xref: /dpdk/lib/ethdev/rte_flow.c (revision 13cd6d5c)
199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson  * Copyright 2016 6WIND S.A.
399a2dd95SBruce Richardson  * Copyright 2016 Mellanox Technologies, Ltd
499a2dd95SBruce Richardson  */
599a2dd95SBruce Richardson 
699a2dd95SBruce Richardson #include <errno.h>
799a2dd95SBruce Richardson #include <stddef.h>
899a2dd95SBruce Richardson #include <stdint.h>
999a2dd95SBruce Richardson #include <string.h>
1099a2dd95SBruce Richardson 
1199a2dd95SBruce Richardson #include <rte_common.h>
1299a2dd95SBruce Richardson #include <rte_errno.h>
1399a2dd95SBruce Richardson #include <rte_branch_prediction.h>
1499a2dd95SBruce Richardson #include <rte_string_fns.h>
1599a2dd95SBruce Richardson #include <rte_mbuf.h>
1699a2dd95SBruce Richardson #include <rte_mbuf_dyn.h>
1799a2dd95SBruce Richardson #include "rte_ethdev.h"
1899a2dd95SBruce Richardson #include "rte_flow_driver.h"
1999a2dd95SBruce Richardson #include "rte_flow.h"
2099a2dd95SBruce Richardson 
2199a2dd95SBruce Richardson /* Mbuf dynamic field name for metadata. */
2299a2dd95SBruce Richardson int32_t rte_flow_dynf_metadata_offs = -1;
2399a2dd95SBruce Richardson 
2499a2dd95SBruce Richardson /* Mbuf dynamic field flag bit number for metadata. */
2599a2dd95SBruce Richardson uint64_t rte_flow_dynf_metadata_mask;
2699a2dd95SBruce Richardson 
2799a2dd95SBruce Richardson /**
2899a2dd95SBruce Richardson  * Flow elements description tables.
2999a2dd95SBruce Richardson  */
3099a2dd95SBruce Richardson struct rte_flow_desc_data {
3199a2dd95SBruce Richardson 	const char *name;
3299a2dd95SBruce Richardson 	size_t size;
336cf72047SGregory Etelson 	size_t (*desc_fn)(void *dst, const void *src);
3499a2dd95SBruce Richardson };
3599a2dd95SBruce Richardson 
366cf72047SGregory Etelson /**
376cf72047SGregory Etelson  *
386cf72047SGregory Etelson  * @param buf
396cf72047SGregory Etelson  * Destination memory.
406cf72047SGregory Etelson  * @param data
416cf72047SGregory Etelson  * Source memory
426cf72047SGregory Etelson  * @param size
436cf72047SGregory Etelson  * Requested copy size
446cf72047SGregory Etelson  * @param desc
456cf72047SGregory Etelson  * rte_flow_desc_item - for flow item conversion.
466cf72047SGregory Etelson  * rte_flow_desc_action - for flow action conversion.
476cf72047SGregory Etelson  * @param type
486cf72047SGregory Etelson  * Offset into the desc param or negative value for private flow elements.
496cf72047SGregory Etelson  */
506cf72047SGregory Etelson static inline size_t
rte_flow_conv_copy(void * buf,const void * data,const size_t size,const struct rte_flow_desc_data * desc,int type)516cf72047SGregory Etelson rte_flow_conv_copy(void *buf, const void *data, const size_t size,
526cf72047SGregory Etelson 		   const struct rte_flow_desc_data *desc, int type)
536cf72047SGregory Etelson {
546cf72047SGregory Etelson 	/**
556cf72047SGregory Etelson 	 * Allow PMD private flow item
566cf72047SGregory Etelson 	 */
57de39080bSGregory Etelson 	bool rte_type = type >= 0;
58de39080bSGregory Etelson 
59de39080bSGregory Etelson 	size_t sz = rte_type ? desc[type].size : sizeof(void *);
606cf72047SGregory Etelson 	if (buf == NULL || data == NULL)
616cf72047SGregory Etelson 		return 0;
626cf72047SGregory Etelson 	rte_memcpy(buf, data, (size > sz ? sz : size));
63de39080bSGregory Etelson 	if (rte_type && desc[type].desc_fn)
646cf72047SGregory Etelson 		sz += desc[type].desc_fn(size > 0 ? buf : NULL, data);
656cf72047SGregory Etelson 	return sz;
666cf72047SGregory Etelson }
676cf72047SGregory Etelson 
68dc4d860eSViacheslav Ovsiienko static size_t
rte_flow_item_flex_conv(void * buf,const void * data)69dc4d860eSViacheslav Ovsiienko rte_flow_item_flex_conv(void *buf, const void *data)
70dc4d860eSViacheslav Ovsiienko {
71dc4d860eSViacheslav Ovsiienko 	struct rte_flow_item_flex *dst = buf;
72dc4d860eSViacheslav Ovsiienko 	const struct rte_flow_item_flex *src = data;
73dc4d860eSViacheslav Ovsiienko 	if (buf) {
74dc4d860eSViacheslav Ovsiienko 		dst->pattern = rte_memcpy
75dc4d860eSViacheslav Ovsiienko 			((void *)((uintptr_t)(dst + 1)), src->pattern,
76dc4d860eSViacheslav Ovsiienko 			 src->length);
77dc4d860eSViacheslav Ovsiienko 	}
78dc4d860eSViacheslav Ovsiienko 	return src->length;
79dc4d860eSViacheslav Ovsiienko }
80dc4d860eSViacheslav Ovsiienko 
8199a2dd95SBruce Richardson /** Generate flow_item[] entry. */
8299a2dd95SBruce Richardson #define MK_FLOW_ITEM(t, s) \
8399a2dd95SBruce Richardson 	[RTE_FLOW_ITEM_TYPE_ ## t] = { \
8499a2dd95SBruce Richardson 		.name = # t, \
8599a2dd95SBruce Richardson 		.size = s,               \
866cf72047SGregory Etelson 		.desc_fn = NULL,\
876cf72047SGregory Etelson 	}
886cf72047SGregory Etelson 
896cf72047SGregory Etelson #define MK_FLOW_ITEM_FN(t, s, fn) \
906cf72047SGregory Etelson 	[RTE_FLOW_ITEM_TYPE_ ## t] = {\
916cf72047SGregory Etelson 		.name = # t,                 \
926cf72047SGregory Etelson 		.size = s,                   \
936cf72047SGregory Etelson 		.desc_fn = fn,               \
9499a2dd95SBruce Richardson 	}
9599a2dd95SBruce Richardson 
9699a2dd95SBruce Richardson /** Information about known flow pattern items. */
9799a2dd95SBruce Richardson static const struct rte_flow_desc_data rte_flow_desc_item[] = {
9899a2dd95SBruce Richardson 	MK_FLOW_ITEM(END, 0),
9999a2dd95SBruce Richardson 	MK_FLOW_ITEM(VOID, 0),
10099a2dd95SBruce Richardson 	MK_FLOW_ITEM(INVERT, 0),
10199a2dd95SBruce Richardson 	MK_FLOW_ITEM(ANY, sizeof(struct rte_flow_item_any)),
10299a2dd95SBruce Richardson 	MK_FLOW_ITEM(PF, 0),
10399a2dd95SBruce Richardson 	MK_FLOW_ITEM(VF, sizeof(struct rte_flow_item_vf)),
10499a2dd95SBruce Richardson 	MK_FLOW_ITEM(PHY_PORT, sizeof(struct rte_flow_item_phy_port)),
10599a2dd95SBruce Richardson 	MK_FLOW_ITEM(PORT_ID, sizeof(struct rte_flow_item_port_id)),
10699a2dd95SBruce Richardson 	MK_FLOW_ITEM(RAW, sizeof(struct rte_flow_item_raw)),
10799a2dd95SBruce Richardson 	MK_FLOW_ITEM(ETH, sizeof(struct rte_flow_item_eth)),
10899a2dd95SBruce Richardson 	MK_FLOW_ITEM(VLAN, sizeof(struct rte_flow_item_vlan)),
10999a2dd95SBruce Richardson 	MK_FLOW_ITEM(IPV4, sizeof(struct rte_flow_item_ipv4)),
11099a2dd95SBruce Richardson 	MK_FLOW_ITEM(IPV6, sizeof(struct rte_flow_item_ipv6)),
11199a2dd95SBruce Richardson 	MK_FLOW_ITEM(ICMP, sizeof(struct rte_flow_item_icmp)),
11299a2dd95SBruce Richardson 	MK_FLOW_ITEM(UDP, sizeof(struct rte_flow_item_udp)),
11399a2dd95SBruce Richardson 	MK_FLOW_ITEM(TCP, sizeof(struct rte_flow_item_tcp)),
11499a2dd95SBruce Richardson 	MK_FLOW_ITEM(SCTP, sizeof(struct rte_flow_item_sctp)),
11599a2dd95SBruce Richardson 	MK_FLOW_ITEM(VXLAN, sizeof(struct rte_flow_item_vxlan)),
11699a2dd95SBruce Richardson 	MK_FLOW_ITEM(E_TAG, sizeof(struct rte_flow_item_e_tag)),
11799a2dd95SBruce Richardson 	MK_FLOW_ITEM(NVGRE, sizeof(struct rte_flow_item_nvgre)),
11899a2dd95SBruce Richardson 	MK_FLOW_ITEM(MPLS, sizeof(struct rte_flow_item_mpls)),
11999a2dd95SBruce Richardson 	MK_FLOW_ITEM(GRE, sizeof(struct rte_flow_item_gre)),
12099a2dd95SBruce Richardson 	MK_FLOW_ITEM(FUZZY, sizeof(struct rte_flow_item_fuzzy)),
12199a2dd95SBruce Richardson 	MK_FLOW_ITEM(GTP, sizeof(struct rte_flow_item_gtp)),
12299a2dd95SBruce Richardson 	MK_FLOW_ITEM(GTPC, sizeof(struct rte_flow_item_gtp)),
12399a2dd95SBruce Richardson 	MK_FLOW_ITEM(GTPU, sizeof(struct rte_flow_item_gtp)),
12499a2dd95SBruce Richardson 	MK_FLOW_ITEM(ESP, sizeof(struct rte_flow_item_esp)),
12599a2dd95SBruce Richardson 	MK_FLOW_ITEM(GENEVE, sizeof(struct rte_flow_item_geneve)),
12699a2dd95SBruce Richardson 	MK_FLOW_ITEM(VXLAN_GPE, sizeof(struct rte_flow_item_vxlan_gpe)),
12799a2dd95SBruce Richardson 	MK_FLOW_ITEM(ARP_ETH_IPV4, sizeof(struct rte_flow_item_arp_eth_ipv4)),
12899a2dd95SBruce Richardson 	MK_FLOW_ITEM(IPV6_EXT, sizeof(struct rte_flow_item_ipv6_ext)),
12999a2dd95SBruce Richardson 	MK_FLOW_ITEM(IPV6_FRAG_EXT, sizeof(struct rte_flow_item_ipv6_frag_ext)),
13099a2dd95SBruce Richardson 	MK_FLOW_ITEM(ICMP6, sizeof(struct rte_flow_item_icmp6)),
13199a2dd95SBruce Richardson 	MK_FLOW_ITEM(ICMP6_ND_NS, sizeof(struct rte_flow_item_icmp6_nd_ns)),
13299a2dd95SBruce Richardson 	MK_FLOW_ITEM(ICMP6_ND_NA, sizeof(struct rte_flow_item_icmp6_nd_na)),
13399a2dd95SBruce Richardson 	MK_FLOW_ITEM(ICMP6_ND_OPT, sizeof(struct rte_flow_item_icmp6_nd_opt)),
13499a2dd95SBruce Richardson 	MK_FLOW_ITEM(ICMP6_ND_OPT_SLA_ETH,
13599a2dd95SBruce Richardson 		     sizeof(struct rte_flow_item_icmp6_nd_opt_sla_eth)),
13699a2dd95SBruce Richardson 	MK_FLOW_ITEM(ICMP6_ND_OPT_TLA_ETH,
13799a2dd95SBruce Richardson 		     sizeof(struct rte_flow_item_icmp6_nd_opt_tla_eth)),
13899a2dd95SBruce Richardson 	MK_FLOW_ITEM(MARK, sizeof(struct rte_flow_item_mark)),
13999a2dd95SBruce Richardson 	MK_FLOW_ITEM(META, sizeof(struct rte_flow_item_meta)),
14099a2dd95SBruce Richardson 	MK_FLOW_ITEM(TAG, sizeof(struct rte_flow_item_tag)),
14199a2dd95SBruce Richardson 	MK_FLOW_ITEM(GRE_KEY, sizeof(rte_be32_t)),
142f61490bdSSean Zhang 	MK_FLOW_ITEM(GRE_OPTION, sizeof(struct rte_flow_item_gre_opt)),
14399a2dd95SBruce Richardson 	MK_FLOW_ITEM(GTP_PSC, sizeof(struct rte_flow_item_gtp_psc)),
14499a2dd95SBruce Richardson 	MK_FLOW_ITEM(PPPOES, sizeof(struct rte_flow_item_pppoe)),
14599a2dd95SBruce Richardson 	MK_FLOW_ITEM(PPPOED, sizeof(struct rte_flow_item_pppoe)),
14699a2dd95SBruce Richardson 	MK_FLOW_ITEM(PPPOE_PROTO_ID,
14799a2dd95SBruce Richardson 			sizeof(struct rte_flow_item_pppoe_proto_id)),
14899a2dd95SBruce Richardson 	MK_FLOW_ITEM(NSH, sizeof(struct rte_flow_item_nsh)),
14999a2dd95SBruce Richardson 	MK_FLOW_ITEM(IGMP, sizeof(struct rte_flow_item_igmp)),
15099a2dd95SBruce Richardson 	MK_FLOW_ITEM(AH, sizeof(struct rte_flow_item_ah)),
15199a2dd95SBruce Richardson 	MK_FLOW_ITEM(HIGIG2, sizeof(struct rte_flow_item_higig2_hdr)),
15299a2dd95SBruce Richardson 	MK_FLOW_ITEM(L2TPV3OIP, sizeof(struct rte_flow_item_l2tpv3oip)),
15399a2dd95SBruce Richardson 	MK_FLOW_ITEM(PFCP, sizeof(struct rte_flow_item_pfcp)),
15499a2dd95SBruce Richardson 	MK_FLOW_ITEM(ECPRI, sizeof(struct rte_flow_item_ecpri)),
15599a2dd95SBruce Richardson 	MK_FLOW_ITEM(GENEVE_OPT, sizeof(struct rte_flow_item_geneve_opt)),
1561d0b9c7dSGregory Etelson 	MK_FLOW_ITEM(INTEGRITY, sizeof(struct rte_flow_item_integrity)),
1579847fd12SBing Zhao 	MK_FLOW_ITEM(CONNTRACK, sizeof(uint32_t)),
158081e42daSIvan Malov 	MK_FLOW_ITEM(PORT_REPRESENTOR, sizeof(struct rte_flow_item_ethdev)),
15949863ae2SIvan Malov 	MK_FLOW_ITEM(REPRESENTED_PORT, sizeof(struct rte_flow_item_ethdev)),
160dc4d860eSViacheslav Ovsiienko 	MK_FLOW_ITEM_FN(FLEX, sizeof(struct rte_flow_item_flex),
161dc4d860eSViacheslav Ovsiienko 			rte_flow_item_flex_conv),
1623a929df1SJie Wang 	MK_FLOW_ITEM(L2TPV2, sizeof(struct rte_flow_item_l2tpv2)),
1633a929df1SJie Wang 	MK_FLOW_ITEM(PPP, sizeof(struct rte_flow_item_ppp)),
16499a2dd95SBruce Richardson };
16599a2dd95SBruce Richardson 
16699a2dd95SBruce Richardson /** Generate flow_action[] entry. */
16799a2dd95SBruce Richardson #define MK_FLOW_ACTION(t, s) \
16899a2dd95SBruce Richardson 	[RTE_FLOW_ACTION_TYPE_ ## t] = { \
16999a2dd95SBruce Richardson 		.name = # t, \
17099a2dd95SBruce Richardson 		.size = s, \
1716cf72047SGregory Etelson 		.desc_fn = NULL,\
17299a2dd95SBruce Richardson 	}
17399a2dd95SBruce Richardson 
1746cf72047SGregory Etelson #define MK_FLOW_ACTION_FN(t, fn) \
1756cf72047SGregory Etelson 	[RTE_FLOW_ACTION_TYPE_ ## t] = { \
1766cf72047SGregory Etelson 		.name = # t, \
1776cf72047SGregory Etelson 		.size = 0, \
1786cf72047SGregory Etelson 		.desc_fn = fn,\
1796cf72047SGregory Etelson 	}
1806cf72047SGregory Etelson 
1816cf72047SGregory Etelson 
18299a2dd95SBruce Richardson /** Information about known flow actions. */
18399a2dd95SBruce Richardson static const struct rte_flow_desc_data rte_flow_desc_action[] = {
18499a2dd95SBruce Richardson 	MK_FLOW_ACTION(END, 0),
18599a2dd95SBruce Richardson 	MK_FLOW_ACTION(VOID, 0),
18699a2dd95SBruce Richardson 	MK_FLOW_ACTION(PASSTHRU, 0),
18799a2dd95SBruce Richardson 	MK_FLOW_ACTION(JUMP, sizeof(struct rte_flow_action_jump)),
18899a2dd95SBruce Richardson 	MK_FLOW_ACTION(MARK, sizeof(struct rte_flow_action_mark)),
18999a2dd95SBruce Richardson 	MK_FLOW_ACTION(FLAG, 0),
19099a2dd95SBruce Richardson 	MK_FLOW_ACTION(QUEUE, sizeof(struct rte_flow_action_queue)),
19199a2dd95SBruce Richardson 	MK_FLOW_ACTION(DROP, 0),
19299a2dd95SBruce Richardson 	MK_FLOW_ACTION(COUNT, sizeof(struct rte_flow_action_count)),
19399a2dd95SBruce Richardson 	MK_FLOW_ACTION(RSS, sizeof(struct rte_flow_action_rss)),
19499a2dd95SBruce Richardson 	MK_FLOW_ACTION(PF, 0),
19599a2dd95SBruce Richardson 	MK_FLOW_ACTION(VF, sizeof(struct rte_flow_action_vf)),
19699a2dd95SBruce Richardson 	MK_FLOW_ACTION(PHY_PORT, sizeof(struct rte_flow_action_phy_port)),
19799a2dd95SBruce Richardson 	MK_FLOW_ACTION(PORT_ID, sizeof(struct rte_flow_action_port_id)),
19899a2dd95SBruce Richardson 	MK_FLOW_ACTION(METER, sizeof(struct rte_flow_action_meter)),
19999a2dd95SBruce Richardson 	MK_FLOW_ACTION(SECURITY, sizeof(struct rte_flow_action_security)),
20099a2dd95SBruce Richardson 	MK_FLOW_ACTION(OF_SET_MPLS_TTL,
20199a2dd95SBruce Richardson 		       sizeof(struct rte_flow_action_of_set_mpls_ttl)),
20299a2dd95SBruce Richardson 	MK_FLOW_ACTION(OF_DEC_MPLS_TTL, 0),
20399a2dd95SBruce Richardson 	MK_FLOW_ACTION(OF_SET_NW_TTL,
20499a2dd95SBruce Richardson 		       sizeof(struct rte_flow_action_of_set_nw_ttl)),
20599a2dd95SBruce Richardson 	MK_FLOW_ACTION(OF_DEC_NW_TTL, 0),
20699a2dd95SBruce Richardson 	MK_FLOW_ACTION(OF_COPY_TTL_OUT, 0),
20799a2dd95SBruce Richardson 	MK_FLOW_ACTION(OF_COPY_TTL_IN, 0),
20899a2dd95SBruce Richardson 	MK_FLOW_ACTION(OF_POP_VLAN, 0),
20999a2dd95SBruce Richardson 	MK_FLOW_ACTION(OF_PUSH_VLAN,
21099a2dd95SBruce Richardson 		       sizeof(struct rte_flow_action_of_push_vlan)),
21199a2dd95SBruce Richardson 	MK_FLOW_ACTION(OF_SET_VLAN_VID,
21299a2dd95SBruce Richardson 		       sizeof(struct rte_flow_action_of_set_vlan_vid)),
21399a2dd95SBruce Richardson 	MK_FLOW_ACTION(OF_SET_VLAN_PCP,
21499a2dd95SBruce Richardson 		       sizeof(struct rte_flow_action_of_set_vlan_pcp)),
21599a2dd95SBruce Richardson 	MK_FLOW_ACTION(OF_POP_MPLS,
21699a2dd95SBruce Richardson 		       sizeof(struct rte_flow_action_of_pop_mpls)),
21799a2dd95SBruce Richardson 	MK_FLOW_ACTION(OF_PUSH_MPLS,
21899a2dd95SBruce Richardson 		       sizeof(struct rte_flow_action_of_push_mpls)),
21999a2dd95SBruce Richardson 	MK_FLOW_ACTION(VXLAN_ENCAP, sizeof(struct rte_flow_action_vxlan_encap)),
22099a2dd95SBruce Richardson 	MK_FLOW_ACTION(VXLAN_DECAP, 0),
22199a2dd95SBruce Richardson 	MK_FLOW_ACTION(NVGRE_ENCAP, sizeof(struct rte_flow_action_vxlan_encap)),
22299a2dd95SBruce Richardson 	MK_FLOW_ACTION(NVGRE_DECAP, 0),
22399a2dd95SBruce Richardson 	MK_FLOW_ACTION(RAW_ENCAP, sizeof(struct rte_flow_action_raw_encap)),
22499a2dd95SBruce Richardson 	MK_FLOW_ACTION(RAW_DECAP, sizeof(struct rte_flow_action_raw_decap)),
22599a2dd95SBruce Richardson 	MK_FLOW_ACTION(SET_IPV4_SRC,
22699a2dd95SBruce Richardson 		       sizeof(struct rte_flow_action_set_ipv4)),
22799a2dd95SBruce Richardson 	MK_FLOW_ACTION(SET_IPV4_DST,
22899a2dd95SBruce Richardson 		       sizeof(struct rte_flow_action_set_ipv4)),
22999a2dd95SBruce Richardson 	MK_FLOW_ACTION(SET_IPV6_SRC,
23099a2dd95SBruce Richardson 		       sizeof(struct rte_flow_action_set_ipv6)),
23199a2dd95SBruce Richardson 	MK_FLOW_ACTION(SET_IPV6_DST,
23299a2dd95SBruce Richardson 		       sizeof(struct rte_flow_action_set_ipv6)),
23399a2dd95SBruce Richardson 	MK_FLOW_ACTION(SET_TP_SRC,
23499a2dd95SBruce Richardson 		       sizeof(struct rte_flow_action_set_tp)),
23599a2dd95SBruce Richardson 	MK_FLOW_ACTION(SET_TP_DST,
23699a2dd95SBruce Richardson 		       sizeof(struct rte_flow_action_set_tp)),
23799a2dd95SBruce Richardson 	MK_FLOW_ACTION(MAC_SWAP, 0),
23899a2dd95SBruce Richardson 	MK_FLOW_ACTION(DEC_TTL, 0),
23999a2dd95SBruce Richardson 	MK_FLOW_ACTION(SET_TTL, sizeof(struct rte_flow_action_set_ttl)),
24099a2dd95SBruce Richardson 	MK_FLOW_ACTION(SET_MAC_SRC, sizeof(struct rte_flow_action_set_mac)),
24199a2dd95SBruce Richardson 	MK_FLOW_ACTION(SET_MAC_DST, sizeof(struct rte_flow_action_set_mac)),
24299a2dd95SBruce Richardson 	MK_FLOW_ACTION(INC_TCP_SEQ, sizeof(rte_be32_t)),
24399a2dd95SBruce Richardson 	MK_FLOW_ACTION(DEC_TCP_SEQ, sizeof(rte_be32_t)),
24499a2dd95SBruce Richardson 	MK_FLOW_ACTION(INC_TCP_ACK, sizeof(rte_be32_t)),
24599a2dd95SBruce Richardson 	MK_FLOW_ACTION(DEC_TCP_ACK, sizeof(rte_be32_t)),
24699a2dd95SBruce Richardson 	MK_FLOW_ACTION(SET_TAG, sizeof(struct rte_flow_action_set_tag)),
24799a2dd95SBruce Richardson 	MK_FLOW_ACTION(SET_META, sizeof(struct rte_flow_action_set_meta)),
24899a2dd95SBruce Richardson 	MK_FLOW_ACTION(SET_IPV4_DSCP, sizeof(struct rte_flow_action_set_dscp)),
24999a2dd95SBruce Richardson 	MK_FLOW_ACTION(SET_IPV6_DSCP, sizeof(struct rte_flow_action_set_dscp)),
25099a2dd95SBruce Richardson 	MK_FLOW_ACTION(AGE, sizeof(struct rte_flow_action_age)),
25199a2dd95SBruce Richardson 	MK_FLOW_ACTION(SAMPLE, sizeof(struct rte_flow_action_sample)),
25299a2dd95SBruce Richardson 	MK_FLOW_ACTION(MODIFY_FIELD,
25399a2dd95SBruce Richardson 		       sizeof(struct rte_flow_action_modify_field)),
25499a2dd95SBruce Richardson 	/**
2554b61b877SBing Zhao 	 * Indirect action represented as handle of type
2564b61b877SBing Zhao 	 * (struct rte_flow_action_handle *) stored in conf field (see
25799a2dd95SBruce Richardson 	 * struct rte_flow_action); no need for additional structure to * store
2584b61b877SBing Zhao 	 * indirect action handle.
25999a2dd95SBruce Richardson 	 */
2604b61b877SBing Zhao 	MK_FLOW_ACTION(INDIRECT, 0),
2619847fd12SBing Zhao 	MK_FLOW_ACTION(CONNTRACK, sizeof(struct rte_flow_action_conntrack)),
2628edb6bc0SIvan Malov 	MK_FLOW_ACTION(PORT_REPRESENTOR, sizeof(struct rte_flow_action_ethdev)),
26388caad25SIvan Malov 	MK_FLOW_ACTION(REPRESENTED_PORT, sizeof(struct rte_flow_action_ethdev)),
26499a2dd95SBruce Richardson };
26599a2dd95SBruce Richardson 
26699a2dd95SBruce Richardson int
rte_flow_dynf_metadata_register(void)26799a2dd95SBruce Richardson rte_flow_dynf_metadata_register(void)
26899a2dd95SBruce Richardson {
26999a2dd95SBruce Richardson 	int offset;
27099a2dd95SBruce Richardson 	int flag;
27199a2dd95SBruce Richardson 
27299a2dd95SBruce Richardson 	static const struct rte_mbuf_dynfield desc_offs = {
27399a2dd95SBruce Richardson 		.name = RTE_MBUF_DYNFIELD_METADATA_NAME,
27499a2dd95SBruce Richardson 		.size = sizeof(uint32_t),
27599a2dd95SBruce Richardson 		.align = __alignof__(uint32_t),
27699a2dd95SBruce Richardson 	};
27799a2dd95SBruce Richardson 	static const struct rte_mbuf_dynflag desc_flag = {
27899a2dd95SBruce Richardson 		.name = RTE_MBUF_DYNFLAG_METADATA_NAME,
27999a2dd95SBruce Richardson 	};
28099a2dd95SBruce Richardson 
28199a2dd95SBruce Richardson 	offset = rte_mbuf_dynfield_register(&desc_offs);
28299a2dd95SBruce Richardson 	if (offset < 0)
28399a2dd95SBruce Richardson 		goto error;
28499a2dd95SBruce Richardson 	flag = rte_mbuf_dynflag_register(&desc_flag);
28599a2dd95SBruce Richardson 	if (flag < 0)
28699a2dd95SBruce Richardson 		goto error;
28799a2dd95SBruce Richardson 	rte_flow_dynf_metadata_offs = offset;
288e1823e08SThomas Monjalon 	rte_flow_dynf_metadata_mask = RTE_BIT64(flag);
28999a2dd95SBruce Richardson 	return 0;
29099a2dd95SBruce Richardson 
29199a2dd95SBruce Richardson error:
29299a2dd95SBruce Richardson 	rte_flow_dynf_metadata_offs = -1;
293e1823e08SThomas Monjalon 	rte_flow_dynf_metadata_mask = UINT64_C(0);
29499a2dd95SBruce Richardson 	return -rte_errno;
29599a2dd95SBruce Richardson }
29699a2dd95SBruce Richardson 
29799a2dd95SBruce Richardson static inline void
fts_enter(struct rte_eth_dev * dev)29899a2dd95SBruce Richardson fts_enter(struct rte_eth_dev *dev)
29999a2dd95SBruce Richardson {
30099a2dd95SBruce Richardson 	if (!(dev->data->dev_flags & RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE))
30199a2dd95SBruce Richardson 		pthread_mutex_lock(&dev->data->flow_ops_mutex);
30299a2dd95SBruce Richardson }
30399a2dd95SBruce Richardson 
30499a2dd95SBruce Richardson static inline void
fts_exit(struct rte_eth_dev * dev)30599a2dd95SBruce Richardson fts_exit(struct rte_eth_dev *dev)
30699a2dd95SBruce Richardson {
30799a2dd95SBruce Richardson 	if (!(dev->data->dev_flags & RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE))
30899a2dd95SBruce Richardson 		pthread_mutex_unlock(&dev->data->flow_ops_mutex);
30999a2dd95SBruce Richardson }
31099a2dd95SBruce Richardson 
31199a2dd95SBruce Richardson static int
flow_err(uint16_t port_id,int ret,struct rte_flow_error * error)31299a2dd95SBruce Richardson flow_err(uint16_t port_id, int ret, struct rte_flow_error *error)
31399a2dd95SBruce Richardson {
31499a2dd95SBruce Richardson 	if (ret == 0)
31599a2dd95SBruce Richardson 		return 0;
31699a2dd95SBruce Richardson 	if (rte_eth_dev_is_removed(port_id))
31799a2dd95SBruce Richardson 		return rte_flow_error_set(error, EIO,
31899a2dd95SBruce Richardson 					  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
31999a2dd95SBruce Richardson 					  NULL, rte_strerror(EIO));
32099a2dd95SBruce Richardson 	return ret;
32199a2dd95SBruce Richardson }
32299a2dd95SBruce Richardson 
32399a2dd95SBruce Richardson /* Get generic flow operations structure from a port. */
32499a2dd95SBruce Richardson const struct rte_flow_ops *
rte_flow_ops_get(uint16_t port_id,struct rte_flow_error * error)32599a2dd95SBruce Richardson rte_flow_ops_get(uint16_t port_id, struct rte_flow_error *error)
32699a2dd95SBruce Richardson {
32799a2dd95SBruce Richardson 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
32899a2dd95SBruce Richardson 	const struct rte_flow_ops *ops;
32999a2dd95SBruce Richardson 	int code;
33099a2dd95SBruce Richardson 
33199a2dd95SBruce Richardson 	if (unlikely(!rte_eth_dev_is_valid_port(port_id)))
33299a2dd95SBruce Richardson 		code = ENODEV;
33399a2dd95SBruce Richardson 	else if (unlikely(dev->dev_ops->flow_ops_get == NULL))
33499a2dd95SBruce Richardson 		/* flow API not supported with this driver dev_ops */
33599a2dd95SBruce Richardson 		code = ENOSYS;
33699a2dd95SBruce Richardson 	else
33799a2dd95SBruce Richardson 		code = dev->dev_ops->flow_ops_get(dev, &ops);
33899a2dd95SBruce Richardson 	if (code == 0 && ops == NULL)
33999a2dd95SBruce Richardson 		/* flow API not supported with this device */
34099a2dd95SBruce Richardson 		code = ENOSYS;
34199a2dd95SBruce Richardson 
34299a2dd95SBruce Richardson 	if (code != 0) {
34399a2dd95SBruce Richardson 		rte_flow_error_set(error, code, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
34499a2dd95SBruce Richardson 				   NULL, rte_strerror(code));
34599a2dd95SBruce Richardson 		return NULL;
34699a2dd95SBruce Richardson 	}
34799a2dd95SBruce Richardson 	return ops;
34899a2dd95SBruce Richardson }
34999a2dd95SBruce Richardson 
35099a2dd95SBruce Richardson /* Check whether a flow rule can be created on a given port. */
35199a2dd95SBruce Richardson int
rte_flow_validate(uint16_t port_id,const struct rte_flow_attr * attr,const struct rte_flow_item pattern[],const struct rte_flow_action actions[],struct rte_flow_error * error)35299a2dd95SBruce Richardson rte_flow_validate(uint16_t port_id,
35399a2dd95SBruce Richardson 		  const struct rte_flow_attr *attr,
35499a2dd95SBruce Richardson 		  const struct rte_flow_item pattern[],
35599a2dd95SBruce Richardson 		  const struct rte_flow_action actions[],
35699a2dd95SBruce Richardson 		  struct rte_flow_error *error)
35799a2dd95SBruce Richardson {
35899a2dd95SBruce Richardson 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
35999a2dd95SBruce Richardson 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
36099a2dd95SBruce Richardson 	int ret;
36199a2dd95SBruce Richardson 
36299a2dd95SBruce Richardson 	if (unlikely(!ops))
36399a2dd95SBruce Richardson 		return -rte_errno;
36499a2dd95SBruce Richardson 	if (likely(!!ops->validate)) {
36599a2dd95SBruce Richardson 		fts_enter(dev);
36699a2dd95SBruce Richardson 		ret = ops->validate(dev, attr, pattern, actions, error);
36799a2dd95SBruce Richardson 		fts_exit(dev);
36899a2dd95SBruce Richardson 		return flow_err(port_id, ret, error);
36999a2dd95SBruce Richardson 	}
37099a2dd95SBruce Richardson 	return rte_flow_error_set(error, ENOSYS,
37199a2dd95SBruce Richardson 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
37299a2dd95SBruce Richardson 				  NULL, rte_strerror(ENOSYS));
37399a2dd95SBruce Richardson }
37499a2dd95SBruce Richardson 
37599a2dd95SBruce Richardson /* Create a flow rule on a given port. */
37699a2dd95SBruce Richardson struct rte_flow *
rte_flow_create(uint16_t port_id,const struct rte_flow_attr * attr,const struct rte_flow_item pattern[],const struct rte_flow_action actions[],struct rte_flow_error * error)37799a2dd95SBruce Richardson rte_flow_create(uint16_t port_id,
37899a2dd95SBruce Richardson 		const struct rte_flow_attr *attr,
37999a2dd95SBruce Richardson 		const struct rte_flow_item pattern[],
38099a2dd95SBruce Richardson 		const struct rte_flow_action actions[],
38199a2dd95SBruce Richardson 		struct rte_flow_error *error)
38299a2dd95SBruce Richardson {
38399a2dd95SBruce Richardson 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
38499a2dd95SBruce Richardson 	struct rte_flow *flow;
38599a2dd95SBruce Richardson 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
38699a2dd95SBruce Richardson 
38799a2dd95SBruce Richardson 	if (unlikely(!ops))
38899a2dd95SBruce Richardson 		return NULL;
38999a2dd95SBruce Richardson 	if (likely(!!ops->create)) {
39099a2dd95SBruce Richardson 		fts_enter(dev);
39199a2dd95SBruce Richardson 		flow = ops->create(dev, attr, pattern, actions, error);
39299a2dd95SBruce Richardson 		fts_exit(dev);
39399a2dd95SBruce Richardson 		if (flow == NULL)
39499a2dd95SBruce Richardson 			flow_err(port_id, -rte_errno, error);
39599a2dd95SBruce Richardson 		return flow;
39699a2dd95SBruce Richardson 	}
39799a2dd95SBruce Richardson 	rte_flow_error_set(error, ENOSYS, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
39899a2dd95SBruce Richardson 			   NULL, rte_strerror(ENOSYS));
39999a2dd95SBruce Richardson 	return NULL;
40099a2dd95SBruce Richardson }
40199a2dd95SBruce Richardson 
40299a2dd95SBruce Richardson /* Destroy a flow rule on a given port. */
40399a2dd95SBruce Richardson int
rte_flow_destroy(uint16_t port_id,struct rte_flow * flow,struct rte_flow_error * error)40499a2dd95SBruce Richardson rte_flow_destroy(uint16_t port_id,
40599a2dd95SBruce Richardson 		 struct rte_flow *flow,
40699a2dd95SBruce Richardson 		 struct rte_flow_error *error)
40799a2dd95SBruce Richardson {
40899a2dd95SBruce Richardson 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
40999a2dd95SBruce Richardson 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
41099a2dd95SBruce Richardson 	int ret;
41199a2dd95SBruce Richardson 
41299a2dd95SBruce Richardson 	if (unlikely(!ops))
41399a2dd95SBruce Richardson 		return -rte_errno;
41499a2dd95SBruce Richardson 	if (likely(!!ops->destroy)) {
41599a2dd95SBruce Richardson 		fts_enter(dev);
41699a2dd95SBruce Richardson 		ret = ops->destroy(dev, flow, error);
41799a2dd95SBruce Richardson 		fts_exit(dev);
41899a2dd95SBruce Richardson 		return flow_err(port_id, ret, error);
41999a2dd95SBruce Richardson 	}
42099a2dd95SBruce Richardson 	return rte_flow_error_set(error, ENOSYS,
42199a2dd95SBruce Richardson 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
42299a2dd95SBruce Richardson 				  NULL, rte_strerror(ENOSYS));
42399a2dd95SBruce Richardson }
42499a2dd95SBruce Richardson 
42599a2dd95SBruce Richardson /* Destroy all flow rules associated with a port. */
42699a2dd95SBruce Richardson int
rte_flow_flush(uint16_t port_id,struct rte_flow_error * error)42799a2dd95SBruce Richardson rte_flow_flush(uint16_t port_id,
42899a2dd95SBruce Richardson 	       struct rte_flow_error *error)
42999a2dd95SBruce Richardson {
43099a2dd95SBruce Richardson 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
43199a2dd95SBruce Richardson 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
43299a2dd95SBruce Richardson 	int ret;
43399a2dd95SBruce Richardson 
43499a2dd95SBruce Richardson 	if (unlikely(!ops))
43599a2dd95SBruce Richardson 		return -rte_errno;
43699a2dd95SBruce Richardson 	if (likely(!!ops->flush)) {
43799a2dd95SBruce Richardson 		fts_enter(dev);
43899a2dd95SBruce Richardson 		ret = ops->flush(dev, error);
43999a2dd95SBruce Richardson 		fts_exit(dev);
44099a2dd95SBruce Richardson 		return flow_err(port_id, ret, error);
44199a2dd95SBruce Richardson 	}
44299a2dd95SBruce Richardson 	return rte_flow_error_set(error, ENOSYS,
44399a2dd95SBruce Richardson 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
44499a2dd95SBruce Richardson 				  NULL, rte_strerror(ENOSYS));
44599a2dd95SBruce Richardson }
44699a2dd95SBruce Richardson 
44799a2dd95SBruce Richardson /* Query an existing flow rule. */
44899a2dd95SBruce Richardson int
rte_flow_query(uint16_t port_id,struct rte_flow * flow,const struct rte_flow_action * action,void * data,struct rte_flow_error * error)44999a2dd95SBruce Richardson rte_flow_query(uint16_t port_id,
45099a2dd95SBruce Richardson 	       struct rte_flow *flow,
45199a2dd95SBruce Richardson 	       const struct rte_flow_action *action,
45299a2dd95SBruce Richardson 	       void *data,
45399a2dd95SBruce Richardson 	       struct rte_flow_error *error)
45499a2dd95SBruce Richardson {
45599a2dd95SBruce Richardson 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
45699a2dd95SBruce Richardson 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
45799a2dd95SBruce Richardson 	int ret;
45899a2dd95SBruce Richardson 
45999a2dd95SBruce Richardson 	if (!ops)
46099a2dd95SBruce Richardson 		return -rte_errno;
46199a2dd95SBruce Richardson 	if (likely(!!ops->query)) {
46299a2dd95SBruce Richardson 		fts_enter(dev);
46399a2dd95SBruce Richardson 		ret = ops->query(dev, flow, action, data, error);
46499a2dd95SBruce Richardson 		fts_exit(dev);
46599a2dd95SBruce Richardson 		return flow_err(port_id, ret, error);
46699a2dd95SBruce Richardson 	}
46799a2dd95SBruce Richardson 	return rte_flow_error_set(error, ENOSYS,
46899a2dd95SBruce Richardson 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
46999a2dd95SBruce Richardson 				  NULL, rte_strerror(ENOSYS));
47099a2dd95SBruce Richardson }
47199a2dd95SBruce Richardson 
47299a2dd95SBruce Richardson /* Restrict ingress traffic to the defined flow rules. */
47399a2dd95SBruce Richardson int
rte_flow_isolate(uint16_t port_id,int set,struct rte_flow_error * error)47499a2dd95SBruce Richardson rte_flow_isolate(uint16_t port_id,
47599a2dd95SBruce Richardson 		 int set,
47699a2dd95SBruce Richardson 		 struct rte_flow_error *error)
47799a2dd95SBruce Richardson {
47899a2dd95SBruce Richardson 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
47999a2dd95SBruce Richardson 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
48099a2dd95SBruce Richardson 	int ret;
48199a2dd95SBruce Richardson 
48299a2dd95SBruce Richardson 	if (!ops)
48399a2dd95SBruce Richardson 		return -rte_errno;
48499a2dd95SBruce Richardson 	if (likely(!!ops->isolate)) {
48599a2dd95SBruce Richardson 		fts_enter(dev);
48699a2dd95SBruce Richardson 		ret = ops->isolate(dev, set, error);
48799a2dd95SBruce Richardson 		fts_exit(dev);
48899a2dd95SBruce Richardson 		return flow_err(port_id, ret, error);
48999a2dd95SBruce Richardson 	}
49099a2dd95SBruce Richardson 	return rte_flow_error_set(error, ENOSYS,
49199a2dd95SBruce Richardson 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
49299a2dd95SBruce Richardson 				  NULL, rte_strerror(ENOSYS));
49399a2dd95SBruce Richardson }
49499a2dd95SBruce Richardson 
49599a2dd95SBruce Richardson /* Initialize flow error structure. */
49699a2dd95SBruce Richardson int
rte_flow_error_set(struct rte_flow_error * error,int code,enum rte_flow_error_type type,const void * cause,const char * message)49799a2dd95SBruce Richardson rte_flow_error_set(struct rte_flow_error *error,
49899a2dd95SBruce Richardson 		   int code,
49999a2dd95SBruce Richardson 		   enum rte_flow_error_type type,
50099a2dd95SBruce Richardson 		   const void *cause,
50199a2dd95SBruce Richardson 		   const char *message)
50299a2dd95SBruce Richardson {
50399a2dd95SBruce Richardson 	if (error) {
50499a2dd95SBruce Richardson 		*error = (struct rte_flow_error){
50599a2dd95SBruce Richardson 			.type = type,
50699a2dd95SBruce Richardson 			.cause = cause,
50799a2dd95SBruce Richardson 			.message = message,
50899a2dd95SBruce Richardson 		};
50999a2dd95SBruce Richardson 	}
51099a2dd95SBruce Richardson 	rte_errno = code;
51199a2dd95SBruce Richardson 	return -code;
51299a2dd95SBruce Richardson }
51399a2dd95SBruce Richardson 
51499a2dd95SBruce Richardson /** Pattern item specification types. */
51599a2dd95SBruce Richardson enum rte_flow_conv_item_spec_type {
51699a2dd95SBruce Richardson 	RTE_FLOW_CONV_ITEM_SPEC,
51799a2dd95SBruce Richardson 	RTE_FLOW_CONV_ITEM_LAST,
51899a2dd95SBruce Richardson 	RTE_FLOW_CONV_ITEM_MASK,
51999a2dd95SBruce Richardson };
52099a2dd95SBruce Richardson 
52199a2dd95SBruce Richardson /**
52299a2dd95SBruce Richardson  * Copy pattern item specification.
52399a2dd95SBruce Richardson  *
52499a2dd95SBruce Richardson  * @param[out] buf
52599a2dd95SBruce Richardson  *   Output buffer. Can be NULL if @p size is zero.
52699a2dd95SBruce Richardson  * @param size
52799a2dd95SBruce Richardson  *   Size of @p buf in bytes.
52899a2dd95SBruce Richardson  * @param[in] item
52999a2dd95SBruce Richardson  *   Pattern item to copy specification from.
53099a2dd95SBruce Richardson  * @param type
53199a2dd95SBruce Richardson  *   Specification selector for either @p spec, @p last or @p mask.
53299a2dd95SBruce Richardson  *
53399a2dd95SBruce Richardson  * @return
53499a2dd95SBruce Richardson  *   Number of bytes needed to store pattern item specification regardless
53599a2dd95SBruce Richardson  *   of @p size. @p buf contents are truncated to @p size if not large
53699a2dd95SBruce Richardson  *   enough.
53799a2dd95SBruce Richardson  */
53899a2dd95SBruce Richardson static size_t
rte_flow_conv_item_spec(void * buf,const size_t size,const struct rte_flow_item * item,enum rte_flow_conv_item_spec_type type)53999a2dd95SBruce Richardson rte_flow_conv_item_spec(void *buf, const size_t size,
54099a2dd95SBruce Richardson 			const struct rte_flow_item *item,
54199a2dd95SBruce Richardson 			enum rte_flow_conv_item_spec_type type)
54299a2dd95SBruce Richardson {
54399a2dd95SBruce Richardson 	size_t off;
54499a2dd95SBruce Richardson 	const void *data =
54599a2dd95SBruce Richardson 		type == RTE_FLOW_CONV_ITEM_SPEC ? item->spec :
54699a2dd95SBruce Richardson 		type == RTE_FLOW_CONV_ITEM_LAST ? item->last :
54799a2dd95SBruce Richardson 		type == RTE_FLOW_CONV_ITEM_MASK ? item->mask :
54899a2dd95SBruce Richardson 		NULL;
54999a2dd95SBruce Richardson 
55099a2dd95SBruce Richardson 	switch (item->type) {
55199a2dd95SBruce Richardson 		union {
55299a2dd95SBruce Richardson 			const struct rte_flow_item_raw *raw;
55399a2dd95SBruce Richardson 		} spec;
55499a2dd95SBruce Richardson 		union {
55599a2dd95SBruce Richardson 			const struct rte_flow_item_raw *raw;
55699a2dd95SBruce Richardson 		} last;
55799a2dd95SBruce Richardson 		union {
55899a2dd95SBruce Richardson 			const struct rte_flow_item_raw *raw;
55999a2dd95SBruce Richardson 		} mask;
56099a2dd95SBruce Richardson 		union {
56199a2dd95SBruce Richardson 			const struct rte_flow_item_raw *raw;
56299a2dd95SBruce Richardson 		} src;
56399a2dd95SBruce Richardson 		union {
56499a2dd95SBruce Richardson 			struct rte_flow_item_raw *raw;
56599a2dd95SBruce Richardson 		} dst;
56699a2dd95SBruce Richardson 		size_t tmp;
56799a2dd95SBruce Richardson 
56899a2dd95SBruce Richardson 	case RTE_FLOW_ITEM_TYPE_RAW:
56999a2dd95SBruce Richardson 		spec.raw = item->spec;
57099a2dd95SBruce Richardson 		last.raw = item->last ? item->last : item->spec;
57199a2dd95SBruce Richardson 		mask.raw = item->mask ? item->mask : &rte_flow_item_raw_mask;
57299a2dd95SBruce Richardson 		src.raw = data;
57399a2dd95SBruce Richardson 		dst.raw = buf;
57499a2dd95SBruce Richardson 		rte_memcpy(dst.raw,
57599a2dd95SBruce Richardson 			   (&(struct rte_flow_item_raw){
57699a2dd95SBruce Richardson 				.relative = src.raw->relative,
57799a2dd95SBruce Richardson 				.search = src.raw->search,
57899a2dd95SBruce Richardson 				.reserved = src.raw->reserved,
57999a2dd95SBruce Richardson 				.offset = src.raw->offset,
58099a2dd95SBruce Richardson 				.limit = src.raw->limit,
58199a2dd95SBruce Richardson 				.length = src.raw->length,
58299a2dd95SBruce Richardson 			   }),
58399a2dd95SBruce Richardson 			   size > sizeof(*dst.raw) ? sizeof(*dst.raw) : size);
58499a2dd95SBruce Richardson 		off = sizeof(*dst.raw);
58599a2dd95SBruce Richardson 		if (type == RTE_FLOW_CONV_ITEM_SPEC ||
58699a2dd95SBruce Richardson 		    (type == RTE_FLOW_CONV_ITEM_MASK &&
58799a2dd95SBruce Richardson 		     ((spec.raw->length & mask.raw->length) >=
58899a2dd95SBruce Richardson 		      (last.raw->length & mask.raw->length))))
58999a2dd95SBruce Richardson 			tmp = spec.raw->length & mask.raw->length;
59099a2dd95SBruce Richardson 		else
59199a2dd95SBruce Richardson 			tmp = last.raw->length & mask.raw->length;
59299a2dd95SBruce Richardson 		if (tmp) {
59399a2dd95SBruce Richardson 			off = RTE_ALIGN_CEIL(off, sizeof(*dst.raw->pattern));
59499a2dd95SBruce Richardson 			if (size >= off + tmp)
59599a2dd95SBruce Richardson 				dst.raw->pattern = rte_memcpy
59699a2dd95SBruce Richardson 					((void *)((uintptr_t)dst.raw + off),
59799a2dd95SBruce Richardson 					 src.raw->pattern, tmp);
59899a2dd95SBruce Richardson 			off += tmp;
59999a2dd95SBruce Richardson 		}
60099a2dd95SBruce Richardson 		break;
60199a2dd95SBruce Richardson 	default:
6026cf72047SGregory Etelson 		off = rte_flow_conv_copy(buf, data, size,
6036cf72047SGregory Etelson 					 rte_flow_desc_item, item->type);
60499a2dd95SBruce Richardson 		break;
60599a2dd95SBruce Richardson 	}
60699a2dd95SBruce Richardson 	return off;
60799a2dd95SBruce Richardson }
60899a2dd95SBruce Richardson 
60999a2dd95SBruce Richardson /**
61099a2dd95SBruce Richardson  * Copy action configuration.
61199a2dd95SBruce Richardson  *
61299a2dd95SBruce Richardson  * @param[out] buf
61399a2dd95SBruce Richardson  *   Output buffer. Can be NULL if @p size is zero.
61499a2dd95SBruce Richardson  * @param size
61599a2dd95SBruce Richardson  *   Size of @p buf in bytes.
61699a2dd95SBruce Richardson  * @param[in] action
61799a2dd95SBruce Richardson  *   Action to copy configuration from.
61899a2dd95SBruce Richardson  *
61999a2dd95SBruce Richardson  * @return
62099a2dd95SBruce Richardson  *   Number of bytes needed to store pattern item specification regardless
62199a2dd95SBruce Richardson  *   of @p size. @p buf contents are truncated to @p size if not large
62299a2dd95SBruce Richardson  *   enough.
62399a2dd95SBruce Richardson  */
62499a2dd95SBruce Richardson static size_t
rte_flow_conv_action_conf(void * buf,const size_t size,const struct rte_flow_action * action)62599a2dd95SBruce Richardson rte_flow_conv_action_conf(void *buf, const size_t size,
62699a2dd95SBruce Richardson 			  const struct rte_flow_action *action)
62799a2dd95SBruce Richardson {
62899a2dd95SBruce Richardson 	size_t off;
62999a2dd95SBruce Richardson 
63099a2dd95SBruce Richardson 	switch (action->type) {
63199a2dd95SBruce Richardson 		union {
63299a2dd95SBruce Richardson 			const struct rte_flow_action_rss *rss;
63399a2dd95SBruce Richardson 			const struct rte_flow_action_vxlan_encap *vxlan_encap;
63499a2dd95SBruce Richardson 			const struct rte_flow_action_nvgre_encap *nvgre_encap;
63599a2dd95SBruce Richardson 		} src;
63699a2dd95SBruce Richardson 		union {
63799a2dd95SBruce Richardson 			struct rte_flow_action_rss *rss;
63899a2dd95SBruce Richardson 			struct rte_flow_action_vxlan_encap *vxlan_encap;
63999a2dd95SBruce Richardson 			struct rte_flow_action_nvgre_encap *nvgre_encap;
64099a2dd95SBruce Richardson 		} dst;
64199a2dd95SBruce Richardson 		size_t tmp;
64299a2dd95SBruce Richardson 		int ret;
64399a2dd95SBruce Richardson 
64499a2dd95SBruce Richardson 	case RTE_FLOW_ACTION_TYPE_RSS:
64599a2dd95SBruce Richardson 		src.rss = action->conf;
64699a2dd95SBruce Richardson 		dst.rss = buf;
64799a2dd95SBruce Richardson 		rte_memcpy(dst.rss,
64899a2dd95SBruce Richardson 			   (&(struct rte_flow_action_rss){
64999a2dd95SBruce Richardson 				.func = src.rss->func,
65099a2dd95SBruce Richardson 				.level = src.rss->level,
65199a2dd95SBruce Richardson 				.types = src.rss->types,
65299a2dd95SBruce Richardson 				.key_len = src.rss->key_len,
65399a2dd95SBruce Richardson 				.queue_num = src.rss->queue_num,
65499a2dd95SBruce Richardson 			   }),
65599a2dd95SBruce Richardson 			   size > sizeof(*dst.rss) ? sizeof(*dst.rss) : size);
65699a2dd95SBruce Richardson 		off = sizeof(*dst.rss);
65799a2dd95SBruce Richardson 		if (src.rss->key_len && src.rss->key) {
65899a2dd95SBruce Richardson 			off = RTE_ALIGN_CEIL(off, sizeof(*dst.rss->key));
65999a2dd95SBruce Richardson 			tmp = sizeof(*src.rss->key) * src.rss->key_len;
66099a2dd95SBruce Richardson 			if (size >= off + tmp)
66199a2dd95SBruce Richardson 				dst.rss->key = rte_memcpy
66299a2dd95SBruce Richardson 					((void *)((uintptr_t)dst.rss + off),
66399a2dd95SBruce Richardson 					 src.rss->key, tmp);
66499a2dd95SBruce Richardson 			off += tmp;
66599a2dd95SBruce Richardson 		}
66699a2dd95SBruce Richardson 		if (src.rss->queue_num) {
66799a2dd95SBruce Richardson 			off = RTE_ALIGN_CEIL(off, sizeof(*dst.rss->queue));
66899a2dd95SBruce Richardson 			tmp = sizeof(*src.rss->queue) * src.rss->queue_num;
66999a2dd95SBruce Richardson 			if (size >= off + tmp)
67099a2dd95SBruce Richardson 				dst.rss->queue = rte_memcpy
67199a2dd95SBruce Richardson 					((void *)((uintptr_t)dst.rss + off),
67299a2dd95SBruce Richardson 					 src.rss->queue, tmp);
67399a2dd95SBruce Richardson 			off += tmp;
67499a2dd95SBruce Richardson 		}
67599a2dd95SBruce Richardson 		break;
67699a2dd95SBruce Richardson 	case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
67799a2dd95SBruce Richardson 	case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
67899a2dd95SBruce Richardson 		src.vxlan_encap = action->conf;
67999a2dd95SBruce Richardson 		dst.vxlan_encap = buf;
68099a2dd95SBruce Richardson 		RTE_BUILD_BUG_ON(sizeof(*src.vxlan_encap) !=
68199a2dd95SBruce Richardson 				 sizeof(*src.nvgre_encap) ||
68299a2dd95SBruce Richardson 				 offsetof(struct rte_flow_action_vxlan_encap,
68399a2dd95SBruce Richardson 					  definition) !=
68499a2dd95SBruce Richardson 				 offsetof(struct rte_flow_action_nvgre_encap,
68599a2dd95SBruce Richardson 					  definition));
68699a2dd95SBruce Richardson 		off = sizeof(*dst.vxlan_encap);
68799a2dd95SBruce Richardson 		if (src.vxlan_encap->definition) {
68899a2dd95SBruce Richardson 			off = RTE_ALIGN_CEIL
68999a2dd95SBruce Richardson 				(off, sizeof(*dst.vxlan_encap->definition));
69099a2dd95SBruce Richardson 			ret = rte_flow_conv
69199a2dd95SBruce Richardson 				(RTE_FLOW_CONV_OP_PATTERN,
69299a2dd95SBruce Richardson 				 (void *)((uintptr_t)dst.vxlan_encap + off),
69399a2dd95SBruce Richardson 				 size > off ? size - off : 0,
69499a2dd95SBruce Richardson 				 src.vxlan_encap->definition, NULL);
69599a2dd95SBruce Richardson 			if (ret < 0)
69699a2dd95SBruce Richardson 				return 0;
69799a2dd95SBruce Richardson 			if (size >= off + ret)
69899a2dd95SBruce Richardson 				dst.vxlan_encap->definition =
69999a2dd95SBruce Richardson 					(void *)((uintptr_t)dst.vxlan_encap +
70099a2dd95SBruce Richardson 						 off);
70199a2dd95SBruce Richardson 			off += ret;
70299a2dd95SBruce Richardson 		}
70399a2dd95SBruce Richardson 		break;
70499a2dd95SBruce Richardson 	default:
7056cf72047SGregory Etelson 		off = rte_flow_conv_copy(buf, action->conf, size,
7066cf72047SGregory Etelson 					 rte_flow_desc_action, action->type);
70799a2dd95SBruce Richardson 		break;
70899a2dd95SBruce Richardson 	}
70999a2dd95SBruce Richardson 	return off;
71099a2dd95SBruce Richardson }
71199a2dd95SBruce Richardson 
71299a2dd95SBruce Richardson /**
71399a2dd95SBruce Richardson  * Copy a list of pattern items.
71499a2dd95SBruce Richardson  *
71599a2dd95SBruce Richardson  * @param[out] dst
71699a2dd95SBruce Richardson  *   Destination buffer. Can be NULL if @p size is zero.
71799a2dd95SBruce Richardson  * @param size
71899a2dd95SBruce Richardson  *   Size of @p dst in bytes.
71999a2dd95SBruce Richardson  * @param[in] src
72099a2dd95SBruce Richardson  *   Source pattern items.
72199a2dd95SBruce Richardson  * @param num
72299a2dd95SBruce Richardson  *   Maximum number of pattern items to process from @p src or 0 to process
72399a2dd95SBruce Richardson  *   the entire list. In both cases, processing stops after
72499a2dd95SBruce Richardson  *   RTE_FLOW_ITEM_TYPE_END is encountered.
72599a2dd95SBruce Richardson  * @param[out] error
72699a2dd95SBruce Richardson  *   Perform verbose error reporting if not NULL.
72799a2dd95SBruce Richardson  *
72899a2dd95SBruce Richardson  * @return
72999a2dd95SBruce Richardson  *   A positive value representing the number of bytes needed to store
73099a2dd95SBruce Richardson  *   pattern items regardless of @p size on success (@p buf contents are
73199a2dd95SBruce Richardson  *   truncated to @p size if not large enough), a negative errno value
73299a2dd95SBruce Richardson  *   otherwise and rte_errno is set.
73399a2dd95SBruce Richardson  */
73499a2dd95SBruce Richardson static int
rte_flow_conv_pattern(struct rte_flow_item * dst,const size_t size,const struct rte_flow_item * src,unsigned int num,struct rte_flow_error * error)73599a2dd95SBruce Richardson rte_flow_conv_pattern(struct rte_flow_item *dst,
73699a2dd95SBruce Richardson 		      const size_t size,
73799a2dd95SBruce Richardson 		      const struct rte_flow_item *src,
73899a2dd95SBruce Richardson 		      unsigned int num,
73999a2dd95SBruce Richardson 		      struct rte_flow_error *error)
74099a2dd95SBruce Richardson {
74199a2dd95SBruce Richardson 	uintptr_t data = (uintptr_t)dst;
74299a2dd95SBruce Richardson 	size_t off;
74399a2dd95SBruce Richardson 	size_t ret;
74499a2dd95SBruce Richardson 	unsigned int i;
74599a2dd95SBruce Richardson 
74699a2dd95SBruce Richardson 	for (i = 0, off = 0; !num || i != num; ++i, ++src, ++dst) {
74799a2dd95SBruce Richardson 		/**
74899a2dd95SBruce Richardson 		 * allow PMD private flow item
74999a2dd95SBruce Richardson 		 */
75099a2dd95SBruce Richardson 		if (((int)src->type >= 0) &&
75199a2dd95SBruce Richardson 			((size_t)src->type >= RTE_DIM(rte_flow_desc_item) ||
75299a2dd95SBruce Richardson 		    !rte_flow_desc_item[src->type].name))
75399a2dd95SBruce Richardson 			return rte_flow_error_set
75499a2dd95SBruce Richardson 				(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, src,
75599a2dd95SBruce Richardson 				 "cannot convert unknown item type");
75699a2dd95SBruce Richardson 		if (size >= off + sizeof(*dst))
75799a2dd95SBruce Richardson 			*dst = (struct rte_flow_item){
75899a2dd95SBruce Richardson 				.type = src->type,
75999a2dd95SBruce Richardson 			};
76099a2dd95SBruce Richardson 		off += sizeof(*dst);
76199a2dd95SBruce Richardson 		if (!src->type)
76299a2dd95SBruce Richardson 			num = i + 1;
76399a2dd95SBruce Richardson 	}
76499a2dd95SBruce Richardson 	num = i;
76599a2dd95SBruce Richardson 	src -= num;
76699a2dd95SBruce Richardson 	dst -= num;
76799a2dd95SBruce Richardson 	do {
76899a2dd95SBruce Richardson 		if (src->spec) {
76999a2dd95SBruce Richardson 			off = RTE_ALIGN_CEIL(off, sizeof(double));
77099a2dd95SBruce Richardson 			ret = rte_flow_conv_item_spec
77199a2dd95SBruce Richardson 				((void *)(data + off),
77299a2dd95SBruce Richardson 				 size > off ? size - off : 0, src,
77399a2dd95SBruce Richardson 				 RTE_FLOW_CONV_ITEM_SPEC);
77499a2dd95SBruce Richardson 			if (size && size >= off + ret)
77599a2dd95SBruce Richardson 				dst->spec = (void *)(data + off);
77699a2dd95SBruce Richardson 			off += ret;
77799a2dd95SBruce Richardson 
77899a2dd95SBruce Richardson 		}
77999a2dd95SBruce Richardson 		if (src->last) {
78099a2dd95SBruce Richardson 			off = RTE_ALIGN_CEIL(off, sizeof(double));
78199a2dd95SBruce Richardson 			ret = rte_flow_conv_item_spec
78299a2dd95SBruce Richardson 				((void *)(data + off),
78399a2dd95SBruce Richardson 				 size > off ? size - off : 0, src,
78499a2dd95SBruce Richardson 				 RTE_FLOW_CONV_ITEM_LAST);
78599a2dd95SBruce Richardson 			if (size && size >= off + ret)
78699a2dd95SBruce Richardson 				dst->last = (void *)(data + off);
78799a2dd95SBruce Richardson 			off += ret;
78899a2dd95SBruce Richardson 		}
78999a2dd95SBruce Richardson 		if (src->mask) {
79099a2dd95SBruce Richardson 			off = RTE_ALIGN_CEIL(off, sizeof(double));
79199a2dd95SBruce Richardson 			ret = rte_flow_conv_item_spec
79299a2dd95SBruce Richardson 				((void *)(data + off),
79399a2dd95SBruce Richardson 				 size > off ? size - off : 0, src,
79499a2dd95SBruce Richardson 				 RTE_FLOW_CONV_ITEM_MASK);
79599a2dd95SBruce Richardson 			if (size && size >= off + ret)
79699a2dd95SBruce Richardson 				dst->mask = (void *)(data + off);
79799a2dd95SBruce Richardson 			off += ret;
79899a2dd95SBruce Richardson 		}
79999a2dd95SBruce Richardson 		++src;
80099a2dd95SBruce Richardson 		++dst;
80199a2dd95SBruce Richardson 	} while (--num);
80299a2dd95SBruce Richardson 	return off;
80399a2dd95SBruce Richardson }
80499a2dd95SBruce Richardson 
80599a2dd95SBruce Richardson /**
80699a2dd95SBruce Richardson  * Copy a list of actions.
80799a2dd95SBruce Richardson  *
80899a2dd95SBruce Richardson  * @param[out] dst
80999a2dd95SBruce Richardson  *   Destination buffer. Can be NULL if @p size is zero.
81099a2dd95SBruce Richardson  * @param size
81199a2dd95SBruce Richardson  *   Size of @p dst in bytes.
81299a2dd95SBruce Richardson  * @param[in] src
81399a2dd95SBruce Richardson  *   Source actions.
81499a2dd95SBruce Richardson  * @param num
81599a2dd95SBruce Richardson  *   Maximum number of actions to process from @p src or 0 to process the
81699a2dd95SBruce Richardson  *   entire list. In both cases, processing stops after
81799a2dd95SBruce Richardson  *   RTE_FLOW_ACTION_TYPE_END is encountered.
81899a2dd95SBruce Richardson  * @param[out] error
81999a2dd95SBruce Richardson  *   Perform verbose error reporting if not NULL.
82099a2dd95SBruce Richardson  *
82199a2dd95SBruce Richardson  * @return
82299a2dd95SBruce Richardson  *   A positive value representing the number of bytes needed to store
82399a2dd95SBruce Richardson  *   actions regardless of @p size on success (@p buf contents are truncated
82499a2dd95SBruce Richardson  *   to @p size if not large enough), a negative errno value otherwise and
82599a2dd95SBruce Richardson  *   rte_errno is set.
82699a2dd95SBruce Richardson  */
82799a2dd95SBruce Richardson static int
rte_flow_conv_actions(struct rte_flow_action * dst,const size_t size,const struct rte_flow_action * src,unsigned int num,struct rte_flow_error * error)82899a2dd95SBruce Richardson rte_flow_conv_actions(struct rte_flow_action *dst,
82999a2dd95SBruce Richardson 		      const size_t size,
83099a2dd95SBruce Richardson 		      const struct rte_flow_action *src,
83199a2dd95SBruce Richardson 		      unsigned int num,
83299a2dd95SBruce Richardson 		      struct rte_flow_error *error)
83399a2dd95SBruce Richardson {
83499a2dd95SBruce Richardson 	uintptr_t data = (uintptr_t)dst;
83599a2dd95SBruce Richardson 	size_t off;
83699a2dd95SBruce Richardson 	size_t ret;
83799a2dd95SBruce Richardson 	unsigned int i;
83899a2dd95SBruce Richardson 
83999a2dd95SBruce Richardson 	for (i = 0, off = 0; !num || i != num; ++i, ++src, ++dst) {
84099a2dd95SBruce Richardson 		/**
84199a2dd95SBruce Richardson 		 * allow PMD private flow action
84299a2dd95SBruce Richardson 		 */
84399a2dd95SBruce Richardson 		if (((int)src->type >= 0) &&
84499a2dd95SBruce Richardson 		    ((size_t)src->type >= RTE_DIM(rte_flow_desc_action) ||
84599a2dd95SBruce Richardson 		    !rte_flow_desc_action[src->type].name))
84699a2dd95SBruce Richardson 			return rte_flow_error_set
84799a2dd95SBruce Richardson 				(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
84899a2dd95SBruce Richardson 				 src, "cannot convert unknown action type");
84999a2dd95SBruce Richardson 		if (size >= off + sizeof(*dst))
85099a2dd95SBruce Richardson 			*dst = (struct rte_flow_action){
85199a2dd95SBruce Richardson 				.type = src->type,
85299a2dd95SBruce Richardson 			};
85399a2dd95SBruce Richardson 		off += sizeof(*dst);
85499a2dd95SBruce Richardson 		if (!src->type)
85599a2dd95SBruce Richardson 			num = i + 1;
85699a2dd95SBruce Richardson 	}
85799a2dd95SBruce Richardson 	num = i;
85899a2dd95SBruce Richardson 	src -= num;
85999a2dd95SBruce Richardson 	dst -= num;
86099a2dd95SBruce Richardson 	do {
86199a2dd95SBruce Richardson 		if (src->conf) {
86299a2dd95SBruce Richardson 			off = RTE_ALIGN_CEIL(off, sizeof(double));
86399a2dd95SBruce Richardson 			ret = rte_flow_conv_action_conf
86499a2dd95SBruce Richardson 				((void *)(data + off),
86599a2dd95SBruce Richardson 				 size > off ? size - off : 0, src);
86699a2dd95SBruce Richardson 			if (size && size >= off + ret)
86799a2dd95SBruce Richardson 				dst->conf = (void *)(data + off);
86899a2dd95SBruce Richardson 			off += ret;
86999a2dd95SBruce Richardson 		}
87099a2dd95SBruce Richardson 		++src;
87199a2dd95SBruce Richardson 		++dst;
87299a2dd95SBruce Richardson 	} while (--num);
87399a2dd95SBruce Richardson 	return off;
87499a2dd95SBruce Richardson }
87599a2dd95SBruce Richardson 
87699a2dd95SBruce Richardson /**
87799a2dd95SBruce Richardson  * Copy flow rule components.
87899a2dd95SBruce Richardson  *
87999a2dd95SBruce Richardson  * This comprises the flow rule descriptor itself, attributes, pattern and
88099a2dd95SBruce Richardson  * actions list. NULL components in @p src are skipped.
88199a2dd95SBruce Richardson  *
88299a2dd95SBruce Richardson  * @param[out] dst
88399a2dd95SBruce Richardson  *   Destination buffer. Can be NULL if @p size is zero.
88499a2dd95SBruce Richardson  * @param size
88599a2dd95SBruce Richardson  *   Size of @p dst in bytes.
88699a2dd95SBruce Richardson  * @param[in] src
88799a2dd95SBruce Richardson  *   Source flow rule descriptor.
88899a2dd95SBruce Richardson  * @param[out] error
88999a2dd95SBruce Richardson  *   Perform verbose error reporting if not NULL.
89099a2dd95SBruce Richardson  *
89199a2dd95SBruce Richardson  * @return
89299a2dd95SBruce Richardson  *   A positive value representing the number of bytes needed to store all
89399a2dd95SBruce Richardson  *   components including the descriptor regardless of @p size on success
89499a2dd95SBruce Richardson  *   (@p buf contents are truncated to @p size if not large enough), a
89599a2dd95SBruce Richardson  *   negative errno value otherwise and rte_errno is set.
89699a2dd95SBruce Richardson  */
89799a2dd95SBruce Richardson static int
rte_flow_conv_rule(struct rte_flow_conv_rule * dst,const size_t size,const struct rte_flow_conv_rule * src,struct rte_flow_error * error)89899a2dd95SBruce Richardson rte_flow_conv_rule(struct rte_flow_conv_rule *dst,
89999a2dd95SBruce Richardson 		   const size_t size,
90099a2dd95SBruce Richardson 		   const struct rte_flow_conv_rule *src,
90199a2dd95SBruce Richardson 		   struct rte_flow_error *error)
90299a2dd95SBruce Richardson {
90399a2dd95SBruce Richardson 	size_t off;
90499a2dd95SBruce Richardson 	int ret;
90599a2dd95SBruce Richardson 
90699a2dd95SBruce Richardson 	rte_memcpy(dst,
90799a2dd95SBruce Richardson 		   (&(struct rte_flow_conv_rule){
90899a2dd95SBruce Richardson 			.attr = NULL,
90999a2dd95SBruce Richardson 			.pattern = NULL,
91099a2dd95SBruce Richardson 			.actions = NULL,
91199a2dd95SBruce Richardson 		   }),
91299a2dd95SBruce Richardson 		   size > sizeof(*dst) ? sizeof(*dst) : size);
91399a2dd95SBruce Richardson 	off = sizeof(*dst);
91499a2dd95SBruce Richardson 	if (src->attr_ro) {
91599a2dd95SBruce Richardson 		off = RTE_ALIGN_CEIL(off, sizeof(double));
91699a2dd95SBruce Richardson 		if (size && size >= off + sizeof(*dst->attr))
91799a2dd95SBruce Richardson 			dst->attr = rte_memcpy
91899a2dd95SBruce Richardson 				((void *)((uintptr_t)dst + off),
91999a2dd95SBruce Richardson 				 src->attr_ro, sizeof(*dst->attr));
92099a2dd95SBruce Richardson 		off += sizeof(*dst->attr);
92199a2dd95SBruce Richardson 	}
92299a2dd95SBruce Richardson 	if (src->pattern_ro) {
92399a2dd95SBruce Richardson 		off = RTE_ALIGN_CEIL(off, sizeof(double));
92499a2dd95SBruce Richardson 		ret = rte_flow_conv_pattern((void *)((uintptr_t)dst + off),
92599a2dd95SBruce Richardson 					    size > off ? size - off : 0,
92699a2dd95SBruce Richardson 					    src->pattern_ro, 0, error);
92799a2dd95SBruce Richardson 		if (ret < 0)
92899a2dd95SBruce Richardson 			return ret;
92999a2dd95SBruce Richardson 		if (size && size >= off + (size_t)ret)
93099a2dd95SBruce Richardson 			dst->pattern = (void *)((uintptr_t)dst + off);
93199a2dd95SBruce Richardson 		off += ret;
93299a2dd95SBruce Richardson 	}
93399a2dd95SBruce Richardson 	if (src->actions_ro) {
93499a2dd95SBruce Richardson 		off = RTE_ALIGN_CEIL(off, sizeof(double));
93599a2dd95SBruce Richardson 		ret = rte_flow_conv_actions((void *)((uintptr_t)dst + off),
93699a2dd95SBruce Richardson 					    size > off ? size - off : 0,
93799a2dd95SBruce Richardson 					    src->actions_ro, 0, error);
93899a2dd95SBruce Richardson 		if (ret < 0)
93999a2dd95SBruce Richardson 			return ret;
94099a2dd95SBruce Richardson 		if (size >= off + (size_t)ret)
94199a2dd95SBruce Richardson 			dst->actions = (void *)((uintptr_t)dst + off);
94299a2dd95SBruce Richardson 		off += ret;
94399a2dd95SBruce Richardson 	}
94499a2dd95SBruce Richardson 	return off;
94599a2dd95SBruce Richardson }
94699a2dd95SBruce Richardson 
94799a2dd95SBruce Richardson /**
94899a2dd95SBruce Richardson  * Retrieve the name of a pattern item/action type.
94999a2dd95SBruce Richardson  *
95099a2dd95SBruce Richardson  * @param is_action
95199a2dd95SBruce Richardson  *   Nonzero when @p src represents an action type instead of a pattern item
95299a2dd95SBruce Richardson  *   type.
95399a2dd95SBruce Richardson  * @param is_ptr
95499a2dd95SBruce Richardson  *   Nonzero to write string address instead of contents into @p dst.
95599a2dd95SBruce Richardson  * @param[out] dst
95699a2dd95SBruce Richardson  *   Destination buffer. Can be NULL if @p size is zero.
95799a2dd95SBruce Richardson  * @param size
95899a2dd95SBruce Richardson  *   Size of @p dst in bytes.
95999a2dd95SBruce Richardson  * @param[in] src
96099a2dd95SBruce Richardson  *   Depending on @p is_action, source pattern item or action type cast as a
96199a2dd95SBruce Richardson  *   pointer.
96299a2dd95SBruce Richardson  * @param[out] error
96399a2dd95SBruce Richardson  *   Perform verbose error reporting if not NULL.
96499a2dd95SBruce Richardson  *
96599a2dd95SBruce Richardson  * @return
96699a2dd95SBruce Richardson  *   A positive value representing the number of bytes needed to store the
96799a2dd95SBruce Richardson  *   name or its address regardless of @p size on success (@p buf contents
96899a2dd95SBruce Richardson  *   are truncated to @p size if not large enough), a negative errno value
96999a2dd95SBruce Richardson  *   otherwise and rte_errno is set.
97099a2dd95SBruce Richardson  */
97199a2dd95SBruce Richardson static int
rte_flow_conv_name(int is_action,int is_ptr,char * dst,const size_t size,const void * src,struct rte_flow_error * error)97299a2dd95SBruce Richardson rte_flow_conv_name(int is_action,
97399a2dd95SBruce Richardson 		   int is_ptr,
97499a2dd95SBruce Richardson 		   char *dst,
97599a2dd95SBruce Richardson 		   const size_t size,
97699a2dd95SBruce Richardson 		   const void *src,
97799a2dd95SBruce Richardson 		   struct rte_flow_error *error)
97899a2dd95SBruce Richardson {
97999a2dd95SBruce Richardson 	struct desc_info {
98099a2dd95SBruce Richardson 		const struct rte_flow_desc_data *data;
98199a2dd95SBruce Richardson 		size_t num;
98299a2dd95SBruce Richardson 	};
98399a2dd95SBruce Richardson 	static const struct desc_info info_rep[2] = {
98499a2dd95SBruce Richardson 		{ rte_flow_desc_item, RTE_DIM(rte_flow_desc_item), },
98599a2dd95SBruce Richardson 		{ rte_flow_desc_action, RTE_DIM(rte_flow_desc_action), },
98699a2dd95SBruce Richardson 	};
98799a2dd95SBruce Richardson 	const struct desc_info *const info = &info_rep[!!is_action];
98899a2dd95SBruce Richardson 	unsigned int type = (uintptr_t)src;
98999a2dd95SBruce Richardson 
99099a2dd95SBruce Richardson 	if (type >= info->num)
99199a2dd95SBruce Richardson 		return rte_flow_error_set
99299a2dd95SBruce Richardson 			(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
99399a2dd95SBruce Richardson 			 "unknown object type to retrieve the name of");
99499a2dd95SBruce Richardson 	if (!is_ptr)
99599a2dd95SBruce Richardson 		return strlcpy(dst, info->data[type].name, size);
99699a2dd95SBruce Richardson 	if (size >= sizeof(const char **))
99799a2dd95SBruce Richardson 		*((const char **)dst) = info->data[type].name;
99899a2dd95SBruce Richardson 	return sizeof(const char **);
99999a2dd95SBruce Richardson }
100099a2dd95SBruce Richardson 
100199a2dd95SBruce Richardson /** Helper function to convert flow API objects. */
100299a2dd95SBruce Richardson int
rte_flow_conv(enum rte_flow_conv_op op,void * dst,size_t size,const void * src,struct rte_flow_error * error)100399a2dd95SBruce Richardson rte_flow_conv(enum rte_flow_conv_op op,
100499a2dd95SBruce Richardson 	      void *dst,
100599a2dd95SBruce Richardson 	      size_t size,
100699a2dd95SBruce Richardson 	      const void *src,
100799a2dd95SBruce Richardson 	      struct rte_flow_error *error)
100899a2dd95SBruce Richardson {
100999a2dd95SBruce Richardson 	switch (op) {
101099a2dd95SBruce Richardson 		const struct rte_flow_attr *attr;
101199a2dd95SBruce Richardson 
101299a2dd95SBruce Richardson 	case RTE_FLOW_CONV_OP_NONE:
101399a2dd95SBruce Richardson 		return 0;
101499a2dd95SBruce Richardson 	case RTE_FLOW_CONV_OP_ATTR:
101599a2dd95SBruce Richardson 		attr = src;
101699a2dd95SBruce Richardson 		if (size > sizeof(*attr))
101799a2dd95SBruce Richardson 			size = sizeof(*attr);
101899a2dd95SBruce Richardson 		rte_memcpy(dst, attr, size);
101999a2dd95SBruce Richardson 		return sizeof(*attr);
102099a2dd95SBruce Richardson 	case RTE_FLOW_CONV_OP_ITEM:
102199a2dd95SBruce Richardson 		return rte_flow_conv_pattern(dst, size, src, 1, error);
102299a2dd95SBruce Richardson 	case RTE_FLOW_CONV_OP_ACTION:
102399a2dd95SBruce Richardson 		return rte_flow_conv_actions(dst, size, src, 1, error);
102499a2dd95SBruce Richardson 	case RTE_FLOW_CONV_OP_PATTERN:
102599a2dd95SBruce Richardson 		return rte_flow_conv_pattern(dst, size, src, 0, error);
102699a2dd95SBruce Richardson 	case RTE_FLOW_CONV_OP_ACTIONS:
102799a2dd95SBruce Richardson 		return rte_flow_conv_actions(dst, size, src, 0, error);
102899a2dd95SBruce Richardson 	case RTE_FLOW_CONV_OP_RULE:
102999a2dd95SBruce Richardson 		return rte_flow_conv_rule(dst, size, src, error);
103099a2dd95SBruce Richardson 	case RTE_FLOW_CONV_OP_ITEM_NAME:
103199a2dd95SBruce Richardson 		return rte_flow_conv_name(0, 0, dst, size, src, error);
103299a2dd95SBruce Richardson 	case RTE_FLOW_CONV_OP_ACTION_NAME:
103399a2dd95SBruce Richardson 		return rte_flow_conv_name(1, 0, dst, size, src, error);
103499a2dd95SBruce Richardson 	case RTE_FLOW_CONV_OP_ITEM_NAME_PTR:
103599a2dd95SBruce Richardson 		return rte_flow_conv_name(0, 1, dst, size, src, error);
103699a2dd95SBruce Richardson 	case RTE_FLOW_CONV_OP_ACTION_NAME_PTR:
103799a2dd95SBruce Richardson 		return rte_flow_conv_name(1, 1, dst, size, src, error);
103899a2dd95SBruce Richardson 	}
103999a2dd95SBruce Richardson 	return rte_flow_error_set
104099a2dd95SBruce Richardson 		(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
104199a2dd95SBruce Richardson 		 "unknown object conversion operation");
104299a2dd95SBruce Richardson }
104399a2dd95SBruce Richardson 
104499a2dd95SBruce Richardson /** Store a full rte_flow description. */
104599a2dd95SBruce Richardson size_t
rte_flow_copy(struct rte_flow_desc * desc,size_t len,const struct rte_flow_attr * attr,const struct rte_flow_item * items,const struct rte_flow_action * actions)104699a2dd95SBruce Richardson rte_flow_copy(struct rte_flow_desc *desc, size_t len,
104799a2dd95SBruce Richardson 	      const struct rte_flow_attr *attr,
104899a2dd95SBruce Richardson 	      const struct rte_flow_item *items,
104999a2dd95SBruce Richardson 	      const struct rte_flow_action *actions)
105099a2dd95SBruce Richardson {
105199a2dd95SBruce Richardson 	/*
105299a2dd95SBruce Richardson 	 * Overlap struct rte_flow_conv with struct rte_flow_desc in order
105399a2dd95SBruce Richardson 	 * to convert the former to the latter without wasting space.
105499a2dd95SBruce Richardson 	 */
105599a2dd95SBruce Richardson 	struct rte_flow_conv_rule *dst =
105699a2dd95SBruce Richardson 		len ?
105799a2dd95SBruce Richardson 		(void *)((uintptr_t)desc +
105899a2dd95SBruce Richardson 			 (offsetof(struct rte_flow_desc, actions) -
105999a2dd95SBruce Richardson 			  offsetof(struct rte_flow_conv_rule, actions))) :
106099a2dd95SBruce Richardson 		NULL;
106199a2dd95SBruce Richardson 	size_t dst_size =
106299a2dd95SBruce Richardson 		len > sizeof(*desc) - sizeof(*dst) ?
106399a2dd95SBruce Richardson 		len - (sizeof(*desc) - sizeof(*dst)) :
106499a2dd95SBruce Richardson 		0;
106599a2dd95SBruce Richardson 	struct rte_flow_conv_rule src = {
106699a2dd95SBruce Richardson 		.attr_ro = NULL,
106799a2dd95SBruce Richardson 		.pattern_ro = items,
106899a2dd95SBruce Richardson 		.actions_ro = actions,
106999a2dd95SBruce Richardson 	};
107099a2dd95SBruce Richardson 	int ret;
107199a2dd95SBruce Richardson 
107299a2dd95SBruce Richardson 	RTE_BUILD_BUG_ON(sizeof(struct rte_flow_desc) <
107399a2dd95SBruce Richardson 			 sizeof(struct rte_flow_conv_rule));
107499a2dd95SBruce Richardson 	if (dst_size &&
107599a2dd95SBruce Richardson 	    (&dst->pattern != &desc->items ||
107699a2dd95SBruce Richardson 	     &dst->actions != &desc->actions ||
107799a2dd95SBruce Richardson 	     (uintptr_t)(dst + 1) != (uintptr_t)(desc + 1))) {
107899a2dd95SBruce Richardson 		rte_errno = EINVAL;
107999a2dd95SBruce Richardson 		return 0;
108099a2dd95SBruce Richardson 	}
108199a2dd95SBruce Richardson 	ret = rte_flow_conv(RTE_FLOW_CONV_OP_RULE, dst, dst_size, &src, NULL);
108299a2dd95SBruce Richardson 	if (ret < 0)
108399a2dd95SBruce Richardson 		return 0;
108499a2dd95SBruce Richardson 	ret += sizeof(*desc) - sizeof(*dst);
108599a2dd95SBruce Richardson 	rte_memcpy(desc,
108699a2dd95SBruce Richardson 		   (&(struct rte_flow_desc){
108799a2dd95SBruce Richardson 			.size = ret,
108899a2dd95SBruce Richardson 			.attr = *attr,
108999a2dd95SBruce Richardson 			.items = dst_size ? dst->pattern : NULL,
109099a2dd95SBruce Richardson 			.actions = dst_size ? dst->actions : NULL,
109199a2dd95SBruce Richardson 		   }),
109299a2dd95SBruce Richardson 		   len > sizeof(*desc) ? sizeof(*desc) : len);
109399a2dd95SBruce Richardson 	return ret;
109499a2dd95SBruce Richardson }
109599a2dd95SBruce Richardson 
109699a2dd95SBruce Richardson int
rte_flow_dev_dump(uint16_t port_id,struct rte_flow * flow,FILE * file,struct rte_flow_error * error)109799a2dd95SBruce Richardson rte_flow_dev_dump(uint16_t port_id, struct rte_flow *flow,
109899a2dd95SBruce Richardson 			FILE *file, struct rte_flow_error *error)
109999a2dd95SBruce Richardson {
110099a2dd95SBruce Richardson 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
110199a2dd95SBruce Richardson 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
110299a2dd95SBruce Richardson 	int ret;
110399a2dd95SBruce Richardson 
110499a2dd95SBruce Richardson 	if (unlikely(!ops))
110599a2dd95SBruce Richardson 		return -rte_errno;
110699a2dd95SBruce Richardson 	if (likely(!!ops->dev_dump)) {
110799a2dd95SBruce Richardson 		fts_enter(dev);
110899a2dd95SBruce Richardson 		ret = ops->dev_dump(dev, flow, file, error);
110999a2dd95SBruce Richardson 		fts_exit(dev);
111099a2dd95SBruce Richardson 		return flow_err(port_id, ret, error);
111199a2dd95SBruce Richardson 	}
111299a2dd95SBruce Richardson 	return rte_flow_error_set(error, ENOSYS,
111399a2dd95SBruce Richardson 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
111499a2dd95SBruce Richardson 				  NULL, rte_strerror(ENOSYS));
111599a2dd95SBruce Richardson }
111699a2dd95SBruce Richardson 
111799a2dd95SBruce Richardson int
rte_flow_get_aged_flows(uint16_t port_id,void ** contexts,uint32_t nb_contexts,struct rte_flow_error * error)111899a2dd95SBruce Richardson rte_flow_get_aged_flows(uint16_t port_id, void **contexts,
111999a2dd95SBruce Richardson 		    uint32_t nb_contexts, struct rte_flow_error *error)
112099a2dd95SBruce Richardson {
112199a2dd95SBruce Richardson 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
112299a2dd95SBruce Richardson 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
112399a2dd95SBruce Richardson 	int ret;
112499a2dd95SBruce Richardson 
112599a2dd95SBruce Richardson 	if (unlikely(!ops))
112699a2dd95SBruce Richardson 		return -rte_errno;
112799a2dd95SBruce Richardson 	if (likely(!!ops->get_aged_flows)) {
112899a2dd95SBruce Richardson 		fts_enter(dev);
112999a2dd95SBruce Richardson 		ret = ops->get_aged_flows(dev, contexts, nb_contexts, error);
113099a2dd95SBruce Richardson 		fts_exit(dev);
113199a2dd95SBruce Richardson 		return flow_err(port_id, ret, error);
113299a2dd95SBruce Richardson 	}
113399a2dd95SBruce Richardson 	return rte_flow_error_set(error, ENOTSUP,
113499a2dd95SBruce Richardson 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
113599a2dd95SBruce Richardson 				  NULL, rte_strerror(ENOTSUP));
113699a2dd95SBruce Richardson }
113799a2dd95SBruce Richardson 
11384b61b877SBing Zhao struct rte_flow_action_handle *
rte_flow_action_handle_create(uint16_t port_id,const struct rte_flow_indir_action_conf * conf,const struct rte_flow_action * action,struct rte_flow_error * error)11394b61b877SBing Zhao rte_flow_action_handle_create(uint16_t port_id,
11404b61b877SBing Zhao 			      const struct rte_flow_indir_action_conf *conf,
114199a2dd95SBruce Richardson 			      const struct rte_flow_action *action,
114299a2dd95SBruce Richardson 			      struct rte_flow_error *error)
114399a2dd95SBruce Richardson {
11444b61b877SBing Zhao 	struct rte_flow_action_handle *handle;
114599a2dd95SBruce Richardson 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
114699a2dd95SBruce Richardson 
114799a2dd95SBruce Richardson 	if (unlikely(!ops))
114899a2dd95SBruce Richardson 		return NULL;
11494b61b877SBing Zhao 	if (unlikely(!ops->action_handle_create)) {
115099a2dd95SBruce Richardson 		rte_flow_error_set(error, ENOSYS,
115199a2dd95SBruce Richardson 				   RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
115299a2dd95SBruce Richardson 				   rte_strerror(ENOSYS));
115399a2dd95SBruce Richardson 		return NULL;
115499a2dd95SBruce Richardson 	}
11554b61b877SBing Zhao 	handle = ops->action_handle_create(&rte_eth_devices[port_id],
115699a2dd95SBruce Richardson 					   conf, action, error);
11574b61b877SBing Zhao 	if (handle == NULL)
115899a2dd95SBruce Richardson 		flow_err(port_id, -rte_errno, error);
11594b61b877SBing Zhao 	return handle;
116099a2dd95SBruce Richardson }
116199a2dd95SBruce Richardson 
116299a2dd95SBruce Richardson int
rte_flow_action_handle_destroy(uint16_t port_id,struct rte_flow_action_handle * handle,struct rte_flow_error * error)11634b61b877SBing Zhao rte_flow_action_handle_destroy(uint16_t port_id,
11644b61b877SBing Zhao 			       struct rte_flow_action_handle *handle,
116599a2dd95SBruce Richardson 			       struct rte_flow_error *error)
116699a2dd95SBruce Richardson {
116799a2dd95SBruce Richardson 	int ret;
116899a2dd95SBruce Richardson 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
116999a2dd95SBruce Richardson 
117099a2dd95SBruce Richardson 	if (unlikely(!ops))
117199a2dd95SBruce Richardson 		return -rte_errno;
11724b61b877SBing Zhao 	if (unlikely(!ops->action_handle_destroy))
117399a2dd95SBruce Richardson 		return rte_flow_error_set(error, ENOSYS,
117499a2dd95SBruce Richardson 					  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
117599a2dd95SBruce Richardson 					  NULL, rte_strerror(ENOSYS));
11764b61b877SBing Zhao 	ret = ops->action_handle_destroy(&rte_eth_devices[port_id],
11774b61b877SBing Zhao 					 handle, error);
117899a2dd95SBruce Richardson 	return flow_err(port_id, ret, error);
117999a2dd95SBruce Richardson }
118099a2dd95SBruce Richardson 
118199a2dd95SBruce Richardson int
rte_flow_action_handle_update(uint16_t port_id,struct rte_flow_action_handle * handle,const void * update,struct rte_flow_error * error)11824b61b877SBing Zhao rte_flow_action_handle_update(uint16_t port_id,
11834b61b877SBing Zhao 			      struct rte_flow_action_handle *handle,
11844b61b877SBing Zhao 			      const void *update,
118599a2dd95SBruce Richardson 			      struct rte_flow_error *error)
118699a2dd95SBruce Richardson {
118799a2dd95SBruce Richardson 	int ret;
118899a2dd95SBruce Richardson 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
118999a2dd95SBruce Richardson 
119099a2dd95SBruce Richardson 	if (unlikely(!ops))
119199a2dd95SBruce Richardson 		return -rte_errno;
11924b61b877SBing Zhao 	if (unlikely(!ops->action_handle_update))
119399a2dd95SBruce Richardson 		return rte_flow_error_set(error, ENOSYS,
119499a2dd95SBruce Richardson 					  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
119599a2dd95SBruce Richardson 					  NULL, rte_strerror(ENOSYS));
11964b61b877SBing Zhao 	ret = ops->action_handle_update(&rte_eth_devices[port_id], handle,
119799a2dd95SBruce Richardson 					update, error);
119899a2dd95SBruce Richardson 	return flow_err(port_id, ret, error);
119999a2dd95SBruce Richardson }
120099a2dd95SBruce Richardson 
120199a2dd95SBruce Richardson int
rte_flow_action_handle_query(uint16_t port_id,const struct rte_flow_action_handle * handle,void * data,struct rte_flow_error * error)12024b61b877SBing Zhao rte_flow_action_handle_query(uint16_t port_id,
12034b61b877SBing Zhao 			     const struct rte_flow_action_handle *handle,
120499a2dd95SBruce Richardson 			     void *data,
120599a2dd95SBruce Richardson 			     struct rte_flow_error *error)
120699a2dd95SBruce Richardson {
120799a2dd95SBruce Richardson 	int ret;
120899a2dd95SBruce Richardson 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
120999a2dd95SBruce Richardson 
121099a2dd95SBruce Richardson 	if (unlikely(!ops))
121199a2dd95SBruce Richardson 		return -rte_errno;
12124b61b877SBing Zhao 	if (unlikely(!ops->action_handle_query))
121399a2dd95SBruce Richardson 		return rte_flow_error_set(error, ENOSYS,
121499a2dd95SBruce Richardson 					  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
121599a2dd95SBruce Richardson 					  NULL, rte_strerror(ENOSYS));
12164b61b877SBing Zhao 	ret = ops->action_handle_query(&rte_eth_devices[port_id], handle,
121799a2dd95SBruce Richardson 				       data, error);
121899a2dd95SBruce Richardson 	return flow_err(port_id, ret, error);
121999a2dd95SBruce Richardson }
122099a2dd95SBruce Richardson 
122199a2dd95SBruce Richardson int
rte_flow_tunnel_decap_set(uint16_t port_id,struct rte_flow_tunnel * tunnel,struct rte_flow_action ** actions,uint32_t * num_of_actions,struct rte_flow_error * error)122299a2dd95SBruce Richardson rte_flow_tunnel_decap_set(uint16_t port_id,
122399a2dd95SBruce Richardson 			  struct rte_flow_tunnel *tunnel,
122499a2dd95SBruce Richardson 			  struct rte_flow_action **actions,
122599a2dd95SBruce Richardson 			  uint32_t *num_of_actions,
122699a2dd95SBruce Richardson 			  struct rte_flow_error *error)
122799a2dd95SBruce Richardson {
122899a2dd95SBruce Richardson 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
122999a2dd95SBruce Richardson 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
123099a2dd95SBruce Richardson 
123199a2dd95SBruce Richardson 	if (unlikely(!ops))
123299a2dd95SBruce Richardson 		return -rte_errno;
123399a2dd95SBruce Richardson 	if (likely(!!ops->tunnel_decap_set)) {
123499a2dd95SBruce Richardson 		return flow_err(port_id,
123599a2dd95SBruce Richardson 				ops->tunnel_decap_set(dev, tunnel, actions,
123699a2dd95SBruce Richardson 						      num_of_actions, error),
123799a2dd95SBruce Richardson 				error);
123899a2dd95SBruce Richardson 	}
123999a2dd95SBruce Richardson 	return rte_flow_error_set(error, ENOTSUP,
124099a2dd95SBruce Richardson 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
124199a2dd95SBruce Richardson 				  NULL, rte_strerror(ENOTSUP));
124299a2dd95SBruce Richardson }
124399a2dd95SBruce Richardson 
124499a2dd95SBruce Richardson int
rte_flow_tunnel_match(uint16_t port_id,struct rte_flow_tunnel * tunnel,struct rte_flow_item ** items,uint32_t * num_of_items,struct rte_flow_error * error)124599a2dd95SBruce Richardson rte_flow_tunnel_match(uint16_t port_id,
124699a2dd95SBruce Richardson 		      struct rte_flow_tunnel *tunnel,
124799a2dd95SBruce Richardson 		      struct rte_flow_item **items,
124899a2dd95SBruce Richardson 		      uint32_t *num_of_items,
124999a2dd95SBruce Richardson 		      struct rte_flow_error *error)
125099a2dd95SBruce Richardson {
125199a2dd95SBruce Richardson 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
125299a2dd95SBruce Richardson 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
125399a2dd95SBruce Richardson 
125499a2dd95SBruce Richardson 	if (unlikely(!ops))
125599a2dd95SBruce Richardson 		return -rte_errno;
125699a2dd95SBruce Richardson 	if (likely(!!ops->tunnel_match)) {
125799a2dd95SBruce Richardson 		return flow_err(port_id,
125899a2dd95SBruce Richardson 				ops->tunnel_match(dev, tunnel, items,
125999a2dd95SBruce Richardson 						  num_of_items, error),
126099a2dd95SBruce Richardson 				error);
126199a2dd95SBruce Richardson 	}
126299a2dd95SBruce Richardson 	return rte_flow_error_set(error, ENOTSUP,
126399a2dd95SBruce Richardson 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
126499a2dd95SBruce Richardson 				  NULL, rte_strerror(ENOTSUP));
126599a2dd95SBruce Richardson }
126699a2dd95SBruce Richardson 
126799a2dd95SBruce Richardson int
rte_flow_get_restore_info(uint16_t port_id,struct rte_mbuf * m,struct rte_flow_restore_info * restore_info,struct rte_flow_error * error)126899a2dd95SBruce Richardson rte_flow_get_restore_info(uint16_t port_id,
126999a2dd95SBruce Richardson 			  struct rte_mbuf *m,
127099a2dd95SBruce Richardson 			  struct rte_flow_restore_info *restore_info,
127199a2dd95SBruce Richardson 			  struct rte_flow_error *error)
127299a2dd95SBruce Richardson {
127399a2dd95SBruce Richardson 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
127499a2dd95SBruce Richardson 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
127599a2dd95SBruce Richardson 
127699a2dd95SBruce Richardson 	if (unlikely(!ops))
127799a2dd95SBruce Richardson 		return -rte_errno;
127899a2dd95SBruce Richardson 	if (likely(!!ops->get_restore_info)) {
127999a2dd95SBruce Richardson 		return flow_err(port_id,
128099a2dd95SBruce Richardson 				ops->get_restore_info(dev, m, restore_info,
128199a2dd95SBruce Richardson 						      error),
128299a2dd95SBruce Richardson 				error);
128399a2dd95SBruce Richardson 	}
128499a2dd95SBruce Richardson 	return rte_flow_error_set(error, ENOTSUP,
128599a2dd95SBruce Richardson 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
128699a2dd95SBruce Richardson 				  NULL, rte_strerror(ENOTSUP));
128799a2dd95SBruce Richardson }
128899a2dd95SBruce Richardson 
128999a2dd95SBruce Richardson int
rte_flow_tunnel_action_decap_release(uint16_t port_id,struct rte_flow_action * actions,uint32_t num_of_actions,struct rte_flow_error * error)129099a2dd95SBruce Richardson rte_flow_tunnel_action_decap_release(uint16_t port_id,
129199a2dd95SBruce Richardson 				     struct rte_flow_action *actions,
129299a2dd95SBruce Richardson 				     uint32_t num_of_actions,
129399a2dd95SBruce Richardson 				     struct rte_flow_error *error)
129499a2dd95SBruce Richardson {
129599a2dd95SBruce Richardson 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
129699a2dd95SBruce Richardson 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
129799a2dd95SBruce Richardson 
129899a2dd95SBruce Richardson 	if (unlikely(!ops))
129999a2dd95SBruce Richardson 		return -rte_errno;
130099a2dd95SBruce Richardson 	if (likely(!!ops->tunnel_action_decap_release)) {
130199a2dd95SBruce Richardson 		return flow_err(port_id,
130299a2dd95SBruce Richardson 				ops->tunnel_action_decap_release(dev, actions,
130399a2dd95SBruce Richardson 								 num_of_actions,
130499a2dd95SBruce Richardson 								 error),
130599a2dd95SBruce Richardson 				error);
130699a2dd95SBruce Richardson 	}
130799a2dd95SBruce Richardson 	return rte_flow_error_set(error, ENOTSUP,
130899a2dd95SBruce Richardson 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
130999a2dd95SBruce Richardson 				  NULL, rte_strerror(ENOTSUP));
131099a2dd95SBruce Richardson }
131199a2dd95SBruce Richardson 
131299a2dd95SBruce Richardson int
rte_flow_tunnel_item_release(uint16_t port_id,struct rte_flow_item * items,uint32_t num_of_items,struct rte_flow_error * error)131399a2dd95SBruce Richardson rte_flow_tunnel_item_release(uint16_t port_id,
131499a2dd95SBruce Richardson 			     struct rte_flow_item *items,
131599a2dd95SBruce Richardson 			     uint32_t num_of_items,
131699a2dd95SBruce Richardson 			     struct rte_flow_error *error)
131799a2dd95SBruce Richardson {
131899a2dd95SBruce Richardson 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
131999a2dd95SBruce Richardson 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
132099a2dd95SBruce Richardson 
132199a2dd95SBruce Richardson 	if (unlikely(!ops))
132299a2dd95SBruce Richardson 		return -rte_errno;
132399a2dd95SBruce Richardson 	if (likely(!!ops->tunnel_item_release)) {
132499a2dd95SBruce Richardson 		return flow_err(port_id,
132599a2dd95SBruce Richardson 				ops->tunnel_item_release(dev, items,
132699a2dd95SBruce Richardson 							 num_of_items, error),
132799a2dd95SBruce Richardson 				error);
132899a2dd95SBruce Richardson 	}
132999a2dd95SBruce Richardson 	return rte_flow_error_set(error, ENOTSUP,
133099a2dd95SBruce Richardson 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
133199a2dd95SBruce Richardson 				  NULL, rte_strerror(ENOTSUP));
133299a2dd95SBruce Richardson }
13331179f05cSIvan Malov 
13341179f05cSIvan Malov int
rte_flow_pick_transfer_proxy(uint16_t port_id,uint16_t * proxy_port_id,struct rte_flow_error * error)13351179f05cSIvan Malov rte_flow_pick_transfer_proxy(uint16_t port_id, uint16_t *proxy_port_id,
13361179f05cSIvan Malov 			     struct rte_flow_error *error)
13371179f05cSIvan Malov {
13381179f05cSIvan Malov 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
13391179f05cSIvan Malov 	struct rte_eth_dev *dev;
13401179f05cSIvan Malov 
13411179f05cSIvan Malov 	if (unlikely(ops == NULL))
13421179f05cSIvan Malov 		return -rte_errno;
13431179f05cSIvan Malov 
13441179f05cSIvan Malov 	if (ops->pick_transfer_proxy == NULL) {
13451179f05cSIvan Malov 		*proxy_port_id = port_id;
13461179f05cSIvan Malov 		return 0;
13471179f05cSIvan Malov 	}
13481179f05cSIvan Malov 
13491179f05cSIvan Malov 	dev = &rte_eth_devices[port_id];
13501179f05cSIvan Malov 
13511179f05cSIvan Malov 	return flow_err(port_id,
13521179f05cSIvan Malov 			ops->pick_transfer_proxy(dev, proxy_port_id, error),
13531179f05cSIvan Malov 			error);
13541179f05cSIvan Malov }
1355dc4d860eSViacheslav Ovsiienko 
1356dc4d860eSViacheslav Ovsiienko struct rte_flow_item_flex_handle *
rte_flow_flex_item_create(uint16_t port_id,const struct rte_flow_item_flex_conf * conf,struct rte_flow_error * error)1357dc4d860eSViacheslav Ovsiienko rte_flow_flex_item_create(uint16_t port_id,
1358dc4d860eSViacheslav Ovsiienko 			  const struct rte_flow_item_flex_conf *conf,
1359dc4d860eSViacheslav Ovsiienko 			  struct rte_flow_error *error)
1360dc4d860eSViacheslav Ovsiienko {
1361dc4d860eSViacheslav Ovsiienko 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1362dc4d860eSViacheslav Ovsiienko 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1363dc4d860eSViacheslav Ovsiienko 	struct rte_flow_item_flex_handle *handle;
1364dc4d860eSViacheslav Ovsiienko 
1365dc4d860eSViacheslav Ovsiienko 	if (unlikely(!ops))
1366dc4d860eSViacheslav Ovsiienko 		return NULL;
1367dc4d860eSViacheslav Ovsiienko 	if (unlikely(!ops->flex_item_create)) {
1368dc4d860eSViacheslav Ovsiienko 		rte_flow_error_set(error, ENOTSUP,
1369dc4d860eSViacheslav Ovsiienko 				   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1370dc4d860eSViacheslav Ovsiienko 				   NULL, rte_strerror(ENOTSUP));
1371dc4d860eSViacheslav Ovsiienko 		return NULL;
1372dc4d860eSViacheslav Ovsiienko 	}
1373dc4d860eSViacheslav Ovsiienko 	handle = ops->flex_item_create(dev, conf, error);
1374dc4d860eSViacheslav Ovsiienko 	if (handle == NULL)
1375dc4d860eSViacheslav Ovsiienko 		flow_err(port_id, -rte_errno, error);
1376dc4d860eSViacheslav Ovsiienko 	return handle;
1377dc4d860eSViacheslav Ovsiienko }
1378dc4d860eSViacheslav Ovsiienko 
1379dc4d860eSViacheslav Ovsiienko int
rte_flow_flex_item_release(uint16_t port_id,const struct rte_flow_item_flex_handle * handle,struct rte_flow_error * error)1380dc4d860eSViacheslav Ovsiienko rte_flow_flex_item_release(uint16_t port_id,
1381dc4d860eSViacheslav Ovsiienko 			   const struct rte_flow_item_flex_handle *handle,
1382dc4d860eSViacheslav Ovsiienko 			   struct rte_flow_error *error)
1383dc4d860eSViacheslav Ovsiienko {
1384dc4d860eSViacheslav Ovsiienko 	int ret;
1385dc4d860eSViacheslav Ovsiienko 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1386dc4d860eSViacheslav Ovsiienko 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1387dc4d860eSViacheslav Ovsiienko 
1388dc4d860eSViacheslav Ovsiienko 	if (unlikely(!ops || !ops->flex_item_release))
1389dc4d860eSViacheslav Ovsiienko 		return rte_flow_error_set(error, ENOTSUP,
1390dc4d860eSViacheslav Ovsiienko 					  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1391dc4d860eSViacheslav Ovsiienko 					  NULL, rte_strerror(ENOTSUP));
1392dc4d860eSViacheslav Ovsiienko 	ret = ops->flex_item_release(dev, handle, error);
1393dc4d860eSViacheslav Ovsiienko 	return flow_err(port_id, ret, error);
1394dc4d860eSViacheslav Ovsiienko }
13954ff58b73SAlexander Kozyrev 
13964ff58b73SAlexander Kozyrev int
rte_flow_info_get(uint16_t port_id,struct rte_flow_port_info * port_info,struct rte_flow_queue_info * queue_info,struct rte_flow_error * error)13974ff58b73SAlexander Kozyrev rte_flow_info_get(uint16_t port_id,
13984ff58b73SAlexander Kozyrev 		  struct rte_flow_port_info *port_info,
1399197e820cSAlexander Kozyrev 		  struct rte_flow_queue_info *queue_info,
14004ff58b73SAlexander Kozyrev 		  struct rte_flow_error *error)
14014ff58b73SAlexander Kozyrev {
14024ff58b73SAlexander Kozyrev 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
14034ff58b73SAlexander Kozyrev 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
14044ff58b73SAlexander Kozyrev 
14054ff58b73SAlexander Kozyrev 	if (unlikely(!ops))
14064ff58b73SAlexander Kozyrev 		return -rte_errno;
14074ff58b73SAlexander Kozyrev 	if (dev->data->dev_configured == 0) {
14084ff58b73SAlexander Kozyrev 		RTE_FLOW_LOG(INFO,
14094ff58b73SAlexander Kozyrev 			"Device with port_id=%"PRIu16" is not configured.\n",
14104ff58b73SAlexander Kozyrev 			port_id);
14114ff58b73SAlexander Kozyrev 		return -EINVAL;
14124ff58b73SAlexander Kozyrev 	}
14134ff58b73SAlexander Kozyrev 	if (port_info == NULL) {
14144ff58b73SAlexander Kozyrev 		RTE_FLOW_LOG(ERR, "Port %"PRIu16" info is NULL.\n", port_id);
14154ff58b73SAlexander Kozyrev 		return -EINVAL;
14164ff58b73SAlexander Kozyrev 	}
14174ff58b73SAlexander Kozyrev 	if (likely(!!ops->info_get)) {
14184ff58b73SAlexander Kozyrev 		return flow_err(port_id,
1419197e820cSAlexander Kozyrev 				ops->info_get(dev, port_info, queue_info, error),
14204ff58b73SAlexander Kozyrev 				error);
14214ff58b73SAlexander Kozyrev 	}
14224ff58b73SAlexander Kozyrev 	return rte_flow_error_set(error, ENOTSUP,
14234ff58b73SAlexander Kozyrev 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14244ff58b73SAlexander Kozyrev 				  NULL, rte_strerror(ENOTSUP));
14254ff58b73SAlexander Kozyrev }
14264ff58b73SAlexander Kozyrev 
14274ff58b73SAlexander Kozyrev int
rte_flow_configure(uint16_t port_id,const struct rte_flow_port_attr * port_attr,uint16_t nb_queue,const struct rte_flow_queue_attr * queue_attr[],struct rte_flow_error * error)14284ff58b73SAlexander Kozyrev rte_flow_configure(uint16_t port_id,
14294ff58b73SAlexander Kozyrev 		   const struct rte_flow_port_attr *port_attr,
1430197e820cSAlexander Kozyrev 		   uint16_t nb_queue,
1431197e820cSAlexander Kozyrev 		   const struct rte_flow_queue_attr *queue_attr[],
14324ff58b73SAlexander Kozyrev 		   struct rte_flow_error *error)
14334ff58b73SAlexander Kozyrev {
14344ff58b73SAlexander Kozyrev 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
14354ff58b73SAlexander Kozyrev 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
14364ff58b73SAlexander Kozyrev 	int ret;
14374ff58b73SAlexander Kozyrev 
14384ff58b73SAlexander Kozyrev 	if (unlikely(!ops))
14394ff58b73SAlexander Kozyrev 		return -rte_errno;
14404ff58b73SAlexander Kozyrev 	if (dev->data->dev_configured == 0) {
14414ff58b73SAlexander Kozyrev 		RTE_FLOW_LOG(INFO,
14424ff58b73SAlexander Kozyrev 			"Device with port_id=%"PRIu16" is not configured.\n",
14434ff58b73SAlexander Kozyrev 			port_id);
14444ff58b73SAlexander Kozyrev 		return -EINVAL;
14454ff58b73SAlexander Kozyrev 	}
14464ff58b73SAlexander Kozyrev 	if (dev->data->dev_started != 0) {
14474ff58b73SAlexander Kozyrev 		RTE_FLOW_LOG(INFO,
14484ff58b73SAlexander Kozyrev 			"Device with port_id=%"PRIu16" already started.\n",
14494ff58b73SAlexander Kozyrev 			port_id);
14504ff58b73SAlexander Kozyrev 		return -EINVAL;
14514ff58b73SAlexander Kozyrev 	}
14524ff58b73SAlexander Kozyrev 	if (port_attr == NULL) {
14534ff58b73SAlexander Kozyrev 		RTE_FLOW_LOG(ERR, "Port %"PRIu16" info is NULL.\n", port_id);
14544ff58b73SAlexander Kozyrev 		return -EINVAL;
14554ff58b73SAlexander Kozyrev 	}
1456197e820cSAlexander Kozyrev 	if (queue_attr == NULL) {
1457197e820cSAlexander Kozyrev 		RTE_FLOW_LOG(ERR, "Port %"PRIu16" queue info is NULL.\n", port_id);
1458197e820cSAlexander Kozyrev 		return -EINVAL;
1459197e820cSAlexander Kozyrev 	}
14604ff58b73SAlexander Kozyrev 	if (likely(!!ops->configure)) {
1461197e820cSAlexander Kozyrev 		ret = ops->configure(dev, port_attr, nb_queue, queue_attr, error);
14624ff58b73SAlexander Kozyrev 		if (ret == 0)
14634ff58b73SAlexander Kozyrev 			dev->data->flow_configured = 1;
14644ff58b73SAlexander Kozyrev 		return flow_err(port_id, ret, error);
14654ff58b73SAlexander Kozyrev 	}
14664ff58b73SAlexander Kozyrev 	return rte_flow_error_set(error, ENOTSUP,
14674ff58b73SAlexander Kozyrev 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14684ff58b73SAlexander Kozyrev 				  NULL, rte_strerror(ENOTSUP));
14694ff58b73SAlexander Kozyrev }
1470f076bcfbSAlexander Kozyrev 
1471f076bcfbSAlexander Kozyrev struct rte_flow_pattern_template *
rte_flow_pattern_template_create(uint16_t port_id,const struct rte_flow_pattern_template_attr * template_attr,const struct rte_flow_item pattern[],struct rte_flow_error * error)1472f076bcfbSAlexander Kozyrev rte_flow_pattern_template_create(uint16_t port_id,
1473f076bcfbSAlexander Kozyrev 		const struct rte_flow_pattern_template_attr *template_attr,
1474f076bcfbSAlexander Kozyrev 		const struct rte_flow_item pattern[],
1475f076bcfbSAlexander Kozyrev 		struct rte_flow_error *error)
1476f076bcfbSAlexander Kozyrev {
1477f076bcfbSAlexander Kozyrev 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1478f076bcfbSAlexander Kozyrev 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1479f076bcfbSAlexander Kozyrev 	struct rte_flow_pattern_template *template;
1480f076bcfbSAlexander Kozyrev 
1481f076bcfbSAlexander Kozyrev 	if (unlikely(!ops))
1482f076bcfbSAlexander Kozyrev 		return NULL;
1483f076bcfbSAlexander Kozyrev 	if (dev->data->flow_configured == 0) {
1484f076bcfbSAlexander Kozyrev 		RTE_FLOW_LOG(INFO,
1485f076bcfbSAlexander Kozyrev 			"Flow engine on port_id=%"PRIu16" is not configured.\n",
1486f076bcfbSAlexander Kozyrev 			port_id);
1487f076bcfbSAlexander Kozyrev 		rte_flow_error_set(error, EINVAL,
1488f076bcfbSAlexander Kozyrev 				RTE_FLOW_ERROR_TYPE_STATE,
1489f076bcfbSAlexander Kozyrev 				NULL, rte_strerror(EINVAL));
1490f076bcfbSAlexander Kozyrev 		return NULL;
1491f076bcfbSAlexander Kozyrev 	}
1492f076bcfbSAlexander Kozyrev 	if (template_attr == NULL) {
1493f076bcfbSAlexander Kozyrev 		RTE_FLOW_LOG(ERR,
1494f076bcfbSAlexander Kozyrev 			     "Port %"PRIu16" template attr is NULL.\n",
1495f076bcfbSAlexander Kozyrev 			     port_id);
1496f076bcfbSAlexander Kozyrev 		rte_flow_error_set(error, EINVAL,
1497f076bcfbSAlexander Kozyrev 				   RTE_FLOW_ERROR_TYPE_ATTR,
1498f076bcfbSAlexander Kozyrev 				   NULL, rte_strerror(EINVAL));
1499f076bcfbSAlexander Kozyrev 		return NULL;
1500f076bcfbSAlexander Kozyrev 	}
1501f076bcfbSAlexander Kozyrev 	if (pattern == NULL) {
1502f076bcfbSAlexander Kozyrev 		RTE_FLOW_LOG(ERR,
1503f076bcfbSAlexander Kozyrev 			     "Port %"PRIu16" pattern is NULL.\n",
1504f076bcfbSAlexander Kozyrev 			     port_id);
1505f076bcfbSAlexander Kozyrev 		rte_flow_error_set(error, EINVAL,
1506f076bcfbSAlexander Kozyrev 				   RTE_FLOW_ERROR_TYPE_ATTR,
1507f076bcfbSAlexander Kozyrev 				   NULL, rte_strerror(EINVAL));
1508f076bcfbSAlexander Kozyrev 		return NULL;
1509f076bcfbSAlexander Kozyrev 	}
1510f076bcfbSAlexander Kozyrev 	if (likely(!!ops->pattern_template_create)) {
1511f076bcfbSAlexander Kozyrev 		template = ops->pattern_template_create(dev, template_attr,
1512f076bcfbSAlexander Kozyrev 							pattern, error);
1513f076bcfbSAlexander Kozyrev 		if (template == NULL)
1514f076bcfbSAlexander Kozyrev 			flow_err(port_id, -rte_errno, error);
1515f076bcfbSAlexander Kozyrev 		return template;
1516f076bcfbSAlexander Kozyrev 	}
1517f076bcfbSAlexander Kozyrev 	rte_flow_error_set(error, ENOTSUP,
1518f076bcfbSAlexander Kozyrev 			   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1519f076bcfbSAlexander Kozyrev 			   NULL, rte_strerror(ENOTSUP));
1520f076bcfbSAlexander Kozyrev 	return NULL;
1521f076bcfbSAlexander Kozyrev }
1522f076bcfbSAlexander Kozyrev 
1523f076bcfbSAlexander Kozyrev int
rte_flow_pattern_template_destroy(uint16_t port_id,struct rte_flow_pattern_template * pattern_template,struct rte_flow_error * error)1524f076bcfbSAlexander Kozyrev rte_flow_pattern_template_destroy(uint16_t port_id,
1525f076bcfbSAlexander Kozyrev 		struct rte_flow_pattern_template *pattern_template,
1526f076bcfbSAlexander Kozyrev 		struct rte_flow_error *error)
1527f076bcfbSAlexander Kozyrev {
1528f076bcfbSAlexander Kozyrev 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1529f076bcfbSAlexander Kozyrev 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1530f076bcfbSAlexander Kozyrev 
1531f076bcfbSAlexander Kozyrev 	if (unlikely(!ops))
1532f076bcfbSAlexander Kozyrev 		return -rte_errno;
1533f076bcfbSAlexander Kozyrev 	if (unlikely(pattern_template == NULL))
1534f076bcfbSAlexander Kozyrev 		return 0;
1535f076bcfbSAlexander Kozyrev 	if (likely(!!ops->pattern_template_destroy)) {
1536f076bcfbSAlexander Kozyrev 		return flow_err(port_id,
1537f076bcfbSAlexander Kozyrev 				ops->pattern_template_destroy(dev,
1538f076bcfbSAlexander Kozyrev 							      pattern_template,
1539f076bcfbSAlexander Kozyrev 							      error),
1540f076bcfbSAlexander Kozyrev 				error);
1541f076bcfbSAlexander Kozyrev 	}
1542f076bcfbSAlexander Kozyrev 	return rte_flow_error_set(error, ENOTSUP,
1543f076bcfbSAlexander Kozyrev 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1544f076bcfbSAlexander Kozyrev 				  NULL, rte_strerror(ENOTSUP));
1545f076bcfbSAlexander Kozyrev }
1546f076bcfbSAlexander Kozyrev 
1547f076bcfbSAlexander Kozyrev struct rte_flow_actions_template *
rte_flow_actions_template_create(uint16_t port_id,const struct rte_flow_actions_template_attr * template_attr,const struct rte_flow_action actions[],const struct rte_flow_action masks[],struct rte_flow_error * error)1548f076bcfbSAlexander Kozyrev rte_flow_actions_template_create(uint16_t port_id,
1549f076bcfbSAlexander Kozyrev 			const struct rte_flow_actions_template_attr *template_attr,
1550f076bcfbSAlexander Kozyrev 			const struct rte_flow_action actions[],
1551f076bcfbSAlexander Kozyrev 			const struct rte_flow_action masks[],
1552f076bcfbSAlexander Kozyrev 			struct rte_flow_error *error)
1553f076bcfbSAlexander Kozyrev {
1554f076bcfbSAlexander Kozyrev 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1555f076bcfbSAlexander Kozyrev 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1556f076bcfbSAlexander Kozyrev 	struct rte_flow_actions_template *template;
1557f076bcfbSAlexander Kozyrev 
1558f076bcfbSAlexander Kozyrev 	if (unlikely(!ops))
1559f076bcfbSAlexander Kozyrev 		return NULL;
1560f076bcfbSAlexander Kozyrev 	if (dev->data->flow_configured == 0) {
1561f076bcfbSAlexander Kozyrev 		RTE_FLOW_LOG(INFO,
1562f076bcfbSAlexander Kozyrev 			"Flow engine on port_id=%"PRIu16" is not configured.\n",
1563f076bcfbSAlexander Kozyrev 			port_id);
1564f076bcfbSAlexander Kozyrev 		rte_flow_error_set(error, EINVAL,
1565f076bcfbSAlexander Kozyrev 				   RTE_FLOW_ERROR_TYPE_STATE,
1566f076bcfbSAlexander Kozyrev 				   NULL, rte_strerror(EINVAL));
1567f076bcfbSAlexander Kozyrev 		return NULL;
1568f076bcfbSAlexander Kozyrev 	}
1569f076bcfbSAlexander Kozyrev 	if (template_attr == NULL) {
1570f076bcfbSAlexander Kozyrev 		RTE_FLOW_LOG(ERR,
1571f076bcfbSAlexander Kozyrev 			     "Port %"PRIu16" template attr is NULL.\n",
1572f076bcfbSAlexander Kozyrev 			     port_id);
1573f076bcfbSAlexander Kozyrev 		rte_flow_error_set(error, EINVAL,
1574f076bcfbSAlexander Kozyrev 				   RTE_FLOW_ERROR_TYPE_ATTR,
1575f076bcfbSAlexander Kozyrev 				   NULL, rte_strerror(EINVAL));
1576f076bcfbSAlexander Kozyrev 		return NULL;
1577f076bcfbSAlexander Kozyrev 	}
1578f076bcfbSAlexander Kozyrev 	if (actions == NULL) {
1579f076bcfbSAlexander Kozyrev 		RTE_FLOW_LOG(ERR,
1580f076bcfbSAlexander Kozyrev 			     "Port %"PRIu16" actions is NULL.\n",
1581f076bcfbSAlexander Kozyrev 			     port_id);
1582f076bcfbSAlexander Kozyrev 		rte_flow_error_set(error, EINVAL,
1583f076bcfbSAlexander Kozyrev 				   RTE_FLOW_ERROR_TYPE_ATTR,
1584f076bcfbSAlexander Kozyrev 				   NULL, rte_strerror(EINVAL));
1585f076bcfbSAlexander Kozyrev 		return NULL;
1586f076bcfbSAlexander Kozyrev 	}
1587f076bcfbSAlexander Kozyrev 	if (masks == NULL) {
1588f076bcfbSAlexander Kozyrev 		RTE_FLOW_LOG(ERR,
1589f076bcfbSAlexander Kozyrev 			     "Port %"PRIu16" masks is NULL.\n",
1590f076bcfbSAlexander Kozyrev 			     port_id);
1591f076bcfbSAlexander Kozyrev 		rte_flow_error_set(error, EINVAL,
1592f076bcfbSAlexander Kozyrev 				   RTE_FLOW_ERROR_TYPE_ATTR,
1593f076bcfbSAlexander Kozyrev 				   NULL, rte_strerror(EINVAL));
1594f076bcfbSAlexander Kozyrev 
1595f076bcfbSAlexander Kozyrev 	}
1596f076bcfbSAlexander Kozyrev 	if (likely(!!ops->actions_template_create)) {
1597f076bcfbSAlexander Kozyrev 		template = ops->actions_template_create(dev, template_attr,
1598f076bcfbSAlexander Kozyrev 							actions, masks, error);
1599f076bcfbSAlexander Kozyrev 		if (template == NULL)
1600f076bcfbSAlexander Kozyrev 			flow_err(port_id, -rte_errno, error);
1601f076bcfbSAlexander Kozyrev 		return template;
1602f076bcfbSAlexander Kozyrev 	}
1603f076bcfbSAlexander Kozyrev 	rte_flow_error_set(error, ENOTSUP,
1604f076bcfbSAlexander Kozyrev 			   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1605f076bcfbSAlexander Kozyrev 			   NULL, rte_strerror(ENOTSUP));
1606f076bcfbSAlexander Kozyrev 	return NULL;
1607f076bcfbSAlexander Kozyrev }
1608f076bcfbSAlexander Kozyrev 
1609f076bcfbSAlexander Kozyrev int
rte_flow_actions_template_destroy(uint16_t port_id,struct rte_flow_actions_template * actions_template,struct rte_flow_error * error)1610f076bcfbSAlexander Kozyrev rte_flow_actions_template_destroy(uint16_t port_id,
1611f076bcfbSAlexander Kozyrev 			struct rte_flow_actions_template *actions_template,
1612f076bcfbSAlexander Kozyrev 			struct rte_flow_error *error)
1613f076bcfbSAlexander Kozyrev {
1614f076bcfbSAlexander Kozyrev 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1615f076bcfbSAlexander Kozyrev 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1616f076bcfbSAlexander Kozyrev 
1617f076bcfbSAlexander Kozyrev 	if (unlikely(!ops))
1618f076bcfbSAlexander Kozyrev 		return -rte_errno;
1619f076bcfbSAlexander Kozyrev 	if (unlikely(actions_template == NULL))
1620f076bcfbSAlexander Kozyrev 		return 0;
1621f076bcfbSAlexander Kozyrev 	if (likely(!!ops->actions_template_destroy)) {
1622f076bcfbSAlexander Kozyrev 		return flow_err(port_id,
1623f076bcfbSAlexander Kozyrev 				ops->actions_template_destroy(dev,
1624f076bcfbSAlexander Kozyrev 							      actions_template,
1625f076bcfbSAlexander Kozyrev 							      error),
1626f076bcfbSAlexander Kozyrev 				error);
1627f076bcfbSAlexander Kozyrev 	}
1628f076bcfbSAlexander Kozyrev 	return rte_flow_error_set(error, ENOTSUP,
1629f076bcfbSAlexander Kozyrev 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1630f076bcfbSAlexander Kozyrev 				  NULL, rte_strerror(ENOTSUP));
1631f076bcfbSAlexander Kozyrev }
1632f076bcfbSAlexander Kozyrev 
1633f076bcfbSAlexander Kozyrev struct rte_flow_template_table *
rte_flow_template_table_create(uint16_t port_id,const struct rte_flow_template_table_attr * table_attr,struct rte_flow_pattern_template * pattern_templates[],uint8_t nb_pattern_templates,struct rte_flow_actions_template * actions_templates[],uint8_t nb_actions_templates,struct rte_flow_error * error)1634f076bcfbSAlexander Kozyrev rte_flow_template_table_create(uint16_t port_id,
1635f076bcfbSAlexander Kozyrev 			const struct rte_flow_template_table_attr *table_attr,
1636f076bcfbSAlexander Kozyrev 			struct rte_flow_pattern_template *pattern_templates[],
1637f076bcfbSAlexander Kozyrev 			uint8_t nb_pattern_templates,
1638f076bcfbSAlexander Kozyrev 			struct rte_flow_actions_template *actions_templates[],
1639f076bcfbSAlexander Kozyrev 			uint8_t nb_actions_templates,
1640f076bcfbSAlexander Kozyrev 			struct rte_flow_error *error)
1641f076bcfbSAlexander Kozyrev {
1642f076bcfbSAlexander Kozyrev 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1643f076bcfbSAlexander Kozyrev 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1644f076bcfbSAlexander Kozyrev 	struct rte_flow_template_table *table;
1645f076bcfbSAlexander Kozyrev 
1646f076bcfbSAlexander Kozyrev 	if (unlikely(!ops))
1647f076bcfbSAlexander Kozyrev 		return NULL;
1648f076bcfbSAlexander Kozyrev 	if (dev->data->flow_configured == 0) {
1649f076bcfbSAlexander Kozyrev 		RTE_FLOW_LOG(INFO,
1650f076bcfbSAlexander Kozyrev 			"Flow engine on port_id=%"PRIu16" is not configured.\n",
1651f076bcfbSAlexander Kozyrev 			port_id);
1652f076bcfbSAlexander Kozyrev 		rte_flow_error_set(error, EINVAL,
1653f076bcfbSAlexander Kozyrev 				   RTE_FLOW_ERROR_TYPE_STATE,
1654f076bcfbSAlexander Kozyrev 				   NULL, rte_strerror(EINVAL));
1655f076bcfbSAlexander Kozyrev 		return NULL;
1656f076bcfbSAlexander Kozyrev 	}
1657f076bcfbSAlexander Kozyrev 	if (table_attr == NULL) {
1658f076bcfbSAlexander Kozyrev 		RTE_FLOW_LOG(ERR,
1659f076bcfbSAlexander Kozyrev 			     "Port %"PRIu16" table attr is NULL.\n",
1660f076bcfbSAlexander Kozyrev 			     port_id);
1661f076bcfbSAlexander Kozyrev 		rte_flow_error_set(error, EINVAL,
1662f076bcfbSAlexander Kozyrev 				   RTE_FLOW_ERROR_TYPE_ATTR,
1663f076bcfbSAlexander Kozyrev 				   NULL, rte_strerror(EINVAL));
1664f076bcfbSAlexander Kozyrev 		return NULL;
1665f076bcfbSAlexander Kozyrev 	}
1666f076bcfbSAlexander Kozyrev 	if (pattern_templates == NULL) {
1667f076bcfbSAlexander Kozyrev 		RTE_FLOW_LOG(ERR,
1668f076bcfbSAlexander Kozyrev 			     "Port %"PRIu16" pattern templates is NULL.\n",
1669f076bcfbSAlexander Kozyrev 			     port_id);
1670f076bcfbSAlexander Kozyrev 		rte_flow_error_set(error, EINVAL,
1671f076bcfbSAlexander Kozyrev 				   RTE_FLOW_ERROR_TYPE_ATTR,
1672f076bcfbSAlexander Kozyrev 				   NULL, rte_strerror(EINVAL));
1673f076bcfbSAlexander Kozyrev 		return NULL;
1674f076bcfbSAlexander Kozyrev 	}
1675f076bcfbSAlexander Kozyrev 	if (actions_templates == NULL) {
1676f076bcfbSAlexander Kozyrev 		RTE_FLOW_LOG(ERR,
1677f076bcfbSAlexander Kozyrev 			     "Port %"PRIu16" actions templates is NULL.\n",
1678f076bcfbSAlexander Kozyrev 			     port_id);
1679f076bcfbSAlexander Kozyrev 		rte_flow_error_set(error, EINVAL,
1680f076bcfbSAlexander Kozyrev 				   RTE_FLOW_ERROR_TYPE_ATTR,
1681f076bcfbSAlexander Kozyrev 				   NULL, rte_strerror(EINVAL));
1682f076bcfbSAlexander Kozyrev 		return NULL;
1683f076bcfbSAlexander Kozyrev 	}
1684f076bcfbSAlexander Kozyrev 	if (likely(!!ops->template_table_create)) {
1685f076bcfbSAlexander Kozyrev 		table = ops->template_table_create(dev, table_attr,
1686f076bcfbSAlexander Kozyrev 					pattern_templates, nb_pattern_templates,
1687f076bcfbSAlexander Kozyrev 					actions_templates, nb_actions_templates,
1688f076bcfbSAlexander Kozyrev 					error);
1689f076bcfbSAlexander Kozyrev 		if (table == NULL)
1690f076bcfbSAlexander Kozyrev 			flow_err(port_id, -rte_errno, error);
1691f076bcfbSAlexander Kozyrev 		return table;
1692f076bcfbSAlexander Kozyrev 	}
1693f076bcfbSAlexander Kozyrev 	rte_flow_error_set(error, ENOTSUP,
1694f076bcfbSAlexander Kozyrev 			   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1695f076bcfbSAlexander Kozyrev 			   NULL, rte_strerror(ENOTSUP));
1696f076bcfbSAlexander Kozyrev 	return NULL;
1697f076bcfbSAlexander Kozyrev }
1698f076bcfbSAlexander Kozyrev 
1699f076bcfbSAlexander Kozyrev int
rte_flow_template_table_destroy(uint16_t port_id,struct rte_flow_template_table * template_table,struct rte_flow_error * error)1700f076bcfbSAlexander Kozyrev rte_flow_template_table_destroy(uint16_t port_id,
1701f076bcfbSAlexander Kozyrev 				struct rte_flow_template_table *template_table,
1702f076bcfbSAlexander Kozyrev 				struct rte_flow_error *error)
1703f076bcfbSAlexander Kozyrev {
1704f076bcfbSAlexander Kozyrev 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1705f076bcfbSAlexander Kozyrev 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1706f076bcfbSAlexander Kozyrev 
1707f076bcfbSAlexander Kozyrev 	if (unlikely(!ops))
1708f076bcfbSAlexander Kozyrev 		return -rte_errno;
1709f076bcfbSAlexander Kozyrev 	if (unlikely(template_table == NULL))
1710f076bcfbSAlexander Kozyrev 		return 0;
1711f076bcfbSAlexander Kozyrev 	if (likely(!!ops->template_table_destroy)) {
1712f076bcfbSAlexander Kozyrev 		return flow_err(port_id,
1713f076bcfbSAlexander Kozyrev 				ops->template_table_destroy(dev,
1714f076bcfbSAlexander Kozyrev 							    template_table,
1715f076bcfbSAlexander Kozyrev 							    error),
1716f076bcfbSAlexander Kozyrev 				error);
1717f076bcfbSAlexander Kozyrev 	}
1718f076bcfbSAlexander Kozyrev 	return rte_flow_error_set(error, ENOTSUP,
1719f076bcfbSAlexander Kozyrev 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1720f076bcfbSAlexander Kozyrev 				  NULL, rte_strerror(ENOTSUP));
1721f076bcfbSAlexander Kozyrev }
1722197e820cSAlexander Kozyrev 
1723197e820cSAlexander Kozyrev struct rte_flow *
rte_flow_async_create(uint16_t port_id,uint32_t queue_id,const struct rte_flow_op_attr * op_attr,struct rte_flow_template_table * template_table,const struct rte_flow_item pattern[],uint8_t pattern_template_index,const struct rte_flow_action actions[],uint8_t actions_template_index,void * user_data,struct rte_flow_error * error)1724197e820cSAlexander Kozyrev rte_flow_async_create(uint16_t port_id,
1725197e820cSAlexander Kozyrev 		      uint32_t queue_id,
1726197e820cSAlexander Kozyrev 		      const struct rte_flow_op_attr *op_attr,
1727197e820cSAlexander Kozyrev 		      struct rte_flow_template_table *template_table,
1728197e820cSAlexander Kozyrev 		      const struct rte_flow_item pattern[],
1729197e820cSAlexander Kozyrev 		      uint8_t pattern_template_index,
1730197e820cSAlexander Kozyrev 		      const struct rte_flow_action actions[],
1731197e820cSAlexander Kozyrev 		      uint8_t actions_template_index,
1732197e820cSAlexander Kozyrev 		      void *user_data,
1733197e820cSAlexander Kozyrev 		      struct rte_flow_error *error)
1734197e820cSAlexander Kozyrev {
1735197e820cSAlexander Kozyrev 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1736197e820cSAlexander Kozyrev 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1737197e820cSAlexander Kozyrev 	struct rte_flow *flow;
1738197e820cSAlexander Kozyrev 
1739197e820cSAlexander Kozyrev 	flow = ops->async_create(dev, queue_id,
1740197e820cSAlexander Kozyrev 				 op_attr, template_table,
1741197e820cSAlexander Kozyrev 				 pattern, pattern_template_index,
1742197e820cSAlexander Kozyrev 				 actions, actions_template_index,
1743197e820cSAlexander Kozyrev 				 user_data, error);
1744197e820cSAlexander Kozyrev 	if (flow == NULL)
1745197e820cSAlexander Kozyrev 		flow_err(port_id, -rte_errno, error);
1746197e820cSAlexander Kozyrev 	return flow;
1747197e820cSAlexander Kozyrev }
1748197e820cSAlexander Kozyrev 
1749197e820cSAlexander Kozyrev int
rte_flow_async_destroy(uint16_t port_id,uint32_t queue_id,const struct rte_flow_op_attr * op_attr,struct rte_flow * flow,void * user_data,struct rte_flow_error * error)1750197e820cSAlexander Kozyrev rte_flow_async_destroy(uint16_t port_id,
1751197e820cSAlexander Kozyrev 		       uint32_t queue_id,
1752197e820cSAlexander Kozyrev 		       const struct rte_flow_op_attr *op_attr,
1753197e820cSAlexander Kozyrev 		       struct rte_flow *flow,
1754197e820cSAlexander Kozyrev 		       void *user_data,
1755197e820cSAlexander Kozyrev 		       struct rte_flow_error *error)
1756197e820cSAlexander Kozyrev {
1757197e820cSAlexander Kozyrev 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1758197e820cSAlexander Kozyrev 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1759197e820cSAlexander Kozyrev 
1760197e820cSAlexander Kozyrev 	return flow_err(port_id,
1761197e820cSAlexander Kozyrev 			ops->async_destroy(dev, queue_id,
1762197e820cSAlexander Kozyrev 					   op_attr, flow,
1763197e820cSAlexander Kozyrev 					   user_data, error),
1764197e820cSAlexander Kozyrev 			error);
1765197e820cSAlexander Kozyrev }
1766197e820cSAlexander Kozyrev 
1767197e820cSAlexander Kozyrev int
rte_flow_push(uint16_t port_id,uint32_t queue_id,struct rte_flow_error * error)1768197e820cSAlexander Kozyrev rte_flow_push(uint16_t port_id,
1769197e820cSAlexander Kozyrev 	      uint32_t queue_id,
1770197e820cSAlexander Kozyrev 	      struct rte_flow_error *error)
1771197e820cSAlexander Kozyrev {
1772197e820cSAlexander Kozyrev 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1773197e820cSAlexander Kozyrev 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1774197e820cSAlexander Kozyrev 
1775197e820cSAlexander Kozyrev 	return flow_err(port_id,
1776197e820cSAlexander Kozyrev 			ops->push(dev, queue_id, error),
1777197e820cSAlexander Kozyrev 			error);
1778197e820cSAlexander Kozyrev }
1779197e820cSAlexander Kozyrev 
1780197e820cSAlexander Kozyrev int
rte_flow_pull(uint16_t port_id,uint32_t queue_id,struct rte_flow_op_result res[],uint16_t n_res,struct rte_flow_error * error)1781197e820cSAlexander Kozyrev rte_flow_pull(uint16_t port_id,
1782197e820cSAlexander Kozyrev 	      uint32_t queue_id,
1783197e820cSAlexander Kozyrev 	      struct rte_flow_op_result res[],
1784197e820cSAlexander Kozyrev 	      uint16_t n_res,
1785197e820cSAlexander Kozyrev 	      struct rte_flow_error *error)
1786197e820cSAlexander Kozyrev {
1787197e820cSAlexander Kozyrev 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1788197e820cSAlexander Kozyrev 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1789197e820cSAlexander Kozyrev 	int ret;
1790197e820cSAlexander Kozyrev 
1791197e820cSAlexander Kozyrev 	ret = ops->pull(dev, queue_id, res, n_res, error);
1792197e820cSAlexander Kozyrev 	return ret ? ret : flow_err(port_id, ret, error);
1793197e820cSAlexander Kozyrev }
1794*13cd6d5cSAlexander Kozyrev 
1795*13cd6d5cSAlexander Kozyrev struct rte_flow_action_handle *
rte_flow_async_action_handle_create(uint16_t port_id,uint32_t queue_id,const struct rte_flow_op_attr * op_attr,const struct rte_flow_indir_action_conf * indir_action_conf,const struct rte_flow_action * action,void * user_data,struct rte_flow_error * error)1796*13cd6d5cSAlexander Kozyrev rte_flow_async_action_handle_create(uint16_t port_id,
1797*13cd6d5cSAlexander Kozyrev 		uint32_t queue_id,
1798*13cd6d5cSAlexander Kozyrev 		const struct rte_flow_op_attr *op_attr,
1799*13cd6d5cSAlexander Kozyrev 		const struct rte_flow_indir_action_conf *indir_action_conf,
1800*13cd6d5cSAlexander Kozyrev 		const struct rte_flow_action *action,
1801*13cd6d5cSAlexander Kozyrev 		void *user_data,
1802*13cd6d5cSAlexander Kozyrev 		struct rte_flow_error *error)
1803*13cd6d5cSAlexander Kozyrev {
1804*13cd6d5cSAlexander Kozyrev 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1805*13cd6d5cSAlexander Kozyrev 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1806*13cd6d5cSAlexander Kozyrev 	struct rte_flow_action_handle *handle;
1807*13cd6d5cSAlexander Kozyrev 
1808*13cd6d5cSAlexander Kozyrev 	handle = ops->async_action_handle_create(dev, queue_id, op_attr,
1809*13cd6d5cSAlexander Kozyrev 					     indir_action_conf, action, user_data, error);
1810*13cd6d5cSAlexander Kozyrev 	if (handle == NULL)
1811*13cd6d5cSAlexander Kozyrev 		flow_err(port_id, -rte_errno, error);
1812*13cd6d5cSAlexander Kozyrev 	return handle;
1813*13cd6d5cSAlexander Kozyrev }
1814*13cd6d5cSAlexander Kozyrev 
1815*13cd6d5cSAlexander Kozyrev int
rte_flow_async_action_handle_destroy(uint16_t port_id,uint32_t queue_id,const struct rte_flow_op_attr * op_attr,struct rte_flow_action_handle * action_handle,void * user_data,struct rte_flow_error * error)1816*13cd6d5cSAlexander Kozyrev rte_flow_async_action_handle_destroy(uint16_t port_id,
1817*13cd6d5cSAlexander Kozyrev 		uint32_t queue_id,
1818*13cd6d5cSAlexander Kozyrev 		const struct rte_flow_op_attr *op_attr,
1819*13cd6d5cSAlexander Kozyrev 		struct rte_flow_action_handle *action_handle,
1820*13cd6d5cSAlexander Kozyrev 		void *user_data,
1821*13cd6d5cSAlexander Kozyrev 		struct rte_flow_error *error)
1822*13cd6d5cSAlexander Kozyrev {
1823*13cd6d5cSAlexander Kozyrev 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1824*13cd6d5cSAlexander Kozyrev 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1825*13cd6d5cSAlexander Kozyrev 	int ret;
1826*13cd6d5cSAlexander Kozyrev 
1827*13cd6d5cSAlexander Kozyrev 	ret = ops->async_action_handle_destroy(dev, queue_id, op_attr,
1828*13cd6d5cSAlexander Kozyrev 					   action_handle, user_data, error);
1829*13cd6d5cSAlexander Kozyrev 	return flow_err(port_id, ret, error);
1830*13cd6d5cSAlexander Kozyrev }
1831*13cd6d5cSAlexander Kozyrev 
1832*13cd6d5cSAlexander Kozyrev int
rte_flow_async_action_handle_update(uint16_t port_id,uint32_t queue_id,const struct rte_flow_op_attr * op_attr,struct rte_flow_action_handle * action_handle,const void * update,void * user_data,struct rte_flow_error * error)1833*13cd6d5cSAlexander Kozyrev rte_flow_async_action_handle_update(uint16_t port_id,
1834*13cd6d5cSAlexander Kozyrev 		uint32_t queue_id,
1835*13cd6d5cSAlexander Kozyrev 		const struct rte_flow_op_attr *op_attr,
1836*13cd6d5cSAlexander Kozyrev 		struct rte_flow_action_handle *action_handle,
1837*13cd6d5cSAlexander Kozyrev 		const void *update,
1838*13cd6d5cSAlexander Kozyrev 		void *user_data,
1839*13cd6d5cSAlexander Kozyrev 		struct rte_flow_error *error)
1840*13cd6d5cSAlexander Kozyrev {
1841*13cd6d5cSAlexander Kozyrev 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1842*13cd6d5cSAlexander Kozyrev 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
1843*13cd6d5cSAlexander Kozyrev 	int ret;
1844*13cd6d5cSAlexander Kozyrev 
1845*13cd6d5cSAlexander Kozyrev 	ret = ops->async_action_handle_update(dev, queue_id, op_attr,
1846*13cd6d5cSAlexander Kozyrev 					  action_handle, update, user_data, error);
1847*13cd6d5cSAlexander Kozyrev 	return flow_err(port_id, ret, error);
1848*13cd6d5cSAlexander Kozyrev }
1849