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 netcp 'interface' */
38 typedef struct NETCP_INTERFACE_Tag
39 {
40 int in_use; /* 1 for valid */
41 int state; /* 0=down, 1=up, future.. */
42 void * nwal_handle; //handle associated with this interface
43 unsigned char mac[6]; // mac address
44 unsigned int vlan; //future
45 NETCP_INTERFACE_IP_T ips[TUNE_NETAPI_MAX_IP_PER_INTERFACE];
46 } NETCP_INTERFACE_T;
48 /*to keep track of netcp config transactions */
49 typedef struct {
50 nwal_Bool_t inUse;
51 uint16_t transType;
52 #define NETAPI_NWAL_HANDLE_TRANS_NONE 0
53 #define NETAPI_NWAL_HANDLE_TRANS_MAC 1
54 #define NETAPI_NWAL_HANDLE_TRANS_IP 2
55 #define NETAPI_NWAL_HANDLE_TRANS_PORT 3
56 #define NETAPI_NWAL_HANDLE_TRANS_SEC_ASSOC 4
57 #define NETAPI_NWAL_HANDLE_TRANS_SEC_POLICY 5
58 #define NETAPI_NWAL_HANDLE_STAT_REQUEST 6
60 uint16_t state;
61 #define NETAPI_NWAL_HANDLE_STATE_IDLE 0
62 #define NETAPI_NWAL_HANDLE_STATE_OPEN_PENDING 1
63 #define NETAPI_NWAL_HANDLE_STATE_OPEN 2
64 #define NETAPI_NWAL_HANDLE_STATE_CLOSE_PENDING 3
65 nwal_Handle handle;
66 uint64_t transId;
67 NETAPI_T netapi_handle; //the thread making the transaction
68 } NetapiNwalTransInfo_t;
70 /* nwal global context */
71 typedef struct
72 {
73 int state;
74 #define NETAPI_NW_CXT_GLOB_INACTIVE 0x0
75 #define NETAPI__CXT_GLOB_ACTIVE 0x1
76 #define NETAPI_NW_CXT_GLOB_RES_ALLOC_COMPLETE 0x3
78 nwal_Handle nwalInstHandle;
79 paSysStats_t paStats;
80 int numCmdPass;
81 int numCmdFail;
82 int numBogusTransIds;
83 NetapiNwalTransInfo_t transInfos[TUNE_NETAPI_MAX_NUM_TRANS];
84 NETCP_INTERFACE_T interfaces[TUNE_NETAPI_MAX_INTERFACES];
86 } NETAPI_NWAL_GLOBAL_CONTEXT_T;
88 /* NWAL Local context (per core/thread) */
89 typedef struct
90 {
91 //void * nwalLocInstance;
92 #define NETAPI_NW_CXT_LOC_INACTIVE 0x0
93 #define NETAPI_NW_CXT_LOC_ACTIVE 0x2
94 int state;
96 int numPendingCfg;
97 NETCP_CFG_STATS_CB stats_cb;
99 /* stats */
100 int numL2PktsRecvd;
101 int numL3PktsRecvd;
102 int numL4PktsRecvd;
103 int numL4PktsSent;
104 int TxErrDrop;
106 /* local config */
107 nwalLocCfg_t nwalLocCfg;
108 } NETAPI_NWAL_LOCAL_CONTEXT_T;
110 /* the global */
111 typedef struct NETAPI_GLOBAL_tag
112 {
113 #define NETAPI_MAX_PKTIO (TUNE_NETAPI_MAX_PKTIO)
114 PKTIO_ENTRY_T pktios[NETAPI_MAX_PKTIO];
116 /* pktlib heap */
118 /* global timers */
120 /* nwal context */
121 NETAPI_NWAL_GLOBAL_CONTEXT_T nwal_context;
123 } NETAPI_GLOBAL_T;
126 /************************************
127 * this is a per thread structure.
128 * It contains stuff local to thread
129 * and pointer to global stuff
130 * that is shared over all threads,
131 **************************************/
132 typedef struct NETAPI_HANDLE_Tag
133 {
134 int master; //master type
136 void * global; /* pointer to the global area */
138 /* heap handle */
139 Pktlib_HeapHandle netcp_heap;
140 Pktlib_HeapHandle netcp_control_heap;
142 /* pktios defined */
143 int n_pktios; /* #of pktios that are active for this instance */
144 void* pktios[NETAPI_MAX_PKTIO]; /* the list of pktios */
146 /* scheduler stuff. unallocated if NETAPI_INCLUDE_SCHED not set */
147 void * p_sched;
149 /* nwal local context */
150 NETAPI_NWAL_LOCAL_CONTEXT_T nwal_local;
152 /* security stuff */
154 /* timer stuff */
157 /* default flow*/
158 NETCP_CFG_FLOW_HANDLE_T def_flow; //uses our heap above
160 /* default route */
161 NETCP_CFG_ROUTE_HANDLE_T def_route; //uses our rx channel above
163 /* thread cookie */
164 void * cookie; /*set by calling thread */
166 } NETAPI_HANDLE_T;
169 //internal initialization routines */
170 int netapi_init_qm(void);
171 int netapi_init_cppi(void);
172 int netapi_init_cpsw(void);
173 int netapi_start_qm(void);
174 int netapi_init_nwal(
175 int region2use,
176 Pktlib_HeapIfTable * p_table,
177 NETAPI_NWAL_GLOBAL_CONTEXT_T * p_nwal_context );
178 int netapi_start_nwal(Pktlib_HeapHandle pkt_heap,
179 Pktlib_HeapHandle cmd_heap,
180 NETAPI_NWAL_LOCAL_CONTEXT_T *p ,
181 NETAPI_NWAL_GLOBAL_CONTEXT_T * p_nwal_glob_context );
183 int netapi_init_timer(void);
184 int netapi_qm_setup_mem_region(
185 unsigned int numDesc,
186 unsigned int descSize,
187 unsigned int* pDescMemBase,
188 int memRegion);
189 //for above
190 #define NETAPI_GLOBAL_REGION 0
191 #define NETAPI_LOCAL_REGION 1
194 //nwal callbacks
195 void netapi_NWALRxPktCallback (uint32_t appCookie,
196 uint8_t numPkts,
197 nwalRxPktInfo_t* pPktInfo,
198 uint64_t timestamp,
199 nwal_Bool_t* pFreePkt);
201 void netapi_NWALCmdCallBack (nwal_AppId appHandle,
202 uint16_t trans_id,
203 nwal_RetValue ret);
205 void netapi_NWALCmdPaStatsReply (nwal_AppId appHandle,
206 nwal_TransID_t trans_id,
207 paSysStats_t *stats);
209 //***********************************
210 //internal utilities
211 //*************************************
213 //return the list of pktios for this instance
214 static inline void * netapi_get_pktio_list(NETAPI_T p)
215 {
216 NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
217 return &pp->pktios[0];
218 }
220 //get scheduler block handle
221 static inline void * netapi_get_scheduler(NETAPI_T p)
222 {
223 NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
224 return pp->p_sched;
225 }
227 /* return pointer to global area */
228 NETAPI_GLOBAL_T * netapi_get_global(void);
230 //add a pktio name (and queue) to global list
231 static inline int netapi_add_global_pktio(NETAPI_T p, char *name, Qmss_Queue * qn)
232 {
233 NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
234 PKTIO_ENTRY_T *pe;
235 int i;
236 //find a free slot
237 pe = &((NETAPI_GLOBAL_T *)(pp->global))->pktios[0];
239 for(i=0;i<NETAPI_MAX_PKTIO; i++,pe++)
240 {
241 if (pe->qn.qNum == -1)
242 {
243 pe->qn.qNum=qn->qNum;
244 pe->qn.qMgr=qn->qMgr;
245 strncpy(pe->name, name, PKTIO_MAX_NAME);
246 return 1;
247 }
248 pe+=1;
249 }
250 return 0; //no room
251 }
253 //delete a pktio name (and queue) to global list
254 static inline int netapi_del_global_pktio(NETAPI_T p, char *name)
255 {
256 NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
257 PKTIO_ENTRY_T *pe;
258 int i;
259 //find slot
260 pe = &((NETAPI_GLOBAL_T *)(pp->global))->pktios[0];
262 for(i=0;i<NETAPI_MAX_PKTIO; i++,pe++)
263 {
264 if (pe->qn.qNum == -1) continue;
265 if (!strncmp(name, pe->name, PKTIO_MAX_NAME))
266 {
267 pe->qn.qNum=-1;
268 pe->name[0]='\0';
269 return 1;
270 }
271 pe+=1;
272 }
273 return 0; //no room
274 }
277 /* get list of global pktios that have been created */
278 static inline Qmss_Queue* netapi_find_global_pktio(NETAPI_T p, char *name)
279 {
280 NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
281 PKTIO_ENTRY_T *pe;
282 int i;
283 //find slot
284 pe = &((NETAPI_GLOBAL_T *)(pp->global))->pktios[0];
286 for(i=0;i<NETAPI_MAX_PKTIO; i++,pe++)
287 {
288 if (pe->qn.qNum == -1) continue;
289 if (!strncmp(name, pe->name, PKTIO_MAX_NAME))
290 {
291 return &pe->qn;
292 }
293 pe +=1;
294 }
295 return NULL; //not found
296 }
298 /* return the nwal global instance handle */
299 static inline nwal_Handle netapi_return_nwal_instance_handle(NETAPI_T p)
300 {
302 NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
303 return ((NETAPI_GLOBAL_T *)(pp->global))->nwal_context.nwalInstHandle;
304 }
306 #endif