9028f257aa3b595e5f9f48b7e817e4f93b64ba9e
[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>
74 extern NETAPI_SHM_T* pnetapiShm;
75 /* Global variablesto hold virtual address of various subsystems */
76 extern hplib_virtualAddrInfo_T netapi_VM_VirtAddr[];
78 /* Global variables which needs to be populated with memory pool attributes
79    which is passed to HPLIB for memory pool initialization*/
80 extern hplib_memPoolAttr_T netapi_VM_MempoolAttr[];
81 extern unsigned char *netapi_VM_QMemLocalDescRam;
82 extern unsigned char *netapi_VM_QMemGlobalDescRam;
83 extern unsigned char *netapi_VM_SaContextVaddr;
85 extern Pktlib_HeapIfTable  netapi_pktlib_ifTable;
86 extern NETAPI_PROC_GLOBAL_T netapi_proc_global;
89 /* TODO verify: */
90 #define CACHE_LINESZ    64
93 #define ALIGN(x)    __attribute__((aligned (x)))
95 /*****************************************************************************
96  * Global Resources shared by all Cores
97  *****************************************************************************/
98 uint8_t *QMemGlobDescRam = 0;
99 uint8_t *cppiMemPaSaLinkBuf = 0;
100 uint8_t *cppiMemSaPaLinkBuf = 0;
102 /*****************************************************************************
103  * Local Resource allocated at each Core
104  *****************************************************************************/
105 /* Descriptors in global shared */
106 uint8_t *QMemLocDescRam = NULL;
107 uint8_t *cppiMemRxPktLinkBuf = NULL;
108 uint8_t *cppiMemTxPktLinkBuf = NULL;
109 uint8_t *cppiMemRxCtlLinkBuf = NULL;
110 uint8_t *cppiMemTxCtlLinkBuf = NULL;
113 /********************************************************************
114  * FUNCTION PURPOSE:  Internal NETAPI function to setup the QM memory region
115  ********************************************************************
116  * DESCRIPTION:  Internal NETAPI function to setup the QM memory region,
117  *               once per SOC
118  ********************************************************************/
119 int netapip_qmSetupMemRegion(
120                       uint32_t          numDesc,
121                       uint32_t          descSize,
122                       uint32_t*         pDescMemBase,
123                       Qmss_MemRegion    memRegion)
125     Qmss_MemRegInfo   memInfo;
126     Int32             result;
127     Int               n;
128     static int  netapi_qm_region_index=0;
130     memset(&memInfo,0,sizeof(Qmss_MemRegInfo));
131     memInfo.descBase       = pDescMemBase;
132     memInfo.descSize       = descSize;
133     memInfo.descNum        = numDesc;
134     memInfo.manageDescFlag = Qmss_ManageDesc_MANAGE_DESCRIPTOR;
135     memInfo.memRegion      = memRegion;
137     if(memRegion == TUNE_NETAPI_QM_GLOBAL_REGION)
138     {
139         memInfo.startIndex = TUNE_NETAPI_QM_START_INDEX;  //was 0
140         netapi_qm_region_index += numDesc;
141     }else if(memRegion ==NETAPI_LOCAL_REGION)
142     {
143         /* 2nd region for descriptors (perhaps private?) */
144         memInfo.startIndex     = netapi_qm_region_index;
145     }
146     else
147     {
148         return -1 ;
149     }
151     memset (pDescMemBase, 0, (descSize * numDesc));
153     result = Qmss_insertMemoryRegion (&memInfo);
154     if (result < QMSS_SOK)  
155     {
156         netapi_Log ("netapip_qmSetupMemRegion: Qmss_insertMemoryRegion returned error code %d\n", result);
157         return (-1);
158     }
160     return 1;
163 /********************************************************************
164  * FUNCTION PURPOSE:  Internal NETAPI function to start QM
165  ********************************************************************
166  * DESCRIPTION:  Internal NETAPI function to start QM
167  *               once per thread/core
168  ********************************************************************/
169 int netapip_startQm(void)
171      int32_t          result;
172      result = Qmss_start();
173      if (result != QMSS_SOK)
174      {
175          netapi_Log ("netapip_startQm: Qmss_start failed with error code %d\n", result);
176          return (-1);
177      }
178      return 1;
182 /*** NWAL Memory Buffer Configuration ***/
183 #define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_HANDLE     3400
184 uint8_t nwalInstMem[NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_HANDLE]ALIGN(CACHE_LINESZ);
186 #define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_MAC                    256
187 #define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_IPSEC_HANDLE_PER_CHAN      256
188 #define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_IP                     128
189 #define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_PORT                   128
190 #define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_L2L3_HDR               128
191 #define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_LOC_CONTEXT            384
192 #define NWAL_CHAN_HANDLE_SIZE    ((NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_MAC * TUNE_NETAPI_MAX_NUM_MAC) + \
193                                   (NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_IPSEC_HANDLE_PER_CHAN * TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS*2) + \
194                                   (NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_IP * TUNE_NETAPI_MAX_NUM_IP) + \
195                                   (NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_PORT * TUNE_NETAPI_MAX_NUM_PORTS)+ \
196                                   (NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_LOC_CONTEXT * TUNE_NETAPI_NUM_CORES) + \
197                                   (NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_L2L3_HDR * TUNE_NETAPI_MAX_NUM_L2_L3_HDRS))
199 uint8_t nwalHandleMem[NWAL_CHAN_HANDLE_SIZE]ALIGN(CACHE_LINESZ);
202 typedef struct NETAPI_PA_SHM_Tag
204 /* todo: Check if below size information can be made available from pa interface file */
205 #define NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF0      256
206 /* PA instance */
207 /* Memory used for the PA Instance. Needs to be assigned global uncached memory for chip */
208 uint8_t paBuf0[NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF0]ALIGN(CACHE_LINESZ);
210 /* Memory used for PA handles */
211 #define NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF1    128 * TUNE_NETAPI_MAX_NUM_MAC
212 uint8_t paBuf1[NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF1]ALIGN(CACHE_LINESZ);
214 #define NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF2   14592
217 uint8_t paBuf2[NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF2]ALIGN(CACHE_LINESZ);
218 } NETAPI_PA_SHM_T;
221 typedef struct NETAPI_SA_SHM_Tag
223 /* Memory used for SA LLD global Handle */
224 #define NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE    512
225 uint8_t salldHandle[NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE]ALIGN(CACHE_LINESZ);
227 /* Memory used by SA LLD per Channel */
228 #define NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE_PER_CHAN          512
229 uint8_t salldChanHandle[NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE_PER_CHAN * TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS*2]ALIGN(CACHE_LINESZ);
230 } NETAPI_SA_SHM_T;
232 /********************************************************************
233 * FUNCTION PURPOSE:  NETAPI internal function to gracefully cleanup when startup
234 *                                  issue occurs.
235  ********************************************************************
236  * DESCRIPTION:  NETAPI internal function to gracefully cleanup when startup
237 *                                  issue occurs.
238  ********************************************************************/
239 void netapipErrTeardown() { netapip_cleanupAtStart(); exit(-99); }
241 /********************************************************************
242  * FUNCTION PURPOSE:  Internal NETAPI function to initialize NWAL subsystem
243  ********************************************************************
244  * DESCRIPTION:  Internal NETAPI function to initialize NWAL subsytem
245  ********************************************************************/
246 int netapip_initNwal(
247     int region2use,
248     Pktlib_HeapIfTable * p_table,
249     NETAPI_NWAL_GLOBAL_CONTEXT_T * p_nwal_context,
250     NETAPI_CFG_T*p_cfg,
251     nwalGlobalDeviceConfigParams_t *p_nwal_device_cfg)
253     nwalSizeInfo_t  nwalSizeInfo;
254     nwal_RetValue   nwalRetVal;
255     nwalGlobCfg_t   nwalGlobCfg;
256     uint8_t         count;
257     int             sizes[nwal_N_BUFS];
258     int             aligns[nwal_N_BUFS];
259     void*           bases[nwal_N_BUFS];   
260     Pktlib_HeapCfg      heapCfg;
261     int32_t             errCode;
262     void* pBase = NULL;
263     NETAPI_PA_SHM_T* paEntry = NULL;
264     NETAPI_SA_SHM_T* saEntry = NULL;
266     memset(p_nwal_context,0,sizeof( NETAPI_NWAL_GLOBAL_CONTEXT_T) );
267     memset(&nwalGlobCfg,0,sizeof(nwalGlobCfg_t ) );
269     pBase = hplib_shmOpen();
270     if (pBase)
271     {
272         if(hplib_shmAddEntry(pBase, sizeof(NETAPI_PA_SHM_T), PA_ENTRY) == hplib_OK)
273         {
274             paEntry = (NETAPI_PA_SHM_T*)hplib_shmGetEntry(pBase,PA_ENTRY);
275             nwalGlobCfg.instPoolBaseAddr = (void *)paEntry;
276         }
277         else
278         {
279             netapi_Log("netapip_initNwal: Unable to Add shared memory segment for PASS\n");
280             return -1;
281         }
282         if(hplib_shmAddEntry(pBase, sizeof(NETAPI_SA_SHM_T), SA_ENTRY) == hplib_OK)
283         {
284             saEntry = (NETAPI_SA_SHM_T*)hplib_shmGetEntry(pBase,SA_ENTRY);
285             nwalGlobCfg.instPoolSaBaseAddr = (void*) saEntry;
286         }
287         else
288         {
289             netapi_Log("netapip_initNwal: Unable to Add shared memory segment for SASS\n");
290             return -1;
291         }
292         
293     }
294     /* Initialize Buffer Pool for NetCP PA to SA packets */
295     nwalGlobCfg.pa2SaBufPool.numBufPools = 1;
296     nwalGlobCfg.pa2SaBufPool.bufPool[0].descSize = TUNE_NETAPI_DESC_SIZE;
297     nwalGlobCfg.pa2SaBufPool.bufPool[0].bufSize =  p_cfg->def_heap_buf_size;
299     /* Initialize the heap configuration. */
300     memset ((void *)&heapCfg, 0, sizeof(Pktlib_HeapCfg));
301     /* Populate the heap configuration */
302     heapCfg.name                = "nwal PA2SA";
303     heapCfg.memRegion           = region2use;
304     heapCfg.sharedHeap          = 0;
305     heapCfg.useStarvationQueue  = 0;
306     heapCfg.dataBufferSize      = p_cfg->def_heap_buf_size;
307     heapCfg.numPkts             = TUNE_NETAPI_CONFIG_MAX_PA_TO_SA_DESC;
308     heapCfg.numZeroBufferPackets= 0;
309     heapCfg.heapInterfaceTable.data_malloc  = p_table->data_malloc;
310     heapCfg.heapInterfaceTable.data_free    = p_table->data_free;
311     heapCfg.dataBufferPktThreshold   = 0;
312     heapCfg.zeroBufferPktThreshold   = 0;
315     nwalGlobCfg.pa2SaBufPool.bufPool[0].heapHandle = p_nwal_context->pa2sa_heap=
316                       Pktlib_createHeap(&heapCfg, &errCode);
317     if(nwalGlobCfg.pa2SaBufPool.bufPool[0].heapHandle == NULL)
318     {
319         netapi_Log ("netapip_initNwal: Pktlib_createHeap:Heap Creation Failed for PA to SA Buffer Pool, Error Code: %d\n",
320                     errCode); 
321         netapipErrTeardown();
322         return -1;
323     }
325  /* Initialize Buffer Pool for NetCP SA to PA packets */
326     nwalGlobCfg.sa2PaBufPool.numBufPools = 1;
327     nwalGlobCfg.sa2PaBufPool.bufPool[0].descSize = TUNE_NETAPI_DESC_SIZE;
328     nwalGlobCfg.sa2PaBufPool.bufPool[0].bufSize =  p_cfg->def_heap_buf_size;
330      /* Populate the heap configuration */
331     heapCfg.name                = "nwal SA2PA";
332     heapCfg.numPkts             = TUNE_NETAPI_CONFIG_MAX_SA_TO_PA_DESC;
334     nwalGlobCfg.sa2PaBufPool.bufPool[0].heapHandle = p_nwal_context->sa2pa_heap=
335         Pktlib_createHeap(&heapCfg, &errCode);
336     if(nwalGlobCfg.sa2PaBufPool.bufPool[0].heapHandle == NULL)
337     {
338         netapi_Log ("netapip_initNwal: Pktlib_createHeap:Heap Creation Failed for SA to PA Buffer Pool, Error Code: %d\n",
339                      errCode); 
340         netapipErrTeardown();
341         return -1;
342     }
344     nwalGlobCfg.hopLimit = 5;/* Default TTL / Hop Limit */
345     nwalGlobCfg.paPowerOn = nwal_TRUE;
346     nwalGlobCfg.saPowerOn = nwal_TRUE;
347     nwalGlobCfg.paFwActive = nwal_TRUE;
348     nwalGlobCfg.saFwActive = nwal_FALSE;
351     if(p_nwal_device_cfg)
352     {
353         nwalGlobCfg.pDeviceCfg = p_nwal_device_cfg;
354     }
355     else
356     {
357         netapi_Log ("netapip_initNwal: nwal device configuration not provided %d\n");
358         return nwal_FALSE;
359     }
361     /* Update nwal cfg with virtual PA and SA addresses */
362     nwalGlobCfg.pDeviceCfg->cslNetCpCfgSaCfgRegs = netapi_VM_VirtAddr->passCfgVaddr +
363                                  (p_nwal_device_cfg->cslNetCpCfgSaCfgRegs -
364                                  p_nwal_device_cfg->cslNetCpCfgRegs);
366     nwalGlobCfg.pDeviceCfg->cslNetCpCfgRegs = (uint32_t) netapi_VM_VirtAddr->passCfgVaddr;
368     nwalGlobCfg.rxDefPktQ = QMSS_PARAM_NOT_SPECIFIED;
370     /* Get the Buffer Requirement from NWAL */
371     memset(&nwalSizeInfo,0,sizeof(nwalSizeInfo));
372     nwalSizeInfo.nMaxMacAddress = TUNE_NETAPI_MAX_NUM_MAC;
373     nwalSizeInfo.nMaxIpAddress = TUNE_NETAPI_MAX_NUM_IP;
374     nwalSizeInfo.nMaxL4Ports = TUNE_NETAPI_MAX_NUM_PORTS;
375     nwalSizeInfo.nMaxIpSecChannels = TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS;//we allocate 2 per channel
376     nwalSizeInfo.nMaxDmSecChannels = TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS;//we allocate 2 per channel
377     nwalSizeInfo.nMaxL2L3Hdr = TUNE_NETAPI_MAX_NUM_L2_L3_HDRS;
378     nwalSizeInfo.nProc = TUNE_NETAPI_NUM_CORES;
379     nwalRetVal = nwal_getBufferReq(&nwalSizeInfo,
380                                    sizes,
381                                    aligns);
382     if(nwalRetVal != nwal_OK)
383     {
384         netapi_Log ("netapip_initNwal: nwal_getBufferReq Failed %d\n", nwalRetVal);
385         return nwal_FALSE;
386     }
388 /* Check for memory size requirement and update the base */
389     count = 0;
390     bases[nwal_BUF_INDEX_INST] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)nwalInstMem);
391     if(NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_HANDLE < sizes[nwal_BUF_INDEX_INST])
392     {
393         printf(" 1memSize issue %d %d\n", 
394             sizes[nwal_BUF_INDEX_INST], NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_HANDLE);
395         /* Resize Memory */
396         return nwal_FALSE;
397         //while(1);
398     }
399     count++;
401     bases[nwal_BUF_INDEX_INT_HANDLES] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)nwalHandleMem);
402     if(NWAL_CHAN_HANDLE_SIZE  < sizes[nwal_BUF_INDEX_INT_HANDLES])
403     {
404         /* Resize Memory */
405         printf(" 2memSize issue %d %d\n", 
406             sizes[nwal_BUF_INDEX_INT_HANDLES], NWAL_CHAN_HANDLE_SIZE);
407         /* Resize Memory */
408         return nwal_FALSE;
409         //while(1);
411     }
412     count++;
413      bases[nwal_BUF_INDEX_PA_LLD_BUF0] =
414         (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)paEntry->paBuf0);
415     if((NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF0) < sizes[nwal_BUF_INDEX_PA_LLD_BUF0])
416     {
417         printf(" 3memSize issue %d %d\n", 
418             sizes[nwal_BUF_INDEX_PA_LLD_BUF0], NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF0);
419         /* Resize Memory */
420         return nwal_FALSE;
421         //while(1);
423     }
424     count++;
426     bases[nwal_BUF_INDEX_PA_LLD_BUF1] =
427         (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)paEntry->paBuf1);
428     if((NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF1) < sizes[nwal_BUF_INDEX_PA_LLD_BUF1])
429     {
430         printf(" 4memSize issue %d %d\n", 
431             sizes[nwal_BUF_INDEX_PA_LLD_BUF1], NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF1);
432         /* Resize Memory */
433         return nwal_FALSE;
434         //while(1);
436     }
437     count++;
439     bases[nwal_BUF_INDEX_PA_LLD_BUF2] =
440         (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)paEntry->paBuf2);
441     if((NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF2) < sizes[nwal_BUF_INDEX_PA_LLD_BUF2])
442     {
443         printf(" 5memSize issue %d %d\n", 
444             sizes[nwal_BUF_INDEX_PA_LLD_BUF2], NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF2);
445         /* Resize Memory */
446         return nwal_FALSE;
447         //while(1);
449     }
450     count++;
451 #ifdef NETAPI_ENABLE_SECURITY
452     bases[nwal_BUF_INDEX_SA_LLD_HANDLE] =
453         (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)saEntry->salldHandle);
454     if((NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE) < sizes[nwal_BUF_INDEX_SA_LLD_HANDLE])
455     {
456         printf(" 6memSize issue %d %d\n", 
457             sizes[nwal_BUF_INDEX_SA_LLD_HANDLE], 
458             NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE);
459         /* Resize Memory */
460         return nwal_FALSE;
461         //while(1);
463     }
464     count++;
466     bases[nwal_BUF_INDEX_SA_CONTEXT] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)netapi_VM_SaContextVaddr);
467     /* also save this here for easy access to sa_start */
468     nwalGlobCfg.scPoolBaseAddr = bases[nwal_BUF_INDEX_SA_CONTEXT];
469     count++;
471     bases[nwal_BUF_INDEX_SA_LLD_CHAN_HANDLE] =
472         (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)saEntry->salldChanHandle);
473     if((NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE_PER_CHAN * TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS*2) <
474         sizes[nwal_BUF_INDEX_SA_LLD_CHAN_HANDLE])
475     {
476         printf(" 7memSize issue %d %d\n", 
477             sizes[nwal_BUF_INDEX_SA_LLD_CHAN_HANDLE], 
478             NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE_PER_CHAN * TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS*2);
479         /* Resize Memory */
480         return nwal_FALSE;
481         //while(1);
483     }
484     count++;
485 #else
486     bases[nwal_BUF_INDEX_SA_LLD_HANDLE] = 0;
487     bases[nwal_BUF_INDEX_SA_CONTEXT] = 0;
488     bases[nwal_BUF_INDEX_SA_LLD_CHAN_HANDLE] = 0;
489     count = count+3;
490 #endif
491     if(count != nwal_N_BUFS)
492     {
493         printf("count failure: %d\n", count);
494         return nwal_FALSE;
495         //while(1);
496     }
498     /* Initialize NWAL module */
499     nwalRetVal = nwal_create(&nwalGlobCfg,
500                              &nwalSizeInfo,
501                              sizes,
502                              bases,
503                              &p_nwal_context->nwalInstHandle);
504     if(nwalRetVal != nwal_OK)
505     {
506         netapi_Log ("netapip_initNwal: nwal_create Failed %d\n",nwalRetVal);
507         return nwal_FALSE;
508         //while(1);
509     }
511     netapi_Log("netapip_initNwal- Global and Local Network initialization Successful \n");
512     return 1;
515 /********************************************************************
516  * FUNCTION PURPOSE:  Internal NETAPI function to start  NWAL 
517  ********************************************************************
518  * DESCRIPTION:  Internal NETAPI function to start NWAL, per thread/core
519  ********************************************************************/
520 int netapip_startNwal(Pktlib_HeapHandle pkt_heap,
521                       Pktlib_HeapHandle cmd_rx_heap,
522                       Pktlib_HeapHandle cmd_tx_heap,
523                       NETAPI_NWAL_LOCAL_CONTEXT_T *p,
524                       NETAPI_CFG_T *p_cfg,
525                       NETAPI_NWAL_GLOBAL_CONTEXT_T * p_nwal_glob_context  )
527     nwalLocCfg_t    nwalLocCfg;
528     int count=0;
529     static int first_time = 0;
530     nwal_RetValue       nwalRetVal;
532     memset(&nwalLocCfg,0,sizeof(nwalLocCfg));
534     /* Update the Start of Packet Offset for the default flows created 
535      * by NWAL
536      */
537     nwalLocCfg.rxSopPktOffset = p_cfg->def_flow_pkt_rx_offset;
538     nwalLocCfg.rxPktTailRoomSz = p_cfg->def_heap_tailroom_size;
540  /* Call back registration for the core */
541     nwalLocCfg.pRxPktCallBack = netapip_pktioNWALRxPktCallback;
542     nwalLocCfg.pCmdCallBack = netapip_netcpCfgNWALCmdCallBack;
543     nwalLocCfg.pPaStatsCallBack = netapip_netcpCfgNWALCmdPaStatsReply;
545     nwalLocCfg.pRxDmCallBack=  netapip_pktioNWALSBPktCallback; //sideband mode callback
547     /* Initialize Buffer Pool for Control packets from NetCP to Host */
548     nwalLocCfg.rxCtlPool.numBufPools = 1;
549     nwalLocCfg.rxCtlPool.bufPool[0].descSize = TUNE_NETAPI_DESC_SIZE;
550     nwalLocCfg.rxCtlPool.bufPool[0].bufSize = TUNE_NETAPI_CONFIG_MAX_CTL_RXTX_BUF_SIZE;
551     nwalLocCfg.rxCtlPool.bufPool[0].heapHandle = cmd_rx_heap;
553     /* Initialize Buffer Pool for Control packets from Host to NetCP */
554     nwalLocCfg.txCtlPool.numBufPools = 1;
555     nwalLocCfg.txCtlPool.bufPool[0].descSize = TUNE_NETAPI_DESC_SIZE;
556     nwalLocCfg.txCtlPool.bufPool[0].bufSize = TUNE_NETAPI_CONFIG_MAX_CTL_RXTX_BUF_SIZE;
557     nwalLocCfg.txCtlPool.bufPool[0].heapHandle =  cmd_tx_heap;
559 /* Initialize Buffer Pool for Packets from NetCP to Host */
560     nwalLocCfg.rxPktPool.numBufPools = 1;
561     nwalLocCfg.rxPktPool.bufPool[0].descSize = TUNE_NETAPI_DESC_SIZE;
562     nwalLocCfg.rxPktPool.bufPool[0].bufSize =  p_cfg->def_heap_buf_size;
563     nwalLocCfg.rxPktPool.bufPool[0].heapHandle = pkt_heap;
565 /* Initialize Buffer Pool for Packets from Host to NetCP */
566     nwalLocCfg.txPktPool.numBufPools = 1;
567     nwalLocCfg.txPktPool.bufPool[0].descSize = TUNE_NETAPI_DESC_SIZE;
568     nwalLocCfg.txPktPool.bufPool[0].bufSize =  p_cfg->def_heap_buf_size;
569     nwalLocCfg.txPktPool.bufPool[0].heapHandle = pkt_heap;
571     memcpy(&p->nwalLocCfg,&nwalLocCfg,sizeof(nwalLocCfg_t));
572     while(1)
573     {
574         nwalRetVal = nwal_start(p_nwal_glob_context->nwalInstHandle,&nwalLocCfg);
575         if(nwalRetVal == nwal_ERR_INVALID_STATE)
576         {
577             continue;
578         }
579         break;
580     }
582     if(nwalRetVal != nwal_OK)
583     {
584         netapi_Log (">nwal_start:Failed ->err %d !!!\n", nwalRetVal);
585         return -1;
586     }
587     p->state = NETAPI_NW_CXT_LOC_ACTIVE;
588     return 1;
592 /***********************************************************************
593  * FUNCTION PURPOSE:  Internal NETAPI function to initialize the 64 bit timer.
594  ***********************************************************************
595  * DESCRIPTION:  Internal NETAPI function to initialize the 64 bit timer. for tci6614 ONLY
596  **********************************************************************/
597 int netapip_initTimer(void)
599 #ifdef CORTEX_A8
600         return t64_start();
601 #endif
607 /***************************************************************************
608 * FUNCTION PURPOSE:  NETAPI internal function for virtual memory allocation.
609  ***************************************************************************
610  * DESCRIPTION:  NETAPI internal function for virtual memory allocation.
611  **************************************************************************/
613 static uint8_t* netapip_sharedMemoryMalloc(uint32_t size)
615 return  (uint8_t *)hplib_vmMemAlloc(size +pnetapiShm->netapi_global.cfg.def_heap_extra_size , 128, 0); 
618 /********************************************************************
619 * FUNCTION PURPOSE:  NETAPI internal function for virtual memory free.
620  ********************************************************************
621  * DESCRIPTION:  NETAPI internal function for virtual memory free.
622  ********************************************************************/
623 static void netapip_sharedMemoryFree(uint8_t* ptr, uint32_t size)
625     /* Do Nothing. */
626     netapi_Log("netapi Unexpected.  need to provide a free () for some reason!! \n");
627     return;
630 //defensive: clean out stuff hanging around
631 //
632 //  open a bunch of free queues and zap them
633 #define NQUEUES2CLEAR 35
634 static Qmss_QueueHnd tempQH[NQUEUES2CLEAR];
635 void netapip_cleanupAtStart(void)
637     int i;
638     uint8_t         isAllocated;
640     for(i=0;i<NQUEUES2CLEAR;i++) 
641     {
642         tempQH[i] = Qmss_queueOpen(Qmss_QueueType_GENERAL_PURPOSE_QUEUE,
643                                                   QMSS_PARAM_NOT_SPECIFIED, &isAllocated);
644         netapip_zapQ(tempQH[i]);
645     }
647     for(i=0;i<NQUEUES2CLEAR;i++)
648     {
649         Qmss_queueClose(tempQH[i]);
650     }
655 /********************************************************************
656 * FUNCTION PURPOSE:  NETAPI internal function system initialization
657  ********************************************************************
658  * DESCRIPTION:  NETAPI internal function system initialization
659  ********************************************************************/
660 int netapip_systemInit(NETAPI_HANDLE_T * handle,
661                        hplib_globalDeviceConfigParams_t *p_hplib_device_cfg,
662                        NETCP_CFG_GLOB_DEVICE_PARAMS_T   *p_netapi_device_cfg,
663                        nwalGlobalDeviceConfigParams_t   *p_nwal_device_cfg,
664                        Bool global_master_process)
666     int32_t             result;
667     Pktlib_HeapHandle   sharedHeapHandle;
668     Pktlib_HeapHandle   controlRxHeapHandle,controlTxHeapHandle;    
669     Pktlib_HeapCfg      heapCfg;
670     int32_t             errCode;
671     int count=0;
673 #ifdef NETAPI_USE_DDR
674     /* Init attributes for DDR */
675     netapi_VM_MempoolAttr[0].attr = HPLIB_ATTR_KM_CACHED0;
676     netapi_VM_MempoolAttr[0].phys_addr = 0;
677     netapi_VM_MempoolAttr[0].size = 0;
679        /* Init attributes for un-cached MSMC */
680     netapi_VM_MempoolAttr[1].attr = HPLIB_ATTR_UN_CACHED;
681     netapi_VM_MempoolAttr[1].phys_addr = CSL_MSMC_SRAM_REGS;
682     netapi_VM_MempoolAttr[1].size = TUNE_NETAPI_PERM_MEM_SZ;
683 #else
684     netapi_VM_MempoolAttr[1].attr = HPLIB_ATTR_KM_CACHED0;
685     netapi_VM_MempoolAttr[1].phys_addr = 0;
686     netapi_VM_MempoolAttr[1].size = 0;
688        /* Init attributes for un-cached MSMC */
689     netapi_VM_MempoolAttr[0].attr = HPLIB_ATTR_UN_CACHED;
690     netapi_VM_MempoolAttr[0].phys_addr = CSL_MSMC_SRAM_REGS;
691     netapi_VM_MempoolAttr[0].size = TUNE_NETAPI_PERM_MEM_SZ;
692 #endif
693     /* initialize all the memory we are going to use
694        - chunk for buffers, descriptors
695        - memory mapped peripherals we use, such as QMSS, PA, etc */
696     result = hplib_vmInit(&netapi_VM_VirtAddr[0],
697                           2,
698                           &netapi_VM_MempoolAttr[0],
699                           p_hplib_device_cfg);
701     if (global_master_process == TRUE)
702     {
703         hplib_initMallocArea(0);
704         hplib_initMallocArea(1);
705     }
706     else
707     {
708         if (hplib_checkMallocArea(0) != hplib_OK)
709             return -1;
710         if (hplib_checkMallocArea(1) != hplib_OK)
711             return -1;
712     }
714     if (result == hplib_OK) netapi_Log("netapip_systemInit: - memory set  up OK\n");
715     else {netapi_Log("netapip_systemInit: - memory set up failed\n"); return -1;}
717     if(global_master_process == FALSE)
718     {
719         //------------------------------------------------
720         //partial initialization.  For process, not for SOC
721         //------------------------------------------------
722        
723 /* Start the QMSS. */
724        if (netapip_startQm() != 1)
725        {
726           netapi_Log("netapip_systemInit: returned from netapip_startQm with failure\n");
727           return -1;
728        }
730         //open shared heap handle but create new controlRx & Tx heaps for this
731         //process
732         netapi_pktlib_ifTable.data_malloc  = netapip_sharedMemoryMalloc;
733         netapi_pktlib_ifTable.data_free    = netapip_sharedMemoryFree;
734         sharedHeapHandle = Pktlib_findHeapByName("netapi");
735         if (!sharedHeapHandle) { netapi_Log(">'netapi' heap create failed, Error Code: %d\n",errCode); return -1;}
736         handle->netcp_heap= sharedHeapHandle;
738         /* Update for Control */
739         heapCfg.name                = "netapi_control_rx";/*todo:add random#*/
740         heapCfg.sharedHeap          = 1;
741         heapCfg.dataBufferSize      = TUNE_NETAPI_CONFIG_MAX_CTL_RXTX_BUF_SIZE;
742         heapCfg.numPkts             = TUNE_NETAPI_CONFIG_NUM_CTL_RX_BUF;
743         heapCfg.numZeroBufferPackets= 0;
744         controlRxHeapHandle = Pktlib_createHeap(&heapCfg, &errCode);
745         if (!controlRxHeapHandle) { netapi_Log("netapi -'netapi_control_rx' heap create failed, Error Code: %d\n",errCode); return -1;}
746         handle->netcp_control_rx_heap= controlRxHeapHandle;
747         heapCfg.name                = "netapi_control_tx";
748         heapCfg.numPkts             = TUNE_NETAPI_CONFIG_NUM_CTL_TX_BUF;
749         controlTxHeapHandle = Pktlib_createHeap(&heapCfg, &errCode);
750         if (!controlTxHeapHandle) { netapi_Log("netapi -'netapi_control_tx' heap create failed, Error Code: %d\n",errCode); return -1;}
751         handle->netcp_control_tx_heap= controlTxHeapHandle;
753         /* Common Initialization for all threads in process */
754         while(count < TUNE_NETAPI_MAX_NUM_TRANS)
755         {
756           netapi_proc_global.nwal_context.transInfos[count].transId = count;
757           count++;
758         }
759         result = netapip_startNwal(sharedHeapHandle,
760                                controlRxHeapHandle,
761                                controlTxHeapHandle,
762                                &handle->nwal_local,
763                                &pnetapiShm->netapi_global.cfg,
764                                &pnetapiShm->netapi_global.nwal_context);
765        if (result<0) {netapi_Log("netapi start_nwal() failed\n"); return -1; }
766        netapi_Log("netapip_systemInit: returned from netapip_startNwal\n");
767     }
769 #ifdef NETAPI_ENABLE_SECURITY
770 #define SEC_CONTEXT_SZ 384  //not tunable
771 /* allocate 2x number of tunnels since we need one for inflow and one for data mode */
772     netapi_VM_SaContextVaddr = hplib_vmMemAlloc((TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS*2 *
773                                         SEC_CONTEXT_SZ), 128, 0);
774     if (!netapi_VM_SaContextVaddr)
775     {
776         netapi_Log("netapip_systemInit: Failed to map SA context memory region\n");
777         return (-1);
778     }
779     netapi_Log("netapip_systemInit: SA Memory mapped/allocated at address %p.\n", netapi_VM_SaContextVaddr);
781 #else
782    netapi_VM_SaContextVaddr= (char *) NULL;
783 #endif
785 /*  TODO: the QM regions is application specific and needs to be moved 
786     since number of regions created is appliction specific, put this in netapip_systemInit */
787     /* (3) Allocate 2 QM regions from continguous chunk above */
788     netapi_VM_QMemGlobalDescRam = 
789                                   (void *)hplib_vmMemAlloc((TUNE_NETAPI_NUM_GLOBAL_DESC *
790                                                             TUNE_NETAPI_DESC_SIZE),
791                                                              128, 0);
793     netapi_VM_QMemLocalDescRam =
794                                   (void *)hplib_vmMemAlloc((TUNE_NETAPI_NUM_LOCAL_DESC *
795                                                             TUNE_NETAPI_DESC_SIZE),
796                                                             128, 0);
797     netapi_Log("netapip_systemInit: desc region=%x global desc region=%x\n", netapi_VM_QMemLocalDescRam, netapi_VM_QMemGlobalDescRam);
799     //get timer running
800 #ifdef CORTEX_A8
801     netapip_initTimer();
802     netapi_Log("netapip_systemInit: returned from netapip_initTimer\n");
803 #endif
805     /* Initialize Queue Manager Sub System */
806     result = netapip_initQm (pnetapiShm->netapi_global.cfg.def_max_descriptors,
807                              p_netapi_device_cfg);
808     
809     if (result != 1)
810     {
811          netapi_Log("netapip_systemInit: returned from netapip_initQm with failure\n");
812         return -1;
813     }
815     /* Start the QMSS. */
816     if (netapip_startQm() != 1)
817     {
818       netapi_Log("netapip_systemInit: returned from netapip_startQm with failure\n");
819         return -1;
820     }
821     
823     //clean our old junk in 1st bunch of queues that will be allocated to us
824     netapip_cleanupAtStart();
825  netapi_Log("netapip_systemInit: returned from netapip_cleanupAtStart\n");
826     /* Initialize the global descriptor memory region. */
827     result= netapip_qmSetupMemRegion( 
828                       pnetapiShm->netapi_global.cfg.def_tot_descriptors_for_us,
829                       TUNE_NETAPI_DESC_SIZE,
830                       (unsigned int *) netapi_VM_QMemGlobalDescRam,
831                       TUNE_NETAPI_QM_GLOBAL_REGION);
832     if(result <0) {netapi_Log("netapip_systemInit: can't setup QM shared region\n"); return -1;}
834 netapi_Log("netapip_systemInit: returned from netapip_qmSetupMemRegion\n");
835     /* Initialize CPPI CPDMA */
837     result = netapip_initCppi (p_netapi_device_cfg);
838     netapi_Log("netapip_systemInit: returned from netapip_initCppi\n");
839     if (result != 1)
840     {
841         netapi_Log ("netapi: Error initializing CPPI SubSystem error code : %d\n",result);
842         return -1;
843     }
845     /* CPPI and Queue Manager are initialized. */
846     netapi_Log ("netapi: Queue Manager and CPPI are initialized.\n");
848     /* create main pkt heap */
849     /* Initialize the Shared Heaps. */
850     Pktlib_sharedHeapInit();
851     netapi_Log("netapip_systemInit: returned from Pktlib_sharedHeapInit\n");
852     /* Populate the heap interface table. */
853     netapi_pktlib_ifTable.data_malloc             = netapip_sharedMemoryMalloc;
854     netapi_pktlib_ifTable.data_free               = netapip_sharedMemoryFree;
856     /* Initialize the heap configuration. */
857     memset ((void *)&heapCfg, 0, sizeof(Pktlib_HeapCfg));
858     /* Populate the heap configuration */
859     heapCfg.name                = "netapi";
860     heapCfg.memRegion           = TUNE_NETAPI_QM_GLOBAL_REGION;
861     heapCfg.sharedHeap          = 1;
862     heapCfg.useStarvationQueue  = 0;
863     heapCfg.dataBufferSize      = pnetapiShm->netapi_global.cfg.def_heap_buf_size;
864     heapCfg.numPkts             = pnetapiShm->netapi_global.cfg.def_heap_n_descriptors;
865     heapCfg.numZeroBufferPackets= pnetapiShm->netapi_global.cfg.def_heap_n_zdescriptors;
866     heapCfg.heapInterfaceTable.data_malloc  = netapi_pktlib_ifTable.data_malloc;
867     heapCfg.heapInterfaceTable.data_free    = netapi_pktlib_ifTable.data_free;
868     heapCfg.dataBufferPktThreshold   = 0;
869     heapCfg.zeroBufferPktThreshold   = 0;
871     /* Create Shared Heap with specified configuration. */
872     sharedHeapHandle = Pktlib_createHeap(&heapCfg, &errCode);
873      netapi_Log("netapip_systemInit: returned from Pktlib_createHeap1\n");
874     //todo -> cleanup on failure
875     if (!sharedHeapHandle) { netapi_Log(">'netapi' heap create failed, Error Code: %d\n",errCode); return -1;}
876     handle->netcp_heap= sharedHeapHandle;
878     /* Update for Control */
879     heapCfg.name                = "netapi_control_rx";
880     heapCfg.sharedHeap          = 1;
881     heapCfg.dataBufferSize      = TUNE_NETAPI_CONFIG_MAX_CTL_RXTX_BUF_SIZE;
882     heapCfg.numPkts             = TUNE_NETAPI_CONFIG_NUM_CTL_RX_BUF;
883     heapCfg.numZeroBufferPackets= 0;
885     controlRxHeapHandle = Pktlib_createHeap(&heapCfg, &errCode);
886      netapi_Log("netapip_systemInit: returned from Pktlib_createHeap2\n");
887    //todo -> cleanup on failure
888    if (!controlRxHeapHandle) { netapi_Log("netapi -'netapi_control_rx' heap create failed, Error Code: %d\n",errCode); return -1;}
889    handle->netcp_control_rx_heap= controlRxHeapHandle;
891    
892    heapCfg.name                = "netapi_control_tx";
893    heapCfg.numPkts             = TUNE_NETAPI_CONFIG_NUM_CTL_TX_BUF;
895    controlTxHeapHandle = Pktlib_createHeap(&heapCfg, &errCode);
896     netapi_Log("netapip_systemInit: returned from Pktlib_createHeap3\n");
897    //todo -> cleanup on failure
898    if (!controlTxHeapHandle) { netapi_Log("netapi -'netapi_control_tx' heap create failed, Error Code: %d\n",errCode); return -1;}
899    handle->netcp_control_tx_heap= controlTxHeapHandle;
901     /* now NWAL */
902     result = netapip_initNwal(TUNE_NETAPI_QM_GLOBAL_REGION,
903                               &netapi_pktlib_ifTable,
904                               &pnetapiShm->netapi_global.nwal_context,
905                               &pnetapiShm->netapi_global.cfg,
906                               p_nwal_device_cfg);
907     if (result<0) {netapi_Log("netapi  init_nwal() failed\n"); return -1; }
908  netapi_Log("netapip_systemInit: returned from netapip_initNwal\n");
909     /* start NWAL */
912     /* Common Initialization for all cores */
913     while(count < TUNE_NETAPI_MAX_NUM_TRANS)
914     {
915         netapi_proc_global.nwal_context.transInfos[count].transId = count;
916         count++;
917     }
918     result = netapip_startNwal(sharedHeapHandle, 
919                                controlRxHeapHandle,
920                                controlTxHeapHandle,
921                                &handle->nwal_local,
922                                &pnetapiShm->netapi_global.cfg,
923                                &pnetapiShm->netapi_global.nwal_context);
924     if (result<0) {netapi_Log("netapi start_nwal() failed\n"); return -1; }
925     netapi_Log("netapip_systemInit: returned from netapip_startNwal\n");
926     return 0;
930 /****************************************************************************
931 * FUNCTION PURPOSE:  NETAPI internal function which performs clean for linux user space
932  ****************************************************************************
933  * DESCRIPTION:  NETAPI internal function which performs clean for linux user space
934  ***************************************************************************/
935 void netapip_zapQ(int queueNum)
937     char * descPtr;
938     int i;
939     if (!queueNum) 
940     {
941         return;
942     }
943     for (i=0;;i+=1 )
944     {
945         /* Pop descriptor from source queue */
946         if ((descPtr = (char *)pktio_mQmssQueuePopRaw(queueNum)) == NULL)
947         {
948             break;
949         }
950     }
951     if(i)
952     {
953         netapi_Log("netapip_zapQ: @recovery -  %d descriptors cleaned from qn %d\n",i, queueNum);
954     }
958 /****************************************************************************
959 * FUNCTION PURPOSE:  NETAPI internal function to display internal heap stats.
960  ****************************************************************************
961  * DESCRIPTION:  NETAPI internal function to display internal heap stats.
962  ***************************************************************************/
963 void netapi_dump_internal_heap_stats(void)
965     Pktlib_HeapStats    pktLibHeapStats;
966     Pktlib_getHeapStats(netapi_get_global()->nwal_context.pa2sa_heap,&pktLibHeapStats);
967     printf("PA2SA(ingress) stats>  #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets,
968                                 pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage);
969     printf("               >  #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n",
970                         pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter,
971                         pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter);
972 #if 0
973 Pktlib_getHeapStats(netapi_get_global()->nwal_context.pa2saTX_heap,&pktLibHeapStats);
974 netapi_Log("PA2SA(egress) stats>  #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets,
975                                 pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage);
976 netapi_Log("               >  #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n",
977                         pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter,
978                         pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter);
979 #endif
980     Pktlib_getHeapStats(netapi_get_global()->nwal_context.sa2pa_heap,&pktLibHeapStats);
981     printf("SA2PA stats>  #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets,
982                                 pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage);
983     printf("               >  #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n",
984                         pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter,
985                         pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter);