]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/netapi.git/blob - ti/runtime/netapi/netcp_cfg.h
added classifier to netcp_cfg.c
[keystone-rtos/netapi.git] / ti / runtime / netapi / netcp_cfg.h
1 /***************************************************\r
2  * File: netcp_cfg.h \r
3  * Purpose: netcp config API\r
4  **************************************************************\r
5  *@file netcp_cfg.h\r
6  * \r
7  * @brief DESCRIPTION:  netapi NETCP configuration API header  file \r
8  *          for user space transport library\r
9  * \r
10  * REVISION HISTORY:  rev 0.0.1 \r
11  *\r
12  *  Copyright (c) Texas Instruments Incorporated 2010-2011\r
13  * \r
14  *  Redistribution and use in source and binary forms, with or without \r
15  *  modification, are permitted provided that the following conditions \r
16  *  are met:\r
17  *\r
18  *    Redistributions of source code must retain the above copyright \r
19  *    notice, this list of conditions and the following disclaimer.\r
20  *\r
21  *    Redistributions in binary form must reproduce the above copyright\r
22  *    notice, this list of conditions and the following disclaimer in the \r
23  *    documentation and/or other materials provided with the   \r
24  *    distribution.\r
25  *\r
26  *    Neither the name of Texas Instruments Incorporated nor the names of\r
27  *    its contributors may be used to endorse or promote products derived\r
28  *    from this software without specific prior written permission.\r
29  *\r
30  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \r
31  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT \r
32  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
33  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT \r
34  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, \r
35  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT \r
36  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
37  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
38  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
39  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
40  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
41 \r
42  ***************************************************/\r
43 \r
44 #ifndef __NETCP_CFG__H\r
45 #define __NETCP_CFG__H\r
46 \r
47 #include "netapi.h"\r
48 #include "ti/drv/pa/pa.h"\r
49 #include "ti/runtime/pktlib/pktlib.h"\r
50 \r
51 //NETCP FLOW\r
52 typedef struct NETCP_CFG_FLOW_Tag\r
53 {\r
54         int flowid;\r
55 } NETCP_CFG_FLOW_T;\r
56 typedef void *  NETCP_CFG_FLOW_HANDLE_T;\r
57 \r
58 \r
59 //NETCP ROUTE\r
60 typedef struct NETCP_CFG_ROUTE_Tag\r
61 {\r
62    NETCP_CFG_FLOW_HANDLE_T p_flow;\r
63    PKTIO_HANDLE_T * p_dest_q;\r
64    int nextAction;\r
65 } NETCP_CFG_ROUTE_T;\r
66 typedef void * NETCP_CFG_ROUTE_HANDLE_T;\r
67 \r
68 /*--------------flow management--------*/\r
69 NETCP_CFG_FLOW_HANDLE_T netcp_cfgAddFlow(NETAPI_T ,\r
70                                             int n, \r
71                                             Pktlib_HeapHandle handles[],\r
72                                             int * err );\r
73 void netcp_cfgDelFlow(NETAPI_T , NETCP_CFG_FLOW_HANDLE_T , int * err);\r
74 \r
75 /*------------Routes------------------*/\r
76 NETCP_CFG_ROUTE_HANDLE_T netcp_cfgAddRoute(NETAPI_T ,int nh, \r
77                                                Pktlib_HeapHandle heaps[],\r
78                                                int *err );\r
79 void netcp_cfgDelRoute(NETAPI_T , NETCP_CFG_ROUTE_HANDLE_T, int *err );\r
80 \r
81 /*-----------Actions----------*/\r
82 #define NETCP_CFG_ACTION_DISCARD 0\r
83 #define NETCP_CFG_ACTION_CONTINUE 1  //pass packet on to next classifier\r
84 #define NETCP_CFG_ACTION_TO_SW    2\r
85 \r
86 /******************************************************************/\r
87 /***********************APP ids for rx meta data********************/\r
88 /******************************************************************/\r
89 // NWAL "AP ids" for PA Rules that are added\r
90 #define NETAPI_NETCP_MATCH_GENERIC_MAC   0x10000000  //lower byte==interface\r
91 #define NETAPI_NETCP_MATCH_GENERIC_IP    0x20000000  //lower byte==interface\r
92 #define NETAPI_NETCP_MATCH_CLASS         0x80000000  //FULL MATCH or' in classifier #, lower byte==interface\r
93 #define NETAPI_NETCP_MATCH_CLASS_L3      0x40000000  //MATCHED L3 but not L4.  lower byte==interface\r
94 \r
95 \r
96 /*---------MAC APPID------------------*/\r
97 typedef uint32_t NETCP_CFG_MACIF_T;\r
98 \r
99 /*------------L2----------------------*/\r
100 typedef void * NETCP_CFG_VLAN_T;\r
101 \r
102 /*---------------IP APPID-------------------*/\r
103 typedef uint32_t NETCP_CFG_IP_T;\r
104 \r
105 /* del mac i/f */\r
106 void netcp_cfgDelMac(NETAPI_T h,int iface_no,  int *err);\r
107 void netcp_cfgDelIp(NETAPI_T h, int iface_no,  nwal_IpType ipType,\r
108                   nwalIpAddr_t  * ip_addr,\r
109                   nwalIpOpt_t * ip_qualifiers, \r
110                   NETCP_CFG_IP_T, \r
111                   int *err);\r
112  \r
113 \r
114 /*****************************************************************\r
115  * Create a  MAC interface \r
116  ****************************************************************/\r
117 /*\r
118 *  @brief  API Creates a MAC interface  \r
119  *\r
120  *  @details This api is used to create a MAC interface.\r
121  *      Once it is created, the MAC interface can be used to receive packets. The API\r
122  *      adds a rule to the NETCP 1st level lookup tables to route all packets with destination\r
123  *      MAC matching supplied argument and not matching any other lookup entry (see @ref netcp_cfgAddIp) to\r
124  *      the supplied route, @ref NETCP_CFG_ROUTE_T, (or default route).\r
125  *      Packets arriving that match this rule are identified in meta data with Appid=  NETAPI_NETCP_MATCH_GENERIC_MAC\r
126  *  Note: The internal SOC switch must be "taught" that this mac\r
127  *      address is present by transmitting a packet with destination mac = this interface mac address.\r
128  *  @param[in]  @ref NETAPI_T: NETAPI instance \r
129  *  @param[in]  char *: pointer to 6 byte MAC address for interface\r
130  *  @param[in]  int : interface number (0,1,..) \r
131  *  @param[in]  int : switch port (0 don't care, 1 switch port 1, 1 switch port 2) [only 0 supported] \r
132  *  @param[in]  @ref NETCP_CFG_ROUTE_HANDLE_T : [future] handle of a created route or NULL to use internal default route \r
133  *  @oaram[in]  @ref NETCP_CFG_VLAN_T : [future[ vlan configuration . Set to NULL\r
134  *  @param[in]  int : [future] interface state (0=down, 1= up)\r
135  *  @param[out] int * err:  pointer to error return\r
136  *  @retval     @ref NETCP_CFG_MACIF_T : returned AppID for interface (this is returned in meta data for\r
137  *                 received packets matching this rule an no others)\r
138  *  @pre       @ref netapi_init \r
139  */\r
140 NETCP_CFG_MACIF_T  netcp_cfgCreateMacInterface(\r
141                   NETAPI_T  h,     //\r
142                   uint8_t *p_mac, //mac address associated with interface\r
143                   int iface_no, //0,1, ..\r
144                   int switch_port,//0=don't care, 1=switch port 1, 2=switch port 2 , ..\r
145                   NETCP_CFG_ROUTE_HANDLE_T  route, //NULL to use default\r
146                   NETCP_CFG_VLAN_T  vlan,  //future\r
147                   int state,  //0=down, 1=up  //FUTURE\r
148                   int * err\r
149                   );\r
150 \r
151 /*****************************************************************\r
152  * Add IP address/qualifier to MAC interface \r
153  ****************************************************************/\r
154 /*\r
155 *  @brief  API attaches an IP adderess and qualifier to a MAC interface \r
156  *\r
157  *  @details This api is used to add an IP address to a MAC interface along\r
158  *           with optional IP qualifier. A route, @ref NETCP_CFG_ROUTE_HANDLE_T,or NULL for default \r
159  *            may be specified to indicate where to send packets matching the MAC interface MAC address, the\r
160  *            supplied IP address and any qualifier.  This API adds a rule to the NETCP level 1 lookup tables\r
161  *            Packets arriving that match this rule are identified in meta data with Appid=  NETAPI_NETCP_MATCH_GENERIC_IP\r
162  * Note: An IP address must be attached to enable NETCP Recevie Checksum offload feature\r
163  *  @param[in]  @ref NETAPI_T: NETAPI instance\r
164  *  @param[in]  int : interface number (0,1,..)\r
165  *  @param[in]  @ref nwal_IpType : type of IP address (V4 for V6) \r
166  *  @oaram[in]  @ref nwalIpAddr_t : ip_address\r
167  *  @param[in]  @ref nwalIpOpt_t : ip_qualifiers (all 0 for no qualifiers). This can be used to apply special handling for\r
168  *                  diffserv category for example\r
169  *  @param[in]  @ref NETCP_CFG_ROUTE_HANDLE_T : [future] handle of a created route or NULL to use internal default route \r
170  *  @param[out] int * err:  pointer to error return\r
171  *  @retval     @ref NETCP_CFG_IP_T : returned AppID for attached rule. This is returned in RX meta data for\r
172  *              packets matching this rule and no other.\r
173  *  @pre       @ref netapi_init , @ref netcp_cfgAddMac \r
174  */\r
175 NETCP_CFG_IP_T  netcp_cfgAddIp(\r
176                   NETAPI_T  h,\r
177                   int  iface_no,\r
178                   nwal_IpType ipType,\r
179                   nwalIpAddr_t  * ip_addr,\r
180                   nwalIpOpt_t * ip_qualifiers,\r
181                   NETCP_CFG_ROUTE_HANDLE_T  route,  //NULL for default\r
182                   int * err\r
183                   );\r
184 #define netcp_addIp netcp_cfgAddIp //oops\r
185 \r
186 /*------------------classification API-------------------*/\r
187 \r
188 //handle to installed classifier returned by API.  Pkts matching\r
189 //this classifier will have meta data with this tag.  Also used\r
190 //to delete classifier\r
191 typedef uint32_t NETCP_CFG_CLASS_T;  \r
192 \r
193 //classifier L4 type  (L2,L3 implied by iface, ip)\r
194 typedef struct NETCP_CFG_CLASS_L4_Tag\r
195 {\r
196         //which mac interface pkt is from, \r
197         int iface;\r
198         NETCP_CFG_IP_T  ip;\r
199 \r
200         //L4  (port)\r
201         nwal_appProtoType_t proto;   //L4 proto  (-1 for don't care)\r
202         nwalAppProto_t   appProto;   //ports or equivalent\r
203 \r
204 } NETCP_CFG_CLASS_L4_T;\r
205 \r
206 //classifier L3_L4 type (L2 implied by iface)\r
207 typedef struct NETCP_CFG_CLASS_L3_L4_Tag\r
208 {\r
209         //which mac interface pkt is from, \r
210         int iface;\r
211 \r
212         //L3 -  iP address: IP type, destination addr, qualifiers\r
213         nwal_IpType ipType;\r
214         nwalIpAddr_t  * ip_addr;\r
215         nwalIpOpt_t * ip_qualifiers;\r
216         NETCP_CFG_ROUTE_HANDLE_T p_fail_route; //what to do if L3 matches but L4 fails AND L3 is a \r
217                                               // new rule.(if exisitng rule, then existing fail\r
218                                               //route will be used.\r
219        \r
220         //L4  (port)\r
221         nwal_appProtoType_t proto;   //L4 proto  (-1 for don't care)\r
222         nwalAppProto_t   appProto;   //ports or equivalent\r
223 \r
224 } NETCP_CFG_CLASS_L3_L4_T;\r
225 \r
226 //classifier\r
227 typedef struct NETCP_CFG_CLASSIFIER_Tag\r
228 {\r
229         int classType;\r
230 #define NETCP_CFG_CLASS_TYPE_L4  0\r
231 #define NETCP_CFG_CLASS_TYPE_L3_L4  1\r
232         union\r
233         {\r
234                 NETCP_CFG_CLASS_L3_L4_T  c_l3_l4;\r
235                 NETCP_CFG_CLASS_L4_T  c_l4;\r
236         } u;\r
237 \r
238 } NETCP_CFG_CLASSIFIER_T;\r
239 \r
240 //Instert a classifier.\r
241 NETCP_CFG_CLASS_T netcp_cfgAddClass(NETAPI_T h,\r
242                                     NETCP_CFG_CLASSIFIER_T *p_class,\r
243                                     NETCP_CFG_ROUTE_HANDLE_T p_route,\r
244                                     int action, int * err);\r
245 //delete classifier\r
246 void netcp_cfgDelClass(NETAPI_T h,\r
247                          NETCP_CFG_CLASS_T classId,\r
248                          int *err);\r
249 \r
250 \r
251 \r
252 /***************************************************************************\r
253 ********************************STATS**************************************\r
254 **************************************************************************/\r
255 \r
256 /*\r
257  *  @brief  This is the callback function that is used to return statistics from NETCP \r
258  *\r
259  *  @details The application provides a callback function that NETAPI  uses to report statistics.\r
260 *    The request for stats is generated from the @ref netcp_cfgReqStats API.\r
261  *   Note: to receive ths stats callback, the @ref netapi_netcpPoll funcition must be called\r
262  *  @param[in]  @ref NETAPI_T: NETAPI instance\r
263  *  @param[in]  @ref paSysStats_t * : the PA (NETCP packet accelerator subsystem) statistics block \r
264  *  @retval     none \r
265  *  @pre       @ref netapi_init , @ref netapi_cfgReqStats, @ref netapi_netcpPoll\r
266  */\r
267 //stats CB\r
268 typedef void (*NETCP_CFG_STATS_CB)( NETAPI_T h, paSysStats_t* pPaStats);\r
269 \r
270 \r
271 //stats request\r
272 /*\r
273  *  @brief  API request statistics from NETCP \r
274  *\r
275  *  @details This api is used to request a statistics from NETCP.  This will generate a stats request\r
276  *           command to NETCP. Sometime later, the statistics result will arrive and will be passed to \r
277  *           the caller via the asynchronus callback @ref NETCP_CFG_STATS_CB that is registered in this call.\r
278  *       Note: to receive the stats callback, the @ref netapi_netcpPoll funcition must be called\r
279  *  @param[in]  @ref NETAPI_T: NETAPI instance\r
280  *  @param[in]  @ref NETCP_CFG_STATS_CB : the function to call with the resulting statistics block\r
281  *  @param[in]  int :  clear the stats in NETCP after the report (0=no, 1=yes)                                          \r
282  *  @param[out] int * err:  pointer to error return\r
283  *  @retval     none \r
284  *  @pre       @ref netapi_init \r
285  */\r
286 void netcp_cfgReqStats(NETAPI_T  h,  //NEAPI instance\r
287                        NETCP_CFG_STATS_CB c, //stats report callback function\r
288                        int doClear,   //0: don't clear, 1 clear\r
289                        int *err);\r
290 \r
291 #endif\r
292 \r