1 /*****************************************
2 * file: netapi_loc.h
3 * purpose: internal netapi stuff
4 ****************************************/
6 #ifndef __NETAPI_LOC__H
7 #define __NETAPI_LOC__H
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
13 #include "ti/drv/nwal/nwal_util.h"
14 #include "ti/runtime/netapi/pktio.h"
15 #include "ti/drv/nwal/nwal.h"
16 //#include "ti/drv/nwal/nwal_util.h"
17 #include "ti/runtime/hplib/hplib.h"
20 extern hplib_virtualAddrInfo_T netapi_VM_VirtAddr[HPLIB_MAX_MEM_POOLS];
21 extern unsigned char *netapi_VM_SaContextVaddr;
23 #define NETAPI_FALSE 0
24 #define NETAPI_TRUE 1
25 /***********************************************
26 * GLOBAL AREA
27 * short term: this is global to process
28 * (multi-process not supported)
29 * long term: this structure gets put in shared memory
30 ***********************************************/
32 /* list of global pktio channels that have been created
33 (NETCP_TX, RX are intrinsic so won't be here) */
34 typedef struct PKTIO_ENTRY_tag
35 {
36 char name[PKTIO_MAX_NAME+1];
37 Qmss_Queue qn; // -1 => slot is free
38 } PKTIO_ENTRY_T;
40 /* to hold an IP on an interface */
41 typedef struct NETCP_INTERFACE_IP_Tag
42 {
43 int in_use;
44 void * nwal_handle;
45 nwal_IpType ip_type;
46 nwalIpAddr_t ip_addr;
47 nwalIpOpt_t ip_qualifiers;
48 void * user_data;
49 } NETCP_INTERFACE_IP_T;
51 /* to hold a classifier */
52 typedef struct NETCP_INTERFACE_CLASSIFIER_Tag
53 {
54 int in_use;
55 int class_type; //see netcp_cfg.h
56 void * nwal_L2_handle;
57 void * nwal_L3_handle;
58 void * nwal_L4_handle;
59 void * user_data;
60 } NETCP_INTERFACE_CLASSIFIER_T;
62 /* to hold an ipsec rx policy */
63 typedef struct NETCP_IPSEC_POLICY_Tag
64 {
65 int in_use;
66 int tunnel; //associated tunnel
67 void * nwal_handle; //handle associated with this RX Policy
68 void * user_data; // user data associtaed with this RX Policy
69 } NETCP_IPSEC_POLICY_T;
71 /* to hold a tunnel */
72 typedef struct NETCP_IPSEC_SA_Tag
73 {
74 int in_use;
75 int inbound; //true if inbound
77 int sa_mode; //mode we are going to use
78 #define NETCP_IPSEC_SA_MODE_INFLOW 0
79 #define NETCP_IPSEC_SA_MODE_SIDEBAND 1
81 void * sa_handle_inflow; //for inflow mode
82 void * sa_handle_sideband; //for sideband mode
83 int iface; //associated interface
84 nwalTxDmPSCmdInfo_t dmPSCmdInfo;
85 uint32_t swInfo0;
86 uint32_t swInfo1;
87 void* user_data;
88 } NETCP_IPSEC_SA_T;
90 /* to hold a netcp 'interface' */
91 typedef struct NETCP_INTERFACE_Tag
92 {
93 int in_use; /* 1 for valid */
94 int state; /* 0=down, 1=up, future.. */
95 void * nwal_handle; //handle associated with this interface
96 unsigned char mac[6]; // mac address
97 unsigned int vlan; //future
98 } NETCP_INTERFACE_T;
100 /*to keep track of netcp config transactions */
101 typedef struct {
102 nwal_Bool_t inUse;
103 uint16_t transType;
104 #define NETAPI_NWAL_HANDLE_TRANS_NONE 0
105 #define NETAPI_NWAL_HANDLE_TRANS_MAC 1
106 #define NETAPI_NWAL_HANDLE_TRANS_IP 2
107 #define NETAPI_NWAL_HANDLE_TRANS_PORT 3
108 #define NETAPI_NWAL_HANDLE_TRANS_SA 4
109 #define NETAPI_NWAL_HANDLE_TRANS_SA_POLICY 5
110 #define NETAPI_NWAL_HANDLE_STAT_REQUEST 6
112 uint16_t state;
113 #define NETAPI_NWAL_HANDLE_STATE_IDLE 0
114 #define NETAPI_NWAL_HANDLE_STATE_OPEN_PENDING 1
115 #define NETAPI_NWAL_HANDLE_STATE_OPEN 2
116 #define NETAPI_NWAL_HANDLE_STATE_CLOSE_PENDING 3
117 #define NETAPI_NWAL_HANDLE_STATE_ERR 4
118 nwal_Handle handle;
119 uint64_t transId;
120 NETAPI_T netapi_handle; //the thread making the transaction
121 } NetapiNwalTransInfo_t;
123 /* to hold user defined flows */
124 typedef struct NETCP_REGISTERED_FLOWS_Tag
125 {
126 int in_use; //1=> in use
127 void* handle; //cppi handle to resource (internal)
128 NETCP_CFG_FLOW_T flow;
129 } NETCP_REGISTERED_FLOWS_T;
131 /******************************
132 * nwal global context : for SOC
133 * (shared over all process instances)
134 *******************************/
135 typedef struct
136 {
137 int state;
138 #define NETAPI_NW_CXT_GLOB_INACTIVE 0x0
139 #define NETAPI__CXT_GLOB_ACTIVE 0x1
140 #define NETAPI_NW_CXT_GLOB_RES_ALLOC_COMPLETE 0x3
142 nwal_Handle nwalInstHandle; //created instance
143 //internal heaps used just by netcp (sa<->pa). SW doesn't touch these
144 Pktlib_HeapHandle sa2pa_heap;
145 Pktlib_HeapHandle pa2sa_heap;
146 //stats
147 paSysStats_t paStats;
148 NETCP_INTERFACE_T interfaces[TUNE_NETAPI_MAX_NUM_MAC]; //interfaces
149 NETCP_INTERFACE_CLASSIFIER_T classi[TUNE_NETAPI_MAX_CLASSIFIERS]; //classifiers
150 NETCP_REGISTERED_FLOWS_T flows[TUNE_NETAPI_MAX_FLOWS]; //flows
151 NETCP_IPSEC_SA_T tunnel[TUNE_NETAPI_MAX_SA]; //tunnels
152 NETCP_IPSEC_POLICY_T policy[TUNE_NETAPI_MAX_POLICY]; //policies
153 NETCP_INTERFACE_IP_T ips[TUNE_NETAPI_MAX_NUM_IP]; //ips
154 } NETAPI_NWAL_GLOBAL_CONTEXT_T;
155 /************************************/
156 /* global instance for this process */
157 /************************************/
158 typedef struct
159 {
160 int state; /* see above*/
161 int numCmdPass;
162 int numCmdFail;
163 int numBogusTransIds;
164 NetapiNwalTransInfo_t transInfos[TUNE_NETAPI_MAX_NUM_TRANS];
165 } NETAPI_NWAL_GLOBAL_PROC_CONTEXT_T;
167 /* NWAL Local context (per core/thread) */
168 typedef struct
169 {
170 #define NETAPI_NW_CXT_LOC_INACTIVE 0x0
171 #define NETAPI_NW_CXT_LOC_ACTIVE 0x2
172 int state;
174 int numPendingCfg;
175 NETCP_CFG_STATS_CB stats_cb;
177 /* stats */
178 int numL2PktsRecvd;
179 int numL3PktsRecvd;
180 int numL4PktsRecvd;
181 int numL4PktsSent;
182 int TxErrDrop;
184 /* local config */
185 nwalLocCfg_t nwalLocCfg;
186 } NETAPI_NWAL_LOCAL_CONTEXT_T;
188 /* the global: for SOC, accross all processes */
189 typedef struct NETAPI_GLOBAL_tag
190 {
191 #define NETAPI_MAX_PKTIO (TUNE_NETAPI_MAX_PKTIO)
192 PKTIO_ENTRY_T pktios[NETAPI_MAX_PKTIO];
193 /* configuration */
194 NETAPI_CFG_T cfg;
195 /* nwal context */
196 NETAPI_NWAL_GLOBAL_CONTEXT_T nwal_context;
197 //NETAPI_T p_master; // save p'masters handle
198 } NETAPI_GLOBAL_T;
200 /* the process global: one per process */
201 typedef struct NETAPI_PROC_GLOBAL_tag
202 {
203 /* nwal context */
204 NETAPI_NWAL_GLOBAL_PROC_CONTEXT_T nwal_context;
206 //NETAPI_T p_master; // save p'masters handle
207 } NETAPI_PROC_GLOBAL_T;
208 /************************************
209 * this is a per thread structure.
210 * It contains stuff local to thread
211 * and pointer to global stuff
212 * that is shared over all threads,
213 **************************************/
214 typedef struct NETAPI_HANDLE_Tag
215 {
216 int master; //master type
218 void* global; /* pointer to the soc global area */
219 void* proc_global; /* pointer to the proc global area */
221 /* heap handles */
222 Pktlib_HeapHandle netcp_heap; /* internal default */
223 Pktlib_HeapHandle netcp_control_rx_heap; /* for control messages */
224 Pktlib_HeapHandle netcp_control_tx_heap; /* for control messages */
225 Pktlib_HeapHandle createdHeaps[TUNE_NETAPI_MAX_HEAPS]; /* created by app and registered */
227 /* pktios defined */
228 int n_pktios; /* #of pktios that are active for this instance */
229 void* pktios[NETAPI_MAX_PKTIO]; /* the list of pktios */
231 /* scheduler stuff. unallocated if NETAPI_INCLUDE_SCHED not set */
232 void* p_sched;
234 /* nwal local context */
235 NETAPI_NWAL_LOCAL_CONTEXT_T nwal_local;
237 /* thread cookie */
238 void* cookie; /*set by calling thread */
239 HPLIB_SPINLOCK_IF_T spinLock;
240 int memRegion;
241 } NETAPI_HANDLE_T;
243 typedef struct NETAPI_SHM_Tag
244 {
245 NETAPI_GLOBAL_T netapi_global;
246 hplib_spinLock_T netapi_pktio_lock;
247 hplib_spinLock_T netapi_netcp_cfg_lock;
248 hplib_spinLock_T netapi_util_lock;
249 hplib_spinLock_T netapi_netcp_cfg_l3_classi_lock;
250 } NETAPI_SHM_T;
252 //internal initialization routines */
253 int netapip_initQm(int max_descriptors, void* rmClientServiceHandle);
255 int netapip_initCppi(void* rmClientServiceHandle);
257 int netapip_startQm(void* rmClientServiceHandle);
258 int netapip_initNwal(int region2use,
259 Pktlib_HeapIfTable * p_table,
260 NETAPI_NWAL_GLOBAL_CONTEXT_T * p_nwal_context,
261 NETAPI_CFG_T *p_cfg);
262 int netapip_startNwal(Pktlib_HeapHandle pkt_heap,
263 Pktlib_HeapHandle cmd_heapRx,
264 Pktlib_HeapHandle cmd_heapTx,
265 NETAPI_NWAL_LOCAL_CONTEXT_T* p,
266 NETAPI_CFG_T* p_cfg,
267 NETAPI_NWAL_GLOBAL_CONTEXT_T* p_nwal_glob_context,
268 int master);
270 int netapip_initTimer(void);
271 int netapip_qmSetupMemRegion(unsigned int numDesc,
272 unsigned int descSize,
273 unsigned int* pDescMemBase,
274 int memRegion);
276 #define NETAPI_GLOBAL_REGION TUNE_NETAPI_QM_GLOBAL_REGION
277 #define NETAPI_LOCAL_REGION ((NETAPI_GLOBAL_REGION)+1)
280 //nwal callbacks
281 void netapip_pktioNWALRxPktCallback(uint32_t appCookie,
282 uint16_t numPkts,
283 nwalRxPktInfo_t* pPktInfo,
284 uint64_t timestamp,
285 nwal_Bool_t* pFreePkt);
287 void netapip_netcpCfgNWALCmdCallBack (nwal_AppId appHandle,
288 uint16_t trans_id,
289 nwal_RetValue ret);
291 void netapip_netcpCfgNWALCmdPaStatsReply (nwal_AppId appHandle,
292 nwal_TransID_t trans_id,
293 paSysStats_t *stats);
295 void netapip_pktioNWALSBPktCallback (uint32_t appCookie,
296 uint16_t numPkts,
297 nwalDmRxPayloadInfo_t* pDmRxPktInfo,
298 nwal_Bool_t* pFreePkt);
301 //***********************************
302 //internal utilities
303 //*************************************
305 //return the list of pktios for this instance
306 static inline void ** netapi_get_pktio_list(NETAPI_T p)
307 {
308 NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
309 return &pp->pktios[0];
310 }
312 //get scheduler block handle
313 static inline void * netapi_get_scheduler(NETAPI_T p)
314 {
315 NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
316 return pp->p_sched;
317 }
319 /* return pointer to global area */
320 NETAPI_GLOBAL_T * netapi_get_global(void);
321 NETAPI_PROC_GLOBAL_T * netapi_get_proc_global(void);
323 //add a pktio name (and queue) to global list
324 static inline int netapip_addGlobalPktio(NETAPI_T p, char *name, Qmss_Queue * qn)
325 {
326 NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
327 PKTIO_ENTRY_T *pe;
328 int i;
329 //find a free slot
330 pe = &((NETAPI_GLOBAL_T *)(pp->global))->pktios[0];
331 //pe = &(pnetapiShm->netapi_global.pktios[0]);
335 //for(i=0;i<NETAPI_MAX_PKTIO; i++,pe++)
336 for(i=0;i<NETAPI_MAX_PKTIO; i++)
337 {
338 //pe = &(pnetapiShm->netapi_global.pktios[i]);
339 pe = &((NETAPI_GLOBAL_T *)(pp->global))->pktios[i];
340 if (pe->qn.qNum == -1)
341 {
342 pe->qn.qNum=qn->qNum;
343 pe->qn.qMgr=qn->qMgr;
344 strncpy(pe->name, name, PKTIO_MAX_NAME);
345 return 1;
346 }
347 //pe+=1;
348 }
349 return 0; //no room
350 }
352 //delete a pktio name (and queue) to global list
353 static inline int netapi_del_global_pktio(NETAPI_T p, char *name)
354 {
355 NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
356 PKTIO_ENTRY_T *pe;
357 int i;
358 //find slot
359 pe = &((NETAPI_GLOBAL_T *)(pp->global))->pktios[0];
361 for(i=0;i<NETAPI_MAX_PKTIO; i++,pe++)
362 {
363 if (pe->qn.qNum == -1) continue;
364 if (!strncmp(name, pe->name, PKTIO_MAX_NAME))
365 {
366 pe->qn.qNum=-1;
367 pe->name[0]='\0';
368 return 1;
369 }
370 pe+=1;
371 }
372 return 0; //no room
373 }
376 /* get list of global pktios that have been created */
377 static inline Qmss_Queue* netapip_findGlobalPktio(NETAPI_T p, char *name)
378 {
379 NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
380 PKTIO_ENTRY_T *pe;
381 int i;
382 //find slot
383 pe = &((NETAPI_GLOBAL_T *)(pp->global))->pktios[0];
385 for(i=0;i<NETAPI_MAX_PKTIO; i++,pe++)
386 {
387 if (pe->qn.qNum == -1) continue;
388 if (!strncmp(name, pe->name, PKTIO_MAX_NAME))
389 {
390 return &pe->qn;
391 }
392 pe +=1;
393 }
394 return NULL; //not found
395 }
397 /* return the nwal global instance handle */
398 static inline nwal_Handle netapip_returnNwalInstanceHandle(NETAPI_T p)
399 {
401 NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
402 return ((NETAPI_GLOBAL_T *)(pp->global))->nwal_context.nwalInstHandle;
403 }
407 //utility to clear out a queue
408 void netapip_zapQ(int queueNum);
409 void netapip_netcpCfgBuildRoute(NETCP_CFG_ROUTE_T * p_route,
410 int16_t * p_flow,
411 Qmss_QueueHnd * p_q,
412 nwalRouteType_t *p_type);
414 //database utilities
415 void netapip_netcpCfgDeleteSa(NETAPI_NWAL_GLOBAL_CONTEXT_T *p,int sa_slot);
417 void netapip_netcpCfgInsertSa(NETAPI_NWAL_GLOBAL_CONTEXT_T *p,
418 int sa_slot, //we 'reserved it already'
419 int dir,
420 int mode,
421 void * temp1,
422 void * temp2,
423 void * handle_inflow,
424 void * handle_sideband,
425 nwalTxDmPSCmdInfo_t *dmPSCmdInfo,
426 uint32_t swInfo0,
427 uint32_t swInfo1,
428 void* user_data);
429 void *netapip_netcpCfgGetSaHandles( NETAPI_NWAL_GLOBAL_CONTEXT_T *p,
430 int sa_slot, void ** p_sideband);
431 void* netapip_netcpCfgGetMacHandle(NETAPI_NWAL_GLOBAL_CONTEXT_T *p,int iface_no);
432 NetapiNwalTransInfo_t * netapip_getFreeTransInfo(NETAPI_HANDLE_T *p_handle,
433 NETAPI_PROC_GLOBAL_T *p_global,
434 nwal_TransID_t *pTransId);
435 void netapip_freeTransInfo(NetapiNwalTransInfo_t* pTransInfo);
436 void *netapip_netcpCfgGetPolicy( NETAPI_NWAL_GLOBAL_CONTEXT_T *p,
437 int policy_slot);
438 nwalTxDmPSCmdInfo_t* netapip_netcpCfgGetSaSBInfo(NETAPI_NWAL_GLOBAL_CONTEXT_T *p,
439 NETCP_CFG_SA_T sa_app_id);
440 int netapip_netcpCfgGetSaInflowInfo(NETAPI_NWAL_GLOBAL_CONTEXT_T *p,
441 NETCP_CFG_SA_T sa_app_id,
442 uint32_t *swInfo0,
443 uint32_t *swInfo1);
445 int netapip_systemInit(NETAPI_HANDLE_T *handle,
446 Bool global_master_process);
449 void netapip_cleanupAtStart(void);
454 #ifdef __cplusplus
455 }
456 #endif
458 #endif