ffc6ce1dad580f5b21e30571da4d6990aab59cbc
[dpdk.git] / drivers / net / enic / enic_flow.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2008-2017 Cisco Systems, Inc.  All rights reserved.
3  */
4
5 #include <errno.h>
6 #include <stdint.h>
7 #include <rte_log.h>
8 #include <rte_ethdev_driver.h>
9 #include <rte_flow_driver.h>
10 #include <rte_ether.h>
11 #include <rte_ip.h>
12 #include <rte_udp.h>
13
14 #include "enic_compat.h"
15 #include "enic.h"
16 #include "vnic_dev.h"
17 #include "vnic_nic.h"
18
19 #define FLOW_TRACE() \
20         rte_log(RTE_LOG_DEBUG, enicpmd_logtype_flow, \
21                 "%s()\n", __func__)
22 #define FLOW_LOG(level, fmt, args...) \
23         rte_log(RTE_LOG_ ## level, enicpmd_logtype_flow, \
24                 fmt "\n", ##args)
25
26 /*
27  * Common arguments passed to copy_item functions. Use this structure
28  * so we can easily add new arguments.
29  * item: Item specification.
30  * filter: Partially filled in NIC filter structure.
31  * inner_ofst: If zero, this is an outer header. If non-zero, this is
32  *   the offset into L5 where the header begins.
33  */
34 struct copy_item_args {
35         const struct rte_flow_item *item;
36         struct filter_v2 *filter;
37         uint8_t *inner_ofst;
38 };
39
40 /* functions for copying items into enic filters */
41 typedef int (enic_copy_item_fn)(struct copy_item_args *arg);
42
43 /** Info about how to copy items into enic filters. */
44 struct enic_items {
45         /** Function for copying and validating an item. */
46         enic_copy_item_fn *copy_item;
47         /** List of valid previous items. */
48         const enum rte_flow_item_type * const prev_items;
49         /** True if it's OK for this item to be the first item. For some NIC
50          * versions, it's invalid to start the stack above layer 3.
51          */
52         const u8 valid_start_item;
53 };
54
55 /** Filtering capabilities for various NIC and firmware versions. */
56 struct enic_filter_cap {
57         /** list of valid items and their handlers and attributes. */
58         const struct enic_items *item_info;
59         /* Max type in the above list, used to detect unsupported types */
60         enum rte_flow_item_type max_item_type;
61 };
62
63 /* functions for copying flow actions into enic actions */
64 typedef int (copy_action_fn)(struct enic *enic,
65                              const struct rte_flow_action actions[],
66                              struct filter_action_v2 *enic_action);
67
68 /** Action capabilities for various NICs. */
69 struct enic_action_cap {
70         /** list of valid actions */
71         const enum rte_flow_action_type *actions;
72         /** copy function for a particular NIC */
73         copy_action_fn *copy_fn;
74 };
75
76 /* Forward declarations */
77 static enic_copy_item_fn enic_copy_item_ipv4_v1;
78 static enic_copy_item_fn enic_copy_item_udp_v1;
79 static enic_copy_item_fn enic_copy_item_tcp_v1;
80 static enic_copy_item_fn enic_copy_item_raw_v2;
81 static enic_copy_item_fn enic_copy_item_eth_v2;
82 static enic_copy_item_fn enic_copy_item_vlan_v2;
83 static enic_copy_item_fn enic_copy_item_ipv4_v2;
84 static enic_copy_item_fn enic_copy_item_ipv6_v2;
85 static enic_copy_item_fn enic_copy_item_udp_v2;
86 static enic_copy_item_fn enic_copy_item_tcp_v2;
87 static enic_copy_item_fn enic_copy_item_sctp_v2;
88 static enic_copy_item_fn enic_copy_item_vxlan_v2;
89 static copy_action_fn enic_copy_action_v1;
90 static copy_action_fn enic_copy_action_v2;
91
92 /**
93  * Legacy NICs or NICs with outdated firmware. Only 5-tuple perfect match
94  * is supported.
95  */
96 static const struct enic_items enic_items_v1[] = {
97         [RTE_FLOW_ITEM_TYPE_IPV4] = {
98                 .copy_item = enic_copy_item_ipv4_v1,
99                 .valid_start_item = 1,
100                 .prev_items = (const enum rte_flow_item_type[]) {
101                                RTE_FLOW_ITEM_TYPE_END,
102                 },
103         },
104         [RTE_FLOW_ITEM_TYPE_UDP] = {
105                 .copy_item = enic_copy_item_udp_v1,
106                 .valid_start_item = 0,
107                 .prev_items = (const enum rte_flow_item_type[]) {
108                                RTE_FLOW_ITEM_TYPE_IPV4,
109                                RTE_FLOW_ITEM_TYPE_END,
110                 },
111         },
112         [RTE_FLOW_ITEM_TYPE_TCP] = {
113                 .copy_item = enic_copy_item_tcp_v1,
114                 .valid_start_item = 0,
115                 .prev_items = (const enum rte_flow_item_type[]) {
116                                RTE_FLOW_ITEM_TYPE_IPV4,
117                                RTE_FLOW_ITEM_TYPE_END,
118                 },
119         },
120 };
121
122 /**
123  * NICs have Advanced Filters capability but they are disabled. This means
124  * that layer 3 must be specified.
125  */
126 static const struct enic_items enic_items_v2[] = {
127         [RTE_FLOW_ITEM_TYPE_RAW] = {
128                 .copy_item = enic_copy_item_raw_v2,
129                 .valid_start_item = 0,
130                 .prev_items = (const enum rte_flow_item_type[]) {
131                                RTE_FLOW_ITEM_TYPE_UDP,
132                                RTE_FLOW_ITEM_TYPE_END,
133                 },
134         },
135         [RTE_FLOW_ITEM_TYPE_ETH] = {
136                 .copy_item = enic_copy_item_eth_v2,
137                 .valid_start_item = 1,
138                 .prev_items = (const enum rte_flow_item_type[]) {
139                                RTE_FLOW_ITEM_TYPE_VXLAN,
140                                RTE_FLOW_ITEM_TYPE_END,
141                 },
142         },
143         [RTE_FLOW_ITEM_TYPE_VLAN] = {
144                 .copy_item = enic_copy_item_vlan_v2,
145                 .valid_start_item = 1,
146                 .prev_items = (const enum rte_flow_item_type[]) {
147                                RTE_FLOW_ITEM_TYPE_ETH,
148                                RTE_FLOW_ITEM_TYPE_END,
149                 },
150         },
151         [RTE_FLOW_ITEM_TYPE_IPV4] = {
152                 .copy_item = enic_copy_item_ipv4_v2,
153                 .valid_start_item = 1,
154                 .prev_items = (const enum rte_flow_item_type[]) {
155                                RTE_FLOW_ITEM_TYPE_ETH,
156                                RTE_FLOW_ITEM_TYPE_VLAN,
157                                RTE_FLOW_ITEM_TYPE_END,
158                 },
159         },
160         [RTE_FLOW_ITEM_TYPE_IPV6] = {
161                 .copy_item = enic_copy_item_ipv6_v2,
162                 .valid_start_item = 1,
163                 .prev_items = (const enum rte_flow_item_type[]) {
164                                RTE_FLOW_ITEM_TYPE_ETH,
165                                RTE_FLOW_ITEM_TYPE_VLAN,
166                                RTE_FLOW_ITEM_TYPE_END,
167                 },
168         },
169         [RTE_FLOW_ITEM_TYPE_UDP] = {
170                 .copy_item = enic_copy_item_udp_v2,
171                 .valid_start_item = 0,
172                 .prev_items = (const enum rte_flow_item_type[]) {
173                                RTE_FLOW_ITEM_TYPE_IPV4,
174                                RTE_FLOW_ITEM_TYPE_IPV6,
175                                RTE_FLOW_ITEM_TYPE_END,
176                 },
177         },
178         [RTE_FLOW_ITEM_TYPE_TCP] = {
179                 .copy_item = enic_copy_item_tcp_v2,
180                 .valid_start_item = 0,
181                 .prev_items = (const enum rte_flow_item_type[]) {
182                                RTE_FLOW_ITEM_TYPE_IPV4,
183                                RTE_FLOW_ITEM_TYPE_IPV6,
184                                RTE_FLOW_ITEM_TYPE_END,
185                 },
186         },
187         [RTE_FLOW_ITEM_TYPE_SCTP] = {
188                 .copy_item = enic_copy_item_sctp_v2,
189                 .valid_start_item = 0,
190                 .prev_items = (const enum rte_flow_item_type[]) {
191                                RTE_FLOW_ITEM_TYPE_IPV4,
192                                RTE_FLOW_ITEM_TYPE_IPV6,
193                                RTE_FLOW_ITEM_TYPE_END,
194                 },
195         },
196         [RTE_FLOW_ITEM_TYPE_VXLAN] = {
197                 .copy_item = enic_copy_item_vxlan_v2,
198                 .valid_start_item = 0,
199                 .prev_items = (const enum rte_flow_item_type[]) {
200                                RTE_FLOW_ITEM_TYPE_UDP,
201                                RTE_FLOW_ITEM_TYPE_END,
202                 },
203         },
204 };
205
206 /** NICs with Advanced filters enabled */
207 static const struct enic_items enic_items_v3[] = {
208         [RTE_FLOW_ITEM_TYPE_RAW] = {
209                 .copy_item = enic_copy_item_raw_v2,
210                 .valid_start_item = 0,
211                 .prev_items = (const enum rte_flow_item_type[]) {
212                                RTE_FLOW_ITEM_TYPE_UDP,
213                                RTE_FLOW_ITEM_TYPE_END,
214                 },
215         },
216         [RTE_FLOW_ITEM_TYPE_ETH] = {
217                 .copy_item = enic_copy_item_eth_v2,
218                 .valid_start_item = 1,
219                 .prev_items = (const enum rte_flow_item_type[]) {
220                                RTE_FLOW_ITEM_TYPE_VXLAN,
221                                RTE_FLOW_ITEM_TYPE_END,
222                 },
223         },
224         [RTE_FLOW_ITEM_TYPE_VLAN] = {
225                 .copy_item = enic_copy_item_vlan_v2,
226                 .valid_start_item = 1,
227                 .prev_items = (const enum rte_flow_item_type[]) {
228                                RTE_FLOW_ITEM_TYPE_ETH,
229                                RTE_FLOW_ITEM_TYPE_END,
230                 },
231         },
232         [RTE_FLOW_ITEM_TYPE_IPV4] = {
233                 .copy_item = enic_copy_item_ipv4_v2,
234                 .valid_start_item = 1,
235                 .prev_items = (const enum rte_flow_item_type[]) {
236                                RTE_FLOW_ITEM_TYPE_ETH,
237                                RTE_FLOW_ITEM_TYPE_VLAN,
238                                RTE_FLOW_ITEM_TYPE_END,
239                 },
240         },
241         [RTE_FLOW_ITEM_TYPE_IPV6] = {
242                 .copy_item = enic_copy_item_ipv6_v2,
243                 .valid_start_item = 1,
244                 .prev_items = (const enum rte_flow_item_type[]) {
245                                RTE_FLOW_ITEM_TYPE_ETH,
246                                RTE_FLOW_ITEM_TYPE_VLAN,
247                                RTE_FLOW_ITEM_TYPE_END,
248                 },
249         },
250         [RTE_FLOW_ITEM_TYPE_UDP] = {
251                 .copy_item = enic_copy_item_udp_v2,
252                 .valid_start_item = 1,
253                 .prev_items = (const enum rte_flow_item_type[]) {
254                                RTE_FLOW_ITEM_TYPE_IPV4,
255                                RTE_FLOW_ITEM_TYPE_IPV6,
256                                RTE_FLOW_ITEM_TYPE_END,
257                 },
258         },
259         [RTE_FLOW_ITEM_TYPE_TCP] = {
260                 .copy_item = enic_copy_item_tcp_v2,
261                 .valid_start_item = 1,
262                 .prev_items = (const enum rte_flow_item_type[]) {
263                                RTE_FLOW_ITEM_TYPE_IPV4,
264                                RTE_FLOW_ITEM_TYPE_IPV6,
265                                RTE_FLOW_ITEM_TYPE_END,
266                 },
267         },
268         [RTE_FLOW_ITEM_TYPE_SCTP] = {
269                 .copy_item = enic_copy_item_sctp_v2,
270                 .valid_start_item = 0,
271                 .prev_items = (const enum rte_flow_item_type[]) {
272                                RTE_FLOW_ITEM_TYPE_IPV4,
273                                RTE_FLOW_ITEM_TYPE_IPV6,
274                                RTE_FLOW_ITEM_TYPE_END,
275                 },
276         },
277         [RTE_FLOW_ITEM_TYPE_VXLAN] = {
278                 .copy_item = enic_copy_item_vxlan_v2,
279                 .valid_start_item = 1,
280                 .prev_items = (const enum rte_flow_item_type[]) {
281                                RTE_FLOW_ITEM_TYPE_UDP,
282                                RTE_FLOW_ITEM_TYPE_END,
283                 },
284         },
285 };
286
287 /** Filtering capabilities indexed this NICs supported filter type. */
288 static const struct enic_filter_cap enic_filter_cap[] = {
289         [FILTER_IPV4_5TUPLE] = {
290                 .item_info = enic_items_v1,
291                 .max_item_type = RTE_FLOW_ITEM_TYPE_TCP,
292         },
293         [FILTER_USNIC_IP] = {
294                 .item_info = enic_items_v2,
295                 .max_item_type = RTE_FLOW_ITEM_TYPE_VXLAN,
296         },
297         [FILTER_DPDK_1] = {
298                 .item_info = enic_items_v3,
299                 .max_item_type = RTE_FLOW_ITEM_TYPE_VXLAN,
300         },
301 };
302
303 /** Supported actions for older NICs */
304 static const enum rte_flow_action_type enic_supported_actions_v1[] = {
305         RTE_FLOW_ACTION_TYPE_QUEUE,
306         RTE_FLOW_ACTION_TYPE_END,
307 };
308
309 /** Supported actions for newer NICs */
310 static const enum rte_flow_action_type enic_supported_actions_v2_id[] = {
311         RTE_FLOW_ACTION_TYPE_QUEUE,
312         RTE_FLOW_ACTION_TYPE_MARK,
313         RTE_FLOW_ACTION_TYPE_FLAG,
314         RTE_FLOW_ACTION_TYPE_RSS,
315         RTE_FLOW_ACTION_TYPE_PASSTHRU,
316         RTE_FLOW_ACTION_TYPE_END,
317 };
318
319 static const enum rte_flow_action_type enic_supported_actions_v2_drop[] = {
320         RTE_FLOW_ACTION_TYPE_QUEUE,
321         RTE_FLOW_ACTION_TYPE_MARK,
322         RTE_FLOW_ACTION_TYPE_FLAG,
323         RTE_FLOW_ACTION_TYPE_DROP,
324         RTE_FLOW_ACTION_TYPE_RSS,
325         RTE_FLOW_ACTION_TYPE_PASSTHRU,
326         RTE_FLOW_ACTION_TYPE_END,
327 };
328
329 static const enum rte_flow_action_type enic_supported_actions_v2_count[] = {
330         RTE_FLOW_ACTION_TYPE_QUEUE,
331         RTE_FLOW_ACTION_TYPE_MARK,
332         RTE_FLOW_ACTION_TYPE_FLAG,
333         RTE_FLOW_ACTION_TYPE_DROP,
334         RTE_FLOW_ACTION_TYPE_COUNT,
335         RTE_FLOW_ACTION_TYPE_RSS,
336         RTE_FLOW_ACTION_TYPE_PASSTHRU,
337         RTE_FLOW_ACTION_TYPE_END,
338 };
339
340 /** Action capabilities indexed by NIC version information */
341 static const struct enic_action_cap enic_action_cap[] = {
342         [FILTER_ACTION_RQ_STEERING_FLAG] = {
343                 .actions = enic_supported_actions_v1,
344                 .copy_fn = enic_copy_action_v1,
345         },
346         [FILTER_ACTION_FILTER_ID_FLAG] = {
347                 .actions = enic_supported_actions_v2_id,
348                 .copy_fn = enic_copy_action_v2,
349         },
350         [FILTER_ACTION_DROP_FLAG] = {
351                 .actions = enic_supported_actions_v2_drop,
352                 .copy_fn = enic_copy_action_v2,
353         },
354         [FILTER_ACTION_COUNTER_FLAG] = {
355                 .actions = enic_supported_actions_v2_count,
356                 .copy_fn = enic_copy_action_v2,
357         },
358 };
359
360 static int
361 mask_exact_match(const u8 *supported, const u8 *supplied,
362                  unsigned int size)
363 {
364         unsigned int i;
365         for (i = 0; i < size; i++) {
366                 if (supported[i] != supplied[i])
367                         return 0;
368         }
369         return 1;
370 }
371
372 static int
373 enic_copy_item_ipv4_v1(struct copy_item_args *arg)
374 {
375         const struct rte_flow_item *item = arg->item;
376         struct filter_v2 *enic_filter = arg->filter;
377         uint8_t *inner_ofst = arg->inner_ofst;
378         const struct rte_flow_item_ipv4 *spec = item->spec;
379         const struct rte_flow_item_ipv4 *mask = item->mask;
380         struct filter_ipv4_5tuple *enic_5tup = &enic_filter->u.ipv4;
381         struct ipv4_hdr supported_mask = {
382                 .src_addr = 0xffffffff,
383                 .dst_addr = 0xffffffff,
384         };
385
386         FLOW_TRACE();
387
388         if (*inner_ofst)
389                 return ENOTSUP;
390
391         if (!mask)
392                 mask = &rte_flow_item_ipv4_mask;
393
394         /* This is an exact match filter, both fields must be set */
395         if (!spec || !spec->hdr.src_addr || !spec->hdr.dst_addr) {
396                 FLOW_LOG(ERR, "IPv4 exact match src/dst addr");
397                 return ENOTSUP;
398         }
399
400         /* check that the suppied mask exactly matches capabilty */
401         if (!mask_exact_match((const u8 *)&supported_mask,
402                               (const u8 *)item->mask, sizeof(*mask))) {
403                 FLOW_LOG(ERR, "IPv4 exact match mask");
404                 return ENOTSUP;
405         }
406
407         enic_filter->u.ipv4.flags = FILTER_FIELDS_IPV4_5TUPLE;
408         enic_5tup->src_addr = spec->hdr.src_addr;
409         enic_5tup->dst_addr = spec->hdr.dst_addr;
410
411         return 0;
412 }
413
414 static int
415 enic_copy_item_udp_v1(struct copy_item_args *arg)
416 {
417         const struct rte_flow_item *item = arg->item;
418         struct filter_v2 *enic_filter = arg->filter;
419         uint8_t *inner_ofst = arg->inner_ofst;
420         const struct rte_flow_item_udp *spec = item->spec;
421         const struct rte_flow_item_udp *mask = item->mask;
422         struct filter_ipv4_5tuple *enic_5tup = &enic_filter->u.ipv4;
423         struct udp_hdr supported_mask = {
424                 .src_port = 0xffff,
425                 .dst_port = 0xffff,
426         };
427
428         FLOW_TRACE();
429
430         if (*inner_ofst)
431                 return ENOTSUP;
432
433         if (!mask)
434                 mask = &rte_flow_item_udp_mask;
435
436         /* This is an exact match filter, both ports must be set */
437         if (!spec || !spec->hdr.src_port || !spec->hdr.dst_port) {
438                 FLOW_LOG(ERR, "UDP exact match src/dst addr");
439                 return ENOTSUP;
440         }
441
442         /* check that the suppied mask exactly matches capabilty */
443         if (!mask_exact_match((const u8 *)&supported_mask,
444                               (const u8 *)item->mask, sizeof(*mask))) {
445                 FLOW_LOG(ERR, "UDP exact match mask");
446                 return ENOTSUP;
447         }
448
449         enic_filter->u.ipv4.flags = FILTER_FIELDS_IPV4_5TUPLE;
450         enic_5tup->src_port = spec->hdr.src_port;
451         enic_5tup->dst_port = spec->hdr.dst_port;
452         enic_5tup->protocol = PROTO_UDP;
453
454         return 0;
455 }
456
457 static int
458 enic_copy_item_tcp_v1(struct copy_item_args *arg)
459 {
460         const struct rte_flow_item *item = arg->item;
461         struct filter_v2 *enic_filter = arg->filter;
462         uint8_t *inner_ofst = arg->inner_ofst;
463         const struct rte_flow_item_tcp *spec = item->spec;
464         const struct rte_flow_item_tcp *mask = item->mask;
465         struct filter_ipv4_5tuple *enic_5tup = &enic_filter->u.ipv4;
466         struct tcp_hdr supported_mask = {
467                 .src_port = 0xffff,
468                 .dst_port = 0xffff,
469         };
470
471         FLOW_TRACE();
472
473         if (*inner_ofst)
474                 return ENOTSUP;
475
476         if (!mask)
477                 mask = &rte_flow_item_tcp_mask;
478
479         /* This is an exact match filter, both ports must be set */
480         if (!spec || !spec->hdr.src_port || !spec->hdr.dst_port) {
481                 FLOW_LOG(ERR, "TCPIPv4 exact match src/dst addr");
482                 return ENOTSUP;
483         }
484
485         /* check that the suppied mask exactly matches capabilty */
486         if (!mask_exact_match((const u8 *)&supported_mask,
487                              (const u8 *)item->mask, sizeof(*mask))) {
488                 FLOW_LOG(ERR, "TCP exact match mask");
489                 return ENOTSUP;
490         }
491
492         enic_filter->u.ipv4.flags = FILTER_FIELDS_IPV4_5TUPLE;
493         enic_5tup->src_port = spec->hdr.src_port;
494         enic_5tup->dst_port = spec->hdr.dst_port;
495         enic_5tup->protocol = PROTO_TCP;
496
497         return 0;
498 }
499
500 static int
501 enic_copy_item_eth_v2(struct copy_item_args *arg)
502 {
503         const struct rte_flow_item *item = arg->item;
504         struct filter_v2 *enic_filter = arg->filter;
505         uint8_t *inner_ofst = arg->inner_ofst;
506         struct ether_hdr enic_spec;
507         struct ether_hdr enic_mask;
508         const struct rte_flow_item_eth *spec = item->spec;
509         const struct rte_flow_item_eth *mask = item->mask;
510         struct filter_generic_1 *gp = &enic_filter->u.generic_1;
511
512         FLOW_TRACE();
513
514         /* Match all if no spec */
515         if (!spec)
516                 return 0;
517
518         if (!mask)
519                 mask = &rte_flow_item_eth_mask;
520
521         memcpy(enic_spec.d_addr.addr_bytes, spec->dst.addr_bytes,
522                ETHER_ADDR_LEN);
523         memcpy(enic_spec.s_addr.addr_bytes, spec->src.addr_bytes,
524                ETHER_ADDR_LEN);
525
526         memcpy(enic_mask.d_addr.addr_bytes, mask->dst.addr_bytes,
527                ETHER_ADDR_LEN);
528         memcpy(enic_mask.s_addr.addr_bytes, mask->src.addr_bytes,
529                ETHER_ADDR_LEN);
530         enic_spec.ether_type = spec->type;
531         enic_mask.ether_type = mask->type;
532
533         if (*inner_ofst == 0) {
534                 /* outer header */
535                 memcpy(gp->layer[FILTER_GENERIC_1_L2].mask, &enic_mask,
536                        sizeof(struct ether_hdr));
537                 memcpy(gp->layer[FILTER_GENERIC_1_L2].val, &enic_spec,
538                        sizeof(struct ether_hdr));
539         } else {
540                 /* inner header */
541                 if ((*inner_ofst + sizeof(struct ether_hdr)) >
542                      FILTER_GENERIC_1_KEY_LEN)
543                         return ENOTSUP;
544                 /* Offset into L5 where inner Ethernet header goes */
545                 memcpy(&gp->layer[FILTER_GENERIC_1_L5].mask[*inner_ofst],
546                        &enic_mask, sizeof(struct ether_hdr));
547                 memcpy(&gp->layer[FILTER_GENERIC_1_L5].val[*inner_ofst],
548                        &enic_spec, sizeof(struct ether_hdr));
549                 *inner_ofst += sizeof(struct ether_hdr);
550         }
551         return 0;
552 }
553
554 static int
555 enic_copy_item_vlan_v2(struct copy_item_args *arg)
556 {
557         const struct rte_flow_item *item = arg->item;
558         struct filter_v2 *enic_filter = arg->filter;
559         uint8_t *inner_ofst = arg->inner_ofst;
560         const struct rte_flow_item_vlan *spec = item->spec;
561         const struct rte_flow_item_vlan *mask = item->mask;
562         struct filter_generic_1 *gp = &enic_filter->u.generic_1;
563
564         FLOW_TRACE();
565
566         /* Match all if no spec */
567         if (!spec)
568                 return 0;
569
570         if (!mask)
571                 mask = &rte_flow_item_vlan_mask;
572
573         if (*inner_ofst == 0) {
574                 struct ether_hdr *eth_mask =
575                         (void *)gp->layer[FILTER_GENERIC_1_L2].mask;
576                 struct ether_hdr *eth_val =
577                         (void *)gp->layer[FILTER_GENERIC_1_L2].val;
578
579                 /* Outer TPID cannot be matched */
580                 if (eth_mask->ether_type)
581                         return ENOTSUP;
582                 eth_mask->ether_type = mask->inner_type;
583                 eth_val->ether_type = spec->inner_type;
584
585                 /* Outer header. Use the vlan mask/val fields */
586                 gp->mask_vlan = mask->tci;
587                 gp->val_vlan = spec->tci;
588         } else {
589                 /* Inner header. Mask/Val start at *inner_ofst into L5 */
590                 if ((*inner_ofst + sizeof(struct vlan_hdr)) >
591                      FILTER_GENERIC_1_KEY_LEN)
592                         return ENOTSUP;
593                 memcpy(&gp->layer[FILTER_GENERIC_1_L5].mask[*inner_ofst],
594                        mask, sizeof(struct vlan_hdr));
595                 memcpy(&gp->layer[FILTER_GENERIC_1_L5].val[*inner_ofst],
596                        spec, sizeof(struct vlan_hdr));
597                 *inner_ofst += sizeof(struct vlan_hdr);
598         }
599         return 0;
600 }
601
602 static int
603 enic_copy_item_ipv4_v2(struct copy_item_args *arg)
604 {
605         const struct rte_flow_item *item = arg->item;
606         struct filter_v2 *enic_filter = arg->filter;
607         uint8_t *inner_ofst = arg->inner_ofst;
608         const struct rte_flow_item_ipv4 *spec = item->spec;
609         const struct rte_flow_item_ipv4 *mask = item->mask;
610         struct filter_generic_1 *gp = &enic_filter->u.generic_1;
611
612         FLOW_TRACE();
613
614         if (*inner_ofst == 0) {
615                 /* Match IPv4 */
616                 gp->mask_flags |= FILTER_GENERIC_1_IPV4;
617                 gp->val_flags |= FILTER_GENERIC_1_IPV4;
618
619                 /* Match all if no spec */
620                 if (!spec)
621                         return 0;
622
623                 if (!mask)
624                         mask = &rte_flow_item_ipv4_mask;
625
626                 memcpy(gp->layer[FILTER_GENERIC_1_L3].mask, &mask->hdr,
627                        sizeof(struct ipv4_hdr));
628                 memcpy(gp->layer[FILTER_GENERIC_1_L3].val, &spec->hdr,
629                        sizeof(struct ipv4_hdr));
630         } else {
631                 /* Inner IPv4 header. Mask/Val start at *inner_ofst into L5 */
632                 if ((*inner_ofst + sizeof(struct ipv4_hdr)) >
633                      FILTER_GENERIC_1_KEY_LEN)
634                         return ENOTSUP;
635                 memcpy(&gp->layer[FILTER_GENERIC_1_L5].mask[*inner_ofst],
636                        mask, sizeof(struct ipv4_hdr));
637                 memcpy(&gp->layer[FILTER_GENERIC_1_L5].val[*inner_ofst],
638                        spec, sizeof(struct ipv4_hdr));
639                 *inner_ofst += sizeof(struct ipv4_hdr);
640         }
641         return 0;
642 }
643
644 static int
645 enic_copy_item_ipv6_v2(struct copy_item_args *arg)
646 {
647         const struct rte_flow_item *item = arg->item;
648         struct filter_v2 *enic_filter = arg->filter;
649         uint8_t *inner_ofst = arg->inner_ofst;
650         const struct rte_flow_item_ipv6 *spec = item->spec;
651         const struct rte_flow_item_ipv6 *mask = item->mask;
652         struct filter_generic_1 *gp = &enic_filter->u.generic_1;
653
654         FLOW_TRACE();
655
656         /* Match IPv6 */
657         gp->mask_flags |= FILTER_GENERIC_1_IPV6;
658         gp->val_flags |= FILTER_GENERIC_1_IPV6;
659
660         /* Match all if no spec */
661         if (!spec)
662                 return 0;
663
664         if (!mask)
665                 mask = &rte_flow_item_ipv6_mask;
666
667         if (*inner_ofst == 0) {
668                 memcpy(gp->layer[FILTER_GENERIC_1_L3].mask, &mask->hdr,
669                        sizeof(struct ipv6_hdr));
670                 memcpy(gp->layer[FILTER_GENERIC_1_L3].val, &spec->hdr,
671                        sizeof(struct ipv6_hdr));
672         } else {
673                 /* Inner IPv6 header. Mask/Val start at *inner_ofst into L5 */
674                 if ((*inner_ofst + sizeof(struct ipv6_hdr)) >
675                      FILTER_GENERIC_1_KEY_LEN)
676                         return ENOTSUP;
677                 memcpy(&gp->layer[FILTER_GENERIC_1_L5].mask[*inner_ofst],
678                        mask, sizeof(struct ipv6_hdr));
679                 memcpy(&gp->layer[FILTER_GENERIC_1_L5].val[*inner_ofst],
680                        spec, sizeof(struct ipv6_hdr));
681                 *inner_ofst += sizeof(struct ipv6_hdr);
682         }
683         return 0;
684 }
685
686 static int
687 enic_copy_item_udp_v2(struct copy_item_args *arg)
688 {
689         const struct rte_flow_item *item = arg->item;
690         struct filter_v2 *enic_filter = arg->filter;
691         uint8_t *inner_ofst = arg->inner_ofst;
692         const struct rte_flow_item_udp *spec = item->spec;
693         const struct rte_flow_item_udp *mask = item->mask;
694         struct filter_generic_1 *gp = &enic_filter->u.generic_1;
695
696         FLOW_TRACE();
697
698         /* Match UDP */
699         gp->mask_flags |= FILTER_GENERIC_1_UDP;
700         gp->val_flags |= FILTER_GENERIC_1_UDP;
701
702         /* Match all if no spec */
703         if (!spec)
704                 return 0;
705
706         if (!mask)
707                 mask = &rte_flow_item_udp_mask;
708
709         if (*inner_ofst == 0) {
710                 memcpy(gp->layer[FILTER_GENERIC_1_L4].mask, &mask->hdr,
711                        sizeof(struct udp_hdr));
712                 memcpy(gp->layer[FILTER_GENERIC_1_L4].val, &spec->hdr,
713                        sizeof(struct udp_hdr));
714         } else {
715                 /* Inner IPv6 header. Mask/Val start at *inner_ofst into L5 */
716                 if ((*inner_ofst + sizeof(struct udp_hdr)) >
717                      FILTER_GENERIC_1_KEY_LEN)
718                         return ENOTSUP;
719                 memcpy(&gp->layer[FILTER_GENERIC_1_L5].mask[*inner_ofst],
720                        mask, sizeof(struct udp_hdr));
721                 memcpy(&gp->layer[FILTER_GENERIC_1_L5].val[*inner_ofst],
722                        spec, sizeof(struct udp_hdr));
723                 *inner_ofst += sizeof(struct udp_hdr);
724         }
725         return 0;
726 }
727
728 static int
729 enic_copy_item_tcp_v2(struct copy_item_args *arg)
730 {
731         const struct rte_flow_item *item = arg->item;
732         struct filter_v2 *enic_filter = arg->filter;
733         uint8_t *inner_ofst = arg->inner_ofst;
734         const struct rte_flow_item_tcp *spec = item->spec;
735         const struct rte_flow_item_tcp *mask = item->mask;
736         struct filter_generic_1 *gp = &enic_filter->u.generic_1;
737
738         FLOW_TRACE();
739
740         /* Match TCP */
741         gp->mask_flags |= FILTER_GENERIC_1_TCP;
742         gp->val_flags |= FILTER_GENERIC_1_TCP;
743
744         /* Match all if no spec */
745         if (!spec)
746                 return 0;
747
748         if (!mask)
749                 return ENOTSUP;
750
751         if (*inner_ofst == 0) {
752                 memcpy(gp->layer[FILTER_GENERIC_1_L4].mask, &mask->hdr,
753                        sizeof(struct tcp_hdr));
754                 memcpy(gp->layer[FILTER_GENERIC_1_L4].val, &spec->hdr,
755                        sizeof(struct tcp_hdr));
756         } else {
757                 /* Inner IPv6 header. Mask/Val start at *inner_ofst into L5 */
758                 if ((*inner_ofst + sizeof(struct tcp_hdr)) >
759                      FILTER_GENERIC_1_KEY_LEN)
760                         return ENOTSUP;
761                 memcpy(&gp->layer[FILTER_GENERIC_1_L5].mask[*inner_ofst],
762                        mask, sizeof(struct tcp_hdr));
763                 memcpy(&gp->layer[FILTER_GENERIC_1_L5].val[*inner_ofst],
764                        spec, sizeof(struct tcp_hdr));
765                 *inner_ofst += sizeof(struct tcp_hdr);
766         }
767         return 0;
768 }
769
770 static int
771 enic_copy_item_sctp_v2(struct copy_item_args *arg)
772 {
773         const struct rte_flow_item *item = arg->item;
774         struct filter_v2 *enic_filter = arg->filter;
775         uint8_t *inner_ofst = arg->inner_ofst;
776         const struct rte_flow_item_sctp *spec = item->spec;
777         const struct rte_flow_item_sctp *mask = item->mask;
778         struct filter_generic_1 *gp = &enic_filter->u.generic_1;
779         uint8_t *ip_proto_mask = NULL;
780         uint8_t *ip_proto = NULL;
781
782         FLOW_TRACE();
783
784         if (*inner_ofst)
785                 return ENOTSUP;
786
787         /*
788          * The NIC filter API has no flags for "match sctp", so explicitly set
789          * the protocol number in the IP pattern.
790          */
791         if (gp->val_flags & FILTER_GENERIC_1_IPV4) {
792                 struct ipv4_hdr *ip;
793                 ip = (struct ipv4_hdr *)gp->layer[FILTER_GENERIC_1_L3].mask;
794                 ip_proto_mask = &ip->next_proto_id;
795                 ip = (struct ipv4_hdr *)gp->layer[FILTER_GENERIC_1_L3].val;
796                 ip_proto = &ip->next_proto_id;
797         } else if (gp->val_flags & FILTER_GENERIC_1_IPV6) {
798                 struct ipv6_hdr *ip;
799                 ip = (struct ipv6_hdr *)gp->layer[FILTER_GENERIC_1_L3].mask;
800                 ip_proto_mask = &ip->proto;
801                 ip = (struct ipv6_hdr *)gp->layer[FILTER_GENERIC_1_L3].val;
802                 ip_proto = &ip->proto;
803         } else {
804                 /* Need IPv4/IPv6 pattern first */
805                 return EINVAL;
806         }
807         *ip_proto = IPPROTO_SCTP;
808         *ip_proto_mask = 0xff;
809
810         /* Match all if no spec */
811         if (!spec)
812                 return 0;
813
814         if (!mask)
815                 mask = &rte_flow_item_sctp_mask;
816
817         memcpy(gp->layer[FILTER_GENERIC_1_L4].mask, &mask->hdr,
818                sizeof(struct sctp_hdr));
819         memcpy(gp->layer[FILTER_GENERIC_1_L4].val, &spec->hdr,
820                sizeof(struct sctp_hdr));
821         return 0;
822 }
823
824 static int
825 enic_copy_item_vxlan_v2(struct copy_item_args *arg)
826 {
827         const struct rte_flow_item *item = arg->item;
828         struct filter_v2 *enic_filter = arg->filter;
829         uint8_t *inner_ofst = arg->inner_ofst;
830         const struct rte_flow_item_vxlan *spec = item->spec;
831         const struct rte_flow_item_vxlan *mask = item->mask;
832         struct filter_generic_1 *gp = &enic_filter->u.generic_1;
833
834         FLOW_TRACE();
835
836         if (*inner_ofst)
837                 return EINVAL;
838
839         /* Match all if no spec */
840         if (!spec)
841                 return 0;
842
843         if (!mask)
844                 mask = &rte_flow_item_vxlan_mask;
845
846         memcpy(gp->layer[FILTER_GENERIC_1_L5].mask, mask,
847                sizeof(struct vxlan_hdr));
848         memcpy(gp->layer[FILTER_GENERIC_1_L5].val, spec,
849                sizeof(struct vxlan_hdr));
850
851         *inner_ofst = sizeof(struct vxlan_hdr);
852         return 0;
853 }
854
855 /*
856  * Copy raw item into version 2 NIC filter. Currently, raw pattern match is
857  * very limited. It is intended for matching UDP tunnel header (e.g. vxlan
858  * or geneve).
859  */
860 static int
861 enic_copy_item_raw_v2(struct copy_item_args *arg)
862 {
863         const struct rte_flow_item *item = arg->item;
864         struct filter_v2 *enic_filter = arg->filter;
865         uint8_t *inner_ofst = arg->inner_ofst;
866         const struct rte_flow_item_raw *spec = item->spec;
867         const struct rte_flow_item_raw *mask = item->mask;
868         struct filter_generic_1 *gp = &enic_filter->u.generic_1;
869
870         FLOW_TRACE();
871
872         /* Cannot be used for inner packet */
873         if (*inner_ofst)
874                 return EINVAL;
875         /* Need both spec and mask */
876         if (!spec || !mask)
877                 return EINVAL;
878         /* Only supports relative with offset 0 */
879         if (!spec->relative || spec->offset != 0 || spec->search || spec->limit)
880                 return EINVAL;
881         /* Need non-null pattern that fits within the NIC's filter pattern */
882         if (spec->length == 0 || spec->length > FILTER_GENERIC_1_KEY_LEN ||
883             !spec->pattern || !mask->pattern)
884                 return EINVAL;
885         /*
886          * Mask fields, including length, are often set to zero. Assume that
887          * means "same as spec" to avoid breaking existing apps. If length
888          * is not zero, then it should be >= spec length.
889          *
890          * No more pattern follows this, so append to the L4 layer instead of
891          * L5 to work with both recent and older VICs.
892          */
893         if (mask->length != 0 && mask->length < spec->length)
894                 return EINVAL;
895         memcpy(gp->layer[FILTER_GENERIC_1_L4].mask + sizeof(struct udp_hdr),
896                mask->pattern, spec->length);
897         memcpy(gp->layer[FILTER_GENERIC_1_L4].val + sizeof(struct udp_hdr),
898                spec->pattern, spec->length);
899
900         return 0;
901 }
902
903 /**
904  * Return 1 if current item is valid on top of the previous one.
905  *
906  * @param prev_item[in]
907  *   The item before this one in the pattern or RTE_FLOW_ITEM_TYPE_END if this
908  *   is the first item.
909  * @param item_info[in]
910  *   Info about this item, like valid previous items.
911  * @param is_first[in]
912  *   True if this the first item in the pattern.
913  */
914 static int
915 item_stacking_valid(enum rte_flow_item_type prev_item,
916                     const struct enic_items *item_info, u8 is_first_item)
917 {
918         enum rte_flow_item_type const *allowed_items = item_info->prev_items;
919
920         FLOW_TRACE();
921
922         for (; *allowed_items != RTE_FLOW_ITEM_TYPE_END; allowed_items++) {
923                 if (prev_item == *allowed_items)
924                         return 1;
925         }
926
927         /* This is the first item in the stack. Check if that's cool */
928         if (is_first_item && item_info->valid_start_item)
929                 return 1;
930
931         return 0;
932 }
933
934 /**
935  * Build the intenal enic filter structure from the provided pattern. The
936  * pattern is validated as the items are copied.
937  *
938  * @param pattern[in]
939  * @param items_info[in]
940  *   Info about this NICs item support, like valid previous items.
941  * @param enic_filter[out]
942  *   NIC specfilc filters derived from the pattern.
943  * @param error[out]
944  */
945 static int
946 enic_copy_filter(const struct rte_flow_item pattern[],
947                  const struct enic_filter_cap *cap,
948                  struct filter_v2 *enic_filter,
949                  struct rte_flow_error *error)
950 {
951         int ret;
952         const struct rte_flow_item *item = pattern;
953         u8 inner_ofst = 0; /* If encapsulated, ofst into L5 */
954         enum rte_flow_item_type prev_item;
955         const struct enic_items *item_info;
956         struct copy_item_args args;
957         u8 is_first_item = 1;
958
959         FLOW_TRACE();
960
961         prev_item = 0;
962
963         args.filter = enic_filter;
964         args.inner_ofst = &inner_ofst;
965         for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
966                 /* Get info about how to validate and copy the item. If NULL
967                  * is returned the nic does not support the item.
968                  */
969                 if (item->type == RTE_FLOW_ITEM_TYPE_VOID)
970                         continue;
971
972                 item_info = &cap->item_info[item->type];
973                 if (item->type > cap->max_item_type ||
974                     item_info->copy_item == NULL) {
975                         rte_flow_error_set(error, ENOTSUP,
976                                 RTE_FLOW_ERROR_TYPE_ITEM,
977                                 NULL, "Unsupported item.");
978                         return -rte_errno;
979                 }
980
981                 /* check to see if item stacking is valid */
982                 if (!item_stacking_valid(prev_item, item_info, is_first_item))
983                         goto stacking_error;
984
985                 args.item = item;
986                 ret = item_info->copy_item(&args);
987                 if (ret)
988                         goto item_not_supported;
989                 prev_item = item->type;
990                 is_first_item = 0;
991         }
992         return 0;
993
994 item_not_supported:
995         rte_flow_error_set(error, ret, RTE_FLOW_ERROR_TYPE_ITEM,
996                            NULL, "enic type error");
997         return -rte_errno;
998
999 stacking_error:
1000         rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM,
1001                            item, "stacking error");
1002         return -rte_errno;
1003 }
1004
1005 /**
1006  * Build the intenal version 1 NIC action structure from the provided pattern.
1007  * The pattern is validated as the items are copied.
1008  *
1009  * @param actions[in]
1010  * @param enic_action[out]
1011  *   NIC specfilc actions derived from the actions.
1012  * @param error[out]
1013  */
1014 static int
1015 enic_copy_action_v1(__rte_unused struct enic *enic,
1016                     const struct rte_flow_action actions[],
1017                     struct filter_action_v2 *enic_action)
1018 {
1019         enum { FATE = 1, };
1020         uint32_t overlap = 0;
1021
1022         FLOW_TRACE();
1023
1024         for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
1025                 if (actions->type == RTE_FLOW_ACTION_TYPE_VOID)
1026                         continue;
1027
1028                 switch (actions->type) {
1029                 case RTE_FLOW_ACTION_TYPE_QUEUE: {
1030                         const struct rte_flow_action_queue *queue =
1031                                 (const struct rte_flow_action_queue *)
1032                                 actions->conf;
1033
1034                         if (overlap & FATE)
1035                                 return ENOTSUP;
1036                         overlap |= FATE;
1037                         enic_action->rq_idx =
1038                                 enic_rte_rq_idx_to_sop_idx(queue->index);
1039                         break;
1040                 }
1041                 default:
1042                         RTE_ASSERT(0);
1043                         break;
1044                 }
1045         }
1046         if (!(overlap & FATE))
1047                 return ENOTSUP;
1048         enic_action->type = FILTER_ACTION_RQ_STEERING;
1049         return 0;
1050 }
1051
1052 /**
1053  * Build the intenal version 2 NIC action structure from the provided pattern.
1054  * The pattern is validated as the items are copied.
1055  *
1056  * @param actions[in]
1057  * @param enic_action[out]
1058  *   NIC specfilc actions derived from the actions.
1059  * @param error[out]
1060  */
1061 static int
1062 enic_copy_action_v2(struct enic *enic,
1063                     const struct rte_flow_action actions[],
1064                     struct filter_action_v2 *enic_action)
1065 {
1066         enum { FATE = 1, MARK = 2, };
1067         uint32_t overlap = 0;
1068         bool passthru = false;
1069
1070         FLOW_TRACE();
1071
1072         for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
1073                 switch (actions->type) {
1074                 case RTE_FLOW_ACTION_TYPE_QUEUE: {
1075                         const struct rte_flow_action_queue *queue =
1076                                 (const struct rte_flow_action_queue *)
1077                                 actions->conf;
1078
1079                         if (overlap & FATE)
1080                                 return ENOTSUP;
1081                         overlap |= FATE;
1082                         enic_action->rq_idx =
1083                                 enic_rte_rq_idx_to_sop_idx(queue->index);
1084                         enic_action->flags |= FILTER_ACTION_RQ_STEERING_FLAG;
1085                         break;
1086                 }
1087                 case RTE_FLOW_ACTION_TYPE_MARK: {
1088                         const struct rte_flow_action_mark *mark =
1089                                 (const struct rte_flow_action_mark *)
1090                                 actions->conf;
1091
1092                         if (overlap & MARK)
1093                                 return ENOTSUP;
1094                         overlap |= MARK;
1095                         /*
1096                          * Map mark ID (32-bit) to filter ID (16-bit):
1097                          * - Reject values > 16 bits
1098                          * - Filter ID 0 is reserved for filters that steer
1099                          *   but not mark. So add 1 to the mark ID to avoid
1100                          *   using 0.
1101                          * - Filter ID (ENIC_MAGIC_FILTER_ID = 0xffff) is
1102                          *   reserved for the "flag" action below.
1103                          */
1104                         if (mark->id >= ENIC_MAGIC_FILTER_ID - 1)
1105                                 return EINVAL;
1106                         enic_action->filter_id = mark->id + 1;
1107                         enic_action->flags |= FILTER_ACTION_FILTER_ID_FLAG;
1108                         break;
1109                 }
1110                 case RTE_FLOW_ACTION_TYPE_FLAG: {
1111                         if (overlap & MARK)
1112                                 return ENOTSUP;
1113                         overlap |= MARK;
1114                         /* ENIC_MAGIC_FILTER_ID is reserved for flagging */
1115                         enic_action->filter_id = ENIC_MAGIC_FILTER_ID;
1116                         enic_action->flags |= FILTER_ACTION_FILTER_ID_FLAG;
1117                         break;
1118                 }
1119                 case RTE_FLOW_ACTION_TYPE_DROP: {
1120                         if (overlap & FATE)
1121                                 return ENOTSUP;
1122                         overlap |= FATE;
1123                         enic_action->flags |= FILTER_ACTION_DROP_FLAG;
1124                         break;
1125                 }
1126                 case RTE_FLOW_ACTION_TYPE_COUNT: {
1127                         enic_action->flags |= FILTER_ACTION_COUNTER_FLAG;
1128                         break;
1129                 }
1130                 case RTE_FLOW_ACTION_TYPE_RSS: {
1131                         const struct rte_flow_action_rss *rss =
1132                                 (const struct rte_flow_action_rss *)
1133                                 actions->conf;
1134                         bool allow;
1135                         uint16_t i;
1136
1137                         /*
1138                          * Hardware does not support general RSS actions, but
1139                          * we can still support the dummy one that is used to
1140                          * "receive normally".
1141                          */
1142                         allow = rss->func == RTE_ETH_HASH_FUNCTION_DEFAULT &&
1143                                 rss->level == 0 &&
1144                                 (rss->types == 0 ||
1145                                  rss->types == enic->rss_hf) &&
1146                                 rss->queue_num == enic->rq_count &&
1147                                 rss->key_len == 0;
1148                         /* Identity queue map is ok */
1149                         for (i = 0; i < rss->queue_num; i++)
1150                                 allow = allow && (i == rss->queue[i]);
1151                         if (!allow)
1152                                 return ENOTSUP;
1153                         if (overlap & FATE)
1154                                 return ENOTSUP;
1155                         /* Need MARK or FLAG */
1156                         if (!(overlap & MARK))
1157                                 return ENOTSUP;
1158                         overlap |= FATE;
1159                         break;
1160                 }
1161                 case RTE_FLOW_ACTION_TYPE_PASSTHRU: {
1162                         /*
1163                          * Like RSS above, PASSTHRU + MARK may be used to
1164                          * "mark and then receive normally". MARK usually comes
1165                          * after PASSTHRU, so remember we have seen passthru
1166                          * and check for mark later.
1167                          */
1168                         if (overlap & FATE)
1169                                 return ENOTSUP;
1170                         overlap |= FATE;
1171                         passthru = true;
1172                         break;
1173                 }
1174                 case RTE_FLOW_ACTION_TYPE_VOID:
1175                         continue;
1176                 default:
1177                         RTE_ASSERT(0);
1178                         break;
1179                 }
1180         }
1181         /* Only PASSTHRU + MARK is allowed */
1182         if (passthru && !(overlap & MARK))
1183                 return ENOTSUP;
1184         if (!(overlap & FATE))
1185                 return ENOTSUP;
1186         enic_action->type = FILTER_ACTION_V2;
1187         return 0;
1188 }
1189
1190 /** Check if the action is supported */
1191 static int
1192 enic_match_action(const struct rte_flow_action *action,
1193                   const enum rte_flow_action_type *supported_actions)
1194 {
1195         for (; *supported_actions != RTE_FLOW_ACTION_TYPE_END;
1196              supported_actions++) {
1197                 if (action->type == *supported_actions)
1198                         return 1;
1199         }
1200         return 0;
1201 }
1202
1203 /** Get the NIC filter capabilties structure */
1204 static const struct enic_filter_cap *
1205 enic_get_filter_cap(struct enic *enic)
1206 {
1207         if (enic->flow_filter_mode)
1208                 return &enic_filter_cap[enic->flow_filter_mode];
1209
1210         return NULL;
1211 }
1212
1213 /** Get the actions for this NIC version. */
1214 static const struct enic_action_cap *
1215 enic_get_action_cap(struct enic *enic)
1216 {
1217         const struct enic_action_cap *ea;
1218         uint8_t actions;
1219
1220         actions = enic->filter_actions;
1221         if (actions & FILTER_ACTION_COUNTER_FLAG)
1222                 ea = &enic_action_cap[FILTER_ACTION_COUNTER_FLAG];
1223         else if (actions & FILTER_ACTION_DROP_FLAG)
1224                 ea = &enic_action_cap[FILTER_ACTION_DROP_FLAG];
1225         else if (actions & FILTER_ACTION_FILTER_ID_FLAG)
1226                 ea = &enic_action_cap[FILTER_ACTION_FILTER_ID_FLAG];
1227         else
1228                 ea = &enic_action_cap[FILTER_ACTION_RQ_STEERING_FLAG];
1229         return ea;
1230 }
1231
1232 /* Debug function to dump internal NIC action structure. */
1233 static void
1234 enic_dump_actions(const struct filter_action_v2 *ea)
1235 {
1236         if (ea->type == FILTER_ACTION_RQ_STEERING) {
1237                 FLOW_LOG(INFO, "Action(V1), queue: %u\n", ea->rq_idx);
1238         } else if (ea->type == FILTER_ACTION_V2) {
1239                 FLOW_LOG(INFO, "Actions(V2)\n");
1240                 if (ea->flags & FILTER_ACTION_RQ_STEERING_FLAG)
1241                         FLOW_LOG(INFO, "\tqueue: %u\n",
1242                                enic_sop_rq_idx_to_rte_idx(ea->rq_idx));
1243                 if (ea->flags & FILTER_ACTION_FILTER_ID_FLAG)
1244                         FLOW_LOG(INFO, "\tfilter_id: %u\n", ea->filter_id);
1245         }
1246 }
1247
1248 /* Debug function to dump internal NIC filter structure. */
1249 static void
1250 enic_dump_filter(const struct filter_v2 *filt)
1251 {
1252         const struct filter_generic_1 *gp;
1253         int i, j, mbyte;
1254         char buf[128], *bp;
1255         char ip4[16], ip6[16], udp[16], tcp[16], tcpudp[16], ip4csum[16];
1256         char l4csum[16], ipfrag[16];
1257
1258         switch (filt->type) {
1259         case FILTER_IPV4_5TUPLE:
1260                 FLOW_LOG(INFO, "FILTER_IPV4_5TUPLE\n");
1261                 break;
1262         case FILTER_USNIC_IP:
1263         case FILTER_DPDK_1:
1264                 /* FIXME: this should be a loop */
1265                 gp = &filt->u.generic_1;
1266                 FLOW_LOG(INFO, "Filter: vlan: 0x%04x, mask: 0x%04x\n",
1267                        gp->val_vlan, gp->mask_vlan);
1268
1269                 if (gp->mask_flags & FILTER_GENERIC_1_IPV4)
1270                         sprintf(ip4, "%s ",
1271                                 (gp->val_flags & FILTER_GENERIC_1_IPV4)
1272                                  ? "ip4(y)" : "ip4(n)");
1273                 else
1274                         sprintf(ip4, "%s ", "ip4(x)");
1275
1276                 if (gp->mask_flags & FILTER_GENERIC_1_IPV6)
1277                         sprintf(ip6, "%s ",
1278                                 (gp->val_flags & FILTER_GENERIC_1_IPV4)
1279                                  ? "ip6(y)" : "ip6(n)");
1280                 else
1281                         sprintf(ip6, "%s ", "ip6(x)");
1282
1283                 if (gp->mask_flags & FILTER_GENERIC_1_UDP)
1284                         sprintf(udp, "%s ",
1285                                 (gp->val_flags & FILTER_GENERIC_1_UDP)
1286                                  ? "udp(y)" : "udp(n)");
1287                 else
1288                         sprintf(udp, "%s ", "udp(x)");
1289
1290                 if (gp->mask_flags & FILTER_GENERIC_1_TCP)
1291                         sprintf(tcp, "%s ",
1292                                 (gp->val_flags & FILTER_GENERIC_1_TCP)
1293                                  ? "tcp(y)" : "tcp(n)");
1294                 else
1295                         sprintf(tcp, "%s ", "tcp(x)");
1296
1297                 if (gp->mask_flags & FILTER_GENERIC_1_TCP_OR_UDP)
1298                         sprintf(tcpudp, "%s ",
1299                                 (gp->val_flags & FILTER_GENERIC_1_TCP_OR_UDP)
1300                                  ? "tcpudp(y)" : "tcpudp(n)");
1301                 else
1302                         sprintf(tcpudp, "%s ", "tcpudp(x)");
1303
1304                 if (gp->mask_flags & FILTER_GENERIC_1_IP4SUM_OK)
1305                         sprintf(ip4csum, "%s ",
1306                                 (gp->val_flags & FILTER_GENERIC_1_IP4SUM_OK)
1307                                  ? "ip4csum(y)" : "ip4csum(n)");
1308                 else
1309                         sprintf(ip4csum, "%s ", "ip4csum(x)");
1310
1311                 if (gp->mask_flags & FILTER_GENERIC_1_L4SUM_OK)
1312                         sprintf(l4csum, "%s ",
1313                                 (gp->val_flags & FILTER_GENERIC_1_L4SUM_OK)
1314                                  ? "l4csum(y)" : "l4csum(n)");
1315                 else
1316                         sprintf(l4csum, "%s ", "l4csum(x)");
1317
1318                 if (gp->mask_flags & FILTER_GENERIC_1_IPFRAG)
1319                         sprintf(ipfrag, "%s ",
1320                                 (gp->val_flags & FILTER_GENERIC_1_IPFRAG)
1321                                  ? "ipfrag(y)" : "ipfrag(n)");
1322                 else
1323                         sprintf(ipfrag, "%s ", "ipfrag(x)");
1324                 FLOW_LOG(INFO, "\tFlags: %s%s%s%s%s%s%s%s\n", ip4, ip6, udp,
1325                          tcp, tcpudp, ip4csum, l4csum, ipfrag);
1326
1327                 for (i = 0; i < FILTER_GENERIC_1_NUM_LAYERS; i++) {
1328                         mbyte = FILTER_GENERIC_1_KEY_LEN - 1;
1329                         while (mbyte && !gp->layer[i].mask[mbyte])
1330                                 mbyte--;
1331                         if (mbyte == 0)
1332                                 continue;
1333
1334                         bp = buf;
1335                         for (j = 0; j <= mbyte; j++) {
1336                                 sprintf(bp, "%02x",
1337                                         gp->layer[i].mask[j]);
1338                                 bp += 2;
1339                         }
1340                         *bp = '\0';
1341                         FLOW_LOG(INFO, "\tL%u mask: %s\n", i + 2, buf);
1342                         bp = buf;
1343                         for (j = 0; j <= mbyte; j++) {
1344                                 sprintf(bp, "%02x",
1345                                         gp->layer[i].val[j]);
1346                                 bp += 2;
1347                         }
1348                         *bp = '\0';
1349                         FLOW_LOG(INFO, "\tL%u  val: %s\n", i + 2, buf);
1350                 }
1351                 break;
1352         default:
1353                 FLOW_LOG(INFO, "FILTER UNKNOWN\n");
1354                 break;
1355         }
1356 }
1357
1358 /* Debug function to dump internal NIC flow structures. */
1359 static void
1360 enic_dump_flow(const struct filter_action_v2 *ea, const struct filter_v2 *filt)
1361 {
1362         enic_dump_filter(filt);
1363         enic_dump_actions(ea);
1364 }
1365
1366
1367 /**
1368  * Internal flow parse/validate function.
1369  *
1370  * @param dev[in]
1371  *   This device pointer.
1372  * @param pattern[in]
1373  * @param actions[in]
1374  * @param error[out]
1375  * @param enic_filter[out]
1376  *   Internal NIC filter structure pointer.
1377  * @param enic_action[out]
1378  *   Internal NIC action structure pointer.
1379  */
1380 static int
1381 enic_flow_parse(struct rte_eth_dev *dev,
1382                 const struct rte_flow_attr *attrs,
1383                 const struct rte_flow_item pattern[],
1384                 const struct rte_flow_action actions[],
1385                 struct rte_flow_error *error,
1386                 struct filter_v2 *enic_filter,
1387                 struct filter_action_v2 *enic_action)
1388 {
1389         unsigned int ret = 0;
1390         struct enic *enic = pmd_priv(dev);
1391         const struct enic_filter_cap *enic_filter_cap;
1392         const struct enic_action_cap *enic_action_cap;
1393         const struct rte_flow_action *action;
1394
1395         FLOW_TRACE();
1396
1397         memset(enic_filter, 0, sizeof(*enic_filter));
1398         memset(enic_action, 0, sizeof(*enic_action));
1399
1400         if (!pattern) {
1401                 rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM_NUM,
1402                                    NULL, "No pattern specified");
1403                 return -rte_errno;
1404         }
1405
1406         if (!actions) {
1407                 rte_flow_error_set(error, EINVAL,
1408                                    RTE_FLOW_ERROR_TYPE_ACTION_NUM,
1409                                    NULL, "No action specified");
1410                 return -rte_errno;
1411         }
1412
1413         if (attrs) {
1414                 if (attrs->group) {
1415                         rte_flow_error_set(error, ENOTSUP,
1416                                            RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
1417                                            NULL,
1418                                            "priority groups are not supported");
1419                         return -rte_errno;
1420                 } else if (attrs->priority) {
1421                         rte_flow_error_set(error, ENOTSUP,
1422                                            RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1423                                            NULL,
1424                                            "priorities are not supported");
1425                         return -rte_errno;
1426                 } else if (attrs->egress) {
1427                         rte_flow_error_set(error, ENOTSUP,
1428                                            RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
1429                                            NULL,
1430                                            "egress is not supported");
1431                         return -rte_errno;
1432                 } else if (attrs->transfer) {
1433                         rte_flow_error_set(error, ENOTSUP,
1434                                            RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1435                                            NULL,
1436                                            "transfer is not supported");
1437                         return -rte_errno;
1438                 } else if (!attrs->ingress) {
1439                         rte_flow_error_set(error, ENOTSUP,
1440                                            RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1441                                            NULL,
1442                                            "only ingress is supported");
1443                         return -rte_errno;
1444                 }
1445
1446         } else {
1447                 rte_flow_error_set(error, EINVAL,
1448                                    RTE_FLOW_ERROR_TYPE_ATTR,
1449                                    NULL, "No attribute specified");
1450                 return -rte_errno;
1451         }
1452
1453         /* Verify Actions. */
1454         enic_action_cap =  enic_get_action_cap(enic);
1455         for (action = &actions[0]; action->type != RTE_FLOW_ACTION_TYPE_END;
1456              action++) {
1457                 if (action->type == RTE_FLOW_ACTION_TYPE_VOID)
1458                         continue;
1459                 else if (!enic_match_action(action, enic_action_cap->actions))
1460                         break;
1461         }
1462         if (action->type != RTE_FLOW_ACTION_TYPE_END) {
1463                 rte_flow_error_set(error, EPERM, RTE_FLOW_ERROR_TYPE_ACTION,
1464                                    action, "Invalid action.");
1465                 return -rte_errno;
1466         }
1467         ret = enic_action_cap->copy_fn(enic, actions, enic_action);
1468         if (ret) {
1469                 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_HANDLE,
1470                            NULL, "Unsupported action.");
1471                 return -rte_errno;
1472         }
1473
1474         /* Verify Flow items. If copying the filter from flow format to enic
1475          * format fails, the flow is not supported
1476          */
1477         enic_filter_cap =  enic_get_filter_cap(enic);
1478         if (enic_filter_cap == NULL) {
1479                 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_HANDLE,
1480                            NULL, "Flow API not available");
1481                 return -rte_errno;
1482         }
1483         enic_filter->type = enic->flow_filter_mode;
1484         ret = enic_copy_filter(pattern, enic_filter_cap,
1485                                        enic_filter, error);
1486         return ret;
1487 }
1488
1489 /**
1490  * Push filter/action to the NIC.
1491  *
1492  * @param enic[in]
1493  *   Device structure pointer.
1494  * @param enic_filter[in]
1495  *   Internal NIC filter structure pointer.
1496  * @param enic_action[in]
1497  *   Internal NIC action structure pointer.
1498  * @param error[out]
1499  */
1500 static struct rte_flow *
1501 enic_flow_add_filter(struct enic *enic, struct filter_v2 *enic_filter,
1502                    struct filter_action_v2 *enic_action,
1503                    struct rte_flow_error *error)
1504 {
1505         struct rte_flow *flow;
1506         int err;
1507         uint16_t entry;
1508         int ctr_idx;
1509         int last_max_flow_ctr;
1510
1511         FLOW_TRACE();
1512
1513         flow = rte_calloc(__func__, 1, sizeof(*flow), 0);
1514         if (!flow) {
1515                 rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_HANDLE,
1516                                    NULL, "cannot allocate flow memory");
1517                 return NULL;
1518         }
1519
1520         flow->counter_idx = -1;
1521         last_max_flow_ctr = -1;
1522         if (enic_action->flags & FILTER_ACTION_COUNTER_FLAG) {
1523                 if (!vnic_dev_counter_alloc(enic->vdev, (uint32_t *)&ctr_idx)) {
1524                         rte_flow_error_set(error, ENOMEM,
1525                                            RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1526                                            NULL, "cannot allocate counter");
1527                         goto unwind_flow_alloc;
1528                 }
1529                 flow->counter_idx = ctr_idx;
1530                 enic_action->counter_index = ctr_idx;
1531
1532                 /* If index is the largest, increase the counter DMA size */
1533                 if (ctr_idx > enic->max_flow_counter) {
1534                         err = vnic_dev_counter_dma_cfg(enic->vdev,
1535                                                  VNIC_FLOW_COUNTER_UPDATE_MSECS,
1536                                                  ctr_idx + 1);
1537                         if (err) {
1538                                 rte_flow_error_set(error, -err,
1539                                            RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1540                                            NULL, "counter DMA config failed");
1541                                 goto unwind_ctr_alloc;
1542                         }
1543                         last_max_flow_ctr = enic->max_flow_counter;
1544                         enic->max_flow_counter = ctr_idx;
1545                 }
1546         }
1547
1548         /* entry[in] is the queue id, entry[out] is the filter Id for delete */
1549         entry = enic_action->rq_idx;
1550         err = vnic_dev_classifier(enic->vdev, CLSF_ADD, &entry, enic_filter,
1551                                   enic_action);
1552         if (err) {
1553                 rte_flow_error_set(error, -err, RTE_FLOW_ERROR_TYPE_HANDLE,
1554                                    NULL, "vnic_dev_classifier error");
1555                 goto unwind_ctr_dma_cfg;
1556         }
1557
1558         flow->enic_filter_id = entry;
1559         flow->enic_filter = *enic_filter;
1560
1561         return flow;
1562
1563 /* unwind if there are errors */
1564 unwind_ctr_dma_cfg:
1565         if (last_max_flow_ctr != -1) {
1566                 /* reduce counter DMA size */
1567                 vnic_dev_counter_dma_cfg(enic->vdev,
1568                                          VNIC_FLOW_COUNTER_UPDATE_MSECS,
1569                                          last_max_flow_ctr + 1);
1570                 enic->max_flow_counter = last_max_flow_ctr;
1571         }
1572 unwind_ctr_alloc:
1573         if (flow->counter_idx != -1)
1574                 vnic_dev_counter_free(enic->vdev, ctr_idx);
1575 unwind_flow_alloc:
1576         rte_free(flow);
1577         return NULL;
1578 }
1579
1580 /**
1581  * Remove filter/action from the NIC.
1582  *
1583  * @param enic[in]
1584  *   Device structure pointer.
1585  * @param filter_id[in]
1586  *   Id of NIC filter.
1587  * @param enic_action[in]
1588  *   Internal NIC action structure pointer.
1589  * @param error[out]
1590  */
1591 static int
1592 enic_flow_del_filter(struct enic *enic, struct rte_flow *flow,
1593                    struct rte_flow_error *error)
1594 {
1595         u16 filter_id;
1596         int err;
1597
1598         FLOW_TRACE();
1599
1600         filter_id = flow->enic_filter_id;
1601         err = vnic_dev_classifier(enic->vdev, CLSF_DEL, &filter_id, NULL, NULL);
1602         if (err) {
1603                 rte_flow_error_set(error, -err, RTE_FLOW_ERROR_TYPE_HANDLE,
1604                                    NULL, "vnic_dev_classifier failed");
1605                 return -err;
1606         }
1607
1608         if (flow->counter_idx != -1) {
1609                 if (!vnic_dev_counter_free(enic->vdev, flow->counter_idx))
1610                         dev_err(enic, "counter free failed, idx: %d\n",
1611                                 flow->counter_idx);
1612                 flow->counter_idx = -1;
1613         }
1614         return 0;
1615 }
1616
1617 /*
1618  * The following functions are callbacks for Generic flow API.
1619  */
1620
1621 /**
1622  * Validate a flow supported by the NIC.
1623  *
1624  * @see rte_flow_validate()
1625  * @see rte_flow_ops
1626  */
1627 static int
1628 enic_flow_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attrs,
1629                    const struct rte_flow_item pattern[],
1630                    const struct rte_flow_action actions[],
1631                    struct rte_flow_error *error)
1632 {
1633         struct filter_v2 enic_filter;
1634         struct filter_action_v2 enic_action;
1635         int ret;
1636
1637         FLOW_TRACE();
1638
1639         ret = enic_flow_parse(dev, attrs, pattern, actions, error,
1640                                &enic_filter, &enic_action);
1641         if (!ret)
1642                 enic_dump_flow(&enic_action, &enic_filter);
1643         return ret;
1644 }
1645
1646 /**
1647  * Create a flow supported by the NIC.
1648  *
1649  * @see rte_flow_create()
1650  * @see rte_flow_ops
1651  */
1652 static struct rte_flow *
1653 enic_flow_create(struct rte_eth_dev *dev,
1654                  const struct rte_flow_attr *attrs,
1655                  const struct rte_flow_item pattern[],
1656                  const struct rte_flow_action actions[],
1657                  struct rte_flow_error *error)
1658 {
1659         int ret;
1660         struct filter_v2 enic_filter;
1661         struct filter_action_v2 enic_action;
1662         struct rte_flow *flow;
1663         struct enic *enic = pmd_priv(dev);
1664
1665         FLOW_TRACE();
1666
1667         ret = enic_flow_parse(dev, attrs, pattern, actions, error, &enic_filter,
1668                               &enic_action);
1669         if (ret < 0)
1670                 return NULL;
1671
1672         rte_spinlock_lock(&enic->flows_lock);
1673         flow = enic_flow_add_filter(enic, &enic_filter, &enic_action,
1674                                     error);
1675         if (flow)
1676                 LIST_INSERT_HEAD(&enic->flows, flow, next);
1677         rte_spinlock_unlock(&enic->flows_lock);
1678
1679         return flow;
1680 }
1681
1682 /**
1683  * Destroy a flow supported by the NIC.
1684  *
1685  * @see rte_flow_destroy()
1686  * @see rte_flow_ops
1687  */
1688 static int
1689 enic_flow_destroy(struct rte_eth_dev *dev, struct rte_flow *flow,
1690                   __rte_unused struct rte_flow_error *error)
1691 {
1692         struct enic *enic = pmd_priv(dev);
1693
1694         FLOW_TRACE();
1695
1696         rte_spinlock_lock(&enic->flows_lock);
1697         enic_flow_del_filter(enic, flow, error);
1698         LIST_REMOVE(flow, next);
1699         rte_spinlock_unlock(&enic->flows_lock);
1700         rte_free(flow);
1701         return 0;
1702 }
1703
1704 /**
1705  * Flush all flows on the device.
1706  *
1707  * @see rte_flow_flush()
1708  * @see rte_flow_ops
1709  */
1710 static int
1711 enic_flow_flush(struct rte_eth_dev *dev, struct rte_flow_error *error)
1712 {
1713         struct rte_flow *flow;
1714         struct enic *enic = pmd_priv(dev);
1715
1716         FLOW_TRACE();
1717
1718         rte_spinlock_lock(&enic->flows_lock);
1719
1720         while (!LIST_EMPTY(&enic->flows)) {
1721                 flow = LIST_FIRST(&enic->flows);
1722                 enic_flow_del_filter(enic, flow, error);
1723                 LIST_REMOVE(flow, next);
1724                 rte_free(flow);
1725         }
1726         rte_spinlock_unlock(&enic->flows_lock);
1727         return 0;
1728 }
1729
1730 static int
1731 enic_flow_query_count(struct rte_eth_dev *dev,
1732                       struct rte_flow *flow, void *data,
1733                       struct rte_flow_error *error)
1734 {
1735         struct enic *enic = pmd_priv(dev);
1736         struct rte_flow_query_count *query;
1737         uint64_t packets, bytes;
1738
1739         FLOW_TRACE();
1740
1741         if (flow->counter_idx == -1) {
1742                 return rte_flow_error_set(error, ENOTSUP,
1743                                           RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1744                                           NULL,
1745                                           "flow does not have counter");
1746         }
1747         query = (struct rte_flow_query_count *)data;
1748         if (!vnic_dev_counter_query(enic->vdev, flow->counter_idx,
1749                                     !!query->reset, &packets, &bytes)) {
1750                 return rte_flow_error_set
1751                         (error, EINVAL,
1752                          RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1753                          NULL,
1754                          "cannot read counter");
1755         }
1756         query->hits_set = 1;
1757         query->bytes_set = 1;
1758         query->hits = packets;
1759         query->bytes = bytes;
1760         return 0;
1761 }
1762
1763 static int
1764 enic_flow_query(struct rte_eth_dev *dev,
1765                 struct rte_flow *flow,
1766                 const struct rte_flow_action *actions,
1767                 void *data,
1768                 struct rte_flow_error *error)
1769 {
1770         int ret = 0;
1771
1772         FLOW_TRACE();
1773
1774         for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
1775                 switch (actions->type) {
1776                 case RTE_FLOW_ACTION_TYPE_VOID:
1777                         break;
1778                 case RTE_FLOW_ACTION_TYPE_COUNT:
1779                         ret = enic_flow_query_count(dev, flow, data, error);
1780                         break;
1781                 default:
1782                         return rte_flow_error_set(error, ENOTSUP,
1783                                                   RTE_FLOW_ERROR_TYPE_ACTION,
1784                                                   actions,
1785                                                   "action not supported");
1786                 }
1787                 if (ret < 0)
1788                         return ret;
1789         }
1790         return 0;
1791 }
1792
1793 /**
1794  * Flow callback registration.
1795  *
1796  * @see rte_flow_ops
1797  */
1798 const struct rte_flow_ops enic_flow_ops = {
1799         .validate = enic_flow_validate,
1800         .create = enic_flow_create,
1801         .destroy = enic_flow_destroy,
1802         .flush = enic_flow_flush,
1803         .query = enic_flow_query,
1804 };