summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b761479)
raw | patch | inline | side by side (parent: b761479)
author | David Lide <a0216552@gtudci01.(none)> | |
Tue, 7 Feb 2012 21:28:22 +0000 (16:28 -0500) | ||
committer | David Lide <a0216552@gtudci01.(none)> | |
Tue, 7 Feb 2012 21:28:22 +0000 (16:28 -0500) |
added cleanup to netapi_shutdown
bug fix in pktio channel context allocation
del mac, del ip tested
added pktlib heap close (kind of)
bug fix in pktio channel context allocation
del mac, del ip tested
added pktlib heap close (kind of)
index f7a8bac0350c1a65497dc436f36c9bd12e79edf7..0f0f31ee839c20fe75bebc42f9e13095d55db77c 100644 (file)
-/**************************************************************
- * 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>
-
-/**
- * @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_MASTE 0 //data only
-
-
-#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_sched.h"
-#include "src/netapi_vm.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
- * @retval @ref NETAPI_T: handle to the instance or NULL on error
- * @pre none
- */
-NETAPI_T netapi_init(int master);
-
-
-/** @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) {
-NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
-return pp->def_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) {
-NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
-return pp->def_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
- */
-int netapi_registerHeap(NETAPI_T p, Pktlib_HeapHandle h);
-
-/** @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()
- */
-int netapi_unregisterHeap(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);
-
-#endif
+/**************************************************************\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
+ * @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_MASTE 0 //data only\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_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
+ * @retval @ref NETAPI_T: handle to the instance or NULL on error \r
+ * @pre none \r
+ */\r
+NETAPI_T netapi_init(int master);\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
+NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;\r
+return pp->def_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
+NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;\r
+return pp->def_route;}\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
+#endif\r
index ce788fd2d8c6122120ec41978fdc519402c7ccbc..6cf7f30ac8fe65f84e953cab260923e81c64bbef 100644 (file)
-/*******************************
- * file: netapi_err.h
- * purpose: netapi error codes
- **************************************************************
- * @file netapi.h
- *
- * @brief DESCRIPTION: netapi Error Definitions 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 __NETAPI_ERR__
-#define __NETAPI_ERR__
-/**
- * @defgroup NETAPI_RetValue NETAPI Return Codes
- */
-/** @ingroup NETAPI_RetValue */
-
-/**
- * @def NETAPI_ERR_OK
- * No error
- */
-#define NETAPI_ERR_OK 0
-/**
- * @ingroup NETAPI_RetValue
- * @def NETAPI_ERR_NOMEM
- * @brief out of memory error
- */
-#define NETAPI_ERR_NOMEM -1
-/**
-* @ingroup NETAPI_RetValue
- * @def NETAPI_ERR_BAD_INPUT
- * arguments or configuraiton is invalid
- */
-#define NETAPI_ERR_BAD_INPUT -2
-/**
-* @ingroup NETAPI_RetValue
- * @def NETAPI_ERR_QLLD
- * QUEUE MANAGER Reports an error
- */
-#define NETAPI_ERR_QLLD -3
-/**
-* @ingroup NETAPI_RetValue
- * @def NETAPI_ERR_NOTFOUND
- * the resource cannot be located
- */
-#define NETAPI_ERR_NOTFOUND -4
-/**
-* @ingroup NETAPI_RetValue
- * @def NETAPI_ERR_BUSY
- * Temporarily out of resources or resource leak
- */
-#define NETAPI_ERR_BUSY -5
-/**
-* @ingroup NETAPI_RetValue
- * @def NETAPI_ERR_NWAL_ERR0
- * NWAL subsytem reports error
- */
-#define NETAPI_ERR_NWAL_ERR0 -6
-/**
-* @ingroup NETAPI_RetValue
- * @def NETAPI_ERR_ALREADY_CANCELLED
- * timer has already been cancelled
- */
-#define NETAPI_ERR_ALREADY_CANCELLED -100
-/**
-* @ingroup NETAPI_RetValue
- * @def NETAPI_ERR_NWAL_TX_ERR
- * error trying to send to NWAL.
- */
-#define NETAPI_ERR_NWAL_TX_ERR -65536
-#endif
+/*******************************\r
+ * file: netapi_err.h\r
+ * purpose: netapi error codes\r
+ **************************************************************\r
+ * @file netapi.h\r
+ * \r
+ * @brief DESCRIPTION: netapi Error Definitions 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
+\r
+#ifndef __NETAPI_ERR__\r
+#define __NETAPI_ERR__\r
+/**\r
+ * @defgroup NETAPI_RetValue NETAPI Return Codes\r
+ */\r
+/** @ingroup NETAPI_RetValue */\r
+\r
+/**\r
+ * @def NETAPI_ERR_OK\r
+ * No error \r
+ */\r
+#define NETAPI_ERR_OK 0\r
+/**\r
+ * @ingroup NETAPI_RetValue\r
+ * @def NETAPI_ERR_NOMEM\r
+ * @brief out of memory error \r
+ */\r
+#define NETAPI_ERR_NOMEM -1\r
+/**\r
+* @ingroup NETAPI_RetValue\r
+ * @def NETAPI_ERR_BAD_INPUT\r
+ * arguments or configuraiton is invalid\r
+ */\r
+#define NETAPI_ERR_BAD_INPUT -2\r
+/**\r
+* @ingroup NETAPI_RetValue\r
+ * @def NETAPI_ERR_QLLD \r
+ * QUEUE MANAGER Reports an error\r
+ */\r
+#define NETAPI_ERR_QLLD -3\r
+/**\r
+* @ingroup NETAPI_RetValue\r
+ * @def NETAPI_ERR_NOTFOUND\r
+ * the resource cannot be located\r
+ */\r
+#define NETAPI_ERR_NOTFOUND -4\r
+/**\r
+* @ingroup NETAPI_RetValue\r
+ * @def NETAPI_ERR_BUSY\r
+ * Temporarily out of resources or resource leak\r
+ */\r
+#define NETAPI_ERR_BUSY -5 \r
+/**\r
+* @ingroup NETAPI_RetValue\r
+ * @def NETAPI_ERR_NWAL_ERR0\r
+ * NWAL subsytem reports error \r
+ */\r
+#define NETAPI_ERR_NWAL_ERR0 -6\r
+/**\r
+* @ingroup NETAPI_RetValue\r
+ * @def NETAPI_ERR_NOT_IMLEMENTED_\r
+ * Feature not implemented in this version \r
+ */\r
+#define NETAPI_ERR_NOT_IMPLEMENTED -7\r
+/**\r
+* @ingroup NETAPI_RetValue\r
+ * @def NETAPI_ERR_ALREADY_CANCELLED\r
+ * timer has already been cancelled\r
+ */\r
+#define NETAPI_ERR_ALREADY_CANCELLED -100\r
+/**\r
+* @ingroup NETAPI_RetValue\r
+ * @def NETAPI_ERR_NWAL_TX_ERR\r
+ * error trying to send to NWAL. \r
+ */\r
+#define NETAPI_ERR_NWAL_TX_ERR -65536\r
+#endif\r
index 3e6215d38bcf2da851a50e92cb114d83b08dd92a..79985be599b1d9808652e8a25953cfffc5275e3b 100644 (file)
-/**************************************************************
- * FILE: netapi_tune.h
- * Purpose: hold tunable parameters (build time)
- **************************************************************
- * @file netapi_tune.h
- *
- * @brief DESCRIPTION: Tuneable (compile time) parameters 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 __NETAPI_TUNE__H
-#define __NETAPI_TUNE__H
-
-
-/**
- * @defgroup NETAPI_TUNE NETAPI tunable parameters
- */
-/** @ingroup NETAPI_TUNE */
-
-/**
-* @def NETAPI_ENABLE_SECURITY
-* (0) define this to enable securtiy. Note: libraries being use need to be built with SA enabled also!
-*/
-//#define NETAPI_ENABLE_SECURITY
-
-/**
- * @def TUNE_NETAPI_NUM_CORES
- * (0) How many cores (theads)
- */
-#define TUNE_NETAPI_NUM_CORES 1
-
-/**
- * @def TUNE_NETAPI_PERM_MEM_SZ
- * (1) how much contiguous memory to grab. This is used for
- * descriptors and buffers. Can't be bigger than MSMC (internal SOC memory area)
- */
-#define TUNE_NETAPI_PERM_MEM_SZ (2*1024*1024)
-
-/**
- * @def TUNE_NETAPI_MAX_PKTIO
- * (2) how many GLOBAL pkt io channels
- */
-#define TUNE_NETAPI_MAX_PKTIO 16
-
-//(2a) default TX channel name
-//(2b) default RX channel name
-
-
-/**
- * @def TUNE_NETAPI_DEFAULT_BUFFER_SIZE
- * (3) size of netapi default pktlib heap buffers
- */
-#define TUNE_NETAPI_DEFAULT_BUFFER_SIZE 1600
-
-//(3a) default pkt heap name
-
-/**
- * @def TUNE_NETAPI_DEFAULT_NUM_BUFFERS
- *(4) number of netapi default pktlib heap buffers (and assoc descriptors)
- */
-#define TUNE_NETAPI_DEFAULT_NUM_BUFFERS 200
-
-/*
- * @def TUNE_NETAPI_DEFAULT_NUM_SOLO_DESCRIPTORS
- * (5) number of netapi default pkt lib heap solo descriptors
- */
-#define TUNE_NETAPI_DEFAULT_NUM_SOLO_DESCRIPTORS 100
-
-/**
- * @def NETAPI_INCLUDE_SCHED
- * (6) define this to include the scheduler component
- */
-#define NETAPI_INCLUDE_SCHED
-
-//(7) # of QM descriptors (total)
-#define TUNE_NETAPI_QM_CONFIG_MAX_DESC_NUM 1024 /* 16384 is abs max */
-
-//(8) Region info
-#define TUNE_NETAPI_NUM_LOCAL_DESC 64
-
-/* at least as big as DEFAULT_NUM_SOLO+DEFAULT_NUM_BUFFERS but also a power of 2*/
-#define TUNE_NETAPI_NUM_GLOBAL_DESC 512
-#define TUNE_NETAPI_DESC_SIZE 128 //don't change!!
-
-//(9) Define to 1 for DEBUG MODE [where NETCP just loops pkts that tx back to rx]
-#define TUNE_NETAPI_NWAL_ENABLE_PASS_LOOPBACK 0 /*1*/
-
-
-//(10) NWAL (internal) config. Should not have to change
-#define TUNE_NETAPI_CONFIG_MAX_PA_TO_SA_DESC 16
-#define TUNE_NETAPI_CONFIG_MAX_SA_TO_PA_DESC 16
-
-#define TUNE_NETAPI_MAX_NUM_MAC 2 //2 'logical' mac addresses
-#define TUNE_NETAPI_MAX_NUM_IP 2 //2 ip addresses
-#define TUNE_NETAPI_MAX_NUM_PORTS_PER_CORE 4 //udp/tcp ports -> for lUT2 )
-#define TUNE_NETAPI_MAX_NUM_PORTS (TUNE_NETAPI_MAX_NUM_PORTS_PER_CORE * (TUNE_NETAPI_NUM_CORES))
-
-#ifdef NETAPI_ENABLE_SECURITY
-#define TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS 2
-#else
-#define TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS 0
-#endif
-#define TUNE_NETAPI_MAX_NUM_L2_L3_HDRS 2
-#define TUNE_NETAPI_MAX_NUM_TRANS (TUNE_NETAPI_MAX_NUM_MAC + TUNE_NETAPI_MAX_NUM_IP + TUNE_NETAPI_MAX_NUM_PORTS + TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS)
-
-//(11) PA control buffer pool (internal)
-#define TUNE_NETAPI_CONFIG_MAX_CTL_RXTX_BUF_SIZE 384
-#define TUNE_NETAPI_CONFIG_NUM_CTL_BUF 16
-
-//(12) PKTIO RECV BURST SIZE
-#define TUNE_NETAPI_MAX_BURST_RCV 32 //max #ok pkts to recv in one poll
-
-//(13) netcp interfaces
-#define TUNE_NETAPI_MAX_IP_PER_INTERFACE 2 //2 ip's per interface
-#define TUNE_NETAPI_MAX_INTERFACES 2 //2 interfaces
-
-//(14) timers
-#define TUNE_NETAPI_NUM_TIMER_CELLS 128 //# of hash bins in a timer group
-#define TUNE_NETAPI_NUM_GLOBAL_TIMERS 4 //# global timer blocks
-#endif
+/**************************************************************\r
+ * FILE: netapi_tune.h\r
+ * Purpose: hold tunable parameters (build time)\r
+ **************************************************************\r
+ * @file netapi_tune.h\r
+ * \r
+ * @brief DESCRIPTION: Tuneable (compile time) parameters 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 __NETAPI_TUNE__H\r
+#define __NETAPI_TUNE__H\r
+\r
+\r
+/**\r
+ * @defgroup NETAPI_TUNE NETAPI tunable parameters\r
+ */\r
+/** @ingroup NETAPI_TUNE */\r
+\r
+/**\r
+* @def NETAPI_ENABLE_SECURITY\r
+* (0) define this to enable securtiy. Note: libraries being use need to be built with SA enabled also! \r
+*/\r
+//#define NETAPI_ENABLE_SECURITY \r
+\r
+/**\r
+ * @def TUNE_NETAPI_NUM_CORES\r
+ * (0) How many cores (theads) \r
+ */\r
+#define TUNE_NETAPI_NUM_CORES 1\r
+\r
+/**\r
+ * @def TUNE_NETAPI_PERM_MEM_SZ\r
+ * (1) how much contiguous memory to grab. This is used for\r
+ * descriptors and buffers. Can't be bigger than MSMC (internal SOC memory area) \r
+ */\r
+#define TUNE_NETAPI_PERM_MEM_SZ (2*1024*1024)\r
+\r
+/**\r
+ * @def TUNE_NETAPI_MAX_PKTIO\r
+ * (2) how many GLOBAL pkt io channels\r
+ */\r
+#define TUNE_NETAPI_MAX_PKTIO 16\r
+\r
+//(2a) default TX channel name\r
+//(2b) default RX channel name\r
+\r
+\r
+/**\r
+ * @def TUNE_NETAPI_DEFAULT_BUFFER_SIZE\r
+ * (3) size of netapi default pktlib heap buffers\r
+ */\r
+#define TUNE_NETAPI_DEFAULT_BUFFER_SIZE 1600 \r
+\r
+//(3a) default pkt heap name\r
+\r
+/**\r
+ * @def TUNE_NETAPI_DEFAULT_NUM_BUFFERS\r
+ *(4) number of netapi default pktlib heap buffers (and assoc descriptors)\r
+ */\r
+#define TUNE_NETAPI_DEFAULT_NUM_BUFFERS 200 \r
+\r
+/*\r
+ * @def TUNE_NETAPI_DEFAULT_NUM_SOLO_DESCRIPTORS\r
+ * (5) number of netapi default pkt lib heap solo descriptors\r
+ */\r
+#define TUNE_NETAPI_DEFAULT_NUM_SOLO_DESCRIPTORS 100 \r
+\r
+/**\r
+ * @def NETAPI_INCLUDE_SCHED\r
+ * (6) define this to include the scheduler component\r
+ */\r
+#define NETAPI_INCLUDE_SCHED \r
+\r
+//(7) # of QM descriptors (total)\r
+#define TUNE_NETAPI_QM_CONFIG_MAX_DESC_NUM 1024 /* 16384 is abs max */\r
+\r
+//(8) Region info\r
+#define TUNE_NETAPI_NUM_LOCAL_DESC 64 \r
+\r
+/* at least as big as DEFAULT_NUM_SOLO+DEFAULT_NUM_BUFFERS but also a power of 2*/\r
+#define TUNE_NETAPI_NUM_GLOBAL_DESC 512 \r
+#define TUNE_NETAPI_DESC_SIZE 128 //don't change!!\r
+\r
+//(9) Define to 1 for DEBUG MODE [where NETCP just loops pkts that tx back to rx]\r
+#define TUNE_NETAPI_NWAL_ENABLE_PASS_LOOPBACK 0 /*1*/\r
+\r
+\r
+//(10) NWAL (internal) config. Should not have to change\r
+#define TUNE_NETAPI_CONFIG_MAX_PA_TO_SA_DESC 16\r
+#define TUNE_NETAPI_CONFIG_MAX_SA_TO_PA_DESC 16\r
+\r
+#define TUNE_NETAPI_MAX_NUM_MAC 2 //2 'logical' mac addresses\r
+#define TUNE_NETAPI_MAX_NUM_IP 2 //2 ip addresses \r
+#define TUNE_NETAPI_MAX_NUM_PORTS_PER_CORE 4 //udp/tcp ports -> for lUT2 ) \r
+#define TUNE_NETAPI_MAX_NUM_PORTS (TUNE_NETAPI_MAX_NUM_PORTS_PER_CORE * (TUNE_NETAPI_NUM_CORES)) \r
+\r
+#ifdef NETAPI_ENABLE_SECURITY\r
+#define TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS 2\r
+#else\r
+#define TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS 0\r
+#endif\r
+#define TUNE_NETAPI_MAX_NUM_L2_L3_HDRS 2\r
+#define TUNE_NETAPI_MAX_NUM_TRANS (TUNE_NETAPI_MAX_NUM_MAC + TUNE_NETAPI_MAX_NUM_IP + TUNE_NETAPI_MAX_NUM_PORTS + TUNE_NETAPI_MAX_NUM_IPSEC_CHANNELS)\r
+\r
+//(11) PA control buffer pool (internal)\r
+#define TUNE_NETAPI_CONFIG_MAX_CTL_RXTX_BUF_SIZE 384\r
+#define TUNE_NETAPI_CONFIG_NUM_CTL_BUF 16 \r
+\r
+//(12) PKTIO RECV BURST SIZE\r
+#define TUNE_NETAPI_MAX_BURST_RCV 32 //max #ok pkts to recv in one poll\r
+\r
+//(13) netcp interfaces\r
+#define TUNE_NETAPI_MAX_IP_PER_INTERFACE 2 //2 ip's per interface\r
+#define TUNE_NETAPI_MAX_INTERFACES 2 //2 interfaces\r
+\r
+//(14) timers\r
+#define TUNE_NETAPI_NUM_TIMER_CELLS 128 //# of hash bins in a timer group\r
+#define TUNE_NETAPI_NUM_GLOBAL_TIMERS 4 //# global timer blocks\r
+\r
+//(15) heaps\r
+#define TUNE_NETAPI_MAX_HEAPS 4 //max # of heaps one instance can create\r
+#endif\r
index 3f1f55a00afd6a76e53ff9a42da0cb15e7b764bb..f59851b57e4a99fe130a0a28922971deb4f853cb 100644 (file)
-/*********************************
- *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 "netapi_err.h"
-
-/*--------------------defines-----------------------*/
-#define PKTIO_NOMEM NETAPI_ERR_NOMEM
-#define NETCP_TX "NETCP_TX"
-#define NETCP_RX "NETCP_RX"
-#define PKTIO_MAX_NAME 19
-
-/*--------------------data structures----------------*/
-typedef struct PKTIO_METADATA_Tag
-{
- int flags1;
-#define PKTIO_META_RX 0x01
-#define PKTIO_META_TX 0x02
-
- union
- {
- nwalRxPktInfo_t * rx_meta;
- nwalTxPktInfo_t * tx_meta;
- } u;
-} PKTIO_METADATA_T;
-
-/* the callback function */
-struct PKTIO_HANDLE_tag;
-
-#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 );
-
-/** 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 q is for NETCP RX
-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
-#define PKTIO_4_ADJ_RX 1
-#define PKTIO_DEF_RX 2
- 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 */
- char name[PKTIO_MAX_NAME+1];
-} PKTIO_HANDLE_T;
-
-
-
-typedef struct PKTIO_CONTROL_Tag
-{
-#define CLEAR 0x1 //clear out the channel
-#define DIVERT 0x2 //divert, (to dest channel)
- int op;
- PKTIO_HANDLE_T *dest;
-} PKTIO_CONTROL_T;
-
-
-//polling control
-typedef struct PKTIO_POLL_Tag
-{
-/* future */
-} PKTIO_POLL_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
- */
-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);
-
-/*
-* @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
- */
-int pktio_poll(PKTIO_HANDLE_T * handle, //handle to pktio
- PKTIO_POLL_T * p_poll_cfg, //polling configuration
- int * 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
-
-#endif
+/*********************************\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 "netapi_err.h"\r
+\r
+/*--------------------defines-----------------------*/\r
+#define PKTIO_NOMEM NETAPI_ERR_NOMEM\r
+#define NETCP_TX "NETCP_TX"\r
+#define NETCP_RX "NETCP_RX"\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
+\r
+ union\r
+ {\r
+ nwalRxPktInfo_t * rx_meta;\r
+ nwalTxPktInfo_t * tx_meta;\r
+ } u;\r
+} PKTIO_METADATA_T;\r
+\r
+/* the callback function */\r
+struct PKTIO_HANDLE_tag;\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
+/** 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 q is for NETCP RX\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\r
+#define PKTIO_4_ADJ_RX 1\r
+#define PKTIO_DEF_RX 2\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
+ 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
+//polling control\r
+typedef struct PKTIO_POLL_Tag\r
+{\r
+/* future */\r
+} PKTIO_POLL_T;\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
+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
+/*\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
+int pktio_poll(PKTIO_HANDLE_T * handle, //handle to pktio\r
+ PKTIO_POLL_T * p_poll_cfg, //polling configuration\r
+ int * err);\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
+\r
+#endif\r
index 5397bb430bab226e4ea72749e137b1627b716b9a..89bf6935bd1f6a733020405528ebb13a0a24fd36 100644 (file)
-/*******************************
- * 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 zapQ(int queueNum);
-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 NUM_SHARED_DESC (TUNE_NETAPI_NUM_GLOBAL_DESC)
-#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 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;}
-
-
-/*-------------------------------------
- * initialize NETAPI instance
- *-------------------------------------*/
-NETAPI_T netapi_init(int master)
-{
- 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)
- {
- 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)
-{
- NETAPI_HANDLE_T * p = (NETAPI_HANDLE_T *) h;
- if (!p) return;
-
- printf(">netapi: shutdown not fully implemented\n");
- if (p->master)
- {
- /* close heap */
- /* close queues */
- netapi_cleanup_at_start();
- /* close pa */
- }
- 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 controlHeapHandle;
-
- /* 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 ();
- 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(
- NUM_SHARED_DESC,
- 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;
-
- /* Create Shared Heap with specified configuration. */
-#define SHARED_MAX_DATA_SIZE (TUNE_NETAPI_DEFAULT_BUFFER_SIZE)
- sharedHeapHandle = Pktlib_createHeap("netapi", Qmss_MemRegion_MEMORY_REGION0,
- 1,
- SHARED_MAX_DATA_SIZE,
- TUNE_NETAPI_DEFAULT_NUM_BUFFERS,
- TUNE_NETAPI_DEFAULT_NUM_SOLO_DESCRIPTORS,
- &netapi_pktlib_ifTable);
- //todo -> cleanup on failure
- if (!sharedHeapHandle) { printf(">'netapi' heap create failed\n"); return -1;}
- handle->netcp_heap= sharedHeapHandle;
-
- controlHeapHandle = Pktlib_createHeap("netapi_control", Qmss_MemRegion_MEMORY_REGION0,
- 1,
- TUNE_NETAPI_CONFIG_MAX_CTL_RXTX_BUF_SIZE,
- TUNE_NETAPI_CONFIG_NUM_CTL_BUF,
- 0,
- &netapi_pktlib_ifTable);
- //todo -> cleanup on failure
- if (!controlHeapHandle) { printf(">netapi -'netapicontrol' heap create failed\n"); return -1;}
- handle->netcp_control_heap= controlHeapHandle;
-
-
- /* now NWAL */
- result = netapi_init_nwal(
- Qmss_MemRegion_MEMORY_REGION0,
- &netapi_pktlib_ifTable,
- &netapi_global.nwal_context);
- if (result<0) {printf(">netapi init_nwal() failed\n"); return -1; }
-
- /* start NWAL */
- result = netapi_start_nwal(sharedHeapHandle,
- controlHeapHandle,
- &handle->nwal_local,
- &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)
-{
- NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) h;
- Pktlib_garbageCollection(n->netcp_heap);
- /* todo: register heaps of app */
-}
-
-/* todo */
-int netapi_registerHeap(NETAPI_T p, Pktlib_HeapHandle h){ return 0;}
-int netapi_unregisterHeap(NETAPI_T p, Pktlib_HeapHandle h) { return 0;}
-
-/* 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
-static void zapQ(int queueNum)
-{
-char * descPtr;
-int i;
-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\n",i);
-}
-
-//defensive: clean out stuff hanging around
-//
-// open a bunch of free queues and zap them
-#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);
- zapQ(tempQH[i]);
-}
-
-for(i=0;i<NQUEUES2CLEAR;i++)
-{
- Qmss_queueClose(tempQH[i]);
-}
-
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+/*******************************\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 NUM_SHARED_DESC (TUNE_NETAPI_NUM_GLOBAL_DESC) \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 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)\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
+ 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: shutdown not 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
+ \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 queues..\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, 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
+\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 (); \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
+ NUM_SHARED_DESC,\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
+ 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
+ /* Create Shared Heap with specified configuration. */\r
+#define SHARED_MAX_DATA_SIZE (TUNE_NETAPI_DEFAULT_BUFFER_SIZE) \r
+ sharedHeapHandle = Pktlib_createHeap("netapi", Qmss_MemRegion_MEMORY_REGION0,\r
+ 1,\r
+ SHARED_MAX_DATA_SIZE,\r
+ TUNE_NETAPI_DEFAULT_NUM_BUFFERS,\r
+ TUNE_NETAPI_DEFAULT_NUM_SOLO_DESCRIPTORS,\r
+ &netapi_pktlib_ifTable);\r
+ //todo -> cleanup on failure\r
+ if (!sharedHeapHandle) { printf(">'netapi' heap create failed\n"); return -1;}\r
+ handle->netcp_heap= sharedHeapHandle;\r
+\r
+ controlHeapHandle = Pktlib_createHeap("netapi_control", Qmss_MemRegion_MEMORY_REGION0,\r
+ 1,\r
+ TUNE_NETAPI_CONFIG_MAX_CTL_RXTX_BUF_SIZE,\r
+ TUNE_NETAPI_CONFIG_NUM_CTL_BUF,\r
+ 0,\r
+ &netapi_pktlib_ifTable);\r
+ //todo -> cleanup on failure\r
+ if (!controlHeapHandle) { printf(">netapi -'netapicontrol' heap create failed\n"); return -1;}\r
+ handle->netcp_control_heap= controlHeapHandle;\r
+\r
+\r
+ /* now NWAL */\r
+ result = netapi_init_nwal(\r
+ Qmss_MemRegion_MEMORY_REGION0,\r
+ &netapi_pktlib_ifTable, \r
+ &netapi_global.nwal_context);\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.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
+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\n",i);\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
index 3af673cec04653f29b59fb9ccbd6d88301c3f882..290ec7384f438903d84125621a7536769b861707 100644 (file)
-/*****************************************
- * file: netapi_loc.h
- * purpose: internal netapi stuff
- ****************************************/
-
-#ifndef __NETAPI_LOC__H
-#define __NETAPI_LOC__H
-/***************************************
-* INTERNAL HANDLE STRUCTURE DEFINITION
-****************************************/
-
-/***********************************************
- * GLOBAL AREA
- * short term: this is global to process
- * (multi-process not supported)
- * long term: this structure gets put in shared memory
- ***********************************************/
-
-/* list of global pktio channels that have been created
- (NETCP_TX, RX are intrinsic so won't be here) */
-typedef struct PKTIO_ENTRY_tag
-{
- char name[PKTIO_MAX_NAME+1];
- Qmss_Queue qn; // -1 => slot is free
-} PKTIO_ENTRY_T;
-
-/* to hold an IP on an interface */
-typedef struct NETCP_INTERFACE_IP_Tag
-{
- int in_use;
- void * nwal_handle;
- nwal_IpType ip_type;
- nwalIpAddr_t ip_addr;
- nwalIpOpt_t ip_qualifiers;
-} NETCP_INTERFACE_IP_T;
-
-/* to hold a netcp 'interface' */
-typedef struct NETCP_INTERFACE_Tag
-{
- int in_use; /* 1 for valid */
- int state; /* 0=down, 1=up, future.. */
- void * nwal_handle; //handle associated with this interface
- unsigned char mac[6]; // mac address
- unsigned int vlan; //future
- NETCP_INTERFACE_IP_T ips[TUNE_NETAPI_MAX_IP_PER_INTERFACE];
-} NETCP_INTERFACE_T;
-
-/*to keep track of netcp config transactions */
-typedef struct {
- nwal_Bool_t inUse;
- uint16_t transType;
-#define NETAPI_NWAL_HANDLE_TRANS_NONE 0
-#define NETAPI_NWAL_HANDLE_TRANS_MAC 1
-#define NETAPI_NWAL_HANDLE_TRANS_IP 2
-#define NETAPI_NWAL_HANDLE_TRANS_PORT 3
-#define NETAPI_NWAL_HANDLE_TRANS_SEC_ASSOC 4
-#define NETAPI_NWAL_HANDLE_TRANS_SEC_POLICY 5
-#define NETAPI_NWAL_HANDLE_STAT_REQUEST 6
-
- uint16_t state;
-#define NETAPI_NWAL_HANDLE_STATE_IDLE 0
-#define NETAPI_NWAL_HANDLE_STATE_OPEN_PENDING 1
-#define NETAPI_NWAL_HANDLE_STATE_OPEN 2
-#define NETAPI_NWAL_HANDLE_STATE_CLOSE_PENDING 3
- nwal_Handle handle;
- uint64_t transId;
- NETAPI_T netapi_handle; //the thread making the transaction
-} NetapiNwalTransInfo_t;
-
-/* nwal global context */
-typedef struct
-{
- int state;
-#define NETAPI_NW_CXT_GLOB_INACTIVE 0x0
-#define NETAPI__CXT_GLOB_ACTIVE 0x1
-#define NETAPI_NW_CXT_GLOB_RES_ALLOC_COMPLETE 0x3
-
- nwal_Handle nwalInstHandle;
- paSysStats_t paStats;
- int numCmdPass;
- int numCmdFail;
- int numBogusTransIds;
- NetapiNwalTransInfo_t transInfos[TUNE_NETAPI_MAX_NUM_TRANS];
- NETCP_INTERFACE_T interfaces[TUNE_NETAPI_MAX_INTERFACES];
-
-} NETAPI_NWAL_GLOBAL_CONTEXT_T;
-
-/* NWAL Local context (per core/thread) */
-typedef struct
-{
- //void * nwalLocInstance;
-#define NETAPI_NW_CXT_LOC_INACTIVE 0x0
-#define NETAPI_NW_CXT_LOC_ACTIVE 0x2
- int state;
-
- int numPendingCfg;
- NETCP_CFG_STATS_CB stats_cb;
-
-/* stats */
- int numL2PktsRecvd;
- int numL3PktsRecvd;
- int numL4PktsRecvd;
- int numL4PktsSent;
- int TxErrDrop;
-
- /* local config */
- nwalLocCfg_t nwalLocCfg;
-} NETAPI_NWAL_LOCAL_CONTEXT_T;
-
-/* the global */
-typedef struct NETAPI_GLOBAL_tag
-{
-#define NETAPI_MAX_PKTIO (TUNE_NETAPI_MAX_PKTIO)
-PKTIO_ENTRY_T pktios[NETAPI_MAX_PKTIO];
-
-/* pktlib heap */
-
-/* global timers */
-
-/* nwal context */
-NETAPI_NWAL_GLOBAL_CONTEXT_T nwal_context;
-
-} NETAPI_GLOBAL_T;
-
-
-/************************************
- * this is a per thread structure.
- * It contains stuff local to thread
- * and pointer to global stuff
- * that is shared over all threads,
- **************************************/
-typedef struct NETAPI_HANDLE_Tag
-{
- int master; //master type
-
-void * global; /* pointer to the global area */
-
-/* heap handle */
-Pktlib_HeapHandle netcp_heap;
-Pktlib_HeapHandle netcp_control_heap;
-
-/* pktios defined */
-int n_pktios; /* #of pktios that are active for this instance */
-void* pktios[NETAPI_MAX_PKTIO]; /* the list of pktios */
-
-/* scheduler stuff. unallocated if NETAPI_INCLUDE_SCHED not set */
-void * p_sched;
-
-/* nwal local context */
-NETAPI_NWAL_LOCAL_CONTEXT_T nwal_local;
-
-/* security stuff */
-
-/* timer stuff */
-
-
-/* default flow*/
-NETCP_CFG_FLOW_HANDLE_T def_flow; //uses our heap above
-
-/* default route */
-NETCP_CFG_ROUTE_HANDLE_T def_route; //uses our rx channel above
-
-/* thread cookie */
-void * cookie; /*set by calling thread */
-
-} NETAPI_HANDLE_T;
-
-
-//internal initialization routines */
-int netapi_init_qm(void);
-int netapi_init_cppi(void);
-int netapi_init_cpsw(void);
-int netapi_start_qm(void);
-int netapi_init_nwal(
- int region2use,
- Pktlib_HeapIfTable * p_table,
- NETAPI_NWAL_GLOBAL_CONTEXT_T * p_nwal_context );
-int netapi_start_nwal(Pktlib_HeapHandle pkt_heap,
- Pktlib_HeapHandle cmd_heap,
- NETAPI_NWAL_LOCAL_CONTEXT_T *p ,
- NETAPI_NWAL_GLOBAL_CONTEXT_T * p_nwal_glob_context );
-
-int netapi_init_timer(void);
-int netapi_qm_setup_mem_region(
- unsigned int numDesc,
- unsigned int descSize,
- unsigned int* pDescMemBase,
- int memRegion);
-//for above
-#define NETAPI_GLOBAL_REGION 0
-#define NETAPI_LOCAL_REGION 1
-
-
-//nwal callbacks
-void netapi_NWALRxPktCallback (uint32_t appCookie,
- uint16_t numPkts,
- nwalRxPktInfo_t* pPktInfo,
- uint64_t timestamp,
- nwal_Bool_t* pFreePkt);
-
-void netapi_NWALCmdCallBack (nwal_AppId appHandle,
- uint16_t trans_id,
- nwal_RetValue ret);
-
-void netapi_NWALCmdPaStatsReply (nwal_AppId appHandle,
- nwal_TransID_t trans_id,
- paSysStats_t *stats);
-
-//***********************************
-//internal utilities
-//*************************************
-
-//return the list of pktios for this instance
-static inline void * netapi_get_pktio_list(NETAPI_T p)
-{
-NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
-return &pp->pktios[0];
-}
-
-//get scheduler block handle
-static inline void * netapi_get_scheduler(NETAPI_T p)
-{
-NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
-return pp->p_sched;
-}
-
-/* return pointer to global area */
-NETAPI_GLOBAL_T * netapi_get_global(void);
-
-//add a pktio name (and queue) to global list
-static inline int netapi_add_global_pktio(NETAPI_T p, char *name, Qmss_Queue * qn)
-{
-NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
-PKTIO_ENTRY_T *pe;
-int i;
-//find a free slot
-pe = &((NETAPI_GLOBAL_T *)(pp->global))->pktios[0];
-
-for(i=0;i<NETAPI_MAX_PKTIO; i++,pe++)
- {
- if (pe->qn.qNum == -1)
- {
- pe->qn.qNum=qn->qNum;
- pe->qn.qMgr=qn->qMgr;
- strncpy(pe->name, name, PKTIO_MAX_NAME);
- return 1;
- }
- pe+=1;
- }
- return 0; //no room
-}
-
-//delete a pktio name (and queue) to global list
-static inline int netapi_del_global_pktio(NETAPI_T p, char *name)
-{
-NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
-PKTIO_ENTRY_T *pe;
-int i;
-//find slot
-pe = &((NETAPI_GLOBAL_T *)(pp->global))->pktios[0];
-
-for(i=0;i<NETAPI_MAX_PKTIO; i++,pe++)
- {
- if (pe->qn.qNum == -1) continue;
- if (!strncmp(name, pe->name, PKTIO_MAX_NAME))
- {
- pe->qn.qNum=-1;
- pe->name[0]='\0';
- return 1;
- }
- pe+=1;
- }
- return 0; //no room
-}
-
-
-/* get list of global pktios that have been created */
-static inline Qmss_Queue* netapi_find_global_pktio(NETAPI_T p, char *name)
-{
-NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
-PKTIO_ENTRY_T *pe;
-int i;
-//find slot
-pe = &((NETAPI_GLOBAL_T *)(pp->global))->pktios[0];
-
-for(i=0;i<NETAPI_MAX_PKTIO; i++,pe++)
- {
- if (pe->qn.qNum == -1) continue;
- if (!strncmp(name, pe->name, PKTIO_MAX_NAME))
- {
- return &pe->qn;
- }
- pe +=1;
- }
- return NULL; //not found
-}
-
-/* return the nwal global instance handle */
-static inline nwal_Handle netapi_return_nwal_instance_handle(NETAPI_T p)
-{
-
-NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;
-return ((NETAPI_GLOBAL_T *)(pp->global))->nwal_context.nwalInstHandle;
-}
-
-#endif
+/*****************************************\r
+ * file: netapi_loc.h\r
+ * purpose: internal netapi stuff\r
+ ****************************************/\r
+\r
+#ifndef __NETAPI_LOC__H\r
+#define __NETAPI_LOC__H\r
+/***************************************\r
+* INTERNAL HANDLE STRUCTURE DEFINITION\r
+****************************************/\r
+\r
+/***********************************************\r
+ * GLOBAL AREA\r
+ * short term: this is global to process\r
+ * (multi-process not supported)\r
+ * long term: this structure gets put in shared memory \r
+ ***********************************************/\r
+\r
+/* list of global pktio channels that have been created\r
+ (NETCP_TX, RX are intrinsic so won't be here) */\r
+typedef struct PKTIO_ENTRY_tag\r
+{\r
+ char name[PKTIO_MAX_NAME+1];\r
+ Qmss_Queue qn; // -1 => slot is free\r
+} PKTIO_ENTRY_T;\r
+\r
+/* to hold an IP on an interface */\r
+typedef struct NETCP_INTERFACE_IP_Tag\r
+{\r
+ int in_use;\r
+ void * nwal_handle;\r
+ nwal_IpType ip_type;\r
+ nwalIpAddr_t ip_addr;\r
+ nwalIpOpt_t ip_qualifiers;\r
+} NETCP_INTERFACE_IP_T;\r
+\r
+/* to hold a netcp 'interface' */\r
+typedef struct NETCP_INTERFACE_Tag\r
+{\r
+ int in_use; /* 1 for valid */\r
+ int state; /* 0=down, 1=up, future.. */\r
+ void * nwal_handle; //handle associated with this interface\r
+ unsigned char mac[6]; // mac address\r
+ unsigned int vlan; //future\r
+ NETCP_INTERFACE_IP_T ips[TUNE_NETAPI_MAX_IP_PER_INTERFACE];\r
+} NETCP_INTERFACE_T;\r
+\r
+/*to keep track of netcp config transactions */\r
+typedef struct {\r
+ nwal_Bool_t inUse;\r
+ uint16_t transType;\r
+#define NETAPI_NWAL_HANDLE_TRANS_NONE 0\r
+#define NETAPI_NWAL_HANDLE_TRANS_MAC 1\r
+#define NETAPI_NWAL_HANDLE_TRANS_IP 2\r
+#define NETAPI_NWAL_HANDLE_TRANS_PORT 3\r
+#define NETAPI_NWAL_HANDLE_TRANS_SEC_ASSOC 4\r
+#define NETAPI_NWAL_HANDLE_TRANS_SEC_POLICY 5\r
+#define NETAPI_NWAL_HANDLE_STAT_REQUEST 6\r
+\r
+ uint16_t state;\r
+#define NETAPI_NWAL_HANDLE_STATE_IDLE 0\r
+#define NETAPI_NWAL_HANDLE_STATE_OPEN_PENDING 1\r
+#define NETAPI_NWAL_HANDLE_STATE_OPEN 2\r
+#define NETAPI_NWAL_HANDLE_STATE_CLOSE_PENDING 3\r
+ nwal_Handle handle;\r
+ uint64_t transId;\r
+ NETAPI_T netapi_handle; //the thread making the transaction\r
+} NetapiNwalTransInfo_t;\r
+\r
+/* nwal global context */\r
+typedef struct\r
+{\r
+ int state;\r
+#define NETAPI_NW_CXT_GLOB_INACTIVE 0x0\r
+#define NETAPI__CXT_GLOB_ACTIVE 0x1\r
+#define NETAPI_NW_CXT_GLOB_RES_ALLOC_COMPLETE 0x3\r
+\r
+ nwal_Handle nwalInstHandle;\r
+ paSysStats_t paStats;\r
+ int numCmdPass;\r
+ int numCmdFail;\r
+ int numBogusTransIds;\r
+ NetapiNwalTransInfo_t transInfos[TUNE_NETAPI_MAX_NUM_TRANS];\r
+ NETCP_INTERFACE_T interfaces[TUNE_NETAPI_MAX_INTERFACES];\r
+\r
+} NETAPI_NWAL_GLOBAL_CONTEXT_T;\r
+\r
+/* NWAL Local context (per core/thread) */\r
+typedef struct\r
+{\r
+ //void * nwalLocInstance;\r
+#define NETAPI_NW_CXT_LOC_INACTIVE 0x0\r
+#define NETAPI_NW_CXT_LOC_ACTIVE 0x2\r
+ int state;\r
+\r
+ int numPendingCfg;\r
+ NETCP_CFG_STATS_CB stats_cb;\r
+\r
+/* stats */\r
+ int numL2PktsRecvd;\r
+ int numL3PktsRecvd;\r
+ int numL4PktsRecvd;\r
+ int numL4PktsSent;\r
+ int TxErrDrop;\r
+\r
+ /* local config */\r
+ nwalLocCfg_t nwalLocCfg;\r
+} NETAPI_NWAL_LOCAL_CONTEXT_T;\r
+\r
+/* the global */\r
+typedef struct NETAPI_GLOBAL_tag\r
+{\r
+#define NETAPI_MAX_PKTIO (TUNE_NETAPI_MAX_PKTIO) \r
+PKTIO_ENTRY_T pktios[NETAPI_MAX_PKTIO];\r
+\r
+/* pktlib heap */\r
+\r
+/* global timers */\r
+\r
+/* nwal context */\r
+NETAPI_NWAL_GLOBAL_CONTEXT_T nwal_context;\r
+\r
+} NETAPI_GLOBAL_T;\r
+\r
+\r
+/************************************\r
+ * this is a per thread structure.\r
+ * It contains stuff local to thread\r
+ * and pointer to global stuff\r
+ * that is shared over all threads,\r
+ **************************************/\r
+typedef struct NETAPI_HANDLE_Tag\r
+{\r
+int master; //master type\r
+\r
+void * global; /* pointer to the global area */\r
+\r
+/* heap handles */\r
+Pktlib_HeapHandle netcp_heap; /* internal default */\r
+Pktlib_HeapHandle netcp_control_heap; /* for control messages */\r
+Pktlib_HeapHandle createdHeaps[TUNE_NETAPI_MAX_HEAPS]; /* created by app and registered */\r
+\r
+/* pktios defined */\r
+int n_pktios; /* #of pktios that are active for this instance */\r
+void* pktios[NETAPI_MAX_PKTIO]; /* the list of pktios */\r
+\r
+/* scheduler stuff. unallocated if NETAPI_INCLUDE_SCHED not set */\r
+void * p_sched;\r
+\r
+/* nwal local context */\r
+NETAPI_NWAL_LOCAL_CONTEXT_T nwal_local;\r
+\r
+/* security stuff */\r
+\r
+/* timer stuff */\r
+\r
+\r
+/* default flow*/\r
+NETCP_CFG_FLOW_HANDLE_T def_flow; //uses our heap above\r
+\r
+/* default route */\r
+NETCP_CFG_ROUTE_HANDLE_T def_route; //uses our rx channel above\r
+\r
+/* thread cookie */\r
+void * cookie; /*set by calling thread */\r
+\r
+} NETAPI_HANDLE_T;\r
+\r
+\r
+//internal initialization routines */\r
+int netapi_init_qm(void);\r
+int netapi_init_cppi(void);\r
+int netapi_init_cpsw(void);\r
+int netapi_start_qm(void);\r
+int netapi_init_nwal(\r
+ int region2use,\r
+ Pktlib_HeapIfTable * p_table,\r
+ NETAPI_NWAL_GLOBAL_CONTEXT_T * p_nwal_context );\r
+int netapi_start_nwal(Pktlib_HeapHandle pkt_heap,\r
+ Pktlib_HeapHandle cmd_heap,\r
+ NETAPI_NWAL_LOCAL_CONTEXT_T *p ,\r
+ NETAPI_NWAL_GLOBAL_CONTEXT_T * p_nwal_glob_context );\r
+\r
+int netapi_init_timer(void);\r
+int netapi_qm_setup_mem_region(\r
+ unsigned int numDesc,\r
+ unsigned int descSize,\r
+ unsigned int* pDescMemBase,\r
+ int memRegion);\r
+//for above\r
+#define NETAPI_GLOBAL_REGION 0\r
+#define NETAPI_LOCAL_REGION 1\r
+\r
+\r
+//nwal callbacks\r
+void netapi_NWALRxPktCallback (uint32_t appCookie,\r
+ uint16_t numPkts,\r
+ nwalRxPktInfo_t* pPktInfo,\r
+ uint64_t timestamp,\r
+ nwal_Bool_t* pFreePkt);\r
+\r
+void netapi_NWALCmdCallBack (nwal_AppId appHandle,\r
+ uint16_t trans_id,\r
+ nwal_RetValue ret);\r
+\r
+void netapi_NWALCmdPaStatsReply (nwal_AppId appHandle,\r
+ nwal_TransID_t trans_id,\r
+ paSysStats_t *stats);\r
+\r
+//***********************************\r
+//internal utilities\r
+//*************************************\r
+\r
+//return the list of pktios for this instance\r
+static inline void ** netapi_get_pktio_list(NETAPI_T p)\r
+{\r
+NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;\r
+return &pp->pktios[0];\r
+}\r
+\r
+//get scheduler block handle\r
+static inline void * netapi_get_scheduler(NETAPI_T p)\r
+{\r
+NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;\r
+return pp->p_sched;\r
+}\r
+\r
+/* return pointer to global area */\r
+NETAPI_GLOBAL_T * netapi_get_global(void);\r
+\r
+//add a pktio name (and queue) to global list\r
+static inline int netapi_add_global_pktio(NETAPI_T p, char *name, Qmss_Queue * qn)\r
+{\r
+NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;\r
+PKTIO_ENTRY_T *pe;\r
+int i;\r
+//find a free slot\r
+pe = &((NETAPI_GLOBAL_T *)(pp->global))->pktios[0];\r
+\r
+for(i=0;i<NETAPI_MAX_PKTIO; i++,pe++)\r
+ {\r
+ if (pe->qn.qNum == -1)\r
+ {\r
+ pe->qn.qNum=qn->qNum;\r
+ pe->qn.qMgr=qn->qMgr;\r
+ strncpy(pe->name, name, PKTIO_MAX_NAME);\r
+ return 1;\r
+ }\r
+ pe+=1;\r
+ }\r
+ return 0; //no room\r
+}\r
+\r
+//delete a pktio name (and queue) to global list\r
+static inline int netapi_del_global_pktio(NETAPI_T p, char *name)\r
+{\r
+NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;\r
+PKTIO_ENTRY_T *pe;\r
+int i;\r
+//find slot\r
+pe = &((NETAPI_GLOBAL_T *)(pp->global))->pktios[0];\r
+\r
+for(i=0;i<NETAPI_MAX_PKTIO; i++,pe++)\r
+ {\r
+ if (pe->qn.qNum == -1) continue;\r
+ if (!strncmp(name, pe->name, PKTIO_MAX_NAME))\r
+ {\r
+ pe->qn.qNum=-1;\r
+ pe->name[0]='\0';\r
+ return 1;\r
+ }\r
+ pe+=1;\r
+ }\r
+ return 0; //no room\r
+}\r
+\r
+\r
+/* get list of global pktios that have been created */\r
+static inline Qmss_Queue* netapi_find_global_pktio(NETAPI_T p, char *name)\r
+{\r
+NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;\r
+PKTIO_ENTRY_T *pe;\r
+int i;\r
+//find slot\r
+pe = &((NETAPI_GLOBAL_T *)(pp->global))->pktios[0];\r
+\r
+for(i=0;i<NETAPI_MAX_PKTIO; i++,pe++)\r
+ {\r
+ if (pe->qn.qNum == -1) continue;\r
+ if (!strncmp(name, pe->name, PKTIO_MAX_NAME))\r
+ {\r
+ return &pe->qn;\r
+ }\r
+ pe +=1;\r
+ }\r
+ return NULL; //not found\r
+}\r
+\r
+/* return the nwal global instance handle */\r
+static inline nwal_Handle netapi_return_nwal_instance_handle(NETAPI_T p)\r
+{\r
+\r
+NETAPI_HANDLE_T *pp = (NETAPI_HANDLE_T *) p;\r
+return ((NETAPI_GLOBAL_T *)(pp->global))->nwal_context.nwalInstHandle;\r
+}\r
+\r
+//utility to clear out a queue\r
+void netapi_zapQ(int queueNum);\r
+#endif\r
index 1388faedb07dad29a3d97bd2d850a63502b07b0f..f947b374dfb50fd3281e2ccb972e35b8484e509e 100644 (file)
-/*********************************
- * FILE: pktio.c
- * PURPOSE: pktio library for NETAPI
- **************************************************************
- * FILE: pktio.c
- *
- * DESCRIPTION: pktio 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"
-
-/*--------------------Utilites-----------------*/
-static PKTIO_HANDLE_T * pktiop_get_free_channel_slot(NETAPI_T n)
-{
- PKTIO_HANDLE_T * pp = (PKTIO_HANDLE_T*) netapi_get_pktio_list(n);
- int i;
- for(i=0;i<NETAPI_MAX_PKTIO;i++)
- {
- if (pp->inuse != PKTIO_INUSE)
- {
- return pp;
- }
- pp+=1;
- }
- return NULL;
-}
-
-/*-----------------------MAIN API----------------------*/
-/* create a channel */
-PKTIO_HANDLE_T * pktio_create(NETAPI_T n, char * name,
- PKTIO_CB cb, PKTIO_CFG_T * p_cfg, int * err)
-{
-int r = 0;
-PKTIO_HANDLE_T *p;
-uint8_t isAllocated;
-
-*err=0;
-
-if ((!p_cfg)||(!name)) {*err=NETAPI_ERR_BAD_INPUT; return NULL;}
-
-/* get a free channel handle */
-p=pktiop_get_free_channel_slot(n);
-if (!p) {*err = PKTIO_NOMEM; return (p); }
-
-p->inuse= PKTIO_INUSE;
-p->back = n;
-p->cb = cb;
-p->max_n = p_cfg->max_n;
-memcpy((char *)&p->cfg, (char*) p_cfg, sizeof(PKTIO_CFG_T));
-
- /* create a general queue (for now). TODO: allow qnum to be passed in */
- p->q = Qmss_queueOpen(Qmss_QueueType_GENERAL_PURPOSE_QUEUE,
- QMSS_PARAM_NOT_SPECIFIED, &isAllocated);
- if (p->q == (Qmss_QueueHnd) NULL)
- {
- printf(">pktio_create: queueOpen failed\n");
- p->inuse=0;
- *err= NETAPI_ERR_QLLD; ///queue lld error
- return NULL;
- }
- p->qInfo = Qmss_getQueueNumber(p->q);
- if (p->cfg.flags2 & PKTIO_PKT)
- {
- p->use_nwal =1;
- p->nwalInstanceHandle = netapi_return_nwal_instance_handle(n);
- }
- else p->use_nwal=0;
-
- /* save name */
- strncpy(p->name,name,
- strlen(name)<PKTIO_MAX_NAME ?
- strlen(name):PKTIO_MAX_NAME);
-
- /* add name, qnum to global name list */
- if ((strcmp(name,NETCP_RX)) && (strcmp(name,NETCP_TX)) &&
- (p_cfg->flags1 & PKTIO_GLOBAL) )
- {
- //todo: make sure this succeeds..
- netapi_add_global_pktio(n, name, &p->qInfo);
- }
- ((NETAPI_HANDLE_T *)n )->n_pktios+=1;
- return p;
-}
-
-
-/***********************************************************/
-/************** open an existing channel. *****************/
-/***********************************************************/
-PKTIO_HANDLE_T * pktio_open(NETAPI_T n, char *name,
- PKTIO_CB cb, PKTIO_CFG_T * p_cfg, int * err)
-{
-int r=0;
-PKTIO_HANDLE_T *p, *p2;
-uint8_t isAllocated;
-*err=0;
-Qmss_Queue *p_qnum;
-
-if ((!p_cfg)||(!name)) {*err=NETAPI_ERR_BAD_INPUT; return NULL;}
-
-/* get a free channel handle */
-p=pktiop_get_free_channel_slot(n);
-if (!p) {*err = PKTIO_NOMEM; return (p); }
-((NETAPI_HANDLE_T *)n)->n_pktios+=1;
-
-p->inuse= PKTIO_INUSE;
-p->back = n;
-p->cb = cb;
-p->max_n = p_cfg->max_n;
-memcpy((char *)&p->cfg, (char*) p_cfg, sizeof(PKTIO_CFG_T));
-
-/* special handling of NETCP_RX, NETCP_TX */
-if( (!strcmp(name, NETCP_RX)) || (!strcmp(name,NETCP_TX)) )
-{
- /* these have already been opened internally, so don't search in global list */
- p->use_nwal = 2;
- p->q = 0;
- p->nwalInstanceHandle = netapi_return_nwal_instance_handle(n);
-}
-else
-{
- /* find queue in global list */
- p_qnum = netapi_find_global_pktio(n, name);
- if (!p_qnum )
- {
- printf(">pktio_open: can't find %s\n",name);
- p->inuse=0;
- *err= NETAPI_ERR_NOTFOUND; ///queue lld error
- return NULL;
- }
-
- /* open a general queue (for now). use qnum that was just found */
- p->q = Qmss_queueOpen(Qmss_QueueType_GENERAL_PURPOSE_QUEUE,
- p_qnum->qNum , &isAllocated);
- if (p->q == (Qmss_QueueHnd) NULL)
- {
- printf(">pktio_create: queueOpen failed\n");
- p->inuse=0;
- *err= NETAPI_ERR_QLLD; ///queue lld error
- return NULL;
- }
- p->qInfo = Qmss_getQueueNumber(p->q);
- if (p_cfg->flags2 & PKTIO_PKT)
- {
- p->use_nwal =1;
- p->nwalInstanceHandle = netapi_return_nwal_instance_handle(n);
- }
- else p->use_nwal=0;
-}
-
- /* save name */
- strncpy(p->name,name,
- strlen(name)<PKTIO_MAX_NAME ?
- strlen(name):PKTIO_MAX_NAME);
-
-
-
-return p;
-}
-
-/***********************************************************/
-/************** control the channel ****************/
-/***********************************************************/
-void pktio_control(PKTIO_HANDLE_T * p,
- PKTIO_CB cb,
- PKTIO_CFG_T * p_cfg,
- PKTIO_CONTROL_T * p_control,
- int *err)
-{
- if (!p) { *err=1; return;}
- if (cb)
- {
- p->cb = cb;
- }
- if (p_control)
- {
- }
- if (p_cfg)
- {
- p->max_n = p_cfg->max_n;
- memcpy((char *)&p->cfg, (char*) p_cfg, sizeof(PKTIO_CFG_T));
- }
- *err=0;
- return;
-}
-
-/***********************************************************/
-/*****************close ***************************/
-/***********************************************************/
-void pktio_close(PKTIO_HANDLE_T * p, int * err)
-{
- if(!p) { *err=1; return;}
- *err=0;
- //Qmss_queueClose(p->q);
- p->q=-1;
- p->inuse=0;
- ((NETAPI_HANDLE_T *)p->back)->n_pktios-=1;
- return;
-}
-
-/***********************************************************/
-/*****************Delete***************************/
-/***********************************************************/
-void pktio_delete(PKTIO_HANDLE_T * p, int * err)
-{
- if(!p) { *err=1; return;}
- *err=0;
- /* todo remove from name list */
- if(p->use_nwal !=2)
- {
- Qmss_queueClose(p->q);
- }
- p->q=-1;
- p->inuse=0;
- ((NETAPI_HANDLE_T *)p->back)->n_pktios-=1;
- return ;
-}
-
-
-/***********************************************************/
-/*****************send *************************/
-/***********************************************************/
-int pktio_send(PKTIO_HANDLE_T * p, Ti_Pkt *pkt, PKTIO_METADATA_T *m, int * err)
-{
- nwalTxPktInfo_t * pPktInfo=m->u.tx_meta;
- nwal_RetValue res;
- *err=0;
- if(! (p->cfg.flags1&PKTIO_W)) return 0;
- if (p->use_nwal)
- {
- pPktInfo->pPkt = pkt;
- res=nwal_send(p->nwalInstanceHandle, nwal_HANDLE_INVALID,pPktInfo);
- if (res != nwal_OK) *err = NETAPI_ERR_NWAL_TX_ERR -res;
- }
- else
- {
- /* tod: meta data for non netcp xfers */
- /* process meta data */
- Qmss_queuePushDesc (p->q, (void*)pkt);
- }
- return 1;
-}
-
-/***********************************************************/
-/*******************send multiple**************************/
-/***********************************************************/
-int pktio_sendMulti(PKTIO_HANDLE_T * p, Ti_Pkt * pkt[], PKTIO_METADATA_T * m[], int np, int* err)
-{
- int r=0;
- *err=0;
- if(! p->cfg.flags1&PKTIO_W) return 0;
- if (p->use_nwal)
- {
- for(r=0;r<np;r++)
- {
- nwalTxPktInfo_t *pPktInfo= m[r]->u.tx_meta;
- nwal_RetValue res;
- pPktInfo->pPkt = pkt[r];
- res=nwal_send(p->nwalInstanceHandle,nwal_HANDLE_INVALID,pPktInfo);
- if (res != nwal_OK) *err = NETAPI_ERR_NWAL_TX_ERR -res;
- }
- }
- else
- {
- for(r=0;r<np;r++)
- {
- /* process meta data */
- Qmss_queuePushDesc(p->q, (void*) pkt[r]);
- }
- }
- return r;
-}
-
-/***********************************************************/
-/******************* polling **********************/
-/***********************************************************/
-
-/* poll a particular channel */
-int pktio_poll(PKTIO_HANDLE_T * p, PKTIO_POLL_T * p_poll_cfg, int * err)
-{
-int r=0;
-int n;
-Ti_Pkt * temp;
-Ti_Pkt * pkt_list[PKTIO_MAX_RECV];
-PKTIO_METADATA_T meta_s[PKTIO_MAX_RECV];
-uint64_t ts= netapi_getTimestamp(); //get_ts
-
- if(! p->cfg.flags1&PKTIO_R) return 0;
-
- /** poll the netcp default RX queue we squirt out below */
- if (p->use_nwal==2)
- {
- /* Poll for common L2/L3 packets */
- nwal_pollPkt(p->nwalInstanceHandle,
- nwal_POLL_DEFAULT_GLOB_PKT_Q,
- (uint32_t) p,
- p->max_n,
- QMSS_PARAM_NOT_SPECIFIED,
- (void*) NULL);
- }
- /** poll a netcp RX queue. we squirt out below */
- else if (p->use_nwal==1)
- {
- /* Poll an additional NETCP RX queue */
- nwal_pollPkt(p->nwalInstanceHandle,
- nwal_POLL_APP_MANAGED_PKT_Q,
- (uint32_t) p,
- p->max_n,
- p->q,
- (void *) NULL);
- }
- /* poll an IPC queue */
- else
- {
- *err=0;
- n= (p->max_n< PKTIO_MAX_RECV) ? p->max_n : PKTIO_MAX_RECV;
- for(r=0;r<n;r++)
- {
- temp=(Cppi_HostDesc*)QMSS_DESC_PTR(Qmss_queuePop(p->q));
- if(!temp) break;
- /* process meta data */
- pkt_list[r]= temp;
- meta_s[r].flags1=0x1;
- }
- if (r) p->cb((struct PKTIO_HANDLE_tag *)p, pkt_list, &meta_s[0], r, ts);
- }
- return r;
-}
-
-/***********************************************************/
-/** poll all channels attached to this handle */
-/***********************************************************/
-int pktio_pollAll(NETAPI_T handle, PKTIO_POLL_T * p_poll_cfg, int *err)
-{
-int i=0;
-int r=0;
-int err2;
-int cnt=0;
-PKTIO_HANDLE_T *pp =( PKTIO_HANDLE_T *) netapi_get_pktio_list(handle);
-
-*err=0;
-for(i=0;i<NETAPI_MAX_PKTIO && cnt < ((NETAPI_HANDLE_T *)handle)->n_pktios;i++,pp+=1)
-{
- if (pp->inuse != PKTIO_INUSE) continue;
- if(!(pp->cfg.flags1&PKTIO_R)) continue;
- r+=pktio_poll(pp, p_poll_cfg, &err2); cnt+=1;
- if (err2) { *err = err2; break;}
-}
-return r;
-
-}
-
-/***** this is the callback we registered with NWAL for pkt reception *****/
-/* appcookie -> pktio handle */
-void netapi_NWALRxPktCallback (uint32_t appCookie,
- uint16_t numPkts,
- nwalRxPktInfo_t* pPktInfo,
- uint64_t timestamp,
- nwal_Bool_t* pFreePkt)
-{
-PKTIO_HANDLE_T * p = (PKTIO_HANDLE_T *) appCookie;
-int r=0;
-int n;
-Ti_Pkt * pkt_list[PKTIO_MAX_RECV];
-PKTIO_METADATA_T meta_s[PKTIO_MAX_RECV];
- for(r=0;r<numPkts;r++)
- {
- pkt_list[r] = pPktInfo[r].pPkt;
- meta_s[r].flags1 = PKTIO_META_RX;
- meta_s[r].u.rx_meta = &pPktInfo[r];
- }
- if (r) p->cb((struct PKTIO_HANDLE_tag *)p, pkt_list, &meta_s[0], r, timestamp);
-
-}
-
-
+/*********************************\r
+ * FILE: pktio.c\r
+ * PURPOSE: pktio library for NETAPI\r
+ **************************************************************\r
+ * FILE: pktio.c\r
+ * \r
+ * DESCRIPTION: pktio 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
+/*--------------------Utilites-----------------*/\r
+static PKTIO_HANDLE_T * pktiop_get_free_channel_slot(NETAPI_T n)\r
+{\r
+ PKTIO_HANDLE_T ** pp = (PKTIO_HANDLE_T **) netapi_get_pktio_list(n);\r
+ int i;\r
+ for(i=0;i<NETAPI_MAX_PKTIO;i++)\r
+ {\r
+ if (pp[i]->inuse != PKTIO_INUSE)\r
+ {\r
+ return pp[i];\r
+ }\r
+ }\r
+ return NULL;\r
+}\r
+\r
+/*-----------------------MAIN API----------------------*/\r
+/* create a channel */\r
+PKTIO_HANDLE_T * pktio_create(NETAPI_T n, char * name,\r
+ PKTIO_CB cb, PKTIO_CFG_T * p_cfg, int * err)\r
+{\r
+int r = 0;\r
+PKTIO_HANDLE_T *p;\r
+uint8_t isAllocated;\r
+\r
+*err=0;\r
+\r
+if ((!p_cfg)||(!name)) {*err=NETAPI_ERR_BAD_INPUT; return NULL;}\r
+\r
+/* get a free channel handle */\r
+p=pktiop_get_free_channel_slot(n);\r
+if (!p) {*err = PKTIO_NOMEM; return (p); }\r
+\r
+p->inuse= PKTIO_INUSE;\r
+p->back = n;\r
+p->cb = cb;\r
+p->max_n = p_cfg->max_n;\r
+memcpy((char *)&p->cfg, (char*) p_cfg, sizeof(PKTIO_CFG_T));\r
+\r
+ /* create a general queue (for now). todo: allow qnum to be passed in */\r
+ p->q = Qmss_queueOpen(Qmss_QueueType_GENERAL_PURPOSE_QUEUE,\r
+ QMSS_PARAM_NOT_SPECIFIED, &isAllocated);\r
+ if (p->q == (Qmss_QueueHnd) NULL)\r
+ {\r
+ printf(">pktio_create: queueOpen failed\n");\r
+ p->inuse=0;\r
+ *err= NETAPI_ERR_QLLD; ///queue lld error\r
+ return NULL;\r
+ }\r
+ p->qInfo = Qmss_getQueueNumber(p->q);\r
+ if (p->cfg.flags2 & PKTIO_PKT) \r
+ {\r
+ p->use_nwal =1; \r
+ p->nwalInstanceHandle = netapi_return_nwal_instance_handle(n); \r
+ }\r
+ else p->use_nwal=0;\r
+\r
+ /* save name */ \r
+ strncpy(p->name,name,\r
+ strlen(name)<PKTIO_MAX_NAME ?\r
+ strlen(name):PKTIO_MAX_NAME); \r
+\r
+ /* add name, qnum to global name list */\r
+ if ((strcmp(name,NETCP_RX)) && (strcmp(name,NETCP_TX)) &&\r
+ (p_cfg->flags1 & PKTIO_GLOBAL) )\r
+ {\r
+ //todo: make sure this succeeds..\r
+ r=netapi_add_global_pktio(n, name, &p->qInfo);\r
+ }\r
+ ((NETAPI_HANDLE_T *)n )->n_pktios+=1;\r
+ return p;\r
+}\r
+\r
+\r
+/***********************************************************/\r
+/************** open an existing channel. *****************/\r
+/***********************************************************/\r
+PKTIO_HANDLE_T * pktio_open(NETAPI_T n, char *name,\r
+ PKTIO_CB cb, PKTIO_CFG_T * p_cfg, int * err)\r
+{\r
+int r=0;\r
+PKTIO_HANDLE_T *p, *p2;\r
+uint8_t isAllocated;\r
+*err=0;\r
+Qmss_Queue *p_qnum;\r
+\r
+if ((!p_cfg)||(!name)) {*err=NETAPI_ERR_BAD_INPUT; return NULL;}\r
+\r
+/* get a free channel handle */\r
+p=pktiop_get_free_channel_slot(n);\r
+if (!p) {*err = PKTIO_NOMEM; return (p); }\r
+((NETAPI_HANDLE_T *)n)->n_pktios+=1;\r
+\r
+p->inuse= PKTIO_INUSE;\r
+p->back = n;\r
+p->cb = cb;\r
+p->max_n = p_cfg->max_n;\r
+memcpy((char *)&p->cfg, (char*) p_cfg, sizeof(PKTIO_CFG_T));\r
+\r
+/* special handling of NETCP_RX, NETCP_TX */\r
+if( (!strcmp(name, NETCP_RX)) || (!strcmp(name,NETCP_TX)) )\r
+{\r
+ /* these have already been opened internally, so don't search in global list */\r
+ p->use_nwal = 2;\r
+ p->q = 0; \r
+ p->nwalInstanceHandle = netapi_return_nwal_instance_handle(n); \r
+}\r
+else\r
+{\r
+ /* find queue in global list */\r
+ p_qnum = netapi_find_global_pktio(n, name);\r
+ if (!p_qnum ) \r
+ {\r
+ printf(">pktio_open: can't find %s\n",name);\r
+ p->inuse=0;\r
+ *err= NETAPI_ERR_NOTFOUND; ///queue lld error\r
+ return NULL;\r
+ }\r
+\r
+ /* open a general queue (for now). use qnum that was just found */\r
+ p->q = Qmss_queueOpen(Qmss_QueueType_GENERAL_PURPOSE_QUEUE,\r
+ p_qnum->qNum , &isAllocated);\r
+ if (p->q == (Qmss_QueueHnd) NULL)\r
+ {\r
+ printf(">pktio_create: queueOpen failed\n");\r
+ p->inuse=0;\r
+ *err= NETAPI_ERR_QLLD; ///queue lld error\r
+ return NULL;\r
+ }\r
+ p->qInfo = Qmss_getQueueNumber(p->q);\r
+ if (p_cfg->flags2 & PKTIO_PKT)\r
+ {\r
+ p->use_nwal =1; \r
+ p->nwalInstanceHandle = netapi_return_nwal_instance_handle(n); \r
+ } \r
+ else p->use_nwal=0;\r
+}\r
+\r
+ /* save name */\r
+ strncpy(p->name,name,\r
+ strlen(name)<PKTIO_MAX_NAME ?\r
+ strlen(name):PKTIO_MAX_NAME);\r
+\r
+\r
+\r
+return p;\r
+}\r
+\r
+/***********************************************************/\r
+/************** control the channel ****************/\r
+/***********************************************************/\r
+void pktio_control(PKTIO_HANDLE_T * p,\r
+ PKTIO_CB cb,\r
+ PKTIO_CFG_T * p_cfg,\r
+ PKTIO_CONTROL_T * p_control,\r
+ int *err)\r
+{\r
+ if (!p) { *err=1; return;}\r
+ if (cb) \r
+ {\r
+ p->cb = cb;\r
+ }\r
+ if (p_control)\r
+ {\r
+ /* todo: implement divert */\r
+ switch(p_control->op)\r
+ {\r
+ //clear the queue\r
+ case(PKTIO_CLEAR):\r
+ netapi_zapQ(p->q);\r
+ break;\r
+ case(PKTIO_DIVERT):\r
+ default:\r
+ printf(">pktio_control: pktio_control op %d not implemented\n",p_control->op);\r
+ *err= NETAPI_ERR_NOT_IMPLEMENTED;\r
+ break;\r
+ }\r
+ }\r
+ //all we configure is max_n. Can't change type of queue, rx/tx, etc\r
+ if (p_cfg)\r
+ {\r
+ p->max_n = p_cfg->max_n;\r
+ }\r
+ *err=0;\r
+ return;\r
+}\r
+\r
+/***********************************************************/\r
+/*****************close ***************************/\r
+/***********************************************************/\r
+void pktio_close(PKTIO_HANDLE_T * p, int * err)\r
+{\r
+ if(!p) { *err=1; return;}\r
+ *err=0;\r
+ Qmss_queueClose(p->q); //LLD keeps reference count\r
+ p->q=-1;\r
+ p->inuse=0;\r
+ ((NETAPI_HANDLE_T *)p->back)->n_pktios-=1;\r
+ return;\r
+}\r
+\r
+/***********************************************************/\r
+/*****************Delete***************************/\r
+/***********************************************************/\r
+void pktio_delete(PKTIO_HANDLE_T * p, int * err)\r
+{\r
+ if(!p) { *err=1; return;}\r
+ *err=0;\r
+ /* remove from name list */\r
+ netapi_del_global_pktio((NETAPI_HANDLE_T *)p->back, p->name);\r
+ if(p->use_nwal !=2)\r
+ {\r
+ Qmss_queueClose(p->q);\r
+ }\r
+ p->q=-1;\r
+ p->inuse=0;\r
+ ((NETAPI_HANDLE_T *)p->back)->n_pktios-=1;\r
+ return ;\r
+}\r
+\r
+\r
+/***********************************************************/\r
+/*****************send *************************/\r
+/***********************************************************/\r
+int pktio_send(PKTIO_HANDLE_T * p, Ti_Pkt *pkt, PKTIO_METADATA_T *m, int * err)\r
+{\r
+ nwalTxPktInfo_t * pPktInfo=m->u.tx_meta;\r
+ nwal_RetValue res;\r
+ *err=0;\r
+ if(! (p->cfg.flags1&PKTIO_W)) return 0;\r
+ if (p->use_nwal)\r
+ {\r
+ pPktInfo->pPkt = pkt;\r
+ res=nwal_send(p->nwalInstanceHandle, nwal_HANDLE_INVALID,pPktInfo);\r
+ if (res != nwal_OK) *err = NETAPI_ERR_NWAL_TX_ERR -res;\r
+ }\r
+ else\r
+ {\r
+ /* tod: meta data for non netcp xfers */\r
+ /* process meta data */\r
+ Qmss_queuePushDesc (p->q, (void*)pkt);\r
+ }\r
+ return 1;\r
+}\r
+\r
+/***********************************************************/\r
+/*******************send multiple**************************/\r
+/***********************************************************/\r
+int pktio_sendMulti(PKTIO_HANDLE_T * p, Ti_Pkt * pkt[], PKTIO_METADATA_T * m[], int np, int* err)\r
+{\r
+ int r=0;\r
+ *err=0;\r
+ if(! p->cfg.flags1&PKTIO_W) return 0;\r
+ if (p->use_nwal)\r
+ {\r
+ for(r=0;r<np;r++)\r
+ {\r
+ nwalTxPktInfo_t *pPktInfo= m[r]->u.tx_meta;\r
+ nwal_RetValue res;\r
+ pPktInfo->pPkt = pkt[r];\r
+ res=nwal_send(p->nwalInstanceHandle,nwal_HANDLE_INVALID,pPktInfo);\r
+ if (res != nwal_OK) *err = NETAPI_ERR_NWAL_TX_ERR -res;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ for(r=0;r<np;r++)\r
+ {\r
+ /* process meta data */\r
+ Qmss_queuePushDesc(p->q, (void*) pkt[r]);\r
+ }\r
+ } \r
+ return r;\r
+}\r
+\r
+/***********************************************************/\r
+/******************* polling **********************/\r
+/***********************************************************/\r
+\r
+/* poll a particular channel */\r
+int pktio_poll(PKTIO_HANDLE_T * p, PKTIO_POLL_T * p_poll_cfg, int * err)\r
+{\r
+int r=0;\r
+int n;\r
+Ti_Pkt * temp;\r
+Ti_Pkt * pkt_list[PKTIO_MAX_RECV];\r
+PKTIO_METADATA_T meta_s[PKTIO_MAX_RECV];\r
+uint64_t ts= netapi_getTimestamp(); //get_ts\r
+\r
+ if(! p->cfg.flags1&PKTIO_R) return 0;\r
+\r
+ /** poll the netcp default RX queue we squirt out below */\r
+ if (p->use_nwal==2)\r
+ {\r
+ /* Poll for common L2/L3 packets */\r
+ nwal_pollPkt(p->nwalInstanceHandle,\r
+ nwal_POLL_DEFAULT_GLOB_PKT_Q,\r
+ (uint32_t) p,\r
+ p->max_n,\r
+ QMSS_PARAM_NOT_SPECIFIED,\r
+ (void*) NULL);\r
+ }\r
+ /** poll a netcp RX queue. we squirt out below */\r
+ else if (p->use_nwal==1)\r
+ {\r
+ /* Poll an additional NETCP RX queue */\r
+ nwal_pollPkt(p->nwalInstanceHandle,\r
+ nwal_POLL_APP_MANAGED_PKT_Q,\r
+ (uint32_t) p,\r
+ p->max_n,\r
+ p->q,\r
+ (void *) NULL);\r
+ }\r
+ /* poll an IPC queue */\r
+ else \r
+ {\r
+ *err=0;\r
+ n= (p->max_n< PKTIO_MAX_RECV) ? p->max_n : PKTIO_MAX_RECV;\r
+ for(r=0;r<n;r++)\r
+ {\r
+ temp=(Cppi_HostDesc*)QMSS_DESC_PTR(Qmss_queuePop(p->q));\r
+ if(!temp) break;\r
+ /* process meta data */\r
+ pkt_list[r]= temp;\r
+ meta_s[r].flags1=0x1;\r
+ } \r
+ if (r) p->cb((struct PKTIO_HANDLE_tag *)p, pkt_list, &meta_s[0], r, ts);\r
+ }\r
+ return r;\r
+}\r
+\r
+/***********************************************************/\r
+/** poll all channels attached to this handle */\r
+/***********************************************************/\r
+int pktio_pollAll(NETAPI_T handle, PKTIO_POLL_T * p_poll_cfg, int *err)\r
+{\r
+int i=0;\r
+int r=0;\r
+int err2;\r
+int cnt=0;\r
+PKTIO_HANDLE_T *pp =( PKTIO_HANDLE_T *) netapi_get_pktio_list(handle);\r
+ \r
+*err=0;\r
+for(i=0;i<NETAPI_MAX_PKTIO && cnt < ((NETAPI_HANDLE_T *)handle)->n_pktios;i++,pp+=1)\r
+{\r
+ if (pp->inuse != PKTIO_INUSE) continue;\r
+ if(!(pp->cfg.flags1&PKTIO_R)) continue;\r
+ r+=pktio_poll(pp, p_poll_cfg, &err2); cnt+=1;\r
+ if (err2) { *err = err2; break;}\r
+}\r
+return r;\r
+\r
+}\r
+\r
+/***** this is the callback we registered with NWAL for pkt reception *****/\r
+/* appcookie -> pktio handle */\r
+void netapi_NWALRxPktCallback (uint32_t appCookie,\r
+ uint16_t numPkts,\r
+ nwalRxPktInfo_t* pPktInfo,\r
+ uint64_t timestamp,\r
+ nwal_Bool_t* pFreePkt)\r
+{\r
+PKTIO_HANDLE_T * p = (PKTIO_HANDLE_T *) appCookie;\r
+int r=0;\r
+int n;\r
+Ti_Pkt * pkt_list[PKTIO_MAX_RECV];\r
+PKTIO_METADATA_T meta_s[PKTIO_MAX_RECV];\r
+ for(r=0;r<numPkts;r++)\r
+ {\r
+ pkt_list[r] = pPktInfo[r].pPkt;\r
+ meta_s[r].flags1 = PKTIO_META_RX;\r
+ meta_s[r].u.rx_meta = &pPktInfo[r];\r
+ }\r
+ if (r) p->cb((struct PKTIO_HANDLE_tag *)p, pkt_list, &meta_s[0], r, timestamp);\r
+\r
+}\r
+ \r
+\r
index fd0f55df2c8728cfe34fce78385c179011a99ca0..1e90059a6ea62b2b8f2ddd46c8bb96f1f57db770 100755 (executable)
\r
NETCP_CFG_IP_T ip_rule0;\r
NETCP_CFG_IP_T ip_rule1;\r
+\r
+PKTIO_CONTROL_T zap_channel_control={PKTIO_CLEAR, NULL};\r
+\r
/*************************END NETAPI OBJECTS***********************/\r
\r
#define START_SRC_IP 0x0a00000a\r
int err;\r
unsigned long long et;\r
printf("TIMER CALLBACK @ %lld %d timers\n", currentTime, n_fired);\r
+printf("netcp_tx_handle check (tc) %x\n", netcp_tx_chan->back);\r
tx = netapi_TimerGetFirst(fired_list);\r
for(i=0;i<n_fired;i++)\r
{\r
uint32_t numPacketsinGarbage;\r
\r
printf("stats @ %lld\n", netapi_getTimestamp());\r
+printf("netcp_tx_handle check %x\n", netcp_tx_chan->back);\r
if(pPaStats)\r
{\r
printf("C1 number of packets: %d\n", pPaStats->classify1.nPackets);\r
printf("done: itx=%d rx=%d tx=%d bad=%d slow=%d\n",stats.itx, stats.rx, stats.tx, stats.n_bad, stats.n_new);\r
our_stats_cb(netapi_handle, NULL);\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
+//close pktio channels we opened\r
+pktio_close(netcp_tx_chan ,&err);\r
+pktio_close(netcp_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
+//delete pktio channels we created\r
+pktio_delete(our_chan, &err);\r
+\r
netapi_shutdown(netapi_handle);\r
\r
}\r