net/mlx5: fix verification of mark action
[dpdk.git] / drivers / net / mlx5 / mlx5_flow.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright 2016 6WIND S.A.
5  *   Copyright 2016 Mellanox.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of 6WIND S.A. nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #include <sys/queue.h>
35 #include <string.h>
36
37 /* Verbs header. */
38 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
39 #ifdef PEDANTIC
40 #pragma GCC diagnostic ignored "-Wpedantic"
41 #endif
42 #include <infiniband/verbs.h>
43 #ifdef PEDANTIC
44 #pragma GCC diagnostic error "-Wpedantic"
45 #endif
46
47 #include <rte_ethdev.h>
48 #include <rte_flow.h>
49 #include <rte_flow_driver.h>
50 #include <rte_malloc.h>
51
52 #include "mlx5.h"
53 #include "mlx5_prm.h"
54
55 static int
56 mlx5_flow_create_eth(const struct rte_flow_item *item,
57                      const void *default_mask,
58                      void *data);
59
60 static int
61 mlx5_flow_create_vlan(const struct rte_flow_item *item,
62                       const void *default_mask,
63                       void *data);
64
65 static int
66 mlx5_flow_create_ipv4(const struct rte_flow_item *item,
67                       const void *default_mask,
68                       void *data);
69
70 static int
71 mlx5_flow_create_ipv6(const struct rte_flow_item *item,
72                       const void *default_mask,
73                       void *data);
74
75 static int
76 mlx5_flow_create_udp(const struct rte_flow_item *item,
77                      const void *default_mask,
78                      void *data);
79
80 static int
81 mlx5_flow_create_tcp(const struct rte_flow_item *item,
82                      const void *default_mask,
83                      void *data);
84
85 static int
86 mlx5_flow_create_vxlan(const struct rte_flow_item *item,
87                        const void *default_mask,
88                        void *data);
89
90 struct rte_flow {
91         LIST_ENTRY(rte_flow) next; /**< Pointer to the next flow structure. */
92         struct ibv_exp_flow_attr *ibv_attr; /**< Pointer to Verbs attributes. */
93         struct ibv_exp_rwq_ind_table *ind_table; /**< Indirection table. */
94         struct ibv_qp *qp; /**< Verbs queue pair. */
95         struct ibv_exp_flow *ibv_flow; /**< Verbs flow. */
96         struct ibv_exp_wq *wq; /**< Verbs work queue. */
97         struct ibv_cq *cq; /**< Verbs completion queue. */
98         struct rxq *rxq; /**< Pointer to the queue, NULL if drop queue. */
99         uint32_t mark:1; /**< Set if the flow is marked. */
100 };
101
102 /** Static initializer for items. */
103 #define ITEMS(...) \
104         (const enum rte_flow_item_type []){ \
105                 __VA_ARGS__, RTE_FLOW_ITEM_TYPE_END, \
106         }
107
108 /** Structure to generate a simple graph of layers supported by the NIC. */
109 struct mlx5_flow_items {
110         /** List of possible actions for these items. */
111         const enum rte_flow_action_type *const actions;
112         /** Bit-masks corresponding to the possibilities for the item. */
113         const void *mask;
114         /**
115          * Default bit-masks to use when item->mask is not provided. When
116          * \default_mask is also NULL, the full supported bit-mask (\mask) is
117          * used instead.
118          */
119         const void *default_mask;
120         /** Bit-masks size in bytes. */
121         const unsigned int mask_sz;
122         /**
123          * Conversion function from rte_flow to NIC specific flow.
124          *
125          * @param item
126          *   rte_flow item to convert.
127          * @param default_mask
128          *   Default bit-masks to use when item->mask is not provided.
129          * @param data
130          *   Internal structure to store the conversion.
131          *
132          * @return
133          *   0 on success, negative value otherwise.
134          */
135         int (*convert)(const struct rte_flow_item *item,
136                        const void *default_mask,
137                        void *data);
138         /** Size in bytes of the destination structure. */
139         const unsigned int dst_sz;
140         /** List of possible following items.  */
141         const enum rte_flow_item_type *const items;
142 };
143
144 /** Valid action for this PMD. */
145 static const enum rte_flow_action_type valid_actions[] = {
146         RTE_FLOW_ACTION_TYPE_DROP,
147         RTE_FLOW_ACTION_TYPE_QUEUE,
148         RTE_FLOW_ACTION_TYPE_MARK,
149         RTE_FLOW_ACTION_TYPE_END,
150 };
151
152 /** Graph of supported items and associated actions. */
153 static const struct mlx5_flow_items mlx5_flow_items[] = {
154         [RTE_FLOW_ITEM_TYPE_END] = {
155                 .items = ITEMS(RTE_FLOW_ITEM_TYPE_ETH,
156                                RTE_FLOW_ITEM_TYPE_VXLAN),
157         },
158         [RTE_FLOW_ITEM_TYPE_ETH] = {
159                 .items = ITEMS(RTE_FLOW_ITEM_TYPE_VLAN,
160                                RTE_FLOW_ITEM_TYPE_IPV4,
161                                RTE_FLOW_ITEM_TYPE_IPV6),
162                 .actions = valid_actions,
163                 .mask = &(const struct rte_flow_item_eth){
164                         .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
165                         .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
166                 },
167                 .default_mask = &rte_flow_item_eth_mask,
168                 .mask_sz = sizeof(struct rte_flow_item_eth),
169                 .convert = mlx5_flow_create_eth,
170                 .dst_sz = sizeof(struct ibv_exp_flow_spec_eth),
171         },
172         [RTE_FLOW_ITEM_TYPE_VLAN] = {
173                 .items = ITEMS(RTE_FLOW_ITEM_TYPE_IPV4,
174                                RTE_FLOW_ITEM_TYPE_IPV6),
175                 .actions = valid_actions,
176                 .mask = &(const struct rte_flow_item_vlan){
177                         .tci = -1,
178                 },
179                 .default_mask = &rte_flow_item_vlan_mask,
180                 .mask_sz = sizeof(struct rte_flow_item_vlan),
181                 .convert = mlx5_flow_create_vlan,
182                 .dst_sz = 0,
183         },
184         [RTE_FLOW_ITEM_TYPE_IPV4] = {
185                 .items = ITEMS(RTE_FLOW_ITEM_TYPE_UDP,
186                                RTE_FLOW_ITEM_TYPE_TCP),
187                 .actions = valid_actions,
188                 .mask = &(const struct rte_flow_item_ipv4){
189                         .hdr = {
190                                 .src_addr = -1,
191                                 .dst_addr = -1,
192                                 .type_of_service = -1,
193                                 .next_proto_id = -1,
194                         },
195                 },
196                 .default_mask = &rte_flow_item_ipv4_mask,
197                 .mask_sz = sizeof(struct rte_flow_item_ipv4),
198                 .convert = mlx5_flow_create_ipv4,
199                 .dst_sz = sizeof(struct ibv_exp_flow_spec_ipv4_ext),
200         },
201         [RTE_FLOW_ITEM_TYPE_IPV6] = {
202                 .items = ITEMS(RTE_FLOW_ITEM_TYPE_UDP,
203                                RTE_FLOW_ITEM_TYPE_TCP),
204                 .actions = valid_actions,
205                 .mask = &(const struct rte_flow_item_ipv6){
206                         .hdr = {
207                                 .src_addr = {
208                                         0xff, 0xff, 0xff, 0xff,
209                                         0xff, 0xff, 0xff, 0xff,
210                                         0xff, 0xff, 0xff, 0xff,
211                                         0xff, 0xff, 0xff, 0xff,
212                                 },
213                                 .dst_addr = {
214                                         0xff, 0xff, 0xff, 0xff,
215                                         0xff, 0xff, 0xff, 0xff,
216                                         0xff, 0xff, 0xff, 0xff,
217                                         0xff, 0xff, 0xff, 0xff,
218                                 },
219                         },
220                 },
221                 .default_mask = &rte_flow_item_ipv6_mask,
222                 .mask_sz = sizeof(struct rte_flow_item_ipv6),
223                 .convert = mlx5_flow_create_ipv6,
224                 .dst_sz = sizeof(struct ibv_exp_flow_spec_ipv6),
225         },
226         [RTE_FLOW_ITEM_TYPE_UDP] = {
227                 .items = ITEMS(RTE_FLOW_ITEM_TYPE_VXLAN),
228                 .actions = valid_actions,
229                 .mask = &(const struct rte_flow_item_udp){
230                         .hdr = {
231                                 .src_port = -1,
232                                 .dst_port = -1,
233                         },
234                 },
235                 .default_mask = &rte_flow_item_udp_mask,
236                 .mask_sz = sizeof(struct rte_flow_item_udp),
237                 .convert = mlx5_flow_create_udp,
238                 .dst_sz = sizeof(struct ibv_exp_flow_spec_tcp_udp),
239         },
240         [RTE_FLOW_ITEM_TYPE_TCP] = {
241                 .actions = valid_actions,
242                 .mask = &(const struct rte_flow_item_tcp){
243                         .hdr = {
244                                 .src_port = -1,
245                                 .dst_port = -1,
246                         },
247                 },
248                 .default_mask = &rte_flow_item_tcp_mask,
249                 .mask_sz = sizeof(struct rte_flow_item_tcp),
250                 .convert = mlx5_flow_create_tcp,
251                 .dst_sz = sizeof(struct ibv_exp_flow_spec_tcp_udp),
252         },
253         [RTE_FLOW_ITEM_TYPE_VXLAN] = {
254                 .items = ITEMS(RTE_FLOW_ITEM_TYPE_ETH),
255                 .actions = valid_actions,
256                 .mask = &(const struct rte_flow_item_vxlan){
257                         .vni = "\xff\xff\xff",
258                 },
259                 .default_mask = &rte_flow_item_vxlan_mask,
260                 .mask_sz = sizeof(struct rte_flow_item_vxlan),
261                 .convert = mlx5_flow_create_vxlan,
262                 .dst_sz = sizeof(struct ibv_exp_flow_spec_tunnel),
263         },
264 };
265
266 /** Structure to pass to the conversion function. */
267 struct mlx5_flow {
268         struct ibv_exp_flow_attr *ibv_attr; /**< Verbs attribute. */
269         unsigned int offset; /**< Offset in bytes in the ibv_attr buffer. */
270         uint32_t inner; /**< Set once VXLAN is encountered. */
271 };
272
273 struct mlx5_flow_action {
274         uint32_t queue:1; /**< Target is a receive queue. */
275         uint32_t drop:1; /**< Target is a drop queue. */
276         uint32_t mark:1; /**< Mark is present in the flow. */
277         uint32_t queue_id; /**< Identifier of the queue. */
278         uint32_t mark_id; /**< Mark identifier. */
279 };
280
281 /**
282  * Check support for a given item.
283  *
284  * @param item[in]
285  *   Item specification.
286  * @param mask[in]
287  *   Bit-masks covering supported fields to compare with spec, last and mask in
288  *   \item.
289  * @param size
290  *   Bit-Mask size in bytes.
291  *
292  * @return
293  *   0 on success.
294  */
295 static int
296 mlx5_flow_item_validate(const struct rte_flow_item *item,
297                         const uint8_t *mask, unsigned int size)
298 {
299         int ret = 0;
300
301         if (!item->spec && (item->mask || item->last))
302                 return -1;
303         if (item->spec && !item->mask) {
304                 unsigned int i;
305                 const uint8_t *spec = item->spec;
306
307                 for (i = 0; i < size; ++i)
308                         if ((spec[i] | mask[i]) != mask[i])
309                                 return -1;
310         }
311         if (item->last && !item->mask) {
312                 unsigned int i;
313                 const uint8_t *spec = item->last;
314
315                 for (i = 0; i < size; ++i)
316                         if ((spec[i] | mask[i]) != mask[i])
317                                 return -1;
318         }
319         if (item->mask) {
320                 unsigned int i;
321                 const uint8_t *spec = item->mask;
322
323                 for (i = 0; i < size; ++i)
324                         if ((spec[i] | mask[i]) != mask[i])
325                                 return -1;
326         }
327         if (item->spec && item->last) {
328                 uint8_t spec[size];
329                 uint8_t last[size];
330                 const uint8_t *apply = mask;
331                 unsigned int i;
332
333                 if (item->mask)
334                         apply = item->mask;
335                 for (i = 0; i < size; ++i) {
336                         spec[i] = ((const uint8_t *)item->spec)[i] & apply[i];
337                         last[i] = ((const uint8_t *)item->last)[i] & apply[i];
338                 }
339                 ret = memcmp(spec, last, size);
340         }
341         return ret;
342 }
343
344 /**
345  * Validate a flow supported by the NIC.
346  *
347  * @param priv
348  *   Pointer to private structure.
349  * @param[in] attr
350  *   Flow rule attributes.
351  * @param[in] pattern
352  *   Pattern specification (list terminated by the END pattern item).
353  * @param[in] actions
354  *   Associated actions (list terminated by the END action).
355  * @param[out] error
356  *   Perform verbose error reporting if not NULL.
357  * @param[in, out] flow
358  *   Flow structure to update.
359  *
360  * @return
361  *   0 on success, a negative errno value otherwise and rte_errno is set.
362  */
363 static int
364 priv_flow_validate(struct priv *priv,
365                    const struct rte_flow_attr *attr,
366                    const struct rte_flow_item items[],
367                    const struct rte_flow_action actions[],
368                    struct rte_flow_error *error,
369                    struct mlx5_flow *flow)
370 {
371         const struct mlx5_flow_items *cur_item = mlx5_flow_items;
372         struct mlx5_flow_action action = {
373                 .queue = 0,
374                 .drop = 0,
375                 .mark = 0,
376         };
377
378         (void)priv;
379         if (attr->group) {
380                 rte_flow_error_set(error, ENOTSUP,
381                                    RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
382                                    NULL,
383                                    "groups are not supported");
384                 return -rte_errno;
385         }
386         if (attr->priority) {
387                 rte_flow_error_set(error, ENOTSUP,
388                                    RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
389                                    NULL,
390                                    "priorities are not supported");
391                 return -rte_errno;
392         }
393         if (attr->egress) {
394                 rte_flow_error_set(error, ENOTSUP,
395                                    RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
396                                    NULL,
397                                    "egress is not supported");
398                 return -rte_errno;
399         }
400         if (!attr->ingress) {
401                 rte_flow_error_set(error, ENOTSUP,
402                                    RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
403                                    NULL,
404                                    "only ingress is supported");
405                 return -rte_errno;
406         }
407         for (; items->type != RTE_FLOW_ITEM_TYPE_END; ++items) {
408                 const struct mlx5_flow_items *token = NULL;
409                 unsigned int i;
410                 int err;
411
412                 if (items->type == RTE_FLOW_ITEM_TYPE_VOID)
413                         continue;
414                 for (i = 0;
415                      cur_item->items &&
416                      cur_item->items[i] != RTE_FLOW_ITEM_TYPE_END;
417                      ++i) {
418                         if (cur_item->items[i] == items->type) {
419                                 token = &mlx5_flow_items[items->type];
420                                 break;
421                         }
422                 }
423                 if (!token)
424                         goto exit_item_not_supported;
425                 cur_item = token;
426                 err = mlx5_flow_item_validate(items,
427                                               (const uint8_t *)cur_item->mask,
428                                               cur_item->mask_sz);
429                 if (err)
430                         goto exit_item_not_supported;
431                 if (flow->ibv_attr && cur_item->convert) {
432                         err = cur_item->convert(items,
433                                                 (cur_item->default_mask ?
434                                                  cur_item->default_mask :
435                                                  cur_item->mask),
436                                                 flow);
437                         if (err)
438                                 goto exit_item_not_supported;
439                 }
440                 flow->offset += cur_item->dst_sz;
441         }
442         for (; actions->type != RTE_FLOW_ACTION_TYPE_END; ++actions) {
443                 if (actions->type == RTE_FLOW_ACTION_TYPE_VOID) {
444                         continue;
445                 } else if (actions->type == RTE_FLOW_ACTION_TYPE_DROP) {
446                         action.drop = 1;
447                 } else if (actions->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
448                         const struct rte_flow_action_queue *queue =
449                                 (const struct rte_flow_action_queue *)
450                                 actions->conf;
451
452                         if (!queue || (queue->index > (priv->rxqs_n - 1)))
453                                 goto exit_action_not_supported;
454                         action.queue = 1;
455                 } else if (actions->type == RTE_FLOW_ACTION_TYPE_MARK) {
456                         const struct rte_flow_action_mark *mark =
457                                 (const struct rte_flow_action_mark *)
458                                 actions->conf;
459
460                         if (!mark) {
461                                 rte_flow_error_set(error, EINVAL,
462                                                    RTE_FLOW_ERROR_TYPE_ACTION,
463                                                    actions,
464                                                    "mark must be defined");
465                                 return -rte_errno;
466                         } else if (mark->id >= MLX5_FLOW_MARK_MAX) {
467                                 rte_flow_error_set(error, ENOTSUP,
468                                                    RTE_FLOW_ERROR_TYPE_ACTION,
469                                                    actions,
470                                                    "mark must be between 0"
471                                                    " and 16777199");
472                                 return -rte_errno;
473                         }
474                         action.mark = 1;
475                 } else {
476                         goto exit_action_not_supported;
477                 }
478         }
479         if (action.mark && !flow->ibv_attr && !action.drop)
480                 flow->offset += sizeof(struct ibv_exp_flow_spec_action_tag);
481         if (!action.queue && !action.drop) {
482                 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_HANDLE,
483                                    NULL, "no valid action");
484                 return -rte_errno;
485         }
486         return 0;
487 exit_item_not_supported:
488         rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM,
489                            items, "item not supported");
490         return -rte_errno;
491 exit_action_not_supported:
492         rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
493                            actions, "action not supported");
494         return -rte_errno;
495 }
496
497 /**
498  * Validate a flow supported by the NIC.
499  *
500  * @see rte_flow_validate()
501  * @see rte_flow_ops
502  */
503 int
504 mlx5_flow_validate(struct rte_eth_dev *dev,
505                    const struct rte_flow_attr *attr,
506                    const struct rte_flow_item items[],
507                    const struct rte_flow_action actions[],
508                    struct rte_flow_error *error)
509 {
510         struct priv *priv = dev->data->dev_private;
511         int ret;
512         struct mlx5_flow flow = { .offset = sizeof(struct ibv_exp_flow_attr) };
513
514         priv_lock(priv);
515         ret = priv_flow_validate(priv, attr, items, actions, error, &flow);
516         priv_unlock(priv);
517         return ret;
518 }
519
520 /**
521  * Convert Ethernet item to Verbs specification.
522  *
523  * @param item[in]
524  *   Item specification.
525  * @param default_mask[in]
526  *   Default bit-masks to use when item->mask is not provided.
527  * @param data[in, out]
528  *   User structure.
529  */
530 static int
531 mlx5_flow_create_eth(const struct rte_flow_item *item,
532                      const void *default_mask,
533                      void *data)
534 {
535         const struct rte_flow_item_eth *spec = item->spec;
536         const struct rte_flow_item_eth *mask = item->mask;
537         struct mlx5_flow *flow = (struct mlx5_flow *)data;
538         struct ibv_exp_flow_spec_eth *eth;
539         const unsigned int eth_size = sizeof(struct ibv_exp_flow_spec_eth);
540         unsigned int i;
541
542         ++flow->ibv_attr->num_of_specs;
543         flow->ibv_attr->priority = 2;
544         eth = (void *)((uintptr_t)flow->ibv_attr + flow->offset);
545         *eth = (struct ibv_exp_flow_spec_eth) {
546                 .type = flow->inner | IBV_EXP_FLOW_SPEC_ETH,
547                 .size = eth_size,
548         };
549         if (!spec)
550                 return 0;
551         if (!mask)
552                 mask = default_mask;
553         memcpy(eth->val.dst_mac, spec->dst.addr_bytes, ETHER_ADDR_LEN);
554         memcpy(eth->val.src_mac, spec->src.addr_bytes, ETHER_ADDR_LEN);
555         memcpy(eth->mask.dst_mac, mask->dst.addr_bytes, ETHER_ADDR_LEN);
556         memcpy(eth->mask.src_mac, mask->src.addr_bytes, ETHER_ADDR_LEN);
557         /* Remove unwanted bits from values. */
558         for (i = 0; i < ETHER_ADDR_LEN; ++i) {
559                 eth->val.dst_mac[i] &= eth->mask.dst_mac[i];
560                 eth->val.src_mac[i] &= eth->mask.src_mac[i];
561         }
562         return 0;
563 }
564
565 /**
566  * Convert VLAN item to Verbs specification.
567  *
568  * @param item[in]
569  *   Item specification.
570  * @param default_mask[in]
571  *   Default bit-masks to use when item->mask is not provided.
572  * @param data[in, out]
573  *   User structure.
574  */
575 static int
576 mlx5_flow_create_vlan(const struct rte_flow_item *item,
577                       const void *default_mask,
578                       void *data)
579 {
580         const struct rte_flow_item_vlan *spec = item->spec;
581         const struct rte_flow_item_vlan *mask = item->mask;
582         struct mlx5_flow *flow = (struct mlx5_flow *)data;
583         struct ibv_exp_flow_spec_eth *eth;
584         const unsigned int eth_size = sizeof(struct ibv_exp_flow_spec_eth);
585
586         eth = (void *)((uintptr_t)flow->ibv_attr + flow->offset - eth_size);
587         if (!spec)
588                 return 0;
589         if (!mask)
590                 mask = default_mask;
591         eth->val.vlan_tag = spec->tci;
592         eth->mask.vlan_tag = mask->tci;
593         eth->val.vlan_tag &= eth->mask.vlan_tag;
594         return 0;
595 }
596
597 /**
598  * Convert IPv4 item to Verbs specification.
599  *
600  * @param item[in]
601  *   Item specification.
602  * @param default_mask[in]
603  *   Default bit-masks to use when item->mask is not provided.
604  * @param data[in, out]
605  *   User structure.
606  */
607 static int
608 mlx5_flow_create_ipv4(const struct rte_flow_item *item,
609                       const void *default_mask,
610                       void *data)
611 {
612         const struct rte_flow_item_ipv4 *spec = item->spec;
613         const struct rte_flow_item_ipv4 *mask = item->mask;
614         struct mlx5_flow *flow = (struct mlx5_flow *)data;
615         struct ibv_exp_flow_spec_ipv4_ext *ipv4;
616         unsigned int ipv4_size = sizeof(struct ibv_exp_flow_spec_ipv4_ext);
617
618         ++flow->ibv_attr->num_of_specs;
619         flow->ibv_attr->priority = 1;
620         ipv4 = (void *)((uintptr_t)flow->ibv_attr + flow->offset);
621         *ipv4 = (struct ibv_exp_flow_spec_ipv4_ext) {
622                 .type = flow->inner | IBV_EXP_FLOW_SPEC_IPV4_EXT,
623                 .size = ipv4_size,
624         };
625         if (!spec)
626                 return 0;
627         if (!mask)
628                 mask = default_mask;
629         ipv4->val = (struct ibv_exp_flow_ipv4_ext_filter){
630                 .src_ip = spec->hdr.src_addr,
631                 .dst_ip = spec->hdr.dst_addr,
632                 .proto = spec->hdr.next_proto_id,
633                 .tos = spec->hdr.type_of_service,
634         };
635         ipv4->mask = (struct ibv_exp_flow_ipv4_ext_filter){
636                 .src_ip = mask->hdr.src_addr,
637                 .dst_ip = mask->hdr.dst_addr,
638                 .proto = mask->hdr.next_proto_id,
639                 .tos = mask->hdr.type_of_service,
640         };
641         /* Remove unwanted bits from values. */
642         ipv4->val.src_ip &= ipv4->mask.src_ip;
643         ipv4->val.dst_ip &= ipv4->mask.dst_ip;
644         ipv4->val.proto &= ipv4->mask.proto;
645         ipv4->val.tos &= ipv4->mask.tos;
646         return 0;
647 }
648
649 /**
650  * Convert IPv6 item to Verbs specification.
651  *
652  * @param item[in]
653  *   Item specification.
654  * @param default_mask[in]
655  *   Default bit-masks to use when item->mask is not provided.
656  * @param data[in, out]
657  *   User structure.
658  */
659 static int
660 mlx5_flow_create_ipv6(const struct rte_flow_item *item,
661                       const void *default_mask,
662                       void *data)
663 {
664         const struct rte_flow_item_ipv6 *spec = item->spec;
665         const struct rte_flow_item_ipv6 *mask = item->mask;
666         struct mlx5_flow *flow = (struct mlx5_flow *)data;
667         struct ibv_exp_flow_spec_ipv6 *ipv6;
668         unsigned int ipv6_size = sizeof(struct ibv_exp_flow_spec_ipv6);
669         unsigned int i;
670
671         ++flow->ibv_attr->num_of_specs;
672         flow->ibv_attr->priority = 1;
673         ipv6 = (void *)((uintptr_t)flow->ibv_attr + flow->offset);
674         *ipv6 = (struct ibv_exp_flow_spec_ipv6) {
675                 .type = flow->inner | IBV_EXP_FLOW_SPEC_IPV6,
676                 .size = ipv6_size,
677         };
678         if (!spec)
679                 return 0;
680         if (!mask)
681                 mask = default_mask;
682         memcpy(ipv6->val.src_ip, spec->hdr.src_addr,
683                RTE_DIM(ipv6->val.src_ip));
684         memcpy(ipv6->val.dst_ip, spec->hdr.dst_addr,
685                RTE_DIM(ipv6->val.dst_ip));
686         memcpy(ipv6->mask.src_ip, mask->hdr.src_addr,
687                RTE_DIM(ipv6->mask.src_ip));
688         memcpy(ipv6->mask.dst_ip, mask->hdr.dst_addr,
689                RTE_DIM(ipv6->mask.dst_ip));
690         /* Remove unwanted bits from values. */
691         for (i = 0; i < RTE_DIM(ipv6->val.src_ip); ++i) {
692                 ipv6->val.src_ip[i] &= ipv6->mask.src_ip[i];
693                 ipv6->val.dst_ip[i] &= ipv6->mask.dst_ip[i];
694         }
695         return 0;
696 }
697
698 /**
699  * Convert UDP item to Verbs specification.
700  *
701  * @param item[in]
702  *   Item specification.
703  * @param default_mask[in]
704  *   Default bit-masks to use when item->mask is not provided.
705  * @param data[in, out]
706  *   User structure.
707  */
708 static int
709 mlx5_flow_create_udp(const struct rte_flow_item *item,
710                      const void *default_mask,
711                      void *data)
712 {
713         const struct rte_flow_item_udp *spec = item->spec;
714         const struct rte_flow_item_udp *mask = item->mask;
715         struct mlx5_flow *flow = (struct mlx5_flow *)data;
716         struct ibv_exp_flow_spec_tcp_udp *udp;
717         unsigned int udp_size = sizeof(struct ibv_exp_flow_spec_tcp_udp);
718
719         ++flow->ibv_attr->num_of_specs;
720         flow->ibv_attr->priority = 0;
721         udp = (void *)((uintptr_t)flow->ibv_attr + flow->offset);
722         *udp = (struct ibv_exp_flow_spec_tcp_udp) {
723                 .type = flow->inner | IBV_EXP_FLOW_SPEC_UDP,
724                 .size = udp_size,
725         };
726         if (!spec)
727                 return 0;
728         if (!mask)
729                 mask = default_mask;
730         udp->val.dst_port = spec->hdr.dst_port;
731         udp->val.src_port = spec->hdr.src_port;
732         udp->mask.dst_port = mask->hdr.dst_port;
733         udp->mask.src_port = mask->hdr.src_port;
734         /* Remove unwanted bits from values. */
735         udp->val.src_port &= udp->mask.src_port;
736         udp->val.dst_port &= udp->mask.dst_port;
737         return 0;
738 }
739
740 /**
741  * Convert TCP item to Verbs specification.
742  *
743  * @param item[in]
744  *   Item specification.
745  * @param default_mask[in]
746  *   Default bit-masks to use when item->mask is not provided.
747  * @param data[in, out]
748  *   User structure.
749  */
750 static int
751 mlx5_flow_create_tcp(const struct rte_flow_item *item,
752                      const void *default_mask,
753                      void *data)
754 {
755         const struct rte_flow_item_tcp *spec = item->spec;
756         const struct rte_flow_item_tcp *mask = item->mask;
757         struct mlx5_flow *flow = (struct mlx5_flow *)data;
758         struct ibv_exp_flow_spec_tcp_udp *tcp;
759         unsigned int tcp_size = sizeof(struct ibv_exp_flow_spec_tcp_udp);
760
761         ++flow->ibv_attr->num_of_specs;
762         flow->ibv_attr->priority = 0;
763         tcp = (void *)((uintptr_t)flow->ibv_attr + flow->offset);
764         *tcp = (struct ibv_exp_flow_spec_tcp_udp) {
765                 .type = flow->inner | IBV_EXP_FLOW_SPEC_TCP,
766                 .size = tcp_size,
767         };
768         if (!spec)
769                 return 0;
770         if (!mask)
771                 mask = default_mask;
772         tcp->val.dst_port = spec->hdr.dst_port;
773         tcp->val.src_port = spec->hdr.src_port;
774         tcp->mask.dst_port = mask->hdr.dst_port;
775         tcp->mask.src_port = mask->hdr.src_port;
776         /* Remove unwanted bits from values. */
777         tcp->val.src_port &= tcp->mask.src_port;
778         tcp->val.dst_port &= tcp->mask.dst_port;
779         return 0;
780 }
781
782 /**
783  * Convert VXLAN item to Verbs specification.
784  *
785  * @param item[in]
786  *   Item specification.
787  * @param default_mask[in]
788  *   Default bit-masks to use when item->mask is not provided.
789  * @param data[in, out]
790  *   User structure.
791  */
792 static int
793 mlx5_flow_create_vxlan(const struct rte_flow_item *item,
794                        const void *default_mask,
795                        void *data)
796 {
797         const struct rte_flow_item_vxlan *spec = item->spec;
798         const struct rte_flow_item_vxlan *mask = item->mask;
799         struct mlx5_flow *flow = (struct mlx5_flow *)data;
800         struct ibv_exp_flow_spec_tunnel *vxlan;
801         unsigned int size = sizeof(struct ibv_exp_flow_spec_tunnel);
802         union vni {
803                 uint32_t vlan_id;
804                 uint8_t vni[4];
805         } id;
806
807         ++flow->ibv_attr->num_of_specs;
808         flow->ibv_attr->priority = 0;
809         id.vni[0] = 0;
810         vxlan = (void *)((uintptr_t)flow->ibv_attr + flow->offset);
811         *vxlan = (struct ibv_exp_flow_spec_tunnel) {
812                 .type = flow->inner | IBV_EXP_FLOW_SPEC_VXLAN_TUNNEL,
813                 .size = size,
814         };
815         flow->inner = IBV_EXP_FLOW_SPEC_INNER;
816         if (!spec)
817                 return 0;
818         if (!mask)
819                 mask = default_mask;
820         memcpy(&id.vni[1], spec->vni, 3);
821         vxlan->val.tunnel_id = id.vlan_id;
822         memcpy(&id.vni[1], mask->vni, 3);
823         vxlan->mask.tunnel_id = id.vlan_id;
824         /* Remove unwanted bits from values. */
825         vxlan->val.tunnel_id &= vxlan->mask.tunnel_id;
826         return 0;
827 }
828
829 /**
830  * Convert mark/flag action to Verbs specification.
831  *
832  * @param flow
833  *   Pointer to MLX5 flow structure.
834  * @param mark_id
835  *   Mark identifier.
836  */
837 static int
838 mlx5_flow_create_flag_mark(struct mlx5_flow *flow, uint32_t mark_id)
839 {
840         struct ibv_exp_flow_spec_action_tag *tag;
841         unsigned int size = sizeof(struct ibv_exp_flow_spec_action_tag);
842
843         tag = (void *)((uintptr_t)flow->ibv_attr + flow->offset);
844         *tag = (struct ibv_exp_flow_spec_action_tag){
845                 .type = IBV_EXP_FLOW_SPEC_ACTION_TAG,
846                 .size = size,
847                 .tag_id = mlx5_flow_mark_set(mark_id),
848         };
849         ++flow->ibv_attr->num_of_specs;
850         return 0;
851 }
852
853 /**
854  * Complete flow rule creation.
855  *
856  * @param priv
857  *   Pointer to private structure.
858  * @param ibv_attr
859  *   Verbs flow attributes.
860  * @param action
861  *   Target action structure.
862  * @param[out] error
863  *   Perform verbose error reporting if not NULL.
864  *
865  * @return
866  *   A flow if the rule could be created.
867  */
868 static struct rte_flow *
869 priv_flow_create_action_queue(struct priv *priv,
870                               struct ibv_exp_flow_attr *ibv_attr,
871                               struct mlx5_flow_action *action,
872                               struct rte_flow_error *error)
873 {
874         struct rxq_ctrl *rxq;
875         struct rte_flow *rte_flow;
876
877         assert(priv->pd);
878         assert(priv->ctx);
879         rte_flow = rte_calloc(__func__, 1, sizeof(*rte_flow), 0);
880         if (!rte_flow) {
881                 rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_HANDLE,
882                                    NULL, "cannot allocate flow memory");
883                 return NULL;
884         }
885         if (action->drop) {
886                 rte_flow->cq =
887                         ibv_exp_create_cq(priv->ctx, 1, NULL, NULL, 0,
888                                           &(struct ibv_exp_cq_init_attr){
889                                                   .comp_mask = 0,
890                                           });
891                 if (!rte_flow->cq) {
892                         rte_flow_error_set(error, ENOMEM,
893                                            RTE_FLOW_ERROR_TYPE_HANDLE,
894                                            NULL, "cannot allocate CQ");
895                         goto error;
896                 }
897                 rte_flow->wq = ibv_exp_create_wq(priv->ctx,
898                                                  &(struct ibv_exp_wq_init_attr){
899                                                  .wq_type = IBV_EXP_WQT_RQ,
900                                                  .max_recv_wr = 1,
901                                                  .max_recv_sge = 1,
902                                                  .pd = priv->pd,
903                                                  .cq = rte_flow->cq,
904                                                  });
905         } else {
906                 rxq = container_of((*priv->rxqs)[action->queue_id],
907                                    struct rxq_ctrl, rxq);
908                 rte_flow->rxq = &rxq->rxq;
909                 rxq->rxq.mark |= action->mark;
910                 rte_flow->wq = rxq->wq;
911         }
912         rte_flow->mark = action->mark;
913         rte_flow->ibv_attr = ibv_attr;
914         rte_flow->ind_table = ibv_exp_create_rwq_ind_table(
915                 priv->ctx,
916                 &(struct ibv_exp_rwq_ind_table_init_attr){
917                         .pd = priv->pd,
918                         .log_ind_tbl_size = 0,
919                         .ind_tbl = &rte_flow->wq,
920                         .comp_mask = 0,
921                 });
922         if (!rte_flow->ind_table) {
923                 rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_HANDLE,
924                                    NULL, "cannot allocate indirection table");
925                 goto error;
926         }
927         rte_flow->qp = ibv_exp_create_qp(
928                 priv->ctx,
929                 &(struct ibv_exp_qp_init_attr){
930                         .qp_type = IBV_QPT_RAW_PACKET,
931                         .comp_mask =
932                                 IBV_EXP_QP_INIT_ATTR_PD |
933                                 IBV_EXP_QP_INIT_ATTR_PORT |
934                                 IBV_EXP_QP_INIT_ATTR_RX_HASH,
935                         .pd = priv->pd,
936                         .rx_hash_conf = &(struct ibv_exp_rx_hash_conf){
937                                 .rx_hash_function =
938                                         IBV_EXP_RX_HASH_FUNC_TOEPLITZ,
939                                 .rx_hash_key_len = rss_hash_default_key_len,
940                                 .rx_hash_key = rss_hash_default_key,
941                                 .rx_hash_fields_mask = 0,
942                                 .rwq_ind_tbl = rte_flow->ind_table,
943                         },
944                         .port_num = priv->port,
945                 });
946         if (!rte_flow->qp) {
947                 rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_HANDLE,
948                                    NULL, "cannot allocate QP");
949                 goto error;
950         }
951         rte_flow->ibv_flow = ibv_exp_create_flow(rte_flow->qp,
952                                                  rte_flow->ibv_attr);
953         if (!rte_flow->ibv_flow) {
954                 rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_HANDLE,
955                                    NULL, "flow rule creation failure");
956                 goto error;
957         }
958         return rte_flow;
959 error:
960         assert(rte_flow);
961         if (rte_flow->qp)
962                 ibv_destroy_qp(rte_flow->qp);
963         if (rte_flow->ind_table)
964                 ibv_exp_destroy_rwq_ind_table(rte_flow->ind_table);
965         if (!rte_flow->rxq && rte_flow->wq)
966                 ibv_exp_destroy_wq(rte_flow->wq);
967         if (!rte_flow->rxq && rte_flow->cq)
968                 ibv_destroy_cq(rte_flow->cq);
969         rte_free(rte_flow->ibv_attr);
970         rte_free(rte_flow);
971         return NULL;
972 }
973
974 /**
975  * Convert a flow.
976  *
977  * @param priv
978  *   Pointer to private structure.
979  * @param[in] attr
980  *   Flow rule attributes.
981  * @param[in] pattern
982  *   Pattern specification (list terminated by the END pattern item).
983  * @param[in] actions
984  *   Associated actions (list terminated by the END action).
985  * @param[out] error
986  *   Perform verbose error reporting if not NULL.
987  *
988  * @return
989  *   A flow on success, NULL otherwise.
990  */
991 static struct rte_flow *
992 priv_flow_create(struct priv *priv,
993                  const struct rte_flow_attr *attr,
994                  const struct rte_flow_item items[],
995                  const struct rte_flow_action actions[],
996                  struct rte_flow_error *error)
997 {
998         struct rte_flow *rte_flow;
999         struct mlx5_flow_action action;
1000         struct mlx5_flow flow = { .offset = sizeof(struct ibv_exp_flow_attr), };
1001         int err;
1002
1003         err = priv_flow_validate(priv, attr, items, actions, error, &flow);
1004         if (err)
1005                 goto exit;
1006         flow.ibv_attr = rte_malloc(__func__, flow.offset, 0);
1007         flow.offset = sizeof(struct ibv_exp_flow_attr);
1008         if (!flow.ibv_attr) {
1009                 rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_HANDLE,
1010                                    NULL, "cannot allocate ibv_attr memory");
1011                 goto exit;
1012         }
1013         *flow.ibv_attr = (struct ibv_exp_flow_attr){
1014                 .type = IBV_EXP_FLOW_ATTR_NORMAL,
1015                 .size = sizeof(struct ibv_exp_flow_attr),
1016                 .priority = attr->priority,
1017                 .num_of_specs = 0,
1018                 .port = 0,
1019                 .flags = 0,
1020                 .reserved = 0,
1021         };
1022         flow.inner = 0;
1023         claim_zero(priv_flow_validate(priv, attr, items, actions,
1024                                       error, &flow));
1025         action = (struct mlx5_flow_action){
1026                 .queue = 0,
1027                 .drop = 0,
1028                 .mark = 0,
1029                 .mark_id = MLX5_FLOW_MARK_DEFAULT,
1030         };
1031         for (; actions->type != RTE_FLOW_ACTION_TYPE_END; ++actions) {
1032                 if (actions->type == RTE_FLOW_ACTION_TYPE_VOID) {
1033                         continue;
1034                 } else if (actions->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
1035                         action.queue = 1;
1036                         action.queue_id =
1037                                 ((const struct rte_flow_action_queue *)
1038                                  actions->conf)->index;
1039                 } else if (actions->type == RTE_FLOW_ACTION_TYPE_DROP) {
1040                         action.drop = 1;
1041                         action.mark = 0;
1042                 } else if (actions->type == RTE_FLOW_ACTION_TYPE_MARK) {
1043                         const struct rte_flow_action_mark *mark =
1044                                 (const struct rte_flow_action_mark *)
1045                                 actions->conf;
1046
1047                         if (mark)
1048                                 action.mark_id = mark->id;
1049                         action.mark = !action.drop;
1050                 } else {
1051                         rte_flow_error_set(error, ENOTSUP,
1052                                            RTE_FLOW_ERROR_TYPE_ACTION,
1053                                            actions, "unsupported action");
1054                         goto exit;
1055                 }
1056         }
1057         if (action.mark) {
1058                 mlx5_flow_create_flag_mark(&flow, action.mark_id);
1059                 flow.offset += sizeof(struct ibv_exp_flow_spec_action_tag);
1060         }
1061         rte_flow = priv_flow_create_action_queue(priv, flow.ibv_attr,
1062                                                  &action, error);
1063         return rte_flow;
1064 exit:
1065         rte_free(flow.ibv_attr);
1066         return NULL;
1067 }
1068
1069 /**
1070  * Create a flow.
1071  *
1072  * @see rte_flow_create()
1073  * @see rte_flow_ops
1074  */
1075 struct rte_flow *
1076 mlx5_flow_create(struct rte_eth_dev *dev,
1077                  const struct rte_flow_attr *attr,
1078                  const struct rte_flow_item items[],
1079                  const struct rte_flow_action actions[],
1080                  struct rte_flow_error *error)
1081 {
1082         struct priv *priv = dev->data->dev_private;
1083         struct rte_flow *flow;
1084
1085         priv_lock(priv);
1086         flow = priv_flow_create(priv, attr, items, actions, error);
1087         if (flow) {
1088                 LIST_INSERT_HEAD(&priv->flows, flow, next);
1089                 DEBUG("Flow created %p", (void *)flow);
1090         }
1091         priv_unlock(priv);
1092         return flow;
1093 }
1094
1095 /**
1096  * Destroy a flow.
1097  *
1098  * @param priv
1099  *   Pointer to private structure.
1100  * @param[in] flow
1101  *   Flow to destroy.
1102  */
1103 static void
1104 priv_flow_destroy(struct priv *priv,
1105                   struct rte_flow *flow)
1106 {
1107         (void)priv;
1108         LIST_REMOVE(flow, next);
1109         if (flow->ibv_flow)
1110                 claim_zero(ibv_exp_destroy_flow(flow->ibv_flow));
1111         if (flow->qp)
1112                 claim_zero(ibv_destroy_qp(flow->qp));
1113         if (flow->ind_table)
1114                 claim_zero(ibv_exp_destroy_rwq_ind_table(flow->ind_table));
1115         if (!flow->rxq && flow->wq)
1116                 claim_zero(ibv_exp_destroy_wq(flow->wq));
1117         if (!flow->rxq && flow->cq)
1118                 claim_zero(ibv_destroy_cq(flow->cq));
1119         if (flow->mark) {
1120                 struct rte_flow *tmp;
1121                 uint32_t mark_n = 0;
1122
1123                 for (tmp = LIST_FIRST(&priv->flows);
1124                      tmp;
1125                      tmp = LIST_NEXT(tmp, next)) {
1126                         if ((flow->rxq == tmp->rxq) && tmp->mark)
1127                                 ++mark_n;
1128                 }
1129                 flow->rxq->mark = !!mark_n;
1130         }
1131         rte_free(flow->ibv_attr);
1132         DEBUG("Flow destroyed %p", (void *)flow);
1133         rte_free(flow);
1134 }
1135
1136 /**
1137  * Destroy a flow.
1138  *
1139  * @see rte_flow_destroy()
1140  * @see rte_flow_ops
1141  */
1142 int
1143 mlx5_flow_destroy(struct rte_eth_dev *dev,
1144                   struct rte_flow *flow,
1145                   struct rte_flow_error *error)
1146 {
1147         struct priv *priv = dev->data->dev_private;
1148
1149         (void)error;
1150         priv_lock(priv);
1151         priv_flow_destroy(priv, flow);
1152         priv_unlock(priv);
1153         return 0;
1154 }
1155
1156 /**
1157  * Destroy all flows.
1158  *
1159  * @param priv
1160  *   Pointer to private structure.
1161  */
1162 static void
1163 priv_flow_flush(struct priv *priv)
1164 {
1165         while (!LIST_EMPTY(&priv->flows)) {
1166                 struct rte_flow *flow;
1167
1168                 flow = LIST_FIRST(&priv->flows);
1169                 priv_flow_destroy(priv, flow);
1170         }
1171 }
1172
1173 /**
1174  * Destroy all flows.
1175  *
1176  * @see rte_flow_flush()
1177  * @see rte_flow_ops
1178  */
1179 int
1180 mlx5_flow_flush(struct rte_eth_dev *dev,
1181                 struct rte_flow_error *error)
1182 {
1183         struct priv *priv = dev->data->dev_private;
1184
1185         (void)error;
1186         priv_lock(priv);
1187         priv_flow_flush(priv);
1188         priv_unlock(priv);
1189         return 0;
1190 }
1191
1192 /**
1193  * Remove all flows.
1194  *
1195  * Called by dev_stop() to remove all flows.
1196  *
1197  * @param priv
1198  *   Pointer to private structure.
1199  */
1200 void
1201 priv_flow_stop(struct priv *priv)
1202 {
1203         struct rte_flow *flow;
1204
1205         for (flow = LIST_FIRST(&priv->flows);
1206              flow;
1207              flow = LIST_NEXT(flow, next)) {
1208                 claim_zero(ibv_exp_destroy_flow(flow->ibv_flow));
1209                 flow->ibv_flow = NULL;
1210                 if (flow->mark)
1211                         flow->rxq->mark = 0;
1212                 DEBUG("Flow %p removed", (void *)flow);
1213         }
1214 }
1215
1216 /**
1217  * Add all flows.
1218  *
1219  * @param priv
1220  *   Pointer to private structure.
1221  *
1222  * @return
1223  *   0 on success, a errno value otherwise and rte_errno is set.
1224  */
1225 int
1226 priv_flow_start(struct priv *priv)
1227 {
1228         struct rte_flow *flow;
1229
1230         for (flow = LIST_FIRST(&priv->flows);
1231              flow;
1232              flow = LIST_NEXT(flow, next)) {
1233                 flow->ibv_flow = ibv_exp_create_flow(flow->qp,
1234                                                      flow->ibv_attr);
1235                 if (!flow->ibv_flow) {
1236                         DEBUG("Flow %p cannot be applied", (void *)flow);
1237                         rte_errno = EINVAL;
1238                         return rte_errno;
1239                 }
1240                 DEBUG("Flow %p applied", (void *)flow);
1241                 if (flow->rxq)
1242                         flow->rxq->mark |= flow->mark;
1243         }
1244         return 0;
1245 }