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