]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/netapi.git/blob - ti/runtime/netapi/netcp_cfg.h
Fixed issue with running and gracefully terminating net_test_router application.
[keystone-rtos/netapi.git] / ti / runtime / netapi / netcp_cfg.h
1 /******************************************************************************
2  * FILE PURPOSE:  netapi NETCP configuration API header file
3  ******************************************************************************
4  * FILE NAME:   netcp_cfg.h
5  *
6  * DESCRIPTION:netapi NETCP configuration API header  file for user space transport library
7  *
8  * REVISION HISTORY:
9  *
10  *  Copyright (c) Texas Instruments Incorporated 2013
11  *
12  *  Redistribution and use in source and binary forms, with or without
13  *  modification, are permitted provided that the following conditions
14  *  are met:
15  *
16  *    Redistributions of source code must retain the above copyright
17  *    notice, this list of conditions and the following disclaimer.
18  *
19  *    Redistributions in binary form must reproduce the above copyright
20  *    notice, this list of conditions and the following disclaimer in the
21  *    documentation and/or other materials provided with the
22  *    distribution.
23  *
24  *    Neither the name of Texas Instruments Incorporated nor the names of
25  *    its contributors may be used to endorse or promote products derived
26  *    from this software without specific prior written permission.
27  *
28  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  *
40  */
41 /* ============================================================= */
43 /**
44  *   @file netcp_cfg.h
45  *   @brief Netapi NETCP configuration API header file for user space transport library
46  */
50 #ifndef __NETCP_CFG__H
51 #define __NETCP_CFG__H
53 #include "netapi.h"
55 /**
56  *  @ingroup cfg_structures
57  *  @brief NETCP Flow ID configuaration informaation
58  *  @details A flow defines a set of free queues (pktlib heap) for hardware to use to get
59  *          free packet descriptor(s) and buffer(s) to use when receiving a packet. CPPI flow ID for
60  *          default case, use NETCP_DEFAULT_FLOW
61  */
62 typedef struct NETCP_CFG_FLOW_Tag
63 {
64     int flowid;         /**< flow id*/
65     int dma_engine;     /**< dma engine (QMSS, NETCP)*/
66 } NETCP_CFG_FLOW_T;
69 /**
70  *  @ingroup cfg_structures
71  *  @brief NETAPI configuration information
72  *
73  *  @details The parameters in this structure are used to configure NETAPI.
74  */
75 typedef struct NETAPI_CFG_Tag
76 {
77  int def_mem_size;                  /**<  Bytes of CMA memory we have allocated */
78  int def_flow_pkt_rx_offset;        /**<  Offset in pkt buffer for hw to start RX */
79  int def_max_descriptors;           /**<  Number of descriptors in system  (must be power of 2), 2^14 max */
80  int def_tot_descriptors_for_us;    /**<  Number of descriptors to create in our region (must be power of 2)*/
81  int def_heap_n_descriptors;        /**<  Number of descriptor plus buffers in default heap*/
82  int def_heap_n_zdescriptors;       /**<  Number of zero len descriptors in defaut heap*/
83  int def_heap_buf_size;             /**<  Size of buffers in default heap, max amount of area for packet data */
84  int def_heap_tailroom_size;        /**<  Size of tailroom in reserve */
85  int def_heap_extra_size;           /**<  Size of extra space at end of buffer */ 
86 }  NETAPI_CFG_T;
88 /* @note:
89    each buffer will be allocated:  def_heap_buf_size+def_heap_extra_size bytes
90    each descriptor attached to these buffers will have rigBufferLen of:
91       def_heap_buf_size.
92    for default RX flow,  for rx packet, the bufptr  will be def_flow_pkt_rx_offset.
93    for detault RX flow,  threshold (ie max # of bytes in buffer) will be:
94        def_heap_buf_size - def_heap_tailroom_size-def_flow_pkt_rx_offset
97  RX Packet from NetCP
99 Headroom [Application]     Packet [HW]                Tailroom [Application]    Extra Space [Application]
100 <-----------------------><--------------------------><------------------------><----------------------->
102 Cppi_HostDesc->origBufferLen
103 <----------------------------------------------------------------------------->
104 Cppi_HostDesc->origBuffPtr
106 \/
107 |------------def_heap_buf_size-------------------------------------------------|--def_heap_extra_size--|
108 | def_flow_pkt_rx_offset| max Cppi_HostDesc->buffLen | def_heap_tailroom_size  |   Extra Size          |
109                         ^
110                         |
111                      Cppi_HostDesc->buffPtr
112 */
115 /**
116  * @ingroup cfg_constants
117  * @brief  This defines the handle to a NETCP configured Flow. A Flow is a set of pktlib heaps that h/w can use to obtain free packets.
118  */
119 typedef void* NETCP_CFG_FLOW_HANDLE_T;
121 /**
122  * @ingroup cfg_constants
123  * @def NETCP_DEFAULT_FLOW
124  * @brief This defines the default FLOW for NETCP to use.
125  * The default flow uses the default pktlib heap created by netapi_init; i.e.
126  * NETCP will allocate descriptors and buffers for received packets from this heap.
127  */
128 #define NETCP_DEFAULT_FLOW  (NETCP_CFG_FLOW_HANDLE_T*) NULL
131 /**
132  * @ingroup cfg_constants
133  * @brief  Handle to a NETCP route.
134  * @details Application to use this handle to identify a NETCP route. A NETCP route defines the
135  *          pktio channel for packets received by NETCP
136  *    and the flow to use.
137  */
138 typedef void* NETCP_CFG_ROUTE_HANDLE_T;
140 /**
141  * @def NETCP_DEFAULT_ROUTE
142  * This defines the NETCP default route.  This route has NETCP send received packets to the default NETCP 
143  * pktio channel using descriptors and buffers from the default flow. The default route is created by netapi_init
144  */
145 #define NETCP_DEFAULT_ROUTE (NETCP_CFG_ROUTE_HANDLE_T*) NULL
148 /**
149  *  @ingroup cfg_structures
150  *  @brief NETCP application defined route information.
151  *  @details This structure is used to define a packet receive route.  A route consists of a 
152  *           flow where to get free descriptors and buffers to hold the packet, and a destination 
153  *           queue where to place the packet.
154  *
155  */
156 typedef struct NETCP_CFG_ROUTE_Tag
158    NETCP_CFG_FLOW_T* p_flow;   /**< NULL or NETCP_DEFAULT_FLOW for default flow, @ref NETCP_CFG_FLOW_T */
159    PKTIO_HANDLE_T*   p_dest_q;   /**<NULL for default destination queue */
160 } NETCP_CFG_ROUTE_T;
162 /**
163  * @ingroup cfg_constants
164  * @def NETCP_CFG_ACTION_DISCARD
165  *      This defines the NETCP action to discard packet.
166  */
167 #define NETCP_CFG_ACTION_DISCARD NWAL_MATCH_ACTION_DISCARD
168 /**
169  * @ingroup cfg_constants
170  * @def  NETCP_CFG_ACTION_CONTINUE
171  *      This defines the NETCP action to pass packet ono the next classifier
172  */
173 #define NETCP_CFG_ACTION_CONTINUE NWAL_MATCH_ACTION_CONTINUE_NEXT_ROUTE
174 /**
175  * @ingroup cfg_constants
176  * @def NETCP_CFG_ACTION_TO_SW
177  *      This defines the NETCP action to pass packet to User space application
178  */
179 #define NETCP_CFG_ACTION_TO_SW    NWAL_MATCH_ACTION_HOST
181 /**
182  * @ingroup cfg_constants
183  * @def NETCP_CFG_ALL_EXCEPTIONS
184  *      This defines NETCP configuration for all Exepction Packets.
185  */
186 #define NETCP_CFG_ALL_EXCEPTIONS 0xff
191 /**
192  * @ingroup cfg_constants
193  * @brief  Handle to NETCP VLAN configuration (FUTURE).
194  * @details Application to use this handle to identify a VLAN configuration.
195  */
196 typedef void * NETCP_CFG_VLAN_T;
198 /**
199  * @ingroup cfg_constants
200  * @brief  AppID for packets matching a  MAC interface rule
201  */
202 typedef uint32_t NETCP_CFG_MACIF_T;
204 /**
205  * @ingroup cfg_constants
206  * @brief AppID for packets matching an IP interface rule
207  */
208 typedef uint32_t NETCP_CFG_IP_T;
210 /**
211  * @ingroup cfg_constants
212  * @brief This define is used to identify the application id associated with a created SA (IPSEC security association) rule
213  */
214 typedef uint32_t NETCP_CFG_SA_T;
217 /**
218  * @ingroup cfg_constants
219  * @brief AppId for packets matching an NETCP IPSEC policy rule
220  */
221 typedef uint32_t NETCP_CFG_IPSEC_POLICY_T;
225 /**
226  * @ingroup cfg_constants
227  * @brief  AppID for packets being classified as  type exception.
228  */
229 typedef uint32_t NETCP_CFG_EXCEPTION_PKT_T;
231 /**
232  * @ingroup cfg_constants
233  *@brief This define is to be used in AddIp, AddClassifier, addSA, etc. to indicate that the rule can be bound to any MAC address.
234  */
235 #define NETCP_CFG_NO_INTERFACE 0xff
239 /**
240  * @note  APPIDs are present in RX packet meta data and tell "how far" the packet got
241  * through the classification rules of NETCP. 
242  * APPID is 32 bits:
243  * bits 31-24 = NETAPI_NETCP_MATCH_STAGE
244  * bits 23-8  = NETAPI_NETCP_MATCH_ID identifier 
245  * bits  7-0  = NETAPI_NETCP_MATCH_LOGICAL_MAC_IFACE logical mac interface
246 */
248 #define NETAPI_NETCP_MATCH_LOGICAL_MAC_IFACE_SHIFT 0 
249 #define NETAPI_NETCP_MATCH_LOGICAL_MAC_IFACE_MASK 0xFF
251 #define NETAPI_NETCP_MATCH_ID_SHIFT 8 
252 #define NETAPI_NETCP_MATCH_ID_MASK 0xFFFF
254 #define NETAPI_NETCP_MATCH_STAGE_SHIFT 24
255 #define NETAPI_NETCP_MATCH_STAGE_MASK 0xFF
258 /**
259  * @brief Helper function to get match stage associated with application ID.
260  */
261 #define netapi_cfgGetMatchStage(appid)  (((appid) >> NETAPI_NETCP_MATCH_STAGE_SHIFT) & NETAPI_NETCP_MATCH_STAGE_MASK)
263 /**
264  * @brief Helper function to get match id associated with application ID.
265  */
266 #define netapi_cfgGetMatchId(appid) (((appid) >> NETAPI_NETCP_MATCH_ID_SHIFT) & NETAPI_NETCP_MATCH_ID_MASK)
268 /**
269  * @brief Helper function to get logical match interface associated with application ID.
270  */
271 #define netapi_cfgGetMatchLogicalMacIface(appid) (((appid) >> NETAPI_NETCP_MATCH_LOGICAL_MAC_IFACE_SHIFT) & \
272                                                     NETAPI_NETCP_MATCH_LOGICAL_MAC_IFACE_MASK)
275 /**
276  * @ingroup cfg_constants
277  * @def NETAPI_NETCP_MATCH_GENERIC_MAC
278  *      This define is used for an APPID that indicates that a packet matched a MAC entry.
279  *      Logical MAC interface location:
280  *          Refer to NETAPI_NETCP_MATCH_LOGICAL_MAC_IFACE_SHIFT and 
281  *          NETAPI_NETCP_MATCH_LOGICAL_MAC_IFACE_MASK.
282  *      Packet did not match any other rule.
283  */
284 #define NETAPI_NETCP_MATCH_GENERIC_MAC  0x10000000
286 /**
287  * @ingroup cfg_constants
288  * @def NETAPI_NETCP_MATCH_GENERIC_IP
289  *      This define is used for an APPID that indicates that a packet matched a MAC entry.
290  *      Logical MAC interface location:
291  *          Refer to NETAPI_NETCP_MATCH_LOGICAL_MAC_IFACE_SHIFT and 
292  *          NETAPI_NETCP_MATCH_LOGICAL_MAC_IFACE_MASK.
293  *       IP rule number for this interface location:
294  *          Refer to NETAPI_NETCP_MATCH_ID_SHIFT and 
295  *          NETAPI_NETCP_MATCH_ID_MASK.
296  *      Packet also matched a generic IP rule attached to that interface.
297  *      Packet did not match any other rule.
298  */
299 #define NETAPI_NETCP_MATCH_GENERIC_IP   0x20000000
301 /**
302  * @ingroup cfg_constants
303  * @def NETAPI_NETCP_MATCH_CLASS
304  *      This define is used for an APPID that indicates that a packet matched a MAC entry.
305  *      Logical MAC interface location:
306  *          Refer to NETAPI_NETCP_MATCH_LOGICAL_MAC_IFACE_SHIFT and 
307  *          NETAPI_NETCP_MATCH_LOGICAL_MAC_IFACE_MASK.
308  *      Classifer ID location:
309  *          Refer to NETAPI_NETCP_MATCH_ID_SHIFT and 
310  *          NETAPI_NETCP_MATCH_ID_MASK.
311  *      Packet also matched a generic IP rule attached to 
312  *      that interface OR a general IP rule added as part of the classifier or it matched a combination
313  *      of ISPEC SA rule and a policy check.  In addition, packet matched a L4 port rule that was added 
314  *      as part of a classifer. Packet did not match any other rule.
315  */
316 #define NETAPI_NETCP_MATCH_CLASS        0x80000000
318 /**
319  * @ingroup cfg_constants
320  * @def NETAPI_NETCP_MATCH_CLASS_L3
321  *      This define is used for an APPID that indicates that a  packet matched a MAC entry.
322  *      Logical MAC interface location:
323  *          Refer to NETAPI_NETCP_MATCH_LOGICAL_MAC_IFACE_SHIFT and 
324  *          NETAPI_NETCP_MATCH_LOGICAL_MAC_IFACE_MASK.
325  *      Packet also  matched a general IP rule added as part 
326  *      of a classifier.  But it not match a L4 port or any other rule. 
327  *      We cannot determine what classifer partially matched so Bytes 3-2 are not applicable
328  */
329 #define NETAPI_NETCP_MATCH_CLASS_L3     0x40000000
331 /**
332  * @ingroup cfg_constants
333  * @def NETAPI_NETCP_MATCH_IPSEC
334  *      This define is used for an APPID that indicates that a packet matched a MAC entry.
335  *      Logical MAC interface location:
336  *          Refer to NETAPI_NETCP_MATCH_LOGICAL_MAC_IFACE_SHIFT and 
337  *          NETAPI_NETCP_MATCH_LOGICAL_MAC_IFACE_MASK.
338  *      SA ID location:
339  *          Refer to NETAPI_NETCP_MATCH_ID_SHIFT and 
340  *          NETAPI_NETCP_MATCH_ID_MASK.
341  *      Packet also matched an IPSEC SA  rule (matched proto, destination ip and SPI).  
342  *      Packet did not match any other rule (so may have failed a policy check)
343  */
344 #define NETAPI_NETCP_MATCH_IPSEC        0x01000000  
347 /**
348  * @ingroup cfg_constants
349  * @def NETAPI_NETCP_MATCH_IPSEC_POLICY
350  *      This define is used for an APPID that indicates that a packet matched a MAC entry
351  *      Logical MAC interface location:
352  *          Refer to NETAPI_NETCP_MATCH_LOGICAL_MAC_IFACE_SHIFT and 
353  *          NETAPI_NETCP_MATCH_LOGICAL_MAC_IFACE_MASK.
354  *      Packet also matched an IPSEC SA rule (matched proto, 
355  *      dest ip and SPI).  Packet also matched a POLICY RULE (this is a check of the inner IP).
356  *      IPSEC RX Policy ID location:
357  *          Refer to NETAPI_NETCP_MATCH_ID_SHIFT and 
358  *          NETAPI_NETCP_MATCH_ID_MASK.
359  *      Packet did not match any other rule 
360  */
361 #define NETAPI_NETCP_MATCH_IPSEC_POLICY 0x02000000  //lower byte==interface, Or' in SA id (16 bits)
363 /**
364  * @ingroup cfg_constants
365  * @def NETAPI_NETCP_CFG_MATCH_EXCEPTION
366  *      This define is used for an APPID that indicates that a packet is of type exception. 
367  *      Actual exception id is in byte 0 of APPID.
368  */
369 #define NETAPI_NETCP_CFG_MATCH_EXCEPTION     0x08000000
373 /**
374  *  @ingroup cfg_structures
375  *  @brief NETCP flow configuration information.
376  *  @details This structure is used to define key parameters for the receive flow to be created.
377  *           These include the flow index to use (or can be left un-specified), the dma_index
378  *           (specifying out of which CPPI DMA engine the flow should be allocated),
379  *           the receive offset (the byte offset into each buffer where received data should be placed),
380  *           and the drop policy for the DMA channel to use if there is no free buffer available (drop or block)
381  *
382  */
383 typedef struct NETCP_CFG_FLOW_CONFIG_Tag
385    int              flow_index;     /**< flow index to use or NETAPI_NETCP_FLOW_INDEX_ANY */
386 /**
387  * @def NETAPI_NETCP_FLOW_INDEX_ANY
388  * @ingroup cfg_constants
389  *      This define is used to let NETAPI pick the flow index to use(for flow_index field)
390  */
391 #define NETAPI_NETCP_FLOW_INDEX_ANY  CPPI_PARAM_NOT_SPECIFIED
393    int              dma_index;      /**< allocate flow out of which DMA */
394 /**
395  * @def NETAPI_DMA_INFRASTRUCTURE
396  * @ingroup cfg_constants
397  *      This define is used specify a flow in the QMSS CPPI DMA (for dma_index field)
398  */
399 #define NETAPI_DMA_INFRASTRUCTURE 0
400 /**
401  * @def NETAPI_DMA_NETCP
402  * @ingroup cfg_constants
403  *      This define us usee specify a flow in the NETCP CPPI DMA (for dma_index field)
404  */
405 #define NETAPI_DMA_NETCP 1
407    int              recv_offset;    /**< start of packet offset */
409    int              block;          /**< TRUE => DMA will wait for free descriptor if heap(s) are empty.
410                                          FALSE => DMA will discard */
411 /**
412  * @def NETAPI_FLOW_DROP
413  * @ingroup cfg_constants
414  *      This define is used to indicate that the flow should institute a Block policy.
415  *      This means that the DMA should wait for a free descriptor/buffer to come available if
416  *      the free poll is empty (for the block field)
417  */
418 #define NETAPI_FLOW_BLOCK 1
419 /**
420  * @def NETAPI_FLOW_DROP
421  * @ingroup cfg_constants
422  *      This define us used to indicate that the flow should institute a Drop policy.
423  *      This means that the DMA should NOT wait for a free descriptor/buffer to come available
424  *      if the free poll is empty. The transfer will be aborted and the data will dropped (for block field)
425  */
426 #define NETAPI_FLOW_DROP 0
428    PKTIO_HANDLE_T * p_dest_q;       /**<destination queue for this flow (may be overwrritten by source DMA) */
429 } NETCP_CFG_FLOW_CONFIG_T;
436 /**
437  *  @ingroup cfg_functions
438  *  @brief netapi_netcpCfgAddFlow   API to add a flow
439  * 
440  *  @details This api is used to add a flow
441  *  @param[in]  h    NETAPI instance handle, @ref NETAPI_T
442  *  @param[in]  n    number of Pktlib_HeapHandle
443  *  @param[in]  handles[]   Handles to Pktlib_HeapHandle
444  *  @param[in]  sizes[]     must be <= heap corresponding heap size-recv_offset-any desired tail room
445  *  @param[in]  p_cfg   @ref NETCP_CFG_FLOW_CONFIG_T
446  *  @param[out] err     pointer to error return
447  *  @retval     NETCP flow handle, @ref NETCP_CFG_FLOW_HANDLE_T
448  *  @pre       @ref netapi_init
449  */
450 NETCP_CFG_FLOW_HANDLE_T netapi_netcpCfgAddFlow(NETAPI_T h,
451                                             int n, 
452                                             Pktlib_HeapHandle handles[],
453                                             int sizes[],
454                                             NETCP_CFG_FLOW_CONFIG_T * p_cfg,
455                                             int * err );
457 /**
458  *  @ingroup cfg_functions
459  *  @brief netapi_netcpCfgDelFlow   API to delete a flow
460  * 
461  *  @details This api is used to delete a flow.
462  *  @param[in]  h    NETAPI instance handle, @ref NETAPI_T
463  *  @param[in]  p    handle to NETCP  flow
464  *  @param[out] err     pointer to error return
465  *  @retval     none
466  *  @pre       @ref netapi_init, netapi_netcpCfgAddFlow
467  */
468 void netapi_netcpCfgDelFlow(NETAPI_T h ,
469                                             NETCP_CFG_FLOW_HANDLE_T p ,
470                                             int * err);
472 /**
473  *  @ingroup cfg_functions
474  *  @brief  API attaches an IP address and qualifier to a MAC interface
475  * 
476  *  @details This api is used to add an IP address to a MAC interface along
477  *            with optional IP qualifier. A route, @ref NETCP_CFG_ROUTE_HANDLE_T,or NULL for default 
478  *            may be specified to indicate where to send packets matching the MAC interface MAC address, the
479  *            supplied IP address and any qualifier.  This API adds a rule to the NETCP level 1 lookup tables.
480  *            Packets arriving that match this rule are identified in meta data with Appid=  NETAPI_NETCP_MATCH_GENERIC_IP
481  *            Note: An IP address must be attached to enable NETCP receive Checksum offload feature
482  *  @param[in]  h    NETAPI instance handle, @ref NETAPI_T
483  *  @param[in]  iface_no    interface number (0,1,..)
484  *  @param[in]  ipType  type of IP address (V4 for V6)
485  *  @param[in]  ip_addr      ip_address
486  *  @param[in]  ip_qualifiers   ip_qualifiers (all 0 for no qualifiers). This can be used to apply special handling for
487  *                  diffserv category for example.
488  *  @param[in]  route       handle of a created route or NULL to use internal default route, @ref NETCP_CFG_ROUTE_HANDLE_T
489  *  @param[in]  user_data     Optional: pointer to user provided data associated with IP
490  *  @param[out] err     pointer to error return
491  *  @retval     returned AppID for attached rule. This is returned in RX meta data for packets matching this rule and no other, @ref NETCP_CFG_IP_T
492  *  @pre       @ref netapi_init
493  */
494 NETCP_CFG_IP_T  netapi_netcpCfgAddIp(NETAPI_T                   h,
495                                      int                        iface_no,
496                                      nwal_IpType                ipType,
497                                      nwalIpAddr_t*              ip_addr,
498                                      nwalIpOpt_t*               ip_qualifiers,
499                                      NETCP_CFG_ROUTE_HANDLE_T   route,
500                                      void*                      user_data,
501                                      int*                       err);
503 /**
504  *  @ingroup cfg_functions
505  *  @brief netapi_netcpCfgDelIp   API to delete IP interface
506  * 
507  *  @details This api is used to delete an IP interface
508  *  @param[in]  h    NETAPI instance handle, @ref NETAPI_T
509  *  @param[in]  iface_no    interface number (0,1,..)
510  *  @param[in]  ipType  type of IP address (V4 for V6)
511  *  @param[in]  ip_addr      ip_address
512  *  @param[in]  ip_qualifiers   ip_qualifiers (all 0 for no qualifiers). This can be used to apply special handling for
513  *                  diffserv category for example.
514  *  @param[in]  ip_rule_id      @ref NETCP_CFG_IP_T
515  *  @param[out] err     pointer to error return
516  *  @retval     returned AppID for attached rule. This is returned in RX meta data for packets matching this rule and no other, @ref NETCP_CFG_IP_T
517  *  @pre       @ref netapi_init , @ref netapi_netcpCfgAddIp
518  */
519 void netapi_netcpCfgDelIp(NETAPI_T          h, 
520                           int               iface_no,
521                           nwal_IpType       ipType,
522                           nwalIpAddr_t*     ip_addr,
523                           nwalIpOpt_t*      ip_qualifiers, 
524                           NETCP_CFG_IP_T    ip_rule_id,
525                           int*              err);
527 /**
528  *  @ingroup cfg_functions
529  *  @brief netapi_netcpCfgCreateMacInterface  API to insert a MAC interface rule in the NETCP hardware
530  *  lookup engines.
531  * 
532  *  @details This api is used to insert a MAC interface in the NETCP hardware lookup engines.
533  *      Once it is created, the MAC interface can be used to receive packets. The API
534  *      adds a rule to the NETCP 1st level lookup tables to route all packets with destination
535  *      MAC matching supplied argument and not matching any other lookup entry (see @ref netapi_netcpCfgAddIp) to
536  *      the supplied route, @ref NETCP_CFG_ROUTE_T, (or default route).
537  *      Packets arriving that match this rule are identified in meta data with Appid=  NETAPI_NETCP_MATCH_GENERIC_MAC
538  *      Note: The internal SOC switch (if operating in full swithc mode) may need to  be "taught" that this mac
539  *      address is present by transmitting a packet with destination mac = this interface mac address.
540  *  @param[in]  h   NETAPI instance handle, @ref NETAPI_T
541  *  @param[in]  p_mac   pointer to 6 byte MAC address for interface
542  *  @param[in]  iface_no    interface number (0,1,..) 
543  *  @param[in]  switch_port     (0 don't care, 1 switch port 1, 1 switch port 2) [only 0 supported currenly] 
544  *  @param[in]  route   handle of a created route or NULL to use internal default route, @ref NETCP_CFG_ROUTE_HANDLE_T
545  *  @param[in]  vlan    [future[ vlan configuration . Set to NULL, @ref NETCP_CFG_VLAN_T
546  *  @param[in]  state   [future] interface state (0=down, 1= up)
547  *  @param[out] err     pointer to error return
548  *  @retval     returns AppID for interface (this is returned in meta data for received packets matching this rule an no others, @ref NETCP_CFG_MACIF_T
549  *  @pre       @ref netapi_init 
550  */
551 NETCP_CFG_MACIF_T  netapi_netcpCfgCreateMacInterface(NETAPI_T                   h,
552                                                      uint8_t*                   p_mac, 
553                                                      int                        iface_no,
554                                                      int                        switch_port,
555                                                      NETCP_CFG_ROUTE_HANDLE_T   route,
556                                                      NETCP_CFG_VLAN_T           vlan,
557                                                      int                        state,
558                                                      int *                      err);
560 /**
561  *  @ingroup cfg_functions
562  *  @brief netapi_netcpCfgDelMac   API to delete MAC  interface
563  * 
564  *  @details This api is used to delete a MAC interface
565  *  @param[in]  h    NETAPI instance handle, @ref NETAPI_T
566  *  @param[in]  iface_no    interface number (0,1,..)
567  *  @param[out] err     pointer to error return
568  *  @retval     returned AppID for attached rule. This is returned in RX meta data for packets matching this rule and no other, @ref NETCP_CFG_IP_T
569  *  @pre       @ref netapi_init , @ref netapi_netcpCfgCreateMacInterface 
570  */
571 void netapi_netcpCfgDelMac(NETAPI_T     h,
572                            int          iface_no,
573                            int*         err);
576 /**
577  * @brief This defines handle to installed classifier returned by API.  Pkts matching this classifier will have meta data with this tag.
578  *  Also used to delete classifier
579  */
580 typedef uint32_t NETCP_CFG_CLASS_T;
583 /**
584  *  @ingroup cfg_structures
585  *  @brief NETAPI Class L4 Configuration
586  *
587  *  @details This structure contains Classifier L4 Configuration. In this type of classifier, the  L2 and L3 header match criteria are implied by the iface and ip entries.  L4 packet match criteria are defined by the proto and appProto fields ( L4 protocol id and ports)
588  */
589 typedef struct NETCP_CFG_CLASS_L4_Tag
591     int                 iface;      /**< Indicates which MAC interface packet should be received on*/
592     NETCP_CFG_IP_T      ip;         /**< IP rule to match: see @ref NETCP_CFG_IP_T */
593     nwal_appProtoType_t proto;   /**< L4 proto (-1 for don't care)*/
594     nwalAppProto_t      appProto;   /**< L4 Ports or equivalent */
596 } NETCP_CFG_CLASS_L4_T;
599 /**
600  *  @ingroup cfg_structures
601  *  @brief NETAPI Classifier L4 plus IPSEC policy configuration
602  *
603  *  @details This structure contains Classifier L4 plus IPSEC policy configuration. In this type of classifier, the  L2,L3 header match criteria are implied by the iface and ip_policy fields. The L4 match criteria are implied by the proto and appProto fields. 
604  */
605 //classifier L4 + policy  (L2, L3 (outer), tunnel, L3 (inner)  implied by policy
606 typedef struct NETCP_CFG_CLASS_L4_IPSEC_Tag
608     int                       iface;      /**< Indicates which MAC interface packet should be received from */
609     NETCP_CFG_IPSEC_POLICY_T  ip_policy; /**< IPSEC policy configuration. see @ref NETCP_CFG_IPSEC_POLICY_T */
610     nwal_appProtoType_t       proto;   /**< L4 proto (-1 for don't care)*/
611     nwalAppProto_t            appProto;   /**< L4 Ports or equivalent */
613 } NETCP_CFG_CLASS_L4_IPSEC_T;
617 /**
618  *  @ingroup cfg_structures
619  *  @brief NETAPI Classifier L4/L3 configuration
620  *
621  *  @details This structure contains Class L4 + L3 Classifier configuration. In this type of classifier the L2 header match criteria is implied by the iface field.  The L3 header match criteria is implied by the ipType, ip_addr and ip_qulaifier fields.  L4 match criteris is implied by the proto and appProto fields.  A failed route can be optionally included to tell NETCP what to do if the L3 portion of the classifier matches but not the L4 portion.
622  */
623 typedef struct NETCP_CFG_CLASS_L3_L4_Tag
625     int                         iface;          /**< Indicates which MAC interface packet is from */
626     nwal_IpType                 ipType;         /**< IP address type, IPV4 or IPV6 */
627     nwalIpAddr_t*               ip_addr;        /**< IP address to match */
628     nwalIpOpt_t*                ip_qualifiers;  /**< IP address qualifiers */
629     NETCP_CFG_ROUTE_HANDLE_T    p_fail_route;   /**< What to do if L3 matches but L4 fails AND L3 is a 
630                                                      new rule.(if exisitng rule, then existing fail
631                                                      route will be used). */
632     nwal_appProtoType_t         proto;          /**< L4 proto (-1 for don't care)*/
633     nwalAppProto_t              appProto;       /**< Ports or equivalent */
634 } NETCP_CFG_CLASS_L3_L4_T;
636 /**
637  *  @ingroup cfg_structures
638  *  @brief NETAPI Classifier configuration
639  *
640  *  @details This structure contains the NETAPI classifer configuration.  This is a union of the different classifier types above
641  */
642 typedef struct NETCP_CFG_CLASSIFIER_Tag
645 /**
646  * Classifer type which can be set to one of the following defines:
647  * <br>
648  *      @ref NETCP_CFG_CLASS_TYPE_L4 , @ref NETCP_CFG_CLASS_TYPE_L3_L4, _
649  */
650     int classType;
652 /**
653  * @def NETCP_CFG_CLASS_TYPE_L4
654  * @ingroup cfg_constants
655  *      This defines classifier type to be Class L4. Class L4 classifiers specifiy the L4 protocol information of the packets to matched;  the L2,L3 portions of the classifier are implied by supplied handles from the mac interface create and IP Add APIs
656  */
657 #define NETCP_CFG_CLASS_TYPE_L4  0
659 /**
660  * @def NETCP_CFG_CLASS_TYPE_L3_L4
661  * @ingroup cfg_constants
662  *      This defines classifier type to be Class L4/L3 .  Class L3_L4 classifiers specify both the IP address (L3) and the L4 protocol information of the packets to be matched.
663  */
664 #define NETCP_CFG_CLASS_TYPE_L3_L4  1
666      union
667     {
668         NETCP_CFG_CLASS_L3_L4_T     c_l3_l4;    /**< @ref NETCP_CFG_CLASS_L3_L4_T */
669         NETCP_CFG_CLASS_L4_T        c_l4;       /**< @ref NETCP_CFG_CLASS_L4_T */
670         NETCP_CFG_CLASS_L4_IPSEC_T  c_l4_ipsec; /**< @ref NETCP_CFG_CLASS_L4_IPSEC_T */
671     } u;                                        /**< union for classifier type configuration structure */
672 } NETCP_CFG_CLASSIFIER_T;
676 /**
677  *  @ingroup cfg_functions
678  *  @brief netapi_netcpCfgAddClass   API to attach a classifier rule to NETCP.
679  *      This can be used to route a particular packet flow to a specific PKTIO channel
680  * 
681  *  @details This api can be used to route a particular packet flow to a particular PktIO channel, using a specific 
682  *  pktLib heap, and/or have NetCP attach a tag (classifier id) to the incoming packet.
683  *  @param[in]  h    NETAPI instance handle, @ref NETAPI_T
684  *  @param[in]  p_class definition of the classifier
685  *  @param[in]  p_route handle to NETCP route.
686  *  @param[in]  action       what to do with packet: one of NETCP_CFG_ACTION_TO_SW, DISCARD or CONTINUE
687  *  @param[in]  user_data     Optional: pointer to user provided data associated with SA
688  *  @param[out] err     pointer to error return
689  *  @retval     returned AppID for attached rule. This is returned in RX meta data for packets matching this rule and no other, @ref NETCP_CFG_IP_T
690  *  @pre       @ref netapi_init
691  */NETCP_CFG_CLASS_T netapi_netcpCfgAddClass(NETAPI_T                   h,
692                                              NETCP_CFG_CLASSIFIER_T*    p_class,
693                                              NETCP_CFG_ROUTE_HANDLE_T   p_route,
694                                              int                        action,
695                                              void*                      user_data,
696                                              int*                       err);
700 /**
701  *  @ingroup cfg_functions
702  *  @brief netapi_netcpCfgDelClass   API to delete a preconfigured classifier
703  * 
704  *  @details This API can be used to delete a preconfigured classifier
705  *  @param[in]  h    NETAPI instance handle, @ref NETAPI_T
706  *  @param[in]  classId
707  *  @param[out] err     pointer to error return
708  *  @retval     none
709  *  @pre       @ref netapi_init, @ref netapi_netcpCfgAddClass
710  */
711 void netapi_netcpCfgDelClass(NETAPI_T           h,
712                              NETCP_CFG_CLASS_T  classId,
713                              int*               err);
716 /**
717  *  @ingroup netapi_cb_functions
718  *  @brief NETCP_CFG_STATS_CB   Callback function that is used to return statistics from NETCP
719  * 
720  *  @details The application provides a callback function that NETAPI  uses to report statistics.
721  *  The request for stats is generated from the @ref netapi_netcpCfgReqStats API.
722  *  Note: to receive this stats callback, the @ref netapi_netcpPoll function must be called
723  *  @param[in]  h   NETAPI instance handle, @ref NETAPI_T
724  *  @param[out]  pPaStats    the PA (NETCP packet accelerator subsystem) statistics block 
725  *  @retval     none 
726  *  @pre       @ref netapi_init , @ref netapi_netcpCfgReqStats, @ref netapi_netcpPoll
727  */
728 typedef void (*NETCP_CFG_STATS_CB)(NETAPI_T      h,
729                                    paSysStats_t* pPaStats);
731 /**
732  *  @ingroup cfg_functions
733  *  @brief netapi_netcpCfgReqStats   API to request statistics from NETCP
734  * 
735  *  @details This api is used to request a statistics from NETCP.  This will generate a stats request
736  *  command to NETCP. Sometime later, the statistics result will arrive and will be passed to 
737  *  the caller via the asynchronus callback @ref NETCP_CFG_STATS_CB that is registered in this call.
738  *  Note: to receive the stats callback, the @ref netapi_netcpPoll funcition must be called
739  *  @param[in]  h    NETAPI instance handle, @ref NETAPI_T
740  *  @param[in]  cb   the callback function to invoke with the resulting statistics block, @ref NETCP_CFG_STATS_CB
741  *  @param[in]  doClear     clear the stats in NETCP after the report (0=no, 1=yes) 
742  *  @param[out] err     pointer to error return
743  *  @retval     none 
744  *  @pre       @ref netapi_init 
745  */
746 void netapi_netcpCfgReqStats(NETAPI_T               h,
747                              NETCP_CFG_STATS_CB     cb,
748                              int                    doClear,
749                              int*                   err);
752 /**
753  *  @ingroup cfg_functions
754  *  @brief netapi_netcpCfgExceptions    API to configure NETCP with global rules for exception packet handling
755  *
756  *  @details This api is used to configure NETCP with global rules of how to handle exception packets specified by exception_id.
757  *  @param[in]  h    NETAPI instance handle, @ref NETAPI_T
758  *  @param[in]  exception_id id of the exception packet, refer to pa.h,.pa_EROUTE_XXX for list of exception packet id's
759  *  @param[in]  p_route handle to NETCP route.
760  *  @param[in]  action, action for NETCP to take upon classifying packet as type exception, refer to nwal. nwal_matchAction_t
761  *  @retval returns app_id, @ref NETCP_CFG_EXCEPTION_PKT_T
762  *  @pre       @ref netapi_init 
763  */
764 NETCP_CFG_EXCEPTION_PKT_T netapi_netcpCfgExceptions(NETAPI_T                    h,
765                                                     int                         exception_id ,
766                                                     nwal_matchAction_t          action,
767                                                     NETCP_CFG_ROUTE_HANDLE_T    p_route);
770 #endif