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