1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2016 6WIND S.A.
3 * Copyright 2016 Mellanox Technologies, Ltd
11 #include <rte_common.h>
12 #include <rte_errno.h>
13 #include <rte_branch_prediction.h>
14 #include <rte_string_fns.h>
16 #include <rte_mbuf_dyn.h>
17 #include "rte_ethdev.h"
18 #include "rte_flow_driver.h"
21 /* Mbuf dynamic field name for metadata. */
22 int32_t rte_flow_dynf_metadata_offs = -1;
24 /* Mbuf dynamic field flag bit number for metadata. */
25 uint64_t rte_flow_dynf_metadata_mask;
28 * Flow elements description tables.
30 struct rte_flow_desc_data {
33 size_t (*desc_fn)(void *dst, const void *src);
45 * rte_flow_desc_item - for flow item conversion.
46 * rte_flow_desc_action - for flow action conversion.
48 * Offset into the desc param or negative value for private flow elements.
51 rte_flow_conv_copy(void *buf, const void *data, const size_t size,
52 const struct rte_flow_desc_data *desc, int type)
55 * Allow PMD private flow item
57 bool rte_type = type >= 0;
59 size_t sz = rte_type ? desc[type].size : sizeof(void *);
60 if (buf == NULL || data == NULL)
62 rte_memcpy(buf, data, (size > sz ? sz : size));
63 if (rte_type && desc[type].desc_fn)
64 sz += desc[type].desc_fn(size > 0 ? buf : NULL, data);
69 rte_flow_item_flex_conv(void *buf, const void *data)
71 struct rte_flow_item_flex *dst = buf;
72 const struct rte_flow_item_flex *src = data;
74 dst->pattern = rte_memcpy
75 ((void *)((uintptr_t)(dst + 1)), src->pattern,
81 /** Generate flow_item[] entry. */
82 #define MK_FLOW_ITEM(t, s) \
83 [RTE_FLOW_ITEM_TYPE_ ## t] = { \
89 #define MK_FLOW_ITEM_FN(t, s, fn) \
90 [RTE_FLOW_ITEM_TYPE_ ## t] = {\
96 /** Information about known flow pattern items. */
97 static const struct rte_flow_desc_data rte_flow_desc_item[] = {
99 MK_FLOW_ITEM(VOID, 0),
100 MK_FLOW_ITEM(INVERT, 0),
101 MK_FLOW_ITEM(ANY, sizeof(struct rte_flow_item_any)),
103 MK_FLOW_ITEM(VF, sizeof(struct rte_flow_item_vf)),
104 MK_FLOW_ITEM(PHY_PORT, sizeof(struct rte_flow_item_phy_port)),
105 MK_FLOW_ITEM(PORT_ID, sizeof(struct rte_flow_item_port_id)),
106 MK_FLOW_ITEM(RAW, sizeof(struct rte_flow_item_raw)),
107 MK_FLOW_ITEM(ETH, sizeof(struct rte_flow_item_eth)),
108 MK_FLOW_ITEM(VLAN, sizeof(struct rte_flow_item_vlan)),
109 MK_FLOW_ITEM(IPV4, sizeof(struct rte_flow_item_ipv4)),
110 MK_FLOW_ITEM(IPV6, sizeof(struct rte_flow_item_ipv6)),
111 MK_FLOW_ITEM(ICMP, sizeof(struct rte_flow_item_icmp)),
112 MK_FLOW_ITEM(UDP, sizeof(struct rte_flow_item_udp)),
113 MK_FLOW_ITEM(TCP, sizeof(struct rte_flow_item_tcp)),
114 MK_FLOW_ITEM(SCTP, sizeof(struct rte_flow_item_sctp)),
115 MK_FLOW_ITEM(VXLAN, sizeof(struct rte_flow_item_vxlan)),
116 MK_FLOW_ITEM(E_TAG, sizeof(struct rte_flow_item_e_tag)),
117 MK_FLOW_ITEM(NVGRE, sizeof(struct rte_flow_item_nvgre)),
118 MK_FLOW_ITEM(MPLS, sizeof(struct rte_flow_item_mpls)),
119 MK_FLOW_ITEM(GRE, sizeof(struct rte_flow_item_gre)),
120 MK_FLOW_ITEM(FUZZY, sizeof(struct rte_flow_item_fuzzy)),
121 MK_FLOW_ITEM(GTP, sizeof(struct rte_flow_item_gtp)),
122 MK_FLOW_ITEM(GTPC, sizeof(struct rte_flow_item_gtp)),
123 MK_FLOW_ITEM(GTPU, sizeof(struct rte_flow_item_gtp)),
124 MK_FLOW_ITEM(ESP, sizeof(struct rte_flow_item_esp)),
125 MK_FLOW_ITEM(GENEVE, sizeof(struct rte_flow_item_geneve)),
126 MK_FLOW_ITEM(VXLAN_GPE, sizeof(struct rte_flow_item_vxlan_gpe)),
127 MK_FLOW_ITEM(ARP_ETH_IPV4, sizeof(struct rte_flow_item_arp_eth_ipv4)),
128 MK_FLOW_ITEM(IPV6_EXT, sizeof(struct rte_flow_item_ipv6_ext)),
129 MK_FLOW_ITEM(IPV6_FRAG_EXT, sizeof(struct rte_flow_item_ipv6_frag_ext)),
130 MK_FLOW_ITEM(ICMP6, sizeof(struct rte_flow_item_icmp6)),
131 MK_FLOW_ITEM(ICMP6_ND_NS, sizeof(struct rte_flow_item_icmp6_nd_ns)),
132 MK_FLOW_ITEM(ICMP6_ND_NA, sizeof(struct rte_flow_item_icmp6_nd_na)),
133 MK_FLOW_ITEM(ICMP6_ND_OPT, sizeof(struct rte_flow_item_icmp6_nd_opt)),
134 MK_FLOW_ITEM(ICMP6_ND_OPT_SLA_ETH,
135 sizeof(struct rte_flow_item_icmp6_nd_opt_sla_eth)),
136 MK_FLOW_ITEM(ICMP6_ND_OPT_TLA_ETH,
137 sizeof(struct rte_flow_item_icmp6_nd_opt_tla_eth)),
138 MK_FLOW_ITEM(MARK, sizeof(struct rte_flow_item_mark)),
139 MK_FLOW_ITEM(META, sizeof(struct rte_flow_item_meta)),
140 MK_FLOW_ITEM(TAG, sizeof(struct rte_flow_item_tag)),
141 MK_FLOW_ITEM(GRE_KEY, sizeof(rte_be32_t)),
142 MK_FLOW_ITEM(GRE_OPTION, sizeof(struct rte_flow_item_gre_opt)),
143 MK_FLOW_ITEM(GTP_PSC, sizeof(struct rte_flow_item_gtp_psc)),
144 MK_FLOW_ITEM(PPPOES, sizeof(struct rte_flow_item_pppoe)),
145 MK_FLOW_ITEM(PPPOED, sizeof(struct rte_flow_item_pppoe)),
146 MK_FLOW_ITEM(PPPOE_PROTO_ID,
147 sizeof(struct rte_flow_item_pppoe_proto_id)),
148 MK_FLOW_ITEM(NSH, sizeof(struct rte_flow_item_nsh)),
149 MK_FLOW_ITEM(IGMP, sizeof(struct rte_flow_item_igmp)),
150 MK_FLOW_ITEM(AH, sizeof(struct rte_flow_item_ah)),
151 MK_FLOW_ITEM(HIGIG2, sizeof(struct rte_flow_item_higig2_hdr)),
152 MK_FLOW_ITEM(L2TPV3OIP, sizeof(struct rte_flow_item_l2tpv3oip)),
153 MK_FLOW_ITEM(PFCP, sizeof(struct rte_flow_item_pfcp)),
154 MK_FLOW_ITEM(ECPRI, sizeof(struct rte_flow_item_ecpri)),
155 MK_FLOW_ITEM(GENEVE_OPT, sizeof(struct rte_flow_item_geneve_opt)),
156 MK_FLOW_ITEM(INTEGRITY, sizeof(struct rte_flow_item_integrity)),
157 MK_FLOW_ITEM(CONNTRACK, sizeof(uint32_t)),
158 MK_FLOW_ITEM(PORT_REPRESENTOR, sizeof(struct rte_flow_item_ethdev)),
159 MK_FLOW_ITEM(REPRESENTED_PORT, sizeof(struct rte_flow_item_ethdev)),
160 MK_FLOW_ITEM_FN(FLEX, sizeof(struct rte_flow_item_flex),
161 rte_flow_item_flex_conv),
162 MK_FLOW_ITEM(L2TPV2, sizeof(struct rte_flow_item_l2tpv2)),
163 MK_FLOW_ITEM(PPP, sizeof(struct rte_flow_item_ppp)),
166 /** Generate flow_action[] entry. */
167 #define MK_FLOW_ACTION(t, s) \
168 [RTE_FLOW_ACTION_TYPE_ ## t] = { \
174 #define MK_FLOW_ACTION_FN(t, fn) \
175 [RTE_FLOW_ACTION_TYPE_ ## t] = { \
182 /** Information about known flow actions. */
183 static const struct rte_flow_desc_data rte_flow_desc_action[] = {
184 MK_FLOW_ACTION(END, 0),
185 MK_FLOW_ACTION(VOID, 0),
186 MK_FLOW_ACTION(PASSTHRU, 0),
187 MK_FLOW_ACTION(JUMP, sizeof(struct rte_flow_action_jump)),
188 MK_FLOW_ACTION(MARK, sizeof(struct rte_flow_action_mark)),
189 MK_FLOW_ACTION(FLAG, 0),
190 MK_FLOW_ACTION(QUEUE, sizeof(struct rte_flow_action_queue)),
191 MK_FLOW_ACTION(DROP, 0),
192 MK_FLOW_ACTION(COUNT, sizeof(struct rte_flow_action_count)),
193 MK_FLOW_ACTION(RSS, sizeof(struct rte_flow_action_rss)),
194 MK_FLOW_ACTION(PF, 0),
195 MK_FLOW_ACTION(VF, sizeof(struct rte_flow_action_vf)),
196 MK_FLOW_ACTION(PHY_PORT, sizeof(struct rte_flow_action_phy_port)),
197 MK_FLOW_ACTION(PORT_ID, sizeof(struct rte_flow_action_port_id)),
198 MK_FLOW_ACTION(METER, sizeof(struct rte_flow_action_meter)),
199 MK_FLOW_ACTION(SECURITY, sizeof(struct rte_flow_action_security)),
200 MK_FLOW_ACTION(OF_SET_MPLS_TTL,
201 sizeof(struct rte_flow_action_of_set_mpls_ttl)),
202 MK_FLOW_ACTION(OF_DEC_MPLS_TTL, 0),
203 MK_FLOW_ACTION(OF_SET_NW_TTL,
204 sizeof(struct rte_flow_action_of_set_nw_ttl)),
205 MK_FLOW_ACTION(OF_DEC_NW_TTL, 0),
206 MK_FLOW_ACTION(OF_COPY_TTL_OUT, 0),
207 MK_FLOW_ACTION(OF_COPY_TTL_IN, 0),
208 MK_FLOW_ACTION(OF_POP_VLAN, 0),
209 MK_FLOW_ACTION(OF_PUSH_VLAN,
210 sizeof(struct rte_flow_action_of_push_vlan)),
211 MK_FLOW_ACTION(OF_SET_VLAN_VID,
212 sizeof(struct rte_flow_action_of_set_vlan_vid)),
213 MK_FLOW_ACTION(OF_SET_VLAN_PCP,
214 sizeof(struct rte_flow_action_of_set_vlan_pcp)),
215 MK_FLOW_ACTION(OF_POP_MPLS,
216 sizeof(struct rte_flow_action_of_pop_mpls)),
217 MK_FLOW_ACTION(OF_PUSH_MPLS,
218 sizeof(struct rte_flow_action_of_push_mpls)),
219 MK_FLOW_ACTION(VXLAN_ENCAP, sizeof(struct rte_flow_action_vxlan_encap)),
220 MK_FLOW_ACTION(VXLAN_DECAP, 0),
221 MK_FLOW_ACTION(NVGRE_ENCAP, sizeof(struct rte_flow_action_vxlan_encap)),
222 MK_FLOW_ACTION(NVGRE_DECAP, 0),
223 MK_FLOW_ACTION(RAW_ENCAP, sizeof(struct rte_flow_action_raw_encap)),
224 MK_FLOW_ACTION(RAW_DECAP, sizeof(struct rte_flow_action_raw_decap)),
225 MK_FLOW_ACTION(SET_IPV4_SRC,
226 sizeof(struct rte_flow_action_set_ipv4)),
227 MK_FLOW_ACTION(SET_IPV4_DST,
228 sizeof(struct rte_flow_action_set_ipv4)),
229 MK_FLOW_ACTION(SET_IPV6_SRC,
230 sizeof(struct rte_flow_action_set_ipv6)),
231 MK_FLOW_ACTION(SET_IPV6_DST,
232 sizeof(struct rte_flow_action_set_ipv6)),
233 MK_FLOW_ACTION(SET_TP_SRC,
234 sizeof(struct rte_flow_action_set_tp)),
235 MK_FLOW_ACTION(SET_TP_DST,
236 sizeof(struct rte_flow_action_set_tp)),
237 MK_FLOW_ACTION(MAC_SWAP, 0),
238 MK_FLOW_ACTION(DEC_TTL, 0),
239 MK_FLOW_ACTION(SET_TTL, sizeof(struct rte_flow_action_set_ttl)),
240 MK_FLOW_ACTION(SET_MAC_SRC, sizeof(struct rte_flow_action_set_mac)),
241 MK_FLOW_ACTION(SET_MAC_DST, sizeof(struct rte_flow_action_set_mac)),
242 MK_FLOW_ACTION(INC_TCP_SEQ, sizeof(rte_be32_t)),
243 MK_FLOW_ACTION(DEC_TCP_SEQ, sizeof(rte_be32_t)),
244 MK_FLOW_ACTION(INC_TCP_ACK, sizeof(rte_be32_t)),
245 MK_FLOW_ACTION(DEC_TCP_ACK, sizeof(rte_be32_t)),
246 MK_FLOW_ACTION(SET_TAG, sizeof(struct rte_flow_action_set_tag)),
247 MK_FLOW_ACTION(SET_META, sizeof(struct rte_flow_action_set_meta)),
248 MK_FLOW_ACTION(SET_IPV4_DSCP, sizeof(struct rte_flow_action_set_dscp)),
249 MK_FLOW_ACTION(SET_IPV6_DSCP, sizeof(struct rte_flow_action_set_dscp)),
250 MK_FLOW_ACTION(AGE, sizeof(struct rte_flow_action_age)),
251 MK_FLOW_ACTION(SAMPLE, sizeof(struct rte_flow_action_sample)),
252 MK_FLOW_ACTION(MODIFY_FIELD,
253 sizeof(struct rte_flow_action_modify_field)),
255 * Indirect action represented as handle of type
256 * (struct rte_flow_action_handle *) stored in conf field (see
257 * struct rte_flow_action); no need for additional structure to * store
258 * indirect action handle.
260 MK_FLOW_ACTION(INDIRECT, 0),
261 MK_FLOW_ACTION(CONNTRACK, sizeof(struct rte_flow_action_conntrack)),
262 MK_FLOW_ACTION(PORT_REPRESENTOR, sizeof(struct rte_flow_action_ethdev)),
263 MK_FLOW_ACTION(REPRESENTED_PORT, sizeof(struct rte_flow_action_ethdev)),
267 rte_flow_dynf_metadata_register(void)
272 static const struct rte_mbuf_dynfield desc_offs = {
273 .name = RTE_MBUF_DYNFIELD_METADATA_NAME,
274 .size = sizeof(uint32_t),
275 .align = __alignof__(uint32_t),
277 static const struct rte_mbuf_dynflag desc_flag = {
278 .name = RTE_MBUF_DYNFLAG_METADATA_NAME,
281 offset = rte_mbuf_dynfield_register(&desc_offs);
284 flag = rte_mbuf_dynflag_register(&desc_flag);
287 rte_flow_dynf_metadata_offs = offset;
288 rte_flow_dynf_metadata_mask = RTE_BIT64(flag);
292 rte_flow_dynf_metadata_offs = -1;
293 rte_flow_dynf_metadata_mask = UINT64_C(0);
298 fts_enter(struct rte_eth_dev *dev)
300 if (!(dev->data->dev_flags & RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE))
301 pthread_mutex_lock(&dev->data->flow_ops_mutex);
305 fts_exit(struct rte_eth_dev *dev)
307 if (!(dev->data->dev_flags & RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE))
308 pthread_mutex_unlock(&dev->data->flow_ops_mutex);
312 flow_err(uint16_t port_id, int ret, struct rte_flow_error *error)
316 if (rte_eth_dev_is_removed(port_id))
317 return rte_flow_error_set(error, EIO,
318 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
319 NULL, rte_strerror(EIO));
323 /* Get generic flow operations structure from a port. */
324 const struct rte_flow_ops *
325 rte_flow_ops_get(uint16_t port_id, struct rte_flow_error *error)
327 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
328 const struct rte_flow_ops *ops;
331 if (unlikely(!rte_eth_dev_is_valid_port(port_id)))
333 else if (unlikely(dev->dev_ops->flow_ops_get == NULL))
334 /* flow API not supported with this driver dev_ops */
337 code = dev->dev_ops->flow_ops_get(dev, &ops);
338 if (code == 0 && ops == NULL)
339 /* flow API not supported with this device */
343 rte_flow_error_set(error, code, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
344 NULL, rte_strerror(code));
350 /* Check whether a flow rule can be created on a given port. */
352 rte_flow_validate(uint16_t port_id,
353 const struct rte_flow_attr *attr,
354 const struct rte_flow_item pattern[],
355 const struct rte_flow_action actions[],
356 struct rte_flow_error *error)
358 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
359 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
364 if (likely(!!ops->validate)) {
366 ret = ops->validate(dev, attr, pattern, actions, error);
368 return flow_err(port_id, ret, error);
370 return rte_flow_error_set(error, ENOSYS,
371 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
372 NULL, rte_strerror(ENOSYS));
375 /* Create a flow rule on a given port. */
377 rte_flow_create(uint16_t port_id,
378 const struct rte_flow_attr *attr,
379 const struct rte_flow_item pattern[],
380 const struct rte_flow_action actions[],
381 struct rte_flow_error *error)
383 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
384 struct rte_flow *flow;
385 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
389 if (likely(!!ops->create)) {
391 flow = ops->create(dev, attr, pattern, actions, error);
394 flow_err(port_id, -rte_errno, error);
397 rte_flow_error_set(error, ENOSYS, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
398 NULL, rte_strerror(ENOSYS));
402 /* Destroy a flow rule on a given port. */
404 rte_flow_destroy(uint16_t port_id,
405 struct rte_flow *flow,
406 struct rte_flow_error *error)
408 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
409 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
414 if (likely(!!ops->destroy)) {
416 ret = ops->destroy(dev, flow, error);
418 return flow_err(port_id, ret, error);
420 return rte_flow_error_set(error, ENOSYS,
421 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
422 NULL, rte_strerror(ENOSYS));
425 /* Destroy all flow rules associated with a port. */
427 rte_flow_flush(uint16_t port_id,
428 struct rte_flow_error *error)
430 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
431 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
436 if (likely(!!ops->flush)) {
438 ret = ops->flush(dev, error);
440 return flow_err(port_id, ret, error);
442 return rte_flow_error_set(error, ENOSYS,
443 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
444 NULL, rte_strerror(ENOSYS));
447 /* Query an existing flow rule. */
449 rte_flow_query(uint16_t port_id,
450 struct rte_flow *flow,
451 const struct rte_flow_action *action,
453 struct rte_flow_error *error)
455 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
456 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
461 if (likely(!!ops->query)) {
463 ret = ops->query(dev, flow, action, data, error);
465 return flow_err(port_id, ret, error);
467 return rte_flow_error_set(error, ENOSYS,
468 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
469 NULL, rte_strerror(ENOSYS));
472 /* Restrict ingress traffic to the defined flow rules. */
474 rte_flow_isolate(uint16_t port_id,
476 struct rte_flow_error *error)
478 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
479 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
484 if (likely(!!ops->isolate)) {
486 ret = ops->isolate(dev, set, error);
488 return flow_err(port_id, ret, error);
490 return rte_flow_error_set(error, ENOSYS,
491 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
492 NULL, rte_strerror(ENOSYS));
495 /* Initialize flow error structure. */
497 rte_flow_error_set(struct rte_flow_error *error,
499 enum rte_flow_error_type type,
504 *error = (struct rte_flow_error){
514 /** Pattern item specification types. */
515 enum rte_flow_conv_item_spec_type {
516 RTE_FLOW_CONV_ITEM_SPEC,
517 RTE_FLOW_CONV_ITEM_LAST,
518 RTE_FLOW_CONV_ITEM_MASK,
522 * Copy pattern item specification.
525 * Output buffer. Can be NULL if @p size is zero.
527 * Size of @p buf in bytes.
529 * Pattern item to copy specification from.
531 * Specification selector for either @p spec, @p last or @p mask.
534 * Number of bytes needed to store pattern item specification regardless
535 * of @p size. @p buf contents are truncated to @p size if not large
539 rte_flow_conv_item_spec(void *buf, const size_t size,
540 const struct rte_flow_item *item,
541 enum rte_flow_conv_item_spec_type type)
545 type == RTE_FLOW_CONV_ITEM_SPEC ? item->spec :
546 type == RTE_FLOW_CONV_ITEM_LAST ? item->last :
547 type == RTE_FLOW_CONV_ITEM_MASK ? item->mask :
550 switch (item->type) {
552 const struct rte_flow_item_raw *raw;
555 const struct rte_flow_item_raw *raw;
558 const struct rte_flow_item_raw *raw;
561 const struct rte_flow_item_raw *raw;
564 struct rte_flow_item_raw *raw;
568 case RTE_FLOW_ITEM_TYPE_RAW:
569 spec.raw = item->spec;
570 last.raw = item->last ? item->last : item->spec;
571 mask.raw = item->mask ? item->mask : &rte_flow_item_raw_mask;
575 (&(struct rte_flow_item_raw){
576 .relative = src.raw->relative,
577 .search = src.raw->search,
578 .reserved = src.raw->reserved,
579 .offset = src.raw->offset,
580 .limit = src.raw->limit,
581 .length = src.raw->length,
583 size > sizeof(*dst.raw) ? sizeof(*dst.raw) : size);
584 off = sizeof(*dst.raw);
585 if (type == RTE_FLOW_CONV_ITEM_SPEC ||
586 (type == RTE_FLOW_CONV_ITEM_MASK &&
587 ((spec.raw->length & mask.raw->length) >=
588 (last.raw->length & mask.raw->length))))
589 tmp = spec.raw->length & mask.raw->length;
591 tmp = last.raw->length & mask.raw->length;
593 off = RTE_ALIGN_CEIL(off, sizeof(*dst.raw->pattern));
594 if (size >= off + tmp)
595 dst.raw->pattern = rte_memcpy
596 ((void *)((uintptr_t)dst.raw + off),
597 src.raw->pattern, tmp);
602 off = rte_flow_conv_copy(buf, data, size,
603 rte_flow_desc_item, item->type);
610 * Copy action configuration.
613 * Output buffer. Can be NULL if @p size is zero.
615 * Size of @p buf in bytes.
617 * Action to copy configuration from.
620 * Number of bytes needed to store pattern item specification regardless
621 * of @p size. @p buf contents are truncated to @p size if not large
625 rte_flow_conv_action_conf(void *buf, const size_t size,
626 const struct rte_flow_action *action)
630 switch (action->type) {
632 const struct rte_flow_action_rss *rss;
633 const struct rte_flow_action_vxlan_encap *vxlan_encap;
634 const struct rte_flow_action_nvgre_encap *nvgre_encap;
637 struct rte_flow_action_rss *rss;
638 struct rte_flow_action_vxlan_encap *vxlan_encap;
639 struct rte_flow_action_nvgre_encap *nvgre_encap;
644 case RTE_FLOW_ACTION_TYPE_RSS:
645 src.rss = action->conf;
648 (&(struct rte_flow_action_rss){
649 .func = src.rss->func,
650 .level = src.rss->level,
651 .types = src.rss->types,
652 .key_len = src.rss->key_len,
653 .queue_num = src.rss->queue_num,
655 size > sizeof(*dst.rss) ? sizeof(*dst.rss) : size);
656 off = sizeof(*dst.rss);
657 if (src.rss->key_len && src.rss->key) {
658 off = RTE_ALIGN_CEIL(off, sizeof(*dst.rss->key));
659 tmp = sizeof(*src.rss->key) * src.rss->key_len;
660 if (size >= off + tmp)
661 dst.rss->key = rte_memcpy
662 ((void *)((uintptr_t)dst.rss + off),
666 if (src.rss->queue_num) {
667 off = RTE_ALIGN_CEIL(off, sizeof(*dst.rss->queue));
668 tmp = sizeof(*src.rss->queue) * src.rss->queue_num;
669 if (size >= off + tmp)
670 dst.rss->queue = rte_memcpy
671 ((void *)((uintptr_t)dst.rss + off),
672 src.rss->queue, tmp);
676 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
677 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
678 src.vxlan_encap = action->conf;
679 dst.vxlan_encap = buf;
680 RTE_BUILD_BUG_ON(sizeof(*src.vxlan_encap) !=
681 sizeof(*src.nvgre_encap) ||
682 offsetof(struct rte_flow_action_vxlan_encap,
684 offsetof(struct rte_flow_action_nvgre_encap,
686 off = sizeof(*dst.vxlan_encap);
687 if (src.vxlan_encap->definition) {
689 (off, sizeof(*dst.vxlan_encap->definition));
691 (RTE_FLOW_CONV_OP_PATTERN,
692 (void *)((uintptr_t)dst.vxlan_encap + off),
693 size > off ? size - off : 0,
694 src.vxlan_encap->definition, NULL);
697 if (size >= off + ret)
698 dst.vxlan_encap->definition =
699 (void *)((uintptr_t)dst.vxlan_encap +
705 off = rte_flow_conv_copy(buf, action->conf, size,
706 rte_flow_desc_action, action->type);
713 * Copy a list of pattern items.
716 * Destination buffer. Can be NULL if @p size is zero.
718 * Size of @p dst in bytes.
720 * Source pattern items.
722 * Maximum number of pattern items to process from @p src or 0 to process
723 * the entire list. In both cases, processing stops after
724 * RTE_FLOW_ITEM_TYPE_END is encountered.
726 * Perform verbose error reporting if not NULL.
729 * A positive value representing the number of bytes needed to store
730 * pattern items regardless of @p size on success (@p buf contents are
731 * truncated to @p size if not large enough), a negative errno value
732 * otherwise and rte_errno is set.
735 rte_flow_conv_pattern(struct rte_flow_item *dst,
737 const struct rte_flow_item *src,
739 struct rte_flow_error *error)
741 uintptr_t data = (uintptr_t)dst;
746 for (i = 0, off = 0; !num || i != num; ++i, ++src, ++dst) {
748 * allow PMD private flow item
750 if (((int)src->type >= 0) &&
751 ((size_t)src->type >= RTE_DIM(rte_flow_desc_item) ||
752 !rte_flow_desc_item[src->type].name))
753 return rte_flow_error_set
754 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, src,
755 "cannot convert unknown item type");
756 if (size >= off + sizeof(*dst))
757 *dst = (struct rte_flow_item){
769 off = RTE_ALIGN_CEIL(off, sizeof(double));
770 ret = rte_flow_conv_item_spec
771 ((void *)(data + off),
772 size > off ? size - off : 0, src,
773 RTE_FLOW_CONV_ITEM_SPEC);
774 if (size && size >= off + ret)
775 dst->spec = (void *)(data + off);
780 off = RTE_ALIGN_CEIL(off, sizeof(double));
781 ret = rte_flow_conv_item_spec
782 ((void *)(data + off),
783 size > off ? size - off : 0, src,
784 RTE_FLOW_CONV_ITEM_LAST);
785 if (size && size >= off + ret)
786 dst->last = (void *)(data + off);
790 off = RTE_ALIGN_CEIL(off, sizeof(double));
791 ret = rte_flow_conv_item_spec
792 ((void *)(data + off),
793 size > off ? size - off : 0, src,
794 RTE_FLOW_CONV_ITEM_MASK);
795 if (size && size >= off + ret)
796 dst->mask = (void *)(data + off);
806 * Copy a list of actions.
809 * Destination buffer. Can be NULL if @p size is zero.
811 * Size of @p dst in bytes.
815 * Maximum number of actions to process from @p src or 0 to process the
816 * entire list. In both cases, processing stops after
817 * RTE_FLOW_ACTION_TYPE_END is encountered.
819 * Perform verbose error reporting if not NULL.
822 * A positive value representing the number of bytes needed to store
823 * actions regardless of @p size on success (@p buf contents are truncated
824 * to @p size if not large enough), a negative errno value otherwise and
828 rte_flow_conv_actions(struct rte_flow_action *dst,
830 const struct rte_flow_action *src,
832 struct rte_flow_error *error)
834 uintptr_t data = (uintptr_t)dst;
839 for (i = 0, off = 0; !num || i != num; ++i, ++src, ++dst) {
841 * allow PMD private flow action
843 if (((int)src->type >= 0) &&
844 ((size_t)src->type >= RTE_DIM(rte_flow_desc_action) ||
845 !rte_flow_desc_action[src->type].name))
846 return rte_flow_error_set
847 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
848 src, "cannot convert unknown action type");
849 if (size >= off + sizeof(*dst))
850 *dst = (struct rte_flow_action){
862 off = RTE_ALIGN_CEIL(off, sizeof(double));
863 ret = rte_flow_conv_action_conf
864 ((void *)(data + off),
865 size > off ? size - off : 0, src);
866 if (size && size >= off + ret)
867 dst->conf = (void *)(data + off);
877 * Copy flow rule components.
879 * This comprises the flow rule descriptor itself, attributes, pattern and
880 * actions list. NULL components in @p src are skipped.
883 * Destination buffer. Can be NULL if @p size is zero.
885 * Size of @p dst in bytes.
887 * Source flow rule descriptor.
889 * Perform verbose error reporting if not NULL.
892 * A positive value representing the number of bytes needed to store all
893 * components including the descriptor regardless of @p size on success
894 * (@p buf contents are truncated to @p size if not large enough), a
895 * negative errno value otherwise and rte_errno is set.
898 rte_flow_conv_rule(struct rte_flow_conv_rule *dst,
900 const struct rte_flow_conv_rule *src,
901 struct rte_flow_error *error)
907 (&(struct rte_flow_conv_rule){
912 size > sizeof(*dst) ? sizeof(*dst) : size);
915 off = RTE_ALIGN_CEIL(off, sizeof(double));
916 if (size && size >= off + sizeof(*dst->attr))
917 dst->attr = rte_memcpy
918 ((void *)((uintptr_t)dst + off),
919 src->attr_ro, sizeof(*dst->attr));
920 off += sizeof(*dst->attr);
922 if (src->pattern_ro) {
923 off = RTE_ALIGN_CEIL(off, sizeof(double));
924 ret = rte_flow_conv_pattern((void *)((uintptr_t)dst + off),
925 size > off ? size - off : 0,
926 src->pattern_ro, 0, error);
929 if (size && size >= off + (size_t)ret)
930 dst->pattern = (void *)((uintptr_t)dst + off);
933 if (src->actions_ro) {
934 off = RTE_ALIGN_CEIL(off, sizeof(double));
935 ret = rte_flow_conv_actions((void *)((uintptr_t)dst + off),
936 size > off ? size - off : 0,
937 src->actions_ro, 0, error);
940 if (size >= off + (size_t)ret)
941 dst->actions = (void *)((uintptr_t)dst + off);
948 * Retrieve the name of a pattern item/action type.
951 * Nonzero when @p src represents an action type instead of a pattern item
954 * Nonzero to write string address instead of contents into @p dst.
956 * Destination buffer. Can be NULL if @p size is zero.
958 * Size of @p dst in bytes.
960 * Depending on @p is_action, source pattern item or action type cast as a
963 * Perform verbose error reporting if not NULL.
966 * A positive value representing the number of bytes needed to store the
967 * name or its address regardless of @p size on success (@p buf contents
968 * are truncated to @p size if not large enough), a negative errno value
969 * otherwise and rte_errno is set.
972 rte_flow_conv_name(int is_action,
977 struct rte_flow_error *error)
980 const struct rte_flow_desc_data *data;
983 static const struct desc_info info_rep[2] = {
984 { rte_flow_desc_item, RTE_DIM(rte_flow_desc_item), },
985 { rte_flow_desc_action, RTE_DIM(rte_flow_desc_action), },
987 const struct desc_info *const info = &info_rep[!!is_action];
988 unsigned int type = (uintptr_t)src;
990 if (type >= info->num)
991 return rte_flow_error_set
992 (error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
993 "unknown object type to retrieve the name of");
995 return strlcpy(dst, info->data[type].name, size);
996 if (size >= sizeof(const char **))
997 *((const char **)dst) = info->data[type].name;
998 return sizeof(const char **);
1001 /** Helper function to convert flow API objects. */
1003 rte_flow_conv(enum rte_flow_conv_op op,
1007 struct rte_flow_error *error)
1010 const struct rte_flow_attr *attr;
1012 case RTE_FLOW_CONV_OP_NONE:
1014 case RTE_FLOW_CONV_OP_ATTR:
1016 if (size > sizeof(*attr))
1017 size = sizeof(*attr);
1018 rte_memcpy(dst, attr, size);
1019 return sizeof(*attr);
1020 case RTE_FLOW_CONV_OP_ITEM:
1021 return rte_flow_conv_pattern(dst, size, src, 1, error);
1022 case RTE_FLOW_CONV_OP_ACTION:
1023 return rte_flow_conv_actions(dst, size, src, 1, error);
1024 case RTE_FLOW_CONV_OP_PATTERN:
1025 return rte_flow_conv_pattern(dst, size, src, 0, error);
1026 case RTE_FLOW_CONV_OP_ACTIONS:
1027 return rte_flow_conv_actions(dst, size, src, 0, error);
1028 case RTE_FLOW_CONV_OP_RULE:
1029 return rte_flow_conv_rule(dst, size, src, error);
1030 case RTE_FLOW_CONV_OP_ITEM_NAME:
1031 return rte_flow_conv_name(0, 0, dst, size, src, error);
1032 case RTE_FLOW_CONV_OP_ACTION_NAME:
1033 return rte_flow_conv_name(1, 0, dst, size, src, error);
1034 case RTE_FLOW_CONV_OP_ITEM_NAME_PTR:
1035 return rte_flow_conv_name(0, 1, dst, size, src, error);
1036 case RTE_FLOW_CONV_OP_ACTION_NAME_PTR:
1037 return rte_flow_conv_name(1, 1, dst, size, src, error);
1039 return rte_flow_error_set
1040 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1041 "unknown object conversion operation");
1044 /** Store a full rte_flow description. */
1046 rte_flow_copy(struct rte_flow_desc *desc, size_t len,
1047 const struct rte_flow_attr *attr,
1048 const struct rte_flow_item *items,
1049 const struct rte_flow_action *actions)
1052 * Overlap struct rte_flow_conv with struct rte_flow_desc in order
1053 * to convert the former to the latter without wasting space.
1055 struct rte_flow_conv_rule *dst =
1057 (void *)((uintptr_t)desc +
1058 (offsetof(struct rte_flow_desc, actions) -
1059 offsetof(struct rte_flow_conv_rule, actions))) :
1062 len > sizeof(*desc) - sizeof(*dst) ?
1063 len - (sizeof(*desc) - sizeof(*dst)) :
1065 struct rte_flow_conv_rule src = {
1067 .pattern_ro = items,
1068 .actions_ro = actions,
1072 RTE_BUILD_BUG_ON(sizeof(struct rte_flow_desc) <
1073 sizeof(struct rte_flow_conv_rule));
1075 (&dst->pattern != &desc->items ||
1076 &dst->actions != &desc->actions ||
1077 (uintptr_t)(dst + 1) != (uintptr_t)(desc + 1))) {
1081 ret = rte_flow_conv(RTE_FLOW_CONV_OP_RULE, dst, dst_size, &src, NULL);
1084 ret += sizeof(*desc) - sizeof(*dst);
1086 (&(struct rte_flow_desc){
1089 .items = dst_size ? dst->pattern : NULL,
1090 .actions = dst_size ? dst->actions : NULL,
1092 len > sizeof(*desc) ? sizeof(*desc) : len);
1097 rte_flow_dev_dump(uint16_t port_id, struct rte_flow *flow,
1098 FILE *file, struct rte_flow_error *error)
1100 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1101 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1106 if (likely(!!ops->dev_dump)) {
1108 ret = ops->dev_dump(dev, flow, file, error);
1110 return flow_err(port_id, ret, error);
1112 return rte_flow_error_set(error, ENOSYS,
1113 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1114 NULL, rte_strerror(ENOSYS));
1118 rte_flow_get_aged_flows(uint16_t port_id, void **contexts,
1119 uint32_t nb_contexts, struct rte_flow_error *error)
1121 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1122 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1127 if (likely(!!ops->get_aged_flows)) {
1129 ret = ops->get_aged_flows(dev, contexts, nb_contexts, error);
1131 return flow_err(port_id, ret, error);
1133 return rte_flow_error_set(error, ENOTSUP,
1134 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1135 NULL, rte_strerror(ENOTSUP));
1138 struct rte_flow_action_handle *
1139 rte_flow_action_handle_create(uint16_t port_id,
1140 const struct rte_flow_indir_action_conf *conf,
1141 const struct rte_flow_action *action,
1142 struct rte_flow_error *error)
1144 struct rte_flow_action_handle *handle;
1145 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1149 if (unlikely(!ops->action_handle_create)) {
1150 rte_flow_error_set(error, ENOSYS,
1151 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1152 rte_strerror(ENOSYS));
1155 handle = ops->action_handle_create(&rte_eth_devices[port_id],
1156 conf, action, error);
1158 flow_err(port_id, -rte_errno, error);
1163 rte_flow_action_handle_destroy(uint16_t port_id,
1164 struct rte_flow_action_handle *handle,
1165 struct rte_flow_error *error)
1168 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1172 if (unlikely(!ops->action_handle_destroy))
1173 return rte_flow_error_set(error, ENOSYS,
1174 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1175 NULL, rte_strerror(ENOSYS));
1176 ret = ops->action_handle_destroy(&rte_eth_devices[port_id],
1178 return flow_err(port_id, ret, error);
1182 rte_flow_action_handle_update(uint16_t port_id,
1183 struct rte_flow_action_handle *handle,
1185 struct rte_flow_error *error)
1188 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1192 if (unlikely(!ops->action_handle_update))
1193 return rte_flow_error_set(error, ENOSYS,
1194 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1195 NULL, rte_strerror(ENOSYS));
1196 ret = ops->action_handle_update(&rte_eth_devices[port_id], handle,
1198 return flow_err(port_id, ret, error);
1202 rte_flow_action_handle_query(uint16_t port_id,
1203 const struct rte_flow_action_handle *handle,
1205 struct rte_flow_error *error)
1208 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1212 if (unlikely(!ops->action_handle_query))
1213 return rte_flow_error_set(error, ENOSYS,
1214 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1215 NULL, rte_strerror(ENOSYS));
1216 ret = ops->action_handle_query(&rte_eth_devices[port_id], handle,
1218 return flow_err(port_id, ret, error);
1222 rte_flow_tunnel_decap_set(uint16_t port_id,
1223 struct rte_flow_tunnel *tunnel,
1224 struct rte_flow_action **actions,
1225 uint32_t *num_of_actions,
1226 struct rte_flow_error *error)
1228 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1229 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1233 if (likely(!!ops->tunnel_decap_set)) {
1234 return flow_err(port_id,
1235 ops->tunnel_decap_set(dev, tunnel, actions,
1236 num_of_actions, error),
1239 return rte_flow_error_set(error, ENOTSUP,
1240 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1241 NULL, rte_strerror(ENOTSUP));
1245 rte_flow_tunnel_match(uint16_t port_id,
1246 struct rte_flow_tunnel *tunnel,
1247 struct rte_flow_item **items,
1248 uint32_t *num_of_items,
1249 struct rte_flow_error *error)
1251 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1252 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1256 if (likely(!!ops->tunnel_match)) {
1257 return flow_err(port_id,
1258 ops->tunnel_match(dev, tunnel, items,
1259 num_of_items, error),
1262 return rte_flow_error_set(error, ENOTSUP,
1263 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1264 NULL, rte_strerror(ENOTSUP));
1268 rte_flow_get_restore_info(uint16_t port_id,
1270 struct rte_flow_restore_info *restore_info,
1271 struct rte_flow_error *error)
1273 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1274 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1278 if (likely(!!ops->get_restore_info)) {
1279 return flow_err(port_id,
1280 ops->get_restore_info(dev, m, restore_info,
1284 return rte_flow_error_set(error, ENOTSUP,
1285 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1286 NULL, rte_strerror(ENOTSUP));
1290 rte_flow_tunnel_action_decap_release(uint16_t port_id,
1291 struct rte_flow_action *actions,
1292 uint32_t num_of_actions,
1293 struct rte_flow_error *error)
1295 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1296 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1300 if (likely(!!ops->tunnel_action_decap_release)) {
1301 return flow_err(port_id,
1302 ops->tunnel_action_decap_release(dev, actions,
1307 return rte_flow_error_set(error, ENOTSUP,
1308 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1309 NULL, rte_strerror(ENOTSUP));
1313 rte_flow_tunnel_item_release(uint16_t port_id,
1314 struct rte_flow_item *items,
1315 uint32_t num_of_items,
1316 struct rte_flow_error *error)
1318 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1319 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1323 if (likely(!!ops->tunnel_item_release)) {
1324 return flow_err(port_id,
1325 ops->tunnel_item_release(dev, items,
1326 num_of_items, error),
1329 return rte_flow_error_set(error, ENOTSUP,
1330 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1331 NULL, rte_strerror(ENOTSUP));
1335 rte_flow_pick_transfer_proxy(uint16_t port_id, uint16_t *proxy_port_id,
1336 struct rte_flow_error *error)
1338 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1339 struct rte_eth_dev *dev;
1341 if (unlikely(ops == NULL))
1344 if (ops->pick_transfer_proxy == NULL) {
1345 *proxy_port_id = port_id;
1349 dev = &rte_eth_devices[port_id];
1351 return flow_err(port_id,
1352 ops->pick_transfer_proxy(dev, proxy_port_id, error),
1356 struct rte_flow_item_flex_handle *
1357 rte_flow_flex_item_create(uint16_t port_id,
1358 const struct rte_flow_item_flex_conf *conf,
1359 struct rte_flow_error *error)
1361 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1362 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1363 struct rte_flow_item_flex_handle *handle;
1367 if (unlikely(!ops->flex_item_create)) {
1368 rte_flow_error_set(error, ENOTSUP,
1369 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1370 NULL, rte_strerror(ENOTSUP));
1373 handle = ops->flex_item_create(dev, conf, error);
1375 flow_err(port_id, -rte_errno, error);
1380 rte_flow_flex_item_release(uint16_t port_id,
1381 const struct rte_flow_item_flex_handle *handle,
1382 struct rte_flow_error *error)
1385 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1386 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1388 if (unlikely(!ops || !ops->flex_item_release))
1389 return rte_flow_error_set(error, ENOTSUP,
1390 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1391 NULL, rte_strerror(ENOTSUP));
1392 ret = ops->flex_item_release(dev, handle, error);
1393 return flow_err(port_id, ret, error);
1397 rte_flow_info_get(uint16_t port_id,
1398 struct rte_flow_port_info *port_info,
1399 struct rte_flow_error *error)
1401 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1402 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1406 if (dev->data->dev_configured == 0) {
1408 "Device with port_id=%"PRIu16" is not configured.\n",
1412 if (port_info == NULL) {
1413 RTE_FLOW_LOG(ERR, "Port %"PRIu16" info is NULL.\n", port_id);
1416 if (likely(!!ops->info_get)) {
1417 return flow_err(port_id,
1418 ops->info_get(dev, port_info, error),
1421 return rte_flow_error_set(error, ENOTSUP,
1422 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1423 NULL, rte_strerror(ENOTSUP));
1427 rte_flow_configure(uint16_t port_id,
1428 const struct rte_flow_port_attr *port_attr,
1429 struct rte_flow_error *error)
1431 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1432 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1437 if (dev->data->dev_configured == 0) {
1439 "Device with port_id=%"PRIu16" is not configured.\n",
1443 if (dev->data->dev_started != 0) {
1445 "Device with port_id=%"PRIu16" already started.\n",
1449 if (port_attr == NULL) {
1450 RTE_FLOW_LOG(ERR, "Port %"PRIu16" info is NULL.\n", port_id);
1453 if (likely(!!ops->configure)) {
1454 ret = ops->configure(dev, port_attr, error);
1456 dev->data->flow_configured = 1;
1457 return flow_err(port_id, ret, error);
1459 return rte_flow_error_set(error, ENOTSUP,
1460 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1461 NULL, rte_strerror(ENOTSUP));
1464 struct rte_flow_pattern_template *
1465 rte_flow_pattern_template_create(uint16_t port_id,
1466 const struct rte_flow_pattern_template_attr *template_attr,
1467 const struct rte_flow_item pattern[],
1468 struct rte_flow_error *error)
1470 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1471 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1472 struct rte_flow_pattern_template *template;
1476 if (dev->data->flow_configured == 0) {
1478 "Flow engine on port_id=%"PRIu16" is not configured.\n",
1480 rte_flow_error_set(error, EINVAL,
1481 RTE_FLOW_ERROR_TYPE_STATE,
1482 NULL, rte_strerror(EINVAL));
1485 if (template_attr == NULL) {
1487 "Port %"PRIu16" template attr is NULL.\n",
1489 rte_flow_error_set(error, EINVAL,
1490 RTE_FLOW_ERROR_TYPE_ATTR,
1491 NULL, rte_strerror(EINVAL));
1494 if (pattern == NULL) {
1496 "Port %"PRIu16" pattern is NULL.\n",
1498 rte_flow_error_set(error, EINVAL,
1499 RTE_FLOW_ERROR_TYPE_ATTR,
1500 NULL, rte_strerror(EINVAL));
1503 if (likely(!!ops->pattern_template_create)) {
1504 template = ops->pattern_template_create(dev, template_attr,
1506 if (template == NULL)
1507 flow_err(port_id, -rte_errno, error);
1510 rte_flow_error_set(error, ENOTSUP,
1511 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1512 NULL, rte_strerror(ENOTSUP));
1517 rte_flow_pattern_template_destroy(uint16_t port_id,
1518 struct rte_flow_pattern_template *pattern_template,
1519 struct rte_flow_error *error)
1521 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1522 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1526 if (unlikely(pattern_template == NULL))
1528 if (likely(!!ops->pattern_template_destroy)) {
1529 return flow_err(port_id,
1530 ops->pattern_template_destroy(dev,
1535 return rte_flow_error_set(error, ENOTSUP,
1536 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1537 NULL, rte_strerror(ENOTSUP));
1540 struct rte_flow_actions_template *
1541 rte_flow_actions_template_create(uint16_t port_id,
1542 const struct rte_flow_actions_template_attr *template_attr,
1543 const struct rte_flow_action actions[],
1544 const struct rte_flow_action masks[],
1545 struct rte_flow_error *error)
1547 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1548 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1549 struct rte_flow_actions_template *template;
1553 if (dev->data->flow_configured == 0) {
1555 "Flow engine on port_id=%"PRIu16" is not configured.\n",
1557 rte_flow_error_set(error, EINVAL,
1558 RTE_FLOW_ERROR_TYPE_STATE,
1559 NULL, rte_strerror(EINVAL));
1562 if (template_attr == NULL) {
1564 "Port %"PRIu16" template attr is NULL.\n",
1566 rte_flow_error_set(error, EINVAL,
1567 RTE_FLOW_ERROR_TYPE_ATTR,
1568 NULL, rte_strerror(EINVAL));
1571 if (actions == NULL) {
1573 "Port %"PRIu16" actions is NULL.\n",
1575 rte_flow_error_set(error, EINVAL,
1576 RTE_FLOW_ERROR_TYPE_ATTR,
1577 NULL, rte_strerror(EINVAL));
1580 if (masks == NULL) {
1582 "Port %"PRIu16" masks is NULL.\n",
1584 rte_flow_error_set(error, EINVAL,
1585 RTE_FLOW_ERROR_TYPE_ATTR,
1586 NULL, rte_strerror(EINVAL));
1589 if (likely(!!ops->actions_template_create)) {
1590 template = ops->actions_template_create(dev, template_attr,
1591 actions, masks, error);
1592 if (template == NULL)
1593 flow_err(port_id, -rte_errno, error);
1596 rte_flow_error_set(error, ENOTSUP,
1597 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1598 NULL, rte_strerror(ENOTSUP));
1603 rte_flow_actions_template_destroy(uint16_t port_id,
1604 struct rte_flow_actions_template *actions_template,
1605 struct rte_flow_error *error)
1607 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1608 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1612 if (unlikely(actions_template == NULL))
1614 if (likely(!!ops->actions_template_destroy)) {
1615 return flow_err(port_id,
1616 ops->actions_template_destroy(dev,
1621 return rte_flow_error_set(error, ENOTSUP,
1622 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1623 NULL, rte_strerror(ENOTSUP));
1626 struct rte_flow_template_table *
1627 rte_flow_template_table_create(uint16_t port_id,
1628 const struct rte_flow_template_table_attr *table_attr,
1629 struct rte_flow_pattern_template *pattern_templates[],
1630 uint8_t nb_pattern_templates,
1631 struct rte_flow_actions_template *actions_templates[],
1632 uint8_t nb_actions_templates,
1633 struct rte_flow_error *error)
1635 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1636 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1637 struct rte_flow_template_table *table;
1641 if (dev->data->flow_configured == 0) {
1643 "Flow engine on port_id=%"PRIu16" is not configured.\n",
1645 rte_flow_error_set(error, EINVAL,
1646 RTE_FLOW_ERROR_TYPE_STATE,
1647 NULL, rte_strerror(EINVAL));
1650 if (table_attr == NULL) {
1652 "Port %"PRIu16" table attr is NULL.\n",
1654 rte_flow_error_set(error, EINVAL,
1655 RTE_FLOW_ERROR_TYPE_ATTR,
1656 NULL, rte_strerror(EINVAL));
1659 if (pattern_templates == NULL) {
1661 "Port %"PRIu16" pattern templates is NULL.\n",
1663 rte_flow_error_set(error, EINVAL,
1664 RTE_FLOW_ERROR_TYPE_ATTR,
1665 NULL, rte_strerror(EINVAL));
1668 if (actions_templates == NULL) {
1670 "Port %"PRIu16" actions templates is NULL.\n",
1672 rte_flow_error_set(error, EINVAL,
1673 RTE_FLOW_ERROR_TYPE_ATTR,
1674 NULL, rte_strerror(EINVAL));
1677 if (likely(!!ops->template_table_create)) {
1678 table = ops->template_table_create(dev, table_attr,
1679 pattern_templates, nb_pattern_templates,
1680 actions_templates, nb_actions_templates,
1683 flow_err(port_id, -rte_errno, error);
1686 rte_flow_error_set(error, ENOTSUP,
1687 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1688 NULL, rte_strerror(ENOTSUP));
1693 rte_flow_template_table_destroy(uint16_t port_id,
1694 struct rte_flow_template_table *template_table,
1695 struct rte_flow_error *error)
1697 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1698 const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1702 if (unlikely(template_table == NULL))
1704 if (likely(!!ops->template_table_destroy)) {
1705 return flow_err(port_id,
1706 ops->template_table_destroy(dev,
1711 return rte_flow_error_set(error, ENOTSUP,
1712 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1713 NULL, rte_strerror(ENOTSUP));