From 37e99201cd4c90d296d41c70618a011bf5ecdf43 Mon Sep 17 00:00:00 2001 From: Tinku Mannan Date: Wed, 17 Jul 2013 16:58:43 -0400 Subject: [PATCH] This commit adds the following: 1. NETAPI changes to support multiproc PA/SA. 2. NETAPI integration with HPLIB shared memory API's 3. New to query per channel SA/PA handles. --- .../ipsecmgr/src/netapilib_interface.c | 21 +++--- ti/runtime/netapi/netapi.h | 12 +-- ti/runtime/netapi/netapi_sec.h | 23 ++++++ ti/runtime/netapi/netapi_util.h | 16 ++-- ti/runtime/netapi/src/netapi.c | 74 ++++++++++++++++++- ti/runtime/netapi/src/netapi_init.c | 66 +++++++++++++---- ti/runtime/netapi/src/netapi_loc.h | 9 +++ ti/runtime/netapi/src/netapi_sec.c | 63 +++++++++++++++- ti/runtime/netapi/src/netcp_cfg.c | 45 +++++------ ti/runtime/netapi/src/pktio.c | 20 ++--- 10 files changed, 265 insertions(+), 84 deletions(-) diff --git a/ti/runtime/netapi/applications/ipsec_offload/ipsecmgr/src/netapilib_interface.c b/ti/runtime/netapi/applications/ipsec_offload/ipsecmgr/src/netapilib_interface.c index 2ecc3de..7ade54d 100755 --- a/ti/runtime/netapi/applications/ipsec_offload/ipsecmgr/src/netapilib_interface.c +++ b/ti/runtime/netapi/applications/ipsec_offload/ipsecmgr/src/netapilib_interface.c @@ -312,7 +312,7 @@ int netapilib_ifAddSA *sa_handle = globalDB.tx_sa[slot].saAppId; printf("netapilib_ifAddSA: using slot: %d\n", slot); #if 0 - netapi_secGetPaHandle(netapi_handle, + netapi_secGetChanHandles(netapi_handle, saAppIdOut, NULL, &pSaHandle); @@ -421,8 +421,9 @@ int32_t netapilib_ifAddSP NETCP_CFG_SA_T sa =(NETCP_CFG_SA_T)sa_handle; NETCP_CFG_ROUTE_T route; NETCP_CFG_FLOW_T flow; - NETCP_CFG_PA_HANDLE_T* pPaHandle; - NETCP_CFG_SA_HANDLE_T* pSaHandle; + NETCP_CFG_PA_HANDLE_T pPaHandleOuterIP; + NETCP_CFG_PA_HANDLE_T pPaHandleInnerIP; + NETCP_CFG_SA_HANDLE_T pSaHandle; ipsecmgr_syslog_msg (SYSLOG_LEVEL_INFO,"netapilib_ifAddSP: called\n"); @@ -474,12 +475,6 @@ int32_t netapilib_ifAddSP return -1; } -#if 0 - ip_qualifiers.flowLabel = 1; - ip_qualifiers.proto = 1; - ip_qualifiers.tos = 1; - ip_qualifiers.validParams = 1; -#endif globalDB.rx_sa[slot].spAppId = netapi_secAddRxPolicy(netapi_handle, (NETCP_CFG_SA_T) sa_handle, ipType, @@ -505,10 +500,12 @@ int32_t netapilib_ifAddSP "netapilib_ifAddSA: Translation of SP successful, app_id: 0x%x\n", *sp_handle); #if 0 - netapi_secGetPaHandle(netapi_handle, + netapi_secGetChanHandles(netapi_handle, (NETCP_CFG_SA_T)sa_handle, - pPaHandle, - pSaHandle); + globalDB.rx_sa[slot].spAppId, + &pPaHandleOuterIP, + &pPaHandleInnerIP, + &pSaHandle); #endif #endif return 0; diff --git a/ti/runtime/netapi/netapi.h b/ti/runtime/netapi/netapi.h index 7cfe3cb..b68513d 100755 --- a/ti/runtime/netapi/netapi.h +++ b/ti/runtime/netapi/netapi.h @@ -83,18 +83,8 @@ #include #include #include -#include "ti/runtime/hplib/hplib.h" - -#if 0 -#include "ti/runtime/netapi/netapi_types.h" -#include "ti/runtime/netapi/netapi_tune.h" -#include "ti/runtime/netapi/pktio.h" -#include "ti/runtime/netapi/netcp_cfg.h" -#include "ti/runtime/netapi/netapi_sec.h" -#include "ti/runtime/netapi/netapi_sched.h" -#include "ti/runtime/netapi/netapi_util.h" -#endif +#include "ti/runtime/hplib/hplib.h" #include "netapi_types.h" #include "netapi_tune.h" #include "pktio.h" diff --git a/ti/runtime/netapi/netapi_sec.h b/ti/runtime/netapi/netapi_sec.h index 8dab9d8..0c7557c 100755 --- a/ti/runtime/netapi/netapi_sec.h +++ b/ti/runtime/netapi/netapi_sec.h @@ -241,4 +241,27 @@ void netapi_getSaStats (NETAPI_T h, NETCP_CFG_SA_T handle, NETAPI_SA_STATS_T* pSaStats); + + +/** + * @ingroup cfg_security_functions + * @brief netapi_secGetChanHandles API to get PA handle for security context + * + * @details API to get PA handle for security context + * @param[in] h The NETAPI handle, @ref NETAPI_T + * @param[in] sa_app_id Application id returned from call to @ref netapi_secAddSA + * @param[in] policy_app_id Application id returned from call to @ref netapi_secAddPolicy + * @param[out] pPaHandleOuterIP Pointer to PA LLD handle for outer IP + * @param[out] pPaHandleInnerIP Pointer to PA LLD handle for inner IP + * @param[out] pSaHandle Pointer to SA LLD + * @retval none + * @pre @ref netapi_init, @ref netapi_secAddSA +*/ +void netapi_secGetChanHandles(NETAPI_T h, + NETCP_CFG_SA_T sa_app_id, + NETCP_CFG_IPSEC_POLICY_T policy_app_id, + NETCP_CFG_PA_HANDLE_T* pPaHandleOuterIP, + NETCP_CFG_PA_HANDLE_T* pPaHandleInnerIP, + NETCP_CFG_SA_HANDLE_T* pSaHandle); + #endif diff --git a/ti/runtime/netapi/netapi_util.h b/ti/runtime/netapi/netapi_util.h index 1d1a1f1..4dfac74 100755 --- a/ti/runtime/netapi/netapi_util.h +++ b/ti/runtime/netapi/netapi_util.h @@ -44,7 +44,6 @@ #define __NETAPI_UTIL__H #include -//#include "ti/runtime/netapi/src/netapi_loc.h" #include "./src/netapi_loc.h" @@ -55,13 +54,14 @@ #define netapi_Log #endif +extern NETAPI_SHM_T* pnetapiShm; /* Wrapper functions around HPLIB APIs for QMSS , *utility to convert virt2phy, phy2virt */ #define _Osal_qmssVirtToPhy hplib_mVMVirtToPhy #define _Osal_qmssPhyToVirt hplib_mVMPhyToVirt -static hplib_spinLock_T netapi_lock = hplib_spinLock_UNLOCKED_INITIALIZER; +//static hplib_spinLock_T netapi_util_lock = hplib_spinLock_UNLOCKED_INITIALIZER; /** * @ingroup netapi_gen_functions @@ -81,17 +81,17 @@ static inline int netapi_registerHeap(NETAPI_T p, { NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p; int i; - hplib_mSpinLockLock(&netapi_lock); + hplib_mSpinLockLock(&pnetapiShm->netapi_util_lock); for(i=0;icreatedHeaps[i]) { pp->createdHeaps[i]=h; - hplib_mSpinLockUnlock(&netapi_lock); + hplib_mSpinLockUnlock(&pnetapiShm->netapi_util_lock); return 1; } } - hplib_mSpinLockUnlock(&netapi_lock); + hplib_mSpinLockUnlock(&pnetapiShm->netapi_util_lock); return -1; } @@ -113,17 +113,17 @@ static inline int netapi_unregisterHeap(NETAPI_T p, { NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p; int i; - hplib_mSpinLockLock(&netapi_lock); + hplib_mSpinLockLock(&pnetapiShm->netapi_util_lock); for(i=0;icreatedHeaps[i] == h) { pp->createdHeaps[i]=NULL; - hplib_mSpinLockUnlock(&netapi_lock); + hplib_mSpinLockUnlock(&pnetapiShm->netapi_util_lock); return 1; } } - hplib_mSpinLockUnlock(&netapi_lock); + hplib_mSpinLockUnlock(&pnetapiShm->netapi_util_lock); return -1; } diff --git a/ti/runtime/netapi/src/netapi.c b/ti/runtime/netapi/src/netapi.c index 21cd90c..fb583e5 100755 --- a/ti/runtime/netapi/src/netapi.c +++ b/ti/runtime/netapi/src/netapi.c @@ -46,6 +46,8 @@ #include "ti/runtime/netapi/netapi.h" #include "netapi_loc.h" +void* pBase; +NETAPI_SHM_T* pnetapiShm; static NETAPI_CFG_T netapi_default_cfg= { TUNE_NETAPI_PERM_MEM_SZ, @@ -83,14 +85,51 @@ Pktlib_HeapIfTable *netapi_getPktlibIfTable(void) {return &netapi_pktlib_ifTable ********************************************************************/ NETAPI_T netapi_init(int master, NETAPI_CFG_T * p_cfg) { + static int first_time = HPLIB_TRUE; int i; int err; int exception_id = 7; + void* pBase = NULL; + + hplib_shmInfo_T* pshmBase = NULL; NETAPI_HANDLE_T * p = (NETAPI_HANDLE_T *) calloc(1,sizeof(NETAPI_HANDLE_T)); NETAPI_HANDLE_T * p_master; if (!p) return NULL; p->master = master; + if (master == NETAPI_SYS_MASTER) + { + pBase = hplib_shmCreate(HPLIB_SHM_SIZE); + + //pshmBase = (hplib_shmInfo_T*)hplib_shmOpen(); + if (pBase == NULL) + { + printf("netapi_init: hplib_shmCreate failure\n"); + return NULL; + } + else + printf("netapi_init: hplib_shmCreate sucess\n"); + +#if 0 + pBase = hplib_shmOpen(); + if(pBase == NULL) + { + printf("netapi_init: shared memory handle is NULL\n"); + return NULL; + } +#endif + if (hplib_shmAddEntry(pBase, sizeof(NETAPI_SHM_T), NETAPI_ENTRY) != + hplib_OK) + { + printf("netapi_init: hplib_shmAddEntry failed for NETAPI_ENTRY\n"); + return NULL; + } + else + { + printf("netapi_init: hplib_shmAddEntry sucess for NETAPI_ENTRY\n"); + } + } + /* create space for our local pktios */ for(i=0;inetapi_pktio_lock= hplib_spinLock_UNLOCKED_INITIALIZER; + pnetapiShm->netapi_netcp_cfg_lock = hplib_spinLock_UNLOCKED_INITIALIZER; + pnetapiShm->netapi_util_lock = hplib_spinLock_UNLOCKED_INITIALIZER; if (p_cfg) { memcpy(&netapi_global.cfg,p_cfg, sizeof(NETAPI_CFG_T)); @@ -154,7 +198,7 @@ NETAPI_T netapi_init(int master, NETAPI_CFG_T * p_cfg) } else if (master==NETAPI_NO_MASTER) { - //dalmt ->simple trial. Just copy master's packetio list for now + /*Just copy master's packetio list for now */ p->n_pktios = p_master->n_pktios; memcpy(&p->pktios[0],&p_master->pktios[0],TUNE_NETAPI_MAX_PKTIO*sizeof(PKTIO_HANDLE_T)); p->nwal_local=p_master->nwal_local; @@ -210,8 +254,11 @@ ERR_netapi_init: void netapi_shutdown(NETAPI_T h) { int i; + hplib_shmInfo_T* pshmBase; NETAPI_HANDLE_T * p = (NETAPI_HANDLE_T *) h; if (!p) return; + void * map_base; + hplib_VirtMemPoolheader_T *poolHdr; netapi_Log("netapi: WARNING shutdown may not be fully implemented\n"); if (p->master ==NETAPI_SYS_MASTER) @@ -226,8 +273,8 @@ void netapi_shutdown(NETAPI_T h) netapi_closeHeap(h, netapi_get_global()->nwal_context.pa2sa_heap); netapi_closeHeap(h, netapi_get_global()->nwal_context.sa2pa_heap); - /* Un-configure rules for execption packet handling */ - netapi_netcpCfgExceptions(p, + /* Un-configure rules for execption packet handling */ + netapi_netcpCfgExceptions(p, NETCP_CFG_ALL_EXCEPTIONS, NETCP_CFG_ACTION_DISCARD, (NETCP_CFG_ROUTE_HANDLE_T) NULL); @@ -236,8 +283,27 @@ void netapi_shutdown(NETAPI_T h) { if (p->createdHeaps[i]) {netapi_closeHeap(h,p->createdHeaps[i]);p->createdHeaps[i]=NULL;} } - netapip_cleanupAtStart(); //clear 1st 50 not-specified queues.. + netapip_cleanupAtStart(); //clear 1st 50 not-specified queues + +#if 0 + hplib_mod_fd = hplib_utilModOpen(); + if (hplib_mod_fd == -1) + { + netapi_Log("netapi_shutdown:: failed to open /dev/netapi: '%s'\n", + strerror(errno)); + return; + } +#endif + map_base = (void *) hplib_utilGetVaOfBufferArea(HPLIBMOD_MMAP_DMA_MEM_OFFSET, 0); + if (map_base) + { + poolHdr = (hplib_VirtMemPoolheader_T*)map_base; + poolHdr->ref_count = 0; + poolHdr->virtMemAllocOffset = 0; + } hplib_vmTeardown(); + printf("netapi_shutdown: calling hplib_shmDelete\n"); + hplib_shmDelete(); } free(p); return; diff --git a/ti/runtime/netapi/src/netapi_init.c b/ti/runtime/netapi/src/netapi_init.c index 69934e7..ed223f5 100755 --- a/ti/runtime/netapi/src/netapi_init.c +++ b/ti/runtime/netapi/src/netapi_init.c @@ -71,7 +71,7 @@ #include #include - +extern NETAPI_SHM_T* pnetapiShm; /* Global variablesto hold virtual address of various subsystems */ extern hplib_virtualAddrInfo_T netapi_VM_VirtAddr[]; @@ -198,6 +198,9 @@ uint8_t nwalInstMem[NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_HANDLE]ALIGN(CACHE_LINESZ); uint8_t nwalHandleMem[NWAL_CHAN_HANDLE_SIZE]ALIGN(CACHE_LINESZ); + +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 128 /* PA instance */ @@ -212,21 +215,19 @@ uint8_t paBuf1[NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF1]ALIGN(CACHE_LINESZ); 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); -#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); - +} NETAPI_SA_SHM_T; /******************************************************************** * FUNCTION PURPOSE: NETAPI internal function to gracefully cleanup when startup @@ -245,7 +246,7 @@ void netapipErrTeardown() { netapip_cleanupAtStart(); exit(-99); } int netapip_initNwal( int region2use, Pktlib_HeapIfTable * p_table, - NETAPI_NWAL_GLOBAL_CONTEXT_T * p_nwal_context, + NETAPI_NWAL_GLOBAL_CONTEXT_T * p_nwal_context, NETAPI_CFG_T*p_cfg ) { nwalSizeInfo_t nwalSizeInfo; @@ -257,11 +258,39 @@ int netapip_initNwal( void* bases[nwal_N_BUFS]; Pktlib_HeapCfg heapCfg; int32_t errCode; + void* pBase = NULL; + NETAPI_PA_SHM_T* paEntry = NULL; + NETAPI_SA_SHM_T* saEntry = NULL; memset(p_nwal_context,0,sizeof( NETAPI_NWAL_GLOBAL_CONTEXT_T) ); memset(&nwalGlobCfg,0,sizeof(nwalGlobCfg_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); + nwalGlobCfg.instPoolBaseAddr = (void *)paEntry; + printf("netapip_initNwal: instPoolBaseAddr: 0x%x\n", nwalGlobCfg.instPoolBaseAddr); + } + else + { + netapi_Log("netapip_initNwal: Unable to Add shared memory segment for PASS\n"); + return -1; + } + if(hplib_shmAddEntry(pBase, sizeof(NETAPI_SA_SHM_T), SA_ENTRY) == hplib_OK) + { + saEntry = (NETAPI_PA_SHM_T*)hplib_shmGetEntry(pBase,SA_ENTRY); + nwalGlobCfg.instPoolSaBaseAddr = (void*) saEntry; + } + else + { + netapi_Log("netapip_initNwal: Unable to Add shared memory segment for SASS\n"); + return -1; + } + + } /* Initialize Buffer Pool for NetCP PA to SA packets */ nwalGlobCfg.pa2SaBufPool.numBufPools = 1; nwalGlobCfg.pa2SaBufPool.bufPool[0].descSize = TUNE_NETAPI_DESC_SIZE; @@ -359,7 +388,8 @@ int netapip_initNwal( while(1); } count++; - bases[nwal_BUF_INDEX_PA_LLD_BUF0] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)paBuf0); + 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 */ @@ -367,7 +397,8 @@ int netapip_initNwal( } count++; - bases[nwal_BUF_INDEX_PA_LLD_BUF1] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)paBuf1); + 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 */ @@ -375,7 +406,8 @@ int netapip_initNwal( } count++; - bases[nwal_BUF_INDEX_PA_LLD_BUF2] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)paBuf2); + 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 */ @@ -383,7 +415,8 @@ int netapip_initNwal( } count++; #ifdef NETAPI_ENABLE_SECURITY - bases[nwal_BUF_INDEX_SA_LLD_HANDLE] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)salldHandle); + 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 */ @@ -392,9 +425,12 @@ int netapip_initNwal( 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 */ + nwalGlobCfg.instPoolSaBaseAddr = bases[nwal_BUF_INDEX_SA_CONTEXT]; count++; - bases[nwal_BUF_INDEX_SA_LLD_CHAN_HANDLE] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)salldChanHandle); + 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]) { diff --git a/ti/runtime/netapi/src/netapi_loc.h b/ti/runtime/netapi/src/netapi_loc.h index 7f8577f..635d422 100755 --- a/ti/runtime/netapi/src/netapi_loc.h +++ b/ti/runtime/netapi/src/netapi_loc.h @@ -7,6 +7,7 @@ #define __NETAPI_LOC__H #include "ti/drv/nwal/nwal_util.h" +#include "ti/runtime/netapi/pktio.h" #include "ti/drv/nwal/nwal.h" #include "ti/drv/nwal/nwal_util.h" @@ -215,6 +216,14 @@ typedef struct NETAPI_HANDLE_Tag void* cookie; /*set by calling thread */ } NETAPI_HANDLE_T; +typedef struct NETAPI_SHM_Tag +{ + NETAPI_GLOBAL_T netapi_global; + hplib_spinLock_T netapi_pktio_lock; + hplib_spinLock_T netapi_netcp_cfg_lock; + hplib_spinLock_T netapi_util_lock; +} NETAPI_SHM_T; + //internal initialization routines */ int netapip_initQm(int max_descriptors); int netapip_initCppi(void); diff --git a/ti/runtime/netapi/src/netapi_sec.c b/ti/runtime/netapi/src/netapi_sec.c index 5ba018e..437de2a 100755 --- a/ti/runtime/netapi/src/netapi_sec.c +++ b/ti/runtime/netapi/src/netapi_sec.c @@ -516,7 +516,7 @@ NETCP_CFG_IPSEC_POLICY_T netapi_secAddRxPolicy(NETAPI_T h, netapip_freeTransInfo(pTransInfo); return -1; } - appId |= (policyId<<8); + appId |= (policyId <<8); /* fire off config message */ retValue = nwal_setSecPolicy (((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle, @@ -527,6 +527,7 @@ NETCP_CFG_IPSEC_POLICY_T netapi_secAddRxPolicy(NETAPI_T h, if(retValue != nwal_OK) { *perr = NETAPI_ERR_NWAL_ERR0; + printf("netapi_secAddPolicy: error returned: %d\n", retValue); netapi_Log ("netapi sec - ERROR: nwal_setPolicy returned Error Code %d\n", retValue); netapip_freeTransInfo(pTransInfo); @@ -672,7 +673,7 @@ void netapi_getSaStats (NETAPI_T h, NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) h; void * handle_inflow; void * handle_sideband; - int tunnelId = (handle >> NETAPI_NETCP_MATCH_ID_SHIFT) & NETAPI_NETCP_MATCH_ID_MASK; + int tunnelId = (handle >> NETAPI_NETCP_MATCH_ID_SHIFT) &0xffff; int have_to_wait = 1; handle_inflow = netapip_netcpCfgGetSaHandles(&netapi_get_global()->nwal_context, tunnelId, &handle_sideband); @@ -689,3 +690,61 @@ void netapi_getSaStats (NETAPI_T h, pSaStats->validParams |= NETAPI_SIDEBAND_DATA_MODE_STAT_VALID; } } + + +/********************************************************************************** + * FUNCTION PURPOSE: API to retrieve SA and PA channel handles for security context if already configured + ********************************************************************************** + * DESCRIPTION: API to retrieve SA and PA channel handles for security context if already configured + *********************************************************************************/ +void netapi_secGetChanHandles(NETAPI_T h, + NETCP_CFG_SA_T sa_app_id, + NETCP_CFG_IPSEC_POLICY_T policy_app_id, + NETCP_CFG_PA_HANDLE_T* pPaHandleOuterIP, + NETCP_CFG_PA_HANDLE_T* pPaHandleInnerIP, + NETCP_CFG_SA_HANDLE_T* pSaHandle) +{ + NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) h; + void * handle_inflow; + void * handle_sideband = NULL; + void * handle_policy=NULL; + + int tunnelId = netapi_cfgGetMatchId(sa_app_id); + int policyId = netapi_cfgGetMatchId(policy_app_id); + + handle_inflow = netapip_netcpCfgGetSaHandles(&netapi_get_global()->nwal_context, + tunnelId, &handle_sideband); + + if(handle_inflow) + { + handle_policy = netapip_netcpCfgGetPolicy(&netapi_get_global()->nwal_context,policyId); + + nwal_secGetChanHandles(((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle, + handle_inflow, + handle_policy, + pPaHandleOuterIP, + pPaHandleInnerIP, + pSaHandle); + if (pPaHandleOuterIP) + printf("netapi_secGetChanHandles: *pa_handle outer IP: 0x%x\n", + (paHandleL2L3_t)*pPaHandleOuterIP); + + if (pPaHandleInnerIP) + printf("netapi_secGetChanHandles: *pa_handle inner IP: 0x%x\n", + (paHandleL2L3_t)*pPaHandleInnerIP); + + if (pSaHandle) + printf("netapi_secGetChanHandles: *sa_handle: 0x%x\n", + (Sa_ChanHandle)*pSaHandle); + } + else + { + if (pPaHandleOuterIP) + *pPaHandleOuterIP = NULL; + if (pPaHandleInnerIP) + *pPaHandleInnerIP = NULL; + if (pSaHandle) + *pSaHandle = NULL; + } + return; +} diff --git a/ti/runtime/netapi/src/netcp_cfg.c b/ti/runtime/netapi/src/netcp_cfg.c index befdb96..eaab5c2 100755 --- a/ti/runtime/netapi/src/netcp_cfg.c +++ b/ti/runtime/netapi/src/netcp_cfg.c @@ -43,11 +43,12 @@ #include "netapi.h" +extern NETAPI_SHM_T* pnetapiShm; /****************************************************************** ********************Netapi internal************************************* *******************************************************************/ -static hplib_spinLock_T netapi_netcp_cfg_lock = hplib_spinLock_UNLOCKED_INITIALIZER; + /******************************************************************** * FUNCTION PURPOSE: Netapi internal function to get a free transaction id @@ -60,19 +61,19 @@ NetapiNwalTransInfo_t * netapip_getFreeTransInfo(NETAPI_GLOBAL_T *p_global, uint16_t count=0; count=0; - hplib_mSpinLockLock(&netapi_netcp_cfg_lock); + hplib_mSpinLockLock(&pnetapiShm->netapi_netcp_cfg_lock); while(count < TUNE_NETAPI_MAX_NUM_TRANS) { if((p_global->nwal_context.transInfos[count].inUse) != nwal_TRUE) { p_global->nwal_context.transInfos[count].inUse = nwal_TRUE; *pTransId = count; - hplib_mSpinLockUnlock(&netapi_netcp_cfg_lock); + hplib_mSpinLockUnlock(&pnetapiShm->netapi_netcp_cfg_lock); return(&p_global->nwal_context.transInfos[count]); } count++; } - hplib_mSpinLockUnlock(&netapi_netcp_cfg_lock); + hplib_mSpinLockUnlock(&pnetapiShm->netapi_netcp_cfg_lock); /* trouble. need to wait for one to free up*/ /* to do: handle this by forcing a poll of cntrl queue*/ netapi_Log(">netcp_cfg: trying to get free transaction slot but all full!!\n"); @@ -126,7 +127,7 @@ int netapip_netcpCfgFindPolicySlot(NETAPI_NWAL_GLOBAL_CONTEXT_T *p, if ((tunnel <0 ) || (tunnel >=TUNE_NETAPI_MAX_SA)) return -1; - hplib_mSpinLockLock(&netapi_netcp_cfg_lock); + hplib_mSpinLockLock(&pnetapiShm->netapi_netcp_cfg_lock); //find a free entry for(i=0;ipolicy[i].in_use = 2; //pending p->policy[i].tunnel= tunnel; //save tunnel this is linked to - hplib_mSpinLockUnlock(&netapi_netcp_cfg_lock); + hplib_mSpinLockUnlock(&pnetapiShm->netapi_netcp_cfg_lock); return i; } } - hplib_mSpinLockUnlock(&netapi_netcp_cfg_lock); + hplib_mSpinLockUnlock(&pnetapiShm->netapi_netcp_cfg_lock); return -1; } @@ -202,7 +203,7 @@ int netapip_netcpCfgFindSaSlot(NETAPI_NWAL_GLOBAL_CONTEXT_T *p, { if ((iface <0 ) || (iface >=TUNE_NETAPI_MAX_NUM_MAC)) return -1; } - hplib_mSpinLockLock(&netapi_netcp_cfg_lock); + hplib_mSpinLockLock(&pnetapiShm->netapi_netcp_cfg_lock); //find a free entry for(i=0;itunnel[i].in_use = 2; //pending p->tunnel[i].iface= iface; //save iface - hplib_mSpinLockUnlock(&netapi_netcp_cfg_lock); + hplib_mSpinLockUnlock(&pnetapiShm->netapi_netcp_cfg_lock); return i; } } - hplib_mSpinLockUnlock(&netapi_netcp_cfg_lock); + hplib_mSpinLockUnlock(&pnetapiShm->netapi_netcp_cfg_lock); return -1; } @@ -338,17 +339,17 @@ static int netapip_netcpCfgFindFlowSlot( NETAPI_NWAL_GLOBAL_CONTEXT_T *p) { int i; //find a free entry - hplib_mSpinLockLock(&netapi_netcp_cfg_lock); + hplib_mSpinLockLock(&pnetapiShm->netapi_netcp_cfg_lock); for(i=0;iflows[i].in_use) { p->flows[i].in_use = 2; /* pending */ - hplib_mSpinLockUnlock(&netapi_netcp_cfg_lock); + hplib_mSpinLockUnlock(&pnetapiShm->netapi_netcp_cfg_lock); return i; } } - hplib_mSpinLockUnlock(&netapi_netcp_cfg_lock); + hplib_mSpinLockUnlock(&pnetapiShm->netapi_netcp_cfg_lock); return -1; } @@ -396,7 +397,7 @@ static int netapip_netcpCfgFindFlow(NETAPI_NWAL_GLOBAL_CONTEXT_T *p, { int i; *handle=NULL; - hplib_mSpinLockLock(&netapi_netcp_cfg_lock); + hplib_mSpinLockLock(&pnetapiShm->netapi_netcp_cfg_lock); for(i=0;iflows[i].in_use)&& @@ -404,11 +405,11 @@ static int netapip_netcpCfgFindFlow(NETAPI_NWAL_GLOBAL_CONTEXT_T *p, (p->flows[i].flow.dma_engine == dma_engine)) { *handle = p->flows[i].handle; - hplib_mSpinLockUnlock(&netapi_netcp_cfg_lock); + hplib_mSpinLockUnlock(&pnetapiShm->netapi_netcp_cfg_lock); return i; } } - hplib_mSpinLockUnlock(&netapi_netcp_cfg_lock); + hplib_mSpinLockUnlock(&pnetapiShm->netapi_netcp_cfg_lock); return -1; } @@ -427,17 +428,17 @@ static int netapip_netcpCfgFindIpSlot(NETAPI_NWAL_GLOBAL_CONTEXT_T *p, int i; //find a free entry - hplib_mSpinLockLock(&netapi_netcp_cfg_lock); + hplib_mSpinLockLock(&pnetapiShm->netapi_netcp_cfg_lock); for(i=0;iips[i].in_use) { p->ips[i].in_use = 2; //pending - hplib_mSpinLockUnlock(&netapi_netcp_cfg_lock); + hplib_mSpinLockUnlock(&pnetapiShm->netapi_netcp_cfg_lock); return i; } } - hplib_mSpinLockUnlock(&netapi_netcp_cfg_lock); + hplib_mSpinLockUnlock(&pnetapiShm->netapi_netcp_cfg_lock); return -1; } @@ -579,17 +580,17 @@ static void netapip_netcpCfgDeleteMac(NETAPI_NWAL_GLOBAL_CONTEXT_T *p, static int netapip_netcpCfgFindClassSlot( NETAPI_NWAL_GLOBAL_CONTEXT_T *p) { int i; - hplib_mSpinLockLock(&netapi_netcp_cfg_lock); + hplib_mSpinLockLock(&pnetapiShm->netapi_netcp_cfg_lock); for(i=0;iclassi[i].in_use) { p->classi[i].in_use = 2; //pending - hplib_mSpinLockUnlock(&netapi_netcp_cfg_lock); + hplib_mSpinLockUnlock(&pnetapiShm->netapi_netcp_cfg_lock); return i; } } - hplib_mSpinLockUnlock(&netapi_netcp_cfg_lock); + hplib_mSpinLockUnlock(&pnetapiShm->netapi_netcp_cfg_lock); return -1; } /******************************************************************************* diff --git a/ti/runtime/netapi/src/pktio.c b/ti/runtime/netapi/src/pktio.c index ea558ae..12ee1b6 100755 --- a/ti/runtime/netapi/src/pktio.c +++ b/ti/runtime/netapi/src/pktio.c @@ -51,7 +51,7 @@ /*This defines the maximum number of packets to receive in one pktio poll */ #define PKTIO_MAX_RECV (TUNE_NETAPI_MAX_BURST_RCV) -static hplib_spinLock_T netapi_pktio_lock = hplib_spinLock_UNLOCKED_INITIALIZER; +extern NETAPI_SHM_T* pnetapiShm; /* Utilites*/ @@ -59,17 +59,17 @@ static PKTIO_HANDLE_T * netapip_pktioGetFreeChannelSlot(NETAPI_T n) { PKTIO_HANDLE_T ** pp = (PKTIO_HANDLE_T **) netapi_get_pktio_list(n); int i; - hplib_mSpinLockLock(&netapi_pktio_lock); + hplib_mSpinLockLock(&pnetapiShm->netapi_pktio_lock); for(i=0;iinuse != PKTIO_INUSE) { pp[i]->inuse = PKTIO_INUSE; - hplib_mSpinLockUnlock(&netapi_pktio_lock); + hplib_mSpinLockUnlock(&pnetapiShm->netapi_pktio_lock); return pp[i]; } } - hplib_mSpinLockUnlock(&netapi_pktio_lock); + hplib_mSpinLockUnlock(&pnetapiShm->netapi_pktio_lock); return NULL; } @@ -718,9 +718,9 @@ PKTIO_HANDLE_T * netapi_pktioCreate(NETAPI_T n, (p_cfg->flags1 & PKTIO_GLOBAL)) { //todo: make sure this succeeds.. - hplib_mSpinLockLock(&netapi_pktio_lock); + hplib_mSpinLockLock(&pnetapiShm->netapi_pktio_lock); r=netapip_addGlobalPktio(n, name, &p->qInfo); - hplib_mSpinLockUnlock(&netapi_pktio_lock); + hplib_mSpinLockUnlock(&pnetapiShm->netapi_pktio_lock); } ((NETAPI_HANDLE_T *)n )->n_pktios+=1; @@ -792,7 +792,7 @@ PKTIO_HANDLE_T * netapi_pktioOpen(NETAPI_T n, } else { - hplib_mSpinLockLock(&netapi_pktio_lock); + hplib_mSpinLockLock(&pnetapiShm->netapi_pktio_lock); /* Find queue in global list Note names like "QUEUE:%d" or IFDMA:%d cause general purpose or IFDMA queues of that number to be opened */ @@ -801,7 +801,7 @@ PKTIO_HANDLE_T * netapi_pktioOpen(NETAPI_T n, qtype= Qmss_QueueType_INFRASTRUCTURE_QUEUE; } - hplib_mSpinLockUnlock(&netapi_pktio_lock); + hplib_mSpinLockUnlock(&pnetapiShm->netapi_pktio_lock); p_qnum = netapip_findGlobalPktio(n, name); if (!p_qnum ) @@ -1000,9 +1000,9 @@ void netapi_pktioDelete(PKTIO_HANDLE_T * p, } /* remove from name list */ - hplib_mSpinLockLock(&netapi_pktio_lock); + hplib_mSpinLockLock(&pnetapiShm->netapi_pktio_lock); netapi_del_global_pktio((NETAPI_HANDLE_T *)p->back, p->name); - hplib_mSpinLockUnlock(&netapi_pktio_lock); + hplib_mSpinLockUnlock(&pnetapiShm->netapi_pktio_lock); if((p->use_nwal != PKTIO_DEF_NWAL) && (p->use_nwal != PKTIO_DEF_SB)) { netapip_zapQ(p->q); //since we are deleting, zap the queue -- 2.39.2