Fix for SDOCM00114893
[keystone-rtos/netapi.git] / ti / runtime / netapi / src / netapi_init.c
1 /****************************************************************************
2 *  FILE:  netapi_init.c
3 *  Global, Private initialization and cleanup routines and defines of NETAPI
4  *
5  * DESCRIPTION: Functions to initialize and cleanup framework resources 
6  *              for running NETAPI
7  *
8  * REVISION HISTORY:
9  *
10  *  Copyright (c) Texas Instruments Incorporated 2013
11  * 
12  *  Redistribution and use in source and binary forms, with or without 
13  *  modification, are permitted provided that the following conditions 
14  *  are met:
15  *
16  *    Redistributions of source code must retain the above copyright 
17  *    notice, this list of conditions and the following disclaimer.
18  *
19  *    Redistributions in binary form must reproduce the above copyright
20  *    notice, this list of conditions and the following disclaimer in the 
21  *    documentation and/or other materials provided with the   
22  *    distribution.
23  *
24  *    Neither the name of Texas Instruments Incorporated nor the names of
25  *    its contributors may be used to endorse or promote products derived
26  *    from this software without specific prior written permission.
27  *
28  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
29  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
30  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
32  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
33  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
34  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
37  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
38  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  *
40  ***************************************************************************/
42 #include "netapi.h"
43 #include "netapi_loc.h"
44 #include <sys/types.h>
45 #include <sys/stat.h>
46 #include <fcntl.h>
47 #include <sys/mman.h>
48 #include <errno.h>
49 #include <unistd.h>
51 #include "ti/drv/nwal/nwal.h"
53 /* CSL RL includes */
54 #include <ti/csl/cslr_device.h>
55 #include <ti/csl/cslr_qm_config.h>
56 #include <ti/csl/cslr_qm_descriptor_region_config.h>
57 #include <ti/csl/cslr_qm_queue_management.h>
58 #include <ti/csl/cslr_qm_queue_status_config.h>
59 #include <ti/csl/cslr_qm_intd.h>
60 #include <ti/csl/cslr_pdsp.h>
61 #include <ti/csl/csl_qm_queue.h>
62 #include <ti/csl/cslr_cppidma_global_config.h>
63 #include <ti/csl/cslr_cppidma_rx_channel_config.h>
64 #include <ti/csl/cslr_cppidma_rx_flow_config.h>
65 #include <ti/csl/cslr_cppidma_tx_channel_config.h>
66 #include <ti/csl/cslr_cppidma_tx_scheduler_config.h>
67 #include <ti/csl/csl_cppi.h>
68 #include <ti/csl/csl_pscAux.h>
69 #include <ti/csl/csl_semAux.h>
70 #include <ti/csl/csl_cacheAux.h>
71 #include <ti/csl/csl_xmcAux.h>
72 #include <ti/drv/qmss/qmss_qm.h>
75 /* pointer to NWAL local context memory block used by NWAL for local 
76    context intance*/
77 void* pNwalLocCtxMem = NULL;
78 extern void *pRmClientHandle;
80 nwal_Handle gPNwalInstHandle = NULL;
83 extern NETAPI_SHM_T* pnetapiShm;
84 /* Global variablesto hold virtual address of various subsystems */
85 extern hplib_virtualAddrInfo_T netapi_VM_VirtAddr[];
87 /* Global variables which needs to be populated with memory pool attributes
88    which is passed to HPLIB for memory pool initialization*/
89 extern hplib_memPoolAttr_T netapi_VM_MempoolAttr[];
90 extern unsigned char *netapi_VM_QMemLocalDescRam;
91 extern unsigned char *netapi_VM_QMemGlobalDescRam;
92 extern unsigned char *netapi_VM_SaContextVaddr;
94 extern Pktlib_HeapIfTable  netapi_pktlib_ifTable;
95 extern NETAPI_PROC_GLOBAL_T netapi_proc_global;
96 extern NETAPI_HANDLE_T * netapi_proc_master;
99 /* TODO verify: */
100 #define CACHE_LINESZ    64
103 #define ALIGN(x)    __attribute__((aligned (x)))
105 /*****************************************************************************
106  * Global Resources shared by all Cores
107  *****************************************************************************/
108 uint8_t *QMemGlobDescRam = 0;
109 uint8_t *cppiMemPaSaLinkBuf = 0;
110 uint8_t *cppiMemSaPaLinkBuf = 0;
114 #if 0
115 /*****************************************************************************
116  * Local Resource allocated at each Core
117  *****************************************************************************/
118 /* Descriptors in global shared */
119 uint8_t *QMemLocDescRam = NULL;
120 uint8_t *cppiMemRxPktLinkBuf = NULL;
121 uint8_t *cppiMemTxPktLinkBuf = NULL;
122 uint8_t *cppiMemRxCtlLinkBuf = NULL;
123 uint8_t *cppiMemTxCtlLinkBuf = NULL;
125 #endif
129 NETCP_CFG_GLOB_DEVICE_PARAMS_T   *p_netapi_device_cfg_local;
130 Qmss_MemRegInfo   memInfo;
133 /********************************************************************
134  * FUNCTION PURPOSE:  Internal NETAPI function to setup the QM memory region
135  ********************************************************************
136  * DESCRIPTION:  Internal NETAPI function to setup the QM memory region,
137  *               once per SOC
138  ********************************************************************/
139 int netapip_qmSetupMemRegion(
140                       uint32_t          numDesc,
141                       uint32_t          descSize,
142                       uint32_t*         pDescMemBase,
143                       int               memRegion,
144                       int               start_index)
146     //Qmss_MemRegInfo   memInfo;
147     int result;
149     memset(&memInfo,0,sizeof(Qmss_MemRegInfo));
150     memInfo.descBase       = pDescMemBase;
151     memInfo.descSize       = descSize;
152     memInfo.descNum        = numDesc;
153     memInfo.manageDescFlag = Qmss_ManageDesc_MANAGE_DESCRIPTOR;
155     if (pRmClientHandle)
156     {
157         memInfo.memRegion = -1;
158         memInfo.startIndex = QMSS_START_INDEX_NOT_SPECIFIED;
159     }
160     else
161     {
162         memInfo.memRegion = memRegion;
163         memInfo.startIndex = start_index;
164     }
166     memset (pDescMemBase, 0, (descSize * numDesc));
168     result = Qmss_insertMemoryRegion (&memInfo);
170     if (result < QMSS_SOK)  
171     {
172         return (-1);
173     }
174     netapi_proc_master->memRegion = memInfo.memRegion;
175     return 1;
178 /********************************************************************
179  * FUNCTION PURPOSE:  Internal NETAPI function to start QM
180  ********************************************************************
181  * DESCRIPTION:  Internal NETAPI function to start QM
182  *               once per thread/core
183  ********************************************************************/
184 int netapip_startQm(void* rmClientServiceHandle)
186      int32_t          result;
187      Qmss_StartCfg    startCfg;
189      startCfg.rmServiceHandle = rmClientServiceHandle;
190      startCfg.pQmssGblCfgParams = NULL;
191      //result = Qmss_start();
192      result = Qmss_startCfg(&startCfg);
193      if (result != QMSS_SOK)
194      {
195          return (-1);
196      }
197      return 1;
201 /*** NWAL Memory Buffer Configuration ***/
202 #define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_HANDLE     3400
203 //uint8_t nwalInstMem[NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_HANDLE]ALIGN(CACHE_LINESZ);
206 #define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_MAC                    256
207 #define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_IPSEC_HANDLE_PER_CHAN      256
208 #define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_IP                     128
209 #define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_PORT                   128
210 #define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_L2L3_HDR               128
211 #define NWAL_CHAN_HANDLE_SIZE    ((NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_MAC * TUNE_NETAPI_MAX_NUM_MAC) + \
212                                   (NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_IPSEC_HANDLE_PER_CHAN * TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS*2) + \
213                                   (NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_IP * TUNE_NETAPI_MAX_NUM_IP) + \
214                                   (NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_PORT * TUNE_NETAPI_MAX_NUM_PORTS)+ \
215                                   (NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_L2L3_HDR * TUNE_NETAPI_MAX_NUM_L2_L3_HDRS))
217 typedef struct NETAPI_NWAL_SHM_Tag
219     uint8_t nwalInstMem[NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_HANDLE]ALIGN(CACHE_LINESZ);
220     uint8_t nwalHandleMem[NWAL_CHAN_HANDLE_SIZE]ALIGN(CACHE_LINESZ);
221 } NETAPI_NWAL_SHM_T;
224 typedef struct NETAPI_PA_SHM_Tag
226 /* todo: Check if below size information can be made available from pa interface file */
227 #define NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF0      256
228 /* PA instance */
229 /* Memory used for the PA Instance. Needs to be assigned global uncached memory for chip */
230 uint8_t paBuf0[NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF0]ALIGN(CACHE_LINESZ);
232 /* Memory used for PA handles */
233 #define NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF1    128 * TUNE_NETAPI_MAX_NUM_MAC
234 uint8_t paBuf1[NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF1]ALIGN(CACHE_LINESZ);
236 #define NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF2   14592
239 uint8_t paBuf2[NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF2]ALIGN(CACHE_LINESZ);
240 } NETAPI_PA_SHM_T;
243 typedef struct NETAPI_SA_SHM_Tag
245 /* Memory used for SA LLD global Handle */
246 #define NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE    512
247 uint8_t salldHandle[NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE]ALIGN(CACHE_LINESZ);
249 /* Memory used by SA LLD per Channel */
250 #define NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE_PER_CHAN          512
251 uint8_t salldChanHandle[NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE_PER_CHAN * TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS*2]ALIGN(CACHE_LINESZ);
252 } NETAPI_SA_SHM_T;
261 /********************************************************************
262 * FUNCTION PURPOSE:  NETAPI internal function to gracefully cleanup when startup
263 *                                  issue occurs.
264  ********************************************************************
265  * DESCRIPTION:  NETAPI internal function to gracefully cleanup when startup
266 *                                  issue occurs.
267  ********************************************************************/
268 void netapipErrTeardown() { netapip_cleanupAtStart(); exit(-99); }
270 /********************************************************************
271  * FUNCTION PURPOSE:  Internal NETAPI function to initialize NWAL subsystem
272  ********************************************************************
273  * DESCRIPTION:  Internal NETAPI function to initialize NWAL subsytem
274  ********************************************************************/
275 int netapip_initNwal(
276     int region2use,
277     Pktlib_HeapIfTable * p_table,
278     NETAPI_NWAL_GLOBAL_CONTEXT_T * p_nwal_context,
279     NETAPI_CFG_T*p_cfg)
281     nwalSizeInfo_t  nwalSizeInfo;
282     nwal_RetValue   nwalRetVal;
283     nwalGlobCfg_t   nwalGlobCfg;
284     nwalBaseAddrCfg_t nwalBaseAddrCfg;
285     uint8_t         count;
286     int             sizes[nwal_N_BUFS];
287     int             aligns[nwal_N_BUFS];
288     void*           bases[nwal_N_BUFS];   
289     Pktlib_HeapCfg      heapCfg;
290     int32_t             errCode = 0;
291     void* pBase = NULL;
292     NETAPI_PA_SHM_T* paEntry = NULL;
293     NETAPI_SA_SHM_T* saEntry = NULL;
294     NETAPI_NWAL_SHM_T* nwalEntry = NULL;
295     uint32_t localCtxSize = 0;
296     memset(p_nwal_context,0,sizeof( NETAPI_NWAL_GLOBAL_CONTEXT_T) );
297     memset(&nwalGlobCfg,0,sizeof(nwalGlobCfg_t ) );
298     memset (&nwalBaseAddrCfg, 0, sizeof(nwalBaseAddrCfg_t));
299     pBase = hplib_shmOpen();
300     if (pBase)
301     {
302         if(hplib_shmAddEntry(pBase, sizeof(NETAPI_PA_SHM_T), PA_ENTRY) == hplib_OK)
303         {
304             paEntry = (NETAPI_PA_SHM_T*)hplib_shmGetEntry(pBase,PA_ENTRY);
305             nwalBaseAddrCfg.pInstPoolPaBaseAddr= (void *)paEntry;
306         }
307         else
308         {
309             return -1;
310         }
311         if(hplib_shmAddEntry(pBase, sizeof(NETAPI_SA_SHM_T), SA_ENTRY) == hplib_OK)
312         {
313             saEntry = (NETAPI_SA_SHM_T*)hplib_shmGetEntry(pBase,SA_ENTRY);
314             nwalBaseAddrCfg.pInstPoolSaBaseAddr= (void*) saEntry;
315         }
316         else
317         {
318             return -1;
319         }
320         if(hplib_shmAddEntry(pBase, sizeof(NETAPI_NWAL_SHM_T), NWAL_ENTRY) == hplib_OK)
321         {
322             nwalEntry = (NETAPI_NWAL_SHM_T*)hplib_shmGetEntry(pBase,NWAL_ENTRY);
323         }
324         else
325         {
326             return -1;
327         }
328         
329     }
330     /* Initialize Buffer Pool for NetCP PA to SA packets */
331     nwalGlobCfg.pa2SaBufPool.numBufPools = 1;
332     nwalGlobCfg.pa2SaBufPool.bufPool[0].descSize = TUNE_NETAPI_DESC_SIZE;
333     nwalGlobCfg.pa2SaBufPool.bufPool[0].bufSize =  p_cfg->def_heap_buf_size;
335     /* Initialize the heap configuration. */
336     memset ((void *)&heapCfg, 0, sizeof(Pktlib_HeapCfg));
337     /* Populate the heap configuration */
338     heapCfg.name                = "nwal PA2SA";
339     heapCfg.memRegion           = region2use;
340     heapCfg.sharedHeap          = 0;
341     heapCfg.useStarvationQueue  = 0;
342     heapCfg.dataBufferSize      = p_cfg->def_heap_buf_size;
343     heapCfg.numPkts             = TUNE_NETAPI_CONFIG_MAX_PA_TO_SA_DESC;
344     heapCfg.numZeroBufferPackets= 0;
345     heapCfg.heapInterfaceTable.data_malloc  = p_table->data_malloc;
346     heapCfg.heapInterfaceTable.data_free    = p_table->data_free;
347     heapCfg.dataBufferPktThreshold   = 0;
348     heapCfg.zeroBufferPktThreshold   = 0;
351     nwalGlobCfg.pa2SaBufPool.bufPool[0].heapHandle = p_nwal_context->pa2sa_heap=
352                       Pktlib_createHeap(&heapCfg, &errCode);
353     if(nwalGlobCfg.pa2SaBufPool.bufPool[0].heapHandle == NULL)
354     {
355         netapipErrTeardown();
356         return -1;
357     }
359  /* Initialize Buffer Pool for NetCP SA to PA packets */
360     nwalGlobCfg.sa2PaBufPool.numBufPools = 1;
361     nwalGlobCfg.sa2PaBufPool.bufPool[0].descSize = TUNE_NETAPI_DESC_SIZE;
362     nwalGlobCfg.sa2PaBufPool.bufPool[0].bufSize =  p_cfg->def_heap_buf_size;
364      /* Populate the heap configuration */
365     heapCfg.name                = "nwal SA2PA";
366     heapCfg.numPkts             = TUNE_NETAPI_CONFIG_MAX_SA_TO_PA_DESC;
368     nwalGlobCfg.sa2PaBufPool.bufPool[0].heapHandle = 
369         p_nwal_context->sa2pa_heap = Pktlib_createHeap(&heapCfg, &errCode);
370     if(nwalGlobCfg.sa2PaBufPool.bufPool[0].heapHandle == NULL)
371     {
372         netapipErrTeardown();
373         return -1;
374     }
376     nwalGlobCfg.hopLimit = 5;/* Default TTL / Hop Limit */
377     nwalGlobCfg.paPowerOn = nwal_TRUE;
378     nwalGlobCfg.saPowerOn = nwal_TRUE;
379     nwalGlobCfg.paFwActive = nwal_TRUE;
380     nwalGlobCfg.saFwActive = nwal_FALSE;
383     /* Update nwal cfg with virtual PA and SA addresses */
386     nwalBaseAddrCfg.paVirtBaseAddr = (uint32_t) netapi_VM_VirtAddr->passCfgVaddr;
389     nwalBaseAddrCfg.pSaVirtBaseAddr = (uint32_t) netapi_VM_VirtAddr->passCfgVaddr +
390                                   CSL_NETCP_CFG_SA_CFG_REGS -
391                                   CSL_NETCP_CFG_REGS;
392         ;
393     nwalGlobCfg.rxDefPktQ = QMSS_PARAM_NOT_SPECIFIED;
396     /* Get the Buffer Requirement from NWAL */
397     memset(&nwalSizeInfo,0,sizeof(nwalSizeInfo));
398     nwalSizeInfo.nMaxMacAddress = TUNE_NETAPI_MAX_NUM_MAC;
399     nwalSizeInfo.nMaxIpAddress = TUNE_NETAPI_MAX_NUM_IP;
400     nwalSizeInfo.nMaxL4Ports = TUNE_NETAPI_MAX_NUM_PORTS;
401     nwalSizeInfo.nMaxIpSecChannels = TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS;//we allocate 2 per channel
402     nwalSizeInfo.nMaxDmSecChannels = TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS;//we allocate 2 per channel
403     nwalSizeInfo.nMaxL2L3Hdr = TUNE_NETAPI_MAX_NUM_L2_L3_HDRS;
404     nwalSizeInfo.nProc = TUNE_NETAPI_NUM_CORES;
405     nwalRetVal = nwal_getBufferReq(&nwalSizeInfo,
406                                    sizes,
407                                    aligns);
408     if(nwalRetVal != nwal_OK)
409     {
410         return nwal_FALSE;
411     }
413 /* Check for memory size requirement and update the base */
414     count = 0;
415     //bases[nwal_BUF_INDEX_INST] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)nwalInstMem);
416     bases[nwal_BUF_INDEX_INST] = 
417                 (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)nwalEntry->nwalInstMem);
419     if(NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_HANDLE < sizes[nwal_BUF_INDEX_INST])
420     {
421         /* Resize Memory */
422         return nwal_FALSE;
423         //while(1);
424     }
425     count++;
427     //bases[nwal_BUF_INDEX_INT_HANDLES] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)nwalHandleMem);
428     bases[nwal_BUF_INDEX_INT_HANDLES] = 
429                     (uint32_t *) Osal_nwalLocToGlobAddr((uint32_t)nwalEntry->nwalHandleMem);
431     
432     if(NWAL_CHAN_HANDLE_SIZE  < sizes[nwal_BUF_INDEX_INT_HANDLES])
433     {
434         /* Resize Memory */
435         return nwal_FALSE;
436         //while(1);
438     }
439     count++;
440      bases[nwal_BUF_INDEX_PA_LLD_BUF0] =
441         (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)paEntry->paBuf0);
442     if((NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF0) < sizes[nwal_BUF_INDEX_PA_LLD_BUF0])
443     {
444         /* Resize Memory */
445         return nwal_FALSE;
446         //while(1);
448     }
449     count++;
451     bases[nwal_BUF_INDEX_PA_LLD_BUF1] =
452         (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)paEntry->paBuf1);
453     if((NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF1) < sizes[nwal_BUF_INDEX_PA_LLD_BUF1])
454     {
455         /* Resize Memory */
456         return nwal_FALSE;
457         //while(1);
459     }
460     count++;
462     bases[nwal_BUF_INDEX_PA_LLD_BUF2] =
463         (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)paEntry->paBuf2);
464     if((NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF2) < sizes[nwal_BUF_INDEX_PA_LLD_BUF2])
465     {
466         /* Resize Memory */
467         return nwal_FALSE;
468         //while(1);
470     }
471     count++;
472 #ifdef NETAPI_ENABLE_SECURITY
473     bases[nwal_BUF_INDEX_SA_LLD_HANDLE] =
474         (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)saEntry->salldHandle);
475     if((NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE) < sizes[nwal_BUF_INDEX_SA_LLD_HANDLE])
476     {
477         /* Resize Memory */
478         return nwal_FALSE;
479         //while(1);
481     }
482     count++;
484     bases[nwal_BUF_INDEX_SA_CONTEXT] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)netapi_VM_SaContextVaddr);
485     /* also save this here for easy access to sa_start */
486     nwalBaseAddrCfg.pScPoolBaseAddr= bases[nwal_BUF_INDEX_SA_CONTEXT];
487     count++;
489     bases[nwal_BUF_INDEX_SA_LLD_CHAN_HANDLE] =
490         (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)saEntry->salldChanHandle);
491     if((NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE_PER_CHAN * TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS*2) <
492         sizes[nwal_BUF_INDEX_SA_LLD_CHAN_HANDLE])
493     {
494         /* Resize Memory */
495         return nwal_FALSE;
496         //while(1);
498     }
499     count++;
500 #else
501     bases[nwal_BUF_INDEX_SA_LLD_HANDLE] = 0;
502     bases[nwal_BUF_INDEX_SA_CONTEXT] = 0;
503     bases[nwal_BUF_INDEX_SA_LLD_CHAN_HANDLE] = 0;
504     count = count+3;
505 #endif
507     /* Initialize NWAL module */
508     nwal_getLocContextBufferReq(nwalSizeInfo.nProc, &localCtxSize);
510     pNwalLocCtxMem = malloc(localCtxSize);
511     nwal_createProc(bases[nwal_BUF_INDEX_INST],
512                           pNwalLocCtxMem,
513                           &nwalBaseAddrCfg);
515     nwalGlobCfg.pBaseAddrCfg = &nwalBaseAddrCfg;
516     nwalRetVal = nwal_create(&nwalGlobCfg,
517                              &nwalSizeInfo,
518                              sizes,
519                              bases,
520                              &gPNwalInstHandle);
521     if(nwalRetVal != nwal_OK)
522     {
523         return nwal_FALSE;
524     }
526     return 1;
529 /********************************************************************
530  * FUNCTION PURPOSE:  Internal NETAPI function to start  NWAL 
531  ********************************************************************
532  * DESCRIPTION:  Internal NETAPI function to start NWAL, per thread/core
533  ********************************************************************/
534 int netapip_startNwal(Pktlib_HeapHandle pkt_heap,
535                       Pktlib_HeapHandle cmd_rx_heap,
536                       Pktlib_HeapHandle cmd_tx_heap,
537                       NETAPI_NWAL_LOCAL_CONTEXT_T *p,
538                       NETAPI_CFG_T *p_cfg,
539                       NETAPI_NWAL_GLOBAL_CONTEXT_T * p_nwal_glob_context,
540                       int master)
542     nwalLocCfg_t    nwalLocCfg;
543     nwalBaseAddrCfg_t nwalBaseAddrCfg;
544     int count=0;
545     static int first_time = 0;
546     nwal_RetValue       nwalRetVal;
547     void* pBase = NULL;
548     NETAPI_NWAL_SHM_T* nwalEntry = NULL;
549     void* pNwalLocCtxMem = NULL;
551     NETAPI_SA_SHM_T* saEntry = NULL;
552     NETAPI_PA_SHM_T* paEntry = NULL;
554     uint32_t            baseAddr;
555     void*               instPoolSaBaseAddr;
556     void*               pScPoolBaseAddr;
557     void*               pInstPoolPaBaseAddr;
558     void*               paVirtBaseAddr;
559     uint32_t          localCtxSize;
561     memset(&nwalLocCfg,0,sizeof(nwalLocCfg));
562     memset(&nwalBaseAddrCfg, 0, sizeof(nwalBaseAddrCfg_t));
564     /* Update the Start of Packet Offset for the default flows created 
565      * by NWAL
566      */
567     nwalLocCfg.rxSopPktOffset = p_cfg->def_flow_pkt_rx_offset;
568     nwalLocCfg.rxPktTailRoomSz = p_cfg->def_heap_tailroom_size;
570  /* Call back registration for the core */
571     nwalLocCfg.pRxPktCallBack = netapip_pktioNWALRxPktCallback;
572     nwalLocCfg.pCmdCallBack = netapip_netcpCfgNWALCmdCallBack;
573     nwalLocCfg.pPaStatsCallBack = netapip_netcpCfgNWALCmdPaStatsReply;
575     nwalLocCfg.pRxDmCallBack=  netapip_pktioNWALSBPktCallback; //sideband mode callback
577     /* Initialize Buffer Pool for Control packets from NetCP to Host */
578     nwalLocCfg.rxCtlPool.numBufPools = 1;
579     nwalLocCfg.rxCtlPool.bufPool[0].descSize = TUNE_NETAPI_DESC_SIZE;
580     nwalLocCfg.rxCtlPool.bufPool[0].bufSize = TUNE_NETAPI_CONFIG_MAX_CTL_RXTX_BUF_SIZE;
581     nwalLocCfg.rxCtlPool.bufPool[0].heapHandle = cmd_rx_heap;
583     /* Initialize Buffer Pool for Control packets from Host to NetCP */
584     nwalLocCfg.txCtlPool.numBufPools = 1;
585     nwalLocCfg.txCtlPool.bufPool[0].descSize = TUNE_NETAPI_DESC_SIZE;
586     nwalLocCfg.txCtlPool.bufPool[0].bufSize = TUNE_NETAPI_CONFIG_MAX_CTL_RXTX_BUF_SIZE;
587     nwalLocCfg.txCtlPool.bufPool[0].heapHandle =  cmd_tx_heap;
589 /* Initialize Buffer Pool for L4 Packets from NetCP to Host */
590     nwalLocCfg.rxPktPool.numBufPools = 1;
591     nwalLocCfg.rxPktPool.bufPool[0].descSize = TUNE_NETAPI_DESC_SIZE;
592     nwalLocCfg.rxPktPool.bufPool[0].bufSize =  p_cfg->def_heap_buf_size;
593     nwalLocCfg.rxPktPool.bufPool[0].heapHandle = pkt_heap;
595 /* Initialize Buffer Pool for Packets from Host to NetCP */
596     nwalLocCfg.txPktPool.numBufPools = 1;
597     nwalLocCfg.txPktPool.bufPool[0].descSize = TUNE_NETAPI_DESC_SIZE;
598     nwalLocCfg.txPktPool.bufPool[0].bufSize =  p_cfg->def_heap_buf_size;
599     nwalLocCfg.txPktPool.bufPool[0].heapHandle = pkt_heap;
604     memcpy(&p->nwalLocCfg,&nwalLocCfg,sizeof(nwalLocCfg_t));
605     while(1)
606     {
607         if(master == NETAPI_PROC_MASTER)
608         {
609             pBase = hplib_shmOpen();
610             nwalEntry = (NETAPI_NWAL_SHM_T*)hplib_shmGetEntry(pBase,NWAL_ENTRY);
612                 baseAddr = (void*) netapi_VM_VirtAddr->passCfgVaddr +
613                                               CSL_NETCP_CFG_SA_CFG_REGS -
614                                               CSL_NETCP_CFG_REGS;
615                  saEntry = (NETAPI_SA_SHM_T*)hplib_shmGetEntry(pBase,SA_ENTRY);
616                  instPoolSaBaseAddr = (void*) saEntry;
617             
618                  pScPoolBaseAddr = Osal_nwalLocToGlobAddr((uint32_t)netapi_VM_SaContextVaddr);
621                  paVirtBaseAddr = (void*) netapi_VM_VirtAddr->passCfgVaddr;
622                  paEntry = (NETAPI_PA_SHM_T*)hplib_shmGetEntry(pBase,PA_ENTRY);
623                  pInstPoolPaBaseAddr = (void *)paEntry;
625             nwal_getLocContextBufferReq(TUNE_NETAPI_NUM_CORES, &localCtxSize);
626             pNwalLocCtxMem = malloc(localCtxSize);
627             if (pNwalLocCtxMem == NULL)
628             {
629                 return -1;
630             }
631             nwalBaseAddrCfg.pSaVirtBaseAddr = baseAddr;
632             nwalBaseAddrCfg.pInstPoolSaBaseAddr = instPoolSaBaseAddr;
633             nwalBaseAddrCfg.pScPoolBaseAddr = pScPoolBaseAddr;
634             nwalBaseAddrCfg.paVirtBaseAddr = paVirtBaseAddr;
635             nwalBaseAddrCfg.pInstPoolPaBaseAddr = pInstPoolPaBaseAddr;
636             /* this is 1 time per process */
637             nwal_createProc(nwalEntry,
638                             pNwalLocCtxMem,
639                             &nwalBaseAddrCfg);
640         }
641         /* this is for every thread including 1st thread of the process */
642         netapi_proc_master->spinLock.lock(&pnetapiShm->netapi_util_lock);
643         nwalRetVal = nwal_start(gPNwalInstHandle,&nwalLocCfg);
644         netapi_proc_master->spinLock.unlock(&pnetapiShm->netapi_util_lock);
645         if(nwalRetVal == nwal_ERR_INVALID_STATE)
646         {
647             continue;
648         }
649         break;
650     }
652     if(nwalRetVal != nwal_OK)
653     {
654         return -1;
655     }
656     p->state = NETAPI_NW_CXT_LOC_ACTIVE;
657     return 1;
661 /***********************************************************************
662  * FUNCTION PURPOSE:  Internal NETAPI function to initialize the 64 bit timer.
663  ***********************************************************************
664  * DESCRIPTION:  Internal NETAPI function to initialize the 64 bit timer. for tci6614 ONLY
665  **********************************************************************/
666 int netapip_initTimer(void)
668 #ifdef CORTEX_A8
669         return t64_start();
670 #else
671     return 0;
672 #endif
678 /***************************************************************************
679 * FUNCTION PURPOSE:  NETAPI internal function for virtual memory allocation.
680  ***************************************************************************
681  * DESCRIPTION:  NETAPI internal function for virtual memory allocation.
682  **************************************************************************/
684 static uint8_t* netapip_sharedMemoryMalloc(uint32_t size)
686     return  (uint8_t *)hplib_vmMemAlloc(size + 
687                                     pnetapiShm->netapi_global.cfg.def_heap_extra_size ,
688                                     128,
689                                     0); 
692 /********************************************************************
693 * FUNCTION PURPOSE:  NETAPI internal function for virtual memory free.
694  ********************************************************************
695  * DESCRIPTION:  NETAPI internal function for virtual memory free.
696  ********************************************************************/
697 static void netapip_sharedMemoryFree(uint8_t* ptr, uint32_t size)
699     /* Do Nothing. */
700     return;
703 //defensive: clean out stuff hanging around
704 //
705 //  open a bunch of free queues and zap them
706 #define NQUEUES2CLEAR 35
707 static Qmss_QueueHnd tempQH[NQUEUES2CLEAR];
708 void netapip_cleanupAtStart(void)
710     int i;
711     uint8_t         isAllocated;
713     for(i=0;i<NQUEUES2CLEAR;i++) 
714     {
715         tempQH[i] = Qmss_queueOpen(Qmss_QueueType_GENERAL_PURPOSE_QUEUE,
716                                                   QMSS_PARAM_NOT_SPECIFIED, &isAllocated);
717         netapip_zapQ(tempQH[i]);
718     }
720     for(i=0;i<NQUEUES2CLEAR;i++)
721     {
722         Qmss_queueClose(tempQH[i]);
723     }
728 /********************************************************************
729 * FUNCTION PURPOSE:  NETAPI internal function system initialization
730  ********************************************************************
731  * DESCRIPTION:  NETAPI internal function system initialization
732  ********************************************************************/
733 int netapip_systemInit(NETAPI_HANDLE_T * handle,
734                        Bool global_master_process)
737     int32_t             result;
738     Pktlib_HeapHandle   sharedHeapHandle;
739     Pktlib_HeapHandle   controlRxHeapHandle,controlTxHeapHandle;
740     Pktlib_HeapCfg      heapCfg;
741     int32_t             errCode = 0;
742     int count=0;
744 #ifdef NETAPI_USE_DDR
745     /* Init attributes for DDR */
746     netapi_VM_MempoolAttr[0].attr = HPLIB_ATTR_KM_CACHED0;
747     netapi_VM_MempoolAttr[0].phys_addr = 0;
748     netapi_VM_MempoolAttr[0].size = 0;
750 #ifdef NETAPI_USE_DDR_AND_MSMC
751        /* Init attributes for un-cached MSMC */
752     netapi_VM_MempoolAttr[1].attr = HPLIB_ATTR_UN_CACHED;
753     netapi_VM_MempoolAttr[1].phys_addr = CSL_MSMC_SRAM_REGS;
754     netapi_VM_MempoolAttr[1].size = TUNE_NETAPI_PERM_MEM_SZ;
755 #endif
756 #else
757        /* Init attributes for un-cached MSMC */
758     netapi_VM_MempoolAttr[0].attr = HPLIB_ATTR_UN_CACHED;
759     netapi_VM_MempoolAttr[0].phys_addr = CSL_MSMC_SRAM_REGS;
760     netapi_VM_MempoolAttr[0].size = TUNE_NETAPI_PERM_MEM_SZ;
761 #ifdef NETAPI_USE_DDR_AND_MSMC
762     netapi_VM_MempoolAttr[1].attr = HPLIB_ATTR_KM_CACHED0;
763     netapi_VM_MempoolAttr[1].phys_addr = 0;
764     netapi_VM_MempoolAttr[1].size = 0;
765 #endif
766 #endif
767     /* initialize all the memory we are going to use
768        - chunk for buffers, descriptors
769        - memory mapped peripherals we use, such as QMSS, PA, etc */
770 #ifdef NETAPI_USE_DDR_AND_MSMC
771     result = hplib_vmInit(&netapi_VM_VirtAddr[0],
772                           2,
773                           &netapi_VM_MempoolAttr[0]);
774 #else
775     result = hplib_vmInit(&netapi_VM_VirtAddr[0],
776                            1,
777                            &netapi_VM_MempoolAttr[0]);
778 #endif
780     if (result != hplib_OK)
781     {
782         return -1;
783     }
785     if (global_master_process == NETAPI_TRUE)
786     {
787         hplib_initMallocArea(0);
788 #ifdef  NETAPI_USE_DDR_AND_MSMC
789         hplib_initMallocArea(1);
790 #endif
791 #ifdef NETAPI_ENABLE_SECURITY
792 #define SEC_CONTEXT_SZ 384  //not tunable
793         /* allocate 2x number of tunnels since we need one for inflow and one for data mode */
794         netapi_VM_SaContextVaddr = hplib_vmMemAlloc((TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS*2 *
795                                         SEC_CONTEXT_SZ), 128, 0);
796         if (!netapi_VM_SaContextVaddr)
797         {
798             return (-1);
799         }
800 #else
801             netapi_VM_SaContextVaddr= (char *) NULL;
802 #endif
804         /* (3) Allocate 2 QM regions from continguous chunk above */
805         netapi_VM_QMemGlobalDescRam = 
806                 (void *)hplib_vmMemAlloc((TUNE_NETAPI_NUM_GLOBAL_DESC *
807                 TUNE_NETAPI_DESC_SIZE),
808                 128,
809                 0);
811         netapi_VM_QMemLocalDescRam =
812                 (void *)hplib_vmMemAlloc((TUNE_NETAPI_NUM_LOCAL_DESC *
813                 TUNE_NETAPI_DESC_SIZE),
814                 128,
815                 0);
816         /* Initialize Queue Manager Sub System */
817         result = netapip_initQm (pnetapiShm->netapi_global.cfg.def_max_descriptors,
818                                  pRmClientHandle);
819         
820         if (result != 1)
821         {
822             return -1;
823         }
824         /* Start the QMSS. */
825         if (netapip_startQm(pRmClientHandle) != 1)
826         {
827             return -1;
828         }
830         //clean our old junk in 1st bunch of queues that will be allocated to us
831         netapip_cleanupAtStart();
832          /* Initialize the global descriptor memory region. */
833         result= netapip_qmSetupMemRegion( 
834                            pnetapiShm->netapi_global.cfg.def_tot_descriptors_for_us,
835                            TUNE_NETAPI_DESC_SIZE,
836                            (unsigned int *) netapi_VM_QMemGlobalDescRam,
837                            pnetapiShm->netapi_global.cfg.memoryRegion,
838                            pnetapiShm->netapi_global.cfg.start_index);
839         if(result <0)
840         {
841             return -1;
842         }
843         /* Initialize CPPI CPDMA */
844         result = netapip_initCppi(pRmClientHandle);
845         if (result != 1)
846         {
847             return -1;
848         }
849         /* CPPI and Queue Manager are initialized. */
851         /* create main pkt heap */
852         /* Initialize the Shared Heaps. */
853         Pktlib_sharedHeapInit();
854         /* Populate the heap interface table. */
855         netapi_pktlib_ifTable.data_malloc             = netapip_sharedMemoryMalloc;
856         netapi_pktlib_ifTable.data_free               = netapip_sharedMemoryFree;
857         /* Initialize the heap configuration. */
858         memset ((void *)&heapCfg, 0, sizeof(Pktlib_HeapCfg));
859         /* Populate the heap configuration */
860         heapCfg.name                = "netapi";
861         heapCfg.memRegion = memInfo.memRegion;
862         heapCfg.sharedHeap          = 1;
863         heapCfg.useStarvationQueue  = 0;
864         heapCfg.dataBufferSize      = pnetapiShm->netapi_global.cfg.def_heap_buf_size;
865         heapCfg.numPkts             = pnetapiShm->netapi_global.cfg.def_heap_n_descriptors;
866         heapCfg.numZeroBufferPackets= pnetapiShm->netapi_global.cfg.def_heap_n_zdescriptors;
867         heapCfg.heapInterfaceTable.data_malloc  = netapi_pktlib_ifTable.data_malloc;
868         heapCfg.heapInterfaceTable.data_free    = netapi_pktlib_ifTable.data_free;
869         heapCfg.dataBufferPktThreshold   = 0;
870         heapCfg.zeroBufferPktThreshold   = 0;
872         /* Create Shared Heap with specified configuration. */
873         sharedHeapHandle = Pktlib_createHeap(&heapCfg, &errCode);
874         if (!sharedHeapHandle) { return -1;}
875         handle->netcp_heap= sharedHeapHandle;
876         /* Update for Control */
877         heapCfg.name                = "netapi_control_rx";
878         heapCfg.sharedHeap          = 1;
879         heapCfg.dataBufferSize      = TUNE_NETAPI_CONFIG_MAX_CTL_RXTX_BUF_SIZE;
880         heapCfg.numPkts             = TUNE_NETAPI_CONFIG_NUM_CTL_RX_BUF;
881         heapCfg.numZeroBufferPackets= 0;
882     
883         controlRxHeapHandle = Pktlib_createHeap(&heapCfg, &errCode);
884         //todo -> cleanup on failure
885         if (!controlRxHeapHandle) { return -1;}
886         handle->netcp_control_rx_heap= controlRxHeapHandle;
887     
888     
889         heapCfg.name                = "netapi_control_tx";
890         heapCfg.numPkts             = TUNE_NETAPI_CONFIG_NUM_CTL_TX_BUF;
891     
892         controlTxHeapHandle = Pktlib_createHeap(&heapCfg, &errCode);
893     //todo -> cleanup on failure
894     if (!controlTxHeapHandle) { return -1;}
895     handle->netcp_control_tx_heap= controlTxHeapHandle;
896              /* now NWAL */
897         result = netapip_initNwal(memInfo.memRegion,
898                               &netapi_pktlib_ifTable,
899                               &pnetapiShm->netapi_global.nwal_context,
900                               &pnetapiShm->netapi_global.cfg);
901         if (result<0) { return -1; }
902         /* Common Initialization for all cores */
903         while(count < TUNE_NETAPI_MAX_NUM_TRANS)
904         {
905             netapi_proc_global.nwal_context.transInfos[count].transId = count;
906             count++;
907         }
908         result = netapip_startNwal(sharedHeapHandle, 
909                                    controlRxHeapHandle,
910                                    controlTxHeapHandle,
911                                    &handle->nwal_local,
912                                    &pnetapiShm->netapi_global.cfg,
913                                    &pnetapiShm->netapi_global.nwal_context,
914                                    handle->master);
915         if (result<0) { return -1; }
916     }
917     else
918     {
919         if (hplib_checkMallocArea(0) != hplib_OK)
920             return -1;
921         if (hplib_checkMallocArea(1) != hplib_OK)
922             return -1;
924 #ifdef NETAPI_ENABLE_SECURITY
925                 /* allocate 2x number of tunnels since we need one for inflow and one for data mode */
926                 netapi_VM_SaContextVaddr = hplib_vmMemAlloc((TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS*2 *
927                                                 SEC_CONTEXT_SZ), 128, 0);
928                 if (!netapi_VM_SaContextVaddr)
929                 {
930                     return (-1);
931                 }
932 #else
933                 netapi_VM_SaContextVaddr= (char *) NULL;
934 #endif
938         /* (3) Allocate 2 QM regions from continguous chunk above */
939         netapi_VM_QMemGlobalDescRam = 
940                 (void *)hplib_vmMemAlloc((TUNE_NETAPI_NUM_GLOBAL_DESC *
941                 TUNE_NETAPI_DESC_SIZE),
942                 128,
943                 0);
945         netapi_VM_QMemLocalDescRam =
946                 (void *)hplib_vmMemAlloc((TUNE_NETAPI_NUM_LOCAL_DESC *
947                 TUNE_NETAPI_DESC_SIZE),
948                 128,
949                 0);
951         /****************************************************
952          * partial initialization.  For process, not for SOC
953          ***************************************************/
954         result = netapip_initQm (pnetapiShm->netapi_global.cfg.def_max_descriptors,
955                                  pRmClientHandle);
956         if (result != 1)
957         {
958             return -1;
959         }
961         /* Start the QMSS. */
962         if (netapip_startQm(pRmClientHandle) != 1)
963         {
964             return -1;
965         }
967         result= netapip_qmSetupMemRegion( 
968                            pnetapiShm->netapi_global.cfg.def_tot_descriptors_for_us,
969                            TUNE_NETAPI_DESC_SIZE,
970                            (unsigned int *) netapi_VM_QMemGlobalDescRam,
971                            pnetapiShm->netapi_global.cfg.memoryRegion,
972                            pnetapiShm->netapi_global.cfg.start_index);
973         if(result <0)
974         {
975             return -1;
976         }
977         /* Initialize CPPI CPDMA */
978         result = netapip_initCppi(pRmClientHandle);
979         if (result != 1)
980         {
981             return -1;
982         }
983         /* CPPI and Queue Manager are initialized. */
985         /* create main pkt heap for this process */
986         /* Initialize the Shared Heaps. */
987         Pktlib_sharedHeapInit();
988         /* Populate the heap interface table. */
989         netapi_pktlib_ifTable.data_malloc             = netapip_sharedMemoryMalloc;
990         netapi_pktlib_ifTable.data_free               = netapip_sharedMemoryFree;
991         /* Initialize the heap configuration. */
992         memset ((void *)&heapCfg, 0, sizeof(Pktlib_HeapCfg));
993         /* Populate the heap configuration */
994         heapCfg.name                = "netapi";
995         //heapCfg.memRegion           = TUNE_NETAPI_QM_GLOBAL_REGION;
996         heapCfg.memRegion = memInfo.memRegion;
997         heapCfg.sharedHeap          = 1;
998         heapCfg.useStarvationQueue  = 0;
999         heapCfg.dataBufferSize      = pnetapiShm->netapi_global.cfg.def_heap_buf_size;
1000         heapCfg.numPkts             = pnetapiShm->netapi_global.cfg.def_heap_n_descriptors;
1001         heapCfg.numZeroBufferPackets= pnetapiShm->netapi_global.cfg.def_heap_n_zdescriptors;
1002         heapCfg.heapInterfaceTable.data_malloc  = netapi_pktlib_ifTable.data_malloc;
1003         heapCfg.heapInterfaceTable.data_free    = netapi_pktlib_ifTable.data_free;
1004         heapCfg.dataBufferPktThreshold   = 0;
1005         heapCfg.zeroBufferPktThreshold   = 0;
1006         
1007         /* Create Shared Heap with specified configuration. */
1008         sharedHeapHandle = Pktlib_createHeap(&heapCfg, &errCode);
1009         //todo -> cleanup on failure
1010         if (!sharedHeapHandle) { return -1;}
1011         handle->netcp_heap= sharedHeapHandle;
1013         //open shared heap handle but create new controlRx & Tx heaps for this
1014         //process
1015         /* Update for Control */
1016         heapCfg.name                = "netapi_control_rx";/*todo:add random#*/
1017         heapCfg.sharedHeap          = 1;
1018         heapCfg.dataBufferSize      = TUNE_NETAPI_CONFIG_MAX_CTL_RXTX_BUF_SIZE;
1019         heapCfg.numPkts             = TUNE_NETAPI_CONFIG_NUM_CTL_RX_BUF;
1020         heapCfg.numZeroBufferPackets= 0;
1021         controlRxHeapHandle = Pktlib_createHeap(&heapCfg, &errCode);
1022         if (!controlRxHeapHandle) { return -1;}
1024         handle->netcp_control_rx_heap= controlRxHeapHandle;
1025         heapCfg.name                = "netapi_control_tx";
1026         heapCfg.numPkts             = TUNE_NETAPI_CONFIG_NUM_CTL_TX_BUF;
1027         controlTxHeapHandle = Pktlib_createHeap(&heapCfg, &errCode);
1028         if (!controlTxHeapHandle) { return -1;}
1029         handle->netcp_control_tx_heap= controlTxHeapHandle;
1031         /* Common Initialization for all threads in process */
1032         while(count < TUNE_NETAPI_MAX_NUM_TRANS)
1033         {
1034           netapi_proc_global.nwal_context.transInfos[count].transId = count;
1035           count++;
1036         }
1037         result = netapip_startNwal(sharedHeapHandle,
1038                                controlRxHeapHandle,
1039                                controlTxHeapHandle,
1040                                &handle->nwal_local,
1041                                &pnetapiShm->netapi_global.cfg,
1042                                &pnetapiShm->netapi_global.nwal_context,
1043                                handle->master);
1044         if (result<0)
1045         {
1046             return -1;
1047         }
1048     }
1050     //get timer running
1051 #ifdef CORTEX_A8
1052         netapip_initTimer();
1053 #endif
1057     return 0;
1061 /****************************************************************************
1062 * FUNCTION PURPOSE:  NETAPI internal function which performs clean for linux user space
1063  ****************************************************************************
1064  * DESCRIPTION:  NETAPI internal function which performs clean for linux user space
1065  ***************************************************************************/
1066 void netapip_zapQ(int queueNum)
1068     int i;
1069     if (!queueNum) 
1070     {
1071         return;
1072     }
1073     for (i=0;;i+=1 )
1074     {
1075         /* Pop descriptor from source queue */
1076         if (pktio_mQmssQueuePopRaw(queueNum) == NULL)
1077         {
1078             break;
1079         }
1080     }
1084 /****************************************************************************
1085 * FUNCTION PURPOSE:  NETAPI internal function to display internal heap stats.
1086  ****************************************************************************
1087  * DESCRIPTION:  NETAPI internal function to display internal heap stats.
1088  ***************************************************************************/
1089 void netapi_dump_internal_heap_stats(void)
1091     Pktlib_HeapStats    pktLibHeapStats;
1092     Pktlib_getHeapStats(netapi_get_global()->nwal_context.pa2sa_heap,&pktLibHeapStats);
1093     printf("PA2SA(ingress) stats>  #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets,
1094                                 pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage);
1095     printf("               >  #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n",
1096                         pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter,
1097                         pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter);
1098     Pktlib_getHeapStats(netapi_get_global()->nwal_context.sa2pa_heap,&pktLibHeapStats);
1099     printf("SA2PA stats>  #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets,
1100                                 pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage);
1101     printf("               >  #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n",
1102                         pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter,
1103                         pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter);