]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/netapi.git/blob - ti/runtime/netapi/src/netapi_loc.h
NETAPI integration with ipsecmgr
[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/drv/nwal/nwal.h"
11 #include "ti/drv/nwal/nwal_util.h"
15 extern hplib_virtualAddrInfo_T netapi_VM_VirtAddr[HPLIB_MAX_MEM_POOLS];
16 extern unsigned char *netapi_VM_SaContextVaddr;
17 /***********************************************
18  *  GLOBAL AREA
19  *   short term:  this is global to process
20  *         (multi-process not supported)
21  *   long term:  this structure gets put in shared memory 
22  ***********************************************/
24 /* list of global pktio channels that have been created
25    (NETCP_TX, RX are intrinsic so won't be here) */
26 typedef struct PKTIO_ENTRY_tag
27 {
28    char name[PKTIO_MAX_NAME+1];
29    Qmss_Queue qn;         // -1 => slot is free
30 } PKTIO_ENTRY_T;
32 /* to hold an IP on an interface */
33 typedef struct NETCP_INTERFACE_IP_Tag
34 {
35         int in_use;
36         void * nwal_handle;
37         nwal_IpType  ip_type;
38         nwalIpAddr_t  ip_addr;
39         nwalIpOpt_t ip_qualifiers;
40         void * user_data;
41 } NETCP_INTERFACE_IP_T;
43 /* to hold a classifier */
44 typedef struct NETCP_INTERFACE_CLASSIFIER_Tag
45 {
46     int  in_use;
47     int  class_type;   //see netcp_cfg.h
48     void * nwal_L2_handle;
49     void * nwal_L3_handle;
50     void * nwal_L4_handle;
51     void * user_data;
52 } NETCP_INTERFACE_CLASSIFIER_T;
54 /* to hold an ipsec rx policy */
55 typedef struct NETCP_IPSEC_POLICY_Tag
56 {
57     int in_use;
58     int tunnel; //associated tunnel
59     void * nwal_handle;  //handle associated with this RX Policy
60     void * user_data; // user data associtaed with this RX Policy
61 } NETCP_IPSEC_POLICY_T;
63 /* to hold a tunnel */
64 typedef struct NETCP_IPSEC_SA_Tag
65 {
66     int in_use;
67     int inbound;  //true if inbound
68        
69     int  sa_mode;  //mode we are going to use 
70 #define NETCP_IPSEC_SA_MODE_INFLOW 0
71 #define NETCP_IPSEC_SA_MODE_SIDEBAND 1
72  
73     void * sa_handle_inflow;   //for inflow mode
74     void * sa_handle_sideband; //for sideband mode
75     int iface;     //associated interface
76     nwalTxDmPSCmdInfo_t     dmPSCmdInfo;
77     uint32_t    swInfo0;
78     uint32_t    swInfo1;
79     void*   user_data;
80 } NETCP_IPSEC_SA_T;
82 /* to hold a netcp 'interface' */
83 typedef struct NETCP_INTERFACE_Tag
84 {
85    int in_use;  /* 1 for valid */
86    int state;  /* 0=down, 1=up,  future.. */
87    void * nwal_handle;  //handle associated with this interface
88    unsigned char mac[6];  // mac address
89    unsigned int vlan;   //future
90 } NETCP_INTERFACE_T;
92 /*to keep track of netcp config transactions */
93 typedef struct {
94     nwal_Bool_t             inUse;
95     uint16_t                transType;
96 #define NETAPI_NWAL_HANDLE_TRANS_NONE             0
97 #define NETAPI_NWAL_HANDLE_TRANS_MAC              1
98 #define NETAPI_NWAL_HANDLE_TRANS_IP               2
99 #define NETAPI_NWAL_HANDLE_TRANS_PORT             3
100 #define NETAPI_NWAL_HANDLE_TRANS_SA               4
101 #define NETAPI_NWAL_HANDLE_TRANS_SA_POLICY        5
102 #define NETAPI_NWAL_HANDLE_STAT_REQUEST           6
104     uint16_t                state;
105 #define NETAPI_NWAL_HANDLE_STATE_IDLE             0
106 #define NETAPI_NWAL_HANDLE_STATE_OPEN_PENDING     1
107 #define NETAPI_NWAL_HANDLE_STATE_OPEN             2
108 #define NETAPI_NWAL_HANDLE_STATE_CLOSE_PENDING    3
109 #define NETAPI_NWAL_HANDLE_STATE_ERR                        4
110     nwal_Handle             handle;
111     uint64_t                transId;
112     NETAPI_T                netapi_handle; //the thread making the transaction
113 }  NetapiNwalTransInfo_t;
115 /* to hold user defined flows */
116 typedef struct NETCP_REGISTERED_FLOWS_Tag
118     int                 in_use;  //1=> in use
119     void*               handle; //cppi handle to resource (internal)
120     NETCP_CFG_FLOW_T    flow;
121 } NETCP_REGISTERED_FLOWS_T;
123 /******************************
124  *    nwal global context 
125  *  (shared over all instances)
126  *******************************/
127 typedef struct
129     int                             state;
130 #define NETAPI_NW_CXT_GLOB_INACTIVE               0x0
131 #define NETAPI__CXT_GLOB_ACTIVE                   0x1
132 #define NETAPI_NW_CXT_GLOB_RES_ALLOC_COMPLETE     0x3
134     nwal_Handle                     nwalInstHandle;
135     //internal heaps used just by netcp (sa<->pa). SW doesn't touch these
136     Pktlib_HeapHandle               sa2pa_heap;
137     Pktlib_HeapHandle               pa2sa_heap;
138     //stats
139     paSysStats_t                    paStats;
140     int                             numCmdPass;
141     int                             numCmdFail;
142     int                             numBogusTransIds;
143     NetapiNwalTransInfo_t           transInfos[TUNE_NETAPI_MAX_NUM_TRANS];     //transactions
144     NETCP_INTERFACE_T               interfaces[TUNE_NETAPI_MAX_NUM_MAC];        //interfaces
145     NETCP_INTERFACE_CLASSIFIER_T    classi[TUNE_NETAPI_MAX_CLASSIFIERS]; //classifiers
146     NETCP_REGISTERED_FLOWS_T        flows[TUNE_NETAPI_MAX_FLOWS]; //flows
147     NETCP_IPSEC_SA_T                tunnel[TUNE_NETAPI_MAX_SA];           //tunnels
148     NETCP_IPSEC_POLICY_T            policy[TUNE_NETAPI_MAX_POLICY];  //policies
149     NETCP_INTERFACE_IP_T            ips[TUNE_NETAPI_MAX_NUM_IP];           //ips
150 } NETAPI_NWAL_GLOBAL_CONTEXT_T;
152 /* NWAL Local context (per core/thread)  */
153 typedef struct
155 #define NETAPI_NW_CXT_LOC_INACTIVE     0x0
156 #define NETAPI_NW_CXT_LOC_ACTIVE       0x2
157     int                     state;
159     int                     numPendingCfg;
160     NETCP_CFG_STATS_CB      stats_cb;
162 /* stats */
163     int                     numL2PktsRecvd;
164     int                     numL3PktsRecvd;
165     int                     numL4PktsRecvd;
166     int                     numL4PktsSent;
167     int                     TxErrDrop;
169     /* local config */
170     nwalLocCfg_t           nwalLocCfg;
171 } NETAPI_NWAL_LOCAL_CONTEXT_T;
173 /* the global */
174 typedef struct NETAPI_GLOBAL_tag
176 #define NETAPI_MAX_PKTIO (TUNE_NETAPI_MAX_PKTIO) 
177     PKTIO_ENTRY_T                   pktios[NETAPI_MAX_PKTIO];
178     /* configuration */
179     NETAPI_CFG_T                    cfg;
180     /* nwal context */
181     NETAPI_NWAL_GLOBAL_CONTEXT_T    nwal_context;
182     NETAPI_T                        p_master;  // save p'masters handle 
183 } NETAPI_GLOBAL_T;
186 /************************************
187  * this is a per thread structure.
188  * It contains stuff local to thread
189  *  and pointer to global stuff
190  *  that is shared over all threads,
191  **************************************/
192 typedef struct NETAPI_HANDLE_Tag
194     int                         master; //master type
196     void*                       global;  /* pointer to the global area */
198     /* heap  handles */
199     Pktlib_HeapHandle           netcp_heap;    /* internal default */
200     Pktlib_HeapHandle           netcp_control_rx_heap; /* for control messages */
201     Pktlib_HeapHandle           netcp_control_tx_heap; /* for control messages */
202     Pktlib_HeapHandle           createdHeaps[TUNE_NETAPI_MAX_HEAPS];  /* created by app and registered */
204     /* pktios defined */
205     int                         n_pktios; /* #of pktios that are active for this instance */
206     void*                       pktios[NETAPI_MAX_PKTIO]; /* the list of pktios */
208     /* scheduler stuff.  unallocated if NETAPI_INCLUDE_SCHED not set */
209     void*                       p_sched;
211     /* nwal local context */
212     NETAPI_NWAL_LOCAL_CONTEXT_T nwal_local;
214     /* thread cookie */
215     void*                       cookie;  /*set by calling thread */
216 } NETAPI_HANDLE_T;
218 //internal initialization routines */
219 int netapip_initQm(int max_descriptors);
220 int netapip_initCppi(void);
221 int netapip_startQm(void);
222 int netapip_initNwal(int region2use,
223                      Pktlib_HeapIfTable * p_table,
224                      NETAPI_NWAL_GLOBAL_CONTEXT_T * p_nwal_context,
225                      NETAPI_CFG_T *p_cfg );
227 int netapip_startNwal(Pktlib_HeapHandle             pkt_heap,
228                       Pktlib_HeapHandle             cmd_heapRx,
229                       Pktlib_HeapHandle             cmd_heapTx,
230                       NETAPI_NWAL_LOCAL_CONTEXT_T*  p,
231                       NETAPI_CFG_T*                 p_cfg,
232                       NETAPI_NWAL_GLOBAL_CONTEXT_T* p_nwal_glob_context );
234 int netapip_initTimer(void);
235 int netapip_qmSetupMemRegion(unsigned int          numDesc,
236                              unsigned int          descSize,
237                              unsigned int*         pDescMemBase,
238                              int                   memRegion);
240 #define NETAPI_GLOBAL_REGION TUNE_NETAPI_QM_GLOBAL_REGION 
241 #define NETAPI_LOCAL_REGION ((NETAPI_GLOBAL_REGION)+1) 
244 //nwal callbacks
245 void netapip_pktioNWALRxPktCallback(uint32_t          appCookie,
246                                     uint16_t          numPkts,
247                                     nwalRxPktInfo_t*  pPktInfo,
248                                     uint64_t          timestamp,
249                                     nwal_Bool_t*      pFreePkt);
251 void netapip_netcpCfgNWALCmdCallBack (nwal_AppId        appHandle,
252                                       uint16_t          trans_id,
253                                       nwal_RetValue     ret);
255 void netapip_netcpCfgNWALCmdPaStatsReply (nwal_AppId        appHandle,
256                                           nwal_TransID_t    trans_id,
257                                           paSysStats_t      *stats);
259 void netapip_pktioNWALSBPktCallback     (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  netapip_addGlobalPktio(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*  netapip_findGlobalPktio(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 netapip_returnNwalInstanceHandle(NETAPI_T p)
358 NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
359 return ((NETAPI_GLOBAL_T *)(pp->global))->nwal_context.nwalInstHandle;
364 //utility to clear out a queue
365 void netapip_zapQ(int queueNum);
366 void netapip_netcpCfgBuildRoute(NETCP_CFG_ROUTE_T * p_route, int16_t * p_flow,  Qmss_QueueHnd * p_q);
368 //database utilities
369 void netapip_netcpCfgDeleteSa(NETAPI_NWAL_GLOBAL_CONTEXT_T *p,int sa_slot);
370 void netapip_netcpCfgInsertSa(NETAPI_NWAL_GLOBAL_CONTEXT_T *p,
371                           int sa_slot,  //we 'reserved it already'
372                           int dir,
373                           int mode,
374                           void * temp1,
375                           void * temp2,
376                           void * handle_inflow,
377                           void * handle_sideband,
378                           nwalTxDmPSCmdInfo_t *dmPSCmdInfo;);
379 void *netapip_netcpCfgGetSaHandles( NETAPI_NWAL_GLOBAL_CONTEXT_T *p,
380                           int sa_slot, void ** p_sideband);
381 void* netapip_netcpCfgGetMacHandle(NETAPI_NWAL_GLOBAL_CONTEXT_T *p,int iface_no);
382 NetapiNwalTransInfo_t *  netapip_getFreeTransInfo(NETAPI_GLOBAL_T *p_global, nwal_TransID_t *pTransId);
383 void netapip_freeTransInfo(NetapiNwalTransInfo_t* pTransInfo);
384 void *netapip_netcpCfgGetPolicy( NETAPI_NWAL_GLOBAL_CONTEXT_T *p,
385                           int policy_slot);
386 nwalTxDmPSCmdInfo_t* netapip_netcpCfgGetSaSBInfo(NETAPI_NWAL_GLOBAL_CONTEXT_T *p,
387                                       NETCP_CFG_SA_T    sa_app_id);
388 int netapip_netcpCfgGetSaInflowInfo(NETAPI_NWAL_GLOBAL_CONTEXT_T *p,
389                                       NETCP_CFG_SA_T    sa_app_id,
390                                       uint32_t *swInfo0,
391                                       uint32_t *swInfo1);
393 int netapip_systemInit(NETAPI_HANDLE_T *);
394 void netapip_cleanupAtStart(void);
395 #endif