1 /*****************************************
2 * file: netapi_loc.h
3 * purpose: internal netapi stuff
4 ****************************************/
6 #ifndef __NETAPI_LOC__H
7 #define __NETAPI_LOC__H
8 /***************************************
9 * INTERNAL HANDLE STRUCTURE DEFINITION
10 ****************************************/
12 /***********************************************
13 * GLOBAL AREA
14 * short term: this is global to process
15 * (multi-process not supported)
16 * long term: this structure gets put in shared memory
17 ***********************************************/
19 /* list of global pktio channels that have been created
20 (NETCP_TX, RX are intrinsic so won't be here) */
21 typedef struct PKTIO_ENTRY_tag
22 {
23 char name[PKTIO_MAX_NAME+1];
24 Qmss_Queue qn; // -1 => slot is free
25 } PKTIO_ENTRY_T;
27 /* to hold an IP on an interface */
28 typedef struct NETCP_INTERFACE_IP_Tag
29 {
30 int in_use;
31 void * nwal_handle;
32 nwal_IpType ip_type;
33 nwalIpAddr_t ip_addr;
34 nwalIpOpt_t ip_qualifiers;
35 } NETCP_INTERFACE_IP_T;
37 /* to hold a classifier */
38 typedef struct NETCP_INTERFACE_CLASSIFIER_Tag
39 {
40 int in_use;
41 int class_type; //see netcp_cfg.h
42 void * nwal_L2_handle;
43 void * nwal_L3_handle;
44 void * nwal_L4_handle;
45 } NETCP_INTERFACE_CLASSIFIER_T;
47 /* to hold an ipsec rx policy */
48 typedef struct NETCP_IPSEC_POLICY_Tag
49 {
50 int in_use;
51 int tunnel; //associated tunnel
52 void * nwal_handle; //handle associated with this RX Policy
53 } NETCP_IPSEC_POLICY_T;
55 /* to hold a tunnel */
56 typedef struct NETCP_IPSEC_SA_Tag
57 {
58 int in_use;
59 int inbound; //true if inbound
61 int sa_mode; //mode we are going to use
62 #define NETCP_IPSEC_SA_MODE_INFLOW 0
63 #define NETCP_IPSEC_SA_MODE_SIDEBAND 1
65 void * sa_handle_inflow; //for inflow mode
66 void * sa_handle_sideband; //for sideband mode
67 int iface; //associated interface
68 } NETCP_IPSEC_SA_T;
70 /* to hold a netcp 'interface' */
71 typedef struct NETCP_INTERFACE_Tag
72 {
73 int in_use; /* 1 for valid */
74 int state; /* 0=down, 1=up, future.. */
75 void * nwal_handle; //handle associated with this interface
76 unsigned char mac[6]; // mac address
77 unsigned int vlan; //future
78 } NETCP_INTERFACE_T;
80 /*to keep track of netcp config transactions */
81 typedef struct {
82 nwal_Bool_t inUse;
83 uint16_t transType;
84 #define NETAPI_NWAL_HANDLE_TRANS_NONE 0
85 #define NETAPI_NWAL_HANDLE_TRANS_MAC 1
86 #define NETAPI_NWAL_HANDLE_TRANS_IP 2
87 #define NETAPI_NWAL_HANDLE_TRANS_PORT 3
88 #define NETAPI_NWAL_HANDLE_TRANS_SA 4
89 #define NETAPI_NWAL_HANDLE_TRANS_SA_POLICY 5
90 #define NETAPI_NWAL_HANDLE_STAT_REQUEST 6
92 uint16_t state;
93 #define NETAPI_NWAL_HANDLE_STATE_IDLE 0
94 #define NETAPI_NWAL_HANDLE_STATE_OPEN_PENDING 1
95 #define NETAPI_NWAL_HANDLE_STATE_OPEN 2
96 #define NETAPI_NWAL_HANDLE_STATE_CLOSE_PENDING 3
97 nwal_Handle handle;
98 uint64_t transId;
99 NETAPI_T netapi_handle; //the thread making the transaction
100 } NetapiNwalTransInfo_t;
102 /* to hold user defined flows */
103 typedef struct NETCP_REGISTERED_FLOWS_Tag
104 {
105 int in_use; //1=> in use
106 void * handle; //cppi handle to resource (internal)
107 NETCP_CFG_FLOW_T flow;
108 } NETCP_REGISTERED_FLOWS_T;
110 /******************************
111 * nwal global context
112 * (shared over all instances)
113 *******************************/
114 typedef struct
115 {
116 int state;
117 #define NETAPI_NW_CXT_GLOB_INACTIVE 0x0
118 #define NETAPI__CXT_GLOB_ACTIVE 0x1
119 #define NETAPI_NW_CXT_GLOB_RES_ALLOC_COMPLETE 0x3
121 nwal_Handle nwalInstHandle;
122 //internal heaps used just by netcp (sa<->pa). SW doesn't touch these
123 Pktlib_HeapHandle sa2pa_heap;
124 Pktlib_HeapHandle pa2sa_heap;
125 //stats
126 paSysStats_t paStats;
127 int numCmdPass;
128 int numCmdFail;
129 int numBogusTransIds;
130 NetapiNwalTransInfo_t transInfos[TUNE_NETAPI_MAX_NUM_TRANS]; //transactions
131 NETCP_INTERFACE_T interfaces[TUNE_NETAPI_MAX_INTERFACES]; //interfaces
132 NETCP_INTERFACE_CLASSIFIER_T classi[TUNE_NETAPI_MAX_CLASSIFIERS]; //classifiers
133 NETCP_REGISTERED_FLOWS_T flows[TUNE_NETAPI_MAX_FLOWS]; //flows
134 NETCP_IPSEC_SA_T tunnel[TUNE_NETAPI_MAX_SA]; //tunnels
135 NETCP_IPSEC_POLICY_T policy[TUNE_NETAPI_MAX_POLICY]; //policies
136 NETCP_INTERFACE_IP_T ips[TUNE_NETAPI_MAX_IP]; //ips
137 } NETAPI_NWAL_GLOBAL_CONTEXT_T;
139 /* NWAL Local context (per core/thread) */
140 typedef struct
141 {
142 //void * nwalLocInstance;
143 #define NETAPI_NW_CXT_LOC_INACTIVE 0x0
144 #define NETAPI_NW_CXT_LOC_ACTIVE 0x2
145 int state;
147 int numPendingCfg;
148 NETCP_CFG_STATS_CB stats_cb;
150 /* stats */
151 int numL2PktsRecvd;
152 int numL3PktsRecvd;
153 int numL4PktsRecvd;
154 int numL4PktsSent;
155 int TxErrDrop;
157 /* local config */
158 nwalLocCfg_t nwalLocCfg;
159 } NETAPI_NWAL_LOCAL_CONTEXT_T;
161 /* the global */
162 typedef struct NETAPI_GLOBAL_tag
163 {
164 #define NETAPI_MAX_PKTIO (TUNE_NETAPI_MAX_PKTIO)
165 PKTIO_ENTRY_T pktios[NETAPI_MAX_PKTIO];
167 /* configuration */
168 NETAPI_CFG_T cfg;
170 /* global timers */
172 /* nwal context */
173 NETAPI_NWAL_GLOBAL_CONTEXT_T nwal_context;
175 } NETAPI_GLOBAL_T;
178 /************************************
179 * this is a per thread structure.
180 * It contains stuff local to thread
181 * and pointer to global stuff
182 * that is shared over all threads,
183 **************************************/
184 typedef struct NETAPI_HANDLE_Tag
185 {
186 int master; //master type
188 void * global; /* pointer to the global area */
190 /* heap handles */
191 Pktlib_HeapHandle netcp_heap; /* internal default */
192 Pktlib_HeapHandle netcp_control_rx_heap; /* for control messages */
193 Pktlib_HeapHandle netcp_control_tx_heap; /* for control messages */
194 Pktlib_HeapHandle createdHeaps[TUNE_NETAPI_MAX_HEAPS]; /* created by app and registered */
196 /* pktios defined */
197 int n_pktios; /* #of pktios that are active for this instance */
198 void* pktios[NETAPI_MAX_PKTIO]; /* the list of pktios */
200 /* scheduler stuff. unallocated if NETAPI_INCLUDE_SCHED not set */
201 void * p_sched;
203 /* nwal local context */
204 NETAPI_NWAL_LOCAL_CONTEXT_T nwal_local;
206 /* security stuff */
208 /* timer stuff */
210 /* thread cookie */
211 void * cookie; /*set by calling thread */
213 } NETAPI_HANDLE_T;
216 //internal initialization routines */
217 int netapi_init_qm(int max_descriptors);
218 int netapi_init_cppi(void);
219 int netapi_init_cpsw(void);
220 int netapi_start_qm(void);
221 int netapi_init_nwal(
222 int region2use,
223 Pktlib_HeapIfTable * p_table,
224 NETAPI_NWAL_GLOBAL_CONTEXT_T * p_nwal_context,
225 NETAPI_CFG_T *p_cfg );
226 int netapi_start_nwal(Pktlib_HeapHandle pkt_heap,
227 Pktlib_HeapHandle cmd_heapRx,
228 Pktlib_HeapHandle cmd_heapTx,
229 NETAPI_NWAL_LOCAL_CONTEXT_T *p ,
230 NETAPI_CFG_T *p_cfg,
231 NETAPI_NWAL_GLOBAL_CONTEXT_T * p_nwal_glob_context );
233 int netapi_init_timer(void);
234 int netapi_qm_setup_mem_region(
235 unsigned int numDesc,
236 unsigned int descSize,
237 unsigned int* pDescMemBase,
238 int memRegion);
239 //for above
240 #define NETAPI_GLOBAL_REGION TUNE_NETAPI_QM_GLOBAL_REGION
241 #define NETAPI_LOCAL_REGION ((NETAPI_GLOBAL_REGION)+1)
243 int netapi_VM_memory_setup(void);
244 void netapi_VM_memory_teardown(void);
246 //nwal callbacks
247 void netapi_NWALRxPktCallback (uint32_t appCookie,
248 uint16_t numPkts,
249 nwalRxPktInfo_t* pPktInfo,
250 uint64_t timestamp,
251 nwal_Bool_t* pFreePkt);
253 void netapi_NWALCmdCallBack (nwal_AppId appHandle,
254 uint16_t trans_id,
255 nwal_RetValue ret);
257 void netapi_NWALCmdPaStatsReply (nwal_AppId appHandle,
258 nwal_TransID_t trans_id,
259 paSysStats_t *stats);
261 void netapi_NWALSBPktCallback (uint32_t appCookie,
262 uint16_t numPkts,
263 nwalDmRxPayloadInfo_t* pDmRxPktInfo,
264 nwal_Bool_t* pFreePkt);
267 //***********************************
268 //internal utilities
269 //*************************************
271 //return the list of pktios for this instance
272 static inline void ** netapi_get_pktio_list(NETAPI_T p)
273 {
274 NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
275 return &pp->pktios[0];
276 }
278 //get scheduler block handle
279 static inline void * netapi_get_scheduler(NETAPI_T p)
280 {
281 NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
282 return pp->p_sched;
283 }
285 /* return pointer to global area */
286 NETAPI_GLOBAL_T * netapi_get_global(void);
288 //add a pktio name (and queue) to global list
289 static inline int netapi_add_global_pktio(NETAPI_T p, char *name, Qmss_Queue * qn)
290 {
291 NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
292 PKTIO_ENTRY_T *pe;
293 int i;
294 //find a free slot
295 pe = &((NETAPI_GLOBAL_T *)(pp->global))->pktios[0];
297 for(i=0;i<NETAPI_MAX_PKTIO; i++,pe++)
298 {
299 if (pe->qn.qNum == -1)
300 {
301 pe->qn.qNum=qn->qNum;
302 pe->qn.qMgr=qn->qMgr;
303 strncpy(pe->name, name, PKTIO_MAX_NAME);
304 return 1;
305 }
306 pe+=1;
307 }
308 return 0; //no room
309 }
311 //delete a pktio name (and queue) to global list
312 static inline int netapi_del_global_pktio(NETAPI_T p, char *name)
313 {
314 NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
315 PKTIO_ENTRY_T *pe;
316 int i;
317 //find slot
318 pe = &((NETAPI_GLOBAL_T *)(pp->global))->pktios[0];
320 for(i=0;i<NETAPI_MAX_PKTIO; i++,pe++)
321 {
322 if (pe->qn.qNum == -1) continue;
323 if (!strncmp(name, pe->name, PKTIO_MAX_NAME))
324 {
325 pe->qn.qNum=-1;
326 pe->name[0]='\0';
327 return 1;
328 }
329 pe+=1;
330 }
331 return 0; //no room
332 }
335 /* get list of global pktios that have been created */
336 static inline Qmss_Queue* netapi_find_global_pktio(NETAPI_T p, char *name)
337 {
338 NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
339 PKTIO_ENTRY_T *pe;
340 int i;
341 //find slot
342 pe = &((NETAPI_GLOBAL_T *)(pp->global))->pktios[0];
344 for(i=0;i<NETAPI_MAX_PKTIO; i++,pe++)
345 {
346 if (pe->qn.qNum == -1) continue;
347 if (!strncmp(name, pe->name, PKTIO_MAX_NAME))
348 {
349 return &pe->qn;
350 }
351 pe +=1;
352 }
353 return NULL; //not found
354 }
356 /* return the nwal global instance handle */
357 static inline nwal_Handle netapi_return_nwal_instance_handle(NETAPI_T p)
358 {
360 NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
361 return ((NETAPI_GLOBAL_T *)(pp->global))->nwal_context.nwalInstHandle;
362 }
364 //utility to clear out a queue
365 void netapi_zapQ(int queueNum);
366 void netcp_cfgp_build_route(NETCP_CFG_ROUTE_T * p_route, int16_t * p_flow, Qmss_QueueHnd * p_q);
368 //database utilities
369 int netcp_cfgp_find_saslot( NETAPI_NWAL_GLOBAL_CONTEXT_T *p, int iface);
370 void netcp_cfgp_delete_sa(NETAPI_NWAL_GLOBAL_CONTEXT_T *p,int sa_slot);
371 void netcp_cfgp_insert_sa(NETAPI_NWAL_GLOBAL_CONTEXT_T *p,
372 int sa_slot, //we 'reserved it already'
373 int dir,
374 int mode,
375 void * temp1,
376 void * temp2,
377 void * handle_inflow,
378 void * handle_sideband);
379 void *netcp_cfgp_get_sa_handles( NETAPI_NWAL_GLOBAL_CONTEXT_T *p,
380 int sa_slot, void ** p_sideband);
381 void* netcp_cfgp_get_mac_handle(NETAPI_NWAL_GLOBAL_CONTEXT_T *p,int iface_no);
382 NetapiNwalTransInfo_t * netapip_GetFreeTransInfo(NETAPI_GLOBAL_T *p_global, nwal_TransID_t *pTransId);
383 void *netcp_cfgp_get_policy( NETAPI_NWAL_GLOBAL_CONTEXT_T *p,
384 int policy_slot);
385 #endif