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 #define NETCP_DEFAULT_FLOW (NETCP_CFG_FLOW_HANDLE_T*) NULL\r
58 \r
59 //NETCP ROUTE\r
60 typedef struct NETCP_CFG_ROUTE_Tag\r
61 {\r
62 NETCP_CFG_FLOW_T * p_flow; //NULL or NETCP_DEFAULT_FLOW for default flow\r
63 PKTIO_HANDLE_T * p_dest_q; //NULL for default destination queue\r
64 } NETCP_CFG_ROUTE_T;\r
65 typedef void * NETCP_CFG_ROUTE_HANDLE_T; \r
66 #define NETCP_DEFAULT_ROUTE (NETCP_CFG_ROUTE_HANDLE_T*) NULL\r
67 \r
68 \r
69 /*--------------flow management--------*/\r
70 NETCP_CFG_FLOW_HANDLE_T netcp_cfgAddFlow(NETAPI_T ,\r
71 int n, \r
72 Pktlib_HeapHandle handles[],\r
73 int sizes[],\r
74 int recv_offset, //bytes to save in front of packet\r
75 int * err );\r
76 void netcp_cfgDelFlow(NETAPI_T , NETCP_CFG_FLOW_HANDLE_T , int * err);\r
77 \r
78 /*-----------Actions----------*/\r
79 #define NETCP_CFG_ACTION_DISCARD 0\r
80 #define NETCP_CFG_ACTION_CONTINUE 1 //pass packet on to next classifier\r
81 #define NETCP_CFG_ACTION_TO_SW 2\r
82 \r
83 /*------------L2----------------------*/\r
84 typedef void * NETCP_CFG_VLAN_T;\r
85 \r
86 /******************************************************************/\r
87 /***********************APP ids for rx meta data********************/\r
88 /******************************************************************/\r
89 \r
90 /* APPIDs are present in RX packet meta data and tell "how far the packet got\r
91 through the classification rules of NETCP \r
92 APPID is 32 bits:\r
93 bits 31-24 = MATCH STAGE (NETAPI_NECP_MATCH_xxx below)\r
94 bits 23-8 = identifier (depends on match stage)\r
95 bits 7-0 = logical mac interface\r
96 \r
97 As a cheat sheet:\r
98 If APPID == _NETCP_MATCH_GENERIC_MAC then\r
99 packet matched a MAC entry. Entry # (logical interface) is in byte 0 of APPID. \r
100 Packet did not match any other rule\r
101 \r
102 If APPID == _NETCP_MATCH_GENERIC_IP then\r
103 packet matched a MAC entry. Entry # (logical interface) is in byte 0 of APPID\r
104 packet matched a generic IP rule attached to that interface. The IP rule # for the interface\r
105 is given in Bytes 3,2 of the APPID. Packet did not match any other rule\r
106 \r
107 If APPID = NETCP_MATCH_CLASS\r
108 packet matched a MAC entry. Entry # (logical interface) is in byte 0 of APPID\r
109 packet matched a generic IP rule attached to that interface OR a general IP rule added as part of\r
110 the classifier or it matched a combination of ISPEC SA rule and a policy check. Finally,\r
111 Packet matched a L4 port rule that was added as part of a classifer. Bytes 3-2\r
112 give the ID of the classifier . Packet did not match any other rule\r
113 \r
114 If APPID = NETCP_MATCH_CLASS_L3 (partial classifier match)\r
115 packet matched a MAC entry. Entry # (logical interface) is in byte 0 of APPID\r
116 packet matched a general IP rule added as part of a classifier. But it not match a\r
117 L4 port or any other rule. We cannout say what classifer partially matched so Bytes 3-2 are\r
118 not applicable\r
119 \r
120 \r
121 If APPID = NETCP_MATCH_IPSEC\r
122 packet matched a MAC entry. Entry # (logical interface) is in byte 0 of APPID\r
123 packet matched an IPSEC SA rule (matched proto, dest ip and SPI). The SA id is in\r
124 bytes 3-2 of APPID. Packet did not match any other rule (so may have failed a policy check)\r
125 \r
126 ID APPID = NETCP_MATCH_IPSEC_POLICY \r
127 packet matched a MAC entry. Entry # (logical interface) is in byte 0 of APPID\r
128 packet matched an IPSEC SA rule (matched proto, dest ip and SPI). Packet matched\r
129 a POLICY RULE - this is a check of the inner IP. The IPSEC RX Policy ID is in\r
130 bytes 3-2 of APPID. Packet did not match any other rule \r
131 */\r
132 \r
133 \r
134 // NWAL "AP ids" for PA Rules that are added\r
135 #define NETAPI_NETCP_MATCH_GENERIC_MAC 0x10000000 //lower byte==interface\r
136 #define NETAPI_NETCP_MATCH_GENERIC_IP 0x20000000 //lower byte==interface\r
137 #define NETAPI_NETCP_MATCH_CLASS 0x80000000 //FULL MATCH or' in classifier (16 bits), lower byte==interface\r
138 #define NETAPI_NETCP_MATCH_CLASS_L3 0x40000000 //MATCHED L3 but not L4. lower byte==interface\r
139 #define NETAPI_NETCP_MATCH_IPSEC 0x01000000 //lower byte==interface, Or' in SA id (16 bits)\r
140 #define NETAPI_NETCP_MATCH_IPSEC_POLICY 0x02000000 //lower byte==interface, Or' in SA id (16 bits)\r
141 \r
142 /*---------MAC APPID------------------*/\r
143 /* Packets just matching MAC rule are tagged with this type (MATCH_GENERIC_MAC) */\r
144 typedef uint32_t NETCP_CFG_MACIF_T;\r
145 \r
146 /*---------------IP APPID-------------------*/\r
147 /* Packets whose final match is an IP rule are tagged with this type (MATCH_GENERIC_IP)*/ \r
148 typedef uint32_t NETCP_CFG_IP_T;\r
149 \r
150 /*--------------Tunnel APPID------------------*/\r
151 /* Packets whose final match a IPSEC tunnel are tagged with this type (MATCH_IPSEC)*/ \r
152 typedef uint32_t NETCP_CFG_SA_T; \r
153 \r
154 /*---------------IPSEc RX Policy APPID------------*/\r
155 /* Packets whose final match is a IPSEC RX Policy are tagged with this type (MATCH_IPSEC_POLICY)*/ \r
156 typedef uint32_t NETCP_CFG_IPSEC_POLICY_T; \r
157 \r
158 \r
159 //use this in AddIp, AddClassifier to indicate any MAC address\r
160 #define NETCP_CFG_NO_INTERFACE 0xff\r
161 \r
162 /* del mac i/f */\r
163 void netcp_cfgDelMac(NETAPI_T h,int iface_no, int *err);\r
164 \r
165 /* del attached IP*/\r
166 void netcp_cfgDelIp(NETAPI_T h, int iface_no, nwal_IpType ipType,\r
167 nwalIpAddr_t * ip_addr,\r
168 nwalIpOpt_t * ip_qualifiers, \r
169 NETCP_CFG_IP_T, \r
170 int *err);\r
171 \r
172 \r
173 /*****************************************************************\r
174 * Create a MAC interface \r
175 ****************************************************************/\r
176 /*\r
177 * @brief API Creates a MAC interface \r
178 *\r
179 * @details This api is used to create a MAC interface.\r
180 * Once it is created, the MAC interface can be used to receive packets. The API\r
181 * adds a rule to the NETCP 1st level lookup tables to route all packets with destination\r
182 * MAC matching supplied argument and not matching any other lookup entry (see @ref netcp_cfgAddIp) to\r
183 * the supplied route, @ref NETCP_CFG_ROUTE_T, (or default route).\r
184 * Packets arriving that match this rule are identified in meta data with Appid= NETAPI_NETCP_MATCH_GENERIC_MAC\r
185 * Note: The internal SOC switch must be "taught" that this mac\r
186 * address is present by transmitting a packet with destination mac = this interface mac address.\r
187 * @param[in] @ref NETAPI_T: NETAPI instance \r
188 * @param[in] char *: pointer to 6 byte MAC address for interface\r
189 * @param[in] int : interface number (0,1,..) \r
190 * @param[in] int : switch port (0 don't care, 1 switch port 1, 1 switch port 2) [only 0 supported] \r
191 * @param[in] @ref NETCP_CFG_ROUTE_HANDLE_T : [future] handle of a created route or NULL to use internal default route \r
192 * @oaram[in] @ref NETCP_CFG_VLAN_T : [future[ vlan configuration . Set to NULL\r
193 * @param[in] int : [future] interface state (0=down, 1= up)\r
194 * @param[out] int * err: pointer to error return\r
195 * @retval @ref NETCP_CFG_MACIF_T : returned AppID for interface (this is returned in meta data for\r
196 * received packets matching this rule an no others)\r
197 * @pre @ref netapi_init \r
198 */\r
199 NETCP_CFG_MACIF_T netcp_cfgCreateMacInterface(\r
200 NETAPI_T h, //\r
201 uint8_t *p_mac, //mac address associated with interface\r
202 int iface_no, //0,1, ..\r
203 int switch_port,//0=don't care, 1=switch port 1, 2=switch port 2 , ..\r
204 NETCP_CFG_ROUTE_HANDLE_T route, //NULL to use default\r
205 NETCP_CFG_VLAN_T vlan, //future\r
206 int state, //0=down, 1=up //FUTURE\r
207 int * err\r
208 );\r
209 \r
210 /*****************************************************************\r
211 * Add IP address/qualifier to MAC interface \r
212 ****************************************************************/\r
213 /*\r
214 * @brief API attaches an IP adderess and qualifier to a MAC interface \r
215 *\r
216 * @details This api is used to add an IP address to a MAC interface along\r
217 * with optional IP qualifier. A route, @ref NETCP_CFG_ROUTE_HANDLE_T,or NULL for default \r
218 * may be specified to indicate where to send packets matching the MAC interface MAC address, the\r
219 * supplied IP address and any qualifier. This API adds a rule to the NETCP level 1 lookup tables\r
220 * Packets arriving that match this rule are identified in meta data with Appid= NETAPI_NETCP_MATCH_GENERIC_IP\r
221 * Note: An IP address must be attached to enable NETCP Recevie Checksum offload feature\r
222 * @param[in] @ref NETAPI_T: NETAPI instance\r
223 * @param[in] int : interface number (0,1,..)\r
224 * @param[in] @ref nwal_IpType : type of IP address (V4 for V6) \r
225 * @oaram[in] @ref nwalIpAddr_t : ip_address\r
226 * @param[in] @ref nwalIpOpt_t : ip_qualifiers (all 0 for no qualifiers). This can be used to apply special handling for\r
227 * diffserv category for example\r
228 * @param[in] @ref NETCP_CFG_ROUTE_HANDLE_T : [future] handle of a created route or NULL to use internal default route \r
229 * @param[out] int * err: pointer to error return\r
230 * @retval @ref NETCP_CFG_IP_T : returned AppID for attached rule. This is returned in RX meta data for\r
231 * packets matching this rule and no other.\r
232 * @pre @ref netapi_init , @ref netcp_cfgAddMac \r
233 */\r
234 NETCP_CFG_IP_T netcp_cfgAddIp(\r
235 NETAPI_T h,\r
236 int iface_no,\r
237 nwal_IpType ipType,\r
238 nwalIpAddr_t * ip_addr,\r
239 nwalIpOpt_t * ip_qualifiers,\r
240 NETCP_CFG_ROUTE_HANDLE_T route, //NULL for default\r
241 int * err\r
242 );\r
243 #define netcp_addIp netcp_cfgAddIp //oops\r
244 \r
245 /*------------------classification API-------------------*/\r
246 \r
247 //handle to installed classifier returned by API. Pkts matching\r
248 //this classifier will have meta data with this tag. Also used\r
249 //to delete classifier\r
250 typedef uint32_t NETCP_CFG_CLASS_T; \r
251 \r
252 //classifier L4 type (L2,L3 implied by iface, ip)\r
253 typedef struct NETCP_CFG_CLASS_L4_Tag\r
254 {\r
255 //which mac interface pkt is from, \r
256 int iface;\r
257 NETCP_CFG_IP_T ip;\r
258 \r
259 //L4 (port)\r
260 nwal_appProtoType_t proto; //L4 proto (-1 for don't care)\r
261 nwalAppProto_t appProto; //ports or equivalent\r
262 \r
263 } NETCP_CFG_CLASS_L4_T;\r
264 \r
265 //classifier L4 + policy (L2, L3 (outer), tunnel, L3 (inner) implied by policy\r
266 typedef struct NETCP_CFG_CLASS_L4_IPSEC_Tag\r
267 {\r
268 //which mac interface pkt is from, \r
269 int iface;\r
270 NETCP_CFG_IPSEC_POLICY_T ip_policy;\r
271 \r
272 //L4 (port)\r
273 nwal_appProtoType_t proto; //L4 proto (-1 for don't care)\r
274 nwalAppProto_t appProto; //ports or equivalent\r
275 \r
276 } NETCP_CFG_CLASS_L4_IPSEC_T;\r
277 \r
278 \r
279 //classifier L3_L4 type (L2 implied by iface)\r
280 typedef struct NETCP_CFG_CLASS_L3_L4_Tag\r
281 {\r
282 //which mac interface pkt is from, \r
283 int iface;\r
284 \r
285 //L3 - iP address: IP type, destination addr, qualifiers\r
286 nwal_IpType ipType;\r
287 nwalIpAddr_t * ip_addr;\r
288 nwalIpOpt_t * ip_qualifiers;\r
289 NETCP_CFG_ROUTE_HANDLE_T p_fail_route; //what to do if L3 matches but L4 fails AND L3 is a \r
290 // new rule.(if exisitng rule, then existing fail\r
291 //route will be used.\r
292 \r
293 //L4 (port)\r
294 nwal_appProtoType_t proto; //L4 proto (-1 for don't care)\r
295 nwalAppProto_t appProto; //ports or equivalent\r
296 \r
297 } NETCP_CFG_CLASS_L3_L4_T;\r
298 \r
299 //classifier\r
300 typedef struct NETCP_CFG_CLASSIFIER_Tag\r
301 {\r
302 int classType;\r
303 #define NETCP_CFG_CLASS_TYPE_L4 0\r
304 #define NETCP_CFG_CLASS_TYPE_L3_L4 1\r
305 union\r
306 {\r
307 NETCP_CFG_CLASS_L3_L4_T c_l3_l4;\r
308 NETCP_CFG_CLASS_L4_T c_l4;\r
309 NETCP_CFG_CLASS_L4_IPSEC_T c_l4_ipsec;\r
310 } u;\r
311 \r
312 } NETCP_CFG_CLASSIFIER_T;\r
313 \r
314 //Instert a classifier.\r
315 NETCP_CFG_CLASS_T netcp_cfgAddClass(NETAPI_T h,\r
316 NETCP_CFG_CLASSIFIER_T *p_class,\r
317 NETCP_CFG_ROUTE_HANDLE_T p_route,\r
318 int action, int * err);\r
319 //delete classifier\r
320 void netcp_cfgDelClass(NETAPI_T h,\r
321 NETCP_CFG_CLASS_T classId,\r
322 int *err);\r
323 \r
324 \r
325 \r
326 /***************************************************************************\r
327 ********************************STATS**************************************\r
328 **************************************************************************/\r
329 \r
330 /*\r
331 * @brief This is the callback function that is used to return statistics from NETCP \r
332 *\r
333 * @details The application provides a callback function that NETAPI uses to report statistics.\r
334 * The request for stats is generated from the @ref netcp_cfgReqStats API.\r
335 * Note: to receive ths stats callback, the @ref netapi_netcpPoll funcition must be called\r
336 * @param[in] @ref NETAPI_T: NETAPI instance\r
337 * @param[in] @ref paSysStats_t * : the PA (NETCP packet accelerator subsystem) statistics block \r
338 * @retval none \r
339 * @pre @ref netapi_init , @ref netapi_cfgReqStats, @ref netapi_netcpPoll\r
340 */\r
341 //stats CB\r
342 typedef void (*NETCP_CFG_STATS_CB)( NETAPI_T h, paSysStats_t* pPaStats);\r
343 \r
344 \r
345 //stats request\r
346 /*\r
347 * @brief API request statistics from NETCP \r
348 *\r
349 * @details This api is used to request a statistics from NETCP. This will generate a stats request\r
350 * command to NETCP. Sometime later, the statistics result will arrive and will be passed to \r
351 * the caller via the asynchronus callback @ref NETCP_CFG_STATS_CB that is registered in this call.\r
352 * Note: to receive the stats callback, the @ref netapi_netcpPoll funcition must be called\r
353 * @param[in] @ref NETAPI_T: NETAPI instance\r
354 * @param[in] @ref NETCP_CFG_STATS_CB : the function to call with the resulting statistics block\r
355 * @param[in] int : clear the stats in NETCP after the report (0=no, 1=yes) \r
356 * @param[out] int * err: pointer to error return\r
357 * @retval none \r
358 * @pre @ref netapi_init \r
359 */\r
360 void netcp_cfgReqStats(NETAPI_T h, //NEAPI instance\r
361 NETCP_CFG_STATS_CB c, //stats report callback function\r
362 int doClear, //0: don't clear, 1 clear\r
363 int *err);\r
364 \r
365 #endif\r
366 \r