net/mlx5: support ether type support in flow item
[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                         .type = -1,
167                 },
168                 .default_mask = &rte_flow_item_eth_mask,
169                 .mask_sz = sizeof(struct rte_flow_item_eth),
170                 .convert = mlx5_flow_create_eth,
171                 .dst_sz = sizeof(struct ibv_exp_flow_spec_eth),
172         },
173         [RTE_FLOW_ITEM_TYPE_VLAN] = {
174                 .items = ITEMS(RTE_FLOW_ITEM_TYPE_IPV4,
175                                RTE_FLOW_ITEM_TYPE_IPV6),
176                 .actions = valid_actions,
177                 .mask = &(const struct rte_flow_item_vlan){
178                         .tci = -1,
179                 },
180                 .default_mask = &rte_flow_item_vlan_mask,
181                 .mask_sz = sizeof(struct rte_flow_item_vlan),
182                 .convert = mlx5_flow_create_vlan,
183                 .dst_sz = 0,
184         },
185         [RTE_FLOW_ITEM_TYPE_IPV4] = {
186                 .items = ITEMS(RTE_FLOW_ITEM_TYPE_UDP,
187                                RTE_FLOW_ITEM_TYPE_TCP),
188                 .actions = valid_actions,
189                 .mask = &(const struct rte_flow_item_ipv4){
190                         .hdr = {
191                                 .src_addr = -1,
192                                 .dst_addr = -1,
193                                 .type_of_service = -1,
194                                 .next_proto_id = -1,
195                         },
196                 },
197                 .default_mask = &rte_flow_item_ipv4_mask,
198                 .mask_sz = sizeof(struct rte_flow_item_ipv4),
199                 .convert = mlx5_flow_create_ipv4,
200                 .dst_sz = sizeof(struct ibv_exp_flow_spec_ipv4_ext),
201         },
202         [RTE_FLOW_ITEM_TYPE_IPV6] = {
203                 .items = ITEMS(RTE_FLOW_ITEM_TYPE_UDP,
204                                RTE_FLOW_ITEM_TYPE_TCP),
205                 .actions = valid_actions,
206                 .mask = &(const struct rte_flow_item_ipv6){
207                         .hdr = {
208                                 .src_addr = {
209                                         0xff, 0xff, 0xff, 0xff,
210                                         0xff, 0xff, 0xff, 0xff,
211                                         0xff, 0xff, 0xff, 0xff,
212                                         0xff, 0xff, 0xff, 0xff,
213                                 },
214                                 .dst_addr = {
215                                         0xff, 0xff, 0xff, 0xff,
216                                         0xff, 0xff, 0xff, 0xff,
217                                         0xff, 0xff, 0xff, 0xff,
218                                         0xff, 0xff, 0xff, 0xff,
219                                 },
220                         },
221                 },
222                 .default_mask = &rte_flow_item_ipv6_mask,
223                 .mask_sz = sizeof(struct rte_flow_item_ipv6),
224                 .convert = mlx5_flow_create_ipv6,
225                 .dst_sz = sizeof(struct ibv_exp_flow_spec_ipv6),
226         },
227         [RTE_FLOW_ITEM_TYPE_UDP] = {
228                 .items = ITEMS(RTE_FLOW_ITEM_TYPE_VXLAN),
229                 .actions = valid_actions,
230                 .mask = &(const struct rte_flow_item_udp){
231                         .hdr = {
232                                 .src_port = -1,
233                                 .dst_port = -1,
234                         },
235                 },
236                 .default_mask = &rte_flow_item_udp_mask,
237                 .mask_sz = sizeof(struct rte_flow_item_udp),
238                 .convert = mlx5_flow_create_udp,
239                 .dst_sz = sizeof(struct ibv_exp_flow_spec_tcp_udp),
240         },
241         [RTE_FLOW_ITEM_TYPE_TCP] = {
242                 .actions = valid_actions,
243                 .mask = &(const struct rte_flow_item_tcp){
244                         .hdr = {
245                                 .src_port = -1,
246                                 .dst_port = -1,
247                         },
248                 },
249                 .default_mask = &rte_flow_item_tcp_mask,
250                 .mask_sz = sizeof(struct rte_flow_item_tcp),
251                 .convert = mlx5_flow_create_tcp,
252                 .dst_sz = sizeof(struct ibv_exp_flow_spec_tcp_udp),
253         },
254         [RTE_FLOW_ITEM_TYPE_VXLAN] = {
255                 .items = ITEMS(RTE_FLOW_ITEM_TYPE_ETH),
256                 .actions = valid_actions,
257                 .mask = &(const struct rte_flow_item_vxlan){
258                         .vni = "\xff\xff\xff",
259                 },
260                 .default_mask = &rte_flow_item_vxlan_mask,
261                 .mask_sz = sizeof(struct rte_flow_item_vxlan),
262                 .convert = mlx5_flow_create_vxlan,
263                 .dst_sz = sizeof(struct ibv_exp_flow_spec_tunnel),
264         },
265 };
266
267 /** Structure to pass to the conversion function. */
268 struct mlx5_flow {
269         struct ibv_exp_flow_attr *ibv_attr; /**< Verbs attribute. */
270         unsigned int offset; /**< Offset in bytes in the ibv_attr buffer. */
271         uint32_t inner; /**< Set once VXLAN is encountered. */
272 };
273
274 struct mlx5_flow_action {
275         uint32_t queue:1; /**< Target is a receive queue. */
276         uint32_t drop:1; /**< Target is a drop queue. */
277         uint32_t mark:1; /**< Mark is present in the flow. */
278         uint32_t queue_id; /**< Identifier of the queue. */
279         uint32_t mark_id; /**< Mark identifier. */
280 };
281
282 /**
283  * Check support for a given item.
284  *
285  * @param item[in]
286  *   Item specification.
287  * @param mask[in]
288  *   Bit-masks covering supported fields to compare with spec, last and mask in
289  *   \item.
290  * @param size
291  *   Bit-Mask size in bytes.
292  *
293  * @return
294  *   0 on success.
295  */
296 static int
297 mlx5_flow_item_validate(const struct rte_flow_item *item,
298                         const uint8_t *mask, unsigned int size)
299 {
300         int ret = 0;
301
302         if (!item->spec && (item->mask || item->last))
303                 return -1;
304         if (item->spec && !item->mask) {
305                 unsigned int i;
306                 const uint8_t *spec = item->spec;
307
308                 for (i = 0; i < size; ++i)
309                         if ((spec[i] | mask[i]) != mask[i])
310                                 return -1;
311         }
312         if (item->last && !item->mask) {
313                 unsigned int i;
314                 const uint8_t *spec = item->last;
315
316                 for (i = 0; i < size; ++i)
317                         if ((spec[i] | mask[i]) != mask[i])
318                                 return -1;
319         }
320         if (item->mask) {
321                 unsigned int i;
322                 const uint8_t *spec = item->mask;
323
324                 for (i = 0; i < size; ++i)
325                         if ((spec[i] | mask[i]) != mask[i])
326                                 return -1;
327         }
328         if (item->spec && item->last) {
329                 uint8_t spec[size];
330                 uint8_t last[size];
331                 const uint8_t *apply = mask;
332                 unsigned int i;
333
334                 if (item->mask)
335                         apply = item->mask;
336                 for (i = 0; i < size; ++i) {
337                         spec[i] = ((const uint8_t *)item->spec)[i] & apply[i];
338                         last[i] = ((const uint8_t *)item->last)[i] & apply[i];
339                 }
340                 ret = memcmp(spec, last, size);
341         }
342         return ret;
343 }
344
345 /**
346  * Validate a flow supported by the NIC.
347  *
348  * @param priv
349  *   Pointer to private structure.
350  * @param[in] attr
351  *   Flow rule attributes.
352  * @param[in] pattern
353  *   Pattern specification (list terminated by the END pattern item).
354  * @param[in] actions
355  *   Associated actions (list terminated by the END action).
356  * @param[out] error
357  *   Perform verbose error reporting if not NULL.
358  * @param[in, out] flow
359  *   Flow structure to update.
360  *
361  * @return
362  *   0 on success, a negative errno value otherwise and rte_errno is set.
363  */
364 static int
365 priv_flow_validate(struct priv *priv,
366                    const struct rte_flow_attr *attr,
367                    const struct rte_flow_item items[],
368                    const struct rte_flow_action actions[],
369                    struct rte_flow_error *error,
370                    struct mlx5_flow *flow)
371 {
372         const struct mlx5_flow_items *cur_item = mlx5_flow_items;
373         struct mlx5_flow_action action = {
374                 .queue = 0,
375                 .drop = 0,
376                 .mark = 0,
377         };
378
379         (void)priv;
380         if (attr->group) {
381                 rte_flow_error_set(error, ENOTSUP,
382                                    RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
383                                    NULL,
384                                    "groups are not supported");
385                 return -rte_errno;
386         }
387         if (attr->priority) {
388                 rte_flow_error_set(error, ENOTSUP,
389                                    RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
390                                    NULL,
391                                    "priorities are not supported");
392                 return -rte_errno;
393         }
394         if (attr->egress) {
395                 rte_flow_error_set(error, ENOTSUP,
396                                    RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
397                                    NULL,
398                                    "egress is not supported");
399                 return -rte_errno;
400         }
401         if (!attr->ingress) {
402                 rte_flow_error_set(error, ENOTSUP,
403                                    RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
404                                    NULL,
405                                    "only ingress is supported");
406                 return -rte_errno;
407         }
408         for (; items->type != RTE_FLOW_ITEM_TYPE_END; ++items) {
409                 const struct mlx5_flow_items *token = NULL;
410                 unsigned int i;
411                 int err;
412
413                 if (items->type == RTE_FLOW_ITEM_TYPE_VOID)
414                         continue;
415                 for (i = 0;
416                      cur_item->items &&
417                      cur_item->items[i] != RTE_FLOW_ITEM_TYPE_END;
418                      ++i) {
419                         if (cur_item->items[i] == items->type) {
420                                 token = &mlx5_flow_items[items->type];
421                                 break;
422                         }
423                 }
424                 if (!token)
425                         goto exit_item_not_supported;
426                 cur_item = token;
427                 err = mlx5_flow_item_validate(items,
428                                               (const uint8_t *)cur_item->mask,
429                                               cur_item->mask_sz);
430                 if (err)
431                         goto exit_item_not_supported;
432                 if (flow->ibv_attr && cur_item->convert) {
433                         err = cur_item->convert(items,
434                                                 (cur_item->default_mask ?
435                                                  cur_item->default_mask :
436                                                  cur_item->mask),
437                                                 flow);
438                         if (err)
439                                 goto exit_item_not_supported;
440                 }
441                 flow->offset += cur_item->dst_sz;
442         }
443         for (; actions->type != RTE_FLOW_ACTION_TYPE_END; ++actions) {
444                 if (actions->type == RTE_FLOW_ACTION_TYPE_VOID) {
445                         continue;
446                 } else if (actions->type == RTE_FLOW_ACTION_TYPE_DROP) {
447                         action.drop = 1;
448                 } else if (actions->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
449                         const struct rte_flow_action_queue *queue =
450                                 (const struct rte_flow_action_queue *)
451                                 actions->conf;
452
453                         if (!queue || (queue->index > (priv->rxqs_n - 1)))
454                                 goto exit_action_not_supported;
455                         action.queue = 1;
456                 } else if (actions->type == RTE_FLOW_ACTION_TYPE_MARK) {
457                         const struct rte_flow_action_mark *mark =
458                                 (const struct rte_flow_action_mark *)
459                                 actions->conf;
460
461                         if (!mark) {
462                                 rte_flow_error_set(error, EINVAL,
463                                                    RTE_FLOW_ERROR_TYPE_ACTION,
464                                                    actions,
465                                                    "mark must be defined");
466                                 return -rte_errno;
467                         } else if (mark->id >= MLX5_FLOW_MARK_MAX) {
468                                 rte_flow_error_set(error, ENOTSUP,
469                                                    RTE_FLOW_ERROR_TYPE_ACTION,
470                                                    actions,
471                                                    "mark must be between 0"
472                                                    " and 16777199");
473                                 return -rte_errno;
474                         }
475                         action.mark = 1;
476                 } else {
477                         goto exit_action_not_supported;
478                 }
479         }
480         if (action.mark && !flow->ibv_attr && !action.drop)
481                 flow->offset += sizeof(struct ibv_exp_flow_spec_action_tag);
482         if (!action.queue && !action.drop) {
483                 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_HANDLE,
484                                    NULL, "no valid action");
485                 return -rte_errno;
486         }
487         return 0;
488 exit_item_not_supported:
489         rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM,
490                            items, "item not supported");
491         return -rte_errno;
492 exit_action_not_supported:
493         rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
494                            actions, "action not supported");
495         return -rte_errno;
496 }
497
498 /**
499  * Validate a flow supported by the NIC.
500  *
501  * @see rte_flow_validate()
502  * @see rte_flow_ops
503  */
504 int
505 mlx5_flow_validate(struct rte_eth_dev *dev,
506                    const struct rte_flow_attr *attr,
507                    const struct rte_flow_item items[],
508                    const struct rte_flow_action actions[],
509                    struct rte_flow_error *error)
510 {
511         struct priv *priv = dev->data->dev_private;
512         int ret;
513         struct mlx5_flow flow = { .offset = sizeof(struct ibv_exp_flow_attr) };
514
515         priv_lock(priv);
516         ret = priv_flow_validate(priv, attr, items, actions, error, &flow);
517         priv_unlock(priv);
518         return ret;
519 }
520
521 /**
522  * Convert Ethernet item to Verbs specification.
523  *
524  * @param item[in]
525  *   Item specification.
526  * @param default_mask[in]
527  *   Default bit-masks to use when item->mask is not provided.
528  * @param data[in, out]
529  *   User structure.
530  */
531 static int
532 mlx5_flow_create_eth(const struct rte_flow_item *item,
533                      const void *default_mask,
534                      void *data)
535 {
536         const struct rte_flow_item_eth *spec = item->spec;
537         const struct rte_flow_item_eth *mask = item->mask;
538         struct mlx5_flow *flow = (struct mlx5_flow *)data;
539         struct ibv_exp_flow_spec_eth *eth;
540         const unsigned int eth_size = sizeof(struct ibv_exp_flow_spec_eth);
541         unsigned int i;
542
543         ++flow->ibv_attr->num_of_specs;
544         flow->ibv_attr->priority = 2;
545         eth = (void *)((uintptr_t)flow->ibv_attr + flow->offset);
546         *eth = (struct ibv_exp_flow_spec_eth) {
547                 .type = flow->inner | IBV_EXP_FLOW_SPEC_ETH,
548                 .size = eth_size,
549         };
550         if (!spec)
551                 return 0;
552         if (!mask)
553                 mask = default_mask;
554         memcpy(eth->val.dst_mac, spec->dst.addr_bytes, ETHER_ADDR_LEN);
555         memcpy(eth->val.src_mac, spec->src.addr_bytes, ETHER_ADDR_LEN);
556         eth->val.ether_type = spec->type;
557         memcpy(eth->mask.dst_mac, mask->dst.addr_bytes, ETHER_ADDR_LEN);
558         memcpy(eth->mask.src_mac, mask->src.addr_bytes, ETHER_ADDR_LEN);
559         eth->mask.ether_type = mask->type;
560         /* Remove unwanted bits from values. */
561         for (i = 0; i < ETHER_ADDR_LEN; ++i) {
562                 eth->val.dst_mac[i] &= eth->mask.dst_mac[i];
563                 eth->val.src_mac[i] &= eth->mask.src_mac[i];
564         }
565         eth->val.ether_type &= eth->mask.ether_type;
566         return 0;
567 }
568
569 /**
570  * Convert VLAN item to Verbs specification.
571  *
572  * @param item[in]
573  *   Item specification.
574  * @param default_mask[in]
575  *   Default bit-masks to use when item->mask is not provided.
576  * @param data[in, out]
577  *   User structure.
578  */
579 static int
580 mlx5_flow_create_vlan(const struct rte_flow_item *item,
581                       const void *default_mask,
582                       void *data)
583 {
584         const struct rte_flow_item_vlan *spec = item->spec;
585         const struct rte_flow_item_vlan *mask = item->mask;
586         struct mlx5_flow *flow = (struct mlx5_flow *)data;
587         struct ibv_exp_flow_spec_eth *eth;
588         const unsigned int eth_size = sizeof(struct ibv_exp_flow_spec_eth);
589
590         eth = (void *)((uintptr_t)flow->ibv_attr + flow->offset - eth_size);
591         if (!spec)
592                 return 0;
593         if (!mask)
594                 mask = default_mask;
595         eth->val.vlan_tag = spec->tci;
596         eth->mask.vlan_tag = mask->tci;
597         eth->val.vlan_tag &= eth->mask.vlan_tag;
598         return 0;
599 }
600
601 /**
602  * Convert IPv4 item to Verbs specification.
603  *
604  * @param item[in]
605  *   Item specification.
606  * @param default_mask[in]
607  *   Default bit-masks to use when item->mask is not provided.
608  * @param data[in, out]
609  *   User structure.
610  */
611 static int
612 mlx5_flow_create_ipv4(const struct rte_flow_item *item,
613                       const void *default_mask,
614                       void *data)
615 {
616         const struct rte_flow_item_ipv4 *spec = item->spec;
617         const struct rte_flow_item_ipv4 *mask = item->mask;
618         struct mlx5_flow *flow = (struct mlx5_flow *)data;
619         struct ibv_exp_flow_spec_ipv4_ext *ipv4;
620         unsigned int ipv4_size = sizeof(struct ibv_exp_flow_spec_ipv4_ext);
621
622         ++flow->ibv_attr->num_of_specs;
623         flow->ibv_attr->priority = 1;
624         ipv4 = (void *)((uintptr_t)flow->ibv_attr + flow->offset);
625         *ipv4 = (struct ibv_exp_flow_spec_ipv4_ext) {
626                 .type = flow->inner | IBV_EXP_FLOW_SPEC_IPV4_EXT,
627                 .size = ipv4_size,
628         };
629         if (!spec)
630                 return 0;
631         if (!mask)
632                 mask = default_mask;
633         ipv4->val = (struct ibv_exp_flow_ipv4_ext_filter){
634                 .src_ip = spec->hdr.src_addr,
635                 .dst_ip = spec->hdr.dst_addr,
636                 .proto = spec->hdr.next_proto_id,
637                 .tos = spec->hdr.type_of_service,
638         };
639         ipv4->mask = (struct ibv_exp_flow_ipv4_ext_filter){
640                 .src_ip = mask->hdr.src_addr,
641                 .dst_ip = mask->hdr.dst_addr,
642                 .proto = mask->hdr.next_proto_id,
643                 .tos = mask->hdr.type_of_service,
644         };
645         /* Remove unwanted bits from values. */
646         ipv4->val.src_ip &= ipv4->mask.src_ip;
647         ipv4->val.dst_ip &= ipv4->mask.dst_ip;
648         ipv4->val.proto &= ipv4->mask.proto;
649         ipv4->val.tos &= ipv4->mask.tos;
650         return 0;
651 }
652
653 /**
654  * Convert IPv6 item to Verbs specification.
655  *
656  * @param item[in]
657  *   Item specification.
658  * @param default_mask[in]
659  *   Default bit-masks to use when item->mask is not provided.
660  * @param data[in, out]
661  *   User structure.
662  */
663 static int
664 mlx5_flow_create_ipv6(const struct rte_flow_item *item,
665                       const void *default_mask,
666                       void *data)
667 {
668         const struct rte_flow_item_ipv6 *spec = item->spec;
669         const struct rte_flow_item_ipv6 *mask = item->mask;
670         struct mlx5_flow *flow = (struct mlx5_flow *)data;
671         struct ibv_exp_flow_spec_ipv6 *ipv6;
672         unsigned int ipv6_size = sizeof(struct ibv_exp_flow_spec_ipv6);
673         unsigned int i;
674
675         ++flow->ibv_attr->num_of_specs;
676         flow->ibv_attr->priority = 1;
677         ipv6 = (void *)((uintptr_t)flow->ibv_attr + flow->offset);
678         *ipv6 = (struct ibv_exp_flow_spec_ipv6) {
679                 .type = flow->inner | IBV_EXP_FLOW_SPEC_IPV6,
680                 .size = ipv6_size,
681         };
682         if (!spec)
683                 return 0;
684         if (!mask)
685                 mask = default_mask;
686         memcpy(ipv6->val.src_ip, spec->hdr.src_addr,
687                RTE_DIM(ipv6->val.src_ip));
688         memcpy(ipv6->val.dst_ip, spec->hdr.dst_addr,
689                RTE_DIM(ipv6->val.dst_ip));
690         memcpy(ipv6->mask.src_ip, mask->hdr.src_addr,
691                RTE_DIM(ipv6->mask.src_ip));
692         memcpy(ipv6->mask.dst_ip, mask->hdr.dst_addr,
693                RTE_DIM(ipv6->mask.dst_ip));
694         /* Remove unwanted bits from values. */
695         for (i = 0; i < RTE_DIM(ipv6->val.src_ip); ++i) {
696                 ipv6->val.src_ip[i] &= ipv6->mask.src_ip[i];
697                 ipv6->val.dst_ip[i] &= ipv6->mask.dst_ip[i];
698         }
699         return 0;
700 }
701
702 /**
703  * Convert UDP item to Verbs specification.
704  *
705  * @param item[in]
706  *   Item specification.
707  * @param default_mask[in]
708  *   Default bit-masks to use when item->mask is not provided.
709  * @param data[in, out]
710  *   User structure.
711  */
712 static int
713 mlx5_flow_create_udp(const struct rte_flow_item *item,
714                      const void *default_mask,
715                      void *data)
716 {
717         const struct rte_flow_item_udp *spec = item->spec;
718         const struct rte_flow_item_udp *mask = item->mask;
719         struct mlx5_flow *flow = (struct mlx5_flow *)data;
720         struct ibv_exp_flow_spec_tcp_udp *udp;
721         unsigned int udp_size = sizeof(struct ibv_exp_flow_spec_tcp_udp);
722
723         ++flow->ibv_attr->num_of_specs;
724         flow->ibv_attr->priority = 0;
725         udp = (void *)((uintptr_t)flow->ibv_attr + flow->offset);
726         *udp = (struct ibv_exp_flow_spec_tcp_udp) {
727                 .type = flow->inner | IBV_EXP_FLOW_SPEC_UDP,
728                 .size = udp_size,
729         };
730         if (!spec)
731                 return 0;
732         if (!mask)
733                 mask = default_mask;
734         udp->val.dst_port = spec->hdr.dst_port;
735         udp->val.src_port = spec->hdr.src_port;
736         udp->mask.dst_port = mask->hdr.dst_port;
737         udp->mask.src_port = mask->hdr.src_port;
738         /* Remove unwanted bits from values. */
739         udp->val.src_port &= udp->mask.src_port;
740         udp->val.dst_port &= udp->mask.dst_port;
741         return 0;
742 }
743
744 /**
745  * Convert TCP item to Verbs specification.
746  *
747  * @param item[in]
748  *   Item specification.
749  * @param default_mask[in]
750  *   Default bit-masks to use when item->mask is not provided.
751  * @param data[in, out]
752  *   User structure.
753  */
754 static int
755 mlx5_flow_create_tcp(const struct rte_flow_item *item,
756                      const void *default_mask,
757                      void *data)
758 {
759         const struct rte_flow_item_tcp *spec = item->spec;
760         const struct rte_flow_item_tcp *mask = item->mask;
761         struct mlx5_flow *flow = (struct mlx5_flow *)data;
762         struct ibv_exp_flow_spec_tcp_udp *tcp;
763         unsigned int tcp_size = sizeof(struct ibv_exp_flow_spec_tcp_udp);
764
765         ++flow->ibv_attr->num_of_specs;
766         flow->ibv_attr->priority = 0;
767         tcp = (void *)((uintptr_t)flow->ibv_attr + flow->offset);
768         *tcp = (struct ibv_exp_flow_spec_tcp_udp) {
769                 .type = flow->inner | IBV_EXP_FLOW_SPEC_TCP,
770                 .size = tcp_size,
771         };
772         if (!spec)
773                 return 0;
774         if (!mask)
775                 mask = default_mask;
776         tcp->val.dst_port = spec->hdr.dst_port;
777         tcp->val.src_port = spec->hdr.src_port;
778         tcp->mask.dst_port = mask->hdr.dst_port;
779         tcp->mask.src_port = mask->hdr.src_port;
780         /* Remove unwanted bits from values. */
781         tcp->val.src_port &= tcp->mask.src_port;
782         tcp->val.dst_port &= tcp->mask.dst_port;
783         return 0;
784 }
785
786 /**
787  * Convert VXLAN item to Verbs specification.
788  *
789  * @param item[in]
790  *   Item specification.
791  * @param default_mask[in]
792  *   Default bit-masks to use when item->mask is not provided.
793  * @param data[in, out]
794  *   User structure.
795  */
796 static int
797 mlx5_flow_create_vxlan(const struct rte_flow_item *item,
798                        const void *default_mask,
799                        void *data)
800 {
801         const struct rte_flow_item_vxlan *spec = item->spec;
802         const struct rte_flow_item_vxlan *mask = item->mask;
803         struct mlx5_flow *flow = (struct mlx5_flow *)data;
804         struct ibv_exp_flow_spec_tunnel *vxlan;
805         unsigned int size = sizeof(struct ibv_exp_flow_spec_tunnel);
806         union vni {
807                 uint32_t vlan_id;
808                 uint8_t vni[4];
809         } id;
810
811         ++flow->ibv_attr->num_of_specs;
812         flow->ibv_attr->priority = 0;
813         id.vni[0] = 0;
814         vxlan = (void *)((uintptr_t)flow->ibv_attr + flow->offset);
815         *vxlan = (struct ibv_exp_flow_spec_tunnel) {
816                 .type = flow->inner | IBV_EXP_FLOW_SPEC_VXLAN_TUNNEL,
817                 .size = size,
818         };
819         flow->inner = IBV_EXP_FLOW_SPEC_INNER;
820         if (!spec)
821                 return 0;
822         if (!mask)
823                 mask = default_mask;
824         memcpy(&id.vni[1], spec->vni, 3);
825         vxlan->val.tunnel_id = id.vlan_id;
826         memcpy(&id.vni[1], mask->vni, 3);
827         vxlan->mask.tunnel_id = id.vlan_id;
828         /* Remove unwanted bits from values. */
829         vxlan->val.tunnel_id &= vxlan->mask.tunnel_id;
830         return 0;
831 }
832
833 /**
834  * Convert mark/flag action to Verbs specification.
835  *
836  * @param flow
837  *   Pointer to MLX5 flow structure.
838  * @param mark_id
839  *   Mark identifier.
840  */
841 static int
842 mlx5_flow_create_flag_mark(struct mlx5_flow *flow, uint32_t mark_id)
843 {
844         struct ibv_exp_flow_spec_action_tag *tag;
845         unsigned int size = sizeof(struct ibv_exp_flow_spec_action_tag);
846
847         tag = (void *)((uintptr_t)flow->ibv_attr + flow->offset);
848         *tag = (struct ibv_exp_flow_spec_action_tag){
849                 .type = IBV_EXP_FLOW_SPEC_ACTION_TAG,
850                 .size = size,
851                 .tag_id = mlx5_flow_mark_set(mark_id),
852         };
853         ++flow->ibv_attr->num_of_specs;
854         return 0;
855 }
856
857 /**
858  * Complete flow rule creation.
859  *
860  * @param priv
861  *   Pointer to private structure.
862  * @param ibv_attr
863  *   Verbs flow attributes.
864  * @param action
865  *   Target action structure.
866  * @param[out] error
867  *   Perform verbose error reporting if not NULL.
868  *
869  * @return
870  *   A flow if the rule could be created.
871  */
872 static struct rte_flow *
873 priv_flow_create_action_queue(struct priv *priv,
874                               struct ibv_exp_flow_attr *ibv_attr,
875                               struct mlx5_flow_action *action,
876                               struct rte_flow_error *error)
877 {
878         struct rxq_ctrl *rxq;
879         struct rte_flow *rte_flow;
880
881         assert(priv->pd);
882         assert(priv->ctx);
883         rte_flow = rte_calloc(__func__, 1, sizeof(*rte_flow), 0);
884         if (!rte_flow) {
885                 rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_HANDLE,
886                                    NULL, "cannot allocate flow memory");
887                 return NULL;
888         }
889         if (action->drop) {
890                 rte_flow->cq =
891                         ibv_exp_create_cq(priv->ctx, 1, NULL, NULL, 0,
892                                           &(struct ibv_exp_cq_init_attr){
893                                                   .comp_mask = 0,
894                                           });
895                 if (!rte_flow->cq) {
896                         rte_flow_error_set(error, ENOMEM,
897                                            RTE_FLOW_ERROR_TYPE_HANDLE,
898                                            NULL, "cannot allocate CQ");
899                         goto error;
900                 }
901                 rte_flow->wq = ibv_exp_create_wq(priv->ctx,
902                                                  &(struct ibv_exp_wq_init_attr){
903                                                  .wq_type = IBV_EXP_WQT_RQ,
904                                                  .max_recv_wr = 1,
905                                                  .max_recv_sge = 1,
906                                                  .pd = priv->pd,
907                                                  .cq = rte_flow->cq,
908                                                  });
909                 if (!rte_flow->wq) {
910                         rte_flow_error_set(error, ENOMEM,
911                                            RTE_FLOW_ERROR_TYPE_HANDLE,
912                                            NULL, "cannot allocate WQ");
913                         goto error;
914                 }
915         } else {
916                 rxq = container_of((*priv->rxqs)[action->queue_id],
917                                    struct rxq_ctrl, rxq);
918                 rte_flow->rxq = &rxq->rxq;
919                 rxq->rxq.mark |= action->mark;
920                 rte_flow->wq = rxq->wq;
921         }
922         rte_flow->mark = action->mark;
923         rte_flow->ibv_attr = ibv_attr;
924         rte_flow->ind_table = ibv_exp_create_rwq_ind_table(
925                 priv->ctx,
926                 &(struct ibv_exp_rwq_ind_table_init_attr){
927                         .pd = priv->pd,
928                         .log_ind_tbl_size = 0,
929                         .ind_tbl = &rte_flow->wq,
930                         .comp_mask = 0,
931                 });
932         if (!rte_flow->ind_table) {
933                 rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_HANDLE,
934                                    NULL, "cannot allocate indirection table");
935                 goto error;
936         }
937         rte_flow->qp = ibv_exp_create_qp(
938                 priv->ctx,
939                 &(struct ibv_exp_qp_init_attr){
940                         .qp_type = IBV_QPT_RAW_PACKET,
941                         .comp_mask =
942                                 IBV_EXP_QP_INIT_ATTR_PD |
943                                 IBV_EXP_QP_INIT_ATTR_PORT |
944                                 IBV_EXP_QP_INIT_ATTR_RX_HASH,
945                         .pd = priv->pd,
946                         .rx_hash_conf = &(struct ibv_exp_rx_hash_conf){
947                                 .rx_hash_function =
948                                         IBV_EXP_RX_HASH_FUNC_TOEPLITZ,
949                                 .rx_hash_key_len = rss_hash_default_key_len,
950                                 .rx_hash_key = rss_hash_default_key,
951                                 .rx_hash_fields_mask = 0,
952                                 .rwq_ind_tbl = rte_flow->ind_table,
953                         },
954                         .port_num = priv->port,
955                 });
956         if (!rte_flow->qp) {
957                 rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_HANDLE,
958                                    NULL, "cannot allocate QP");
959                 goto error;
960         }
961         if (!priv->started)
962                 return rte_flow;
963         rte_flow->ibv_flow = ibv_exp_create_flow(rte_flow->qp,
964                                                  rte_flow->ibv_attr);
965         if (!rte_flow->ibv_flow) {
966                 rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_HANDLE,
967                                    NULL, "flow rule creation failure");
968                 goto error;
969         }
970         return rte_flow;
971 error:
972         assert(rte_flow);
973         if (rte_flow->qp)
974                 ibv_destroy_qp(rte_flow->qp);
975         if (rte_flow->ind_table)
976                 ibv_exp_destroy_rwq_ind_table(rte_flow->ind_table);
977         if (!rte_flow->rxq && rte_flow->wq)
978                 ibv_exp_destroy_wq(rte_flow->wq);
979         if (!rte_flow->rxq && rte_flow->cq)
980                 ibv_destroy_cq(rte_flow->cq);
981         rte_free(rte_flow);
982         return NULL;
983 }
984
985 /**
986  * Convert a flow.
987  *
988  * @param priv
989  *   Pointer to private structure.
990  * @param[in] attr
991  *   Flow rule attributes.
992  * @param[in] pattern
993  *   Pattern specification (list terminated by the END pattern item).
994  * @param[in] actions
995  *   Associated actions (list terminated by the END action).
996  * @param[out] error
997  *   Perform verbose error reporting if not NULL.
998  *
999  * @return
1000  *   A flow on success, NULL otherwise.
1001  */
1002 static struct rte_flow *
1003 priv_flow_create(struct priv *priv,
1004                  const struct rte_flow_attr *attr,
1005                  const struct rte_flow_item items[],
1006                  const struct rte_flow_action actions[],
1007                  struct rte_flow_error *error)
1008 {
1009         struct rte_flow *rte_flow;
1010         struct mlx5_flow_action action;
1011         struct mlx5_flow flow = { .offset = sizeof(struct ibv_exp_flow_attr), };
1012         int err;
1013
1014         err = priv_flow_validate(priv, attr, items, actions, error, &flow);
1015         if (err)
1016                 goto exit;
1017         flow.ibv_attr = rte_malloc(__func__, flow.offset, 0);
1018         flow.offset = sizeof(struct ibv_exp_flow_attr);
1019         if (!flow.ibv_attr) {
1020                 rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_HANDLE,
1021                                    NULL, "cannot allocate ibv_attr memory");
1022                 goto exit;
1023         }
1024         *flow.ibv_attr = (struct ibv_exp_flow_attr){
1025                 .type = IBV_EXP_FLOW_ATTR_NORMAL,
1026                 .size = sizeof(struct ibv_exp_flow_attr),
1027                 .priority = attr->priority,
1028                 .num_of_specs = 0,
1029                 .port = 0,
1030                 .flags = 0,
1031                 .reserved = 0,
1032         };
1033         flow.inner = 0;
1034         claim_zero(priv_flow_validate(priv, attr, items, actions,
1035                                       error, &flow));
1036         action = (struct mlx5_flow_action){
1037                 .queue = 0,
1038                 .drop = 0,
1039                 .mark = 0,
1040                 .mark_id = MLX5_FLOW_MARK_DEFAULT,
1041         };
1042         for (; actions->type != RTE_FLOW_ACTION_TYPE_END; ++actions) {
1043                 if (actions->type == RTE_FLOW_ACTION_TYPE_VOID) {
1044                         continue;
1045                 } else if (actions->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
1046                         action.queue = 1;
1047                         action.queue_id =
1048                                 ((const struct rte_flow_action_queue *)
1049                                  actions->conf)->index;
1050                 } else if (actions->type == RTE_FLOW_ACTION_TYPE_DROP) {
1051                         action.drop = 1;
1052                         action.mark = 0;
1053                 } else if (actions->type == RTE_FLOW_ACTION_TYPE_MARK) {
1054                         const struct rte_flow_action_mark *mark =
1055                                 (const struct rte_flow_action_mark *)
1056                                 actions->conf;
1057
1058                         if (mark)
1059                                 action.mark_id = mark->id;
1060                         action.mark = !action.drop;
1061                 } else {
1062                         rte_flow_error_set(error, ENOTSUP,
1063                                            RTE_FLOW_ERROR_TYPE_ACTION,
1064                                            actions, "unsupported action");
1065                         goto exit;
1066                 }
1067         }
1068         if (action.mark) {
1069                 mlx5_flow_create_flag_mark(&flow, action.mark_id);
1070                 flow.offset += sizeof(struct ibv_exp_flow_spec_action_tag);
1071         }
1072         rte_flow = priv_flow_create_action_queue(priv, flow.ibv_attr,
1073                                                  &action, error);
1074         if (!rte_flow)
1075                 goto exit;
1076         return rte_flow;
1077 exit:
1078         rte_free(flow.ibv_attr);
1079         return NULL;
1080 }
1081
1082 /**
1083  * Create a flow.
1084  *
1085  * @see rte_flow_create()
1086  * @see rte_flow_ops
1087  */
1088 struct rte_flow *
1089 mlx5_flow_create(struct rte_eth_dev *dev,
1090                  const struct rte_flow_attr *attr,
1091                  const struct rte_flow_item items[],
1092                  const struct rte_flow_action actions[],
1093                  struct rte_flow_error *error)
1094 {
1095         struct priv *priv = dev->data->dev_private;
1096         struct rte_flow *flow;
1097
1098         priv_lock(priv);
1099         flow = priv_flow_create(priv, attr, items, actions, error);
1100         if (flow) {
1101                 LIST_INSERT_HEAD(&priv->flows, flow, next);
1102                 DEBUG("Flow created %p", (void *)flow);
1103         }
1104         priv_unlock(priv);
1105         return flow;
1106 }
1107
1108 /**
1109  * Destroy a flow.
1110  *
1111  * @param priv
1112  *   Pointer to private structure.
1113  * @param[in] flow
1114  *   Flow to destroy.
1115  */
1116 static void
1117 priv_flow_destroy(struct priv *priv,
1118                   struct rte_flow *flow)
1119 {
1120         (void)priv;
1121         LIST_REMOVE(flow, next);
1122         if (flow->ibv_flow)
1123                 claim_zero(ibv_exp_destroy_flow(flow->ibv_flow));
1124         if (flow->qp)
1125                 claim_zero(ibv_destroy_qp(flow->qp));
1126         if (flow->ind_table)
1127                 claim_zero(ibv_exp_destroy_rwq_ind_table(flow->ind_table));
1128         if (!flow->rxq && flow->wq)
1129                 claim_zero(ibv_exp_destroy_wq(flow->wq));
1130         if (!flow->rxq && flow->cq)
1131                 claim_zero(ibv_destroy_cq(flow->cq));
1132         if (flow->mark) {
1133                 struct rte_flow *tmp;
1134                 uint32_t mark_n = 0;
1135
1136                 for (tmp = LIST_FIRST(&priv->flows);
1137                      tmp;
1138                      tmp = LIST_NEXT(tmp, next)) {
1139                         if ((flow->rxq == tmp->rxq) && tmp->mark)
1140                                 ++mark_n;
1141                 }
1142                 flow->rxq->mark = !!mark_n;
1143         }
1144         rte_free(flow->ibv_attr);
1145         DEBUG("Flow destroyed %p", (void *)flow);
1146         rte_free(flow);
1147 }
1148
1149 /**
1150  * Destroy a flow.
1151  *
1152  * @see rte_flow_destroy()
1153  * @see rte_flow_ops
1154  */
1155 int
1156 mlx5_flow_destroy(struct rte_eth_dev *dev,
1157                   struct rte_flow *flow,
1158                   struct rte_flow_error *error)
1159 {
1160         struct priv *priv = dev->data->dev_private;
1161
1162         (void)error;
1163         priv_lock(priv);
1164         priv_flow_destroy(priv, flow);
1165         priv_unlock(priv);
1166         return 0;
1167 }
1168
1169 /**
1170  * Destroy all flows.
1171  *
1172  * @param priv
1173  *   Pointer to private structure.
1174  */
1175 static void
1176 priv_flow_flush(struct priv *priv)
1177 {
1178         while (!LIST_EMPTY(&priv->flows)) {
1179                 struct rte_flow *flow;
1180
1181                 flow = LIST_FIRST(&priv->flows);
1182                 priv_flow_destroy(priv, flow);
1183         }
1184 }
1185
1186 /**
1187  * Destroy all flows.
1188  *
1189  * @see rte_flow_flush()
1190  * @see rte_flow_ops
1191  */
1192 int
1193 mlx5_flow_flush(struct rte_eth_dev *dev,
1194                 struct rte_flow_error *error)
1195 {
1196         struct priv *priv = dev->data->dev_private;
1197
1198         (void)error;
1199         priv_lock(priv);
1200         priv_flow_flush(priv);
1201         priv_unlock(priv);
1202         return 0;
1203 }
1204
1205 /**
1206  * Remove all flows.
1207  *
1208  * Called by dev_stop() to remove all flows.
1209  *
1210  * @param priv
1211  *   Pointer to private structure.
1212  */
1213 void
1214 priv_flow_stop(struct priv *priv)
1215 {
1216         struct rte_flow *flow;
1217
1218         for (flow = LIST_FIRST(&priv->flows);
1219              flow;
1220              flow = LIST_NEXT(flow, next)) {
1221                 claim_zero(ibv_exp_destroy_flow(flow->ibv_flow));
1222                 flow->ibv_flow = NULL;
1223                 if (flow->mark)
1224                         flow->rxq->mark = 0;
1225                 DEBUG("Flow %p removed", (void *)flow);
1226         }
1227 }
1228
1229 /**
1230  * Add all flows.
1231  *
1232  * @param priv
1233  *   Pointer to private structure.
1234  *
1235  * @return
1236  *   0 on success, a errno value otherwise and rte_errno is set.
1237  */
1238 int
1239 priv_flow_start(struct priv *priv)
1240 {
1241         struct rte_flow *flow;
1242
1243         for (flow = LIST_FIRST(&priv->flows);
1244              flow;
1245              flow = LIST_NEXT(flow, next)) {
1246                 flow->ibv_flow = ibv_exp_create_flow(flow->qp,
1247                                                      flow->ibv_attr);
1248                 if (!flow->ibv_flow) {
1249                         DEBUG("Flow %p cannot be applied", (void *)flow);
1250                         rte_errno = EINVAL;
1251                         return rte_errno;
1252                 }
1253                 DEBUG("Flow %p applied", (void *)flow);
1254                 if (flow->rxq)
1255                         flow->rxq->mark |= flow->mark;
1256         }
1257         return 0;
1258 }