12d7cf70c4713233e8db78a72dcab19eae5df650
[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* rmClientServiceHandle)
180      int32_t          result;
181      Qmss_StartCfg    startCfg;
183      startCfg.rmServiceHandle = rmClientServiceHandle;
184      startCfg.pQmssGblCfgParams = NULL;
185      //result = Qmss_start();
186      result = Qmss_startCfg(&startCfg);
187      if (result != QMSS_SOK)
188      {
189          netapi_Log ("netapip_startQm: Qmss_start failed with error code %d\n", result);
190          return (-1);
191      }
192      return 1;
196 /*** NWAL Memory Buffer Configuration ***/
197 #define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_HANDLE     3400
198 uint8_t nwalInstMem[NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_HANDLE]ALIGN(CACHE_LINESZ);
200 #define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_MAC                    256
201 #define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_IPSEC_HANDLE_PER_CHAN      256
202 #define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_IP                     128
203 #define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_PORT                   128
204 #define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_L2L3_HDR               128
205 #define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_LOC_CONTEXT            384
206 #define NWAL_CHAN_HANDLE_SIZE    ((NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_MAC * TUNE_NETAPI_MAX_NUM_MAC) + \
207                                   (NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_IPSEC_HANDLE_PER_CHAN * TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS*2) + \
208                                   (NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_IP * TUNE_NETAPI_MAX_NUM_IP) + \
209                                   (NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_PORT * TUNE_NETAPI_MAX_NUM_PORTS)+ \
210                                   (NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_LOC_CONTEXT * TUNE_NETAPI_NUM_CORES) + \
211                                   (NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_L2L3_HDR * TUNE_NETAPI_MAX_NUM_L2_L3_HDRS))
213 uint8_t nwalHandleMem[NWAL_CHAN_HANDLE_SIZE]ALIGN(CACHE_LINESZ);
216 typedef struct NETAPI_PA_SHM_Tag
218 /* todo: Check if below size information can be made available from pa interface file */
219 #define NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF0      256
220 /* PA instance */
221 /* Memory used for the PA Instance. Needs to be assigned global uncached memory for chip */
222 uint8_t paBuf0[NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF0]ALIGN(CACHE_LINESZ);
224 /* Memory used for PA handles */
225 #define NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF1    128 * TUNE_NETAPI_MAX_NUM_MAC
226 uint8_t paBuf1[NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF1]ALIGN(CACHE_LINESZ);
228 #define NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF2   14592
231 uint8_t paBuf2[NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF2]ALIGN(CACHE_LINESZ);
232 } NETAPI_PA_SHM_T;
235 typedef struct NETAPI_SA_SHM_Tag
237 /* Memory used for SA LLD global Handle */
238 #define NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE    512
239 uint8_t salldHandle[NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE]ALIGN(CACHE_LINESZ);
241 /* Memory used by SA LLD per Channel */
242 #define NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE_PER_CHAN          512
243 uint8_t salldChanHandle[NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE_PER_CHAN * TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS*2]ALIGN(CACHE_LINESZ);
244 } NETAPI_SA_SHM_T;
246 /********************************************************************
247 * FUNCTION PURPOSE:  NETAPI internal function to gracefully cleanup when startup
248 *                                  issue occurs.
249  ********************************************************************
250  * DESCRIPTION:  NETAPI internal function to gracefully cleanup when startup
251 *                                  issue occurs.
252  ********************************************************************/
253 void netapipErrTeardown() { netapip_cleanupAtStart(); exit(-99); }
255 /********************************************************************
256  * FUNCTION PURPOSE:  Internal NETAPI function to initialize NWAL subsystem
257  ********************************************************************
258  * DESCRIPTION:  Internal NETAPI function to initialize NWAL subsytem
259  ********************************************************************/
260 int netapip_initNwal(
261     int region2use,
262     Pktlib_HeapIfTable * p_table,
263     NETAPI_NWAL_GLOBAL_CONTEXT_T * p_nwal_context,
264     NETAPI_CFG_T*p_cfg)
266     nwalSizeInfo_t  nwalSizeInfo;
267     nwal_RetValue   nwalRetVal;
268     nwalGlobCfg_t   nwalGlobCfg;
269     uint8_t         count;
270     int             sizes[nwal_N_BUFS];
271     int             aligns[nwal_N_BUFS];
272     void*           bases[nwal_N_BUFS];   
273     Pktlib_HeapCfg      heapCfg;
274     int32_t             errCode;
275     void* pBase = NULL;
276     NETAPI_PA_SHM_T* paEntry = NULL;
277     NETAPI_SA_SHM_T* saEntry = NULL;
279     memset(p_nwal_context,0,sizeof( NETAPI_NWAL_GLOBAL_CONTEXT_T) );
280     memset(&nwalGlobCfg,0,sizeof(nwalGlobCfg_t ) );
282     pBase = hplib_shmOpen();
283     if (pBase)
284     {
285         if(hplib_shmAddEntry(pBase, sizeof(NETAPI_PA_SHM_T), PA_ENTRY) == hplib_OK)
286         {
287             paEntry = (NETAPI_PA_SHM_T*)hplib_shmGetEntry(pBase,PA_ENTRY);
288             nwalGlobCfg.instPoolBaseAddr = (void *)paEntry;
289         }
290         else
291         {
292             netapi_Log("netapip_initNwal: Unable to Add shared memory segment for PASS\n");
293             return -1;
294         }
295         if(hplib_shmAddEntry(pBase, sizeof(NETAPI_SA_SHM_T), SA_ENTRY) == hplib_OK)
296         {
297             saEntry = (NETAPI_SA_SHM_T*)hplib_shmGetEntry(pBase,SA_ENTRY);
298             nwalGlobCfg.instPoolSaBaseAddr = (void*) saEntry;
299         }
300         else
301         {
302             netapi_Log("netapip_initNwal: Unable to Add shared memory segment for SASS\n");
303             return -1;
304         }
305         
306     }
307     /* Initialize Buffer Pool for NetCP PA to SA packets */
308     nwalGlobCfg.pa2SaBufPool.numBufPools = 1;
309     nwalGlobCfg.pa2SaBufPool.bufPool[0].descSize = TUNE_NETAPI_DESC_SIZE;
310     nwalGlobCfg.pa2SaBufPool.bufPool[0].bufSize =  p_cfg->def_heap_buf_size;
312     /* Initialize the heap configuration. */
313     memset ((void *)&heapCfg, 0, sizeof(Pktlib_HeapCfg));
314     /* Populate the heap configuration */
315     heapCfg.name                = "nwal PA2SA";
316     heapCfg.memRegion           = region2use;
317     heapCfg.sharedHeap          = 0;
318     heapCfg.useStarvationQueue  = 0;
319     heapCfg.dataBufferSize      = p_cfg->def_heap_buf_size;
320     heapCfg.numPkts             = TUNE_NETAPI_CONFIG_MAX_PA_TO_SA_DESC;
321     heapCfg.numZeroBufferPackets= 0;
322     heapCfg.heapInterfaceTable.data_malloc  = p_table->data_malloc;
323     heapCfg.heapInterfaceTable.data_free    = p_table->data_free;
324     heapCfg.dataBufferPktThreshold   = 0;
325     heapCfg.zeroBufferPktThreshold   = 0;
328     nwalGlobCfg.pa2SaBufPool.bufPool[0].heapHandle = p_nwal_context->pa2sa_heap=
329                       Pktlib_createHeap(&heapCfg, &errCode);
330     if(nwalGlobCfg.pa2SaBufPool.bufPool[0].heapHandle == NULL)
331     {
332         netapi_Log ("netapip_initNwal: Pktlib_createHeap:Heap Creation Failed for PA to SA Buffer Pool, Error Code: %d\n",
333                     errCode); 
334         netapipErrTeardown();
335         return -1;
336     }
338  /* Initialize Buffer Pool for NetCP SA to PA packets */
339     nwalGlobCfg.sa2PaBufPool.numBufPools = 1;
340     nwalGlobCfg.sa2PaBufPool.bufPool[0].descSize = TUNE_NETAPI_DESC_SIZE;
341     nwalGlobCfg.sa2PaBufPool.bufPool[0].bufSize =  p_cfg->def_heap_buf_size;
343      /* Populate the heap configuration */
344     heapCfg.name                = "nwal SA2PA";
345     heapCfg.numPkts             = TUNE_NETAPI_CONFIG_MAX_SA_TO_PA_DESC;
347     nwalGlobCfg.sa2PaBufPool.bufPool[0].heapHandle = p_nwal_context->sa2pa_heap=
348         Pktlib_createHeap(&heapCfg, &errCode);
349     if(nwalGlobCfg.sa2PaBufPool.bufPool[0].heapHandle == NULL)
350     {
351         netapi_Log ("netapip_initNwal: Pktlib_createHeap:Heap Creation Failed for SA to PA Buffer Pool, Error Code: %d\n",
352                      errCode); 
353         netapipErrTeardown();
354         return -1;
355     }
357     nwalGlobCfg.hopLimit = 5;/* Default TTL / Hop Limit */
358     nwalGlobCfg.paPowerOn = nwal_TRUE;
359     nwalGlobCfg.saPowerOn = nwal_TRUE;
360     nwalGlobCfg.paFwActive = nwal_TRUE;
361     nwalGlobCfg.saFwActive = nwal_FALSE;
364     /* Update nwal cfg with virtual PA and SA addresses */
367     nwalGlobCfg.paVirtBaseAddr = (uint32_t) netapi_VM_VirtAddr->passCfgVaddr;
368     nwalGlobCfg.saVirtBaseAddr = (uint32_t) netapi_VM_VirtAddr->passCfgVaddr +
369                                   CSL_NETCP_CFG_SA_CFG_REGS -
370                                   CSL_NETCP_CFG_REGS;
371         ;
373     nwalGlobCfg.rxDefPktQ = QMSS_PARAM_NOT_SPECIFIED;
376     /* Get the Buffer Requirement from NWAL */
377     memset(&nwalSizeInfo,0,sizeof(nwalSizeInfo));
378     nwalSizeInfo.nMaxMacAddress = TUNE_NETAPI_MAX_NUM_MAC;
379     nwalSizeInfo.nMaxIpAddress = TUNE_NETAPI_MAX_NUM_IP;
380     nwalSizeInfo.nMaxL4Ports = TUNE_NETAPI_MAX_NUM_PORTS;
381     nwalSizeInfo.nMaxIpSecChannels = TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS;//we allocate 2 per channel
382     nwalSizeInfo.nMaxDmSecChannels = TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS;//we allocate 2 per channel
383     nwalSizeInfo.nMaxL2L3Hdr = TUNE_NETAPI_MAX_NUM_L2_L3_HDRS;
384     nwalSizeInfo.nProc = TUNE_NETAPI_NUM_CORES;
385     nwalRetVal = nwal_getBufferReq(&nwalSizeInfo,
386                                    sizes,
387                                    aligns);
388     if(nwalRetVal != nwal_OK)
389     {
390         netapi_Log ("netapip_initNwal: nwal_getBufferReq Failed %d\n", nwalRetVal);
391         return nwal_FALSE;
392     }
394 /* Check for memory size requirement and update the base */
395     count = 0;
396     bases[nwal_BUF_INDEX_INST] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)nwalInstMem);
397     if(NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_HANDLE < sizes[nwal_BUF_INDEX_INST])
398     {
399         printf(" 1memSize issue %d %d\n", 
400             sizes[nwal_BUF_INDEX_INST], NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_HANDLE);
401         /* Resize Memory */
402         return nwal_FALSE;
403         //while(1);
404     }
405     count++;
407     bases[nwal_BUF_INDEX_INT_HANDLES] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)nwalHandleMem);
408     if(NWAL_CHAN_HANDLE_SIZE  < sizes[nwal_BUF_INDEX_INT_HANDLES])
409     {
410         /* Resize Memory */
411         printf(" 2memSize issue %d %d\n", 
412             sizes[nwal_BUF_INDEX_INT_HANDLES], NWAL_CHAN_HANDLE_SIZE);
413         /* Resize Memory */
414         return nwal_FALSE;
415         //while(1);
417     }
418     count++;
419      bases[nwal_BUF_INDEX_PA_LLD_BUF0] =
420         (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)paEntry->paBuf0);
421     if((NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF0) < sizes[nwal_BUF_INDEX_PA_LLD_BUF0])
422     {
423         printf(" 3memSize issue %d %d\n", 
424             sizes[nwal_BUF_INDEX_PA_LLD_BUF0], NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF0);
425         /* Resize Memory */
426         return nwal_FALSE;
427         //while(1);
429     }
430     count++;
432     bases[nwal_BUF_INDEX_PA_LLD_BUF1] =
433         (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)paEntry->paBuf1);
434     if((NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF1) < sizes[nwal_BUF_INDEX_PA_LLD_BUF1])
435     {
436         printf(" 4memSize issue %d %d\n", 
437             sizes[nwal_BUF_INDEX_PA_LLD_BUF1], NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF1);
438         /* Resize Memory */
439         return nwal_FALSE;
440         //while(1);
442     }
443     count++;
445     bases[nwal_BUF_INDEX_PA_LLD_BUF2] =
446         (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)paEntry->paBuf2);
447     if((NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF2) < sizes[nwal_BUF_INDEX_PA_LLD_BUF2])
448     {
449         printf(" 5memSize issue %d %d\n", 
450             sizes[nwal_BUF_INDEX_PA_LLD_BUF2], NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF2);
451         /* Resize Memory */
452         return nwal_FALSE;
453         //while(1);
455     }
456     count++;
457 #ifdef NETAPI_ENABLE_SECURITY
458     bases[nwal_BUF_INDEX_SA_LLD_HANDLE] =
459         (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)saEntry->salldHandle);
460     if((NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE) < sizes[nwal_BUF_INDEX_SA_LLD_HANDLE])
461     {
462         printf(" 6memSize issue %d %d\n", 
463             sizes[nwal_BUF_INDEX_SA_LLD_HANDLE], 
464             NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE);
465         /* Resize Memory */
466         return nwal_FALSE;
467         //while(1);
469     }
470     count++;
472     bases[nwal_BUF_INDEX_SA_CONTEXT] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)netapi_VM_SaContextVaddr);
473     /* also save this here for easy access to sa_start */
474     nwalGlobCfg.scPoolBaseAddr = bases[nwal_BUF_INDEX_SA_CONTEXT];
475     count++;
477     bases[nwal_BUF_INDEX_SA_LLD_CHAN_HANDLE] =
478         (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)saEntry->salldChanHandle);
479     if((NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE_PER_CHAN * TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS*2) <
480         sizes[nwal_BUF_INDEX_SA_LLD_CHAN_HANDLE])
481     {
482         printf(" 7memSize issue %d %d\n", 
483             sizes[nwal_BUF_INDEX_SA_LLD_CHAN_HANDLE], 
484             NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE_PER_CHAN * TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS*2);
485         /* Resize Memory */
486         return nwal_FALSE;
487         //while(1);
489     }
490     count++;
491 #else
492     bases[nwal_BUF_INDEX_SA_LLD_HANDLE] = 0;
493     bases[nwal_BUF_INDEX_SA_CONTEXT] = 0;
494     bases[nwal_BUF_INDEX_SA_LLD_CHAN_HANDLE] = 0;
495     count = count+3;
496 #endif
497     if(count != nwal_N_BUFS)
498     {
499         printf("count failure: %d\n", count);
500         return nwal_FALSE;
501         //while(1);
502     }
504     /* Initialize NWAL module */
505     nwalRetVal = nwal_create(&nwalGlobCfg,
506                              &nwalSizeInfo,
507                              sizes,
508                              bases,
509                              &p_nwal_context->nwalInstHandle);
510     if(nwalRetVal != nwal_OK)
511     {
512         netapi_Log ("netapip_initNwal: nwal_create Failed %d\n",nwalRetVal);
513         return nwal_FALSE;
514         //while(1);
515     }
517     netapi_Log("netapip_initNwal- Global and Local Network initialization Successful \n");
518     return 1;
521 /********************************************************************
522  * FUNCTION PURPOSE:  Internal NETAPI function to start  NWAL 
523  ********************************************************************
524  * DESCRIPTION:  Internal NETAPI function to start NWAL, per thread/core
525  ********************************************************************/
526 int netapip_startNwal(Pktlib_HeapHandle pkt_heap,
527                       Pktlib_HeapHandle cmd_rx_heap,
528                       Pktlib_HeapHandle cmd_tx_heap,
529                       NETAPI_NWAL_LOCAL_CONTEXT_T *p,
530                       NETAPI_CFG_T *p_cfg,
531                       NETAPI_NWAL_GLOBAL_CONTEXT_T * p_nwal_glob_context  )
533     nwalLocCfg_t    nwalLocCfg;
534     int count=0;
535     static int first_time = 0;
536     nwal_RetValue       nwalRetVal;
538     memset(&nwalLocCfg,0,sizeof(nwalLocCfg));
540     /* Update the Start of Packet Offset for the default flows created 
541      * by NWAL
542      */
543     nwalLocCfg.rxSopPktOffset = p_cfg->def_flow_pkt_rx_offset;
544     nwalLocCfg.rxPktTailRoomSz = p_cfg->def_heap_tailroom_size;
546  /* Call back registration for the core */
547     nwalLocCfg.pRxPktCallBack = netapip_pktioNWALRxPktCallback;
548     nwalLocCfg.pCmdCallBack = netapip_netcpCfgNWALCmdCallBack;
549     nwalLocCfg.pPaStatsCallBack = netapip_netcpCfgNWALCmdPaStatsReply;
551     nwalLocCfg.pRxDmCallBack=  netapip_pktioNWALSBPktCallback; //sideband mode callback
553     /* Initialize Buffer Pool for Control packets from NetCP to Host */
554     nwalLocCfg.rxCtlPool.numBufPools = 1;
555     nwalLocCfg.rxCtlPool.bufPool[0].descSize = TUNE_NETAPI_DESC_SIZE;
556     nwalLocCfg.rxCtlPool.bufPool[0].bufSize = TUNE_NETAPI_CONFIG_MAX_CTL_RXTX_BUF_SIZE;
557     nwalLocCfg.rxCtlPool.bufPool[0].heapHandle = cmd_rx_heap;
559     /* Initialize Buffer Pool for Control packets from Host to NetCP */
560     nwalLocCfg.txCtlPool.numBufPools = 1;
561     nwalLocCfg.txCtlPool.bufPool[0].descSize = TUNE_NETAPI_DESC_SIZE;
562     nwalLocCfg.txCtlPool.bufPool[0].bufSize = TUNE_NETAPI_CONFIG_MAX_CTL_RXTX_BUF_SIZE;
563     nwalLocCfg.txCtlPool.bufPool[0].heapHandle =  cmd_tx_heap;
565 /* Initialize Buffer Pool for Packets from NetCP to Host */
566     nwalLocCfg.rxPktPool.numBufPools = 1;
567     nwalLocCfg.rxPktPool.bufPool[0].descSize = TUNE_NETAPI_DESC_SIZE;
568     nwalLocCfg.rxPktPool.bufPool[0].bufSize =  p_cfg->def_heap_buf_size;
569     nwalLocCfg.rxPktPool.bufPool[0].heapHandle = pkt_heap;
571 /* Initialize Buffer Pool for Packets from Host to NetCP */
572     nwalLocCfg.txPktPool.numBufPools = 1;
573     nwalLocCfg.txPktPool.bufPool[0].descSize = TUNE_NETAPI_DESC_SIZE;
574     nwalLocCfg.txPktPool.bufPool[0].bufSize =  p_cfg->def_heap_buf_size;
575     nwalLocCfg.txPktPool.bufPool[0].heapHandle = pkt_heap;
577     memcpy(&p->nwalLocCfg,&nwalLocCfg,sizeof(nwalLocCfg_t));
578     while(1)
579     {
580         nwalRetVal = nwal_start(p_nwal_glob_context->nwalInstHandle,&nwalLocCfg);
581         if(nwalRetVal == nwal_ERR_INVALID_STATE)
582         {
583             continue;
584         }
585         break;
586     }
588     if(nwalRetVal != nwal_OK)
589     {
590         netapi_Log (">nwal_start:Failed ->err %d !!!\n", nwalRetVal);
591         return -1;
592     }
593     p->state = NETAPI_NW_CXT_LOC_ACTIVE;
594     return 1;
598 /***********************************************************************
599  * FUNCTION PURPOSE:  Internal NETAPI function to initialize the 64 bit timer.
600  ***********************************************************************
601  * DESCRIPTION:  Internal NETAPI function to initialize the 64 bit timer. for tci6614 ONLY
602  **********************************************************************/
603 int netapip_initTimer(void)
605 #ifdef CORTEX_A8
606         return t64_start();
607 #endif
613 /***************************************************************************
614 * FUNCTION PURPOSE:  NETAPI internal function for virtual memory allocation.
615  ***************************************************************************
616  * DESCRIPTION:  NETAPI internal function for virtual memory allocation.
617  **************************************************************************/
619 static uint8_t* netapip_sharedMemoryMalloc(uint32_t size)
621     //printf("netapip_sharedMemoryMalloc called for size: %d\n", size);
622     return  (uint8_t *)hplib_vmMemAlloc(size + 
623                                     pnetapiShm->netapi_global.cfg.def_heap_extra_size ,
624                                     128,
625                                     0); 
628 /********************************************************************
629 * FUNCTION PURPOSE:  NETAPI internal function for virtual memory free.
630  ********************************************************************
631  * DESCRIPTION:  NETAPI internal function for virtual memory free.
632  ********************************************************************/
633 static void netapip_sharedMemoryFree(uint8_t* ptr, uint32_t size)
635     /* Do Nothing. */
636     //printf("netapip_sharedMemoryMalloc called for size: %d\n", size);
637     //hplib_vmMemFree(ptr, size + pnetapiShm->netapi_global.cfg.def_heap_extra_size,0);
638     netapi_Log("netapi Unexpected.  need to provide a free () for some reason!! \n");
639     return;
642 //defensive: clean out stuff hanging around
643 //
644 //  open a bunch of free queues and zap them
645 #define NQUEUES2CLEAR 35
646 static Qmss_QueueHnd tempQH[NQUEUES2CLEAR];
647 void netapip_cleanupAtStart(void)
649     int i;
650     uint8_t         isAllocated;
652     for(i=0;i<NQUEUES2CLEAR;i++) 
653     {
654         tempQH[i] = Qmss_queueOpen(Qmss_QueueType_GENERAL_PURPOSE_QUEUE,
655                                                   QMSS_PARAM_NOT_SPECIFIED, &isAllocated);
656         netapip_zapQ(tempQH[i]);
657     }
659     for(i=0;i<NQUEUES2CLEAR;i++)
660     {
661         Qmss_queueClose(tempQH[i]);
662     }
667 /********************************************************************
668 * FUNCTION PURPOSE:  NETAPI internal function system initialization
669  ********************************************************************
670  * DESCRIPTION:  NETAPI internal function system initialization
671  ********************************************************************/
672 int netapip_systemInit(NETAPI_HANDLE_T * handle,
673                        Bool global_master_process)
676     int32_t             result;
677     Pktlib_HeapHandle   sharedHeapHandle;
678     Pktlib_HeapHandle   controlRxHeapHandle,controlTxHeapHandle;    
679     Pktlib_HeapCfg      heapCfg;
680     int32_t             errCode;
681     int count=0;
683 #ifdef NETAPI_USE_DDR
684     /* Init attributes for DDR */
685     netapi_VM_MempoolAttr[0].attr = HPLIB_ATTR_KM_CACHED0;
686     netapi_VM_MempoolAttr[0].phys_addr = 0;
687     netapi_VM_MempoolAttr[0].size = 0;
689        /* Init attributes for un-cached MSMC */
690     netapi_VM_MempoolAttr[1].attr = HPLIB_ATTR_UN_CACHED;
691     netapi_VM_MempoolAttr[1].phys_addr = CSL_MSMC_SRAM_REGS;
692     netapi_VM_MempoolAttr[1].size = TUNE_NETAPI_PERM_MEM_SZ;
693 #else
694     netapi_VM_MempoolAttr[1].attr = HPLIB_ATTR_KM_CACHED0;
695     netapi_VM_MempoolAttr[1].phys_addr = 0;
696     netapi_VM_MempoolAttr[1].size = 0;
698        /* Init attributes for un-cached MSMC */
699     netapi_VM_MempoolAttr[0].attr = HPLIB_ATTR_UN_CACHED;
700     netapi_VM_MempoolAttr[0].phys_addr = CSL_MSMC_SRAM_REGS;
701     netapi_VM_MempoolAttr[0].size = TUNE_NETAPI_PERM_MEM_SZ;
702 #endif
703     /* initialize all the memory we are going to use
704        - chunk for buffers, descriptors
705        - memory mapped peripherals we use, such as QMSS, PA, etc */
706     result = hplib_vmInit(&netapi_VM_VirtAddr[0],
707                           2,
708                           &netapi_VM_MempoolAttr[0]);
710     if (result == hplib_OK)
711         netapi_Log("netapip_systemInit: - hplib_vmInit pass\n");
712     else
713     {
714         netapi_Log("netapip_systemInit: - hplib_vmInit fail\n");
715         return -1;
716     }
720     if (global_master_process == NETAPI_TRUE)
721     {
722         hplib_initMallocArea(0);
723         hplib_initMallocArea(1);
724     }
725     else
726     {
727         if (hplib_checkMallocArea(0) != hplib_OK)
728             return -1;
729         if (hplib_checkMallocArea(1) != hplib_OK)
730             return -1;
731     }
734     if(global_master_process == NETAPI_FALSE)
735     {
736         /****************************************************
737          * partial initialization.  For process, not for SOC
738          ***************************************************/
739        
740        /* Start the QMSS. */
741        if (netapip_startQm(pnetapiShm->netapi_global.cfg.rmHandle) != 1)
742        {
743           netapi_Log("netapip_systemInit: returned from netapip_startQm with failure\n");
744           return -1;
745        }
747         //open shared heap handle but create new controlRx & Tx heaps for this
748         //process
749         netapi_pktlib_ifTable.data_malloc  = netapip_sharedMemoryMalloc;
750         netapi_pktlib_ifTable.data_free    = netapip_sharedMemoryFree;
751         sharedHeapHandle = Pktlib_findHeapByName("netapi");
752         if (!sharedHeapHandle) { netapi_Log(">'netapi' heap create failed, Error Code: %d\n",errCode); return -1;}
753         handle->netcp_heap= sharedHeapHandle;
755         /* Update for Control */
756         heapCfg.name                = "netapi_control_rx";/*todo:add random#*/
757         heapCfg.sharedHeap          = 1;
758         heapCfg.dataBufferSize      = TUNE_NETAPI_CONFIG_MAX_CTL_RXTX_BUF_SIZE;
759         heapCfg.numPkts             = TUNE_NETAPI_CONFIG_NUM_CTL_RX_BUF;
760         heapCfg.numZeroBufferPackets= 0;
761         controlRxHeapHandle = Pktlib_createHeap(&heapCfg, &errCode);
762         if (!controlRxHeapHandle) { netapi_Log("netapi -'netapi_control_rx' heap create failed, Error Code: %d\n",errCode); return -1;}
763         handle->netcp_control_rx_heap= controlRxHeapHandle;
764         heapCfg.name                = "netapi_control_tx";
765         heapCfg.numPkts             = TUNE_NETAPI_CONFIG_NUM_CTL_TX_BUF;
766         controlTxHeapHandle = Pktlib_createHeap(&heapCfg, &errCode);
767         if (!controlTxHeapHandle) { netapi_Log("netapi -'netapi_control_tx' heap create failed, Error Code: %d\n",errCode); return -1;}
768         handle->netcp_control_tx_heap= controlTxHeapHandle;
770         /* Common Initialization for all threads in process */
771         while(count < TUNE_NETAPI_MAX_NUM_TRANS)
772         {
773           netapi_proc_global.nwal_context.transInfos[count].transId = count;
774           count++;
775         }
776         result = netapip_startNwal(sharedHeapHandle,
777                                controlRxHeapHandle,
778                                controlTxHeapHandle,
779                                &handle->nwal_local,
780                                &pnetapiShm->netapi_global.cfg,
781                                &pnetapiShm->netapi_global.nwal_context);
782         if (result<0)
783         {
784             netapi_Log("netapi start_nwal() failed\n");
785             return -1;
786         }
787         netapi_Log("netapip_systemInit: returned from netapip_startNwal\n");
788     }
790 #ifdef NETAPI_ENABLE_SECURITY
791 #define SEC_CONTEXT_SZ 384  //not tunable
792 /* allocate 2x number of tunnels since we need one for inflow and one for data mode */
793     netapi_VM_SaContextVaddr = hplib_vmMemAlloc((TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS*2 *
794                                         SEC_CONTEXT_SZ), 128, 0);
795     if (!netapi_VM_SaContextVaddr)
796     {
797         netapi_Log("netapip_systemInit: Failed to map SA context memory region\n");
798         return (-1);
799     }
800     netapi_Log("netapip_systemInit: SA Memory mapped/allocated at address %p.\n", netapi_VM_SaContextVaddr);
802 #else
803    netapi_VM_SaContextVaddr= (char *) NULL;
804 #endif
806     /* (3) Allocate 2 QM regions from continguous chunk above */
807     netapi_VM_QMemGlobalDescRam = 
808                                   (void *)hplib_vmMemAlloc((TUNE_NETAPI_NUM_GLOBAL_DESC *
809                                                             TUNE_NETAPI_DESC_SIZE),
810                                                              128, 0);
812     netapi_VM_QMemLocalDescRam =
813                                   (void *)hplib_vmMemAlloc((TUNE_NETAPI_NUM_LOCAL_DESC *
814                                                             TUNE_NETAPI_DESC_SIZE),
815                                                             128, 0);
816     netapi_Log("netapip_systemInit: desc region=%x global desc region=%x\n", netapi_VM_QMemLocalDescRam, netapi_VM_QMemGlobalDescRam);
818     //get timer running
819 #ifdef CORTEX_A8
820     netapip_initTimer();
821     netapi_Log("netapip_systemInit: returned from netapip_initTimer\n");
822 #endif
824     /* Initialize Queue Manager Sub System */
825     result = netapip_initQm (pnetapiShm->netapi_global.cfg.def_max_descriptors,
826                              pnetapiShm->netapi_global.cfg.rmHandle);
827     
828     if (result != 1)
829     {
830          netapi_Log("netapip_systemInit: returned from netapip_initQm with failure\n");
831         return -1;
832     }
834     /* Start the QMSS. */
835     if (netapip_startQm(pnetapiShm->netapi_global.cfg.rmHandle) != 1)
836     {
837       netapi_Log("netapip_systemInit: returned from netapip_startQm with failure\n");
838         return -1;
839     }
840     
842     //clean our old junk in 1st bunch of queues that will be allocated to us
843     netapip_cleanupAtStart();
844     /* Initialize the global descriptor memory region. */
845     result= netapip_qmSetupMemRegion( 
846                       pnetapiShm->netapi_global.cfg.def_tot_descriptors_for_us,
847                       TUNE_NETAPI_DESC_SIZE,
848                       (unsigned int *) netapi_VM_QMemGlobalDescRam,
849                       TUNE_NETAPI_QM_GLOBAL_REGION);
850     if(result <0)
851     {
852         netapi_Log("netapip_systemInit: can't setup QM shared region\n");
853         return -1;
854     }
856     /* Initialize CPPI CPDMA */
858     result = netapip_initCppi(pnetapiShm->netapi_global.cfg.rmHandle);
859     if (result != 1)
860     {
861         netapi_Log ("netapi: Error initializing CPPI SubSystem error code : %d\n",result);
862         return -1;
863     }
865     /* CPPI and Queue Manager are initialized. */
866     netapi_Log ("netapi: Queue Manager and CPPI are initialized.\n");
868     /* create main pkt heap */
869     /* Initialize the Shared Heaps. */
870     Pktlib_sharedHeapInit();
871     /* Populate the heap interface table. */
872     netapi_pktlib_ifTable.data_malloc             = netapip_sharedMemoryMalloc;
873     netapi_pktlib_ifTable.data_free               = netapip_sharedMemoryFree;
875     /* Initialize the heap configuration. */
876     memset ((void *)&heapCfg, 0, sizeof(Pktlib_HeapCfg));
877     /* Populate the heap configuration */
878     heapCfg.name                = "netapi";
879     heapCfg.memRegion           = TUNE_NETAPI_QM_GLOBAL_REGION;
880     heapCfg.sharedHeap          = 1;
881     heapCfg.useStarvationQueue  = 0;
882     heapCfg.dataBufferSize      = pnetapiShm->netapi_global.cfg.def_heap_buf_size;
883     heapCfg.numPkts             = pnetapiShm->netapi_global.cfg.def_heap_n_descriptors;
884     heapCfg.numZeroBufferPackets= pnetapiShm->netapi_global.cfg.def_heap_n_zdescriptors;
885     heapCfg.heapInterfaceTable.data_malloc  = netapi_pktlib_ifTable.data_malloc;
886     heapCfg.heapInterfaceTable.data_free    = netapi_pktlib_ifTable.data_free;
887     heapCfg.dataBufferPktThreshold   = 0;
888     heapCfg.zeroBufferPktThreshold   = 0;
890     /* Create Shared Heap with specified configuration. */
891     sharedHeapHandle = Pktlib_createHeap(&heapCfg, &errCode);
892     //todo -> cleanup on failure
893     if (!sharedHeapHandle) { netapi_Log(">'netapi' heap create failed, Error Code: %d\n",errCode); return -1;}
894     handle->netcp_heap= sharedHeapHandle;
896     /* Update for Control */
897     heapCfg.name                = "netapi_control_rx";
898     heapCfg.sharedHeap          = 1;
899     heapCfg.dataBufferSize      = TUNE_NETAPI_CONFIG_MAX_CTL_RXTX_BUF_SIZE;
900     heapCfg.numPkts             = TUNE_NETAPI_CONFIG_NUM_CTL_RX_BUF;
901     heapCfg.numZeroBufferPackets= 0;
903     controlRxHeapHandle = Pktlib_createHeap(&heapCfg, &errCode);
904    //todo -> cleanup on failure
905    if (!controlRxHeapHandle) { netapi_Log("netapi -'netapi_control_rx' heap create failed, Error Code: %d\n",errCode); return -1;}
906    handle->netcp_control_rx_heap= controlRxHeapHandle;
908    
909    heapCfg.name                = "netapi_control_tx";
910    heapCfg.numPkts             = TUNE_NETAPI_CONFIG_NUM_CTL_TX_BUF;
912    controlTxHeapHandle = Pktlib_createHeap(&heapCfg, &errCode);
913    //todo -> cleanup on failure
914    if (!controlTxHeapHandle) { netapi_Log("netapi -'netapi_control_tx' heap create failed, Error Code: %d\n",errCode); return -1;}
915    handle->netcp_control_tx_heap= controlTxHeapHandle;
917     /* now NWAL */
918     result = netapip_initNwal(TUNE_NETAPI_QM_GLOBAL_REGION,
919                               &netapi_pktlib_ifTable,
920                               &pnetapiShm->netapi_global.nwal_context,
921                               &pnetapiShm->netapi_global.cfg);
923     if (result<0) {netapi_Log("netapi  init_nwal() failed\n"); return -1; }
924  netapi_Log("netapip_systemInit: returned from netapip_initNwal\n");
925     /* start NWAL */
928     /* Common Initialization for all cores */
929     while(count < TUNE_NETAPI_MAX_NUM_TRANS)
930     {
931         netapi_proc_global.nwal_context.transInfos[count].transId = count;
932         count++;
933     }
934     result = netapip_startNwal(sharedHeapHandle, 
935                                controlRxHeapHandle,
936                                controlTxHeapHandle,
937                                &handle->nwal_local,
938                                &pnetapiShm->netapi_global.cfg,
939                                &pnetapiShm->netapi_global.nwal_context);
940     if (result<0) {netapi_Log("netapi start_nwal() failed\n"); return -1; }
941     netapi_Log("netapip_systemInit: returned from netapip_startNwal\n");
942     return 0;
946 /****************************************************************************
947 * FUNCTION PURPOSE:  NETAPI internal function which performs clean for linux user space
948  ****************************************************************************
949  * DESCRIPTION:  NETAPI internal function which performs clean for linux user space
950  ***************************************************************************/
951 void netapip_zapQ(int queueNum)
953     char * descPtr;
954     int i;
955     if (!queueNum) 
956     {
957         return;
958     }
959     for (i=0;;i+=1 )
960     {
961         /* Pop descriptor from source queue */
962         if ((descPtr = (char *)pktio_mQmssQueuePopRaw(queueNum)) == NULL)
963         {
964             break;
965         }
966     }
967     if(i)
968     {
969         netapi_Log("netapip_zapQ: @recovery -  %d descriptors cleaned from qn %d\n",i, queueNum);
970     }
974 /****************************************************************************
975 * FUNCTION PURPOSE:  NETAPI internal function to display internal heap stats.
976  ****************************************************************************
977  * DESCRIPTION:  NETAPI internal function to display internal heap stats.
978  ***************************************************************************/
979 void netapi_dump_internal_heap_stats(void)
981     Pktlib_HeapStats    pktLibHeapStats;
982     Pktlib_getHeapStats(netapi_get_global()->nwal_context.pa2sa_heap,&pktLibHeapStats);
983     printf("PA2SA(ingress) stats>  #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets,
984                                 pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage);
985     printf("               >  #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n",
986                         pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter,
987                         pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter);
988 #if 0
989 Pktlib_getHeapStats(netapi_get_global()->nwal_context.pa2saTX_heap,&pktLibHeapStats);
990 netapi_Log("PA2SA(egress) stats>  #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets,
991                                 pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage);
992 netapi_Log("               >  #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n",
993                         pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter,
994                         pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter);
995 #endif
996     Pktlib_getHeapStats(netapi_get_global()->nwal_context.sa2pa_heap,&pktLibHeapStats);
997     printf("SA2PA stats>  #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets,
998                                 pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage);
999     printf("               >  #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n",
1000                         pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter,
1001                         pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter);