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