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 : : /*
38 : : * Shared array for quick translation between port_id and vport mask/values
39 : : * used for HWS rules.
40 : : */
41 : : struct flow_hw_port_info mlx5_flow_hw_port_infos[RTE_MAX_ETHPORTS];
42 : :
43 : : struct tunnel_default_miss_ctx {
44 : : uint16_t *queue;
45 : : __extension__
46 : : union {
47 : : struct rte_flow_action_rss action_rss;
48 : : struct rte_flow_action_queue miss_queue;
49 : : struct rte_flow_action_jump miss_jump;
50 : : uint8_t raw[0];
51 : : };
52 : : };
53 : :
54 : : void
55 : 0 : mlx5_indirect_list_handles_release(struct rte_eth_dev *dev)
56 : : {
57 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
58 : : #ifdef HAVE_MLX5_HWS_SUPPORT
59 : : struct rte_flow_error error;
60 : : #endif
61 : :
62 [ # # ]: 0 : while (!LIST_EMPTY(&priv->indirect_list_head)) {
63 : : struct mlx5_indirect_list *e =
64 : : LIST_FIRST(&priv->indirect_list_head);
65 : :
66 [ # # ]: 0 : LIST_REMOVE(e, entry);
67 [ # # # # ]: 0 : switch (e->type) {
68 : : #ifdef HAVE_MLX5_HWS_SUPPORT
69 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_MIRROR:
70 : 0 : mlx5_hw_mirror_destroy(dev, (struct mlx5_mirror *)e);
71 : 0 : break;
72 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_LEGACY:
73 : 0 : mlx5_destroy_legacy_indirect(dev, e);
74 : 0 : break;
75 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_REFORMAT:
76 : 0 : mlx5_reformat_action_destroy(dev,
77 : : (struct rte_flow_action_list_handle *)e, &error);
78 : 0 : break;
79 : : #endif
80 : 0 : default:
81 : 0 : DRV_LOG(ERR, "invalid indirect list type");
82 : : MLX5_ASSERT(false);
83 : 0 : break;
84 : : }
85 : : }
86 : 0 : }
87 : :
88 : : static int
89 : : flow_tunnel_add_default_miss(struct rte_eth_dev *dev,
90 : : struct rte_flow *flow,
91 : : const struct rte_flow_attr *attr,
92 : : const struct rte_flow_action *app_actions,
93 : : uint32_t flow_idx,
94 : : const struct mlx5_flow_tunnel *tunnel,
95 : : struct tunnel_default_miss_ctx *ctx,
96 : : struct rte_flow_error *error);
97 : : static struct mlx5_flow_tunnel *
98 : : mlx5_find_tunnel_id(struct rte_eth_dev *dev, uint32_t id);
99 : : static void
100 : : mlx5_flow_tunnel_free(struct rte_eth_dev *dev, struct mlx5_flow_tunnel *tunnel);
101 : : static uint32_t
102 : : tunnel_flow_group_to_flow_table(struct rte_eth_dev *dev,
103 : : const struct mlx5_flow_tunnel *tunnel,
104 : : uint32_t group, uint32_t *table,
105 : : struct rte_flow_error *error);
106 : :
107 : : /** Device flow drivers. */
108 : : extern const struct mlx5_flow_driver_ops mlx5_flow_verbs_drv_ops;
109 : :
110 : : const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops;
111 : :
112 : : const struct mlx5_flow_driver_ops *flow_drv_ops[] = {
113 : : [MLX5_FLOW_TYPE_MIN] = &mlx5_flow_null_drv_ops,
114 : : #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
115 : : [MLX5_FLOW_TYPE_DV] = &mlx5_flow_dv_drv_ops,
116 : : #endif
117 : : #ifdef HAVE_MLX5_HWS_SUPPORT
118 : : [MLX5_FLOW_TYPE_HW] = &mlx5_flow_hw_drv_ops,
119 : : #endif
120 : : [MLX5_FLOW_TYPE_VERBS] = &mlx5_flow_verbs_drv_ops,
121 : : [MLX5_FLOW_TYPE_MAX] = &mlx5_flow_null_drv_ops
122 : : };
123 : :
124 : : /** Helper macro to build input graph for mlx5_flow_expand_rss(). */
125 : : #define MLX5_FLOW_EXPAND_RSS_NEXT(...) \
126 : : (const int []){ \
127 : : __VA_ARGS__, 0, \
128 : : }
129 : :
130 : : /** Node object of input graph for mlx5_flow_expand_rss(). */
131 : : struct mlx5_flow_expand_node {
132 : : const int *const next;
133 : : /**<
134 : : * List of next node indexes. Index 0 is interpreted as a terminator.
135 : : */
136 : : const enum rte_flow_item_type type;
137 : : /**< Pattern item type of current node. */
138 : : uint64_t rss_types;
139 : : /**<
140 : : * RSS types bit-field associated with this node
141 : : * (see RTE_ETH_RSS_* definitions).
142 : : */
143 : : uint64_t node_flags;
144 : : /**<
145 : : * Bit-fields that define how the node is used in the expansion.
146 : : * (see MLX5_EXPANSION_NODE_* definitions).
147 : : */
148 : : };
149 : :
150 : : /** Keep same format with mlx5_flow_expand_rss to share the buffer for expansion. */
151 : : struct mlx5_flow_expand_sqn {
152 : : uint32_t entries; /** Number of entries */
153 : : struct {
154 : : struct rte_flow_item *pattern; /**< Expanded pattern array. */
155 : : uint32_t priority; /**< Priority offset for each expansion. */
156 : : } entry[];
157 : : };
158 : :
159 : : /* Optional expand field. The expansion alg will not go deeper. */
160 : : #define MLX5_EXPANSION_NODE_OPTIONAL (UINT64_C(1) << 0)
161 : :
162 : : /* The node is not added implicitly as expansion to the flow pattern.
163 : : * If the node type does not match the flow pattern item type, the
164 : : * expansion alg will go deeper to its next items.
165 : : * In the current implementation, the list of next nodes indexes can
166 : : * have up to one node with this flag set and it has to be the last
167 : : * node index (before the list terminator).
168 : : */
169 : : #define MLX5_EXPANSION_NODE_EXPLICIT (UINT64_C(1) << 1)
170 : :
171 : : /** Object returned by mlx5_flow_expand_rss(). */
172 : : struct mlx5_flow_expand_rss {
173 : : uint32_t entries;
174 : : /**< Number of entries @p patterns and @p priorities. */
175 : : struct {
176 : : struct rte_flow_item *pattern; /**< Expanded pattern array. */
177 : : uint32_t priority; /**< Priority offset for each expansion. */
178 : : } entry[];
179 : : };
180 : :
181 : : static void
182 : : mlx5_dbg__print_pattern(const struct rte_flow_item *item);
183 : :
184 : : static const struct mlx5_flow_expand_node *
185 : : mlx5_flow_expand_rss_adjust_node(const struct rte_flow_item *pattern,
186 : : unsigned int item_idx,
187 : : const struct mlx5_flow_expand_node graph[],
188 : : const struct mlx5_flow_expand_node *node);
189 : :
190 : : static __rte_always_inline int
191 : : mlx5_need_cache_flow(const struct mlx5_priv *priv,
192 : : const struct rte_flow_attr *attr)
193 : : {
194 [ # # # # : 0 : return priv->isolated && priv->sh->config.dv_flow_en == 1 &&
# # # # ]
195 [ # # # # ]: 0 : (attr ? !attr->group : true) &&
196 [ # # # # : 0 : priv->mode_info.mode == RTE_PMD_MLX5_FLOW_ENGINE_MODE_STANDBY &&
# # # # #
# # # # #
# # ]
197 [ # # # # : 0 : (!priv->sh->config.dv_esw_en || !priv->sh->config.fdb_def_rule);
# # # # ]
198 : : }
199 : :
200 : : static bool
201 : 0 : mlx5_flow_is_rss_expandable_item(const struct rte_flow_item *item)
202 : : {
203 [ # # ]: 0 : switch (item->type) {
204 : : case RTE_FLOW_ITEM_TYPE_ETH:
205 : : case RTE_FLOW_ITEM_TYPE_VLAN:
206 : : case RTE_FLOW_ITEM_TYPE_IPV4:
207 : : case RTE_FLOW_ITEM_TYPE_IPV6:
208 : : case RTE_FLOW_ITEM_TYPE_UDP:
209 : : case RTE_FLOW_ITEM_TYPE_TCP:
210 : : case RTE_FLOW_ITEM_TYPE_ESP:
211 : : case RTE_FLOW_ITEM_TYPE_ICMP:
212 : : case RTE_FLOW_ITEM_TYPE_ICMP6:
213 : : case RTE_FLOW_ITEM_TYPE_VXLAN:
214 : : case RTE_FLOW_ITEM_TYPE_NVGRE:
215 : : case RTE_FLOW_ITEM_TYPE_GRE:
216 : : case RTE_FLOW_ITEM_TYPE_GENEVE:
217 : : case RTE_FLOW_ITEM_TYPE_MPLS:
218 : : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
219 : : case RTE_FLOW_ITEM_TYPE_GRE_KEY:
220 : : case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
221 : : case RTE_FLOW_ITEM_TYPE_GTP:
222 : : return true;
223 : : default:
224 : : break;
225 : : }
226 : 0 : return false;
227 : : }
228 : :
229 : : /**
230 : : * Network Service Header (NSH) and its next protocol values
231 : : * are described in RFC-8393.
232 : : */
233 : : static enum rte_flow_item_type
234 : : mlx5_nsh_proto_to_item_type(uint8_t proto_spec, uint8_t proto_mask)
235 : : {
236 : : enum rte_flow_item_type type;
237 : :
238 : 0 : switch (proto_mask & proto_spec) {
239 : : case 0:
240 : : type = RTE_FLOW_ITEM_TYPE_VOID;
241 : : break;
242 : : case RTE_VXLAN_GPE_TYPE_IPV4:
243 : : type = RTE_FLOW_ITEM_TYPE_IPV4;
244 : : break;
245 : : case RTE_VXLAN_GPE_TYPE_IPV6:
246 : : type = RTE_VXLAN_GPE_TYPE_IPV6;
247 : : break;
248 : : case RTE_VXLAN_GPE_TYPE_ETH:
249 : : type = RTE_FLOW_ITEM_TYPE_ETH;
250 : : break;
251 : : default:
252 : : type = RTE_FLOW_ITEM_TYPE_END;
253 : : }
254 : : return type;
255 : : }
256 : :
257 : : static enum rte_flow_item_type
258 : : mlx5_inet_proto_to_item_type(uint8_t proto_spec, uint8_t proto_mask)
259 : : {
260 : : enum rte_flow_item_type type;
261 : :
262 [ # # # # : 0 : switch (proto_mask & proto_spec) {
# # # # #
# # # #
# ]
263 : : case 0:
264 : : type = RTE_FLOW_ITEM_TYPE_VOID;
265 : : break;
266 : 0 : case IPPROTO_UDP:
267 : : type = RTE_FLOW_ITEM_TYPE_UDP;
268 : 0 : break;
269 : 0 : case IPPROTO_TCP:
270 : : type = RTE_FLOW_ITEM_TYPE_TCP;
271 : 0 : break;
272 : 0 : case IPPROTO_IPIP:
273 : : type = RTE_FLOW_ITEM_TYPE_IPV4;
274 : 0 : break;
275 : 0 : case IPPROTO_IPV6:
276 : : type = RTE_FLOW_ITEM_TYPE_IPV6;
277 : 0 : break;
278 : 0 : case IPPROTO_ESP:
279 : : type = RTE_FLOW_ITEM_TYPE_ESP;
280 : 0 : break;
281 : 0 : default:
282 : : type = RTE_FLOW_ITEM_TYPE_END;
283 : : }
284 : : return type;
285 : : }
286 : :
287 : : static enum rte_flow_item_type
288 : : mlx5_ethertype_to_item_type(rte_be16_t type_spec,
289 : : rte_be16_t type_mask, bool is_tunnel)
290 : : {
291 : : enum rte_flow_item_type type;
292 : :
293 [ # # # # : 0 : switch (rte_be_to_cpu_16(type_spec & type_mask)) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
294 : : case 0:
295 : : type = RTE_FLOW_ITEM_TYPE_VOID;
296 : : break;
297 : 0 : case RTE_ETHER_TYPE_TEB:
298 : : type = is_tunnel ?
299 : : RTE_FLOW_ITEM_TYPE_ETH : RTE_FLOW_ITEM_TYPE_END;
300 : : break;
301 : 0 : case RTE_ETHER_TYPE_VLAN:
302 : : type = !is_tunnel ?
303 : : RTE_FLOW_ITEM_TYPE_VLAN : RTE_FLOW_ITEM_TYPE_END;
304 : : break;
305 : 0 : case RTE_ETHER_TYPE_IPV4:
306 : : type = RTE_FLOW_ITEM_TYPE_IPV4;
307 : 0 : break;
308 : 0 : case RTE_ETHER_TYPE_IPV6:
309 : : type = RTE_FLOW_ITEM_TYPE_IPV6;
310 : 0 : break;
311 : 0 : default:
312 : : type = RTE_FLOW_ITEM_TYPE_END;
313 : : }
314 : : return type;
315 : : }
316 : :
317 : : static enum rte_flow_item_type
318 : 0 : mlx5_flow_expand_rss_item_complete(const struct rte_flow_item *item)
319 : : {
320 : : #define MLX5_XSET_ITEM_MASK_SPEC(type, fld) \
321 : : do { \
322 : : const void *m = item->mask; \
323 : : const void *s = item->spec; \
324 : : mask = m ? \
325 : : ((const struct rte_flow_item_##type *)m)->fld : \
326 : : rte_flow_item_##type##_mask.fld; \
327 : : spec = ((const struct rte_flow_item_##type *)s)->fld; \
328 : : } while (0)
329 : :
330 : : enum rte_flow_item_type ret;
331 : : uint16_t spec, mask;
332 : :
333 [ # # # # ]: 0 : if (item == NULL || item->spec == NULL)
334 : : return RTE_FLOW_ITEM_TYPE_VOID;
335 [ # # # # : 0 : switch (item->type) {
# # # # ]
336 : 0 : case RTE_FLOW_ITEM_TYPE_ETH:
337 [ # # ]: 0 : MLX5_XSET_ITEM_MASK_SPEC(eth, hdr.ether_type);
338 [ # # ]: 0 : if (!mask)
339 : : return RTE_FLOW_ITEM_TYPE_VOID;
340 : : ret = mlx5_ethertype_to_item_type(spec, mask, false);
341 : : break;
342 : 0 : case RTE_FLOW_ITEM_TYPE_VLAN:
343 [ # # ]: 0 : MLX5_XSET_ITEM_MASK_SPEC(vlan, hdr.eth_proto);
344 [ # # ]: 0 : if (!mask)
345 : : return RTE_FLOW_ITEM_TYPE_VOID;
346 : : ret = mlx5_ethertype_to_item_type(spec, mask, false);
347 : : break;
348 : 0 : case RTE_FLOW_ITEM_TYPE_IPV4:
349 [ # # ]: 0 : MLX5_XSET_ITEM_MASK_SPEC(ipv4, hdr.next_proto_id);
350 [ # # ]: 0 : if (!mask)
351 : : return RTE_FLOW_ITEM_TYPE_VOID;
352 : : ret = mlx5_inet_proto_to_item_type(spec, mask);
353 : : break;
354 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6:
355 [ # # ]: 0 : MLX5_XSET_ITEM_MASK_SPEC(ipv6, hdr.proto);
356 [ # # ]: 0 : if (!mask)
357 : : return RTE_FLOW_ITEM_TYPE_VOID;
358 : : ret = mlx5_inet_proto_to_item_type(spec, mask);
359 : : break;
360 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE:
361 [ # # # # ]: 0 : MLX5_XSET_ITEM_MASK_SPEC(geneve, protocol);
362 : : ret = mlx5_ethertype_to_item_type(spec, mask, true);
363 : : break;
364 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
365 [ # # # # ]: 0 : MLX5_XSET_ITEM_MASK_SPEC(gre, protocol);
366 : : ret = mlx5_ethertype_to_item_type(spec, mask, true);
367 : : break;
368 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
369 [ # # ]: 0 : MLX5_XSET_ITEM_MASK_SPEC(vxlan_gpe, hdr.proto);
370 [ # # ]: 0 : ret = mlx5_nsh_proto_to_item_type(spec, mask);
371 : : break;
372 : : default:
373 : : ret = RTE_FLOW_ITEM_TYPE_VOID;
374 : : break;
375 : : }
376 : : return ret;
377 : : #undef MLX5_XSET_ITEM_MASK_SPEC
378 : : }
379 : :
380 : : static const int *
381 : : mlx5_flow_expand_rss_skip_explicit(const struct mlx5_flow_expand_node graph[],
382 : : const int *next_node)
383 : : {
384 : : const struct mlx5_flow_expand_node *node = NULL;
385 : : const int *next = next_node;
386 : :
387 [ # # # # : 0 : while (next && *next) {
# # # # #
# # # # #
# # ]
388 : : /*
389 : : * Skip the nodes with the MLX5_EXPANSION_NODE_EXPLICIT
390 : : * flag set, because they were not found in the flow pattern.
391 : : */
392 : 0 : node = &graph[*next];
393 [ # # # # : 0 : if (!(node->node_flags & MLX5_EXPANSION_NODE_EXPLICIT))
# # # # ]
394 : : break;
395 : 0 : next = node->next;
396 : : }
397 : : return next;
398 : : }
399 : :
400 : : #define MLX5_RSS_EXP_ELT_N 32
401 : :
402 : : /**
403 : : * Expand RSS flows into several possible flows according to the RSS hash
404 : : * fields requested and the driver capabilities.
405 : : *
406 : : * @param[out] buf
407 : : * Buffer to store the result expansion.
408 : : * @param[in] size
409 : : * Buffer size in bytes. If 0, @p buf can be NULL.
410 : : * @param[in] pattern
411 : : * User flow pattern.
412 : : * @param[in] types
413 : : * RSS types to expand (see RTE_ETH_RSS_* definitions).
414 : : * @param[in] graph
415 : : * Input graph to expand @p pattern according to @p types.
416 : : * @param[in] graph_root_index
417 : : * Index of root node in @p graph, typically 0.
418 : : *
419 : : * @return
420 : : * A positive value representing the size of @p buf in bytes regardless of
421 : : * @p size on success, a negative errno value otherwise and rte_errno is
422 : : * set, the following errors are defined:
423 : : *
424 : : * -E2BIG: graph-depth @p graph is too deep.
425 : : * -EINVAL: @p size has not enough space for expanded pattern.
426 : : */
427 : : static int
428 : 0 : mlx5_flow_expand_rss(struct mlx5_flow_expand_rss *buf, size_t size,
429 : : const struct rte_flow_item *pattern, uint64_t types,
430 : : const struct mlx5_flow_expand_node graph[],
431 : : int graph_root_index)
432 : : {
433 : : const struct rte_flow_item *item;
434 [ # # ]: 0 : const struct mlx5_flow_expand_node *node = &graph[graph_root_index];
435 : : const int *next_node;
436 : : const int *stack[MLX5_RSS_EXP_ELT_N];
437 : : int stack_pos = 0;
438 : : struct rte_flow_item flow_items[MLX5_RSS_EXP_ELT_N];
439 : : unsigned int i, item_idx, last_expand_item_idx = 0;
440 : : size_t lsize;
441 : : size_t user_pattern_size = 0;
442 : : void *addr = NULL;
443 : : const struct mlx5_flow_expand_node *next = NULL;
444 : : struct rte_flow_item missed_item;
445 : : int missed = 0;
446 : : int elt = 0;
447 : : const struct rte_flow_item *last_expand_item = NULL;
448 : :
449 : : memset(&missed_item, 0, sizeof(missed_item));
450 : : lsize = offsetof(struct mlx5_flow_expand_rss, entry) +
451 : : MLX5_RSS_EXP_ELT_N * sizeof(buf->entry[0]);
452 [ # # ]: 0 : if (lsize > size)
453 : : return -EINVAL;
454 : 0 : buf->entry[0].priority = 0;
455 : 0 : buf->entry[0].pattern = (void *)&buf->entry[MLX5_RSS_EXP_ELT_N];
456 : 0 : buf->entries = 0;
457 : : addr = buf->entry[0].pattern;
458 : 0 : for (item = pattern, item_idx = 0;
459 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_END;
460 : 0 : item++, item_idx++) {
461 [ # # ]: 0 : if (!mlx5_flow_is_rss_expandable_item(item)) {
462 : 0 : user_pattern_size += sizeof(*item);
463 : 0 : continue;
464 : : }
465 : : last_expand_item = item;
466 : : last_expand_item_idx = item_idx;
467 : : i = 0;
468 [ # # # # ]: 0 : while (node->next && node->next[i]) {
469 : 0 : next = &graph[node->next[i]];
470 [ # # ]: 0 : if (next->type == item->type)
471 : : break;
472 [ # # ]: 0 : if (next->node_flags & MLX5_EXPANSION_NODE_EXPLICIT) {
473 : : node = next;
474 : : i = 0;
475 : : } else {
476 : 0 : ++i;
477 : : }
478 : : }
479 [ # # ]: 0 : if (next)
480 : : node = next;
481 : 0 : user_pattern_size += sizeof(*item);
482 : : }
483 : 0 : user_pattern_size += sizeof(*item); /* Handle END item. */
484 : 0 : lsize += user_pattern_size;
485 [ # # ]: 0 : if (lsize > size)
486 : : return -EINVAL;
487 : : /* Copy the user pattern in the first entry of the buffer. */
488 : : rte_memcpy(addr, pattern, user_pattern_size);
489 : 0 : addr = (void *)(((uintptr_t)addr) + user_pattern_size);
490 : 0 : buf->entries = 1;
491 : : /* Start expanding. */
492 : : memset(flow_items, 0, sizeof(flow_items));
493 : : user_pattern_size -= sizeof(*item);
494 : : /*
495 : : * Check if the last valid item has spec set, need complete pattern,
496 : : * and the pattern can be used for expansion.
497 : : */
498 : 0 : missed_item.type = mlx5_flow_expand_rss_item_complete(last_expand_item);
499 [ # # ]: 0 : if (missed_item.type == RTE_FLOW_ITEM_TYPE_END) {
500 : : /* Item type END indicates expansion is not required. */
501 : 0 : return lsize;
502 : : }
503 [ # # ]: 0 : if (missed_item.type != RTE_FLOW_ITEM_TYPE_VOID) {
504 : : next = NULL;
505 : : missed = 1;
506 : : i = 0;
507 [ # # # # ]: 0 : while (node->next && node->next[i]) {
508 : 0 : next = &graph[node->next[i]];
509 [ # # ]: 0 : if (next->type == missed_item.type) {
510 : 0 : flow_items[0].type = missed_item.type;
511 : : flow_items[1].type = RTE_FLOW_ITEM_TYPE_END;
512 : 0 : break;
513 : : }
514 [ # # ]: 0 : if (next->node_flags & MLX5_EXPANSION_NODE_EXPLICIT) {
515 : : node = next;
516 : : i = 0;
517 : : } else {
518 : 0 : ++i;
519 : : }
520 : : next = NULL;
521 : : }
522 : : }
523 [ # # ]: 0 : if (next && missed) {
524 : : elt = 2; /* missed item + item end. */
525 : : node = next;
526 : 0 : lsize += elt * sizeof(*item) + user_pattern_size;
527 [ # # ]: 0 : if (lsize > size)
528 : : return -EINVAL;
529 [ # # ]: 0 : if (node->rss_types & types) {
530 : 0 : buf->entry[buf->entries].priority = 1;
531 : 0 : buf->entry[buf->entries].pattern = addr;
532 : 0 : buf->entries++;
533 [ # # ]: 0 : rte_memcpy(addr, buf->entry[0].pattern,
534 : : user_pattern_size);
535 [ # # ]: 0 : addr = (void *)(((uintptr_t)addr) + user_pattern_size);
536 : : rte_memcpy(addr, flow_items, elt * sizeof(*item));
537 : 0 : addr = (void *)(((uintptr_t)addr) +
538 : : elt * sizeof(*item));
539 : : }
540 [ # # ]: 0 : } else if (last_expand_item != NULL) {
541 : 0 : node = mlx5_flow_expand_rss_adjust_node(pattern,
542 : : last_expand_item_idx, graph, node);
543 : : }
544 : : memset(flow_items, 0, sizeof(flow_items));
545 : : next_node = mlx5_flow_expand_rss_skip_explicit(graph,
546 : 0 : node->next);
547 : 0 : stack[stack_pos] = next_node;
548 [ # # ]: 0 : node = next_node ? &graph[*next_node] : NULL;
549 [ # # ]: 0 : while (node) {
550 : 0 : flow_items[stack_pos].type = node->type;
551 [ # # ]: 0 : if (node->rss_types & types) {
552 : : size_t n;
553 : : /*
554 : : * compute the number of items to copy from the
555 : : * expansion and copy it.
556 : : * When the stack_pos is 0, there are 1 element in it,
557 : : * plus the addition END item.
558 : : */
559 : 0 : elt = stack_pos + 2;
560 : 0 : flow_items[stack_pos + 1].type = RTE_FLOW_ITEM_TYPE_END;
561 : 0 : lsize += elt * sizeof(*item) + user_pattern_size;
562 [ # # ]: 0 : if (lsize > size)
563 : : return -EINVAL;
564 : : n = elt * sizeof(*item);
565 : : MLX5_ASSERT((buf->entries) < MLX5_RSS_EXP_ELT_N);
566 : 0 : buf->entry[buf->entries].priority =
567 : 0 : stack_pos + 1 + missed;
568 : 0 : buf->entry[buf->entries].pattern = addr;
569 : 0 : buf->entries++;
570 [ # # ]: 0 : rte_memcpy(addr, buf->entry[0].pattern,
571 : : user_pattern_size);
572 : 0 : addr = (void *)(((uintptr_t)addr) +
573 : : user_pattern_size);
574 [ # # ]: 0 : rte_memcpy(addr, &missed_item,
575 : : missed * sizeof(*item));
576 [ # # ]: 0 : addr = (void *)(((uintptr_t)addr) +
577 : : missed * sizeof(*item));
578 : : rte_memcpy(addr, flow_items, n);
579 : 0 : addr = (void *)(((uintptr_t)addr) + n);
580 : : }
581 : : /* Go deeper. */
582 [ # # ]: 0 : if (!(node->node_flags & MLX5_EXPANSION_NODE_OPTIONAL) &&
583 [ # # ]: 0 : node->next) {
584 : : next_node = mlx5_flow_expand_rss_skip_explicit(graph,
585 : : node->next);
586 [ # # ]: 0 : if (stack_pos++ == MLX5_RSS_EXP_ELT_N) {
587 : 0 : rte_errno = E2BIG;
588 : 0 : return -rte_errno;
589 : : }
590 : 0 : stack[stack_pos] = next_node;
591 [ # # ]: 0 : } else if (*(next_node + 1)) {
592 : : /* Follow up with the next possibility. */
593 : 0 : next_node = mlx5_flow_expand_rss_skip_explicit(graph,
594 : : ++next_node);
595 [ # # ]: 0 : } else if (!stack_pos) {
596 : : /*
597 : : * Completing the traverse over the different paths.
598 : : * The next_node is advanced to the terminator.
599 : : */
600 : 0 : ++next_node;
601 : : } else {
602 : : /* Move to the next path. */
603 [ # # ]: 0 : while (stack_pos) {
604 : 0 : next_node = stack[--stack_pos];
605 : 0 : next_node++;
606 [ # # ]: 0 : if (*next_node)
607 : : break;
608 : : }
609 : : next_node = mlx5_flow_expand_rss_skip_explicit(graph,
610 : : next_node);
611 : 0 : stack[stack_pos] = next_node;
612 : : }
613 [ # # # # ]: 0 : node = next_node && *next_node ? &graph[*next_node] : NULL;
614 : : };
615 : 0 : return lsize;
616 : : }
617 : :
618 : : /**
619 : : * Expand SQN flows into several possible flows according to the Tx queue
620 : : * number
621 : : *
622 : : * @param[in] buf
623 : : * Buffer to store the result expansion.
624 : : * @param[in] size
625 : : * Buffer size in bytes. If 0, @p buf can be NULL.
626 : : * @param[in] pattern
627 : : * User flow pattern.
628 : : * @param[in] sq_specs
629 : : * Buffer to store sq spec.
630 : : *
631 : : * @return
632 : : * 0 for success and negative value for failure
633 : : *
634 : : */
635 : : static int
636 : 0 : mlx5_flow_expand_sqn(struct mlx5_flow_expand_sqn *buf, size_t size,
637 : : const struct rte_flow_item *pattern,
638 : : struct mlx5_rte_flow_item_sq *sq_specs)
639 : : {
640 : : const struct rte_flow_item *item;
641 : : bool port_representor = false;
642 : : size_t user_pattern_size = 0;
643 : : struct rte_eth_dev *dev;
644 : : struct mlx5_priv *priv;
645 : : void *addr = NULL;
646 : : uint16_t port_id;
647 : : size_t lsize;
648 : : int elt = 2;
649 : : uint16_t i;
650 : :
651 : 0 : buf->entries = 0;
652 [ # # ]: 0 : for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
653 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR) {
654 : 0 : const struct rte_flow_item_ethdev *pid_v = item->spec;
655 : :
656 [ # # ]: 0 : if (!pid_v)
657 : : return 0;
658 : 0 : port_id = pid_v->port_id;
659 : : port_representor = true;
660 : : }
661 : 0 : user_pattern_size += sizeof(*item);
662 : : }
663 [ # # ]: 0 : if (!port_representor)
664 : : return 0;
665 : 0 : dev = &rte_eth_devices[port_id];
666 : 0 : priv = dev->data->dev_private;
667 : 0 : buf->entry[0].pattern = (void *)&buf->entry[priv->txqs_n];
668 : 0 : lsize = offsetof(struct mlx5_flow_expand_sqn, entry) +
669 : 0 : sizeof(buf->entry[0]) * priv->txqs_n;
670 [ # # ]: 0 : if (lsize + (user_pattern_size + sizeof(struct rte_flow_item) * elt) * priv->txqs_n > size)
671 : : return -EINVAL;
672 : : addr = buf->entry[0].pattern;
673 [ # # ]: 0 : for (i = 0; i != priv->txqs_n; ++i) {
674 : 0 : struct rte_flow_item pattern_add[] = {
675 : : {
676 : : .type = (enum rte_flow_item_type)
677 : : MLX5_RTE_FLOW_ITEM_TYPE_SQ,
678 : 0 : .spec = &sq_specs[i],
679 : : },
680 : : {
681 : : .type = RTE_FLOW_ITEM_TYPE_END,
682 : : },
683 : : };
684 : 0 : struct mlx5_txq_ctrl *txq = mlx5_txq_get(dev, i);
685 : :
686 [ # # ]: 0 : if (txq == NULL)
687 : 0 : return -EINVAL;
688 : 0 : buf->entry[i].pattern = addr;
689 : 0 : sq_specs[i].queue = mlx5_txq_get_sqn(txq);
690 : 0 : mlx5_txq_release(dev, i);
691 : : rte_memcpy(addr, pattern, user_pattern_size);
692 [ # # ]: 0 : addr = (void *)(((uintptr_t)addr) + user_pattern_size);
693 : : rte_memcpy(addr, pattern_add, sizeof(struct rte_flow_item) * elt);
694 : 0 : addr = (void *)(((uintptr_t)addr) + sizeof(struct rte_flow_item) * elt);
695 : 0 : buf->entries++;
696 : : }
697 : : return 0;
698 : : }
699 : :
700 : : enum mlx5_expansion {
701 : : MLX5_EXPANSION_ROOT,
702 : : MLX5_EXPANSION_ROOT_OUTER,
703 : : MLX5_EXPANSION_OUTER_ETH,
704 : : MLX5_EXPANSION_OUTER_VLAN,
705 : : MLX5_EXPANSION_OUTER_IPV4,
706 : : MLX5_EXPANSION_OUTER_IPV4_UDP,
707 : : MLX5_EXPANSION_OUTER_IPV4_TCP,
708 : : MLX5_EXPANSION_OUTER_IPV4_ESP,
709 : : MLX5_EXPANSION_OUTER_IPV4_ICMP,
710 : : MLX5_EXPANSION_OUTER_IPV6,
711 : : MLX5_EXPANSION_OUTER_IPV6_UDP,
712 : : MLX5_EXPANSION_OUTER_IPV6_TCP,
713 : : MLX5_EXPANSION_OUTER_IPV6_ESP,
714 : : MLX5_EXPANSION_OUTER_IPV6_ICMP6,
715 : : MLX5_EXPANSION_VXLAN,
716 : : MLX5_EXPANSION_STD_VXLAN,
717 : : MLX5_EXPANSION_L3_VXLAN,
718 : : MLX5_EXPANSION_VXLAN_GPE,
719 : : MLX5_EXPANSION_GRE,
720 : : MLX5_EXPANSION_NVGRE,
721 : : MLX5_EXPANSION_GRE_KEY,
722 : : MLX5_EXPANSION_MPLS,
723 : : MLX5_EXPANSION_ETH,
724 : : MLX5_EXPANSION_VLAN,
725 : : MLX5_EXPANSION_IPV4,
726 : : MLX5_EXPANSION_IPV4_UDP,
727 : : MLX5_EXPANSION_IPV4_TCP,
728 : : MLX5_EXPANSION_IPV4_ESP,
729 : : MLX5_EXPANSION_IPV4_ICMP,
730 : : MLX5_EXPANSION_IPV6,
731 : : MLX5_EXPANSION_IPV6_UDP,
732 : : MLX5_EXPANSION_IPV6_TCP,
733 : : MLX5_EXPANSION_IPV6_ESP,
734 : : MLX5_EXPANSION_IPV6_ICMP6,
735 : : MLX5_EXPANSION_IPV6_FRAG_EXT,
736 : : MLX5_EXPANSION_GTP,
737 : : MLX5_EXPANSION_GENEVE,
738 : : };
739 : :
740 : : /** Supported expansion of items. */
741 : : static const struct mlx5_flow_expand_node mlx5_support_expansion[] = {
742 : : [MLX5_EXPANSION_ROOT] = {
743 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
744 : : MLX5_EXPANSION_IPV4,
745 : : MLX5_EXPANSION_IPV6),
746 : : .type = RTE_FLOW_ITEM_TYPE_END,
747 : : },
748 : : [MLX5_EXPANSION_ROOT_OUTER] = {
749 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH,
750 : : MLX5_EXPANSION_OUTER_IPV4,
751 : : MLX5_EXPANSION_OUTER_IPV6),
752 : : .type = RTE_FLOW_ITEM_TYPE_END,
753 : : },
754 : : [MLX5_EXPANSION_OUTER_ETH] = {
755 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_VLAN),
756 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
757 : : .rss_types = 0,
758 : : },
759 : : [MLX5_EXPANSION_OUTER_VLAN] = {
760 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
761 : : MLX5_EXPANSION_OUTER_IPV6),
762 : : .type = RTE_FLOW_ITEM_TYPE_VLAN,
763 : : .node_flags = MLX5_EXPANSION_NODE_EXPLICIT,
764 : : },
765 : : [MLX5_EXPANSION_OUTER_IPV4] = {
766 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT
767 : : (MLX5_EXPANSION_OUTER_IPV4_UDP,
768 : : MLX5_EXPANSION_OUTER_IPV4_TCP,
769 : : MLX5_EXPANSION_OUTER_IPV4_ESP,
770 : : MLX5_EXPANSION_OUTER_IPV4_ICMP,
771 : : MLX5_EXPANSION_GRE,
772 : : MLX5_EXPANSION_NVGRE,
773 : : MLX5_EXPANSION_IPV4,
774 : : MLX5_EXPANSION_IPV6),
775 : : .type = RTE_FLOW_ITEM_TYPE_IPV4,
776 : : .rss_types = RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_FRAG_IPV4 |
777 : : RTE_ETH_RSS_NONFRAG_IPV4_OTHER,
778 : : },
779 : : [MLX5_EXPANSION_OUTER_IPV4_UDP] = {
780 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
781 : : MLX5_EXPANSION_VXLAN_GPE,
782 : : MLX5_EXPANSION_MPLS,
783 : : MLX5_EXPANSION_GENEVE,
784 : : MLX5_EXPANSION_GTP),
785 : : .type = RTE_FLOW_ITEM_TYPE_UDP,
786 : : .rss_types = RTE_ETH_RSS_NONFRAG_IPV4_UDP,
787 : : },
788 : : [MLX5_EXPANSION_OUTER_IPV4_TCP] = {
789 : : .type = RTE_FLOW_ITEM_TYPE_TCP,
790 : : .rss_types = RTE_ETH_RSS_NONFRAG_IPV4_TCP,
791 : : },
792 : : [MLX5_EXPANSION_OUTER_IPV4_ESP] = {
793 : : .type = RTE_FLOW_ITEM_TYPE_ESP,
794 : : .rss_types = RTE_ETH_RSS_ESP,
795 : : },
796 : : [MLX5_EXPANSION_OUTER_IPV4_ICMP] = {
797 : : .type = RTE_FLOW_ITEM_TYPE_ICMP,
798 : : },
799 : : [MLX5_EXPANSION_OUTER_IPV6] = {
800 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT
801 : : (MLX5_EXPANSION_OUTER_IPV6_UDP,
802 : : MLX5_EXPANSION_OUTER_IPV6_TCP,
803 : : MLX5_EXPANSION_OUTER_IPV6_ESP,
804 : : MLX5_EXPANSION_OUTER_IPV6_ICMP6,
805 : : MLX5_EXPANSION_IPV4,
806 : : MLX5_EXPANSION_IPV6,
807 : : MLX5_EXPANSION_GRE,
808 : : MLX5_EXPANSION_NVGRE),
809 : : .type = RTE_FLOW_ITEM_TYPE_IPV6,
810 : : .rss_types = RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_FRAG_IPV6 |
811 : : RTE_ETH_RSS_NONFRAG_IPV6_OTHER,
812 : : },
813 : : [MLX5_EXPANSION_OUTER_IPV6_UDP] = {
814 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
815 : : MLX5_EXPANSION_VXLAN_GPE,
816 : : MLX5_EXPANSION_MPLS,
817 : : MLX5_EXPANSION_GENEVE,
818 : : MLX5_EXPANSION_GTP),
819 : : .type = RTE_FLOW_ITEM_TYPE_UDP,
820 : : .rss_types = RTE_ETH_RSS_NONFRAG_IPV6_UDP,
821 : : },
822 : : [MLX5_EXPANSION_OUTER_IPV6_TCP] = {
823 : : .type = RTE_FLOW_ITEM_TYPE_TCP,
824 : : .rss_types = RTE_ETH_RSS_NONFRAG_IPV6_TCP,
825 : : },
826 : : [MLX5_EXPANSION_OUTER_IPV6_ESP] = {
827 : : .type = RTE_FLOW_ITEM_TYPE_ESP,
828 : : .rss_types = RTE_ETH_RSS_ESP,
829 : : },
830 : : [MLX5_EXPANSION_OUTER_IPV6_ICMP6] = {
831 : : .type = RTE_FLOW_ITEM_TYPE_ICMP6,
832 : : },
833 : : [MLX5_EXPANSION_VXLAN] = {
834 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
835 : : MLX5_EXPANSION_IPV4,
836 : : MLX5_EXPANSION_IPV6),
837 : : .type = RTE_FLOW_ITEM_TYPE_VXLAN,
838 : : },
839 : : [MLX5_EXPANSION_STD_VXLAN] = {
840 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH),
841 : : .type = RTE_FLOW_ITEM_TYPE_VXLAN,
842 : : },
843 : : [MLX5_EXPANSION_L3_VXLAN] = {
844 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
845 : : MLX5_EXPANSION_IPV6),
846 : : .type = RTE_FLOW_ITEM_TYPE_VXLAN,
847 : : },
848 : : [MLX5_EXPANSION_VXLAN_GPE] = {
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_GPE,
853 : : },
854 : : [MLX5_EXPANSION_GRE] = {
855 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
856 : : MLX5_EXPANSION_IPV4,
857 : : MLX5_EXPANSION_IPV6,
858 : : MLX5_EXPANSION_GRE_KEY,
859 : : MLX5_EXPANSION_MPLS),
860 : : .type = RTE_FLOW_ITEM_TYPE_GRE,
861 : : },
862 : : [MLX5_EXPANSION_GRE_KEY] = {
863 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
864 : : MLX5_EXPANSION_IPV6,
865 : : MLX5_EXPANSION_MPLS),
866 : : .type = RTE_FLOW_ITEM_TYPE_GRE_KEY,
867 : : .node_flags = MLX5_EXPANSION_NODE_OPTIONAL,
868 : : },
869 : : [MLX5_EXPANSION_NVGRE] = {
870 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH),
871 : : .type = RTE_FLOW_ITEM_TYPE_NVGRE,
872 : : },
873 : : [MLX5_EXPANSION_MPLS] = {
874 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
875 : : MLX5_EXPANSION_IPV6,
876 : : MLX5_EXPANSION_ETH),
877 : : .type = RTE_FLOW_ITEM_TYPE_MPLS,
878 : : .node_flags = MLX5_EXPANSION_NODE_OPTIONAL,
879 : : },
880 : : [MLX5_EXPANSION_ETH] = {
881 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VLAN),
882 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
883 : : },
884 : : [MLX5_EXPANSION_VLAN] = {
885 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
886 : : MLX5_EXPANSION_IPV6),
887 : : .type = RTE_FLOW_ITEM_TYPE_VLAN,
888 : : .node_flags = MLX5_EXPANSION_NODE_EXPLICIT,
889 : : },
890 : : [MLX5_EXPANSION_IPV4] = {
891 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4_UDP,
892 : : MLX5_EXPANSION_IPV4_TCP,
893 : : MLX5_EXPANSION_IPV4_ESP,
894 : : MLX5_EXPANSION_IPV4_ICMP),
895 : : .type = RTE_FLOW_ITEM_TYPE_IPV4,
896 : : .rss_types = RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_FRAG_IPV4 |
897 : : RTE_ETH_RSS_NONFRAG_IPV4_OTHER,
898 : : },
899 : : [MLX5_EXPANSION_IPV4_UDP] = {
900 : : .type = RTE_FLOW_ITEM_TYPE_UDP,
901 : : .rss_types = RTE_ETH_RSS_NONFRAG_IPV4_UDP,
902 : : },
903 : : [MLX5_EXPANSION_IPV4_TCP] = {
904 : : .type = RTE_FLOW_ITEM_TYPE_TCP,
905 : : .rss_types = RTE_ETH_RSS_NONFRAG_IPV4_TCP,
906 : : },
907 : : [MLX5_EXPANSION_IPV4_ESP] = {
908 : : .type = RTE_FLOW_ITEM_TYPE_ESP,
909 : : .rss_types = RTE_ETH_RSS_ESP,
910 : : },
911 : : [MLX5_EXPANSION_IPV4_ICMP] = {
912 : : .type = RTE_FLOW_ITEM_TYPE_ICMP,
913 : : },
914 : : [MLX5_EXPANSION_IPV6] = {
915 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV6_UDP,
916 : : MLX5_EXPANSION_IPV6_TCP,
917 : : MLX5_EXPANSION_IPV6_ESP,
918 : : MLX5_EXPANSION_IPV6_ICMP6,
919 : : MLX5_EXPANSION_IPV6_FRAG_EXT),
920 : : .type = RTE_FLOW_ITEM_TYPE_IPV6,
921 : : .rss_types = RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_FRAG_IPV6 |
922 : : RTE_ETH_RSS_NONFRAG_IPV6_OTHER,
923 : : },
924 : : [MLX5_EXPANSION_IPV6_UDP] = {
925 : : .type = RTE_FLOW_ITEM_TYPE_UDP,
926 : : .rss_types = RTE_ETH_RSS_NONFRAG_IPV6_UDP,
927 : : },
928 : : [MLX5_EXPANSION_IPV6_TCP] = {
929 : : .type = RTE_FLOW_ITEM_TYPE_TCP,
930 : : .rss_types = RTE_ETH_RSS_NONFRAG_IPV6_TCP,
931 : : },
932 : : [MLX5_EXPANSION_IPV6_ESP] = {
933 : : .type = RTE_FLOW_ITEM_TYPE_ESP,
934 : : .rss_types = RTE_ETH_RSS_ESP,
935 : : },
936 : : [MLX5_EXPANSION_IPV6_FRAG_EXT] = {
937 : : .type = RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT,
938 : : },
939 : : [MLX5_EXPANSION_IPV6_ICMP6] = {
940 : : .type = RTE_FLOW_ITEM_TYPE_ICMP6,
941 : : },
942 : : [MLX5_EXPANSION_GTP] = {
943 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
944 : : MLX5_EXPANSION_IPV6),
945 : : .type = RTE_FLOW_ITEM_TYPE_GTP,
946 : : },
947 : : [MLX5_EXPANSION_GENEVE] = {
948 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
949 : : MLX5_EXPANSION_IPV4,
950 : : MLX5_EXPANSION_IPV6),
951 : : .type = RTE_FLOW_ITEM_TYPE_GENEVE,
952 : : },
953 : : };
954 : :
955 : : static struct rte_flow_action_handle *
956 : : mlx5_action_handle_create(struct rte_eth_dev *dev,
957 : : const struct rte_flow_indir_action_conf *conf,
958 : : const struct rte_flow_action *action,
959 : : struct rte_flow_error *error);
960 : : static int mlx5_action_handle_destroy
961 : : (struct rte_eth_dev *dev,
962 : : struct rte_flow_action_handle *handle,
963 : : struct rte_flow_error *error);
964 : : static int mlx5_action_handle_update
965 : : (struct rte_eth_dev *dev,
966 : : struct rte_flow_action_handle *handle,
967 : : const void *update,
968 : : struct rte_flow_error *error);
969 : : static int mlx5_action_handle_query
970 : : (struct rte_eth_dev *dev,
971 : : const struct rte_flow_action_handle *handle,
972 : : void *data,
973 : : struct rte_flow_error *error);
974 : : static int
975 : : mlx5_flow_tunnel_decap_set(struct rte_eth_dev *dev,
976 : : struct rte_flow_tunnel *app_tunnel,
977 : : struct rte_flow_action **actions,
978 : : uint32_t *num_of_actions,
979 : : struct rte_flow_error *error);
980 : : static int
981 : : mlx5_flow_tunnel_match(struct rte_eth_dev *dev,
982 : : struct rte_flow_tunnel *app_tunnel,
983 : : struct rte_flow_item **items,
984 : : uint32_t *num_of_items,
985 : : struct rte_flow_error *error);
986 : : static int
987 : : mlx5_flow_tunnel_item_release(struct rte_eth_dev *dev,
988 : : struct rte_flow_item *pmd_items,
989 : : uint32_t num_items, struct rte_flow_error *err);
990 : : static int
991 : : mlx5_flow_tunnel_action_release(struct rte_eth_dev *dev,
992 : : struct rte_flow_action *pmd_actions,
993 : : uint32_t num_actions,
994 : : struct rte_flow_error *err);
995 : : static int
996 : : mlx5_flow_tunnel_get_restore_info(struct rte_eth_dev *dev,
997 : : struct rte_mbuf *m,
998 : : struct rte_flow_restore_info *info,
999 : : struct rte_flow_error *err);
1000 : : static struct rte_flow_item_flex_handle *
1001 : : mlx5_flow_flex_item_create(struct rte_eth_dev *dev,
1002 : : const struct rte_flow_item_flex_conf *conf,
1003 : : struct rte_flow_error *error);
1004 : : static int
1005 : : mlx5_flow_flex_item_release(struct rte_eth_dev *dev,
1006 : : const struct rte_flow_item_flex_handle *handle,
1007 : : struct rte_flow_error *error);
1008 : : static int
1009 : : mlx5_flow_info_get(struct rte_eth_dev *dev,
1010 : : struct rte_flow_port_info *port_info,
1011 : : struct rte_flow_queue_info *queue_info,
1012 : : struct rte_flow_error *error);
1013 : : static int
1014 : : mlx5_flow_port_configure(struct rte_eth_dev *dev,
1015 : : const struct rte_flow_port_attr *port_attr,
1016 : : uint16_t nb_queue,
1017 : : const struct rte_flow_queue_attr *queue_attr[],
1018 : : struct rte_flow_error *err);
1019 : :
1020 : : static struct rte_flow_pattern_template *
1021 : : mlx5_flow_pattern_template_create(struct rte_eth_dev *dev,
1022 : : const struct rte_flow_pattern_template_attr *attr,
1023 : : const struct rte_flow_item items[],
1024 : : struct rte_flow_error *error);
1025 : :
1026 : : static int
1027 : : mlx5_flow_pattern_template_destroy(struct rte_eth_dev *dev,
1028 : : struct rte_flow_pattern_template *template,
1029 : : struct rte_flow_error *error);
1030 : : static struct rte_flow_actions_template *
1031 : : mlx5_flow_actions_template_create(struct rte_eth_dev *dev,
1032 : : const struct rte_flow_actions_template_attr *attr,
1033 : : const struct rte_flow_action actions[],
1034 : : const struct rte_flow_action masks[],
1035 : : struct rte_flow_error *error);
1036 : : static int
1037 : : mlx5_flow_actions_template_destroy(struct rte_eth_dev *dev,
1038 : : struct rte_flow_actions_template *template,
1039 : : struct rte_flow_error *error);
1040 : :
1041 : : static struct rte_flow_template_table *
1042 : : mlx5_flow_table_create(struct rte_eth_dev *dev,
1043 : : const struct rte_flow_template_table_attr *attr,
1044 : : struct rte_flow_pattern_template *item_templates[],
1045 : : uint8_t nb_item_templates,
1046 : : struct rte_flow_actions_template *action_templates[],
1047 : : uint8_t nb_action_templates,
1048 : : struct rte_flow_error *error);
1049 : : static int
1050 : : mlx5_flow_table_destroy(struct rte_eth_dev *dev,
1051 : : struct rte_flow_template_table *table,
1052 : : struct rte_flow_error *error);
1053 : : static int
1054 : : mlx5_flow_group_set_miss_actions(struct rte_eth_dev *dev,
1055 : : uint32_t group_id,
1056 : : const struct rte_flow_group_attr *attr,
1057 : : const struct rte_flow_action actions[],
1058 : : struct rte_flow_error *error);
1059 : :
1060 : : static int
1061 : : mlx5_action_handle_query_update(struct rte_eth_dev *dev,
1062 : : struct rte_flow_action_handle *handle,
1063 : : const void *update, void *query,
1064 : : enum rte_flow_query_update_mode qu_mode,
1065 : : struct rte_flow_error *error);
1066 : :
1067 : : static struct rte_flow_action_list_handle *
1068 : : mlx5_action_list_handle_create(struct rte_eth_dev *dev,
1069 : : const struct rte_flow_indir_action_conf *conf,
1070 : : const struct rte_flow_action *actions,
1071 : : struct rte_flow_error *error);
1072 : :
1073 : : static int
1074 : : mlx5_action_list_handle_destroy(struct rte_eth_dev *dev,
1075 : : struct rte_flow_action_list_handle *handle,
1076 : : struct rte_flow_error *error);
1077 : :
1078 : : static int
1079 : : mlx5_flow_action_list_handle_query_update(struct rte_eth_dev *dev,
1080 : : const
1081 : : struct rte_flow_action_list_handle *handle,
1082 : : const void **update, void **query,
1083 : : enum rte_flow_query_update_mode mode,
1084 : : struct rte_flow_error *error);
1085 : :
1086 : : static int
1087 : : mlx5_flow_calc_table_hash(struct rte_eth_dev *dev,
1088 : : const struct rte_flow_template_table *table,
1089 : : const struct rte_flow_item pattern[],
1090 : : uint8_t pattern_template_index,
1091 : : uint32_t *hash, struct rte_flow_error *error);
1092 : : static int
1093 : : mlx5_flow_calc_encap_hash(struct rte_eth_dev *dev,
1094 : : const struct rte_flow_item pattern[],
1095 : : enum rte_flow_encap_hash_field dest_field,
1096 : : uint8_t *hash,
1097 : : struct rte_flow_error *error);
1098 : :
1099 : : static int
1100 : : mlx5_template_table_resize(struct rte_eth_dev *dev,
1101 : : struct rte_flow_template_table *table,
1102 : : uint32_t nb_rules, struct rte_flow_error *error);
1103 : : static int
1104 : : mlx5_flow_async_update_resized(struct rte_eth_dev *dev, uint32_t queue,
1105 : : const struct rte_flow_op_attr *attr,
1106 : : struct rte_flow *rule, void *user_data,
1107 : : struct rte_flow_error *error);
1108 : : static int
1109 : : mlx5_table_resize_complete(struct rte_eth_dev *dev,
1110 : : struct rte_flow_template_table *table,
1111 : : struct rte_flow_error *error);
1112 : :
1113 : : static const struct rte_flow_ops mlx5_flow_ops = {
1114 : : .validate = mlx5_flow_validate,
1115 : : .create = mlx5_flow_create,
1116 : : .destroy = mlx5_flow_destroy,
1117 : : .flush = mlx5_flow_flush,
1118 : : .isolate = mlx5_flow_isolate,
1119 : : .query = mlx5_flow_query,
1120 : : .dev_dump = mlx5_flow_dev_dump,
1121 : : .get_q_aged_flows = mlx5_flow_get_q_aged_flows,
1122 : : .get_aged_flows = mlx5_flow_get_aged_flows,
1123 : : .action_handle_create = mlx5_action_handle_create,
1124 : : .action_handle_destroy = mlx5_action_handle_destroy,
1125 : : .action_handle_update = mlx5_action_handle_update,
1126 : : .action_handle_query = mlx5_action_handle_query,
1127 : : .action_handle_query_update = mlx5_action_handle_query_update,
1128 : : .action_list_handle_create = mlx5_action_list_handle_create,
1129 : : .action_list_handle_destroy = mlx5_action_list_handle_destroy,
1130 : : .tunnel_decap_set = mlx5_flow_tunnel_decap_set,
1131 : : .tunnel_match = mlx5_flow_tunnel_match,
1132 : : .tunnel_action_decap_release = mlx5_flow_tunnel_action_release,
1133 : : .tunnel_item_release = mlx5_flow_tunnel_item_release,
1134 : : .get_restore_info = mlx5_flow_tunnel_get_restore_info,
1135 : : .flex_item_create = mlx5_flow_flex_item_create,
1136 : : .flex_item_release = mlx5_flow_flex_item_release,
1137 : : .info_get = mlx5_flow_info_get,
1138 : : .pick_transfer_proxy = mlx5_flow_pick_transfer_proxy,
1139 : : .configure = mlx5_flow_port_configure,
1140 : : .pattern_template_create = mlx5_flow_pattern_template_create,
1141 : : .pattern_template_destroy = mlx5_flow_pattern_template_destroy,
1142 : : .actions_template_create = mlx5_flow_actions_template_create,
1143 : : .actions_template_destroy = mlx5_flow_actions_template_destroy,
1144 : : .template_table_create = mlx5_flow_table_create,
1145 : : .template_table_destroy = mlx5_flow_table_destroy,
1146 : : .group_set_miss_actions = mlx5_flow_group_set_miss_actions,
1147 : : .action_list_handle_query_update =
1148 : : mlx5_flow_action_list_handle_query_update,
1149 : : .flow_calc_table_hash = mlx5_flow_calc_table_hash,
1150 : : .flow_calc_encap_hash = mlx5_flow_calc_encap_hash,
1151 : : .flow_template_table_resize = mlx5_template_table_resize,
1152 : : .flow_update_resized = mlx5_flow_async_update_resized,
1153 : : .flow_template_table_resize_complete = mlx5_table_resize_complete,
1154 : : };
1155 : :
1156 : : /* Tunnel information. */
1157 : : struct mlx5_flow_tunnel_info {
1158 : : uint64_t tunnel; /**< Tunnel bit (see MLX5_FLOW_*). */
1159 : : uint32_t ptype; /**< Tunnel Ptype (see RTE_PTYPE_*). */
1160 : : };
1161 : :
1162 : : static struct mlx5_flow_tunnel_info tunnels_info[] = {
1163 : : {
1164 : : .tunnel = MLX5_FLOW_LAYER_VXLAN,
1165 : : .ptype = RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_L4_UDP,
1166 : : },
1167 : : {
1168 : : .tunnel = MLX5_FLOW_LAYER_GENEVE,
1169 : : .ptype = RTE_PTYPE_TUNNEL_GENEVE | RTE_PTYPE_L4_UDP,
1170 : : },
1171 : : {
1172 : : .tunnel = MLX5_FLOW_LAYER_VXLAN_GPE,
1173 : : .ptype = RTE_PTYPE_TUNNEL_VXLAN_GPE | RTE_PTYPE_L4_UDP,
1174 : : },
1175 : : {
1176 : : .tunnel = MLX5_FLOW_LAYER_GRE,
1177 : : .ptype = RTE_PTYPE_TUNNEL_GRE,
1178 : : },
1179 : : {
1180 : : .tunnel = MLX5_FLOW_LAYER_MPLS | MLX5_FLOW_LAYER_OUTER_L4_UDP,
1181 : : .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_UDP | RTE_PTYPE_L4_UDP,
1182 : : },
1183 : : {
1184 : : .tunnel = MLX5_FLOW_LAYER_MPLS,
1185 : : .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE,
1186 : : },
1187 : : {
1188 : : .tunnel = MLX5_FLOW_LAYER_NVGRE,
1189 : : .ptype = RTE_PTYPE_TUNNEL_NVGRE,
1190 : : },
1191 : : {
1192 : : .tunnel = MLX5_FLOW_LAYER_IPIP,
1193 : : .ptype = RTE_PTYPE_TUNNEL_IP,
1194 : : },
1195 : : {
1196 : : .tunnel = MLX5_FLOW_LAYER_IPV6_ENCAP,
1197 : : .ptype = RTE_PTYPE_TUNNEL_IP,
1198 : : },
1199 : : {
1200 : : .tunnel = MLX5_FLOW_LAYER_GTP,
1201 : : .ptype = RTE_PTYPE_TUNNEL_GTPU,
1202 : : },
1203 : : };
1204 : :
1205 : :
1206 : :
1207 : : /**
1208 : : * Translate tag ID to register.
1209 : : *
1210 : : * @param[in] dev
1211 : : * Pointer to the Ethernet device structure.
1212 : : * @param[in] feature
1213 : : * The feature that request the register.
1214 : : * @param[in] id
1215 : : * The request register ID.
1216 : : * @param[out] error
1217 : : * Error description in case of any.
1218 : : *
1219 : : * @return
1220 : : * The request register on success, a negative errno
1221 : : * value otherwise and rte_errno is set.
1222 : : */
1223 : : int
1224 : 0 : mlx5_flow_get_reg_id(struct rte_eth_dev *dev,
1225 : : enum mlx5_feature_name feature,
1226 : : uint32_t id,
1227 : : struct rte_flow_error *error)
1228 : : {
1229 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1230 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
1231 : : struct mlx5_dev_registers *reg = &priv->sh->registers;
1232 : : enum modify_reg start_reg;
1233 : : bool skip_mtr_reg = false;
1234 : :
1235 [ # # # # : 0 : switch (feature) {
# # # # #
# # ]
1236 : : case MLX5_HAIRPIN_RX:
1237 : : return REG_B;
1238 : 0 : case MLX5_HAIRPIN_TX:
1239 : 0 : return REG_A;
1240 : 0 : case MLX5_METADATA_RX:
1241 [ # # # # : 0 : switch (config->dv_xmeta_en) {
# ]
1242 : : case MLX5_XMETA_MODE_LEGACY:
1243 : : return REG_B;
1244 : 0 : case MLX5_XMETA_MODE_META16:
1245 : 0 : return REG_C_0;
1246 : 0 : case MLX5_XMETA_MODE_META32:
1247 : 0 : return REG_C_1;
1248 : 0 : case MLX5_XMETA_MODE_META32_HWS:
1249 : 0 : return REG_C_1;
1250 : : }
1251 : : break;
1252 : 0 : case MLX5_METADATA_TX:
1253 [ # # ]: 0 : if (config->dv_flow_en == 2 && config->dv_xmeta_en == MLX5_XMETA_MODE_META32_HWS) {
1254 : : return REG_C_1;
1255 : : } else {
1256 : 0 : return REG_A;
1257 : : }
1258 : 0 : case MLX5_METADATA_FDB:
1259 [ # # # # : 0 : switch (config->dv_xmeta_en) {
# ]
1260 : : case MLX5_XMETA_MODE_LEGACY:
1261 : : return REG_NON;
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 : : break;
1270 : 0 : case MLX5_FLOW_MARK:
1271 [ # # # # ]: 0 : switch (config->dv_xmeta_en) {
1272 : : case MLX5_XMETA_MODE_LEGACY:
1273 : : case MLX5_XMETA_MODE_META32_HWS:
1274 : : return REG_NON;
1275 : 0 : case MLX5_XMETA_MODE_META16:
1276 : 0 : return REG_C_1;
1277 : 0 : case MLX5_XMETA_MODE_META32:
1278 : 0 : return REG_C_0;
1279 : : }
1280 : : break;
1281 : 0 : case MLX5_MTR_ID:
1282 : : /*
1283 : : * If meter color and meter id share one register, flow match
1284 : : * should use the meter color register for match.
1285 : : */
1286 [ # # ]: 0 : if (priv->mtr_reg_share)
1287 : 0 : return reg->aso_reg;
1288 : : else
1289 [ # # ]: 0 : return reg->aso_reg != REG_C_2 ? REG_C_2 :
1290 : : REG_C_3;
1291 : 0 : case MLX5_MTR_COLOR:
1292 : : case MLX5_ASO_FLOW_HIT:
1293 : : case MLX5_ASO_CONNTRACK:
1294 : : case MLX5_SAMPLE_ID:
1295 : : /* All features use the same REG_C. */
1296 : : MLX5_ASSERT(reg->aso_reg != REG_NON);
1297 : 0 : return reg->aso_reg;
1298 : 0 : case MLX5_COPY_MARK:
1299 : : /*
1300 : : * Metadata COPY_MARK register using is in meter suffix sub
1301 : : * flow while with meter. It's safe to share the same register.
1302 : : */
1303 [ # # ]: 0 : return reg->aso_reg != REG_C_2 ? REG_C_2 : REG_C_3;
1304 : 0 : case MLX5_APP_TAG:
1305 : : /*
1306 : : * If meter is enable, it will engage the register for color
1307 : : * match and flow match. If meter color match is not using the
1308 : : * REG_C_2, need to skip the REG_C_x be used by meter color
1309 : : * match.
1310 : : * If meter is disable, free to use all available registers.
1311 : : */
1312 [ # # ]: 0 : start_reg = reg->aso_reg != REG_C_2 ? REG_C_2 :
1313 [ # # ]: 0 : (priv->mtr_reg_share ? REG_C_3 : REG_C_4);
1314 [ # # # # ]: 0 : skip_mtr_reg = !!(priv->mtr_en && start_reg == REG_C_2);
1315 [ # # ]: 0 : if (id > (uint32_t)(REG_C_7 - start_reg))
1316 : 0 : return rte_flow_error_set(error, EINVAL,
1317 : : RTE_FLOW_ERROR_TYPE_ITEM,
1318 : : NULL, "invalid tag id");
1319 [ # # ]: 0 : if (priv->sh->flow_mreg_c[id + start_reg - REG_C_0] == REG_NON)
1320 : 0 : return rte_flow_error_set(error, ENOTSUP,
1321 : : RTE_FLOW_ERROR_TYPE_ITEM,
1322 : : NULL, "unsupported tag id");
1323 : : /*
1324 : : * This case means meter is using the REG_C_x great than 2.
1325 : : * Take care not to conflict with meter color REG_C_x.
1326 : : * If the available index REG_C_y >= REG_C_x, skip the
1327 : : * color register.
1328 : : */
1329 [ # # # # ]: 0 : if (skip_mtr_reg && priv->sh->flow_mreg_c
1330 : : [id + start_reg - REG_C_0] >= reg->aso_reg) {
1331 [ # # ]: 0 : if (id >= (uint32_t)(REG_C_7 - start_reg))
1332 : 0 : return rte_flow_error_set(error, EINVAL,
1333 : : RTE_FLOW_ERROR_TYPE_ITEM,
1334 : : NULL, "invalid tag id");
1335 : 0 : if (priv->sh->flow_mreg_c
1336 [ # # ]: 0 : [id + 1 + start_reg - REG_C_0] != REG_NON)
1337 : : return priv->sh->flow_mreg_c
1338 : 0 : [id + 1 + start_reg - REG_C_0];
1339 : 0 : return rte_flow_error_set(error, ENOTSUP,
1340 : : RTE_FLOW_ERROR_TYPE_ITEM,
1341 : : NULL, "unsupported tag id");
1342 : : }
1343 : 0 : return priv->sh->flow_mreg_c[id + start_reg - REG_C_0];
1344 : : }
1345 : : MLX5_ASSERT(false);
1346 : 0 : return rte_flow_error_set(error, EINVAL,
1347 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1348 : : NULL, "invalid feature name");
1349 : : }
1350 : :
1351 : : /**
1352 : : * Check extensive flow metadata register support.
1353 : : *
1354 : : * @param dev
1355 : : * Pointer to rte_eth_dev structure.
1356 : : *
1357 : : * @return
1358 : : * True if device supports extensive flow metadata register, otherwise false.
1359 : : */
1360 : : bool
1361 : 0 : mlx5_flow_ext_mreg_supported(struct rte_eth_dev *dev)
1362 : : {
1363 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1364 : :
1365 : : /*
1366 : : * Having available reg_c can be regarded inclusively as supporting
1367 : : * extensive flow metadata register, which could mean,
1368 : : * - metadata register copy action by modify header.
1369 : : * - 16 modify header actions is supported.
1370 : : * - reg_c's are preserved across different domain (FDB and NIC) on
1371 : : * packet loopback by flow lookup miss.
1372 : : */
1373 : 0 : return priv->sh->flow_mreg_c[2] != REG_NON;
1374 : : }
1375 : :
1376 : : /**
1377 : : * Get the lowest priority.
1378 : : *
1379 : : * @param[in] dev
1380 : : * Pointer to the Ethernet device structure.
1381 : : * @param[in] attributes
1382 : : * Pointer to device flow rule attributes.
1383 : : *
1384 : : * @return
1385 : : * The value of lowest priority of flow.
1386 : : */
1387 : : uint32_t
1388 : 0 : mlx5_get_lowest_priority(struct rte_eth_dev *dev,
1389 : : const struct rte_flow_attr *attr)
1390 : : {
1391 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1392 : :
1393 [ # # # # : 0 : if (!attr->group && !(attr->transfer && priv->fdb_def_rule))
# # ]
1394 : 0 : return priv->sh->flow_max_priority - 2;
1395 : : return MLX5_NON_ROOT_FLOW_MAX_PRIO - 1;
1396 : : }
1397 : :
1398 : : /**
1399 : : * Calculate matcher priority of the flow.
1400 : : *
1401 : : * @param[in] dev
1402 : : * Pointer to the Ethernet device structure.
1403 : : * @param[in] attr
1404 : : * Pointer to device flow rule attributes.
1405 : : * @param[in] subpriority
1406 : : * The priority based on the items.
1407 : : * @param[in] external
1408 : : * Flow is user flow.
1409 : : * @return
1410 : : * The matcher priority of the flow.
1411 : : */
1412 : : uint16_t
1413 : 0 : mlx5_get_matcher_priority(struct rte_eth_dev *dev,
1414 : : const struct rte_flow_attr *attr,
1415 : : uint32_t subpriority, bool external)
1416 : : {
1417 : 0 : uint16_t priority = (uint16_t)attr->priority;
1418 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1419 : :
1420 : : /* NIC root rules */
1421 [ # # # # ]: 0 : if (!attr->group && !attr->transfer) {
1422 [ # # ]: 0 : if (attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)
1423 : 0 : priority = priv->sh->flow_max_priority - 1;
1424 : 0 : return mlx5_os_flow_adjust_priority(dev, priority, subpriority);
1425 : : /* FDB root rules */
1426 [ # # # # : 0 : } else if (attr->transfer && (!external || !priv->fdb_def_rule) &&
# # # # ]
1427 [ # # ]: 0 : attr->group == 0 &&
1428 : : attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR) {
1429 : 0 : return (priv->sh->flow_max_priority - 1) * 3;
1430 : : }
1431 [ # # ]: 0 : if (attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)
1432 : : priority = MLX5_NON_ROOT_FLOW_MAX_PRIO;
1433 : 0 : return priority * 3 + subpriority;
1434 : : }
1435 : :
1436 : : /**
1437 : : * Verify the @p item specifications (spec, last, mask) are compatible with the
1438 : : * NIC capabilities.
1439 : : *
1440 : : * @param[in] item
1441 : : * Item specification.
1442 : : * @param[in] mask
1443 : : * @p item->mask or flow default bit-masks.
1444 : : * @param[in] nic_mask
1445 : : * Bit-masks covering supported fields by the NIC to compare with user mask.
1446 : : * @param[in] size
1447 : : * Bit-masks size in bytes.
1448 : : * @param[in] range_accepted
1449 : : * True if range of values is accepted for specific fields, false otherwise.
1450 : : * @param[out] error
1451 : : * Pointer to error structure.
1452 : : *
1453 : : * @return
1454 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1455 : : */
1456 : : int
1457 : 0 : mlx5_flow_item_acceptable(const struct rte_eth_dev *dev,
1458 : : const struct rte_flow_item *item,
1459 : : const uint8_t *mask,
1460 : : const uint8_t *nic_mask,
1461 : : unsigned int size,
1462 : : bool range_accepted,
1463 : : struct rte_flow_error *error)
1464 : : {
1465 : : unsigned int i;
1466 : :
1467 : : MLX5_ASSERT(nic_mask);
1468 [ # # ]: 0 : for (i = 0; i < size; ++i)
1469 [ # # ]: 0 : if ((nic_mask[i] | mask[i]) != nic_mask[i])
1470 : 0 : return rte_flow_error_set(error, ENOTSUP,
1471 : : RTE_FLOW_ERROR_TYPE_ITEM,
1472 : : item,
1473 : : "mask enables non supported"
1474 : : " bits");
1475 [ # # ]: 0 : if (mlx5_hws_active(dev))
1476 : : return 0;
1477 [ # # # # : 0 : if (!item->spec && (item->mask || item->last))
# # ]
1478 : 0 : return rte_flow_error_set(error, EINVAL,
1479 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
1480 : : "mask/last without a spec is not"
1481 : : " supported");
1482 [ # # # # : 0 : if (item->spec && item->last && !range_accepted) {
# # ]
1483 : 0 : uint8_t *spec = alloca(size);
1484 : 0 : uint8_t *last = alloca(size);
1485 : : unsigned int i;
1486 : : int ret;
1487 : :
1488 [ # # ]: 0 : for (i = 0; i < size; ++i) {
1489 : 0 : spec[i] = ((const uint8_t *)item->spec)[i] & mask[i];
1490 : 0 : last[i] = ((const uint8_t *)item->last)[i] & mask[i];
1491 : : }
1492 : 0 : ret = memcmp(spec, last, size);
1493 [ # # ]: 0 : if (ret != 0)
1494 : 0 : return rte_flow_error_set(error, EINVAL,
1495 : : RTE_FLOW_ERROR_TYPE_ITEM,
1496 : : item,
1497 : : "range is not valid");
1498 : : }
1499 : : return 0;
1500 : : }
1501 : :
1502 : : /**
1503 : : * Adjust the hash fields according to the @p flow information.
1504 : : *
1505 : : * @param[in] dev_flow.
1506 : : * Pointer to the mlx5_flow.
1507 : : * @param[in] tunnel
1508 : : * 1 when the hash field is for a tunnel item.
1509 : : * @param[in] layer_types
1510 : : * RTE_ETH_RSS_* types.
1511 : : * @param[in] hash_fields
1512 : : * Item hash fields.
1513 : : *
1514 : : * @return
1515 : : * The hash fields that should be used.
1516 : : */
1517 : : uint64_t
1518 : 0 : mlx5_flow_hashfields_adjust(struct mlx5_flow_rss_desc *rss_desc,
1519 : : int tunnel __rte_unused, uint64_t layer_types,
1520 : : uint64_t hash_fields)
1521 : : {
1522 : : #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1523 : 0 : int rss_request_inner = rss_desc->level >= 2;
1524 : :
1525 : : /* Check RSS hash level for tunnel. */
1526 [ # # ]: 0 : if (tunnel && rss_request_inner)
1527 : 0 : hash_fields |= IBV_RX_HASH_INNER;
1528 [ # # ]: 0 : else if (tunnel || rss_request_inner)
1529 : : return 0;
1530 : : #endif
1531 : : /* Check if requested layer matches RSS hash fields. */
1532 [ # # ]: 0 : if (!(rss_desc->types & layer_types))
1533 : 0 : return 0;
1534 : : return hash_fields;
1535 : : }
1536 : :
1537 : : /**
1538 : : * Lookup and set the ptype in the data Rx part. A single Ptype can be used,
1539 : : * if several tunnel rules are used on this queue, the tunnel ptype will be
1540 : : * cleared.
1541 : : *
1542 : : * @param rxq_ctrl
1543 : : * Rx queue to update.
1544 : : */
1545 : : static void
1546 : : flow_rxq_tunnel_ptype_update(struct mlx5_rxq_ctrl *rxq_ctrl)
1547 : : {
1548 : : unsigned int i;
1549 : : uint32_t tunnel_ptype = 0;
1550 : :
1551 : : /* Look up for the ptype to use. */
1552 [ # # # # ]: 0 : for (i = 0; i != MLX5_FLOW_TUNNEL; ++i) {
1553 [ # # # # ]: 0 : if (!rxq_ctrl->flow_tunnels_n[i])
1554 : 0 : continue;
1555 [ # # # # ]: 0 : if (!tunnel_ptype) {
1556 : 0 : tunnel_ptype = tunnels_info[i].ptype;
1557 : : } else {
1558 : : tunnel_ptype = 0;
1559 : : break;
1560 : : }
1561 : : }
1562 : 0 : rxq_ctrl->rxq.tunnel = tunnel_ptype;
1563 : 0 : }
1564 : :
1565 : : /**
1566 : : * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) according to the device
1567 : : * flow.
1568 : : *
1569 : : * @param[in] dev
1570 : : * Pointer to the Ethernet device structure.
1571 : : * @param[in] dev_handle
1572 : : * Pointer to device flow handle structure.
1573 : : */
1574 : : void
1575 : 0 : flow_drv_rxq_flags_set(struct rte_eth_dev *dev,
1576 : : struct mlx5_flow_handle *dev_handle)
1577 : : {
1578 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1579 : 0 : const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1580 : : struct mlx5_ind_table_obj *ind_tbl = NULL;
1581 : : unsigned int i;
1582 : :
1583 [ # # ]: 0 : if (dev_handle->fate_action == MLX5_FLOW_FATE_QUEUE) {
1584 : : struct mlx5_hrxq *hrxq;
1585 : :
1586 : 0 : hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1587 : : dev_handle->rix_hrxq);
1588 [ # # ]: 0 : if (hrxq)
1589 : 0 : ind_tbl = hrxq->ind_table;
1590 [ # # ]: 0 : } else if (dev_handle->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
1591 : : struct mlx5_shared_action_rss *shared_rss;
1592 : :
1593 : 0 : shared_rss = mlx5_ipool_get
1594 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
1595 : : dev_handle->rix_srss);
1596 [ # # ]: 0 : if (shared_rss)
1597 : 0 : ind_tbl = shared_rss->ind_tbl;
1598 : : }
1599 [ # # ]: 0 : if (!ind_tbl)
1600 : 0 : return;
1601 [ # # ]: 0 : for (i = 0; i != ind_tbl->queues_n; ++i) {
1602 [ # # ]: 0 : int idx = ind_tbl->queues[i];
1603 : : struct mlx5_rxq_ctrl *rxq_ctrl;
1604 : :
1605 [ # # ]: 0 : if (mlx5_is_external_rxq(dev, idx))
1606 : 0 : continue;
1607 : 0 : rxq_ctrl = mlx5_rxq_ctrl_get(dev, idx);
1608 : : MLX5_ASSERT(rxq_ctrl != NULL);
1609 [ # # ]: 0 : if (rxq_ctrl == NULL)
1610 : 0 : continue;
1611 : : /*
1612 : : * To support metadata register copy on Tx loopback,
1613 : : * this must be always enabled (metadata may arive
1614 : : * from other port - not from local flows only.
1615 : : */
1616 [ # # ]: 0 : if (tunnel) {
1617 : : unsigned int j;
1618 : :
1619 : : /* Increase the counter matching the flow. */
1620 [ # # ]: 0 : for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1621 : 0 : if ((tunnels_info[j].tunnel &
1622 [ # # ]: 0 : dev_handle->layers) ==
1623 : : tunnels_info[j].tunnel) {
1624 : 0 : rxq_ctrl->flow_tunnels_n[j]++;
1625 : 0 : break;
1626 : : }
1627 : : }
1628 : : flow_rxq_tunnel_ptype_update(rxq_ctrl);
1629 : : }
1630 : : }
1631 : : }
1632 : :
1633 : : static void
1634 : 0 : flow_rxq_mark_flag_set(struct rte_eth_dev *dev)
1635 : : {
1636 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1637 : : struct mlx5_rxq_ctrl *rxq_ctrl;
1638 : : uint16_t port_id;
1639 : :
1640 [ # # ]: 0 : if (priv->sh->shared_mark_enabled)
1641 : : return;
1642 [ # # ]: 0 : if (priv->master || priv->representor) {
1643 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port_id, dev->device) {
1644 : 0 : struct mlx5_priv *opriv =
1645 : 0 : rte_eth_devices[port_id].data->dev_private;
1646 : :
1647 [ # # ]: 0 : if (!opriv ||
1648 [ # # ]: 0 : opriv->sh != priv->sh ||
1649 [ # # # # ]: 0 : opriv->domain_id != priv->domain_id ||
1650 : : opriv->mark_enabled)
1651 : 0 : continue;
1652 [ # # ]: 0 : LIST_FOREACH(rxq_ctrl, &opriv->rxqsctrl, next) {
1653 : 0 : rxq_ctrl->rxq.mark = 1;
1654 : : }
1655 [ # # ]: 0 : LIST_FOREACH(rxq_ctrl, &opriv->sh->shared_rxqs, next) {
1656 : 0 : rxq_ctrl->rxq.mark = 1;
1657 : : }
1658 : 0 : opriv->mark_enabled = 1;
1659 : : }
1660 : : } else {
1661 [ # # ]: 0 : LIST_FOREACH(rxq_ctrl, &priv->rxqsctrl, next) {
1662 : 0 : rxq_ctrl->rxq.mark = 1;
1663 : : }
1664 [ # # ]: 0 : LIST_FOREACH(rxq_ctrl, &priv->sh->shared_rxqs, next) {
1665 : 0 : rxq_ctrl->rxq.mark = 1;
1666 : : }
1667 : 0 : priv->mark_enabled = 1;
1668 : : }
1669 : 0 : priv->sh->shared_mark_enabled = 1;
1670 : : }
1671 : :
1672 : : /**
1673 : : * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) for a flow
1674 : : *
1675 : : * @param[in] dev
1676 : : * Pointer to the Ethernet device structure.
1677 : : * @param[in] flow
1678 : : * Pointer to flow structure.
1679 : : */
1680 : : static void
1681 : 0 : flow_rxq_flags_set(struct rte_eth_dev *dev, struct rte_flow *flow)
1682 : : {
1683 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1684 : : uint32_t handle_idx;
1685 : : struct mlx5_flow_handle *dev_handle;
1686 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
1687 : :
1688 : : MLX5_ASSERT(wks);
1689 [ # # ]: 0 : if (wks->mark)
1690 : 0 : flow_rxq_mark_flag_set(dev);
1691 [ # # # # : 0 : SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
# # ]
1692 : : handle_idx, dev_handle, next)
1693 : 0 : flow_drv_rxq_flags_set(dev, dev_handle);
1694 : 0 : }
1695 : :
1696 : : /**
1697 : : * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1698 : : * device flow if no other flow uses it with the same kind of request.
1699 : : *
1700 : : * @param dev
1701 : : * Pointer to Ethernet device.
1702 : : * @param[in] dev_handle
1703 : : * Pointer to the device flow handle structure.
1704 : : */
1705 : : static void
1706 : 0 : flow_drv_rxq_flags_trim(struct rte_eth_dev *dev,
1707 : : struct mlx5_flow_handle *dev_handle)
1708 : : {
1709 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1710 : 0 : const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1711 : : struct mlx5_ind_table_obj *ind_tbl = NULL;
1712 : : unsigned int i;
1713 : :
1714 [ # # ]: 0 : if (dev_handle->fate_action == MLX5_FLOW_FATE_QUEUE) {
1715 : : struct mlx5_hrxq *hrxq;
1716 : :
1717 : 0 : hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1718 : : dev_handle->rix_hrxq);
1719 [ # # ]: 0 : if (hrxq)
1720 : 0 : ind_tbl = hrxq->ind_table;
1721 [ # # ]: 0 : } else if (dev_handle->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
1722 : : struct mlx5_shared_action_rss *shared_rss;
1723 : :
1724 : 0 : shared_rss = mlx5_ipool_get
1725 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
1726 : : dev_handle->rix_srss);
1727 [ # # ]: 0 : if (shared_rss)
1728 : 0 : ind_tbl = shared_rss->ind_tbl;
1729 : : }
1730 [ # # ]: 0 : if (!ind_tbl)
1731 : 0 : return;
1732 : : MLX5_ASSERT(dev->data->dev_started);
1733 [ # # ]: 0 : for (i = 0; i != ind_tbl->queues_n; ++i) {
1734 [ # # ]: 0 : int idx = ind_tbl->queues[i];
1735 : : struct mlx5_rxq_ctrl *rxq_ctrl;
1736 : :
1737 [ # # ]: 0 : if (mlx5_is_external_rxq(dev, idx))
1738 : 0 : continue;
1739 : 0 : rxq_ctrl = mlx5_rxq_ctrl_get(dev, idx);
1740 : : MLX5_ASSERT(rxq_ctrl != NULL);
1741 [ # # ]: 0 : if (rxq_ctrl == NULL)
1742 : 0 : continue;
1743 [ # # ]: 0 : if (tunnel) {
1744 : : unsigned int j;
1745 : :
1746 : : /* Decrease the counter matching the flow. */
1747 [ # # ]: 0 : for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1748 : 0 : if ((tunnels_info[j].tunnel &
1749 [ # # ]: 0 : dev_handle->layers) ==
1750 : : tunnels_info[j].tunnel) {
1751 : 0 : rxq_ctrl->flow_tunnels_n[j]--;
1752 : 0 : break;
1753 : : }
1754 : : }
1755 : : flow_rxq_tunnel_ptype_update(rxq_ctrl);
1756 : : }
1757 : : }
1758 : : }
1759 : :
1760 : : /**
1761 : : * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1762 : : * @p flow if no other flow uses it with the same kind of request.
1763 : : *
1764 : : * @param dev
1765 : : * Pointer to Ethernet device.
1766 : : * @param[in] flow
1767 : : * Pointer to the flow.
1768 : : */
1769 : : static void
1770 : 0 : flow_rxq_flags_trim(struct rte_eth_dev *dev, struct rte_flow *flow)
1771 : : {
1772 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1773 : : uint32_t handle_idx;
1774 : : struct mlx5_flow_handle *dev_handle;
1775 : :
1776 [ # # # # : 0 : SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
# # ]
1777 : : handle_idx, dev_handle, next)
1778 : 0 : flow_drv_rxq_flags_trim(dev, dev_handle);
1779 : 0 : }
1780 : :
1781 : : /**
1782 : : * Clear the Mark/Flag and Tunnel ptype information in all Rx queues.
1783 : : *
1784 : : * @param dev
1785 : : * Pointer to Ethernet device.
1786 : : */
1787 : : static void
1788 : 0 : flow_rxq_flags_clear(struct rte_eth_dev *dev)
1789 : : {
1790 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1791 : : unsigned int i;
1792 : :
1793 [ # # ]: 0 : for (i = 0; i != priv->rxqs_n; ++i) {
1794 : 0 : struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, i);
1795 : : unsigned int j;
1796 : :
1797 [ # # # # ]: 0 : if (rxq == NULL || rxq->ctrl == NULL)
1798 : 0 : continue;
1799 : 0 : rxq->ctrl->rxq.mark = 0;
1800 [ # # ]: 0 : for (j = 0; j != MLX5_FLOW_TUNNEL; ++j)
1801 : 0 : rxq->ctrl->flow_tunnels_n[j] = 0;
1802 : 0 : rxq->ctrl->rxq.tunnel = 0;
1803 : : }
1804 : 0 : priv->mark_enabled = 0;
1805 : 0 : priv->sh->shared_mark_enabled = 0;
1806 : 0 : }
1807 : :
1808 : : static uint64_t mlx5_restore_info_dynflag;
1809 : :
1810 : : int
1811 : 0 : mlx5_flow_rx_metadata_negotiate(struct rte_eth_dev *dev, uint64_t *features)
1812 : : {
1813 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
1814 : : uint64_t supported = 0;
1815 : :
1816 [ # # ]: 0 : if (!is_tunnel_offload_active(dev)) {
1817 : : supported |= RTE_ETH_RX_METADATA_USER_FLAG;
1818 : : supported |= RTE_ETH_RX_METADATA_USER_MARK;
1819 [ # # ]: 0 : if ((*features & RTE_ETH_RX_METADATA_TUNNEL_ID) != 0) {
1820 : 0 : DRV_LOG(DEBUG,
1821 : : "tunnel offload was not activated, consider setting dv_xmeta_en=%d",
1822 : : MLX5_XMETA_MODE_MISS_INFO);
1823 : : }
1824 : : } else {
1825 : : supported |= RTE_ETH_RX_METADATA_TUNNEL_ID;
1826 [ # # ]: 0 : if ((*features & RTE_ETH_RX_METADATA_TUNNEL_ID) != 0 &&
1827 [ # # ]: 0 : mlx5_restore_info_dynflag == 0)
1828 : 0 : mlx5_restore_info_dynflag = rte_flow_restore_info_dynflag();
1829 : : }
1830 : :
1831 [ # # ]: 0 : if (((*features & supported) & RTE_ETH_RX_METADATA_TUNNEL_ID) != 0)
1832 : 0 : priv->tunnel_enabled = 1;
1833 : : else
1834 : 0 : priv->tunnel_enabled = 0;
1835 : :
1836 : 0 : *features &= supported;
1837 : 0 : return 0;
1838 : : }
1839 : :
1840 : : /**
1841 : : * Set the Rx queue dynamic metadata (mask and offset) for a flow
1842 : : *
1843 : : * @param[in] dev
1844 : : * Pointer to the Ethernet device structure.
1845 : : */
1846 : : void
1847 : 0 : mlx5_flow_rxq_dynf_set(struct rte_eth_dev *dev)
1848 : : {
1849 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1850 : : uint64_t mark_flag = RTE_MBUF_F_RX_FDIR_ID;
1851 : : unsigned int i;
1852 : :
1853 [ # # ]: 0 : if (priv->tunnel_enabled)
1854 : 0 : mark_flag |= mlx5_restore_info_dynflag;
1855 : :
1856 [ # # ]: 0 : for (i = 0; i != priv->rxqs_n; ++i) {
1857 : 0 : struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, i);
1858 : : struct mlx5_rxq_data *data;
1859 : :
1860 [ # # # # ]: 0 : if (rxq == NULL || rxq->ctrl == NULL)
1861 : 0 : continue;
1862 : : data = &rxq->ctrl->rxq;
1863 [ # # # # ]: 0 : if (!data->shared || !rxq->ctrl->started) {
1864 [ # # ]: 0 : if (!rte_flow_dynf_metadata_avail()) {
1865 : 0 : data->dynf_meta = 0;
1866 : 0 : data->flow_meta_mask = 0;
1867 : 0 : data->flow_meta_offset = -1;
1868 : 0 : data->flow_meta_port_mask = 0;
1869 : : } else {
1870 : 0 : data->dynf_meta = 1;
1871 : 0 : data->flow_meta_mask = rte_flow_dynf_metadata_mask;
1872 : 0 : data->flow_meta_offset = rte_flow_dynf_metadata_offs;
1873 : 0 : data->flow_meta_port_mask = priv->sh->dv_meta_mask;
1874 : : }
1875 : : }
1876 : 0 : data->mark_flag = mark_flag;
1877 : : }
1878 : 0 : }
1879 : :
1880 : : /*
1881 : : * return a pointer to the desired action in the list of actions.
1882 : : *
1883 : : * @param[in] actions
1884 : : * The list of actions to search the action in.
1885 : : * @param[in] action
1886 : : * The action to find.
1887 : : *
1888 : : * @return
1889 : : * Pointer to the action in the list, if found. NULL otherwise.
1890 : : */
1891 : : const struct rte_flow_action *
1892 : 0 : mlx5_flow_find_action(const struct rte_flow_action *actions,
1893 : : enum rte_flow_action_type action)
1894 : : {
1895 [ # # ]: 0 : if (actions == NULL)
1896 : : return NULL;
1897 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++)
1898 [ # # ]: 0 : if (actions->type == action)
1899 : 0 : return actions;
1900 : : return NULL;
1901 : : }
1902 : :
1903 : : /*
1904 : : * Validate the flag action.
1905 : : *
1906 : : * @param[in] action_flags
1907 : : * Bit-fields that holds the actions detected until now.
1908 : : * @param[in] attr
1909 : : * Attributes of flow that includes this action.
1910 : : * @param[out] error
1911 : : * Pointer to error structure.
1912 : : *
1913 : : * @return
1914 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1915 : : */
1916 : : int
1917 : 0 : mlx5_flow_validate_action_flag(uint64_t action_flags,
1918 : : const struct rte_flow_attr *attr,
1919 : : struct rte_flow_error *error)
1920 : : {
1921 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
1922 : 0 : return rte_flow_error_set(error, EINVAL,
1923 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1924 : : "can't mark and flag in same flow");
1925 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_FLAG)
1926 : 0 : return rte_flow_error_set(error, EINVAL,
1927 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1928 : : "can't have 2 flag"
1929 : : " actions in same flow");
1930 [ # # ]: 0 : if (attr->egress)
1931 : 0 : return rte_flow_error_set(error, ENOTSUP,
1932 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1933 : : "flag action not supported for "
1934 : : "egress");
1935 : : return 0;
1936 : : }
1937 : :
1938 : : /*
1939 : : * Validate the mark action.
1940 : : *
1941 : : * @param[in] action
1942 : : * Pointer to the queue action.
1943 : : * @param[in] action_flags
1944 : : * Bit-fields that holds the actions detected until now.
1945 : : * @param[in] attr
1946 : : * Attributes of flow that includes this action.
1947 : : * @param[out] error
1948 : : * Pointer to error structure.
1949 : : *
1950 : : * @return
1951 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1952 : : */
1953 : : int
1954 : 0 : mlx5_flow_validate_action_mark(__rte_unused struct rte_eth_dev *dev,
1955 : : const struct rte_flow_action *action,
1956 : : uint64_t action_flags,
1957 : : const struct rte_flow_attr *attr,
1958 : : struct rte_flow_error *error)
1959 : : {
1960 : 0 : const struct rte_flow_action_mark *mark = action->conf;
1961 : :
1962 [ # # ]: 0 : if (!mark)
1963 : 0 : return rte_flow_error_set(error, EINVAL,
1964 : : RTE_FLOW_ERROR_TYPE_ACTION,
1965 : : action,
1966 : : "configuration cannot be null");
1967 [ # # ]: 0 : if (mark->id >= MLX5_FLOW_MARK_MAX)
1968 : 0 : return rte_flow_error_set(error, EINVAL,
1969 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1970 : 0 : &mark->id,
1971 : : "mark id must in 0 <= id < "
1972 : : RTE_STR(MLX5_FLOW_MARK_MAX));
1973 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_FLAG)
1974 : 0 : return rte_flow_error_set(error, EINVAL,
1975 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1976 : : "can't flag and mark in same flow");
1977 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
1978 : 0 : return rte_flow_error_set(error, EINVAL,
1979 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1980 : : "can't have 2 mark actions in same"
1981 : : " flow");
1982 [ # # ]: 0 : if (attr->egress)
1983 : 0 : return rte_flow_error_set(error, ENOTSUP,
1984 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1985 : : "mark action not supported for "
1986 : : "egress");
1987 : : return 0;
1988 : : }
1989 : :
1990 : : /*
1991 : : * Validate the drop action.
1992 : : *
1993 : : * @param[in] dev
1994 : : * Pointer to the Ethernet device structure.
1995 : : * @param[in] is_root
1996 : : * True if flow is validated for root table. False otherwise.
1997 : : * @param[in] attr
1998 : : * Attributes of flow that includes this action.
1999 : : * @param[out] error
2000 : : * Pointer to error structure.
2001 : : *
2002 : : * @return
2003 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2004 : : */
2005 : : int
2006 : 0 : mlx5_flow_validate_action_drop(struct rte_eth_dev *dev,
2007 : : bool is_root,
2008 : : const struct rte_flow_attr *attr,
2009 : : struct rte_flow_error *error)
2010 : : {
2011 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2012 : :
2013 [ # # # # ]: 0 : if (priv->sh->config.dv_flow_en == 0 && attr->egress)
2014 : 0 : return rte_flow_error_set(error, ENOTSUP,
2015 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
2016 : : "drop action not supported for "
2017 : : "egress");
2018 [ # # # # : 0 : if (priv->sh->config.dv_flow_en == 1 && is_root && (attr->egress || attr->transfer) &&
# # ]
2019 [ # # ]: 0 : !priv->sh->dr_root_drop_action_en) {
2020 : 0 : return rte_flow_error_set(error, ENOTSUP,
2021 : : RTE_FLOW_ERROR_TYPE_ATTR, NULL,
2022 : : "drop action not supported for "
2023 : : "egress and transfer on group 0");
2024 : : }
2025 : : return 0;
2026 : : }
2027 : :
2028 : : /*
2029 : : * Check if a queue specified in the queue action is valid.
2030 : : *
2031 : : * @param[in] dev
2032 : : * Pointer to the Ethernet device structure.
2033 : : * @param[in] action
2034 : : * Pointer to the queue action.
2035 : : * @param[out] error
2036 : : * Pointer to error structure.
2037 : : *
2038 : : * @return
2039 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2040 : : */
2041 : : int
2042 : 0 : mlx5_flow_validate_target_queue(struct rte_eth_dev *dev,
2043 : : const struct rte_flow_action *action,
2044 : : struct rte_flow_error *error)
2045 : : {
2046 : 0 : const struct rte_flow_action_queue *queue = action->conf;
2047 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2048 : :
2049 [ # # # # ]: 0 : if (mlx5_is_external_rxq(dev, queue->index))
2050 : : return 0;
2051 [ # # ]: 0 : if (!priv->rxqs_n)
2052 : 0 : return rte_flow_error_set(error, EINVAL,
2053 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2054 : : NULL, "No Rx queues configured");
2055 [ # # ]: 0 : if (queue->index >= priv->rxqs_n)
2056 : 0 : return rte_flow_error_set(error, EINVAL,
2057 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2058 : 0 : &queue->index,
2059 : : "queue index out of range");
2060 [ # # ]: 0 : if (mlx5_rxq_get(dev, queue->index) == NULL)
2061 : 0 : return rte_flow_error_set(error, EINVAL,
2062 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2063 : 0 : &queue->index,
2064 : : "queue is not configured");
2065 : : return 0;
2066 : : }
2067 : :
2068 : : /*
2069 : : * Validate the queue action.
2070 : : *
2071 : : * @param[in] action
2072 : : * Pointer to the queue action.
2073 : : * @param[in] action_flags
2074 : : * Bit-fields that holds the actions detected until now.
2075 : : * @param[in] dev
2076 : : * Pointer to the Ethernet device structure.
2077 : : * @param[in] attr
2078 : : * Attributes of flow that includes this action.
2079 : : * @param[out] error
2080 : : * Pointer to error structure.
2081 : : *
2082 : : * @return
2083 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2084 : : */
2085 : : int
2086 : 0 : mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
2087 : : uint64_t action_flags,
2088 : : struct rte_eth_dev *dev,
2089 : : const struct rte_flow_attr *attr,
2090 : : struct rte_flow_error *error)
2091 : : {
2092 : 0 : const struct rte_flow_action_queue *queue = action->conf;
2093 : :
2094 [ # # ]: 0 : if (!queue)
2095 : 0 : return rte_flow_error_set(error, EINVAL,
2096 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
2097 : : "no QUEUE action configuration");
2098 [ # # ]: 0 : if (action_flags & MLX5_FLOW_FATE_ACTIONS)
2099 : 0 : return rte_flow_error_set(error, EINVAL,
2100 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2101 : : "can't have 2 fate actions in"
2102 : : " same flow");
2103 [ # # ]: 0 : if (attr->egress)
2104 : 0 : return rte_flow_error_set(error, ENOTSUP,
2105 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
2106 : : "queue action not supported for egress.");
2107 : 0 : return mlx5_flow_validate_target_queue(dev, action, error);
2108 : : }
2109 : :
2110 : : /**
2111 : : * Validate queue numbers for device RSS.
2112 : : *
2113 : : * @param[in] dev
2114 : : * Configured device.
2115 : : * @param[in] queues
2116 : : * Array of queue numbers.
2117 : : * @param[in] queues_n
2118 : : * Size of the @p queues array.
2119 : : * @param[out] error
2120 : : * On error, filled with a textual error description.
2121 : : * @param[out] queue_idx
2122 : : * On error, filled with an offending queue index in @p queues array.
2123 : : *
2124 : : * @return
2125 : : * 0 on success, a negative errno code on error.
2126 : : */
2127 : : static int
2128 : 0 : mlx5_validate_rss_queues(struct rte_eth_dev *dev,
2129 : : const uint16_t *queues, uint32_t queues_n,
2130 : : const char **error, uint32_t *queue_idx)
2131 : : {
2132 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
2133 : : bool is_hairpin = false;
2134 : : bool is_ext_rss = false;
2135 : : uint32_t i;
2136 : :
2137 [ # # ]: 0 : for (i = 0; i != queues_n; ++i) {
2138 : : struct mlx5_rxq_ctrl *rxq_ctrl;
2139 : :
2140 [ # # # # ]: 0 : if (mlx5_is_external_rxq(dev, queues[0])) {
2141 : : is_ext_rss = true;
2142 : 0 : continue;
2143 : : }
2144 [ # # ]: 0 : if (is_ext_rss) {
2145 : 0 : *error = "Combining external and regular RSS queues is not supported";
2146 : 0 : *queue_idx = i;
2147 : 0 : return -ENOTSUP;
2148 : : }
2149 [ # # ]: 0 : if (queues[i] >= priv->rxqs_n) {
2150 : 0 : *error = "queue index out of range";
2151 : 0 : *queue_idx = i;
2152 : 0 : return -EINVAL;
2153 : : }
2154 : 0 : rxq_ctrl = mlx5_rxq_ctrl_get(dev, queues[i]);
2155 [ # # ]: 0 : if (rxq_ctrl == NULL) {
2156 : 0 : *error = "queue is not configured";
2157 : 0 : *queue_idx = i;
2158 : 0 : return -EINVAL;
2159 : : }
2160 [ # # # # ]: 0 : if (i == 0 && rxq_ctrl->is_hairpin)
2161 : : is_hairpin = true;
2162 [ # # ]: 0 : if (is_hairpin != rxq_ctrl->is_hairpin) {
2163 : 0 : *error = "combining hairpin and regular RSS queues is not supported";
2164 : 0 : *queue_idx = i;
2165 : 0 : return -ENOTSUP;
2166 : : }
2167 : : }
2168 : : return 0;
2169 : : }
2170 : :
2171 : : /*
2172 : : * Validate the rss action.
2173 : : *
2174 : : * @param[in] dev
2175 : : * Pointer to the Ethernet device structure.
2176 : : * @param[in] action
2177 : : * Pointer to the queue action.
2178 : : * @param[out] error
2179 : : * Pointer to error structure.
2180 : : *
2181 : : * @return
2182 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2183 : : */
2184 : : int
2185 : 0 : mlx5_validate_action_rss(struct rte_eth_dev *dev,
2186 : : const struct rte_flow_action *action,
2187 : : struct rte_flow_error *error)
2188 : : {
2189 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2190 : 0 : const struct rte_flow_action_rss *rss = action->conf;
2191 : : int ret;
2192 : : const char *message;
2193 : : uint32_t queue_idx;
2194 : :
2195 [ # # ]: 0 : if (!rss)
2196 : 0 : return rte_flow_error_set
2197 : : (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
2198 : : action, "no RSS action configuration");
2199 [ # # ]: 0 : if (rss->func == RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ) {
2200 : 0 : DRV_LOG(WARNING, "port %u symmetric RSS supported with SORT",
2201 : : dev->data->port_id);
2202 [ # # ]: 0 : } else if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
2203 : : rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
2204 : 0 : return rte_flow_error_set(error, ENOTSUP,
2205 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2206 : 0 : &rss->func,
2207 : : "RSS hash function not supported");
2208 : : #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
2209 [ # # ]: 0 : if (rss->level > 2)
2210 : : #else
2211 : : if (rss->level > 1)
2212 : : #endif
2213 : 0 : return rte_flow_error_set(error, ENOTSUP,
2214 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2215 : 0 : &rss->level,
2216 : : "tunnel RSS is not supported");
2217 : : /* allow RSS key_len 0 in case of NULL (default) RSS key. */
2218 [ # # # # ]: 0 : if (rss->key_len == 0 && rss->key != NULL)
2219 : 0 : return rte_flow_error_set(error, ENOTSUP,
2220 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2221 : 0 : &rss->key_len,
2222 : : "RSS hash key length 0");
2223 [ # # ]: 0 : if (rss->key_len > 0 && rss->key_len < MLX5_RSS_HASH_KEY_LEN)
2224 : 0 : return rte_flow_error_set(error, ENOTSUP,
2225 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2226 : 0 : &rss->key_len,
2227 : : "RSS hash key too small");
2228 [ # # ]: 0 : if (rss->key_len > MLX5_RSS_HASH_KEY_LEN)
2229 : 0 : return rte_flow_error_set(error, ENOTSUP,
2230 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2231 : 0 : &rss->key_len,
2232 : : "RSS hash key too large");
2233 [ # # ]: 0 : if (rss->queue_num > priv->sh->dev_cap.ind_table_max_size)
2234 : 0 : return rte_flow_error_set(error, ENOTSUP,
2235 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2236 : 0 : &rss->queue_num,
2237 : : "number of queues too large");
2238 [ # # ]: 0 : if (rss->types & MLX5_RSS_HF_MASK)
2239 : 0 : return rte_flow_error_set(error, ENOTSUP,
2240 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2241 : 0 : &rss->types,
2242 : : "some RSS protocols are not"
2243 : : " supported");
2244 [ # # ]: 0 : if ((rss->types & (RTE_ETH_RSS_L3_SRC_ONLY | RTE_ETH_RSS_L3_DST_ONLY)) &&
2245 [ # # ]: 0 : !(rss->types & RTE_ETH_RSS_IP))
2246 : 0 : return rte_flow_error_set(error, EINVAL,
2247 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
2248 : : "L3 partial RSS requested but L3 RSS"
2249 : : " type not specified");
2250 [ # # ]: 0 : if ((rss->types & (RTE_ETH_RSS_L4_SRC_ONLY | RTE_ETH_RSS_L4_DST_ONLY)) &&
2251 [ # # ]: 0 : !(rss->types & (RTE_ETH_RSS_UDP | RTE_ETH_RSS_TCP)))
2252 : 0 : return rte_flow_error_set(error, EINVAL,
2253 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
2254 : : "L4 partial RSS requested but L4 RSS"
2255 : : " type not specified");
2256 [ # # # # ]: 0 : if (!priv->rxqs_n && priv->ext_rxqs == NULL)
2257 : 0 : return rte_flow_error_set(error, EINVAL,
2258 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2259 : : NULL, "No Rx queues configured");
2260 [ # # ]: 0 : if (!rss->queue_num)
2261 : 0 : return rte_flow_error_set(error, EINVAL,
2262 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2263 : : NULL, "No queues configured");
2264 : 0 : ret = mlx5_validate_rss_queues(dev, rss->queue, rss->queue_num,
2265 : : &message, &queue_idx);
2266 [ # # ]: 0 : if (ret != 0) {
2267 : 0 : return rte_flow_error_set(error, -ret,
2268 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2269 : 0 : &rss->queue[queue_idx], message);
2270 : : }
2271 : : return 0;
2272 : : }
2273 : :
2274 : : /*
2275 : : * Validate the rss action.
2276 : : *
2277 : : * @param[in] action
2278 : : * Pointer to the queue action.
2279 : : * @param[in] action_flags
2280 : : * Bit-fields that holds the actions detected until now.
2281 : : * @param[in] dev
2282 : : * Pointer to the Ethernet device structure.
2283 : : * @param[in] attr
2284 : : * Attributes of flow that includes this action.
2285 : : * @param[in] item_flags
2286 : : * Items that were detected.
2287 : : * @param[out] error
2288 : : * Pointer to error structure.
2289 : : *
2290 : : * @return
2291 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2292 : : */
2293 : : int
2294 : 0 : mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
2295 : : uint64_t action_flags,
2296 : : struct rte_eth_dev *dev,
2297 : : const struct rte_flow_attr *attr,
2298 : : uint64_t item_flags,
2299 : : struct rte_flow_error *error)
2300 : : {
2301 : 0 : const struct rte_flow_action_rss *rss = action->conf;
2302 : 0 : int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2303 : : int ret;
2304 : :
2305 [ # # ]: 0 : if (action_flags & MLX5_FLOW_FATE_ACTIONS)
2306 : 0 : return rte_flow_error_set(error, EINVAL,
2307 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2308 : : "can't have 2 fate actions"
2309 : : " in same flow");
2310 : 0 : ret = mlx5_validate_action_rss(dev, action, error);
2311 [ # # ]: 0 : if (ret)
2312 : : return ret;
2313 [ # # ]: 0 : if (attr->egress)
2314 : 0 : return rte_flow_error_set(error, ENOTSUP,
2315 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
2316 : : "rss action not supported for "
2317 : : "egress");
2318 [ # # # # ]: 0 : if (rss->level > 1 && !tunnel)
2319 : 0 : return rte_flow_error_set(error, EINVAL,
2320 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
2321 : : "inner RSS is not supported for "
2322 : : "non-tunnel flows");
2323 [ # # ]: 0 : if ((item_flags & MLX5_FLOW_LAYER_ECPRI) &&
2324 : : !(item_flags & MLX5_FLOW_LAYER_INNER_L4_UDP)) {
2325 : 0 : return rte_flow_error_set(error, EINVAL,
2326 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
2327 : : "RSS on eCPRI is not supported now");
2328 : : }
2329 [ # # ]: 0 : if ((item_flags & MLX5_FLOW_LAYER_MPLS) &&
2330 : : !(item_flags &
2331 [ # # ]: 0 : (MLX5_FLOW_LAYER_INNER_L2 | MLX5_FLOW_LAYER_INNER_L3)) &&
2332 : : rss->level > 1)
2333 : 0 : return rte_flow_error_set(error, EINVAL,
2334 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2335 : : "MPLS inner RSS needs to specify inner L2/L3 items after MPLS in pattern");
2336 : : return 0;
2337 : : }
2338 : :
2339 : : /*
2340 : : * Validate the default miss action.
2341 : : *
2342 : : * @param[in] action_flags
2343 : : * Bit-fields that holds the actions detected until now.
2344 : : * @param[out] error
2345 : : * Pointer to error structure.
2346 : : *
2347 : : * @return
2348 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2349 : : */
2350 : : int
2351 : 0 : mlx5_flow_validate_action_default_miss(uint64_t action_flags,
2352 : : const struct rte_flow_attr *attr,
2353 : : struct rte_flow_error *error)
2354 : : {
2355 [ # # ]: 0 : if (action_flags & MLX5_FLOW_FATE_ACTIONS)
2356 : 0 : return rte_flow_error_set(error, EINVAL,
2357 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2358 : : "can't have 2 fate actions in"
2359 : : " same flow");
2360 [ # # ]: 0 : if (attr->egress)
2361 : 0 : return rte_flow_error_set(error, ENOTSUP,
2362 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
2363 : : "default miss action not supported "
2364 : : "for egress");
2365 [ # # ]: 0 : if (attr->group)
2366 : 0 : return rte_flow_error_set(error, ENOTSUP,
2367 : : RTE_FLOW_ERROR_TYPE_ATTR_GROUP, NULL,
2368 : : "only group 0 is supported");
2369 [ # # ]: 0 : if (attr->transfer)
2370 : 0 : return rte_flow_error_set(error, ENOTSUP,
2371 : : RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
2372 : : NULL, "transfer is not supported");
2373 : : return 0;
2374 : : }
2375 : :
2376 : : /*
2377 : : * Validate the count action.
2378 : : *
2379 : : * @param[in] dev
2380 : : * Pointer to the Ethernet device structure.
2381 : : * @param[in] attr
2382 : : * Attributes of flow that includes this action.
2383 : : * @param[out] error
2384 : : * Pointer to error structure.
2385 : : *
2386 : : * @return
2387 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2388 : : */
2389 : : int
2390 : 0 : mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,
2391 : : const struct rte_flow_attr *attr,
2392 : : struct rte_flow_error *error)
2393 : : {
2394 [ # # ]: 0 : if (attr->egress)
2395 : 0 : return rte_flow_error_set(error, ENOTSUP,
2396 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
2397 : : "count action not supported for "
2398 : : "egress");
2399 : : return 0;
2400 : : }
2401 : :
2402 : : /*
2403 : : * Validate the ASO CT action.
2404 : : *
2405 : : * @param[in] dev
2406 : : * Pointer to the Ethernet device structure.
2407 : : * @param[in] conntrack
2408 : : * Pointer to the CT action profile.
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_validate_action_ct(struct rte_eth_dev *dev,
2417 : : const struct rte_flow_action_conntrack *conntrack,
2418 : : struct rte_flow_error *error)
2419 : : {
2420 : : RTE_SET_USED(dev);
2421 : :
2422 [ # # ]: 0 : if (conntrack->state > RTE_FLOW_CONNTRACK_STATE_TIME_WAIT)
2423 : 0 : return rte_flow_error_set(error, EINVAL,
2424 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2425 : : "Invalid CT state");
2426 [ # # ]: 0 : if (conntrack->last_index > RTE_FLOW_CONNTRACK_FLAG_RST)
2427 : 0 : return rte_flow_error_set(error, EINVAL,
2428 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2429 : : "Invalid last TCP packet flag");
2430 : : return 0;
2431 : : }
2432 : :
2433 : : /**
2434 : : * Validate the level value for modify field action.
2435 : : *
2436 : : * @param[in] data
2437 : : * Pointer to the rte_flow_field_data structure either src or dst.
2438 : : * @param[out] error
2439 : : * Pointer to error structure.
2440 : : *
2441 : : * @return
2442 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2443 : : */
2444 : : int
2445 : 0 : flow_validate_modify_field_level(const struct rte_flow_field_data *data,
2446 : : struct rte_flow_error *error)
2447 : : {
2448 [ # # # # ]: 0 : if (data->level == 0 || data->field == RTE_FLOW_FIELD_FLEX_ITEM)
2449 : : return 0;
2450 [ # # ]: 0 : if (data->field != RTE_FLOW_FIELD_TAG &&
2451 : : data->field != (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG) {
2452 [ # # ]: 0 : if (data->level > 1)
2453 : 0 : return rte_flow_error_set(error, ENOTSUP,
2454 : : RTE_FLOW_ERROR_TYPE_ACTION,
2455 : : NULL,
2456 : : "inner header fields modification is not supported");
2457 : : return 0;
2458 : : }
2459 [ # # ]: 0 : if (data->tag_index != 0)
2460 : 0 : return rte_flow_error_set(error, EINVAL,
2461 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2462 : : "tag array can be provided using 'level' or 'tag_index' fields, not both");
2463 : : /*
2464 : : * The tag array for RTE_FLOW_FIELD_TAG type is provided using
2465 : : * 'tag_index' field. In old API, it was provided using 'level' field
2466 : : * and it is still supported for backwards compatibility.
2467 : : */
2468 : 0 : DRV_LOG(DEBUG, "tag array provided in 'level' field instead of 'tag_index' field.");
2469 : 0 : return 0;
2470 : : }
2471 : :
2472 : : /**
2473 : : * Validate ICMP6 item.
2474 : : *
2475 : : * @param[in] item
2476 : : * Item specification.
2477 : : * @param[in] item_flags
2478 : : * Bit-fields that holds the items detected until now.
2479 : : * @param[in] ext_vlan_sup
2480 : : * Whether extended VLAN features are supported or not.
2481 : : * @param[out] error
2482 : : * Pointer to error structure.
2483 : : *
2484 : : * @return
2485 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2486 : : */
2487 : : int
2488 : 0 : mlx5_flow_validate_item_icmp6(const struct rte_eth_dev *dev,
2489 : : const struct rte_flow_item *item,
2490 : : uint64_t item_flags,
2491 : : uint8_t target_protocol,
2492 : : struct rte_flow_error *error)
2493 : : {
2494 : 0 : const struct rte_flow_item_icmp6 *mask = item->mask;
2495 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2496 [ # # ]: 0 : const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
2497 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6;
2498 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2499 : : MLX5_FLOW_LAYER_OUTER_L4;
2500 : : int ret;
2501 : :
2502 [ # # ]: 0 : if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMPV6)
2503 : 0 : return rte_flow_error_set(error, EINVAL,
2504 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2505 : : "protocol filtering not compatible"
2506 : : " with ICMP6 layer");
2507 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
2508 [ # # ]: 0 : if (!(item_flags & l3m))
2509 : 0 : return rte_flow_error_set(error, EINVAL,
2510 : : RTE_FLOW_ERROR_TYPE_ITEM,
2511 : : item, "IPv6 is mandatory to filter on ICMP6");
2512 : : }
2513 [ # # ]: 0 : if (item_flags & l4m)
2514 : 0 : return rte_flow_error_set(error, EINVAL,
2515 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2516 : : "multiple L4 layers not supported");
2517 [ # # ]: 0 : if (!mask)
2518 : : mask = &rte_flow_item_icmp6_mask;
2519 : 0 : ret = mlx5_flow_item_acceptable
2520 : : (dev, item, (const uint8_t *)mask,
2521 : : (const uint8_t *)&rte_flow_item_icmp6_mask,
2522 : : sizeof(struct rte_flow_item_icmp6),
2523 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2524 : : if (ret < 0)
2525 : : return ret;
2526 : : return 0;
2527 : : }
2528 : :
2529 : : /**
2530 : : * Validate ICMP6 echo request/reply item.
2531 : : *
2532 : : * @param[in] item
2533 : : * Item specification.
2534 : : * @param[in] item_flags
2535 : : * Bit-fields that holds the items detected until now.
2536 : : * @param[in] ext_vlan_sup
2537 : : * Whether extended VLAN features are supported or not.
2538 : : * @param[out] error
2539 : : * Pointer to error structure.
2540 : : *
2541 : : * @return
2542 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2543 : : */
2544 : : int
2545 : 0 : mlx5_flow_validate_item_icmp6_echo(const struct rte_eth_dev *dev,
2546 : : const struct rte_flow_item *item,
2547 : : uint64_t item_flags,
2548 : : uint8_t target_protocol,
2549 : : struct rte_flow_error *error)
2550 : : {
2551 : 0 : const struct rte_flow_item_icmp6_echo *mask = item->mask;
2552 : 0 : const struct rte_flow_item_icmp6_echo nic_mask = {
2553 : : .hdr.base.type = 0xff,
2554 : : .hdr.base.code = 0xff,
2555 : : .hdr.identifier = RTE_BE16(0xffff),
2556 : : .hdr.sequence = RTE_BE16(0xffff),
2557 : : };
2558 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2559 [ # # ]: 0 : const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
2560 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6;
2561 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2562 : : MLX5_FLOW_LAYER_OUTER_L4;
2563 : : int ret;
2564 : :
2565 [ # # ]: 0 : if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMPV6)
2566 : 0 : return rte_flow_error_set(error, EINVAL,
2567 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2568 : : "protocol filtering not compatible"
2569 : : " with ICMP6 layer");
2570 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
2571 [ # # ]: 0 : if (!(item_flags & l3m))
2572 : 0 : return rte_flow_error_set(error, EINVAL,
2573 : : RTE_FLOW_ERROR_TYPE_ITEM,
2574 : : item, "IPv6 is mandatory to filter on ICMP6");
2575 : : }
2576 [ # # ]: 0 : if (item_flags & l4m)
2577 : 0 : return rte_flow_error_set(error, EINVAL,
2578 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2579 : : "multiple L4 layers not supported");
2580 [ # # ]: 0 : if (!mask)
2581 : : mask = &nic_mask;
2582 : 0 : ret = mlx5_flow_item_acceptable
2583 : : (dev, item, (const uint8_t *)mask,
2584 : : (const uint8_t *)&nic_mask,
2585 : : sizeof(struct rte_flow_item_icmp6_echo),
2586 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2587 : : if (ret < 0)
2588 : : return ret;
2589 : : return 0;
2590 : : }
2591 : :
2592 : : /**
2593 : : * Validate ICMP item.
2594 : : *
2595 : : * @param[in] item
2596 : : * Item specification.
2597 : : * @param[in] item_flags
2598 : : * Bit-fields that holds the items detected until now.
2599 : : * @param[out] error
2600 : : * Pointer to error structure.
2601 : : *
2602 : : * @return
2603 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2604 : : */
2605 : : int
2606 : 0 : mlx5_flow_validate_item_icmp(const struct rte_eth_dev *dev,
2607 : : const struct rte_flow_item *item,
2608 : : uint64_t item_flags,
2609 : : uint8_t target_protocol,
2610 : : struct rte_flow_error *error)
2611 : : {
2612 : 0 : const struct rte_flow_item_icmp *mask = item->mask;
2613 : 0 : const struct rte_flow_item_icmp nic_mask = {
2614 : : .hdr.icmp_type = 0xff,
2615 : : .hdr.icmp_code = 0xff,
2616 : : .hdr.icmp_ident = RTE_BE16(0xffff),
2617 : : .hdr.icmp_seq_nb = RTE_BE16(0xffff),
2618 : : };
2619 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2620 [ # # ]: 0 : const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
2621 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4;
2622 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2623 : : MLX5_FLOW_LAYER_OUTER_L4;
2624 : : int ret;
2625 : :
2626 [ # # ]: 0 : if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMP)
2627 : 0 : return rte_flow_error_set(error, EINVAL,
2628 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2629 : : "protocol filtering not compatible"
2630 : : " with ICMP layer");
2631 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
2632 [ # # ]: 0 : if (!(item_flags & l3m))
2633 : 0 : return rte_flow_error_set(error, EINVAL,
2634 : : RTE_FLOW_ERROR_TYPE_ITEM,
2635 : : item, "IPv4 is mandatory to filter on ICMP");
2636 : : }
2637 [ # # ]: 0 : if (item_flags & l4m)
2638 : 0 : return rte_flow_error_set(error, EINVAL,
2639 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2640 : : "multiple L4 layers not supported");
2641 [ # # ]: 0 : if (!mask)
2642 : : mask = &nic_mask;
2643 : 0 : ret = mlx5_flow_item_acceptable
2644 : : (dev, item, (const uint8_t *)mask,
2645 : : (const uint8_t *)&nic_mask,
2646 : : sizeof(struct rte_flow_item_icmp),
2647 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2648 : : if (ret < 0)
2649 : : return ret;
2650 : : return 0;
2651 : : }
2652 : :
2653 : : /**
2654 : : * Validate Ethernet item.
2655 : : *
2656 : : * @param[in] item
2657 : : * Item specification.
2658 : : * @param[in] item_flags
2659 : : * Bit-fields that holds the items detected until now.
2660 : : * @param[out] error
2661 : : * Pointer to error structure.
2662 : : *
2663 : : * @return
2664 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2665 : : */
2666 : : int
2667 : 0 : mlx5_flow_validate_item_eth(const struct rte_eth_dev *dev,
2668 : : const struct rte_flow_item *item,
2669 : : uint64_t item_flags, bool ext_vlan_sup,
2670 : : struct rte_flow_error *error)
2671 : : {
2672 : 0 : const struct rte_flow_item_eth *mask = item->mask;
2673 : 0 : const struct rte_flow_item_eth nic_mask = {
2674 : : .hdr.dst_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
2675 : : .hdr.src_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
2676 : : .hdr.ether_type = RTE_BE16(0xffff),
2677 : : .has_vlan = ext_vlan_sup ? 1 : 0,
2678 : : };
2679 : : int ret;
2680 : 0 : int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2681 [ # # ]: 0 : const uint64_t ethm = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
2682 : : MLX5_FLOW_LAYER_OUTER_L2;
2683 : :
2684 [ # # ]: 0 : if (item_flags & ethm)
2685 : 0 : return rte_flow_error_set(error, ENOTSUP,
2686 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2687 : : "multiple L2 layers not supported");
2688 [ # # # # : 0 : if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_L3)) ||
# # ]
2689 [ # # ]: 0 : (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_L3)))
2690 : 0 : return rte_flow_error_set(error, EINVAL,
2691 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2692 : : "L2 layer should not follow "
2693 : : "L3 layers");
2694 [ # # # # : 0 : if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_VLAN)) ||
# # ]
2695 [ # # ]: 0 : (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_VLAN)))
2696 : 0 : return rte_flow_error_set(error, EINVAL,
2697 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2698 : : "L2 layer should not follow VLAN");
2699 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_GTP)
2700 : 0 : return rte_flow_error_set(error, EINVAL,
2701 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2702 : : "L2 layer should not follow GTP");
2703 [ # # ]: 0 : if (!mask)
2704 : : mask = &rte_flow_item_eth_mask;
2705 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2706 : : (const uint8_t *)&nic_mask,
2707 : : sizeof(struct rte_flow_item_eth),
2708 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2709 : 0 : return ret;
2710 : : }
2711 : :
2712 : : /**
2713 : : * Validate VLAN item.
2714 : : *
2715 : : * @param[in] item
2716 : : * Item specification.
2717 : : * @param[in] item_flags
2718 : : * Bit-fields that holds the items detected until now.
2719 : : * @param[in] dev
2720 : : * Ethernet device flow is being created on.
2721 : : * @param[out] error
2722 : : * Pointer to error structure.
2723 : : *
2724 : : * @return
2725 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2726 : : */
2727 : : int
2728 : 0 : mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
2729 : : uint64_t item_flags,
2730 : : struct rte_eth_dev *dev,
2731 : : struct rte_flow_error *error)
2732 : : {
2733 : 0 : const struct rte_flow_item_vlan *spec = item->spec;
2734 : 0 : const struct rte_flow_item_vlan *mask = item->mask;
2735 : 0 : const struct rte_flow_item_vlan nic_mask = {
2736 : : .hdr.vlan_tci = RTE_BE16(UINT16_MAX),
2737 : : .hdr.eth_proto = RTE_BE16(UINT16_MAX),
2738 : : };
2739 : : uint16_t vlan_tag = 0;
2740 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2741 : : int ret;
2742 : : const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
2743 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L4) :
2744 : : (MLX5_FLOW_LAYER_OUTER_L3 |
2745 : : MLX5_FLOW_LAYER_OUTER_L4);
2746 [ # # ]: 0 : const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
2747 : : MLX5_FLOW_LAYER_OUTER_VLAN;
2748 : :
2749 [ # # ]: 0 : if (item_flags & vlanm)
2750 : 0 : return rte_flow_error_set(error, EINVAL,
2751 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2752 : : "multiple VLAN layers not supported");
2753 [ # # ]: 0 : else if ((item_flags & l34m) != 0)
2754 : 0 : return rte_flow_error_set(error, EINVAL,
2755 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2756 : : "VLAN cannot follow L3/L4 layer");
2757 [ # # ]: 0 : if (!mask)
2758 : : mask = &rte_flow_item_vlan_mask;
2759 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2760 : : (const uint8_t *)&nic_mask,
2761 : : sizeof(struct rte_flow_item_vlan),
2762 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2763 [ # # ]: 0 : if (ret)
2764 : : return ret;
2765 [ # # # # ]: 0 : if (!tunnel && mask->hdr.vlan_tci != RTE_BE16(0x0fff)) {
2766 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2767 : :
2768 [ # # ]: 0 : if (priv->vmwa_context) {
2769 : : /*
2770 : : * Non-NULL context means we have a virtual machine
2771 : : * and SR-IOV enabled, we have to create VLAN interface
2772 : : * to make hypervisor to setup E-Switch vport
2773 : : * context correctly. We avoid creating the multiple
2774 : : * VLAN interfaces, so we cannot support VLAN tag mask.
2775 : : */
2776 : 0 : return rte_flow_error_set(error, EINVAL,
2777 : : RTE_FLOW_ERROR_TYPE_ITEM,
2778 : : item,
2779 : : "VLAN tag mask is not"
2780 : : " supported in virtual"
2781 : : " environment");
2782 : : }
2783 : : }
2784 [ # # ]: 0 : if (spec) {
2785 : 0 : vlan_tag = spec->hdr.vlan_tci;
2786 : 0 : vlan_tag &= mask->hdr.vlan_tci;
2787 : : }
2788 : : /*
2789 : : * From verbs perspective an empty VLAN is equivalent
2790 : : * to a packet without VLAN layer.
2791 : : */
2792 [ # # ]: 0 : if (!vlan_tag)
2793 : 0 : return rte_flow_error_set(error, EINVAL,
2794 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2795 : 0 : item->spec,
2796 : : "VLAN cannot be empty");
2797 : : return 0;
2798 : : }
2799 : :
2800 : : /**
2801 : : * Validate IPV4 item.
2802 : : *
2803 : : * @param[in] item
2804 : : * Item specification.
2805 : : * @param[in] item_flags
2806 : : * Bit-fields that holds the items detected until now.
2807 : : * @param[in] last_item
2808 : : * Previous validated item in the pattern items.
2809 : : * @param[in] ether_type
2810 : : * Type in the ethernet layer header (including dot1q).
2811 : : * @param[in] acc_mask
2812 : : * Acceptable mask, if NULL default internal default mask
2813 : : * will be used to check whether item fields are supported.
2814 : : * @param[in] range_accepted
2815 : : * True if range of values is accepted for specific fields, false otherwise.
2816 : : * @param[out] error
2817 : : * Pointer to error structure.
2818 : : *
2819 : : * @return
2820 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2821 : : */
2822 : : int
2823 : 0 : mlx5_flow_validate_item_ipv4(const struct rte_eth_dev *dev,
2824 : : const struct rte_flow_item *item,
2825 : : uint64_t item_flags,
2826 : : uint64_t last_item,
2827 : : uint16_t ether_type,
2828 : : const struct rte_flow_item_ipv4 *acc_mask,
2829 : : bool range_accepted,
2830 : : struct rte_flow_error *error)
2831 : : {
2832 : 0 : const struct rte_flow_item_ipv4 *mask = item->mask;
2833 : 0 : const struct rte_flow_item_ipv4 *spec = item->spec;
2834 : 0 : const struct rte_flow_item_ipv4 nic_mask = {
2835 : : .hdr = {
2836 : : .src_addr = RTE_BE32(0xffffffff),
2837 : : .dst_addr = RTE_BE32(0xffffffff),
2838 : : .type_of_service = 0xff,
2839 : : .next_proto_id = 0xff,
2840 : : },
2841 : : };
2842 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2843 [ # # ]: 0 : const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2844 : : MLX5_FLOW_LAYER_OUTER_L3;
2845 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2846 : : MLX5_FLOW_LAYER_OUTER_L4;
2847 : : int ret;
2848 : : uint8_t next_proto = 0xFF;
2849 : : const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2850 : : MLX5_FLOW_LAYER_OUTER_VLAN |
2851 : : MLX5_FLOW_LAYER_INNER_VLAN);
2852 : :
2853 [ # # ]: 0 : if ((last_item & l2_vlan) && ether_type &&
2854 [ # # ]: 0 : ether_type != RTE_ETHER_TYPE_IPV4)
2855 : 0 : return rte_flow_error_set(error, EINVAL,
2856 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2857 : : "IPv4 cannot follow L2/VLAN layer "
2858 : : "which ether type is not IPv4");
2859 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_IPIP) {
2860 [ # # ]: 0 : if (mask && spec)
2861 : 0 : next_proto = mask->hdr.next_proto_id &
2862 : 0 : spec->hdr.next_proto_id;
2863 [ # # ]: 0 : if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2864 : 0 : return rte_flow_error_set(error, EINVAL,
2865 : : RTE_FLOW_ERROR_TYPE_ITEM,
2866 : : item,
2867 : : "multiple tunnel "
2868 : : "not supported");
2869 : : }
2870 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP)
2871 : 0 : return rte_flow_error_set(error, EINVAL,
2872 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2873 : : "wrong tunnel type - IPv6 specified "
2874 : : "but IPv4 item provided");
2875 [ # # ]: 0 : if (item_flags & l3m)
2876 : 0 : return rte_flow_error_set(error, ENOTSUP,
2877 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2878 : : "multiple L3 layers not supported");
2879 [ # # ]: 0 : else if (item_flags & l4m)
2880 : 0 : return rte_flow_error_set(error, EINVAL,
2881 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2882 : : "L3 cannot follow an L4 layer.");
2883 [ # # ]: 0 : else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2884 : : !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2885 : 0 : return rte_flow_error_set(error, EINVAL,
2886 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2887 : : "L3 cannot follow an NVGRE layer.");
2888 [ # # ]: 0 : if (!mask)
2889 : : mask = &rte_flow_item_ipv4_mask;
2890 [ # # ]: 0 : else if (mask->hdr.next_proto_id != 0 &&
2891 : : mask->hdr.next_proto_id != 0xff)
2892 : 0 : return rte_flow_error_set(error, EINVAL,
2893 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2894 : : "partial mask is not supported"
2895 : : " for protocol");
2896 [ # # ]: 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2897 : : acc_mask ? (const uint8_t *)acc_mask
2898 : : : (const uint8_t *)&nic_mask,
2899 : : sizeof(struct rte_flow_item_ipv4),
2900 : : range_accepted, error);
2901 : : if (ret < 0)
2902 : : return ret;
2903 : : return 0;
2904 : : }
2905 : :
2906 : : /**
2907 : : * Validate IPV6 item.
2908 : : *
2909 : : * @param[in] item
2910 : : * Item specification.
2911 : : * @param[in] item_flags
2912 : : * Bit-fields that holds the items detected until now.
2913 : : * @param[in] last_item
2914 : : * Previous validated item in the pattern items.
2915 : : * @param[in] ether_type
2916 : : * Type in the ethernet layer header (including dot1q).
2917 : : * @param[in] acc_mask
2918 : : * Acceptable mask, if NULL default internal default mask
2919 : : * will be used to check whether item fields are supported.
2920 : : * @param[out] error
2921 : : * Pointer to error structure.
2922 : : *
2923 : : * @return
2924 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2925 : : */
2926 : : int
2927 : 0 : mlx5_flow_validate_item_ipv6(const struct rte_eth_dev *dev,
2928 : : const struct rte_flow_item *item,
2929 : : uint64_t item_flags,
2930 : : uint64_t last_item,
2931 : : uint16_t ether_type,
2932 : : const struct rte_flow_item_ipv6 *acc_mask,
2933 : : struct rte_flow_error *error)
2934 : : {
2935 : 0 : const struct rte_flow_item_ipv6 *mask = item->mask;
2936 : 0 : const struct rte_flow_item_ipv6 *spec = item->spec;
2937 : 0 : const struct rte_flow_item_ipv6 nic_mask = {
2938 : : .hdr = {
2939 : : .src_addr = RTE_IPV6_MASK_FULL,
2940 : : .dst_addr = RTE_IPV6_MASK_FULL,
2941 : : .vtc_flow = RTE_BE32(0xffffffff),
2942 : : .proto = 0xff,
2943 : : },
2944 : : };
2945 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2946 [ # # ]: 0 : const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2947 : : MLX5_FLOW_LAYER_OUTER_L3;
2948 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2949 : : MLX5_FLOW_LAYER_OUTER_L4;
2950 : : int ret;
2951 : : uint8_t next_proto = 0xFF;
2952 : : const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2953 : : MLX5_FLOW_LAYER_OUTER_VLAN |
2954 : : MLX5_FLOW_LAYER_INNER_VLAN);
2955 : :
2956 [ # # ]: 0 : if ((last_item & l2_vlan) && ether_type &&
2957 [ # # ]: 0 : ether_type != RTE_ETHER_TYPE_IPV6)
2958 : 0 : return rte_flow_error_set(error, EINVAL,
2959 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2960 : : "IPv6 cannot follow L2/VLAN layer "
2961 : : "which ether type is not IPv6");
2962 [ # # # # : 0 : if (mask && mask->hdr.proto == UINT8_MAX && spec)
# # ]
2963 : 0 : next_proto = spec->hdr.proto;
2964 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_IPIP) {
2965 [ # # ]: 0 : if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2966 : 0 : return rte_flow_error_set(error, EINVAL,
2967 : : RTE_FLOW_ERROR_TYPE_ITEM,
2968 : : item,
2969 : : "multiple tunnel "
2970 : : "not supported");
2971 : : }
2972 : 0 : if (next_proto == IPPROTO_HOPOPTS ||
2973 [ # # ]: 0 : next_proto == IPPROTO_ROUTING ||
2974 : : next_proto == IPPROTO_FRAGMENT ||
2975 : : next_proto == IPPROTO_AH ||
2976 [ # # ]: 0 : next_proto == IPPROTO_DSTOPTS ||
2977 [ # # ]: 0 : (!mlx5_hws_active(dev) && next_proto == IPPROTO_ESP))
2978 : 0 : return rte_flow_error_set(error, EINVAL,
2979 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2980 : : "IPv6 proto (next header) should "
2981 : : "not be set as extension header");
2982 [ # # ]: 0 : if (item_flags & l3m)
2983 : 0 : return rte_flow_error_set(error, ENOTSUP,
2984 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2985 : : "multiple L3 layers not supported");
2986 [ # # ]: 0 : else if (item_flags & l4m)
2987 : 0 : return rte_flow_error_set(error, EINVAL,
2988 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2989 : : "L3 cannot follow an L4 layer.");
2990 [ # # ]: 0 : else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2991 : : !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2992 : 0 : return rte_flow_error_set(error, EINVAL,
2993 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2994 : : "L3 cannot follow an NVGRE layer.");
2995 [ # # ]: 0 : if (!mask)
2996 : : mask = &rte_flow_item_ipv6_mask;
2997 [ # # ]: 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2998 : : acc_mask ? (const uint8_t *)acc_mask
2999 : : : (const uint8_t *)&nic_mask,
3000 : : sizeof(struct rte_flow_item_ipv6),
3001 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3002 : : if (ret < 0)
3003 : : return ret;
3004 : : return 0;
3005 : : }
3006 : :
3007 : : /**
3008 : : * Validate UDP item.
3009 : : *
3010 : : * @param[in] item
3011 : : * Item specification.
3012 : : * @param[in] item_flags
3013 : : * Bit-fields that holds the items detected until now.
3014 : : * @param[in] target_protocol
3015 : : * The next protocol in the previous item.
3016 : : * @param[in] flow_mask
3017 : : * mlx5 flow-specific (DV, verbs, etc.) supported header fields mask.
3018 : : * @param[out] error
3019 : : * Pointer to error structure.
3020 : : *
3021 : : * @return
3022 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3023 : : */
3024 : : int
3025 : 0 : mlx5_flow_validate_item_udp(const struct rte_eth_dev *dev,
3026 : : const struct rte_flow_item *item,
3027 : : uint64_t item_flags,
3028 : : uint8_t target_protocol,
3029 : : struct rte_flow_error *error)
3030 : : {
3031 : 0 : const struct rte_flow_item_udp *mask = item->mask;
3032 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
3033 [ # # ]: 0 : const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
3034 : : MLX5_FLOW_LAYER_OUTER_L3;
3035 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
3036 : : MLX5_FLOW_LAYER_OUTER_L4;
3037 : : int ret;
3038 : :
3039 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
3040 [ # # ]: 0 : if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
3041 : 0 : return rte_flow_error_set(error, EINVAL,
3042 : : RTE_FLOW_ERROR_TYPE_ITEM,
3043 : : item, "protocol filtering not compatible with UDP layer");
3044 [ # # ]: 0 : if (!(item_flags & l3m))
3045 : 0 : return rte_flow_error_set(error, EINVAL,
3046 : : RTE_FLOW_ERROR_TYPE_ITEM,
3047 : : item,
3048 : : "L3 is mandatory to filter on L4");
3049 : : }
3050 [ # # ]: 0 : if (item_flags & l4m)
3051 : 0 : return rte_flow_error_set(error, EINVAL,
3052 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3053 : : "multiple L4 layers not supported");
3054 [ # # ]: 0 : if (!mask)
3055 : : mask = &rte_flow_item_udp_mask;
3056 : 0 : ret = mlx5_flow_item_acceptable
3057 : : (dev, item, (const uint8_t *)mask,
3058 : : (const uint8_t *)&rte_flow_item_udp_mask,
3059 : : sizeof(struct rte_flow_item_udp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
3060 : : error);
3061 : : if (ret < 0)
3062 : : return ret;
3063 : : return 0;
3064 : : }
3065 : :
3066 : : /**
3067 : : * Validate TCP item.
3068 : : *
3069 : : * @param[in] item
3070 : : * Item specification.
3071 : : * @param[in] item_flags
3072 : : * Bit-fields that holds the items detected until now.
3073 : : * @param[in] target_protocol
3074 : : * The next protocol in the previous item.
3075 : : * @param[out] error
3076 : : * Pointer to error structure.
3077 : : *
3078 : : * @return
3079 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3080 : : */
3081 : : int
3082 : 0 : mlx5_flow_validate_item_tcp(const struct rte_eth_dev *dev,
3083 : : const struct rte_flow_item *item,
3084 : : uint64_t item_flags,
3085 : : uint8_t target_protocol,
3086 : : const struct rte_flow_item_tcp *flow_mask,
3087 : : struct rte_flow_error *error)
3088 : : {
3089 : 0 : const struct rte_flow_item_tcp *mask = item->mask;
3090 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
3091 [ # # ]: 0 : const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
3092 : : MLX5_FLOW_LAYER_OUTER_L3;
3093 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
3094 : : MLX5_FLOW_LAYER_OUTER_L4;
3095 : : int ret;
3096 : :
3097 : : MLX5_ASSERT(flow_mask);
3098 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
3099 [ # # ]: 0 : if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
3100 : 0 : return rte_flow_error_set(error, EINVAL,
3101 : : RTE_FLOW_ERROR_TYPE_ITEM,
3102 : : item, "protocol filtering not compatible with TCP layer");
3103 [ # # ]: 0 : if (!(item_flags & l3m))
3104 : 0 : return rte_flow_error_set(error, EINVAL,
3105 : : RTE_FLOW_ERROR_TYPE_ITEM,
3106 : : item, "L3 is mandatory to filter on L4");
3107 : : }
3108 [ # # ]: 0 : if (item_flags & l4m)
3109 : 0 : return rte_flow_error_set(error, EINVAL,
3110 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3111 : : "multiple L4 layers not supported");
3112 [ # # ]: 0 : if (!mask)
3113 : : mask = &rte_flow_item_tcp_mask;
3114 : 0 : ret = mlx5_flow_item_acceptable
3115 : : (dev, item, (const uint8_t *)mask,
3116 : : (const uint8_t *)flow_mask,
3117 : : sizeof(struct rte_flow_item_tcp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
3118 : : error);
3119 : : if (ret < 0)
3120 : : return ret;
3121 : : return 0;
3122 : : }
3123 : :
3124 : : /**
3125 : : * Validate VXLAN item.
3126 : : *
3127 : : * @param[in] dev
3128 : : * Pointer to the Ethernet device structure.
3129 : : * @param[in] udp_dport
3130 : : * UDP destination port
3131 : : * @param[in] item
3132 : : * Item specification.
3133 : : * @param[in] item_flags
3134 : : * Bit-fields that holds the items detected until now.
3135 : : * @param root
3136 : : * Whether action is on root table.
3137 : : * @param[out] error
3138 : : * Pointer to error structure.
3139 : : *
3140 : : * @return
3141 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3142 : : */
3143 : : int
3144 : 0 : mlx5_flow_validate_item_vxlan(struct rte_eth_dev *dev,
3145 : : uint16_t udp_dport,
3146 : : const struct rte_flow_item *item,
3147 : : uint64_t item_flags,
3148 : : bool root,
3149 : : struct rte_flow_error *error)
3150 : : {
3151 : 0 : const struct rte_flow_item_vxlan *spec = item->spec;
3152 : 0 : const struct rte_flow_item_vxlan *mask = item->mask;
3153 : : int ret;
3154 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3155 : : union vni {
3156 : : uint32_t vlan_id;
3157 : : uint8_t vni[4];
3158 : 0 : } id = { .vlan_id = 0, };
3159 : 0 : const struct rte_flow_item_vxlan nic_mask = {
3160 : : .hdr.vni = { 0xff, 0xff, 0xff },
3161 : : .hdr.rsvd1 = 0xff,
3162 : : };
3163 : : const struct rte_flow_item_vxlan *valid_mask;
3164 : :
3165 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3166 : 0 : return rte_flow_error_set(error, ENOTSUP,
3167 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3168 : : "multiple tunnel layers not"
3169 : : " supported");
3170 : : /* HWS can match entire VXLAN, VXLAN-GBP and VXLAN-GPE headers */
3171 [ # # ]: 0 : if (mlx5_hws_active(dev))
3172 : : return 0;
3173 : : valid_mask = &rte_flow_item_vxlan_mask;
3174 : : /*
3175 : : * Verify only UDPv4 is present as defined in
3176 : : * https://tools.ietf.org/html/rfc7348
3177 : : */
3178 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
3179 : 0 : return rte_flow_error_set(error, EINVAL,
3180 : : RTE_FLOW_ERROR_TYPE_ITEM,
3181 : : item, "no outer UDP layer found");
3182 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
3183 : 0 : return rte_flow_error_set(error, ENOTSUP,
3184 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3185 : : "VXLAN tunnel must be fully defined");
3186 [ # # ]: 0 : if (!mask)
3187 : : mask = &rte_flow_item_vxlan_mask;
3188 : :
3189 [ # # ]: 0 : if (priv->sh->steering_format_version !=
3190 : : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5 ||
3191 [ # # ]: 0 : !udp_dport || udp_dport == MLX5_UDP_PORT_VXLAN) {
3192 : : /* non-root table */
3193 [ # # # # ]: 0 : if (!root && priv->sh->misc5_cap)
3194 : : valid_mask = &nic_mask;
3195 : : /* Group zero in NIC domain */
3196 [ # # # # ]: 0 : if (!root && priv->sh->tunnel_header_0_1)
3197 : : valid_mask = &nic_mask;
3198 : : }
3199 : 0 : ret = mlx5_flow_item_acceptable
3200 : : (dev, item, (const uint8_t *)mask,
3201 : : (const uint8_t *)valid_mask,
3202 : : sizeof(struct rte_flow_item_vxlan),
3203 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3204 : : if (ret < 0)
3205 : : return ret;
3206 : : if (spec) {
3207 : : memcpy(&id.vni[1], spec->hdr.vni, 3);
3208 : : memcpy(&id.vni[1], mask->hdr.vni, 3);
3209 : : }
3210 : : return 0;
3211 : : }
3212 : :
3213 : : /**
3214 : : * Validate VXLAN_GPE item.
3215 : : *
3216 : : * @param[in] item
3217 : : * Item specification.
3218 : : * @param[in] item_flags
3219 : : * Bit-fields that holds the items detected until now.
3220 : : * @param[in] priv
3221 : : * Pointer to the private data structure.
3222 : : * @param[in] target_protocol
3223 : : * The next protocol in the previous item.
3224 : : * @param[out] error
3225 : : * Pointer to error structure.
3226 : : *
3227 : : * @return
3228 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3229 : : */
3230 : : int
3231 : 0 : mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
3232 : : uint64_t item_flags,
3233 : : struct rte_eth_dev *dev,
3234 : : struct rte_flow_error *error)
3235 : : {
3236 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3237 : : const struct rte_flow_item_vxlan_gpe *spec = item->spec;
3238 : 0 : const struct rte_flow_item_vxlan_gpe *mask = item->mask;
3239 : : int ret;
3240 : : union vni {
3241 : : uint32_t vlan_id;
3242 : : uint8_t vni[4];
3243 : 0 : } id = { .vlan_id = 0, };
3244 : :
3245 : 0 : struct rte_flow_item_vxlan_gpe nic_mask = {
3246 : : .vni = { 0xff, 0xff, 0xff },
3247 : : .protocol = 0xff,
3248 : : .flags = 0xff,
3249 : : };
3250 : :
3251 [ # # ]: 0 : if (!priv->sh->config.l3_vxlan_en)
3252 : 0 : return rte_flow_error_set(error, ENOTSUP,
3253 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3254 : : "L3 VXLAN is not enabled by device"
3255 : : " parameter and/or not configured in"
3256 : : " firmware");
3257 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3258 : 0 : return rte_flow_error_set(error, ENOTSUP,
3259 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3260 : : "multiple tunnel layers not"
3261 : : " supported");
3262 : : /*
3263 : : * Verify only UDPv4 is present as defined in
3264 : : * https://tools.ietf.org/html/rfc7348
3265 : : */
3266 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
3267 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
3268 : 0 : return rte_flow_error_set(error, EINVAL,
3269 : : RTE_FLOW_ERROR_TYPE_ITEM,
3270 : : item, "no outer UDP layer found");
3271 : : }
3272 [ # # ]: 0 : if (!mask)
3273 : : mask = &rte_flow_item_vxlan_gpe_mask;
3274 [ # # ]: 0 : if (mlx5_hws_active(dev) ||
3275 [ # # ]: 0 : (priv->sh->misc5_cap && priv->sh->tunnel_header_0_1)) {
3276 : 0 : nic_mask.rsvd0[0] = 0xff;
3277 : 0 : nic_mask.rsvd0[1] = 0xff;
3278 : 0 : nic_mask.rsvd1 = 0xff;
3279 : : }
3280 : 0 : ret = mlx5_flow_item_acceptable
3281 : : (dev, item, (const uint8_t *)mask,
3282 : : (const uint8_t *)&nic_mask,
3283 : : sizeof(struct rte_flow_item_vxlan_gpe),
3284 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3285 [ # # ]: 0 : if (ret < 0)
3286 : : return ret;
3287 : : if (spec) {
3288 : : memcpy(&id.vni[1], spec->hdr.vni, 3);
3289 : : memcpy(&id.vni[1], mask->hdr.vni, 3);
3290 : : }
3291 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
3292 : 0 : return rte_flow_error_set(error, ENOTSUP,
3293 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3294 : : "VXLAN-GPE tunnel must be fully"
3295 : : " defined");
3296 : : return 0;
3297 : : }
3298 : : /**
3299 : : * Validate GRE Key item.
3300 : : *
3301 : : * @param[in] item
3302 : : * Item specification.
3303 : : * @param[in] item_flags
3304 : : * Bit flags to mark detected items.
3305 : : * @param[in] gre_item
3306 : : * Pointer to gre_item
3307 : : * @param[out] error
3308 : : * Pointer to error structure.
3309 : : *
3310 : : * @return
3311 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3312 : : */
3313 : : int
3314 : 0 : mlx5_flow_validate_item_gre_key(const struct rte_eth_dev *dev,
3315 : : const struct rte_flow_item *item,
3316 : : uint64_t item_flags,
3317 : : const struct rte_flow_item *gre_item,
3318 : : struct rte_flow_error *error)
3319 : : {
3320 : 0 : const rte_be32_t *mask = item->mask;
3321 : : int ret = 0;
3322 : 0 : rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
3323 : : const struct rte_flow_item_gre *gre_spec;
3324 : : const struct rte_flow_item_gre *gre_mask;
3325 : :
3326 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_GRE_KEY)
3327 : 0 : return rte_flow_error_set(error, ENOTSUP,
3328 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3329 : : "Multiple GRE key not support");
3330 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_GRE))
3331 : 0 : return rte_flow_error_set(error, ENOTSUP,
3332 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3333 : : "No preceding GRE header");
3334 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_INNER)
3335 : 0 : return rte_flow_error_set(error, ENOTSUP,
3336 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3337 : : "GRE key following a wrong item");
3338 [ # # ]: 0 : gre_mask = gre_item ? gre_item->mask : NULL;
3339 [ # # ]: 0 : if (!gre_mask)
3340 : : gre_mask = &rte_flow_item_gre_mask;
3341 [ # # ]: 0 : gre_spec = gre_item ? gre_item->spec : NULL;
3342 [ # # # # ]: 0 : if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
3343 [ # # ]: 0 : !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
3344 : 0 : return rte_flow_error_set(error, EINVAL,
3345 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3346 : : "Key bit must be on");
3347 : :
3348 [ # # ]: 0 : if (!mask)
3349 : : mask = &gre_key_default_mask;
3350 : 0 : ret = mlx5_flow_item_acceptable
3351 : : (dev, item, (const uint8_t *)mask,
3352 : : (const uint8_t *)&gre_key_default_mask,
3353 : : sizeof(rte_be32_t), MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3354 : 0 : return ret;
3355 : : }
3356 : :
3357 : : /**
3358 : : * Validate GRE optional item.
3359 : : *
3360 : : * @param[in] dev
3361 : : * Pointer to the Ethernet device structure.
3362 : : * @param[in] item
3363 : : * Item specification.
3364 : : * @param[in] item_flags
3365 : : * Bit flags to mark detected items.
3366 : : * @param[in] attr
3367 : : * Flow rule attributes.
3368 : : * @param[in] gre_item
3369 : : * Pointer to gre_item
3370 : : * @param[out] error
3371 : : * Pointer to error structure.
3372 : : *
3373 : : * @return
3374 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3375 : : */
3376 : : int
3377 : 0 : mlx5_flow_validate_item_gre_option(struct rte_eth_dev *dev,
3378 : : const struct rte_flow_item *item,
3379 : : uint64_t item_flags,
3380 : : const struct rte_flow_attr *attr,
3381 : : const struct rte_flow_item *gre_item,
3382 : : struct rte_flow_error *error)
3383 : : {
3384 [ # # ]: 0 : const struct rte_flow_item_gre *gre_spec = gre_item ? gre_item->spec : NULL;
3385 [ # # ]: 0 : const struct rte_flow_item_gre *gre_mask = gre_item ? gre_item->mask : NULL;
3386 : 0 : const struct rte_flow_item_gre_opt *spec = item->spec;
3387 : 0 : const struct rte_flow_item_gre_opt *mask = item->mask;
3388 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3389 : : int ret = 0;
3390 : 0 : struct rte_flow_item_gre_opt nic_mask = {
3391 : : .checksum_rsvd = {
3392 : : .checksum = RTE_BE16(UINT16_MAX),
3393 : : .reserved1 = 0x0,
3394 : : },
3395 : : .key = {
3396 : : .key = RTE_BE32(UINT32_MAX),
3397 : : },
3398 : : .sequence = {
3399 : : .sequence = RTE_BE32(UINT32_MAX),
3400 : : },
3401 : : };
3402 : :
3403 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_GRE))
3404 : 0 : return rte_flow_error_set(error, ENOTSUP,
3405 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3406 : : "No preceding GRE header");
3407 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_INNER)
3408 : 0 : return rte_flow_error_set(error, ENOTSUP,
3409 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3410 : : "GRE option following a wrong item");
3411 [ # # # # : 0 : if ((!spec && !mlx5_hws_active(dev)) || !mask)
# # ]
3412 : 0 : return rte_flow_error_set(error, EINVAL,
3413 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3414 : : "At least one field gre_option(checksum/key/sequence) must be specified");
3415 [ # # ]: 0 : if (!gre_mask)
3416 : : gre_mask = &rte_flow_item_gre_mask;
3417 [ # # ]: 0 : if (mask->checksum_rsvd.checksum)
3418 [ # # # # ]: 0 : if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x8000)) &&
3419 [ # # ]: 0 : !(gre_spec->c_rsvd0_ver & RTE_BE16(0x8000)))
3420 : 0 : return rte_flow_error_set(error, EINVAL,
3421 : : RTE_FLOW_ERROR_TYPE_ITEM,
3422 : : item,
3423 : : "Checksum bit must be on");
3424 [ # # ]: 0 : if (mask->key.key)
3425 [ # # # # ]: 0 : if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
3426 [ # # ]: 0 : !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
3427 : 0 : return rte_flow_error_set(error, EINVAL,
3428 : : RTE_FLOW_ERROR_TYPE_ITEM,
3429 : : item, "Key bit must be on");
3430 [ # # ]: 0 : if (mask->sequence.sequence)
3431 [ # # # # ]: 0 : if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x1000)) &&
3432 [ # # ]: 0 : !(gre_spec->c_rsvd0_ver & RTE_BE16(0x1000)))
3433 : 0 : return rte_flow_error_set(error, EINVAL,
3434 : : RTE_FLOW_ERROR_TYPE_ITEM,
3435 : : item,
3436 : : "Sequence bit must be on");
3437 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
3438 [ # # # # ]: 0 : if (mask->checksum_rsvd.checksum || mask->sequence.sequence) {
3439 [ # # ]: 0 : if (priv->sh->steering_format_version ==
3440 : 0 : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5 ||
3441 [ # # ]: 0 : ((attr->group ||
3442 [ # # # # ]: 0 : (attr->transfer && priv->fdb_def_rule)) &&
3443 [ # # ]: 0 : !priv->sh->misc5_cap) ||
3444 [ # # ]: 0 : (!(priv->sh->tunnel_header_0_1 &&
3445 [ # # ]: 0 : priv->sh->tunnel_header_2_3) &&
3446 : 0 : !attr->group &&
3447 [ # # # # ]: 0 : (!attr->transfer || !priv->fdb_def_rule)))
3448 : 0 : return rte_flow_error_set
3449 : : (error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM,
3450 : : item, "Checksum/Sequence not supported");
3451 : : }
3452 : : }
3453 : 0 : ret = mlx5_flow_item_acceptable
3454 : : (dev, item, (const uint8_t *)mask,
3455 : : (const uint8_t *)&nic_mask,
3456 : : sizeof(struct rte_flow_item_gre_opt),
3457 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3458 : 0 : return ret;
3459 : : }
3460 : :
3461 : : /**
3462 : : * Validate GRE item.
3463 : : *
3464 : : * @param[in] item
3465 : : * Item specification.
3466 : : * @param[in] item_flags
3467 : : * Bit flags to mark detected items.
3468 : : * @param[in] target_protocol
3469 : : * The next protocol in the previous item.
3470 : : * @param[out] error
3471 : : * Pointer to error structure.
3472 : : *
3473 : : * @return
3474 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3475 : : */
3476 : : int
3477 : 0 : mlx5_flow_validate_item_gre(const struct rte_eth_dev *dev,
3478 : : const struct rte_flow_item *item,
3479 : : uint64_t item_flags,
3480 : : uint8_t target_protocol,
3481 : : struct rte_flow_error *error)
3482 : : {
3483 : : const struct rte_flow_item_gre *spec __rte_unused = item->spec;
3484 : 0 : const struct rte_flow_item_gre *mask = item->mask;
3485 : : int ret;
3486 : 0 : const struct rte_flow_item_gre nic_mask = {
3487 : : .c_rsvd0_ver = RTE_BE16(0xB000),
3488 : : .protocol = RTE_BE16(UINT16_MAX),
3489 : : };
3490 : :
3491 [ # # ]: 0 : if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
3492 : 0 : return rte_flow_error_set(error, EINVAL,
3493 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3494 : : "protocol filtering not compatible"
3495 : : " with this GRE layer");
3496 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3497 : 0 : return rte_flow_error_set(error, ENOTSUP,
3498 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3499 : : "multiple tunnel layers not"
3500 : : " supported");
3501 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
3502 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
3503 : 0 : return rte_flow_error_set(error, ENOTSUP,
3504 : : RTE_FLOW_ERROR_TYPE_ITEM,
3505 : : item, "L3 Layer is missing");
3506 : : }
3507 [ # # ]: 0 : if (!mask)
3508 : : mask = &rte_flow_item_gre_mask;
3509 : 0 : ret = mlx5_flow_item_acceptable
3510 : : (dev, item, (const uint8_t *)mask,
3511 : : (const uint8_t *)&nic_mask,
3512 : : sizeof(struct rte_flow_item_gre), MLX5_ITEM_RANGE_NOT_ACCEPTED,
3513 : : error);
3514 : : if (ret < 0)
3515 : : return ret;
3516 : : #ifndef HAVE_MLX5DV_DR
3517 : : #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
3518 : : if (spec && (spec->protocol & mask->protocol))
3519 : : return rte_flow_error_set(error, ENOTSUP,
3520 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3521 : : "without MPLS support the"
3522 : : " specification cannot be used for"
3523 : : " filtering");
3524 : : #endif
3525 : : #endif
3526 : : return 0;
3527 : : }
3528 : :
3529 : : /**
3530 : : * Validate Geneve item.
3531 : : *
3532 : : * @param[in] item
3533 : : * Item specification.
3534 : : * @param[in] itemFlags
3535 : : * Bit-fields that holds the items detected until now.
3536 : : * @param[in] enPriv
3537 : : * Pointer to the private data structure.
3538 : : * @param[out] error
3539 : : * Pointer to error structure.
3540 : : *
3541 : : * @return
3542 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3543 : : */
3544 : :
3545 : : int
3546 : 0 : mlx5_flow_validate_item_geneve(const struct rte_flow_item *item,
3547 : : uint64_t item_flags,
3548 : : struct rte_eth_dev *dev,
3549 : : struct rte_flow_error *error)
3550 : : {
3551 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3552 : 0 : const struct rte_flow_item_geneve *spec = item->spec;
3553 : 0 : const struct rte_flow_item_geneve *mask = item->mask;
3554 : : int ret;
3555 : : uint16_t gbhdr;
3556 [ # # ]: 0 : uint8_t opt_len = priv->sh->cdev->config.hca_attr.geneve_max_opt_len ?
3557 : : MLX5_GENEVE_OPT_LEN_1 : MLX5_GENEVE_OPT_LEN_0;
3558 : 0 : const struct rte_flow_item_geneve nic_mask = {
3559 : : .ver_opt_len_o_c_rsvd0 = RTE_BE16(0x3f80),
3560 : : .vni = { 0xff, 0xff, 0xff },
3561 : : .protocol = RTE_BE16(UINT16_MAX),
3562 : : };
3563 : :
3564 [ # # ]: 0 : if (!priv->sh->cdev->config.hca_attr.tunnel_stateless_geneve_rx)
3565 : 0 : return rte_flow_error_set(error, ENOTSUP,
3566 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3567 : : "L3 Geneve is not enabled by device"
3568 : : " parameter and/or not configured in"
3569 : : " firmware");
3570 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3571 : 0 : return rte_flow_error_set(error, ENOTSUP,
3572 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3573 : : "multiple tunnel layers not"
3574 : : " supported");
3575 : : /*
3576 : : * Verify only UDPv4 is present as defined in
3577 : : * https://tools.ietf.org/html/rfc7348
3578 : : */
3579 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
3580 : 0 : return rte_flow_error_set(error, EINVAL,
3581 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3582 : : "no outer UDP layer found");
3583 [ # # ]: 0 : if (!mask)
3584 : : mask = &rte_flow_item_geneve_mask;
3585 : 0 : ret = mlx5_flow_item_acceptable
3586 : : (dev, item, (const uint8_t *)mask,
3587 : : (const uint8_t *)&nic_mask,
3588 : : sizeof(struct rte_flow_item_geneve),
3589 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3590 [ # # ]: 0 : if (ret)
3591 : : return ret;
3592 [ # # ]: 0 : if (spec) {
3593 [ # # ]: 0 : gbhdr = rte_be_to_cpu_16(spec->ver_opt_len_o_c_rsvd0);
3594 [ # # ]: 0 : if (MLX5_GENEVE_VER_VAL(gbhdr) ||
3595 [ # # # # ]: 0 : MLX5_GENEVE_CRITO_VAL(gbhdr) ||
3596 [ # # ]: 0 : MLX5_GENEVE_RSVD_VAL(gbhdr) || spec->rsvd1)
3597 : 0 : return rte_flow_error_set(error, ENOTSUP,
3598 : : RTE_FLOW_ERROR_TYPE_ITEM,
3599 : : item,
3600 : : "Geneve protocol unsupported"
3601 : : " fields are being used");
3602 [ # # ]: 0 : if (MLX5_GENEVE_OPTLEN_VAL(gbhdr) > opt_len)
3603 : 0 : return rte_flow_error_set
3604 : : (error, ENOTSUP,
3605 : : RTE_FLOW_ERROR_TYPE_ITEM,
3606 : : item,
3607 : : "Unsupported Geneve options length");
3608 : : }
3609 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
3610 : 0 : return rte_flow_error_set
3611 : : (error, ENOTSUP,
3612 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3613 : : "Geneve tunnel must be fully defined");
3614 : : return 0;
3615 : : }
3616 : :
3617 : : /**
3618 : : * Validate Geneve TLV option item.
3619 : : *
3620 : : * @param[in] item
3621 : : * Item specification.
3622 : : * @param[in] last_item
3623 : : * Previous validated item in the pattern items.
3624 : : * @param[in] geneve_item
3625 : : * Previous GENEVE item specification.
3626 : : * @param[in] dev
3627 : : * Pointer to the rte_eth_dev structure.
3628 : : * @param[out] error
3629 : : * Pointer to error structure.
3630 : : *
3631 : : * @return
3632 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3633 : : */
3634 : : int
3635 : 0 : mlx5_flow_validate_item_geneve_opt(const struct rte_flow_item *item,
3636 : : uint64_t last_item,
3637 : : const struct rte_flow_item *geneve_item,
3638 : : struct rte_eth_dev *dev,
3639 : : struct rte_flow_error *error)
3640 : : {
3641 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3642 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
3643 : : struct mlx5_geneve_tlv_option_resource *geneve_opt_resource;
3644 : 0 : struct mlx5_hca_attr *hca_attr = &sh->cdev->config.hca_attr;
3645 : 0 : uint8_t data_max_supported =
3646 : 0 : hca_attr->max_geneve_tlv_option_data_len * 4;
3647 : : const struct rte_flow_item_geneve *geneve_spec;
3648 : : const struct rte_flow_item_geneve *geneve_mask;
3649 : 0 : const struct rte_flow_item_geneve_opt *spec = item->spec;
3650 : 0 : const struct rte_flow_item_geneve_opt *mask = item->mask;
3651 : : unsigned int i;
3652 : : unsigned int data_len;
3653 : : uint8_t tlv_option_len;
3654 : : uint16_t optlen_m, optlen_v;
3655 : : const struct rte_flow_item_geneve_opt full_mask = {
3656 : : .option_class = RTE_BE16(0xffff),
3657 : : .option_type = 0xff,
3658 : : .option_len = 0x1f,
3659 : : };
3660 : :
3661 [ # # ]: 0 : if (!mask)
3662 : : mask = &rte_flow_item_geneve_opt_mask;
3663 [ # # ]: 0 : if (!spec)
3664 : 0 : return rte_flow_error_set
3665 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3666 : : "Geneve TLV opt class/type/length must be specified");
3667 [ # # ]: 0 : if ((uint32_t)spec->option_len > MLX5_GENEVE_OPTLEN_MASK)
3668 : 0 : return rte_flow_error_set
3669 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3670 : : "Geneve TLV opt length exceeds the limit (31)");
3671 : : /* Check if class type and length masks are full. */
3672 [ # # ]: 0 : if (full_mask.option_class != mask->option_class ||
3673 : 0 : full_mask.option_type != mask->option_type ||
3674 [ # # ]: 0 : full_mask.option_len != (mask->option_len & full_mask.option_len))
3675 : 0 : return rte_flow_error_set
3676 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3677 : : "Geneve TLV opt class/type/length masks must be full");
3678 : : /* Check if length is supported */
3679 [ # # ]: 0 : if ((uint32_t)spec->option_len >
3680 : : hca_attr->max_geneve_tlv_option_data_len)
3681 : 0 : return rte_flow_error_set
3682 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3683 : : "Geneve TLV opt length not supported");
3684 [ # # ]: 0 : if (hca_attr->max_geneve_tlv_options > 1)
3685 : 0 : DRV_LOG(DEBUG,
3686 : : "max_geneve_tlv_options supports more than 1 option");
3687 : : /* Check GENEVE item preceding. */
3688 [ # # # # ]: 0 : if (!geneve_item || !(last_item & MLX5_FLOW_LAYER_GENEVE))
3689 : 0 : return rte_flow_error_set
3690 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3691 : : "Geneve opt item must be preceded with Geneve item");
3692 : 0 : geneve_spec = geneve_item->spec;
3693 [ # # ]: 0 : geneve_mask = geneve_item->mask ? geneve_item->mask :
3694 : : &rte_flow_item_geneve_mask;
3695 : : /* Check if GENEVE TLV option size doesn't exceed option length */
3696 [ # # # # ]: 0 : if (geneve_spec && (geneve_mask->ver_opt_len_o_c_rsvd0 ||
3697 [ # # ]: 0 : geneve_spec->ver_opt_len_o_c_rsvd0)) {
3698 : 0 : tlv_option_len = spec->option_len & mask->option_len;
3699 [ # # ]: 0 : optlen_v = rte_be_to_cpu_16(geneve_spec->ver_opt_len_o_c_rsvd0);
3700 : 0 : optlen_v = MLX5_GENEVE_OPTLEN_VAL(optlen_v);
3701 [ # # ]: 0 : optlen_m = rte_be_to_cpu_16(geneve_mask->ver_opt_len_o_c_rsvd0);
3702 : 0 : optlen_m = MLX5_GENEVE_OPTLEN_VAL(optlen_m);
3703 [ # # ]: 0 : if ((optlen_v & optlen_m) <= tlv_option_len)
3704 : 0 : return rte_flow_error_set
3705 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3706 : : "GENEVE TLV option length exceeds optlen");
3707 : : }
3708 : : /* Check if length is 0 or data is 0. */
3709 [ # # # # ]: 0 : if (spec->data == NULL || spec->option_len == 0)
3710 : 0 : return rte_flow_error_set
3711 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3712 : : "Geneve TLV opt with zero data/length not supported");
3713 : : /* Check not all data & mask are 0. */
3714 : 0 : data_len = spec->option_len * 4;
3715 [ # # ]: 0 : if (mask->data == NULL) {
3716 [ # # ]: 0 : for (i = 0; i < data_len; i++)
3717 [ # # ]: 0 : if (spec->data[i])
3718 : : break;
3719 [ # # ]: 0 : if (i == data_len)
3720 : 0 : return rte_flow_error_set(error, ENOTSUP,
3721 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3722 : : "Can't match on Geneve option data 0");
3723 : : } else {
3724 [ # # ]: 0 : for (i = 0; i < data_len; i++)
3725 [ # # ]: 0 : if (spec->data[i] & mask->data[i])
3726 : : break;
3727 [ # # ]: 0 : if (i == data_len)
3728 : 0 : return rte_flow_error_set(error, ENOTSUP,
3729 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3730 : : "Can't match on Geneve option data and mask 0");
3731 : : /* Check data mask supported. */
3732 [ # # ]: 0 : for (i = data_max_supported; i < data_len ; i++)
3733 [ # # ]: 0 : if (mask->data[i])
3734 : 0 : return rte_flow_error_set(error, ENOTSUP,
3735 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3736 : : "Data mask is of unsupported size");
3737 : : }
3738 : : /* Check GENEVE option is supported in NIC. */
3739 [ # # ]: 0 : if (!hca_attr->geneve_tlv_opt)
3740 : 0 : return rte_flow_error_set
3741 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3742 : : "Geneve TLV opt not supported");
3743 : : /* Check if we already have geneve option with different type/class. */
3744 : 0 : rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
3745 : 0 : geneve_opt_resource = sh->geneve_tlv_option_resource;
3746 [ # # ]: 0 : if (geneve_opt_resource != NULL)
3747 : 0 : if (geneve_opt_resource->option_class != spec->option_class ||
3748 [ # # ]: 0 : geneve_opt_resource->option_type != spec->option_type ||
3749 : : geneve_opt_resource->length != spec->option_len) {
3750 : : rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
3751 : 0 : return rte_flow_error_set(error, ENOTSUP,
3752 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3753 : : "Only one Geneve TLV option supported");
3754 : : }
3755 : : rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
3756 : 0 : return 0;
3757 : : }
3758 : :
3759 : : /**
3760 : : * Validate MPLS item.
3761 : : *
3762 : : * @param[in] dev
3763 : : * Pointer to the rte_eth_dev structure.
3764 : : * @param[in] item
3765 : : * Item specification.
3766 : : * @param[in] item_flags
3767 : : * Bit-fields that holds the items detected until now.
3768 : : * @param[in] prev_layer
3769 : : * The protocol layer indicated in previous item.
3770 : : * @param[out] error
3771 : : * Pointer to error structure.
3772 : : *
3773 : : * @return
3774 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3775 : : */
3776 : : int
3777 : 0 : mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev __rte_unused,
3778 : : const struct rte_flow_item *item __rte_unused,
3779 : : uint64_t item_flags __rte_unused,
3780 : : uint64_t prev_layer __rte_unused,
3781 : : struct rte_flow_error *error)
3782 : : {
3783 : : #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
3784 [ # # ]: 0 : const struct rte_flow_item_mpls hws_nic_mask = {
3785 : : .label_tc_s = {0xff, 0xff, 0xff},
3786 : : .ttl = 0xff
3787 : : };
3788 : : const struct rte_flow_item_mpls *nic_mask = !mlx5_hws_active(dev) ?
3789 [ # # ]: 0 : &rte_flow_item_mpls_mask : &hws_nic_mask;
3790 : 0 : const struct rte_flow_item_mpls *mask = item->mask;
3791 : : struct mlx5_priv *priv = dev->data->dev_private;
3792 : : int ret;
3793 : :
3794 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
3795 : : /* MPLS has HW support in HWS */
3796 [ # # ]: 0 : if (!priv->sh->dev_cap.mpls_en)
3797 : 0 : return rte_flow_error_set(error, ENOTSUP,
3798 : : RTE_FLOW_ERROR_TYPE_ITEM,
3799 : : item, "MPLS not supported or disabled in firmware configuration.");
3800 : : /* MPLS over UDP, GRE is allowed */
3801 [ # # ]: 0 : if (!(prev_layer & (MLX5_FLOW_LAYER_OUTER_L4_UDP |
3802 : : MLX5_FLOW_LAYER_GRE |
3803 : : MLX5_FLOW_LAYER_GRE_KEY)))
3804 : 0 : return rte_flow_error_set(error, EINVAL,
3805 : : RTE_FLOW_ERROR_TYPE_ITEM,
3806 : : item, "protocol filtering not compatible with MPLS layer");
3807 : : /* Multi-tunnel isn't allowed but MPLS over GRE is an exception. */
3808 [ # # ]: 0 : if ((item_flags & MLX5_FLOW_LAYER_TUNNEL) &&
3809 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_GRE))
3810 : 0 : return rte_flow_error_set(error, ENOTSUP,
3811 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3812 : : "multiple tunnel layers not supported");
3813 : : }
3814 [ # # ]: 0 : if (!mask)
3815 : : mask = nic_mask;
3816 : 0 : ret = mlx5_flow_item_acceptable
3817 : : (dev, item, (const uint8_t *)mask,
3818 : : (const uint8_t *)nic_mask,
3819 : : sizeof(struct rte_flow_item_mpls),
3820 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3821 : : if (ret < 0)
3822 : : return ret;
3823 : : return 0;
3824 : : #else
3825 : : return rte_flow_error_set(error, ENOTSUP,
3826 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3827 : : "MPLS is not supported by Verbs, please"
3828 : : " update.");
3829 : : #endif
3830 : : }
3831 : :
3832 : : /**
3833 : : * Validate NVGRE item.
3834 : : *
3835 : : * @param[in] item
3836 : : * Item specification.
3837 : : * @param[in] item_flags
3838 : : * Bit flags to mark detected items.
3839 : : * @param[in] target_protocol
3840 : : * The next protocol in the previous item.
3841 : : * @param[out] error
3842 : : * Pointer to error structure.
3843 : : *
3844 : : * @return
3845 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3846 : : */
3847 : : int
3848 : 0 : mlx5_flow_validate_item_nvgre(const struct rte_eth_dev *dev,
3849 : : const struct rte_flow_item *item,
3850 : : uint64_t item_flags,
3851 : : uint8_t target_protocol,
3852 : : struct rte_flow_error *error)
3853 : : {
3854 : 0 : const struct rte_flow_item_nvgre *mask = item->mask;
3855 : : int ret;
3856 : :
3857 [ # # ]: 0 : const struct rte_flow_item_nvgre hws_nic_mask = {
3858 : : .c_k_s_rsvd0_ver = RTE_BE16(0xB000),
3859 : : .protocol = RTE_BE16(UINT16_MAX),
3860 : : .tni = {0xff, 0xff, 0xff},
3861 : : .flow_id = 0xff
3862 : : };
3863 : : const struct rte_flow_item_nvgre *nic_mask = !mlx5_hws_active(dev) ?
3864 [ # # ]: 0 : &rte_flow_item_nvgre_mask : &hws_nic_mask;
3865 : :
3866 [ # # ]: 0 : if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
3867 : 0 : return rte_flow_error_set(error, EINVAL,
3868 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3869 : : "protocol filtering not compatible"
3870 : : " with this GRE layer");
3871 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3872 : 0 : return rte_flow_error_set(error, ENOTSUP,
3873 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3874 : : "multiple tunnel layers not"
3875 : : " supported");
3876 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
3877 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
3878 : 0 : return rte_flow_error_set(error, ENOTSUP,
3879 : : RTE_FLOW_ERROR_TYPE_ITEM,
3880 : : item, "L3 Layer is missing");
3881 : : }
3882 [ # # ]: 0 : if (!mask)
3883 : : mask = nic_mask;
3884 : 0 : ret = mlx5_flow_item_acceptable
3885 : : (dev, item, (const uint8_t *)mask,
3886 : : (const uint8_t *)nic_mask,
3887 : : sizeof(struct rte_flow_item_nvgre),
3888 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3889 : : if (ret < 0)
3890 : : return ret;
3891 : : return 0;
3892 : : }
3893 : :
3894 : : /**
3895 : : * Validate eCPRI item.
3896 : : *
3897 : : * @param[in] item
3898 : : * Item specification.
3899 : : * @param[in] item_flags
3900 : : * Bit-fields that holds the items detected until now.
3901 : : * @param[in] last_item
3902 : : * Previous validated item in the pattern items.
3903 : : * @param[in] ether_type
3904 : : * Type in the ethernet layer header (including dot1q).
3905 : : * @param[in] acc_mask
3906 : : * Acceptable mask, if NULL default internal default mask
3907 : : * will be used to check whether item fields are supported.
3908 : : * @param[out] error
3909 : : * Pointer to error structure.
3910 : : *
3911 : : * @return
3912 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3913 : : */
3914 : : int
3915 : 0 : mlx5_flow_validate_item_ecpri(const struct rte_eth_dev *dev,
3916 : : const struct rte_flow_item *item,
3917 : : uint64_t item_flags,
3918 : : uint64_t last_item,
3919 : : uint16_t ether_type,
3920 : : const struct rte_flow_item_ecpri *acc_mask,
3921 : : struct rte_flow_error *error)
3922 : : {
3923 : 0 : const struct rte_flow_item_ecpri *mask = item->mask;
3924 : 0 : const struct rte_flow_item_ecpri nic_mask = {
3925 : : .hdr = {
3926 : : .common = {
3927 : : .u32 =
3928 : : RTE_BE32(((const struct rte_ecpri_common_hdr) {
3929 : : .type = 0xFF,
3930 : : }).u32),
3931 : : },
3932 : : .dummy[0] = 0xFFFFFFFF,
3933 : : },
3934 : : };
3935 : : const uint64_t outer_l2_vlan = (MLX5_FLOW_LAYER_OUTER_L2 |
3936 : : MLX5_FLOW_LAYER_OUTER_VLAN);
3937 : : struct rte_flow_item_ecpri mask_lo;
3938 : :
3939 [ # # # # ]: 0 : if (!(last_item & outer_l2_vlan) &&
3940 : : last_item != MLX5_FLOW_LAYER_OUTER_L4_UDP)
3941 : 0 : return rte_flow_error_set(error, EINVAL,
3942 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3943 : : "eCPRI can only follow L2/VLAN layer or UDP layer");
3944 [ # # ]: 0 : if ((last_item & outer_l2_vlan) && ether_type &&
3945 [ # # ]: 0 : ether_type != RTE_ETHER_TYPE_ECPRI)
3946 : 0 : return rte_flow_error_set(error, EINVAL,
3947 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3948 : : "eCPRI cannot follow L2/VLAN layer which ether type is not 0xAEFE");
3949 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3950 : 0 : return rte_flow_error_set(error, EINVAL,
3951 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3952 : : "eCPRI with tunnel is not supported right now");
3953 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_OUTER_L3)
3954 : 0 : return rte_flow_error_set(error, ENOTSUP,
3955 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3956 : : "multiple L3 layers not supported");
3957 [ # # ]: 0 : else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP)
3958 : 0 : return rte_flow_error_set(error, EINVAL,
3959 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3960 : : "eCPRI cannot coexist with a TCP layer");
3961 : : /* In specification, eCPRI could be over UDP layer. */
3962 [ # # ]: 0 : else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP)
3963 : 0 : return rte_flow_error_set(error, EINVAL,
3964 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3965 : : "eCPRI over UDP layer is not yet supported right now");
3966 : : /* Mask for type field in common header could be zero. */
3967 [ # # ]: 0 : if (!mask)
3968 : : mask = &rte_flow_item_ecpri_mask;
3969 [ # # ]: 0 : mask_lo.hdr.common.u32 = rte_be_to_cpu_32(mask->hdr.common.u32);
3970 : : /* Input mask is in big-endian format. */
3971 [ # # ]: 0 : if (mask_lo.hdr.common.type != 0 && mask_lo.hdr.common.type != 0xff)
3972 : 0 : return rte_flow_error_set(error, EINVAL,
3973 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
3974 : : "partial mask is not supported for protocol");
3975 [ # # # # ]: 0 : else if (mask_lo.hdr.common.type == 0 && mask->hdr.dummy[0] != 0)
3976 : 0 : return rte_flow_error_set(error, EINVAL,
3977 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
3978 : : "message header mask must be after a type mask");
3979 [ # # ]: 0 : return mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
3980 : : acc_mask ? (const uint8_t *)acc_mask
3981 : : : (const uint8_t *)&nic_mask,
3982 : : sizeof(struct rte_flow_item_ecpri),
3983 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3984 : : }
3985 : :
3986 : : /**
3987 : : * Validate the NSH item.
3988 : : *
3989 : : * @param[in] dev
3990 : : * Pointer to Ethernet device on which flow rule is being created on.
3991 : : * @param[out] error
3992 : : * Pointer to error structure.
3993 : : *
3994 : : * @return
3995 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3996 : : */
3997 : : int
3998 : 0 : mlx5_flow_validate_item_nsh(struct rte_eth_dev *dev,
3999 : : const struct rte_flow_item *item,
4000 : : struct rte_flow_error *error)
4001 : : {
4002 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4003 : :
4004 [ # # ]: 0 : if (item->mask) {
4005 : 0 : return rte_flow_error_set(error, ENOTSUP,
4006 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
4007 : : "NSH fields matching is not supported");
4008 : : }
4009 : :
4010 [ # # ]: 0 : if (!priv->sh->config.dv_flow_en) {
4011 : 0 : return rte_flow_error_set(error, ENOTSUP,
4012 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4013 : : NULL, "NSH support requires DV flow interface");
4014 : : }
4015 : :
4016 [ # # ]: 0 : if (!priv->sh->cdev->config.hca_attr.tunnel_stateless_vxlan_gpe_nsh) {
4017 : 0 : return rte_flow_error_set(error, ENOTSUP,
4018 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
4019 : : "Current FW does not support matching on NSH");
4020 : : }
4021 : :
4022 : : return 0;
4023 : : }
4024 : :
4025 : : static uintptr_t
4026 : 0 : flow_null_list_create(struct rte_eth_dev *dev __rte_unused,
4027 : : enum mlx5_flow_type type __rte_unused,
4028 : : const struct rte_flow_attr *attr __rte_unused,
4029 : : const struct rte_flow_item items[] __rte_unused,
4030 : : const struct rte_flow_action actions[] __rte_unused,
4031 : : bool external __rte_unused,
4032 : : struct rte_flow_error *error)
4033 : : {
4034 : 0 : rte_flow_error_set(error, ENOTSUP,
4035 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
4036 : 0 : return 0;
4037 : : }
4038 : :
4039 : : static int
4040 : 0 : flow_null_validate(struct rte_eth_dev *dev __rte_unused,
4041 : : const struct rte_flow_attr *attr __rte_unused,
4042 : : const struct rte_flow_item items[] __rte_unused,
4043 : : const struct rte_flow_action actions[] __rte_unused,
4044 : : bool external __rte_unused,
4045 : : int hairpin __rte_unused,
4046 : : struct rte_flow_error *error)
4047 : : {
4048 : 0 : return rte_flow_error_set(error, ENOTSUP,
4049 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
4050 : : }
4051 : :
4052 : : static struct mlx5_flow *
4053 : 0 : flow_null_prepare(struct rte_eth_dev *dev __rte_unused,
4054 : : const struct rte_flow_attr *attr __rte_unused,
4055 : : const struct rte_flow_item items[] __rte_unused,
4056 : : const struct rte_flow_action actions[] __rte_unused,
4057 : : struct rte_flow_error *error)
4058 : : {
4059 : 0 : rte_flow_error_set(error, ENOTSUP,
4060 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
4061 : 0 : return NULL;
4062 : : }
4063 : :
4064 : : static int
4065 : 0 : flow_null_translate(struct rte_eth_dev *dev __rte_unused,
4066 : : struct mlx5_flow *dev_flow __rte_unused,
4067 : : const struct rte_flow_attr *attr __rte_unused,
4068 : : const struct rte_flow_item items[] __rte_unused,
4069 : : const struct rte_flow_action actions[] __rte_unused,
4070 : : struct rte_flow_error *error)
4071 : : {
4072 : 0 : return rte_flow_error_set(error, ENOTSUP,
4073 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
4074 : : }
4075 : :
4076 : : static int
4077 : 0 : flow_null_apply(struct rte_eth_dev *dev __rte_unused,
4078 : : struct rte_flow *flow __rte_unused,
4079 : : struct rte_flow_error *error)
4080 : : {
4081 : 0 : return rte_flow_error_set(error, ENOTSUP,
4082 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
4083 : : }
4084 : :
4085 : : static void
4086 : 0 : flow_null_remove(struct rte_eth_dev *dev __rte_unused,
4087 : : struct rte_flow *flow __rte_unused)
4088 : : {
4089 : 0 : }
4090 : :
4091 : : static void
4092 : 0 : flow_null_destroy(struct rte_eth_dev *dev __rte_unused,
4093 : : struct rte_flow *flow __rte_unused)
4094 : : {
4095 : 0 : }
4096 : :
4097 : : static int
4098 : 0 : flow_null_query(struct rte_eth_dev *dev __rte_unused,
4099 : : struct rte_flow *flow __rte_unused,
4100 : : const struct rte_flow_action *actions __rte_unused,
4101 : : void *data __rte_unused,
4102 : : struct rte_flow_error *error)
4103 : : {
4104 : 0 : return rte_flow_error_set(error, ENOTSUP,
4105 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
4106 : : }
4107 : :
4108 : : static int
4109 : 0 : flow_null_sync_domain(struct rte_eth_dev *dev __rte_unused,
4110 : : uint32_t domains __rte_unused,
4111 : : uint32_t flags __rte_unused)
4112 : : {
4113 : 0 : return 0;
4114 : : }
4115 : :
4116 : : int
4117 : 0 : flow_null_get_aged_flows(struct rte_eth_dev *dev,
4118 : : void **context __rte_unused,
4119 : : uint32_t nb_contexts __rte_unused,
4120 : : struct rte_flow_error *error __rte_unused)
4121 : : {
4122 : 0 : DRV_LOG(ERR, "port %u get aged flows is not supported.",
4123 : : dev->data->port_id);
4124 : 0 : return -ENOTSUP;
4125 : : }
4126 : :
4127 : : uint32_t
4128 : 0 : flow_null_counter_allocate(struct rte_eth_dev *dev)
4129 : : {
4130 : 0 : DRV_LOG(ERR, "port %u counter allocate is not supported.",
4131 : : dev->data->port_id);
4132 : 0 : return 0;
4133 : : }
4134 : :
4135 : : void
4136 : 0 : flow_null_counter_free(struct rte_eth_dev *dev,
4137 : : uint32_t counter __rte_unused)
4138 : : {
4139 : 0 : DRV_LOG(ERR, "port %u counter free is not supported.",
4140 : : dev->data->port_id);
4141 : 0 : }
4142 : :
4143 : : int
4144 : 0 : flow_null_counter_query(struct rte_eth_dev *dev,
4145 : : uint32_t counter __rte_unused,
4146 : : bool clear __rte_unused,
4147 : : uint64_t *pkts __rte_unused,
4148 : : uint64_t *bytes __rte_unused,
4149 : : void **action __rte_unused)
4150 : : {
4151 : 0 : DRV_LOG(ERR, "port %u counter query is not supported.",
4152 : : dev->data->port_id);
4153 : 0 : return -ENOTSUP;
4154 : : }
4155 : :
4156 : : /* Void driver to protect from null pointer reference. */
4157 : : const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
4158 : : .list_create = flow_null_list_create,
4159 : : .validate = flow_null_validate,
4160 : : .prepare = flow_null_prepare,
4161 : : .translate = flow_null_translate,
4162 : : .apply = flow_null_apply,
4163 : : .remove = flow_null_remove,
4164 : : .destroy = flow_null_destroy,
4165 : : .query = flow_null_query,
4166 : : .sync_domain = flow_null_sync_domain,
4167 : : .get_aged_flows = flow_null_get_aged_flows,
4168 : : .counter_alloc = flow_null_counter_allocate,
4169 : : .counter_free = flow_null_counter_free,
4170 : : .counter_query = flow_null_counter_query
4171 : : };
4172 : :
4173 : : /**
4174 : : * Select flow driver type according to flow attributes and device
4175 : : * configuration.
4176 : : *
4177 : : * @param[in] dev
4178 : : * Pointer to the dev structure.
4179 : : * @param[in] attr
4180 : : * Pointer to the flow attributes.
4181 : : *
4182 : : * @return
4183 : : * flow driver type, MLX5_FLOW_TYPE_MAX otherwise.
4184 : : */
4185 : : static enum mlx5_flow_drv_type
4186 : 0 : flow_get_drv_type(struct rte_eth_dev *dev, const struct rte_flow_attr *attr)
4187 : : {
4188 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4189 : : /* The OS can determine first a specific flow type (DV, VERBS) */
4190 : : enum mlx5_flow_drv_type type = mlx5_flow_os_get_type();
4191 : :
4192 : : if (type != MLX5_FLOW_TYPE_MAX)
4193 : : return type;
4194 : : /*
4195 : : * Currently when dv_flow_en == 2, only HW steering engine is
4196 : : * supported. New engines can also be chosen here if ready.
4197 : : */
4198 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
4199 : : return MLX5_FLOW_TYPE_HW;
4200 [ # # ]: 0 : if (!attr)
4201 : : return MLX5_FLOW_TYPE_MIN;
4202 : : /* If no OS specific type - continue with DV/VERBS selection */
4203 [ # # # # ]: 0 : if (attr->transfer && priv->sh->config.dv_esw_en)
4204 : : type = MLX5_FLOW_TYPE_DV;
4205 [ # # ]: 0 : if (!attr->transfer)
4206 [ # # # # : 0 : type = priv->sh->config.dv_flow_en ? MLX5_FLOW_TYPE_DV :
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
4207 : : MLX5_FLOW_TYPE_VERBS;
4208 : : return type;
4209 : : }
4210 : :
4211 : : #define flow_get_drv_ops(type) flow_drv_ops[type]
4212 : :
4213 : : /**
4214 : : * Flow driver validation API. This abstracts calling driver specific functions.
4215 : : * The type of flow driver is determined according to flow attributes.
4216 : : *
4217 : : * @param[in] dev
4218 : : * Pointer to the dev structure.
4219 : : * @param[in] attr
4220 : : * Pointer to the flow attributes.
4221 : : * @param[in] items
4222 : : * Pointer to the list of items.
4223 : : * @param[in] actions
4224 : : * Pointer to the list of actions.
4225 : : * @param[in] external
4226 : : * This flow rule is created by request external to PMD.
4227 : : * @param[in] hairpin
4228 : : * Number of hairpin TX actions, 0 means classic flow.
4229 : : * @param[out] error
4230 : : * Pointer to the error structure.
4231 : : *
4232 : : * @return
4233 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4234 : : */
4235 : : static inline int
4236 : 0 : flow_drv_validate(struct rte_eth_dev *dev,
4237 : : const struct rte_flow_attr *attr,
4238 : : const struct rte_flow_item items[],
4239 : : const struct rte_flow_action actions[],
4240 : : bool external, int hairpin, struct rte_flow_error *error)
4241 : : {
4242 : : const struct mlx5_flow_driver_ops *fops;
4243 : 0 : enum mlx5_flow_drv_type type = flow_get_drv_type(dev, attr);
4244 : :
4245 : 0 : fops = flow_get_drv_ops(type);
4246 : 0 : return fops->validate(dev, attr, items, actions, external,
4247 : : hairpin, error);
4248 : : }
4249 : :
4250 : : /**
4251 : : * Flow driver preparation API. This abstracts calling driver specific
4252 : : * functions. Parent flow (rte_flow) should have driver type (drv_type). It
4253 : : * calculates the size of memory required for device flow, allocates the memory,
4254 : : * initializes the device flow and returns the pointer.
4255 : : *
4256 : : * @note
4257 : : * This function initializes device flow structure such as dv or verbs in
4258 : : * struct mlx5_flow. However, it is caller's responsibility to initialize the
4259 : : * rest. For example, adding returning device flow to flow->dev_flow list and
4260 : : * setting backward reference to the flow should be done out of this function.
4261 : : * layers field is not filled either.
4262 : : *
4263 : : * @param[in] dev
4264 : : * Pointer to the dev structure.
4265 : : * @param[in] attr
4266 : : * Pointer to the flow attributes.
4267 : : * @param[in] items
4268 : : * Pointer to the list of items.
4269 : : * @param[in] actions
4270 : : * Pointer to the list of actions.
4271 : : * @param[in] flow_idx
4272 : : * This memory pool index to the flow.
4273 : : * @param[out] error
4274 : : * Pointer to the error structure.
4275 : : *
4276 : : * @return
4277 : : * Pointer to device flow on success, otherwise NULL and rte_errno is set.
4278 : : */
4279 : : static inline struct mlx5_flow *
4280 : : flow_drv_prepare(struct rte_eth_dev *dev,
4281 : : const struct rte_flow *flow,
4282 : : const struct rte_flow_attr *attr,
4283 : : const struct rte_flow_item items[],
4284 : : const struct rte_flow_action actions[],
4285 : : uint32_t flow_idx,
4286 : : struct rte_flow_error *error)
4287 : : {
4288 : : const struct mlx5_flow_driver_ops *fops;
4289 : 0 : enum mlx5_flow_drv_type type = flow->drv_type;
4290 : : struct mlx5_flow *mlx5_flow = NULL;
4291 : :
4292 : : MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
4293 : 0 : fops = flow_get_drv_ops(type);
4294 : 0 : mlx5_flow = fops->prepare(dev, attr, items, actions, error);
4295 [ # # # # : 0 : if (mlx5_flow)
# # ]
4296 : 0 : mlx5_flow->flow_idx = flow_idx;
4297 : : return mlx5_flow;
4298 : : }
4299 : :
4300 : : /**
4301 : : * Flow driver translation API. This abstracts calling driver specific
4302 : : * functions. Parent flow (rte_flow) should have driver type (drv_type). It
4303 : : * translates a generic flow into a driver flow. flow_drv_prepare() must
4304 : : * precede.
4305 : : *
4306 : : * @note
4307 : : * dev_flow->layers could be filled as a result of parsing during translation
4308 : : * if needed by flow_drv_apply(). dev_flow->flow->actions can also be filled
4309 : : * if necessary. As a flow can have multiple dev_flows by RSS flow expansion,
4310 : : * flow->actions could be overwritten even though all the expanded dev_flows
4311 : : * have the same actions.
4312 : : *
4313 : : * @param[in] dev
4314 : : * Pointer to the rte dev structure.
4315 : : * @param[in, out] dev_flow
4316 : : * Pointer to the mlx5 flow.
4317 : : * @param[in] attr
4318 : : * Pointer to the flow attributes.
4319 : : * @param[in] items
4320 : : * Pointer to the list of items.
4321 : : * @param[in] actions
4322 : : * Pointer to the list of actions.
4323 : : * @param[out] error
4324 : : * Pointer to the error structure.
4325 : : *
4326 : : * @return
4327 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4328 : : */
4329 : : static inline int
4330 : : flow_drv_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
4331 : : const struct rte_flow_attr *attr,
4332 : : const struct rte_flow_item items[],
4333 : : const struct rte_flow_action actions[],
4334 : : struct rte_flow_error *error)
4335 : : {
4336 : : const struct mlx5_flow_driver_ops *fops;
4337 : 0 : enum mlx5_flow_drv_type type = dev_flow->flow->drv_type;
4338 : :
4339 : : MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
4340 : 0 : fops = flow_get_drv_ops(type);
4341 : 0 : return fops->translate(dev, dev_flow, attr, items, actions, error);
4342 : : }
4343 : :
4344 : : /**
4345 : : * Flow driver apply API. This abstracts calling driver specific functions.
4346 : : * Parent flow (rte_flow) should have driver type (drv_type). It applies
4347 : : * translated driver flows on to device. flow_drv_translate() must precede.
4348 : : *
4349 : : * @param[in] dev
4350 : : * Pointer to Ethernet device structure.
4351 : : * @param[in, out] flow
4352 : : * Pointer to flow structure.
4353 : : * @param[out] error
4354 : : * Pointer to error structure.
4355 : : *
4356 : : * @return
4357 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4358 : : */
4359 : : static inline int
4360 : : flow_drv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
4361 : : struct rte_flow_error *error)
4362 : : {
4363 : : const struct mlx5_flow_driver_ops *fops;
4364 : 0 : enum mlx5_flow_drv_type type = flow->drv_type;
4365 : :
4366 : : MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
4367 : 0 : fops = flow_get_drv_ops(type);
4368 : 0 : return fops->apply(dev, flow, error);
4369 : : }
4370 : :
4371 : : /**
4372 : : * Flow driver destroy API. This abstracts calling driver specific functions.
4373 : : * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
4374 : : * on device and releases resources of the flow.
4375 : : *
4376 : : * @param[in] dev
4377 : : * Pointer to Ethernet device.
4378 : : * @param[in, out] flow
4379 : : * Pointer to flow structure.
4380 : : */
4381 : : static inline void
4382 : : flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
4383 : : {
4384 : : const struct mlx5_flow_driver_ops *fops;
4385 : 0 : enum mlx5_flow_drv_type type = flow->drv_type;
4386 : :
4387 : : MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
4388 : 0 : fops = flow_get_drv_ops(type);
4389 : 0 : fops->destroy(dev, flow);
4390 : : }
4391 : :
4392 : : /**
4393 : : * Flow driver find RSS policy tbl API. This abstracts calling driver
4394 : : * specific functions. Parent flow (rte_flow) should have driver
4395 : : * type (drv_type). It will find the RSS policy table that has the rss_desc.
4396 : : *
4397 : : * @param[in] dev
4398 : : * Pointer to Ethernet device.
4399 : : * @param[in, out] flow
4400 : : * Pointer to flow structure.
4401 : : * @param[in] policy
4402 : : * Pointer to meter policy table.
4403 : : * @param[in] rss_desc
4404 : : * Pointer to rss_desc
4405 : : */
4406 : : static struct mlx5_flow_meter_sub_policy *
4407 : : flow_drv_meter_sub_policy_rss_prepare(struct rte_eth_dev *dev,
4408 : : struct rte_flow *flow,
4409 : : struct mlx5_flow_meter_policy *policy,
4410 : : struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS])
4411 : : {
4412 : : const struct mlx5_flow_driver_ops *fops;
4413 : 0 : enum mlx5_flow_drv_type type = flow->drv_type;
4414 : :
4415 : : MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
4416 : 0 : fops = flow_get_drv_ops(type);
4417 : 0 : return fops->meter_sub_policy_rss_prepare(dev, policy, rss_desc);
4418 : : }
4419 : :
4420 : : /**
4421 : : * Flow driver color tag rule API. This abstracts calling driver
4422 : : * specific functions. Parent flow (rte_flow) should have driver
4423 : : * type (drv_type). It will create the color tag rules in hierarchy meter.
4424 : : *
4425 : : * @param[in] dev
4426 : : * Pointer to Ethernet device.
4427 : : * @param[in, out] flow
4428 : : * Pointer to flow structure.
4429 : : * @param[in] fm
4430 : : * Pointer to flow meter structure.
4431 : : * @param[in] src_port
4432 : : * The src port this extra rule should use.
4433 : : * @param[in] item
4434 : : * The src port id match item.
4435 : : * @param[out] error
4436 : : * Pointer to error structure.
4437 : : */
4438 : : static int
4439 : : flow_drv_mtr_hierarchy_rule_create(struct rte_eth_dev *dev,
4440 : : struct rte_flow *flow,
4441 : : struct mlx5_flow_meter_info *fm,
4442 : : int32_t src_port,
4443 : : const struct rte_flow_item *item,
4444 : : struct rte_flow_error *error)
4445 : : {
4446 : : const struct mlx5_flow_driver_ops *fops;
4447 : 0 : enum mlx5_flow_drv_type type = flow->drv_type;
4448 : :
4449 : : MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
4450 : 0 : fops = flow_get_drv_ops(type);
4451 : 0 : return fops->meter_hierarchy_rule_create(dev, fm,
4452 : : src_port, item, error);
4453 : : }
4454 : :
4455 : : /**
4456 : : * Get RSS action from the action list.
4457 : : *
4458 : : * @param[in] dev
4459 : : * Pointer to Ethernet device.
4460 : : * @param[in] actions
4461 : : * Pointer to the list of actions.
4462 : : * @param[in] flow
4463 : : * Parent flow structure pointer.
4464 : : *
4465 : : * @return
4466 : : * Pointer to the RSS action if exist, else return NULL.
4467 : : */
4468 : : static const struct rte_flow_action_rss*
4469 : 0 : flow_get_rss_action(struct rte_eth_dev *dev,
4470 : : const struct rte_flow_action actions[])
4471 : : {
4472 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4473 : : const struct rte_flow_action_rss *rss = NULL;
4474 : : struct mlx5_meter_policy_action_container *acg;
4475 : : struct mlx5_meter_policy_action_container *acy;
4476 : :
4477 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4478 [ # # # # ]: 0 : switch (actions->type) {
4479 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
4480 : 0 : rss = actions->conf;
4481 : 0 : break;
4482 : 0 : case RTE_FLOW_ACTION_TYPE_SAMPLE:
4483 : : {
4484 : 0 : const struct rte_flow_action_sample *sample =
4485 : : actions->conf;
4486 : 0 : const struct rte_flow_action *act = sample->actions;
4487 [ # # ]: 0 : for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++)
4488 [ # # ]: 0 : if (act->type == RTE_FLOW_ACTION_TYPE_RSS)
4489 : 0 : rss = act->conf;
4490 : : break;
4491 : : }
4492 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
4493 : : {
4494 : : uint32_t mtr_idx;
4495 : : struct mlx5_flow_meter_info *fm;
4496 : : struct mlx5_flow_meter_policy *policy;
4497 : 0 : const struct rte_flow_action_meter *mtr = actions->conf;
4498 : :
4499 : 0 : fm = mlx5_flow_meter_find(priv, mtr->mtr_id, &mtr_idx);
4500 [ # # # # ]: 0 : if (fm && !fm->def_policy) {
4501 : 0 : policy = mlx5_flow_meter_policy_find(dev,
4502 : : fm->policy_id, NULL);
4503 : : MLX5_ASSERT(policy);
4504 [ # # ]: 0 : if (policy->is_hierarchy) {
4505 : : policy =
4506 : 0 : mlx5_flow_meter_hierarchy_get_final_policy(dev,
4507 : : policy);
4508 [ # # ]: 0 : if (!policy)
4509 : 0 : return NULL;
4510 : : }
4511 [ # # ]: 0 : if (policy->is_rss) {
4512 : : acg =
4513 : : &policy->act_cnt[RTE_COLOR_GREEN];
4514 : : acy =
4515 : : &policy->act_cnt[RTE_COLOR_YELLOW];
4516 [ # # ]: 0 : if (acg->fate_action ==
4517 : : MLX5_FLOW_FATE_SHARED_RSS)
4518 : 0 : rss = acg->rss->conf;
4519 [ # # ]: 0 : else if (acy->fate_action ==
4520 : : MLX5_FLOW_FATE_SHARED_RSS)
4521 : 0 : rss = acy->rss->conf;
4522 : : }
4523 : : }
4524 : 0 : break;
4525 : : }
4526 : : default:
4527 : : break;
4528 : : }
4529 : : }
4530 : : return rss;
4531 : : }
4532 : :
4533 : : /**
4534 : : * Get ASO age action by index.
4535 : : *
4536 : : * @param[in] dev
4537 : : * Pointer to the Ethernet device structure.
4538 : : * @param[in] age_idx
4539 : : * Index to the ASO age action.
4540 : : *
4541 : : * @return
4542 : : * The specified ASO age action.
4543 : : */
4544 : : struct mlx5_aso_age_action*
4545 : 0 : flow_aso_age_get_by_idx(struct rte_eth_dev *dev, uint32_t age_idx)
4546 : : {
4547 : 0 : uint16_t pool_idx = age_idx & UINT16_MAX;
4548 : 0 : uint16_t offset = (age_idx >> 16) & UINT16_MAX;
4549 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4550 : 0 : struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
4551 : : struct mlx5_aso_age_pool *pool;
4552 : :
4553 : 0 : rte_rwlock_read_lock(&mng->resize_rwl);
4554 : 0 : pool = mng->pools[pool_idx];
4555 : : rte_rwlock_read_unlock(&mng->resize_rwl);
4556 : 0 : return &pool->actions[offset - 1];
4557 : : }
4558 : :
4559 : : /* maps indirect action to translated direct in some actions array */
4560 : : struct mlx5_translated_action_handle {
4561 : : struct rte_flow_action_handle *action; /**< Indirect action handle. */
4562 : : int index; /**< Index in related array of rte_flow_action. */
4563 : : };
4564 : :
4565 : : /**
4566 : : * Translates actions of type RTE_FLOW_ACTION_TYPE_INDIRECT to related
4567 : : * direct action if translation possible.
4568 : : * This functionality used to run same execution path for both direct and
4569 : : * indirect actions on flow create. All necessary preparations for indirect
4570 : : * action handling should be performed on *handle* actions list returned
4571 : : * from this call.
4572 : : *
4573 : : * @param[in] dev
4574 : : * Pointer to Ethernet device.
4575 : : * @param[in] actions
4576 : : * List of actions to translate.
4577 : : * @param[out] handle
4578 : : * List to store translated indirect action object handles.
4579 : : * @param[in, out] indir_n
4580 : : * Size of *handle* array. On return should be updated with number of
4581 : : * indirect actions retrieved from the *actions* list.
4582 : : * @param[out] translated_actions
4583 : : * List of actions where all indirect actions were translated to direct
4584 : : * if possible. NULL if no translation took place.
4585 : : * @param[out] error
4586 : : * Pointer to the error structure.
4587 : : *
4588 : : * @return
4589 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4590 : : */
4591 : : static int
4592 : 0 : flow_action_handles_translate(struct rte_eth_dev *dev,
4593 : : const struct rte_flow_action actions[],
4594 : : struct mlx5_translated_action_handle *handle,
4595 : : int *indir_n,
4596 : : struct rte_flow_action **translated_actions,
4597 : : struct rte_flow_error *error)
4598 : : {
4599 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4600 : : struct rte_flow_action *translated = NULL;
4601 : : size_t actions_size;
4602 : : int n;
4603 : : int copied_n = 0;
4604 : : struct mlx5_translated_action_handle *handle_end = NULL;
4605 : :
4606 [ # # ]: 0 : for (n = 0; actions[n].type != RTE_FLOW_ACTION_TYPE_END; n++) {
4607 [ # # ]: 0 : if (actions[n].type != RTE_FLOW_ACTION_TYPE_INDIRECT)
4608 : 0 : continue;
4609 [ # # ]: 0 : if (copied_n == *indir_n) {
4610 : 0 : return rte_flow_error_set
4611 : : (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_NUM,
4612 : : NULL, "too many shared actions");
4613 : : }
4614 [ # # ]: 0 : rte_memcpy(&handle[copied_n].action, &actions[n].conf,
4615 : : sizeof(actions[n].conf));
4616 : 0 : handle[copied_n].index = n;
4617 : 0 : copied_n++;
4618 : : }
4619 : 0 : n++;
4620 : 0 : *indir_n = copied_n;
4621 [ # # ]: 0 : if (!copied_n)
4622 : : return 0;
4623 : 0 : actions_size = sizeof(struct rte_flow_action) * n;
4624 : 0 : translated = mlx5_malloc(MLX5_MEM_ZERO, actions_size, 0, SOCKET_ID_ANY);
4625 [ # # ]: 0 : if (!translated) {
4626 : 0 : rte_errno = ENOMEM;
4627 : 0 : return -ENOMEM;
4628 : : }
4629 : : memcpy(translated, actions, actions_size);
4630 [ # # ]: 0 : for (handle_end = handle + copied_n; handle < handle_end; handle++) {
4631 : : struct mlx5_shared_action_rss *shared_rss;
4632 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle->action;
4633 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
4634 : 0 : uint32_t idx = act_idx &
4635 : : ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
4636 : :
4637 [ # # # # : 0 : switch (type) {
# # ]
4638 : 0 : case MLX5_INDIRECT_ACTION_TYPE_RSS:
4639 : 0 : shared_rss = mlx5_ipool_get
4640 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
4641 : 0 : translated[handle->index].type =
4642 : : RTE_FLOW_ACTION_TYPE_RSS;
4643 : 0 : translated[handle->index].conf =
4644 : 0 : &shared_rss->origin;
4645 : 0 : break;
4646 : 0 : case MLX5_INDIRECT_ACTION_TYPE_COUNT:
4647 : 0 : translated[handle->index].type =
4648 : : (enum rte_flow_action_type)
4649 : : MLX5_RTE_FLOW_ACTION_TYPE_COUNT;
4650 : 0 : translated[handle->index].conf = (void *)(uintptr_t)idx;
4651 : 0 : break;
4652 : 0 : case MLX5_INDIRECT_ACTION_TYPE_METER_MARK:
4653 : 0 : translated[handle->index].type =
4654 : : (enum rte_flow_action_type)
4655 : : MLX5_RTE_FLOW_ACTION_TYPE_METER_MARK;
4656 : 0 : translated[handle->index].conf = (void *)(uintptr_t)idx;
4657 : 0 : break;
4658 : 0 : case MLX5_INDIRECT_ACTION_TYPE_AGE:
4659 [ # # ]: 0 : if (priv->sh->flow_hit_aso_en) {
4660 : 0 : translated[handle->index].type =
4661 : : (enum rte_flow_action_type)
4662 : : MLX5_RTE_FLOW_ACTION_TYPE_AGE;
4663 : 0 : translated[handle->index].conf =
4664 : 0 : (void *)(uintptr_t)idx;
4665 : 0 : break;
4666 : : }
4667 : : /* Fall-through */
4668 : : case MLX5_INDIRECT_ACTION_TYPE_CT:
4669 [ # # ]: 0 : if (priv->sh->ct_aso_en) {
4670 : 0 : translated[handle->index].type =
4671 : : RTE_FLOW_ACTION_TYPE_CONNTRACK;
4672 : 0 : translated[handle->index].conf =
4673 : 0 : (void *)(uintptr_t)idx;
4674 : 0 : break;
4675 : : }
4676 : : /* Fall-through */
4677 : : default:
4678 : 0 : mlx5_free(translated);
4679 : 0 : return rte_flow_error_set
4680 : : (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
4681 : : NULL, "invalid indirect action type");
4682 : : }
4683 : : }
4684 : 0 : *translated_actions = translated;
4685 : 0 : return 0;
4686 : : }
4687 : :
4688 : : /**
4689 : : * Get Shared RSS action from the action list.
4690 : : *
4691 : : * @param[in] dev
4692 : : * Pointer to Ethernet device.
4693 : : * @param[in] shared
4694 : : * Pointer to the list of actions.
4695 : : * @param[in] shared_n
4696 : : * Actions list length.
4697 : : *
4698 : : * @return
4699 : : * The MLX5 RSS action ID if exists, otherwise return 0.
4700 : : */
4701 : : static uint32_t
4702 : 0 : flow_get_shared_rss_action(struct rte_eth_dev *dev,
4703 : : struct mlx5_translated_action_handle *handle,
4704 : : int shared_n)
4705 : : {
4706 : : struct mlx5_translated_action_handle *handle_end;
4707 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4708 : : struct mlx5_shared_action_rss *shared_rss;
4709 : :
4710 : :
4711 [ # # ]: 0 : for (handle_end = handle + shared_n; handle < handle_end; handle++) {
4712 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle->action;
4713 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
4714 : 0 : uint32_t idx = act_idx &
4715 : : ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
4716 [ # # ]: 0 : switch (type) {
4717 : 0 : case MLX5_INDIRECT_ACTION_TYPE_RSS:
4718 : 0 : shared_rss = mlx5_ipool_get
4719 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
4720 : : idx);
4721 : 0 : rte_atomic_fetch_add_explicit(&shared_rss->refcnt, 1,
4722 : : rte_memory_order_relaxed);
4723 : 0 : return idx;
4724 : : default:
4725 : : break;
4726 : : }
4727 : : }
4728 : : return 0;
4729 : : }
4730 : :
4731 : : static unsigned int
4732 : : find_graph_root(uint32_t rss_level)
4733 : : {
4734 : 0 : return rss_level < 2 ? MLX5_EXPANSION_ROOT :
4735 : : MLX5_EXPANSION_ROOT_OUTER;
4736 : : }
4737 : :
4738 : : /**
4739 : : * Get layer flags from the prefix flow.
4740 : : *
4741 : : * Some flows may be split to several subflows, the prefix subflow gets the
4742 : : * match items and the suffix sub flow gets the actions.
4743 : : * Some actions need the user defined match item flags to get the detail for
4744 : : * the action.
4745 : : * This function helps the suffix flow to get the item layer flags from prefix
4746 : : * subflow.
4747 : : *
4748 : : * @param[in] dev_flow
4749 : : * Pointer the created prefix subflow.
4750 : : *
4751 : : * @return
4752 : : * The layers get from prefix subflow.
4753 : : */
4754 : : static inline uint64_t
4755 : 0 : flow_get_prefix_layer_flags(struct mlx5_flow *dev_flow)
4756 : : {
4757 : : uint64_t layers = 0;
4758 : :
4759 : : /*
4760 : : * Layers bits could be localization, but usually the compiler will
4761 : : * help to do the optimization work for source code.
4762 : : * If no decap actions, use the layers directly.
4763 : : */
4764 [ # # ]: 0 : if (!(dev_flow->act_flags & MLX5_FLOW_ACTION_DECAP))
4765 : 0 : return dev_flow->handle->layers;
4766 : : /* Convert L3 layers with decap action. */
4767 [ # # ]: 0 : if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV4)
4768 : : layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV4;
4769 [ # # ]: 0 : else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV6)
4770 : : layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
4771 : : /* Convert L4 layers with decap action. */
4772 [ # # ]: 0 : if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_TCP)
4773 : 0 : layers |= MLX5_FLOW_LAYER_OUTER_L4_TCP;
4774 [ # # ]: 0 : else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_UDP)
4775 : 0 : layers |= MLX5_FLOW_LAYER_OUTER_L4_UDP;
4776 : : return layers;
4777 : : }
4778 : :
4779 : : /**
4780 : : * Get metadata split action information.
4781 : : *
4782 : : * @param[in] actions
4783 : : * Pointer to the list of actions.
4784 : : * @param[out] qrss
4785 : : * Pointer to the return pointer.
4786 : : * @param[out] qrss_type
4787 : : * Pointer to the action type to return. RTE_FLOW_ACTION_TYPE_END is returned
4788 : : * if no QUEUE/RSS is found.
4789 : : * @param[out] encap_idx
4790 : : * Pointer to the index of the encap action if exists, otherwise the last
4791 : : * action index.
4792 : : *
4793 : : * @return
4794 : : * Total number of actions.
4795 : : */
4796 : : static int
4797 : 0 : flow_parse_metadata_split_actions_info(const struct rte_flow_action actions[],
4798 : : const struct rte_flow_action **qrss,
4799 : : int *encap_idx)
4800 : : {
4801 : : const struct rte_flow_action_raw_encap *raw_encap;
4802 : : int actions_n = 0;
4803 : : int raw_decap_idx = -1;
4804 : :
4805 : 0 : *encap_idx = -1;
4806 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4807 [ # # # # : 0 : switch (actions->type) {
# ]
4808 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4809 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4810 : 0 : *encap_idx = actions_n;
4811 : 0 : break;
4812 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4813 : : raw_decap_idx = actions_n;
4814 : 0 : break;
4815 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4816 : 0 : raw_encap = actions->conf;
4817 [ # # ]: 0 : if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4818 : 0 : *encap_idx = raw_decap_idx != -1 ?
4819 [ # # ]: 0 : raw_decap_idx : actions_n;
4820 : : break;
4821 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
4822 : : case RTE_FLOW_ACTION_TYPE_RSS:
4823 : 0 : *qrss = actions;
4824 : 0 : break;
4825 : : default:
4826 : : break;
4827 : : }
4828 : 0 : actions_n++;
4829 : : }
4830 [ # # ]: 0 : if (*encap_idx == -1)
4831 : 0 : *encap_idx = actions_n;
4832 : : /* Count RTE_FLOW_ACTION_TYPE_END. */
4833 : 0 : return actions_n + 1;
4834 : : }
4835 : :
4836 : : /**
4837 : : * Check if the action will change packet.
4838 : : *
4839 : : * @param dev
4840 : : * Pointer to Ethernet device.
4841 : : * @param[in] type
4842 : : * action type.
4843 : : *
4844 : : * @return
4845 : : * true if action will change packet, false otherwise.
4846 : : */
4847 : 0 : static bool flow_check_modify_action_type(struct rte_eth_dev *dev,
4848 : : enum rte_flow_action_type type)
4849 : : {
4850 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4851 : :
4852 [ # # # ]: 0 : switch (type) {
4853 : : case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
4854 : : case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
4855 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
4856 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
4857 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
4858 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
4859 : : case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
4860 : : case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
4861 : : case RTE_FLOW_ACTION_TYPE_DEC_TTL:
4862 : : case RTE_FLOW_ACTION_TYPE_SET_TTL:
4863 : : case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
4864 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
4865 : : case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
4866 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
4867 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
4868 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
4869 : : case RTE_FLOW_ACTION_TYPE_SET_META:
4870 : : case RTE_FLOW_ACTION_TYPE_SET_TAG:
4871 : : case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
4872 : : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4873 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4874 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
4875 : : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4876 : : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
4877 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4878 : : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
4879 : : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4880 : : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4881 : : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
4882 : : return true;
4883 : 0 : case RTE_FLOW_ACTION_TYPE_FLAG:
4884 : : case RTE_FLOW_ACTION_TYPE_MARK:
4885 [ # # ]: 0 : if (priv->sh->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
4886 : : priv->sh->config.dv_xmeta_en != MLX5_XMETA_MODE_META32_HWS)
4887 : : return true;
4888 : : else
4889 : 0 : return false;
4890 : 0 : default:
4891 : 0 : return false;
4892 : : }
4893 : : }
4894 : :
4895 : : /**
4896 : : * Check meter action from the action list.
4897 : : *
4898 : : * @param dev
4899 : : * Pointer to Ethernet device.
4900 : : * @param[in] actions
4901 : : * Pointer to the list of actions.
4902 : : * @param[out] has_mtr
4903 : : * Pointer to the meter exist flag.
4904 : : * @param[out] has_modify
4905 : : * Pointer to the flag showing there's packet change action.
4906 : : * @param[out] meter_id
4907 : : * Pointer to the meter id.
4908 : : *
4909 : : * @return
4910 : : * Total number of actions.
4911 : : */
4912 : : static int
4913 : 0 : flow_check_meter_action(struct rte_eth_dev *dev,
4914 : : const struct rte_flow_action actions[],
4915 : : bool *has_mtr, bool *has_modify, uint32_t *meter_id)
4916 : : {
4917 : : const struct rte_flow_action_meter *mtr = NULL;
4918 : : int actions_n = 0;
4919 : :
4920 : : MLX5_ASSERT(has_mtr);
4921 : 0 : *has_mtr = false;
4922 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4923 [ # # ]: 0 : switch (actions->type) {
4924 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
4925 : 0 : mtr = actions->conf;
4926 : 0 : *meter_id = mtr->mtr_id;
4927 : 0 : *has_mtr = true;
4928 : 0 : break;
4929 : : default:
4930 : : break;
4931 : : }
4932 [ # # ]: 0 : if (!*has_mtr)
4933 : 0 : *has_modify |= flow_check_modify_action_type(dev,
4934 : 0 : actions->type);
4935 : 0 : actions_n++;
4936 : : }
4937 : : /* Count RTE_FLOW_ACTION_TYPE_END. */
4938 : 0 : return actions_n + 1;
4939 : : }
4940 : :
4941 : : /**
4942 : : * Check if the flow should be split due to hairpin.
4943 : : * The reason for the split is that in current HW we can't
4944 : : * support encap and push-vlan on Rx, so if a flow contains
4945 : : * these actions we move it to Tx.
4946 : : *
4947 : : * @param dev
4948 : : * Pointer to Ethernet device.
4949 : : * @param[in] attr
4950 : : * Flow rule attributes.
4951 : : * @param[in] actions
4952 : : * Associated actions (list terminated by the END action).
4953 : : *
4954 : : * @return
4955 : : * > 0 the number of actions and the flow should be split,
4956 : : * 0 when no split required.
4957 : : */
4958 : : static int
4959 : 0 : flow_check_hairpin_split(struct rte_eth_dev *dev,
4960 : : const struct rte_flow_attr *attr,
4961 : : const struct rte_flow_action actions[])
4962 : : {
4963 : : int queue_action = 0;
4964 : : int action_n = 0;
4965 : : int split = 0;
4966 : : int push_vlan = 0;
4967 : : const struct rte_flow_action_queue *queue;
4968 : : const struct rte_flow_action_rss *rss;
4969 : : const struct rte_flow_action_raw_encap *raw_encap;
4970 : : const struct rte_eth_hairpin_conf *conf;
4971 : :
4972 [ # # ]: 0 : if (!attr->ingress)
4973 : : return 0;
4974 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4975 [ # # ]: 0 : if (actions->type == RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN)
4976 : : push_vlan = 1;
4977 [ # # # # : 0 : switch (actions->type) {
# # ]
4978 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
4979 : 0 : queue = actions->conf;
4980 [ # # ]: 0 : if (queue == NULL)
4981 : : return 0;
4982 : 0 : conf = mlx5_rxq_get_hairpin_conf(dev, queue->index);
4983 [ # # # # ]: 0 : if (conf == NULL || conf->tx_explicit != 0)
4984 : : return 0;
4985 : : queue_action = 1;
4986 : 0 : action_n++;
4987 : 0 : break;
4988 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
4989 : 0 : rss = actions->conf;
4990 [ # # # # ]: 0 : if (rss == NULL || rss->queue_num == 0)
4991 : : return 0;
4992 : 0 : conf = mlx5_rxq_get_hairpin_conf(dev, rss->queue[0]);
4993 [ # # # # ]: 0 : if (conf == NULL || conf->tx_explicit != 0)
4994 : : return 0;
4995 : : queue_action = 1;
4996 : 0 : action_n++;
4997 : 0 : break;
4998 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4999 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
5000 : : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
5001 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
5002 : 0 : split++;
5003 : 0 : action_n++;
5004 : 0 : break;
5005 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
5006 [ # # ]: 0 : if (push_vlan)
5007 : 0 : split++;
5008 : 0 : action_n++;
5009 : 0 : break;
5010 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
5011 : 0 : raw_encap = actions->conf;
5012 [ # # ]: 0 : if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
5013 : 0 : split++;
5014 : 0 : action_n++;
5015 : 0 : break;
5016 : 0 : default:
5017 : 0 : action_n++;
5018 : 0 : break;
5019 : : }
5020 : : }
5021 [ # # ]: 0 : if (split && queue_action)
5022 : 0 : return action_n;
5023 : : return 0;
5024 : : }
5025 : :
5026 : : int
5027 : 0 : flow_dv_mreg_match_cb(void *tool_ctx __rte_unused,
5028 : : struct mlx5_list_entry *entry, void *cb_ctx)
5029 : : {
5030 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
5031 : : struct mlx5_flow_mreg_copy_resource *mcp_res =
5032 : : container_of(entry, typeof(*mcp_res), hlist_ent);
5033 : :
5034 : 0 : return mcp_res->mark_id != *(uint32_t *)(ctx->data);
5035 : : }
5036 : :
5037 : : struct mlx5_list_entry *
5038 : 0 : flow_dv_mreg_create_cb(void *tool_ctx, void *cb_ctx)
5039 : : {
5040 : : struct rte_eth_dev *dev = tool_ctx;
5041 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5042 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
5043 : : struct mlx5_flow_mreg_copy_resource *mcp_res;
5044 : 0 : struct rte_flow_error *error = ctx->error;
5045 : 0 : uint32_t idx = 0;
5046 : : int ret;
5047 : 0 : uint32_t mark_id = *(uint32_t *)(ctx->data);
5048 : 0 : struct rte_flow_attr attr = {
5049 : : .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
5050 : : .ingress = 1,
5051 : : };
5052 : 0 : struct mlx5_rte_flow_item_tag tag_spec = {
5053 : : .data = mark_id,
5054 : : };
5055 : 0 : struct rte_flow_item items[] = {
5056 : : [1] = { .type = RTE_FLOW_ITEM_TYPE_END, },
5057 : : };
5058 : 0 : struct rte_flow_action_mark ftag = {
5059 : : .id = mark_id,
5060 : : };
5061 : 0 : struct mlx5_flow_action_copy_mreg cp_mreg = {
5062 : : .dst = REG_B,
5063 : : .src = REG_NON,
5064 : : };
5065 : 0 : struct rte_flow_action_jump jump = {
5066 : : .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
5067 : : };
5068 : 0 : struct rte_flow_action actions[] = {
5069 : : [3] = { .type = RTE_FLOW_ACTION_TYPE_END, },
5070 : : };
5071 : :
5072 : : /* Fill the register fields in the flow. */
5073 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
5074 [ # # ]: 0 : if (ret < 0)
5075 : : return NULL;
5076 : 0 : tag_spec.id = ret;
5077 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
5078 [ # # ]: 0 : if (ret < 0)
5079 : : return NULL;
5080 : 0 : cp_mreg.src = ret;
5081 : : /* Provide the full width of FLAG specific value. */
5082 [ # # ]: 0 : if (mark_id == (priv->sh->dv_regc0_mask & MLX5_FLOW_MARK_DEFAULT))
5083 : 0 : tag_spec.data = MLX5_FLOW_MARK_DEFAULT;
5084 : : /* Build a new flow. */
5085 [ # # ]: 0 : if (mark_id != MLX5_DEFAULT_COPY_ID) {
5086 : 0 : items[0] = (struct rte_flow_item){
5087 : : .type = (enum rte_flow_item_type)
5088 : : MLX5_RTE_FLOW_ITEM_TYPE_TAG,
5089 : : .spec = &tag_spec,
5090 : : };
5091 : 0 : items[1] = (struct rte_flow_item){
5092 : : .type = RTE_FLOW_ITEM_TYPE_END,
5093 : : };
5094 : 0 : actions[0] = (struct rte_flow_action){
5095 : : .type = (enum rte_flow_action_type)
5096 : : MLX5_RTE_FLOW_ACTION_TYPE_MARK,
5097 : : .conf = &ftag,
5098 : : };
5099 : 0 : actions[1] = (struct rte_flow_action){
5100 : : .type = (enum rte_flow_action_type)
5101 : : MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5102 : : .conf = &cp_mreg,
5103 : : };
5104 : 0 : actions[2] = (struct rte_flow_action){
5105 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
5106 : : .conf = &jump,
5107 : : };
5108 : 0 : actions[3] = (struct rte_flow_action){
5109 : : .type = RTE_FLOW_ACTION_TYPE_END,
5110 : : };
5111 : : } else {
5112 : : /* Default rule, wildcard match. */
5113 : 0 : attr.priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR;
5114 : 0 : items[0] = (struct rte_flow_item){
5115 : : .type = RTE_FLOW_ITEM_TYPE_END,
5116 : : };
5117 : 0 : actions[0] = (struct rte_flow_action){
5118 : : .type = (enum rte_flow_action_type)
5119 : : MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5120 : : .conf = &cp_mreg,
5121 : : };
5122 : 0 : actions[1] = (struct rte_flow_action){
5123 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
5124 : : .conf = &jump,
5125 : : };
5126 : 0 : actions[2] = (struct rte_flow_action){
5127 : : .type = RTE_FLOW_ACTION_TYPE_END,
5128 : : };
5129 : : }
5130 : : /* Build a new entry. */
5131 : 0 : mcp_res = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
5132 [ # # ]: 0 : if (!mcp_res) {
5133 : 0 : rte_errno = ENOMEM;
5134 : 0 : return NULL;
5135 : : }
5136 : 0 : mcp_res->idx = idx;
5137 : 0 : mcp_res->mark_id = mark_id;
5138 : : /*
5139 : : * The copy Flows are not included in any list. There
5140 : : * ones are referenced from other Flows and can not
5141 : : * be applied, removed, deleted in arbitrary order
5142 : : * by list traversing.
5143 : : */
5144 : 0 : mcp_res->rix_flow = mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_MCP,
5145 : : &attr, items, actions, false, error);
5146 [ # # ]: 0 : if (!mcp_res->rix_flow) {
5147 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], idx);
5148 : 0 : return NULL;
5149 : : }
5150 : 0 : return &mcp_res->hlist_ent;
5151 : : }
5152 : :
5153 : : struct mlx5_list_entry *
5154 : 0 : flow_dv_mreg_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
5155 : : void *cb_ctx __rte_unused)
5156 : : {
5157 : : struct rte_eth_dev *dev = tool_ctx;
5158 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5159 : : struct mlx5_flow_mreg_copy_resource *mcp_res;
5160 : 0 : uint32_t idx = 0;
5161 : :
5162 : 0 : mcp_res = mlx5_ipool_malloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
5163 [ # # ]: 0 : if (!mcp_res) {
5164 : 0 : rte_errno = ENOMEM;
5165 : 0 : return NULL;
5166 : : }
5167 : : memcpy(mcp_res, oentry, sizeof(*mcp_res));
5168 : 0 : mcp_res->idx = idx;
5169 : 0 : return &mcp_res->hlist_ent;
5170 : : }
5171 : :
5172 : : void
5173 : 0 : flow_dv_mreg_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
5174 : : {
5175 : : struct mlx5_flow_mreg_copy_resource *mcp_res =
5176 : : container_of(entry, typeof(*mcp_res), hlist_ent);
5177 : : struct rte_eth_dev *dev = tool_ctx;
5178 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5179 : :
5180 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
5181 : 0 : }
5182 : :
5183 : : /**
5184 : : * Add a flow of copying flow metadata registers in RX_CP_TBL.
5185 : : *
5186 : : * As mark_id is unique, if there's already a registered flow for the mark_id,
5187 : : * return by increasing the reference counter of the resource. Otherwise, create
5188 : : * the resource (mcp_res) and flow.
5189 : : *
5190 : : * Flow looks like,
5191 : : * - If ingress port is ANY and reg_c[1] is mark_id,
5192 : : * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
5193 : : *
5194 : : * For default flow (zero mark_id), flow is like,
5195 : : * - If ingress port is ANY,
5196 : : * reg_b := reg_c[0] and jump to RX_ACT_TBL.
5197 : : *
5198 : : * @param dev
5199 : : * Pointer to Ethernet device.
5200 : : * @param mark_id
5201 : : * ID of MARK action, zero means default flow for META.
5202 : : * @param[out] error
5203 : : * Perform verbose error reporting if not NULL.
5204 : : *
5205 : : * @return
5206 : : * Associated resource on success, NULL otherwise and rte_errno is set.
5207 : : */
5208 : : static struct mlx5_flow_mreg_copy_resource *
5209 : 0 : flow_mreg_add_copy_action(struct rte_eth_dev *dev, uint32_t mark_id,
5210 : : struct rte_flow_error *error)
5211 : : {
5212 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5213 : : struct mlx5_list_entry *entry;
5214 : 0 : struct mlx5_flow_cb_ctx ctx = {
5215 : : .dev = dev,
5216 : : .error = error,
5217 : : .data = &mark_id,
5218 : : };
5219 : :
5220 : : /* Check if already registered. */
5221 : : MLX5_ASSERT(priv->sh->mreg_cp_tbl);
5222 : 0 : entry = mlx5_hlist_register(priv->sh->mreg_cp_tbl, mark_id, &ctx);
5223 [ # # ]: 0 : if (!entry)
5224 : 0 : return NULL;
5225 : : return container_of(entry, struct mlx5_flow_mreg_copy_resource,
5226 : : hlist_ent);
5227 : : }
5228 : :
5229 : : void
5230 : 0 : flow_dv_mreg_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
5231 : : {
5232 : : struct mlx5_flow_mreg_copy_resource *mcp_res =
5233 : : container_of(entry, typeof(*mcp_res), hlist_ent);
5234 : : struct rte_eth_dev *dev = tool_ctx;
5235 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5236 : :
5237 : : MLX5_ASSERT(mcp_res->rix_flow);
5238 : 0 : mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_MCP, mcp_res->rix_flow);
5239 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
5240 : 0 : }
5241 : :
5242 : : /**
5243 : : * Release flow in RX_CP_TBL.
5244 : : *
5245 : : * @param dev
5246 : : * Pointer to Ethernet device.
5247 : : * @flow
5248 : : * Parent flow for wich copying is provided.
5249 : : */
5250 : : static void
5251 : 0 : flow_mreg_del_copy_action(struct rte_eth_dev *dev,
5252 : : struct rte_flow *flow)
5253 : : {
5254 : : struct mlx5_flow_mreg_copy_resource *mcp_res;
5255 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5256 : :
5257 [ # # ]: 0 : if (!flow->rix_mreg_copy)
5258 : : return;
5259 : 0 : mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
5260 : : flow->rix_mreg_copy);
5261 [ # # # # ]: 0 : if (!mcp_res || !priv->sh->mreg_cp_tbl)
5262 : : return;
5263 : : MLX5_ASSERT(mcp_res->rix_flow);
5264 : 0 : mlx5_hlist_unregister(priv->sh->mreg_cp_tbl, &mcp_res->hlist_ent);
5265 : 0 : flow->rix_mreg_copy = 0;
5266 : : }
5267 : :
5268 : : /**
5269 : : * Remove the default copy action from RX_CP_TBL.
5270 : : *
5271 : : * This functions is called in the mlx5_dev_start(). No thread safe
5272 : : * is guaranteed.
5273 : : *
5274 : : * @param dev
5275 : : * Pointer to Ethernet device.
5276 : : */
5277 : : static void
5278 : 0 : flow_mreg_del_default_copy_action(struct rte_eth_dev *dev)
5279 : : {
5280 : : struct mlx5_list_entry *entry;
5281 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5282 : : struct mlx5_flow_cb_ctx ctx;
5283 : : uint32_t mark_id;
5284 : :
5285 : : /* Check if default flow is registered. */
5286 [ # # ]: 0 : if (!priv->sh->mreg_cp_tbl)
5287 : 0 : return;
5288 : 0 : mark_id = MLX5_DEFAULT_COPY_ID;
5289 : 0 : ctx.data = &mark_id;
5290 : 0 : entry = mlx5_hlist_lookup(priv->sh->mreg_cp_tbl, mark_id, &ctx);
5291 [ # # ]: 0 : if (!entry)
5292 : : return;
5293 : 0 : mlx5_hlist_unregister(priv->sh->mreg_cp_tbl, entry);
5294 : : }
5295 : :
5296 : : /**
5297 : : * Add the default copy action in RX_CP_TBL.
5298 : : *
5299 : : * This functions is called in the mlx5_dev_start(). No thread safe
5300 : : * is guaranteed.
5301 : : *
5302 : : * @param dev
5303 : : * Pointer to Ethernet device.
5304 : : * @param[out] error
5305 : : * Perform verbose error reporting if not NULL.
5306 : : *
5307 : : * @return
5308 : : * 0 for success, negative value otherwise and rte_errno is set.
5309 : : */
5310 : : static int
5311 : 0 : flow_mreg_add_default_copy_action(struct rte_eth_dev *dev,
5312 : : struct rte_flow_error *error)
5313 : : {
5314 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5315 : : struct mlx5_flow_mreg_copy_resource *mcp_res;
5316 : : struct mlx5_flow_cb_ctx ctx;
5317 : : uint32_t mark_id;
5318 : :
5319 : : /* Check whether extensive metadata feature is engaged. */
5320 [ # # ]: 0 : if (!priv->sh->config.dv_flow_en ||
5321 [ # # # # ]: 0 : priv->sh->config.dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
5322 : 0 : !mlx5_flow_ext_mreg_supported(dev) ||
5323 [ # # ]: 0 : !priv->sh->dv_regc0_mask)
5324 : 0 : return 0;
5325 : : /*
5326 : : * Add default mreg copy flow may be called multiple time, but
5327 : : * only be called once in stop. Avoid register it twice.
5328 : : */
5329 : 0 : mark_id = MLX5_DEFAULT_COPY_ID;
5330 : 0 : ctx.data = &mark_id;
5331 [ # # ]: 0 : if (mlx5_hlist_lookup(priv->sh->mreg_cp_tbl, mark_id, &ctx))
5332 : : return 0;
5333 : 0 : mcp_res = flow_mreg_add_copy_action(dev, mark_id, error);
5334 [ # # ]: 0 : if (!mcp_res)
5335 : 0 : return -rte_errno;
5336 : : return 0;
5337 : : }
5338 : :
5339 : : /**
5340 : : * Add a flow of copying flow metadata registers in RX_CP_TBL.
5341 : : *
5342 : : * All the flow having Q/RSS action should be split by
5343 : : * flow_mreg_split_qrss_prep() to pass by RX_CP_TBL. A flow in the RX_CP_TBL
5344 : : * performs the following,
5345 : : * - CQE->flow_tag := reg_c[1] (MARK)
5346 : : * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
5347 : : * As CQE's flow_tag is not a register, it can't be simply copied from reg_c[1]
5348 : : * but there should be a flow per each MARK ID set by MARK action.
5349 : : *
5350 : : * For the aforementioned reason, if there's a MARK action in flow's action
5351 : : * list, a corresponding flow should be added to the RX_CP_TBL in order to copy
5352 : : * the MARK ID to CQE's flow_tag like,
5353 : : * - If reg_c[1] is mark_id,
5354 : : * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
5355 : : *
5356 : : * For SET_META action which stores value in reg_c[0], as the destination is
5357 : : * also a flow metadata register (reg_b), adding a default flow is enough. Zero
5358 : : * MARK ID means the default flow. The default flow looks like,
5359 : : * - For all flow, reg_b := reg_c[0] and jump to RX_ACT_TBL.
5360 : : *
5361 : : * @param dev
5362 : : * Pointer to Ethernet device.
5363 : : * @param flow
5364 : : * Pointer to flow structure.
5365 : : * @param[in] actions
5366 : : * Pointer to the list of actions.
5367 : : * @param[out] error
5368 : : * Perform verbose error reporting if not NULL.
5369 : : *
5370 : : * @return
5371 : : * 0 on success, negative value otherwise and rte_errno is set.
5372 : : */
5373 : : static int
5374 : 0 : flow_mreg_update_copy_table(struct rte_eth_dev *dev,
5375 : : struct rte_flow *flow,
5376 : : const struct rte_flow_action *actions,
5377 : : struct rte_flow_error *error)
5378 : : {
5379 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5380 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
5381 : : struct mlx5_flow_mreg_copy_resource *mcp_res;
5382 : : const struct rte_flow_action_mark *mark;
5383 : :
5384 : : /* Check whether extensive metadata feature is engaged. */
5385 [ # # ]: 0 : if (!config->dv_flow_en ||
5386 [ # # # # ]: 0 : config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
5387 : 0 : !mlx5_flow_ext_mreg_supported(dev) ||
5388 [ # # ]: 0 : !priv->sh->dv_regc0_mask)
5389 : 0 : return 0;
5390 : : /* Find MARK action. */
5391 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
5392 [ # # # ]: 0 : switch (actions->type) {
5393 : 0 : case RTE_FLOW_ACTION_TYPE_FLAG:
5394 : 0 : mcp_res = flow_mreg_add_copy_action
5395 : : (dev, MLX5_FLOW_MARK_DEFAULT, error);
5396 [ # # ]: 0 : if (!mcp_res)
5397 : 0 : return -rte_errno;
5398 : 0 : flow->rix_mreg_copy = mcp_res->idx;
5399 : 0 : return 0;
5400 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
5401 : 0 : mark = (const struct rte_flow_action_mark *)
5402 : : actions->conf;
5403 : : mcp_res =
5404 : 0 : flow_mreg_add_copy_action(dev, mark->id, error);
5405 [ # # ]: 0 : if (!mcp_res)
5406 : 0 : return -rte_errno;
5407 : 0 : flow->rix_mreg_copy = mcp_res->idx;
5408 : 0 : return 0;
5409 : : default:
5410 : : break;
5411 : : }
5412 : : }
5413 : : return 0;
5414 : : }
5415 : :
5416 : : #define MLX5_MAX_SPLIT_ACTIONS 24
5417 : : #define MLX5_MAX_SPLIT_ITEMS 24
5418 : :
5419 : : /**
5420 : : * Split the hairpin flow.
5421 : : * Since HW can't support encap and push-vlan on Rx, we move these
5422 : : * actions to Tx.
5423 : : * If the count action is after the encap then we also
5424 : : * move the count action. in this case the count will also measure
5425 : : * the outer bytes.
5426 : : *
5427 : : * @param dev
5428 : : * Pointer to Ethernet device.
5429 : : * @param[in] actions
5430 : : * Associated actions (list terminated by the END action).
5431 : : * @param[out] actions_rx
5432 : : * Rx flow actions.
5433 : : * @param[out] actions_tx
5434 : : * Tx flow actions..
5435 : : * @param[out] pattern_tx
5436 : : * The pattern items for the Tx flow.
5437 : : * @param[out] flow_id
5438 : : * The flow ID connected to this flow.
5439 : : *
5440 : : * @return
5441 : : * 0 on success.
5442 : : */
5443 : : static int
5444 : 0 : flow_hairpin_split(struct rte_eth_dev *dev,
5445 : : const struct rte_flow_action actions[],
5446 : : struct rte_flow_action actions_rx[],
5447 : : struct rte_flow_action actions_tx[],
5448 : : struct rte_flow_item pattern_tx[],
5449 : : uint32_t flow_id)
5450 : : {
5451 : : const struct rte_flow_action_raw_encap *raw_encap;
5452 : : const struct rte_flow_action_raw_decap *raw_decap;
5453 : : struct mlx5_rte_flow_action_set_tag *set_tag;
5454 : : struct rte_flow_action *tag_action;
5455 : : struct mlx5_rte_flow_item_tag *tag_item;
5456 : : struct rte_flow_item *item;
5457 : : char *addr;
5458 : : int push_vlan = 0;
5459 : : int encap = 0;
5460 : :
5461 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
5462 [ # # ]: 0 : if (actions->type == RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN)
5463 : : push_vlan = 1;
5464 [ # # # # : 0 : switch (actions->type) {
# # ]
5465 : : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
5466 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
5467 : : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
5468 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
5469 : : rte_memcpy(actions_tx, actions,
5470 : : sizeof(struct rte_flow_action));
5471 : 0 : actions_tx++;
5472 : 0 : break;
5473 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
5474 [ # # ]: 0 : if (push_vlan) {
5475 : : rte_memcpy(actions_tx, actions,
5476 : : sizeof(struct rte_flow_action));
5477 : 0 : actions_tx++;
5478 : : } else {
5479 : : rte_memcpy(actions_rx, actions,
5480 : : sizeof(struct rte_flow_action));
5481 : 0 : actions_rx++;
5482 : : }
5483 : : break;
5484 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
5485 : : case RTE_FLOW_ACTION_TYPE_AGE:
5486 [ # # ]: 0 : if (encap) {
5487 : : rte_memcpy(actions_tx, actions,
5488 : : sizeof(struct rte_flow_action));
5489 : 0 : actions_tx++;
5490 : : } else {
5491 : : rte_memcpy(actions_rx, actions,
5492 : : sizeof(struct rte_flow_action));
5493 : 0 : actions_rx++;
5494 : : }
5495 : : break;
5496 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
5497 : 0 : raw_encap = actions->conf;
5498 [ # # ]: 0 : if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE) {
5499 : : memcpy(actions_tx, actions,
5500 : : sizeof(struct rte_flow_action));
5501 : 0 : actions_tx++;
5502 : : encap = 1;
5503 : : } else {
5504 : : rte_memcpy(actions_rx, actions,
5505 : : sizeof(struct rte_flow_action));
5506 : 0 : actions_rx++;
5507 : : }
5508 : : break;
5509 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
5510 : 0 : raw_decap = actions->conf;
5511 [ # # ]: 0 : if (raw_decap->size < MLX5_ENCAPSULATION_DECISION_SIZE) {
5512 : : memcpy(actions_tx, actions,
5513 : : sizeof(struct rte_flow_action));
5514 : 0 : actions_tx++;
5515 : : } else {
5516 : : rte_memcpy(actions_rx, actions,
5517 : : sizeof(struct rte_flow_action));
5518 : 0 : actions_rx++;
5519 : : }
5520 : : break;
5521 : : default:
5522 : : rte_memcpy(actions_rx, actions,
5523 : : sizeof(struct rte_flow_action));
5524 : 0 : actions_rx++;
5525 : 0 : break;
5526 : : }
5527 : : }
5528 : : /* Add set meta action and end action for the Rx flow. */
5529 : : tag_action = actions_rx;
5530 : 0 : tag_action->type = (enum rte_flow_action_type)
5531 : : MLX5_RTE_FLOW_ACTION_TYPE_TAG;
5532 [ # # ]: 0 : actions_rx++;
5533 : : rte_memcpy(actions_rx, actions, sizeof(struct rte_flow_action));
5534 : 0 : actions_rx++;
5535 : : set_tag = (void *)actions_rx;
5536 : 0 : *set_tag = (struct mlx5_rte_flow_action_set_tag) {
5537 : 0 : .id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_RX, 0, NULL),
5538 : : .data = flow_id,
5539 : : };
5540 : : MLX5_ASSERT(set_tag->id > REG_NON);
5541 [ # # ]: 0 : tag_action->conf = set_tag;
5542 : : /* Create Tx item list. */
5543 : : rte_memcpy(actions_tx, actions, sizeof(struct rte_flow_action));
5544 : 0 : addr = (void *)&pattern_tx[2];
5545 : : item = pattern_tx;
5546 : 0 : item->type = (enum rte_flow_item_type)
5547 : : MLX5_RTE_FLOW_ITEM_TYPE_TAG;
5548 : : tag_item = (void *)addr;
5549 : 0 : tag_item->data = flow_id;
5550 : 0 : tag_item->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_TX, 0, NULL);
5551 : : MLX5_ASSERT(set_tag->id > REG_NON);
5552 : 0 : item->spec = tag_item;
5553 : 0 : addr += sizeof(struct mlx5_rte_flow_item_tag);
5554 : : tag_item = (void *)addr;
5555 : 0 : tag_item->data = UINT32_MAX;
5556 : 0 : tag_item->id = UINT16_MAX;
5557 : 0 : item->mask = tag_item;
5558 : 0 : item->last = NULL;
5559 : : item++;
5560 : 0 : item->type = RTE_FLOW_ITEM_TYPE_END;
5561 : 0 : return 0;
5562 : : }
5563 : :
5564 : : /**
5565 : : * The last stage of splitting chain, just creates the subflow
5566 : : * without any modification.
5567 : : *
5568 : : * @param[in] dev
5569 : : * Pointer to Ethernet device.
5570 : : * @param[in] flow
5571 : : * Parent flow structure pointer.
5572 : : * @param[in, out] sub_flow
5573 : : * Pointer to return the created subflow, may be NULL.
5574 : : * @param[in] attr
5575 : : * Flow rule attributes.
5576 : : * @param[in] items
5577 : : * Pattern specification (list terminated by the END pattern item).
5578 : : * @param[in] actions
5579 : : * Associated actions (list terminated by the END action).
5580 : : * @param[in] flow_split_info
5581 : : * Pointer to flow split info structure.
5582 : : * @param[out] error
5583 : : * Perform verbose error reporting if not NULL.
5584 : : * @return
5585 : : * 0 on success, negative value otherwise
5586 : : */
5587 : : static int
5588 : 0 : flow_create_split_inner(struct rte_eth_dev *dev,
5589 : : struct rte_flow *flow,
5590 : : struct mlx5_flow **sub_flow,
5591 : : const struct rte_flow_attr *attr,
5592 : : const struct rte_flow_item items[],
5593 : : const struct rte_flow_action actions[],
5594 : : struct mlx5_flow_split_info *flow_split_info,
5595 : : struct rte_flow_error *error)
5596 : : {
5597 : : struct mlx5_flow *dev_flow;
5598 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
5599 : :
5600 : 0 : dev_flow = flow_drv_prepare(dev, flow, attr, items, actions,
5601 : : flow_split_info->flow_idx, error);
5602 [ # # ]: 0 : if (!dev_flow)
5603 : 0 : return -rte_errno;
5604 : 0 : dev_flow->flow = flow;
5605 : 0 : dev_flow->external = flow_split_info->external;
5606 : 0 : dev_flow->skip_scale = flow_split_info->skip_scale;
5607 : : /* Subflow object was created, we must include one in the list. */
5608 : 0 : SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
5609 : : dev_flow->handle, next);
5610 : : /*
5611 : : * If dev_flow is as one of the suffix flow, some actions in suffix
5612 : : * flow may need some user defined item layer flags, and pass the
5613 : : * Metadata rxq mark flag to suffix flow as well.
5614 : : */
5615 [ # # ]: 0 : if (flow_split_info->prefix_layers)
5616 : 0 : dev_flow->handle->layers = flow_split_info->prefix_layers;
5617 [ # # ]: 0 : if (flow_split_info->prefix_mark) {
5618 : : MLX5_ASSERT(wks);
5619 : 0 : wks->mark = 1;
5620 : : }
5621 [ # # ]: 0 : if (sub_flow)
5622 : 0 : *sub_flow = dev_flow;
5623 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
5624 : 0 : dev_flow->dv.table_id = flow_split_info->table_id;
5625 : : #endif
5626 : 0 : return flow_drv_translate(dev, dev_flow, attr, items, actions, error);
5627 : : }
5628 : :
5629 : : /**
5630 : : * Get the sub policy of a meter.
5631 : : *
5632 : : * @param[in] dev
5633 : : * Pointer to Ethernet device.
5634 : : * @param[in] flow
5635 : : * Parent flow structure pointer.
5636 : : * @param wks
5637 : : * Pointer to thread flow work space.
5638 : : * @param[in] attr
5639 : : * Flow rule attributes.
5640 : : * @param[in] items
5641 : : * Pattern specification (list terminated by the END pattern item).
5642 : : * @param[out] error
5643 : : * Perform verbose error reporting if not NULL.
5644 : : *
5645 : : * @return
5646 : : * Pointer to the meter sub policy, NULL otherwise and rte_errno is set.
5647 : : */
5648 : : static struct mlx5_flow_meter_sub_policy *
5649 : 0 : get_meter_sub_policy(struct rte_eth_dev *dev,
5650 : : struct rte_flow *flow,
5651 : : struct mlx5_flow_workspace *wks,
5652 : : const struct rte_flow_attr *attr,
5653 : : const struct rte_flow_item items[],
5654 : : struct rte_flow_error *error)
5655 : : {
5656 : : struct mlx5_flow_meter_policy *policy;
5657 : : struct mlx5_flow_meter_policy *final_policy;
5658 : : struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
5659 : :
5660 : 0 : policy = wks->policy;
5661 [ # # ]: 0 : final_policy = policy->is_hierarchy ? wks->final_policy : policy;
5662 [ # # ]: 0 : if (final_policy->is_rss || final_policy->is_queue) {
5663 : : struct mlx5_flow_rss_desc rss_desc_v[MLX5_MTR_RTE_COLORS];
5664 : 0 : struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS] = {0};
5665 : : uint32_t i;
5666 : :
5667 : : /*
5668 : : * This is a tmp dev_flow,
5669 : : * no need to register any matcher for it in translate.
5670 : : */
5671 : 0 : wks->skip_matcher_reg = 1;
5672 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
5673 : 0 : struct mlx5_flow dev_flow = {0};
5674 : 0 : struct mlx5_flow_handle dev_handle = { {0} };
5675 : 0 : uint8_t fate = final_policy->act_cnt[i].fate_action;
5676 : :
5677 [ # # ]: 0 : if (fate == MLX5_FLOW_FATE_SHARED_RSS) {
5678 : 0 : const struct rte_flow_action_rss *rss_act =
5679 : 0 : final_policy->act_cnt[i].rss->conf;
5680 : 0 : struct rte_flow_action rss_actions[2] = {
5681 : : [0] = {
5682 : : .type = RTE_FLOW_ACTION_TYPE_RSS,
5683 : : .conf = rss_act,
5684 : : },
5685 : : [1] = {
5686 : : .type = RTE_FLOW_ACTION_TYPE_END,
5687 : : .conf = NULL,
5688 : : }
5689 : : };
5690 : :
5691 : 0 : dev_flow.handle = &dev_handle;
5692 : 0 : dev_flow.ingress = attr->ingress;
5693 : 0 : dev_flow.flow = flow;
5694 : : dev_flow.external = 0;
5695 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
5696 : 0 : dev_flow.dv.transfer = attr->transfer;
5697 : : #endif
5698 : : /**
5699 : : * Translate RSS action to get rss hash fields.
5700 : : */
5701 [ # # ]: 0 : if (flow_drv_translate(dev, &dev_flow, attr,
5702 : : items, rss_actions, error))
5703 : 0 : goto exit;
5704 : 0 : rss_desc_v[i] = wks->rss_desc;
5705 : 0 : rss_desc_v[i].symmetric_hash_function =
5706 : 0 : dev_flow.symmetric_hash_function;
5707 : 0 : rss_desc_v[i].key_len = MLX5_RSS_HASH_KEY_LEN;
5708 : 0 : rss_desc_v[i].hash_fields =
5709 : 0 : dev_flow.hash_fields;
5710 : 0 : rss_desc_v[i].queue_num =
5711 : : rss_desc_v[i].hash_fields ?
5712 [ # # ]: 0 : rss_desc_v[i].queue_num : 1;
5713 : 0 : rss_desc_v[i].tunnel =
5714 : 0 : !!(dev_flow.handle->layers &
5715 : : MLX5_FLOW_LAYER_TUNNEL);
5716 : : /* Use the RSS queues in the containers. */
5717 : 0 : rss_desc_v[i].queue =
5718 : 0 : (uint16_t *)(uintptr_t)rss_act->queue;
5719 : 0 : rss_desc[i] = &rss_desc_v[i];
5720 [ # # ]: 0 : } else if (fate == MLX5_FLOW_FATE_QUEUE) {
5721 : : /* This is queue action. */
5722 : 0 : rss_desc_v[i] = wks->rss_desc;
5723 : 0 : rss_desc_v[i].key_len = 0;
5724 : 0 : rss_desc_v[i].hash_fields = 0;
5725 : 0 : rss_desc_v[i].queue =
5726 : 0 : &final_policy->act_cnt[i].queue;
5727 : 0 : rss_desc_v[i].queue_num = 1;
5728 : 0 : rss_desc[i] = &rss_desc_v[i];
5729 : : } else {
5730 : 0 : rss_desc[i] = NULL;
5731 : : }
5732 : : }
5733 : : sub_policy = flow_drv_meter_sub_policy_rss_prepare(dev,
5734 : : flow, policy, rss_desc);
5735 : : } else {
5736 : : enum mlx5_meter_domain mtr_domain =
5737 [ # # ]: 0 : attr->transfer ? MLX5_MTR_DOMAIN_TRANSFER :
5738 : 0 : (attr->egress ? MLX5_MTR_DOMAIN_EGRESS :
5739 : : MLX5_MTR_DOMAIN_INGRESS);
5740 : 0 : sub_policy = policy->sub_policys[mtr_domain][0];
5741 : : }
5742 [ # # ]: 0 : if (!sub_policy)
5743 : 0 : rte_flow_error_set(error, EINVAL,
5744 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5745 : : "Failed to get meter sub-policy.");
5746 : 0 : exit:
5747 : 0 : return sub_policy;
5748 : : }
5749 : :
5750 : : /**
5751 : : * Split the meter flow.
5752 : : *
5753 : : * As meter flow will split to three sub flow, other than meter
5754 : : * action, the other actions make sense to only meter accepts
5755 : : * the packet. If it need to be dropped, no other additional
5756 : : * actions should be take.
5757 : : *
5758 : : * One kind of special action which decapsulates the L3 tunnel
5759 : : * header will be in the prefix sub flow, as not to take the
5760 : : * L3 tunnel header into account.
5761 : : *
5762 : : * @param[in] dev
5763 : : * Pointer to Ethernet device.
5764 : : * @param[in] flow
5765 : : * Parent flow structure pointer.
5766 : : * @param wks
5767 : : * Pointer to thread flow work space.
5768 : : * @param[in] attr
5769 : : * Flow rule attributes.
5770 : : * @param[in] items
5771 : : * Pattern specification (list terminated by the END pattern item).
5772 : : * @param[out] sfx_items
5773 : : * Suffix flow match items (list terminated by the END pattern item).
5774 : : * @param[in] actions
5775 : : * Associated actions (list terminated by the END action).
5776 : : * @param[out] actions_sfx
5777 : : * Suffix flow actions.
5778 : : * @param[out] actions_pre
5779 : : * Prefix flow actions.
5780 : : * @param[out] mtr_flow_id
5781 : : * Pointer to meter flow id.
5782 : : * @param[out] error
5783 : : * Perform verbose error reporting if not NULL.
5784 : : *
5785 : : * @return
5786 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5787 : : */
5788 : : static int
5789 : 0 : flow_meter_split_prep(struct rte_eth_dev *dev,
5790 : : struct rte_flow *flow,
5791 : : struct mlx5_flow_workspace *wks,
5792 : : const struct rte_flow_attr *attr,
5793 : : const struct rte_flow_item items[],
5794 : : struct rte_flow_item sfx_items[],
5795 : : const struct rte_flow_action actions[],
5796 : : struct rte_flow_action actions_sfx[],
5797 : : struct rte_flow_action actions_pre[],
5798 : : uint32_t *mtr_flow_id,
5799 : : struct rte_flow_error *error)
5800 : : {
5801 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5802 : 0 : struct mlx5_flow_meter_info *fm = wks->fm;
5803 : : struct rte_flow_action *tag_action = NULL;
5804 : : struct rte_flow_item *tag_item;
5805 : : struct mlx5_rte_flow_action_set_tag *set_tag;
5806 : : const struct rte_flow_action_raw_encap *raw_encap;
5807 : : const struct rte_flow_action_raw_decap *raw_decap;
5808 : : struct mlx5_rte_flow_item_tag *tag_item_spec;
5809 : : struct mlx5_rte_flow_item_tag *tag_item_mask;
5810 : 0 : uint32_t tag_id = 0;
5811 : : bool vlan_actions;
5812 : : struct rte_flow_item *orig_sfx_items = sfx_items;
5813 : : const struct rte_flow_item *orig_items = items;
5814 : : struct rte_flow_action *hw_mtr_action;
5815 : : struct rte_flow_action *action_pre_head = NULL;
5816 : 0 : uint16_t flow_src_port = priv->representor_id;
5817 : : bool mtr_first;
5818 : 0 : uint8_t mtr_id_offset = priv->mtr_reg_share ? MLX5_MTR_COLOR_BITS : 0;
5819 [ # # ]: 0 : uint8_t mtr_reg_bits = priv->mtr_reg_share ?
5820 : : MLX5_MTR_IDLE_BITS_IN_COLOR_REG : MLX5_REG_BITS;
5821 : : uint32_t flow_id = 0;
5822 : : uint32_t flow_id_reversed = 0;
5823 : : uint8_t flow_id_bits = 0;
5824 : : bool after_meter = false;
5825 : : int shift;
5826 : :
5827 : : /* Prepare the suffix subflow items. */
5828 : 0 : tag_item = sfx_items++;
5829 : 0 : tag_item->type = (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_TAG;
5830 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
5831 : : int item_type = items->type;
5832 : :
5833 [ # # # ]: 0 : switch (item_type) {
5834 : 0 : case RTE_FLOW_ITEM_TYPE_PORT_ID:
5835 : : case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
5836 : : case RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR:
5837 [ # # ]: 0 : if (mlx5_flow_get_item_vport_id(dev, items, &flow_src_port, NULL, error))
5838 : 0 : return -rte_errno;
5839 [ # # # # ]: 0 : if (!fm->def_policy && wks->policy->hierarchy_match_port &&
5840 [ # # ]: 0 : flow_src_port != priv->representor_id) {
5841 [ # # ]: 0 : if (flow_drv_mtr_hierarchy_rule_create(dev,
5842 : : flow, fm,
5843 : : flow_src_port,
5844 : : items,
5845 : : error))
5846 : 0 : return -rte_errno;
5847 : : }
5848 : : memcpy(sfx_items, items, sizeof(*sfx_items));
5849 : 0 : sfx_items++;
5850 : 0 : break;
5851 : : case RTE_FLOW_ITEM_TYPE_VLAN:
5852 : : /*
5853 : : * Copy VLAN items in case VLAN actions are performed.
5854 : : * If there are no VLAN actions, these items will be VOID.
5855 : : */
5856 : : memcpy(sfx_items, items, sizeof(*sfx_items));
5857 : 0 : sfx_items->type = (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_VLAN;
5858 : 0 : sfx_items++;
5859 : 0 : break;
5860 : : default:
5861 : : break;
5862 : : }
5863 : : }
5864 : 0 : sfx_items->type = RTE_FLOW_ITEM_TYPE_END;
5865 : 0 : sfx_items++;
5866 [ # # ]: 0 : mtr_first = priv->sh->meter_aso_en &&
5867 [ # # # # : 0 : (attr->egress || (attr->transfer && flow_src_port != UINT16_MAX));
# # ]
5868 : : /* For ASO meter, meter must be before tag in TX direction. */
5869 [ # # ]: 0 : if (mtr_first) {
5870 : 0 : action_pre_head = actions_pre++;
5871 : : /* Leave space for tag action. */
5872 : 0 : tag_action = actions_pre++;
5873 : : }
5874 : : /* Prepare the actions for prefix and suffix flow. */
5875 : : vlan_actions = false;
5876 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
5877 : : struct rte_flow_action *action_cur = NULL;
5878 : :
5879 [ # # # # : 0 : switch (actions->type) {
# # # ]
5880 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
5881 [ # # ]: 0 : if (mtr_first) {
5882 : : action_cur = action_pre_head;
5883 : : } else {
5884 : : /* Leave space for tag action. */
5885 : 0 : tag_action = actions_pre++;
5886 : 0 : action_cur = actions_pre++;
5887 : : }
5888 : : after_meter = true;
5889 : : break;
5890 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
5891 : : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
5892 : 0 : action_cur = actions_pre++;
5893 : 0 : break;
5894 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
5895 : 0 : raw_encap = actions->conf;
5896 [ # # ]: 0 : if (raw_encap->size < MLX5_ENCAPSULATION_DECISION_SIZE)
5897 : 0 : action_cur = actions_pre++;
5898 : : break;
5899 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
5900 : 0 : raw_decap = actions->conf;
5901 [ # # ]: 0 : if (raw_decap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
5902 : 0 : action_cur = actions_pre++;
5903 : : break;
5904 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
5905 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
5906 : : vlan_actions = true;
5907 : 0 : break;
5908 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
5909 [ # # ]: 0 : if (fm->def_policy)
5910 : : action_cur = after_meter ?
5911 [ # # ]: 0 : actions_sfx++ : actions_pre++;
5912 : : break;
5913 : : default:
5914 : : break;
5915 : : }
5916 [ # # ]: 0 : if (!action_cur)
5917 : 0 : action_cur = (fm->def_policy) ?
5918 [ # # ]: 0 : actions_sfx++ : actions_pre++;
5919 : : memcpy(action_cur, actions, sizeof(struct rte_flow_action));
5920 : : }
5921 : : /* If there are no VLAN actions, convert VLAN items to VOID in suffix flow items. */
5922 [ # # ]: 0 : if (!vlan_actions) {
5923 : : struct rte_flow_item *it = orig_sfx_items;
5924 : :
5925 [ # # ]: 0 : for (; it->type != RTE_FLOW_ITEM_TYPE_END; it++)
5926 [ # # ]: 0 : if (it->type == (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_VLAN)
5927 : 0 : it->type = RTE_FLOW_ITEM_TYPE_VOID;
5928 : : }
5929 : : /* Add end action to the actions. */
5930 : 0 : actions_sfx->type = RTE_FLOW_ACTION_TYPE_END;
5931 [ # # ]: 0 : if (priv->sh->meter_aso_en) {
5932 : : /**
5933 : : * For ASO meter, need to add an extra jump action explicitly,
5934 : : * to jump from meter to policer table.
5935 : : */
5936 : : struct mlx5_flow_meter_sub_policy *sub_policy;
5937 : : struct mlx5_flow_tbl_data_entry *tbl_data;
5938 : :
5939 [ # # ]: 0 : if (!fm->def_policy) {
5940 : 0 : sub_policy = get_meter_sub_policy(dev, flow, wks,
5941 : : attr, orig_items,
5942 : : error);
5943 [ # # ]: 0 : if (!sub_policy)
5944 : 0 : return -rte_errno;
5945 : : } else {
5946 : : enum mlx5_meter_domain mtr_domain =
5947 [ # # ]: 0 : attr->transfer ? MLX5_MTR_DOMAIN_TRANSFER :
5948 : 0 : (attr->egress ? MLX5_MTR_DOMAIN_EGRESS :
5949 : : MLX5_MTR_DOMAIN_INGRESS);
5950 : :
5951 : 0 : sub_policy =
5952 : 0 : &priv->sh->mtrmng->def_policy[mtr_domain]->sub_policy;
5953 : : }
5954 : 0 : tbl_data = container_of(sub_policy->tbl_rsc,
5955 : : struct mlx5_flow_tbl_data_entry, tbl);
5956 : 0 : hw_mtr_action = actions_pre++;
5957 : 0 : hw_mtr_action->type = (enum rte_flow_action_type)
5958 : : MLX5_RTE_FLOW_ACTION_TYPE_JUMP;
5959 : 0 : hw_mtr_action->conf = tbl_data->jump.action;
5960 : : }
5961 : 0 : actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
5962 : 0 : actions_pre++;
5963 [ # # ]: 0 : if (!tag_action)
5964 : 0 : return rte_flow_error_set(error, ENOMEM,
5965 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5966 : : NULL, "No tag action space.");
5967 [ # # ]: 0 : if (!mtr_flow_id) {
5968 : 0 : tag_action->type = RTE_FLOW_ACTION_TYPE_VOID;
5969 : 0 : goto exit;
5970 : : }
5971 : : /* Only default-policy Meter creates mtr flow id. */
5972 [ # # ]: 0 : if (fm->def_policy) {
5973 : 0 : mlx5_ipool_malloc(fm->flow_ipool, &tag_id);
5974 [ # # ]: 0 : if (!tag_id)
5975 : 0 : return rte_flow_error_set(error, ENOMEM,
5976 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5977 : : "Failed to allocate meter flow id.");
5978 : 0 : flow_id = tag_id - 1;
5979 [ # # ]: 0 : flow_id_bits = (!flow_id) ? 1 :
5980 : 0 : (MLX5_REG_BITS - rte_clz32(flow_id));
5981 [ # # ]: 0 : if ((flow_id_bits + priv->sh->mtrmng->max_mtr_bits) >
5982 : : mtr_reg_bits) {
5983 : 0 : mlx5_ipool_free(fm->flow_ipool, tag_id);
5984 : 0 : return rte_flow_error_set(error, EINVAL,
5985 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5986 : : "Meter flow id exceeds max limit.");
5987 : : }
5988 [ # # ]: 0 : if (flow_id_bits > priv->sh->mtrmng->max_mtr_flow_bits)
5989 : 0 : priv->sh->mtrmng->max_mtr_flow_bits = flow_id_bits;
5990 : : }
5991 : : /* Build tag actions and items for meter_id/meter flow_id. */
5992 : : set_tag = (struct mlx5_rte_flow_action_set_tag *)actions_pre;
5993 : : tag_item_spec = (struct mlx5_rte_flow_item_tag *)sfx_items;
5994 : 0 : tag_item_mask = tag_item_spec + 1;
5995 : : /* Both flow_id and meter_id share the same register. */
5996 : 0 : *set_tag = (struct mlx5_rte_flow_action_set_tag) {
5997 : 0 : .id = (enum modify_reg)mlx5_flow_get_reg_id(dev, MLX5_MTR_ID,
5998 : : 0, error),
5999 : : .offset = mtr_id_offset,
6000 : : .length = mtr_reg_bits,
6001 : 0 : .data = flow->meter,
6002 : : };
6003 : : /*
6004 : : * The color Reg bits used by flow_id are growing from
6005 : : * msb to lsb, so must do bit reverse for flow_id val in RegC.
6006 : : */
6007 [ # # ]: 0 : for (shift = 0; shift < flow_id_bits; shift++)
6008 : 0 : flow_id_reversed = (flow_id_reversed << 1) |
6009 : 0 : ((flow_id >> shift) & 0x1);
6010 : 0 : set_tag->data |=
6011 : 0 : flow_id_reversed << (mtr_reg_bits - flow_id_bits);
6012 : 0 : tag_item_spec->id = set_tag->id;
6013 : 0 : tag_item_spec->data = set_tag->data << mtr_id_offset;
6014 : 0 : tag_item_mask->data = UINT32_MAX << mtr_id_offset;
6015 : 0 : tag_action->type = (enum rte_flow_action_type)
6016 : : MLX5_RTE_FLOW_ACTION_TYPE_TAG;
6017 : 0 : tag_action->conf = set_tag;
6018 : 0 : tag_item->spec = tag_item_spec;
6019 : 0 : tag_item->last = NULL;
6020 : 0 : tag_item->mask = tag_item_mask;
6021 : 0 : exit:
6022 [ # # ]: 0 : if (mtr_flow_id)
6023 : 0 : *mtr_flow_id = tag_id;
6024 : : return 0;
6025 : : }
6026 : :
6027 : : /**
6028 : : * Split action list having QUEUE/RSS for metadata register copy.
6029 : : *
6030 : : * Once Q/RSS action is detected in user's action list, the flow action
6031 : : * should be split in order to copy metadata registers, which will happen in
6032 : : * RX_CP_TBL like,
6033 : : * - CQE->flow_tag := reg_c[1] (MARK)
6034 : : * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
6035 : : * The Q/RSS action will be performed on RX_ACT_TBL after passing by RX_CP_TBL.
6036 : : * This is because the last action of each flow must be a terminal action
6037 : : * (QUEUE, RSS or DROP).
6038 : : *
6039 : : * Flow ID must be allocated to identify actions in the RX_ACT_TBL and it is
6040 : : * stored and kept in the mlx5_flow structure per each sub_flow.
6041 : : *
6042 : : * The Q/RSS action is replaced with,
6043 : : * - SET_TAG, setting the allocated flow ID to reg_c[2].
6044 : : * And the following JUMP action is added at the end,
6045 : : * - JUMP, to RX_CP_TBL.
6046 : : *
6047 : : * A flow to perform remained Q/RSS action will be created in RX_ACT_TBL by
6048 : : * flow_create_split_metadata() routine. The flow will look like,
6049 : : * - If flow ID matches (reg_c[2]), perform Q/RSS.
6050 : : *
6051 : : * @param dev
6052 : : * Pointer to Ethernet device.
6053 : : * @param[out] split_actions
6054 : : * Pointer to store split actions to jump to CP_TBL.
6055 : : * @param[in] actions
6056 : : * Pointer to the list of original flow actions.
6057 : : * @param[in] qrss
6058 : : * Pointer to the Q/RSS action.
6059 : : * @param[in] actions_n
6060 : : * Number of original actions.
6061 : : * @param[in] mtr_sfx
6062 : : * Check if it is in meter suffix table.
6063 : : * @param[out] error
6064 : : * Perform verbose error reporting if not NULL.
6065 : : *
6066 : : * @return
6067 : : * non-zero unique flow_id on success, otherwise 0 and
6068 : : * error/rte_error are set.
6069 : : */
6070 : : static uint32_t
6071 : 0 : flow_mreg_split_qrss_prep(struct rte_eth_dev *dev,
6072 : : struct rte_flow_action *split_actions,
6073 : : const struct rte_flow_action *actions,
6074 : : const struct rte_flow_action *qrss,
6075 : : int actions_n, int mtr_sfx,
6076 : : struct rte_flow_error *error)
6077 : : {
6078 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6079 : : struct mlx5_rte_flow_action_set_tag *set_tag;
6080 : : struct rte_flow_action_jump *jump;
6081 : 0 : const int qrss_idx = qrss - actions;
6082 : 0 : uint32_t flow_id = 0;
6083 : : int ret = 0;
6084 : :
6085 : : /*
6086 : : * Given actions will be split
6087 : : * - Replace QUEUE/RSS action with SET_TAG to set flow ID.
6088 : : * - Add jump to mreg CP_TBL.
6089 : : * As a result, there will be one more action.
6090 : : */
6091 [ # # ]: 0 : memcpy(split_actions, actions, sizeof(*split_actions) * actions_n);
6092 : : /* Count MLX5_RTE_FLOW_ACTION_TYPE_TAG. */
6093 : 0 : ++actions_n;
6094 : 0 : set_tag = (void *)(split_actions + actions_n);
6095 : : /*
6096 : : * If we are not the meter suffix flow, add the tag action.
6097 : : * Since meter suffix flow already has the tag added.
6098 : : */
6099 [ # # ]: 0 : if (!mtr_sfx) {
6100 : : /*
6101 : : * Allocate the new subflow ID. This one is unique within
6102 : : * device and not shared with representors. Otherwise,
6103 : : * we would have to resolve multi-thread access synch
6104 : : * issue. Each flow on the shared device is appended
6105 : : * with source vport identifier, so the resulting
6106 : : * flows will be unique in the shared (by master and
6107 : : * representors) domain even if they have coinciding
6108 : : * IDs.
6109 : : */
6110 : 0 : mlx5_ipool_malloc(priv->sh->ipool
6111 : : [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &flow_id);
6112 [ # # ]: 0 : if (!flow_id)
6113 : 0 : return rte_flow_error_set(error, ENOMEM,
6114 : : RTE_FLOW_ERROR_TYPE_ACTION,
6115 : : NULL, "can't allocate id "
6116 : : "for split Q/RSS subflow");
6117 : : /* Internal SET_TAG action to set flow ID. */
6118 : 0 : *set_tag = (struct mlx5_rte_flow_action_set_tag){
6119 : : .data = flow_id,
6120 : : };
6121 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0, error);
6122 [ # # ]: 0 : if (ret < 0)
6123 : 0 : return ret;
6124 : 0 : set_tag->id = ret;
6125 : : /* Construct new actions array. */
6126 : : /* Replace QUEUE/RSS action. */
6127 : 0 : split_actions[qrss_idx] = (struct rte_flow_action){
6128 : : .type = (enum rte_flow_action_type)
6129 : : MLX5_RTE_FLOW_ACTION_TYPE_TAG,
6130 : : .conf = set_tag,
6131 : : };
6132 : : } else {
6133 : : /*
6134 : : * If we are the suffix flow of meter, tag already exist.
6135 : : * Set the QUEUE/RSS action to void.
6136 : : */
6137 : 0 : split_actions[qrss_idx].type = RTE_FLOW_ACTION_TYPE_VOID;
6138 : : }
6139 : : /* JUMP action to jump to mreg copy table (CP_TBL). */
6140 : 0 : jump = (void *)(set_tag + 1);
6141 : 0 : *jump = (struct rte_flow_action_jump){
6142 : : .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
6143 : : };
6144 : 0 : split_actions[actions_n - 2] = (struct rte_flow_action){
6145 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
6146 : : .conf = jump,
6147 : : };
6148 : 0 : split_actions[actions_n - 1] = (struct rte_flow_action){
6149 : : .type = RTE_FLOW_ACTION_TYPE_END,
6150 : : };
6151 : 0 : return flow_id;
6152 : : }
6153 : :
6154 : : /**
6155 : : * Extend the given action list for Tx metadata copy.
6156 : : *
6157 : : * Copy the given action list to the ext_actions and add flow metadata register
6158 : : * copy action in order to copy reg_a set by WQE to reg_c[0].
6159 : : *
6160 : : * @param[out] ext_actions
6161 : : * Pointer to the extended action list.
6162 : : * @param[in] actions
6163 : : * Pointer to the list of actions.
6164 : : * @param[in] actions_n
6165 : : * Number of actions in the list.
6166 : : * @param[out] error
6167 : : * Perform verbose error reporting if not NULL.
6168 : : * @param[in] encap_idx
6169 : : * The encap action index.
6170 : : *
6171 : : * @return
6172 : : * 0 on success, negative value otherwise
6173 : : */
6174 : : static int
6175 : 0 : flow_mreg_tx_copy_prep(struct rte_eth_dev *dev,
6176 : : struct rte_flow_action *ext_actions,
6177 : : const struct rte_flow_action *actions,
6178 : : int actions_n, struct rte_flow_error *error,
6179 : : int encap_idx)
6180 : : {
6181 : 0 : struct mlx5_flow_action_copy_mreg *cp_mreg =
6182 : : (struct mlx5_flow_action_copy_mreg *)
6183 : 0 : (ext_actions + actions_n + 1);
6184 : : int ret;
6185 : :
6186 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
6187 [ # # ]: 0 : if (ret < 0)
6188 : : return ret;
6189 : 0 : cp_mreg->dst = ret;
6190 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_TX, 0, error);
6191 [ # # ]: 0 : if (ret < 0)
6192 : : return ret;
6193 : 0 : cp_mreg->src = ret;
6194 [ # # ]: 0 : if (encap_idx != 0)
6195 : 0 : memcpy(ext_actions, actions, sizeof(*ext_actions) * encap_idx);
6196 [ # # ]: 0 : if (encap_idx == actions_n - 1) {
6197 : 0 : ext_actions[actions_n - 1] = (struct rte_flow_action){
6198 : : .type = (enum rte_flow_action_type)
6199 : : MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
6200 : : .conf = cp_mreg,
6201 : : };
6202 : 0 : ext_actions[actions_n] = (struct rte_flow_action){
6203 : : .type = RTE_FLOW_ACTION_TYPE_END,
6204 : : };
6205 : : } else {
6206 : 0 : ext_actions[encap_idx] = (struct rte_flow_action){
6207 : : .type = (enum rte_flow_action_type)
6208 : : MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
6209 : : .conf = cp_mreg,
6210 : : };
6211 : 0 : memcpy(ext_actions + encap_idx + 1, actions + encap_idx,
6212 : 0 : sizeof(*ext_actions) * (actions_n - encap_idx));
6213 : : }
6214 : : return 0;
6215 : : }
6216 : :
6217 : : /**
6218 : : * Check the match action from the action list.
6219 : : *
6220 : : * @param[in] actions
6221 : : * Pointer to the list of actions.
6222 : : * @param[in] attr
6223 : : * Flow rule attributes.
6224 : : * @param[in] action
6225 : : * The action to be check if exist.
6226 : : * @param[out] match_action_pos
6227 : : * Pointer to the position of the matched action if exists, otherwise is -1.
6228 : : * @param[out] qrss_action_pos
6229 : : * Pointer to the position of the Queue/RSS action if exists, otherwise is -1.
6230 : : * @param[out] modify_after_mirror
6231 : : * Pointer to the flag of modify action after FDB mirroring.
6232 : : *
6233 : : * @return
6234 : : * > 0 the total number of actions.
6235 : : * 0 if not found match action in action list.
6236 : : */
6237 : : static int
6238 : 0 : flow_check_match_action(const struct rte_flow_action actions[],
6239 : : const struct rte_flow_attr *attr,
6240 : : enum rte_flow_action_type action,
6241 : : int *match_action_pos, int *qrss_action_pos,
6242 : : int *modify_after_mirror)
6243 : : {
6244 : : const struct rte_flow_action_sample *sample;
6245 : : const struct rte_flow_action_raw_decap *decap;
6246 : : const struct rte_flow_action *action_cur = NULL;
6247 : : int actions_n = 0;
6248 : : uint32_t ratio = 0;
6249 : : int sub_type = 0;
6250 : : int flag = 0;
6251 : : int fdb_mirror = 0;
6252 : :
6253 : 0 : *match_action_pos = -1;
6254 : 0 : *qrss_action_pos = -1;
6255 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
6256 [ # # ]: 0 : if (actions->type == action) {
6257 : : flag = 1;
6258 : 0 : *match_action_pos = actions_n;
6259 : : }
6260 [ # # # # : 0 : switch (actions->type) {
# ]
6261 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
6262 : : case RTE_FLOW_ACTION_TYPE_RSS:
6263 : 0 : *qrss_action_pos = actions_n;
6264 : 0 : break;
6265 : 0 : case RTE_FLOW_ACTION_TYPE_SAMPLE:
6266 : 0 : sample = actions->conf;
6267 : 0 : ratio = sample->ratio;
6268 : 0 : sub_type = ((const struct rte_flow_action *)
6269 : 0 : (sample->actions))->type;
6270 [ # # # # : 0 : if (ratio == 1 && attr->transfer &&
# # ]
6271 : : sub_type != RTE_FLOW_ACTION_TYPE_END)
6272 : : fdb_mirror = 1;
6273 : : break;
6274 : 0 : case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
6275 : : case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
6276 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
6277 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
6278 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
6279 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
6280 : : case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
6281 : : case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
6282 : : case RTE_FLOW_ACTION_TYPE_DEC_TTL:
6283 : : case RTE_FLOW_ACTION_TYPE_SET_TTL:
6284 : : case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
6285 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
6286 : : case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
6287 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
6288 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
6289 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
6290 : : case RTE_FLOW_ACTION_TYPE_FLAG:
6291 : : case RTE_FLOW_ACTION_TYPE_MARK:
6292 : : case RTE_FLOW_ACTION_TYPE_SET_META:
6293 : : case RTE_FLOW_ACTION_TYPE_SET_TAG:
6294 : : case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
6295 : : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
6296 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
6297 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
6298 : : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
6299 : : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
6300 : : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
6301 : : case RTE_FLOW_ACTION_TYPE_METER:
6302 [ # # ]: 0 : if (fdb_mirror)
6303 : 0 : *modify_after_mirror = 1;
6304 : : break;
6305 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
6306 : 0 : decap = actions->conf;
6307 : : action_cur = actions;
6308 [ # # ]: 0 : while ((++action_cur)->type == RTE_FLOW_ACTION_TYPE_VOID)
6309 : : ;
6310 [ # # ]: 0 : if (action_cur->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
6311 : 0 : const struct rte_flow_action_raw_encap *encap =
6312 : : action_cur->conf;
6313 [ # # ]: 0 : if (decap->size <=
6314 : 0 : MLX5_ENCAPSULATION_DECISION_SIZE &&
6315 [ # # ]: 0 : encap->size >
6316 : : MLX5_ENCAPSULATION_DECISION_SIZE)
6317 : : /* L3 encap. */
6318 : : break;
6319 : : }
6320 [ # # ]: 0 : if (fdb_mirror)
6321 : 0 : *modify_after_mirror = 1;
6322 : : break;
6323 : : default:
6324 : : break;
6325 : : }
6326 : 0 : actions_n++;
6327 : : }
6328 [ # # # # ]: 0 : if (flag && fdb_mirror && !*modify_after_mirror) {
6329 : : /* FDB mirroring uses the destination array to implement
6330 : : * instead of FLOW_SAMPLER object.
6331 : : */
6332 [ # # ]: 0 : if (sub_type != RTE_FLOW_ACTION_TYPE_END)
6333 : : flag = 0;
6334 : : }
6335 : : /* Count RTE_FLOW_ACTION_TYPE_END. */
6336 [ # # ]: 0 : return flag ? actions_n + 1 : 0;
6337 : : }
6338 : :
6339 : : #define SAMPLE_SUFFIX_ITEM 3
6340 : :
6341 : : /**
6342 : : * Split the sample flow.
6343 : : *
6344 : : * As sample flow will split to two sub flow, sample flow with
6345 : : * sample action, the other actions will move to new suffix flow.
6346 : : *
6347 : : * Also add unique tag id with tag action in the sample flow,
6348 : : * the same tag id will be as match in the suffix flow.
6349 : : *
6350 : : * @param dev
6351 : : * Pointer to Ethernet device.
6352 : : * @param[in] add_tag
6353 : : * Add extra tag action flag.
6354 : : * @param[out] sfx_items
6355 : : * Suffix flow match items (list terminated by the END pattern item).
6356 : : * @param[in] actions
6357 : : * Associated actions (list terminated by the END action).
6358 : : * @param[out] actions_sfx
6359 : : * Suffix flow actions.
6360 : : * @param[out] actions_pre
6361 : : * Prefix flow actions.
6362 : : * @param[in] actions_n
6363 : : * The total number of actions.
6364 : : * @param[in] sample_action_pos
6365 : : * The sample action position.
6366 : : * @param[in] qrss_action_pos
6367 : : * The Queue/RSS action position.
6368 : : * @param[in] jump_table
6369 : : * Add extra jump action flag.
6370 : : * @param[out] error
6371 : : * Perform verbose error reporting if not NULL.
6372 : : *
6373 : : * @return
6374 : : * 0 on success, or unique flow_id, a negative errno value
6375 : : * otherwise and rte_errno is set.
6376 : : */
6377 : : static int
6378 : 0 : flow_sample_split_prep(struct rte_eth_dev *dev,
6379 : : int add_tag,
6380 : : const struct rte_flow_item items[],
6381 : : struct rte_flow_item sfx_items[],
6382 : : const struct rte_flow_action actions[],
6383 : : struct rte_flow_action actions_sfx[],
6384 : : struct rte_flow_action actions_pre[],
6385 : : int actions_n,
6386 : : int sample_action_pos,
6387 : : int qrss_action_pos,
6388 : : int jump_table,
6389 : : struct rte_flow_error *error)
6390 : : {
6391 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6392 : : struct mlx5_rte_flow_action_set_tag *set_tag;
6393 : : struct mlx5_rte_flow_item_tag *tag_spec;
6394 : : struct mlx5_rte_flow_item_tag *tag_mask;
6395 : : struct rte_flow_action_jump *jump_action;
6396 : 0 : uint32_t tag_id = 0;
6397 : : int append_index = 0;
6398 : : int set_tag_idx = -1;
6399 : : int index;
6400 : : int ret;
6401 : :
6402 [ # # ]: 0 : if (sample_action_pos < 0)
6403 : 0 : return rte_flow_error_set(error, EINVAL,
6404 : : RTE_FLOW_ERROR_TYPE_ACTION,
6405 : : NULL, "invalid position of sample "
6406 : : "action in list");
6407 : : /* Prepare the actions for prefix and suffix flow. */
6408 [ # # ]: 0 : if (add_tag) {
6409 : : /* Update the new added tag action index preceding
6410 : : * the PUSH_VLAN or ENCAP action.
6411 : : */
6412 : : const struct rte_flow_action_raw_encap *raw_encap;
6413 : : const struct rte_flow_action *action = actions;
6414 : : int encap_idx;
6415 : : int action_idx = 0;
6416 : : int raw_decap_idx = -1;
6417 : : int push_vlan_idx = -1;
6418 [ # # ]: 0 : for (; action->type != RTE_FLOW_ACTION_TYPE_END; action++) {
6419 [ # # # # : 0 : switch (action->type) {
# ]
6420 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
6421 : : raw_decap_idx = action_idx;
6422 : 0 : break;
6423 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
6424 : 0 : raw_encap = action->conf;
6425 [ # # ]: 0 : if (raw_encap->size >
6426 : : MLX5_ENCAPSULATION_DECISION_SIZE) {
6427 : : encap_idx = raw_decap_idx != -1 ?
6428 [ # # ]: 0 : raw_decap_idx : action_idx;
6429 : 0 : if (encap_idx < sample_action_pos &&
6430 [ # # ]: 0 : push_vlan_idx == -1)
6431 : : set_tag_idx = encap_idx;
6432 : : }
6433 : : break;
6434 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
6435 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
6436 : : encap_idx = action_idx;
6437 : 0 : if (encap_idx < sample_action_pos &&
6438 [ # # ]: 0 : push_vlan_idx == -1)
6439 : : set_tag_idx = encap_idx;
6440 : : break;
6441 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
6442 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
6443 : 0 : if (action_idx < sample_action_pos &&
6444 [ # # ]: 0 : push_vlan_idx == -1) {
6445 : : set_tag_idx = action_idx;
6446 : : push_vlan_idx = action_idx;
6447 : : }
6448 : : break;
6449 : : default:
6450 : : break;
6451 : : }
6452 : 0 : action_idx++;
6453 : : }
6454 : : }
6455 : : /* Prepare the actions for prefix and suffix flow. */
6456 [ # # ]: 0 : if (qrss_action_pos >= 0 && qrss_action_pos < sample_action_pos) {
6457 : : index = qrss_action_pos;
6458 : : /* Put the preceding the Queue/RSS action into prefix flow. */
6459 [ # # ]: 0 : if (index != 0)
6460 : 0 : memcpy(actions_pre, actions,
6461 : : sizeof(struct rte_flow_action) * index);
6462 : : /* Put others preceding the sample action into prefix flow. */
6463 [ # # ]: 0 : if (sample_action_pos > index + 1)
6464 : 0 : memcpy(actions_pre + index, actions + index + 1,
6465 : : sizeof(struct rte_flow_action) *
6466 : 0 : (sample_action_pos - index - 1));
6467 : 0 : index = sample_action_pos - 1;
6468 : : /* Put Queue/RSS action into Suffix flow. */
6469 : 0 : memcpy(actions_sfx, actions + qrss_action_pos,
6470 : : sizeof(struct rte_flow_action));
6471 : 0 : actions_sfx++;
6472 [ # # ]: 0 : } else if (add_tag && set_tag_idx >= 0) {
6473 [ # # ]: 0 : if (set_tag_idx > 0)
6474 : 0 : memcpy(actions_pre, actions,
6475 : : sizeof(struct rte_flow_action) * set_tag_idx);
6476 : 0 : memcpy(actions_pre + set_tag_idx + 1, actions + set_tag_idx,
6477 : : sizeof(struct rte_flow_action) *
6478 : 0 : (sample_action_pos - set_tag_idx));
6479 : : index = sample_action_pos;
6480 : : } else {
6481 : : index = sample_action_pos;
6482 [ # # ]: 0 : if (index != 0)
6483 : 0 : memcpy(actions_pre, actions,
6484 : : sizeof(struct rte_flow_action) * index);
6485 : : }
6486 : : /* For CX5, add an extra tag action for NIC-RX and E-Switch ingress.
6487 : : * For CX6DX and above, metadata registers Cx preserve their value,
6488 : : * add an extra tag action for NIC-RX and E-Switch Domain.
6489 : : */
6490 [ # # ]: 0 : if (add_tag) {
6491 : : /* Prepare the prefix tag action. */
6492 : : append_index++;
6493 : 0 : set_tag = (void *)(actions_pre + actions_n + append_index);
6494 : : /* Trust VF/SF on CX5 not supported meter so that the reserved
6495 : : * metadata regC is REG_NON, back to use application tag
6496 : : * index 0.
6497 : : */
6498 [ # # ]: 0 : if (unlikely(priv->sh->registers.aso_reg == REG_NON))
6499 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, 0, error);
6500 : : else
6501 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_SAMPLE_ID, 0, error);
6502 [ # # ]: 0 : if (ret < 0)
6503 : : return ret;
6504 : 0 : mlx5_ipool_malloc(priv->sh->ipool
6505 : : [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &tag_id);
6506 : 0 : *set_tag = (struct mlx5_rte_flow_action_set_tag) {
6507 : : .id = ret,
6508 : : .data = tag_id,
6509 : : };
6510 : : /* Prepare the suffix subflow items. */
6511 : 0 : tag_spec = (void *)(sfx_items + SAMPLE_SUFFIX_ITEM);
6512 : 0 : tag_spec->data = tag_id;
6513 : 0 : tag_spec->id = set_tag->id;
6514 : 0 : tag_mask = tag_spec + 1;
6515 : 0 : tag_mask->data = UINT32_MAX;
6516 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
6517 [ # # ]: 0 : if (items->type == RTE_FLOW_ITEM_TYPE_PORT_ID ||
6518 : : items->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR ||
6519 : : items->type == RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT) {
6520 : : memcpy(sfx_items, items, sizeof(*sfx_items));
6521 : 0 : sfx_items++;
6522 : 0 : break;
6523 : : }
6524 : : }
6525 : 0 : sfx_items[0] = (struct rte_flow_item){
6526 : : .type = (enum rte_flow_item_type)
6527 : : MLX5_RTE_FLOW_ITEM_TYPE_TAG,
6528 : : .spec = tag_spec,
6529 : : .last = NULL,
6530 : : .mask = tag_mask,
6531 : : };
6532 : 0 : sfx_items[1] = (struct rte_flow_item){
6533 : : .type = (enum rte_flow_item_type)
6534 : : RTE_FLOW_ITEM_TYPE_END,
6535 : : };
6536 : : /* Prepare the tag action in prefix subflow. */
6537 [ # # ]: 0 : set_tag_idx = (set_tag_idx == -1) ? index : set_tag_idx;
6538 : 0 : actions_pre[set_tag_idx] =
6539 : : (struct rte_flow_action){
6540 : : .type = (enum rte_flow_action_type)
6541 : : MLX5_RTE_FLOW_ACTION_TYPE_TAG,
6542 : : .conf = set_tag,
6543 : : };
6544 : : /* Update next sample position due to add one tag action */
6545 : 0 : index += 1;
6546 : : }
6547 : : /* Copy the sample action into prefix flow. */
6548 [ # # ]: 0 : memcpy(actions_pre + index, actions + sample_action_pos,
6549 : : sizeof(struct rte_flow_action));
6550 : 0 : index += 1;
6551 : : /* For the modify action after the sample action in E-Switch mirroring,
6552 : : * Add the extra jump action in prefix subflow and jump into the next
6553 : : * table, then do the modify action in the new table.
6554 : : */
6555 [ # # ]: 0 : if (jump_table) {
6556 : : /* Prepare the prefix jump action. */
6557 : 0 : append_index++;
6558 : 0 : jump_action = (void *)(actions_pre + actions_n + append_index);
6559 : 0 : jump_action->group = jump_table;
6560 : 0 : actions_pre[index++] =
6561 : : (struct rte_flow_action){
6562 : : .type = (enum rte_flow_action_type)
6563 : : RTE_FLOW_ACTION_TYPE_JUMP,
6564 : : .conf = jump_action,
6565 : : };
6566 : : }
6567 : 0 : actions_pre[index] = (struct rte_flow_action){
6568 : : .type = (enum rte_flow_action_type)
6569 : : RTE_FLOW_ACTION_TYPE_END,
6570 : : };
6571 : : /* Put the actions after sample into Suffix flow. */
6572 : 0 : memcpy(actions_sfx, actions + sample_action_pos + 1,
6573 : : sizeof(struct rte_flow_action) *
6574 : 0 : (actions_n - sample_action_pos - 1));
6575 : 0 : return tag_id;
6576 : : }
6577 : :
6578 : : /**
6579 : : * The splitting for metadata feature.
6580 : : *
6581 : : * - Q/RSS action on NIC Rx should be split in order to pass by
6582 : : * the mreg copy table (RX_CP_TBL) and then it jumps to the
6583 : : * action table (RX_ACT_TBL) which has the split Q/RSS action.
6584 : : *
6585 : : * - All the actions on NIC Tx should have a mreg copy action to
6586 : : * copy reg_a from WQE to reg_c[0].
6587 : : *
6588 : : * @param dev
6589 : : * Pointer to Ethernet device.
6590 : : * @param[in] flow
6591 : : * Parent flow structure pointer.
6592 : : * @param[in] attr
6593 : : * Flow rule attributes.
6594 : : * @param[in] items
6595 : : * Pattern specification (list terminated by the END pattern item).
6596 : : * @param[in] actions
6597 : : * Associated actions (list terminated by the END action).
6598 : : * @param[in] flow_split_info
6599 : : * Pointer to flow split info structure.
6600 : : * @param[out] error
6601 : : * Perform verbose error reporting if not NULL.
6602 : : * @return
6603 : : * 0 on success, negative value otherwise
6604 : : */
6605 : : static int
6606 : 0 : flow_create_split_metadata(struct rte_eth_dev *dev,
6607 : : struct rte_flow *flow,
6608 : : const struct rte_flow_attr *attr,
6609 : : const struct rte_flow_item items[],
6610 : : const struct rte_flow_action actions[],
6611 : : struct mlx5_flow_split_info *flow_split_info,
6612 : : struct rte_flow_error *error)
6613 : : {
6614 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6615 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
6616 : 0 : const struct rte_flow_action *qrss = NULL;
6617 : : struct rte_flow_action *ext_actions = NULL;
6618 : 0 : struct mlx5_flow *dev_flow = NULL;
6619 : : uint32_t qrss_id = 0;
6620 : : int mtr_sfx = 0;
6621 : : size_t act_size;
6622 : : int actions_n;
6623 : : int encap_idx;
6624 : : int ret;
6625 : :
6626 : : /* Check whether extensive metadata feature is engaged. */
6627 [ # # ]: 0 : if (!config->dv_flow_en ||
6628 [ # # # # ]: 0 : config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
6629 : 0 : !mlx5_flow_ext_mreg_supported(dev))
6630 : 0 : return flow_create_split_inner(dev, flow, NULL, attr, items,
6631 : : actions, flow_split_info, error);
6632 : 0 : actions_n = flow_parse_metadata_split_actions_info(actions, &qrss,
6633 : : &encap_idx);
6634 [ # # ]: 0 : if (qrss) {
6635 : : /* Exclude hairpin flows from splitting. */
6636 [ # # ]: 0 : if (qrss->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
6637 : : const struct rte_flow_action_queue *queue;
6638 : :
6639 : 0 : queue = qrss->conf;
6640 [ # # ]: 0 : if (mlx5_rxq_is_hairpin(dev, queue->index))
6641 : 0 : qrss = NULL;
6642 [ # # ]: 0 : } else if (qrss->type == RTE_FLOW_ACTION_TYPE_RSS) {
6643 : : const struct rte_flow_action_rss *rss;
6644 : :
6645 : 0 : rss = qrss->conf;
6646 [ # # ]: 0 : if (mlx5_rxq_is_hairpin(dev, rss->queue[0]))
6647 : 0 : qrss = NULL;
6648 : : }
6649 : : }
6650 [ # # ]: 0 : if (qrss) {
6651 : : /* Check if it is in meter suffix table. */
6652 : 0 : mtr_sfx = attr->group ==
6653 [ # # ]: 0 : ((attr->transfer && priv->fdb_def_rule) ?
6654 [ # # ]: 0 : (MLX5_FLOW_TABLE_LEVEL_METER - 1) :
6655 : : MLX5_FLOW_TABLE_LEVEL_METER);
6656 : : /*
6657 : : * Q/RSS action on NIC Rx should be split in order to pass by
6658 : : * the mreg copy table (RX_CP_TBL) and then it jumps to the
6659 : : * action table (RX_ACT_TBL) which has the split Q/RSS action.
6660 : : */
6661 : 0 : act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
6662 : 0 : sizeof(struct rte_flow_action_set_tag) +
6663 : : sizeof(struct rte_flow_action_jump);
6664 : 0 : ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
6665 : : SOCKET_ID_ANY);
6666 [ # # ]: 0 : if (!ext_actions)
6667 : 0 : return rte_flow_error_set(error, ENOMEM,
6668 : : RTE_FLOW_ERROR_TYPE_ACTION,
6669 : : NULL, "no memory to split "
6670 : : "metadata flow");
6671 : : /*
6672 : : * Create the new actions list with removed Q/RSS action
6673 : : * and appended set tag and jump to register copy table
6674 : : * (RX_CP_TBL). We should preallocate unique tag ID here
6675 : : * in advance, because it is needed for set tag action.
6676 : : */
6677 : 0 : qrss_id = flow_mreg_split_qrss_prep(dev, ext_actions, actions,
6678 : : qrss, actions_n,
6679 : : mtr_sfx, error);
6680 [ # # ]: 0 : if (!mtr_sfx && !qrss_id) {
6681 : 0 : ret = -rte_errno;
6682 : 0 : goto exit;
6683 : : }
6684 [ # # ]: 0 : } else if (attr->egress) {
6685 : : /*
6686 : : * All the actions on NIC Tx should have a metadata register
6687 : : * copy action to copy reg_a from WQE to reg_c[meta]
6688 : : */
6689 : 0 : act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
6690 : : sizeof(struct mlx5_flow_action_copy_mreg);
6691 : 0 : ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
6692 : : SOCKET_ID_ANY);
6693 [ # # ]: 0 : if (!ext_actions)
6694 : 0 : return rte_flow_error_set(error, ENOMEM,
6695 : : RTE_FLOW_ERROR_TYPE_ACTION,
6696 : : NULL, "no memory to split "
6697 : : "metadata flow");
6698 : : /* Create the action list appended with copy register. */
6699 : 0 : ret = flow_mreg_tx_copy_prep(dev, ext_actions, actions,
6700 : : actions_n, error, encap_idx);
6701 [ # # ]: 0 : if (ret < 0)
6702 : 0 : goto exit;
6703 : : }
6704 : : /* Add the unmodified original or prefix subflow. */
6705 [ # # ]: 0 : ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
6706 : : items, ext_actions ? ext_actions :
6707 : : actions, flow_split_info, error);
6708 [ # # ]: 0 : if (ret < 0)
6709 : 0 : goto exit;
6710 : : MLX5_ASSERT(dev_flow);
6711 [ # # ]: 0 : if (qrss) {
6712 : 0 : const struct rte_flow_attr q_attr = {
6713 : : .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
6714 : : .ingress = 1,
6715 : : };
6716 : : /* Internal PMD action to set register. */
6717 : 0 : struct mlx5_rte_flow_item_tag q_tag_spec = {
6718 : : .data = qrss_id,
6719 : : .id = REG_NON,
6720 : : };
6721 : 0 : struct rte_flow_item q_items[] = {
6722 : : {
6723 : : .type = (enum rte_flow_item_type)
6724 : : MLX5_RTE_FLOW_ITEM_TYPE_TAG,
6725 : : .spec = &q_tag_spec,
6726 : : .last = NULL,
6727 : : .mask = NULL,
6728 : : },
6729 : : {
6730 : : .type = RTE_FLOW_ITEM_TYPE_END,
6731 : : },
6732 : : };
6733 : 0 : struct rte_flow_action q_actions[] = {
6734 : : {
6735 : 0 : .type = qrss->type,
6736 : 0 : .conf = qrss->conf,
6737 : : },
6738 : : {
6739 : : .type = RTE_FLOW_ACTION_TYPE_END,
6740 : : },
6741 : : };
6742 : 0 : uint64_t layers = flow_get_prefix_layer_flags(dev_flow);
6743 : :
6744 : : /*
6745 : : * Configure the tag item only if there is no meter subflow.
6746 : : * Since tag is already marked in the meter suffix subflow
6747 : : * we can just use the meter suffix items as is.
6748 : : */
6749 [ # # ]: 0 : if (qrss_id) {
6750 : : /* Not meter subflow. */
6751 : : MLX5_ASSERT(!mtr_sfx);
6752 : : /*
6753 : : * Put unique id in prefix flow due to it is destroyed
6754 : : * after suffix flow and id will be freed after there
6755 : : * is no actual flows with this id and identifier
6756 : : * reallocation becomes possible (for example, for
6757 : : * other flows in other threads).
6758 : : */
6759 : 0 : dev_flow->handle->split_flow_id = qrss_id;
6760 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0,
6761 : : error);
6762 [ # # ]: 0 : if (ret < 0)
6763 : 0 : goto exit;
6764 : 0 : q_tag_spec.id = ret;
6765 : : }
6766 : 0 : dev_flow = NULL;
6767 : : /* Add suffix subflow to execute Q/RSS. */
6768 : 0 : flow_split_info->prefix_layers = layers;
6769 : 0 : flow_split_info->prefix_mark = 0;
6770 : 0 : flow_split_info->table_id = 0;
6771 [ # # ]: 0 : ret = flow_create_split_inner(dev, flow, &dev_flow,
6772 : : &q_attr, mtr_sfx ? items :
6773 : : q_items, q_actions,
6774 : : flow_split_info, error);
6775 [ # # ]: 0 : if (ret < 0)
6776 : 0 : goto exit;
6777 : : /* qrss ID should be freed if failed. */
6778 : : qrss_id = 0;
6779 : : MLX5_ASSERT(dev_flow);
6780 : : }
6781 : :
6782 : 0 : exit:
6783 : : /*
6784 : : * We do not destroy the partially created sub_flows in case of error.
6785 : : * These ones are included into parent flow list and will be destroyed
6786 : : * by flow_drv_destroy.
6787 : : */
6788 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
6789 : : qrss_id);
6790 : 0 : mlx5_free(ext_actions);
6791 : 0 : return ret;
6792 : : }
6793 : :
6794 : : /**
6795 : : * Create meter internal drop flow with the original pattern.
6796 : : *
6797 : : * @param dev
6798 : : * Pointer to Ethernet device.
6799 : : * @param[in] flow
6800 : : * Parent flow structure pointer.
6801 : : * @param[in] attr
6802 : : * Flow rule attributes.
6803 : : * @param[in] items
6804 : : * Pattern specification (list terminated by the END pattern item).
6805 : : * @param[in] flow_split_info
6806 : : * Pointer to flow split info structure.
6807 : : * @param[in] fm
6808 : : * Pointer to flow meter structure.
6809 : : * @param[out] error
6810 : : * Perform verbose error reporting if not NULL.
6811 : : * @return
6812 : : * 0 on success, negative value otherwise
6813 : : */
6814 : : static uint32_t
6815 : 0 : flow_meter_create_drop_flow_with_org_pattern(struct rte_eth_dev *dev,
6816 : : struct rte_flow *flow,
6817 : : const struct rte_flow_attr *attr,
6818 : : const struct rte_flow_item items[],
6819 : : struct mlx5_flow_split_info *flow_split_info,
6820 : : struct mlx5_flow_meter_info *fm,
6821 : : struct rte_flow_error *error)
6822 : : {
6823 : 0 : struct mlx5_flow *dev_flow = NULL;
6824 : 0 : struct rte_flow_attr drop_attr = *attr;
6825 : : struct rte_flow_action drop_actions[3];
6826 : 0 : struct mlx5_flow_split_info drop_split_info = *flow_split_info;
6827 : :
6828 : : MLX5_ASSERT(fm->drop_cnt);
6829 : 0 : drop_actions[0].type =
6830 : : (enum rte_flow_action_type)MLX5_RTE_FLOW_ACTION_TYPE_COUNT;
6831 : 0 : drop_actions[0].conf = (void *)(uintptr_t)fm->drop_cnt;
6832 : 0 : drop_actions[1].type = RTE_FLOW_ACTION_TYPE_DROP;
6833 : 0 : drop_actions[1].conf = NULL;
6834 : 0 : drop_actions[2].type = RTE_FLOW_ACTION_TYPE_END;
6835 : 0 : drop_actions[2].conf = NULL;
6836 : 0 : drop_split_info.external = false;
6837 : 0 : drop_split_info.skip_scale |= 1 << MLX5_SCALE_FLOW_GROUP_BIT;
6838 : 0 : drop_split_info.table_id = MLX5_MTR_TABLE_ID_DROP;
6839 : 0 : drop_attr.group = MLX5_FLOW_TABLE_LEVEL_METER;
6840 : 0 : return flow_create_split_inner(dev, flow, &dev_flow,
6841 : : &drop_attr, items, drop_actions,
6842 : : &drop_split_info, error);
6843 : : }
6844 : :
6845 : : static int
6846 : : flow_count_vlan_items(const struct rte_flow_item items[])
6847 : : {
6848 : : int items_n = 0;
6849 : :
6850 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
6851 [ # # ]: 0 : if (items->type == RTE_FLOW_ITEM_TYPE_VLAN ||
6852 : : items->type == (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_VLAN)
6853 : 0 : items_n++;
6854 : : }
6855 : : return items_n;
6856 : : }
6857 : :
6858 : : /**
6859 : : * The splitting for meter feature.
6860 : : *
6861 : : * - The meter flow will be split to two flows as prefix and
6862 : : * suffix flow. The packets make sense only it pass the prefix
6863 : : * meter action.
6864 : : *
6865 : : * - Reg_C_5 is used for the packet to match betweend prefix and
6866 : : * suffix flow.
6867 : : *
6868 : : * @param dev
6869 : : * Pointer to Ethernet device.
6870 : : * @param[in] flow
6871 : : * Parent flow structure pointer.
6872 : : * @param[in] attr
6873 : : * Flow rule attributes.
6874 : : * @param[in] items
6875 : : * Pattern specification (list terminated by the END pattern item).
6876 : : * @param[in] actions
6877 : : * Associated actions (list terminated by the END action).
6878 : : * @param[in] flow_split_info
6879 : : * Pointer to flow split info structure.
6880 : : * @param[out] error
6881 : : * Perform verbose error reporting if not NULL.
6882 : : * @return
6883 : : * 0 on success, negative value otherwise
6884 : : */
6885 : : static int
6886 : 0 : flow_create_split_meter(struct rte_eth_dev *dev,
6887 : : struct rte_flow *flow,
6888 : : const struct rte_flow_attr *attr,
6889 : : const struct rte_flow_item items[],
6890 : : const struct rte_flow_action actions[],
6891 : : struct mlx5_flow_split_info *flow_split_info,
6892 : : struct rte_flow_error *error)
6893 : : {
6894 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6895 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
6896 : : struct rte_flow_action *sfx_actions = NULL;
6897 : : struct rte_flow_action *pre_actions = NULL;
6898 : : struct rte_flow_item *sfx_items = NULL;
6899 : 0 : struct mlx5_flow *dev_flow = NULL;
6900 : 0 : struct rte_flow_attr sfx_attr = *attr;
6901 : : struct mlx5_flow_meter_info *fm = NULL;
6902 : : uint8_t skip_scale_restore;
6903 : 0 : bool has_mtr = false;
6904 : 0 : bool has_modify = false;
6905 : : bool set_mtr_reg = true;
6906 : : bool is_mtr_hierarchy = false;
6907 : 0 : uint32_t meter_id = 0;
6908 : 0 : uint32_t mtr_idx = 0;
6909 : 0 : uint32_t mtr_flow_id = 0;
6910 : : size_t act_size;
6911 : : size_t item_size;
6912 : : int actions_n = 0;
6913 : : int vlan_items_n = 0;
6914 : : int ret = 0;
6915 : :
6916 [ # # ]: 0 : if (priv->mtr_en)
6917 : 0 : actions_n = flow_check_meter_action(dev, actions, &has_mtr,
6918 : : &has_modify, &meter_id);
6919 [ # # ]: 0 : if (has_mtr) {
6920 [ # # ]: 0 : if (flow->meter) {
6921 : 0 : fm = flow_dv_meter_find_by_idx(priv, flow->meter);
6922 [ # # ]: 0 : if (!fm)
6923 : 0 : return rte_flow_error_set(error, EINVAL,
6924 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6925 : : NULL, "Meter not found.");
6926 : : } else {
6927 : 0 : fm = mlx5_flow_meter_find(priv, meter_id, &mtr_idx);
6928 [ # # ]: 0 : if (!fm)
6929 : 0 : return rte_flow_error_set(error, EINVAL,
6930 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6931 : : NULL, "Meter not found.");
6932 : 0 : ret = mlx5_flow_meter_attach(priv, fm,
6933 : : &sfx_attr, error);
6934 [ # # ]: 0 : if (ret)
6935 : 0 : return -rte_errno;
6936 : 0 : flow->meter = mtr_idx;
6937 : : }
6938 : : MLX5_ASSERT(wks);
6939 : 0 : wks->fm = fm;
6940 [ # # ]: 0 : if (!fm->def_policy) {
6941 : 0 : wks->policy = mlx5_flow_meter_policy_find(dev,
6942 : : fm->policy_id,
6943 : : NULL);
6944 : : MLX5_ASSERT(wks->policy);
6945 [ # # ]: 0 : if (wks->policy->mark)
6946 : 0 : wks->mark = 1;
6947 [ # # ]: 0 : if (wks->policy->is_hierarchy) {
6948 : 0 : wks->final_policy =
6949 : 0 : mlx5_flow_meter_hierarchy_get_final_policy(dev,
6950 : : wks->policy);
6951 [ # # ]: 0 : if (!wks->final_policy)
6952 : 0 : return rte_flow_error_set(error,
6953 : : EINVAL,
6954 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6955 : : "Failed to find terminal policy of hierarchy.");
6956 : : is_mtr_hierarchy = true;
6957 : : }
6958 : : }
6959 : : /*
6960 : : * If it isn't default-policy Meter, and
6961 : : * 1. Not meter hierarchy and there's no action in flow to change
6962 : : * packet (modify/encap/decap etc.), OR
6963 : : * 2. No drop count needed for this meter.
6964 : : * Then no need to use regC to save meter id anymore.
6965 : : */
6966 [ # # # # : 0 : if (!fm->def_policy && ((!has_modify && !is_mtr_hierarchy) || !fm->drop_cnt))
# # # # ]
6967 : : set_mtr_reg = false;
6968 : : /* Prefix actions: meter, decap, encap, tag, jump, end, cnt. */
6969 : : #define METER_PREFIX_ACTION 7
6970 : 0 : act_size = (sizeof(struct rte_flow_action) *
6971 : 0 : (actions_n + METER_PREFIX_ACTION)) +
6972 : : sizeof(struct mlx5_rte_flow_action_set_tag);
6973 : : /* Flow can have multiple VLAN items. Account for them in suffix items. */
6974 : : vlan_items_n = flow_count_vlan_items(items);
6975 : : /* Suffix items: tag, [vlans], port id, end. */
6976 : : #define METER_SUFFIX_ITEM 3
6977 : 0 : item_size = sizeof(struct rte_flow_item) * (METER_SUFFIX_ITEM + vlan_items_n) +
6978 : : sizeof(struct mlx5_rte_flow_item_tag) * 2;
6979 : 0 : sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size + item_size),
6980 : : 0, SOCKET_ID_ANY);
6981 [ # # ]: 0 : if (!sfx_actions)
6982 : 0 : return rte_flow_error_set(error, ENOMEM,
6983 : : RTE_FLOW_ERROR_TYPE_ACTION,
6984 : : NULL, "no memory to split "
6985 : : "meter flow");
6986 : 0 : sfx_items = (struct rte_flow_item *)((char *)sfx_actions +
6987 : : act_size);
6988 : : /* There's no suffix flow for meter of non-default policy. */
6989 [ # # ]: 0 : if (!fm->def_policy)
6990 : 0 : pre_actions = sfx_actions + 1;
6991 : : else
6992 : 0 : pre_actions = sfx_actions + actions_n;
6993 [ # # ]: 0 : ret = flow_meter_split_prep(dev, flow, wks, &sfx_attr,
6994 : : items, sfx_items, actions,
6995 : : sfx_actions, pre_actions,
6996 : : (set_mtr_reg ? &mtr_flow_id : NULL),
6997 : : error);
6998 [ # # ]: 0 : if (ret) {
6999 : 0 : ret = -rte_errno;
7000 : 0 : goto exit;
7001 : : }
7002 : : /* Add the prefix subflow. */
7003 : 0 : skip_scale_restore = flow_split_info->skip_scale;
7004 : 0 : flow_split_info->skip_scale |=
7005 : : 1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT;
7006 : 0 : ret = flow_create_split_inner(dev, flow, &dev_flow,
7007 : : attr, items, pre_actions,
7008 : : flow_split_info, error);
7009 : 0 : flow_split_info->skip_scale = skip_scale_restore;
7010 [ # # ]: 0 : if (ret) {
7011 [ # # ]: 0 : if (mtr_flow_id)
7012 : 0 : mlx5_ipool_free(fm->flow_ipool, mtr_flow_id);
7013 : 0 : ret = -rte_errno;
7014 : 0 : goto exit;
7015 : : }
7016 [ # # ]: 0 : if (mtr_flow_id) {
7017 : 0 : dev_flow->handle->split_flow_id = mtr_flow_id;
7018 : 0 : dev_flow->handle->is_meter_flow_id = 1;
7019 : : }
7020 [ # # ]: 0 : if (!fm->def_policy) {
7021 [ # # # # ]: 0 : if (!set_mtr_reg && fm->drop_cnt)
7022 : 0 : ret =
7023 : 0 : flow_meter_create_drop_flow_with_org_pattern(dev, flow,
7024 : : &sfx_attr, items,
7025 : : flow_split_info,
7026 : : fm, error);
7027 : 0 : goto exit;
7028 : : }
7029 : : /* Setting the sfx group atrr. */
7030 : 0 : sfx_attr.group = sfx_attr.transfer ?
7031 [ # # ]: 0 : (MLX5_FLOW_TABLE_LEVEL_METER - 1) :
7032 : : MLX5_FLOW_TABLE_LEVEL_METER;
7033 : 0 : flow_split_info->prefix_layers =
7034 : 0 : flow_get_prefix_layer_flags(dev_flow);
7035 : 0 : flow_split_info->prefix_mark |= wks->mark;
7036 : 0 : flow_split_info->table_id = MLX5_MTR_TABLE_ID_SUFFIX;
7037 : : }
7038 : : /* Add the prefix subflow. */
7039 [ # # ]: 0 : ret = flow_create_split_metadata(dev, flow,
7040 : : &sfx_attr, sfx_items ?
7041 : : sfx_items : items,
7042 : : sfx_actions ? sfx_actions : actions,
7043 : : flow_split_info, error);
7044 : 0 : exit:
7045 [ # # ]: 0 : if (sfx_actions)
7046 : 0 : mlx5_free(sfx_actions);
7047 : : return ret;
7048 : : }
7049 : :
7050 : : /**
7051 : : * The splitting for sample feature.
7052 : : *
7053 : : * Once Sample action is detected in the action list, the flow actions should
7054 : : * be split into prefix sub flow and suffix sub flow.
7055 : : *
7056 : : * The original items remain in the prefix sub flow, all actions preceding the
7057 : : * sample action and the sample action itself will be copied to the prefix
7058 : : * sub flow, the actions following the sample action will be copied to the
7059 : : * suffix sub flow, Queue action always be located in the suffix sub flow.
7060 : : *
7061 : : * In order to make the packet from prefix sub flow matches with suffix sub
7062 : : * flow, an extra tag action be added into prefix sub flow, and the suffix sub
7063 : : * flow uses tag item with the unique flow id.
7064 : : *
7065 : : * @param dev
7066 : : * Pointer to Ethernet device.
7067 : : * @param[in] flow
7068 : : * Parent flow structure pointer.
7069 : : * @param[in] attr
7070 : : * Flow rule attributes.
7071 : : * @param[in] items
7072 : : * Pattern specification (list terminated by the END pattern item).
7073 : : * @param[in] actions
7074 : : * Associated actions (list terminated by the END action).
7075 : : * @param[in] flow_split_info
7076 : : * Pointer to flow split info structure.
7077 : : * @param[out] error
7078 : : * Perform verbose error reporting if not NULL.
7079 : : * @return
7080 : : * 0 on success, negative value otherwise
7081 : : */
7082 : : static int
7083 : 0 : flow_create_split_sample(struct rte_eth_dev *dev,
7084 : : struct rte_flow *flow,
7085 : : const struct rte_flow_attr *attr,
7086 : : const struct rte_flow_item items[],
7087 : : const struct rte_flow_action actions[],
7088 : : struct mlx5_flow_split_info *flow_split_info,
7089 : : struct rte_flow_error *error)
7090 : : {
7091 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7092 : : struct rte_flow_action *sfx_actions = NULL;
7093 : : struct rte_flow_action *pre_actions = NULL;
7094 : : struct rte_flow_item *sfx_items = NULL;
7095 : 0 : struct mlx5_flow *dev_flow = NULL;
7096 : 0 : struct rte_flow_attr sfx_attr = *attr;
7097 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
7098 : : struct mlx5_flow_dv_sample_resource *sample_res;
7099 : : struct mlx5_flow_tbl_data_entry *sfx_tbl_data;
7100 : : struct mlx5_flow_tbl_resource *sfx_tbl;
7101 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
7102 : : #endif
7103 : : size_t act_size;
7104 : : size_t item_size;
7105 : : uint32_t fdb_tx = 0;
7106 : : int32_t tag_id = 0;
7107 : : int actions_n = 0;
7108 : : int sample_action_pos;
7109 : : int qrss_action_pos;
7110 : : int add_tag = 0;
7111 : 0 : int modify_after_mirror = 0;
7112 : : uint16_t jump_table = 0;
7113 : : const uint32_t next_ft_step = 1;
7114 : : int ret = 0;
7115 : : struct mlx5_priv *item_port_priv = NULL;
7116 : : const struct rte_flow_item *item;
7117 : :
7118 [ # # ]: 0 : if (priv->sampler_en)
7119 : 0 : actions_n = flow_check_match_action(actions, attr,
7120 : : RTE_FLOW_ACTION_TYPE_SAMPLE,
7121 : : &sample_action_pos, &qrss_action_pos,
7122 : : &modify_after_mirror);
7123 [ # # ]: 0 : if (actions_n) {
7124 : : /* The prefix actions must includes sample, tag, end. */
7125 : 0 : act_size = sizeof(struct rte_flow_action) * (actions_n * 2 + 1)
7126 : : + sizeof(struct mlx5_rte_flow_action_set_tag);
7127 : : item_size = sizeof(struct rte_flow_item) * SAMPLE_SUFFIX_ITEM +
7128 : : sizeof(struct mlx5_rte_flow_item_tag) * 2;
7129 : 0 : sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size +
7130 : : item_size), 0, SOCKET_ID_ANY);
7131 [ # # ]: 0 : if (!sfx_actions)
7132 : 0 : return rte_flow_error_set(error, ENOMEM,
7133 : : RTE_FLOW_ERROR_TYPE_ACTION,
7134 : : NULL, "no memory to split "
7135 : : "sample flow");
7136 [ # # ]: 0 : for (item = items; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
7137 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_PORT_ID) {
7138 : : const struct rte_flow_item_port_id *spec;
7139 : :
7140 : 0 : spec = (const struct rte_flow_item_port_id *)item->spec;
7141 [ # # ]: 0 : if (spec)
7142 : : item_port_priv =
7143 : 0 : mlx5_port_to_eswitch_info(spec->id, true);
7144 : : break;
7145 [ # # ]: 0 : } else if (item->type == RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT) {
7146 : : const struct rte_flow_item_ethdev *spec;
7147 : :
7148 : 0 : spec = (const struct rte_flow_item_ethdev *)item->spec;
7149 [ # # ]: 0 : if (spec)
7150 : : item_port_priv =
7151 : 0 : mlx5_port_to_eswitch_info(spec->port_id, true);
7152 : : break;
7153 [ # # ]: 0 : } else if (item->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR) {
7154 : : const struct rte_flow_item_ethdev *spec;
7155 : :
7156 : 0 : spec = (const struct rte_flow_item_ethdev *)item->spec;
7157 [ # # ]: 0 : if (spec)
7158 : : item_port_priv =
7159 : 0 : mlx5_port_to_eswitch_info(spec->port_id, true);
7160 : : break;
7161 : : }
7162 : : }
7163 : : /* The representor_id is UINT16_MAX for uplink. */
7164 [ # # # # ]: 0 : fdb_tx = (attr->transfer &&
7165 : : flow_source_vport_representor(priv, item_port_priv));
7166 : : /*
7167 : : * When reg_c_preserve is set, metadata registers Cx preserve
7168 : : * their value even through packet duplication.
7169 : : */
7170 : 0 : add_tag = (!fdb_tx ||
7171 [ # # ]: 0 : priv->sh->cdev->config.hca_attr.reg_c_preserve);
7172 : : if (add_tag)
7173 : 0 : sfx_items = (struct rte_flow_item *)((char *)sfx_actions
7174 : : + act_size);
7175 [ # # ]: 0 : if (modify_after_mirror)
7176 : 0 : jump_table = attr->group * MLX5_FLOW_TABLE_FACTOR +
7177 : : next_ft_step;
7178 : 0 : pre_actions = sfx_actions + actions_n;
7179 : 0 : tag_id = flow_sample_split_prep(dev, add_tag, items, sfx_items,
7180 : : actions, sfx_actions,
7181 : : pre_actions, actions_n,
7182 : : sample_action_pos,
7183 : : qrss_action_pos, jump_table,
7184 : : error);
7185 [ # # # # ]: 0 : if (tag_id < 0 || (add_tag && !tag_id)) {
7186 : 0 : ret = -rte_errno;
7187 : 0 : goto exit;
7188 : : }
7189 [ # # ]: 0 : if (modify_after_mirror)
7190 : 0 : flow_split_info->skip_scale =
7191 : : 1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT;
7192 : : /* Add the prefix subflow. */
7193 : 0 : ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
7194 : : items, pre_actions,
7195 : : flow_split_info, error);
7196 [ # # ]: 0 : if (ret) {
7197 : 0 : ret = -rte_errno;
7198 : 0 : goto exit;
7199 : : }
7200 : 0 : dev_flow->handle->split_flow_id = tag_id;
7201 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
7202 [ # # ]: 0 : if (!modify_after_mirror) {
7203 : : /* Set the sfx group attr. */
7204 : 0 : sample_res = (struct mlx5_flow_dv_sample_resource *)
7205 : : dev_flow->dv.sample_res;
7206 : 0 : sfx_tbl = (struct mlx5_flow_tbl_resource *)
7207 : : sample_res->normal_path_tbl;
7208 : 0 : sfx_tbl_data = container_of(sfx_tbl,
7209 : : struct mlx5_flow_tbl_data_entry,
7210 : : tbl);
7211 : 0 : sfx_attr.group = sfx_attr.transfer ?
7212 [ # # ]: 0 : (sfx_tbl_data->level - 1) : sfx_tbl_data->level;
7213 : : } else {
7214 : : MLX5_ASSERT(attr->transfer);
7215 : 0 : sfx_attr.group = jump_table;
7216 : : }
7217 : 0 : flow_split_info->prefix_layers =
7218 : 0 : flow_get_prefix_layer_flags(dev_flow);
7219 : : MLX5_ASSERT(wks);
7220 : 0 : flow_split_info->prefix_mark |= wks->mark;
7221 : : /* Suffix group level already be scaled with factor, set
7222 : : * MLX5_SCALE_FLOW_GROUP_BIT of skip_scale to 1 to avoid scale
7223 : : * again in translation.
7224 : : */
7225 : 0 : flow_split_info->skip_scale = 1 << MLX5_SCALE_FLOW_GROUP_BIT;
7226 : : #endif
7227 : : }
7228 : : /* Add the suffix subflow. */
7229 [ # # # # ]: 0 : ret = flow_create_split_meter(dev, flow, &sfx_attr,
7230 : : sfx_items ? sfx_items : items,
7231 : : sfx_actions ? sfx_actions : actions,
7232 : : flow_split_info, error);
7233 : 0 : exit:
7234 [ # # ]: 0 : if (sfx_actions)
7235 : 0 : mlx5_free(sfx_actions);
7236 : : return ret;
7237 : : }
7238 : :
7239 : : /**
7240 : : * Split the flow to subflow set. The splitters might be linked
7241 : : * in the chain, like this:
7242 : : * flow_create_split_outer() calls:
7243 : : * flow_create_split_meter() calls:
7244 : : * flow_create_split_metadata(meter_subflow_0) calls:
7245 : : * flow_create_split_inner(metadata_subflow_0)
7246 : : * flow_create_split_inner(metadata_subflow_1)
7247 : : * flow_create_split_inner(metadata_subflow_2)
7248 : : * flow_create_split_metadata(meter_subflow_1) calls:
7249 : : * flow_create_split_inner(metadata_subflow_0)
7250 : : * flow_create_split_inner(metadata_subflow_1)
7251 : : * flow_create_split_inner(metadata_subflow_2)
7252 : : *
7253 : : * This provide flexible way to add new levels of flow splitting.
7254 : : * The all of successfully created subflows are included to the
7255 : : * parent flow dev_flow list.
7256 : : *
7257 : : * @param dev
7258 : : * Pointer to Ethernet device.
7259 : : * @param[in] flow
7260 : : * Parent flow structure pointer.
7261 : : * @param[in] attr
7262 : : * Flow rule attributes.
7263 : : * @param[in] items
7264 : : * Pattern specification (list terminated by the END pattern item).
7265 : : * @param[in] actions
7266 : : * Associated actions (list terminated by the END action).
7267 : : * @param[in] flow_split_info
7268 : : * Pointer to flow split info structure.
7269 : : * @param[out] error
7270 : : * Perform verbose error reporting if not NULL.
7271 : : * @return
7272 : : * 0 on success, negative value otherwise
7273 : : */
7274 : : static int
7275 : : flow_create_split_outer(struct rte_eth_dev *dev,
7276 : : struct rte_flow *flow,
7277 : : const struct rte_flow_attr *attr,
7278 : : const struct rte_flow_item items[],
7279 : : const struct rte_flow_action actions[],
7280 : : struct mlx5_flow_split_info *flow_split_info,
7281 : : struct rte_flow_error *error)
7282 : : {
7283 : : int ret;
7284 : :
7285 : 0 : ret = flow_create_split_sample(dev, flow, attr, items,
7286 : : actions, flow_split_info, error);
7287 : : MLX5_ASSERT(ret <= 0);
7288 : : return ret;
7289 : : }
7290 : :
7291 : : static inline struct mlx5_flow_tunnel *
7292 : : flow_tunnel_from_rule(const struct mlx5_flow *flow)
7293 : : {
7294 : : struct mlx5_flow_tunnel *tunnel;
7295 : :
7296 : 0 : tunnel = RTE_PTR_UNQUAL(flow->tunnel);
7297 : :
7298 : : return tunnel;
7299 : : }
7300 : :
7301 : : /**
7302 : : * Create a flow and add it to @p list.
7303 : : *
7304 : : * @param dev
7305 : : * Pointer to Ethernet device.
7306 : : * @param list
7307 : : * Pointer to a TAILQ flow list. If this parameter NULL,
7308 : : * no list insertion occurred, flow is just created,
7309 : : * this is caller's responsibility to track the
7310 : : * created flow.
7311 : : * @param[in] attr
7312 : : * Flow rule attributes.
7313 : : * @param[in] items
7314 : : * Pattern specification (list terminated by the END pattern item).
7315 : : * @param[in] actions
7316 : : * Associated actions (list terminated by the END action).
7317 : : * @param[in] external
7318 : : * This flow rule is created by request external to PMD.
7319 : : * @param[out] error
7320 : : * Perform verbose error reporting if not NULL.
7321 : : *
7322 : : * @return
7323 : : * A flow index on success, 0 otherwise and rte_errno is set.
7324 : : */
7325 : : uintptr_t
7326 : 0 : flow_legacy_list_create(struct rte_eth_dev *dev, enum mlx5_flow_type type,
7327 : : const struct rte_flow_attr *attr,
7328 : : const struct rte_flow_item items[],
7329 : : const struct rte_flow_action original_actions[],
7330 : : bool external, struct rte_flow_error *error)
7331 : : {
7332 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7333 : : struct rte_flow *flow = NULL;
7334 : : struct mlx5_flow *dev_flow;
7335 : : const struct rte_flow_action_rss *rss = NULL;
7336 : : struct mlx5_translated_action_handle
7337 : : indir_actions[MLX5_MAX_INDIRECT_ACTIONS];
7338 : 0 : int indir_actions_n = MLX5_MAX_INDIRECT_ACTIONS;
7339 : : union {
7340 : : struct mlx5_flow_expand_rss buf;
7341 : : uint8_t buffer[8192];
7342 : : } expand_buffer;
7343 : : union {
7344 : : struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
7345 : : uint8_t buffer[2048];
7346 : : } actions_rx;
7347 : : union {
7348 : : struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
7349 : : uint8_t buffer[2048];
7350 : : } actions_hairpin_tx;
7351 : : union {
7352 : : struct rte_flow_item items[MLX5_MAX_SPLIT_ITEMS];
7353 : : uint8_t buffer[2048];
7354 : : } items_tx;
7355 : : struct mlx5_rte_flow_item_sq sq_specs[RTE_MAX_QUEUES_PER_PORT];
7356 : : struct mlx5_flow_expand_rss *buf = &expand_buffer.buf;
7357 : : struct mlx5_flow_rss_desc *rss_desc;
7358 : : const struct rte_flow_action *p_actions_rx;
7359 : : uint32_t i;
7360 : 0 : uint32_t idx = 0;
7361 : : int hairpin_flow;
7362 : 0 : struct rte_flow_attr attr_tx = { .priority = 0 };
7363 : : const struct rte_flow_action *actions;
7364 : 0 : struct rte_flow_action *translated_actions = NULL;
7365 : : struct mlx5_flow_tunnel *tunnel;
7366 : 0 : struct tunnel_default_miss_ctx default_miss_ctx = { 0, };
7367 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_push_thread_workspace();
7368 : 0 : struct mlx5_flow_split_info flow_split_info = {
7369 : : .external = !!external,
7370 : : .skip_scale = 0,
7371 : : .flow_idx = 0,
7372 : : .prefix_mark = 0,
7373 : : .prefix_layers = 0,
7374 : : .table_id = 0
7375 : : };
7376 : : int ret;
7377 : : struct mlx5_shared_action_rss *shared_rss_action;
7378 : :
7379 [ # # ]: 0 : if (!wks)
7380 : 0 : return rte_flow_error_set(error, ENOMEM,
7381 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7382 : : NULL,
7383 : : "failed to push flow workspace");
7384 : : memset(indir_actions, 0, sizeof(indir_actions));
7385 : 0 : rss_desc = &wks->rss_desc;
7386 : 0 : ret = flow_action_handles_translate(dev, original_actions,
7387 : : indir_actions,
7388 : : &indir_actions_n,
7389 : : &translated_actions, error);
7390 [ # # ]: 0 : if (ret < 0) {
7391 : : MLX5_ASSERT(translated_actions == NULL);
7392 : : return 0;
7393 : : }
7394 [ # # ]: 0 : actions = translated_actions ? translated_actions : original_actions;
7395 : : p_actions_rx = actions;
7396 : 0 : hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
7397 : 0 : ret = flow_drv_validate(dev, attr, items, p_actions_rx,
7398 : : external, hairpin_flow, error);
7399 [ # # ]: 0 : if (ret < 0)
7400 : 0 : goto error_before_hairpin_split;
7401 : 0 : flow = mlx5_ipool_zmalloc(priv->flows[type], &idx);
7402 [ # # ]: 0 : if (!flow) {
7403 : 0 : rte_errno = ENOMEM;
7404 : 0 : goto error_before_hairpin_split;
7405 : : }
7406 [ # # ]: 0 : if (hairpin_flow > 0) {
7407 [ # # ]: 0 : if (hairpin_flow > MLX5_MAX_SPLIT_ACTIONS) {
7408 : 0 : rte_errno = EINVAL;
7409 : 0 : goto error_before_hairpin_split;
7410 : : }
7411 : 0 : flow_hairpin_split(dev, actions, actions_rx.actions,
7412 : : actions_hairpin_tx.actions, items_tx.items,
7413 : : idx);
7414 : : p_actions_rx = actions_rx.actions;
7415 : : }
7416 : 0 : flow_split_info.flow_idx = idx;
7417 [ # # ]: 0 : flow->drv_type = flow_get_drv_type(dev, attr);
7418 : : MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
7419 : : flow->drv_type < MLX5_FLOW_TYPE_MAX);
7420 : : memset(rss_desc, 0, offsetof(struct mlx5_flow_rss_desc, queue));
7421 : : /* RSS Action only works on NIC RX domain */
7422 [ # # ]: 0 : if (attr->ingress)
7423 : 0 : rss = flow_get_rss_action(dev, p_actions_rx);
7424 [ # # ]: 0 : if (rss) {
7425 : : MLX5_ASSERT(rss->queue_num <= RTE_ETH_RSS_RETA_SIZE_512);
7426 : 0 : rss_desc->symmetric_hash_function = MLX5_RSS_IS_SYMM(rss->func);
7427 : : /*
7428 : : * The following information is required by
7429 : : * mlx5_flow_hashfields_adjust() in advance.
7430 : : */
7431 : 0 : rss_desc->level = rss->level;
7432 : : /* RSS type 0 indicates default RSS type (RTE_ETH_RSS_IP). */
7433 [ # # ]: 0 : rss_desc->types = !rss->types ? RTE_ETH_RSS_IP : rss->types;
7434 : : }
7435 : 0 : flow->dev_handles = 0;
7436 [ # # # # ]: 0 : if (rss && rss->types) {
7437 : : unsigned int graph_root;
7438 : :
7439 : 0 : graph_root = find_graph_root(rss->level);
7440 : 0 : ret = mlx5_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
7441 : : items, rss->types,
7442 : : mlx5_support_expansion, graph_root);
7443 : : MLX5_ASSERT(ret > 0 &&
7444 : : (unsigned int)ret < sizeof(expand_buffer.buffer));
7445 [ # # ]: 0 : if (rte_log_can_log(mlx5_logtype, RTE_LOG_DEBUG)) {
7446 [ # # ]: 0 : for (i = 0; i < buf->entries; ++i)
7447 : 0 : mlx5_dbg__print_pattern(buf->entry[i].pattern);
7448 : : }
7449 : : } else {
7450 : 0 : ret = mlx5_flow_expand_sqn((struct mlx5_flow_expand_sqn *)buf,
7451 : : sizeof(expand_buffer.buffer),
7452 : : items, sq_specs);
7453 [ # # ]: 0 : if (ret) {
7454 : 0 : rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_HANDLE,
7455 : : NULL, "not enough memory for rte_flow");
7456 : 0 : goto error;
7457 : : }
7458 [ # # ]: 0 : if (buf->entries == 0) {
7459 : 0 : buf->entries = 1;
7460 : 0 : buf->entry[0].pattern = (void *)(uintptr_t)items;
7461 : : }
7462 : : }
7463 : 0 : rss_desc->shared_rss = flow_get_shared_rss_action(dev, indir_actions,
7464 : : indir_actions_n);
7465 [ # # ]: 0 : for (i = 0; i < buf->entries; ++i) {
7466 : : /* Initialize flow split data. */
7467 : 0 : flow_split_info.prefix_layers = 0;
7468 : 0 : flow_split_info.prefix_mark = 0;
7469 : 0 : flow_split_info.skip_scale = 0;
7470 : : /*
7471 : : * The splitter may create multiple dev_flows,
7472 : : * depending on configuration. In the simplest
7473 : : * case it just creates unmodified original flow.
7474 : : */
7475 : : ret = flow_create_split_outer(dev, flow, attr,
7476 : 0 : buf->entry[i].pattern,
7477 : : p_actions_rx, &flow_split_info,
7478 : : error);
7479 [ # # ]: 0 : if (ret < 0)
7480 : 0 : goto error;
7481 [ # # ]: 0 : if (is_flow_tunnel_steer_rule(wks->flows[0].tof_type)) {
7482 : 0 : ret = flow_tunnel_add_default_miss(dev, flow, attr,
7483 : : p_actions_rx,
7484 : : idx,
7485 : : wks->flows[0].tunnel,
7486 : : &default_miss_ctx,
7487 : : error);
7488 [ # # ]: 0 : if (ret < 0) {
7489 : 0 : mlx5_free(default_miss_ctx.queue);
7490 : 0 : goto error;
7491 : : }
7492 : : }
7493 : : }
7494 : : /* Create the tx flow. */
7495 [ # # ]: 0 : if (hairpin_flow) {
7496 : 0 : attr_tx.group = MLX5_HAIRPIN_TX_TABLE;
7497 : 0 : attr_tx.ingress = 0;
7498 : 0 : attr_tx.egress = 1;
7499 : 0 : dev_flow = flow_drv_prepare(dev, flow, &attr_tx, items_tx.items,
7500 : : actions_hairpin_tx.actions,
7501 : : idx, error);
7502 [ # # ]: 0 : if (!dev_flow)
7503 : 0 : goto error;
7504 : 0 : dev_flow->flow = flow;
7505 : 0 : dev_flow->external = 0;
7506 : 0 : SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
7507 : : dev_flow->handle, next);
7508 : : ret = flow_drv_translate(dev, dev_flow, &attr_tx,
7509 : : items_tx.items,
7510 : : actions_hairpin_tx.actions, error);
7511 [ # # ]: 0 : if (ret < 0)
7512 : 0 : goto error;
7513 : : }
7514 : : /*
7515 : : * Update the metadata register copy table. If extensive
7516 : : * metadata feature is enabled and registers are supported
7517 : : * we might create the extra rte_flow for each unique
7518 : : * MARK/FLAG action ID.
7519 : : *
7520 : : * The table is updated for ingress and transfer flows only, because
7521 : : * the egress Flows belong to the different device and
7522 : : * copy table should be updated in peer NIC Rx domain.
7523 : : */
7524 [ # # # # ]: 0 : if ((attr->ingress || attr->transfer) &&
7525 [ # # ]: 0 : (external || attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
7526 : 0 : ret = flow_mreg_update_copy_table(dev, flow, actions, error);
7527 [ # # ]: 0 : if (ret)
7528 : 0 : goto error;
7529 : : }
7530 : : /*
7531 : : * If the flow is external (from application) OR device is started,
7532 : : * OR mreg discover, then apply immediately.
7533 : : */
7534 [ # # # # ]: 0 : if (external || dev->data->dev_started ||
7535 [ # # ]: 0 : (attr->group == MLX5_FLOW_MREG_CP_TABLE_GROUP &&
7536 [ # # ]: 0 : attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)) {
7537 : : ret = flow_drv_apply(dev, flow, error);
7538 [ # # ]: 0 : if (ret < 0)
7539 : 0 : goto error;
7540 : : }
7541 : 0 : flow->type = type;
7542 : 0 : flow_rxq_flags_set(dev, flow);
7543 : 0 : rte_free(translated_actions);
7544 : : tunnel = flow_tunnel_from_rule(wks->flows);
7545 [ # # ]: 0 : if (tunnel) {
7546 : 0 : flow->tunnel = 1;
7547 : 0 : flow->tunnel_id = tunnel->tunnel_id;
7548 : 0 : rte_atomic_fetch_add_explicit(&tunnel->refctn, 1, rte_memory_order_relaxed);
7549 : 0 : mlx5_free(default_miss_ctx.queue);
7550 : : }
7551 : 0 : mlx5_flow_pop_thread_workspace();
7552 : 0 : return idx;
7553 : 0 : error:
7554 : : MLX5_ASSERT(flow);
7555 : 0 : ret = rte_errno; /* Save rte_errno before cleanup. */
7556 : 0 : flow_mreg_del_copy_action(dev, flow);
7557 : : flow_drv_destroy(dev, flow);
7558 : :
7559 [ # # ]: 0 : if (rss_desc->shared_rss) {
7560 : : shared_rss_action = (struct mlx5_shared_action_rss *)
7561 : 0 : mlx5_ipool_get
7562 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
7563 : : rss_desc->shared_rss);
7564 [ # # ]: 0 : if (shared_rss_action)
7565 : 0 : rte_atomic_fetch_sub_explicit(&(shared_rss_action)->refcnt, 1,
7566 : : rte_memory_order_relaxed);
7567 : : }
7568 : 0 : mlx5_ipool_free(priv->flows[type], idx);
7569 : 0 : rte_errno = ret; /* Restore rte_errno. */
7570 : : ret = rte_errno;
7571 : : rte_errno = ret;
7572 : 0 : error_before_hairpin_split:
7573 : 0 : mlx5_flow_pop_thread_workspace();
7574 : 0 : rte_free(translated_actions);
7575 : 0 : return 0;
7576 : : }
7577 : :
7578 : : /**
7579 : : * Create a dedicated flow rule on e-switch table 0 (root table), to direct all
7580 : : * incoming packets to table 1.
7581 : : *
7582 : : * Other flow rules, requested for group n, will be created in
7583 : : * e-switch table n+1.
7584 : : * Jump action to e-switch group n will be created to group n+1.
7585 : : *
7586 : : * Used when working in switchdev mode, to utilise advantages of table 1
7587 : : * and above.
7588 : : *
7589 : : * @param dev
7590 : : * Pointer to Ethernet device.
7591 : : *
7592 : : * @return
7593 : : * Pointer to flow on success, NULL otherwise and rte_errno is set.
7594 : : */
7595 : : struct rte_flow *
7596 : 0 : mlx5_flow_create_esw_table_zero_flow(struct rte_eth_dev *dev)
7597 : : {
7598 : 0 : const struct rte_flow_attr attr = {
7599 : : .group = 0,
7600 : : .priority = 0,
7601 : : .ingress = 0,
7602 : : .egress = 0,
7603 : : .transfer = 1,
7604 : : };
7605 : 0 : const struct rte_flow_item pattern = {
7606 : : .type = RTE_FLOW_ITEM_TYPE_END,
7607 : : };
7608 : 0 : struct rte_flow_action_jump jump = {
7609 : : .group = 1,
7610 : : };
7611 : 0 : const struct rte_flow_action actions[] = {
7612 : : {
7613 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
7614 : : .conf = &jump,
7615 : : },
7616 : : {
7617 : : .type = RTE_FLOW_ACTION_TYPE_END,
7618 : : },
7619 : : };
7620 : : struct rte_flow_error error;
7621 : :
7622 : 0 : return (void *)(uintptr_t)mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
7623 : : &attr, &pattern,
7624 : : actions, false, &error);
7625 : : }
7626 : :
7627 : : /**
7628 : : * Create a dedicated flow rule on e-switch table 1, matches ESW manager
7629 : : * and sq number, directs all packets to peer vport.
7630 : : *
7631 : : * @param dev
7632 : : * Pointer to Ethernet device.
7633 : : * @param sq_num
7634 : : * SQ number.
7635 : : *
7636 : : * @return
7637 : : * Flow ID on success, 0 otherwise and rte_errno is set.
7638 : : */
7639 : : uint32_t
7640 : 0 : mlx5_flow_create_devx_sq_miss_flow(struct rte_eth_dev *dev, uint32_t sq_num)
7641 : : {
7642 : 0 : struct rte_flow_attr attr = {
7643 : : .group = 0,
7644 : : .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
7645 : : .ingress = 0,
7646 : : .egress = 0,
7647 : : .transfer = 1,
7648 : : };
7649 : 0 : struct rte_flow_item_port_id port_spec = {
7650 : : .id = MLX5_PORT_ESW_MGR,
7651 : : };
7652 : 0 : struct mlx5_rte_flow_item_sq sq_spec = {
7653 : : .queue = sq_num,
7654 : : };
7655 : 0 : struct rte_flow_item pattern[] = {
7656 : : {
7657 : : .type = RTE_FLOW_ITEM_TYPE_PORT_ID,
7658 : : .spec = &port_spec,
7659 : : },
7660 : : {
7661 : : .type = (enum rte_flow_item_type)
7662 : : MLX5_RTE_FLOW_ITEM_TYPE_SQ,
7663 : : .spec = &sq_spec,
7664 : : },
7665 : : {
7666 : : .type = RTE_FLOW_ITEM_TYPE_END,
7667 : : },
7668 : : };
7669 : 0 : struct rte_flow_action_jump jump = {
7670 : : .group = 1,
7671 : : };
7672 : 0 : struct rte_flow_action_port_id port = {
7673 : 0 : .id = dev->data->port_id,
7674 : : };
7675 : 0 : struct rte_flow_action actions[] = {
7676 : : {
7677 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
7678 : : .conf = &jump,
7679 : : },
7680 : : {
7681 : : .type = RTE_FLOW_ACTION_TYPE_END,
7682 : : },
7683 : : };
7684 : : struct rte_flow_error error;
7685 : :
7686 : : /*
7687 : : * Creates group 0, highest priority jump flow.
7688 : : * Matches txq to bypass kernel packets.
7689 : : */
7690 [ # # ]: 0 : if (mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_CTL, &attr, pattern, actions,
7691 : : false, &error) == 0)
7692 : : return 0;
7693 : : /* Create group 1, lowest priority redirect flow for txq. */
7694 : 0 : attr.group = 1;
7695 : 0 : actions[0].conf = &port;
7696 : 0 : actions[0].type = RTE_FLOW_ACTION_TYPE_PORT_ID;
7697 : 0 : return mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_CTL, &attr, pattern,
7698 : : actions, false, &error);
7699 : : }
7700 : :
7701 : : /**
7702 : : * Validate a flow supported by the NIC.
7703 : : *
7704 : : * @see rte_flow_validate()
7705 : : * @see rte_flow_ops
7706 : : */
7707 : : int
7708 : 0 : mlx5_flow_validate(struct rte_eth_dev *dev,
7709 : : const struct rte_flow_attr *attr,
7710 : : const struct rte_flow_item items[],
7711 : : const struct rte_flow_action original_actions[],
7712 : : struct rte_flow_error *error)
7713 : : {
7714 : : int hairpin_flow;
7715 : : struct mlx5_translated_action_handle
7716 : : indir_actions[MLX5_MAX_INDIRECT_ACTIONS];
7717 : 0 : int indir_actions_n = MLX5_MAX_INDIRECT_ACTIONS;
7718 : : const struct rte_flow_action *actions;
7719 : 0 : struct rte_flow_action *translated_actions = NULL;
7720 : 0 : int ret = flow_action_handles_translate(dev, original_actions,
7721 : : indir_actions,
7722 : : &indir_actions_n,
7723 : : &translated_actions, error);
7724 : :
7725 [ # # ]: 0 : if (ret)
7726 : : return ret;
7727 [ # # ]: 0 : actions = translated_actions ? translated_actions : original_actions;
7728 : 0 : hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
7729 : 0 : ret = flow_drv_validate(dev, attr, items, actions,
7730 : : true, hairpin_flow, error);
7731 : 0 : rte_free(translated_actions);
7732 : 0 : return ret;
7733 : : }
7734 : :
7735 : : static int
7736 : 0 : mlx5_flow_cache_flow_info(struct rte_eth_dev *dev,
7737 : : const struct rte_flow_attr *attr,
7738 : : const uint32_t orig_prio,
7739 : : const struct rte_flow_item *items,
7740 : : const struct rte_flow_action *actions,
7741 : : uint32_t flow_idx)
7742 : : {
7743 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7744 : : struct rte_pmd_mlx5_flow_engine_mode_info *mode_info = &priv->mode_info;
7745 : : struct mlx5_dv_flow_info *flow_info, *tmp_info;
7746 : : struct rte_flow_error error;
7747 : : int len, ret;
7748 : :
7749 : 0 : flow_info = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*flow_info), 0, SOCKET_ID_ANY);
7750 [ # # ]: 0 : if (!flow_info) {
7751 : 0 : DRV_LOG(ERR, "No enough memory for flow_info caching.");
7752 : 0 : return -1;
7753 : : }
7754 : 0 : flow_info->orig_prio = orig_prio;
7755 : 0 : flow_info->attr = *attr;
7756 : : /* Standby mode rule awlays saves it in low priority entry. */
7757 : 0 : flow_info->flow_idx_low_prio = flow_idx;
7758 : :
7759 : : /* Store matching items. */
7760 : 0 : ret = rte_flow_conv(RTE_FLOW_CONV_OP_PATTERN, NULL, 0, items, &error);
7761 [ # # ]: 0 : if (ret <= 0) {
7762 : 0 : DRV_LOG(ERR, "Can't get items length.");
7763 : 0 : goto end;
7764 : : }
7765 : 0 : len = RTE_ALIGN(ret, 16);
7766 : 0 : flow_info->items = mlx5_malloc(MLX5_MEM_ZERO, len, 0, SOCKET_ID_ANY);
7767 [ # # ]: 0 : if (!flow_info->items) {
7768 : 0 : DRV_LOG(ERR, "No enough memory for items caching.");
7769 : 0 : goto end;
7770 : : }
7771 : 0 : ret = rte_flow_conv(RTE_FLOW_CONV_OP_PATTERN, flow_info->items, ret, items, &error);
7772 [ # # ]: 0 : if (ret <= 0) {
7773 : 0 : DRV_LOG(ERR, "Can't duplicate items.");
7774 : 0 : goto end;
7775 : : }
7776 : :
7777 : : /* Store flow actions. */
7778 : 0 : ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTIONS, NULL, 0, actions, &error);
7779 [ # # ]: 0 : if (ret <= 0) {
7780 : 0 : DRV_LOG(ERR, "Can't get actions length.");
7781 : 0 : goto end;
7782 : : }
7783 : 0 : len = RTE_ALIGN(ret, 16);
7784 : 0 : flow_info->actions = mlx5_malloc(MLX5_MEM_ZERO, len, 0, SOCKET_ID_ANY);
7785 [ # # ]: 0 : if (!flow_info->actions) {
7786 : 0 : DRV_LOG(ERR, "No enough memory for actions caching.");
7787 : 0 : goto end;
7788 : : }
7789 : 0 : ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTIONS, flow_info->actions, ret, actions, &error);
7790 [ # # ]: 0 : if (ret <= 0) {
7791 : 0 : DRV_LOG(ERR, "Can't duplicate actions.");
7792 : 0 : goto end;
7793 : : }
7794 : :
7795 : : /* Insert to the list end. */
7796 [ # # ]: 0 : if (LIST_EMPTY(&mode_info->hot_upgrade)) {
7797 : 0 : LIST_INSERT_HEAD(&mode_info->hot_upgrade, flow_info, next);
7798 : : } else {
7799 : : tmp_info = LIST_FIRST(&mode_info->hot_upgrade);
7800 [ # # ]: 0 : while (LIST_NEXT(tmp_info, next))
7801 : : tmp_info = LIST_NEXT(tmp_info, next);
7802 : 0 : LIST_INSERT_AFTER(tmp_info, flow_info, next);
7803 : : }
7804 : : return 0;
7805 : 0 : end:
7806 [ # # ]: 0 : if (flow_info->items)
7807 : 0 : mlx5_free(flow_info->items);
7808 [ # # ]: 0 : if (flow_info->actions)
7809 : 0 : mlx5_free(flow_info->actions);
7810 : 0 : mlx5_free(flow_info);
7811 : 0 : return -1;
7812 : : }
7813 : :
7814 : : static int
7815 : 0 : mlx5_flow_cache_flow_toggle(struct rte_eth_dev *dev, bool orig_prio)
7816 : : {
7817 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7818 : : struct rte_pmd_mlx5_flow_engine_mode_info *mode_info = &priv->mode_info;
7819 : : struct mlx5_dv_flow_info *flow_info;
7820 : : struct rte_flow_attr attr;
7821 : : struct rte_flow_error error;
7822 : : struct rte_flow *high, *low;
7823 : :
7824 : 0 : flow_info = LIST_FIRST(&mode_info->hot_upgrade);
7825 [ # # ]: 0 : while (flow_info) {
7826 : : /* DUP flow may have the same priority. */
7827 [ # # ]: 0 : if (flow_info->orig_prio != flow_info->attr.priority) {
7828 : 0 : attr = flow_info->attr;
7829 [ # # ]: 0 : if (orig_prio)
7830 : 0 : attr.priority = flow_info->orig_prio;
7831 : 0 : flow_info->flow_idx_high_prio = mlx5_flow_list_create(dev,
7832 : : MLX5_FLOW_TYPE_GEN, &attr,
7833 : 0 : flow_info->items, flow_info->actions,
7834 : : true, &error);
7835 [ # # ]: 0 : if (!flow_info->flow_idx_high_prio) {
7836 : 0 : DRV_LOG(ERR, "Priority toggle failed internally.");
7837 : 0 : goto err;
7838 : : }
7839 : : }
7840 : 0 : flow_info = LIST_NEXT(flow_info, next);
7841 : : }
7842 : : /* Delete the low priority rules and swap the flow handle. */
7843 : 0 : flow_info = LIST_FIRST(&mode_info->hot_upgrade);
7844 [ # # ]: 0 : while (flow_info) {
7845 : : MLX5_ASSERT(flow_info->flow_idx_low_prio);
7846 [ # # ]: 0 : if (flow_info->orig_prio != flow_info->attr.priority) {
7847 : 0 : high = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
7848 : : flow_info->flow_idx_high_prio);
7849 : 0 : low = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
7850 : : flow_info->flow_idx_low_prio);
7851 [ # # ]: 0 : if (high && low) {
7852 : 0 : RTE_SWAP(*low, *high);
7853 : 0 : mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN,
7854 : 0 : flow_info->flow_idx_low_prio);
7855 : 0 : flow_info->flow_idx_high_prio = 0;
7856 : : }
7857 : : }
7858 : 0 : flow_info = LIST_NEXT(flow_info, next);
7859 : : }
7860 : : return 0;
7861 : : err:
7862 : : /* Destroy preceding successful high priority rules. */
7863 : 0 : flow_info = LIST_FIRST(&mode_info->hot_upgrade);
7864 [ # # ]: 0 : while (flow_info) {
7865 [ # # ]: 0 : if (flow_info->orig_prio != flow_info->attr.priority) {
7866 [ # # ]: 0 : if (flow_info->flow_idx_high_prio)
7867 : 0 : mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN,
7868 : : flow_info->flow_idx_high_prio);
7869 : : else
7870 : : break;
7871 : 0 : flow_info->flow_idx_high_prio = 0;
7872 : : }
7873 : 0 : flow_info = LIST_NEXT(flow_info, next);
7874 : : }
7875 : : return -1;
7876 : : }
7877 : :
7878 : : /**
7879 : : * Set the mode of the flow engine of a process to active or standby during live migration.
7880 : : *
7881 : : * @param[in] mode
7882 : : * MLX5 flow engine mode, @see `enum rte_pmd_mlx5_flow_engine_mode`.
7883 : : * @param[in] flags
7884 : : * Flow engine mode specific flags.
7885 : : *
7886 : : * @return
7887 : : * Negative value on error, positive on success.
7888 : : */
7889 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_mlx5_flow_engine_set_mode, 23.03)
7890 : : int
7891 : 0 : rte_pmd_mlx5_flow_engine_set_mode(enum rte_pmd_mlx5_flow_engine_mode mode, uint32_t flags)
7892 : : {
7893 : : struct mlx5_priv *priv;
7894 : : struct rte_pmd_mlx5_flow_engine_mode_info *mode_info;
7895 : : struct mlx5_dv_flow_info *flow_info, *tmp_info;
7896 : : uint16_t port, port_id;
7897 : : uint16_t toggle_num = 0;
7898 : : struct rte_eth_dev *dev;
7899 : : enum rte_pmd_mlx5_flow_engine_mode orig_mode;
7900 : : uint32_t orig_flags;
7901 : : bool need_toggle = false;
7902 : :
7903 : : /* Check if flags combinations are supported. */
7904 [ # # ]: 0 : if (flags && flags != RTE_PMD_MLX5_FLOW_ENGINE_FLAG_STANDBY_DUP_INGRESS) {
7905 : 0 : DRV_LOG(ERR, "Doesn't support such flags %u", flags);
7906 : 0 : return -1;
7907 : : }
7908 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port, NULL) {
7909 : 0 : dev = &rte_eth_devices[port];
7910 : 0 : priv = dev->data->dev_private;
7911 : : mode_info = &priv->mode_info;
7912 : : /* No mode change. Assume all devices hold the same mode. */
7913 [ # # ]: 0 : if (mode_info->mode == mode) {
7914 : 0 : DRV_LOG(INFO, "Process flow engine has been in mode %u", mode);
7915 [ # # # # ]: 0 : if (mode_info->mode_flag != flags && !LIST_EMPTY(&mode_info->hot_upgrade)) {
7916 : 0 : DRV_LOG(ERR, "Port %u has rule cache with different flag %u\n",
7917 : : port, mode_info->mode_flag);
7918 : 0 : orig_mode = mode_info->mode;
7919 : 0 : orig_flags = mode_info->mode_flag;
7920 : 0 : goto err;
7921 : : }
7922 : 0 : mode_info->mode_flag = flags;
7923 : 0 : toggle_num++;
7924 : 0 : continue;
7925 : : }
7926 : : /* Active -> standby. */
7927 [ # # ]: 0 : if (mode == RTE_PMD_MLX5_FLOW_ENGINE_MODE_STANDBY) {
7928 [ # # ]: 0 : if (!LIST_EMPTY(&mode_info->hot_upgrade)) {
7929 : 0 : DRV_LOG(ERR, "Cached rule existed");
7930 : 0 : orig_mode = mode_info->mode;
7931 : 0 : orig_flags = mode_info->mode_flag;
7932 : 0 : goto err;
7933 : : }
7934 : 0 : mode_info->mode_flag = flags;
7935 : 0 : mode_info->mode = mode;
7936 : 0 : toggle_num++;
7937 : : /* Standby -> active. */
7938 [ # # ]: 0 : } else if (mode == RTE_PMD_MLX5_FLOW_ENGINE_MODE_ACTIVE) {
7939 [ # # ]: 0 : if (LIST_EMPTY(&mode_info->hot_upgrade)) {
7940 : 0 : DRV_LOG(INFO, "No cached rule existed");
7941 : : } else {
7942 [ # # ]: 0 : if (mlx5_flow_cache_flow_toggle(dev, true)) {
7943 : 0 : orig_mode = mode_info->mode;
7944 : 0 : orig_flags = mode_info->mode_flag;
7945 : : need_toggle = true;
7946 : 0 : goto err;
7947 : : }
7948 : : }
7949 : 0 : toggle_num++;
7950 : : }
7951 : : }
7952 [ # # ]: 0 : if (mode == RTE_PMD_MLX5_FLOW_ENGINE_MODE_ACTIVE) {
7953 : : /* Clear cache flow rules. */
7954 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port, NULL) {
7955 : 0 : priv = rte_eth_devices[port].data->dev_private;
7956 : : mode_info = &priv->mode_info;
7957 : 0 : flow_info = LIST_FIRST(&mode_info->hot_upgrade);
7958 [ # # ]: 0 : while (flow_info) {
7959 : 0 : tmp_info = LIST_NEXT(flow_info, next);
7960 [ # # ]: 0 : LIST_REMOVE(flow_info, next);
7961 : 0 : mlx5_free(flow_info->actions);
7962 : 0 : mlx5_free(flow_info->items);
7963 : 0 : mlx5_free(flow_info);
7964 : : flow_info = tmp_info;
7965 : : }
7966 : : MLX5_ASSERT(LIST_EMPTY(&mode_info->hot_upgrade));
7967 : : }
7968 : : }
7969 : 0 : return toggle_num;
7970 : 0 : err:
7971 : : /* Rollback all preceding successful ports. */
7972 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port_id, NULL) {
7973 [ # # ]: 0 : if (port_id == port)
7974 : : break;
7975 : 0 : priv = rte_eth_devices[port_id].data->dev_private;
7976 : : mode_info = &priv->mode_info;
7977 [ # # # # : 0 : if (need_toggle && !LIST_EMPTY(&mode_info->hot_upgrade) &&
# # ]
7978 : 0 : mlx5_flow_cache_flow_toggle(dev, false))
7979 : : return -EPERM;
7980 : 0 : mode_info->mode = orig_mode;
7981 : 0 : mode_info->mode_flag = orig_flags;
7982 : : }
7983 : : return -EINVAL;
7984 : : }
7985 : : /**
7986 : : * Create a flow.
7987 : : *
7988 : : * @see rte_flow_create()
7989 : : * @see rte_flow_ops
7990 : : */
7991 : : struct rte_flow *
7992 : 0 : mlx5_flow_create(struct rte_eth_dev *dev,
7993 : : const struct rte_flow_attr *attr,
7994 : : const struct rte_flow_item items[],
7995 : : const struct rte_flow_action actions[],
7996 : : struct rte_flow_error *error)
7997 : : {
7998 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7999 : : struct rte_flow_attr *new_attr = (void *)(uintptr_t)attr;
8000 : 0 : uint32_t prio = attr->priority;
8001 : : uintptr_t flow_idx;
8002 : :
8003 : : /*
8004 : : * If the device is not started yet, it is not allowed to created a
8005 : : * flow from application. PMD default flows and traffic control flows
8006 : : * are not affected.
8007 : : */
8008 [ # # ]: 0 : if (unlikely(!dev->data->dev_started)) {
8009 : 0 : DRV_LOG(DEBUG, "port %u is not started when "
8010 : : "inserting a flow", dev->data->port_id);
8011 : 0 : rte_flow_error_set(error, ENODEV,
8012 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8013 : : NULL,
8014 : : "port not started");
8015 : 0 : return NULL;
8016 : : }
8017 [ # # ]: 0 : if (unlikely(mlx5_need_cache_flow(priv, attr))) {
8018 [ # # ]: 0 : if (attr->transfer ||
8019 [ # # # # ]: 0 : (attr->ingress && !(priv->mode_info.mode_flag &
8020 : : RTE_PMD_MLX5_FLOW_ENGINE_FLAG_STANDBY_DUP_INGRESS)))
8021 : 0 : new_attr->priority += 1;
8022 : : }
8023 : 0 : flow_idx = mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_GEN, attr, items, actions,
8024 : : true, error);
8025 [ # # ]: 0 : if (!flow_idx)
8026 : : return NULL;
8027 [ # # ]: 0 : if (unlikely(mlx5_need_cache_flow(priv, attr))) {
8028 [ # # ]: 0 : if (mlx5_flow_cache_flow_info(dev, attr, prio, items, actions, flow_idx)) {
8029 : 0 : mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN, flow_idx);
8030 : : flow_idx = 0;
8031 : : }
8032 : : }
8033 : 0 : return (void *)(uintptr_t)flow_idx;
8034 : : }
8035 : :
8036 : : uintptr_t
8037 : 0 : mlx5_flow_list_create(struct rte_eth_dev *dev, enum mlx5_flow_type type,
8038 : : const struct rte_flow_attr *attr,
8039 : : const struct rte_flow_item items[],
8040 : : const struct rte_flow_action actions[],
8041 : : bool external, struct rte_flow_error *error)
8042 : : {
8043 : : const struct mlx5_flow_driver_ops *fops;
8044 : 0 : enum mlx5_flow_drv_type drv_type = flow_get_drv_type(dev, attr);
8045 : :
8046 : 0 : fops = flow_get_drv_ops(drv_type);
8047 : 0 : return fops->list_create(dev, type, attr, items, actions, external,
8048 : : error);
8049 : : }
8050 : :
8051 : : /**
8052 : : * Destroy a flow in a list.
8053 : : *
8054 : : * @param dev
8055 : : * Pointer to Ethernet device.
8056 : : * @param[in] flow_idx
8057 : : * Index of flow to destroy.
8058 : : */
8059 : : void
8060 : 0 : flow_legacy_list_destroy(struct rte_eth_dev *dev, enum mlx5_flow_type type,
8061 : : uintptr_t flow_idx)
8062 : : {
8063 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8064 : 0 : struct rte_flow *flow = mlx5_ipool_get(priv->flows[type], (uint32_t)flow_idx);
8065 : :
8066 [ # # ]: 0 : if (!flow)
8067 : : return;
8068 : : MLX5_ASSERT((type >= MLX5_FLOW_TYPE_CTL) && (type < MLX5_FLOW_TYPE_MAXI));
8069 : : MLX5_ASSERT(flow->type == type);
8070 : : /*
8071 : : * Update RX queue flags only if port is started, otherwise it is
8072 : : * already clean.
8073 : : */
8074 [ # # ]: 0 : if (dev->data->dev_started)
8075 : 0 : flow_rxq_flags_trim(dev, flow);
8076 : : flow_drv_destroy(dev, flow);
8077 [ # # ]: 0 : if (flow->tunnel) {
8078 : : struct mlx5_flow_tunnel *tunnel;
8079 : :
8080 : 0 : tunnel = mlx5_find_tunnel_id(dev, flow->tunnel_id);
8081 : 0 : RTE_VERIFY(tunnel);
8082 [ # # ]: 0 : if (!(rte_atomic_fetch_sub_explicit(&tunnel->refctn, 1,
8083 : : rte_memory_order_relaxed) - 1))
8084 : 0 : mlx5_flow_tunnel_free(dev, tunnel);
8085 : : }
8086 : 0 : flow_mreg_del_copy_action(dev, flow);
8087 : 0 : mlx5_ipool_free(priv->flows[type], flow_idx);
8088 : : }
8089 : :
8090 : : void
8091 [ # # ]: 0 : mlx5_flow_list_destroy(struct rte_eth_dev *dev, enum mlx5_flow_type type,
8092 : : uintptr_t flow_idx)
8093 : : {
8094 : : const struct mlx5_flow_driver_ops *fops;
8095 : : struct rte_flow_attr attr = { .transfer = 0 };
8096 : : enum mlx5_flow_drv_type drv_type = flow_get_drv_type(dev, &attr);
8097 : :
8098 : 0 : fops = flow_get_drv_ops(drv_type);
8099 : 0 : fops->list_destroy(dev, type, flow_idx);
8100 : 0 : }
8101 : :
8102 : : /**
8103 : : * Destroy all flows.
8104 : : *
8105 : : * @param dev
8106 : : * Pointer to Ethernet device.
8107 : : * @param type
8108 : : * Flow type to be flushed.
8109 : : * @param active
8110 : : * If flushing is called actively.
8111 : : */
8112 : : void
8113 : 0 : mlx5_flow_list_flush(struct rte_eth_dev *dev, enum mlx5_flow_type type,
8114 : : bool active)
8115 : : {
8116 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8117 : 0 : uint32_t num_flushed = 0, fidx = 1;
8118 : : struct rte_flow *flow;
8119 : : struct rte_pmd_mlx5_flow_engine_mode_info *mode_info = &priv->mode_info;
8120 : : struct mlx5_dv_flow_info *flow_info;
8121 : :
8122 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8123 [ # # # # ]: 0 : if (priv->sh->config.dv_flow_en == 2 &&
8124 : : type == MLX5_FLOW_TYPE_GEN) {
8125 : 0 : priv->hws_rule_flushing = true;
8126 : 0 : flow_hw_q_flow_flush(dev, NULL);
8127 : 0 : priv->hws_rule_flushing = false;
8128 : : }
8129 : : #endif
8130 [ # # ]: 0 : MLX5_IPOOL_FOREACH(priv->flows[type], fidx, flow) {
8131 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2) {
8132 : 0 : mlx5_flow_list_destroy(dev, type, (uintptr_t)flow);
8133 : : } else {
8134 : 0 : mlx5_flow_list_destroy(dev, type, fidx);
8135 : : }
8136 [ # # # # ]: 0 : if (unlikely(mlx5_need_cache_flow(priv, NULL) && type == MLX5_FLOW_TYPE_GEN)) {
8137 : 0 : flow_info = LIST_FIRST(&mode_info->hot_upgrade);
8138 [ # # ]: 0 : while (flow_info) {
8139 : : /* Romove the cache flow info. */
8140 [ # # ]: 0 : if (flow_info->flow_idx_low_prio == (uint32_t)(uintptr_t)fidx) {
8141 : : MLX5_ASSERT(!flow_info->flow_idx_high_prio);
8142 [ # # ]: 0 : LIST_REMOVE(flow_info, next);
8143 : 0 : mlx5_free(flow_info->items);
8144 : 0 : mlx5_free(flow_info->actions);
8145 : 0 : mlx5_free(flow_info);
8146 : 0 : break;
8147 : : }
8148 : 0 : flow_info = LIST_NEXT(flow_info, next);
8149 : : }
8150 : : }
8151 : 0 : num_flushed++;
8152 : : }
8153 [ # # ]: 0 : if (active) {
8154 : 0 : DRV_LOG(INFO, "port %u: %u flows flushed before stopping",
8155 : : dev->data->port_id, num_flushed);
8156 : : }
8157 : 0 : }
8158 : :
8159 : : /**
8160 : : * Stop all default actions for flows.
8161 : : *
8162 : : * @param dev
8163 : : * Pointer to Ethernet device.
8164 : : */
8165 : : void
8166 : 0 : mlx5_flow_stop_default(struct rte_eth_dev *dev)
8167 : : {
8168 : : #ifdef HAVE_MLX5_HWS_SUPPORT
8169 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8170 : :
8171 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2) {
8172 : 0 : mlx5_flow_nta_del_default_copy_action(dev);
8173 [ # # ]: 0 : if (!rte_atomic_load_explicit(&priv->hws_mark_refcnt,
8174 : : rte_memory_order_relaxed))
8175 : 0 : flow_hw_rxq_flag_set(dev, false);
8176 : 0 : return;
8177 : : }
8178 : : #endif
8179 : 0 : flow_mreg_del_default_copy_action(dev);
8180 : 0 : flow_rxq_flags_clear(dev);
8181 : : }
8182 : :
8183 : : /**
8184 : : * Set rxq flag.
8185 : : *
8186 : : * @param[in] dev
8187 : : * Pointer to the rte_eth_dev structure.
8188 : : * @param[in] enable
8189 : : * Flag to enable or not.
8190 : : */
8191 : : void
8192 : 0 : flow_hw_rxq_flag_set(struct rte_eth_dev *dev, bool enable)
8193 : : {
8194 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8195 : : unsigned int i;
8196 : :
8197 [ # # # # : 0 : if ((!priv->mark_enabled && !enable) ||
# # ]
8198 [ # # ]: 0 : (priv->mark_enabled && enable))
8199 : : return;
8200 [ # # ]: 0 : for (i = 0; i < priv->rxqs_n; ++i) {
8201 : 0 : struct mlx5_rxq_ctrl *rxq_ctrl = mlx5_rxq_ctrl_get(dev, i);
8202 : :
8203 : : /* With RXQ start/stop feature, RXQ might be stopped. */
8204 [ # # ]: 0 : if (!rxq_ctrl)
8205 : 0 : continue;
8206 : 0 : rxq_ctrl->rxq.mark = enable;
8207 : : }
8208 : 0 : priv->mark_enabled = enable;
8209 : : }
8210 : :
8211 : : /**
8212 : : * Start all default actions for flows.
8213 : : *
8214 : : * @param dev
8215 : : * Pointer to Ethernet device.
8216 : : * @return
8217 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
8218 : : */
8219 : : int
8220 : 0 : mlx5_flow_start_default(struct rte_eth_dev *dev)
8221 : : {
8222 : : struct rte_flow_error error;
8223 : : #ifdef HAVE_MLX5_HWS_SUPPORT
8224 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8225 : :
8226 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2) {
8227 : : /*
8228 : : * Ignore this failure, if the proxy port is not started, other
8229 : : * default jump actions are not created and this rule will not
8230 : : * be hit.
8231 : : */
8232 [ # # ]: 0 : if (mlx5_flow_nta_add_default_copy_action(dev, &error)) {
8233 : 0 : DRV_LOG(DEBUG, "port %u failed to start default copy action: %s",
8234 : : dev->data->port_id, strerror(rte_errno));
8235 : 0 : return 0;
8236 : : }
8237 : : }
8238 : : #endif
8239 : : /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
8240 : 0 : return flow_mreg_add_default_copy_action(dev, &error);
8241 : : }
8242 : :
8243 : : /**
8244 : : * Release key of thread specific flow workspace data.
8245 : : */
8246 : : void
8247 : 0 : flow_release_workspace(void *data)
8248 : : {
8249 : : struct mlx5_flow_workspace *wks = data;
8250 : : struct mlx5_flow_workspace *next;
8251 : :
8252 [ # # ]: 0 : while (wks) {
8253 : 0 : next = wks->next;
8254 : 0 : free(wks);
8255 : : wks = next;
8256 : : }
8257 : 0 : }
8258 : :
8259 : : /**
8260 : : * Get thread specific current flow workspace.
8261 : : *
8262 : : * @return pointer to thread specific flow workspace data, NULL on error.
8263 : : */
8264 : : struct mlx5_flow_workspace*
8265 : 0 : mlx5_flow_get_thread_workspace(void)
8266 : : {
8267 : : struct mlx5_flow_workspace *data;
8268 : :
8269 : 0 : data = mlx5_flow_os_get_specific_workspace();
8270 : : MLX5_ASSERT(data && data->inuse);
8271 [ # # # # ]: 0 : if (!data || !data->inuse)
8272 : 0 : DRV_LOG(ERR, "flow workspace not initialized.");
8273 : 0 : return data;
8274 : : }
8275 : :
8276 : : /**
8277 : : * Allocate and init new flow workspace.
8278 : : *
8279 : : * @return pointer to flow workspace data, NULL on error.
8280 : : */
8281 : : static struct mlx5_flow_workspace*
8282 : 0 : flow_alloc_thread_workspace(void)
8283 : : {
8284 : : size_t data_size = RTE_ALIGN(sizeof(struct mlx5_flow_workspace), sizeof(long));
8285 : : size_t rss_queue_array_size = sizeof(uint16_t) * RTE_ETH_RSS_RETA_SIZE_512;
8286 : : size_t alloc_size = data_size + rss_queue_array_size;
8287 : : #ifdef HAVE_MLX5_HWS_SUPPORT
8288 : : /* Dummy table size for the non-template API. */
8289 : : alloc_size += sizeof(struct rte_flow_template_table);
8290 : : #endif
8291 : 0 : struct mlx5_flow_workspace *data = calloc(1, alloc_size);
8292 : :
8293 [ # # ]: 0 : if (!data) {
8294 : 0 : DRV_LOG(ERR, "Failed to allocate flow workspace memory.");
8295 : 0 : return NULL;
8296 : : }
8297 : 0 : data->rss_desc.queue = RTE_PTR_ADD(data, data_size);
8298 : : #ifdef HAVE_MLX5_HWS_SUPPORT
8299 : 0 : data->table = RTE_PTR_ADD(data->rss_desc.queue, rss_queue_array_size);
8300 : : #endif
8301 : 0 : return data;
8302 : : }
8303 : :
8304 : : /**
8305 : : * Get new thread specific flow workspace.
8306 : : *
8307 : : * If current workspace inuse, create new one and set as current.
8308 : : *
8309 : : * @return pointer to thread specific flow workspace data, NULL on error.
8310 : : */
8311 : : struct mlx5_flow_workspace*
8312 : 0 : mlx5_flow_push_thread_workspace(void)
8313 : : {
8314 : : struct mlx5_flow_workspace *curr;
8315 : : struct mlx5_flow_workspace *data;
8316 : :
8317 : 0 : curr = mlx5_flow_os_get_specific_workspace();
8318 [ # # ]: 0 : if (!curr) {
8319 : 0 : data = flow_alloc_thread_workspace();
8320 [ # # ]: 0 : if (!data)
8321 : : return NULL;
8322 : 0 : mlx5_flow_os_workspace_gc_add(data);
8323 [ # # ]: 0 : } else if (!curr->inuse) {
8324 : : data = curr;
8325 [ # # ]: 0 : } else if (curr->next) {
8326 : : data = curr->next;
8327 : : } else {
8328 : 0 : data = flow_alloc_thread_workspace();
8329 [ # # ]: 0 : if (!data)
8330 : : return NULL;
8331 : 0 : curr->next = data;
8332 : 0 : data->prev = curr;
8333 : : }
8334 : 0 : data->inuse = 1;
8335 : 0 : data->flow_idx = 0;
8336 : : /* Set as current workspace */
8337 [ # # ]: 0 : if (mlx5_flow_os_set_specific_workspace(data))
8338 : 0 : DRV_LOG(ERR, "Failed to set flow workspace to thread.");
8339 : : return data;
8340 : : }
8341 : :
8342 : : /**
8343 : : * Close current thread specific flow workspace.
8344 : : *
8345 : : * If previous workspace available, set it as current.
8346 : : *
8347 : : * @return pointer to thread specific flow workspace data, NULL on error.
8348 : : */
8349 : : void
8350 : 0 : mlx5_flow_pop_thread_workspace(void)
8351 : : {
8352 : 0 : struct mlx5_flow_workspace *data = mlx5_flow_get_thread_workspace();
8353 : :
8354 [ # # ]: 0 : if (!data)
8355 : : return;
8356 [ # # ]: 0 : if (!data->inuse) {
8357 : 0 : DRV_LOG(ERR, "Failed to close unused flow workspace.");
8358 : 0 : return;
8359 : : }
8360 : 0 : data->inuse = 0;
8361 [ # # ]: 0 : if (!data->prev)
8362 : : return;
8363 [ # # ]: 0 : if (mlx5_flow_os_set_specific_workspace(data->prev))
8364 : 0 : DRV_LOG(ERR, "Failed to set flow workspace to thread.");
8365 : : }
8366 : :
8367 : : /**
8368 : : * Verify the flow list is empty
8369 : : *
8370 : : * @param dev
8371 : : * Pointer to Ethernet device.
8372 : : *
8373 : : * @return the number of flows not released.
8374 : : */
8375 : : int
8376 : 0 : mlx5_flow_verify(struct rte_eth_dev *dev __rte_unused)
8377 : : {
8378 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8379 : : struct rte_flow *flow;
8380 : : uint32_t idx = 0;
8381 : : int ret = 0, i;
8382 : :
8383 [ # # ]: 0 : for (i = 0; i < MLX5_FLOW_TYPE_MAXI; i++) {
8384 [ # # ]: 0 : MLX5_IPOOL_FOREACH(priv->flows[i], idx, flow) {
8385 : 0 : DRV_LOG(DEBUG, "port %u flow %p still referenced",
8386 : : dev->data->port_id, (void *)flow);
8387 : 0 : ret++;
8388 : : }
8389 : : }
8390 : 0 : return ret;
8391 : : }
8392 : :
8393 : : /**
8394 : : * Enable default hairpin egress flow.
8395 : : *
8396 : : * @param dev
8397 : : * Pointer to Ethernet device.
8398 : : * @param sq_num
8399 : : * The SQ hw number.
8400 : : *
8401 : : * @return
8402 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
8403 : : */
8404 : : int
8405 : 0 : mlx5_ctrl_flow_source_queue(struct rte_eth_dev *dev,
8406 : : uint32_t sq_num)
8407 : : {
8408 : 0 : const struct rte_flow_attr attr = {
8409 : : .egress = 1,
8410 : : .priority = 0,
8411 : : };
8412 : 0 : struct mlx5_rte_flow_item_sq queue_spec = {
8413 : : .queue = sq_num,
8414 : : };
8415 : 0 : struct mlx5_rte_flow_item_sq queue_mask = {
8416 : : .queue = UINT32_MAX,
8417 : : };
8418 : 0 : struct rte_flow_item items[] = {
8419 : : {
8420 : : .type = (enum rte_flow_item_type)
8421 : : MLX5_RTE_FLOW_ITEM_TYPE_SQ,
8422 : : .spec = &queue_spec,
8423 : : .last = NULL,
8424 : : .mask = &queue_mask,
8425 : : },
8426 : : {
8427 : : .type = RTE_FLOW_ITEM_TYPE_END,
8428 : : },
8429 : : };
8430 : 0 : struct rte_flow_action_jump jump = {
8431 : : .group = MLX5_HAIRPIN_TX_TABLE,
8432 : : };
8433 : : struct rte_flow_action actions[2];
8434 : : uint32_t flow_idx;
8435 : : struct rte_flow_error error;
8436 : :
8437 : 0 : actions[0].type = RTE_FLOW_ACTION_TYPE_JUMP;
8438 : 0 : actions[0].conf = &jump;
8439 : 0 : actions[1].type = RTE_FLOW_ACTION_TYPE_END;
8440 : 0 : flow_idx = mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
8441 : : &attr, items, actions, false, &error);
8442 [ # # ]: 0 : if (!flow_idx) {
8443 [ # # ]: 0 : DRV_LOG(DEBUG,
8444 : : "Failed to create ctrl flow: rte_errno(%d),"
8445 : : " type(%d), message(%s)",
8446 : : rte_errno, error.type,
8447 : : error.message ? error.message : " (no stated reason)");
8448 : 0 : return -rte_errno;
8449 : : }
8450 : : return 0;
8451 : : }
8452 : :
8453 : : /**
8454 : : * Enable a control flow configured from the control plane.
8455 : : *
8456 : : * @param dev
8457 : : * Pointer to Ethernet device.
8458 : : * @param eth_spec
8459 : : * An Ethernet flow spec to apply.
8460 : : * @param eth_mask
8461 : : * An Ethernet flow mask to apply.
8462 : : * @param vlan_spec
8463 : : * A VLAN flow spec to apply.
8464 : : * @param vlan_mask
8465 : : * A VLAN flow mask to apply.
8466 : : *
8467 : : * @return
8468 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
8469 : : */
8470 : : int
8471 : 0 : mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
8472 : : struct rte_flow_item_eth *eth_spec,
8473 : : struct rte_flow_item_eth *eth_mask,
8474 : : struct rte_flow_item_vlan *vlan_spec,
8475 : : struct rte_flow_item_vlan *vlan_mask)
8476 : : {
8477 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8478 : 0 : const struct rte_flow_attr attr = {
8479 : : .ingress = 1,
8480 : : .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
8481 : : };
8482 : 0 : struct rte_flow_item items[] = {
8483 : : {
8484 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
8485 : : .spec = eth_spec,
8486 : : .last = NULL,
8487 : : .mask = eth_mask,
8488 : : },
8489 : : {
8490 [ # # ]: 0 : .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
8491 : : RTE_FLOW_ITEM_TYPE_END,
8492 : : .spec = vlan_spec,
8493 : : .last = NULL,
8494 : : .mask = vlan_mask,
8495 : : },
8496 : : {
8497 : : .type = RTE_FLOW_ITEM_TYPE_END,
8498 : : },
8499 : : };
8500 : 0 : uint16_t *queue = alloca(sizeof(uint16_t) * priv->reta_idx_n);
8501 : 0 : struct rte_flow_action_rss action_rss = {
8502 : : .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
8503 : : .level = 0,
8504 : 0 : .types = priv->rss_conf.rss_hf,
8505 : 0 : .key_len = priv->rss_conf.rss_key_len,
8506 : : .queue_num = priv->reta_idx_n,
8507 : 0 : .key = priv->rss_conf.rss_key,
8508 : : .queue = queue,
8509 : : };
8510 : 0 : struct rte_flow_action actions[] = {
8511 : : {
8512 : : .type = RTE_FLOW_ACTION_TYPE_RSS,
8513 : : .conf = &action_rss,
8514 : : },
8515 : : {
8516 : : .type = RTE_FLOW_ACTION_TYPE_END,
8517 : : },
8518 : : };
8519 : : uintptr_t flow_idx;
8520 : : struct rte_flow_error error;
8521 : : struct mlx5_ctrl_flow_entry *entry;
8522 : : unsigned int i;
8523 : :
8524 [ # # # # ]: 0 : if (!priv->reta_idx_n || !priv->rxqs_n) {
8525 : : return 0;
8526 : : }
8527 [ # # ]: 0 : if (!(dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG))
8528 : 0 : action_rss.types = 0;
8529 [ # # ]: 0 : for (i = 0; i != priv->reta_idx_n; ++i)
8530 : 0 : queue[i] = (*priv->reta_idx)[i];
8531 : :
8532 : 0 : entry = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*entry), alignof(typeof(*entry)), SOCKET_ID_ANY);
8533 [ # # ]: 0 : if (entry == NULL) {
8534 : 0 : rte_errno = ENOMEM;
8535 : 0 : goto err;
8536 : : }
8537 : :
8538 : 0 : entry->owner_dev = dev;
8539 [ # # ]: 0 : if (vlan_spec == NULL) {
8540 : 0 : entry->info.type = MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC;
8541 : : } else {
8542 : 0 : entry->info.type = MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC_VLAN;
8543 [ # # ]: 0 : entry->info.uc.vlan = rte_be_to_cpu_16(vlan_spec->hdr.vlan_tci);
8544 : : }
8545 : 0 : entry->info.uc.dmac = eth_spec->hdr.dst_addr;
8546 : :
8547 : 0 : flow_idx = mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
8548 : : &attr, items, actions, false, &error);
8549 [ # # ]: 0 : if (!flow_idx) {
8550 : 0 : mlx5_free(entry);
8551 : 0 : goto err;
8552 : : }
8553 : :
8554 : 0 : entry->flow = (struct rte_flow *)flow_idx;
8555 [ # # ]: 0 : LIST_INSERT_HEAD(&priv->hw_ctrl_flows, entry, next);
8556 : :
8557 : 0 : return 0;
8558 : :
8559 : 0 : err:
8560 : 0 : return -rte_errno;
8561 : : }
8562 : :
8563 : : /**
8564 : : * Enable a flow control configured from the control plane.
8565 : : *
8566 : : * @param dev
8567 : : * Pointer to Ethernet device.
8568 : : * @param eth_spec
8569 : : * An Ethernet flow spec to apply.
8570 : : * @param eth_mask
8571 : : * An Ethernet flow mask to apply.
8572 : : *
8573 : : * @return
8574 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
8575 : : */
8576 : : int
8577 : 0 : mlx5_ctrl_flow(struct rte_eth_dev *dev,
8578 : : struct rte_flow_item_eth *eth_spec,
8579 : : struct rte_flow_item_eth *eth_mask)
8580 : : {
8581 : 0 : return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
8582 : : }
8583 : :
8584 : : int
8585 : 0 : mlx5_legacy_dmac_flow_create(struct rte_eth_dev *dev, const struct rte_ether_addr *addr)
8586 : : {
8587 : 0 : struct rte_flow_item_eth unicast = {
8588 : : .hdr.dst_addr = *addr,
8589 : : };
8590 : 0 : struct rte_flow_item_eth unicast_mask = {
8591 : : .hdr.dst_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
8592 : : };
8593 : :
8594 : 0 : return mlx5_ctrl_flow(dev, &unicast, &unicast_mask);
8595 : : }
8596 : :
8597 : : int
8598 : 0 : mlx5_legacy_dmac_vlan_flow_create(struct rte_eth_dev *dev,
8599 : : const struct rte_ether_addr *addr,
8600 : : const uint16_t vid)
8601 : : {
8602 : 0 : struct rte_flow_item_eth unicast_spec = {
8603 : : .hdr.dst_addr = *addr,
8604 : : };
8605 : 0 : struct rte_flow_item_eth unicast_mask = {
8606 : : .hdr.dst_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
8607 : : };
8608 : 0 : struct rte_flow_item_vlan vlan_spec = {
8609 [ # # ]: 0 : .hdr.vlan_tci = rte_cpu_to_be_16(vid),
8610 : : };
8611 : 0 : struct rte_flow_item_vlan vlan_mask = rte_flow_item_vlan_mask;
8612 : :
8613 : 0 : return mlx5_ctrl_flow_vlan(dev, &unicast_spec, &unicast_mask, &vlan_spec, &vlan_mask);
8614 : : }
8615 : :
8616 : : void
8617 : 0 : mlx5_legacy_ctrl_flow_destroy(struct rte_eth_dev *dev, struct mlx5_ctrl_flow_entry *entry)
8618 : : {
8619 : : uintptr_t flow_idx;
8620 : :
8621 : 0 : flow_idx = (uintptr_t)entry->flow;
8622 : 0 : mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_CTL, flow_idx);
8623 [ # # ]: 0 : LIST_REMOVE(entry, next);
8624 : 0 : mlx5_free(entry);
8625 : 0 : }
8626 : :
8627 : : int
8628 : 0 : mlx5_legacy_dmac_flow_destroy(struct rte_eth_dev *dev, const struct rte_ether_addr *addr)
8629 : : {
8630 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8631 : : struct mlx5_ctrl_flow_entry *entry;
8632 : :
8633 [ # # ]: 0 : LIST_FOREACH(entry, &priv->hw_ctrl_flows, next) {
8634 [ # # # # ]: 0 : if (entry->info.type != MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC ||
8635 : : !rte_is_same_ether_addr(addr, &entry->info.uc.dmac))
8636 : : continue;
8637 : :
8638 : 0 : mlx5_legacy_ctrl_flow_destroy(dev, entry);
8639 : 0 : return 0;
8640 : : }
8641 : : return 0;
8642 : : }
8643 : :
8644 : : int
8645 : 0 : mlx5_legacy_dmac_vlan_flow_destroy(struct rte_eth_dev *dev,
8646 : : const struct rte_ether_addr *addr,
8647 : : const uint16_t vid)
8648 : : {
8649 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8650 : : struct mlx5_ctrl_flow_entry *entry;
8651 : :
8652 [ # # ]: 0 : LIST_FOREACH(entry, &priv->hw_ctrl_flows, next) {
8653 [ # # # # ]: 0 : if (entry->info.type != MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC_VLAN ||
8654 : 0 : !rte_is_same_ether_addr(addr, &entry->info.uc.dmac) ||
8655 [ # # ]: 0 : vid != entry->info.uc.vlan)
8656 : : continue;
8657 : :
8658 : 0 : mlx5_legacy_ctrl_flow_destroy(dev, entry);
8659 : 0 : return 0;
8660 : : }
8661 : : return 0;
8662 : : }
8663 : :
8664 : : /**
8665 : : * Create default miss flow rule matching lacp traffic
8666 : : *
8667 : : * @param dev
8668 : : * Pointer to Ethernet device.
8669 : : * @param eth_spec
8670 : : * An Ethernet flow spec to apply.
8671 : : *
8672 : : * @return
8673 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
8674 : : */
8675 : : int
8676 : 0 : mlx5_flow_lacp_miss(struct rte_eth_dev *dev)
8677 : : {
8678 : : /*
8679 : : * The LACP matching is done by only using ether type since using
8680 : : * a multicast dst mac causes kernel to give low priority to this flow.
8681 : : */
8682 : : static const struct rte_flow_item_eth lacp_spec = {
8683 : : .hdr.ether_type = RTE_BE16(0x8809),
8684 : : };
8685 : : static const struct rte_flow_item_eth lacp_mask = {
8686 : : .hdr.ether_type = 0xffff,
8687 : : };
8688 : 0 : const struct rte_flow_attr attr = {
8689 : : .ingress = 1,
8690 : : };
8691 : 0 : struct rte_flow_item items[] = {
8692 : : {
8693 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
8694 : : .spec = &lacp_spec,
8695 : : .mask = &lacp_mask,
8696 : : },
8697 : : {
8698 : : .type = RTE_FLOW_ITEM_TYPE_END,
8699 : : },
8700 : : };
8701 : 0 : struct rte_flow_action actions[] = {
8702 : : {
8703 : : .type = (enum rte_flow_action_type)
8704 : : MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
8705 : : },
8706 : : {
8707 : : .type = RTE_FLOW_ACTION_TYPE_END,
8708 : : },
8709 : : };
8710 : : struct rte_flow_error error;
8711 : 0 : uint32_t flow_idx = mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
8712 : : &attr, items, actions,
8713 : : false, &error);
8714 : :
8715 [ # # ]: 0 : if (!flow_idx)
8716 : 0 : return -rte_errno;
8717 : : return 0;
8718 : : }
8719 : :
8720 : : /**
8721 : : * Destroy a flow.
8722 : : *
8723 : : * @see rte_flow_destroy()
8724 : : * @see rte_flow_ops
8725 : : */
8726 : : int
8727 : 0 : mlx5_flow_destroy(struct rte_eth_dev *dev,
8728 : : struct rte_flow *flow,
8729 : : struct rte_flow_error *error __rte_unused)
8730 : : {
8731 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8732 : : struct rte_pmd_mlx5_flow_engine_mode_info *mode_info = &priv->mode_info;
8733 : : struct mlx5_dv_flow_info *flow_info;
8734 : :
8735 : 0 : mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN,
8736 : : (uintptr_t)(void *)flow);
8737 [ # # ]: 0 : if (unlikely(mlx5_need_cache_flow(priv, NULL))) {
8738 : 0 : flow_info = LIST_FIRST(&mode_info->hot_upgrade);
8739 [ # # ]: 0 : while (flow_info) {
8740 : : /* Romove the cache flow info. */
8741 [ # # ]: 0 : if (flow_info->flow_idx_low_prio == (uint32_t)(uintptr_t)flow) {
8742 : : MLX5_ASSERT(!flow_info->flow_idx_high_prio);
8743 [ # # ]: 0 : LIST_REMOVE(flow_info, next);
8744 : 0 : mlx5_free(flow_info->items);
8745 : 0 : mlx5_free(flow_info->actions);
8746 : 0 : mlx5_free(flow_info);
8747 : 0 : break;
8748 : : }
8749 : 0 : flow_info = LIST_NEXT(flow_info, next);
8750 : : }
8751 : : }
8752 : 0 : return 0;
8753 : : }
8754 : :
8755 : : /**
8756 : : * Destroy all flows.
8757 : : *
8758 : : * @see rte_flow_flush()
8759 : : * @see rte_flow_ops
8760 : : */
8761 : : int
8762 : 0 : mlx5_flow_flush(struct rte_eth_dev *dev,
8763 : : struct rte_flow_error *error __rte_unused)
8764 : : {
8765 : 0 : mlx5_flow_list_flush(dev, MLX5_FLOW_TYPE_GEN, false);
8766 : 0 : return 0;
8767 : : }
8768 : :
8769 : : /**
8770 : : * Isolated mode.
8771 : : *
8772 : : * @see rte_flow_isolate()
8773 : : * @see rte_flow_ops
8774 : : */
8775 : : int
8776 : 0 : mlx5_flow_isolate(struct rte_eth_dev *dev,
8777 : : int enable,
8778 : : struct rte_flow_error *error)
8779 : : {
8780 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8781 : :
8782 [ # # ]: 0 : if (dev->data->dev_started) {
8783 : 0 : rte_flow_error_set(error, EBUSY,
8784 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8785 : : NULL,
8786 : : "port must be stopped first");
8787 : 0 : return -rte_errno;
8788 : : }
8789 [ # # # # ]: 0 : if (!enable && !priv->sh->config.repr_matching)
8790 : 0 : return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8791 : : "isolated mode cannot be disabled when "
8792 : : "representor matching is disabled");
8793 : 0 : priv->isolated = !!enable;
8794 [ # # ]: 0 : if (enable)
8795 : 0 : dev->dev_ops = &mlx5_dev_ops_isolate;
8796 : : else
8797 : 0 : dev->dev_ops = &mlx5_dev_ops;
8798 : :
8799 : 0 : dev->rx_descriptor_status = mlx5_rx_descriptor_status;
8800 : 0 : dev->tx_descriptor_status = mlx5_tx_descriptor_status;
8801 : :
8802 : 0 : return 0;
8803 : : }
8804 : :
8805 : : /**
8806 : : * Query a flow.
8807 : : *
8808 : : * @see rte_flow_query()
8809 : : * @see rte_flow_ops
8810 : : */
8811 : : static int
8812 : 0 : flow_drv_query(struct rte_eth_dev *dev,
8813 : : struct rte_flow *eflow,
8814 : : const struct rte_flow_action *actions,
8815 : : void *data,
8816 : : struct rte_flow_error *error)
8817 : : {
8818 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8819 : : const struct mlx5_flow_driver_ops *fops;
8820 : : struct rte_flow *flow = NULL;
8821 : : enum mlx5_flow_drv_type ftype = MLX5_FLOW_TYPE_MIN;
8822 : :
8823 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2) {
8824 : : #ifdef HAVE_MLX5_HWS_SUPPORT
8825 : : flow = eflow;
8826 : : ftype = MLX5_FLOW_TYPE_HW;
8827 : : #endif
8828 : : } else {
8829 : 0 : flow = (struct rte_flow *)mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
8830 : : (uintptr_t)(void *)eflow);
8831 : : }
8832 [ # # ]: 0 : if (!flow) {
8833 : 0 : return rte_flow_error_set(error, ENOENT,
8834 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8835 : : NULL,
8836 : : "invalid flow handle");
8837 : : }
8838 [ # # ]: 0 : if (ftype == MLX5_FLOW_TYPE_MIN)
8839 : 0 : ftype = flow->drv_type;
8840 : : MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX);
8841 : 0 : fops = flow_get_drv_ops(ftype);
8842 : :
8843 : 0 : return fops->query(dev, flow, actions, data, error);
8844 : : }
8845 : :
8846 : : /**
8847 : : * Query a flow.
8848 : : *
8849 : : * @see rte_flow_query()
8850 : : * @see rte_flow_ops
8851 : : */
8852 : : int
8853 : 0 : mlx5_flow_query(struct rte_eth_dev *dev,
8854 : : struct rte_flow *flow,
8855 : : const struct rte_flow_action *actions,
8856 : : void *data,
8857 : : struct rte_flow_error *error)
8858 : : {
8859 : : int ret;
8860 : :
8861 : 0 : ret = flow_drv_query(dev, flow, actions, data,
8862 : : error);
8863 : : if (ret < 0)
8864 : : return ret;
8865 : : return 0;
8866 : : }
8867 : :
8868 : : /**
8869 : : * Get rte_flow callbacks.
8870 : : *
8871 : : * @param dev
8872 : : * Pointer to Ethernet device structure.
8873 : : * @param ops
8874 : : * Pointer to operation-specific structure.
8875 : : *
8876 : : * @return 0
8877 : : */
8878 : : int
8879 : 0 : mlx5_flow_ops_get(struct rte_eth_dev *dev __rte_unused,
8880 : : const struct rte_flow_ops **ops)
8881 : : {
8882 : 0 : *ops = &mlx5_flow_ops;
8883 : 0 : return 0;
8884 : : }
8885 : :
8886 : : /**
8887 : : * Validate meter policy actions.
8888 : : * Dispatcher for action type specific validation.
8889 : : *
8890 : : * @param[in] dev
8891 : : * Pointer to the Ethernet device structure.
8892 : : * @param[in] action
8893 : : * The meter policy action object to validate.
8894 : : * @param[in] attr
8895 : : * Attributes of flow to determine steering domain.
8896 : : * @param[out] is_rss
8897 : : * Is RSS or not.
8898 : : * @param[out] domain_bitmap
8899 : : * Domain bitmap.
8900 : : * @param[out] is_def_policy
8901 : : * Is default policy or not.
8902 : : * @param[out] error
8903 : : * Perform verbose error reporting if not NULL. Initialized in case of
8904 : : * error only.
8905 : : *
8906 : : * @return
8907 : : * 0 on success, otherwise negative errno value.
8908 : : */
8909 : : int
8910 : 0 : mlx5_flow_validate_mtr_acts(struct rte_eth_dev *dev,
8911 : : const struct rte_flow_action *actions[RTE_COLORS],
8912 : : struct rte_flow_attr *attr,
8913 : : bool *is_rss,
8914 : : uint8_t *domain_bitmap,
8915 : : uint8_t *policy_mode,
8916 : : struct rte_mtr_error *error)
8917 : : {
8918 : : const struct mlx5_flow_driver_ops *fops;
8919 : :
8920 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
8921 : 0 : return fops->validate_mtr_acts(dev, actions, attr, is_rss,
8922 : : domain_bitmap, policy_mode, error);
8923 : : }
8924 : :
8925 : : /**
8926 : : * Destroy the meter table set.
8927 : : *
8928 : : * @param[in] dev
8929 : : * Pointer to Ethernet device.
8930 : : * @param[in] mtr_policy
8931 : : * Meter policy struct.
8932 : : */
8933 : : void
8934 : 0 : mlx5_flow_destroy_mtr_acts(struct rte_eth_dev *dev,
8935 : : struct mlx5_flow_meter_policy *mtr_policy)
8936 : : {
8937 : : const struct mlx5_flow_driver_ops *fops;
8938 : :
8939 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
8940 : 0 : fops->destroy_mtr_acts(dev, mtr_policy);
8941 : 0 : }
8942 : :
8943 : : /**
8944 : : * Create policy action, lock free,
8945 : : * (mutex should be acquired by caller).
8946 : : * Dispatcher for action type specific call.
8947 : : *
8948 : : * @param[in] dev
8949 : : * Pointer to the Ethernet device structure.
8950 : : * @param[in] mtr_policy
8951 : : * Meter policy struct.
8952 : : * @param[in] action
8953 : : * Action specification used to create meter actions.
8954 : : * @param[in] attr
8955 : : * Flow rule attributes.
8956 : : * @param[out] error
8957 : : * Perform verbose error reporting if not NULL. Initialized in case of
8958 : : * error only.
8959 : : *
8960 : : * @return
8961 : : * 0 on success, otherwise negative errno value.
8962 : : */
8963 : : int
8964 : 0 : mlx5_flow_create_mtr_acts(struct rte_eth_dev *dev,
8965 : : struct mlx5_flow_meter_policy *mtr_policy,
8966 : : const struct rte_flow_action *actions[RTE_COLORS],
8967 : : struct rte_flow_attr *attr,
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->create_mtr_acts(dev, mtr_policy, actions, attr, error);
8974 : : }
8975 : :
8976 : : /**
8977 : : * Create policy rules, lock free,
8978 : : * (mutex should be acquired by caller).
8979 : : * Dispatcher for action type specific call.
8980 : : *
8981 : : * @param[in] dev
8982 : : * Pointer to the Ethernet device structure.
8983 : : * @param[in] mtr_policy
8984 : : * Meter policy struct.
8985 : : *
8986 : : * @return
8987 : : * 0 on success, -1 otherwise.
8988 : : */
8989 : : int
8990 : 0 : mlx5_flow_create_policy_rules(struct rte_eth_dev *dev,
8991 : : struct mlx5_flow_meter_policy *mtr_policy)
8992 : : {
8993 : : const struct mlx5_flow_driver_ops *fops;
8994 : :
8995 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
8996 : 0 : return fops->create_policy_rules(dev, mtr_policy);
8997 : : }
8998 : :
8999 : : /**
9000 : : * Destroy policy rules, lock free,
9001 : : * (mutex should be acquired by caller).
9002 : : * Dispatcher for action type specific call.
9003 : : *
9004 : : * @param[in] dev
9005 : : * Pointer to the Ethernet device structure.
9006 : : * @param[in] mtr_policy
9007 : : * Meter policy struct.
9008 : : */
9009 : : void
9010 : 0 : mlx5_flow_destroy_policy_rules(struct rte_eth_dev *dev,
9011 : : struct mlx5_flow_meter_policy *mtr_policy)
9012 : : {
9013 : : const struct mlx5_flow_driver_ops *fops;
9014 : :
9015 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9016 : 0 : fops->destroy_policy_rules(dev, mtr_policy);
9017 : 0 : }
9018 : :
9019 : : /**
9020 : : * Destroy the default policy table set.
9021 : : *
9022 : : * @param[in] dev
9023 : : * Pointer to Ethernet device.
9024 : : */
9025 : : void
9026 : 0 : mlx5_flow_destroy_def_policy(struct rte_eth_dev *dev)
9027 : : {
9028 : : const struct mlx5_flow_driver_ops *fops;
9029 : :
9030 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9031 : 0 : fops->destroy_def_policy(dev);
9032 : 0 : }
9033 : :
9034 : : /**
9035 : : * Destroy the default policy table set.
9036 : : *
9037 : : * @param[in] dev
9038 : : * Pointer to Ethernet device.
9039 : : *
9040 : : * @return
9041 : : * 0 on success, -1 otherwise.
9042 : : */
9043 : : int
9044 : 0 : mlx5_flow_create_def_policy(struct rte_eth_dev *dev)
9045 : : {
9046 : : const struct mlx5_flow_driver_ops *fops;
9047 : :
9048 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9049 : 0 : return fops->create_def_policy(dev);
9050 : : }
9051 : :
9052 : : /**
9053 : : * Create the needed meter and suffix tables.
9054 : : *
9055 : : * @param[in] dev
9056 : : * Pointer to Ethernet device.
9057 : : *
9058 : : * @return
9059 : : * 0 on success, -1 otherwise.
9060 : : */
9061 : : int
9062 : 0 : mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
9063 : : struct mlx5_flow_meter_info *fm,
9064 : : uint32_t mtr_idx,
9065 : : uint8_t domain_bitmap)
9066 : : {
9067 : : const struct mlx5_flow_driver_ops *fops;
9068 : :
9069 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9070 : 0 : return fops->create_mtr_tbls(dev, fm, mtr_idx, domain_bitmap);
9071 : : }
9072 : :
9073 : : /**
9074 : : * Destroy the meter table set.
9075 : : *
9076 : : * @param[in] dev
9077 : : * Pointer to Ethernet device.
9078 : : * @param[in] tbl
9079 : : * Pointer to the meter table set.
9080 : : */
9081 : : void
9082 : 0 : mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
9083 : : struct mlx5_flow_meter_info *fm)
9084 : : {
9085 : : const struct mlx5_flow_driver_ops *fops;
9086 : :
9087 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9088 : 0 : fops->destroy_mtr_tbls(dev, fm);
9089 : 0 : }
9090 : :
9091 : : /**
9092 : : * Destroy the global meter drop table.
9093 : : *
9094 : : * @param[in] dev
9095 : : * Pointer to Ethernet device.
9096 : : */
9097 : : void
9098 : 0 : mlx5_flow_destroy_mtr_drop_tbls(struct rte_eth_dev *dev)
9099 : : {
9100 : : const struct mlx5_flow_driver_ops *fops;
9101 : :
9102 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9103 : 0 : fops->destroy_mtr_drop_tbls(dev);
9104 : 0 : }
9105 : :
9106 : : /**
9107 : : * Destroy the sub policy table with RX queue.
9108 : : *
9109 : : * @param[in] dev
9110 : : * Pointer to Ethernet device.
9111 : : * @param[in] mtr_policy
9112 : : * Pointer to meter policy table.
9113 : : */
9114 : : void
9115 : 0 : mlx5_flow_destroy_sub_policy_with_rxq(struct rte_eth_dev *dev,
9116 : : struct mlx5_flow_meter_policy *mtr_policy)
9117 : : {
9118 : : const struct mlx5_flow_driver_ops *fops;
9119 : :
9120 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9121 : 0 : fops->destroy_sub_policy_with_rxq(dev, mtr_policy);
9122 : 0 : }
9123 : :
9124 : : /**
9125 : : * Allocate the needed aso flow meter id.
9126 : : *
9127 : : * @param[in] dev
9128 : : * Pointer to Ethernet device.
9129 : : *
9130 : : * @return
9131 : : * Index to aso flow meter on success, NULL otherwise.
9132 : : */
9133 : : uint32_t
9134 : 0 : mlx5_flow_mtr_alloc(struct rte_eth_dev *dev)
9135 : : {
9136 : : const struct mlx5_flow_driver_ops *fops;
9137 : :
9138 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9139 : 0 : return fops->create_meter(dev);
9140 : : }
9141 : :
9142 : : /**
9143 : : * Free the aso flow meter id.
9144 : : *
9145 : : * @param[in] dev
9146 : : * Pointer to Ethernet device.
9147 : : * @param[in] mtr_idx
9148 : : * Index to aso flow meter to be free.
9149 : : *
9150 : : * @return
9151 : : * 0 on success.
9152 : : */
9153 : : void
9154 : 0 : mlx5_flow_mtr_free(struct rte_eth_dev *dev, uint32_t mtr_idx)
9155 : : {
9156 : : const struct mlx5_flow_driver_ops *fops;
9157 : :
9158 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9159 : 0 : fops->free_meter(dev, mtr_idx);
9160 : 0 : }
9161 : :
9162 : : /**
9163 : : * Allocate a counter.
9164 : : *
9165 : : * @param[in] dev
9166 : : * Pointer to Ethernet device structure.
9167 : : *
9168 : : * @return
9169 : : * Index to allocated counter on success, 0 otherwise.
9170 : : */
9171 : : uint32_t
9172 [ # # ]: 0 : mlx5_counter_alloc(struct rte_eth_dev *dev)
9173 : : {
9174 : : struct rte_flow_attr attr = { .transfer = 0 };
9175 : :
9176 : 0 : return flow_get_drv_ops(flow_get_drv_type(dev, &attr))->counter_alloc
9177 : : (dev);
9178 : : }
9179 : :
9180 : : /**
9181 : : * Free a counter.
9182 : : *
9183 : : * @param[in] dev
9184 : : * Pointer to Ethernet device structure.
9185 : : * @param[in] cnt
9186 : : * Index to counter to be free.
9187 : : */
9188 : : void
9189 [ # # ]: 0 : mlx5_counter_free(struct rte_eth_dev *dev, uint32_t cnt)
9190 : : {
9191 : : struct rte_flow_attr attr = { .transfer = 0 };
9192 : :
9193 : 0 : flow_get_drv_ops(flow_get_drv_type(dev, &attr))->counter_free(dev, cnt);
9194 : 0 : }
9195 : :
9196 : : /**
9197 : : * Query counter statistics.
9198 : : *
9199 : : * @param[in] dev
9200 : : * Pointer to Ethernet device structure.
9201 : : * @param[in] cnt
9202 : : * Index to counter to query.
9203 : : * @param[in] clear
9204 : : * Set to clear counter statistics.
9205 : : * @param[out] pkts
9206 : : * The counter hits packets number to save.
9207 : : * @param[out] bytes
9208 : : * The counter hits bytes number to save.
9209 : : *
9210 : : * @return
9211 : : * 0 on success, a negative errno value otherwise.
9212 : : */
9213 : : int
9214 [ # # ]: 0 : mlx5_counter_query(struct rte_eth_dev *dev, uint32_t cnt,
9215 : : bool clear, uint64_t *pkts, uint64_t *bytes, void **action)
9216 : : {
9217 : : struct rte_flow_attr attr = { .transfer = 0 };
9218 : :
9219 : 0 : return flow_get_drv_ops(flow_get_drv_type(dev, &attr))->counter_query
9220 : : (dev, cnt, clear, pkts, bytes, action);
9221 : : }
9222 : :
9223 : : /**
9224 : : * Get information about HWS pre-configurable resources.
9225 : : *
9226 : : * @param[in] dev
9227 : : * Pointer to the rte_eth_dev structure.
9228 : : * @param[out] port_info
9229 : : * Pointer to port information.
9230 : : * @param[out] queue_info
9231 : : * Pointer to queue information.
9232 : : * @param[out] error
9233 : : * Pointer to error structure.
9234 : : *
9235 : : * @return
9236 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9237 : : */
9238 : : static int
9239 [ # # ]: 0 : mlx5_flow_info_get(struct rte_eth_dev *dev,
9240 : : struct rte_flow_port_info *port_info,
9241 : : struct rte_flow_queue_info *queue_info,
9242 : : struct rte_flow_error *error)
9243 : : {
9244 : : const struct mlx5_flow_driver_ops *fops;
9245 : : struct rte_flow_attr attr = {0};
9246 : :
9247 : : if (flow_get_drv_type(dev, &attr) != MLX5_FLOW_TYPE_HW)
9248 : 0 : return rte_flow_error_set(error, ENOTSUP,
9249 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9250 : : NULL,
9251 : : "info get with incorrect steering mode");
9252 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9253 : 0 : return fops->info_get(dev, port_info, queue_info, error);
9254 : : }
9255 : :
9256 : : /**
9257 : : * Configure port HWS resources.
9258 : : *
9259 : : * @param[in] dev
9260 : : * Pointer to the rte_eth_dev structure.
9261 : : * @param[in] port_attr
9262 : : * Port configuration attributes.
9263 : : * @param[in] nb_queue
9264 : : * Number of queue.
9265 : : * @param[in] queue_attr
9266 : : * Array that holds attributes for each flow queue.
9267 : : * @param[out] error
9268 : : * Pointer to error structure.
9269 : : *
9270 : : * @return
9271 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9272 : : */
9273 : : static int
9274 [ # # ]: 0 : mlx5_flow_port_configure(struct rte_eth_dev *dev,
9275 : : const struct rte_flow_port_attr *port_attr,
9276 : : uint16_t nb_queue,
9277 : : const struct rte_flow_queue_attr *queue_attr[],
9278 : : struct rte_flow_error *error)
9279 : : {
9280 : : const struct mlx5_flow_driver_ops *fops;
9281 : : struct rte_flow_attr attr = {0};
9282 : :
9283 : : if (flow_get_drv_type(dev, &attr) != MLX5_FLOW_TYPE_HW)
9284 : 0 : return rte_flow_error_set(error, ENOTSUP,
9285 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9286 : : NULL,
9287 : : "port configure with incorrect steering mode");
9288 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9289 : 0 : return fops->configure(dev, port_attr, nb_queue, queue_attr, error);
9290 : : }
9291 : :
9292 : : /**
9293 : : * Validate item template.
9294 : : *
9295 : : * @param[in] dev
9296 : : * Pointer to the rte_eth_dev structure.
9297 : : * @param[in] attr
9298 : : * Pointer to the item template attributes.
9299 : : * @param[in] items
9300 : : * The template item pattern.
9301 : : * @param[out] error
9302 : : * Pointer to error structure.
9303 : : *
9304 : : * @return
9305 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9306 : : */
9307 : : int
9308 : 0 : mlx5_flow_pattern_validate(struct rte_eth_dev *dev,
9309 : : const struct rte_flow_pattern_template_attr *attr,
9310 : : const struct rte_flow_item items[],
9311 : : struct rte_flow_error *error)
9312 : : {
9313 : : const struct mlx5_flow_driver_ops *fops;
9314 : : struct rte_flow_attr fattr = {0};
9315 [ # # ]: 0 : uint64_t item_flags = 0;
9316 : :
9317 : : if (flow_get_drv_type(dev, &fattr) != MLX5_FLOW_TYPE_HW) {
9318 : 0 : rte_flow_error_set(error, ENOTSUP,
9319 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9320 : : "pattern validate with incorrect steering mode");
9321 : 0 : return -ENOTSUP;
9322 : : }
9323 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9324 : 0 : return fops->pattern_validate(dev, attr, items, &item_flags, error);
9325 : : }
9326 : :
9327 : : /**
9328 : : * Create flow item template.
9329 : : *
9330 : : * @param[in] dev
9331 : : * Pointer to the rte_eth_dev structure.
9332 : : * @param[in] attr
9333 : : * Pointer to the item template attributes.
9334 : : * @param[in] items
9335 : : * The template item pattern.
9336 : : * @param[out] error
9337 : : * Pointer to error structure.
9338 : : *
9339 : : * @return
9340 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9341 : : */
9342 : : static struct rte_flow_pattern_template *
9343 [ # # ]: 0 : mlx5_flow_pattern_template_create(struct rte_eth_dev *dev,
9344 : : const struct rte_flow_pattern_template_attr *attr,
9345 : : const struct rte_flow_item items[],
9346 : : struct rte_flow_error *error)
9347 : : {
9348 : : const struct mlx5_flow_driver_ops *fops;
9349 : : struct rte_flow_attr fattr = {0};
9350 : :
9351 : : if (flow_get_drv_type(dev, &fattr) != MLX5_FLOW_TYPE_HW) {
9352 : 0 : rte_flow_error_set(error, ENOTSUP,
9353 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9354 : : NULL,
9355 : : "pattern create with incorrect steering mode");
9356 : 0 : return NULL;
9357 : : }
9358 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9359 : 0 : return fops->pattern_template_create(dev, attr, items, error);
9360 : : }
9361 : :
9362 : : /**
9363 : : * Destroy flow item template.
9364 : : *
9365 : : * @param[in] dev
9366 : : * Pointer to the rte_eth_dev structure.
9367 : : * @param[in] template
9368 : : * Pointer to the item template to be destroyed.
9369 : : * @param[out] error
9370 : : * Pointer to error structure.
9371 : : *
9372 : : * @return
9373 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9374 : : */
9375 : : static int
9376 [ # # ]: 0 : mlx5_flow_pattern_template_destroy(struct rte_eth_dev *dev,
9377 : : struct rte_flow_pattern_template *template,
9378 : : struct rte_flow_error *error)
9379 : : {
9380 : : const struct mlx5_flow_driver_ops *fops;
9381 : : struct rte_flow_attr attr = {0};
9382 : :
9383 : : if (flow_get_drv_type(dev, &attr) != MLX5_FLOW_TYPE_HW)
9384 : 0 : return rte_flow_error_set(error, ENOTSUP,
9385 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9386 : : NULL,
9387 : : "pattern destroy with incorrect steering mode");
9388 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9389 : 0 : return fops->pattern_template_destroy(dev, template, error);
9390 : : }
9391 : :
9392 : : /**
9393 : : * Validate flow actions template.
9394 : : *
9395 : : * @param[in] dev
9396 : : * Pointer to the rte_eth_dev structure.
9397 : : * @param[in] attr
9398 : : * Pointer to the action template attributes.
9399 : : * @param[in] actions
9400 : : * Associated actions (list terminated by the END action).
9401 : : * @param[in] masks
9402 : : * List of actions that marks which of the action's member is constant.
9403 : : * @param[out] error
9404 : : * Pointer to error structure.
9405 : : *
9406 : : * @return
9407 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9408 : : */
9409 : : int
9410 [ # # ]: 0 : mlx5_flow_actions_validate(struct rte_eth_dev *dev,
9411 : : const struct rte_flow_actions_template_attr *attr,
9412 : : const struct rte_flow_action actions[],
9413 : : const struct rte_flow_action masks[],
9414 : : struct rte_flow_error *error)
9415 : : {
9416 : : const struct mlx5_flow_driver_ops *fops;
9417 : : struct rte_flow_attr fattr = {0};
9418 : :
9419 : : if (flow_get_drv_type(dev, &fattr) != MLX5_FLOW_TYPE_HW) {
9420 : 0 : rte_flow_error_set(error, ENOTSUP,
9421 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9422 : : "actions validate with incorrect steering mode");
9423 : 0 : return -ENOTSUP;
9424 : : }
9425 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9426 : 0 : return fops->actions_validate(dev, attr, actions, masks, error);
9427 : : }
9428 : :
9429 : : /**
9430 : : * Create flow item template.
9431 : : *
9432 : : * @param[in] dev
9433 : : * Pointer to the rte_eth_dev structure.
9434 : : * @param[in] attr
9435 : : * Pointer to the action template attributes.
9436 : : * @param[in] actions
9437 : : * Associated actions (list terminated by the END action).
9438 : : * @param[in] masks
9439 : : * List of actions that marks which of the action's member is constant.
9440 : : * @param[out] error
9441 : : * Pointer to error structure.
9442 : : *
9443 : : * @return
9444 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9445 : : */
9446 : : static struct rte_flow_actions_template *
9447 [ # # ]: 0 : mlx5_flow_actions_template_create(struct rte_eth_dev *dev,
9448 : : const struct rte_flow_actions_template_attr *attr,
9449 : : const struct rte_flow_action actions[],
9450 : : const struct rte_flow_action masks[],
9451 : : struct rte_flow_error *error)
9452 : : {
9453 : : const struct mlx5_flow_driver_ops *fops;
9454 : : struct rte_flow_attr fattr = {0};
9455 : :
9456 : : if (flow_get_drv_type(dev, &fattr) != MLX5_FLOW_TYPE_HW) {
9457 : 0 : rte_flow_error_set(error, ENOTSUP,
9458 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9459 : : NULL,
9460 : : "action create with incorrect steering mode");
9461 : 0 : return NULL;
9462 : : }
9463 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9464 : 0 : return fops->actions_template_create(dev, attr, actions, masks, error);
9465 : : }
9466 : :
9467 : : /**
9468 : : * Destroy flow action template.
9469 : : *
9470 : : * @param[in] dev
9471 : : * Pointer to the rte_eth_dev structure.
9472 : : * @param[in] template
9473 : : * Pointer to the action template to be destroyed.
9474 : : * @param[out] error
9475 : : * Pointer to error structure.
9476 : : *
9477 : : * @return
9478 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9479 : : */
9480 : : static int
9481 [ # # ]: 0 : mlx5_flow_actions_template_destroy(struct rte_eth_dev *dev,
9482 : : struct rte_flow_actions_template *template,
9483 : : struct rte_flow_error *error)
9484 : : {
9485 : : const struct mlx5_flow_driver_ops *fops;
9486 : : struct rte_flow_attr attr = {0};
9487 : :
9488 : : if (flow_get_drv_type(dev, &attr) != MLX5_FLOW_TYPE_HW)
9489 : 0 : return rte_flow_error_set(error, ENOTSUP,
9490 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9491 : : NULL,
9492 : : "action destroy with incorrect steering mode");
9493 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9494 : 0 : return fops->actions_template_destroy(dev, template, error);
9495 : : }
9496 : :
9497 : : /**
9498 : : * Create flow table.
9499 : : *
9500 : : * @param[in] dev
9501 : : * Pointer to the rte_eth_dev structure.
9502 : : * @param[in] attr
9503 : : * Pointer to the table attributes.
9504 : : * @param[in] item_templates
9505 : : * Item template array to be binded to the table.
9506 : : * @param[in] nb_item_templates
9507 : : * Number of item template.
9508 : : * @param[in] action_templates
9509 : : * Action template array to be binded to the table.
9510 : : * @param[in] nb_action_templates
9511 : : * Number of action template.
9512 : : * @param[out] error
9513 : : * Pointer to error structure.
9514 : : *
9515 : : * @return
9516 : : * Table on success, NULL otherwise and rte_errno is set.
9517 : : */
9518 : : static struct rte_flow_template_table *
9519 [ # # ]: 0 : mlx5_flow_table_create(struct rte_eth_dev *dev,
9520 : : const struct rte_flow_template_table_attr *attr,
9521 : : struct rte_flow_pattern_template *item_templates[],
9522 : : uint8_t nb_item_templates,
9523 : : struct rte_flow_actions_template *action_templates[],
9524 : : uint8_t nb_action_templates,
9525 : : struct rte_flow_error *error)
9526 : : {
9527 : : const struct mlx5_flow_driver_ops *fops;
9528 : : struct rte_flow_attr fattr = {0};
9529 : :
9530 : : if (flow_get_drv_type(dev, &fattr) != MLX5_FLOW_TYPE_HW) {
9531 : 0 : rte_flow_error_set(error, ENOTSUP,
9532 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9533 : : NULL,
9534 : : "table create with incorrect steering mode");
9535 : 0 : return NULL;
9536 : : }
9537 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9538 : 0 : return fops->template_table_create(dev,
9539 : : attr,
9540 : : item_templates,
9541 : : nb_item_templates,
9542 : : action_templates,
9543 : : nb_action_templates,
9544 : : error);
9545 : : }
9546 : :
9547 : : /**
9548 : : * PMD destroy flow table.
9549 : : *
9550 : : * @param[in] dev
9551 : : * Pointer to the rte_eth_dev structure.
9552 : : * @param[in] table
9553 : : * Pointer to the table to be destroyed.
9554 : : * @param[out] error
9555 : : * Pointer to error structure.
9556 : : *
9557 : : * @return
9558 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9559 : : */
9560 : : static int
9561 [ # # ]: 0 : mlx5_flow_table_destroy(struct rte_eth_dev *dev,
9562 : : struct rte_flow_template_table *table,
9563 : : struct rte_flow_error *error)
9564 : : {
9565 : : const struct mlx5_flow_driver_ops *fops;
9566 : : struct rte_flow_attr attr = {0};
9567 : :
9568 : : if (flow_get_drv_type(dev, &attr) != MLX5_FLOW_TYPE_HW)
9569 : 0 : return rte_flow_error_set(error, ENOTSUP,
9570 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9571 : : NULL,
9572 : : "table destroy with incorrect steering mode");
9573 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9574 : 0 : return fops->template_table_destroy(dev, table, error);
9575 : : }
9576 : :
9577 : : /**
9578 : : * PMD group set miss actions.
9579 : : *
9580 : : * @param[in] dev
9581 : : * Pointer to the rte_eth_dev structure.
9582 : : * @param[in] attr
9583 : : * Pointer to group attributes
9584 : : * @param[in] actions
9585 : : * Array of actions
9586 : : * @param[out] error
9587 : : * Pointer to error structure.
9588 : : *
9589 : : * @return
9590 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9591 : : */
9592 : : static int
9593 [ # # ]: 0 : mlx5_flow_group_set_miss_actions(struct rte_eth_dev *dev,
9594 : : uint32_t group_id,
9595 : : const struct rte_flow_group_attr *attr,
9596 : : const struct rte_flow_action actions[],
9597 : : struct rte_flow_error *error)
9598 : : {
9599 : : const struct mlx5_flow_driver_ops *fops;
9600 : : struct rte_flow_attr fattr = {0};
9601 : :
9602 : : if (flow_get_drv_type(dev, &fattr) != MLX5_FLOW_TYPE_HW)
9603 : 0 : return rte_flow_error_set(error, ENOTSUP,
9604 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9605 : : NULL,
9606 : : "group set miss actions with incorrect steering mode");
9607 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9608 : 0 : return fops->group_set_miss_actions(dev, group_id, attr, actions, error);
9609 : : }
9610 : :
9611 : : /**
9612 : : * Allocate a new memory for the counter values wrapped by all the needed
9613 : : * management.
9614 : : *
9615 : : * @param[in] sh
9616 : : * Pointer to mlx5_dev_ctx_shared object.
9617 : : *
9618 : : * @return
9619 : : * 0 on success, a negative errno value otherwise.
9620 : : */
9621 : : static int
9622 : 0 : mlx5_flow_create_counter_stat_mem_mng(struct mlx5_dev_ctx_shared *sh)
9623 : : {
9624 : : struct mlx5_counter_stats_mem_mng *mem_mng;
9625 : : volatile struct flow_counter_stats *raw_data;
9626 : : int raws_n = MLX5_CNT_MR_ALLOC_BULK + MLX5_MAX_PENDING_QUERIES;
9627 : : int size = (sizeof(struct flow_counter_stats) *
9628 : : MLX5_COUNTERS_PER_POOL +
9629 : : sizeof(struct mlx5_counter_stats_raw)) * raws_n +
9630 : : sizeof(struct mlx5_counter_stats_mem_mng);
9631 : 0 : size_t pgsize = rte_mem_page_size();
9632 : : uint8_t *mem;
9633 : : int ret;
9634 : : int i;
9635 : :
9636 [ # # ]: 0 : if (pgsize == (size_t)-1) {
9637 : 0 : DRV_LOG(ERR, "Failed to get mem page size");
9638 : 0 : rte_errno = ENOMEM;
9639 : 0 : return -ENOMEM;
9640 : : }
9641 : 0 : mem = mlx5_malloc(MLX5_MEM_ZERO, size, pgsize, SOCKET_ID_ANY);
9642 [ # # ]: 0 : if (!mem) {
9643 : 0 : rte_errno = ENOMEM;
9644 : 0 : return -ENOMEM;
9645 : : }
9646 : 0 : mem_mng = (struct mlx5_counter_stats_mem_mng *)(mem + size) - 1;
9647 : : size = sizeof(*raw_data) * MLX5_COUNTERS_PER_POOL * raws_n;
9648 : 0 : ret = mlx5_os_wrapped_mkey_create(sh->cdev->ctx, sh->cdev->pd,
9649 : 0 : sh->cdev->pdn, mem, size,
9650 : : &mem_mng->wm);
9651 [ # # ]: 0 : if (ret) {
9652 : 0 : rte_errno = errno;
9653 : 0 : mlx5_free(mem);
9654 : 0 : return -rte_errno;
9655 : : }
9656 : 0 : mem_mng->raws = (struct mlx5_counter_stats_raw *)(mem + size);
9657 : : raw_data = (volatile struct flow_counter_stats *)mem;
9658 [ # # ]: 0 : for (i = 0; i < raws_n; ++i) {
9659 : 0 : mem_mng->raws[i].mem_mng = mem_mng;
9660 : 0 : mem_mng->raws[i].data = raw_data + i * MLX5_COUNTERS_PER_POOL;
9661 : : }
9662 [ # # ]: 0 : for (i = 0; i < MLX5_MAX_PENDING_QUERIES; ++i)
9663 [ # # ]: 0 : LIST_INSERT_HEAD(&sh->sws_cmng.free_stat_raws,
9664 : : mem_mng->raws + MLX5_CNT_MR_ALLOC_BULK + i,
9665 : : next);
9666 [ # # ]: 0 : LIST_INSERT_HEAD(&sh->sws_cmng.mem_mngs, mem_mng, next);
9667 : 0 : sh->sws_cmng.mem_mng = mem_mng;
9668 : 0 : return 0;
9669 : : }
9670 : :
9671 : : /**
9672 : : * Set the statistic memory to the new counter pool.
9673 : : *
9674 : : * @param[in] sh
9675 : : * Pointer to mlx5_dev_ctx_shared object.
9676 : : * @param[in] pool
9677 : : * Pointer to the pool to set the statistic memory.
9678 : : *
9679 : : * @return
9680 : : * 0 on success, a negative errno value otherwise.
9681 : : */
9682 : : static int
9683 : 0 : mlx5_flow_set_counter_stat_mem(struct mlx5_dev_ctx_shared *sh,
9684 : : struct mlx5_flow_counter_pool *pool)
9685 : : {
9686 : : struct mlx5_flow_counter_mng *cmng = &sh->sws_cmng;
9687 : : /* Resize statistic memory once used out. */
9688 [ # # # # ]: 0 : if (!(pool->index % MLX5_CNT_MR_ALLOC_BULK) &&
9689 : 0 : mlx5_flow_create_counter_stat_mem_mng(sh)) {
9690 : 0 : DRV_LOG(ERR, "Cannot resize counter stat mem.");
9691 : 0 : return -1;
9692 : : }
9693 : 0 : rte_spinlock_lock(&pool->sl);
9694 : 0 : pool->raw = cmng->mem_mng->raws + pool->index % MLX5_CNT_MR_ALLOC_BULK;
9695 : : rte_spinlock_unlock(&pool->sl);
9696 : 0 : pool->raw_hw = NULL;
9697 : 0 : return 0;
9698 : : }
9699 : :
9700 : : #define MLX5_POOL_QUERY_FREQ_US 1000000
9701 : :
9702 : : /**
9703 : : * Set the periodic procedure for triggering asynchronous batch queries for all
9704 : : * the counter pools.
9705 : : *
9706 : : * @param[in] sh
9707 : : * Pointer to mlx5_dev_ctx_shared object.
9708 : : */
9709 : : void
9710 : 0 : mlx5_set_query_alarm(struct mlx5_dev_ctx_shared *sh)
9711 : : {
9712 : : uint32_t pools_n, us;
9713 : :
9714 : 0 : pools_n = rte_atomic_load_explicit(&sh->sws_cmng.n_valid, rte_memory_order_relaxed);
9715 : 0 : us = MLX5_POOL_QUERY_FREQ_US / pools_n;
9716 : 0 : DRV_LOG(DEBUG, "Set alarm for %u pools each %u us", pools_n, us);
9717 [ # # ]: 0 : if (rte_eal_alarm_set(us, mlx5_flow_query_alarm, sh)) {
9718 : 0 : sh->sws_cmng.query_thread_on = 0;
9719 : 0 : DRV_LOG(ERR, "Cannot reinitialize query alarm");
9720 : : } else {
9721 : 0 : sh->sws_cmng.query_thread_on = 1;
9722 : : }
9723 : 0 : }
9724 : :
9725 : : /**
9726 : : * The periodic procedure for triggering asynchronous batch queries for all the
9727 : : * counter pools. This function is probably called by the host thread.
9728 : : *
9729 : : * @param[in] arg
9730 : : * The parameter for the alarm process.
9731 : : */
9732 : : void
9733 : 0 : mlx5_flow_query_alarm(void *arg)
9734 : : {
9735 : : struct mlx5_dev_ctx_shared *sh = arg;
9736 : : struct mlx5_flow_counter_mng *cmng = &sh->sws_cmng;
9737 : 0 : uint16_t pool_index = cmng->pool_index;
9738 : : struct mlx5_flow_counter_pool *pool;
9739 : : uint16_t n_valid;
9740 : : int ret;
9741 : :
9742 [ # # ]: 0 : if (cmng->pending_queries >= MLX5_MAX_PENDING_QUERIES)
9743 : 0 : goto set_alarm;
9744 : 0 : rte_spinlock_lock(&cmng->pool_update_sl);
9745 : 0 : pool = cmng->pools[pool_index];
9746 : 0 : n_valid = cmng->n_valid;
9747 : : rte_spinlock_unlock(&cmng->pool_update_sl);
9748 : : /* Set the statistic memory to the new created pool. */
9749 [ # # # # ]: 0 : if ((!pool->raw && mlx5_flow_set_counter_stat_mem(sh, pool)))
9750 : 0 : goto set_alarm;
9751 [ # # ]: 0 : if (pool->raw_hw)
9752 : : /* There is a pool query in progress. */
9753 : 0 : goto set_alarm;
9754 : 0 : pool->raw_hw = LIST_FIRST(&cmng->free_stat_raws);
9755 [ # # ]: 0 : if (!pool->raw_hw)
9756 : : /* No free counter statistics raw memory. */
9757 : 0 : goto set_alarm;
9758 : : /*
9759 : : * Identify the counters released between query trigger and query
9760 : : * handle more efficiently. The counter released in this gap period
9761 : : * should wait for a new round of query as the new arrived packets
9762 : : * will not be taken into account.
9763 : : */
9764 : 0 : pool->query_gen++;
9765 : 0 : ret = mlx5_devx_cmd_flow_counter_query(pool->min_dcs, 0,
9766 : : MLX5_COUNTERS_PER_POOL,
9767 : : NULL, NULL,
9768 : 0 : pool->raw_hw->mem_mng->wm.lkey,
9769 : : (void *)(uintptr_t)
9770 : 0 : pool->raw_hw->data,
9771 : : sh->devx_comp,
9772 : : (uint64_t)(uintptr_t)pool);
9773 [ # # ]: 0 : if (ret) {
9774 : 0 : DRV_LOG(ERR, "Failed to trigger asynchronous query for dcs ID"
9775 : : " %d", pool->min_dcs->id);
9776 : 0 : pool->raw_hw = NULL;
9777 : 0 : goto set_alarm;
9778 : : }
9779 [ # # ]: 0 : LIST_REMOVE(pool->raw_hw, next);
9780 : 0 : cmng->pending_queries++;
9781 : 0 : pool_index++;
9782 [ # # ]: 0 : if (pool_index >= n_valid)
9783 : : pool_index = 0;
9784 : 0 : set_alarm:
9785 : 0 : cmng->pool_index = pool_index;
9786 : 0 : mlx5_set_query_alarm(sh);
9787 : 0 : }
9788 : :
9789 : : /**
9790 : : * Check and callback event for new aged flow in the counter pool
9791 : : *
9792 : : * @param[in] sh
9793 : : * Pointer to mlx5_dev_ctx_shared object.
9794 : : * @param[in] pool
9795 : : * Pointer to Current counter pool.
9796 : : */
9797 : : static void
9798 : 0 : mlx5_flow_aging_check(struct mlx5_dev_ctx_shared *sh,
9799 : : struct mlx5_flow_counter_pool *pool)
9800 : : {
9801 : : struct mlx5_priv *priv;
9802 : : struct mlx5_flow_counter *cnt;
9803 : : struct mlx5_age_info *age_info;
9804 : : struct mlx5_age_param *age_param;
9805 : 0 : struct mlx5_counter_stats_raw *cur = pool->raw_hw;
9806 : 0 : struct mlx5_counter_stats_raw *prev = pool->raw;
9807 : 0 : const uint64_t curr_time = MLX5_CURR_TIME_SEC;
9808 : 0 : const uint32_t time_delta = curr_time - pool->time_of_last_age_check;
9809 : : uint16_t expected = AGE_CANDIDATE;
9810 : : uint32_t i;
9811 : :
9812 : 0 : pool->time_of_last_age_check = curr_time;
9813 [ # # ]: 0 : for (i = 0; i < MLX5_COUNTERS_PER_POOL; ++i) {
9814 [ # # ]: 0 : cnt = MLX5_POOL_GET_CNT(pool, i);
9815 : : age_param = MLX5_CNT_TO_AGE(cnt);
9816 [ # # ]: 0 : if (rte_atomic_load_explicit(&age_param->state,
9817 : : rte_memory_order_relaxed) != AGE_CANDIDATE)
9818 : 0 : continue;
9819 [ # # ]: 0 : if (cur->data[i].hits != prev->data[i].hits) {
9820 : 0 : rte_atomic_store_explicit(&age_param->sec_since_last_hit, 0,
9821 : : rte_memory_order_relaxed);
9822 : 0 : continue;
9823 : : }
9824 : 0 : if (rte_atomic_fetch_add_explicit(&age_param->sec_since_last_hit,
9825 : : time_delta,
9826 [ # # ]: 0 : rte_memory_order_relaxed) + time_delta <= age_param->timeout)
9827 : 0 : continue;
9828 : : /**
9829 : : * Hold the lock first, or if between the
9830 : : * state AGE_TMOUT and tailq operation the
9831 : : * release happened, the release procedure
9832 : : * may delete a non-existent tailq node.
9833 : : */
9834 : 0 : priv = rte_eth_devices[age_param->port_id].data->dev_private;
9835 : 0 : age_info = GET_PORT_AGE_INFO(priv);
9836 : 0 : rte_spinlock_lock(&age_info->aged_sl);
9837 [ # # ]: 0 : if (rte_atomic_compare_exchange_strong_explicit(&age_param->state, &expected,
9838 : : AGE_TMOUT,
9839 : : rte_memory_order_relaxed,
9840 : : rte_memory_order_relaxed)) {
9841 : 0 : TAILQ_INSERT_TAIL(&age_info->aged_counters, cnt, next);
9842 : 0 : MLX5_AGE_SET(age_info, MLX5_AGE_EVENT_NEW);
9843 : : }
9844 : : rte_spinlock_unlock(&age_info->aged_sl);
9845 : : }
9846 : 0 : mlx5_age_event_prepare(sh);
9847 : 0 : }
9848 : :
9849 : : /**
9850 : : * Handler for the HW respond about ready values from an asynchronous batch
9851 : : * query. This function is probably called by the host thread.
9852 : : *
9853 : : * @param[in] sh
9854 : : * The pointer to the shared device context.
9855 : : * @param[in] async_id
9856 : : * The Devx async ID.
9857 : : * @param[in] status
9858 : : * The status of the completion.
9859 : : */
9860 : : void
9861 : 0 : mlx5_flow_async_pool_query_handle(struct mlx5_dev_ctx_shared *sh,
9862 : : uint64_t async_id, int status)
9863 : : {
9864 : 0 : struct mlx5_flow_counter_pool *pool =
9865 : : (struct mlx5_flow_counter_pool *)(uintptr_t)async_id;
9866 : : struct mlx5_counter_stats_raw *raw_to_free;
9867 : 0 : uint8_t query_gen = pool->query_gen ^ 1;
9868 : : struct mlx5_flow_counter_mng *cmng = &sh->sws_cmng;
9869 : 0 : enum mlx5_counter_type cnt_type =
9870 : 0 : pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
9871 : : MLX5_COUNTER_TYPE_ORIGIN;
9872 : :
9873 [ # # ]: 0 : if (unlikely(status)) {
9874 : 0 : raw_to_free = pool->raw_hw;
9875 : : } else {
9876 : 0 : raw_to_free = pool->raw;
9877 [ # # ]: 0 : if (pool->is_aged)
9878 : 0 : mlx5_flow_aging_check(sh, pool);
9879 : 0 : rte_spinlock_lock(&pool->sl);
9880 : 0 : pool->raw = pool->raw_hw;
9881 : : rte_spinlock_unlock(&pool->sl);
9882 : : /* Be sure the new raw counters data is updated in memory. */
9883 : 0 : rte_io_wmb();
9884 [ # # ]: 0 : if (!TAILQ_EMPTY(&pool->counters[query_gen])) {
9885 : 0 : rte_spinlock_lock(&cmng->csl[cnt_type]);
9886 [ # # ]: 0 : TAILQ_CONCAT(&cmng->counters[cnt_type],
9887 : : &pool->counters[query_gen], next);
9888 : : rte_spinlock_unlock(&cmng->csl[cnt_type]);
9889 : : }
9890 : : }
9891 [ # # ]: 0 : LIST_INSERT_HEAD(&sh->sws_cmng.free_stat_raws, raw_to_free, next);
9892 : 0 : pool->raw_hw = NULL;
9893 : 0 : sh->sws_cmng.pending_queries--;
9894 : 0 : }
9895 : :
9896 : : static int
9897 : 0 : flow_group_to_table(uint32_t port_id, uint32_t group, uint32_t *table,
9898 : : const struct flow_grp_info *grp_info,
9899 : : struct rte_flow_error *error)
9900 : : {
9901 [ # # ]: 0 : if (grp_info->transfer && grp_info->external &&
9902 : : grp_info->fdb_def_rule) {
9903 [ # # ]: 0 : if (group == UINT32_MAX)
9904 : 0 : return rte_flow_error_set
9905 : : (error, EINVAL,
9906 : : RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
9907 : : NULL,
9908 : : "group index not supported");
9909 : 0 : *table = group + 1;
9910 : : } else {
9911 : 0 : *table = group;
9912 : : }
9913 : 0 : DRV_LOG(DEBUG, "port %u group=%#x table=%#x", port_id, group, *table);
9914 : 0 : return 0;
9915 : : }
9916 : :
9917 : : /**
9918 : : * Translate the rte_flow group index to HW table value.
9919 : : *
9920 : : * If tunnel offload is disabled, all group ids converted to flow table
9921 : : * id using the standard method.
9922 : : * If tunnel offload is enabled, group id can be converted using the
9923 : : * standard or tunnel conversion method. Group conversion method
9924 : : * selection depends on flags in `grp_info` parameter:
9925 : : * - Internal (grp_info.external == 0) groups conversion uses the
9926 : : * standard method.
9927 : : * - Group ids in JUMP action converted with the tunnel conversion.
9928 : : * - Group id in rule attribute conversion depends on a rule type and
9929 : : * group id value:
9930 : : * ** non zero group attributes converted with the tunnel method
9931 : : * ** zero group attribute in non-tunnel rule is converted using the
9932 : : * standard method - there's only one root table
9933 : : * ** zero group attribute in steer tunnel rule is converted with the
9934 : : * standard method - single root table
9935 : : * ** zero group attribute in match tunnel rule is a special OvS
9936 : : * case: that value is used for portability reasons. That group
9937 : : * id is converted with the tunnel conversion method.
9938 : : *
9939 : : * @param[in] dev
9940 : : * Port device
9941 : : * @param[in] tunnel
9942 : : * PMD tunnel offload object
9943 : : * @param[in] group
9944 : : * rte_flow group index value.
9945 : : * @param[out] table
9946 : : * HW table value.
9947 : : * @param[in] grp_info
9948 : : * flags used for conversion
9949 : : * @param[out] error
9950 : : * Pointer to error structure.
9951 : : *
9952 : : * @return
9953 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9954 : : */
9955 : : int
9956 : 0 : mlx5_flow_group_to_table(struct rte_eth_dev *dev,
9957 : : const struct mlx5_flow_tunnel *tunnel,
9958 : : uint32_t group, uint32_t *table,
9959 : : const struct flow_grp_info *grp_info,
9960 : : struct rte_flow_error *error)
9961 : : {
9962 : : int ret;
9963 : : bool standard_translation;
9964 : :
9965 [ # # # # ]: 0 : if (!grp_info->skip_scale && grp_info->external &&
9966 : : group < MLX5_MAX_TABLES_EXTERNAL)
9967 : 0 : group *= MLX5_FLOW_TABLE_FACTOR;
9968 [ # # ]: 0 : if (is_tunnel_offload_active(dev)) {
9969 : 0 : standard_translation = !grp_info->external ||
9970 : : grp_info->std_tbl_fix;
9971 : : } else {
9972 : : standard_translation = true;
9973 : : }
9974 [ # # ]: 0 : DRV_LOG(DEBUG,
9975 : : "port %u group=%u transfer=%d external=%d fdb_def_rule=%d translate=%s",
9976 : : dev->data->port_id, group, grp_info->transfer,
9977 : : grp_info->external, grp_info->fdb_def_rule,
9978 : : standard_translation ? "STANDARD" : "TUNNEL");
9979 [ # # ]: 0 : if (standard_translation)
9980 : 0 : ret = flow_group_to_table(dev->data->port_id, group, table,
9981 : : grp_info, error);
9982 : : else
9983 : 0 : ret = tunnel_flow_group_to_flow_table(dev, tunnel, group,
9984 : : table, error);
9985 : :
9986 : 0 : return ret;
9987 : : }
9988 : :
9989 : : /**
9990 : : * Discover availability of metadata reg_c's.
9991 : : *
9992 : : * Iteratively use test flows to check availability.
9993 : : *
9994 : : * @param[in] dev
9995 : : * Pointer to the Ethernet device structure.
9996 : : *
9997 : : * @return
9998 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9999 : : */
10000 : : int
10001 : 0 : mlx5_flow_discover_mreg_c(struct rte_eth_dev *dev)
10002 : : {
10003 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10004 : : enum modify_reg idx;
10005 : : int n = 0;
10006 : :
10007 : : /* reg_c[0] and reg_c[1] are reserved. */
10008 : 0 : priv->sh->flow_mreg_c[n++] = REG_C_0;
10009 : 0 : priv->sh->flow_mreg_c[n++] = REG_C_1;
10010 : : /* Discover availability of other reg_c's. */
10011 [ # # ]: 0 : for (idx = REG_C_2; idx <= REG_C_7; ++idx) {
10012 : 0 : struct rte_flow_attr attr = {
10013 : : .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
10014 : : .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
10015 : : .ingress = 1,
10016 : : };
10017 : 0 : struct rte_flow_item items[] = {
10018 : : [0] = {
10019 : : .type = RTE_FLOW_ITEM_TYPE_END,
10020 : : },
10021 : : };
10022 : 0 : struct rte_flow_action actions[] = {
10023 : : [0] = {
10024 : : .type = (enum rte_flow_action_type)
10025 : : MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
10026 : 0 : .conf = &(struct mlx5_flow_action_copy_mreg){
10027 : : .src = REG_C_1,
10028 : : .dst = idx,
10029 : : },
10030 : : },
10031 : : [1] = {
10032 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
10033 : 0 : .conf = &(struct rte_flow_action_jump){
10034 : : .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
10035 : : },
10036 : : },
10037 : : [2] = {
10038 : : .type = RTE_FLOW_ACTION_TYPE_END,
10039 : : },
10040 : : };
10041 : : uint32_t flow_idx;
10042 : : struct rte_flow *flow;
10043 : : struct rte_flow_error error;
10044 : :
10045 [ # # ]: 0 : if (!priv->sh->config.dv_flow_en)
10046 : : break;
10047 : : /* Create internal flow, validation skips copy action. */
10048 : 0 : flow_idx = mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_GEN, &attr,
10049 : : items, actions, false, &error);
10050 : 0 : flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
10051 : : flow_idx);
10052 [ # # ]: 0 : if (!flow)
10053 : 0 : continue;
10054 : 0 : priv->sh->flow_mreg_c[n++] = idx;
10055 : 0 : mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN, flow_idx);
10056 : : }
10057 [ # # ]: 0 : for (; n < MLX5_MREG_C_NUM; ++n)
10058 : 0 : priv->sh->flow_mreg_c[n] = REG_NON;
10059 : 0 : priv->sh->metadata_regc_check_flag = 1;
10060 : 0 : return 0;
10061 : : }
10062 : :
10063 : : int
10064 [ # # # # ]: 0 : save_dump_file(const uint8_t *data, uint32_t size,
10065 : : uint32_t type, uint64_t id, void *arg, FILE *file)
10066 : : {
10067 : : char line[BUF_SIZE];
10068 : : uint32_t out = 0;
10069 : : uint32_t k;
10070 : : uint32_t actions_num;
10071 : : struct rte_flow_query_count *count;
10072 : :
10073 : : memset(line, 0, BUF_SIZE);
10074 [ # # # # ]: 0 : switch (type) {
10075 : 0 : case DR_DUMP_REC_TYPE_PMD_MODIFY_HDR:
10076 : 0 : actions_num = *(uint32_t *)(arg);
10077 : 0 : out += snprintf(line + out, BUF_SIZE - out, "%d,0x%" PRIx64 ",%d,",
10078 : : type, id, actions_num);
10079 : 0 : break;
10080 : 0 : case DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT:
10081 : 0 : out += snprintf(line + out, BUF_SIZE - out, "%d,0x%" PRIx64 ",",
10082 : : type, id);
10083 : 0 : break;
10084 : 0 : case DR_DUMP_REC_TYPE_PMD_COUNTER:
10085 : : count = (struct rte_flow_query_count *)arg;
10086 : 0 : fprintf(file,
10087 : : "%d,0x%" PRIx64 ",%" PRIu64 ",%" PRIu64 "\n",
10088 : : type, id, count->hits, count->bytes);
10089 : 0 : return 0;
10090 : : default:
10091 : : return -1;
10092 : : }
10093 : :
10094 [ # # ]: 0 : for (k = 0; k < size; k++) {
10095 : : /* Make sure we do not overrun the line buffer length. */
10096 [ # # ]: 0 : if (out >= BUF_SIZE - 4) {
10097 : 0 : line[out] = '\0';
10098 : 0 : break;
10099 : : }
10100 : 0 : out += snprintf(line + out, BUF_SIZE - out, "%02x",
10101 : 0 : (data[k]) & 0xff);
10102 : : }
10103 : : fprintf(file, "%s\n", line);
10104 : 0 : return 0;
10105 : : }
10106 : :
10107 : : int
10108 : 0 : mlx5_flow_query_counter(struct rte_eth_dev *dev, struct rte_flow *flow,
10109 : : struct rte_flow_query_count *count, struct rte_flow_error *error)
10110 : : {
10111 : : struct rte_flow_action action[2];
10112 : : enum mlx5_flow_drv_type ftype;
10113 : : const struct mlx5_flow_driver_ops *fops;
10114 : :
10115 [ # # ]: 0 : if (!flow) {
10116 : 0 : return rte_flow_error_set(error, ENOENT,
10117 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10118 : : NULL,
10119 : : "invalid flow handle");
10120 : : }
10121 : 0 : action[0].type = RTE_FLOW_ACTION_TYPE_COUNT;
10122 : 0 : action[1].type = RTE_FLOW_ACTION_TYPE_END;
10123 [ # # ]: 0 : if (flow->counter) {
10124 : : memset(count, 0, sizeof(struct rte_flow_query_count));
10125 : 0 : ftype = (enum mlx5_flow_drv_type)(flow->drv_type);
10126 : : MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN &&
10127 : : ftype < MLX5_FLOW_TYPE_MAX);
10128 : 0 : fops = flow_get_drv_ops(ftype);
10129 : 0 : return fops->query(dev, flow, action, count, error);
10130 : : }
10131 : : return -1;
10132 : : }
10133 : :
10134 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
10135 : : /**
10136 : : * Dump flow ipool data to file
10137 : : *
10138 : : * @param[in] dev
10139 : : * The pointer to Ethernet device.
10140 : : * @param[in] file
10141 : : * A pointer to a file for output.
10142 : : * @param[out] error
10143 : : * Perform verbose error reporting if not NULL. PMDs initialize this
10144 : : * structure in case of error only.
10145 : : * @return
10146 : : * 0 on success, a negative value otherwise.
10147 : : */
10148 : : int
10149 : 0 : mlx5_flow_dev_dump_ipool(struct rte_eth_dev *dev,
10150 : : struct rte_flow *flow, FILE *file,
10151 : : struct rte_flow_error *error)
10152 : : {
10153 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10154 : : struct mlx5_flow_dv_modify_hdr_resource *modify_hdr;
10155 : : struct mlx5_flow_dv_encap_decap_resource *encap_decap;
10156 : : uint32_t handle_idx;
10157 : : struct mlx5_flow_handle *dh;
10158 : : struct rte_flow_query_count count;
10159 : : uint32_t actions_num;
10160 : : const uint8_t *data;
10161 : : size_t size;
10162 : : uint64_t id;
10163 : : uint32_t type;
10164 : 0 : void *action = NULL;
10165 : :
10166 [ # # ]: 0 : if (!flow) {
10167 : 0 : return rte_flow_error_set(error, ENOENT,
10168 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10169 : : NULL,
10170 : : "invalid flow handle");
10171 : : }
10172 : 0 : handle_idx = flow->dev_handles;
10173 : : /* query counter */
10174 [ # # # # ]: 0 : if (flow->counter &&
10175 : 0 : (!mlx5_counter_query(dev, flow->counter, false,
10176 [ # # ]: 0 : &count.hits, &count.bytes, &action)) && action) {
10177 : 0 : id = (uint64_t)(uintptr_t)action;
10178 : : type = DR_DUMP_REC_TYPE_PMD_COUNTER;
10179 : 0 : save_dump_file(NULL, 0, type,
10180 : : id, (void *)&count, file);
10181 : : }
10182 : :
10183 [ # # ]: 0 : while (handle_idx) {
10184 : 0 : dh = mlx5_ipool_get(priv->sh->ipool
10185 : : [MLX5_IPOOL_MLX5_FLOW], handle_idx);
10186 [ # # ]: 0 : if (!dh)
10187 : 0 : continue;
10188 : 0 : handle_idx = dh->next.next;
10189 : :
10190 : : /* Get modify_hdr and encap_decap buf from ipools. */
10191 : : encap_decap = NULL;
10192 : 0 : modify_hdr = dh->dvh.modify_hdr;
10193 : :
10194 [ # # ]: 0 : if (dh->dvh.rix_encap_decap) {
10195 : 0 : encap_decap = mlx5_ipool_get(priv->sh->ipool
10196 : : [MLX5_IPOOL_DECAP_ENCAP],
10197 : : dh->dvh.rix_encap_decap);
10198 : : }
10199 [ # # ]: 0 : if (modify_hdr) {
10200 : 0 : data = (const uint8_t *)modify_hdr->actions;
10201 : 0 : size = (size_t)(modify_hdr->actions_num) * 8;
10202 : 0 : id = (uint64_t)(uintptr_t)modify_hdr->action;
10203 : 0 : actions_num = modify_hdr->actions_num;
10204 : : type = DR_DUMP_REC_TYPE_PMD_MODIFY_HDR;
10205 : 0 : save_dump_file(data, size, type, id,
10206 : : (void *)(&actions_num), file);
10207 : : }
10208 [ # # ]: 0 : if (encap_decap) {
10209 : 0 : data = encap_decap->buf;
10210 : 0 : size = encap_decap->size;
10211 : 0 : id = (uint64_t)(uintptr_t)encap_decap->action;
10212 : : type = DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT;
10213 : 0 : save_dump_file(data, size, type,
10214 : : id, NULL, file);
10215 : : }
10216 : : }
10217 : : return 0;
10218 : : }
10219 : :
10220 : : /**
10221 : : * Dump all flow's encap_decap/modify_hdr/counter data to file
10222 : : *
10223 : : * @param[in] dev
10224 : : * The pointer to Ethernet device.
10225 : : * @param[in] file
10226 : : * A pointer to a file for output.
10227 : : * @param[out] error
10228 : : * Perform verbose error reporting if not NULL. PMDs initialize this
10229 : : * structure in case of error only.
10230 : : * @return
10231 : : * 0 on success, a negative value otherwise.
10232 : : */
10233 : : static int
10234 : 0 : mlx5_flow_dev_dump_sh_all(struct rte_eth_dev *dev,
10235 : : FILE *file, struct rte_flow_error *error __rte_unused)
10236 : : {
10237 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10238 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
10239 : : struct mlx5_hlist *h;
10240 : : struct mlx5_flow_dv_modify_hdr_resource *modify_hdr;
10241 : : struct mlx5_flow_dv_encap_decap_resource *encap_decap;
10242 : : struct rte_flow_query_count count;
10243 : : uint32_t actions_num;
10244 : : const uint8_t *data;
10245 : : size_t size;
10246 : : uint64_t id;
10247 : : uint32_t type;
10248 : : uint32_t i;
10249 : : uint32_t j;
10250 : : struct mlx5_list_inconst *l_inconst;
10251 : : struct mlx5_list_entry *e;
10252 : : int lcore_index;
10253 : : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
10254 : : uint32_t max;
10255 : : void *action;
10256 : :
10257 : : /* encap_decap hlist is lcore_share, get global core cache. */
10258 : : i = MLX5_LIST_GLOBAL;
10259 : 0 : h = sh->encaps_decaps;
10260 [ # # ]: 0 : if (h) {
10261 [ # # ]: 0 : for (j = 0; j <= h->mask; j++) {
10262 : : l_inconst = &h->buckets[j].l;
10263 [ # # ]: 0 : if (!l_inconst || !l_inconst->cache[i])
10264 : 0 : continue;
10265 : :
10266 : 0 : e = LIST_FIRST(&l_inconst->cache[i]->h);
10267 [ # # ]: 0 : while (e) {
10268 : : encap_decap =
10269 : : (struct mlx5_flow_dv_encap_decap_resource *)e;
10270 : 0 : data = encap_decap->buf;
10271 : 0 : size = encap_decap->size;
10272 : 0 : id = (uint64_t)(uintptr_t)encap_decap->action;
10273 : : type = DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT;
10274 : 0 : save_dump_file(data, size, type,
10275 : : id, NULL, file);
10276 : 0 : e = LIST_NEXT(e, next);
10277 : : }
10278 : : }
10279 : : }
10280 : :
10281 : : /* get modify_hdr */
10282 : 0 : h = sh->modify_cmds;
10283 [ # # ]: 0 : if (h) {
10284 : 0 : lcore_index = rte_lcore_index(rte_lcore_id());
10285 [ # # ]: 0 : if (unlikely(lcore_index == -1)) {
10286 : : lcore_index = MLX5_LIST_NLCORE;
10287 : 0 : rte_spinlock_lock(&h->l_const.lcore_lock);
10288 : : }
10289 : 0 : i = lcore_index;
10290 : :
10291 [ # # ]: 0 : if (lcore_index == MLX5_LIST_NLCORE) {
10292 [ # # ]: 0 : for (i = 0; i <= (uint32_t)lcore_index; i++) {
10293 [ # # ]: 0 : for (j = 0; j <= h->mask; j++) {
10294 : : l_inconst = &h->buckets[j].l;
10295 [ # # ]: 0 : if (!l_inconst || !l_inconst->cache[i])
10296 : 0 : continue;
10297 : :
10298 : 0 : e = LIST_FIRST(&l_inconst->cache[i]->h);
10299 [ # # ]: 0 : while (e) {
10300 : : modify_hdr =
10301 : : (struct mlx5_flow_dv_modify_hdr_resource *)e;
10302 : 0 : data = (const uint8_t *)modify_hdr->actions;
10303 : 0 : size = (size_t)(modify_hdr->actions_num) * 8;
10304 : 0 : actions_num = modify_hdr->actions_num;
10305 : 0 : id = (uint64_t)(uintptr_t)modify_hdr->action;
10306 : : type = DR_DUMP_REC_TYPE_PMD_MODIFY_HDR;
10307 : 0 : save_dump_file(data, size, type, id,
10308 : : (void *)(&actions_num), file);
10309 : 0 : e = LIST_NEXT(e, next);
10310 : : }
10311 : : }
10312 : : }
10313 : : } else {
10314 [ # # ]: 0 : for (j = 0; j <= h->mask; j++) {
10315 : : l_inconst = &h->buckets[j].l;
10316 [ # # ]: 0 : if (!l_inconst || !l_inconst->cache[i])
10317 : 0 : continue;
10318 : :
10319 : 0 : e = LIST_FIRST(&l_inconst->cache[i]->h);
10320 [ # # ]: 0 : while (e) {
10321 : : modify_hdr =
10322 : : (struct mlx5_flow_dv_modify_hdr_resource *)e;
10323 : 0 : data = (const uint8_t *)modify_hdr->actions;
10324 : 0 : size = (size_t)(modify_hdr->actions_num) * 8;
10325 : 0 : actions_num = modify_hdr->actions_num;
10326 : 0 : id = (uint64_t)(uintptr_t)modify_hdr->action;
10327 : : type = DR_DUMP_REC_TYPE_PMD_MODIFY_HDR;
10328 : 0 : save_dump_file(data, size, type, id,
10329 : : (void *)(&actions_num), file);
10330 : 0 : e = LIST_NEXT(e, next);
10331 : : }
10332 : : }
10333 : : }
10334 : :
10335 [ # # ]: 0 : if (unlikely(lcore_index == MLX5_LIST_NLCORE))
10336 : 0 : rte_spinlock_unlock(&h->l_const.lcore_lock);
10337 : : }
10338 : :
10339 : : /* get counter */
10340 : : MLX5_ASSERT(cmng->n_valid <= MLX5_COUNTER_POOLS_MAX_NUM);
10341 : 0 : max = MLX5_COUNTERS_PER_POOL * cmng->n_valid;
10342 [ # # ]: 0 : for (j = 1; j <= max; j++) {
10343 : 0 : action = NULL;
10344 [ # # ]: 0 : if ((!mlx5_counter_query(dev, j, false, &count.hits,
10345 [ # # ]: 0 : &count.bytes, &action)) && action) {
10346 : 0 : id = (uint64_t)(uintptr_t)action;
10347 : : type = DR_DUMP_REC_TYPE_PMD_COUNTER;
10348 : 0 : save_dump_file(NULL, 0, type,
10349 : : id, (void *)&count, file);
10350 : : }
10351 : : }
10352 : 0 : return 0;
10353 : : }
10354 : : #endif
10355 : :
10356 : : /**
10357 : : * Dump flow raw hw data to file
10358 : : *
10359 : : * @param[in] dev
10360 : : * The pointer to Ethernet device.
10361 : : * @param[in] file
10362 : : * A pointer to a file for output.
10363 : : * @param[out] error
10364 : : * Perform verbose error reporting if not NULL. PMDs initialize this
10365 : : * structure in case of error only.
10366 : : * @return
10367 : : * 0 on success, a negative value otherwise.
10368 : : */
10369 : : int
10370 : 0 : mlx5_flow_dev_dump(struct rte_eth_dev *dev, struct rte_flow *flow_idx,
10371 : : FILE *file,
10372 : : struct rte_flow_error *error __rte_unused)
10373 : : {
10374 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10375 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
10376 : : uint32_t handle_idx;
10377 : : int ret;
10378 : : struct mlx5_flow_handle *dh;
10379 : : struct rte_flow *flow;
10380 : :
10381 [ # # ]: 0 : if (!sh->config.dv_flow_en) {
10382 [ # # ]: 0 : if (fputs("device dv flow disabled\n", file) <= 0)
10383 : 0 : return -errno;
10384 : : return -ENOTSUP;
10385 : : }
10386 : :
10387 : : /* dump all */
10388 [ # # ]: 0 : if (!flow_idx) {
10389 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
10390 [ # # ]: 0 : if (mlx5_flow_dev_dump_sh_all(dev, file, error))
10391 : : return -EINVAL;
10392 : :
10393 [ # # ]: 0 : if (sh->config.dv_flow_en == 2)
10394 : 0 : return mlx5dr_debug_dump(priv->dr_ctx, file);
10395 : : #endif
10396 : 0 : return mlx5_devx_cmd_flow_dump(sh->fdb_domain,
10397 : : sh->rx_domain,
10398 : : sh->tx_domain, file);
10399 : : }
10400 : : /* dump one */
10401 : 0 : flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
10402 : : (uintptr_t)(void *)flow_idx);
10403 [ # # ]: 0 : if (!flow)
10404 : : return -EINVAL;
10405 : :
10406 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
10407 : 0 : mlx5_flow_dev_dump_ipool(dev, flow, file, error);
10408 : : #endif
10409 : 0 : handle_idx = flow->dev_handles;
10410 [ # # ]: 0 : while (handle_idx) {
10411 : 0 : dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
10412 : : handle_idx);
10413 [ # # ]: 0 : if (!dh)
10414 : : return -ENOENT;
10415 [ # # ]: 0 : if (dh->drv_flow) {
10416 [ # # ]: 0 : if (sh->config.dv_flow_en == 2)
10417 : : return -ENOTSUP;
10418 : :
10419 : 0 : ret = mlx5_devx_cmd_flow_single_dump(dh->drv_flow,
10420 : : file);
10421 [ # # ]: 0 : if (ret)
10422 : : return -ENOENT;
10423 : : }
10424 : 0 : handle_idx = dh->next.next;
10425 : : }
10426 : : return 0;
10427 : : }
10428 : :
10429 : : /**
10430 : : * Get aged-out flows.
10431 : : *
10432 : : * @param[in] dev
10433 : : * Pointer to the Ethernet device structure.
10434 : : * @param[in] context
10435 : : * The address of an array of pointers to the aged-out flows contexts.
10436 : : * @param[in] nb_countexts
10437 : : * The length of context array pointers.
10438 : : * @param[out] error
10439 : : * Perform verbose error reporting if not NULL. Initialized in case of
10440 : : * error only.
10441 : : *
10442 : : * @return
10443 : : * how many contexts get in success, otherwise negative errno value.
10444 : : * if nb_contexts is 0, return the amount of all aged contexts.
10445 : : * if nb_contexts is not 0 , return the amount of aged flows reported
10446 : : * in the context array.
10447 : : */
10448 : : int
10449 [ # # ]: 0 : mlx5_flow_get_aged_flows(struct rte_eth_dev *dev, void **contexts,
10450 : : uint32_t nb_contexts, struct rte_flow_error *error)
10451 : : {
10452 : : struct rte_flow_attr attr = { .transfer = 0 };
10453 : :
10454 : 0 : return flow_get_drv_ops(flow_get_drv_type(dev, &attr))->get_aged_flows
10455 : : (dev, contexts, nb_contexts, error);
10456 : : }
10457 : :
10458 : : /**
10459 : : * Get aged-out flows per HWS queue.
10460 : : *
10461 : : * @param[in] dev
10462 : : * Pointer to the Ethernet device structure.
10463 : : * @param[in] queue_id
10464 : : * Flow queue to query.
10465 : : * @param[in] context
10466 : : * The address of an array of pointers to the aged-out flows contexts.
10467 : : * @param[in] nb_countexts
10468 : : * The length of context array pointers.
10469 : : * @param[out] error
10470 : : * Perform verbose error reporting if not NULL. Initialized in case of
10471 : : * error only.
10472 : : *
10473 : : * @return
10474 : : * how many contexts get in success, otherwise negative errno value.
10475 : : * if nb_contexts is 0, return the amount of all aged contexts.
10476 : : * if nb_contexts is not 0 , return the amount of aged flows reported
10477 : : * in the context array.
10478 : : */
10479 : : int
10480 [ # # ]: 0 : mlx5_flow_get_q_aged_flows(struct rte_eth_dev *dev, uint32_t queue_id,
10481 : : void **contexts, uint32_t nb_contexts,
10482 : : struct rte_flow_error *error)
10483 : : {
10484 : : const struct mlx5_flow_driver_ops *fops;
10485 : : struct rte_flow_attr attr = { 0 };
10486 : :
10487 : : if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_HW) {
10488 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
10489 : 0 : return fops->get_q_aged_flows(dev, queue_id, contexts,
10490 : : nb_contexts, error);
10491 : : }
10492 : 0 : DRV_LOG(ERR, "port %u queue %u get aged flows is not supported.",
10493 : : dev->data->port_id, queue_id);
10494 : 0 : return rte_flow_error_set(error, ENOTSUP,
10495 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10496 : : "get Q aged flows with incorrect steering mode");
10497 : : }
10498 : :
10499 : : /* Wrapper for driver action_validate op callback */
10500 : : static int
10501 : 0 : flow_drv_action_validate(struct rte_eth_dev *dev,
10502 : : const struct rte_flow_indir_action_conf *conf,
10503 : : const struct rte_flow_action *action,
10504 : : const struct mlx5_flow_driver_ops *fops,
10505 : : struct rte_flow_error *error)
10506 : : {
10507 : : static const char err_msg[] = "indirect action validation unsupported";
10508 : :
10509 [ # # ]: 0 : if (!fops->action_validate) {
10510 : 0 : DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
10511 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
10512 : : NULL, err_msg);
10513 : 0 : return -rte_errno;
10514 : : }
10515 : 0 : return fops->action_validate(dev, conf, action, error);
10516 : : }
10517 : :
10518 : : /**
10519 : : * Destroys the shared action by handle.
10520 : : *
10521 : : * @param dev
10522 : : * Pointer to Ethernet device structure.
10523 : : * @param[in] handle
10524 : : * Handle for the indirect action object to be destroyed.
10525 : : * @param[out] error
10526 : : * Perform verbose error reporting if not NULL. PMDs initialize this
10527 : : * structure in case of error only.
10528 : : *
10529 : : * @return
10530 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
10531 : : *
10532 : : * @note: wrapper for driver action_create op callback.
10533 : : */
10534 : : static int
10535 [ # # ]: 0 : mlx5_action_handle_destroy(struct rte_eth_dev *dev,
10536 : : struct rte_flow_action_handle *handle,
10537 : : struct rte_flow_error *error)
10538 : : {
10539 : : static const char err_msg[] = "indirect action destruction unsupported";
10540 : : struct rte_flow_attr attr = { .transfer = 0 };
10541 : 0 : const struct mlx5_flow_driver_ops *fops =
10542 : : flow_get_drv_ops(flow_get_drv_type(dev, &attr));
10543 : :
10544 [ # # ]: 0 : if (!fops->action_destroy) {
10545 : 0 : DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
10546 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
10547 : : NULL, err_msg);
10548 : 0 : return -rte_errno;
10549 : : }
10550 : 0 : return fops->action_destroy(dev, handle, error);
10551 : : }
10552 : :
10553 : : /* Wrapper for driver action_destroy op callback */
10554 : : static int
10555 : 0 : flow_drv_action_update(struct rte_eth_dev *dev,
10556 : : struct rte_flow_action_handle *handle,
10557 : : const void *update,
10558 : : const struct mlx5_flow_driver_ops *fops,
10559 : : struct rte_flow_error *error)
10560 : : {
10561 : : static const char err_msg[] = "indirect action update unsupported";
10562 : :
10563 [ # # ]: 0 : if (!fops->action_update) {
10564 : 0 : DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
10565 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
10566 : : NULL, err_msg);
10567 : 0 : return -rte_errno;
10568 : : }
10569 : 0 : return fops->action_update(dev, handle, update, error);
10570 : : }
10571 : :
10572 : : /* Wrapper for driver action_destroy op callback */
10573 : : static int
10574 : 0 : flow_drv_action_query(struct rte_eth_dev *dev,
10575 : : const struct rte_flow_action_handle *handle,
10576 : : void *data,
10577 : : const struct mlx5_flow_driver_ops *fops,
10578 : : struct rte_flow_error *error)
10579 : : {
10580 : : static const char err_msg[] = "indirect action query unsupported";
10581 : :
10582 [ # # ]: 0 : if (!fops->action_query) {
10583 : 0 : DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
10584 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
10585 : : NULL, err_msg);
10586 : 0 : return -rte_errno;
10587 : : }
10588 : 0 : return fops->action_query(dev, handle, data, error);
10589 : : }
10590 : :
10591 : : /**
10592 : : * Create indirect action for reuse in multiple flow rules.
10593 : : *
10594 : : * @param dev
10595 : : * Pointer to Ethernet device structure.
10596 : : * @param conf
10597 : : * Pointer to indirect action object configuration.
10598 : : * @param[in] action
10599 : : * Action configuration for indirect action object creation.
10600 : : * @param[out] error
10601 : : * Perform verbose error reporting if not NULL. PMDs initialize this
10602 : : * structure in case of error only.
10603 : : * @return
10604 : : * A valid handle in case of success, NULL otherwise and rte_errno is set.
10605 : : */
10606 : : static struct rte_flow_action_handle *
10607 [ # # ]: 0 : mlx5_action_handle_create(struct rte_eth_dev *dev,
10608 : : const struct rte_flow_indir_action_conf *conf,
10609 : : const struct rte_flow_action *action,
10610 : : struct rte_flow_error *error)
10611 : : {
10612 : : static const char err_msg[] = "indirect action creation unsupported";
10613 : : struct rte_flow_attr attr = { .transfer = 0 };
10614 : 0 : const struct mlx5_flow_driver_ops *fops =
10615 : : flow_get_drv_ops(flow_get_drv_type(dev, &attr));
10616 : :
10617 [ # # ]: 0 : if (flow_drv_action_validate(dev, conf, action, fops, error))
10618 : : return NULL;
10619 [ # # ]: 0 : if (!fops->action_create) {
10620 : 0 : DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
10621 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
10622 : : NULL, err_msg);
10623 : 0 : return NULL;
10624 : : }
10625 : 0 : return fops->action_create(dev, conf, action, error);
10626 : : }
10627 : :
10628 : : /**
10629 : : * Updates inplace the indirect action configuration pointed by *handle*
10630 : : * with the configuration provided as *update* argument.
10631 : : * The update of the indirect action configuration effects all flow rules
10632 : : * reusing the action via handle.
10633 : : *
10634 : : * @param dev
10635 : : * Pointer to Ethernet device structure.
10636 : : * @param[in] handle
10637 : : * Handle for the indirect action to be updated.
10638 : : * @param[in] update
10639 : : * Action specification used to modify the action pointed by handle.
10640 : : * *update* could be of same type with the action pointed by the *handle*
10641 : : * handle argument, or some other structures like a wrapper, depending on
10642 : : * the indirect action type.
10643 : : * @param[out] error
10644 : : * Perform verbose error reporting if not NULL. PMDs initialize this
10645 : : * structure in case of error only.
10646 : : *
10647 : : * @return
10648 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
10649 : : */
10650 : : static int
10651 [ # # ]: 0 : mlx5_action_handle_update(struct rte_eth_dev *dev,
10652 : : struct rte_flow_action_handle *handle,
10653 : : const void *update,
10654 : : struct rte_flow_error *error)
10655 : : {
10656 : : struct rte_flow_attr attr = { .transfer = 0 };
10657 : 0 : const struct mlx5_flow_driver_ops *fops =
10658 : : flow_get_drv_ops(flow_get_drv_type(dev, &attr));
10659 : : int ret;
10660 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
10661 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
10662 : :
10663 [ # # ]: 0 : switch (type) {
10664 : : case MLX5_INDIRECT_ACTION_TYPE_CT:
10665 : : case MLX5_INDIRECT_ACTION_TYPE_METER_MARK:
10666 : : ret = 0;
10667 : : break;
10668 : 0 : default:
10669 : 0 : ret = flow_drv_action_validate(dev, NULL,
10670 : : (const struct rte_flow_action *)update,
10671 : : fops, error);
10672 : : }
10673 [ # # ]: 0 : if (ret)
10674 : : return ret;
10675 : 0 : return flow_drv_action_update(dev, handle, update, fops,
10676 : : error);
10677 : : }
10678 : :
10679 : : /**
10680 : : * Query the indirect action by handle.
10681 : : *
10682 : : * This function allows retrieving action-specific data such as counters.
10683 : : * Data is gathered by special action which may be present/referenced in
10684 : : * more than one flow rule definition.
10685 : : *
10686 : : * see @RTE_FLOW_ACTION_TYPE_COUNT
10687 : : *
10688 : : * @param dev
10689 : : * Pointer to Ethernet device structure.
10690 : : * @param[in] handle
10691 : : * Handle for the indirect action to query.
10692 : : * @param[in, out] data
10693 : : * Pointer to storage for the associated query data type.
10694 : : * @param[out] error
10695 : : * Perform verbose error reporting if not NULL. PMDs initialize this
10696 : : * structure in case of error only.
10697 : : *
10698 : : * @return
10699 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
10700 : : */
10701 : : static int
10702 [ # # ]: 0 : mlx5_action_handle_query(struct rte_eth_dev *dev,
10703 : : const struct rte_flow_action_handle *handle,
10704 : : void *data,
10705 : : struct rte_flow_error *error)
10706 : : {
10707 : : struct rte_flow_attr attr = { .transfer = 0 };
10708 : 0 : const struct mlx5_flow_driver_ops *fops =
10709 : : flow_get_drv_ops(flow_get_drv_type(dev, &attr));
10710 : :
10711 : 0 : return flow_drv_action_query(dev, handle, data, fops, error);
10712 : : }
10713 : :
10714 : : static int
10715 [ # # ]: 0 : mlx5_action_handle_query_update(struct rte_eth_dev *dev,
10716 : : struct rte_flow_action_handle *handle,
10717 : : const void *update, void *query,
10718 : : enum rte_flow_query_update_mode qu_mode,
10719 : : struct rte_flow_error *error)
10720 : : {
10721 : : struct rte_flow_attr attr = { .transfer = 0 };
10722 : : enum mlx5_flow_drv_type drv_type = flow_get_drv_type(dev, &attr);
10723 : : const struct mlx5_flow_driver_ops *fops;
10724 : :
10725 : : if (drv_type == MLX5_FLOW_TYPE_MIN || drv_type == MLX5_FLOW_TYPE_MAX)
10726 : : return rte_flow_error_set(error, ENOTSUP,
10727 : : RTE_FLOW_ERROR_TYPE_ACTION,
10728 : : NULL, "invalid driver type");
10729 : 0 : fops = flow_get_drv_ops(drv_type);
10730 [ # # # # ]: 0 : if (!fops || !fops->action_query_update)
10731 : 0 : return rte_flow_error_set(error, ENOTSUP,
10732 : : RTE_FLOW_ERROR_TYPE_ACTION,
10733 : : NULL, "no query_update handler");
10734 : 0 : return fops->action_query_update(dev, handle, update,
10735 : : query, qu_mode, error);
10736 : : }
10737 : :
10738 : :
10739 : : #define MLX5_DRV_FOPS_OR_ERR(dev, fops, drv_cb, ret) \
10740 : : { \
10741 : : struct rte_flow_attr attr = { .transfer = 0 }; \
10742 : : enum mlx5_flow_drv_type drv_type = flow_get_drv_type((dev), &attr); \
10743 : : if (drv_type == MLX5_FLOW_TYPE_MIN || \
10744 : : drv_type == MLX5_FLOW_TYPE_MAX) { \
10745 : : rte_flow_error_set(error, ENOTSUP, \
10746 : : RTE_FLOW_ERROR_TYPE_ACTION, \
10747 : : NULL, "invalid driver type"); \
10748 : : return ret; \
10749 : : } \
10750 : : (fops) = flow_get_drv_ops(drv_type); \
10751 : : if (!(fops) || !(fops)->drv_cb) { \
10752 : : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, \
10753 : : NULL, "no action_list handler"); \
10754 : : return ret; \
10755 : : } \
10756 : : }
10757 : :
10758 : : static struct rte_flow_action_list_handle *
10759 [ # # ]: 0 : mlx5_action_list_handle_create(struct rte_eth_dev *dev,
10760 : : const struct rte_flow_indir_action_conf *conf,
10761 : : const struct rte_flow_action *actions,
10762 : : struct rte_flow_error *error)
10763 : : {
10764 : : const struct mlx5_flow_driver_ops *fops;
10765 : :
10766 [ # # # # ]: 0 : MLX5_DRV_FOPS_OR_ERR(dev, fops, action_list_handle_create, NULL);
10767 : 0 : return fops->action_list_handle_create(dev, conf, actions, error);
10768 : : }
10769 : :
10770 : : static int
10771 [ # # ]: 0 : mlx5_action_list_handle_destroy(struct rte_eth_dev *dev,
10772 : : struct rte_flow_action_list_handle *handle,
10773 : : struct rte_flow_error *error)
10774 : : {
10775 : : const struct mlx5_flow_driver_ops *fops;
10776 : :
10777 [ # # # # ]: 0 : MLX5_DRV_FOPS_OR_ERR(dev, fops, action_list_handle_destroy, ENOTSUP);
10778 : 0 : return fops->action_list_handle_destroy(dev, handle, error);
10779 : : }
10780 : :
10781 : : static int
10782 [ # # ]: 0 : mlx5_flow_action_list_handle_query_update(struct rte_eth_dev *dev,
10783 : : const
10784 : : struct rte_flow_action_list_handle *handle,
10785 : : const void **update, void **query,
10786 : : enum rte_flow_query_update_mode mode,
10787 : : struct rte_flow_error *error)
10788 : : {
10789 : : const struct mlx5_flow_driver_ops *fops;
10790 : :
10791 [ # # # # ]: 0 : MLX5_DRV_FOPS_OR_ERR(dev, fops,
10792 : : action_list_handle_query_update, ENOTSUP);
10793 : 0 : return fops->action_list_handle_query_update(dev, handle, update, query,
10794 : : mode, error);
10795 : : }
10796 : : static int
10797 [ # # ]: 0 : mlx5_flow_calc_table_hash(struct rte_eth_dev *dev,
10798 : : const struct rte_flow_template_table *table,
10799 : : const struct rte_flow_item pattern[],
10800 : : uint8_t pattern_template_index,
10801 : : uint32_t *hash, struct rte_flow_error *error)
10802 : : {
10803 : : struct rte_flow_attr attr = { .transfer = 0 };
10804 : : enum mlx5_flow_drv_type drv_type = flow_get_drv_type(dev, &attr);
10805 : : const struct mlx5_flow_driver_ops *fops;
10806 : :
10807 : : if (drv_type == MLX5_FLOW_TYPE_MIN || drv_type == MLX5_FLOW_TYPE_MAX)
10808 : : return rte_flow_error_set(error, ENOTSUP,
10809 : : RTE_FLOW_ERROR_TYPE_ACTION,
10810 : : NULL, "invalid driver type");
10811 : 0 : fops = flow_get_drv_ops(drv_type);
10812 [ # # # # ]: 0 : if (!fops || !fops->action_query_update)
10813 : 0 : return rte_flow_error_set(error, ENOTSUP,
10814 : : RTE_FLOW_ERROR_TYPE_ACTION,
10815 : : NULL, "no query_update handler");
10816 : 0 : return fops->flow_calc_table_hash(dev, table, pattern, pattern_template_index,
10817 : : hash, error);
10818 : : }
10819 : :
10820 : : static int
10821 [ # # ]: 0 : mlx5_flow_calc_encap_hash(struct rte_eth_dev *dev,
10822 : : const struct rte_flow_item pattern[],
10823 : : enum rte_flow_encap_hash_field dest_field,
10824 : : uint8_t *hash,
10825 : : struct rte_flow_error *error)
10826 : : {
10827 : : enum mlx5_flow_drv_type drv_type = flow_get_drv_type(dev, NULL);
10828 : : const struct mlx5_flow_driver_ops *fops;
10829 : :
10830 : : if (drv_type == MLX5_FLOW_TYPE_MIN || drv_type == MLX5_FLOW_TYPE_MAX)
10831 : 0 : return rte_flow_error_set(error, ENOTSUP,
10832 : : RTE_FLOW_ERROR_TYPE_ACTION,
10833 : : NULL, "invalid driver type");
10834 : 0 : fops = flow_get_drv_ops(drv_type);
10835 [ # # # # ]: 0 : if (!fops || !fops->flow_calc_encap_hash)
10836 : 0 : return rte_flow_error_set(error, ENOTSUP,
10837 : : RTE_FLOW_ERROR_TYPE_ACTION,
10838 : : NULL, "no calc encap hash handler");
10839 : 0 : return fops->flow_calc_encap_hash(dev, pattern, dest_field, hash, error);
10840 : : }
10841 : :
10842 : : static int
10843 [ # # ]: 0 : mlx5_template_table_resize(struct rte_eth_dev *dev,
10844 : : struct rte_flow_template_table *table,
10845 : : uint32_t nb_rules, struct rte_flow_error *error)
10846 : : {
10847 : : const struct mlx5_flow_driver_ops *fops;
10848 : :
10849 [ # # # # ]: 0 : MLX5_DRV_FOPS_OR_ERR(dev, fops, table_resize, ENOTSUP);
10850 : 0 : return fops->table_resize(dev, table, nb_rules, error);
10851 : : }
10852 : :
10853 : : static int
10854 [ # # ]: 0 : mlx5_table_resize_complete(struct rte_eth_dev *dev,
10855 : : struct rte_flow_template_table *table,
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, table_resize_complete, ENOTSUP);
10861 : 0 : return fops->table_resize_complete(dev, table, error);
10862 : : }
10863 : :
10864 : : static int
10865 [ # # ]: 0 : mlx5_flow_async_update_resized(struct rte_eth_dev *dev, uint32_t queue,
10866 : : const struct rte_flow_op_attr *op_attr,
10867 : : struct rte_flow *rule, void *user_data,
10868 : : struct rte_flow_error *error)
10869 : : {
10870 : : const struct mlx5_flow_driver_ops *fops;
10871 : :
10872 [ # # # # ]: 0 : MLX5_DRV_FOPS_OR_ERR(dev, fops, flow_update_resized, ENOTSUP);
10873 : 0 : return fops->flow_update_resized(dev, queue, op_attr, rule, user_data, error);
10874 : : }
10875 : :
10876 : : /**
10877 : : * Destroy all indirect actions (shared RSS).
10878 : : *
10879 : : * @param dev
10880 : : * Pointer to Ethernet device.
10881 : : *
10882 : : * @return
10883 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
10884 : : */
10885 : : int
10886 : 0 : mlx5_action_handle_flush(struct rte_eth_dev *dev)
10887 : : {
10888 : : struct rte_flow_error error;
10889 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10890 : : struct mlx5_shared_action_rss *shared_rss;
10891 : : int ret = 0;
10892 : : uint32_t idx;
10893 : :
10894 [ # # # # ]: 0 : ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
10895 : : priv->rss_shared_actions, idx, shared_rss, next) {
10896 [ # # ]: 0 : ret |= mlx5_action_handle_destroy(dev,
10897 : 0 : (struct rte_flow_action_handle *)(uintptr_t)idx, &error);
10898 : : }
10899 : 0 : return ret;
10900 : : }
10901 : :
10902 : : /**
10903 : : * Validate existing indirect actions against current device configuration
10904 : : * and attach them to device resources.
10905 : : *
10906 : : * @param dev
10907 : : * Pointer to Ethernet device.
10908 : : *
10909 : : * @return
10910 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
10911 : : */
10912 : : int
10913 : 0 : mlx5_action_handle_attach(struct rte_eth_dev *dev)
10914 : : {
10915 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10916 : : int ret = 0;
10917 : : struct mlx5_ind_table_obj *ind_tbl, *ind_tbl_last;
10918 : :
10919 [ # # ]: 0 : LIST_FOREACH(ind_tbl, &priv->standalone_ind_tbls, next) {
10920 : : const char *message;
10921 : : uint32_t queue_idx;
10922 : :
10923 : 0 : ret = mlx5_validate_rss_queues(dev, ind_tbl->queues,
10924 : : ind_tbl->queues_n,
10925 : : &message, &queue_idx);
10926 [ # # ]: 0 : if (ret != 0) {
10927 : 0 : DRV_LOG(ERR, "Port %u cannot use queue %u in RSS: %s",
10928 : : dev->data->port_id, ind_tbl->queues[queue_idx],
10929 : : message);
10930 : 0 : break;
10931 : : }
10932 : : }
10933 [ # # ]: 0 : if (ret != 0)
10934 : : return ret;
10935 [ # # ]: 0 : LIST_FOREACH(ind_tbl, &priv->standalone_ind_tbls, next) {
10936 : 0 : ret = mlx5_ind_table_obj_attach(dev, ind_tbl);
10937 [ # # ]: 0 : if (ret != 0) {
10938 : 0 : DRV_LOG(ERR, "Port %u could not attach "
10939 : : "indirection table obj %p",
10940 : : dev->data->port_id, (void *)ind_tbl);
10941 : 0 : goto error;
10942 : : }
10943 : : }
10944 : :
10945 : : return 0;
10946 : : error:
10947 : : ind_tbl_last = ind_tbl;
10948 [ # # ]: 0 : LIST_FOREACH(ind_tbl, &priv->standalone_ind_tbls, next) {
10949 [ # # ]: 0 : if (ind_tbl == ind_tbl_last)
10950 : : break;
10951 [ # # ]: 0 : if (mlx5_ind_table_obj_detach(dev, ind_tbl) != 0)
10952 : 0 : DRV_LOG(CRIT, "Port %u could not detach "
10953 : : "indirection table obj %p on rollback",
10954 : : dev->data->port_id, (void *)ind_tbl);
10955 : : }
10956 : : return ret;
10957 : : }
10958 : :
10959 : : /**
10960 : : * Detach indirect actions of the device from its resources.
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_detach(struct rte_eth_dev *dev)
10970 : : {
10971 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10972 : : int ret = 0;
10973 : : struct mlx5_ind_table_obj *ind_tbl, *ind_tbl_last;
10974 : :
10975 [ # # ]: 0 : LIST_FOREACH(ind_tbl, &priv->standalone_ind_tbls, next) {
10976 : 0 : ret = mlx5_ind_table_obj_detach(dev, ind_tbl);
10977 [ # # ]: 0 : if (ret != 0) {
10978 : 0 : DRV_LOG(ERR, "Port %u could not detach "
10979 : : "indirection table obj %p",
10980 : : dev->data->port_id, (void *)ind_tbl);
10981 : 0 : goto error;
10982 : : }
10983 : : }
10984 : : return 0;
10985 : : error:
10986 : : ind_tbl_last = ind_tbl;
10987 [ # # ]: 0 : LIST_FOREACH(ind_tbl, &priv->standalone_ind_tbls, next) {
10988 [ # # ]: 0 : if (ind_tbl == ind_tbl_last)
10989 : : break;
10990 [ # # ]: 0 : if (mlx5_ind_table_obj_attach(dev, ind_tbl) != 0)
10991 : 0 : DRV_LOG(CRIT, "Port %u could not attach "
10992 : : "indirection table obj %p on rollback",
10993 : : dev->data->port_id, (void *)ind_tbl);
10994 : : }
10995 : : return ret;
10996 : : }
10997 : :
10998 : : #ifndef HAVE_MLX5DV_DR
10999 : : #define MLX5_DOMAIN_SYNC_FLOW ((1 << 0) | (1 << 1))
11000 : : #else
11001 : : #define MLX5_DOMAIN_SYNC_FLOW \
11002 : : (MLX5DV_DR_DOMAIN_SYNC_FLAGS_SW | MLX5DV_DR_DOMAIN_SYNC_FLAGS_HW)
11003 : : #endif
11004 : :
11005 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_mlx5_sync_flow, 20.11)
11006 : 0 : int rte_pmd_mlx5_sync_flow(uint16_t port_id, uint32_t domains)
11007 : : {
11008 [ # # ]: 0 : struct rte_eth_dev *dev = &rte_eth_devices[port_id];
11009 : : const struct mlx5_flow_driver_ops *fops;
11010 : : int ret;
11011 : : struct rte_flow_attr attr = { .transfer = 0 };
11012 : :
11013 : 0 : fops = flow_get_drv_ops(flow_get_drv_type(dev, &attr));
11014 : 0 : ret = fops->sync_domain(dev, domains, MLX5_DOMAIN_SYNC_FLOW);
11015 [ # # ]: 0 : if (ret > 0)
11016 : 0 : ret = -ret;
11017 : 0 : return ret;
11018 : : }
11019 : :
11020 : : const struct mlx5_flow_tunnel *
11021 : 0 : mlx5_get_tof(const struct rte_flow_item *item,
11022 : : const struct rte_flow_action *action,
11023 : : enum mlx5_tof_rule_type *rule_type)
11024 : : {
11025 [ # # ]: 0 : for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
11026 [ # # ]: 0 : if (item->type == (typeof(item->type))
11027 : : MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL) {
11028 : 0 : *rule_type = MLX5_TUNNEL_OFFLOAD_MATCH_RULE;
11029 : 0 : return flow_items_to_tunnel(item);
11030 : : }
11031 : : }
11032 [ # # ]: 0 : for (; action->conf != RTE_FLOW_ACTION_TYPE_END; action++) {
11033 [ # # ]: 0 : if (action->type == (typeof(action->type))
11034 : : MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET) {
11035 : 0 : *rule_type = MLX5_TUNNEL_OFFLOAD_SET_RULE;
11036 : 0 : return flow_actions_to_tunnel(action);
11037 : : }
11038 : : }
11039 : : return NULL;
11040 : : }
11041 : :
11042 : : /**
11043 : : * tunnel offload functionality is defined for DV environment only
11044 : : */
11045 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
11046 : : __extension__
11047 : : union tunnel_offload_mark {
11048 : : uint32_t val;
11049 : : struct {
11050 : : uint32_t app_reserve:8;
11051 : : uint32_t table_id:15;
11052 : : uint32_t transfer:1;
11053 : : uint32_t _unused_:8;
11054 : : };
11055 : : };
11056 : :
11057 : : static bool
11058 : : mlx5_access_tunnel_offload_db
11059 : : (struct rte_eth_dev *dev,
11060 : : bool (*match)(struct rte_eth_dev *,
11061 : : struct mlx5_flow_tunnel *, const void *),
11062 : : void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
11063 : : void (*miss)(struct rte_eth_dev *, void *),
11064 : : void *ctx, bool lock_op);
11065 : :
11066 : : static int
11067 : 0 : flow_tunnel_add_default_miss(struct rte_eth_dev *dev,
11068 : : struct rte_flow *flow,
11069 : : const struct rte_flow_attr *attr,
11070 : : const struct rte_flow_action *app_actions,
11071 : : uint32_t flow_idx,
11072 : : const struct mlx5_flow_tunnel *tunnel,
11073 : : struct tunnel_default_miss_ctx *ctx,
11074 : : struct rte_flow_error *error)
11075 : : {
11076 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11077 : : struct mlx5_flow *dev_flow;
11078 : 0 : struct rte_flow_attr miss_attr = *attr;
11079 : 0 : const struct rte_flow_item miss_items[2] = {
11080 : : {
11081 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
11082 : : .spec = NULL,
11083 : : .last = NULL,
11084 : : .mask = NULL
11085 : : },
11086 : : {
11087 : : .type = RTE_FLOW_ITEM_TYPE_END,
11088 : : .spec = NULL,
11089 : : .last = NULL,
11090 : : .mask = NULL
11091 : : }
11092 : : };
11093 : : union tunnel_offload_mark mark_id;
11094 : : struct rte_flow_action_mark miss_mark;
11095 : 0 : struct rte_flow_action miss_actions[3] = {
11096 : : [0] = { .type = RTE_FLOW_ACTION_TYPE_MARK, .conf = &miss_mark },
11097 : : [2] = { .type = RTE_FLOW_ACTION_TYPE_END, .conf = NULL }
11098 : : };
11099 : : const struct rte_flow_action_jump *jump_data;
11100 : 0 : uint32_t i, flow_table = 0; /* prevent compilation warning */
11101 : 0 : struct flow_grp_info grp_info = {
11102 : : .external = 1,
11103 : 0 : .transfer = attr->transfer,
11104 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
11105 : : .std_tbl_fix = 0,
11106 : : };
11107 : : int ret;
11108 : :
11109 [ # # ]: 0 : if (!attr->transfer) {
11110 : : uint32_t q_size;
11111 : :
11112 : 0 : miss_actions[1].type = RTE_FLOW_ACTION_TYPE_RSS;
11113 : 0 : q_size = priv->reta_idx_n * sizeof(ctx->queue[0]);
11114 : 0 : ctx->queue = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, q_size,
11115 : : 0, SOCKET_ID_ANY);
11116 [ # # ]: 0 : if (!ctx->queue)
11117 : 0 : return rte_flow_error_set
11118 : : (error, ENOMEM,
11119 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
11120 : : NULL, "invalid default miss RSS");
11121 : 0 : ctx->action_rss.func = RTE_ETH_HASH_FUNCTION_DEFAULT,
11122 : 0 : ctx->action_rss.level = 0,
11123 : 0 : ctx->action_rss.types = priv->rss_conf.rss_hf,
11124 : 0 : ctx->action_rss.key_len = priv->rss_conf.rss_key_len,
11125 : 0 : ctx->action_rss.queue_num = priv->reta_idx_n,
11126 : 0 : ctx->action_rss.key = priv->rss_conf.rss_key,
11127 : 0 : ctx->action_rss.queue = ctx->queue;
11128 [ # # # # ]: 0 : if (!priv->reta_idx_n || !priv->rxqs_n)
11129 : 0 : return rte_flow_error_set
11130 : : (error, EINVAL,
11131 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
11132 : : NULL, "invalid port configuration");
11133 [ # # ]: 0 : if (!(dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG))
11134 : 0 : ctx->action_rss.types = 0;
11135 [ # # ]: 0 : for (i = 0; i != priv->reta_idx_n; ++i)
11136 : 0 : ctx->queue[i] = (*priv->reta_idx)[i];
11137 : : } else {
11138 : 0 : miss_actions[1].type = RTE_FLOW_ACTION_TYPE_JUMP;
11139 : 0 : ctx->miss_jump.group = MLX5_TNL_MISS_FDB_JUMP_GRP;
11140 : : }
11141 : 0 : miss_actions[1].conf = (typeof(miss_actions[1].conf))ctx->raw;
11142 [ # # ]: 0 : for (; app_actions->type != RTE_FLOW_ACTION_TYPE_JUMP; app_actions++);
11143 : 0 : jump_data = app_actions->conf;
11144 : 0 : miss_attr.priority = MLX5_TNL_MISS_RULE_PRIORITY;
11145 : 0 : miss_attr.group = jump_data->group;
11146 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel, jump_data->group,
11147 : : &flow_table, &grp_info, error);
11148 [ # # ]: 0 : if (ret)
11149 : 0 : return rte_flow_error_set(error, EINVAL,
11150 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
11151 : : NULL, "invalid tunnel id");
11152 : 0 : mark_id.app_reserve = 0;
11153 : 0 : mark_id.table_id = tunnel_flow_tbl_to_id(flow_table);
11154 : 0 : mark_id.transfer = !!attr->transfer;
11155 : 0 : mark_id._unused_ = 0;
11156 : 0 : miss_mark.id = mark_id.val;
11157 : : dev_flow = flow_drv_prepare(dev, flow, &miss_attr,
11158 : : miss_items, miss_actions, flow_idx, error);
11159 [ # # ]: 0 : if (!dev_flow)
11160 : 0 : return -rte_errno;
11161 : 0 : dev_flow->flow = flow;
11162 : 0 : dev_flow->external = true;
11163 : 0 : dev_flow->tunnel = tunnel;
11164 : 0 : dev_flow->tof_type = MLX5_TUNNEL_OFFLOAD_MISS_RULE;
11165 : : /* Subflow object was created, we must include one in the list. */
11166 : 0 : SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
11167 : : dev_flow->handle, next);
11168 : 0 : DRV_LOG(DEBUG,
11169 : : "port %u tunnel type=%d id=%u miss rule priority=%u group=%u",
11170 : : dev->data->port_id, tunnel->app_tunnel.type,
11171 : : tunnel->tunnel_id, miss_attr.priority, miss_attr.group);
11172 : : ret = flow_drv_translate(dev, dev_flow, &miss_attr, miss_items,
11173 : : miss_actions, error);
11174 [ # # ]: 0 : if (!ret)
11175 : 0 : ret = flow_mreg_update_copy_table(dev, flow, miss_actions,
11176 : : error);
11177 : :
11178 : : return ret;
11179 : : }
11180 : :
11181 : : static const struct mlx5_flow_tbl_data_entry *
11182 : 0 : tunnel_mark_decode(struct rte_eth_dev *dev, uint32_t mark)
11183 : : {
11184 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11185 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
11186 : : struct mlx5_list_entry *he;
11187 : 0 : union tunnel_offload_mark mbits = { .val = mark };
11188 : 0 : union mlx5_flow_tbl_key table_key = {
11189 : : {
11190 : 0 : .level = tunnel_id_to_flow_tbl(mbits.table_id),
11191 : : .id = 0,
11192 : : .reserved = 0,
11193 : : .dummy = 0,
11194 : 0 : .is_fdb = !!mbits.transfer,
11195 : : .is_egress = 0,
11196 : : }
11197 : : };
11198 : 0 : struct mlx5_flow_cb_ctx ctx = {
11199 : : .data = &table_key.v64,
11200 : : };
11201 : :
11202 : 0 : he = mlx5_hlist_lookup(sh->flow_tbls, table_key.v64, &ctx);
11203 : : return he ?
11204 [ # # ]: 0 : container_of(he, struct mlx5_flow_tbl_data_entry, entry) : NULL;
11205 : : }
11206 : :
11207 : : static void
11208 : 0 : mlx5_flow_tunnel_grp2tbl_remove_cb(void *tool_ctx,
11209 : : struct mlx5_list_entry *entry)
11210 : : {
11211 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11212 : : struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
11213 : :
11214 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
11215 : : tunnel_flow_tbl_to_id(tte->flow_table));
11216 : 0 : mlx5_free(tte);
11217 : 0 : }
11218 : :
11219 : : static int
11220 : 0 : mlx5_flow_tunnel_grp2tbl_match_cb(void *tool_ctx __rte_unused,
11221 : : struct mlx5_list_entry *entry, void *cb_ctx)
11222 : : {
11223 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11224 : : union tunnel_tbl_key tbl = {
11225 : 0 : .val = *(uint64_t *)(ctx->data),
11226 : : };
11227 : : struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
11228 : :
11229 [ # # # # ]: 0 : return tbl.tunnel_id != tte->tunnel_id || tbl.group != tte->group;
11230 : : }
11231 : :
11232 : : static struct mlx5_list_entry *
11233 : 0 : mlx5_flow_tunnel_grp2tbl_create_cb(void *tool_ctx, void *cb_ctx)
11234 : : {
11235 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11236 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11237 : : struct tunnel_tbl_entry *tte;
11238 : : union tunnel_tbl_key tbl = {
11239 : 0 : .val = *(uint64_t *)(ctx->data),
11240 : : };
11241 : :
11242 : 0 : tte = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO,
11243 : : sizeof(*tte), 0,
11244 : : SOCKET_ID_ANY);
11245 [ # # ]: 0 : if (!tte)
11246 : 0 : goto err;
11247 : 0 : mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
11248 : : &tte->flow_table);
11249 [ # # ]: 0 : if (tte->flow_table >= MLX5_MAX_TABLES) {
11250 : 0 : DRV_LOG(ERR, "Tunnel TBL ID %d exceed max limit.",
11251 : : tte->flow_table);
11252 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
11253 : : tte->flow_table);
11254 : 0 : goto err;
11255 [ # # ]: 0 : } else if (!tte->flow_table) {
11256 : 0 : goto err;
11257 : : }
11258 : 0 : tte->flow_table = tunnel_id_to_flow_tbl(tte->flow_table);
11259 : 0 : tte->tunnel_id = tbl.tunnel_id;
11260 : 0 : tte->group = tbl.group;
11261 : 0 : return &tte->hash;
11262 : 0 : err:
11263 [ # # ]: 0 : if (tte)
11264 : 0 : mlx5_free(tte);
11265 : : return NULL;
11266 : : }
11267 : :
11268 : : static struct mlx5_list_entry *
11269 : 0 : mlx5_flow_tunnel_grp2tbl_clone_cb(void *tool_ctx __rte_unused,
11270 : : struct mlx5_list_entry *oentry,
11271 : : void *cb_ctx __rte_unused)
11272 : : {
11273 : 0 : struct tunnel_tbl_entry *tte = mlx5_malloc(MLX5_MEM_SYS, sizeof(*tte),
11274 : : 0, SOCKET_ID_ANY);
11275 : :
11276 [ # # ]: 0 : if (!tte)
11277 : : return NULL;
11278 : : memcpy(tte, oentry, sizeof(*tte));
11279 : 0 : return &tte->hash;
11280 : : }
11281 : :
11282 : : static void
11283 : 0 : mlx5_flow_tunnel_grp2tbl_clone_free_cb(void *tool_ctx __rte_unused,
11284 : : struct mlx5_list_entry *entry)
11285 : : {
11286 : : struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
11287 : :
11288 : 0 : mlx5_free(tte);
11289 : 0 : }
11290 : :
11291 : : static uint32_t
11292 : 0 : tunnel_flow_group_to_flow_table(struct rte_eth_dev *dev,
11293 : : const struct mlx5_flow_tunnel *tunnel,
11294 : : uint32_t group, uint32_t *table,
11295 : : struct rte_flow_error *error)
11296 : : {
11297 : : struct mlx5_list_entry *he;
11298 : : struct tunnel_tbl_entry *tte;
11299 [ # # ]: 0 : union tunnel_tbl_key key = {
11300 [ # # ]: 0 : .tunnel_id = tunnel ? tunnel->tunnel_id : 0,
11301 : : .group = group
11302 : : };
11303 : : struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
11304 : : struct mlx5_hlist *group_hash;
11305 : 0 : struct mlx5_flow_cb_ctx ctx = {
11306 : : .data = &key.val,
11307 : : };
11308 : :
11309 [ # # ]: 0 : group_hash = tunnel ? tunnel->groups : thub->groups;
11310 : 0 : he = mlx5_hlist_register(group_hash, key.val, &ctx);
11311 [ # # ]: 0 : if (!he)
11312 : 0 : return rte_flow_error_set(error, EINVAL,
11313 : : RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
11314 : : NULL,
11315 : : "tunnel group index not supported");
11316 : : tte = container_of(he, typeof(*tte), hash);
11317 : 0 : *table = tte->flow_table;
11318 : 0 : DRV_LOG(DEBUG, "port %u tunnel %u group=%#x table=%#x",
11319 : : dev->data->port_id, key.tunnel_id, group, *table);
11320 : 0 : return 0;
11321 : : }
11322 : :
11323 : : static void
11324 : 0 : mlx5_flow_tunnel_free(struct rte_eth_dev *dev,
11325 : : struct mlx5_flow_tunnel *tunnel)
11326 : : {
11327 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11328 : : struct mlx5_indexed_pool *ipool;
11329 : :
11330 : 0 : DRV_LOG(DEBUG, "port %u release pmd tunnel id=0x%x",
11331 : : dev->data->port_id, tunnel->tunnel_id);
11332 [ # # ]: 0 : LIST_REMOVE(tunnel, chain);
11333 : 0 : mlx5_hlist_destroy(tunnel->groups);
11334 : 0 : ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
11335 : 0 : mlx5_ipool_free(ipool, tunnel->tunnel_id);
11336 : 0 : }
11337 : :
11338 : : static bool
11339 : 0 : mlx5_access_tunnel_offload_db
11340 : : (struct rte_eth_dev *dev,
11341 : : bool (*match)(struct rte_eth_dev *,
11342 : : struct mlx5_flow_tunnel *, const void *),
11343 : : void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
11344 : : void (*miss)(struct rte_eth_dev *, void *),
11345 : : void *ctx, bool lock_op)
11346 : : {
11347 : : bool verdict = false;
11348 : : struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
11349 : : struct mlx5_flow_tunnel *tunnel;
11350 : :
11351 : 0 : rte_spinlock_lock(&thub->sl);
11352 [ # # ]: 0 : LIST_FOREACH(tunnel, &thub->tunnels, chain) {
11353 : 0 : verdict = match(dev, tunnel, (const void *)ctx);
11354 [ # # ]: 0 : if (verdict)
11355 : : break;
11356 : : }
11357 [ # # ]: 0 : if (!lock_op)
11358 : : rte_spinlock_unlock(&thub->sl);
11359 [ # # ]: 0 : if (verdict && hit)
11360 : 0 : hit(dev, tunnel, ctx);
11361 [ # # ]: 0 : if (!verdict && miss)
11362 : 0 : miss(dev, ctx);
11363 [ # # ]: 0 : if (lock_op)
11364 : : rte_spinlock_unlock(&thub->sl);
11365 : :
11366 : 0 : return verdict;
11367 : : }
11368 : :
11369 : : struct tunnel_db_find_tunnel_id_ctx {
11370 : : uint32_t tunnel_id;
11371 : : struct mlx5_flow_tunnel *tunnel;
11372 : : };
11373 : :
11374 : : static bool
11375 : 0 : find_tunnel_id_match(struct rte_eth_dev *dev,
11376 : : struct mlx5_flow_tunnel *tunnel, const void *x)
11377 : : {
11378 : : const struct tunnel_db_find_tunnel_id_ctx *ctx = x;
11379 : :
11380 : : RTE_SET_USED(dev);
11381 : 0 : return tunnel->tunnel_id == ctx->tunnel_id;
11382 : : }
11383 : :
11384 : : static void
11385 : 0 : find_tunnel_id_hit(struct rte_eth_dev *dev,
11386 : : struct mlx5_flow_tunnel *tunnel, void *x)
11387 : : {
11388 : : struct tunnel_db_find_tunnel_id_ctx *ctx = x;
11389 : : RTE_SET_USED(dev);
11390 : 0 : ctx->tunnel = tunnel;
11391 : 0 : }
11392 : :
11393 : : static struct mlx5_flow_tunnel *
11394 : : mlx5_find_tunnel_id(struct rte_eth_dev *dev, uint32_t id)
11395 : : {
11396 : 0 : struct tunnel_db_find_tunnel_id_ctx ctx = {
11397 : : .tunnel_id = id,
11398 : : };
11399 : :
11400 : 0 : mlx5_access_tunnel_offload_db(dev, find_tunnel_id_match,
11401 : : find_tunnel_id_hit, NULL, &ctx, true);
11402 : :
11403 [ # # ]: 0 : return ctx.tunnel;
11404 : : }
11405 : :
11406 : : static struct mlx5_flow_tunnel *
11407 : 0 : mlx5_flow_tunnel_allocate(struct rte_eth_dev *dev,
11408 : : const struct rte_flow_tunnel *app_tunnel)
11409 : : {
11410 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11411 : : struct mlx5_indexed_pool *ipool;
11412 : : struct mlx5_flow_tunnel *tunnel;
11413 : : uint32_t id;
11414 : :
11415 : 0 : ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
11416 : 0 : tunnel = mlx5_ipool_zmalloc(ipool, &id);
11417 [ # # ]: 0 : if (!tunnel)
11418 : : return NULL;
11419 [ # # ]: 0 : if (id >= MLX5_MAX_TUNNELS) {
11420 : 0 : mlx5_ipool_free(ipool, id);
11421 : 0 : DRV_LOG(ERR, "Tunnel ID %d exceed max limit.", id);
11422 : 0 : return NULL;
11423 : : }
11424 : 0 : tunnel->groups = mlx5_hlist_create("tunnel groups", 64, false, true,
11425 : 0 : priv->sh,
11426 : : mlx5_flow_tunnel_grp2tbl_create_cb,
11427 : : mlx5_flow_tunnel_grp2tbl_match_cb,
11428 : : mlx5_flow_tunnel_grp2tbl_remove_cb,
11429 : : mlx5_flow_tunnel_grp2tbl_clone_cb,
11430 : : mlx5_flow_tunnel_grp2tbl_clone_free_cb);
11431 [ # # ]: 0 : if (!tunnel->groups) {
11432 : 0 : mlx5_ipool_free(ipool, id);
11433 : 0 : return NULL;
11434 : : }
11435 : : /* initiate new PMD tunnel */
11436 : 0 : memcpy(&tunnel->app_tunnel, app_tunnel, sizeof(*app_tunnel));
11437 : 0 : tunnel->tunnel_id = id;
11438 : 0 : tunnel->action.type = (typeof(tunnel->action.type))
11439 : : MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET;
11440 : 0 : tunnel->action.conf = tunnel;
11441 : 0 : tunnel->item.type = (typeof(tunnel->item.type))
11442 : : MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL;
11443 : 0 : tunnel->item.spec = tunnel;
11444 : 0 : tunnel->item.last = NULL;
11445 : 0 : tunnel->item.mask = NULL;
11446 : :
11447 : 0 : DRV_LOG(DEBUG, "port %u new pmd tunnel id=0x%x",
11448 : : dev->data->port_id, tunnel->tunnel_id);
11449 : :
11450 : 0 : return tunnel;
11451 : : }
11452 : :
11453 : : struct tunnel_db_get_tunnel_ctx {
11454 : : const struct rte_flow_tunnel *app_tunnel;
11455 : : struct mlx5_flow_tunnel *tunnel;
11456 : : };
11457 : :
11458 : 0 : static bool get_tunnel_match(struct rte_eth_dev *dev,
11459 : : struct mlx5_flow_tunnel *tunnel, const void *x)
11460 : : {
11461 : : const struct tunnel_db_get_tunnel_ctx *ctx = x;
11462 : :
11463 : : RTE_SET_USED(dev);
11464 : 0 : return !memcmp(ctx->app_tunnel, &tunnel->app_tunnel,
11465 : : sizeof(*ctx->app_tunnel));
11466 : : }
11467 : :
11468 : 0 : static void get_tunnel_hit(struct rte_eth_dev *dev,
11469 : : struct mlx5_flow_tunnel *tunnel, void *x)
11470 : : {
11471 : : /* called under tunnel spinlock protection */
11472 : : struct tunnel_db_get_tunnel_ctx *ctx = x;
11473 : :
11474 : : RTE_SET_USED(dev);
11475 : 0 : tunnel->refctn++;
11476 : 0 : ctx->tunnel = tunnel;
11477 : 0 : }
11478 : :
11479 : 0 : static void get_tunnel_miss(struct rte_eth_dev *dev, void *x)
11480 : : {
11481 : : /* called under tunnel spinlock protection */
11482 : : struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
11483 : : struct tunnel_db_get_tunnel_ctx *ctx = x;
11484 : :
11485 : 0 : rte_spinlock_unlock(&thub->sl);
11486 : 0 : ctx->tunnel = mlx5_flow_tunnel_allocate(dev, ctx->app_tunnel);
11487 : : rte_spinlock_lock(&thub->sl);
11488 [ # # ]: 0 : if (ctx->tunnel) {
11489 : 0 : ctx->tunnel->refctn = 1;
11490 [ # # ]: 0 : LIST_INSERT_HEAD(&thub->tunnels, ctx->tunnel, chain);
11491 : : }
11492 : 0 : }
11493 : :
11494 : :
11495 : : static int
11496 : 0 : mlx5_get_flow_tunnel(struct rte_eth_dev *dev,
11497 : : const struct rte_flow_tunnel *app_tunnel,
11498 : : struct mlx5_flow_tunnel **tunnel)
11499 : : {
11500 : 0 : struct tunnel_db_get_tunnel_ctx ctx = {
11501 : : .app_tunnel = app_tunnel,
11502 : : };
11503 : :
11504 : 0 : mlx5_access_tunnel_offload_db(dev, get_tunnel_match, get_tunnel_hit,
11505 : : get_tunnel_miss, &ctx, true);
11506 : 0 : *tunnel = ctx.tunnel;
11507 [ # # ]: 0 : return ctx.tunnel ? 0 : -ENOMEM;
11508 : : }
11509 : :
11510 : 0 : void mlx5_release_tunnel_hub(struct mlx5_dev_ctx_shared *sh, uint16_t port_id)
11511 : : {
11512 : 0 : struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
11513 : :
11514 [ # # ]: 0 : if (!thub)
11515 : : return;
11516 [ # # ]: 0 : if (!LIST_EMPTY(&thub->tunnels))
11517 : 0 : DRV_LOG(WARNING, "port %u tunnels present", port_id);
11518 : 0 : mlx5_hlist_destroy(thub->groups);
11519 : 0 : mlx5_free(thub);
11520 : : }
11521 : :
11522 : 0 : int mlx5_alloc_tunnel_hub(struct mlx5_dev_ctx_shared *sh)
11523 : : {
11524 : : int err;
11525 : : struct mlx5_flow_tunnel_hub *thub;
11526 : :
11527 : 0 : thub = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, sizeof(*thub),
11528 : : 0, SOCKET_ID_ANY);
11529 [ # # ]: 0 : if (!thub)
11530 : : return -ENOMEM;
11531 : 0 : LIST_INIT(&thub->tunnels);
11532 : : rte_spinlock_init(&thub->sl);
11533 : 0 : thub->groups = mlx5_hlist_create("flow groups", 64,
11534 : : false, true, sh,
11535 : : mlx5_flow_tunnel_grp2tbl_create_cb,
11536 : : mlx5_flow_tunnel_grp2tbl_match_cb,
11537 : : mlx5_flow_tunnel_grp2tbl_remove_cb,
11538 : : mlx5_flow_tunnel_grp2tbl_clone_cb,
11539 : : mlx5_flow_tunnel_grp2tbl_clone_free_cb);
11540 [ # # ]: 0 : if (!thub->groups) {
11541 : 0 : err = -rte_errno;
11542 : 0 : goto err;
11543 : : }
11544 : 0 : sh->tunnel_hub = thub;
11545 : :
11546 : 0 : return 0;
11547 : :
11548 : : err:
11549 : : if (thub->groups)
11550 : : mlx5_hlist_destroy(thub->groups);
11551 : : if (thub)
11552 : 0 : mlx5_free(thub);
11553 : 0 : return err;
11554 : : }
11555 : :
11556 : : static inline int
11557 : 0 : mlx5_flow_tunnel_validate(struct rte_eth_dev *dev,
11558 : : struct rte_flow_tunnel *tunnel,
11559 : : struct rte_flow_error *error)
11560 : : {
11561 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11562 : :
11563 [ # # ]: 0 : if (!priv->sh->config.dv_flow_en)
11564 : 0 : return rte_flow_error_set(error, ENOTSUP,
11565 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
11566 : : "flow DV interface is off");
11567 [ # # ]: 0 : if (!is_tunnel_offload_active(dev))
11568 : 0 : return rte_flow_error_set(error, ENOTSUP,
11569 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
11570 : : "tunnel offload was not activated, consider setting dv_xmeta_en=3");
11571 [ # # ]: 0 : if (!tunnel)
11572 : 0 : return rte_flow_error_set(error, EINVAL,
11573 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
11574 : : "no application tunnel");
11575 [ # # ]: 0 : switch (tunnel->type) {
11576 : 0 : default:
11577 : 0 : return rte_flow_error_set(error, EINVAL,
11578 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
11579 : : "unsupported tunnel type");
11580 : : case RTE_FLOW_ITEM_TYPE_VXLAN:
11581 : : case RTE_FLOW_ITEM_TYPE_GRE:
11582 : : case RTE_FLOW_ITEM_TYPE_NVGRE:
11583 : : case RTE_FLOW_ITEM_TYPE_GENEVE:
11584 : : break;
11585 : : }
11586 : : return 0;
11587 : : }
11588 : :
11589 : : static int
11590 : 0 : mlx5_flow_tunnel_decap_set(struct rte_eth_dev *dev,
11591 : : struct rte_flow_tunnel *app_tunnel,
11592 : : struct rte_flow_action **actions,
11593 : : uint32_t *num_of_actions,
11594 : : struct rte_flow_error *error)
11595 : : {
11596 : : struct mlx5_flow_tunnel *tunnel;
11597 : 0 : int ret = mlx5_flow_tunnel_validate(dev, app_tunnel, error);
11598 : :
11599 [ # # ]: 0 : if (ret)
11600 : : return ret;
11601 : 0 : ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
11602 [ # # ]: 0 : if (ret < 0) {
11603 : 0 : return rte_flow_error_set(error, ret,
11604 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
11605 : : "failed to initialize pmd tunnel");
11606 : : }
11607 : 0 : *actions = &tunnel->action;
11608 : 0 : *num_of_actions = 1;
11609 : 0 : return 0;
11610 : : }
11611 : :
11612 : : static int
11613 : 0 : mlx5_flow_tunnel_match(struct rte_eth_dev *dev,
11614 : : struct rte_flow_tunnel *app_tunnel,
11615 : : struct rte_flow_item **items,
11616 : : uint32_t *num_of_items,
11617 : : struct rte_flow_error *error)
11618 : : {
11619 : : struct mlx5_flow_tunnel *tunnel;
11620 : 0 : int ret = mlx5_flow_tunnel_validate(dev, app_tunnel, error);
11621 : :
11622 [ # # ]: 0 : if (ret)
11623 : : return ret;
11624 : 0 : ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
11625 [ # # ]: 0 : if (ret < 0) {
11626 : 0 : return rte_flow_error_set(error, ret,
11627 : : RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
11628 : : "failed to initialize pmd tunnel");
11629 : : }
11630 : 0 : *items = &tunnel->item;
11631 : 0 : *num_of_items = 1;
11632 : 0 : return 0;
11633 : : }
11634 : :
11635 : : struct tunnel_db_element_release_ctx {
11636 : : struct rte_flow_item *items;
11637 : : struct rte_flow_action *actions;
11638 : : uint32_t num_elements;
11639 : : struct rte_flow_error *error;
11640 : : int ret;
11641 : : };
11642 : :
11643 : : static bool
11644 : 0 : tunnel_element_release_match(struct rte_eth_dev *dev,
11645 : : struct mlx5_flow_tunnel *tunnel, const void *x)
11646 : : {
11647 : : const struct tunnel_db_element_release_ctx *ctx = x;
11648 : :
11649 : : RTE_SET_USED(dev);
11650 [ # # ]: 0 : if (ctx->num_elements != 1)
11651 : : return false;
11652 [ # # ]: 0 : else if (ctx->items)
11653 : 0 : return ctx->items == &tunnel->item;
11654 [ # # ]: 0 : else if (ctx->actions)
11655 : 0 : return ctx->actions == &tunnel->action;
11656 : :
11657 : : return false;
11658 : : }
11659 : :
11660 : : static void
11661 : 0 : tunnel_element_release_hit(struct rte_eth_dev *dev,
11662 : : struct mlx5_flow_tunnel *tunnel, void *x)
11663 : : {
11664 : : struct tunnel_db_element_release_ctx *ctx = x;
11665 : 0 : ctx->ret = 0;
11666 [ # # ]: 0 : if (!(rte_atomic_fetch_sub_explicit(&tunnel->refctn, 1, rte_memory_order_relaxed) - 1))
11667 : 0 : mlx5_flow_tunnel_free(dev, tunnel);
11668 : 0 : }
11669 : :
11670 : : static void
11671 : 0 : tunnel_element_release_miss(struct rte_eth_dev *dev, void *x)
11672 : : {
11673 : : struct tunnel_db_element_release_ctx *ctx = x;
11674 : : RTE_SET_USED(dev);
11675 : 0 : ctx->ret = rte_flow_error_set(ctx->error, EINVAL,
11676 : : RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
11677 : : "invalid argument");
11678 : 0 : }
11679 : :
11680 : : static int
11681 : 0 : mlx5_flow_tunnel_item_release(struct rte_eth_dev *dev,
11682 : : struct rte_flow_item *pmd_items,
11683 : : uint32_t num_items, struct rte_flow_error *err)
11684 : : {
11685 : 0 : struct tunnel_db_element_release_ctx ctx = {
11686 : : .items = pmd_items,
11687 : : .actions = NULL,
11688 : : .num_elements = num_items,
11689 : : .error = err,
11690 : : };
11691 : :
11692 : 0 : mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
11693 : : tunnel_element_release_hit,
11694 : : tunnel_element_release_miss, &ctx, false);
11695 : :
11696 : 0 : return ctx.ret;
11697 : : }
11698 : :
11699 : : static int
11700 : 0 : mlx5_flow_tunnel_action_release(struct rte_eth_dev *dev,
11701 : : struct rte_flow_action *pmd_actions,
11702 : : uint32_t num_actions, struct rte_flow_error *err)
11703 : : {
11704 : 0 : struct tunnel_db_element_release_ctx ctx = {
11705 : : .items = NULL,
11706 : : .actions = pmd_actions,
11707 : : .num_elements = num_actions,
11708 : : .error = err,
11709 : : };
11710 : :
11711 : 0 : mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
11712 : : tunnel_element_release_hit,
11713 : : tunnel_element_release_miss, &ctx, false);
11714 : :
11715 : 0 : return ctx.ret;
11716 : : }
11717 : :
11718 : : static int
11719 : 0 : mlx5_flow_tunnel_get_restore_info(struct rte_eth_dev *dev,
11720 : : struct rte_mbuf *m,
11721 : : struct rte_flow_restore_info *info,
11722 : : struct rte_flow_error *err)
11723 : : {
11724 : 0 : uint64_t ol_flags = m->ol_flags;
11725 : : const struct mlx5_flow_tbl_data_entry *tble;
11726 : : const uint64_t mask = RTE_MBUF_F_RX_FDIR | RTE_MBUF_F_RX_FDIR_ID;
11727 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11728 : :
11729 [ # # ]: 0 : if (priv->tunnel_enabled == 0)
11730 : 0 : goto err;
11731 [ # # ]: 0 : if ((ol_flags & mask) != mask)
11732 : 0 : goto err;
11733 : 0 : tble = tunnel_mark_decode(dev, m->hash.fdir.hi);
11734 [ # # ]: 0 : if (!tble) {
11735 : 0 : DRV_LOG(DEBUG, "port %u invalid miss tunnel mark %#x",
11736 : : dev->data->port_id, m->hash.fdir.hi);
11737 : 0 : goto err;
11738 : : }
11739 : : MLX5_ASSERT(tble->tunnel);
11740 : 0 : memcpy(&info->tunnel, &tble->tunnel->app_tunnel, sizeof(info->tunnel));
11741 : 0 : info->group_id = tble->group_id;
11742 : 0 : info->flags = RTE_FLOW_RESTORE_INFO_TUNNEL |
11743 : : RTE_FLOW_RESTORE_INFO_GROUP_ID |
11744 : : RTE_FLOW_RESTORE_INFO_ENCAPSULATED;
11745 : :
11746 : 0 : return 0;
11747 : :
11748 : 0 : err:
11749 : 0 : return rte_flow_error_set(err, EINVAL,
11750 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11751 : : "failed to get restore info");
11752 : : }
11753 : :
11754 : : #else /* HAVE_IBV_FLOW_DV_SUPPORT */
11755 : : static int
11756 : : mlx5_flow_tunnel_decap_set(__rte_unused struct rte_eth_dev *dev,
11757 : : __rte_unused struct rte_flow_tunnel *app_tunnel,
11758 : : __rte_unused struct rte_flow_action **actions,
11759 : : __rte_unused uint32_t *num_of_actions,
11760 : : __rte_unused struct rte_flow_error *error)
11761 : : {
11762 : : return -ENOTSUP;
11763 : : }
11764 : :
11765 : : static int
11766 : : mlx5_flow_tunnel_match(__rte_unused struct rte_eth_dev *dev,
11767 : : __rte_unused struct rte_flow_tunnel *app_tunnel,
11768 : : __rte_unused struct rte_flow_item **items,
11769 : : __rte_unused uint32_t *num_of_items,
11770 : : __rte_unused struct rte_flow_error *error)
11771 : : {
11772 : : return -ENOTSUP;
11773 : : }
11774 : :
11775 : : static int
11776 : : mlx5_flow_tunnel_item_release(__rte_unused struct rte_eth_dev *dev,
11777 : : __rte_unused struct rte_flow_item *pmd_items,
11778 : : __rte_unused uint32_t num_items,
11779 : : __rte_unused struct rte_flow_error *err)
11780 : : {
11781 : : return -ENOTSUP;
11782 : : }
11783 : :
11784 : : static int
11785 : : mlx5_flow_tunnel_action_release(__rte_unused struct rte_eth_dev *dev,
11786 : : __rte_unused struct rte_flow_action *pmd_action,
11787 : : __rte_unused uint32_t num_actions,
11788 : : __rte_unused struct rte_flow_error *err)
11789 : : {
11790 : : return -ENOTSUP;
11791 : : }
11792 : :
11793 : : static int
11794 : : mlx5_flow_tunnel_get_restore_info(__rte_unused struct rte_eth_dev *dev,
11795 : : __rte_unused struct rte_mbuf *m,
11796 : : __rte_unused struct rte_flow_restore_info *i,
11797 : : __rte_unused struct rte_flow_error *err)
11798 : : {
11799 : : return -ENOTSUP;
11800 : : }
11801 : :
11802 : : static int
11803 : : flow_tunnel_add_default_miss(__rte_unused struct rte_eth_dev *dev,
11804 : : __rte_unused struct rte_flow *flow,
11805 : : __rte_unused const struct rte_flow_attr *attr,
11806 : : __rte_unused const struct rte_flow_action *actions,
11807 : : __rte_unused uint32_t flow_idx,
11808 : : __rte_unused const struct mlx5_flow_tunnel *tunnel,
11809 : : __rte_unused struct tunnel_default_miss_ctx *ctx,
11810 : : __rte_unused struct rte_flow_error *error)
11811 : : {
11812 : : return -ENOTSUP;
11813 : : }
11814 : :
11815 : : static struct mlx5_flow_tunnel *
11816 : : mlx5_find_tunnel_id(__rte_unused struct rte_eth_dev *dev,
11817 : : __rte_unused uint32_t id)
11818 : : {
11819 : : return NULL;
11820 : : }
11821 : :
11822 : : static void
11823 : : mlx5_flow_tunnel_free(__rte_unused struct rte_eth_dev *dev,
11824 : : __rte_unused struct mlx5_flow_tunnel *tunnel)
11825 : : {
11826 : : }
11827 : :
11828 : : static uint32_t
11829 : : tunnel_flow_group_to_flow_table(__rte_unused struct rte_eth_dev *dev,
11830 : : __rte_unused const struct mlx5_flow_tunnel *t,
11831 : : __rte_unused uint32_t group,
11832 : : __rte_unused uint32_t *table,
11833 : : struct rte_flow_error *error)
11834 : : {
11835 : : return rte_flow_error_set(error, ENOTSUP,
11836 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11837 : : "tunnel offload requires DV support");
11838 : : }
11839 : :
11840 : : void
11841 : : mlx5_release_tunnel_hub(__rte_unused struct mlx5_dev_ctx_shared *sh,
11842 : : __rte_unused uint16_t port_id)
11843 : : {
11844 : : }
11845 : : #endif /* HAVE_IBV_FLOW_DV_SUPPORT */
11846 : :
11847 : : /* Flex flow item API */
11848 : : static struct rte_flow_item_flex_handle *
11849 : 0 : mlx5_flow_flex_item_create(struct rte_eth_dev *dev,
11850 : : const struct rte_flow_item_flex_conf *conf,
11851 : : struct rte_flow_error *error)
11852 : : {
11853 : : static const char err_msg[] = "flex item creation unsupported";
11854 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
11855 : : struct rte_flow_attr attr = { .transfer = 0 };
11856 : 0 : const struct mlx5_flow_driver_ops *fops =
11857 : : flow_get_drv_ops(flow_get_drv_type(dev, &attr));
11858 : :
11859 [ # # ]: 0 : if (!priv->pci_dev) {
11860 : 0 : rte_flow_error_set(error, ENOTSUP,
11861 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11862 : : "create flex item on PF only");
11863 : 0 : return NULL;
11864 : : }
11865 [ # # ]: 0 : switch (priv->pci_dev->id.device_id) {
11866 : : case PCI_DEVICE_ID_MELLANOX_BLUEFIELD2:
11867 : : case PCI_DEVICE_ID_MELLANOX_BLUEFIELD3:
11868 : : break;
11869 : 0 : default:
11870 : 0 : rte_flow_error_set(error, ENOTSUP,
11871 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11872 : : "flex item available on BlueField ports only");
11873 : 0 : return NULL;
11874 : : }
11875 [ # # ]: 0 : if (!fops->item_create) {
11876 : 0 : DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
11877 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
11878 : : NULL, err_msg);
11879 : 0 : return NULL;
11880 : : }
11881 : 0 : return fops->item_create(dev, conf, error);
11882 : : }
11883 : :
11884 : : static int
11885 [ # # ]: 0 : mlx5_flow_flex_item_release(struct rte_eth_dev *dev,
11886 : : const struct rte_flow_item_flex_handle *handle,
11887 : : struct rte_flow_error *error)
11888 : : {
11889 : : static const char err_msg[] = "flex item release unsupported";
11890 : : struct rte_flow_attr attr = { .transfer = 0 };
11891 : 0 : const struct mlx5_flow_driver_ops *fops =
11892 : : flow_get_drv_ops(flow_get_drv_type(dev, &attr));
11893 : :
11894 [ # # ]: 0 : if (!fops->item_release) {
11895 : 0 : DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
11896 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
11897 : : NULL, err_msg);
11898 : 0 : return -rte_errno;
11899 : : }
11900 : 0 : return fops->item_release(dev, handle, error);
11901 : : }
11902 : :
11903 : : static void
11904 : 0 : mlx5_dbg__print_pattern(const struct rte_flow_item *item)
11905 : : {
11906 : : int ret;
11907 : : struct rte_flow_error error;
11908 : :
11909 [ # # ]: 0 : for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
11910 : : char *item_name;
11911 : 0 : ret = rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_NAME_PTR, &item_name,
11912 : : sizeof(item_name),
11913 : 0 : (void *)(uintptr_t)item->type, &error);
11914 [ # # ]: 0 : if (ret > 0)
11915 : 0 : printf("%s ", item_name);
11916 : : else
11917 : 0 : printf("%d\n", (int)item->type);
11918 : : }
11919 : : printf("END\n");
11920 : 0 : }
11921 : :
11922 : : static int
11923 : : mlx5_flow_is_std_vxlan_port(const struct rte_flow_item *udp_item)
11924 : : {
11925 : 0 : const struct rte_flow_item_udp *spec = udp_item->spec;
11926 : 0 : const struct rte_flow_item_udp *mask = udp_item->mask;
11927 : : uint16_t udp_dport = 0;
11928 : :
11929 : 0 : if (spec != NULL) {
11930 [ # # ]: 0 : if (!mask)
11931 : : mask = &rte_flow_item_udp_mask;
11932 [ # # ]: 0 : udp_dport = rte_be_to_cpu_16(spec->hdr.dst_port &
11933 : : mask->hdr.dst_port);
11934 : : }
11935 : 0 : return (!udp_dport || udp_dport == MLX5_UDP_PORT_VXLAN);
11936 : : }
11937 : :
11938 : : static const struct mlx5_flow_expand_node *
11939 : 0 : mlx5_flow_expand_rss_adjust_node(const struct rte_flow_item *pattern,
11940 : : unsigned int item_idx,
11941 : : const struct mlx5_flow_expand_node graph[],
11942 : : const struct mlx5_flow_expand_node *node)
11943 : : {
11944 : 0 : const struct rte_flow_item *item = pattern + item_idx, *prev_item;
11945 : :
11946 [ # # # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_VXLAN &&
11947 : 0 : node != NULL &&
11948 [ # # ]: 0 : node->type == RTE_FLOW_ITEM_TYPE_VXLAN) {
11949 : : /*
11950 : : * The expansion node is VXLAN and it is also the last
11951 : : * expandable item in the pattern, so need to continue
11952 : : * expansion of the inner tunnel.
11953 : : */
11954 : : MLX5_ASSERT(item_idx > 0);
11955 [ # # ]: 0 : prev_item = pattern + item_idx - 1;
11956 : : MLX5_ASSERT(prev_item->type == RTE_FLOW_ITEM_TYPE_UDP);
11957 [ # # ]: 0 : if (mlx5_flow_is_std_vxlan_port(prev_item))
11958 : 0 : return &graph[MLX5_EXPANSION_STD_VXLAN];
11959 : 0 : return &graph[MLX5_EXPANSION_L3_VXLAN];
11960 : : }
11961 : : return node;
11962 : : }
11963 : :
11964 : : /* Map of Verbs to Flow priority with 8 Verbs priorities. */
11965 : : static const uint32_t priority_map_3[][MLX5_PRIORITY_MAP_MAX] = {
11966 : : { 0, 1, 2 }, { 2, 3, 4 }, { 5, 6, 7 },
11967 : : };
11968 : :
11969 : : /* Map of Verbs to Flow priority with 16 Verbs priorities. */
11970 : : static const uint32_t priority_map_5[][MLX5_PRIORITY_MAP_MAX] = {
11971 : : { 0, 1, 2 }, { 3, 4, 5 }, { 6, 7, 8 },
11972 : : { 9, 10, 11 }, { 12, 13, 14 },
11973 : : };
11974 : :
11975 : : /**
11976 : : * Discover the number of available flow priorities.
11977 : : *
11978 : : * @param dev
11979 : : * Ethernet device.
11980 : : *
11981 : : * @return
11982 : : * On success, number of available flow priorities.
11983 : : * On failure, a negative errno-style code and rte_errno is set.
11984 : : */
11985 : : int
11986 : 0 : mlx5_flow_discover_priorities(struct rte_eth_dev *dev)
11987 : : {
11988 : : static const uint16_t vprio[] = {8, 16};
11989 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
11990 : : const struct mlx5_flow_driver_ops *fops;
11991 : : enum mlx5_flow_drv_type type;
11992 : : int ret;
11993 : :
11994 : : type = mlx5_flow_os_get_type();
11995 : : if (type == MLX5_FLOW_TYPE_MAX) {
11996 : : type = MLX5_FLOW_TYPE_VERBS;
11997 [ # # # # ]: 0 : if (priv->sh->cdev->config.devx && priv->sh->config.dv_flow_en)
11998 : : type = MLX5_FLOW_TYPE_DV;
11999 : : }
12000 : 0 : fops = flow_get_drv_ops(type);
12001 [ # # ]: 0 : if (fops->discover_priorities == NULL) {
12002 : 0 : DRV_LOG(ERR, "Priority discovery not supported");
12003 : 0 : rte_errno = ENOTSUP;
12004 : 0 : return -rte_errno;
12005 : : }
12006 : 0 : ret = fops->discover_priorities(dev, vprio, RTE_DIM(vprio));
12007 [ # # ]: 0 : if (ret < 0)
12008 : : return ret;
12009 [ # # # ]: 0 : switch (ret) {
12010 : : case 8:
12011 : : ret = RTE_DIM(priority_map_3);
12012 : : break;
12013 : 0 : case 16:
12014 : : ret = RTE_DIM(priority_map_5);
12015 : 0 : break;
12016 : 0 : default:
12017 : 0 : rte_errno = ENOTSUP;
12018 : 0 : DRV_LOG(ERR,
12019 : : "port %u maximum priority: %d expected 8/16",
12020 : : dev->data->port_id, ret);
12021 : 0 : return -rte_errno;
12022 : : }
12023 : 0 : DRV_LOG(INFO, "port %u supported flow priorities:"
12024 : : " 0-%d for ingress or egress root table,"
12025 : : " 0-%d for non-root table or transfer root table.",
12026 : : dev->data->port_id, ret - 2,
12027 : : MLX5_NON_ROOT_FLOW_MAX_PRIO - 1);
12028 : 0 : return ret;
12029 : : }
12030 : :
12031 : : /**
12032 : : * Adjust flow priority based on the highest layer and the request priority.
12033 : : *
12034 : : * @param[in] dev
12035 : : * Pointer to the Ethernet device structure.
12036 : : * @param[in] priority
12037 : : * The rule base priority.
12038 : : * @param[in] subpriority
12039 : : * The priority based on the items.
12040 : : *
12041 : : * @return
12042 : : * The new priority.
12043 : : */
12044 : : uint32_t
12045 : 0 : mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
12046 : : uint32_t subpriority)
12047 : : {
12048 : : uint32_t res = 0;
12049 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12050 : :
12051 [ # # # ]: 0 : switch (priv->sh->flow_max_priority) {
12052 : 0 : case RTE_DIM(priority_map_3):
12053 : 0 : res = priority_map_3[priority][subpriority];
12054 : 0 : break;
12055 : 0 : case RTE_DIM(priority_map_5):
12056 : 0 : res = priority_map_5[priority][subpriority];
12057 : 0 : break;
12058 : : }
12059 : 0 : return res;
12060 : : }
12061 : :
12062 : : /**
12063 : : * Get the priority for sending traffic to kernel table.
12064 : : *
12065 : : * @param[in] dev
12066 : : * Pointer to the Ethernet device structure.
12067 : : *
12068 : : * @return
12069 : : * On success: the value of priority for sending traffic to kernel table
12070 : : * On failure: -1
12071 : : */
12072 : : uint32_t
12073 : 0 : mlx5_get_send_to_kernel_priority(struct rte_eth_dev *dev)
12074 : : {
12075 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12076 : : uint32_t res;
12077 : :
12078 [ # # # ]: 0 : switch (priv->sh->flow_max_priority) {
12079 : : case RTE_DIM(priority_map_5):
12080 : : res = 15;
12081 : : break;
12082 : 0 : case RTE_DIM(priority_map_3):
12083 : : res = 7;
12084 : 0 : break;
12085 : 0 : default:
12086 : 0 : DRV_LOG(ERR,
12087 : : "port %u maximum priority: %d expected 8/16",
12088 : : dev->data->port_id, priv->sh->flow_max_priority);
12089 : : res = (uint32_t)-1;
12090 : : }
12091 : 0 : return res;
12092 : : }
12093 : :
12094 : : /**
12095 : : * Get the E-Switch Manager vport id.
12096 : : *
12097 : : * @param[in] dev
12098 : : * Pointer to the Ethernet device structure.
12099 : : *
12100 : : * @return
12101 : : * The vport id.
12102 : : */
12103 : 0 : int16_t mlx5_flow_get_esw_manager_vport_id(struct rte_eth_dev *dev)
12104 : : {
12105 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12106 : 0 : struct mlx5_common_device *cdev = priv->sh->cdev;
12107 : :
12108 : : /* New FW exposes E-Switch Manager vport ID, can use it directly. */
12109 [ # # ]: 0 : if (cdev->config.hca_attr.esw_mgr_vport_id_valid)
12110 : 0 : return (int16_t)cdev->config.hca_attr.esw_mgr_vport_id;
12111 : :
12112 [ # # ]: 0 : if (priv->pci_dev == NULL)
12113 : : return 0;
12114 [ # # ]: 0 : switch (priv->pci_dev->id.device_id) {
12115 : : case PCI_DEVICE_ID_MELLANOX_BLUEFIELD:
12116 : : case PCI_DEVICE_ID_MELLANOX_BLUEFIELD2:
12117 : : case PCI_DEVICE_ID_MELLANOX_BLUEFIELD3:
12118 : : /*
12119 : : * In old FW which doesn't expose the E-Switch Manager vport ID in the capability,
12120 : : * only the BF embedded CPUs control the E-Switch Manager port. Hence,
12121 : : * ECPF vport ID is selected and not the host port (0) in any BF case.
12122 : : */
12123 : : return (int16_t)MLX5_ECPF_VPORT_ID;
12124 : 0 : default:
12125 : 0 : return MLX5_PF_VPORT_ID;
12126 : : }
12127 : : }
12128 : :
12129 : : /**
12130 : : * Parse item to get the vport id.
12131 : : *
12132 : : * @param[in] dev
12133 : : * Pointer to the Ethernet device structure.
12134 : : * @param[in] item
12135 : : * The src port id match item.
12136 : : * @param[out] vport_id
12137 : : * Pointer to put the vport id.
12138 : : * @param[out] all_ports
12139 : : * Indicate if the item matches all ports.
12140 : : * @param[out] error
12141 : : * Pointer to error structure.
12142 : : *
12143 : : * @return
12144 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
12145 : : */
12146 : 0 : int mlx5_flow_get_item_vport_id(struct rte_eth_dev *dev,
12147 : : const struct rte_flow_item *item,
12148 : : uint16_t *vport_id,
12149 : : bool *all_ports,
12150 : : struct rte_flow_error *error)
12151 : : {
12152 : : struct mlx5_priv *port_priv;
12153 : : const struct rte_flow_item_port_id *pid_v = NULL;
12154 : : const struct rte_flow_item_ethdev *dev_v = NULL;
12155 : : uint32_t esw_mgr_port;
12156 : : uint32_t src_port;
12157 : :
12158 [ # # ]: 0 : if (all_ports)
12159 : 0 : *all_ports = false;
12160 [ # # # # ]: 0 : switch (item->type) {
12161 : 0 : case RTE_FLOW_ITEM_TYPE_PORT_ID:
12162 : 0 : pid_v = item->spec;
12163 [ # # ]: 0 : if (!pid_v)
12164 : : return 0;
12165 : 0 : src_port = pid_v->id;
12166 : : esw_mgr_port = MLX5_PORT_ESW_MGR;
12167 : 0 : break;
12168 : 0 : case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
12169 : 0 : dev_v = item->spec;
12170 [ # # ]: 0 : if (!dev_v) {
12171 [ # # ]: 0 : if (all_ports)
12172 : 0 : *all_ports = true;
12173 : 0 : return 0;
12174 : : }
12175 : 0 : src_port = dev_v->port_id;
12176 : : esw_mgr_port = MLX5_REPRESENTED_PORT_ESW_MGR;
12177 : 0 : break;
12178 : : case RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR:
12179 : : src_port = MLX5_REPRESENTED_PORT_ESW_MGR;
12180 : : esw_mgr_port = MLX5_REPRESENTED_PORT_ESW_MGR;
12181 : : break;
12182 : 0 : default:
12183 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
12184 : : NULL, "Incorrect item type.");
12185 : : }
12186 [ # # ]: 0 : if (src_port == esw_mgr_port) {
12187 : 0 : *vport_id = mlx5_flow_get_esw_manager_vport_id(dev);
12188 : : } else {
12189 : 0 : port_priv = mlx5_port_to_eswitch_info(src_port, false);
12190 [ # # ]: 0 : if (!port_priv)
12191 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
12192 : : NULL, "Failed to get port info.");
12193 : 0 : *vport_id = port_priv->representor_id;
12194 : : }
12195 : :
12196 : : return 0;
12197 : : }
12198 : :
12199 : : int
12200 : 0 : mlx5_flow_pick_transfer_proxy(struct rte_eth_dev *dev,
12201 : : uint16_t *proxy_port_id,
12202 : : struct rte_flow_error *error)
12203 : : {
12204 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
12205 : : uint16_t port_id;
12206 : :
12207 [ # # ]: 0 : if (!priv->sh->config.dv_esw_en)
12208 : 0 : return rte_flow_error_set(error, EINVAL,
12209 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12210 : : NULL,
12211 : : "unable to provide a proxy port"
12212 : : " without E-Switch configured");
12213 [ # # ]: 0 : if (!priv->master && !priv->representor)
12214 : 0 : return rte_flow_error_set(error, EINVAL,
12215 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12216 : : NULL,
12217 : : "unable to provide a proxy port"
12218 : : " for port which is not a master"
12219 : : " or a representor port");
12220 [ # # ]: 0 : if (priv->master) {
12221 : 0 : *proxy_port_id = dev->data->port_id;
12222 : 0 : return 0;
12223 : : }
12224 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port_id, dev->device) {
12225 : 0 : const struct rte_eth_dev *port_dev = &rte_eth_devices[port_id];
12226 : 0 : const struct mlx5_priv *port_priv = port_dev->data->dev_private;
12227 : :
12228 [ # # ]: 0 : if (port_priv->master &&
12229 [ # # ]: 0 : port_priv->domain_id == priv->domain_id) {
12230 : 0 : *proxy_port_id = port_id;
12231 : 0 : return 0;
12232 : : }
12233 : : }
12234 : 0 : return rte_flow_error_set(error, ENODEV,
12235 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12236 : : NULL, "unable to find a proxy port");
12237 : : }
12238 : :
12239 : : /**
12240 : : * Discover IPv6 traffic class ID support in rdma-core and firmware.
12241 : : *
12242 : : * @param dev
12243 : : * Ethernet device.
12244 : : *
12245 : : * @return
12246 : : * 0, rdma-core is good to work with firmware.
12247 : : * -EOPNOTSUPP, rdma-core could not work with new IPv6 TC ID.
12248 : : */
12249 : : int
12250 : 0 : mlx5_flow_discover_ipv6_tc_support(struct rte_eth_dev *dev)
12251 : : {
12252 : : struct rte_flow_action_set_dscp set_dscp;
12253 : : struct rte_flow_attr attr;
12254 : : struct rte_flow_action actions[2];
12255 : : struct rte_flow_item items[3];
12256 : : struct rte_flow_error error;
12257 : : uint32_t flow_idx;
12258 : :
12259 : : memset(&attr, 0, sizeof(attr));
12260 : : memset(actions, 0, sizeof(actions));
12261 : : memset(items, 0, sizeof(items));
12262 : 0 : attr.group = 1;
12263 : 0 : attr.egress = 1;
12264 : 0 : items[0].type = RTE_FLOW_ITEM_TYPE_ETH;
12265 : 0 : items[1].type = RTE_FLOW_ITEM_TYPE_IPV6;
12266 : : items[2].type = RTE_FLOW_ITEM_TYPE_END;
12267 : : /* Random value */
12268 : 0 : set_dscp.dscp = 9;
12269 : 0 : actions[0].type = RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP;
12270 : 0 : actions[0].conf = &set_dscp;
12271 : : actions[1].type = RTE_FLOW_ACTION_TYPE_END;
12272 : :
12273 : 0 : flow_idx = mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_GEN, &attr, items,
12274 : : actions, true, &error);
12275 [ # # ]: 0 : if (!flow_idx)
12276 : : return -EOPNOTSUPP;
12277 : :
12278 : 0 : mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN, flow_idx);
12279 : 0 : return 0;
12280 : : }
12281 : :
12282 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_mlx5_create_geneve_tlv_parser, 24.03)
12283 : : void *
12284 : 0 : rte_pmd_mlx5_create_geneve_tlv_parser(uint16_t port_id,
12285 : : const struct rte_pmd_mlx5_geneve_tlv tlv_list[],
12286 : : uint8_t nb_options)
12287 : : {
12288 : : #ifdef HAVE_MLX5_HWS_SUPPORT
12289 : 0 : return mlx5_geneve_tlv_parser_create(port_id, tlv_list, nb_options);
12290 : : #else
12291 : : (void)port_id;
12292 : : (void)tlv_list;
12293 : : (void)nb_options;
12294 : : DRV_LOG(ERR, "%s is not supported.", __func__);
12295 : : rte_errno = ENOTSUP;
12296 : : return NULL;
12297 : : #endif
12298 : : }
12299 : :
12300 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_mlx5_destroy_geneve_tlv_parser, 24.03)
12301 : : int
12302 : 0 : rte_pmd_mlx5_destroy_geneve_tlv_parser(void *handle)
12303 : : {
12304 : : #ifdef HAVE_MLX5_HWS_SUPPORT
12305 : 0 : return mlx5_geneve_tlv_parser_destroy(handle);
12306 : : #else
12307 : : (void)handle;
12308 : : DRV_LOG(ERR, "%s is not supported.", __func__);
12309 : : rte_errno = ENOTSUP;
12310 : : return -rte_errno;
12311 : : #endif
12312 : : }
12313 : :
12314 : : bool
12315 : 0 : mlx5_ctrl_flow_uc_dmac_exists(struct rte_eth_dev *dev, const struct rte_ether_addr *addr)
12316 : : {
12317 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12318 : : struct mlx5_ctrl_flow_entry *entry;
12319 : : bool exists = false;
12320 : :
12321 [ # # ]: 0 : LIST_FOREACH(entry, &priv->hw_ctrl_flows, next) {
12322 [ # # # # ]: 0 : if (entry->info.type == MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC &&
12323 : : rte_is_same_ether_addr(addr, &entry->info.uc.dmac)) {
12324 : : exists = true;
12325 : : break;
12326 : : }
12327 : : }
12328 : 0 : return exists;
12329 : : }
12330 : :
12331 : : bool
12332 : 0 : mlx5_ctrl_flow_uc_dmac_vlan_exists(struct rte_eth_dev *dev,
12333 : : const struct rte_ether_addr *addr,
12334 : : const uint16_t vid)
12335 : : {
12336 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12337 : : struct mlx5_ctrl_flow_entry *entry;
12338 : : bool exists = false;
12339 : :
12340 [ # # ]: 0 : LIST_FOREACH(entry, &priv->hw_ctrl_flows, next) {
12341 [ # # # # ]: 0 : if (entry->info.type == MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC_VLAN &&
12342 : 0 : rte_is_same_ether_addr(addr, &entry->info.uc.dmac) &&
12343 [ # # ]: 0 : vid == entry->info.uc.vlan) {
12344 : : exists = true;
12345 : : break;
12346 : : }
12347 : : }
12348 : 0 : return exists;
12349 : : }
|