index 91fc87cd09e0f301caf493883cce99a3196e13b8..68168e0c0dfce577d449a18c4290c758c7cd97df 100755 (executable)
-/************************************************\r
-* FILE: netapi_init.c\r
-* Global, local initialization of NETAPI\r
- *\r
- * DESCRIPTION: Functions to initialize framework resources for running NETAPI\r
- *\r
- * REVISION HISTORY:\r
- *\r
- * Copyright (c) Texas Instruments Incorporated 2010-2011\r
- * \r
- * Redistribution and use in source and binary forms, with or without \r
- * modification, are permitted provided that the following conditions \r
- * are met:\r
- *\r
- * Redistributions of source code must retain the above copyright \r
- * notice, this list of conditions and the following disclaimer.\r
- *\r
- * Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the \r
- * documentation and/or other materials provided with the \r
- * distribution.\r
- *\r
- * Neither the name of Texas Instruments Incorporated nor the names of\r
- * its contributors may be used to endorse or promote products derived\r
- * from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \r
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT \r
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT \r
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, \r
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT \r
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- *\r
- ***********************************************/\r
-#include <stdint.h>\r
-#include <stdio.h>\r
-#include <string.h>\r
-#include <sys/types.h>\r
-#include <sys/stat.h>\r
-#include <fcntl.h>\r
-#include <sys/mman.h>\r
-#include <errno.h>\r
-#include <unistd.h>\r
-\r
-#include <ti/drv/nwal/nwal.h>\r
-#include "netapi.h"\r
-#include "netapi_vm.h"\r
-#include "netapi_loc.h"\r
-#include "ti/drv/nwal/nwal.h"\r
-\r
-/* CSL RL includes */\r
-#include <ti/csl/cslr_device.h>\r
-#include <ti/csl/cslr_qm_config.h>\r
-#include <ti/csl/cslr_qm_descriptor_region_config.h>\r
-#include <ti/csl/cslr_qm_queue_management.h>\r
-#include <ti/csl/cslr_qm_queue_status_config.h>\r
-#include <ti/csl/cslr_qm_intd.h>\r
-#include <ti/csl/cslr_pdsp.h>\r
-#include <ti/csl/csl_qm_queue.h>\r
-#include <ti/csl/cslr_cppidma_global_config.h>\r
-#include <ti/csl/cslr_cppidma_rx_channel_config.h>\r
-#include <ti/csl/cslr_cppidma_rx_flow_config.h>\r
-#include <ti/csl/cslr_cppidma_tx_channel_config.h>\r
-#include <ti/csl/cslr_cppidma_tx_scheduler_config.h>\r
-#include <ti/csl/csl_cppi.h>\r
-#include <ti/csl/csl_pscAux.h>\r
-#include <ti/csl/csl_semAux.h>\r
-#include <ti/csl/csl_cacheAux.h>\r
-#include <ti/csl/csl_xmcAux.h>\r
-#include <ti/csl/csl_cpsw_3gfAux.h>\r
-#include <ti/csl/csl_cpsw.h>\r
-#include <ti/csl/csl_cpsgmiiAux.h>\r
-#include <ti/drv/qmss/qmss_qm.h>\r
-//pull in device config for qmss, cppi\r
-#include <ti/drv/qmss/device/qmss_device.c>\r
-#include <ti/drv/cppi/device/cppi_device.c>\r
-\r
-/* TODO verify: */\r
-#define CACHE_LINESZ 64\r
-\r
-#define System_printf printf\r
-#define ALIGN(x) __attribute__((aligned (x)))\r
-\r
-/*****************************************************************************\r
- * Global Resources shared by all Cores\r
- *****************************************************************************/\r
-uint8_t *QMemGlobDescRam = 0;\r
-uint8_t *cppiMemPaSaLinkBuf = 0;\r
-uint8_t *cppiMemSaPaLinkBuf = 0;\r
-\r
-/*****************************************************************************\r
- * Local Resource allocated at each Core\r
- *****************************************************************************/\r
-/* Descriptors in global shared */\r
-uint8_t *QMemLocDescRam = NULL;\r
-uint8_t *cppiMemRxPktLinkBuf = NULL;\r
-uint8_t *cppiMemTxPktLinkBuf = NULL;\r
-uint8_t *cppiMemRxCtlLinkBuf = NULL;\r
-uint8_t *cppiMemTxCtlLinkBuf = NULL;\r
-\r
-\r
-//****************************************************\r
-// initialize CPSW (switch) [per SOC]\r
-//***************************************************\r
-int netapi_init_cpsw(void)\r
-{\r
- CSL_CPSW_3GF_ALE_PORTCONTROL alePortControlCfg;\r
-\r
- CSL_CPSW_3GF_clearAleTable();\r
-\r
- alePortControlCfg.dropUntaggedEnable = 0;\r
- alePortControlCfg.vidIngressCheckEnable = 0;\r
-\r
- alePortControlCfg.mcastLimit = 0;\r
- alePortControlCfg.bcastLimit = 0;\r
-\r
- /* Disable learning mode for Port 0 */\r
- alePortControlCfg.noLearnModeEnable = 1;\r
- alePortControlCfg.portState = ALE_PORTSTATE_FORWARD;\r
- CSL_CPSW_3GF_setAlePortControlReg (0, &alePortControlCfg);\r
-\r
- /* Enable learning mode for Port 1 */\r
- alePortControlCfg.noLearnModeEnable = 0;\r
- alePortControlCfg.portState = ALE_PORTSTATE_FORWARD;\r
- CSL_CPSW_3GF_setAlePortControlReg (1, &alePortControlCfg);\r
-\r
- /* Enable learning mode for Port 2 */\r
- alePortControlCfg.noLearnModeEnable = 0;\r
- alePortControlCfg.portState = ALE_PORTSTATE_FORWARD;\r
- CSL_CPSW_3GF_setAlePortControlReg (2, &alePortControlCfg);\r
-\r
- return 1;\r
-}\r
-\r
-//****************************************************\r
-// initialize QM (per SOC)\r
-//***************************************************\r
-int netapi_init_qm(int max_descriptors)\r
-{\r
- Qmss_InitCfg qmssInitConfig;\r
- int32_t result;\r
- Qmss_GlobalConfigParams nwalTest_qmssGblCfgParams;\r
-\r
- memset (&qmssInitConfig, 0, sizeof (Qmss_InitCfg));\r
-\r
- /* Use Internal Linking RAM for optimal performance */\r
- qmssInitConfig.linkingRAM0Base = 0;\r
- qmssInitConfig.linkingRAM0Size = 0;\r
- qmssInitConfig.linkingRAM1Base = 0;\r
- qmssInitConfig.maxDescNum = max_descriptors;\r
- qmssInitConfig.qmssHwStatus =QMSS_HW_INIT_COMPLETE; //bypass some of the hw init\r
- nwalTest_qmssGblCfgParams = qmssGblCfgParams[0];\r
-\r
- nwalTest_qmssGblCfgParams.qmConfigReg = (void *)((uint8_t *)netapi_VM_qmssCfgVaddr +\r
- (CSL_QM_SS_CFG_CONFIG_STARVATION_COUNTER_REGS - CSL_QM_SS_CFG_QUE_PEEK_REGS));\r
- nwalTest_qmssGblCfgParams.qmDescReg = (void *)((uint32_t)netapi_VM_qmssCfgVaddr +\r
- ((uint32_t)CSL_QM_SS_CFG_DESCRIPTION_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS);\r
- nwalTest_qmssGblCfgParams.qmQueMgmtReg = (void *)((uint32_t)netapi_VM_qmssCfgVaddr +\r
- ((uint32_t)CSL_QM_SS_CFG_QM_QUEUE_DEQUEUE_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS);\r
- nwalTest_qmssGblCfgParams.qmQueMgmtProxyReg = (void *)((uint32_t)netapi_VM_qmssCfgVaddr +\r
- ((uint32_t)CSL_QM_SS_CFG_PROXY_QUEUE_DEQUEUE_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS);\r
- nwalTest_qmssGblCfgParams.qmQueStatReg = (void *)((uint32_t)netapi_VM_qmssCfgVaddr +\r
- ((uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS);\r
- nwalTest_qmssGblCfgParams.qmQueIntdReg = (void *)((uint32_t)netapi_VM_qmssCfgVaddr +\r
- ((uint32_t)CSL_QM_SS_CFG_INTD_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS);\r
- nwalTest_qmssGblCfgParams.qmPdspCmdReg[0] = (void *)((uint32_t)netapi_VM_qmssCfgVaddr +\r
- ((uint32_t)CSL_QM_SS_CFG_SCRACH_RAM1_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS);\r
- nwalTest_qmssGblCfgParams.qmPdspCmdReg[1] = (void *)((uint32_t)netapi_VM_qmssCfgVaddr +\r
- ((uint32_t)CSL_QM_SS_CFG_SCRACH_RAM2_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS);\r
- nwalTest_qmssGblCfgParams.qmPdspCtrlReg[0] = (void *)((uint32_t)netapi_VM_qmssCfgVaddr +\r
- ((uint32_t)CSL_QM_SS_CFG_ADSP1_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS);\r
- nwalTest_qmssGblCfgParams.qmPdspCtrlReg[1] = (void *)((uint32_t)netapi_VM_qmssCfgVaddr +\r
- ((uint32_t)CSL_QM_SS_CFG_ADSP2_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS);\r
- nwalTest_qmssGblCfgParams.qmPdspIRamReg[0] = (void *)((uint32_t)netapi_VM_qmssCfgVaddr +\r
- ((uint32_t)CSL_QM_SS_CFG_APDSP1_RAM_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS);\r
- nwalTest_qmssGblCfgParams.qmPdspIRamReg[1] = (void *)((uint32_t)netapi_VM_qmssCfgVaddr +\r
- ((uint32_t)CSL_QM_SS_CFG_APDSP2_RAM_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS);\r
- nwalTest_qmssGblCfgParams.qmStatusRAM = (void *)((uint32_t)netapi_VM_qmssCfgVaddr +\r
- ((uint32_t)CSL_QM_SS_CFG_QM_STATUS_RAM_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS);\r
- nwalTest_qmssGblCfgParams.qmLinkingRAMReg = (void *)((uint32_t)netapi_VM_qmssCfgVaddr +\r
- ((uint32_t)CSL_QM_SS_CFG_LINKING_RAM_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS);\r
- nwalTest_qmssGblCfgParams.qmMcDMAReg = (void *)((uint32_t)netapi_VM_qmssCfgVaddr +\r
- ((uint32_t)CSL_QM_SS_CFG_MCDMA_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS);\r
- nwalTest_qmssGblCfgParams.qmTimer16Reg[0] = (void *)((uint32_t)netapi_VM_qmssCfgVaddr +\r
- ((uint32_t)CSL_QM_SS_CFG_TIMER1_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS);\r
- nwalTest_qmssGblCfgParams.qmTimer16Reg[1] = (void *)((uint32_t)netapi_VM_qmssCfgVaddr +\r
- ((uint32_t)CSL_QM_SS_CFG_TIMER2_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS);\r
- nwalTest_qmssGblCfgParams.qmQueMgmtDataReg = (void *)((uint32_t)netapi_VM_qmssDataVaddr);\r
- nwalTest_qmssGblCfgParams.qmQueMgmtProxyDataReg = \r
- (void *)((uint32_t)netapi_VM_qmssDataVaddr + ((uint32_t)(0x44040000) - (uint32_t)(0x44020000)));\r
-\r
- result = Qmss_init (&qmssInitConfig, &nwalTest_qmssGblCfgParams);\r
- if (result != QMSS_SOK) {\r
- System_printf (">function init_qm: qmss_Init failed with error code %d\n", result);\r
- return (nwal_FALSE);\r
- }\r
-\r
- return 1;\r
-}\r
-\r
-//****************************************************\r
-// Set up QM memory region (per SOC)\r
-//***************************************************\r
-int netapi_qm_setup_mem_region(\r
- uint32_t numDesc,\r
- uint32_t descSize,\r
- uint32_t* pDescMemBase,\r
- Qmss_MemRegion memRegion)\r
-{\r
- Qmss_MemRegInfo memInfo;\r
- Int32 result;\r
- Int n;\r
- static int netapi_qm_region_index=0;\r
-\r
- memset(&memInfo,0,sizeof(Qmss_MemRegInfo));\r
- memInfo.descBase = pDescMemBase;\r
- memInfo.descSize = descSize;\r
- memInfo.descNum = numDesc;\r
- memInfo.manageDescFlag = Qmss_ManageDesc_MANAGE_DESCRIPTOR;\r
- memInfo.memRegion = memRegion;\r
-\r
- if(memRegion == NETAPI_GLOBAL_REGION)\r
- {\r
- memInfo.startIndex = TUNE_NETAPI_QM_START_INDEX; //was 0\r
- netapi_qm_region_index += numDesc;\r
- }else if(memRegion ==NETAPI_LOCAL_REGION)\r
- {\r
- /* 2nd region for descriptors (perhaps private?) */\r
- memInfo.startIndex = netapi_qm_region_index;\r
- }\r
- else\r
- {\r
- return -1 ;\r
- }\r
-\r
- memset (pDescMemBase, 0, (descSize * numDesc));\r
-\r
- result = Qmss_insertMemoryRegion (&memInfo);\r
- if (result < QMSS_SOK) \r
- {\r
- printf (">function setup_qm_region: Qmss_insertMemoryRegion returned error code %d\n", result);\r
- return (-1);\r
- }\r
-\r
- return 1;\r
-\r
-}\r
-\r
-//****************************************************\r
-// Start QM (per thread)\r
-//***************************************************\r
-int netapi_start_qm(void)\r
-{\r
- int32_t result;\r
- result = Qmss_start();\r
- if (result != QMSS_SOK)\r
- {\r
- System_printf (">start_qm: Qmss_start failed with error code %d\n", result);\r
- return (-1);\r
- }\r
- return 1;\r
-}\r
-\r
-//*************************************************\r
-//initilaize CPPI (once per soc)\r
-//*************************************************\r
-int netapi_init_cppi(void)\r
-{\r
- int32_t result, i;\r
- Cppi_GlobalConfigParams nwalTest_cppiGblCfgParams[CPPI_MAX_CPDMA];\r
-\r
- for (i=0; i<CPPI_MAX_CPDMA; i++)\r
- nwalTest_cppiGblCfgParams[i] = cppiGblCfgParams[i];\r
-\r
- /* SRIO CPDMA regs */\r
- nwalTest_cppiGblCfgParams[Cppi_CpDma_SRIO_CPDMA].gblCfgRegs =\r
- (void *)((uint32_t)netapi_VM_srioCfgVaddr +\r
- (((uint32_t)CSL_SRIO_CONFIG_CPPI_DMA_GLOBAL_CFG_REGS) - (uint32_t)CSL_SRIO_CONFIG_REGS));\r
- nwalTest_cppiGblCfgParams[Cppi_CpDma_SRIO_CPDMA].txChRegs =\r
- (void *)((uint32_t)netapi_VM_srioCfgVaddr +\r
- (((uint32_t)CSL_SRIO_CONFIG_CPPI_DMA_TX_CFG_REGS) - (uint32_t)CSL_SRIO_CONFIG_REGS));\r
-\r
- nwalTest_cppiGblCfgParams[Cppi_CpDma_SRIO_CPDMA].rxChRegs =\r
- (void *)((uint32_t)netapi_VM_srioCfgVaddr +\r
- (((uint32_t)CSL_SRIO_CONFIG_CPPI_DMA_RX_CFG_REGS) - (uint32_t)CSL_SRIO_CONFIG_REGS));\r
- nwalTest_cppiGblCfgParams[Cppi_CpDma_SRIO_CPDMA].txSchedRegs =\r
- (void *)((uint32_t)netapi_VM_srioCfgVaddr +\r
- (((uint32_t)CSL_SRIO_CONFIG_CPPI_DMA_TX_SCHEDULER_CFG_REGS) - (uint32_t)CSL_SRIO_CONFIG_REGS));\r
- nwalTest_cppiGblCfgParams[Cppi_CpDma_SRIO_CPDMA].rxFlowRegs =\r
- (void *)((uint32_t)netapi_VM_srioCfgVaddr +\r
- (((uint32_t)CSL_SRIO_CONFIG_CPPI_DMA_RX_FLOW_CFG_REGS) - (uint32_t)CSL_SRIO_CONFIG_REGS));\r
-\r
- /* PASS CPDMA regs */\r
- nwalTest_cppiGblCfgParams[Cppi_CpDma_PASS_CPDMA].gblCfgRegs =\r
- (void *)((uint32_t)netapi_VM_passCfgVaddr +\r
- (((uint32_t)CSL_PA_SS_CFG_CPPI_DMA_GLOBAL_CFG_REGS) - (uint32_t)CSL_PA_SS_CFG_REGS));\r
- nwalTest_cppiGblCfgParams[Cppi_CpDma_PASS_CPDMA].txChRegs =\r
- (void *)((uint32_t)netapi_VM_passCfgVaddr +\r
- (((uint32_t)CSL_PA_SS_CFG_CPPI_DMA_TX_CFG_REGS) - (uint32_t)CSL_PA_SS_CFG_REGS));\r
- nwalTest_cppiGblCfgParams[Cppi_CpDma_PASS_CPDMA].rxChRegs =\r
- (void *)((uint32_t)netapi_VM_passCfgVaddr +\r
- (((uint32_t)CSL_PA_SS_CFG_CPPI_DMA_RX_CFG_REGS) - (uint32_t)CSL_PA_SS_CFG_REGS));\r
- nwalTest_cppiGblCfgParams[Cppi_CpDma_PASS_CPDMA].txSchedRegs =\r
- (void *)((uint32_t)netapi_VM_passCfgVaddr +\r
- (((uint32_t)CSL_PA_SS_CFG_CPPI_DMA_TX_SCHEDULER_CFG_REGS) - (uint32_t)CSL_PA_SS_CFG_REGS));\r
- nwalTest_cppiGblCfgParams[Cppi_CpDma_PASS_CPDMA].rxFlowRegs =\r
- (void *)((uint32_t)netapi_VM_passCfgVaddr +\r
- (((uint32_t)CSL_PA_SS_CFG_CPPI_DMA_RX_FLOW_CFG_REGS) - (uint32_t)CSL_PA_SS_CFG_REGS));\r
- /* QMSS CPDMA regs */\r
- nwalTest_cppiGblCfgParams[Cppi_CpDma_QMSS_CPDMA].gblCfgRegs =\r
- (void *)((uint32_t)netapi_VM_qmssCfgVaddr +\r
- (((uint32_t)CSL_QM_SS_CFG_CPPI_DMA_GLOBAL_CFG_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS));\r
- nwalTest_cppiGblCfgParams[Cppi_CpDma_QMSS_CPDMA].txChRegs =\r
- (void *)((uint32_t)netapi_VM_qmssCfgVaddr +\r
- (((uint32_t)CSL_QM_SS_CFG_CPPI_DMA_TX_CFG_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS));\r
- nwalTest_cppiGblCfgParams[Cppi_CpDma_QMSS_CPDMA].rxChRegs =\r
- (void *)((uint32_t)netapi_VM_qmssCfgVaddr +\r
- (((uint32_t)CSL_QM_SS_CFG_CPPI_DMA_RX_CFG_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS));\r
- nwalTest_cppiGblCfgParams[Cppi_CpDma_QMSS_CPDMA].txSchedRegs =\r
- (void *)((uint32_t)netapi_VM_qmssCfgVaddr +\r
- (((uint32_t)CSL_QM_SS_CFG_CPPI_DMA_TX_SCHEDULER_CFG_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS));\r
- nwalTest_cppiGblCfgParams[Cppi_CpDma_QMSS_CPDMA].rxFlowRegs =\r
- (void *)((uint32_t)netapi_VM_qmssCfgVaddr +\r
- (((uint32_t)CSL_QM_SS_CFG_CPPI_DMA_RX_FLOW_CFG_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS));\r
-\r
- result = Cppi_init (nwalTest_cppiGblCfgParams);\r
- if (result != CPPI_SOK) \r
- {\r
- printf (">function cppi_init: Cppi_init failed with error code %d\n", result);\r
- return (-1);\r
- }\r
- return 1;\r
-}\r
-\r
-//*************************************************\r
-//initialize NWAL (one per soc) \r
-//*************************************************\r
-/*** NWAL Memory Buffer Configuration ***/\r
-#define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_HANDLE 3400\r
-uint8_t nwalInstMem[NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_HANDLE]ALIGN(CACHE_LINESZ);\r
-\r
-#define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_MAC 128\r
-#define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_IPSEC_HANDLE_PER_CHAN 256\r
-#define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_IP 128\r
-#define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_PORT 128\r
-#define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_L2L3_HDR 128\r
-#define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_LOC_CONTEXT 384\r
-#define NWAL_CHAN_HANDLE_SIZE ((NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_MAC * TUNE_NETAPI_MAX_NUM_MAC) + \\r
- (NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_IPSEC_HANDLE_PER_CHAN * TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS*2) + \\r
- (NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_IP * TUNE_NETAPI_MAX_NUM_IP) + \\r
- (NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_PORT * TUNE_NETAPI_MAX_NUM_PORTS)+ \\r
- (NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_LOC_CONTEXT * TUNE_NETAPI_NUM_CORES) + \\r
- (NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_L2L3_HDR * TUNE_NETAPI_MAX_NUM_L2_L3_HDRS))\r
-\r
-uint8_t nwalHandleMem[NWAL_CHAN_HANDLE_SIZE]ALIGN(CACHE_LINESZ);\r
-\r
-/* todo: Check if below size information can be made available from pa interface file */\r
-#define NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF0 128\r
-/* PA instance */\r
-/* Memory used for the PA Instance. Needs to be assigned global uncached memory for chip */\r
-uint8_t paBuf0[NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF0]ALIGN(CACHE_LINESZ);\r
-\r
-/* Memory used for PA handles */\r
-#define NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF1 128\r
-uint8_t paBuf1[NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF1]ALIGN(CACHE_LINESZ);\r
-\r
-#define NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF2 768 \r
-uint8_t paBuf2[NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF2]ALIGN(CACHE_LINESZ);\r
-\r
-/* Memory used for SA LLD global Handle */\r
-#define NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE 384\r
-uint8_t salldHandle[NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE]ALIGN(CACHE_LINESZ);\r
-\r
-#if 0 //need to alloc this since we need phy addr also \r
-/* Memory used for SA contet Handle */\r
-#define NETAPI_NWAL_CONFIG_BUFSIZE_SA_CONTEXT_PER_CHAN 384\r
-uint8_t saContext[NETAPI_NWAL_CONFIG_BUFSIZE_SA_CONTEXT_PER_CHAN * TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS]ALIGN(CACHE_LINESZ);\r
-#endif\r
-\r
-/* Memory used by SA LLD per Channel */\r
-#define NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE_PER_CHAN 512\r
-uint8_t salldChanHandle[NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE_PER_CHAN * TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS*2]ALIGN(CACHE_LINESZ);\r
-\r
-\r
-/*******************************************\r
- * Initialize the nwal subsystem for NETAPI use\r
- ***********************************************/\r
-int netapi_init_nwal(\r
- int region2use, \r
- Pktlib_HeapIfTable * p_table,\r
- NETAPI_NWAL_GLOBAL_CONTEXT_T * p_nwal_context, \r
- NETAPI_CFG_T*p_cfg )\r
-{\r
- nwalSizeInfo_t nwalSizeInfo;\r
- nwalMemBuf_t nwalMemBuf[nwal_N_BUFS];\r
- nwal_RetValue nwalRetVal;\r
- nwalGlobCfg_t nwalGlobCfg;\r
- uint8_t count;\r
- int sizes[nwal_N_BUFS];\r
- int aligns[nwal_N_BUFS];\r
- void* bases[nwal_N_BUFS]; \r
- Pktlib_HeapCfg heapCfg;\r
- int32_t errCode;\r
-\r
- memset(p_nwal_context,0,sizeof( NETAPI_NWAL_GLOBAL_CONTEXT_T) );\r
- memset(&nwalGlobCfg,0,sizeof(nwalGlobCfg_t ) );\r
-\r
-\r
- /* Initialize Buffer Pool for NetCP PA to SA packets */\r
- nwalGlobCfg.pa2SaBufPool.numBufPools = 1;\r
- nwalGlobCfg.pa2SaBufPool.bufPool[0].descSize = TUNE_NETAPI_DESC_SIZE;\r
- nwalGlobCfg.pa2SaBufPool.bufPool[0].bufSize = p_cfg->def_heap_buf_size;\r
-\r
- /* Initialize the heap configuration. */\r
- memset ((void *)&heapCfg, 0, sizeof(Pktlib_HeapCfg));\r
- /* Populate the heap configuration */\r
- heapCfg.name = "nwal PA2SA";\r
- heapCfg.memRegion = region2use;\r
- heapCfg.sharedHeap = 0;\r
- heapCfg.useStarvationQueue = 0;\r
- heapCfg.dataBufferSize = p_cfg->def_heap_buf_size;\r
- heapCfg.numPkts = TUNE_NETAPI_CONFIG_MAX_PA_TO_SA_DESC;\r
- heapCfg.numZeroBufferPackets= 0;\r
- heapCfg.heapInterfaceTable.data_malloc = p_table->data_malloc;\r
- heapCfg.heapInterfaceTable.data_free = p_table->data_free;\r
- heapCfg.dataBufferPktThreshold = 0;\r
- heapCfg.zeroBufferPktThreshold = 0;\r
-\r
-\r
- nwalGlobCfg.pa2SaBufPool.bufPool[0].heapHandle = p_nwal_context->pa2sa_heap=\r
- Pktlib_createHeap(&heapCfg, &errCode);\r
- if(nwalGlobCfg.pa2SaBufPool.bufPool[0].heapHandle == NULL)\r
- {\r
- printf (">Pktlib_createHeap:Heap Creation Failed for PA to SA Buffer Pool , Error Code: %d\n",errCode); \r
- netapi_err_teardown(); \r
- return -1;\r
- }\r
-\r
- /* Initialize Buffer Pool for NetCP SA to PA packets */\r
- nwalGlobCfg.sa2PaBufPool.numBufPools = 1;\r
- nwalGlobCfg.sa2PaBufPool.bufPool[0].descSize = TUNE_NETAPI_DESC_SIZE;\r
- nwalGlobCfg.sa2PaBufPool.bufPool[0].bufSize = p_cfg->def_heap_buf_size;\r
-\r
- /* Populate the heap configuration */\r
- heapCfg.name = "nwal SA2PA";\r
- heapCfg.numPkts = TUNE_NETAPI_CONFIG_MAX_SA_TO_PA_DESC;\r
-\r
- nwalGlobCfg.sa2PaBufPool.bufPool[0].heapHandle = p_nwal_context->sa2pa_heap=\r
- Pktlib_createHeap(&heapCfg, &errCode);\r
- if(nwalGlobCfg.sa2PaBufPool.bufPool[0].heapHandle == NULL)\r
- {\r
- printf (">Pktlib_createHeap:Heap Creation Failed for SA to PA Buffer Pool , Error Code: %d\n",errCode); \r
- netapi_err_teardown();\r
- return -1;\r
- }\r
-\r
- nwalGlobCfg.hopLimit = 5;/* Default TTL / Hop Limit */\r
- nwalGlobCfg.paPowerOn = nwal_TRUE;\r
- nwalGlobCfg.saPowerOn = nwal_TRUE;\r
- nwalGlobCfg.paFwActive = nwal_TRUE;\r
- nwalGlobCfg.saFwActive = nwal_FALSE;\r
-\r
- /* Pick Default Physical Address */\r
- nwalGlobCfg.paVirtBaseAddr = (uint32_t) netapi_VM_passCfgVaddr;\r
- nwalGlobCfg.saVirtBaseAddr = (uint32_t) netapi_VM_passCfgVaddr +\r
- ((uint32_t)CSL_PA_SS_CFG_CP_ACE_CFG_REGS - (uint32_t)CSL_PA_SS_CFG_REGS) ;\r
- nwalGlobCfg.rxDefPktQ = QMSS_PARAM_NOT_SPECIFIED;\r
-\r
- /* Get the Buffer Requirement from NWAL */\r
- memset(&nwalMemBuf,0,sizeof(nwalMemBuf));\r
- memset(&nwalSizeInfo,0,sizeof(nwalSizeInfo));\r
- nwalSizeInfo.nMaxMacAddress = TUNE_NETAPI_MAX_NUM_MAC;\r
- nwalSizeInfo.nMaxIpAddress = TUNE_NETAPI_MAX_NUM_IP;\r
- nwalSizeInfo.nMaxL4Ports = TUNE_NETAPI_MAX_NUM_PORTS;\r
- nwalSizeInfo.nMaxIpSecChannels = TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS;//we allocate 2 per channel\r
- nwalSizeInfo.nMaxDmSecChannels = TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS;//we allocate 2 per channel\r
- nwalSizeInfo.nMaxL2L3Hdr = TUNE_NETAPI_MAX_NUM_L2_L3_HDRS;\r
- nwalSizeInfo.nProc = TUNE_NETAPI_NUM_CORES;\r
- for(count=0;count < nwal_N_BUFS;count++)\r
- {\r
- nwalMemBuf[count].cacheLineSize = CACHE_LINESZ;\r
- }\r
- nwalRetVal = nwal_getBufferReq(&nwalSizeInfo,\r
- sizes,\r
- aligns);\r
- if(nwalRetVal != nwal_OK)\r
- {\r
- printf (">netapi: init_nwal - nwal_getBufferReq Failed %d\n", nwalRetVal);\r
- return nwal_FALSE;\r
- }\r
-\r
-/* Check for memory size requirement and update the base */\r
- count = 0;\r
- bases[nwal_BUF_INDEX_INST] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)nwalInstMem);\r
- if(NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_HANDLE < sizes[nwal_BUF_INDEX_INST])\r
- {\r
- /* Resize Memory */\r
- while(1);\r
- }\r
- count++;\r
-\r
- bases[nwal_BUF_INDEX_INT_HANDLES] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)nwalHandleMem);\r
- if(NWAL_CHAN_HANDLE_SIZE < sizes[nwal_BUF_INDEX_INT_HANDLES])\r
- {\r
- /* Resize Memory */\r
- while(1);\r
- }\r
- count++;\r
- bases[nwal_BUF_INDEX_PA_LLD_BUF0] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)paBuf0);\r
- if((NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF0) < sizes[nwal_BUF_INDEX_PA_LLD_BUF0])\r
- {\r
- /* Resize Memory */\r
- while(1);\r
- }\r
- count++;\r
-\r
- bases[nwal_BUF_INDEX_PA_LLD_BUF1] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)paBuf1);\r
- if((NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF1) < sizes[nwal_BUF_INDEX_PA_LLD_BUF1])\r
- {\r
- /* Resize Memory */\r
- while(1);\r
- }\r
- count++;\r
-\r
- bases[nwal_BUF_INDEX_PA_LLD_BUF2] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)paBuf2);\r
- if((NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF2) < sizes[nwal_BUF_INDEX_PA_LLD_BUF2])\r
- {\r
- /* Resize Memory */\r
- while(1);\r
- }\r
- count++;\r
-#ifdef NETAPI_ENABLE_SECURITY\r
- bases[nwal_BUF_INDEX_SA_LLD_HANDLE] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)salldHandle);\r
- if((NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE) < sizes[nwal_BUF_INDEX_SA_LLD_HANDLE])\r
- {\r
- /* Resize Memory */\r
- while(1);\r
- }\r
- count++;\r
-\r
- bases[nwal_BUF_INDEX_SA_CONTEXT] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)netapi_VM_SaContextVaddr);\r
- count++;\r
-\r
- bases[nwal_BUF_INDEX_SA_LLD_CHAN_HANDLE] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)salldChanHandle);\r
- if((NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE_PER_CHAN * TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS*2) <\r
- sizes[nwal_BUF_INDEX_SA_LLD_CHAN_HANDLE])\r
- {\r
- /* Resize Memory */\r
- while(1);\r
- }\r
- count++;\r
-#else\r
- bases[nwal_BUF_INDEX_SA_LLD_HANDLE] = 0;\r
- bases[nwal_BUF_INDEX_SA_CONTEXT] = 0;\r
- bases[nwal_BUF_INDEX_SA_LLD_CHAN_HANDLE] = 0;\r
- count = count+3;\r
-#endif\r
- if(count != nwal_N_BUFS)\r
- {\r
- while(1);\r
- }\r
-\r
- /* Initialize NWAL module */\r
- nwalRetVal = nwal_create(&nwalGlobCfg,\r
- &nwalSizeInfo,\r
- sizes,\r
- bases,\r
- &p_nwal_context->nwalInstHandle);\r
- if(nwalRetVal != nwal_OK)\r
- {\r
- printf (">netapi: init_nwal- nwal_create Failed %d\n",nwalRetVal);\r
- while(1);\r
- }\r
-\r
- printf(">netapi: init_nwal - Global and Local Network initialization Successful \n");\r
- return 1;\r
-}\r
-\r
-//*************************************************\r
-//* Local (per thread/core) nwal initialization0\r
-//**************************************************\r
-int netapi_start_nwal(Pktlib_HeapHandle pkt_heap,\r
- Pktlib_HeapHandle cmd_heap,\r
- NETAPI_NWAL_LOCAL_CONTEXT_T *p,\r
- NETAPI_CFG_T *p_cfg,\r
- NETAPI_NWAL_GLOBAL_CONTEXT_T * p_nwal_glob_context )\r
-{\r
- nwalLocCfg_t nwalLocCfg;\r
- int count;\r
- nwal_RetValue nwalRetVal;\r
-\r
- memset(&nwalLocCfg,0,sizeof(nwalLocCfg));\r
-\r
- /* Common Initialization for all cores */\r
- while(count < TUNE_NETAPI_MAX_NUM_TRANS)\r
- {\r
- p_nwal_glob_context->transInfos[count].transId = count;\r
- count++;\r
- }\r
-\r
- /* Update the Start of Packet Offset for the default flows created \r
- * by NWAL\r
- */\r
- nwalLocCfg.rxSopPktOffset = p_cfg->def_flow_pkt_rx_offset;\r
- nwalLocCfg.rxPktTailRoomSz = p_cfg->def_heap_tailroom_size;\r
-\r
- /* Call back registration for the core */\r
- nwalLocCfg.pRxPktCallBack = netapi_NWALRxPktCallback;\r
- nwalLocCfg.pCmdCallBack = netapi_NWALCmdCallBack;\r
- nwalLocCfg.pPaStatsCallBack = netapi_NWALCmdPaStatsReply;\r
- nwalLocCfg.pRxDmCallBack= netapi_NWALSBPktCallback; //sideband mode callback\r
-\r
- /* Initialize Buffer Pool for Control packets from NetCP to Host */\r
- nwalLocCfg.rxCtlPool.numBufPools = 1;\r
- nwalLocCfg.rxCtlPool.bufPool[0].descSize = TUNE_NETAPI_DESC_SIZE;\r
- nwalLocCfg.rxCtlPool.bufPool[0].bufSize = TUNE_NETAPI_CONFIG_MAX_CTL_RXTX_BUF_SIZE;\r
- nwalLocCfg.rxCtlPool.bufPool[0].heapHandle = cmd_heap;\r
-\r
- /* Initialize Buffer Pool for Control packets from Host to NetCP */\r
- nwalLocCfg.txCtlPool.numBufPools = 1;\r
- nwalLocCfg.txCtlPool.bufPool[0].descSize = TUNE_NETAPI_DESC_SIZE;\r
- nwalLocCfg.txCtlPool.bufPool[0].bufSize = TUNE_NETAPI_CONFIG_MAX_CTL_RXTX_BUF_SIZE;\r
- nwalLocCfg.txCtlPool.bufPool[0].heapHandle = cmd_heap;\r
-\r
-/* Initialize Buffer Pool for Packets from NetCP to Host */\r
- nwalLocCfg.rxPktPool.numBufPools = 1;\r
- nwalLocCfg.rxPktPool.bufPool[0].descSize = TUNE_NETAPI_DESC_SIZE;\r
- nwalLocCfg.rxPktPool.bufPool[0].bufSize = p_cfg->def_heap_buf_size;\r
- nwalLocCfg.rxPktPool.bufPool[0].heapHandle = pkt_heap;\r
-\r
-/* Initialize Buffer Pool for Packets from Host to NetCP */\r
- nwalLocCfg.txPktPool.numBufPools = 1;\r
- nwalLocCfg.txPktPool.bufPool[0].descSize = TUNE_NETAPI_DESC_SIZE;\r
- nwalLocCfg.txPktPool.bufPool[0].bufSize = p_cfg->def_heap_buf_size;\r
- nwalLocCfg.txPktPool.bufPool[0].heapHandle = pkt_heap;\r
-\r
- memcpy(&p->nwalLocCfg,&nwalLocCfg,sizeof(nwalLocCfg_t));\r
- while(1)\r
- {\r
- nwalRetVal = nwal_start(p_nwal_glob_context->nwalInstHandle,&nwalLocCfg);\r
- if(nwalRetVal == nwal_ERR_INVALID_STATE)\r
- {\r
- continue;\r
- }\r
- break;\r
- }\r
-\r
- if(nwalRetVal != nwal_OK)\r
- {\r
- printf (">nwal_start:Failed ->err %d !!!\n", nwalRetVal);\r
- return -1;\r
- }\r
- p->state = NETAPI_NW_CXT_LOC_ACTIVE;\r
- return 1;\r
-\r
-\r
-}\r
-//***************************************************\r
-// intialize timer\r
-//***************************************************\r
-int netapi_init_timer(void)\r
-{\r
- return t64_start();\r
-}\r
-\r
-\r
+/****************************************************************************
+* 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 <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include "ti/drv/nwal/nwal.h"
+
+/* CSL RL includes */
+#include <ti/csl/cslr_device.h>
+#include <ti/csl/cslr_qm_config.h>
+#include <ti/csl/cslr_qm_descriptor_region_config.h>
+#include <ti/csl/cslr_qm_queue_management.h>
+#include <ti/csl/cslr_qm_queue_status_config.h>
+#include <ti/csl/cslr_qm_intd.h>
+#include <ti/csl/cslr_pdsp.h>
+#include <ti/csl/csl_qm_queue.h>
+#include <ti/csl/cslr_cppidma_global_config.h>
+#include <ti/csl/cslr_cppidma_rx_channel_config.h>
+#include <ti/csl/cslr_cppidma_rx_flow_config.h>
+#include <ti/csl/cslr_cppidma_tx_channel_config.h>
+#include <ti/csl/cslr_cppidma_tx_scheduler_config.h>
+#include <ti/csl/csl_cppi.h>
+#include <ti/csl/csl_pscAux.h>
+#include <ti/csl/csl_semAux.h>
+#include <ti/csl/csl_cacheAux.h>
+#include <ti/csl/csl_xmcAux.h>
+#include <ti/drv/qmss/qmss_qm.h>
+
+
+/* pointer to NWAL local context memory block used by NWAL for local
+ context intance*/
+void* pNwalLocCtxMem = NULL;
+extern void *pRmClientHandle;
+
+nwal_Handle gPNwalInstHandle = NULL;
+
+
+extern NETAPI_SHM_T* pnetapiShm;
+/* 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_PROC_GLOBAL_T netapi_proc_global;
+extern NETAPI_HANDLE_T * netapi_proc_master;
+
+
+/* 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;
+
+
+
+#if 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;
+
+#endif
+
+
+
+NETCP_CFG_GLOB_DEVICE_PARAMS_T *p_netapi_device_cfg_local;
+Qmss_MemRegInfo memInfo;
+
+
+/********************************************************************
+ * 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,
+ int memRegion,
+ int start_index)
+{
+ //Qmss_MemRegInfo memInfo;
+ int result;
+
+ memset(&memInfo,0,sizeof(Qmss_MemRegInfo));
+ memInfo.descBase = pDescMemBase;
+ memInfo.descSize = descSize;
+ memInfo.descNum = numDesc;
+ memInfo.manageDescFlag = Qmss_ManageDesc_MANAGE_DESCRIPTOR;
+
+ if (pRmClientHandle)
+ {
+ memInfo.memRegion = -1;
+ memInfo.startIndex = QMSS_START_INDEX_NOT_SPECIFIED;
+ }
+ else
+ {
+ memInfo.memRegion = memRegion;
+ memInfo.startIndex = start_index;
+ }
+
+ memset (pDescMemBase, 0, (descSize * numDesc));
+
+ result = Qmss_insertMemoryRegion (&memInfo);
+
+ if (result < QMSS_SOK)
+ {
+ return (-1);
+ }
+ netapi_proc_master->memRegion = memInfo.memRegion;
+ 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* rmClientServiceHandle)
+{
+ int32_t result;
+ Qmss_StartCfg startCfg;
+
+ startCfg.rmServiceHandle = rmClientServiceHandle;
+ startCfg.pQmssGblCfgParams = NULL;
+ //result = Qmss_start();
+ result = Qmss_startCfg(&startCfg);
+ if (result != QMSS_SOK)
+ {
+ 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 256
+#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 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_L2L3_HDR * TUNE_NETAPI_MAX_NUM_L2_L3_HDRS))
+
+typedef struct NETAPI_NWAL_SHM_Tag
+{
+ uint8_t nwalInstMem[NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_HANDLE]ALIGN(CACHE_LINESZ);
+ uint8_t nwalHandleMem[NWAL_CHAN_HANDLE_SIZE]ALIGN(CACHE_LINESZ);
+} NETAPI_NWAL_SHM_T;
+
+
+typedef struct NETAPI_PA_SHM_Tag
+{
+/* todo: Check if below size information can be made available from pa interface file */
+#define NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF0 256
+/* 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 14592
+
+
+uint8_t paBuf2[NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF2]ALIGN(CACHE_LINESZ);
+} NETAPI_PA_SHM_T;
+
+
+typedef struct NETAPI_SA_SHM_Tag
+{
+/* 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);
+
+/* 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);
+} NETAPI_SA_SHM_T;
+
+
+
+
+
+
+
+
+/********************************************************************
+* 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;
+ nwalBaseAddrCfg_t nwalBaseAddrCfg;
+ uint8_t count;
+ int sizes[nwal_N_BUFS];
+ int aligns[nwal_N_BUFS];
+ void* bases[nwal_N_BUFS];
+ Pktlib_HeapCfg heapCfg;
+ int32_t errCode = 0;
+ void* pBase = NULL;
+ NETAPI_PA_SHM_T* paEntry = NULL;
+ NETAPI_SA_SHM_T* saEntry = NULL;
+ NETAPI_NWAL_SHM_T* nwalEntry = NULL;
+ uint32_t localCtxSize = 0;
+ memset(p_nwal_context,0,sizeof( NETAPI_NWAL_GLOBAL_CONTEXT_T) );
+ memset(&nwalGlobCfg,0,sizeof(nwalGlobCfg_t ) );
+ memset (&nwalBaseAddrCfg, 0, sizeof(nwalBaseAddrCfg_t));
+ pBase = hplib_shmOpen();
+ if (pBase)
+ {
+ if(hplib_shmAddEntry(pBase, sizeof(NETAPI_PA_SHM_T), PA_ENTRY) == hplib_OK)
+ {
+ paEntry = (NETAPI_PA_SHM_T*)hplib_shmGetEntry(pBase,PA_ENTRY);
+ nwalBaseAddrCfg.pInstPoolPaBaseAddr= (void *)paEntry;
+ }
+ else
+ {
+ return -1;
+ }
+ if(hplib_shmAddEntry(pBase, sizeof(NETAPI_SA_SHM_T), SA_ENTRY) == hplib_OK)
+ {
+ saEntry = (NETAPI_SA_SHM_T*)hplib_shmGetEntry(pBase,SA_ENTRY);
+ nwalBaseAddrCfg.pInstPoolSaBaseAddr= (void*) saEntry;
+ }
+ else
+ {
+ return -1;
+ }
+ if(hplib_shmAddEntry(pBase, sizeof(NETAPI_NWAL_SHM_T), NWAL_ENTRY) == hplib_OK)
+ {
+ nwalEntry = (NETAPI_NWAL_SHM_T*)hplib_shmGetEntry(pBase,NWAL_ENTRY);
+ }
+ else
+ {
+ return -1;
+ }
+
+ }
+ /* 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)
+ {
+ 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)
+ {
+ 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;
+
+
+ /* Update nwal cfg with virtual PA and SA addresses */
+
+
+ nwalBaseAddrCfg.paVirtBaseAddr = (uint32_t) netapi_VM_VirtAddr->passCfgVaddr;
+
+
+ nwalBaseAddrCfg.pSaVirtBaseAddr = (uint32_t) netapi_VM_VirtAddr->passCfgVaddr +
+ CSL_NETCP_CFG_SA_CFG_REGS -
+ CSL_NETCP_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)
+ {
+ 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);
+ bases[nwal_BUF_INDEX_INST] =
+ (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)nwalEntry->nwalInstMem);
+
+ if(NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_HANDLE < sizes[nwal_BUF_INDEX_INST])
+ {
+ /* Resize Memory */
+ return nwal_FALSE;
+ //while(1);
+ }
+ count++;
+
+ //bases[nwal_BUF_INDEX_INT_HANDLES] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)nwalHandleMem);
+ bases[nwal_BUF_INDEX_INT_HANDLES] =
+ (uint32_t *) Osal_nwalLocToGlobAddr((uint32_t)nwalEntry->nwalHandleMem);
+
+
+ if(NWAL_CHAN_HANDLE_SIZE < sizes[nwal_BUF_INDEX_INT_HANDLES])
+ {
+ /* Resize Memory */
+ return nwal_FALSE;
+ //while(1);
+
+ }
+ count++;
+ bases[nwal_BUF_INDEX_PA_LLD_BUF0] =
+ (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)paEntry->paBuf0);
+ if((NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF0) < sizes[nwal_BUF_INDEX_PA_LLD_BUF0])
+ {
+ /* Resize Memory */
+ return nwal_FALSE;
+ //while(1);
+
+ }
+ count++;
+
+ bases[nwal_BUF_INDEX_PA_LLD_BUF1] =
+ (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)paEntry->paBuf1);
+ if((NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF1) < sizes[nwal_BUF_INDEX_PA_LLD_BUF1])
+ {
+ /* Resize Memory */
+ return nwal_FALSE;
+ //while(1);
+
+ }
+ count++;
+
+ bases[nwal_BUF_INDEX_PA_LLD_BUF2] =
+ (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)paEntry->paBuf2);
+ if((NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF2) < sizes[nwal_BUF_INDEX_PA_LLD_BUF2])
+ {
+ /* Resize Memory */
+ return nwal_FALSE;
+ //while(1);
+
+ }
+ count++;
+#ifdef NETAPI_ENABLE_SECURITY
+ bases[nwal_BUF_INDEX_SA_LLD_HANDLE] =
+ (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)saEntry->salldHandle);
+ if((NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE) < sizes[nwal_BUF_INDEX_SA_LLD_HANDLE])
+ {
+ /* Resize Memory */
+ return nwal_FALSE;
+ //while(1);
+
+ }
+ count++;
+
+ bases[nwal_BUF_INDEX_SA_CONTEXT] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)netapi_VM_SaContextVaddr);
+ /* also save this here for easy access to sa_start */
+ nwalBaseAddrCfg.pScPoolBaseAddr= bases[nwal_BUF_INDEX_SA_CONTEXT];
+ count++;
+
+ bases[nwal_BUF_INDEX_SA_LLD_CHAN_HANDLE] =
+ (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)saEntry->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 */
+ return nwal_FALSE;
+ //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
+
+ /* Initialize NWAL module */
+ nwal_getLocContextBufferReq(nwalSizeInfo.nProc, &localCtxSize);
+
+ pNwalLocCtxMem = malloc(localCtxSize);
+ nwal_createProc(bases[nwal_BUF_INDEX_INST],
+ pNwalLocCtxMem,
+ &nwalBaseAddrCfg);
+
+ nwalGlobCfg.pBaseAddrCfg = &nwalBaseAddrCfg;
+ nwalRetVal = nwal_create(&nwalGlobCfg,
+ &nwalSizeInfo,
+ sizes,
+ bases,
+ &gPNwalInstHandle);
+ if(nwalRetVal != nwal_OK)
+ {
+ return nwal_FALSE;
+ }
+
+ 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,
+ int master)
+{
+ nwalLocCfg_t nwalLocCfg;
+ nwalBaseAddrCfg_t nwalBaseAddrCfg;
+ int count=0;
+ static int first_time = 0;
+ nwal_RetValue nwalRetVal;
+ void* pBase = NULL;
+ NETAPI_NWAL_SHM_T* nwalEntry = NULL;
+ void* pNwalLocCtxMem = NULL;
+
+ NETAPI_SA_SHM_T* saEntry = NULL;
+ NETAPI_PA_SHM_T* paEntry = NULL;
+
+ uint32_t baseAddr;
+ void* instPoolSaBaseAddr;
+ void* pScPoolBaseAddr;
+ void* pInstPoolPaBaseAddr;
+ void* paVirtBaseAddr;
+ uint32_t localCtxSize;
+
+ memset(&nwalLocCfg,0,sizeof(nwalLocCfg));
+ memset(&nwalBaseAddrCfg, 0, sizeof(nwalBaseAddrCfg_t));
+
+ /* 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 L4 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)
+ {
+ if(master == NETAPI_PROC_MASTER)
+ {
+ pBase = hplib_shmOpen();
+ nwalEntry = (NETAPI_NWAL_SHM_T*)hplib_shmGetEntry(pBase,NWAL_ENTRY);
+
+ baseAddr = (void*) netapi_VM_VirtAddr->passCfgVaddr +
+ CSL_NETCP_CFG_SA_CFG_REGS -
+ CSL_NETCP_CFG_REGS;
+ saEntry = (NETAPI_SA_SHM_T*)hplib_shmGetEntry(pBase,SA_ENTRY);
+ instPoolSaBaseAddr = (void*) saEntry;
+
+ pScPoolBaseAddr = Osal_nwalLocToGlobAddr((uint32_t)netapi_VM_SaContextVaddr);
+
+
+ paVirtBaseAddr = (void*) netapi_VM_VirtAddr->passCfgVaddr;
+ paEntry = (NETAPI_PA_SHM_T*)hplib_shmGetEntry(pBase,PA_ENTRY);
+ pInstPoolPaBaseAddr = (void *)paEntry;
+
+ nwal_getLocContextBufferReq(TUNE_NETAPI_NUM_CORES, &localCtxSize);
+ pNwalLocCtxMem = malloc(localCtxSize);
+ if (pNwalLocCtxMem == NULL)
+ {
+ return -1;
+ }
+ nwalBaseAddrCfg.pSaVirtBaseAddr = baseAddr;
+ nwalBaseAddrCfg.pInstPoolSaBaseAddr = instPoolSaBaseAddr;
+ nwalBaseAddrCfg.pScPoolBaseAddr = pScPoolBaseAddr;
+ nwalBaseAddrCfg.paVirtBaseAddr = paVirtBaseAddr;
+ nwalBaseAddrCfg.pInstPoolPaBaseAddr = pInstPoolPaBaseAddr;
+ /* this is 1 time per process */
+ nwal_createProc(nwalEntry,
+ pNwalLocCtxMem,
+ &nwalBaseAddrCfg);
+ }
+ /* this is for every thread including 1st thread of the process */
+ netapi_proc_master->spinLock.lock(&pnetapiShm->netapi_util_lock);
+ nwalRetVal = nwal_start(gPNwalInstHandle,&nwalLocCfg);
+ netapi_proc_master->spinLock.unlock(&pnetapiShm->netapi_util_lock);
+ if(nwalRetVal == nwal_ERR_INVALID_STATE)
+ {
+ continue;
+ }
+ break;
+ }
+
+ if(nwalRetVal != nwal_OK)
+ {
+ 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();
+#else
+ return 0;
+#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 +
+ pnetapiShm->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. */
+ 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<NQUEUES2CLEAR;i++)
+ {
+ tempQH[i] = Qmss_queueOpen(Qmss_QueueType_GENERAL_PURPOSE_QUEUE,
+ QMSS_PARAM_NOT_SPECIFIED, &isAllocated);
+ netapip_zapQ(tempQH[i]);
+ }
+
+ for(i=0;i<NQUEUES2CLEAR;i++)
+ {
+ Qmss_queueClose(tempQH[i]);
+ }
+}
+
+
+
+/********************************************************************
+* FUNCTION PURPOSE: NETAPI internal function system initialization
+ ********************************************************************
+ * DESCRIPTION: NETAPI internal function system initialization
+ ********************************************************************/
+int netapip_systemInit(NETAPI_HANDLE_T * handle,
+ Bool global_master_process)
+{
+
+ int32_t result;
+ Pktlib_HeapHandle sharedHeapHandle;
+ Pktlib_HeapHandle controlRxHeapHandle,controlTxHeapHandle;
+ Pktlib_HeapCfg heapCfg;
+ int32_t errCode = 0;
+ int count=0;
+
+#ifdef NETAPI_USE_DDR
+ /* Init attributes for DDR */
+ netapi_VM_MempoolAttr[0].attr = HPLIB_ATTR_KM_CACHED0;
+ netapi_VM_MempoolAttr[0].phys_addr = 0;
+ netapi_VM_MempoolAttr[0].size = 0;
+
+#ifdef NETAPI_USE_DDR_AND_MSMC
+ /* Init attributes for un-cached MSMC */
+ netapi_VM_MempoolAttr[1].attr = HPLIB_ATTR_UN_CACHED;
+ netapi_VM_MempoolAttr[1].phys_addr = CSL_MSMC_SRAM_REGS;
+ netapi_VM_MempoolAttr[1].size = TUNE_NETAPI_PERM_MEM_SZ;
+#endif
+#else
+ /* Init attributes for un-cached MSMC */
+ netapi_VM_MempoolAttr[0].attr = HPLIB_ATTR_UN_CACHED;
+ netapi_VM_MempoolAttr[0].phys_addr = CSL_MSMC_SRAM_REGS;
+ netapi_VM_MempoolAttr[0].size = TUNE_NETAPI_PERM_MEM_SZ;
+#ifdef NETAPI_USE_DDR_AND_MSMC
+ netapi_VM_MempoolAttr[1].attr = HPLIB_ATTR_KM_CACHED0;
+ netapi_VM_MempoolAttr[1].phys_addr = 0;
+ netapi_VM_MempoolAttr[1].size = 0;
+#endif
+#endif
+ /* initialize all the memory we are going to use
+ - chunk for buffers, descriptors
+ - memory mapped peripherals we use, such as QMSS, PA, etc */
+#ifdef NETAPI_USE_DDR_AND_MSMC
+ result = hplib_vmInit(&netapi_VM_VirtAddr[0],
+ 2,
+ &netapi_VM_MempoolAttr[0]);
+#else
+ result = hplib_vmInit(&netapi_VM_VirtAddr[0],
+ 1,
+ &netapi_VM_MempoolAttr[0]);
+#endif
+
+ if (result != hplib_OK)
+ {
+ return -1;
+ }
+
+ if (global_master_process == NETAPI_TRUE)
+ {
+ hplib_initMallocArea(0);
+#ifdef NETAPI_USE_DDR_AND_MSMC
+ hplib_initMallocArea(1);
+#endif
+#ifdef NETAPI_ENABLE_SECURITY
+#define SEC_CONTEXT_SZ 384 //not tunable
+ /* allocate 2x number of tunnels since we need one for inflow and one for data mode */
+ netapi_VM_SaContextVaddr = hplib_vmMemAlloc((TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS*2 *
+ SEC_CONTEXT_SZ), 128, 0);
+ if (!netapi_VM_SaContextVaddr)
+ {
+ return (-1);
+ }
+#else
+ netapi_VM_SaContextVaddr= (char *) NULL;
+#endif
+
+ /* (3) Allocate 2 QM regions from continguous chunk above */
+ netapi_VM_QMemGlobalDescRam =
+ (void *)hplib_vmMemAlloc((TUNE_NETAPI_NUM_GLOBAL_DESC *
+ TUNE_NETAPI_DESC_SIZE),
+ 128,
+ 0);
+
+ netapi_VM_QMemLocalDescRam =
+ (void *)hplib_vmMemAlloc((TUNE_NETAPI_NUM_LOCAL_DESC *
+ TUNE_NETAPI_DESC_SIZE),
+ 128,
+ 0);
+ /* Initialize Queue Manager Sub System */
+ result = netapip_initQm (pnetapiShm->netapi_global.cfg.def_max_descriptors,
+ pRmClientHandle);
+
+ if (result != 1)
+ {
+ return -1;
+ }
+ /* Start the QMSS. */
+ if (netapip_startQm(pRmClientHandle) != 1)
+ {
+ return -1;
+ }
+
+ //clean our old junk in 1st bunch of queues that will be allocated to us
+ netapip_cleanupAtStart();
+ /* Initialize the global descriptor memory region. */
+ result= netapip_qmSetupMemRegion(
+ pnetapiShm->netapi_global.cfg.def_tot_descriptors_for_us,
+ TUNE_NETAPI_DESC_SIZE,
+ (unsigned int *) netapi_VM_QMemGlobalDescRam,
+ pnetapiShm->netapi_global.cfg.memoryRegion,
+ pnetapiShm->netapi_global.cfg.start_index);
+ if(result <0)
+ {
+ return -1;
+ }
+ /* Initialize CPPI CPDMA */
+ result = netapip_initCppi(pRmClientHandle);
+ if (result != 1)
+ {
+ return -1;
+ }
+ /* CPPI and Queue Manager are initialized. */
+
+ /* create main pkt heap */
+ /* Initialize the Shared Heaps. */
+ Pktlib_sharedHeapInit();
+ /* Populate the heap interface table. */
+ netapi_pktlib_ifTable.data_malloc = netapip_sharedMemoryMalloc;
+ netapi_pktlib_ifTable.data_free = netapip_sharedMemoryFree;
+ /* Initialize the heap configuration. */
+ memset ((void *)&heapCfg, 0, sizeof(Pktlib_HeapCfg));
+ /* Populate the heap configuration */
+ heapCfg.name = "netapi";
+ heapCfg.memRegion = memInfo.memRegion;
+ heapCfg.sharedHeap = 1;
+ heapCfg.useStarvationQueue = 0;
+ heapCfg.dataBufferSize = pnetapiShm->netapi_global.cfg.def_heap_buf_size;
+ heapCfg.numPkts = pnetapiShm->netapi_global.cfg.def_heap_n_descriptors;
+ heapCfg.numZeroBufferPackets= pnetapiShm->netapi_global.cfg.def_heap_n_zdescriptors;
+ heapCfg.heapInterfaceTable.data_malloc = netapi_pktlib_ifTable.data_malloc;
+ heapCfg.heapInterfaceTable.data_free = netapi_pktlib_ifTable.data_free;
+ heapCfg.dataBufferPktThreshold = 0;
+ heapCfg.zeroBufferPktThreshold = 0;
+
+ /* Create Shared Heap with specified configuration. */
+ sharedHeapHandle = Pktlib_createHeap(&heapCfg, &errCode);
+ if (!sharedHeapHandle) { 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);
+ //todo -> cleanup on failure
+ if (!controlRxHeapHandle) { 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);
+ //todo -> cleanup on failure
+ if (!controlTxHeapHandle) { return -1;}
+ handle->netcp_control_tx_heap= controlTxHeapHandle;
+ /* now NWAL */
+ result = netapip_initNwal(memInfo.memRegion,
+ &netapi_pktlib_ifTable,
+ &pnetapiShm->netapi_global.nwal_context,
+ &pnetapiShm->netapi_global.cfg);
+ if (result<0) { return -1; }
+ /* Common Initialization for all cores */
+ while(count < TUNE_NETAPI_MAX_NUM_TRANS)
+ {
+ netapi_proc_global.nwal_context.transInfos[count].transId = count;
+ count++;
+ }
+ result = netapip_startNwal(sharedHeapHandle,
+ controlRxHeapHandle,
+ controlTxHeapHandle,
+ &handle->nwal_local,
+ &pnetapiShm->netapi_global.cfg,
+ &pnetapiShm->netapi_global.nwal_context,
+ handle->master);
+ if (result<0) { return -1; }
+ }
+ else
+ {
+ if (hplib_checkMallocArea(0) != hplib_OK)
+ return -1;
+ if (hplib_checkMallocArea(1) != hplib_OK)
+ return -1;
+
+#ifdef NETAPI_ENABLE_SECURITY
+ /* allocate 2x number of tunnels since we need one for inflow and one for data mode */
+ netapi_VM_SaContextVaddr = hplib_vmMemAlloc((TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS*2 *
+ SEC_CONTEXT_SZ), 128, 0);
+ if (!netapi_VM_SaContextVaddr)
+ {
+ return (-1);
+ }
+#else
+ netapi_VM_SaContextVaddr= (char *) NULL;
+#endif
+
+
+
+ /* (3) Allocate 2 QM regions from continguous chunk above */
+ netapi_VM_QMemGlobalDescRam =
+ (void *)hplib_vmMemAlloc((TUNE_NETAPI_NUM_GLOBAL_DESC *
+ TUNE_NETAPI_DESC_SIZE),
+ 128,
+ 0);
+
+ netapi_VM_QMemLocalDescRam =
+ (void *)hplib_vmMemAlloc((TUNE_NETAPI_NUM_LOCAL_DESC *
+ TUNE_NETAPI_DESC_SIZE),
+ 128,
+ 0);
+
+ /****************************************************
+ * partial initialization. For process, not for SOC
+ ***************************************************/
+ result = netapip_initQm (pnetapiShm->netapi_global.cfg.def_max_descriptors,
+ pRmClientHandle);
+ if (result != 1)
+ {
+ return -1;
+ }
+
+ /* Start the QMSS. */
+ if (netapip_startQm(pRmClientHandle) != 1)
+ {
+ return -1;
+ }
+
+ result= netapip_qmSetupMemRegion(
+ pnetapiShm->netapi_global.cfg.def_tot_descriptors_for_us,
+ TUNE_NETAPI_DESC_SIZE,
+ (unsigned int *) netapi_VM_QMemGlobalDescRam,
+ pnetapiShm->netapi_global.cfg.memoryRegion,
+ pnetapiShm->netapi_global.cfg.start_index);
+ if(result <0)
+ {
+ return -1;
+ }
+ /* Initialize CPPI CPDMA */
+ result = netapip_initCppi(pRmClientHandle);
+ if (result != 1)
+ {
+ return -1;
+ }
+ /* CPPI and Queue Manager are initialized. */
+
+ /* create main pkt heap for this process */
+ /* Initialize the Shared Heaps. */
+ Pktlib_sharedHeapInit();
+ /* Populate the heap interface table. */
+ netapi_pktlib_ifTable.data_malloc = netapip_sharedMemoryMalloc;
+ netapi_pktlib_ifTable.data_free = netapip_sharedMemoryFree;
+ /* Initialize the heap configuration. */
+ memset ((void *)&heapCfg, 0, sizeof(Pktlib_HeapCfg));
+ /* Populate the heap configuration */
+ heapCfg.name = "netapi";
+ //heapCfg.memRegion = TUNE_NETAPI_QM_GLOBAL_REGION;
+ heapCfg.memRegion = memInfo.memRegion;
+ heapCfg.sharedHeap = 1;
+ heapCfg.useStarvationQueue = 0;
+ heapCfg.dataBufferSize = pnetapiShm->netapi_global.cfg.def_heap_buf_size;
+ heapCfg.numPkts = pnetapiShm->netapi_global.cfg.def_heap_n_descriptors;
+ heapCfg.numZeroBufferPackets= pnetapiShm->netapi_global.cfg.def_heap_n_zdescriptors;
+ heapCfg.heapInterfaceTable.data_malloc = netapi_pktlib_ifTable.data_malloc;
+ heapCfg.heapInterfaceTable.data_free = netapi_pktlib_ifTable.data_free;
+ heapCfg.dataBufferPktThreshold = 0;
+ heapCfg.zeroBufferPktThreshold = 0;
+
+ /* Create Shared Heap with specified configuration. */
+ sharedHeapHandle = Pktlib_createHeap(&heapCfg, &errCode);
+ //todo -> cleanup on failure
+ if (!sharedHeapHandle) { return -1;}
+ handle->netcp_heap= sharedHeapHandle;
+
+ //open shared heap handle but create new controlRx & Tx heaps for this
+ //process
+ /* Update for Control */
+ heapCfg.name = "netapi_control_rx";/*todo:add random#*/
+ 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);
+ if (!controlRxHeapHandle) { 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);
+ if (!controlTxHeapHandle) { return -1;}
+ handle->netcp_control_tx_heap= controlTxHeapHandle;
+
+ /* Common Initialization for all threads in process */
+ while(count < TUNE_NETAPI_MAX_NUM_TRANS)
+ {
+ netapi_proc_global.nwal_context.transInfos[count].transId = count;
+ count++;
+ }
+ result = netapip_startNwal(sharedHeapHandle,
+ controlRxHeapHandle,
+ controlTxHeapHandle,
+ &handle->nwal_local,
+ &pnetapiShm->netapi_global.cfg,
+ &pnetapiShm->netapi_global.nwal_context,
+ handle->master);
+ if (result<0)
+ {
+ return -1;
+ }
+ }
+
+ //get timer running
+#ifdef CORTEX_A8
+ netapip_initTimer();
+#endif
+
+
+
+ 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)
+{
+ int i;
+ if (!queueNum)
+ {
+ return;
+ }
+ for (i=0;;i+=1 )
+ {
+ /* Pop descriptor from source queue */
+ if (pktio_mQmssQueuePopRaw(queueNum) == NULL)
+ {
+ break;
+ }
+ }
+}
+
+
+/****************************************************************************
+* 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);
+ printf("PA2SA(ingress) stats> #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets,
+ pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage);
+ printf(" > #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n",
+ pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter,
+ pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter);
+ Pktlib_getHeapStats(netapi_get_global()->nwal_context.sa2pa_heap,&pktLibHeapStats);
+ printf("SA2PA stats> #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets,
+ pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage);
+ printf(" > #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n",
+ pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter,
+ pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter);
+
+}
+