ethdev: support PF index in representor
[dpdk.git] / lib / librte_ethdev / rte_flow.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2016 6WIND S.A.
3  * Copyright 2016 Mellanox Technologies, Ltd
4  */
5
6 #include <errno.h>
7 #include <stddef.h>
8 #include <stdint.h>
9 #include <string.h>
10
11 #include <rte_common.h>
12 #include <rte_errno.h>
13 #include <rte_branch_prediction.h>
14 #include <rte_string_fns.h>
15 #include <rte_mbuf.h>
16 #include <rte_mbuf_dyn.h>
17 #include "rte_ethdev.h"
18 #include "rte_flow_driver.h"
19 #include "rte_flow.h"
20
21 /* Mbuf dynamic field name for metadata. */
22 int32_t rte_flow_dynf_metadata_offs = -1;
23
24 /* Mbuf dynamic field flag bit number for metadata. */
25 uint64_t rte_flow_dynf_metadata_mask;
26
27 /**
28  * Flow elements description tables.
29  */
30 struct rte_flow_desc_data {
31         const char *name;
32         size_t size;
33 };
34
35 /** Generate flow_item[] entry. */
36 #define MK_FLOW_ITEM(t, s) \
37         [RTE_FLOW_ITEM_TYPE_ ## t] = { \
38                 .name = # t, \
39                 .size = s, \
40         }
41
42 /** Information about known flow pattern items. */
43 static const struct rte_flow_desc_data rte_flow_desc_item[] = {
44         MK_FLOW_ITEM(END, 0),
45         MK_FLOW_ITEM(VOID, 0),
46         MK_FLOW_ITEM(INVERT, 0),
47         MK_FLOW_ITEM(ANY, sizeof(struct rte_flow_item_any)),
48         MK_FLOW_ITEM(PF, 0),
49         MK_FLOW_ITEM(VF, sizeof(struct rte_flow_item_vf)),
50         MK_FLOW_ITEM(PHY_PORT, sizeof(struct rte_flow_item_phy_port)),
51         MK_FLOW_ITEM(PORT_ID, sizeof(struct rte_flow_item_port_id)),
52         MK_FLOW_ITEM(RAW, sizeof(struct rte_flow_item_raw)),
53         MK_FLOW_ITEM(ETH, sizeof(struct rte_flow_item_eth)),
54         MK_FLOW_ITEM(VLAN, sizeof(struct rte_flow_item_vlan)),
55         MK_FLOW_ITEM(IPV4, sizeof(struct rte_flow_item_ipv4)),
56         MK_FLOW_ITEM(IPV6, sizeof(struct rte_flow_item_ipv6)),
57         MK_FLOW_ITEM(ICMP, sizeof(struct rte_flow_item_icmp)),
58         MK_FLOW_ITEM(UDP, sizeof(struct rte_flow_item_udp)),
59         MK_FLOW_ITEM(TCP, sizeof(struct rte_flow_item_tcp)),
60         MK_FLOW_ITEM(SCTP, sizeof(struct rte_flow_item_sctp)),
61         MK_FLOW_ITEM(VXLAN, sizeof(struct rte_flow_item_vxlan)),
62         MK_FLOW_ITEM(E_TAG, sizeof(struct rte_flow_item_e_tag)),
63         MK_FLOW_ITEM(NVGRE, sizeof(struct rte_flow_item_nvgre)),
64         MK_FLOW_ITEM(MPLS, sizeof(struct rte_flow_item_mpls)),
65         MK_FLOW_ITEM(GRE, sizeof(struct rte_flow_item_gre)),
66         MK_FLOW_ITEM(FUZZY, sizeof(struct rte_flow_item_fuzzy)),
67         MK_FLOW_ITEM(GTP, sizeof(struct rte_flow_item_gtp)),
68         MK_FLOW_ITEM(GTPC, sizeof(struct rte_flow_item_gtp)),
69         MK_FLOW_ITEM(GTPU, sizeof(struct rte_flow_item_gtp)),
70         MK_FLOW_ITEM(ESP, sizeof(struct rte_flow_item_esp)),
71         MK_FLOW_ITEM(GENEVE, sizeof(struct rte_flow_item_geneve)),
72         MK_FLOW_ITEM(VXLAN_GPE, sizeof(struct rte_flow_item_vxlan_gpe)),
73         MK_FLOW_ITEM(ARP_ETH_IPV4, sizeof(struct rte_flow_item_arp_eth_ipv4)),
74         MK_FLOW_ITEM(IPV6_EXT, sizeof(struct rte_flow_item_ipv6_ext)),
75         MK_FLOW_ITEM(IPV6_FRAG_EXT, sizeof(struct rte_flow_item_ipv6_frag_ext)),
76         MK_FLOW_ITEM(ICMP6, sizeof(struct rte_flow_item_icmp6)),
77         MK_FLOW_ITEM(ICMP6_ND_NS, sizeof(struct rte_flow_item_icmp6_nd_ns)),
78         MK_FLOW_ITEM(ICMP6_ND_NA, sizeof(struct rte_flow_item_icmp6_nd_na)),
79         MK_FLOW_ITEM(ICMP6_ND_OPT, sizeof(struct rte_flow_item_icmp6_nd_opt)),
80         MK_FLOW_ITEM(ICMP6_ND_OPT_SLA_ETH,
81                      sizeof(struct rte_flow_item_icmp6_nd_opt_sla_eth)),
82         MK_FLOW_ITEM(ICMP6_ND_OPT_TLA_ETH,
83                      sizeof(struct rte_flow_item_icmp6_nd_opt_tla_eth)),
84         MK_FLOW_ITEM(MARK, sizeof(struct rte_flow_item_mark)),
85         MK_FLOW_ITEM(META, sizeof(struct rte_flow_item_meta)),
86         MK_FLOW_ITEM(TAG, sizeof(struct rte_flow_item_tag)),
87         MK_FLOW_ITEM(GRE_KEY, sizeof(rte_be32_t)),
88         MK_FLOW_ITEM(GTP_PSC, sizeof(struct rte_flow_item_gtp_psc)),
89         MK_FLOW_ITEM(PPPOES, sizeof(struct rte_flow_item_pppoe)),
90         MK_FLOW_ITEM(PPPOED, sizeof(struct rte_flow_item_pppoe)),
91         MK_FLOW_ITEM(PPPOE_PROTO_ID,
92                         sizeof(struct rte_flow_item_pppoe_proto_id)),
93         MK_FLOW_ITEM(NSH, sizeof(struct rte_flow_item_nsh)),
94         MK_FLOW_ITEM(IGMP, sizeof(struct rte_flow_item_igmp)),
95         MK_FLOW_ITEM(AH, sizeof(struct rte_flow_item_ah)),
96         MK_FLOW_ITEM(HIGIG2, sizeof(struct rte_flow_item_higig2_hdr)),
97         MK_FLOW_ITEM(L2TPV3OIP, sizeof(struct rte_flow_item_l2tpv3oip)),
98         MK_FLOW_ITEM(PFCP, sizeof(struct rte_flow_item_pfcp)),
99         MK_FLOW_ITEM(ECPRI, sizeof(struct rte_flow_item_ecpri)),
100         MK_FLOW_ITEM(GENEVE_OPT, sizeof(struct rte_flow_item_geneve_opt)),
101 };
102
103 /** Generate flow_action[] entry. */
104 #define MK_FLOW_ACTION(t, s) \
105         [RTE_FLOW_ACTION_TYPE_ ## t] = { \
106                 .name = # t, \
107                 .size = s, \
108         }
109
110 /** Information about known flow actions. */
111 static const struct rte_flow_desc_data rte_flow_desc_action[] = {
112         MK_FLOW_ACTION(END, 0),
113         MK_FLOW_ACTION(VOID, 0),
114         MK_FLOW_ACTION(PASSTHRU, 0),
115         MK_FLOW_ACTION(JUMP, sizeof(struct rte_flow_action_jump)),
116         MK_FLOW_ACTION(MARK, sizeof(struct rte_flow_action_mark)),
117         MK_FLOW_ACTION(FLAG, 0),
118         MK_FLOW_ACTION(QUEUE, sizeof(struct rte_flow_action_queue)),
119         MK_FLOW_ACTION(DROP, 0),
120         MK_FLOW_ACTION(COUNT, sizeof(struct rte_flow_action_count)),
121         MK_FLOW_ACTION(RSS, sizeof(struct rte_flow_action_rss)),
122         MK_FLOW_ACTION(PF, 0),
123         MK_FLOW_ACTION(VF, sizeof(struct rte_flow_action_vf)),
124         MK_FLOW_ACTION(PHY_PORT, sizeof(struct rte_flow_action_phy_port)),
125         MK_FLOW_ACTION(PORT_ID, sizeof(struct rte_flow_action_port_id)),
126         MK_FLOW_ACTION(METER, sizeof(struct rte_flow_action_meter)),
127         MK_FLOW_ACTION(SECURITY, sizeof(struct rte_flow_action_security)),
128         MK_FLOW_ACTION(OF_SET_MPLS_TTL,
129                        sizeof(struct rte_flow_action_of_set_mpls_ttl)),
130         MK_FLOW_ACTION(OF_DEC_MPLS_TTL, 0),
131         MK_FLOW_ACTION(OF_SET_NW_TTL,
132                        sizeof(struct rte_flow_action_of_set_nw_ttl)),
133         MK_FLOW_ACTION(OF_DEC_NW_TTL, 0),
134         MK_FLOW_ACTION(OF_COPY_TTL_OUT, 0),
135         MK_FLOW_ACTION(OF_COPY_TTL_IN, 0),
136         MK_FLOW_ACTION(OF_POP_VLAN, 0),
137         MK_FLOW_ACTION(OF_PUSH_VLAN,
138                        sizeof(struct rte_flow_action_of_push_vlan)),
139         MK_FLOW_ACTION(OF_SET_VLAN_VID,
140                        sizeof(struct rte_flow_action_of_set_vlan_vid)),
141         MK_FLOW_ACTION(OF_SET_VLAN_PCP,
142                        sizeof(struct rte_flow_action_of_set_vlan_pcp)),
143         MK_FLOW_ACTION(OF_POP_MPLS,
144                        sizeof(struct rte_flow_action_of_pop_mpls)),
145         MK_FLOW_ACTION(OF_PUSH_MPLS,
146                        sizeof(struct rte_flow_action_of_push_mpls)),
147         MK_FLOW_ACTION(VXLAN_ENCAP, sizeof(struct rte_flow_action_vxlan_encap)),
148         MK_FLOW_ACTION(VXLAN_DECAP, 0),
149         MK_FLOW_ACTION(NVGRE_ENCAP, sizeof(struct rte_flow_action_vxlan_encap)),
150         MK_FLOW_ACTION(NVGRE_DECAP, 0),
151         MK_FLOW_ACTION(RAW_ENCAP, sizeof(struct rte_flow_action_raw_encap)),
152         MK_FLOW_ACTION(RAW_DECAP, sizeof(struct rte_flow_action_raw_decap)),
153         MK_FLOW_ACTION(SET_IPV4_SRC,
154                        sizeof(struct rte_flow_action_set_ipv4)),
155         MK_FLOW_ACTION(SET_IPV4_DST,
156                        sizeof(struct rte_flow_action_set_ipv4)),
157         MK_FLOW_ACTION(SET_IPV6_SRC,
158                        sizeof(struct rte_flow_action_set_ipv6)),
159         MK_FLOW_ACTION(SET_IPV6_DST,
160                        sizeof(struct rte_flow_action_set_ipv6)),
161         MK_FLOW_ACTION(SET_TP_SRC,
162                        sizeof(struct rte_flow_action_set_tp)),
163         MK_FLOW_ACTION(SET_TP_DST,
164                        sizeof(struct rte_flow_action_set_tp)),
165         MK_FLOW_ACTION(MAC_SWAP, 0),
166         MK_FLOW_ACTION(DEC_TTL, 0),
167         MK_FLOW_ACTION(SET_TTL, sizeof(struct rte_flow_action_set_ttl)),
168         MK_FLOW_ACTION(SET_MAC_SRC, sizeof(struct rte_flow_action_set_mac)),
169         MK_FLOW_ACTION(SET_MAC_DST, sizeof(struct rte_flow_action_set_mac)),
170         MK_FLOW_ACTION(INC_TCP_SEQ, sizeof(rte_be32_t)),
171         MK_FLOW_ACTION(DEC_TCP_SEQ, sizeof(rte_be32_t)),
172         MK_FLOW_ACTION(INC_TCP_ACK, sizeof(rte_be32_t)),
173         MK_FLOW_ACTION(DEC_TCP_ACK, sizeof(rte_be32_t)),
174         MK_FLOW_ACTION(SET_TAG, sizeof(struct rte_flow_action_set_tag)),
175         MK_FLOW_ACTION(SET_META, sizeof(struct rte_flow_action_set_meta)),
176         MK_FLOW_ACTION(SET_IPV4_DSCP, sizeof(struct rte_flow_action_set_dscp)),
177         MK_FLOW_ACTION(SET_IPV6_DSCP, sizeof(struct rte_flow_action_set_dscp)),
178         MK_FLOW_ACTION(AGE, sizeof(struct rte_flow_action_age)),
179         MK_FLOW_ACTION(SAMPLE, sizeof(struct rte_flow_action_sample)),
180         MK_FLOW_ACTION(MODIFY_FIELD,
181                        sizeof(struct rte_flow_action_modify_field)),
182         /**
183          * Shared action represented as handle of type
184          * (struct rte_flow_shared action *) stored in conf field (see
185          * struct rte_flow_action); no need for additional structure to * store
186          * shared action handle.
187          */
188         MK_FLOW_ACTION(SHARED, 0),
189 };
190
191 int
192 rte_flow_dynf_metadata_register(void)
193 {
194         int offset;
195         int flag;
196
197         static const struct rte_mbuf_dynfield desc_offs = {
198                 .name = RTE_MBUF_DYNFIELD_METADATA_NAME,
199                 .size = sizeof(uint32_t),
200                 .align = __alignof__(uint32_t),
201         };
202         static const struct rte_mbuf_dynflag desc_flag = {
203                 .name = RTE_MBUF_DYNFLAG_METADATA_NAME,
204         };
205
206         offset = rte_mbuf_dynfield_register(&desc_offs);
207         if (offset < 0)
208                 goto error;
209         flag = rte_mbuf_dynflag_register(&desc_flag);
210         if (flag < 0)
211                 goto error;
212         rte_flow_dynf_metadata_offs = offset;
213         rte_flow_dynf_metadata_mask = (1ULL << flag);
214         return 0;
215
216 error:
217         rte_flow_dynf_metadata_offs = -1;
218         rte_flow_dynf_metadata_mask = 0ULL;
219         return -rte_errno;
220 }
221
222 static inline void
223 fts_enter(struct rte_eth_dev *dev)
224 {
225         if (!(dev->data->dev_flags & RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE))
226                 pthread_mutex_lock(&dev->data->flow_ops_mutex);
227 }
228
229 static inline void
230 fts_exit(struct rte_eth_dev *dev)
231 {
232         if (!(dev->data->dev_flags & RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE))
233                 pthread_mutex_unlock(&dev->data->flow_ops_mutex);
234 }
235
236 static int
237 flow_err(uint16_t port_id, int ret, struct rte_flow_error *error)
238 {
239         if (ret == 0)
240                 return 0;
241         if (rte_eth_dev_is_removed(port_id))
242                 return rte_flow_error_set(error, EIO,
243                                           RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
244                                           NULL, rte_strerror(EIO));
245         return ret;
246 }
247
248 /* Get generic flow operations structure from a port. */
249 const struct rte_flow_ops *
250 rte_flow_ops_get(uint16_t port_id, struct rte_flow_error *error)
251 {
252         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
253         const struct rte_flow_ops *ops;
254         int code;
255
256         if (unlikely(!rte_eth_dev_is_valid_port(port_id)))
257                 code = ENODEV;
258         else if (unlikely(!dev->dev_ops->filter_ctrl ||
259                           dev->dev_ops->filter_ctrl(dev,
260                                                     RTE_ETH_FILTER_GENERIC,
261                                                     RTE_ETH_FILTER_GET,
262                                                     &ops) ||
263                           !ops))
264                 code = ENOSYS;
265         else
266                 return ops;
267         rte_flow_error_set(error, code, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
268                            NULL, rte_strerror(code));
269         return NULL;
270 }
271
272 /* Check whether a flow rule can be created on a given port. */
273 int
274 rte_flow_validate(uint16_t port_id,
275                   const struct rte_flow_attr *attr,
276                   const struct rte_flow_item pattern[],
277                   const struct rte_flow_action actions[],
278                   struct rte_flow_error *error)
279 {
280         const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
281         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
282         int ret;
283
284         if (unlikely(!ops))
285                 return -rte_errno;
286         if (likely(!!ops->validate)) {
287                 fts_enter(dev);
288                 ret = ops->validate(dev, attr, pattern, actions, error);
289                 fts_exit(dev);
290                 return flow_err(port_id, ret, error);
291         }
292         return rte_flow_error_set(error, ENOSYS,
293                                   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
294                                   NULL, rte_strerror(ENOSYS));
295 }
296
297 /* Create a flow rule on a given port. */
298 struct rte_flow *
299 rte_flow_create(uint16_t port_id,
300                 const struct rte_flow_attr *attr,
301                 const struct rte_flow_item pattern[],
302                 const struct rte_flow_action actions[],
303                 struct rte_flow_error *error)
304 {
305         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
306         struct rte_flow *flow;
307         const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
308
309         if (unlikely(!ops))
310                 return NULL;
311         if (likely(!!ops->create)) {
312                 fts_enter(dev);
313                 flow = ops->create(dev, attr, pattern, actions, error);
314                 fts_exit(dev);
315                 if (flow == NULL)
316                         flow_err(port_id, -rte_errno, error);
317                 return flow;
318         }
319         rte_flow_error_set(error, ENOSYS, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
320                            NULL, rte_strerror(ENOSYS));
321         return NULL;
322 }
323
324 /* Destroy a flow rule on a given port. */
325 int
326 rte_flow_destroy(uint16_t port_id,
327                  struct rte_flow *flow,
328                  struct rte_flow_error *error)
329 {
330         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
331         const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
332         int ret;
333
334         if (unlikely(!ops))
335                 return -rte_errno;
336         if (likely(!!ops->destroy)) {
337                 fts_enter(dev);
338                 ret = ops->destroy(dev, flow, error);
339                 fts_exit(dev);
340                 return flow_err(port_id, ret, error);
341         }
342         return rte_flow_error_set(error, ENOSYS,
343                                   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
344                                   NULL, rte_strerror(ENOSYS));
345 }
346
347 /* Destroy all flow rules associated with a port. */
348 int
349 rte_flow_flush(uint16_t port_id,
350                struct rte_flow_error *error)
351 {
352         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
353         const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
354         int ret;
355
356         if (unlikely(!ops))
357                 return -rte_errno;
358         if (likely(!!ops->flush)) {
359                 fts_enter(dev);
360                 ret = ops->flush(dev, error);
361                 fts_exit(dev);
362                 return flow_err(port_id, ret, error);
363         }
364         return rte_flow_error_set(error, ENOSYS,
365                                   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
366                                   NULL, rte_strerror(ENOSYS));
367 }
368
369 /* Query an existing flow rule. */
370 int
371 rte_flow_query(uint16_t port_id,
372                struct rte_flow *flow,
373                const struct rte_flow_action *action,
374                void *data,
375                struct rte_flow_error *error)
376 {
377         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
378         const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
379         int ret;
380
381         if (!ops)
382                 return -rte_errno;
383         if (likely(!!ops->query)) {
384                 fts_enter(dev);
385                 ret = ops->query(dev, flow, action, data, error);
386                 fts_exit(dev);
387                 return flow_err(port_id, ret, error);
388         }
389         return rte_flow_error_set(error, ENOSYS,
390                                   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
391                                   NULL, rte_strerror(ENOSYS));
392 }
393
394 /* Restrict ingress traffic to the defined flow rules. */
395 int
396 rte_flow_isolate(uint16_t port_id,
397                  int set,
398                  struct rte_flow_error *error)
399 {
400         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
401         const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
402         int ret;
403
404         if (!ops)
405                 return -rte_errno;
406         if (likely(!!ops->isolate)) {
407                 fts_enter(dev);
408                 ret = ops->isolate(dev, set, error);
409                 fts_exit(dev);
410                 return flow_err(port_id, ret, error);
411         }
412         return rte_flow_error_set(error, ENOSYS,
413                                   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
414                                   NULL, rte_strerror(ENOSYS));
415 }
416
417 /* Initialize flow error structure. */
418 int
419 rte_flow_error_set(struct rte_flow_error *error,
420                    int code,
421                    enum rte_flow_error_type type,
422                    const void *cause,
423                    const char *message)
424 {
425         if (error) {
426                 *error = (struct rte_flow_error){
427                         .type = type,
428                         .cause = cause,
429                         .message = message,
430                 };
431         }
432         rte_errno = code;
433         return -code;
434 }
435
436 /** Pattern item specification types. */
437 enum rte_flow_conv_item_spec_type {
438         RTE_FLOW_CONV_ITEM_SPEC,
439         RTE_FLOW_CONV_ITEM_LAST,
440         RTE_FLOW_CONV_ITEM_MASK,
441 };
442
443 /**
444  * Copy pattern item specification.
445  *
446  * @param[out] buf
447  *   Output buffer. Can be NULL if @p size is zero.
448  * @param size
449  *   Size of @p buf in bytes.
450  * @param[in] item
451  *   Pattern item to copy specification from.
452  * @param type
453  *   Specification selector for either @p spec, @p last or @p mask.
454  *
455  * @return
456  *   Number of bytes needed to store pattern item specification regardless
457  *   of @p size. @p buf contents are truncated to @p size if not large
458  *   enough.
459  */
460 static size_t
461 rte_flow_conv_item_spec(void *buf, const size_t size,
462                         const struct rte_flow_item *item,
463                         enum rte_flow_conv_item_spec_type type)
464 {
465         size_t off;
466         const void *data =
467                 type == RTE_FLOW_CONV_ITEM_SPEC ? item->spec :
468                 type == RTE_FLOW_CONV_ITEM_LAST ? item->last :
469                 type == RTE_FLOW_CONV_ITEM_MASK ? item->mask :
470                 NULL;
471
472         switch (item->type) {
473                 union {
474                         const struct rte_flow_item_raw *raw;
475                 } spec;
476                 union {
477                         const struct rte_flow_item_raw *raw;
478                 } last;
479                 union {
480                         const struct rte_flow_item_raw *raw;
481                 } mask;
482                 union {
483                         const struct rte_flow_item_raw *raw;
484                 } src;
485                 union {
486                         struct rte_flow_item_raw *raw;
487                 } dst;
488                 size_t tmp;
489
490         case RTE_FLOW_ITEM_TYPE_RAW:
491                 spec.raw = item->spec;
492                 last.raw = item->last ? item->last : item->spec;
493                 mask.raw = item->mask ? item->mask : &rte_flow_item_raw_mask;
494                 src.raw = data;
495                 dst.raw = buf;
496                 rte_memcpy(dst.raw,
497                            (&(struct rte_flow_item_raw){
498                                 .relative = src.raw->relative,
499                                 .search = src.raw->search,
500                                 .reserved = src.raw->reserved,
501                                 .offset = src.raw->offset,
502                                 .limit = src.raw->limit,
503                                 .length = src.raw->length,
504                            }),
505                            size > sizeof(*dst.raw) ? sizeof(*dst.raw) : size);
506                 off = sizeof(*dst.raw);
507                 if (type == RTE_FLOW_CONV_ITEM_SPEC ||
508                     (type == RTE_FLOW_CONV_ITEM_MASK &&
509                      ((spec.raw->length & mask.raw->length) >=
510                       (last.raw->length & mask.raw->length))))
511                         tmp = spec.raw->length & mask.raw->length;
512                 else
513                         tmp = last.raw->length & mask.raw->length;
514                 if (tmp) {
515                         off = RTE_ALIGN_CEIL(off, sizeof(*dst.raw->pattern));
516                         if (size >= off + tmp)
517                                 dst.raw->pattern = rte_memcpy
518                                         ((void *)((uintptr_t)dst.raw + off),
519                                          src.raw->pattern, tmp);
520                         off += tmp;
521                 }
522                 break;
523         default:
524                 /**
525                  * allow PMD private flow item
526                  */
527                 off = (int)item->type >= 0 ?
528                       rte_flow_desc_item[item->type].size : sizeof(void *);
529                 rte_memcpy(buf, data, (size > off ? off : size));
530                 break;
531         }
532         return off;
533 }
534
535 /**
536  * Copy action configuration.
537  *
538  * @param[out] buf
539  *   Output buffer. Can be NULL if @p size is zero.
540  * @param size
541  *   Size of @p buf in bytes.
542  * @param[in] action
543  *   Action to copy configuration from.
544  *
545  * @return
546  *   Number of bytes needed to store pattern item specification regardless
547  *   of @p size. @p buf contents are truncated to @p size if not large
548  *   enough.
549  */
550 static size_t
551 rte_flow_conv_action_conf(void *buf, const size_t size,
552                           const struct rte_flow_action *action)
553 {
554         size_t off;
555
556         switch (action->type) {
557                 union {
558                         const struct rte_flow_action_rss *rss;
559                         const struct rte_flow_action_vxlan_encap *vxlan_encap;
560                         const struct rte_flow_action_nvgre_encap *nvgre_encap;
561                 } src;
562                 union {
563                         struct rte_flow_action_rss *rss;
564                         struct rte_flow_action_vxlan_encap *vxlan_encap;
565                         struct rte_flow_action_nvgre_encap *nvgre_encap;
566                 } dst;
567                 size_t tmp;
568                 int ret;
569
570         case RTE_FLOW_ACTION_TYPE_RSS:
571                 src.rss = action->conf;
572                 dst.rss = buf;
573                 rte_memcpy(dst.rss,
574                            (&(struct rte_flow_action_rss){
575                                 .func = src.rss->func,
576                                 .level = src.rss->level,
577                                 .types = src.rss->types,
578                                 .key_len = src.rss->key_len,
579                                 .queue_num = src.rss->queue_num,
580                            }),
581                            size > sizeof(*dst.rss) ? sizeof(*dst.rss) : size);
582                 off = sizeof(*dst.rss);
583                 if (src.rss->key_len && src.rss->key) {
584                         off = RTE_ALIGN_CEIL(off, sizeof(*dst.rss->key));
585                         tmp = sizeof(*src.rss->key) * src.rss->key_len;
586                         if (size >= off + tmp)
587                                 dst.rss->key = rte_memcpy
588                                         ((void *)((uintptr_t)dst.rss + off),
589                                          src.rss->key, tmp);
590                         off += tmp;
591                 }
592                 if (src.rss->queue_num) {
593                         off = RTE_ALIGN_CEIL(off, sizeof(*dst.rss->queue));
594                         tmp = sizeof(*src.rss->queue) * src.rss->queue_num;
595                         if (size >= off + tmp)
596                                 dst.rss->queue = rte_memcpy
597                                         ((void *)((uintptr_t)dst.rss + off),
598                                          src.rss->queue, tmp);
599                         off += tmp;
600                 }
601                 break;
602         case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
603         case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
604                 src.vxlan_encap = action->conf;
605                 dst.vxlan_encap = buf;
606                 RTE_BUILD_BUG_ON(sizeof(*src.vxlan_encap) !=
607                                  sizeof(*src.nvgre_encap) ||
608                                  offsetof(struct rte_flow_action_vxlan_encap,
609                                           definition) !=
610                                  offsetof(struct rte_flow_action_nvgre_encap,
611                                           definition));
612                 off = sizeof(*dst.vxlan_encap);
613                 if (src.vxlan_encap->definition) {
614                         off = RTE_ALIGN_CEIL
615                                 (off, sizeof(*dst.vxlan_encap->definition));
616                         ret = rte_flow_conv
617                                 (RTE_FLOW_CONV_OP_PATTERN,
618                                  (void *)((uintptr_t)dst.vxlan_encap + off),
619                                  size > off ? size - off : 0,
620                                  src.vxlan_encap->definition, NULL);
621                         if (ret < 0)
622                                 return 0;
623                         if (size >= off + ret)
624                                 dst.vxlan_encap->definition =
625                                         (void *)((uintptr_t)dst.vxlan_encap +
626                                                  off);
627                         off += ret;
628                 }
629                 break;
630         default:
631                 /**
632                  * allow PMD private flow action
633                  */
634                 off = (int)action->type >= 0 ?
635                       rte_flow_desc_action[action->type].size : sizeof(void *);
636                 rte_memcpy(buf, action->conf, (size > off ? off : size));
637                 break;
638         }
639         return off;
640 }
641
642 /**
643  * Copy a list of pattern items.
644  *
645  * @param[out] dst
646  *   Destination buffer. Can be NULL if @p size is zero.
647  * @param size
648  *   Size of @p dst in bytes.
649  * @param[in] src
650  *   Source pattern items.
651  * @param num
652  *   Maximum number of pattern items to process from @p src or 0 to process
653  *   the entire list. In both cases, processing stops after
654  *   RTE_FLOW_ITEM_TYPE_END is encountered.
655  * @param[out] error
656  *   Perform verbose error reporting if not NULL.
657  *
658  * @return
659  *   A positive value representing the number of bytes needed to store
660  *   pattern items regardless of @p size on success (@p buf contents are
661  *   truncated to @p size if not large enough), a negative errno value
662  *   otherwise and rte_errno is set.
663  */
664 static int
665 rte_flow_conv_pattern(struct rte_flow_item *dst,
666                       const size_t size,
667                       const struct rte_flow_item *src,
668                       unsigned int num,
669                       struct rte_flow_error *error)
670 {
671         uintptr_t data = (uintptr_t)dst;
672         size_t off;
673         size_t ret;
674         unsigned int i;
675
676         for (i = 0, off = 0; !num || i != num; ++i, ++src, ++dst) {
677                 /**
678                  * allow PMD private flow item
679                  */
680                 if (((int)src->type >= 0) &&
681                         ((size_t)src->type >= RTE_DIM(rte_flow_desc_item) ||
682                     !rte_flow_desc_item[src->type].name))
683                         return rte_flow_error_set
684                                 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, src,
685                                  "cannot convert unknown item type");
686                 if (size >= off + sizeof(*dst))
687                         *dst = (struct rte_flow_item){
688                                 .type = src->type,
689                         };
690                 off += sizeof(*dst);
691                 if (!src->type)
692                         num = i + 1;
693         }
694         num = i;
695         src -= num;
696         dst -= num;
697         do {
698                 if (src->spec) {
699                         off = RTE_ALIGN_CEIL(off, sizeof(double));
700                         ret = rte_flow_conv_item_spec
701                                 ((void *)(data + off),
702                                  size > off ? size - off : 0, src,
703                                  RTE_FLOW_CONV_ITEM_SPEC);
704                         if (size && size >= off + ret)
705                                 dst->spec = (void *)(data + off);
706                         off += ret;
707
708                 }
709                 if (src->last) {
710                         off = RTE_ALIGN_CEIL(off, sizeof(double));
711                         ret = rte_flow_conv_item_spec
712                                 ((void *)(data + off),
713                                  size > off ? size - off : 0, src,
714                                  RTE_FLOW_CONV_ITEM_LAST);
715                         if (size && size >= off + ret)
716                                 dst->last = (void *)(data + off);
717                         off += ret;
718                 }
719                 if (src->mask) {
720                         off = RTE_ALIGN_CEIL(off, sizeof(double));
721                         ret = rte_flow_conv_item_spec
722                                 ((void *)(data + off),
723                                  size > off ? size - off : 0, src,
724                                  RTE_FLOW_CONV_ITEM_MASK);
725                         if (size && size >= off + ret)
726                                 dst->mask = (void *)(data + off);
727                         off += ret;
728                 }
729                 ++src;
730                 ++dst;
731         } while (--num);
732         return off;
733 }
734
735 /**
736  * Copy a list of actions.
737  *
738  * @param[out] dst
739  *   Destination buffer. Can be NULL if @p size is zero.
740  * @param size
741  *   Size of @p dst in bytes.
742  * @param[in] src
743  *   Source actions.
744  * @param num
745  *   Maximum number of actions to process from @p src or 0 to process the
746  *   entire list. In both cases, processing stops after
747  *   RTE_FLOW_ACTION_TYPE_END is encountered.
748  * @param[out] error
749  *   Perform verbose error reporting if not NULL.
750  *
751  * @return
752  *   A positive value representing the number of bytes needed to store
753  *   actions regardless of @p size on success (@p buf contents are truncated
754  *   to @p size if not large enough), a negative errno value otherwise and
755  *   rte_errno is set.
756  */
757 static int
758 rte_flow_conv_actions(struct rte_flow_action *dst,
759                       const size_t size,
760                       const struct rte_flow_action *src,
761                       unsigned int num,
762                       struct rte_flow_error *error)
763 {
764         uintptr_t data = (uintptr_t)dst;
765         size_t off;
766         size_t ret;
767         unsigned int i;
768
769         for (i = 0, off = 0; !num || i != num; ++i, ++src, ++dst) {
770                 /**
771                  * allow PMD private flow action
772                  */
773                 if (((int)src->type >= 0) &&
774                     ((size_t)src->type >= RTE_DIM(rte_flow_desc_action) ||
775                     !rte_flow_desc_action[src->type].name))
776                         return rte_flow_error_set
777                                 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
778                                  src, "cannot convert unknown action type");
779                 if (size >= off + sizeof(*dst))
780                         *dst = (struct rte_flow_action){
781                                 .type = src->type,
782                         };
783                 off += sizeof(*dst);
784                 if (!src->type)
785                         num = i + 1;
786         }
787         num = i;
788         src -= num;
789         dst -= num;
790         do {
791                 if (src->conf) {
792                         off = RTE_ALIGN_CEIL(off, sizeof(double));
793                         ret = rte_flow_conv_action_conf
794                                 ((void *)(data + off),
795                                  size > off ? size - off : 0, src);
796                         if (size && size >= off + ret)
797                                 dst->conf = (void *)(data + off);
798                         off += ret;
799                 }
800                 ++src;
801                 ++dst;
802         } while (--num);
803         return off;
804 }
805
806 /**
807  * Copy flow rule components.
808  *
809  * This comprises the flow rule descriptor itself, attributes, pattern and
810  * actions list. NULL components in @p src are skipped.
811  *
812  * @param[out] dst
813  *   Destination buffer. Can be NULL if @p size is zero.
814  * @param size
815  *   Size of @p dst in bytes.
816  * @param[in] src
817  *   Source flow rule descriptor.
818  * @param[out] error
819  *   Perform verbose error reporting if not NULL.
820  *
821  * @return
822  *   A positive value representing the number of bytes needed to store all
823  *   components including the descriptor regardless of @p size on success
824  *   (@p buf contents are truncated to @p size if not large enough), a
825  *   negative errno value otherwise and rte_errno is set.
826  */
827 static int
828 rte_flow_conv_rule(struct rte_flow_conv_rule *dst,
829                    const size_t size,
830                    const struct rte_flow_conv_rule *src,
831                    struct rte_flow_error *error)
832 {
833         size_t off;
834         int ret;
835
836         rte_memcpy(dst,
837                    (&(struct rte_flow_conv_rule){
838                         .attr = NULL,
839                         .pattern = NULL,
840                         .actions = NULL,
841                    }),
842                    size > sizeof(*dst) ? sizeof(*dst) : size);
843         off = sizeof(*dst);
844         if (src->attr_ro) {
845                 off = RTE_ALIGN_CEIL(off, sizeof(double));
846                 if (size && size >= off + sizeof(*dst->attr))
847                         dst->attr = rte_memcpy
848                                 ((void *)((uintptr_t)dst + off),
849                                  src->attr_ro, sizeof(*dst->attr));
850                 off += sizeof(*dst->attr);
851         }
852         if (src->pattern_ro) {
853                 off = RTE_ALIGN_CEIL(off, sizeof(double));
854                 ret = rte_flow_conv_pattern((void *)((uintptr_t)dst + off),
855                                             size > off ? size - off : 0,
856                                             src->pattern_ro, 0, error);
857                 if (ret < 0)
858                         return ret;
859                 if (size && size >= off + (size_t)ret)
860                         dst->pattern = (void *)((uintptr_t)dst + off);
861                 off += ret;
862         }
863         if (src->actions_ro) {
864                 off = RTE_ALIGN_CEIL(off, sizeof(double));
865                 ret = rte_flow_conv_actions((void *)((uintptr_t)dst + off),
866                                             size > off ? size - off : 0,
867                                             src->actions_ro, 0, error);
868                 if (ret < 0)
869                         return ret;
870                 if (size >= off + (size_t)ret)
871                         dst->actions = (void *)((uintptr_t)dst + off);
872                 off += ret;
873         }
874         return off;
875 }
876
877 /**
878  * Retrieve the name of a pattern item/action type.
879  *
880  * @param is_action
881  *   Nonzero when @p src represents an action type instead of a pattern item
882  *   type.
883  * @param is_ptr
884  *   Nonzero to write string address instead of contents into @p dst.
885  * @param[out] dst
886  *   Destination buffer. Can be NULL if @p size is zero.
887  * @param size
888  *   Size of @p dst in bytes.
889  * @param[in] src
890  *   Depending on @p is_action, source pattern item or action type cast as a
891  *   pointer.
892  * @param[out] error
893  *   Perform verbose error reporting if not NULL.
894  *
895  * @return
896  *   A positive value representing the number of bytes needed to store the
897  *   name or its address regardless of @p size on success (@p buf contents
898  *   are truncated to @p size if not large enough), a negative errno value
899  *   otherwise and rte_errno is set.
900  */
901 static int
902 rte_flow_conv_name(int is_action,
903                    int is_ptr,
904                    char *dst,
905                    const size_t size,
906                    const void *src,
907                    struct rte_flow_error *error)
908 {
909         struct desc_info {
910                 const struct rte_flow_desc_data *data;
911                 size_t num;
912         };
913         static const struct desc_info info_rep[2] = {
914                 { rte_flow_desc_item, RTE_DIM(rte_flow_desc_item), },
915                 { rte_flow_desc_action, RTE_DIM(rte_flow_desc_action), },
916         };
917         const struct desc_info *const info = &info_rep[!!is_action];
918         unsigned int type = (uintptr_t)src;
919
920         if (type >= info->num)
921                 return rte_flow_error_set
922                         (error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
923                          "unknown object type to retrieve the name of");
924         if (!is_ptr)
925                 return strlcpy(dst, info->data[type].name, size);
926         if (size >= sizeof(const char **))
927                 *((const char **)dst) = info->data[type].name;
928         return sizeof(const char **);
929 }
930
931 /** Helper function to convert flow API objects. */
932 int
933 rte_flow_conv(enum rte_flow_conv_op op,
934               void *dst,
935               size_t size,
936               const void *src,
937               struct rte_flow_error *error)
938 {
939         switch (op) {
940                 const struct rte_flow_attr *attr;
941
942         case RTE_FLOW_CONV_OP_NONE:
943                 return 0;
944         case RTE_FLOW_CONV_OP_ATTR:
945                 attr = src;
946                 if (size > sizeof(*attr))
947                         size = sizeof(*attr);
948                 rte_memcpy(dst, attr, size);
949                 return sizeof(*attr);
950         case RTE_FLOW_CONV_OP_ITEM:
951                 return rte_flow_conv_pattern(dst, size, src, 1, error);
952         case RTE_FLOW_CONV_OP_ACTION:
953                 return rte_flow_conv_actions(dst, size, src, 1, error);
954         case RTE_FLOW_CONV_OP_PATTERN:
955                 return rte_flow_conv_pattern(dst, size, src, 0, error);
956         case RTE_FLOW_CONV_OP_ACTIONS:
957                 return rte_flow_conv_actions(dst, size, src, 0, error);
958         case RTE_FLOW_CONV_OP_RULE:
959                 return rte_flow_conv_rule(dst, size, src, error);
960         case RTE_FLOW_CONV_OP_ITEM_NAME:
961                 return rte_flow_conv_name(0, 0, dst, size, src, error);
962         case RTE_FLOW_CONV_OP_ACTION_NAME:
963                 return rte_flow_conv_name(1, 0, dst, size, src, error);
964         case RTE_FLOW_CONV_OP_ITEM_NAME_PTR:
965                 return rte_flow_conv_name(0, 1, dst, size, src, error);
966         case RTE_FLOW_CONV_OP_ACTION_NAME_PTR:
967                 return rte_flow_conv_name(1, 1, dst, size, src, error);
968         }
969         return rte_flow_error_set
970                 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
971                  "unknown object conversion operation");
972 }
973
974 /** Store a full rte_flow description. */
975 size_t
976 rte_flow_copy(struct rte_flow_desc *desc, size_t len,
977               const struct rte_flow_attr *attr,
978               const struct rte_flow_item *items,
979               const struct rte_flow_action *actions)
980 {
981         /*
982          * Overlap struct rte_flow_conv with struct rte_flow_desc in order
983          * to convert the former to the latter without wasting space.
984          */
985         struct rte_flow_conv_rule *dst =
986                 len ?
987                 (void *)((uintptr_t)desc +
988                          (offsetof(struct rte_flow_desc, actions) -
989                           offsetof(struct rte_flow_conv_rule, actions))) :
990                 NULL;
991         size_t dst_size =
992                 len > sizeof(*desc) - sizeof(*dst) ?
993                 len - (sizeof(*desc) - sizeof(*dst)) :
994                 0;
995         struct rte_flow_conv_rule src = {
996                 .attr_ro = NULL,
997                 .pattern_ro = items,
998                 .actions_ro = actions,
999         };
1000         int ret;
1001
1002         RTE_BUILD_BUG_ON(sizeof(struct rte_flow_desc) <
1003                          sizeof(struct rte_flow_conv_rule));
1004         if (dst_size &&
1005             (&dst->pattern != &desc->items ||
1006              &dst->actions != &desc->actions ||
1007              (uintptr_t)(dst + 1) != (uintptr_t)(desc + 1))) {
1008                 rte_errno = EINVAL;
1009                 return 0;
1010         }
1011         ret = rte_flow_conv(RTE_FLOW_CONV_OP_RULE, dst, dst_size, &src, NULL);
1012         if (ret < 0)
1013                 return 0;
1014         ret += sizeof(*desc) - sizeof(*dst);
1015         rte_memcpy(desc,
1016                    (&(struct rte_flow_desc){
1017                         .size = ret,
1018                         .attr = *attr,
1019                         .items = dst_size ? dst->pattern : NULL,
1020                         .actions = dst_size ? dst->actions : NULL,
1021                    }),
1022                    len > sizeof(*desc) ? sizeof(*desc) : len);
1023         return ret;
1024 }
1025
1026 int
1027 rte_flow_dev_dump(uint16_t port_id, FILE *file, struct rte_flow_error *error)
1028 {
1029         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1030         const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1031         int ret;
1032
1033         if (unlikely(!ops))
1034                 return -rte_errno;
1035         if (likely(!!ops->dev_dump)) {
1036                 fts_enter(dev);
1037                 ret = ops->dev_dump(dev, file, error);
1038                 fts_exit(dev);
1039                 return flow_err(port_id, ret, error);
1040         }
1041         return rte_flow_error_set(error, ENOSYS,
1042                                   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1043                                   NULL, rte_strerror(ENOSYS));
1044 }
1045
1046 int
1047 rte_flow_get_aged_flows(uint16_t port_id, void **contexts,
1048                     uint32_t nb_contexts, struct rte_flow_error *error)
1049 {
1050         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1051         const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1052         int ret;
1053
1054         if (unlikely(!ops))
1055                 return -rte_errno;
1056         if (likely(!!ops->get_aged_flows)) {
1057                 fts_enter(dev);
1058                 ret = ops->get_aged_flows(dev, contexts, nb_contexts, error);
1059                 fts_exit(dev);
1060                 return flow_err(port_id, ret, error);
1061         }
1062         return rte_flow_error_set(error, ENOTSUP,
1063                                   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1064                                   NULL, rte_strerror(ENOTSUP));
1065 }
1066
1067 struct rte_flow_shared_action *
1068 rte_flow_shared_action_create(uint16_t port_id,
1069                               const struct rte_flow_shared_action_conf *conf,
1070                               const struct rte_flow_action *action,
1071                               struct rte_flow_error *error)
1072 {
1073         struct rte_flow_shared_action *shared_action;
1074         const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1075
1076         if (unlikely(!ops))
1077                 return NULL;
1078         if (unlikely(!ops->shared_action_create)) {
1079                 rte_flow_error_set(error, ENOSYS,
1080                                    RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1081                                    rte_strerror(ENOSYS));
1082                 return NULL;
1083         }
1084         shared_action = ops->shared_action_create(&rte_eth_devices[port_id],
1085                                                   conf, action, error);
1086         if (shared_action == NULL)
1087                 flow_err(port_id, -rte_errno, error);
1088         return shared_action;
1089 }
1090
1091 int
1092 rte_flow_shared_action_destroy(uint16_t port_id,
1093                               struct rte_flow_shared_action *action,
1094                               struct rte_flow_error *error)
1095 {
1096         int ret;
1097         const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1098
1099         if (unlikely(!ops))
1100                 return -rte_errno;
1101         if (unlikely(!ops->shared_action_destroy))
1102                 return rte_flow_error_set(error, ENOSYS,
1103                                           RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1104                                           NULL, rte_strerror(ENOSYS));
1105         ret = ops->shared_action_destroy(&rte_eth_devices[port_id], action,
1106                                          error);
1107         return flow_err(port_id, ret, error);
1108 }
1109
1110 int
1111 rte_flow_shared_action_update(uint16_t port_id,
1112                               struct rte_flow_shared_action *action,
1113                               const struct rte_flow_action *update,
1114                               struct rte_flow_error *error)
1115 {
1116         int ret;
1117         const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1118
1119         if (unlikely(!ops))
1120                 return -rte_errno;
1121         if (unlikely(!ops->shared_action_update))
1122                 return rte_flow_error_set(error, ENOSYS,
1123                                           RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1124                                           NULL, rte_strerror(ENOSYS));
1125         ret = ops->shared_action_update(&rte_eth_devices[port_id], action,
1126                                         update, error);
1127         return flow_err(port_id, ret, error);
1128 }
1129
1130 int
1131 rte_flow_shared_action_query(uint16_t port_id,
1132                              const struct rte_flow_shared_action *action,
1133                              void *data,
1134                              struct rte_flow_error *error)
1135 {
1136         int ret;
1137         const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1138
1139         if (unlikely(!ops))
1140                 return -rte_errno;
1141         if (unlikely(!ops->shared_action_query))
1142                 return rte_flow_error_set(error, ENOSYS,
1143                                           RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1144                                           NULL, rte_strerror(ENOSYS));
1145         ret = ops->shared_action_query(&rte_eth_devices[port_id], action,
1146                                        data, error);
1147         return flow_err(port_id, ret, error);
1148 }
1149
1150 int
1151 rte_flow_tunnel_decap_set(uint16_t port_id,
1152                           struct rte_flow_tunnel *tunnel,
1153                           struct rte_flow_action **actions,
1154                           uint32_t *num_of_actions,
1155                           struct rte_flow_error *error)
1156 {
1157         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1158         const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1159
1160         if (unlikely(!ops))
1161                 return -rte_errno;
1162         if (likely(!!ops->tunnel_decap_set)) {
1163                 return flow_err(port_id,
1164                                 ops->tunnel_decap_set(dev, tunnel, actions,
1165                                                       num_of_actions, error),
1166                                 error);
1167         }
1168         return rte_flow_error_set(error, ENOTSUP,
1169                                   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1170                                   NULL, rte_strerror(ENOTSUP));
1171 }
1172
1173 int
1174 rte_flow_tunnel_match(uint16_t port_id,
1175                       struct rte_flow_tunnel *tunnel,
1176                       struct rte_flow_item **items,
1177                       uint32_t *num_of_items,
1178                       struct rte_flow_error *error)
1179 {
1180         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1181         const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1182
1183         if (unlikely(!ops))
1184                 return -rte_errno;
1185         if (likely(!!ops->tunnel_match)) {
1186                 return flow_err(port_id,
1187                                 ops->tunnel_match(dev, tunnel, items,
1188                                                   num_of_items, error),
1189                                 error);
1190         }
1191         return rte_flow_error_set(error, ENOTSUP,
1192                                   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1193                                   NULL, rte_strerror(ENOTSUP));
1194 }
1195
1196 int
1197 rte_flow_get_restore_info(uint16_t port_id,
1198                           struct rte_mbuf *m,
1199                           struct rte_flow_restore_info *restore_info,
1200                           struct rte_flow_error *error)
1201 {
1202         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1203         const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1204
1205         if (unlikely(!ops))
1206                 return -rte_errno;
1207         if (likely(!!ops->get_restore_info)) {
1208                 return flow_err(port_id,
1209                                 ops->get_restore_info(dev, m, restore_info,
1210                                                       error),
1211                                 error);
1212         }
1213         return rte_flow_error_set(error, ENOTSUP,
1214                                   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1215                                   NULL, rte_strerror(ENOTSUP));
1216 }
1217
1218 int
1219 rte_flow_tunnel_action_decap_release(uint16_t port_id,
1220                                      struct rte_flow_action *actions,
1221                                      uint32_t num_of_actions,
1222                                      struct rte_flow_error *error)
1223 {
1224         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1225         const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1226
1227         if (unlikely(!ops))
1228                 return -rte_errno;
1229         if (likely(!!ops->tunnel_action_decap_release)) {
1230                 return flow_err(port_id,
1231                                 ops->tunnel_action_decap_release(dev, actions,
1232                                                                  num_of_actions,
1233                                                                  error),
1234                                 error);
1235         }
1236         return rte_flow_error_set(error, ENOTSUP,
1237                                   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1238                                   NULL, rte_strerror(ENOTSUP));
1239 }
1240
1241 int
1242 rte_flow_tunnel_item_release(uint16_t port_id,
1243                              struct rte_flow_item *items,
1244                              uint32_t num_of_items,
1245                              struct rte_flow_error *error)
1246 {
1247         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1248         const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1249
1250         if (unlikely(!ops))
1251                 return -rte_errno;
1252         if (likely(!!ops->tunnel_item_release)) {
1253                 return flow_err(port_id,
1254                                 ops->tunnel_item_release(dev, items,
1255                                                          num_of_items, error),
1256                                 error);
1257         }
1258         return rte_flow_error_set(error, ENOTSUP,
1259                                   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1260                                   NULL, rte_strerror(ENOTSUP));
1261 }