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