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