All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
caviumaccess.h
Go to the documentation of this file.
1 #pragma once
2 
3 extern "C"
4 {
5 #include <cvmx-config.h>
6 #include <cvmx.h>
7 #include <cvmx-version.h>
8 #include <cvmx-wqe.h>
9 #include <cvmx-fpa.h>
10 #include <cvmx-pow.h>
11 #include <cvmx-pko.h>
12 #include <cvmx-mdio.h>
13 }
14 
15 #define IP2STRING(value) (((value) >> 24) & 0xff), (((value) >> 16) & 0xff), (((value) >> 8) & 0xff), (((value) >> 0) & 0xff)
16 
17 
18 #define GRP_MASK(x) (0x1 << (x))
19 #define CORE_MASK(x) (0x1 << (x))
20 #define IP_OFFSET 4
21 
22 #define cavium_panic(...) \
23 { \
24  printf("CAVIUM_PANIC:" __VA_ARGS__); \
25  printf("\n"); \
26  exit(-1); \
27 }
28 
29 
30 #define CAVIUM_ASSERT(exp,msg) \
31 { \
32  if(!(exp)) cavium_panic msg; \
33 }
34 
36 {
37 public:
38 
39 #pragma pack(push,2)
40 
41  struct TPhyStatus
42  {
43  bool bLinkUp;
45  int iSpeed;
46  };
47 
48 
49  struct TCfgVlan
50  {
51  uint8_t ucPriority;
52  bool bCfi;
53  uint16_t usVLanId;
54  };
55 
56  struct TNetEth
57  {
58  uint16_t usMacDstHigh; // Set in TcpConnectionData or NewArpEntry
59  uint16_t usMacDstMid; // Set in TcpConnectionData or NewArpEntry
60  uint16_t usMacDstLow; // Set in TcpConnectionData or NewArpEntry
61  uint16_t usMacSrcHigh; // Set in Startup
62  uint16_t usMacSrcMid; // Set in Startup
63  uint16_t usMacSrcLow; // Set in Startup
64  uint16_t usType; // Set in Startup
65  };
66 
67  struct TNetVlan
68  {
69  uint16_t usPrioCfiVlanId;
70  uint16_t usOrgType;
71  };
72 
73  struct TNetIp
74  {
75  uint8_t ucVersionIhl; //1 Set in Startup
76  uint8_t ucTos; // Set in Startup
77  uint16_t usTotalLength; // Set in TcpConnectionData
78  uint16_t usId; // Set in Startup
79  union
80  {
81  uint16_t usFlagsFrameoffset; // Set in Startup
82  struct
83  {
84  uint16_t Flags:3;
85  uint16_t Offset:13;
86  }ui16Fragment;
87  };
88  uint8_t ucTtl; // Set in Startup
89  uint8_t ucProtocol; // Set in Startup
90  uint16_t usChecksum; // Calculated by Octeon
91  union
92  {
93  struct
94  {
95  uint16_t usIpSrcHigh; // Set in Startup
96  uint16_t usIpSrcLow; // Set in Startup
97  };
99  };
100  union
101  {
102  struct
103  {
104  uint16_t usIpDstHigh; // Set in TcpConnectionData
105  uint16_t usIpDstLow; // Set in TcpConnectionData
106  };
108  };
109  };
110 
111  struct TNetIpv6
112  {
113  uint16_t usVtfMsw;
114  uint16_t usVtfLsw;
115  uint16_t usPayloadLength;
116  uint8_t ucNextHeader;
117  uint8_t ucHopLimit;
118  union
119  {
120  uint16_t usSource[8];
121  uint64_t uxSource[2];
122  };
123  union
124  {
125  uint16_t usDestination[8];
126  uint64_t uxDestination[2];
127  };
128  };
129 
130 
131  struct TNetUdp
132  {
133  uint16_t usUdpSrcPort; // Set in TcpConnectionOpen
134  uint16_t usUdpDstPort; // Set in TcpConnectionData
135  uint16_t usUdpLength; // Set in TcpConnectionData
136  uint16_t usUdpChecksum; // Calculated by Octeon
137  };
138 
139 // +----------------+
140 // | 207 < B < 224 -+--> forward to VSN Transport
141 // | |
142 // | 127 < B < 192 -+--> forward to RTP
143 // packet --> | |
144 // | 19 < B < 64 -+--> forward to DTLS
145 // | |
146 // | B < 2 -+--> forward to STUN
147 // +----------------+
148 
149  struct TNetRtp
150  {
151  uint8_t ucRtpHeader;
153  uint16_t usRtpSequence;
156  uint16_t usRtpSsrcH;
157  uint16_t usRtpSsrcL;
158  };
159 
160  struct TNetStun
161  {
166  uint16_t usStunTransactionId[6];
167  };
168 
169  struct TNetDtls
170  {
171  uint8_t ucContentType;
173  uint8_t ucLength;
174  };
175 
176  struct TNetVutp // VSN Protocol
177  {
178  uint8_t ucIdentifier:4; // should be 0xD first byte 207 < B < 224
179  uint8_t ucVersion:4; // should be 0 for now
180  uint8_t ucType; // EVutpType
181  uint16_t usTagInputValue; // tag can be calculated
182  uint16_t usUserData;
183  uint16_t usLength;
184  };
185 
186 
187  struct TNetTcp
188  {
189  uint16_t usTcpSrcPort;
190  uint16_t usTcpDstPort;
191  uint16_t usTcpSeqNoHigh;
192  uint16_t usTcpSeqNoLow;
193  uint16_t usTcpAckNoHigh;
194  uint16_t usTcpAckNoLow;
196  uint8_t ucTcpFlags;
197  uint16_t usTcpWindowSize;
198  uint16_t usTcpChecksum;
200  };
201 
202  struct TTypeLength
203  {
204  uint16_t usType;
205  uint16_t usLength;
206  };
207 
208  struct TPacketInfo
209  {
220  uint16_t usType; // Eth Type (in case of Vlan original Eth Type)
221  uint8_t ucProtocol; // Protocol for IPv6, IP
222  };
223 
224  struct TMac
225  {
226  union
227  {
228  uint8_t ucOctet[6];
229  struct
230  {
231  uint16_t usHigh;
232  uint16_t usMid;
233  uint16_t usLow;
234  };
235  };
236  };
237 
238  // MAc address is not included is resolved by arp class
240  {
241  uint16_t usActivePort;
242  uint16_t usVlanId;
243  uint16_t usLocalIpHigh;
244  uint16_t usLocalIpLow;
245  uint16_t usLocalUdpPort;
246  uint16_t usRemoteIpHigh;
247  uint16_t usRemoteIpLow;
248  uint16_t usRemoteUdpPort;
249  };
250 #pragma pack(pop)
251 
253  {
254  MSK_VLAN = 0xFFF,
255  MSK_RTP = 0x80,
256  MSK_STUN = 0x00,
258  };
259 
261  {
263  PT_VLAN = 0x8100,
264  PT_IP = 0x0800,
265  PT_IPV6 = 0x86DD,
266  PT_ARP = 0x0806,
267  PT_ICMP = 0x01,
270  PT_TCP = 0x06,
271  PT_UDP = 0x11,
272  PT_VOCALLO_NET = 0x5200,
273  PT_VSN_NET = 0x5201
274  };
275 
277  {
289  };
290 
292  {
295  };
296 
297 #pragma pack(push,1)
298  struct TVsnNet
299  {
300  uint16_t eVsnNetType;
301  uint16_t usLength;
302  };
303 #pragma pack(pop)
304 
305  static void MacRead (TMac *ptMac, uint8_t *pucUcCount);
306  static bool SendPacket (cvmx_wqe_t *ptWork, uint32_t ulPort, uint32_t QueueSelector);
307  static bool SendPacket (cvmx_wqe_t *ptWork, uint32_t ulPort, TPacketInfo* ptPacketInfo = NULL, uint8_t ucResendId = 0, bool bOverruleQueue = false, uint32_t ulQueueSelector = 0);
308  static void SendNewPacket (unsigned char *pcPacketFPA, uint32_t ui32Len, int iPort, TPacketInfo* ptPacketInfo = NULL, bool bOverruleQueue = false, uint32_t ulQueueSelector = 0);
309  static bool ForwardNewPacket (unsigned char *pcPacketFPA, uint32_t ui32Len, int iPort, uint32_t ulGroup, uint32_t ulTag = 0, cvmx_pow_tag_type_t tTagType = CVMX_POW_TAG_TYPE_ORDERED, uint32_t ulUnused=0);
310  static void ForwardPacket (cvmx_wqe_t *ptWork);
311  static void DropPacket (cvmx_wqe_t *ptWork);
312  static void TagSwitch (uint32_t ulTag);
313  static uint8_t* GetMemPacketPool (void);
314  static void ReturnMemPacketPool (uint8_t* pBuffer);
315  static void ReturnMemPool (uint8_t* pBuffer, uint64_t uxPool);
316  static cvmx_wqe_t* GetMemWqePool (void);
317  static void ReturnMemWqePool (cvmx_wqe_t *ptWork);
318  static void VlanChange (uint16_t usVlanId, cvmx_wqe_t* ptWork, TPacketInfo* ptPacketInfo);
319  static void VlanAdd (cvmx_wqe_t *ptWork, TPacketInfo *ptPacketInfo, uint16_t usVlanId);
320  static void VlanRemove (cvmx_wqe_t *ptWork, TPacketInfo *ptPacketInfo);
321  static void VlanChange (uint16_t usVlanId, uint8_t* pucData, uint16_t usSize, TPacketInfo* ptPacketInfo, uint16_t* pusNewSize);
322  static void VlanAdd (uint8_t* pucData, uint16_t usSize, TPacketInfo *ptPacketInfo, uint16_t usVlanId, uint16_t* pusNewSize);
323  static void VlanAddAndMacChange (cvmx_wqe_t *ptWork, TPacketInfo *ptPacketInfo, uint16_t usVlanId, TMac tNewDstMac);
324  static void VlanRemove (uint8_t* pucData, uint16_t usSize, TPacketInfo *ptPacketInfo, uint16_t* pusNewSize);
325  static void CalcIpChecksum (TPacketInfo* ptPacketInfo);
326  static void GetPacketPointersOld (TPacketInfo* ptPacketInfo, uint8_t* pucBuffer, uint16_t usLength);
327  static void GetPacketPointers (TPacketInfo* ptPacketInfo, uint8_t* pucBuffer, uint16_t usLength);
328  static void SetPacketPointersEth (TPacketInfo* ptPacketInfo, uint8_t* pucBuffer, bool bVlan = false);
329  static void SetPacketPointersUdp (TPacketInfo* ptPacketInfo, uint8_t* pucBuffer, uint16_t usVlanId);
330  static void SetPacketPointersUdpIpV6(TPacketInfo* ptPacketInfo, uint8_t* pucBuffer, uint16_t usVlanId);
331  static void PrintPacketPointerInfo (TPacketInfo* ptPacketInfo);
332  static void PrintPacketInfo (TPacketInfo* ptPacketInfo);
333  static void PrintDestination (TDestination* ptDestination);
334  static void PrintMemory (uint8_t* pucData, uint16_t usLength);
335  static uint16_t Crc16 (uint16_t usInitialValue, uint64_t uxData);
336  static uint32_t Crc32 (uint8_t *pucData, int iSize, uint32_t ulInitialValue, uint32_t ulPoly);
337  static uint32_t CalcTag (uint32_t laddr, uint16_t lport, uint32_t faddr, uint16_t fport);
338  static uint32_t CalcTag (const uint64_t *ptSrcIp, uint16_t usSrcPrt, const uint64_t *ptDstIp, uint16_t usDstPrt);
339  static uint32_t CalcTag (const uint64_t *ptDstIp, uint16_t usDstPrt);
340  static uint32_t CalcTag (uint32_t ulIp, uint16_t usPrt);
341  static uint32_t CalcTag (uint32_t ulIp, uint16_t usPrt, uint16_t usVlan);
342  static uint32_t CalcCRC (uint64_t *pdata, int size, uint32_t iv = 0xffffffff);
343  static uint32_t CalcCRC (uint8_t *pdata, int size, int poly_width = 32, uint32_t iv = 0xffffffff);
344  static uint32_t CalcTag (uint16_t usPrt);
345  static uint32_t CalcTag (uint16_t usPrt, uint16_t usVlan);
346  static uint64_t PowGetGroupMask (uint64_t core_num);
347 
348  static uint32_t WqeGetBufs (cvmx_wqe_t *pWQE);
349  static uint32_t WqeSetBufs (cvmx_wqe_t *pWQE, uint32_t bufs);
350  static bool WqeIsVlan (cvmx_wqe_t *pWQE);
351  static uint16_t WqeGetVlan (cvmx_wqe_t *pWQE);
352  static bool WqeIsArp (cvmx_wqe_t *pWQE);
353  static bool WqeIsICMP (cvmx_wqe_t* pWQE);
354  static bool WqeIsL4UDPTCP (cvmx_wqe_t* pWQE);
355  static bool WqeIsIP (cvmx_wqe_t *pWQE);
356  static bool WqeIsIPV4 (cvmx_wqe_t *pWQE);
357  static bool WqeIsIPV6 (cvmx_wqe_t *pWQE);
358  static bool WqeIsFragmented (cvmx_wqe_t *pWQE);
359  static cvmx_buf_ptr_t WqeGetBase (cvmx_wqe_t *pWQE);
360  static void *WqeGetStartOfIP (cvmx_wqe_t *pWQE);
361  static void *WqeGetStartOfL3 (cvmx_wqe_t *pWQE);
362  static bool WqeIsL1L2Error (cvmx_wqe_t *pWQE);
363  static bool WqeIsIPError (cvmx_wqe_t *pWQE);
364  static bool WqeIsL4Error (cvmx_wqe_t *pWQE);
365  static int WqeGetRcvError (cvmx_wqe_t *pWQE);
366  static void WqeFreeWqe (cvmx_wqe_t *pWQE);
367  static CCaviumAccess::TPhyStatus GetPhyStatus(int iPort);
368 
369 private:
370 
371 };
372 
static void PrintDestination(TDestination *ptDestination)
static uint32_t CalcCRC(uint64_t *pdata, int size, uint32_t iv=0xffffffff)
static void ReturnMemPool(uint8_t *pBuffer, uint64_t uxPool)
static void PrintMemory(uint8_t *pucData, uint16_t usLength)
static bool WqeIsVlan(cvmx_wqe_t *pWQE)
static uint32_t Crc32(uint8_t *pucData, int iSize, uint32_t ulInitialValue, uint32_t ulPoly)
static uint8_t * GetMemPacketPool(void)
static cvmx_wqe_t * GetMemWqePool(void)
static bool WqeIsArp(cvmx_wqe_t *pWQE)
static bool WqeIsIP(cvmx_wqe_t *pWQE)
static void MacRead(TMac *ptMac, uint8_t *pucUcCount)
static bool ForwardNewPacket(unsigned char *pcPacketFPA, uint32_t ui32Len, int iPort, uint32_t ulGroup, uint32_t ulTag=0, cvmx_pow_tag_type_t tTagType=CVMX_POW_TAG_TYPE_ORDERED, uint32_t ulUnused=0)
static void SetPacketPointersUdpIpV6(TPacketInfo *ptPacketInfo, uint8_t *pucBuffer, uint16_t usVlanId)
static uint32_t CalcTag(uint32_t laddr, uint16_t lport, uint32_t faddr, uint16_t fport)
static void ForwardPacket(cvmx_wqe_t *ptWork)
static bool WqeIsL1L2Error(cvmx_wqe_t *pWQE)
static bool WqeIsIPV6(cvmx_wqe_t *pWQE)
static bool WqeIsL4Error(cvmx_wqe_t *pWQE)
static void PrintPacketPointerInfo(TPacketInfo *ptPacketInfo)
static bool WqeIsFragmented(cvmx_wqe_t *pWQE)
static cvmx_buf_ptr_t WqeGetBase(cvmx_wqe_t *pWQE)
static CCaviumAccess::TPhyStatus GetPhyStatus(int iPort)
static bool WqeIsICMP(cvmx_wqe_t *pWQE)
static void PrintPacketInfo(TPacketInfo *ptPacketInfo)
static uint32_t WqeGetBufs(cvmx_wqe_t *pWQE)
static void SetPacketPointersUdp(TPacketInfo *ptPacketInfo, uint8_t *pucBuffer, uint16_t usVlanId)
static void CalcIpChecksum(TPacketInfo *ptPacketInfo)
static void SendNewPacket(unsigned char *pcPacketFPA, uint32_t ui32Len, int iPort, TPacketInfo *ptPacketInfo=NULL, bool bOverruleQueue=false, uint32_t ulQueueSelector=0)
static int WqeGetRcvError(cvmx_wqe_t *pWQE)
static void WqeFreeWqe(cvmx_wqe_t *pWQE)
static uint16_t WqeGetVlan(cvmx_wqe_t *pWQE)
static void VlanAdd(cvmx_wqe_t *ptWork, TPacketInfo *ptPacketInfo, uint16_t usVlanId)
static void GetPacketPointers(TPacketInfo *ptPacketInfo, uint8_t *pucBuffer, uint16_t usLength)
uint16_t usFlagsFrameoffset
Definition: caviumaccess.h:81
static void SetPacketPointersEth(TPacketInfo *ptPacketInfo, uint8_t *pucBuffer, bool bVlan=false)
static uint32_t WqeSetBufs(cvmx_wqe_t *pWQE, uint32_t bufs)
struct CCaviumAccess::TNetIp::@17::@23 ui16Fragment
static void * WqeGetStartOfIP(cvmx_wqe_t *pWQE)
static bool WqeIsL4UDPTCP(cvmx_wqe_t *pWQE)
static void DropPacket(cvmx_wqe_t *ptWork)
static void GetPacketPointersOld(TPacketInfo *ptPacketInfo, uint8_t *pucBuffer, uint16_t usLength)
static void VlanAddAndMacChange(cvmx_wqe_t *ptWork, TPacketInfo *ptPacketInfo, uint16_t usVlanId, TMac tNewDstMac)
uint16_t usStunTransactionId[6]
Definition: caviumaccess.h:166
static void ReturnMemPacketPool(uint8_t *pBuffer)
static bool SendPacket(cvmx_wqe_t *ptWork, uint32_t ulPort, uint32_t QueueSelector)
static uint64_t PowGetGroupMask(uint64_t core_num)
static void ReturnMemWqePool(cvmx_wqe_t *ptWork)
static uint16_t Crc16(uint16_t usInitialValue, uint64_t uxData)
static void TagSwitch(uint32_t ulTag)
static void VlanRemove(cvmx_wqe_t *ptWork, TPacketInfo *ptPacketInfo)
static bool WqeIsIPError(cvmx_wqe_t *pWQE)
static bool WqeIsIPV4(cvmx_wqe_t *pWQE)
static void VlanChange(uint16_t usVlanId, cvmx_wqe_t *ptWork, TPacketInfo *ptPacketInfo)
static void * WqeGetStartOfL3(cvmx_wqe_t *pWQE)