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 {
145 //Qmss_MemRegInfo memInfo;
146 Int32 result;
147 Int n;
148 static int netapi_qm_region_index=0;
150 memset(&memInfo,0,sizeof(Qmss_MemRegInfo));
151 memInfo.descBase = pDescMemBase;
152 memInfo.descSize = descSize;
153 memInfo.descNum = numDesc;
154 memInfo.manageDescFlag = Qmss_ManageDesc_MANAGE_DESCRIPTOR;
155 //memInfo.memRegion = memRegion;
156 memInfo.memRegion = -1;
157 #if 0
158 if(memRegion == TUNE_NETAPI_QM_GLOBAL_REGION)
159 {
160 memInfo.startIndex = TUNE_NETAPI_QM_START_INDEX; //was 0
161 netapi_qm_region_index += numDesc;
162 }else if(memRegion ==NETAPI_LOCAL_REGION)
163 {
164 /* 2nd region for descriptors (perhaps private?) */
165 memInfo.startIndex = netapi_qm_region_index;
166 }
167 else
168 {
169 return -1 ;
170 }
171 #endif
172 memset (pDescMemBase, 0, (descSize * numDesc));
174 result = Qmss_insertMemoryRegion (&memInfo);
176 if (result < QMSS_SOK)
177 {
178 netapi_Log ("netapip_qmSetupMemRegion: Qmss_insertMemoryRegion returned error code %d\n", result);
179 return (-1);
180 }
181 printf("netapip_qmSetupMemRegion: region: %d\n", memInfo.memRegion);
182 netapi_proc_master->memRegion = memInfo.memRegion;
183 return 1;
184 }
186 /********************************************************************
187 * FUNCTION PURPOSE: Internal NETAPI function to start QM
188 ********************************************************************
189 * DESCRIPTION: Internal NETAPI function to start QM
190 * once per thread/core
191 ********************************************************************/
192 int netapip_startQm(void* rmClientServiceHandle)
193 {
194 int32_t result;
195 Qmss_StartCfg startCfg;
197 startCfg.rmServiceHandle = rmClientServiceHandle;
198 startCfg.pQmssGblCfgParams = NULL;
199 //result = Qmss_start();
200 result = Qmss_startCfg(&startCfg);
201 if (result != QMSS_SOK)
202 {
203 netapi_Log ("netapip_startQm: Qmss_start failed with error code %d\n", result);
204 return (-1);
205 }
206 return 1;
207 }
210 /*** NWAL Memory Buffer Configuration ***/
211 #define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_HANDLE 3400
212 //uint8_t nwalInstMem[NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_HANDLE]ALIGN(CACHE_LINESZ);
215 #define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_MAC 256
216 #define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_IPSEC_HANDLE_PER_CHAN 256
217 #define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_IP 128
218 #define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_PORT 128
219 #define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_L2L3_HDR 128
220 #define NWAL_CHAN_HANDLE_SIZE ((NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_MAC * TUNE_NETAPI_MAX_NUM_MAC) + \
221 (NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_IPSEC_HANDLE_PER_CHAN * TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS*2) + \
222 (NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_IP * TUNE_NETAPI_MAX_NUM_IP) + \
223 (NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_PORT * TUNE_NETAPI_MAX_NUM_PORTS)+ \
224 (NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_L2L3_HDR * TUNE_NETAPI_MAX_NUM_L2_L3_HDRS))
226 typedef struct NETAPI_NWAL_SHM_Tag
227 {
228 uint8_t nwalInstMem[NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_HANDLE]ALIGN(CACHE_LINESZ);
229 uint8_t nwalHandleMem[NWAL_CHAN_HANDLE_SIZE]ALIGN(CACHE_LINESZ);
230 } NETAPI_NWAL_SHM_T;
233 typedef struct NETAPI_PA_SHM_Tag
234 {
235 /* todo: Check if below size information can be made available from pa interface file */
236 #define NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF0 256
237 /* PA instance */
238 /* Memory used for the PA Instance. Needs to be assigned global uncached memory for chip */
239 uint8_t paBuf0[NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF0]ALIGN(CACHE_LINESZ);
241 /* Memory used for PA handles */
242 #define NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF1 128 * TUNE_NETAPI_MAX_NUM_MAC
243 uint8_t paBuf1[NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF1]ALIGN(CACHE_LINESZ);
245 #define NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF2 14592
248 uint8_t paBuf2[NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF2]ALIGN(CACHE_LINESZ);
249 } NETAPI_PA_SHM_T;
252 typedef struct NETAPI_SA_SHM_Tag
253 {
254 /* Memory used for SA LLD global Handle */
255 #define NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE 512
256 uint8_t salldHandle[NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE]ALIGN(CACHE_LINESZ);
258 /* Memory used by SA LLD per Channel */
259 #define NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE_PER_CHAN 512
260 uint8_t salldChanHandle[NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE_PER_CHAN * TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS*2]ALIGN(CACHE_LINESZ);
261 } NETAPI_SA_SHM_T;
270 /********************************************************************
271 * FUNCTION PURPOSE: NETAPI internal function to gracefully cleanup when startup
272 * issue occurs.
273 ********************************************************************
274 * DESCRIPTION: NETAPI internal function to gracefully cleanup when startup
275 * issue occurs.
276 ********************************************************************/
277 void netapipErrTeardown() { netapip_cleanupAtStart(); exit(-99); }
279 /********************************************************************
280 * FUNCTION PURPOSE: Internal NETAPI function to initialize NWAL subsystem
281 ********************************************************************
282 * DESCRIPTION: Internal NETAPI function to initialize NWAL subsytem
283 ********************************************************************/
284 int netapip_initNwal(
285 int region2use,
286 Pktlib_HeapIfTable * p_table,
287 NETAPI_NWAL_GLOBAL_CONTEXT_T * p_nwal_context,
288 NETAPI_CFG_T*p_cfg)
289 {
290 nwalSizeInfo_t nwalSizeInfo;
291 nwal_RetValue nwalRetVal;
292 nwalGlobCfg_t nwalGlobCfg;
293 nwalBaseAddrCfg_t nwalBaseAddrCfg;
294 uint8_t count;
295 int sizes[nwal_N_BUFS];
296 int aligns[nwal_N_BUFS];
297 void* bases[nwal_N_BUFS];
298 Pktlib_HeapCfg heapCfg;
299 int32_t errCode = 0;
300 void* pBase = NULL;
301 NETAPI_PA_SHM_T* paEntry = NULL;
302 NETAPI_SA_SHM_T* saEntry = NULL;
303 NETAPI_NWAL_SHM_T* nwalEntry = NULL;
304 uint32_t localCtxSize = 0;
305 memset(p_nwal_context,0,sizeof( NETAPI_NWAL_GLOBAL_CONTEXT_T) );
306 memset(&nwalGlobCfg,0,sizeof(nwalGlobCfg_t ) );
307 memset (&nwalBaseAddrCfg, 0, sizeof(nwalBaseAddrCfg_t));
308 pBase = hplib_shmOpen();
309 if (pBase)
310 {
311 if(hplib_shmAddEntry(pBase, sizeof(NETAPI_PA_SHM_T), PA_ENTRY) == hplib_OK)
312 {
313 paEntry = (NETAPI_PA_SHM_T*)hplib_shmGetEntry(pBase,PA_ENTRY);
314 nwalBaseAddrCfg.pInstPoolPaBaseAddr= (void *)paEntry;
315 }
316 else
317 {
318 netapi_Log("netapip_initNwal: Unable to Add shared memory segment for PASS\n");
319 return -1;
320 }
321 if(hplib_shmAddEntry(pBase, sizeof(NETAPI_SA_SHM_T), SA_ENTRY) == hplib_OK)
322 {
323 saEntry = (NETAPI_SA_SHM_T*)hplib_shmGetEntry(pBase,SA_ENTRY);
324 nwalBaseAddrCfg.pInstPoolSaBaseAddr= (void*) saEntry;
325 }
326 else
327 {
328 netapi_Log("netapip_initNwal: Unable to Add shared memory segment for SASS\n");
329 return -1;
330 }
331 if(hplib_shmAddEntry(pBase, sizeof(NETAPI_NWAL_SHM_T), NWAL_ENTRY) == hplib_OK)
332 {
333 printf("netapip_initNwal: calling shmGetEntry for nwal\n");
334 nwalEntry = (NETAPI_NWAL_SHM_T*)hplib_shmGetEntry(pBase,NWAL_ENTRY);
335 printf("netapip_initNwal: base address of nwal entry: 0x%x\n", (uint32_t) nwalEntry);
336 }
337 else
338 {
339 netapi_Log("netapip_initNwal: Unable to Add shared memory segment for SASS\n");
340 return -1;
341 }
343 }
344 /* Initialize Buffer Pool for NetCP PA to SA packets */
345 nwalGlobCfg.pa2SaBufPool.numBufPools = 1;
346 nwalGlobCfg.pa2SaBufPool.bufPool[0].descSize = TUNE_NETAPI_DESC_SIZE;
347 nwalGlobCfg.pa2SaBufPool.bufPool[0].bufSize = p_cfg->def_heap_buf_size;
349 /* Initialize the heap configuration. */
350 memset ((void *)&heapCfg, 0, sizeof(Pktlib_HeapCfg));
351 /* Populate the heap configuration */
352 heapCfg.name = "nwal PA2SA";
353 heapCfg.memRegion = region2use;
354 heapCfg.sharedHeap = 0;
355 heapCfg.useStarvationQueue = 0;
356 heapCfg.dataBufferSize = p_cfg->def_heap_buf_size;
357 heapCfg.numPkts = TUNE_NETAPI_CONFIG_MAX_PA_TO_SA_DESC;
358 heapCfg.numZeroBufferPackets= 0;
359 heapCfg.heapInterfaceTable.data_malloc = p_table->data_malloc;
360 heapCfg.heapInterfaceTable.data_free = p_table->data_free;
361 heapCfg.dataBufferPktThreshold = 0;
362 heapCfg.zeroBufferPktThreshold = 0;
365 nwalGlobCfg.pa2SaBufPool.bufPool[0].heapHandle = p_nwal_context->pa2sa_heap=
366 Pktlib_createHeap(&heapCfg, &errCode);
367 if(nwalGlobCfg.pa2SaBufPool.bufPool[0].heapHandle == NULL)
368 {
369 netapi_Log ("netapip_initNwal: Pktlib_createHeap:Heap Creation Failed for PA to SA Buffer Pool, Error Code: %d\n",
370 errCode);
371 netapipErrTeardown();
372 return -1;
373 }
375 /* Initialize Buffer Pool for NetCP SA to PA packets */
376 nwalGlobCfg.sa2PaBufPool.numBufPools = 1;
377 nwalGlobCfg.sa2PaBufPool.bufPool[0].descSize = TUNE_NETAPI_DESC_SIZE;
378 nwalGlobCfg.sa2PaBufPool.bufPool[0].bufSize = p_cfg->def_heap_buf_size;
380 /* Populate the heap configuration */
381 heapCfg.name = "nwal SA2PA";
382 heapCfg.numPkts = TUNE_NETAPI_CONFIG_MAX_SA_TO_PA_DESC;
384 nwalGlobCfg.sa2PaBufPool.bufPool[0].heapHandle =
385 p_nwal_context->sa2pa_heap = Pktlib_createHeap(&heapCfg, &errCode);
386 if(nwalGlobCfg.sa2PaBufPool.bufPool[0].heapHandle == NULL)
387 {
388 netapi_Log ("netapip_initNwal: Pktlib_createHeap:Heap Creation Failed for SA to PA Buffer Pool, Error Code: %d\n",
389 errCode);
390 netapipErrTeardown();
391 return -1;
392 }
394 nwalGlobCfg.hopLimit = 5;/* Default TTL / Hop Limit */
395 nwalGlobCfg.paPowerOn = nwal_TRUE;
396 nwalGlobCfg.saPowerOn = nwal_TRUE;
397 nwalGlobCfg.paFwActive = nwal_TRUE;
398 nwalGlobCfg.saFwActive = nwal_FALSE;
401 /* Update nwal cfg with virtual PA and SA addresses */
404 nwalBaseAddrCfg.paVirtBaseAddr = (uint32_t) netapi_VM_VirtAddr->passCfgVaddr;
407 nwalBaseAddrCfg.pSaVirtBaseAddr = (uint32_t) netapi_VM_VirtAddr->passCfgVaddr +
408 CSL_NETCP_CFG_SA_CFG_REGS -
409 CSL_NETCP_CFG_REGS;
410 ;
411 nwalGlobCfg.rxDefPktQ = QMSS_PARAM_NOT_SPECIFIED;
414 /* Get the Buffer Requirement from NWAL */
415 memset(&nwalSizeInfo,0,sizeof(nwalSizeInfo));
416 nwalSizeInfo.nMaxMacAddress = TUNE_NETAPI_MAX_NUM_MAC;
417 nwalSizeInfo.nMaxIpAddress = TUNE_NETAPI_MAX_NUM_IP;
418 nwalSizeInfo.nMaxL4Ports = TUNE_NETAPI_MAX_NUM_PORTS;
419 nwalSizeInfo.nMaxIpSecChannels = TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS;//we allocate 2 per channel
420 nwalSizeInfo.nMaxDmSecChannels = TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS;//we allocate 2 per channel
421 nwalSizeInfo.nMaxL2L3Hdr = TUNE_NETAPI_MAX_NUM_L2_L3_HDRS;
422 nwalSizeInfo.nProc = TUNE_NETAPI_NUM_CORES;
423 nwalRetVal = nwal_getBufferReq(&nwalSizeInfo,
424 sizes,
425 aligns);
426 if(nwalRetVal != nwal_OK)
427 {
428 netapi_Log ("netapip_initNwal: nwal_getBufferReq Failed %d\n", nwalRetVal);
429 return nwal_FALSE;
430 }
432 /* Check for memory size requirement and update the base */
433 count = 0;
434 //bases[nwal_BUF_INDEX_INST] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)nwalInstMem);
435 bases[nwal_BUF_INDEX_INST] =
436 (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)nwalEntry->nwalInstMem);
438 if(NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_HANDLE < sizes[nwal_BUF_INDEX_INST])
439 {
440 printf(" 1memSize issue %d %d\n",
441 sizes[nwal_BUF_INDEX_INST], NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_HANDLE);
442 /* Resize Memory */
443 return nwal_FALSE;
444 //while(1);
445 }
446 count++;
448 //bases[nwal_BUF_INDEX_INT_HANDLES] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)nwalHandleMem);
449 bases[nwal_BUF_INDEX_INT_HANDLES] =
450 (uint32_t *) Osal_nwalLocToGlobAddr((uint32_t)nwalEntry->nwalHandleMem);
453 if(NWAL_CHAN_HANDLE_SIZE < sizes[nwal_BUF_INDEX_INT_HANDLES])
454 {
455 /* Resize Memory */
456 printf(" 2memSize issue %d %d\n",
457 sizes[nwal_BUF_INDEX_INT_HANDLES], NWAL_CHAN_HANDLE_SIZE);
458 /* Resize Memory */
459 return nwal_FALSE;
460 //while(1);
462 }
463 count++;
464 bases[nwal_BUF_INDEX_PA_LLD_BUF0] =
465 (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)paEntry->paBuf0);
466 if((NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF0) < sizes[nwal_BUF_INDEX_PA_LLD_BUF0])
467 {
468 printf(" 3memSize issue %d %d\n",
469 sizes[nwal_BUF_INDEX_PA_LLD_BUF0], NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF0);
470 /* Resize Memory */
471 return nwal_FALSE;
472 //while(1);
474 }
475 count++;
477 bases[nwal_BUF_INDEX_PA_LLD_BUF1] =
478 (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)paEntry->paBuf1);
479 if((NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF1) < sizes[nwal_BUF_INDEX_PA_LLD_BUF1])
480 {
481 printf(" 4memSize issue %d %d\n",
482 sizes[nwal_BUF_INDEX_PA_LLD_BUF1], NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF1);
483 /* Resize Memory */
484 return nwal_FALSE;
485 //while(1);
487 }
488 count++;
490 bases[nwal_BUF_INDEX_PA_LLD_BUF2] =
491 (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)paEntry->paBuf2);
492 if((NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF2) < sizes[nwal_BUF_INDEX_PA_LLD_BUF2])
493 {
494 printf(" 5memSize issue %d %d\n",
495 sizes[nwal_BUF_INDEX_PA_LLD_BUF2], NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF2);
496 /* Resize Memory */
497 return nwal_FALSE;
498 //while(1);
500 }
501 count++;
502 #ifdef NETAPI_ENABLE_SECURITY
503 bases[nwal_BUF_INDEX_SA_LLD_HANDLE] =
504 (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)saEntry->salldHandle);
505 if((NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE) < sizes[nwal_BUF_INDEX_SA_LLD_HANDLE])
506 {
507 printf(" 6memSize issue %d %d\n",
508 sizes[nwal_BUF_INDEX_SA_LLD_HANDLE],
509 NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE);
510 /* Resize Memory */
511 return nwal_FALSE;
512 //while(1);
514 }
515 count++;
517 bases[nwal_BUF_INDEX_SA_CONTEXT] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)netapi_VM_SaContextVaddr);
518 /* also save this here for easy access to sa_start */
519 nwalBaseAddrCfg.pScPoolBaseAddr= bases[nwal_BUF_INDEX_SA_CONTEXT];
520 count++;
522 bases[nwal_BUF_INDEX_SA_LLD_CHAN_HANDLE] =
523 (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)saEntry->salldChanHandle);
524 if((NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE_PER_CHAN * TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS*2) <
525 sizes[nwal_BUF_INDEX_SA_LLD_CHAN_HANDLE])
526 {
527 printf(" 7memSize issue %d %d\n",
528 sizes[nwal_BUF_INDEX_SA_LLD_CHAN_HANDLE],
529 NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE_PER_CHAN * TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS*2);
530 /* Resize Memory */
531 return nwal_FALSE;
532 //while(1);
534 }
535 count++;
536 #else
537 bases[nwal_BUF_INDEX_SA_LLD_HANDLE] = 0;
538 bases[nwal_BUF_INDEX_SA_CONTEXT] = 0;
539 bases[nwal_BUF_INDEX_SA_LLD_CHAN_HANDLE] = 0;
540 count = count+3;
541 #endif
543 /* Initialize NWAL module */
544 nwal_getLocContextBufferReq(nwalSizeInfo.nProc, &localCtxSize);
545 printf("testNwGlobInit: localCtxSize: 0x%x\n", localCtxSize);
547 pNwalLocCtxMem = malloc(localCtxSize);
548 nwal_createProc(bases[nwal_BUF_INDEX_INST],
549 pNwalLocCtxMem,
550 &nwalBaseAddrCfg);
552 if (pNwalLocCtxMem)
553 printf("netapip_initNwal: passing 0x%x to nwal as local ctx intance:n",
554 pNwalLocCtxMem);
555 nwalGlobCfg.pBaseAddrCfg = &nwalBaseAddrCfg;
556 nwalRetVal = nwal_create(&nwalGlobCfg,
557 &nwalSizeInfo,
558 sizes,
559 bases,
560 &gPNwalInstHandle);
561 //printf("netapip_initNwal: nwalInstanceHandle: 0x%x\n", gPNwalGlobCtx);
562 if(nwalRetVal != nwal_OK)
563 {
564 netapi_Log ("netapip_initNwal: nwal_create Failed %d\n",nwalRetVal);
565 return nwal_FALSE;
566 //while(1);
567 }
569 netapi_Log("netapip_initNwal- Global and Local Network initialization Successful \n");
570 return 1;
571 }
573 /********************************************************************
574 * FUNCTION PURPOSE: Internal NETAPI function to start NWAL
575 ********************************************************************
576 * DESCRIPTION: Internal NETAPI function to start NWAL, per thread/core
577 ********************************************************************/
578 int netapip_startNwal(Pktlib_HeapHandle pkt_heap,
579 Pktlib_HeapHandle cmd_rx_heap,
580 Pktlib_HeapHandle cmd_tx_heap,
581 NETAPI_NWAL_LOCAL_CONTEXT_T *p,
582 NETAPI_CFG_T *p_cfg,
583 NETAPI_NWAL_GLOBAL_CONTEXT_T * p_nwal_glob_context,
584 int master)
585 {
586 nwalLocCfg_t nwalLocCfg;
587 nwalBaseAddrCfg_t nwalBaseAddrCfg;
588 int count=0;
589 static int first_time = 0;
590 nwal_RetValue nwalRetVal;
591 void* pBase = NULL;
592 NETAPI_NWAL_SHM_T* nwalEntry = NULL;
593 void* pNwalLocCtxMem = NULL;
595 NETAPI_SA_SHM_T* saEntry = NULL;
596 NETAPI_PA_SHM_T* paEntry = NULL;
598 uint32_t baseAddr;
599 void* instPoolSaBaseAddr;
600 void* pScPoolBaseAddr;
601 void* pInstPoolPaBaseAddr;
602 void* paVirtBaseAddr;
603 uint32_t localCtxSize;
605 memset(&nwalLocCfg,0,sizeof(nwalLocCfg));
606 memset(&nwalBaseAddrCfg, 0, sizeof(nwalBaseAddrCfg_t));
608 /* Update the Start of Packet Offset for the default flows created
609 * by NWAL
610 */
611 nwalLocCfg.rxSopPktOffset = p_cfg->def_flow_pkt_rx_offset;
612 nwalLocCfg.rxPktTailRoomSz = p_cfg->def_heap_tailroom_size;
614 /* Call back registration for the core */
615 nwalLocCfg.pRxPktCallBack = netapip_pktioNWALRxPktCallback;
616 nwalLocCfg.pCmdCallBack = netapip_netcpCfgNWALCmdCallBack;
617 nwalLocCfg.pPaStatsCallBack = netapip_netcpCfgNWALCmdPaStatsReply;
619 nwalLocCfg.pRxDmCallBack= netapip_pktioNWALSBPktCallback; //sideband mode callback
621 /* Initialize Buffer Pool for Control packets from NetCP to Host */
622 nwalLocCfg.rxCtlPool.numBufPools = 1;
623 nwalLocCfg.rxCtlPool.bufPool[0].descSize = TUNE_NETAPI_DESC_SIZE;
624 nwalLocCfg.rxCtlPool.bufPool[0].bufSize = TUNE_NETAPI_CONFIG_MAX_CTL_RXTX_BUF_SIZE;
625 nwalLocCfg.rxCtlPool.bufPool[0].heapHandle = cmd_rx_heap;
627 /* Initialize Buffer Pool for Control packets from Host to NetCP */
628 nwalLocCfg.txCtlPool.numBufPools = 1;
629 nwalLocCfg.txCtlPool.bufPool[0].descSize = TUNE_NETAPI_DESC_SIZE;
630 nwalLocCfg.txCtlPool.bufPool[0].bufSize = TUNE_NETAPI_CONFIG_MAX_CTL_RXTX_BUF_SIZE;
631 nwalLocCfg.txCtlPool.bufPool[0].heapHandle = cmd_tx_heap;
633 /* Initialize Buffer Pool for L4 Packets from NetCP to Host */
634 nwalLocCfg.rxPktPool.numBufPools = 1;
635 nwalLocCfg.rxPktPool.bufPool[0].descSize = TUNE_NETAPI_DESC_SIZE;
636 nwalLocCfg.rxPktPool.bufPool[0].bufSize = p_cfg->def_heap_buf_size;
637 nwalLocCfg.rxPktPool.bufPool[0].heapHandle = pkt_heap;
639 /* Initialize Buffer Pool for Packets from Host to NetCP */
640 nwalLocCfg.txPktPool.numBufPools = 1;
641 nwalLocCfg.txPktPool.bufPool[0].descSize = TUNE_NETAPI_DESC_SIZE;
642 nwalLocCfg.txPktPool.bufPool[0].bufSize = p_cfg->def_heap_buf_size;
643 nwalLocCfg.txPktPool.bufPool[0].heapHandle = pkt_heap;
648 memcpy(&p->nwalLocCfg,&nwalLocCfg,sizeof(nwalLocCfg_t));
649 while(1)
650 {
651 if(master == NETAPI_PROC_MASTER)
652 {
653 pBase = hplib_shmOpen();
654 nwalEntry = (NETAPI_NWAL_SHM_T*)hplib_shmGetEntry(pBase,NWAL_ENTRY);
656 baseAddr = (void*) netapi_VM_VirtAddr->passCfgVaddr +
657 CSL_NETCP_CFG_SA_CFG_REGS -
658 CSL_NETCP_CFG_REGS;
659 saEntry = (NETAPI_SA_SHM_T*)hplib_shmGetEntry(pBase,SA_ENTRY);
660 instPoolSaBaseAddr = (void*) saEntry;
662 pScPoolBaseAddr = Osal_nwalLocToGlobAddr((uint32_t)netapi_VM_SaContextVaddr);
665 paVirtBaseAddr = (void*) netapi_VM_VirtAddr->passCfgVaddr;
666 paEntry = (NETAPI_PA_SHM_T*)hplib_shmGetEntry(pBase,PA_ENTRY);
667 pInstPoolPaBaseAddr = (void *)paEntry;
669 nwal_getLocContextBufferReq(TUNE_NETAPI_NUM_CORES, &localCtxSize);
670 printf("testNwGlobInit: localCtxSize: 0x%x\n", localCtxSize);
671 pNwalLocCtxMem = malloc(localCtxSize);
672 if (pNwalLocCtxMem == NULL)
673 {
674 netapi_Log ("netapip_startNwal:malloc failure for nwal local context memory\n");
675 return -1;
676 }
677 nwalBaseAddrCfg.pSaVirtBaseAddr = baseAddr;
678 nwalBaseAddrCfg.pInstPoolSaBaseAddr = instPoolSaBaseAddr;
679 nwalBaseAddrCfg.pScPoolBaseAddr = pScPoolBaseAddr;
680 nwalBaseAddrCfg.paVirtBaseAddr = paVirtBaseAddr;
681 nwalBaseAddrCfg.pInstPoolPaBaseAddr = pInstPoolPaBaseAddr;
682 /* this is 1 time per process */
683 nwal_createProc(nwalEntry,
684 pNwalLocCtxMem,
685 &nwalBaseAddrCfg);
686 }
687 /* this is for every thread including 1st thread of the process */
688 netapi_proc_master->spinLock.lock(&pnetapiShm->netapi_util_lock);
689 nwalRetVal = nwal_start(gPNwalInstHandle,&nwalLocCfg);
690 netapi_proc_master->spinLock.unlock(&pnetapiShm->netapi_util_lock);
691 if(nwalRetVal == nwal_ERR_INVALID_STATE)
692 {
693 continue;
694 }
695 break;
696 }
698 if(nwalRetVal != nwal_OK)
699 {
700 netapi_Log (">nwal_start:Failed ->err %d !!!\n", nwalRetVal);
701 return -1;
702 }
703 else
704 printf("netapip_startnwal: complete !!!!!!!!!!!!!!!!!!!\n");
705 p->state = NETAPI_NW_CXT_LOC_ACTIVE;
706 return 1;
709 }
710 /***********************************************************************
711 * FUNCTION PURPOSE: Internal NETAPI function to initialize the 64 bit timer.
712 ***********************************************************************
713 * DESCRIPTION: Internal NETAPI function to initialize the 64 bit timer. for tci6614 ONLY
714 **********************************************************************/
715 int netapip_initTimer(void)
716 {
717 #ifdef CORTEX_A8
718 return t64_start();
719 #else
720 return 0;
721 #endif
722 }
727 /***************************************************************************
728 * FUNCTION PURPOSE: NETAPI internal function for virtual memory allocation.
729 ***************************************************************************
730 * DESCRIPTION: NETAPI internal function for virtual memory allocation.
731 **************************************************************************/
733 static uint8_t* netapip_sharedMemoryMalloc(uint32_t size)
734 {
735 //printf("netapip_sharedMemoryMalloc called for size: %d\n", size);
736 return (uint8_t *)hplib_vmMemAlloc(size +
737 pnetapiShm->netapi_global.cfg.def_heap_extra_size ,
738 128,
739 0);
740 }
742 /********************************************************************
743 * FUNCTION PURPOSE: NETAPI internal function for virtual memory free.
744 ********************************************************************
745 * DESCRIPTION: NETAPI internal function for virtual memory free.
746 ********************************************************************/
747 static void netapip_sharedMemoryFree(uint8_t* ptr, uint32_t size)
748 {
749 /* Do Nothing. */
750 //printf("netapip_sharedMemoryMalloc called for size: %d\n", size);
751 //hplib_vmMemFree(ptr, size + pnetapiShm->netapi_global.cfg.def_heap_extra_size,0);
752 netapi_Log("netapi Unexpected. need to provide a free () for some reason!! \n");
753 return;
754 }
756 //defensive: clean out stuff hanging around
757 //
758 // open a bunch of free queues and zap them
759 #define NQUEUES2CLEAR 35
760 static Qmss_QueueHnd tempQH[NQUEUES2CLEAR];
761 void netapip_cleanupAtStart(void)
762 {
763 int i;
764 uint8_t isAllocated;
766 for(i=0;i<NQUEUES2CLEAR;i++)
767 {
768 tempQH[i] = Qmss_queueOpen(Qmss_QueueType_GENERAL_PURPOSE_QUEUE,
769 QMSS_PARAM_NOT_SPECIFIED, &isAllocated);
770 netapip_zapQ(tempQH[i]);
771 }
773 for(i=0;i<NQUEUES2CLEAR;i++)
774 {
775 Qmss_queueClose(tempQH[i]);
776 }
777 }
781 /********************************************************************
782 * FUNCTION PURPOSE: NETAPI internal function system initialization
783 ********************************************************************
784 * DESCRIPTION: NETAPI internal function system initialization
785 ********************************************************************/
786 int netapip_systemInit(NETAPI_HANDLE_T * handle,
787 Bool global_master_process)
788 {
790 int32_t result;
791 Pktlib_HeapHandle sharedHeapHandle;
792 Pktlib_HeapHandle controlRxHeapHandle,controlTxHeapHandle;
793 Pktlib_HeapCfg heapCfg;
794 int32_t errCode = 0;
795 int count=0;
797 #ifdef NETAPI_USE_DDR
798 /* Init attributes for DDR */
799 netapi_VM_MempoolAttr[0].attr = HPLIB_ATTR_KM_CACHED0;
800 netapi_VM_MempoolAttr[0].phys_addr = 0;
801 netapi_VM_MempoolAttr[0].size = 0;
803 /* Init attributes for un-cached MSMC */
804 netapi_VM_MempoolAttr[1].attr = HPLIB_ATTR_UN_CACHED;
805 netapi_VM_MempoolAttr[1].phys_addr = CSL_MSMC_SRAM_REGS;
806 netapi_VM_MempoolAttr[1].size = TUNE_NETAPI_PERM_MEM_SZ;
807 #else
808 netapi_VM_MempoolAttr[1].attr = HPLIB_ATTR_KM_CACHED0;
809 netapi_VM_MempoolAttr[1].phys_addr = 0;
810 netapi_VM_MempoolAttr[1].size = 0;
812 /* Init attributes for un-cached MSMC */
813 netapi_VM_MempoolAttr[0].attr = HPLIB_ATTR_UN_CACHED;
814 netapi_VM_MempoolAttr[0].phys_addr = CSL_MSMC_SRAM_REGS;
815 netapi_VM_MempoolAttr[0].size = TUNE_NETAPI_PERM_MEM_SZ;
816 #endif
817 /* initialize all the memory we are going to use
818 - chunk for buffers, descriptors
819 - memory mapped peripherals we use, such as QMSS, PA, etc */
820 result = hplib_vmInit(&netapi_VM_VirtAddr[0],
821 2,
822 &netapi_VM_MempoolAttr[0]);
824 if (result == hplib_OK)
825 netapi_Log("netapip_systemInit: - hplib_vmInit pass\n");
826 else
827 {
828 netapi_Log("netapip_systemInit: - hplib_vmInit fail\n");
829 return -1;
830 }
832 if (global_master_process == NETAPI_TRUE)
833 {
834 hplib_initMallocArea(0);
835 hplib_initMallocArea(1);
836 #ifdef NETAPI_ENABLE_SECURITY
837 #define SEC_CONTEXT_SZ 384 //not tunable
838 /* allocate 2x number of tunnels since we need one for inflow and one for data mode */
839 netapi_VM_SaContextVaddr = hplib_vmMemAlloc((TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS*2 *
840 SEC_CONTEXT_SZ), 128, 0);
841 if (!netapi_VM_SaContextVaddr)
842 {
843 netapi_Log("netapip_systemInit: Failed to map SA context memory region\n");
844 return (-1);
845 }
846 netapi_Log("netapip_systemInit: SA Memory mapped/allocated at address %p.\n", netapi_VM_SaContextVaddr);
847 #else
848 netapi_VM_SaContextVaddr= (char *) NULL;
849 #endif
851 /* (3) Allocate 2 QM regions from continguous chunk above */
852 netapi_VM_QMemGlobalDescRam =
853 (void *)hplib_vmMemAlloc((TUNE_NETAPI_NUM_GLOBAL_DESC *
854 TUNE_NETAPI_DESC_SIZE),
855 128,
856 0);
858 netapi_VM_QMemLocalDescRam =
859 (void *)hplib_vmMemAlloc((TUNE_NETAPI_NUM_LOCAL_DESC *
860 TUNE_NETAPI_DESC_SIZE),
861 128,
862 0);
863 netapi_Log("netapip_systemInit(sysMaster): desc region=%x global desc region=%x\n",
864 netapi_VM_QMemLocalDescRam, netapi_VM_QMemGlobalDescRam);
865 /* Initialize Queue Manager Sub System */
866 result = netapip_initQm (pnetapiShm->netapi_global.cfg.def_max_descriptors,
867 pRmClientHandle);
869 if (result != 1)
870 {
871 netapi_Log("netapip_systemInit: returned from netapip_initQm with failure\n");
872 return -1;
873 }
874 /* Start the QMSS. */
875 if (netapip_startQm(pRmClientHandle) != 1)
876 {
877 netapi_Log("netapip_systemInit: returned from netapip_startQm with failure\n");
878 return -1;
879 }
881 //clean our old junk in 1st bunch of queues that will be allocated to us
882 netapip_cleanupAtStart();
883 /* Initialize the global descriptor memory region. */
884 result= netapip_qmSetupMemRegion(
885 pnetapiShm->netapi_global.cfg.def_tot_descriptors_for_us,
886 TUNE_NETAPI_DESC_SIZE,
887 (unsigned int *) netapi_VM_QMemGlobalDescRam,
888 TUNE_NETAPI_QM_GLOBAL_REGION);
889 if(result <0)
890 {
891 netapi_Log("netapip_systemInit: can't setup QM shared region\n");
892 return -1;
893 }
894 /* Initialize CPPI CPDMA */
895 result = netapip_initCppi(pRmClientHandle);
896 if (result != 1)
897 {
898 netapi_Log ("netapi: Error initializing CPPI SubSystem error code : %d\n",result);
899 return -1;
900 }
901 /* CPPI and Queue Manager are initialized. */
902 netapi_Log ("netapi: Queue Manager and CPPI are initialized.\n");
904 /* create main pkt heap */
905 /* Initialize the Shared Heaps. */
906 Pktlib_sharedHeapInit();
907 /* Populate the heap interface table. */
908 netapi_pktlib_ifTable.data_malloc = netapip_sharedMemoryMalloc;
909 netapi_pktlib_ifTable.data_free = netapip_sharedMemoryFree;
910 /* Initialize the heap configuration. */
911 memset ((void *)&heapCfg, 0, sizeof(Pktlib_HeapCfg));
912 /* Populate the heap configuration */
913 heapCfg.name = "netapi";
914 // heapCfg.memRegion = TUNE_NETAPI_QM_GLOBAL_REGION;
915 heapCfg.memRegion = memInfo.memRegion;
916 printf("netapip_systemInit: memRegion: %d\n",memInfo.memRegion);
917 heapCfg.sharedHeap = 1;
918 heapCfg.useStarvationQueue = 0;
919 heapCfg.dataBufferSize = pnetapiShm->netapi_global.cfg.def_heap_buf_size;
920 heapCfg.numPkts = pnetapiShm->netapi_global.cfg.def_heap_n_descriptors;
921 heapCfg.numZeroBufferPackets= pnetapiShm->netapi_global.cfg.def_heap_n_zdescriptors;
922 heapCfg.heapInterfaceTable.data_malloc = netapi_pktlib_ifTable.data_malloc;
923 heapCfg.heapInterfaceTable.data_free = netapi_pktlib_ifTable.data_free;
924 heapCfg.dataBufferPktThreshold = 0;
925 heapCfg.zeroBufferPktThreshold = 0;
927 /* Create Shared Heap with specified configuration. */
928 sharedHeapHandle = Pktlib_createHeap(&heapCfg, &errCode);
929 if (!sharedHeapHandle) { netapi_Log(">'netapi' heap create failed, Error Code: %d\n",errCode); return -1;}
930 handle->netcp_heap= sharedHeapHandle;
931 printf("netapi_systemInit: netapi heap handle: 0x%x\n",
932 handle->netcp_heap);
933 /* Update for Control */
934 heapCfg.name = "netapi_control_rx";
935 heapCfg.sharedHeap = 1;
936 heapCfg.dataBufferSize = TUNE_NETAPI_CONFIG_MAX_CTL_RXTX_BUF_SIZE;
937 heapCfg.numPkts = TUNE_NETAPI_CONFIG_NUM_CTL_RX_BUF;
938 heapCfg.numZeroBufferPackets= 0;
940 controlRxHeapHandle = Pktlib_createHeap(&heapCfg, &errCode);
941 //todo -> cleanup on failure
942 if (!controlRxHeapHandle) { netapi_Log("netapi -'netapi_control_rx' heap create failed, Error Code: %d\n",errCode); return -1;}
943 handle->netcp_control_rx_heap= controlRxHeapHandle;
946 heapCfg.name = "netapi_control_tx";
947 heapCfg.numPkts = TUNE_NETAPI_CONFIG_NUM_CTL_TX_BUF;
949 controlTxHeapHandle = Pktlib_createHeap(&heapCfg, &errCode);
950 //todo -> cleanup on failure
951 if (!controlTxHeapHandle) { netapi_Log("netapi -'netapi_control_tx' heap create failed, Error Code: %d\n",errCode); return -1;}
952 handle->netcp_control_tx_heap= controlTxHeapHandle;
953 /* now NWAL */
954 result = netapip_initNwal(memInfo.memRegion,
955 &netapi_pktlib_ifTable,
956 &pnetapiShm->netapi_global.nwal_context,
957 &pnetapiShm->netapi_global.cfg);
958 if (result<0) {netapi_Log("netapi init_nwal() failed\n"); return -1; }
959 netapi_Log("netapip_systemInit: returned from netapip_initNwal\n");
960 /* Common Initialization for all cores */
961 while(count < TUNE_NETAPI_MAX_NUM_TRANS)
962 {
963 netapi_proc_global.nwal_context.transInfos[count].transId = count;
964 count++;
965 }
966 result = netapip_startNwal(sharedHeapHandle,
967 controlRxHeapHandle,
968 controlTxHeapHandle,
969 &handle->nwal_local,
970 &pnetapiShm->netapi_global.cfg,
971 &pnetapiShm->netapi_global.nwal_context,
972 handle->master);
973 if (result<0) {netapi_Log("netapi start_nwal() failed\n"); return -1; }
974 netapi_Log("netapip_systemInit: returned from netapip_startNwal\n");
975 }
976 else
977 {
978 if (hplib_checkMallocArea(0) != hplib_OK)
979 return -1;
980 if (hplib_checkMallocArea(1) != hplib_OK)
981 return -1;
982 #if 1
983 #ifdef NETAPI_ENABLE_SECURITY
984 /* allocate 2x number of tunnels since we need one for inflow and one for data mode */
985 netapi_VM_SaContextVaddr = hplib_vmMemAlloc((TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS*2 *
986 SEC_CONTEXT_SZ), 128, 0);
987 if (!netapi_VM_SaContextVaddr)
988 {
989 netapi_Log("netapip_systemInit: Failed to map SA context memory region\n");
990 return (-1);
991 }
992 netapi_Log("netapip_systemInit: SA Memory mapped/allocated at address %p.\n", netapi_VM_SaContextVaddr);
993 #else
994 netapi_VM_SaContextVaddr= (char *) NULL;
995 #endif
999 /* (3) Allocate 2 QM regions from continguous chunk above */
1000 netapi_VM_QMemGlobalDescRam =
1001 (void *)hplib_vmMemAlloc((TUNE_NETAPI_NUM_GLOBAL_DESC *
1002 TUNE_NETAPI_DESC_SIZE),
1003 128,
1004 0);
1006 netapi_VM_QMemLocalDescRam =
1007 (void *)hplib_vmMemAlloc((TUNE_NETAPI_NUM_LOCAL_DESC *
1008 TUNE_NETAPI_DESC_SIZE),
1009 128,
1010 0);
1011 netapi_Log("netapip_systemInit(procMaster): desc region=%x global desc region=%x\n",
1012 netapi_VM_QMemLocalDescRam, netapi_VM_QMemGlobalDescRam);
1014 #endif
1016 /****************************************************
1017 * partial initialization. For process, not for SOC
1018 ***************************************************/
1019 result = netapip_initQm (pnetapiShm->netapi_global.cfg.def_max_descriptors,
1020 pRmClientHandle);
1021 if (result != 1)
1022 {
1023 netapi_Log("netapip_systemInit: returned from netapip_initQm with failure\n");
1024 return -1;
1025 }
1027 /* Start the QMSS. */
1028 if (netapip_startQm(pRmClientHandle) != 1)
1029 {
1030 netapi_Log("netapip_systemInit: returned from netapip_startQm with failure\n");
1031 return -1;
1032 }
1033 #if 1
1034 result= netapip_qmSetupMemRegion(
1035 pnetapiShm->netapi_global.cfg.def_tot_descriptors_for_us,
1036 TUNE_NETAPI_DESC_SIZE,
1037 (unsigned int *) netapi_VM_QMemGlobalDescRam,
1038 TUNE_NETAPI_QM_GLOBAL_REGION);
1039 if(result <0)
1040 {
1041 netapi_Log("netapip_systemInit: can't setup QM shared region\n");
1042 return -1;
1043 }
1044 #endif
1045 /* Initialize CPPI CPDMA */
1046 result = netapip_initCppi(pRmClientHandle);
1047 if (result != 1)
1048 {
1049 netapi_Log ("netapi: Error initializing CPPI SubSystem error code : %d\n",result);
1050 return -1;
1051 }
1052 /* CPPI and Queue Manager are initialized. */
1053 netapi_Log ("netapi: Queue Manager and CPPI are initialized.\n");
1055 /* create main pkt heap for this process */
1056 /* Initialize the Shared Heaps. */
1057 Pktlib_sharedHeapInit();
1058 /* Populate the heap interface table. */
1059 netapi_pktlib_ifTable.data_malloc = netapip_sharedMemoryMalloc;
1060 netapi_pktlib_ifTable.data_free = netapip_sharedMemoryFree;
1061 /* Initialize the heap configuration. */
1062 memset ((void *)&heapCfg, 0, sizeof(Pktlib_HeapCfg));
1063 /* Populate the heap configuration */
1064 heapCfg.name = "netapi";
1065 //heapCfg.memRegion = TUNE_NETAPI_QM_GLOBAL_REGION;
1066 heapCfg.memRegion = memInfo.memRegion;
1067 heapCfg.sharedHeap = 1;
1068 heapCfg.useStarvationQueue = 0;
1069 heapCfg.dataBufferSize = pnetapiShm->netapi_global.cfg.def_heap_buf_size;
1070 heapCfg.numPkts = pnetapiShm->netapi_global.cfg.def_heap_n_descriptors;
1071 heapCfg.numZeroBufferPackets= pnetapiShm->netapi_global.cfg.def_heap_n_zdescriptors;
1072 heapCfg.heapInterfaceTable.data_malloc = netapi_pktlib_ifTable.data_malloc;
1073 heapCfg.heapInterfaceTable.data_free = netapi_pktlib_ifTable.data_free;
1074 heapCfg.dataBufferPktThreshold = 0;
1075 heapCfg.zeroBufferPktThreshold = 0;
1077 /* Create Shared Heap with specified configuration. */
1078 sharedHeapHandle = Pktlib_createHeap(&heapCfg, &errCode);
1079 //todo -> cleanup on failure
1080 if (!sharedHeapHandle) { netapi_Log(">'netapi' heap create failed, Error Code: %d\n",errCode); return -1;}
1081 handle->netcp_heap= sharedHeapHandle;
1082 printf("netapi_systemInit: netapi heap handle: 0x%x\n",
1083 handle->netcp_heap);
1085 //open shared heap handle but create new controlRx & Tx heaps for this
1086 //process
1087 /* Update for Control */
1088 heapCfg.name = "netapi_control_rx";/*todo:add random#*/
1089 heapCfg.sharedHeap = 1;
1090 heapCfg.dataBufferSize = TUNE_NETAPI_CONFIG_MAX_CTL_RXTX_BUF_SIZE;
1091 heapCfg.numPkts = TUNE_NETAPI_CONFIG_NUM_CTL_RX_BUF;
1092 heapCfg.numZeroBufferPackets= 0;
1093 controlRxHeapHandle = Pktlib_createHeap(&heapCfg, &errCode);
1094 if (!controlRxHeapHandle) { netapi_Log("netapi -'netapi_control_rx' heap create failed, Error Code: %d\n",errCode); return -1;}
1096 handle->netcp_control_rx_heap= controlRxHeapHandle;
1097 heapCfg.name = "netapi_control_tx";
1098 heapCfg.numPkts = TUNE_NETAPI_CONFIG_NUM_CTL_TX_BUF;
1099 controlTxHeapHandle = Pktlib_createHeap(&heapCfg, &errCode);
1100 if (!controlTxHeapHandle) { netapi_Log("netapi -'netapi_control_tx' heap create failed, Error Code: %d\n",errCode); return -1;}
1101 handle->netcp_control_tx_heap= controlTxHeapHandle;
1103 /* Common Initialization for all threads in process */
1104 while(count < TUNE_NETAPI_MAX_NUM_TRANS)
1105 {
1106 netapi_proc_global.nwal_context.transInfos[count].transId = count;
1107 count++;
1108 }
1109 result = netapip_startNwal(sharedHeapHandle,
1110 controlRxHeapHandle,
1111 controlTxHeapHandle,
1112 &handle->nwal_local,
1113 &pnetapiShm->netapi_global.cfg,
1114 &pnetapiShm->netapi_global.nwal_context,
1115 handle->master);
1116 if (result<0)
1117 {
1118 netapi_Log("netapi start_nwal() failed\n");
1119 return -1;
1120 }
1121 netapi_Log("netapip_systemInit: returned from netapip_startNwal\n");
1122 }
1124 //get timer running
1125 #ifdef CORTEX_A8
1126 netapip_initTimer();
1127 netapi_Log("netapip_systemInit: returned from netapip_initTimer\n");
1128 #endif
1132 return 0;
1133 }
1136 /****************************************************************************
1137 * FUNCTION PURPOSE: NETAPI internal function which performs clean for linux user space
1138 ****************************************************************************
1139 * DESCRIPTION: NETAPI internal function which performs clean for linux user space
1140 ***************************************************************************/
1141 void netapip_zapQ(int queueNum)
1142 {
1143 int i;
1144 if (!queueNum)
1145 {
1146 return;
1147 }
1148 for (i=0;;i+=1 )
1149 {
1150 /* Pop descriptor from source queue */
1151 if (pktio_mQmssQueuePopRaw(queueNum) == NULL)
1152 {
1153 break;
1154 }
1155 }
1156 }
1159 /****************************************************************************
1160 * FUNCTION PURPOSE: NETAPI internal function to display internal heap stats.
1161 ****************************************************************************
1162 * DESCRIPTION: NETAPI internal function to display internal heap stats.
1163 ***************************************************************************/
1164 void netapi_dump_internal_heap_stats(void)
1165 {
1166 Pktlib_HeapStats pktLibHeapStats;
1167 Pktlib_getHeapStats(netapi_get_global()->nwal_context.pa2sa_heap,&pktLibHeapStats);
1168 printf("PA2SA(ingress) stats> #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets,
1169 pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage);
1170 printf(" > #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n",
1171 pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter,
1172 pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter);
1173 #if 0
1174 Pktlib_getHeapStats(netapi_get_global()->nwal_context.pa2saTX_heap,&pktLibHeapStats);
1175 netapi_Log("PA2SA(egress) stats> #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets,
1176 pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage);
1177 netapi_Log(" > #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n",
1178 pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter,
1179 pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter);
1180 #endif
1181 Pktlib_getHeapStats(netapi_get_global()->nwal_context.sa2pa_heap,&pktLibHeapStats);
1182 printf("SA2PA stats> #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets,
1183 pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage);
1184 printf(" > #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n",
1185 pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter,
1186 pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter);
1188 }