/**************************************************************************** * FILE: netapi_init.c * Global, Private initialization and cleanup routines and defines of NETAPI * * DESCRIPTION: Functions to initialize and cleanup framework resources * for running NETAPI * * REVISION HISTORY: * * Copyright (c) Texas Instruments Incorporated 2013 * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the * distribution. * * Neither the name of Texas Instruments Incorporated nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ***************************************************************************/ #include "netapi.h" #include "netapi_loc.h" #include #include #include #include #include #include #include "ti/drv/nwal/nwal.h" /* CSL RL includes */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* Global variablesto hold virtual address of various subsystems */ extern hplib_virtualAddrInfo_T netapi_VM_VirtAddr[]; /* Global variables which needs to be populated with memory pool attributes which is passed to HPLIB for memory pool initialization*/ extern hplib_memPoolAttr_T netapi_VM_MempoolAttr[]; extern unsigned char *netapi_VM_QMemLocalDescRam; extern unsigned char *netapi_VM_QMemGlobalDescRam; extern unsigned char *netapi_VM_SaContextVaddr; extern Pktlib_HeapIfTable netapi_pktlib_ifTable; extern NETAPI_GLOBAL_T netapi_global; /* TODO verify: */ #define CACHE_LINESZ 64 #define ALIGN(x) __attribute__((aligned (x))) /***************************************************************************** * Global Resources shared by all Cores *****************************************************************************/ uint8_t *QMemGlobDescRam = 0; uint8_t *cppiMemPaSaLinkBuf = 0; uint8_t *cppiMemSaPaLinkBuf = 0; /***************************************************************************** * Local Resource allocated at each Core *****************************************************************************/ /* Descriptors in global shared */ uint8_t *QMemLocDescRam = NULL; uint8_t *cppiMemRxPktLinkBuf = NULL; uint8_t *cppiMemTxPktLinkBuf = NULL; uint8_t *cppiMemRxCtlLinkBuf = NULL; uint8_t *cppiMemTxCtlLinkBuf = NULL; /******************************************************************** * FUNCTION PURPOSE: Internal NETAPI function to setup the QM memory region ******************************************************************** * DESCRIPTION: Internal NETAPI function to setup the QM memory region, * once per SOC ********************************************************************/ int netapip_qmSetupMemRegion( uint32_t numDesc, uint32_t descSize, uint32_t* pDescMemBase, Qmss_MemRegion memRegion) { Qmss_MemRegInfo memInfo; Int32 result; Int n; static int netapi_qm_region_index=0; memset(&memInfo,0,sizeof(Qmss_MemRegInfo)); memInfo.descBase = pDescMemBase; memInfo.descSize = descSize; memInfo.descNum = numDesc; memInfo.manageDescFlag = Qmss_ManageDesc_MANAGE_DESCRIPTOR; memInfo.memRegion = memRegion; if(memRegion == TUNE_NETAPI_QM_GLOBAL_REGION) { memInfo.startIndex = TUNE_NETAPI_QM_START_INDEX; //was 0 netapi_qm_region_index += numDesc; }else if(memRegion ==NETAPI_LOCAL_REGION) { /* 2nd region for descriptors (perhaps private?) */ memInfo.startIndex = netapi_qm_region_index; } else { return -1 ; } memset (pDescMemBase, 0, (descSize * numDesc)); result = Qmss_insertMemoryRegion (&memInfo); if (result < QMSS_SOK) { netapi_Log ("netapip_qmSetupMemRegion: Qmss_insertMemoryRegion returned error code %d\n", result); return (-1); } return 1; } /******************************************************************** * FUNCTION PURPOSE: Internal NETAPI function to start QM ******************************************************************** * DESCRIPTION: Internal NETAPI function to start QM * once per thread/core ********************************************************************/ int netapip_startQm(void) { int32_t result; result = Qmss_start(); if (result != QMSS_SOK) { netapi_Log ("netapip_startQm: Qmss_start failed with error code %d\n", result); return (-1); } return 1; } /*** NWAL Memory Buffer Configuration ***/ #define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_HANDLE 3400 uint8_t nwalInstMem[NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_HANDLE]ALIGN(CACHE_LINESZ); #define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_MAC 128 #define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_IPSEC_HANDLE_PER_CHAN 256 #define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_IP 128 #define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_PORT 128 #define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_L2L3_HDR 128 #define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_LOC_CONTEXT 384 #define NWAL_CHAN_HANDLE_SIZE ((NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_MAC * TUNE_NETAPI_MAX_NUM_MAC) + \ (NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_IPSEC_HANDLE_PER_CHAN * TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS*2) + \ (NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_IP * TUNE_NETAPI_MAX_NUM_IP) + \ (NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_PORT * TUNE_NETAPI_MAX_NUM_PORTS)+ \ (NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_LOC_CONTEXT * TUNE_NETAPI_NUM_CORES) + \ (NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_L2L3_HDR * TUNE_NETAPI_MAX_NUM_L2_L3_HDRS)) uint8_t nwalHandleMem[NWAL_CHAN_HANDLE_SIZE]ALIGN(CACHE_LINESZ); /* todo: Check if below size information can be made available from pa interface file */ #define NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF0 128 /* PA instance */ /* Memory used for the PA Instance. Needs to be assigned global uncached memory for chip */ uint8_t paBuf0[NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF0]ALIGN(CACHE_LINESZ); /* Memory used for PA handles */ #define NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF1 128 * TUNE_NETAPI_MAX_NUM_MAC uint8_t paBuf1[NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF1]ALIGN(CACHE_LINESZ); #define NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF2 13824 uint8_t paBuf2[NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF2]ALIGN(CACHE_LINESZ); /* Memory used for SA LLD global Handle */ #define NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE 512 uint8_t salldHandle[NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE]ALIGN(CACHE_LINESZ); #if 0 //need to alloc this since we need phy addr also /* Memory used for SA contet Handle */ #define NETAPI_NWAL_CONFIG_BUFSIZE_SA_CONTEXT_PER_CHAN 384 uint8_t saContext[NETAPI_NWAL_CONFIG_BUFSIZE_SA_CONTEXT_PER_CHAN * TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS]ALIGN(CACHE_LINESZ); #endif /* Memory used by SA LLD per Channel */ #define NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE_PER_CHAN 512 uint8_t salldChanHandle[NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE_PER_CHAN * TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS*2]ALIGN(CACHE_LINESZ); /******************************************************************** * FUNCTION PURPOSE: NETAPI internal function to gracefully cleanup when startup * issue occurs. ******************************************************************** * DESCRIPTION: NETAPI internal function to gracefully cleanup when startup * issue occurs. ********************************************************************/ void netapipErrTeardown() { netapip_cleanupAtStart(); exit(-99); } /******************************************************************** * FUNCTION PURPOSE: Internal NETAPI function to initialize NWAL subsystem ******************************************************************** * DESCRIPTION: Internal NETAPI function to initialize NWAL subsytem ********************************************************************/ int netapip_initNwal( int region2use, Pktlib_HeapIfTable * p_table, NETAPI_NWAL_GLOBAL_CONTEXT_T * p_nwal_context, NETAPI_CFG_T*p_cfg ) { nwalSizeInfo_t nwalSizeInfo; nwal_RetValue nwalRetVal; nwalGlobCfg_t nwalGlobCfg; uint8_t count; int sizes[nwal_N_BUFS]; int aligns[nwal_N_BUFS]; void* bases[nwal_N_BUFS]; Pktlib_HeapCfg heapCfg; int32_t errCode; memset(p_nwal_context,0,sizeof( NETAPI_NWAL_GLOBAL_CONTEXT_T) ); memset(&nwalGlobCfg,0,sizeof(nwalGlobCfg_t ) ); /* Initialize Buffer Pool for NetCP PA to SA packets */ nwalGlobCfg.pa2SaBufPool.numBufPools = 1; nwalGlobCfg.pa2SaBufPool.bufPool[0].descSize = TUNE_NETAPI_DESC_SIZE; nwalGlobCfg.pa2SaBufPool.bufPool[0].bufSize = p_cfg->def_heap_buf_size; /* Initialize the heap configuration. */ memset ((void *)&heapCfg, 0, sizeof(Pktlib_HeapCfg)); /* Populate the heap configuration */ heapCfg.name = "nwal PA2SA"; heapCfg.memRegion = region2use; heapCfg.sharedHeap = 0; heapCfg.useStarvationQueue = 0; heapCfg.dataBufferSize = p_cfg->def_heap_buf_size; heapCfg.numPkts = TUNE_NETAPI_CONFIG_MAX_PA_TO_SA_DESC; heapCfg.numZeroBufferPackets= 0; heapCfg.heapInterfaceTable.data_malloc = p_table->data_malloc; heapCfg.heapInterfaceTable.data_free = p_table->data_free; heapCfg.dataBufferPktThreshold = 0; heapCfg.zeroBufferPktThreshold = 0; nwalGlobCfg.pa2SaBufPool.bufPool[0].heapHandle = p_nwal_context->pa2sa_heap= Pktlib_createHeap(&heapCfg, &errCode); if(nwalGlobCfg.pa2SaBufPool.bufPool[0].heapHandle == NULL) { netapi_Log ("netapip_initNwal: Pktlib_createHeap:Heap Creation Failed for PA to SA Buffer Pool, Error Code: %d\n", errCode); netapipErrTeardown(); return -1; } /* Initialize Buffer Pool for NetCP SA to PA packets */ nwalGlobCfg.sa2PaBufPool.numBufPools = 1; nwalGlobCfg.sa2PaBufPool.bufPool[0].descSize = TUNE_NETAPI_DESC_SIZE; nwalGlobCfg.sa2PaBufPool.bufPool[0].bufSize = p_cfg->def_heap_buf_size; /* Populate the heap configuration */ heapCfg.name = "nwal SA2PA"; heapCfg.numPkts = TUNE_NETAPI_CONFIG_MAX_SA_TO_PA_DESC; nwalGlobCfg.sa2PaBufPool.bufPool[0].heapHandle = p_nwal_context->sa2pa_heap= Pktlib_createHeap(&heapCfg, &errCode); if(nwalGlobCfg.sa2PaBufPool.bufPool[0].heapHandle == NULL) { netapi_Log ("netapip_initNwal: Pktlib_createHeap:Heap Creation Failed for SA to PA Buffer Pool, Error Code: %d\n", errCode); netapipErrTeardown(); return -1; } nwalGlobCfg.hopLimit = 5;/* Default TTL / Hop Limit */ nwalGlobCfg.paPowerOn = nwal_TRUE; nwalGlobCfg.saPowerOn = nwal_TRUE; nwalGlobCfg.paFwActive = nwal_TRUE; nwalGlobCfg.saFwActive = nwal_FALSE; /* Pick Default Physical Address */ nwalGlobCfg.paVirtBaseAddr = (uint32_t) netapi_VM_VirtAddr->passCfgVaddr; nwalGlobCfg.saVirtBaseAddr = (uint32_t) netapi_VM_VirtAddr->passCfgVaddr + ((uint32_t)CSL_PA_SS_CFG_CP_ACE_CFG_REGS - (uint32_t)CSL_PA_SS_CFG_REGS) ; nwalGlobCfg.rxDefPktQ = QMSS_PARAM_NOT_SPECIFIED; /* Get the Buffer Requirement from NWAL */ memset(&nwalSizeInfo,0,sizeof(nwalSizeInfo)); nwalSizeInfo.nMaxMacAddress = TUNE_NETAPI_MAX_NUM_MAC; nwalSizeInfo.nMaxIpAddress = TUNE_NETAPI_MAX_NUM_IP; nwalSizeInfo.nMaxL4Ports = TUNE_NETAPI_MAX_NUM_PORTS; nwalSizeInfo.nMaxIpSecChannels = TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS;//we allocate 2 per channel nwalSizeInfo.nMaxDmSecChannels = TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS;//we allocate 2 per channel nwalSizeInfo.nMaxL2L3Hdr = TUNE_NETAPI_MAX_NUM_L2_L3_HDRS; nwalSizeInfo.nProc = TUNE_NETAPI_NUM_CORES; nwalRetVal = nwal_getBufferReq(&nwalSizeInfo, sizes, aligns); if(nwalRetVal != nwal_OK) { netapi_Log ("netapip_initNwal: nwal_getBufferReq Failed %d\n", nwalRetVal); return nwal_FALSE; } /* Check for memory size requirement and update the base */ count = 0; bases[nwal_BUF_INDEX_INST] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)nwalInstMem); if(NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_HANDLE < sizes[nwal_BUF_INDEX_INST]) { /* Resize Memory */ while(1); } count++; bases[nwal_BUF_INDEX_INT_HANDLES] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)nwalHandleMem); if(NWAL_CHAN_HANDLE_SIZE < sizes[nwal_BUF_INDEX_INT_HANDLES]) { /* Resize Memory */ while(1); } count++; bases[nwal_BUF_INDEX_PA_LLD_BUF0] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)paBuf0); if((NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF0) < sizes[nwal_BUF_INDEX_PA_LLD_BUF0]) { /* Resize Memory */ while(1); } count++; bases[nwal_BUF_INDEX_PA_LLD_BUF1] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)paBuf1); if((NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF1) < sizes[nwal_BUF_INDEX_PA_LLD_BUF1]) { /* Resize Memory */ while(1); } count++; bases[nwal_BUF_INDEX_PA_LLD_BUF2] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)paBuf2); if((NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF2) < sizes[nwal_BUF_INDEX_PA_LLD_BUF2]) { /* Resize Memory */ while(1); } count++; #ifdef NETAPI_ENABLE_SECURITY bases[nwal_BUF_INDEX_SA_LLD_HANDLE] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)salldHandle); if((NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE) < sizes[nwal_BUF_INDEX_SA_LLD_HANDLE]) { /* Resize Memory */ while(1); } count++; bases[nwal_BUF_INDEX_SA_CONTEXT] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)netapi_VM_SaContextVaddr); count++; bases[nwal_BUF_INDEX_SA_LLD_CHAN_HANDLE] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)salldChanHandle); if((NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE_PER_CHAN * TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS*2) < sizes[nwal_BUF_INDEX_SA_LLD_CHAN_HANDLE]) { /* Resize Memory */ while(1); } count++; #else bases[nwal_BUF_INDEX_SA_LLD_HANDLE] = 0; bases[nwal_BUF_INDEX_SA_CONTEXT] = 0; bases[nwal_BUF_INDEX_SA_LLD_CHAN_HANDLE] = 0; count = count+3; #endif if(count != nwal_N_BUFS) { while(1); } /* Initialize NWAL module */ nwalRetVal = nwal_create(&nwalGlobCfg, &nwalSizeInfo, sizes, bases, &p_nwal_context->nwalInstHandle); if(nwalRetVal != nwal_OK) { netapi_Log ("netapip_initNwal: nwal_create Failed %d\n",nwalRetVal); while(1); } netapi_Log("netapip_initNwal- Global and Local Network initialization Successful \n"); return 1; } /******************************************************************** * FUNCTION PURPOSE: Internal NETAPI function to start NWAL ******************************************************************** * DESCRIPTION: Internal NETAPI function to start NWAL, per thread/core ********************************************************************/ int netapip_startNwal(Pktlib_HeapHandle pkt_heap, Pktlib_HeapHandle cmd_rx_heap, Pktlib_HeapHandle cmd_tx_heap, NETAPI_NWAL_LOCAL_CONTEXT_T *p, NETAPI_CFG_T *p_cfg, NETAPI_NWAL_GLOBAL_CONTEXT_T * p_nwal_glob_context ) { nwalLocCfg_t nwalLocCfg; int count=0; static int first_time = 0; nwal_RetValue nwalRetVal; memset(&nwalLocCfg,0,sizeof(nwalLocCfg)); /* Update the Start of Packet Offset for the default flows created * by NWAL */ nwalLocCfg.rxSopPktOffset = p_cfg->def_flow_pkt_rx_offset; nwalLocCfg.rxPktTailRoomSz = p_cfg->def_heap_tailroom_size; /* Call back registration for the core */ nwalLocCfg.pRxPktCallBack = netapip_pktioNWALRxPktCallback; nwalLocCfg.pCmdCallBack = netapip_netcpCfgNWALCmdCallBack; nwalLocCfg.pPaStatsCallBack = netapip_netcpCfgNWALCmdPaStatsReply; nwalLocCfg.pRxDmCallBack= netapip_pktioNWALSBPktCallback; //sideband mode callback /* Initialize Buffer Pool for Control packets from NetCP to Host */ nwalLocCfg.rxCtlPool.numBufPools = 1; nwalLocCfg.rxCtlPool.bufPool[0].descSize = TUNE_NETAPI_DESC_SIZE; nwalLocCfg.rxCtlPool.bufPool[0].bufSize = TUNE_NETAPI_CONFIG_MAX_CTL_RXTX_BUF_SIZE; nwalLocCfg.rxCtlPool.bufPool[0].heapHandle = cmd_rx_heap; /* Initialize Buffer Pool for Control packets from Host to NetCP */ nwalLocCfg.txCtlPool.numBufPools = 1; nwalLocCfg.txCtlPool.bufPool[0].descSize = TUNE_NETAPI_DESC_SIZE; nwalLocCfg.txCtlPool.bufPool[0].bufSize = TUNE_NETAPI_CONFIG_MAX_CTL_RXTX_BUF_SIZE; nwalLocCfg.txCtlPool.bufPool[0].heapHandle = cmd_tx_heap; /* Initialize Buffer Pool for Packets from NetCP to Host */ nwalLocCfg.rxPktPool.numBufPools = 1; nwalLocCfg.rxPktPool.bufPool[0].descSize = TUNE_NETAPI_DESC_SIZE; nwalLocCfg.rxPktPool.bufPool[0].bufSize = p_cfg->def_heap_buf_size; nwalLocCfg.rxPktPool.bufPool[0].heapHandle = pkt_heap; /* Initialize Buffer Pool for Packets from Host to NetCP */ nwalLocCfg.txPktPool.numBufPools = 1; nwalLocCfg.txPktPool.bufPool[0].descSize = TUNE_NETAPI_DESC_SIZE; nwalLocCfg.txPktPool.bufPool[0].bufSize = p_cfg->def_heap_buf_size; nwalLocCfg.txPktPool.bufPool[0].heapHandle = pkt_heap; memcpy(&p->nwalLocCfg,&nwalLocCfg,sizeof(nwalLocCfg_t)); while(1) { nwalRetVal = nwal_start(p_nwal_glob_context->nwalInstHandle,&nwalLocCfg); if(nwalRetVal == nwal_ERR_INVALID_STATE) { continue; } break; } if(nwalRetVal != nwal_OK) { netapi_Log (">nwal_start:Failed ->err %d !!!\n", nwalRetVal); return -1; } p->state = NETAPI_NW_CXT_LOC_ACTIVE; return 1; } /*********************************************************************** * FUNCTION PURPOSE: Internal NETAPI function to initialize the 64 bit timer. *********************************************************************** * DESCRIPTION: Internal NETAPI function to initialize the 64 bit timer. for tci6614 ONLY **********************************************************************/ int netapip_initTimer(void) { #ifdef CORTEX_A8 return t64_start(); #endif } /*************************************************************************** * FUNCTION PURPOSE: NETAPI internal function for virtual memory allocation. *************************************************************************** * DESCRIPTION: NETAPI internal function for virtual memory allocation. **************************************************************************/ static uint8_t* netapip_sharedMemoryMalloc(uint32_t size) { return (uint8_t *)hplib_vmMemAlloc(size +netapi_global.cfg.def_heap_extra_size , 128, 0); } /******************************************************************** * FUNCTION PURPOSE: NETAPI internal function for virtual memory free. ******************************************************************** * DESCRIPTION: NETAPI internal function for virtual memory free. ********************************************************************/ static void netapip_sharedMemoryFree(uint8_t* ptr, uint32_t size) { /* Do Nothing. */ netapi_Log("netapi Unexpected. need to provide a free () for some reason!! \n"); return; } //defensive: clean out stuff hanging around // // open a bunch of free queues and zap them #define NQUEUES2CLEAR 35 static Qmss_QueueHnd tempQH[NQUEUES2CLEAR]; void netapip_cleanupAtStart(void) { int i; uint8_t isAllocated; for(i=0;i cleanup on failure if (!sharedHeapHandle) { netapi_Log(">'netapi' heap create failed, Error Code: %d\n",errCode); return -1;} handle->netcp_heap= sharedHeapHandle; /* Update for Control */ heapCfg.name = "netapi_control_rx"; heapCfg.sharedHeap = 1; heapCfg.dataBufferSize = TUNE_NETAPI_CONFIG_MAX_CTL_RXTX_BUF_SIZE; heapCfg.numPkts = TUNE_NETAPI_CONFIG_NUM_CTL_RX_BUF; heapCfg.numZeroBufferPackets= 0; controlRxHeapHandle = Pktlib_createHeap(&heapCfg, &errCode); netapi_Log("netapip_systemInit: returned from Pktlib_createHeap2\n"); //todo -> cleanup on failure if (!controlRxHeapHandle) { netapi_Log("netapi -'netapi_control_rx' heap create failed, Error Code: %d\n",errCode); return -1;} handle->netcp_control_rx_heap= controlRxHeapHandle; heapCfg.name = "netapi_control_tx"; heapCfg.numPkts = TUNE_NETAPI_CONFIG_NUM_CTL_TX_BUF; controlTxHeapHandle = Pktlib_createHeap(&heapCfg, &errCode); netapi_Log("netapip_systemInit: returned from Pktlib_createHeap3\n"); //todo -> cleanup on failure if (!controlTxHeapHandle) { netapi_Log("netapi -'netapi_control_tx' heap create failed, Error Code: %d\n",errCode); return -1;} handle->netcp_control_tx_heap= controlTxHeapHandle; /* now NWAL */ result = netapip_initNwal( TUNE_NETAPI_QM_GLOBAL_REGION, &netapi_pktlib_ifTable, &netapi_global.nwal_context, &netapi_global.cfg); if (result<0) {netapi_Log("netapi init_nwal() failed\n"); return -1; } netapi_Log("netapip_systemInit: returned from netapip_initNwal\n"); /* start NWAL */ /* Common Initialization for all cores */ while(count < TUNE_NETAPI_MAX_NUM_TRANS) { netapi_global.nwal_context.transInfos[count].transId = count; count++; } result = netapip_startNwal(sharedHeapHandle, controlRxHeapHandle, controlTxHeapHandle, &handle->nwal_local, &netapi_global.cfg, &netapi_global.nwal_context); if (result<0) {netapi_Log("netapi start_nwal() failed\n"); return -1; } netapi_Log("netapip_systemInit: returned from netapip_startNwal\n"); return 0; } /**************************************************************************** * FUNCTION PURPOSE: NETAPI internal function which performs clean for linux user space **************************************************************************** * DESCRIPTION: NETAPI internal function which performs clean for linux user space ***************************************************************************/ void netapip_zapQ(int queueNum) { char * descPtr; int i; if (!queueNum) { return; } for (i=0;;i+=1 ) { /* Pop descriptor from source queue */ if ((descPtr = (char *)pktio_mQmssQueuePopRaw(queueNum)) == NULL) { break; } } if(i) { netapi_Log("netapip_zapQ: @recovery - %d descriptors cleaned from qn %d\n",i, queueNum); } } /**************************************************************************** * FUNCTION PURPOSE: NETAPI internal function to display internal heap stats. **************************************************************************** * DESCRIPTION: NETAPI internal function to display internal heap stats. ***************************************************************************/ void netapi_dump_internal_heap_stats(void) { Pktlib_HeapStats pktLibHeapStats; Pktlib_getHeapStats(netapi_get_global()->nwal_context.pa2sa_heap,&pktLibHeapStats); netapi_Log("PA2SA(ingress) stats> #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets, pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage); netapi_Log(" > #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n", pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter, pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter); #if 0 Pktlib_getHeapStats(netapi_get_global()->nwal_context.pa2saTX_heap,&pktLibHeapStats); netapi_Log("PA2SA(egress) stats> #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets, pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage); netapi_Log(" > #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n", pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter, pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter); #endif Pktlib_getHeapStats(netapi_get_global()->nwal_context.sa2pa_heap,&pktLibHeapStats); netapi_Log("SA2PA stats> #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets, pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage); netapi_Log(" > #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n", pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter, pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter); }