Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright 2016 6WIND S.A.
3 : : * Copyright 2016 Mellanox Technologies, Ltd
4 : : */
5 : :
6 : : #include <stdalign.h>
7 : : #include <stdint.h>
8 : : #include <string.h>
9 : : #include <stdbool.h>
10 : : #include <sys/queue.h>
11 : :
12 : : #include <eal_export.h>
13 : : #include <rte_common.h>
14 : : #include <rte_ether.h>
15 : : #include <ethdev_driver.h>
16 : : #include <rte_eal_paging.h>
17 : : #include <rte_flow.h>
18 : : #include <rte_cycles.h>
19 : : #include <rte_flow_driver.h>
20 : : #include <rte_malloc.h>
21 : : #include <rte_ip.h>
22 : :
23 : : #include <mlx5_glue.h>
24 : : #include <mlx5_devx_cmds.h>
25 : : #include <mlx5_prm.h>
26 : : #include <mlx5_malloc.h>
27 : :
28 : : #include "mlx5_defs.h"
29 : : #include "mlx5.h"
30 : : #include "mlx5_flow.h"
31 : : #include "mlx5_flow_os.h"
32 : : #include "mlx5_rx.h"
33 : : #include "mlx5_tx.h"
34 : : #include "mlx5_common_os.h"
35 : : #include "rte_pmd_mlx5.h"
36 : :
37 : : const uint64_t mlx5_rss_hash_fields[] = {
38 : : [MLX5_RSS_HASH_IDX_IPV4] = MLX5_RSS_HASH_IPV4,
39 : : [MLX5_RSS_HASH_IDX_IPV4_TCP] = MLX5_RSS_HASH_IPV4_TCP,
40 : : [MLX5_RSS_HASH_IDX_IPV4_UDP] = MLX5_RSS_HASH_IPV4_UDP,
41 : : [MLX5_RSS_HASH_IDX_IPV4_ESP] = MLX5_RSS_HASH_IPV4_ESP,
42 : : [MLX5_RSS_HASH_IDX_IPV6] = MLX5_RSS_HASH_IPV6,
43 : : [MLX5_RSS_HASH_IDX_IPV6_TCP] = MLX5_RSS_HASH_IPV6_TCP,
44 : : [MLX5_RSS_HASH_IDX_IPV6_UDP] = MLX5_RSS_HASH_IPV6_UDP,
45 : : [MLX5_RSS_HASH_IDX_IPV6_ESP] = MLX5_RSS_HASH_IPV6_ESP,
46 : : [MLX5_RSS_HASH_IDX_TCP] = MLX5_TCP_IBV_RX_HASH,
47 : : [MLX5_RSS_HASH_IDX_UDP] = MLX5_UDP_IBV_RX_HASH,
48 : : [MLX5_RSS_HASH_IDX_ESP_SPI] = MLX5_RSS_HASH_ESP_SPI,
49 : : [MLX5_RSS_HASH_IDX_NONE] = MLX5_RSS_HASH_NONE,
50 : : };
51 : :
52 : : /*
53 : : * Shared array for quick translation between port_id and vport mask/values
54 : : * used for HWS rules.
55 : : */
56 : : struct flow_hw_port_info mlx5_flow_hw_port_infos[RTE_MAX_ETHPORTS];
57 : :
58 : : struct tunnel_default_miss_ctx {
59 : : uint16_t *queue;
60 : : __extension__
61 : : union {
62 : : struct rte_flow_action_rss action_rss;
63 : : struct rte_flow_action_queue miss_queue;
64 : : struct rte_flow_action_jump miss_jump;
65 : : uint8_t raw[0];
66 : : };
67 : : };
68 : :
69 : : void
70 : 0 : mlx5_indirect_list_handles_release(struct rte_eth_dev *dev)
71 : : {
72 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
73 : : #ifdef HAVE_MLX5_HWS_SUPPORT
74 : : struct rte_flow_error error;
75 : : #endif
76 : :
77 [ # # ]: 0 : while (!LIST_EMPTY(&priv->indirect_list_head)) {
78 : : struct mlx5_indirect_list *e =
79 : : LIST_FIRST(&priv->indirect_list_head);
80 : :
81 [ # # ]: 0 : LIST_REMOVE(e, entry);
82 [ # # # # ]: 0 : switch (e->type) {
83 : : #ifdef HAVE_MLX5_HWS_SUPPORT
84 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_MIRROR:
85 : 0 : mlx5_hw_mirror_destroy(dev, (struct mlx5_mirror *)e);
86 : 0 : break;
87 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_LEGACY:
88 : 0 : mlx5_destroy_legacy_indirect(dev, e);
89 : 0 : break;
90 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_REFORMAT:
91 : 0 : mlx5_reformat_action_destroy(dev,
92 : : (struct rte_flow_action_list_handle *)e, &error);
93 : 0 : break;
94 : : #endif
95 : 0 : default:
96 : 0 : DRV_LOG(ERR, "invalid indirect list type");
97 : : MLX5_ASSERT(false);
98 : 0 : break;
99 : : }
100 : : }
101 : 0 : }
102 : :
103 : : static int
104 : : flow_tunnel_add_default_miss(struct rte_eth_dev *dev,
105 : : struct rte_flow *flow,
106 : : const struct rte_flow_attr *attr,
107 : : const struct rte_flow_action *app_actions,
108 : : uint32_t flow_idx,
109 : : const struct mlx5_flow_tunnel *tunnel,
110 : : struct tunnel_default_miss_ctx *ctx,
111 : : struct rte_flow_error *error);
112 : : static struct mlx5_flow_tunnel *
113 : : mlx5_find_tunnel_id(struct rte_eth_dev *dev, uint32_t id);
114 : : static void
115 : : mlx5_flow_tunnel_free(struct rte_eth_dev *dev, struct mlx5_flow_tunnel *tunnel);
116 : : static uint32_t
117 : : tunnel_flow_group_to_flow_table(struct rte_eth_dev *dev,
118 : : const struct mlx5_flow_tunnel *tunnel,
119 : : uint32_t group, uint32_t *table,
120 : : struct rte_flow_error *error);
121 : :
122 : : /** Device flow drivers. */
123 : : extern const struct mlx5_flow_driver_ops mlx5_flow_verbs_drv_ops;
124 : :
125 : : const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops;
126 : :
127 : : static const struct mlx5_flow_driver_ops *flow_drv_ops[] = {
128 : : [MLX5_FLOW_TYPE_MIN] = &mlx5_flow_null_drv_ops,
129 : : #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
130 : : [MLX5_FLOW_TYPE_DV] = &mlx5_flow_dv_drv_ops,
131 : : #endif
132 : : #ifdef HAVE_MLX5_HWS_SUPPORT
133 : : [MLX5_FLOW_TYPE_HW] = &mlx5_flow_hw_drv_ops,
134 : : #endif
135 : : [MLX5_FLOW_TYPE_VERBS] = &mlx5_flow_verbs_drv_ops,
136 : : [MLX5_FLOW_TYPE_MAX] = &mlx5_flow_null_drv_ops
137 : : };
138 : :
139 : : /** Helper macro to build input graph for mlx5_flow_expand_rss(). */
140 : : #define MLX5_FLOW_EXPAND_RSS_NEXT(...) \
141 : : (const int []){ \
142 : : __VA_ARGS__, 0, \
143 : : }
144 : :
145 : : /** Node object of input graph for mlx5_flow_expand_rss(). */
146 : : struct mlx5_flow_expand_node {
147 : : const int *const next;
148 : : /**<
149 : : * List of next node indexes. Index 0 is interpreted as a terminator.
150 : : */
151 : : const enum rte_flow_item_type type;
152 : : /**< Pattern item type of current node. */
153 : : uint64_t rss_types;
154 : : /**<
155 : : * RSS types bit-field associated with this node
156 : : * (see RTE_ETH_RSS_* definitions).
157 : : */
158 : : uint64_t node_flags;
159 : : /**<
160 : : * Bit-fields that define how the node is used in the expansion.
161 : : * (see MLX5_EXPANSION_NODE_* definitions).
162 : : */
163 : : };
164 : :
165 : : /** Keep same format with mlx5_flow_expand_rss to share the buffer for expansion. */
166 : : struct mlx5_flow_expand_sqn {
167 : : uint32_t entries; /** Number of entries */
168 : : struct {
169 : : struct rte_flow_item *pattern; /**< Expanded pattern array. */
170 : : uint32_t priority; /**< Priority offset for each expansion. */
171 : : } entry[];
172 : : };
173 : :
174 : : /* Optional expand field. The expansion alg will not go deeper. */
175 : : #define MLX5_EXPANSION_NODE_OPTIONAL (UINT64_C(1) << 0)
176 : :
177 : : /* The node is not added implicitly as expansion to the flow pattern.
178 : : * If the node type does not match the flow pattern item type, the
179 : : * expansion alg will go deeper to its next items.
180 : : * In the current implementation, the list of next nodes indexes can
181 : : * have up to one node with this flag set and it has to be the last
182 : : * node index (before the list terminator).
183 : : */
184 : : #define MLX5_EXPANSION_NODE_EXPLICIT (UINT64_C(1) << 1)
185 : :
186 : : /** Object returned by mlx5_flow_expand_rss(). */
187 : : struct mlx5_flow_expand_rss {
188 : : uint32_t entries;
189 : : /**< Number of entries @p patterns and @p priorities. */
190 : : struct {
191 : : struct rte_flow_item *pattern; /**< Expanded pattern array. */
192 : : uint32_t priority; /**< Priority offset for each expansion. */
193 : : } entry[];
194 : : };
195 : :
196 : : static void
197 : : mlx5_dbg__print_pattern(const struct rte_flow_item *item);
198 : :
199 : : static const struct mlx5_flow_expand_node *
200 : : mlx5_flow_expand_rss_adjust_node(const struct rte_flow_item *pattern,
201 : : unsigned int item_idx,
202 : : const struct mlx5_flow_expand_node graph[],
203 : : const struct mlx5_flow_expand_node *node);
204 : :
205 : : static __rte_always_inline int
206 : : mlx5_need_cache_flow(const struct mlx5_priv *priv,
207 : : const struct rte_flow_attr *attr)
208 : : {
209 [ # # # # : 0 : return priv->isolated && priv->sh->config.dv_flow_en == 1 &&
# # # # ]
210 [ # # # # ]: 0 : (attr ? !attr->group : true) &&
211 [ # # # # : 0 : priv->mode_info.mode == RTE_PMD_MLX5_FLOW_ENGINE_MODE_STANDBY &&
# # # # #
# # # # #
# # ]
212 [ # # # # : 0 : (!priv->sh->config.dv_esw_en || !priv->sh->config.fdb_def_rule);
# # # # ]
213 : : }
214 : :
215 : : static bool
216 : 0 : mlx5_flow_is_rss_expandable_item(const struct rte_flow_item *item)
217 : : {
218 [ # # ]: 0 : switch (item->type) {
219 : : case RTE_FLOW_ITEM_TYPE_ETH:
220 : : case RTE_FLOW_ITEM_TYPE_VLAN:
221 : : case RTE_FLOW_ITEM_TYPE_IPV4:
222 : : case RTE_FLOW_ITEM_TYPE_IPV6:
223 : : case RTE_FLOW_ITEM_TYPE_UDP:
224 : : case RTE_FLOW_ITEM_TYPE_TCP:
225 : : case RTE_FLOW_ITEM_TYPE_ESP:
226 : : case RTE_FLOW_ITEM_TYPE_ICMP:
227 : : case RTE_FLOW_ITEM_TYPE_ICMP6:
228 : : case RTE_FLOW_ITEM_TYPE_VXLAN:
229 : : case RTE_FLOW_ITEM_TYPE_NVGRE:
230 : : case RTE_FLOW_ITEM_TYPE_GRE:
231 : : case RTE_FLOW_ITEM_TYPE_GENEVE:
232 : : case RTE_FLOW_ITEM_TYPE_MPLS:
233 : : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
234 : : case RTE_FLOW_ITEM_TYPE_GRE_KEY:
235 : : case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
236 : : case RTE_FLOW_ITEM_TYPE_GTP:
237 : : return true;
238 : : default:
239 : : break;
240 : : }
241 : 0 : return false;
242 : : }
243 : :
244 : : /**
245 : : * Network Service Header (NSH) and its next protocol values
246 : : * are described in RFC-8393.
247 : : */
248 : : static enum rte_flow_item_type
249 : : mlx5_nsh_proto_to_item_type(uint8_t proto_spec, uint8_t proto_mask)
250 : : {
251 : : enum rte_flow_item_type type;
252 : :
253 : 0 : switch (proto_mask & proto_spec) {
254 : : case 0:
255 : : type = RTE_FLOW_ITEM_TYPE_VOID;
256 : : break;
257 : : case RTE_VXLAN_GPE_TYPE_IPV4:
258 : : type = RTE_FLOW_ITEM_TYPE_IPV4;
259 : : break;
260 : : case RTE_VXLAN_GPE_TYPE_IPV6:
261 : : type = RTE_VXLAN_GPE_TYPE_IPV6;
262 : : break;
263 : : case RTE_VXLAN_GPE_TYPE_ETH:
264 : : type = RTE_FLOW_ITEM_TYPE_ETH;
265 : : break;
266 : : default:
267 : : type = RTE_FLOW_ITEM_TYPE_END;
268 : : }
269 : : return type;
270 : : }
271 : :
272 : : static enum rte_flow_item_type
273 : : mlx5_inet_proto_to_item_type(uint8_t proto_spec, uint8_t proto_mask)
274 : : {
275 : : enum rte_flow_item_type type;
276 : :
277 [ # # # # : 0 : switch (proto_mask & proto_spec) {
# # # # #
# # # #
# ]
278 : : case 0:
279 : : type = RTE_FLOW_ITEM_TYPE_VOID;
280 : : break;
281 : 0 : case IPPROTO_UDP:
282 : : type = RTE_FLOW_ITEM_TYPE_UDP;
283 : 0 : break;
284 : 0 : case IPPROTO_TCP:
285 : : type = RTE_FLOW_ITEM_TYPE_TCP;
286 : 0 : break;
287 : 0 : case IPPROTO_IPIP:
288 : : type = RTE_FLOW_ITEM_TYPE_IPV4;
289 : 0 : break;
290 : 0 : case IPPROTO_IPV6:
291 : : type = RTE_FLOW_ITEM_TYPE_IPV6;
292 : 0 : break;
293 : 0 : case IPPROTO_ESP:
294 : : type = RTE_FLOW_ITEM_TYPE_ESP;
295 : 0 : break;
296 : 0 : default:
297 : : type = RTE_FLOW_ITEM_TYPE_END;
298 : : }
299 : : return type;
300 : : }
301 : :
302 : : static enum rte_flow_item_type
303 : : mlx5_ethertype_to_item_type(rte_be16_t type_spec,
304 : : rte_be16_t type_mask, bool is_tunnel)
305 : : {
306 : : enum rte_flow_item_type type;
307 : :
308 [ # # # # : 0 : switch (rte_be_to_cpu_16(type_spec & type_mask)) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
309 : : case 0:
310 : : type = RTE_FLOW_ITEM_TYPE_VOID;
311 : : break;
312 : 0 : case RTE_ETHER_TYPE_TEB:
313 : : type = is_tunnel ?
314 : : RTE_FLOW_ITEM_TYPE_ETH : RTE_FLOW_ITEM_TYPE_END;
315 : : break;
316 : 0 : case RTE_ETHER_TYPE_VLAN:
317 : : type = !is_tunnel ?
318 : : RTE_FLOW_ITEM_TYPE_VLAN : RTE_FLOW_ITEM_TYPE_END;
319 : : break;
320 : 0 : case RTE_ETHER_TYPE_IPV4:
321 : : type = RTE_FLOW_ITEM_TYPE_IPV4;
322 : 0 : break;
323 : 0 : case RTE_ETHER_TYPE_IPV6:
324 : : type = RTE_FLOW_ITEM_TYPE_IPV6;
325 : 0 : break;
326 : 0 : default:
327 : : type = RTE_FLOW_ITEM_TYPE_END;
328 : : }
329 : : return type;
330 : : }
331 : :
332 : : static enum rte_flow_item_type
333 : 0 : mlx5_flow_expand_rss_item_complete(const struct rte_flow_item *item)
334 : : {
335 : : #define MLX5_XSET_ITEM_MASK_SPEC(type, fld) \
336 : : do { \
337 : : const void *m = item->mask; \
338 : : const void *s = item->spec; \
339 : : mask = m ? \
340 : : ((const struct rte_flow_item_##type *)m)->fld : \
341 : : rte_flow_item_##type##_mask.fld; \
342 : : spec = ((const struct rte_flow_item_##type *)s)->fld; \
343 : : } while (0)
344 : :
345 : : enum rte_flow_item_type ret;
346 : : uint16_t spec, mask;
347 : :
348 [ # # # # ]: 0 : if (item == NULL || item->spec == NULL)
349 : : return RTE_FLOW_ITEM_TYPE_VOID;
350 [ # # # # : 0 : switch (item->type) {
# # # # ]
351 : 0 : case RTE_FLOW_ITEM_TYPE_ETH:
352 [ # # ]: 0 : MLX5_XSET_ITEM_MASK_SPEC(eth, hdr.ether_type);
353 [ # # ]: 0 : if (!mask)
354 : : return RTE_FLOW_ITEM_TYPE_VOID;
355 : : ret = mlx5_ethertype_to_item_type(spec, mask, false);
356 : : break;
357 : 0 : case RTE_FLOW_ITEM_TYPE_VLAN:
358 [ # # ]: 0 : MLX5_XSET_ITEM_MASK_SPEC(vlan, hdr.eth_proto);
359 [ # # ]: 0 : if (!mask)
360 : : return RTE_FLOW_ITEM_TYPE_VOID;
361 : : ret = mlx5_ethertype_to_item_type(spec, mask, false);
362 : : break;
363 : 0 : case RTE_FLOW_ITEM_TYPE_IPV4:
364 [ # # ]: 0 : MLX5_XSET_ITEM_MASK_SPEC(ipv4, hdr.next_proto_id);
365 [ # # ]: 0 : if (!mask)
366 : : return RTE_FLOW_ITEM_TYPE_VOID;
367 : : ret = mlx5_inet_proto_to_item_type(spec, mask);
368 : : break;
369 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6:
370 [ # # ]: 0 : MLX5_XSET_ITEM_MASK_SPEC(ipv6, hdr.proto);
371 [ # # ]: 0 : if (!mask)
372 : : return RTE_FLOW_ITEM_TYPE_VOID;
373 : : ret = mlx5_inet_proto_to_item_type(spec, mask);
374 : : break;
375 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE:
376 [ # # # # ]: 0 : MLX5_XSET_ITEM_MASK_SPEC(geneve, protocol);
377 : : ret = mlx5_ethertype_to_item_type(spec, mask, true);
378 : : break;
379 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
380 [ # # # # ]: 0 : MLX5_XSET_ITEM_MASK_SPEC(gre, protocol);
381 : : ret = mlx5_ethertype_to_item_type(spec, mask, true);
382 : : break;
383 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
384 [ # # ]: 0 : MLX5_XSET_ITEM_MASK_SPEC(vxlan_gpe, hdr.proto);
385 [ # # ]: 0 : ret = mlx5_nsh_proto_to_item_type(spec, mask);
386 : : break;
387 : : default:
388 : : ret = RTE_FLOW_ITEM_TYPE_VOID;
389 : : break;
390 : : }
391 : : return ret;
392 : : #undef MLX5_XSET_ITEM_MASK_SPEC
393 : : }
394 : :
395 : : static const int *
396 : : mlx5_flow_expand_rss_skip_explicit(const struct mlx5_flow_expand_node graph[],
397 : : const int *next_node)
398 : : {
399 : : const struct mlx5_flow_expand_node *node = NULL;
400 : : const int *next = next_node;
401 : :
402 [ # # # # : 0 : while (next && *next) {
# # # # #
# # # # #
# # ]
403 : : /*
404 : : * Skip the nodes with the MLX5_EXPANSION_NODE_EXPLICIT
405 : : * flag set, because they were not found in the flow pattern.
406 : : */
407 : 0 : node = &graph[*next];
408 [ # # # # : 0 : if (!(node->node_flags & MLX5_EXPANSION_NODE_EXPLICIT))
# # # # ]
409 : : break;
410 : 0 : next = node->next;
411 : : }
412 : : return next;
413 : : }
414 : :
415 : : #define MLX5_RSS_EXP_ELT_N 32
416 : :
417 : : /**
418 : : * Expand RSS flows into several possible flows according to the RSS hash
419 : : * fields requested and the driver capabilities.
420 : : *
421 : : * @param[out] buf
422 : : * Buffer to store the result expansion.
423 : : * @param[in] size
424 : : * Buffer size in bytes. If 0, @p buf can be NULL.
425 : : * @param[in] pattern
426 : : * User flow pattern.
427 : : * @param[in] types
428 : : * RSS types to expand (see RTE_ETH_RSS_* definitions).
429 : : * @param[in] graph
430 : : * Input graph to expand @p pattern according to @p types.
431 : : * @param[in] graph_root_index
432 : : * Index of root node in @p graph, typically 0.
433 : : *
434 : : * @return
435 : : * A positive value representing the size of @p buf in bytes regardless of
436 : : * @p size on success, a negative errno value otherwise and rte_errno is
437 : : * set, the following errors are defined:
438 : : *
439 : : * -E2BIG: graph-depth @p graph is too deep.
440 : : * -EINVAL: @p size has not enough space for expanded pattern.
441 : : */
442 : : static int
443 : 0 : mlx5_flow_expand_rss(struct mlx5_flow_expand_rss *buf, size_t size,
444 : : const struct rte_flow_item *pattern, uint64_t types,
445 : : const struct mlx5_flow_expand_node graph[],
446 : : int graph_root_index)
447 : : {
448 : : const struct rte_flow_item *item;
449 [ # # ]: 0 : const struct mlx5_flow_expand_node *node = &graph[graph_root_index];
450 : : const int *next_node;
451 : : const int *stack[MLX5_RSS_EXP_ELT_N];
452 : : int stack_pos = 0;
453 : : struct rte_flow_item flow_items[MLX5_RSS_EXP_ELT_N];
454 : : unsigned int i, item_idx, last_expand_item_idx = 0;
455 : : size_t lsize;
456 : : size_t user_pattern_size = 0;
457 : : void *addr = NULL;
458 : : const struct mlx5_flow_expand_node *next = NULL;
459 : : struct rte_flow_item missed_item;
460 : : int missed = 0;
461 : : int elt = 0;
462 : : const struct rte_flow_item *last_expand_item = NULL;
463 : :
464 : : memset(&missed_item, 0, sizeof(missed_item));
465 : : lsize = offsetof(struct mlx5_flow_expand_rss, entry) +
466 : : MLX5_RSS_EXP_ELT_N * sizeof(buf->entry[0]);
467 [ # # ]: 0 : if (lsize > size)
468 : : return -EINVAL;
469 : 0 : buf->entry[0].priority = 0;
470 : 0 : buf->entry[0].pattern = (void *)&buf->entry[MLX5_RSS_EXP_ELT_N];
471 : 0 : buf->entries = 0;
472 : : addr = buf->entry[0].pattern;
473 : 0 : for (item = pattern, item_idx = 0;
474 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_END;
475 : 0 : item++, item_idx++) {
476 [ # # ]: 0 : if (!mlx5_flow_is_rss_expandable_item(item)) {
477 : 0 : user_pattern_size += sizeof(*item);
478 : 0 : continue;
479 : : }
480 : : last_expand_item = item;
481 : : last_expand_item_idx = item_idx;
482 : : i = 0;
483 [ # # # # ]: 0 : while (node->next && node->next[i]) {
484 : 0 : next = &graph[node->next[i]];
485 [ # # ]: 0 : if (next->type == item->type)
486 : : break;
487 [ # # ]: 0 : if (next->node_flags & MLX5_EXPANSION_NODE_EXPLICIT) {
488 : : node = next;
489 : : i = 0;
490 : : } else {
491 : 0 : ++i;
492 : : }
493 : : }
494 [ # # ]: 0 : if (next)
495 : : node = next;
496 : 0 : user_pattern_size += sizeof(*item);
497 : : }
498 : 0 : user_pattern_size += sizeof(*item); /* Handle END item. */
499 : 0 : lsize += user_pattern_size;
500 [ # # ]: 0 : if (lsize > size)
501 : : return -EINVAL;
502 : : /* Copy the user pattern in the first entry of the buffer. */
503 : : rte_memcpy(addr, pattern, user_pattern_size);
504 : 0 : addr = (void *)(((uintptr_t)addr) + user_pattern_size);
505 : 0 : buf->entries = 1;
506 : : /* Start expanding. */
507 : : memset(flow_items, 0, sizeof(flow_items));
508 : : user_pattern_size -= sizeof(*item);
509 : : /*
510 : : * Check if the last valid item has spec set, need complete pattern,
511 : : * and the pattern can be used for expansion.
512 : : */
513 : 0 : missed_item.type = mlx5_flow_expand_rss_item_complete(last_expand_item);
514 [ # # ]: 0 : if (missed_item.type == RTE_FLOW_ITEM_TYPE_END) {
515 : : /* Item type END indicates expansion is not required. */
516 : 0 : return lsize;
517 : : }
518 [ # # ]: 0 : if (missed_item.type != RTE_FLOW_ITEM_TYPE_VOID) {
519 : : next = NULL;
520 : : missed = 1;
521 : : i = 0;
522 [ # # # # ]: 0 : while (node->next && node->next[i]) {
523 : 0 : next = &graph[node->next[i]];
524 [ # # ]: 0 : if (next->type == missed_item.type) {
525 : 0 : flow_items[0].type = missed_item.type;
526 : : flow_items[1].type = RTE_FLOW_ITEM_TYPE_END;
527 : 0 : break;
528 : : }
529 [ # # ]: 0 : if (next->node_flags & MLX5_EXPANSION_NODE_EXPLICIT) {
530 : : node = next;
531 : : i = 0;
532 : : } else {
533 : 0 : ++i;
534 : : }
535 : : next = NULL;
536 : : }
537 : : }
538 [ # # ]: 0 : if (next && missed) {
539 : : elt = 2; /* missed item + item end. */
540 : : node = next;
541 : 0 : lsize += elt * sizeof(*item) + user_pattern_size;
542 [ # # ]: 0 : if (lsize > size)
543 : : return -EINVAL;
544 [ # # ]: 0 : if (node->rss_types & types) {
545 : 0 : buf->entry[buf->entries].priority = 1;
546 : 0 : buf->entry[buf->entries].pattern = addr;
547 : 0 : buf->entries++;
548 [ # # ]: 0 : rte_memcpy(addr, buf->entry[0].pattern,
549 : : user_pattern_size);
550 : 0 : addr = (void *)(((uintptr_t)addr) + user_pattern_size);
551 : : rte_memcpy(addr, flow_items, elt * sizeof(*item));
552 : 0 : addr = (void *)(((uintptr_t)addr) +
553 : : elt * sizeof(*item));
554 : : }
555 [ # # ]: 0 : } else if (last_expand_item != NULL) {
556 : 0 : node = mlx5_flow_expand_rss_adjust_node(pattern,
557 : : last_expand_item_idx, graph, node);
558 : : }
559 : : memset(flow_items, 0, sizeof(flow_items));
560 : : next_node = mlx5_flow_expand_rss_skip_explicit(graph,
561 : 0 : node->next);
562 : 0 : stack[stack_pos] = next_node;
563 [ # # ]: 0 : node = next_node ? &graph[*next_node] : NULL;
564 [ # # ]: 0 : while (node) {
565 : 0 : flow_items[stack_pos].type = node->type;
566 [ # # ]: 0 : if (node->rss_types & types) {
567 : : size_t n;
568 : : /*
569 : : * compute the number of items to copy from the
570 : : * expansion and copy it.
571 : : * When the stack_pos is 0, there are 1 element in it,
572 : : * plus the addition END item.
573 : : */
574 : 0 : elt = stack_pos + 2;
575 : 0 : flow_items[stack_pos + 1].type = RTE_FLOW_ITEM_TYPE_END;
576 : 0 : lsize += elt * sizeof(*item) + user_pattern_size;
577 [ # # ]: 0 : if (lsize > size)
578 : : return -EINVAL;
579 : : n = elt * sizeof(*item);
580 : : MLX5_ASSERT((buf->entries) < MLX5_RSS_EXP_ELT_N);
581 : 0 : buf->entry[buf->entries].priority =
582 : 0 : stack_pos + 1 + missed;
583 : 0 : buf->entry[buf->entries].pattern = addr;
584 : 0 : buf->entries++;
585 [ # # ]: 0 : rte_memcpy(addr, buf->entry[0].pattern,
586 : : user_pattern_size);
587 : 0 : addr = (void *)(((uintptr_t)addr) +
588 : : user_pattern_size);
589 [ # # ]: 0 : rte_memcpy(addr, &missed_item,
590 : : missed * sizeof(*item));
591 [ # # ]: 0 : addr = (void *)(((uintptr_t)addr) +
592 : : missed * sizeof(*item));
593 : : rte_memcpy(addr, flow_items, n);
594 : 0 : addr = (void *)(((uintptr_t)addr) + n);
595 : : }
596 : : /* Go deeper. */
597 [ # # ]: 0 : if (!(node->node_flags & MLX5_EXPANSION_NODE_OPTIONAL) &&
598 [ # # ]: 0 : node->next) {
599 : : next_node = mlx5_flow_expand_rss_skip_explicit(graph,
600 : : node->next);
601 [ # # ]: 0 : if (stack_pos++ == MLX5_RSS_EXP_ELT_N) {
602 : 0 : rte_errno = E2BIG;
603 : 0 : return -rte_errno;
604 : : }
605 : 0 : stack[stack_pos] = next_node;
606 [ # # ]: 0 : } else if (*(next_node + 1)) {
607 : : /* Follow up with the next possibility. */
608 : 0 : next_node = mlx5_flow_expand_rss_skip_explicit(graph,
609 : : ++next_node);
610 [ # # ]: 0 : } else if (!stack_pos) {
611 : : /*
612 : : * Completing the traverse over the different paths.
613 : : * The next_node is advanced to the terminator.
614 : : */
615 : 0 : ++next_node;
616 : : } else {
617 : : /* Move to the next path. */
618 [ # # ]: 0 : while (stack_pos) {
619 : 0 : next_node = stack[--stack_pos];
620 : 0 : next_node++;
621 [ # # ]: 0 : if (*next_node)
622 : : break;
623 : : }
624 : : next_node = mlx5_flow_expand_rss_skip_explicit(graph,
625 : : next_node);
626 : 0 : stack[stack_pos] = next_node;
627 : : }
628 [ # # # # ]: 0 : node = next_node && *next_node ? &graph[*next_node] : NULL;
629 : : };
630 : 0 : return lsize;
631 : : }
632 : :
633 : : /**
634 : : * Expand SQN flows into several possible flows according to the Tx queue
635 : : * number
636 : : *
637 : : * @param[in] buf
638 : : * Buffer to store the result expansion.
639 : : * @param[in] size
640 : : * Buffer size in bytes. If 0, @p buf can be NULL.
641 : : * @param[in] pattern
642 : : * User flow pattern.
643 : : * @param[in] sq_specs
644 : : * Buffer to store sq spec.
645 : : *
646 : : * @return
647 : : * 0 for success and negative value for failure
648 : : *
649 : : */
650 : : static int
651 : 0 : mlx5_flow_expand_sqn(struct mlx5_flow_expand_sqn *buf, size_t size,
652 : : const struct rte_flow_item *pattern,
653 : : struct mlx5_rte_flow_item_sq *sq_specs)
654 : : {
655 : : const struct rte_flow_item *item;
656 : : bool port_representor = false;
657 : : size_t user_pattern_size = 0;
658 : : struct rte_eth_dev *dev;
659 : : struct mlx5_priv *priv;
660 : : void *addr = NULL;
661 : : uint16_t port_id;
662 : : size_t lsize;
663 : : int elt = 2;
664 : : uint16_t i;
665 : :
666 : 0 : buf->entries = 0;
667 [ # # ]: 0 : for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
668 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR) {
669 : 0 : const struct rte_flow_item_ethdev *pid_v = item->spec;
670 : :
671 [ # # ]: 0 : if (!pid_v)
672 : : return 0;
673 : 0 : port_id = pid_v->port_id;
674 : : port_representor = true;
675 : : }
676 : 0 : user_pattern_size += sizeof(*item);
677 : : }
678 [ # # ]: 0 : if (!port_representor)
679 : : return 0;
680 : 0 : dev = &rte_eth_devices[port_id];
681 : 0 : priv = dev->data->dev_private;
682 : 0 : buf->entry[0].pattern = (void *)&buf->entry[priv->txqs_n];
683 : 0 : lsize = offsetof(struct mlx5_flow_expand_sqn, entry) +
684 : 0 : sizeof(buf->entry[0]) * priv->txqs_n;
685 [ # # ]: 0 : if (lsize + (user_pattern_size + sizeof(struct rte_flow_item) * elt) * priv->txqs_n > size)
686 : : return -EINVAL;
687 : : addr = buf->entry[0].pattern;
688 [ # # ]: 0 : for (i = 0; i != priv->txqs_n; ++i) {
689 : 0 : struct rte_flow_item pattern_add[] = {
690 : : {
691 : : .type = (enum rte_flow_item_type)
692 : : MLX5_RTE_FLOW_ITEM_TYPE_SQ,
693 : 0 : .spec = &sq_specs[i],
694 : : },
695 : : {
696 : : .type = RTE_FLOW_ITEM_TYPE_END,
697 : : },
698 : : };
699 : 0 : struct mlx5_txq_ctrl *txq = mlx5_txq_get(dev, i);
700 : :
701 [ # # ]: 0 : if (txq == NULL)
702 : 0 : return -EINVAL;
703 : 0 : buf->entry[i].pattern = addr;
704 : 0 : sq_specs[i].queue = mlx5_txq_get_sqn(txq);
705 : 0 : mlx5_txq_release(dev, i);
706 : : rte_memcpy(addr, pattern, user_pattern_size);
707 : 0 : addr = (void *)(((uintptr_t)addr) + user_pattern_size);
708 : : rte_memcpy(addr, pattern_add, sizeof(struct rte_flow_item) * elt);
709 : 0 : addr = (void *)(((uintptr_t)addr) + sizeof(struct rte_flow_item) * elt);
710 : 0 : buf->entries++;
711 : : }
712 : : return 0;
713 : : }
714 : :
715 : : enum mlx5_expansion {
716 : : MLX5_EXPANSION_ROOT,
717 : : MLX5_EXPANSION_ROOT_OUTER,
718 : : MLX5_EXPANSION_OUTER_ETH,
719 : : MLX5_EXPANSION_OUTER_VLAN,
720 : : MLX5_EXPANSION_OUTER_IPV4,
721 : : MLX5_EXPANSION_OUTER_IPV4_UDP,
722 : : MLX5_EXPANSION_OUTER_IPV4_TCP,
723 : : MLX5_EXPANSION_OUTER_IPV4_ESP,
724 : : MLX5_EXPANSION_OUTER_IPV4_ICMP,
725 : : MLX5_EXPANSION_OUTER_IPV6,
726 : : MLX5_EXPANSION_OUTER_IPV6_UDP,
727 : : MLX5_EXPANSION_OUTER_IPV6_TCP,
728 : : MLX5_EXPANSION_OUTER_IPV6_ESP,
729 : : MLX5_EXPANSION_OUTER_IPV6_ICMP6,
730 : : MLX5_EXPANSION_VXLAN,
731 : : MLX5_EXPANSION_STD_VXLAN,
732 : : MLX5_EXPANSION_L3_VXLAN,
733 : : MLX5_EXPANSION_VXLAN_GPE,
734 : : MLX5_EXPANSION_GRE,
735 : : MLX5_EXPANSION_NVGRE,
736 : : MLX5_EXPANSION_GRE_KEY,
737 : : MLX5_EXPANSION_MPLS,
738 : : MLX5_EXPANSION_ETH,
739 : : MLX5_EXPANSION_VLAN,
740 : : MLX5_EXPANSION_IPV4,
741 : : MLX5_EXPANSION_IPV4_UDP,
742 : : MLX5_EXPANSION_IPV4_TCP,
743 : : MLX5_EXPANSION_IPV4_ESP,
744 : : MLX5_EXPANSION_IPV4_ICMP,
745 : : MLX5_EXPANSION_IPV6,
746 : : MLX5_EXPANSION_IPV6_UDP,
747 : : MLX5_EXPANSION_IPV6_TCP,
748 : : MLX5_EXPANSION_IPV6_ESP,
749 : : MLX5_EXPANSION_IPV6_ICMP6,
750 : : MLX5_EXPANSION_IPV6_FRAG_EXT,
751 : : MLX5_EXPANSION_GTP,
752 : : MLX5_EXPANSION_GENEVE,
753 : : };
754 : :
755 : : /** Supported expansion of items. */
756 : : static const struct mlx5_flow_expand_node mlx5_support_expansion[] = {
757 : : [MLX5_EXPANSION_ROOT] = {
758 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
759 : : MLX5_EXPANSION_IPV4,
760 : : MLX5_EXPANSION_IPV6),
761 : : .type = RTE_FLOW_ITEM_TYPE_END,
762 : : },
763 : : [MLX5_EXPANSION_ROOT_OUTER] = {
764 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH,
765 : : MLX5_EXPANSION_OUTER_IPV4,
766 : : MLX5_EXPANSION_OUTER_IPV6),
767 : : .type = RTE_FLOW_ITEM_TYPE_END,
768 : : },
769 : : [MLX5_EXPANSION_OUTER_ETH] = {
770 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_VLAN),
771 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
772 : : .rss_types = 0,
773 : : },
774 : : [MLX5_EXPANSION_OUTER_VLAN] = {
775 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
776 : : MLX5_EXPANSION_OUTER_IPV6),
777 : : .type = RTE_FLOW_ITEM_TYPE_VLAN,
778 : : .node_flags = MLX5_EXPANSION_NODE_EXPLICIT,
779 : : },
780 : : [MLX5_EXPANSION_OUTER_IPV4] = {
781 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT
782 : : (MLX5_EXPANSION_OUTER_IPV4_UDP,
783 : : MLX5_EXPANSION_OUTER_IPV4_TCP,
784 : : MLX5_EXPANSION_OUTER_IPV4_ESP,
785 : : MLX5_EXPANSION_OUTER_IPV4_ICMP,
786 : : MLX5_EXPANSION_GRE,
787 : : MLX5_EXPANSION_NVGRE,
788 : : MLX5_EXPANSION_IPV4,
789 : : MLX5_EXPANSION_IPV6),
790 : : .type = RTE_FLOW_ITEM_TYPE_IPV4,
791 : : .rss_types = RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_FRAG_IPV4 |
792 : : RTE_ETH_RSS_NONFRAG_IPV4_OTHER,
793 : : },
794 : : [MLX5_EXPANSION_OUTER_IPV4_UDP] = {
795 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
796 : : MLX5_EXPANSION_VXLAN_GPE,
797 : : MLX5_EXPANSION_MPLS,
798 : : MLX5_EXPANSION_GENEVE,
799 : : MLX5_EXPANSION_GTP),
800 : : .type = RTE_FLOW_ITEM_TYPE_UDP,
801 : : .rss_types = RTE_ETH_RSS_NONFRAG_IPV4_UDP,
802 : : },
803 : : [MLX5_EXPANSION_OUTER_IPV4_TCP] = {
804 : : .type = RTE_FLOW_ITEM_TYPE_TCP,
805 : : .rss_types = RTE_ETH_RSS_NONFRAG_IPV4_TCP,
806 : : },
807 : : [MLX5_EXPANSION_OUTER_IPV4_ESP] = {
808 : : .type = RTE_FLOW_ITEM_TYPE_ESP,
809 : : .rss_types = RTE_ETH_RSS_ESP,
810 : : },
811 : : [MLX5_EXPANSION_OUTER_IPV4_ICMP] = {
812 : : .type = RTE_FLOW_ITEM_TYPE_ICMP,
813 : : },
814 : : [MLX5_EXPANSION_OUTER_IPV6] = {
815 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT
816 : : (MLX5_EXPANSION_OUTER_IPV6_UDP,
817 : : MLX5_EXPANSION_OUTER_IPV6_TCP,
818 : : MLX5_EXPANSION_OUTER_IPV6_ESP,
819 : : MLX5_EXPANSION_OUTER_IPV6_ICMP6,
820 : : MLX5_EXPANSION_IPV4,
821 : : MLX5_EXPANSION_IPV6,
822 : : MLX5_EXPANSION_GRE,
823 : : MLX5_EXPANSION_NVGRE),
824 : : .type = RTE_FLOW_ITEM_TYPE_IPV6,
825 : : .rss_types = RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_FRAG_IPV6 |
826 : : RTE_ETH_RSS_NONFRAG_IPV6_OTHER,
827 : : },
828 : : [MLX5_EXPANSION_OUTER_IPV6_UDP] = {
829 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
830 : : MLX5_EXPANSION_VXLAN_GPE,
831 : : MLX5_EXPANSION_MPLS,
832 : : MLX5_EXPANSION_GENEVE,
833 : : MLX5_EXPANSION_GTP),
834 : : .type = RTE_FLOW_ITEM_TYPE_UDP,
835 : : .rss_types = RTE_ETH_RSS_NONFRAG_IPV6_UDP,
836 : : },
837 : : [MLX5_EXPANSION_OUTER_IPV6_TCP] = {
838 : : .type = RTE_FLOW_ITEM_TYPE_TCP,
839 : : .rss_types = RTE_ETH_RSS_NONFRAG_IPV6_TCP,
840 : : },
841 : : [MLX5_EXPANSION_OUTER_IPV6_ESP] = {
842 : : .type = RTE_FLOW_ITEM_TYPE_ESP,
843 : : .rss_types = RTE_ETH_RSS_ESP,
844 : : },
845 : : [MLX5_EXPANSION_OUTER_IPV6_ICMP6] = {
846 : : .type = RTE_FLOW_ITEM_TYPE_ICMP6,
847 : : },
848 : : [MLX5_EXPANSION_VXLAN] = {
849 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
850 : : MLX5_EXPANSION_IPV4,
851 : : MLX5_EXPANSION_IPV6),
852 : : .type = RTE_FLOW_ITEM_TYPE_VXLAN,
853 : : },
854 : : [MLX5_EXPANSION_STD_VXLAN] = {
855 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH),
856 : : .type = RTE_FLOW_ITEM_TYPE_VXLAN,
857 : : },
858 : : [MLX5_EXPANSION_L3_VXLAN] = {
859 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
860 : : MLX5_EXPANSION_IPV6),
861 : : .type = RTE_FLOW_ITEM_TYPE_VXLAN,
862 : : },
863 : : [MLX5_EXPANSION_VXLAN_GPE] = {
864 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
865 : : MLX5_EXPANSION_IPV4,
866 : : MLX5_EXPANSION_IPV6),
867 : : .type = RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
868 : : },
869 : : [MLX5_EXPANSION_GRE] = {
870 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
871 : : MLX5_EXPANSION_IPV4,
872 : : MLX5_EXPANSION_IPV6,
873 : : MLX5_EXPANSION_GRE_KEY,
874 : : MLX5_EXPANSION_MPLS),
875 : : .type = RTE_FLOW_ITEM_TYPE_GRE,
876 : : },
877 : : [MLX5_EXPANSION_GRE_KEY] = {
878 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
879 : : MLX5_EXPANSION_IPV6,
880 : : MLX5_EXPANSION_MPLS),
881 : : .type = RTE_FLOW_ITEM_TYPE_GRE_KEY,
882 : : .node_flags = MLX5_EXPANSION_NODE_OPTIONAL,
883 : : },
884 : : [MLX5_EXPANSION_NVGRE] = {
885 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH),
886 : : .type = RTE_FLOW_ITEM_TYPE_NVGRE,
887 : : },
888 : : [MLX5_EXPANSION_MPLS] = {
889 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
890 : : MLX5_EXPANSION_IPV6,
891 : : MLX5_EXPANSION_ETH),
892 : : .type = RTE_FLOW_ITEM_TYPE_MPLS,
893 : : .node_flags = MLX5_EXPANSION_NODE_OPTIONAL,
894 : : },
895 : : [MLX5_EXPANSION_ETH] = {
896 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VLAN),
897 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
898 : : },
899 : : [MLX5_EXPANSION_VLAN] = {
900 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
901 : : MLX5_EXPANSION_IPV6),
902 : : .type = RTE_FLOW_ITEM_TYPE_VLAN,
903 : : .node_flags = MLX5_EXPANSION_NODE_EXPLICIT,
904 : : },
905 : : [MLX5_EXPANSION_IPV4] = {
906 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4_UDP,
907 : : MLX5_EXPANSION_IPV4_TCP,
908 : : MLX5_EXPANSION_IPV4_ESP,
909 : : MLX5_EXPANSION_IPV4_ICMP),
910 : : .type = RTE_FLOW_ITEM_TYPE_IPV4,
911 : : .rss_types = RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_FRAG_IPV4 |
912 : : RTE_ETH_RSS_NONFRAG_IPV4_OTHER,
913 : : },
914 : : [MLX5_EXPANSION_IPV4_UDP] = {
915 : : .type = RTE_FLOW_ITEM_TYPE_UDP,
916 : : .rss_types = RTE_ETH_RSS_NONFRAG_IPV4_UDP,
917 : : },
918 : : [MLX5_EXPANSION_IPV4_TCP] = {
919 : : .type = RTE_FLOW_ITEM_TYPE_TCP,
920 : : .rss_types = RTE_ETH_RSS_NONFRAG_IPV4_TCP,
921 : : },
922 : : [MLX5_EXPANSION_IPV4_ESP] = {
923 : : .type = RTE_FLOW_ITEM_TYPE_ESP,
924 : : .rss_types = RTE_ETH_RSS_ESP,
925 : : },
926 : : [MLX5_EXPANSION_IPV4_ICMP] = {
927 : : .type = RTE_FLOW_ITEM_TYPE_ICMP,
928 : : },
929 : : [MLX5_EXPANSION_IPV6] = {
930 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV6_UDP,
931 : : MLX5_EXPANSION_IPV6_TCP,
932 : : MLX5_EXPANSION_IPV6_ESP,
933 : : MLX5_EXPANSION_IPV6_ICMP6,
934 : : MLX5_EXPANSION_IPV6_FRAG_EXT),
935 : : .type = RTE_FLOW_ITEM_TYPE_IPV6,
936 : : .rss_types = RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_FRAG_IPV6 |
937 : : RTE_ETH_RSS_NONFRAG_IPV6_OTHER,
938 : : },
939 : : [MLX5_EXPANSION_IPV6_UDP] = {
940 : : .type = RTE_FLOW_ITEM_TYPE_UDP,
941 : : .rss_types = RTE_ETH_RSS_NONFRAG_IPV6_UDP,
942 : : },
943 : : [MLX5_EXPANSION_IPV6_TCP] = {
944 : : .type = RTE_FLOW_ITEM_TYPE_TCP,
945 : : .rss_types = RTE_ETH_RSS_NONFRAG_IPV6_TCP,
946 : : },
947 : : [MLX5_EXPANSION_IPV6_ESP] = {
948 : : .type = RTE_FLOW_ITEM_TYPE_ESP,
949 : : .rss_types = RTE_ETH_RSS_ESP,
950 : : },
951 : : [MLX5_EXPANSION_IPV6_FRAG_EXT] = {
952 : : .type = RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT,
953 : : },
954 : : [MLX5_EXPANSION_IPV6_ICMP6] = {
955 : : .type = RTE_FLOW_ITEM_TYPE_ICMP6,
956 : : },
957 : : [MLX5_EXPANSION_GTP] = {
958 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
959 : : MLX5_EXPANSION_IPV6),
960 : : .type = RTE_FLOW_ITEM_TYPE_GTP,
961 : : },
962 : : [MLX5_EXPANSION_GENEVE] = {
963 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
964 : : MLX5_EXPANSION_IPV4,
965 : : MLX5_EXPANSION_IPV6),
966 : : .type = RTE_FLOW_ITEM_TYPE_GENEVE,
967 : : },
968 : : };
969 : :
970 : : static struct rte_flow_action_handle *
971 : : mlx5_action_handle_create(struct rte_eth_dev *dev,
972 : : const struct rte_flow_indir_action_conf *conf,
973 : : const struct rte_flow_action *action,
974 : : struct rte_flow_error *error);
975 : : static int mlx5_action_handle_destroy
976 : : (struct rte_eth_dev *dev,
977 : : struct rte_flow_action_handle *handle,
978 : : struct rte_flow_error *error);
979 : : static int mlx5_action_handle_update
980 : : (struct rte_eth_dev *dev,
981 : : struct rte_flow_action_handle *handle,
982 : : const void *update,
983 : : struct rte_flow_error *error);
984 : : static int mlx5_action_handle_query
985 : : (struct rte_eth_dev *dev,
986 : : const struct rte_flow_action_handle *handle,
987 : : void *data,
988 : : struct rte_flow_error *error);
989 : : static int
990 : : mlx5_flow_tunnel_decap_set(struct rte_eth_dev *dev,
991 : : struct rte_flow_tunnel *app_tunnel,
992 : : struct rte_flow_action **actions,
993 : : uint32_t *num_of_actions,
994 : : struct rte_flow_error *error);
995 : : static int
996 : : mlx5_flow_tunnel_match(struct rte_eth_dev *dev,
997 : : struct rte_flow_tunnel *app_tunnel,
998 : : struct rte_flow_item **items,
999 : : uint32_t *num_of_items,
1000 : : struct rte_flow_error *error);
1001 : : static int
1002 : : mlx5_flow_tunnel_item_release(struct rte_eth_dev *dev,
1003 : : struct rte_flow_item *pmd_items,
1004 : : uint32_t num_items, struct rte_flow_error *err);
1005 : : static int
1006 : : mlx5_flow_tunnel_action_release(struct rte_eth_dev *dev,
1007 : : struct rte_flow_action *pmd_actions,
1008 : : uint32_t num_actions,
1009 : : struct rte_flow_error *err);
1010 : : static int
1011 : : mlx5_flow_tunnel_get_restore_info(struct rte_eth_dev *dev,
1012 : : struct rte_mbuf *m,
1013 : : struct rte_flow_restore_info *info,
1014 : : struct rte_flow_error *err);
1015 : : static struct rte_flow_item_flex_handle *
1016 : : mlx5_flow_flex_item_create(struct rte_eth_dev *dev,
1017 : : const struct rte_flow_item_flex_conf *conf,
1018 : : struct rte_flow_error *error);
1019 : : static int
1020 : : mlx5_flow_flex_item_release(struct rte_eth_dev *dev,
1021 : : const struct rte_flow_item_flex_handle *handle,
1022 : : struct rte_flow_error *error);
1023 : : static int
1024 : : mlx5_flow_info_get(struct rte_eth_dev *dev,
1025 : : struct rte_flow_port_info *port_info,
1026 : : struct rte_flow_queue_info *queue_info,
1027 : : struct rte_flow_error *error);
1028 : : static int
1029 : : mlx5_flow_port_configure(struct rte_eth_dev *dev,
1030 : : const struct rte_flow_port_attr *port_attr,
1031 : : uint16_t nb_queue,
1032 : : const struct rte_flow_queue_attr *queue_attr[],
1033 : : struct rte_flow_error *err);
1034 : :
1035 : : static struct rte_flow_pattern_template *
1036 : : mlx5_flow_pattern_template_create(struct rte_eth_dev *dev,
1037 : : const struct rte_flow_pattern_template_attr *attr,
1038 : : const struct rte_flow_item items[],
1039 : : struct rte_flow_error *error);
1040 : :
1041 : : static int
1042 : : mlx5_flow_pattern_template_destroy(struct rte_eth_dev *dev,
1043 : : struct rte_flow_pattern_template *template,
1044 : : struct rte_flow_error *error);
1045 : : static struct rte_flow_actions_template *
1046 : : mlx5_flow_actions_template_create(struct rte_eth_dev *dev,
1047 : : const struct rte_flow_actions_template_attr *attr,
1048 : : const struct rte_flow_action actions[],
1049 : : const struct rte_flow_action masks[],
1050 : : struct rte_flow_error *error);
1051 : : static int
1052 : : mlx5_flow_actions_template_destroy(struct rte_eth_dev *dev,
1053 : : struct rte_flow_actions_template *template,
1054 : : struct rte_flow_error *error);
1055 : :
1056 : : static struct rte_flow_template_table *
1057 : : mlx5_flow_table_create(struct rte_eth_dev *dev,
1058 : : const struct rte_flow_template_table_attr *attr,
1059 : : struct rte_flow_pattern_template *item_templates[],
1060 : : uint8_t nb_item_templates,
1061 : : struct rte_flow_actions_template *action_templates[],
1062 : : uint8_t nb_action_templates,
1063 : : struct rte_flow_error *error);
1064 : : static int
1065 : : mlx5_flow_table_destroy(struct rte_eth_dev *dev,
1066 : : struct rte_flow_template_table *table,
1067 : : struct rte_flow_error *error);
1068 : : static int
1069 : : mlx5_flow_group_set_miss_actions(struct rte_eth_dev *dev,
1070 : : uint32_t group_id,
1071 : : const struct rte_flow_group_attr *attr,
1072 : : const struct rte_flow_action actions[],
1073 : : struct rte_flow_error *error);
1074 : :
1075 : : static int
1076 : : mlx5_action_handle_query_update(struct rte_eth_dev *dev,
1077 : : struct rte_flow_action_handle *handle,
1078 : : const void *update, void *query,
1079 : : enum rte_flow_query_update_mode qu_mode,
1080 : : struct rte_flow_error *error);
1081 : :
1082 : : static struct rte_flow_action_list_handle *
1083 : : mlx5_action_list_handle_create(struct rte_eth_dev *dev,
1084 : : const struct rte_flow_indir_action_conf *conf,
1085 : : const struct rte_flow_action *actions,
1086 : : struct rte_flow_error *error);
1087 : :
1088 : : static int
1089 : : mlx5_action_list_handle_destroy(struct rte_eth_dev *dev,
1090 : : struct rte_flow_action_list_handle *handle,
1091 : : struct rte_flow_error *error);
1092 : :
1093 : : static int
1094 : : mlx5_flow_action_list_handle_query_update(struct rte_eth_dev *dev,
1095 : : const
1096 : : struct rte_flow_action_list_handle *handle,
1097 : : const void **update, void **query,
1098 : : enum rte_flow_query_update_mode mode,
1099 : : struct rte_flow_error *error);
1100 : :
1101 : : static int
1102 : : mlx5_flow_calc_table_hash(struct rte_eth_dev *dev,
1103 : : const struct rte_flow_template_table *table,
1104 : : const struct rte_flow_item pattern[],
1105 : : uint8_t pattern_template_index,
1106 : : uint32_t *hash, struct rte_flow_error *error);
1107 : : static int
1108 : : mlx5_flow_calc_encap_hash(struct rte_eth_dev *dev,
1109 : : const struct rte_flow_item pattern[],
1110 : : enum rte_flow_encap_hash_field dest_field,
1111 : : uint8_t *hash,
1112 : : struct rte_flow_error *error);
1113 : :
1114 : : static int
1115 : : mlx5_template_table_resize(struct rte_eth_dev *dev,
1116 : : struct rte_flow_template_table *table,
1117 : : uint32_t nb_rules, struct rte_flow_error *error);
1118 : : static int
1119 : : mlx5_flow_async_update_resized(struct rte_eth_dev *dev, uint32_t queue,
1120 : : const struct rte_flow_op_attr *attr,
1121 : : struct rte_flow *rule, void *user_data,
1122 : : struct rte_flow_error *error);
1123 : : static int
1124 : : mlx5_table_resize_complete(struct rte_eth_dev *dev,
1125 : : struct rte_flow_template_table *table,
1126 : : struct rte_flow_error *error);
1127 : :
1128 : : static const struct rte_flow_ops mlx5_flow_ops = {
1129 : : .validate = mlx5_flow_validate,
1130 : : .create = mlx5_flow_create,
1131 : : .destroy = mlx5_flow_destroy,
1132 : : .flush = mlx5_flow_flush,
1133 : : .isolate = mlx5_flow_isolate,
1134 : : .query = mlx5_flow_query,
1135 : : .dev_dump = mlx5_flow_dev_dump,
1136 : : .get_q_aged_flows = mlx5_flow_get_q_aged_flows,
1137 : : .get_aged_flows = mlx5_flow_get_aged_flows,
1138 : : .action_handle_create = mlx5_action_handle_create,
1139 : : .action_handle_destroy = mlx5_action_handle_destroy,
1140 : : .action_handle_update = mlx5_action_handle_update,
1141 : : .action_handle_query = mlx5_action_handle_query,
1142 : : .action_handle_query_update = mlx5_action_handle_query_update,
1143 : : .action_list_handle_create = mlx5_action_list_handle_create,
1144 : : .action_list_handle_destroy = mlx5_action_list_handle_destroy,
1145 : : .tunnel_decap_set = mlx5_flow_tunnel_decap_set,
1146 : : .tunnel_match = mlx5_flow_tunnel_match,
1147 : : .tunnel_action_decap_release = mlx5_flow_tunnel_action_release,
1148 : : .tunnel_item_release = mlx5_flow_tunnel_item_release,
1149 : : .get_restore_info = mlx5_flow_tunnel_get_restore_info,
1150 : : .flex_item_create = mlx5_flow_flex_item_create,
1151 : : .flex_item_release = mlx5_flow_flex_item_release,
1152 : : .info_get = mlx5_flow_info_get,
1153 : : .pick_transfer_proxy = mlx5_flow_pick_transfer_proxy,
1154 : : .configure = mlx5_flow_port_configure,
1155 : : .pattern_template_create = mlx5_flow_pattern_template_create,
1156 : : .pattern_template_destroy = mlx5_flow_pattern_template_destroy,
1157 : : .actions_template_create = mlx5_flow_actions_template_create,
1158 : : .actions_template_destroy = mlx5_flow_actions_template_destroy,
1159 : : .template_table_create = mlx5_flow_table_create,
1160 : : .template_table_destroy = mlx5_flow_table_destroy,
1161 : : .group_set_miss_actions = mlx5_flow_group_set_miss_actions,
1162 : : .action_list_handle_query_update =
1163 : : mlx5_flow_action_list_handle_query_update,
1164 : : .flow_calc_table_hash = mlx5_flow_calc_table_hash,
1165 : : .flow_calc_encap_hash = mlx5_flow_calc_encap_hash,
1166 : : .flow_template_table_resize = mlx5_template_table_resize,
1167 : : .flow_update_resized = mlx5_flow_async_update_resized,
1168 : : .flow_template_table_resize_complete = mlx5_table_resize_complete,
1169 : : };
1170 : :
1171 : : /* Tunnel information. */
1172 : : struct mlx5_flow_tunnel_info {
1173 : : uint64_t tunnel; /**< Tunnel bit (see MLX5_FLOW_*). */
1174 : : uint32_t ptype; /**< Tunnel Ptype (see RTE_PTYPE_*). */
1175 : : };
1176 : :
1177 : : static struct mlx5_flow_tunnel_info tunnels_info[] = {
1178 : : {
1179 : : .tunnel = MLX5_FLOW_LAYER_VXLAN,
1180 : : .ptype = RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_L4_UDP,
1181 : : },
1182 : : {
1183 : : .tunnel = MLX5_FLOW_LAYER_GENEVE,
1184 : : .ptype = RTE_PTYPE_TUNNEL_GENEVE | RTE_PTYPE_L4_UDP,
1185 : : },
1186 : : {
1187 : : .tunnel = MLX5_FLOW_LAYER_VXLAN_GPE,
1188 : : .ptype = RTE_PTYPE_TUNNEL_VXLAN_GPE | RTE_PTYPE_L4_UDP,
1189 : : },
1190 : : {
1191 : : .tunnel = MLX5_FLOW_LAYER_GRE,
1192 : : .ptype = RTE_PTYPE_TUNNEL_GRE,
1193 : : },
1194 : : {
1195 : : .tunnel = MLX5_FLOW_LAYER_MPLS | MLX5_FLOW_LAYER_OUTER_L4_UDP,
1196 : : .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_UDP | RTE_PTYPE_L4_UDP,
1197 : : },
1198 : : {
1199 : : .tunnel = MLX5_FLOW_LAYER_MPLS,
1200 : : .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE,
1201 : : },
1202 : : {
1203 : : .tunnel = MLX5_FLOW_LAYER_NVGRE,
1204 : : .ptype = RTE_PTYPE_TUNNEL_NVGRE,
1205 : : },
1206 : : {
1207 : : .tunnel = MLX5_FLOW_LAYER_IPIP,
1208 : : .ptype = RTE_PTYPE_TUNNEL_IP,
1209 : : },
1210 : : {
1211 : : .tunnel = MLX5_FLOW_LAYER_IPV6_ENCAP,
1212 : : .ptype = RTE_PTYPE_TUNNEL_IP,
1213 : : },
1214 : : {
1215 : : .tunnel = MLX5_FLOW_LAYER_GTP,
1216 : : .ptype = RTE_PTYPE_TUNNEL_GTPU,
1217 : : },
1218 : : };
1219 : :
1220 : :
1221 : :
1222 : : /**
1223 : : * Translate tag ID to register.
1224 : : *
1225 : : * @param[in] dev
1226 : : * Pointer to the Ethernet device structure.
1227 : : * @param[in] feature
1228 : : * The feature that request the register.
1229 : : * @param[in] id
1230 : : * The request register ID.
1231 : : * @param[out] error
1232 : : * Error description in case of any.
1233 : : *
1234 : : * @return
1235 : : * The request register on success, a negative errno
1236 : : * value otherwise and rte_errno is set.
1237 : : */
1238 : : int
1239 : 0 : mlx5_flow_get_reg_id(struct rte_eth_dev *dev,
1240 : : enum mlx5_feature_name feature,
1241 : : uint32_t id,
1242 : : struct rte_flow_error *error)
1243 : : {
1244 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1245 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
1246 : : struct mlx5_dev_registers *reg = &priv->sh->registers;
1247 : : enum modify_reg start_reg;
1248 : : bool skip_mtr_reg = false;
1249 : :
1250 [ # # # # : 0 : switch (feature) {
# # # # #
# # ]
1251 : : case MLX5_HAIRPIN_RX:
1252 : : return REG_B;
1253 : 0 : case MLX5_HAIRPIN_TX:
1254 : 0 : return REG_A;
1255 : 0 : case MLX5_METADATA_RX:
1256 [ # # ]: 0 : if (mlx5_vport_rx_metadata_passing_enabled(priv->sh)) {
1257 : : return REG_C_1;
1258 : : } else {
1259 [ # # # # : 0 : switch (config->dv_xmeta_en) {
# ]
1260 : : case MLX5_XMETA_MODE_LEGACY:
1261 : : return REG_B;
1262 : 0 : case MLX5_XMETA_MODE_META16:
1263 : 0 : return REG_C_0;
1264 : 0 : case MLX5_XMETA_MODE_META32:
1265 : 0 : return REG_C_1;
1266 : 0 : case MLX5_XMETA_MODE_META32_HWS:
1267 : 0 : return REG_C_1;
1268 : : }
1269 : : }
1270 : : break;
1271 : 0 : case MLX5_METADATA_TX:
1272 [ # # ]: 0 : if ((config->dv_flow_en == 2 &&
1273 [ # # ]: 0 : config->dv_xmeta_en == MLX5_XMETA_MODE_META32_HWS) ||
1274 : 0 : mlx5_vport_tx_metadata_passing_enabled(priv->sh)) {
1275 : 0 : return REG_C_1;
1276 : : } else {
1277 : : return REG_A;
1278 : : }
1279 : 0 : case MLX5_METADATA_FDB:
1280 [ # # ]: 0 : if (mlx5_esw_metadata_passing_enabled(priv->sh)) {
1281 : : return REG_C_1;
1282 : : } else {
1283 [ # # # # : 0 : switch (config->dv_xmeta_en) {
# ]
1284 : : case MLX5_XMETA_MODE_LEGACY:
1285 : : return REG_NON;
1286 : 0 : case MLX5_XMETA_MODE_META16:
1287 : 0 : return REG_C_0;
1288 : 0 : case MLX5_XMETA_MODE_META32:
1289 : 0 : return REG_C_1;
1290 : 0 : case MLX5_XMETA_MODE_META32_HWS:
1291 : 0 : return REG_C_1;
1292 : : }
1293 : : }
1294 : : break;
1295 : 0 : case MLX5_FLOW_MARK:
1296 [ # # # # ]: 0 : switch (config->dv_xmeta_en) {
1297 : : case MLX5_XMETA_MODE_LEGACY:
1298 : : case MLX5_XMETA_MODE_META32_HWS:
1299 : : return REG_NON;
1300 : 0 : case MLX5_XMETA_MODE_META16:
1301 : 0 : return REG_C_1;
1302 : 0 : case MLX5_XMETA_MODE_META32:
1303 : 0 : return REG_C_0;
1304 : : }
1305 : : break;
1306 : 0 : case MLX5_MTR_ID:
1307 : : /*
1308 : : * If meter color and meter id share one register, flow match
1309 : : * should use the meter color register for match.
1310 : : */
1311 [ # # ]: 0 : if (priv->mtr_reg_share)
1312 : 0 : return reg->aso_reg;
1313 : : else
1314 [ # # ]: 0 : return reg->aso_reg != REG_C_2 ? REG_C_2 :
1315 : : REG_C_3;
1316 : 0 : case MLX5_MTR_COLOR:
1317 : : case MLX5_ASO_FLOW_HIT:
1318 : : case MLX5_ASO_CONNTRACK:
1319 : : case MLX5_SAMPLE_ID:
1320 : : /* All features use the same REG_C. */
1321 : : MLX5_ASSERT(reg->aso_reg != REG_NON);
1322 : 0 : return reg->aso_reg;
1323 : 0 : case MLX5_COPY_MARK:
1324 : : /*
1325 : : * Metadata COPY_MARK register using is in meter suffix sub
1326 : : * flow while with meter. It's safe to share the same register.
1327 : : */
1328 [ # # ]: 0 : return reg->aso_reg != REG_C_2 ? REG_C_2 : REG_C_3;
1329 : 0 : case MLX5_APP_TAG:
1330 : : /*
1331 : : * If meter is enable, it will engage the register for color
1332 : : * match and flow match. If meter color match is not using the
1333 : : * REG_C_2, need to skip the REG_C_x be used by meter color
1334 : : * match.
1335 : : * If meter is disable, free to use all available registers.
1336 : : */
1337 [ # # ]: 0 : start_reg = reg->aso_reg != REG_C_2 ? REG_C_2 :
1338 [ # # ]: 0 : (priv->mtr_reg_share ? REG_C_3 : REG_C_4);
1339 [ # # # # ]: 0 : skip_mtr_reg = !!(priv->mtr_en && start_reg == REG_C_2);
1340 [ # # ]: 0 : if (id > (uint32_t)(REG_C_7 - start_reg))
1341 : 0 : return rte_flow_error_set(error, EINVAL,
1342 : : RTE_FLOW_ERROR_TYPE_ITEM,
1343 : : NULL, "invalid tag id");
1344 [ # # ]: 0 : if (priv->sh->flow_mreg_c[id + start_reg - REG_C_0] == REG_NON)
1345 : 0 : return rte_flow_error_set(error, ENOTSUP,
1346 : : RTE_FLOW_ERROR_TYPE_ITEM,
1347 : : NULL, "unsupported tag id");
1348 : : /*
1349 : : * This case means meter is using the REG_C_x great than 2.
1350 : : * Take care not to conflict with meter color REG_C_x.
1351 : : * If the available index REG_C_y >= REG_C_x, skip the
1352 : : * color register.
1353 : : */
1354 [ # # # # ]: 0 : if (skip_mtr_reg && priv->sh->flow_mreg_c
1355 : : [id + start_reg - REG_C_0] >= reg->aso_reg) {
1356 [ # # ]: 0 : if (id >= (uint32_t)(REG_C_7 - start_reg))
1357 : 0 : return rte_flow_error_set(error, EINVAL,
1358 : : RTE_FLOW_ERROR_TYPE_ITEM,
1359 : : NULL, "invalid tag id");
1360 : 0 : if (priv->sh->flow_mreg_c
1361 [ # # ]: 0 : [id + 1 + start_reg - REG_C_0] != REG_NON)
1362 : : return priv->sh->flow_mreg_c
1363 : 0 : [id + 1 + start_reg - REG_C_0];
1364 : 0 : return rte_flow_error_set(error, ENOTSUP,
1365 : : RTE_FLOW_ERROR_TYPE_ITEM,
1366 : : NULL, "unsupported tag id");
1367 : : }
1368 : 0 : return priv->sh->flow_mreg_c[id + start_reg - REG_C_0];
1369 : : }
1370 : : MLX5_ASSERT(false);
1371 : 0 : return rte_flow_error_set(error, EINVAL,
1372 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1373 : : NULL, "invalid feature name");
1374 : : }
1375 : :
1376 : : /**
1377 : : * Check extensive flow metadata register support.
1378 : : *
1379 : : * @param dev
1380 : : * Pointer to rte_eth_dev structure.
1381 : : *
1382 : : * @return
1383 : : * True if device supports extensive flow metadata register, otherwise false.
1384 : : */
1385 : : bool
1386 : 0 : mlx5_flow_ext_mreg_supported(struct rte_eth_dev *dev)
1387 : : {
1388 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1389 : :
1390 : : /*
1391 : : * Having available reg_c can be regarded inclusively as supporting
1392 : : * extensive flow metadata register, which could mean,
1393 : : * - metadata register copy action by modify header.
1394 : : * - 16 modify header actions is supported.
1395 : : * - reg_c's are preserved across different domain (FDB and NIC) on
1396 : : * packet loopback by flow lookup miss.
1397 : : */
1398 : 0 : return priv->sh->flow_mreg_c[2] != REG_NON;
1399 : : }
1400 : :
1401 : : /**
1402 : : * Get the lowest priority.
1403 : : *
1404 : : * @param[in] dev
1405 : : * Pointer to the Ethernet device structure.
1406 : : * @param[in] attributes
1407 : : * Pointer to device flow rule attributes.
1408 : : *
1409 : : * @return
1410 : : * The value of lowest priority of flow.
1411 : : */
1412 : : uint32_t
1413 : 0 : mlx5_get_lowest_priority(struct rte_eth_dev *dev,
1414 : : const struct rte_flow_attr *attr)
1415 : : {
1416 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1417 : :
1418 [ # # # # : 0 : if (!attr->group && !(attr->transfer && priv->fdb_def_rule))
# # ]
1419 : 0 : return priv->sh->flow_max_priority - 2;
1420 : : return MLX5_NON_ROOT_FLOW_MAX_PRIO - 1;
1421 : : }
1422 : :
1423 : : /**
1424 : : * Calculate matcher priority of the flow.
1425 : : *
1426 : : * @param[in] dev
1427 : : * Pointer to the Ethernet device structure.
1428 : : * @param[in] attr
1429 : : * Pointer to device flow rule attributes.
1430 : : * @param[in] subpriority
1431 : : * The priority based on the items.
1432 : : * @param[in] external
1433 : : * Flow is user flow.
1434 : : * @return
1435 : : * The matcher priority of the flow.
1436 : : */
1437 : : uint16_t
1438 : 0 : mlx5_get_matcher_priority(struct rte_eth_dev *dev,
1439 : : const struct rte_flow_attr *attr,
1440 : : uint32_t subpriority, bool external)
1441 : : {
1442 : 0 : uint16_t priority = (uint16_t)attr->priority;
1443 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1444 : :
1445 : : /* NIC root rules */
1446 [ # # # # ]: 0 : if (!attr->group && !attr->transfer) {
1447 [ # # ]: 0 : if (attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)
1448 : 0 : priority = priv->sh->flow_max_priority - 1;
1449 : 0 : return mlx5_os_flow_adjust_priority(dev, priority, subpriority);
1450 : : /* FDB root rules */
1451 [ # # # # : 0 : } else if (attr->transfer && (!external || !priv->fdb_def_rule) &&
# # # # ]
1452 [ # # ]: 0 : attr->group == 0 &&
1453 : : attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR) {
1454 : 0 : return (priv->sh->flow_max_priority - 1) * 3;
1455 : : }
1456 [ # # ]: 0 : if (attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)
1457 : : priority = MLX5_NON_ROOT_FLOW_MAX_PRIO;
1458 : 0 : return priority * 3 + subpriority;
1459 : : }
1460 : :
1461 : : /**
1462 : : * Verify the @p item specifications (spec, last, mask) are compatible with the
1463 : : * NIC capabilities.
1464 : : *
1465 : : * @param[in] item
1466 : : * Item specification.
1467 : : * @param[in] mask
1468 : : * @p item->mask or flow default bit-masks.
1469 : : * @param[in] nic_mask
1470 : : * Bit-masks covering supported fields by the NIC to compare with user mask.
1471 : : * @param[in] size
1472 : : * Bit-masks size in bytes.
1473 : : * @param[in] range_accepted
1474 : : * True if range of values is accepted for specific fields, false otherwise.
1475 : : * @param[out] error
1476 : : * Pointer to error structure.
1477 : : *
1478 : : * @return
1479 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1480 : : */
1481 : : int
1482 : 0 : mlx5_flow_item_acceptable(const struct rte_eth_dev *dev,
1483 : : const struct rte_flow_item *item,
1484 : : const uint8_t *mask,
1485 : : const uint8_t *nic_mask,
1486 : : unsigned int size,
1487 : : bool range_accepted,
1488 : : struct rte_flow_error *error)
1489 : : {
1490 : : unsigned int i;
1491 : :
1492 : : MLX5_ASSERT(nic_mask);
1493 [ # # ]: 0 : for (i = 0; i < size; ++i)
1494 [ # # ]: 0 : if ((nic_mask[i] | mask[i]) != nic_mask[i])
1495 : 0 : return rte_flow_error_set(error, ENOTSUP,
1496 : : RTE_FLOW_ERROR_TYPE_ITEM,
1497 : : item,
1498 : : "mask enables non supported"
1499 : : " bits");
1500 [ # # ]: 0 : if (mlx5_hws_active(dev))
1501 : : return 0;
1502 [ # # # # : 0 : if (!item->spec && (item->mask || item->last))
# # ]
1503 : 0 : return rte_flow_error_set(error, EINVAL,
1504 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
1505 : : "mask/last without a spec is not"
1506 : : " supported");
1507 [ # # # # : 0 : if (item->spec && item->last && !range_accepted) {
# # ]
1508 : 0 : uint8_t *spec = alloca(size);
1509 : 0 : uint8_t *last = alloca(size);
1510 : : unsigned int i;
1511 : : int ret;
1512 : :
1513 [ # # ]: 0 : for (i = 0; i < size; ++i) {
1514 : 0 : spec[i] = ((const uint8_t *)item->spec)[i] & mask[i];
1515 : 0 : last[i] = ((const uint8_t *)item->last)[i] & mask[i];
1516 : : }
1517 : 0 : ret = memcmp(spec, last, size);
1518 [ # # ]: 0 : if (ret != 0)
1519 : 0 : return rte_flow_error_set(error, EINVAL,
1520 : : RTE_FLOW_ERROR_TYPE_ITEM,
1521 : : item,
1522 : : "range is not valid");
1523 : : }
1524 : : return 0;
1525 : : }
1526 : :
1527 : : /**
1528 : : * Adjust the hash fields according to the @p flow information.
1529 : : *
1530 : : * @param[in] dev_flow.
1531 : : * Pointer to the mlx5_flow.
1532 : : * @param[in] tunnel
1533 : : * 1 when the hash field is for a tunnel item.
1534 : : * @param[in] layer_types
1535 : : * RTE_ETH_RSS_* types.
1536 : : * @param[in] hash_fields
1537 : : * Item hash fields.
1538 : : *
1539 : : * @return
1540 : : * The hash fields that should be used.
1541 : : */
1542 : : uint64_t
1543 : 0 : mlx5_flow_hashfields_adjust(struct mlx5_flow_rss_desc *rss_desc,
1544 : : int tunnel __rte_unused, uint64_t layer_types,
1545 : : uint64_t hash_fields)
1546 : : {
1547 : : #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1548 : 0 : int rss_request_inner = rss_desc->level >= 2;
1549 : :
1550 : : /* Check RSS hash level for tunnel. */
1551 [ # # ]: 0 : if (tunnel && rss_request_inner)
1552 : 0 : hash_fields |= IBV_RX_HASH_INNER;
1553 [ # # ]: 0 : else if (tunnel || rss_request_inner)
1554 : : return 0;
1555 : : #endif
1556 : : /* Check if requested layer matches RSS hash fields. */
1557 [ # # ]: 0 : if (!(rss_desc->types & layer_types))
1558 : 0 : return 0;
1559 : : return hash_fields;
1560 : : }
1561 : :
1562 : : /**
1563 : : * Lookup and set the ptype in the data Rx part. A single Ptype can be used,
1564 : : * if several tunnel rules are used on this queue, the tunnel ptype will be
1565 : : * cleared.
1566 : : *
1567 : : * @param rxq_ctrl
1568 : : * Rx queue to update.
1569 : : */
1570 : : static void
1571 : : flow_rxq_tunnel_ptype_update(struct mlx5_rxq_ctrl *rxq_ctrl)
1572 : : {
1573 : : unsigned int i;
1574 : : uint32_t tunnel_ptype = 0;
1575 : :
1576 : : /* Look up for the ptype to use. */
1577 [ # # # # ]: 0 : for (i = 0; i != MLX5_FLOW_TUNNEL; ++i) {
1578 [ # # # # ]: 0 : if (!rxq_ctrl->flow_tunnels_n[i])
1579 : 0 : continue;
1580 [ # # # # ]: 0 : if (!tunnel_ptype) {
1581 : 0 : tunnel_ptype = tunnels_info[i].ptype;
1582 : : } else {
1583 : : tunnel_ptype = 0;
1584 : : break;
1585 : : }
1586 : : }
1587 : 0 : rxq_ctrl->rxq.tunnel = tunnel_ptype;
1588 : 0 : }
1589 : :
1590 : : /**
1591 : : * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) according to the device
1592 : : * flow.
1593 : : *
1594 : : * @param[in] dev
1595 : : * Pointer to the Ethernet device structure.
1596 : : * @param[in] dev_handle
1597 : : * Pointer to device flow handle structure.
1598 : : */
1599 : : void
1600 : 0 : mlx5_flow_drv_rxq_flags_set(struct rte_eth_dev *dev,
1601 : : struct mlx5_flow_handle *dev_handle)
1602 : : {
1603 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1604 : 0 : const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1605 : : struct mlx5_ind_table_obj *ind_tbl = NULL;
1606 : : unsigned int i;
1607 : :
1608 [ # # ]: 0 : if (dev_handle->fate_action == MLX5_FLOW_FATE_QUEUE) {
1609 : : struct mlx5_hrxq *hrxq;
1610 : :
1611 : 0 : hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1612 : : dev_handle->rix_hrxq);
1613 [ # # ]: 0 : if (hrxq)
1614 : 0 : ind_tbl = hrxq->ind_table;
1615 [ # # ]: 0 : } else if (dev_handle->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
1616 : : struct mlx5_shared_action_rss *shared_rss;
1617 : :
1618 : 0 : shared_rss = mlx5_ipool_get
1619 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
1620 : : dev_handle->rix_srss);
1621 [ # # ]: 0 : if (shared_rss)
1622 : 0 : ind_tbl = shared_rss->ind_tbl;
1623 : : }
1624 [ # # ]: 0 : if (!ind_tbl)
1625 : 0 : return;
1626 [ # # ]: 0 : for (i = 0; i != ind_tbl->queues_n; ++i) {
1627 [ # # ]: 0 : int idx = ind_tbl->queues[i];
1628 : : struct mlx5_rxq_ctrl *rxq_ctrl;
1629 : :
1630 [ # # ]: 0 : if (mlx5_is_external_rxq(dev, idx))
1631 : 0 : continue;
1632 : 0 : rxq_ctrl = mlx5_rxq_ctrl_get(dev, idx);
1633 : : MLX5_ASSERT(rxq_ctrl != NULL);
1634 [ # # ]: 0 : if (rxq_ctrl == NULL)
1635 : 0 : continue;
1636 : : /*
1637 : : * To support metadata register copy on Tx loopback,
1638 : : * this must be always enabled (metadata may arive
1639 : : * from other port - not from local flows only.
1640 : : */
1641 [ # # ]: 0 : if (tunnel) {
1642 : : unsigned int j;
1643 : :
1644 : : /* Increase the counter matching the flow. */
1645 [ # # ]: 0 : for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1646 : 0 : if ((tunnels_info[j].tunnel &
1647 [ # # ]: 0 : dev_handle->layers) ==
1648 : : tunnels_info[j].tunnel) {
1649 : 0 : rxq_ctrl->flow_tunnels_n[j]++;
1650 : 0 : break;
1651 : : }
1652 : : }
1653 : : flow_rxq_tunnel_ptype_update(rxq_ctrl);
1654 : : }
1655 : : }
1656 : : }
1657 : :
1658 : : void
1659 : 0 : mlx5_flow_rxq_mark_flag_set(struct rte_eth_dev *dev)
1660 : : {
1661 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1662 : : struct mlx5_rxq_ctrl *rxq_ctrl;
1663 : : uint16_t port_id;
1664 : :
1665 [ # # ]: 0 : if (priv->sh->shared_mark_enabled)
1666 : : return;
1667 [ # # ]: 0 : if (priv->master || priv->representor) {
1668 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port_id, dev->device) {
1669 : 0 : struct mlx5_priv *opriv =
1670 : 0 : rte_eth_devices[port_id].data->dev_private;
1671 : :
1672 [ # # ]: 0 : if (!opriv ||
1673 [ # # ]: 0 : opriv->sh != priv->sh ||
1674 [ # # # # ]: 0 : opriv->domain_id != priv->domain_id ||
1675 : : opriv->mark_enabled)
1676 : 0 : continue;
1677 [ # # ]: 0 : LIST_FOREACH(rxq_ctrl, &opriv->rxqsctrl, next) {
1678 : 0 : rxq_ctrl->rxq.mark = 1;
1679 : : }
1680 [ # # ]: 0 : LIST_FOREACH(rxq_ctrl, &opriv->sh->shared_rxqs, next) {
1681 : 0 : rxq_ctrl->rxq.mark = 1;
1682 : : }
1683 : 0 : opriv->mark_enabled = 1;
1684 : : }
1685 : : } else {
1686 [ # # ]: 0 : LIST_FOREACH(rxq_ctrl, &priv->rxqsctrl, next) {
1687 : 0 : rxq_ctrl->rxq.mark = 1;
1688 : : }
1689 [ # # ]: 0 : LIST_FOREACH(rxq_ctrl, &priv->sh->shared_rxqs, next) {
1690 : 0 : rxq_ctrl->rxq.mark = 1;
1691 : : }
1692 : 0 : priv->mark_enabled = 1;
1693 : : }
1694 : 0 : priv->sh->shared_mark_enabled = 1;
1695 : : }
1696 : :
1697 : : /**
1698 : : * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) for a flow
1699 : : *
1700 : : * @param[in] dev
1701 : : * Pointer to the Ethernet device structure.
1702 : : * @param[in] flow
1703 : : * Pointer to flow structure.
1704 : : */
1705 : : static void
1706 : 0 : flow_rxq_flags_set(struct rte_eth_dev *dev, struct rte_flow *flow)
1707 : : {
1708 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1709 : : uint32_t handle_idx;
1710 : : struct mlx5_flow_handle *dev_handle;
1711 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
1712 : :
1713 : : MLX5_ASSERT(wks);
1714 [ # # ]: 0 : if (wks->mark)
1715 : 0 : mlx5_flow_rxq_mark_flag_set(dev);
1716 [ # # # # : 0 : SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
# # ]
1717 : : handle_idx, dev_handle, next)
1718 : 0 : mlx5_flow_drv_rxq_flags_set(dev, dev_handle);
1719 : 0 : }
1720 : :
1721 : : /**
1722 : : * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1723 : : * device flow if no other flow uses it with the same kind of request.
1724 : : *
1725 : : * @param dev
1726 : : * Pointer to Ethernet device.
1727 : : * @param[in] dev_handle
1728 : : * Pointer to the device flow handle structure.
1729 : : */
1730 : : static void
1731 : 0 : flow_drv_rxq_flags_trim(struct rte_eth_dev *dev,
1732 : : struct mlx5_flow_handle *dev_handle)
1733 : : {
1734 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1735 : 0 : const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1736 : : struct mlx5_ind_table_obj *ind_tbl = NULL;
1737 : : unsigned int i;
1738 : :
1739 [ # # ]: 0 : if (dev_handle->fate_action == MLX5_FLOW_FATE_QUEUE) {
1740 : : struct mlx5_hrxq *hrxq;
1741 : :
1742 : 0 : hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1743 : : dev_handle->rix_hrxq);
1744 [ # # ]: 0 : if (hrxq)
1745 : 0 : ind_tbl = hrxq->ind_table;
1746 [ # # ]: 0 : } else if (dev_handle->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
1747 : : struct mlx5_shared_action_rss *shared_rss;
1748 : :
1749 : 0 : shared_rss = mlx5_ipool_get
1750 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
1751 : : dev_handle->rix_srss);
1752 [ # # ]: 0 : if (shared_rss)
1753 : 0 : ind_tbl = shared_rss->ind_tbl;
1754 : : }
1755 [ # # ]: 0 : if (!ind_tbl)
1756 : 0 : return;
1757 : : MLX5_ASSERT(dev->data->dev_started);
1758 [ # # ]: 0 : for (i = 0; i != ind_tbl->queues_n; ++i) {
1759 [ # # ]: 0 : int idx = ind_tbl->queues[i];
1760 : : struct mlx5_rxq_ctrl *rxq_ctrl;
1761 : :
1762 [ # # ]: 0 : if (mlx5_is_external_rxq(dev, idx))
1763 : 0 : continue;
1764 : 0 : rxq_ctrl = mlx5_rxq_ctrl_get(dev, idx);
1765 : : MLX5_ASSERT(rxq_ctrl != NULL);
1766 [ # # ]: 0 : if (rxq_ctrl == NULL)
1767 : 0 : continue;
1768 [ # # ]: 0 : if (tunnel) {
1769 : : unsigned int j;
1770 : :
1771 : : /* Decrease the counter matching the flow. */
1772 [ # # ]: 0 : for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1773 : 0 : if ((tunnels_info[j].tunnel &
1774 [ # # ]: 0 : dev_handle->layers) ==
1775 : : tunnels_info[j].tunnel) {
1776 : 0 : rxq_ctrl->flow_tunnels_n[j]--;
1777 : 0 : break;
1778 : : }
1779 : : }
1780 : : flow_rxq_tunnel_ptype_update(rxq_ctrl);
1781 : : }
1782 : : }
1783 : : }
1784 : :
1785 : : /**
1786 : : * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1787 : : * @p flow if no other flow uses it with the same kind of request.
1788 : : *
1789 : : * @param dev
1790 : : * Pointer to Ethernet device.
1791 : : * @param[in] flow
1792 : : * Pointer to the flow.
1793 : : */
1794 : : static void
1795 : 0 : flow_rxq_flags_trim(struct rte_eth_dev *dev, struct rte_flow *flow)
1796 : : {
1797 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1798 : : uint32_t handle_idx;
1799 : : struct mlx5_flow_handle *dev_handle;
1800 : :
1801 [ # # # # : 0 : SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
# # ]
1802 : : handle_idx, dev_handle, next)
1803 : 0 : flow_drv_rxq_flags_trim(dev, dev_handle);
1804 : 0 : }
1805 : :
1806 : : /**
1807 : : * Clear the Mark/Flag and Tunnel ptype information in all Rx queues.
1808 : : *
1809 : : * @param dev
1810 : : * Pointer to Ethernet device.
1811 : : */
1812 : : void
1813 : 0 : mlx5_flow_rxq_flags_clear(struct rte_eth_dev *dev)
1814 : : {
1815 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1816 : : unsigned int i;
1817 : :
1818 [ # # ]: 0 : for (i = 0; i != priv->rxqs_n; ++i) {
1819 : 0 : struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, i);
1820 : : unsigned int j;
1821 : :
1822 [ # # # # ]: 0 : if (rxq == NULL || rxq->ctrl == NULL)
1823 : 0 : continue;
1824 : 0 : rxq->ctrl->rxq.mark = 0;
1825 [ # # ]: 0 : for (j = 0; j != MLX5_FLOW_TUNNEL; ++j)
1826 : 0 : rxq->ctrl->flow_tunnels_n[j] = 0;
1827 : 0 : rxq->ctrl->rxq.tunnel = 0;
1828 : : }
1829 : 0 : priv->mark_enabled = 0;
1830 : 0 : priv->sh->shared_mark_enabled = 0;
1831 : 0 : }
1832 : :
1833 : : static uint64_t mlx5_restore_info_dynflag;
1834 : :
1835 : : int
1836 : 0 : mlx5_flow_rx_metadata_negotiate(struct rte_eth_dev *dev, uint64_t *features)
1837 : : {
1838 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
1839 : : uint64_t supported = 0;
1840 : :
1841 [ # # ]: 0 : if (!is_tunnel_offload_active(dev)) {
1842 : : supported |= RTE_ETH_RX_METADATA_USER_FLAG;
1843 : : supported |= RTE_ETH_RX_METADATA_USER_MARK;
1844 [ # # ]: 0 : if ((*features & RTE_ETH_RX_METADATA_TUNNEL_ID) != 0) {
1845 : 0 : DRV_LOG(DEBUG,
1846 : : "tunnel offload was not activated, consider setting dv_xmeta_en=%d",
1847 : : MLX5_XMETA_MODE_MISS_INFO);
1848 : : }
1849 : : } else {
1850 : : supported |= RTE_ETH_RX_METADATA_TUNNEL_ID;
1851 [ # # ]: 0 : if ((*features & RTE_ETH_RX_METADATA_TUNNEL_ID) != 0 &&
1852 [ # # ]: 0 : mlx5_restore_info_dynflag == 0)
1853 : 0 : mlx5_restore_info_dynflag = rte_flow_restore_info_dynflag();
1854 : : }
1855 : :
1856 [ # # ]: 0 : if (((*features & supported) & RTE_ETH_RX_METADATA_TUNNEL_ID) != 0)
1857 : 0 : priv->tunnel_enabled = 1;
1858 : : else
1859 : 0 : priv->tunnel_enabled = 0;
1860 : :
1861 : 0 : *features &= supported;
1862 : 0 : return 0;
1863 : : }
1864 : :
1865 : : /**
1866 : : * Set the Rx queue dynamic metadata (mask and offset) for a flow
1867 : : *
1868 : : * @param[in] dev
1869 : : * Pointer to the Ethernet device structure.
1870 : : */
1871 : : void
1872 : 0 : mlx5_flow_rxq_dynf_set(struct rte_eth_dev *dev)
1873 : : {
1874 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1875 : : uint64_t mark_flag = RTE_MBUF_F_RX_FDIR_ID;
1876 : : unsigned int i;
1877 : :
1878 [ # # ]: 0 : if (priv->tunnel_enabled)
1879 : 0 : mark_flag |= mlx5_restore_info_dynflag;
1880 : :
1881 [ # # ]: 0 : for (i = 0; i != priv->rxqs_n; ++i) {
1882 : 0 : struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, i);
1883 : : struct mlx5_rxq_data *data;
1884 : :
1885 [ # # # # ]: 0 : if (rxq == NULL || rxq->ctrl == NULL)
1886 : 0 : continue;
1887 : : data = &rxq->ctrl->rxq;
1888 [ # # # # ]: 0 : if (!data->shared || !rxq->ctrl->started) {
1889 [ # # ]: 0 : if (!rte_flow_dynf_metadata_avail()) {
1890 : 0 : data->dynf_meta = 0;
1891 : 0 : data->flow_meta_mask = 0;
1892 : 0 : data->flow_meta_offset = -1;
1893 : 0 : data->flow_meta_port_mask = 0;
1894 : : } else {
1895 : 0 : data->dynf_meta = 1;
1896 : 0 : data->flow_meta_mask = rte_flow_dynf_metadata_mask;
1897 : 0 : data->flow_meta_offset = rte_flow_dynf_metadata_offs;
1898 : 0 : data->flow_meta_port_mask = priv->sh->dv_meta_mask;
1899 : : }
1900 : : }
1901 : 0 : data->mark = !!priv->mark_enabled;
1902 : 0 : data->mark_flag = mark_flag;
1903 : : }
1904 : 0 : }
1905 : :
1906 : : /*
1907 : : * return a pointer to the desired action in the list of actions.
1908 : : *
1909 : : * @param[in] actions
1910 : : * The list of actions to search the action in.
1911 : : * @param[in] action
1912 : : * The action to find.
1913 : : *
1914 : : * @return
1915 : : * Pointer to the action in the list, if found. NULL otherwise.
1916 : : */
1917 : : const struct rte_flow_action *
1918 : 0 : mlx5_flow_find_action(const struct rte_flow_action *actions,
1919 : : enum rte_flow_action_type action)
1920 : : {
1921 [ # # ]: 0 : if (actions == NULL)
1922 : : return NULL;
1923 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++)
1924 [ # # ]: 0 : if (actions->type == action)
1925 : 0 : return actions;
1926 : : return NULL;
1927 : : }
1928 : :
1929 : : /*
1930 : : * Validate the flag action.
1931 : : *
1932 : : * @param[in] action_flags
1933 : : * Bit-fields that holds the actions detected until now.
1934 : : * @param[in] attr
1935 : : * Attributes of flow that includes this action.
1936 : : * @param[out] error
1937 : : * Pointer to error structure.
1938 : : *
1939 : : * @return
1940 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1941 : : */
1942 : : int
1943 : 0 : mlx5_flow_validate_action_flag(uint64_t action_flags,
1944 : : const struct rte_flow_attr *attr,
1945 : : struct rte_flow_error *error)
1946 : : {
1947 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
1948 : 0 : return rte_flow_error_set(error, EINVAL,
1949 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1950 : : "can't mark and flag in same flow");
1951 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_FLAG)
1952 : 0 : return rte_flow_error_set(error, EINVAL,
1953 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1954 : : "can't have 2 flag"
1955 : : " actions in same flow");
1956 [ # # ]: 0 : if (attr->egress)
1957 : 0 : return rte_flow_error_set(error, ENOTSUP,
1958 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1959 : : "flag action not supported for "
1960 : : "egress");
1961 : : return 0;
1962 : : }
1963 : :
1964 : : /*
1965 : : * Validate the mark action.
1966 : : *
1967 : : * @param[in] action
1968 : : * Pointer to the queue action.
1969 : : * @param[in] action_flags
1970 : : * Bit-fields that holds the actions detected until now.
1971 : : * @param[in] attr
1972 : : * Attributes of flow that includes this action.
1973 : : * @param[out] error
1974 : : * Pointer to error structure.
1975 : : *
1976 : : * @return
1977 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1978 : : */
1979 : : int
1980 : 0 : mlx5_flow_validate_action_mark(__rte_unused struct rte_eth_dev *dev,
1981 : : const struct rte_flow_action *action,
1982 : : uint64_t action_flags,
1983 : : const struct rte_flow_attr *attr,
1984 : : struct rte_flow_error *error)
1985 : : {
1986 : 0 : const struct rte_flow_action_mark *mark = action->conf;
1987 : :
1988 [ # # ]: 0 : if (!mark)
1989 : 0 : return rte_flow_error_set(error, EINVAL,
1990 : : RTE_FLOW_ERROR_TYPE_ACTION,
1991 : : action,
1992 : : "configuration cannot be null");
1993 [ # # ]: 0 : if (mark->id >= MLX5_FLOW_MARK_MAX)
1994 : 0 : return rte_flow_error_set(error, EINVAL,
1995 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1996 : 0 : &mark->id,
1997 : : "mark id must in 0 <= id < "
1998 : : RTE_STR(MLX5_FLOW_MARK_MAX));
1999 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_FLAG)
2000 : 0 : return rte_flow_error_set(error, EINVAL,
2001 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2002 : : "can't flag and mark in same flow");
2003 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
2004 : 0 : return rte_flow_error_set(error, EINVAL,
2005 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2006 : : "can't have 2 mark actions in same"
2007 : : " flow");
2008 [ # # ]: 0 : if (attr->egress)
2009 : 0 : return rte_flow_error_set(error, ENOTSUP,
2010 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
2011 : : "mark action not supported for "
2012 : : "egress");
2013 : : return 0;
2014 : : }
2015 : :
2016 : : /*
2017 : : * Validate the drop action.
2018 : : *
2019 : : * @param[in] dev
2020 : : * Pointer to the Ethernet device structure.
2021 : : * @param[in] is_root
2022 : : * True if flow is validated for root table. False otherwise.
2023 : : * @param[in] attr
2024 : : * Attributes of flow that includes this action.
2025 : : * @param[out] error
2026 : : * Pointer to error structure.
2027 : : *
2028 : : * @return
2029 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2030 : : */
2031 : : int
2032 : 0 : mlx5_flow_validate_action_drop(struct rte_eth_dev *dev,
2033 : : bool is_root,
2034 : : const struct rte_flow_attr *attr,
2035 : : struct rte_flow_error *error)
2036 : : {
2037 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2038 : :
2039 [ # # # # ]: 0 : if (priv->sh->config.dv_flow_en == 0 && attr->egress)
2040 : 0 : return rte_flow_error_set(error, ENOTSUP,
2041 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
2042 : : "drop action not supported for "
2043 : : "egress");
2044 [ # # # # : 0 : if (priv->sh->config.dv_flow_en == 1 && is_root && (attr->egress || attr->transfer) &&
# # ]
2045 [ # # ]: 0 : !priv->sh->dr_root_drop_action_en) {
2046 : 0 : return rte_flow_error_set(error, ENOTSUP,
2047 : : RTE_FLOW_ERROR_TYPE_ATTR, NULL,
2048 : : "drop action not supported for "
2049 : : "egress and transfer on group 0");
2050 : : }
2051 : : return 0;
2052 : : }
2053 : :
2054 : : /*
2055 : : * Check if a queue specified in the queue action is valid.
2056 : : *
2057 : : * @param[in] dev
2058 : : * Pointer to the Ethernet device structure.
2059 : : * @param[in] action
2060 : : * Pointer to the queue action.
2061 : : * @param[out] error
2062 : : * Pointer to error structure.
2063 : : *
2064 : : * @return
2065 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2066 : : */
2067 : : int
2068 : 0 : mlx5_flow_validate_target_queue(struct rte_eth_dev *dev,
2069 : : const struct rte_flow_action *action,
2070 : : struct rte_flow_error *error)
2071 : : {
2072 : 0 : const struct rte_flow_action_queue *queue = action->conf;
2073 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2074 : :
2075 [ # # # # ]: 0 : if (mlx5_is_external_rxq(dev, queue->index))
2076 : : return 0;
2077 [ # # ]: 0 : if (!priv->rxqs_n)
2078 : 0 : return rte_flow_error_set(error, EINVAL,
2079 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2080 : : NULL, "No Rx queues configured");
2081 [ # # ]: 0 : if (queue->index >= priv->rxqs_n)
2082 : 0 : return rte_flow_error_set(error, EINVAL,
2083 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2084 : 0 : &queue->index,
2085 : : "queue index out of range");
2086 [ # # ]: 0 : if (mlx5_rxq_get(dev, queue->index) == NULL)
2087 : 0 : return rte_flow_error_set(error, EINVAL,
2088 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2089 : 0 : &queue->index,
2090 : : "queue is not configured");
2091 : : return 0;
2092 : : }
2093 : :
2094 : : /*
2095 : : * Validate the queue action.
2096 : : *
2097 : : * @param[in] action
2098 : : * Pointer to the queue action.
2099 : : * @param[in] action_flags
2100 : : * Bit-fields that holds the actions detected until now.
2101 : : * @param[in] dev
2102 : : * Pointer to the Ethernet device structure.
2103 : : * @param[in] attr
2104 : : * Attributes of flow that includes this action.
2105 : : * @param[out] error
2106 : : * Pointer to error structure.
2107 : : *
2108 : : * @return
2109 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2110 : : */
2111 : : int
2112 : 0 : mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
2113 : : uint64_t action_flags,
2114 : : struct rte_eth_dev *dev,
2115 : : const struct rte_flow_attr *attr,
2116 : : struct rte_flow_error *error)
2117 : : {
2118 : 0 : const struct rte_flow_action_queue *queue = action->conf;
2119 : :
2120 [ # # ]: 0 : if (!queue)
2121 : 0 : return rte_flow_error_set(error, EINVAL,
2122 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
2123 : : "no QUEUE action configuration");
2124 [ # # ]: 0 : if (action_flags & MLX5_FLOW_FATE_ACTIONS)
2125 : 0 : return rte_flow_error_set(error, EINVAL,
2126 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2127 : : "can't have 2 fate actions in"
2128 : : " same flow");
2129 [ # # ]: 0 : if (attr->egress)
2130 : 0 : return rte_flow_error_set(error, ENOTSUP,
2131 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
2132 : : "queue action not supported for egress.");
2133 : 0 : return mlx5_flow_validate_target_queue(dev, action, error);
2134 : : }
2135 : :
2136 : : /**
2137 : : * Validate queue numbers for device RSS.
2138 : : *
2139 : : * @param[in] dev
2140 : : * Configured device.
2141 : : * @param[in] queues
2142 : : * Array of queue numbers.
2143 : : * @param[in] queues_n
2144 : : * Size of the @p queues array.
2145 : : * @param[out] error
2146 : : * On error, filled with a textual error description.
2147 : : * @param[out] queue_idx
2148 : : * On error, filled with an offending queue index in @p queues array.
2149 : : *
2150 : : * @return
2151 : : * 0 on success, a negative errno code on error.
2152 : : */
2153 : : static int
2154 : 0 : mlx5_validate_rss_queues(struct rte_eth_dev *dev,
2155 : : const uint16_t *queues, uint32_t queues_n,
2156 : : const char **error, uint32_t *queue_idx)
2157 : : {
2158 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
2159 : : bool is_hairpin = false;
2160 : : bool is_ext_rss = false;
2161 : : uint32_t i;
2162 : :
2163 [ # # ]: 0 : for (i = 0; i != queues_n; ++i) {
2164 : : struct mlx5_rxq_ctrl *rxq_ctrl;
2165 : :
2166 [ # # # # ]: 0 : if (mlx5_is_external_rxq(dev, queues[0])) {
2167 : : is_ext_rss = true;
2168 : 0 : continue;
2169 : : }
2170 [ # # ]: 0 : if (is_ext_rss) {
2171 : 0 : *error = "Combining external and regular RSS queues is not supported";
2172 : 0 : *queue_idx = i;
2173 : 0 : return -ENOTSUP;
2174 : : }
2175 [ # # ]: 0 : if (queues[i] >= priv->rxqs_n) {
2176 : 0 : *error = "queue index out of range";
2177 : 0 : *queue_idx = i;
2178 : 0 : return -EINVAL;
2179 : : }
2180 : 0 : rxq_ctrl = mlx5_rxq_ctrl_get(dev, queues[i]);
2181 [ # # ]: 0 : if (rxq_ctrl == NULL) {
2182 : 0 : *error = "queue is not configured";
2183 : 0 : *queue_idx = i;
2184 : 0 : return -EINVAL;
2185 : : }
2186 [ # # # # ]: 0 : if (i == 0 && rxq_ctrl->is_hairpin)
2187 : : is_hairpin = true;
2188 [ # # ]: 0 : if (is_hairpin != rxq_ctrl->is_hairpin) {
2189 : 0 : *error = "combining hairpin and regular RSS queues is not supported";
2190 : 0 : *queue_idx = i;
2191 : 0 : return -ENOTSUP;
2192 : : }
2193 : : }
2194 : : return 0;
2195 : : }
2196 : :
2197 : : /*
2198 : : * Validate the rss action.
2199 : : *
2200 : : * @param[in] dev
2201 : : * Pointer to the Ethernet device structure.
2202 : : * @param[in] action
2203 : : * Pointer to the queue action.
2204 : : * @param[out] error
2205 : : * Pointer to error structure.
2206 : : *
2207 : : * @return
2208 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2209 : : */
2210 : : int
2211 : 0 : mlx5_validate_action_rss(struct rte_eth_dev *dev,
2212 : : const struct rte_flow_action *action,
2213 : : struct rte_flow_error *error)
2214 : : {
2215 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2216 : 0 : const struct rte_flow_action_rss *rss = action->conf;
2217 : : int ret;
2218 : : const char *message;
2219 : : uint32_t queue_idx;
2220 : :
2221 [ # # ]: 0 : if (!rss)
2222 : 0 : return rte_flow_error_set
2223 : : (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
2224 : : action, "no RSS action configuration");
2225 [ # # ]: 0 : if (rss->func == RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ) {
2226 : 0 : DRV_LOG(WARNING, "port %u symmetric RSS supported with SORT",
2227 : : dev->data->port_id);
2228 [ # # ]: 0 : } else if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
2229 : : rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
2230 : 0 : return rte_flow_error_set(error, ENOTSUP,
2231 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2232 : 0 : &rss->func,
2233 : : "RSS hash function not supported");
2234 : : #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
2235 [ # # ]: 0 : if (rss->level > 2)
2236 : : #else
2237 : : if (rss->level > 1)
2238 : : #endif
2239 : 0 : return rte_flow_error_set(error, ENOTSUP,
2240 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2241 : 0 : &rss->level,
2242 : : "tunnel RSS is not supported");
2243 : : /* allow RSS key_len 0 in case of NULL (default) RSS key. */
2244 [ # # # # ]: 0 : if (rss->key_len == 0 && rss->key != NULL)
2245 : 0 : return rte_flow_error_set(error, ENOTSUP,
2246 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2247 : 0 : &rss->key_len,
2248 : : "RSS hash key length 0");
2249 [ # # ]: 0 : if (rss->key_len > 0 && rss->key_len < MLX5_RSS_HASH_KEY_LEN)
2250 : 0 : return rte_flow_error_set(error, ENOTSUP,
2251 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2252 : 0 : &rss->key_len,
2253 : : "RSS hash key too small");
2254 [ # # ]: 0 : if (rss->key_len > MLX5_RSS_HASH_KEY_LEN)
2255 : 0 : return rte_flow_error_set(error, ENOTSUP,
2256 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2257 : 0 : &rss->key_len,
2258 : : "RSS hash key too large");
2259 [ # # ]: 0 : if (rss->queue_num > priv->sh->dev_cap.ind_table_max_size)
2260 : 0 : return rte_flow_error_set(error, ENOTSUP,
2261 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2262 : 0 : &rss->queue_num,
2263 : : "number of queues too large");
2264 [ # # ]: 0 : if (rss->types & MLX5_RSS_HF_MASK)
2265 : 0 : return rte_flow_error_set(error, ENOTSUP,
2266 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2267 : 0 : &rss->types,
2268 : : "some RSS protocols are not"
2269 : : " supported");
2270 [ # # ]: 0 : if ((rss->types & (RTE_ETH_RSS_L3_SRC_ONLY | RTE_ETH_RSS_L3_DST_ONLY)) &&
2271 [ # # ]: 0 : !(rss->types & RTE_ETH_RSS_IP))
2272 : 0 : return rte_flow_error_set(error, EINVAL,
2273 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
2274 : : "L3 partial RSS requested but L3 RSS"
2275 : : " type not specified");
2276 [ # # ]: 0 : if ((rss->types & (RTE_ETH_RSS_L4_SRC_ONLY | RTE_ETH_RSS_L4_DST_ONLY)) &&
2277 [ # # ]: 0 : !(rss->types & (RTE_ETH_RSS_UDP | RTE_ETH_RSS_TCP)))
2278 : 0 : return rte_flow_error_set(error, EINVAL,
2279 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
2280 : : "L4 partial RSS requested but L4 RSS"
2281 : : " type not specified");
2282 [ # # # # ]: 0 : if (!priv->rxqs_n && priv->ext_rxqs == NULL)
2283 : 0 : return rte_flow_error_set(error, EINVAL,
2284 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2285 : : NULL, "No Rx queues configured");
2286 [ # # ]: 0 : if (!rss->queue_num)
2287 : 0 : return rte_flow_error_set(error, EINVAL,
2288 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2289 : : NULL, "No queues configured");
2290 : 0 : ret = mlx5_validate_rss_queues(dev, rss->queue, rss->queue_num,
2291 : : &message, &queue_idx);
2292 [ # # ]: 0 : if (ret != 0) {
2293 : 0 : return rte_flow_error_set(error, -ret,
2294 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2295 : 0 : &rss->queue[queue_idx], message);
2296 : : }
2297 : : return 0;
2298 : : }
2299 : :
2300 : : /*
2301 : : * Validate the rss action.
2302 : : *
2303 : : * @param[in] action
2304 : : * Pointer to the queue action.
2305 : : * @param[in] action_flags
2306 : : * Bit-fields that holds the actions detected until now.
2307 : : * @param[in] dev
2308 : : * Pointer to the Ethernet device structure.
2309 : : * @param[in] attr
2310 : : * Attributes of flow that includes this action.
2311 : : * @param[in] item_flags
2312 : : * Items that were detected.
2313 : : * @param[out] error
2314 : : * Pointer to error structure.
2315 : : *
2316 : : * @return
2317 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2318 : : */
2319 : : int
2320 : 0 : mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
2321 : : uint64_t action_flags,
2322 : : struct rte_eth_dev *dev,
2323 : : const struct rte_flow_attr *attr,
2324 : : uint64_t item_flags,
2325 : : struct rte_flow_error *error)
2326 : : {
2327 : 0 : const struct rte_flow_action_rss *rss = action->conf;
2328 : 0 : int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2329 : : int ret;
2330 : :
2331 [ # # ]: 0 : if (action_flags & MLX5_FLOW_FATE_ACTIONS)
2332 : 0 : return rte_flow_error_set(error, EINVAL,
2333 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2334 : : "can't have 2 fate actions"
2335 : : " in same flow");
2336 : 0 : ret = mlx5_validate_action_rss(dev, action, error);
2337 [ # # ]: 0 : if (ret)
2338 : : return ret;
2339 [ # # ]: 0 : if (attr->egress)
2340 : 0 : return rte_flow_error_set(error, ENOTSUP,
2341 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
2342 : : "rss action not supported for "
2343 : : "egress");
2344 [ # # # # ]: 0 : if (rss->level > 1 && !tunnel)
2345 : 0 : return rte_flow_error_set(error, EINVAL,
2346 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
2347 : : "inner RSS is not supported for "
2348 : : "non-tunnel flows");
2349 [ # # ]: 0 : if ((item_flags & MLX5_FLOW_LAYER_ECPRI) &&
2350 : : !(item_flags & MLX5_FLOW_LAYER_INNER_L4_UDP)) {
2351 : 0 : return rte_flow_error_set(error, EINVAL,
2352 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
2353 : : "RSS on eCPRI is not supported now");
2354 : : }
2355 [ # # ]: 0 : if ((item_flags & MLX5_FLOW_LAYER_MPLS) &&
2356 : : !(item_flags &
2357 [ # # ]: 0 : (MLX5_FLOW_LAYER_INNER_L2 | MLX5_FLOW_LAYER_INNER_L3)) &&
2358 : : rss->level > 1)
2359 : 0 : return rte_flow_error_set(error, EINVAL,
2360 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2361 : : "MPLS inner RSS needs to specify inner L2/L3 items after MPLS in pattern");
2362 : : return 0;
2363 : : }
2364 : :
2365 : : /*
2366 : : * Validate the default miss action.
2367 : : *
2368 : : * @param[in] action_flags
2369 : : * Bit-fields that holds the actions detected until now.
2370 : : * @param[out] error
2371 : : * Pointer to error structure.
2372 : : *
2373 : : * @return
2374 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2375 : : */
2376 : : int
2377 : 0 : mlx5_flow_validate_action_default_miss(uint64_t action_flags,
2378 : : const struct rte_flow_attr *attr,
2379 : : struct rte_flow_error *error)
2380 : : {
2381 [ # # ]: 0 : if (action_flags & MLX5_FLOW_FATE_ACTIONS)
2382 : 0 : return rte_flow_error_set(error, EINVAL,
2383 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2384 : : "can't have 2 fate actions in"
2385 : : " same flow");
2386 [ # # ]: 0 : if (attr->egress)
2387 : 0 : return rte_flow_error_set(error, ENOTSUP,
2388 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
2389 : : "default miss action not supported "
2390 : : "for egress");
2391 [ # # ]: 0 : if (attr->group)
2392 : 0 : return rte_flow_error_set(error, ENOTSUP,
2393 : : RTE_FLOW_ERROR_TYPE_ATTR_GROUP, NULL,
2394 : : "only group 0 is supported");
2395 [ # # ]: 0 : if (attr->transfer)
2396 : 0 : return rte_flow_error_set(error, ENOTSUP,
2397 : : RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
2398 : : NULL, "transfer is not supported");
2399 : : return 0;
2400 : : }
2401 : :
2402 : : /*
2403 : : * Validate the count action.
2404 : : *
2405 : : * @param[in] dev
2406 : : * Pointer to the Ethernet device structure.
2407 : : * @param[in] attr
2408 : : * Attributes of flow that includes this action.
2409 : : * @param[out] error
2410 : : * Pointer to error structure.
2411 : : *
2412 : : * @return
2413 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2414 : : */
2415 : : int
2416 : 0 : mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,
2417 : : const struct rte_flow_attr *attr,
2418 : : struct rte_flow_error *error)
2419 : : {
2420 [ # # ]: 0 : if (attr->egress)
2421 : 0 : return rte_flow_error_set(error, ENOTSUP,
2422 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
2423 : : "count action not supported for "
2424 : : "egress");
2425 : : return 0;
2426 : : }
2427 : :
2428 : : /*
2429 : : * Validate the ASO CT action.
2430 : : *
2431 : : * @param[in] dev
2432 : : * Pointer to the Ethernet device structure.
2433 : : * @param[in] conntrack
2434 : : * Pointer to the CT action profile.
2435 : : * @param[out] error
2436 : : * Pointer to error structure.
2437 : : *
2438 : : * @return
2439 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2440 : : */
2441 : : int
2442 : 0 : mlx5_validate_action_ct(struct rte_eth_dev *dev,
2443 : : const struct rte_flow_action_conntrack *conntrack,
2444 : : struct rte_flow_error *error)
2445 : : {
2446 : : RTE_SET_USED(dev);
2447 : :
2448 [ # # ]: 0 : if (conntrack->state > RTE_FLOW_CONNTRACK_STATE_TIME_WAIT)
2449 : 0 : return rte_flow_error_set(error, EINVAL,
2450 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2451 : : "Invalid CT state");
2452 [ # # ]: 0 : if (conntrack->last_index > RTE_FLOW_CONNTRACK_FLAG_RST)
2453 : 0 : return rte_flow_error_set(error, EINVAL,
2454 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2455 : : "Invalid last TCP packet flag");
2456 : : return 0;
2457 : : }
2458 : :
2459 : : /**
2460 : : * Validate the level value for modify field action.
2461 : : *
2462 : : * @param[in] data
2463 : : * Pointer to the rte_flow_field_data structure either src or dst.
2464 : : * @param[out] error
2465 : : * Pointer to error structure.
2466 : : *
2467 : : * @return
2468 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2469 : : */
2470 : : int
2471 : 0 : mlx5_flow_validate_modify_field_level(const struct rte_flow_field_data *data,
2472 : : struct rte_flow_error *error)
2473 : : {
2474 [ # # # # ]: 0 : if (data->level == 0 || data->field == RTE_FLOW_FIELD_FLEX_ITEM)
2475 : : return 0;
2476 [ # # ]: 0 : if (data->field != RTE_FLOW_FIELD_TAG &&
2477 : : data->field != (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG) {
2478 [ # # ]: 0 : if (data->level > 1)
2479 : 0 : return rte_flow_error_set(error, ENOTSUP,
2480 : : RTE_FLOW_ERROR_TYPE_ACTION,
2481 : : NULL,
2482 : : "inner header fields modification is not supported");
2483 : : return 0;
2484 : : }
2485 [ # # ]: 0 : if (data->tag_index != 0)
2486 : 0 : return rte_flow_error_set(error, EINVAL,
2487 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2488 : : "tag array can be provided using 'level' or 'tag_index' fields, not both");
2489 : : /*
2490 : : * The tag array for RTE_FLOW_FIELD_TAG type is provided using
2491 : : * 'tag_index' field. In old API, it was provided using 'level' field
2492 : : * and it is still supported for backwards compatibility.
2493 : : */
2494 : 0 : DRV_LOG(DEBUG, "tag array provided in 'level' field instead of 'tag_index' field.");
2495 : 0 : return 0;
2496 : : }
2497 : :
2498 : : /**
2499 : : * Validate ICMP6 item.
2500 : : *
2501 : : * @param[in] item
2502 : : * Item specification.
2503 : : * @param[in] item_flags
2504 : : * Bit-fields that holds the items detected until now.
2505 : : * @param[in] ext_vlan_sup
2506 : : * Whether extended VLAN features are supported or not.
2507 : : * @param[out] error
2508 : : * Pointer to error structure.
2509 : : *
2510 : : * @return
2511 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2512 : : */
2513 : : int
2514 : 0 : mlx5_flow_validate_item_icmp6(const struct rte_eth_dev *dev,
2515 : : const struct rte_flow_item *item,
2516 : : uint64_t item_flags,
2517 : : uint8_t target_protocol,
2518 : : struct rte_flow_error *error)
2519 : : {
2520 : 0 : const struct rte_flow_item_icmp6 *mask = item->mask;
2521 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2522 [ # # ]: 0 : const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
2523 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6;
2524 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2525 : : MLX5_FLOW_LAYER_OUTER_L4;
2526 : : int ret;
2527 : :
2528 [ # # ]: 0 : if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMPV6)
2529 : 0 : return rte_flow_error_set(error, EINVAL,
2530 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2531 : : "protocol filtering not compatible"
2532 : : " with ICMP6 layer");
2533 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
2534 [ # # ]: 0 : if (!(item_flags & l3m))
2535 : 0 : return rte_flow_error_set(error, EINVAL,
2536 : : RTE_FLOW_ERROR_TYPE_ITEM,
2537 : : item, "IPv6 is mandatory to filter on ICMP6");
2538 : : }
2539 [ # # ]: 0 : if (item_flags & l4m)
2540 : 0 : return rte_flow_error_set(error, EINVAL,
2541 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2542 : : "multiple L4 layers not supported");
2543 [ # # ]: 0 : if (!mask)
2544 : : mask = &rte_flow_item_icmp6_mask;
2545 : 0 : ret = mlx5_flow_item_acceptable
2546 : : (dev, item, (const uint8_t *)mask,
2547 : : (const uint8_t *)&rte_flow_item_icmp6_mask,
2548 : : sizeof(struct rte_flow_item_icmp6),
2549 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2550 : : if (ret < 0)
2551 : : return ret;
2552 : : return 0;
2553 : : }
2554 : :
2555 : : /**
2556 : : * Validate ICMP6 echo request/reply item.
2557 : : *
2558 : : * @param[in] item
2559 : : * Item specification.
2560 : : * @param[in] item_flags
2561 : : * Bit-fields that holds the items detected until now.
2562 : : * @param[in] ext_vlan_sup
2563 : : * Whether extended VLAN features are supported or not.
2564 : : * @param[out] error
2565 : : * Pointer to error structure.
2566 : : *
2567 : : * @return
2568 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2569 : : */
2570 : : int
2571 : 0 : mlx5_flow_validate_item_icmp6_echo(const struct rte_eth_dev *dev,
2572 : : const struct rte_flow_item *item,
2573 : : uint64_t item_flags,
2574 : : uint8_t target_protocol,
2575 : : struct rte_flow_error *error)
2576 : : {
2577 : 0 : const struct rte_flow_item_icmp6_echo *mask = item->mask;
2578 : 0 : const struct rte_flow_item_icmp6_echo nic_mask = {
2579 : : .hdr.base.type = 0xff,
2580 : : .hdr.base.code = 0xff,
2581 : : .hdr.identifier = RTE_BE16(0xffff),
2582 : : .hdr.sequence = RTE_BE16(0xffff),
2583 : : };
2584 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2585 [ # # ]: 0 : const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
2586 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6;
2587 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2588 : : MLX5_FLOW_LAYER_OUTER_L4;
2589 : : int ret;
2590 : :
2591 [ # # ]: 0 : if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMPV6)
2592 : 0 : return rte_flow_error_set(error, EINVAL,
2593 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2594 : : "protocol filtering not compatible"
2595 : : " with ICMP6 layer");
2596 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
2597 [ # # ]: 0 : if (!(item_flags & l3m))
2598 : 0 : return rte_flow_error_set(error, EINVAL,
2599 : : RTE_FLOW_ERROR_TYPE_ITEM,
2600 : : item, "IPv6 is mandatory to filter on ICMP6");
2601 : : }
2602 [ # # ]: 0 : if (item_flags & l4m)
2603 : 0 : return rte_flow_error_set(error, EINVAL,
2604 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2605 : : "multiple L4 layers not supported");
2606 [ # # ]: 0 : if (!mask)
2607 : : mask = &nic_mask;
2608 : 0 : ret = mlx5_flow_item_acceptable
2609 : : (dev, item, (const uint8_t *)mask,
2610 : : (const uint8_t *)&nic_mask,
2611 : : sizeof(struct rte_flow_item_icmp6_echo),
2612 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2613 : : if (ret < 0)
2614 : : return ret;
2615 : : return 0;
2616 : : }
2617 : :
2618 : : /**
2619 : : * Validate ICMP item.
2620 : : *
2621 : : * @param[in] item
2622 : : * Item specification.
2623 : : * @param[in] item_flags
2624 : : * Bit-fields that holds the items detected until now.
2625 : : * @param[out] error
2626 : : * Pointer to error structure.
2627 : : *
2628 : : * @return
2629 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2630 : : */
2631 : : int
2632 : 0 : mlx5_flow_validate_item_icmp(const struct rte_eth_dev *dev,
2633 : : const struct rte_flow_item *item,
2634 : : uint64_t item_flags,
2635 : : uint8_t target_protocol,
2636 : : struct rte_flow_error *error)
2637 : : {
2638 : 0 : const struct rte_flow_item_icmp *mask = item->mask;
2639 : 0 : const struct rte_flow_item_icmp nic_mask = {
2640 : : .hdr.icmp_type = 0xff,
2641 : : .hdr.icmp_code = 0xff,
2642 : : .hdr.icmp_ident = RTE_BE16(0xffff),
2643 : : .hdr.icmp_seq_nb = RTE_BE16(0xffff),
2644 : : };
2645 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2646 [ # # ]: 0 : const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
2647 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4;
2648 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2649 : : MLX5_FLOW_LAYER_OUTER_L4;
2650 : : int ret;
2651 : :
2652 [ # # ]: 0 : if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMP)
2653 : 0 : return rte_flow_error_set(error, EINVAL,
2654 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2655 : : "protocol filtering not compatible"
2656 : : " with ICMP layer");
2657 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
2658 [ # # ]: 0 : if (!(item_flags & l3m))
2659 : 0 : return rte_flow_error_set(error, EINVAL,
2660 : : RTE_FLOW_ERROR_TYPE_ITEM,
2661 : : item, "IPv4 is mandatory to filter on ICMP");
2662 : : }
2663 [ # # ]: 0 : if (item_flags & l4m)
2664 : 0 : return rte_flow_error_set(error, EINVAL,
2665 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2666 : : "multiple L4 layers not supported");
2667 [ # # ]: 0 : if (!mask)
2668 : : mask = &nic_mask;
2669 : 0 : ret = mlx5_flow_item_acceptable
2670 : : (dev, item, (const uint8_t *)mask,
2671 : : (const uint8_t *)&nic_mask,
2672 : : sizeof(struct rte_flow_item_icmp),
2673 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2674 : : if (ret < 0)
2675 : : return ret;
2676 : : return 0;
2677 : : }
2678 : :
2679 : : /**
2680 : : * Validate Ethernet item.
2681 : : *
2682 : : * @param[in] item
2683 : : * Item specification.
2684 : : * @param[in] item_flags
2685 : : * Bit-fields that holds the items detected until now.
2686 : : * @param[out] error
2687 : : * Pointer to error structure.
2688 : : *
2689 : : * @return
2690 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2691 : : */
2692 : : int
2693 : 0 : mlx5_flow_validate_item_eth(const struct rte_eth_dev *dev,
2694 : : const struct rte_flow_item *item,
2695 : : uint64_t item_flags, bool ext_vlan_sup,
2696 : : struct rte_flow_error *error)
2697 : : {
2698 : 0 : const struct rte_flow_item_eth *mask = item->mask;
2699 : 0 : const struct rte_flow_item_eth nic_mask = {
2700 : : .hdr.dst_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
2701 : : .hdr.src_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
2702 : : .hdr.ether_type = RTE_BE16(0xffff),
2703 : : .has_vlan = ext_vlan_sup ? 1 : 0,
2704 : : };
2705 : : int ret;
2706 : 0 : int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2707 [ # # ]: 0 : const uint64_t ethm = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
2708 : : MLX5_FLOW_LAYER_OUTER_L2;
2709 : :
2710 [ # # ]: 0 : if (item_flags & ethm)
2711 : 0 : return rte_flow_error_set(error, ENOTSUP,
2712 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2713 : : "multiple L2 layers not supported");
2714 [ # # # # : 0 : if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_L3)) ||
# # ]
2715 [ # # ]: 0 : (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_L3)))
2716 : 0 : return rte_flow_error_set(error, EINVAL,
2717 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2718 : : "L2 layer should not follow "
2719 : : "L3 layers");
2720 [ # # # # : 0 : if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_VLAN)) ||
# # ]
2721 [ # # ]: 0 : (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_VLAN)))
2722 : 0 : return rte_flow_error_set(error, EINVAL,
2723 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2724 : : "L2 layer should not follow VLAN");
2725 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_GTP)
2726 : 0 : return rte_flow_error_set(error, EINVAL,
2727 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2728 : : "L2 layer should not follow GTP");
2729 [ # # ]: 0 : if (!mask)
2730 : : mask = &rte_flow_item_eth_mask;
2731 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2732 : : (const uint8_t *)&nic_mask,
2733 : : sizeof(struct rte_flow_item_eth),
2734 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2735 : 0 : return ret;
2736 : : }
2737 : :
2738 : : /**
2739 : : * Validate VLAN item.
2740 : : *
2741 : : * @param[in] item
2742 : : * Item specification.
2743 : : * @param[in] item_flags
2744 : : * Bit-fields that holds the items detected until now.
2745 : : * @param[in] dev
2746 : : * Ethernet device flow is being created on.
2747 : : * @param[out] error
2748 : : * Pointer to error structure.
2749 : : *
2750 : : * @return
2751 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2752 : : */
2753 : : int
2754 : 0 : mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
2755 : : uint64_t item_flags,
2756 : : struct rte_eth_dev *dev,
2757 : : struct rte_flow_error *error)
2758 : : {
2759 : 0 : const struct rte_flow_item_vlan *spec = item->spec;
2760 : 0 : const struct rte_flow_item_vlan *mask = item->mask;
2761 : 0 : const struct rte_flow_item_vlan nic_mask = {
2762 : : .hdr.vlan_tci = RTE_BE16(UINT16_MAX),
2763 : : .hdr.eth_proto = RTE_BE16(UINT16_MAX),
2764 : : };
2765 : : uint16_t vlan_tag = 0;
2766 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2767 : : int ret;
2768 : : const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
2769 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L4) :
2770 : : (MLX5_FLOW_LAYER_OUTER_L3 |
2771 : : MLX5_FLOW_LAYER_OUTER_L4);
2772 [ # # ]: 0 : const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
2773 : : MLX5_FLOW_LAYER_OUTER_VLAN;
2774 : :
2775 [ # # ]: 0 : if (item_flags & vlanm)
2776 : 0 : return rte_flow_error_set(error, EINVAL,
2777 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2778 : : "multiple VLAN layers not supported");
2779 [ # # ]: 0 : else if ((item_flags & l34m) != 0)
2780 : 0 : return rte_flow_error_set(error, EINVAL,
2781 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2782 : : "VLAN cannot follow L3/L4 layer");
2783 [ # # ]: 0 : if (!mask)
2784 : : mask = &rte_flow_item_vlan_mask;
2785 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2786 : : (const uint8_t *)&nic_mask,
2787 : : sizeof(struct rte_flow_item_vlan),
2788 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2789 [ # # ]: 0 : if (ret)
2790 : : return ret;
2791 [ # # # # ]: 0 : if (!tunnel && mask->hdr.vlan_tci != RTE_BE16(0x0fff)) {
2792 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2793 : :
2794 [ # # ]: 0 : if (priv->vmwa_context) {
2795 : : /*
2796 : : * Non-NULL context means we have a virtual machine
2797 : : * and SR-IOV enabled, we have to create VLAN interface
2798 : : * to make hypervisor to setup E-Switch vport
2799 : : * context correctly. We avoid creating the multiple
2800 : : * VLAN interfaces, so we cannot support VLAN tag mask.
2801 : : */
2802 : 0 : return rte_flow_error_set(error, EINVAL,
2803 : : RTE_FLOW_ERROR_TYPE_ITEM,
2804 : : item,
2805 : : "VLAN tag mask is not"
2806 : : " supported in virtual"
2807 : : " environment");
2808 : : }
2809 : : }
2810 [ # # ]: 0 : if (spec) {
2811 : 0 : vlan_tag = spec->hdr.vlan_tci;
2812 : 0 : vlan_tag &= mask->hdr.vlan_tci;
2813 : : }
2814 : : /*
2815 : : * From verbs perspective an empty VLAN is equivalent
2816 : : * to a packet without VLAN layer.
2817 : : */
2818 [ # # ]: 0 : if (!vlan_tag)
2819 : 0 : return rte_flow_error_set(error, EINVAL,
2820 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2821 : 0 : item->spec,
2822 : : "VLAN cannot be empty");
2823 : : return 0;
2824 : : }
2825 : :
2826 : : /**
2827 : : * Validate IPV4 item.
2828 : : *
2829 : : * @param[in] item
2830 : : * Item specification.
2831 : : * @param[in] item_flags
2832 : : * Bit-fields that holds the items detected until now.
2833 : : * @param[in] last_item
2834 : : * Previous validated item in the pattern items.
2835 : : * @param[in] ether_type
2836 : : * Type in the ethernet layer header (including dot1q).
2837 : : * @param[in] acc_mask
2838 : : * Acceptable mask, if NULL default internal default mask
2839 : : * will be used to check whether item fields are supported.
2840 : : * @param[in] range_accepted
2841 : : * True if range of values is accepted for specific fields, false otherwise.
2842 : : * @param[out] error
2843 : : * Pointer to error structure.
2844 : : *
2845 : : * @return
2846 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2847 : : */
2848 : : int
2849 : 0 : mlx5_flow_validate_item_ipv4(const struct rte_eth_dev *dev,
2850 : : const struct rte_flow_item *item,
2851 : : uint64_t item_flags,
2852 : : uint64_t last_item,
2853 : : uint16_t ether_type,
2854 : : const struct rte_flow_item_ipv4 *acc_mask,
2855 : : bool range_accepted,
2856 : : struct rte_flow_error *error)
2857 : : {
2858 : 0 : const struct rte_flow_item_ipv4 *mask = item->mask;
2859 : 0 : const struct rte_flow_item_ipv4 *spec = item->spec;
2860 : 0 : const struct rte_flow_item_ipv4 nic_mask = {
2861 : : .hdr = {
2862 : : .src_addr = RTE_BE32(0xffffffff),
2863 : : .dst_addr = RTE_BE32(0xffffffff),
2864 : : .type_of_service = 0xff,
2865 : : .next_proto_id = 0xff,
2866 : : },
2867 : : };
2868 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2869 [ # # ]: 0 : const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2870 : : MLX5_FLOW_LAYER_OUTER_L3;
2871 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2872 : : MLX5_FLOW_LAYER_OUTER_L4;
2873 : : int ret;
2874 : : uint8_t next_proto = 0xFF;
2875 : : const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2876 : : MLX5_FLOW_LAYER_OUTER_VLAN |
2877 : : MLX5_FLOW_LAYER_INNER_VLAN);
2878 : :
2879 [ # # ]: 0 : if ((last_item & l2_vlan) && ether_type &&
2880 [ # # ]: 0 : ether_type != RTE_ETHER_TYPE_IPV4)
2881 : 0 : return rte_flow_error_set(error, EINVAL,
2882 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2883 : : "IPv4 cannot follow L2/VLAN layer "
2884 : : "which ether type is not IPv4");
2885 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_IPIP) {
2886 [ # # ]: 0 : if (mask && spec)
2887 : 0 : next_proto = mask->hdr.next_proto_id &
2888 : 0 : spec->hdr.next_proto_id;
2889 [ # # ]: 0 : if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2890 : 0 : return rte_flow_error_set(error, EINVAL,
2891 : : RTE_FLOW_ERROR_TYPE_ITEM,
2892 : : item,
2893 : : "multiple tunnel "
2894 : : "not supported");
2895 : : }
2896 [ # # ]: 0 : if (item_flags & l3m)
2897 : 0 : return rte_flow_error_set(error, ENOTSUP,
2898 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2899 : : "multiple L3 layers not supported");
2900 [ # # ]: 0 : else if (item_flags & l4m)
2901 : 0 : return rte_flow_error_set(error, EINVAL,
2902 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2903 : : "L3 cannot follow an L4 layer.");
2904 [ # # ]: 0 : else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2905 : : !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2906 : 0 : return rte_flow_error_set(error, EINVAL,
2907 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2908 : : "L3 cannot follow an NVGRE layer.");
2909 [ # # ]: 0 : if (!mask)
2910 : : mask = &rte_flow_item_ipv4_mask;
2911 [ # # ]: 0 : else if (mask->hdr.next_proto_id != 0 &&
2912 : : mask->hdr.next_proto_id != 0xff)
2913 : 0 : return rte_flow_error_set(error, EINVAL,
2914 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2915 : : "partial mask is not supported"
2916 : : " for protocol");
2917 [ # # ]: 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2918 : : acc_mask ? (const uint8_t *)acc_mask
2919 : : : (const uint8_t *)&nic_mask,
2920 : : sizeof(struct rte_flow_item_ipv4),
2921 : : range_accepted, error);
2922 : : if (ret < 0)
2923 : : return ret;
2924 : : return 0;
2925 : : }
2926 : :
2927 : : /**
2928 : : * Validate IPV6 item.
2929 : : *
2930 : : * @param[in] item
2931 : : * Item specification.
2932 : : * @param[in] item_flags
2933 : : * Bit-fields that holds the items detected until now.
2934 : : * @param[in] last_item
2935 : : * Previous validated item in the pattern items.
2936 : : * @param[in] ether_type
2937 : : * Type in the ethernet layer header (including dot1q).
2938 : : * @param[in] acc_mask
2939 : : * Acceptable mask, if NULL default internal default mask
2940 : : * will be used to check whether item fields are supported.
2941 : : * @param[out] error
2942 : : * Pointer to error structure.
2943 : : *
2944 : : * @return
2945 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2946 : : */
2947 : : int
2948 : 0 : mlx5_flow_validate_item_ipv6(const struct rte_eth_dev *dev,
2949 : : const struct rte_flow_item *item,
2950 : : uint64_t item_flags,
2951 : : uint64_t last_item,
2952 : : uint16_t ether_type,
2953 : : const struct rte_flow_item_ipv6 *acc_mask,
2954 : : struct rte_flow_error *error)
2955 : : {
2956 : 0 : const struct rte_flow_item_ipv6 *mask = item->mask;
2957 : 0 : const struct rte_flow_item_ipv6 *spec = item->spec;
2958 : 0 : const struct rte_flow_item_ipv6 nic_mask = {
2959 : : .hdr = {
2960 : : .src_addr = RTE_IPV6_MASK_FULL,
2961 : : .dst_addr = RTE_IPV6_MASK_FULL,
2962 : : .vtc_flow = RTE_BE32(0xffffffff),
2963 : : .proto = 0xff,
2964 : : },
2965 : : };
2966 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2967 [ # # ]: 0 : const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2968 : : MLX5_FLOW_LAYER_OUTER_L3;
2969 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2970 : : MLX5_FLOW_LAYER_OUTER_L4;
2971 : : int ret;
2972 : : uint8_t next_proto = 0xFF;
2973 : : const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2974 : : MLX5_FLOW_LAYER_OUTER_VLAN |
2975 : : MLX5_FLOW_LAYER_INNER_VLAN);
2976 : :
2977 [ # # ]: 0 : if ((last_item & l2_vlan) && ether_type &&
2978 [ # # ]: 0 : ether_type != RTE_ETHER_TYPE_IPV6)
2979 : 0 : return rte_flow_error_set(error, EINVAL,
2980 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2981 : : "IPv6 cannot follow L2/VLAN layer "
2982 : : "which ether type is not IPv6");
2983 [ # # # # : 0 : if (mask && mask->hdr.proto == UINT8_MAX && spec)
# # ]
2984 : 0 : next_proto = spec->hdr.proto;
2985 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_IPIP) {
2986 [ # # ]: 0 : if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2987 : 0 : return rte_flow_error_set(error, EINVAL,
2988 : : RTE_FLOW_ERROR_TYPE_ITEM,
2989 : : item,
2990 : : "multiple tunnel "
2991 : : "not supported");
2992 : : }
2993 : 0 : if (next_proto == IPPROTO_HOPOPTS ||
2994 [ # # ]: 0 : next_proto == IPPROTO_ROUTING ||
2995 : : next_proto == IPPROTO_FRAGMENT ||
2996 : : next_proto == IPPROTO_AH ||
2997 [ # # ]: 0 : next_proto == IPPROTO_DSTOPTS ||
2998 [ # # ]: 0 : (!mlx5_hws_active(dev) && next_proto == IPPROTO_ESP))
2999 : 0 : return rte_flow_error_set(error, EINVAL,
3000 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3001 : : "IPv6 proto (next header) should "
3002 : : "not be set as extension header");
3003 [ # # ]: 0 : if (item_flags & l3m)
3004 : 0 : return rte_flow_error_set(error, ENOTSUP,
3005 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3006 : : "multiple L3 layers not supported");
3007 [ # # ]: 0 : else if (item_flags & l4m)
3008 : 0 : return rte_flow_error_set(error, EINVAL,
3009 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3010 : : "L3 cannot follow an L4 layer.");
3011 [ # # ]: 0 : else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
3012 : : !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
3013 : 0 : return rte_flow_error_set(error, EINVAL,
3014 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3015 : : "L3 cannot follow an NVGRE layer.");
3016 [ # # ]: 0 : if (!mask)
3017 : : mask = &rte_flow_item_ipv6_mask;
3018 [ # # ]: 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
3019 : : acc_mask ? (const uint8_t *)acc_mask
3020 : : : (const uint8_t *)&nic_mask,
3021 : : sizeof(struct rte_flow_item_ipv6),
3022 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3023 : : if (ret < 0)
3024 : : return ret;
3025 : : return 0;
3026 : : }
3027 : :
3028 : : /**
3029 : : * Validate UDP item.
3030 : : *
3031 : : * @param[in] item
3032 : : * Item specification.
3033 : : * @param[in] item_flags
3034 : : * Bit-fields that holds the items detected until now.
3035 : : * @param[in] target_protocol
3036 : : * The next protocol in the previous item.
3037 : : * @param[in] flow_mask
3038 : : * mlx5 flow-specific (DV, verbs, etc.) supported header fields mask.
3039 : : * @param[out] error
3040 : : * Pointer to error structure.
3041 : : *
3042 : : * @return
3043 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3044 : : */
3045 : : int
3046 : 0 : mlx5_flow_validate_item_udp(const struct rte_eth_dev *dev,
3047 : : const struct rte_flow_item *item,
3048 : : uint64_t item_flags,
3049 : : uint8_t target_protocol,
3050 : : struct rte_flow_error *error)
3051 : : {
3052 : 0 : const struct rte_flow_item_udp *mask = item->mask;
3053 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
3054 [ # # ]: 0 : const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
3055 : : MLX5_FLOW_LAYER_OUTER_L3;
3056 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
3057 : : MLX5_FLOW_LAYER_OUTER_L4;
3058 : : int ret;
3059 : :
3060 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
3061 [ # # ]: 0 : if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
3062 : 0 : return rte_flow_error_set(error, EINVAL,
3063 : : RTE_FLOW_ERROR_TYPE_ITEM,
3064 : : item, "protocol filtering not compatible with UDP layer");
3065 [ # # ]: 0 : if (!(item_flags & l3m))
3066 : 0 : return rte_flow_error_set(error, EINVAL,
3067 : : RTE_FLOW_ERROR_TYPE_ITEM,
3068 : : item,
3069 : : "L3 is mandatory to filter on L4");
3070 : : }
3071 [ # # ]: 0 : if (item_flags & l4m)
3072 : 0 : return rte_flow_error_set(error, EINVAL,
3073 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3074 : : "multiple L4 layers not supported");
3075 [ # # ]: 0 : if (!mask)
3076 : : mask = &rte_flow_item_udp_mask;
3077 : 0 : ret = mlx5_flow_item_acceptable
3078 : : (dev, item, (const uint8_t *)mask,
3079 : : (const uint8_t *)&rte_flow_item_udp_mask,
3080 : : sizeof(struct rte_flow_item_udp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
3081 : : error);
3082 : : if (ret < 0)
3083 : : return ret;
3084 : : return 0;
3085 : : }
3086 : :
3087 : : /**
3088 : : * Validate TCP item.
3089 : : *
3090 : : * @param[in] item
3091 : : * Item specification.
3092 : : * @param[in] item_flags
3093 : : * Bit-fields that holds the items detected until now.
3094 : : * @param[in] target_protocol
3095 : : * The next protocol in the previous item.
3096 : : * @param[out] error
3097 : : * Pointer to error structure.
3098 : : *
3099 : : * @return
3100 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3101 : : */
3102 : : int
3103 : 0 : mlx5_flow_validate_item_tcp(const struct rte_eth_dev *dev,
3104 : : const struct rte_flow_item *item,
3105 : : uint64_t item_flags,
3106 : : uint8_t target_protocol,
3107 : : const struct rte_flow_item_tcp *flow_mask,
3108 : : struct rte_flow_error *error)
3109 : : {
3110 : 0 : const struct rte_flow_item_tcp *mask = item->mask;
3111 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
3112 [ # # ]: 0 : const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
3113 : : MLX5_FLOW_LAYER_OUTER_L3;
3114 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
3115 : : MLX5_FLOW_LAYER_OUTER_L4;
3116 : : int ret;
3117 : :
3118 : : MLX5_ASSERT(flow_mask);
3119 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
3120 [ # # ]: 0 : if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
3121 : 0 : return rte_flow_error_set(error, EINVAL,
3122 : : RTE_FLOW_ERROR_TYPE_ITEM,
3123 : : item, "protocol filtering not compatible with TCP layer");
3124 [ # # ]: 0 : if (!(item_flags & l3m))
3125 : 0 : return rte_flow_error_set(error, EINVAL,
3126 : : RTE_FLOW_ERROR_TYPE_ITEM,
3127 : : item, "L3 is mandatory to filter on L4");
3128 : : }
3129 [ # # ]: 0 : if (item_flags & l4m)
3130 : 0 : return rte_flow_error_set(error, EINVAL,
3131 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3132 : : "multiple L4 layers not supported");
3133 [ # # ]: 0 : if (!mask)
3134 : : mask = &rte_flow_item_tcp_mask;
3135 : 0 : ret = mlx5_flow_item_acceptable
3136 : : (dev, item, (const uint8_t *)mask,
3137 : : (const uint8_t *)flow_mask,
3138 : : sizeof(struct rte_flow_item_tcp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
3139 : : error);
3140 : : if (ret < 0)
3141 : : return ret;
3142 : : return 0;
3143 : : }
3144 : :
3145 : : /**
3146 : : * Validate VXLAN item.
3147 : : *
3148 : : * @param[in] dev
3149 : : * Pointer to the Ethernet device structure.
3150 : : * @param[in] udp_dport
3151 : : * UDP destination port
3152 : : * @param[in] item
3153 : : * Item specification.
3154 : : * @param[in] item_flags
3155 : : * Bit-fields that holds the items detected until now.
3156 : : * @param root
3157 : : * Whether action is on root table.
3158 : : * @param[out] error
3159 : : * Pointer to error structure.
3160 : : *
3161 : : * @return
3162 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3163 : : */
3164 : : int
3165 : 0 : mlx5_flow_validate_item_vxlan(struct rte_eth_dev *dev,
3166 : : uint16_t udp_dport,
3167 : : const struct rte_flow_item *item,
3168 : : uint64_t item_flags,
3169 : : bool root,
3170 : : struct rte_flow_error *error)
3171 : : {
3172 : 0 : const struct rte_flow_item_vxlan *spec = item->spec;
3173 : 0 : const struct rte_flow_item_vxlan *mask = item->mask;
3174 : : int ret;
3175 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3176 : : union vni {
3177 : : uint32_t vlan_id;
3178 : : uint8_t vni[4];
3179 : 0 : } id = { .vlan_id = 0, };
3180 : 0 : const struct rte_flow_item_vxlan nic_mask = {
3181 : : .hdr.vni = { 0xff, 0xff, 0xff },
3182 : : .hdr.rsvd1 = 0xff,
3183 : : };
3184 : : const struct rte_flow_item_vxlan *valid_mask;
3185 : :
3186 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3187 : 0 : return rte_flow_error_set(error, ENOTSUP,
3188 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3189 : : "multiple tunnel layers not"
3190 : : " supported");
3191 : : /* HWS can match entire VXLAN, VXLAN-GBP and VXLAN-GPE headers */
3192 [ # # ]: 0 : if (mlx5_hws_active(dev))
3193 : : return 0;
3194 : : valid_mask = &rte_flow_item_vxlan_mask;
3195 : : /*
3196 : : * Verify only UDPv4 is present as defined in
3197 : : * https://tools.ietf.org/html/rfc7348
3198 : : */
3199 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
3200 : 0 : return rte_flow_error_set(error, EINVAL,
3201 : : RTE_FLOW_ERROR_TYPE_ITEM,
3202 : : item, "no outer UDP layer found");
3203 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
3204 : 0 : return rte_flow_error_set(error, ENOTSUP,
3205 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3206 : : "VXLAN tunnel must be fully defined");
3207 [ # # ]: 0 : if (!mask)
3208 : : mask = &rte_flow_item_vxlan_mask;
3209 : :
3210 [ # # ]: 0 : if (priv->sh->steering_format_version !=
3211 : : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5 ||
3212 [ # # ]: 0 : !udp_dport || udp_dport == MLX5_UDP_PORT_VXLAN) {
3213 : : /* non-root table */
3214 [ # # # # ]: 0 : if (!root && priv->sh->misc5_cap)
3215 : : valid_mask = &nic_mask;
3216 : : /* Group zero in NIC domain */
3217 [ # # # # ]: 0 : if (!root && priv->sh->tunnel_header_0_1)
3218 : : valid_mask = &nic_mask;
3219 : : }
3220 : 0 : ret = mlx5_flow_item_acceptable
3221 : : (dev, item, (const uint8_t *)mask,
3222 : : (const uint8_t *)valid_mask,
3223 : : sizeof(struct rte_flow_item_vxlan),
3224 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3225 : : if (ret < 0)
3226 : : return ret;
3227 : : if (spec) {
3228 : : memcpy(&id.vni[1], spec->hdr.vni, 3);
3229 : : memcpy(&id.vni[1], mask->hdr.vni, 3);
3230 : : }
3231 : : return 0;
3232 : : }
3233 : :
3234 : : /**
3235 : : * Validate VXLAN_GPE item.
3236 : : *
3237 : : * @param[in] item
3238 : : * Item specification.
3239 : : * @param[in] item_flags
3240 : : * Bit-fields that holds the items detected until now.
3241 : : * @param[in] priv
3242 : : * Pointer to the private data structure.
3243 : : * @param[in] target_protocol
3244 : : * The next protocol in the previous item.
3245 : : * @param[out] error
3246 : : * Pointer to error structure.
3247 : : *
3248 : : * @return
3249 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3250 : : */
3251 : : int
3252 : 0 : mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
3253 : : uint64_t item_flags,
3254 : : struct rte_eth_dev *dev,
3255 : : struct rte_flow_error *error)
3256 : : {
3257 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3258 : : const struct rte_flow_item_vxlan_gpe *spec = item->spec;
3259 : 0 : const struct rte_flow_item_vxlan_gpe *mask = item->mask;
3260 : : int ret;
3261 : : union vni {
3262 : : uint32_t vlan_id;
3263 : : uint8_t vni[4];
3264 : 0 : } id = { .vlan_id = 0, };
3265 : :
3266 : 0 : struct rte_flow_item_vxlan_gpe nic_mask = {
3267 : : .vni = { 0xff, 0xff, 0xff },
3268 : : .protocol = 0xff,
3269 : : .flags = 0xff,
3270 : : };
3271 : :
3272 [ # # ]: 0 : if (!priv->sh->config.l3_vxlan_en)
3273 : 0 : return rte_flow_error_set(error, ENOTSUP,
3274 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3275 : : "L3 VXLAN is not enabled by device"
3276 : : " parameter and/or not configured in"
3277 : : " firmware");
3278 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3279 : 0 : return rte_flow_error_set(error, ENOTSUP,
3280 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3281 : : "multiple tunnel layers not"
3282 : : " supported");
3283 : : /*
3284 : : * Verify only UDPv4 is present as defined in
3285 : : * https://tools.ietf.org/html/rfc7348
3286 : : */
3287 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
3288 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
3289 : 0 : return rte_flow_error_set(error, EINVAL,
3290 : : RTE_FLOW_ERROR_TYPE_ITEM,
3291 : : item, "no outer UDP layer found");
3292 : : }
3293 [ # # ]: 0 : if (!mask)
3294 : : mask = &rte_flow_item_vxlan_gpe_mask;
3295 [ # # ]: 0 : if (mlx5_hws_active(dev) ||
3296 [ # # ]: 0 : (priv->sh->misc5_cap && priv->sh->tunnel_header_0_1)) {
3297 : 0 : nic_mask.rsvd0[0] = 0xff;
3298 : 0 : nic_mask.rsvd0[1] = 0xff;
3299 : 0 : nic_mask.rsvd1 = 0xff;
3300 : : }
3301 : 0 : ret = mlx5_flow_item_acceptable
3302 : : (dev, item, (const uint8_t *)mask,
3303 : : (const uint8_t *)&nic_mask,
3304 : : sizeof(struct rte_flow_item_vxlan_gpe),
3305 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3306 [ # # ]: 0 : if (ret < 0)
3307 : : return ret;
3308 : : if (spec) {
3309 : : memcpy(&id.vni[1], spec->hdr.vni, 3);
3310 : : memcpy(&id.vni[1], mask->hdr.vni, 3);
3311 : : }
3312 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
3313 : 0 : return rte_flow_error_set(error, ENOTSUP,
3314 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3315 : : "VXLAN-GPE tunnel must be fully"
3316 : : " defined");
3317 : : return 0;
3318 : : }
3319 : : /**
3320 : : * Validate GRE Key item.
3321 : : *
3322 : : * @param[in] item
3323 : : * Item specification.
3324 : : * @param[in] item_flags
3325 : : * Bit flags to mark detected items.
3326 : : * @param[in] gre_item
3327 : : * Pointer to gre_item
3328 : : * @param[out] error
3329 : : * Pointer to error structure.
3330 : : *
3331 : : * @return
3332 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3333 : : */
3334 : : int
3335 : 0 : mlx5_flow_validate_item_gre_key(const struct rte_eth_dev *dev,
3336 : : const struct rte_flow_item *item,
3337 : : uint64_t item_flags,
3338 : : const struct rte_flow_item *gre_item,
3339 : : struct rte_flow_error *error)
3340 : : {
3341 : 0 : const rte_be32_t *mask = item->mask;
3342 : : int ret = 0;
3343 : 0 : rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
3344 : : const struct rte_flow_item_gre *gre_spec;
3345 : : const struct rte_flow_item_gre *gre_mask;
3346 : :
3347 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_GRE_KEY)
3348 : 0 : return rte_flow_error_set(error, ENOTSUP,
3349 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3350 : : "Multiple GRE key not support");
3351 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_GRE))
3352 : 0 : return rte_flow_error_set(error, ENOTSUP,
3353 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3354 : : "No preceding GRE header");
3355 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_INNER)
3356 : 0 : return rte_flow_error_set(error, ENOTSUP,
3357 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3358 : : "GRE key following a wrong item");
3359 [ # # ]: 0 : gre_mask = gre_item ? gre_item->mask : NULL;
3360 [ # # ]: 0 : if (!gre_mask)
3361 : : gre_mask = &rte_flow_item_gre_mask;
3362 [ # # ]: 0 : gre_spec = gre_item ? gre_item->spec : NULL;
3363 [ # # # # ]: 0 : if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
3364 [ # # ]: 0 : !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
3365 : 0 : return rte_flow_error_set(error, EINVAL,
3366 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3367 : : "Key bit must be on");
3368 : :
3369 [ # # ]: 0 : if (!mask)
3370 : : mask = &gre_key_default_mask;
3371 : 0 : ret = mlx5_flow_item_acceptable
3372 : : (dev, item, (const uint8_t *)mask,
3373 : : (const uint8_t *)&gre_key_default_mask,
3374 : : sizeof(rte_be32_t), MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3375 : 0 : return ret;
3376 : : }
3377 : :
3378 : : /**
3379 : : * Validate GRE optional item.
3380 : : *
3381 : : * @param[in] dev
3382 : : * Pointer to the Ethernet device structure.
3383 : : * @param[in] item
3384 : : * Item specification.
3385 : : * @param[in] item_flags
3386 : : * Bit flags to mark detected items.
3387 : : * @param[in] attr
3388 : : * Flow rule attributes.
3389 : : * @param[in] gre_item
3390 : : * Pointer to gre_item
3391 : : * @param[out] error
3392 : : * Pointer to error structure.
3393 : : *
3394 : : * @return
3395 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3396 : : */
3397 : : int
3398 : 0 : mlx5_flow_validate_item_gre_option(struct rte_eth_dev *dev,
3399 : : const struct rte_flow_item *item,
3400 : : uint64_t item_flags,
3401 : : const struct rte_flow_attr *attr,
3402 : : const struct rte_flow_item *gre_item,
3403 : : struct rte_flow_error *error)
3404 : : {
3405 [ # # ]: 0 : const struct rte_flow_item_gre *gre_spec = gre_item ? gre_item->spec : NULL;
3406 [ # # ]: 0 : const struct rte_flow_item_gre *gre_mask = gre_item ? gre_item->mask : NULL;
3407 : 0 : const struct rte_flow_item_gre_opt *spec = item->spec;
3408 : 0 : const struct rte_flow_item_gre_opt *mask = item->mask;
3409 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3410 : : int ret = 0;
3411 : 0 : struct rte_flow_item_gre_opt nic_mask = {
3412 : : .checksum_rsvd = {
3413 : : .checksum = RTE_BE16(UINT16_MAX),
3414 : : .reserved1 = 0x0,
3415 : : },
3416 : : .key = {
3417 : : .key = RTE_BE32(UINT32_MAX),
3418 : : },
3419 : : .sequence = {
3420 : : .sequence = RTE_BE32(UINT32_MAX),
3421 : : },
3422 : : };
3423 : :
3424 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_GRE))
3425 : 0 : return rte_flow_error_set(error, ENOTSUP,
3426 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3427 : : "No preceding GRE header");
3428 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_INNER)
3429 : 0 : return rte_flow_error_set(error, ENOTSUP,
3430 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3431 : : "GRE option following a wrong item");
3432 [ # # # # : 0 : if ((!spec && !mlx5_hws_active(dev)) || !mask)
# # ]
3433 : 0 : return rte_flow_error_set(error, EINVAL,
3434 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3435 : : "At least one field gre_option(checksum/key/sequence) must be specified");
3436 [ # # ]: 0 : if (!gre_mask)
3437 : : gre_mask = &rte_flow_item_gre_mask;
3438 [ # # ]: 0 : if (mask->checksum_rsvd.checksum)
3439 [ # # # # ]: 0 : if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x8000)) &&
3440 [ # # ]: 0 : !(gre_spec->c_rsvd0_ver & RTE_BE16(0x8000)))
3441 : 0 : return rte_flow_error_set(error, EINVAL,
3442 : : RTE_FLOW_ERROR_TYPE_ITEM,
3443 : : item,
3444 : : "Checksum bit must be on");
3445 [ # # ]: 0 : if (mask->key.key)
3446 [ # # # # ]: 0 : if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
3447 [ # # ]: 0 : !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
3448 : 0 : return rte_flow_error_set(error, EINVAL,
3449 : : RTE_FLOW_ERROR_TYPE_ITEM,
3450 : : item, "Key bit must be on");
3451 [ # # ]: 0 : if (mask->sequence.sequence)
3452 [ # # # # ]: 0 : if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x1000)) &&
3453 [ # # ]: 0 : !(gre_spec->c_rsvd0_ver & RTE_BE16(0x1000)))
3454 : 0 : return rte_flow_error_set(error, EINVAL,
3455 : : RTE_FLOW_ERROR_TYPE_ITEM,
3456 : : item,
3457 : : "Sequence bit must be on");
3458 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
3459 [ # # # # ]: 0 : if (mask->checksum_rsvd.checksum || mask->sequence.sequence) {
3460 [ # # ]: 0 : if (priv->sh->steering_format_version ==
3461 : 0 : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5 ||
3462 [ # # ]: 0 : ((attr->group ||
3463 [ # # # # ]: 0 : (attr->transfer && priv->fdb_def_rule)) &&
3464 [ # # ]: 0 : !priv->sh->misc5_cap) ||
3465 [ # # ]: 0 : (!(priv->sh->tunnel_header_0_1 &&
3466 [ # # ]: 0 : priv->sh->tunnel_header_2_3) &&
3467 : 0 : !attr->group &&
3468 [ # # # # ]: 0 : (!attr->transfer || !priv->fdb_def_rule)))
3469 : 0 : return rte_flow_error_set
3470 : : (error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM,
3471 : : item, "Checksum/Sequence not supported");
3472 : : }
3473 : : }
3474 : 0 : ret = mlx5_flow_item_acceptable
3475 : : (dev, item, (const uint8_t *)mask,
3476 : : (const uint8_t *)&nic_mask,
3477 : : sizeof(struct rte_flow_item_gre_opt),
3478 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3479 : 0 : return ret;
3480 : : }
3481 : :
3482 : : /**
3483 : : * Validate GRE item.
3484 : : *
3485 : : * @param[in] item
3486 : : * Item specification.
3487 : : * @param[in] item_flags
3488 : : * Bit flags to mark detected items.
3489 : : * @param[in] target_protocol
3490 : : * The next protocol in the previous item.
3491 : : * @param[out] error
3492 : : * Pointer to error structure.
3493 : : *
3494 : : * @return
3495 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3496 : : */
3497 : : int
3498 : 0 : mlx5_flow_validate_item_gre(const struct rte_eth_dev *dev,
3499 : : const struct rte_flow_item *item,
3500 : : uint64_t item_flags,
3501 : : uint8_t target_protocol,
3502 : : struct rte_flow_error *error)
3503 : : {
3504 : : const struct rte_flow_item_gre *spec __rte_unused = item->spec;
3505 : 0 : const struct rte_flow_item_gre *mask = item->mask;
3506 : : int ret;
3507 : 0 : const struct rte_flow_item_gre nic_mask = {
3508 : : .c_rsvd0_ver = RTE_BE16(0xB000),
3509 : : .protocol = RTE_BE16(UINT16_MAX),
3510 : : };
3511 : :
3512 [ # # ]: 0 : if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
3513 : 0 : return rte_flow_error_set(error, EINVAL,
3514 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3515 : : "protocol filtering not compatible"
3516 : : " with this GRE layer");
3517 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3518 : 0 : return rte_flow_error_set(error, ENOTSUP,
3519 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3520 : : "multiple tunnel layers not"
3521 : : " supported");
3522 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP)
3523 : 0 : return rte_flow_error_set(error, ENOTSUP,
3524 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3525 : : "GRE over UDP is not supported");
3526 [ # # ]: 0 : if (item_flags & (MLX5_FLOW_LAYER_OUTER_L4_TCP |
3527 : : MLX5_FLOW_LAYER_ICMP | MLX5_FLOW_LAYER_ICMP6 |
3528 : : MLX5_FLOW_ITEM_ESP))
3529 : 0 : return rte_flow_error_set(error, EINVAL,
3530 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3531 : : "GRE cannot follow TCP, ICMP or ESP layer");
3532 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
3533 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
3534 : 0 : return rte_flow_error_set(error, ENOTSUP,
3535 : : RTE_FLOW_ERROR_TYPE_ITEM,
3536 : : item, "L3 Layer is missing");
3537 : : }
3538 [ # # ]: 0 : if (!mask)
3539 : : mask = &rte_flow_item_gre_mask;
3540 : 0 : ret = mlx5_flow_item_acceptable
3541 : : (dev, item, (const uint8_t *)mask,
3542 : : (const uint8_t *)&nic_mask,
3543 : : sizeof(struct rte_flow_item_gre), MLX5_ITEM_RANGE_NOT_ACCEPTED,
3544 : : error);
3545 : : if (ret < 0)
3546 : : return ret;
3547 : : #ifndef HAVE_MLX5DV_DR
3548 : : #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
3549 : : if (spec && (spec->protocol & mask->protocol))
3550 : : return rte_flow_error_set(error, ENOTSUP,
3551 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3552 : : "without MPLS support the"
3553 : : " specification cannot be used for"
3554 : : " filtering");
3555 : : #endif
3556 : : #endif
3557 : : return 0;
3558 : : }
3559 : :
3560 : : /**
3561 : : * Validate Geneve item.
3562 : : *
3563 : : * @param[in] item
3564 : : * Item specification.
3565 : : * @param[in] itemFlags
3566 : : * Bit-fields that holds the items detected until now.
3567 : : * @param[in] enPriv
3568 : : * Pointer to the private data structure.
3569 : : * @param[out] error
3570 : : * Pointer to error structure.
3571 : : *
3572 : : * @return
3573 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3574 : : */
3575 : :
3576 : : int
3577 : 0 : mlx5_flow_validate_item_geneve(const struct rte_flow_item *item,
3578 : : uint64_t item_flags,
3579 : : struct rte_eth_dev *dev,
3580 : : struct rte_flow_error *error)
3581 : : {
3582 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3583 : 0 : const struct rte_flow_item_geneve *spec = item->spec;
3584 : 0 : const struct rte_flow_item_geneve *mask = item->mask;
3585 : : int ret;
3586 : : uint16_t gbhdr;
3587 [ # # ]: 0 : uint8_t opt_len = priv->sh->cdev->config.hca_attr.geneve_max_opt_len ?
3588 : : MLX5_GENEVE_OPT_LEN_1 : MLX5_GENEVE_OPT_LEN_0;
3589 : 0 : const struct rte_flow_item_geneve nic_mask = {
3590 : : .ver_opt_len_o_c_rsvd0 = RTE_BE16(0x3f80),
3591 : : .vni = { 0xff, 0xff, 0xff },
3592 : : .protocol = RTE_BE16(UINT16_MAX),
3593 : : };
3594 : :
3595 [ # # ]: 0 : if (!priv->sh->cdev->config.hca_attr.tunnel_stateless_geneve_rx)
3596 : 0 : return rte_flow_error_set(error, ENOTSUP,
3597 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3598 : : "L3 Geneve is not enabled by device"
3599 : : " parameter and/or not configured in"
3600 : : " firmware");
3601 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3602 : 0 : return rte_flow_error_set(error, ENOTSUP,
3603 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3604 : : "multiple tunnel layers not"
3605 : : " supported");
3606 : : /*
3607 : : * Verify only UDPv4 is present as defined in
3608 : : * https://tools.ietf.org/html/rfc7348
3609 : : */
3610 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
3611 : 0 : return rte_flow_error_set(error, EINVAL,
3612 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3613 : : "no outer UDP layer found");
3614 [ # # ]: 0 : if (!mask)
3615 : : mask = &rte_flow_item_geneve_mask;
3616 : 0 : ret = mlx5_flow_item_acceptable
3617 : : (dev, item, (const uint8_t *)mask,
3618 : : (const uint8_t *)&nic_mask,
3619 : : sizeof(struct rte_flow_item_geneve),
3620 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3621 [ # # ]: 0 : if (ret)
3622 : : return ret;
3623 [ # # ]: 0 : if (spec) {
3624 [ # # ]: 0 : gbhdr = rte_be_to_cpu_16(spec->ver_opt_len_o_c_rsvd0);
3625 [ # # ]: 0 : if (MLX5_GENEVE_VER_VAL(gbhdr) ||
3626 [ # # # # ]: 0 : MLX5_GENEVE_CRITO_VAL(gbhdr) ||
3627 [ # # ]: 0 : MLX5_GENEVE_RSVD_VAL(gbhdr) || spec->rsvd1)
3628 : 0 : return rte_flow_error_set(error, ENOTSUP,
3629 : : RTE_FLOW_ERROR_TYPE_ITEM,
3630 : : item,
3631 : : "Geneve protocol unsupported"
3632 : : " fields are being used");
3633 [ # # ]: 0 : if (MLX5_GENEVE_OPTLEN_VAL(gbhdr) > opt_len)
3634 : 0 : return rte_flow_error_set
3635 : : (error, ENOTSUP,
3636 : : RTE_FLOW_ERROR_TYPE_ITEM,
3637 : : item,
3638 : : "Unsupported Geneve options length");
3639 : : }
3640 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
3641 : 0 : return rte_flow_error_set
3642 : : (error, ENOTSUP,
3643 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3644 : : "Geneve tunnel must be fully defined");
3645 : : return 0;
3646 : : }
3647 : :
3648 : : /**
3649 : : * Validate Geneve TLV option item.
3650 : : *
3651 : : * @param[in] item
3652 : : * Item specification.
3653 : : * @param[in] last_item
3654 : : * Previous validated item in the pattern items.
3655 : : * @param[in] geneve_item
3656 : : * Previous GENEVE item specification.
3657 : : * @param[in] dev
3658 : : * Pointer to the rte_eth_dev structure.
3659 : : * @param[out] error
3660 : : * Pointer to error structure.
3661 : : *
3662 : : * @return
3663 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3664 : : */
3665 : : int
3666 : 0 : mlx5_flow_validate_item_geneve_opt(const struct rte_flow_item *item,
3667 : : uint64_t last_item,
3668 : : const struct rte_flow_item *geneve_item,
3669 : : struct rte_eth_dev *dev,
3670 : : struct rte_flow_error *error)
3671 : : {
3672 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3673 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
3674 : : struct mlx5_geneve_tlv_option_resource *geneve_opt_resource;
3675 : 0 : struct mlx5_hca_attr *hca_attr = &sh->cdev->config.hca_attr;
3676 : 0 : uint8_t data_max_supported =
3677 : 0 : hca_attr->max_geneve_tlv_option_data_len * 4;
3678 : : const struct rte_flow_item_geneve *geneve_spec;
3679 : : const struct rte_flow_item_geneve *geneve_mask;
3680 : 0 : const struct rte_flow_item_geneve_opt *spec = item->spec;
3681 : 0 : const struct rte_flow_item_geneve_opt *mask = item->mask;
3682 : : unsigned int i;
3683 : : unsigned int data_len;
3684 : : uint8_t tlv_option_len;
3685 : : uint16_t optlen_m, optlen_v;
3686 : : const struct rte_flow_item_geneve_opt full_mask = {
3687 : : .option_class = RTE_BE16(0xffff),
3688 : : .option_type = 0xff,
3689 : : .option_len = 0x1f,
3690 : : };
3691 : :
3692 [ # # ]: 0 : if (!mask)
3693 : : mask = &rte_flow_item_geneve_opt_mask;
3694 [ # # ]: 0 : if (!spec)
3695 : 0 : return rte_flow_error_set
3696 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3697 : : "Geneve TLV opt class/type/length must be specified");
3698 [ # # ]: 0 : if ((uint32_t)spec->option_len > MLX5_GENEVE_OPTLEN_MASK)
3699 : 0 : return rte_flow_error_set
3700 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3701 : : "Geneve TLV opt length exceeds the limit (31)");
3702 : : /* Check if class type and length masks are full. */
3703 [ # # ]: 0 : if (full_mask.option_class != mask->option_class ||
3704 : 0 : full_mask.option_type != mask->option_type ||
3705 [ # # ]: 0 : full_mask.option_len != (mask->option_len & full_mask.option_len))
3706 : 0 : return rte_flow_error_set
3707 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3708 : : "Geneve TLV opt class/type/length masks must be full");
3709 : : /* Check if length is supported */
3710 [ # # ]: 0 : if ((uint32_t)spec->option_len >
3711 : : hca_attr->max_geneve_tlv_option_data_len)
3712 : 0 : return rte_flow_error_set
3713 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3714 : : "Geneve TLV opt length not supported");
3715 [ # # ]: 0 : if (hca_attr->max_geneve_tlv_options > 1)
3716 : 0 : DRV_LOG(DEBUG,
3717 : : "max_geneve_tlv_options supports more than 1 option");
3718 : : /* Check GENEVE item preceding. */
3719 [ # # # # ]: 0 : if (!geneve_item || !(last_item & MLX5_FLOW_LAYER_GENEVE))
3720 : 0 : return rte_flow_error_set
3721 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3722 : : "Geneve opt item must be preceded with Geneve item");
3723 : 0 : geneve_spec = geneve_item->spec;
3724 [ # # ]: 0 : geneve_mask = geneve_item->mask ? geneve_item->mask :
3725 : : &rte_flow_item_geneve_mask;
3726 : : /* Check if GENEVE TLV option size doesn't exceed option length */
3727 [ # # # # ]: 0 : if (geneve_spec && (geneve_mask->ver_opt_len_o_c_rsvd0 ||
3728 [ # # ]: 0 : geneve_spec->ver_opt_len_o_c_rsvd0)) {
3729 : 0 : tlv_option_len = spec->option_len & mask->option_len;
3730 [ # # ]: 0 : optlen_v = rte_be_to_cpu_16(geneve_spec->ver_opt_len_o_c_rsvd0);
3731 : 0 : optlen_v = MLX5_GENEVE_OPTLEN_VAL(optlen_v);
3732 [ # # ]: 0 : optlen_m = rte_be_to_cpu_16(geneve_mask->ver_opt_len_o_c_rsvd0);
3733 : 0 : optlen_m = MLX5_GENEVE_OPTLEN_VAL(optlen_m);
3734 [ # # ]: 0 : if ((optlen_v & optlen_m) <= tlv_option_len)
3735 : 0 : return rte_flow_error_set
3736 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3737 : : "GENEVE TLV option length exceeds optlen");
3738 : : }
3739 : : /* Check if length is 0 or data is 0. */
3740 [ # # # # ]: 0 : if (spec->data == NULL || spec->option_len == 0)
3741 : 0 : return rte_flow_error_set
3742 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3743 : : "Geneve TLV opt with zero data/length not supported");
3744 : : /* Check not all data & mask are 0. */
3745 : 0 : data_len = spec->option_len * 4;
3746 [ # # ]: 0 : if (mask->data == NULL) {
3747 [ # # ]: 0 : for (i = 0; i < data_len; i++)
3748 [ # # ]: 0 : if (spec->data[i])
3749 : : break;
3750 [ # # ]: 0 : if (i == data_len)
3751 : 0 : return rte_flow_error_set(error, ENOTSUP,
3752 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3753 : : "Can't match on Geneve option data 0");
3754 : : } else {
3755 [ # # ]: 0 : for (i = 0; i < data_len; i++)
3756 [ # # ]: 0 : if (spec->data[i] & mask->data[i])
3757 : : break;
3758 [ # # ]: 0 : if (i == data_len)
3759 : 0 : return rte_flow_error_set(error, ENOTSUP,
3760 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3761 : : "Can't match on Geneve option data and mask 0");
3762 : : /* Check data mask supported. */
3763 [ # # ]: 0 : for (i = data_max_supported; i < data_len ; i++)
3764 [ # # ]: 0 : if (mask->data[i])
3765 : 0 : return rte_flow_error_set(error, ENOTSUP,
3766 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3767 : : "Data mask is of unsupported size");
3768 : : }
3769 : : /* Check GENEVE option is supported in NIC. */
3770 [ # # ]: 0 : if (!hca_attr->geneve_tlv_opt)
3771 : 0 : return rte_flow_error_set
3772 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3773 : : "Geneve TLV opt not supported");
3774 : : /* Check if we already have geneve option with different type/class. */
3775 : 0 : rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
3776 : 0 : geneve_opt_resource = sh->geneve_tlv_option_resource;
3777 [ # # ]: 0 : if (geneve_opt_resource != NULL)
3778 : 0 : if (geneve_opt_resource->option_class != spec->option_class ||
3779 [ # # ]: 0 : geneve_opt_resource->option_type != spec->option_type ||
3780 : : geneve_opt_resource->length != spec->option_len) {
3781 : : rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
3782 : 0 : return rte_flow_error_set(error, ENOTSUP,
3783 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3784 : : "Only one Geneve TLV option supported");
3785 : : }
3786 : : rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
3787 : 0 : return 0;
3788 : : }
3789 : :
3790 : : /**
3791 : : * Validate MPLS item.
3792 : : *
3793 : : * @param[in] dev
3794 : : * Pointer to the rte_eth_dev structure.
3795 : : * @param[in] item
3796 : : * Item specification.
3797 : : * @param[in] item_flags
3798 : : * Bit-fields that holds the items detected until now.
3799 : : * @param[in] prev_layer
3800 : : * The protocol layer indicated in previous item.
3801 : : * @param[out] error
3802 : : * Pointer to error structure.
3803 : : *
3804 : : * @return
3805 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3806 : : */
3807 : : int
3808 : 0 : mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev __rte_unused,
3809 : : const struct rte_flow_item *item __rte_unused,
3810 : : uint64_t item_flags __rte_unused,
3811 : : uint64_t prev_layer __rte_unused,
3812 : : struct rte_flow_error *error)
3813 : : {
3814 : : #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
3815 [ # # ]: 0 : const struct rte_flow_item_mpls hws_nic_mask = {
3816 : : .label_tc_s = {0xff, 0xff, 0xff},
3817 : : .ttl = 0xff
3818 : : };
3819 : : const struct rte_flow_item_mpls *nic_mask = !mlx5_hws_active(dev) ?
3820 [ # # ]: 0 : &rte_flow_item_mpls_mask : &hws_nic_mask;
3821 : 0 : const struct rte_flow_item_mpls *mask = item->mask;
3822 : : struct mlx5_priv *priv = dev->data->dev_private;
3823 : : int ret;
3824 : :
3825 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
3826 : : /* MPLS has HW support in HWS */
3827 [ # # ]: 0 : if (!priv->sh->dev_cap.mpls_en)
3828 : 0 : return rte_flow_error_set(error, ENOTSUP,
3829 : : RTE_FLOW_ERROR_TYPE_ITEM,
3830 : : item, "MPLS not supported or disabled in firmware configuration.");
3831 : : /* MPLS over UDP, GRE is allowed */
3832 [ # # ]: 0 : if (!(prev_layer & (MLX5_FLOW_LAYER_OUTER_L4_UDP |
3833 : : MLX5_FLOW_LAYER_GRE |
3834 : : MLX5_FLOW_LAYER_GRE_KEY)))
3835 : 0 : return rte_flow_error_set(error, EINVAL,
3836 : : RTE_FLOW_ERROR_TYPE_ITEM,
3837 : : item, "protocol filtering not compatible with MPLS layer");
3838 : : /* Multi-tunnel isn't allowed but MPLS over GRE is an exception. */
3839 [ # # ]: 0 : if ((item_flags & MLX5_FLOW_LAYER_TUNNEL) &&
3840 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_GRE))
3841 : 0 : return rte_flow_error_set(error, ENOTSUP,
3842 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3843 : : "multiple tunnel layers not supported");
3844 : : }
3845 [ # # ]: 0 : if (!mask)
3846 : : mask = nic_mask;
3847 : 0 : ret = mlx5_flow_item_acceptable
3848 : : (dev, item, (const uint8_t *)mask,
3849 : : (const uint8_t *)nic_mask,
3850 : : sizeof(struct rte_flow_item_mpls),
3851 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3852 : : if (ret < 0)
3853 : : return ret;
3854 : : return 0;
3855 : : #else
3856 : : return rte_flow_error_set(error, ENOTSUP,
3857 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3858 : : "MPLS is not supported by Verbs, please"
3859 : : " update.");
3860 : : #endif
3861 : : }
3862 : :
3863 : : /**
3864 : : * Validate NVGRE item.
3865 : : *
3866 : : * @param[in] item
3867 : : * Item specification.
3868 : : * @param[in] item_flags
3869 : : * Bit flags to mark detected items.
3870 : : * @param[in] target_protocol
3871 : : * The next protocol in the previous item.
3872 : : * @param[out] error
3873 : : * Pointer to error structure.
3874 : : *
3875 : : * @return
3876 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3877 : : */
3878 : : int
3879 : 0 : mlx5_flow_validate_item_nvgre(const struct rte_eth_dev *dev,
3880 : : const struct rte_flow_item *item,
3881 : : uint64_t item_flags,
3882 : : uint8_t target_protocol,
3883 : : struct rte_flow_error *error)
3884 : : {
3885 : 0 : const struct rte_flow_item_nvgre *mask = item->mask;
3886 : : int ret;
3887 : :
3888 [ # # ]: 0 : const struct rte_flow_item_nvgre hws_nic_mask = {
3889 : : .c_k_s_rsvd0_ver = RTE_BE16(0xB000),
3890 : : .protocol = RTE_BE16(UINT16_MAX),
3891 : : .tni = {0xff, 0xff, 0xff},
3892 : : .flow_id = 0xff
3893 : : };
3894 : : const struct rte_flow_item_nvgre *nic_mask = !mlx5_hws_active(dev) ?
3895 [ # # ]: 0 : &rte_flow_item_nvgre_mask : &hws_nic_mask;
3896 : :
3897 [ # # ]: 0 : if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
3898 : 0 : return rte_flow_error_set(error, EINVAL,
3899 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3900 : : "protocol filtering not compatible"
3901 : : " with this GRE layer");
3902 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3903 : 0 : return rte_flow_error_set(error, ENOTSUP,
3904 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3905 : : "multiple tunnel layers not"
3906 : : " supported");
3907 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP)
3908 : 0 : return rte_flow_error_set(error, ENOTSUP,
3909 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3910 : : "NVGRE over UDP is not supported");
3911 [ # # ]: 0 : if (item_flags & (MLX5_FLOW_LAYER_OUTER_L4_TCP |
3912 : : MLX5_FLOW_LAYER_ICMP | MLX5_FLOW_LAYER_ICMP6 |
3913 : : MLX5_FLOW_ITEM_ESP))
3914 : 0 : return rte_flow_error_set(error, EINVAL,
3915 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3916 : : "NVGRE cannot follow TCP, ICMP or ESP layer");
3917 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
3918 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
3919 : 0 : return rte_flow_error_set(error, ENOTSUP,
3920 : : RTE_FLOW_ERROR_TYPE_ITEM,
3921 : : item, "L3 Layer is missing");
3922 : : }
3923 [ # # ]: 0 : if (!mask)
3924 : : mask = nic_mask;
3925 : 0 : ret = mlx5_flow_item_acceptable
3926 : : (dev, item, (const uint8_t *)mask,
3927 : : (const uint8_t *)nic_mask,
3928 : : sizeof(struct rte_flow_item_nvgre),
3929 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3930 : : if (ret < 0)
3931 : : return ret;
3932 : : return 0;
3933 : : }
3934 : :
3935 : : /**
3936 : : * Validate eCPRI item.
3937 : : *
3938 : : * @param[in] item
3939 : : * Item specification.
3940 : : * @param[in] item_flags
3941 : : * Bit-fields that holds the items detected until now.
3942 : : * @param[in] last_item
3943 : : * Previous validated item in the pattern items.
3944 : : * @param[in] ether_type
3945 : : * Type in the ethernet layer header (including dot1q).
3946 : : * @param[in] acc_mask
3947 : : * Acceptable mask, if NULL default internal default mask
3948 : : * will be used to check whether item fields are supported.
3949 : : * @param[out] error
3950 : : * Pointer to error structure.
3951 : : *
3952 : : * @return
3953 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3954 : : */
3955 : : int
3956 : 0 : mlx5_flow_validate_item_ecpri(const struct rte_eth_dev *dev,
3957 : : const struct rte_flow_item *item,
3958 : : uint64_t item_flags,
3959 : : uint64_t last_item,
3960 : : uint16_t ether_type,
3961 : : const struct rte_flow_item_ecpri *acc_mask,
3962 : : struct rte_flow_error *error)
3963 : : {
3964 : 0 : const struct rte_flow_item_ecpri *mask = item->mask;
3965 : 0 : const struct rte_flow_item_ecpri nic_mask = {
3966 : : .hdr = {
3967 : : .common = {
3968 : : .u32 =
3969 : : RTE_BE32(((const struct rte_ecpri_common_hdr) {
3970 : : .type = 0xFF,
3971 : : }).u32),
3972 : : },
3973 : : .dummy[0] = 0xFFFFFFFF,
3974 : : },
3975 : : };
3976 : : const uint64_t outer_l2_vlan = (MLX5_FLOW_LAYER_OUTER_L2 |
3977 : : MLX5_FLOW_LAYER_OUTER_VLAN);
3978 : : struct rte_flow_item_ecpri mask_lo;
3979 : :
3980 [ # # # # ]: 0 : if (!(last_item & outer_l2_vlan) &&
3981 : : last_item != MLX5_FLOW_LAYER_OUTER_L4_UDP)
3982 : 0 : return rte_flow_error_set(error, EINVAL,
3983 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3984 : : "eCPRI can only follow L2/VLAN layer or UDP layer");
3985 [ # # ]: 0 : if ((last_item & outer_l2_vlan) && ether_type &&
3986 [ # # ]: 0 : ether_type != RTE_ETHER_TYPE_ECPRI)
3987 : 0 : return rte_flow_error_set(error, EINVAL,
3988 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3989 : : "eCPRI cannot follow L2/VLAN layer which ether type is not 0xAEFE");
3990 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3991 : 0 : return rte_flow_error_set(error, EINVAL,
3992 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3993 : : "eCPRI with tunnel is not supported right now");
3994 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_OUTER_L3)
3995 : 0 : return rte_flow_error_set(error, ENOTSUP,
3996 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3997 : : "multiple L3 layers not supported");
3998 [ # # ]: 0 : else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP)
3999 : 0 : return rte_flow_error_set(error, EINVAL,
4000 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
4001 : : "eCPRI cannot coexist with a TCP layer");
4002 : : /* In specification, eCPRI could be over UDP layer. */
4003 [ # # ]: 0 : else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP)
4004 : 0 : return rte_flow_error_set(error, EINVAL,
4005 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
4006 : : "eCPRI over UDP layer is not yet supported right now");
4007 : : /* Mask for type field in common header could be zero. */
4008 [ # # ]: 0 : if (!mask)
4009 : : mask = &rte_flow_item_ecpri_mask;
4010 [ # # ]: 0 : mask_lo.hdr.common.u32 = rte_be_to_cpu_32(mask->hdr.common.u32);
4011 : : /* Input mask is in big-endian format. */
4012 [ # # ]: 0 : if (mask_lo.hdr.common.type != 0 && mask_lo.hdr.common.type != 0xff)
4013 : 0 : return rte_flow_error_set(error, EINVAL,
4014 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
4015 : : "partial mask is not supported for protocol");
4016 [ # # # # ]: 0 : else if (mask_lo.hdr.common.type == 0 && mask->hdr.dummy[0] != 0)
4017 : 0 : return rte_flow_error_set(error, EINVAL,
4018 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
4019 : : "message header mask must be after a type mask");
4020 [ # # ]: 0 : return mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
4021 : : acc_mask ? (const uint8_t *)acc_mask
4022 : : : (const uint8_t *)&nic_mask,
4023 : : sizeof(struct rte_flow_item_ecpri),
4024 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
4025 : : }
4026 : :
4027 : : /**
4028 : : * Validate the NSH item.
4029 : : *
4030 : : * @param[in] dev
4031 : : * Pointer to Ethernet device on which flow rule is being created on.
4032 : : * @param[out] error
4033 : : * Pointer to error structure.
4034 : : *
4035 : : * @return
4036 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4037 : : */
4038 : : int
4039 : 0 : mlx5_flow_validate_item_nsh(struct rte_eth_dev *dev,
4040 : : const struct rte_flow_item *item,
4041 : : struct rte_flow_error *error)
4042 : : {
4043 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4044 : :
4045 [ # # ]: 0 : if (item->mask) {
4046 : 0 : return rte_flow_error_set(error, ENOTSUP,
4047 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
4048 : : "NSH fields matching is not supported");
4049 : : }
4050 : :
4051 [ # # ]: 0 : if (!priv->sh->config.dv_flow_en) {
4052 : 0 : return rte_flow_error_set(error, ENOTSUP,
4053 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4054 : : NULL, "NSH support requires DV flow interface");
4055 : : }
4056 : :
4057 [ # # ]: 0 : if (!priv->sh->cdev->config.hca_attr.tunnel_stateless_vxlan_gpe_nsh) {
4058 : 0 : return rte_flow_error_set(error, ENOTSUP,
4059 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
4060 : : "Current FW does not support matching on NSH");
4061 : : }
4062 : :
4063 : : return 0;
4064 : : }
4065 : :
4066 : : static uintptr_t
4067 : 0 : flow_null_list_create(struct rte_eth_dev *dev __rte_unused,
4068 : : enum mlx5_flow_type type __rte_unused,
4069 : : const struct rte_flow_attr *attr __rte_unused,
4070 : : const struct rte_flow_item items[] __rte_unused,
4071 : : const struct rte_flow_action actions[] __rte_unused,
4072 : : bool external __rte_unused,
4073 : : struct rte_flow_error *error)
4074 : : {
4075 : 0 : rte_flow_error_set(error, ENOTSUP,
4076 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
4077 : 0 : return 0;
4078 : : }
4079 : :
4080 : : static int
4081 : 0 : flow_null_validate(struct rte_eth_dev *dev __rte_unused,
4082 : : const struct rte_flow_attr *attr __rte_unused,
4083 : : const struct rte_flow_item items[] __rte_unused,
4084 : : const struct rte_flow_action actions[] __rte_unused,
4085 : : bool external __rte_unused,
4086 : : int hairpin __rte_unused,
4087 : : struct rte_flow_error *error)
4088 : : {
4089 : 0 : return rte_flow_error_set(error, ENOTSUP,
4090 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
4091 : : }
4092 : :
4093 : : static struct mlx5_flow *
4094 : 0 : flow_null_prepare(struct rte_eth_dev *dev __rte_unused,
4095 : : const struct rte_flow_attr *attr __rte_unused,
4096 : : const struct rte_flow_item items[] __rte_unused,
4097 : : const struct rte_flow_action actions[] __rte_unused,
4098 : : struct rte_flow_error *error)
4099 : : {
4100 : 0 : rte_flow_error_set(error, ENOTSUP,
4101 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
4102 : 0 : return NULL;
4103 : : }
4104 : :
4105 : : static int
4106 : 0 : flow_null_translate(struct rte_eth_dev *dev __rte_unused,
4107 : : struct mlx5_flow *dev_flow __rte_unused,
4108 : : const struct rte_flow_attr *attr __rte_unused,
4109 : : const struct rte_flow_item items[] __rte_unused,
4110 : : const struct rte_flow_action actions[] __rte_unused,
4111 : : struct rte_flow_error *error)
4112 : : {
4113 : 0 : return rte_flow_error_set(error, ENOTSUP,
4114 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
4115 : : }
4116 : :
4117 : : static int
4118 : 0 : flow_null_apply(struct rte_eth_dev *dev __rte_unused,
4119 : : struct rte_flow *flow __rte_unused,
4120 : : struct rte_flow_error *error)
4121 : : {
4122 : 0 : return rte_flow_error_set(error, ENOTSUP,
4123 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
4124 : : }
4125 : :
4126 : : static void
4127 : 0 : flow_null_remove(struct rte_eth_dev *dev __rte_unused,
4128 : : struct rte_flow *flow __rte_unused)
4129 : : {
4130 : 0 : }
4131 : :
4132 : : static void
4133 : 0 : flow_null_destroy(struct rte_eth_dev *dev __rte_unused,
4134 : : struct rte_flow *flow __rte_unused)
4135 : : {
4136 : 0 : }
4137 : :
4138 : : static int
4139 : 0 : flow_null_query(struct rte_eth_dev *dev __rte_unused,
4140 : : struct rte_flow *flow __rte_unused,
4141 : : const struct rte_flow_action *actions __rte_unused,
4142 : : void *data __rte_unused,
4143 : : struct rte_flow_error *error)
4144 : : {
4145 : 0 : return rte_flow_error_set(error, ENOTSUP,
4146 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
4147 : : }
4148 : :
4149 : : static int
4150 : 0 : flow_null_sync_domain(struct rte_eth_dev *dev __rte_unused,
4151 : : uint32_t domains __rte_unused,
4152 : : uint32_t flags __rte_unused)
4153 : : {
4154 : 0 : return 0;
4155 : : }
4156 : :
4157 : : int
4158 : 0 : mlx5_flow_null_get_aged_flows(struct rte_eth_dev *dev,
4159 : : void **context __rte_unused,
4160 : : uint32_t nb_contexts __rte_unused,
4161 : : struct rte_flow_error *error __rte_unused)
4162 : : {
4163 : 0 : DRV_LOG(ERR, "port %u get aged flows is not supported.",
4164 : : dev->data->port_id);
4165 : 0 : return -ENOTSUP;
4166 : : }
4167 : :
4168 : : uint32_t
4169 : 0 : mlx5_flow_null_counter_allocate(struct rte_eth_dev *dev)
4170 : : {
4171 : 0 : DRV_LOG(ERR, "port %u counter allocate is not supported.",
4172 : : dev->data->port_id);
4173 : 0 : return 0;
4174 : : }
4175 : :
4176 : : void
4177 : 0 : mlx5_flow_null_counter_free(struct rte_eth_dev *dev,
4178 : : uint32_t counter __rte_unused)
4179 : : {
4180 : 0 : DRV_LOG(ERR, "port %u counter free is not supported.",
4181 : : dev->data->port_id);
4182 : 0 : }
4183 : :
4184 : : int
4185 : 0 : mlx5_flow_null_counter_query(struct rte_eth_dev *dev,
4186 : : uint32_t counter __rte_unused,
4187 : : bool clear __rte_unused,
4188 : : uint64_t *pkts __rte_unused,
4189 : : uint64_t *bytes __rte_unused,
4190 : : void **action __rte_unused)
4191 : : {
4192 : 0 : DRV_LOG(ERR, "port %u counter query is not supported.",
4193 : : dev->data->port_id);
4194 : 0 : return -ENOTSUP;
4195 : : }
4196 : :
4197 : : /* Void driver to protect from null pointer reference. */
4198 : : const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
4199 : : .list_create = flow_null_list_create,
4200 : : .validate = flow_null_validate,
4201 : : .prepare = flow_null_prepare,
4202 : : .translate = flow_null_translate,
4203 : : .apply = flow_null_apply,
4204 : : .remove = flow_null_remove,
4205 : : .destroy = flow_null_destroy,
4206 : : .query = flow_null_query,
4207 : : .sync_domain = flow_null_sync_domain,
4208 : : .get_aged_flows = mlx5_flow_null_get_aged_flows,
4209 : : .counter_alloc = mlx5_flow_null_counter_allocate,
4210 : : .counter_free = mlx5_flow_null_counter_free,
4211 : : .counter_query = mlx5_flow_null_counter_query
4212 : : };
4213 : :
4214 : : /**
4215 : : * Select flow driver type according to flow attributes and device
4216 : : * configuration.
4217 : : *
4218 : : * @param[in] dev
4219 : : * Pointer to the dev structure.
4220 : : * @param[in] attr
4221 : : * Pointer to the flow attributes.
4222 : : *
4223 : : * @return
4224 : : * flow driver type, MLX5_FLOW_TYPE_MAX otherwise.
4225 : : */
4226 : : static enum mlx5_flow_drv_type
4227 : 0 : flow_get_drv_type(struct rte_eth_dev *dev, const struct rte_flow_attr *attr)
4228 : : {
4229 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4230 : : /* The OS can determine first a specific flow type (DV, VERBS) */
4231 : : enum mlx5_flow_drv_type type = mlx5_flow_os_get_type();
4232 : :
4233 : : if (type != MLX5_FLOW_TYPE_MAX)
4234 : : return type;
4235 : : /*
4236 : : * Currently when dv_flow_en == 2, only HW steering engine is
4237 : : * supported. New engines can also be chosen here if ready.
4238 : : */
4239 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
4240 : : return MLX5_FLOW_TYPE_HW;
4241 [ # # ]: 0 : if (!attr)
4242 : : return MLX5_FLOW_TYPE_MIN;
4243 : : /* If no OS specific type - continue with DV/VERBS selection */
4244 [ # # # # ]: 0 : if (attr->transfer && priv->sh->config.dv_esw_en)
4245 : : type = MLX5_FLOW_TYPE_DV;
4246 [ # # ]: 0 : if (!attr->transfer)
4247 [ # # # # : 0 : type = priv->sh->config.dv_flow_en ? MLX5_FLOW_TYPE_DV :
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
4248 : : MLX5_FLOW_TYPE_VERBS;
4249 : : return type;
4250 : : }
4251 : :
4252 : : #define flow_get_drv_ops(type) flow_drv_ops[type]
4253 : :
4254 : : /**
4255 : : * Flow driver validation API. This abstracts calling driver specific functions.
4256 : : * The type of flow driver is determined according to flow attributes.
4257 : : *
4258 : : * @param[in] dev
4259 : : * Pointer to the dev structure.
4260 : : * @param[in] attr
4261 : : * Pointer to the flow attributes.
4262 : : * @param[in] items
4263 : : * Pointer to the list of items.
4264 : : * @param[in] actions
4265 : : * Pointer to the list of actions.
4266 : : * @param[in] external
4267 : : * This flow rule is created by request external to PMD.
4268 : : * @param[in] hairpin
4269 : : * Number of hairpin TX actions, 0 means classic flow.
4270 : : * @param[out] error
4271 : : * Pointer to the error structure.
4272 : : *
4273 : : * @return
4274 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4275 : : */
4276 : : static inline int
4277 : 0 : flow_drv_validate(struct rte_eth_dev *dev,
4278 : : const struct rte_flow_attr *attr,
4279 : : const struct rte_flow_item items[],
4280 : : const struct rte_flow_action actions[],
4281 : : bool external, int hairpin, struct rte_flow_error *error)
4282 : : {
4283 : : const struct mlx5_flow_driver_ops *fops;
4284 : 0 : enum mlx5_flow_drv_type type = flow_get_drv_type(dev, attr);
4285 : :
4286 : 0 : fops = flow_get_drv_ops(type);
4287 : 0 : return fops->validate(dev, attr, items, actions, external,
4288 : : hairpin, error);
4289 : : }
4290 : :
4291 : : /**
4292 : : * Flow driver preparation API. This abstracts calling driver specific
4293 : : * functions. Parent flow (rte_flow) should have driver type (drv_type). It
4294 : : * calculates the size of memory required for device flow, allocates the memory,
4295 : : * initializes the device flow and returns the pointer.
4296 : : *
4297 : : * @note
4298 : : * This function initializes device flow structure such as dv or verbs in
4299 : : * struct mlx5_flow. However, it is caller's responsibility to initialize the
4300 : : * rest. For example, adding returning device flow to flow->dev_flow list and
4301 : : * setting backward reference to the flow should be done out of this function.
4302 : : * layers field is not filled either.
4303 : : *
4304 : : * @param[in] dev
4305 : : * Pointer to the dev structure.
4306 : : * @param[in] attr
4307 : : * Pointer to the flow attributes.
4308 : : * @param[in] items
4309 : : * Pointer to the list of items.
4310 : : * @param[in] actions
4311 : : * Pointer to the list of actions.
4312 : : * @param[in] flow_idx
4313 : : * This memory pool index to the flow.
4314 : : * @param[out] error
4315 : : * Pointer to the error structure.
4316 : : *
4317 : : * @return
4318 : : * Pointer to device flow on success, otherwise NULL and rte_errno is set.
4319 : : */
4320 : : static inline struct mlx5_flow *
4321 : : flow_drv_prepare(struct rte_eth_dev *dev,
4322 : : const struct rte_flow *flow,
4323 : : const struct rte_flow_attr *attr,
4324 : : const struct rte_flow_item items[],
4325 : : const struct rte_flow_action actions[],
4326 : : uint32_t flow_idx,
4327 : : struct rte_flow_error *error)
4328 : : {
4329 : : const struct mlx5_flow_driver_ops *fops;
4330 : 0 : enum mlx5_flow_drv_type type = flow->drv_type;
4331 : : struct mlx5_flow *mlx5_flow = NULL;
4332 : :
4333 : : MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
4334 : 0 : fops = flow_get_drv_ops(type);
4335 : 0 : mlx5_flow = fops->prepare(dev, attr, items, actions, error);
4336 [ # # # # : 0 : if (mlx5_flow)
# # ]
4337 : 0 : mlx5_flow->flow_idx = flow_idx;
4338 : : return mlx5_flow;
4339 : : }
4340 : :
4341 : : /**
4342 : : * Flow driver translation API. This abstracts calling driver specific
4343 : : * functions. Parent flow (rte_flow) should have driver type (drv_type). It
4344 : : * translates a generic flow into a driver flow. flow_drv_prepare() must
4345 : : * precede.
4346 : : *
4347 : : * @note
4348 : : * dev_flow->layers could be filled as a result of parsing during translation
4349 : : * if needed by flow_drv_apply(). dev_flow->flow->actions can also be filled
4350 : : * if necessary. As a flow can have multiple dev_flows by RSS flow expansion,
4351 : : * flow->actions could be overwritten even though all the expanded dev_flows
4352 : : * have the same actions.
4353 : : *
4354 : : * @param[in] dev
4355 : : * Pointer to the rte dev structure.
4356 : : * @param[in, out] dev_flow
4357 : : * Pointer to the mlx5 flow.
4358 : : * @param[in] attr
4359 : : * Pointer to the flow attributes.
4360 : : * @param[in] items
4361 : : * Pointer to the list of items.
4362 : : * @param[in] actions
4363 : : * Pointer to the list of actions.
4364 : : * @param[out] error
4365 : : * Pointer to the error structure.
4366 : : *
4367 : : * @return
4368 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4369 : : */
4370 : : static inline int
4371 : : flow_drv_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
4372 : : const struct rte_flow_attr *attr,
4373 : : const struct rte_flow_item items[],
4374 : : const struct rte_flow_action actions[],
4375 : : struct rte_flow_error *error)
4376 : : {
4377 : : const struct mlx5_flow_driver_ops *fops;
4378 : 0 : enum mlx5_flow_drv_type type = dev_flow->flow->drv_type;
4379 : :
4380 : : MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
4381 : 0 : fops = flow_get_drv_ops(type);
4382 : 0 : return fops->translate(dev, dev_flow, attr, items, actions, error);
4383 : : }
4384 : :
4385 : : /**
4386 : : * Flow driver apply API. This abstracts calling driver specific functions.
4387 : : * Parent flow (rte_flow) should have driver type (drv_type). It applies
4388 : : * translated driver flows on to device. flow_drv_translate() must precede.
4389 : : *
4390 : : * @param[in] dev
4391 : : * Pointer to Ethernet device structure.
4392 : : * @param[in, out] flow
4393 : : * Pointer to flow structure.
4394 : : * @param[out] error
4395 : : * Pointer to error structure.
4396 : : *
4397 : : * @return
4398 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4399 : : */
4400 : : static inline int
4401 : : flow_drv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
4402 : : struct rte_flow_error *error)
4403 : : {
4404 : : const struct mlx5_flow_driver_ops *fops;
4405 : 0 : enum mlx5_flow_drv_type type = flow->drv_type;
4406 : :
4407 : : MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
4408 : 0 : fops = flow_get_drv_ops(type);
4409 : 0 : return fops->apply(dev, flow, error);
4410 : : }
4411 : :
4412 : : /**
4413 : : * Flow driver destroy API. This abstracts calling driver specific functions.
4414 : : * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
4415 : : * on device and releases resources of the flow.
4416 : : *
4417 : : * @param[in] dev
4418 : : * Pointer to Ethernet device.
4419 : : * @param[in, out] flow
4420 : : * Pointer to flow structure.
4421 : : */
4422 : : static inline void
4423 : : flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
4424 : : {
4425 : : const struct mlx5_flow_driver_ops *fops;
4426 : 0 : enum mlx5_flow_drv_type type = flow->drv_type;
4427 : :
4428 : : MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
4429 : 0 : fops = flow_get_drv_ops(type);
4430 : 0 : fops->destroy(dev, flow);
4431 : : }
4432 : :
4433 : : /**
4434 : : * Flow driver find RSS policy tbl API. This abstracts calling driver
4435 : : * specific functions. Parent flow (rte_flow) should have driver
4436 : : * type (drv_type). It will find the RSS policy table that has the rss_desc.
4437 : : *
4438 : : * @param[in] dev
4439 : : * Pointer to Ethernet device.
4440 : : * @param[in, out] flow
4441 : : * Pointer to flow structure.
4442 : : * @param[in] policy
4443 : : * Pointer to meter policy table.
4444 : : * @param[in] rss_desc
4445 : : * Pointer to rss_desc
4446 : : */
4447 : : static struct mlx5_flow_meter_sub_policy *
4448 : : flow_drv_meter_sub_policy_rss_prepare(struct rte_eth_dev *dev,
4449 : : struct rte_flow *flow,
4450 : : struct mlx5_flow_meter_policy *policy,
4451 : : struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS])
4452 : : {
4453 : : const struct mlx5_flow_driver_ops *fops;
4454 : 0 : enum mlx5_flow_drv_type type = flow->drv_type;
4455 : :
4456 : : MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
4457 : 0 : fops = flow_get_drv_ops(type);
4458 : 0 : return fops->meter_sub_policy_rss_prepare(dev, policy, rss_desc);
4459 : : }
4460 : :
4461 : : /**
4462 : : * Flow driver color tag rule API. This abstracts calling driver
4463 : : * specific functions. Parent flow (rte_flow) should have driver
4464 : : * type (drv_type). It will create the color tag rules in hierarchy meter.
4465 : : *
4466 : : * @param[in] dev
4467 : : * Pointer to Ethernet device.
4468 : : * @param[in, out] flow
4469 : : * Pointer to flow structure.
4470 : : * @param[in] fm
4471 : : * Pointer to flow meter structure.
4472 : : * @param[in] src_port
4473 : : * The src port this extra rule should use.
4474 : : * @param[in] item
4475 : : * The src port id match item.
4476 : : * @param[out] error
4477 : : * Pointer to error structure.
4478 : : */
4479 : : static int
4480 : : flow_drv_mtr_hierarchy_rule_create(struct rte_eth_dev *dev,
4481 : : struct rte_flow *flow,
4482 : : struct mlx5_flow_meter_info *fm,
4483 : : int32_t src_port,
4484 : : const struct rte_flow_item *item,
4485 : : struct rte_flow_error *error)
4486 : : {
4487 : : const struct mlx5_flow_driver_ops *fops;
4488 : 0 : enum mlx5_flow_drv_type type = flow->drv_type;
4489 : :
4490 : : MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
4491 : 0 : fops = flow_get_drv_ops(type);
4492 : 0 : return fops->meter_hierarchy_rule_create(dev, fm,
4493 : : src_port, item, error);
4494 : : }
4495 : :
4496 : : /**
4497 : : * Get RSS action from the action list.
4498 : : *
4499 : : * @param[in] dev
4500 : : * Pointer to Ethernet device.
4501 : : * @param[in] actions
4502 : : * Pointer to the list of actions.
4503 : : * @param[in] flow
4504 : : * Parent flow structure pointer.
4505 : : *
4506 : : * @return
4507 : : * Pointer to the RSS action if exist, else return NULL.
4508 : : */
4509 : : static const struct rte_flow_action_rss*
4510 : 0 : flow_get_rss_action(struct rte_eth_dev *dev,
4511 : : const struct rte_flow_action actions[])
4512 : : {
4513 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4514 : : const struct rte_flow_action_rss *rss = NULL;
4515 : : struct mlx5_meter_policy_action_container *acg;
4516 : : struct mlx5_meter_policy_action_container *acy;
4517 : :
4518 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4519 [ # # # # ]: 0 : switch (actions->type) {
4520 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
4521 : 0 : rss = actions->conf;
4522 : 0 : break;
4523 : 0 : case RTE_FLOW_ACTION_TYPE_SAMPLE:
4524 : : {
4525 : 0 : const struct rte_flow_action_sample *sample =
4526 : : actions->conf;
4527 : 0 : const struct rte_flow_action *act = sample->actions;
4528 [ # # ]: 0 : for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++)
4529 [ # # ]: 0 : if (act->type == RTE_FLOW_ACTION_TYPE_RSS)
4530 : 0 : rss = act->conf;
4531 : : break;
4532 : : }
4533 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
4534 : : {
4535 : : uint32_t mtr_idx;
4536 : : struct mlx5_flow_meter_info *fm;
4537 : : struct mlx5_flow_meter_policy *policy;
4538 : 0 : const struct rte_flow_action_meter *mtr = actions->conf;
4539 : :
4540 : 0 : fm = mlx5_flow_meter_find(priv, mtr->mtr_id, &mtr_idx);
4541 [ # # # # ]: 0 : if (fm && !fm->def_policy) {
4542 : 0 : policy = mlx5_flow_meter_policy_find(dev,
4543 : : fm->policy_id, NULL);
4544 : : MLX5_ASSERT(policy);
4545 [ # # ]: 0 : if (policy->is_hierarchy) {
4546 : : policy =
4547 : 0 : mlx5_flow_meter_hierarchy_get_final_policy(dev,
4548 : : policy);
4549 [ # # ]: 0 : if (!policy)
4550 : 0 : return NULL;
4551 : : }
4552 [ # # ]: 0 : if (policy->is_rss) {
4553 : : acg =
4554 : : &policy->act_cnt[RTE_COLOR_GREEN];
4555 : : acy =
4556 : : &policy->act_cnt[RTE_COLOR_YELLOW];
4557 [ # # ]: 0 : if (acg->fate_action ==
4558 : : MLX5_FLOW_FATE_SHARED_RSS)
4559 : 0 : rss = acg->rss->conf;
4560 [ # # ]: 0 : else if (acy->fate_action ==
4561 : : MLX5_FLOW_FATE_SHARED_RSS)
4562 : 0 : rss = acy->rss->conf;
4563 : : }
4564 : : }
4565 : 0 : break;
4566 : : }
4567 : : default:
4568 : : break;
4569 : : }
4570 : : }
4571 : : return rss;
4572 : : }
4573 : :
4574 : : /**
4575 : : * Get ASO age action by index.
4576 : : *
4577 : : * @param[in] dev
4578 : : * Pointer to the Ethernet device structure.
4579 : : * @param[in] age_idx
4580 : : * Index to the ASO age action.
4581 : : *
4582 : : * @return
4583 : : * The specified ASO age action.
4584 : : */
4585 : : struct mlx5_aso_age_action*
4586 : 0 : mlx5_flow_aso_age_get_by_idx(struct rte_eth_dev *dev, uint32_t age_idx)
4587 : : {
4588 : 0 : uint16_t pool_idx = age_idx & UINT16_MAX;
4589 : 0 : uint16_t offset = (age_idx >> 16) & UINT16_MAX;
4590 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4591 : 0 : struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
4592 : : struct mlx5_aso_age_pool *pool;
4593 : :
4594 : 0 : rte_rwlock_read_lock(&mng->resize_rwl);
4595 : 0 : pool = mng->pools[pool_idx];
4596 : : rte_rwlock_read_unlock(&mng->resize_rwl);
4597 : 0 : return &pool->actions[offset - 1];
4598 : : }
4599 : :
4600 : : /* maps indirect action to translated direct in some actions array */
4601 : : struct mlx5_translated_action_handle {
4602 : : struct rte_flow_action_handle *action; /**< Indirect action handle. */
4603 : : int index; /**< Index in related array of rte_flow_action. */
4604 : : };
4605 : :
4606 : : /**
4607 : : * Translates actions of type RTE_FLOW_ACTION_TYPE_INDIRECT to related
4608 : : * direct action if translation possible.
4609 : : * This functionality used to run same execution path for both direct and
4610 : : * indirect actions on flow create. All necessary preparations for indirect
4611 : : * action handling should be performed on *handle* actions list returned
4612 : : * from this call.
4613 : : *
4614 : : * @param[in] dev
4615 : : * Pointer to Ethernet device.
4616 : : * @param[in] actions
4617 : : * List of actions to translate.
4618 : : * @param[out] handle
4619 : : * List to store translated indirect action object handles.
4620 : : * @param[in, out] indir_n
4621 : : * Size of *handle* array. On return should be updated with number of
4622 : : * indirect actions retrieved from the *actions* list.
4623 : : * @param[out] translated_actions
4624 : : * List of actions where all indirect actions were translated to direct
4625 : : * if possible. NULL if no translation took place.
4626 : : * @param[out] error
4627 : : * Pointer to the error structure.
4628 : : *
4629 : : * @return
4630 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4631 : : */
4632 : : static int
4633 : 0 : flow_action_handles_translate(struct rte_eth_dev *dev,
4634 : : const struct rte_flow_action actions[],
4635 : : struct mlx5_translated_action_handle *handle,
4636 : : int *indir_n,
4637 : : struct rte_flow_action **translated_actions,
4638 : : struct rte_flow_error *error)
4639 : : {
4640 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4641 : : struct rte_flow_action *translated = NULL;
4642 : : size_t actions_size;
4643 : : int n;
4644 : : int copied_n = 0;
4645 : : struct mlx5_translated_action_handle *handle_end = NULL;
4646 : :
4647 [ # # ]: 0 : for (n = 0; actions[n].type != RTE_FLOW_ACTION_TYPE_END; n++) {
4648 [ # # ]: 0 : if (actions[n].type != RTE_FLOW_ACTION_TYPE_INDIRECT)
4649 : 0 : continue;
4650 [ # # ]: 0 : if (copied_n == *indir_n) {
4651 : 0 : return rte_flow_error_set
4652 : : (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_NUM,
4653 : : NULL, "too many shared actions");
4654 : : }
4655 : 0 : rte_memcpy(&handle[copied_n].action, &actions[n].conf,
4656 : : sizeof(actions[n].conf));
4657 : 0 : handle[copied_n].index = n;
4658 : 0 : copied_n++;
4659 : : }
4660 : 0 : n++;
4661 : 0 : *indir_n = copied_n;
4662 [ # # ]: 0 : if (!copied_n)
4663 : : return 0;
4664 : 0 : actions_size = sizeof(struct rte_flow_action) * n;
4665 : 0 : translated = mlx5_malloc(MLX5_MEM_ZERO, actions_size, 0, SOCKET_ID_ANY);
4666 [ # # ]: 0 : if (!translated) {
4667 : 0 : rte_errno = ENOMEM;
4668 : 0 : return -ENOMEM;
4669 : : }
4670 : : memcpy(translated, actions, actions_size);
4671 [ # # ]: 0 : for (handle_end = handle + copied_n; handle < handle_end; handle++) {
4672 : : struct mlx5_shared_action_rss *shared_rss;
4673 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle->action;
4674 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
4675 : 0 : uint32_t idx = act_idx &
4676 : : ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
4677 : :
4678 [ # # # # : 0 : switch (type) {
# # ]
4679 : 0 : case MLX5_INDIRECT_ACTION_TYPE_RSS:
4680 : 0 : shared_rss = mlx5_ipool_get
4681 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
4682 : 0 : translated[handle->index].type =
4683 : : RTE_FLOW_ACTION_TYPE_RSS;
4684 : 0 : translated[handle->index].conf =
4685 : 0 : &shared_rss->origin;
4686 : 0 : break;
4687 : 0 : case MLX5_INDIRECT_ACTION_TYPE_COUNT:
4688 : 0 : translated[handle->index].type =
4689 : : (enum rte_flow_action_type)
4690 : : MLX5_RTE_FLOW_ACTION_TYPE_COUNT;
4691 : 0 : translated[handle->index].conf = (void *)(uintptr_t)idx;
4692 : 0 : break;
4693 : 0 : case MLX5_INDIRECT_ACTION_TYPE_METER_MARK:
4694 : 0 : translated[handle->index].type =
4695 : : (enum rte_flow_action_type)
4696 : : MLX5_RTE_FLOW_ACTION_TYPE_METER_MARK;
4697 : 0 : translated[handle->index].conf = (void *)(uintptr_t)idx;
4698 : 0 : break;
4699 : 0 : case MLX5_INDIRECT_ACTION_TYPE_AGE:
4700 [ # # ]: 0 : if (priv->sh->flow_hit_aso_en) {
4701 : 0 : translated[handle->index].type =
4702 : : (enum rte_flow_action_type)
4703 : : MLX5_RTE_FLOW_ACTION_TYPE_AGE;
4704 : 0 : translated[handle->index].conf =
4705 : 0 : (void *)(uintptr_t)idx;
4706 : 0 : break;
4707 : : }
4708 : : /* Fall-through */
4709 : : case MLX5_INDIRECT_ACTION_TYPE_CT:
4710 [ # # ]: 0 : if (priv->sh->ct_aso_en) {
4711 : 0 : translated[handle->index].type =
4712 : : RTE_FLOW_ACTION_TYPE_CONNTRACK;
4713 : 0 : translated[handle->index].conf =
4714 : 0 : (void *)(uintptr_t)idx;
4715 : 0 : break;
4716 : : }
4717 : : /* Fall-through */
4718 : : default:
4719 : 0 : mlx5_free(translated);
4720 : 0 : return rte_flow_error_set
4721 : : (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
4722 : : NULL, "invalid indirect action type");
4723 : : }
4724 : : }
4725 : 0 : *translated_actions = translated;
4726 : 0 : return 0;
4727 : : }
4728 : :
4729 : : /**
4730 : : * Get Shared RSS action from the action list.
4731 : : *
4732 : : * @param[in] dev
4733 : : * Pointer to Ethernet device.
4734 : : * @param[in] shared
4735 : : * Pointer to the list of actions.
4736 : : * @param[in] shared_n
4737 : : * Actions list length.
4738 : : *
4739 : : * @return
4740 : : * The MLX5 RSS action ID if exists, otherwise return 0.
4741 : : */
4742 : : static uint32_t
4743 : 0 : flow_get_shared_rss_action(struct rte_eth_dev *dev,
4744 : : struct mlx5_translated_action_handle *handle,
4745 : : int shared_n)
4746 : : {
4747 : : struct mlx5_translated_action_handle *handle_end;
4748 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4749 : : struct mlx5_shared_action_rss *shared_rss;
4750 : :
4751 : :
4752 [ # # ]: 0 : for (handle_end = handle + shared_n; handle < handle_end; handle++) {
4753 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle->action;
4754 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
4755 : 0 : uint32_t idx = act_idx &
4756 : : ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
4757 [ # # ]: 0 : switch (type) {
4758 : 0 : case MLX5_INDIRECT_ACTION_TYPE_RSS:
4759 : 0 : shared_rss = mlx5_ipool_get
4760 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
4761 : : idx);
4762 : 0 : rte_atomic_fetch_add_explicit(&shared_rss->refcnt, 1,
4763 : : rte_memory_order_relaxed);
4764 : 0 : return idx;
4765 : : default:
4766 : : break;
4767 : : }
4768 : : }
4769 : : return 0;
4770 : : }
4771 : :
4772 : : static unsigned int
4773 : : find_graph_root(uint32_t rss_level)
4774 : : {
4775 : 0 : return rss_level < 2 ? MLX5_EXPANSION_ROOT :
4776 : : MLX5_EXPANSION_ROOT_OUTER;
4777 : : }
4778 : :
4779 : : /**
4780 : : * Get layer flags from the prefix flow.
4781 : : *
4782 : : * Some flows may be split to several subflows, the prefix subflow gets the
4783 : : * match items and the suffix sub flow gets the actions.
4784 : : * Some actions need the user defined match item flags to get the detail for
4785 : : * the action.
4786 : : * This function helps the suffix flow to get the item layer flags from prefix
4787 : : * subflow.
4788 : : *
4789 : : * @param[in] dev_flow
4790 : : * Pointer the created prefix subflow.
4791 : : *
4792 : : * @return
4793 : : * The layers get from prefix subflow.
4794 : : */
4795 : : static inline uint64_t
4796 : 0 : flow_get_prefix_layer_flags(struct mlx5_flow *dev_flow)
4797 : : {
4798 : : uint64_t layers = 0;
4799 : :
4800 : : /*
4801 : : * Layers bits could be localization, but usually the compiler will
4802 : : * help to do the optimization work for source code.
4803 : : * If no decap actions, use the layers directly.
4804 : : */
4805 [ # # ]: 0 : if (!(dev_flow->act_flags & MLX5_FLOW_ACTION_DECAP))
4806 : 0 : return dev_flow->handle->layers;
4807 : : /* Convert L3 layers with decap action. */
4808 [ # # ]: 0 : if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV4)
4809 : : layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV4;
4810 [ # # ]: 0 : else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV6)
4811 : : layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
4812 : : /* Convert L4 layers with decap action. */
4813 [ # # ]: 0 : if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_TCP)
4814 : 0 : layers |= MLX5_FLOW_LAYER_OUTER_L4_TCP;
4815 [ # # ]: 0 : else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_UDP)
4816 : 0 : layers |= MLX5_FLOW_LAYER_OUTER_L4_UDP;
4817 : : return layers;
4818 : : }
4819 : :
4820 : : /**
4821 : : * Get metadata split action information.
4822 : : *
4823 : : * @param[in] actions
4824 : : * Pointer to the list of actions.
4825 : : * @param[out] qrss
4826 : : * Pointer to the return pointer.
4827 : : * @param[out] qrss_type
4828 : : * Pointer to the action type to return. RTE_FLOW_ACTION_TYPE_END is returned
4829 : : * if no QUEUE/RSS is found.
4830 : : * @param[out] encap_idx
4831 : : * Pointer to the index of the encap action if exists, otherwise the last
4832 : : * action index.
4833 : : *
4834 : : * @return
4835 : : * Total number of actions.
4836 : : */
4837 : : static int
4838 : 0 : flow_parse_metadata_split_actions_info(const struct rte_flow_action actions[],
4839 : : const struct rte_flow_action **qrss,
4840 : : int *encap_idx)
4841 : : {
4842 : : const struct rte_flow_action_raw_encap *raw_encap;
4843 : : int actions_n = 0;
4844 : : int raw_decap_idx = -1;
4845 : :
4846 : 0 : *encap_idx = -1;
4847 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4848 [ # # # # : 0 : switch (actions->type) {
# ]
4849 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4850 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4851 : 0 : *encap_idx = actions_n;
4852 : 0 : break;
4853 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4854 : : raw_decap_idx = actions_n;
4855 : 0 : break;
4856 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4857 : 0 : raw_encap = actions->conf;
4858 [ # # ]: 0 : if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4859 : 0 : *encap_idx = raw_decap_idx != -1 ?
4860 [ # # ]: 0 : raw_decap_idx : actions_n;
4861 : : break;
4862 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
4863 : : case RTE_FLOW_ACTION_TYPE_RSS:
4864 : 0 : *qrss = actions;
4865 : 0 : break;
4866 : : default:
4867 : : break;
4868 : : }
4869 : 0 : actions_n++;
4870 : : }
4871 [ # # ]: 0 : if (*encap_idx == -1)
4872 : 0 : *encap_idx = actions_n;
4873 : : /* Count RTE_FLOW_ACTION_TYPE_END. */
4874 : 0 : return actions_n + 1;
4875 : : }
4876 : :
4877 : : /**
4878 : : * Check if the action will change packet.
4879 : : *
4880 : : * @param dev
4881 : : * Pointer to Ethernet device.
4882 : : * @param[in] type
4883 : : * action type.
4884 : : *
4885 : : * @return
4886 : : * true if action will change packet, false otherwise.
4887 : : */
4888 : 0 : static bool flow_check_modify_action_type(struct rte_eth_dev *dev,
4889 : : enum rte_flow_action_type type)
4890 : : {
4891 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4892 : :
4893 [ # # # ]: 0 : switch (type) {
4894 : : case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
4895 : : case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
4896 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
4897 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
4898 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
4899 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
4900 : : case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
4901 : : case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
4902 : : case RTE_FLOW_ACTION_TYPE_DEC_TTL:
4903 : : case RTE_FLOW_ACTION_TYPE_SET_TTL:
4904 : : case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
4905 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
4906 : : case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
4907 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
4908 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
4909 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
4910 : : case RTE_FLOW_ACTION_TYPE_SET_META:
4911 : : case RTE_FLOW_ACTION_TYPE_SET_TAG:
4912 : : case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
4913 : : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4914 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4915 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
4916 : : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4917 : : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
4918 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4919 : : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
4920 : : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4921 : : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4922 : : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
4923 : : return true;
4924 : 0 : case RTE_FLOW_ACTION_TYPE_FLAG:
4925 : : case RTE_FLOW_ACTION_TYPE_MARK:
4926 [ # # ]: 0 : if (priv->sh->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
4927 : : priv->sh->config.dv_xmeta_en != MLX5_XMETA_MODE_META32_HWS)
4928 : : return true;
4929 : : else
4930 : 0 : return false;
4931 : 0 : default:
4932 : 0 : return false;
4933 : : }
4934 : : }
4935 : :
4936 : : /**
4937 : : * Check meter action from the action list.
4938 : : *
4939 : : * @param dev
4940 : : * Pointer to Ethernet device.
4941 : : * @param[in] actions
4942 : : * Pointer to the list of actions.
4943 : : * @param[out] has_mtr
4944 : : * Pointer to the meter exist flag.
4945 : : * @param[out] has_modify
4946 : : * Pointer to the flag showing there's packet change action.
4947 : : * @param[out] meter_id
4948 : : * Pointer to the meter id.
4949 : : *
4950 : : * @return
4951 : : * Total number of actions.
4952 : : */
4953 : : static int
4954 : 0 : flow_check_meter_action(struct rte_eth_dev *dev,
4955 : : const struct rte_flow_action actions[],
4956 : : bool *has_mtr, bool *has_modify, uint32_t *meter_id)
4957 : : {
4958 : : const struct rte_flow_action_meter *mtr = NULL;
4959 : : int actions_n = 0;
4960 : :
4961 : : MLX5_ASSERT(has_mtr);
4962 : 0 : *has_mtr = false;
4963 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4964 [ # # ]: 0 : switch (actions->type) {
4965 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
4966 : 0 : mtr = actions->conf;
4967 : 0 : *meter_id = mtr->mtr_id;
4968 : 0 : *has_mtr = true;
4969 : 0 : break;
4970 : : default:
4971 : : break;
4972 : : }
4973 [ # # ]: 0 : if (!*has_mtr)
4974 : 0 : *has_modify |= flow_check_modify_action_type(dev,
4975 : 0 : actions->type);
4976 : 0 : actions_n++;
4977 : : }
4978 : : /* Count RTE_FLOW_ACTION_TYPE_END. */
4979 : 0 : return actions_n + 1;
4980 : : }
4981 : :
4982 : : /**
4983 : : * Check if the flow should be split due to hairpin.
4984 : : * The reason for the split is that in current HW we can't
4985 : : * support encap and push-vlan on Rx, so if a flow contains
4986 : : * these actions we move it to Tx.
4987 : : *
4988 : : * @param dev
4989 : : * Pointer to Ethernet device.
4990 : : * @param[in] attr
4991 : : * Flow rule attributes.
4992 : : * @param[in] actions
4993 : : * Associated actions (list terminated by the END action).
4994 : : *
4995 : : * @return
4996 : : * > 0 the number of actions and the flow should be split,
4997 : : * 0 when no split required.
4998 : : */
4999 : : static int
5000 : 0 : flow_check_hairpin_split(struct rte_eth_dev *dev,
5001 : : const struct rte_flow_attr *attr,
5002 : : const struct rte_flow_action actions[])
5003 : : {
5004 : : int queue_action = 0;
5005 : : int action_n = 0;
5006 : : int split = 0;
5007 : : int push_vlan = 0;
5008 : : const struct rte_flow_action_queue *queue;
5009 : : const struct rte_flow_action_rss *rss;
5010 : : const struct rte_flow_action_raw_encap *raw_encap;
5011 : : const struct rte_eth_hairpin_conf *conf;
5012 : :
5013 [ # # ]: 0 : if (!attr->ingress)
5014 : : return 0;
5015 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
5016 [ # # ]: 0 : if (actions->type == RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN)
5017 : : push_vlan = 1;
5018 [ # # # # : 0 : switch (actions->type) {
# # ]
5019 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
5020 : 0 : queue = actions->conf;
5021 [ # # ]: 0 : if (queue == NULL)
5022 : : return 0;
5023 : 0 : conf = mlx5_rxq_get_hairpin_conf(dev, queue->index);
5024 [ # # # # ]: 0 : if (conf == NULL || conf->tx_explicit != 0)
5025 : : return 0;
5026 : : queue_action = 1;
5027 : 0 : action_n++;
5028 : 0 : break;
5029 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
5030 : 0 : rss = actions->conf;
5031 [ # # # # ]: 0 : if (rss == NULL || rss->queue_num == 0)
5032 : : return 0;
5033 : 0 : conf = mlx5_rxq_get_hairpin_conf(dev, rss->queue[0]);
5034 [ # # # # ]: 0 : if (conf == NULL || conf->tx_explicit != 0)
5035 : : return 0;
5036 : : queue_action = 1;
5037 : 0 : action_n++;
5038 : 0 : break;
5039 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
5040 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
5041 : : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
5042 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
5043 : 0 : split++;
5044 : 0 : action_n++;
5045 : 0 : break;
5046 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
5047 [ # # ]: 0 : if (push_vlan)
5048 : 0 : split++;
5049 : 0 : action_n++;
5050 : 0 : break;
5051 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
5052 : 0 : raw_encap = actions->conf;
5053 [ # # ]: 0 : if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
5054 : 0 : split++;
5055 : 0 : action_n++;
5056 : 0 : break;
5057 : 0 : default:
5058 : 0 : action_n++;
5059 : 0 : break;
5060 : : }
5061 : : }
5062 [ # # ]: 0 : if (split && queue_action)
5063 : 0 : return action_n;
5064 : : return 0;
5065 : : }
5066 : :
5067 : : int
5068 : 0 : mlx5_flow_dv_mreg_match_cb(void *tool_ctx __rte_unused,
5069 : : struct mlx5_list_entry *entry, void *cb_ctx)
5070 : : {
5071 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
5072 : : struct mlx5_flow_mreg_copy_resource *mcp_res =
5073 : : container_of(entry, typeof(*mcp_res), hlist_ent);
5074 : :
5075 : 0 : return mcp_res->mark_id != *(uint32_t *)(ctx->data);
5076 : : }
5077 : :
5078 : : struct mlx5_list_entry *
5079 : 0 : mlx5_flow_dv_mreg_create_cb(void *tool_ctx, void *cb_ctx)
5080 : : {
5081 : : struct rte_eth_dev *dev = tool_ctx;
5082 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5083 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
5084 : : struct mlx5_flow_mreg_copy_resource *mcp_res;
5085 : 0 : struct rte_flow_error *error = ctx->error;
5086 : 0 : uint32_t idx = 0;
5087 : : int ret;
5088 : 0 : uint32_t mark_id = *(uint32_t *)(ctx->data);
5089 : 0 : struct rte_flow_attr attr = {
5090 : : .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
5091 : : .ingress = 1,
5092 : : };
5093 : 0 : struct mlx5_rte_flow_item_tag tag_spec = {
5094 : : .data = mark_id,
5095 : : };
5096 : 0 : struct rte_flow_item items[] = {
5097 : : [1] = { .type = RTE_FLOW_ITEM_TYPE_END, },
5098 : : };
5099 : 0 : struct rte_flow_action_mark ftag = {
5100 : : .id = mark_id,
5101 : : };
5102 : 0 : struct mlx5_flow_action_copy_mreg cp_mreg = {
5103 : : .dst = REG_B,
5104 : : .src = REG_NON,
5105 : : };
5106 : 0 : struct rte_flow_action_jump jump = {
5107 : : .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
5108 : : };
5109 : 0 : struct rte_flow_action actions[] = {
5110 : : [3] = { .type = RTE_FLOW_ACTION_TYPE_END, },
5111 : : };
5112 : :
5113 : : /* Fill the register fields in the flow. */
5114 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
5115 [ # # ]: 0 : if (ret < 0)
5116 : : return NULL;
5117 : 0 : tag_spec.id = ret;
5118 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
5119 [ # # ]: 0 : if (ret < 0)
5120 : : return NULL;
5121 : 0 : cp_mreg.src = ret;
5122 : : /* Provide the full width of FLAG specific value. */
5123 [ # # ]: 0 : if (mark_id == (priv->sh->dv_regc0_mask & MLX5_FLOW_MARK_DEFAULT))
5124 : 0 : tag_spec.data = MLX5_FLOW_MARK_DEFAULT;
5125 : : /* Build a new flow. */
5126 [ # # ]: 0 : if (mark_id != MLX5_DEFAULT_COPY_ID) {
5127 : 0 : items[0] = (struct rte_flow_item){
5128 : : .type = (enum rte_flow_item_type)
5129 : : MLX5_RTE_FLOW_ITEM_TYPE_TAG,
5130 : : .spec = &tag_spec,
5131 : : };
5132 : 0 : items[1] = (struct rte_flow_item){
5133 : : .type = RTE_FLOW_ITEM_TYPE_END,
5134 : : };
5135 : 0 : actions[0] = (struct rte_flow_action){
5136 : : .type = (enum rte_flow_action_type)
5137 : : MLX5_RTE_FLOW_ACTION_TYPE_MARK,
5138 : : .conf = &ftag,
5139 : : };
5140 : 0 : actions[1] = (struct rte_flow_action){
5141 : : .type = (enum rte_flow_action_type)
5142 : : MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5143 : : .conf = &cp_mreg,
5144 : : };
5145 : 0 : actions[2] = (struct rte_flow_action){
5146 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
5147 : : .conf = &jump,
5148 : : };
5149 : 0 : actions[3] = (struct rte_flow_action){
5150 : : .type = RTE_FLOW_ACTION_TYPE_END,
5151 : : };
5152 : : } else {
5153 : : /* Default rule, wildcard match. */
5154 : 0 : attr.priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR;
5155 : 0 : items[0] = (struct rte_flow_item){
5156 : : .type = RTE_FLOW_ITEM_TYPE_END,
5157 : : };
5158 : 0 : actions[0] = (struct rte_flow_action){
5159 : : .type = (enum rte_flow_action_type)
5160 : : MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5161 : : .conf = &cp_mreg,
5162 : : };
5163 : 0 : actions[1] = (struct rte_flow_action){
5164 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
5165 : : .conf = &jump,
5166 : : };
5167 : 0 : actions[2] = (struct rte_flow_action){
5168 : : .type = RTE_FLOW_ACTION_TYPE_END,
5169 : : };
5170 : : }
5171 : : /* Build a new entry. */
5172 : 0 : mcp_res = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
5173 [ # # ]: 0 : if (!mcp_res) {
5174 : 0 : rte_errno = ENOMEM;
5175 : 0 : return NULL;
5176 : : }
5177 : 0 : mcp_res->idx = idx;
5178 : 0 : mcp_res->mark_id = mark_id;
5179 : : /*
5180 : : * The copy Flows are not included in any list. There
5181 : : * ones are referenced from other Flows and can not
5182 : : * be applied, removed, deleted in arbitrary order
5183 : : * by list traversing.
5184 : : */
5185 : 0 : mcp_res->rix_flow = mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_MCP,
5186 : : &attr, items, actions, false, error);
5187 [ # # ]: 0 : if (!mcp_res->rix_flow) {
5188 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], idx);
5189 : 0 : return NULL;
5190 : : }
5191 : 0 : return &mcp_res->hlist_ent;
5192 : : }
5193 : :
5194 : : struct mlx5_list_entry *
5195 : 0 : mlx5_flow_dv_mreg_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
5196 : : void *cb_ctx __rte_unused)
5197 : : {
5198 : : struct rte_eth_dev *dev = tool_ctx;
5199 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5200 : : struct mlx5_flow_mreg_copy_resource *mcp_res;
5201 : 0 : uint32_t idx = 0;
5202 : :
5203 : 0 : mcp_res = mlx5_ipool_malloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
5204 [ # # ]: 0 : if (!mcp_res) {
5205 : 0 : rte_errno = ENOMEM;
5206 : 0 : return NULL;
5207 : : }
5208 : : memcpy(mcp_res, oentry, sizeof(*mcp_res));
5209 : 0 : mcp_res->idx = idx;
5210 : 0 : return &mcp_res->hlist_ent;
5211 : : }
5212 : :
5213 : : void
5214 : 0 : mlx5_flow_dv_mreg_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
5215 : : {
5216 : : struct mlx5_flow_mreg_copy_resource *mcp_res =
5217 : : container_of(entry, typeof(*mcp_res), hlist_ent);
5218 : : struct rte_eth_dev *dev = tool_ctx;
5219 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5220 : :
5221 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
5222 : 0 : }
5223 : :
5224 : : /**
5225 : : * Add a flow of copying flow metadata registers in RX_CP_TBL.
5226 : : *
5227 : : * As mark_id is unique, if there's already a registered flow for the mark_id,
5228 : : * return by increasing the reference counter of the resource. Otherwise, create
5229 : : * the resource (mcp_res) and flow.
5230 : : *
5231 : : * Flow looks like,
5232 : : * - If ingress port is ANY and reg_c[1] is mark_id,
5233 : : * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
5234 : : *
5235 : : * For default flow (zero mark_id), flow is like,
5236 : : * - If ingress port is ANY,
5237 : : * reg_b := reg_c[0] and jump to RX_ACT_TBL.
5238 : : *
5239 : : * @param dev
5240 : : * Pointer to Ethernet device.
5241 : : * @param mark_id
5242 : : * ID of MARK action, zero means default flow for META.
5243 : : * @param[out] error
5244 : : * Perform verbose error reporting if not NULL.
5245 : : *
5246 : : * @return
5247 : : * Associated resource on success, NULL otherwise and rte_errno is set.
5248 : : */
5249 : : static struct mlx5_flow_mreg_copy_resource *
5250 : 0 : flow_mreg_add_copy_action(struct rte_eth_dev *dev, uint32_t mark_id,
5251 : : struct rte_flow_error *error)
5252 : : {
5253 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5254 : : struct mlx5_list_entry *entry;
5255 : 0 : struct mlx5_flow_cb_ctx ctx = {
5256 : : .dev = dev,
5257 : : .error = error,
5258 : : .data = &mark_id,
5259 : : };
5260 : :
5261 : : /* Check if already registered. */
5262 : : MLX5_ASSERT(priv->sh->mreg_cp_tbl);
5263 : 0 : entry = mlx5_hlist_register(priv->sh->mreg_cp_tbl, mark_id, &ctx);
5264 [ # # ]: 0 : if (!entry)
5265 : 0 : return NULL;
5266 : : return container_of(entry, struct mlx5_flow_mreg_copy_resource,
5267 : : hlist_ent);
5268 : : }
5269 : :
5270 : : void
5271 : 0 : mlx5_flow_dv_mreg_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
5272 : : {
5273 : : struct mlx5_flow_mreg_copy_resource *mcp_res =
5274 : : container_of(entry, typeof(*mcp_res), hlist_ent);
5275 : : struct rte_eth_dev *dev = tool_ctx;
5276 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5277 : :
5278 : : MLX5_ASSERT(mcp_res->rix_flow);
5279 : 0 : mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_MCP, mcp_res->rix_flow);
5280 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
5281 : 0 : }
5282 : :
5283 : : /**
5284 : : * Release flow in RX_CP_TBL.
5285 : : *
5286 : : * @param dev
5287 : : * Pointer to Ethernet device.
5288 : : * @flow
5289 : : * Parent flow for wich copying is provided.
5290 : : */
5291 : : static void
5292 : 0 : flow_mreg_del_copy_action(struct rte_eth_dev *dev,
5293 : : struct rte_flow *flow)
5294 : : {
5295 : : struct mlx5_flow_mreg_copy_resource *mcp_res;
5296 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5297 : :
5298 [ # # ]: 0 : if (!flow->rix_mreg_copy)
5299 : : return;
5300 : 0 : mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
5301 : : flow->rix_mreg_copy);
5302 [ # # # # ]: 0 : if (!mcp_res || !priv->sh->mreg_cp_tbl)
5303 : : return;
5304 : : MLX5_ASSERT(mcp_res->rix_flow);
5305 : 0 : mlx5_hlist_unregister(priv->sh->mreg_cp_tbl, &mcp_res->hlist_ent);
5306 : 0 : flow->rix_mreg_copy = 0;
5307 : : }
5308 : :
5309 : : /**
5310 : : * Remove the default copy action from RX_CP_TBL.
5311 : : *
5312 : : * This functions is called in the mlx5_dev_start(). No thread safe
5313 : : * is guaranteed.
5314 : : *
5315 : : * @param dev
5316 : : * Pointer to Ethernet device.
5317 : : */
5318 : : static void
5319 : 0 : flow_mreg_del_default_copy_action(struct rte_eth_dev *dev)
5320 : : {
5321 : : struct mlx5_list_entry *entry;
5322 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5323 : : struct mlx5_flow_cb_ctx ctx;
5324 : : uint32_t mark_id;
5325 : :
5326 : : /* Check if default flow is registered. */
5327 [ # # ]: 0 : if (!priv->sh->mreg_cp_tbl)
5328 : 0 : return;
5329 : 0 : mark_id = MLX5_DEFAULT_COPY_ID;
5330 : 0 : ctx.data = &mark_id;
5331 : 0 : entry = mlx5_hlist_lookup(priv->sh->mreg_cp_tbl, mark_id, &ctx);
5332 [ # # ]: 0 : if (!entry)
5333 : : return;
5334 : 0 : mlx5_hlist_unregister(priv->sh->mreg_cp_tbl, entry);
5335 : : }
5336 : :
5337 : : /**
5338 : : * Add the default copy action in RX_CP_TBL.
5339 : : *
5340 : : * This functions is called in the mlx5_dev_start(). No thread safe
5341 : : * is guaranteed.
5342 : : *
5343 : : * @param dev
5344 : : * Pointer to Ethernet device.
5345 : : * @param[out] error
5346 : : * Perform verbose error reporting if not NULL.
5347 : : *
5348 : : * @return
5349 : : * 0 for success, negative value otherwise and rte_errno is set.
5350 : : */
5351 : : static int
5352 : 0 : flow_mreg_add_default_copy_action(struct rte_eth_dev *dev,
5353 : : struct rte_flow_error *error)
5354 : : {
5355 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5356 : : struct mlx5_flow_mreg_copy_resource *mcp_res;
5357 : : struct mlx5_flow_cb_ctx ctx;
5358 : : uint32_t mark_id;
5359 : :
5360 : : /* Check whether extensive metadata feature is engaged. */
5361 [ # # ]: 0 : if (!priv->sh->config.dv_flow_en ||
5362 [ # # # # ]: 0 : priv->sh->config.dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
5363 : 0 : !mlx5_flow_ext_mreg_supported(dev) ||
5364 [ # # ]: 0 : !priv->sh->dv_regc0_mask)
5365 : 0 : return 0;
5366 : : /*
5367 : : * Add default mreg copy flow may be called multiple time, but
5368 : : * only be called once in stop. Avoid register it twice.
5369 : : */
5370 : 0 : mark_id = MLX5_DEFAULT_COPY_ID;
5371 : 0 : ctx.data = &mark_id;
5372 [ # # ]: 0 : if (mlx5_hlist_lookup(priv->sh->mreg_cp_tbl, mark_id, &ctx))
5373 : : return 0;
5374 : 0 : mcp_res = flow_mreg_add_copy_action(dev, mark_id, error);
5375 [ # # ]: 0 : if (!mcp_res)
5376 : 0 : return -rte_errno;
5377 : : return 0;
5378 : : }
5379 : :
5380 : : /**
5381 : : * Add a flow of copying flow metadata registers in RX_CP_TBL.
5382 : : *
5383 : : * All the flow having Q/RSS action should be split by
5384 : : * flow_mreg_split_qrss_prep() to pass by RX_CP_TBL. A flow in the RX_CP_TBL
5385 : : * performs the following,
5386 : : * - CQE->flow_tag := reg_c[1] (MARK)
5387 : : * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
5388 : : * As CQE's flow_tag is not a register, it can't be simply copied from reg_c[1]
5389 : : * but there should be a flow per each MARK ID set by MARK action.
5390 : : *
5391 : : * For the aforementioned reason, if there's a MARK action in flow's action
5392 : : * list, a corresponding flow should be added to the RX_CP_TBL in order to copy
5393 : : * the MARK ID to CQE's flow_tag like,
5394 : : * - If reg_c[1] is mark_id,
5395 : : * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
5396 : : *
5397 : : * For SET_META action which stores value in reg_c[0], as the destination is
5398 : : * also a flow metadata register (reg_b), adding a default flow is enough. Zero
5399 : : * MARK ID means the default flow. The default flow looks like,
5400 : : * - For all flow, reg_b := reg_c[0] and jump to RX_ACT_TBL.
5401 : : *
5402 : : * @param dev
5403 : : * Pointer to Ethernet device.
5404 : : * @param flow
5405 : : * Pointer to flow structure.
5406 : : * @param[in] actions
5407 : : * Pointer to the list of actions.
5408 : : * @param[out] error
5409 : : * Perform verbose error reporting if not NULL.
5410 : : *
5411 : : * @return
5412 : : * 0 on success, negative value otherwise and rte_errno is set.
5413 : : */
5414 : : static int
5415 : 0 : flow_mreg_update_copy_table(struct rte_eth_dev *dev,
5416 : : struct rte_flow *flow,
5417 : : const struct rte_flow_action *actions,
5418 : : struct rte_flow_error *error)
5419 : : {
5420 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5421 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
5422 : : struct mlx5_flow_mreg_copy_resource *mcp_res;
5423 : : const struct rte_flow_action_mark *mark;
5424 : :
5425 : : /* Check whether extensive metadata feature is engaged. */
5426 [ # # ]: 0 : if (!config->dv_flow_en ||
5427 [ # # # # ]: 0 : config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
5428 : 0 : !mlx5_flow_ext_mreg_supported(dev) ||
5429 [ # # ]: 0 : !priv->sh->dv_regc0_mask)
5430 : 0 : return 0;
5431 : : /* Find MARK action. */
5432 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
5433 [ # # # ]: 0 : switch (actions->type) {
5434 : 0 : case RTE_FLOW_ACTION_TYPE_FLAG:
5435 : 0 : mcp_res = flow_mreg_add_copy_action
5436 : : (dev, MLX5_FLOW_MARK_DEFAULT, error);
5437 [ # # ]: 0 : if (!mcp_res)
5438 : 0 : return -rte_errno;
5439 : 0 : flow->rix_mreg_copy = mcp_res->idx;
5440 : 0 : return 0;
5441 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
5442 : 0 : mark = (const struct rte_flow_action_mark *)
5443 : : actions->conf;
5444 : : mcp_res =
5445 : 0 : flow_mreg_add_copy_action(dev, mark->id, error);
5446 [ # # ]: 0 : if (!mcp_res)
5447 : 0 : return -rte_errno;
5448 : 0 : flow->rix_mreg_copy = mcp_res->idx;
5449 : 0 : return 0;
5450 : : default:
5451 : : break;
5452 : : }
5453 : : }
5454 : : return 0;
5455 : : }
5456 : :
5457 : : #define MLX5_MAX_SPLIT_ACTIONS 24
5458 : : #define MLX5_MAX_SPLIT_ITEMS 24
5459 : :
5460 : : /**
5461 : : * Split the hairpin flow.
5462 : : * Since HW can't support encap and push-vlan on Rx, we move these
5463 : : * actions to Tx.
5464 : : * If the count action is after the encap then we also
5465 : : * move the count action. in this case the count will also measure
5466 : : * the outer bytes.
5467 : : *
5468 : : * @param dev
5469 : : * Pointer to Ethernet device.
5470 : : * @param[in] actions
5471 : : * Associated actions (list terminated by the END action).
5472 : : * @param[out] actions_rx
5473 : : * Rx flow actions.
5474 : : * @param[out] actions_tx
5475 : : * Tx flow actions..
5476 : : * @param[out] pattern_tx
5477 : : * The pattern items for the Tx flow.
5478 : : * @param[out] flow_id
5479 : : * The flow ID connected to this flow.
5480 : : *
5481 : : * @return
5482 : : * 0 on success.
5483 : : */
5484 : : static int
5485 : 0 : flow_hairpin_split(struct rte_eth_dev *dev,
5486 : : const struct rte_flow_action actions[],
5487 : : struct rte_flow_action actions_rx[],
5488 : : struct rte_flow_action actions_tx[],
5489 : : struct rte_flow_item pattern_tx[],
5490 : : uint32_t flow_id)
5491 : : {
5492 : : const struct rte_flow_action_raw_encap *raw_encap;
5493 : : const struct rte_flow_action_raw_decap *raw_decap;
5494 : : struct mlx5_rte_flow_action_set_tag *set_tag;
5495 : : struct rte_flow_action *tag_action;
5496 : : struct mlx5_rte_flow_item_tag *tag_item;
5497 : : struct rte_flow_item *item;
5498 : : char *addr;
5499 : : int push_vlan = 0;
5500 : : int encap = 0;
5501 : :
5502 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
5503 [ # # ]: 0 : if (actions->type == RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN)
5504 : : push_vlan = 1;
5505 [ # # # # : 0 : switch (actions->type) {
# # ]
5506 : : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
5507 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
5508 : : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
5509 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
5510 : : rte_memcpy(actions_tx, actions,
5511 : : sizeof(struct rte_flow_action));
5512 : 0 : actions_tx++;
5513 : 0 : break;
5514 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
5515 [ # # ]: 0 : if (push_vlan) {
5516 : : rte_memcpy(actions_tx, actions,
5517 : : sizeof(struct rte_flow_action));
5518 : 0 : actions_tx++;
5519 : : } else {
5520 : : rte_memcpy(actions_rx, actions,
5521 : : sizeof(struct rte_flow_action));
5522 : 0 : actions_rx++;
5523 : : }
5524 : : break;
5525 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
5526 : : case RTE_FLOW_ACTION_TYPE_AGE:
5527 [ # # ]: 0 : if (encap) {
5528 : : rte_memcpy(actions_tx, actions,
5529 : : sizeof(struct rte_flow_action));
5530 : 0 : actions_tx++;
5531 : : } else {
5532 : : rte_memcpy(actions_rx, actions,
5533 : : sizeof(struct rte_flow_action));
5534 : 0 : actions_rx++;
5535 : : }
5536 : : break;
5537 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
5538 : 0 : raw_encap = actions->conf;
5539 [ # # ]: 0 : if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE) {
5540 : : memcpy(actions_tx, actions,
5541 : : sizeof(struct rte_flow_action));
5542 : 0 : actions_tx++;
5543 : : encap = 1;
5544 : : } else {
5545 : : rte_memcpy(actions_rx, actions,
5546 : : sizeof(struct rte_flow_action));
5547 : 0 : actions_rx++;
5548 : : }
5549 : : break;
5550 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
5551 : 0 : raw_decap = actions->conf;
5552 [ # # ]: 0 : if (raw_decap->size < MLX5_ENCAPSULATION_DECISION_SIZE) {
5553 : : memcpy(actions_tx, actions,
5554 : : sizeof(struct rte_flow_action));
5555 : 0 : actions_tx++;
5556 : : } else {
5557 : : rte_memcpy(actions_rx, actions,
5558 : : sizeof(struct rte_flow_action));
5559 : 0 : actions_rx++;
5560 : : }
5561 : : break;
5562 : : default:
5563 : : rte_memcpy(actions_rx, actions,
5564 : : sizeof(struct rte_flow_action));
5565 : 0 : actions_rx++;
5566 : 0 : break;
5567 : : }
5568 : : }
5569 : : /* Add set meta action and end action for the Rx flow. */
5570 : : tag_action = actions_rx;
5571 : 0 : tag_action->type = (enum rte_flow_action_type)
5572 : : MLX5_RTE_FLOW_ACTION_TYPE_TAG;
5573 : : actions_rx++;
5574 : : rte_memcpy(actions_rx, actions, sizeof(struct rte_flow_action));
5575 : 0 : actions_rx++;
5576 : : set_tag = (void *)actions_rx;
5577 : 0 : *set_tag = (struct mlx5_rte_flow_action_set_tag) {
5578 : 0 : .id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_RX, 0, NULL),
5579 : : .data = flow_id,
5580 : : };
5581 : : MLX5_ASSERT(set_tag->id > REG_NON);
5582 : 0 : tag_action->conf = set_tag;
5583 : : /* Create Tx item list. */
5584 : : rte_memcpy(actions_tx, actions, sizeof(struct rte_flow_action));
5585 : 0 : addr = (void *)&pattern_tx[2];
5586 : : item = pattern_tx;
5587 : 0 : item->type = (enum rte_flow_item_type)
5588 : : MLX5_RTE_FLOW_ITEM_TYPE_TAG;
5589 : : tag_item = (void *)addr;
5590 : 0 : tag_item->data = flow_id;
5591 : 0 : tag_item->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_TX, 0, NULL);
5592 : : MLX5_ASSERT(set_tag->id > REG_NON);
5593 : 0 : item->spec = tag_item;
5594 : 0 : addr += sizeof(struct mlx5_rte_flow_item_tag);
5595 : : tag_item = (void *)addr;
5596 : 0 : tag_item->data = UINT32_MAX;
5597 : 0 : tag_item->id = UINT16_MAX;
5598 : 0 : item->mask = tag_item;
5599 : 0 : item->last = NULL;
5600 : : item++;
5601 : 0 : item->type = RTE_FLOW_ITEM_TYPE_END;
5602 : 0 : return 0;
5603 : : }
5604 : :
5605 : : /**
5606 : : * The last stage of splitting chain, just creates the subflow
5607 : : * without any modification.
5608 : : *
5609 : : * @param[in] dev
5610 : : * Pointer to Ethernet device.
5611 : : * @param[in] flow
5612 : : * Parent flow structure pointer.
5613 : : * @param[in, out] sub_flow
5614 : : * Pointer to return the created subflow, may be NULL.
5615 : : * @param[in] attr
5616 : : * Flow rule attributes.
5617 : : * @param[in] items
5618 : : * Pattern specification (list terminated by the END pattern item).
5619 : : * @param[in] actions
5620 : : * Associated actions (list terminated by the END action).
5621 : : * @param[in] flow_split_info
5622 : : * Pointer to flow split info structure.
5623 : : * @param[out] error
5624 : : * Perform verbose error reporting if not NULL.
5625 : : * @return
5626 : : * 0 on success, negative value otherwise
5627 : : */
5628 : : static int
5629 : 0 : flow_create_split_inner(struct rte_eth_dev *dev,
5630 : : struct rte_flow *flow,
5631 : : struct mlx5_flow **sub_flow,
5632 : : const struct rte_flow_attr *attr,
5633 : : const struct rte_flow_item items[],
5634 : : const struct rte_flow_action actions[],
5635 : : struct mlx5_flow_split_info *flow_split_info,
5636 : : struct rte_flow_error *error)
5637 : : {
5638 : : struct mlx5_flow *dev_flow;
5639 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
5640 : :
5641 : 0 : dev_flow = flow_drv_prepare(dev, flow, attr, items, actions,
5642 : : flow_split_info->flow_idx, error);
5643 [ # # ]: 0 : if (!dev_flow)
5644 : 0 : return -rte_errno;
5645 : 0 : dev_flow->flow = flow;
5646 : 0 : dev_flow->external = flow_split_info->external;
5647 : 0 : dev_flow->skip_scale = flow_split_info->skip_scale;
5648 : : /* Subflow object was created, we must include one in the list. */
5649 : 0 : SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
5650 : : dev_flow->handle, next);
5651 : : /*
5652 : : * If dev_flow is as one of the suffix flow, some actions in suffix
5653 : : * flow may need some user defined item layer flags, and pass the
5654 : : * Metadata rxq mark flag to suffix flow as well.
5655 : : */
5656 [ # # ]: 0 : if (flow_split_info->prefix_layers)
5657 : 0 : dev_flow->handle->layers = flow_split_info->prefix_layers;
5658 [ # # ]: 0 : if (flow_split_info->prefix_mark) {
5659 : : MLX5_ASSERT(wks);
5660 : 0 : wks->mark = 1;
5661 : : }
5662 [ # # ]: 0 : if (sub_flow)
5663 : 0 : *sub_flow = dev_flow;
5664 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
5665 : 0 : dev_flow->dv.table_id = flow_split_info->table_id;
5666 : : #endif
5667 : 0 : return flow_drv_translate(dev, dev_flow, attr, items, actions, error);
5668 : : }
5669 : :
5670 : : /**
5671 : : * Get the sub policy of a meter.
5672 : : *
5673 : : * @param[in] dev
5674 : : * Pointer to Ethernet device.
5675 : : * @param[in] flow
5676 : : * Parent flow structure pointer.
5677 : : * @param wks
5678 : : * Pointer to thread flow work space.
5679 : : * @param[in] attr
5680 : : * Flow rule attributes.
5681 : : * @param[in] items
5682 : : * Pattern specification (list terminated by the END pattern item).
5683 : : * @param[out] error
5684 : : * Perform verbose error reporting if not NULL.
5685 : : *
5686 : : * @return
5687 : : * Pointer to the meter sub policy, NULL otherwise and rte_errno is set.
5688 : : */
5689 : : static struct mlx5_flow_meter_sub_policy *
5690 : 0 : get_meter_sub_policy(struct rte_eth_dev *dev,
5691 : : struct rte_flow *flow,
5692 : : struct mlx5_flow_workspace *wks,
5693 : : const struct rte_flow_attr *attr,
5694 : : const struct rte_flow_item items[],
5695 : : struct rte_flow_error *error)
5696 : : {
5697 : : struct mlx5_flow_meter_policy *policy;
5698 : : struct mlx5_flow_meter_policy *final_policy;
5699 : : struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
5700 : :
5701 : 0 : policy = wks->policy;
5702 [ # # ]: 0 : final_policy = policy->is_hierarchy ? wks->final_policy : policy;
5703 [ # # ]: 0 : if (final_policy->is_rss || final_policy->is_queue) {
5704 : : struct mlx5_flow_rss_desc rss_desc_v[MLX5_MTR_RTE_COLORS];
5705 : 0 : struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS] = {0};
5706 : : uint32_t i;
5707 : :
5708 : : /*
5709 : : * This is a tmp dev_flow,
5710 : : * no need to register any matcher for it in translate.
5711 : : */
5712 : 0 : wks->skip_matcher_reg = 1;
5713 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
5714 : 0 : struct mlx5_flow dev_flow = {0};
5715 : 0 : struct mlx5_flow_handle dev_handle = { {0} };
5716 : 0 : uint8_t fate = final_policy->act_cnt[i].fate_action;
5717 : :
5718 [ # # ]: 0 : if (fate == MLX5_FLOW_FATE_SHARED_RSS) {
5719 : 0 : const struct rte_flow_action_rss *rss_act =
5720 : 0 : final_policy->act_cnt[i].rss->conf;
5721 : 0 : struct rte_flow_action rss_actions[2] = {
5722 : : [0] = {
5723 : : .type = RTE_FLOW_ACTION_TYPE_RSS,
5724 : : .conf = rss_act,
5725 : : },
5726 : : [1] = {
5727 : : .type = RTE_FLOW_ACTION_TYPE_END,
5728 : : .conf = NULL,
5729 : : }
5730 : : };
5731 : :
5732 : 0 : dev_flow.handle = &dev_handle;
5733 : 0 : dev_flow.ingress = attr->ingress;
5734 : 0 : dev_flow.flow = flow;
5735 : : dev_flow.external = 0;
5736 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
5737 : 0 : dev_flow.dv.transfer = attr->transfer;
5738 : : #endif
5739 : : /**
5740 : : * Translate RSS action to get rss hash fields.
5741 : : */
5742 [ # # ]: 0 : if (flow_drv_translate(dev, &dev_flow, attr,
5743 : : items, rss_actions, error))
5744 : 0 : goto exit;
5745 : 0 : rss_desc_v[i] = wks->rss_desc;
5746 : 0 : rss_desc_v[i].symmetric_hash_function =
5747 : 0 : dev_flow.symmetric_hash_function;
5748 : 0 : rss_desc_v[i].key_len = MLX5_RSS_HASH_KEY_LEN;
5749 : 0 : rss_desc_v[i].hash_fields =
5750 : 0 : dev_flow.hash_fields;
5751 : 0 : rss_desc_v[i].queue_num =
5752 : : rss_desc_v[i].hash_fields ?
5753 [ # # ]: 0 : rss_desc_v[i].queue_num : 1;
5754 : 0 : rss_desc_v[i].tunnel =
5755 : 0 : !!(dev_flow.handle->layers &
5756 : : MLX5_FLOW_LAYER_TUNNEL);
5757 : : /* Use the RSS queues in the containers. */
5758 : 0 : rss_desc_v[i].queue =
5759 : 0 : (uint16_t *)(uintptr_t)rss_act->queue;
5760 : 0 : rss_desc[i] = &rss_desc_v[i];
5761 [ # # ]: 0 : } else if (fate == MLX5_FLOW_FATE_QUEUE) {
5762 : : /* This is queue action. */
5763 : 0 : rss_desc_v[i] = wks->rss_desc;
5764 : 0 : rss_desc_v[i].key_len = 0;
5765 : 0 : rss_desc_v[i].hash_fields = 0;
5766 : 0 : rss_desc_v[i].queue =
5767 : 0 : &final_policy->act_cnt[i].queue;
5768 : 0 : rss_desc_v[i].queue_num = 1;
5769 : 0 : rss_desc[i] = &rss_desc_v[i];
5770 : : } else {
5771 : 0 : rss_desc[i] = NULL;
5772 : : }
5773 : : }
5774 : : sub_policy = flow_drv_meter_sub_policy_rss_prepare(dev,
5775 : : flow, policy, rss_desc);
5776 : : } else {
5777 : : enum mlx5_meter_domain mtr_domain =
5778 [ # # ]: 0 : attr->transfer ? MLX5_MTR_DOMAIN_TRANSFER :
5779 : 0 : (attr->egress ? MLX5_MTR_DOMAIN_EGRESS :
5780 : : MLX5_MTR_DOMAIN_INGRESS);
5781 : 0 : sub_policy = policy->sub_policys[mtr_domain][0];
5782 : : }
5783 [ # # ]: 0 : if (!sub_policy)
5784 : 0 : rte_flow_error_set(error, EINVAL,
5785 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5786 : : "Failed to get meter sub-policy.");
5787 : 0 : exit:
5788 : 0 : return sub_policy;
5789 : : }
5790 : :
5791 : : /**
5792 : : * Split the meter flow.
5793 : : *
5794 : : * As meter flow will split to three sub flow, other than meter
5795 : : * action, the other actions make sense to only meter accepts
5796 : : * the packet. If it need to be dropped, no other additional
5797 : : * actions should be take.
5798 : : *
5799 : : * One kind of special action which decapsulates the L3 tunnel
5800 : : * header will be in the prefix sub flow, as not to take the
5801 : : * L3 tunnel header into account.
5802 : : *
5803 : : * @param[in] dev
5804 : : * Pointer to Ethernet device.
5805 : : * @param[in] flow
5806 : : * Parent flow structure pointer.
5807 : : * @param wks
5808 : : * Pointer to thread flow work space.
5809 : : * @param[in] attr
5810 : : * Flow rule attributes.
5811 : : * @param[in] items
5812 : : * Pattern specification (list terminated by the END pattern item).
5813 : : * @param[out] sfx_items
5814 : : * Suffix flow match items (list terminated by the END pattern item).
5815 : : * @param[in] actions
5816 : : * Associated actions (list terminated by the END action).
5817 : : * @param[out] actions_sfx
5818 : : * Suffix flow actions.
5819 : : * @param[out] actions_pre
5820 : : * Prefix flow actions.
5821 : : * @param[out] mtr_flow_id
5822 : : * Pointer to meter flow id.
5823 : : * @param[out] error
5824 : : * Perform verbose error reporting if not NULL.
5825 : : *
5826 : : * @return
5827 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5828 : : */
5829 : : static int
5830 : 0 : flow_meter_split_prep(struct rte_eth_dev *dev,
5831 : : struct rte_flow *flow,
5832 : : struct mlx5_flow_workspace *wks,
5833 : : const struct rte_flow_attr *attr,
5834 : : const struct rte_flow_item items[],
5835 : : struct rte_flow_item sfx_items[],
5836 : : const struct rte_flow_action actions[],
5837 : : struct rte_flow_action actions_sfx[],
5838 : : struct rte_flow_action actions_pre[],
5839 : : uint32_t *mtr_flow_id,
5840 : : struct rte_flow_error *error)
5841 : : {
5842 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5843 : 0 : struct mlx5_flow_meter_info *fm = wks->fm;
5844 : : struct rte_flow_action *tag_action = NULL;
5845 : : struct rte_flow_item *tag_item;
5846 : : struct mlx5_rte_flow_action_set_tag *set_tag;
5847 : : const struct rte_flow_action_raw_encap *raw_encap;
5848 : : const struct rte_flow_action_raw_decap *raw_decap;
5849 : : struct mlx5_rte_flow_item_tag *tag_item_spec;
5850 : : struct mlx5_rte_flow_item_tag *tag_item_mask;
5851 : 0 : uint32_t tag_id = 0;
5852 : : bool vlan_actions;
5853 : : struct rte_flow_item *orig_sfx_items = sfx_items;
5854 : : const struct rte_flow_item *orig_items = items;
5855 : : struct rte_flow_action *hw_mtr_action;
5856 : : struct rte_flow_action *action_pre_head = NULL;
5857 : 0 : uint16_t flow_src_port = priv->representor_id;
5858 : : bool mtr_first;
5859 : 0 : uint8_t mtr_id_offset = priv->mtr_reg_share ? MLX5_MTR_COLOR_BITS : 0;
5860 [ # # ]: 0 : uint8_t mtr_reg_bits = priv->mtr_reg_share ?
5861 : : MLX5_MTR_IDLE_BITS_IN_COLOR_REG : MLX5_REG_BITS;
5862 : : uint32_t flow_id = 0;
5863 : : uint32_t flow_id_reversed = 0;
5864 : : uint8_t flow_id_bits = 0;
5865 : : bool after_meter = false;
5866 : : int shift;
5867 : :
5868 : : /* Prepare the suffix subflow items. */
5869 : 0 : tag_item = sfx_items++;
5870 : 0 : tag_item->type = (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_TAG;
5871 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
5872 : : int item_type = items->type;
5873 : :
5874 [ # # # ]: 0 : switch (item_type) {
5875 : 0 : case RTE_FLOW_ITEM_TYPE_PORT_ID:
5876 : : case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
5877 : : case RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR:
5878 [ # # ]: 0 : if (mlx5_flow_get_item_vport_id(dev, items, &flow_src_port, NULL, error))
5879 : 0 : return -rte_errno;
5880 [ # # # # ]: 0 : if (!fm->def_policy && wks->policy->hierarchy_match_port &&
5881 [ # # ]: 0 : flow_src_port != priv->representor_id) {
5882 [ # # ]: 0 : if (flow_drv_mtr_hierarchy_rule_create(dev,
5883 : : flow, fm,
5884 : : flow_src_port,
5885 : : items,
5886 : : error))
5887 : 0 : return -rte_errno;
5888 : : }
5889 : : memcpy(sfx_items, items, sizeof(*sfx_items));
5890 : 0 : sfx_items++;
5891 : 0 : break;
5892 : : case RTE_FLOW_ITEM_TYPE_VLAN:
5893 : : /*
5894 : : * Copy VLAN items in case VLAN actions are performed.
5895 : : * If there are no VLAN actions, these items will be VOID.
5896 : : */
5897 : : memcpy(sfx_items, items, sizeof(*sfx_items));
5898 : 0 : sfx_items->type = (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_VLAN;
5899 : 0 : sfx_items++;
5900 : 0 : break;
5901 : : default:
5902 : : break;
5903 : : }
5904 : : }
5905 : 0 : sfx_items->type = RTE_FLOW_ITEM_TYPE_END;
5906 : 0 : sfx_items++;
5907 [ # # ]: 0 : mtr_first = priv->sh->meter_aso_en &&
5908 [ # # # # : 0 : (attr->egress || (attr->transfer && flow_src_port != UINT16_MAX));
# # ]
5909 : : /* For ASO meter, meter must be before tag in TX direction. */
5910 [ # # ]: 0 : if (mtr_first) {
5911 : 0 : action_pre_head = actions_pre++;
5912 : : /* Leave space for tag action. */
5913 : 0 : tag_action = actions_pre++;
5914 : : }
5915 : : /* Prepare the actions for prefix and suffix flow. */
5916 : : vlan_actions = false;
5917 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
5918 : : struct rte_flow_action *action_cur = NULL;
5919 : :
5920 [ # # # # : 0 : switch (actions->type) {
# # # ]
5921 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
5922 [ # # ]: 0 : if (mtr_first) {
5923 : : action_cur = action_pre_head;
5924 : : } else {
5925 : : /* Leave space for tag action. */
5926 : 0 : tag_action = actions_pre++;
5927 : 0 : action_cur = actions_pre++;
5928 : : }
5929 : : after_meter = true;
5930 : : break;
5931 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
5932 : : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
5933 : 0 : action_cur = actions_pre++;
5934 : 0 : break;
5935 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
5936 : 0 : raw_encap = actions->conf;
5937 [ # # ]: 0 : if (raw_encap->size < MLX5_ENCAPSULATION_DECISION_SIZE)
5938 : 0 : action_cur = actions_pre++;
5939 : : break;
5940 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
5941 : 0 : raw_decap = actions->conf;
5942 [ # # ]: 0 : if (raw_decap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
5943 : 0 : action_cur = actions_pre++;
5944 : : break;
5945 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
5946 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
5947 : : vlan_actions = true;
5948 : 0 : break;
5949 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
5950 [ # # ]: 0 : if (fm->def_policy)
5951 : : action_cur = after_meter ?
5952 [ # # ]: 0 : actions_sfx++ : actions_pre++;
5953 : : break;
5954 : : default:
5955 : : break;
5956 : : }
5957 [ # # ]: 0 : if (!action_cur)
5958 : 0 : action_cur = (fm->def_policy) ?
5959 [ # # ]: 0 : actions_sfx++ : actions_pre++;
5960 : : memcpy(action_cur, actions, sizeof(struct rte_flow_action));
5961 : : }
5962 : : /* If there are no VLAN actions, convert VLAN items to VOID in suffix flow items. */
5963 [ # # ]: 0 : if (!vlan_actions) {
5964 : : struct rte_flow_item *it = orig_sfx_items;
5965 : :
5966 [ # # ]: 0 : for (; it->type != RTE_FLOW_ITEM_TYPE_END; it++)
5967 [ # # ]: 0 : if (it->type == (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_VLAN)
5968 : 0 : it->type = RTE_FLOW_ITEM_TYPE_VOID;
5969 : : }
5970 : : /* Add end action to the actions. */
5971 : 0 : actions_sfx->type = RTE_FLOW_ACTION_TYPE_END;
5972 [ # # ]: 0 : if (priv->sh->meter_aso_en) {
5973 : : /**
5974 : : * For ASO meter, need to add an extra jump action explicitly,
5975 : : * to jump from meter to policer table.
5976 : : */
5977 : : struct mlx5_flow_meter_sub_policy *sub_policy;
5978 : : struct mlx5_flow_tbl_data_entry *tbl_data;
5979 : :
5980 [ # # ]: 0 : if (!fm->def_policy) {
5981 : 0 : sub_policy = get_meter_sub_policy(dev, flow, wks,
5982 : : attr, orig_items,
5983 : : error);
5984 [ # # ]: 0 : if (!sub_policy)
5985 : 0 : return -rte_errno;
5986 : : } else {
5987 : : enum mlx5_meter_domain mtr_domain =
5988 [ # # ]: 0 : attr->transfer ? MLX5_MTR_DOMAIN_TRANSFER :
5989 : 0 : (attr->egress ? MLX5_MTR_DOMAIN_EGRESS :
5990 : : MLX5_MTR_DOMAIN_INGRESS);
5991 : :
5992 : 0 : sub_policy =
5993 : 0 : &priv->sh->mtrmng->def_policy[mtr_domain]->sub_policy;
5994 : : }
5995 : 0 : tbl_data = container_of(sub_policy->tbl_rsc,
5996 : : struct mlx5_flow_tbl_data_entry, tbl);
5997 : 0 : hw_mtr_action = actions_pre++;
5998 : 0 : hw_mtr_action->type = (enum rte_flow_action_type)
5999 : : MLX5_RTE_FLOW_ACTION_TYPE_JUMP;
6000 : 0 : hw_mtr_action->conf = tbl_data->jump.action;
6001 : : }
6002 : 0 : actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
6003 : 0 : actions_pre++;
6004 [ # # ]: 0 : if (!tag_action)
6005 : 0 : return rte_flow_error_set(error, ENOMEM,
6006 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6007 : : NULL, "No tag action space.");
6008 [ # # ]: 0 : if (!mtr_flow_id) {
6009 : 0 : tag_action->type = RTE_FLOW_ACTION_TYPE_VOID;
6010 : 0 : goto exit;
6011 : : }
6012 : : /* Only default-policy Meter creates mtr flow id. */
6013 [ # # ]: 0 : if (fm->def_policy) {
6014 : 0 : mlx5_ipool_malloc(fm->flow_ipool, &tag_id);
6015 [ # # ]: 0 : if (!tag_id)
6016 : 0 : return rte_flow_error_set(error, ENOMEM,
6017 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6018 : : "Failed to allocate meter flow id.");
6019 : 0 : flow_id = tag_id - 1;
6020 [ # # ]: 0 : flow_id_bits = (!flow_id) ? 1 :
6021 : 0 : (MLX5_REG_BITS - rte_clz32(flow_id));
6022 [ # # ]: 0 : if ((flow_id_bits + priv->sh->mtrmng->max_mtr_bits) >
6023 : : mtr_reg_bits) {
6024 : 0 : mlx5_ipool_free(fm->flow_ipool, tag_id);
6025 : 0 : return rte_flow_error_set(error, EINVAL,
6026 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6027 : : "Meter flow id exceeds max limit.");
6028 : : }
6029 [ # # ]: 0 : if (flow_id_bits > priv->sh->mtrmng->max_mtr_flow_bits)
6030 : 0 : priv->sh->mtrmng->max_mtr_flow_bits = flow_id_bits;
6031 : : }
6032 : : /* Build tag actions and items for meter_id/meter flow_id. */
6033 : : set_tag = (struct mlx5_rte_flow_action_set_tag *)actions_pre;
6034 : : tag_item_spec = (struct mlx5_rte_flow_item_tag *)sfx_items;
6035 : 0 : tag_item_mask = tag_item_spec + 1;
6036 : : /* Both flow_id and meter_id share the same register. */
6037 : 0 : *set_tag = (struct mlx5_rte_flow_action_set_tag) {
6038 : 0 : .id = (enum modify_reg)mlx5_flow_get_reg_id(dev, MLX5_MTR_ID,
6039 : : 0, error),
6040 : : .offset = mtr_id_offset,
6041 : : .length = mtr_reg_bits,
6042 : 0 : .data = flow->meter,
6043 : : };
6044 : : /*
6045 : : * The color Reg bits used by flow_id are growing from
6046 : : * msb to lsb, so must do bit reverse for flow_id val in RegC.
6047 : : */
6048 [ # # ]: 0 : for (shift = 0; shift < flow_id_bits; shift++)
6049 : 0 : flow_id_reversed = (flow_id_reversed << 1) |
6050 : 0 : ((flow_id >> shift) & 0x1);
6051 : 0 : set_tag->data |=
6052 : 0 : flow_id_reversed << (mtr_reg_bits - flow_id_bits);
6053 : 0 : tag_item_spec->id = set_tag->id;
6054 : 0 : tag_item_spec->data = set_tag->data << mtr_id_offset;
6055 : 0 : tag_item_mask->data = UINT32_MAX << mtr_id_offset;
6056 : 0 : tag_action->type = (enum rte_flow_action_type)
6057 : : MLX5_RTE_FLOW_ACTION_TYPE_TAG;
6058 : 0 : tag_action->conf = set_tag;
6059 : 0 : tag_item->spec = tag_item_spec;
6060 : 0 : tag_item->last = NULL;
6061 : 0 : tag_item->mask = tag_item_mask;
6062 : 0 : exit:
6063 [ # # ]: 0 : if (mtr_flow_id)
6064 : 0 : *mtr_flow_id = tag_id;
6065 : : return 0;
6066 : : }
6067 : :
6068 : : /**
6069 : : * Split action list having QUEUE/RSS for metadata register copy.
6070 : : *
6071 : : * Once Q/RSS action is detected in user's action list, the flow action
6072 : : * should be split in order to copy metadata registers, which will happen in
6073 : : * RX_CP_TBL like,
6074 : : * - CQE->flow_tag := reg_c[1] (MARK)
6075 : : * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
6076 : : * The Q/RSS action will be performed on RX_ACT_TBL after passing by RX_CP_TBL.
6077 : : * This is because the last action of each flow must be a terminal action
6078 : : * (QUEUE, RSS or DROP).
6079 : : *
6080 : : * Flow ID must be allocated to identify actions in the RX_ACT_TBL and it is
6081 : : * stored and kept in the mlx5_flow structure per each sub_flow.
6082 : : *
6083 : : * The Q/RSS action is replaced with,
6084 : : * - SET_TAG, setting the allocated flow ID to reg_c[2].
6085 : : * And the following JUMP action is added at the end,
6086 : : * - JUMP, to RX_CP_TBL.
6087 : : *
6088 : : * A flow to perform remained Q/RSS action will be created in RX_ACT_TBL by
6089 : : * flow_create_split_metadata() routine. The flow will look like,
6090 : : * - If flow ID matches (reg_c[2]), perform Q/RSS.
6091 : : *
6092 : : * @param dev
6093 : : * Pointer to Ethernet device.
6094 : : * @param[out] split_actions
6095 : : * Pointer to store split actions to jump to CP_TBL.
6096 : : * @param[in] actions
6097 : : * Pointer to the list of original flow actions.
6098 : : * @param[in] qrss
6099 : : * Pointer to the Q/RSS action.
6100 : : * @param[in] actions_n
6101 : : * Number of original actions.
6102 : : * @param[in] mtr_sfx
6103 : : * Check if it is in meter suffix table.
6104 : : * @param[out] error
6105 : : * Perform verbose error reporting if not NULL.
6106 : : *
6107 : : * @return
6108 : : * non-zero unique flow_id on success, otherwise 0 and
6109 : : * error/rte_error are set.
6110 : : */
6111 : : static uint32_t
6112 : 0 : flow_mreg_split_qrss_prep(struct rte_eth_dev *dev,
6113 : : struct rte_flow_action *split_actions,
6114 : : const struct rte_flow_action *actions,
6115 : : const struct rte_flow_action *qrss,
6116 : : int actions_n, int mtr_sfx,
6117 : : struct rte_flow_error *error)
6118 : : {
6119 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6120 : : struct mlx5_rte_flow_action_set_tag *set_tag;
6121 : : struct rte_flow_action_jump *jump;
6122 : 0 : const int qrss_idx = qrss - actions;
6123 : 0 : uint32_t flow_id = 0;
6124 : : int ret = 0;
6125 : :
6126 : : /*
6127 : : * Given actions will be split
6128 : : * - Replace QUEUE/RSS action with SET_TAG to set flow ID.
6129 : : * - Add jump to mreg CP_TBL.
6130 : : * As a result, there will be one more action.
6131 : : */
6132 [ # # ]: 0 : memcpy(split_actions, actions, sizeof(*split_actions) * actions_n);
6133 : : /* Count MLX5_RTE_FLOW_ACTION_TYPE_TAG. */
6134 : 0 : ++actions_n;
6135 : 0 : set_tag = (void *)(split_actions + actions_n);
6136 : : /*
6137 : : * If we are not the meter suffix flow, add the tag action.
6138 : : * Since meter suffix flow already has the tag added.
6139 : : */
6140 [ # # ]: 0 : if (!mtr_sfx) {
6141 : : /*
6142 : : * Allocate the new subflow ID. This one is unique within
6143 : : * device and not shared with representors. Otherwise,
6144 : : * we would have to resolve multi-thread access synch
6145 : : * issue. Each flow on the shared device is appended
6146 : : * with source vport identifier, so the resulting
6147 : : * flows will be unique in the shared (by master and
6148 : : * representors) domain even if they have coinciding
6149 : : * IDs.
6150 : : */
6151 : 0 : mlx5_ipool_malloc(priv->sh->ipool
6152 : : [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &flow_id);
6153 [ # # ]: 0 : if (!flow_id)
6154 : 0 : return rte_flow_error_set(error, ENOMEM,
6155 : : RTE_FLOW_ERROR_TYPE_ACTION,
6156 : : NULL, "can't allocate id "
6157 : : "for split Q/RSS subflow");
6158 : : /* Internal SET_TAG action to set flow ID. */
6159 : 0 : *set_tag = (struct mlx5_rte_flow_action_set_tag){
6160 : : .data = flow_id,
6161 : : };
6162 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0, error);
6163 [ # # ]: 0 : if (ret < 0)
6164 : 0 : return ret;
6165 : 0 : set_tag->id = ret;
6166 : : /* Construct new actions array. */
6167 : : /* Replace QUEUE/RSS action. */
6168 : 0 : split_actions[qrss_idx] = (struct rte_flow_action){
6169 : : .type = (enum rte_flow_action_type)
6170 : : MLX5_RTE_FLOW_ACTION_TYPE_TAG,
6171 : : .conf = set_tag,
6172 : : };
6173 : : } else {
6174 : : /*
6175 : : * If we are the suffix flow of meter, tag already exist.
6176 : : * Set the QUEUE/RSS action to void.
6177 : : */
6178 : 0 : split_actions[qrss_idx].type = RTE_FLOW_ACTION_TYPE_VOID;
6179 : : }
6180 : : /* JUMP action to jump to mreg copy table (CP_TBL). */
6181 : 0 : jump = (void *)(set_tag + 1);
6182 : 0 : *jump = (struct rte_flow_action_jump){
6183 : : .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
6184 : : };
6185 : 0 : split_actions[actions_n - 2] = (struct rte_flow_action){
6186 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
6187 : : .conf = jump,
6188 : : };
6189 : 0 : split_actions[actions_n - 1] = (struct rte_flow_action){
6190 : : .type = RTE_FLOW_ACTION_TYPE_END,
6191 : : };
6192 : 0 : return flow_id;
6193 : : }
6194 : :
6195 : : /**
6196 : : * Extend the given action list for Tx metadata copy.
6197 : : *
6198 : : * Copy the given action list to the ext_actions and add flow metadata register
6199 : : * copy action in order to copy reg_a set by WQE to reg_c[0].
6200 : : *
6201 : : * @param[out] ext_actions
6202 : : * Pointer to the extended action list.
6203 : : * @param[in] actions
6204 : : * Pointer to the list of actions.
6205 : : * @param[in] actions_n
6206 : : * Number of actions in the list.
6207 : : * @param[out] error
6208 : : * Perform verbose error reporting if not NULL.
6209 : : * @param[in] encap_idx
6210 : : * The encap action index.
6211 : : *
6212 : : * @return
6213 : : * 0 on success, negative value otherwise
6214 : : */
6215 : : static int
6216 : 0 : flow_mreg_tx_copy_prep(struct rte_eth_dev *dev,
6217 : : struct rte_flow_action *ext_actions,
6218 : : const struct rte_flow_action *actions,
6219 : : int actions_n, struct rte_flow_error *error,
6220 : : int encap_idx)
6221 : : {
6222 : 0 : struct mlx5_flow_action_copy_mreg *cp_mreg =
6223 : : (struct mlx5_flow_action_copy_mreg *)
6224 : 0 : (ext_actions + actions_n + 1);
6225 : : int ret;
6226 : :
6227 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
6228 [ # # ]: 0 : if (ret < 0)
6229 : : return ret;
6230 : 0 : cp_mreg->dst = ret;
6231 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_TX, 0, error);
6232 [ # # ]: 0 : if (ret < 0)
6233 : : return ret;
6234 : 0 : cp_mreg->src = ret;
6235 [ # # ]: 0 : if (encap_idx != 0)
6236 : 0 : memcpy(ext_actions, actions, sizeof(*ext_actions) * encap_idx);
6237 [ # # ]: 0 : if (encap_idx == actions_n - 1) {
6238 : 0 : ext_actions[actions_n - 1] = (struct rte_flow_action){
6239 : : .type = (enum rte_flow_action_type)
6240 : : MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
6241 : : .conf = cp_mreg,
6242 : : };
6243 : 0 : ext_actions[actions_n] = (struct rte_flow_action){
6244 : : .type = RTE_FLOW_ACTION_TYPE_END,
6245 : : };
6246 : : } else {
6247 : 0 : ext_actions[encap_idx] = (struct rte_flow_action){
6248 : : .type = (enum rte_flow_action_type)
6249 : : MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
6250 : : .conf = cp_mreg,
6251 : : };
6252 : 0 : memcpy(ext_actions + encap_idx + 1, actions + encap_idx,
6253 : 0 : sizeof(*ext_actions) * (actions_n - encap_idx));
6254 : : }
6255 : : return 0;
6256 : : }
6257 : :
6258 : : /**
6259 : : * Check the match action from the action list.
6260 : : *
6261 : : * @param[in] actions
6262 : : * Pointer to the list of actions.
6263 : : * @param[in] attr
6264 : : * Flow rule attributes.
6265 : : * @param[in] action
6266 : : * The action to be check if exist.
6267 : : * @param[out] match_action_pos
6268 : : * Pointer to the position of the matched action if exists, otherwise is -1.
6269 : : * @param[out] qrss_action_pos
6270 : : * Pointer to the position of the Queue/RSS action if exists, otherwise is -1.
6271 : : * @param[out] modify_after_mirror
6272 : : * Pointer to the flag of modify action after FDB mirroring.
6273 : : *
6274 : : * @return
6275 : : * > 0 the total number of actions.
6276 : : * 0 if not found match action in action list.
6277 : : */
6278 : : static int
6279 : 0 : flow_check_match_action(const struct rte_flow_action actions[],
6280 : : const struct rte_flow_attr *attr,
6281 : : enum rte_flow_action_type action,
6282 : : int *match_action_pos, int *qrss_action_pos,
6283 : : int *modify_after_mirror)
6284 : : {
6285 : : const struct rte_flow_action_sample *sample;
6286 : : const struct rte_flow_action_raw_decap *decap;
6287 : : const struct rte_flow_action *action_cur = NULL;
6288 : : int actions_n = 0;
6289 : : uint32_t ratio = 0;
6290 : : int sub_type = 0;
6291 : : int flag = 0;
6292 : : int fdb_mirror = 0;
6293 : :
6294 : 0 : *match_action_pos = -1;
6295 : 0 : *qrss_action_pos = -1;
6296 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
6297 [ # # ]: 0 : if (actions->type == action) {
6298 : : flag = 1;
6299 : 0 : *match_action_pos = actions_n;
6300 : : }
6301 [ # # # # : 0 : switch (actions->type) {
# ]
6302 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
6303 : : case RTE_FLOW_ACTION_TYPE_RSS:
6304 : 0 : *qrss_action_pos = actions_n;
6305 : 0 : break;
6306 : 0 : case RTE_FLOW_ACTION_TYPE_SAMPLE:
6307 : 0 : sample = actions->conf;
6308 : 0 : ratio = sample->ratio;
6309 : 0 : sub_type = ((const struct rte_flow_action *)
6310 : 0 : (sample->actions))->type;
6311 [ # # # # : 0 : if (ratio == 1 && attr->transfer &&
# # ]
6312 : : sub_type != RTE_FLOW_ACTION_TYPE_END)
6313 : : fdb_mirror = 1;
6314 : : break;
6315 : 0 : case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
6316 : : case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
6317 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
6318 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
6319 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
6320 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
6321 : : case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
6322 : : case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
6323 : : case RTE_FLOW_ACTION_TYPE_DEC_TTL:
6324 : : case RTE_FLOW_ACTION_TYPE_SET_TTL:
6325 : : case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
6326 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
6327 : : case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
6328 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
6329 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
6330 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
6331 : : case RTE_FLOW_ACTION_TYPE_FLAG:
6332 : : case RTE_FLOW_ACTION_TYPE_MARK:
6333 : : case RTE_FLOW_ACTION_TYPE_SET_META:
6334 : : case RTE_FLOW_ACTION_TYPE_SET_TAG:
6335 : : case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
6336 : : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
6337 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
6338 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
6339 : : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
6340 : : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
6341 : : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
6342 : : case RTE_FLOW_ACTION_TYPE_METER:
6343 [ # # ]: 0 : if (fdb_mirror)
6344 : 0 : *modify_after_mirror = 1;
6345 : : break;
6346 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
6347 : 0 : decap = actions->conf;
6348 : : action_cur = actions;
6349 [ # # ]: 0 : while ((++action_cur)->type == RTE_FLOW_ACTION_TYPE_VOID)
6350 : : ;
6351 [ # # ]: 0 : if (action_cur->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
6352 : 0 : const struct rte_flow_action_raw_encap *encap =
6353 : : action_cur->conf;
6354 [ # # ]: 0 : if (decap->size <=
6355 : 0 : MLX5_ENCAPSULATION_DECISION_SIZE &&
6356 [ # # ]: 0 : encap->size >
6357 : : MLX5_ENCAPSULATION_DECISION_SIZE)
6358 : : /* L3 encap. */
6359 : : break;
6360 : : }
6361 [ # # ]: 0 : if (fdb_mirror)
6362 : 0 : *modify_after_mirror = 1;
6363 : : break;
6364 : : default:
6365 : : break;
6366 : : }
6367 : 0 : actions_n++;
6368 : : }
6369 [ # # # # ]: 0 : if (flag && fdb_mirror && !*modify_after_mirror) {
6370 : : /* FDB mirroring uses the destination array to implement
6371 : : * instead of FLOW_SAMPLER object.
6372 : : */
6373 [ # # ]: 0 : if (sub_type != RTE_FLOW_ACTION_TYPE_END)
6374 : : flag = 0;
6375 : : }
6376 : : /* Count RTE_FLOW_ACTION_TYPE_END. */
6377 [ # # ]: 0 : return flag ? actions_n + 1 : 0;
6378 : : }
6379 : :
6380 : : #define SAMPLE_SUFFIX_ITEM 3
6381 : :
6382 : : /**
6383 : : * Split the sample flow.
6384 : : *
6385 : : * As sample flow will split to two sub flow, sample flow with
6386 : : * sample action, the other actions will move to new suffix flow.
6387 : : *
6388 : : * Also add unique tag id with tag action in the sample flow,
6389 : : * the same tag id will be as match in the suffix flow.
6390 : : *
6391 : : * @param dev
6392 : : * Pointer to Ethernet device.
6393 : : * @param[in] add_tag
6394 : : * Add extra tag action flag.
6395 : : * @param[out] sfx_items
6396 : : * Suffix flow match items (list terminated by the END pattern item).
6397 : : * @param[in] actions
6398 : : * Associated actions (list terminated by the END action).
6399 : : * @param[out] actions_sfx
6400 : : * Suffix flow actions.
6401 : : * @param[out] actions_pre
6402 : : * Prefix flow actions.
6403 : : * @param[in] actions_n
6404 : : * The total number of actions.
6405 : : * @param[in] sample_action_pos
6406 : : * The sample action position.
6407 : : * @param[in] qrss_action_pos
6408 : : * The Queue/RSS action position.
6409 : : * @param[in] jump_table
6410 : : * Add extra jump action flag.
6411 : : * @param[out] error
6412 : : * Perform verbose error reporting if not NULL.
6413 : : *
6414 : : * @return
6415 : : * 0 on success, or unique flow_id, a negative errno value
6416 : : * otherwise and rte_errno is set.
6417 : : */
6418 : : static int
6419 : 0 : flow_sample_split_prep(struct rte_eth_dev *dev,
6420 : : int add_tag,
6421 : : const struct rte_flow_item items[],
6422 : : struct rte_flow_item sfx_items[],
6423 : : const struct rte_flow_action actions[],
6424 : : struct rte_flow_action actions_sfx[],
6425 : : struct rte_flow_action actions_pre[],
6426 : : int actions_n,
6427 : : int sample_action_pos,
6428 : : int qrss_action_pos,
6429 : : int jump_table,
6430 : : struct rte_flow_error *error)
6431 : : {
6432 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6433 : : struct mlx5_rte_flow_action_set_tag *set_tag;
6434 : : struct mlx5_rte_flow_item_tag *tag_spec;
6435 : : struct mlx5_rte_flow_item_tag *tag_mask;
6436 : : struct rte_flow_action_jump *jump_action;
6437 : 0 : uint32_t tag_id = 0;
6438 : : int append_index = 0;
6439 : : int set_tag_idx = -1;
6440 : : int index;
6441 : : int ret;
6442 : :
6443 [ # # ]: 0 : if (sample_action_pos < 0)
6444 : 0 : return rte_flow_error_set(error, EINVAL,
6445 : : RTE_FLOW_ERROR_TYPE_ACTION,
6446 : : NULL, "invalid position of sample "
6447 : : "action in list");
6448 : : /* Prepare the actions for prefix and suffix flow. */
6449 [ # # ]: 0 : if (add_tag) {
6450 : : /* Update the new added tag action index preceding
6451 : : * the PUSH_VLAN or ENCAP action.
6452 : : */
6453 : : const struct rte_flow_action_raw_encap *raw_encap;
6454 : : const struct rte_flow_action *action = actions;
6455 : : int encap_idx;
6456 : : int action_idx = 0;
6457 : : int raw_decap_idx = -1;
6458 : : int push_vlan_idx = -1;
6459 [ # # ]: 0 : for (; action->type != RTE_FLOW_ACTION_TYPE_END; action++) {
6460 [ # # # # : 0 : switch (action->type) {
# ]
6461 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
6462 : : raw_decap_idx = action_idx;
6463 : 0 : break;
6464 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
6465 : 0 : raw_encap = action->conf;
6466 [ # # ]: 0 : if (raw_encap->size >
6467 : : MLX5_ENCAPSULATION_DECISION_SIZE) {
6468 : : encap_idx = raw_decap_idx != -1 ?
6469 [ # # ]: 0 : raw_decap_idx : action_idx;
6470 : 0 : if (encap_idx < sample_action_pos &&
6471 [ # # ]: 0 : push_vlan_idx == -1)
6472 : : set_tag_idx = encap_idx;
6473 : : }
6474 : : break;
6475 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
6476 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
6477 : : encap_idx = action_idx;
6478 : 0 : if (encap_idx < sample_action_pos &&
6479 [ # # ]: 0 : push_vlan_idx == -1)
6480 : : set_tag_idx = encap_idx;
6481 : : break;
6482 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
6483 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
6484 : 0 : if (action_idx < sample_action_pos &&
6485 [ # # ]: 0 : push_vlan_idx == -1) {
6486 : : set_tag_idx = action_idx;
6487 : : push_vlan_idx = action_idx;
6488 : : }
6489 : : break;
6490 : : default:
6491 : : break;
6492 : : }
6493 : 0 : action_idx++;
6494 : : }
6495 : : }
6496 : : /* Prepare the actions for prefix and suffix flow. */
6497 [ # # ]: 0 : if (qrss_action_pos >= 0 && qrss_action_pos < sample_action_pos) {
6498 : : index = qrss_action_pos;
6499 : : /* Put the preceding the Queue/RSS action into prefix flow. */
6500 [ # # ]: 0 : if (index != 0)
6501 : 0 : memcpy(actions_pre, actions,
6502 : : sizeof(struct rte_flow_action) * index);
6503 : : /* Put others preceding the sample action into prefix flow. */
6504 [ # # ]: 0 : if (sample_action_pos > index + 1)
6505 : 0 : memcpy(actions_pre + index, actions + index + 1,
6506 : : sizeof(struct rte_flow_action) *
6507 : 0 : (sample_action_pos - index - 1));
6508 : 0 : index = sample_action_pos - 1;
6509 : : /* Put Queue/RSS action into Suffix flow. */
6510 : 0 : memcpy(actions_sfx, actions + qrss_action_pos,
6511 : : sizeof(struct rte_flow_action));
6512 : 0 : actions_sfx++;
6513 [ # # ]: 0 : } else if (add_tag && set_tag_idx >= 0) {
6514 [ # # ]: 0 : if (set_tag_idx > 0)
6515 : 0 : memcpy(actions_pre, actions,
6516 : : sizeof(struct rte_flow_action) * set_tag_idx);
6517 : 0 : memcpy(actions_pre + set_tag_idx + 1, actions + set_tag_idx,
6518 : : sizeof(struct rte_flow_action) *
6519 : 0 : (sample_action_pos - set_tag_idx));
6520 : : index = sample_action_pos;
6521 : : } else {
6522 : : index = sample_action_pos;
6523 [ # # ]: 0 : if (index != 0)
6524 : 0 : memcpy(actions_pre, actions,
6525 : : sizeof(struct rte_flow_action) * index);
6526 : : }
6527 : : /* For CX5, add an extra tag action for NIC-RX and E-Switch ingress.
6528 : : * For CX6DX and above, metadata registers Cx preserve their value,
6529 : : * add an extra tag action for NIC-RX and E-Switch Domain.
6530 : : */
6531 [ # # ]: 0 : if (add_tag) {
6532 : : /* Prepare the prefix tag action. */
6533 : : append_index++;
6534 : 0 : set_tag = (void *)(actions_pre + actions_n + append_index);
6535 : : /* Trust VF/SF on CX5 not supported meter so that the reserved
6536 : : * metadata regC is REG_NON, back to use application tag
6537 : : * index 0.
6538 : : */
6539 [ # # ]: 0 : if (unlikely(priv->sh->registers.aso_reg == REG_NON))
6540 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, 0, error);
6541 : : else
6542 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_SAMPLE_ID, 0, error);
6543 [ # # ]: 0 : if (ret < 0)
6544 : : return ret;
6545 : 0 : mlx5_ipool_malloc(priv->sh->ipool
6546 : : [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &tag_id);
6547 : 0 : *set_tag = (struct mlx5_rte_flow_action_set_tag) {
6548 : : .id = ret,
6549 : : .data = tag_id,
6550 : : };
6551 : : /* Prepare the suffix subflow items. */
6552 : 0 : tag_spec = (void *)(sfx_items + SAMPLE_SUFFIX_ITEM);
6553 : 0 : tag_spec->data = tag_id;
6554 : 0 : tag_spec->id = set_tag->id;
6555 : 0 : tag_mask = tag_spec + 1;
6556 : 0 : tag_mask->data = UINT32_MAX;
6557 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
6558 [ # # ]: 0 : if (items->type == RTE_FLOW_ITEM_TYPE_PORT_ID ||
6559 : : items->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR ||
6560 : : items->type == RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT) {
6561 : : memcpy(sfx_items, items, sizeof(*sfx_items));
6562 : 0 : sfx_items++;
6563 : 0 : break;
6564 : : }
6565 : : }
6566 : 0 : sfx_items[0] = (struct rte_flow_item){
6567 : : .type = (enum rte_flow_item_type)
6568 : : MLX5_RTE_FLOW_ITEM_TYPE_TAG,
6569 : : .spec = tag_spec,
6570 : : .last = NULL,
6571 : : .mask = tag_mask,
6572 : : };
6573 : 0 : sfx_items[1] = (struct rte_flow_item){
6574 : : .type = (enum rte_flow_item_type)
6575 : : RTE_FLOW_ITEM_TYPE_END,
6576 : : };
6577 : : /* Prepare the tag action in prefix subflow. */
6578 [ # # ]: 0 : set_tag_idx = (set_tag_idx == -1) ? index : set_tag_idx;
6579 : 0 : actions_pre[set_tag_idx] =
6580 : : (struct rte_flow_action){
6581 : : .type = (enum rte_flow_action_type)
6582 : : MLX5_RTE_FLOW_ACTION_TYPE_TAG,
6583 : : .conf = set_tag,
6584 : : };
6585 : : /* Update next sample position due to add one tag action */
6586 : 0 : index += 1;
6587 : : }
6588 : : /* Copy the sample action into prefix flow. */
6589 [ # # ]: 0 : memcpy(actions_pre + index, actions + sample_action_pos,
6590 : : sizeof(struct rte_flow_action));
6591 : 0 : index += 1;
6592 : : /* For the modify action after the sample action in E-Switch mirroring,
6593 : : * Add the extra jump action in prefix subflow and jump into the next
6594 : : * table, then do the modify action in the new table.
6595 : : */
6596 [ # # ]: 0 : if (jump_table) {
6597 : : /* Prepare the prefix jump action. */
6598 : 0 : append_index++;
6599 : 0 : jump_action = (void *)(actions_pre + actions_n + append_index);
6600 : 0 : jump_action->group = jump_table;
6601 : 0 : actions_pre[index++] =
6602 : : (struct rte_flow_action){
6603 : : .type = (enum rte_flow_action_type)
6604 : : RTE_FLOW_ACTION_TYPE_JUMP,
6605 : : .conf = jump_action,
6606 : : };
6607 : : }
6608 : 0 : actions_pre[index] = (struct rte_flow_action){
6609 : : .type = (enum rte_flow_action_type)
6610 : : RTE_FLOW_ACTION_TYPE_END,
6611 : : };
6612 : : /* Put the actions after sample into Suffix flow. */
6613 : 0 : memcpy(actions_sfx, actions + sample_action_pos + 1,
6614 : : sizeof(struct rte_flow_action) *
6615 : 0 : (actions_n - sample_action_pos - 1));
6616 : 0 : return tag_id;
6617 : : }
6618 : :
6619 : : /**
6620 : : * The splitting for metadata feature.
6621 : : *
6622 : : * - Q/RSS action on NIC Rx should be split in order to pass by
6623 : : * the mreg copy table (RX_CP_TBL) and then it jumps to the
6624 : : * action table (RX_ACT_TBL) which has the split Q/RSS action.
6625 : : *
6626 : : * - All the actions on NIC Tx should have a mreg copy action to
6627 : : * copy reg_a from WQE to reg_c[0].
6628 : : *
6629 : : * @param dev
6630 : : * Pointer to Ethernet device.
6631 : : * @param[in] flow
6632 : : * Parent flow structure pointer.
6633 : : * @param[in] attr
6634 : : * Flow rule attributes.
6635 : : * @param[in] items
6636 : : * Pattern specification (list terminated by the END pattern item).
6637 : : * @param[in] actions
6638 : : * Associated actions (list terminated by the END action).
6639 : : * @param[in] flow_split_info
6640 : : * Pointer to flow split info structure.
6641 : : * @param[out] error
6642 : : * Perform verbose error reporting if not NULL.
6643 : : * @return
6644 : : * 0 on success, negative value otherwise
6645 : : */
6646 : : static int
6647 : 0 : flow_create_split_metadata(struct rte_eth_dev *dev,
6648 : : struct rte_flow *flow,
6649 : : const struct rte_flow_attr *attr,
6650 : : const struct rte_flow_item items[],
6651 : : const struct rte_flow_action actions[],
6652 : : struct mlx5_flow_split_info *flow_split_info,
6653 : : struct rte_flow_error *error)
6654 : : {
6655 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6656 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
6657 : 0 : const struct rte_flow_action *qrss = NULL;
6658 : : struct rte_flow_action *ext_actions = NULL;
6659 : 0 : struct mlx5_flow *dev_flow = NULL;
6660 : : uint32_t qrss_id = 0;
6661 : : int mtr_sfx = 0;
6662 : : size_t act_size;
6663 : : int actions_n;
6664 : : int encap_idx;
6665 : : int ret;
6666 : :
6667 : : /* Check whether extensive metadata feature is engaged. */
6668 [ # # ]: 0 : if (!config->dv_flow_en ||
6669 [ # # # # ]: 0 : config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
6670 : 0 : !mlx5_flow_ext_mreg_supported(dev))
6671 : 0 : return flow_create_split_inner(dev, flow, NULL, attr, items,
6672 : : actions, flow_split_info, error);
6673 : 0 : actions_n = flow_parse_metadata_split_actions_info(actions, &qrss,
6674 : : &encap_idx);
6675 [ # # ]: 0 : if (qrss) {
6676 : : /* Exclude hairpin flows from splitting. */
6677 [ # # ]: 0 : if (qrss->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
6678 : : const struct rte_flow_action_queue *queue;
6679 : :
6680 : 0 : queue = qrss->conf;
6681 [ # # ]: 0 : if (mlx5_rxq_is_hairpin(dev, queue->index))
6682 : 0 : qrss = NULL;
6683 [ # # ]: 0 : } else if (qrss->type == RTE_FLOW_ACTION_TYPE_RSS) {
6684 : : const struct rte_flow_action_rss *rss;
6685 : :
6686 : 0 : rss = qrss->conf;
6687 [ # # ]: 0 : if (mlx5_rxq_is_hairpin(dev, rss->queue[0]))
6688 : 0 : qrss = NULL;
6689 : : }
6690 : : }
6691 [ # # ]: 0 : if (qrss) {
6692 : : /* Check if it is in meter suffix table. */
6693 : 0 : mtr_sfx = attr->group ==
6694 [ # # ]: 0 : ((attr->transfer && priv->fdb_def_rule) ?
6695 [ # # ]: 0 : (MLX5_FLOW_TABLE_LEVEL_METER - 1) :
6696 : : MLX5_FLOW_TABLE_LEVEL_METER);
6697 : : /*
6698 : : * Q/RSS action on NIC Rx should be split in order to pass by
6699 : : * the mreg copy table (RX_CP_TBL) and then it jumps to the
6700 : : * action table (RX_ACT_TBL) which has the split Q/RSS action.
6701 : : */
6702 : 0 : act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
6703 : 0 : sizeof(struct rte_flow_action_set_tag) +
6704 : : sizeof(struct rte_flow_action_jump);
6705 : 0 : ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
6706 : : SOCKET_ID_ANY);
6707 [ # # ]: 0 : if (!ext_actions)
6708 : 0 : return rte_flow_error_set(error, ENOMEM,
6709 : : RTE_FLOW_ERROR_TYPE_ACTION,
6710 : : NULL, "no memory to split "
6711 : : "metadata flow");
6712 : : /*
6713 : : * Create the new actions list with removed Q/RSS action
6714 : : * and appended set tag and jump to register copy table
6715 : : * (RX_CP_TBL). We should preallocate unique tag ID here
6716 : : * in advance, because it is needed for set tag action.
6717 : : */
6718 : 0 : qrss_id = flow_mreg_split_qrss_prep(dev, ext_actions, actions,
6719 : : qrss, actions_n,
6720 : : mtr_sfx, error);
6721 [ # # ]: 0 : if (!mtr_sfx && !qrss_id) {
6722 : 0 : ret = -rte_errno;
6723 : 0 : goto exit;
6724 : : }
6725 [ # # ]: 0 : } else if (attr->egress) {
6726 : : /*
6727 : : * All the actions on NIC Tx should have a metadata register
6728 : : * copy action to copy reg_a from WQE to reg_c[meta]
6729 : : */
6730 : 0 : act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
6731 : : sizeof(struct mlx5_flow_action_copy_mreg);
6732 : 0 : ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
6733 : : SOCKET_ID_ANY);
6734 [ # # ]: 0 : if (!ext_actions)
6735 : 0 : return rte_flow_error_set(error, ENOMEM,
6736 : : RTE_FLOW_ERROR_TYPE_ACTION,
6737 : : NULL, "no memory to split "
6738 : : "metadata flow");
6739 : : /* Create the action list appended with copy register. */
6740 : 0 : ret = flow_mreg_tx_copy_prep(dev, ext_actions, actions,
6741 : : actions_n, error, encap_idx);
6742 [ # # ]: 0 : if (ret < 0)
6743 : 0 : goto exit;
6744 : : }
6745 : : /* Add the unmodified original or prefix subflow. */
6746 [ # # ]: 0 : ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
6747 : : items, ext_actions ? ext_actions :
6748 : : actions, flow_split_info, error);
6749 [ # # ]: 0 : if (ret < 0)
6750 : 0 : goto exit;
6751 : : MLX5_ASSERT(dev_flow);
6752 [ # # ]: 0 : if (qrss) {
6753 : 0 : const struct rte_flow_attr q_attr = {
6754 : : .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
6755 : : .ingress = 1,
6756 : : };
6757 : : /* Internal PMD action to set register. */
6758 : 0 : struct mlx5_rte_flow_item_tag q_tag_spec = {
6759 : : .data = qrss_id,
6760 : : .id = REG_NON,
6761 : : };
6762 : 0 : struct rte_flow_item q_items[] = {
6763 : : {
6764 : : .type = (enum rte_flow_item_type)
6765 : : MLX5_RTE_FLOW_ITEM_TYPE_TAG,
6766 : : .spec = &q_tag_spec,
6767 : : .last = NULL,
6768 : : .mask = NULL,
6769 : : },
6770 : : {
6771 : : .type = RTE_FLOW_ITEM_TYPE_END,
6772 : : },
6773 : : };
6774 : 0 : struct rte_flow_action q_actions[] = {
6775 : : {
6776 : 0 : .type = qrss->type,
6777 : 0 : .conf = qrss->conf,
6778 : : },
6779 : : {
6780 : : .type = RTE_FLOW_ACTION_TYPE_END,
6781 : : },
6782 : : };
6783 : 0 : uint64_t layers = flow_get_prefix_layer_flags(dev_flow);
6784 : :
6785 : : /*
6786 : : * Configure the tag item only if there is no meter subflow.
6787 : : * Since tag is already marked in the meter suffix subflow
6788 : : * we can just use the meter suffix items as is.
6789 : : */
6790 [ # # ]: 0 : if (qrss_id) {
6791 : : /* Not meter subflow. */
6792 : : MLX5_ASSERT(!mtr_sfx);
6793 : : /*
6794 : : * Put unique id in prefix flow due to it is destroyed
6795 : : * after suffix flow and id will be freed after there
6796 : : * is no actual flows with this id and identifier
6797 : : * reallocation becomes possible (for example, for
6798 : : * other flows in other threads).
6799 : : */
6800 : 0 : dev_flow->handle->split_flow_id = qrss_id;
6801 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0,
6802 : : error);
6803 [ # # ]: 0 : if (ret < 0)
6804 : 0 : goto exit;
6805 : 0 : q_tag_spec.id = ret;
6806 : : }
6807 : 0 : dev_flow = NULL;
6808 : : /* Add suffix subflow to execute Q/RSS. */
6809 : 0 : flow_split_info->prefix_layers = layers;
6810 : 0 : flow_split_info->prefix_mark = 0;
6811 : 0 : flow_split_info->table_id = 0;
6812 [ # # ]: 0 : ret = flow_create_split_inner(dev, flow, &dev_flow,
6813 : : &q_attr, mtr_sfx ? items :
6814 : : q_items, q_actions,
6815 : : flow_split_info, error);
6816 [ # # ]: 0 : if (ret < 0)
6817 : 0 : goto exit;
6818 : : /* qrss ID should be freed if failed. */
6819 : : qrss_id = 0;
6820 : : MLX5_ASSERT(dev_flow);
6821 : : }
6822 : :
6823 : 0 : exit:
6824 : : /*
6825 : : * We do not destroy the partially created sub_flows in case of error.
6826 : : * These ones are included into parent flow list and will be destroyed
6827 : : * by flow_drv_destroy.
6828 : : */
6829 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
6830 : : qrss_id);
6831 : 0 : mlx5_free(ext_actions);
6832 : 0 : return ret;
6833 : : }
6834 : :
6835 : : /**
6836 : : * Create meter internal drop flow with the original pattern.
6837 : : *
6838 : : * @param dev
6839 : : * Pointer to Ethernet device.
6840 : : * @param[in] flow
6841 : : * Parent flow structure pointer.
6842 : : * @param[in] attr
6843 : : * Flow rule attributes.
6844 : : * @param[in] items
6845 : : * Pattern specification (list terminated by the END pattern item).
6846 : : * @param[in] flow_split_info
6847 : : * Pointer to flow split info structure.
6848 : : * @param[in] fm
6849 : : * Pointer to flow meter structure.
6850 : : * @param[out] error
6851 : : * Perform verbose error reporting if not NULL.
6852 : : * @return
6853 : : * 0 on success, negative value otherwise
6854 : : */
6855 : : static uint32_t
6856 : 0 : flow_meter_create_drop_flow_with_org_pattern(struct rte_eth_dev *dev,
6857 : : struct rte_flow *flow,
6858 : : const struct rte_flow_attr *attr,
6859 : : const struct rte_flow_item items[],
6860 : : struct mlx5_flow_split_info *flow_split_info,
6861 : : struct mlx5_flow_meter_info *fm,
6862 : : struct rte_flow_error *error)
6863 : : {
6864 : 0 : struct mlx5_flow *dev_flow = NULL;
6865 : 0 : struct rte_flow_attr drop_attr = *attr;
6866 : : struct rte_flow_action drop_actions[3];
6867 : 0 : struct mlx5_flow_split_info drop_split_info = *flow_split_info;
6868 : :
6869 : : MLX5_ASSERT(fm->drop_cnt);
6870 : 0 : drop_actions[0].type =
6871 : : (enum rte_flow_action_type)MLX5_RTE_FLOW_ACTION_TYPE_COUNT;
6872 : 0 : drop_actions[0].conf = (void *)(uintptr_t)fm->drop_cnt;
6873 : 0 : drop_actions[1].type = RTE_FLOW_ACTION_TYPE_DROP;
6874 : 0 : drop_actions[1].conf = NULL;
6875 : 0 : drop_actions[2].type = RTE_FLOW_ACTION_TYPE_END;
6876 : 0 : drop_actions[2].conf = NULL;
6877 : 0 : drop_split_info.external = false;
6878 : 0 : drop_split_info.skip_scale |= 1 << MLX5_SCALE_FLOW_GROUP_BIT;
6879 : 0 : drop_split_info.table_id = MLX5_MTR_TABLE_ID_DROP;
6880 : 0 : drop_attr.group = MLX5_FLOW_TABLE_LEVEL_METER;
6881 : 0 : return flow_create_split_inner(dev, flow, &dev_flow,
6882 : : &drop_attr, items, drop_actions,
6883 : : &drop_split_info, error);
6884 : : }
6885 : :
6886 : : static int
6887 : : flow_count_vlan_items(const struct rte_flow_item items[])
6888 : : {
6889 : : int items_n = 0;
6890 : :
6891 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
6892 [ # # ]: 0 : if (items->type == RTE_FLOW_ITEM_TYPE_VLAN ||
6893 : : items->type == (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_VLAN)
6894 : 0 : items_n++;
6895 : : }
6896 : : return items_n;
6897 : : }
6898 : :
6899 : : /**
6900 : : * The splitting for meter feature.
6901 : : *
6902 : : * - The meter flow will be split to two flows as prefix and
6903 : : * suffix flow. The packets make sense only it pass the prefix
6904 : : * meter action.
6905 : : *
6906 : : * - Reg_C_5 is used for the packet to match betweend prefix and
6907 : : * suffix flow.
6908 : : *
6909 : : * @param dev
6910 : : * Pointer to Ethernet device.
6911 : : * @param[in] flow
6912 : : * Parent flow structure pointer.
6913 : : * @param[in] attr
6914 : : * Flow rule attributes.
6915 : : * @param[in] items
6916 : : * Pattern specification (list terminated by the END pattern item).
6917 : : * @param[in] actions
6918 : : * Associated actions (list terminated by the END action).
6919 : : * @param[in] flow_split_info
6920 : : * Pointer to flow split info structure.
6921 : : * @param[out] error
6922 : : * Perform verbose error reporting if not NULL.
6923 : : * @return
6924 : : * 0 on success, negative value otherwise
6925 : : */
6926 : : static int
6927 : 0 : flow_create_split_meter(struct rte_eth_dev *dev,
6928 : : struct rte_flow *flow,
6929 : : const struct rte_flow_attr *attr,
6930 : : const struct rte_flow_item items[],
6931 : : const struct rte_flow_action actions[],
6932 : : struct mlx5_flow_split_info *flow_split_info,
6933 : : struct rte_flow_error *error)
6934 : : {
6935 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6936 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
6937 : : struct rte_flow_action *sfx_actions = NULL;
6938 : : struct rte_flow_action *pre_actions = NULL;
6939 : : struct rte_flow_item *sfx_items = NULL;
6940 : 0 : struct mlx5_flow *dev_flow = NULL;
6941 : 0 : struct rte_flow_attr sfx_attr = *attr;
6942 : : struct mlx5_flow_meter_info *fm = NULL;
6943 : : uint8_t skip_scale_restore;
6944 : 0 : bool has_mtr = false;
6945 : 0 : bool has_modify = false;
6946 : : bool set_mtr_reg = true;
6947 : : bool is_mtr_hierarchy = false;
6948 : 0 : uint32_t meter_id = 0;
6949 : 0 : uint32_t mtr_idx = 0;
6950 : 0 : uint32_t mtr_flow_id = 0;
6951 : : size_t act_size;
6952 : : size_t item_size;
6953 : : int actions_n = 0;
6954 : : int vlan_items_n = 0;
6955 : : int ret = 0;
6956 : :
6957 [ # # ]: 0 : if (priv->mtr_en)
6958 : 0 : actions_n = flow_check_meter_action(dev, actions, &has_mtr,
6959 : : &has_modify, &meter_id);
6960 [ # # ]: 0 : if (has_mtr) {
6961 [ # # ]: 0 : if (flow->meter) {
6962 : 0 : fm = mlx5_flow_dv_meter_find_by_idx(priv, flow->meter);
6963 [ # # ]: 0 : if (!fm)
6964 : 0 : return rte_flow_error_set(error, EINVAL,
6965 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6966 : : NULL, "Meter not found.");
6967 : : } else {
6968 : 0 : fm = mlx5_flow_meter_find(priv, meter_id, &mtr_idx);
6969 [ # # ]: 0 : if (!fm)
6970 : 0 : return rte_flow_error_set(error, EINVAL,
6971 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6972 : : NULL, "Meter not found.");
6973 : 0 : ret = mlx5_flow_meter_attach(priv, fm,
6974 : : &sfx_attr, error);
6975 [ # # ]: 0 : if (ret)
6976 : 0 : return -rte_errno;
6977 : 0 : flow->meter = mtr_idx;
6978 : : }
6979 : : MLX5_ASSERT(wks);
6980 : 0 : wks->fm = fm;
6981 [ # # ]: 0 : if (!fm->def_policy) {
6982 : 0 : wks->policy = mlx5_flow_meter_policy_find(dev,
6983 : : fm->policy_id,
6984 : : NULL);
6985 : : MLX5_ASSERT(wks->policy);
6986 [ # # ]: 0 : if (wks->policy->mark)
6987 : 0 : wks->mark = 1;
6988 [ # # ]: 0 : if (wks->policy->is_hierarchy) {
6989 : 0 : wks->final_policy =
6990 : 0 : mlx5_flow_meter_hierarchy_get_final_policy(dev,
6991 : : wks->policy);
6992 [ # # ]: 0 : if (!wks->final_policy)
6993 : 0 : return rte_flow_error_set(error,
6994 : : EINVAL,
6995 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6996 : : "Failed to find terminal policy of hierarchy.");
6997 : : is_mtr_hierarchy = true;
6998 : : }
6999 : : }
7000 : : /*
7001 : : * If it isn't default-policy Meter, and
7002 : : * 1. Not meter hierarchy and there's no action in flow to change
7003 : : * packet (modify/encap/decap etc.), OR
7004 : : * 2. No drop count needed for this meter.
7005 : : * Then no need to use regC to save meter id anymore.
7006 : : */
7007 [ # # # # : 0 : if (!fm->def_policy && ((!has_modify && !is_mtr_hierarchy) || !fm->drop_cnt))
# # # # ]
7008 : : set_mtr_reg = false;
7009 : : /* Prefix actions: meter, decap, encap, tag, jump, end, cnt. */
7010 : : #define METER_PREFIX_ACTION 7
7011 : 0 : act_size = (sizeof(struct rte_flow_action) *
7012 : 0 : (actions_n + METER_PREFIX_ACTION)) +
7013 : : sizeof(struct mlx5_rte_flow_action_set_tag);
7014 : : /* Flow can have multiple VLAN items. Account for them in suffix items. */
7015 : : vlan_items_n = flow_count_vlan_items(items);
7016 : : /* Suffix items: tag, [vlans], port id, end. */
7017 : : #define METER_SUFFIX_ITEM 3
7018 : 0 : item_size = sizeof(struct rte_flow_item) * (METER_SUFFIX_ITEM + vlan_items_n) +
7019 : : sizeof(struct mlx5_rte_flow_item_tag) * 2;
7020 : 0 : sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size + item_size),
7021 : : 0, SOCKET_ID_ANY);
7022 [ # # ]: 0 : if (!sfx_actions)
7023 : 0 : return rte_flow_error_set(error, ENOMEM,
7024 : : RTE_FLOW_ERROR_TYPE_ACTION,
7025 : : NULL, "no memory to split "
7026 : : "meter flow");
7027 : 0 : sfx_items = (struct rte_flow_item *)((char *)sfx_actions +
7028 : : act_size);
7029 : : /* There's no suffix flow for meter of non-default policy. */
7030 [ # # ]: 0 : if (!fm->def_policy)
7031 : 0 : pre_actions = sfx_actions + 1;
7032 : : else
7033 : 0 : pre_actions = sfx_actions + actions_n;
7034 [ # # ]: 0 : ret = flow_meter_split_prep(dev, flow, wks, &sfx_attr,
7035 : : items, sfx_items, actions,
7036 : : sfx_actions, pre_actions,
7037 : : (set_mtr_reg ? &mtr_flow_id : NULL),
7038 : : error);
7039 [ # # ]: 0 : if (ret) {
7040 : 0 : ret = -rte_errno;
7041 : 0 : goto exit;
7042 : : }
7043 : : /* Add the prefix subflow. */
7044 : 0 : skip_scale_restore = flow_split_info->skip_scale;
7045 : 0 : flow_split_info->skip_scale |=
7046 : : 1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT;
7047 : 0 : ret = flow_create_split_inner(dev, flow, &dev_flow,
7048 : : attr, items, pre_actions,
7049 : : flow_split_info, error);
7050 : 0 : flow_split_info->skip_scale = skip_scale_restore;
7051 [ # # ]: 0 : if (ret) {
7052 [ # # ]: 0 : if (mtr_flow_id)
7053 : 0 : mlx5_ipool_free(fm->flow_ipool, mtr_flow_id);
7054 : 0 : ret = -rte_errno;
7055 : 0 : goto exit;
7056 : : }
7057 [ # # ]: 0 : if (mtr_flow_id) {
7058 : 0 : dev_flow->handle->split_flow_id = mtr_flow_id;
7059 : 0 : dev_flow->handle->is_meter_flow_id = 1;
7060 : : }
7061 [ # # ]: 0 : if (!fm->def_policy) {
7062 [ # # # # ]: 0 : if (!set_mtr_reg && fm->drop_cnt)
7063 : 0 : ret =
7064 : 0 : flow_meter_create_drop_flow_with_org_pattern(dev, flow,
7065 : : &sfx_attr, items,
7066 : : flow_split_info,
7067 : : fm, error);
7068 : 0 : goto exit;
7069 : : }
7070 : : /* Setting the sfx group atrr. */
7071 [ # # ]: 0 : sfx_attr.group = (sfx_attr.transfer && priv->fdb_def_rule) ?
7072 [ # # ]: 0 : (MLX5_FLOW_TABLE_LEVEL_METER - 1) :
7073 : : MLX5_FLOW_TABLE_LEVEL_METER;
7074 : 0 : flow_split_info->prefix_layers =
7075 : 0 : flow_get_prefix_layer_flags(dev_flow);
7076 : 0 : flow_split_info->prefix_mark |= wks->mark;
7077 : 0 : flow_split_info->table_id = MLX5_MTR_TABLE_ID_SUFFIX;
7078 : : }
7079 : : /* Add the prefix subflow. */
7080 [ # # ]: 0 : ret = flow_create_split_metadata(dev, flow,
7081 : : &sfx_attr, sfx_items ?
7082 : : sfx_items : items,
7083 : : sfx_actions ? sfx_actions : actions,
7084 : : flow_split_info, error);
7085 : 0 : exit:
7086 [ # # ]: 0 : if (sfx_actions)
7087 : 0 : mlx5_free(sfx_actions);
7088 : : return ret;
7089 : : }
7090 : :
7091 : : /**
7092 : : * The splitting for sample feature.
7093 : : *
7094 : : * Once Sample action is detected in the action list, the flow actions should
7095 : : * be split into prefix sub flow and suffix sub flow.
7096 : : *
7097 : : * The original items remain in the prefix sub flow, all actions preceding the
7098 : : * sample action and the sample action itself will be copied to the prefix
7099 : : * sub flow, the actions following the sample action will be copied to the
7100 : : * suffix sub flow, Queue action always be located in the suffix sub flow.
7101 : : *
7102 : : * In order to make the packet from prefix sub flow matches with suffix sub
7103 : : * flow, an extra tag action be added into prefix sub flow, and the suffix sub
7104 : : * flow uses tag item with the unique flow id.
7105 : : *
7106 : : * @param dev
7107 : : * Pointer to Ethernet device.
7108 : : * @param[in] flow
7109 : : * Parent flow structure pointer.
7110 : : * @param[in] attr
7111 : : * Flow rule attributes.
7112 : : * @param[in] items
7113 : : * Pattern specification (list terminated by the END pattern item).
7114 : : * @param[in] actions
7115 : : * Associated actions (list terminated by the END action).
7116 : : * @param[in] flow_split_info
7117 : : * Pointer to flow split info structure.
7118 : : * @param[out] error
7119 : : * Perform verbose error reporting if not NULL.
7120 : : * @return
7121 : : * 0 on success, negative value otherwise
7122 : : */
7123 : : static int
7124 : 0 : flow_create_split_sample(struct rte_eth_dev *dev,
7125 : : struct rte_flow *flow,
7126 : : const struct rte_flow_attr *attr,
7127 : : const struct rte_flow_item items[],
7128 : : const struct rte_flow_action actions[],
7129 : : struct mlx5_flow_split_info *flow_split_info,
7130 : : struct rte_flow_error *error)
7131 : : {
7132 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7133 : : struct rte_flow_action *sfx_actions = NULL;
7134 : : struct rte_flow_action *pre_actions = NULL;
7135 : : struct rte_flow_item *sfx_items = NULL;
7136 : 0 : struct mlx5_flow *dev_flow = NULL;
7137 : 0 : struct rte_flow_attr sfx_attr = *attr;
7138 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
7139 : : struct mlx5_flow_dv_sample_resource *sample_res;
7140 : : struct mlx5_flow_tbl_data_entry *sfx_tbl_data;
7141 : : struct mlx5_flow_tbl_resource *sfx_tbl;
7142 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
7143 : : #endif
7144 : : size_t act_size;
7145 : : size_t item_size;
7146 : : uint32_t fdb_tx = 0;
7147 : : int32_t tag_id = 0;
7148 : : int actions_n = 0;
7149 : : int sample_action_pos;
7150 : : int qrss_action_pos;
7151 : : int add_tag = 0;
7152 : 0 : int modify_after_mirror = 0;
7153 : : uint16_t jump_table = 0;
7154 : : const uint32_t next_ft_step = 1;
7155 : : int ret = 0;
7156 : : struct mlx5_priv *item_port_priv = NULL;
7157 : : const struct rte_flow_item *item;
7158 : :
7159 [ # # ]: 0 : if (priv->sampler_en)
7160 : 0 : actions_n = flow_check_match_action(actions, attr,
7161 : : RTE_FLOW_ACTION_TYPE_SAMPLE,
7162 : : &sample_action_pos, &qrss_action_pos,
7163 : : &modify_after_mirror);
7164 [ # # ]: 0 : if (actions_n) {
7165 : : /* The prefix actions must includes sample, tag, end. */
7166 : 0 : act_size = sizeof(struct rte_flow_action) * (actions_n * 2 + 1)
7167 : : + sizeof(struct mlx5_rte_flow_action_set_tag);
7168 : : item_size = sizeof(struct rte_flow_item) * SAMPLE_SUFFIX_ITEM +
7169 : : sizeof(struct mlx5_rte_flow_item_tag) * 2;
7170 : 0 : sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size +
7171 : : item_size), 0, SOCKET_ID_ANY);
7172 [ # # ]: 0 : if (!sfx_actions)
7173 : 0 : return rte_flow_error_set(error, ENOMEM,
7174 : : RTE_FLOW_ERROR_TYPE_ACTION,
7175 : : NULL, "no memory to split "
7176 : : "sample flow");
7177 [ # # ]: 0 : for (item = items; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
7178 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_PORT_ID) {
7179 : : const struct rte_flow_item_port_id *spec;
7180 : :
7181 : 0 : spec = (const struct rte_flow_item_port_id *)item->spec;
7182 [ # # ]: 0 : if (spec)
7183 : : item_port_priv =
7184 : 0 : mlx5_port_to_eswitch_info(spec->id, true);
7185 : : break;
7186 [ # # ]: 0 : } else if (item->type == RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT) {
7187 : : const struct rte_flow_item_ethdev *spec;
7188 : :
7189 : 0 : spec = (const struct rte_flow_item_ethdev *)item->spec;
7190 [ # # ]: 0 : if (spec)
7191 : : item_port_priv =
7192 : 0 : mlx5_port_to_eswitch_info(spec->port_id, true);
7193 : : break;
7194 [ # # ]: 0 : } else if (item->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR) {
7195 : : const struct rte_flow_item_ethdev *spec;
7196 : :
7197 : 0 : spec = (const struct rte_flow_item_ethdev *)item->spec;
7198 [ # # ]: 0 : if (spec)
7199 : : item_port_priv =
7200 : 0 : mlx5_port_to_eswitch_info(spec->port_id, true);
7201 : : break;
7202 : : }
7203 : : }
7204 : : /* The representor_id is UINT16_MAX for uplink. */
7205 [ # # # # ]: 0 : fdb_tx = (attr->transfer &&
7206 : : flow_source_vport_representor(priv, item_port_priv));
7207 : : /*
7208 : : * When reg_c_preserve is set, metadata registers Cx preserve
7209 : : * their value even through packet duplication.
7210 : : */
7211 : 0 : add_tag = (!fdb_tx ||
7212 [ # # ]: 0 : priv->sh->cdev->config.hca_attr.reg_c_preserve);
7213 : : if (add_tag)
7214 : 0 : sfx_items = (struct rte_flow_item *)((char *)sfx_actions
7215 : : + act_size);
7216 [ # # ]: 0 : if (modify_after_mirror)
7217 : 0 : jump_table = attr->group * MLX5_FLOW_TABLE_FACTOR +
7218 : : next_ft_step;
7219 : 0 : pre_actions = sfx_actions + actions_n;
7220 : 0 : tag_id = flow_sample_split_prep(dev, add_tag, items, sfx_items,
7221 : : actions, sfx_actions,
7222 : : pre_actions, actions_n,
7223 : : sample_action_pos,
7224 : : qrss_action_pos, jump_table,
7225 : : error);
7226 [ # # # # ]: 0 : if (tag_id < 0 || (add_tag && !tag_id)) {
7227 : 0 : ret = -rte_errno;
7228 : 0 : goto exit;
7229 : : }
7230 [ # # ]: 0 : if (modify_after_mirror)
7231 : 0 : flow_split_info->skip_scale =
7232 : : 1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT;
7233 : : /* Add the prefix subflow. */
7234 : 0 : ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
7235 : : items, pre_actions,
7236 : : flow_split_info, error);
7237 [ # # ]: 0 : if (ret) {
7238 : 0 : ret = -rte_errno;
7239 : 0 : goto exit;
7240 : : }
7241 : 0 : dev_flow->handle->split_flow_id = tag_id;
7242 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
7243 [ # # ]: 0 : if (!modify_after_mirror) {
7244 : : /* Set the sfx group attr. */
7245 : 0 : sample_res = (struct mlx5_flow_dv_sample_resource *)
7246 : : dev_flow->dv.sample_res;
7247 : 0 : sfx_tbl = (struct mlx5_flow_tbl_resource *)
7248 : : sample_res->normal_path_tbl;
7249 : 0 : sfx_tbl_data = container_of(sfx_tbl,
7250 : : struct mlx5_flow_tbl_data_entry,
7251 : : tbl);
7252 [ # # ]: 0 : sfx_attr.group = (sfx_attr.transfer && priv->fdb_def_rule) ?
7253 [ # # ]: 0 : (sfx_tbl_data->level - 1) : sfx_tbl_data->level;
7254 : : } else {
7255 : : MLX5_ASSERT(attr->transfer);
7256 : 0 : sfx_attr.group = jump_table;
7257 : : }
7258 : 0 : flow_split_info->prefix_layers =
7259 : 0 : flow_get_prefix_layer_flags(dev_flow);
7260 : : MLX5_ASSERT(wks);
7261 : 0 : flow_split_info->prefix_mark |= wks->mark;
7262 : : /* Suffix group level already be scaled with factor, set
7263 : : * MLX5_SCALE_FLOW_GROUP_BIT of skip_scale to 1 to avoid scale
7264 : : * again in translation.
7265 : : */
7266 : 0 : flow_split_info->skip_scale = 1 << MLX5_SCALE_FLOW_GROUP_BIT;
7267 : : #endif
7268 : : }
7269 : : /* Add the suffix subflow. */
7270 [ # # # # ]: 0 : ret = flow_create_split_meter(dev, flow, &sfx_attr,
7271 : : sfx_items ? sfx_items : items,
7272 : : sfx_actions ? sfx_actions : actions,
7273 : : flow_split_info, error);
7274 : 0 : exit:
7275 [ # # ]: 0 : if (sfx_actions)
7276 : 0 : mlx5_free(sfx_actions);
7277 : : return ret;
7278 : : }
7279 : :
7280 : : /**
7281 : : * Split the flow to subflow set. The splitters might be linked
7282 : : * in the chain, like this:
7283 : : * flow_create_split_outer() calls:
7284 : : * flow_create_split_meter() calls:
7285 : : * flow_create_split_metadata(meter_subflow_0) calls:
7286 : : * flow_create_split_inner(metadata_subflow_0)
7287 : : * flow_create_split_inner(metadata_subflow_1)
7288 : : * flow_create_split_inner(metadata_subflow_2)
7289 : : * flow_create_split_metadata(meter_subflow_1) calls:
7290 : : * flow_create_split_inner(metadata_subflow_0)
7291 : : * flow_create_split_inner(metadata_subflow_1)
7292 : : * flow_create_split_inner(metadata_subflow_2)
7293 : : *
7294 : : * This provide flexible way to add new levels of flow splitting.
7295 : : * The all of successfully created subflows are included to the
7296 : : * parent flow dev_flow list.
7297 : : *
7298 : : * @param dev
7299 : : * Pointer to Ethernet device.
7300 : : * @param[in] flow
7301 : : * Parent flow structure pointer.
7302 : : * @param[in] attr
7303 : : * Flow rule attributes.
7304 : : * @param[in] items
7305 : : * Pattern specification (list terminated by the END pattern item).
7306 : : * @param[in] actions
7307 : : * Associated actions (list terminated by the END action).
7308 : : * @param[in] flow_split_info
7309 : : * Pointer to flow split info structure.
7310 : : * @param[out] error
7311 : : * Perform verbose error reporting if not NULL.
7312 : : * @return
7313 : : * 0 on success, negative value otherwise
7314 : : */
7315 : : static int
7316 : : flow_create_split_outer(struct rte_eth_dev *dev,
7317 : : struct rte_flow *flow,
7318 : : const struct rte_flow_attr *attr,
7319 : : const struct rte_flow_item items[],
7320 : : const struct rte_flow_action actions[],
7321 : : struct mlx5_flow_split_info *flow_split_info,
7322 : : struct rte_flow_error *error)
7323 : : {
7324 : : int ret;
7325 : :
7326 : 0 : ret = flow_create_split_sample(dev, flow, attr, items,
7327 : : actions, flow_split_info, error);
7328 : : MLX5_ASSERT(ret <= 0);
7329 : : return ret;
7330 : : }
7331 : :
7332 : : static inline struct mlx5_flow_tunnel *
7333 : : flow_tunnel_from_rule(const struct mlx5_flow *flow)
7334 : : {
7335 : : struct mlx5_flow_tunnel *tunnel;
7336 : :
7337 : 0 : tunnel = RTE_PTR_UNQUAL(flow->tunnel);
7338 : :
7339 : : return tunnel;
7340 : : }
7341 : :
7342 : : /**
7343 : : * Create a flow and add it to @p list.
7344 : : *
7345 : : * @param dev
7346 : : * Pointer to Ethernet device.
7347 : : * @param list
7348 : : * Pointer to a TAILQ flow list. If this parameter NULL,
7349 : : * no list insertion occurred, flow is just created,
7350 : : * this is caller's responsibility to track the
7351 : : * created flow.
7352 : : * @param[in] attr
7353 : : * Flow rule attributes.
7354 : : * @param[in] items
7355 : : * Pattern specification (list terminated by the END pattern item).
7356 : : * @param[in] actions
7357 : : * Associated actions (list terminated by the END action).
7358 : : * @param[in] external
7359 : : * This flow rule is created by request external to PMD.
7360 : : * @param[out] error
7361 : : * Perform verbose error reporting if not NULL.
7362 : : *
7363 : : * @return
7364 : : * A flow index on success, 0 otherwise and rte_errno is set.
7365 : : */
7366 : : uintptr_t
7367 : 0 : mlx5_flow_legacy_list_create(struct rte_eth_dev *dev, enum mlx5_flow_type type,
7368 : : const struct rte_flow_attr *attr,
7369 : : const struct rte_flow_item items[],
7370 : : const struct rte_flow_action original_actions[],
7371 : : bool external, struct rte_flow_error *error)
7372 : : {
7373 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7374 : : struct rte_flow *flow = NULL;
7375 : : struct mlx5_flow *dev_flow;
7376 : : const struct rte_flow_action_rss *rss = NULL;
7377 : : struct mlx5_translated_action_handle
7378 : : indir_actions[MLX5_MAX_INDIRECT_ACTIONS];
7379 : 0 : int indir_actions_n = MLX5_MAX_INDIRECT_ACTIONS;
7380 : : union {
7381 : : struct mlx5_flow_expand_rss buf;
7382 : : uint8_t buffer[8192];
7383 : : } expand_buffer;
7384 : : union {
7385 : : struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
7386 : : uint8_t buffer[2048];
7387 : : } actions_rx;
7388 : : union {
7389 : : struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
7390 : : uint8_t buffer[2048];
7391 : : } actions_hairpin_tx;
7392 : : union {
7393 : : struct rte_flow_item items[MLX5_MAX_SPLIT_ITEMS];
7394 : : uint8_t buffer[2048];
7395 : : } items_tx;
7396 : : struct mlx5_rte_flow_item_sq sq_specs[RTE_MAX_QUEUES_PER_PORT];
7397 : : struct mlx5_flow_expand_rss *buf = &expand_buffer.buf;
7398 : : struct mlx5_flow_rss_desc *rss_desc;
7399 : : const struct rte_flow_action *p_actions_rx;
7400 : : uint32_t i;
7401 : 0 : uint32_t idx = 0;
7402 : : int hairpin_flow;
7403 : 0 : struct rte_flow_attr attr_tx = { .priority = 0 };
7404 : : const struct rte_flow_action *actions;
7405 : 0 : struct rte_flow_action *translated_actions = NULL;
7406 : : struct mlx5_flow_tunnel *tunnel;
7407 : 0 : struct tunnel_default_miss_ctx default_miss_ctx = { 0, };
7408 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_push_thread_workspace();
7409 : 0 : struct mlx5_flow_split_info flow_split_info = {
7410 : : .external = !!external,
7411 : : .skip_scale = 0,
7412 : : .flow_idx = 0,
7413 : : .prefix_mark = 0,
7414 : : .prefix_layers = 0,
7415 : : .table_id = 0
7416 : : };
7417 : : int ret;
7418 : : struct mlx5_shared_action_rss *shared_rss_action;
7419 : :
7420 [ # # ]: 0 : if (!wks)
7421 : 0 : return rte_flow_error_set(error, ENOMEM,
7422 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7423 : : NULL,
7424 : : "failed to push flow workspace");
7425 : : memset(indir_actions, 0, sizeof(indir_actions));
7426 : 0 : rss_desc = &wks->rss_desc;
7427 : 0 : ret = flow_action_handles_translate(dev, original_actions,
7428 : : indir_actions,
7429 : : &indir_actions_n,
7430 : : &translated_actions, error);
7431 [ # # ]: 0 : if (ret < 0) {
7432 : : MLX5_ASSERT(translated_actions == NULL);
7433 : : return 0;
7434 : : }
7435 [ # # ]: 0 : actions = translated_actions ? translated_actions : original_actions;
7436 : : p_actions_rx = actions;
7437 : 0 : hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
7438 : 0 : ret = flow_drv_validate(dev, attr, items, p_actions_rx,
7439 : : external, hairpin_flow, error);
7440 [ # # ]: 0 : if (ret < 0)
7441 : 0 : goto error_before_hairpin_split;
7442 : 0 : flow = mlx5_ipool_zmalloc(priv->flows[type], &idx);
7443 [ # # ]: 0 : if (!flow) {
7444 : 0 : rte_errno = ENOMEM;
7445 : 0 : goto error_before_hairpin_split;
7446 : : }
7447 [ # # ]: 0 : if (hairpin_flow > 0) {
7448 [ # # ]: 0 : if (hairpin_flow > MLX5_MAX_SPLIT_ACTIONS) {
7449 : 0 : rte_errno = EINVAL;
7450 : 0 : goto error_before_hairpin_split;
7451 : : }
7452 : 0 : flow_hairpin_split(dev, actions, actions_rx.actions,
7453 : : actions_hairpin_tx.actions, items_tx.items,
7454 : : idx);
7455 : : p_actions_rx = actions_rx.actions;
7456 : : }
7457 : 0 : flow_split_info.flow_idx = idx;
7458 [ # # ]: 0 : flow->drv_type = flow_get_drv_type(dev, attr);
7459 : : /* drv_type upper limit does not require range check since it's only 2b size. */
7460 : : MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN);
7461 : : memset(rss_desc, 0, offsetof(struct mlx5_flow_rss_desc, queue));
7462 : : /* RSS Action only works on NIC RX domain */
7463 [ # # ]: 0 : if (attr->ingress)
7464 : 0 : rss = flow_get_rss_action(dev, p_actions_rx);
7465 [ # # ]: 0 : if (rss) {
7466 : : MLX5_ASSERT(rss->queue_num <= RTE_ETH_RSS_RETA_SIZE_512);
7467 : 0 : rss_desc->symmetric_hash_function = MLX5_RSS_IS_SYMM(rss->func);
7468 : : /*
7469 : : * The following information is required by
7470 : : * mlx5_flow_hashfields_adjust() in advance.
7471 : : */
7472 : 0 : rss_desc->level = rss->level;
7473 : : /* RSS type 0 indicates default RSS type (RTE_ETH_RSS_IP). */
7474 [ # # ]: 0 : rss_desc->types = !rss->types ? RTE_ETH_RSS_IP : rss->types;
7475 : : }
7476 : 0 : flow->dev_handles = 0;
7477 [ # # # # ]: 0 : if (rss && rss->types) {
7478 : : unsigned int graph_root;
7479 : :
7480 : 0 : graph_root = find_graph_root(rss->level);
7481 : 0 : ret = mlx5_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
7482 : : items, rss->types,
7483 : : mlx5_support_expansion, graph_root);
7484 : : MLX5_ASSERT(ret > 0 &&
7485 : : (unsigned int)ret < sizeof(expand_buffer.buffer));
7486 [ # # ]: 0 : if (rte_log_can_log(mlx5_logtype, RTE_LOG_DEBUG)) {
7487 [ # # ]: 0 : for (i = 0; i < buf->entries; ++i)
7488 : 0 : mlx5_dbg__print_pattern(buf->entry[i].pattern);
7489 : : }
7490 : : } else {
7491 : 0 : ret = mlx5_flow_expand_sqn((struct mlx5_flow_expand_sqn *)buf,
7492 : : sizeof(expand_buffer.buffer),
7493 : : items, sq_specs);
7494 [ # # ]: 0 : if (ret) {
7495 : 0 : rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_HANDLE,
7496 : : NULL, "not enough memory for rte_flow");
7497 : 0 : goto error;
7498 : : }
7499 [ # # ]: 0 : if (buf->entries == 0) {
7500 : 0 : buf->entries = 1;
7501 : 0 : buf->entry[0].pattern = (void *)(uintptr_t)items;
7502 : : }
7503 : : }
7504 : 0 : rss_desc->shared_rss = flow_get_shared_rss_action(dev, indir_actions,
7505 : : indir_actions_n);
7506 [ # # ]: 0 : for (i = 0; i < buf->entries; ++i) {
7507 : : /* Initialize flow split data. */
7508 : 0 : flow_split_info.prefix_layers = 0;
7509 : 0 : flow_split_info.prefix_mark = 0;
7510 : 0 : flow_split_info.skip_scale = 0;
7511 : : /*
7512 : : * The splitter may create multiple dev_flows,
7513 : : * depending on configuration. In the simplest
7514 : : * case it just creates unmodified original flow.
7515 : : */
7516 : : ret = flow_create_split_outer(dev, flow, attr,
7517 : 0 : buf->entry[i].pattern,
7518 : : p_actions_rx, &flow_split_info,
7519 : : error);
7520 [ # # ]: 0 : if (ret < 0)
7521 : 0 : goto error;
7522 [ # # ]: 0 : if (is_flow_tunnel_steer_rule(wks->flows[0].tof_type)) {
7523 : 0 : ret = flow_tunnel_add_default_miss(dev, flow, attr,
7524 : : p_actions_rx,
7525 : : idx,
7526 : : wks->flows[0].tunnel,
7527 : : &default_miss_ctx,
7528 : : error);
7529 [ # # ]: 0 : if (ret < 0) {
7530 : 0 : mlx5_free(default_miss_ctx.queue);
7531 : 0 : goto error;
7532 : : }
7533 : : }
7534 : : }
7535 : : /* Create the tx flow. */
7536 [ # # ]: 0 : if (hairpin_flow) {
7537 : 0 : attr_tx.group = MLX5_HAIRPIN_TX_TABLE;
7538 : 0 : attr_tx.ingress = 0;
7539 : 0 : attr_tx.egress = 1;
7540 : 0 : dev_flow = flow_drv_prepare(dev, flow, &attr_tx, items_tx.items,
7541 : : actions_hairpin_tx.actions,
7542 : : idx, error);
7543 [ # # ]: 0 : if (!dev_flow)
7544 : 0 : goto error;
7545 : 0 : dev_flow->flow = flow;
7546 : 0 : dev_flow->external = 0;
7547 : 0 : SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
7548 : : dev_flow->handle, next);
7549 : : ret = flow_drv_translate(dev, dev_flow, &attr_tx,
7550 : : items_tx.items,
7551 : : actions_hairpin_tx.actions, error);
7552 [ # # ]: 0 : if (ret < 0)
7553 : 0 : goto error;
7554 : : }
7555 : : /*
7556 : : * Update the metadata register copy table. If extensive
7557 : : * metadata feature is enabled and registers are supported
7558 : : * we might create the extra rte_flow for each unique
7559 : : * MARK/FLAG action ID.
7560 : : *
7561 : : * The table is updated for ingress and transfer flows only, because
7562 : : * the egress Flows belong to the different device and
7563 : : * copy table should be updated in peer NIC Rx domain.
7564 : : */
7565 [ # # # # ]: 0 : if ((attr->ingress || attr->transfer) &&
7566 [ # # ]: 0 : (external || attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
7567 : 0 : ret = flow_mreg_update_copy_table(dev, flow, actions, error);
7568 [ # # ]: 0 : if (ret)
7569 : 0 : goto error;
7570 : : }
7571 : : /*
7572 : : * If the flow is external (from application) OR device is started,
7573 : : * OR mreg discover, then apply immediately.
7574 : : */
7575 [ # # # # ]: 0 : if (external || dev->data->dev_started ||
7576 [ # # ]: 0 : (attr->group == MLX5_FLOW_MREG_CP_TABLE_GROUP &&
7577 [ # # ]: 0 : attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)) {
7578 : : ret = flow_drv_apply(dev, flow, error);
7579 [ # # ]: 0 : if (ret < 0)
7580 : 0 : goto error;
7581 : : }
7582 : 0 : flow->type = type;
7583 : 0 : flow_rxq_flags_set(dev, flow);
7584 : 0 : rte_free(translated_actions);
7585 : : tunnel = flow_tunnel_from_rule(wks->flows);
7586 [ # # ]: 0 : if (tunnel) {
7587 : 0 : flow->tunnel = 1;
7588 : 0 : flow->tunnel_id = tunnel->tunnel_id;
7589 : 0 : rte_atomic_fetch_add_explicit(&tunnel->refctn, 1, rte_memory_order_relaxed);
7590 : 0 : mlx5_free(default_miss_ctx.queue);
7591 : : }
7592 : 0 : mlx5_flow_pop_thread_workspace();
7593 : 0 : return idx;
7594 : 0 : error:
7595 : : MLX5_ASSERT(flow);
7596 : 0 : ret = rte_errno; /* Save rte_errno before cleanup. */
7597 : 0 : flow_mreg_del_copy_action(dev, flow);
7598 : : flow_drv_destroy(dev, flow);
7599 : :
7600 [ # # ]: 0 : if (rss_desc->shared_rss) {
7601 : : shared_rss_action = (struct mlx5_shared_action_rss *)
7602 : 0 : mlx5_ipool_get
7603 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
7604 : : rss_desc->shared_rss);
7605 [ # # ]: 0 : if (shared_rss_action)
7606 : 0 : rte_atomic_fetch_sub_explicit(&(shared_rss_action)->refcnt, 1,
7607 : : rte_memory_order_relaxed);
7608 : : }
7609 : 0 : mlx5_ipool_free(priv->flows[type], idx);
7610 : 0 : rte_errno = ret; /* Restore rte_errno. */
7611 : : ret = rte_errno;
7612 : : rte_errno = ret;
7613 : 0 : error_before_hairpin_split:
7614 : 0 : mlx5_flow_pop_thread_workspace();
7615 : 0 : rte_free(translated_actions);
7616 : 0 : return 0;
7617 : : }
7618 : :
7619 : : /**
7620 : : * Create a dedicated flow rule on e-switch table 0 (root table), to direct all
7621 : : * incoming packets to table 1.
7622 : : *
7623 : : * Other flow rules, requested for group n, will be created in
7624 : : * e-switch table n+1.
7625 : : * Jump action to e-switch group n will be created to group n+1.
7626 : : *
7627 : : * Used when working in switchdev mode, to utilise advantages of table 1
7628 : : * and above.
7629 : : *
7630 : : * @param dev
7631 : : * Pointer to Ethernet device.
7632 : : *
7633 : : * @return
7634 : : * Pointer to flow on success, NULL otherwise and rte_errno is set.
7635 : : */
7636 : : struct rte_flow *
7637 : 0 : mlx5_flow_create_esw_table_zero_flow(struct rte_eth_dev *dev)
7638 : : {
7639 : 0 : const struct rte_flow_attr attr = {
7640 : : .group = 0,
7641 : : .priority = 0,
7642 : : .ingress = 0,
7643 : : .egress = 0,
7644 : : .transfer = 1,
7645 : : };
7646 : 0 : const struct rte_flow_item pattern = {
7647 : : .type = RTE_FLOW_ITEM_TYPE_END,
7648 : : };
7649 : 0 : struct rte_flow_action_jump jump = {
7650 : : .group = 1,
7651 : : };
7652 : 0 : const struct rte_flow_action actions[] = {
7653 : : {
7654 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
7655 : : .conf = &jump,
7656 : : },
7657 : : {
7658 : : .type = RTE_FLOW_ACTION_TYPE_END,
7659 : : },
7660 : : };
7661 : : struct rte_flow_error error;
7662 : :
7663 : 0 : return (void *)(uintptr_t)mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
7664 : : &attr, &pattern,
7665 : : actions, false, &error);
7666 : : }
7667 : :
7668 : : /**
7669 : : * Create a dedicated flow rule on e-switch table 1, matches ESW manager
7670 : : * and sq number, directs all packets to peer vport.
7671 : : *
7672 : : * @param dev
7673 : : * Pointer to Ethernet device.
7674 : : * @param sq_num
7675 : : * SQ number.
7676 : : *
7677 : : * @return
7678 : : * Flow ID on success, 0 otherwise and rte_errno is set.
7679 : : */
7680 : : uint32_t
7681 : 0 : mlx5_flow_create_devx_sq_miss_flow(struct rte_eth_dev *dev, uint32_t sq_num)
7682 : : {
7683 : 0 : struct rte_flow_attr attr = {
7684 : : .group = 0,
7685 : : .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
7686 : : .ingress = 0,
7687 : : .egress = 0,
7688 : : .transfer = 1,
7689 : : };
7690 : 0 : struct rte_flow_item_port_id port_spec = {
7691 : : .id = MLX5_PORT_ESW_MGR,
7692 : : };
7693 : 0 : struct mlx5_rte_flow_item_sq sq_spec = {
7694 : : .queue = sq_num,
7695 : : };
7696 : 0 : struct rte_flow_item pattern[] = {
7697 : : {
7698 : : .type = RTE_FLOW_ITEM_TYPE_PORT_ID,
7699 : : .spec = &port_spec,
7700 : : },
7701 : : {
7702 : : .type = (enum rte_flow_item_type)
7703 : : MLX5_RTE_FLOW_ITEM_TYPE_SQ,
7704 : : .spec = &sq_spec,
7705 : : },
7706 : : {
7707 : : .type = RTE_FLOW_ITEM_TYPE_END,
7708 : : },
7709 : : };
7710 : 0 : struct rte_flow_action_jump jump = {
7711 : : .group = 1,
7712 : : };
7713 : 0 : struct rte_flow_action_port_id port = {
7714 : 0 : .id = dev->data->port_id,
7715 : : };
7716 : 0 : struct rte_flow_action actions[] = {
7717 : : {
7718 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
7719 : : .conf = &jump,
7720 : : },
7721 : : {
7722 : : .type = RTE_FLOW_ACTION_TYPE_END,
7723 : : },
7724 : : };
7725 : : struct rte_flow_error error;
7726 : :
7727 : : /*
7728 : : * Creates group 0, highest priority jump flow.
7729 : : * Matches txq to bypass kernel packets.
7730 : : */
7731 [ # # ]: 0 : if (mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_CTL, &attr, pattern, actions,
7732 : : false, &error) == 0)
7733 : : return 0;
7734 : : /* Create group 1, lowest priority redirect flow for txq. */
7735 : 0 : attr.group = 1;
7736 : 0 : actions[0].conf = &port;
7737 : 0 : actions[0].type = RTE_FLOW_ACTION_TYPE_PORT_ID;
7738 : 0 : return mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_CTL, &attr, pattern,
7739 : : actions, false, &error);
7740 : : }
7741 : :
7742 : : /**
7743 : : * Validate a flow supported by the NIC.
7744 : : *
7745 : : * @see rte_flow_validate()
7746 : : * @see rte_flow_ops
7747 : : */
7748 : : int
7749 : 0 : mlx5_flow_validate(struct rte_eth_dev *dev,
7750 : : const struct rte_flow_attr *attr,
7751 : : const struct rte_flow_item items[],
7752 : : const struct rte_flow_action original_actions[],
7753 : : struct rte_flow_error *error)
7754 : : {
7755 : : int hairpin_flow;
7756 : : struct mlx5_translated_action_handle
7757 : : indir_actions[MLX5_MAX_INDIRECT_ACTIONS];
7758 : 0 : int indir_actions_n = MLX5_MAX_INDIRECT_ACTIONS;
7759 : : const struct rte_flow_action *actions;
7760 : 0 : struct rte_flow_action *translated_actions = NULL;
7761 : 0 : int ret = flow_action_handles_translate(dev, original_actions,
7762 : : indir_actions,
7763 : : &indir_actions_n,
7764 : : &translated_actions, error);
7765 : :
7766 [ # # ]: 0 : if (ret)
7767 : : return ret;
7768 [ # # ]: 0 : actions = translated_actions ? translated_actions : original_actions;
7769 : 0 : hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
7770 : 0 : ret = flow_drv_validate(dev, attr, items, actions,
7771 : : true, hairpin_flow, error);
7772 : 0 : rte_free(translated_actions);
7773 : 0 : return ret;
7774 : : }
7775 : :
7776 : : static int
7777 : 0 : mlx5_flow_cache_flow_info(struct rte_eth_dev *dev,
7778 : : const struct rte_flow_attr *attr,
7779 : : const uint32_t orig_prio,
7780 : : const struct rte_flow_item *items,
7781 : : const struct rte_flow_action *actions,
7782 : : uint32_t flow_idx)
7783 : : {
7784 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7785 : : struct rte_pmd_mlx5_flow_engine_mode_info *mode_info = &priv->mode_info;
7786 : : struct mlx5_dv_flow_info *flow_info, *tmp_info;
7787 : : struct rte_flow_error error;
7788 : : int len, ret;
7789 : :
7790 : 0 : flow_info = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*flow_info), 0, SOCKET_ID_ANY);
7791 [ # # ]: 0 : if (!flow_info) {
7792 : 0 : DRV_LOG(ERR, "No enough memory for flow_info caching.");
7793 : 0 : return -1;
7794 : : }
7795 : 0 : flow_info->orig_prio = orig_prio;
7796 : 0 : flow_info->attr = *attr;
7797 : : /* Standby mode rule awlays saves it in low priority entry. */
7798 : 0 : flow_info->flow_idx_low_prio = flow_idx;
7799 : :
7800 : : /* Store matching items. */
7801 : 0 : ret = rte_flow_conv(RTE_FLOW_CONV_OP_PATTERN, NULL, 0, items, &error);
7802 [ # # ]: 0 : if (ret <= 0) {
7803 : 0 : DRV_LOG(ERR, "Can't get items length.");
7804 : 0 : goto end;
7805 : : }
7806 : 0 : len = RTE_ALIGN(ret, 16);
7807 : 0 : flow_info->items = mlx5_malloc(MLX5_MEM_ZERO, len, 0, SOCKET_ID_ANY);
7808 [ # # ]: 0 : if (!flow_info->items) {
7809 : 0 : DRV_LOG(ERR, "No enough memory for items caching.");
7810 : 0 : goto end;
7811 : : }
7812 : 0 : ret = rte_flow_conv(RTE_FLOW_CONV_OP_PATTERN, flow_info->items, ret, items, &error);
7813 [ # # ]: 0 : if (ret <= 0) {
7814 : 0 : DRV_LOG(ERR, "Can't duplicate items.");
7815 : 0 : goto end;
7816 : : }
7817 : :
7818 : : /* Store flow actions. */
7819 : 0 : ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTIONS, NULL, 0, actions, &error);
7820 [ # # ]: 0 : if (ret <= 0) {
7821 : 0 : DRV_LOG(ERR, "Can't get actions length.");
7822 : 0 : goto end;
7823 : : }
7824 : 0 : len = RTE_ALIGN(ret, 16);
7825 : 0 : flow_info->actions = mlx5_malloc(MLX5_MEM_ZERO, len, 0, SOCKET_ID_ANY);
7826 [ # # ]: 0 : if (!flow_info->actions) {
7827 : 0 : DRV_LOG(ERR, "No enough memory for actions caching.");
7828 : 0 : goto end;
7829 : : }
7830 : 0 : ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTIONS, flow_info->actions, ret, actions, &error);
7831 [ # # ]: 0 : if (ret <= 0) {
7832 : 0 : DRV_LOG(ERR, "Can't duplicate actions.");
7833 : 0 : goto end;
7834 : : }
7835 : :
7836 : : /* Insert to the list end. */
7837 [ # # ]: 0 : if (LIST_EMPTY(&mode_info->hot_upgrade)) {
7838 : 0 : LIST_INSERT_HEAD(&mode_info->hot_upgrade, flow_info, next);
7839 : : } else {
7840 : : tmp_info = LIST_FIRST(&mode_info->hot_upgrade);
7841 [ # # ]: 0 : while (LIST_NEXT(tmp_info, next))
7842 : : tmp_info = LIST_NEXT(tmp_info, next);
7843 : 0 : LIST_INSERT_AFTER(tmp_info, flow_info, next);
7844 : : }
7845 : : return 0;
7846 : 0 : end:
7847 [ # # ]: 0 : if (flow_info->items)
7848 : 0 : mlx5_free(flow_info->items);
7849 [ # # ]: 0 : if (flow_info->actions)
7850 : 0 : mlx5_free(flow_info->actions);
7851 : 0 : mlx5_free(flow_info);
7852 : 0 : return -1;
7853 : : }
7854 : :
7855 : : static int
7856 : 0 : mlx5_flow_cache_flow_toggle(struct rte_eth_dev *dev, bool orig_prio)
7857 : : {
7858 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7859 : : struct rte_pmd_mlx5_flow_engine_mode_info *mode_info = &priv->mode_info;
7860 : : struct mlx5_dv_flow_info *flow_info;
7861 : : struct rte_flow_attr attr;
7862 : : struct rte_flow_error error;
7863 : : struct rte_flow *high, *low;
7864 : :
7865 : 0 : flow_info = LIST_FIRST(&mode_info->hot_upgrade);
7866 [ # # ]: 0 : while (flow_info) {
7867 : : /* DUP flow may have the same priority. */
7868 [ # # ]: 0 : if (flow_info->orig_prio != flow_info->attr.priority) {
7869 : 0 : attr = flow_info->attr;
7870 [ # # ]: 0 : if (orig_prio)
7871 : 0 : attr.priority = flow_info->orig_prio;
7872 : 0 : flow_info->flow_idx_high_prio = mlx5_flow_list_create(dev,
7873 : : MLX5_FLOW_TYPE_GEN, &attr,
7874 : 0 : flow_info->items, flow_info->actions,
7875 : : true, &error);
7876 [ # # ]: 0 : if (!flow_info->flow_idx_high_prio) {
7877 : 0 : DRV_LOG(ERR, "Priority toggle failed internally.");
7878 : 0 : goto err;
7879 : : }
7880 : : }
7881 : 0 : flow_info = LIST_NEXT(flow_info, next);
7882 : : }
7883 : : /* Delete the low priority rules and swap the flow handle. */
7884 : 0 : flow_info = LIST_FIRST(&mode_info->hot_upgrade);
7885 [ # # ]: 0 : while (flow_info) {
7886 : : MLX5_ASSERT(flow_info->flow_idx_low_prio);
7887 [ # # ]: 0 : if (flow_info->orig_prio != flow_info->attr.priority) {
7888 : 0 : high = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
7889 : : flow_info->flow_idx_high_prio);
7890 : 0 : low = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
7891 : : flow_info->flow_idx_low_prio);
7892 [ # # ]: 0 : if (high && low) {
7893 : 0 : RTE_SWAP(*low, *high);
7894 : 0 : mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN,
7895 : 0 : flow_info->flow_idx_low_prio);
7896 : 0 : flow_info->flow_idx_high_prio = 0;
7897 : : }
7898 : : }
7899 : 0 : flow_info = LIST_NEXT(flow_info, next);
7900 : : }
7901 : : return 0;
7902 : : err:
7903 : : /* Destroy preceding successful high priority rules. */
7904 : 0 : flow_info = LIST_FIRST(&mode_info->hot_upgrade);
7905 [ # # ]: 0 : while (flow_info) {
7906 [ # # ]: 0 : if (flow_info->orig_prio != flow_info->attr.priority) {
7907 [ # # ]: 0 : if (flow_info->flow_idx_high_prio)
7908 : 0 : mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN,
7909 : : flow_info->flow_idx_high_prio);
7910 : : else
7911 : : break;
7912 : 0 : flow_info->flow_idx_high_prio = 0;
7913 : : }
7914 : 0 : flow_info = LIST_NEXT(flow_info, next);
7915 : : }
7916 : : return -1;
7917 : : }
7918 : :
7919 : : /**
7920 : : * Set the mode of the flow engine of a process to active or standby during live migration.
7921 : : *
7922 : : * @param[in] mode
7923 : : * MLX5 flow engine mode, @see `enum rte_pmd_mlx5_flow_engine_mode`.
7924 : : * @param[in] flags
7925 : : * Flow engine mode specific flags.
7926 : : *
7927 : : * @return
7928 : : * Negative value on error, positive on success.
7929 : : */
7930 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_mlx5_flow_engine_set_mode, 23.03)
7931 : : int
7932 : 0 : rte_pmd_mlx5_flow_engine_set_mode(enum rte_pmd_mlx5_flow_engine_mode mode, uint32_t flags)
7933 : : {
7934 : : struct mlx5_priv *priv;
7935 : : struct rte_pmd_mlx5_flow_engine_mode_info *mode_info;
7936 : : struct mlx5_dv_flow_info *flow_info, *tmp_info;
7937 : : uint16_t port, port_id;
7938 : : uint16_t toggle_num = 0;
7939 : : struct rte_eth_dev *dev;
7940 : : enum rte_pmd_mlx5_flow_engine_mode orig_mode;
7941 : : uint32_t orig_flags;
7942 : : bool need_toggle = false;
7943 : :
7944 : : /* Check if flags combinations are supported. */
7945 [ # # ]: 0 : if (flags && flags != RTE_PMD_MLX5_FLOW_ENGINE_FLAG_STANDBY_DUP_INGRESS) {
7946 : 0 : DRV_LOG(ERR, "Doesn't support such flags %u", flags);
7947 : 0 : return -1;
7948 : : }
7949 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port, NULL) {
7950 : 0 : dev = &rte_eth_devices[port];
7951 : 0 : priv = dev->data->dev_private;
7952 : : mode_info = &priv->mode_info;
7953 : : /* No mode change. Assume all devices hold the same mode. */
7954 [ # # ]: 0 : if (mode_info->mode == mode) {
7955 : 0 : DRV_LOG(INFO, "Process flow engine has been in mode %u", mode);
7956 [ # # # # ]: 0 : if (mode_info->mode_flag != flags && !LIST_EMPTY(&mode_info->hot_upgrade)) {
7957 : 0 : DRV_LOG(ERR, "Port %u has rule cache with different flag %u\n",
7958 : : port, mode_info->mode_flag);
7959 : 0 : orig_mode = mode_info->mode;
7960 : 0 : orig_flags = mode_info->mode_flag;
7961 : 0 : goto err;
7962 : : }
7963 : 0 : mode_info->mode_flag = flags;
7964 : 0 : toggle_num++;
7965 : 0 : continue;
7966 : : }
7967 : : /* Active -> standby. */
7968 [ # # ]: 0 : if (mode == RTE_PMD_MLX5_FLOW_ENGINE_MODE_STANDBY) {
7969 [ # # ]: 0 : if (!LIST_EMPTY(&mode_info->hot_upgrade)) {
7970 : 0 : DRV_LOG(ERR, "Cached rule existed");
7971 : 0 : orig_mode = mode_info->mode;
7972 : 0 : orig_flags = mode_info->mode_flag;
7973 : 0 : goto err;
7974 : : }
7975 : 0 : mode_info->mode_flag = flags;
7976 : 0 : mode_info->mode = mode;
7977 : 0 : toggle_num++;
7978 : : /* Standby -> active. */
7979 [ # # ]: 0 : } else if (mode == RTE_PMD_MLX5_FLOW_ENGINE_MODE_ACTIVE) {
7980 [ # # ]: 0 : if (LIST_EMPTY(&mode_info->hot_upgrade)) {
7981 : 0 : DRV_LOG(INFO, "No cached rule existed");
7982 : : } else {
7983 [ # # ]: 0 : if (mlx5_flow_cache_flow_toggle(dev, true)) {
7984 : 0 : orig_mode = mode_info->mode;
7985 : 0 : orig_flags = mode_info->mode_flag;
7986 : : need_toggle = true;
7987 : 0 : goto err;
7988 : : }
7989 : : }
7990 : 0 : toggle_num++;
7991 : : }
7992 : : }
7993 [ # # ]: 0 : if (mode == RTE_PMD_MLX5_FLOW_ENGINE_MODE_ACTIVE) {
7994 : : /* Clear cache flow rules. */
7995 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port, NULL) {
7996 : 0 : priv = rte_eth_devices[port].data->dev_private;
7997 : : mode_info = &priv->mode_info;
7998 : 0 : flow_info = LIST_FIRST(&mode_info->hot_upgrade);
7999 [ # # ]: 0 : while (flow_info) {
8000 : 0 : tmp_info = LIST_NEXT(flow_info, next);
8001 [ # # ]: 0 : LIST_REMOVE(flow_info, next);
8002 : 0 : mlx5_free(flow_info->actions);
8003 : 0 : mlx5_free(flow_info->items);
8004 : 0 : mlx5_free(flow_info);
8005 : : flow_info = tmp_info;
8006 : : }
8007 : : MLX5_ASSERT(LIST_EMPTY(&mode_info->hot_upgrade));
8008 : : }
8009 : : }
8010 : 0 : return toggle_num;
8011 : 0 : err:
8012 : : /* Rollback all preceding successful ports. */
8013 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port_id, NULL) {
8014 [ # # ]: 0 : if (port_id == port)
8015 : : break;
8016 : 0 : priv = rte_eth_devices[port_id].data->dev_private;
8017 : : mode_info = &priv->mode_info;
8018 [ # # # # : 0 : if (need_toggle && !LIST_EMPTY(&mode_info->hot_upgrade) &&
# # ]
8019 : 0 : mlx5_flow_cache_flow_toggle(dev, false))
8020 : : return -EPERM;
8021 : 0 : mode_info->mode = orig_mode;
8022 : 0 : mode_info->mode_flag = orig_flags;
8023 : : }
8024 : : return -EINVAL;
8025 : : }
8026 : : /**
8027 : : * Create a flow.
8028 : : *
8029 : : * @see rte_flow_create()
8030 : : * @see rte_flow_ops
8031 : : */
8032 : : struct rte_flow *
8033 : 0 : mlx5_flow_create(struct rte_eth_dev *dev,
8034 : : const struct rte_flow_attr *attr,
8035 : : const struct rte_flow_item items[],
8036 : : const struct rte_flow_action actions[],
8037 : : struct rte_flow_error *error)
8038 : : {
8039 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8040 : : struct rte_flow_attr *new_attr = (void *)(uintptr_t)attr;
8041 : 0 : uint32_t prio = attr->priority;
8042 : : uintptr_t flow_idx;
8043 : :
8044 : : /*
8045 : : * If the device is not started yet, it is not allowed to created a
8046 : : * flow from application. PMD default flows and traffic control flows
8047 : : * are not affected.
8048 : : */
8049 [ # # ]: 0 : if (unlikely(!dev->data->dev_started)) {
8050 : 0 : DRV_LOG(DEBUG, "port %u is not started when "
8051 : : "inserting a flow", dev->data->port_id);
8052 : 0 : rte_flow_error_set(error, ENODEV,
8053 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8054 : : NULL,
8055 : : "port not started");
8056 : 0 : return NULL;
8057 : : }
8058 [ # # ]: 0 : if (unlikely(mlx5_need_cache_flow(priv, attr))) {
8059 [ # # ]: 0 : if (attr->transfer ||
8060 [ # # # # ]: 0 : (attr->ingress && !(priv->mode_info.mode_flag &
8061 : : RTE_PMD_MLX5_FLOW_ENGINE_FLAG_STANDBY_DUP_INGRESS)))
8062 : 0 : new_attr->priority += 1;
8063 : : }
8064 : 0 : flow_idx = mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_GEN, attr, items, actions,
8065 : : true, error);
8066 [ # # ]: 0 : if (!flow_idx)
8067 : : return NULL;
8068 [ # # ]: 0 : if (unlikely(mlx5_need_cache_flow(priv, attr))) {
8069 [ # # ]: 0 : if (mlx5_flow_cache_flow_info(dev, attr, prio, items, actions, flow_idx)) {
8070 : 0 : mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN, flow_idx);
8071 : : flow_idx = 0;
8072 : : }
8073 : : }
8074 : 0 : return (void *)(uintptr_t)flow_idx;
8075 : : }
8076 : :
8077 : : uintptr_t
8078 : 0 : mlx5_flow_list_create(struct rte_eth_dev *dev, enum mlx5_flow_type type,
8079 : : const struct rte_flow_attr *attr,
8080 : : const struct rte_flow_item items[],
8081 : : const struct rte_flow_action actions[],
8082 : : bool external, struct rte_flow_error *error)
8083 : : {
8084 : : const struct mlx5_flow_driver_ops *fops;
8085 : 0 : enum mlx5_flow_drv_type drv_type = flow_get_drv_type(dev, attr);
8086 : :
8087 : 0 : fops = flow_get_drv_ops(drv_type);
8088 : 0 : return fops->list_create(dev, type, attr, items, actions, external,
8089 : : error);
8090 : : }
8091 : :
8092 : : /**
8093 : : * Destroy a flow in a list.
8094 : : *
8095 : : * @param dev
8096 : : * Pointer to Ethernet device.
8097 : : * @param[in] flow_idx
8098 : : * Index of flow to destroy.
8099 : : */
8100 : : void
8101 : 0 : mlx5_flow_legacy_list_destroy(struct rte_eth_dev *dev, enum mlx5_flow_type type,
8102 : : uintptr_t flow_idx)
8103 : : {
8104 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8105 : 0 : struct rte_flow *flow = mlx5_ipool_get(priv->flows[type], (uint32_t)flow_idx);
8106 : :
8107 [ # # ]: 0 : if (!flow)
8108 : : return;
8109 : : MLX5_ASSERT(type < MLX5_FLOW_TYPE_MAXI);
8110 : : MLX5_ASSERT(flow->type == type);
8111 : : /*
8112 : : * Update RX queue flags only if port is started, otherwise it is
8113 : : * already clean.
8114 : : */
8115 [ # # ]: 0 : if (dev->data->dev_started)
8116 : 0 : flow_rxq_flags_trim(dev, flow);
8117 : : flow_drv_destroy(dev, flow);
8118 [ # # ]: 0 : if (flow->tunnel) {
8119 : : struct mlx5_flow_tunnel *tunnel;
8120 : :
8121 : 0 : tunnel = mlx5_find_tunnel_id(dev, flow->tunnel_id);
8122 : 0 : RTE_VERIFY(tunnel);
8123 [ # # ]: 0 : if (!(rte_atomic_fetch_sub_explicit(&tunnel->refctn, 1,
8124 : : rte_memory_order_relaxed) - 1))
8125 : 0 : mlx5_flow_tunnel_free(dev, tunnel);
8126 : : }
8127 : 0 : flow_mreg_del_copy_action(dev, flow);
8128 : 0 : mlx5_ipool_free(priv->flows[type], flow_idx);
8129 : : }
8130 : :
8131 : : void
8132 [ # # ]: 0 : mlx5_flow_list_destroy(struct rte_eth_dev *dev, enum mlx5_flow_type type,
8133 : : uintptr_t flow_idx)
8134 : : {
8135 : : const struct mlx5_flow_driver_ops *fops;
8136 : : struct rte_flow_attr attr = { .transfer = 0 };
8137 : : enum mlx5_flow_drv_type drv_type = flow_get_drv_type(dev, &attr);
8138 : :
8139 : 0 : fops = flow_get_drv_ops(drv_type);
8140 : 0 : fops->list_destroy(dev, type, flow_idx);
8141 : 0 : }
8142 : :
8143 : : /**
8144 : : * Destroy all flows.
8145 : : *
8146 : : * @param dev
8147 : : * Pointer to Ethernet device.
8148 : : * @param type
8149 : : * Flow type to be flushed.
8150 : : * @param active
8151 : : * If flushing is called actively.
8152 : : */
8153 : : void
8154 : 0 : mlx5_flow_list_flush(struct rte_eth_dev *dev, enum mlx5_flow_type type,
8155 : : bool active)
8156 : : {
8157 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8158 : 0 : uint32_t num_flushed = 0, fidx = 1;
8159 : : struct rte_flow *flow;
8160 : : struct rte_pmd_mlx5_flow_engine_mode_info *mode_info = &priv->mode_info;
8161 : : struct mlx5_dv_flow_info *flow_info;
8162 : :
8163 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8164 [ # # # # ]: 0 : if (priv->sh->config.dv_flow_en == 2 &&
8165 : : type == MLX5_FLOW_TYPE_GEN) {
8166 : 0 : priv->hws_rule_flushing = true;
8167 : 0 : mlx5_flow_hw_q_flow_flush(dev, NULL);
8168 : 0 : priv->hws_rule_flushing = false;
8169 : : }
8170 : : #endif
8171 [ # # ]: 0 : MLX5_IPOOL_FOREACH(priv->flows[type], fidx, flow) {
8172 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2) {
8173 : 0 : mlx5_flow_list_destroy(dev, type, (uintptr_t)flow);
8174 : : } else {
8175 : 0 : mlx5_flow_list_destroy(dev, type, fidx);
8176 : : }
8177 [ # # # # ]: 0 : if (unlikely(mlx5_need_cache_flow(priv, NULL) && type == MLX5_FLOW_TYPE_GEN)) {
8178 : 0 : flow_info = LIST_FIRST(&mode_info->hot_upgrade);
8179 [ # # ]: 0 : while (flow_info) {
8180 : : /* Romove the cache flow info. */
8181 [ # # ]: 0 : if (flow_info->flow_idx_low_prio == (uint32_t)(uintptr_t)fidx) {
8182 : : MLX5_ASSERT(!flow_info->flow_idx_high_prio);
8183 [ # # ]: 0 : LIST_REMOVE(flow_info, next);
8184 : 0 : mlx5_free(flow_info->items);
8185 : 0 : mlx5_free(flow_info->actions);
8186 : 0 : mlx5_free(flow_info);
8187 : 0 : break;
8188 : : }
8189 : 0 : flow_info = LIST_NEXT(flow_info, next);
8190 : : }
8191 : : }
8192 : 0 : num_flushed++;
8193 : : }
8194 [ # # ]: 0 : if (active) {
8195 : 0 : DRV_LOG(INFO, "port %u: %u flows flushed before stopping",
8196 : : dev->data->port_id, num_flushed);
8197 : : }
8198 : 0 : }
8199 : :
8200 : : /**
8201 : : * Stop all default actions for flows.
8202 : : *
8203 : : * @param dev
8204 : : * Pointer to Ethernet device.
8205 : : */
8206 : : void
8207 : 0 : mlx5_flow_stop_default(struct rte_eth_dev *dev)
8208 : : {
8209 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8210 : :
8211 [ # # ]: 0 : if (mlx5_flow_is_steering_disabled())
8212 : : return;
8213 : :
8214 : : #ifdef HAVE_MLX5_HWS_SUPPORT
8215 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2) {
8216 : 0 : mlx5_flow_nta_del_default_copy_action(dev);
8217 [ # # ]: 0 : if (!rte_atomic_load_explicit(&priv->hws_mark_refcnt,
8218 : : rte_memory_order_relaxed))
8219 : 0 : mlx5_flow_hw_rxq_flag_set(dev, false);
8220 : 0 : return;
8221 : : }
8222 : : #else
8223 : : RTE_SET_USED(priv);
8224 : : #endif
8225 : 0 : flow_mreg_del_default_copy_action(dev);
8226 : 0 : mlx5_flow_rxq_flags_clear(dev);
8227 : : }
8228 : :
8229 : : /**
8230 : : * Set rxq flag.
8231 : : *
8232 : : * @param[in] dev
8233 : : * Pointer to the rte_eth_dev structure.
8234 : : * @param[in] enable
8235 : : * Flag to enable or not.
8236 : : */
8237 : : void
8238 : 0 : mlx5_flow_hw_rxq_flag_set(struct rte_eth_dev *dev, bool enable)
8239 : : {
8240 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8241 : : unsigned int i;
8242 : :
8243 [ # # # # : 0 : if ((!priv->mark_enabled && !enable) ||
# # ]
8244 [ # # ]: 0 : (priv->mark_enabled && enable))
8245 : : return;
8246 [ # # ]: 0 : for (i = 0; i < priv->rxqs_n; ++i) {
8247 : 0 : struct mlx5_rxq_ctrl *rxq_ctrl = mlx5_rxq_ctrl_get(dev, i);
8248 : :
8249 : : /* With RXQ start/stop feature, RXQ might be stopped. */
8250 [ # # ]: 0 : if (!rxq_ctrl)
8251 : 0 : continue;
8252 : 0 : rxq_ctrl->rxq.mark = enable;
8253 : : }
8254 : 0 : priv->mark_enabled = enable;
8255 : : }
8256 : :
8257 : : /**
8258 : : * Start all default actions for flows.
8259 : : *
8260 : : * @param dev
8261 : : * Pointer to Ethernet device.
8262 : : * @return
8263 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
8264 : : */
8265 : : int
8266 : 0 : mlx5_flow_start_default(struct rte_eth_dev *dev)
8267 : : {
8268 : : struct rte_flow_error error;
8269 : :
8270 [ # # ]: 0 : if (mlx5_flow_is_steering_disabled())
8271 : : return 0;
8272 : :
8273 : : #ifdef HAVE_MLX5_HWS_SUPPORT
8274 [ # # ]: 0 : if (MLX5_SH(dev)->config.dv_flow_en == 2) {
8275 : : /*
8276 : : * Ignore this failure, if the proxy port is not started, other
8277 : : * default jump actions are not created and this rule will not
8278 : : * be hit.
8279 : : */
8280 [ # # ]: 0 : if (mlx5_flow_nta_add_default_copy_action(dev, &error)) {
8281 : 0 : DRV_LOG(DEBUG, "port %u failed to start default copy action: %s",
8282 : : dev->data->port_id, strerror(rte_errno));
8283 : 0 : return 0;
8284 : : }
8285 : : }
8286 : : #endif
8287 : : /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
8288 : 0 : return flow_mreg_add_default_copy_action(dev, &error);
8289 : : }
8290 : :
8291 : : /**
8292 : : * Release key of thread specific flow workspace data.
8293 : : */
8294 : : void
8295 : 0 : mlx5_flow_release_workspace(void *data)
8296 : : {
8297 : : struct mlx5_flow_workspace *wks = data;
8298 : : struct mlx5_flow_workspace *next;
8299 : :
8300 [ # # ]: 0 : while (wks) {
8301 : 0 : next = wks->next;
8302 : 0 : free(wks);
8303 : : wks = next;
8304 : : }
8305 : 0 : }
8306 : :
8307 : : /**
8308 : : * Get thread specific current flow workspace.
8309 : : *
8310 : : * @return pointer to thread specific flow workspace data, NULL on error.
8311 : : */
8312 : : struct mlx5_flow_workspace*
8313 : 0 : mlx5_flow_get_thread_workspace(void)
8314 : : {
8315 : : struct mlx5_flow_workspace *data;
8316 : :
8317 : 0 : data = mlx5_flow_os_get_specific_workspace();
8318 : : MLX5_ASSERT(data && data->inuse);
8319 [ # # # # ]: 0 : if (!data || !data->inuse)
8320 : 0 : DRV_LOG(ERR, "flow workspace not initialized.");
8321 : 0 : return data;
8322 : : }
8323 : :
8324 : : /**
8325 : : * Allocate and init new flow workspace.
8326 : : *
8327 : : * @return pointer to flow workspace data, NULL on error.
8328 : : */
8329 : : static struct mlx5_flow_workspace*
8330 : 0 : flow_alloc_thread_workspace(void)
8331 : : {
8332 : : size_t data_size = RTE_ALIGN(sizeof(struct mlx5_flow_workspace), sizeof(long));
8333 : : size_t rss_queue_array_size = sizeof(uint16_t) * RTE_ETH_RSS_RETA_SIZE_512;
8334 : : size_t alloc_size = data_size + rss_queue_array_size;
8335 : : #ifdef HAVE_MLX5_HWS_SUPPORT
8336 : : /* Dummy table size for the non-template API. */
8337 : : alloc_size += sizeof(struct rte_flow_template_table);
8338 : : #endif
8339 : 0 : struct mlx5_flow_workspace *data = calloc(1, alloc_size);
8340 : :
8341 [ # # ]: 0 : if (!data) {
8342 : 0 : DRV_LOG(ERR, "Failed to allocate flow workspace memory.");
8343 : 0 : return NULL;
8344 : : }
8345 : 0 : data->rss_desc.queue = RTE_PTR_ADD(data, data_size);
8346 : : #ifdef HAVE_MLX5_HWS_SUPPORT
8347 : 0 : data->table = RTE_PTR_ADD(data->rss_desc.queue, rss_queue_array_size);
8348 : : #endif
8349 : 0 : return data;
8350 : : }
8351 : :
8352 : : /**
8353 : : * Get new thread specific flow workspace.
8354 : : *
8355 : : * If current workspace inuse, create new one and set as current.
8356 : : *
8357 : : * @return pointer to thread specific flow workspace data, NULL on error.
8358 : : */
8359 : : struct mlx5_flow_workspace*
8360 : 0 : mlx5_flow_push_thread_workspace(void)
8361 : : {
8362 : : struct mlx5_flow_workspace *curr;
8363 : : struct mlx5_flow_workspace *data;
8364 : :
8365 : 0 : curr = mlx5_flow_os_get_specific_workspace();
8366 [ # # ]: 0 : if (!curr) {
8367 : 0 : data = flow_alloc_thread_workspace();
8368 [ # # ]: 0 : if (!data)
8369 : : return NULL;
8370 : 0 : mlx5_flow_os_workspace_gc_add(data);
8371 [ # # ]: 0 : } else if (!curr->inuse) {
8372 : : data = curr;
8373 [ # # ]: 0 : } else if (curr->next) {
8374 : : data = curr->next;
8375 : : } else {
8376 : 0 : data = flow_alloc_thread_workspace();
8377 [ # # ]: 0 : if (!data)
8378 : : return NULL;
8379 : 0 : curr->next = data;
8380 : 0 : data->prev = curr;
8381 : : }
8382 : 0 : data->inuse = 1;
8383 : 0 : data->flow_idx = 0;
8384 : : /* Set as current workspace */
8385 [ # # ]: 0 : if (mlx5_flow_os_set_specific_workspace(data))
8386 : 0 : DRV_LOG(ERR, "Failed to set flow workspace to thread.");
8387 : : return data;
8388 : : }
8389 : :
8390 : : /**
8391 : : * Close current thread specific flow workspace.
8392 : : *
8393 : : * If previous workspace available, set it as current.
8394 : : *
8395 : : * @return pointer to thread specific flow workspace data, NULL on error.
8396 : : */
8397 : : void
8398 : 0 : mlx5_flow_pop_thread_workspace(void)
8399 : : {
8400 : 0 : struct mlx5_flow_workspace *data = mlx5_flow_get_thread_workspace();
8401 : :
8402 [ # # ]: 0 : if (!data)
8403 : : return;
8404 [ # # ]: 0 : if (!data->inuse) {
8405 : 0 : DRV_LOG(ERR, "Failed to close unused flow workspace.");
8406 : 0 : return;
8407 : : }
8408 : 0 : data->inuse = 0;
8409 [ # # ]: 0 : if (!data->prev)
8410 : : return;
8411 [ # # ]: 0 : if (mlx5_flow_os_set_specific_workspace(data->prev))
8412 : 0 : DRV_LOG(ERR, "Failed to set flow workspace to thread.");
8413 : : }
8414 : :
8415 : : /**
8416 : : * Verify the flow list is empty
8417 : : *
8418 : : * @param dev
8419 : : * Pointer to Ethernet device.
8420 : : *
8421 : : * @return the number of flows not released.
8422 : : */
8423 : : int
8424 : 0 : mlx5_flow_verify(struct rte_eth_dev *dev __rte_unused)
8425 : : {
8426 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8427 : : struct rte_flow *flow;
8428 : : uint32_t idx = 0;
8429 : : int ret = 0, i;
8430 : :
8431 [ # # ]: 0 : for (i = 0; i < MLX5_FLOW_TYPE_MAXI; i++) {
8432 [ # # ]: 0 : MLX5_IPOOL_FOREACH(priv->flows[i], idx, flow) {
8433 : 0 : DRV_LOG(DEBUG, "port %u flow %p still referenced",
8434 : : dev->data->port_id, (void *)flow);
8435 : 0 : ret++;
8436 : : }
8437 : : }
8438 : 0 : return ret;
8439 : : }
8440 : :
8441 : : /**
8442 : : * Enable default hairpin egress flow.
8443 : : *
8444 : : * @param dev
8445 : : * Pointer to Ethernet device.
8446 : : * @param sq_num
8447 : : * The SQ hw number.
8448 : : *
8449 : : * @return
8450 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
8451 : : */
8452 : : int
8453 : 0 : mlx5_ctrl_flow_source_queue(struct rte_eth_dev *dev,
8454 : : uint32_t sq_num)
8455 : : {
8456 : 0 : const struct rte_flow_attr attr = {
8457 : : .egress = 1,
8458 : : .priority = 0,
8459 : : };
8460 : 0 : struct mlx5_rte_flow_item_sq queue_spec = {
8461 : : .queue = sq_num,
8462 : : };
8463 : 0 : struct mlx5_rte_flow_item_sq queue_mask = {
8464 : : .queue = UINT32_MAX,
8465 : : };
8466 : 0 : struct rte_flow_item items[] = {
8467 : : {
8468 : : .type = (enum rte_flow_item_type)
8469 : : MLX5_RTE_FLOW_ITEM_TYPE_SQ,
8470 : : .spec = &queue_spec,
8471 : : .last = NULL,
8472 : : .mask = &queue_mask,
8473 : : },
8474 : : {
8475 : : .type = RTE_FLOW_ITEM_TYPE_END,
8476 : : },
8477 : : };
8478 : 0 : struct rte_flow_action_jump jump = {
8479 : : .group = MLX5_HAIRPIN_TX_TABLE,
8480 : : };
8481 : : struct rte_flow_action actions[2];
8482 : : uint32_t flow_idx;
8483 : : struct rte_flow_error error;
8484 : :
8485 : 0 : actions[0].type = RTE_FLOW_ACTION_TYPE_JUMP;
8486 : 0 : actions[0].conf = &jump;
8487 : 0 : actions[1].type = RTE_FLOW_ACTION_TYPE_END;
8488 : 0 : flow_idx = mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
8489 : : &attr, items, actions, false, &error);
8490 [ # # ]: 0 : if (!flow_idx) {
8491 [ # # ]: 0 : DRV_LOG(DEBUG,
8492 : : "Failed to create ctrl flow: rte_errno(%d),"
8493 : : " type(%d), message(%s)",
8494 : : rte_errno, error.type,
8495 : : error.message ? error.message : " (no stated reason)");
8496 : 0 : return -rte_errno;
8497 : : }
8498 : : return 0;
8499 : : }
8500 : :
8501 : : /**
8502 : : * Enable a control flow configured from the control plane.
8503 : : *
8504 : : * @param dev
8505 : : * Pointer to Ethernet device.
8506 : : * @param eth_spec
8507 : : * An Ethernet flow spec to apply.
8508 : : * @param eth_mask
8509 : : * An Ethernet flow mask to apply.
8510 : : * @param vlan_spec
8511 : : * A VLAN flow spec to apply.
8512 : : * @param vlan_mask
8513 : : * A VLAN flow mask to apply.
8514 : : *
8515 : : * @return
8516 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
8517 : : */
8518 : : int
8519 : 0 : mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
8520 : : struct rte_flow_item_eth *eth_spec,
8521 : : struct rte_flow_item_eth *eth_mask,
8522 : : struct rte_flow_item_vlan *vlan_spec,
8523 : : struct rte_flow_item_vlan *vlan_mask)
8524 : : {
8525 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8526 : 0 : const struct rte_flow_attr attr = {
8527 : : .ingress = 1,
8528 : : .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
8529 : : };
8530 : 0 : struct rte_flow_item items[] = {
8531 : : {
8532 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
8533 : : .spec = eth_spec,
8534 : : .last = NULL,
8535 : : .mask = eth_mask,
8536 : : },
8537 : : {
8538 [ # # ]: 0 : .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
8539 : : RTE_FLOW_ITEM_TYPE_END,
8540 : : .spec = vlan_spec,
8541 : : .last = NULL,
8542 : : .mask = vlan_mask,
8543 : : },
8544 : : {
8545 : : .type = RTE_FLOW_ITEM_TYPE_END,
8546 : : },
8547 : : };
8548 : 0 : uint16_t *queue = alloca(sizeof(uint16_t) * priv->reta_idx_n);
8549 : 0 : struct rte_flow_action_rss action_rss = {
8550 : : .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
8551 : : .level = 0,
8552 : 0 : .types = priv->rss_conf.rss_hf,
8553 : 0 : .key_len = priv->rss_conf.rss_key_len,
8554 : : .queue_num = priv->reta_idx_n,
8555 : 0 : .key = priv->rss_conf.rss_key,
8556 : : .queue = queue,
8557 : : };
8558 : 0 : struct rte_flow_action actions[] = {
8559 : : {
8560 : : .type = RTE_FLOW_ACTION_TYPE_RSS,
8561 : : .conf = &action_rss,
8562 : : },
8563 : : {
8564 : : .type = RTE_FLOW_ACTION_TYPE_END,
8565 : : },
8566 : : };
8567 : : uintptr_t flow_idx;
8568 : : struct rte_flow_error error;
8569 : : struct mlx5_ctrl_flow_entry *entry;
8570 : : unsigned int i;
8571 : :
8572 [ # # # # ]: 0 : if (!priv->reta_idx_n || !priv->rxqs_n) {
8573 : : return 0;
8574 : : }
8575 [ # # ]: 0 : if (!(dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG))
8576 : 0 : action_rss.types = 0;
8577 [ # # ]: 0 : for (i = 0; i != priv->reta_idx_n; ++i)
8578 : 0 : queue[i] = (*priv->reta_idx)[i];
8579 : :
8580 : 0 : entry = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*entry), alignof(typeof(*entry)), SOCKET_ID_ANY);
8581 [ # # ]: 0 : if (entry == NULL) {
8582 : 0 : rte_errno = ENOMEM;
8583 : 0 : goto err;
8584 : : }
8585 : :
8586 : 0 : entry->owner_dev = dev;
8587 [ # # ]: 0 : if (vlan_spec == NULL) {
8588 : 0 : entry->info.type = MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC;
8589 : : } else {
8590 : 0 : entry->info.type = MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC_VLAN;
8591 [ # # ]: 0 : entry->info.uc.vlan = rte_be_to_cpu_16(vlan_spec->hdr.vlan_tci);
8592 : : }
8593 : 0 : entry->info.uc.dmac = eth_spec->hdr.dst_addr;
8594 : :
8595 : 0 : flow_idx = mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
8596 : : &attr, items, actions, false, &error);
8597 [ # # ]: 0 : if (!flow_idx) {
8598 : 0 : mlx5_free(entry);
8599 : 0 : goto err;
8600 : : }
8601 : :
8602 : 0 : entry->flow = (struct rte_flow *)flow_idx;
8603 [ # # ]: 0 : LIST_INSERT_HEAD(&priv->hw_ctrl_flows, entry, next);
8604 : :
8605 : 0 : return 0;
8606 : :
8607 : 0 : err:
8608 : 0 : return -rte_errno;
8609 : : }
8610 : :
8611 : : /**
8612 : : * Enable a flow control configured from the control plane.
8613 : : *
8614 : : * @param dev
8615 : : * Pointer to Ethernet device.
8616 : : * @param eth_spec
8617 : : * An Ethernet flow spec to apply.
8618 : : * @param eth_mask
8619 : : * An Ethernet flow mask to apply.
8620 : : *
8621 : : * @return
8622 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
8623 : : */
8624 : : int
8625 : 0 : mlx5_ctrl_flow(struct rte_eth_dev *dev,
8626 : : struct rte_flow_item_eth *eth_spec,
8627 : : struct rte_flow_item_eth *eth_mask)
8628 : : {
8629 : 0 : return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
8630 : : }
8631 : :
8632 : : int
8633 : 0 : mlx5_legacy_dmac_flow_create(struct rte_eth_dev *dev, const struct rte_ether_addr *addr)
8634 : : {
8635 : 0 : struct rte_flow_item_eth unicast = {
8636 : : .hdr.dst_addr = *addr,
8637 : : };
8638 : 0 : struct rte_flow_item_eth unicast_mask = {
8639 : : .hdr.dst_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
8640 : : };
8641 : :
8642 : 0 : return mlx5_ctrl_flow(dev, &unicast, &unicast_mask);
8643 : : }
8644 : :
8645 : : int
8646 : 0 : mlx5_legacy_dmac_vlan_flow_create(struct rte_eth_dev *dev,
8647 : : const struct rte_ether_addr *addr,
8648 : : const uint16_t vid)
8649 : : {
8650 : 0 : struct rte_flow_item_eth unicast_spec = {
8651 : : .hdr.dst_addr = *addr,
8652 : : };
8653 : 0 : struct rte_flow_item_eth unicast_mask = {
8654 : : .hdr.dst_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
8655 : : };
8656 : 0 : struct rte_flow_item_vlan vlan_spec = {
8657 [ # # ]: 0 : .hdr.vlan_tci = rte_cpu_to_be_16(vid),
8658 : : };
8659 : 0 : struct rte_flow_item_vlan vlan_mask = rte_flow_item_vlan_mask;
8660 : :
8661 : 0 : return mlx5_ctrl_flow_vlan(dev, &unicast_spec, &unicast_mask, &vlan_spec, &vlan_mask);
8662 : : }
8663 : :
8664 : : void
8665 : 0 : mlx5_legacy_ctrl_flow_destroy(struct rte_eth_dev *dev, struct mlx5_ctrl_flow_entry *entry)
8666 : : {
8667 : : uintptr_t flow_idx;
8668 : :
8669 : 0 : flow_idx = (uintptr_t)entry->flow;
8670 : 0 : mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_CTL, flow_idx);
8671 [ # # ]: 0 : LIST_REMOVE(entry, next);
8672 : 0 : mlx5_free(entry);
8673 : 0 : }
8674 : :
8675 : : int
8676 : 0 : mlx5_legacy_dmac_flow_destroy(struct rte_eth_dev *dev, const struct rte_ether_addr *addr)
8677 : : {
8678 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8679 : : struct mlx5_ctrl_flow_entry *entry;
8680 : :
8681 [ # # ]: 0 : LIST_FOREACH(entry, &priv->hw_ctrl_flows, next) {
8682 [ # # # # ]: 0 : if (entry->info.type != MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC ||
8683 : : !rte_is_same_ether_addr(addr, &entry->info.uc.dmac))
8684 : : continue;
8685 : :
8686 : 0 : mlx5_legacy_ctrl_flow_destroy(dev, entry);
8687 : 0 : return 0;
8688 : : }
8689 : : return 0;
8690 : : }
8691 : :
8692 : : int
8693 : 0 : mlx5_legacy_dmac_vlan_flow_destroy(struct rte_eth_dev *dev,
8694 : : const struct rte_ether_addr *addr,
8695 : : const uint16_t vid)
8696 : : {
8697 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8698 : : struct mlx5_ctrl_flow_entry *entry;
8699 : :
8700 [ # # ]: 0 : LIST_FOREACH(entry, &priv->hw_ctrl_flows, next) {
8701 [ # # # # ]: 0 : if (entry->info.type != MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC_VLAN ||
8702 : 0 : !rte_is_same_ether_addr(addr, &entry->info.uc.dmac) ||
8703 [ # # ]: 0 : vid != entry->info.uc.vlan)
8704 : : continue;
8705 : :
8706 : 0 : mlx5_legacy_ctrl_flow_destroy(dev, entry);
8707 : 0 : return 0;
8708 : : }
8709 : : return 0;
8710 : : }
8711 : :
8712 : : /**
8713 : : * Create default miss flow rule matching lacp traffic
8714 : : *
8715 : : * @param dev
8716 : : * Pointer to Ethernet device.
8717 : : * @param eth_spec
8718 : : * An Ethernet flow spec to apply.
8719 : : *
8720 : : * @return
8721 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
8722 : : */
8723 : : int
8724 : 0 : mlx5_flow_lacp_miss(struct rte_eth_dev *dev)
8725 : : {
8726 : : /*
8727 : : * The LACP matching is done by only using ether type since using
8728 : : * a multicast dst mac causes kernel to give low priority to this flow.
8729 : : */
8730 : : static const struct rte_flow_item_eth lacp_spec = {
8731 : : .hdr.ether_type = RTE_BE16(0x8809),
8732 : : };
8733 : : static const struct rte_flow_item_eth lacp_mask = {
8734 : : .hdr.ether_type = 0xffff,
8735 : : };
8736 : 0 : const struct rte_flow_attr attr = {
8737 : : .ingress = 1,
8738 : : };
8739 : 0 : struct rte_flow_item items[] = {
8740 : : {
8741 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
8742 : : .spec = &lacp_spec,
8743 : : .mask = &lacp_mask,
8744 : : },
8745 : : {
8746 : : .type = RTE_FLOW_ITEM_TYPE_END,
8747 : : },
8748 : : };
8749 : 0 : struct rte_flow_action actions[] = {
8750 : : {
8751 : : .type = (enum rte_flow_action_type)
8752 : : MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
8753 : : },
8754 : : {
8755 : : .type = RTE_FLOW_ACTION_TYPE_END,
8756 : : },
8757 : : };
8758 : : struct rte_flow_error error;
8759 : 0 : uint32_t flow_idx = mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
8760 : : &attr, items, actions,
8761 : : false, &error);
8762 : :
8763 [ # # ]: 0 : if (!flow_idx)
8764 : 0 : return -rte_errno;
8765 : : return 0;
8766 : : }
8767 : :
8768 : : /**
8769 : : * Destroy a flow.
8770 : : *
8771 : : * @see rte_flow_destroy()
8772 : : * @see rte_flow_ops
8773 : : */
8774 : : int
8775 : 0 : mlx5_flow_destroy(struct rte_eth_dev *dev,
8776 : : struct rte_flow *flow,
8777 : : struct rte_flow_error *error __rte_unused)
8778 : : {
8779 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8780 : : struct rte_pmd_mlx5_flow_engine_mode_info *mode_info = &priv->mode_info;
8781 : : struct mlx5_dv_flow_info *flow_info;
8782 : :
8783 : 0 : mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN,
8784 : : (uintptr_t)(void *)flow);
8785 [ # # ]: 0 : if (unlikely(mlx5_need_cache_flow(priv, NULL))) {
8786 : 0 : flow_info = LIST_FIRST(&mode_info->hot_upgrade);
8787 [ # # ]: 0 : while (flow_info) {
8788 : : /* Romove the cache flow info. */
8789 [ # # ]: 0 : if (flow_info->flow_idx_low_prio == (uint32_t)(uintptr_t)flow) {
8790 : : MLX5_ASSERT(!flow_info->flow_idx_high_prio);
8791 [ # # ]: 0 : LIST_REMOVE(flow_info, next);
8792 : 0 : mlx5_free(flow_info->items);
8793 : 0 : mlx5_free(flow_info->actions);
8794 : 0 : mlx5_free(flow_info);
8795 : 0 : break;
8796 : : }
8797 : 0 : flow_info = LIST_NEXT(flow_info, next);
8798 : : }
8799 : : }
8800 : 0 : return 0;
8801 : : }
8802 : :
8803 : : /**
8804 : : * Destroy all flows.
8805 : : *
8806 : : * @see rte_flow_flush()
8807 : : * @see rte_flow_ops
8808 : : */
8809 : : int
8810 : 0 : mlx5_flow_flush(struct rte_eth_dev *dev,
8811 : : struct rte_flow_error *error __rte_unused)
8812 : : {
8813 : 0 : mlx5_flow_list_flush(dev, MLX5_FLOW_TYPE_GEN, false);
8814 : 0 : return 0;
8815 : : }
8816 : :
8817 : : /**
8818 : : * Isolated mode.
8819 : : *
8820 : : * @see rte_flow_isolate()
8821 : : * @see rte_flow_ops
8822 : : */
8823 : : int
8824 : 0 : mlx5_flow_isolate(struct rte_eth_dev *dev,
8825 : : int enable,
8826 : : struct rte_flow_error *error)
8827 : : {
8828 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8829 : :
8830 [ # # ]: 0 : if (dev->data->dev_started) {
8831 : 0 : rte_flow_error_set(error, EBUSY,
8832 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8833 : : NULL,
8834 : : "port must be stopped first");
8835 : 0 : return -rte_errno;
8836 : : }
8837 : :
8838 : 0 : priv->isolated = !!enable;
8839 [ # # ]: 0 : if (enable)
8840 : 0 : dev->dev_ops = &mlx5_dev_ops_isolate;
8841 : : else
8842 : 0 : dev->dev_ops = &mlx5_dev_ops;
8843 : :
8844 : 0 : dev->rx_descriptor_status = mlx5_rx_descriptor_status;
8845 : 0 : dev->tx_descriptor_status = mlx5_tx_descriptor_status;
8846 : :
8847 : 0 : return 0;
8848 : : }
8849 : :
8850 : : /**
8851 : : * Query a flow.
8852 : : *
8853 : : * @see rte_flow_query()
8854 : : * @see rte_flow_ops
8855 : : */
8856 : : static int
8857 : 0 : flow_drv_query(struct rte_eth_dev *dev,
8858 : : struct rte_flow *eflow,
8859 : : const struct rte_flow_action *actions,
8860 : : void *data,
8861 : : struct rte_flow_error *error)
8862 : : {
8863 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8864 : : const struct mlx5_flow_driver_ops *fops;
8865 : : struct rte_flow *flow = NULL;
8866 : : enum mlx5_flow_drv_type ftype = MLX5_FLOW_TYPE_MIN;
8867 : :
8868 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2) {
8869 : : #ifdef HAVE_MLX5_HWS_SUPPORT
8870 : : flow = eflow;
8871 : : ftype = MLX5_FLOW_TYPE_HW;
8872 : : #endif
8873 : : } else {
8874 : 0 : flow = (struct rte_flow *)mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
8875 : : (uintptr_t)(void *)eflow);
8876 : : }
8877 [ # # ]: 0 : if (!flow) {
8878 : 0 : return rte_flow_error_set(error, ENOENT,
8879 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8880 : : NULL,
8881 : : "invalid flow handle");
8882 : : }
8883 [ # # ]: 0 : if (ftype == MLX5_FLOW_TYPE_MIN)
8884 : 0 : ftype = flow->drv_type;
8885 : : MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX);
8886 : 0 : fops = flow_get_drv_ops(ftype);
8887 : :
8888 : 0 : return fops->query(dev, flow, actions, data, error);
8889 : : }
8890 : :
8891 : : /**
8892 : : * Query a flow.
8893 : : *
8894 : : * @see rte_flow_query()
8895 : : * @see rte_flow_ops
8896 : : */
8897 : : int
8898 : 0 : mlx5_flow_query(struct rte_eth_dev *dev,
8899 : : struct rte_flow *flow,
8900 : : const struct rte_flow_action *actions,
8901 : : void *data,
8902 : : struct rte_flow_error *error)
8903 : : {
8904 : : int ret;
8905 : :
8906 : 0 : ret = flow_drv_query(dev, flow, actions, data,
8907 : : error);
8908 : : if (ret < 0)
8909 : : return ret;
8910 : : return 0;
8911 : : }
8912 : :
8913 : : /**
8914 : : * Get rte_flow callbacks.
8915 : : *
8916 : : * @param dev
8917 : : * Pointer to Ethernet device structure.
8918 : : * @param ops
8919 : : * Pointer to operation-specific structure.
8920 : : *
8921 : : * @return 0
8922 : : */
8923 : : int
8924 : 0 : mlx5_flow_ops_get(struct rte_eth_dev *dev __rte_unused,
8925 : : const struct rte_flow_ops **ops)
8926 : : {
8927 [ # # ]: 0 : if (mlx5_flow_is_steering_disabled()) {
8928 : 0 : DRV_LOG(WARNING, "port %u flow API is not supported since steering was disabled",
8929 : : dev->data->port_id);
8930 : 0 : *ops = NULL;
8931 : 0 : return 0;
8932 : : }
8933 : :
8934 : 0 : *ops = &mlx5_flow_ops;
8935 : 0 : return 0;
8936 : : }
8937 : :
8938 : : /**
8939 : : * Validate meter policy actions.
8940 : : * Dispatcher for action type specific validation.
8941 : : *
8942 : : * @param[in] dev
8943 : : * Pointer to the Ethernet device structure.
8944 : : * @param[in] action
8945 : : * The meter policy action object to validate.
8946 : : * @param[in] attr
8947 : : * Attributes of flow to determine steering domain.
8948 : : * @param[out] is_rss
8949 : : * Is RSS or not.
8950 : : * @param[out] domain_bitmap
8951 : : * Domain bitmap.
8952 : : * @param[out] is_def_policy
8953 : : * Is default policy or not.
8954 : : * @param[out] error
8955 : : * Perform verbose error reporting if not NULL. Initialized in case of
8956 : : * error only.
8957 : : *
8958 : : * @return
8959 : : * 0 on success, otherwise negative errno value.
8960 : : */
8961 : : int
8962 : 0 : mlx5_flow_validate_mtr_acts(struct rte_eth_dev *dev,
8963 : : const struct rte_flow_action *actions[RTE_COLORS],
8964 : : struct rte_flow_attr *attr,
8965 : : bool *is_rss,
8966 : : uint8_t *domain_bitmap,
8967 : : uint8_t *policy_mode,
8968 : : struct rte_mtr_error *error)
8969 : : {
8970 : : const struct mlx5_flow_driver_ops *fops;
8971 : :
8972 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
8973 : 0 : return fops->validate_mtr_acts(dev, actions, attr, is_rss,
8974 : : domain_bitmap, policy_mode, error);
8975 : : }
8976 : :
8977 : : /**
8978 : : * Destroy the meter table set.
8979 : : *
8980 : : * @param[in] dev
8981 : : * Pointer to Ethernet device.
8982 : : * @param[in] mtr_policy
8983 : : * Meter policy struct.
8984 : : */
8985 : : void
8986 : 0 : mlx5_flow_destroy_mtr_acts(struct rte_eth_dev *dev,
8987 : : struct mlx5_flow_meter_policy *mtr_policy)
8988 : : {
8989 : : const struct mlx5_flow_driver_ops *fops;
8990 : :
8991 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
8992 : 0 : fops->destroy_mtr_acts(dev, mtr_policy);
8993 : 0 : }
8994 : :
8995 : : /**
8996 : : * Create policy action, lock free,
8997 : : * (mutex should be acquired by caller).
8998 : : * Dispatcher for action type specific call.
8999 : : *
9000 : : * @param[in] dev
9001 : : * Pointer to the Ethernet device structure.
9002 : : * @param[in] mtr_policy
9003 : : * Meter policy struct.
9004 : : * @param[in] action
9005 : : * Action specification used to create meter actions.
9006 : : * @param[in] attr
9007 : : * Flow rule attributes.
9008 : : * @param[out] error
9009 : : * Perform verbose error reporting if not NULL. Initialized in case of
9010 : : * error only.
9011 : : *
9012 : : * @return
9013 : : * 0 on success, otherwise negative errno value.
9014 : : */
9015 : : int
9016 : 0 : mlx5_flow_create_mtr_acts(struct rte_eth_dev *dev,
9017 : : struct mlx5_flow_meter_policy *mtr_policy,
9018 : : const struct rte_flow_action *actions[RTE_COLORS],
9019 : : struct rte_flow_attr *attr,
9020 : : struct rte_mtr_error *error)
9021 : : {
9022 : : const struct mlx5_flow_driver_ops *fops;
9023 : :
9024 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9025 : 0 : return fops->create_mtr_acts(dev, mtr_policy, actions, attr, error);
9026 : : }
9027 : :
9028 : : /**
9029 : : * Create policy rules, lock free,
9030 : : * (mutex should be acquired by caller).
9031 : : * Dispatcher for action type specific call.
9032 : : *
9033 : : * @param[in] dev
9034 : : * Pointer to the Ethernet device structure.
9035 : : * @param[in] mtr_policy
9036 : : * Meter policy struct.
9037 : : *
9038 : : * @return
9039 : : * 0 on success, -1 otherwise.
9040 : : */
9041 : : int
9042 : 0 : mlx5_flow_create_policy_rules(struct rte_eth_dev *dev,
9043 : : struct mlx5_flow_meter_policy *mtr_policy)
9044 : : {
9045 : : const struct mlx5_flow_driver_ops *fops;
9046 : :
9047 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9048 : 0 : return fops->create_policy_rules(dev, mtr_policy);
9049 : : }
9050 : :
9051 : : /**
9052 : : * Destroy policy rules, lock free,
9053 : : * (mutex should be acquired by caller).
9054 : : * Dispatcher for action type specific call.
9055 : : *
9056 : : * @param[in] dev
9057 : : * Pointer to the Ethernet device structure.
9058 : : * @param[in] mtr_policy
9059 : : * Meter policy struct.
9060 : : */
9061 : : void
9062 : 0 : mlx5_flow_destroy_policy_rules(struct rte_eth_dev *dev,
9063 : : struct mlx5_flow_meter_policy *mtr_policy)
9064 : : {
9065 : : const struct mlx5_flow_driver_ops *fops;
9066 : :
9067 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9068 : 0 : fops->destroy_policy_rules(dev, mtr_policy);
9069 : 0 : }
9070 : :
9071 : : /**
9072 : : * Destroy the default policy table set.
9073 : : *
9074 : : * @param[in] dev
9075 : : * Pointer to Ethernet device.
9076 : : */
9077 : : void
9078 : 0 : mlx5_flow_destroy_def_policy(struct rte_eth_dev *dev)
9079 : : {
9080 : : const struct mlx5_flow_driver_ops *fops;
9081 : :
9082 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9083 : 0 : fops->destroy_def_policy(dev);
9084 : 0 : }
9085 : :
9086 : : /**
9087 : : * Destroy the default policy table set.
9088 : : *
9089 : : * @param[in] dev
9090 : : * Pointer to Ethernet device.
9091 : : *
9092 : : * @return
9093 : : * 0 on success, -1 otherwise.
9094 : : */
9095 : : int
9096 : 0 : mlx5_flow_create_def_policy(struct rte_eth_dev *dev)
9097 : : {
9098 : : const struct mlx5_flow_driver_ops *fops;
9099 : :
9100 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9101 : 0 : return fops->create_def_policy(dev);
9102 : : }
9103 : :
9104 : : /**
9105 : : * Create the needed meter and suffix tables.
9106 : : *
9107 : : * @param[in] dev
9108 : : * Pointer to Ethernet device.
9109 : : *
9110 : : * @return
9111 : : * 0 on success, -1 otherwise.
9112 : : */
9113 : : int
9114 : 0 : mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
9115 : : struct mlx5_flow_meter_info *fm,
9116 : : uint32_t mtr_idx,
9117 : : uint8_t domain_bitmap)
9118 : : {
9119 : : const struct mlx5_flow_driver_ops *fops;
9120 : :
9121 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9122 : 0 : return fops->create_mtr_tbls(dev, fm, mtr_idx, domain_bitmap);
9123 : : }
9124 : :
9125 : : /**
9126 : : * Destroy the meter table set.
9127 : : *
9128 : : * @param[in] dev
9129 : : * Pointer to Ethernet device.
9130 : : * @param[in] tbl
9131 : : * Pointer to the meter table set.
9132 : : */
9133 : : void
9134 : 0 : mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
9135 : : struct mlx5_flow_meter_info *fm)
9136 : : {
9137 : : const struct mlx5_flow_driver_ops *fops;
9138 : :
9139 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9140 : 0 : fops->destroy_mtr_tbls(dev, fm);
9141 : 0 : }
9142 : :
9143 : : /**
9144 : : * Destroy the global meter drop table.
9145 : : *
9146 : : * @param[in] dev
9147 : : * Pointer to Ethernet device.
9148 : : */
9149 : : void
9150 : 0 : mlx5_flow_destroy_mtr_drop_tbls(struct rte_eth_dev *dev)
9151 : : {
9152 : : const struct mlx5_flow_driver_ops *fops;
9153 : :
9154 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9155 : 0 : fops->destroy_mtr_drop_tbls(dev);
9156 : 0 : }
9157 : :
9158 : : /**
9159 : : * Destroy the sub policy table with RX queue.
9160 : : *
9161 : : * @param[in] dev
9162 : : * Pointer to Ethernet device.
9163 : : * @param[in] mtr_policy
9164 : : * Pointer to meter policy table.
9165 : : */
9166 : : void
9167 : 0 : mlx5_flow_destroy_sub_policy_with_rxq(struct rte_eth_dev *dev,
9168 : : struct mlx5_flow_meter_policy *mtr_policy)
9169 : : {
9170 : : const struct mlx5_flow_driver_ops *fops;
9171 : :
9172 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9173 : 0 : fops->destroy_sub_policy_with_rxq(dev, mtr_policy);
9174 : 0 : }
9175 : :
9176 : : /**
9177 : : * Allocate the needed aso flow meter id.
9178 : : *
9179 : : * @param[in] dev
9180 : : * Pointer to Ethernet device.
9181 : : *
9182 : : * @return
9183 : : * Index to aso flow meter on success, NULL otherwise.
9184 : : */
9185 : : uint32_t
9186 : 0 : mlx5_flow_mtr_alloc(struct rte_eth_dev *dev)
9187 : : {
9188 : : const struct mlx5_flow_driver_ops *fops;
9189 : :
9190 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9191 : 0 : return fops->create_meter(dev);
9192 : : }
9193 : :
9194 : : /**
9195 : : * Free the aso flow meter id.
9196 : : *
9197 : : * @param[in] dev
9198 : : * Pointer to Ethernet device.
9199 : : * @param[in] mtr_idx
9200 : : * Index to aso flow meter to be free.
9201 : : *
9202 : : * @return
9203 : : * 0 on success.
9204 : : */
9205 : : void
9206 : 0 : mlx5_flow_mtr_free(struct rte_eth_dev *dev, uint32_t mtr_idx)
9207 : : {
9208 : : const struct mlx5_flow_driver_ops *fops;
9209 : :
9210 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9211 : 0 : fops->free_meter(dev, mtr_idx);
9212 : 0 : }
9213 : :
9214 : : /**
9215 : : * Allocate a counter.
9216 : : *
9217 : : * @param[in] dev
9218 : : * Pointer to Ethernet device structure.
9219 : : *
9220 : : * @return
9221 : : * Index to allocated counter on success, 0 otherwise.
9222 : : */
9223 : : uint32_t
9224 [ # # ]: 0 : mlx5_counter_alloc(struct rte_eth_dev *dev)
9225 : : {
9226 : : struct rte_flow_attr attr = { .transfer = 0 };
9227 : :
9228 : 0 : return flow_get_drv_ops(flow_get_drv_type(dev, &attr))->counter_alloc
9229 : : (dev);
9230 : : }
9231 : :
9232 : : /**
9233 : : * Free a counter.
9234 : : *
9235 : : * @param[in] dev
9236 : : * Pointer to Ethernet device structure.
9237 : : * @param[in] cnt
9238 : : * Index to counter to be free.
9239 : : */
9240 : : void
9241 [ # # ]: 0 : mlx5_counter_free(struct rte_eth_dev *dev, uint32_t cnt)
9242 : : {
9243 : : struct rte_flow_attr attr = { .transfer = 0 };
9244 : :
9245 : 0 : flow_get_drv_ops(flow_get_drv_type(dev, &attr))->counter_free(dev, cnt);
9246 : 0 : }
9247 : :
9248 : : /**
9249 : : * Query counter statistics.
9250 : : *
9251 : : * @param[in] dev
9252 : : * Pointer to Ethernet device structure.
9253 : : * @param[in] cnt
9254 : : * Index to counter to query.
9255 : : * @param[in] clear
9256 : : * Set to clear counter statistics.
9257 : : * @param[out] pkts
9258 : : * The counter hits packets number to save.
9259 : : * @param[out] bytes
9260 : : * The counter hits bytes number to save.
9261 : : *
9262 : : * @return
9263 : : * 0 on success, a negative errno value otherwise.
9264 : : */
9265 : : int
9266 [ # # ]: 0 : mlx5_counter_query(struct rte_eth_dev *dev, uint32_t cnt,
9267 : : bool clear, uint64_t *pkts, uint64_t *bytes, void **action)
9268 : : {
9269 : : struct rte_flow_attr attr = { .transfer = 0 };
9270 : :
9271 : 0 : return flow_get_drv_ops(flow_get_drv_type(dev, &attr))->counter_query
9272 : : (dev, cnt, clear, pkts, bytes, action);
9273 : : }
9274 : :
9275 : : /**
9276 : : * Get information about HWS pre-configurable resources.
9277 : : *
9278 : : * @param[in] dev
9279 : : * Pointer to the rte_eth_dev structure.
9280 : : * @param[out] port_info
9281 : : * Pointer to port information.
9282 : : * @param[out] queue_info
9283 : : * Pointer to queue information.
9284 : : * @param[out] error
9285 : : * Pointer to error structure.
9286 : : *
9287 : : * @return
9288 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9289 : : */
9290 : : static int
9291 [ # # ]: 0 : mlx5_flow_info_get(struct rte_eth_dev *dev,
9292 : : struct rte_flow_port_info *port_info,
9293 : : struct rte_flow_queue_info *queue_info,
9294 : : struct rte_flow_error *error)
9295 : : {
9296 : : const struct mlx5_flow_driver_ops *fops;
9297 : : struct rte_flow_attr attr = {0};
9298 : :
9299 : : if (flow_get_drv_type(dev, &attr) != MLX5_FLOW_TYPE_HW)
9300 : 0 : return rte_flow_error_set(error, ENOTSUP,
9301 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9302 : : NULL,
9303 : : "info get with incorrect steering mode");
9304 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9305 : 0 : return fops->info_get(dev, port_info, queue_info, error);
9306 : : }
9307 : :
9308 : : /**
9309 : : * Configure port HWS resources.
9310 : : *
9311 : : * @param[in] dev
9312 : : * Pointer to the rte_eth_dev structure.
9313 : : * @param[in] port_attr
9314 : : * Port configuration attributes.
9315 : : * @param[in] nb_queue
9316 : : * Number of queue.
9317 : : * @param[in] queue_attr
9318 : : * Array that holds attributes for each flow queue.
9319 : : * @param[out] error
9320 : : * Pointer to error structure.
9321 : : *
9322 : : * @return
9323 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9324 : : */
9325 : : static int
9326 [ # # ]: 0 : mlx5_flow_port_configure(struct rte_eth_dev *dev,
9327 : : const struct rte_flow_port_attr *port_attr,
9328 : : uint16_t nb_queue,
9329 : : const struct rte_flow_queue_attr *queue_attr[],
9330 : : struct rte_flow_error *error)
9331 : : {
9332 : : const struct mlx5_flow_driver_ops *fops;
9333 : : struct rte_flow_attr attr = {0};
9334 : :
9335 : : if (flow_get_drv_type(dev, &attr) != MLX5_FLOW_TYPE_HW)
9336 : 0 : return rte_flow_error_set(error, ENOTSUP,
9337 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9338 : : NULL,
9339 : : "port configure with incorrect steering mode");
9340 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9341 : 0 : return fops->configure(dev, port_attr, nb_queue, queue_attr, error);
9342 : : }
9343 : :
9344 : : /**
9345 : : * Validate item template.
9346 : : *
9347 : : * @param[in] dev
9348 : : * Pointer to the rte_eth_dev structure.
9349 : : * @param[in] attr
9350 : : * Pointer to the item template attributes.
9351 : : * @param[in] items
9352 : : * The template item pattern.
9353 : : * @param[out] error
9354 : : * Pointer to error structure.
9355 : : *
9356 : : * @return
9357 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9358 : : */
9359 : : int
9360 : 0 : mlx5_flow_pattern_validate(struct rte_eth_dev *dev,
9361 : : const struct rte_flow_pattern_template_attr *attr,
9362 : : const struct rte_flow_item items[],
9363 : : struct rte_flow_error *error)
9364 : : {
9365 : : const struct mlx5_flow_driver_ops *fops;
9366 : : struct rte_flow_attr fattr = {0};
9367 [ # # ]: 0 : uint64_t item_flags = 0;
9368 : :
9369 : : if (flow_get_drv_type(dev, &fattr) != MLX5_FLOW_TYPE_HW) {
9370 : 0 : rte_flow_error_set(error, ENOTSUP,
9371 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9372 : : "pattern validate with incorrect steering mode");
9373 : 0 : return -ENOTSUP;
9374 : : }
9375 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9376 : 0 : return fops->pattern_validate(dev, attr, items, &item_flags, error);
9377 : : }
9378 : :
9379 : : /**
9380 : : * Create flow item template.
9381 : : *
9382 : : * @param[in] dev
9383 : : * Pointer to the rte_eth_dev structure.
9384 : : * @param[in] attr
9385 : : * Pointer to the item template attributes.
9386 : : * @param[in] items
9387 : : * The template item pattern.
9388 : : * @param[out] error
9389 : : * Pointer to error structure.
9390 : : *
9391 : : * @return
9392 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9393 : : */
9394 : : static struct rte_flow_pattern_template *
9395 [ # # ]: 0 : mlx5_flow_pattern_template_create(struct rte_eth_dev *dev,
9396 : : const struct rte_flow_pattern_template_attr *attr,
9397 : : const struct rte_flow_item items[],
9398 : : struct rte_flow_error *error)
9399 : : {
9400 : : const struct mlx5_flow_driver_ops *fops;
9401 : : struct rte_flow_attr fattr = {0};
9402 : :
9403 : : if (flow_get_drv_type(dev, &fattr) != MLX5_FLOW_TYPE_HW) {
9404 : 0 : rte_flow_error_set(error, ENOTSUP,
9405 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9406 : : NULL,
9407 : : "pattern create with incorrect steering mode");
9408 : 0 : return NULL;
9409 : : }
9410 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9411 : 0 : return fops->pattern_template_create(dev, attr, items, error);
9412 : : }
9413 : :
9414 : : /**
9415 : : * Destroy flow item template.
9416 : : *
9417 : : * @param[in] dev
9418 : : * Pointer to the rte_eth_dev structure.
9419 : : * @param[in] template
9420 : : * Pointer to the item template to be destroyed.
9421 : : * @param[out] error
9422 : : * Pointer to error structure.
9423 : : *
9424 : : * @return
9425 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9426 : : */
9427 : : static int
9428 [ # # ]: 0 : mlx5_flow_pattern_template_destroy(struct rte_eth_dev *dev,
9429 : : struct rte_flow_pattern_template *template,
9430 : : struct rte_flow_error *error)
9431 : : {
9432 : : const struct mlx5_flow_driver_ops *fops;
9433 : : struct rte_flow_attr attr = {0};
9434 : :
9435 : : if (flow_get_drv_type(dev, &attr) != MLX5_FLOW_TYPE_HW)
9436 : 0 : return rte_flow_error_set(error, ENOTSUP,
9437 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9438 : : NULL,
9439 : : "pattern destroy with incorrect steering mode");
9440 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9441 : 0 : return fops->pattern_template_destroy(dev, template, error);
9442 : : }
9443 : :
9444 : : /**
9445 : : * Validate flow actions template.
9446 : : *
9447 : : * @param[in] dev
9448 : : * Pointer to the rte_eth_dev structure.
9449 : : * @param[in] attr
9450 : : * Pointer to the action template attributes.
9451 : : * @param[in] actions
9452 : : * Associated actions (list terminated by the END action).
9453 : : * @param[in] masks
9454 : : * List of actions that marks which of the action's member is constant.
9455 : : * @param[out] error
9456 : : * Pointer to error structure.
9457 : : *
9458 : : * @return
9459 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9460 : : */
9461 : : int
9462 [ # # ]: 0 : mlx5_flow_actions_validate(struct rte_eth_dev *dev,
9463 : : const struct rte_flow_actions_template_attr *attr,
9464 : : const struct rte_flow_action actions[],
9465 : : const struct rte_flow_action masks[],
9466 : : struct rte_flow_error *error)
9467 : : {
9468 : : const struct mlx5_flow_driver_ops *fops;
9469 : : struct rte_flow_attr fattr = {0};
9470 : :
9471 : : if (flow_get_drv_type(dev, &fattr) != MLX5_FLOW_TYPE_HW) {
9472 : 0 : rte_flow_error_set(error, ENOTSUP,
9473 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9474 : : "actions validate with incorrect steering mode");
9475 : 0 : return -ENOTSUP;
9476 : : }
9477 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9478 : 0 : return fops->actions_validate(dev, attr, actions, masks, error);
9479 : : }
9480 : :
9481 : : /**
9482 : : * Create flow item template.
9483 : : *
9484 : : * @param[in] dev
9485 : : * Pointer to the rte_eth_dev structure.
9486 : : * @param[in] attr
9487 : : * Pointer to the action template attributes.
9488 : : * @param[in] actions
9489 : : * Associated actions (list terminated by the END action).
9490 : : * @param[in] masks
9491 : : * List of actions that marks which of the action's member is constant.
9492 : : * @param[out] error
9493 : : * Pointer to error structure.
9494 : : *
9495 : : * @return
9496 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9497 : : */
9498 : : static struct rte_flow_actions_template *
9499 [ # # ]: 0 : mlx5_flow_actions_template_create(struct rte_eth_dev *dev,
9500 : : const struct rte_flow_actions_template_attr *attr,
9501 : : const struct rte_flow_action actions[],
9502 : : const struct rte_flow_action masks[],
9503 : : struct rte_flow_error *error)
9504 : : {
9505 : : const struct mlx5_flow_driver_ops *fops;
9506 : : struct rte_flow_attr fattr = {0};
9507 : :
9508 : : if (flow_get_drv_type(dev, &fattr) != MLX5_FLOW_TYPE_HW) {
9509 : 0 : rte_flow_error_set(error, ENOTSUP,
9510 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9511 : : NULL,
9512 : : "action create with incorrect steering mode");
9513 : 0 : return NULL;
9514 : : }
9515 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9516 : 0 : return fops->actions_template_create(dev, attr, actions, masks, error);
9517 : : }
9518 : :
9519 : : /**
9520 : : * Destroy flow action template.
9521 : : *
9522 : : * @param[in] dev
9523 : : * Pointer to the rte_eth_dev structure.
9524 : : * @param[in] template
9525 : : * Pointer to the action template to be destroyed.
9526 : : * @param[out] error
9527 : : * Pointer to error structure.
9528 : : *
9529 : : * @return
9530 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9531 : : */
9532 : : static int
9533 [ # # ]: 0 : mlx5_flow_actions_template_destroy(struct rte_eth_dev *dev,
9534 : : struct rte_flow_actions_template *template,
9535 : : struct rte_flow_error *error)
9536 : : {
9537 : : const struct mlx5_flow_driver_ops *fops;
9538 : : struct rte_flow_attr attr = {0};
9539 : :
9540 : : if (flow_get_drv_type(dev, &attr) != MLX5_FLOW_TYPE_HW)
9541 : 0 : return rte_flow_error_set(error, ENOTSUP,
9542 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9543 : : NULL,
9544 : : "action destroy with incorrect steering mode");
9545 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9546 : 0 : return fops->actions_template_destroy(dev, template, error);
9547 : : }
9548 : :
9549 : : /**
9550 : : * Create flow table.
9551 : : *
9552 : : * @param[in] dev
9553 : : * Pointer to the rte_eth_dev structure.
9554 : : * @param[in] attr
9555 : : * Pointer to the table attributes.
9556 : : * @param[in] item_templates
9557 : : * Item template array to be binded to the table.
9558 : : * @param[in] nb_item_templates
9559 : : * Number of item template.
9560 : : * @param[in] action_templates
9561 : : * Action template array to be binded to the table.
9562 : : * @param[in] nb_action_templates
9563 : : * Number of action template.
9564 : : * @param[out] error
9565 : : * Pointer to error structure.
9566 : : *
9567 : : * @return
9568 : : * Table on success, NULL otherwise and rte_errno is set.
9569 : : */
9570 : : static struct rte_flow_template_table *
9571 [ # # ]: 0 : mlx5_flow_table_create(struct rte_eth_dev *dev,
9572 : : const struct rte_flow_template_table_attr *attr,
9573 : : struct rte_flow_pattern_template *item_templates[],
9574 : : uint8_t nb_item_templates,
9575 : : struct rte_flow_actions_template *action_templates[],
9576 : : uint8_t nb_action_templates,
9577 : : struct rte_flow_error *error)
9578 : : {
9579 : : const struct mlx5_flow_driver_ops *fops;
9580 : : struct rte_flow_attr fattr = {0};
9581 : :
9582 : : if (flow_get_drv_type(dev, &fattr) != MLX5_FLOW_TYPE_HW) {
9583 : 0 : rte_flow_error_set(error, ENOTSUP,
9584 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9585 : : NULL,
9586 : : "table create with incorrect steering mode");
9587 : 0 : return NULL;
9588 : : }
9589 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9590 : 0 : return fops->template_table_create(dev,
9591 : : attr,
9592 : : item_templates,
9593 : : nb_item_templates,
9594 : : action_templates,
9595 : : nb_action_templates,
9596 : : error);
9597 : : }
9598 : :
9599 : : /**
9600 : : * PMD destroy flow table.
9601 : : *
9602 : : * @param[in] dev
9603 : : * Pointer to the rte_eth_dev structure.
9604 : : * @param[in] table
9605 : : * Pointer to the table to be destroyed.
9606 : : * @param[out] error
9607 : : * Pointer to error structure.
9608 : : *
9609 : : * @return
9610 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9611 : : */
9612 : : static int
9613 [ # # ]: 0 : mlx5_flow_table_destroy(struct rte_eth_dev *dev,
9614 : : struct rte_flow_template_table *table,
9615 : : struct rte_flow_error *error)
9616 : : {
9617 : : const struct mlx5_flow_driver_ops *fops;
9618 : : struct rte_flow_attr attr = {0};
9619 : :
9620 : : if (flow_get_drv_type(dev, &attr) != MLX5_FLOW_TYPE_HW)
9621 : 0 : return rte_flow_error_set(error, ENOTSUP,
9622 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9623 : : NULL,
9624 : : "table destroy with incorrect steering mode");
9625 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9626 : 0 : return fops->template_table_destroy(dev, table, error);
9627 : : }
9628 : :
9629 : : /**
9630 : : * PMD group set miss actions.
9631 : : *
9632 : : * @param[in] dev
9633 : : * Pointer to the rte_eth_dev structure.
9634 : : * @param[in] attr
9635 : : * Pointer to group attributes
9636 : : * @param[in] actions
9637 : : * Array of actions
9638 : : * @param[out] error
9639 : : * Pointer to error structure.
9640 : : *
9641 : : * @return
9642 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9643 : : */
9644 : : static int
9645 [ # # ]: 0 : mlx5_flow_group_set_miss_actions(struct rte_eth_dev *dev,
9646 : : uint32_t group_id,
9647 : : const struct rte_flow_group_attr *attr,
9648 : : const struct rte_flow_action actions[],
9649 : : struct rte_flow_error *error)
9650 : : {
9651 : : const struct mlx5_flow_driver_ops *fops;
9652 : : struct rte_flow_attr fattr = {0};
9653 : :
9654 : : if (flow_get_drv_type(dev, &fattr) != MLX5_FLOW_TYPE_HW)
9655 : 0 : return rte_flow_error_set(error, ENOTSUP,
9656 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9657 : : NULL,
9658 : : "group set miss actions with incorrect steering mode");
9659 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9660 : 0 : return fops->group_set_miss_actions(dev, group_id, attr, actions, error);
9661 : : }
9662 : :
9663 : : /**
9664 : : * Allocate a new memory for the counter values wrapped by all the needed
9665 : : * management.
9666 : : *
9667 : : * @param[in] sh
9668 : : * Pointer to mlx5_dev_ctx_shared object.
9669 : : *
9670 : : * @return
9671 : : * 0 on success, a negative errno value otherwise.
9672 : : */
9673 : : static int
9674 : 0 : mlx5_flow_create_counter_stat_mem_mng(struct mlx5_dev_ctx_shared *sh)
9675 : : {
9676 : : struct mlx5_counter_stats_mem_mng *mem_mng;
9677 : : volatile struct flow_counter_stats *raw_data;
9678 : : int raws_n = MLX5_CNT_MR_ALLOC_BULK + MLX5_MAX_PENDING_QUERIES;
9679 : : int size = (sizeof(struct flow_counter_stats) *
9680 : : MLX5_COUNTERS_PER_POOL +
9681 : : sizeof(struct mlx5_counter_stats_raw)) * raws_n +
9682 : : sizeof(struct mlx5_counter_stats_mem_mng);
9683 : 0 : size_t pgsize = rte_mem_page_size();
9684 : : uint8_t *mem;
9685 : : int ret;
9686 : : int i;
9687 : :
9688 [ # # ]: 0 : if (pgsize == (size_t)-1) {
9689 : 0 : DRV_LOG(ERR, "Failed to get mem page size");
9690 : 0 : rte_errno = ENOMEM;
9691 : 0 : return -ENOMEM;
9692 : : }
9693 : 0 : mem = mlx5_malloc(MLX5_MEM_ZERO, size, pgsize, SOCKET_ID_ANY);
9694 [ # # ]: 0 : if (!mem) {
9695 : 0 : rte_errno = ENOMEM;
9696 : 0 : return -ENOMEM;
9697 : : }
9698 : 0 : mem_mng = (struct mlx5_counter_stats_mem_mng *)(mem + size) - 1;
9699 : : size = sizeof(*raw_data) * MLX5_COUNTERS_PER_POOL * raws_n;
9700 : 0 : ret = mlx5_os_wrapped_mkey_create(sh->cdev->ctx, sh->cdev->pd,
9701 : 0 : sh->cdev->pdn, mem, size,
9702 : : &mem_mng->wm);
9703 [ # # ]: 0 : if (ret) {
9704 : 0 : rte_errno = errno;
9705 : 0 : mlx5_free(mem);
9706 : 0 : return -rte_errno;
9707 : : }
9708 : 0 : mem_mng->raws = (struct mlx5_counter_stats_raw *)(mem + size);
9709 : : raw_data = (volatile struct flow_counter_stats *)mem;
9710 [ # # ]: 0 : for (i = 0; i < raws_n; ++i) {
9711 : 0 : mem_mng->raws[i].mem_mng = mem_mng;
9712 : 0 : mem_mng->raws[i].data = raw_data + i * MLX5_COUNTERS_PER_POOL;
9713 : : }
9714 [ # # ]: 0 : for (i = 0; i < MLX5_MAX_PENDING_QUERIES; ++i)
9715 [ # # ]: 0 : LIST_INSERT_HEAD(&sh->sws_cmng.free_stat_raws,
9716 : : mem_mng->raws + MLX5_CNT_MR_ALLOC_BULK + i,
9717 : : next);
9718 [ # # ]: 0 : LIST_INSERT_HEAD(&sh->sws_cmng.mem_mngs, mem_mng, next);
9719 : 0 : sh->sws_cmng.mem_mng = mem_mng;
9720 : 0 : return 0;
9721 : : }
9722 : :
9723 : : /**
9724 : : * Set the statistic memory to the new counter pool.
9725 : : *
9726 : : * @param[in] sh
9727 : : * Pointer to mlx5_dev_ctx_shared object.
9728 : : * @param[in] pool
9729 : : * Pointer to the pool to set the statistic memory.
9730 : : *
9731 : : * @return
9732 : : * 0 on success, a negative errno value otherwise.
9733 : : */
9734 : : static int
9735 : 0 : mlx5_flow_set_counter_stat_mem(struct mlx5_dev_ctx_shared *sh,
9736 : : struct mlx5_flow_counter_pool *pool)
9737 : : {
9738 : : struct mlx5_flow_counter_mng *cmng = &sh->sws_cmng;
9739 : : /* Resize statistic memory once used out. */
9740 [ # # # # ]: 0 : if (!(pool->index % MLX5_CNT_MR_ALLOC_BULK) &&
9741 : 0 : mlx5_flow_create_counter_stat_mem_mng(sh)) {
9742 : 0 : DRV_LOG(ERR, "Cannot resize counter stat mem.");
9743 : 0 : return -1;
9744 : : }
9745 : 0 : rte_spinlock_lock(&pool->sl);
9746 : 0 : pool->raw = cmng->mem_mng->raws + pool->index % MLX5_CNT_MR_ALLOC_BULK;
9747 : : rte_spinlock_unlock(&pool->sl);
9748 : 0 : pool->raw_hw = NULL;
9749 : 0 : return 0;
9750 : : }
9751 : :
9752 : : #define MLX5_POOL_QUERY_FREQ_US 1000000
9753 : :
9754 : : /**
9755 : : * Set the periodic procedure for triggering asynchronous batch queries for all
9756 : : * the counter pools.
9757 : : *
9758 : : * @param[in] sh
9759 : : * Pointer to mlx5_dev_ctx_shared object.
9760 : : */
9761 : : void
9762 : 0 : mlx5_set_query_alarm(struct mlx5_dev_ctx_shared *sh)
9763 : : {
9764 : : uint32_t pools_n, us;
9765 : :
9766 : 0 : pools_n = rte_atomic_load_explicit(&sh->sws_cmng.n_valid, rte_memory_order_relaxed);
9767 : 0 : us = MLX5_POOL_QUERY_FREQ_US / pools_n;
9768 : 0 : DRV_LOG(DEBUG, "Set alarm for %u pools each %u us", pools_n, us);
9769 [ # # ]: 0 : if (rte_eal_alarm_set(us, mlx5_flow_query_alarm, sh)) {
9770 : 0 : sh->sws_cmng.query_thread_on = 0;
9771 : 0 : DRV_LOG(ERR, "Cannot reinitialize query alarm");
9772 : : } else {
9773 : 0 : sh->sws_cmng.query_thread_on = 1;
9774 : : }
9775 : 0 : }
9776 : :
9777 : : /**
9778 : : * The periodic procedure for triggering asynchronous batch queries for all the
9779 : : * counter pools. This function is probably called by the host thread.
9780 : : *
9781 : : * @param[in] arg
9782 : : * The parameter for the alarm process.
9783 : : */
9784 : : void
9785 : 0 : mlx5_flow_query_alarm(void *arg)
9786 : : {
9787 : : struct mlx5_dev_ctx_shared *sh = arg;
9788 : : struct mlx5_flow_counter_mng *cmng = &sh->sws_cmng;
9789 : 0 : uint16_t pool_index = cmng->pool_index;
9790 : : struct mlx5_flow_counter_pool *pool;
9791 : : uint16_t n_valid;
9792 : : int ret;
9793 : :
9794 [ # # ]: 0 : if (cmng->pending_queries >= MLX5_MAX_PENDING_QUERIES)
9795 : 0 : goto set_alarm;
9796 : 0 : rte_spinlock_lock(&cmng->pool_update_sl);
9797 : 0 : pool = cmng->pools[pool_index];
9798 : 0 : n_valid = cmng->n_valid;
9799 : : rte_spinlock_unlock(&cmng->pool_update_sl);
9800 : : /* Set the statistic memory to the new created pool. */
9801 [ # # # # ]: 0 : if ((!pool->raw && mlx5_flow_set_counter_stat_mem(sh, pool)))
9802 : 0 : goto set_alarm;
9803 [ # # ]: 0 : if (pool->raw_hw)
9804 : : /* There is a pool query in progress. */
9805 : 0 : goto set_alarm;
9806 : 0 : pool->raw_hw = LIST_FIRST(&cmng->free_stat_raws);
9807 [ # # ]: 0 : if (!pool->raw_hw)
9808 : : /* No free counter statistics raw memory. */
9809 : 0 : goto set_alarm;
9810 : : /*
9811 : : * Identify the counters released between query trigger and query
9812 : : * handle more efficiently. The counter released in this gap period
9813 : : * should wait for a new round of query as the new arrived packets
9814 : : * will not be taken into account.
9815 : : */
9816 : 0 : pool->query_gen++;
9817 : 0 : ret = mlx5_devx_cmd_flow_counter_query(pool->min_dcs, 0,
9818 : : MLX5_COUNTERS_PER_POOL,
9819 : : NULL, NULL,
9820 : 0 : pool->raw_hw->mem_mng->wm.lkey,
9821 : : (void *)(uintptr_t)
9822 : 0 : pool->raw_hw->data,
9823 : : sh->devx_comp,
9824 : : (uint64_t)(uintptr_t)pool);
9825 [ # # ]: 0 : if (ret) {
9826 : 0 : DRV_LOG(ERR, "Failed to trigger asynchronous query for dcs ID"
9827 : : " %d", pool->min_dcs->id);
9828 : 0 : pool->raw_hw = NULL;
9829 : 0 : goto set_alarm;
9830 : : }
9831 [ # # ]: 0 : LIST_REMOVE(pool->raw_hw, next);
9832 : 0 : cmng->pending_queries++;
9833 : 0 : pool_index++;
9834 [ # # ]: 0 : if (pool_index >= n_valid)
9835 : : pool_index = 0;
9836 : 0 : set_alarm:
9837 : 0 : cmng->pool_index = pool_index;
9838 : 0 : mlx5_set_query_alarm(sh);
9839 : 0 : }
9840 : :
9841 : : /**
9842 : : * Check and callback event for new aged flow in the counter pool
9843 : : *
9844 : : * @param[in] sh
9845 : : * Pointer to mlx5_dev_ctx_shared object.
9846 : : * @param[in] pool
9847 : : * Pointer to Current counter pool.
9848 : : */
9849 : : static void
9850 : 0 : mlx5_flow_aging_check(struct mlx5_dev_ctx_shared *sh,
9851 : : struct mlx5_flow_counter_pool *pool)
9852 : : {
9853 : : struct mlx5_priv *priv;
9854 : : struct mlx5_flow_counter *cnt;
9855 : : struct mlx5_age_info *age_info;
9856 : : struct mlx5_age_param *age_param;
9857 : 0 : struct mlx5_counter_stats_raw *cur = pool->raw_hw;
9858 : 0 : struct mlx5_counter_stats_raw *prev = pool->raw;
9859 : 0 : const uint64_t curr_time = MLX5_CURR_TIME_SEC;
9860 : 0 : const uint32_t time_delta = curr_time - pool->time_of_last_age_check;
9861 : : uint16_t expected = AGE_CANDIDATE;
9862 : : uint32_t i;
9863 : :
9864 : 0 : pool->time_of_last_age_check = curr_time;
9865 [ # # ]: 0 : for (i = 0; i < MLX5_COUNTERS_PER_POOL; ++i) {
9866 [ # # ]: 0 : cnt = MLX5_POOL_GET_CNT(pool, i);
9867 : : age_param = MLX5_CNT_TO_AGE(cnt);
9868 [ # # ]: 0 : if (rte_atomic_load_explicit(&age_param->state,
9869 : : rte_memory_order_relaxed) != AGE_CANDIDATE)
9870 : 0 : continue;
9871 [ # # ]: 0 : if (cur->data[i].hits != prev->data[i].hits) {
9872 : 0 : rte_atomic_store_explicit(&age_param->sec_since_last_hit, 0,
9873 : : rte_memory_order_relaxed);
9874 : 0 : continue;
9875 : : }
9876 : 0 : if (rte_atomic_fetch_add_explicit(&age_param->sec_since_last_hit,
9877 : : time_delta,
9878 [ # # ]: 0 : rte_memory_order_relaxed) + time_delta <= age_param->timeout)
9879 : 0 : continue;
9880 : : /**
9881 : : * Hold the lock first, or if between the
9882 : : * state AGE_TMOUT and tailq operation the
9883 : : * release happened, the release procedure
9884 : : * may delete a non-existent tailq node.
9885 : : */
9886 : 0 : priv = rte_eth_devices[age_param->port_id].data->dev_private;
9887 : 0 : age_info = GET_PORT_AGE_INFO(priv);
9888 : 0 : rte_spinlock_lock(&age_info->aged_sl);
9889 [ # # ]: 0 : if (rte_atomic_compare_exchange_strong_explicit(&age_param->state, &expected,
9890 : : AGE_TMOUT,
9891 : : rte_memory_order_relaxed,
9892 : : rte_memory_order_relaxed)) {
9893 : 0 : TAILQ_INSERT_TAIL(&age_info->aged_counters, cnt, next);
9894 : 0 : MLX5_AGE_SET(age_info, MLX5_AGE_EVENT_NEW);
9895 : : }
9896 : : rte_spinlock_unlock(&age_info->aged_sl);
9897 : : }
9898 : 0 : mlx5_age_event_prepare(sh);
9899 : 0 : }
9900 : :
9901 : : /**
9902 : : * Handler for the HW respond about ready values from an asynchronous batch
9903 : : * query. This function is probably called by the host thread.
9904 : : *
9905 : : * @param[in] sh
9906 : : * The pointer to the shared device context.
9907 : : * @param[in] async_id
9908 : : * The Devx async ID.
9909 : : * @param[in] status
9910 : : * The status of the completion.
9911 : : */
9912 : : void
9913 : 0 : mlx5_flow_async_pool_query_handle(struct mlx5_dev_ctx_shared *sh,
9914 : : uint64_t async_id, int status)
9915 : : {
9916 : : /*
9917 : : * Handle async counter pool query completion.
9918 : : * query_gen is flipped each round: freed counters go into [query_gen],
9919 : : * while this callback moves [query_gen ^ 1] to the global free list.
9920 : : * pool->csl must be held when operating on pool->counters[] to serialize
9921 : : * with concurrent free-path insertions.
9922 : : */
9923 : 0 : struct mlx5_flow_counter_pool *pool =
9924 : : (struct mlx5_flow_counter_pool *)(uintptr_t)async_id;
9925 : : struct mlx5_counter_stats_raw *raw_to_free;
9926 : 0 : uint8_t query_gen = pool->query_gen ^ 1;
9927 : : struct mlx5_flow_counter_mng *cmng = &sh->sws_cmng;
9928 : 0 : enum mlx5_counter_type cnt_type =
9929 : 0 : pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
9930 : : MLX5_COUNTER_TYPE_ORIGIN;
9931 : :
9932 [ # # ]: 0 : if (unlikely(status)) {
9933 : 0 : raw_to_free = pool->raw_hw;
9934 : : /*
9935 : : * The query failed, so the freed counters accumulated
9936 : : * in the old-gen list would otherwise be stranded.
9937 : : * Move them back to the global free list. This is safe
9938 : : * for both transient and persistent failures: the
9939 : : * counters are still valid and can be reused.
9940 : : */
9941 [ # # ]: 0 : if (!TAILQ_EMPTY(&pool->counters[query_gen])) {
9942 : 0 : rte_spinlock_lock(&pool->csl);
9943 : 0 : rte_spinlock_lock(&cmng->csl[cnt_type]);
9944 [ # # ]: 0 : TAILQ_CONCAT(&cmng->counters[cnt_type],
9945 : : &pool->counters[query_gen], next);
9946 : : rte_spinlock_unlock(&cmng->csl[cnt_type]);
9947 : : rte_spinlock_unlock(&pool->csl);
9948 : : }
9949 : : } else {
9950 : 0 : raw_to_free = pool->raw;
9951 [ # # ]: 0 : if (pool->is_aged)
9952 : 0 : mlx5_flow_aging_check(sh, pool);
9953 : 0 : rte_spinlock_lock(&pool->sl);
9954 : 0 : pool->raw = pool->raw_hw;
9955 : : rte_spinlock_unlock(&pool->sl);
9956 : : /* Be sure the new raw counters data is updated in memory. */
9957 : 0 : rte_io_wmb();
9958 : : /*
9959 : : * A counter free thread may have read a stale query_gen
9960 : : * before the generation was flipped and could still be
9961 : : * inserting into this same old-gen list. Hold pool->csl to
9962 : : * serialize TAILQ_CONCAT with that TAILQ_INSERT_TAIL and
9963 : : * avoid corrupting the list.
9964 : : */
9965 [ # # ]: 0 : if (!TAILQ_EMPTY(&pool->counters[query_gen])) {
9966 : 0 : rte_spinlock_lock(&pool->csl);
9967 : 0 : rte_spinlock_lock(&cmng->csl[cnt_type]);
9968 [ # # ]: 0 : TAILQ_CONCAT(&cmng->counters[cnt_type],
9969 : : &pool->counters[query_gen], next);
9970 : : rte_spinlock_unlock(&cmng->csl[cnt_type]);
9971 : : rte_spinlock_unlock(&pool->csl);
9972 : : }
9973 : : }
9974 [ # # ]: 0 : LIST_INSERT_HEAD(&sh->sws_cmng.free_stat_raws, raw_to_free, next);
9975 : 0 : pool->raw_hw = NULL;
9976 : 0 : sh->sws_cmng.pending_queries--;
9977 : 0 : }
9978 : :
9979 : : static int
9980 : 0 : flow_group_to_table(uint32_t port_id, uint32_t group, uint32_t *table,
9981 : : const struct flow_grp_info *grp_info,
9982 : : struct rte_flow_error *error)
9983 : : {
9984 [ # # ]: 0 : if (grp_info->transfer && grp_info->external &&
9985 : : grp_info->fdb_def_rule) {
9986 [ # # ]: 0 : if (group == UINT32_MAX)
9987 : 0 : return rte_flow_error_set
9988 : : (error, EINVAL,
9989 : : RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
9990 : : NULL,
9991 : : "group index not supported");
9992 : 0 : *table = group + 1;
9993 : : } else {
9994 : 0 : *table = group;
9995 : : }
9996 : 0 : DRV_LOG(DEBUG, "port %u group=%#x table=%#x", port_id, group, *table);
9997 : 0 : return 0;
9998 : : }
9999 : :
10000 : : /**
10001 : : * Translate the rte_flow group index to HW table value.
10002 : : *
10003 : : * If tunnel offload is disabled, all group ids converted to flow table
10004 : : * id using the standard method.
10005 : : * If tunnel offload is enabled, group id can be converted using the
10006 : : * standard or tunnel conversion method. Group conversion method
10007 : : * selection depends on flags in `grp_info` parameter:
10008 : : * - Internal (grp_info.external == 0) groups conversion uses the
10009 : : * standard method.
10010 : : * - Group ids in JUMP action converted with the tunnel conversion.
10011 : : * - Group id in rule attribute conversion depends on a rule type and
10012 : : * group id value:
10013 : : * ** non zero group attributes converted with the tunnel method
10014 : : * ** zero group attribute in non-tunnel rule is converted using the
10015 : : * standard method - there's only one root table
10016 : : * ** zero group attribute in steer tunnel rule is converted with the
10017 : : * standard method - single root table
10018 : : * ** zero group attribute in match tunnel rule is a special OvS
10019 : : * case: that value is used for portability reasons. That group
10020 : : * id is converted with the tunnel conversion method.
10021 : : *
10022 : : * @param[in] dev
10023 : : * Port device
10024 : : * @param[in] tunnel
10025 : : * PMD tunnel offload object
10026 : : * @param[in] group
10027 : : * rte_flow group index value.
10028 : : * @param[out] table
10029 : : * HW table value.
10030 : : * @param[in] grp_info
10031 : : * flags used for conversion
10032 : : * @param[out] error
10033 : : * Pointer to error structure.
10034 : : *
10035 : : * @return
10036 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
10037 : : */
10038 : : int
10039 : 0 : mlx5_flow_group_to_table(struct rte_eth_dev *dev,
10040 : : const struct mlx5_flow_tunnel *tunnel,
10041 : : uint32_t group, uint32_t *table,
10042 : : const struct flow_grp_info *grp_info,
10043 : : struct rte_flow_error *error)
10044 : : {
10045 : : int ret;
10046 : : bool standard_translation;
10047 : :
10048 [ # # # # ]: 0 : if (!grp_info->skip_scale && grp_info->external &&
10049 : : group < MLX5_MAX_TABLES_EXTERNAL)
10050 : 0 : group *= MLX5_FLOW_TABLE_FACTOR;
10051 [ # # ]: 0 : if (is_tunnel_offload_active(dev)) {
10052 : 0 : standard_translation = !grp_info->external ||
10053 : : grp_info->std_tbl_fix;
10054 : : } else {
10055 : : standard_translation = true;
10056 : : }
10057 [ # # ]: 0 : DRV_LOG(DEBUG,
10058 : : "port %u group=%u transfer=%d external=%d fdb_def_rule=%d translate=%s",
10059 : : dev->data->port_id, group, grp_info->transfer,
10060 : : grp_info->external, grp_info->fdb_def_rule,
10061 : : standard_translation ? "STANDARD" : "TUNNEL");
10062 [ # # ]: 0 : if (standard_translation)
10063 : 0 : ret = flow_group_to_table(dev->data->port_id, group, table,
10064 : : grp_info, error);
10065 : : else
10066 : 0 : ret = tunnel_flow_group_to_flow_table(dev, tunnel, group,
10067 : : table, error);
10068 : :
10069 : 0 : return ret;
10070 : : }
10071 : :
10072 : : /**
10073 : : * Discover availability of metadata reg_c's.
10074 : : *
10075 : : * Iteratively use test flows to check availability.
10076 : : *
10077 : : * @param[in] dev
10078 : : * Pointer to the Ethernet device structure.
10079 : : *
10080 : : * @return
10081 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
10082 : : */
10083 : : int
10084 : 0 : mlx5_flow_discover_mreg_c(struct rte_eth_dev *dev)
10085 : : {
10086 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10087 : : enum modify_reg idx;
10088 : : int n = 0;
10089 : :
10090 : : /* reg_c[0] and reg_c[1] are reserved. */
10091 : 0 : priv->sh->flow_mreg_c[n++] = REG_C_0;
10092 : 0 : priv->sh->flow_mreg_c[n++] = REG_C_1;
10093 : : /* Discover availability of other reg_c's. */
10094 [ # # ]: 0 : for (idx = REG_C_2; idx <= REG_C_7; ++idx) {
10095 : 0 : struct rte_flow_attr attr = {
10096 : : .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
10097 : : .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
10098 : : .ingress = 1,
10099 : : };
10100 : 0 : struct rte_flow_item items[] = {
10101 : : [0] = {
10102 : : .type = RTE_FLOW_ITEM_TYPE_END,
10103 : : },
10104 : : };
10105 : 0 : struct rte_flow_action actions[] = {
10106 : : [0] = {
10107 : : .type = (enum rte_flow_action_type)
10108 : : MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
10109 : 0 : .conf = &(struct mlx5_flow_action_copy_mreg){
10110 : : .src = REG_C_1,
10111 : : .dst = idx,
10112 : : },
10113 : : },
10114 : : [1] = {
10115 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
10116 : 0 : .conf = &(struct rte_flow_action_jump){
10117 : : .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
10118 : : },
10119 : : },
10120 : : [2] = {
10121 : : .type = RTE_FLOW_ACTION_TYPE_END,
10122 : : },
10123 : : };
10124 : : uint32_t flow_idx;
10125 : : struct rte_flow *flow;
10126 : : struct rte_flow_error error;
10127 : :
10128 [ # # ]: 0 : if (!priv->sh->config.dv_flow_en)
10129 : : break;
10130 : : /* Create internal flow, validation skips copy action. */
10131 : 0 : flow_idx = mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_GEN, &attr,
10132 : : items, actions, false, &error);
10133 : 0 : flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
10134 : : flow_idx);
10135 [ # # ]: 0 : if (!flow)
10136 : 0 : continue;
10137 : 0 : priv->sh->flow_mreg_c[n++] = idx;
10138 : 0 : mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN, flow_idx);
10139 : : }
10140 [ # # ]: 0 : for (; n < MLX5_MREG_C_NUM; ++n)
10141 : 0 : priv->sh->flow_mreg_c[n] = REG_NON;
10142 : 0 : priv->sh->metadata_regc_check_flag = 1;
10143 : 0 : return 0;
10144 : : }
10145 : :
10146 : : int
10147 [ # # # # ]: 0 : mlx5_save_dump_file(const uint8_t *data, uint32_t size,
10148 : : uint32_t type, uint64_t id, void *arg, FILE *file)
10149 : : {
10150 : : char line[BUF_SIZE];
10151 : : uint32_t out = 0;
10152 : : uint32_t k;
10153 : : uint32_t actions_num;
10154 : : struct rte_flow_query_count *count;
10155 : :
10156 : : memset(line, 0, BUF_SIZE);
10157 [ # # # # ]: 0 : switch (type) {
10158 : 0 : case DR_DUMP_REC_TYPE_PMD_MODIFY_HDR:
10159 : 0 : actions_num = *(uint32_t *)(arg);
10160 : 0 : out += snprintf(line + out, BUF_SIZE - out, "%d,0x%" PRIx64 ",%d,",
10161 : : type, id, actions_num);
10162 : 0 : break;
10163 : 0 : case DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT:
10164 : 0 : out += snprintf(line + out, BUF_SIZE - out, "%d,0x%" PRIx64 ",",
10165 : : type, id);
10166 : 0 : break;
10167 : 0 : case DR_DUMP_REC_TYPE_PMD_COUNTER:
10168 : : count = (struct rte_flow_query_count *)arg;
10169 : 0 : fprintf(file,
10170 : : "%d,0x%" PRIx64 ",%" PRIu64 ",%" PRIu64 "\n",
10171 : : type, id, count->hits, count->bytes);
10172 : 0 : return 0;
10173 : : default:
10174 : : return -1;
10175 : : }
10176 : :
10177 [ # # ]: 0 : for (k = 0; k < size; k++) {
10178 : : /* Make sure we do not overrun the line buffer length. */
10179 [ # # ]: 0 : if (out >= BUF_SIZE - 4) {
10180 : 0 : line[out] = '\0';
10181 : 0 : break;
10182 : : }
10183 : 0 : out += snprintf(line + out, BUF_SIZE - out, "%02x",
10184 : 0 : (data[k]) & 0xff);
10185 : : }
10186 : : fprintf(file, "%s\n", line);
10187 : 0 : return 0;
10188 : : }
10189 : :
10190 : : int
10191 : 0 : mlx5_flow_query_counter(struct rte_eth_dev *dev, struct rte_flow *flow,
10192 : : struct rte_flow_query_count *count, struct rte_flow_error *error)
10193 : : {
10194 : : struct rte_flow_action action[2];
10195 : : enum mlx5_flow_drv_type ftype;
10196 : : const struct mlx5_flow_driver_ops *fops;
10197 : :
10198 [ # # ]: 0 : if (!flow) {
10199 : 0 : return rte_flow_error_set(error, ENOENT,
10200 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10201 : : NULL,
10202 : : "invalid flow handle");
10203 : : }
10204 : 0 : action[0].type = RTE_FLOW_ACTION_TYPE_COUNT;
10205 : 0 : action[1].type = RTE_FLOW_ACTION_TYPE_END;
10206 [ # # ]: 0 : if (flow->counter) {
10207 : : memset(count, 0, sizeof(struct rte_flow_query_count));
10208 : 0 : ftype = (enum mlx5_flow_drv_type)(flow->drv_type);
10209 : : MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN &&
10210 : : ftype < MLX5_FLOW_TYPE_MAX);
10211 : 0 : fops = flow_get_drv_ops(ftype);
10212 : 0 : return fops->query(dev, flow, action, count, error);
10213 : : }
10214 : : return -1;
10215 : : }
10216 : :
10217 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
10218 : : /**
10219 : : * Dump flow ipool data to file
10220 : : *
10221 : : * @param[in] dev
10222 : : * The pointer to Ethernet device.
10223 : : * @param[in] file
10224 : : * A pointer to a file for output.
10225 : : * @param[out] error
10226 : : * Perform verbose error reporting if not NULL. PMDs initialize this
10227 : : * structure in case of error only.
10228 : : * @return
10229 : : * 0 on success, a negative value otherwise.
10230 : : */
10231 : : int
10232 : 0 : mlx5_flow_dev_dump_ipool(struct rte_eth_dev *dev,
10233 : : struct rte_flow *flow, FILE *file,
10234 : : struct rte_flow_error *error)
10235 : : {
10236 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10237 : : struct mlx5_flow_dv_modify_hdr_resource *modify_hdr;
10238 : : struct mlx5_flow_dv_encap_decap_resource *encap_decap;
10239 : : uint32_t handle_idx;
10240 : : struct mlx5_flow_handle *dh;
10241 : : struct rte_flow_query_count count;
10242 : : uint32_t actions_num;
10243 : : const uint8_t *data;
10244 : : size_t size;
10245 : : uint64_t id;
10246 : : uint32_t type;
10247 : 0 : void *action = NULL;
10248 : :
10249 [ # # ]: 0 : if (!flow) {
10250 : 0 : return rte_flow_error_set(error, ENOENT,
10251 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10252 : : NULL,
10253 : : "invalid flow handle");
10254 : : }
10255 : 0 : handle_idx = flow->dev_handles;
10256 : : /* query counter */
10257 [ # # # # ]: 0 : if (flow->counter &&
10258 : 0 : (!mlx5_counter_query(dev, flow->counter, false,
10259 [ # # ]: 0 : &count.hits, &count.bytes, &action)) && action) {
10260 : 0 : id = (uint64_t)(uintptr_t)action;
10261 : : type = DR_DUMP_REC_TYPE_PMD_COUNTER;
10262 : 0 : mlx5_save_dump_file(NULL, 0, type,
10263 : : id, (void *)&count, file);
10264 : : }
10265 : :
10266 [ # # ]: 0 : while (handle_idx) {
10267 : 0 : dh = mlx5_ipool_get(priv->sh->ipool
10268 : : [MLX5_IPOOL_MLX5_FLOW], handle_idx);
10269 [ # # ]: 0 : if (!dh)
10270 : 0 : continue;
10271 : 0 : handle_idx = dh->next.next;
10272 : :
10273 : : /* Get modify_hdr and encap_decap buf from ipools. */
10274 : : encap_decap = NULL;
10275 : 0 : modify_hdr = dh->dvh.modify_hdr;
10276 : :
10277 [ # # ]: 0 : if (dh->dvh.rix_encap_decap) {
10278 : 0 : encap_decap = mlx5_ipool_get(priv->sh->ipool
10279 : : [MLX5_IPOOL_DECAP_ENCAP],
10280 : : dh->dvh.rix_encap_decap);
10281 : : }
10282 [ # # ]: 0 : if (modify_hdr) {
10283 : 0 : data = (const uint8_t *)modify_hdr->actions;
10284 : 0 : size = (size_t)(modify_hdr->actions_num) * 8;
10285 : 0 : id = (uint64_t)(uintptr_t)modify_hdr->action;
10286 : 0 : actions_num = modify_hdr->actions_num;
10287 : : type = DR_DUMP_REC_TYPE_PMD_MODIFY_HDR;
10288 : 0 : mlx5_save_dump_file(data, size, type, id,
10289 : : (void *)(&actions_num), file);
10290 : : }
10291 [ # # ]: 0 : if (encap_decap) {
10292 : 0 : data = encap_decap->buf;
10293 : 0 : size = encap_decap->size;
10294 : 0 : id = (uint64_t)(uintptr_t)encap_decap->action;
10295 : : type = DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT;
10296 : 0 : mlx5_save_dump_file(data, size, type,
10297 : : id, NULL, file);
10298 : : }
10299 : : }
10300 : : return 0;
10301 : : }
10302 : :
10303 : : /**
10304 : : * Dump all flow's encap_decap/modify_hdr/counter data to file
10305 : : *
10306 : : * @param[in] dev
10307 : : * The pointer to Ethernet device.
10308 : : * @param[in] file
10309 : : * A pointer to a file for output.
10310 : : * @param[out] error
10311 : : * Perform verbose error reporting if not NULL. PMDs initialize this
10312 : : * structure in case of error only.
10313 : : * @return
10314 : : * 0 on success, a negative value otherwise.
10315 : : */
10316 : : static int
10317 : 0 : mlx5_flow_dev_dump_sh_all(struct rte_eth_dev *dev,
10318 : : FILE *file, struct rte_flow_error *error __rte_unused)
10319 : : {
10320 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10321 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
10322 : : struct mlx5_hlist *h;
10323 : : struct mlx5_flow_dv_modify_hdr_resource *modify_hdr;
10324 : : struct mlx5_flow_dv_encap_decap_resource *encap_decap;
10325 : : struct rte_flow_query_count count;
10326 : : uint32_t actions_num;
10327 : : const uint8_t *data;
10328 : : size_t size;
10329 : : uint64_t id;
10330 : : uint32_t type;
10331 : : uint32_t i;
10332 : : uint32_t j;
10333 : : struct mlx5_list_inconst *l_inconst;
10334 : : struct mlx5_list_entry *e;
10335 : : int lcore_index;
10336 : : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
10337 : : uint32_t max;
10338 : : void *action;
10339 : :
10340 : : /* encap_decap hlist is lcore_share, get global core cache. */
10341 : : i = MLX5_LIST_GLOBAL;
10342 : 0 : h = sh->encaps_decaps;
10343 [ # # ]: 0 : if (h) {
10344 [ # # ]: 0 : for (j = 0; j <= h->mask; j++) {
10345 : : l_inconst = &h->buckets[j].l;
10346 [ # # ]: 0 : if (!l_inconst || !l_inconst->cache[i])
10347 : 0 : continue;
10348 : :
10349 : 0 : e = LIST_FIRST(&l_inconst->cache[i]->h);
10350 [ # # ]: 0 : while (e) {
10351 : : encap_decap =
10352 : : (struct mlx5_flow_dv_encap_decap_resource *)e;
10353 : 0 : data = encap_decap->buf;
10354 : 0 : size = encap_decap->size;
10355 : 0 : id = (uint64_t)(uintptr_t)encap_decap->action;
10356 : : type = DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT;
10357 : 0 : mlx5_save_dump_file(data, size, type,
10358 : : id, NULL, file);
10359 : 0 : e = LIST_NEXT(e, next);
10360 : : }
10361 : : }
10362 : : }
10363 : :
10364 : : /* get modify_hdr */
10365 : 0 : h = sh->modify_cmds;
10366 [ # # ]: 0 : if (h) {
10367 : 0 : lcore_index = rte_lcore_index(rte_lcore_id());
10368 [ # # ]: 0 : if (unlikely(lcore_index == -1)) {
10369 : : lcore_index = MLX5_LIST_NLCORE;
10370 : 0 : rte_spinlock_lock(&h->l_const.lcore_lock);
10371 : : }
10372 : 0 : i = lcore_index;
10373 : :
10374 [ # # ]: 0 : if (lcore_index == MLX5_LIST_NLCORE) {
10375 [ # # ]: 0 : for (i = 0; i <= (uint32_t)lcore_index; i++) {
10376 [ # # ]: 0 : for (j = 0; j <= h->mask; j++) {
10377 : : l_inconst = &h->buckets[j].l;
10378 [ # # ]: 0 : if (!l_inconst || !l_inconst->cache[i])
10379 : 0 : continue;
10380 : :
10381 : 0 : e = LIST_FIRST(&l_inconst->cache[i]->h);
10382 [ # # ]: 0 : while (e) {
10383 : : modify_hdr =
10384 : : (struct mlx5_flow_dv_modify_hdr_resource *)e;
10385 : 0 : data = (const uint8_t *)modify_hdr->actions;
10386 : 0 : size = (size_t)(modify_hdr->actions_num) * 8;
10387 : 0 : actions_num = modify_hdr->actions_num;
10388 : 0 : id = (uint64_t)(uintptr_t)modify_hdr->action;
10389 : : type = DR_DUMP_REC_TYPE_PMD_MODIFY_HDR;
10390 : 0 : mlx5_save_dump_file(data, size, type, id,
10391 : : (void *)(&actions_num), file);
10392 : 0 : e = LIST_NEXT(e, next);
10393 : : }
10394 : : }
10395 : : }
10396 : : } else {
10397 [ # # ]: 0 : for (j = 0; j <= h->mask; j++) {
10398 : : l_inconst = &h->buckets[j].l;
10399 [ # # ]: 0 : if (!l_inconst || !l_inconst->cache[i])
10400 : 0 : continue;
10401 : :
10402 : 0 : e = LIST_FIRST(&l_inconst->cache[i]->h);
10403 [ # # ]: 0 : while (e) {
10404 : : modify_hdr =
10405 : : (struct mlx5_flow_dv_modify_hdr_resource *)e;
10406 : 0 : data = (const uint8_t *)modify_hdr->actions;
10407 : 0 : size = (size_t)(modify_hdr->actions_num) * 8;
10408 : 0 : actions_num = modify_hdr->actions_num;
10409 : 0 : id = (uint64_t)(uintptr_t)modify_hdr->action;
10410 : : type = DR_DUMP_REC_TYPE_PMD_MODIFY_HDR;
10411 : 0 : mlx5_save_dump_file(data, size, type, id,
10412 : : (void *)(&actions_num), file);
10413 : 0 : e = LIST_NEXT(e, next);
10414 : : }
10415 : : }
10416 : : }
10417 : :
10418 [ # # ]: 0 : if (unlikely(lcore_index == MLX5_LIST_NLCORE))
10419 : 0 : rte_spinlock_unlock(&h->l_const.lcore_lock);
10420 : : }
10421 : :
10422 : : /* get counter */
10423 : : MLX5_ASSERT(cmng->n_valid <= MLX5_COUNTER_POOLS_MAX_NUM);
10424 : 0 : max = MLX5_COUNTERS_PER_POOL * cmng->n_valid;
10425 [ # # ]: 0 : for (j = 1; j <= max; j++) {
10426 : 0 : action = NULL;
10427 [ # # ]: 0 : if ((!mlx5_counter_query(dev, j, false, &count.hits,
10428 [ # # ]: 0 : &count.bytes, &action)) && action) {
10429 : 0 : id = (uint64_t)(uintptr_t)action;
10430 : : type = DR_DUMP_REC_TYPE_PMD_COUNTER;
10431 : 0 : mlx5_save_dump_file(NULL, 0, type,
10432 : : id, (void *)&count, file);
10433 : : }
10434 : : }
10435 : 0 : return 0;
10436 : : }
10437 : : #endif
10438 : :
10439 : : /**
10440 : : * Dump flow raw hw data to file
10441 : : *
10442 : : * @param[in] dev
10443 : : * The pointer to Ethernet device.
10444 : : * @param[in] file
10445 : : * A pointer to a file for output.
10446 : : * @param[out] error
10447 : : * Perform verbose error reporting if not NULL. PMDs initialize this
10448 : : * structure in case of error only.
10449 : : * @return
10450 : : * 0 on success, a negative value otherwise.
10451 : : */
10452 : : int
10453 : 0 : mlx5_flow_dev_dump(struct rte_eth_dev *dev, struct rte_flow *flow_idx,
10454 : : FILE *file,
10455 : : struct rte_flow_error *error __rte_unused)
10456 : : {
10457 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10458 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
10459 : : uint32_t handle_idx;
10460 : : int ret;
10461 : : struct mlx5_flow_handle *dh;
10462 : : struct rte_flow *flow;
10463 : :
10464 [ # # ]: 0 : if (!sh->config.dv_flow_en) {
10465 [ # # ]: 0 : if (fputs("device dv flow disabled\n", file) <= 0)
10466 : 0 : return -errno;
10467 : : return -ENOTSUP;
10468 : : }
10469 : :
10470 : : /* dump all */
10471 [ # # ]: 0 : if (!flow_idx) {
10472 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
10473 [ # # ]: 0 : if (mlx5_flow_dev_dump_sh_all(dev, file, error))
10474 : : return -EINVAL;
10475 : :
10476 [ # # ]: 0 : if (sh->config.dv_flow_en == 2)
10477 : 0 : return mlx5dr_debug_dump(priv->dr_ctx, file);
10478 : : #endif
10479 : 0 : return mlx5_devx_cmd_flow_dump(sh->fdb_domain,
10480 : : sh->rx_domain,
10481 : : sh->tx_domain, file);
10482 : : }
10483 : : /* dump one */
10484 : 0 : flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
10485 : : (uintptr_t)(void *)flow_idx);
10486 [ # # ]: 0 : if (!flow)
10487 : : return -EINVAL;
10488 : :
10489 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
10490 : 0 : mlx5_flow_dev_dump_ipool(dev, flow, file, error);
10491 : : #endif
10492 : 0 : handle_idx = flow->dev_handles;
10493 [ # # ]: 0 : while (handle_idx) {
10494 : 0 : dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
10495 : : handle_idx);
10496 [ # # ]: 0 : if (!dh)
10497 : : return -ENOENT;
10498 [ # # ]: 0 : if (dh->drv_flow) {
10499 [ # # ]: 0 : if (sh->config.dv_flow_en == 2)
10500 : : return -ENOTSUP;
10501 : :
10502 : 0 : ret = mlx5_devx_cmd_flow_single_dump(dh->drv_flow,
10503 : : file);
10504 [ # # ]: 0 : if (ret)
10505 : : return -ENOENT;
10506 : : }
10507 : 0 : handle_idx = dh->next.next;
10508 : : }
10509 : : return 0;
10510 : : }
10511 : :
10512 : : /**
10513 : : * Get aged-out flows.
10514 : : *
10515 : : * @param[in] dev
10516 : : * Pointer to the Ethernet device structure.
10517 : : * @param[in] context
10518 : : * The address of an array of pointers to the aged-out flows contexts.
10519 : : * @param[in] nb_countexts
10520 : : * The length of context array pointers.
10521 : : * @param[out] error
10522 : : * Perform verbose error reporting if not NULL. Initialized in case of
10523 : : * error only.
10524 : : *
10525 : : * @return
10526 : : * how many contexts get in success, otherwise negative errno value.
10527 : : * if nb_contexts is 0, return the amount of all aged contexts.
10528 : : * if nb_contexts is not 0 , return the amount of aged flows reported
10529 : : * in the context array.
10530 : : */
10531 : : int
10532 [ # # ]: 0 : mlx5_flow_get_aged_flows(struct rte_eth_dev *dev, void **contexts,
10533 : : uint32_t nb_contexts, struct rte_flow_error *error)
10534 : : {
10535 : : struct rte_flow_attr attr = { .transfer = 0 };
10536 : :
10537 : 0 : return flow_get_drv_ops(flow_get_drv_type(dev, &attr))->get_aged_flows
10538 : : (dev, contexts, nb_contexts, error);
10539 : : }
10540 : :
10541 : : /**
10542 : : * Get aged-out flows per HWS queue.
10543 : : *
10544 : : * @param[in] dev
10545 : : * Pointer to the Ethernet device structure.
10546 : : * @param[in] queue_id
10547 : : * Flow queue to query.
10548 : : * @param[in] context
10549 : : * The address of an array of pointers to the aged-out flows contexts.
10550 : : * @param[in] nb_countexts
10551 : : * The length of context array pointers.
10552 : : * @param[out] error
10553 : : * Perform verbose error reporting if not NULL. Initialized in case of
10554 : : * error only.
10555 : : *
10556 : : * @return
10557 : : * how many contexts get in success, otherwise negative errno value.
10558 : : * if nb_contexts is 0, return the amount of all aged contexts.
10559 : : * if nb_contexts is not 0 , return the amount of aged flows reported
10560 : : * in the context array.
10561 : : */
10562 : : int
10563 [ # # ]: 0 : mlx5_flow_get_q_aged_flows(struct rte_eth_dev *dev, uint32_t queue_id,
10564 : : void **contexts, uint32_t nb_contexts,
10565 : : struct rte_flow_error *error)
10566 : : {
10567 : : const struct mlx5_flow_driver_ops *fops;
10568 : : struct rte_flow_attr attr = { 0 };
10569 : :
10570 : : if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_HW) {
10571 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
10572 : 0 : return fops->get_q_aged_flows(dev, queue_id, contexts,
10573 : : nb_contexts, error);
10574 : : }
10575 : 0 : DRV_LOG(ERR, "port %u queue %u get aged flows is not supported.",
10576 : : dev->data->port_id, queue_id);
10577 : 0 : return rte_flow_error_set(error, ENOTSUP,
10578 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10579 : : "get Q aged flows with incorrect steering mode");
10580 : : }
10581 : :
10582 : : /* Wrapper for driver action_validate op callback */
10583 : : static int
10584 : 0 : flow_drv_action_validate(struct rte_eth_dev *dev,
10585 : : const struct rte_flow_indir_action_conf *conf,
10586 : : const struct rte_flow_action *action,
10587 : : const struct mlx5_flow_driver_ops *fops,
10588 : : struct rte_flow_error *error)
10589 : : {
10590 : : static const char err_msg[] = "indirect action validation unsupported";
10591 : :
10592 [ # # ]: 0 : if (!fops->action_validate) {
10593 : 0 : DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
10594 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
10595 : : NULL, err_msg);
10596 : 0 : return -rte_errno;
10597 : : }
10598 : 0 : return fops->action_validate(dev, conf, action, error);
10599 : : }
10600 : :
10601 : : /**
10602 : : * Destroys the shared action by handle.
10603 : : *
10604 : : * @param dev
10605 : : * Pointer to Ethernet device structure.
10606 : : * @param[in] handle
10607 : : * Handle for the indirect action object to be destroyed.
10608 : : * @param[out] error
10609 : : * Perform verbose error reporting if not NULL. PMDs initialize this
10610 : : * structure in case of error only.
10611 : : *
10612 : : * @return
10613 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
10614 : : *
10615 : : * @note: wrapper for driver action_create op callback.
10616 : : */
10617 : : static int
10618 [ # # ]: 0 : mlx5_action_handle_destroy(struct rte_eth_dev *dev,
10619 : : struct rte_flow_action_handle *handle,
10620 : : struct rte_flow_error *error)
10621 : : {
10622 : : static const char err_msg[] = "indirect action destruction unsupported";
10623 : : struct rte_flow_attr attr = { .transfer = 0 };
10624 : 0 : const struct mlx5_flow_driver_ops *fops =
10625 : : flow_get_drv_ops(flow_get_drv_type(dev, &attr));
10626 : :
10627 [ # # ]: 0 : if (!fops->action_destroy) {
10628 : 0 : DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
10629 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
10630 : : NULL, err_msg);
10631 : 0 : return -rte_errno;
10632 : : }
10633 : 0 : return fops->action_destroy(dev, handle, error);
10634 : : }
10635 : :
10636 : : /* Wrapper for driver action_destroy op callback */
10637 : : static int
10638 : 0 : flow_drv_action_update(struct rte_eth_dev *dev,
10639 : : struct rte_flow_action_handle *handle,
10640 : : const void *update,
10641 : : const struct mlx5_flow_driver_ops *fops,
10642 : : struct rte_flow_error *error)
10643 : : {
10644 : : static const char err_msg[] = "indirect action update unsupported";
10645 : :
10646 [ # # ]: 0 : if (!fops->action_update) {
10647 : 0 : DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
10648 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
10649 : : NULL, err_msg);
10650 : 0 : return -rte_errno;
10651 : : }
10652 : 0 : return fops->action_update(dev, handle, update, error);
10653 : : }
10654 : :
10655 : : /* Wrapper for driver action_destroy op callback */
10656 : : static int
10657 : 0 : flow_drv_action_query(struct rte_eth_dev *dev,
10658 : : const struct rte_flow_action_handle *handle,
10659 : : void *data,
10660 : : const struct mlx5_flow_driver_ops *fops,
10661 : : struct rte_flow_error *error)
10662 : : {
10663 : : static const char err_msg[] = "indirect action query unsupported";
10664 : :
10665 [ # # ]: 0 : if (!fops->action_query) {
10666 : 0 : DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
10667 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
10668 : : NULL, err_msg);
10669 : 0 : return -rte_errno;
10670 : : }
10671 : 0 : return fops->action_query(dev, handle, data, error);
10672 : : }
10673 : :
10674 : : /**
10675 : : * Create indirect action for reuse in multiple flow rules.
10676 : : *
10677 : : * @param dev
10678 : : * Pointer to Ethernet device structure.
10679 : : * @param conf
10680 : : * Pointer to indirect action object configuration.
10681 : : * @param[in] action
10682 : : * Action configuration for indirect action object creation.
10683 : : * @param[out] error
10684 : : * Perform verbose error reporting if not NULL. PMDs initialize this
10685 : : * structure in case of error only.
10686 : : * @return
10687 : : * A valid handle in case of success, NULL otherwise and rte_errno is set.
10688 : : */
10689 : : static struct rte_flow_action_handle *
10690 [ # # ]: 0 : mlx5_action_handle_create(struct rte_eth_dev *dev,
10691 : : const struct rte_flow_indir_action_conf *conf,
10692 : : const struct rte_flow_action *action,
10693 : : struct rte_flow_error *error)
10694 : : {
10695 : : static const char err_msg[] = "indirect action creation unsupported";
10696 : : struct rte_flow_attr attr = { .transfer = 0 };
10697 : 0 : const struct mlx5_flow_driver_ops *fops =
10698 : : flow_get_drv_ops(flow_get_drv_type(dev, &attr));
10699 : :
10700 [ # # ]: 0 : if (flow_drv_action_validate(dev, conf, action, fops, error))
10701 : : return NULL;
10702 [ # # ]: 0 : if (!fops->action_create) {
10703 : 0 : DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
10704 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
10705 : : NULL, err_msg);
10706 : 0 : return NULL;
10707 : : }
10708 : 0 : return fops->action_create(dev, conf, action, error);
10709 : : }
10710 : :
10711 : : /**
10712 : : * Updates inplace the indirect action configuration pointed by *handle*
10713 : : * with the configuration provided as *update* argument.
10714 : : * The update of the indirect action configuration effects all flow rules
10715 : : * reusing the action via handle.
10716 : : *
10717 : : * @param dev
10718 : : * Pointer to Ethernet device structure.
10719 : : * @param[in] handle
10720 : : * Handle for the indirect action to be updated.
10721 : : * @param[in] update
10722 : : * Action specification used to modify the action pointed by handle.
10723 : : * *update* could be of same type with the action pointed by the *handle*
10724 : : * handle argument, or some other structures like a wrapper, depending on
10725 : : * the indirect action type.
10726 : : * @param[out] error
10727 : : * Perform verbose error reporting if not NULL. PMDs initialize this
10728 : : * structure in case of error only.
10729 : : *
10730 : : * @return
10731 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
10732 : : */
10733 : : static int
10734 [ # # ]: 0 : mlx5_action_handle_update(struct rte_eth_dev *dev,
10735 : : struct rte_flow_action_handle *handle,
10736 : : const void *update,
10737 : : struct rte_flow_error *error)
10738 : : {
10739 : : struct rte_flow_attr attr = { .transfer = 0 };
10740 : 0 : const struct mlx5_flow_driver_ops *fops =
10741 : : flow_get_drv_ops(flow_get_drv_type(dev, &attr));
10742 : : int ret;
10743 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
10744 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
10745 : :
10746 [ # # ]: 0 : switch (type) {
10747 : : case MLX5_INDIRECT_ACTION_TYPE_CT:
10748 : : case MLX5_INDIRECT_ACTION_TYPE_METER_MARK:
10749 : : ret = 0;
10750 : : break;
10751 : 0 : default:
10752 : 0 : ret = flow_drv_action_validate(dev, NULL,
10753 : : (const struct rte_flow_action *)update,
10754 : : fops, error);
10755 : : }
10756 [ # # ]: 0 : if (ret)
10757 : : return ret;
10758 : 0 : return flow_drv_action_update(dev, handle, update, fops,
10759 : : error);
10760 : : }
10761 : :
10762 : : /**
10763 : : * Query the indirect action by handle.
10764 : : *
10765 : : * This function allows retrieving action-specific data such as counters.
10766 : : * Data is gathered by special action which may be present/referenced in
10767 : : * more than one flow rule definition.
10768 : : *
10769 : : * see @RTE_FLOW_ACTION_TYPE_COUNT
10770 : : *
10771 : : * @param dev
10772 : : * Pointer to Ethernet device structure.
10773 : : * @param[in] handle
10774 : : * Handle for the indirect action to query.
10775 : : * @param[in, out] data
10776 : : * Pointer to storage for the associated query data type.
10777 : : * @param[out] error
10778 : : * Perform verbose error reporting if not NULL. PMDs initialize this
10779 : : * structure in case of error only.
10780 : : *
10781 : : * @return
10782 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
10783 : : */
10784 : : static int
10785 [ # # ]: 0 : mlx5_action_handle_query(struct rte_eth_dev *dev,
10786 : : const struct rte_flow_action_handle *handle,
10787 : : void *data,
10788 : : struct rte_flow_error *error)
10789 : : {
10790 : : struct rte_flow_attr attr = { .transfer = 0 };
10791 : 0 : const struct mlx5_flow_driver_ops *fops =
10792 : : flow_get_drv_ops(flow_get_drv_type(dev, &attr));
10793 : :
10794 : 0 : return flow_drv_action_query(dev, handle, data, fops, error);
10795 : : }
10796 : :
10797 : : static int
10798 [ # # ]: 0 : mlx5_action_handle_query_update(struct rte_eth_dev *dev,
10799 : : struct rte_flow_action_handle *handle,
10800 : : const void *update, void *query,
10801 : : enum rte_flow_query_update_mode qu_mode,
10802 : : struct rte_flow_error *error)
10803 : : {
10804 : : struct rte_flow_attr attr = { .transfer = 0 };
10805 : : enum mlx5_flow_drv_type drv_type = flow_get_drv_type(dev, &attr);
10806 : : const struct mlx5_flow_driver_ops *fops;
10807 : :
10808 : : if (drv_type == MLX5_FLOW_TYPE_MIN || drv_type == MLX5_FLOW_TYPE_MAX)
10809 : : return rte_flow_error_set(error, ENOTSUP,
10810 : : RTE_FLOW_ERROR_TYPE_ACTION,
10811 : : NULL, "invalid driver type");
10812 : 0 : fops = flow_get_drv_ops(drv_type);
10813 [ # # # # ]: 0 : if (!fops || !fops->action_query_update)
10814 : 0 : return rte_flow_error_set(error, ENOTSUP,
10815 : : RTE_FLOW_ERROR_TYPE_ACTION,
10816 : : NULL, "no query_update handler");
10817 : 0 : return fops->action_query_update(dev, handle, update,
10818 : : query, qu_mode, error);
10819 : : }
10820 : :
10821 : :
10822 : : #define MLX5_DRV_FOPS_OR_ERR(dev, fops, drv_cb, ret) \
10823 : : { \
10824 : : struct rte_flow_attr attr = { .transfer = 0 }; \
10825 : : enum mlx5_flow_drv_type drv_type = flow_get_drv_type((dev), &attr); \
10826 : : if (drv_type == MLX5_FLOW_TYPE_MIN || \
10827 : : drv_type == MLX5_FLOW_TYPE_MAX) { \
10828 : : rte_flow_error_set(error, ENOTSUP, \
10829 : : RTE_FLOW_ERROR_TYPE_ACTION, \
10830 : : NULL, "invalid driver type"); \
10831 : : return ret; \
10832 : : } \
10833 : : (fops) = flow_get_drv_ops(drv_type); \
10834 : : if (!(fops) || !(fops)->drv_cb) { \
10835 : : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, \
10836 : : NULL, "no action_list handler"); \
10837 : : return ret; \
10838 : : } \
10839 : : }
10840 : :
10841 : : static struct rte_flow_action_list_handle *
10842 [ # # ]: 0 : mlx5_action_list_handle_create(struct rte_eth_dev *dev,
10843 : : const struct rte_flow_indir_action_conf *conf,
10844 : : const struct rte_flow_action *actions,
10845 : : struct rte_flow_error *error)
10846 : : {
10847 : : const struct mlx5_flow_driver_ops *fops;
10848 : :
10849 [ # # # # ]: 0 : MLX5_DRV_FOPS_OR_ERR(dev, fops, action_list_handle_create, NULL);
10850 : 0 : return fops->action_list_handle_create(dev, conf, actions, error);
10851 : : }
10852 : :
10853 : : static int
10854 [ # # ]: 0 : mlx5_action_list_handle_destroy(struct rte_eth_dev *dev,
10855 : : struct rte_flow_action_list_handle *handle,
10856 : : struct rte_flow_error *error)
10857 : : {
10858 : : const struct mlx5_flow_driver_ops *fops;
10859 : :
10860 [ # # # # ]: 0 : MLX5_DRV_FOPS_OR_ERR(dev, fops, action_list_handle_destroy, ENOTSUP);
10861 : 0 : return fops->action_list_handle_destroy(dev, handle, error);
10862 : : }
10863 : :
10864 : : static int
10865 [ # # ]: 0 : mlx5_flow_action_list_handle_query_update(struct rte_eth_dev *dev,
10866 : : const
10867 : : struct rte_flow_action_list_handle *handle,
10868 : : const void **update, void **query,
10869 : : enum rte_flow_query_update_mode mode,
10870 : : struct rte_flow_error *error)
10871 : : {
10872 : : const struct mlx5_flow_driver_ops *fops;
10873 : :
10874 [ # # # # ]: 0 : MLX5_DRV_FOPS_OR_ERR(dev, fops,
10875 : : action_list_handle_query_update, ENOTSUP);
10876 : 0 : return fops->action_list_handle_query_update(dev, handle, update, query,
10877 : : mode, error);
10878 : : }
10879 : : static int
10880 [ # # ]: 0 : mlx5_flow_calc_table_hash(struct rte_eth_dev *dev,
10881 : : const struct rte_flow_template_table *table,
10882 : : const struct rte_flow_item pattern[],
10883 : : uint8_t pattern_template_index,
10884 : : uint32_t *hash, struct rte_flow_error *error)
10885 : : {
10886 : : struct rte_flow_attr attr = { .transfer = 0 };
10887 : : enum mlx5_flow_drv_type drv_type = flow_get_drv_type(dev, &attr);
10888 : : const struct mlx5_flow_driver_ops *fops;
10889 : :
10890 : : if (drv_type == MLX5_FLOW_TYPE_MIN || drv_type == MLX5_FLOW_TYPE_MAX)
10891 : : return rte_flow_error_set(error, ENOTSUP,
10892 : : RTE_FLOW_ERROR_TYPE_ACTION,
10893 : : NULL, "invalid driver type");
10894 : 0 : fops = flow_get_drv_ops(drv_type);
10895 [ # # # # ]: 0 : if (!fops || !fops->action_query_update)
10896 : 0 : return rte_flow_error_set(error, ENOTSUP,
10897 : : RTE_FLOW_ERROR_TYPE_ACTION,
10898 : : NULL, "no query_update handler");
10899 : 0 : return fops->flow_calc_table_hash(dev, table, pattern, pattern_template_index,
10900 : : hash, error);
10901 : : }
10902 : :
10903 : : static int
10904 [ # # ]: 0 : mlx5_flow_calc_encap_hash(struct rte_eth_dev *dev,
10905 : : const struct rte_flow_item pattern[],
10906 : : enum rte_flow_encap_hash_field dest_field,
10907 : : uint8_t *hash,
10908 : : struct rte_flow_error *error)
10909 : : {
10910 : : enum mlx5_flow_drv_type drv_type = flow_get_drv_type(dev, NULL);
10911 : : const struct mlx5_flow_driver_ops *fops;
10912 : :
10913 : : if (drv_type == MLX5_FLOW_TYPE_MIN || drv_type == MLX5_FLOW_TYPE_MAX)
10914 : 0 : return rte_flow_error_set(error, ENOTSUP,
10915 : : RTE_FLOW_ERROR_TYPE_ACTION,
10916 : : NULL, "invalid driver type");
10917 : 0 : fops = flow_get_drv_ops(drv_type);
10918 [ # # # # ]: 0 : if (!fops || !fops->flow_calc_encap_hash)
10919 : 0 : return rte_flow_error_set(error, ENOTSUP,
10920 : : RTE_FLOW_ERROR_TYPE_ACTION,
10921 : : NULL, "no calc encap hash handler");
10922 : 0 : return fops->flow_calc_encap_hash(dev, pattern, dest_field, hash, error);
10923 : : }
10924 : :
10925 : : static int
10926 [ # # ]: 0 : mlx5_template_table_resize(struct rte_eth_dev *dev,
10927 : : struct rte_flow_template_table *table,
10928 : : uint32_t nb_rules, struct rte_flow_error *error)
10929 : : {
10930 : : const struct mlx5_flow_driver_ops *fops;
10931 : :
10932 [ # # # # ]: 0 : MLX5_DRV_FOPS_OR_ERR(dev, fops, table_resize, ENOTSUP);
10933 : 0 : return fops->table_resize(dev, table, nb_rules, error);
10934 : : }
10935 : :
10936 : : static int
10937 [ # # ]: 0 : mlx5_table_resize_complete(struct rte_eth_dev *dev,
10938 : : struct rte_flow_template_table *table,
10939 : : struct rte_flow_error *error)
10940 : : {
10941 : : const struct mlx5_flow_driver_ops *fops;
10942 : :
10943 [ # # # # ]: 0 : MLX5_DRV_FOPS_OR_ERR(dev, fops, table_resize_complete, ENOTSUP);
10944 : 0 : return fops->table_resize_complete(dev, table, error);
10945 : : }
10946 : :
10947 : : static int
10948 [ # # ]: 0 : mlx5_flow_async_update_resized(struct rte_eth_dev *dev, uint32_t queue,
10949 : : const struct rte_flow_op_attr *op_attr,
10950 : : struct rte_flow *rule, void *user_data,
10951 : : struct rte_flow_error *error)
10952 : : {
10953 : : const struct mlx5_flow_driver_ops *fops;
10954 : :
10955 [ # # # # ]: 0 : MLX5_DRV_FOPS_OR_ERR(dev, fops, flow_update_resized, ENOTSUP);
10956 : 0 : return fops->flow_update_resized(dev, queue, op_attr, rule, user_data, error);
10957 : : }
10958 : :
10959 : : /**
10960 : : * Destroy all indirect actions (shared RSS).
10961 : : *
10962 : : * @param dev
10963 : : * Pointer to Ethernet device.
10964 : : *
10965 : : * @return
10966 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
10967 : : */
10968 : : int
10969 : 0 : mlx5_action_handle_flush(struct rte_eth_dev *dev)
10970 : : {
10971 : : struct rte_flow_error error;
10972 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10973 : : struct mlx5_shared_action_rss *shared_rss;
10974 : : int ret = 0;
10975 : : uint32_t idx;
10976 : :
10977 [ # # # # ]: 0 : ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
10978 : : priv->rss_shared_actions, idx, shared_rss, next) {
10979 [ # # ]: 0 : ret |= mlx5_action_handle_destroy(dev,
10980 : 0 : (struct rte_flow_action_handle *)(uintptr_t)idx, &error);
10981 : : }
10982 : 0 : return ret;
10983 : : }
10984 : :
10985 : : /**
10986 : : * Validate existing indirect actions against current device configuration
10987 : : * and attach them to device resources.
10988 : : *
10989 : : * @param dev
10990 : : * Pointer to Ethernet device.
10991 : : *
10992 : : * @return
10993 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
10994 : : */
10995 : : int
10996 : 0 : mlx5_action_handle_attach(struct rte_eth_dev *dev)
10997 : : {
10998 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10999 : : int ret = 0;
11000 : : struct mlx5_ind_table_obj *ind_tbl, *ind_tbl_last;
11001 : :
11002 [ # # ]: 0 : LIST_FOREACH(ind_tbl, &priv->standalone_ind_tbls, next) {
11003 : : const char *message;
11004 : : uint32_t queue_idx;
11005 : :
11006 : 0 : ret = mlx5_validate_rss_queues(dev, ind_tbl->queues,
11007 : : ind_tbl->queues_n,
11008 : : &message, &queue_idx);
11009 [ # # ]: 0 : if (ret != 0) {
11010 : 0 : DRV_LOG(ERR, "Port %u cannot use queue %u in RSS: %s",
11011 : : dev->data->port_id, ind_tbl->queues[queue_idx],
11012 : : message);
11013 : 0 : break;
11014 : : }
11015 : : }
11016 [ # # ]: 0 : if (ret != 0)
11017 : : return ret;
11018 [ # # ]: 0 : LIST_FOREACH(ind_tbl, &priv->standalone_ind_tbls, next) {
11019 : 0 : ret = mlx5_ind_table_obj_attach(dev, ind_tbl);
11020 [ # # ]: 0 : if (ret != 0) {
11021 : 0 : DRV_LOG(ERR, "Port %u could not attach "
11022 : : "indirection table obj %p",
11023 : : dev->data->port_id, (void *)ind_tbl);
11024 : 0 : goto error;
11025 : : }
11026 : : }
11027 : :
11028 : : return 0;
11029 : : error:
11030 : : ind_tbl_last = ind_tbl;
11031 [ # # ]: 0 : LIST_FOREACH(ind_tbl, &priv->standalone_ind_tbls, next) {
11032 [ # # ]: 0 : if (ind_tbl == ind_tbl_last)
11033 : : break;
11034 [ # # ]: 0 : if (mlx5_ind_table_obj_detach(dev, ind_tbl) != 0)
11035 : 0 : DRV_LOG(CRIT, "Port %u could not detach "
11036 : : "indirection table obj %p on rollback",
11037 : : dev->data->port_id, (void *)ind_tbl);
11038 : : }
11039 : : return ret;
11040 : : }
11041 : :
11042 : : /**
11043 : : * Detach indirect actions of the device from its resources.
11044 : : *
11045 : : * @param dev
11046 : : * Pointer to Ethernet device.
11047 : : *
11048 : : * @return
11049 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
11050 : : */
11051 : : int
11052 : 0 : mlx5_action_handle_detach(struct rte_eth_dev *dev)
11053 : : {
11054 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11055 : : int ret = 0;
11056 : : struct mlx5_ind_table_obj *ind_tbl, *ind_tbl_last;
11057 : :
11058 [ # # ]: 0 : LIST_FOREACH(ind_tbl, &priv->standalone_ind_tbls, next) {
11059 : 0 : ret = mlx5_ind_table_obj_detach(dev, ind_tbl);
11060 [ # # ]: 0 : if (ret != 0) {
11061 : 0 : DRV_LOG(ERR, "Port %u could not detach "
11062 : : "indirection table obj %p",
11063 : : dev->data->port_id, (void *)ind_tbl);
11064 : 0 : goto error;
11065 : : }
11066 : : }
11067 : : return 0;
11068 : : error:
11069 : : ind_tbl_last = ind_tbl;
11070 [ # # ]: 0 : LIST_FOREACH(ind_tbl, &priv->standalone_ind_tbls, next) {
11071 [ # # ]: 0 : if (ind_tbl == ind_tbl_last)
11072 : : break;
11073 [ # # ]: 0 : if (mlx5_ind_table_obj_attach(dev, ind_tbl) != 0)
11074 : 0 : DRV_LOG(CRIT, "Port %u could not attach "
11075 : : "indirection table obj %p on rollback",
11076 : : dev->data->port_id, (void *)ind_tbl);
11077 : : }
11078 : : return ret;
11079 : : }
11080 : :
11081 : : #ifndef HAVE_MLX5DV_DR
11082 : : #define MLX5_DOMAIN_SYNC_FLOW ((1 << 0) | (1 << 1))
11083 : : #else
11084 : : #define MLX5_DOMAIN_SYNC_FLOW \
11085 : : (MLX5DV_DR_DOMAIN_SYNC_FLAGS_SW | MLX5DV_DR_DOMAIN_SYNC_FLAGS_HW)
11086 : : #endif
11087 : :
11088 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_mlx5_sync_flow, 20.11)
11089 : 0 : int rte_pmd_mlx5_sync_flow(uint16_t port_id, uint32_t domains)
11090 : : {
11091 [ # # ]: 0 : struct rte_eth_dev *dev = &rte_eth_devices[port_id];
11092 : : const struct mlx5_flow_driver_ops *fops;
11093 : : int ret;
11094 : : struct rte_flow_attr attr = { .transfer = 0 };
11095 : :
11096 : 0 : fops = flow_get_drv_ops(flow_get_drv_type(dev, &attr));
11097 : 0 : ret = fops->sync_domain(dev, domains, MLX5_DOMAIN_SYNC_FLOW);
11098 [ # # ]: 0 : if (ret > 0)
11099 : 0 : ret = -ret;
11100 : 0 : return ret;
11101 : : }
11102 : :
11103 : : const struct mlx5_flow_tunnel *
11104 : 0 : mlx5_get_tof(const struct rte_flow_item *item,
11105 : : const struct rte_flow_action *action,
11106 : : enum mlx5_tof_rule_type *rule_type)
11107 : : {
11108 [ # # ]: 0 : for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
11109 [ # # ]: 0 : if (item->type == (typeof(item->type))
11110 : : MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL) {
11111 : 0 : *rule_type = MLX5_TUNNEL_OFFLOAD_MATCH_RULE;
11112 : 0 : return flow_items_to_tunnel(item);
11113 : : }
11114 : : }
11115 [ # # ]: 0 : for (; action->conf != RTE_FLOW_ACTION_TYPE_END; action++) {
11116 [ # # ]: 0 : if (action->type == (typeof(action->type))
11117 : : MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET) {
11118 : 0 : *rule_type = MLX5_TUNNEL_OFFLOAD_SET_RULE;
11119 : 0 : return flow_actions_to_tunnel(action);
11120 : : }
11121 : : }
11122 : : return NULL;
11123 : : }
11124 : :
11125 : : /**
11126 : : * tunnel offload functionality is defined for DV environment only
11127 : : */
11128 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
11129 : : __extension__
11130 : : union tunnel_offload_mark {
11131 : : uint32_t val;
11132 : : struct {
11133 : : uint32_t app_reserve:8;
11134 : : uint32_t table_id:15;
11135 : : uint32_t transfer:1;
11136 : : uint32_t _unused_:8;
11137 : : };
11138 : : };
11139 : :
11140 : : static bool
11141 : : mlx5_access_tunnel_offload_db
11142 : : (struct rte_eth_dev *dev,
11143 : : bool (*match)(struct rte_eth_dev *,
11144 : : struct mlx5_flow_tunnel *, const void *),
11145 : : void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
11146 : : void (*miss)(struct rte_eth_dev *, void *),
11147 : : void *ctx, bool lock_op);
11148 : :
11149 : : static int
11150 : 0 : flow_tunnel_add_default_miss(struct rte_eth_dev *dev,
11151 : : struct rte_flow *flow,
11152 : : const struct rte_flow_attr *attr,
11153 : : const struct rte_flow_action *app_actions,
11154 : : uint32_t flow_idx,
11155 : : const struct mlx5_flow_tunnel *tunnel,
11156 : : struct tunnel_default_miss_ctx *ctx,
11157 : : struct rte_flow_error *error)
11158 : : {
11159 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11160 : : struct mlx5_flow *dev_flow;
11161 : 0 : struct rte_flow_attr miss_attr = *attr;
11162 : 0 : const struct rte_flow_item miss_items[2] = {
11163 : : {
11164 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
11165 : : .spec = NULL,
11166 : : .last = NULL,
11167 : : .mask = NULL
11168 : : },
11169 : : {
11170 : : .type = RTE_FLOW_ITEM_TYPE_END,
11171 : : .spec = NULL,
11172 : : .last = NULL,
11173 : : .mask = NULL
11174 : : }
11175 : : };
11176 : : union tunnel_offload_mark mark_id;
11177 : : struct rte_flow_action_mark miss_mark;
11178 : 0 : struct rte_flow_action miss_actions[3] = {
11179 : : [0] = { .type = RTE_FLOW_ACTION_TYPE_MARK, .conf = &miss_mark },
11180 : : [2] = { .type = RTE_FLOW_ACTION_TYPE_END, .conf = NULL }
11181 : : };
11182 : : const struct rte_flow_action_jump *jump_data;
11183 : 0 : uint32_t i, flow_table = 0; /* prevent compilation warning */
11184 : 0 : struct flow_grp_info grp_info = {
11185 : : .external = 1,
11186 : 0 : .transfer = attr->transfer,
11187 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
11188 : : .std_tbl_fix = 0,
11189 : : };
11190 : : int ret;
11191 : :
11192 [ # # ]: 0 : if (!attr->transfer) {
11193 : : uint32_t q_size;
11194 : :
11195 : 0 : miss_actions[1].type = RTE_FLOW_ACTION_TYPE_RSS;
11196 : 0 : q_size = priv->reta_idx_n * sizeof(ctx->queue[0]);
11197 : 0 : ctx->queue = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, q_size,
11198 : : 0, SOCKET_ID_ANY);
11199 [ # # ]: 0 : if (!ctx->queue)
11200 : 0 : return rte_flow_error_set
11201 : : (error, ENOMEM,
11202 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
11203 : : NULL, "invalid default miss RSS");
11204 : 0 : ctx->action_rss.func = RTE_ETH_HASH_FUNCTION_DEFAULT;
11205 : 0 : ctx->action_rss.level = 0;
11206 : 0 : ctx->action_rss.types = priv->rss_conf.rss_hf;
11207 : 0 : ctx->action_rss.key_len = priv->rss_conf.rss_key_len;
11208 : 0 : ctx->action_rss.queue_num = priv->reta_idx_n;
11209 : 0 : ctx->action_rss.key = priv->rss_conf.rss_key;
11210 : 0 : ctx->action_rss.queue = ctx->queue;
11211 [ # # # # ]: 0 : if (!priv->reta_idx_n || !priv->rxqs_n)
11212 : 0 : return rte_flow_error_set
11213 : : (error, EINVAL,
11214 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
11215 : : NULL, "invalid port configuration");
11216 [ # # ]: 0 : if (!(dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG))
11217 : 0 : ctx->action_rss.types = 0;
11218 [ # # ]: 0 : for (i = 0; i != priv->reta_idx_n; ++i)
11219 : 0 : ctx->queue[i] = (*priv->reta_idx)[i];
11220 : : } else {
11221 : 0 : miss_actions[1].type = RTE_FLOW_ACTION_TYPE_JUMP;
11222 : 0 : ctx->miss_jump.group = MLX5_TNL_MISS_FDB_JUMP_GRP;
11223 : : }
11224 : 0 : miss_actions[1].conf = (typeof(miss_actions[1].conf))ctx->raw;
11225 [ # # ]: 0 : for (; app_actions->type != RTE_FLOW_ACTION_TYPE_JUMP; app_actions++);
11226 : 0 : jump_data = app_actions->conf;
11227 : 0 : miss_attr.priority = MLX5_TNL_MISS_RULE_PRIORITY;
11228 : 0 : miss_attr.group = jump_data->group;
11229 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel, jump_data->group,
11230 : : &flow_table, &grp_info, error);
11231 [ # # ]: 0 : if (ret)
11232 : 0 : return rte_flow_error_set(error, EINVAL,
11233 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
11234 : : NULL, "invalid tunnel id");
11235 : 0 : mark_id.app_reserve = 0;
11236 : 0 : mark_id.table_id = tunnel_flow_tbl_to_id(flow_table);
11237 : 0 : mark_id.transfer = !!attr->transfer;
11238 : 0 : mark_id._unused_ = 0;
11239 : 0 : miss_mark.id = mark_id.val;
11240 : : dev_flow = flow_drv_prepare(dev, flow, &miss_attr,
11241 : : miss_items, miss_actions, flow_idx, error);
11242 [ # # ]: 0 : if (!dev_flow)
11243 : 0 : return -rte_errno;
11244 : 0 : dev_flow->flow = flow;
11245 : 0 : dev_flow->external = true;
11246 : 0 : dev_flow->tunnel = tunnel;
11247 : 0 : dev_flow->tof_type = MLX5_TUNNEL_OFFLOAD_MISS_RULE;
11248 : : /* Subflow object was created, we must include one in the list. */
11249 : 0 : SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
11250 : : dev_flow->handle, next);
11251 : 0 : DRV_LOG(DEBUG,
11252 : : "port %u tunnel type=%d id=%u miss rule priority=%u group=%u",
11253 : : dev->data->port_id, tunnel->app_tunnel.type,
11254 : : tunnel->tunnel_id, miss_attr.priority, miss_attr.group);
11255 : : ret = flow_drv_translate(dev, dev_flow, &miss_attr, miss_items,
11256 : : miss_actions, error);
11257 [ # # ]: 0 : if (!ret)
11258 : 0 : ret = flow_mreg_update_copy_table(dev, flow, miss_actions,
11259 : : error);
11260 : :
11261 : : return ret;
11262 : : }
11263 : :
11264 : : static const struct mlx5_flow_tbl_data_entry *
11265 : 0 : tunnel_mark_decode(struct rte_eth_dev *dev, uint32_t mark)
11266 : : {
11267 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11268 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
11269 : : struct mlx5_list_entry *he;
11270 : 0 : union tunnel_offload_mark mbits = { .val = mark };
11271 : 0 : union mlx5_flow_tbl_key table_key = {
11272 : : {
11273 : 0 : .level = tunnel_id_to_flow_tbl(mbits.table_id),
11274 : : .id = 0,
11275 : : .reserved = 0,
11276 : : .dummy = 0,
11277 : 0 : .is_fdb = !!mbits.transfer,
11278 : : .is_egress = 0,
11279 : : }
11280 : : };
11281 : 0 : struct mlx5_flow_cb_ctx ctx = {
11282 : : .data = &table_key.v64,
11283 : : };
11284 : :
11285 : 0 : he = mlx5_hlist_lookup(sh->flow_tbls, table_key.v64, &ctx);
11286 : : return he ?
11287 [ # # ]: 0 : container_of(he, struct mlx5_flow_tbl_data_entry, entry) : NULL;
11288 : : }
11289 : :
11290 : : static void
11291 : 0 : mlx5_flow_tunnel_grp2tbl_remove_cb(void *tool_ctx,
11292 : : struct mlx5_list_entry *entry)
11293 : : {
11294 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11295 : : struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
11296 : :
11297 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
11298 : : tunnel_flow_tbl_to_id(tte->flow_table));
11299 : 0 : mlx5_free(tte);
11300 : 0 : }
11301 : :
11302 : : static int
11303 : 0 : mlx5_flow_tunnel_grp2tbl_match_cb(void *tool_ctx __rte_unused,
11304 : : struct mlx5_list_entry *entry, void *cb_ctx)
11305 : : {
11306 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11307 : : union tunnel_tbl_key tbl = {
11308 : 0 : .val = *(uint64_t *)(ctx->data),
11309 : : };
11310 : : struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
11311 : :
11312 [ # # # # ]: 0 : return tbl.tunnel_id != tte->tunnel_id || tbl.group != tte->group;
11313 : : }
11314 : :
11315 : : static struct mlx5_list_entry *
11316 : 0 : mlx5_flow_tunnel_grp2tbl_create_cb(void *tool_ctx, void *cb_ctx)
11317 : : {
11318 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11319 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11320 : : struct tunnel_tbl_entry *tte;
11321 : : union tunnel_tbl_key tbl = {
11322 : 0 : .val = *(uint64_t *)(ctx->data),
11323 : : };
11324 : :
11325 : 0 : tte = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO,
11326 : : sizeof(*tte), 0,
11327 : : SOCKET_ID_ANY);
11328 [ # # ]: 0 : if (!tte)
11329 : 0 : goto err;
11330 : 0 : mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
11331 : : &tte->flow_table);
11332 [ # # ]: 0 : if (tte->flow_table >= MLX5_MAX_TABLES) {
11333 : 0 : DRV_LOG(ERR, "Tunnel TBL ID %d exceed max limit.",
11334 : : tte->flow_table);
11335 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
11336 : : tte->flow_table);
11337 : 0 : goto err;
11338 [ # # ]: 0 : } else if (!tte->flow_table) {
11339 : 0 : goto err;
11340 : : }
11341 : 0 : tte->flow_table = tunnel_id_to_flow_tbl(tte->flow_table);
11342 : 0 : tte->tunnel_id = tbl.tunnel_id;
11343 : 0 : tte->group = tbl.group;
11344 : 0 : return &tte->hash;
11345 : 0 : err:
11346 [ # # ]: 0 : if (tte)
11347 : 0 : mlx5_free(tte);
11348 : : return NULL;
11349 : : }
11350 : :
11351 : : static struct mlx5_list_entry *
11352 : 0 : mlx5_flow_tunnel_grp2tbl_clone_cb(void *tool_ctx __rte_unused,
11353 : : struct mlx5_list_entry *oentry,
11354 : : void *cb_ctx __rte_unused)
11355 : : {
11356 : 0 : struct tunnel_tbl_entry *tte = mlx5_malloc(MLX5_MEM_SYS, sizeof(*tte),
11357 : : 0, SOCKET_ID_ANY);
11358 : :
11359 [ # # ]: 0 : if (!tte)
11360 : : return NULL;
11361 : : memcpy(tte, oentry, sizeof(*tte));
11362 : 0 : return &tte->hash;
11363 : : }
11364 : :
11365 : : static void
11366 : 0 : mlx5_flow_tunnel_grp2tbl_clone_free_cb(void *tool_ctx __rte_unused,
11367 : : struct mlx5_list_entry *entry)
11368 : : {
11369 : : struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
11370 : :
11371 : 0 : mlx5_free(tte);
11372 : 0 : }
11373 : :
11374 : : static uint32_t
11375 : 0 : tunnel_flow_group_to_flow_table(struct rte_eth_dev *dev,
11376 : : const struct mlx5_flow_tunnel *tunnel,
11377 : : uint32_t group, uint32_t *table,
11378 : : struct rte_flow_error *error)
11379 : : {
11380 : : struct mlx5_list_entry *he;
11381 : : struct tunnel_tbl_entry *tte;
11382 [ # # ]: 0 : union tunnel_tbl_key key = {
11383 [ # # ]: 0 : .tunnel_id = tunnel ? tunnel->tunnel_id : 0,
11384 : : .group = group
11385 : : };
11386 : : struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
11387 : : struct mlx5_hlist *group_hash;
11388 : 0 : struct mlx5_flow_cb_ctx ctx = {
11389 : : .data = &key.val,
11390 : : };
11391 : :
11392 [ # # ]: 0 : group_hash = tunnel ? tunnel->groups : thub->groups;
11393 : 0 : he = mlx5_hlist_register(group_hash, key.val, &ctx);
11394 [ # # ]: 0 : if (!he)
11395 : 0 : return rte_flow_error_set(error, EINVAL,
11396 : : RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
11397 : : NULL,
11398 : : "tunnel group index not supported");
11399 : : tte = container_of(he, typeof(*tte), hash);
11400 : 0 : *table = tte->flow_table;
11401 : 0 : DRV_LOG(DEBUG, "port %u tunnel %u group=%#x table=%#x",
11402 : : dev->data->port_id, key.tunnel_id, group, *table);
11403 : 0 : return 0;
11404 : : }
11405 : :
11406 : : static void
11407 : 0 : mlx5_flow_tunnel_free(struct rte_eth_dev *dev,
11408 : : struct mlx5_flow_tunnel *tunnel)
11409 : : {
11410 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11411 : : struct mlx5_indexed_pool *ipool;
11412 : :
11413 : 0 : DRV_LOG(DEBUG, "port %u release pmd tunnel id=0x%x",
11414 : : dev->data->port_id, tunnel->tunnel_id);
11415 [ # # ]: 0 : LIST_REMOVE(tunnel, chain);
11416 : 0 : mlx5_hlist_destroy(tunnel->groups);
11417 : 0 : ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
11418 : 0 : mlx5_ipool_free(ipool, tunnel->tunnel_id);
11419 : 0 : }
11420 : :
11421 : : static bool
11422 : 0 : mlx5_access_tunnel_offload_db
11423 : : (struct rte_eth_dev *dev,
11424 : : bool (*match)(struct rte_eth_dev *,
11425 : : struct mlx5_flow_tunnel *, const void *),
11426 : : void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
11427 : : void (*miss)(struct rte_eth_dev *, void *),
11428 : : void *ctx, bool lock_op)
11429 : : {
11430 : : bool verdict = false;
11431 : : struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
11432 : : struct mlx5_flow_tunnel *tunnel;
11433 : :
11434 : 0 : rte_spinlock_lock(&thub->sl);
11435 [ # # ]: 0 : LIST_FOREACH(tunnel, &thub->tunnels, chain) {
11436 : 0 : verdict = match(dev, tunnel, (const void *)ctx);
11437 [ # # ]: 0 : if (verdict)
11438 : : break;
11439 : : }
11440 [ # # ]: 0 : if (!lock_op)
11441 : : rte_spinlock_unlock(&thub->sl);
11442 [ # # ]: 0 : if (verdict && hit)
11443 : 0 : hit(dev, tunnel, ctx);
11444 [ # # ]: 0 : if (!verdict && miss)
11445 : 0 : miss(dev, ctx);
11446 [ # # ]: 0 : if (lock_op)
11447 : : rte_spinlock_unlock(&thub->sl);
11448 : :
11449 : 0 : return verdict;
11450 : : }
11451 : :
11452 : : struct tunnel_db_find_tunnel_id_ctx {
11453 : : uint32_t tunnel_id;
11454 : : struct mlx5_flow_tunnel *tunnel;
11455 : : };
11456 : :
11457 : : static bool
11458 : 0 : find_tunnel_id_match(struct rte_eth_dev *dev,
11459 : : struct mlx5_flow_tunnel *tunnel, const void *x)
11460 : : {
11461 : : const struct tunnel_db_find_tunnel_id_ctx *ctx = x;
11462 : :
11463 : : RTE_SET_USED(dev);
11464 : 0 : return tunnel->tunnel_id == ctx->tunnel_id;
11465 : : }
11466 : :
11467 : : static void
11468 : 0 : find_tunnel_id_hit(struct rte_eth_dev *dev,
11469 : : struct mlx5_flow_tunnel *tunnel, void *x)
11470 : : {
11471 : : struct tunnel_db_find_tunnel_id_ctx *ctx = x;
11472 : : RTE_SET_USED(dev);
11473 : 0 : ctx->tunnel = tunnel;
11474 : 0 : }
11475 : :
11476 : : static struct mlx5_flow_tunnel *
11477 : : mlx5_find_tunnel_id(struct rte_eth_dev *dev, uint32_t id)
11478 : : {
11479 : 0 : struct tunnel_db_find_tunnel_id_ctx ctx = {
11480 : : .tunnel_id = id,
11481 : : };
11482 : :
11483 : 0 : mlx5_access_tunnel_offload_db(dev, find_tunnel_id_match,
11484 : : find_tunnel_id_hit, NULL, &ctx, true);
11485 : :
11486 [ # # ]: 0 : return ctx.tunnel;
11487 : : }
11488 : :
11489 : : static struct mlx5_flow_tunnel *
11490 : 0 : mlx5_flow_tunnel_allocate(struct rte_eth_dev *dev,
11491 : : const struct rte_flow_tunnel *app_tunnel)
11492 : : {
11493 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11494 : : struct mlx5_indexed_pool *ipool;
11495 : : struct mlx5_flow_tunnel *tunnel;
11496 : : uint32_t id;
11497 : :
11498 : 0 : ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
11499 : 0 : tunnel = mlx5_ipool_zmalloc(ipool, &id);
11500 [ # # ]: 0 : if (!tunnel)
11501 : : return NULL;
11502 [ # # ]: 0 : if (id >= MLX5_MAX_TUNNELS) {
11503 : 0 : mlx5_ipool_free(ipool, id);
11504 : 0 : DRV_LOG(ERR, "Tunnel ID %d exceed max limit.", id);
11505 : 0 : return NULL;
11506 : : }
11507 : 0 : tunnel->groups = mlx5_hlist_create("tunnel groups", 64, false, true,
11508 : 0 : priv->sh,
11509 : : mlx5_flow_tunnel_grp2tbl_create_cb,
11510 : : mlx5_flow_tunnel_grp2tbl_match_cb,
11511 : : mlx5_flow_tunnel_grp2tbl_remove_cb,
11512 : : mlx5_flow_tunnel_grp2tbl_clone_cb,
11513 : : mlx5_flow_tunnel_grp2tbl_clone_free_cb);
11514 [ # # ]: 0 : if (!tunnel->groups) {
11515 : 0 : mlx5_ipool_free(ipool, id);
11516 : 0 : return NULL;
11517 : : }
11518 : : /* initiate new PMD tunnel */
11519 : 0 : memcpy(&tunnel->app_tunnel, app_tunnel, sizeof(*app_tunnel));
11520 : 0 : tunnel->tunnel_id = id;
11521 : 0 : tunnel->action.type = (typeof(tunnel->action.type))
11522 : : MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET;
11523 : 0 : tunnel->action.conf = tunnel;
11524 : 0 : tunnel->item.type = (typeof(tunnel->item.type))
11525 : : MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL;
11526 : 0 : tunnel->item.spec = tunnel;
11527 : 0 : tunnel->item.last = NULL;
11528 : 0 : tunnel->item.mask = NULL;
11529 : :
11530 : 0 : DRV_LOG(DEBUG, "port %u new pmd tunnel id=0x%x",
11531 : : dev->data->port_id, tunnel->tunnel_id);
11532 : :
11533 : 0 : return tunnel;
11534 : : }
11535 : :
11536 : : struct tunnel_db_get_tunnel_ctx {
11537 : : const struct rte_flow_tunnel *app_tunnel;
11538 : : struct mlx5_flow_tunnel *tunnel;
11539 : : };
11540 : :
11541 : 0 : static bool get_tunnel_match(struct rte_eth_dev *dev,
11542 : : struct mlx5_flow_tunnel *tunnel, const void *x)
11543 : : {
11544 : : const struct tunnel_db_get_tunnel_ctx *ctx = x;
11545 : :
11546 : : RTE_SET_USED(dev);
11547 : 0 : return !memcmp(ctx->app_tunnel, &tunnel->app_tunnel,
11548 : : sizeof(*ctx->app_tunnel));
11549 : : }
11550 : :
11551 : 0 : static void get_tunnel_hit(struct rte_eth_dev *dev,
11552 : : struct mlx5_flow_tunnel *tunnel, void *x)
11553 : : {
11554 : : /* called under tunnel spinlock protection */
11555 : : struct tunnel_db_get_tunnel_ctx *ctx = x;
11556 : :
11557 : : RTE_SET_USED(dev);
11558 : 0 : tunnel->refctn++;
11559 : 0 : ctx->tunnel = tunnel;
11560 : 0 : }
11561 : :
11562 : 0 : static void get_tunnel_miss(struct rte_eth_dev *dev, void *x)
11563 : : {
11564 : : /* called under tunnel spinlock protection */
11565 : : struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
11566 : : struct tunnel_db_get_tunnel_ctx *ctx = x;
11567 : :
11568 : 0 : rte_spinlock_unlock(&thub->sl);
11569 : 0 : ctx->tunnel = mlx5_flow_tunnel_allocate(dev, ctx->app_tunnel);
11570 : : rte_spinlock_lock(&thub->sl);
11571 [ # # ]: 0 : if (ctx->tunnel) {
11572 : 0 : ctx->tunnel->refctn = 1;
11573 [ # # ]: 0 : LIST_INSERT_HEAD(&thub->tunnels, ctx->tunnel, chain);
11574 : : }
11575 : 0 : }
11576 : :
11577 : :
11578 : : static int
11579 : 0 : mlx5_get_flow_tunnel(struct rte_eth_dev *dev,
11580 : : const struct rte_flow_tunnel *app_tunnel,
11581 : : struct mlx5_flow_tunnel **tunnel)
11582 : : {
11583 : 0 : struct tunnel_db_get_tunnel_ctx ctx = {
11584 : : .app_tunnel = app_tunnel,
11585 : : };
11586 : :
11587 : 0 : mlx5_access_tunnel_offload_db(dev, get_tunnel_match, get_tunnel_hit,
11588 : : get_tunnel_miss, &ctx, true);
11589 : 0 : *tunnel = ctx.tunnel;
11590 [ # # ]: 0 : return ctx.tunnel ? 0 : -ENOMEM;
11591 : : }
11592 : :
11593 : 0 : void mlx5_release_tunnel_hub(struct mlx5_dev_ctx_shared *sh, uint16_t port_id)
11594 : : {
11595 : 0 : struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
11596 : :
11597 [ # # ]: 0 : if (!thub)
11598 : : return;
11599 [ # # ]: 0 : if (!LIST_EMPTY(&thub->tunnels))
11600 : 0 : DRV_LOG(WARNING, "port %u tunnels present", port_id);
11601 : 0 : mlx5_hlist_destroy(thub->groups);
11602 : 0 : mlx5_free(thub);
11603 : : }
11604 : :
11605 : 0 : int mlx5_alloc_tunnel_hub(struct mlx5_dev_ctx_shared *sh)
11606 : : {
11607 : : int err;
11608 : : struct mlx5_flow_tunnel_hub *thub;
11609 : :
11610 : 0 : thub = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, sizeof(*thub),
11611 : : 0, SOCKET_ID_ANY);
11612 [ # # ]: 0 : if (!thub)
11613 : : return -ENOMEM;
11614 : 0 : LIST_INIT(&thub->tunnels);
11615 : : rte_spinlock_init(&thub->sl);
11616 : 0 : thub->groups = mlx5_hlist_create("flow groups", 64,
11617 : : false, true, sh,
11618 : : mlx5_flow_tunnel_grp2tbl_create_cb,
11619 : : mlx5_flow_tunnel_grp2tbl_match_cb,
11620 : : mlx5_flow_tunnel_grp2tbl_remove_cb,
11621 : : mlx5_flow_tunnel_grp2tbl_clone_cb,
11622 : : mlx5_flow_tunnel_grp2tbl_clone_free_cb);
11623 [ # # ]: 0 : if (!thub->groups) {
11624 : 0 : err = -rte_errno;
11625 : 0 : goto err;
11626 : : }
11627 : 0 : sh->tunnel_hub = thub;
11628 : :
11629 : 0 : return 0;
11630 : :
11631 : : err:
11632 : : if (thub->groups)
11633 : : mlx5_hlist_destroy(thub->groups);
11634 : : if (thub)
11635 : 0 : mlx5_free(thub);
11636 : 0 : return err;
11637 : : }
11638 : :
11639 : : static inline int
11640 : 0 : mlx5_flow_tunnel_validate(struct rte_eth_dev *dev,
11641 : : struct rte_flow_tunnel *tunnel,
11642 : : struct rte_flow_error *error)
11643 : : {
11644 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11645 : :
11646 [ # # ]: 0 : if (!priv->sh->config.dv_flow_en)
11647 : 0 : return rte_flow_error_set(error, ENOTSUP,
11648 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
11649 : : "flow DV interface is off");
11650 [ # # ]: 0 : if (!is_tunnel_offload_active(dev))
11651 : 0 : return rte_flow_error_set(error, ENOTSUP,
11652 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
11653 : : "tunnel offload was not activated, consider setting dv_xmeta_en=3");
11654 [ # # ]: 0 : if (!tunnel)
11655 : 0 : return rte_flow_error_set(error, EINVAL,
11656 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
11657 : : "no application tunnel");
11658 [ # # ]: 0 : switch (tunnel->type) {
11659 : 0 : default:
11660 : 0 : return rte_flow_error_set(error, EINVAL,
11661 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
11662 : : "unsupported tunnel type");
11663 : : case RTE_FLOW_ITEM_TYPE_VXLAN:
11664 : : case RTE_FLOW_ITEM_TYPE_GRE:
11665 : : case RTE_FLOW_ITEM_TYPE_NVGRE:
11666 : : case RTE_FLOW_ITEM_TYPE_GENEVE:
11667 : : break;
11668 : : }
11669 : : return 0;
11670 : : }
11671 : :
11672 : : static int
11673 : 0 : mlx5_flow_tunnel_decap_set(struct rte_eth_dev *dev,
11674 : : struct rte_flow_tunnel *app_tunnel,
11675 : : struct rte_flow_action **actions,
11676 : : uint32_t *num_of_actions,
11677 : : struct rte_flow_error *error)
11678 : : {
11679 : : struct mlx5_flow_tunnel *tunnel;
11680 : 0 : int ret = mlx5_flow_tunnel_validate(dev, app_tunnel, error);
11681 : :
11682 [ # # ]: 0 : if (ret)
11683 : : return ret;
11684 : 0 : ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
11685 [ # # ]: 0 : if (ret < 0) {
11686 : 0 : return rte_flow_error_set(error, ret,
11687 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
11688 : : "failed to initialize pmd tunnel");
11689 : : }
11690 : 0 : *actions = &tunnel->action;
11691 : 0 : *num_of_actions = 1;
11692 : 0 : return 0;
11693 : : }
11694 : :
11695 : : static int
11696 : 0 : mlx5_flow_tunnel_match(struct rte_eth_dev *dev,
11697 : : struct rte_flow_tunnel *app_tunnel,
11698 : : struct rte_flow_item **items,
11699 : : uint32_t *num_of_items,
11700 : : struct rte_flow_error *error)
11701 : : {
11702 : : struct mlx5_flow_tunnel *tunnel;
11703 : 0 : int ret = mlx5_flow_tunnel_validate(dev, app_tunnel, error);
11704 : :
11705 [ # # ]: 0 : if (ret)
11706 : : return ret;
11707 : 0 : ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
11708 [ # # ]: 0 : if (ret < 0) {
11709 : 0 : return rte_flow_error_set(error, ret,
11710 : : RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
11711 : : "failed to initialize pmd tunnel");
11712 : : }
11713 : 0 : *items = &tunnel->item;
11714 : 0 : *num_of_items = 1;
11715 : 0 : return 0;
11716 : : }
11717 : :
11718 : : struct tunnel_db_element_release_ctx {
11719 : : struct rte_flow_item *items;
11720 : : struct rte_flow_action *actions;
11721 : : uint32_t num_elements;
11722 : : struct rte_flow_error *error;
11723 : : int ret;
11724 : : };
11725 : :
11726 : : static bool
11727 : 0 : tunnel_element_release_match(struct rte_eth_dev *dev,
11728 : : struct mlx5_flow_tunnel *tunnel, const void *x)
11729 : : {
11730 : : const struct tunnel_db_element_release_ctx *ctx = x;
11731 : :
11732 : : RTE_SET_USED(dev);
11733 [ # # ]: 0 : if (ctx->num_elements != 1)
11734 : : return false;
11735 [ # # ]: 0 : else if (ctx->items)
11736 : 0 : return ctx->items == &tunnel->item;
11737 [ # # ]: 0 : else if (ctx->actions)
11738 : 0 : return ctx->actions == &tunnel->action;
11739 : :
11740 : : return false;
11741 : : }
11742 : :
11743 : : static void
11744 : 0 : tunnel_element_release_hit(struct rte_eth_dev *dev,
11745 : : struct mlx5_flow_tunnel *tunnel, void *x)
11746 : : {
11747 : : struct tunnel_db_element_release_ctx *ctx = x;
11748 : 0 : ctx->ret = 0;
11749 [ # # ]: 0 : if (!(rte_atomic_fetch_sub_explicit(&tunnel->refctn, 1, rte_memory_order_relaxed) - 1))
11750 : 0 : mlx5_flow_tunnel_free(dev, tunnel);
11751 : 0 : }
11752 : :
11753 : : static void
11754 : 0 : tunnel_element_release_miss(struct rte_eth_dev *dev, void *x)
11755 : : {
11756 : : struct tunnel_db_element_release_ctx *ctx = x;
11757 : : RTE_SET_USED(dev);
11758 : 0 : ctx->ret = rte_flow_error_set(ctx->error, EINVAL,
11759 : : RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
11760 : : "invalid argument");
11761 : 0 : }
11762 : :
11763 : : static int
11764 : 0 : mlx5_flow_tunnel_item_release(struct rte_eth_dev *dev,
11765 : : struct rte_flow_item *pmd_items,
11766 : : uint32_t num_items, struct rte_flow_error *err)
11767 : : {
11768 : 0 : struct tunnel_db_element_release_ctx ctx = {
11769 : : .items = pmd_items,
11770 : : .actions = NULL,
11771 : : .num_elements = num_items,
11772 : : .error = err,
11773 : : };
11774 : :
11775 : 0 : mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
11776 : : tunnel_element_release_hit,
11777 : : tunnel_element_release_miss, &ctx, false);
11778 : :
11779 : 0 : return ctx.ret;
11780 : : }
11781 : :
11782 : : static int
11783 : 0 : mlx5_flow_tunnel_action_release(struct rte_eth_dev *dev,
11784 : : struct rte_flow_action *pmd_actions,
11785 : : uint32_t num_actions, struct rte_flow_error *err)
11786 : : {
11787 : 0 : struct tunnel_db_element_release_ctx ctx = {
11788 : : .items = NULL,
11789 : : .actions = pmd_actions,
11790 : : .num_elements = num_actions,
11791 : : .error = err,
11792 : : };
11793 : :
11794 : 0 : mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
11795 : : tunnel_element_release_hit,
11796 : : tunnel_element_release_miss, &ctx, false);
11797 : :
11798 : 0 : return ctx.ret;
11799 : : }
11800 : :
11801 : : static int
11802 : 0 : mlx5_flow_tunnel_get_restore_info(struct rte_eth_dev *dev,
11803 : : struct rte_mbuf *m,
11804 : : struct rte_flow_restore_info *info,
11805 : : struct rte_flow_error *err)
11806 : : {
11807 : 0 : uint64_t ol_flags = m->ol_flags;
11808 : : const struct mlx5_flow_tbl_data_entry *tble;
11809 : : const uint64_t mask = RTE_MBUF_F_RX_FDIR | RTE_MBUF_F_RX_FDIR_ID;
11810 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11811 : :
11812 [ # # ]: 0 : if (priv->tunnel_enabled == 0)
11813 : 0 : goto err;
11814 [ # # ]: 0 : if ((ol_flags & mask) != mask)
11815 : 0 : goto err;
11816 : 0 : tble = tunnel_mark_decode(dev, m->hash.fdir.hi);
11817 [ # # ]: 0 : if (!tble) {
11818 : 0 : DRV_LOG(DEBUG, "port %u invalid miss tunnel mark %#x",
11819 : : dev->data->port_id, m->hash.fdir.hi);
11820 : 0 : goto err;
11821 : : }
11822 : : MLX5_ASSERT(tble->tunnel);
11823 : 0 : memcpy(&info->tunnel, &tble->tunnel->app_tunnel, sizeof(info->tunnel));
11824 : 0 : info->group_id = tble->group_id;
11825 : 0 : info->flags = RTE_FLOW_RESTORE_INFO_TUNNEL |
11826 : : RTE_FLOW_RESTORE_INFO_GROUP_ID |
11827 : : RTE_FLOW_RESTORE_INFO_ENCAPSULATED;
11828 : :
11829 : 0 : return 0;
11830 : :
11831 : 0 : err:
11832 : 0 : return rte_flow_error_set(err, EINVAL,
11833 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11834 : : "failed to get restore info");
11835 : : }
11836 : :
11837 : : #else /* HAVE_IBV_FLOW_DV_SUPPORT */
11838 : : static int
11839 : : mlx5_flow_tunnel_decap_set(__rte_unused struct rte_eth_dev *dev,
11840 : : __rte_unused struct rte_flow_tunnel *app_tunnel,
11841 : : __rte_unused struct rte_flow_action **actions,
11842 : : __rte_unused uint32_t *num_of_actions,
11843 : : __rte_unused struct rte_flow_error *error)
11844 : : {
11845 : : return -ENOTSUP;
11846 : : }
11847 : :
11848 : : static int
11849 : : mlx5_flow_tunnel_match(__rte_unused struct rte_eth_dev *dev,
11850 : : __rte_unused struct rte_flow_tunnel *app_tunnel,
11851 : : __rte_unused struct rte_flow_item **items,
11852 : : __rte_unused uint32_t *num_of_items,
11853 : : __rte_unused struct rte_flow_error *error)
11854 : : {
11855 : : return -ENOTSUP;
11856 : : }
11857 : :
11858 : : static int
11859 : : mlx5_flow_tunnel_item_release(__rte_unused struct rte_eth_dev *dev,
11860 : : __rte_unused struct rte_flow_item *pmd_items,
11861 : : __rte_unused uint32_t num_items,
11862 : : __rte_unused struct rte_flow_error *err)
11863 : : {
11864 : : return -ENOTSUP;
11865 : : }
11866 : :
11867 : : static int
11868 : : mlx5_flow_tunnel_action_release(__rte_unused struct rte_eth_dev *dev,
11869 : : __rte_unused struct rte_flow_action *pmd_action,
11870 : : __rte_unused uint32_t num_actions,
11871 : : __rte_unused struct rte_flow_error *err)
11872 : : {
11873 : : return -ENOTSUP;
11874 : : }
11875 : :
11876 : : static int
11877 : : mlx5_flow_tunnel_get_restore_info(__rte_unused struct rte_eth_dev *dev,
11878 : : __rte_unused struct rte_mbuf *m,
11879 : : __rte_unused struct rte_flow_restore_info *i,
11880 : : __rte_unused struct rte_flow_error *err)
11881 : : {
11882 : : return -ENOTSUP;
11883 : : }
11884 : :
11885 : : static int
11886 : : flow_tunnel_add_default_miss(__rte_unused struct rte_eth_dev *dev,
11887 : : __rte_unused struct rte_flow *flow,
11888 : : __rte_unused const struct rte_flow_attr *attr,
11889 : : __rte_unused const struct rte_flow_action *actions,
11890 : : __rte_unused uint32_t flow_idx,
11891 : : __rte_unused const struct mlx5_flow_tunnel *tunnel,
11892 : : __rte_unused struct tunnel_default_miss_ctx *ctx,
11893 : : __rte_unused struct rte_flow_error *error)
11894 : : {
11895 : : return -ENOTSUP;
11896 : : }
11897 : :
11898 : : static struct mlx5_flow_tunnel *
11899 : : mlx5_find_tunnel_id(__rte_unused struct rte_eth_dev *dev,
11900 : : __rte_unused uint32_t id)
11901 : : {
11902 : : return NULL;
11903 : : }
11904 : :
11905 : : static void
11906 : : mlx5_flow_tunnel_free(__rte_unused struct rte_eth_dev *dev,
11907 : : __rte_unused struct mlx5_flow_tunnel *tunnel)
11908 : : {
11909 : : }
11910 : :
11911 : : static uint32_t
11912 : : tunnel_flow_group_to_flow_table(__rte_unused struct rte_eth_dev *dev,
11913 : : __rte_unused const struct mlx5_flow_tunnel *t,
11914 : : __rte_unused uint32_t group,
11915 : : __rte_unused uint32_t *table,
11916 : : struct rte_flow_error *error)
11917 : : {
11918 : : return rte_flow_error_set(error, ENOTSUP,
11919 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11920 : : "tunnel offload requires DV support");
11921 : : }
11922 : :
11923 : : void
11924 : : mlx5_release_tunnel_hub(__rte_unused struct mlx5_dev_ctx_shared *sh,
11925 : : __rte_unused uint16_t port_id)
11926 : : {
11927 : : }
11928 : : #endif /* HAVE_IBV_FLOW_DV_SUPPORT */
11929 : :
11930 : : /* Flex flow item API */
11931 : : static struct rte_flow_item_flex_handle *
11932 : 0 : mlx5_flow_flex_item_create(struct rte_eth_dev *dev,
11933 : : const struct rte_flow_item_flex_conf *conf,
11934 : : struct rte_flow_error *error)
11935 : : {
11936 : : static const char err_msg[] = "flex item creation unsupported";
11937 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
11938 : : struct rte_flow_attr attr = { .transfer = 0 };
11939 : 0 : const struct mlx5_flow_driver_ops *fops =
11940 : : flow_get_drv_ops(flow_get_drv_type(dev, &attr));
11941 : :
11942 [ # # ]: 0 : if (!priv->pci_dev) {
11943 : 0 : rte_flow_error_set(error, ENOTSUP,
11944 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11945 : : "create flex item on PF only");
11946 : 0 : return NULL;
11947 : : }
11948 [ # # ]: 0 : switch (priv->pci_dev->id.device_id) {
11949 : : case PCI_DEVICE_ID_MELLANOX_BLUEFIELD2:
11950 : : case PCI_DEVICE_ID_MELLANOX_BLUEFIELD3:
11951 : : break;
11952 : 0 : default:
11953 : 0 : rte_flow_error_set(error, ENOTSUP,
11954 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11955 : : "flex item available on BlueField ports only");
11956 : 0 : return NULL;
11957 : : }
11958 [ # # ]: 0 : if (!priv->sh->cdev->config.hca_attr.parse_graph_flex_node) {
11959 : 0 : rte_flow_error_set(error, ENOTSUP,
11960 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11961 : : "flex item not supported on current FW");
11962 : 0 : return NULL;
11963 : : }
11964 [ # # ]: 0 : if (!fops->item_create) {
11965 : 0 : DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
11966 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
11967 : : NULL, err_msg);
11968 : 0 : return NULL;
11969 : : }
11970 : 0 : return fops->item_create(dev, conf, error);
11971 : : }
11972 : :
11973 : : static int
11974 [ # # ]: 0 : mlx5_flow_flex_item_release(struct rte_eth_dev *dev,
11975 : : const struct rte_flow_item_flex_handle *handle,
11976 : : struct rte_flow_error *error)
11977 : : {
11978 : : static const char err_msg[] = "flex item release unsupported";
11979 : : struct rte_flow_attr attr = { .transfer = 0 };
11980 : 0 : const struct mlx5_flow_driver_ops *fops =
11981 : : flow_get_drv_ops(flow_get_drv_type(dev, &attr));
11982 : :
11983 [ # # ]: 0 : if (!fops->item_release) {
11984 : 0 : DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
11985 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
11986 : : NULL, err_msg);
11987 : 0 : return -rte_errno;
11988 : : }
11989 : 0 : return fops->item_release(dev, handle, error);
11990 : : }
11991 : :
11992 : : static void
11993 : 0 : mlx5_dbg__print_pattern(const struct rte_flow_item *item)
11994 : : {
11995 : : int ret;
11996 : : struct rte_flow_error error;
11997 : :
11998 [ # # ]: 0 : for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
11999 : : char *item_name;
12000 : 0 : ret = rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_NAME_PTR, &item_name,
12001 : : sizeof(item_name),
12002 : 0 : (void *)(uintptr_t)item->type, &error);
12003 [ # # ]: 0 : if (ret > 0)
12004 : 0 : printf("%s ", item_name);
12005 : : else
12006 : 0 : printf("%d\n", (int)item->type);
12007 : : }
12008 : : printf("END\n");
12009 : 0 : }
12010 : :
12011 : : static int
12012 : : mlx5_flow_is_std_vxlan_port(const struct rte_flow_item *udp_item)
12013 : : {
12014 : 0 : const struct rte_flow_item_udp *spec = udp_item->spec;
12015 : 0 : const struct rte_flow_item_udp *mask = udp_item->mask;
12016 : : uint16_t udp_dport = 0;
12017 : :
12018 : 0 : if (spec != NULL) {
12019 [ # # ]: 0 : if (!mask)
12020 : : mask = &rte_flow_item_udp_mask;
12021 [ # # ]: 0 : udp_dport = rte_be_to_cpu_16(spec->hdr.dst_port &
12022 : : mask->hdr.dst_port);
12023 : : }
12024 : 0 : return (!udp_dport || udp_dport == MLX5_UDP_PORT_VXLAN);
12025 : : }
12026 : :
12027 : : static const struct mlx5_flow_expand_node *
12028 : 0 : mlx5_flow_expand_rss_adjust_node(const struct rte_flow_item *pattern,
12029 : : unsigned int item_idx,
12030 : : const struct mlx5_flow_expand_node graph[],
12031 : : const struct mlx5_flow_expand_node *node)
12032 : : {
12033 : 0 : const struct rte_flow_item *item = pattern + item_idx, *prev_item;
12034 : :
12035 [ # # # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_VXLAN &&
12036 : 0 : node != NULL &&
12037 [ # # ]: 0 : node->type == RTE_FLOW_ITEM_TYPE_VXLAN) {
12038 : : /*
12039 : : * The expansion node is VXLAN and it is also the last
12040 : : * expandable item in the pattern, so need to continue
12041 : : * expansion of the inner tunnel.
12042 : : */
12043 : : MLX5_ASSERT(item_idx > 0);
12044 [ # # ]: 0 : prev_item = pattern + item_idx - 1;
12045 : : MLX5_ASSERT(prev_item->type == RTE_FLOW_ITEM_TYPE_UDP);
12046 [ # # ]: 0 : if (mlx5_flow_is_std_vxlan_port(prev_item))
12047 : 0 : return &graph[MLX5_EXPANSION_STD_VXLAN];
12048 : 0 : return &graph[MLX5_EXPANSION_L3_VXLAN];
12049 : : }
12050 : : return node;
12051 : : }
12052 : :
12053 : : /* Map of Verbs to Flow priority with 8 Verbs priorities. */
12054 : : static const uint32_t priority_map_3[][MLX5_PRIORITY_MAP_MAX] = {
12055 : : { 0, 1, 2 }, { 2, 3, 4 }, { 5, 6, 7 },
12056 : : };
12057 : :
12058 : : /* Map of Verbs to Flow priority with 16 Verbs priorities. */
12059 : : static const uint32_t priority_map_5[][MLX5_PRIORITY_MAP_MAX] = {
12060 : : { 0, 1, 2 }, { 3, 4, 5 }, { 6, 7, 8 },
12061 : : { 9, 10, 11 }, { 12, 13, 14 },
12062 : : };
12063 : :
12064 : : /**
12065 : : * Discover the number of available flow priorities.
12066 : : *
12067 : : * @param dev
12068 : : * Ethernet device.
12069 : : *
12070 : : * @return
12071 : : * On success, number of available flow priorities.
12072 : : * On failure, a negative errno-style code and rte_errno is set.
12073 : : */
12074 : : int
12075 : 0 : mlx5_flow_discover_priorities(struct rte_eth_dev *dev)
12076 : : {
12077 : : static const uint16_t vprio[] = {8, 16};
12078 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
12079 : : const struct mlx5_flow_driver_ops *fops;
12080 : : enum mlx5_flow_drv_type type;
12081 : : int ret;
12082 : :
12083 : : type = mlx5_flow_os_get_type();
12084 : : if (type == MLX5_FLOW_TYPE_MAX) {
12085 : : type = MLX5_FLOW_TYPE_VERBS;
12086 [ # # # # ]: 0 : if (priv->sh->cdev->config.devx && priv->sh->config.dv_flow_en)
12087 : : type = MLX5_FLOW_TYPE_DV;
12088 : : }
12089 : 0 : fops = flow_get_drv_ops(type);
12090 [ # # ]: 0 : if (fops->discover_priorities == NULL) {
12091 : 0 : DRV_LOG(ERR, "Priority discovery not supported");
12092 : 0 : rte_errno = ENOTSUP;
12093 : 0 : return -rte_errno;
12094 : : }
12095 : 0 : ret = fops->discover_priorities(dev, vprio, RTE_DIM(vprio));
12096 [ # # ]: 0 : if (ret < 0)
12097 : : return ret;
12098 [ # # # ]: 0 : switch (ret) {
12099 : : case 8:
12100 : : ret = RTE_DIM(priority_map_3);
12101 : : break;
12102 : 0 : case 16:
12103 : : ret = RTE_DIM(priority_map_5);
12104 : 0 : break;
12105 : 0 : default:
12106 : 0 : rte_errno = ENOTSUP;
12107 : 0 : DRV_LOG(ERR,
12108 : : "port %u maximum priority: %d expected 8/16",
12109 : : dev->data->port_id, ret);
12110 : 0 : return -rte_errno;
12111 : : }
12112 : 0 : DRV_LOG(INFO, "port %u supported flow priorities:"
12113 : : " 0-%d for ingress or egress root table,"
12114 : : " 0-%d for non-root table or transfer root table.",
12115 : : dev->data->port_id, ret - 2,
12116 : : MLX5_NON_ROOT_FLOW_MAX_PRIO - 1);
12117 : 0 : return ret;
12118 : : }
12119 : :
12120 : : /**
12121 : : * Adjust flow priority based on the highest layer and the request priority.
12122 : : *
12123 : : * @param[in] dev
12124 : : * Pointer to the Ethernet device structure.
12125 : : * @param[in] priority
12126 : : * The rule base priority.
12127 : : * @param[in] subpriority
12128 : : * The priority based on the items.
12129 : : *
12130 : : * @return
12131 : : * The new priority.
12132 : : */
12133 : : uint32_t
12134 : 0 : mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
12135 : : uint32_t subpriority)
12136 : : {
12137 : : uint32_t res = 0;
12138 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12139 : :
12140 [ # # # ]: 0 : switch (priv->sh->flow_max_priority) {
12141 : 0 : case RTE_DIM(priority_map_3):
12142 : 0 : res = priority_map_3[priority][subpriority];
12143 : 0 : break;
12144 : 0 : case RTE_DIM(priority_map_5):
12145 : 0 : res = priority_map_5[priority][subpriority];
12146 : 0 : break;
12147 : : }
12148 : 0 : return res;
12149 : : }
12150 : :
12151 : : /**
12152 : : * Get the priority for sending traffic to kernel table.
12153 : : *
12154 : : * @param[in] dev
12155 : : * Pointer to the Ethernet device structure.
12156 : : *
12157 : : * @return
12158 : : * On success: the value of priority for sending traffic to kernel table
12159 : : * On failure: -1
12160 : : */
12161 : : uint32_t
12162 : 0 : mlx5_get_send_to_kernel_priority(struct rte_eth_dev *dev)
12163 : : {
12164 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12165 : : uint32_t res;
12166 : :
12167 [ # # # ]: 0 : switch (priv->sh->flow_max_priority) {
12168 : : case RTE_DIM(priority_map_5):
12169 : : res = 15;
12170 : : break;
12171 : 0 : case RTE_DIM(priority_map_3):
12172 : : res = 7;
12173 : 0 : break;
12174 : 0 : default:
12175 : 0 : DRV_LOG(ERR,
12176 : : "port %u maximum priority: %d expected 8/16",
12177 : : dev->data->port_id, priv->sh->flow_max_priority);
12178 : : res = (uint32_t)-1;
12179 : : }
12180 : 0 : return res;
12181 : : }
12182 : :
12183 : : /**
12184 : : * Get the E-Switch Manager vport id.
12185 : : *
12186 : : * @param[in] dev
12187 : : * Pointer to the Ethernet device structure.
12188 : : *
12189 : : * @return
12190 : : * The vport id.
12191 : : */
12192 : 0 : int16_t mlx5_flow_get_esw_manager_vport_id(struct rte_eth_dev *dev)
12193 : : {
12194 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12195 : 0 : struct mlx5_common_device *cdev = priv->sh->cdev;
12196 : :
12197 : : /* New FW exposes E-Switch Manager vport ID, can use it directly. */
12198 [ # # ]: 0 : if (cdev->config.hca_attr.esw_mgr_vport_id_valid)
12199 : 0 : return (int16_t)cdev->config.hca_attr.esw_mgr_vport_id;
12200 : :
12201 [ # # ]: 0 : if (priv->pci_dev == NULL)
12202 : : return 0;
12203 [ # # ]: 0 : switch (priv->pci_dev->id.device_id) {
12204 : : case PCI_DEVICE_ID_MELLANOX_BLUEFIELD:
12205 : : case PCI_DEVICE_ID_MELLANOX_BLUEFIELD2:
12206 : : case PCI_DEVICE_ID_MELLANOX_BLUEFIELD3:
12207 : : /*
12208 : : * In old FW which doesn't expose the E-Switch Manager vport ID in the capability,
12209 : : * only the BF embedded CPUs control the E-Switch Manager port. Hence,
12210 : : * ECPF vport ID is selected and not the host port (0) in any BF case.
12211 : : */
12212 : : return (int16_t)MLX5_ECPF_VPORT_ID;
12213 : 0 : default:
12214 : 0 : return MLX5_PF_VPORT_ID;
12215 : : }
12216 : : }
12217 : :
12218 : : /**
12219 : : * Parse item to get the vport id.
12220 : : *
12221 : : * @param[in] dev
12222 : : * Pointer to the Ethernet device structure.
12223 : : * @param[in] item
12224 : : * The src port id match item.
12225 : : * @param[out] vport_id
12226 : : * Pointer to put the vport id.
12227 : : * @param[out] all_ports
12228 : : * Indicate if the item matches all ports.
12229 : : * @param[out] error
12230 : : * Pointer to error structure.
12231 : : *
12232 : : * @return
12233 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
12234 : : */
12235 : 0 : int mlx5_flow_get_item_vport_id(struct rte_eth_dev *dev,
12236 : : const struct rte_flow_item *item,
12237 : : uint16_t *vport_id,
12238 : : bool *all_ports,
12239 : : struct rte_flow_error *error)
12240 : : {
12241 : : struct mlx5_priv *port_priv;
12242 : : const struct rte_flow_item_port_id *pid_v = NULL;
12243 : : const struct rte_flow_item_ethdev *dev_v = NULL;
12244 : : uint32_t esw_mgr_port;
12245 : : uint32_t src_port;
12246 : :
12247 [ # # ]: 0 : if (all_ports)
12248 : 0 : *all_ports = false;
12249 [ # # # # ]: 0 : switch (item->type) {
12250 : 0 : case RTE_FLOW_ITEM_TYPE_PORT_ID:
12251 : 0 : pid_v = item->spec;
12252 [ # # ]: 0 : if (!pid_v)
12253 : : return 0;
12254 : 0 : src_port = pid_v->id;
12255 : : esw_mgr_port = MLX5_PORT_ESW_MGR;
12256 : 0 : break;
12257 : 0 : case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
12258 : 0 : dev_v = item->spec;
12259 [ # # ]: 0 : if (!dev_v) {
12260 [ # # ]: 0 : if (all_ports)
12261 : 0 : *all_ports = true;
12262 : 0 : return 0;
12263 : : }
12264 : 0 : src_port = dev_v->port_id;
12265 : : esw_mgr_port = MLX5_REPRESENTED_PORT_ESW_MGR;
12266 : 0 : break;
12267 : : case RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR:
12268 : : src_port = MLX5_REPRESENTED_PORT_ESW_MGR;
12269 : : esw_mgr_port = MLX5_REPRESENTED_PORT_ESW_MGR;
12270 : : break;
12271 : 0 : default:
12272 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
12273 : : NULL, "Incorrect item type.");
12274 : : }
12275 [ # # ]: 0 : if (src_port == esw_mgr_port) {
12276 : 0 : *vport_id = mlx5_flow_get_esw_manager_vport_id(dev);
12277 : : } else {
12278 : 0 : port_priv = mlx5_port_to_eswitch_info(src_port, false);
12279 [ # # ]: 0 : if (!port_priv)
12280 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
12281 : : NULL, "Failed to get port info.");
12282 : 0 : *vport_id = port_priv->representor_id;
12283 : : }
12284 : :
12285 : : return 0;
12286 : : }
12287 : :
12288 : : int
12289 : 0 : mlx5_flow_pick_transfer_proxy(struct rte_eth_dev *dev,
12290 : : uint16_t *proxy_port_id,
12291 : : struct rte_flow_error *error)
12292 : : {
12293 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
12294 : : uint16_t port_id;
12295 : :
12296 [ # # ]: 0 : if (!priv->sh->config.dv_esw_en)
12297 : 0 : return rte_flow_error_set(error, EINVAL,
12298 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12299 : : NULL,
12300 : : "unable to provide a proxy port"
12301 : : " without E-Switch configured");
12302 [ # # ]: 0 : if (!priv->master && !priv->representor)
12303 : 0 : return rte_flow_error_set(error, EINVAL,
12304 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12305 : : NULL,
12306 : : "unable to provide a proxy port"
12307 : : " for port which is not a master"
12308 : : " or a representor port");
12309 [ # # ]: 0 : if (priv->master) {
12310 : 0 : *proxy_port_id = dev->data->port_id;
12311 : 0 : return 0;
12312 : : }
12313 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port_id, dev->device) {
12314 : 0 : const struct rte_eth_dev *port_dev = &rte_eth_devices[port_id];
12315 : 0 : const struct mlx5_priv *port_priv = port_dev->data->dev_private;
12316 : :
12317 [ # # ]: 0 : if (port_priv->master &&
12318 [ # # ]: 0 : port_priv->domain_id == priv->domain_id) {
12319 : 0 : *proxy_port_id = port_id;
12320 : 0 : return 0;
12321 : : }
12322 : : }
12323 : 0 : return rte_flow_error_set(error, ENODEV,
12324 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12325 : : NULL, "unable to find a proxy port");
12326 : : }
12327 : :
12328 : : /**
12329 : : * Discover IPv6 traffic class ID support in rdma-core and firmware.
12330 : : *
12331 : : * @param dev
12332 : : * Ethernet device.
12333 : : *
12334 : : * @return
12335 : : * 0, rdma-core is good to work with firmware.
12336 : : * -EOPNOTSUPP, rdma-core could not work with new IPv6 TC ID.
12337 : : */
12338 : : int
12339 : 0 : mlx5_flow_discover_ipv6_tc_support(struct rte_eth_dev *dev)
12340 : : {
12341 : : struct rte_flow_action_set_dscp set_dscp;
12342 : : struct rte_flow_attr attr;
12343 : : struct rte_flow_action actions[2];
12344 : : struct rte_flow_item items[3];
12345 : : struct rte_flow_error error;
12346 : : uint32_t flow_idx;
12347 : :
12348 : : memset(&attr, 0, sizeof(attr));
12349 : : memset(actions, 0, sizeof(actions));
12350 : : memset(items, 0, sizeof(items));
12351 : 0 : attr.group = 1;
12352 : 0 : attr.egress = 1;
12353 : 0 : items[0].type = RTE_FLOW_ITEM_TYPE_ETH;
12354 : 0 : items[1].type = RTE_FLOW_ITEM_TYPE_IPV6;
12355 : : items[2].type = RTE_FLOW_ITEM_TYPE_END;
12356 : : /* Random value */
12357 : 0 : set_dscp.dscp = 9;
12358 : 0 : actions[0].type = RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP;
12359 : 0 : actions[0].conf = &set_dscp;
12360 : : actions[1].type = RTE_FLOW_ACTION_TYPE_END;
12361 : :
12362 : 0 : flow_idx = mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_GEN, &attr, items,
12363 : : actions, true, &error);
12364 [ # # ]: 0 : if (!flow_idx)
12365 : : return -EOPNOTSUPP;
12366 : :
12367 : 0 : mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN, flow_idx);
12368 : 0 : return 0;
12369 : : }
12370 : :
12371 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_mlx5_create_geneve_tlv_parser, 24.03)
12372 : : void *
12373 : 0 : rte_pmd_mlx5_create_geneve_tlv_parser(uint16_t port_id,
12374 : : const struct rte_pmd_mlx5_geneve_tlv tlv_list[],
12375 : : uint8_t nb_options)
12376 : : {
12377 : : #ifdef HAVE_MLX5_HWS_SUPPORT
12378 : 0 : return mlx5_geneve_tlv_parser_create(port_id, tlv_list, nb_options);
12379 : : #else
12380 : : (void)port_id;
12381 : : (void)tlv_list;
12382 : : (void)nb_options;
12383 : : DRV_LOG(ERR, "%s is not supported.", __func__);
12384 : : rte_errno = ENOTSUP;
12385 : : return NULL;
12386 : : #endif
12387 : : }
12388 : :
12389 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_mlx5_destroy_geneve_tlv_parser, 24.03)
12390 : : int
12391 : 0 : rte_pmd_mlx5_destroy_geneve_tlv_parser(void *handle)
12392 : : {
12393 : : #ifdef HAVE_MLX5_HWS_SUPPORT
12394 : 0 : return mlx5_geneve_tlv_parser_destroy(handle);
12395 : : #else
12396 : : (void)handle;
12397 : : DRV_LOG(ERR, "%s is not supported.", __func__);
12398 : : rte_errno = ENOTSUP;
12399 : : return -rte_errno;
12400 : : #endif
12401 : : }
12402 : :
12403 : : bool
12404 : 0 : mlx5_ctrl_flow_uc_dmac_exists(struct rte_eth_dev *dev, const struct rte_ether_addr *addr)
12405 : : {
12406 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12407 : : struct mlx5_ctrl_flow_entry *entry;
12408 : : bool exists = false;
12409 : :
12410 [ # # ]: 0 : LIST_FOREACH(entry, &priv->hw_ctrl_flows, next) {
12411 [ # # # # ]: 0 : if (entry->info.type == MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC &&
12412 : : rte_is_same_ether_addr(addr, &entry->info.uc.dmac)) {
12413 : : exists = true;
12414 : : break;
12415 : : }
12416 : : }
12417 : 0 : return exists;
12418 : : }
12419 : :
12420 : : bool
12421 : 0 : mlx5_ctrl_flow_uc_dmac_vlan_exists(struct rte_eth_dev *dev,
12422 : : const struct rte_ether_addr *addr,
12423 : : const uint16_t vid)
12424 : : {
12425 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12426 : : struct mlx5_ctrl_flow_entry *entry;
12427 : : bool exists = false;
12428 : :
12429 [ # # ]: 0 : LIST_FOREACH(entry, &priv->hw_ctrl_flows, next) {
12430 [ # # # # ]: 0 : if (entry->info.type == MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC_VLAN &&
12431 : 0 : rte_is_same_ether_addr(addr, &entry->info.uc.dmac) &&
12432 [ # # ]: 0 : vid == entry->info.uc.vlan) {
12433 : : exists = true;
12434 : : break;
12435 : : }
12436 : : }
12437 : 0 : return exists;
12438 : : }
12439 : :
12440 : : static bool mlx5_steering_disabled;
12441 : :
12442 : : bool
12443 : 0 : mlx5_flow_is_steering_disabled(void)
12444 : : {
12445 : 0 : return mlx5_steering_disabled;
12446 : : }
12447 : :
12448 : : static void
12449 : 0 : flow_disable_steering_flush(struct rte_eth_dev *dev)
12450 : : {
12451 : : /*
12452 : : * This repeats the steps done in mlx5_dev_stop(), with a small difference:
12453 : : * - mlx5_flow_hw_cleanup_ctrl_rx_templates() and mlx5_action_handle_detach()
12454 : : * They are rearranged to make it work with different dev->data->dev_started.
12455 : : * Please see a TODO note in mlx5_dev_stop().
12456 : : */
12457 : :
12458 : 0 : mlx5_flow_stop_default(dev);
12459 : 0 : mlx5_traffic_disable(dev);
12460 : 0 : mlx5_flow_list_flush(dev, MLX5_FLOW_TYPE_GEN, true);
12461 : 0 : mlx5_flow_meter_rxq_flush(dev);
12462 : : #ifdef HAVE_MLX5_HWS_SUPPORT
12463 : 0 : mlx5_flow_hw_cleanup_ctrl_rx_templates(dev);
12464 : : #endif
12465 : 0 : mlx5_action_handle_detach(dev);
12466 : 0 : }
12467 : :
12468 : : static void
12469 : 0 : flow_disable_steering_cleanup(struct rte_eth_dev *dev)
12470 : : {
12471 : : /*
12472 : : * See mlx5_dev_close(). Only steps not done on mlx5_dev_stop() are executed here.
12473 : : * Necessary steps are copied as is because steering resource cleanup in mlx5_dev_close()
12474 : : * is interleaved with other steps.
12475 : : * TODO: Rework steering resource cleanup in mlx5_dev_close() to allow code reuse.
12476 : : */
12477 : :
12478 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12479 : :
12480 : 0 : mlx5_action_handle_flush(dev);
12481 : 0 : mlx5_flow_meter_flush(dev, NULL);
12482 : 0 : mlx5_flex_parser_ecpri_release(dev);
12483 : 0 : mlx5_flex_item_port_cleanup(dev);
12484 : 0 : mlx5_indirect_list_handles_release(dev);
12485 : : #ifdef HAVE_MLX5_HWS_SUPPORT
12486 : 0 : mlx5_flow_hw_destroy_vport_action(dev);
12487 : 0 : mlx5_flow_hw_resource_release(dev);
12488 : 0 : mlx5_flow_hw_clear_port_info(dev);
12489 [ # # ]: 0 : if (priv->tlv_options != NULL) {
12490 : : /* Free the GENEVE TLV parser resource. */
12491 : 0 : claim_zero(mlx5_geneve_tlv_options_destroy(priv->tlv_options, priv->sh->phdev));
12492 : 0 : priv->tlv_options = NULL;
12493 : : }
12494 [ # # ]: 0 : if (priv->ptype_rss_groups) {
12495 : 0 : mlx5_ipool_destroy(priv->ptype_rss_groups);
12496 : 0 : priv->ptype_rss_groups = NULL;
12497 : : }
12498 [ # # ]: 0 : if (priv->dr_ctx) {
12499 : 0 : claim_zero(mlx5dr_context_close(priv->dr_ctx));
12500 : 0 : priv->dr_ctx = NULL;
12501 : : }
12502 : : #else
12503 : : RTE_SET_USED(priv);
12504 : : #endif
12505 : 0 : }
12506 : :
12507 : : typedef void (*run_on_related_cb_t)(struct rte_eth_dev *dev);
12508 : :
12509 : : static void
12510 : 0 : flow_disable_steering_run_on_related(struct rte_eth_dev *dev,
12511 : : run_on_related_cb_t cb)
12512 : : {
12513 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12514 : : uint16_t other_port_id;
12515 : : uint16_t proxy_port_id;
12516 : : uint16_t port_id;
12517 : : int ret __rte_unused;
12518 : :
12519 [ # # ]: 0 : if (priv->sh->config.dv_esw_en) {
12520 : 0 : ret = mlx5_flow_pick_transfer_proxy(dev, &proxy_port_id, NULL);
12521 [ # # ]: 0 : if (ret != 0) {
12522 : : /*
12523 : : * This case should not happen because E-Switch is enabled.
12524 : : * However, in any case, release resources on the given port
12525 : : * and log the misconfigured port.
12526 : : */
12527 : 0 : DRV_LOG(ERR, "port %u unable to find transfer proxy port ret=%d",
12528 : : priv->dev_data->port_id, ret);
12529 : 0 : cb(dev);
12530 : 0 : return;
12531 : : }
12532 : :
12533 : : /* Run callback on representors. */
12534 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(other_port_id, dev->device) {
12535 : 0 : struct rte_eth_dev *other_dev = &rte_eth_devices[other_port_id];
12536 : :
12537 [ # # ]: 0 : if (other_port_id != proxy_port_id)
12538 : 0 : cb(other_dev);
12539 : : }
12540 : :
12541 : : /* Run callback on proxy port. */
12542 : 0 : cb(&rte_eth_devices[proxy_port_id]);
12543 [ # # ]: 0 : } else if (rte_atomic_load_explicit(&priv->shared_refcnt, rte_memory_order_relaxed) > 0) {
12544 : : /* Run callback on guest ports. */
12545 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port_id, NULL) {
12546 : 0 : struct rte_eth_dev *other_dev = &rte_eth_devices[port_id];
12547 : 0 : struct mlx5_priv *other_priv = other_dev->data->dev_private;
12548 : :
12549 [ # # ]: 0 : if (other_priv->shared_host == dev)
12550 : 0 : cb(other_dev);
12551 : : }
12552 : :
12553 : : /* Run callback on host port. */
12554 : 0 : cb(dev);
12555 : : } else {
12556 : 0 : cb(dev);
12557 : : }
12558 : : }
12559 : :
12560 : : RTE_EXPORT_SYMBOL(rte_pmd_mlx5_disable_steering)
12561 : : void
12562 : 0 : rte_pmd_mlx5_disable_steering(void)
12563 : : {
12564 : : uint16_t port_id;
12565 : :
12566 [ # # ]: 0 : if (mlx5_steering_disabled)
12567 : : return;
12568 : :
12569 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port_id, NULL) {
12570 [ # # ]: 0 : struct rte_eth_dev *dev = &rte_eth_devices[port_id];
12571 : :
12572 [ # # ]: 0 : if (mlx5_hws_active(dev)) {
12573 : 0 : flow_disable_steering_run_on_related(dev, flow_disable_steering_flush);
12574 : 0 : flow_disable_steering_run_on_related(dev, flow_disable_steering_cleanup);
12575 : : } else {
12576 : 0 : flow_disable_steering_flush(dev);
12577 : 0 : flow_disable_steering_cleanup(dev);
12578 : : }
12579 : :
12580 : 0 : mlx5_flow_rxq_mark_flag_set(dev);
12581 : : }
12582 : :
12583 : 0 : mlx5_steering_disabled = true;
12584 : : }
12585 : :
12586 : : RTE_EXPORT_SYMBOL(rte_pmd_mlx5_enable_steering)
12587 : : int
12588 : 0 : rte_pmd_mlx5_enable_steering(void)
12589 : : {
12590 : : uint16_t port_id;
12591 : :
12592 [ # # ]: 0 : if (!mlx5_steering_disabled)
12593 : : return 0;
12594 : :
12595 : : /* If any mlx5 port is probed, disallow enabling steering. */
12596 : 0 : port_id = mlx5_eth_find_next(0, NULL);
12597 [ # # ]: 0 : if (port_id != RTE_MAX_ETHPORTS)
12598 : : return -EBUSY;
12599 : :
12600 : 0 : mlx5_steering_disabled = false;
12601 : :
12602 : 0 : return 0;
12603 : : }
12604 : :
12605 : : bool
12606 : 0 : mlx5_vport_rx_metadata_passing_enabled(const struct mlx5_dev_ctx_shared *sh)
12607 : : {
12608 : : const struct mlx5_sh_config *dev_config = &sh->config;
12609 : 0 : const struct mlx5_hca_attr *hca_attr = &sh->cdev->config.hca_attr;
12610 : :
12611 [ # # # # ]: 0 : return !dev_config->dv_esw_en && hca_attr->fdb_to_vport_metadata;
12612 : : }
12613 : :
12614 : : bool
12615 : 0 : mlx5_vport_tx_metadata_passing_enabled(const struct mlx5_dev_ctx_shared *sh)
12616 : : {
12617 : : const struct mlx5_sh_config *dev_config = &sh->config;
12618 : 0 : const struct mlx5_hca_attr *hca_attr = &sh->cdev->config.hca_attr;
12619 : :
12620 [ # # # # ]: 0 : return !dev_config->dv_esw_en && hca_attr->vport_to_fdb_metadata;
12621 : : }
12622 : :
12623 : : bool
12624 : 0 : mlx5_esw_metadata_passing_enabled(const struct mlx5_dev_ctx_shared *sh)
12625 : : {
12626 : : const struct mlx5_sh_config *dev_config = &sh->config;
12627 : 0 : const struct mlx5_hca_attr *hca_attr = &sh->cdev->config.hca_attr;
12628 : 0 : bool fdb_to_vport_metadata_on = (hca_attr->fdb_to_vport_reg_c_id &
12629 : : RTE_BIT32(MLX5_ESW_VPORT_METADATA_REG_C_1)) != 0;
12630 : :
12631 [ # # # # ]: 0 : return dev_config->dv_esw_en && hca_attr->fdb_to_vport_reg_c && fdb_to_vport_metadata_on &&
12632 [ # # # # ]: 0 : hca_attr->vport_to_fdb_metadata && hca_attr->fdb_to_vport_metadata;
12633 : : }
|