]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/netapi.git/blob - ti/runtime/netapi/src/netapi_loc.h
This commit adds the following:
[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"
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 
126  *  (shared over all 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;
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     int                             numCmdPass;
142     int                             numCmdFail;
143     int                             numBogusTransIds;
144     NetapiNwalTransInfo_t           transInfos[TUNE_NETAPI_MAX_NUM_TRANS];     //transactions
145     NETCP_INTERFACE_T               interfaces[TUNE_NETAPI_MAX_NUM_MAC];        //interfaces
146     NETCP_INTERFACE_CLASSIFIER_T    classi[TUNE_NETAPI_MAX_CLASSIFIERS]; //classifiers
147     NETCP_REGISTERED_FLOWS_T        flows[TUNE_NETAPI_MAX_FLOWS]; //flows
148     NETCP_IPSEC_SA_T                tunnel[TUNE_NETAPI_MAX_SA];           //tunnels
149     NETCP_IPSEC_POLICY_T            policy[TUNE_NETAPI_MAX_POLICY];  //policies
150     NETCP_INTERFACE_IP_T            ips[TUNE_NETAPI_MAX_NUM_IP];           //ips
151 } NETAPI_NWAL_GLOBAL_CONTEXT_T;
153 /* NWAL Local context (per core/thread)  */
154 typedef struct
156 #define NETAPI_NW_CXT_LOC_INACTIVE     0x0
157 #define NETAPI_NW_CXT_LOC_ACTIVE       0x2
158     int                     state;
160     int                     numPendingCfg;
161     NETCP_CFG_STATS_CB      stats_cb;
163 /* stats */
164     int                     numL2PktsRecvd;
165     int                     numL3PktsRecvd;
166     int                     numL4PktsRecvd;
167     int                     numL4PktsSent;
168     int                     TxErrDrop;
170     /* local config */
171     nwalLocCfg_t           nwalLocCfg;
172 } NETAPI_NWAL_LOCAL_CONTEXT_T;
174 /* the global */
175 typedef struct NETAPI_GLOBAL_tag
177 #define NETAPI_MAX_PKTIO (TUNE_NETAPI_MAX_PKTIO) 
178     PKTIO_ENTRY_T                   pktios[NETAPI_MAX_PKTIO];
179     /* configuration */
180     NETAPI_CFG_T                    cfg;
181     /* nwal context */
182     NETAPI_NWAL_GLOBAL_CONTEXT_T    nwal_context;
183     NETAPI_T                        p_master;  // save p'masters handle 
184 } NETAPI_GLOBAL_T;
187 /************************************
188  * this is a per thread structure.
189  * It contains stuff local to thread
190  *  and pointer to global stuff
191  *  that is shared over all threads,
192  **************************************/
193 typedef struct NETAPI_HANDLE_Tag
195     int                         master; //master type
197     void*                       global;  /* pointer to the global area */
199     /* heap  handles */
200     Pktlib_HeapHandle           netcp_heap;    /* internal default */
201     Pktlib_HeapHandle           netcp_control_rx_heap; /* for control messages */
202     Pktlib_HeapHandle           netcp_control_tx_heap; /* for control messages */
203     Pktlib_HeapHandle           createdHeaps[TUNE_NETAPI_MAX_HEAPS];  /* created by app and registered */
205     /* pktios defined */
206     int                         n_pktios; /* #of pktios that are active for this instance */
207     void*                       pktios[NETAPI_MAX_PKTIO]; /* the list of pktios */
209     /* scheduler stuff.  unallocated if NETAPI_INCLUDE_SCHED not set */
210     void*                       p_sched;
212     /* nwal local context */
213     NETAPI_NWAL_LOCAL_CONTEXT_T nwal_local;
215     /* thread cookie */
216     void*                       cookie;  /*set by calling thread */
217 } NETAPI_HANDLE_T;
219 typedef struct NETAPI_SHM_Tag
221     NETAPI_GLOBAL_T     netapi_global;
222     hplib_spinLock_T    netapi_pktio_lock;
223     hplib_spinLock_T    netapi_netcp_cfg_lock;
224     hplib_spinLock_T    netapi_util_lock;
225 } NETAPI_SHM_T;
227 //internal initialization routines */
228 int netapip_initQm(int max_descriptors);
229 int netapip_initCppi(void);
230 int netapip_startQm(void);
231 int netapip_initNwal(int region2use,
232                      Pktlib_HeapIfTable * p_table,
233                      NETAPI_NWAL_GLOBAL_CONTEXT_T * p_nwal_context,
234                      NETAPI_CFG_T *p_cfg );
236 int netapip_startNwal(Pktlib_HeapHandle             pkt_heap,
237                       Pktlib_HeapHandle             cmd_heapRx,
238                       Pktlib_HeapHandle             cmd_heapTx,
239                       NETAPI_NWAL_LOCAL_CONTEXT_T*  p,
240                       NETAPI_CFG_T*                 p_cfg,
241                       NETAPI_NWAL_GLOBAL_CONTEXT_T* p_nwal_glob_context );
243 int netapip_initTimer(void);
244 int netapip_qmSetupMemRegion(unsigned int          numDesc,
245                              unsigned int          descSize,
246                              unsigned int*         pDescMemBase,
247                              int                   memRegion);
249 #define NETAPI_GLOBAL_REGION TUNE_NETAPI_QM_GLOBAL_REGION 
250 #define NETAPI_LOCAL_REGION ((NETAPI_GLOBAL_REGION)+1) 
253 //nwal callbacks
254 void netapip_pktioNWALRxPktCallback(uint32_t          appCookie,
255                                     uint16_t          numPkts,
256                                     nwalRxPktInfo_t*  pPktInfo,
257                                     uint64_t          timestamp,
258                                     nwal_Bool_t*      pFreePkt);
260 void netapip_netcpCfgNWALCmdCallBack (nwal_AppId        appHandle,
261                                       uint16_t          trans_id,
262                                       nwal_RetValue     ret);
264 void netapip_netcpCfgNWALCmdPaStatsReply (nwal_AppId        appHandle,
265                                           nwal_TransID_t    trans_id,
266                                           paSysStats_t      *stats);
268 void netapip_pktioNWALSBPktCallback     (uint32_t                   appCookie,
269                                          uint16_t                   numPkts,
270                                          nwalDmRxPayloadInfo_t*     pDmRxPktInfo,
271                                         nwal_Bool_t*                pFreePkt);
274 //***********************************
275 //internal utilities
276 //*************************************
278 //return the list of pktios for this instance
279 static inline void ** netapi_get_pktio_list(NETAPI_T p)
281 NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
282 return &pp->pktios[0];
285 //get scheduler block handle
286 static inline void * netapi_get_scheduler(NETAPI_T p)
288     NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
289     return pp->p_sched;
292 /* return pointer to global area */
293 NETAPI_GLOBAL_T * netapi_get_global(void);
295 //add a pktio name (and queue) to global list
296 static inline int  netapip_addGlobalPktio(NETAPI_T p, char *name, Qmss_Queue * qn)
298 NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
299 PKTIO_ENTRY_T *pe;
300 int i;
301 //find a free slot
302 pe = &((NETAPI_GLOBAL_T *)(pp->global))->pktios[0];
304 for(i=0;i<NETAPI_MAX_PKTIO; i++,pe++)
305  {
306    if (pe->qn.qNum ==  -1)
307    {
308      pe->qn.qNum=qn->qNum;
309      pe->qn.qMgr=qn->qMgr;
310      strncpy(pe->name, name, PKTIO_MAX_NAME);
311      return 1;
312    }
313    pe+=1;
314  }
315  return 0;  //no room
318 //delete a pktio name (and queue) to global list
319 static inline int  netapi_del_global_pktio(NETAPI_T p, char *name)
321 NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
322 PKTIO_ENTRY_T *pe;
323 int i;
324 //find slot
325 pe = &((NETAPI_GLOBAL_T *)(pp->global))->pktios[0];
327 for(i=0;i<NETAPI_MAX_PKTIO; i++,pe++)
328  {
329    if (pe->qn.qNum == -1) continue;
330    if (!strncmp(name, pe->name, PKTIO_MAX_NAME))
331    {
332      pe->qn.qNum=-1;
333      pe->name[0]='\0';
334      return 1;
335    }
336    pe+=1;
337  }
338  return 0;  //no room
342 /* get list of global pktios that have been created */
343 static inline  Qmss_Queue*  netapip_findGlobalPktio(NETAPI_T p, char *name)
345 NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
346 PKTIO_ENTRY_T *pe;
347 int i;
348 //find slot
349 pe = &((NETAPI_GLOBAL_T *)(pp->global))->pktios[0];
351 for(i=0;i<NETAPI_MAX_PKTIO; i++,pe++)
352  {
353    if (pe->qn.qNum  == -1) continue;
354    if (!strncmp(name, pe->name, PKTIO_MAX_NAME))
355    {
356      return &pe->qn;
357    }
358    pe +=1;
359  }
360  return NULL;  //not found
363 /* return the nwal global instance handle */
364 static inline nwal_Handle netapip_returnNwalInstanceHandle(NETAPI_T p)
367 NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
368 return ((NETAPI_GLOBAL_T *)(pp->global))->nwal_context.nwalInstHandle;
373 //utility to clear out a queue
374 void netapip_zapQ(int queueNum);
375 void netapip_netcpCfgBuildRoute(NETCP_CFG_ROUTE_T * p_route, int16_t * p_flow,  Qmss_QueueHnd * p_q);
377 //database utilities
378 void netapip_netcpCfgDeleteSa(NETAPI_NWAL_GLOBAL_CONTEXT_T *p,int sa_slot);
379 void netapip_netcpCfgInsertSa(NETAPI_NWAL_GLOBAL_CONTEXT_T *p,
380                           int sa_slot,  //we 'reserved it already'
381                           int dir,
382                           int mode,
383                           void * temp1,
384                           void * temp2,
385                           void * handle_inflow,
386                           void * handle_sideband,
387                           nwalTxDmPSCmdInfo_t *dmPSCmdInfo;);
388 void *netapip_netcpCfgGetSaHandles( NETAPI_NWAL_GLOBAL_CONTEXT_T *p,
389                           int sa_slot, void ** p_sideband);
390 void* netapip_netcpCfgGetMacHandle(NETAPI_NWAL_GLOBAL_CONTEXT_T *p,int iface_no);
391 NetapiNwalTransInfo_t *  netapip_getFreeTransInfo(NETAPI_GLOBAL_T *p_global, nwal_TransID_t *pTransId);
392 void netapip_freeTransInfo(NetapiNwalTransInfo_t* pTransInfo);
393 void *netapip_netcpCfgGetPolicy( NETAPI_NWAL_GLOBAL_CONTEXT_T *p,
394                           int policy_slot);
395 nwalTxDmPSCmdInfo_t* netapip_netcpCfgGetSaSBInfo(NETAPI_NWAL_GLOBAL_CONTEXT_T *p,
396                                       NETCP_CFG_SA_T    sa_app_id);
397 int netapip_netcpCfgGetSaInflowInfo(NETAPI_NWAL_GLOBAL_CONTEXT_T *p,
398                                       NETCP_CFG_SA_T    sa_app_id,
399                                       uint32_t *swInfo0,
400                                       uint32_t *swInfo1);
402 int netapip_systemInit(NETAPI_HANDLE_T *);
403 void netapip_cleanupAtStart(void);
404 #endif