author | Raghu Nambiath <rnambiath@ti.com> | |
Fri, 15 Jun 2012 21:53:42 +0000 (17:53 -0400) | ||
committer | Raghu Nambiath <rnambiath@ti.com> | |
Fri, 15 Jun 2012 21:53:42 +0000 (17:53 -0400) |
Conflicts:
ti/runtime/netapi/src/netapi.c
ti/runtime/netapi/src/netapi_init.c
ti/runtime/netapi/src/netapi.c
ti/runtime/netapi/src/netapi_init.c
1 | 2 | |||
---|---|---|---|---|
ti/runtime/netapi/netapi.h | patch | | diff1 | | diff2 | | blob | history |
ti/runtime/netapi/netcp_cfg.h | patch | | diff1 | | diff2 | | blob | history |
ti/runtime/netapi/pktio.h | patch | | diff1 | | diff2 | | blob | history |
ti/runtime/netapi/src/netapi.c | patch | | diff1 | | diff2 | | blob | history |
ti/runtime/netapi/src/netapi_init.c | patch | | diff1 | | diff2 | | blob | history |
ti/runtime/netapi/src/netapi_vm.c | patch | | diff1 | | diff2 | | blob | history |
ti/runtime/netapi/test/net_test.c | patch | | diff1 | | diff2 | | blob | history |
diff --combined ti/runtime/netapi/netapi.h
index 82a5d254e8cc8869e51edf9ed284f30050be51de,8a95dfdf648c8a0e702c35164dd50d49fc7800b7..b0fe2c0afd3a4c887ce908ea9b4f48233c53552c
-/**************************************************************\r
- * FILE PURPOSE : -----------NETAPI-------------\r
- * user space access to transport resources on SOC\r
- **************************************************************\r
- * @file netapi.h\r
- * \r
- * @brief DESCRIPTION: netapi main header file for user space transport\r
- * library\r
- * \r
- * REVISION HISTORY: rev 0.0.1 \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
-/** @mainpage Network API \r
- *\r
- * @section intro Introduction\r
- *\r
- * The network API provides a user space interface to TI SOC transport \r
- * Resources. The library includes:\r
- * - general startup and setup for user space operations\r
- * - memory heap and packet buffer management\r
- * - pktio either to/from network or internal queues\r
- * - timers for network stacks\r
- * - netcp (network co-processor) configuration and control\r
- * - utilities including user space synchronization primitivies\r
- * - sample scheduling event loop\r
- *\r
- * NETAPI allows user space transport to configure control the NETCP:\r
- * - Classification of packets based on L2: MAC header fields\r
- * - Classification of packets based on L3: IP header fields\r
- * - Routing of packets to host based on L4 UDP or L5 GTPU ID\r
- * - Unidirectional IPSec SA creation and deletion\r
- * - Unidirectional IPSec Security Policy creation and deletion\r
- *\r
- * \par\r
- * NOTE:\r
- * (C) Copyright 2010-2011 Texas Instruments, Inc.\r
- * \par\r
- */\r
-\r
-/* Define NETAPI as a master group in Doxygen format and add all NETAPI \r
- definitions to this group. */\r
-/** @defgroup netapi USERSPACE TRANSPORT NETAPI\r
- * @{\r
- */\r
-/** @} */\r
-\r
-\r
-#ifndef __NETAPI__H\r
-#define __NETAPI__H\r
-#include <stdint.h>\r
-#include <stdlib.h>\r
-#include <stddef.h>\r
-#include <string.h>\r
-\r
-/**\r
- * @brief This is the NWAL LLD Version. Versions numbers are encoded in the following \r
- * format:\r
- * 0xAABBCCDD -> Arch (AA); API Changes (BB); Major (CC); Minor (DD)\r
- */\r
-#define NETAPI_VERSION_ID (0x01000002)\r
-\r
-/**\r
- * @brief This is the version string which describes the NWAL LLD along with the\r
- * date and build information.\r
- */\r
-#define NETAPI_VERSION_STR "NETAPI Revision: 01.00.00.02"\r
-\r
-\r
-/**\r
- * @defgroup netapi_structures NETAPI data structures\r
- */\r
-/** @ingroup netapi */\r
-\r
-/** @defgroup netapi_api_functions NETAPI API's\r
- * @ingroup netapi_api_functions\r
- */\r
-\r
-/** @ingroup netapi_structures */\r
-/**\r
- * @def NETAPI_T\r
- * @brief netapi handle: one per thread\r
- * used in most NETAPI calls\r
- */\r
-typedef void * NETAPI_T;\r
-\r
-\r
-#define NETAPI_SYS_MASTER 2 //master for system\r
-#define NETAPI_CORE_MASTER 1 //master for core\r
-#define NETAPI_NO_MASTER 0 //data only\r
-\r
-/***********************************************\r
-*************RUN TIME CONTROLS*****************\r
-***********************************************/\r
-typedef struct NETAPI_CFG_Tag\r
-{\r
- int def_mem_size; //bytes of CMA memory we have allocated \r
- int def_flow_pkt_rx_offset; //offset in pkt buffer for hw to start RX\r
- int def_max_descriptors; //# of descriptors in system (must be power of 2), 2^14 max\r
- int def_tot_descriptors_for_us; //#of descriptors to create in our region (must be power of 2)\r
- int def_heap_n_descriptors; //# descriptors+buffers in default heap\r
- int def_heap_n_zdescriptors; //# zero len descriptors in defaule heap\r
- int def_heap_buf_size; //size of buffers in default heap\r
- //=MAX amount of area for packet data\r
- int def_heap_tailroom_size; //size of tailroom in reserve \r
- int def_heap_extra_size; //size of extra space at end of buffer\r
-}NETAPI_CFG_T;\r
-/* note:\r
- each buffer will be allocated: def_heap_buf_size+def_heap_extra_size bytes\r
- each descriptor attached to these buffers will have original_pkt_len of:\r
- def_heap_buf_size.\r
- for default RX flow, for rx packet, the bufptr will be def_flow_pkt_rx_offset.\r
- for detault RX flow, threshold (ie max # of bytes in buffer) will be:\r
- def_heap_buf_size - def_heap_tailroom_size-def_flow_pkt_rx_offset\r
-*/\r
-\r
-\r
-\r
-#include "netapi_err.h"\r
-#include "netapi_tune.h"\r
-#include "ti/runtime/pktlib/pktlib_osal.h"\r
-#include "ti/runtime/pktlib/pktlib.h"\r
-#include "pktio.h"\r
-#include "ti/drv/pa/pa.h"\r
-#include "netcp_cfg.h"\r
-#include "netapi_sec.h"\r
-#include "netapi_sched.h"\r
-#include "src/netapi_vm.h"\r
-#include "src/netapi_util.h"\r
-#include "netsync.h"\r
-#include "ti/drv/nwal/nwal.h"\r
-#include "netapi_timer.h"\r
-#include "src/netapi_loc.h"\r
-\r
-/************************************************\r
- **********BUILD TIME CONTROLS *****************\r
- ***********************************************/\r
-/* see netapi_tune.h */\r
-\r
-\r
-/*************************************\r
- **************NETAPI****************\r
- ************************************/\r
-\r
-/** @ingroup netapi_api_functions */\r
-\r
-/*\r
-* @brief API instantiates the NETAPI and allocated global resources and is pre-requisite \r
- *\r
- * @details Allocates global resources valid per system level common across all ARM cores \r
- * or per thread based on "master" argument.\r
- * Intializes the following substems:\r
- * - pktio\r
- * - pktlib\r
- * - qmss\r
- * - cppi\r
- * - nwal\r
- * @param[in] master mode: NETAPI_SYS_MASTER or NETAPI_NO_MASTER\r
- * @param[in] configuration (master mode). pointer to NETAPI_CFG_T above or NULL\r
- * @retval @ref NETAPI_T: handle to the instance or NULL on error \r
- * @pre none \r
- */\r
-NETAPI_T netapi_init(int master, NETAPI_CFG_T * p_cfg);\r
-\r
-\r
-/** @ingroup netapi_api_functions */\r
-/*\r
-* @brief API shutdowns a previously intialized NETAPI instance \r
- *\r
- * @details de-llocates global resources valid per system level common across all ARM cores \r
- * or per thread based on "master" argument passed in at init time.\r
- * @param[in] @ref NETAPI_T: handle to the instance \r
- * @retval none \r
- * @pre @ref netapi_init \r
- */\r
-void netapi_shutdown(NETAPI_T p);\r
-\r
-/** @ingroup netapi_api_functions */\r
-/*\r
-\r
-* @brief API returns a @ref Pktlib_HeapIfTable to use when creating pktlib heaps \r
- *\r
- * @details Application will need a heapIfTable in order to create its own heaps. This\r
- * function returns a table that can be passed in the call to @ref Pktlib_CreateHeap\r
-* The memory used for these heaps is special: \r
- * - specific alignment, \r
- * - must be contguous, \r
- * - must have a physical to virtual mapping that\r
- * - is known by NETAPI. \r
- * Thus it must be completely managed by NETAPI. This interfaced table provides a\r
- * malloc function that the pktlib heap library uses to allocate data for the heap\r
- * buffers.\r
- * @param[in] none \r
- * @retval @ref Pktlib_HeapIfTable pointer \r
- * @pre @ref netapi_init \r
- */\r
-Pktlib_HeapIfTable *netapi_getPktlibIfTable(void) ;\r
-\r
-/** utilities to see how much mem/descriptor space is remaining **/\r
-\r
-/** @ingroup netapi_api_functions */\r
-/*\r
-* @brief API is used to return the amount of free memory available for allocating buffers\r
- ( for additonal Pktlib heaps. \r
- * @details the applicaiton can use this API to determine how much free memory is .\r
- * available for heap buffers if it decides to create its own. \r
- * @param[in] void \r
- * @retval int : amount of memory available for heap buffer storage (in bytes)\r
- * @pre @ref netapi_init \r
- */\r
-int netapi_getBufMemRemainder(void);\r
-/** @ingroup netapi_api_functions */\r
-\r
-/*\r
-* @brief API is used to return the amount of free memory available for allocating Descriptors \r
- ( for additonal Pktlib heaps. \r
- * @details the applicaiton can use this API to determine how much free memory is .\r
- * available for heap descriptors if it decides to create its own heap. \r
- * @param[in] void \r
- * @retval int : amount of memory available for heap descriptor storage (in bytes)\r
- * @pre @ref netapi_init \r
- */\r
-int netapi_getDescRemainder(void);\r
-\r
-/* utility to get default flow */\r
-/** @ingroup netapi_api_functions */\r
-/*\r
-* @brief API is used to return the default NETCP flow that is to be used for received \r
- ( packets..\r
- * @details the applicaiton can use this API to return the default NETCP flow that is used \r
- * for received packets. A NETCP flow is a list of PacketLib Heaps that are to be\r
- * used to supply free packets to the receive DMA function.\r
- * @param[in] @ref NETAPI_T handle to NETAPI instance \r
- * @retval NETCP_CFG_FLOW_HANDLE_T : handle to default flow\r
- * @pre @ref netapi_init \r
- */\r
-static inline NETCP_CFG_FLOW_HANDLE_T netapi_getDefaultFlow(NETAPI_T p) {\r
-return NETCP_DEFAULT_FLOW;\r
-}\r
-\r
-/* utility to get default route */\r
-/** @ingroup netapi_api_functions */\r
-/*\r
-* @brief API is used to return the default NETCP route\r
- *\r
- * @details this functions returns the default NETCP route created by @ref netapi_init. \r
- * A netcp route consists of a NETCP flow plus a destination pktio channel \r
- * @param[in] @ref NETAPI_T handle to NETAPI instance \r
- * @retval NETCP_CFG_ROUTE_HANDLE_T: the handle of the default route. \r
- * @pre @ref netapi_init \r
- */\r
-static inline NETCP_CFG_ROUTE_HANDLE_T netapi_getDefaultRoute(NETAPI_T p) {\r
-return NETCP_DEFAULT_ROUTE;\r
-}\r
-\r
-/* utility to set/get a cookie in the netapi handle */\r
-/** @ingroup netapi_api_functions */\r
-/*\r
-* @brief API is used to return a piece of application-provided opaque data that has been \r
- ( stored in the netapi instance.\r
- * @details the applicaiton can save a pointer to opaque data in the @ref NETAPI_T instance.\r
- * This APi lets this data be returned to the application.\r
- * @param[in] @ref NETAPI_T handle to NETAPI instance \r
- * @retval void * \r
- * @pre @ref netapi_init @ref netapi_setCookie\r
- */\r
-static inline void * netapi_getCookie(NETAPI_T p)\r
-{\r
-NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;\r
-return pp->cookie;\r
-}\r
-\r
-/** @ingroup netapi_api_functions */\r
-/*\r
-* @brief API is used to set a piece of application-provided opaque data in the\r
- ( netapi instance.\r
- * @details the applicaiton can save a pointer to opaque data in the @ref NETAPI_T instance.\r
- * This APi can be returned later to the application via @ref netapi_getCookie\r
- * @param[in] @ref NETAPI_T : handle to NETAPI instance \r
- * @param[in] void * : opaque data to be saved\r
- * @retval void \r
- * @pre @ref netapi_init \r
- */\r
-static inline void netapi_setCookie(NETAPI_T p, void * cookie)\r
-{\r
-NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;\r
-pp->cookie= cookie;\r
-}\r
-\r
-\r
-/** @ingroup netapi_api_functions */\r
-/*\r
-* @brief API is used to poll for NETCP configuration response messages. \r
- *\r
- * @details Application, if controlling the scheduler, will need to call this\r
- * function periodically to check for NETCP configuration responses (eg\r
- * statistics requests). \r
- * @param[in] @ref NETAPI_T handle to NETAPI instance \r
- * @retval none \r
- * @pre @ref netapi_init \r
- */\r
-void netapi_netcpPoll(NETAPI_T p);\r
-\r
-//heap registration for polling purposes\r
-\r
-/** @ingroup netapi_api_functions */\r
-/*\r
-* @brief API is used to register a heap that is created by application so that\r
- * it's garbage queue can be polled automatically by @ref netapi_poll_heapGarbage(). \r
- *\r
- * @details this function registers an application-created heap with the netapi instance\r
- * so that it can add that heap's garbage queue to the garbage poll function. \r
- * NOTE: netapi internal heap is automatically registered\r
- * @param[in] @ref NETAPI_T handle to NETAPI instance\r
- * @param[in] @ref Pktlib_HeapHandle: handle of heap to register\r
- * @retval int : 1 if OK, <0 on error \r
- * @pre @ref netapi_init @ref Pktlib_CreateHeap\r
- */\r
-static inline int netapi_registerHeap(NETAPI_T p, Pktlib_HeapHandle h)\r
-{\r
-NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;\r
-int i;\r
-for(i=0;i<TUNE_NETAPI_MAX_HEAPS;i++)\r
-{\r
- if (!pp->createdHeaps[i]) {pp->createdHeaps[i]=h; return 1;}\r
-}\r
-return -1; //no room\r
-}\r
-\r
-/** @ingroup netapi_api_functions */\r
-/*\r
-* @brief API is used to un-register a heap that was created by application and previously\r
-* registerd so that\r
- * it's garbage queue could be polled automatically by @ref netapi_poll_heapGarbage(). \r
- *\r
- * @details this function un-registers an application-created heap with the netapi instance\r
- * @param[in] @ref NETAPI_T: handle to NETAPI instance \r
- * @param[in] @ref Pktlib_HeapHandle : handle to heap \r
- * @retval <0 if err, 1 if OK\r
- * @pre @ref netapi_init , @ref Pktlib_CreateHeap, @ref netai_registerHeap()\r
- */\r
-static inline int netapi_unregisterHeap(NETAPI_T p, Pktlib_HeapHandle h)\r
-{\r
-NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;\r
-int i;\r
-for(i=0;i<TUNE_NETAPI_MAX_HEAPS;i++)\r
-{\r
- if (pp->createdHeaps[i] == h) {pp->createdHeaps[i]=NULL; return 1;}\r
-}\r
-return -1; //not found\r
-}\r
-\r
-/** @ingroup netapi_api_functions */\r
-/*\r
-* @brief API is used to remove a created pktlib heap\r
- *\r
- * @details this function removes anapplication-created heap with the netapi instance\r
- * [note -> descriptors are zapped and cannot be reused]\r
- * @param[in] @ref NETAPI_T: handle to NETAPI instance \r
- * @param[in] @ref Pktlib_HeapHandle : handle to heap \r
- * @retval <0 if err, 1 if OK\r
- * @pre @ref netapi_init , @ref Pktlib_CreateHeap, @ref netai_registerHeap()\r
- */\r
-\r
-int netapi_closeHeap(NETAPI_T p, Pktlib_HeapHandle h);\r
-\r
-/** @ingroup netapi_api_functions */\r
-/*\r
-* @brief API is used to poll the garbage collection queue for the internal NETAPI heaps and \r
- * any application created heaps\r
- *\r
- * @details this function is used to poll the netapi internal heaps and any \r
- * application-created heaps that have been registered with the netapi instance. The\r
- * poll function checks the garbage collection queue associated with the heap and returns\r
- * descriptors and buffers when appropriate to the main free queue.\r
- * @param[in] @ref NETAPI_T handle to NETAPI instance \r
- * @retval none \r
- * @pre @ref netapi_init @ref pktlib_CreateHeap\r
- */\r
-void netapi_poll_heapGarbage(NETAPI_T p);\r
-\r
-static inline int netapi_get_version(void) {return NETAPI_VERSION_ID;}\r
-static inline char * netapi_get_version_string(void) { return NETAPI_VERSION_STR;}\r
-\r
-#endif\r
+/**************************************************************
+ * FILE PURPOSE : -----------NETAPI-------------
+ * user space access to transport resources on SOC
+ **************************************************************
+ * @file netapi.h
+ *
+ * @brief DESCRIPTION: netapi main header file for user space transport
+ * library
+ *
+ * REVISION HISTORY: rev 0.0.1
+ *
+ * Copyright (c) Texas Instruments Incorporated 2010-2011
+ *
+ * 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.
+*****************************************************************************/
+
+/** @mainpage Network API
+ *
+ * @section intro Introduction
+ *
+ * The network API provides a user space interface to TI SOC transport
+ * Resources. The library includes:
+ * - general startup and setup for user space operations
+ * - memory heap and packet buffer management
+ * - pktio either to/from network or internal queues
+ * - timers for network stacks
+ * - netcp (network co-processor) configuration and control
+ * - utilities including user space synchronization primitivies
+ * - sample scheduling event loop
+ *
+ * NETAPI allows user space transport to configure control the NETCP:
+ * - Classification of packets based on L2: MAC header fields
+ * - Classification of packets based on L3: IP header fields
+ * - Routing of packets to host based on L4 UDP or L5 GTPU ID
+ * - Unidirectional IPSec SA creation and deletion
+ * - Unidirectional IPSec Security Policy creation and deletion
+ *
+ * \par
+ * NOTE:
+ * (C) Copyright 2010-2011 Texas Instruments, Inc.
+ * \par
+ */
+
+/* Define NETAPI as a master group in Doxygen format and add all NETAPI
+ definitions to this group. */
+/** @defgroup netapi USERSPACE TRANSPORT NETAPI
+ * @{
+ */
+/** @} */
+
+
+#ifndef __NETAPI__H
+#define __NETAPI__H
+#include <stdint.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <string.h>
+
++/**
++ * @brief This is the NWAL LLD Version. Versions numbers are encoded in the following
++ * format:
++ * 0xAABBCCDD -> Arch (AA); API Changes (BB); Major (CC); Minor (DD)
++ */
++#define NETAPI_VERSION_ID (0x01000002)
++
++/**
++ * @brief This is the version string which describes the NWAL LLD along with the
++ * date and build information.
++ */
++#define NETAPI_VERSION_STR "NETAPI Revision: 01.00.00.02"
++
++
+/**
+ * @defgroup netapi_structures NETAPI data structures
+ */
+/** @ingroup netapi */
+
+/** @defgroup netapi_api_functions NETAPI API's
+ * @ingroup netapi_api_functions
+ */
+
+/** @ingroup netapi_structures */
+/**
+ * @def NETAPI_T
+ * @brief netapi handle: one per thread
+ * used in most NETAPI calls
+ */
+typedef void * NETAPI_T;
+
+
+#define NETAPI_SYS_MASTER 2 //master for system
+#define NETAPI_CORE_MASTER 1 //master for core
+#define NETAPI_NO_MASTER 0 //data only
+
+/***********************************************
+*************RUN TIME CONTROLS*****************
+***********************************************/
+typedef struct NETAPI_CFG_Tag
+{
+ int def_mem_size; //bytes of CMA memory we have allocated
+ int def_flow_pkt_rx_offset; //offset in pkt buffer for hw to start RX
+ int def_max_descriptors; //# of descriptors in system (must be power of 2), 2^14 max
+ int def_tot_descriptors_for_us; //#of descriptors to create in our region (must be power of 2)
+ int def_heap_n_descriptors; //# descriptors+buffers in default heap
+ int def_heap_n_zdescriptors; //# zero len descriptors in defaule heap
+ int def_heap_buf_size; //size of buffers in default heap
++ //=MAX amount of area for packet data
++ int def_heap_tailroom_size; //size of tailroom in reserve
++ int def_heap_extra_size; //size of extra space at end of buffer
+}NETAPI_CFG_T;
++/* note:
++ each buffer will be allocated: def_heap_buf_size+def_heap_extra_size bytes
++ each descriptor attached to these buffers will have original_pkt_len of:
++ def_heap_buf_size.
++ for default RX flow, for rx packet, the bufptr will be def_flow_pkt_rx_offset.
++ for detault RX flow, threshold (ie max # of bytes in buffer) will be:
++ def_heap_buf_size - def_heap_tailroom_size-def_flow_pkt_rx_offset
++*/
+
+
+
+#include "netapi_err.h"
+#include "netapi_tune.h"
+#include "ti/runtime/pktlib/pktlib_osal.h"
+#include "ti/runtime/pktlib/pktlib.h"
+#include "pktio.h"
+#include "ti/drv/pa/pa.h"
+#include "netcp_cfg.h"
+#include "netapi_sec.h"
+#include "netapi_sched.h"
+#include "src/netapi_vm.h"
- #include "netapi_util.h"
++#include "src/netapi_util.h"
+#include "netsync.h"
+#include "ti/drv/nwal/nwal.h"
+#include "netapi_timer.h"
+#include "src/netapi_loc.h"
+
+/************************************************
+ **********BUILD TIME CONTROLS *****************
+ ***********************************************/
+/* see netapi_tune.h */
+
+
+/*************************************
+ **************NETAPI****************
+ ************************************/
+
+/** @ingroup netapi_api_functions */
+
+/*
+* @brief API instantiates the NETAPI and allocated global resources and is pre-requisite
+ *
+ * @details Allocates global resources valid per system level common across all ARM cores
+ * or per thread based on "master" argument.
+ * Intializes the following substems:
+ * - pktio
+ * - pktlib
+ * - qmss
+ * - cppi
+ * - nwal
+ * @param[in] master mode: NETAPI_SYS_MASTER or NETAPI_NO_MASTER
+ * @param[in] configuration (master mode). pointer to NETAPI_CFG_T above or NULL
+ * @retval @ref NETAPI_T: handle to the instance or NULL on error
+ * @pre none
+ */
+NETAPI_T netapi_init(int master, NETAPI_CFG_T * p_cfg);
+
+
+/** @ingroup netapi_api_functions */
+/*
+* @brief API shutdowns a previously intialized NETAPI instance
+ *
+ * @details de-llocates global resources valid per system level common across all ARM cores
+ * or per thread based on "master" argument passed in at init time.
+ * @param[in] @ref NETAPI_T: handle to the instance
+ * @retval none
+ * @pre @ref netapi_init
+ */
+void netapi_shutdown(NETAPI_T p);
+
+/** @ingroup netapi_api_functions */
+/*
+
+* @brief API returns a @ref Pktlib_HeapIfTable to use when creating pktlib heaps
+ *
+ * @details Application will need a heapIfTable in order to create its own heaps. This
+ * function returns a table that can be passed in the call to @ref Pktlib_CreateHeap
+* The memory used for these heaps is special:
+ * - specific alignment,
+ * - must be contguous,
+ * - must have a physical to virtual mapping that
+ * - is known by NETAPI.
+ * Thus it must be completely managed by NETAPI. This interfaced table provides a
+ * malloc function that the pktlib heap library uses to allocate data for the heap
+ * buffers.
+ * @param[in] none
+ * @retval @ref Pktlib_HeapIfTable pointer
+ * @pre @ref netapi_init
+ */
+Pktlib_HeapIfTable *netapi_getPktlibIfTable(void) ;
+
+/** utilities to see how much mem/descriptor space is remaining **/
+
+/** @ingroup netapi_api_functions */
+/*
+* @brief API is used to return the amount of free memory available for allocating buffers
+ ( for additonal Pktlib heaps.
+ * @details the applicaiton can use this API to determine how much free memory is .
+ * available for heap buffers if it decides to create its own.
+ * @param[in] void
+ * @retval int : amount of memory available for heap buffer storage (in bytes)
+ * @pre @ref netapi_init
+ */
+int netapi_getBufMemRemainder(void);
+/** @ingroup netapi_api_functions */
+
+/*
+* @brief API is used to return the amount of free memory available for allocating Descriptors
+ ( for additonal Pktlib heaps.
+ * @details the applicaiton can use this API to determine how much free memory is .
+ * available for heap descriptors if it decides to create its own heap.
+ * @param[in] void
+ * @retval int : amount of memory available for heap descriptor storage (in bytes)
+ * @pre @ref netapi_init
+ */
+int netapi_getDescRemainder(void);
+
+/* utility to get default flow */
+/** @ingroup netapi_api_functions */
+/*
+* @brief API is used to return the default NETCP flow that is to be used for received
+ ( packets..
+ * @details the applicaiton can use this API to return the default NETCP flow that is used
+ * for received packets. A NETCP flow is a list of PacketLib Heaps that are to be
+ * used to supply free packets to the receive DMA function.
+ * @param[in] @ref NETAPI_T handle to NETAPI instance
+ * @retval NETCP_CFG_FLOW_HANDLE_T : handle to default flow
+ * @pre @ref netapi_init
+ */
+static inline NETCP_CFG_FLOW_HANDLE_T netapi_getDefaultFlow(NETAPI_T p) {
+return NETCP_DEFAULT_FLOW;
+}
+
+/* utility to get default route */
+/** @ingroup netapi_api_functions */
+/*
+* @brief API is used to return the default NETCP route
+ *
+ * @details this functions returns the default NETCP route created by @ref netapi_init.
+ * A netcp route consists of a NETCP flow plus a destination pktio channel
+ * @param[in] @ref NETAPI_T handle to NETAPI instance
+ * @retval NETCP_CFG_ROUTE_HANDLE_T: the handle of the default route.
+ * @pre @ref netapi_init
+ */
+static inline NETCP_CFG_ROUTE_HANDLE_T netapi_getDefaultRoute(NETAPI_T p) {
+return NETCP_DEFAULT_ROUTE;
+}
+
+/* utility to set/get a cookie in the netapi handle */
+/** @ingroup netapi_api_functions */
+/*
+* @brief API is used to return a piece of application-provided opaque data that has been
+ ( stored in the netapi instance.
+ * @details the applicaiton can save a pointer to opaque data in the @ref NETAPI_T instance.
+ * This APi lets this data be returned to the application.
+ * @param[in] @ref NETAPI_T handle to NETAPI instance
+ * @retval void *
+ * @pre @ref netapi_init @ref netapi_setCookie
+ */
+static inline void * netapi_getCookie(NETAPI_T p)
+{
+NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
+return pp->cookie;
+}
+
+/** @ingroup netapi_api_functions */
+/*
+* @brief API is used to set a piece of application-provided opaque data in the
+ ( netapi instance.
+ * @details the applicaiton can save a pointer to opaque data in the @ref NETAPI_T instance.
+ * This APi can be returned later to the application via @ref netapi_getCookie
+ * @param[in] @ref NETAPI_T : handle to NETAPI instance
+ * @param[in] void * : opaque data to be saved
+ * @retval void
+ * @pre @ref netapi_init
+ */
+static inline void netapi_setCookie(NETAPI_T p, void * cookie)
+{
+NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
+pp->cookie= cookie;
+}
+
+
+/** @ingroup netapi_api_functions */
+/*
+* @brief API is used to poll for NETCP configuration response messages.
+ *
+ * @details Application, if controlling the scheduler, will need to call this
+ * function periodically to check for NETCP configuration responses (eg
+ * statistics requests).
+ * @param[in] @ref NETAPI_T handle to NETAPI instance
+ * @retval none
+ * @pre @ref netapi_init
+ */
+void netapi_netcpPoll(NETAPI_T p);
+
+//heap registration for polling purposes
+
+/** @ingroup netapi_api_functions */
+/*
+* @brief API is used to register a heap that is created by application so that
+ * it's garbage queue can be polled automatically by @ref netapi_poll_heapGarbage().
+ *
+ * @details this function registers an application-created heap with the netapi instance
+ * so that it can add that heap's garbage queue to the garbage poll function.
+ * NOTE: netapi internal heap is automatically registered
+ * @param[in] @ref NETAPI_T handle to NETAPI instance
+ * @param[in] @ref Pktlib_HeapHandle: handle of heap to register
+ * @retval int : 1 if OK, <0 on error
+ * @pre @ref netapi_init @ref Pktlib_CreateHeap
+ */
+static inline int netapi_registerHeap(NETAPI_T p, Pktlib_HeapHandle h)
+{
+NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
+int i;
+for(i=0;i<TUNE_NETAPI_MAX_HEAPS;i++)
+{
+ if (!pp->createdHeaps[i]) {pp->createdHeaps[i]=h; return 1;}
+}
+return -1; //no room
+}
+
+/** @ingroup netapi_api_functions */
+/*
+* @brief API is used to un-register a heap that was created by application and previously
+* registerd so that
+ * it's garbage queue could be polled automatically by @ref netapi_poll_heapGarbage().
+ *
+ * @details this function un-registers an application-created heap with the netapi instance
+ * @param[in] @ref NETAPI_T: handle to NETAPI instance
+ * @param[in] @ref Pktlib_HeapHandle : handle to heap
+ * @retval <0 if err, 1 if OK
+ * @pre @ref netapi_init , @ref Pktlib_CreateHeap, @ref netai_registerHeap()
+ */
+static inline int netapi_unregisterHeap(NETAPI_T p, Pktlib_HeapHandle h)
+{
+NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
+int i;
+for(i=0;i<TUNE_NETAPI_MAX_HEAPS;i++)
+{
+ if (pp->createdHeaps[i] == h) {pp->createdHeaps[i]=NULL; return 1;}
+}
+return -1; //not found
+}
+
+/** @ingroup netapi_api_functions */
+/*
+* @brief API is used to remove a created pktlib heap
+ *
+ * @details this function removes anapplication-created heap with the netapi instance
+ * [note -> descriptors are zapped and cannot be reused]
+ * @param[in] @ref NETAPI_T: handle to NETAPI instance
+ * @param[in] @ref Pktlib_HeapHandle : handle to heap
+ * @retval <0 if err, 1 if OK
+ * @pre @ref netapi_init , @ref Pktlib_CreateHeap, @ref netai_registerHeap()
+ */
+
+int netapi_closeHeap(NETAPI_T p, Pktlib_HeapHandle h);
+
+/** @ingroup netapi_api_functions */
+/*
+* @brief API is used to poll the garbage collection queue for the internal NETAPI heaps and
+ * any application created heaps
+ *
+ * @details this function 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.
+ * @param[in] @ref NETAPI_T handle to NETAPI instance
+ * @retval none
+ * @pre @ref netapi_init @ref pktlib_CreateHeap
+ */
+void netapi_poll_heapGarbage(NETAPI_T p);
+
++static inline int netapi_get_version(void) {return NETAPI_VERSION_ID;}
++static inline char * netapi_get_version_string(void) { return NETAPI_VERSION_STR;}
++
+#endif
diff --combined ti/runtime/netapi/netcp_cfg.h
index 073a65fcfde23f2a4207c5db0cbf91bf82f4e689,ca7691ad803e4caac91ba5bf8b3e552ea2336492..7bc17e4b02cd971ac148696132fa71ecda136f9e
--/***************************************************\r
-- * File: netcp_cfg.h \r
-- * Purpose: netcp config API\r
-- **************************************************************\r
-- *@file netcp_cfg.h\r
-- * \r
-- * @brief DESCRIPTION: netapi NETCP configuration API header file \r
-- * for user space transport library\r
-- * \r
-- * REVISION HISTORY: rev 0.0.1 \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
--\r
--#ifndef __NETCP_CFG__H\r
--#define __NETCP_CFG__H\r
--\r
--#include "netapi.h"\r
--#include "ti/drv/pa/pa.h"\r
--#include "ti/runtime/pktlib/pktlib.h"\r
--\r
--//NETCP FLOW\r
--typedef struct NETCP_CFG_FLOW_Tag\r
--{\r
-- int flowid;\r
--} NETCP_CFG_FLOW_T;\r
--typedef void * NETCP_CFG_FLOW_HANDLE_T;\r
--#define NETCP_DEFAULT_FLOW (NETCP_CFG_FLOW_HANDLE_T*) NULL\r
--\r
--//NETCP ROUTE\r
--typedef struct NETCP_CFG_ROUTE_Tag\r
--{\r
-- NETCP_CFG_FLOW_T * p_flow; //NULL or NETCP_DEFAULT_FLOW for default flow\r
-- PKTIO_HANDLE_T * p_dest_q; //NULL for default destination queue\r
--} NETCP_CFG_ROUTE_T;\r
--typedef void * NETCP_CFG_ROUTE_HANDLE_T; \r
--#define NETCP_DEFAULT_ROUTE (NETCP_CFG_ROUTE_HANDLE_T*) NULL\r
--\r
--\r
--/*--------------flow management--------*/\r
--NETCP_CFG_FLOW_HANDLE_T netcp_cfgAddFlow(NETAPI_T ,\r
-- int n, \r
-- Pktlib_HeapHandle handles[],\r
- int sizes[],\r
- int sizes[], //must be<= heap corresponding heap size-recv_offset-any desired tail room\r
-- int recv_offset, //bytes to save in front of packet\r
-- int * err );\r
--void netcp_cfgDelFlow(NETAPI_T , NETCP_CFG_FLOW_HANDLE_T , int * err);\r
--\r
--/*-----------Actions----------*/\r
--#define NETCP_CFG_ACTION_DISCARD 0\r
--#define NETCP_CFG_ACTION_CONTINUE 1 //pass packet on to next classifier\r
--#define NETCP_CFG_ACTION_TO_SW 2\r
--\r
--/*------------L2----------------------*/\r
--typedef void * NETCP_CFG_VLAN_T;\r
--\r
--/******************************************************************/\r
--/***********************APP ids for rx meta data********************/\r
--/******************************************************************/\r
--\r
--/* APPIDs are present in RX packet meta data and tell "how far the packet got\r
-- through the classification rules of NETCP \r
-- APPID is 32 bits:\r
-- bits 31-24 = MATCH STAGE (NETAPI_NECP_MATCH_xxx below)\r
-- bits 23-8 = identifier (depends on match stage)\r
-- bits 7-0 = logical mac interface\r
--\r
-- As a cheat sheet:\r
--If APPID == _NETCP_MATCH_GENERIC_MAC then\r
-- packet matched a MAC entry. Entry # (logical interface) is in byte 0 of APPID. \r
-- Packet did not match any other rule\r
--\r
--If APPID == _NETCP_MATCH_GENERIC_IP then\r
-- packet matched a MAC entry. Entry # (logical interface) is in byte 0 of APPID\r
-- packet matched a generic IP rule attached to that interface. The IP rule # for the interface\r
-- is given in Bytes 3,2 of the APPID. Packet did not match any other rule\r
--\r
--If APPID = NETCP_MATCH_CLASS\r
-- packet matched a MAC entry. Entry # (logical interface) is in byte 0 of APPID\r
-- packet matched a generic IP rule attached to that interface OR a general IP rule added as part of\r
-- the classifier or it matched a combination of ISPEC SA rule and a policy check. Finally,\r
-- Packet matched a L4 port rule that was added as part of a classifer. Bytes 3-2\r
-- give the ID of the classifier . Packet did not match any other rule\r
--\r
--If APPID = NETCP_MATCH_CLASS_L3 (partial classifier match)\r
-- packet matched a MAC entry. Entry # (logical interface) is in byte 0 of APPID\r
-- packet matched a general IP rule added as part of a classifier. But it not match a\r
-- L4 port or any other rule. We cannout say what classifer partially matched so Bytes 3-2 are\r
-- not applicable\r
--\r
--\r
--If APPID = NETCP_MATCH_IPSEC\r
-- packet matched a MAC entry. Entry # (logical interface) is in byte 0 of APPID\r
-- packet matched an IPSEC SA rule (matched proto, dest ip and SPI). The SA id is in\r
-- bytes 3-2 of APPID. Packet did not match any other rule (so may have failed a policy check)\r
--\r
--ID APPID = NETCP_MATCH_IPSEC_POLICY \r
-- packet matched a MAC entry. Entry # (logical interface) is in byte 0 of APPID\r
-- packet matched an IPSEC SA rule (matched proto, dest ip and SPI). Packet matched\r
-- a POLICY RULE - this is a check of the inner IP. The IPSEC RX Policy ID is in\r
-- bytes 3-2 of APPID. Packet did not match any other rule \r
--*/\r
--\r
-- \r
--// NWAL "AP ids" for PA Rules that are added\r
--#define NETAPI_NETCP_MATCH_GENERIC_MAC 0x10000000 //lower byte==interface\r
--#define NETAPI_NETCP_MATCH_GENERIC_IP 0x20000000 //lower byte==interface\r
--#define NETAPI_NETCP_MATCH_CLASS 0x80000000 //FULL MATCH or' in classifier (16 bits), lower byte==interface\r
--#define NETAPI_NETCP_MATCH_CLASS_L3 0x40000000 //MATCHED L3 but not L4. lower byte==interface\r
--#define NETAPI_NETCP_MATCH_IPSEC 0x01000000 //lower byte==interface, Or' in SA id (16 bits)\r
--#define NETAPI_NETCP_MATCH_IPSEC_POLICY 0x02000000 //lower byte==interface, Or' in SA id (16 bits)\r
--\r
--/*---------MAC APPID------------------*/\r
--/* Packets just matching MAC rule are tagged with this type (MATCH_GENERIC_MAC) */\r
--typedef uint32_t NETCP_CFG_MACIF_T;\r
--\r
--/*---------------IP APPID-------------------*/\r
--/* Packets whose final match is an IP rule are tagged with this type (MATCH_GENERIC_IP)*/ \r
--typedef uint32_t NETCP_CFG_IP_T;\r
--\r
--/*--------------Tunnel APPID------------------*/\r
--/* Packets whose final match a IPSEC tunnel are tagged with this type (MATCH_IPSEC)*/ \r
--typedef uint32_t NETCP_CFG_SA_T; \r
--\r
--/*---------------IPSEc RX Policy APPID------------*/\r
--/* Packets whose final match is a IPSEC RX Policy are tagged with this type (MATCH_IPSEC_POLICY)*/ \r
--typedef uint32_t NETCP_CFG_IPSEC_POLICY_T; \r
--\r
--\r
--//use this in AddIp, AddClassifier to indicate any MAC address\r
--#define NETCP_CFG_NO_INTERFACE 0xff\r
--\r
--/* del mac i/f */\r
--void netcp_cfgDelMac(NETAPI_T h,int iface_no, int *err);\r
--\r
--/* del attached IP*/\r
--void netcp_cfgDelIp(NETAPI_T h, int iface_no, nwal_IpType ipType,\r
-- nwalIpAddr_t * ip_addr,\r
-- nwalIpOpt_t * ip_qualifiers, \r
-- NETCP_CFG_IP_T, \r
-- int *err);\r
-- \r
--\r
--/*****************************************************************\r
-- * Create a MAC interface \r
-- ****************************************************************/\r
--/*\r
--* @brief API Creates a MAC interface \r
-- *\r
-- * @details This api is used to create a MAC interface.\r
-- * Once it is created, the MAC interface can be used to receive packets. The API\r
-- * adds a rule to the NETCP 1st level lookup tables to route all packets with destination\r
-- * MAC matching supplied argument and not matching any other lookup entry (see @ref netcp_cfgAddIp) to\r
-- * the supplied route, @ref NETCP_CFG_ROUTE_T, (or default route).\r
-- * Packets arriving that match this rule are identified in meta data with Appid= NETAPI_NETCP_MATCH_GENERIC_MAC\r
-- * Note: The internal SOC switch must be "taught" that this mac\r
-- * address is present by transmitting a packet with destination mac = this interface mac address.\r
-- * @param[in] @ref NETAPI_T: NETAPI instance \r
-- * @param[in] char *: pointer to 6 byte MAC address for interface\r
-- * @param[in] int : interface number (0,1,..) \r
-- * @param[in] int : switch port (0 don't care, 1 switch port 1, 1 switch port 2) [only 0 supported] \r
-- * @param[in] @ref NETCP_CFG_ROUTE_HANDLE_T : [future] handle of a created route or NULL to use internal default route \r
-- * @oaram[in] @ref NETCP_CFG_VLAN_T : [future[ vlan configuration . Set to NULL\r
-- * @param[in] int : [future] interface state (0=down, 1= up)\r
-- * @param[out] int * err: pointer to error return\r
-- * @retval @ref NETCP_CFG_MACIF_T : returned AppID for interface (this is returned in meta data for\r
-- * received packets matching this rule an no others)\r
-- * @pre @ref netapi_init \r
-- */\r
--NETCP_CFG_MACIF_T netcp_cfgCreateMacInterface(\r
-- NETAPI_T h, //\r
-- uint8_t *p_mac, //mac address associated with interface\r
-- int iface_no, //0,1, ..\r
-- int switch_port,//0=don't care, 1=switch port 1, 2=switch port 2 , ..\r
-- NETCP_CFG_ROUTE_HANDLE_T route, //NULL to use default\r
-- NETCP_CFG_VLAN_T vlan, //future\r
-- int state, //0=down, 1=up //FUTURE\r
-- int * err\r
-- );\r
--\r
--/*****************************************************************\r
-- * Add IP address/qualifier to MAC interface \r
-- ****************************************************************/\r
--/*\r
--* @brief API attaches an IP adderess and qualifier to a MAC interface \r
-- *\r
-- * @details This api is used to add an IP address to a MAC interface along\r
-- * with optional IP qualifier. A route, @ref NETCP_CFG_ROUTE_HANDLE_T,or NULL for default \r
-- * may be specified to indicate where to send packets matching the MAC interface MAC address, the\r
-- * supplied IP address and any qualifier. This API adds a rule to the NETCP level 1 lookup tables\r
-- * Packets arriving that match this rule are identified in meta data with Appid= NETAPI_NETCP_MATCH_GENERIC_IP\r
-- * Note: An IP address must be attached to enable NETCP Recevie Checksum offload feature\r
-- * @param[in] @ref NETAPI_T: NETAPI instance\r
-- * @param[in] int : interface number (0,1,..)\r
-- * @param[in] @ref nwal_IpType : type of IP address (V4 for V6) \r
-- * @oaram[in] @ref nwalIpAddr_t : ip_address\r
-- * @param[in] @ref nwalIpOpt_t : ip_qualifiers (all 0 for no qualifiers). This can be used to apply special handling for\r
-- * diffserv category for example\r
-- * @param[in] @ref NETCP_CFG_ROUTE_HANDLE_T : [future] handle of a created route or NULL to use internal default route \r
-- * @param[out] int * err: pointer to error return\r
-- * @retval @ref NETCP_CFG_IP_T : returned AppID for attached rule. This is returned in RX meta data for\r
-- * packets matching this rule and no other.\r
-- * @pre @ref netapi_init , @ref netcp_cfgAddMac \r
-- */\r
--NETCP_CFG_IP_T netcp_cfgAddIp(\r
-- NETAPI_T h,\r
-- int iface_no,\r
-- nwal_IpType ipType,\r
-- nwalIpAddr_t * ip_addr,\r
-- nwalIpOpt_t * ip_qualifiers,\r
-- NETCP_CFG_ROUTE_HANDLE_T route, //NULL for default\r
-- int * err\r
-- );\r
--#define netcp_addIp netcp_cfgAddIp //oops\r
--\r
--/*------------------classification API-------------------*/\r
--\r
--//handle to installed classifier returned by API. Pkts matching\r
--//this classifier will have meta data with this tag. Also used\r
--//to delete classifier\r
--typedef uint32_t NETCP_CFG_CLASS_T; \r
--\r
--//classifier L4 type (L2,L3 implied by iface, ip)\r
--typedef struct NETCP_CFG_CLASS_L4_Tag\r
--{\r
-- //which mac interface pkt is from, \r
-- int iface;\r
-- NETCP_CFG_IP_T ip;\r
--\r
-- //L4 (port)\r
-- nwal_appProtoType_t proto; //L4 proto (-1 for don't care)\r
-- nwalAppProto_t appProto; //ports or equivalent\r
--\r
--} NETCP_CFG_CLASS_L4_T;\r
--\r
--//classifier L4 + policy (L2, L3 (outer), tunnel, L3 (inner) implied by policy\r
--typedef struct NETCP_CFG_CLASS_L4_IPSEC_Tag\r
--{\r
-- //which mac interface pkt is from, \r
-- int iface;\r
-- NETCP_CFG_IPSEC_POLICY_T ip_policy;\r
--\r
-- //L4 (port)\r
-- nwal_appProtoType_t proto; //L4 proto (-1 for don't care)\r
-- nwalAppProto_t appProto; //ports or equivalent\r
--\r
--} NETCP_CFG_CLASS_L4_IPSEC_T;\r
--\r
--\r
--//classifier L3_L4 type (L2 implied by iface)\r
--typedef struct NETCP_CFG_CLASS_L3_L4_Tag\r
--{\r
-- //which mac interface pkt is from, \r
-- int iface;\r
--\r
-- //L3 - iP address: IP type, destination addr, qualifiers\r
-- nwal_IpType ipType;\r
-- nwalIpAddr_t * ip_addr;\r
-- nwalIpOpt_t * ip_qualifiers;\r
-- NETCP_CFG_ROUTE_HANDLE_T p_fail_route; //what to do if L3 matches but L4 fails AND L3 is a \r
-- // new rule.(if exisitng rule, then existing fail\r
-- //route will be used.\r
-- \r
-- //L4 (port)\r
-- nwal_appProtoType_t proto; //L4 proto (-1 for don't care)\r
-- nwalAppProto_t appProto; //ports or equivalent\r
--\r
--} NETCP_CFG_CLASS_L3_L4_T;\r
--\r
--//classifier\r
--typedef struct NETCP_CFG_CLASSIFIER_Tag\r
--{\r
-- int classType;\r
--#define NETCP_CFG_CLASS_TYPE_L4 0\r
--#define NETCP_CFG_CLASS_TYPE_L3_L4 1\r
-- union\r
-- {\r
-- NETCP_CFG_CLASS_L3_L4_T c_l3_l4;\r
-- NETCP_CFG_CLASS_L4_T c_l4;\r
-- NETCP_CFG_CLASS_L4_IPSEC_T c_l4_ipsec;\r
-- } u;\r
--\r
--} NETCP_CFG_CLASSIFIER_T;\r
--\r
--//Instert a classifier.\r
--NETCP_CFG_CLASS_T netcp_cfgAddClass(NETAPI_T h,\r
-- NETCP_CFG_CLASSIFIER_T *p_class,\r
-- NETCP_CFG_ROUTE_HANDLE_T p_route,\r
-- int action, int * err);\r
--//delete classifier\r
--void netcp_cfgDelClass(NETAPI_T h,\r
-- NETCP_CFG_CLASS_T classId,\r
-- int *err);\r
--\r
--\r
--\r
--/***************************************************************************\r
--********************************STATS**************************************\r
--**************************************************************************/\r
--\r
--/*\r
-- * @brief This is the callback function that is used to return statistics from NETCP \r
-- *\r
-- * @details The application provides a callback function that NETAPI uses to report statistics.\r
--* The request for stats is generated from the @ref netcp_cfgReqStats API.\r
-- * Note: to receive ths stats callback, the @ref netapi_netcpPoll funcition must be called\r
-- * @param[in] @ref NETAPI_T: NETAPI instance\r
-- * @param[in] @ref paSysStats_t * : the PA (NETCP packet accelerator subsystem) statistics block \r
-- * @retval none \r
-- * @pre @ref netapi_init , @ref netapi_cfgReqStats, @ref netapi_netcpPoll\r
-- */\r
--//stats CB\r
--typedef void (*NETCP_CFG_STATS_CB)( NETAPI_T h, paSysStats_t* pPaStats);\r
--\r
--\r
--//stats request\r
--/*\r
-- * @brief API request statistics from NETCP \r
-- *\r
-- * @details This api is used to request a statistics from NETCP. This will generate a stats request\r
-- * command to NETCP. Sometime later, the statistics result will arrive and will be passed to \r
-- * the caller via the asynchronus callback @ref NETCP_CFG_STATS_CB that is registered in this call.\r
-- * Note: to receive the stats callback, the @ref netapi_netcpPoll funcition must be called\r
-- * @param[in] @ref NETAPI_T: NETAPI instance\r
-- * @param[in] @ref NETCP_CFG_STATS_CB : the function to call with the resulting statistics block\r
-- * @param[in] int : clear the stats in NETCP after the report (0=no, 1=yes) \r
-- * @param[out] int * err: pointer to error return\r
-- * @retval none \r
-- * @pre @ref netapi_init \r
-- */\r
--void netcp_cfgReqStats(NETAPI_T h, //NEAPI instance\r
-- NETCP_CFG_STATS_CB c, //stats report callback function\r
-- int doClear, //0: don't clear, 1 clear\r
-- int *err);\r
--\r
--#endif\r
--\r
++/***************************************************
++ * File: netcp_cfg.h
++ * Purpose: netcp config API
++ **************************************************************
++ *@file netcp_cfg.h
++ *
++ * @brief DESCRIPTION: netapi NETCP configuration API header file
++ * for user space transport library
++ *
++ * REVISION HISTORY: rev 0.0.1
++ *
++ * Copyright (c) Texas Instruments Incorporated 2010-2011
++ *
++ * 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.
++
++ ***************************************************/
++
++#ifndef __NETCP_CFG__H
++#define __NETCP_CFG__H
++
++#include "netapi.h"
++#include "ti/drv/pa/pa.h"
++#include "ti/runtime/pktlib/pktlib.h"
++
++//NETCP FLOW
++typedef struct NETCP_CFG_FLOW_Tag
++{
++ int flowid;
++} NETCP_CFG_FLOW_T;
++typedef void * NETCP_CFG_FLOW_HANDLE_T;
++#define NETCP_DEFAULT_FLOW (NETCP_CFG_FLOW_HANDLE_T*) NULL
++
++//NETCP ROUTE
++typedef struct NETCP_CFG_ROUTE_Tag
++{
++ NETCP_CFG_FLOW_T * p_flow; //NULL or NETCP_DEFAULT_FLOW for default flow
++ PKTIO_HANDLE_T * p_dest_q; //NULL for default destination queue
++} NETCP_CFG_ROUTE_T;
++typedef void * NETCP_CFG_ROUTE_HANDLE_T;
++#define NETCP_DEFAULT_ROUTE (NETCP_CFG_ROUTE_HANDLE_T*) NULL
++
++
++/*--------------flow management--------*/
++NETCP_CFG_FLOW_HANDLE_T netcp_cfgAddFlow(NETAPI_T ,
++ int n,
++ Pktlib_HeapHandle handles[],
++ int sizes[], //must be<= heap corresponding heap size-recv_offset-any desired tail room
++ int recv_offset, //bytes to save in front of packet
++ int * err );
++void netcp_cfgDelFlow(NETAPI_T , NETCP_CFG_FLOW_HANDLE_T , int * err);
++
++/*-----------Actions----------*/
++#define NETCP_CFG_ACTION_DISCARD 0
++#define NETCP_CFG_ACTION_CONTINUE 1 //pass packet on to next classifier
++#define NETCP_CFG_ACTION_TO_SW 2
++
++/*------------L2----------------------*/
++typedef void * NETCP_CFG_VLAN_T;
++
++/******************************************************************/
++/***********************APP ids for rx meta data********************/
++/******************************************************************/
++
++/* APPIDs are present in RX packet meta data and tell "how far the packet got
++ through the classification rules of NETCP
++ APPID is 32 bits:
++ bits 31-24 = MATCH STAGE (NETAPI_NECP_MATCH_xxx below)
++ bits 23-8 = identifier (depends on match stage)
++ bits 7-0 = logical mac interface
++
++ As a cheat sheet:
++If APPID == _NETCP_MATCH_GENERIC_MAC then
++ packet matched a MAC entry. Entry # (logical interface) is in byte 0 of APPID.
++ Packet did not match any other rule
++
++If APPID == _NETCP_MATCH_GENERIC_IP then
++ packet matched a MAC entry. Entry # (logical interface) is in byte 0 of APPID
++ packet matched a generic IP rule attached to that interface. The IP rule # for the interface
++ is given in Bytes 3,2 of the APPID. Packet did not match any other rule
++
++If APPID = NETCP_MATCH_CLASS
++ packet matched a MAC entry. Entry # (logical interface) is in byte 0 of APPID
++ packet matched a generic IP rule attached to that interface OR a general IP rule added as part of
++ the classifier or it matched a combination of ISPEC SA rule and a policy check. Finally,
++ Packet matched a L4 port rule that was added as part of a classifer. Bytes 3-2
++ give the ID of the classifier . Packet did not match any other rule
++
++If APPID = NETCP_MATCH_CLASS_L3 (partial classifier match)
++ packet matched a MAC entry. Entry # (logical interface) is in byte 0 of APPID
++ packet matched a general IP rule added as part of a classifier. But it not match a
++ L4 port or any other rule. We cannout say what classifer partially matched so Bytes 3-2 are
++ not applicable
++
++
++If APPID = NETCP_MATCH_IPSEC
++ packet matched a MAC entry. Entry # (logical interface) is in byte 0 of APPID
++ packet matched an IPSEC SA rule (matched proto, dest ip and SPI). The SA id is in
++ bytes 3-2 of APPID. Packet did not match any other rule (so may have failed a policy check)
++
++ID APPID = NETCP_MATCH_IPSEC_POLICY
++ packet matched a MAC entry. Entry # (logical interface) is in byte 0 of APPID
++ packet matched an IPSEC SA rule (matched proto, dest ip and SPI). Packet matched
++ a POLICY RULE - this is a check of the inner IP. The IPSEC RX Policy ID is in
++ bytes 3-2 of APPID. Packet did not match any other rule
++*/
++
++
++// NWAL "AP ids" for PA Rules that are added
++#define NETAPI_NETCP_MATCH_GENERIC_MAC 0x10000000 //lower byte==interface
++#define NETAPI_NETCP_MATCH_GENERIC_IP 0x20000000 //lower byte==interface
++#define NETAPI_NETCP_MATCH_CLASS 0x80000000 //FULL MATCH or' in classifier (16 bits), lower byte==interface
++#define NETAPI_NETCP_MATCH_CLASS_L3 0x40000000 //MATCHED L3 but not L4. lower byte==interface
++#define NETAPI_NETCP_MATCH_IPSEC 0x01000000 //lower byte==interface, Or' in SA id (16 bits)
++#define NETAPI_NETCP_MATCH_IPSEC_POLICY 0x02000000 //lower byte==interface, Or' in SA id (16 bits)
++
++/*---------MAC APPID------------------*/
++/* Packets just matching MAC rule are tagged with this type (MATCH_GENERIC_MAC) */
++typedef uint32_t NETCP_CFG_MACIF_T;
++
++/*---------------IP APPID-------------------*/
++/* Packets whose final match is an IP rule are tagged with this type (MATCH_GENERIC_IP)*/
++typedef uint32_t NETCP_CFG_IP_T;
++
++/*--------------Tunnel APPID------------------*/
++/* Packets whose final match a IPSEC tunnel are tagged with this type (MATCH_IPSEC)*/
++typedef uint32_t NETCP_CFG_SA_T;
++
++/*---------------IPSEc RX Policy APPID------------*/
++/* Packets whose final match is a IPSEC RX Policy are tagged with this type (MATCH_IPSEC_POLICY)*/
++typedef uint32_t NETCP_CFG_IPSEC_POLICY_T;
++
++
++//use this in AddIp, AddClassifier to indicate any MAC address
++#define NETCP_CFG_NO_INTERFACE 0xff
++
++/* del mac i/f */
++void netcp_cfgDelMac(NETAPI_T h,int iface_no, int *err);
++
++/* del attached IP*/
++void netcp_cfgDelIp(NETAPI_T h, int iface_no, nwal_IpType ipType,
++ nwalIpAddr_t * ip_addr,
++ nwalIpOpt_t * ip_qualifiers,
++ NETCP_CFG_IP_T,
++ int *err);
++
++
++/*****************************************************************
++ * Create a MAC interface
++ ****************************************************************/
++/*
++* @brief API Creates a MAC interface
++ *
++ * @details This api is used to create a MAC interface.
++ * Once it is created, the MAC interface can be used to receive packets. The API
++ * adds a rule to the NETCP 1st level lookup tables to route all packets with destination
++ * MAC matching supplied argument and not matching any other lookup entry (see @ref netcp_cfgAddIp) to
++ * the supplied route, @ref NETCP_CFG_ROUTE_T, (or default route).
++ * Packets arriving that match this rule are identified in meta data with Appid= NETAPI_NETCP_MATCH_GENERIC_MAC
++ * Note: The internal SOC switch must be "taught" that this mac
++ * address is present by transmitting a packet with destination mac = this interface mac address.
++ * @param[in] @ref NETAPI_T: NETAPI instance
++ * @param[in] char *: pointer to 6 byte MAC address for interface
++ * @param[in] int : interface number (0,1,..)
++ * @param[in] int : switch port (0 don't care, 1 switch port 1, 1 switch port 2) [only 0 supported]
++ * @param[in] @ref NETCP_CFG_ROUTE_HANDLE_T : [future] handle of a created route or NULL to use internal default route
++ * @oaram[in] @ref NETCP_CFG_VLAN_T : [future[ vlan configuration . Set to NULL
++ * @param[in] int : [future] interface state (0=down, 1= up)
++ * @param[out] int * err: pointer to error return
++ * @retval @ref NETCP_CFG_MACIF_T : returned AppID for interface (this is returned in meta data for
++ * received packets matching this rule an no others)
++ * @pre @ref netapi_init
++ */
++NETCP_CFG_MACIF_T netcp_cfgCreateMacInterface(
++ NETAPI_T h, //
++ uint8_t *p_mac, //mac address associated with interface
++ int iface_no, //0,1, ..
++ int switch_port,//0=don't care, 1=switch port 1, 2=switch port 2 , ..
++ NETCP_CFG_ROUTE_HANDLE_T route, //NULL to use default
++ NETCP_CFG_VLAN_T vlan, //future
++ int state, //0=down, 1=up //FUTURE
++ int * err
++ );
++
++/*****************************************************************
++ * Add IP address/qualifier to MAC interface
++ ****************************************************************/
++/*
++* @brief API attaches an IP adderess and qualifier to a MAC interface
++ *
++ * @details This api is used to add an IP address to a MAC interface along
++ * with optional IP qualifier. A route, @ref NETCP_CFG_ROUTE_HANDLE_T,or NULL for default
++ * may be specified to indicate where to send packets matching the MAC interface MAC address, the
++ * supplied IP address and any qualifier. This API adds a rule to the NETCP level 1 lookup tables
++ * Packets arriving that match this rule are identified in meta data with Appid= NETAPI_NETCP_MATCH_GENERIC_IP
++ * Note: An IP address must be attached to enable NETCP Recevie Checksum offload feature
++ * @param[in] @ref NETAPI_T: NETAPI instance
++ * @param[in] int : interface number (0,1,..)
++ * @param[in] @ref nwal_IpType : type of IP address (V4 for V6)
++ * @oaram[in] @ref nwalIpAddr_t : ip_address
++ * @param[in] @ref nwalIpOpt_t : ip_qualifiers (all 0 for no qualifiers). This can be used to apply special handling for
++ * diffserv category for example
++ * @param[in] @ref NETCP_CFG_ROUTE_HANDLE_T : [future] handle of a created route or NULL to use internal default route
++ * @param[out] int * err: pointer to error return
++ * @retval @ref NETCP_CFG_IP_T : returned AppID for attached rule. This is returned in RX meta data for
++ * packets matching this rule and no other.
++ * @pre @ref netapi_init , @ref netcp_cfgAddMac
++ */
++NETCP_CFG_IP_T netcp_cfgAddIp(
++ NETAPI_T h,
++ int iface_no,
++ nwal_IpType ipType,
++ nwalIpAddr_t * ip_addr,
++ nwalIpOpt_t * ip_qualifiers,
++ NETCP_CFG_ROUTE_HANDLE_T route, //NULL for default
++ int * err
++ );
++#define netcp_addIp netcp_cfgAddIp //oops
++
++/*------------------classification API-------------------*/
++
++//handle to installed classifier returned by API. Pkts matching
++//this classifier will have meta data with this tag. Also used
++//to delete classifier
++typedef uint32_t NETCP_CFG_CLASS_T;
++
++//classifier L4 type (L2,L3 implied by iface, ip)
++typedef struct NETCP_CFG_CLASS_L4_Tag
++{
++ //which mac interface pkt is from,
++ int iface;
++ NETCP_CFG_IP_T ip;
++
++ //L4 (port)
++ nwal_appProtoType_t proto; //L4 proto (-1 for don't care)
++ nwalAppProto_t appProto; //ports or equivalent
++
++} NETCP_CFG_CLASS_L4_T;
++
++//classifier L4 + policy (L2, L3 (outer), tunnel, L3 (inner) implied by policy
++typedef struct NETCP_CFG_CLASS_L4_IPSEC_Tag
++{
++ //which mac interface pkt is from,
++ int iface;
++ NETCP_CFG_IPSEC_POLICY_T ip_policy;
++
++ //L4 (port)
++ nwal_appProtoType_t proto; //L4 proto (-1 for don't care)
++ nwalAppProto_t appProto; //ports or equivalent
++
++} NETCP_CFG_CLASS_L4_IPSEC_T;
++
++
++//classifier L3_L4 type (L2 implied by iface)
++typedef struct NETCP_CFG_CLASS_L3_L4_Tag
++{
++ //which mac interface pkt is from,
++ int iface;
++
++ //L3 - iP address: IP type, destination addr, qualifiers
++ nwal_IpType ipType;
++ nwalIpAddr_t * ip_addr;
++ nwalIpOpt_t * ip_qualifiers;
++ NETCP_CFG_ROUTE_HANDLE_T p_fail_route; //what to do if L3 matches but L4 fails AND L3 is a
++ // new rule.(if exisitng rule, then existing fail
++ //route will be used.
++
++ //L4 (port)
++ nwal_appProtoType_t proto; //L4 proto (-1 for don't care)
++ nwalAppProto_t appProto; //ports or equivalent
++
++} NETCP_CFG_CLASS_L3_L4_T;
++
++//classifier
++typedef struct NETCP_CFG_CLASSIFIER_Tag
++{
++ int classType;
++#define NETCP_CFG_CLASS_TYPE_L4 0
++#define NETCP_CFG_CLASS_TYPE_L3_L4 1
++ union
++ {
++ NETCP_CFG_CLASS_L3_L4_T c_l3_l4;
++ NETCP_CFG_CLASS_L4_T c_l4;
++ NETCP_CFG_CLASS_L4_IPSEC_T c_l4_ipsec;
++ } u;
++
++} NETCP_CFG_CLASSIFIER_T;
++
++//Instert a classifier.
++NETCP_CFG_CLASS_T netcp_cfgAddClass(NETAPI_T h,
++ NETCP_CFG_CLASSIFIER_T *p_class,
++ NETCP_CFG_ROUTE_HANDLE_T p_route,
++ int action, int * err);
++//delete classifier
++void netcp_cfgDelClass(NETAPI_T h,
++ NETCP_CFG_CLASS_T classId,
++ int *err);
++
++
++
++/***************************************************************************
++********************************STATS**************************************
++**************************************************************************/
++
++/*
++ * @brief This is the callback function that is used to return statistics from NETCP
++ *
++ * @details The application provides a callback function that NETAPI uses to report statistics.
++* The request for stats is generated from the @ref netcp_cfgReqStats API.
++ * Note: to receive ths stats callback, the @ref netapi_netcpPoll funcition must be called
++ * @param[in] @ref NETAPI_T: NETAPI instance
++ * @param[in] @ref paSysStats_t * : the PA (NETCP packet accelerator subsystem) statistics block
++ * @retval none
++ * @pre @ref netapi_init , @ref netapi_cfgReqStats, @ref netapi_netcpPoll
++ */
++//stats CB
++typedef void (*NETCP_CFG_STATS_CB)( NETAPI_T h, paSysStats_t* pPaStats);
++
++
++//stats request
++/*
++ * @brief API request statistics from NETCP
++ *
++ * @details This api is used to request a statistics from NETCP. This will generate a stats request
++ * command to NETCP. Sometime later, the statistics result will arrive and will be passed to
++ * the caller via the asynchronus callback @ref NETCP_CFG_STATS_CB that is registered in this call.
++ * Note: to receive the stats callback, the @ref netapi_netcpPoll funcition must be called
++ * @param[in] @ref NETAPI_T: NETAPI instance
++ * @param[in] @ref NETCP_CFG_STATS_CB : the function to call with the resulting statistics block
++ * @param[in] int : clear the stats in NETCP after the report (0=no, 1=yes)
++ * @param[out] int * err: pointer to error return
++ * @retval none
++ * @pre @ref netapi_init
++ */
++void netcp_cfgReqStats(NETAPI_T h, //NEAPI instance
++ NETCP_CFG_STATS_CB c, //stats report callback function
++ int doClear, //0: don't clear, 1 clear
++ int *err);
++
++#endif
++
diff --combined ti/runtime/netapi/pktio.h
index e4c729667887f2de3796f667e170e946a3e53cb9,618db5fab4698b164d0ca9642d26a088902fdf62..e9d3d7f67e23721ffaa0fd033bd93720debf50dc
-/*********************************\r
- *FILE: pktio.h\r
- *PURPOSE: pktio library header\r
- **************************************************************\r
- * @file pktio.h\r
- * \r
- * @bried DESCRIPTION: pktio module main header file for user space transport\r
- * library\r
- * \r
- * REVISION HISTORY: rev 0.0.1 \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
-#ifndef __PKTIO__H\r
-#define __PKTIO__H\r
-#include "netapi.h"\r
-#include "ti/runtime/pktlib/pktlib.h"\r
-#include "ti/drv/nwal/nwal.h"\r
-#include "ti/drv/nwal/nwal_util.h"\r
-#include "netapi_err.h"\r
-\r
-/*--------------------defines-----------------------*/\r
-#define PKTIO_NOMEM NETAPI_ERR_NOMEM\r
-//default pktio channels \r
-#define NETCP_TX "NETCP_TX"\r
-#define NETCP_RX "NETCP_RX"\r
-#define NETCP_SB_RX "NETCP_SB_RX"\r
-#define NETCP_SB_TX "NETCP_SB_TX"\r
-#define PKTIO_MAX_NAME 19 \r
-\r
-/*--------------------data structures----------------*/\r
-typedef struct PKTIO_METADATA_Tag\r
-{\r
- int flags1;\r
-#define PKTIO_META_RX 0x01\r
-#define PKTIO_META_TX 0x02\r
-#define PKTIO_META_SB_RX 0x4 //SB crypto rx \r
-#define PKTIO_META_SB_TX 0x8 //SB crypto tx\r
-#define PKTIO_META_APP_DEF 0x80000000\r
- union\r
- {\r
- nwalRxPktInfo_t * rx_meta;\r
- nwalTxPktInfo_t * tx_meta;\r
- nwalDmRxPayloadInfo_t * rx_sb_meta;\r
- nwalDmTxPayloadInfo_t * tx_sb_meta;\r
- } u;\r
- void * sa_handle; //valid for PKTIO_META_TX with IPSEC inflow or PKTIO_PKTIO_META_SB_TX . \r
- // MUST BE nwal_HANDLE_INVALID otherwise\r
-} PKTIO_METADATA_T;\r
-\r
-/* the callback function */\r
-struct PKTIO_HANDLE_tag;\r
-\r
-//polling control\r
-typedef struct PKTIO_POLL_Tag\r
-{\r
-/* future */\r
-} PKTIO_POLL_T;\r
-\r
-#define PKTIO_MAX_RECV (TUNE_NETAPI_MAX_BURST_RCV)\r
-typedef void (*PKTIO_CB)(struct PKTIO_HANDLE_tag * channel, Ti_Pkt* p_recv[],\r
- PKTIO_METADATA_T p_meta[], int n_pkts,\r
- uint64_t ts );\r
-\r
-typedef int (*PKTIO_SEND)(struct PKTIO_HANDLE_tag * channel, Ti_Pkt* p_send,\r
- PKTIO_METADATA_T *p_meta, int * p_err);\r
-\r
-typedef int (*PKTIO_POLL)(struct PKTIO_HANDLE_tag * channel,PKTIO_POLL_T * p_poll_cfg ,\r
- int * p_err);\r
-\r
-/** channel configuration */\r
-#define PKTIO_NA 0\r
-typedef struct PKTIO_CFG_Tag\r
-{\r
-#define PKTIO_R 0x1\r
-#define PKTIO_W 0x2\r
-#define PKTIO_RW (PKTIO_R | PKTIO_W)\r
-int flags1;\r
-\r
-#define PKTIO_LOCAL 0x2 \r
-#define PKTIO_GLOBAL 0x1\r
-#define PKTIO_PKT 0x4 //define this if this channel is for NETCP \r
-#define PKTIO_SB 0x8 //define this if this channel is for sideband crypto \r
-int flags2;\r
-\r
-//for create\r
-#define PKTIO_Q_ANY -1\r
-int qnum;\r
-\r
-//for poll\r
-int max_n;\r
-}PKTIO_CFG_T;\r
-\r
-struct NETAPI_tag;\r
-\r
-/* a pktio channel .. */\r
-\r
-typedef struct PKTIO_HANDLE_Tag\r
-{\r
-#define PKTIO_INUSE 0xfeedfeed\r
- int inuse;\r
- int use_nwal; /* true if this is managed by nwal */\r
-#define PKTIO_4_IPC 0 //For IPC\r
-#define PKTIO_4_ADJ_NWAL 1 //(RX)app queues managed by NWAL\r
-#define PKTIO_DEF_NWAL 2 // default NWAL RX/TX queues\r
-#define PKTIO_4_ADJ_SB 3 //(RX) crypto side band app defined\r
-#define PKTIO_DEF_SB 4 //crypto side band default\r
- struct NETAPI_tag * back; /* back handle */\r
- void * nwalInstanceHandle; /* save here for conveninece */\r
- PKTIO_CB cb; /* callback for channel */\r
- PKTIO_CFG_T cfg; /* configuration */\r
- Qmss_QueueHnd q; /* the associated queue handle */\r
- Qmss_Queue qInfo; /* and its qm#/q# */\r
- int max_n; /* max # of pkts to read in one poll */\r
- void * cookie; /* app specific */\r
- PKTIO_SEND _send; /* pktio type specific send function */\r
- PKTIO_POLL _poll; /* pktio type specific POLL function */\r
- char name[PKTIO_MAX_NAME+1];\r
-} PKTIO_HANDLE_T;\r
-\r
-\r
-\r
-typedef struct PKTIO_CONTROL_Tag\r
-{\r
-#define PKTIO_CLEAR 0x1 //clear out the channel\r
-#define PKTIO_DIVERT 0x2 //divert, (to dest channel)\r
- int op;\r
- PKTIO_HANDLE_T *dest;\r
-} PKTIO_CONTROL_T;\r
-\r
-\r
-\r
-/*---------------------------------------------------*/\r
-/*-------------------------API-----------------------*/\r
-/*---------------------------------------------------*/\r
-\r
-/*\r
-* @brief API creates a NETAPI channel \r
- *\r
- * @details This assigns global resources to a NETAPI pktio channel.\r
- * Once created, the channel can be used to send and/or receive\r
- * a TI @ref Ti_Pkt. This can be used for communication with the \r
- * the Network co-processor (NETCP) or for internal inter-processor\r
- * communication. The channel is saved under the assigned name \r
- * and can be opened by other netapi threads instances.\r
- * @param[in] @ref NETAPI_T: handle to the instance \r
- * @param[in] char * name: a pointer to the char string name for channel\r
- * @param[in] @ref PKTIO_CB : callback to be issued on packet receive\r
- * @param[in] @ref PKTIO_CFG_T: pointer to channel configuration\r
- * @param[out] int * err: pointer to error return \r
- * @retval @ref PKTIO_HANDLE_T: handle to the pktio instance or NULL on error\r
- * @pre @ref netapi_init \r
- */\r
-PKTIO_HANDLE_T * pktio_create(NETAPI_T netapi_handle, /* netapi instance */\r
- char * name, /* name of the channel */\r
- PKTIO_CB cb, /* receive callback */\r
- PKTIO_CFG_T * p_cfg, /* ptr to config*/\r
- int * err);\r
-\r
-/*\r
-* @brief API opens an existing NETAPI channel\r
- *\r
- * @details This opens an NETAPI pktio channel for use. The channel\r
- * must have already been created via @ref pktio_create or may have\r
- * been created internally during the netapi intialization.\r
- * Once opened, the channel can be used to send and/or receive\r
- * a TI @ref Ti_Pkt. This can be used for communication with the \r
- * the Network co-processor (NETCP) or for internal inter-processor\r
- * communication. \r
- *\r
- * @param[in] @ref NETAPI_T: handle to the instance \r
- * @param[in] char * name: a pointer to the char string name for channel\r
- * @param[in] @ref PKTIO_CB : callback to be issued on packet receive\r
- * @param[in] @ref PKTIO_CFG_T: pointer to channel configuration\r
- * @param[out] int * err: pointer to error return\r
- * @retval @ref PKTIO_HANDLE_T: handle to the pktio instance or NULL on error\r
- * @pre @ref netapi_init , @ref pktio_create\r
- */\r
-PKTIO_HANDLE_T * pktio_open(NETAPI_T netapi_handle, /* netapi instance */\r
- char *name, /* name of channel to open */\r
- PKTIO_CB cb, /* receive callback */\r
- PKTIO_CFG_T *p_cfg, /* channel configuration */\r
- int * err);\r
-\r
-/* future: control the channel */\r
-void pktio_control(PKTIO_HANDLE_T * channel, //handle from open or create\r
- PKTIO_CB cb, //change the callback\r
- PKTIO_CFG_T * p_cfg,//optional \r
- PKTIO_CONTROL_T *p_control,//optional\r
- int *err);\r
- \r
-/* future: close or delete a pktio channel */\r
-void pktio_close(PKTIO_HANDLE_T * channel, int * err);\r
-void pktio_delete(PKTIO_HANDLE_T * channel, int * err);\r
-\r
-/*\r
-* @brief API sends data to a pktio channel \r
- *\r
- * @details This sends a @ref Ti_Pkt and associated meta data, \r
- * @ref PKTIO_METADATA_T to a channel. The channel\r
- * must have already been created via @ref pktio_create or opened\r
- * via @ref pktio_open. It may have\r
- * been created internally during the netapi intialization.\r
- * @param[in] @ref PKTIO_HANDLE_T: handle to the channel\r
- * @param[in] @ref Ti_Pkt*: pointer to the packet to send\r
- * @param[in] @ref PKTIO_METADATA_T: pointer to meta data associated with packet \r
- * @param[out] int * err: pointer to error return\r
- * @retval int npkts: 1 if packet sent, 0 if error \r
- * @pre @ref netapi_init, @ref pktio_create, @ref pktio_open\r
- */\r
-static inline int pktio_send(PKTIO_HANDLE_T * channel, /* the channel */\r
- Ti_Pkt *pkt, /* pointer to packet */\r
- PKTIO_METADATA_T *m, /* pointer to meta data */\r
- int * err)\r
-{\r
- return channel->_send((struct PKTIO_HANDLE_tag *)channel, pkt, m, err);\r
-}\r
-\r
-/*\r
-* @brief API sends data to a pktio channel\r
- *\r
- * @details This sends an array of @ref Ti_Pkt and associated meta data,\r
- * @ref PKTIO_METADATA_T to a channel. The channel\r
- * must have already been created via @ref pktio_create or opened\r
- * via @ref pktio_open. It may have\r
- * been created internally during the netapi intialization.\r
- * @param[in] @ref PKTIO_HANDLE_T: handle to the channel\r
- * @param[in] @ref Ti_Pkt*: pointer to the packet to send\r
- * @param[in] @ref PKTIO_METADATA_T: pointer to meta data associated with packet\r
- * @oaran[in[ int np: the number of packets in list to send\r
- * @param[out] int * err: pointer to error return\r
- * @retval int npkts: number of packets sent, 0 if error\r
- * @pre @ref netapi_init, @ref pktio_create, @ref pktio_open\r
- */\r
-int pktio_sendMulti(PKTIO_HANDLE_T *channel, /* the channel handle */\r
- Ti_Pkt * pkt[], /* array of packets to send */\r
- PKTIO_METADATA_T * m[], /* meta data array */\r
- int np, /* number of packets to send */\r
- int * err);\r
-\r
-/***********************************/\r
-/************* polling **************/\r
-/***********************************/\r
-\r
-/*\r
-* @brief API polls a pkto channel for received packets \r
- *\r
- * @details This api polls a pktio channel. Any pending data in the channel is\r
- * passed to the @ref PKTIO_CB registered when the channel was\r
- * created or opened. The channel must\r
- * have already been created via @ref pktio_create or opened\r
- * via @ref pktio_open. It may have\r
- * been created internally during the netapi intialization.\r
- * @param[in] @ref PKTIO_HANDLE_T: handle to the channel\r
- * @param[in] @ref PKTIO_POLL_T *: pointer to pktio poll configuration\r
- * @param[out] int * err: pointer to error return\r
- * @retval int npkts: number of packets received by poll \r
- * @pre @ref netapi_init, @ref pktio_create, @ref pktio_open\r
- */\r
-static inline int pktio_poll(PKTIO_HANDLE_T * handle, //handle to pktio\r
- PKTIO_POLL_T * p_poll_cfg, //polling configuration\r
- int * err)\r
-{\r
- handle->_poll((struct PKTIO_HANDLE_tag *) handle, p_poll_cfg, err);\r
-}\r
-\r
-/*\r
-* @brief API polls all pkto channels associarted with @ref NETAPI_T instance\r
- * for received packets\r
- *\r
- * @details This api polls all pktio channels attached to an instance.\r
- * Any pending data in these channels are \r
- * passed to the @ref PKTIO_CB registered when the channel was\r
- * created or opened. The channels must\r
- * have already been created via @ref pktio_create or opened\r
- * via @ref pktio_open. They may have\r
- * been created internally during the netapi intialization.\r
- * @param[in] @ref NETAPI_T: handle of the NETAPI instance \r
- * @param[in] @ref PKTIO_POLL_T *: pointer to pktio poll configuration\r
- * @param[out] int * err: pointer to error return\r
- * @retval int npkts: number of packets received by poll\r
- * @pre @ref netapi_init, @ref pktio_create, @ref pktio_open\r
- */\r
-int pktio_pollAll(NETAPI_T handle, PKTIO_POLL_T * p_poll_cfg, int *err);\r
-\r
-/*----------------- utilities------------------ */\r
-/* update max_n for poll */\r
-#define pktio_set_max_n(handle,max_n) (handle)->max_n=max_n;\r
-#define pktio_get_netapi_handle(handle) (handle)->back\r
-#define pktio_set_cookie(handle, cookie) (handle)->cookie = cookie\r
-#define pktio_get_cookie(handle) (handle)->cookie\r
-#define pktio_get_q(handle) (handle)->q\r
-\r
-/*-----------------Extra Fast Path pkt meta data macros--------------------*/\r
-#include "cppi_desc.h"\r
-#include "ti/drv/pa/pa.h"\r
-#include "ti/drv/pa/pasahost.h"\r
-\r
-\r
-//return default packet queue to poll for netcp RX\r
-//these are expensive calls, so call once and save\r
-static inline Qmss_QueueHnd PKTIO_GET_DEFAULT_NETCP_Q(PKTIO_HANDLE_T *h)\r
-{\r
-nwalGlobCxtInfo_t Info;\r
-nwal_getGlobCxtInfo(h->nwalInstanceHandle,&Info);\r
-return Info.rxDefPktQ;\r
-}\r
-\r
-//return L4Queue to poll for netcp RX (L4 classifier queue)\r
-//these are expensive calls, so call once and save\r
-static inline Qmss_QueueHnd PKTIO_GET_DEFAULT_NETCP_L4Q(PKTIO_HANDLE_T *h)\r
-{\r
-nwalLocCxtInfo_t Info;\r
-nwal_getLocCxtInfo(h->nwalInstanceHandle,&Info);\r
-return Info.rxL4PktQ;\r
-}\r
-\r
-\r
-\r
-static inline void PKTIO_QMSS_QUEUE_PUSH_DESC_SIZE_RAW(Qmss_QueueHnd hnd, void *descAddr, uint32_t descSize)\r
-{\r
- return(nwal_Qmss_queuePushDescSizeRaw(hnd,descAddr,descSize));\r
-}\r
-\r
-static inline void* PKTIO_QMSS_QUEUE_POP_RAW(Qmss_QueueHnd hnd)\r
-{\r
- return(nwal_Qmss_queuePopRaw(hnd));\r
-}\r
-\r
-//Return NWAL Global Instance\r
-static inline nwal_Inst PKTIO_GET_NWAL_INSTANCE(PKTIO_HANDLE_T *h)\r
-{\r
-return h->nwalInstanceHandle;\r
-}\r
-/* find pointer to proto info fields in descriptor */\r
-static inline pasahoLongInfo_t* PKTIO_GET_PROTO_INFO( Ti_Pkt * pkt)\r
-{\r
- uint32_t TEMPdataLen;\r
- return (pasahoLongInfo_t *) nwalCppi_getPSData ( Cppi_DescType_HOST,Cppi_PSLoc_PS_IN_DESC , (Cppi_Desc *)pkt, &TEMPdataLen);\r
-}\r
-\r
-/** "p" below is return of PKTIO_GET_PROTO_INFO() above**/\r
-\r
-/* offset to L3 header */\r
-#define PKTIO_GET_L3_OFFSET(p) PASAHO_LINFO_READ_L3_OFFSET(p)\r
-\r
-/* offset to L4 header */\r
-#define PKTIO_GET_L4_OFFSET(p) PASAHO_LINFO_READ_L4_OFFSET(p)\r
-\r
-/* next proto header */\r
-#define PKTIO_GET_NEXT_HEADER_TYPE(P) PASAHO_LINFO_READ_NXT_HDR_TYPE(p)\r
-\r
-/* offset to L4 payload */\r
-#define PKTIO_GET_L5_OFFSET(p) PASAHO_LINFO_READ_L5_OFFSET(p)\r
-\r
-/* end of L4 payload */\r
-#define PKTIO_GET_PAYLOAD_END(p) PASAHO_LINFO_READ_END_OFFSET(p)\r
-\r
-/* IPSEC ESP done ? */\r
-#define PKTIO_ESP_DONE(p) PASAHO_LINFO_IS_IPSEC_ESP(p)\r
-\r
-/* IPSEC ESP done ? */\r
-#define PKTIO_AH_DONE(p) PASAHO_LINFO_IS_IPSEC_AH(p)\r
-\r
-/* MAC info */\r
-#define PKTIO_IS_MAC_BROADCAST(p) PASAHO_READ_BITFIELD(p)\r
-#define PKTIO_IS_MAC_MULTICAST(p) PASAHO_READ_BITFIELD(p)\r
-#define PKTIO_GET_MAC_TYPE(p) PASAHO_LINFO_READ_MAC_PKTTYPE(p)\r
-\r
-/* read input port */\r
-#define PKTIO_GET_INPUT_PORT(p) PASAHO_LINFO_READ_INPORT(p) \r
-\r
-/* AppId */\r
-static inline unsigned int PKTIO_GET_APPID( Ti_Pkt * pkt) \r
-{\r
-unsigned char * p_swinfo0;\r
-Cppi_getSoftwareInfo (Cppi_DescType_HOST,\r
- (Cppi_Desc *)pkt,\r
- &p_swinfo0);\r
-return *((unsigned int *)p_swinfo0);\r
-} \r
-\r
-#endif\r
+/*********************************
+ *FILE: pktio.h
+ *PURPOSE: pktio library header
+ **************************************************************
+ * @file pktio.h
+ *
+ * @bried DESCRIPTION: pktio module main header file for user space transport
+ * library
+ *
+ * REVISION HISTORY: rev 0.0.1
+ *
+ * Copyright (c) Texas Instruments Incorporated 2010-2011
+ *
+ * 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.
+
+ ********************************/
+#ifndef __PKTIO__H
+#define __PKTIO__H
+#include "netapi.h"
+#include "ti/runtime/pktlib/pktlib.h"
+#include "ti/drv/nwal/nwal.h"
+#include "ti/drv/nwal/nwal_util.h"
+#include "netapi_err.h"
+
+/*--------------------defines-----------------------*/
+#define PKTIO_NOMEM NETAPI_ERR_NOMEM
+//default pktio channels
+#define NETCP_TX "NETCP_TX"
+#define NETCP_RX "NETCP_RX"
+#define NETCP_SB_RX "NETCP_SB_RX"
+#define NETCP_SB_TX "NETCP_SB_TX"
+#define PKTIO_MAX_NAME 19
+
+/*--------------------data structures----------------*/
+typedef struct PKTIO_METADATA_Tag
+{
+ int flags1;
+#define PKTIO_META_RX 0x01
+#define PKTIO_META_TX 0x02
+#define PKTIO_META_SB_RX 0x4 //SB crypto rx
+#define PKTIO_META_SB_TX 0x8 //SB crypto tx
+#define PKTIO_META_APP_DEF 0x80000000
+ union
+ {
+ nwalRxPktInfo_t * rx_meta;
+ nwalTxPktInfo_t * tx_meta;
+ nwalDmRxPayloadInfo_t * rx_sb_meta;
+ nwalDmTxPayloadInfo_t * tx_sb_meta;
+ } u;
+ void * sa_handle; //valid for PKTIO_META_TX with IPSEC inflow or PKTIO_PKTIO_META_SB_TX .
+ // MUST BE nwal_HANDLE_INVALID otherwise
+} PKTIO_METADATA_T;
+
+/* the callback function */
+struct PKTIO_HANDLE_tag;
+
+//polling control
+typedef struct PKTIO_POLL_Tag
+{
+/* future */
+} PKTIO_POLL_T;
+
+#define PKTIO_MAX_RECV (TUNE_NETAPI_MAX_BURST_RCV)
+typedef void (*PKTIO_CB)(struct PKTIO_HANDLE_tag * channel, Ti_Pkt* p_recv[],
+ PKTIO_METADATA_T p_meta[], int n_pkts,
+ uint64_t ts );
+
+typedef int (*PKTIO_SEND)(struct PKTIO_HANDLE_tag * channel, Ti_Pkt* p_send,
+ PKTIO_METADATA_T *p_meta, int * p_err);
+
+typedef int (*PKTIO_POLL)(struct PKTIO_HANDLE_tag * channel,PKTIO_POLL_T * p_poll_cfg ,
+ int * p_err);
+
+/** channel configuration */
+#define PKTIO_NA 0
+typedef struct PKTIO_CFG_Tag
+{
+#define PKTIO_R 0x1
+#define PKTIO_W 0x2
+#define PKTIO_RW (PKTIO_R | PKTIO_W)
+int flags1;
+
+#define PKTIO_LOCAL 0x2
+#define PKTIO_GLOBAL 0x1
+#define PKTIO_PKT 0x4 //define this if this channel is for NETCP
+#define PKTIO_SB 0x8 //define this if this channel is for sideband crypto
+int flags2;
+
+//for create
+#define PKTIO_Q_ANY -1
+int qnum;
+
+//for poll
+int max_n;
+}PKTIO_CFG_T;
+
+struct NETAPI_tag;
+
+/* a pktio channel .. */
+
+typedef struct PKTIO_HANDLE_Tag
+{
+#define PKTIO_INUSE 0xfeedfeed
+ int inuse;
+ int use_nwal; /* true if this is managed by nwal */
+#define PKTIO_4_IPC 0 //For IPC
+#define PKTIO_4_ADJ_NWAL 1 //(RX)app queues managed by NWAL
+#define PKTIO_DEF_NWAL 2 // default NWAL RX/TX queues
+#define PKTIO_4_ADJ_SB 3 //(RX) crypto side band app defined
+#define PKTIO_DEF_SB 4 //crypto side band default
+ struct NETAPI_tag * back; /* back handle */
+ void * nwalInstanceHandle; /* save here for conveninece */
+ PKTIO_CB cb; /* callback for channel */
+ PKTIO_CFG_T cfg; /* configuration */
+ Qmss_QueueHnd q; /* the associated queue handle */
+ Qmss_Queue qInfo; /* and its qm#/q# */
+ int max_n; /* max # of pkts to read in one poll */
+ void * cookie; /* app specific */
+ PKTIO_SEND _send; /* pktio type specific send function */
+ PKTIO_POLL _poll; /* pktio type specific POLL function */
+ char name[PKTIO_MAX_NAME+1];
+} PKTIO_HANDLE_T;
+
+
+
+typedef struct PKTIO_CONTROL_Tag
+{
+#define PKTIO_CLEAR 0x1 //clear out the channel
+#define PKTIO_DIVERT 0x2 //divert, (to dest channel)
+ int op;
+ PKTIO_HANDLE_T *dest;
+} PKTIO_CONTROL_T;
+
+
+
+/*---------------------------------------------------*/
+/*-------------------------API-----------------------*/
+/*---------------------------------------------------*/
+
+/*
+* @brief API creates a NETAPI channel
+ *
+ * @details This assigns global resources to a NETAPI pktio channel.
+ * Once created, the channel can be used to send and/or receive
+ * a TI @ref Ti_Pkt. This can be used for communication with the
+ * the Network co-processor (NETCP) or for internal inter-processor
+ * communication. The channel is saved under the assigned name
+ * and can be opened by other netapi threads instances.
+ * @param[in] @ref NETAPI_T: handle to the instance
+ * @param[in] char * name: a pointer to the char string name for channel
+ * @param[in] @ref PKTIO_CB : callback to be issued on packet receive
+ * @param[in] @ref PKTIO_CFG_T: pointer to channel configuration
+ * @param[out] int * err: pointer to error return
+ * @retval @ref PKTIO_HANDLE_T: handle to the pktio instance or NULL on error
+ * @pre @ref netapi_init
+ */
+PKTIO_HANDLE_T * pktio_create(NETAPI_T netapi_handle, /* netapi instance */
+ char * name, /* name of the channel */
+ PKTIO_CB cb, /* receive callback */
+ PKTIO_CFG_T * p_cfg, /* ptr to config*/
+ int * err);
+
+/*
+* @brief API opens an existing NETAPI channel
+ *
+ * @details This opens an NETAPI pktio channel for use. The channel
+ * must have already been created via @ref pktio_create or may have
+ * been created internally during the netapi intialization.
+ * Once opened, the channel can be used to send and/or receive
+ * a TI @ref Ti_Pkt. This can be used for communication with the
+ * the Network co-processor (NETCP) or for internal inter-processor
+ * communication.
+ *
+ * @param[in] @ref NETAPI_T: handle to the instance
+ * @param[in] char * name: a pointer to the char string name for channel
+ * @param[in] @ref PKTIO_CB : callback to be issued on packet receive
+ * @param[in] @ref PKTIO_CFG_T: pointer to channel configuration
+ * @param[out] int * err: pointer to error return
+ * @retval @ref PKTIO_HANDLE_T: handle to the pktio instance or NULL on error
+ * @pre @ref netapi_init , @ref pktio_create
+ */
+PKTIO_HANDLE_T * pktio_open(NETAPI_T netapi_handle, /* netapi instance */
+ char *name, /* name of channel to open */
+ PKTIO_CB cb, /* receive callback */
+ PKTIO_CFG_T *p_cfg, /* channel configuration */
+ int * err);
+
+/* future: control the channel */
+void pktio_control(PKTIO_HANDLE_T * channel, //handle from open or create
+ PKTIO_CB cb, //change the callback
+ PKTIO_CFG_T * p_cfg,//optional
+ PKTIO_CONTROL_T *p_control,//optional
+ int *err);
+
+/* future: close or delete a pktio channel */
+void pktio_close(PKTIO_HANDLE_T * channel, int * err);
+void pktio_delete(PKTIO_HANDLE_T * channel, int * err);
+
+/*
+* @brief API sends data to a pktio channel
+ *
+ * @details This sends a @ref Ti_Pkt and associated meta data,
+ * @ref PKTIO_METADATA_T to a channel. The channel
+ * must have already been created via @ref pktio_create or opened
+ * via @ref pktio_open. It may have
+ * been created internally during the netapi intialization.
+ * @param[in] @ref PKTIO_HANDLE_T: handle to the channel
+ * @param[in] @ref Ti_Pkt*: pointer to the packet to send
+ * @param[in] @ref PKTIO_METADATA_T: pointer to meta data associated with packet
+ * @param[out] int * err: pointer to error return
+ * @retval int npkts: 1 if packet sent, 0 if error
+ * @pre @ref netapi_init, @ref pktio_create, @ref pktio_open
+ */
+static inline int pktio_send(PKTIO_HANDLE_T * channel, /* the channel */
+ Ti_Pkt *pkt, /* pointer to packet */
+ PKTIO_METADATA_T *m, /* pointer to meta data */
+ int * err)
+{
+ return channel->_send((struct PKTIO_HANDLE_tag *)channel, pkt, m, err);
+}
+
+/*
+* @brief API sends data to a pktio channel
+ *
+ * @details This sends an array of @ref Ti_Pkt and associated meta data,
+ * @ref PKTIO_METADATA_T to a channel. The channel
+ * must have already been created via @ref pktio_create or opened
+ * via @ref pktio_open. It may have
+ * been created internally during the netapi intialization.
+ * @param[in] @ref PKTIO_HANDLE_T: handle to the channel
+ * @param[in] @ref Ti_Pkt*: pointer to the packet to send
+ * @param[in] @ref PKTIO_METADATA_T: pointer to meta data associated with packet
+ * @oaran[in[ int np: the number of packets in list to send
+ * @param[out] int * err: pointer to error return
+ * @retval int npkts: number of packets sent, 0 if error
+ * @pre @ref netapi_init, @ref pktio_create, @ref pktio_open
+ */
+int pktio_sendMulti(PKTIO_HANDLE_T *channel, /* the channel handle */
+ Ti_Pkt * pkt[], /* array of packets to send */
+ PKTIO_METADATA_T * m[], /* meta data array */
+ int np, /* number of packets to send */
+ int * err);
+
+/***********************************/
+/************* polling **************/
+/***********************************/
+
+/*
+* @brief API polls a pkto channel for received packets
+ *
+ * @details This api polls a pktio channel. Any pending data in the channel is
+ * passed to the @ref PKTIO_CB registered when the channel was
+ * created or opened. The channel must
+ * have already been created via @ref pktio_create or opened
+ * via @ref pktio_open. It may have
+ * been created internally during the netapi intialization.
+ * @param[in] @ref PKTIO_HANDLE_T: handle to the channel
+ * @param[in] @ref PKTIO_POLL_T *: pointer to pktio poll configuration
+ * @param[out] int * err: pointer to error return
+ * @retval int npkts: number of packets received by poll
+ * @pre @ref netapi_init, @ref pktio_create, @ref pktio_open
+ */
+static inline int pktio_poll(PKTIO_HANDLE_T * handle, //handle to pktio
+ PKTIO_POLL_T * p_poll_cfg, //polling configuration
+ int * err)
+{
+ handle->_poll((struct PKTIO_HANDLE_tag *) handle, p_poll_cfg, err);
+}
+
+/*
+* @brief API polls all pkto channels associarted with @ref NETAPI_T instance
+ * for received packets
+ *
+ * @details This api polls all pktio channels attached to an instance.
+ * Any pending data in these channels are
+ * passed to the @ref PKTIO_CB registered when the channel was
+ * created or opened. The channels must
+ * have already been created via @ref pktio_create or opened
+ * via @ref pktio_open. They may have
+ * been created internally during the netapi intialization.
+ * @param[in] @ref NETAPI_T: handle of the NETAPI instance
+ * @param[in] @ref PKTIO_POLL_T *: pointer to pktio poll configuration
+ * @param[out] int * err: pointer to error return
+ * @retval int npkts: number of packets received by poll
+ * @pre @ref netapi_init, @ref pktio_create, @ref pktio_open
+ */
+int pktio_pollAll(NETAPI_T handle, PKTIO_POLL_T * p_poll_cfg, int *err);
+
+/*----------------- utilities------------------ */
+/* update max_n for poll */
+#define pktio_set_max_n(handle,max_n) (handle)->max_n=max_n;
+#define pktio_get_netapi_handle(handle) (handle)->back
+#define pktio_set_cookie(handle, cookie) (handle)->cookie = cookie
+#define pktio_get_cookie(handle) (handle)->cookie
+#define pktio_get_q(handle) (handle)->q
+
+/*-----------------Extra Fast Path pkt meta data macros--------------------*/
+#include "cppi_desc.h"
+#include "ti/drv/pa/pa.h"
+#include "ti/drv/pa/pasahost.h"
+
+
+//return default packet queue to poll for netcp RX
+//these are expensive calls, so call once and save
+static inline Qmss_QueueHnd PKTIO_GET_DEFAULT_NETCP_Q(PKTIO_HANDLE_T *h)
+{
+nwalGlobCxtInfo_t Info;
+nwal_getGlobCxtInfo(h->nwalInstanceHandle,&Info);
+return Info.rxDefPktQ;
+}
+
+//return L4Queue to poll for netcp RX (L4 classifier queue)
+//these are expensive calls, so call once and save
+static inline Qmss_QueueHnd PKTIO_GET_DEFAULT_NETCP_L4Q(PKTIO_HANDLE_T *h)
+{
+nwalLocCxtInfo_t Info;
+nwal_getLocCxtInfo(h->nwalInstanceHandle,&Info);
+return Info.rxL4PktQ;
+}
+
+
+
+static inline void PKTIO_QMSS_QUEUE_PUSH_DESC_SIZE_RAW(Qmss_QueueHnd hnd, void *descAddr, uint32_t descSize)
+{
+ return(nwal_Qmss_queuePushDescSizeRaw(hnd,descAddr,descSize));
+}
+
+static inline void* PKTIO_QMSS_QUEUE_POP_RAW(Qmss_QueueHnd hnd)
+{
+ return(nwal_Qmss_queuePopRaw(hnd));
+}
+
+//Return NWAL Global Instance
+static inline nwal_Inst PKTIO_GET_NWAL_INSTANCE(PKTIO_HANDLE_T *h)
+{
+return h->nwalInstanceHandle;
+}
+/* find pointer to proto info fields in descriptor */
+static inline pasahoLongInfo_t* PKTIO_GET_PROTO_INFO( Ti_Pkt * pkt)
+{
- pasahoLongInfo_t* pinfo;
- uint32_t infoLen;
- Cppi_getPSData (Cppi_DescType_HOST, Cppi_PSLoc_PS_IN_DESC,(Cppi_Desc *)pkt, (uint8_t **)&pinfo, &infoLen);
- return pinfo;
++ uint32_t TEMPdataLen;
++ return (pasahoLongInfo_t *) nwalCppi_getPSData ( Cppi_DescType_HOST,Cppi_PSLoc_PS_IN_DESC , (Cppi_Desc *)pkt, &TEMPdataLen);
+}
+
+/** "p" below is return of PKTIO_GET_PROTO_INFO() above**/
+
+/* offset to L3 header */
+#define PKTIO_GET_L3_OFFSET(p) PASAHO_LINFO_READ_L3_OFFSET(p)
+
+/* offset to L4 header */
+#define PKTIO_GET_L4_OFFSET(p) PASAHO_LINFO_READ_L4_OFFSET(p)
+
+/* next proto header */
+#define PKTIO_GET_NEXT_HEADER_TYPE(P) PASAHO_LINFO_READ_NXT_HDR_TYPE(p)
+
+/* offset to L4 payload */
+#define PKTIO_GET_L5_OFFSET(p) PASAHO_LINFO_READ_L5_OFFSET(p)
+
+/* end of L4 payload */
+#define PKTIO_GET_PAYLOAD_END(p) PASAHO_LINFO_READ_END_OFFSET(p)
+
+/* IPSEC ESP done ? */
+#define PKTIO_ESP_DONE(p) PASAHO_LINFO_IS_IPSEC_ESP(p)
+
+/* IPSEC ESP done ? */
+#define PKTIO_AH_DONE(p) PASAHO_LINFO_IS_IPSEC_AH(p)
+
+/* MAC info */
+#define PKTIO_IS_MAC_BROADCAST(p) PASAHO_READ_BITFIELD(p)
+#define PKTIO_IS_MAC_MULTICAST(p) PASAHO_READ_BITFIELD(p)
+#define PKTIO_GET_MAC_TYPE(p) PASAHO_LINFO_READ_MAC_PKTTYPE(p)
+
+/* read input port */
+#define PKTIO_GET_INPUT_PORT(p) PASAHO_LINFO_READ_INPORT(p)
+
+/* AppId */
+static inline unsigned int PKTIO_GET_APPID( Ti_Pkt * pkt)
+{
+unsigned char * p_swinfo0;
+Cppi_getSoftwareInfo (Cppi_DescType_HOST,
+ (Cppi_Desc *)pkt,
+ &p_swinfo0);
+return *((unsigned int *)p_swinfo0);
+}
+
+#endif
diff --combined ti/runtime/netapi/src/netapi.c
index 2390ad1f8142a9c14349903b257024e1eb1207f4,e33585d3bdd4501ed0d9ec1a95318e08d86872de..bebb9201b028c11543ce9ea2b1e457012a4ce73e
-/*******************************\r
- * FILE: netapi.c\r
- * Purpose: implementation of netapi startup/shutdown\r
- **************************************************************\r
- * FILE: netapi.c\r
- * \r
- * DESCRIPTION: netapi main source file for user space transport\r
- * library\r
- * \r
- * REVISION HISTORY: rev 0.0.1 \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 <stdio.h>\r
-#include <stdlib.h>\r
-#include <unistd.h>\r
-#include <string.h>\r
-#include "netapi.h"\r
-\r
-typedef struct PRESET_Tag\r
-{\r
-#define KMAXQ 10\r
- int kqinuse[KMAXQ];\r
- //more..\r
-} PRESET_T;\r
-\r
-/*------------internal prototypes---------------*/\r
-static uint8_t* netapiSharedMemoryMalloc(uint32_t size);\r
-static void netapiSharedMemoryFree(uint8_t* ptr);\r
-static int system_init(NETAPI_HANDLE_T *);\r
-static void get_presets(PRESET_T * p_preset);\r
-static void netapi_cleanup_at_start(void);\r
-\r
-\r
-/*------------globals-----------------*/\r
-#define NUM_HOST_DESC (TUNE_NETAPI_NUM_LOCAL_DESC)\r
-#define SIZE_LOCAL_DESC (TUNE_NETAPI_DESC_SIZE) \r
-#define SIZE_SHARED_DESC (TUNE_NETAPI_DESC_SIZE)\r
-\r
-#define CONFIG_BUFSIZE_PA_INST 256\r
-#define CONFIG_BUFSIZE_L2_TABLE 1000\r
-#define CONFIG_BUFSIZE_L3_TABLE 4000\r
-\r
-static NETAPI_CFG_T netapi_default_cfg=\r
-{\r
-TUNE_NETAPI_PERM_MEM_SZ,\r
-0, //start of packet offset for hw to place data on rx for default flow\r
-TUNE_NETAPI_QM_CONFIG_MAX_DESC_NUM, //max number of descriptors in system\r
-TUNE_NETAPI_NUM_GLOBAL_DESC, //total we will use\r
-TUNE_NETAPI_DEFAULT_NUM_BUFFERS, //#descriptors+buffers in default heap\r
-TUNE_NETAPI_DEFAULT_NUM_SOLO_DESCRIPTORS, //#descriptors w/o buffers in default heap\r
-TUNE_NETAPI_DEFAULT_BUFFER_SIZE, //size of buffers in default heap\r
-0,0\r
-\r
-};\r
-\r
-static Pktlib_HeapIfTable netapi_pktlib_ifTable;\r
-static NETAPI_GLOBAL_T netapi_global;\r
-NETAPI_GLOBAL_T * netapi_get_global(){ return &netapi_global;}\r
-\r
-/* utility API for NETAPI user to get pktlib if table to use if he creates his own heap */\r
-Pktlib_HeapIfTable *netapi_getPktlibIfTable(void) {return &netapi_pktlib_ifTable;}\r
-\r
-//zap a queue\r
-void netapi_zapQ(int queueNum);\r
-/*-------------------------------------\r
- * initialize NETAPI instance \r
- *-------------------------------------*/\r
-NETAPI_T netapi_init(int master, NETAPI_CFG_T * p_cfg)\r
-{\r
- int i;\r
- int err;\r
- NETAPI_HANDLE_T * p = (NETAPI_HANDLE_T *) calloc(1,sizeof(NETAPI_HANDLE_T));\r
- if (!p) return NULL;\r
- p->master = master;\r
-\r
- /* create space for our local pktios */\r
- for(i=0;i<NETAPI_MAX_PKTIO; i++)\r
- {\r
- p->pktios[i] = calloc(1,sizeof(PKTIO_HANDLE_T));\r
- if (!p->pktios[i]) return NULL;\r
- }\r
-\r
-#ifdef NETAPI_INCLUDE_SCHED\r
- /* create space for scheduler */\r
- p->p_sched = calloc(1,sizeof(NETAPI_SCHED_HANDLE_T));\r
-#endif \r
-\r
-\r
- /* global stuff (if master) */\r
- if (master==NETAPI_SYS_MASTER)\r
- {\r
- if (p_cfg) memcpy(&netapi_global.cfg,p_cfg, sizeof(NETAPI_CFG_T));\r
- else memcpy(&netapi_global.cfg,&netapi_default_cfg, sizeof(NETAPI_CFG_T));\r
- for(i=0;i<NETAPI_MAX_PKTIO;i++) \r
- { \r
- netapi_global.pktios[i].qn.qNum=-1;\r
- netapi_global.pktios[i].name[0]='\0';\r
- }\r
- } \r
- //this goes to shared memory eventually\r
- p->global = (void *) &netapi_global;\r
-\r
-\r
- /* system init */\r
- if(master==NETAPI_SYS_MASTER)\r
- {\r
- err = system_init(p);\r
- if (err<0) \r
- {\r
- //todo: cleanup\r
- return NULL;\r
- }\r
- /* create pktio channels for tx,rx */\r
- }\r
- else\r
- {\r
- /*todo init for non-system cores/threads */\r
- /* qm_start, */\r
- /* attach to heaps */\r
- /* nwal_start */\r
- }\r
- \r
- return (NETAPI_T) p;\r
-}\r
-\r
-/*-------------------------------\r
- * Shut down netapi instance\r
- *-------------------------------*/\r
-void netapi_shutdown(NETAPI_T h)\r
-{\r
- int i;\r
- NETAPI_HANDLE_T * p = (NETAPI_HANDLE_T *) h;\r
- if (!p) return;\r
-\r
- printf(">netapi: WARNING shutdown may not be fully implemented\n");\r
- if (p->master)\r
- {\r
- /* close nwal */\r
- nwal_delete(netapi_global.nwal_context.nwalInstHandle);\r
-\r
- /* close heaps */\r
- netapi_closeHeap(h, p->netcp_heap);\r
- netapi_closeHeap(h, p->netcp_control_heap);\r
- netapi_closeHeap(h, netapi_get_global()->nwal_context.pa2sa_heap); \r
- netapi_closeHeap(h, netapi_get_global()->nwal_context.sa2pa_heap); \r
- \r
- //loop over registered heaps\r
- for(i=0;i<TUNE_NETAPI_MAX_HEAPS;i++)\r
- {\r
- if (p->createdHeaps[i]) {netapi_closeHeap(h,p->createdHeaps[i]);p->createdHeaps[i]=NULL;}\r
- }\r
- netapi_cleanup_at_start(); //clear 1st 50 not-specified queues..\r
- netapi_VM_memory_teardown();\r
- } \r
- free(p);\r
- return;\r
-}\r
-\r
-//exception crash\r
-void netapi_err_teardown() { netapi_cleanup_at_start(); exit(-99); }\r
-\r
-/*-------------------utilities-------------------*/\r
-static uint8_t* netapiSharedMemoryMalloc(uint32_t size)\r
-{\r
-return (uint8_t *)netapi_VM_memAlloc(size +netapi_global.cfg.def_heap_extra_size , 128); \r
-}\r
-\r
-static void netapiSharedMemoryFree(uint8_t* ptr)\r
-{\r
- /* Do Nothing. */\r
- printf(">netapi Unexpected. need to provide a free () for some reason!! \n");\r
- return;\r
-}\r
-\r
-// initialization\r
-static int system_init(NETAPI_HANDLE_T * handle) \r
-{\r
- int32_t result;\r
- Pktlib_HeapHandle sharedHeapHandle;\r
- Pktlib_HeapHandle controlHeapHandle; \r
- Pktlib_HeapCfg heapCfg;\r
- int32_t errCode;\r
-\r
- /* initialize all the memory we are going to use\r
- - chunk for buffers, descriptors\r
- - memory mapped peripherals we use, such as QMSS, PA, etc */\r
- result= netapi_VM_memory_setup();\r
- if (result) printf(">netapi: system init - memory set up OK\n");\r
- else {printf(">netap: system init - memory set up failed\n"); return -1;}\r
-\r
- //get timer running\r
- netapi_init_timer();\r
-\r
- /* Initialize Queue Manager Sub System */\r
- result = netapi_init_qm (netapi_global.cfg.def_max_descriptors); \r
- if (result != 1)\r
- {\r
- return -1;\r
- }\r
-\r
- /* Start the QMSS. */\r
- if (netapi_start_qm() != 1)\r
- {\r
- return -1;\r
- }\r
-\r
- //clean our old junk in 1st bunch of queues that will be allocated to us\r
- netapi_cleanup_at_start();\r
-\r
- /* Initialize the global descriptor memory region. */\r
- result= netapi_qm_setup_mem_region( \r
- netapi_global.cfg.def_tot_descriptors_for_us,\r
- SIZE_SHARED_DESC,\r
- (unsigned int *) netapi_VM_QMemGlobalDescRam,\r
- NETAPI_GLOBAL_REGION);\r
- if(result <0) {printf(">netapi; can't setup QM shared region\n"); return -1;}\r
-\r
-#if 0 //todo setup 2nd region\r
-/* Initialize the local memory region configuration. */\r
- result= netapi_qm_setup_mem_region( \r
- NUM_HOST_DESC,\r
- SIZE_LOCAL_DESC,\r
- netapi_VM_QMemLocalDescRam,\r
- NETAPI_LOCAL_REGION);\r
- if(result <0) {printf("can't setup local region\n"); return -1;}\r
-#endif\r
- /* Initialize CPPI CPDMA */\r
-\r
- result = netapi_init_cppi ();\r
- if (result != 1)\r
- {\r
- printf (">netapi: Error initializing CPPI SubSystem error code : %d\n",result);\r
- return -1;\r
- }\r
-\r
- /* CPPI and Queue Manager are initialized. */\r
- printf (">netapi: Queue Manager and CPPI are initialized.\n");\r
-\r
- /* create main pkt heap */\r
- /* Initialize the Shared Heaps. */\r
- Pktlib_sharedHeapInit();\r
-\r
- /* Populate the heap interface table. */\r
- netapi_pktlib_ifTable.data_malloc = netapiSharedMemoryMalloc;\r
- netapi_pktlib_ifTable.data_free = netapiSharedMemoryFree;\r
-\r
- /* Initialize the heap configuration. */\r
- memset ((void *)&heapCfg, 0, sizeof(Pktlib_HeapCfg));\r
- /* Populate the heap configuration */\r
- heapCfg.name = "netapi";\r
- heapCfg.memRegion = NETAPI_GLOBAL_REGION;\r
- heapCfg.sharedHeap = 1;\r
- heapCfg.useStarvationQueue = 0;\r
- heapCfg.dataBufferSize = netapi_global.cfg.def_heap_buf_size;\r
- heapCfg.numPkts = netapi_global.cfg.def_heap_n_descriptors;\r
- heapCfg.numZeroBufferPackets= netapi_global.cfg.def_heap_n_zdescriptors;\r
- heapCfg.heapInterfaceTable.data_malloc = netapi_pktlib_ifTable.data_malloc;\r
- heapCfg.heapInterfaceTable.data_free = netapi_pktlib_ifTable.data_free;\r
- heapCfg.dataBufferPktThreshold = 0;\r
- heapCfg.zeroBufferPktThreshold = 0;\r
-\r
- /* Create Shared Heap with specified configuration. */\r
- sharedHeapHandle = Pktlib_createHeap(&heapCfg, &errCode);\r
- //todo -> cleanup on failure\r
- if (!sharedHeapHandle) { printf(">'netapi' heap create failed, Error Code: %d\n",errCode); return -1;}\r
- handle->netcp_heap= sharedHeapHandle;\r
-\r
-\r
- /* Update for Control */\r
- heapCfg.name = "netapi_control";\r
- heapCfg.sharedHeap = 1;\r
- heapCfg.dataBufferSize = TUNE_NETAPI_CONFIG_MAX_CTL_RXTX_BUF_SIZE;\r
- heapCfg.numPkts = TUNE_NETAPI_CONFIG_NUM_CTL_BUF;\r
- heapCfg.numZeroBufferPackets= 0;\r
-\r
- controlHeapHandle = Pktlib_createHeap(&heapCfg, &errCode);;\r
- //todo -> cleanup on failure\r
- if (!controlHeapHandle) { printf(">netapi -'netapicontrol' heap create failed, Error Code: %d\n",errCode); return -1;}\r
- handle->netcp_control_heap= controlHeapHandle;\r
-\r
-\r
- /* now NWAL */\r
- result = netapi_init_nwal(\r
- NETAPI_GLOBAL_REGION,\r
- &netapi_pktlib_ifTable, \r
- &netapi_global.nwal_context,\r
- &netapi_global.cfg);\r
- if (result<0) {printf(">netapi init_nwal() failed\n"); return -1; }\r
-\r
- /* start NWAL */\r
- result = netapi_start_nwal(sharedHeapHandle, \r
- controlHeapHandle,\r
- &handle->nwal_local,\r
- &netapi_global.cfg,\r
- &netapi_global.nwal_context);\r
- if (result<0) {printf(">netapi start_nwal() failed\n"); return -1; }\r
- //** success **\r
-\r
-\r
- return 0;\r
-\r
-}\r
-\r
-\r
-/*---------------\r
- * get presets()\r
- *---------------*/\r
-static void get_presets(PRESET_T * p_preset)\r
-{\r
- /* read from kernel or overall config area */\r
- /* for now hard code what kernel did */\r
-}\r
-\r
-\r
-/*************************************************************\r
- ******************MISC INTERNAL******************************\r
-**************************************************************/\r
-/* poll the garbage queues of all registered heaps */\r
-void netapi_pollHeapGarbage(NETAPI_T h)\r
-{\r
-int i;\r
- NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) h;\r
- Pktlib_garbageCollection(n->netcp_heap);\r
- //no need to do garbage collection on other internal heaps\r
- for(i=0;i<TUNE_NETAPI_MAX_HEAPS;i++)\r
- {\r
- if (n->createdHeaps[i]) Pktlib_garbageCollection(n->createdHeaps[i]);\r
- }\r
-}\r
-\r
-/* poll NETCP control queue for responses */\r
-void netapi_netcpPoll(NETAPI_T p)\r
-{\r
- NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) p;\r
- nwal_pollCtl( ((NETAPI_GLOBAL_T *) (n->global))->nwal_context.nwalInstHandle,NULL,NULL);\r
-}\r
-\r
-/****************************************************************\r
- *****************Cleanup Functions******************************\r
-*****************************************************************/\r
-\r
-//clean up function for linux user space\r
-void netapi_zapQ(int queueNum)\r
-{\r
-char * descPtr;\r
-int i;\r
-if (!queueNum) return;\r
-for (i=0;;i+=1 )\r
- {\r
- /* Pop descriptor from source queue */\r
- if ((descPtr = (char *)Qmss_queuePop (queueNum)) == NULL)\r
- {\r
- break;\r
- }\r
- else {/*printf("netapi qzap in play\n");*/}\r
- }\r
- if(i) printf(">netapi: @recovery - %d descriptors cleaned from qn %d\n",i, queueNum);\r
-}\r
-\r
-//defensive: clean out stuff hanging around\r
-//\r
-// open a bunch of free queues and zap them\r
-#define NQUEUES2CLEAR 15\r
-static Qmss_QueueHnd tempQH[NQUEUES2CLEAR];\r
-static void netapi_cleanup_at_start(void)\r
-{\r
-int i;\r
-uint8_t isAllocated;\r
-\r
-for(i=0;i<NQUEUES2CLEAR;i++) \r
-{\r
- tempQH[i] = Qmss_queueOpen(Qmss_QueueType_GENERAL_PURPOSE_QUEUE,\r
- QMSS_PARAM_NOT_SPECIFIED, &isAllocated);\r
- netapi_zapQ(tempQH[i]);\r
-}\r
-\r
-for(i=0;i<NQUEUES2CLEAR;i++)\r
-{\r
- Qmss_queueClose(tempQH[i]);\r
-}\r
-\r
-}\r
-\r
-/********************************\r
- * clean up a pktlib heap\r
- ***********************************/\r
-int netapi_closeHeap(NETAPI_T h, Pktlib_HeapHandle p)\r
-{\r
-Qmss_QueueHnd q;\r
-Pktlib_garbageCollection(p); \r
-q = Pktlib_getZeroHeapQueue(p);\r
-netapi_zapQ(q);\r
-q= Pktlib_getInternalHeapQueue(p);\r
-netapi_zapQ(q);\r
-}\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
+/*******************************
+ * FILE: netapi.c
+ * Purpose: implementation of netapi startup/shutdown
+ **************************************************************
+ * FILE: netapi.c
+ *
+ * DESCRIPTION: netapi main source file for user space transport
+ * library
+ *
+ * REVISION HISTORY: rev 0.0.1
+ *
+ * Copyright (c) Texas Instruments Incorporated 2010-2011
+ *
+ * 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 <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);
+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
+
+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
+
+};
+
+static Pktlib_HeapIfTable netapi_pktlib_ifTable;
+static 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
+ *-------------------------------------*/
+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));
+ 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;
+ }
+
+#ifdef NETAPI_INCLUDE_SCHED
+ /* create space for scheduler */
+ p->p_sched = calloc(1,sizeof(NETAPI_SCHED_HANDLE_T));
+#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;
+
+
+ /* 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
+ {
+ /*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;
+
+ printf(">netapi: WARNING shutdown may not be fully implemented\n");
+ if (p->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, p->netcp_control_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..
+ netapi_VM_memory_teardown();
+ }
+ 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 *)netapi_VM_memAlloc(size, 128);
+}
+
+static void netapiSharedMemoryFree(uint8_t* ptr)
+{
+ /* 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_HeapHandle controlHeapHandle;
+ Pktlib_HeapCfg heapCfg;
+ int32_t errCode;
+
+ /* initialize all the memory we are going to use
+ - chunk for buffers, descriptors
+ - memory mapped peripherals we use, such as QMSS, PA, etc */
+ result= netapi_VM_memory_setup();
+ if (result) printf(">netapi: system init - memory set up OK\n");
+ else {printf(">netap: system init - memory set up failed\n"); return -1;}
+
+ //get timer running
+ netapi_init_timer();
+
+ /* Initialize Queue Manager Sub System */
+ result = netapi_init_qm (netapi_global.cfg.def_max_descriptors);
+ if (result != 1)
+ {
+ return -1;
+ }
+
+ /* Start the QMSS. */
+ if (netapi_start_qm() != 1)
+ {
+ return -1;
+ }
+
+ //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.name = "netapi_control";
+ heapCfg.sharedHeap = 1;
+ heapCfg.dataBufferSize = TUNE_NETAPI_CONFIG_MAX_CTL_RXTX_BUF_SIZE;
- heapCfg.numPkts = TUNE_NETAPI_CONFIG_NUM_CTL_RX_BUF;
++ heapCfg.numPkts = TUNE_NETAPI_CONFIG_NUM_CTL_BUF;
+ heapCfg.numZeroBufferPackets= 0;
+
- controlRxHeapHandle = Pktlib_createHeap(&heapCfg, &errCode);
++ controlHeapHandle = 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;
++ if (!controlHeapHandle) { printf(">netapi -'netapicontrol' heap create failed, Error Code: %d\n",errCode); return -1;}
++ handle->netcp_control_heap= controlHeapHandle;
+
-
- 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,
++ controlHeapHandle,
+ &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 */
+}
+
+
+/*************************************************************
+ ******************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)
+{
+ NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) p;
+ nwal_pollCtl( ((NETAPI_GLOBAL_T *) (n->global))->nwal_context.nwalInstHandle,NULL,NULL);
+}
+
+/****************************************************************
+ *****************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 )
+ {
+ /* Pop descriptor from source queue */
+ if ((descPtr = (char *)Qmss_queuePop (queueNum)) == NULL)
+ {
+ break;
+ }
+ else {/*printf("netapi qzap in play\n");*/}
+ }
+ 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
++#define NQUEUES2CLEAR 15
+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);
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --combined ti/runtime/netapi/src/netapi_init.c
index c64b58cf3abb4e600727e59a20a7b03780075d87,91fc87cd09e0f301caf493883cce99a3196e13b8..f06293d63b27b444648d9957462b651da6700722
-/************************************************\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, local initialization of NETAPI
+ *
+ * DESCRIPTION: Functions to initialize framework resources for running NETAPI
+ *
+ * REVISION HISTORY:
+ *
+ * Copyright (c) Texas Instruments Incorporated 2010-2011
+ *
+ * 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 <stdint.h>
+#include <stdio.h>
+#include <string.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>
+#include "netapi.h"
+#include "netapi_vm.h"
+#include "netapi_loc.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/csl/csl_cpsw_3gfAux.h>
+#include <ti/csl/csl_cpsw.h>
+#include <ti/csl/csl_cpsgmiiAux.h>
+#include <ti/drv/qmss/qmss_qm.h>
+//pull in device config for qmss, cppi
+#include <ti/drv/qmss/device/qmss_device.c>
+#include <ti/drv/cppi/device/cppi_device.c>
+
+/* TODO verify: */
+#define CACHE_LINESZ 64
+
+#define System_printf printf
+#define ALIGN(x) __attribute__((aligned (x)))
+
+/*****************************************************************************
+ * Global Resources shared by all Cores
+ *****************************************************************************/
+uint8_t *QMemGlobDescRam = 0;
+uint8_t *cppiMemPaSaLinkBuf = 0;
+uint8_t *cppiMemSaPaLinkBuf = 0;
+
+/*****************************************************************************
+ * Local Resource allocated at each Core
+ *****************************************************************************/
+/* Descriptors in global shared */
+uint8_t *QMemLocDescRam = NULL;
+uint8_t *cppiMemRxPktLinkBuf = NULL;
+uint8_t *cppiMemTxPktLinkBuf = NULL;
+uint8_t *cppiMemRxCtlLinkBuf = NULL;
+uint8_t *cppiMemTxCtlLinkBuf = NULL;
+
+
+//****************************************************
+// initialize CPSW (switch) [per SOC]
+//***************************************************
+int netapi_init_cpsw(void)
+{
+ CSL_CPSW_3GF_ALE_PORTCONTROL alePortControlCfg;
+
+ CSL_CPSW_3GF_clearAleTable();
+
+ alePortControlCfg.dropUntaggedEnable = 0;
+ alePortControlCfg.vidIngressCheckEnable = 0;
+
+ alePortControlCfg.mcastLimit = 0;
+ alePortControlCfg.bcastLimit = 0;
+
+ /* Disable learning mode for Port 0 */
+ alePortControlCfg.noLearnModeEnable = 1;
+ alePortControlCfg.portState = ALE_PORTSTATE_FORWARD;
+ CSL_CPSW_3GF_setAlePortControlReg (0, &alePortControlCfg);
+
+ /* Enable learning mode for Port 1 */
+ alePortControlCfg.noLearnModeEnable = 0;
+ alePortControlCfg.portState = ALE_PORTSTATE_FORWARD;
+ CSL_CPSW_3GF_setAlePortControlReg (1, &alePortControlCfg);
+
+ /* Enable learning mode for Port 2 */
+ alePortControlCfg.noLearnModeEnable = 0;
+ alePortControlCfg.portState = ALE_PORTSTATE_FORWARD;
+ CSL_CPSW_3GF_setAlePortControlReg (2, &alePortControlCfg);
+
+ return 1;
+}
+
+//****************************************************
+// initialize QM (per SOC)
+//***************************************************
+int netapi_init_qm(int max_descriptors)
+{
+ Qmss_InitCfg qmssInitConfig;
+ int32_t result;
+ Qmss_GlobalConfigParams nwalTest_qmssGblCfgParams;
+
+ memset (&qmssInitConfig, 0, sizeof (Qmss_InitCfg));
+
+ /* Use Internal Linking RAM for optimal performance */
+ qmssInitConfig.linkingRAM0Base = 0;
+ qmssInitConfig.linkingRAM0Size = 0;
+ qmssInitConfig.linkingRAM1Base = 0;
+ qmssInitConfig.maxDescNum = max_descriptors;
+ qmssInitConfig.qmssHwStatus =QMSS_HW_INIT_COMPLETE; //bypass some of the hw init
+ nwalTest_qmssGblCfgParams = qmssGblCfgParams[0];
+
+ nwalTest_qmssGblCfgParams.qmConfigReg = (void *)((uint8_t *)netapi_VM_qmssCfgVaddr +
+ (CSL_QM_SS_CFG_CONFIG_STARVATION_COUNTER_REGS - CSL_QM_SS_CFG_QUE_PEEK_REGS));
+ nwalTest_qmssGblCfgParams.qmDescReg = (void *)((uint32_t)netapi_VM_qmssCfgVaddr +
+ ((uint32_t)CSL_QM_SS_CFG_DESCRIPTION_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS);
+ nwalTest_qmssGblCfgParams.qmQueMgmtReg = (void *)((uint32_t)netapi_VM_qmssCfgVaddr +
+ ((uint32_t)CSL_QM_SS_CFG_QM_QUEUE_DEQUEUE_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS);
+ nwalTest_qmssGblCfgParams.qmQueMgmtProxyReg = (void *)((uint32_t)netapi_VM_qmssCfgVaddr +
+ ((uint32_t)CSL_QM_SS_CFG_PROXY_QUEUE_DEQUEUE_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS);
+ nwalTest_qmssGblCfgParams.qmQueStatReg = (void *)((uint32_t)netapi_VM_qmssCfgVaddr +
+ ((uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS);
+ nwalTest_qmssGblCfgParams.qmQueIntdReg = (void *)((uint32_t)netapi_VM_qmssCfgVaddr +
+ ((uint32_t)CSL_QM_SS_CFG_INTD_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS);
+ nwalTest_qmssGblCfgParams.qmPdspCmdReg[0] = (void *)((uint32_t)netapi_VM_qmssCfgVaddr +
+ ((uint32_t)CSL_QM_SS_CFG_SCRACH_RAM1_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS);
+ nwalTest_qmssGblCfgParams.qmPdspCmdReg[1] = (void *)((uint32_t)netapi_VM_qmssCfgVaddr +
+ ((uint32_t)CSL_QM_SS_CFG_SCRACH_RAM2_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS);
+ nwalTest_qmssGblCfgParams.qmPdspCtrlReg[0] = (void *)((uint32_t)netapi_VM_qmssCfgVaddr +
+ ((uint32_t)CSL_QM_SS_CFG_ADSP1_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS);
+ nwalTest_qmssGblCfgParams.qmPdspCtrlReg[1] = (void *)((uint32_t)netapi_VM_qmssCfgVaddr +
+ ((uint32_t)CSL_QM_SS_CFG_ADSP2_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS);
+ nwalTest_qmssGblCfgParams.qmPdspIRamReg[0] = (void *)((uint32_t)netapi_VM_qmssCfgVaddr +
+ ((uint32_t)CSL_QM_SS_CFG_APDSP1_RAM_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS);
+ nwalTest_qmssGblCfgParams.qmPdspIRamReg[1] = (void *)((uint32_t)netapi_VM_qmssCfgVaddr +
+ ((uint32_t)CSL_QM_SS_CFG_APDSP2_RAM_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS);
+ nwalTest_qmssGblCfgParams.qmStatusRAM = (void *)((uint32_t)netapi_VM_qmssCfgVaddr +
+ ((uint32_t)CSL_QM_SS_CFG_QM_STATUS_RAM_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS);
+ nwalTest_qmssGblCfgParams.qmLinkingRAMReg = (void *)((uint32_t)netapi_VM_qmssCfgVaddr +
+ ((uint32_t)CSL_QM_SS_CFG_LINKING_RAM_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS);
+ nwalTest_qmssGblCfgParams.qmMcDMAReg = (void *)((uint32_t)netapi_VM_qmssCfgVaddr +
+ ((uint32_t)CSL_QM_SS_CFG_MCDMA_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS);
+ nwalTest_qmssGblCfgParams.qmTimer16Reg[0] = (void *)((uint32_t)netapi_VM_qmssCfgVaddr +
+ ((uint32_t)CSL_QM_SS_CFG_TIMER1_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS);
+ nwalTest_qmssGblCfgParams.qmTimer16Reg[1] = (void *)((uint32_t)netapi_VM_qmssCfgVaddr +
+ ((uint32_t)CSL_QM_SS_CFG_TIMER2_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS);
+ nwalTest_qmssGblCfgParams.qmQueMgmtDataReg = (void *)((uint32_t)netapi_VM_qmssDataVaddr);
+ nwalTest_qmssGblCfgParams.qmQueMgmtProxyDataReg =
+ (void *)((uint32_t)netapi_VM_qmssDataVaddr + ((uint32_t)(0x44040000) - (uint32_t)(0x44020000)));
+
+ result = Qmss_init (&qmssInitConfig, &nwalTest_qmssGblCfgParams);
+ if (result != QMSS_SOK) {
+ System_printf (">function init_qm: qmss_Init failed with error code %d\n", result);
+ return (nwal_FALSE);
+ }
+
+ return 1;
+}
+
+//****************************************************
+// Set up QM memory region (per SOC)
+//***************************************************
+int netapi_qm_setup_mem_region(
+ uint32_t numDesc,
+ uint32_t descSize,
+ uint32_t* pDescMemBase,
+ Qmss_MemRegion memRegion)
+{
+ Qmss_MemRegInfo memInfo;
+ Int32 result;
+ Int n;
+ static int netapi_qm_region_index=0;
+
+ memset(&memInfo,0,sizeof(Qmss_MemRegInfo));
+ memInfo.descBase = pDescMemBase;
+ memInfo.descSize = descSize;
+ memInfo.descNum = numDesc;
+ memInfo.manageDescFlag = Qmss_ManageDesc_MANAGE_DESCRIPTOR;
+ memInfo.memRegion = memRegion;
+
+ if(memRegion == NETAPI_GLOBAL_REGION)
+ {
+ memInfo.startIndex = TUNE_NETAPI_QM_START_INDEX; //was 0
+ netapi_qm_region_index += numDesc;
+ }else if(memRegion ==NETAPI_LOCAL_REGION)
+ {
+ /* 2nd region for descriptors (perhaps private?) */
+ memInfo.startIndex = netapi_qm_region_index;
+ }
+ else
+ {
+ return -1 ;
+ }
+
+ memset (pDescMemBase, 0, (descSize * numDesc));
+
+ result = Qmss_insertMemoryRegion (&memInfo);
+ if (result < QMSS_SOK)
+ {
+ printf (">function setup_qm_region: Qmss_insertMemoryRegion returned error code %d\n", result);
+ return (-1);
+ }
+
+ return 1;
+
+}
+
+//****************************************************
+// Start QM (per thread)
+//***************************************************
+int netapi_start_qm(void)
+{
+ int32_t result;
+ result = Qmss_start();
+ if (result != QMSS_SOK)
+ {
+ System_printf (">start_qm: Qmss_start failed with error code %d\n", result);
+ return (-1);
+ }
+ return 1;
+}
+
+//*************************************************
+//initilaize CPPI (once per soc)
+//*************************************************
+int netapi_init_cppi(void)
+{
+ int32_t result, i;
+ Cppi_GlobalConfigParams nwalTest_cppiGblCfgParams[CPPI_MAX_CPDMA];
+
+ for (i=0; i<CPPI_MAX_CPDMA; i++)
+ nwalTest_cppiGblCfgParams[i] = cppiGblCfgParams[i];
+
+ /* SRIO CPDMA regs */
+ nwalTest_cppiGblCfgParams[Cppi_CpDma_SRIO_CPDMA].gblCfgRegs =
+ (void *)((uint32_t)netapi_VM_srioCfgVaddr +
+ (((uint32_t)CSL_SRIO_CONFIG_CPPI_DMA_GLOBAL_CFG_REGS) - (uint32_t)CSL_SRIO_CONFIG_REGS));
+ nwalTest_cppiGblCfgParams[Cppi_CpDma_SRIO_CPDMA].txChRegs =
+ (void *)((uint32_t)netapi_VM_srioCfgVaddr +
+ (((uint32_t)CSL_SRIO_CONFIG_CPPI_DMA_TX_CFG_REGS) - (uint32_t)CSL_SRIO_CONFIG_REGS));
+
+ nwalTest_cppiGblCfgParams[Cppi_CpDma_SRIO_CPDMA].rxChRegs =
+ (void *)((uint32_t)netapi_VM_srioCfgVaddr +
+ (((uint32_t)CSL_SRIO_CONFIG_CPPI_DMA_RX_CFG_REGS) - (uint32_t)CSL_SRIO_CONFIG_REGS));
+ nwalTest_cppiGblCfgParams[Cppi_CpDma_SRIO_CPDMA].txSchedRegs =
+ (void *)((uint32_t)netapi_VM_srioCfgVaddr +
+ (((uint32_t)CSL_SRIO_CONFIG_CPPI_DMA_TX_SCHEDULER_CFG_REGS) - (uint32_t)CSL_SRIO_CONFIG_REGS));
+ nwalTest_cppiGblCfgParams[Cppi_CpDma_SRIO_CPDMA].rxFlowRegs =
+ (void *)((uint32_t)netapi_VM_srioCfgVaddr +
+ (((uint32_t)CSL_SRIO_CONFIG_CPPI_DMA_RX_FLOW_CFG_REGS) - (uint32_t)CSL_SRIO_CONFIG_REGS));
+
+ /* PASS CPDMA regs */
+ nwalTest_cppiGblCfgParams[Cppi_CpDma_PASS_CPDMA].gblCfgRegs =
+ (void *)((uint32_t)netapi_VM_passCfgVaddr +
+ (((uint32_t)CSL_PA_SS_CFG_CPPI_DMA_GLOBAL_CFG_REGS) - (uint32_t)CSL_PA_SS_CFG_REGS));
+ nwalTest_cppiGblCfgParams[Cppi_CpDma_PASS_CPDMA].txChRegs =
+ (void *)((uint32_t)netapi_VM_passCfgVaddr +
+ (((uint32_t)CSL_PA_SS_CFG_CPPI_DMA_TX_CFG_REGS) - (uint32_t)CSL_PA_SS_CFG_REGS));
+ nwalTest_cppiGblCfgParams[Cppi_CpDma_PASS_CPDMA].rxChRegs =
+ (void *)((uint32_t)netapi_VM_passCfgVaddr +
+ (((uint32_t)CSL_PA_SS_CFG_CPPI_DMA_RX_CFG_REGS) - (uint32_t)CSL_PA_SS_CFG_REGS));
+ nwalTest_cppiGblCfgParams[Cppi_CpDma_PASS_CPDMA].txSchedRegs =
+ (void *)((uint32_t)netapi_VM_passCfgVaddr +
+ (((uint32_t)CSL_PA_SS_CFG_CPPI_DMA_TX_SCHEDULER_CFG_REGS) - (uint32_t)CSL_PA_SS_CFG_REGS));
+ nwalTest_cppiGblCfgParams[Cppi_CpDma_PASS_CPDMA].rxFlowRegs =
+ (void *)((uint32_t)netapi_VM_passCfgVaddr +
+ (((uint32_t)CSL_PA_SS_CFG_CPPI_DMA_RX_FLOW_CFG_REGS) - (uint32_t)CSL_PA_SS_CFG_REGS));
+ /* QMSS CPDMA regs */
+ nwalTest_cppiGblCfgParams[Cppi_CpDma_QMSS_CPDMA].gblCfgRegs =
+ (void *)((uint32_t)netapi_VM_qmssCfgVaddr +
+ (((uint32_t)CSL_QM_SS_CFG_CPPI_DMA_GLOBAL_CFG_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS));
+ nwalTest_cppiGblCfgParams[Cppi_CpDma_QMSS_CPDMA].txChRegs =
+ (void *)((uint32_t)netapi_VM_qmssCfgVaddr +
+ (((uint32_t)CSL_QM_SS_CFG_CPPI_DMA_TX_CFG_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS));
+ nwalTest_cppiGblCfgParams[Cppi_CpDma_QMSS_CPDMA].rxChRegs =
+ (void *)((uint32_t)netapi_VM_qmssCfgVaddr +
+ (((uint32_t)CSL_QM_SS_CFG_CPPI_DMA_RX_CFG_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS));
+ nwalTest_cppiGblCfgParams[Cppi_CpDma_QMSS_CPDMA].txSchedRegs =
+ (void *)((uint32_t)netapi_VM_qmssCfgVaddr +
+ (((uint32_t)CSL_QM_SS_CFG_CPPI_DMA_TX_SCHEDULER_CFG_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS));
+ nwalTest_cppiGblCfgParams[Cppi_CpDma_QMSS_CPDMA].rxFlowRegs =
+ (void *)((uint32_t)netapi_VM_qmssCfgVaddr +
+ (((uint32_t)CSL_QM_SS_CFG_CPPI_DMA_RX_FLOW_CFG_REGS) - (uint32_t)CSL_QM_SS_CFG_QUE_PEEK_REGS));
+
+ result = Cppi_init (nwalTest_cppiGblCfgParams);
+ if (result != CPPI_SOK)
+ {
+ printf (">function cppi_init: Cppi_init failed with error code %d\n", result);
+ return (-1);
+ }
+ return 1;
+}
+
+//*************************************************
+//initialize NWAL (one per soc)
+//*************************************************
+/*** NWAL Memory Buffer Configuration ***/
+#define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_HANDLE 3400
+uint8_t nwalInstMem[NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_HANDLE]ALIGN(CACHE_LINESZ);
+
+#define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_MAC 128
+#define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_IPSEC_HANDLE_PER_CHAN 256
+#define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_IP 128
+#define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_PORT 128
+#define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_L2L3_HDR 128
+#define NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_LOC_CONTEXT 384
+#define NWAL_CHAN_HANDLE_SIZE ((NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_MAC * TUNE_NETAPI_MAX_NUM_MAC) + \
+ (NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_IPSEC_HANDLE_PER_CHAN * TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS*2) + \
+ (NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_IP * TUNE_NETAPI_MAX_NUM_IP) + \
+ (NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_PORT * TUNE_NETAPI_MAX_NUM_PORTS)+ \
+ (NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_LOC_CONTEXT * TUNE_NETAPI_NUM_CORES) + \
+ (NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_PER_L2L3_HDR * TUNE_NETAPI_MAX_NUM_L2_L3_HDRS))
+
+uint8_t nwalHandleMem[NWAL_CHAN_HANDLE_SIZE]ALIGN(CACHE_LINESZ);
+
+/* todo: Check if below size information can be made available from pa interface file */
+#define NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF0 128
+/* PA instance */
+/* Memory used for the PA Instance. Needs to be assigned global uncached memory for chip */
+uint8_t paBuf0[NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF0]ALIGN(CACHE_LINESZ);
+
+/* Memory used for PA handles */
+#define NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF1 128
+uint8_t paBuf1[NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF1]ALIGN(CACHE_LINESZ);
+
+#define NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF2 768
+uint8_t paBuf2[NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF2]ALIGN(CACHE_LINESZ);
+
+/* Memory used for SA LLD global Handle */
+#define NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE 384
+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);
+
+
+/*******************************************
+ * Initialize the nwal subsystem for NETAPI use
+ ***********************************************/
+int netapi_init_nwal(
+ int region2use,
+ Pktlib_HeapIfTable * p_table,
+ NETAPI_NWAL_GLOBAL_CONTEXT_T * p_nwal_context,
+ NETAPI_CFG_T*p_cfg )
+{
+ nwalSizeInfo_t nwalSizeInfo;
+ nwalMemBuf_t nwalMemBuf[nwal_N_BUFS];
+ nwal_RetValue nwalRetVal;
+ nwalGlobCfg_t nwalGlobCfg;
+ uint8_t count;
+ int sizes[nwal_N_BUFS];
+ int aligns[nwal_N_BUFS];
+ void* bases[nwal_N_BUFS];
+ Pktlib_HeapCfg heapCfg;
+ int32_t errCode;
+
+ memset(p_nwal_context,0,sizeof( NETAPI_NWAL_GLOBAL_CONTEXT_T) );
+ memset(&nwalGlobCfg,0,sizeof(nwalGlobCfg_t ) );
+
+
+ /* Initialize Buffer Pool for NetCP PA to SA packets */
+ nwalGlobCfg.pa2SaBufPool.numBufPools = 1;
+ nwalGlobCfg.pa2SaBufPool.bufPool[0].descSize = TUNE_NETAPI_DESC_SIZE;
+ nwalGlobCfg.pa2SaBufPool.bufPool[0].bufSize = p_cfg->def_heap_buf_size;
+
+ /* Initialize the heap configuration. */
+ memset ((void *)&heapCfg, 0, sizeof(Pktlib_HeapCfg));
+ /* Populate the heap configuration */
+ heapCfg.name = "nwal PA2SA";
+ heapCfg.memRegion = region2use;
+ heapCfg.sharedHeap = 0;
+ heapCfg.useStarvationQueue = 0;
+ heapCfg.dataBufferSize = p_cfg->def_heap_buf_size;
+ heapCfg.numPkts = TUNE_NETAPI_CONFIG_MAX_PA_TO_SA_DESC;
+ heapCfg.numZeroBufferPackets= 0;
+ heapCfg.heapInterfaceTable.data_malloc = p_table->data_malloc;
+ heapCfg.heapInterfaceTable.data_free = p_table->data_free;
+ heapCfg.dataBufferPktThreshold = 0;
+ heapCfg.zeroBufferPktThreshold = 0;
+
+
+ nwalGlobCfg.pa2SaBufPool.bufPool[0].heapHandle = p_nwal_context->pa2sa_heap=
+ Pktlib_createHeap(&heapCfg, &errCode);
+ if(nwalGlobCfg.pa2SaBufPool.bufPool[0].heapHandle == NULL)
+ {
+ printf (">Pktlib_createHeap:Heap Creation Failed for PA to SA Buffer Pool , Error Code: %d\n",errCode);
+ netapi_err_teardown();
+ 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)
+ {
+ printf (">Pktlib_createHeap:Heap Creation Failed for SA to PA Buffer Pool , Error Code: %d\n",errCode);
+ netapi_err_teardown();
+ return -1;
+ }
+
+ nwalGlobCfg.hopLimit = 5;/* Default TTL / Hop Limit */
+ nwalGlobCfg.paPowerOn = nwal_TRUE;
+ nwalGlobCfg.saPowerOn = nwal_TRUE;
+ nwalGlobCfg.paFwActive = nwal_TRUE;
+ nwalGlobCfg.saFwActive = nwal_FALSE;
+
+ /* Pick Default Physical Address */
+ nwalGlobCfg.paVirtBaseAddr = (uint32_t) netapi_VM_passCfgVaddr;
+ nwalGlobCfg.saVirtBaseAddr = (uint32_t) netapi_VM_passCfgVaddr +
+ ((uint32_t)CSL_PA_SS_CFG_CP_ACE_CFG_REGS - (uint32_t)CSL_PA_SS_CFG_REGS) ;
+ nwalGlobCfg.rxDefPktQ = QMSS_PARAM_NOT_SPECIFIED;
+
+ /* Get the Buffer Requirement from NWAL */
+ memset(&nwalMemBuf,0,sizeof(nwalMemBuf));
+ 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;
+ for(count=0;count < nwal_N_BUFS;count++)
+ {
+ nwalMemBuf[count].cacheLineSize = CACHE_LINESZ;
+ }
+ nwalRetVal = nwal_getBufferReq(&nwalSizeInfo,
+ sizes,
+ aligns);
+ if(nwalRetVal != nwal_OK)
+ {
+ printf (">netapi: init_nwal - nwal_getBufferReq Failed %d\n", nwalRetVal);
+ return nwal_FALSE;
+ }
+
+/* Check for memory size requirement and update the base */
+ count = 0;
+ bases[nwal_BUF_INDEX_INST] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)nwalInstMem);
+ if(NETAPI_NWAL_CONFIG_BUFSIZE_NWAL_HANDLE < sizes[nwal_BUF_INDEX_INST])
+ {
+ /* Resize Memory */
+ while(1);
+ }
+ count++;
+
+ bases[nwal_BUF_INDEX_INT_HANDLES] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)nwalHandleMem);
+ if(NWAL_CHAN_HANDLE_SIZE < sizes[nwal_BUF_INDEX_INT_HANDLES])
+ {
+ /* Resize Memory */
+ while(1);
+ }
+ count++;
+ bases[nwal_BUF_INDEX_PA_LLD_BUF0] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)paBuf0);
+ if((NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF0) < sizes[nwal_BUF_INDEX_PA_LLD_BUF0])
+ {
+ /* Resize Memory */
+ while(1);
+ }
+ count++;
+
+ bases[nwal_BUF_INDEX_PA_LLD_BUF1] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)paBuf1);
+ if((NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF1) < sizes[nwal_BUF_INDEX_PA_LLD_BUF1])
+ {
+ /* Resize Memory */
+ while(1);
+ }
+ count++;
+
+ bases[nwal_BUF_INDEX_PA_LLD_BUF2] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)paBuf2);
+ if((NETAPI_NWAL_CONFIG_BUFSIZE_PA_BUF2) < sizes[nwal_BUF_INDEX_PA_LLD_BUF2])
+ {
+ /* Resize Memory */
+ while(1);
+ }
+ count++;
+#ifdef NETAPI_ENABLE_SECURITY
+ bases[nwal_BUF_INDEX_SA_LLD_HANDLE] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)salldHandle);
+ if((NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE) < sizes[nwal_BUF_INDEX_SA_LLD_HANDLE])
+ {
+ /* Resize Memory */
+ while(1);
+ }
+ count++;
+
+ bases[nwal_BUF_INDEX_SA_CONTEXT] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)netapi_VM_SaContextVaddr);
+ count++;
+
+ bases[nwal_BUF_INDEX_SA_LLD_CHAN_HANDLE] = (uint32_t *)Osal_nwalLocToGlobAddr((uint32_t)salldChanHandle);
+ if((NETAPI_NWAL_CONFIG_BUFSIZE_SA_LLD_HANDLE_PER_CHAN * TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS*2) <
+ sizes[nwal_BUF_INDEX_SA_LLD_CHAN_HANDLE])
+ {
+ /* Resize Memory */
+ while(1);
+ }
+ count++;
+#else
+ bases[nwal_BUF_INDEX_SA_LLD_HANDLE] = 0;
+ bases[nwal_BUF_INDEX_SA_CONTEXT] = 0;
+ bases[nwal_BUF_INDEX_SA_LLD_CHAN_HANDLE] = 0;
+ count = count+3;
+#endif
+ if(count != nwal_N_BUFS)
+ {
+ while(1);
+ }
+
+ /* Initialize NWAL module */
+ nwalRetVal = nwal_create(&nwalGlobCfg,
+ &nwalSizeInfo,
+ sizes,
+ bases,
+ &p_nwal_context->nwalInstHandle);
+ if(nwalRetVal != nwal_OK)
+ {
+ printf (">netapi: init_nwal- nwal_create Failed %d\n",nwalRetVal);
+ while(1);
+ }
+
+ printf(">netapi: init_nwal - Global and Local Network initialization Successful \n");
+ return 1;
+}
+
+//*************************************************
+//* Local (per thread/core) nwal initialization0
+//**************************************************
+int netapi_start_nwal(Pktlib_HeapHandle pkt_heap,
- Pktlib_HeapHandle cmd_rx_heap,
- Pktlib_HeapHandle cmd_tx_heap,
++ Pktlib_HeapHandle cmd_heap,
+ NETAPI_NWAL_LOCAL_CONTEXT_T *p,
+ NETAPI_CFG_T *p_cfg,
+ NETAPI_NWAL_GLOBAL_CONTEXT_T * p_nwal_glob_context )
+{
+ nwalLocCfg_t nwalLocCfg;
+ int count;
+ nwal_RetValue nwalRetVal;
+
+ memset(&nwalLocCfg,0,sizeof(nwalLocCfg));
+
+ /* Common Initialization for all cores */
+ while(count < TUNE_NETAPI_MAX_NUM_TRANS)
+ {
+ p_nwal_glob_context->transInfos[count].transId = count;
+ count++;
+ }
+
+ /* Update the Start of Packet Offset for the default flows created
+ * by NWAL
+ */
+ nwalLocCfg.rxSopPktOffset = p_cfg->def_flow_pkt_rx_offset;
+
+ /* Call back registration for the core */
+ nwalLocCfg.pRxPktCallBack = netapi_NWALRxPktCallback;
+ nwalLocCfg.pCmdCallBack = netapi_NWALCmdCallBack;
+ nwalLocCfg.pPaStatsCallBack = netapi_NWALCmdPaStatsReply;
+ nwalLocCfg.pRxDmCallBack= netapi_NWALSBPktCallback; //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;
++ nwalLocCfg.rxCtlPool.bufPool[0].heapHandle = cmd_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;
++ nwalLocCfg.txCtlPool.bufPool[0].heapHandle = cmd_heap;
+
+/* Initialize Buffer Pool for Packets from NetCP to Host */
+ nwalLocCfg.rxPktPool.numBufPools = 1;
+ nwalLocCfg.rxPktPool.bufPool[0].descSize = TUNE_NETAPI_DESC_SIZE;
+ nwalLocCfg.rxPktPool.bufPool[0].bufSize = TUNE_NETAPI_DEFAULT_BUFFER_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 = TUNE_NETAPI_DEFAULT_BUFFER_SIZE;
+ nwalLocCfg.txPktPool.bufPool[0].heapHandle = pkt_heap;
+
+ memcpy(&p->nwalLocCfg,&nwalLocCfg,sizeof(nwalLocCfg_t));
+ while(1)
+ {
+ nwalRetVal = nwal_start(p_nwal_glob_context->nwalInstHandle,&nwalLocCfg);
+ if(nwalRetVal == nwal_ERR_INVALID_STATE)
+ {
+ continue;
+ }
+ break;
+ }
+
+ if(nwalRetVal != nwal_OK)
+ {
+ printf (">nwal_start:Failed ->err %d !!!\n", nwalRetVal);
+ return -1;
+ }
+ p->state = NETAPI_NW_CXT_LOC_ACTIVE;
+ return 1;
+
+
+}
+//***************************************************
+// intialize timer
+//***************************************************
+int netapi_init_timer(void)
+{
+ return t64_start();
+}
+
+
diff --combined ti/runtime/netapi/src/netapi_vm.c
index d61ddc6acb06f6a8778842dd778f2ce43a7ce16d,6358745e5598b350c4210270846160b1aeedb989..cba24bedce4f271f9b0b50edf4317fcd007f2bb0
-\r
-/******************************************************************************\r
- * FILE netapi_vm.c\r
- * PURPOSE: Memory allocator for NETAPI and related utilities\r
- * -- using MSMC for descriptors/buffers (current), use CMA (future) \r
- ******************************************************************************\r
- * FILE NAME: netapi_vm.c\r
- *\r
- * DESCRIPTION: Memory allocator for netapi \r
- * This is only a permanent memory allocator.\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
-\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_vm.h"\r
-#include <sys/ioctl.h>\r
-#include "tools/module/netapimod.h"\r
-\r
-\r
-/***********************RAW MEMORY ALLOCATION & TRANSLATION*************************/\r
-/* Macro to align x to y */\r
-#define align(x,y) ((x + y) & (~y))\r
-\r
-#define NETAPI_PERM_MEM_SZ (TUNE_NETAPI_PERM_MEM_SZ) \r
-\r
-/* Physical address map & size for various subsystems */\r
-#define QMSS_CFG_BASE_ADDR CSL_QM_SS_CFG_QUE_PEEK_REGS\r
-#define QMSS_CFG_BLK_SZ (1*1024*1024)\r
-#define QMSS_DATA_BASE_ADDR 0x44020000 \r
-#define QMSS_DATA_BLK_SZ (0x60000)\r
-#define SRIO_CFG_BASE_ADDR CSL_SRIO_CONFIG_REGS\r
-#define SRIO_CFG_BLK_SZ (132*1024)\r
-#define PASS_CFG_BASE_ADDR CSL_PA_SS_CFG_REGS \r
-#define PASS_CFG_BLK_SZ (1*1024*1024)\r
-\r
-#define MSMC_SRAM_BASE_ADDR CSL_MSMC_SRAM_REGS\r
-uint8_t *netapi_VM_mem_start_phy = (uint8_t*)0;\r
-uint8_t *netapi_VM_mem_start = (uint8_t*)0;\r
-uint8_t *netapi_VM_mem_end = (uint8_t*)0;\r
-uint8_t *netapi_VM_mem_end_phy = (uint8_t*)0;\r
-static uint8_t *netapi_VM_mem_alloc_ptr = (uint8_t*)0;\r
-static uint32_t netapi_VM_mem_size = 0;\r
-\r
-\r
-/* File descriptor for /dev/mem */ \r
-static int dev_mem_fd;\r
-static int our_netapi_module_fd;\r
-#define USE_MODULE_MMAP //we will mmap through netapi kernel module, not /dev/mem\r
-#ifndef USE_MODULE_MMAP\r
-static int temp_fd;\r
-#endif\r
-\r
-//inialize the allocate area.\r
-nwal_Bool_t netapi_VM_memAllocInit\r
-(\r
- uint8_t *addr, /* Physical address */\r
- uint32_t size /* Size of block */\r
-)\r
-{\r
- void *map_base; \r
-\r
- //always open dev/mem, since we need for QM, CPPI, etc\r
- if((dev_mem_fd = open("/dev/mem", (O_RDWR | O_SYNC))) == -1)\r
- {\r
- printf(">netapi_VM_memAllocInit: Failed to open \"dev/mem\" err=%s\n",\r
- strerror(errno));\r
- return nwal_FALSE;\r
- }\r
-\r
-#ifdef NETAPI_USE_MSMC\r
- // memory map in addr to addr+size (msmc)\r
- map_base = netapi_VM_memMap ((void *)addr, size); \r
-\r
- if (!map_base)\r
- {\r
- printf(">netapi_VM_memAllocInit: Failed to mmap addr (0x%x)", addr);\r
- return nwal_FALSE;\r
- }\r
-\r
- printf(">netapi_VM_memAllocInit (uncached msmc) Phy Addr %x Memory (%d bytes) mapped at address %p.\n", addr,size, map_base); \r
-#else \r
- //use cached DDR. This requires NETAPI kernel module\r
- our_netapi_module_fd=netapi_utilModInit();\r
-\r
- if (our_netapi_module_fd == -1) {\r
- printf(">netapi_VM_memAllocInit: failed to open /dev/netapi: '%s'\n", strerror(errno));\r
- return nwal_FALSE;\r
- }\r
- addr= ( uint8_t *) netapi_utilGetPhysOfBufferArea(); //get address that was allocated for us by kernela module */\r
- size = netapi_utilGetSizeOfBufferArea(); //get the size that was allocated\r
-#ifdef USE_MODULE_MMAP\r
- map_base = (void *) netapi_utilGetVaOfBufferArea(NETAPIMOD_MMAP_DMA_MEM_OFFSET, size); //mmap into our space, return va\r
-#else\r
- if( (temp_fd = open("/dev/mem", O_RDWR )) == -1) {\r
- printf(">netapi_VM_memAllocInit: failed to open dev/mem again cached err=%d\n",errno);\r
- return nwal_FALSE; \r
- }\r
-\r
- map_base = mmap(0,size , PROT_READ | PROT_WRITE, MAP_SHARED, temp_fd, addr);\r
- if(map_base == (void *) -1) {\r
- printf(">netapi_VM_memAllocInit: failed to mmap CMA area at phy %x err=%d\n",\r
- addr, errno); \r
- return nwal_FALSE;\r
- }\r
-#endif\r
- printf(">netapi_VM_memAllocInit: (cached ddr) Phy Addr %x Memory (%d bytes) mapped at address %p.\n", addr,size, map_base); \r
-#endif\r
-\r
- netapi_VM_mem_alloc_ptr = netapi_VM_mem_start = map_base;\r
- netapi_VM_mem_size = size;\r
- netapi_VM_mem_end = netapi_VM_mem_start + netapi_VM_mem_size;\r
- netapi_VM_mem_start_phy = addr;\r
- netapi_VM_mem_end_phy = netapi_VM_mem_start_phy + netapi_VM_mem_size;\r
- return nwal_TRUE;\r
-}\r
-\r
-//utility to return free amount in buffer/descriptor area\r
-int netapi_getBufMemRemainder(void)\r
-{\r
- return (int) ((unsigned int) netapi_VM_mem_end) - ((unsigned int) netapi_VM_mem_alloc_ptr);\r
-}\r
-\r
-\r
-//------------------------------------------------------------------------\r
-//allocator function for our Buffer/Descriptor/SAcontext area (either MSMC\r
-//or kernel module provided CMA area in DDR\r
-//-----------------------------------------------------------------------\r
-void* netapi_VM_memAlloc\r
-(\r
- uint32_t size,\r
- uint32_t align\r
-)\r
-{\r
- uint32_t key;\r
- uint8_t *alloc_ptr;\r
- void *p_block =NULL;\r
-\r
- Osal_stubCsEnter();\r
- alloc_ptr = (uint8_t*)align((uint32_t)netapi_VM_mem_alloc_ptr, align);\r
- if ((alloc_ptr + size) < netapi_VM_mem_end)\r
- {\r
- p_block =(void *)alloc_ptr;\r
- netapi_VM_mem_alloc_ptr = alloc_ptr + size;\r
- Osal_stubCsExit(key);\r
- memset (p_block, 0, size);\r
- }\r
- else \r
- {\r
- Osal_stubCsExit(key);\r
- }\r
- return p_block;\r
-}\r
-uint32_t xtraLogs=0;\r
-/* Api to map the give physical address to virtual memory space */\r
-void *netapi_VM_memMap\r
-(\r
- void *addr, /* Physical address */\r
- uint32_t size /* Size of block */\r
-)\r
-{\r
- void *map_base,*virt_addr,*tmpAddr;\r
- uint32_t page_sz;\r
- long retval;\r
- uint32_t mask = (size-1);\r
- uint32_t offset;\r
-\r
- retval = sysconf(_SC_PAGE_SIZE);\r
- if (retval == -1)\r
- {\r
- printf(">netapi_VM_memMap: Failed to get page size err=%s\n",\r
- strerror(errno));\r
- return (void *)0;\r
- }\r
-\r
- page_sz = (uint32_t)retval;\r
-\r
- if (size%page_sz)\r
- {\r
- printf(">netapi_VM_memMap: error: block size not aligned to page size\n");\r
- return (void *)0;\r
- }\r
-\r
- if ((uint32_t)addr%page_sz)\r
- {\r
- printf(">netapi_VM_memMap: error: addr not aligned to page size\n");\r
- return (void *)0;\r
- }\r
-\r
- map_base = mmap(0, size, (PROT_READ|PROT_WRITE), MAP_SHARED, dev_mem_fd, (off_t)addr & ~mask);\r
- if(map_base == (void *) -1) \r
- {\r
- printf(">netapi_VM_memMap: Failed to mmap \"dev/mem\" err=%s\n",\r
- strerror(errno));\r
- return (void *)0;\r
- }\r
- virt_addr = map_base + ((off_t)addr & mask);\r
- if(xtraLogs)\r
- {\r
- printf(">netapi_VM_memMap:Memory mapped Begin Address 0x%x Read Value: 0x%x.\n", virt_addr,*((unsigned long *)virt_addr));\r
- // offset = size/(sizeof(unsigned long));\r
- // tmpAddr = (unsigned long *)virt_addr + offset-1;\r
- tmpAddr = (uint8_t *)virt_addr + 0x6800c;\r
- printf("netapi_VM_memMap:Memory mapped End Address 0x%x Read Value: 0x%x.\n", (unsigned long *)tmpAddr ,*((unsigned long *)tmpAddr));\r
- *((unsigned long *)tmpAddr) = 0x1234;\r
- printf("netapi_VM_memMap:Memory mapped End Address 0x%x Write Value: 0x%x.\n", (unsigned long *)tmpAddr ,*((unsigned long *)tmpAddr));\r
- \r
- }\r
- return(virt_addr);\r
-}\r
-\r
-/***************************************************************/\r
-/*************** Memory Initilaization**************************/\r
-/***************************************************************/\r
-/* for now use msmc */\r
-/* Total Permanent memory required in NWAL test\r
- * for Packet buffers & descriptor buffers\r
- */\r
-/* Global variables to hold virtual address of various subsystems */\r
-void *netapi_VM_qmssCfgVaddr;\r
-void *netapi_VM_qmssDataVaddr;\r
-void *netapi_VM_srioCfgVaddr;\r
-void *netapi_VM_passCfgVaddr;\r
-\r
-/* also for our descriptor area */\r
-unsigned char *netapi_VM_QMemLocalDescRam=NULL;\r
-unsigned char *netapi_VM_QMemGlobalDescRam=NULL;\r
-\r
-/* finaly SA context area */\r
-unsigned char *netapi_VM_SaContextVaddr=NULL;\r
-\r
-/************************************************\r
- * teardown VM memory\r
- ***********************************************/\r
-void netapi_VM_memory_teardown(void)\r
-{\r
- netapi_utilModClose();\r
- close(dev_mem_fd);\r
-#ifndef USE_MODULE_MMAP\r
- close(temp_fd);\r
-#endif\r
-}\r
-/*************************************************\r
- * setup VM memory\r
- ************************************************/\r
-int netapi_VM_memory_setup(void)\r
-{\r
-/* (1) big chunck of memory out of MSMC or DDR via kernel CMA */\r
-#ifdef NETAPI_USE_DDR\r
- if (netapi_VM_memAllocInit( NULL, 0) == nwal_FALSE) {\r
- printf(">netapi ERROR: netapi_V_MmemAllocInit from DDR/CMA failed\n");\r
- return (-1);\r
- }\r
-#else //uncached MSMC \r
- if (netapi_VM_memAllocInit((uint8_t*)MSMC_SRAM_BASE_ADDR,\r
- NETAPI_PERM_MEM_SZ) == nwal_FALSE) {\r
- printf(">netapi ERROR: netapi_V_MmemAllocInit from MSMC failed\n");\r
- return (-1);\r
- }\r
-#endif\r
-\r
- /* (2) Create virtual memory maps for peripherals */\r
- /* (2a) QMSS CFG Regs */\r
- netapi_VM_qmssCfgVaddr = netapi_VM_memMap((void*)QMSS_CFG_BASE_ADDR,\r
- QMSS_CFG_BLK_SZ);\r
- if (!netapi_VM_qmssCfgVaddr)\r
- {\r
- printf(">netapi ERROR: Failed to map QMSS CFG registers\n");\r
- return (-1);\r
- }\r
- printf(">netapi QMSS_CFG_BASE_ADDR:0x%x Memory mapped at address %p.\n",(void*)QMSS_CFG_BASE_ADDR, netapi_VM_qmssCfgVaddr);\r
-\r
- /* (2b) QMSS DATA Regs */\r
-#ifdef USE_MODULE_MMAP\r
- netapi_VM_qmssDataVaddr = (void *) netapi_utilGetVaOfBufferArea(NETAPIMOD_MMAP_QM_DATA_REG_MEM_OFFSET, QMSS_DATA_BLK_SZ);\r
-#else\r
- netapi_VM_qmssDataVaddr = netapi_VM_memMap((void*)QMSS_DATA_BASE_ADDR,\r
- QMSS_DATA_BLK_SZ);\r
-#endif\r
-\r
- if (!netapi_VM_qmssDataVaddr)\r
- {\r
- printf(">netapi ERROR: Failed to map QMSS DATA registers\n");\r
- return (-1);\r
- }\r
- printf(">netapi QMSS_DATA_BASE_ADDR:0x%x Memory mapped at address %p.\n",(void*)QMSS_DATA_BASE_ADDR, netapi_VM_qmssDataVaddr);\r
-\r
- /* (2c) SRIO CFG Regs */\r
- netapi_VM_srioCfgVaddr = netapi_VM_memMap((void*)SRIO_CFG_BASE_ADDR,\r
- SRIO_CFG_BLK_SZ);\r
- if (!netapi_VM_srioCfgVaddr)\r
- {\r
- printf(">netapi ERROR: Failed to map SRIO CFG registers\n");\r
- return (-1);\r
- }\r
- printf(">netapi SRIO_CFG_BASE_ADDR:0x%x Memory mapped at address %p.\n",(void*)SRIO_CFG_BASE_ADDR, netapi_VM_srioCfgVaddr);\r
-\r
- /* (2d) PASS CFG Regs */\r
- netapi_VM_passCfgVaddr = netapi_VM_memMap((void*)PASS_CFG_BASE_ADDR,\r
- PASS_CFG_BLK_SZ);\r
- if (!netapi_VM_passCfgVaddr)\r
- {\r
- printf(">netapi ERROR: Failed to map PASS CFG registers\n");\r
- return (-1);\r
- }\r
- printf(">netapi PASS_CFG_BASE_ADDR:0x%x Memory mapped at address %p.\n",(void*)PASS_CFG_BASE_ADDR, netapi_VM_passCfgVaddr);\r
-\r
- /* (2e) SA COntext area */\r
-#ifdef NETAPI_ENABLE_SECURITY\r
-#define SEC_CONTEXT_SZ 384 //not tunable\r
-/* allocate 2x number of tunnels since we need one for inflow and one for data mode */\r
- netapi_VM_SaContextVaddr = netapi_VM_memAlloc((TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS*2 *\r
- SEC_CONTEXT_SZ),\r
- 128);\r
- if (!netapi_VM_SaContextVaddr)\r
- {\r
- printf(">netapi ERROR: Failed to map SA context memory region\n");\r
- return (-1);\r
- }\r
- printf(">netapi VM_SaContext: Memory mapped/allocated at address %p.\n", netapi_VM_SaContextVaddr);\r
-\r
-#else\r
- netapi_VM_SaContextVaddr= (char *) NULL;\r
-#endif\r
-\r
- /* (2f) Timer */\r
- t64_memmap(dev_mem_fd);\r
-\r
- /* (3) Allocate 2 QM regions from continguous chunk above */\r
- netapi_VM_QMemGlobalDescRam = (void *)netapi_VM_memAlloc((TUNE_NETAPI_NUM_GLOBAL_DESC *\r
- TUNE_NETAPI_DESC_SIZE),\r
- 128);\r
- netapi_VM_QMemLocalDescRam = (void *)netapi_VM_memAlloc((TUNE_NETAPI_NUM_LOCAL_DESC *\r
- TUNE_NETAPI_DESC_SIZE),\r
- 128);\r
- printf(">netapi local desc region=%x global desc region=%x\n", netapi_VM_QMemLocalDescRam,netapi_VM_QMemGlobalDescRam);\r
-\r
- return 1;\r
-\r
-}\r
-\r
+
+/******************************************************************************
+ * FILE netapi_vm.c
+ * PURPOSE: Memory allocator for NETAPI and related utilities
+ * -- using MSMC for descriptors/buffers (current), use CMA (future)
+ ******************************************************************************
+ * FILE NAME: netapi_vm.c
+ *
+ * DESCRIPTION: Memory allocator for netapi
+ * This is only a permanent memory allocator.
+ *
+ * REVISION HISTORY:
+ *
+ * Copyright (c) Texas Instruments Incorporated 2010-2011
+ *
+ * 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 <stdint.h>
+#include <stdio.h>
+#include <string.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>
+#include "netapi_vm.h"
+#include <sys/ioctl.h>
+#include "tools/module/netapimod.h"
+
+
+/***********************RAW MEMORY ALLOCATION & TRANSLATION*************************/
+/* Macro to align x to y */
+#define align(x,y) ((x + y) & (~y))
+
+#define NETAPI_PERM_MEM_SZ (TUNE_NETAPI_PERM_MEM_SZ)
+
+/* Physical address map & size for various subsystems */
+#define QMSS_CFG_BASE_ADDR CSL_QM_SS_CFG_QUE_PEEK_REGS
+#define QMSS_CFG_BLK_SZ (1*1024*1024)
+#define QMSS_DATA_BASE_ADDR 0x44020000
+#define QMSS_DATA_BLK_SZ (0x60000)
+#define SRIO_CFG_BASE_ADDR CSL_SRIO_CONFIG_REGS
+#define SRIO_CFG_BLK_SZ (132*1024)
+#define PASS_CFG_BASE_ADDR CSL_PA_SS_CFG_REGS
+#define PASS_CFG_BLK_SZ (1*1024*1024)
+
+#define MSMC_SRAM_BASE_ADDR CSL_MSMC_SRAM_REGS
+uint8_t *netapi_VM_mem_start_phy = (uint8_t*)0;
+uint8_t *netapi_VM_mem_start = (uint8_t*)0;
+uint8_t *netapi_VM_mem_end = (uint8_t*)0;
+uint8_t *netapi_VM_mem_end_phy = (uint8_t*)0;
+static uint8_t *netapi_VM_mem_alloc_ptr = (uint8_t*)0;
+static uint32_t netapi_VM_mem_size = 0;
+
+
+/* File descriptor for /dev/mem */
+static int dev_mem_fd;
+static int our_netapi_module_fd;
+#define USE_MODULE_MMAP //we will mmap through netapi kernel module, not /dev/mem
+#ifndef USE_MODULE_MMAP
+static int temp_fd;
+#endif
+
++//inialize the allocate area.
+nwal_Bool_t netapi_VM_memAllocInit
+(
+ uint8_t *addr, /* Physical address */
+ uint32_t size /* Size of block */
+)
+{
+ void *map_base;
+
+ //always open dev/mem, since we need for QM, CPPI, etc
+ if((dev_mem_fd = open("/dev/mem", (O_RDWR | O_SYNC))) == -1)
+ {
+ printf(">netapi_VM_memAllocInit: Failed to open \"dev/mem\" err=%s\n",
+ strerror(errno));
+ return nwal_FALSE;
+ }
+
+#ifdef NETAPI_USE_MSMC
+ // memory map in addr to addr+size (msmc)
+ map_base = netapi_VM_memMap ((void *)addr, size);
+
+ if (!map_base)
+ {
+ printf(">netapi_VM_memAllocInit: Failed to mmap addr (0x%x)", addr);
+ return nwal_FALSE;
+ }
+
+ printf(">netapi_VM_memAllocInit (uncached msmc) Phy Addr %x Memory (%d bytes) mapped at address %p.\n", addr,size, map_base);
+#else
+ //use cached DDR. This requires NETAPI kernel module
+ our_netapi_module_fd=netapi_utilModInit();
+
+ if (our_netapi_module_fd == -1) {
+ printf(">netapi_VM_memAllocInit: failed to open /dev/netapi: '%s'\n", strerror(errno));
+ return nwal_FALSE;
+ }
+ addr= ( uint8_t *) netapi_utilGetPhysOfBufferArea(); //get address that was allocated for us by kernela module */
+ size = netapi_utilGetSizeOfBufferArea(); //get the size that was allocated
+#ifdef USE_MODULE_MMAP
+ map_base = (void *) netapi_utilGetVaOfBufferArea(NETAPIMOD_MMAP_DMA_MEM_OFFSET, size); //mmap into our space, return va
+#else
+ if( (temp_fd = open("/dev/mem", O_RDWR )) == -1) {
+ printf(">netapi_VM_memAllocInit: failed to open dev/mem again cached err=%d\n",errno);
+ return nwal_FALSE;
+ }
+
+ map_base = mmap(0,size , PROT_READ | PROT_WRITE, MAP_SHARED, temp_fd, addr);
+ if(map_base == (void *) -1) {
+ printf(">netapi_VM_memAllocInit: failed to mmap CMA area at phy %x err=%d\n",
+ addr, errno);
+ return nwal_FALSE;
+ }
+#endif
+ printf(">netapi_VM_memAllocInit: (cached ddr) Phy Addr %x Memory (%d bytes) mapped at address %p.\n", addr,size, map_base);
+#endif
+
+ netapi_VM_mem_alloc_ptr = netapi_VM_mem_start = map_base;
+ netapi_VM_mem_size = size;
+ netapi_VM_mem_end = netapi_VM_mem_start + netapi_VM_mem_size;
+ netapi_VM_mem_start_phy = addr;
+ netapi_VM_mem_end_phy = netapi_VM_mem_start_phy + netapi_VM_mem_size;
+ return nwal_TRUE;
+}
+
++//utility to return free amount in buffer/descriptor area
++int netapi_getBufMemRemainder(void)
++{
++ return (int) ((unsigned int) netapi_VM_mem_end) - ((unsigned int) netapi_VM_mem_alloc_ptr);
++}
++
++
++//------------------------------------------------------------------------
++//allocator function for our Buffer/Descriptor/SAcontext area (either MSMC
++//or kernel module provided CMA area in DDR
++//-----------------------------------------------------------------------
+void* netapi_VM_memAlloc
+(
+ uint32_t size,
+ uint32_t align
+)
+{
+ uint32_t key;
+ uint8_t *alloc_ptr;
+ void *p_block =NULL;
+
+ Osal_stubCsEnter();
+ alloc_ptr = (uint8_t*)align((uint32_t)netapi_VM_mem_alloc_ptr, align);
+ if ((alloc_ptr + size) < netapi_VM_mem_end)
+ {
+ p_block =(void *)alloc_ptr;
+ netapi_VM_mem_alloc_ptr = alloc_ptr + size;
+ Osal_stubCsExit(key);
+ memset (p_block, 0, size);
+ }
+ else
+ {
+ Osal_stubCsExit(key);
+ }
+ return p_block;
+}
+uint32_t xtraLogs=0;
+/* Api to map the give physical address to virtual memory space */
+void *netapi_VM_memMap
+(
+ void *addr, /* Physical address */
+ uint32_t size /* Size of block */
+)
+{
+ void *map_base,*virt_addr,*tmpAddr;
+ uint32_t page_sz;
+ long retval;
+ uint32_t mask = (size-1);
+ uint32_t offset;
+
+ retval = sysconf(_SC_PAGE_SIZE);
+ if (retval == -1)
+ {
+ printf(">netapi_VM_memMap: Failed to get page size err=%s\n",
+ strerror(errno));
+ return (void *)0;
+ }
+
+ page_sz = (uint32_t)retval;
+
+ if (size%page_sz)
+ {
+ printf(">netapi_VM_memMap: error: block size not aligned to page size\n");
+ return (void *)0;
+ }
+
+ if ((uint32_t)addr%page_sz)
+ {
+ printf(">netapi_VM_memMap: error: addr not aligned to page size\n");
+ return (void *)0;
+ }
+
+ map_base = mmap(0, size, (PROT_READ|PROT_WRITE), MAP_SHARED, dev_mem_fd, (off_t)addr & ~mask);
+ if(map_base == (void *) -1)
+ {
+ printf(">netapi_VM_memMap: Failed to mmap \"dev/mem\" err=%s\n",
+ strerror(errno));
+ return (void *)0;
+ }
+ virt_addr = map_base + ((off_t)addr & mask);
+ if(xtraLogs)
+ {
+ printf(">netapi_VM_memMap:Memory mapped Begin Address 0x%x Read Value: 0x%x.\n", virt_addr,*((unsigned long *)virt_addr));
+ // offset = size/(sizeof(unsigned long));
+ // tmpAddr = (unsigned long *)virt_addr + offset-1;
+ tmpAddr = (uint8_t *)virt_addr + 0x6800c;
+ printf("netapi_VM_memMap:Memory mapped End Address 0x%x Read Value: 0x%x.\n", (unsigned long *)tmpAddr ,*((unsigned long *)tmpAddr));
+ *((unsigned long *)tmpAddr) = 0x1234;
+ printf("netapi_VM_memMap:Memory mapped End Address 0x%x Write Value: 0x%x.\n", (unsigned long *)tmpAddr ,*((unsigned long *)tmpAddr));
+
+ }
+ return(virt_addr);
+}
+
+/***************************************************************/
+/*************** Memory Initilaization**************************/
+/***************************************************************/
+/* for now use msmc */
+/* Total Permanent memory required in NWAL test
+ * for Packet buffers & descriptor buffers
+ */
+/* Global variables to hold virtual address of various subsystems */
+void *netapi_VM_qmssCfgVaddr;
+void *netapi_VM_qmssDataVaddr;
+void *netapi_VM_srioCfgVaddr;
+void *netapi_VM_passCfgVaddr;
+
+/* also for our descriptor area */
+unsigned char *netapi_VM_QMemLocalDescRam=NULL;
+unsigned char *netapi_VM_QMemGlobalDescRam=NULL;
+
+/* finaly SA context area */
+unsigned char *netapi_VM_SaContextVaddr=NULL;
+
+/************************************************
+ * teardown VM memory
+ ***********************************************/
+void netapi_VM_memory_teardown(void)
+{
+ netapi_utilModClose();
+ close(dev_mem_fd);
+#ifndef USE_MODULE_MMAP
+ close(temp_fd);
+#endif
+}
+/*************************************************
+ * setup VM memory
+ ************************************************/
+int netapi_VM_memory_setup(void)
+{
+/* (1) big chunck of memory out of MSMC or DDR via kernel CMA */
+#ifdef NETAPI_USE_DDR
+ if (netapi_VM_memAllocInit( NULL, 0) == nwal_FALSE) {
+ printf(">netapi ERROR: netapi_V_MmemAllocInit from DDR/CMA failed\n");
+ return (-1);
+ }
+#else //uncached MSMC
+ if (netapi_VM_memAllocInit((uint8_t*)MSMC_SRAM_BASE_ADDR,
+ NETAPI_PERM_MEM_SZ) == nwal_FALSE) {
+ printf(">netapi ERROR: netapi_V_MmemAllocInit from MSMC failed\n");
+ return (-1);
+ }
+#endif
+
+ /* (2) Create virtual memory maps for peripherals */
+ /* (2a) QMSS CFG Regs */
+ netapi_VM_qmssCfgVaddr = netapi_VM_memMap((void*)QMSS_CFG_BASE_ADDR,
+ QMSS_CFG_BLK_SZ);
+ if (!netapi_VM_qmssCfgVaddr)
+ {
+ printf(">netapi ERROR: Failed to map QMSS CFG registers\n");
+ return (-1);
+ }
+ printf(">netapi QMSS_CFG_BASE_ADDR:0x%x Memory mapped at address %p.\n",(void*)QMSS_CFG_BASE_ADDR, netapi_VM_qmssCfgVaddr);
+
+ /* (2b) QMSS DATA Regs */
+#ifdef USE_MODULE_MMAP
+ netapi_VM_qmssDataVaddr = (void *) netapi_utilGetVaOfBufferArea(NETAPIMOD_MMAP_QM_DATA_REG_MEM_OFFSET, QMSS_DATA_BLK_SZ);
+#else
+ netapi_VM_qmssDataVaddr = netapi_VM_memMap((void*)QMSS_DATA_BASE_ADDR,
+ QMSS_DATA_BLK_SZ);
+#endif
+
+ if (!netapi_VM_qmssDataVaddr)
+ {
+ printf(">netapi ERROR: Failed to map QMSS DATA registers\n");
+ return (-1);
+ }
+ printf(">netapi QMSS_DATA_BASE_ADDR:0x%x Memory mapped at address %p.\n",(void*)QMSS_DATA_BASE_ADDR, netapi_VM_qmssDataVaddr);
+
+ /* (2c) SRIO CFG Regs */
+ netapi_VM_srioCfgVaddr = netapi_VM_memMap((void*)SRIO_CFG_BASE_ADDR,
+ SRIO_CFG_BLK_SZ);
+ if (!netapi_VM_srioCfgVaddr)
+ {
+ printf(">netapi ERROR: Failed to map SRIO CFG registers\n");
+ return (-1);
+ }
+ printf(">netapi SRIO_CFG_BASE_ADDR:0x%x Memory mapped at address %p.\n",(void*)SRIO_CFG_BASE_ADDR, netapi_VM_srioCfgVaddr);
+
+ /* (2d) PASS CFG Regs */
+ netapi_VM_passCfgVaddr = netapi_VM_memMap((void*)PASS_CFG_BASE_ADDR,
+ PASS_CFG_BLK_SZ);
+ if (!netapi_VM_passCfgVaddr)
+ {
+ printf(">netapi ERROR: Failed to map PASS CFG registers\n");
+ return (-1);
+ }
+ printf(">netapi PASS_CFG_BASE_ADDR:0x%x Memory mapped at address %p.\n",(void*)PASS_CFG_BASE_ADDR, netapi_VM_passCfgVaddr);
+
+ /* (2e) SA COntext area */
+#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 = netapi_VM_memAlloc((TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS*2 *
+ SEC_CONTEXT_SZ),
+ 128);
+ if (!netapi_VM_SaContextVaddr)
+ {
+ printf(">netapi ERROR: Failed to map SA context memory region\n");
+ return (-1);
+ }
+ printf(">netapi VM_SaContext: Memory mapped/allocated at address %p.\n", netapi_VM_SaContextVaddr);
+
+#else
+ netapi_VM_SaContextVaddr= (char *) NULL;
+#endif
+
+ /* (2f) Timer */
+ t64_memmap(dev_mem_fd);
+
+ /* (3) Allocate 2 QM regions from continguous chunk above */
+ netapi_VM_QMemGlobalDescRam = (void *)netapi_VM_memAlloc((TUNE_NETAPI_NUM_GLOBAL_DESC *
+ TUNE_NETAPI_DESC_SIZE),
+ 128);
+ netapi_VM_QMemLocalDescRam = (void *)netapi_VM_memAlloc((TUNE_NETAPI_NUM_LOCAL_DESC *
+ TUNE_NETAPI_DESC_SIZE),
+ 128);
+ printf(">netapi local desc region=%x global desc region=%x\n", netapi_VM_QMemLocalDescRam,netapi_VM_QMemGlobalDescRam);
+
+ return 1;
+
+}
+
diff --combined ti/runtime/netapi/test/net_test.c
index 3da0c35770450843e864a503c24fd08a255dc629,411bf889dbbcc11444a75a96fb6b3ea9fa24db24..d828a5635bdc5d68b3e07c0486b9360c3322cb64
-/******************************************\r
- * File: net_test.c\r
- * Purpose: test app for netapi\r
- **************************************************************\r
- * FILE: net_test.c\r
- * \r
- * DESCRIPTION: netapi user space transport\r
- * library test application\r
- * \r
- * REVISION HISTORY: rev 0.0.1 \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
-\r
-#include <stdio.h>\r
-#include <stdlib.h>\r
-#include <unistd.h>\r
-#include <string.h>\r
-\r
-\r
-#include "trie.h"\r
-#include "string.h"\r
-#include "netapi.h"\r
-#include "pktio.h"\r
-#include <sys/resource.h>\r
-\r
-//IPSEC MODE(only choose one rx and one tx)\r
-#define IPSEC_MODE_RX_INFLOW\r
-#define IPSEC_MODE_TX_INFLOW\r
-//#define IPSEC_MODE_RX_SIDEBAND\r
-//#define IPSEC_MODE_TX_SIDEBAND\r
-\r
-//#define TEST_TIMERS\r
-\r
-/*************debug********************/\r
-void dump_descr(unsigned long *p, int n)\r
-{\r
- printf("--------dump of descriptor %d %x\n", n, (int) p);\r
- printf("> %x %x %x %x %x %x %x %x\n",p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7]);\r
- printf("> %x %x %x %x %x %x %x %x\n",p[8],p[9],p[10],p[11],p[12],p[13],p[14],p[15]);\r
- printf("-----------------------------\n");\r
-}\r
-void dump_header(unsigned long *p, int n, int a, int r)\r
-{\r
- printf("--------dump of header %d %x appID=%x flag1=%x\n", n, (int) p,a,r);\r
- printf("> %x %x %x %x %x %x %x %x\n",p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7]);\r
- printf("> %x %x %x %x %x %x %x %x\n",p[8],p[9],p[10],p[11],p[12],p[13],p[14],p[15]);\r
- printf("> %x %x %x %x %x %x %x %x\n",p[16],p[17],p[18],p[19],p[20],p[21],p[22],p[23]);\r
- printf("> %x %x %x %x %x %x %x %x\n",p[24],p[25],p[26],p[27],p[28],p[29],p[30],p[31]);\r
- printf("-----------------------------\n");\r
-}\r
-\r
-/*****************************************/\r
-\r
-\r
-//************for multi pkt burst xfer test in loopback mode\r
-#define TX_BURST 800 \r
-int pktloopback=TUNE_NETAPI_NWAL_ENABLE_PASS_LOOPBACK;\r
-nwalTxPSCmdInfo_t flowPSCmdInfo;\r
-\r
-//this device: 10.0.0.100, mac 0x,01,02,03,04,05 and .. 0x6\r
-\r
-//test packet, setup for loopback (so dest is ourself)\r
-static uint8_t testPkt[] = {\r
-\r
- /* MAC header */\r
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,\r
- 0x00, 0xe0, 0xa6, 0x66, 0x57, 0x04,\r
- 0x08, 0x00,\r
-\r
- /* IP header */\r
- 0x45, 0x00,\r
- 0x00, 0x6c, /* Length (including this header) */\r
- 0x00, 0x00, 0x00, 0x00, 0x05, 0x11,\r
- 0x00, 0x00, /* Header checksum */\r
- 0x0a, 0x00, 0x00, 0x0a, 0x0a, 0x00, 0x00, 0x64,\r
-\r
- /* UDP header */\r
- 0x12, 0x34, 0x05, 0x55,\r
- 0x00, 0x58, /* Length, including this header */\r
- 0x00, 0x00, /* Header checksum */\r
-\r
- /* Payload */\r
- 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,\r
- 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41,\r
- 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,\r
- 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51,\r
- 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,\r
- 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61,\r
- 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,\r
- 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71,\r
- 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,\r
- 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81\r
-\r
-};\r
-\r
-#define TEST_PAYLOAD_LEN 80\r
-\r
-#define TEST_PKT_IP_OFFSET_BYTES 14\r
-#define TEST_PKT_UDP_OFFSET_BYTES 34\r
-#define TEST_PKT_PLOAD_OFFSET_BYTES 42\r
-#define TEST_PKT_UDP_HDR_LEN 8\r
-/* Offsets to length fields */\r
-#define TEST_PKT_OFFSET_IP_LEN 16\r
-#define TEST_PKT_OFFSET_UDP_LEN 38\r
-\r
-#define TEST_PKT_LEN 122\r
-\r
-/* The pseudo header checksum of the packet except for the 16 bit length */\r
-#define TEST_PKT_PSEUDO_HDR_CHKSUM_SANS_LEN 0x0FFC\r
-\r
-void example_fast_poll( PKTIO_HANDLE_T * p_pktio);\r
-\r
-#if 1\r
-//#include "arpa/inet.h"\r
-long htonl(long x)\r
-{\r
- long temp = (x&0xff000000)>>24 | (x&0xff0000)>>8 | (x&0xff00)<<8 | (x&0xff)<<24 ;\r
- return temp;\r
-}\r
-\r
-/********************************************************************\r
- * FUNCTION PURPOSE: Ones complement addition utility\r
- ********************************************************************\r
- ********************************************************************/\r
-uint16_t test_utilOnesComplementAdd (uint16_t v1, uint16_t v2)\r
-{\r
- uint32_t result;\r
-\r
- result = (uint32_t)v1 + (uint32_t)v2;\r
- result = (result >> 16) + (result & 0xffff);\r
- result = (result >> 16) + (result & 0xffff);\r
-\r
- return ((uint16_t)result);\r
-}\r
-\r
-/********************************************************************\r
- * FUNCTION PURPOSE: Ones complement checksum utility\r
- ********************************************************************\r
- ********************************************************************/\r
- uint16_t test_utilOnesCompChkSum (uint8_t *p, uint32_t nwords)\r
-{\r
- uint16_t chksum = 0;\r
- uint16_t v;\r
- uint32_t i;\r
- uint32_t j;\r
-\r
- for (i = j = 0; i < nwords; i++, j+=2) {\r
- v = (p[j] << 8) | p[j+1];\r
- chksum = test_utilOnesComplementAdd (chksum, v);\r
- }\r
- return (chksum);\r
-} /* utilOnesCompChkSum */\r
-\r
-/**************************************************************************************\r
- * FUNCTION PURPOSE: Compute ipv4 psudo checksum\r
- **************************************************************************************\r
- * DESCRIPTION: Compute ipv4 psudo checksum\r
- **************************************************************************************/\r
-uint16_t test_utilGetIpv4PsudoChkSum (uint8_t *data, uint16_t payloadLen)\r
-{\r
- uint16_t psudo_chksum;\r
-\r
- psudo_chksum = test_utilOnesCompChkSum (&data[12], 4);\r
- psudo_chksum = test_utilOnesComplementAdd(psudo_chksum, (uint16_t) data[9]);\r
- psudo_chksum = test_utilOnesComplementAdd(psudo_chksum, payloadLen);\r
-\r
- return (psudo_chksum);\r
-\r
-} /* utilGetIpv4PsudoChkSum */\r
-\r
-\r
-\r
-#endif\r
-typedef struct stats_t\r
-{\r
- long itx; //initially generated\r
- long itx2;\r
- long rx;\r
- long tx;\r
- long n_bad;\r
- long n_new;\r
- long n_class0_rx; //count of pkts classified \r
- long n_class1_rx; //count of pkts classified \r
- long n_class2_rx; //count of pkts classified \r
- long n_t1;\r
- long n_t2;\r
- long n_t3;\r
- long sec_tx;\r
- long sec_rx;\r
- long sb_tx;\r
- long sb_rx;\r
- long secp_rx;\r
- long n_auth_ok;\r
-} STATS_T;\r
-\r
-typedef struct head_t\r
-{\r
- long ip[5];\r
- long udp[2];\r
-} HEAD_T;\r
-\r
-typedef struct key_t\r
-{\r
- long src_ip;\r
- long dst_ip;\r
- short src_port;\r
- short dst_port;\r
-} KEY_T;\r
-\r
-unsigned char mac0[]={0x00,0x01,0x02,0x03,0x04,0x05}; //interface 0\r
-unsigned char mac1[]={0x00,0x01,0x02,0x03,0x04,0x06}; //interface 1\r
-nwalIpAddr_t OurIp0={ 10, 0, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };\r
-nwalIpAddr_t OurIp1={ 10, 0, 1, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };\r
-nwalIpAddr_t OurIp2={ 10, 0, 2, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };\r
-nwalIpAddr_t OurIp4IPSEC={ 192,168 , 1, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };\r
-nwalIpAddr_t TheirIp4IPSEC={ 192,168 , 1, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };\r
-\r
-\r
-#if 1 //goes with real tx (to laptop) \r
-unsigned char real_mac_header[]={0xd4,0xbe,0xd9,0x00,0xd3,0x7e,\r
- 0x00,0x01,0x02,0x03,0x04,0x05,\r
- 0x08,0x00};\r
-unsigned char real_ip_addr[]={0xa,0x00,0x00,0x64,0xa,0x0,0x0,0xa};\r
-#endif\r
-\r
-#if 0 //goes with loopback\r
-unsigned char mac_header[]={0x00,0x01,0x02,0x03,0x04,0x05, \r
- 0x00,0x11,0x22,0x33,0x44,0x55,\r
- 0x08,0x00};\r
-#endif\r
-#define NE 65536 \r
-HEAD_T *nat;\r
-\r
-#define NP 5000\r
-int n_pkt = NP;\r
-STATS_T stats;\r
-\r
-Trie * P_trie;\r
-HEAD_T pkts[NP];\r
-#define PERSLOW 10 //% of pkts that will not be fastpath'd \r
-int perslow= PERSLOW;\r
-\r
-/*******************************************\r
- *************NETAPI OBJECTS***************\r
- *****************************************/\r
-static NETAPI_CFG_T our_netapi_default_cfg=\r
-{\r
-TUNE_NETAPI_PERM_MEM_SZ,\r
-128, //start of packet offset for hw to place data on rx for default flow\r
-TUNE_NETAPI_QM_CONFIG_MAX_DESC_NUM, //max number of descriptors in system\r
-TUNE_NETAPI_NUM_GLOBAL_DESC, //total we will use\r
-TUNE_NETAPI_DEFAULT_NUM_BUFFERS, //#descriptors+buffers in default heap\r
-64, //#descriptors w/o buffers in default heap\r
-TUNE_NETAPI_DEFAULT_BUFFER_SIZE+128+128, //size of buffers in default heap\r
-128 , //tail room\r
-256 //extra room \r
-};\r
-\r
-Pktlib_HeapHandle OurHeap;\r
-Pktlib_HeapHandle specialSmall;\r
-Pktlib_HeapHandle specialLarge;\r
-\r
-PKTIO_HANDLE_T *our_chan;\r
-PKTIO_HANDLE_T *netcp_rx_chan;\r
-PKTIO_HANDLE_T *netcp_rx_chan2;\r
-PKTIO_HANDLE_T *netcp_tx_chan;\r
-PKTIO_HANDLE_T *netcp_sb_tx_chan;\r
-PKTIO_HANDLE_T *netcp_sb_rx_chan;\r
-PKTIO_CFG_T our_chan_cfg={PKTIO_RW, PKTIO_LOCAL, PKTIO_Q_ANY, 8};\r
-PKTIO_CFG_T netcp_rx_cfg={PKTIO_R, PKTIO_NA, PKTIO_NA, 8};\r
-PKTIO_CFG_T netcp_rx_cfg2={PKTIO_R, (PKTIO_GLOBAL|PKTIO_PKT), PKTIO_Q_ANY, 8};\r
-PKTIO_CFG_T netcp_tx_cfg={PKTIO_W, PKTIO_NA, PKTIO_NA, 8};\r
-PKTIO_CFG_T netcp_sb_rx_cfg={PKTIO_R, PKTIO_NA, PKTIO_NA, 8};\r
-PKTIO_CFG_T netcp_sb_tx_cfg={PKTIO_W, PKTIO_NA, PKTIO_NA, 8};\r
-\r
-void house(NETAPI_SCHED_HANDLE_T *s);\r
-NETAPI_T netapi_handle;\r
-NETAPI_SCHED_HANDLE_T * our_sched;\r
-NETAPI_SCHED_CONFIG_T our_sched_cfg={\r
- NETAPI_SCHED_DURATION|NETAPI_SCHED_CBV, 0, house, 50000 //every 5000 poll loops\r
-};\r
-void our_stats_cb(NETAPI_T h, paSysStats_t* pPaStats);\r
-NETAPI_TIMER_GROUP_HANDLE_T ourTimerBlock; \r
-NETAPI_TIMER_T t1;\r
-NETAPI_TIMER_T t2;\r
-NETAPI_TIMER_T t3;\r
-\r
-void our_timer_cb( NETAPI_TIMER_GROUP_HANDLE_T th,\r
- int n_fired, //# timers fired\r
- NETAPI_TIMER_LIST_T fired_list,\r
- uint64_t currentTime);\r
-\r
-NETCP_CFG_IP_T ip_rule0;\r
-NETCP_CFG_IP_T ip_rule1;\r
-NETCP_CFG_CLASS_T class_0;\r
-NETCP_CFG_CLASS_T class_1;\r
-NETCP_CFG_CLASS_T class_2;\r
-NETCP_CFG_FLOW_HANDLE_T specialFlow;\r
-\r
-NETCP_CFG_CLASSIFIER_T class_0_cfg=\r
-{\r
- NETCP_CFG_CLASS_TYPE_L4,\r
- {\r
- {0,0, NWAL_APP_PLOAD_PROTO_UDP, {2500}}\r
- }\r
-};\r
-\r
-NETCP_CFG_CLASSIFIER_T class_1_cfg=\r
-{\r
- NETCP_CFG_CLASS_TYPE_L4,\r
- {\r
- {0,0, NWAL_APP_PLOAD_PROTO_UDP, {2502}}\r
- }\r
-};\r
-\r
-NETCP_CFG_ROUTE_T class2_route=\r
-{\r
-NULL, NULL //* to be filled in\r
-};\r
-NETCP_CFG_CLASSIFIER_T class_2_cfg= \r
-{\r
- NETCP_CFG_CLASS_TYPE_L3_L4,\r
- {\r
- {0, 4 ,0/*fill in below*/ , NULL, NULL, //L2/L3\r
- NWAL_APP_PLOAD_PROTO_UDP, {2504}} //L4\r
- }\r
-};\r
-\r
-PKTIO_CONTROL_T zap_channel_control={PKTIO_CLEAR, NULL};\r
-\r
-/* security objects. (for loopback mode) */\r
-NETCP_CFG_SA_T rx_tunnel;\r
-NETCP_CFG_SA_T tx_tunnel;\r
-NETCP_CFG_IPSEC_POLICY_T rx_policy;\r
-void * rx_data_mode_handle;\r
-void * tx_data_mode_handle;\r
-void * rx_inflow_mode_handle;\r
-void * tx_inflow_mode_handle;\r
-/* rx */\r
-NETAPI_SEC_SA_INFO_T rx_sa=\r
-{\r
- NWAL_SA_DIR_INBOUND,\r
- 0x44444444, //spi\r
- nwal_IpSecProtoESP, //ESP mode\r
- nwal_SA_MODE_TUNNEL, //tunnel mode\r
- nwal_IPV4, //v4\r
- { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */\r
- { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/\r
- 64,/* replayWindow */\r
- NWAL_SA_AALG_HMAC_SHA1,\r
- NWAL_SA_EALG_AES_CBC,\r
- 0,0 //na\r
-};\r
-\r
-/*tx */\r
-NETAPI_SEC_SA_INFO_T tx_sa=\r
-{\r
- NWAL_SA_DIR_OUTBOUND,\r
- 0x44444444, //spi\r
- nwal_IpSecProtoESP, //ESP mode\r
- nwal_SA_MODE_TUNNEL, //tunnel mode\r
- nwal_IPV4, //v4\r
- { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (us) -> set below */\r
- { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (them) -> set below*/\r
- 64, /* NA replayWindow */\r
- NWAL_SA_AALG_HMAC_SHA1,\r
- NWAL_SA_EALG_AES_CBC,\r
- 0,0 //seq no\r
-};\r
-\r
-//since we are doing loopback, the rx key params = tx key params\r
-static nwalSecKeyParams_t ourTXKeyParams =\r
-{\r
- 16, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt : 24 bytes:NWAL_SA_EALG_DES_CBC and 0 bytes Salt*/\r
- 20, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_MD5 */\r
- NULL, //set below\r
- NULL, //set below\r
-};\r
-\r
-static nwalSecKeyParams_t ourRXKeyParams ={\r
- 16, /* encKeySize: 16 bytes Encryption Key and 4 bytes Salt : 24 bytes:NWAL_SA_EALG_DES_CBC and 0 bytes Salt*/\r
- 20, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_MD5 */\r
- NULL, //set below\r
- NULL, //set below\r
-};\r
-\r
-//keys\r
-static uint8_t ourAuthKey[36] =\r
- {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,\r
- 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,\r
- 0x20, 0x21, 0x22, 0x23 };\r
-static uint8_t ourEncrKey[36] =\r
- {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,\r
- 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,\r
- 0x30, 0x31, 0x32, 0x33 };\r
-\r
-\r
-/*************************END NETAPI OBJECTS***********************/\r
-\r
-#define START_SRC_IP 0x0a00000a\r
-#define DST_IP 0xc0a80001\r
-#define NEW_START_SRC_IP 0x9eda000a\r
-#define DST_PORT 0x555 \r
-#define START_SRC_PORT 0x1234\r
-#define NEW_START_SRC_PORT 100\r
-void update_header(HEAD_T * p_head, int len)\r
-{\r
- unsigned char *p = (unsigned char *) &p_head->udp[1];\r
- len -= (20+14);\r
- /* update ip checksum */\r
- /* update udp checksum */\r
- /* update length */\r
- *p= (len&0xff00)>>8;\r
- *(p+1) = len&0xff;\r
-}\r
-\r
-#if 0\r
-void gen_pkts(int np)\r
-{\r
-int i;\r
-int ip = START_SRC_IP &0xff;\r
-int port= START_SRC_PORT;\r
-//HEAD_T temp={{0x25000200,0xdead0000,0x80110000,START_SRC_IP,DST_IP},\r
-// {START_SRC_PORT<<16|DST_PORT,0x01ec<<16|0x0000}};\r
-HEAD_T temp;\r
-memcpy(&temp,&testPkt[0],sizeof(HEAD_T));\r
-\r
-for(i=0;(i<np) && (i<NP);i++)\r
- {\r
- memcpy(&pkts[i],&temp,sizeof(temp));\r
- update_header(&pkts[i],512); /* update checksums etc */\r
- /* change template for new pkt */\r
- ip+=1;\r
- if(ip>254) {(ip=START_SRC_IP&0xff); port+=1; }\r
- temp.ip[3] = htonl((START_SRC_IP&0xffffff00)| ip);\r
- temp.udp[0] = htonl( (temp.udp[0]&0xffff0000)| port);\r
- temp.udp[1] = htonl(temp.udp[1]);\r
- \r
- }\r
- n_pkt=np;\r
-}\r
-#endif\r
-\r
-void build_table(Trie * p_trie)\r
-{\r
-int i;\r
-int sport=NEW_START_SRC_PORT; \r
-HEAD_T temp,temp2;\r
-KEY_T key;\r
-\r
-memcpy(&temp,&testPkt[14],sizeof(temp));\r
-\r
- //insert entry into trie\r
-key.src_ip = temp.ip[3];\r
-key.dst_ip = temp.ip[4];\r
-key.src_port= (temp.udp[0]&0xffff0000)>>16;\r
-key.dst_port= (temp.udp[0]&0x0000ffff);\r
-trie_insert(p_trie,(char *)&key,sizeof(key), (void *) &nat[0]); //asociate with nat entry 0\r
-\r
-//build nat table\r
-for(i=0;i<100;i++)\r
-{\r
- memcpy(&temp2,&testPkt[14],sizeof(temp));\r
- temp2.udp[0] = (temp2.udp[0] & 0xffff0000) | sport;\r
- memcpy(&nat[i], &temp2, sizeof(temp2));\r
- sport+= 1;\r
-}\r
-}\r
-\r
-//===========stub transmitter==================\r
-void send_pkt(Ti_Pkt *pkt, int len)\r
-{\r
-//just free pkt. Don't send\r
-Pktlib_freePacket((Ti_Pkt*)pkt);\r
- return;\r
-}\r
-\r
-//==========stub slow path============\r
-void slow_path(Ti_Pkt *pkt, int len)\r
-{\r
-// debug: check descriptor for validity by verifying that desciptor link field is null as expected\n");\r
- {Ti_Pkt * k= Pktlib_getNextPacket(pkt); if(k != 0) {printf(" slowpath, nexpkt != NULL");}}\r
-//just free pkt\r
-Pktlib_freePacket((Ti_Pkt*)pkt);\r
- return;\r
-}\r
-/* check header */\r
-struct LastPktInfo\r
-{\r
-int iface;\r
-int ipcsum;\r
-int l4csum;\r
-} ;\r
-static struct LastPktInfo lpInfo;\r
-\r
-int check_header(HEAD_T * p_head, PKTIO_METADATA_T * p_meta)\r
-{\r
-if (NWAL_RX_FLAG1_META_DATA_VALID & p_meta->u.rx_meta->rxFlag1)\r
-{\r
-lpInfo.iface = ((unsigned int)p_meta->u.rx_meta->appId) &0xff; //last byte is interface num\r
-lpInfo.ipcsum =(p_meta->u.rx_meta->rxFlag1 & NWAL_RX_FLAG1_IPV4_CHKSUM_VERIFY_MASK )== NWAL_RX_FLAG1_IPV4_CHKSUM_VERIFY_ACK ? 1 : 0;\r
-lpInfo.l4csum = (p_meta->u.rx_meta->rxFlag1 & NWAL_RX_FLAG1_L4_CHKSUM_VERIFY_MASK )== ((NWAL_RX_FLAG1_L4_CHKSUM_VERIFY_ACK) << NWAL_RX_FLAG1_L4_CHKSUM_VERIFY_SHIFT) ? 1 : 0; \r
-if ((unsigned int)p_meta->u.rx_meta->appId & NETAPI_NETCP_MATCH_IPSEC)\r
-{\r
- stats.sec_rx++;\r
-}\r
-if ((unsigned int)p_meta->u.rx_meta->appId & NETAPI_NETCP_MATCH_IPSEC_POLICY)\r
-{\r
- stats.secp_rx++;\r
-}\r
-\r
-if ((unsigned int)p_meta->u.rx_meta->appId & NETAPI_NETCP_MATCH_CLASS)\r
-{\r
- int c= ((unsigned int)p_meta->u.rx_meta->appId >>8)&0xffff;\r
- if (c==0) stats.n_class0_rx +=1;\r
- else if (c==1) stats.n_class1_rx +=1;\r
- else if (c==2) stats.n_class2_rx +=1;\r
- else printf("**NET_TEST RX -unknown class: %x\n", p_meta->u.rx_meta->appId);\r
-}\r
-}\r
-\r
- return 1;\r
-}\r
-\r
-#define PKT_LEN 1400\r
-void test_alloc_free(int n)\r
-{\r
-int i;\r
-Ti_Pkt * b;\r
-\r
-for(i=0;i<n;i++)\r
-{\r
- b=Pktlib_allocPacket(OurHeap,PKT_LEN);\r
- Pktlib_freePacket(b);\r
-}\r
-}\r
-\r
-//measurement test points\r
-unsigned int vv1;\r
-unsigned int vv2;\r
-unsigned int vv3;\r
-unsigned int vv4;\r
-unsigned int vv5;\r
-unsigned int vv6;\r
-//these are updated by pktio.\r
-unsigned int vv7p;\r
-unsigned int vv8p;\r
-unsigned int vv9p;\r
-unsigned int vv10p;\r
-unsigned int vv11p;\r
-unsigned int vv12p;\r
-\r
-unsigned int vv11;\r
-\r
-unsigned int vv13p; //rcv path\r
-unsigned int vv14p;\r
-unsigned int vv15p;\r
-\r
-extern unsigned int nwal_prof1,nwal_prof2,nwal_prof3,nwal_prof4,nwal_prof5,nwal_prof6;\r
-\r
-//#define REASSEMBLE_BENCH\r
-#ifdef REASSEMBLE_BENCH\r
-#include <ti/drv/pa/example/reassemLib/reassemLib.h>\r
-/*--------------reassembly benchmark--------------------------------*/\r
-void our_reassemble_bench(int nfrags)\r
-{\r
-paIPReassemblyConfig_t Config={5,128,10000 };\r
-int i,j;\r
-int len;\r
-Ti_Pkt tip;\r
-char *buffer;\r
-unsigned long v1;\r
-unsigned long v2;\r
-unsigned long sum1=0;\r
-unsigned long sum2=0;\r
-paEx_reassemLibInit(&Config);\r
-for(j=0;j<200/nfrags;j++)\r
-{\r
- for(i=0;i<nfrags;i++)\r
- {\r
- short temp;\r
- tip=Pktlib_allocPacket(OurHeap,PKT_LEN);\r
- Pktlib_getDataBuffer(tip,(uint8_t**)&buffer,&len);\r
- memcpy(&buffer[0],&testPkt[14],20); //IP header\r
- if (i < (nfrags-1)) buffer[6] = 0x20;\r
- temp = i*40; \r
- buffer[6]|= (temp&0x1f00)>>8;\r
- buffer[7]= (temp&0xff);\r
- temp = 20+40*8; \r
- buffer[2]= (temp&0xff00)>>8;\r
- buffer[3]= (temp&0xff);\r
- Pktlib_setPacketLen(tip, temp);\r
- v1= netapi_timing_stop();\r
- paEx_reassemLibProc(tip, 0xffff);\r
- v2= netapi_timing_stop();\r
- sum1+= v2-v1;\r
- }\r
- sum2 += v2-v1;\r
-}\r
-printf("reasssembly test: %d trials, %d frags/pkt %d cycles/frag %d cycles/last frag\n",j,nfrags, sum1/(j*nfrags), sum2/(j));\r
-}\r
-#endif\r
-\r
-/*--------------basic pktio send/recv benchmark----------------------*/\r
-unsigned int timings[10];\r
-void our_pktio_bench(int ntrials)\r
-{\r
-int i;\r
-#define NBATCH 8\r
-Ti_Pkt tip;\r
-unsigned char * pData;\r
-int len;\r
-int n;\r
-int err;\r
-int sum =0;\r
-\r
- Osal_cache_op_measure_reset();\r
- for(i=0;i<10;i++) timings[i]=0;\r
- printf("calibration loop .. ");\r
- for(i=0;i<1000;i++)\r
- {\r
- vv1= netapi_timing_stop();\r
- vv2= netapi_timing_stop();\r
- sum+=(vv2-vv1);\r
- }\r
- printf(" accuracy = +- %d cycles\n", sum/1000);\r
- sleep(1);\r
- \r
-PKTIO_METADATA_T meta[10]={0};\r
-//send single, recv single\r
-for(i=0;i<ntrials;i++)\r
-{\r
- vv1= netapi_timing_stop();\r
- tip=Pktlib_allocPacket(OurHeap,PKT_LEN);\r
- vv2= netapi_timing_stop();\r
- Pktlib_getDataBuffer(tip,&pData,&len);\r
- vv3= netapi_timing_stop();\r
- pktio_send(our_chan,tip,&meta[0],&err);\r
- vv4= netapi_timing_stop();\r
- n=pktio_poll(our_chan,NULL , &err);\r
- vv5= netapi_timing_stop();\r
- timings[0]+=(vv6-vv4);\r
- timings[1]+=(vv5-vv4);\r
- timings[2]+=(vv7p-vv4);\r
- timings[3]+=(vv4-vv3);\r
- timings[4]+=(vv8p-vv3); \r
- timings[5]+=(vv3-vv1);\r
- timings[6]+=(vv9p-vv8p);\r
- timings[7]+=(vv10p-vv7p);\r
- timings[8]+=(vv11-vv6);\r
-}\r
- printf("pktio bench. rx=%d (wcb%d) (toqm%d) tx=%d (toqm%d) alloc=%d qpush=%d qpop=%d free=%d\n", timings[0]/ntrials,\r
- timings[1]/ntrials, timings[2]/ntrials,timings[3]/ntrials, timings[4]/ntrials,timings[5]/ntrials,\r
- timings[6]/ntrials,timings[7]/ntrials, timings[8]/ntrials );\r
- printf("raw qpop = %d raw qpush = %d pa2va = %d ", pktio_get_qop_time(), \r
- pktio_get_qpush_time(),\r
- pktio_get_pa2va_time());\r
-{\r
- unsigned int ccycles;\r
- int n_c_ops;\r
- ccycles =Osal_cache_op_measure(&n_c_ops);\r
- printf("n_c_ops=%d cache_op_time=%d (total) = %d (pp)\n", n_c_ops, ccycles, n_c_ops? (ccycles/(n_c_ops)) : 0);\r
-}\r
-\r
-}\r
-/*-----------test driver: gen an input pkt------- */\r
-//char buffer[sizeof(HEAD_T)+PKT_LEN];\r
-Ti_Pkt * get_pkt(int n, unsigned int *p_len)\r
-{\r
- int ind;\r
- long long temp;\r
- Ti_Pkt * b;\r
- char * buffer;\r
- unsigned int len;\r
-\r
- if (pktloopback==0)\r
- {\r
- if (n>=TX_BURST) return NULL; //just gen pkts to warm swtich, so that it knows\r
- //our mac is valid\r
- } \r
- b=Pktlib_allocPacket(OurHeap,PKT_LEN);\r
- if (!b) \r
- {printf("net_test: get_pkt() heap empty!! %d pkts gen'd %d \n", n); return NULL;};\r
-\r
- //debug - way to validate descriptor\r
- {Ti_Pkt* k= Pktlib_getNextPacket(b); \r
- if(k != 0) {printf(" genpkt, nexpkt != NULL");}}\r
-\r
-\r
- //get pointer to buffer area of packet\r
- Pktlib_getDataBuffer(b,(uint8_t**)&buffer,&len);\r
- if (!buffer) \r
- {printf("net_test: get_pkt() heap returned empty buffer %d \n", n); return NULL;};\r
-\r
-#if 0 \r
-if (pktloopback==0)\r
-{\r
- temp = (long long) rand();\r
- temp *= PKT_LEN;\r
- temp /= RAND_MAX;\r
- temp +=2;\r
- *p_len = (int) temp; \r
- *p_len = *p_len &0xfffffffe;\r
- temp = (long long) rand();\r
- temp *= n_pkt;\r
- temp /= RAND_MAX;\r
- ind = (int) temp;\r
- update_header(&pkts[ind],*p_len);\r
- //printf("get pkt:%d %d ind=%d len=%d\n",RAND_MAX, rand(),ind, *p_len);\r
- memcpy(&buffer[0], &mac_header[0],14);\r
- memcpy(&buffer[14],(char*)&pkts[ind],sizeof(HEAD_T)); \r
-}\r
-else\r
-#endif\r
-\r
- //copy test packet into buffer\r
-{\r
- memcpy(&buffer[0], &testPkt[0],TEST_PKT_LEN);\r
- *p_len = TEST_PKT_LEN;\r
-}\r
- return b; \r
-}\r
-\r
-\r
-/*--------------------------------------------------------------\r
- *----------utility to flip a packet and send \r
- *--------------------back to source----------------------------\r
- * flag=1 => ipsec\r
- *--------------------------------------------------------------*/\r
-void flip_and_send_pkt(Ti_Pkt *tip, unsigned char * p_pkt, int len, int flag)\r
-{\r
-unsigned char mac_temp[6];\r
-unsigned char ip_temp[4];\r
-unsigned char new_dest_port[2]={0x75,0x30}; // 30000\r
-uint16_t blah; \r
-//mac\r
-memcpy(&mac_temp,&p_pkt[0],6);\r
-memcpy(&p_pkt[0],&p_pkt[6],6);\r
-memcpy(&p_pkt[6],&mac_temp,6);\r
-//memcpy(&p_pkt[0],real_mac_header,6); //for testing to wireshark pc\r
-\r
-//ip (outer in case of ipsec)\r
-memcpy(&ip_temp, &p_pkt[14+12],4);\r
-memcpy(&p_pkt[14+12],&p_pkt[14+12+4],4);\r
-memcpy(&p_pkt[14+12+4],&ip_temp,4);\r
-\r
-//outer checksum to 0\r
-if (!flag) memset(&p_pkt[14+10],0,2);\r
-\r
-//inner ip &udp for ipsec\r
-if (flag) \r
-{\r
- //just drop non-udp packet\r
- if (p_pkt[14+20+8+16+9]!=0x11)\r
- {\r
- stats.n_new+=1;Pktlib_freePacket(tip); return;\r
- }\r
-\r
-//spi\r
-//memset(&p_pkt[14+20],0x88,4); \r
-//inner ip\r
-memcpy(&ip_temp, &p_pkt[14+20+8+16+12],4);\r
-memcpy(&p_pkt[14+20+8+16+12],&p_pkt[14+20+8+16+12+4],4);\r
-memcpy(&p_pkt[14+20+8+16+12+4],&ip_temp,4);\r
-\r
-//udp\r
-memcpy(&p_pkt[14+20+8+16+20+2],&new_dest_port[0],2);\r
-memset(&p_pkt[14+20+8+16+20+6],0,2); //checksum\r
-\r
-#ifdef IPSEC_MODE_TX_SIDEBAND\r
-\r
-//inner ip checksum : leave alone\r
-#if 0\r
-blah=test_utilOnesCompChkSum (&p_pkt[14+20+8+16], 10);\r
-p_pkt[14+20+8+16+10]= (blah&0xff00)>>8;\r
-p_pkt[14+20+8+16+11]= blah&0xff;\r
-#endif\r
-\r
-//tbd udp checksum (leave at 0)\r
-\r
-//outer ip, set to 0 (we will compute on way out\r
-memset(&p_pkt[14+10],0,2);\r
-\r
-#else //inflow, don't touch outer , clear inner \r
-memset(&p_pkt[14+20+8+16+10],0,2); //inner checksum, we will compute on way out\r
-//outer ip checksum : leave alone\r
-#if 0\r
-blah = test_utilOnesCompChkSum (&p_pkt[14], 10);\r
-p_pkt[14+10]= (blah&0xff00)>>8;\r
-p_pkt[14+11]= blah&0xff;\r
-#endif\r
-#endif\r
-}\r
-else\r
-{\r
-memset(&p_pkt[14+20+6],0,2);//0 udp checksum (we will compute on way out\r
-memcpy(&p_pkt[14+20+2],&new_dest_port[0],2);\r
-}\r
-\r
-//IPSEC case, \r
-if (flag)\r
-{\r
-#ifdef IPSEC_MODE_TX_SIDEBAND\r
- //send to crypto for encryption\r
-//12 byte auth tag\r
- {\r
- PKTIO_METADATA_T meta = {PKTIO_META_SB_TX,{0},0};\r
- int err;\r
- nwalDmTxPayloadInfo_t meta_tx={0};\r
- meta.sa_handle=tx_data_mode_handle; //use TX SA context\r
- meta_tx.ploadLen = len;\r
- meta_tx.encOffset = 14+20+8+16 ;\r
- meta_tx.authOffset =14+20 ;\r
- meta_tx.encSize=len - 14- 20-8-16-12;\r
- meta_tx.authSize= len -14-20-12;\r
- meta_tx.encIvSize=16;\r
- meta_tx.pEncIV= &p_pkt[14+20+8]; //just use same IV..\r
- meta_tx.authIvSize=0;\r
- meta_tx.pAuthIV=NULL;\r
- meta_tx.aadSize=0;\r
- meta_tx.pAad=NULL;\r
- /* post it to netcp sb tx channel*/\r
- meta.u.tx_sb_meta=&meta_tx;\r
- pktio_send(netcp_sb_tx_chan,tip,&meta,&err);\r
- }\r
-\r
-#else\r
- {\r
- //inflow tx\r
- //send pkt directly, asking for IP and UDP checksum offloads AND IPSEC to be applied\r
- PKTIO_METADATA_T meta = {PKTIO_META_TX,{0},0};\r
- int err;\r
- nwalTxPktInfo_t meta_tx={0};\r
- meta.sa_handle=tx_inflow_mode_handle; //this tells netapi that inflow crypto needs to be applied\r
- meta_tx.txFlag1 = (NWAL_TX_FLAG1_DO_IPV4_CHKSUM|NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_DO_IPSEC_CRYPTO| NWAL_TX_FLAG1_META_DATA_VALID );\r
- meta_tx.saOffBytes=14+20; \r
- meta_tx.saPayloadLen=len-14-20; //don't include tag, mac and outer header\r
- meta_tx.startOffset = 0;\r
- meta_tx.ipOffBytes = 14+20+8+16; //to inner header\r
- meta_tx.l4OffBytes = 14+20+8+16+20; //to L4 \r
- meta_tx.l4HdrLen = 8;\r
- meta_tx.ploadLen = (unsigned) ((p_pkt[14+20+8+16+20+4]<<8)|p_pkt[14+20+8+16+20+4+1]) -8 ;\r
- meta_tx.pseudoHdrChecksum =\r
- test_utilGetIpv4PsudoChkSum(&p_pkt[14+20+8+16],8+ meta_tx.ploadLen);\r
-\r
- /* post it to netcp tx channel*/\r
- meta.u.tx_meta=&meta_tx;\r
- pktio_send(netcp_tx_chan,tip,&meta,&err);\r
- stats.tx +=1;\r
- stats.sec_tx +=1;\r
- }\r
-#endif\r
-\r
-\r
-}\r
-else //non ipsec send pkt directly, asking for IP and UDP checksum ofload\r
-{\r
- PKTIO_METADATA_T meta2 = {PKTIO_META_TX,{0},0};\r
- int err;\r
- nwalTxPktInfo_t meta_tx2={0};\r
- meta2.sa_handle=nwal_HANDLE_INVALID;\r
- meta_tx2.txFlag1 = (NWAL_TX_FLAG1_DO_IPV4_CHKSUM|NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID );\r
- meta_tx2.startOffset = 0;\r
- meta_tx2.ipOffBytes = 14;\r
- meta_tx2.l4OffBytes = 14+20;\r
- meta_tx2.l4HdrLen = 8;\r
- meta_tx2.ploadLen = (unsigned) ((p_pkt[14+20+4]<<8)|p_pkt[14+20+4+1]) -8 ;\r
- meta_tx2.pseudoHdrChecksum =\r
- test_utilGetIpv4PsudoChkSum(&p_pkt[14],8+ meta_tx2.ploadLen);\r
-\r
- /* post it to netcp tx channel*/\r
- meta2.u.tx_meta=&meta_tx2;\r
- pktio_send(netcp_tx_chan,tip,&meta2,&err);\r
- stats.tx +=1;\r
-}\r
-}\r
-\r
-\r
-\r
-\r
-/***************************************\r
- benchmark receive handler\r
-****************************************/\r
-void recv_cb_bench(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],\r
- PKTIO_METADATA_T meta[], int n_pkts,\r
- uint64_t ts )\r
-{\r
- int i;\r
- vv6= netapi_timing_stop();\r
- for (i=0;i<n_pkts; i++) \r
- {\r
- Pktlib_freePacket(p_recv[i]);\r
- }\r
- vv11 = netapi_timing_stop();\r
-}\r
-\r
-/****************************************************************************************/\r
-/******************SB Accelerator Callback PKT RECEIVE HANDLER *************************/\r
-/****************** Handles Decrypt and Encrypt operation callbacks ******************/\r
-/******************************************************************************************/\r
-void recv_sb_cb(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],\r
- PKTIO_METADATA_T meta[], int n_pkts,\r
- uint64_t ts )\r
-{\r
-int i;\r
-int len;\r
-int p;\r
-HEAD_T * p_res;\r
-Ti_Pkt * tip;\r
-unsigned int templen;\r
-int err;\r
-KEY_T key;\r
-char * p_pkt;\r
-HEAD_T * p_head;\r
-HEAD_T temp_head;\r
-int tag_cmp=0;\r
-unsigned int hash[3];\r
-\r
- /* loop over received pkts */\r
- for(i=0;i<n_pkts;i++)\r
- {\r
- tip = p_recv[i];\r
- Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&templen);//ignore templen\r
- len = Pktlib_getPacketLen(tip);//real length\r
-\r
- //is this a decrypt (rx_tunnel) complete\r
- if (meta[i].u.rx_sb_meta->appId == rx_tunnel)\r
- {\r
- stats.sb_rx+=1;\r
- //copy hash out of meta data (for some reason it needs endian conversion)\r
- hash[0]= htonl( meta[i].u.rx_sb_meta->pAuthTag[0]);\r
- hash[1]= htonl( meta[i].u.rx_sb_meta->pAuthTag[1]);\r
- hash[2]= htonl( meta[i].u.rx_sb_meta->pAuthTag[2]);\r
-\r
- if(stats.sb_rx<=16)\r
- {\r
- char *tp = (char *) &hash[0];\r
- dump_header((long*)p_pkt, stats.sb_rx, meta[i].u.rx_sb_meta->appId,0);\r
- printf("tag in pkt=%x %x %x %x %x %x %x %x %x %x %x %x\n",\r
- p_pkt[len-12],p_pkt[len-11],p_pkt[len-10],p_pkt[len-9], p_pkt[len-8],\r
- p_pkt[len-7],p_pkt[len-6],\r
- p_pkt[len-5],p_pkt[len-4],p_pkt[len-3],p_pkt[len-2],p_pkt[len-1]);\r
- printf("tag from SA=%x %x %x %x %x %x %x %x %x %x %x %x\n",\r
- tp[0],tp[1],tp[2],tp[3],tp[4],tp[5],\r
- tp[6],tp[7],tp[8],tp[9],tp[10],tp[11]);\r
- }\r
- //check tag \r
- tag_cmp = memcmp(&p_pkt[len-12],(char*) &hash[0],12); //todo, really use meta->authTagLen\r
- stats.n_auth_ok += !(tag_cmp);\r
- flip_and_send_pkt(tip, p_pkt, len,1); //flip packet to echo back and send\r
- }\r
- //this is an encrypt (tx tunnel) complete\r
- else if(meta[i].u.rx_sb_meta->appId== tx_tunnel )\r
- {\r
- hash[0]= htonl( meta[i].u.rx_sb_meta->pAuthTag[0]);\r
- hash[1]= htonl( meta[i].u.rx_sb_meta->pAuthTag[1]);\r
- hash[2]= htonl( meta[i].u.rx_sb_meta->pAuthTag[2]);\r
- stats.sb_tx+=1;\r
- if(stats.sb_tx<=16)\r
- {\r
- char *tp1 = (char *) &hash[0];\r
- dump_header((long*)p_pkt, stats.sb_tx, meta[i].u.rx_sb_meta->appId,0);\r
- printf("tag in original rx pkt=%x %x %x %x %x %x %x %x %x %x %x %x\n",\r
- p_pkt[len-12],p_pkt[len-11],p_pkt[len-10],p_pkt[len-9], p_pkt[len-8],\r
- p_pkt[len-7],p_pkt[len-6],\r
- p_pkt[len-5],p_pkt[len-4],p_pkt[len-3],p_pkt[len-2],p_pkt[len-1]);\r
-\r
- printf("tag from SA=%x %x %x %x %x %x %x %x %x %x %x %x\n",\r
- tp1[0],tp1[1],tp1[2],tp1[3],tp1[4],tp1[5],\r
- tp1[6],tp1[7],tp1[8],tp1[9],tp1[10],tp1[11]);\r
- }\r
- //put the computed tag in the packet\r
- memcpy(&p_pkt[len-12],(char*)&hash[0],12); //todo, really use meta->authTagLen\r
- {\r
- PKTIO_METADATA_T meta2 = {PKTIO_META_TX,{0},0};\r
- nwalTxPktInfo_t meta_tx={0};\r
- // now send directly \r
- meta2.sa_handle=nwal_HANDLE_INVALID;\r
- meta_tx.txFlag1 = (NWAL_TX_FLAG1_DO_IPV4_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID);//only outer IP header checksum. no udp checksum possible since pkt is already encrypted\r
- meta_tx.startOffset = 0;\r
- meta_tx.ipOffBytes = 14;\r
- //not used\r
- meta_tx.l4OffBytes = 0;\r
- meta_tx.l4HdrLen = 0;\r
- meta_tx.ploadLen = 0;\r
-\r
- /* post it to netcp tx channel*/\r
- meta2.u.tx_meta=&meta_tx;\r
- pktio_send(netcp_tx_chan,tip,&meta2,&err);\r
- stats.tx +=1;\r
- }\r
- }\r
- else printf("netapi recv_sb_cb: unknown appiD %x \n",meta[i].u.rx_sb_meta->appId );\r
- }\r
-}\r
-\r
-/******************************************************/\r
-/******************PKT RECEIVE HANDLER *************************/\r
-/******************************************************/\r
-void recv_cb(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],\r
- PKTIO_METADATA_T meta[], int n_pkts,\r
- uint64_t ts )\r
-{\r
-int i;\r
-int len;\r
-int p;\r
-HEAD_T * p_res;\r
-Ti_Pkt * tip;\r
-unsigned int templen;\r
-int err;\r
-KEY_T key;\r
-char * p_pkt;\r
-HEAD_T * p_head;\r
-HEAD_T temp_head;\r
-\r
- p_head=&temp_head;\r
-\r
- //debug\r
-#if 0\r
- if (n_pkts != TX_BURST) {\r
- printf("recv_cb, txsofar=%d rxsofar=%d np = %d, NOT %d\n", \r
- stats.itx, stats.rx, n_pkts,TX_BURST);\r
- our_stats_cb(netapi_handle,NULL);\r
- }\r
-#endif\r
- //test_alloc_free(7);\r
- //printf("recv start\n");\r
-\r
- /* loop over received pkts */\r
- for(i=0;i<n_pkts;i++)\r
- {\r
- tip = p_recv[i];\r
- Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&templen);//ignore templen\r
- len = Pktlib_getPacketLen(tip)-4;//real length, subtract mac trailer\r
-\r
- //debug: validate descriptor */\r
- if(Pktlib_getNextPacket(tip) != 0) {printf(" rcv_cb, nexpkt != NULL");}\r
- //debug printf("recv pkt, len=%d %d\n", len, templen);\r
- stats.rx+=1;\r
-\r
-#ifdef DEBUG_DESC\r
- if (stats.rx<16){printf(">rx dmp.."); dump_descr((long *) tip, stats.rx);}\r
- else if (stats.rx>99) {printf(">rx dmp.."); dump_descr((long *) tip,stats.rx);}\r
-#endif\r
- if(stats.rx<=16)\r
- {\r
- dump_header((long*)p_pkt, stats.rx, meta[i].u.rx_meta->appId,meta[i].u.rx_meta->rxFlag1);\r
- }\r
- /* check header */\r
- memcpy(p_head,&p_pkt[14],sizeof(HEAD_T));\r
-\r
- if ((p_head->ip[2]&0x0000ff00)==0x00003200)\r
- {\r
- if (!check_header(p_head,&meta[i])) {\r
- stats.n_bad+=1;Pktlib_freePacket(tip); continue;\r
- }\r
- \r
- //process IP SEC PACKET\r
-#ifdef IPSEC_MODE_RX_SIDEBAND\r
- {\r
- //ship to crypto for decrypt!!\r
- //12 byte auth tag\r
- PKTIO_METADATA_T meta2 = {PKTIO_META_SB_TX,{0},0};\r
- nwalDmTxPayloadInfo_t meta_tx={0};\r
- meta2.sa_handle=rx_data_mode_handle;\r
- meta_tx.ploadLen = len;\r
- meta_tx.encOffset = 14+20+8+16 ;\r
- meta_tx.authOffset =14+20 ;\r
- meta_tx.encSize=len - 14- 20-8-16-12;\r
- meta_tx.authSize= len -14-20-12;\r
- meta_tx.encIvSize=16;\r
- meta_tx.pEncIV= &p_pkt[14+20+8];\r
- meta_tx.authIvSize=0;\r
- meta_tx.pAuthIV=NULL;\r
- meta_tx.aadSize=0;\r
- meta_tx.pAad=NULL;\r
- /* post it to netcp sb tx channel*/\r
- meta2.u.tx_sb_meta=&meta_tx;\r
- pktio_send(netcp_sb_tx_chan,tip,&meta2,&err);\r
- continue;\r
- }\r
-#else \r
- //inflow mode. flip and send\r
- flip_and_send_pkt(tip,p_pkt,len,1);\r
-#endif\r
- }\r
- else if ((p_head->ip[2]&0x0000ff00)!=0x00001100)\r
- {\r
- stats.n_new+=1;Pktlib_freePacket(tip); continue;\r
- }\r
- else //non ipsec\r
- {\r
- if (!check_header(p_head,&meta[i])) { \r
- stats.n_bad+=1;Pktlib_freePacket(tip); continue;\r
- }\r
-\r
-#if 0\r
- /* lookup flow */\r
- key.src_ip = p_head->ip[3];\r
- key.dst_ip = p_head->ip[4];\r
- key.src_port= (p_head->udp[0]&0xffff0000)>>16;\r
- key.dst_port= (p_head->udp[0]&0x0000ffff);\r
- p_res= (HEAD_T *) trie_lookup(P_trie, (char *) &key, sizeof(key));\r
- if (!p_res) { stats.n_new+=1; slow_path(tip, len); continue;}\r
-\r
- /* copy header */\r
- memcpy((char *) p_head, (char *) p_res, sizeof(HEAD_T));\r
-\r
- memcpy(&p_pkt[14],p_head,sizeof(HEAD_T));\r
- /* update_mac(&p_pkt[0]); */\r
-\r
- /* 'simulate' send pkt */\r
- send_pkt(tip,len);\r
-#endif\r
- //just flip and send\r
- flip_and_send_pkt(tip,p_pkt,len,0);\r
- }\r
- }\r
- //printf("recv done\n");\r
-}\r
-\r
-//timer callback \r
-void our_timer_cb( NETAPI_TIMER_GROUP_HANDLE_T th,\r
- int n_fired, //# timers fired\r
- NETAPI_TIMER_LIST_T fired_list,\r
- uint64_t currentTime)\r
-{\r
-int i;\r
-NETAPI_TIMER_T tx;\r
-int cookie;\r
-int err;\r
-unsigned long long et;\r
-//DEBUGprintf("TIMER CALLBACK @ %lld %d timers\n", currentTime, n_fired);\r
-tx = netapi_TimerGetFirst(fired_list);\r
-for(i=0;i<n_fired;i++)\r
-{\r
- cookie = (int) netapi_TimerGetCookie(tx);\r
- et = netapi_TimerGetTs(tx); //debug\r
- //DEBUGprintf(" timer %d - cookie = %d expected ts=%lld (delta=%lld)\n", i, cookie, et, currentTime-et);\r
- if (cookie ==1)\r
- { \r
- stats.n_t1+=1;\r
- t1 = netapi_TimerGroupStartTimer(\r
- th,\r
- (void *) 1,\r
- 100LL, //timer group tics\r
- &err);\r
- }\r
- else if (cookie ==2)\r
- {\r
- stats.n_t2+=1;\r
- t2 = netapi_TimerGroupStartTimer(\r
- th,\r
- (void *) 2,\r
- 200LL, //timer group ticks\r
- &err);\r
- }\r
- else\r
- {\r
- stats.n_t3+=1;\r
- t3 = netapi_TimerGroupStartTimer(\r
- th,\r
- (void *) 3,\r
- 300LL, //timer group ticks\r
- &err);\r
- //cancel 1 and restart 1\r
- netapi_TimerGroupCancel(th,t1,&err);\r
- t1 = netapi_TimerGroupStartTimer(\r
- th,\r
- (void *) 1,\r
- 100LL, //timer group ticks\r
- &err);\r
- }\r
- tx = netapi_TimerGetNext(fired_list,tx); \r
-}\r
-}\r
-\r
-\r
-static int np2process = NP;\r
-/******************************************************\r
- * stats callback\r
- *******************************************************/\r
-void our_stats_cb(NETAPI_T h, paSysStats_t* pPaStats)\r
-{\r
-uint32_t numFreeDataPackets;\r
-uint32_t numZeroBufferPackets;\r
-uint32_t numPacketsinGarbage;\r
-Pktlib_HeapStats pktLibHeapStats;\r
-\r
-printf(">*****stats @ %lld\n", netapi_getTimestamp());\r
-//printf("netcp_tx_handle check %x\n", netcp_tx_chan->back);\r
-printf(">itx=%d rx=%d tx=%d bad=%d slow=%d \n>rx_class0=%d rx_class1=%d rx_class2=%d secRx=%d secPRX=%d sb_rx=%d sb_tx=%d auth_ok=%d\n n_t1=%d n_t2=%d n_t3=%d\n",stats.itx, stats.rx, stats.tx, stats.n_bad, stats.n_new, \r
- stats.n_class0_rx, stats.n_class1_rx, \r
- stats.n_class2_rx, stats.sec_rx, stats.secp_rx, stats.sb_rx, stats.sb_tx, stats.n_auth_ok,\r
- stats.n_t1, stats.n_t2,stats.n_t3);\r
-\r
-if(pPaStats)\r
-{\r
- printf("C1 number of packets: %d\n", pPaStats->classify1.nPackets);\r
- printf("C1 number IPv4 packets: %d\n", pPaStats->classify1.nIpv4Packets);\r
- //printf("C1 number llc/snap fail: %d\n", pPaStats->classify1.nLlcSnapFail);\r
- printf("C1 number table matched: %d\n", pPaStats->classify1.nTableMatch);\r
- printf("C1 number failed table matched: %d\n", pPaStats->classify1.nNoTableMatch);\r
- printf ("C1 number of parse fail: %d\n",pPaStats->classify1.nParseFail);\r
- printf("C1 number of command failures: %d\n", pPaStats->classify1.nCommandFail);\r
- printf("C1 number invalid reply dests: %d\n", pPaStats->classify1.nInvalidComReplyDest);\r
- printf ("C1 number of silent discard: %d\n",pPaStats->classify1.nSilentDiscard);\r
- printf("C1 number of invalid control: %d\n", pPaStats->classify1.nInvalidControl);\r
- printf ("C1 number of invalid states: %d\n",pPaStats->classify1.nInvalidState);\r
- printf ("C1 number of system fails: %d\n",pPaStats->classify1.nSystemFail);\r
- printf ("C2 number parse failed : %d\n",pPaStats->classify2.nParseFail);\r
- printf ("C2 number Invld Header : %d\n",pPaStats->classify2.nInvldHdr);\r
- printf ("C2 number udp : %d\n",pPaStats->classify2.nUdp);\r
- printf ("C2 number tcp : %d\n",pPaStats->classify2.nTcp);\r
- printf ("C2 number cmd fail : %d\n",pPaStats->classify2.nCommandFail);\r
- printf ("C2 number silent drop : %d\n",pPaStats->classify2.nSilentDiscard);\r
- printf ("C2 number invalid cntrl : %d\n\n",pPaStats->classify2.nInvalidControl);\r
-}\r
-Pktlib_getHeapStats(OurHeap, &pktLibHeapStats);\r
-printf("main heap stats> #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets,\r
- pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage);\r
-printf(" > #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n", \r
- pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter,\r
- pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter);\r
-\r
-Pktlib_getHeapStats(specialSmall, &pktLibHeapStats);\r
-printf("specialSmall heap stats> #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets,\r
- pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage);\r
-printf(" > #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n", \r
- pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter,\r
- pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter);\r
-\r
-\r
-Pktlib_getHeapStats(specialLarge, &pktLibHeapStats);\r
-printf("specialLarge heap stats> #free=%d #zb=%d #garbage=%d\n", pktLibHeapStats.numFreeDataPackets,\r
- pktLibHeapStats.numZeroBufferPackets, pktLibHeapStats.numPacketsinGarbage);\r
-printf(" > #dataBufThreshStatus=%d #dataBufStarvCounter=%d #zBufThreshStatus=%d #zBufStarvCounter=%d \n", \r
- pktLibHeapStats.dataBufferThresholdStatus,pktLibHeapStats.dataBufferStarvationCounter,\r
- pktLibHeapStats.zeroDataBufferThresholdStatus, pktLibHeapStats.zeroDataBufferStarvationCounter);\r
-\r
-\r
-//debug = dump timer polling stats\r
-dump_poll_stats();\r
-\r
-\r
-}\r
-\r
-//******************************************************\r
-//use scheduling housekeeping callback to generate pkts\r
-//******************************************************\r
-void house(NETAPI_SCHED_HANDLE_T * s)\r
-{\r
-Ti_Pkt * tip;\r
-unsigned int len;\r
-nwalTxPktInfo_t meta_tx;\r
-PKTIO_METADATA_T meta = {PKTIO_META_TX,{0},0};\r
-int err;\r
-static int house_pkts_gened=0;\r
-int p;\r
-unsigned char * pIpHdr,* pData;\r
-unsigned int vv1,vv2,vv3;\r
-unsigned int sum_vv1=0;\r
-unsigned int sum_vv2=0;\r
-unsigned int sum_vv3=0;\r
-unsigned int sum_vv4=0;\r
-unsigned int sum_vv5=0;\r
-\r
-unsigned int nwal_flow_vv1,nwal_flow_vv2;\r
-unsigned int nwal_sum_vv1=0;\r
-unsigned int nwal_sum_vv2=0;\r
-unsigned int nwal_sum_vv3=0;\r
-unsigned int nwal_sum_vv4=0;\r
-unsigned int nwal_sum_vv5=0;\r
-unsigned int nwal_sum_vv6=0;\r
-\r
-unsigned int nwal_sum_flow_vv1=0;\r
-unsigned int nwal_sum_flow_vv2=0;\r
-static int first =0;\r
-Cppi_HostDesc* pPktDesc;\r
-\r
-Osal_cache_op_measure_reset();\r
-memset(&meta_tx,0,sizeof(meta_tx));\r
-for(p=0;p<TX_BURST;p++) { \r
-//reguest stats \r
-if ((house_pkts_gened>0) && (! (house_pkts_gened%1000)) )\r
-{\r
- printf("net_test> request stats at n=%d \n",house_pkts_gened);\r
- //netcp_cfgReqStats(netapi_handle, our_stats_cb, 0,&err); \r
- if (err!=0) {printf("stats req failed\n");}\r
-}\r
-\r
-\r
- if (house_pkts_gened >= np2process+ 100)\r
- {\r
- //shutdown\r
- netapi_schedShutdown(s,NULL,&err);\r
- continue;\r
- }\r
-\r
- else if (house_pkts_gened >= np2process) { house_pkts_gened+=1; continue;}\r
- \r
-\r
-/* manufacture a pkt to transmit */\r
- tip = get_pkt(house_pkts_gened, &len);\r
- if(!tip) { house_pkts_gened +=1; continue; }\r
-\r
-\r
- /* set the pkt length */\r
- vv1 = netapi_timing_start();\r
- Pktlib_setPacketLen(tip, len);\r
-\r
- /* set up meta data */\r
- meta.sa_handle=nwal_HANDLE_INVALID;\r
- meta_tx.txFlag1 = (NWAL_TX_FLAG1_DO_IPV4_CHKSUM | NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID);\r
- meta_tx.startOffset = 0;\r
- //GONE in V2 meta_tx.pktLen = len;\r
- meta_tx.ipOffBytes = TEST_PKT_IP_OFFSET_BYTES;\r
- meta_tx.l4OffBytes = TEST_PKT_UDP_OFFSET_BYTES;\r
- meta_tx.l4HdrLen = TEST_PKT_UDP_HDR_LEN;\r
- //GONE in V2 meta_tx.ploadOffBytes = TEST_PKT_PLOAD_OFFSET_BYTES;\r
- meta_tx.ploadLen = TEST_PAYLOAD_LEN;\r
-\r
- Pktlib_getDataBuffer(tip,&pData,&len);\r
- pIpHdr = pData + meta_tx.ipOffBytes;\r
- meta_tx.pseudoHdrChecksum =\r
- test_utilGetIpv4PsudoChkSum(pIpHdr,(TEST_PAYLOAD_LEN+TEST_PKT_UDP_HDR_LEN));\r
-\r
- /* post it to netcp tx channel*/\r
- meta.u.tx_meta=&meta_tx;\r
-#ifdef DEBUG_DESC\r
- if (house_pkts_gened<16) dump_descr((long *) tip, house_pkts_gened);\r
- else if (house_pkts_gened>99) dump_descr((long *) tip,house_pkts_gened);\r
-#endif\r
-\r
- if(!first)\r
- {\r
- first++;\r
- nwal_flow_vv1= netapi_timing_stop();\r
- if(nwal_initPSCmdInfo(PKTIO_GET_NWAL_INSTANCE(netcp_tx_chan),\r
- &meta_tx,\r
- &flowPSCmdInfo) != nwal_OK)\r
- {\r
- printf("nwal_initPSCmdInfo() ERROR \n");\r
- }\r
- nwal_flow_vv2= netapi_timing_stop();\r
- nwal_sum_flow_vv1 += (nwal_flow_vv1-vv1); \r
- nwal_sum_flow_vv2 += (nwal_flow_vv2-nwal_flow_vv1); \r
- }\r
- \r
- vv2= netapi_timing_stop();\r
- nwal_mCmdSetL4CkSumPort( tip,\r
- &flowPSCmdInfo,\r
- TEST_PKT_UDP_OFFSET_BYTES,\r
- (TEST_PKT_UDP_HDR_LEN + TEST_PAYLOAD_LEN),\r
- meta_tx.pseudoHdrChecksum,\r
- meta_tx.enetPort);\r
-\r
- pPktDesc = Pktlib_getDescFromPacket(tip);\r
- /* Send the packet out to transmit Q*/\r
- Qmss_queuePushDescSize (flowPSCmdInfo.txQueue, \r
- pPktDesc, \r
- NWAL_DESC_SIZE);\r
- vv3= netapi_timing_stop();\r
- \r
-\r
- sum_vv1 += (vv2-vv1);\r
- if(!house_pkts_gened)\r
- {\r
- /* first packet. Take out the PS command label creation cost */\r
- sum_vv1 = sum_vv1 - nwal_sum_flow_vv2;\r
- }\r
-\r
- sum_vv3 += (vv3-vv2);\r
-\r
- // printf("pktio send. full=%d metadata=%d pktio_send=%d\n", vv3-vv1, vv2-vv1, vv3-vv2);\r
- \r
-\r
- stats.itx +=1;\r
- house_pkts_gened +=1;\r
- }\r
-{\r
- unsigned int ccycles;\r
- int n_c_ops;\r
- ccycles =Osal_cache_op_measure(&n_c_ops);\r
- if (sum_vv1) \r
- {\r
- printf("BURST NWAL Fast send %d pkts. metadata=%d Cmd Label Creation Cost=%d nwal Fast Send Cost= %d n_c_ops=%d cache_op_time=%d (pp-> %d)\n", \r
- stats.itx, sum_vv1/stats.itx, nwal_sum_flow_vv2, sum_vv3/stats.itx, \r
- n_c_ops, ccycles, n_c_ops? (ccycles/(n_c_ops/2)) : 0);\r
-\r
- printf("NWAL Profile Cycles: Prof1= %d,Prof2=%d,Prof3=%d,Prof4=%d,Prof5=%d ,Prof6=%d \n",\r
- nwal_sum_vv1/stats.itx,nwal_sum_vv2/stats.itx,nwal_sum_vv3/stats.itx,\r
- nwal_sum_vv4/stats.itx,nwal_sum_vv5/stats.itx,nwal_sum_vv6/stats.itx);\r
- \r
-\r
- if(stats.itx2)\r
- {\r
- printf("nwal_flowSend Profile Cycles: Prof1= %d,Prof2=%d \n",\r
- nwal_sum_flow_vv1/stats.itx2,nwal_sum_flow_vv2/stats.itx2);\r
- }\r
-\r
- }\r
-}\r
-}\r
-\r
-\r
-/***************************************\r
- ********** test driver*****************\r
- ***************************************/\r
-int main(int argc, char **argv)\r
-{\r
-int err;\r
-rlim_t oss,ss = 1024*1024;\r
-struct rlimit rl;\r
- \r
-Pktlib_HeapCfg heapCfg;\r
-int32_t errCode;\r
-Pktlib_HeapIfTable* pPktifTable;\r
-\r
-err= getrlimit(RLIMIT_STACK,&rl);\r
-if (!err) printf(" stack limit = %d\n",rl.rlim_cur); else printf("getrlimit failed\n");\r
-#if 0\r
-rl.rlim_cur = ss;\r
-err=setrlimit(RLIMIT_STACK,&rl);\r
-if (!err) printf("set stack to %d\n",rl.rlim_cur); else printf("setrlimit failed\n");\r
-#endif\r
-\r
-if (argc>=2) np2process = atoi(argv[1]);\r
-if (np2process<0) np2process = NP; /* default */\r
-if (argc==3) perslow = atoi(argv[2]);\r
-if ((perslow<0)||(perslow>100)) perslow=PERSLOW;//default\r
-if (argc>3) {printf("net_test <no of pkts to process> <percent slow path>\n"); exit(1);}\r
-\r
-\r
-//real mode, so update our test packet mac header and ip header\r
-if (pktloopback==0)\r
-{\r
-memcpy(&testPkt,&real_mac_header[0],14); //overwrite test pkt mac address\r
-memcpy(&testPkt[26],&real_ip_addr[0],8);//overrite test pkt ip addresses\r
-}\r
-\r
-/*******************************************/\r
-/*************NETAPI STARTUP****************/\r
-/*******************************************/\r
-\r
-/* create netapi */\r
-netapi_handle = netapi_init(NETAPI_SYS_MASTER, &our_netapi_default_cfg);\r
-\r
-/* open the main heap */\r
-OurHeap = Pktlib_findHeapByName("netapi");\r
-if (!OurHeap) {printf("findheapbyname fail\n"); exit(1);}\r
-\r
-/* create two secondary heaps */\r
-/* Initialize the heap configuration. */\r
-memset ((void *)&heapCfg, 0, sizeof(Pktlib_HeapCfg));\r
-\r
-pPktifTable = netapi_getPktlibIfTable();\r
-/* Populate the heap configuration */\r
-heapCfg.name = "netapi-small";\r
-heapCfg.memRegion = NETAPI_GLOBAL_REGION;\r
-heapCfg.sharedHeap = 1;\r
-heapCfg.useStarvationQueue = 0;\r
-heapCfg.dataBufferSize = 512;\r
-heapCfg.numPkts = 64;\r
-heapCfg.numZeroBufferPackets= 0;\r
-heapCfg.heapInterfaceTable.data_malloc = pPktifTable->data_malloc;\r
-heapCfg.heapInterfaceTable.data_free = pPktifTable->data_free;\r
-heapCfg.dataBufferPktThreshold = 0;\r
-heapCfg.zeroBufferPktThreshold = 0;\r
-\r
-specialSmall = Pktlib_createHeap(&heapCfg, &errCode);\r
-heapCfg.name = "netapi-big";\r
-heapCfg.dataBufferSize = 1600;\r
-specialLarge = Pktlib_createHeap(&heapCfg, &errCode);\r
-//register these heaps so poll routine will include their garbage queues.\r
-netapi_registerHeap(netapi_handle, specialSmall);\r
-netapi_registerHeap(netapi_handle, specialLarge);\r
-\r
-#ifdef REASSEMBLE_BENCH\r
-our_reassemble_bench(2);\r
-exit(1);\r
-#endif\r
-\r
-/* create a pktio channel */\r
-our_chan=pktio_create(netapi_handle,"our1stq",(PKTIO_CB) recv_cb_bench, &our_chan_cfg,&err);\r
-if (!our_chan) {printf("pktio create failed err=%d\n",err); exit(1);}\r
-\r
-/* open netcp default tx, rx queues */\r
-netcp_tx_chan= pktio_open(netapi_handle, NETCP_TX, NULL, &netcp_tx_cfg, &err);\r
-if (!netcp_tx_chan) {printf("pktio open TX failed err=%d\n",err); exit(1);}\r
-netcp_rx_chan= pktio_open(netapi_handle, NETCP_RX, (PKTIO_CB) recv_cb, &netcp_rx_cfg, &err);\r
-if (!netcp_rx_chan) {printf("pktio open RX failed err=%d\n",err); exit(1);}\r
-\r
-/* create a pktio channel for specially classified pkts */\r
-netcp_rx_chan2= pktio_create(netapi_handle, "classq", (PKTIO_CB) recv_cb, &netcp_rx_cfg2, &err);\r
-if (!netcp_rx_chan2) {printf("pktio create RX2 failed err=%d\n",err); exit(1);}\r
-\r
-/* open netcp default tx, rx queues for sideband crypto */\r
-netcp_sb_tx_chan= pktio_open(netapi_handle, NETCP_SB_TX, NULL, &netcp_sb_tx_cfg, &err);\r
-if (!netcp_sb_tx_chan) {printf("pktio open SB TX failed err=%d\n",err); exit(1);}\r
-netcp_sb_rx_chan= pktio_open(netapi_handle, NETCP_SB_RX, (PKTIO_CB) recv_sb_cb, &netcp_sb_rx_cfg, &err);\r
-if (!netcp_sb_rx_chan) {printf("pktio open SB RX failed err=%d\n",err); exit(1);}\r
-\r
-printf("net_test> %d bytes left in our CMA area\n", netapi_getBufMemRemainder());\r
-/* create scheduler instance */\r
-our_sched =netapi_schedOpen(netapi_handle,&our_sched_cfg, &err);\r
-if (!our_sched) {printf("sched create failed\n"); exit(1);}\r
-\r
-/********************************************\r
-* Basic pkt loopback test\r
-*********************************************/\r
-printf("...running pure push/pop benchmark\n");\r
-our_pktio_bench(1000);\r
-our_pktio_bench(1000);\r
-our_pktio_bench(1000);\r
-our_pktio_bench(1000);\r
-our_pktio_bench(1000);\r
-/*********************************************/\r
-\r
-\r
-\r
-\r
-/* add mac intefaces */\r
-netcp_cfgCreateMacInterface(\r
- netapi_handle,\r
- &mac0[0],\r
- 0,0,\r
- (NETCP_CFG_ROUTE_HANDLE_T) NULL,\r
- (NETCP_CFG_VLAN_T ) NULL , //future\r
- 1, \r
- &err);\r
-if (err) {printf("addmac0 failed %d\n",err); exit(1); } \r
-\r
-//attach an IP to this interface\r
-ip_rule0=netcp_addIp(\r
- netapi_handle,\r
- 0,\r
- nwal_IPV4,\r
- &OurIp0,\r
- NULL, //all IP\r
- (NETCP_CFG_ROUTE_HANDLE_T) NULL,\r
- &err\r
- );\r
-if (err) {printf("addip0 failed %d\n",err); exit(1); } \r
-\r
-//create a 2nd mac instance\r
-netcp_cfgCreateMacInterface(\r
- netapi_handle,\r
- &mac1[0],\r
- 1,1,\r
- (NETCP_CFG_ROUTE_HANDLE_T) NULL,\r
- (NETCP_CFG_VLAN_T ) NULL , //future\r
- 1,\r
- &err);\r
-if (err) {printf("addmac1 failed %d\n",err); exit(1); }\r
-\r
-//attach an IP to this interface\r
-ip_rule1=netcp_addIp(\r
- netapi_handle,\r
- 1,\r
- nwal_IPV4,\r
- &OurIp1,\r
- NULL, //all IP\r
- (NETCP_CFG_ROUTE_HANDLE_T) NULL,\r
- &err\r
- );\r
-if (err) {printf("addip1 failed %d\n",err); exit(1); }\r
-\r
-//attach 2 classifiers to iface 0, ip0\r
-class_0_cfg.u.c_l4.ip = ip_rule0;\r
-class_0 = netcp_cfgAddClass(netapi_handle,\r
- &class_0_cfg,\r
- NULL,\r
- NETCP_CFG_ACTION_TO_SW,\r
- &err);\r
-if (err) {printf("addclass0 failed %d\n",err); exit(1);}\r
-\r
-class_1_cfg.u.c_l4.ip = ip_rule0;\r
-class_1 = netcp_cfgAddClass(netapi_handle,\r
- &class_1_cfg,\r
- NULL,\r
- NETCP_CFG_ACTION_TO_SW,\r
- &err);\r
-if (err) {printf("addclass1 failed %d\n",err); exit(1);}\r
-\r
-\r
-//3rd classifier has a different IP and route\r
-class_2_cfg.u.c_l3_l4.ip_addr = &OurIp2;\r
-\r
-//create specialFlow for this classifier\r
-{\r
-Pktlib_HeapHandle heaps[2];\r
-int sizes[2];\r
-heaps[0]= specialSmall;\r
-heaps[1]= specialLarge;\r
-#define SPECIAL_SOP_OFF 128\r
-sizes[0]=512-SPECIAL_SOP_OFF;\r
-sizes[1]=1600-SPECIAL_SOP_OFF;\r
-specialFlow = netcp_cfgAddFlow( netapi_handle,\r
- 2,\r
- heaps,\r
- sizes,\r
- SPECIAL_SOP_OFF, //offset to start rx is 128 \r
- &err);\r
-if (err) {printf("add flow failed\n", err); exit(1);}\r
-}\r
-#if 0\r
-//special route for this classifier: different flow + destination q\r
-class2_route.p_dest_q = netcp_rx_chan2;\r
-class2_route.p_flow = specialFlow;\r
-class_2 = netcp_cfgAddClass(netapi_handle,\r
- &class_2_cfg,\r
- (void*) &class2_route,\r
- NETCP_CFG_ACTION_TO_SW,\r
- &err);\r
-if (err) {printf("addclass2 failed %d\n",err); exit(1);}\r
-#endif\r
-\r
-//security stuff \r
-ourRXKeyParams.pEncKey = &ourEncrKey[0];\r
-ourRXKeyParams.pAuthKey = &ourAuthKey[0];\r
-memcpy(&rx_sa.src, &TheirIp4IPSEC,4);\r
-memcpy(&rx_sa.dst, &OurIp4IPSEC,4);\r
-\r
-#if 1\r
-rx_tunnel = netapi_secAddSA( netapi_handle,\r
- 0, //iface #0 \r
- &rx_sa,\r
- &ourRXKeyParams,\r
-#ifdef IPSEC_MODE_RX_SIDEBAND\r
- NETAPI_SEC_SA_SIDEBAND,\r
-#else\r
- NETAPI_SEC_SA_INFLOW, //USE inflow mode\r
-#endif\r
- NULL, //use default route \r
- &rx_data_mode_handle,\r
- &rx_inflow_mode_handle,\r
- &err);\r
-if (err) {printf("addRxSa failed %d\n",err); exit(1);}\r
-\r
-#ifdef IPSEC_MODE_RX_INFLOW\r
-//assume inner and outer ip is the same\r
-rx_policy= netapi_secAddRxPolicy( netapi_handle,\r
- rx_tunnel, //link to tunnel above\r
- 4, //ipv4\r
- &TheirIp4IPSEC, //src -> them\r
- &OurIp4IPSEC, //dst -> us\r
- NULL, // no qualifiers\r
- NULL, //default route\r
- &err);\r
-if (err) {printf("addSaPolicy failed %d\n",err); exit(1);}\r
-#else \r
-rx_policy = 0;\r
-#endif\r
-#endif\r
-\r
-//tx SA\r
-//security stuff \r
-ourTXKeyParams.pEncKey = &ourEncrKey[0];\r
-ourTXKeyParams.pAuthKey = &ourAuthKey[0];\r
-memcpy(&tx_sa.src, &OurIp4IPSEC,4);\r
-memcpy(&tx_sa.dst, &TheirIp4IPSEC,4);\r
-tx_tunnel = netapi_secAddSA( netapi_handle,\r
- 0, //iface #0 \r
- &tx_sa,\r
- &ourTXKeyParams,\r
-#ifdef IPSEC_MODE_TX_SIDEBAND\r
- NETAPI_SEC_SA_SIDEBAND,\r
-#else\r
- NETAPI_SEC_SA_INFLOW, //USE inflow mode\r
-#endif\r
- NULL, //use default route \r
- &tx_data_mode_handle,\r
- &tx_inflow_mode_handle,\r
- &err);\r
-if (err) {printf("addTxSa failed %d\n",err); exit(1);}\r
-\r
-\r
-#ifdef TEST_TIMERS\r
-//timers\r
-ourTimerBlock = netapi_TimerGroupCreate(\r
- netapi_handle,\r
- "our1sttimer",\r
- our_timer_cb,\r
- 0, //1 if timers local to thread\r
- 0, //1 if expect to cancel\r
- netapi_getTicksPerSec()/1000, /* 1 msc resolution for these timers */\r
- netapi_getTicksPerSec()/5000, /* would like .5 msc tolerence */\r
- 10, //small # of timers to test garbage collection\r
- &err);\r
-if (err) {printf("timergroupcreate failed %d\n",err); exit(1);}\r
-\r
-//start a couple of timers \r
-t1 = netapi_TimerGroupStartTimer(\r
- ourTimerBlock,\r
- (void *) 1,\r
- 100LL, //timer group ticks\r
- &err);\r
-if (err) {printf("timerstart failed %d\n");}\r
-t2 = netapi_TimerGroupStartTimer(\r
- ourTimerBlock,\r
- (void *) 2,\r
- 200LL, //timer group ticks\r
- &err);\r
-if (err) {printf("timerstart failed %d\n");}\r
-t3 = netapi_TimerGroupStartTimer(\r
- ourTimerBlock,\r
- (void *) 3,\r
- 300LL, //timer group ticks\r
- &err);\r
-if (err) {printf("timerstart failed %d\n");}\r
-#endif\r
-//netcp_cfgReqStats(netapi_handle, our_stats_cb, 1,&err);\r
-if (err!=0) {printf("stats req failed\n");}\r
-\r
-/*********************************************/\r
-/*****************end NETAPI STARTUP**********/\r
-/*********************************************/\r
-\r
-\r
-/********************************************\r
-* Basic pkt loopback test\r
-*********************************************/\r
-printf("...runnining pure push/pop benchmark\n");\r
-our_pktio_bench(100);\r
-\r
-\r
-/**************unused stuff******************/\r
-/* create TRIE */\r
-P_trie = trie_new();\r
-if (!P_trie) {printf("trie alloc failed\n"); exit(1);}\r
-\r
-nat = (HEAD_T *) malloc(NE * sizeof(HEAD_T));\r
-if (!nat) {printf("malloc of nat table failed\n"); exit(1);}\r
-\r
-//gen_pkts(np2process<NP ? np2process:NP);\r
-n_pkt= np2process;\r
-\r
-/* build table */\r
-build_table(P_trie);\r
-\r
-\r
-/* processing loop: get pkt, check it, look up in table, copy new header,\r
- send packet */\r
-srand((unsigned) np2process);\r
-\r
-\r
-/*********************************************/\r
-/**************Entry point into scheduler ****/\r
-/*********************************************/\r
-netapi_schedWaitForEvents(our_sched, &err);\r
-\r
-/* done */\r
-our_stats_cb(netapi_handle, NULL);\r
-\r
-\r
-#define DO_FAST_POLL\r
-#ifdef DO_FAST_POLL\r
-example_fast_poll(netcp_rx_chan);\r
-#endif\r
-\r
-/*************************************************\r
- ************CLEAN UP****************************\r
- ************************************************/\r
-\r
-//delete Classifiers\r
-netcp_cfgDelClass(netapi_handle, class_0, &err); \r
-netcp_cfgDelClass(netapi_handle, class_1, &err); \r
-//netcp_cfgDelClass(netapi_handle, class_2, &err); \r
-\r
-//delete flow \r
-netcp_cfgDelFlow(netapi_handle, specialFlow, &err);\r
-\r
-#if 1\r
-//delete policy\r
-if (rx_policy)\r
- netapi_secDelRxPolicy(netapi_handle, rx_policy, &err);\r
-\r
-//delete tunnels\r
-netapi_secDelSA(netapi_handle, 0, rx_tunnel, &err);\r
-netapi_secDelSA(netapi_handle, 0, tx_tunnel, &err);\r
-#endif\r
-\r
-//delete IPs and MAC Interfacess\r
-netcp_cfgDelIp(netapi_handle, 0, 0, NULL, NULL, ip_rule0, &err);\r
-netcp_cfgDelIp(netapi_handle, 1, 0, NULL, NULL, ip_rule1, &err);\r
-netcp_cfgDelMac(netapi_handle,0,&err);\r
-netcp_cfgDelMac(netapi_handle,1,&err);\r
-\r
-\r
-//close pktio channels we opened\r
-pktio_close(netcp_tx_chan ,&err);\r
-pktio_close(netcp_rx_chan ,&err);\r
-pktio_close(netcp_sb_tx_chan ,&err);\r
-pktio_close(netcp_sb_rx_chan ,&err);\r
-\r
-//clear pktio channel we created\r
-pktio_control(our_chan, (PKTIO_CB) NULL, (PKTIO_CFG_T *) NULL, &zap_channel_control, &err);\r
-pktio_control(netcp_rx_chan2, (PKTIO_CB) NULL, (PKTIO_CFG_T *) NULL, &zap_channel_control, &err);\r
-\r
-//delete pktio channels we created\r
-pktio_delete(our_chan, &err);\r
-pktio_delete(netcp_rx_chan2,&err);\r
-\r
-netapi_shutdown(netapi_handle);\r
-\r
-}\r
-\r
-//EXAMPLE FAST POLL\r
-/* PLD */\r
-void netapi_pld(void * x)\r
-{ \r
- asm volatile("pld [r0]");\r
-}\r
-#include "ti/drv/nwal/nwal_util.h"\r
-\r
-#define M 1008\r
-static int l3_off[M], l4_off[M], L3_chk_ok[M], L4_chk_ok[M], appid[M], len[M] ;\r
-static unsigned char * buf[M];\r
-#define N2POLL 8 //batch size\r
-void example_fast_poll( PKTIO_HANDLE_T * p_pktio)\r
-{\r
-int j=0;\r
-int jj=0;\r
-int i,k,l=0,ltot=0;\r
-int n= N2POLL; //max # of pkts to poll\r
-Ti_Pkt * pHd[N2POLL];\r
-Ti_Pkt * tempVA;\r
-pasahoLongInfo_t* pinfo;\r
-unsigned long t1;\r
-unsigned long t2;\r
-unsigned long t11;\r
-unsigned long t12;\r
-unsigned long np;\r
-unsigned long sumt=0;\r
-unsigned long sumf=0;\r
-unsigned long sump=0;\r
-unsigned long totlen=0;\r
-int max_batch=0;\r
-\r
-//this should be done once and saved\r
-Qmss_QueueHnd rxQ= PKTIO_GET_DEFAULT_NETCP_Q(p_pktio);\r
-Qmss_QueueHnd freeQ;\r
-//loop forever\r
-for(;;)\r
-{\r
- t1= netapi_timing_stop();\r
- pHd[0] = (Ti_Pkt *)QMSS_DESC_PTR(PKTIO_QMSS_QUEUE_POP_RAW (rxQ));\r
- if (!pHd[0]) continue;\r
- //got pkt\r
- for(i=1;(i<n) && (pHd[i-1]);i++)\r
- {\r
- //convert previous descriptor PA -> VA\r
- tempVA = Osal_qmssPhyToVirt(pHd[i-1]); \r
-\r
- //try and preload desriptor\r
- __builtin_prefetch(tempVA);\r
- //netapi_pld(tempVA);\r
-\r
- //read next descriptor from queue \r
- pHd[i] = (Ti_Pkt *)QMSS_DESC_PTR(PKTIO_QMSS_QUEUE_POP_RAW (rxQ));\r
-#if 1 \r
- /* extract some meta data */\r
- Cppi_getData (Cppi_DescType_HOST, (Cppi_Desc*)tempVA, &buf[jj], &len[jj]);\r
- pinfo = PKTIO_GET_PROTO_INFO(tempVA);\r
- l3_off[jj]= PKTIO_GET_L3_OFFSET(pinfo);\r
- l4_off[jj]= PKTIO_GET_L4_OFFSET(pinfo);\r
- appid[jj]= PKTIO_GET_APPID(tempVA);\r
-//#define VERIFY_SOP\r
-#ifdef VERIFY_SOP\r
- if (sump < 200) printf("..sop off=%d\n", (int) buf[jj]-\r
- (int) ((Cppi_HostDesc *) tempVA)->origBuffPtr) ;\r
-#endif\r
-#endif\r
- jj+=1;\r
- }\r
- //finish last pkt in burst\r
- if(pHd[i-1])\r
- {\r
- //convert previous descriptor PA -> VA\r
- tempVA = Osal_qmssPhyToVirt(pHd[i-1]); \r
-\r
- /* extract some meta data */\r
-#if 1\r
- pinfo = PKTIO_GET_PROTO_INFO(tempVA);\r
- l3_off[jj]= PKTIO_GET_L3_OFFSET(pinfo);\r
- l4_off[jj]= PKTIO_GET_L4_OFFSET(pinfo);\r
- appid[jj]= PKTIO_GET_APPID(tempVA);\r
-#endif\r
- //get ptr (Physical address) and length of associate buffer\r
- Cppi_getData (Cppi_DescType_HOST, (Cppi_Desc*)tempVA, &buf[jj], &len[jj]);\r
- jj+=1;\r
- }\r
- t2= netapi_timing_stop();\r
- j+=(pHd[i-1]? i: (i-1)) ;\r
- if (jj>(M-n)) jj=0;\r
- l+=1; //n batches\r
- ltot+=1;\r
- if(pHd[i-1])\r
- {\r
- if (i>max_batch) max_batch= i;\r
- }\r
- else\r
- {\r
- if( (i-1) >max_batch) max_batch = i-1;\r
- }\r
-\r
- //cleanup\r
- //printf("cleanup %d\n",i);\r
- for(k=0;k<i;k++)\r
- {\r
- //cleanup. need to covert all of desriptor to VA so that i can use freePacket() \r
- //alternative would be to just do cache ops plus descriptor raw push to pktlib\r
- // heap free queue\r
- if(pHd[k])\r
- {\r
-\r
- //tempVA=Qmss_osalConvertDescPhyToVirt(pHd[k]);\r
- tempVA = Osal_qmssPhyToVirt(pHd[k]);\r
- freeQ=Qmss_getQueueHandle(Cppi_getReturnQueue (Cppi_DescType_HOST, tempVA));\r
- netapi_utilCacheWbInv(tempVA,128);\r
- //would need to wbInv buffer also in practice. Also need to walk\r
- // descriptor chain \r
- t11= netapi_timing_stop();\r
- // Pktlib_freePacket(tempVA);\r
- PKTIO_QMSS_QUEUE_PUSH_DESC_SIZE_RAW (freeQ,\r
- (void *) pHd[k],\r
- 128);\r
-\r
- t12= netapi_timing_stop();\r
- sumf += (t12-t11); \r
- }\r
- }\r
- sumt += (t2-t1);\r
- sump +=(pHd[i-1]? i: (i-1));\r
- //printf("end cleanup %d %d %d\n",sumt,sumf,sump );\r
- if (sump > 10000) {\r
- printf("pkts rx %d batches=%d appid=%x l3_off=%d l4_off=%d len=%d buf=0x%x rxcycle= %d pkts/batchx1000=%d maxbatch=%d cycles per rawpush = %d\n", \r
- j,ltot, appid[j%M], \r
- l3_off[j%M],l4_off[j%M], \r
- len[j%M],buf[j%M],\r
- sumt/sump, (sump*1000)/l, max_batch,\r
- sumf/sump);\r
- sumt=sump=sumf=0;\r
- l=0;\r
- }\r
-}\r
-\r
-\r
-}\r
-\r
-\r
+/******************************************
+ * File: net_test.c
+ * Purpose: test app for netapi
+ **************************************************************
+ * FILE: net_test.c
+ *
+ * DESCRIPTION: netapi user space transport
+ * library test application
+ *
+ * REVISION HISTORY: rev 0.0.1
+ *
+ * Copyright (c) Texas Instruments Incorporated 2010-2011
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+
+#include "trie.h"
+#include "string.h"
+#include "netapi.h"
+#include "pktio.h"
+#include <sys/resource.h>
+
+//IPSEC MODE(only choose one rx and one tx)
+#define IPSEC_MODE_RX_INFLOW
+#define IPSEC_MODE_TX_INFLOW
+//#define IPSEC_MODE_RX_SIDEBAND
+//#define IPSEC_MODE_TX_SIDEBAND
+
+//#define TEST_TIMERS
+
+/*************debug********************/
+void dump_descr(unsigned long *p, int n)
+{
+ printf("--------dump of descriptor %d %x\n", n, (int) p);
+ printf("> %x %x %x %x %x %x %x %x\n",p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7]);
+ printf("> %x %x %x %x %x %x %x %x\n",p[8],p[9],p[10],p[11],p[12],p[13],p[14],p[15]);
+ printf("-----------------------------\n");
+}
+void dump_header(unsigned long *p, int n, int a, int r)
+{
+ printf("--------dump of header %d %x appID=%x flag1=%x\n", n, (int) p,a,r);
+ printf("> %x %x %x %x %x %x %x %x\n",p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7]);
+ printf("> %x %x %x %x %x %x %x %x\n",p[8],p[9],p[10],p[11],p[12],p[13],p[14],p[15]);
+ printf("> %x %x %x %x %x %x %x %x\n",p[16],p[17],p[18],p[19],p[20],p[21],p[22],p[23]);
+ printf("> %x %x %x %x %x %x %x %x\n",p[24],p[25],p[26],p[27],p[28],p[29],p[30],p[31]);
+ printf("-----------------------------\n");
+}
+
+/*****************************************/
+
+
+//************for multi pkt burst xfer test in loopback mode
+#define TX_BURST 800
+int pktloopback=TUNE_NETAPI_NWAL_ENABLE_PASS_LOOPBACK;
+nwalTxPSCmdInfo_t flowPSCmdInfo;
+
+//this device: 10.0.0.100, mac 0x,01,02,03,04,05 and .. 0x6
+
+//test packet, setup for loopback (so dest is ourself)
+static uint8_t testPkt[] = {
+
+ /* MAC header */
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
+ 0x00, 0xe0, 0xa6, 0x66, 0x57, 0x04,
+ 0x08, 0x00,
+
+ /* IP header */
+ 0x45, 0x00,
+ 0x00, 0x6c, /* Length (including this header) */
+ 0x00, 0x00, 0x00, 0x00, 0x05, 0x11,
+ 0x00, 0x00, /* Header checksum */
+ 0x0a, 0x00, 0x00, 0x0a, 0x0a, 0x00, 0x00, 0x64,
+
+ /* UDP header */
+ 0x12, 0x34, 0x05, 0x55,
+ 0x00, 0x58, /* Length, including this header */
+ 0x00, 0x00, /* Header checksum */
+
+ /* Payload */
+ 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
+ 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41,
+ 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
+ 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51,
+ 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
+ 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61,
+ 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
+ 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71,
+ 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
+ 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81
+
+};
+
+#define TEST_PAYLOAD_LEN 80
+
+#define TEST_PKT_IP_OFFSET_BYTES 14
+#define TEST_PKT_UDP_OFFSET_BYTES 34
+#define TEST_PKT_PLOAD_OFFSET_BYTES 42
+#define TEST_PKT_UDP_HDR_LEN 8
+/* Offsets to length fields */
+#define TEST_PKT_OFFSET_IP_LEN 16
+#define TEST_PKT_OFFSET_UDP_LEN 38
+
+#define TEST_PKT_LEN 122
+
+/* The pseudo header checksum of the packet except for the 16 bit length */
+#define TEST_PKT_PSEUDO_HDR_CHKSUM_SANS_LEN 0x0FFC
+
+void example_fast_poll( PKTIO_HANDLE_T * p_pktio);
+
+#if 1
+//#include "arpa/inet.h"
+long htonl(long x)
+{
+ long temp = (x&0xff000000)>>24 | (x&0xff0000)>>8 | (x&0xff00)<<8 | (x&0xff)<<24 ;
+ return temp;
+}
+
+/********************************************************************
+ * FUNCTION PURPOSE: Ones complement addition utility
+ ********************************************************************
+ ********************************************************************/
+uint16_t test_utilOnesComplementAdd (uint16_t v1, uint16_t v2)
+{
+ uint32_t result;
+
+ result = (uint32_t)v1 + (uint32_t)v2;
+ result = (result >> 16) + (result & 0xffff);
+ result = (result >> 16) + (result & 0xffff);
+
+ return ((uint16_t)result);
+}
+
+/********************************************************************
+ * FUNCTION PURPOSE: Ones complement checksum utility
+ ********************************************************************
+ ********************************************************************/
+ uint16_t test_utilOnesCompChkSum (uint8_t *p, uint32_t nwords)
+{
+ uint16_t chksum = 0;
+ uint16_t v;
+ uint32_t i;
+ uint32_t j;
+
+ for (i = j = 0; i < nwords; i++, j+=2) {
+ v = (p[j] << 8) | p[j+1];
+ chksum = test_utilOnesComplementAdd (chksum, v);
+ }
+ return (chksum);
+} /* utilOnesCompChkSum */
+
+/**************************************************************************************
+ * FUNCTION PURPOSE: Compute ipv4 psudo checksum
+ **************************************************************************************
+ * DESCRIPTION: Compute ipv4 psudo checksum
+ **************************************************************************************/
+uint16_t test_utilGetIpv4PsudoChkSum (uint8_t *data, uint16_t payloadLen)
+{
+ uint16_t psudo_chksum;
+
+ psudo_chksum = test_utilOnesCompChkSum (&data[12], 4);
+ psudo_chksum = test_utilOnesComplementAdd(psudo_chksum, (uint16_t) data[9]);
+ psudo_chksum = test_utilOnesComplementAdd(psudo_chksum, payloadLen);
+
+ return (psudo_chksum);
+
+} /* utilGetIpv4PsudoChkSum */
+
+
+
+#endif
+typedef struct stats_t
+{
+ long itx; //initially generated
+ long itx2;
+ long rx;
+ long tx;
+ long n_bad;
+ long n_new;
+ long n_class0_rx; //count of pkts classified
+ long n_class1_rx; //count of pkts classified
+ long n_class2_rx; //count of pkts classified
+ long n_t1;
+ long n_t2;
+ long n_t3;
+ long sec_tx;
+ long sec_rx;
+ long sb_tx;
+ long sb_rx;
+ long secp_rx;
+ long n_auth_ok;
+} STATS_T;
+
+typedef struct head_t
+{
+ long ip[5];
+ long udp[2];
+} HEAD_T;
+
+typedef struct key_t
+{
+ long src_ip;
+ long dst_ip;
+ short src_port;
+ short dst_port;
+} KEY_T;
+
+unsigned char mac0[]={0x00,0x01,0x02,0x03,0x04,0x05}; //interface 0
+unsigned char mac1[]={0x00,0x01,0x02,0x03,0x04,0x06}; //interface 1
+nwalIpAddr_t OurIp0={ 10, 0, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+nwalIpAddr_t OurIp1={ 10, 0, 1, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+nwalIpAddr_t OurIp2={ 10, 0, 2, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+nwalIpAddr_t OurIp4IPSEC={ 192,168 , 1, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+nwalIpAddr_t TheirIp4IPSEC={ 192,168 , 1, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+
+
+#if 1 //goes with real tx (to laptop)
+unsigned char real_mac_header[]={0xd4,0xbe,0xd9,0x00,0xd3,0x7e,
+ 0x00,0x01,0x02,0x03,0x04,0x05,
+ 0x08,0x00};
+unsigned char real_ip_addr[]={0xa,0x00,0x00,0x64,0xa,0x0,0x0,0xa};
+#endif
+
+#if 0 //goes with loopback
+unsigned char mac_header[]={0x00,0x01,0x02,0x03,0x04,0x05,
+ 0x00,0x11,0x22,0x33,0x44,0x55,
+ 0x08,0x00};
+#endif
+#define NE 65536
+HEAD_T *nat;
+
+#define NP 5000
+int n_pkt = NP;
+STATS_T stats;
+
+Trie * P_trie;
+HEAD_T pkts[NP];
+#define PERSLOW 10 //% of pkts that will not be fastpath'd
+int perslow= PERSLOW;
+
+/*******************************************
+ *************NETAPI OBJECTS***************
+ *****************************************/
+static NETAPI_CFG_T our_netapi_default_cfg=
+{
+TUNE_NETAPI_PERM_MEM_SZ,
- 256, //start of packet offset for hw to place data on rx for default flow
++128, //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
- 0, //#descriptors w/o buffers in default heap
- TUNE_NETAPI_DEFAULT_BUFFER_SIZE+256 //size of buffers in default heap
++64, //#descriptors w/o buffers in default heap
++TUNE_NETAPI_DEFAULT_BUFFER_SIZE+128+128, //size of buffers in default heap
++128 , //tail room
++256 //extra room
+};
+
+Pktlib_HeapHandle OurHeap;
+Pktlib_HeapHandle specialSmall;
+Pktlib_HeapHandle specialLarge;
+
+PKTIO_HANDLE_T *our_chan;
+PKTIO_HANDLE_T *netcp_rx_chan;
+PKTIO_HANDLE_T *netcp_rx_chan2;
+PKTIO_HANDLE_T *netcp_tx_chan;
+PKTIO_HANDLE_T *netcp_sb_tx_chan;
+PKTIO_HANDLE_T *netcp_sb_rx_chan;
+PKTIO_CFG_T our_chan_cfg={PKTIO_RW, PKTIO_LOCAL, PKTIO_Q_ANY, 8};
+PKTIO_CFG_T netcp_rx_cfg={PKTIO_R, PKTIO_NA, PKTIO_NA, 8};
+PKTIO_CFG_T netcp_rx_cfg2={PKTIO_R, (PKTIO_GLOBAL|PKTIO_PKT), PKTIO_Q_ANY, 8};
+PKTIO_CFG_T netcp_tx_cfg={PKTIO_W, PKTIO_NA, PKTIO_NA, 8};
+PKTIO_CFG_T netcp_sb_rx_cfg={PKTIO_R, PKTIO_NA, PKTIO_NA, 8};
+PKTIO_CFG_T netcp_sb_tx_cfg={PKTIO_W, PKTIO_NA, PKTIO_NA, 8};
+
+void house(NETAPI_SCHED_HANDLE_T *s);
+NETAPI_T netapi_handle;
+NETAPI_SCHED_HANDLE_T * our_sched;
+NETAPI_SCHED_CONFIG_T our_sched_cfg={
+ NETAPI_SCHED_DURATION|NETAPI_SCHED_CBV, 0, house, 50000 //every 5000 poll loops
+};
+void our_stats_cb(NETAPI_T h, paSysStats_t* pPaStats);
+NETAPI_TIMER_GROUP_HANDLE_T ourTimerBlock;
+NETAPI_TIMER_T t1;
+NETAPI_TIMER_T t2;
+NETAPI_TIMER_T t3;
+
+void our_timer_cb( NETAPI_TIMER_GROUP_HANDLE_T th,
+ int n_fired, //# timers fired
+ NETAPI_TIMER_LIST_T fired_list,
+ uint64_t currentTime);
+
+NETCP_CFG_IP_T ip_rule0;
+NETCP_CFG_IP_T ip_rule1;
+NETCP_CFG_CLASS_T class_0;
+NETCP_CFG_CLASS_T class_1;
+NETCP_CFG_CLASS_T class_2;
+NETCP_CFG_FLOW_HANDLE_T specialFlow;
+
+NETCP_CFG_CLASSIFIER_T class_0_cfg=
+{
+ NETCP_CFG_CLASS_TYPE_L4,
+ {
+ {0,0, NWAL_APP_PLOAD_PROTO_UDP, {2500}}
+ }
+};
+
+NETCP_CFG_CLASSIFIER_T class_1_cfg=
+{
+ NETCP_CFG_CLASS_TYPE_L4,
+ {
+ {0,0, NWAL_APP_PLOAD_PROTO_UDP, {2502}}
+ }
+};
+
+NETCP_CFG_ROUTE_T class2_route=
+{
+NULL, NULL //* to be filled in
+};
+NETCP_CFG_CLASSIFIER_T class_2_cfg=
+{
+ NETCP_CFG_CLASS_TYPE_L3_L4,
+ {
+ {0, 4 ,0/*fill in below*/ , NULL, NULL, //L2/L3
+ NWAL_APP_PLOAD_PROTO_UDP, {2504}} //L4
+ }
+};
+
+PKTIO_CONTROL_T zap_channel_control={PKTIO_CLEAR, NULL};
+
+/* security objects. (for loopback mode) */
+NETCP_CFG_SA_T rx_tunnel;
+NETCP_CFG_SA_T tx_tunnel;
+NETCP_CFG_IPSEC_POLICY_T rx_policy;
+void * rx_data_mode_handle;
+void * tx_data_mode_handle;
+void * rx_inflow_mode_handle;
+void * tx_inflow_mode_handle;
+/* rx */
+NETAPI_SEC_SA_INFO_T rx_sa=
+{
+ NWAL_SA_DIR_INBOUND,
+ 0x44444444, //spi
+ nwal_IpSecProtoESP, //ESP mode
+ nwal_SA_MODE_TUNNEL, //tunnel mode
+ nwal_IPV4, //v4
+ { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (them) -> set below */
+ { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (us)-> set below*/
+ 64,/* replayWindow */
+ NWAL_SA_AALG_HMAC_SHA1,
+ NWAL_SA_EALG_AES_CBC,
+ 0,0 //na
+};
+
+/*tx */
+NETAPI_SEC_SA_INFO_T tx_sa=
+{
+ NWAL_SA_DIR_OUTBOUND,
+ 0x44444444, //spi
+ nwal_IpSecProtoESP, //ESP mode
+ nwal_SA_MODE_TUNNEL, //tunnel mode
+ nwal_IPV4, //v4
+ { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Src IP (us) -> set below */
+ { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* dst IP (them) -> set below*/
+ 64, /* NA replayWindow */
+ NWAL_SA_AALG_HMAC_SHA1,
+ NWAL_SA_EALG_AES_CBC,
+ 0,0 //seq no
+};
+
+//since we are doing loopback, the rx key params = tx key params
+static nwalSecKeyParams_t ourTXKeyParams =
+{
+ 16, /* encKeySize: CTR 16 bytes Encryption Key and 4 bytes Salt : 24 bytes:NWAL_SA_EALG_DES_CBC and 0 bytes Salt*/
+ 20, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_MD5 */
+ NULL, //set below
+ NULL, //set below
+};
+
+static nwalSecKeyParams_t ourRXKeyParams ={
+ 16, /* encKeySize: 16 bytes Encryption Key and 4 bytes Salt : 24 bytes:NWAL_SA_EALG_DES_CBC and 0 bytes Salt*/
+ 20, /* macKeySize: 16 bytes NWAL_SA_AALG_HMAC_MD5 */
+ NULL, //set below
+ NULL, //set below
+};
+
+//keys
+static uint8_t ourAuthKey[36] =
+ {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
+ 0x20, 0x21, 0x22, 0x23 };
+static uint8_t ourEncrKey[36] =
+ {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
+ 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
+ 0x30, 0x31, 0x32, 0x33 };
+
+
+/*************************END NETAPI OBJECTS***********************/
+
+#define START_SRC_IP 0x0a00000a
+#define DST_IP 0xc0a80001
+#define NEW_START_SRC_IP 0x9eda000a
+#define DST_PORT 0x555
+#define START_SRC_PORT 0x1234
+#define NEW_START_SRC_PORT 100
+void update_header(HEAD_T * p_head, int len)
+{
+ unsigned char *p = (unsigned char *) &p_head->udp[1];
+ len -= (20+14);
+ /* update ip checksum */
+ /* update udp checksum */
+ /* update length */
+ *p= (len&0xff00)>>8;
+ *(p+1) = len&0xff;
+}
+
+#if 0
+void gen_pkts(int np)
+{
+int i;
+int ip = START_SRC_IP &0xff;
+int port= START_SRC_PORT;
+//HEAD_T temp={{0x25000200,0xdead0000,0x80110000,START_SRC_IP,DST_IP},
+// {START_SRC_PORT<<16|DST_PORT,0x01ec<<16|0x0000}};
+HEAD_T temp;
+memcpy(&temp,&testPkt[0],sizeof(HEAD_T));
+
+for(i=0;(i<np) && (i<NP);i++)
+ {
+ memcpy(&pkts[i],&temp,sizeof(temp));
+ update_header(&pkts[i],512); /* update checksums etc */
+ /* change template for new pkt */
+ ip+=1;
+ if(ip>254) {(ip=START_SRC_IP&0xff); port+=1; }
+ temp.ip[3] = htonl((START_SRC_IP&0xffffff00)| ip);
+ temp.udp[0] = htonl( (temp.udp[0]&0xffff0000)| port);
+ temp.udp[1] = htonl(temp.udp[1]);
+
+ }
+ n_pkt=np;
+}
+#endif
+
+void build_table(Trie * p_trie)
+{
+int i;
+int sport=NEW_START_SRC_PORT;
+HEAD_T temp,temp2;
+KEY_T key;
+
+memcpy(&temp,&testPkt[14],sizeof(temp));
+
+ //insert entry into trie
+key.src_ip = temp.ip[3];
+key.dst_ip = temp.ip[4];
+key.src_port= (temp.udp[0]&0xffff0000)>>16;
+key.dst_port= (temp.udp[0]&0x0000ffff);
+trie_insert(p_trie,(char *)&key,sizeof(key), (void *) &nat[0]); //asociate with nat entry 0
+
+//build nat table
+for(i=0;i<100;i++)
+{
+ memcpy(&temp2,&testPkt[14],sizeof(temp));
+ temp2.udp[0] = (temp2.udp[0] & 0xffff0000) | sport;
+ memcpy(&nat[i], &temp2, sizeof(temp2));
+ sport+= 1;
+}
+}
+
+//===========stub transmitter==================
+void send_pkt(Ti_Pkt *pkt, int len)
+{
+//just free pkt. Don't send
+Pktlib_freePacket((Ti_Pkt*)pkt);
+ return;
+}
+
+//==========stub slow path============
+void slow_path(Ti_Pkt *pkt, int len)
+{
+// debug: check descriptor for validity by verifying that desciptor link field is null as expected\n");
+ {Ti_Pkt * k= Pktlib_getNextPacket(pkt); if(k != 0) {printf(" slowpath, nexpkt != NULL");}}
+//just free pkt
+Pktlib_freePacket((Ti_Pkt*)pkt);
+ return;
+}
+/* check header */
+struct LastPktInfo
+{
+int iface;
+int ipcsum;
+int l4csum;
+} ;
+static struct LastPktInfo lpInfo;
+
+int check_header(HEAD_T * p_head, PKTIO_METADATA_T * p_meta)
+{
+if (NWAL_RX_FLAG1_META_DATA_VALID & p_meta->u.rx_meta->rxFlag1)
+{
+lpInfo.iface = ((unsigned int)p_meta->u.rx_meta->appId) &0xff; //last byte is interface num
+lpInfo.ipcsum =(p_meta->u.rx_meta->rxFlag1 & NWAL_RX_FLAG1_IPV4_CHKSUM_VERIFY_MASK )== NWAL_RX_FLAG1_IPV4_CHKSUM_VERIFY_ACK ? 1 : 0;
+lpInfo.l4csum = (p_meta->u.rx_meta->rxFlag1 & NWAL_RX_FLAG1_L4_CHKSUM_VERIFY_MASK )== ((NWAL_RX_FLAG1_L4_CHKSUM_VERIFY_ACK) << NWAL_RX_FLAG1_L4_CHKSUM_VERIFY_SHIFT) ? 1 : 0;
+if ((unsigned int)p_meta->u.rx_meta->appId & NETAPI_NETCP_MATCH_IPSEC)
+{
+ stats.sec_rx++;
+}
+if ((unsigned int)p_meta->u.rx_meta->appId & NETAPI_NETCP_MATCH_IPSEC_POLICY)
+{
+ stats.secp_rx++;
+}
+
+if ((unsigned int)p_meta->u.rx_meta->appId & NETAPI_NETCP_MATCH_CLASS)
+{
+ int c= ((unsigned int)p_meta->u.rx_meta->appId >>8)&0xffff;
+ if (c==0) stats.n_class0_rx +=1;
+ else if (c==1) stats.n_class1_rx +=1;
+ else if (c==2) stats.n_class2_rx +=1;
+ else printf("**NET_TEST RX -unknown class: %x\n", p_meta->u.rx_meta->appId);
+}
+}
+
+ return 1;
+}
+
+#define PKT_LEN 1400
+void test_alloc_free(int n)
+{
+int i;
+Ti_Pkt * b;
+
+for(i=0;i<n;i++)
+{
+ b=Pktlib_allocPacket(OurHeap,PKT_LEN);
+ Pktlib_freePacket(b);
+}
+}
+
+//measurement test points
+unsigned int vv1;
+unsigned int vv2;
+unsigned int vv3;
+unsigned int vv4;
+unsigned int vv5;
+unsigned int vv6;
+//these are updated by pktio.
+unsigned int vv7p;
+unsigned int vv8p;
+unsigned int vv9p;
+unsigned int vv10p;
+unsigned int vv11p;
+unsigned int vv12p;
+
+unsigned int vv11;
+
+unsigned int vv13p; //rcv path
+unsigned int vv14p;
+unsigned int vv15p;
+
+extern unsigned int nwal_prof1,nwal_prof2,nwal_prof3,nwal_prof4,nwal_prof5,nwal_prof6;
+
+//#define REASSEMBLE_BENCH
+#ifdef REASSEMBLE_BENCH
+#include <ti/drv/pa/example/reassemLib/reassemLib.h>
+/*--------------reassembly benchmark--------------------------------*/
+void our_reassemble_bench(int nfrags)
+{
+paIPReassemblyConfig_t Config={5,128,10000 };
+int i,j;
+int len;
+Ti_Pkt tip;
+char *buffer;
+unsigned long v1;
+unsigned long v2;
+unsigned long sum1=0;
+unsigned long sum2=0;
+paEx_reassemLibInit(&Config);
+for(j=0;j<200/nfrags;j++)
+{
+ for(i=0;i<nfrags;i++)
+ {
+ short temp;
+ tip=Pktlib_allocPacket(OurHeap,PKT_LEN);
+ Pktlib_getDataBuffer(tip,(uint8_t**)&buffer,&len);
+ memcpy(&buffer[0],&testPkt[14],20); //IP header
+ if (i < (nfrags-1)) buffer[6] = 0x20;
+ temp = i*40;
+ buffer[6]|= (temp&0x1f00)>>8;
+ buffer[7]= (temp&0xff);
+ temp = 20+40*8;
+ buffer[2]= (temp&0xff00)>>8;
+ buffer[3]= (temp&0xff);
+ Pktlib_setPacketLen(tip, temp);
+ v1= netapi_timing_stop();
+ paEx_reassemLibProc(tip, 0xffff);
+ v2= netapi_timing_stop();
+ sum1+= v2-v1;
+ }
+ sum2 += v2-v1;
+}
+printf("reasssembly test: %d trials, %d frags/pkt %d cycles/frag %d cycles/last frag\n",j,nfrags, sum1/(j*nfrags), sum2/(j));
+}
+#endif
+
+/*--------------basic pktio send/recv benchmark----------------------*/
+unsigned int timings[10];
+void our_pktio_bench(int ntrials)
+{
+int i;
+#define NBATCH 8
+Ti_Pkt tip;
+unsigned char * pData;
+int len;
+int n;
+int err;
+int sum =0;
+
+ Osal_cache_op_measure_reset();
+ for(i=0;i<10;i++) timings[i]=0;
+ printf("calibration loop .. ");
+ for(i=0;i<1000;i++)
+ {
+ vv1= netapi_timing_stop();
+ vv2= netapi_timing_stop();
+ sum+=(vv2-vv1);
+ }
+ printf(" accuracy = +- %d cycles\n", sum/1000);
+ sleep(1);
+
+PKTIO_METADATA_T meta[10]={0};
+//send single, recv single
+for(i=0;i<ntrials;i++)
+{
+ vv1= netapi_timing_stop();
+ tip=Pktlib_allocPacket(OurHeap,PKT_LEN);
+ vv2= netapi_timing_stop();
+ Pktlib_getDataBuffer(tip,&pData,&len);
+ vv3= netapi_timing_stop();
+ pktio_send(our_chan,tip,&meta[0],&err);
+ vv4= netapi_timing_stop();
+ n=pktio_poll(our_chan,NULL , &err);
+ vv5= netapi_timing_stop();
+ timings[0]+=(vv6-vv4);
+ timings[1]+=(vv5-vv4);
+ timings[2]+=(vv7p-vv4);
+ timings[3]+=(vv4-vv3);
+ timings[4]+=(vv8p-vv3);
+ timings[5]+=(vv3-vv1);
+ timings[6]+=(vv9p-vv8p);
+ timings[7]+=(vv10p-vv7p);
+ timings[8]+=(vv11-vv6);
+}
+ printf("pktio bench. rx=%d (wcb%d) (toqm%d) tx=%d (toqm%d) alloc=%d qpush=%d qpop=%d free=%d\n", timings[0]/ntrials,
+ timings[1]/ntrials, timings[2]/ntrials,timings[3]/ntrials, timings[4]/ntrials,timings[5]/ntrials,
+ timings[6]/ntrials,timings[7]/ntrials, timings[8]/ntrials );
+ printf("raw qpop = %d raw qpush = %d pa2va = %d ", pktio_get_qop_time(),
+ pktio_get_qpush_time(),
+ pktio_get_pa2va_time());
+{
+ unsigned int ccycles;
+ int n_c_ops;
+ ccycles =Osal_cache_op_measure(&n_c_ops);
+ printf("n_c_ops=%d cache_op_time=%d (total) = %d (pp)\n", n_c_ops, ccycles, n_c_ops? (ccycles/(n_c_ops)) : 0);
+}
+
+}
+/*-----------test driver: gen an input pkt------- */
+//char buffer[sizeof(HEAD_T)+PKT_LEN];
+Ti_Pkt * get_pkt(int n, unsigned int *p_len)
+{
+ int ind;
+ long long temp;
+ Ti_Pkt * b;
+ char * buffer;
+ unsigned int len;
+
+ if (pktloopback==0)
+ {
+ if (n>=TX_BURST) return NULL; //just gen pkts to warm swtich, so that it knows
+ //our mac is valid
+ }
+ b=Pktlib_allocPacket(OurHeap,PKT_LEN);
+ if (!b)
+ {printf("net_test: get_pkt() heap empty!! %d pkts gen'd %d \n", n); return NULL;};
+
+ //debug - way to validate descriptor
+ {Ti_Pkt* k= Pktlib_getNextPacket(b);
+ if(k != 0) {printf(" genpkt, nexpkt != NULL");}}
+
+
+ //get pointer to buffer area of packet
+ Pktlib_getDataBuffer(b,(uint8_t**)&buffer,&len);
+ if (!buffer)
+ {printf("net_test: get_pkt() heap returned empty buffer %d \n", n); return NULL;};
+
+#if 0
+if (pktloopback==0)
+{
+ temp = (long long) rand();
+ temp *= PKT_LEN;
+ temp /= RAND_MAX;
+ temp +=2;
+ *p_len = (int) temp;
+ *p_len = *p_len &0xfffffffe;
+ temp = (long long) rand();
+ temp *= n_pkt;
+ temp /= RAND_MAX;
+ ind = (int) temp;
+ update_header(&pkts[ind],*p_len);
+ //printf("get pkt:%d %d ind=%d len=%d\n",RAND_MAX, rand(),ind, *p_len);
+ memcpy(&buffer[0], &mac_header[0],14);
+ memcpy(&buffer[14],(char*)&pkts[ind],sizeof(HEAD_T));
+}
+else
+#endif
+
+ //copy test packet into buffer
+{
+ memcpy(&buffer[0], &testPkt[0],TEST_PKT_LEN);
+ *p_len = TEST_PKT_LEN;
+}
+ return b;
+}
+
+
+/*--------------------------------------------------------------
+ *----------utility to flip a packet and send
+ *--------------------back to source----------------------------
+ * flag=1 => ipsec
+ *--------------------------------------------------------------*/
+void flip_and_send_pkt(Ti_Pkt *tip, unsigned char * p_pkt, int len, int flag)
+{
+unsigned char mac_temp[6];
+unsigned char ip_temp[4];
+unsigned char new_dest_port[2]={0x75,0x30}; // 30000
+uint16_t blah;
+//mac
+memcpy(&mac_temp,&p_pkt[0],6);
+memcpy(&p_pkt[0],&p_pkt[6],6);
+memcpy(&p_pkt[6],&mac_temp,6);
+//memcpy(&p_pkt[0],real_mac_header,6); //for testing to wireshark pc
+
+//ip (outer in case of ipsec)
+memcpy(&ip_temp, &p_pkt[14+12],4);
+memcpy(&p_pkt[14+12],&p_pkt[14+12+4],4);
+memcpy(&p_pkt[14+12+4],&ip_temp,4);
+
+//outer checksum to 0
+if (!flag) memset(&p_pkt[14+10],0,2);
+
+//inner ip &udp for ipsec
+if (flag)
+{
+ //just drop non-udp packet
+ if (p_pkt[14+20+8+16+9]!=0x11)
+ {
+ stats.n_new+=1;Pktlib_freePacket(tip); return;
+ }
+
+//spi
+//memset(&p_pkt[14+20],0x88,4);
+//inner ip
+memcpy(&ip_temp, &p_pkt[14+20+8+16+12],4);
+memcpy(&p_pkt[14+20+8+16+12],&p_pkt[14+20+8+16+12+4],4);
+memcpy(&p_pkt[14+20+8+16+12+4],&ip_temp,4);
+
+//udp
+memcpy(&p_pkt[14+20+8+16+20+2],&new_dest_port[0],2);
+memset(&p_pkt[14+20+8+16+20+6],0,2); //checksum
+
+#ifdef IPSEC_MODE_TX_SIDEBAND
+
+//inner ip checksum : leave alone
+#if 0
+blah=test_utilOnesCompChkSum (&p_pkt[14+20+8+16], 10);
+p_pkt[14+20+8+16+10]= (blah&0xff00)>>8;
+p_pkt[14+20+8+16+11]= blah&0xff;
+#endif
+
+//tbd udp checksum (leave at 0)
+
+//outer ip, set to 0 (we will compute on way out
+memset(&p_pkt[14+10],0,2);
+
+#else //inflow, don't touch outer , clear inner
+memset(&p_pkt[14+20+8+16+10],0,2); //inner checksum, we will compute on way out
+//outer ip checksum : leave alone
+#if 0
+blah = test_utilOnesCompChkSum (&p_pkt[14], 10);
+p_pkt[14+10]= (blah&0xff00)>>8;
+p_pkt[14+11]= blah&0xff;
+#endif
+#endif
+}
+else
+{
+memset(&p_pkt[14+20+6],0,2);//0 udp checksum (we will compute on way out
+memcpy(&p_pkt[14+20+2],&new_dest_port[0],2);
+}
+
+//IPSEC case,
+if (flag)
+{
+#ifdef IPSEC_MODE_TX_SIDEBAND
+ //send to crypto for encryption
+//12 byte auth tag
+ {
+ PKTIO_METADATA_T meta = {PKTIO_META_SB_TX,{0},0};
+ int err;
+ nwalDmTxPayloadInfo_t meta_tx={0};
+ meta.sa_handle=tx_data_mode_handle; //use TX SA context
+ meta_tx.ploadLen = len;
+ meta_tx.encOffset = 14+20+8+16 ;
+ meta_tx.authOffset =14+20 ;
+ meta_tx.encSize=len - 14- 20-8-16-12;
+ meta_tx.authSize= len -14-20-12;
+ meta_tx.encIvSize=16;
+ meta_tx.pEncIV= &p_pkt[14+20+8]; //just use same IV..
+ meta_tx.authIvSize=0;
+ meta_tx.pAuthIV=NULL;
+ meta_tx.aadSize=0;
+ meta_tx.pAad=NULL;
+ /* post it to netcp sb tx channel*/
+ meta.u.tx_sb_meta=&meta_tx;
+ pktio_send(netcp_sb_tx_chan,tip,&meta,&err);
+ }
+
+#else
+ {
+ //inflow tx
+ //send pkt directly, asking for IP and UDP checksum offloads AND IPSEC to be applied
+ PKTIO_METADATA_T meta = {PKTIO_META_TX,{0},0};
+ int err;
+ nwalTxPktInfo_t meta_tx={0};
+ meta.sa_handle=tx_inflow_mode_handle; //this tells netapi that inflow crypto needs to be applied
+ meta_tx.txFlag1 = (NWAL_TX_FLAG1_DO_IPV4_CHKSUM|NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_DO_IPSEC_CRYPTO| NWAL_TX_FLAG1_META_DATA_VALID );
+ meta_tx.saOffBytes=14+20;
+ meta_tx.saPayloadLen=len-14-20; //don't include tag, mac and outer header
+ meta_tx.startOffset = 0;
+ meta_tx.ipOffBytes = 14+20+8+16; //to inner header
+ meta_tx.l4OffBytes = 14+20+8+16+20; //to L4
+ meta_tx.l4HdrLen = 8;
+ meta_tx.ploadLen = (unsigned) ((p_pkt[14+20+8+16+20+4]<<8)|p_pkt[14+20+8+16+20+4+1]) -8 ;
+ meta_tx.pseudoHdrChecksum =
+ test_utilGetIpv4PsudoChkSum(&p_pkt[14+20+8+16],8+ meta_tx.ploadLen);
+
+ /* post it to netcp tx channel*/
+ meta.u.tx_meta=&meta_tx;
+ pktio_send(netcp_tx_chan,tip,&meta,&err);
+ stats.tx +=1;
+ stats.sec_tx +=1;
+ }
+#endif
+
+
+}
+else //non ipsec send pkt directly, asking for IP and UDP checksum ofload
+{
+ PKTIO_METADATA_T meta2 = {PKTIO_META_TX,{0},0};
+ int err;
+ nwalTxPktInfo_t meta_tx2={0};
+ meta2.sa_handle=nwal_HANDLE_INVALID;
+ meta_tx2.txFlag1 = (NWAL_TX_FLAG1_DO_IPV4_CHKSUM|NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID );
+ meta_tx2.startOffset = 0;
+ meta_tx2.ipOffBytes = 14;
+ meta_tx2.l4OffBytes = 14+20;
+ meta_tx2.l4HdrLen = 8;
+ meta_tx2.ploadLen = (unsigned) ((p_pkt[14+20+4]<<8)|p_pkt[14+20+4+1]) -8 ;
+ meta_tx2.pseudoHdrChecksum =
+ test_utilGetIpv4PsudoChkSum(&p_pkt[14],8+ meta_tx2.ploadLen);
+
+ /* post it to netcp tx channel*/
+ meta2.u.tx_meta=&meta_tx2;
+ pktio_send(netcp_tx_chan,tip,&meta2,&err);
+ stats.tx +=1;
+}
+}
+
+
+
+
+/***************************************
+ benchmark receive handler
+****************************************/
+void recv_cb_bench(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
+ PKTIO_METADATA_T meta[], int n_pkts,
+ uint64_t ts )
+{
+ int i;
+ vv6= netapi_timing_stop();
+ for (i=0;i<n_pkts; i++)
+ {
+ Pktlib_freePacket(p_recv[i]);
+ }
+ vv11 = netapi_timing_stop();
+}
+
+/****************************************************************************************/
+/******************SB Accelerator Callback PKT RECEIVE HANDLER *************************/
+/****************** Handles Decrypt and Encrypt operation callbacks ******************/
+/******************************************************************************************/
+void recv_sb_cb(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
+ PKTIO_METADATA_T meta[], int n_pkts,
+ uint64_t ts )
+{
+int i;
+int len;
+int p;
+HEAD_T * p_res;
+Ti_Pkt * tip;
+unsigned int templen;
+int err;
+KEY_T key;
+char * p_pkt;
+HEAD_T * p_head;
+HEAD_T temp_head;
+int tag_cmp=0;
+unsigned int hash[3];
+
+ /* loop over received pkts */
+ for(i=0;i<n_pkts;i++)
+ {
+ tip = p_recv[i];
+ Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&templen);//ignore templen
+ len = Pktlib_getPacketLen(tip);//real length
+
+ //is this a decrypt (rx_tunnel) complete
+ if (meta[i].u.rx_sb_meta->appId == rx_tunnel)
+ {
+ stats.sb_rx+=1;
+ //copy hash out of meta data (for some reason it needs endian conversion)
+ hash[0]= htonl( meta[i].u.rx_sb_meta->pAuthTag[0]);
+ hash[1]= htonl( meta[i].u.rx_sb_meta->pAuthTag[1]);
+ hash[2]= htonl( meta[i].u.rx_sb_meta->pAuthTag[2]);
+
+ if(stats.sb_rx<=16)
+ {
+ char *tp = (char *) &hash[0];
+ dump_header((long*)p_pkt, stats.sb_rx, meta[i].u.rx_sb_meta->appId,0);
+ printf("tag in pkt=%x %x %x %x %x %x %x %x %x %x %x %x\n",
+ p_pkt[len-12],p_pkt[len-11],p_pkt[len-10],p_pkt[len-9], p_pkt[len-8],
+ p_pkt[len-7],p_pkt[len-6],
+ p_pkt[len-5],p_pkt[len-4],p_pkt[len-3],p_pkt[len-2],p_pkt[len-1]);
+ printf("tag from SA=%x %x %x %x %x %x %x %x %x %x %x %x\n",
+ tp[0],tp[1],tp[2],tp[3],tp[4],tp[5],
+ tp[6],tp[7],tp[8],tp[9],tp[10],tp[11]);
+ }
+ //check tag
+ tag_cmp = memcmp(&p_pkt[len-12],(char*) &hash[0],12); //todo, really use meta->authTagLen
+ stats.n_auth_ok += !(tag_cmp);
+ flip_and_send_pkt(tip, p_pkt, len,1); //flip packet to echo back and send
+ }
+ //this is an encrypt (tx tunnel) complete
+ else if(meta[i].u.rx_sb_meta->appId== tx_tunnel )
+ {
+ hash[0]= htonl( meta[i].u.rx_sb_meta->pAuthTag[0]);
+ hash[1]= htonl( meta[i].u.rx_sb_meta->pAuthTag[1]);
+ hash[2]= htonl( meta[i].u.rx_sb_meta->pAuthTag[2]);
+ stats.sb_tx+=1;
+ if(stats.sb_tx<=16)
+ {
+ char *tp1 = (char *) &hash[0];
+ dump_header((long*)p_pkt, stats.sb_tx, meta[i].u.rx_sb_meta->appId,0);
+ printf("tag in original rx pkt=%x %x %x %x %x %x %x %x %x %x %x %x\n",
+ p_pkt[len-12],p_pkt[len-11],p_pkt[len-10],p_pkt[len-9], p_pkt[len-8],
+ p_pkt[len-7],p_pkt[len-6],
+ p_pkt[len-5],p_pkt[len-4],p_pkt[len-3],p_pkt[len-2],p_pkt[len-1]);
+
+ printf("tag from SA=%x %x %x %x %x %x %x %x %x %x %x %x\n",
+ tp1[0],tp1[1],tp1[2],tp1[3],tp1[4],tp1[5],
+ tp1[6],tp1[7],tp1[8],tp1[9],tp1[10],tp1[11]);
+ }
+ //put the computed tag in the packet
+ memcpy(&p_pkt[len-12],(char*)&hash[0],12); //todo, really use meta->authTagLen
+ {
+ PKTIO_METADATA_T meta2 = {PKTIO_META_TX,{0},0};
+ nwalTxPktInfo_t meta_tx={0};
+ // now send directly
+ meta2.sa_handle=nwal_HANDLE_INVALID;
+ meta_tx.txFlag1 = (NWAL_TX_FLAG1_DO_IPV4_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID);//only outer IP header checksum. no udp checksum possible since pkt is already encrypted
+ meta_tx.startOffset = 0;
+ meta_tx.ipOffBytes = 14;
+ //not used
+ meta_tx.l4OffBytes = 0;
+ meta_tx.l4HdrLen = 0;
+ meta_tx.ploadLen = 0;
+
+ /* post it to netcp tx channel*/
+ meta2.u.tx_meta=&meta_tx;
+ pktio_send(netcp_tx_chan,tip,&meta2,&err);
+ stats.tx +=1;
+ }
+ }
+ else printf("netapi recv_sb_cb: unknown appiD %x \n",meta[i].u.rx_sb_meta->appId );
+ }
+}
+
+/******************************************************/
+/******************PKT RECEIVE HANDLER *************************/
+/******************************************************/
+void recv_cb(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
+ PKTIO_METADATA_T meta[], int n_pkts,
+ uint64_t ts )
+{
+int i;
+int len;
+int p;
+HEAD_T * p_res;
+Ti_Pkt * tip;
+unsigned int templen;
+int err;
+KEY_T key;
+char * p_pkt;
+HEAD_T * p_head;
+HEAD_T temp_head;
+
+ p_head=&temp_head;
+
+ //debug
+#if 0
+ if (n_pkts != TX_BURST) {
+ printf("recv_cb, txsofar=%d rxsofar=%d np = %d, NOT %d\n",
+ stats.itx, stats.rx, n_pkts,TX_BURST);
+ our_stats_cb(netapi_handle,NULL);
+ }
+#endif
+ //test_alloc_free(7);
+ //printf("recv start\n");
+
+ /* loop over received pkts */
+ for(i=0;i<n_pkts;i++)
+ {
+ tip = p_recv[i];
+ Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&templen);//ignore templen
+ len = Pktlib_getPacketLen(tip)-4;//real length, subtract mac trailer
+
+ //debug: validate descriptor */
+ if(Pktlib_getNextPacket(tip) != 0) {printf(" rcv_cb, nexpkt != NULL");}
+ //debug printf("recv pkt, len=%d %d\n", len, templen);
+ stats.rx+=1;
+
+#ifdef DEBUG_DESC
+ if (stats.rx<16){printf(">rx dmp.."); dump_descr((long *) tip, stats.rx);}
+ else if (stats.rx>99) {printf(">rx dmp.."); dump_descr((long *) tip,stats.rx);}
+#endif
+ if(stats.rx<=16)
+ {
+ dump_header((long*)p_pkt, stats.rx, meta[i].u.rx_meta->appId,meta[i].u.rx_meta->rxFlag1);
+ }
+ /* check header */
+ memcpy(p_head,&p_pkt[14],sizeof(HEAD_T));
+
+ if ((p_head->ip[2]&0x0000ff00)==0x00003200)
+ {
+ if (!check_header(p_head,&meta[i])) {
+ stats.n_bad+=1;Pktlib_freePacket(tip); continue;
+ }
+
+ //process IP SEC PACKET
+#ifdef IPSEC_MODE_RX_SIDEBAND
+ {
+ //ship to crypto for decrypt!!
+ //12 byte auth tag
+ PKTIO_METADATA_T meta2 = {PKTIO_META_SB_TX,{0},0};
+ nwalDmTxPayloadInfo_t meta_tx={0};
+ meta2.sa_handle=rx_data_mode_handle;
+ meta_tx.ploadLen = len;
+ meta_tx.encOffset = 14+20+8+16 ;
+ meta_tx.authOffset =14+20 ;
+ meta_tx.encSize=len - 14- 20-8-16-12;
+ meta_tx.authSize= len -14-20-12;
+ meta_tx.encIvSize=16;
+ meta_tx.pEncIV= &p_pkt[14+20+8];
+ meta_tx.authIvSize=0;
+ meta_tx.pAuthIV=NULL;
+ meta_tx.aadSize=0;
+ meta_tx.pAad=NULL;
+ /* post it to netcp sb tx channel*/
+ meta2.u.tx_sb_meta=&meta_tx;
+ pktio_send(netcp_sb_tx_chan,tip,&meta2,&err);
+ continue;
+ }
+#else
+ //inflow mode. flip and send
+ flip_and_send_pkt(tip,p_pkt,len,1);
+#endif
+ }
+ else if ((p_head->ip[2]&0x0000ff00)!=0x00001100)
+ {
+ stats.n_new+=1;Pktlib_freePacket(tip); continue;
+ }
+ else //non ipsec
+ {
+ if (!check_header(p_head,&meta[i])) {
+ stats.n_bad+=1;Pktlib_freePacket(tip); continue;
+ }
+
+#if 0
+ /* lookup flow */
+ key.src_ip = p_head->ip[3];
+ key.dst_ip = p_head->ip[4];
+ key.src_port= (p_head->udp[0]&0xffff0000)>>16;
+ key.dst_port= (p_head->udp[0]&0x0000ffff);
+ p_res= (HEAD_T *) trie_lookup(P_trie, (char *) &key, sizeof(key));
+ if (!p_res) { stats.n_new+=1; slow_path(tip, len); continue;}
+
+ /* copy header */
+ memcpy((char *) p_head, (char *) p_res, sizeof(HEAD_T));
+
+ memcpy(&p_pkt[14],p_head,sizeof(HEAD_T));
+ /* update_mac(&p_pkt[0]); */
+
+ /* 'simulate' send pkt */
+ send_pkt(tip,len);
+#endif
+ //just flip and send
+ flip_and_send_pkt(tip,p_pkt,len,0);
+ }
+ }
+ //printf("recv done\n");
+}
+
+//timer callback
+void our_timer_cb( NETAPI_TIMER_GROUP_HANDLE_T th,
+ int n_fired, //# timers fired
+ NETAPI_TIMER_LIST_T fired_list,
+ uint64_t currentTime)
+{
+int i;
+NETAPI_TIMER_T tx;
+int cookie;
+int err;
+unsigned long long et;
+//DEBUGprintf("TIMER CALLBACK @ %lld %d timers\n", currentTime, n_fired);
+tx = netapi_TimerGetFirst(fired_list);
+for(i=0;i<n_fired;i++)
+{
+ cookie = (int) netapi_TimerGetCookie(tx);
+ et = netapi_TimerGetTs(tx); //debug
+ //DEBUGprintf(" timer %d - cookie = %d expected ts=%lld (delta=%lld)\n", i, cookie, et, currentTime-et);
+ if (cookie ==1)
+ {
+ stats.n_t1+=1;
+ t1 = netapi_TimerGroupStartTimer(
+ th,
+ (void *) 1,
+ 100LL, //timer group tics
+ &err);
+ }
+ else if (cookie ==2)
+ {
+ stats.n_t2+=1;
+ t2 = netapi_TimerGroupStartTimer(
+ th,
+ (void *) 2,
+ 200LL, //timer group ticks
+ &err);
+ }
+ else
+ {
+ stats.n_t3+=1;
+ t3 = netapi_TimerGroupStartTimer(
+ th,
+ (void *) 3,
+ 300LL, //timer group ticks
+ &err);
+ //cancel 1 and restart 1
+ netapi_TimerGroupCancel(th,t1,&err);
+ t1 = netapi_TimerGroupStartTimer(
+ th,
+ (void *) 1,
+ 100LL, //timer group ticks
+ &err);
+ }
+ tx = netapi_TimerGetNext(fired_list,tx);
+}
+}
+
+
+static int np2process = NP;
+/******************************************************
+ * stats callback
+ *******************************************************/
+void our_stats_cb(NETAPI_T h, paSysStats_t* pPaStats)
+{
+uint32_t numFreeDataPackets;
+uint32_t numZeroBufferPackets;
+uint32_t numPacketsinGarbage;
+Pktlib_HeapStats pktLibHeapStats;
+
+printf(">*****stats @ %lld\n", netapi_getTimestamp());
+//printf("netcp_tx_handle check %x\n", netcp_tx_chan->back);
+printf(">itx=%d rx=%d tx=%d bad=%d slow=%d \n>rx_class0=%d rx_class1=%d rx_class2=%d secRx=%d secPRX=%d sb_rx=%d sb_tx=%d auth_ok=%d\n n_t1=%d n_t2=%d n_t3=%d\n",stats.itx, stats.rx, stats.tx, stats.n_bad, stats.n_new,
+ stats.n_class0_rx, stats.n_class1_rx,
+ stats.n_class2_rx, stats.sec_rx, stats.secp_rx, stats.sb_rx, stats.sb_tx, stats.n_auth_ok,
+ stats.n_t1, stats.n_t2,stats.n_t3);
+
+if(pPaStats)
+{
+ printf("C1 number of packets: %d\n", pPaStats->classify1.nPackets);
+ printf("C1 number IPv4 packets: %d\n", pPaStats->classify1.nIpv4Packets);
+ //printf("C1 number llc/snap fail: %d\n", pPaStats->classify1.nLlcSnapFail);
+ printf("C1 number table matched: %d\n", pPaStats->classify1.nTableMatch);
+ printf("C1 number failed table matched: %d\n", pPaStats->classify1.nNoTableMatch);
+ printf ("C1 number of parse fail: %d\n",pPaStats->classify1.nParseFail);
+ printf("C1 number of command failures: %d\n", pPaStats->classify1.nCommandFail);
+ printf("C1 number invalid reply dests: %d\n", pPaStats->classify1.nInvalidComReplyDest);
+ printf ("C1 number of silent discard: %d\n",pPaStats->classify1.nSilentDiscard);
+ printf("C1 number of invalid control: %d\n", pPaStats->classify1.nInvalidControl);
+ printf ("C1 number of invalid states: %d\n",pPaStats->classify1.nInvalidState);
+ printf ("C1 number of system fails: %d\n",pPaStats->classify1.nSystemFail);
+ printf ("C2 number parse failed : %d\n",pPaStats->classify2.nParseFail);
+ printf ("C2 number Invld Header : %d\n",pPaStats->classify2.nInvldHdr);
+ printf ("C2 number udp : %d\n",pPaStats->classify2.nUdp);
+ printf ("C2 number tcp : %d\n",pPaStats->classify2.nTcp);
+ printf ("C2 number cmd fail : %d\n",pPaStats->classify2.nCommandFail);
+ printf ("C2 number silent drop : %d\n",pPaStats->classify2.nSilentDiscard);
+ printf ("C2 number invalid cntrl : %d\n\n",pPaStats->classify2.nInvalidControl);
+}
+Pktlib_getHeapStats(OurHeap, &pktLibHeapStats);
+printf("main heap 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(specialSmall, &pktLibHeapStats);
+printf("specialSmall heap 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(specialLarge, &pktLibHeapStats);
+printf("specialLarge heap 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);
+
+
+//debug = dump timer polling stats
+dump_poll_stats();
+
+
+}
+
+//******************************************************
+//use scheduling housekeeping callback to generate pkts
+//******************************************************
+void house(NETAPI_SCHED_HANDLE_T * s)
+{
+Ti_Pkt * tip;
+unsigned int len;
+nwalTxPktInfo_t meta_tx;
+PKTIO_METADATA_T meta = {PKTIO_META_TX,{0},0};
+int err;
+static int house_pkts_gened=0;
+int p;
+unsigned char * pIpHdr,* pData;
+unsigned int vv1,vv2,vv3;
+unsigned int sum_vv1=0;
+unsigned int sum_vv2=0;
+unsigned int sum_vv3=0;
+unsigned int sum_vv4=0;
+unsigned int sum_vv5=0;
+
+unsigned int nwal_flow_vv1,nwal_flow_vv2;
+unsigned int nwal_sum_vv1=0;
+unsigned int nwal_sum_vv2=0;
+unsigned int nwal_sum_vv3=0;
+unsigned int nwal_sum_vv4=0;
+unsigned int nwal_sum_vv5=0;
+unsigned int nwal_sum_vv6=0;
+
+unsigned int nwal_sum_flow_vv1=0;
+unsigned int nwal_sum_flow_vv2=0;
+static int first =0;
+Cppi_HostDesc* pPktDesc;
+
+Osal_cache_op_measure_reset();
+memset(&meta_tx,0,sizeof(meta_tx));
+for(p=0;p<TX_BURST;p++) {
+//reguest stats
+if ((house_pkts_gened>0) && (! (house_pkts_gened%1000)) )
+{
+ printf("net_test> request stats at n=%d \n",house_pkts_gened);
- netcp_cfgReqStats(netapi_handle, our_stats_cb, 0,&err);
++ //netcp_cfgReqStats(netapi_handle, our_stats_cb, 0,&err);
+ if (err!=0) {printf("stats req failed\n");}
+}
+
+
+ if (house_pkts_gened >= np2process+ 100)
+ {
+ //shutdown
+ netapi_schedShutdown(s,NULL,&err);
+ continue;
+ }
+
+ else if (house_pkts_gened >= np2process) { house_pkts_gened+=1; continue;}
+
+
+/* manufacture a pkt to transmit */
+ tip = get_pkt(house_pkts_gened, &len);
+ if(!tip) { house_pkts_gened +=1; continue; }
+
+
+ /* set the pkt length */
+ vv1 = netapi_timing_start();
+ Pktlib_setPacketLen(tip, len);
+
+ /* set up meta data */
+ meta.sa_handle=nwal_HANDLE_INVALID;
+ meta_tx.txFlag1 = (NWAL_TX_FLAG1_DO_IPV4_CHKSUM | NWAL_TX_FLAG1_DO_UDP_CHKSUM| NWAL_TX_FLAG1_META_DATA_VALID);
+ meta_tx.startOffset = 0;
+ //GONE in V2 meta_tx.pktLen = len;
+ meta_tx.ipOffBytes = TEST_PKT_IP_OFFSET_BYTES;
+ meta_tx.l4OffBytes = TEST_PKT_UDP_OFFSET_BYTES;
+ meta_tx.l4HdrLen = TEST_PKT_UDP_HDR_LEN;
+ //GONE in V2 meta_tx.ploadOffBytes = TEST_PKT_PLOAD_OFFSET_BYTES;
+ meta_tx.ploadLen = TEST_PAYLOAD_LEN;
+
+ Pktlib_getDataBuffer(tip,&pData,&len);
+ pIpHdr = pData + meta_tx.ipOffBytes;
+ meta_tx.pseudoHdrChecksum =
+ test_utilGetIpv4PsudoChkSum(pIpHdr,(TEST_PAYLOAD_LEN+TEST_PKT_UDP_HDR_LEN));
+
+ /* post it to netcp tx channel*/
+ meta.u.tx_meta=&meta_tx;
+#ifdef DEBUG_DESC
+ if (house_pkts_gened<16) dump_descr((long *) tip, house_pkts_gened);
+ else if (house_pkts_gened>99) dump_descr((long *) tip,house_pkts_gened);
+#endif
+
+ if(!first)
+ {
+ first++;
+ nwal_flow_vv1= netapi_timing_stop();
+ if(nwal_initPSCmdInfo(PKTIO_GET_NWAL_INSTANCE(netcp_tx_chan),
+ &meta_tx,
+ &flowPSCmdInfo) != nwal_OK)
+ {
+ printf("nwal_initPSCmdInfo() ERROR \n");
+ }
+ nwal_flow_vv2= netapi_timing_stop();
+ nwal_sum_flow_vv1 += (nwal_flow_vv1-vv1);
+ nwal_sum_flow_vv2 += (nwal_flow_vv2-nwal_flow_vv1);
+ }
+
+ vv2= netapi_timing_stop();
+ nwal_mCmdSetL4CkSumPort( tip,
+ &flowPSCmdInfo,
+ TEST_PKT_UDP_OFFSET_BYTES,
+ (TEST_PKT_UDP_HDR_LEN + TEST_PAYLOAD_LEN),
+ meta_tx.pseudoHdrChecksum,
+ meta_tx.enetPort);
+
+ pPktDesc = Pktlib_getDescFromPacket(tip);
+ /* Send the packet out to transmit Q*/
+ Qmss_queuePushDescSize (flowPSCmdInfo.txQueue,
+ pPktDesc,
+ NWAL_DESC_SIZE);
+ vv3= netapi_timing_stop();
+
+
+ sum_vv1 += (vv2-vv1);
+ if(!house_pkts_gened)
+ {
+ /* first packet. Take out the PS command label creation cost */
+ sum_vv1 = sum_vv1 - nwal_sum_flow_vv2;
+ }
+
+ sum_vv3 += (vv3-vv2);
+
+ // printf("pktio send. full=%d metadata=%d pktio_send=%d\n", vv3-vv1, vv2-vv1, vv3-vv2);
+
+
+ stats.itx +=1;
+ house_pkts_gened +=1;
+ }
+{
+ unsigned int ccycles;
+ int n_c_ops;
+ ccycles =Osal_cache_op_measure(&n_c_ops);
+ if (sum_vv1)
+ {
+ printf("BURST NWAL Fast send %d pkts. metadata=%d Cmd Label Creation Cost=%d nwal Fast Send Cost= %d n_c_ops=%d cache_op_time=%d (pp-> %d)\n",
+ stats.itx, sum_vv1/stats.itx, nwal_sum_flow_vv2, sum_vv3/stats.itx,
+ n_c_ops, ccycles, n_c_ops? (ccycles/(n_c_ops/2)) : 0);
+
+ printf("NWAL Profile Cycles: Prof1= %d,Prof2=%d,Prof3=%d,Prof4=%d,Prof5=%d ,Prof6=%d \n",
+ nwal_sum_vv1/stats.itx,nwal_sum_vv2/stats.itx,nwal_sum_vv3/stats.itx,
+ nwal_sum_vv4/stats.itx,nwal_sum_vv5/stats.itx,nwal_sum_vv6/stats.itx);
+
+
+ if(stats.itx2)
+ {
+ printf("nwal_flowSend Profile Cycles: Prof1= %d,Prof2=%d \n",
+ nwal_sum_flow_vv1/stats.itx2,nwal_sum_flow_vv2/stats.itx2);
+ }
+
+ }
+}
+}
+
+
+/***************************************
+ ********** test driver*****************
+ ***************************************/
+int main(int argc, char **argv)
+{
+int err;
+rlim_t oss,ss = 1024*1024;
+struct rlimit rl;
+
+Pktlib_HeapCfg heapCfg;
+int32_t errCode;
+Pktlib_HeapIfTable* pPktifTable;
+
+err= getrlimit(RLIMIT_STACK,&rl);
+if (!err) printf(" stack limit = %d\n",rl.rlim_cur); else printf("getrlimit failed\n");
+#if 0
+rl.rlim_cur = ss;
+err=setrlimit(RLIMIT_STACK,&rl);
+if (!err) printf("set stack to %d\n",rl.rlim_cur); else printf("setrlimit failed\n");
+#endif
+
+if (argc>=2) np2process = atoi(argv[1]);
+if (np2process<0) np2process = NP; /* default */
+if (argc==3) perslow = atoi(argv[2]);
+if ((perslow<0)||(perslow>100)) perslow=PERSLOW;//default
+if (argc>3) {printf("net_test <no of pkts to process> <percent slow path>\n"); exit(1);}
+
+
+//real mode, so update our test packet mac header and ip header
+if (pktloopback==0)
+{
+memcpy(&testPkt,&real_mac_header[0],14); //overwrite test pkt mac address
+memcpy(&testPkt[26],&real_ip_addr[0],8);//overrite test pkt ip addresses
+}
+
+/*******************************************/
+/*************NETAPI STARTUP****************/
+/*******************************************/
+
+/* create netapi */
+netapi_handle = netapi_init(NETAPI_SYS_MASTER, &our_netapi_default_cfg);
+
+/* open the main heap */
+OurHeap = Pktlib_findHeapByName("netapi");
+if (!OurHeap) {printf("findheapbyname fail\n"); exit(1);}
+
+/* create two secondary heaps */
+/* Initialize the heap configuration. */
+memset ((void *)&heapCfg, 0, sizeof(Pktlib_HeapCfg));
+
+pPktifTable = netapi_getPktlibIfTable();
+/* Populate the heap configuration */
+heapCfg.name = "netapi-small";
+heapCfg.memRegion = NETAPI_GLOBAL_REGION;
+heapCfg.sharedHeap = 1;
+heapCfg.useStarvationQueue = 0;
- heapCfg.dataBufferSize = 256;
++heapCfg.dataBufferSize = 512;
+heapCfg.numPkts = 64;
+heapCfg.numZeroBufferPackets= 0;
+heapCfg.heapInterfaceTable.data_malloc = pPktifTable->data_malloc;
+heapCfg.heapInterfaceTable.data_free = pPktifTable->data_free;
+heapCfg.dataBufferPktThreshold = 0;
+heapCfg.zeroBufferPktThreshold = 0;
+
+specialSmall = Pktlib_createHeap(&heapCfg, &errCode);
+heapCfg.name = "netapi-big";
+heapCfg.dataBufferSize = 1600;
+specialLarge = Pktlib_createHeap(&heapCfg, &errCode);
+//register these heaps so poll routine will include their garbage queues.
+netapi_registerHeap(netapi_handle, specialSmall);
+netapi_registerHeap(netapi_handle, specialLarge);
+
+#ifdef REASSEMBLE_BENCH
+our_reassemble_bench(2);
+exit(1);
+#endif
+
+/* create a pktio channel */
+our_chan=pktio_create(netapi_handle,"our1stq",(PKTIO_CB) recv_cb_bench, &our_chan_cfg,&err);
+if (!our_chan) {printf("pktio create failed err=%d\n",err); exit(1);}
+
+/* open netcp default tx, rx queues */
+netcp_tx_chan= pktio_open(netapi_handle, NETCP_TX, NULL, &netcp_tx_cfg, &err);
+if (!netcp_tx_chan) {printf("pktio open TX failed err=%d\n",err); exit(1);}
+netcp_rx_chan= pktio_open(netapi_handle, NETCP_RX, (PKTIO_CB) recv_cb, &netcp_rx_cfg, &err);
+if (!netcp_rx_chan) {printf("pktio open RX failed err=%d\n",err); exit(1);}
+
+/* create a pktio channel for specially classified pkts */
+netcp_rx_chan2= pktio_create(netapi_handle, "classq", (PKTIO_CB) recv_cb, &netcp_rx_cfg2, &err);
+if (!netcp_rx_chan2) {printf("pktio create RX2 failed err=%d\n",err); exit(1);}
+
+/* open netcp default tx, rx queues for sideband crypto */
+netcp_sb_tx_chan= pktio_open(netapi_handle, NETCP_SB_TX, NULL, &netcp_sb_tx_cfg, &err);
+if (!netcp_sb_tx_chan) {printf("pktio open SB TX failed err=%d\n",err); exit(1);}
+netcp_sb_rx_chan= pktio_open(netapi_handle, NETCP_SB_RX, (PKTIO_CB) recv_sb_cb, &netcp_sb_rx_cfg, &err);
+if (!netcp_sb_rx_chan) {printf("pktio open SB RX failed err=%d\n",err); exit(1);}
+
-
++printf("net_test> %d bytes left in our CMA area\n", netapi_getBufMemRemainder());
+/* create scheduler instance */
+our_sched =netapi_schedOpen(netapi_handle,&our_sched_cfg, &err);
+if (!our_sched) {printf("sched create failed\n"); exit(1);}
+
+/********************************************
+* Basic pkt loopback test
+*********************************************/
+printf("...running pure push/pop benchmark\n");
+our_pktio_bench(1000);
+our_pktio_bench(1000);
+our_pktio_bench(1000);
+our_pktio_bench(1000);
+our_pktio_bench(1000);
+/*********************************************/
+
+
+
+
+/* add mac intefaces */
+netcp_cfgCreateMacInterface(
+ netapi_handle,
+ &mac0[0],
+ 0,0,
+ (NETCP_CFG_ROUTE_HANDLE_T) NULL,
+ (NETCP_CFG_VLAN_T ) NULL , //future
+ 1,
+ &err);
+if (err) {printf("addmac0 failed %d\n",err); exit(1); }
+
+//attach an IP to this interface
+ip_rule0=netcp_addIp(
+ netapi_handle,
+ 0,
+ nwal_IPV4,
+ &OurIp0,
+ NULL, //all IP
+ (NETCP_CFG_ROUTE_HANDLE_T) NULL,
+ &err
+ );
+if (err) {printf("addip0 failed %d\n",err); exit(1); }
+
+//create a 2nd mac instance
+netcp_cfgCreateMacInterface(
+ netapi_handle,
+ &mac1[0],
+ 1,1,
+ (NETCP_CFG_ROUTE_HANDLE_T) NULL,
+ (NETCP_CFG_VLAN_T ) NULL , //future
+ 1,
+ &err);
+if (err) {printf("addmac1 failed %d\n",err); exit(1); }
+
+//attach an IP to this interface
+ip_rule1=netcp_addIp(
+ netapi_handle,
+ 1,
+ nwal_IPV4,
+ &OurIp1,
+ NULL, //all IP
+ (NETCP_CFG_ROUTE_HANDLE_T) NULL,
+ &err
+ );
+if (err) {printf("addip1 failed %d\n",err); exit(1); }
+
+//attach 2 classifiers to iface 0, ip0
+class_0_cfg.u.c_l4.ip = ip_rule0;
+class_0 = netcp_cfgAddClass(netapi_handle,
+ &class_0_cfg,
+ NULL,
+ NETCP_CFG_ACTION_TO_SW,
+ &err);
+if (err) {printf("addclass0 failed %d\n",err); exit(1);}
+
+class_1_cfg.u.c_l4.ip = ip_rule0;
+class_1 = netcp_cfgAddClass(netapi_handle,
+ &class_1_cfg,
+ NULL,
+ NETCP_CFG_ACTION_TO_SW,
+ &err);
+if (err) {printf("addclass1 failed %d\n",err); exit(1);}
+
+
+//3rd classifier has a different IP and route
+class_2_cfg.u.c_l3_l4.ip_addr = &OurIp2;
+
+//create specialFlow for this classifier
+{
+Pktlib_HeapHandle heaps[2];
+int sizes[2];
+heaps[0]= specialSmall;
+heaps[1]= specialLarge;
- sizes[0]=256;
- sizes[1]=1600;
++#define SPECIAL_SOP_OFF 128
++sizes[0]=512-SPECIAL_SOP_OFF;
++sizes[1]=1600-SPECIAL_SOP_OFF;
+specialFlow = netcp_cfgAddFlow( netapi_handle,
+ 2,
+ heaps,
+ sizes,
- 0, //offset to start rx is 0
++ SPECIAL_SOP_OFF, //offset to start rx is 128
+ &err);
+if (err) {printf("add flow failed\n", err); exit(1);}
+}
+#if 0
+//special route for this classifier: different flow + destination q
+class2_route.p_dest_q = netcp_rx_chan2;
+class2_route.p_flow = specialFlow;
+class_2 = netcp_cfgAddClass(netapi_handle,
+ &class_2_cfg,
+ (void*) &class2_route,
+ NETCP_CFG_ACTION_TO_SW,
+ &err);
+if (err) {printf("addclass2 failed %d\n",err); exit(1);}
+#endif
+
+//security stuff
+ourRXKeyParams.pEncKey = &ourEncrKey[0];
+ourRXKeyParams.pAuthKey = &ourAuthKey[0];
+memcpy(&rx_sa.src, &TheirIp4IPSEC,4);
+memcpy(&rx_sa.dst, &OurIp4IPSEC,4);
+
+#if 1
+rx_tunnel = netapi_secAddSA( netapi_handle,
+ 0, //iface #0
+ &rx_sa,
+ &ourRXKeyParams,
+#ifdef IPSEC_MODE_RX_SIDEBAND
+ NETAPI_SEC_SA_SIDEBAND,
+#else
+ NETAPI_SEC_SA_INFLOW, //USE inflow mode
+#endif
+ NULL, //use default route
+ &rx_data_mode_handle,
+ &rx_inflow_mode_handle,
+ &err);
+if (err) {printf("addRxSa failed %d\n",err); exit(1);}
+
+#ifdef IPSEC_MODE_RX_INFLOW
+//assume inner and outer ip is the same
+rx_policy= netapi_secAddRxPolicy( netapi_handle,
+ rx_tunnel, //link to tunnel above
+ 4, //ipv4
+ &TheirIp4IPSEC, //src -> them
+ &OurIp4IPSEC, //dst -> us
+ NULL, // no qualifiers
+ NULL, //default route
+ &err);
+if (err) {printf("addSaPolicy failed %d\n",err); exit(1);}
+#else
+rx_policy = 0;
+#endif
+#endif
+
+//tx SA
+//security stuff
+ourTXKeyParams.pEncKey = &ourEncrKey[0];
+ourTXKeyParams.pAuthKey = &ourAuthKey[0];
+memcpy(&tx_sa.src, &OurIp4IPSEC,4);
+memcpy(&tx_sa.dst, &TheirIp4IPSEC,4);
+tx_tunnel = netapi_secAddSA( netapi_handle,
+ 0, //iface #0
+ &tx_sa,
+ &ourTXKeyParams,
+#ifdef IPSEC_MODE_TX_SIDEBAND
+ NETAPI_SEC_SA_SIDEBAND,
+#else
+ NETAPI_SEC_SA_INFLOW, //USE inflow mode
+#endif
+ NULL, //use default route
+ &tx_data_mode_handle,
+ &tx_inflow_mode_handle,
+ &err);
+if (err) {printf("addTxSa failed %d\n",err); exit(1);}
+
+
+#ifdef TEST_TIMERS
+//timers
+ourTimerBlock = netapi_TimerGroupCreate(
+ netapi_handle,
+ "our1sttimer",
+ our_timer_cb,
+ 0, //1 if timers local to thread
+ 0, //1 if expect to cancel
+ netapi_getTicksPerSec()/1000, /* 1 msc resolution for these timers */
+ netapi_getTicksPerSec()/5000, /* would like .5 msc tolerence */
+ 10, //small # of timers to test garbage collection
+ &err);
+if (err) {printf("timergroupcreate failed %d\n",err); exit(1);}
+
+//start a couple of timers
+t1 = netapi_TimerGroupStartTimer(
+ ourTimerBlock,
+ (void *) 1,
+ 100LL, //timer group ticks
+ &err);
+if (err) {printf("timerstart failed %d\n");}
+t2 = netapi_TimerGroupStartTimer(
+ ourTimerBlock,
+ (void *) 2,
+ 200LL, //timer group ticks
+ &err);
+if (err) {printf("timerstart failed %d\n");}
+t3 = netapi_TimerGroupStartTimer(
+ ourTimerBlock,
+ (void *) 3,
+ 300LL, //timer group ticks
+ &err);
+if (err) {printf("timerstart failed %d\n");}
+#endif
- netcp_cfgReqStats(netapi_handle, our_stats_cb, 1,&err);
++//netcp_cfgReqStats(netapi_handle, our_stats_cb, 1,&err);
+if (err!=0) {printf("stats req failed\n");}
+
+/*********************************************/
+/*****************end NETAPI STARTUP**********/
+/*********************************************/
+
+
+/********************************************
+* Basic pkt loopback test
+*********************************************/
+printf("...runnining pure push/pop benchmark\n");
+our_pktio_bench(100);
+
+
+/**************unused stuff******************/
+/* create TRIE */
+P_trie = trie_new();
+if (!P_trie) {printf("trie alloc failed\n"); exit(1);}
+
+nat = (HEAD_T *) malloc(NE * sizeof(HEAD_T));
+if (!nat) {printf("malloc of nat table failed\n"); exit(1);}
+
+//gen_pkts(np2process<NP ? np2process:NP);
+n_pkt= np2process;
+
+/* build table */
+build_table(P_trie);
+
+
+/* processing loop: get pkt, check it, look up in table, copy new header,
+ send packet */
+srand((unsigned) np2process);
+
+
+/*********************************************/
+/**************Entry point into scheduler ****/
+/*********************************************/
+netapi_schedWaitForEvents(our_sched, &err);
+
+/* done */
+our_stats_cb(netapi_handle, NULL);
+
+
+#define DO_FAST_POLL
+#ifdef DO_FAST_POLL
+example_fast_poll(netcp_rx_chan);
+#endif
+
+/*************************************************
+ ************CLEAN UP****************************
+ ************************************************/
+
+//delete Classifiers
+netcp_cfgDelClass(netapi_handle, class_0, &err);
+netcp_cfgDelClass(netapi_handle, class_1, &err);
+//netcp_cfgDelClass(netapi_handle, class_2, &err);
+
+//delete flow
+netcp_cfgDelFlow(netapi_handle, specialFlow, &err);
+
+#if 1
+//delete policy
+if (rx_policy)
+ netapi_secDelRxPolicy(netapi_handle, rx_policy, &err);
+
+//delete tunnels
+netapi_secDelSA(netapi_handle, 0, rx_tunnel, &err);
+netapi_secDelSA(netapi_handle, 0, tx_tunnel, &err);
+#endif
+
+//delete IPs and MAC Interfacess
+netcp_cfgDelIp(netapi_handle, 0, 0, NULL, NULL, ip_rule0, &err);
+netcp_cfgDelIp(netapi_handle, 1, 0, NULL, NULL, ip_rule1, &err);
+netcp_cfgDelMac(netapi_handle,0,&err);
+netcp_cfgDelMac(netapi_handle,1,&err);
+
+
+//close pktio channels we opened
+pktio_close(netcp_tx_chan ,&err);
+pktio_close(netcp_rx_chan ,&err);
+pktio_close(netcp_sb_tx_chan ,&err);
+pktio_close(netcp_sb_rx_chan ,&err);
+
+//clear pktio channel we created
+pktio_control(our_chan, (PKTIO_CB) NULL, (PKTIO_CFG_T *) NULL, &zap_channel_control, &err);
+pktio_control(netcp_rx_chan2, (PKTIO_CB) NULL, (PKTIO_CFG_T *) NULL, &zap_channel_control, &err);
+
+//delete pktio channels we created
+pktio_delete(our_chan, &err);
+pktio_delete(netcp_rx_chan2,&err);
+
+netapi_shutdown(netapi_handle);
+
+}
+
+//EXAMPLE FAST POLL
+/* PLD */
+void netapi_pld(void * x)
+{
+ asm volatile("pld [r0]");
+}
++#include "ti/drv/nwal/nwal_util.h"
+
+#define M 1008
+static int l3_off[M], l4_off[M], L3_chk_ok[M], L4_chk_ok[M], appid[M], len[M] ;
+static unsigned char * buf[M];
- #define N2POLL 8
++#define N2POLL 8 //batch size
+void example_fast_poll( PKTIO_HANDLE_T * p_pktio)
+{
+int j=0;
+int jj=0;
+int i,k,l=0,ltot=0;
+int n= N2POLL; //max # of pkts to poll
+Ti_Pkt * pHd[N2POLL];
+Ti_Pkt * tempVA;
+pasahoLongInfo_t* pinfo;
+unsigned long t1;
+unsigned long t2;
+unsigned long t11;
+unsigned long t12;
+unsigned long np;
+unsigned long sumt=0;
+unsigned long sumf=0;
+unsigned long sump=0;
+unsigned long totlen=0;
+int max_batch=0;
+
+//this should be done once and saved
+Qmss_QueueHnd rxQ= PKTIO_GET_DEFAULT_NETCP_Q(p_pktio);
+Qmss_QueueHnd freeQ;
+//loop forever
+for(;;)
+{
+ t1= netapi_timing_stop();
+ pHd[0] = (Ti_Pkt *)QMSS_DESC_PTR(PKTIO_QMSS_QUEUE_POP_RAW (rxQ));
+ if (!pHd[0]) continue;
+ //got pkt
+ for(i=1;(i<n) && (pHd[i-1]);i++)
+ {
+ //convert previous descriptor PA -> VA
+ tempVA = Osal_qmssPhyToVirt(pHd[i-1]);
- Cppi_getData (Cppi_DescType_HOST, (Cppi_Desc*)tempVA, &buf[jj], &len[jj]);
+
+ //try and preload desriptor
- //__builtin_prefetch(tempVA);
++ __builtin_prefetch(tempVA);
+ //netapi_pld(tempVA);
+
+ //read next descriptor from queue
+ pHd[i] = (Ti_Pkt *)QMSS_DESC_PTR(PKTIO_QMSS_QUEUE_POP_RAW (rxQ));
-
++#if 1
+ /* extract some meta data */
++ Cppi_getData (Cppi_DescType_HOST, (Cppi_Desc*)tempVA, &buf[jj], &len[jj]);
+ pinfo = PKTIO_GET_PROTO_INFO(tempVA);
+ l3_off[jj]= PKTIO_GET_L3_OFFSET(pinfo);
+ l4_off[jj]= PKTIO_GET_L4_OFFSET(pinfo);
+ appid[jj]= PKTIO_GET_APPID(tempVA);
- //get ptr (Physical address) and length of associate buffer
- //Cppi_getData (Cppi_DescType_HOST, (Cppi_Desc*)tempVA, &buf[jj], &len[jj]);
++//#define VERIFY_SOP
++#ifdef VERIFY_SOP
++ if (sump < 200) printf("..sop off=%d\n", (int) buf[jj]-
++ (int) ((Cppi_HostDesc *) tempVA)->origBuffPtr) ;
++#endif
++#endif
+ jj+=1;
+ }
+ //finish last pkt in burst
+ if(pHd[i-1])
+ {
+ //convert previous descriptor PA -> VA
+ tempVA = Osal_qmssPhyToVirt(pHd[i-1]);
+
+ /* extract some meta data */
++#if 1
+ pinfo = PKTIO_GET_PROTO_INFO(tempVA);
+ l3_off[jj]= PKTIO_GET_L3_OFFSET(pinfo);
+ l4_off[jj]= PKTIO_GET_L4_OFFSET(pinfo);
+ appid[jj]= PKTIO_GET_APPID(tempVA);
++#endif
+ //get ptr (Physical address) and length of associate buffer
+ Cppi_getData (Cppi_DescType_HOST, (Cppi_Desc*)tempVA, &buf[jj], &len[jj]);
+ jj+=1;
+ }
+ t2= netapi_timing_stop();
+ j+=(pHd[i-1]? i: (i-1)) ;
+ if (jj>(M-n)) jj=0;
+ l+=1; //n batches
+ ltot+=1;
+ if(pHd[i-1])
+ {
+ if (i>max_batch) max_batch= i;
+ }
+ else
+ {
+ if( (i-1) >max_batch) max_batch = i-1;
+ }
+
+ //cleanup
+ //printf("cleanup %d\n",i);
+ for(k=0;k<i;k++)
+ {
+ //cleanup. need to covert all of desriptor to VA so that i can use freePacket()
+ //alternative would be to just do cache ops plus descriptor raw push to pktlib
+ // heap free queue
+ if(pHd[k])
+ {
+
+ //tempVA=Qmss_osalConvertDescPhyToVirt(pHd[k]);
+ tempVA = Osal_qmssPhyToVirt(pHd[k]);
+ freeQ=Qmss_getQueueHandle(Cppi_getReturnQueue (Cppi_DescType_HOST, tempVA));
- netapi_utilCacheWbInv(pHd[k],128);
++ netapi_utilCacheWbInv(tempVA,128);
+ //would need to wbInv buffer also in practice. Also need to walk
+ // descriptor chain
+ t11= netapi_timing_stop();
+ // Pktlib_freePacket(tempVA);
+ PKTIO_QMSS_QUEUE_PUSH_DESC_SIZE_RAW (freeQ,
+ (void *) pHd[k],
+ 128);
+
+ t12= netapi_timing_stop();
+ sumf += (t12-t11);
+ }
+ }
+ sumt += (t2-t1);
+ sump +=(pHd[i-1]? i: (i-1));
+ //printf("end cleanup %d %d %d\n",sumt,sumf,sump );
+ if (sump > 10000) {
+ printf("pkts rx %d batches=%d appid=%x l3_off=%d l4_off=%d len=%d buf=0x%x rxcycle= %d pkts/batchx1000=%d maxbatch=%d cycles per rawpush = %d\n",
+ j,ltot, appid[j%M],
+ l3_off[j%M],l4_off[j%M],
+ len[j%M],buf[j%M],
+ sumt/sump, (sump*1000)/l, max_batch,
+ sumf/sump);
+ sumt=sump=sumf=0;
+ l=0;
+ }
+}
+
+
+}
+
+