index 2639f12561035ace6e49ce46be844f03f1375c55..21cd90c2309902b9c3b15e9d1ca9d2ca53ff6c3c 100755 (executable)
-/*******************************
+/***********************************************************************
* FILE: netapi.c
- * Purpose: implementation of netapi startup/shutdown
- **************************************************************
+ * Purpose: Main initialization and shutdown routines of NETAPI
+ * user space transport library.
+ ***********************************************************************
* FILE: netapi.c
*
* DESCRIPTION: netapi main source file for user space transport
* library
*
- * REVISION HISTORY: rev 0.0.1
+ * REVISION HISTORY:
*
- * Copyright (c) Texas Instruments Incorporated 2010-2011
+ * 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
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *****************************/
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include "netapi.h"
-
-typedef struct PRESET_Tag
-{
-#define KMAXQ 10
- int kqinuse[KMAXQ];
- //more..
-} PRESET_T;
-
-/*------------internal prototypes---------------*/
-static uint8_t* netapiSharedMemoryMalloc(uint32_t size);
-static void netapiSharedMemoryFree(uint8_t* ptr, uint32_t size);
-static int system_init(NETAPI_HANDLE_T *);
-static void get_presets(PRESET_T * p_preset);
-static void netapi_cleanup_at_start(void);
-
-/*------------globals-----------------*/
-#define NUM_HOST_DESC (TUNE_NETAPI_NUM_LOCAL_DESC)
-#define SIZE_LOCAL_DESC (TUNE_NETAPI_DESC_SIZE)
-#define SIZE_SHARED_DESC (TUNE_NETAPI_DESC_SIZE)
-
-#define CONFIG_BUFSIZE_PA_INST 256
-#define CONFIG_BUFSIZE_L2_TABLE 1000
-#define CONFIG_BUFSIZE_L3_TABLE 4000
+#include <unistd.h>
+#include "ti/runtime/netapi/netapi.h"
+#include "netapi_loc.h"
static NETAPI_CFG_T netapi_default_cfg=
{
-TUNE_NETAPI_PERM_MEM_SZ,
-0, //start of packet offset for hw to place data on rx for default flow
-TUNE_NETAPI_QM_CONFIG_MAX_DESC_NUM, //max number of descriptors in system
-TUNE_NETAPI_NUM_GLOBAL_DESC, //total we will use
-TUNE_NETAPI_DEFAULT_NUM_BUFFERS, //#descriptors+buffers in default heap
-TUNE_NETAPI_DEFAULT_NUM_SOLO_DESCRIPTORS, //#descriptors w/o buffers in default heap
-TUNE_NETAPI_DEFAULT_BUFFER_SIZE, //size of buffers in default heap
-0,0
+ TUNE_NETAPI_PERM_MEM_SZ,
+ 0, //start of packet offset for hw to place data on rx for default flow
+ TUNE_NETAPI_QM_CONFIG_MAX_DESC_NUM, //max number of descriptors in system
+ TUNE_NETAPI_NUM_GLOBAL_DESC, //total we will use
+ TUNE_NETAPI_DEFAULT_NUM_BUFFERS, //#descriptors+buffers in default heap
+ TUNE_NETAPI_DEFAULT_NUM_SOLO_DESCRIPTORS, //#descriptors w/o buffers in default heap
+ TUNE_NETAPI_DEFAULT_BUFFER_SIZE, //size of buffers in default heap
+ 0,0
};
/* Global variablesto hold virtual address of various subsystems */
hplib_virtualAddrInfo_T netapi_VM_VirtAddr[HPLIB_MAX_MEM_POOLS];
+
/* Global variables which needs to be populated with memory pool attributes
- which is passed to HPLIB for memory pool initialization*/
+ which is passed to HPLIB for memory pool initialization*/
hplib_memPoolAttr_T netapi_VM_MempoolAttr[HPLIB_MAX_MEM_POOLS];
unsigned char *netapi_VM_QMemLocalDescRam;
unsigned char *netapi_VM_QMemGlobalDescRam;
unsigned char *netapi_VM_SaContextVaddr;
-static Pktlib_HeapIfTable netapi_pktlib_ifTable;
-static NETAPI_GLOBAL_T netapi_global;
+Pktlib_HeapIfTable netapi_pktlib_ifTable;
+NETAPI_GLOBAL_T netapi_global;
NETAPI_GLOBAL_T * netapi_get_global(){ return &netapi_global;}
/* utility API for NETAPI user to get pktlib if table to use if he creates his own heap */
Pktlib_HeapIfTable *netapi_getPktlibIfTable(void) {return &netapi_pktlib_ifTable;}
-//zap a queue
-void netapi_zapQ(int queueNum);
-/*-------------------------------------
- * initialize NETAPI instance
- *-------------------------------------*/
+
+/********************************************************************
+* FUNCTION PURPOSE: API instantiates the NETAPI and allocated global resources.
+ ********************************************************************
+ * DESCRIPTION: API instantiates the NETAPI and allocated global resources.
+ ********************************************************************/
NETAPI_T netapi_init(int master, NETAPI_CFG_T * p_cfg)
{
- int i;
- int err;
- 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;
-
- /* create space for our local pktios */
- for(i=0;i<NETAPI_MAX_PKTIO; i++)
- {
- p->pktios[i] = calloc(1,sizeof(PKTIO_HANDLE_T));
- if (!p->pktios[i]) return NULL;
- }
+ int i;
+ int err;
+ int exception_id = 7;
+ 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;
+
+ /* create space for our local pktios */
+ for(i=0;i<TUNE_NETAPI_MAX_PKTIO; i++)
+ {
+ p->pktios[i] = calloc(1,sizeof(PKTIO_HANDLE_T));
+ if (!p->pktios[i])
+ {
+ return NULL;
+ }
+ }
#ifdef NETAPI_INCLUDE_SCHED
- /* create space for scheduler */
- p->p_sched = calloc(1,sizeof(NETAPI_SCHED_HANDLE_T));
-#endif
-
+ /* create space for scheduler */
+ p->p_sched = calloc(1,sizeof(NETAPI_SCHED_HANDLE_T));
+ if (!p->p_sched)
+ {
+ goto ERR_netapi_init;
+ }
+#endif
- /* global stuff (if master) */
- if (master==NETAPI_SYS_MASTER)
- {
- if (p_cfg) memcpy(&netapi_global.cfg,p_cfg, sizeof(NETAPI_CFG_T));
- else memcpy(&netapi_global.cfg,&netapi_default_cfg, sizeof(NETAPI_CFG_T));
- for(i=0;i<NETAPI_MAX_PKTIO;i++)
- {
- netapi_global.pktios[i].qn.qNum=-1;
- netapi_global.pktios[i].name[0]='\0';
- }
- }
- //this goes to shared memory eventually
- p->global = (void *) &netapi_global;
+ /* Global init for SYS_MATER */
+ if (master==NETAPI_SYS_MASTER)
+ {
+ if (p_cfg)
+ {
+ memcpy(&netapi_global.cfg,p_cfg, sizeof(NETAPI_CFG_T));
+ }
+ else
+ {
+ memcpy(&netapi_global.cfg,&netapi_default_cfg, sizeof(NETAPI_CFG_T));
+ }
+ for(i=0;i<TUNE_NETAPI_MAX_PKTIO;i++)
+ {
+ netapi_global.pktios[i].qn.qNum=-1;
+ netapi_global.pktios[i].name[0]='\0';
+ }
+ }
+ //this goes to shared memory eventually
+ p->global = (void *) &netapi_global;
- //dalmt: save master's handle back in global; else for slave retrieve p_master
- if (master==NETAPI_SYS_MASTER)
- {
- netapi_global.p_master = p;
- }
- else
- {
- p_master=(NETAPI_HANDLE_T *)netapi_global.p_master;
- }
+ //save master's handle back in global; else for slave retrieve p_master
+ if (master==NETAPI_SYS_MASTER)
+ {
+ netapi_global.p_master = p;
+ }
+ else
+ {
+ /* get system master reqquired for core and no master */
+ p_master=(NETAPI_HANDLE_T *)netapi_global.p_master;
+ }
- /* system init */
- if(master==NETAPI_SYS_MASTER)
- {
- err = system_init(p);
- if (err<0)
- {
- //todo: cleanup
- return NULL;
- }
- /* create pktio channels for tx,rx */
- }
- else if (master==NETAPI_NO_MASTER)
- {
- //dalmt ->simple trial. Just copy master's packetio list for now
+ /* system init */
+ if(master==NETAPI_SYS_MASTER)
+ {
+ err = netapip_systemInit(p);
+ netapi_netcpCfgExceptions(p, NETCP_CFG_ALL_EXCEPTIONS, NETCP_CFG_ACTION_TO_SW, (NETCP_CFG_ROUTE_HANDLE_T) NULL);
+ if (err<0)
+ {
+ goto ERR_netapi_init;
+ }
+ /* create pktio channels for tx,rx */
+ }
+ else if (master==NETAPI_NO_MASTER)
+ {
+ //dalmt ->simple trial. Just copy master's packetio list for now
p->n_pktios = p_master->n_pktios;
- memcpy(&p->pktios[0],&p_master->pktios[0],NETAPI_MAX_PKTIO*sizeof(PKTIO_HANDLE_T));
+ memcpy(&p->pktios[0],&p_master->pktios[0],TUNE_NETAPI_MAX_PKTIO*sizeof(PKTIO_HANDLE_T));
p->nwal_local=p_master->nwal_local;
- }
- else
- {
- /*todo init for non-system cores/threads */
- /* qm_start, */
- /* attach to heaps */
- /* nwal_start */
- }
-
- return (NETAPI_T) p;
-}
-
-/*-------------------------------
- * Shut down netapi instance
- *-------------------------------*/
-void netapi_shutdown(NETAPI_T h)
-{
- int i;
- NETAPI_HANDLE_T * p = (NETAPI_HANDLE_T *) h;
- if (!p) return;
+ }
+ /* this is the NETAPI_CORE_MASTER case */
+ else if (master==NETAPI_CORE_MASTER)
+ {
- printf(">netapi: WARNING shutdown may not be fully implemented\n");
- if (p->master)
+ /* Start the QMSS. */
+ if (netapip_startQm() != 1)
{
- /* close nwal */
- nwal_delete(netapi_global.nwal_context.nwalInstHandle);
-
- /* close heaps */
- netapi_closeHeap(h, p->netcp_heap);
- netapi_closeHeap(h, p->netcp_control_rx_heap);
- netapi_closeHeap(h, p->netcp_control_tx_heap);
- netapi_closeHeap(h, netapi_get_global()->nwal_context.pa2sa_heap);
- netapi_closeHeap(h, netapi_get_global()->nwal_context.sa2pa_heap);
-
- //loop over registered heaps
- for(i=0;i<TUNE_NETAPI_MAX_HEAPS;i++)
- {
- if (p->createdHeaps[i]) {netapi_closeHeap(h,p->createdHeaps[i]);p->createdHeaps[i]=NULL;}
- }
- netapi_cleanup_at_start(); //clear 1st 50 not-specified queues..
- hplib_vmTeardown();
- }
- free(p);
- return;
-}
-
-//exception crash
-void netapi_err_teardown() { netapi_cleanup_at_start(); exit(-99); }
-
-/*-------------------utilities-------------------*/
-static uint8_t* netapiSharedMemoryMalloc(uint32_t size)
-{
-return (uint8_t *)hplib_vmMemAlloc(size +netapi_global.cfg.def_heap_extra_size , 128, 0);
-}
-
-static void netapiSharedMemoryFree(uint8_t* ptr, uint32_t size)
-{
- /* Do Nothing. */
- printf(">netapi Unexpected. need to provide a free () for some reason!! \n");
- return;
-}
-
-// initialization
-static int system_init(NETAPI_HANDLE_T * handle)
-{
- int32_t result;
- Pktlib_HeapHandle sharedHeapHandle;
- Pktlib_HeapHandle controlRxHeapHandle,controlTxHeapHandle;
- Pktlib_HeapCfg heapCfg;
- int32_t errCode;
-
- /* 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;
-
- /* 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;
- /* initialize all the memory we are going to use
- - chunk for buffers, descriptors
- - memory mapped peripherals we use, such as QMSS, PA, etc */
- result = hplib_vmInit(&netapi_VM_VirtAddr[0], 2, &netapi_VM_MempoolAttr[0]);
- /* TODO: at this point, we need to create the QM regions which need to moved out of the above
- netapi_VM_memory_setup() call, also need to move out the SA context stuff */
-
- if (result == hplib_OK) printf(">netapi: system init - memory set up OK\n");
- else {printf(">netap: system init - memory set up failed\n"); return -1;}
-
-
-#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)
+ goto ERR_netapi_init;
+ }
+ netapip_startNwal(p_master->netcp_heap,
+ p_master->netcp_control_rx_heap,
+ p_master->netcp_control_tx_heap,
+ &p->nwal_local,
+ &netapi_global.cfg,
+ &netapi_global.nwal_context);
+ }
+ else
{
- printf(">netapi ERROR: Failed to map SA context memory region\n");
- return (-1);
+ netapi_Log("netapi_init: no master specified\n");
+ goto ERR_netapi_init;
}
- printf(">hplib VM_SaContext: Memory mapped/allocated at address %p.\n", netapi_VM_SaContextVaddr);
-
-#else
- netapi_VM_SaContextVaddr= (char *) NULL;
-#endif
-/* TODO: the QM regions is application specific and needs to be moved since number of regions created is appliction specific, put this in system_init */
- /* (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);
+ return (NETAPI_T) p;
- netapi_VM_QMemLocalDescRam =
- (void *)hplib_vmMemAlloc((TUNE_NETAPI_NUM_LOCAL_DESC *
- TUNE_NETAPI_DESC_SIZE),
- 128, 0);
- printf(">netapi local desc region=%x global desc region=%x\n", netapi_VM_QMemLocalDescRam, netapi_VM_QMemGlobalDescRam);
-
- //get timer running
- netapi_init_timer();
-
- /* Initialize Queue Manager Sub System */
- result = netapi_init_qm (netapi_global.cfg.def_max_descriptors);
- if (result != 1)
+ERR_netapi_init:
+ for(i=0;i<TUNE_NETAPI_MAX_PKTIO; i++)
{
- return -1;
+ if (p->pktios[i])
+ {
+ free(p->pktios[i]);
+ }
}
-
- /* Start the QMSS. */
- if (netapi_start_qm() != 1)
+#ifdef NETAPI_INCLUDE_SCHED
+ if (p->p_sched)
{
- return -1;
+ free(p->p_sched);
}
-
- //clean our old junk in 1st bunch of queues that will be allocated to us
- netapi_cleanup_at_start();
-
- /* Initialize the global descriptor memory region. */
- result= netapi_qm_setup_mem_region(
- netapi_global.cfg.def_tot_descriptors_for_us,
- SIZE_SHARED_DESC,
- (unsigned int *) netapi_VM_QMemGlobalDescRam,
- NETAPI_GLOBAL_REGION);
- if(result <0) {printf(">netapi; can't setup QM shared region\n"); return -1;}
-
-#if 0 //todo setup 2nd region
-/* Initialize the local memory region configuration. */
- result= netapi_qm_setup_mem_region(
- NUM_HOST_DESC,
- SIZE_LOCAL_DESC,
- netapi_VM_QMemLocalDescRam,
- NETAPI_LOCAL_REGION);
- if(result <0) {printf("can't setup local region\n"); return -1;}
#endif
- /* Initialize CPPI CPDMA */
-
- result = netapi_init_cppi ();
- if (result != 1)
- {
- printf (">netapi: Error initializing CPPI SubSystem error code : %d\n",result);
- return -1;
- }
-
- /* CPPI and Queue Manager are initialized. */
- printf (">netapi: Queue Manager and CPPI are initialized.\n");
-
- /* create main pkt heap */
- /* Initialize the Shared Heaps. */
- Pktlib_sharedHeapInit();
-
- /* Populate the heap interface table. */
- netapi_pktlib_ifTable.data_malloc = netapiSharedMemoryMalloc;
- netapi_pktlib_ifTable.data_free = netapiSharedMemoryFree;
-
- /* Initialize the heap configuration. */
- memset ((void *)&heapCfg, 0, sizeof(Pktlib_HeapCfg));
- /* Populate the heap configuration */
- heapCfg.name = "netapi";
- heapCfg.memRegion = NETAPI_GLOBAL_REGION;
- heapCfg.sharedHeap = 1;
- heapCfg.useStarvationQueue = 0;
- heapCfg.dataBufferSize = netapi_global.cfg.def_heap_buf_size;
- heapCfg.numPkts = netapi_global.cfg.def_heap_n_descriptors;
- heapCfg.numZeroBufferPackets= 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) { printf(">'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);
- //todo -> cleanup on failure
- if (!controlRxHeapHandle) { printf(">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);
- //todo -> cleanup on failure
- if (!controlTxHeapHandle) { printf(">netapi -'netapi_control_tx' heap create failed, Error Code: %d\n",errCode); return -1;}
- handle->netcp_control_tx_heap= controlTxHeapHandle;
-
- /* now NWAL */
- result = netapi_init_nwal(
- NETAPI_GLOBAL_REGION,
- &netapi_pktlib_ifTable,
- &netapi_global.nwal_context,
- &netapi_global.cfg);
- if (result<0) {printf(">netapi init_nwal() failed\n"); return -1; }
-
- /* start NWAL */
- result = netapi_start_nwal(sharedHeapHandle,
- controlRxHeapHandle,
- controlTxHeapHandle,
- &handle->nwal_local,
- &netapi_global.cfg,
- &netapi_global.nwal_context);
- if (result<0) {printf(">netapi start_nwal() failed\n"); return -1; }
- //** success **
-
-
- return 0;
-
-}
-
-
-/*---------------
- * get presets()
- *---------------*/
-static void get_presets(PRESET_T * p_preset)
-{
- /* read from kernel or overall config area */
- /* for now hard code what kernel did */
+ return NULL;
}
-
-/*************************************************************
- ******************MISC INTERNAL******************************
-**************************************************************/
-/* poll the garbage queues of all registered heaps */
-void netapi_pollHeapGarbage(NETAPI_T h)
-{
-int i;
- NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) h;
- Pktlib_garbageCollection(n->netcp_heap);
- //no need to do garbage collection on other internal heaps
- for(i=0;i<TUNE_NETAPI_MAX_HEAPS;i++)
- {
- if (n->createdHeaps[i]) Pktlib_garbageCollection(n->createdHeaps[i]);
- }
-}
-
-/* poll NETCP control queue for responses */
-void netapi_netcpPoll(NETAPI_T p)
+/********************************************************************
+* FUNCTION PURPOSE: API de-allocates all global resources allocated as part
+* of ref netapi_init
+ ********************************************************************
+ * DESCRIPTION: API de-allocates all global resources allocated as part
+* of ref netapi_init
+ ********************************************************************/
+void netapi_shutdown(NETAPI_T h)
{
- NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) p;
- nwal_pollCtl( ((NETAPI_GLOBAL_T *) (n->global))->nwal_context.nwalInstHandle,NULL,NULL);
-}
+ int i;
+ NETAPI_HANDLE_T * p = (NETAPI_HANDLE_T *) h;
+ if (!p) return;
-/****************************************************************
- *****************Cleanup Functions******************************
-*****************************************************************/
-
-//clean up function for linux user space
-void netapi_zapQ(int queueNum)
-{
-char * descPtr;
-int i;
-if (!queueNum) return;
-for (i=0;;i+=1 )
+ netapi_Log("netapi: WARNING shutdown may not be fully implemented\n");
+ if (p->master ==NETAPI_SYS_MASTER)
+ {
+ /* close nwal */
+ nwal_delete(netapi_global.nwal_context.nwalInstHandle);
+
+ /* close heaps */
+ netapi_closeHeap(h, p->netcp_heap);
+ netapi_closeHeap(h, p->netcp_control_rx_heap);
+ netapi_closeHeap(h, p->netcp_control_tx_heap);
+ 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,
+ NETCP_CFG_ALL_EXCEPTIONS,
+ NETCP_CFG_ACTION_DISCARD,
+ (NETCP_CFG_ROUTE_HANDLE_T) NULL);
+ //loop over registered heaps
+ for(i=0;i<TUNE_NETAPI_MAX_HEAPS;i++)
{
- /* Pop descriptor from source queue */
- if ((descPtr = (char *)PKTIO_QMSS_QUEUE_POP_RAW (queueNum)) == NULL)
- {
- break;
- }
- else {/*printf("netapi qzap in play\n");*/}
+ if (p->createdHeaps[i]) {netapi_closeHeap(h,p->createdHeaps[i]);p->createdHeaps[i]=NULL;}
}
- if(i) printf(">netapi: @recovery - %d descriptors cleaned from qn %d\n",i, queueNum);
-}
-
-//defensive: clean out stuff hanging around
-//
-// open a bunch of free queues and zap them
-#define NQUEUES2CLEAR 35
-static Qmss_QueueHnd tempQH[NQUEUES2CLEAR];
-static void netapi_cleanup_at_start(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);
- netapi_zapQ(tempQH[i]);
-}
-
-for(i=0;i<NQUEUES2CLEAR;i++)
-{
- Qmss_queueClose(tempQH[i]);
-}
-
-}
-
-/********************************
- * clean up a pktlib heap
- ***********************************/
-int netapi_closeHeap(NETAPI_T h, Pktlib_HeapHandle p)
-{
-Qmss_QueueHnd q;
-Pktlib_garbageCollection(p);
-q = Pktlib_getZeroHeapQueue(p);
-netapi_zapQ(q);
-q= Pktlib_getInternalHeapQueue(p);
-netapi_zapQ(q);
+ netapip_cleanupAtStart(); //clear 1st 50 not-specified queues..
+ hplib_vmTeardown();
+ }
+ free(p);
+ return;
}
-
-
-
-
-netapi_getBufMemRemainder(void)
+/***********************************************************************
+* FUNCTION PURPOSE: API is used to poll for NETCP configuration response messages.
+************************************************************************
+* DESCRIPTION: This API is used to poll the netapi internal heaps and any
+ * application-created heaps that have been registered with
+ * the netapi instance. The poll function checks the garbage collection
+ * queue associated with the heap and returns descriptors and buffers
+ * when appropriate to the main free queue.
+***********************************************************************/
+void netapi_pollHeapGarbage(NETAPI_T h)
{
- hplib_vmGetBufMemRemainder(0);
+ int i;
+ NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) h;
+ Pktlib_garbageCollection(n->netcp_heap);
+ //no need to do garbage collection on other internal heaps
+ for(i=0;i<TUNE_NETAPI_MAX_HEAPS;i++)
+ {
+ if (n->createdHeaps[i])
+ {
+ Pktlib_garbageCollection(n->createdHeaps[i]);
+ }
+ }
}
-
-
-void netapi_dump_internal_heap_stats(void)
+/****************************************************************************
+* FUNCTION PURPOSE: API is used to poll for NETCP configuration response messages.
+****************************************************************************
+* DESCRIPTION: This API is used to poll the netapi internal heaps and any
+ * application-created heaps that have been registered with the
+ * netapi instance. The poll function checks the garbage collection
+ * queue associated with the heap and returns descriptors and buffers
+ * when appropriate to the main free queue.
+***************************************************************************/
+void netapi_netcpPoll(NETAPI_T p)
{
-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);
-#if 0
-Pktlib_getHeapStats(netapi_get_global()->nwal_context.pa2saTX_heap,&pktLibHeapStats);
-printf("PA2SA(egress) 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);
-#endif
-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);
-
+ NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) p;
+ nwal_pollCtl( ((NETAPI_GLOBAL_T *) (n->global))->nwal_context.nwalInstHandle,NULL,NULL);
}
-
-
-
-
-
-