]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/netapi.git/blob - ti/runtime/netapi/src/netapi_loc.h
Merge branch 'benchmark'
[keystone-rtos/netapi.git] / ti / runtime / netapi / src / netapi_loc.h
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
60        
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
64  
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
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
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
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
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
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_heap; /* for control messages */
193 Pktlib_HeapHandle  createdHeaps[TUNE_NETAPI_MAX_HEAPS];  /* created by app and registered */
195 /* pktios defined */
196 int n_pktios; /* #of pktios that are active for this instance */
197 void*  pktios[NETAPI_MAX_PKTIO]; /* the list of pktios */
199 /* scheduler stuff.  unallocated if NETAPI_INCLUDE_SCHED not set */
200 void * p_sched;
202 /* nwal local context */
203 NETAPI_NWAL_LOCAL_CONTEXT_T nwal_local;
205 /* security stuff */
207 /* timer stuff */
209 /* thread cookie */
210 void * cookie;  /*set by calling thread */
212 } NETAPI_HANDLE_T;
215 //internal initialization routines */
216 int netapi_init_qm(int max_descriptors);
217 int netapi_init_cppi(void);
218 int netapi_init_cpsw(void);
219 int netapi_start_qm(void);
220 int netapi_init_nwal(
221      int region2use,
222      Pktlib_HeapIfTable * p_table,
223      NETAPI_NWAL_GLOBAL_CONTEXT_T * p_nwal_context,
224      NETAPI_CFG_T *p_cfg );
225 int netapi_start_nwal(Pktlib_HeapHandle pkt_heap,
226                     Pktlib_HeapHandle cmd_heap,
227                      NETAPI_NWAL_LOCAL_CONTEXT_T *p ,
228                      NETAPI_CFG_T *p_cfg,
229                      NETAPI_NWAL_GLOBAL_CONTEXT_T * p_nwal_glob_context );
231 int netapi_init_timer(void);
232 int netapi_qm_setup_mem_region(
233                       unsigned int          numDesc,
234                       unsigned int          descSize,
235                       unsigned int*         pDescMemBase,
236                       int                   memRegion);
237 //for above
238 #define NETAPI_GLOBAL_REGION TUNE_NETAPI_QM_GLOBAL_REGION 
239 #define NETAPI_LOCAL_REGION ((NETAPI_GLOBAL_REGION)+1) 
241 int netapi_VM_memory_setup(void);
242 void netapi_VM_memory_teardown(void);
244 //nwal callbacks
245 void netapi_NWALRxPktCallback     (uint32_t            appCookie,
246                                 uint16_t             numPkts,
247                                 nwalRxPktInfo_t*    pPktInfo,
248                                 uint64_t            timestamp,
249                                 nwal_Bool_t*        pFreePkt);
251 void netapi_NWALCmdCallBack (nwal_AppId        appHandle,
252                           uint16_t            trans_id,
253                           nwal_RetValue     ret);
255 void netapi_NWALCmdPaStatsReply (nwal_AppId        appHandle,
256                               nwal_TransID_t    trans_id,
257                               paSysStats_t      *stats);
259 void netapi_NWALSBPktCallback     (uint32_t            appCookie,
260                                 uint16_t             numPkts,
261                                 nwalDmRxPayloadInfo_t*  pDmRxPktInfo,
262                                 nwal_Bool_t*        pFreePkt);
265 //***********************************
266 //internal utilities
267 //*************************************
269 //return the list of pktios for this instance
270 static inline void ** netapi_get_pktio_list(NETAPI_T p)
272 NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
273 return &pp->pktios[0];
276 //get scheduler block handle
277 static inline void * netapi_get_scheduler(NETAPI_T p)
279 NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
280 return pp->p_sched;
283 /* return pointer to global area */
284 NETAPI_GLOBAL_T * netapi_get_global(void);
286 //add a pktio name (and queue) to global list
287 static inline int  netapi_add_global_pktio(NETAPI_T p, char *name, Qmss_Queue * qn)
289 NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
290 PKTIO_ENTRY_T *pe;
291 int i;
292 //find a free slot
293 pe = &((NETAPI_GLOBAL_T *)(pp->global))->pktios[0];
295 for(i=0;i<NETAPI_MAX_PKTIO; i++,pe++)
296  {
297    if (pe->qn.qNum ==  -1)
298    {
299      pe->qn.qNum=qn->qNum;
300      pe->qn.qMgr=qn->qMgr;
301      strncpy(pe->name, name, PKTIO_MAX_NAME);
302      return 1;
303    }
304    pe+=1;
305  }
306  return 0;  //no room
309 //delete a pktio name (and queue) to global list
310 static inline int  netapi_del_global_pktio(NETAPI_T p, char *name)
312 NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
313 PKTIO_ENTRY_T *pe;
314 int i;
315 //find slot
316 pe = &((NETAPI_GLOBAL_T *)(pp->global))->pktios[0];
318 for(i=0;i<NETAPI_MAX_PKTIO; i++,pe++)
319  {
320    if (pe->qn.qNum == -1) continue;
321    if (!strncmp(name, pe->name, PKTIO_MAX_NAME))
322    {
323      pe->qn.qNum=-1;
324      pe->name[0]='\0';
325      return 1;
326    }
327    pe+=1;
328  }
329  return 0;  //no room
333 /* get list of global pktios that have been created */
334 static inline  Qmss_Queue*  netapi_find_global_pktio(NETAPI_T p, char *name)
336 NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
337 PKTIO_ENTRY_T *pe;
338 int i;
339 //find slot
340 pe = &((NETAPI_GLOBAL_T *)(pp->global))->pktios[0];
342 for(i=0;i<NETAPI_MAX_PKTIO; i++,pe++)
343  {
344    if (pe->qn.qNum  == -1) continue;
345    if (!strncmp(name, pe->name, PKTIO_MAX_NAME))
346    {
347      return &pe->qn;
348    }
349    pe +=1;
350  }
351  return NULL;  //not found
354 /* return the nwal global instance handle */
355 static inline nwal_Handle netapi_return_nwal_instance_handle(NETAPI_T p)
358 NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
359 return ((NETAPI_GLOBAL_T *)(pp->global))->nwal_context.nwalInstHandle;
362 //utility to clear out a queue
363 void netapi_zapQ(int queueNum);
364 void netcp_cfgp_build_route(NETCP_CFG_ROUTE_T * p_route, int16_t * p_flow,  Qmss_QueueHnd * p_q);
366 //database utilities
367 int netcp_cfgp_find_saslot( NETAPI_NWAL_GLOBAL_CONTEXT_T *p, int iface);
368 void netcp_cfgp_delete_sa(NETAPI_NWAL_GLOBAL_CONTEXT_T *p,int sa_slot);
369 void netcp_cfgp_insert_sa(NETAPI_NWAL_GLOBAL_CONTEXT_T *p,
370                           int sa_slot,  //we 'reserved it already'
371                           int dir,
372                           int mode,
373                           void * temp1,
374                           void * temp2,
375                           void * handle_inflow,
376                           void * handle_sideband);
377 void *netcp_cfgp_get_sa_handles( NETAPI_NWAL_GLOBAL_CONTEXT_T *p,
378                           int sa_slot, void ** p_sideband);
379 void* netcp_cfgp_get_mac_handle(NETAPI_NWAL_GLOBAL_CONTEXT_T *p,int iface_no);
380 NetapiNwalTransInfo_t *  netapip_GetFreeTransInfo(NETAPI_GLOBAL_T *p_global, nwal_TransID_t *pTransId);
381 void *netcp_cfgp_get_policy( NETAPI_NWAL_GLOBAL_CONTEXT_T *p,
382                           int policy_slot);
383 #endif