xref: /dpdk/drivers/net/mlx5/mlx5_flow_verbs.c (revision a94e89e47b59ebaf84246bbb34c06e1a004cde8a)
184c406e7SOri Kam /* SPDX-License-Identifier: BSD-3-Clause
284c406e7SOri Kam  * Copyright 2018 Mellanox Technologies, Ltd
384c406e7SOri Kam  */
484c406e7SOri Kam 
584c406e7SOri Kam #include <netinet/in.h>
684c406e7SOri Kam #include <sys/queue.h>
784c406e7SOri Kam #include <stdalign.h>
884c406e7SOri Kam #include <stdint.h>
984c406e7SOri Kam #include <string.h>
1084c406e7SOri Kam 
1184c406e7SOri Kam #include <rte_common.h>
1284c406e7SOri Kam #include <rte_ether.h>
13df96fd0dSBruce Richardson #include <ethdev_driver.h>
1484c406e7SOri Kam #include <rte_flow.h>
1584c406e7SOri Kam #include <rte_flow_driver.h>
1684c406e7SOri Kam #include <rte_malloc.h>
1784c406e7SOri Kam #include <rte_ip.h>
1884c406e7SOri Kam 
197b4f1e6bSMatan Azrad #include <mlx5_glue.h>
207b4f1e6bSMatan Azrad #include <mlx5_prm.h>
2183c2047cSSuanming Mou #include <mlx5_malloc.h>
227b4f1e6bSMatan Azrad 
2384c406e7SOri Kam #include "mlx5_defs.h"
247b4f1e6bSMatan Azrad #include "mlx5.h"
2584c406e7SOri Kam #include "mlx5_flow.h"
26151cbe3aSMichael Baum #include "mlx5_rx.h"
2784c406e7SOri Kam 
284a78c88eSYongseok Koh #define VERBS_SPEC_INNER(item_flags) \
294a78c88eSYongseok Koh 	(!!((item_flags) & MLX5_FLOW_LAYER_TUNNEL) ? IBV_FLOW_SPEC_INNER : 0)
304a78c88eSYongseok Koh 
31f1ae0b35SOphir Munk /* Verbs specification header. */
32f1ae0b35SOphir Munk struct ibv_spec_header {
33f1ae0b35SOphir Munk 	enum ibv_flow_spec_type type;
34f1ae0b35SOphir Munk 	uint16_t size;
35f1ae0b35SOphir Munk };
36f1ae0b35SOphir Munk 
373eca5f8aSOphir Munk /**
383eca5f8aSOphir Munk  * Discover the maximum number of priority available.
393eca5f8aSOphir Munk  *
403eca5f8aSOphir Munk  * @param[in] dev
413eca5f8aSOphir Munk  *   Pointer to the Ethernet device structure.
42c5042f93SDmitry Kozlyuk  * @param[in] vprio
43c5042f93SDmitry Kozlyuk  *   Expected result variants.
44c5042f93SDmitry Kozlyuk  * @param[in] vprio_n
45c5042f93SDmitry Kozlyuk  *   Number of entries in @p vprio array.
463eca5f8aSOphir Munk  * @return
47c5042f93SDmitry Kozlyuk  *   Number of supported flow priority on success, a negative errno
483eca5f8aSOphir Munk  *   value otherwise and rte_errno is set.
493eca5f8aSOphir Munk  */
50c5042f93SDmitry Kozlyuk static int
51c5042f93SDmitry Kozlyuk flow_verbs_discover_priorities(struct rte_eth_dev *dev,
52c5042f93SDmitry Kozlyuk 			       const uint16_t *vprio, int vprio_n)
533eca5f8aSOphir Munk {
543eca5f8aSOphir Munk 	struct mlx5_priv *priv = dev->data->dev_private;
553eca5f8aSOphir Munk 	struct {
563eca5f8aSOphir Munk 		struct ibv_flow_attr attr;
573eca5f8aSOphir Munk 		struct ibv_flow_spec_eth eth;
583eca5f8aSOphir Munk 		struct ibv_flow_spec_action_drop drop;
593eca5f8aSOphir Munk 	} flow_attr = {
603eca5f8aSOphir Munk 		.attr = {
613eca5f8aSOphir Munk 			.num_of_specs = 2,
623eca5f8aSOphir Munk 			.port = (uint8_t)priv->dev_port,
633eca5f8aSOphir Munk 		},
643eca5f8aSOphir Munk 		.eth = {
653eca5f8aSOphir Munk 			.type = IBV_FLOW_SPEC_ETH,
663eca5f8aSOphir Munk 			.size = sizeof(struct ibv_flow_spec_eth),
673eca5f8aSOphir Munk 		},
683eca5f8aSOphir Munk 		.drop = {
693eca5f8aSOphir Munk 			.size = sizeof(struct ibv_flow_spec_action_drop),
703eca5f8aSOphir Munk 			.type = IBV_FLOW_SPEC_ACTION_DROP,
713eca5f8aSOphir Munk 		},
723eca5f8aSOphir Munk 	};
733eca5f8aSOphir Munk 	struct ibv_flow *flow;
7465b3cd0dSSuanming Mou 	struct mlx5_hrxq *drop = priv->drop_queue.hrxq;
753eca5f8aSOphir Munk 	int i;
763eca5f8aSOphir Munk 	int priority = 0;
773eca5f8aSOphir Munk 
781d47e933SXueming Li #if defined(HAVE_MLX5DV_DR_DEVX_PORT) || defined(HAVE_MLX5DV_DR_DEVX_PORT_V35)
791d47e933SXueming Li 	/* If DevX supported, driver must support 16 verbs flow priorities. */
80c5042f93SDmitry Kozlyuk 	priority = 16;
811d47e933SXueming Li 	goto out;
821d47e933SXueming Li #endif
8365b3cd0dSSuanming Mou 	if (!drop->qp) {
843eca5f8aSOphir Munk 		rte_errno = ENOTSUP;
853eca5f8aSOphir Munk 		return -rte_errno;
863eca5f8aSOphir Munk 	}
87c5042f93SDmitry Kozlyuk 	for (i = 0; i != vprio_n; i++) {
883eca5f8aSOphir Munk 		flow_attr.attr.priority = vprio[i] - 1;
893eca5f8aSOphir Munk 		flow = mlx5_glue->create_flow(drop->qp, &flow_attr.attr);
903eca5f8aSOphir Munk 		if (!flow)
913eca5f8aSOphir Munk 			break;
923eca5f8aSOphir Munk 		claim_zero(mlx5_glue->destroy_flow(flow));
933eca5f8aSOphir Munk 		priority = vprio[i];
943eca5f8aSOphir Munk 	}
951d47e933SXueming Li #if defined(HAVE_MLX5DV_DR_DEVX_PORT) || defined(HAVE_MLX5DV_DR_DEVX_PORT_V35)
961d47e933SXueming Li out:
971d47e933SXueming Li #endif
985f8ae44dSDong Zhou 	DRV_LOG(INFO, "port %u supported flow priorities:"
995f8ae44dSDong Zhou 		" 0-%d for ingress or egress root table,"
1005f8ae44dSDong Zhou 		" 0-%d for non-root table or transfer root table.",
1015f8ae44dSDong Zhou 		dev->data->port_id, priority - 2,
1025f8ae44dSDong Zhou 		MLX5_NON_ROOT_FLOW_MAX_PRIO - 1);
1033eca5f8aSOphir Munk 	return priority;
1043eca5f8aSOphir Munk }
1053eca5f8aSOphir Munk 
1063eca5f8aSOphir Munk /**
107c3d3b140SSuanming Mou  * Get Verbs flow counter by index.
108c3d3b140SSuanming Mou  *
109c3d3b140SSuanming Mou  * @param[in] dev
110c3d3b140SSuanming Mou  *   Pointer to the Ethernet device structure.
111c3d3b140SSuanming Mou  * @param[in] idx
112c3d3b140SSuanming Mou  *   mlx5 flow counter index in the container.
113c3d3b140SSuanming Mou  * @param[out] ppool
114c3d3b140SSuanming Mou  *   mlx5 flow counter pool in the container,
115c3d3b140SSuanming Mou  *
116c3d3b140SSuanming Mou  * @return
117c3d3b140SSuanming Mou  *   A pointer to the counter, NULL otherwise.
118c3d3b140SSuanming Mou  */
119c3d3b140SSuanming Mou static struct mlx5_flow_counter *
120c3d3b140SSuanming Mou flow_verbs_counter_get_by_idx(struct rte_eth_dev *dev,
121c3d3b140SSuanming Mou 			      uint32_t idx,
122c3d3b140SSuanming Mou 			      struct mlx5_flow_counter_pool **ppool)
123c3d3b140SSuanming Mou {
124c3d3b140SSuanming Mou 	struct mlx5_priv *priv = dev->data->dev_private;
12504a4de75SMichael Baum 	struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
126c3d3b140SSuanming Mou 	struct mlx5_flow_counter_pool *pool;
127c3d3b140SSuanming Mou 
128df051a3eSSuanming Mou 	idx = (idx - 1) & (MLX5_CNT_SHARED_OFFSET - 1);
129994829e6SSuanming Mou 	pool = cmng->pools[idx / MLX5_COUNTERS_PER_POOL];
130c3d3b140SSuanming Mou 	MLX5_ASSERT(pool);
131c3d3b140SSuanming Mou 	if (ppool)
132c3d3b140SSuanming Mou 		*ppool = pool;
1338d93c830SDong Zhou 	return MLX5_POOL_GET_CNT(pool, idx % MLX5_COUNTERS_PER_POOL);
134c3d3b140SSuanming Mou }
135c3d3b140SSuanming Mou 
136c3d3b140SSuanming Mou /**
137db48f9dbSViacheslav Ovsiienko  * Create Verbs flow counter with Verbs library.
138db48f9dbSViacheslav Ovsiienko  *
139db48f9dbSViacheslav Ovsiienko  * @param[in] dev
140db48f9dbSViacheslav Ovsiienko  *   Pointer to the Ethernet device structure.
141db48f9dbSViacheslav Ovsiienko  * @param[in, out] counter
142db48f9dbSViacheslav Ovsiienko  *   mlx5 flow counter object, contains the counter id,
143db48f9dbSViacheslav Ovsiienko  *   handle of created Verbs flow counter is returned
144db48f9dbSViacheslav Ovsiienko  *   in cs field (if counters are supported).
145db48f9dbSViacheslav Ovsiienko  *
146db48f9dbSViacheslav Ovsiienko  * @return
147db48f9dbSViacheslav Ovsiienko  *   0 On success else a negative errno value is returned
148db48f9dbSViacheslav Ovsiienko  *   and rte_errno is set.
149db48f9dbSViacheslav Ovsiienko  */
150db48f9dbSViacheslav Ovsiienko static int
151db48f9dbSViacheslav Ovsiienko flow_verbs_counter_create(struct rte_eth_dev *dev,
1522b5b1aebSSuanming Mou 			  struct mlx5_flow_counter *counter)
153db48f9dbSViacheslav Ovsiienko {
154db48f9dbSViacheslav Ovsiienko #if defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42)
155dbeba4cfSThomas Monjalon 	struct mlx5_priv *priv = dev->data->dev_private;
156ca1418ceSMichael Baum 	struct ibv_context *ctx = priv->sh->cdev->ctx;
157db48f9dbSViacheslav Ovsiienko 	struct ibv_counter_set_init_attr init = {
1582b5b1aebSSuanming Mou 			 .counter_set_id = counter->shared_info.id};
159db48f9dbSViacheslav Ovsiienko 
1602b5b1aebSSuanming Mou 	counter->dcs_when_free = mlx5_glue->create_counter_set(ctx, &init);
1612b5b1aebSSuanming Mou 	if (!counter->dcs_when_free) {
162db48f9dbSViacheslav Ovsiienko 		rte_errno = ENOTSUP;
163db48f9dbSViacheslav Ovsiienko 		return -ENOTSUP;
164db48f9dbSViacheslav Ovsiienko 	}
165db48f9dbSViacheslav Ovsiienko 	return 0;
166db48f9dbSViacheslav Ovsiienko #elif defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45)
167dbeba4cfSThomas Monjalon 	struct mlx5_priv *priv = dev->data->dev_private;
168ca1418ceSMichael Baum 	struct ibv_context *ctx = priv->sh->cdev->ctx;
169db48f9dbSViacheslav Ovsiienko 	struct ibv_counters_init_attr init = {0};
1700c15f3c0SAli Alnubani 	struct ibv_counter_attach_attr attach;
171db48f9dbSViacheslav Ovsiienko 	int ret;
172db48f9dbSViacheslav Ovsiienko 
1730c15f3c0SAli Alnubani 	memset(&attach, 0, sizeof(attach));
1742b5b1aebSSuanming Mou 	counter->dcs_when_free = mlx5_glue->create_counters(ctx, &init);
1752b5b1aebSSuanming Mou 	if (!counter->dcs_when_free) {
176db48f9dbSViacheslav Ovsiienko 		rte_errno = ENOTSUP;
177db48f9dbSViacheslav Ovsiienko 		return -ENOTSUP;
178db48f9dbSViacheslav Ovsiienko 	}
179db48f9dbSViacheslav Ovsiienko 	attach.counter_desc = IBV_COUNTER_PACKETS;
180db48f9dbSViacheslav Ovsiienko 	attach.index = 0;
1812b5b1aebSSuanming Mou 	ret = mlx5_glue->attach_counters(counter->dcs_when_free, &attach, NULL);
182db48f9dbSViacheslav Ovsiienko 	if (!ret) {
183db48f9dbSViacheslav Ovsiienko 		attach.counter_desc = IBV_COUNTER_BYTES;
184db48f9dbSViacheslav Ovsiienko 		attach.index = 1;
185db48f9dbSViacheslav Ovsiienko 		ret = mlx5_glue->attach_counters
1862b5b1aebSSuanming Mou 					(counter->dcs_when_free, &attach, NULL);
187db48f9dbSViacheslav Ovsiienko 	}
188db48f9dbSViacheslav Ovsiienko 	if (ret) {
1892b5b1aebSSuanming Mou 		claim_zero(mlx5_glue->destroy_counters(counter->dcs_when_free));
1902b5b1aebSSuanming Mou 		counter->dcs_when_free = NULL;
191db48f9dbSViacheslav Ovsiienko 		rte_errno = ret;
192db48f9dbSViacheslav Ovsiienko 		return -ret;
193db48f9dbSViacheslav Ovsiienko 	}
194db48f9dbSViacheslav Ovsiienko 	return 0;
195db48f9dbSViacheslav Ovsiienko #else
196db48f9dbSViacheslav Ovsiienko 	(void)dev;
197db48f9dbSViacheslav Ovsiienko 	(void)counter;
198db48f9dbSViacheslav Ovsiienko 	rte_errno = ENOTSUP;
199db48f9dbSViacheslav Ovsiienko 	return -ENOTSUP;
200db48f9dbSViacheslav Ovsiienko #endif
201db48f9dbSViacheslav Ovsiienko }
202db48f9dbSViacheslav Ovsiienko 
203db48f9dbSViacheslav Ovsiienko /**
20484c406e7SOri Kam  * Get a flow counter.
20584c406e7SOri Kam  *
20684c406e7SOri Kam  * @param[in] dev
20784c406e7SOri Kam  *   Pointer to the Ethernet device structure.
20884c406e7SOri Kam  * @param[in] id
20984c406e7SOri Kam  *   Counter identifier.
21084c406e7SOri Kam  *
21184c406e7SOri Kam  * @return
212956d5c74SSuanming Mou  *   Index to the counter, 0 otherwise and rte_errno is set.
21384c406e7SOri Kam  */
214956d5c74SSuanming Mou static uint32_t
21592ef4b8fSAndrew Rybchenko flow_verbs_counter_new(struct rte_eth_dev *dev, uint32_t id __rte_unused)
21684c406e7SOri Kam {
217dbeba4cfSThomas Monjalon 	struct mlx5_priv *priv = dev->data->dev_private;
21804a4de75SMichael Baum 	struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
219c3d3b140SSuanming Mou 	struct mlx5_flow_counter_pool *pool = NULL;
220c3d3b140SSuanming Mou 	struct mlx5_flow_counter *cnt = NULL;
2213aa27915SSuanming Mou 	uint32_t n_valid = cmng->n_valid;
222df051a3eSSuanming Mou 	uint32_t pool_idx, cnt_idx;
223c3d3b140SSuanming Mou 	uint32_t i;
224db48f9dbSViacheslav Ovsiienko 	int ret;
22584c406e7SOri Kam 
226c3d3b140SSuanming Mou 	for (pool_idx = 0; pool_idx < n_valid; ++pool_idx) {
227994829e6SSuanming Mou 		pool = cmng->pools[pool_idx];
228c3d3b140SSuanming Mou 		if (!pool)
229c3d3b140SSuanming Mou 			continue;
230ac79183dSSuanming Mou 		cnt = TAILQ_FIRST(&pool->counters[0]);
231c3d3b140SSuanming Mou 		if (cnt)
232c3d3b140SSuanming Mou 			break;
233c3d3b140SSuanming Mou 	}
23484c406e7SOri Kam 	if (!cnt) {
235c3d3b140SSuanming Mou 		uint32_t size;
236c3d3b140SSuanming Mou 
237*a94e89e4SMichael Baum 		if (n_valid == MLX5_COUNTER_POOLS_MAX_NUM) {
238*a94e89e4SMichael Baum 			DRV_LOG(ERR, "All counter is in used, try again later.");
239*a94e89e4SMichael Baum 			rte_errno = EAGAIN;
240956d5c74SSuanming Mou 			return 0;
241c3d3b140SSuanming Mou 		}
242c3d3b140SSuanming Mou 		/* Allocate memory for new pool */
2432b5b1aebSSuanming Mou 		size = sizeof(*pool) + sizeof(*cnt) * MLX5_COUNTERS_PER_POOL;
24483c2047cSSuanming Mou 		pool = mlx5_malloc(MLX5_MEM_ZERO, size, 0, SOCKET_ID_ANY);
245c3d3b140SSuanming Mou 		if (!pool)
246956d5c74SSuanming Mou 			return 0;
247c3d3b140SSuanming Mou 		for (i = 0; i < MLX5_COUNTERS_PER_POOL; ++i) {
2488d93c830SDong Zhou 			cnt = MLX5_POOL_GET_CNT(pool, i);
249ac79183dSSuanming Mou 			TAILQ_INSERT_HEAD(&pool->counters[0], cnt, next);
250c3d3b140SSuanming Mou 		}
2518d93c830SDong Zhou 		cnt = MLX5_POOL_GET_CNT(pool, 0);
252994829e6SSuanming Mou 		cmng->pools[n_valid] = pool;
253c3d3b140SSuanming Mou 		pool_idx = n_valid;
2543aa27915SSuanming Mou 		cmng->n_valid++;
25584c406e7SOri Kam 	}
2562b5b1aebSSuanming Mou 	TAILQ_REMOVE(&pool->counters[0], cnt, next);
2578d93c830SDong Zhou 	i = MLX5_CNT_ARRAY_IDX(pool, cnt);
258df051a3eSSuanming Mou 	cnt_idx = MLX5_MAKE_CNT_IDX(pool_idx, i);
2592b5b1aebSSuanming Mou 	/* Create counter with Verbs. */
2602b5b1aebSSuanming Mou 	ret = flow_verbs_counter_create(dev, cnt);
2612b5b1aebSSuanming Mou 	if (!ret) {
2622b5b1aebSSuanming Mou 		cnt->dcs_when_active = cnt->dcs_when_free;
263db48f9dbSViacheslav Ovsiienko 		cnt->hits = 0;
264db48f9dbSViacheslav Ovsiienko 		cnt->bytes = 0;
265df051a3eSSuanming Mou 		return cnt_idx;
266db48f9dbSViacheslav Ovsiienko 	}
2672b5b1aebSSuanming Mou 	TAILQ_INSERT_HEAD(&pool->counters[0], cnt, next);
268db48f9dbSViacheslav Ovsiienko 	/* Some error occurred in Verbs library. */
269db48f9dbSViacheslav Ovsiienko 	rte_errno = -ret;
270956d5c74SSuanming Mou 	return 0;
27184c406e7SOri Kam }
27284c406e7SOri Kam 
27384c406e7SOri Kam /**
27484c406e7SOri Kam  * Release a flow counter.
27584c406e7SOri Kam  *
2765382d28cSMatan Azrad  * @param[in] dev
2775382d28cSMatan Azrad  *   Pointer to the Ethernet device structure.
27884c406e7SOri Kam  * @param[in] counter
279956d5c74SSuanming Mou  *   Index to the counter handler.
28084c406e7SOri Kam  */
28184c406e7SOri Kam static void
282956d5c74SSuanming Mou flow_verbs_counter_release(struct rte_eth_dev *dev, uint32_t counter)
28384c406e7SOri Kam {
284c3d3b140SSuanming Mou 	struct mlx5_flow_counter_pool *pool;
285c3d3b140SSuanming Mou 	struct mlx5_flow_counter *cnt;
2865382d28cSMatan Azrad 
287df051a3eSSuanming Mou 	cnt = flow_verbs_counter_get_by_idx(dev, counter, &pool);
288db48f9dbSViacheslav Ovsiienko #if defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42)
2892b5b1aebSSuanming Mou 	claim_zero(mlx5_glue->destroy_counter_set
2902b5b1aebSSuanming Mou 			((struct ibv_counter_set *)cnt->dcs_when_active));
291db48f9dbSViacheslav Ovsiienko #elif defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45)
2922b5b1aebSSuanming Mou 	claim_zero(mlx5_glue->destroy_counters
2932b5b1aebSSuanming Mou 				((struct ibv_counters *)cnt->dcs_when_active));
294db48f9dbSViacheslav Ovsiienko #endif
295ac79183dSSuanming Mou 	TAILQ_INSERT_HEAD(&pool->counters[0], cnt, next);
29684c406e7SOri Kam }
29784c406e7SOri Kam 
29884c406e7SOri Kam /**
29906629d86SViacheslav Ovsiienko  * Query a flow counter via Verbs library call.
30006629d86SViacheslav Ovsiienko  *
30106629d86SViacheslav Ovsiienko  * @see rte_flow_query()
30206629d86SViacheslav Ovsiienko  * @see rte_flow_ops
30306629d86SViacheslav Ovsiienko  */
30406629d86SViacheslav Ovsiienko static int
30506629d86SViacheslav Ovsiienko flow_verbs_counter_query(struct rte_eth_dev *dev __rte_unused,
306db48f9dbSViacheslav Ovsiienko 			 struct rte_flow *flow, void *data,
30706629d86SViacheslav Ovsiienko 			 struct rte_flow_error *error)
30806629d86SViacheslav Ovsiienko {
309db48f9dbSViacheslav Ovsiienko #if defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42) || \
310db48f9dbSViacheslav Ovsiienko 	defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45)
311956d5c74SSuanming Mou 	if (flow->counter) {
312826b8a87SSuanming Mou 		struct mlx5_flow_counter_pool *pool;
313c3d3b140SSuanming Mou 		struct mlx5_flow_counter *cnt = flow_verbs_counter_get_by_idx
314826b8a87SSuanming Mou 						(dev, flow->counter, &pool);
31506629d86SViacheslav Ovsiienko 		struct rte_flow_query_count *qc = data;
31606629d86SViacheslav Ovsiienko 		uint64_t counters[2] = {0, 0};
317db48f9dbSViacheslav Ovsiienko #if defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42)
31806629d86SViacheslav Ovsiienko 		struct ibv_query_counter_set_attr query_cs_attr = {
3192b5b1aebSSuanming Mou 			.dcs_when_free = (struct ibv_counter_set *)
3202b5b1aebSSuanming Mou 						cnt->dcs_when_active,
32106629d86SViacheslav Ovsiienko 			.query_flags = IBV_COUNTER_SET_FORCE_UPDATE,
32206629d86SViacheslav Ovsiienko 		};
32306629d86SViacheslav Ovsiienko 		struct ibv_counter_set_data query_out = {
32406629d86SViacheslav Ovsiienko 			.out = counters,
32506629d86SViacheslav Ovsiienko 			.outlen = 2 * sizeof(uint64_t),
32606629d86SViacheslav Ovsiienko 		};
32706629d86SViacheslav Ovsiienko 		int err = mlx5_glue->query_counter_set(&query_cs_attr,
32806629d86SViacheslav Ovsiienko 						       &query_out);
329db48f9dbSViacheslav Ovsiienko #elif defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45)
330db48f9dbSViacheslav Ovsiienko 		int err = mlx5_glue->query_counters
3312b5b1aebSSuanming Mou 			((struct ibv_counters *)cnt->dcs_when_active, counters,
332db48f9dbSViacheslav Ovsiienko 				RTE_DIM(counters),
333db48f9dbSViacheslav Ovsiienko 				IBV_READ_COUNTERS_ATTR_PREFER_CACHED);
334db48f9dbSViacheslav Ovsiienko #endif
33506629d86SViacheslav Ovsiienko 		if (err)
33606629d86SViacheslav Ovsiienko 			return rte_flow_error_set
33706629d86SViacheslav Ovsiienko 				(error, err,
33806629d86SViacheslav Ovsiienko 				 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
33906629d86SViacheslav Ovsiienko 				 NULL,
34006629d86SViacheslav Ovsiienko 				 "cannot read counter");
34106629d86SViacheslav Ovsiienko 		qc->hits_set = 1;
34206629d86SViacheslav Ovsiienko 		qc->bytes_set = 1;
343c3d3b140SSuanming Mou 		qc->hits = counters[0] - cnt->hits;
344c3d3b140SSuanming Mou 		qc->bytes = counters[1] - cnt->bytes;
34506629d86SViacheslav Ovsiienko 		if (qc->reset) {
346c3d3b140SSuanming Mou 			cnt->hits = counters[0];
347c3d3b140SSuanming Mou 			cnt->bytes = counters[1];
34806629d86SViacheslav Ovsiienko 		}
34906629d86SViacheslav Ovsiienko 		return 0;
35006629d86SViacheslav Ovsiienko 	}
35106629d86SViacheslav Ovsiienko 	return rte_flow_error_set(error, EINVAL,
35206629d86SViacheslav Ovsiienko 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
35306629d86SViacheslav Ovsiienko 				  NULL,
35406629d86SViacheslav Ovsiienko 				  "flow does not have counter");
35506629d86SViacheslav Ovsiienko #else
356db48f9dbSViacheslav Ovsiienko 	(void)flow;
357db48f9dbSViacheslav Ovsiienko 	(void)data;
35806629d86SViacheslav Ovsiienko 	return rte_flow_error_set(error, ENOTSUP,
35906629d86SViacheslav Ovsiienko 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
36006629d86SViacheslav Ovsiienko 				  NULL,
36106629d86SViacheslav Ovsiienko 				  "counters are not available");
36206629d86SViacheslav Ovsiienko #endif
36306629d86SViacheslav Ovsiienko }
36406629d86SViacheslav Ovsiienko 
36506629d86SViacheslav Ovsiienko /**
3664a78c88eSYongseok Koh  * Add a verbs item specification into @p verbs.
36784c406e7SOri Kam  *
3684a78c88eSYongseok Koh  * @param[out] verbs
3694a78c88eSYongseok Koh  *   Pointer to verbs structure.
37084c406e7SOri Kam  * @param[in] src
37184c406e7SOri Kam  *   Create specification.
37284c406e7SOri Kam  * @param[in] size
37384c406e7SOri Kam  *   Size in bytes of the specification to copy.
37484c406e7SOri Kam  */
37584c406e7SOri Kam static void
376e7bfa359SBing Zhao flow_verbs_spec_add(struct mlx5_flow_verbs_workspace *verbs,
377c42f44bdSBing Zhao 		    void *src, unsigned int size)
37884c406e7SOri Kam {
37984c406e7SOri Kam 	void *dst;
38084c406e7SOri Kam 
3814a78c88eSYongseok Koh 	if (!verbs)
3824a78c88eSYongseok Koh 		return;
3838e46d4e1SAlexander Kozyrev 	MLX5_ASSERT(verbs->specs);
38484c406e7SOri Kam 	dst = (void *)(verbs->specs + verbs->size);
38584c406e7SOri Kam 	memcpy(dst, src, size);
386e7bfa359SBing Zhao 	++verbs->attr.num_of_specs;
38784c406e7SOri Kam 	verbs->size += size;
38884c406e7SOri Kam }
38984c406e7SOri Kam 
39084c406e7SOri Kam /**
39184c406e7SOri Kam  * Convert the @p item into a Verbs specification. This function assumes that
39284c406e7SOri Kam  * the input is valid and that there is space to insert the requested item
39384c406e7SOri Kam  * into the flow.
39484c406e7SOri Kam  *
3954a78c88eSYongseok Koh  * @param[in, out] dev_flow
3964a78c88eSYongseok Koh  *   Pointer to dev_flow structure.
39784c406e7SOri Kam  * @param[in] item
39884c406e7SOri Kam  *   Item specification.
39984c406e7SOri Kam  * @param[in] item_flags
4004a78c88eSYongseok Koh  *   Parsed item flags.
40184c406e7SOri Kam  */
40284c406e7SOri Kam static void
4034a78c88eSYongseok Koh flow_verbs_translate_item_eth(struct mlx5_flow *dev_flow,
4044a78c88eSYongseok Koh 			      const struct rte_flow_item *item,
4054a78c88eSYongseok Koh 			      uint64_t item_flags)
40684c406e7SOri Kam {
40784c406e7SOri Kam 	const struct rte_flow_item_eth *spec = item->spec;
40884c406e7SOri Kam 	const struct rte_flow_item_eth *mask = item->mask;
40984c406e7SOri Kam 	const unsigned int size = sizeof(struct ibv_flow_spec_eth);
41084c406e7SOri Kam 	struct ibv_flow_spec_eth eth = {
4114a78c88eSYongseok Koh 		.type = IBV_FLOW_SPEC_ETH | VERBS_SPEC_INNER(item_flags),
41284c406e7SOri Kam 		.size = size,
41384c406e7SOri Kam 	};
41484c406e7SOri Kam 
41584c406e7SOri Kam 	if (!mask)
41684c406e7SOri Kam 		mask = &rte_flow_item_eth_mask;
41784c406e7SOri Kam 	if (spec) {
41884c406e7SOri Kam 		unsigned int i;
41984c406e7SOri Kam 
42035b2d13fSOlivier Matz 		memcpy(&eth.val.dst_mac, spec->dst.addr_bytes,
42135b2d13fSOlivier Matz 			RTE_ETHER_ADDR_LEN);
42235b2d13fSOlivier Matz 		memcpy(&eth.val.src_mac, spec->src.addr_bytes,
42335b2d13fSOlivier Matz 			RTE_ETHER_ADDR_LEN);
42484c406e7SOri Kam 		eth.val.ether_type = spec->type;
42535b2d13fSOlivier Matz 		memcpy(&eth.mask.dst_mac, mask->dst.addr_bytes,
42635b2d13fSOlivier Matz 			RTE_ETHER_ADDR_LEN);
42735b2d13fSOlivier Matz 		memcpy(&eth.mask.src_mac, mask->src.addr_bytes,
42835b2d13fSOlivier Matz 			RTE_ETHER_ADDR_LEN);
42984c406e7SOri Kam 		eth.mask.ether_type = mask->type;
43084c406e7SOri Kam 		/* Remove unwanted bits from values. */
43135b2d13fSOlivier Matz 		for (i = 0; i < RTE_ETHER_ADDR_LEN; ++i) {
43284c406e7SOri Kam 			eth.val.dst_mac[i] &= eth.mask.dst_mac[i];
43384c406e7SOri Kam 			eth.val.src_mac[i] &= eth.mask.src_mac[i];
43484c406e7SOri Kam 		}
43584c406e7SOri Kam 		eth.val.ether_type &= eth.mask.ether_type;
43684c406e7SOri Kam 	}
4374a78c88eSYongseok Koh 	flow_verbs_spec_add(&dev_flow->verbs, &eth, size);
43884c406e7SOri Kam }
43984c406e7SOri Kam 
44084c406e7SOri Kam /**
44184c406e7SOri Kam  * Update the VLAN tag in the Verbs Ethernet specification.
44284c406e7SOri Kam  * This function assumes that the input is valid and there is space to add
44384c406e7SOri Kam  * the requested item.
44484c406e7SOri Kam  *
44584c406e7SOri Kam  * @param[in, out] attr
44684c406e7SOri Kam  *   Pointer to Verbs attributes structure.
44784c406e7SOri Kam  * @param[in] eth
44884c406e7SOri Kam  *   Verbs structure containing the VLAN information to copy.
44984c406e7SOri Kam  */
45084c406e7SOri Kam static void
45184c406e7SOri Kam flow_verbs_item_vlan_update(struct ibv_flow_attr *attr,
45284c406e7SOri Kam 			    struct ibv_flow_spec_eth *eth)
45384c406e7SOri Kam {
45484c406e7SOri Kam 	unsigned int i;
45584c406e7SOri Kam 	const enum ibv_flow_spec_type search = eth->type;
45684c406e7SOri Kam 	struct ibv_spec_header *hdr = (struct ibv_spec_header *)
45784c406e7SOri Kam 		((uint8_t *)attr + sizeof(struct ibv_flow_attr));
45884c406e7SOri Kam 
45984c406e7SOri Kam 	for (i = 0; i != attr->num_of_specs; ++i) {
46084c406e7SOri Kam 		if (hdr->type == search) {
46184c406e7SOri Kam 			struct ibv_flow_spec_eth *e =
46284c406e7SOri Kam 				(struct ibv_flow_spec_eth *)hdr;
46384c406e7SOri Kam 
46484c406e7SOri Kam 			e->val.vlan_tag = eth->val.vlan_tag;
46584c406e7SOri Kam 			e->mask.vlan_tag = eth->mask.vlan_tag;
46684c406e7SOri Kam 			e->val.ether_type = eth->val.ether_type;
46784c406e7SOri Kam 			e->mask.ether_type = eth->mask.ether_type;
46884c406e7SOri Kam 			break;
46984c406e7SOri Kam 		}
47084c406e7SOri Kam 		hdr = (struct ibv_spec_header *)((uint8_t *)hdr + hdr->size);
47184c406e7SOri Kam 	}
47284c406e7SOri Kam }
47384c406e7SOri Kam 
47484c406e7SOri Kam /**
47584c406e7SOri Kam  * Convert the @p item into a Verbs specification. This function assumes that
47684c406e7SOri Kam  * the input is valid and that there is space to insert the requested item
47784c406e7SOri Kam  * into the flow.
47884c406e7SOri Kam  *
47984c406e7SOri Kam  * @param[in, out] dev_flow
48084c406e7SOri Kam  *   Pointer to dev_flow structure.
4814a78c88eSYongseok Koh  * @param[in] item
4824a78c88eSYongseok Koh  *   Item specification.
4834a78c88eSYongseok Koh  * @param[in] item_flags
4844a78c88eSYongseok Koh  *   Parsed item flags.
48584c406e7SOri Kam  */
48684c406e7SOri Kam static void
4874a78c88eSYongseok Koh flow_verbs_translate_item_vlan(struct mlx5_flow *dev_flow,
4884a78c88eSYongseok Koh 			       const struct rte_flow_item *item,
4894a78c88eSYongseok Koh 			       uint64_t item_flags)
49084c406e7SOri Kam {
49184c406e7SOri Kam 	const struct rte_flow_item_vlan *spec = item->spec;
49284c406e7SOri Kam 	const struct rte_flow_item_vlan *mask = item->mask;
49384c406e7SOri Kam 	unsigned int size = sizeof(struct ibv_flow_spec_eth);
4944a78c88eSYongseok Koh 	const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
49584c406e7SOri Kam 	struct ibv_flow_spec_eth eth = {
4964a78c88eSYongseok Koh 		.type = IBV_FLOW_SPEC_ETH | VERBS_SPEC_INNER(item_flags),
49784c406e7SOri Kam 		.size = size,
49884c406e7SOri Kam 	};
49984c406e7SOri Kam 	const uint32_t l2m = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
50084c406e7SOri Kam 				      MLX5_FLOW_LAYER_OUTER_L2;
50184c406e7SOri Kam 
50284c406e7SOri Kam 	if (!mask)
50384c406e7SOri Kam 		mask = &rte_flow_item_vlan_mask;
50484c406e7SOri Kam 	if (spec) {
50584c406e7SOri Kam 		eth.val.vlan_tag = spec->tci;
50684c406e7SOri Kam 		eth.mask.vlan_tag = mask->tci;
50784c406e7SOri Kam 		eth.val.vlan_tag &= eth.mask.vlan_tag;
50884c406e7SOri Kam 		eth.val.ether_type = spec->inner_type;
50984c406e7SOri Kam 		eth.mask.ether_type = mask->inner_type;
51084c406e7SOri Kam 		eth.val.ether_type &= eth.mask.ether_type;
51184c406e7SOri Kam 	}
5124a78c88eSYongseok Koh 	if (!(item_flags & l2m))
5134a78c88eSYongseok Koh 		flow_verbs_spec_add(&dev_flow->verbs, &eth, size);
5144a78c88eSYongseok Koh 	else
515e7bfa359SBing Zhao 		flow_verbs_item_vlan_update(&dev_flow->verbs.attr, &eth);
516dfedf3e3SViacheslav Ovsiienko 	if (!tunnel)
517e7bfa359SBing Zhao 		dev_flow->handle->vf_vlan.tag =
518dfedf3e3SViacheslav Ovsiienko 			rte_be_to_cpu_16(spec->tci) & 0x0fff;
51984c406e7SOri Kam }
52084c406e7SOri Kam 
52184c406e7SOri Kam /**
52284c406e7SOri Kam  * Convert the @p item into a Verbs specification. This function assumes that
52384c406e7SOri Kam  * the input is valid and that there is space to insert the requested item
52484c406e7SOri Kam  * into the flow.
52584c406e7SOri Kam  *
5264a78c88eSYongseok Koh  * @param[in, out] dev_flow
5274a78c88eSYongseok Koh  *   Pointer to dev_flow structure.
52884c406e7SOri Kam  * @param[in] item
52984c406e7SOri Kam  *   Item specification.
5304a78c88eSYongseok Koh  * @param[in] item_flags
5314a78c88eSYongseok Koh  *   Parsed item flags.
53284c406e7SOri Kam  */
53384c406e7SOri Kam static void
5344a78c88eSYongseok Koh flow_verbs_translate_item_ipv4(struct mlx5_flow *dev_flow,
5354a78c88eSYongseok Koh 			       const struct rte_flow_item *item,
5364a78c88eSYongseok Koh 			       uint64_t item_flags)
53784c406e7SOri Kam {
53884c406e7SOri Kam 	const struct rte_flow_item_ipv4 *spec = item->spec;
53984c406e7SOri Kam 	const struct rte_flow_item_ipv4 *mask = item->mask;
54084c406e7SOri Kam 	unsigned int size = sizeof(struct ibv_flow_spec_ipv4_ext);
54184c406e7SOri Kam 	struct ibv_flow_spec_ipv4_ext ipv4 = {
5424a78c88eSYongseok Koh 		.type = IBV_FLOW_SPEC_IPV4_EXT | VERBS_SPEC_INNER(item_flags),
54384c406e7SOri Kam 		.size = size,
54484c406e7SOri Kam 	};
54584c406e7SOri Kam 
54684c406e7SOri Kam 	if (!mask)
54784c406e7SOri Kam 		mask = &rte_flow_item_ipv4_mask;
54884c406e7SOri Kam 	if (spec) {
54984c406e7SOri Kam 		ipv4.val = (struct ibv_flow_ipv4_ext_filter){
55084c406e7SOri Kam 			.src_ip = spec->hdr.src_addr,
55184c406e7SOri Kam 			.dst_ip = spec->hdr.dst_addr,
55284c406e7SOri Kam 			.proto = spec->hdr.next_proto_id,
55384c406e7SOri Kam 			.tos = spec->hdr.type_of_service,
55484c406e7SOri Kam 		};
55584c406e7SOri Kam 		ipv4.mask = (struct ibv_flow_ipv4_ext_filter){
55684c406e7SOri Kam 			.src_ip = mask->hdr.src_addr,
55784c406e7SOri Kam 			.dst_ip = mask->hdr.dst_addr,
55884c406e7SOri Kam 			.proto = mask->hdr.next_proto_id,
55984c406e7SOri Kam 			.tos = mask->hdr.type_of_service,
56084c406e7SOri Kam 		};
56184c406e7SOri Kam 		/* Remove unwanted bits from values. */
56284c406e7SOri Kam 		ipv4.val.src_ip &= ipv4.mask.src_ip;
56384c406e7SOri Kam 		ipv4.val.dst_ip &= ipv4.mask.dst_ip;
56484c406e7SOri Kam 		ipv4.val.proto &= ipv4.mask.proto;
56584c406e7SOri Kam 		ipv4.val.tos &= ipv4.mask.tos;
56684c406e7SOri Kam 	}
5674a78c88eSYongseok Koh 	flow_verbs_spec_add(&dev_flow->verbs, &ipv4, size);
56884c406e7SOri Kam }
56984c406e7SOri Kam 
57084c406e7SOri Kam /**
57184c406e7SOri Kam  * Convert the @p item into a Verbs specification. This function assumes that
57284c406e7SOri Kam  * the input is valid and that there is space to insert the requested item
57384c406e7SOri Kam  * into the flow.
57484c406e7SOri Kam  *
5754a78c88eSYongseok Koh  * @param[in, out] dev_flow
5764a78c88eSYongseok Koh  *   Pointer to dev_flow structure.
57784c406e7SOri Kam  * @param[in] item
57884c406e7SOri Kam  *   Item specification.
5794a78c88eSYongseok Koh  * @param[in] item_flags
5804a78c88eSYongseok Koh  *   Parsed item flags.
58184c406e7SOri Kam  */
58284c406e7SOri Kam static void
5834a78c88eSYongseok Koh flow_verbs_translate_item_ipv6(struct mlx5_flow *dev_flow,
5844a78c88eSYongseok Koh 			       const struct rte_flow_item *item,
5854a78c88eSYongseok Koh 			       uint64_t item_flags)
58684c406e7SOri Kam {
58784c406e7SOri Kam 	const struct rte_flow_item_ipv6 *spec = item->spec;
58884c406e7SOri Kam 	const struct rte_flow_item_ipv6 *mask = item->mask;
58984c406e7SOri Kam 	unsigned int size = sizeof(struct ibv_flow_spec_ipv6);
59084c406e7SOri Kam 	struct ibv_flow_spec_ipv6 ipv6 = {
5914a78c88eSYongseok Koh 		.type = IBV_FLOW_SPEC_IPV6 | VERBS_SPEC_INNER(item_flags),
59284c406e7SOri Kam 		.size = size,
59384c406e7SOri Kam 	};
59484c406e7SOri Kam 
59584c406e7SOri Kam 	if (!mask)
59684c406e7SOri Kam 		mask = &rte_flow_item_ipv6_mask;
59784c406e7SOri Kam 	if (spec) {
59884c406e7SOri Kam 		unsigned int i;
59984c406e7SOri Kam 		uint32_t vtc_flow_val;
60084c406e7SOri Kam 		uint32_t vtc_flow_mask;
60184c406e7SOri Kam 
60284c406e7SOri Kam 		memcpy(&ipv6.val.src_ip, spec->hdr.src_addr,
60384c406e7SOri Kam 		       RTE_DIM(ipv6.val.src_ip));
60484c406e7SOri Kam 		memcpy(&ipv6.val.dst_ip, spec->hdr.dst_addr,
60584c406e7SOri Kam 		       RTE_DIM(ipv6.val.dst_ip));
60684c406e7SOri Kam 		memcpy(&ipv6.mask.src_ip, mask->hdr.src_addr,
60784c406e7SOri Kam 		       RTE_DIM(ipv6.mask.src_ip));
60884c406e7SOri Kam 		memcpy(&ipv6.mask.dst_ip, mask->hdr.dst_addr,
60984c406e7SOri Kam 		       RTE_DIM(ipv6.mask.dst_ip));
61084c406e7SOri Kam 		vtc_flow_val = rte_be_to_cpu_32(spec->hdr.vtc_flow);
61184c406e7SOri Kam 		vtc_flow_mask = rte_be_to_cpu_32(mask->hdr.vtc_flow);
61284c406e7SOri Kam 		ipv6.val.flow_label =
61324ac604eSOlivier Matz 			rte_cpu_to_be_32((vtc_flow_val & RTE_IPV6_HDR_FL_MASK) >>
61424ac604eSOlivier Matz 					 RTE_IPV6_HDR_FL_SHIFT);
61524ac604eSOlivier Matz 		ipv6.val.traffic_class = (vtc_flow_val & RTE_IPV6_HDR_TC_MASK) >>
61624ac604eSOlivier Matz 					 RTE_IPV6_HDR_TC_SHIFT;
61784c406e7SOri Kam 		ipv6.val.next_hdr = spec->hdr.proto;
61884c406e7SOri Kam 		ipv6.mask.flow_label =
61924ac604eSOlivier Matz 			rte_cpu_to_be_32((vtc_flow_mask & RTE_IPV6_HDR_FL_MASK) >>
62024ac604eSOlivier Matz 					 RTE_IPV6_HDR_FL_SHIFT);
62124ac604eSOlivier Matz 		ipv6.mask.traffic_class = (vtc_flow_mask & RTE_IPV6_HDR_TC_MASK) >>
62224ac604eSOlivier Matz 					  RTE_IPV6_HDR_TC_SHIFT;
62384c406e7SOri Kam 		ipv6.mask.next_hdr = mask->hdr.proto;
62484c406e7SOri Kam 		/* Remove unwanted bits from values. */
62584c406e7SOri Kam 		for (i = 0; i < RTE_DIM(ipv6.val.src_ip); ++i) {
62684c406e7SOri Kam 			ipv6.val.src_ip[i] &= ipv6.mask.src_ip[i];
62784c406e7SOri Kam 			ipv6.val.dst_ip[i] &= ipv6.mask.dst_ip[i];
62884c406e7SOri Kam 		}
62984c406e7SOri Kam 		ipv6.val.flow_label &= ipv6.mask.flow_label;
63084c406e7SOri Kam 		ipv6.val.traffic_class &= ipv6.mask.traffic_class;
63184c406e7SOri Kam 		ipv6.val.next_hdr &= ipv6.mask.next_hdr;
63284c406e7SOri Kam 	}
6334a78c88eSYongseok Koh 	flow_verbs_spec_add(&dev_flow->verbs, &ipv6, size);
63484c406e7SOri Kam }
63584c406e7SOri Kam 
63684c406e7SOri Kam /**
63784c406e7SOri Kam  * Convert the @p item into a Verbs specification. This function assumes that
63884c406e7SOri Kam  * the input is valid and that there is space to insert the requested item
63984c406e7SOri Kam  * into the flow.
64084c406e7SOri Kam  *
6414a78c88eSYongseok Koh  * @param[in, out] dev_flow
6424a78c88eSYongseok Koh  *   Pointer to dev_flow structure.
64384c406e7SOri Kam  * @param[in] item
64484c406e7SOri Kam  *   Item specification.
6454a78c88eSYongseok Koh  * @param[in] item_flags
6464a78c88eSYongseok Koh  *   Parsed item flags.
64784c406e7SOri Kam  */
64884c406e7SOri Kam static void
6494a78c88eSYongseok Koh flow_verbs_translate_item_tcp(struct mlx5_flow *dev_flow,
6504a78c88eSYongseok Koh 			      const struct rte_flow_item *item,
6514a78c88eSYongseok Koh 			      uint64_t item_flags __rte_unused)
65284c406e7SOri Kam {
65384c406e7SOri Kam 	const struct rte_flow_item_tcp *spec = item->spec;
65484c406e7SOri Kam 	const struct rte_flow_item_tcp *mask = item->mask;
65584c406e7SOri Kam 	unsigned int size = sizeof(struct ibv_flow_spec_tcp_udp);
65684c406e7SOri Kam 	struct ibv_flow_spec_tcp_udp tcp = {
6574a78c88eSYongseok Koh 		.type = IBV_FLOW_SPEC_TCP | VERBS_SPEC_INNER(item_flags),
65884c406e7SOri Kam 		.size = size,
65984c406e7SOri Kam 	};
66084c406e7SOri Kam 
66184c406e7SOri Kam 	if (!mask)
66284c406e7SOri Kam 		mask = &rte_flow_item_tcp_mask;
66384c406e7SOri Kam 	if (spec) {
66484c406e7SOri Kam 		tcp.val.dst_port = spec->hdr.dst_port;
66584c406e7SOri Kam 		tcp.val.src_port = spec->hdr.src_port;
66684c406e7SOri Kam 		tcp.mask.dst_port = mask->hdr.dst_port;
66784c406e7SOri Kam 		tcp.mask.src_port = mask->hdr.src_port;
66884c406e7SOri Kam 		/* Remove unwanted bits from values. */
66984c406e7SOri Kam 		tcp.val.src_port &= tcp.mask.src_port;
67084c406e7SOri Kam 		tcp.val.dst_port &= tcp.mask.dst_port;
67184c406e7SOri Kam 	}
6724a78c88eSYongseok Koh 	flow_verbs_spec_add(&dev_flow->verbs, &tcp, size);
67384c406e7SOri Kam }
67484c406e7SOri Kam 
67584c406e7SOri Kam /**
67684c406e7SOri Kam  * Convert the @p item into a Verbs specification. This function assumes that
67784c406e7SOri Kam  * the input is valid and that there is space to insert the requested item
67884c406e7SOri Kam  * into the flow.
67984c406e7SOri Kam  *
6804a78c88eSYongseok Koh  * @param[in, out] dev_flow
6814a78c88eSYongseok Koh  *   Pointer to dev_flow structure.
68284c406e7SOri Kam  * @param[in] item
68384c406e7SOri Kam  *   Item specification.
6844a78c88eSYongseok Koh  * @param[in] item_flags
6854a78c88eSYongseok Koh  *   Parsed item flags.
68684c406e7SOri Kam  */
68784c406e7SOri Kam static void
6884a78c88eSYongseok Koh flow_verbs_translate_item_udp(struct mlx5_flow *dev_flow,
6894a78c88eSYongseok Koh 			      const struct rte_flow_item *item,
6904a78c88eSYongseok Koh 			      uint64_t item_flags __rte_unused)
6914a78c88eSYongseok Koh {
6924a78c88eSYongseok Koh 	const struct rte_flow_item_udp *spec = item->spec;
6934a78c88eSYongseok Koh 	const struct rte_flow_item_udp *mask = item->mask;
6944a78c88eSYongseok Koh 	unsigned int size = sizeof(struct ibv_flow_spec_tcp_udp);
6954a78c88eSYongseok Koh 	struct ibv_flow_spec_tcp_udp udp = {
6964a78c88eSYongseok Koh 		.type = IBV_FLOW_SPEC_UDP | VERBS_SPEC_INNER(item_flags),
6974a78c88eSYongseok Koh 		.size = size,
6984a78c88eSYongseok Koh 	};
6994a78c88eSYongseok Koh 
7004a78c88eSYongseok Koh 	if (!mask)
7014a78c88eSYongseok Koh 		mask = &rte_flow_item_udp_mask;
7024a78c88eSYongseok Koh 	if (spec) {
7034a78c88eSYongseok Koh 		udp.val.dst_port = spec->hdr.dst_port;
7044a78c88eSYongseok Koh 		udp.val.src_port = spec->hdr.src_port;
7054a78c88eSYongseok Koh 		udp.mask.dst_port = mask->hdr.dst_port;
7064a78c88eSYongseok Koh 		udp.mask.src_port = mask->hdr.src_port;
7074a78c88eSYongseok Koh 		/* Remove unwanted bits from values. */
7084a78c88eSYongseok Koh 		udp.val.src_port &= udp.mask.src_port;
7094a78c88eSYongseok Koh 		udp.val.dst_port &= udp.mask.dst_port;
7104a78c88eSYongseok Koh 	}
7118a2e026aSRaslan Darawsheh 	item++;
7128a2e026aSRaslan Darawsheh 	while (item->type == RTE_FLOW_ITEM_TYPE_VOID)
7138a2e026aSRaslan Darawsheh 		item++;
7148a2e026aSRaslan Darawsheh 	if (!(udp.val.dst_port & udp.mask.dst_port)) {
7158a2e026aSRaslan Darawsheh 		switch ((item)->type) {
7168a2e026aSRaslan Darawsheh 		case RTE_FLOW_ITEM_TYPE_VXLAN:
7178a2e026aSRaslan Darawsheh 			udp.val.dst_port = htons(MLX5_UDP_PORT_VXLAN);
7188a2e026aSRaslan Darawsheh 			udp.mask.dst_port = 0xffff;
7198a2e026aSRaslan Darawsheh 			break;
7208a2e026aSRaslan Darawsheh 		case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
7218a2e026aSRaslan Darawsheh 			udp.val.dst_port = htons(MLX5_UDP_PORT_VXLAN_GPE);
7228a2e026aSRaslan Darawsheh 			udp.mask.dst_port = 0xffff;
7238a2e026aSRaslan Darawsheh 			break;
7248a2e026aSRaslan Darawsheh 		case RTE_FLOW_ITEM_TYPE_MPLS:
7258a2e026aSRaslan Darawsheh 			udp.val.dst_port = htons(MLX5_UDP_PORT_MPLS);
7268a2e026aSRaslan Darawsheh 			udp.mask.dst_port = 0xffff;
7278a2e026aSRaslan Darawsheh 			break;
7288a2e026aSRaslan Darawsheh 		default:
7298a2e026aSRaslan Darawsheh 			break;
7308a2e026aSRaslan Darawsheh 		}
7318a2e026aSRaslan Darawsheh 	}
7328a2e026aSRaslan Darawsheh 
7334a78c88eSYongseok Koh 	flow_verbs_spec_add(&dev_flow->verbs, &udp, size);
7344a78c88eSYongseok Koh }
7354a78c88eSYongseok Koh 
7364a78c88eSYongseok Koh /**
7374a78c88eSYongseok Koh  * Convert the @p item into a Verbs specification. This function assumes that
7384a78c88eSYongseok Koh  * the input is valid and that there is space to insert the requested item
7394a78c88eSYongseok Koh  * into the flow.
7404a78c88eSYongseok Koh  *
7414a78c88eSYongseok Koh  * @param[in, out] dev_flow
7424a78c88eSYongseok Koh  *   Pointer to dev_flow structure.
7434a78c88eSYongseok Koh  * @param[in] item
7444a78c88eSYongseok Koh  *   Item specification.
7454a78c88eSYongseok Koh  * @param[in] item_flags
7464a78c88eSYongseok Koh  *   Parsed item flags.
7474a78c88eSYongseok Koh  */
7484a78c88eSYongseok Koh static void
7494a78c88eSYongseok Koh flow_verbs_translate_item_vxlan(struct mlx5_flow *dev_flow,
7504a78c88eSYongseok Koh 				const struct rte_flow_item *item,
7514a78c88eSYongseok Koh 				uint64_t item_flags __rte_unused)
75284c406e7SOri Kam {
75384c406e7SOri Kam 	const struct rte_flow_item_vxlan *spec = item->spec;
75484c406e7SOri Kam 	const struct rte_flow_item_vxlan *mask = item->mask;
75584c406e7SOri Kam 	unsigned int size = sizeof(struct ibv_flow_spec_tunnel);
75684c406e7SOri Kam 	struct ibv_flow_spec_tunnel vxlan = {
75784c406e7SOri Kam 		.type = IBV_FLOW_SPEC_VXLAN_TUNNEL,
75884c406e7SOri Kam 		.size = size,
75984c406e7SOri Kam 	};
76084c406e7SOri Kam 	union vni {
76184c406e7SOri Kam 		uint32_t vlan_id;
76284c406e7SOri Kam 		uint8_t vni[4];
76384c406e7SOri Kam 	} id = { .vlan_id = 0, };
76484c406e7SOri Kam 
76584c406e7SOri Kam 	if (!mask)
76684c406e7SOri Kam 		mask = &rte_flow_item_vxlan_mask;
76784c406e7SOri Kam 	if (spec) {
76884c406e7SOri Kam 		memcpy(&id.vni[1], spec->vni, 3);
76984c406e7SOri Kam 		vxlan.val.tunnel_id = id.vlan_id;
77084c406e7SOri Kam 		memcpy(&id.vni[1], mask->vni, 3);
77184c406e7SOri Kam 		vxlan.mask.tunnel_id = id.vlan_id;
77284c406e7SOri Kam 		/* Remove unwanted bits from values. */
77384c406e7SOri Kam 		vxlan.val.tunnel_id &= vxlan.mask.tunnel_id;
77484c406e7SOri Kam 	}
7754a78c88eSYongseok Koh 	flow_verbs_spec_add(&dev_flow->verbs, &vxlan, size);
77684c406e7SOri Kam }
77784c406e7SOri Kam 
77884c406e7SOri Kam /**
77984c406e7SOri Kam  * Convert the @p item into a Verbs specification. This function assumes that
78084c406e7SOri Kam  * the input is valid and that there is space to insert the requested item
78184c406e7SOri Kam  * into the flow.
78284c406e7SOri Kam  *
7834a78c88eSYongseok Koh  * @param[in, out] dev_flow
7844a78c88eSYongseok Koh  *   Pointer to dev_flow structure.
78584c406e7SOri Kam  * @param[in] item
78684c406e7SOri Kam  *   Item specification.
7874a78c88eSYongseok Koh  * @param[in] item_flags
7884a78c88eSYongseok Koh  *   Parsed item flags.
78984c406e7SOri Kam  */
79084c406e7SOri Kam static void
7914a78c88eSYongseok Koh flow_verbs_translate_item_vxlan_gpe(struct mlx5_flow *dev_flow,
7924a78c88eSYongseok Koh 				    const struct rte_flow_item *item,
7934a78c88eSYongseok Koh 				    uint64_t item_flags __rte_unused)
79484c406e7SOri Kam {
79584c406e7SOri Kam 	const struct rte_flow_item_vxlan_gpe *spec = item->spec;
79684c406e7SOri Kam 	const struct rte_flow_item_vxlan_gpe *mask = item->mask;
79784c406e7SOri Kam 	unsigned int size = sizeof(struct ibv_flow_spec_tunnel);
79884c406e7SOri Kam 	struct ibv_flow_spec_tunnel vxlan_gpe = {
79984c406e7SOri Kam 		.type = IBV_FLOW_SPEC_VXLAN_TUNNEL,
80084c406e7SOri Kam 		.size = size,
80184c406e7SOri Kam 	};
80284c406e7SOri Kam 	union vni {
80384c406e7SOri Kam 		uint32_t vlan_id;
80484c406e7SOri Kam 		uint8_t vni[4];
80584c406e7SOri Kam 	} id = { .vlan_id = 0, };
80684c406e7SOri Kam 
80784c406e7SOri Kam 	if (!mask)
80884c406e7SOri Kam 		mask = &rte_flow_item_vxlan_gpe_mask;
80984c406e7SOri Kam 	if (spec) {
81084c406e7SOri Kam 		memcpy(&id.vni[1], spec->vni, 3);
81184c406e7SOri Kam 		vxlan_gpe.val.tunnel_id = id.vlan_id;
81284c406e7SOri Kam 		memcpy(&id.vni[1], mask->vni, 3);
81384c406e7SOri Kam 		vxlan_gpe.mask.tunnel_id = id.vlan_id;
81484c406e7SOri Kam 		/* Remove unwanted bits from values. */
81584c406e7SOri Kam 		vxlan_gpe.val.tunnel_id &= vxlan_gpe.mask.tunnel_id;
81684c406e7SOri Kam 	}
8174a78c88eSYongseok Koh 	flow_verbs_spec_add(&dev_flow->verbs, &vxlan_gpe, size);
81884c406e7SOri Kam }
81984c406e7SOri Kam 
82084c406e7SOri Kam /**
82184c406e7SOri Kam  * Update the protocol in Verbs IPv4/IPv6 spec.
82284c406e7SOri Kam  *
82384c406e7SOri Kam  * @param[in, out] attr
82484c406e7SOri Kam  *   Pointer to Verbs attributes structure.
82584c406e7SOri Kam  * @param[in] search
82684c406e7SOri Kam  *   Specification type to search in order to update the IP protocol.
82784c406e7SOri Kam  * @param[in] protocol
82884c406e7SOri Kam  *   Protocol value to set if none is present in the specification.
82984c406e7SOri Kam  */
83084c406e7SOri Kam static void
83184c406e7SOri Kam flow_verbs_item_gre_ip_protocol_update(struct ibv_flow_attr *attr,
83284c406e7SOri Kam 				       enum ibv_flow_spec_type search,
83384c406e7SOri Kam 				       uint8_t protocol)
83484c406e7SOri Kam {
83584c406e7SOri Kam 	unsigned int i;
83684c406e7SOri Kam 	struct ibv_spec_header *hdr = (struct ibv_spec_header *)
83784c406e7SOri Kam 		((uint8_t *)attr + sizeof(struct ibv_flow_attr));
83884c406e7SOri Kam 
83984c406e7SOri Kam 	if (!attr)
84084c406e7SOri Kam 		return;
84184c406e7SOri Kam 	for (i = 0; i != attr->num_of_specs; ++i) {
84284c406e7SOri Kam 		if (hdr->type == search) {
84384c406e7SOri Kam 			union {
84484c406e7SOri Kam 				struct ibv_flow_spec_ipv4_ext *ipv4;
84584c406e7SOri Kam 				struct ibv_flow_spec_ipv6 *ipv6;
84684c406e7SOri Kam 			} ip;
84784c406e7SOri Kam 
84884c406e7SOri Kam 			switch (search) {
84984c406e7SOri Kam 			case IBV_FLOW_SPEC_IPV4_EXT:
85084c406e7SOri Kam 				ip.ipv4 = (struct ibv_flow_spec_ipv4_ext *)hdr;
85184c406e7SOri Kam 				if (!ip.ipv4->val.proto) {
85284c406e7SOri Kam 					ip.ipv4->val.proto = protocol;
85384c406e7SOri Kam 					ip.ipv4->mask.proto = 0xff;
85484c406e7SOri Kam 				}
85584c406e7SOri Kam 				break;
85684c406e7SOri Kam 			case IBV_FLOW_SPEC_IPV6:
85784c406e7SOri Kam 				ip.ipv6 = (struct ibv_flow_spec_ipv6 *)hdr;
85884c406e7SOri Kam 				if (!ip.ipv6->val.next_hdr) {
85984c406e7SOri Kam 					ip.ipv6->val.next_hdr = protocol;
86084c406e7SOri Kam 					ip.ipv6->mask.next_hdr = 0xff;
86184c406e7SOri Kam 				}
86284c406e7SOri Kam 				break;
86384c406e7SOri Kam 			default:
86484c406e7SOri Kam 				break;
86584c406e7SOri Kam 			}
86684c406e7SOri Kam 			break;
86784c406e7SOri Kam 		}
86884c406e7SOri Kam 		hdr = (struct ibv_spec_header *)((uint8_t *)hdr + hdr->size);
86984c406e7SOri Kam 	}
87084c406e7SOri Kam }
87184c406e7SOri Kam 
87284c406e7SOri Kam /**
87398008ce6SDariusz Sosnowski  * Reserve space for GRE spec in spec buffer.
87484c406e7SOri Kam  *
8754a78c88eSYongseok Koh  * @param[in,out] dev_flow
8764a78c88eSYongseok Koh  *   Pointer to dev_flow structure.
87798008ce6SDariusz Sosnowski  *
87898008ce6SDariusz Sosnowski  * @return
87998008ce6SDariusz Sosnowski  *   Pointer to reserved space in spec buffer.
88098008ce6SDariusz Sosnowski  */
88198008ce6SDariusz Sosnowski static uint8_t *
88298008ce6SDariusz Sosnowski flow_verbs_reserve_gre(struct mlx5_flow *dev_flow)
88398008ce6SDariusz Sosnowski {
88498008ce6SDariusz Sosnowski 	uint8_t *buffer;
88598008ce6SDariusz Sosnowski 	struct mlx5_flow_verbs_workspace *verbs = &dev_flow->verbs;
88698008ce6SDariusz Sosnowski #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
88798008ce6SDariusz Sosnowski 	unsigned int size = sizeof(struct ibv_flow_spec_tunnel);
88898008ce6SDariusz Sosnowski 	struct ibv_flow_spec_tunnel tunnel = {
88998008ce6SDariusz Sosnowski 		.type = IBV_FLOW_SPEC_VXLAN_TUNNEL,
89098008ce6SDariusz Sosnowski 		.size = size,
89198008ce6SDariusz Sosnowski 	};
89298008ce6SDariusz Sosnowski #else
89398008ce6SDariusz Sosnowski 	unsigned int size = sizeof(struct ibv_flow_spec_gre);
89498008ce6SDariusz Sosnowski 	struct ibv_flow_spec_gre tunnel = {
89598008ce6SDariusz Sosnowski 		.type = IBV_FLOW_SPEC_GRE,
89698008ce6SDariusz Sosnowski 		.size = size,
89798008ce6SDariusz Sosnowski 	};
89898008ce6SDariusz Sosnowski #endif
89998008ce6SDariusz Sosnowski 
90098008ce6SDariusz Sosnowski 	buffer = verbs->specs + verbs->size;
90198008ce6SDariusz Sosnowski 	flow_verbs_spec_add(verbs, &tunnel, size);
90298008ce6SDariusz Sosnowski 	return buffer;
90398008ce6SDariusz Sosnowski }
90498008ce6SDariusz Sosnowski 
90598008ce6SDariusz Sosnowski /**
90698008ce6SDariusz Sosnowski  * Convert the @p item into a Verbs specification. This function assumes that
90798008ce6SDariusz Sosnowski  * the input is valid and that Verbs specification will be placed in
90898008ce6SDariusz Sosnowski  * the pre-reserved space.
90998008ce6SDariusz Sosnowski  *
91098008ce6SDariusz Sosnowski  * @param[in, out] dev_flow
91198008ce6SDariusz Sosnowski  *   Pointer to dev_flow structure.
91298008ce6SDariusz Sosnowski  * @param[in, out] gre_spec
91398008ce6SDariusz Sosnowski  *   Pointer to space reserved for GRE spec.
91484c406e7SOri Kam  * @param[in] item
91584c406e7SOri Kam  *   Item specification.
9164a78c88eSYongseok Koh  * @param[in] item_flags
9174a78c88eSYongseok Koh  *   Parsed item flags.
91884c406e7SOri Kam  */
91984c406e7SOri Kam static void
9204a78c88eSYongseok Koh flow_verbs_translate_item_gre(struct mlx5_flow *dev_flow,
92198008ce6SDariusz Sosnowski 			      uint8_t *gre_spec,
9224a78c88eSYongseok Koh 			      const struct rte_flow_item *item __rte_unused,
9234a78c88eSYongseok Koh 			      uint64_t item_flags)
92484c406e7SOri Kam {
925e7bfa359SBing Zhao 	struct mlx5_flow_verbs_workspace *verbs = &dev_flow->verbs;
92684c406e7SOri Kam #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
92784c406e7SOri Kam 	unsigned int size = sizeof(struct ibv_flow_spec_tunnel);
92884c406e7SOri Kam 	struct ibv_flow_spec_tunnel tunnel = {
92984c406e7SOri Kam 		.type = IBV_FLOW_SPEC_VXLAN_TUNNEL,
93084c406e7SOri Kam 		.size = size,
93184c406e7SOri Kam 	};
93284c406e7SOri Kam #else
933985b4792SGregory Etelson 	static const struct rte_flow_item_gre empty_gre = {0,};
93484c406e7SOri Kam 	const struct rte_flow_item_gre *spec = item->spec;
93584c406e7SOri Kam 	const struct rte_flow_item_gre *mask = item->mask;
93684c406e7SOri Kam 	unsigned int size = sizeof(struct ibv_flow_spec_gre);
93784c406e7SOri Kam 	struct ibv_flow_spec_gre tunnel = {
93884c406e7SOri Kam 		.type = IBV_FLOW_SPEC_GRE,
93984c406e7SOri Kam 		.size = size,
94084c406e7SOri Kam 	};
94184c406e7SOri Kam 
942985b4792SGregory Etelson 	if (!spec) {
943985b4792SGregory Etelson 		spec = &empty_gre;
944985b4792SGregory Etelson 		mask = &empty_gre;
945985b4792SGregory Etelson 	} else {
94684c406e7SOri Kam 		if (!mask)
94784c406e7SOri Kam 			mask = &rte_flow_item_gre_mask;
948985b4792SGregory Etelson 	}
94984c406e7SOri Kam 	tunnel.val.c_ks_res0_ver = spec->c_rsvd0_ver;
95084c406e7SOri Kam 	tunnel.val.protocol = spec->protocol;
95184c406e7SOri Kam 	tunnel.mask.c_ks_res0_ver = mask->c_rsvd0_ver;
95284c406e7SOri Kam 	tunnel.mask.protocol = mask->protocol;
95384c406e7SOri Kam 	/* Remove unwanted bits from values. */
95484c406e7SOri Kam 	tunnel.val.c_ks_res0_ver &= tunnel.mask.c_ks_res0_ver;
95584c406e7SOri Kam 	tunnel.val.key &= tunnel.mask.key;
956985b4792SGregory Etelson 	if (tunnel.mask.protocol) {
957985b4792SGregory Etelson 		tunnel.val.protocol &= tunnel.mask.protocol;
958985b4792SGregory Etelson 	} else {
959985b4792SGregory Etelson 		tunnel.val.protocol = mlx5_translate_tunnel_etypes(item_flags);
960985b4792SGregory Etelson 		if (tunnel.val.protocol) {
961985b4792SGregory Etelson 			tunnel.mask.protocol = 0xFFFF;
962985b4792SGregory Etelson 			tunnel.val.protocol =
963985b4792SGregory Etelson 				rte_cpu_to_be_16(tunnel.val.protocol);
964985b4792SGregory Etelson 		}
96584c406e7SOri Kam 	}
96684c406e7SOri Kam #endif
9674a78c88eSYongseok Koh 	if (item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV4)
968e7bfa359SBing Zhao 		flow_verbs_item_gre_ip_protocol_update(&verbs->attr,
96984c406e7SOri Kam 						       IBV_FLOW_SPEC_IPV4_EXT,
97084c406e7SOri Kam 						       IPPROTO_GRE);
97184c406e7SOri Kam 	else
972e7bfa359SBing Zhao 		flow_verbs_item_gre_ip_protocol_update(&verbs->attr,
97384c406e7SOri Kam 						       IBV_FLOW_SPEC_IPV6,
97484c406e7SOri Kam 						       IPPROTO_GRE);
97598008ce6SDariusz Sosnowski 	MLX5_ASSERT(gre_spec);
97698008ce6SDariusz Sosnowski 	memcpy(gre_spec, &tunnel, size);
97784c406e7SOri Kam }
97884c406e7SOri Kam 
97984c406e7SOri Kam /**
98084c406e7SOri Kam  * Convert the @p action into a Verbs specification. This function assumes that
98184c406e7SOri Kam  * the input is valid and that there is space to insert the requested action
98284c406e7SOri Kam  * into the flow. This function also return the action that was added.
98384c406e7SOri Kam  *
9844a78c88eSYongseok Koh  * @param[in, out] dev_flow
9854a78c88eSYongseok Koh  *   Pointer to dev_flow structure.
98684c406e7SOri Kam  * @param[in] item
98784c406e7SOri Kam  *   Item specification.
9884a78c88eSYongseok Koh  * @param[in] item_flags
9894a78c88eSYongseok Koh  *   Parsed item flags.
99084c406e7SOri Kam  */
99184c406e7SOri Kam static void
9924a78c88eSYongseok Koh flow_verbs_translate_item_mpls(struct mlx5_flow *dev_flow __rte_unused,
9934a78c88eSYongseok Koh 			       const struct rte_flow_item *item __rte_unused,
9944a78c88eSYongseok Koh 			       uint64_t item_flags __rte_unused)
99584c406e7SOri Kam {
99684c406e7SOri Kam #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
99784c406e7SOri Kam 	const struct rte_flow_item_mpls *spec = item->spec;
99884c406e7SOri Kam 	const struct rte_flow_item_mpls *mask = item->mask;
99984c406e7SOri Kam 	unsigned int size = sizeof(struct ibv_flow_spec_mpls);
100084c406e7SOri Kam 	struct ibv_flow_spec_mpls mpls = {
100184c406e7SOri Kam 		.type = IBV_FLOW_SPEC_MPLS,
100284c406e7SOri Kam 		.size = size,
100384c406e7SOri Kam 	};
100484c406e7SOri Kam 
100584c406e7SOri Kam 	if (!mask)
100684c406e7SOri Kam 		mask = &rte_flow_item_mpls_mask;
100784c406e7SOri Kam 	if (spec) {
100884c406e7SOri Kam 		memcpy(&mpls.val.label, spec, sizeof(mpls.val.label));
100984c406e7SOri Kam 		memcpy(&mpls.mask.label, mask, sizeof(mpls.mask.label));
101084c406e7SOri Kam 		/* Remove unwanted bits from values.  */
101184c406e7SOri Kam 		mpls.val.label &= mpls.mask.label;
101284c406e7SOri Kam 	}
10134a78c88eSYongseok Koh 	flow_verbs_spec_add(&dev_flow->verbs, &mpls, size);
101484c406e7SOri Kam #endif
101584c406e7SOri Kam }
101684c406e7SOri Kam 
101784c406e7SOri Kam /**
101884c406e7SOri Kam  * Convert the @p action into a Verbs specification. This function assumes that
101984c406e7SOri Kam  * the input is valid and that there is space to insert the requested action
10204a78c88eSYongseok Koh  * into the flow.
102184c406e7SOri Kam  *
102284c406e7SOri Kam  * @param[in] dev_flow
102384c406e7SOri Kam  *   Pointer to mlx5_flow.
10244a78c88eSYongseok Koh  * @param[in] action
10254a78c88eSYongseok Koh  *   Action configuration.
102684c406e7SOri Kam  */
102784c406e7SOri Kam static void
10284a78c88eSYongseok Koh flow_verbs_translate_action_drop
10294a78c88eSYongseok Koh 	(struct mlx5_flow *dev_flow,
10304a78c88eSYongseok Koh 	 const struct rte_flow_action *action __rte_unused)
103184c406e7SOri Kam {
103284c406e7SOri Kam 	unsigned int size = sizeof(struct ibv_flow_spec_action_drop);
103384c406e7SOri Kam 	struct ibv_flow_spec_action_drop drop = {
103484c406e7SOri Kam 			.type = IBV_FLOW_SPEC_ACTION_DROP,
103584c406e7SOri Kam 			.size = size,
103684c406e7SOri Kam 	};
103784c406e7SOri Kam 
10384a78c88eSYongseok Koh 	flow_verbs_spec_add(&dev_flow->verbs, &drop, size);
103984c406e7SOri Kam }
104084c406e7SOri Kam 
104184c406e7SOri Kam /**
104284c406e7SOri Kam  * Convert the @p action into a Verbs specification. This function assumes that
104384c406e7SOri Kam  * the input is valid and that there is space to insert the requested action
10444a78c88eSYongseok Koh  * into the flow.
104584c406e7SOri Kam  *
1046e745f900SSuanming Mou  * @param[in] rss_desc
1047e745f900SSuanming Mou  *   Pointer to mlx5_flow_rss_desc.
10484a78c88eSYongseok Koh  * @param[in] action
10494a78c88eSYongseok Koh  *   Action configuration.
105084c406e7SOri Kam  */
105184c406e7SOri Kam static void
1052e745f900SSuanming Mou flow_verbs_translate_action_queue(struct mlx5_flow_rss_desc *rss_desc,
10534a78c88eSYongseok Koh 				  const struct rte_flow_action *action)
105484c406e7SOri Kam {
105584c406e7SOri Kam 	const struct rte_flow_action_queue *queue = action->conf;
105684c406e7SOri Kam 
1057e745f900SSuanming Mou 	rss_desc->queue[0] = queue->index;
1058e745f900SSuanming Mou 	rss_desc->queue_num = 1;
105984c406e7SOri Kam }
106084c406e7SOri Kam 
106184c406e7SOri Kam /**
106284c406e7SOri Kam  * Convert the @p action into a Verbs specification. This function assumes that
106384c406e7SOri Kam  * the input is valid and that there is space to insert the requested action
10644a78c88eSYongseok Koh  * into the flow.
106584c406e7SOri Kam  *
1066e745f900SSuanming Mou  * @param[in] rss_desc
1067e745f900SSuanming Mou  *   Pointer to mlx5_flow_rss_desc.
106884c406e7SOri Kam  * @param[in] action
106984c406e7SOri Kam  *   Action configuration.
107084c406e7SOri Kam  */
107184c406e7SOri Kam static void
1072e745f900SSuanming Mou flow_verbs_translate_action_rss(struct mlx5_flow_rss_desc *rss_desc,
10734a78c88eSYongseok Koh 				const struct rte_flow_action *action)
107484c406e7SOri Kam {
107584c406e7SOri Kam 	const struct rte_flow_action_rss *rss = action->conf;
1076f1b85a27SOphir Munk 	const uint8_t *rss_key;
107784c406e7SOri Kam 
1078e745f900SSuanming Mou 	memcpy(rss_desc->queue, rss->queue, rss->queue_num * sizeof(uint16_t));
1079e745f900SSuanming Mou 	rss_desc->queue_num = rss->queue_num;
1080f1b85a27SOphir Munk 	/* NULL RSS key indicates default RSS key. */
1081f1b85a27SOphir Munk 	rss_key = !rss->key ? rss_hash_default_key : rss->key;
1082e745f900SSuanming Mou 	memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
1083e205c95fSViacheslav Ovsiienko 	/*
1084e205c95fSViacheslav Ovsiienko 	 * rss->level and rss.types should be set in advance when expanding
1085e205c95fSViacheslav Ovsiienko 	 * items for RSS.
1086e205c95fSViacheslav Ovsiienko 	 */
108784c406e7SOri Kam }
108884c406e7SOri Kam 
108984c406e7SOri Kam /**
109084c406e7SOri Kam  * Convert the @p action into a Verbs specification. This function assumes that
109184c406e7SOri Kam  * the input is valid and that there is space to insert the requested action
10924a78c88eSYongseok Koh  * into the flow.
109384c406e7SOri Kam  *
109484c406e7SOri Kam  * @param[in] dev_flow
109584c406e7SOri Kam  *   Pointer to mlx5_flow.
10964a78c88eSYongseok Koh  * @param[in] action
10974a78c88eSYongseok Koh  *   Action configuration.
109884c406e7SOri Kam  */
109984c406e7SOri Kam static void
110084c406e7SOri Kam flow_verbs_translate_action_flag
11014a78c88eSYongseok Koh 	(struct mlx5_flow *dev_flow,
11024a78c88eSYongseok Koh 	 const struct rte_flow_action *action __rte_unused)
110384c406e7SOri Kam {
110484c406e7SOri Kam 	unsigned int size = sizeof(struct ibv_flow_spec_action_tag);
110584c406e7SOri Kam 	struct ibv_flow_spec_action_tag tag = {
110684c406e7SOri Kam 		.type = IBV_FLOW_SPEC_ACTION_TAG,
110784c406e7SOri Kam 		.size = size,
110884c406e7SOri Kam 		.tag_id = mlx5_flow_mark_set(MLX5_FLOW_MARK_DEFAULT),
110984c406e7SOri Kam 	};
111084c406e7SOri Kam 
11114a78c88eSYongseok Koh 	flow_verbs_spec_add(&dev_flow->verbs, &tag, size);
111284c406e7SOri Kam }
111384c406e7SOri Kam 
111484c406e7SOri Kam /**
111584c406e7SOri Kam  * Convert the @p action into a Verbs specification. This function assumes that
111684c406e7SOri Kam  * the input is valid and that there is space to insert the requested action
11174a78c88eSYongseok Koh  * into the flow.
111884c406e7SOri Kam  *
111984c406e7SOri Kam  * @param[in] dev_flow
112084c406e7SOri Kam  *   Pointer to mlx5_flow.
11214a78c88eSYongseok Koh  * @param[in] action
11224a78c88eSYongseok Koh  *   Action configuration.
112384c406e7SOri Kam  */
112484c406e7SOri Kam static void
11254a78c88eSYongseok Koh flow_verbs_translate_action_mark(struct mlx5_flow *dev_flow,
11264a78c88eSYongseok Koh 				 const struct rte_flow_action *action)
112784c406e7SOri Kam {
112884c406e7SOri Kam 	const struct rte_flow_action_mark *mark = action->conf;
112984c406e7SOri Kam 	unsigned int size = sizeof(struct ibv_flow_spec_action_tag);
113084c406e7SOri Kam 	struct ibv_flow_spec_action_tag tag = {
113184c406e7SOri Kam 		.type = IBV_FLOW_SPEC_ACTION_TAG,
113284c406e7SOri Kam 		.size = size,
11334a78c88eSYongseok Koh 		.tag_id = mlx5_flow_mark_set(mark->id),
113484c406e7SOri Kam 	};
113584c406e7SOri Kam 
11364a78c88eSYongseok Koh 	flow_verbs_spec_add(&dev_flow->verbs, &tag, size);
113784c406e7SOri Kam }
113884c406e7SOri Kam 
113984c406e7SOri Kam /**
114084c406e7SOri Kam  * Convert the @p action into a Verbs specification. This function assumes that
114184c406e7SOri Kam  * the input is valid and that there is space to insert the requested action
11424a78c88eSYongseok Koh  * into the flow.
114384c406e7SOri Kam  *
114484c406e7SOri Kam  * @param[in] dev
114584c406e7SOri Kam  *   Pointer to the Ethernet device structure.
114684c406e7SOri Kam  * @param[in] action
114784c406e7SOri Kam  *   Action configuration.
114884c406e7SOri Kam  * @param[in] dev_flow
114984c406e7SOri Kam  *   Pointer to mlx5_flow.
115084c406e7SOri Kam  * @param[out] error
115184c406e7SOri Kam  *   Pointer to error structure.
115284c406e7SOri Kam  *
115384c406e7SOri Kam  * @return
115484c406e7SOri Kam  *   0 On success else a negative errno value is returned and rte_errno is set.
115584c406e7SOri Kam  */
115684c406e7SOri Kam static int
11574a78c88eSYongseok Koh flow_verbs_translate_action_count(struct mlx5_flow *dev_flow,
115884c406e7SOri Kam 				  const struct rte_flow_action *action,
11594a78c88eSYongseok Koh 				  struct rte_eth_dev *dev,
116084c406e7SOri Kam 				  struct rte_flow_error *error)
116184c406e7SOri Kam {
116284c406e7SOri Kam 	const struct rte_flow_action_count *count = action->conf;
116384c406e7SOri Kam 	struct rte_flow *flow = dev_flow->flow;
1164db48f9dbSViacheslav Ovsiienko #if defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42) || \
1165db48f9dbSViacheslav Ovsiienko 	defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45)
1166826b8a87SSuanming Mou 	struct mlx5_flow_counter_pool *pool;
1167826b8a87SSuanming Mou 	struct mlx5_flow_counter *cnt = NULL;
116884c406e7SOri Kam 	unsigned int size = sizeof(struct ibv_flow_spec_counter_action);
116984c406e7SOri Kam 	struct ibv_flow_spec_counter_action counter = {
117084c406e7SOri Kam 		.type = IBV_FLOW_SPEC_ACTION_COUNT,
117184c406e7SOri Kam 		.size = size,
117284c406e7SOri Kam 	};
117384c406e7SOri Kam #endif
117484c406e7SOri Kam 
117584c406e7SOri Kam 	if (!flow->counter) {
117692ef4b8fSAndrew Rybchenko 		flow->counter = flow_verbs_counter_new(dev, count->id);
117784c406e7SOri Kam 		if (!flow->counter)
117884c406e7SOri Kam 			return rte_flow_error_set(error, rte_errno,
117984c406e7SOri Kam 						  RTE_FLOW_ERROR_TYPE_ACTION,
118084c406e7SOri Kam 						  action,
118184c406e7SOri Kam 						  "cannot get counter"
118284c406e7SOri Kam 						  " context.");
118384c406e7SOri Kam 	}
1184db48f9dbSViacheslav Ovsiienko #if defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42)
1185826b8a87SSuanming Mou 	cnt = flow_verbs_counter_get_by_idx(dev, flow->counter, &pool);
11862b5b1aebSSuanming Mou 	counter.counter_set_handle =
11872b5b1aebSSuanming Mou 		((struct ibv_counter_set *)cnt->dcs_when_active)->handle;
11884a78c88eSYongseok Koh 	flow_verbs_spec_add(&dev_flow->verbs, &counter, size);
1189db48f9dbSViacheslav Ovsiienko #elif defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45)
1190826b8a87SSuanming Mou 	cnt = flow_verbs_counter_get_by_idx(dev, flow->counter, &pool);
11912b5b1aebSSuanming Mou 	counter.counters = (struct ibv_counters *)cnt->dcs_when_active;
11924a78c88eSYongseok Koh 	flow_verbs_spec_add(&dev_flow->verbs, &counter, size);
119384c406e7SOri Kam #endif
119484c406e7SOri Kam 	return 0;
119584c406e7SOri Kam }
119684c406e7SOri Kam 
119784c406e7SOri Kam /**
119884c406e7SOri Kam  * Internal validation function. For validating both actions and items.
119984c406e7SOri Kam  *
120084c406e7SOri Kam  * @param[in] dev
120184c406e7SOri Kam  *   Pointer to the Ethernet device structure.
120284c406e7SOri Kam  * @param[in] attr
120384c406e7SOri Kam  *   Pointer to the flow attributes.
120484c406e7SOri Kam  * @param[in] items
120584c406e7SOri Kam  *   Pointer to the list of items.
120684c406e7SOri Kam  * @param[in] actions
120784c406e7SOri Kam  *   Pointer to the list of actions.
1208b67b4ecbSDekel Peled  * @param[in] external
1209b67b4ecbSDekel Peled  *   This flow rule is created by request external to PMD.
121072a944dbSBing Zhao  * @param[in] hairpin
121172a944dbSBing Zhao  *   Number of hairpin TX actions, 0 means classic flow.
121284c406e7SOri Kam  * @param[out] error
121384c406e7SOri Kam  *   Pointer to the error structure.
121484c406e7SOri Kam  *
121584c406e7SOri Kam  * @return
121684c406e7SOri Kam  *   0 on success, a negative errno value otherwise and rte_errno is set.
121784c406e7SOri Kam  */
121884c406e7SOri Kam static int
121984c406e7SOri Kam flow_verbs_validate(struct rte_eth_dev *dev,
122084c406e7SOri Kam 		    const struct rte_flow_attr *attr,
122184c406e7SOri Kam 		    const struct rte_flow_item items[],
122284c406e7SOri Kam 		    const struct rte_flow_action actions[],
1223b67b4ecbSDekel Peled 		    bool external __rte_unused,
122472a944dbSBing Zhao 		    int hairpin __rte_unused,
122584c406e7SOri Kam 		    struct rte_flow_error *error)
122684c406e7SOri Kam {
122784c406e7SOri Kam 	int ret;
12280ddd1143SYongseok Koh 	uint64_t action_flags = 0;
12290ddd1143SYongseok Koh 	uint64_t item_flags = 0;
123038f7efaaSDekel Peled 	uint64_t last_item = 0;
123184c406e7SOri Kam 	uint8_t next_protocol = 0xff;
1232fba32130SXiaoyu Min 	uint16_t ether_type = 0;
1233b6aaaa22SShiri Kuzin 	bool is_empty_vlan = false;
1234a1fd0c82SRongwei Liu 	uint16_t udp_dport = 0;
12351939eb6fSDariusz Sosnowski 	bool is_root;
123684c406e7SOri Kam 
123784c406e7SOri Kam 	if (items == NULL)
123884c406e7SOri Kam 		return -1;
123984c406e7SOri Kam 	ret = mlx5_flow_validate_attributes(dev, attr, error);
124084c406e7SOri Kam 	if (ret < 0)
124184c406e7SOri Kam 		return ret;
12421939eb6fSDariusz Sosnowski 	is_root = ret;
124384c406e7SOri Kam 	for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
12444a78c88eSYongseok Koh 		int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
124584c406e7SOri Kam 		int ret = 0;
124624663641SYongseok Koh 
124784c406e7SOri Kam 		switch (items->type) {
124884c406e7SOri Kam 		case RTE_FLOW_ITEM_TYPE_VOID:
124984c406e7SOri Kam 			break;
125084c406e7SOri Kam 		case RTE_FLOW_ITEM_TYPE_ETH:
125184c406e7SOri Kam 			ret = mlx5_flow_validate_item_eth(items, item_flags,
125286b59a1aSMatan Azrad 							  false, error);
125384c406e7SOri Kam 			if (ret < 0)
125484c406e7SOri Kam 				return ret;
125538f7efaaSDekel Peled 			last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
125684c406e7SOri Kam 					     MLX5_FLOW_LAYER_OUTER_L2;
1257fba32130SXiaoyu Min 			if (items->mask != NULL && items->spec != NULL) {
1258fba32130SXiaoyu Min 				ether_type =
1259fba32130SXiaoyu Min 					((const struct rte_flow_item_eth *)
1260fba32130SXiaoyu Min 					 items->spec)->type;
1261fba32130SXiaoyu Min 				ether_type &=
1262fba32130SXiaoyu Min 					((const struct rte_flow_item_eth *)
1263fba32130SXiaoyu Min 					 items->mask)->type;
1264b6aaaa22SShiri Kuzin 				if (ether_type == RTE_BE16(RTE_ETHER_TYPE_VLAN))
1265b6aaaa22SShiri Kuzin 					is_empty_vlan = true;
1266fba32130SXiaoyu Min 				ether_type = rte_be_to_cpu_16(ether_type);
1267fba32130SXiaoyu Min 			} else {
1268fba32130SXiaoyu Min 				ether_type = 0;
1269fba32130SXiaoyu Min 			}
127084c406e7SOri Kam 			break;
127184c406e7SOri Kam 		case RTE_FLOW_ITEM_TYPE_VLAN:
127284c406e7SOri Kam 			ret = mlx5_flow_validate_item_vlan(items, item_flags,
1273dfedf3e3SViacheslav Ovsiienko 							   dev, error);
127484c406e7SOri Kam 			if (ret < 0)
127584c406e7SOri Kam 				return ret;
127638f7efaaSDekel Peled 			last_item = tunnel ? (MLX5_FLOW_LAYER_INNER_L2 |
12774a78c88eSYongseok Koh 					      MLX5_FLOW_LAYER_INNER_VLAN) :
12784a78c88eSYongseok Koh 					     (MLX5_FLOW_LAYER_OUTER_L2 |
12794a78c88eSYongseok Koh 					      MLX5_FLOW_LAYER_OUTER_VLAN);
1280fba32130SXiaoyu Min 			if (items->mask != NULL && items->spec != NULL) {
1281fba32130SXiaoyu Min 				ether_type =
1282fba32130SXiaoyu Min 					((const struct rte_flow_item_vlan *)
1283fba32130SXiaoyu Min 					 items->spec)->inner_type;
1284fba32130SXiaoyu Min 				ether_type &=
1285fba32130SXiaoyu Min 					((const struct rte_flow_item_vlan *)
1286fba32130SXiaoyu Min 					 items->mask)->inner_type;
1287fba32130SXiaoyu Min 				ether_type = rte_be_to_cpu_16(ether_type);
1288fba32130SXiaoyu Min 			} else {
1289fba32130SXiaoyu Min 				ether_type = 0;
1290fba32130SXiaoyu Min 			}
1291b6aaaa22SShiri Kuzin 			is_empty_vlan = false;
129284c406e7SOri Kam 			break;
129384c406e7SOri Kam 		case RTE_FLOW_ITEM_TYPE_IPV4:
12946859e67eSDekel Peled 			ret = mlx5_flow_validate_item_ipv4
12956859e67eSDekel Peled 						(items, item_flags,
12966859e67eSDekel Peled 						 last_item, ether_type, NULL,
12976859e67eSDekel Peled 						 MLX5_ITEM_RANGE_NOT_ACCEPTED,
1298fba32130SXiaoyu Min 						 error);
129984c406e7SOri Kam 			if (ret < 0)
130084c406e7SOri Kam 				return ret;
130138f7efaaSDekel Peled 			last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
130284c406e7SOri Kam 					     MLX5_FLOW_LAYER_OUTER_L3_IPV4;
130384c406e7SOri Kam 			if (items->mask != NULL &&
130484c406e7SOri Kam 			    ((const struct rte_flow_item_ipv4 *)
13053193c249SYongseok Koh 			     items->mask)->hdr.next_proto_id) {
130684c406e7SOri Kam 				next_protocol =
130784c406e7SOri Kam 					((const struct rte_flow_item_ipv4 *)
130884c406e7SOri Kam 					 (items->spec))->hdr.next_proto_id;
13093193c249SYongseok Koh 				next_protocol &=
13103193c249SYongseok Koh 					((const struct rte_flow_item_ipv4 *)
13113193c249SYongseok Koh 					 (items->mask))->hdr.next_proto_id;
13123193c249SYongseok Koh 			} else {
13133193c249SYongseok Koh 				/* Reset for inner layer. */
13143193c249SYongseok Koh 				next_protocol = 0xff;
13153193c249SYongseok Koh 			}
131684c406e7SOri Kam 			break;
131784c406e7SOri Kam 		case RTE_FLOW_ITEM_TYPE_IPV6:
131884c406e7SOri Kam 			ret = mlx5_flow_validate_item_ipv6(items, item_flags,
1319fba32130SXiaoyu Min 							   last_item,
1320fba32130SXiaoyu Min 							   ether_type, NULL,
1321fba32130SXiaoyu Min 							   error);
132284c406e7SOri Kam 			if (ret < 0)
132384c406e7SOri Kam 				return ret;
132438f7efaaSDekel Peled 			last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
132584c406e7SOri Kam 					     MLX5_FLOW_LAYER_OUTER_L3_IPV6;
132684c406e7SOri Kam 			if (items->mask != NULL &&
132784c406e7SOri Kam 			    ((const struct rte_flow_item_ipv6 *)
13283193c249SYongseok Koh 			     items->mask)->hdr.proto) {
132984c406e7SOri Kam 				next_protocol =
133084c406e7SOri Kam 					((const struct rte_flow_item_ipv6 *)
133184c406e7SOri Kam 					 items->spec)->hdr.proto;
13323193c249SYongseok Koh 				next_protocol &=
13333193c249SYongseok Koh 					((const struct rte_flow_item_ipv6 *)
13343193c249SYongseok Koh 					 items->mask)->hdr.proto;
13353193c249SYongseok Koh 			} else {
13363193c249SYongseok Koh 				/* Reset for inner layer. */
13373193c249SYongseok Koh 				next_protocol = 0xff;
13383193c249SYongseok Koh 			}
133984c406e7SOri Kam 			break;
134084c406e7SOri Kam 		case RTE_FLOW_ITEM_TYPE_UDP:
134184c406e7SOri Kam 			ret = mlx5_flow_validate_item_udp(items, item_flags,
134284c406e7SOri Kam 							  next_protocol,
134384c406e7SOri Kam 							  error);
1344a1fd0c82SRongwei Liu 			const struct rte_flow_item_udp *spec = items->spec;
1345a1fd0c82SRongwei Liu 			const struct rte_flow_item_udp *mask = items->mask;
1346a1fd0c82SRongwei Liu 			if (!mask)
1347a1fd0c82SRongwei Liu 				mask = &rte_flow_item_udp_mask;
1348a1fd0c82SRongwei Liu 			if (spec != NULL)
1349a1fd0c82SRongwei Liu 				udp_dport = rte_be_to_cpu_16
1350a1fd0c82SRongwei Liu 						(spec->hdr.dst_port &
1351a1fd0c82SRongwei Liu 						 mask->hdr.dst_port);
1352a1fd0c82SRongwei Liu 
135384c406e7SOri Kam 			if (ret < 0)
135484c406e7SOri Kam 				return ret;
135538f7efaaSDekel Peled 			last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
135684c406e7SOri Kam 					     MLX5_FLOW_LAYER_OUTER_L4_UDP;
135784c406e7SOri Kam 			break;
135884c406e7SOri Kam 		case RTE_FLOW_ITEM_TYPE_TCP:
135992378c2bSMoti Haimovsky 			ret = mlx5_flow_validate_item_tcp
136092378c2bSMoti Haimovsky 						(items, item_flags,
136192378c2bSMoti Haimovsky 						 next_protocol,
136292378c2bSMoti Haimovsky 						 &rte_flow_item_tcp_mask,
136392378c2bSMoti Haimovsky 						 error);
136484c406e7SOri Kam 			if (ret < 0)
136584c406e7SOri Kam 				return ret;
136638f7efaaSDekel Peled 			last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
136784c406e7SOri Kam 					     MLX5_FLOW_LAYER_OUTER_L4_TCP;
136884c406e7SOri Kam 			break;
136984c406e7SOri Kam 		case RTE_FLOW_ITEM_TYPE_VXLAN:
1370a1fd0c82SRongwei Liu 			ret = mlx5_flow_validate_item_vxlan(dev, udp_dport,
1371a1fd0c82SRongwei Liu 							    items, item_flags,
13721939eb6fSDariusz Sosnowski 							    is_root, error);
137384c406e7SOri Kam 			if (ret < 0)
137484c406e7SOri Kam 				return ret;
137538f7efaaSDekel Peled 			last_item = MLX5_FLOW_LAYER_VXLAN;
137684c406e7SOri Kam 			break;
137784c406e7SOri Kam 		case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
137884c406e7SOri Kam 			ret = mlx5_flow_validate_item_vxlan_gpe(items,
137984c406e7SOri Kam 								item_flags,
138084c406e7SOri Kam 								dev, error);
138184c406e7SOri Kam 			if (ret < 0)
138284c406e7SOri Kam 				return ret;
138338f7efaaSDekel Peled 			last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
138484c406e7SOri Kam 			break;
138584c406e7SOri Kam 		case RTE_FLOW_ITEM_TYPE_GRE:
138684c406e7SOri Kam 			ret = mlx5_flow_validate_item_gre(items, item_flags,
138784c406e7SOri Kam 							  next_protocol, error);
138884c406e7SOri Kam 			if (ret < 0)
138984c406e7SOri Kam 				return ret;
139038f7efaaSDekel Peled 			last_item = MLX5_FLOW_LAYER_GRE;
139184c406e7SOri Kam 			break;
139284c406e7SOri Kam 		case RTE_FLOW_ITEM_TYPE_MPLS:
139338f7efaaSDekel Peled 			ret = mlx5_flow_validate_item_mpls(dev, items,
139438f7efaaSDekel Peled 							   item_flags,
139538f7efaaSDekel Peled 							   last_item, error);
139684c406e7SOri Kam 			if (ret < 0)
139784c406e7SOri Kam 				return ret;
139838f7efaaSDekel Peled 			last_item = MLX5_FLOW_LAYER_MPLS;
139984c406e7SOri Kam 			break;
140058df16e0SDekel Peled 		case RTE_FLOW_ITEM_TYPE_ICMP:
140158df16e0SDekel Peled 		case RTE_FLOW_ITEM_TYPE_ICMP6:
140284c406e7SOri Kam 			return rte_flow_error_set(error, ENOTSUP,
140384c406e7SOri Kam 						  RTE_FLOW_ERROR_TYPE_ITEM,
140458df16e0SDekel Peled 						  NULL, "ICMP/ICMP6 "
140558df16e0SDekel Peled 						  "item not supported");
140658df16e0SDekel Peled 		default:
140758df16e0SDekel Peled 			return rte_flow_error_set(error, ENOTSUP,
140858df16e0SDekel Peled 						  RTE_FLOW_ERROR_TYPE_ITEM,
140958df16e0SDekel Peled 						  NULL, "item not supported");
141084c406e7SOri Kam 		}
141138f7efaaSDekel Peled 		item_flags |= last_item;
141284c406e7SOri Kam 	}
1413b6aaaa22SShiri Kuzin 	if (is_empty_vlan)
1414b6aaaa22SShiri Kuzin 		return rte_flow_error_set(error, ENOTSUP,
1415b6aaaa22SShiri Kuzin 						 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
1416b6aaaa22SShiri Kuzin 		    "VLAN matching without vid specification is not supported");
141784c406e7SOri Kam 	for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
141884c406e7SOri Kam 		switch (actions->type) {
141984c406e7SOri Kam 		case RTE_FLOW_ACTION_TYPE_VOID:
142084c406e7SOri Kam 			break;
142184c406e7SOri Kam 		case RTE_FLOW_ACTION_TYPE_FLAG:
142284c406e7SOri Kam 			ret = mlx5_flow_validate_action_flag(action_flags,
14233e9fa079SDekel Peled 							     attr,
142484c406e7SOri Kam 							     error);
142584c406e7SOri Kam 			if (ret < 0)
142684c406e7SOri Kam 				return ret;
142784c406e7SOri Kam 			action_flags |= MLX5_FLOW_ACTION_FLAG;
142884c406e7SOri Kam 			break;
142984c406e7SOri Kam 		case RTE_FLOW_ACTION_TYPE_MARK:
143084c406e7SOri Kam 			ret = mlx5_flow_validate_action_mark(actions,
143184c406e7SOri Kam 							     action_flags,
14323e9fa079SDekel Peled 							     attr,
143384c406e7SOri Kam 							     error);
143484c406e7SOri Kam 			if (ret < 0)
143584c406e7SOri Kam 				return ret;
143684c406e7SOri Kam 			action_flags |= MLX5_FLOW_ACTION_MARK;
143784c406e7SOri Kam 			break;
143884c406e7SOri Kam 		case RTE_FLOW_ACTION_TYPE_DROP:
143984c406e7SOri Kam 			ret = mlx5_flow_validate_action_drop(action_flags,
14403e9fa079SDekel Peled 							     attr,
144184c406e7SOri Kam 							     error);
144284c406e7SOri Kam 			if (ret < 0)
144384c406e7SOri Kam 				return ret;
144484c406e7SOri Kam 			action_flags |= MLX5_FLOW_ACTION_DROP;
144584c406e7SOri Kam 			break;
144684c406e7SOri Kam 		case RTE_FLOW_ACTION_TYPE_QUEUE:
144784c406e7SOri Kam 			ret = mlx5_flow_validate_action_queue(actions,
144884c406e7SOri Kam 							      action_flags, dev,
14493e9fa079SDekel Peled 							      attr,
145084c406e7SOri Kam 							      error);
145184c406e7SOri Kam 			if (ret < 0)
145284c406e7SOri Kam 				return ret;
145384c406e7SOri Kam 			action_flags |= MLX5_FLOW_ACTION_QUEUE;
145484c406e7SOri Kam 			break;
145584c406e7SOri Kam 		case RTE_FLOW_ACTION_TYPE_RSS:
145684c406e7SOri Kam 			ret = mlx5_flow_validate_action_rss(actions,
145784c406e7SOri Kam 							    action_flags, dev,
14581183f12fSOri Kam 							    attr, item_flags,
145984c406e7SOri Kam 							    error);
146084c406e7SOri Kam 			if (ret < 0)
146184c406e7SOri Kam 				return ret;
146284c406e7SOri Kam 			action_flags |= MLX5_FLOW_ACTION_RSS;
146384c406e7SOri Kam 			break;
146484c406e7SOri Kam 		case RTE_FLOW_ACTION_TYPE_COUNT:
14653e9fa079SDekel Peled 			ret = mlx5_flow_validate_action_count(dev, attr, error);
146684c406e7SOri Kam 			if (ret < 0)
146784c406e7SOri Kam 				return ret;
146884c406e7SOri Kam 			action_flags |= MLX5_FLOW_ACTION_COUNT;
146984c406e7SOri Kam 			break;
147084c406e7SOri Kam 		default:
147184c406e7SOri Kam 			return rte_flow_error_set(error, ENOTSUP,
147284c406e7SOri Kam 						  RTE_FLOW_ERROR_TYPE_ACTION,
147384c406e7SOri Kam 						  actions,
147484c406e7SOri Kam 						  "action not supported");
147584c406e7SOri Kam 		}
147684c406e7SOri Kam 	}
147770faf9aeSDekel Peled 	/*
147870faf9aeSDekel Peled 	 * Validate the drop action mutual exclusion with other actions.
147970faf9aeSDekel Peled 	 * Drop action is mutually-exclusive with any other action, except for
148070faf9aeSDekel Peled 	 * Count action.
148170faf9aeSDekel Peled 	 */
148270faf9aeSDekel Peled 	if ((action_flags & MLX5_FLOW_ACTION_DROP) &&
148370faf9aeSDekel Peled 	    (action_flags & ~(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_COUNT)))
148470faf9aeSDekel Peled 		return rte_flow_error_set(error, EINVAL,
148570faf9aeSDekel Peled 					  RTE_FLOW_ERROR_TYPE_ACTION, NULL,
148670faf9aeSDekel Peled 					  "Drop action is mutually-exclusive "
148770faf9aeSDekel Peled 					  "with any other action, except for "
148870faf9aeSDekel Peled 					  "Count action");
148984c406e7SOri Kam 	if (!(action_flags & MLX5_FLOW_FATE_ACTIONS))
149084c406e7SOri Kam 		return rte_flow_error_set(error, EINVAL,
149184c406e7SOri Kam 					  RTE_FLOW_ERROR_TYPE_ACTION, actions,
149284c406e7SOri Kam 					  "no fate action is found");
149384c406e7SOri Kam 	return 0;
149484c406e7SOri Kam }
149584c406e7SOri Kam 
149684c406e7SOri Kam /**
149784c406e7SOri Kam  * Calculate the required bytes that are needed for the action part of the verbs
1498c1cfb132SYongseok Koh  * flow.
149984c406e7SOri Kam  *
150084c406e7SOri Kam  * @param[in] actions
150184c406e7SOri Kam  *   Pointer to the list of actions.
150284c406e7SOri Kam  *
150384c406e7SOri Kam  * @return
150484c406e7SOri Kam  *   The size of the memory needed for all actions.
150584c406e7SOri Kam  */
150684c406e7SOri Kam static int
1507c1cfb132SYongseok Koh flow_verbs_get_actions_size(const struct rte_flow_action actions[])
150884c406e7SOri Kam {
150984c406e7SOri Kam 	int size = 0;
151084c406e7SOri Kam 
151184c406e7SOri Kam 	for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
151284c406e7SOri Kam 		switch (actions->type) {
151384c406e7SOri Kam 		case RTE_FLOW_ACTION_TYPE_VOID:
151484c406e7SOri Kam 			break;
151584c406e7SOri Kam 		case RTE_FLOW_ACTION_TYPE_FLAG:
151684c406e7SOri Kam 			size += sizeof(struct ibv_flow_spec_action_tag);
151784c406e7SOri Kam 			break;
151884c406e7SOri Kam 		case RTE_FLOW_ACTION_TYPE_MARK:
151984c406e7SOri Kam 			size += sizeof(struct ibv_flow_spec_action_tag);
152084c406e7SOri Kam 			break;
152184c406e7SOri Kam 		case RTE_FLOW_ACTION_TYPE_DROP:
152284c406e7SOri Kam 			size += sizeof(struct ibv_flow_spec_action_drop);
152384c406e7SOri Kam 			break;
152484c406e7SOri Kam 		case RTE_FLOW_ACTION_TYPE_QUEUE:
152584c406e7SOri Kam 			break;
152684c406e7SOri Kam 		case RTE_FLOW_ACTION_TYPE_RSS:
152784c406e7SOri Kam 			break;
152884c406e7SOri Kam 		case RTE_FLOW_ACTION_TYPE_COUNT:
1529db48f9dbSViacheslav Ovsiienko #if defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42) || \
1530db48f9dbSViacheslav Ovsiienko 	defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45)
153184c406e7SOri Kam 			size += sizeof(struct ibv_flow_spec_counter_action);
153284c406e7SOri Kam #endif
153384c406e7SOri Kam 			break;
153484c406e7SOri Kam 		default:
153584c406e7SOri Kam 			break;
153684c406e7SOri Kam 		}
153784c406e7SOri Kam 	}
153884c406e7SOri Kam 	return size;
153984c406e7SOri Kam }
154084c406e7SOri Kam 
154184c406e7SOri Kam /**
154284c406e7SOri Kam  * Calculate the required bytes that are needed for the item part of the verbs
1543c1cfb132SYongseok Koh  * flow.
154484c406e7SOri Kam  *
1545c1cfb132SYongseok Koh  * @param[in] items
154684c406e7SOri Kam  *   Pointer to the list of items.
154784c406e7SOri Kam  *
154884c406e7SOri Kam  * @return
154984c406e7SOri Kam  *   The size of the memory needed for all items.
155084c406e7SOri Kam  */
155184c406e7SOri Kam static int
1552c1cfb132SYongseok Koh flow_verbs_get_items_size(const struct rte_flow_item items[])
155384c406e7SOri Kam {
155484c406e7SOri Kam 	int size = 0;
155584c406e7SOri Kam 
155684c406e7SOri Kam 	for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
155784c406e7SOri Kam 		switch (items->type) {
155884c406e7SOri Kam 		case RTE_FLOW_ITEM_TYPE_VOID:
155984c406e7SOri Kam 			break;
156084c406e7SOri Kam 		case RTE_FLOW_ITEM_TYPE_ETH:
156184c406e7SOri Kam 			size += sizeof(struct ibv_flow_spec_eth);
156284c406e7SOri Kam 			break;
156384c406e7SOri Kam 		case RTE_FLOW_ITEM_TYPE_VLAN:
156484c406e7SOri Kam 			size += sizeof(struct ibv_flow_spec_eth);
156584c406e7SOri Kam 			break;
156684c406e7SOri Kam 		case RTE_FLOW_ITEM_TYPE_IPV4:
156784c406e7SOri Kam 			size += sizeof(struct ibv_flow_spec_ipv4_ext);
156884c406e7SOri Kam 			break;
156984c406e7SOri Kam 		case RTE_FLOW_ITEM_TYPE_IPV6:
157084c406e7SOri Kam 			size += sizeof(struct ibv_flow_spec_ipv6);
157184c406e7SOri Kam 			break;
157284c406e7SOri Kam 		case RTE_FLOW_ITEM_TYPE_UDP:
157384c406e7SOri Kam 			size += sizeof(struct ibv_flow_spec_tcp_udp);
157484c406e7SOri Kam 			break;
157584c406e7SOri Kam 		case RTE_FLOW_ITEM_TYPE_TCP:
157684c406e7SOri Kam 			size += sizeof(struct ibv_flow_spec_tcp_udp);
157784c406e7SOri Kam 			break;
157884c406e7SOri Kam 		case RTE_FLOW_ITEM_TYPE_VXLAN:
157984c406e7SOri Kam 			size += sizeof(struct ibv_flow_spec_tunnel);
158084c406e7SOri Kam 			break;
158184c406e7SOri Kam 		case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
158284c406e7SOri Kam 			size += sizeof(struct ibv_flow_spec_tunnel);
158384c406e7SOri Kam 			break;
158484c406e7SOri Kam #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
158584c406e7SOri Kam 		case RTE_FLOW_ITEM_TYPE_GRE:
158684c406e7SOri Kam 			size += sizeof(struct ibv_flow_spec_gre);
158784c406e7SOri Kam 			break;
158884c406e7SOri Kam 		case RTE_FLOW_ITEM_TYPE_MPLS:
158984c406e7SOri Kam 			size += sizeof(struct ibv_flow_spec_mpls);
159084c406e7SOri Kam 			break;
159184c406e7SOri Kam #else
159284c406e7SOri Kam 		case RTE_FLOW_ITEM_TYPE_GRE:
159384c406e7SOri Kam 			size += sizeof(struct ibv_flow_spec_tunnel);
159484c406e7SOri Kam 			break;
159584c406e7SOri Kam #endif
159684c406e7SOri Kam 		default:
159784c406e7SOri Kam 			break;
159884c406e7SOri Kam 		}
159984c406e7SOri Kam 	}
160084c406e7SOri Kam 	return size;
160184c406e7SOri Kam }
160284c406e7SOri Kam 
160384c406e7SOri Kam /**
160484c406e7SOri Kam  * Internal preparation function. Allocate mlx5_flow with the required size.
160584c406e7SOri Kam  * The required size is calculate based on the actions and items. This function
160684c406e7SOri Kam  * also returns the detected actions and items for later use.
160784c406e7SOri Kam  *
1608e7bfa359SBing Zhao  * @param[in] dev
1609e7bfa359SBing Zhao  *   Pointer to Ethernet device.
161084c406e7SOri Kam  * @param[in] attr
161184c406e7SOri Kam  *   Pointer to the flow attributes.
161284c406e7SOri Kam  * @param[in] items
161384c406e7SOri Kam  *   Pointer to the list of items.
161484c406e7SOri Kam  * @param[in] actions
161584c406e7SOri Kam  *   Pointer to the list of actions.
161684c406e7SOri Kam  * @param[out] error
161784c406e7SOri Kam  *   Pointer to the error structure.
161884c406e7SOri Kam  *
161984c406e7SOri Kam  * @return
162084c406e7SOri Kam  *   Pointer to mlx5_flow object on success, otherwise NULL and rte_errno
162184c406e7SOri Kam  *   is set.
162284c406e7SOri Kam  */
162384c406e7SOri Kam static struct mlx5_flow *
1624e7bfa359SBing Zhao flow_verbs_prepare(struct rte_eth_dev *dev,
1625e7bfa359SBing Zhao 		   const struct rte_flow_attr *attr __rte_unused,
162684c406e7SOri Kam 		   const struct rte_flow_item items[],
162784c406e7SOri Kam 		   const struct rte_flow_action actions[],
162884c406e7SOri Kam 		   struct rte_flow_error *error)
162984c406e7SOri Kam {
1630e7bfa359SBing Zhao 	size_t size = 0;
1631b88341caSSuanming Mou 	uint32_t handle_idx = 0;
1632e205c95fSViacheslav Ovsiienko 	struct mlx5_flow *dev_flow;
1633e7bfa359SBing Zhao 	struct mlx5_flow_handle *dev_handle;
1634e7bfa359SBing Zhao 	struct mlx5_priv *priv = dev->data->dev_private;
16358bb81f26SXueming Li 	struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
163684c406e7SOri Kam 
16378bb81f26SXueming Li 	MLX5_ASSERT(wks);
1638c1cfb132SYongseok Koh 	size += flow_verbs_get_actions_size(actions);
1639c1cfb132SYongseok Koh 	size += flow_verbs_get_items_size(items);
1640e7bfa359SBing Zhao 	if (size > MLX5_VERBS_MAX_SPEC_ACT_SIZE) {
1641e7bfa359SBing Zhao 		rte_flow_error_set(error, E2BIG,
164284c406e7SOri Kam 				   RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1643e7bfa359SBing Zhao 				   "Verbs spec/action size too large");
164484c406e7SOri Kam 		return NULL;
164584c406e7SOri Kam 	}
1646e7bfa359SBing Zhao 	/* In case of corrupting the memory. */
16478bb81f26SXueming Li 	if (wks->flow_idx >= MLX5_NUM_MAX_DEV_FLOWS) {
1648e7bfa359SBing Zhao 		rte_flow_error_set(error, ENOSPC,
1649e7bfa359SBing Zhao 				   RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1650e7bfa359SBing Zhao 				   "not free temporary device flow");
1651e7bfa359SBing Zhao 		return NULL;
1652e7bfa359SBing Zhao 	}
1653b88341caSSuanming Mou 	dev_handle = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
1654b88341caSSuanming Mou 				   &handle_idx);
1655e7bfa359SBing Zhao 	if (!dev_handle) {
1656e7bfa359SBing Zhao 		rte_flow_error_set(error, ENOMEM,
1657e7bfa359SBing Zhao 				   RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1658e7bfa359SBing Zhao 				   "not enough memory to create flow handle");
1659e7bfa359SBing Zhao 		return NULL;
1660e7bfa359SBing Zhao 	}
16618bb81f26SXueming Li 	MLX5_ASSERT(wks->flow_idx + 1 < RTE_DIM(wks->flows));
16628bb81f26SXueming Li 	dev_flow = &wks->flows[wks->flow_idx++];
1663e7bfa359SBing Zhao 	dev_flow->handle = dev_handle;
1664b88341caSSuanming Mou 	dev_flow->handle_idx = handle_idx;
1665e7bfa359SBing Zhao 	/* Memcpy is used, only size needs to be cleared to 0. */
1666e7bfa359SBing Zhao 	dev_flow->verbs.size = 0;
1667e7bfa359SBing Zhao 	dev_flow->verbs.attr.num_of_specs = 0;
1668e205c95fSViacheslav Ovsiienko 	dev_flow->ingress = attr->ingress;
16690efc99beSOphir Munk 	dev_flow->hash_fields = 0;
1670c42f44bdSBing Zhao 	/* Need to set transfer attribute: not supported in Verbs mode. */
1671e205c95fSViacheslav Ovsiienko 	return dev_flow;
167284c406e7SOri Kam }
167384c406e7SOri Kam 
167484c406e7SOri Kam /**
167584c406e7SOri Kam  * Fill the flow with verb spec.
167684c406e7SOri Kam  *
167784c406e7SOri Kam  * @param[in] dev
167884c406e7SOri Kam  *   Pointer to Ethernet device.
167984c406e7SOri Kam  * @param[in, out] dev_flow
168084c406e7SOri Kam  *   Pointer to the mlx5 flow.
168184c406e7SOri Kam  * @param[in] attr
168284c406e7SOri Kam  *   Pointer to the flow attributes.
168384c406e7SOri Kam  * @param[in] items
168484c406e7SOri Kam  *   Pointer to the list of items.
168584c406e7SOri Kam  * @param[in] actions
168684c406e7SOri Kam  *   Pointer to the list of actions.
168784c406e7SOri Kam  * @param[out] error
168884c406e7SOri Kam  *   Pointer to the error structure.
168984c406e7SOri Kam  *
169084c406e7SOri Kam  * @return
1691de90612fSDekel Peled  *   0 on success, else a negative errno value otherwise and rte_errno is set.
169284c406e7SOri Kam  */
169384c406e7SOri Kam static int
169484c406e7SOri Kam flow_verbs_translate(struct rte_eth_dev *dev,
169584c406e7SOri Kam 		     struct mlx5_flow *dev_flow,
169684c406e7SOri Kam 		     const struct rte_flow_attr *attr,
169784c406e7SOri Kam 		     const struct rte_flow_item items[],
169884c406e7SOri Kam 		     const struct rte_flow_action actions[],
169984c406e7SOri Kam 		     struct rte_flow_error *error)
170084c406e7SOri Kam {
170184c406e7SOri Kam 	uint64_t item_flags = 0;
17024a78c88eSYongseok Koh 	uint64_t action_flags = 0;
170384c406e7SOri Kam 	uint64_t priority = attr->priority;
17044a78c88eSYongseok Koh 	uint32_t subpriority = 0;
1705dbeba4cfSThomas Monjalon 	struct mlx5_priv *priv = dev->data->dev_private;
17068bb81f26SXueming Li 	struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
17078bb81f26SXueming Li 	struct mlx5_flow_rss_desc *rss_desc;
1708df498655SGregory Etelson 	const struct rte_flow_item *tunnel_item = NULL;
170998008ce6SDariusz Sosnowski 	uint8_t *gre_spec = NULL;
171084c406e7SOri Kam 
17118bb81f26SXueming Li 	MLX5_ASSERT(wks);
17120064bf43SXueming Li 	rss_desc = &wks->rss_desc;
17135f8ae44dSDong Zhou 	if (priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)
17143c4338a4SJiawei Wang 		priority = priv->sh->flow_max_priority - 1;
171584c406e7SOri Kam 	for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
171684c406e7SOri Kam 		int ret;
17174a78c88eSYongseok Koh 
171884c406e7SOri Kam 		switch (actions->type) {
171984c406e7SOri Kam 		case RTE_FLOW_ACTION_TYPE_VOID:
172084c406e7SOri Kam 			break;
172184c406e7SOri Kam 		case RTE_FLOW_ACTION_TYPE_FLAG:
17224a78c88eSYongseok Koh 			flow_verbs_translate_action_flag(dev_flow, actions);
17234a78c88eSYongseok Koh 			action_flags |= MLX5_FLOW_ACTION_FLAG;
1724082becbfSRaja Zidane 			wks->mark = 1;
172584c406e7SOri Kam 			break;
172684c406e7SOri Kam 		case RTE_FLOW_ACTION_TYPE_MARK:
17274a78c88eSYongseok Koh 			flow_verbs_translate_action_mark(dev_flow, actions);
17284a78c88eSYongseok Koh 			action_flags |= MLX5_FLOW_ACTION_MARK;
1729082becbfSRaja Zidane 			wks->mark = 1;
173084c406e7SOri Kam 			break;
173184c406e7SOri Kam 		case RTE_FLOW_ACTION_TYPE_DROP:
17324a78c88eSYongseok Koh 			flow_verbs_translate_action_drop(dev_flow, actions);
17334a78c88eSYongseok Koh 			action_flags |= MLX5_FLOW_ACTION_DROP;
1734488d13abSSuanming Mou 			dev_flow->handle->fate_action = MLX5_FLOW_FATE_DROP;
173584c406e7SOri Kam 			break;
173684c406e7SOri Kam 		case RTE_FLOW_ACTION_TYPE_QUEUE:
1737e745f900SSuanming Mou 			flow_verbs_translate_action_queue(rss_desc, actions);
17384a78c88eSYongseok Koh 			action_flags |= MLX5_FLOW_ACTION_QUEUE;
1739488d13abSSuanming Mou 			dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
174084c406e7SOri Kam 			break;
174184c406e7SOri Kam 		case RTE_FLOW_ACTION_TYPE_RSS:
1742e745f900SSuanming Mou 			flow_verbs_translate_action_rss(rss_desc, actions);
17434a78c88eSYongseok Koh 			action_flags |= MLX5_FLOW_ACTION_RSS;
1744488d13abSSuanming Mou 			dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
174584c406e7SOri Kam 			break;
174684c406e7SOri Kam 		case RTE_FLOW_ACTION_TYPE_COUNT:
17474a78c88eSYongseok Koh 			ret = flow_verbs_translate_action_count(dev_flow,
174884c406e7SOri Kam 								actions,
17494a78c88eSYongseok Koh 								dev, error);
175084c406e7SOri Kam 			if (ret < 0)
175184c406e7SOri Kam 				return ret;
17524a78c88eSYongseok Koh 			action_flags |= MLX5_FLOW_ACTION_COUNT;
175384c406e7SOri Kam 			break;
175484c406e7SOri Kam 		default:
175584c406e7SOri Kam 			return rte_flow_error_set(error, ENOTSUP,
175684c406e7SOri Kam 						  RTE_FLOW_ERROR_TYPE_ACTION,
175784c406e7SOri Kam 						  actions,
175884c406e7SOri Kam 						  "action not supported");
175984c406e7SOri Kam 		}
176084c406e7SOri Kam 	}
1761488d13abSSuanming Mou 	dev_flow->act_flags = action_flags;
176284c406e7SOri Kam 	for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
17634a78c88eSYongseok Koh 		int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
17644a78c88eSYongseok Koh 
176584c406e7SOri Kam 		switch (items->type) {
176684c406e7SOri Kam 		case RTE_FLOW_ITEM_TYPE_VOID:
176784c406e7SOri Kam 			break;
176884c406e7SOri Kam 		case RTE_FLOW_ITEM_TYPE_ETH:
17694a78c88eSYongseok Koh 			flow_verbs_translate_item_eth(dev_flow, items,
17704a78c88eSYongseok Koh 						      item_flags);
17714a78c88eSYongseok Koh 			subpriority = MLX5_PRIORITY_MAP_L2;
17724a78c88eSYongseok Koh 			item_flags |= tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
17734a78c88eSYongseok Koh 					       MLX5_FLOW_LAYER_OUTER_L2;
177484c406e7SOri Kam 			break;
177584c406e7SOri Kam 		case RTE_FLOW_ITEM_TYPE_VLAN:
17764a78c88eSYongseok Koh 			flow_verbs_translate_item_vlan(dev_flow, items,
17774a78c88eSYongseok Koh 						       item_flags);
17784a78c88eSYongseok Koh 			subpriority = MLX5_PRIORITY_MAP_L2;
17794a78c88eSYongseok Koh 			item_flags |= tunnel ? (MLX5_FLOW_LAYER_INNER_L2 |
17804a78c88eSYongseok Koh 						MLX5_FLOW_LAYER_INNER_VLAN) :
17814a78c88eSYongseok Koh 					       (MLX5_FLOW_LAYER_OUTER_L2 |
17824a78c88eSYongseok Koh 						MLX5_FLOW_LAYER_OUTER_VLAN);
178384c406e7SOri Kam 			break;
178484c406e7SOri Kam 		case RTE_FLOW_ITEM_TYPE_IPV4:
17854a78c88eSYongseok Koh 			flow_verbs_translate_item_ipv4(dev_flow, items,
17864a78c88eSYongseok Koh 						       item_flags);
17874a78c88eSYongseok Koh 			subpriority = MLX5_PRIORITY_MAP_L3;
1788e205c95fSViacheslav Ovsiienko 			dev_flow->hash_fields |=
17894a78c88eSYongseok Koh 				mlx5_flow_hashfields_adjust
1790e745f900SSuanming Mou 					(rss_desc, tunnel,
17914a78c88eSYongseok Koh 					 MLX5_IPV4_LAYER_TYPES,
17924a78c88eSYongseok Koh 					 MLX5_IPV4_IBV_RX_HASH);
17934a78c88eSYongseok Koh 			item_flags |= tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
17944a78c88eSYongseok Koh 					       MLX5_FLOW_LAYER_OUTER_L3_IPV4;
179584c406e7SOri Kam 			break;
179684c406e7SOri Kam 		case RTE_FLOW_ITEM_TYPE_IPV6:
17974a78c88eSYongseok Koh 			flow_verbs_translate_item_ipv6(dev_flow, items,
17984a78c88eSYongseok Koh 						       item_flags);
17994a78c88eSYongseok Koh 			subpriority = MLX5_PRIORITY_MAP_L3;
1800e205c95fSViacheslav Ovsiienko 			dev_flow->hash_fields |=
18014a78c88eSYongseok Koh 				mlx5_flow_hashfields_adjust
1802e745f900SSuanming Mou 					(rss_desc, tunnel,
18034a78c88eSYongseok Koh 					 MLX5_IPV6_LAYER_TYPES,
18044a78c88eSYongseok Koh 					 MLX5_IPV6_IBV_RX_HASH);
18054a78c88eSYongseok Koh 			item_flags |= tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
18064a78c88eSYongseok Koh 					       MLX5_FLOW_LAYER_OUTER_L3_IPV6;
180784c406e7SOri Kam 			break;
180884c406e7SOri Kam 		case RTE_FLOW_ITEM_TYPE_TCP:
18094a78c88eSYongseok Koh 			flow_verbs_translate_item_tcp(dev_flow, items,
18104a78c88eSYongseok Koh 						      item_flags);
18114a78c88eSYongseok Koh 			subpriority = MLX5_PRIORITY_MAP_L4;
18125e1db76dSLior Margalit 			if (dev_flow->hash_fields != 0)
1813e205c95fSViacheslav Ovsiienko 				dev_flow->hash_fields |=
18144a78c88eSYongseok Koh 					mlx5_flow_hashfields_adjust
1815295968d1SFerruh Yigit 					(rss_desc, tunnel, RTE_ETH_RSS_TCP,
18164a78c88eSYongseok Koh 					 (IBV_RX_HASH_SRC_PORT_TCP |
18174a78c88eSYongseok Koh 					  IBV_RX_HASH_DST_PORT_TCP));
18184a78c88eSYongseok Koh 			item_flags |= tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
18194a78c88eSYongseok Koh 					       MLX5_FLOW_LAYER_OUTER_L4_TCP;
18204a78c88eSYongseok Koh 			break;
18214a78c88eSYongseok Koh 		case RTE_FLOW_ITEM_TYPE_UDP:
18224a78c88eSYongseok Koh 			flow_verbs_translate_item_udp(dev_flow, items,
18234a78c88eSYongseok Koh 						      item_flags);
18244a78c88eSYongseok Koh 			subpriority = MLX5_PRIORITY_MAP_L4;
18255e1db76dSLior Margalit 			if (dev_flow->hash_fields != 0)
1826e205c95fSViacheslav Ovsiienko 				dev_flow->hash_fields |=
18274a78c88eSYongseok Koh 					mlx5_flow_hashfields_adjust
1828295968d1SFerruh Yigit 					(rss_desc, tunnel, RTE_ETH_RSS_UDP,
18294a78c88eSYongseok Koh 					 (IBV_RX_HASH_SRC_PORT_UDP |
18304a78c88eSYongseok Koh 					  IBV_RX_HASH_DST_PORT_UDP));
18314a78c88eSYongseok Koh 			item_flags |= tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
18324a78c88eSYongseok Koh 					       MLX5_FLOW_LAYER_OUTER_L4_UDP;
183384c406e7SOri Kam 			break;
183484c406e7SOri Kam 		case RTE_FLOW_ITEM_TYPE_VXLAN:
18354a78c88eSYongseok Koh 			flow_verbs_translate_item_vxlan(dev_flow, items,
18364a78c88eSYongseok Koh 							item_flags);
1837750ff30aSGregory Etelson 			subpriority = MLX5_TUNNEL_PRIO_GET(rss_desc);
18384a78c88eSYongseok Koh 			item_flags |= MLX5_FLOW_LAYER_VXLAN;
183984c406e7SOri Kam 			break;
184084c406e7SOri Kam 		case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
18414a78c88eSYongseok Koh 			flow_verbs_translate_item_vxlan_gpe(dev_flow, items,
18424a78c88eSYongseok Koh 							    item_flags);
1843750ff30aSGregory Etelson 			subpriority = MLX5_TUNNEL_PRIO_GET(rss_desc);
18444a78c88eSYongseok Koh 			item_flags |= MLX5_FLOW_LAYER_VXLAN_GPE;
184584c406e7SOri Kam 			break;
184684c406e7SOri Kam 		case RTE_FLOW_ITEM_TYPE_GRE:
184798008ce6SDariusz Sosnowski 			gre_spec = flow_verbs_reserve_gre(dev_flow);
1848750ff30aSGregory Etelson 			subpriority = MLX5_TUNNEL_PRIO_GET(rss_desc);
18494a78c88eSYongseok Koh 			item_flags |= MLX5_FLOW_LAYER_GRE;
1850df498655SGregory Etelson 			tunnel_item = items;
185184c406e7SOri Kam 			break;
185284c406e7SOri Kam 		case RTE_FLOW_ITEM_TYPE_MPLS:
18534a78c88eSYongseok Koh 			flow_verbs_translate_item_mpls(dev_flow, items,
18544a78c88eSYongseok Koh 						       item_flags);
1855750ff30aSGregory Etelson 			subpriority = MLX5_TUNNEL_PRIO_GET(rss_desc);
18564a78c88eSYongseok Koh 			item_flags |= MLX5_FLOW_LAYER_MPLS;
185784c406e7SOri Kam 			break;
185884c406e7SOri Kam 		default:
185984c406e7SOri Kam 			return rte_flow_error_set(error, ENOTSUP,
186084c406e7SOri Kam 						  RTE_FLOW_ERROR_TYPE_ITEM,
186158df16e0SDekel Peled 						  NULL, "item not supported");
186284c406e7SOri Kam 		}
186384c406e7SOri Kam 	}
1864985b4792SGregory Etelson 	if (item_flags & MLX5_FLOW_LAYER_GRE)
186598008ce6SDariusz Sosnowski 		flow_verbs_translate_item_gre(dev_flow, gre_spec,
186698008ce6SDariusz Sosnowski 					      tunnel_item, item_flags);
1867e7bfa359SBing Zhao 	dev_flow->handle->layers = item_flags;
1868e7bfa359SBing Zhao 	/* Other members of attr will be ignored. */
1869e7bfa359SBing Zhao 	dev_flow->verbs.attr.priority =
18704a78c88eSYongseok Koh 		mlx5_flow_adjust_priority(dev, priority, subpriority);
187191389890SOphir Munk 	dev_flow->verbs.attr.port = (uint8_t)priv->dev_port;
187284c406e7SOri Kam 	return 0;
187384c406e7SOri Kam }
187484c406e7SOri Kam 
187584c406e7SOri Kam /**
187684c406e7SOri Kam  * Remove the flow from the NIC but keeps it in memory.
187784c406e7SOri Kam  *
187884c406e7SOri Kam  * @param[in] dev
187984c406e7SOri Kam  *   Pointer to the Ethernet device structure.
188084c406e7SOri Kam  * @param[in, out] flow
188184c406e7SOri Kam  *   Pointer to flow structure.
188284c406e7SOri Kam  */
188384c406e7SOri Kam static void
188484c406e7SOri Kam flow_verbs_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
188584c406e7SOri Kam {
1886b88341caSSuanming Mou 	struct mlx5_priv *priv = dev->data->dev_private;
1887e7bfa359SBing Zhao 	struct mlx5_flow_handle *handle;
1888b88341caSSuanming Mou 	uint32_t handle_idx;
188984c406e7SOri Kam 
189084c406e7SOri Kam 	if (!flow)
189184c406e7SOri Kam 		return;
1892b88341caSSuanming Mou 	SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
1893b88341caSSuanming Mou 		       handle_idx, handle, next) {
1894341c8941SDekel Peled 		if (handle->drv_flow) {
1895341c8941SDekel Peled 			claim_zero(mlx5_glue->destroy_flow(handle->drv_flow));
1896341c8941SDekel Peled 			handle->drv_flow = NULL;
189784c406e7SOri Kam 		}
18986fc18392SSuanming Mou 		/* hrxq is union, don't touch it only the flag is set. */
189965b3cd0dSSuanming Mou 		if (handle->rix_hrxq &&
190065b3cd0dSSuanming Mou 		    handle->fate_action == MLX5_FLOW_FATE_QUEUE) {
190177749adaSSuanming Mou 			mlx5_hrxq_release(dev, handle->rix_hrxq);
190277749adaSSuanming Mou 			handle->rix_hrxq = 0;
190384c406e7SOri Kam 		}
1904e7bfa359SBing Zhao 		if (handle->vf_vlan.tag && handle->vf_vlan.created)
1905e7bfa359SBing Zhao 			mlx5_vlan_vmwa_release(dev, &handle->vf_vlan);
190684c406e7SOri Kam 	}
190784c406e7SOri Kam }
190884c406e7SOri Kam 
190984c406e7SOri Kam /**
191084c406e7SOri Kam  * Remove the flow from the NIC and the memory.
191184c406e7SOri Kam  *
191284c406e7SOri Kam  * @param[in] dev
191384c406e7SOri Kam  *   Pointer to the Ethernet device structure.
191484c406e7SOri Kam  * @param[in, out] flow
191584c406e7SOri Kam  *   Pointer to flow structure.
191684c406e7SOri Kam  */
191784c406e7SOri Kam static void
191884c406e7SOri Kam flow_verbs_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
191984c406e7SOri Kam {
1920b88341caSSuanming Mou 	struct mlx5_priv *priv = dev->data->dev_private;
1921e7bfa359SBing Zhao 	struct mlx5_flow_handle *handle;
192284c406e7SOri Kam 
192384c406e7SOri Kam 	if (!flow)
192484c406e7SOri Kam 		return;
192584c406e7SOri Kam 	flow_verbs_remove(dev, flow);
1926b88341caSSuanming Mou 	while (flow->dev_handles) {
1927b88341caSSuanming Mou 		uint32_t tmp_idx = flow->dev_handles;
1928b88341caSSuanming Mou 
1929b88341caSSuanming Mou 		handle = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
1930b88341caSSuanming Mou 				   tmp_idx);
1931b88341caSSuanming Mou 		if (!handle)
1932b88341caSSuanming Mou 			return;
1933b88341caSSuanming Mou 		flow->dev_handles = handle->next.next;
1934b88341caSSuanming Mou 		mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
1935b88341caSSuanming Mou 			   tmp_idx);
193684c406e7SOri Kam 	}
193784be903cSViacheslav Ovsiienko 	if (flow->counter) {
19385382d28cSMatan Azrad 		flow_verbs_counter_release(dev, flow->counter);
1939956d5c74SSuanming Mou 		flow->counter = 0;
194084be903cSViacheslav Ovsiienko 	}
194184c406e7SOri Kam }
194284c406e7SOri Kam 
194384c406e7SOri Kam /**
194484c406e7SOri Kam  * Apply the flow to the NIC.
194584c406e7SOri Kam  *
194684c406e7SOri Kam  * @param[in] dev
194784c406e7SOri Kam  *   Pointer to the Ethernet device structure.
194884c406e7SOri Kam  * @param[in, out] flow
194984c406e7SOri Kam  *   Pointer to flow structure.
195084c406e7SOri Kam  * @param[out] error
195184c406e7SOri Kam  *   Pointer to error structure.
195284c406e7SOri Kam  *
195384c406e7SOri Kam  * @return
195484c406e7SOri Kam  *   0 on success, a negative errno value otherwise and rte_errno is set.
195584c406e7SOri Kam  */
195684c406e7SOri Kam static int
195784c406e7SOri Kam flow_verbs_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
195884c406e7SOri Kam 		 struct rte_flow_error *error)
195984c406e7SOri Kam {
1960dfedf3e3SViacheslav Ovsiienko 	struct mlx5_priv *priv = dev->data->dev_private;
1961e7bfa359SBing Zhao 	struct mlx5_flow_handle *handle;
196284c406e7SOri Kam 	struct mlx5_flow *dev_flow;
1963772dc0ebSSuanming Mou 	struct mlx5_hrxq *hrxq;
1964b88341caSSuanming Mou 	uint32_t dev_handles;
196584c406e7SOri Kam 	int err;
1966e7bfa359SBing Zhao 	int idx;
19678bb81f26SXueming Li 	struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
196884c406e7SOri Kam 
19698bb81f26SXueming Li 	MLX5_ASSERT(wks);
19700064bf43SXueming Li 	for (idx = wks->flow_idx - 1; idx >= 0; idx--) {
19718bb81f26SXueming Li 		dev_flow = &wks->flows[idx];
1972e7bfa359SBing Zhao 		handle = dev_flow->handle;
1973488d13abSSuanming Mou 		if (handle->fate_action == MLX5_FLOW_FATE_DROP) {
197465b3cd0dSSuanming Mou 			MLX5_ASSERT(priv->drop_queue.hrxq);
197565b3cd0dSSuanming Mou 			hrxq = priv->drop_queue.hrxq;
197684c406e7SOri Kam 		} else {
19770064bf43SXueming Li 			struct mlx5_flow_rss_desc *rss_desc = &wks->rss_desc;
197884c406e7SOri Kam 
1979e745f900SSuanming Mou 			MLX5_ASSERT(rss_desc->queue_num);
1980e1592b6cSSuanming Mou 			rss_desc->key_len = MLX5_RSS_HASH_KEY_LEN;
1981e1592b6cSSuanming Mou 			rss_desc->hash_fields = dev_flow->hash_fields;
1982e1592b6cSSuanming Mou 			rss_desc->tunnel = !!(handle->layers &
1983e1592b6cSSuanming Mou 					      MLX5_FLOW_LAYER_TUNNEL);
1984fabf8a37SSuanming Mou 			rss_desc->shared_rss = 0;
19853a2f674bSSuanming Mou 			hrxq = mlx5_hrxq_get(dev, rss_desc);
198684c406e7SOri Kam 			if (!hrxq) {
198784c406e7SOri Kam 				rte_flow_error_set
198884c406e7SOri Kam 					(error, rte_errno,
198984c406e7SOri Kam 					 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
199084c406e7SOri Kam 					 "cannot get hash queue");
199184c406e7SOri Kam 				goto error;
199284c406e7SOri Kam 			}
19933a2f674bSSuanming Mou 			handle->rix_hrxq = hrxq->idx;
199484c406e7SOri Kam 		}
1995772dc0ebSSuanming Mou 		MLX5_ASSERT(hrxq);
1996341c8941SDekel Peled 		handle->drv_flow = mlx5_glue->create_flow
1997341c8941SDekel Peled 					(hrxq->qp, &dev_flow->verbs.attr);
1998341c8941SDekel Peled 		if (!handle->drv_flow) {
199984c406e7SOri Kam 			rte_flow_error_set(error, errno,
200084c406e7SOri Kam 					   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
200184c406e7SOri Kam 					   NULL,
200284c406e7SOri Kam 					   "hardware refuses to create flow");
200384c406e7SOri Kam 			goto error;
200484c406e7SOri Kam 		}
2005dfedf3e3SViacheslav Ovsiienko 		if (priv->vmwa_context &&
2006e7bfa359SBing Zhao 		    handle->vf_vlan.tag && !handle->vf_vlan.created) {
2007dfedf3e3SViacheslav Ovsiienko 			/*
2008dfedf3e3SViacheslav Ovsiienko 			 * The rule contains the VLAN pattern.
2009dfedf3e3SViacheslav Ovsiienko 			 * For VF we are going to create VLAN
2010dfedf3e3SViacheslav Ovsiienko 			 * interface to make hypervisor set correct
2011dfedf3e3SViacheslav Ovsiienko 			 * e-Switch vport context.
2012dfedf3e3SViacheslav Ovsiienko 			 */
2013e7bfa359SBing Zhao 			mlx5_vlan_vmwa_acquire(dev, &handle->vf_vlan);
2014dfedf3e3SViacheslav Ovsiienko 		}
201584c406e7SOri Kam 	}
201684c406e7SOri Kam 	return 0;
201784c406e7SOri Kam error:
201884c406e7SOri Kam 	err = rte_errno; /* Save rte_errno before cleanup. */
2019b88341caSSuanming Mou 	SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
2020b88341caSSuanming Mou 		       dev_handles, handle, next) {
20216fc18392SSuanming Mou 		/* hrxq is union, don't touch it only the flag is set. */
202265b3cd0dSSuanming Mou 		if (handle->rix_hrxq &&
202365b3cd0dSSuanming Mou 		    handle->fate_action == MLX5_FLOW_FATE_QUEUE) {
202477749adaSSuanming Mou 			mlx5_hrxq_release(dev, handle->rix_hrxq);
202577749adaSSuanming Mou 			handle->rix_hrxq = 0;
202684c406e7SOri Kam 		}
2027e7bfa359SBing Zhao 		if (handle->vf_vlan.tag && handle->vf_vlan.created)
2028e7bfa359SBing Zhao 			mlx5_vlan_vmwa_release(dev, &handle->vf_vlan);
202984c406e7SOri Kam 	}
203084c406e7SOri Kam 	rte_errno = err; /* Restore rte_errno. */
203184c406e7SOri Kam 	return -rte_errno;
203284c406e7SOri Kam }
203384c406e7SOri Kam 
2034684dafe7SMoti Haimovsky /**
2035684dafe7SMoti Haimovsky  * Query a flow.
2036684dafe7SMoti Haimovsky  *
2037684dafe7SMoti Haimovsky  * @see rte_flow_query()
2038684dafe7SMoti Haimovsky  * @see rte_flow_ops
2039684dafe7SMoti Haimovsky  */
2040684dafe7SMoti Haimovsky static int
2041684dafe7SMoti Haimovsky flow_verbs_query(struct rte_eth_dev *dev,
2042684dafe7SMoti Haimovsky 		 struct rte_flow *flow,
2043684dafe7SMoti Haimovsky 		 const struct rte_flow_action *actions,
2044684dafe7SMoti Haimovsky 		 void *data,
2045684dafe7SMoti Haimovsky 		 struct rte_flow_error *error)
2046684dafe7SMoti Haimovsky {
2047684dafe7SMoti Haimovsky 	int ret = -EINVAL;
2048684dafe7SMoti Haimovsky 
2049684dafe7SMoti Haimovsky 	for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2050684dafe7SMoti Haimovsky 		switch (actions->type) {
2051684dafe7SMoti Haimovsky 		case RTE_FLOW_ACTION_TYPE_VOID:
2052684dafe7SMoti Haimovsky 			break;
2053684dafe7SMoti Haimovsky 		case RTE_FLOW_ACTION_TYPE_COUNT:
205406629d86SViacheslav Ovsiienko 			ret = flow_verbs_counter_query(dev, flow, data, error);
2055684dafe7SMoti Haimovsky 			break;
2056684dafe7SMoti Haimovsky 		default:
2057684dafe7SMoti Haimovsky 			return rte_flow_error_set(error, ENOTSUP,
2058684dafe7SMoti Haimovsky 						  RTE_FLOW_ERROR_TYPE_ACTION,
2059684dafe7SMoti Haimovsky 						  actions,
2060684dafe7SMoti Haimovsky 						  "action not supported");
2061684dafe7SMoti Haimovsky 		}
2062684dafe7SMoti Haimovsky 	}
2063684dafe7SMoti Haimovsky 	return ret;
2064684dafe7SMoti Haimovsky }
2065684dafe7SMoti Haimovsky 
206623f627e0SBing Zhao static int
206723f627e0SBing Zhao flow_verbs_sync_domain(struct rte_eth_dev *dev, uint32_t domains,
206823f627e0SBing Zhao 		       uint32_t flags)
206923f627e0SBing Zhao {
207023f627e0SBing Zhao 	RTE_SET_USED(dev);
207123f627e0SBing Zhao 	RTE_SET_USED(domains);
207223f627e0SBing Zhao 	RTE_SET_USED(flags);
207323f627e0SBing Zhao 
207423f627e0SBing Zhao 	return 0;
207523f627e0SBing Zhao }
207623f627e0SBing Zhao 
20770c76d1c9SYongseok Koh const struct mlx5_flow_driver_ops mlx5_flow_verbs_drv_ops = {
207884c406e7SOri Kam 	.validate = flow_verbs_validate,
207984c406e7SOri Kam 	.prepare = flow_verbs_prepare,
208084c406e7SOri Kam 	.translate = flow_verbs_translate,
208184c406e7SOri Kam 	.apply = flow_verbs_apply,
208284c406e7SOri Kam 	.remove = flow_verbs_remove,
208384c406e7SOri Kam 	.destroy = flow_verbs_destroy,
2084684dafe7SMoti Haimovsky 	.query = flow_verbs_query,
208523f627e0SBing Zhao 	.sync_domain = flow_verbs_sync_domain,
2086c5042f93SDmitry Kozlyuk 	.discover_priorities = flow_verbs_discover_priorities,
208784c406e7SOri Kam };
2088