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 <rte_common.h>
13 : : #include <rte_ether.h>
14 : : #include <ethdev_driver.h>
15 : : #include <rte_eal_paging.h>
16 : : #include <rte_flow.h>
17 : : #include <rte_cycles.h>
18 : : #include <rte_flow_driver.h>
19 : : #include <rte_malloc.h>
20 : : #include <rte_ip.h>
21 : :
22 : : #include <mlx5_glue.h>
23 : : #include <mlx5_devx_cmds.h>
24 : : #include <mlx5_prm.h>
25 : : #include <mlx5_malloc.h>
26 : :
27 : : #include "mlx5_defs.h"
28 : : #include "mlx5.h"
29 : : #include "mlx5_flow.h"
30 : : #include "mlx5_flow_os.h"
31 : : #include "mlx5_rx.h"
32 : : #include "mlx5_tx.h"
33 : : #include "mlx5_common_os.h"
34 : : #include "rte_pmd_mlx5.h"
35 : :
36 : : /*
37 : : * Shared array for quick translation between port_id and vport mask/values
38 : : * used for HWS rules.
39 : : */
40 : : struct flow_hw_port_info mlx5_flow_hw_port_infos[RTE_MAX_ETHPORTS];
41 : :
42 : : struct tunnel_default_miss_ctx {
43 : : uint16_t *queue;
44 : : __extension__
45 : : union {
46 : : struct rte_flow_action_rss action_rss;
47 : : struct rte_flow_action_queue miss_queue;
48 : : struct rte_flow_action_jump miss_jump;
49 : : uint8_t raw[0];
50 : : };
51 : : };
52 : :
53 : : void
54 : 0 : mlx5_indirect_list_handles_release(struct rte_eth_dev *dev)
55 : : {
56 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
57 : : #ifdef HAVE_MLX5_HWS_SUPPORT
58 : : struct rte_flow_error error;
59 : : #endif
60 : :
61 [ # # ]: 0 : while (!LIST_EMPTY(&priv->indirect_list_head)) {
62 : : struct mlx5_indirect_list *e =
63 : : LIST_FIRST(&priv->indirect_list_head);
64 : :
65 [ # # ]: 0 : LIST_REMOVE(e, entry);
66 [ # # # # ]: 0 : switch (e->type) {
67 : : #ifdef HAVE_MLX5_HWS_SUPPORT
68 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_MIRROR:
69 : 0 : mlx5_hw_mirror_destroy(dev, (struct mlx5_mirror *)e);
70 : 0 : break;
71 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_LEGACY:
72 : 0 : mlx5_destroy_legacy_indirect(dev, e);
73 : 0 : break;
74 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_REFORMAT:
75 : 0 : mlx5_reformat_action_destroy(dev,
76 : : (struct rte_flow_action_list_handle *)e, &error);
77 : 0 : break;
78 : : #endif
79 : 0 : default:
80 : 0 : DRV_LOG(ERR, "invalid indirect list type");
81 : : MLX5_ASSERT(false);
82 : 0 : break;
83 : : }
84 : : }
85 : 0 : }
86 : :
87 : : static int
88 : : flow_tunnel_add_default_miss(struct rte_eth_dev *dev,
89 : : struct rte_flow *flow,
90 : : const struct rte_flow_attr *attr,
91 : : const struct rte_flow_action *app_actions,
92 : : uint32_t flow_idx,
93 : : const struct mlx5_flow_tunnel *tunnel,
94 : : struct tunnel_default_miss_ctx *ctx,
95 : : struct rte_flow_error *error);
96 : : static struct mlx5_flow_tunnel *
97 : : mlx5_find_tunnel_id(struct rte_eth_dev *dev, uint32_t id);
98 : : static void
99 : : mlx5_flow_tunnel_free(struct rte_eth_dev *dev, struct mlx5_flow_tunnel *tunnel);
100 : : static uint32_t
101 : : tunnel_flow_group_to_flow_table(struct rte_eth_dev *dev,
102 : : const struct mlx5_flow_tunnel *tunnel,
103 : : uint32_t group, uint32_t *table,
104 : : struct rte_flow_error *error);
105 : :
106 : : /** Device flow drivers. */
107 : : extern const struct mlx5_flow_driver_ops mlx5_flow_verbs_drv_ops;
108 : :
109 : : const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops;
110 : :
111 : : const struct mlx5_flow_driver_ops *flow_drv_ops[] = {
112 : : [MLX5_FLOW_TYPE_MIN] = &mlx5_flow_null_drv_ops,
113 : : #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
114 : : [MLX5_FLOW_TYPE_DV] = &mlx5_flow_dv_drv_ops,
115 : : #endif
116 : : #ifdef HAVE_MLX5_HWS_SUPPORT
117 : : [MLX5_FLOW_TYPE_HW] = &mlx5_flow_hw_drv_ops,
118 : : #endif
119 : : [MLX5_FLOW_TYPE_VERBS] = &mlx5_flow_verbs_drv_ops,
120 : : [MLX5_FLOW_TYPE_MAX] = &mlx5_flow_null_drv_ops
121 : : };
122 : :
123 : : /** Helper macro to build input graph for mlx5_flow_expand_rss(). */
124 : : #define MLX5_FLOW_EXPAND_RSS_NEXT(...) \
125 : : (const int []){ \
126 : : __VA_ARGS__, 0, \
127 : : }
128 : :
129 : : /** Node object of input graph for mlx5_flow_expand_rss(). */
130 : : struct mlx5_flow_expand_node {
131 : : const int *const next;
132 : : /**<
133 : : * List of next node indexes. Index 0 is interpreted as a terminator.
134 : : */
135 : : const enum rte_flow_item_type type;
136 : : /**< Pattern item type of current node. */
137 : : uint64_t rss_types;
138 : : /**<
139 : : * RSS types bit-field associated with this node
140 : : * (see RTE_ETH_RSS_* definitions).
141 : : */
142 : : uint64_t node_flags;
143 : : /**<
144 : : * Bit-fields that define how the node is used in the expansion.
145 : : * (see MLX5_EXPANSION_NODE_* definitions).
146 : : */
147 : : };
148 : :
149 : : /** Keep same format with mlx5_flow_expand_rss to share the buffer for expansion. */
150 : : struct mlx5_flow_expand_sqn {
151 : : uint32_t entries; /** Number of entries */
152 : : struct {
153 : : struct rte_flow_item *pattern; /**< Expanded pattern array. */
154 : : uint32_t priority; /**< Priority offset for each expansion. */
155 : : } entry[];
156 : : };
157 : :
158 : : /* Optional expand field. The expansion alg will not go deeper. */
159 : : #define MLX5_EXPANSION_NODE_OPTIONAL (UINT64_C(1) << 0)
160 : :
161 : : /* The node is not added implicitly as expansion to the flow pattern.
162 : : * If the node type does not match the flow pattern item type, the
163 : : * expansion alg will go deeper to its next items.
164 : : * In the current implementation, the list of next nodes indexes can
165 : : * have up to one node with this flag set and it has to be the last
166 : : * node index (before the list terminator).
167 : : */
168 : : #define MLX5_EXPANSION_NODE_EXPLICIT (UINT64_C(1) << 1)
169 : :
170 : : /** Object returned by mlx5_flow_expand_rss(). */
171 : : struct mlx5_flow_expand_rss {
172 : : uint32_t entries;
173 : : /**< Number of entries @p patterns and @p priorities. */
174 : : struct {
175 : : struct rte_flow_item *pattern; /**< Expanded pattern array. */
176 : : uint32_t priority; /**< Priority offset for each expansion. */
177 : : } entry[];
178 : : };
179 : :
180 : : static void
181 : : mlx5_dbg__print_pattern(const struct rte_flow_item *item);
182 : :
183 : : static const struct mlx5_flow_expand_node *
184 : : mlx5_flow_expand_rss_adjust_node(const struct rte_flow_item *pattern,
185 : : unsigned int item_idx,
186 : : const struct mlx5_flow_expand_node graph[],
187 : : const struct mlx5_flow_expand_node *node);
188 : :
189 : : static __rte_always_inline int
190 : : mlx5_need_cache_flow(const struct mlx5_priv *priv,
191 : : const struct rte_flow_attr *attr)
192 : : {
193 [ # # # # : 0 : return priv->isolated && priv->sh->config.dv_flow_en == 1 &&
# # # # ]
194 [ # # # # ]: 0 : (attr ? !attr->group : true) &&
195 [ # # # # : 0 : priv->mode_info.mode == RTE_PMD_MLX5_FLOW_ENGINE_MODE_STANDBY &&
# # # # #
# # # # #
# # ]
196 [ # # # # : 0 : (!priv->sh->config.dv_esw_en || !priv->sh->config.fdb_def_rule);
# # # # #
# # # # #
# # ]
197 : : }
198 : :
199 : : static bool
200 : 0 : mlx5_flow_is_rss_expandable_item(const struct rte_flow_item *item)
201 : : {
202 [ # # ]: 0 : switch (item->type) {
203 : : case RTE_FLOW_ITEM_TYPE_ETH:
204 : : case RTE_FLOW_ITEM_TYPE_VLAN:
205 : : case RTE_FLOW_ITEM_TYPE_IPV4:
206 : : case RTE_FLOW_ITEM_TYPE_IPV6:
207 : : case RTE_FLOW_ITEM_TYPE_UDP:
208 : : case RTE_FLOW_ITEM_TYPE_TCP:
209 : : case RTE_FLOW_ITEM_TYPE_ESP:
210 : : case RTE_FLOW_ITEM_TYPE_ICMP:
211 : : case RTE_FLOW_ITEM_TYPE_ICMP6:
212 : : case RTE_FLOW_ITEM_TYPE_VXLAN:
213 : : case RTE_FLOW_ITEM_TYPE_NVGRE:
214 : : case RTE_FLOW_ITEM_TYPE_GRE:
215 : : case RTE_FLOW_ITEM_TYPE_GENEVE:
216 : : case RTE_FLOW_ITEM_TYPE_MPLS:
217 : : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
218 : : case RTE_FLOW_ITEM_TYPE_GRE_KEY:
219 : : case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
220 : : case RTE_FLOW_ITEM_TYPE_GTP:
221 : : return true;
222 : : default:
223 : : break;
224 : : }
225 : 0 : return false;
226 : : }
227 : :
228 : : /**
229 : : * Network Service Header (NSH) and its next protocol values
230 : : * are described in RFC-8393.
231 : : */
232 : : static enum rte_flow_item_type
233 : : mlx5_nsh_proto_to_item_type(uint8_t proto_spec, uint8_t proto_mask)
234 : : {
235 : : enum rte_flow_item_type type;
236 : :
237 : 0 : switch (proto_mask & proto_spec) {
238 : : case 0:
239 : : type = RTE_FLOW_ITEM_TYPE_VOID;
240 : : break;
241 : : case RTE_VXLAN_GPE_TYPE_IPV4:
242 : : type = RTE_FLOW_ITEM_TYPE_IPV4;
243 : : break;
244 : : case RTE_VXLAN_GPE_TYPE_IPV6:
245 : : type = RTE_VXLAN_GPE_TYPE_IPV6;
246 : : break;
247 : : case RTE_VXLAN_GPE_TYPE_ETH:
248 : : type = RTE_FLOW_ITEM_TYPE_ETH;
249 : : break;
250 : : default:
251 : : type = RTE_FLOW_ITEM_TYPE_END;
252 : : }
253 : : return type;
254 : : }
255 : :
256 : : static enum rte_flow_item_type
257 : : mlx5_inet_proto_to_item_type(uint8_t proto_spec, uint8_t proto_mask)
258 : : {
259 : : enum rte_flow_item_type type;
260 : :
261 [ # # # # : 0 : switch (proto_mask & proto_spec) {
# # # # #
# # # #
# ]
262 : : case 0:
263 : : type = RTE_FLOW_ITEM_TYPE_VOID;
264 : : break;
265 : 0 : case IPPROTO_UDP:
266 : : type = RTE_FLOW_ITEM_TYPE_UDP;
267 : 0 : break;
268 : 0 : case IPPROTO_TCP:
269 : : type = RTE_FLOW_ITEM_TYPE_TCP;
270 : 0 : break;
271 : 0 : case IPPROTO_IPIP:
272 : : type = RTE_FLOW_ITEM_TYPE_IPV4;
273 : 0 : break;
274 : 0 : case IPPROTO_IPV6:
275 : : type = RTE_FLOW_ITEM_TYPE_IPV6;
276 : 0 : break;
277 : 0 : case IPPROTO_ESP:
278 : : type = RTE_FLOW_ITEM_TYPE_ESP;
279 : 0 : break;
280 : 0 : default:
281 : : type = RTE_FLOW_ITEM_TYPE_END;
282 : : }
283 : : return type;
284 : : }
285 : :
286 : : static enum rte_flow_item_type
287 : : mlx5_ethertype_to_item_type(rte_be16_t type_spec,
288 : : rte_be16_t type_mask, bool is_tunnel)
289 : : {
290 : : enum rte_flow_item_type type;
291 : :
292 [ # # # # : 0 : switch (rte_be_to_cpu_16(type_spec & type_mask)) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
293 : : case 0:
294 : : type = RTE_FLOW_ITEM_TYPE_VOID;
295 : : break;
296 : 0 : case RTE_ETHER_TYPE_TEB:
297 : : type = is_tunnel ?
298 : : RTE_FLOW_ITEM_TYPE_ETH : RTE_FLOW_ITEM_TYPE_END;
299 : : break;
300 : 0 : case RTE_ETHER_TYPE_VLAN:
301 : : type = !is_tunnel ?
302 : : RTE_FLOW_ITEM_TYPE_VLAN : RTE_FLOW_ITEM_TYPE_END;
303 : : break;
304 : 0 : case RTE_ETHER_TYPE_IPV4:
305 : : type = RTE_FLOW_ITEM_TYPE_IPV4;
306 : 0 : break;
307 : 0 : case RTE_ETHER_TYPE_IPV6:
308 : : type = RTE_FLOW_ITEM_TYPE_IPV6;
309 : 0 : break;
310 : 0 : default:
311 : : type = RTE_FLOW_ITEM_TYPE_END;
312 : : }
313 : : return type;
314 : : }
315 : :
316 : : static enum rte_flow_item_type
317 : 0 : mlx5_flow_expand_rss_item_complete(const struct rte_flow_item *item)
318 : : {
319 : : #define MLX5_XSET_ITEM_MASK_SPEC(type, fld) \
320 : : do { \
321 : : const void *m = item->mask; \
322 : : const void *s = item->spec; \
323 : : mask = m ? \
324 : : ((const struct rte_flow_item_##type *)m)->fld : \
325 : : rte_flow_item_##type##_mask.fld; \
326 : : spec = ((const struct rte_flow_item_##type *)s)->fld; \
327 : : } while (0)
328 : :
329 : : enum rte_flow_item_type ret;
330 : : uint16_t spec, mask;
331 : :
332 [ # # # # ]: 0 : if (item == NULL || item->spec == NULL)
333 : : return RTE_FLOW_ITEM_TYPE_VOID;
334 [ # # # # : 0 : switch (item->type) {
# # # # ]
335 : 0 : case RTE_FLOW_ITEM_TYPE_ETH:
336 [ # # ]: 0 : MLX5_XSET_ITEM_MASK_SPEC(eth, hdr.ether_type);
337 [ # # ]: 0 : if (!mask)
338 : : return RTE_FLOW_ITEM_TYPE_VOID;
339 : : ret = mlx5_ethertype_to_item_type(spec, mask, false);
340 : : break;
341 : 0 : case RTE_FLOW_ITEM_TYPE_VLAN:
342 [ # # ]: 0 : MLX5_XSET_ITEM_MASK_SPEC(vlan, hdr.eth_proto);
343 [ # # ]: 0 : if (!mask)
344 : : return RTE_FLOW_ITEM_TYPE_VOID;
345 : : ret = mlx5_ethertype_to_item_type(spec, mask, false);
346 : : break;
347 : 0 : case RTE_FLOW_ITEM_TYPE_IPV4:
348 [ # # ]: 0 : MLX5_XSET_ITEM_MASK_SPEC(ipv4, hdr.next_proto_id);
349 [ # # ]: 0 : if (!mask)
350 : : return RTE_FLOW_ITEM_TYPE_VOID;
351 : : ret = mlx5_inet_proto_to_item_type(spec, mask);
352 : : break;
353 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6:
354 [ # # ]: 0 : MLX5_XSET_ITEM_MASK_SPEC(ipv6, hdr.proto);
355 [ # # ]: 0 : if (!mask)
356 : : return RTE_FLOW_ITEM_TYPE_VOID;
357 : : ret = mlx5_inet_proto_to_item_type(spec, mask);
358 : : break;
359 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE:
360 [ # # # # ]: 0 : MLX5_XSET_ITEM_MASK_SPEC(geneve, protocol);
361 : : ret = mlx5_ethertype_to_item_type(spec, mask, true);
362 : : break;
363 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
364 [ # # # # ]: 0 : MLX5_XSET_ITEM_MASK_SPEC(gre, protocol);
365 : : ret = mlx5_ethertype_to_item_type(spec, mask, true);
366 : : break;
367 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
368 [ # # ]: 0 : MLX5_XSET_ITEM_MASK_SPEC(vxlan_gpe, hdr.proto);
369 [ # # ]: 0 : ret = mlx5_nsh_proto_to_item_type(spec, mask);
370 : : break;
371 : : default:
372 : : ret = RTE_FLOW_ITEM_TYPE_VOID;
373 : : break;
374 : : }
375 : : return ret;
376 : : #undef MLX5_XSET_ITEM_MASK_SPEC
377 : : }
378 : :
379 : : static const int *
380 : : mlx5_flow_expand_rss_skip_explicit(const struct mlx5_flow_expand_node graph[],
381 : : const int *next_node)
382 : : {
383 : : const struct mlx5_flow_expand_node *node = NULL;
384 : : const int *next = next_node;
385 : :
386 [ # # # # : 0 : while (next && *next) {
# # # # #
# # # # #
# # ]
387 : : /*
388 : : * Skip the nodes with the MLX5_EXPANSION_NODE_EXPLICIT
389 : : * flag set, because they were not found in the flow pattern.
390 : : */
391 : 0 : node = &graph[*next];
392 [ # # # # : 0 : if (!(node->node_flags & MLX5_EXPANSION_NODE_EXPLICIT))
# # # # ]
393 : : break;
394 : 0 : next = node->next;
395 : : }
396 : : return next;
397 : : }
398 : :
399 : : #define MLX5_RSS_EXP_ELT_N 32
400 : :
401 : : /**
402 : : * Expand RSS flows into several possible flows according to the RSS hash
403 : : * fields requested and the driver capabilities.
404 : : *
405 : : * @param[out] buf
406 : : * Buffer to store the result expansion.
407 : : * @param[in] size
408 : : * Buffer size in bytes. If 0, @p buf can be NULL.
409 : : * @param[in] pattern
410 : : * User flow pattern.
411 : : * @param[in] types
412 : : * RSS types to expand (see RTE_ETH_RSS_* definitions).
413 : : * @param[in] graph
414 : : * Input graph to expand @p pattern according to @p types.
415 : : * @param[in] graph_root_index
416 : : * Index of root node in @p graph, typically 0.
417 : : *
418 : : * @return
419 : : * A positive value representing the size of @p buf in bytes regardless of
420 : : * @p size on success, a negative errno value otherwise and rte_errno is
421 : : * set, the following errors are defined:
422 : : *
423 : : * -E2BIG: graph-depth @p graph is too deep.
424 : : * -EINVAL: @p size has not enough space for expanded pattern.
425 : : */
426 : : static int
427 : 0 : mlx5_flow_expand_rss(struct mlx5_flow_expand_rss *buf, size_t size,
428 : : const struct rte_flow_item *pattern, uint64_t types,
429 : : const struct mlx5_flow_expand_node graph[],
430 : : int graph_root_index)
431 : : {
432 : : const struct rte_flow_item *item;
433 [ # # ]: 0 : const struct mlx5_flow_expand_node *node = &graph[graph_root_index];
434 : : const int *next_node;
435 : : const int *stack[MLX5_RSS_EXP_ELT_N];
436 : : int stack_pos = 0;
437 : : struct rte_flow_item flow_items[MLX5_RSS_EXP_ELT_N];
438 : : unsigned int i, item_idx, last_expand_item_idx = 0;
439 : : size_t lsize;
440 : : size_t user_pattern_size = 0;
441 : : void *addr = NULL;
442 : : const struct mlx5_flow_expand_node *next = NULL;
443 : : struct rte_flow_item missed_item;
444 : : int missed = 0;
445 : : int elt = 0;
446 : : const struct rte_flow_item *last_expand_item = NULL;
447 : :
448 : : memset(&missed_item, 0, sizeof(missed_item));
449 : : lsize = offsetof(struct mlx5_flow_expand_rss, entry) +
450 : : MLX5_RSS_EXP_ELT_N * sizeof(buf->entry[0]);
451 [ # # ]: 0 : if (lsize > size)
452 : : return -EINVAL;
453 : 0 : buf->entry[0].priority = 0;
454 : 0 : buf->entry[0].pattern = (void *)&buf->entry[MLX5_RSS_EXP_ELT_N];
455 : 0 : buf->entries = 0;
456 : : addr = buf->entry[0].pattern;
457 : 0 : for (item = pattern, item_idx = 0;
458 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_END;
459 : 0 : item++, item_idx++) {
460 [ # # ]: 0 : if (!mlx5_flow_is_rss_expandable_item(item)) {
461 : 0 : user_pattern_size += sizeof(*item);
462 : 0 : continue;
463 : : }
464 : : last_expand_item = item;
465 : : last_expand_item_idx = item_idx;
466 : : i = 0;
467 [ # # # # ]: 0 : while (node->next && node->next[i]) {
468 : 0 : next = &graph[node->next[i]];
469 [ # # ]: 0 : if (next->type == item->type)
470 : : break;
471 [ # # ]: 0 : if (next->node_flags & MLX5_EXPANSION_NODE_EXPLICIT) {
472 : : node = next;
473 : : i = 0;
474 : : } else {
475 : 0 : ++i;
476 : : }
477 : : }
478 [ # # ]: 0 : if (next)
479 : : node = next;
480 : 0 : user_pattern_size += sizeof(*item);
481 : : }
482 : 0 : user_pattern_size += sizeof(*item); /* Handle END item. */
483 : 0 : lsize += user_pattern_size;
484 [ # # ]: 0 : if (lsize > size)
485 : : return -EINVAL;
486 : : /* Copy the user pattern in the first entry of the buffer. */
487 : : rte_memcpy(addr, pattern, user_pattern_size);
488 : 0 : addr = (void *)(((uintptr_t)addr) + user_pattern_size);
489 : 0 : buf->entries = 1;
490 : : /* Start expanding. */
491 : : memset(flow_items, 0, sizeof(flow_items));
492 : : user_pattern_size -= sizeof(*item);
493 : : /*
494 : : * Check if the last valid item has spec set, need complete pattern,
495 : : * and the pattern can be used for expansion.
496 : : */
497 : 0 : missed_item.type = mlx5_flow_expand_rss_item_complete(last_expand_item);
498 [ # # ]: 0 : if (missed_item.type == RTE_FLOW_ITEM_TYPE_END) {
499 : : /* Item type END indicates expansion is not required. */
500 : 0 : return lsize;
501 : : }
502 [ # # ]: 0 : if (missed_item.type != RTE_FLOW_ITEM_TYPE_VOID) {
503 : : next = NULL;
504 : : missed = 1;
505 : : i = 0;
506 [ # # # # ]: 0 : while (node->next && node->next[i]) {
507 : 0 : next = &graph[node->next[i]];
508 [ # # ]: 0 : if (next->type == missed_item.type) {
509 : 0 : flow_items[0].type = missed_item.type;
510 : : flow_items[1].type = RTE_FLOW_ITEM_TYPE_END;
511 : 0 : break;
512 : : }
513 [ # # ]: 0 : if (next->node_flags & MLX5_EXPANSION_NODE_EXPLICIT) {
514 : : node = next;
515 : : i = 0;
516 : : } else {
517 : 0 : ++i;
518 : : }
519 : : next = NULL;
520 : : }
521 : : }
522 [ # # ]: 0 : if (next && missed) {
523 : : elt = 2; /* missed item + item end. */
524 : : node = next;
525 : 0 : lsize += elt * sizeof(*item) + user_pattern_size;
526 [ # # ]: 0 : if (lsize > size)
527 : : return -EINVAL;
528 [ # # ]: 0 : if (node->rss_types & types) {
529 : 0 : buf->entry[buf->entries].priority = 1;
530 : 0 : buf->entry[buf->entries].pattern = addr;
531 : 0 : buf->entries++;
532 [ # # ]: 0 : rte_memcpy(addr, buf->entry[0].pattern,
533 : : user_pattern_size);
534 [ # # ]: 0 : addr = (void *)(((uintptr_t)addr) + user_pattern_size);
535 : : rte_memcpy(addr, flow_items, elt * sizeof(*item));
536 : 0 : addr = (void *)(((uintptr_t)addr) +
537 : : elt * sizeof(*item));
538 : : }
539 [ # # ]: 0 : } else if (last_expand_item != NULL) {
540 : 0 : node = mlx5_flow_expand_rss_adjust_node(pattern,
541 : : last_expand_item_idx, graph, node);
542 : : }
543 : : memset(flow_items, 0, sizeof(flow_items));
544 : : next_node = mlx5_flow_expand_rss_skip_explicit(graph,
545 : 0 : node->next);
546 : 0 : stack[stack_pos] = next_node;
547 [ # # ]: 0 : node = next_node ? &graph[*next_node] : NULL;
548 [ # # ]: 0 : while (node) {
549 : 0 : flow_items[stack_pos].type = node->type;
550 [ # # ]: 0 : if (node->rss_types & types) {
551 : : size_t n;
552 : : /*
553 : : * compute the number of items to copy from the
554 : : * expansion and copy it.
555 : : * When the stack_pos is 0, there are 1 element in it,
556 : : * plus the addition END item.
557 : : */
558 : 0 : elt = stack_pos + 2;
559 : 0 : flow_items[stack_pos + 1].type = RTE_FLOW_ITEM_TYPE_END;
560 : 0 : lsize += elt * sizeof(*item) + user_pattern_size;
561 [ # # ]: 0 : if (lsize > size)
562 : : return -EINVAL;
563 : : n = elt * sizeof(*item);
564 : : MLX5_ASSERT((buf->entries) < MLX5_RSS_EXP_ELT_N);
565 : 0 : buf->entry[buf->entries].priority =
566 : 0 : stack_pos + 1 + missed;
567 : 0 : buf->entry[buf->entries].pattern = addr;
568 : 0 : buf->entries++;
569 [ # # ]: 0 : rte_memcpy(addr, buf->entry[0].pattern,
570 : : user_pattern_size);
571 : 0 : addr = (void *)(((uintptr_t)addr) +
572 : : user_pattern_size);
573 [ # # ]: 0 : rte_memcpy(addr, &missed_item,
574 : : missed * sizeof(*item));
575 [ # # ]: 0 : addr = (void *)(((uintptr_t)addr) +
576 : : missed * sizeof(*item));
577 : : rte_memcpy(addr, flow_items, n);
578 : 0 : addr = (void *)(((uintptr_t)addr) + n);
579 : : }
580 : : /* Go deeper. */
581 [ # # ]: 0 : if (!(node->node_flags & MLX5_EXPANSION_NODE_OPTIONAL) &&
582 [ # # ]: 0 : node->next) {
583 : : next_node = mlx5_flow_expand_rss_skip_explicit(graph,
584 : : node->next);
585 [ # # ]: 0 : if (stack_pos++ == MLX5_RSS_EXP_ELT_N) {
586 : 0 : rte_errno = E2BIG;
587 : 0 : return -rte_errno;
588 : : }
589 : 0 : stack[stack_pos] = next_node;
590 [ # # ]: 0 : } else if (*(next_node + 1)) {
591 : : /* Follow up with the next possibility. */
592 : 0 : next_node = mlx5_flow_expand_rss_skip_explicit(graph,
593 : : ++next_node);
594 [ # # ]: 0 : } else if (!stack_pos) {
595 : : /*
596 : : * Completing the traverse over the different paths.
597 : : * The next_node is advanced to the terminator.
598 : : */
599 : 0 : ++next_node;
600 : : } else {
601 : : /* Move to the next path. */
602 [ # # ]: 0 : while (stack_pos) {
603 : 0 : next_node = stack[--stack_pos];
604 : 0 : next_node++;
605 [ # # ]: 0 : if (*next_node)
606 : : break;
607 : : }
608 : : next_node = mlx5_flow_expand_rss_skip_explicit(graph,
609 : : next_node);
610 : 0 : stack[stack_pos] = next_node;
611 : : }
612 [ # # # # ]: 0 : node = next_node && *next_node ? &graph[*next_node] : NULL;
613 : : };
614 : 0 : return lsize;
615 : : }
616 : :
617 : : /**
618 : : * Expand SQN flows into several possible flows according to the Tx queue
619 : : * number
620 : : *
621 : : * @param[in] buf
622 : : * Buffer to store the result expansion.
623 : : * @param[in] size
624 : : * Buffer size in bytes. If 0, @p buf can be NULL.
625 : : * @param[in] pattern
626 : : * User flow pattern.
627 : : * @param[in] sq_specs
628 : : * Buffer to store sq spec.
629 : : *
630 : : * @return
631 : : * 0 for success and negative value for failure
632 : : *
633 : : */
634 : : static int
635 : 0 : mlx5_flow_expand_sqn(struct mlx5_flow_expand_sqn *buf, size_t size,
636 : : const struct rte_flow_item *pattern,
637 : : struct mlx5_rte_flow_item_sq *sq_specs)
638 : : {
639 : : const struct rte_flow_item *item;
640 : : bool port_representor = false;
641 : : size_t user_pattern_size = 0;
642 : : struct rte_eth_dev *dev;
643 : : struct mlx5_priv *priv;
644 : : void *addr = NULL;
645 : : uint16_t port_id;
646 : : size_t lsize;
647 : : int elt = 2;
648 : : uint16_t i;
649 : :
650 : 0 : buf->entries = 0;
651 [ # # ]: 0 : for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
652 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR) {
653 : 0 : const struct rte_flow_item_ethdev *pid_v = item->spec;
654 : :
655 [ # # ]: 0 : if (!pid_v)
656 : : return 0;
657 : 0 : port_id = pid_v->port_id;
658 : : port_representor = true;
659 : : }
660 : 0 : user_pattern_size += sizeof(*item);
661 : : }
662 [ # # ]: 0 : if (!port_representor)
663 : : return 0;
664 : 0 : dev = &rte_eth_devices[port_id];
665 : 0 : priv = dev->data->dev_private;
666 : 0 : buf->entry[0].pattern = (void *)&buf->entry[priv->txqs_n];
667 : 0 : lsize = offsetof(struct mlx5_flow_expand_sqn, entry) +
668 : 0 : sizeof(buf->entry[0]) * priv->txqs_n;
669 [ # # ]: 0 : if (lsize + (user_pattern_size + sizeof(struct rte_flow_item) * elt) * priv->txqs_n > size)
670 : : return -EINVAL;
671 : : addr = buf->entry[0].pattern;
672 [ # # ]: 0 : for (i = 0; i != priv->txqs_n; ++i) {
673 : 0 : struct rte_flow_item pattern_add[] = {
674 : : {
675 : : .type = (enum rte_flow_item_type)
676 : : MLX5_RTE_FLOW_ITEM_TYPE_SQ,
677 : 0 : .spec = &sq_specs[i],
678 : : },
679 : : {
680 : : .type = RTE_FLOW_ITEM_TYPE_END,
681 : : },
682 : : };
683 : 0 : struct mlx5_txq_ctrl *txq = mlx5_txq_get(dev, i);
684 : :
685 [ # # ]: 0 : if (txq == NULL)
686 : 0 : return -EINVAL;
687 : 0 : buf->entry[i].pattern = addr;
688 : 0 : sq_specs[i].queue = mlx5_txq_get_sqn(txq);
689 : 0 : mlx5_txq_release(dev, i);
690 : : rte_memcpy(addr, pattern, user_pattern_size);
691 [ # # ]: 0 : addr = (void *)(((uintptr_t)addr) + user_pattern_size);
692 : : rte_memcpy(addr, pattern_add, sizeof(struct rte_flow_item) * elt);
693 : 0 : addr = (void *)(((uintptr_t)addr) + sizeof(struct rte_flow_item) * elt);
694 : 0 : buf->entries++;
695 : : }
696 : : return 0;
697 : : }
698 : :
699 : : enum mlx5_expansion {
700 : : MLX5_EXPANSION_ROOT,
701 : : MLX5_EXPANSION_ROOT_OUTER,
702 : : MLX5_EXPANSION_OUTER_ETH,
703 : : MLX5_EXPANSION_OUTER_VLAN,
704 : : MLX5_EXPANSION_OUTER_IPV4,
705 : : MLX5_EXPANSION_OUTER_IPV4_UDP,
706 : : MLX5_EXPANSION_OUTER_IPV4_TCP,
707 : : MLX5_EXPANSION_OUTER_IPV4_ESP,
708 : : MLX5_EXPANSION_OUTER_IPV4_ICMP,
709 : : MLX5_EXPANSION_OUTER_IPV6,
710 : : MLX5_EXPANSION_OUTER_IPV6_UDP,
711 : : MLX5_EXPANSION_OUTER_IPV6_TCP,
712 : : MLX5_EXPANSION_OUTER_IPV6_ESP,
713 : : MLX5_EXPANSION_OUTER_IPV6_ICMP6,
714 : : MLX5_EXPANSION_VXLAN,
715 : : MLX5_EXPANSION_STD_VXLAN,
716 : : MLX5_EXPANSION_L3_VXLAN,
717 : : MLX5_EXPANSION_VXLAN_GPE,
718 : : MLX5_EXPANSION_GRE,
719 : : MLX5_EXPANSION_NVGRE,
720 : : MLX5_EXPANSION_GRE_KEY,
721 : : MLX5_EXPANSION_MPLS,
722 : : MLX5_EXPANSION_ETH,
723 : : MLX5_EXPANSION_VLAN,
724 : : MLX5_EXPANSION_IPV4,
725 : : MLX5_EXPANSION_IPV4_UDP,
726 : : MLX5_EXPANSION_IPV4_TCP,
727 : : MLX5_EXPANSION_IPV4_ESP,
728 : : MLX5_EXPANSION_IPV4_ICMP,
729 : : MLX5_EXPANSION_IPV6,
730 : : MLX5_EXPANSION_IPV6_UDP,
731 : : MLX5_EXPANSION_IPV6_TCP,
732 : : MLX5_EXPANSION_IPV6_ESP,
733 : : MLX5_EXPANSION_IPV6_ICMP6,
734 : : MLX5_EXPANSION_IPV6_FRAG_EXT,
735 : : MLX5_EXPANSION_GTP,
736 : : MLX5_EXPANSION_GENEVE,
737 : : };
738 : :
739 : : /** Supported expansion of items. */
740 : : static const struct mlx5_flow_expand_node mlx5_support_expansion[] = {
741 : : [MLX5_EXPANSION_ROOT] = {
742 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
743 : : MLX5_EXPANSION_IPV4,
744 : : MLX5_EXPANSION_IPV6),
745 : : .type = RTE_FLOW_ITEM_TYPE_END,
746 : : },
747 : : [MLX5_EXPANSION_ROOT_OUTER] = {
748 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH,
749 : : MLX5_EXPANSION_OUTER_IPV4,
750 : : MLX5_EXPANSION_OUTER_IPV6),
751 : : .type = RTE_FLOW_ITEM_TYPE_END,
752 : : },
753 : : [MLX5_EXPANSION_OUTER_ETH] = {
754 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_VLAN),
755 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
756 : : .rss_types = 0,
757 : : },
758 : : [MLX5_EXPANSION_OUTER_VLAN] = {
759 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
760 : : MLX5_EXPANSION_OUTER_IPV6),
761 : : .type = RTE_FLOW_ITEM_TYPE_VLAN,
762 : : .node_flags = MLX5_EXPANSION_NODE_EXPLICIT,
763 : : },
764 : : [MLX5_EXPANSION_OUTER_IPV4] = {
765 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT
766 : : (MLX5_EXPANSION_OUTER_IPV4_UDP,
767 : : MLX5_EXPANSION_OUTER_IPV4_TCP,
768 : : MLX5_EXPANSION_OUTER_IPV4_ESP,
769 : : MLX5_EXPANSION_OUTER_IPV4_ICMP,
770 : : MLX5_EXPANSION_GRE,
771 : : MLX5_EXPANSION_NVGRE,
772 : : MLX5_EXPANSION_IPV4,
773 : : MLX5_EXPANSION_IPV6),
774 : : .type = RTE_FLOW_ITEM_TYPE_IPV4,
775 : : .rss_types = RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_FRAG_IPV4 |
776 : : RTE_ETH_RSS_NONFRAG_IPV4_OTHER,
777 : : },
778 : : [MLX5_EXPANSION_OUTER_IPV4_UDP] = {
779 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
780 : : MLX5_EXPANSION_VXLAN_GPE,
781 : : MLX5_EXPANSION_MPLS,
782 : : MLX5_EXPANSION_GENEVE,
783 : : MLX5_EXPANSION_GTP),
784 : : .type = RTE_FLOW_ITEM_TYPE_UDP,
785 : : .rss_types = RTE_ETH_RSS_NONFRAG_IPV4_UDP,
786 : : },
787 : : [MLX5_EXPANSION_OUTER_IPV4_TCP] = {
788 : : .type = RTE_FLOW_ITEM_TYPE_TCP,
789 : : .rss_types = RTE_ETH_RSS_NONFRAG_IPV4_TCP,
790 : : },
791 : : [MLX5_EXPANSION_OUTER_IPV4_ESP] = {
792 : : .type = RTE_FLOW_ITEM_TYPE_ESP,
793 : : .rss_types = RTE_ETH_RSS_ESP,
794 : : },
795 : : [MLX5_EXPANSION_OUTER_IPV4_ICMP] = {
796 : : .type = RTE_FLOW_ITEM_TYPE_ICMP,
797 : : },
798 : : [MLX5_EXPANSION_OUTER_IPV6] = {
799 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT
800 : : (MLX5_EXPANSION_OUTER_IPV6_UDP,
801 : : MLX5_EXPANSION_OUTER_IPV6_TCP,
802 : : MLX5_EXPANSION_OUTER_IPV6_ESP,
803 : : MLX5_EXPANSION_OUTER_IPV6_ICMP6,
804 : : MLX5_EXPANSION_IPV4,
805 : : MLX5_EXPANSION_IPV6,
806 : : MLX5_EXPANSION_GRE,
807 : : MLX5_EXPANSION_NVGRE),
808 : : .type = RTE_FLOW_ITEM_TYPE_IPV6,
809 : : .rss_types = RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_FRAG_IPV6 |
810 : : RTE_ETH_RSS_NONFRAG_IPV6_OTHER,
811 : : },
812 : : [MLX5_EXPANSION_OUTER_IPV6_UDP] = {
813 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
814 : : MLX5_EXPANSION_VXLAN_GPE,
815 : : MLX5_EXPANSION_MPLS,
816 : : MLX5_EXPANSION_GENEVE,
817 : : MLX5_EXPANSION_GTP),
818 : : .type = RTE_FLOW_ITEM_TYPE_UDP,
819 : : .rss_types = RTE_ETH_RSS_NONFRAG_IPV6_UDP,
820 : : },
821 : : [MLX5_EXPANSION_OUTER_IPV6_TCP] = {
822 : : .type = RTE_FLOW_ITEM_TYPE_TCP,
823 : : .rss_types = RTE_ETH_RSS_NONFRAG_IPV6_TCP,
824 : : },
825 : : [MLX5_EXPANSION_OUTER_IPV6_ESP] = {
826 : : .type = RTE_FLOW_ITEM_TYPE_ESP,
827 : : .rss_types = RTE_ETH_RSS_ESP,
828 : : },
829 : : [MLX5_EXPANSION_OUTER_IPV6_ICMP6] = {
830 : : .type = RTE_FLOW_ITEM_TYPE_ICMP6,
831 : : },
832 : : [MLX5_EXPANSION_VXLAN] = {
833 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
834 : : MLX5_EXPANSION_IPV4,
835 : : MLX5_EXPANSION_IPV6),
836 : : .type = RTE_FLOW_ITEM_TYPE_VXLAN,
837 : : },
838 : : [MLX5_EXPANSION_STD_VXLAN] = {
839 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH),
840 : : .type = RTE_FLOW_ITEM_TYPE_VXLAN,
841 : : },
842 : : [MLX5_EXPANSION_L3_VXLAN] = {
843 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
844 : : MLX5_EXPANSION_IPV6),
845 : : .type = RTE_FLOW_ITEM_TYPE_VXLAN,
846 : : },
847 : : [MLX5_EXPANSION_VXLAN_GPE] = {
848 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
849 : : MLX5_EXPANSION_IPV4,
850 : : MLX5_EXPANSION_IPV6),
851 : : .type = RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
852 : : },
853 : : [MLX5_EXPANSION_GRE] = {
854 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
855 : : MLX5_EXPANSION_IPV4,
856 : : MLX5_EXPANSION_IPV6,
857 : : MLX5_EXPANSION_GRE_KEY,
858 : : MLX5_EXPANSION_MPLS),
859 : : .type = RTE_FLOW_ITEM_TYPE_GRE,
860 : : },
861 : : [MLX5_EXPANSION_GRE_KEY] = {
862 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
863 : : MLX5_EXPANSION_IPV6,
864 : : MLX5_EXPANSION_MPLS),
865 : : .type = RTE_FLOW_ITEM_TYPE_GRE_KEY,
866 : : .node_flags = MLX5_EXPANSION_NODE_OPTIONAL,
867 : : },
868 : : [MLX5_EXPANSION_NVGRE] = {
869 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH),
870 : : .type = RTE_FLOW_ITEM_TYPE_NVGRE,
871 : : },
872 : : [MLX5_EXPANSION_MPLS] = {
873 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
874 : : MLX5_EXPANSION_IPV6,
875 : : MLX5_EXPANSION_ETH),
876 : : .type = RTE_FLOW_ITEM_TYPE_MPLS,
877 : : .node_flags = MLX5_EXPANSION_NODE_OPTIONAL,
878 : : },
879 : : [MLX5_EXPANSION_ETH] = {
880 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VLAN),
881 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
882 : : },
883 : : [MLX5_EXPANSION_VLAN] = {
884 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
885 : : MLX5_EXPANSION_IPV6),
886 : : .type = RTE_FLOW_ITEM_TYPE_VLAN,
887 : : .node_flags = MLX5_EXPANSION_NODE_EXPLICIT,
888 : : },
889 : : [MLX5_EXPANSION_IPV4] = {
890 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4_UDP,
891 : : MLX5_EXPANSION_IPV4_TCP,
892 : : MLX5_EXPANSION_IPV4_ESP,
893 : : MLX5_EXPANSION_IPV4_ICMP),
894 : : .type = RTE_FLOW_ITEM_TYPE_IPV4,
895 : : .rss_types = RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_FRAG_IPV4 |
896 : : RTE_ETH_RSS_NONFRAG_IPV4_OTHER,
897 : : },
898 : : [MLX5_EXPANSION_IPV4_UDP] = {
899 : : .type = RTE_FLOW_ITEM_TYPE_UDP,
900 : : .rss_types = RTE_ETH_RSS_NONFRAG_IPV4_UDP,
901 : : },
902 : : [MLX5_EXPANSION_IPV4_TCP] = {
903 : : .type = RTE_FLOW_ITEM_TYPE_TCP,
904 : : .rss_types = RTE_ETH_RSS_NONFRAG_IPV4_TCP,
905 : : },
906 : : [MLX5_EXPANSION_IPV4_ESP] = {
907 : : .type = RTE_FLOW_ITEM_TYPE_ESP,
908 : : .rss_types = RTE_ETH_RSS_ESP,
909 : : },
910 : : [MLX5_EXPANSION_IPV4_ICMP] = {
911 : : .type = RTE_FLOW_ITEM_TYPE_ICMP,
912 : : },
913 : : [MLX5_EXPANSION_IPV6] = {
914 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV6_UDP,
915 : : MLX5_EXPANSION_IPV6_TCP,
916 : : MLX5_EXPANSION_IPV6_ESP,
917 : : MLX5_EXPANSION_IPV6_ICMP6,
918 : : MLX5_EXPANSION_IPV6_FRAG_EXT),
919 : : .type = RTE_FLOW_ITEM_TYPE_IPV6,
920 : : .rss_types = RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_FRAG_IPV6 |
921 : : RTE_ETH_RSS_NONFRAG_IPV6_OTHER,
922 : : },
923 : : [MLX5_EXPANSION_IPV6_UDP] = {
924 : : .type = RTE_FLOW_ITEM_TYPE_UDP,
925 : : .rss_types = RTE_ETH_RSS_NONFRAG_IPV6_UDP,
926 : : },
927 : : [MLX5_EXPANSION_IPV6_TCP] = {
928 : : .type = RTE_FLOW_ITEM_TYPE_TCP,
929 : : .rss_types = RTE_ETH_RSS_NONFRAG_IPV6_TCP,
930 : : },
931 : : [MLX5_EXPANSION_IPV6_ESP] = {
932 : : .type = RTE_FLOW_ITEM_TYPE_ESP,
933 : : .rss_types = RTE_ETH_RSS_ESP,
934 : : },
935 : : [MLX5_EXPANSION_IPV6_FRAG_EXT] = {
936 : : .type = RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT,
937 : : },
938 : : [MLX5_EXPANSION_IPV6_ICMP6] = {
939 : : .type = RTE_FLOW_ITEM_TYPE_ICMP6,
940 : : },
941 : : [MLX5_EXPANSION_GTP] = {
942 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
943 : : MLX5_EXPANSION_IPV6),
944 : : .type = RTE_FLOW_ITEM_TYPE_GTP,
945 : : },
946 : : [MLX5_EXPANSION_GENEVE] = {
947 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
948 : : MLX5_EXPANSION_IPV4,
949 : : MLX5_EXPANSION_IPV6),
950 : : .type = RTE_FLOW_ITEM_TYPE_GENEVE,
951 : : },
952 : : };
953 : :
954 : : static struct rte_flow_action_handle *
955 : : mlx5_action_handle_create(struct rte_eth_dev *dev,
956 : : const struct rte_flow_indir_action_conf *conf,
957 : : const struct rte_flow_action *action,
958 : : struct rte_flow_error *error);
959 : : static int mlx5_action_handle_destroy
960 : : (struct rte_eth_dev *dev,
961 : : struct rte_flow_action_handle *handle,
962 : : struct rte_flow_error *error);
963 : : static int mlx5_action_handle_update
964 : : (struct rte_eth_dev *dev,
965 : : struct rte_flow_action_handle *handle,
966 : : const void *update,
967 : : struct rte_flow_error *error);
968 : : static int mlx5_action_handle_query
969 : : (struct rte_eth_dev *dev,
970 : : const struct rte_flow_action_handle *handle,
971 : : void *data,
972 : : struct rte_flow_error *error);
973 : : static int
974 : : mlx5_flow_tunnel_decap_set(struct rte_eth_dev *dev,
975 : : struct rte_flow_tunnel *app_tunnel,
976 : : struct rte_flow_action **actions,
977 : : uint32_t *num_of_actions,
978 : : struct rte_flow_error *error);
979 : : static int
980 : : mlx5_flow_tunnel_match(struct rte_eth_dev *dev,
981 : : struct rte_flow_tunnel *app_tunnel,
982 : : struct rte_flow_item **items,
983 : : uint32_t *num_of_items,
984 : : struct rte_flow_error *error);
985 : : static int
986 : : mlx5_flow_tunnel_item_release(struct rte_eth_dev *dev,
987 : : struct rte_flow_item *pmd_items,
988 : : uint32_t num_items, struct rte_flow_error *err);
989 : : static int
990 : : mlx5_flow_tunnel_action_release(struct rte_eth_dev *dev,
991 : : struct rte_flow_action *pmd_actions,
992 : : uint32_t num_actions,
993 : : struct rte_flow_error *err);
994 : : static int
995 : : mlx5_flow_tunnel_get_restore_info(struct rte_eth_dev *dev,
996 : : struct rte_mbuf *m,
997 : : struct rte_flow_restore_info *info,
998 : : struct rte_flow_error *err);
999 : : static struct rte_flow_item_flex_handle *
1000 : : mlx5_flow_flex_item_create(struct rte_eth_dev *dev,
1001 : : const struct rte_flow_item_flex_conf *conf,
1002 : : struct rte_flow_error *error);
1003 : : static int
1004 : : mlx5_flow_flex_item_release(struct rte_eth_dev *dev,
1005 : : const struct rte_flow_item_flex_handle *handle,
1006 : : struct rte_flow_error *error);
1007 : : static int
1008 : : mlx5_flow_info_get(struct rte_eth_dev *dev,
1009 : : struct rte_flow_port_info *port_info,
1010 : : struct rte_flow_queue_info *queue_info,
1011 : : struct rte_flow_error *error);
1012 : : static int
1013 : : mlx5_flow_port_configure(struct rte_eth_dev *dev,
1014 : : const struct rte_flow_port_attr *port_attr,
1015 : : uint16_t nb_queue,
1016 : : const struct rte_flow_queue_attr *queue_attr[],
1017 : : struct rte_flow_error *err);
1018 : :
1019 : : static struct rte_flow_pattern_template *
1020 : : mlx5_flow_pattern_template_create(struct rte_eth_dev *dev,
1021 : : const struct rte_flow_pattern_template_attr *attr,
1022 : : const struct rte_flow_item items[],
1023 : : struct rte_flow_error *error);
1024 : :
1025 : : static int
1026 : : mlx5_flow_pattern_template_destroy(struct rte_eth_dev *dev,
1027 : : struct rte_flow_pattern_template *template,
1028 : : struct rte_flow_error *error);
1029 : : static struct rte_flow_actions_template *
1030 : : mlx5_flow_actions_template_create(struct rte_eth_dev *dev,
1031 : : const struct rte_flow_actions_template_attr *attr,
1032 : : const struct rte_flow_action actions[],
1033 : : const struct rte_flow_action masks[],
1034 : : struct rte_flow_error *error);
1035 : : static int
1036 : : mlx5_flow_actions_template_destroy(struct rte_eth_dev *dev,
1037 : : struct rte_flow_actions_template *template,
1038 : : struct rte_flow_error *error);
1039 : :
1040 : : static struct rte_flow_template_table *
1041 : : mlx5_flow_table_create(struct rte_eth_dev *dev,
1042 : : const struct rte_flow_template_table_attr *attr,
1043 : : struct rte_flow_pattern_template *item_templates[],
1044 : : uint8_t nb_item_templates,
1045 : : struct rte_flow_actions_template *action_templates[],
1046 : : uint8_t nb_action_templates,
1047 : : struct rte_flow_error *error);
1048 : : static int
1049 : : mlx5_flow_table_destroy(struct rte_eth_dev *dev,
1050 : : struct rte_flow_template_table *table,
1051 : : struct rte_flow_error *error);
1052 : : static int
1053 : : mlx5_flow_group_set_miss_actions(struct rte_eth_dev *dev,
1054 : : uint32_t group_id,
1055 : : const struct rte_flow_group_attr *attr,
1056 : : const struct rte_flow_action actions[],
1057 : : struct rte_flow_error *error);
1058 : :
1059 : : static int
1060 : : mlx5_action_handle_query_update(struct rte_eth_dev *dev,
1061 : : struct rte_flow_action_handle *handle,
1062 : : const void *update, void *query,
1063 : : enum rte_flow_query_update_mode qu_mode,
1064 : : struct rte_flow_error *error);
1065 : :
1066 : : static struct rte_flow_action_list_handle *
1067 : : mlx5_action_list_handle_create(struct rte_eth_dev *dev,
1068 : : const struct rte_flow_indir_action_conf *conf,
1069 : : const struct rte_flow_action *actions,
1070 : : struct rte_flow_error *error);
1071 : :
1072 : : static int
1073 : : mlx5_action_list_handle_destroy(struct rte_eth_dev *dev,
1074 : : struct rte_flow_action_list_handle *handle,
1075 : : struct rte_flow_error *error);
1076 : :
1077 : : static int
1078 : : mlx5_flow_action_list_handle_query_update(struct rte_eth_dev *dev,
1079 : : const
1080 : : struct rte_flow_action_list_handle *handle,
1081 : : const void **update, void **query,
1082 : : enum rte_flow_query_update_mode mode,
1083 : : struct rte_flow_error *error);
1084 : :
1085 : : static int
1086 : : mlx5_flow_calc_table_hash(struct rte_eth_dev *dev,
1087 : : const struct rte_flow_template_table *table,
1088 : : const struct rte_flow_item pattern[],
1089 : : uint8_t pattern_template_index,
1090 : : uint32_t *hash, struct rte_flow_error *error);
1091 : : static int
1092 : : mlx5_flow_calc_encap_hash(struct rte_eth_dev *dev,
1093 : : const struct rte_flow_item pattern[],
1094 : : enum rte_flow_encap_hash_field dest_field,
1095 : : uint8_t *hash,
1096 : : struct rte_flow_error *error);
1097 : :
1098 : : static int
1099 : : mlx5_template_table_resize(struct rte_eth_dev *dev,
1100 : : struct rte_flow_template_table *table,
1101 : : uint32_t nb_rules, struct rte_flow_error *error);
1102 : : static int
1103 : : mlx5_flow_async_update_resized(struct rte_eth_dev *dev, uint32_t queue,
1104 : : const struct rte_flow_op_attr *attr,
1105 : : struct rte_flow *rule, void *user_data,
1106 : : struct rte_flow_error *error);
1107 : : static int
1108 : : mlx5_table_resize_complete(struct rte_eth_dev *dev,
1109 : : struct rte_flow_template_table *table,
1110 : : struct rte_flow_error *error);
1111 : :
1112 : : static const struct rte_flow_ops mlx5_flow_ops = {
1113 : : .validate = mlx5_flow_validate,
1114 : : .create = mlx5_flow_create,
1115 : : .destroy = mlx5_flow_destroy,
1116 : : .flush = mlx5_flow_flush,
1117 : : .isolate = mlx5_flow_isolate,
1118 : : .query = mlx5_flow_query,
1119 : : .dev_dump = mlx5_flow_dev_dump,
1120 : : .get_q_aged_flows = mlx5_flow_get_q_aged_flows,
1121 : : .get_aged_flows = mlx5_flow_get_aged_flows,
1122 : : .action_handle_create = mlx5_action_handle_create,
1123 : : .action_handle_destroy = mlx5_action_handle_destroy,
1124 : : .action_handle_update = mlx5_action_handle_update,
1125 : : .action_handle_query = mlx5_action_handle_query,
1126 : : .action_handle_query_update = mlx5_action_handle_query_update,
1127 : : .action_list_handle_create = mlx5_action_list_handle_create,
1128 : : .action_list_handle_destroy = mlx5_action_list_handle_destroy,
1129 : : .tunnel_decap_set = mlx5_flow_tunnel_decap_set,
1130 : : .tunnel_match = mlx5_flow_tunnel_match,
1131 : : .tunnel_action_decap_release = mlx5_flow_tunnel_action_release,
1132 : : .tunnel_item_release = mlx5_flow_tunnel_item_release,
1133 : : .get_restore_info = mlx5_flow_tunnel_get_restore_info,
1134 : : .flex_item_create = mlx5_flow_flex_item_create,
1135 : : .flex_item_release = mlx5_flow_flex_item_release,
1136 : : .info_get = mlx5_flow_info_get,
1137 : : .pick_transfer_proxy = mlx5_flow_pick_transfer_proxy,
1138 : : .configure = mlx5_flow_port_configure,
1139 : : .pattern_template_create = mlx5_flow_pattern_template_create,
1140 : : .pattern_template_destroy = mlx5_flow_pattern_template_destroy,
1141 : : .actions_template_create = mlx5_flow_actions_template_create,
1142 : : .actions_template_destroy = mlx5_flow_actions_template_destroy,
1143 : : .template_table_create = mlx5_flow_table_create,
1144 : : .template_table_destroy = mlx5_flow_table_destroy,
1145 : : .group_set_miss_actions = mlx5_flow_group_set_miss_actions,
1146 : : .action_list_handle_query_update =
1147 : : mlx5_flow_action_list_handle_query_update,
1148 : : .flow_calc_table_hash = mlx5_flow_calc_table_hash,
1149 : : .flow_calc_encap_hash = mlx5_flow_calc_encap_hash,
1150 : : .flow_template_table_resize = mlx5_template_table_resize,
1151 : : .flow_update_resized = mlx5_flow_async_update_resized,
1152 : : .flow_template_table_resize_complete = mlx5_table_resize_complete,
1153 : : };
1154 : :
1155 : : /* Tunnel information. */
1156 : : struct mlx5_flow_tunnel_info {
1157 : : uint64_t tunnel; /**< Tunnel bit (see MLX5_FLOW_*). */
1158 : : uint32_t ptype; /**< Tunnel Ptype (see RTE_PTYPE_*). */
1159 : : };
1160 : :
1161 : : static struct mlx5_flow_tunnel_info tunnels_info[] = {
1162 : : {
1163 : : .tunnel = MLX5_FLOW_LAYER_VXLAN,
1164 : : .ptype = RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_L4_UDP,
1165 : : },
1166 : : {
1167 : : .tunnel = MLX5_FLOW_LAYER_GENEVE,
1168 : : .ptype = RTE_PTYPE_TUNNEL_GENEVE | RTE_PTYPE_L4_UDP,
1169 : : },
1170 : : {
1171 : : .tunnel = MLX5_FLOW_LAYER_VXLAN_GPE,
1172 : : .ptype = RTE_PTYPE_TUNNEL_VXLAN_GPE | RTE_PTYPE_L4_UDP,
1173 : : },
1174 : : {
1175 : : .tunnel = MLX5_FLOW_LAYER_GRE,
1176 : : .ptype = RTE_PTYPE_TUNNEL_GRE,
1177 : : },
1178 : : {
1179 : : .tunnel = MLX5_FLOW_LAYER_MPLS | MLX5_FLOW_LAYER_OUTER_L4_UDP,
1180 : : .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_UDP | RTE_PTYPE_L4_UDP,
1181 : : },
1182 : : {
1183 : : .tunnel = MLX5_FLOW_LAYER_MPLS,
1184 : : .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE,
1185 : : },
1186 : : {
1187 : : .tunnel = MLX5_FLOW_LAYER_NVGRE,
1188 : : .ptype = RTE_PTYPE_TUNNEL_NVGRE,
1189 : : },
1190 : : {
1191 : : .tunnel = MLX5_FLOW_LAYER_IPIP,
1192 : : .ptype = RTE_PTYPE_TUNNEL_IP,
1193 : : },
1194 : : {
1195 : : .tunnel = MLX5_FLOW_LAYER_IPV6_ENCAP,
1196 : : .ptype = RTE_PTYPE_TUNNEL_IP,
1197 : : },
1198 : : {
1199 : : .tunnel = MLX5_FLOW_LAYER_GTP,
1200 : : .ptype = RTE_PTYPE_TUNNEL_GTPU,
1201 : : },
1202 : : };
1203 : :
1204 : :
1205 : :
1206 : : /**
1207 : : * Translate tag ID to register.
1208 : : *
1209 : : * @param[in] dev
1210 : : * Pointer to the Ethernet device structure.
1211 : : * @param[in] feature
1212 : : * The feature that request the register.
1213 : : * @param[in] id
1214 : : * The request register ID.
1215 : : * @param[out] error
1216 : : * Error description in case of any.
1217 : : *
1218 : : * @return
1219 : : * The request register on success, a negative errno
1220 : : * value otherwise and rte_errno is set.
1221 : : */
1222 : : int
1223 : 0 : mlx5_flow_get_reg_id(struct rte_eth_dev *dev,
1224 : : enum mlx5_feature_name feature,
1225 : : uint32_t id,
1226 : : struct rte_flow_error *error)
1227 : : {
1228 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1229 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
1230 : : struct mlx5_dev_registers *reg = &priv->sh->registers;
1231 : : enum modify_reg start_reg;
1232 : : bool skip_mtr_reg = false;
1233 : :
1234 [ # # # # : 0 : switch (feature) {
# # # # #
# # ]
1235 : : case MLX5_HAIRPIN_RX:
1236 : : return REG_B;
1237 : 0 : case MLX5_HAIRPIN_TX:
1238 : 0 : return REG_A;
1239 : 0 : case MLX5_METADATA_RX:
1240 [ # # # # : 0 : switch (config->dv_xmeta_en) {
# ]
1241 : : case MLX5_XMETA_MODE_LEGACY:
1242 : : return REG_B;
1243 : 0 : case MLX5_XMETA_MODE_META16:
1244 : 0 : return REG_C_0;
1245 : 0 : case MLX5_XMETA_MODE_META32:
1246 : 0 : return REG_C_1;
1247 : 0 : case MLX5_XMETA_MODE_META32_HWS:
1248 : 0 : return REG_C_1;
1249 : : }
1250 : : break;
1251 : 0 : case MLX5_METADATA_TX:
1252 [ # # ]: 0 : if (config->dv_flow_en == 2 && config->dv_xmeta_en == MLX5_XMETA_MODE_META32_HWS) {
1253 : : return REG_C_1;
1254 : : } else {
1255 : 0 : return REG_A;
1256 : : }
1257 : 0 : case MLX5_METADATA_FDB:
1258 [ # # # # : 0 : switch (config->dv_xmeta_en) {
# ]
1259 : : case MLX5_XMETA_MODE_LEGACY:
1260 : : return REG_NON;
1261 : 0 : case MLX5_XMETA_MODE_META16:
1262 : 0 : return REG_C_0;
1263 : 0 : case MLX5_XMETA_MODE_META32:
1264 : 0 : return REG_C_1;
1265 : 0 : case MLX5_XMETA_MODE_META32_HWS:
1266 : 0 : return REG_C_1;
1267 : : }
1268 : : break;
1269 : 0 : case MLX5_FLOW_MARK:
1270 [ # # # # ]: 0 : switch (config->dv_xmeta_en) {
1271 : : case MLX5_XMETA_MODE_LEGACY:
1272 : : case MLX5_XMETA_MODE_META32_HWS:
1273 : : return REG_NON;
1274 : 0 : case MLX5_XMETA_MODE_META16:
1275 : 0 : return REG_C_1;
1276 : 0 : case MLX5_XMETA_MODE_META32:
1277 : 0 : return REG_C_0;
1278 : : }
1279 : : break;
1280 : 0 : case MLX5_MTR_ID:
1281 : : /*
1282 : : * If meter color and meter id share one register, flow match
1283 : : * should use the meter color register for match.
1284 : : */
1285 [ # # ]: 0 : if (priv->mtr_reg_share)
1286 : 0 : return reg->aso_reg;
1287 : : else
1288 [ # # ]: 0 : return reg->aso_reg != REG_C_2 ? REG_C_2 :
1289 : : REG_C_3;
1290 : 0 : case MLX5_MTR_COLOR:
1291 : : case MLX5_ASO_FLOW_HIT:
1292 : : case MLX5_ASO_CONNTRACK:
1293 : : case MLX5_SAMPLE_ID:
1294 : : /* All features use the same REG_C. */
1295 : : MLX5_ASSERT(reg->aso_reg != REG_NON);
1296 : 0 : return reg->aso_reg;
1297 : 0 : case MLX5_COPY_MARK:
1298 : : /*
1299 : : * Metadata COPY_MARK register using is in meter suffix sub
1300 : : * flow while with meter. It's safe to share the same register.
1301 : : */
1302 [ # # ]: 0 : return reg->aso_reg != REG_C_2 ? REG_C_2 : REG_C_3;
1303 : 0 : case MLX5_APP_TAG:
1304 : : /*
1305 : : * If meter is enable, it will engage the register for color
1306 : : * match and flow match. If meter color match is not using the
1307 : : * REG_C_2, need to skip the REG_C_x be used by meter color
1308 : : * match.
1309 : : * If meter is disable, free to use all available registers.
1310 : : */
1311 [ # # ]: 0 : start_reg = reg->aso_reg != REG_C_2 ? REG_C_2 :
1312 [ # # ]: 0 : (priv->mtr_reg_share ? REG_C_3 : REG_C_4);
1313 [ # # # # ]: 0 : skip_mtr_reg = !!(priv->mtr_en && start_reg == REG_C_2);
1314 [ # # ]: 0 : if (id > (uint32_t)(REG_C_7 - start_reg))
1315 : 0 : return rte_flow_error_set(error, EINVAL,
1316 : : RTE_FLOW_ERROR_TYPE_ITEM,
1317 : : NULL, "invalid tag id");
1318 [ # # ]: 0 : if (priv->sh->flow_mreg_c[id + start_reg - REG_C_0] == REG_NON)
1319 : 0 : return rte_flow_error_set(error, ENOTSUP,
1320 : : RTE_FLOW_ERROR_TYPE_ITEM,
1321 : : NULL, "unsupported tag id");
1322 : : /*
1323 : : * This case means meter is using the REG_C_x great than 2.
1324 : : * Take care not to conflict with meter color REG_C_x.
1325 : : * If the available index REG_C_y >= REG_C_x, skip the
1326 : : * color register.
1327 : : */
1328 [ # # # # ]: 0 : if (skip_mtr_reg && priv->sh->flow_mreg_c
1329 : : [id + start_reg - REG_C_0] >= reg->aso_reg) {
1330 [ # # ]: 0 : if (id >= (uint32_t)(REG_C_7 - start_reg))
1331 : 0 : return rte_flow_error_set(error, EINVAL,
1332 : : RTE_FLOW_ERROR_TYPE_ITEM,
1333 : : NULL, "invalid tag id");
1334 : 0 : if (priv->sh->flow_mreg_c
1335 [ # # ]: 0 : [id + 1 + start_reg - REG_C_0] != REG_NON)
1336 : : return priv->sh->flow_mreg_c
1337 : 0 : [id + 1 + start_reg - REG_C_0];
1338 : 0 : return rte_flow_error_set(error, ENOTSUP,
1339 : : RTE_FLOW_ERROR_TYPE_ITEM,
1340 : : NULL, "unsupported tag id");
1341 : : }
1342 : 0 : return priv->sh->flow_mreg_c[id + start_reg - REG_C_0];
1343 : : }
1344 : : MLX5_ASSERT(false);
1345 : 0 : return rte_flow_error_set(error, EINVAL,
1346 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1347 : : NULL, "invalid feature name");
1348 : : }
1349 : :
1350 : : /**
1351 : : * Check extensive flow metadata register support.
1352 : : *
1353 : : * @param dev
1354 : : * Pointer to rte_eth_dev structure.
1355 : : *
1356 : : * @return
1357 : : * True if device supports extensive flow metadata register, otherwise false.
1358 : : */
1359 : : bool
1360 : 0 : mlx5_flow_ext_mreg_supported(struct rte_eth_dev *dev)
1361 : : {
1362 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1363 : :
1364 : : /*
1365 : : * Having available reg_c can be regarded inclusively as supporting
1366 : : * extensive flow metadata register, which could mean,
1367 : : * - metadata register copy action by modify header.
1368 : : * - 16 modify header actions is supported.
1369 : : * - reg_c's are preserved across different domain (FDB and NIC) on
1370 : : * packet loopback by flow lookup miss.
1371 : : */
1372 : 0 : return priv->sh->flow_mreg_c[2] != REG_NON;
1373 : : }
1374 : :
1375 : : /**
1376 : : * Get the lowest priority.
1377 : : *
1378 : : * @param[in] dev
1379 : : * Pointer to the Ethernet device structure.
1380 : : * @param[in] attributes
1381 : : * Pointer to device flow rule attributes.
1382 : : *
1383 : : * @return
1384 : : * The value of lowest priority of flow.
1385 : : */
1386 : : uint32_t
1387 : 0 : mlx5_get_lowest_priority(struct rte_eth_dev *dev,
1388 : : const struct rte_flow_attr *attr)
1389 : : {
1390 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1391 : :
1392 [ # # # # : 0 : if (!attr->group && !(attr->transfer && priv->fdb_def_rule))
# # ]
1393 : 0 : return priv->sh->flow_max_priority - 2;
1394 : : return MLX5_NON_ROOT_FLOW_MAX_PRIO - 1;
1395 : : }
1396 : :
1397 : : /**
1398 : : * Calculate matcher priority of the flow.
1399 : : *
1400 : : * @param[in] dev
1401 : : * Pointer to the Ethernet device structure.
1402 : : * @param[in] attr
1403 : : * Pointer to device flow rule attributes.
1404 : : * @param[in] subpriority
1405 : : * The priority based on the items.
1406 : : * @param[in] external
1407 : : * Flow is user flow.
1408 : : * @return
1409 : : * The matcher priority of the flow.
1410 : : */
1411 : : uint16_t
1412 : 0 : mlx5_get_matcher_priority(struct rte_eth_dev *dev,
1413 : : const struct rte_flow_attr *attr,
1414 : : uint32_t subpriority, bool external)
1415 : : {
1416 : 0 : uint16_t priority = (uint16_t)attr->priority;
1417 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1418 : :
1419 : : /* NIC root rules */
1420 [ # # # # ]: 0 : if (!attr->group && !attr->transfer) {
1421 [ # # ]: 0 : if (attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)
1422 : 0 : priority = priv->sh->flow_max_priority - 1;
1423 : 0 : return mlx5_os_flow_adjust_priority(dev, priority, subpriority);
1424 : : /* FDB root rules */
1425 [ # # # # : 0 : } else if (attr->transfer && (!external || !priv->fdb_def_rule) &&
# # # # ]
1426 [ # # ]: 0 : attr->group == 0 &&
1427 : : attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR) {
1428 : 0 : return (priv->sh->flow_max_priority - 1) * 3;
1429 : : }
1430 [ # # ]: 0 : if (attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)
1431 : : priority = MLX5_NON_ROOT_FLOW_MAX_PRIO;
1432 : 0 : return priority * 3 + subpriority;
1433 : : }
1434 : :
1435 : : /**
1436 : : * Verify the @p item specifications (spec, last, mask) are compatible with the
1437 : : * NIC capabilities.
1438 : : *
1439 : : * @param[in] item
1440 : : * Item specification.
1441 : : * @param[in] mask
1442 : : * @p item->mask or flow default bit-masks.
1443 : : * @param[in] nic_mask
1444 : : * Bit-masks covering supported fields by the NIC to compare with user mask.
1445 : : * @param[in] size
1446 : : * Bit-masks size in bytes.
1447 : : * @param[in] range_accepted
1448 : : * True if range of values is accepted for specific fields, false otherwise.
1449 : : * @param[out] error
1450 : : * Pointer to error structure.
1451 : : *
1452 : : * @return
1453 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1454 : : */
1455 : : int
1456 : 0 : mlx5_flow_item_acceptable(const struct rte_eth_dev *dev,
1457 : : const struct rte_flow_item *item,
1458 : : const uint8_t *mask,
1459 : : const uint8_t *nic_mask,
1460 : : unsigned int size,
1461 : : bool range_accepted,
1462 : : struct rte_flow_error *error)
1463 : : {
1464 : : unsigned int i;
1465 : :
1466 : : MLX5_ASSERT(nic_mask);
1467 [ # # ]: 0 : for (i = 0; i < size; ++i)
1468 [ # # ]: 0 : if ((nic_mask[i] | mask[i]) != nic_mask[i])
1469 : 0 : return rte_flow_error_set(error, ENOTSUP,
1470 : : RTE_FLOW_ERROR_TYPE_ITEM,
1471 : : item,
1472 : : "mask enables non supported"
1473 : : " bits");
1474 [ # # ]: 0 : if (mlx5_hws_active(dev))
1475 : : return 0;
1476 [ # # # # : 0 : if (!item->spec && (item->mask || item->last))
# # ]
1477 : 0 : return rte_flow_error_set(error, EINVAL,
1478 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
1479 : : "mask/last without a spec is not"
1480 : : " supported");
1481 [ # # # # : 0 : if (item->spec && item->last && !range_accepted) {
# # ]
1482 : 0 : uint8_t *spec = alloca(size);
1483 : 0 : uint8_t *last = alloca(size);
1484 : : unsigned int i;
1485 : : int ret;
1486 : :
1487 [ # # ]: 0 : for (i = 0; i < size; ++i) {
1488 : 0 : spec[i] = ((const uint8_t *)item->spec)[i] & mask[i];
1489 : 0 : last[i] = ((const uint8_t *)item->last)[i] & mask[i];
1490 : : }
1491 : 0 : ret = memcmp(spec, last, size);
1492 [ # # ]: 0 : if (ret != 0)
1493 : 0 : return rte_flow_error_set(error, EINVAL,
1494 : : RTE_FLOW_ERROR_TYPE_ITEM,
1495 : : item,
1496 : : "range is not valid");
1497 : : }
1498 : : return 0;
1499 : : }
1500 : :
1501 : : /**
1502 : : * Adjust the hash fields according to the @p flow information.
1503 : : *
1504 : : * @param[in] dev_flow.
1505 : : * Pointer to the mlx5_flow.
1506 : : * @param[in] tunnel
1507 : : * 1 when the hash field is for a tunnel item.
1508 : : * @param[in] layer_types
1509 : : * RTE_ETH_RSS_* types.
1510 : : * @param[in] hash_fields
1511 : : * Item hash fields.
1512 : : *
1513 : : * @return
1514 : : * The hash fields that should be used.
1515 : : */
1516 : : uint64_t
1517 : 0 : mlx5_flow_hashfields_adjust(struct mlx5_flow_rss_desc *rss_desc,
1518 : : int tunnel __rte_unused, uint64_t layer_types,
1519 : : uint64_t hash_fields)
1520 : : {
1521 : : #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1522 : 0 : int rss_request_inner = rss_desc->level >= 2;
1523 : :
1524 : : /* Check RSS hash level for tunnel. */
1525 [ # # ]: 0 : if (tunnel && rss_request_inner)
1526 : 0 : hash_fields |= IBV_RX_HASH_INNER;
1527 [ # # ]: 0 : else if (tunnel || rss_request_inner)
1528 : : return 0;
1529 : : #endif
1530 : : /* Check if requested layer matches RSS hash fields. */
1531 [ # # ]: 0 : if (!(rss_desc->types & layer_types))
1532 : 0 : return 0;
1533 : : return hash_fields;
1534 : : }
1535 : :
1536 : : /**
1537 : : * Lookup and set the ptype in the data Rx part. A single Ptype can be used,
1538 : : * if several tunnel rules are used on this queue, the tunnel ptype will be
1539 : : * cleared.
1540 : : *
1541 : : * @param rxq_ctrl
1542 : : * Rx queue to update.
1543 : : */
1544 : : static void
1545 : : flow_rxq_tunnel_ptype_update(struct mlx5_rxq_ctrl *rxq_ctrl)
1546 : : {
1547 : : unsigned int i;
1548 : : uint32_t tunnel_ptype = 0;
1549 : :
1550 : : /* Look up for the ptype to use. */
1551 [ # # # # ]: 0 : for (i = 0; i != MLX5_FLOW_TUNNEL; ++i) {
1552 [ # # # # ]: 0 : if (!rxq_ctrl->flow_tunnels_n[i])
1553 : 0 : continue;
1554 [ # # # # ]: 0 : if (!tunnel_ptype) {
1555 : 0 : tunnel_ptype = tunnels_info[i].ptype;
1556 : : } else {
1557 : : tunnel_ptype = 0;
1558 : : break;
1559 : : }
1560 : : }
1561 : 0 : rxq_ctrl->rxq.tunnel = tunnel_ptype;
1562 : 0 : }
1563 : :
1564 : : /**
1565 : : * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) according to the device
1566 : : * flow.
1567 : : *
1568 : : * @param[in] dev
1569 : : * Pointer to the Ethernet device structure.
1570 : : * @param[in] dev_handle
1571 : : * Pointer to device flow handle structure.
1572 : : */
1573 : : void
1574 : 0 : flow_drv_rxq_flags_set(struct rte_eth_dev *dev,
1575 : : struct mlx5_flow_handle *dev_handle)
1576 : : {
1577 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1578 : 0 : const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1579 : : struct mlx5_ind_table_obj *ind_tbl = NULL;
1580 : : unsigned int i;
1581 : :
1582 [ # # ]: 0 : if (dev_handle->fate_action == MLX5_FLOW_FATE_QUEUE) {
1583 : : struct mlx5_hrxq *hrxq;
1584 : :
1585 : 0 : hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1586 : : dev_handle->rix_hrxq);
1587 [ # # ]: 0 : if (hrxq)
1588 : 0 : ind_tbl = hrxq->ind_table;
1589 [ # # ]: 0 : } else if (dev_handle->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
1590 : : struct mlx5_shared_action_rss *shared_rss;
1591 : :
1592 : 0 : shared_rss = mlx5_ipool_get
1593 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
1594 : : dev_handle->rix_srss);
1595 [ # # ]: 0 : if (shared_rss)
1596 : 0 : ind_tbl = shared_rss->ind_tbl;
1597 : : }
1598 [ # # ]: 0 : if (!ind_tbl)
1599 : 0 : return;
1600 [ # # ]: 0 : for (i = 0; i != ind_tbl->queues_n; ++i) {
1601 [ # # ]: 0 : int idx = ind_tbl->queues[i];
1602 : : struct mlx5_rxq_ctrl *rxq_ctrl;
1603 : :
1604 [ # # ]: 0 : if (mlx5_is_external_rxq(dev, idx))
1605 : 0 : continue;
1606 : 0 : rxq_ctrl = mlx5_rxq_ctrl_get(dev, idx);
1607 : : MLX5_ASSERT(rxq_ctrl != NULL);
1608 [ # # ]: 0 : if (rxq_ctrl == NULL)
1609 : 0 : continue;
1610 : : /*
1611 : : * To support metadata register copy on Tx loopback,
1612 : : * this must be always enabled (metadata may arive
1613 : : * from other port - not from local flows only.
1614 : : */
1615 [ # # ]: 0 : if (tunnel) {
1616 : : unsigned int j;
1617 : :
1618 : : /* Increase the counter matching the flow. */
1619 [ # # ]: 0 : for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1620 : 0 : if ((tunnels_info[j].tunnel &
1621 [ # # ]: 0 : dev_handle->layers) ==
1622 : : tunnels_info[j].tunnel) {
1623 : 0 : rxq_ctrl->flow_tunnels_n[j]++;
1624 : 0 : break;
1625 : : }
1626 : : }
1627 : : flow_rxq_tunnel_ptype_update(rxq_ctrl);
1628 : : }
1629 : : }
1630 : : }
1631 : :
1632 : : static void
1633 : 0 : flow_rxq_mark_flag_set(struct rte_eth_dev *dev)
1634 : : {
1635 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1636 : : struct mlx5_rxq_ctrl *rxq_ctrl;
1637 : : uint16_t port_id;
1638 : :
1639 [ # # ]: 0 : if (priv->sh->shared_mark_enabled)
1640 : : return;
1641 [ # # ]: 0 : if (priv->master || priv->representor) {
1642 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port_id, dev->device) {
1643 : 0 : struct mlx5_priv *opriv =
1644 : 0 : rte_eth_devices[port_id].data->dev_private;
1645 : :
1646 [ # # ]: 0 : if (!opriv ||
1647 [ # # ]: 0 : opriv->sh != priv->sh ||
1648 [ # # # # ]: 0 : opriv->domain_id != priv->domain_id ||
1649 : : opriv->mark_enabled)
1650 : 0 : continue;
1651 [ # # ]: 0 : LIST_FOREACH(rxq_ctrl, &opriv->rxqsctrl, next) {
1652 : 0 : rxq_ctrl->rxq.mark = 1;
1653 : : }
1654 : 0 : opriv->mark_enabled = 1;
1655 : : }
1656 : : } else {
1657 [ # # ]: 0 : LIST_FOREACH(rxq_ctrl, &priv->rxqsctrl, next) {
1658 : 0 : rxq_ctrl->rxq.mark = 1;
1659 : : }
1660 : 0 : priv->mark_enabled = 1;
1661 : : }
1662 : 0 : priv->sh->shared_mark_enabled = 1;
1663 : : }
1664 : :
1665 : : /**
1666 : : * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) for a flow
1667 : : *
1668 : : * @param[in] dev
1669 : : * Pointer to the Ethernet device structure.
1670 : : * @param[in] flow
1671 : : * Pointer to flow structure.
1672 : : */
1673 : : static void
1674 : 0 : flow_rxq_flags_set(struct rte_eth_dev *dev, struct rte_flow *flow)
1675 : : {
1676 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1677 : : uint32_t handle_idx;
1678 : : struct mlx5_flow_handle *dev_handle;
1679 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
1680 : :
1681 : : MLX5_ASSERT(wks);
1682 [ # # ]: 0 : if (wks->mark)
1683 : 0 : flow_rxq_mark_flag_set(dev);
1684 [ # # # # : 0 : SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
# # ]
1685 : : handle_idx, dev_handle, next)
1686 : 0 : flow_drv_rxq_flags_set(dev, dev_handle);
1687 : 0 : }
1688 : :
1689 : : /**
1690 : : * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1691 : : * device flow if no other flow uses it with the same kind of request.
1692 : : *
1693 : : * @param dev
1694 : : * Pointer to Ethernet device.
1695 : : * @param[in] dev_handle
1696 : : * Pointer to the device flow handle structure.
1697 : : */
1698 : : static void
1699 : 0 : flow_drv_rxq_flags_trim(struct rte_eth_dev *dev,
1700 : : struct mlx5_flow_handle *dev_handle)
1701 : : {
1702 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1703 : 0 : const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1704 : : struct mlx5_ind_table_obj *ind_tbl = NULL;
1705 : : unsigned int i;
1706 : :
1707 [ # # ]: 0 : if (dev_handle->fate_action == MLX5_FLOW_FATE_QUEUE) {
1708 : : struct mlx5_hrxq *hrxq;
1709 : :
1710 : 0 : hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1711 : : dev_handle->rix_hrxq);
1712 [ # # ]: 0 : if (hrxq)
1713 : 0 : ind_tbl = hrxq->ind_table;
1714 [ # # ]: 0 : } else if (dev_handle->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
1715 : : struct mlx5_shared_action_rss *shared_rss;
1716 : :
1717 : 0 : shared_rss = mlx5_ipool_get
1718 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
1719 : : dev_handle->rix_srss);
1720 [ # # ]: 0 : if (shared_rss)
1721 : 0 : ind_tbl = shared_rss->ind_tbl;
1722 : : }
1723 [ # # ]: 0 : if (!ind_tbl)
1724 : 0 : return;
1725 : : MLX5_ASSERT(dev->data->dev_started);
1726 [ # # ]: 0 : for (i = 0; i != ind_tbl->queues_n; ++i) {
1727 [ # # ]: 0 : int idx = ind_tbl->queues[i];
1728 : : struct mlx5_rxq_ctrl *rxq_ctrl;
1729 : :
1730 [ # # ]: 0 : if (mlx5_is_external_rxq(dev, idx))
1731 : 0 : continue;
1732 : 0 : rxq_ctrl = mlx5_rxq_ctrl_get(dev, idx);
1733 : : MLX5_ASSERT(rxq_ctrl != NULL);
1734 [ # # ]: 0 : if (rxq_ctrl == NULL)
1735 : 0 : continue;
1736 [ # # ]: 0 : if (tunnel) {
1737 : : unsigned int j;
1738 : :
1739 : : /* Decrease the counter matching the flow. */
1740 [ # # ]: 0 : for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1741 : 0 : if ((tunnels_info[j].tunnel &
1742 [ # # ]: 0 : dev_handle->layers) ==
1743 : : tunnels_info[j].tunnel) {
1744 : 0 : rxq_ctrl->flow_tunnels_n[j]--;
1745 : 0 : break;
1746 : : }
1747 : : }
1748 : : flow_rxq_tunnel_ptype_update(rxq_ctrl);
1749 : : }
1750 : : }
1751 : : }
1752 : :
1753 : : /**
1754 : : * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1755 : : * @p flow if no other flow uses it with the same kind of request.
1756 : : *
1757 : : * @param dev
1758 : : * Pointer to Ethernet device.
1759 : : * @param[in] flow
1760 : : * Pointer to the flow.
1761 : : */
1762 : : static void
1763 : 0 : flow_rxq_flags_trim(struct rte_eth_dev *dev, struct rte_flow *flow)
1764 : : {
1765 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1766 : : uint32_t handle_idx;
1767 : : struct mlx5_flow_handle *dev_handle;
1768 : :
1769 [ # # # # : 0 : SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
# # ]
1770 : : handle_idx, dev_handle, next)
1771 : 0 : flow_drv_rxq_flags_trim(dev, dev_handle);
1772 : 0 : }
1773 : :
1774 : : /**
1775 : : * Clear the Mark/Flag and Tunnel ptype information in all Rx queues.
1776 : : *
1777 : : * @param dev
1778 : : * Pointer to Ethernet device.
1779 : : */
1780 : : static void
1781 : 0 : flow_rxq_flags_clear(struct rte_eth_dev *dev)
1782 : : {
1783 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1784 : : unsigned int i;
1785 : :
1786 [ # # ]: 0 : for (i = 0; i != priv->rxqs_n; ++i) {
1787 : 0 : struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, i);
1788 : : unsigned int j;
1789 : :
1790 [ # # # # ]: 0 : if (rxq == NULL || rxq->ctrl == NULL)
1791 : 0 : continue;
1792 : 0 : rxq->ctrl->rxq.mark = 0;
1793 [ # # ]: 0 : for (j = 0; j != MLX5_FLOW_TUNNEL; ++j)
1794 : 0 : rxq->ctrl->flow_tunnels_n[j] = 0;
1795 : 0 : rxq->ctrl->rxq.tunnel = 0;
1796 : : }
1797 : 0 : priv->mark_enabled = 0;
1798 : 0 : priv->sh->shared_mark_enabled = 0;
1799 : 0 : }
1800 : :
1801 : : static uint64_t mlx5_restore_info_dynflag;
1802 : :
1803 : : int
1804 : 0 : mlx5_flow_rx_metadata_negotiate(struct rte_eth_dev *dev, uint64_t *features)
1805 : : {
1806 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
1807 : : uint64_t supported = 0;
1808 : :
1809 [ # # ]: 0 : if (!is_tunnel_offload_active(dev)) {
1810 : : supported |= RTE_ETH_RX_METADATA_USER_FLAG;
1811 : : supported |= RTE_ETH_RX_METADATA_USER_MARK;
1812 [ # # ]: 0 : if ((*features & RTE_ETH_RX_METADATA_TUNNEL_ID) != 0) {
1813 : 0 : DRV_LOG(DEBUG,
1814 : : "tunnel offload was not activated, consider setting dv_xmeta_en=%d",
1815 : : MLX5_XMETA_MODE_MISS_INFO);
1816 : : }
1817 : : } else {
1818 : : supported |= RTE_ETH_RX_METADATA_TUNNEL_ID;
1819 [ # # ]: 0 : if ((*features & RTE_ETH_RX_METADATA_TUNNEL_ID) != 0 &&
1820 [ # # ]: 0 : mlx5_restore_info_dynflag == 0)
1821 : 0 : mlx5_restore_info_dynflag = rte_flow_restore_info_dynflag();
1822 : : }
1823 : :
1824 [ # # ]: 0 : if (((*features & supported) & RTE_ETH_RX_METADATA_TUNNEL_ID) != 0)
1825 : 0 : priv->tunnel_enabled = 1;
1826 : : else
1827 : 0 : priv->tunnel_enabled = 0;
1828 : :
1829 : 0 : *features &= supported;
1830 : 0 : return 0;
1831 : : }
1832 : :
1833 : : /**
1834 : : * Set the Rx queue dynamic metadata (mask and offset) for a flow
1835 : : *
1836 : : * @param[in] dev
1837 : : * Pointer to the Ethernet device structure.
1838 : : */
1839 : : void
1840 : 0 : mlx5_flow_rxq_dynf_set(struct rte_eth_dev *dev)
1841 : : {
1842 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1843 : : uint64_t mark_flag = RTE_MBUF_F_RX_FDIR_ID;
1844 : : unsigned int i;
1845 : :
1846 [ # # ]: 0 : if (priv->tunnel_enabled)
1847 : 0 : mark_flag |= mlx5_restore_info_dynflag;
1848 : :
1849 [ # # ]: 0 : for (i = 0; i != priv->rxqs_n; ++i) {
1850 : 0 : struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, i);
1851 : : struct mlx5_rxq_data *data;
1852 : :
1853 [ # # # # ]: 0 : if (rxq == NULL || rxq->ctrl == NULL)
1854 : 0 : continue;
1855 : : data = &rxq->ctrl->rxq;
1856 [ # # # # ]: 0 : if (!data->shared || !rxq->ctrl->started) {
1857 [ # # ]: 0 : if (!rte_flow_dynf_metadata_avail()) {
1858 : 0 : data->dynf_meta = 0;
1859 : 0 : data->flow_meta_mask = 0;
1860 : 0 : data->flow_meta_offset = -1;
1861 : 0 : data->flow_meta_port_mask = 0;
1862 : : } else {
1863 : 0 : data->dynf_meta = 1;
1864 : 0 : data->flow_meta_mask = rte_flow_dynf_metadata_mask;
1865 : 0 : data->flow_meta_offset = rte_flow_dynf_metadata_offs;
1866 : 0 : data->flow_meta_port_mask = priv->sh->dv_meta_mask;
1867 : : }
1868 : 0 : data->mark_flag = mark_flag;
1869 : : }
1870 : : }
1871 : 0 : }
1872 : :
1873 : : /*
1874 : : * return a pointer to the desired action in the list of actions.
1875 : : *
1876 : : * @param[in] actions
1877 : : * The list of actions to search the action in.
1878 : : * @param[in] action
1879 : : * The action to find.
1880 : : *
1881 : : * @return
1882 : : * Pointer to the action in the list, if found. NULL otherwise.
1883 : : */
1884 : : const struct rte_flow_action *
1885 : 0 : mlx5_flow_find_action(const struct rte_flow_action *actions,
1886 : : enum rte_flow_action_type action)
1887 : : {
1888 [ # # ]: 0 : if (actions == NULL)
1889 : : return NULL;
1890 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++)
1891 [ # # ]: 0 : if (actions->type == action)
1892 : 0 : return actions;
1893 : : return NULL;
1894 : : }
1895 : :
1896 : : /*
1897 : : * Validate the flag action.
1898 : : *
1899 : : * @param[in] action_flags
1900 : : * Bit-fields that holds the actions detected until now.
1901 : : * @param[in] attr
1902 : : * Attributes of flow that includes this action.
1903 : : * @param[out] error
1904 : : * Pointer to error structure.
1905 : : *
1906 : : * @return
1907 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1908 : : */
1909 : : int
1910 : 0 : mlx5_flow_validate_action_flag(uint64_t action_flags,
1911 : : const struct rte_flow_attr *attr,
1912 : : struct rte_flow_error *error)
1913 : : {
1914 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
1915 : 0 : return rte_flow_error_set(error, EINVAL,
1916 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1917 : : "can't mark and flag in same flow");
1918 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_FLAG)
1919 : 0 : return rte_flow_error_set(error, EINVAL,
1920 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1921 : : "can't have 2 flag"
1922 : : " actions in same flow");
1923 [ # # ]: 0 : if (attr->egress)
1924 : 0 : return rte_flow_error_set(error, ENOTSUP,
1925 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1926 : : "flag action not supported for "
1927 : : "egress");
1928 : : return 0;
1929 : : }
1930 : :
1931 : : /*
1932 : : * Validate the mark action.
1933 : : *
1934 : : * @param[in] action
1935 : : * Pointer to the queue action.
1936 : : * @param[in] action_flags
1937 : : * Bit-fields that holds the actions detected until now.
1938 : : * @param[in] attr
1939 : : * Attributes of flow that includes this action.
1940 : : * @param[out] error
1941 : : * Pointer to error structure.
1942 : : *
1943 : : * @return
1944 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1945 : : */
1946 : : int
1947 : 0 : mlx5_flow_validate_action_mark(__rte_unused struct rte_eth_dev *dev,
1948 : : const struct rte_flow_action *action,
1949 : : uint64_t action_flags,
1950 : : const struct rte_flow_attr *attr,
1951 : : struct rte_flow_error *error)
1952 : : {
1953 : 0 : const struct rte_flow_action_mark *mark = action->conf;
1954 : :
1955 [ # # ]: 0 : if (!mark)
1956 : 0 : return rte_flow_error_set(error, EINVAL,
1957 : : RTE_FLOW_ERROR_TYPE_ACTION,
1958 : : action,
1959 : : "configuration cannot be null");
1960 [ # # ]: 0 : if (mark->id >= MLX5_FLOW_MARK_MAX)
1961 : 0 : return rte_flow_error_set(error, EINVAL,
1962 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1963 : 0 : &mark->id,
1964 : : "mark id must in 0 <= id < "
1965 : : RTE_STR(MLX5_FLOW_MARK_MAX));
1966 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_FLAG)
1967 : 0 : return rte_flow_error_set(error, EINVAL,
1968 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1969 : : "can't flag and mark in same flow");
1970 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
1971 : 0 : return rte_flow_error_set(error, EINVAL,
1972 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1973 : : "can't have 2 mark actions in same"
1974 : : " flow");
1975 [ # # ]: 0 : if (attr->egress)
1976 : 0 : return rte_flow_error_set(error, ENOTSUP,
1977 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1978 : : "mark action not supported for "
1979 : : "egress");
1980 : : return 0;
1981 : : }
1982 : :
1983 : : /*
1984 : : * Validate the drop action.
1985 : : *
1986 : : * @param[in] dev
1987 : : * Pointer to the Ethernet device structure.
1988 : : * @param[in] is_root
1989 : : * True if flow is validated for root table. False otherwise.
1990 : : * @param[in] attr
1991 : : * Attributes of flow that includes this action.
1992 : : * @param[out] error
1993 : : * Pointer to error structure.
1994 : : *
1995 : : * @return
1996 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1997 : : */
1998 : : int
1999 : 0 : mlx5_flow_validate_action_drop(struct rte_eth_dev *dev,
2000 : : bool is_root,
2001 : : const struct rte_flow_attr *attr,
2002 : : struct rte_flow_error *error)
2003 : : {
2004 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2005 : :
2006 [ # # # # ]: 0 : if (priv->sh->config.dv_flow_en == 0 && attr->egress)
2007 : 0 : return rte_flow_error_set(error, ENOTSUP,
2008 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
2009 : : "drop action not supported for "
2010 : : "egress");
2011 [ # # # # : 0 : if (priv->sh->config.dv_flow_en == 1 && is_root && (attr->egress || attr->transfer) &&
# # ]
2012 [ # # ]: 0 : !priv->sh->dr_root_drop_action_en) {
2013 : 0 : return rte_flow_error_set(error, ENOTSUP,
2014 : : RTE_FLOW_ERROR_TYPE_ATTR, NULL,
2015 : : "drop action not supported for "
2016 : : "egress and transfer on group 0");
2017 : : }
2018 : : return 0;
2019 : : }
2020 : :
2021 : : /*
2022 : : * Check if a queue specified in the queue action is valid.
2023 : : *
2024 : : * @param[in] dev
2025 : : * Pointer to the Ethernet device structure.
2026 : : * @param[in] action
2027 : : * Pointer to the queue action.
2028 : : * @param[out] error
2029 : : * Pointer to error structure.
2030 : : *
2031 : : * @return
2032 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2033 : : */
2034 : : int
2035 : 0 : mlx5_flow_validate_target_queue(struct rte_eth_dev *dev,
2036 : : const struct rte_flow_action *action,
2037 : : struct rte_flow_error *error)
2038 : : {
2039 : 0 : const struct rte_flow_action_queue *queue = action->conf;
2040 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2041 : :
2042 [ # # # # ]: 0 : if (mlx5_is_external_rxq(dev, queue->index))
2043 : : return 0;
2044 [ # # ]: 0 : if (!priv->rxqs_n)
2045 : 0 : return rte_flow_error_set(error, EINVAL,
2046 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2047 : : NULL, "No Rx queues configured");
2048 [ # # ]: 0 : if (queue->index >= priv->rxqs_n)
2049 : 0 : return rte_flow_error_set(error, EINVAL,
2050 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2051 : 0 : &queue->index,
2052 : : "queue index out of range");
2053 [ # # ]: 0 : if (mlx5_rxq_get(dev, queue->index) == NULL)
2054 : 0 : return rte_flow_error_set(error, EINVAL,
2055 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2056 : 0 : &queue->index,
2057 : : "queue is not configured");
2058 : : return 0;
2059 : : }
2060 : :
2061 : : /*
2062 : : * Validate the queue action.
2063 : : *
2064 : : * @param[in] action
2065 : : * Pointer to the queue action.
2066 : : * @param[in] action_flags
2067 : : * Bit-fields that holds the actions detected until now.
2068 : : * @param[in] dev
2069 : : * Pointer to the Ethernet device structure.
2070 : : * @param[in] attr
2071 : : * Attributes of flow that includes this action.
2072 : : * @param[out] error
2073 : : * Pointer to error structure.
2074 : : *
2075 : : * @return
2076 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2077 : : */
2078 : : int
2079 : 0 : mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
2080 : : uint64_t action_flags,
2081 : : struct rte_eth_dev *dev,
2082 : : const struct rte_flow_attr *attr,
2083 : : struct rte_flow_error *error)
2084 : : {
2085 : 0 : const struct rte_flow_action_queue *queue = action->conf;
2086 : :
2087 [ # # ]: 0 : if (!queue)
2088 : 0 : return rte_flow_error_set(error, EINVAL,
2089 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
2090 : : "no QUEUE action configuration");
2091 [ # # ]: 0 : if (action_flags & MLX5_FLOW_FATE_ACTIONS)
2092 : 0 : return rte_flow_error_set(error, EINVAL,
2093 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2094 : : "can't have 2 fate actions in"
2095 : : " same flow");
2096 [ # # ]: 0 : if (attr->egress)
2097 : 0 : return rte_flow_error_set(error, ENOTSUP,
2098 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
2099 : : "queue action not supported for egress.");
2100 : 0 : return mlx5_flow_validate_target_queue(dev, action, error);
2101 : : }
2102 : :
2103 : : /**
2104 : : * Validate queue numbers for device RSS.
2105 : : *
2106 : : * @param[in] dev
2107 : : * Configured device.
2108 : : * @param[in] queues
2109 : : * Array of queue numbers.
2110 : : * @param[in] queues_n
2111 : : * Size of the @p queues array.
2112 : : * @param[out] error
2113 : : * On error, filled with a textual error description.
2114 : : * @param[out] queue_idx
2115 : : * On error, filled with an offending queue index in @p queues array.
2116 : : *
2117 : : * @return
2118 : : * 0 on success, a negative errno code on error.
2119 : : */
2120 : : static int
2121 : 0 : mlx5_validate_rss_queues(struct rte_eth_dev *dev,
2122 : : const uint16_t *queues, uint32_t queues_n,
2123 : : const char **error, uint32_t *queue_idx)
2124 : : {
2125 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
2126 : : bool is_hairpin = false;
2127 : : bool is_ext_rss = false;
2128 : : uint32_t i;
2129 : :
2130 [ # # ]: 0 : for (i = 0; i != queues_n; ++i) {
2131 : : struct mlx5_rxq_ctrl *rxq_ctrl;
2132 : :
2133 [ # # # # ]: 0 : if (mlx5_is_external_rxq(dev, queues[0])) {
2134 : : is_ext_rss = true;
2135 : 0 : continue;
2136 : : }
2137 [ # # ]: 0 : if (is_ext_rss) {
2138 : 0 : *error = "Combining external and regular RSS queues is not supported";
2139 : 0 : *queue_idx = i;
2140 : 0 : return -ENOTSUP;
2141 : : }
2142 [ # # ]: 0 : if (queues[i] >= priv->rxqs_n) {
2143 : 0 : *error = "queue index out of range";
2144 : 0 : *queue_idx = i;
2145 : 0 : return -EINVAL;
2146 : : }
2147 : 0 : rxq_ctrl = mlx5_rxq_ctrl_get(dev, queues[i]);
2148 [ # # ]: 0 : if (rxq_ctrl == NULL) {
2149 : 0 : *error = "queue is not configured";
2150 : 0 : *queue_idx = i;
2151 : 0 : return -EINVAL;
2152 : : }
2153 [ # # # # ]: 0 : if (i == 0 && rxq_ctrl->is_hairpin)
2154 : : is_hairpin = true;
2155 [ # # ]: 0 : if (is_hairpin != rxq_ctrl->is_hairpin) {
2156 : 0 : *error = "combining hairpin and regular RSS queues is not supported";
2157 : 0 : *queue_idx = i;
2158 : 0 : return -ENOTSUP;
2159 : : }
2160 : : }
2161 : : return 0;
2162 : : }
2163 : :
2164 : : /*
2165 : : * Validate the rss action.
2166 : : *
2167 : : * @param[in] dev
2168 : : * Pointer to the Ethernet device structure.
2169 : : * @param[in] action
2170 : : * Pointer to the queue action.
2171 : : * @param[out] error
2172 : : * Pointer to error structure.
2173 : : *
2174 : : * @return
2175 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2176 : : */
2177 : : int
2178 : 0 : mlx5_validate_action_rss(struct rte_eth_dev *dev,
2179 : : const struct rte_flow_action *action,
2180 : : struct rte_flow_error *error)
2181 : : {
2182 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2183 : 0 : const struct rte_flow_action_rss *rss = action->conf;
2184 : : int ret;
2185 : : const char *message;
2186 : : uint32_t queue_idx;
2187 : :
2188 [ # # ]: 0 : if (!rss)
2189 : 0 : return rte_flow_error_set
2190 : : (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
2191 : : action, "no RSS action configuration");
2192 [ # # ]: 0 : if (rss->func == RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ) {
2193 : 0 : DRV_LOG(WARNING, "port %u symmetric RSS supported with SORT",
2194 : : dev->data->port_id);
2195 [ # # ]: 0 : } else if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
2196 : : rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
2197 : 0 : return rte_flow_error_set(error, ENOTSUP,
2198 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2199 : 0 : &rss->func,
2200 : : "RSS hash function not supported");
2201 : : #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
2202 [ # # ]: 0 : if (rss->level > 2)
2203 : : #else
2204 : : if (rss->level > 1)
2205 : : #endif
2206 : 0 : return rte_flow_error_set(error, ENOTSUP,
2207 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2208 : 0 : &rss->level,
2209 : : "tunnel RSS is not supported");
2210 : : /* allow RSS key_len 0 in case of NULL (default) RSS key. */
2211 [ # # # # ]: 0 : if (rss->key_len == 0 && rss->key != NULL)
2212 : 0 : return rte_flow_error_set(error, ENOTSUP,
2213 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2214 : 0 : &rss->key_len,
2215 : : "RSS hash key length 0");
2216 [ # # ]: 0 : if (rss->key_len > 0 && rss->key_len < MLX5_RSS_HASH_KEY_LEN)
2217 : 0 : return rte_flow_error_set(error, ENOTSUP,
2218 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2219 : 0 : &rss->key_len,
2220 : : "RSS hash key too small");
2221 [ # # ]: 0 : if (rss->key_len > MLX5_RSS_HASH_KEY_LEN)
2222 : 0 : return rte_flow_error_set(error, ENOTSUP,
2223 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2224 : 0 : &rss->key_len,
2225 : : "RSS hash key too large");
2226 [ # # ]: 0 : if (rss->queue_num > priv->sh->dev_cap.ind_table_max_size)
2227 : 0 : return rte_flow_error_set(error, ENOTSUP,
2228 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2229 : 0 : &rss->queue_num,
2230 : : "number of queues too large");
2231 [ # # ]: 0 : if (rss->types & MLX5_RSS_HF_MASK)
2232 : 0 : return rte_flow_error_set(error, ENOTSUP,
2233 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2234 : 0 : &rss->types,
2235 : : "some RSS protocols are not"
2236 : : " supported");
2237 [ # # ]: 0 : if ((rss->types & (RTE_ETH_RSS_L3_SRC_ONLY | RTE_ETH_RSS_L3_DST_ONLY)) &&
2238 [ # # ]: 0 : !(rss->types & RTE_ETH_RSS_IP))
2239 : 0 : return rte_flow_error_set(error, EINVAL,
2240 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
2241 : : "L3 partial RSS requested but L3 RSS"
2242 : : " type not specified");
2243 [ # # ]: 0 : if ((rss->types & (RTE_ETH_RSS_L4_SRC_ONLY | RTE_ETH_RSS_L4_DST_ONLY)) &&
2244 [ # # ]: 0 : !(rss->types & (RTE_ETH_RSS_UDP | RTE_ETH_RSS_TCP)))
2245 : 0 : return rte_flow_error_set(error, EINVAL,
2246 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
2247 : : "L4 partial RSS requested but L4 RSS"
2248 : : " type not specified");
2249 [ # # # # ]: 0 : if (!priv->rxqs_n && priv->ext_rxqs == NULL)
2250 : 0 : return rte_flow_error_set(error, EINVAL,
2251 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2252 : : NULL, "No Rx queues configured");
2253 [ # # ]: 0 : if (!rss->queue_num)
2254 : 0 : return rte_flow_error_set(error, EINVAL,
2255 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2256 : : NULL, "No queues configured");
2257 : 0 : ret = mlx5_validate_rss_queues(dev, rss->queue, rss->queue_num,
2258 : : &message, &queue_idx);
2259 [ # # ]: 0 : if (ret != 0) {
2260 : 0 : return rte_flow_error_set(error, -ret,
2261 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2262 : 0 : &rss->queue[queue_idx], message);
2263 : : }
2264 : : return 0;
2265 : : }
2266 : :
2267 : : /*
2268 : : * Validate the rss action.
2269 : : *
2270 : : * @param[in] action
2271 : : * Pointer to the queue action.
2272 : : * @param[in] action_flags
2273 : : * Bit-fields that holds the actions detected until now.
2274 : : * @param[in] dev
2275 : : * Pointer to the Ethernet device structure.
2276 : : * @param[in] attr
2277 : : * Attributes of flow that includes this action.
2278 : : * @param[in] item_flags
2279 : : * Items that were detected.
2280 : : * @param[out] error
2281 : : * Pointer to error structure.
2282 : : *
2283 : : * @return
2284 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2285 : : */
2286 : : int
2287 : 0 : mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
2288 : : uint64_t action_flags,
2289 : : struct rte_eth_dev *dev,
2290 : : const struct rte_flow_attr *attr,
2291 : : uint64_t item_flags,
2292 : : struct rte_flow_error *error)
2293 : : {
2294 : 0 : const struct rte_flow_action_rss *rss = action->conf;
2295 : 0 : int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2296 : : int ret;
2297 : :
2298 [ # # ]: 0 : if (action_flags & MLX5_FLOW_FATE_ACTIONS)
2299 : 0 : return rte_flow_error_set(error, EINVAL,
2300 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2301 : : "can't have 2 fate actions"
2302 : : " in same flow");
2303 : 0 : ret = mlx5_validate_action_rss(dev, action, error);
2304 [ # # ]: 0 : if (ret)
2305 : : return ret;
2306 [ # # ]: 0 : if (attr->egress)
2307 : 0 : return rte_flow_error_set(error, ENOTSUP,
2308 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
2309 : : "rss action not supported for "
2310 : : "egress");
2311 [ # # # # ]: 0 : if (rss->level > 1 && !tunnel)
2312 : 0 : return rte_flow_error_set(error, EINVAL,
2313 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
2314 : : "inner RSS is not supported for "
2315 : : "non-tunnel flows");
2316 [ # # ]: 0 : if ((item_flags & MLX5_FLOW_LAYER_ECPRI) &&
2317 : : !(item_flags & MLX5_FLOW_LAYER_INNER_L4_UDP)) {
2318 : 0 : return rte_flow_error_set(error, EINVAL,
2319 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
2320 : : "RSS on eCPRI is not supported now");
2321 : : }
2322 [ # # ]: 0 : if ((item_flags & MLX5_FLOW_LAYER_MPLS) &&
2323 : : !(item_flags &
2324 [ # # ]: 0 : (MLX5_FLOW_LAYER_INNER_L2 | MLX5_FLOW_LAYER_INNER_L3)) &&
2325 : : rss->level > 1)
2326 : 0 : return rte_flow_error_set(error, EINVAL,
2327 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2328 : : "MPLS inner RSS needs to specify inner L2/L3 items after MPLS in pattern");
2329 : : return 0;
2330 : : }
2331 : :
2332 : : /*
2333 : : * Validate the default miss action.
2334 : : *
2335 : : * @param[in] action_flags
2336 : : * Bit-fields that holds the actions detected until now.
2337 : : * @param[out] error
2338 : : * Pointer to error structure.
2339 : : *
2340 : : * @return
2341 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2342 : : */
2343 : : int
2344 : 0 : mlx5_flow_validate_action_default_miss(uint64_t action_flags,
2345 : : const struct rte_flow_attr *attr,
2346 : : struct rte_flow_error *error)
2347 : : {
2348 [ # # ]: 0 : if (action_flags & MLX5_FLOW_FATE_ACTIONS)
2349 : 0 : return rte_flow_error_set(error, EINVAL,
2350 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2351 : : "can't have 2 fate actions in"
2352 : : " same flow");
2353 [ # # ]: 0 : if (attr->egress)
2354 : 0 : return rte_flow_error_set(error, ENOTSUP,
2355 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
2356 : : "default miss action not supported "
2357 : : "for egress");
2358 [ # # ]: 0 : if (attr->group)
2359 : 0 : return rte_flow_error_set(error, ENOTSUP,
2360 : : RTE_FLOW_ERROR_TYPE_ATTR_GROUP, NULL,
2361 : : "only group 0 is supported");
2362 [ # # ]: 0 : if (attr->transfer)
2363 : 0 : return rte_flow_error_set(error, ENOTSUP,
2364 : : RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
2365 : : NULL, "transfer is not supported");
2366 : : return 0;
2367 : : }
2368 : :
2369 : : /*
2370 : : * Validate the count action.
2371 : : *
2372 : : * @param[in] dev
2373 : : * Pointer to the Ethernet device structure.
2374 : : * @param[in] attr
2375 : : * Attributes of flow that includes this action.
2376 : : * @param[out] error
2377 : : * Pointer to error structure.
2378 : : *
2379 : : * @return
2380 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2381 : : */
2382 : : int
2383 : 0 : mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,
2384 : : const struct rte_flow_attr *attr,
2385 : : struct rte_flow_error *error)
2386 : : {
2387 [ # # ]: 0 : if (attr->egress)
2388 : 0 : return rte_flow_error_set(error, ENOTSUP,
2389 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
2390 : : "count action not supported for "
2391 : : "egress");
2392 : : return 0;
2393 : : }
2394 : :
2395 : : /*
2396 : : * Validate the ASO CT action.
2397 : : *
2398 : : * @param[in] dev
2399 : : * Pointer to the Ethernet device structure.
2400 : : * @param[in] conntrack
2401 : : * Pointer to the CT action profile.
2402 : : * @param[out] error
2403 : : * Pointer to error structure.
2404 : : *
2405 : : * @return
2406 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2407 : : */
2408 : : int
2409 : 0 : mlx5_validate_action_ct(struct rte_eth_dev *dev,
2410 : : const struct rte_flow_action_conntrack *conntrack,
2411 : : struct rte_flow_error *error)
2412 : : {
2413 : : RTE_SET_USED(dev);
2414 : :
2415 [ # # ]: 0 : if (conntrack->state > RTE_FLOW_CONNTRACK_STATE_TIME_WAIT)
2416 : 0 : return rte_flow_error_set(error, EINVAL,
2417 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2418 : : "Invalid CT state");
2419 [ # # ]: 0 : if (conntrack->last_index > RTE_FLOW_CONNTRACK_FLAG_RST)
2420 : 0 : return rte_flow_error_set(error, EINVAL,
2421 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2422 : : "Invalid last TCP packet flag");
2423 : : return 0;
2424 : : }
2425 : :
2426 : : /**
2427 : : * Validate the level value for modify field action.
2428 : : *
2429 : : * @param[in] data
2430 : : * Pointer to the rte_flow_field_data structure either src or dst.
2431 : : * @param[out] error
2432 : : * Pointer to error structure.
2433 : : *
2434 : : * @return
2435 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2436 : : */
2437 : : int
2438 : 0 : flow_validate_modify_field_level(const struct rte_flow_field_data *data,
2439 : : struct rte_flow_error *error)
2440 : : {
2441 [ # # # # ]: 0 : if (data->level == 0 || data->field == RTE_FLOW_FIELD_FLEX_ITEM)
2442 : : return 0;
2443 [ # # ]: 0 : if (data->field != RTE_FLOW_FIELD_TAG &&
2444 : : data->field != (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG) {
2445 [ # # ]: 0 : if (data->level > 1)
2446 : 0 : return rte_flow_error_set(error, ENOTSUP,
2447 : : RTE_FLOW_ERROR_TYPE_ACTION,
2448 : : NULL,
2449 : : "inner header fields modification is not supported");
2450 : : return 0;
2451 : : }
2452 [ # # ]: 0 : if (data->tag_index != 0)
2453 : 0 : return rte_flow_error_set(error, EINVAL,
2454 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2455 : : "tag array can be provided using 'level' or 'tag_index' fields, not both");
2456 : : /*
2457 : : * The tag array for RTE_FLOW_FIELD_TAG type is provided using
2458 : : * 'tag_index' field. In old API, it was provided using 'level' field
2459 : : * and it is still supported for backwards compatibility.
2460 : : */
2461 : 0 : DRV_LOG(DEBUG, "tag array provided in 'level' field instead of 'tag_index' field.");
2462 : 0 : return 0;
2463 : : }
2464 : :
2465 : : /**
2466 : : * Validate ICMP6 item.
2467 : : *
2468 : : * @param[in] item
2469 : : * Item specification.
2470 : : * @param[in] item_flags
2471 : : * Bit-fields that holds the items detected until now.
2472 : : * @param[in] ext_vlan_sup
2473 : : * Whether extended VLAN features are supported or not.
2474 : : * @param[out] error
2475 : : * Pointer to error structure.
2476 : : *
2477 : : * @return
2478 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2479 : : */
2480 : : int
2481 : 0 : mlx5_flow_validate_item_icmp6(const struct rte_eth_dev *dev,
2482 : : const struct rte_flow_item *item,
2483 : : uint64_t item_flags,
2484 : : uint8_t target_protocol,
2485 : : struct rte_flow_error *error)
2486 : : {
2487 : 0 : const struct rte_flow_item_icmp6 *mask = item->mask;
2488 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2489 [ # # ]: 0 : const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
2490 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6;
2491 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2492 : : MLX5_FLOW_LAYER_OUTER_L4;
2493 : : int ret;
2494 : :
2495 [ # # ]: 0 : if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMPV6)
2496 : 0 : return rte_flow_error_set(error, EINVAL,
2497 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2498 : : "protocol filtering not compatible"
2499 : : " with ICMP6 layer");
2500 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
2501 [ # # ]: 0 : if (!(item_flags & l3m))
2502 : 0 : return rte_flow_error_set(error, EINVAL,
2503 : : RTE_FLOW_ERROR_TYPE_ITEM,
2504 : : item, "IPv6 is mandatory to filter on ICMP6");
2505 : : }
2506 [ # # ]: 0 : if (item_flags & l4m)
2507 : 0 : return rte_flow_error_set(error, EINVAL,
2508 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2509 : : "multiple L4 layers not supported");
2510 [ # # ]: 0 : if (!mask)
2511 : : mask = &rte_flow_item_icmp6_mask;
2512 : 0 : ret = mlx5_flow_item_acceptable
2513 : : (dev, item, (const uint8_t *)mask,
2514 : : (const uint8_t *)&rte_flow_item_icmp6_mask,
2515 : : sizeof(struct rte_flow_item_icmp6),
2516 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2517 : : if (ret < 0)
2518 : : return ret;
2519 : : return 0;
2520 : : }
2521 : :
2522 : : /**
2523 : : * Validate ICMP6 echo request/reply item.
2524 : : *
2525 : : * @param[in] item
2526 : : * Item specification.
2527 : : * @param[in] item_flags
2528 : : * Bit-fields that holds the items detected until now.
2529 : : * @param[in] ext_vlan_sup
2530 : : * Whether extended VLAN features are supported or not.
2531 : : * @param[out] error
2532 : : * Pointer to error structure.
2533 : : *
2534 : : * @return
2535 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2536 : : */
2537 : : int
2538 : 0 : mlx5_flow_validate_item_icmp6_echo(const struct rte_eth_dev *dev,
2539 : : const struct rte_flow_item *item,
2540 : : uint64_t item_flags,
2541 : : uint8_t target_protocol,
2542 : : struct rte_flow_error *error)
2543 : : {
2544 : 0 : const struct rte_flow_item_icmp6_echo *mask = item->mask;
2545 : 0 : const struct rte_flow_item_icmp6_echo nic_mask = {
2546 : : .hdr.base.type = 0xff,
2547 : : .hdr.base.code = 0xff,
2548 : : .hdr.identifier = RTE_BE16(0xffff),
2549 : : .hdr.sequence = RTE_BE16(0xffff),
2550 : : };
2551 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2552 [ # # ]: 0 : const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
2553 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6;
2554 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2555 : : MLX5_FLOW_LAYER_OUTER_L4;
2556 : : int ret;
2557 : :
2558 [ # # ]: 0 : if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMPV6)
2559 : 0 : return rte_flow_error_set(error, EINVAL,
2560 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2561 : : "protocol filtering not compatible"
2562 : : " with ICMP6 layer");
2563 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
2564 [ # # ]: 0 : if (!(item_flags & l3m))
2565 : 0 : return rte_flow_error_set(error, EINVAL,
2566 : : RTE_FLOW_ERROR_TYPE_ITEM,
2567 : : item, "IPv6 is mandatory to filter on ICMP6");
2568 : : }
2569 [ # # ]: 0 : if (item_flags & l4m)
2570 : 0 : return rte_flow_error_set(error, EINVAL,
2571 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2572 : : "multiple L4 layers not supported");
2573 [ # # ]: 0 : if (!mask)
2574 : : mask = &nic_mask;
2575 : 0 : ret = mlx5_flow_item_acceptable
2576 : : (dev, item, (const uint8_t *)mask,
2577 : : (const uint8_t *)&nic_mask,
2578 : : sizeof(struct rte_flow_item_icmp6_echo),
2579 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2580 : : if (ret < 0)
2581 : : return ret;
2582 : : return 0;
2583 : : }
2584 : :
2585 : : /**
2586 : : * Validate ICMP item.
2587 : : *
2588 : : * @param[in] item
2589 : : * Item specification.
2590 : : * @param[in] item_flags
2591 : : * Bit-fields that holds the items detected until now.
2592 : : * @param[out] error
2593 : : * Pointer to error structure.
2594 : : *
2595 : : * @return
2596 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2597 : : */
2598 : : int
2599 : 0 : mlx5_flow_validate_item_icmp(const struct rte_eth_dev *dev,
2600 : : const struct rte_flow_item *item,
2601 : : uint64_t item_flags,
2602 : : uint8_t target_protocol,
2603 : : struct rte_flow_error *error)
2604 : : {
2605 : 0 : const struct rte_flow_item_icmp *mask = item->mask;
2606 : 0 : const struct rte_flow_item_icmp nic_mask = {
2607 : : .hdr.icmp_type = 0xff,
2608 : : .hdr.icmp_code = 0xff,
2609 : : .hdr.icmp_ident = RTE_BE16(0xffff),
2610 : : .hdr.icmp_seq_nb = RTE_BE16(0xffff),
2611 : : };
2612 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2613 [ # # ]: 0 : const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
2614 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4;
2615 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2616 : : MLX5_FLOW_LAYER_OUTER_L4;
2617 : : int ret;
2618 : :
2619 [ # # ]: 0 : if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMP)
2620 : 0 : return rte_flow_error_set(error, EINVAL,
2621 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2622 : : "protocol filtering not compatible"
2623 : : " with ICMP layer");
2624 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
2625 [ # # ]: 0 : if (!(item_flags & l3m))
2626 : 0 : return rte_flow_error_set(error, EINVAL,
2627 : : RTE_FLOW_ERROR_TYPE_ITEM,
2628 : : item, "IPv4 is mandatory to filter on ICMP");
2629 : : }
2630 [ # # ]: 0 : if (item_flags & l4m)
2631 : 0 : return rte_flow_error_set(error, EINVAL,
2632 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2633 : : "multiple L4 layers not supported");
2634 [ # # ]: 0 : if (!mask)
2635 : : mask = &nic_mask;
2636 : 0 : ret = mlx5_flow_item_acceptable
2637 : : (dev, item, (const uint8_t *)mask,
2638 : : (const uint8_t *)&nic_mask,
2639 : : sizeof(struct rte_flow_item_icmp),
2640 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2641 : : if (ret < 0)
2642 : : return ret;
2643 : : return 0;
2644 : : }
2645 : :
2646 : : /**
2647 : : * Validate Ethernet item.
2648 : : *
2649 : : * @param[in] item
2650 : : * Item specification.
2651 : : * @param[in] item_flags
2652 : : * Bit-fields that holds the items detected until now.
2653 : : * @param[out] error
2654 : : * Pointer to error structure.
2655 : : *
2656 : : * @return
2657 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2658 : : */
2659 : : int
2660 : 0 : mlx5_flow_validate_item_eth(const struct rte_eth_dev *dev,
2661 : : const struct rte_flow_item *item,
2662 : : uint64_t item_flags, bool ext_vlan_sup,
2663 : : struct rte_flow_error *error)
2664 : : {
2665 : 0 : const struct rte_flow_item_eth *mask = item->mask;
2666 : 0 : const struct rte_flow_item_eth nic_mask = {
2667 : : .hdr.dst_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
2668 : : .hdr.src_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
2669 : : .hdr.ether_type = RTE_BE16(0xffff),
2670 : : .has_vlan = ext_vlan_sup ? 1 : 0,
2671 : : };
2672 : : int ret;
2673 : 0 : int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2674 [ # # ]: 0 : const uint64_t ethm = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
2675 : : MLX5_FLOW_LAYER_OUTER_L2;
2676 : :
2677 [ # # ]: 0 : if (item_flags & ethm)
2678 : 0 : return rte_flow_error_set(error, ENOTSUP,
2679 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2680 : : "multiple L2 layers not supported");
2681 [ # # # # : 0 : if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_L3)) ||
# # ]
2682 [ # # ]: 0 : (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_L3)))
2683 : 0 : return rte_flow_error_set(error, EINVAL,
2684 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2685 : : "L2 layer should not follow "
2686 : : "L3 layers");
2687 [ # # # # : 0 : if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_VLAN)) ||
# # ]
2688 [ # # ]: 0 : (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_VLAN)))
2689 : 0 : return rte_flow_error_set(error, EINVAL,
2690 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2691 : : "L2 layer should not follow VLAN");
2692 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_GTP)
2693 : 0 : return rte_flow_error_set(error, EINVAL,
2694 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2695 : : "L2 layer should not follow GTP");
2696 [ # # ]: 0 : if (!mask)
2697 : : mask = &rte_flow_item_eth_mask;
2698 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2699 : : (const uint8_t *)&nic_mask,
2700 : : sizeof(struct rte_flow_item_eth),
2701 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2702 : 0 : return ret;
2703 : : }
2704 : :
2705 : : /**
2706 : : * Validate VLAN item.
2707 : : *
2708 : : * @param[in] item
2709 : : * Item specification.
2710 : : * @param[in] item_flags
2711 : : * Bit-fields that holds the items detected until now.
2712 : : * @param[in] dev
2713 : : * Ethernet device flow is being created on.
2714 : : * @param[out] error
2715 : : * Pointer to error structure.
2716 : : *
2717 : : * @return
2718 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2719 : : */
2720 : : int
2721 : 0 : mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
2722 : : uint64_t item_flags,
2723 : : struct rte_eth_dev *dev,
2724 : : struct rte_flow_error *error)
2725 : : {
2726 : 0 : const struct rte_flow_item_vlan *spec = item->spec;
2727 : 0 : const struct rte_flow_item_vlan *mask = item->mask;
2728 : 0 : const struct rte_flow_item_vlan nic_mask = {
2729 : : .hdr.vlan_tci = RTE_BE16(UINT16_MAX),
2730 : : .hdr.eth_proto = RTE_BE16(UINT16_MAX),
2731 : : };
2732 : : uint16_t vlan_tag = 0;
2733 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2734 : : int ret;
2735 : : const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
2736 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L4) :
2737 : : (MLX5_FLOW_LAYER_OUTER_L3 |
2738 : : MLX5_FLOW_LAYER_OUTER_L4);
2739 [ # # ]: 0 : const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
2740 : : MLX5_FLOW_LAYER_OUTER_VLAN;
2741 : :
2742 [ # # ]: 0 : if (item_flags & vlanm)
2743 : 0 : return rte_flow_error_set(error, EINVAL,
2744 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2745 : : "multiple VLAN layers not supported");
2746 [ # # ]: 0 : else if ((item_flags & l34m) != 0)
2747 : 0 : return rte_flow_error_set(error, EINVAL,
2748 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2749 : : "VLAN cannot follow L3/L4 layer");
2750 [ # # ]: 0 : if (!mask)
2751 : : mask = &rte_flow_item_vlan_mask;
2752 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2753 : : (const uint8_t *)&nic_mask,
2754 : : sizeof(struct rte_flow_item_vlan),
2755 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2756 [ # # ]: 0 : if (ret)
2757 : : return ret;
2758 [ # # # # ]: 0 : if (!tunnel && mask->hdr.vlan_tci != RTE_BE16(0x0fff)) {
2759 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2760 : :
2761 [ # # ]: 0 : if (priv->vmwa_context) {
2762 : : /*
2763 : : * Non-NULL context means we have a virtual machine
2764 : : * and SR-IOV enabled, we have to create VLAN interface
2765 : : * to make hypervisor to setup E-Switch vport
2766 : : * context correctly. We avoid creating the multiple
2767 : : * VLAN interfaces, so we cannot support VLAN tag mask.
2768 : : */
2769 : 0 : return rte_flow_error_set(error, EINVAL,
2770 : : RTE_FLOW_ERROR_TYPE_ITEM,
2771 : : item,
2772 : : "VLAN tag mask is not"
2773 : : " supported in virtual"
2774 : : " environment");
2775 : : }
2776 : : }
2777 [ # # ]: 0 : if (spec) {
2778 : 0 : vlan_tag = spec->hdr.vlan_tci;
2779 : 0 : vlan_tag &= mask->hdr.vlan_tci;
2780 : : }
2781 : : /*
2782 : : * From verbs perspective an empty VLAN is equivalent
2783 : : * to a packet without VLAN layer.
2784 : : */
2785 [ # # ]: 0 : if (!vlan_tag)
2786 : 0 : return rte_flow_error_set(error, EINVAL,
2787 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2788 : 0 : item->spec,
2789 : : "VLAN cannot be empty");
2790 : : return 0;
2791 : : }
2792 : :
2793 : : /**
2794 : : * Validate IPV4 item.
2795 : : *
2796 : : * @param[in] item
2797 : : * Item specification.
2798 : : * @param[in] item_flags
2799 : : * Bit-fields that holds the items detected until now.
2800 : : * @param[in] last_item
2801 : : * Previous validated item in the pattern items.
2802 : : * @param[in] ether_type
2803 : : * Type in the ethernet layer header (including dot1q).
2804 : : * @param[in] acc_mask
2805 : : * Acceptable mask, if NULL default internal default mask
2806 : : * will be used to check whether item fields are supported.
2807 : : * @param[in] range_accepted
2808 : : * True if range of values is accepted for specific fields, false otherwise.
2809 : : * @param[out] error
2810 : : * Pointer to error structure.
2811 : : *
2812 : : * @return
2813 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2814 : : */
2815 : : int
2816 : 0 : mlx5_flow_validate_item_ipv4(const struct rte_eth_dev *dev,
2817 : : const struct rte_flow_item *item,
2818 : : uint64_t item_flags,
2819 : : uint64_t last_item,
2820 : : uint16_t ether_type,
2821 : : const struct rte_flow_item_ipv4 *acc_mask,
2822 : : bool range_accepted,
2823 : : struct rte_flow_error *error)
2824 : : {
2825 : 0 : const struct rte_flow_item_ipv4 *mask = item->mask;
2826 : 0 : const struct rte_flow_item_ipv4 *spec = item->spec;
2827 : 0 : const struct rte_flow_item_ipv4 nic_mask = {
2828 : : .hdr = {
2829 : : .src_addr = RTE_BE32(0xffffffff),
2830 : : .dst_addr = RTE_BE32(0xffffffff),
2831 : : .type_of_service = 0xff,
2832 : : .next_proto_id = 0xff,
2833 : : },
2834 : : };
2835 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2836 [ # # ]: 0 : const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2837 : : MLX5_FLOW_LAYER_OUTER_L3;
2838 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2839 : : MLX5_FLOW_LAYER_OUTER_L4;
2840 : : int ret;
2841 : : uint8_t next_proto = 0xFF;
2842 : : const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2843 : : MLX5_FLOW_LAYER_OUTER_VLAN |
2844 : : MLX5_FLOW_LAYER_INNER_VLAN);
2845 : :
2846 [ # # ]: 0 : if ((last_item & l2_vlan) && ether_type &&
2847 [ # # ]: 0 : ether_type != RTE_ETHER_TYPE_IPV4)
2848 : 0 : return rte_flow_error_set(error, EINVAL,
2849 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2850 : : "IPv4 cannot follow L2/VLAN layer "
2851 : : "which ether type is not IPv4");
2852 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_IPIP) {
2853 [ # # ]: 0 : if (mask && spec)
2854 : 0 : next_proto = mask->hdr.next_proto_id &
2855 : 0 : spec->hdr.next_proto_id;
2856 [ # # ]: 0 : if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2857 : 0 : return rte_flow_error_set(error, EINVAL,
2858 : : RTE_FLOW_ERROR_TYPE_ITEM,
2859 : : item,
2860 : : "multiple tunnel "
2861 : : "not supported");
2862 : : }
2863 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP)
2864 : 0 : return rte_flow_error_set(error, EINVAL,
2865 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2866 : : "wrong tunnel type - IPv6 specified "
2867 : : "but IPv4 item provided");
2868 [ # # ]: 0 : if (item_flags & l3m)
2869 : 0 : return rte_flow_error_set(error, ENOTSUP,
2870 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2871 : : "multiple L3 layers not supported");
2872 [ # # ]: 0 : else if (item_flags & l4m)
2873 : 0 : return rte_flow_error_set(error, EINVAL,
2874 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2875 : : "L3 cannot follow an L4 layer.");
2876 [ # # ]: 0 : else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2877 : : !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2878 : 0 : return rte_flow_error_set(error, EINVAL,
2879 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2880 : : "L3 cannot follow an NVGRE layer.");
2881 [ # # ]: 0 : if (!mask)
2882 : : mask = &rte_flow_item_ipv4_mask;
2883 [ # # ]: 0 : else if (mask->hdr.next_proto_id != 0 &&
2884 : : mask->hdr.next_proto_id != 0xff)
2885 : 0 : return rte_flow_error_set(error, EINVAL,
2886 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2887 : : "partial mask is not supported"
2888 : : " for protocol");
2889 [ # # ]: 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2890 : : acc_mask ? (const uint8_t *)acc_mask
2891 : : : (const uint8_t *)&nic_mask,
2892 : : sizeof(struct rte_flow_item_ipv4),
2893 : : range_accepted, error);
2894 : : if (ret < 0)
2895 : : return ret;
2896 : : return 0;
2897 : : }
2898 : :
2899 : : /**
2900 : : * Validate IPV6 item.
2901 : : *
2902 : : * @param[in] item
2903 : : * Item specification.
2904 : : * @param[in] item_flags
2905 : : * Bit-fields that holds the items detected until now.
2906 : : * @param[in] last_item
2907 : : * Previous validated item in the pattern items.
2908 : : * @param[in] ether_type
2909 : : * Type in the ethernet layer header (including dot1q).
2910 : : * @param[in] acc_mask
2911 : : * Acceptable mask, if NULL default internal default mask
2912 : : * will be used to check whether item fields are supported.
2913 : : * @param[out] error
2914 : : * Pointer to error structure.
2915 : : *
2916 : : * @return
2917 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2918 : : */
2919 : : int
2920 : 0 : mlx5_flow_validate_item_ipv6(const struct rte_eth_dev *dev,
2921 : : const struct rte_flow_item *item,
2922 : : uint64_t item_flags,
2923 : : uint64_t last_item,
2924 : : uint16_t ether_type,
2925 : : const struct rte_flow_item_ipv6 *acc_mask,
2926 : : struct rte_flow_error *error)
2927 : : {
2928 : 0 : const struct rte_flow_item_ipv6 *mask = item->mask;
2929 : 0 : const struct rte_flow_item_ipv6 *spec = item->spec;
2930 : 0 : const struct rte_flow_item_ipv6 nic_mask = {
2931 : : .hdr = {
2932 : : .src_addr = RTE_IPV6_MASK_FULL,
2933 : : .dst_addr = RTE_IPV6_MASK_FULL,
2934 : : .vtc_flow = RTE_BE32(0xffffffff),
2935 : : .proto = 0xff,
2936 : : },
2937 : : };
2938 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2939 [ # # ]: 0 : const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2940 : : MLX5_FLOW_LAYER_OUTER_L3;
2941 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2942 : : MLX5_FLOW_LAYER_OUTER_L4;
2943 : : int ret;
2944 : : uint8_t next_proto = 0xFF;
2945 : : const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2946 : : MLX5_FLOW_LAYER_OUTER_VLAN |
2947 : : MLX5_FLOW_LAYER_INNER_VLAN);
2948 : :
2949 [ # # ]: 0 : if ((last_item & l2_vlan) && ether_type &&
2950 [ # # ]: 0 : ether_type != RTE_ETHER_TYPE_IPV6)
2951 : 0 : return rte_flow_error_set(error, EINVAL,
2952 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2953 : : "IPv6 cannot follow L2/VLAN layer "
2954 : : "which ether type is not IPv6");
2955 [ # # # # : 0 : if (mask && mask->hdr.proto == UINT8_MAX && spec)
# # ]
2956 : 0 : next_proto = spec->hdr.proto;
2957 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_IPIP) {
2958 [ # # ]: 0 : if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2959 : 0 : return rte_flow_error_set(error, EINVAL,
2960 : : RTE_FLOW_ERROR_TYPE_ITEM,
2961 : : item,
2962 : : "multiple tunnel "
2963 : : "not supported");
2964 : : }
2965 : 0 : if (next_proto == IPPROTO_HOPOPTS ||
2966 [ # # ]: 0 : next_proto == IPPROTO_ROUTING ||
2967 : : next_proto == IPPROTO_FRAGMENT ||
2968 : : next_proto == IPPROTO_AH ||
2969 [ # # ]: 0 : next_proto == IPPROTO_DSTOPTS ||
2970 [ # # ]: 0 : (!mlx5_hws_active(dev) && next_proto == IPPROTO_ESP))
2971 : 0 : return rte_flow_error_set(error, EINVAL,
2972 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2973 : : "IPv6 proto (next header) should "
2974 : : "not be set as extension header");
2975 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_IPIP)
2976 : 0 : return rte_flow_error_set(error, EINVAL,
2977 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2978 : : "wrong tunnel type - IPv4 specified "
2979 : : "but IPv6 item provided");
2980 [ # # ]: 0 : if (item_flags & l3m)
2981 : 0 : return rte_flow_error_set(error, ENOTSUP,
2982 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2983 : : "multiple L3 layers not supported");
2984 [ # # ]: 0 : else if (item_flags & l4m)
2985 : 0 : return rte_flow_error_set(error, EINVAL,
2986 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2987 : : "L3 cannot follow an L4 layer.");
2988 [ # # ]: 0 : else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2989 : : !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2990 : 0 : return rte_flow_error_set(error, EINVAL,
2991 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2992 : : "L3 cannot follow an NVGRE layer.");
2993 [ # # ]: 0 : if (!mask)
2994 : : mask = &rte_flow_item_ipv6_mask;
2995 [ # # ]: 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2996 : : acc_mask ? (const uint8_t *)acc_mask
2997 : : : (const uint8_t *)&nic_mask,
2998 : : sizeof(struct rte_flow_item_ipv6),
2999 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3000 : : if (ret < 0)
3001 : : return ret;
3002 : : return 0;
3003 : : }
3004 : :
3005 : : /**
3006 : : * Validate UDP item.
3007 : : *
3008 : : * @param[in] item
3009 : : * Item specification.
3010 : : * @param[in] item_flags
3011 : : * Bit-fields that holds the items detected until now.
3012 : : * @param[in] target_protocol
3013 : : * The next protocol in the previous item.
3014 : : * @param[in] flow_mask
3015 : : * mlx5 flow-specific (DV, verbs, etc.) supported header fields mask.
3016 : : * @param[out] error
3017 : : * Pointer to error structure.
3018 : : *
3019 : : * @return
3020 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3021 : : */
3022 : : int
3023 : 0 : mlx5_flow_validate_item_udp(const struct rte_eth_dev *dev,
3024 : : const struct rte_flow_item *item,
3025 : : uint64_t item_flags,
3026 : : uint8_t target_protocol,
3027 : : struct rte_flow_error *error)
3028 : : {
3029 : 0 : const struct rte_flow_item_udp *mask = item->mask;
3030 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
3031 [ # # ]: 0 : const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
3032 : : MLX5_FLOW_LAYER_OUTER_L3;
3033 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
3034 : : MLX5_FLOW_LAYER_OUTER_L4;
3035 : : int ret;
3036 : :
3037 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
3038 [ # # ]: 0 : if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
3039 : 0 : return rte_flow_error_set(error, EINVAL,
3040 : : RTE_FLOW_ERROR_TYPE_ITEM,
3041 : : item, "protocol filtering not compatible with UDP layer");
3042 [ # # ]: 0 : if (!(item_flags & l3m))
3043 : 0 : return rte_flow_error_set(error, EINVAL,
3044 : : RTE_FLOW_ERROR_TYPE_ITEM,
3045 : : item,
3046 : : "L3 is mandatory to filter on L4");
3047 : : }
3048 [ # # ]: 0 : if (item_flags & l4m)
3049 : 0 : return rte_flow_error_set(error, EINVAL,
3050 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3051 : : "multiple L4 layers not supported");
3052 [ # # ]: 0 : if (!mask)
3053 : : mask = &rte_flow_item_udp_mask;
3054 : 0 : ret = mlx5_flow_item_acceptable
3055 : : (dev, item, (const uint8_t *)mask,
3056 : : (const uint8_t *)&rte_flow_item_udp_mask,
3057 : : sizeof(struct rte_flow_item_udp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
3058 : : error);
3059 : : if (ret < 0)
3060 : : return ret;
3061 : : return 0;
3062 : : }
3063 : :
3064 : : /**
3065 : : * Validate TCP item.
3066 : : *
3067 : : * @param[in] item
3068 : : * Item specification.
3069 : : * @param[in] item_flags
3070 : : * Bit-fields that holds the items detected until now.
3071 : : * @param[in] target_protocol
3072 : : * The next protocol in the previous item.
3073 : : * @param[out] error
3074 : : * Pointer to error structure.
3075 : : *
3076 : : * @return
3077 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3078 : : */
3079 : : int
3080 : 0 : mlx5_flow_validate_item_tcp(const struct rte_eth_dev *dev,
3081 : : const struct rte_flow_item *item,
3082 : : uint64_t item_flags,
3083 : : uint8_t target_protocol,
3084 : : const struct rte_flow_item_tcp *flow_mask,
3085 : : struct rte_flow_error *error)
3086 : : {
3087 : 0 : const struct rte_flow_item_tcp *mask = item->mask;
3088 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
3089 [ # # ]: 0 : const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
3090 : : MLX5_FLOW_LAYER_OUTER_L3;
3091 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
3092 : : MLX5_FLOW_LAYER_OUTER_L4;
3093 : : int ret;
3094 : :
3095 : : MLX5_ASSERT(flow_mask);
3096 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
3097 [ # # ]: 0 : if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
3098 : 0 : return rte_flow_error_set(error, EINVAL,
3099 : : RTE_FLOW_ERROR_TYPE_ITEM,
3100 : : item, "protocol filtering not compatible with TCP layer");
3101 [ # # ]: 0 : if (!(item_flags & l3m))
3102 : 0 : return rte_flow_error_set(error, EINVAL,
3103 : : RTE_FLOW_ERROR_TYPE_ITEM,
3104 : : item, "L3 is mandatory to filter on L4");
3105 : : }
3106 [ # # ]: 0 : if (item_flags & l4m)
3107 : 0 : return rte_flow_error_set(error, EINVAL,
3108 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3109 : : "multiple L4 layers not supported");
3110 [ # # ]: 0 : if (!mask)
3111 : : mask = &rte_flow_item_tcp_mask;
3112 : 0 : ret = mlx5_flow_item_acceptable
3113 : : (dev, item, (const uint8_t *)mask,
3114 : : (const uint8_t *)flow_mask,
3115 : : sizeof(struct rte_flow_item_tcp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
3116 : : error);
3117 : : if (ret < 0)
3118 : : return ret;
3119 : : return 0;
3120 : : }
3121 : :
3122 : : /**
3123 : : * Validate VXLAN item.
3124 : : *
3125 : : * @param[in] dev
3126 : : * Pointer to the Ethernet device structure.
3127 : : * @param[in] udp_dport
3128 : : * UDP destination port
3129 : : * @param[in] item
3130 : : * Item specification.
3131 : : * @param[in] item_flags
3132 : : * Bit-fields that holds the items detected until now.
3133 : : * @param root
3134 : : * Whether action is on root table.
3135 : : * @param[out] error
3136 : : * Pointer to error structure.
3137 : : *
3138 : : * @return
3139 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3140 : : */
3141 : : int
3142 : 0 : mlx5_flow_validate_item_vxlan(struct rte_eth_dev *dev,
3143 : : uint16_t udp_dport,
3144 : : const struct rte_flow_item *item,
3145 : : uint64_t item_flags,
3146 : : bool root,
3147 : : struct rte_flow_error *error)
3148 : : {
3149 : 0 : const struct rte_flow_item_vxlan *spec = item->spec;
3150 : 0 : const struct rte_flow_item_vxlan *mask = item->mask;
3151 : : int ret;
3152 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3153 : : union vni {
3154 : : uint32_t vlan_id;
3155 : : uint8_t vni[4];
3156 : 0 : } id = { .vlan_id = 0, };
3157 : 0 : const struct rte_flow_item_vxlan nic_mask = {
3158 : : .hdr.vni = { 0xff, 0xff, 0xff },
3159 : : .hdr.rsvd1 = 0xff,
3160 : : };
3161 : : const struct rte_flow_item_vxlan *valid_mask;
3162 : :
3163 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3164 : 0 : return rte_flow_error_set(error, ENOTSUP,
3165 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3166 : : "multiple tunnel layers not"
3167 : : " supported");
3168 : : /* HWS can match entire VXLAN, VXLAN-GBP and VXLAN-GPE headers */
3169 [ # # ]: 0 : if (mlx5_hws_active(dev))
3170 : : return 0;
3171 : : valid_mask = &rte_flow_item_vxlan_mask;
3172 : : /*
3173 : : * Verify only UDPv4 is present as defined in
3174 : : * https://tools.ietf.org/html/rfc7348
3175 : : */
3176 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
3177 : 0 : return rte_flow_error_set(error, EINVAL,
3178 : : RTE_FLOW_ERROR_TYPE_ITEM,
3179 : : item, "no outer UDP layer found");
3180 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
3181 : 0 : return rte_flow_error_set(error, ENOTSUP,
3182 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3183 : : "VXLAN tunnel must be fully defined");
3184 [ # # ]: 0 : if (!mask)
3185 : : mask = &rte_flow_item_vxlan_mask;
3186 : :
3187 [ # # ]: 0 : if (priv->sh->steering_format_version !=
3188 : : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5 ||
3189 [ # # ]: 0 : !udp_dport || udp_dport == MLX5_UDP_PORT_VXLAN) {
3190 : : /* non-root table */
3191 [ # # # # ]: 0 : if (!root && priv->sh->misc5_cap)
3192 : : valid_mask = &nic_mask;
3193 : : /* Group zero in NIC domain */
3194 [ # # # # ]: 0 : if (!root && priv->sh->tunnel_header_0_1)
3195 : : valid_mask = &nic_mask;
3196 : : }
3197 : 0 : ret = mlx5_flow_item_acceptable
3198 : : (dev, item, (const uint8_t *)mask,
3199 : : (const uint8_t *)valid_mask,
3200 : : sizeof(struct rte_flow_item_vxlan),
3201 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3202 : : if (ret < 0)
3203 : : return ret;
3204 : : if (spec) {
3205 : : memcpy(&id.vni[1], spec->hdr.vni, 3);
3206 : : memcpy(&id.vni[1], mask->hdr.vni, 3);
3207 : : }
3208 : : return 0;
3209 : : }
3210 : :
3211 : : /**
3212 : : * Validate VXLAN_GPE item.
3213 : : *
3214 : : * @param[in] item
3215 : : * Item specification.
3216 : : * @param[in] item_flags
3217 : : * Bit-fields that holds the items detected until now.
3218 : : * @param[in] priv
3219 : : * Pointer to the private data structure.
3220 : : * @param[in] target_protocol
3221 : : * The next protocol in the previous item.
3222 : : * @param[out] error
3223 : : * Pointer to error structure.
3224 : : *
3225 : : * @return
3226 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3227 : : */
3228 : : int
3229 : 0 : mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
3230 : : uint64_t item_flags,
3231 : : struct rte_eth_dev *dev,
3232 : : struct rte_flow_error *error)
3233 : : {
3234 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3235 : : const struct rte_flow_item_vxlan_gpe *spec = item->spec;
3236 : 0 : const struct rte_flow_item_vxlan_gpe *mask = item->mask;
3237 : : int ret;
3238 : : union vni {
3239 : : uint32_t vlan_id;
3240 : : uint8_t vni[4];
3241 : 0 : } id = { .vlan_id = 0, };
3242 : :
3243 : 0 : struct rte_flow_item_vxlan_gpe nic_mask = {
3244 : : .vni = { 0xff, 0xff, 0xff },
3245 : : .protocol = 0xff,
3246 : : .flags = 0xff,
3247 : : };
3248 : :
3249 [ # # ]: 0 : if (!priv->sh->config.l3_vxlan_en)
3250 : 0 : return rte_flow_error_set(error, ENOTSUP,
3251 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3252 : : "L3 VXLAN is not enabled by device"
3253 : : " parameter and/or not configured in"
3254 : : " firmware");
3255 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3256 : 0 : return rte_flow_error_set(error, ENOTSUP,
3257 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3258 : : "multiple tunnel layers not"
3259 : : " supported");
3260 : : /*
3261 : : * Verify only UDPv4 is present as defined in
3262 : : * https://tools.ietf.org/html/rfc7348
3263 : : */
3264 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
3265 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
3266 : 0 : return rte_flow_error_set(error, EINVAL,
3267 : : RTE_FLOW_ERROR_TYPE_ITEM,
3268 : : item, "no outer UDP layer found");
3269 : : }
3270 [ # # ]: 0 : if (!mask)
3271 : : mask = &rte_flow_item_vxlan_gpe_mask;
3272 [ # # ]: 0 : if (mlx5_hws_active(dev) ||
3273 [ # # ]: 0 : (priv->sh->misc5_cap && priv->sh->tunnel_header_0_1)) {
3274 : 0 : nic_mask.rsvd0[0] = 0xff;
3275 : 0 : nic_mask.rsvd0[1] = 0xff;
3276 : 0 : nic_mask.rsvd1 = 0xff;
3277 : : }
3278 : 0 : ret = mlx5_flow_item_acceptable
3279 : : (dev, item, (const uint8_t *)mask,
3280 : : (const uint8_t *)&nic_mask,
3281 : : sizeof(struct rte_flow_item_vxlan_gpe),
3282 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3283 [ # # ]: 0 : if (ret < 0)
3284 : : return ret;
3285 : : if (spec) {
3286 : : memcpy(&id.vni[1], spec->hdr.vni, 3);
3287 : : memcpy(&id.vni[1], mask->hdr.vni, 3);
3288 : : }
3289 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
3290 : 0 : return rte_flow_error_set(error, ENOTSUP,
3291 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3292 : : "VXLAN-GPE tunnel must be fully"
3293 : : " defined");
3294 : : return 0;
3295 : : }
3296 : : /**
3297 : : * Validate GRE Key item.
3298 : : *
3299 : : * @param[in] item
3300 : : * Item specification.
3301 : : * @param[in] item_flags
3302 : : * Bit flags to mark detected items.
3303 : : * @param[in] gre_item
3304 : : * Pointer to gre_item
3305 : : * @param[out] error
3306 : : * Pointer to error structure.
3307 : : *
3308 : : * @return
3309 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3310 : : */
3311 : : int
3312 : 0 : mlx5_flow_validate_item_gre_key(const struct rte_eth_dev *dev,
3313 : : const struct rte_flow_item *item,
3314 : : uint64_t item_flags,
3315 : : const struct rte_flow_item *gre_item,
3316 : : struct rte_flow_error *error)
3317 : : {
3318 : 0 : const rte_be32_t *mask = item->mask;
3319 : : int ret = 0;
3320 : 0 : rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
3321 : : const struct rte_flow_item_gre *gre_spec;
3322 : : const struct rte_flow_item_gre *gre_mask;
3323 : :
3324 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_GRE_KEY)
3325 : 0 : return rte_flow_error_set(error, ENOTSUP,
3326 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3327 : : "Multiple GRE key not support");
3328 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_GRE))
3329 : 0 : return rte_flow_error_set(error, ENOTSUP,
3330 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3331 : : "No preceding GRE header");
3332 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_INNER)
3333 : 0 : return rte_flow_error_set(error, ENOTSUP,
3334 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3335 : : "GRE key following a wrong item");
3336 : 0 : gre_mask = gre_item->mask;
3337 [ # # ]: 0 : if (!gre_mask)
3338 : : gre_mask = &rte_flow_item_gre_mask;
3339 : 0 : gre_spec = gre_item->spec;
3340 [ # # # # ]: 0 : if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
3341 [ # # ]: 0 : !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
3342 : 0 : return rte_flow_error_set(error, EINVAL,
3343 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3344 : : "Key bit must be on");
3345 : :
3346 [ # # ]: 0 : if (!mask)
3347 : : mask = &gre_key_default_mask;
3348 : 0 : ret = mlx5_flow_item_acceptable
3349 : : (dev, item, (const uint8_t *)mask,
3350 : : (const uint8_t *)&gre_key_default_mask,
3351 : : sizeof(rte_be32_t), MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3352 : 0 : return ret;
3353 : : }
3354 : :
3355 : : /**
3356 : : * Validate GRE optional item.
3357 : : *
3358 : : * @param[in] dev
3359 : : * Pointer to the Ethernet device structure.
3360 : : * @param[in] item
3361 : : * Item specification.
3362 : : * @param[in] item_flags
3363 : : * Bit flags to mark detected items.
3364 : : * @param[in] attr
3365 : : * Flow rule attributes.
3366 : : * @param[in] gre_item
3367 : : * Pointer to gre_item
3368 : : * @param[out] error
3369 : : * Pointer to error structure.
3370 : : *
3371 : : * @return
3372 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3373 : : */
3374 : : int
3375 : 0 : mlx5_flow_validate_item_gre_option(struct rte_eth_dev *dev,
3376 : : const struct rte_flow_item *item,
3377 : : uint64_t item_flags,
3378 : : const struct rte_flow_attr *attr,
3379 : : const struct rte_flow_item *gre_item,
3380 : : struct rte_flow_error *error)
3381 : : {
3382 : 0 : const struct rte_flow_item_gre *gre_spec = gre_item->spec;
3383 : 0 : const struct rte_flow_item_gre *gre_mask = gre_item->mask;
3384 : 0 : const struct rte_flow_item_gre_opt *spec = item->spec;
3385 : 0 : const struct rte_flow_item_gre_opt *mask = item->mask;
3386 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3387 : : int ret = 0;
3388 : 0 : struct rte_flow_item_gre_opt nic_mask = {
3389 : : .checksum_rsvd = {
3390 : : .checksum = RTE_BE16(UINT16_MAX),
3391 : : .reserved1 = 0x0,
3392 : : },
3393 : : .key = {
3394 : : .key = RTE_BE32(UINT32_MAX),
3395 : : },
3396 : : .sequence = {
3397 : : .sequence = RTE_BE32(UINT32_MAX),
3398 : : },
3399 : : };
3400 : :
3401 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_GRE))
3402 : 0 : return rte_flow_error_set(error, ENOTSUP,
3403 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3404 : : "No preceding GRE header");
3405 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_INNER)
3406 : 0 : return rte_flow_error_set(error, ENOTSUP,
3407 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3408 : : "GRE option following a wrong item");
3409 [ # # # # : 0 : if ((!spec && !mlx5_hws_active(dev)) || !mask)
# # ]
3410 : 0 : return rte_flow_error_set(error, EINVAL,
3411 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3412 : : "At least one field gre_option(checksum/key/sequence) must be specified");
3413 [ # # ]: 0 : if (!gre_mask)
3414 : : gre_mask = &rte_flow_item_gre_mask;
3415 [ # # ]: 0 : if (mask->checksum_rsvd.checksum)
3416 [ # # # # ]: 0 : if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x8000)) &&
3417 [ # # ]: 0 : !(gre_spec->c_rsvd0_ver & RTE_BE16(0x8000)))
3418 : 0 : return rte_flow_error_set(error, EINVAL,
3419 : : RTE_FLOW_ERROR_TYPE_ITEM,
3420 : : item,
3421 : : "Checksum bit must be on");
3422 [ # # ]: 0 : if (mask->key.key)
3423 [ # # # # ]: 0 : if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
3424 [ # # ]: 0 : !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
3425 : 0 : return rte_flow_error_set(error, EINVAL,
3426 : : RTE_FLOW_ERROR_TYPE_ITEM,
3427 : : item, "Key bit must be on");
3428 [ # # ]: 0 : if (mask->sequence.sequence)
3429 [ # # # # ]: 0 : if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x1000)) &&
3430 [ # # ]: 0 : !(gre_spec->c_rsvd0_ver & RTE_BE16(0x1000)))
3431 : 0 : return rte_flow_error_set(error, EINVAL,
3432 : : RTE_FLOW_ERROR_TYPE_ITEM,
3433 : : item,
3434 : : "Sequence bit must be on");
3435 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
3436 [ # # # # ]: 0 : if (mask->checksum_rsvd.checksum || mask->sequence.sequence) {
3437 [ # # ]: 0 : if (priv->sh->steering_format_version ==
3438 : 0 : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5 ||
3439 [ # # ]: 0 : ((attr->group ||
3440 [ # # # # ]: 0 : (attr->transfer && priv->fdb_def_rule)) &&
3441 [ # # ]: 0 : !priv->sh->misc5_cap) ||
3442 [ # # ]: 0 : (!(priv->sh->tunnel_header_0_1 &&
3443 [ # # ]: 0 : priv->sh->tunnel_header_2_3) &&
3444 : 0 : !attr->group &&
3445 [ # # # # ]: 0 : (!attr->transfer || !priv->fdb_def_rule)))
3446 : 0 : return rte_flow_error_set
3447 : : (error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM,
3448 : : item, "Checksum/Sequence not supported");
3449 : : }
3450 : : }
3451 : 0 : ret = mlx5_flow_item_acceptable
3452 : : (dev, item, (const uint8_t *)mask,
3453 : : (const uint8_t *)&nic_mask,
3454 : : sizeof(struct rte_flow_item_gre_opt),
3455 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3456 : 0 : return ret;
3457 : : }
3458 : :
3459 : : /**
3460 : : * Validate GRE item.
3461 : : *
3462 : : * @param[in] item
3463 : : * Item specification.
3464 : : * @param[in] item_flags
3465 : : * Bit flags to mark detected items.
3466 : : * @param[in] target_protocol
3467 : : * The next protocol in the previous item.
3468 : : * @param[out] error
3469 : : * Pointer to error structure.
3470 : : *
3471 : : * @return
3472 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3473 : : */
3474 : : int
3475 : 0 : mlx5_flow_validate_item_gre(const struct rte_eth_dev *dev,
3476 : : const struct rte_flow_item *item,
3477 : : uint64_t item_flags,
3478 : : uint8_t target_protocol,
3479 : : struct rte_flow_error *error)
3480 : : {
3481 : : const struct rte_flow_item_gre *spec __rte_unused = item->spec;
3482 : 0 : const struct rte_flow_item_gre *mask = item->mask;
3483 : : int ret;
3484 : 0 : const struct rte_flow_item_gre nic_mask = {
3485 : : .c_rsvd0_ver = RTE_BE16(0xB000),
3486 : : .protocol = RTE_BE16(UINT16_MAX),
3487 : : };
3488 : :
3489 [ # # ]: 0 : if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
3490 : 0 : return rte_flow_error_set(error, EINVAL,
3491 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3492 : : "protocol filtering not compatible"
3493 : : " with this GRE layer");
3494 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3495 : 0 : return rte_flow_error_set(error, ENOTSUP,
3496 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3497 : : "multiple tunnel layers not"
3498 : : " supported");
3499 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
3500 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
3501 : 0 : return rte_flow_error_set(error, ENOTSUP,
3502 : : RTE_FLOW_ERROR_TYPE_ITEM,
3503 : : item, "L3 Layer is missing");
3504 : : }
3505 [ # # ]: 0 : if (!mask)
3506 : : mask = &rte_flow_item_gre_mask;
3507 : 0 : ret = mlx5_flow_item_acceptable
3508 : : (dev, item, (const uint8_t *)mask,
3509 : : (const uint8_t *)&nic_mask,
3510 : : sizeof(struct rte_flow_item_gre), MLX5_ITEM_RANGE_NOT_ACCEPTED,
3511 : : error);
3512 : : if (ret < 0)
3513 : : return ret;
3514 : : #ifndef HAVE_MLX5DV_DR
3515 : : #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
3516 : : if (spec && (spec->protocol & mask->protocol))
3517 : : return rte_flow_error_set(error, ENOTSUP,
3518 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3519 : : "without MPLS support the"
3520 : : " specification cannot be used for"
3521 : : " filtering");
3522 : : #endif
3523 : : #endif
3524 : : return 0;
3525 : : }
3526 : :
3527 : : /**
3528 : : * Validate Geneve item.
3529 : : *
3530 : : * @param[in] item
3531 : : * Item specification.
3532 : : * @param[in] itemFlags
3533 : : * Bit-fields that holds the items detected until now.
3534 : : * @param[in] enPriv
3535 : : * Pointer to the private data structure.
3536 : : * @param[out] error
3537 : : * Pointer to error structure.
3538 : : *
3539 : : * @return
3540 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3541 : : */
3542 : :
3543 : : int
3544 : 0 : mlx5_flow_validate_item_geneve(const struct rte_flow_item *item,
3545 : : uint64_t item_flags,
3546 : : struct rte_eth_dev *dev,
3547 : : struct rte_flow_error *error)
3548 : : {
3549 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3550 : 0 : const struct rte_flow_item_geneve *spec = item->spec;
3551 : 0 : const struct rte_flow_item_geneve *mask = item->mask;
3552 : : int ret;
3553 : : uint16_t gbhdr;
3554 [ # # ]: 0 : uint8_t opt_len = priv->sh->cdev->config.hca_attr.geneve_max_opt_len ?
3555 : : MLX5_GENEVE_OPT_LEN_1 : MLX5_GENEVE_OPT_LEN_0;
3556 : 0 : const struct rte_flow_item_geneve nic_mask = {
3557 : : .ver_opt_len_o_c_rsvd0 = RTE_BE16(0x3f80),
3558 : : .vni = { 0xff, 0xff, 0xff },
3559 : : .protocol = RTE_BE16(UINT16_MAX),
3560 : : };
3561 : :
3562 [ # # ]: 0 : if (!priv->sh->cdev->config.hca_attr.tunnel_stateless_geneve_rx)
3563 : 0 : return rte_flow_error_set(error, ENOTSUP,
3564 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3565 : : "L3 Geneve is not enabled by device"
3566 : : " parameter and/or not configured in"
3567 : : " firmware");
3568 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3569 : 0 : return rte_flow_error_set(error, ENOTSUP,
3570 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3571 : : "multiple tunnel layers not"
3572 : : " supported");
3573 : : /*
3574 : : * Verify only UDPv4 is present as defined in
3575 : : * https://tools.ietf.org/html/rfc7348
3576 : : */
3577 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
3578 : 0 : return rte_flow_error_set(error, EINVAL,
3579 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3580 : : "no outer UDP layer found");
3581 [ # # ]: 0 : if (!mask)
3582 : : mask = &rte_flow_item_geneve_mask;
3583 : 0 : ret = mlx5_flow_item_acceptable
3584 : : (dev, item, (const uint8_t *)mask,
3585 : : (const uint8_t *)&nic_mask,
3586 : : sizeof(struct rte_flow_item_geneve),
3587 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3588 [ # # ]: 0 : if (ret)
3589 : : return ret;
3590 [ # # ]: 0 : if (spec) {
3591 [ # # ]: 0 : gbhdr = rte_be_to_cpu_16(spec->ver_opt_len_o_c_rsvd0);
3592 [ # # ]: 0 : if (MLX5_GENEVE_VER_VAL(gbhdr) ||
3593 [ # # # # ]: 0 : MLX5_GENEVE_CRITO_VAL(gbhdr) ||
3594 [ # # ]: 0 : MLX5_GENEVE_RSVD_VAL(gbhdr) || spec->rsvd1)
3595 : 0 : return rte_flow_error_set(error, ENOTSUP,
3596 : : RTE_FLOW_ERROR_TYPE_ITEM,
3597 : : item,
3598 : : "Geneve protocol unsupported"
3599 : : " fields are being used");
3600 [ # # ]: 0 : if (MLX5_GENEVE_OPTLEN_VAL(gbhdr) > opt_len)
3601 : 0 : return rte_flow_error_set
3602 : : (error, ENOTSUP,
3603 : : RTE_FLOW_ERROR_TYPE_ITEM,
3604 : : item,
3605 : : "Unsupported Geneve options length");
3606 : : }
3607 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
3608 : 0 : return rte_flow_error_set
3609 : : (error, ENOTSUP,
3610 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3611 : : "Geneve tunnel must be fully defined");
3612 : : return 0;
3613 : : }
3614 : :
3615 : : /**
3616 : : * Validate Geneve TLV option item.
3617 : : *
3618 : : * @param[in] item
3619 : : * Item specification.
3620 : : * @param[in] last_item
3621 : : * Previous validated item in the pattern items.
3622 : : * @param[in] geneve_item
3623 : : * Previous GENEVE item specification.
3624 : : * @param[in] dev
3625 : : * Pointer to the rte_eth_dev structure.
3626 : : * @param[out] error
3627 : : * Pointer to error structure.
3628 : : *
3629 : : * @return
3630 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3631 : : */
3632 : : int
3633 : 0 : mlx5_flow_validate_item_geneve_opt(const struct rte_flow_item *item,
3634 : : uint64_t last_item,
3635 : : const struct rte_flow_item *geneve_item,
3636 : : struct rte_eth_dev *dev,
3637 : : struct rte_flow_error *error)
3638 : : {
3639 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3640 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
3641 : : struct mlx5_geneve_tlv_option_resource *geneve_opt_resource;
3642 : 0 : struct mlx5_hca_attr *hca_attr = &sh->cdev->config.hca_attr;
3643 : 0 : uint8_t data_max_supported =
3644 : 0 : hca_attr->max_geneve_tlv_option_data_len * 4;
3645 : : const struct rte_flow_item_geneve *geneve_spec;
3646 : : const struct rte_flow_item_geneve *geneve_mask;
3647 : 0 : const struct rte_flow_item_geneve_opt *spec = item->spec;
3648 : 0 : const struct rte_flow_item_geneve_opt *mask = item->mask;
3649 : : unsigned int i;
3650 : : unsigned int data_len;
3651 : : uint8_t tlv_option_len;
3652 : : uint16_t optlen_m, optlen_v;
3653 : : const struct rte_flow_item_geneve_opt full_mask = {
3654 : : .option_class = RTE_BE16(0xffff),
3655 : : .option_type = 0xff,
3656 : : .option_len = 0x1f,
3657 : : };
3658 : :
3659 [ # # ]: 0 : if (!mask)
3660 : : mask = &rte_flow_item_geneve_opt_mask;
3661 [ # # ]: 0 : if (!spec)
3662 : 0 : return rte_flow_error_set
3663 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3664 : : "Geneve TLV opt class/type/length must be specified");
3665 [ # # ]: 0 : if ((uint32_t)spec->option_len > MLX5_GENEVE_OPTLEN_MASK)
3666 : 0 : return rte_flow_error_set
3667 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3668 : : "Geneve TLV opt length exceeds the limit (31)");
3669 : : /* Check if class type and length masks are full. */
3670 [ # # ]: 0 : if (full_mask.option_class != mask->option_class ||
3671 : 0 : full_mask.option_type != mask->option_type ||
3672 [ # # ]: 0 : full_mask.option_len != (mask->option_len & full_mask.option_len))
3673 : 0 : return rte_flow_error_set
3674 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3675 : : "Geneve TLV opt class/type/length masks must be full");
3676 : : /* Check if length is supported */
3677 [ # # ]: 0 : if ((uint32_t)spec->option_len >
3678 : : hca_attr->max_geneve_tlv_option_data_len)
3679 : 0 : return rte_flow_error_set
3680 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3681 : : "Geneve TLV opt length not supported");
3682 [ # # ]: 0 : if (hca_attr->max_geneve_tlv_options > 1)
3683 : 0 : DRV_LOG(DEBUG,
3684 : : "max_geneve_tlv_options supports more than 1 option");
3685 : : /* Check GENEVE item preceding. */
3686 [ # # # # ]: 0 : if (!geneve_item || !(last_item & MLX5_FLOW_LAYER_GENEVE))
3687 : 0 : return rte_flow_error_set
3688 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3689 : : "Geneve opt item must be preceded with Geneve item");
3690 : 0 : geneve_spec = geneve_item->spec;
3691 [ # # ]: 0 : geneve_mask = geneve_item->mask ? geneve_item->mask :
3692 : : &rte_flow_item_geneve_mask;
3693 : : /* Check if GENEVE TLV option size doesn't exceed option length */
3694 [ # # # # ]: 0 : if (geneve_spec && (geneve_mask->ver_opt_len_o_c_rsvd0 ||
3695 [ # # ]: 0 : geneve_spec->ver_opt_len_o_c_rsvd0)) {
3696 : 0 : tlv_option_len = spec->option_len & mask->option_len;
3697 [ # # ]: 0 : optlen_v = rte_be_to_cpu_16(geneve_spec->ver_opt_len_o_c_rsvd0);
3698 : 0 : optlen_v = MLX5_GENEVE_OPTLEN_VAL(optlen_v);
3699 [ # # ]: 0 : optlen_m = rte_be_to_cpu_16(geneve_mask->ver_opt_len_o_c_rsvd0);
3700 : 0 : optlen_m = MLX5_GENEVE_OPTLEN_VAL(optlen_m);
3701 [ # # ]: 0 : if ((optlen_v & optlen_m) <= tlv_option_len)
3702 : 0 : return rte_flow_error_set
3703 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3704 : : "GENEVE TLV option length exceeds optlen");
3705 : : }
3706 : : /* Check if length is 0 or data is 0. */
3707 [ # # # # ]: 0 : if (spec->data == NULL || spec->option_len == 0)
3708 : 0 : return rte_flow_error_set
3709 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3710 : : "Geneve TLV opt with zero data/length not supported");
3711 : : /* Check not all data & mask are 0. */
3712 : 0 : data_len = spec->option_len * 4;
3713 [ # # ]: 0 : if (mask->data == NULL) {
3714 [ # # ]: 0 : for (i = 0; i < data_len; i++)
3715 [ # # ]: 0 : if (spec->data[i])
3716 : : break;
3717 [ # # ]: 0 : if (i == data_len)
3718 : 0 : return rte_flow_error_set(error, ENOTSUP,
3719 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3720 : : "Can't match on Geneve option data 0");
3721 : : } else {
3722 [ # # ]: 0 : for (i = 0; i < data_len; i++)
3723 [ # # ]: 0 : if (spec->data[i] & mask->data[i])
3724 : : break;
3725 [ # # ]: 0 : if (i == data_len)
3726 : 0 : return rte_flow_error_set(error, ENOTSUP,
3727 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3728 : : "Can't match on Geneve option data and mask 0");
3729 : : /* Check data mask supported. */
3730 [ # # ]: 0 : for (i = data_max_supported; i < data_len ; i++)
3731 [ # # ]: 0 : if (mask->data[i])
3732 : 0 : return rte_flow_error_set(error, ENOTSUP,
3733 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3734 : : "Data mask is of unsupported size");
3735 : : }
3736 : : /* Check GENEVE option is supported in NIC. */
3737 [ # # ]: 0 : if (!hca_attr->geneve_tlv_opt)
3738 : 0 : return rte_flow_error_set
3739 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3740 : : "Geneve TLV opt not supported");
3741 : : /* Check if we already have geneve option with different type/class. */
3742 : 0 : rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
3743 : 0 : geneve_opt_resource = sh->geneve_tlv_option_resource;
3744 [ # # ]: 0 : if (geneve_opt_resource != NULL)
3745 : 0 : if (geneve_opt_resource->option_class != spec->option_class ||
3746 [ # # ]: 0 : geneve_opt_resource->option_type != spec->option_type ||
3747 : : geneve_opt_resource->length != spec->option_len) {
3748 : : rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
3749 : 0 : return rte_flow_error_set(error, ENOTSUP,
3750 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3751 : : "Only one Geneve TLV option supported");
3752 : : }
3753 : : rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
3754 : 0 : return 0;
3755 : : }
3756 : :
3757 : : /**
3758 : : * Validate MPLS item.
3759 : : *
3760 : : * @param[in] dev
3761 : : * Pointer to the rte_eth_dev structure.
3762 : : * @param[in] item
3763 : : * Item specification.
3764 : : * @param[in] item_flags
3765 : : * Bit-fields that holds the items detected until now.
3766 : : * @param[in] prev_layer
3767 : : * The protocol layer indicated in previous item.
3768 : : * @param[out] error
3769 : : * Pointer to error structure.
3770 : : *
3771 : : * @return
3772 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3773 : : */
3774 : : int
3775 : 0 : mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev __rte_unused,
3776 : : const struct rte_flow_item *item __rte_unused,
3777 : : uint64_t item_flags __rte_unused,
3778 : : uint64_t prev_layer __rte_unused,
3779 : : struct rte_flow_error *error)
3780 : : {
3781 : : #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
3782 [ # # ]: 0 : const struct rte_flow_item_mpls hws_nic_mask = {
3783 : : .label_tc_s = {0xff, 0xff, 0xff},
3784 : : .ttl = 0xff
3785 : : };
3786 : : const struct rte_flow_item_mpls *nic_mask = !mlx5_hws_active(dev) ?
3787 [ # # ]: 0 : &rte_flow_item_mpls_mask : &hws_nic_mask;
3788 : 0 : const struct rte_flow_item_mpls *mask = item->mask;
3789 : : struct mlx5_priv *priv = dev->data->dev_private;
3790 : : int ret;
3791 : :
3792 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
3793 : : /* MPLS has HW support in HWS */
3794 [ # # ]: 0 : if (!priv->sh->dev_cap.mpls_en)
3795 : 0 : return rte_flow_error_set(error, ENOTSUP,
3796 : : RTE_FLOW_ERROR_TYPE_ITEM,
3797 : : item, "MPLS not supported or disabled in firmware configuration.");
3798 : : /* MPLS over UDP, GRE is allowed */
3799 [ # # ]: 0 : if (!(prev_layer & (MLX5_FLOW_LAYER_OUTER_L4_UDP |
3800 : : MLX5_FLOW_LAYER_GRE |
3801 : : MLX5_FLOW_LAYER_GRE_KEY)))
3802 : 0 : return rte_flow_error_set(error, EINVAL,
3803 : : RTE_FLOW_ERROR_TYPE_ITEM,
3804 : : item, "protocol filtering not compatible with MPLS layer");
3805 : : /* Multi-tunnel isn't allowed but MPLS over GRE is an exception. */
3806 [ # # ]: 0 : if ((item_flags & MLX5_FLOW_LAYER_TUNNEL) &&
3807 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_GRE))
3808 : 0 : return rte_flow_error_set(error, ENOTSUP,
3809 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3810 : : "multiple tunnel layers not supported");
3811 : : }
3812 [ # # ]: 0 : if (!mask)
3813 : : mask = nic_mask;
3814 : 0 : ret = mlx5_flow_item_acceptable
3815 : : (dev, item, (const uint8_t *)mask,
3816 : : (const uint8_t *)nic_mask,
3817 : : sizeof(struct rte_flow_item_mpls),
3818 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3819 : : if (ret < 0)
3820 : : return ret;
3821 : : return 0;
3822 : : #else
3823 : : return rte_flow_error_set(error, ENOTSUP,
3824 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3825 : : "MPLS is not supported by Verbs, please"
3826 : : " update.");
3827 : : #endif
3828 : : }
3829 : :
3830 : : /**
3831 : : * Validate NVGRE item.
3832 : : *
3833 : : * @param[in] item
3834 : : * Item specification.
3835 : : * @param[in] item_flags
3836 : : * Bit flags to mark detected items.
3837 : : * @param[in] target_protocol
3838 : : * The next protocol in the previous item.
3839 : : * @param[out] error
3840 : : * Pointer to error structure.
3841 : : *
3842 : : * @return
3843 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3844 : : */
3845 : : int
3846 : 0 : mlx5_flow_validate_item_nvgre(const struct rte_eth_dev *dev,
3847 : : const struct rte_flow_item *item,
3848 : : uint64_t item_flags,
3849 : : uint8_t target_protocol,
3850 : : struct rte_flow_error *error)
3851 : : {
3852 : 0 : const struct rte_flow_item_nvgre *mask = item->mask;
3853 : : int ret;
3854 : :
3855 [ # # ]: 0 : const struct rte_flow_item_nvgre hws_nic_mask = {
3856 : : .c_k_s_rsvd0_ver = RTE_BE16(0xB000),
3857 : : .protocol = RTE_BE16(UINT16_MAX),
3858 : : .tni = {0xff, 0xff, 0xff},
3859 : : .flow_id = 0xff
3860 : : };
3861 : : const struct rte_flow_item_nvgre *nic_mask = !mlx5_hws_active(dev) ?
3862 [ # # ]: 0 : &rte_flow_item_nvgre_mask : &hws_nic_mask;
3863 : :
3864 [ # # ]: 0 : if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
3865 : 0 : return rte_flow_error_set(error, EINVAL,
3866 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3867 : : "protocol filtering not compatible"
3868 : : " with this GRE layer");
3869 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3870 : 0 : return rte_flow_error_set(error, ENOTSUP,
3871 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3872 : : "multiple tunnel layers not"
3873 : : " supported");
3874 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
3875 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
3876 : 0 : return rte_flow_error_set(error, ENOTSUP,
3877 : : RTE_FLOW_ERROR_TYPE_ITEM,
3878 : : item, "L3 Layer is missing");
3879 : : }
3880 [ # # ]: 0 : if (!mask)
3881 : : mask = nic_mask;
3882 : 0 : ret = mlx5_flow_item_acceptable
3883 : : (dev, item, (const uint8_t *)mask,
3884 : : (const uint8_t *)nic_mask,
3885 : : sizeof(struct rte_flow_item_nvgre),
3886 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3887 : : if (ret < 0)
3888 : : return ret;
3889 : : return 0;
3890 : : }
3891 : :
3892 : : /**
3893 : : * Validate eCPRI item.
3894 : : *
3895 : : * @param[in] item
3896 : : * Item specification.
3897 : : * @param[in] item_flags
3898 : : * Bit-fields that holds the items detected until now.
3899 : : * @param[in] last_item
3900 : : * Previous validated item in the pattern items.
3901 : : * @param[in] ether_type
3902 : : * Type in the ethernet layer header (including dot1q).
3903 : : * @param[in] acc_mask
3904 : : * Acceptable mask, if NULL default internal default mask
3905 : : * will be used to check whether item fields are supported.
3906 : : * @param[out] error
3907 : : * Pointer to error structure.
3908 : : *
3909 : : * @return
3910 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3911 : : */
3912 : : int
3913 : 0 : mlx5_flow_validate_item_ecpri(const struct rte_eth_dev *dev,
3914 : : const struct rte_flow_item *item,
3915 : : uint64_t item_flags,
3916 : : uint64_t last_item,
3917 : : uint16_t ether_type,
3918 : : const struct rte_flow_item_ecpri *acc_mask,
3919 : : struct rte_flow_error *error)
3920 : : {
3921 : 0 : const struct rte_flow_item_ecpri *mask = item->mask;
3922 : 0 : const struct rte_flow_item_ecpri nic_mask = {
3923 : : .hdr = {
3924 : : .common = {
3925 : : .u32 =
3926 : : RTE_BE32(((const struct rte_ecpri_common_hdr) {
3927 : : .type = 0xFF,
3928 : : }).u32),
3929 : : },
3930 : : .dummy[0] = 0xFFFFFFFF,
3931 : : },
3932 : : };
3933 : : const uint64_t outer_l2_vlan = (MLX5_FLOW_LAYER_OUTER_L2 |
3934 : : MLX5_FLOW_LAYER_OUTER_VLAN);
3935 : : struct rte_flow_item_ecpri mask_lo;
3936 : :
3937 [ # # # # ]: 0 : if (!(last_item & outer_l2_vlan) &&
3938 : : last_item != MLX5_FLOW_LAYER_OUTER_L4_UDP)
3939 : 0 : return rte_flow_error_set(error, EINVAL,
3940 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3941 : : "eCPRI can only follow L2/VLAN layer or UDP layer");
3942 [ # # ]: 0 : if ((last_item & outer_l2_vlan) && ether_type &&
3943 [ # # ]: 0 : ether_type != RTE_ETHER_TYPE_ECPRI)
3944 : 0 : return rte_flow_error_set(error, EINVAL,
3945 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3946 : : "eCPRI cannot follow L2/VLAN layer which ether type is not 0xAEFE");
3947 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3948 : 0 : return rte_flow_error_set(error, EINVAL,
3949 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3950 : : "eCPRI with tunnel is not supported right now");
3951 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_OUTER_L3)
3952 : 0 : return rte_flow_error_set(error, ENOTSUP,
3953 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3954 : : "multiple L3 layers not supported");
3955 [ # # ]: 0 : else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP)
3956 : 0 : return rte_flow_error_set(error, EINVAL,
3957 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3958 : : "eCPRI cannot coexist with a TCP layer");
3959 : : /* In specification, eCPRI could be over UDP layer. */
3960 [ # # ]: 0 : else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP)
3961 : 0 : return rte_flow_error_set(error, EINVAL,
3962 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3963 : : "eCPRI over UDP layer is not yet supported right now");
3964 : : /* Mask for type field in common header could be zero. */
3965 [ # # ]: 0 : if (!mask)
3966 : : mask = &rte_flow_item_ecpri_mask;
3967 [ # # ]: 0 : mask_lo.hdr.common.u32 = rte_be_to_cpu_32(mask->hdr.common.u32);
3968 : : /* Input mask is in big-endian format. */
3969 [ # # ]: 0 : if (mask_lo.hdr.common.type != 0 && mask_lo.hdr.common.type != 0xff)
3970 : 0 : return rte_flow_error_set(error, EINVAL,
3971 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
3972 : : "partial mask is not supported for protocol");
3973 [ # # # # ]: 0 : else if (mask_lo.hdr.common.type == 0 && mask->hdr.dummy[0] != 0)
3974 : 0 : return rte_flow_error_set(error, EINVAL,
3975 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
3976 : : "message header mask must be after a type mask");
3977 [ # # ]: 0 : return mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
3978 : : acc_mask ? (const uint8_t *)acc_mask
3979 : : : (const uint8_t *)&nic_mask,
3980 : : sizeof(struct rte_flow_item_ecpri),
3981 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3982 : : }
3983 : :
3984 : : /**
3985 : : * Validate the NSH item.
3986 : : *
3987 : : * @param[in] dev
3988 : : * Pointer to Ethernet device on which flow rule is being created on.
3989 : : * @param[out] error
3990 : : * Pointer to error structure.
3991 : : *
3992 : : * @return
3993 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3994 : : */
3995 : : int
3996 : 0 : mlx5_flow_validate_item_nsh(struct rte_eth_dev *dev,
3997 : : const struct rte_flow_item *item,
3998 : : struct rte_flow_error *error)
3999 : : {
4000 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4001 : :
4002 [ # # ]: 0 : if (item->mask) {
4003 : 0 : return rte_flow_error_set(error, ENOTSUP,
4004 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
4005 : : "NSH fields matching is not supported");
4006 : : }
4007 : :
4008 [ # # ]: 0 : if (!priv->sh->config.dv_flow_en) {
4009 : 0 : return rte_flow_error_set(error, ENOTSUP,
4010 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4011 : : NULL, "NSH support requires DV flow interface");
4012 : : }
4013 : :
4014 [ # # ]: 0 : if (!priv->sh->cdev->config.hca_attr.tunnel_stateless_vxlan_gpe_nsh) {
4015 : 0 : return rte_flow_error_set(error, ENOTSUP,
4016 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
4017 : : "Current FW does not support matching on NSH");
4018 : : }
4019 : :
4020 : : return 0;
4021 : : }
4022 : :
4023 : : static uintptr_t
4024 : 0 : flow_null_list_create(struct rte_eth_dev *dev __rte_unused,
4025 : : enum mlx5_flow_type type __rte_unused,
4026 : : const struct rte_flow_attr *attr __rte_unused,
4027 : : const struct rte_flow_item items[] __rte_unused,
4028 : : const struct rte_flow_action actions[] __rte_unused,
4029 : : bool external __rte_unused,
4030 : : struct rte_flow_error *error)
4031 : : {
4032 : 0 : rte_flow_error_set(error, ENOTSUP,
4033 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
4034 : 0 : return 0;
4035 : : }
4036 : :
4037 : : static int
4038 : 0 : flow_null_validate(struct rte_eth_dev *dev __rte_unused,
4039 : : const struct rte_flow_attr *attr __rte_unused,
4040 : : const struct rte_flow_item items[] __rte_unused,
4041 : : const struct rte_flow_action actions[] __rte_unused,
4042 : : bool external __rte_unused,
4043 : : int hairpin __rte_unused,
4044 : : struct rte_flow_error *error)
4045 : : {
4046 : 0 : return rte_flow_error_set(error, ENOTSUP,
4047 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
4048 : : }
4049 : :
4050 : : static struct mlx5_flow *
4051 : 0 : flow_null_prepare(struct rte_eth_dev *dev __rte_unused,
4052 : : const struct rte_flow_attr *attr __rte_unused,
4053 : : const struct rte_flow_item items[] __rte_unused,
4054 : : const struct rte_flow_action actions[] __rte_unused,
4055 : : struct rte_flow_error *error)
4056 : : {
4057 : 0 : rte_flow_error_set(error, ENOTSUP,
4058 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
4059 : 0 : return NULL;
4060 : : }
4061 : :
4062 : : static int
4063 : 0 : flow_null_translate(struct rte_eth_dev *dev __rte_unused,
4064 : : struct mlx5_flow *dev_flow __rte_unused,
4065 : : const struct rte_flow_attr *attr __rte_unused,
4066 : : const struct rte_flow_item items[] __rte_unused,
4067 : : const struct rte_flow_action actions[] __rte_unused,
4068 : : struct rte_flow_error *error)
4069 : : {
4070 : 0 : return rte_flow_error_set(error, ENOTSUP,
4071 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
4072 : : }
4073 : :
4074 : : static int
4075 : 0 : flow_null_apply(struct rte_eth_dev *dev __rte_unused,
4076 : : struct rte_flow *flow __rte_unused,
4077 : : struct rte_flow_error *error)
4078 : : {
4079 : 0 : return rte_flow_error_set(error, ENOTSUP,
4080 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
4081 : : }
4082 : :
4083 : : static void
4084 : 0 : flow_null_remove(struct rte_eth_dev *dev __rte_unused,
4085 : : struct rte_flow *flow __rte_unused)
4086 : : {
4087 : 0 : }
4088 : :
4089 : : static void
4090 : 0 : flow_null_destroy(struct rte_eth_dev *dev __rte_unused,
4091 : : struct rte_flow *flow __rte_unused)
4092 : : {
4093 : 0 : }
4094 : :
4095 : : static int
4096 : 0 : flow_null_query(struct rte_eth_dev *dev __rte_unused,
4097 : : struct rte_flow *flow __rte_unused,
4098 : : const struct rte_flow_action *actions __rte_unused,
4099 : : void *data __rte_unused,
4100 : : struct rte_flow_error *error)
4101 : : {
4102 : 0 : return rte_flow_error_set(error, ENOTSUP,
4103 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
4104 : : }
4105 : :
4106 : : static int
4107 : 0 : flow_null_sync_domain(struct rte_eth_dev *dev __rte_unused,
4108 : : uint32_t domains __rte_unused,
4109 : : uint32_t flags __rte_unused)
4110 : : {
4111 : 0 : return 0;
4112 : : }
4113 : :
4114 : : int
4115 : 0 : flow_null_get_aged_flows(struct rte_eth_dev *dev,
4116 : : void **context __rte_unused,
4117 : : uint32_t nb_contexts __rte_unused,
4118 : : struct rte_flow_error *error __rte_unused)
4119 : : {
4120 : 0 : DRV_LOG(ERR, "port %u get aged flows is not supported.",
4121 : : dev->data->port_id);
4122 : 0 : return -ENOTSUP;
4123 : : }
4124 : :
4125 : : uint32_t
4126 : 0 : flow_null_counter_allocate(struct rte_eth_dev *dev)
4127 : : {
4128 : 0 : DRV_LOG(ERR, "port %u counter allocate is not supported.",
4129 : : dev->data->port_id);
4130 : 0 : return 0;
4131 : : }
4132 : :
4133 : : void
4134 : 0 : flow_null_counter_free(struct rte_eth_dev *dev,
4135 : : uint32_t counter __rte_unused)
4136 : : {
4137 : 0 : DRV_LOG(ERR, "port %u counter free is not supported.",
4138 : : dev->data->port_id);
4139 : 0 : }
4140 : :
4141 : : int
4142 : 0 : flow_null_counter_query(struct rte_eth_dev *dev,
4143 : : uint32_t counter __rte_unused,
4144 : : bool clear __rte_unused,
4145 : : uint64_t *pkts __rte_unused,
4146 : : uint64_t *bytes __rte_unused,
4147 : : void **action __rte_unused)
4148 : : {
4149 : 0 : DRV_LOG(ERR, "port %u counter query is not supported.",
4150 : : dev->data->port_id);
4151 : 0 : return -ENOTSUP;
4152 : : }
4153 : :
4154 : : /* Void driver to protect from null pointer reference. */
4155 : : const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
4156 : : .list_create = flow_null_list_create,
4157 : : .validate = flow_null_validate,
4158 : : .prepare = flow_null_prepare,
4159 : : .translate = flow_null_translate,
4160 : : .apply = flow_null_apply,
4161 : : .remove = flow_null_remove,
4162 : : .destroy = flow_null_destroy,
4163 : : .query = flow_null_query,
4164 : : .sync_domain = flow_null_sync_domain,
4165 : : .get_aged_flows = flow_null_get_aged_flows,
4166 : : .counter_alloc = flow_null_counter_allocate,
4167 : : .counter_free = flow_null_counter_free,
4168 : : .counter_query = flow_null_counter_query
4169 : : };
4170 : :
4171 : : /**
4172 : : * Select flow driver type according to flow attributes and device
4173 : : * configuration.
4174 : : *
4175 : : * @param[in] dev
4176 : : * Pointer to the dev structure.
4177 : : * @param[in] attr
4178 : : * Pointer to the flow attributes.
4179 : : *
4180 : : * @return
4181 : : * flow driver type, MLX5_FLOW_TYPE_MAX otherwise.
4182 : : */
4183 : : static enum mlx5_flow_drv_type
4184 : 0 : flow_get_drv_type(struct rte_eth_dev *dev, const struct rte_flow_attr *attr)
4185 : : {
4186 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4187 : : /* The OS can determine first a specific flow type (DV, VERBS) */
4188 : : enum mlx5_flow_drv_type type = mlx5_flow_os_get_type();
4189 : :
4190 : : if (type != MLX5_FLOW_TYPE_MAX)
4191 : : return type;
4192 : : /*
4193 : : * Currently when dv_flow_en == 2, only HW steering engine is
4194 : : * supported. New engines can also be chosen here if ready.
4195 : : */
4196 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
4197 : : return MLX5_FLOW_TYPE_HW;
4198 [ # # ]: 0 : if (!attr)
4199 : : return MLX5_FLOW_TYPE_MIN;
4200 : : /* If no OS specific type - continue with DV/VERBS selection */
4201 [ # # # # ]: 0 : if (attr->transfer && priv->sh->config.dv_esw_en)
4202 : : type = MLX5_FLOW_TYPE_DV;
4203 [ # # ]: 0 : if (!attr->transfer)
4204 [ # # # # : 0 : type = priv->sh->config.dv_flow_en ? MLX5_FLOW_TYPE_DV :
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
4205 : : MLX5_FLOW_TYPE_VERBS;
4206 : : return type;
4207 : : }
4208 : :
4209 : : #define flow_get_drv_ops(type) flow_drv_ops[type]
4210 : :
4211 : : /**
4212 : : * Flow driver validation API. This abstracts calling driver specific functions.
4213 : : * The type of flow driver is determined according to flow attributes.
4214 : : *
4215 : : * @param[in] dev
4216 : : * Pointer to the dev structure.
4217 : : * @param[in] attr
4218 : : * Pointer to the flow attributes.
4219 : : * @param[in] items
4220 : : * Pointer to the list of items.
4221 : : * @param[in] actions
4222 : : * Pointer to the list of actions.
4223 : : * @param[in] external
4224 : : * This flow rule is created by request external to PMD.
4225 : : * @param[in] hairpin
4226 : : * Number of hairpin TX actions, 0 means classic flow.
4227 : : * @param[out] error
4228 : : * Pointer to the error structure.
4229 : : *
4230 : : * @return
4231 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4232 : : */
4233 : : static inline int
4234 : 0 : flow_drv_validate(struct rte_eth_dev *dev,
4235 : : const struct rte_flow_attr *attr,
4236 : : const struct rte_flow_item items[],
4237 : : const struct rte_flow_action actions[],
4238 : : bool external, int hairpin, struct rte_flow_error *error)
4239 : : {
4240 : : const struct mlx5_flow_driver_ops *fops;
4241 : 0 : enum mlx5_flow_drv_type type = flow_get_drv_type(dev, attr);
4242 : :
4243 : 0 : fops = flow_get_drv_ops(type);
4244 : 0 : return fops->validate(dev, attr, items, actions, external,
4245 : : hairpin, error);
4246 : : }
4247 : :
4248 : : /**
4249 : : * Flow driver preparation API. This abstracts calling driver specific
4250 : : * functions. Parent flow (rte_flow) should have driver type (drv_type). It
4251 : : * calculates the size of memory required for device flow, allocates the memory,
4252 : : * initializes the device flow and returns the pointer.
4253 : : *
4254 : : * @note
4255 : : * This function initializes device flow structure such as dv or verbs in
4256 : : * struct mlx5_flow. However, it is caller's responsibility to initialize the
4257 : : * rest. For example, adding returning device flow to flow->dev_flow list and
4258 : : * setting backward reference to the flow should be done out of this function.
4259 : : * layers field is not filled either.
4260 : : *
4261 : : * @param[in] dev
4262 : : * Pointer to the dev structure.
4263 : : * @param[in] attr
4264 : : * Pointer to the flow attributes.
4265 : : * @param[in] items
4266 : : * Pointer to the list of items.
4267 : : * @param[in] actions
4268 : : * Pointer to the list of actions.
4269 : : * @param[in] flow_idx
4270 : : * This memory pool index to the flow.
4271 : : * @param[out] error
4272 : : * Pointer to the error structure.
4273 : : *
4274 : : * @return
4275 : : * Pointer to device flow on success, otherwise NULL and rte_errno is set.
4276 : : */
4277 : : static inline struct mlx5_flow *
4278 : : flow_drv_prepare(struct rte_eth_dev *dev,
4279 : : const struct rte_flow *flow,
4280 : : const struct rte_flow_attr *attr,
4281 : : const struct rte_flow_item items[],
4282 : : const struct rte_flow_action actions[],
4283 : : uint32_t flow_idx,
4284 : : struct rte_flow_error *error)
4285 : : {
4286 : : const struct mlx5_flow_driver_ops *fops;
4287 : 0 : enum mlx5_flow_drv_type type = flow->drv_type;
4288 : : struct mlx5_flow *mlx5_flow = NULL;
4289 : :
4290 : : MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
4291 : 0 : fops = flow_get_drv_ops(type);
4292 : 0 : mlx5_flow = fops->prepare(dev, attr, items, actions, error);
4293 [ # # # # : 0 : if (mlx5_flow)
# # ]
4294 : 0 : mlx5_flow->flow_idx = flow_idx;
4295 : : return mlx5_flow;
4296 : : }
4297 : :
4298 : : /**
4299 : : * Flow driver translation API. This abstracts calling driver specific
4300 : : * functions. Parent flow (rte_flow) should have driver type (drv_type). It
4301 : : * translates a generic flow into a driver flow. flow_drv_prepare() must
4302 : : * precede.
4303 : : *
4304 : : * @note
4305 : : * dev_flow->layers could be filled as a result of parsing during translation
4306 : : * if needed by flow_drv_apply(). dev_flow->flow->actions can also be filled
4307 : : * if necessary. As a flow can have multiple dev_flows by RSS flow expansion,
4308 : : * flow->actions could be overwritten even though all the expanded dev_flows
4309 : : * have the same actions.
4310 : : *
4311 : : * @param[in] dev
4312 : : * Pointer to the rte dev structure.
4313 : : * @param[in, out] dev_flow
4314 : : * Pointer to the mlx5 flow.
4315 : : * @param[in] attr
4316 : : * Pointer to the flow attributes.
4317 : : * @param[in] items
4318 : : * Pointer to the list of items.
4319 : : * @param[in] actions
4320 : : * Pointer to the list of actions.
4321 : : * @param[out] error
4322 : : * Pointer to the error structure.
4323 : : *
4324 : : * @return
4325 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4326 : : */
4327 : : static inline int
4328 : : flow_drv_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
4329 : : const struct rte_flow_attr *attr,
4330 : : const struct rte_flow_item items[],
4331 : : const struct rte_flow_action actions[],
4332 : : struct rte_flow_error *error)
4333 : : {
4334 : : const struct mlx5_flow_driver_ops *fops;
4335 : 0 : enum mlx5_flow_drv_type type = dev_flow->flow->drv_type;
4336 : :
4337 : : MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
4338 : 0 : fops = flow_get_drv_ops(type);
4339 : 0 : return fops->translate(dev, dev_flow, attr, items, actions, error);
4340 : : }
4341 : :
4342 : : /**
4343 : : * Flow driver apply API. This abstracts calling driver specific functions.
4344 : : * Parent flow (rte_flow) should have driver type (drv_type). It applies
4345 : : * translated driver flows on to device. flow_drv_translate() must precede.
4346 : : *
4347 : : * @param[in] dev
4348 : : * Pointer to Ethernet device structure.
4349 : : * @param[in, out] flow
4350 : : * Pointer to flow structure.
4351 : : * @param[out] error
4352 : : * Pointer to error structure.
4353 : : *
4354 : : * @return
4355 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4356 : : */
4357 : : static inline int
4358 : : flow_drv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
4359 : : struct rte_flow_error *error)
4360 : : {
4361 : : const struct mlx5_flow_driver_ops *fops;
4362 : 0 : enum mlx5_flow_drv_type type = flow->drv_type;
4363 : :
4364 : : MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
4365 : 0 : fops = flow_get_drv_ops(type);
4366 : 0 : return fops->apply(dev, flow, error);
4367 : : }
4368 : :
4369 : : /**
4370 : : * Flow driver destroy API. This abstracts calling driver specific functions.
4371 : : * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
4372 : : * on device and releases resources of the flow.
4373 : : *
4374 : : * @param[in] dev
4375 : : * Pointer to Ethernet device.
4376 : : * @param[in, out] flow
4377 : : * Pointer to flow structure.
4378 : : */
4379 : : static inline void
4380 : : flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
4381 : : {
4382 : : const struct mlx5_flow_driver_ops *fops;
4383 : 0 : enum mlx5_flow_drv_type type = flow->drv_type;
4384 : :
4385 : : MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
4386 : 0 : fops = flow_get_drv_ops(type);
4387 : 0 : fops->destroy(dev, flow);
4388 : : }
4389 : :
4390 : : /**
4391 : : * Flow driver find RSS policy tbl API. This abstracts calling driver
4392 : : * specific functions. Parent flow (rte_flow) should have driver
4393 : : * type (drv_type). It will find the RSS policy table that has the rss_desc.
4394 : : *
4395 : : * @param[in] dev
4396 : : * Pointer to Ethernet device.
4397 : : * @param[in, out] flow
4398 : : * Pointer to flow structure.
4399 : : * @param[in] policy
4400 : : * Pointer to meter policy table.
4401 : : * @param[in] rss_desc
4402 : : * Pointer to rss_desc
4403 : : */
4404 : : static struct mlx5_flow_meter_sub_policy *
4405 : : flow_drv_meter_sub_policy_rss_prepare(struct rte_eth_dev *dev,
4406 : : struct rte_flow *flow,
4407 : : struct mlx5_flow_meter_policy *policy,
4408 : : struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS])
4409 : : {
4410 : : const struct mlx5_flow_driver_ops *fops;
4411 : 0 : enum mlx5_flow_drv_type type = flow->drv_type;
4412 : :
4413 : : MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
4414 : 0 : fops = flow_get_drv_ops(type);
4415 : 0 : return fops->meter_sub_policy_rss_prepare(dev, policy, rss_desc);
4416 : : }
4417 : :
4418 : : /**
4419 : : * Flow driver color tag rule API. This abstracts calling driver
4420 : : * specific functions. Parent flow (rte_flow) should have driver
4421 : : * type (drv_type). It will create the color tag rules in hierarchy meter.
4422 : : *
4423 : : * @param[in] dev
4424 : : * Pointer to Ethernet device.
4425 : : * @param[in, out] flow
4426 : : * Pointer to flow structure.
4427 : : * @param[in] fm
4428 : : * Pointer to flow meter structure.
4429 : : * @param[in] src_port
4430 : : * The src port this extra rule should use.
4431 : : * @param[in] item
4432 : : * The src port id match item.
4433 : : * @param[out] error
4434 : : * Pointer to error structure.
4435 : : */
4436 : : static int
4437 : : flow_drv_mtr_hierarchy_rule_create(struct rte_eth_dev *dev,
4438 : : struct rte_flow *flow,
4439 : : struct mlx5_flow_meter_info *fm,
4440 : : int32_t src_port,
4441 : : const struct rte_flow_item *item,
4442 : : struct rte_flow_error *error)
4443 : : {
4444 : : const struct mlx5_flow_driver_ops *fops;
4445 : 0 : enum mlx5_flow_drv_type type = flow->drv_type;
4446 : :
4447 : : MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
4448 : 0 : fops = flow_get_drv_ops(type);
4449 : 0 : return fops->meter_hierarchy_rule_create(dev, fm,
4450 : : src_port, item, error);
4451 : : }
4452 : :
4453 : : /**
4454 : : * Get RSS action from the action list.
4455 : : *
4456 : : * @param[in] dev
4457 : : * Pointer to Ethernet device.
4458 : : * @param[in] actions
4459 : : * Pointer to the list of actions.
4460 : : * @param[in] flow
4461 : : * Parent flow structure pointer.
4462 : : *
4463 : : * @return
4464 : : * Pointer to the RSS action if exist, else return NULL.
4465 : : */
4466 : : static const struct rte_flow_action_rss*
4467 : 0 : flow_get_rss_action(struct rte_eth_dev *dev,
4468 : : const struct rte_flow_action actions[])
4469 : : {
4470 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4471 : : const struct rte_flow_action_rss *rss = NULL;
4472 : : struct mlx5_meter_policy_action_container *acg;
4473 : : struct mlx5_meter_policy_action_container *acy;
4474 : :
4475 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4476 [ # # # # ]: 0 : switch (actions->type) {
4477 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
4478 : 0 : rss = actions->conf;
4479 : 0 : break;
4480 : 0 : case RTE_FLOW_ACTION_TYPE_SAMPLE:
4481 : : {
4482 : 0 : const struct rte_flow_action_sample *sample =
4483 : : actions->conf;
4484 : 0 : const struct rte_flow_action *act = sample->actions;
4485 [ # # ]: 0 : for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++)
4486 [ # # ]: 0 : if (act->type == RTE_FLOW_ACTION_TYPE_RSS)
4487 : 0 : rss = act->conf;
4488 : : break;
4489 : : }
4490 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
4491 : : {
4492 : : uint32_t mtr_idx;
4493 : : struct mlx5_flow_meter_info *fm;
4494 : : struct mlx5_flow_meter_policy *policy;
4495 : 0 : const struct rte_flow_action_meter *mtr = actions->conf;
4496 : :
4497 : 0 : fm = mlx5_flow_meter_find(priv, mtr->mtr_id, &mtr_idx);
4498 [ # # # # ]: 0 : if (fm && !fm->def_policy) {
4499 : 0 : policy = mlx5_flow_meter_policy_find(dev,
4500 : : fm->policy_id, NULL);
4501 : : MLX5_ASSERT(policy);
4502 [ # # ]: 0 : if (policy->is_hierarchy) {
4503 : : policy =
4504 : 0 : mlx5_flow_meter_hierarchy_get_final_policy(dev,
4505 : : policy);
4506 [ # # ]: 0 : if (!policy)
4507 : 0 : return NULL;
4508 : : }
4509 [ # # ]: 0 : if (policy->is_rss) {
4510 : : acg =
4511 : : &policy->act_cnt[RTE_COLOR_GREEN];
4512 : : acy =
4513 : : &policy->act_cnt[RTE_COLOR_YELLOW];
4514 [ # # ]: 0 : if (acg->fate_action ==
4515 : : MLX5_FLOW_FATE_SHARED_RSS)
4516 : 0 : rss = acg->rss->conf;
4517 [ # # ]: 0 : else if (acy->fate_action ==
4518 : : MLX5_FLOW_FATE_SHARED_RSS)
4519 : 0 : rss = acy->rss->conf;
4520 : : }
4521 : : }
4522 : 0 : break;
4523 : : }
4524 : : default:
4525 : : break;
4526 : : }
4527 : : }
4528 : : return rss;
4529 : : }
4530 : :
4531 : : /**
4532 : : * Get ASO age action by index.
4533 : : *
4534 : : * @param[in] dev
4535 : : * Pointer to the Ethernet device structure.
4536 : : * @param[in] age_idx
4537 : : * Index to the ASO age action.
4538 : : *
4539 : : * @return
4540 : : * The specified ASO age action.
4541 : : */
4542 : : struct mlx5_aso_age_action*
4543 : 0 : flow_aso_age_get_by_idx(struct rte_eth_dev *dev, uint32_t age_idx)
4544 : : {
4545 : 0 : uint16_t pool_idx = age_idx & UINT16_MAX;
4546 : 0 : uint16_t offset = (age_idx >> 16) & UINT16_MAX;
4547 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4548 : 0 : struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
4549 : : struct mlx5_aso_age_pool *pool;
4550 : :
4551 : 0 : rte_rwlock_read_lock(&mng->resize_rwl);
4552 : 0 : pool = mng->pools[pool_idx];
4553 : : rte_rwlock_read_unlock(&mng->resize_rwl);
4554 : 0 : return &pool->actions[offset - 1];
4555 : : }
4556 : :
4557 : : /* maps indirect action to translated direct in some actions array */
4558 : : struct mlx5_translated_action_handle {
4559 : : struct rte_flow_action_handle *action; /**< Indirect action handle. */
4560 : : int index; /**< Index in related array of rte_flow_action. */
4561 : : };
4562 : :
4563 : : /**
4564 : : * Translates actions of type RTE_FLOW_ACTION_TYPE_INDIRECT to related
4565 : : * direct action if translation possible.
4566 : : * This functionality used to run same execution path for both direct and
4567 : : * indirect actions on flow create. All necessary preparations for indirect
4568 : : * action handling should be performed on *handle* actions list returned
4569 : : * from this call.
4570 : : *
4571 : : * @param[in] dev
4572 : : * Pointer to Ethernet device.
4573 : : * @param[in] actions
4574 : : * List of actions to translate.
4575 : : * @param[out] handle
4576 : : * List to store translated indirect action object handles.
4577 : : * @param[in, out] indir_n
4578 : : * Size of *handle* array. On return should be updated with number of
4579 : : * indirect actions retrieved from the *actions* list.
4580 : : * @param[out] translated_actions
4581 : : * List of actions where all indirect actions were translated to direct
4582 : : * if possible. NULL if no translation took place.
4583 : : * @param[out] error
4584 : : * Pointer to the error structure.
4585 : : *
4586 : : * @return
4587 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4588 : : */
4589 : : static int
4590 : 0 : flow_action_handles_translate(struct rte_eth_dev *dev,
4591 : : const struct rte_flow_action actions[],
4592 : : struct mlx5_translated_action_handle *handle,
4593 : : int *indir_n,
4594 : : struct rte_flow_action **translated_actions,
4595 : : struct rte_flow_error *error)
4596 : : {
4597 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4598 : : struct rte_flow_action *translated = NULL;
4599 : : size_t actions_size;
4600 : : int n;
4601 : : int copied_n = 0;
4602 : : struct mlx5_translated_action_handle *handle_end = NULL;
4603 : :
4604 [ # # ]: 0 : for (n = 0; actions[n].type != RTE_FLOW_ACTION_TYPE_END; n++) {
4605 [ # # ]: 0 : if (actions[n].type != RTE_FLOW_ACTION_TYPE_INDIRECT)
4606 : 0 : continue;
4607 [ # # ]: 0 : if (copied_n == *indir_n) {
4608 : 0 : return rte_flow_error_set
4609 : : (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_NUM,
4610 : : NULL, "too many shared actions");
4611 : : }
4612 [ # # ]: 0 : rte_memcpy(&handle[copied_n].action, &actions[n].conf,
4613 : : sizeof(actions[n].conf));
4614 : 0 : handle[copied_n].index = n;
4615 : 0 : copied_n++;
4616 : : }
4617 : 0 : n++;
4618 : 0 : *indir_n = copied_n;
4619 [ # # ]: 0 : if (!copied_n)
4620 : : return 0;
4621 : 0 : actions_size = sizeof(struct rte_flow_action) * n;
4622 : 0 : translated = mlx5_malloc(MLX5_MEM_ZERO, actions_size, 0, SOCKET_ID_ANY);
4623 [ # # ]: 0 : if (!translated) {
4624 : 0 : rte_errno = ENOMEM;
4625 : 0 : return -ENOMEM;
4626 : : }
4627 : : memcpy(translated, actions, actions_size);
4628 [ # # ]: 0 : for (handle_end = handle + copied_n; handle < handle_end; handle++) {
4629 : : struct mlx5_shared_action_rss *shared_rss;
4630 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle->action;
4631 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
4632 : 0 : uint32_t idx = act_idx &
4633 : : ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
4634 : :
4635 [ # # # # : 0 : switch (type) {
# # ]
4636 : 0 : case MLX5_INDIRECT_ACTION_TYPE_RSS:
4637 : 0 : shared_rss = mlx5_ipool_get
4638 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
4639 : 0 : translated[handle->index].type =
4640 : : RTE_FLOW_ACTION_TYPE_RSS;
4641 : 0 : translated[handle->index].conf =
4642 : 0 : &shared_rss->origin;
4643 : 0 : break;
4644 : 0 : case MLX5_INDIRECT_ACTION_TYPE_COUNT:
4645 : 0 : translated[handle->index].type =
4646 : : (enum rte_flow_action_type)
4647 : : MLX5_RTE_FLOW_ACTION_TYPE_COUNT;
4648 : 0 : translated[handle->index].conf = (void *)(uintptr_t)idx;
4649 : 0 : break;
4650 : 0 : case MLX5_INDIRECT_ACTION_TYPE_METER_MARK:
4651 : 0 : translated[handle->index].type =
4652 : : (enum rte_flow_action_type)
4653 : : MLX5_RTE_FLOW_ACTION_TYPE_METER_MARK;
4654 : 0 : translated[handle->index].conf = (void *)(uintptr_t)idx;
4655 : 0 : break;
4656 : 0 : case MLX5_INDIRECT_ACTION_TYPE_AGE:
4657 [ # # ]: 0 : if (priv->sh->flow_hit_aso_en) {
4658 : 0 : translated[handle->index].type =
4659 : : (enum rte_flow_action_type)
4660 : : MLX5_RTE_FLOW_ACTION_TYPE_AGE;
4661 : 0 : translated[handle->index].conf =
4662 : 0 : (void *)(uintptr_t)idx;
4663 : 0 : break;
4664 : : }
4665 : : /* Fall-through */
4666 : : case MLX5_INDIRECT_ACTION_TYPE_CT:
4667 [ # # ]: 0 : if (priv->sh->ct_aso_en) {
4668 : 0 : translated[handle->index].type =
4669 : : RTE_FLOW_ACTION_TYPE_CONNTRACK;
4670 : 0 : translated[handle->index].conf =
4671 : 0 : (void *)(uintptr_t)idx;
4672 : 0 : break;
4673 : : }
4674 : : /* Fall-through */
4675 : : default:
4676 : 0 : mlx5_free(translated);
4677 : 0 : return rte_flow_error_set
4678 : : (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
4679 : : NULL, "invalid indirect action type");
4680 : : }
4681 : : }
4682 : 0 : *translated_actions = translated;
4683 : 0 : return 0;
4684 : : }
4685 : :
4686 : : /**
4687 : : * Get Shared RSS action from the action list.
4688 : : *
4689 : : * @param[in] dev
4690 : : * Pointer to Ethernet device.
4691 : : * @param[in] shared
4692 : : * Pointer to the list of actions.
4693 : : * @param[in] shared_n
4694 : : * Actions list length.
4695 : : *
4696 : : * @return
4697 : : * The MLX5 RSS action ID if exists, otherwise return 0.
4698 : : */
4699 : : static uint32_t
4700 : 0 : flow_get_shared_rss_action(struct rte_eth_dev *dev,
4701 : : struct mlx5_translated_action_handle *handle,
4702 : : int shared_n)
4703 : : {
4704 : : struct mlx5_translated_action_handle *handle_end;
4705 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4706 : : struct mlx5_shared_action_rss *shared_rss;
4707 : :
4708 : :
4709 [ # # ]: 0 : for (handle_end = handle + shared_n; handle < handle_end; handle++) {
4710 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle->action;
4711 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
4712 : 0 : uint32_t idx = act_idx &
4713 : : ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
4714 [ # # ]: 0 : switch (type) {
4715 : 0 : case MLX5_INDIRECT_ACTION_TYPE_RSS:
4716 : 0 : shared_rss = mlx5_ipool_get
4717 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
4718 : : idx);
4719 : 0 : rte_atomic_fetch_add_explicit(&shared_rss->refcnt, 1,
4720 : : rte_memory_order_relaxed);
4721 : 0 : return idx;
4722 : : default:
4723 : : break;
4724 : : }
4725 : : }
4726 : : return 0;
4727 : : }
4728 : :
4729 : : static unsigned int
4730 : : find_graph_root(uint32_t rss_level)
4731 : : {
4732 : 0 : return rss_level < 2 ? MLX5_EXPANSION_ROOT :
4733 : : MLX5_EXPANSION_ROOT_OUTER;
4734 : : }
4735 : :
4736 : : /**
4737 : : * Get layer flags from the prefix flow.
4738 : : *
4739 : : * Some flows may be split to several subflows, the prefix subflow gets the
4740 : : * match items and the suffix sub flow gets the actions.
4741 : : * Some actions need the user defined match item flags to get the detail for
4742 : : * the action.
4743 : : * This function helps the suffix flow to get the item layer flags from prefix
4744 : : * subflow.
4745 : : *
4746 : : * @param[in] dev_flow
4747 : : * Pointer the created prefix subflow.
4748 : : *
4749 : : * @return
4750 : : * The layers get from prefix subflow.
4751 : : */
4752 : : static inline uint64_t
4753 : 0 : flow_get_prefix_layer_flags(struct mlx5_flow *dev_flow)
4754 : : {
4755 : : uint64_t layers = 0;
4756 : :
4757 : : /*
4758 : : * Layers bits could be localization, but usually the compiler will
4759 : : * help to do the optimization work for source code.
4760 : : * If no decap actions, use the layers directly.
4761 : : */
4762 [ # # ]: 0 : if (!(dev_flow->act_flags & MLX5_FLOW_ACTION_DECAP))
4763 : 0 : return dev_flow->handle->layers;
4764 : : /* Convert L3 layers with decap action. */
4765 [ # # ]: 0 : if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV4)
4766 : : layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV4;
4767 [ # # ]: 0 : else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV6)
4768 : : layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
4769 : : /* Convert L4 layers with decap action. */
4770 [ # # ]: 0 : if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_TCP)
4771 : 0 : layers |= MLX5_FLOW_LAYER_OUTER_L4_TCP;
4772 [ # # ]: 0 : else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_UDP)
4773 : 0 : layers |= MLX5_FLOW_LAYER_OUTER_L4_UDP;
4774 : : return layers;
4775 : : }
4776 : :
4777 : : /**
4778 : : * Get metadata split action information.
4779 : : *
4780 : : * @param[in] actions
4781 : : * Pointer to the list of actions.
4782 : : * @param[out] qrss
4783 : : * Pointer to the return pointer.
4784 : : * @param[out] qrss_type
4785 : : * Pointer to the action type to return. RTE_FLOW_ACTION_TYPE_END is returned
4786 : : * if no QUEUE/RSS is found.
4787 : : * @param[out] encap_idx
4788 : : * Pointer to the index of the encap action if exists, otherwise the last
4789 : : * action index.
4790 : : *
4791 : : * @return
4792 : : * Total number of actions.
4793 : : */
4794 : : static int
4795 : 0 : flow_parse_metadata_split_actions_info(const struct rte_flow_action actions[],
4796 : : const struct rte_flow_action **qrss,
4797 : : int *encap_idx)
4798 : : {
4799 : : const struct rte_flow_action_raw_encap *raw_encap;
4800 : : int actions_n = 0;
4801 : : int raw_decap_idx = -1;
4802 : :
4803 : 0 : *encap_idx = -1;
4804 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4805 [ # # # # : 0 : switch (actions->type) {
# ]
4806 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4807 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4808 : 0 : *encap_idx = actions_n;
4809 : 0 : break;
4810 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4811 : : raw_decap_idx = actions_n;
4812 : 0 : break;
4813 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4814 : 0 : raw_encap = actions->conf;
4815 [ # # ]: 0 : if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4816 : 0 : *encap_idx = raw_decap_idx != -1 ?
4817 [ # # ]: 0 : raw_decap_idx : actions_n;
4818 : : break;
4819 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
4820 : : case RTE_FLOW_ACTION_TYPE_RSS:
4821 : 0 : *qrss = actions;
4822 : 0 : break;
4823 : : default:
4824 : : break;
4825 : : }
4826 : 0 : actions_n++;
4827 : : }
4828 [ # # ]: 0 : if (*encap_idx == -1)
4829 : 0 : *encap_idx = actions_n;
4830 : : /* Count RTE_FLOW_ACTION_TYPE_END. */
4831 : 0 : return actions_n + 1;
4832 : : }
4833 : :
4834 : : /**
4835 : : * Check if the action will change packet.
4836 : : *
4837 : : * @param dev
4838 : : * Pointer to Ethernet device.
4839 : : * @param[in] type
4840 : : * action type.
4841 : : *
4842 : : * @return
4843 : : * true if action will change packet, false otherwise.
4844 : : */
4845 : 0 : static bool flow_check_modify_action_type(struct rte_eth_dev *dev,
4846 : : enum rte_flow_action_type type)
4847 : : {
4848 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4849 : :
4850 [ # # # ]: 0 : switch (type) {
4851 : : case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
4852 : : case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
4853 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
4854 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
4855 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
4856 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
4857 : : case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
4858 : : case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
4859 : : case RTE_FLOW_ACTION_TYPE_DEC_TTL:
4860 : : case RTE_FLOW_ACTION_TYPE_SET_TTL:
4861 : : case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
4862 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
4863 : : case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
4864 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
4865 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
4866 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
4867 : : case RTE_FLOW_ACTION_TYPE_SET_META:
4868 : : case RTE_FLOW_ACTION_TYPE_SET_TAG:
4869 : : case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
4870 : : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4871 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4872 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
4873 : : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4874 : : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
4875 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4876 : : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
4877 : : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4878 : : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4879 : : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
4880 : : return true;
4881 : 0 : case RTE_FLOW_ACTION_TYPE_FLAG:
4882 : : case RTE_FLOW_ACTION_TYPE_MARK:
4883 [ # # ]: 0 : if (priv->sh->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
4884 : : priv->sh->config.dv_xmeta_en != MLX5_XMETA_MODE_META32_HWS)
4885 : : return true;
4886 : : else
4887 : 0 : return false;
4888 : 0 : default:
4889 : 0 : return false;
4890 : : }
4891 : : }
4892 : :
4893 : : /**
4894 : : * Check meter action from the action list.
4895 : : *
4896 : : * @param dev
4897 : : * Pointer to Ethernet device.
4898 : : * @param[in] actions
4899 : : * Pointer to the list of actions.
4900 : : * @param[out] has_mtr
4901 : : * Pointer to the meter exist flag.
4902 : : * @param[out] has_modify
4903 : : * Pointer to the flag showing there's packet change action.
4904 : : * @param[out] meter_id
4905 : : * Pointer to the meter id.
4906 : : *
4907 : : * @return
4908 : : * Total number of actions.
4909 : : */
4910 : : static int
4911 : 0 : flow_check_meter_action(struct rte_eth_dev *dev,
4912 : : const struct rte_flow_action actions[],
4913 : : bool *has_mtr, bool *has_modify, uint32_t *meter_id)
4914 : : {
4915 : : const struct rte_flow_action_meter *mtr = NULL;
4916 : : int actions_n = 0;
4917 : :
4918 : : MLX5_ASSERT(has_mtr);
4919 : 0 : *has_mtr = false;
4920 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4921 [ # # ]: 0 : switch (actions->type) {
4922 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
4923 : 0 : mtr = actions->conf;
4924 : 0 : *meter_id = mtr->mtr_id;
4925 : 0 : *has_mtr = true;
4926 : 0 : break;
4927 : : default:
4928 : : break;
4929 : : }
4930 [ # # ]: 0 : if (!*has_mtr)
4931 : 0 : *has_modify |= flow_check_modify_action_type(dev,
4932 : 0 : actions->type);
4933 : 0 : actions_n++;
4934 : : }
4935 : : /* Count RTE_FLOW_ACTION_TYPE_END. */
4936 : 0 : return actions_n + 1;
4937 : : }
4938 : :
4939 : : /**
4940 : : * Check if the flow should be split due to hairpin.
4941 : : * The reason for the split is that in current HW we can't
4942 : : * support encap and push-vlan on Rx, so if a flow contains
4943 : : * these actions we move it to Tx.
4944 : : *
4945 : : * @param dev
4946 : : * Pointer to Ethernet device.
4947 : : * @param[in] attr
4948 : : * Flow rule attributes.
4949 : : * @param[in] actions
4950 : : * Associated actions (list terminated by the END action).
4951 : : *
4952 : : * @return
4953 : : * > 0 the number of actions and the flow should be split,
4954 : : * 0 when no split required.
4955 : : */
4956 : : static int
4957 : 0 : flow_check_hairpin_split(struct rte_eth_dev *dev,
4958 : : const struct rte_flow_attr *attr,
4959 : : const struct rte_flow_action actions[])
4960 : : {
4961 : : int queue_action = 0;
4962 : : int action_n = 0;
4963 : : int split = 0;
4964 : : int push_vlan = 0;
4965 : : const struct rte_flow_action_queue *queue;
4966 : : const struct rte_flow_action_rss *rss;
4967 : : const struct rte_flow_action_raw_encap *raw_encap;
4968 : : const struct rte_eth_hairpin_conf *conf;
4969 : :
4970 [ # # ]: 0 : if (!attr->ingress)
4971 : : return 0;
4972 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4973 [ # # ]: 0 : if (actions->type == RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN)
4974 : : push_vlan = 1;
4975 [ # # # # : 0 : switch (actions->type) {
# # ]
4976 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
4977 : 0 : queue = actions->conf;
4978 [ # # ]: 0 : if (queue == NULL)
4979 : : return 0;
4980 : 0 : conf = mlx5_rxq_get_hairpin_conf(dev, queue->index);
4981 [ # # # # ]: 0 : if (conf == NULL || conf->tx_explicit != 0)
4982 : : return 0;
4983 : : queue_action = 1;
4984 : 0 : action_n++;
4985 : 0 : break;
4986 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
4987 : 0 : rss = actions->conf;
4988 [ # # # # ]: 0 : if (rss == NULL || rss->queue_num == 0)
4989 : : return 0;
4990 : 0 : conf = mlx5_rxq_get_hairpin_conf(dev, rss->queue[0]);
4991 [ # # # # ]: 0 : if (conf == NULL || conf->tx_explicit != 0)
4992 : : return 0;
4993 : : queue_action = 1;
4994 : 0 : action_n++;
4995 : 0 : break;
4996 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4997 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4998 : : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4999 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
5000 : 0 : split++;
5001 : 0 : action_n++;
5002 : 0 : break;
5003 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
5004 [ # # ]: 0 : if (push_vlan)
5005 : 0 : split++;
5006 : 0 : action_n++;
5007 : 0 : break;
5008 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
5009 : 0 : raw_encap = actions->conf;
5010 [ # # ]: 0 : if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
5011 : 0 : split++;
5012 : 0 : action_n++;
5013 : 0 : break;
5014 : 0 : default:
5015 : 0 : action_n++;
5016 : 0 : break;
5017 : : }
5018 : : }
5019 [ # # ]: 0 : if (split && queue_action)
5020 : 0 : return action_n;
5021 : : return 0;
5022 : : }
5023 : :
5024 : : int
5025 : 0 : flow_dv_mreg_match_cb(void *tool_ctx __rte_unused,
5026 : : struct mlx5_list_entry *entry, void *cb_ctx)
5027 : : {
5028 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
5029 : : struct mlx5_flow_mreg_copy_resource *mcp_res =
5030 : : container_of(entry, typeof(*mcp_res), hlist_ent);
5031 : :
5032 : 0 : return mcp_res->mark_id != *(uint32_t *)(ctx->data);
5033 : : }
5034 : :
5035 : : struct mlx5_list_entry *
5036 : 0 : flow_dv_mreg_create_cb(void *tool_ctx, void *cb_ctx)
5037 : : {
5038 : : struct rte_eth_dev *dev = tool_ctx;
5039 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5040 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
5041 : : struct mlx5_flow_mreg_copy_resource *mcp_res;
5042 : 0 : struct rte_flow_error *error = ctx->error;
5043 : 0 : uint32_t idx = 0;
5044 : : int ret;
5045 : 0 : uint32_t mark_id = *(uint32_t *)(ctx->data);
5046 : 0 : struct rte_flow_attr attr = {
5047 : : .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
5048 : : .ingress = 1,
5049 : : };
5050 : 0 : struct mlx5_rte_flow_item_tag tag_spec = {
5051 : : .data = mark_id,
5052 : : };
5053 : 0 : struct rte_flow_item items[] = {
5054 : : [1] = { .type = RTE_FLOW_ITEM_TYPE_END, },
5055 : : };
5056 : 0 : struct rte_flow_action_mark ftag = {
5057 : : .id = mark_id,
5058 : : };
5059 : 0 : struct mlx5_flow_action_copy_mreg cp_mreg = {
5060 : : .dst = REG_B,
5061 : : .src = REG_NON,
5062 : : };
5063 : 0 : struct rte_flow_action_jump jump = {
5064 : : .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
5065 : : };
5066 : 0 : struct rte_flow_action actions[] = {
5067 : : [3] = { .type = RTE_FLOW_ACTION_TYPE_END, },
5068 : : };
5069 : :
5070 : : /* Fill the register fields in the flow. */
5071 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
5072 [ # # ]: 0 : if (ret < 0)
5073 : : return NULL;
5074 : 0 : tag_spec.id = ret;
5075 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
5076 [ # # ]: 0 : if (ret < 0)
5077 : : return NULL;
5078 : 0 : cp_mreg.src = ret;
5079 : : /* Provide the full width of FLAG specific value. */
5080 [ # # ]: 0 : if (mark_id == (priv->sh->dv_regc0_mask & MLX5_FLOW_MARK_DEFAULT))
5081 : 0 : tag_spec.data = MLX5_FLOW_MARK_DEFAULT;
5082 : : /* Build a new flow. */
5083 [ # # ]: 0 : if (mark_id != MLX5_DEFAULT_COPY_ID) {
5084 : 0 : items[0] = (struct rte_flow_item){
5085 : : .type = (enum rte_flow_item_type)
5086 : : MLX5_RTE_FLOW_ITEM_TYPE_TAG,
5087 : : .spec = &tag_spec,
5088 : : };
5089 : 0 : items[1] = (struct rte_flow_item){
5090 : : .type = RTE_FLOW_ITEM_TYPE_END,
5091 : : };
5092 : 0 : actions[0] = (struct rte_flow_action){
5093 : : .type = (enum rte_flow_action_type)
5094 : : MLX5_RTE_FLOW_ACTION_TYPE_MARK,
5095 : : .conf = &ftag,
5096 : : };
5097 : 0 : actions[1] = (struct rte_flow_action){
5098 : : .type = (enum rte_flow_action_type)
5099 : : MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5100 : : .conf = &cp_mreg,
5101 : : };
5102 : 0 : actions[2] = (struct rte_flow_action){
5103 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
5104 : : .conf = &jump,
5105 : : };
5106 : 0 : actions[3] = (struct rte_flow_action){
5107 : : .type = RTE_FLOW_ACTION_TYPE_END,
5108 : : };
5109 : : } else {
5110 : : /* Default rule, wildcard match. */
5111 : 0 : attr.priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR;
5112 : 0 : items[0] = (struct rte_flow_item){
5113 : : .type = RTE_FLOW_ITEM_TYPE_END,
5114 : : };
5115 : 0 : actions[0] = (struct rte_flow_action){
5116 : : .type = (enum rte_flow_action_type)
5117 : : MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5118 : : .conf = &cp_mreg,
5119 : : };
5120 : 0 : actions[1] = (struct rte_flow_action){
5121 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
5122 : : .conf = &jump,
5123 : : };
5124 : 0 : actions[2] = (struct rte_flow_action){
5125 : : .type = RTE_FLOW_ACTION_TYPE_END,
5126 : : };
5127 : : }
5128 : : /* Build a new entry. */
5129 : 0 : mcp_res = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
5130 [ # # ]: 0 : if (!mcp_res) {
5131 : 0 : rte_errno = ENOMEM;
5132 : 0 : return NULL;
5133 : : }
5134 : 0 : mcp_res->idx = idx;
5135 : 0 : mcp_res->mark_id = mark_id;
5136 : : /*
5137 : : * The copy Flows are not included in any list. There
5138 : : * ones are referenced from other Flows and can not
5139 : : * be applied, removed, deleted in arbitrary order
5140 : : * by list traversing.
5141 : : */
5142 : 0 : mcp_res->rix_flow = mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_MCP,
5143 : : &attr, items, actions, false, error);
5144 [ # # ]: 0 : if (!mcp_res->rix_flow) {
5145 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], idx);
5146 : 0 : return NULL;
5147 : : }
5148 : 0 : return &mcp_res->hlist_ent;
5149 : : }
5150 : :
5151 : : struct mlx5_list_entry *
5152 : 0 : flow_dv_mreg_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
5153 : : void *cb_ctx __rte_unused)
5154 : : {
5155 : : struct rte_eth_dev *dev = tool_ctx;
5156 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5157 : : struct mlx5_flow_mreg_copy_resource *mcp_res;
5158 : 0 : uint32_t idx = 0;
5159 : :
5160 : 0 : mcp_res = mlx5_ipool_malloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
5161 [ # # ]: 0 : if (!mcp_res) {
5162 : 0 : rte_errno = ENOMEM;
5163 : 0 : return NULL;
5164 : : }
5165 : : memcpy(mcp_res, oentry, sizeof(*mcp_res));
5166 : 0 : mcp_res->idx = idx;
5167 : 0 : return &mcp_res->hlist_ent;
5168 : : }
5169 : :
5170 : : void
5171 : 0 : flow_dv_mreg_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
5172 : : {
5173 : : struct mlx5_flow_mreg_copy_resource *mcp_res =
5174 : : container_of(entry, typeof(*mcp_res), hlist_ent);
5175 : : struct rte_eth_dev *dev = tool_ctx;
5176 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5177 : :
5178 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
5179 : 0 : }
5180 : :
5181 : : /**
5182 : : * Add a flow of copying flow metadata registers in RX_CP_TBL.
5183 : : *
5184 : : * As mark_id is unique, if there's already a registered flow for the mark_id,
5185 : : * return by increasing the reference counter of the resource. Otherwise, create
5186 : : * the resource (mcp_res) and flow.
5187 : : *
5188 : : * Flow looks like,
5189 : : * - If ingress port is ANY and reg_c[1] is mark_id,
5190 : : * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
5191 : : *
5192 : : * For default flow (zero mark_id), flow is like,
5193 : : * - If ingress port is ANY,
5194 : : * reg_b := reg_c[0] and jump to RX_ACT_TBL.
5195 : : *
5196 : : * @param dev
5197 : : * Pointer to Ethernet device.
5198 : : * @param mark_id
5199 : : * ID of MARK action, zero means default flow for META.
5200 : : * @param[out] error
5201 : : * Perform verbose error reporting if not NULL.
5202 : : *
5203 : : * @return
5204 : : * Associated resource on success, NULL otherwise and rte_errno is set.
5205 : : */
5206 : : static struct mlx5_flow_mreg_copy_resource *
5207 : 0 : flow_mreg_add_copy_action(struct rte_eth_dev *dev, uint32_t mark_id,
5208 : : struct rte_flow_error *error)
5209 : : {
5210 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5211 : : struct mlx5_list_entry *entry;
5212 : 0 : struct mlx5_flow_cb_ctx ctx = {
5213 : : .dev = dev,
5214 : : .error = error,
5215 : : .data = &mark_id,
5216 : : };
5217 : :
5218 : : /* Check if already registered. */
5219 : : MLX5_ASSERT(priv->sh->mreg_cp_tbl);
5220 : 0 : entry = mlx5_hlist_register(priv->sh->mreg_cp_tbl, mark_id, &ctx);
5221 [ # # ]: 0 : if (!entry)
5222 : 0 : return NULL;
5223 : : return container_of(entry, struct mlx5_flow_mreg_copy_resource,
5224 : : hlist_ent);
5225 : : }
5226 : :
5227 : : void
5228 : 0 : flow_dv_mreg_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
5229 : : {
5230 : : struct mlx5_flow_mreg_copy_resource *mcp_res =
5231 : : container_of(entry, typeof(*mcp_res), hlist_ent);
5232 : : struct rte_eth_dev *dev = tool_ctx;
5233 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5234 : :
5235 : : MLX5_ASSERT(mcp_res->rix_flow);
5236 : 0 : mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_MCP, mcp_res->rix_flow);
5237 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
5238 : 0 : }
5239 : :
5240 : : /**
5241 : : * Release flow in RX_CP_TBL.
5242 : : *
5243 : : * @param dev
5244 : : * Pointer to Ethernet device.
5245 : : * @flow
5246 : : * Parent flow for wich copying is provided.
5247 : : */
5248 : : static void
5249 : 0 : flow_mreg_del_copy_action(struct rte_eth_dev *dev,
5250 : : struct rte_flow *flow)
5251 : : {
5252 : : struct mlx5_flow_mreg_copy_resource *mcp_res;
5253 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5254 : :
5255 [ # # ]: 0 : if (!flow->rix_mreg_copy)
5256 : : return;
5257 : 0 : mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
5258 : : flow->rix_mreg_copy);
5259 [ # # # # ]: 0 : if (!mcp_res || !priv->sh->mreg_cp_tbl)
5260 : : return;
5261 : : MLX5_ASSERT(mcp_res->rix_flow);
5262 : 0 : mlx5_hlist_unregister(priv->sh->mreg_cp_tbl, &mcp_res->hlist_ent);
5263 : 0 : flow->rix_mreg_copy = 0;
5264 : : }
5265 : :
5266 : : /**
5267 : : * Remove the default copy action from RX_CP_TBL.
5268 : : *
5269 : : * This functions is called in the mlx5_dev_start(). No thread safe
5270 : : * is guaranteed.
5271 : : *
5272 : : * @param dev
5273 : : * Pointer to Ethernet device.
5274 : : */
5275 : : static void
5276 : 0 : flow_mreg_del_default_copy_action(struct rte_eth_dev *dev)
5277 : : {
5278 : : struct mlx5_list_entry *entry;
5279 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5280 : : struct mlx5_flow_cb_ctx ctx;
5281 : : uint32_t mark_id;
5282 : :
5283 : : /* Check if default flow is registered. */
5284 [ # # ]: 0 : if (!priv->sh->mreg_cp_tbl)
5285 : 0 : return;
5286 : 0 : mark_id = MLX5_DEFAULT_COPY_ID;
5287 : 0 : ctx.data = &mark_id;
5288 : 0 : entry = mlx5_hlist_lookup(priv->sh->mreg_cp_tbl, mark_id, &ctx);
5289 [ # # ]: 0 : if (!entry)
5290 : : return;
5291 : 0 : mlx5_hlist_unregister(priv->sh->mreg_cp_tbl, entry);
5292 : : }
5293 : :
5294 : : /**
5295 : : * Add the default copy action in RX_CP_TBL.
5296 : : *
5297 : : * This functions is called in the mlx5_dev_start(). No thread safe
5298 : : * is guaranteed.
5299 : : *
5300 : : * @param dev
5301 : : * Pointer to Ethernet device.
5302 : : * @param[out] error
5303 : : * Perform verbose error reporting if not NULL.
5304 : : *
5305 : : * @return
5306 : : * 0 for success, negative value otherwise and rte_errno is set.
5307 : : */
5308 : : static int
5309 : 0 : flow_mreg_add_default_copy_action(struct rte_eth_dev *dev,
5310 : : struct rte_flow_error *error)
5311 : : {
5312 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5313 : : struct mlx5_flow_mreg_copy_resource *mcp_res;
5314 : : struct mlx5_flow_cb_ctx ctx;
5315 : : uint32_t mark_id;
5316 : :
5317 : : /* Check whether extensive metadata feature is engaged. */
5318 [ # # ]: 0 : if (!priv->sh->config.dv_flow_en ||
5319 [ # # # # ]: 0 : priv->sh->config.dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
5320 : 0 : !mlx5_flow_ext_mreg_supported(dev) ||
5321 [ # # ]: 0 : !priv->sh->dv_regc0_mask)
5322 : 0 : return 0;
5323 : : /*
5324 : : * Add default mreg copy flow may be called multiple time, but
5325 : : * only be called once in stop. Avoid register it twice.
5326 : : */
5327 : 0 : mark_id = MLX5_DEFAULT_COPY_ID;
5328 : 0 : ctx.data = &mark_id;
5329 [ # # ]: 0 : if (mlx5_hlist_lookup(priv->sh->mreg_cp_tbl, mark_id, &ctx))
5330 : : return 0;
5331 : 0 : mcp_res = flow_mreg_add_copy_action(dev, mark_id, error);
5332 [ # # ]: 0 : if (!mcp_res)
5333 : 0 : return -rte_errno;
5334 : : return 0;
5335 : : }
5336 : :
5337 : : /**
5338 : : * Add a flow of copying flow metadata registers in RX_CP_TBL.
5339 : : *
5340 : : * All the flow having Q/RSS action should be split by
5341 : : * flow_mreg_split_qrss_prep() to pass by RX_CP_TBL. A flow in the RX_CP_TBL
5342 : : * performs the following,
5343 : : * - CQE->flow_tag := reg_c[1] (MARK)
5344 : : * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
5345 : : * As CQE's flow_tag is not a register, it can't be simply copied from reg_c[1]
5346 : : * but there should be a flow per each MARK ID set by MARK action.
5347 : : *
5348 : : * For the aforementioned reason, if there's a MARK action in flow's action
5349 : : * list, a corresponding flow should be added to the RX_CP_TBL in order to copy
5350 : : * the MARK ID to CQE's flow_tag like,
5351 : : * - If reg_c[1] is mark_id,
5352 : : * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
5353 : : *
5354 : : * For SET_META action which stores value in reg_c[0], as the destination is
5355 : : * also a flow metadata register (reg_b), adding a default flow is enough. Zero
5356 : : * MARK ID means the default flow. The default flow looks like,
5357 : : * - For all flow, reg_b := reg_c[0] and jump to RX_ACT_TBL.
5358 : : *
5359 : : * @param dev
5360 : : * Pointer to Ethernet device.
5361 : : * @param flow
5362 : : * Pointer to flow structure.
5363 : : * @param[in] actions
5364 : : * Pointer to the list of actions.
5365 : : * @param[out] error
5366 : : * Perform verbose error reporting if not NULL.
5367 : : *
5368 : : * @return
5369 : : * 0 on success, negative value otherwise and rte_errno is set.
5370 : : */
5371 : : static int
5372 : 0 : flow_mreg_update_copy_table(struct rte_eth_dev *dev,
5373 : : struct rte_flow *flow,
5374 : : const struct rte_flow_action *actions,
5375 : : struct rte_flow_error *error)
5376 : : {
5377 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5378 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
5379 : : struct mlx5_flow_mreg_copy_resource *mcp_res;
5380 : : const struct rte_flow_action_mark *mark;
5381 : :
5382 : : /* Check whether extensive metadata feature is engaged. */
5383 [ # # ]: 0 : if (!config->dv_flow_en ||
5384 [ # # # # ]: 0 : config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
5385 : 0 : !mlx5_flow_ext_mreg_supported(dev) ||
5386 [ # # ]: 0 : !priv->sh->dv_regc0_mask)
5387 : 0 : return 0;
5388 : : /* Find MARK action. */
5389 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
5390 [ # # # ]: 0 : switch (actions->type) {
5391 : 0 : case RTE_FLOW_ACTION_TYPE_FLAG:
5392 : 0 : mcp_res = flow_mreg_add_copy_action
5393 : : (dev, MLX5_FLOW_MARK_DEFAULT, error);
5394 [ # # ]: 0 : if (!mcp_res)
5395 : 0 : return -rte_errno;
5396 : 0 : flow->rix_mreg_copy = mcp_res->idx;
5397 : 0 : return 0;
5398 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
5399 : 0 : mark = (const struct rte_flow_action_mark *)
5400 : : actions->conf;
5401 : : mcp_res =
5402 : 0 : flow_mreg_add_copy_action(dev, mark->id, error);
5403 [ # # ]: 0 : if (!mcp_res)
5404 : 0 : return -rte_errno;
5405 : 0 : flow->rix_mreg_copy = mcp_res->idx;
5406 : 0 : return 0;
5407 : : default:
5408 : : break;
5409 : : }
5410 : : }
5411 : : return 0;
5412 : : }
5413 : :
5414 : : #define MLX5_MAX_SPLIT_ACTIONS 24
5415 : : #define MLX5_MAX_SPLIT_ITEMS 24
5416 : :
5417 : : /**
5418 : : * Split the hairpin flow.
5419 : : * Since HW can't support encap and push-vlan on Rx, we move these
5420 : : * actions to Tx.
5421 : : * If the count action is after the encap then we also
5422 : : * move the count action. in this case the count will also measure
5423 : : * the outer bytes.
5424 : : *
5425 : : * @param dev
5426 : : * Pointer to Ethernet device.
5427 : : * @param[in] actions
5428 : : * Associated actions (list terminated by the END action).
5429 : : * @param[out] actions_rx
5430 : : * Rx flow actions.
5431 : : * @param[out] actions_tx
5432 : : * Tx flow actions..
5433 : : * @param[out] pattern_tx
5434 : : * The pattern items for the Tx flow.
5435 : : * @param[out] flow_id
5436 : : * The flow ID connected to this flow.
5437 : : *
5438 : : * @return
5439 : : * 0 on success.
5440 : : */
5441 : : static int
5442 : 0 : flow_hairpin_split(struct rte_eth_dev *dev,
5443 : : const struct rte_flow_action actions[],
5444 : : struct rte_flow_action actions_rx[],
5445 : : struct rte_flow_action actions_tx[],
5446 : : struct rte_flow_item pattern_tx[],
5447 : : uint32_t flow_id)
5448 : : {
5449 : : const struct rte_flow_action_raw_encap *raw_encap;
5450 : : const struct rte_flow_action_raw_decap *raw_decap;
5451 : : struct mlx5_rte_flow_action_set_tag *set_tag;
5452 : : struct rte_flow_action *tag_action;
5453 : : struct mlx5_rte_flow_item_tag *tag_item;
5454 : : struct rte_flow_item *item;
5455 : : char *addr;
5456 : : int push_vlan = 0;
5457 : : int encap = 0;
5458 : :
5459 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
5460 [ # # ]: 0 : if (actions->type == RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN)
5461 : : push_vlan = 1;
5462 [ # # # # : 0 : switch (actions->type) {
# # ]
5463 : : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
5464 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
5465 : : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
5466 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
5467 : : rte_memcpy(actions_tx, actions,
5468 : : sizeof(struct rte_flow_action));
5469 : 0 : actions_tx++;
5470 : 0 : break;
5471 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
5472 [ # # ]: 0 : if (push_vlan) {
5473 : : rte_memcpy(actions_tx, actions,
5474 : : sizeof(struct rte_flow_action));
5475 : 0 : actions_tx++;
5476 : : } else {
5477 : : rte_memcpy(actions_rx, actions,
5478 : : sizeof(struct rte_flow_action));
5479 : 0 : actions_rx++;
5480 : : }
5481 : : break;
5482 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
5483 : : case RTE_FLOW_ACTION_TYPE_AGE:
5484 [ # # ]: 0 : if (encap) {
5485 : : rte_memcpy(actions_tx, actions,
5486 : : sizeof(struct rte_flow_action));
5487 : 0 : actions_tx++;
5488 : : } else {
5489 : : rte_memcpy(actions_rx, actions,
5490 : : sizeof(struct rte_flow_action));
5491 : 0 : actions_rx++;
5492 : : }
5493 : : break;
5494 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
5495 : 0 : raw_encap = actions->conf;
5496 [ # # ]: 0 : if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE) {
5497 : : memcpy(actions_tx, actions,
5498 : : sizeof(struct rte_flow_action));
5499 : 0 : actions_tx++;
5500 : : encap = 1;
5501 : : } else {
5502 : : rte_memcpy(actions_rx, actions,
5503 : : sizeof(struct rte_flow_action));
5504 : 0 : actions_rx++;
5505 : : }
5506 : : break;
5507 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
5508 : 0 : raw_decap = actions->conf;
5509 [ # # ]: 0 : if (raw_decap->size < MLX5_ENCAPSULATION_DECISION_SIZE) {
5510 : : memcpy(actions_tx, actions,
5511 : : sizeof(struct rte_flow_action));
5512 : 0 : actions_tx++;
5513 : : } else {
5514 : : rte_memcpy(actions_rx, actions,
5515 : : sizeof(struct rte_flow_action));
5516 : 0 : actions_rx++;
5517 : : }
5518 : : break;
5519 : : default:
5520 : : rte_memcpy(actions_rx, actions,
5521 : : sizeof(struct rte_flow_action));
5522 : 0 : actions_rx++;
5523 : 0 : break;
5524 : : }
5525 : : }
5526 : : /* Add set meta action and end action for the Rx flow. */
5527 : : tag_action = actions_rx;
5528 : 0 : tag_action->type = (enum rte_flow_action_type)
5529 : : MLX5_RTE_FLOW_ACTION_TYPE_TAG;
5530 [ # # ]: 0 : actions_rx++;
5531 : : rte_memcpy(actions_rx, actions, sizeof(struct rte_flow_action));
5532 : 0 : actions_rx++;
5533 : : set_tag = (void *)actions_rx;
5534 : 0 : *set_tag = (struct mlx5_rte_flow_action_set_tag) {
5535 : 0 : .id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_RX, 0, NULL),
5536 : : .data = flow_id,
5537 : : };
5538 : : MLX5_ASSERT(set_tag->id > REG_NON);
5539 [ # # ]: 0 : tag_action->conf = set_tag;
5540 : : /* Create Tx item list. */
5541 : : rte_memcpy(actions_tx, actions, sizeof(struct rte_flow_action));
5542 : 0 : addr = (void *)&pattern_tx[2];
5543 : : item = pattern_tx;
5544 : 0 : item->type = (enum rte_flow_item_type)
5545 : : MLX5_RTE_FLOW_ITEM_TYPE_TAG;
5546 : : tag_item = (void *)addr;
5547 : 0 : tag_item->data = flow_id;
5548 : 0 : tag_item->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_TX, 0, NULL);
5549 : : MLX5_ASSERT(set_tag->id > REG_NON);
5550 : 0 : item->spec = tag_item;
5551 : 0 : addr += sizeof(struct mlx5_rte_flow_item_tag);
5552 : : tag_item = (void *)addr;
5553 : 0 : tag_item->data = UINT32_MAX;
5554 : 0 : tag_item->id = UINT16_MAX;
5555 : 0 : item->mask = tag_item;
5556 : 0 : item->last = NULL;
5557 : : item++;
5558 : 0 : item->type = RTE_FLOW_ITEM_TYPE_END;
5559 : 0 : return 0;
5560 : : }
5561 : :
5562 : : /**
5563 : : * The last stage of splitting chain, just creates the subflow
5564 : : * without any modification.
5565 : : *
5566 : : * @param[in] dev
5567 : : * Pointer to Ethernet device.
5568 : : * @param[in] flow
5569 : : * Parent flow structure pointer.
5570 : : * @param[in, out] sub_flow
5571 : : * Pointer to return the created subflow, may be NULL.
5572 : : * @param[in] attr
5573 : : * Flow rule attributes.
5574 : : * @param[in] items
5575 : : * Pattern specification (list terminated by the END pattern item).
5576 : : * @param[in] actions
5577 : : * Associated actions (list terminated by the END action).
5578 : : * @param[in] flow_split_info
5579 : : * Pointer to flow split info structure.
5580 : : * @param[out] error
5581 : : * Perform verbose error reporting if not NULL.
5582 : : * @return
5583 : : * 0 on success, negative value otherwise
5584 : : */
5585 : : static int
5586 : 0 : flow_create_split_inner(struct rte_eth_dev *dev,
5587 : : struct rte_flow *flow,
5588 : : struct mlx5_flow **sub_flow,
5589 : : const struct rte_flow_attr *attr,
5590 : : const struct rte_flow_item items[],
5591 : : const struct rte_flow_action actions[],
5592 : : struct mlx5_flow_split_info *flow_split_info,
5593 : : struct rte_flow_error *error)
5594 : : {
5595 : : struct mlx5_flow *dev_flow;
5596 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
5597 : :
5598 : 0 : dev_flow = flow_drv_prepare(dev, flow, attr, items, actions,
5599 : : flow_split_info->flow_idx, error);
5600 [ # # ]: 0 : if (!dev_flow)
5601 : 0 : return -rte_errno;
5602 : 0 : dev_flow->flow = flow;
5603 : 0 : dev_flow->external = flow_split_info->external;
5604 : 0 : dev_flow->skip_scale = flow_split_info->skip_scale;
5605 : : /* Subflow object was created, we must include one in the list. */
5606 : 0 : SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
5607 : : dev_flow->handle, next);
5608 : : /*
5609 : : * If dev_flow is as one of the suffix flow, some actions in suffix
5610 : : * flow may need some user defined item layer flags, and pass the
5611 : : * Metadata rxq mark flag to suffix flow as well.
5612 : : */
5613 [ # # ]: 0 : if (flow_split_info->prefix_layers)
5614 : 0 : dev_flow->handle->layers = flow_split_info->prefix_layers;
5615 [ # # ]: 0 : if (flow_split_info->prefix_mark) {
5616 : : MLX5_ASSERT(wks);
5617 : 0 : wks->mark = 1;
5618 : : }
5619 [ # # ]: 0 : if (sub_flow)
5620 : 0 : *sub_flow = dev_flow;
5621 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
5622 : 0 : dev_flow->dv.table_id = flow_split_info->table_id;
5623 : : #endif
5624 : 0 : return flow_drv_translate(dev, dev_flow, attr, items, actions, error);
5625 : : }
5626 : :
5627 : : /**
5628 : : * Get the sub policy of a meter.
5629 : : *
5630 : : * @param[in] dev
5631 : : * Pointer to Ethernet device.
5632 : : * @param[in] flow
5633 : : * Parent flow structure pointer.
5634 : : * @param wks
5635 : : * Pointer to thread flow work space.
5636 : : * @param[in] attr
5637 : : * Flow rule attributes.
5638 : : * @param[in] items
5639 : : * Pattern specification (list terminated by the END pattern item).
5640 : : * @param[out] error
5641 : : * Perform verbose error reporting if not NULL.
5642 : : *
5643 : : * @return
5644 : : * Pointer to the meter sub policy, NULL otherwise and rte_errno is set.
5645 : : */
5646 : : static struct mlx5_flow_meter_sub_policy *
5647 : 0 : get_meter_sub_policy(struct rte_eth_dev *dev,
5648 : : struct rte_flow *flow,
5649 : : struct mlx5_flow_workspace *wks,
5650 : : const struct rte_flow_attr *attr,
5651 : : const struct rte_flow_item items[],
5652 : : struct rte_flow_error *error)
5653 : : {
5654 : : struct mlx5_flow_meter_policy *policy;
5655 : : struct mlx5_flow_meter_policy *final_policy;
5656 : : struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
5657 : :
5658 : 0 : policy = wks->policy;
5659 [ # # ]: 0 : final_policy = policy->is_hierarchy ? wks->final_policy : policy;
5660 [ # # ]: 0 : if (final_policy->is_rss || final_policy->is_queue) {
5661 : : struct mlx5_flow_rss_desc rss_desc_v[MLX5_MTR_RTE_COLORS];
5662 : 0 : struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS] = {0};
5663 : : uint32_t i;
5664 : :
5665 : : /*
5666 : : * This is a tmp dev_flow,
5667 : : * no need to register any matcher for it in translate.
5668 : : */
5669 : 0 : wks->skip_matcher_reg = 1;
5670 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
5671 : 0 : struct mlx5_flow dev_flow = {0};
5672 : 0 : struct mlx5_flow_handle dev_handle = { {0} };
5673 : 0 : uint8_t fate = final_policy->act_cnt[i].fate_action;
5674 : :
5675 [ # # ]: 0 : if (fate == MLX5_FLOW_FATE_SHARED_RSS) {
5676 : 0 : const struct rte_flow_action_rss *rss_act =
5677 : 0 : final_policy->act_cnt[i].rss->conf;
5678 : 0 : struct rte_flow_action rss_actions[2] = {
5679 : : [0] = {
5680 : : .type = RTE_FLOW_ACTION_TYPE_RSS,
5681 : : .conf = rss_act,
5682 : : },
5683 : : [1] = {
5684 : : .type = RTE_FLOW_ACTION_TYPE_END,
5685 : : .conf = NULL,
5686 : : }
5687 : : };
5688 : :
5689 : 0 : dev_flow.handle = &dev_handle;
5690 : 0 : dev_flow.ingress = attr->ingress;
5691 : 0 : dev_flow.flow = flow;
5692 : : dev_flow.external = 0;
5693 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
5694 : 0 : dev_flow.dv.transfer = attr->transfer;
5695 : : #endif
5696 : : /**
5697 : : * Translate RSS action to get rss hash fields.
5698 : : */
5699 [ # # ]: 0 : if (flow_drv_translate(dev, &dev_flow, attr,
5700 : : items, rss_actions, error))
5701 : 0 : goto exit;
5702 : 0 : rss_desc_v[i] = wks->rss_desc;
5703 : 0 : rss_desc_v[i].symmetric_hash_function =
5704 : 0 : dev_flow.symmetric_hash_function;
5705 : 0 : rss_desc_v[i].key_len = MLX5_RSS_HASH_KEY_LEN;
5706 : 0 : rss_desc_v[i].hash_fields =
5707 : 0 : dev_flow.hash_fields;
5708 : 0 : rss_desc_v[i].queue_num =
5709 : : rss_desc_v[i].hash_fields ?
5710 [ # # ]: 0 : rss_desc_v[i].queue_num : 1;
5711 : 0 : rss_desc_v[i].tunnel =
5712 : 0 : !!(dev_flow.handle->layers &
5713 : : MLX5_FLOW_LAYER_TUNNEL);
5714 : : /* Use the RSS queues in the containers. */
5715 : 0 : rss_desc_v[i].queue =
5716 : 0 : (uint16_t *)(uintptr_t)rss_act->queue;
5717 : 0 : rss_desc[i] = &rss_desc_v[i];
5718 [ # # ]: 0 : } else if (fate == MLX5_FLOW_FATE_QUEUE) {
5719 : : /* This is queue action. */
5720 : 0 : rss_desc_v[i] = wks->rss_desc;
5721 : 0 : rss_desc_v[i].key_len = 0;
5722 : 0 : rss_desc_v[i].hash_fields = 0;
5723 : 0 : rss_desc_v[i].queue =
5724 : 0 : &final_policy->act_cnt[i].queue;
5725 : 0 : rss_desc_v[i].queue_num = 1;
5726 : 0 : rss_desc[i] = &rss_desc_v[i];
5727 : : } else {
5728 : 0 : rss_desc[i] = NULL;
5729 : : }
5730 : : }
5731 : : sub_policy = flow_drv_meter_sub_policy_rss_prepare(dev,
5732 : : flow, policy, rss_desc);
5733 : : } else {
5734 : : enum mlx5_meter_domain mtr_domain =
5735 [ # # ]: 0 : attr->transfer ? MLX5_MTR_DOMAIN_TRANSFER :
5736 : 0 : (attr->egress ? MLX5_MTR_DOMAIN_EGRESS :
5737 : : MLX5_MTR_DOMAIN_INGRESS);
5738 : 0 : sub_policy = policy->sub_policys[mtr_domain][0];
5739 : : }
5740 [ # # ]: 0 : if (!sub_policy)
5741 : 0 : rte_flow_error_set(error, EINVAL,
5742 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5743 : : "Failed to get meter sub-policy.");
5744 : 0 : exit:
5745 : 0 : return sub_policy;
5746 : : }
5747 : :
5748 : : /**
5749 : : * Split the meter flow.
5750 : : *
5751 : : * As meter flow will split to three sub flow, other than meter
5752 : : * action, the other actions make sense to only meter accepts
5753 : : * the packet. If it need to be dropped, no other additional
5754 : : * actions should be take.
5755 : : *
5756 : : * One kind of special action which decapsulates the L3 tunnel
5757 : : * header will be in the prefix sub flow, as not to take the
5758 : : * L3 tunnel header into account.
5759 : : *
5760 : : * @param[in] dev
5761 : : * Pointer to Ethernet device.
5762 : : * @param[in] flow
5763 : : * Parent flow structure pointer.
5764 : : * @param wks
5765 : : * Pointer to thread flow work space.
5766 : : * @param[in] attr
5767 : : * Flow rule attributes.
5768 : : * @param[in] items
5769 : : * Pattern specification (list terminated by the END pattern item).
5770 : : * @param[out] sfx_items
5771 : : * Suffix flow match items (list terminated by the END pattern item).
5772 : : * @param[in] actions
5773 : : * Associated actions (list terminated by the END action).
5774 : : * @param[out] actions_sfx
5775 : : * Suffix flow actions.
5776 : : * @param[out] actions_pre
5777 : : * Prefix flow actions.
5778 : : * @param[out] mtr_flow_id
5779 : : * Pointer to meter flow id.
5780 : : * @param[out] error
5781 : : * Perform verbose error reporting if not NULL.
5782 : : *
5783 : : * @return
5784 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5785 : : */
5786 : : static int
5787 : 0 : flow_meter_split_prep(struct rte_eth_dev *dev,
5788 : : struct rte_flow *flow,
5789 : : struct mlx5_flow_workspace *wks,
5790 : : const struct rte_flow_attr *attr,
5791 : : const struct rte_flow_item items[],
5792 : : struct rte_flow_item sfx_items[],
5793 : : const struct rte_flow_action actions[],
5794 : : struct rte_flow_action actions_sfx[],
5795 : : struct rte_flow_action actions_pre[],
5796 : : uint32_t *mtr_flow_id,
5797 : : struct rte_flow_error *error)
5798 : : {
5799 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5800 : 0 : struct mlx5_flow_meter_info *fm = wks->fm;
5801 : : struct rte_flow_action *tag_action = NULL;
5802 : : struct rte_flow_item *tag_item;
5803 : : struct mlx5_rte_flow_action_set_tag *set_tag;
5804 : : const struct rte_flow_action_raw_encap *raw_encap;
5805 : : const struct rte_flow_action_raw_decap *raw_decap;
5806 : : struct mlx5_rte_flow_item_tag *tag_item_spec;
5807 : : struct mlx5_rte_flow_item_tag *tag_item_mask;
5808 : 0 : uint32_t tag_id = 0;
5809 : : bool vlan_actions;
5810 : : struct rte_flow_item *orig_sfx_items = sfx_items;
5811 : : const struct rte_flow_item *orig_items = items;
5812 : : struct rte_flow_action *hw_mtr_action;
5813 : : struct rte_flow_action *action_pre_head = NULL;
5814 : 0 : uint16_t flow_src_port = priv->representor_id;
5815 : : bool mtr_first;
5816 : 0 : uint8_t mtr_id_offset = priv->mtr_reg_share ? MLX5_MTR_COLOR_BITS : 0;
5817 [ # # ]: 0 : uint8_t mtr_reg_bits = priv->mtr_reg_share ?
5818 : : MLX5_MTR_IDLE_BITS_IN_COLOR_REG : MLX5_REG_BITS;
5819 : : uint32_t flow_id = 0;
5820 : : uint32_t flow_id_reversed = 0;
5821 : : uint8_t flow_id_bits = 0;
5822 : : bool after_meter = false;
5823 : : int shift;
5824 : :
5825 : : /* Prepare the suffix subflow items. */
5826 : 0 : tag_item = sfx_items++;
5827 : 0 : tag_item->type = (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_TAG;
5828 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
5829 : : int item_type = items->type;
5830 : :
5831 [ # # # ]: 0 : switch (item_type) {
5832 : 0 : case RTE_FLOW_ITEM_TYPE_PORT_ID:
5833 : : case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
5834 : : case RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR:
5835 [ # # ]: 0 : if (mlx5_flow_get_item_vport_id(dev, items, &flow_src_port, NULL, error))
5836 : 0 : return -rte_errno;
5837 [ # # # # ]: 0 : if (!fm->def_policy && wks->policy->hierarchy_match_port &&
5838 [ # # ]: 0 : flow_src_port != priv->representor_id) {
5839 [ # # ]: 0 : if (flow_drv_mtr_hierarchy_rule_create(dev,
5840 : : flow, fm,
5841 : : flow_src_port,
5842 : : items,
5843 : : error))
5844 : 0 : return -rte_errno;
5845 : : }
5846 : : memcpy(sfx_items, items, sizeof(*sfx_items));
5847 : 0 : sfx_items++;
5848 : 0 : break;
5849 : : case RTE_FLOW_ITEM_TYPE_VLAN:
5850 : : /*
5851 : : * Copy VLAN items in case VLAN actions are performed.
5852 : : * If there are no VLAN actions, these items will be VOID.
5853 : : */
5854 : : memcpy(sfx_items, items, sizeof(*sfx_items));
5855 : 0 : sfx_items->type = (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_VLAN;
5856 : 0 : sfx_items++;
5857 : 0 : break;
5858 : : default:
5859 : : break;
5860 : : }
5861 : : }
5862 : 0 : sfx_items->type = RTE_FLOW_ITEM_TYPE_END;
5863 : 0 : sfx_items++;
5864 [ # # ]: 0 : mtr_first = priv->sh->meter_aso_en &&
5865 [ # # # # : 0 : (attr->egress || (attr->transfer && flow_src_port != UINT16_MAX));
# # ]
5866 : : /* For ASO meter, meter must be before tag in TX direction. */
5867 [ # # ]: 0 : if (mtr_first) {
5868 : 0 : action_pre_head = actions_pre++;
5869 : : /* Leave space for tag action. */
5870 : 0 : tag_action = actions_pre++;
5871 : : }
5872 : : /* Prepare the actions for prefix and suffix flow. */
5873 : : vlan_actions = false;
5874 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
5875 : : struct rte_flow_action *action_cur = NULL;
5876 : :
5877 [ # # # # : 0 : switch (actions->type) {
# # # ]
5878 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
5879 [ # # ]: 0 : if (mtr_first) {
5880 : : action_cur = action_pre_head;
5881 : : } else {
5882 : : /* Leave space for tag action. */
5883 : 0 : tag_action = actions_pre++;
5884 : 0 : action_cur = actions_pre++;
5885 : : }
5886 : : after_meter = true;
5887 : : break;
5888 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
5889 : : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
5890 : 0 : action_cur = actions_pre++;
5891 : 0 : break;
5892 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
5893 : 0 : raw_encap = actions->conf;
5894 [ # # ]: 0 : if (raw_encap->size < MLX5_ENCAPSULATION_DECISION_SIZE)
5895 : 0 : action_cur = actions_pre++;
5896 : : break;
5897 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
5898 : 0 : raw_decap = actions->conf;
5899 [ # # ]: 0 : if (raw_decap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
5900 : 0 : action_cur = actions_pre++;
5901 : : break;
5902 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
5903 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
5904 : : vlan_actions = true;
5905 : 0 : break;
5906 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
5907 [ # # ]: 0 : if (fm->def_policy)
5908 : : action_cur = after_meter ?
5909 [ # # ]: 0 : actions_sfx++ : actions_pre++;
5910 : : break;
5911 : : default:
5912 : : break;
5913 : : }
5914 [ # # ]: 0 : if (!action_cur)
5915 : 0 : action_cur = (fm->def_policy) ?
5916 [ # # ]: 0 : actions_sfx++ : actions_pre++;
5917 : : memcpy(action_cur, actions, sizeof(struct rte_flow_action));
5918 : : }
5919 : : /* If there are no VLAN actions, convert VLAN items to VOID in suffix flow items. */
5920 [ # # ]: 0 : if (!vlan_actions) {
5921 : : struct rte_flow_item *it = orig_sfx_items;
5922 : :
5923 [ # # ]: 0 : for (; it->type != RTE_FLOW_ITEM_TYPE_END; it++)
5924 [ # # ]: 0 : if (it->type == (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_VLAN)
5925 : 0 : it->type = RTE_FLOW_ITEM_TYPE_VOID;
5926 : : }
5927 : : /* Add end action to the actions. */
5928 : 0 : actions_sfx->type = RTE_FLOW_ACTION_TYPE_END;
5929 [ # # ]: 0 : if (priv->sh->meter_aso_en) {
5930 : : /**
5931 : : * For ASO meter, need to add an extra jump action explicitly,
5932 : : * to jump from meter to policer table.
5933 : : */
5934 : : struct mlx5_flow_meter_sub_policy *sub_policy;
5935 : : struct mlx5_flow_tbl_data_entry *tbl_data;
5936 : :
5937 [ # # ]: 0 : if (!fm->def_policy) {
5938 : 0 : sub_policy = get_meter_sub_policy(dev, flow, wks,
5939 : : attr, orig_items,
5940 : : error);
5941 [ # # ]: 0 : if (!sub_policy)
5942 : 0 : return -rte_errno;
5943 : : } else {
5944 : : enum mlx5_meter_domain mtr_domain =
5945 [ # # ]: 0 : attr->transfer ? MLX5_MTR_DOMAIN_TRANSFER :
5946 : 0 : (attr->egress ? MLX5_MTR_DOMAIN_EGRESS :
5947 : : MLX5_MTR_DOMAIN_INGRESS);
5948 : :
5949 : 0 : sub_policy =
5950 : 0 : &priv->sh->mtrmng->def_policy[mtr_domain]->sub_policy;
5951 : : }
5952 : 0 : tbl_data = container_of(sub_policy->tbl_rsc,
5953 : : struct mlx5_flow_tbl_data_entry, tbl);
5954 : 0 : hw_mtr_action = actions_pre++;
5955 : 0 : hw_mtr_action->type = (enum rte_flow_action_type)
5956 : : MLX5_RTE_FLOW_ACTION_TYPE_JUMP;
5957 : 0 : hw_mtr_action->conf = tbl_data->jump.action;
5958 : : }
5959 : 0 : actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
5960 : 0 : actions_pre++;
5961 [ # # ]: 0 : if (!tag_action)
5962 : 0 : return rte_flow_error_set(error, ENOMEM,
5963 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5964 : : NULL, "No tag action space.");
5965 [ # # ]: 0 : if (!mtr_flow_id) {
5966 : 0 : tag_action->type = RTE_FLOW_ACTION_TYPE_VOID;
5967 : 0 : goto exit;
5968 : : }
5969 : : /* Only default-policy Meter creates mtr flow id. */
5970 [ # # ]: 0 : if (fm->def_policy) {
5971 : 0 : mlx5_ipool_malloc(fm->flow_ipool, &tag_id);
5972 [ # # ]: 0 : if (!tag_id)
5973 : 0 : return rte_flow_error_set(error, ENOMEM,
5974 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5975 : : "Failed to allocate meter flow id.");
5976 : 0 : flow_id = tag_id - 1;
5977 [ # # ]: 0 : flow_id_bits = (!flow_id) ? 1 :
5978 : 0 : (MLX5_REG_BITS - rte_clz32(flow_id));
5979 [ # # ]: 0 : if ((flow_id_bits + priv->sh->mtrmng->max_mtr_bits) >
5980 : : mtr_reg_bits) {
5981 : 0 : mlx5_ipool_free(fm->flow_ipool, tag_id);
5982 : 0 : return rte_flow_error_set(error, EINVAL,
5983 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5984 : : "Meter flow id exceeds max limit.");
5985 : : }
5986 [ # # ]: 0 : if (flow_id_bits > priv->sh->mtrmng->max_mtr_flow_bits)
5987 : 0 : priv->sh->mtrmng->max_mtr_flow_bits = flow_id_bits;
5988 : : }
5989 : : /* Build tag actions and items for meter_id/meter flow_id. */
5990 : : set_tag = (struct mlx5_rte_flow_action_set_tag *)actions_pre;
5991 : : tag_item_spec = (struct mlx5_rte_flow_item_tag *)sfx_items;
5992 : 0 : tag_item_mask = tag_item_spec + 1;
5993 : : /* Both flow_id and meter_id share the same register. */
5994 : 0 : *set_tag = (struct mlx5_rte_flow_action_set_tag) {
5995 : 0 : .id = (enum modify_reg)mlx5_flow_get_reg_id(dev, MLX5_MTR_ID,
5996 : : 0, error),
5997 : : .offset = mtr_id_offset,
5998 : : .length = mtr_reg_bits,
5999 : 0 : .data = flow->meter,
6000 : : };
6001 : : /*
6002 : : * The color Reg bits used by flow_id are growing from
6003 : : * msb to lsb, so must do bit reverse for flow_id val in RegC.
6004 : : */
6005 [ # # ]: 0 : for (shift = 0; shift < flow_id_bits; shift++)
6006 : 0 : flow_id_reversed = (flow_id_reversed << 1) |
6007 : 0 : ((flow_id >> shift) & 0x1);
6008 : 0 : set_tag->data |=
6009 : 0 : flow_id_reversed << (mtr_reg_bits - flow_id_bits);
6010 : 0 : tag_item_spec->id = set_tag->id;
6011 : 0 : tag_item_spec->data = set_tag->data << mtr_id_offset;
6012 : 0 : tag_item_mask->data = UINT32_MAX << mtr_id_offset;
6013 : 0 : tag_action->type = (enum rte_flow_action_type)
6014 : : MLX5_RTE_FLOW_ACTION_TYPE_TAG;
6015 : 0 : tag_action->conf = set_tag;
6016 : 0 : tag_item->spec = tag_item_spec;
6017 : 0 : tag_item->last = NULL;
6018 : 0 : tag_item->mask = tag_item_mask;
6019 : 0 : exit:
6020 [ # # ]: 0 : if (mtr_flow_id)
6021 : 0 : *mtr_flow_id = tag_id;
6022 : : return 0;
6023 : : }
6024 : :
6025 : : /**
6026 : : * Split action list having QUEUE/RSS for metadata register copy.
6027 : : *
6028 : : * Once Q/RSS action is detected in user's action list, the flow action
6029 : : * should be split in order to copy metadata registers, which will happen in
6030 : : * RX_CP_TBL like,
6031 : : * - CQE->flow_tag := reg_c[1] (MARK)
6032 : : * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
6033 : : * The Q/RSS action will be performed on RX_ACT_TBL after passing by RX_CP_TBL.
6034 : : * This is because the last action of each flow must be a terminal action
6035 : : * (QUEUE, RSS or DROP).
6036 : : *
6037 : : * Flow ID must be allocated to identify actions in the RX_ACT_TBL and it is
6038 : : * stored and kept in the mlx5_flow structure per each sub_flow.
6039 : : *
6040 : : * The Q/RSS action is replaced with,
6041 : : * - SET_TAG, setting the allocated flow ID to reg_c[2].
6042 : : * And the following JUMP action is added at the end,
6043 : : * - JUMP, to RX_CP_TBL.
6044 : : *
6045 : : * A flow to perform remained Q/RSS action will be created in RX_ACT_TBL by
6046 : : * flow_create_split_metadata() routine. The flow will look like,
6047 : : * - If flow ID matches (reg_c[2]), perform Q/RSS.
6048 : : *
6049 : : * @param dev
6050 : : * Pointer to Ethernet device.
6051 : : * @param[out] split_actions
6052 : : * Pointer to store split actions to jump to CP_TBL.
6053 : : * @param[in] actions
6054 : : * Pointer to the list of original flow actions.
6055 : : * @param[in] qrss
6056 : : * Pointer to the Q/RSS action.
6057 : : * @param[in] actions_n
6058 : : * Number of original actions.
6059 : : * @param[in] mtr_sfx
6060 : : * Check if it is in meter suffix table.
6061 : : * @param[out] error
6062 : : * Perform verbose error reporting if not NULL.
6063 : : *
6064 : : * @return
6065 : : * non-zero unique flow_id on success, otherwise 0 and
6066 : : * error/rte_error are set.
6067 : : */
6068 : : static uint32_t
6069 : 0 : flow_mreg_split_qrss_prep(struct rte_eth_dev *dev,
6070 : : struct rte_flow_action *split_actions,
6071 : : const struct rte_flow_action *actions,
6072 : : const struct rte_flow_action *qrss,
6073 : : int actions_n, int mtr_sfx,
6074 : : struct rte_flow_error *error)
6075 : : {
6076 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6077 : : struct mlx5_rte_flow_action_set_tag *set_tag;
6078 : : struct rte_flow_action_jump *jump;
6079 : 0 : const int qrss_idx = qrss - actions;
6080 : 0 : uint32_t flow_id = 0;
6081 : : int ret = 0;
6082 : :
6083 : : /*
6084 : : * Given actions will be split
6085 : : * - Replace QUEUE/RSS action with SET_TAG to set flow ID.
6086 : : * - Add jump to mreg CP_TBL.
6087 : : * As a result, there will be one more action.
6088 : : */
6089 [ # # ]: 0 : memcpy(split_actions, actions, sizeof(*split_actions) * actions_n);
6090 : : /* Count MLX5_RTE_FLOW_ACTION_TYPE_TAG. */
6091 : 0 : ++actions_n;
6092 : 0 : set_tag = (void *)(split_actions + actions_n);
6093 : : /*
6094 : : * If we are not the meter suffix flow, add the tag action.
6095 : : * Since meter suffix flow already has the tag added.
6096 : : */
6097 [ # # ]: 0 : if (!mtr_sfx) {
6098 : : /*
6099 : : * Allocate the new subflow ID. This one is unique within
6100 : : * device and not shared with representors. Otherwise,
6101 : : * we would have to resolve multi-thread access synch
6102 : : * issue. Each flow on the shared device is appended
6103 : : * with source vport identifier, so the resulting
6104 : : * flows will be unique in the shared (by master and
6105 : : * representors) domain even if they have coinciding
6106 : : * IDs.
6107 : : */
6108 : 0 : mlx5_ipool_malloc(priv->sh->ipool
6109 : : [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &flow_id);
6110 [ # # ]: 0 : if (!flow_id)
6111 : 0 : return rte_flow_error_set(error, ENOMEM,
6112 : : RTE_FLOW_ERROR_TYPE_ACTION,
6113 : : NULL, "can't allocate id "
6114 : : "for split Q/RSS subflow");
6115 : : /* Internal SET_TAG action to set flow ID. */
6116 : 0 : *set_tag = (struct mlx5_rte_flow_action_set_tag){
6117 : : .data = flow_id,
6118 : : };
6119 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0, error);
6120 [ # # ]: 0 : if (ret < 0)
6121 : 0 : return ret;
6122 : 0 : set_tag->id = ret;
6123 : : /* Construct new actions array. */
6124 : : /* Replace QUEUE/RSS action. */
6125 : 0 : split_actions[qrss_idx] = (struct rte_flow_action){
6126 : : .type = (enum rte_flow_action_type)
6127 : : MLX5_RTE_FLOW_ACTION_TYPE_TAG,
6128 : : .conf = set_tag,
6129 : : };
6130 : : } else {
6131 : : /*
6132 : : * If we are the suffix flow of meter, tag already exist.
6133 : : * Set the QUEUE/RSS action to void.
6134 : : */
6135 : 0 : split_actions[qrss_idx].type = RTE_FLOW_ACTION_TYPE_VOID;
6136 : : }
6137 : : /* JUMP action to jump to mreg copy table (CP_TBL). */
6138 : 0 : jump = (void *)(set_tag + 1);
6139 : 0 : *jump = (struct rte_flow_action_jump){
6140 : : .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
6141 : : };
6142 : 0 : split_actions[actions_n - 2] = (struct rte_flow_action){
6143 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
6144 : : .conf = jump,
6145 : : };
6146 : 0 : split_actions[actions_n - 1] = (struct rte_flow_action){
6147 : : .type = RTE_FLOW_ACTION_TYPE_END,
6148 : : };
6149 : 0 : return flow_id;
6150 : : }
6151 : :
6152 : : /**
6153 : : * Extend the given action list for Tx metadata copy.
6154 : : *
6155 : : * Copy the given action list to the ext_actions and add flow metadata register
6156 : : * copy action in order to copy reg_a set by WQE to reg_c[0].
6157 : : *
6158 : : * @param[out] ext_actions
6159 : : * Pointer to the extended action list.
6160 : : * @param[in] actions
6161 : : * Pointer to the list of actions.
6162 : : * @param[in] actions_n
6163 : : * Number of actions in the list.
6164 : : * @param[out] error
6165 : : * Perform verbose error reporting if not NULL.
6166 : : * @param[in] encap_idx
6167 : : * The encap action index.
6168 : : *
6169 : : * @return
6170 : : * 0 on success, negative value otherwise
6171 : : */
6172 : : static int
6173 : 0 : flow_mreg_tx_copy_prep(struct rte_eth_dev *dev,
6174 : : struct rte_flow_action *ext_actions,
6175 : : const struct rte_flow_action *actions,
6176 : : int actions_n, struct rte_flow_error *error,
6177 : : int encap_idx)
6178 : : {
6179 : 0 : struct mlx5_flow_action_copy_mreg *cp_mreg =
6180 : : (struct mlx5_flow_action_copy_mreg *)
6181 : 0 : (ext_actions + actions_n + 1);
6182 : : int ret;
6183 : :
6184 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
6185 [ # # ]: 0 : if (ret < 0)
6186 : : return ret;
6187 : 0 : cp_mreg->dst = ret;
6188 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_TX, 0, error);
6189 [ # # ]: 0 : if (ret < 0)
6190 : : return ret;
6191 : 0 : cp_mreg->src = ret;
6192 [ # # ]: 0 : if (encap_idx != 0)
6193 : 0 : memcpy(ext_actions, actions, sizeof(*ext_actions) * encap_idx);
6194 [ # # ]: 0 : if (encap_idx == actions_n - 1) {
6195 : 0 : ext_actions[actions_n - 1] = (struct rte_flow_action){
6196 : : .type = (enum rte_flow_action_type)
6197 : : MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
6198 : : .conf = cp_mreg,
6199 : : };
6200 : 0 : ext_actions[actions_n] = (struct rte_flow_action){
6201 : : .type = RTE_FLOW_ACTION_TYPE_END,
6202 : : };
6203 : : } else {
6204 : 0 : ext_actions[encap_idx] = (struct rte_flow_action){
6205 : : .type = (enum rte_flow_action_type)
6206 : : MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
6207 : : .conf = cp_mreg,
6208 : : };
6209 : 0 : memcpy(ext_actions + encap_idx + 1, actions + encap_idx,
6210 : 0 : sizeof(*ext_actions) * (actions_n - encap_idx));
6211 : : }
6212 : : return 0;
6213 : : }
6214 : :
6215 : : /**
6216 : : * Check the match action from the action list.
6217 : : *
6218 : : * @param[in] actions
6219 : : * Pointer to the list of actions.
6220 : : * @param[in] attr
6221 : : * Flow rule attributes.
6222 : : * @param[in] action
6223 : : * The action to be check if exist.
6224 : : * @param[out] match_action_pos
6225 : : * Pointer to the position of the matched action if exists, otherwise is -1.
6226 : : * @param[out] qrss_action_pos
6227 : : * Pointer to the position of the Queue/RSS action if exists, otherwise is -1.
6228 : : * @param[out] modify_after_mirror
6229 : : * Pointer to the flag of modify action after FDB mirroring.
6230 : : *
6231 : : * @return
6232 : : * > 0 the total number of actions.
6233 : : * 0 if not found match action in action list.
6234 : : */
6235 : : static int
6236 : 0 : flow_check_match_action(const struct rte_flow_action actions[],
6237 : : const struct rte_flow_attr *attr,
6238 : : enum rte_flow_action_type action,
6239 : : int *match_action_pos, int *qrss_action_pos,
6240 : : int *modify_after_mirror)
6241 : : {
6242 : : const struct rte_flow_action_sample *sample;
6243 : : const struct rte_flow_action_raw_decap *decap;
6244 : : const struct rte_flow_action *action_cur = NULL;
6245 : : int actions_n = 0;
6246 : : uint32_t ratio = 0;
6247 : : int sub_type = 0;
6248 : : int flag = 0;
6249 : : int fdb_mirror = 0;
6250 : :
6251 : 0 : *match_action_pos = -1;
6252 : 0 : *qrss_action_pos = -1;
6253 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
6254 [ # # ]: 0 : if (actions->type == action) {
6255 : : flag = 1;
6256 : 0 : *match_action_pos = actions_n;
6257 : : }
6258 [ # # # # : 0 : switch (actions->type) {
# ]
6259 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
6260 : : case RTE_FLOW_ACTION_TYPE_RSS:
6261 : 0 : *qrss_action_pos = actions_n;
6262 : 0 : break;
6263 : 0 : case RTE_FLOW_ACTION_TYPE_SAMPLE:
6264 : 0 : sample = actions->conf;
6265 : 0 : ratio = sample->ratio;
6266 : 0 : sub_type = ((const struct rte_flow_action *)
6267 : 0 : (sample->actions))->type;
6268 [ # # # # : 0 : if (ratio == 1 && attr->transfer &&
# # ]
6269 : : sub_type != RTE_FLOW_ACTION_TYPE_END)
6270 : : fdb_mirror = 1;
6271 : : break;
6272 : 0 : case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
6273 : : case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
6274 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
6275 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
6276 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
6277 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
6278 : : case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
6279 : : case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
6280 : : case RTE_FLOW_ACTION_TYPE_DEC_TTL:
6281 : : case RTE_FLOW_ACTION_TYPE_SET_TTL:
6282 : : case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
6283 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
6284 : : case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
6285 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
6286 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
6287 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
6288 : : case RTE_FLOW_ACTION_TYPE_FLAG:
6289 : : case RTE_FLOW_ACTION_TYPE_MARK:
6290 : : case RTE_FLOW_ACTION_TYPE_SET_META:
6291 : : case RTE_FLOW_ACTION_TYPE_SET_TAG:
6292 : : case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
6293 : : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
6294 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
6295 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
6296 : : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
6297 : : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
6298 : : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
6299 : : case RTE_FLOW_ACTION_TYPE_METER:
6300 [ # # ]: 0 : if (fdb_mirror)
6301 : 0 : *modify_after_mirror = 1;
6302 : : break;
6303 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
6304 : 0 : decap = actions->conf;
6305 : : action_cur = actions;
6306 [ # # ]: 0 : while ((++action_cur)->type == RTE_FLOW_ACTION_TYPE_VOID)
6307 : : ;
6308 [ # # ]: 0 : if (action_cur->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
6309 : 0 : const struct rte_flow_action_raw_encap *encap =
6310 : : action_cur->conf;
6311 [ # # ]: 0 : if (decap->size <=
6312 : 0 : MLX5_ENCAPSULATION_DECISION_SIZE &&
6313 [ # # ]: 0 : encap->size >
6314 : : MLX5_ENCAPSULATION_DECISION_SIZE)
6315 : : /* L3 encap. */
6316 : : break;
6317 : : }
6318 [ # # ]: 0 : if (fdb_mirror)
6319 : 0 : *modify_after_mirror = 1;
6320 : : break;
6321 : : default:
6322 : : break;
6323 : : }
6324 : 0 : actions_n++;
6325 : : }
6326 [ # # # # ]: 0 : if (flag && fdb_mirror && !*modify_after_mirror) {
6327 : : /* FDB mirroring uses the destination array to implement
6328 : : * instead of FLOW_SAMPLER object.
6329 : : */
6330 [ # # ]: 0 : if (sub_type != RTE_FLOW_ACTION_TYPE_END)
6331 : : flag = 0;
6332 : : }
6333 : : /* Count RTE_FLOW_ACTION_TYPE_END. */
6334 [ # # ]: 0 : return flag ? actions_n + 1 : 0;
6335 : : }
6336 : :
6337 : : #define SAMPLE_SUFFIX_ITEM 3
6338 : :
6339 : : /**
6340 : : * Split the sample flow.
6341 : : *
6342 : : * As sample flow will split to two sub flow, sample flow with
6343 : : * sample action, the other actions will move to new suffix flow.
6344 : : *
6345 : : * Also add unique tag id with tag action in the sample flow,
6346 : : * the same tag id will be as match in the suffix flow.
6347 : : *
6348 : : * @param dev
6349 : : * Pointer to Ethernet device.
6350 : : * @param[in] add_tag
6351 : : * Add extra tag action flag.
6352 : : * @param[out] sfx_items
6353 : : * Suffix flow match items (list terminated by the END pattern item).
6354 : : * @param[in] actions
6355 : : * Associated actions (list terminated by the END action).
6356 : : * @param[out] actions_sfx
6357 : : * Suffix flow actions.
6358 : : * @param[out] actions_pre
6359 : : * Prefix flow actions.
6360 : : * @param[in] actions_n
6361 : : * The total number of actions.
6362 : : * @param[in] sample_action_pos
6363 : : * The sample action position.
6364 : : * @param[in] qrss_action_pos
6365 : : * The Queue/RSS action position.
6366 : : * @param[in] jump_table
6367 : : * Add extra jump action flag.
6368 : : * @param[out] error
6369 : : * Perform verbose error reporting if not NULL.
6370 : : *
6371 : : * @return
6372 : : * 0 on success, or unique flow_id, a negative errno value
6373 : : * otherwise and rte_errno is set.
6374 : : */
6375 : : static int
6376 : 0 : flow_sample_split_prep(struct rte_eth_dev *dev,
6377 : : int add_tag,
6378 : : const struct rte_flow_item items[],
6379 : : struct rte_flow_item sfx_items[],
6380 : : const struct rte_flow_action actions[],
6381 : : struct rte_flow_action actions_sfx[],
6382 : : struct rte_flow_action actions_pre[],
6383 : : int actions_n,
6384 : : int sample_action_pos,
6385 : : int qrss_action_pos,
6386 : : int jump_table,
6387 : : struct rte_flow_error *error)
6388 : : {
6389 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6390 : : struct mlx5_rte_flow_action_set_tag *set_tag;
6391 : : struct mlx5_rte_flow_item_tag *tag_spec;
6392 : : struct mlx5_rte_flow_item_tag *tag_mask;
6393 : : struct rte_flow_action_jump *jump_action;
6394 : 0 : uint32_t tag_id = 0;
6395 : : int append_index = 0;
6396 : : int set_tag_idx = -1;
6397 : : int index;
6398 : : int ret;
6399 : :
6400 [ # # ]: 0 : if (sample_action_pos < 0)
6401 : 0 : return rte_flow_error_set(error, EINVAL,
6402 : : RTE_FLOW_ERROR_TYPE_ACTION,
6403 : : NULL, "invalid position of sample "
6404 : : "action in list");
6405 : : /* Prepare the actions for prefix and suffix flow. */
6406 [ # # ]: 0 : if (add_tag) {
6407 : : /* Update the new added tag action index preceding
6408 : : * the PUSH_VLAN or ENCAP action.
6409 : : */
6410 : : const struct rte_flow_action_raw_encap *raw_encap;
6411 : : const struct rte_flow_action *action = actions;
6412 : : int encap_idx;
6413 : : int action_idx = 0;
6414 : : int raw_decap_idx = -1;
6415 : : int push_vlan_idx = -1;
6416 [ # # ]: 0 : for (; action->type != RTE_FLOW_ACTION_TYPE_END; action++) {
6417 [ # # # # : 0 : switch (action->type) {
# ]
6418 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
6419 : : raw_decap_idx = action_idx;
6420 : 0 : break;
6421 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
6422 : 0 : raw_encap = action->conf;
6423 [ # # ]: 0 : if (raw_encap->size >
6424 : : MLX5_ENCAPSULATION_DECISION_SIZE) {
6425 : : encap_idx = raw_decap_idx != -1 ?
6426 [ # # ]: 0 : raw_decap_idx : action_idx;
6427 : 0 : if (encap_idx < sample_action_pos &&
6428 [ # # ]: 0 : push_vlan_idx == -1)
6429 : : set_tag_idx = encap_idx;
6430 : : }
6431 : : break;
6432 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
6433 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
6434 : : encap_idx = action_idx;
6435 : 0 : if (encap_idx < sample_action_pos &&
6436 [ # # ]: 0 : push_vlan_idx == -1)
6437 : : set_tag_idx = encap_idx;
6438 : : break;
6439 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
6440 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
6441 : 0 : if (action_idx < sample_action_pos &&
6442 [ # # ]: 0 : push_vlan_idx == -1) {
6443 : : set_tag_idx = action_idx;
6444 : : push_vlan_idx = action_idx;
6445 : : }
6446 : : break;
6447 : : default:
6448 : : break;
6449 : : }
6450 : 0 : action_idx++;
6451 : : }
6452 : : }
6453 : : /* Prepare the actions for prefix and suffix flow. */
6454 [ # # ]: 0 : if (qrss_action_pos >= 0 && qrss_action_pos < sample_action_pos) {
6455 : : index = qrss_action_pos;
6456 : : /* Put the preceding the Queue/RSS action into prefix flow. */
6457 [ # # ]: 0 : if (index != 0)
6458 : 0 : memcpy(actions_pre, actions,
6459 : : sizeof(struct rte_flow_action) * index);
6460 : : /* Put others preceding the sample action into prefix flow. */
6461 [ # # ]: 0 : if (sample_action_pos > index + 1)
6462 : 0 : memcpy(actions_pre + index, actions + index + 1,
6463 : : sizeof(struct rte_flow_action) *
6464 : 0 : (sample_action_pos - index - 1));
6465 : 0 : index = sample_action_pos - 1;
6466 : : /* Put Queue/RSS action into Suffix flow. */
6467 : 0 : memcpy(actions_sfx, actions + qrss_action_pos,
6468 : : sizeof(struct rte_flow_action));
6469 : 0 : actions_sfx++;
6470 [ # # ]: 0 : } else if (add_tag && set_tag_idx >= 0) {
6471 [ # # ]: 0 : if (set_tag_idx > 0)
6472 : 0 : memcpy(actions_pre, actions,
6473 : : sizeof(struct rte_flow_action) * set_tag_idx);
6474 : 0 : memcpy(actions_pre + set_tag_idx + 1, actions + set_tag_idx,
6475 : : sizeof(struct rte_flow_action) *
6476 : 0 : (sample_action_pos - set_tag_idx));
6477 : : index = sample_action_pos;
6478 : : } else {
6479 : : index = sample_action_pos;
6480 [ # # ]: 0 : if (index != 0)
6481 : 0 : memcpy(actions_pre, actions,
6482 : : sizeof(struct rte_flow_action) * index);
6483 : : }
6484 : : /* For CX5, add an extra tag action for NIC-RX and E-Switch ingress.
6485 : : * For CX6DX and above, metadata registers Cx preserve their value,
6486 : : * add an extra tag action for NIC-RX and E-Switch Domain.
6487 : : */
6488 [ # # ]: 0 : if (add_tag) {
6489 : : /* Prepare the prefix tag action. */
6490 : : append_index++;
6491 : 0 : set_tag = (void *)(actions_pre + actions_n + append_index);
6492 : : /* Trust VF/SF on CX5 not supported meter so that the reserved
6493 : : * metadata regC is REG_NON, back to use application tag
6494 : : * index 0.
6495 : : */
6496 [ # # ]: 0 : if (unlikely(priv->sh->registers.aso_reg == REG_NON))
6497 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, 0, error);
6498 : : else
6499 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_SAMPLE_ID, 0, error);
6500 [ # # ]: 0 : if (ret < 0)
6501 : : return ret;
6502 : 0 : mlx5_ipool_malloc(priv->sh->ipool
6503 : : [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &tag_id);
6504 : 0 : *set_tag = (struct mlx5_rte_flow_action_set_tag) {
6505 : : .id = ret,
6506 : : .data = tag_id,
6507 : : };
6508 : : /* Prepare the suffix subflow items. */
6509 : 0 : tag_spec = (void *)(sfx_items + SAMPLE_SUFFIX_ITEM);
6510 : 0 : tag_spec->data = tag_id;
6511 : 0 : tag_spec->id = set_tag->id;
6512 : 0 : tag_mask = tag_spec + 1;
6513 : 0 : tag_mask->data = UINT32_MAX;
6514 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
6515 [ # # ]: 0 : if (items->type == RTE_FLOW_ITEM_TYPE_PORT_ID ||
6516 : : items->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR ||
6517 : : items->type == RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT) {
6518 : : memcpy(sfx_items, items, sizeof(*sfx_items));
6519 : 0 : sfx_items++;
6520 : 0 : break;
6521 : : }
6522 : : }
6523 : 0 : sfx_items[0] = (struct rte_flow_item){
6524 : : .type = (enum rte_flow_item_type)
6525 : : MLX5_RTE_FLOW_ITEM_TYPE_TAG,
6526 : : .spec = tag_spec,
6527 : : .last = NULL,
6528 : : .mask = tag_mask,
6529 : : };
6530 : 0 : sfx_items[1] = (struct rte_flow_item){
6531 : : .type = (enum rte_flow_item_type)
6532 : : RTE_FLOW_ITEM_TYPE_END,
6533 : : };
6534 : : /* Prepare the tag action in prefix subflow. */
6535 [ # # ]: 0 : set_tag_idx = (set_tag_idx == -1) ? index : set_tag_idx;
6536 : 0 : actions_pre[set_tag_idx] =
6537 : : (struct rte_flow_action){
6538 : : .type = (enum rte_flow_action_type)
6539 : : MLX5_RTE_FLOW_ACTION_TYPE_TAG,
6540 : : .conf = set_tag,
6541 : : };
6542 : : /* Update next sample position due to add one tag action */
6543 : 0 : index += 1;
6544 : : }
6545 : : /* Copy the sample action into prefix flow. */
6546 [ # # ]: 0 : memcpy(actions_pre + index, actions + sample_action_pos,
6547 : : sizeof(struct rte_flow_action));
6548 : 0 : index += 1;
6549 : : /* For the modify action after the sample action in E-Switch mirroring,
6550 : : * Add the extra jump action in prefix subflow and jump into the next
6551 : : * table, then do the modify action in the new table.
6552 : : */
6553 [ # # ]: 0 : if (jump_table) {
6554 : : /* Prepare the prefix jump action. */
6555 : 0 : append_index++;
6556 : 0 : jump_action = (void *)(actions_pre + actions_n + append_index);
6557 : 0 : jump_action->group = jump_table;
6558 : 0 : actions_pre[index++] =
6559 : : (struct rte_flow_action){
6560 : : .type = (enum rte_flow_action_type)
6561 : : RTE_FLOW_ACTION_TYPE_JUMP,
6562 : : .conf = jump_action,
6563 : : };
6564 : : }
6565 : 0 : actions_pre[index] = (struct rte_flow_action){
6566 : : .type = (enum rte_flow_action_type)
6567 : : RTE_FLOW_ACTION_TYPE_END,
6568 : : };
6569 : : /* Put the actions after sample into Suffix flow. */
6570 : 0 : memcpy(actions_sfx, actions + sample_action_pos + 1,
6571 : : sizeof(struct rte_flow_action) *
6572 : 0 : (actions_n - sample_action_pos - 1));
6573 : 0 : return tag_id;
6574 : : }
6575 : :
6576 : : /**
6577 : : * The splitting for metadata feature.
6578 : : *
6579 : : * - Q/RSS action on NIC Rx should be split in order to pass by
6580 : : * the mreg copy table (RX_CP_TBL) and then it jumps to the
6581 : : * action table (RX_ACT_TBL) which has the split Q/RSS action.
6582 : : *
6583 : : * - All the actions on NIC Tx should have a mreg copy action to
6584 : : * copy reg_a from WQE to reg_c[0].
6585 : : *
6586 : : * @param dev
6587 : : * Pointer to Ethernet device.
6588 : : * @param[in] flow
6589 : : * Parent flow structure pointer.
6590 : : * @param[in] attr
6591 : : * Flow rule attributes.
6592 : : * @param[in] items
6593 : : * Pattern specification (list terminated by the END pattern item).
6594 : : * @param[in] actions
6595 : : * Associated actions (list terminated by the END action).
6596 : : * @param[in] flow_split_info
6597 : : * Pointer to flow split info structure.
6598 : : * @param[out] error
6599 : : * Perform verbose error reporting if not NULL.
6600 : : * @return
6601 : : * 0 on success, negative value otherwise
6602 : : */
6603 : : static int
6604 : 0 : flow_create_split_metadata(struct rte_eth_dev *dev,
6605 : : struct rte_flow *flow,
6606 : : const struct rte_flow_attr *attr,
6607 : : const struct rte_flow_item items[],
6608 : : const struct rte_flow_action actions[],
6609 : : struct mlx5_flow_split_info *flow_split_info,
6610 : : struct rte_flow_error *error)
6611 : : {
6612 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6613 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
6614 : 0 : const struct rte_flow_action *qrss = NULL;
6615 : : struct rte_flow_action *ext_actions = NULL;
6616 : 0 : struct mlx5_flow *dev_flow = NULL;
6617 : : uint32_t qrss_id = 0;
6618 : : int mtr_sfx = 0;
6619 : : size_t act_size;
6620 : : int actions_n;
6621 : : int encap_idx;
6622 : : int ret;
6623 : :
6624 : : /* Check whether extensive metadata feature is engaged. */
6625 [ # # ]: 0 : if (!config->dv_flow_en ||
6626 [ # # # # ]: 0 : config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
6627 : 0 : !mlx5_flow_ext_mreg_supported(dev))
6628 : 0 : return flow_create_split_inner(dev, flow, NULL, attr, items,
6629 : : actions, flow_split_info, error);
6630 : 0 : actions_n = flow_parse_metadata_split_actions_info(actions, &qrss,
6631 : : &encap_idx);
6632 [ # # ]: 0 : if (qrss) {
6633 : : /* Exclude hairpin flows from splitting. */
6634 [ # # ]: 0 : if (qrss->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
6635 : : const struct rte_flow_action_queue *queue;
6636 : :
6637 : 0 : queue = qrss->conf;
6638 [ # # ]: 0 : if (mlx5_rxq_is_hairpin(dev, queue->index))
6639 : 0 : qrss = NULL;
6640 [ # # ]: 0 : } else if (qrss->type == RTE_FLOW_ACTION_TYPE_RSS) {
6641 : : const struct rte_flow_action_rss *rss;
6642 : :
6643 : 0 : rss = qrss->conf;
6644 [ # # ]: 0 : if (mlx5_rxq_is_hairpin(dev, rss->queue[0]))
6645 : 0 : qrss = NULL;
6646 : : }
6647 : : }
6648 [ # # ]: 0 : if (qrss) {
6649 : : /* Check if it is in meter suffix table. */
6650 : 0 : mtr_sfx = attr->group ==
6651 [ # # ]: 0 : ((attr->transfer && priv->fdb_def_rule) ?
6652 [ # # ]: 0 : (MLX5_FLOW_TABLE_LEVEL_METER - 1) :
6653 : : MLX5_FLOW_TABLE_LEVEL_METER);
6654 : : /*
6655 : : * Q/RSS action on NIC Rx should be split in order to pass by
6656 : : * the mreg copy table (RX_CP_TBL) and then it jumps to the
6657 : : * action table (RX_ACT_TBL) which has the split Q/RSS action.
6658 : : */
6659 : 0 : act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
6660 : 0 : sizeof(struct rte_flow_action_set_tag) +
6661 : : sizeof(struct rte_flow_action_jump);
6662 : 0 : ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
6663 : : SOCKET_ID_ANY);
6664 [ # # ]: 0 : if (!ext_actions)
6665 : 0 : return rte_flow_error_set(error, ENOMEM,
6666 : : RTE_FLOW_ERROR_TYPE_ACTION,
6667 : : NULL, "no memory to split "
6668 : : "metadata flow");
6669 : : /*
6670 : : * Create the new actions list with removed Q/RSS action
6671 : : * and appended set tag and jump to register copy table
6672 : : * (RX_CP_TBL). We should preallocate unique tag ID here
6673 : : * in advance, because it is needed for set tag action.
6674 : : */
6675 : 0 : qrss_id = flow_mreg_split_qrss_prep(dev, ext_actions, actions,
6676 : : qrss, actions_n,
6677 : : mtr_sfx, error);
6678 [ # # ]: 0 : if (!mtr_sfx && !qrss_id) {
6679 : 0 : ret = -rte_errno;
6680 : 0 : goto exit;
6681 : : }
6682 [ # # ]: 0 : } else if (attr->egress) {
6683 : : /*
6684 : : * All the actions on NIC Tx should have a metadata register
6685 : : * copy action to copy reg_a from WQE to reg_c[meta]
6686 : : */
6687 : 0 : act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
6688 : : sizeof(struct mlx5_flow_action_copy_mreg);
6689 : 0 : ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
6690 : : SOCKET_ID_ANY);
6691 [ # # ]: 0 : if (!ext_actions)
6692 : 0 : return rte_flow_error_set(error, ENOMEM,
6693 : : RTE_FLOW_ERROR_TYPE_ACTION,
6694 : : NULL, "no memory to split "
6695 : : "metadata flow");
6696 : : /* Create the action list appended with copy register. */
6697 : 0 : ret = flow_mreg_tx_copy_prep(dev, ext_actions, actions,
6698 : : actions_n, error, encap_idx);
6699 [ # # ]: 0 : if (ret < 0)
6700 : 0 : goto exit;
6701 : : }
6702 : : /* Add the unmodified original or prefix subflow. */
6703 [ # # ]: 0 : ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
6704 : : items, ext_actions ? ext_actions :
6705 : : actions, flow_split_info, error);
6706 [ # # ]: 0 : if (ret < 0)
6707 : 0 : goto exit;
6708 : : MLX5_ASSERT(dev_flow);
6709 [ # # ]: 0 : if (qrss) {
6710 : 0 : const struct rte_flow_attr q_attr = {
6711 : : .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
6712 : : .ingress = 1,
6713 : : };
6714 : : /* Internal PMD action to set register. */
6715 : 0 : struct mlx5_rte_flow_item_tag q_tag_spec = {
6716 : : .data = qrss_id,
6717 : : .id = REG_NON,
6718 : : };
6719 : 0 : struct rte_flow_item q_items[] = {
6720 : : {
6721 : : .type = (enum rte_flow_item_type)
6722 : : MLX5_RTE_FLOW_ITEM_TYPE_TAG,
6723 : : .spec = &q_tag_spec,
6724 : : .last = NULL,
6725 : : .mask = NULL,
6726 : : },
6727 : : {
6728 : : .type = RTE_FLOW_ITEM_TYPE_END,
6729 : : },
6730 : : };
6731 : 0 : struct rte_flow_action q_actions[] = {
6732 : : {
6733 : 0 : .type = qrss->type,
6734 : 0 : .conf = qrss->conf,
6735 : : },
6736 : : {
6737 : : .type = RTE_FLOW_ACTION_TYPE_END,
6738 : : },
6739 : : };
6740 : 0 : uint64_t layers = flow_get_prefix_layer_flags(dev_flow);
6741 : :
6742 : : /*
6743 : : * Configure the tag item only if there is no meter subflow.
6744 : : * Since tag is already marked in the meter suffix subflow
6745 : : * we can just use the meter suffix items as is.
6746 : : */
6747 [ # # ]: 0 : if (qrss_id) {
6748 : : /* Not meter subflow. */
6749 : : MLX5_ASSERT(!mtr_sfx);
6750 : : /*
6751 : : * Put unique id in prefix flow due to it is destroyed
6752 : : * after suffix flow and id will be freed after there
6753 : : * is no actual flows with this id and identifier
6754 : : * reallocation becomes possible (for example, for
6755 : : * other flows in other threads).
6756 : : */
6757 : 0 : dev_flow->handle->split_flow_id = qrss_id;
6758 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0,
6759 : : error);
6760 [ # # ]: 0 : if (ret < 0)
6761 : 0 : goto exit;
6762 : 0 : q_tag_spec.id = ret;
6763 : : }
6764 : 0 : dev_flow = NULL;
6765 : : /* Add suffix subflow to execute Q/RSS. */
6766 : 0 : flow_split_info->prefix_layers = layers;
6767 : 0 : flow_split_info->prefix_mark = 0;
6768 : 0 : flow_split_info->table_id = 0;
6769 [ # # ]: 0 : ret = flow_create_split_inner(dev, flow, &dev_flow,
6770 : : &q_attr, mtr_sfx ? items :
6771 : : q_items, q_actions,
6772 : : flow_split_info, error);
6773 [ # # ]: 0 : if (ret < 0)
6774 : 0 : goto exit;
6775 : : /* qrss ID should be freed if failed. */
6776 : : qrss_id = 0;
6777 : : MLX5_ASSERT(dev_flow);
6778 : : }
6779 : :
6780 : 0 : exit:
6781 : : /*
6782 : : * We do not destroy the partially created sub_flows in case of error.
6783 : : * These ones are included into parent flow list and will be destroyed
6784 : : * by flow_drv_destroy.
6785 : : */
6786 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
6787 : : qrss_id);
6788 : 0 : mlx5_free(ext_actions);
6789 : 0 : return ret;
6790 : : }
6791 : :
6792 : : /**
6793 : : * Create meter internal drop flow with the original pattern.
6794 : : *
6795 : : * @param dev
6796 : : * Pointer to Ethernet device.
6797 : : * @param[in] flow
6798 : : * Parent flow structure pointer.
6799 : : * @param[in] attr
6800 : : * Flow rule attributes.
6801 : : * @param[in] items
6802 : : * Pattern specification (list terminated by the END pattern item).
6803 : : * @param[in] flow_split_info
6804 : : * Pointer to flow split info structure.
6805 : : * @param[in] fm
6806 : : * Pointer to flow meter structure.
6807 : : * @param[out] error
6808 : : * Perform verbose error reporting if not NULL.
6809 : : * @return
6810 : : * 0 on success, negative value otherwise
6811 : : */
6812 : : static uint32_t
6813 : 0 : flow_meter_create_drop_flow_with_org_pattern(struct rte_eth_dev *dev,
6814 : : struct rte_flow *flow,
6815 : : const struct rte_flow_attr *attr,
6816 : : const struct rte_flow_item items[],
6817 : : struct mlx5_flow_split_info *flow_split_info,
6818 : : struct mlx5_flow_meter_info *fm,
6819 : : struct rte_flow_error *error)
6820 : : {
6821 : 0 : struct mlx5_flow *dev_flow = NULL;
6822 : 0 : struct rte_flow_attr drop_attr = *attr;
6823 : : struct rte_flow_action drop_actions[3];
6824 : 0 : struct mlx5_flow_split_info drop_split_info = *flow_split_info;
6825 : :
6826 : : MLX5_ASSERT(fm->drop_cnt);
6827 : 0 : drop_actions[0].type =
6828 : : (enum rte_flow_action_type)MLX5_RTE_FLOW_ACTION_TYPE_COUNT;
6829 : 0 : drop_actions[0].conf = (void *)(uintptr_t)fm->drop_cnt;
6830 : 0 : drop_actions[1].type = RTE_FLOW_ACTION_TYPE_DROP;
6831 : 0 : drop_actions[1].conf = NULL;
6832 : 0 : drop_actions[2].type = RTE_FLOW_ACTION_TYPE_END;
6833 : 0 : drop_actions[2].conf = NULL;
6834 : 0 : drop_split_info.external = false;
6835 : 0 : drop_split_info.skip_scale |= 1 << MLX5_SCALE_FLOW_GROUP_BIT;
6836 : 0 : drop_split_info.table_id = MLX5_MTR_TABLE_ID_DROP;
6837 : 0 : drop_attr.group = MLX5_FLOW_TABLE_LEVEL_METER;
6838 : 0 : return flow_create_split_inner(dev, flow, &dev_flow,
6839 : : &drop_attr, items, drop_actions,
6840 : : &drop_split_info, error);
6841 : : }
6842 : :
6843 : : static int
6844 : : flow_count_vlan_items(const struct rte_flow_item items[])
6845 : : {
6846 : : int items_n = 0;
6847 : :
6848 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
6849 [ # # ]: 0 : if (items->type == RTE_FLOW_ITEM_TYPE_VLAN ||
6850 : : items->type == (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_VLAN)
6851 : 0 : items_n++;
6852 : : }
6853 : : return items_n;
6854 : : }
6855 : :
6856 : : /**
6857 : : * The splitting for meter feature.
6858 : : *
6859 : : * - The meter flow will be split to two flows as prefix and
6860 : : * suffix flow. The packets make sense only it pass the prefix
6861 : : * meter action.
6862 : : *
6863 : : * - Reg_C_5 is used for the packet to match betweend prefix and
6864 : : * suffix flow.
6865 : : *
6866 : : * @param dev
6867 : : * Pointer to Ethernet device.
6868 : : * @param[in] flow
6869 : : * Parent flow structure pointer.
6870 : : * @param[in] attr
6871 : : * Flow rule attributes.
6872 : : * @param[in] items
6873 : : * Pattern specification (list terminated by the END pattern item).
6874 : : * @param[in] actions
6875 : : * Associated actions (list terminated by the END action).
6876 : : * @param[in] flow_split_info
6877 : : * Pointer to flow split info structure.
6878 : : * @param[out] error
6879 : : * Perform verbose error reporting if not NULL.
6880 : : * @return
6881 : : * 0 on success, negative value otherwise
6882 : : */
6883 : : static int
6884 : 0 : flow_create_split_meter(struct rte_eth_dev *dev,
6885 : : struct rte_flow *flow,
6886 : : const struct rte_flow_attr *attr,
6887 : : const struct rte_flow_item items[],
6888 : : const struct rte_flow_action actions[],
6889 : : struct mlx5_flow_split_info *flow_split_info,
6890 : : struct rte_flow_error *error)
6891 : : {
6892 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6893 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
6894 : : struct rte_flow_action *sfx_actions = NULL;
6895 : : struct rte_flow_action *pre_actions = NULL;
6896 : : struct rte_flow_item *sfx_items = NULL;
6897 : 0 : struct mlx5_flow *dev_flow = NULL;
6898 : 0 : struct rte_flow_attr sfx_attr = *attr;
6899 : : struct mlx5_flow_meter_info *fm = NULL;
6900 : : uint8_t skip_scale_restore;
6901 : 0 : bool has_mtr = false;
6902 : 0 : bool has_modify = false;
6903 : : bool set_mtr_reg = true;
6904 : : bool is_mtr_hierarchy = false;
6905 : 0 : uint32_t meter_id = 0;
6906 : 0 : uint32_t mtr_idx = 0;
6907 : 0 : uint32_t mtr_flow_id = 0;
6908 : : size_t act_size;
6909 : : size_t item_size;
6910 : : int actions_n = 0;
6911 : : int vlan_items_n = 0;
6912 : : int ret = 0;
6913 : :
6914 [ # # ]: 0 : if (priv->mtr_en)
6915 : 0 : actions_n = flow_check_meter_action(dev, actions, &has_mtr,
6916 : : &has_modify, &meter_id);
6917 [ # # ]: 0 : if (has_mtr) {
6918 [ # # ]: 0 : if (flow->meter) {
6919 : 0 : fm = flow_dv_meter_find_by_idx(priv, flow->meter);
6920 [ # # ]: 0 : if (!fm)
6921 : 0 : return rte_flow_error_set(error, EINVAL,
6922 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6923 : : NULL, "Meter not found.");
6924 : : } else {
6925 : 0 : fm = mlx5_flow_meter_find(priv, meter_id, &mtr_idx);
6926 [ # # ]: 0 : if (!fm)
6927 : 0 : return rte_flow_error_set(error, EINVAL,
6928 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6929 : : NULL, "Meter not found.");
6930 : 0 : ret = mlx5_flow_meter_attach(priv, fm,
6931 : : &sfx_attr, error);
6932 [ # # ]: 0 : if (ret)
6933 : 0 : return -rte_errno;
6934 : 0 : flow->meter = mtr_idx;
6935 : : }
6936 : : MLX5_ASSERT(wks);
6937 : 0 : wks->fm = fm;
6938 [ # # ]: 0 : if (!fm->def_policy) {
6939 : 0 : wks->policy = mlx5_flow_meter_policy_find(dev,
6940 : : fm->policy_id,
6941 : : NULL);
6942 : : MLX5_ASSERT(wks->policy);
6943 [ # # ]: 0 : if (wks->policy->mark)
6944 : 0 : wks->mark = 1;
6945 [ # # ]: 0 : if (wks->policy->is_hierarchy) {
6946 : 0 : wks->final_policy =
6947 : 0 : mlx5_flow_meter_hierarchy_get_final_policy(dev,
6948 : : wks->policy);
6949 [ # # ]: 0 : if (!wks->final_policy)
6950 : 0 : return rte_flow_error_set(error,
6951 : : EINVAL,
6952 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6953 : : "Failed to find terminal policy of hierarchy.");
6954 : : is_mtr_hierarchy = true;
6955 : : }
6956 : : }
6957 : : /*
6958 : : * If it isn't default-policy Meter, and
6959 : : * 1. Not meter hierarchy and there's no action in flow to change
6960 : : * packet (modify/encap/decap etc.), OR
6961 : : * 2. No drop count needed for this meter.
6962 : : * Then no need to use regC to save meter id anymore.
6963 : : */
6964 [ # # # # : 0 : if (!fm->def_policy && ((!has_modify && !is_mtr_hierarchy) || !fm->drop_cnt))
# # # # ]
6965 : : set_mtr_reg = false;
6966 : : /* Prefix actions: meter, decap, encap, tag, jump, end, cnt. */
6967 : : #define METER_PREFIX_ACTION 7
6968 : 0 : act_size = (sizeof(struct rte_flow_action) *
6969 : 0 : (actions_n + METER_PREFIX_ACTION)) +
6970 : : sizeof(struct mlx5_rte_flow_action_set_tag);
6971 : : /* Flow can have multiple VLAN items. Account for them in suffix items. */
6972 : : vlan_items_n = flow_count_vlan_items(items);
6973 : : /* Suffix items: tag, [vlans], port id, end. */
6974 : : #define METER_SUFFIX_ITEM 3
6975 : 0 : item_size = sizeof(struct rte_flow_item) * (METER_SUFFIX_ITEM + vlan_items_n) +
6976 : : sizeof(struct mlx5_rte_flow_item_tag) * 2;
6977 : 0 : sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size + item_size),
6978 : : 0, SOCKET_ID_ANY);
6979 [ # # ]: 0 : if (!sfx_actions)
6980 : 0 : return rte_flow_error_set(error, ENOMEM,
6981 : : RTE_FLOW_ERROR_TYPE_ACTION,
6982 : : NULL, "no memory to split "
6983 : : "meter flow");
6984 : 0 : sfx_items = (struct rte_flow_item *)((char *)sfx_actions +
6985 : : act_size);
6986 : : /* There's no suffix flow for meter of non-default policy. */
6987 [ # # ]: 0 : if (!fm->def_policy)
6988 : 0 : pre_actions = sfx_actions + 1;
6989 : : else
6990 : 0 : pre_actions = sfx_actions + actions_n;
6991 [ # # ]: 0 : ret = flow_meter_split_prep(dev, flow, wks, &sfx_attr,
6992 : : items, sfx_items, actions,
6993 : : sfx_actions, pre_actions,
6994 : : (set_mtr_reg ? &mtr_flow_id : NULL),
6995 : : error);
6996 [ # # ]: 0 : if (ret) {
6997 : 0 : ret = -rte_errno;
6998 : 0 : goto exit;
6999 : : }
7000 : : /* Add the prefix subflow. */
7001 : 0 : skip_scale_restore = flow_split_info->skip_scale;
7002 : 0 : flow_split_info->skip_scale |=
7003 : : 1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT;
7004 : 0 : ret = flow_create_split_inner(dev, flow, &dev_flow,
7005 : : attr, items, pre_actions,
7006 : : flow_split_info, error);
7007 : 0 : flow_split_info->skip_scale = skip_scale_restore;
7008 [ # # ]: 0 : if (ret) {
7009 [ # # ]: 0 : if (mtr_flow_id)
7010 : 0 : mlx5_ipool_free(fm->flow_ipool, mtr_flow_id);
7011 : 0 : ret = -rte_errno;
7012 : 0 : goto exit;
7013 : : }
7014 [ # # ]: 0 : if (mtr_flow_id) {
7015 : 0 : dev_flow->handle->split_flow_id = mtr_flow_id;
7016 : 0 : dev_flow->handle->is_meter_flow_id = 1;
7017 : : }
7018 [ # # ]: 0 : if (!fm->def_policy) {
7019 [ # # # # ]: 0 : if (!set_mtr_reg && fm->drop_cnt)
7020 : 0 : ret =
7021 : 0 : flow_meter_create_drop_flow_with_org_pattern(dev, flow,
7022 : : &sfx_attr, items,
7023 : : flow_split_info,
7024 : : fm, error);
7025 : 0 : goto exit;
7026 : : }
7027 : : /* Setting the sfx group atrr. */
7028 : 0 : sfx_attr.group = sfx_attr.transfer ?
7029 [ # # ]: 0 : (MLX5_FLOW_TABLE_LEVEL_METER - 1) :
7030 : : MLX5_FLOW_TABLE_LEVEL_METER;
7031 : 0 : flow_split_info->prefix_layers =
7032 : 0 : flow_get_prefix_layer_flags(dev_flow);
7033 : 0 : flow_split_info->prefix_mark |= wks->mark;
7034 : 0 : flow_split_info->table_id = MLX5_MTR_TABLE_ID_SUFFIX;
7035 : : }
7036 : : /* Add the prefix subflow. */
7037 [ # # ]: 0 : ret = flow_create_split_metadata(dev, flow,
7038 : : &sfx_attr, sfx_items ?
7039 : : sfx_items : items,
7040 : : sfx_actions ? sfx_actions : actions,
7041 : : flow_split_info, error);
7042 : 0 : exit:
7043 [ # # ]: 0 : if (sfx_actions)
7044 : 0 : mlx5_free(sfx_actions);
7045 : : return ret;
7046 : : }
7047 : :
7048 : : /**
7049 : : * The splitting for sample feature.
7050 : : *
7051 : : * Once Sample action is detected in the action list, the flow actions should
7052 : : * be split into prefix sub flow and suffix sub flow.
7053 : : *
7054 : : * The original items remain in the prefix sub flow, all actions preceding the
7055 : : * sample action and the sample action itself will be copied to the prefix
7056 : : * sub flow, the actions following the sample action will be copied to the
7057 : : * suffix sub flow, Queue action always be located in the suffix sub flow.
7058 : : *
7059 : : * In order to make the packet from prefix sub flow matches with suffix sub
7060 : : * flow, an extra tag action be added into prefix sub flow, and the suffix sub
7061 : : * flow uses tag item with the unique flow id.
7062 : : *
7063 : : * @param dev
7064 : : * Pointer to Ethernet device.
7065 : : * @param[in] flow
7066 : : * Parent flow structure pointer.
7067 : : * @param[in] attr
7068 : : * Flow rule attributes.
7069 : : * @param[in] items
7070 : : * Pattern specification (list terminated by the END pattern item).
7071 : : * @param[in] actions
7072 : : * Associated actions (list terminated by the END action).
7073 : : * @param[in] flow_split_info
7074 : : * Pointer to flow split info structure.
7075 : : * @param[out] error
7076 : : * Perform verbose error reporting if not NULL.
7077 : : * @return
7078 : : * 0 on success, negative value otherwise
7079 : : */
7080 : : static int
7081 : 0 : flow_create_split_sample(struct rte_eth_dev *dev,
7082 : : struct rte_flow *flow,
7083 : : const struct rte_flow_attr *attr,
7084 : : const struct rte_flow_item items[],
7085 : : const struct rte_flow_action actions[],
7086 : : struct mlx5_flow_split_info *flow_split_info,
7087 : : struct rte_flow_error *error)
7088 : : {
7089 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7090 : : struct rte_flow_action *sfx_actions = NULL;
7091 : : struct rte_flow_action *pre_actions = NULL;
7092 : : struct rte_flow_item *sfx_items = NULL;
7093 : 0 : struct mlx5_flow *dev_flow = NULL;
7094 : 0 : struct rte_flow_attr sfx_attr = *attr;
7095 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
7096 : : struct mlx5_flow_dv_sample_resource *sample_res;
7097 : : struct mlx5_flow_tbl_data_entry *sfx_tbl_data;
7098 : : struct mlx5_flow_tbl_resource *sfx_tbl;
7099 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
7100 : : #endif
7101 : : size_t act_size;
7102 : : size_t item_size;
7103 : : uint32_t fdb_tx = 0;
7104 : : int32_t tag_id = 0;
7105 : : int actions_n = 0;
7106 : : int sample_action_pos;
7107 : : int qrss_action_pos;
7108 : : int add_tag = 0;
7109 : 0 : int modify_after_mirror = 0;
7110 : : uint16_t jump_table = 0;
7111 : : const uint32_t next_ft_step = 1;
7112 : : int ret = 0;
7113 : : struct mlx5_priv *item_port_priv = NULL;
7114 : : const struct rte_flow_item *item;
7115 : :
7116 [ # # ]: 0 : if (priv->sampler_en)
7117 : 0 : actions_n = flow_check_match_action(actions, attr,
7118 : : RTE_FLOW_ACTION_TYPE_SAMPLE,
7119 : : &sample_action_pos, &qrss_action_pos,
7120 : : &modify_after_mirror);
7121 [ # # ]: 0 : if (actions_n) {
7122 : : /* The prefix actions must includes sample, tag, end. */
7123 : 0 : act_size = sizeof(struct rte_flow_action) * (actions_n * 2 + 1)
7124 : : + sizeof(struct mlx5_rte_flow_action_set_tag);
7125 : : item_size = sizeof(struct rte_flow_item) * SAMPLE_SUFFIX_ITEM +
7126 : : sizeof(struct mlx5_rte_flow_item_tag) * 2;
7127 : 0 : sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size +
7128 : : item_size), 0, SOCKET_ID_ANY);
7129 [ # # ]: 0 : if (!sfx_actions)
7130 : 0 : return rte_flow_error_set(error, ENOMEM,
7131 : : RTE_FLOW_ERROR_TYPE_ACTION,
7132 : : NULL, "no memory to split "
7133 : : "sample flow");
7134 [ # # ]: 0 : for (item = items; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
7135 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_PORT_ID) {
7136 : : const struct rte_flow_item_port_id *spec;
7137 : :
7138 : 0 : spec = (const struct rte_flow_item_port_id *)item->spec;
7139 [ # # ]: 0 : if (spec)
7140 : : item_port_priv =
7141 : 0 : mlx5_port_to_eswitch_info(spec->id, true);
7142 : : break;
7143 [ # # ]: 0 : } else if (item->type == RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT) {
7144 : : const struct rte_flow_item_ethdev *spec;
7145 : :
7146 : 0 : spec = (const struct rte_flow_item_ethdev *)item->spec;
7147 [ # # ]: 0 : if (spec)
7148 : : item_port_priv =
7149 : 0 : mlx5_port_to_eswitch_info(spec->port_id, true);
7150 : : break;
7151 [ # # ]: 0 : } else if (item->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR) {
7152 : : const struct rte_flow_item_ethdev *spec;
7153 : :
7154 : 0 : spec = (const struct rte_flow_item_ethdev *)item->spec;
7155 [ # # ]: 0 : if (spec)
7156 : : item_port_priv =
7157 : 0 : mlx5_port_to_eswitch_info(spec->port_id, true);
7158 : : break;
7159 : : }
7160 : : }
7161 : : /* The representor_id is UINT16_MAX for uplink. */
7162 [ # # # # ]: 0 : fdb_tx = (attr->transfer &&
7163 : : flow_source_vport_representor(priv, item_port_priv));
7164 : : /*
7165 : : * When reg_c_preserve is set, metadata registers Cx preserve
7166 : : * their value even through packet duplication.
7167 : : */
7168 : 0 : add_tag = (!fdb_tx ||
7169 [ # # ]: 0 : priv->sh->cdev->config.hca_attr.reg_c_preserve);
7170 : : if (add_tag)
7171 : 0 : sfx_items = (struct rte_flow_item *)((char *)sfx_actions
7172 : : + act_size);
7173 [ # # ]: 0 : if (modify_after_mirror)
7174 : 0 : jump_table = attr->group * MLX5_FLOW_TABLE_FACTOR +
7175 : : next_ft_step;
7176 : 0 : pre_actions = sfx_actions + actions_n;
7177 : 0 : tag_id = flow_sample_split_prep(dev, add_tag, items, sfx_items,
7178 : : actions, sfx_actions,
7179 : : pre_actions, actions_n,
7180 : : sample_action_pos,
7181 : : qrss_action_pos, jump_table,
7182 : : error);
7183 [ # # # # ]: 0 : if (tag_id < 0 || (add_tag && !tag_id)) {
7184 : 0 : ret = -rte_errno;
7185 : 0 : goto exit;
7186 : : }
7187 [ # # ]: 0 : if (modify_after_mirror)
7188 : 0 : flow_split_info->skip_scale =
7189 : : 1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT;
7190 : : /* Add the prefix subflow. */
7191 : 0 : ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
7192 : : items, pre_actions,
7193 : : flow_split_info, error);
7194 [ # # ]: 0 : if (ret) {
7195 : 0 : ret = -rte_errno;
7196 : 0 : goto exit;
7197 : : }
7198 : 0 : dev_flow->handle->split_flow_id = tag_id;
7199 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
7200 [ # # ]: 0 : if (!modify_after_mirror) {
7201 : : /* Set the sfx group attr. */
7202 : 0 : sample_res = (struct mlx5_flow_dv_sample_resource *)
7203 : : dev_flow->dv.sample_res;
7204 : 0 : sfx_tbl = (struct mlx5_flow_tbl_resource *)
7205 : : sample_res->normal_path_tbl;
7206 : 0 : sfx_tbl_data = container_of(sfx_tbl,
7207 : : struct mlx5_flow_tbl_data_entry,
7208 : : tbl);
7209 : 0 : sfx_attr.group = sfx_attr.transfer ?
7210 [ # # ]: 0 : (sfx_tbl_data->level - 1) : sfx_tbl_data->level;
7211 : : } else {
7212 : : MLX5_ASSERT(attr->transfer);
7213 : 0 : sfx_attr.group = jump_table;
7214 : : }
7215 : 0 : flow_split_info->prefix_layers =
7216 : 0 : flow_get_prefix_layer_flags(dev_flow);
7217 : : MLX5_ASSERT(wks);
7218 : 0 : flow_split_info->prefix_mark |= wks->mark;
7219 : : /* Suffix group level already be scaled with factor, set
7220 : : * MLX5_SCALE_FLOW_GROUP_BIT of skip_scale to 1 to avoid scale
7221 : : * again in translation.
7222 : : */
7223 : 0 : flow_split_info->skip_scale = 1 << MLX5_SCALE_FLOW_GROUP_BIT;
7224 : : #endif
7225 : : }
7226 : : /* Add the suffix subflow. */
7227 [ # # # # ]: 0 : ret = flow_create_split_meter(dev, flow, &sfx_attr,
7228 : : sfx_items ? sfx_items : items,
7229 : : sfx_actions ? sfx_actions : actions,
7230 : : flow_split_info, error);
7231 : 0 : exit:
7232 [ # # ]: 0 : if (sfx_actions)
7233 : 0 : mlx5_free(sfx_actions);
7234 : : return ret;
7235 : : }
7236 : :
7237 : : /**
7238 : : * Split the flow to subflow set. The splitters might be linked
7239 : : * in the chain, like this:
7240 : : * flow_create_split_outer() calls:
7241 : : * flow_create_split_meter() calls:
7242 : : * flow_create_split_metadata(meter_subflow_0) calls:
7243 : : * flow_create_split_inner(metadata_subflow_0)
7244 : : * flow_create_split_inner(metadata_subflow_1)
7245 : : * flow_create_split_inner(metadata_subflow_2)
7246 : : * flow_create_split_metadata(meter_subflow_1) calls:
7247 : : * flow_create_split_inner(metadata_subflow_0)
7248 : : * flow_create_split_inner(metadata_subflow_1)
7249 : : * flow_create_split_inner(metadata_subflow_2)
7250 : : *
7251 : : * This provide flexible way to add new levels of flow splitting.
7252 : : * The all of successfully created subflows are included to the
7253 : : * parent flow dev_flow list.
7254 : : *
7255 : : * @param dev
7256 : : * Pointer to Ethernet device.
7257 : : * @param[in] flow
7258 : : * Parent flow structure pointer.
7259 : : * @param[in] attr
7260 : : * Flow rule attributes.
7261 : : * @param[in] items
7262 : : * Pattern specification (list terminated by the END pattern item).
7263 : : * @param[in] actions
7264 : : * Associated actions (list terminated by the END action).
7265 : : * @param[in] flow_split_info
7266 : : * Pointer to flow split info structure.
7267 : : * @param[out] error
7268 : : * Perform verbose error reporting if not NULL.
7269 : : * @return
7270 : : * 0 on success, negative value otherwise
7271 : : */
7272 : : static int
7273 : : flow_create_split_outer(struct rte_eth_dev *dev,
7274 : : struct rte_flow *flow,
7275 : : const struct rte_flow_attr *attr,
7276 : : const struct rte_flow_item items[],
7277 : : const struct rte_flow_action actions[],
7278 : : struct mlx5_flow_split_info *flow_split_info,
7279 : : struct rte_flow_error *error)
7280 : : {
7281 : : int ret;
7282 : :
7283 : 0 : ret = flow_create_split_sample(dev, flow, attr, items,
7284 : : actions, flow_split_info, error);
7285 : : MLX5_ASSERT(ret <= 0);
7286 : : return ret;
7287 : : }
7288 : :
7289 : : static inline struct mlx5_flow_tunnel *
7290 : : flow_tunnel_from_rule(const struct mlx5_flow *flow)
7291 : : {
7292 : : struct mlx5_flow_tunnel *tunnel;
7293 : :
7294 : 0 : tunnel = RTE_PTR_UNQUAL(flow->tunnel);
7295 : :
7296 : : return tunnel;
7297 : : }
7298 : :
7299 : : /**
7300 : : * Create a flow and add it to @p list.
7301 : : *
7302 : : * @param dev
7303 : : * Pointer to Ethernet device.
7304 : : * @param list
7305 : : * Pointer to a TAILQ flow list. If this parameter NULL,
7306 : : * no list insertion occurred, flow is just created,
7307 : : * this is caller's responsibility to track the
7308 : : * created flow.
7309 : : * @param[in] attr
7310 : : * Flow rule attributes.
7311 : : * @param[in] items
7312 : : * Pattern specification (list terminated by the END pattern item).
7313 : : * @param[in] actions
7314 : : * Associated actions (list terminated by the END action).
7315 : : * @param[in] external
7316 : : * This flow rule is created by request external to PMD.
7317 : : * @param[out] error
7318 : : * Perform verbose error reporting if not NULL.
7319 : : *
7320 : : * @return
7321 : : * A flow index on success, 0 otherwise and rte_errno is set.
7322 : : */
7323 : : uintptr_t
7324 : 0 : flow_legacy_list_create(struct rte_eth_dev *dev, enum mlx5_flow_type type,
7325 : : const struct rte_flow_attr *attr,
7326 : : const struct rte_flow_item items[],
7327 : : const struct rte_flow_action original_actions[],
7328 : : bool external, struct rte_flow_error *error)
7329 : : {
7330 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7331 : : struct rte_flow *flow = NULL;
7332 : : struct mlx5_flow *dev_flow;
7333 : : const struct rte_flow_action_rss *rss = NULL;
7334 : : struct mlx5_translated_action_handle
7335 : : indir_actions[MLX5_MAX_INDIRECT_ACTIONS];
7336 : 0 : int indir_actions_n = MLX5_MAX_INDIRECT_ACTIONS;
7337 : : union {
7338 : : struct mlx5_flow_expand_rss buf;
7339 : : uint8_t buffer[8192];
7340 : : } expand_buffer;
7341 : : union {
7342 : : struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
7343 : : uint8_t buffer[2048];
7344 : : } actions_rx;
7345 : : union {
7346 : : struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
7347 : : uint8_t buffer[2048];
7348 : : } actions_hairpin_tx;
7349 : : union {
7350 : : struct rte_flow_item items[MLX5_MAX_SPLIT_ITEMS];
7351 : : uint8_t buffer[2048];
7352 : : } items_tx;
7353 : : struct mlx5_rte_flow_item_sq sq_specs[RTE_MAX_QUEUES_PER_PORT];
7354 : : struct mlx5_flow_expand_rss *buf = &expand_buffer.buf;
7355 : : struct mlx5_flow_rss_desc *rss_desc;
7356 : : const struct rte_flow_action *p_actions_rx;
7357 : : uint32_t i;
7358 : 0 : uint32_t idx = 0;
7359 : : int hairpin_flow;
7360 : 0 : struct rte_flow_attr attr_tx = { .priority = 0 };
7361 : : const struct rte_flow_action *actions;
7362 : 0 : struct rte_flow_action *translated_actions = NULL;
7363 : : struct mlx5_flow_tunnel *tunnel;
7364 : 0 : struct tunnel_default_miss_ctx default_miss_ctx = { 0, };
7365 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_push_thread_workspace();
7366 : 0 : struct mlx5_flow_split_info flow_split_info = {
7367 : : .external = !!external,
7368 : : .skip_scale = 0,
7369 : : .flow_idx = 0,
7370 : : .prefix_mark = 0,
7371 : : .prefix_layers = 0,
7372 : : .table_id = 0
7373 : : };
7374 : : int ret;
7375 : : struct mlx5_shared_action_rss *shared_rss_action;
7376 : :
7377 [ # # ]: 0 : if (!wks)
7378 : 0 : return rte_flow_error_set(error, ENOMEM,
7379 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7380 : : NULL,
7381 : : "failed to push flow workspace");
7382 : : memset(indir_actions, 0, sizeof(indir_actions));
7383 : 0 : rss_desc = &wks->rss_desc;
7384 : 0 : ret = flow_action_handles_translate(dev, original_actions,
7385 : : indir_actions,
7386 : : &indir_actions_n,
7387 : : &translated_actions, error);
7388 [ # # ]: 0 : if (ret < 0) {
7389 : : MLX5_ASSERT(translated_actions == NULL);
7390 : : return 0;
7391 : : }
7392 [ # # ]: 0 : actions = translated_actions ? translated_actions : original_actions;
7393 : : p_actions_rx = actions;
7394 : 0 : hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
7395 : 0 : ret = flow_drv_validate(dev, attr, items, p_actions_rx,
7396 : : external, hairpin_flow, error);
7397 [ # # ]: 0 : if (ret < 0)
7398 : 0 : goto error_before_hairpin_split;
7399 : 0 : flow = mlx5_ipool_zmalloc(priv->flows[type], &idx);
7400 [ # # ]: 0 : if (!flow) {
7401 : 0 : rte_errno = ENOMEM;
7402 : 0 : goto error_before_hairpin_split;
7403 : : }
7404 [ # # ]: 0 : if (hairpin_flow > 0) {
7405 [ # # ]: 0 : if (hairpin_flow > MLX5_MAX_SPLIT_ACTIONS) {
7406 : 0 : rte_errno = EINVAL;
7407 : 0 : goto error_before_hairpin_split;
7408 : : }
7409 : 0 : flow_hairpin_split(dev, actions, actions_rx.actions,
7410 : : actions_hairpin_tx.actions, items_tx.items,
7411 : : idx);
7412 : : p_actions_rx = actions_rx.actions;
7413 : : }
7414 : 0 : flow_split_info.flow_idx = idx;
7415 [ # # ]: 0 : flow->drv_type = flow_get_drv_type(dev, attr);
7416 : : MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
7417 : : flow->drv_type < MLX5_FLOW_TYPE_MAX);
7418 : : memset(rss_desc, 0, offsetof(struct mlx5_flow_rss_desc, queue));
7419 : : /* RSS Action only works on NIC RX domain */
7420 [ # # ]: 0 : if (attr->ingress)
7421 : 0 : rss = flow_get_rss_action(dev, p_actions_rx);
7422 [ # # ]: 0 : if (rss) {
7423 : : MLX5_ASSERT(rss->queue_num <= RTE_ETH_RSS_RETA_SIZE_512);
7424 : 0 : rss_desc->symmetric_hash_function = MLX5_RSS_IS_SYMM(rss->func);
7425 : : /*
7426 : : * The following information is required by
7427 : : * mlx5_flow_hashfields_adjust() in advance.
7428 : : */
7429 : 0 : rss_desc->level = rss->level;
7430 : : /* RSS type 0 indicates default RSS type (RTE_ETH_RSS_IP). */
7431 [ # # ]: 0 : rss_desc->types = !rss->types ? RTE_ETH_RSS_IP : rss->types;
7432 : : }
7433 : 0 : flow->dev_handles = 0;
7434 [ # # # # ]: 0 : if (rss && rss->types) {
7435 : : unsigned int graph_root;
7436 : :
7437 : 0 : graph_root = find_graph_root(rss->level);
7438 : 0 : ret = mlx5_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
7439 : : items, rss->types,
7440 : : mlx5_support_expansion, graph_root);
7441 : : MLX5_ASSERT(ret > 0 &&
7442 : : (unsigned int)ret < sizeof(expand_buffer.buffer));
7443 [ # # ]: 0 : if (rte_log_can_log(mlx5_logtype, RTE_LOG_DEBUG)) {
7444 [ # # ]: 0 : for (i = 0; i < buf->entries; ++i)
7445 : 0 : mlx5_dbg__print_pattern(buf->entry[i].pattern);
7446 : : }
7447 : : } else {
7448 : 0 : ret = mlx5_flow_expand_sqn((struct mlx5_flow_expand_sqn *)buf,
7449 : : sizeof(expand_buffer.buffer),
7450 : : items, sq_specs);
7451 [ # # ]: 0 : if (ret) {
7452 : 0 : rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_HANDLE,
7453 : : NULL, "not enough memory for rte_flow");
7454 : 0 : goto error;
7455 : : }
7456 [ # # ]: 0 : if (buf->entries == 0) {
7457 : 0 : buf->entries = 1;
7458 : 0 : buf->entry[0].pattern = (void *)(uintptr_t)items;
7459 : : }
7460 : : }
7461 : 0 : rss_desc->shared_rss = flow_get_shared_rss_action(dev, indir_actions,
7462 : : indir_actions_n);
7463 [ # # ]: 0 : for (i = 0; i < buf->entries; ++i) {
7464 : : /* Initialize flow split data. */
7465 : 0 : flow_split_info.prefix_layers = 0;
7466 : 0 : flow_split_info.prefix_mark = 0;
7467 : 0 : flow_split_info.skip_scale = 0;
7468 : : /*
7469 : : * The splitter may create multiple dev_flows,
7470 : : * depending on configuration. In the simplest
7471 : : * case it just creates unmodified original flow.
7472 : : */
7473 : : ret = flow_create_split_outer(dev, flow, attr,
7474 : 0 : buf->entry[i].pattern,
7475 : : p_actions_rx, &flow_split_info,
7476 : : error);
7477 [ # # ]: 0 : if (ret < 0)
7478 : 0 : goto error;
7479 [ # # ]: 0 : if (is_flow_tunnel_steer_rule(wks->flows[0].tof_type)) {
7480 : 0 : ret = flow_tunnel_add_default_miss(dev, flow, attr,
7481 : : p_actions_rx,
7482 : : idx,
7483 : : wks->flows[0].tunnel,
7484 : : &default_miss_ctx,
7485 : : error);
7486 [ # # ]: 0 : if (ret < 0) {
7487 : 0 : mlx5_free(default_miss_ctx.queue);
7488 : 0 : goto error;
7489 : : }
7490 : : }
7491 : : }
7492 : : /* Create the tx flow. */
7493 [ # # ]: 0 : if (hairpin_flow) {
7494 : 0 : attr_tx.group = MLX5_HAIRPIN_TX_TABLE;
7495 : 0 : attr_tx.ingress = 0;
7496 : 0 : attr_tx.egress = 1;
7497 : 0 : dev_flow = flow_drv_prepare(dev, flow, &attr_tx, items_tx.items,
7498 : : actions_hairpin_tx.actions,
7499 : : idx, error);
7500 [ # # ]: 0 : if (!dev_flow)
7501 : 0 : goto error;
7502 : 0 : dev_flow->flow = flow;
7503 : 0 : dev_flow->external = 0;
7504 : 0 : SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
7505 : : dev_flow->handle, next);
7506 : : ret = flow_drv_translate(dev, dev_flow, &attr_tx,
7507 : : items_tx.items,
7508 : : actions_hairpin_tx.actions, error);
7509 [ # # ]: 0 : if (ret < 0)
7510 : 0 : goto error;
7511 : : }
7512 : : /*
7513 : : * Update the metadata register copy table. If extensive
7514 : : * metadata feature is enabled and registers are supported
7515 : : * we might create the extra rte_flow for each unique
7516 : : * MARK/FLAG action ID.
7517 : : *
7518 : : * The table is updated for ingress and transfer flows only, because
7519 : : * the egress Flows belong to the different device and
7520 : : * copy table should be updated in peer NIC Rx domain.
7521 : : */
7522 [ # # # # ]: 0 : if ((attr->ingress || attr->transfer) &&
7523 [ # # ]: 0 : (external || attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
7524 : 0 : ret = flow_mreg_update_copy_table(dev, flow, actions, error);
7525 [ # # ]: 0 : if (ret)
7526 : 0 : goto error;
7527 : : }
7528 : : /*
7529 : : * If the flow is external (from application) OR device is started,
7530 : : * OR mreg discover, then apply immediately.
7531 : : */
7532 [ # # # # ]: 0 : if (external || dev->data->dev_started ||
7533 [ # # ]: 0 : (attr->group == MLX5_FLOW_MREG_CP_TABLE_GROUP &&
7534 [ # # ]: 0 : attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)) {
7535 : : ret = flow_drv_apply(dev, flow, error);
7536 [ # # ]: 0 : if (ret < 0)
7537 : 0 : goto error;
7538 : : }
7539 : 0 : flow->type = type;
7540 : 0 : flow_rxq_flags_set(dev, flow);
7541 : 0 : rte_free(translated_actions);
7542 : : tunnel = flow_tunnel_from_rule(wks->flows);
7543 [ # # ]: 0 : if (tunnel) {
7544 : 0 : flow->tunnel = 1;
7545 : 0 : flow->tunnel_id = tunnel->tunnel_id;
7546 : 0 : rte_atomic_fetch_add_explicit(&tunnel->refctn, 1, rte_memory_order_relaxed);
7547 : 0 : mlx5_free(default_miss_ctx.queue);
7548 : : }
7549 : 0 : mlx5_flow_pop_thread_workspace();
7550 : 0 : return idx;
7551 : 0 : error:
7552 : : MLX5_ASSERT(flow);
7553 : 0 : ret = rte_errno; /* Save rte_errno before cleanup. */
7554 : 0 : flow_mreg_del_copy_action(dev, flow);
7555 : : flow_drv_destroy(dev, flow);
7556 : :
7557 [ # # ]: 0 : if (rss_desc->shared_rss) {
7558 : : shared_rss_action = (struct mlx5_shared_action_rss *)
7559 : 0 : mlx5_ipool_get
7560 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
7561 : : rss_desc->shared_rss);
7562 [ # # ]: 0 : if (shared_rss_action)
7563 : 0 : rte_atomic_fetch_sub_explicit(&(shared_rss_action)->refcnt, 1,
7564 : : rte_memory_order_relaxed);
7565 : : }
7566 : 0 : mlx5_ipool_free(priv->flows[type], idx);
7567 : 0 : rte_errno = ret; /* Restore rte_errno. */
7568 : : ret = rte_errno;
7569 : : rte_errno = ret;
7570 : 0 : error_before_hairpin_split:
7571 : 0 : mlx5_flow_pop_thread_workspace();
7572 : 0 : rte_free(translated_actions);
7573 : 0 : return 0;
7574 : : }
7575 : :
7576 : : /**
7577 : : * Create a dedicated flow rule on e-switch table 0 (root table), to direct all
7578 : : * incoming packets to table 1.
7579 : : *
7580 : : * Other flow rules, requested for group n, will be created in
7581 : : * e-switch table n+1.
7582 : : * Jump action to e-switch group n will be created to group n+1.
7583 : : *
7584 : : * Used when working in switchdev mode, to utilise advantages of table 1
7585 : : * and above.
7586 : : *
7587 : : * @param dev
7588 : : * Pointer to Ethernet device.
7589 : : *
7590 : : * @return
7591 : : * Pointer to flow on success, NULL otherwise and rte_errno is set.
7592 : : */
7593 : : struct rte_flow *
7594 : 0 : mlx5_flow_create_esw_table_zero_flow(struct rte_eth_dev *dev)
7595 : : {
7596 : 0 : const struct rte_flow_attr attr = {
7597 : : .group = 0,
7598 : : .priority = 0,
7599 : : .ingress = 0,
7600 : : .egress = 0,
7601 : : .transfer = 1,
7602 : : };
7603 : 0 : const struct rte_flow_item pattern = {
7604 : : .type = RTE_FLOW_ITEM_TYPE_END,
7605 : : };
7606 : 0 : struct rte_flow_action_jump jump = {
7607 : : .group = 1,
7608 : : };
7609 : 0 : const struct rte_flow_action actions[] = {
7610 : : {
7611 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
7612 : : .conf = &jump,
7613 : : },
7614 : : {
7615 : : .type = RTE_FLOW_ACTION_TYPE_END,
7616 : : },
7617 : : };
7618 : : struct rte_flow_error error;
7619 : :
7620 : 0 : return (void *)(uintptr_t)mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
7621 : : &attr, &pattern,
7622 : : actions, false, &error);
7623 : : }
7624 : :
7625 : : /**
7626 : : * Create a dedicated flow rule on e-switch table 1, matches ESW manager
7627 : : * and sq number, directs all packets to peer vport.
7628 : : *
7629 : : * @param dev
7630 : : * Pointer to Ethernet device.
7631 : : * @param sq_num
7632 : : * SQ number.
7633 : : *
7634 : : * @return
7635 : : * Flow ID on success, 0 otherwise and rte_errno is set.
7636 : : */
7637 : : uint32_t
7638 : 0 : mlx5_flow_create_devx_sq_miss_flow(struct rte_eth_dev *dev, uint32_t sq_num)
7639 : : {
7640 : 0 : struct rte_flow_attr attr = {
7641 : : .group = 0,
7642 : : .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
7643 : : .ingress = 0,
7644 : : .egress = 0,
7645 : : .transfer = 1,
7646 : : };
7647 : 0 : struct rte_flow_item_port_id port_spec = {
7648 : : .id = MLX5_PORT_ESW_MGR,
7649 : : };
7650 : 0 : struct mlx5_rte_flow_item_sq sq_spec = {
7651 : : .queue = sq_num,
7652 : : };
7653 : 0 : struct rte_flow_item pattern[] = {
7654 : : {
7655 : : .type = RTE_FLOW_ITEM_TYPE_PORT_ID,
7656 : : .spec = &port_spec,
7657 : : },
7658 : : {
7659 : : .type = (enum rte_flow_item_type)
7660 : : MLX5_RTE_FLOW_ITEM_TYPE_SQ,
7661 : : .spec = &sq_spec,
7662 : : },
7663 : : {
7664 : : .type = RTE_FLOW_ITEM_TYPE_END,
7665 : : },
7666 : : };
7667 : 0 : struct rte_flow_action_jump jump = {
7668 : : .group = 1,
7669 : : };
7670 : 0 : struct rte_flow_action_port_id port = {
7671 : 0 : .id = dev->data->port_id,
7672 : : };
7673 : 0 : struct rte_flow_action actions[] = {
7674 : : {
7675 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
7676 : : .conf = &jump,
7677 : : },
7678 : : {
7679 : : .type = RTE_FLOW_ACTION_TYPE_END,
7680 : : },
7681 : : };
7682 : : struct rte_flow_error error;
7683 : :
7684 : : /*
7685 : : * Creates group 0, highest priority jump flow.
7686 : : * Matches txq to bypass kernel packets.
7687 : : */
7688 [ # # ]: 0 : if (mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_CTL, &attr, pattern, actions,
7689 : : false, &error) == 0)
7690 : : return 0;
7691 : : /* Create group 1, lowest priority redirect flow for txq. */
7692 : 0 : attr.group = 1;
7693 : 0 : actions[0].conf = &port;
7694 : 0 : actions[0].type = RTE_FLOW_ACTION_TYPE_PORT_ID;
7695 : 0 : return mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_CTL, &attr, pattern,
7696 : : actions, false, &error);
7697 : : }
7698 : :
7699 : : /**
7700 : : * Validate a flow supported by the NIC.
7701 : : *
7702 : : * @see rte_flow_validate()
7703 : : * @see rte_flow_ops
7704 : : */
7705 : : int
7706 : 0 : mlx5_flow_validate(struct rte_eth_dev *dev,
7707 : : const struct rte_flow_attr *attr,
7708 : : const struct rte_flow_item items[],
7709 : : const struct rte_flow_action original_actions[],
7710 : : struct rte_flow_error *error)
7711 : : {
7712 : : int hairpin_flow;
7713 : : struct mlx5_translated_action_handle
7714 : : indir_actions[MLX5_MAX_INDIRECT_ACTIONS];
7715 : 0 : int indir_actions_n = MLX5_MAX_INDIRECT_ACTIONS;
7716 : : const struct rte_flow_action *actions;
7717 : 0 : struct rte_flow_action *translated_actions = NULL;
7718 : 0 : int ret = flow_action_handles_translate(dev, original_actions,
7719 : : indir_actions,
7720 : : &indir_actions_n,
7721 : : &translated_actions, error);
7722 : :
7723 [ # # ]: 0 : if (ret)
7724 : : return ret;
7725 [ # # ]: 0 : actions = translated_actions ? translated_actions : original_actions;
7726 : 0 : hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
7727 : 0 : ret = flow_drv_validate(dev, attr, items, actions,
7728 : : true, hairpin_flow, error);
7729 : 0 : rte_free(translated_actions);
7730 : 0 : return ret;
7731 : : }
7732 : :
7733 : : static int
7734 : 0 : mlx5_flow_cache_flow_info(struct rte_eth_dev *dev,
7735 : : const struct rte_flow_attr *attr,
7736 : : const uint32_t orig_prio,
7737 : : const struct rte_flow_item *items,
7738 : : const struct rte_flow_action *actions,
7739 : : uint32_t flow_idx)
7740 : : {
7741 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7742 : : struct rte_pmd_mlx5_flow_engine_mode_info *mode_info = &priv->mode_info;
7743 : : struct mlx5_dv_flow_info *flow_info, *tmp_info;
7744 : : struct rte_flow_error error;
7745 : : int len, ret;
7746 : :
7747 : 0 : flow_info = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*flow_info), 0, SOCKET_ID_ANY);
7748 [ # # ]: 0 : if (!flow_info) {
7749 : 0 : DRV_LOG(ERR, "No enough memory for flow_info caching.");
7750 : 0 : return -1;
7751 : : }
7752 : 0 : flow_info->orig_prio = orig_prio;
7753 : 0 : flow_info->attr = *attr;
7754 : : /* Standby mode rule awlays saves it in low priority entry. */
7755 : 0 : flow_info->flow_idx_low_prio = flow_idx;
7756 : :
7757 : : /* Store matching items. */
7758 : 0 : ret = rte_flow_conv(RTE_FLOW_CONV_OP_PATTERN, NULL, 0, items, &error);
7759 [ # # ]: 0 : if (ret <= 0) {
7760 : 0 : DRV_LOG(ERR, "Can't get items length.");
7761 : 0 : goto end;
7762 : : }
7763 : 0 : len = RTE_ALIGN(ret, 16);
7764 : 0 : flow_info->items = mlx5_malloc(MLX5_MEM_ZERO, len, 0, SOCKET_ID_ANY);
7765 [ # # ]: 0 : if (!flow_info->items) {
7766 : 0 : DRV_LOG(ERR, "No enough memory for items caching.");
7767 : 0 : goto end;
7768 : : }
7769 : 0 : ret = rte_flow_conv(RTE_FLOW_CONV_OP_PATTERN, flow_info->items, ret, items, &error);
7770 [ # # ]: 0 : if (ret <= 0) {
7771 : 0 : DRV_LOG(ERR, "Can't duplicate items.");
7772 : 0 : goto end;
7773 : : }
7774 : :
7775 : : /* Store flow actions. */
7776 : 0 : ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTIONS, NULL, 0, actions, &error);
7777 [ # # ]: 0 : if (ret <= 0) {
7778 : 0 : DRV_LOG(ERR, "Can't get actions length.");
7779 : 0 : goto end;
7780 : : }
7781 : 0 : len = RTE_ALIGN(ret, 16);
7782 : 0 : flow_info->actions = mlx5_malloc(MLX5_MEM_ZERO, len, 0, SOCKET_ID_ANY);
7783 [ # # ]: 0 : if (!flow_info->actions) {
7784 : 0 : DRV_LOG(ERR, "No enough memory for actions caching.");
7785 : 0 : goto end;
7786 : : }
7787 : 0 : ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTIONS, flow_info->actions, ret, actions, &error);
7788 [ # # ]: 0 : if (ret <= 0) {
7789 : 0 : DRV_LOG(ERR, "Can't duplicate actions.");
7790 : 0 : goto end;
7791 : : }
7792 : :
7793 : : /* Insert to the list end. */
7794 [ # # ]: 0 : if (LIST_EMPTY(&mode_info->hot_upgrade)) {
7795 : 0 : LIST_INSERT_HEAD(&mode_info->hot_upgrade, flow_info, next);
7796 : : } else {
7797 : : tmp_info = LIST_FIRST(&mode_info->hot_upgrade);
7798 [ # # ]: 0 : while (LIST_NEXT(tmp_info, next))
7799 : : tmp_info = LIST_NEXT(tmp_info, next);
7800 : 0 : LIST_INSERT_AFTER(tmp_info, flow_info, next);
7801 : : }
7802 : : return 0;
7803 : 0 : end:
7804 [ # # ]: 0 : if (flow_info->items)
7805 : 0 : mlx5_free(flow_info->items);
7806 [ # # ]: 0 : if (flow_info->actions)
7807 : 0 : mlx5_free(flow_info->actions);
7808 : 0 : mlx5_free(flow_info);
7809 : 0 : return -1;
7810 : : }
7811 : :
7812 : : static int
7813 : 0 : mlx5_flow_cache_flow_toggle(struct rte_eth_dev *dev, bool orig_prio)
7814 : : {
7815 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7816 : : struct rte_pmd_mlx5_flow_engine_mode_info *mode_info = &priv->mode_info;
7817 : : struct mlx5_dv_flow_info *flow_info;
7818 : : struct rte_flow_attr attr;
7819 : : struct rte_flow_error error;
7820 : : struct rte_flow *high, *low;
7821 : :
7822 : 0 : flow_info = LIST_FIRST(&mode_info->hot_upgrade);
7823 [ # # ]: 0 : while (flow_info) {
7824 : : /* DUP flow may have the same priority. */
7825 [ # # ]: 0 : if (flow_info->orig_prio != flow_info->attr.priority) {
7826 : 0 : attr = flow_info->attr;
7827 [ # # ]: 0 : if (orig_prio)
7828 : 0 : attr.priority = flow_info->orig_prio;
7829 : 0 : flow_info->flow_idx_high_prio = mlx5_flow_list_create(dev,
7830 : : MLX5_FLOW_TYPE_GEN, &attr,
7831 : 0 : flow_info->items, flow_info->actions,
7832 : : true, &error);
7833 [ # # ]: 0 : if (!flow_info->flow_idx_high_prio) {
7834 : 0 : DRV_LOG(ERR, "Priority toggle failed internally.");
7835 : 0 : goto err;
7836 : : }
7837 : : }
7838 : 0 : flow_info = LIST_NEXT(flow_info, next);
7839 : : }
7840 : : /* Delete the low priority rules and swap the flow handle. */
7841 : 0 : flow_info = LIST_FIRST(&mode_info->hot_upgrade);
7842 [ # # ]: 0 : while (flow_info) {
7843 : : MLX5_ASSERT(flow_info->flow_idx_low_prio);
7844 [ # # ]: 0 : if (flow_info->orig_prio != flow_info->attr.priority) {
7845 : 0 : high = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
7846 : : flow_info->flow_idx_high_prio);
7847 : 0 : low = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
7848 : : flow_info->flow_idx_low_prio);
7849 [ # # ]: 0 : if (high && low) {
7850 : 0 : RTE_SWAP(*low, *high);
7851 : 0 : mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN,
7852 : 0 : flow_info->flow_idx_low_prio);
7853 : 0 : flow_info->flow_idx_high_prio = 0;
7854 : : }
7855 : : }
7856 : 0 : flow_info = LIST_NEXT(flow_info, next);
7857 : : }
7858 : : return 0;
7859 : : err:
7860 : : /* Destroy preceding successful high priority rules. */
7861 : 0 : flow_info = LIST_FIRST(&mode_info->hot_upgrade);
7862 [ # # ]: 0 : while (flow_info) {
7863 [ # # ]: 0 : if (flow_info->orig_prio != flow_info->attr.priority) {
7864 [ # # ]: 0 : if (flow_info->flow_idx_high_prio)
7865 : 0 : mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN,
7866 : : flow_info->flow_idx_high_prio);
7867 : : else
7868 : : break;
7869 : 0 : flow_info->flow_idx_high_prio = 0;
7870 : : }
7871 : 0 : flow_info = LIST_NEXT(flow_info, next);
7872 : : }
7873 : : return -1;
7874 : : }
7875 : :
7876 : : /**
7877 : : * Set the mode of the flow engine of a process to active or standby during live migration.
7878 : : *
7879 : : * @param[in] mode
7880 : : * MLX5 flow engine mode, @see `enum rte_pmd_mlx5_flow_engine_mode`.
7881 : : * @param[in] flags
7882 : : * Flow engine mode specific flags.
7883 : : *
7884 : : * @return
7885 : : * Negative value on error, positive on success.
7886 : : */
7887 : : int
7888 : 0 : rte_pmd_mlx5_flow_engine_set_mode(enum rte_pmd_mlx5_flow_engine_mode mode, uint32_t flags)
7889 : : {
7890 : : struct mlx5_priv *priv;
7891 : : struct rte_pmd_mlx5_flow_engine_mode_info *mode_info;
7892 : : struct mlx5_dv_flow_info *flow_info, *tmp_info;
7893 : : uint16_t port, port_id;
7894 : : uint16_t toggle_num = 0;
7895 : : struct rte_eth_dev *dev;
7896 : : enum rte_pmd_mlx5_flow_engine_mode orig_mode;
7897 : : uint32_t orig_flags;
7898 : : bool need_toggle = false;
7899 : :
7900 : : /* Check if flags combinations are supported. */
7901 [ # # ]: 0 : if (flags && flags != RTE_PMD_MLX5_FLOW_ENGINE_FLAG_STANDBY_DUP_INGRESS) {
7902 : 0 : DRV_LOG(ERR, "Doesn't support such flags %u", flags);
7903 : 0 : return -1;
7904 : : }
7905 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port, NULL) {
7906 : 0 : dev = &rte_eth_devices[port];
7907 : 0 : priv = dev->data->dev_private;
7908 : : mode_info = &priv->mode_info;
7909 : : /* No mode change. Assume all devices hold the same mode. */
7910 [ # # ]: 0 : if (mode_info->mode == mode) {
7911 : 0 : DRV_LOG(INFO, "Process flow engine has been in mode %u", mode);
7912 [ # # # # ]: 0 : if (mode_info->mode_flag != flags && !LIST_EMPTY(&mode_info->hot_upgrade)) {
7913 : 0 : DRV_LOG(ERR, "Port %u has rule cache with different flag %u\n",
7914 : : port, mode_info->mode_flag);
7915 : 0 : orig_mode = mode_info->mode;
7916 : 0 : orig_flags = mode_info->mode_flag;
7917 : 0 : goto err;
7918 : : }
7919 : 0 : mode_info->mode_flag = flags;
7920 : 0 : toggle_num++;
7921 : 0 : continue;
7922 : : }
7923 : : /* Active -> standby. */
7924 [ # # ]: 0 : if (mode == RTE_PMD_MLX5_FLOW_ENGINE_MODE_STANDBY) {
7925 [ # # ]: 0 : if (!LIST_EMPTY(&mode_info->hot_upgrade)) {
7926 : 0 : DRV_LOG(ERR, "Cached rule existed");
7927 : 0 : orig_mode = mode_info->mode;
7928 : 0 : orig_flags = mode_info->mode_flag;
7929 : 0 : goto err;
7930 : : }
7931 : 0 : mode_info->mode_flag = flags;
7932 : 0 : mode_info->mode = mode;
7933 : 0 : toggle_num++;
7934 : : /* Standby -> active. */
7935 [ # # ]: 0 : } else if (mode == RTE_PMD_MLX5_FLOW_ENGINE_MODE_ACTIVE) {
7936 [ # # ]: 0 : if (LIST_EMPTY(&mode_info->hot_upgrade)) {
7937 : 0 : DRV_LOG(INFO, "No cached rule existed");
7938 : : } else {
7939 [ # # ]: 0 : if (mlx5_flow_cache_flow_toggle(dev, true)) {
7940 : 0 : orig_mode = mode_info->mode;
7941 : 0 : orig_flags = mode_info->mode_flag;
7942 : : need_toggle = true;
7943 : 0 : goto err;
7944 : : }
7945 : : }
7946 : 0 : toggle_num++;
7947 : : }
7948 : : }
7949 [ # # ]: 0 : if (mode == RTE_PMD_MLX5_FLOW_ENGINE_MODE_ACTIVE) {
7950 : : /* Clear cache flow rules. */
7951 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port, NULL) {
7952 : 0 : priv = rte_eth_devices[port].data->dev_private;
7953 : : mode_info = &priv->mode_info;
7954 : 0 : flow_info = LIST_FIRST(&mode_info->hot_upgrade);
7955 [ # # ]: 0 : while (flow_info) {
7956 : 0 : tmp_info = LIST_NEXT(flow_info, next);
7957 [ # # ]: 0 : LIST_REMOVE(flow_info, next);
7958 : 0 : mlx5_free(flow_info->actions);
7959 : 0 : mlx5_free(flow_info->items);
7960 : 0 : mlx5_free(flow_info);
7961 : : flow_info = tmp_info;
7962 : : }
7963 : : MLX5_ASSERT(LIST_EMPTY(&mode_info->hot_upgrade));
7964 : : }
7965 : : }
7966 : 0 : return toggle_num;
7967 : 0 : err:
7968 : : /* Rollback all preceding successful ports. */
7969 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port_id, NULL) {
7970 [ # # ]: 0 : if (port_id == port)
7971 : : break;
7972 : 0 : priv = rte_eth_devices[port_id].data->dev_private;
7973 : : mode_info = &priv->mode_info;
7974 [ # # # # : 0 : if (need_toggle && !LIST_EMPTY(&mode_info->hot_upgrade) &&
# # ]
7975 : 0 : mlx5_flow_cache_flow_toggle(dev, false))
7976 : : return -EPERM;
7977 : 0 : mode_info->mode = orig_mode;
7978 : 0 : mode_info->mode_flag = orig_flags;
7979 : : }
7980 : : return -EINVAL;
7981 : : }
7982 : : /**
7983 : : * Create a flow.
7984 : : *
7985 : : * @see rte_flow_create()
7986 : : * @see rte_flow_ops
7987 : : */
7988 : : struct rte_flow *
7989 : 0 : mlx5_flow_create(struct rte_eth_dev *dev,
7990 : : const struct rte_flow_attr *attr,
7991 : : const struct rte_flow_item items[],
7992 : : const struct rte_flow_action actions[],
7993 : : struct rte_flow_error *error)
7994 : : {
7995 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7996 : : struct rte_flow_attr *new_attr = (void *)(uintptr_t)attr;
7997 : 0 : uint32_t prio = attr->priority;
7998 : : uintptr_t flow_idx;
7999 : :
8000 : : /*
8001 : : * If the device is not started yet, it is not allowed to created a
8002 : : * flow from application. PMD default flows and traffic control flows
8003 : : * are not affected.
8004 : : */
8005 [ # # ]: 0 : if (unlikely(!dev->data->dev_started)) {
8006 : 0 : DRV_LOG(DEBUG, "port %u is not started when "
8007 : : "inserting a flow", dev->data->port_id);
8008 : 0 : rte_flow_error_set(error, ENODEV,
8009 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8010 : : NULL,
8011 : : "port not started");
8012 : 0 : return NULL;
8013 : : }
8014 [ # # ]: 0 : if (unlikely(mlx5_need_cache_flow(priv, attr))) {
8015 [ # # ]: 0 : if (attr->transfer ||
8016 [ # # # # ]: 0 : (attr->ingress && !(priv->mode_info.mode_flag &
8017 : : RTE_PMD_MLX5_FLOW_ENGINE_FLAG_STANDBY_DUP_INGRESS)))
8018 : 0 : new_attr->priority += 1;
8019 : : }
8020 : 0 : flow_idx = mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_GEN, attr, items, actions,
8021 : : true, error);
8022 [ # # ]: 0 : if (!flow_idx)
8023 : : return NULL;
8024 [ # # ]: 0 : if (unlikely(mlx5_need_cache_flow(priv, attr))) {
8025 [ # # ]: 0 : if (mlx5_flow_cache_flow_info(dev, attr, prio, items, actions, flow_idx)) {
8026 : 0 : mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN, flow_idx);
8027 : : flow_idx = 0;
8028 : : }
8029 : : }
8030 : 0 : return (void *)(uintptr_t)flow_idx;
8031 : : }
8032 : :
8033 : : uintptr_t
8034 : 0 : mlx5_flow_list_create(struct rte_eth_dev *dev, enum mlx5_flow_type type,
8035 : : const struct rte_flow_attr *attr,
8036 : : const struct rte_flow_item items[],
8037 : : const struct rte_flow_action actions[],
8038 : : bool external, struct rte_flow_error *error)
8039 : : {
8040 : : const struct mlx5_flow_driver_ops *fops;
8041 : 0 : enum mlx5_flow_drv_type drv_type = flow_get_drv_type(dev, attr);
8042 : :
8043 : 0 : fops = flow_get_drv_ops(drv_type);
8044 : 0 : return fops->list_create(dev, type, attr, items, actions, external,
8045 : : error);
8046 : : }
8047 : :
8048 : : /**
8049 : : * Destroy a flow in a list.
8050 : : *
8051 : : * @param dev
8052 : : * Pointer to Ethernet device.
8053 : : * @param[in] flow_idx
8054 : : * Index of flow to destroy.
8055 : : */
8056 : : void
8057 : 0 : flow_legacy_list_destroy(struct rte_eth_dev *dev, enum mlx5_flow_type type,
8058 : : uintptr_t flow_idx)
8059 : : {
8060 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8061 : 0 : struct rte_flow *flow = mlx5_ipool_get(priv->flows[type], (uint32_t)flow_idx);
8062 : :
8063 [ # # ]: 0 : if (!flow)
8064 : : return;
8065 : : MLX5_ASSERT((type >= MLX5_FLOW_TYPE_CTL) && (type < MLX5_FLOW_TYPE_MAXI));
8066 : : MLX5_ASSERT(flow->type == type);
8067 : : /*
8068 : : * Update RX queue flags only if port is started, otherwise it is
8069 : : * already clean.
8070 : : */
8071 [ # # ]: 0 : if (dev->data->dev_started)
8072 : 0 : flow_rxq_flags_trim(dev, flow);
8073 : : flow_drv_destroy(dev, flow);
8074 [ # # ]: 0 : if (flow->tunnel) {
8075 : : struct mlx5_flow_tunnel *tunnel;
8076 : :
8077 : 0 : tunnel = mlx5_find_tunnel_id(dev, flow->tunnel_id);
8078 : 0 : RTE_VERIFY(tunnel);
8079 [ # # ]: 0 : if (!(rte_atomic_fetch_sub_explicit(&tunnel->refctn, 1,
8080 : : rte_memory_order_relaxed) - 1))
8081 : 0 : mlx5_flow_tunnel_free(dev, tunnel);
8082 : : }
8083 : 0 : flow_mreg_del_copy_action(dev, flow);
8084 : 0 : mlx5_ipool_free(priv->flows[type], flow_idx);
8085 : : }
8086 : :
8087 : : void
8088 [ # # ]: 0 : mlx5_flow_list_destroy(struct rte_eth_dev *dev, enum mlx5_flow_type type,
8089 : : uintptr_t flow_idx)
8090 : : {
8091 : : const struct mlx5_flow_driver_ops *fops;
8092 : : struct rte_flow_attr attr = { .transfer = 0 };
8093 : : enum mlx5_flow_drv_type drv_type = flow_get_drv_type(dev, &attr);
8094 : :
8095 : 0 : fops = flow_get_drv_ops(drv_type);
8096 : 0 : fops->list_destroy(dev, type, flow_idx);
8097 : 0 : }
8098 : :
8099 : : /**
8100 : : * Destroy all flows.
8101 : : *
8102 : : * @param dev
8103 : : * Pointer to Ethernet device.
8104 : : * @param type
8105 : : * Flow type to be flushed.
8106 : : * @param active
8107 : : * If flushing is called actively.
8108 : : */
8109 : : void
8110 : 0 : mlx5_flow_list_flush(struct rte_eth_dev *dev, enum mlx5_flow_type type,
8111 : : bool active)
8112 : : {
8113 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8114 : 0 : uint32_t num_flushed = 0, fidx = 1;
8115 : : struct rte_flow *flow;
8116 : : struct rte_pmd_mlx5_flow_engine_mode_info *mode_info = &priv->mode_info;
8117 : : struct mlx5_dv_flow_info *flow_info;
8118 : :
8119 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8120 [ # # # # ]: 0 : if (priv->sh->config.dv_flow_en == 2 &&
8121 : : type == MLX5_FLOW_TYPE_GEN) {
8122 : 0 : priv->hws_rule_flushing = true;
8123 : 0 : flow_hw_q_flow_flush(dev, NULL);
8124 : 0 : priv->hws_rule_flushing = false;
8125 : : }
8126 : : #endif
8127 [ # # ]: 0 : MLX5_IPOOL_FOREACH(priv->flows[type], fidx, flow) {
8128 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2) {
8129 : 0 : mlx5_flow_list_destroy(dev, type, (uintptr_t)flow);
8130 : : } else {
8131 : 0 : mlx5_flow_list_destroy(dev, type, fidx);
8132 : : }
8133 [ # # # # ]: 0 : if (unlikely(mlx5_need_cache_flow(priv, NULL) && type == MLX5_FLOW_TYPE_GEN)) {
8134 : 0 : flow_info = LIST_FIRST(&mode_info->hot_upgrade);
8135 [ # # ]: 0 : while (flow_info) {
8136 : : /* Romove the cache flow info. */
8137 [ # # ]: 0 : if (flow_info->flow_idx_low_prio == (uint32_t)(uintptr_t)fidx) {
8138 : : MLX5_ASSERT(!flow_info->flow_idx_high_prio);
8139 [ # # ]: 0 : LIST_REMOVE(flow_info, next);
8140 : 0 : mlx5_free(flow_info->items);
8141 : 0 : mlx5_free(flow_info->actions);
8142 : 0 : mlx5_free(flow_info);
8143 : 0 : break;
8144 : : }
8145 : 0 : flow_info = LIST_NEXT(flow_info, next);
8146 : : }
8147 : : }
8148 : 0 : num_flushed++;
8149 : : }
8150 [ # # ]: 0 : if (active) {
8151 : 0 : DRV_LOG(INFO, "port %u: %u flows flushed before stopping",
8152 : : dev->data->port_id, num_flushed);
8153 : : }
8154 : 0 : }
8155 : :
8156 : : /**
8157 : : * Stop all default actions for flows.
8158 : : *
8159 : : * @param dev
8160 : : * Pointer to Ethernet device.
8161 : : */
8162 : : void
8163 : 0 : mlx5_flow_stop_default(struct rte_eth_dev *dev)
8164 : : {
8165 : : #ifdef HAVE_MLX5_HWS_SUPPORT
8166 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8167 : :
8168 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2) {
8169 : 0 : mlx5_flow_nta_del_default_copy_action(dev);
8170 [ # # ]: 0 : if (!rte_atomic_load_explicit(&priv->hws_mark_refcnt,
8171 : : rte_memory_order_relaxed))
8172 : 0 : flow_hw_rxq_flag_set(dev, false);
8173 : 0 : return;
8174 : : }
8175 : : #endif
8176 : 0 : flow_mreg_del_default_copy_action(dev);
8177 : 0 : flow_rxq_flags_clear(dev);
8178 : : }
8179 : :
8180 : : /**
8181 : : * Set rxq flag.
8182 : : *
8183 : : * @param[in] dev
8184 : : * Pointer to the rte_eth_dev structure.
8185 : : * @param[in] enable
8186 : : * Flag to enable or not.
8187 : : */
8188 : : void
8189 : 0 : flow_hw_rxq_flag_set(struct rte_eth_dev *dev, bool enable)
8190 : : {
8191 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8192 : : unsigned int i;
8193 : :
8194 [ # # # # : 0 : if ((!priv->mark_enabled && !enable) ||
# # ]
8195 [ # # ]: 0 : (priv->mark_enabled && enable))
8196 : : return;
8197 [ # # ]: 0 : for (i = 0; i < priv->rxqs_n; ++i) {
8198 : 0 : struct mlx5_rxq_ctrl *rxq_ctrl = mlx5_rxq_ctrl_get(dev, i);
8199 : :
8200 : : /* With RXQ start/stop feature, RXQ might be stopped. */
8201 [ # # ]: 0 : if (!rxq_ctrl)
8202 : 0 : continue;
8203 : 0 : rxq_ctrl->rxq.mark = enable;
8204 : : }
8205 : 0 : priv->mark_enabled = enable;
8206 : : }
8207 : :
8208 : : /**
8209 : : * Start all default actions for flows.
8210 : : *
8211 : : * @param dev
8212 : : * Pointer to Ethernet device.
8213 : : * @return
8214 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
8215 : : */
8216 : : int
8217 : 0 : mlx5_flow_start_default(struct rte_eth_dev *dev)
8218 : : {
8219 : : struct rte_flow_error error;
8220 : : #ifdef HAVE_MLX5_HWS_SUPPORT
8221 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8222 : :
8223 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
8224 : 0 : return mlx5_flow_nta_add_default_copy_action(dev, &error);
8225 : : #endif
8226 : : /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
8227 : 0 : return flow_mreg_add_default_copy_action(dev, &error);
8228 : : }
8229 : :
8230 : : /**
8231 : : * Release key of thread specific flow workspace data.
8232 : : */
8233 : : void
8234 : 0 : flow_release_workspace(void *data)
8235 : : {
8236 : : struct mlx5_flow_workspace *wks = data;
8237 : : struct mlx5_flow_workspace *next;
8238 : :
8239 [ # # ]: 0 : while (wks) {
8240 : 0 : next = wks->next;
8241 : 0 : free(wks);
8242 : : wks = next;
8243 : : }
8244 : 0 : }
8245 : :
8246 : : /**
8247 : : * Get thread specific current flow workspace.
8248 : : *
8249 : : * @return pointer to thread specific flow workspace data, NULL on error.
8250 : : */
8251 : : struct mlx5_flow_workspace*
8252 : 0 : mlx5_flow_get_thread_workspace(void)
8253 : : {
8254 : : struct mlx5_flow_workspace *data;
8255 : :
8256 : 0 : data = mlx5_flow_os_get_specific_workspace();
8257 : : MLX5_ASSERT(data && data->inuse);
8258 [ # # # # ]: 0 : if (!data || !data->inuse)
8259 : 0 : DRV_LOG(ERR, "flow workspace not initialized.");
8260 : 0 : return data;
8261 : : }
8262 : :
8263 : : /**
8264 : : * Allocate and init new flow workspace.
8265 : : *
8266 : : * @return pointer to flow workspace data, NULL on error.
8267 : : */
8268 : : static struct mlx5_flow_workspace*
8269 : 0 : flow_alloc_thread_workspace(void)
8270 : : {
8271 : : size_t data_size = RTE_ALIGN(sizeof(struct mlx5_flow_workspace), sizeof(long));
8272 : : size_t rss_queue_array_size = sizeof(uint16_t) * RTE_ETH_RSS_RETA_SIZE_512;
8273 : : size_t alloc_size = data_size + rss_queue_array_size;
8274 : : #ifdef HAVE_MLX5_HWS_SUPPORT
8275 : : /* Dummy table size for the non-template API. */
8276 : : alloc_size += sizeof(struct rte_flow_template_table);
8277 : : #endif
8278 : 0 : struct mlx5_flow_workspace *data = calloc(1, alloc_size);
8279 : :
8280 [ # # ]: 0 : if (!data) {
8281 : 0 : DRV_LOG(ERR, "Failed to allocate flow workspace memory.");
8282 : 0 : return NULL;
8283 : : }
8284 : 0 : data->rss_desc.queue = RTE_PTR_ADD(data, data_size);
8285 : : #ifdef HAVE_MLX5_HWS_SUPPORT
8286 : 0 : data->table = RTE_PTR_ADD(data->rss_desc.queue, rss_queue_array_size);
8287 : : #endif
8288 : 0 : return data;
8289 : : }
8290 : :
8291 : : /**
8292 : : * Get new thread specific flow workspace.
8293 : : *
8294 : : * If current workspace inuse, create new one and set as current.
8295 : : *
8296 : : * @return pointer to thread specific flow workspace data, NULL on error.
8297 : : */
8298 : : struct mlx5_flow_workspace*
8299 : 0 : mlx5_flow_push_thread_workspace(void)
8300 : : {
8301 : : struct mlx5_flow_workspace *curr;
8302 : : struct mlx5_flow_workspace *data;
8303 : :
8304 : 0 : curr = mlx5_flow_os_get_specific_workspace();
8305 [ # # ]: 0 : if (!curr) {
8306 : 0 : data = flow_alloc_thread_workspace();
8307 [ # # ]: 0 : if (!data)
8308 : : return NULL;
8309 : 0 : mlx5_flow_os_workspace_gc_add(data);
8310 [ # # ]: 0 : } else if (!curr->inuse) {
8311 : : data = curr;
8312 [ # # ]: 0 : } else if (curr->next) {
8313 : : data = curr->next;
8314 : : } else {
8315 : 0 : data = flow_alloc_thread_workspace();
8316 [ # # ]: 0 : if (!data)
8317 : : return NULL;
8318 : 0 : curr->next = data;
8319 : 0 : data->prev = curr;
8320 : : }
8321 : 0 : data->inuse = 1;
8322 : 0 : data->flow_idx = 0;
8323 : : /* Set as current workspace */
8324 [ # # ]: 0 : if (mlx5_flow_os_set_specific_workspace(data))
8325 : 0 : DRV_LOG(ERR, "Failed to set flow workspace to thread.");
8326 : : return data;
8327 : : }
8328 : :
8329 : : /**
8330 : : * Close current thread specific flow workspace.
8331 : : *
8332 : : * If previous workspace available, set it as current.
8333 : : *
8334 : : * @return pointer to thread specific flow workspace data, NULL on error.
8335 : : */
8336 : : void
8337 : 0 : mlx5_flow_pop_thread_workspace(void)
8338 : : {
8339 : 0 : struct mlx5_flow_workspace *data = mlx5_flow_get_thread_workspace();
8340 : :
8341 [ # # ]: 0 : if (!data)
8342 : : return;
8343 [ # # ]: 0 : if (!data->inuse) {
8344 : 0 : DRV_LOG(ERR, "Failed to close unused flow workspace.");
8345 : 0 : return;
8346 : : }
8347 : 0 : data->inuse = 0;
8348 [ # # ]: 0 : if (!data->prev)
8349 : : return;
8350 [ # # ]: 0 : if (mlx5_flow_os_set_specific_workspace(data->prev))
8351 : 0 : DRV_LOG(ERR, "Failed to set flow workspace to thread.");
8352 : : }
8353 : :
8354 : : /**
8355 : : * Verify the flow list is empty
8356 : : *
8357 : : * @param dev
8358 : : * Pointer to Ethernet device.
8359 : : *
8360 : : * @return the number of flows not released.
8361 : : */
8362 : : int
8363 : 0 : mlx5_flow_verify(struct rte_eth_dev *dev __rte_unused)
8364 : : {
8365 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8366 : : struct rte_flow *flow;
8367 : : uint32_t idx = 0;
8368 : : int ret = 0, i;
8369 : :
8370 [ # # ]: 0 : for (i = 0; i < MLX5_FLOW_TYPE_MAXI; i++) {
8371 [ # # ]: 0 : MLX5_IPOOL_FOREACH(priv->flows[i], idx, flow) {
8372 : 0 : DRV_LOG(DEBUG, "port %u flow %p still referenced",
8373 : : dev->data->port_id, (void *)flow);
8374 : 0 : ret++;
8375 : : }
8376 : : }
8377 : 0 : return ret;
8378 : : }
8379 : :
8380 : : /**
8381 : : * Enable default hairpin egress flow.
8382 : : *
8383 : : * @param dev
8384 : : * Pointer to Ethernet device.
8385 : : * @param sq_num
8386 : : * The SQ hw number.
8387 : : *
8388 : : * @return
8389 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
8390 : : */
8391 : : int
8392 : 0 : mlx5_ctrl_flow_source_queue(struct rte_eth_dev *dev,
8393 : : uint32_t sq_num)
8394 : : {
8395 : 0 : const struct rte_flow_attr attr = {
8396 : : .egress = 1,
8397 : : .priority = 0,
8398 : : };
8399 : 0 : struct mlx5_rte_flow_item_sq queue_spec = {
8400 : : .queue = sq_num,
8401 : : };
8402 : 0 : struct mlx5_rte_flow_item_sq queue_mask = {
8403 : : .queue = UINT32_MAX,
8404 : : };
8405 : 0 : struct rte_flow_item items[] = {
8406 : : {
8407 : : .type = (enum rte_flow_item_type)
8408 : : MLX5_RTE_FLOW_ITEM_TYPE_SQ,
8409 : : .spec = &queue_spec,
8410 : : .last = NULL,
8411 : : .mask = &queue_mask,
8412 : : },
8413 : : {
8414 : : .type = RTE_FLOW_ITEM_TYPE_END,
8415 : : },
8416 : : };
8417 : 0 : struct rte_flow_action_jump jump = {
8418 : : .group = MLX5_HAIRPIN_TX_TABLE,
8419 : : };
8420 : : struct rte_flow_action actions[2];
8421 : : uint32_t flow_idx;
8422 : : struct rte_flow_error error;
8423 : :
8424 : 0 : actions[0].type = RTE_FLOW_ACTION_TYPE_JUMP;
8425 : 0 : actions[0].conf = &jump;
8426 : 0 : actions[1].type = RTE_FLOW_ACTION_TYPE_END;
8427 : 0 : flow_idx = mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
8428 : : &attr, items, actions, false, &error);
8429 [ # # ]: 0 : if (!flow_idx) {
8430 [ # # ]: 0 : DRV_LOG(DEBUG,
8431 : : "Failed to create ctrl flow: rte_errno(%d),"
8432 : : " type(%d), message(%s)",
8433 : : rte_errno, error.type,
8434 : : error.message ? error.message : " (no stated reason)");
8435 : 0 : return -rte_errno;
8436 : : }
8437 : : return 0;
8438 : : }
8439 : :
8440 : : /**
8441 : : * Enable a control flow configured from the control plane.
8442 : : *
8443 : : * @param dev
8444 : : * Pointer to Ethernet device.
8445 : : * @param eth_spec
8446 : : * An Ethernet flow spec to apply.
8447 : : * @param eth_mask
8448 : : * An Ethernet flow mask to apply.
8449 : : * @param vlan_spec
8450 : : * A VLAN flow spec to apply.
8451 : : * @param vlan_mask
8452 : : * A VLAN flow mask to apply.
8453 : : *
8454 : : * @return
8455 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
8456 : : */
8457 : : int
8458 : 0 : mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
8459 : : struct rte_flow_item_eth *eth_spec,
8460 : : struct rte_flow_item_eth *eth_mask,
8461 : : struct rte_flow_item_vlan *vlan_spec,
8462 : : struct rte_flow_item_vlan *vlan_mask)
8463 : : {
8464 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8465 : 0 : const struct rte_flow_attr attr = {
8466 : : .ingress = 1,
8467 : : .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
8468 : : };
8469 : 0 : struct rte_flow_item items[] = {
8470 : : {
8471 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
8472 : : .spec = eth_spec,
8473 : : .last = NULL,
8474 : : .mask = eth_mask,
8475 : : },
8476 : : {
8477 [ # # ]: 0 : .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
8478 : : RTE_FLOW_ITEM_TYPE_END,
8479 : : .spec = vlan_spec,
8480 : : .last = NULL,
8481 : : .mask = vlan_mask,
8482 : : },
8483 : : {
8484 : : .type = RTE_FLOW_ITEM_TYPE_END,
8485 : : },
8486 : : };
8487 : 0 : uint16_t *queue = alloca(sizeof(uint16_t) * priv->reta_idx_n);
8488 : 0 : struct rte_flow_action_rss action_rss = {
8489 : : .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
8490 : : .level = 0,
8491 : 0 : .types = priv->rss_conf.rss_hf,
8492 : 0 : .key_len = priv->rss_conf.rss_key_len,
8493 : : .queue_num = priv->reta_idx_n,
8494 : 0 : .key = priv->rss_conf.rss_key,
8495 : : .queue = queue,
8496 : : };
8497 : 0 : struct rte_flow_action actions[] = {
8498 : : {
8499 : : .type = RTE_FLOW_ACTION_TYPE_RSS,
8500 : : .conf = &action_rss,
8501 : : },
8502 : : {
8503 : : .type = RTE_FLOW_ACTION_TYPE_END,
8504 : : },
8505 : : };
8506 : : uintptr_t flow_idx;
8507 : : struct rte_flow_error error;
8508 : : struct mlx5_ctrl_flow_entry *entry;
8509 : : unsigned int i;
8510 : :
8511 [ # # # # ]: 0 : if (!priv->reta_idx_n || !priv->rxqs_n) {
8512 : : return 0;
8513 : : }
8514 [ # # ]: 0 : if (!(dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG))
8515 : 0 : action_rss.types = 0;
8516 [ # # ]: 0 : for (i = 0; i != priv->reta_idx_n; ++i)
8517 : 0 : queue[i] = (*priv->reta_idx)[i];
8518 : :
8519 : 0 : entry = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*entry), alignof(typeof(*entry)), SOCKET_ID_ANY);
8520 [ # # ]: 0 : if (entry == NULL) {
8521 : 0 : rte_errno = ENOMEM;
8522 : 0 : goto err;
8523 : : }
8524 : :
8525 : 0 : entry->owner_dev = dev;
8526 [ # # ]: 0 : if (vlan_spec == NULL) {
8527 : 0 : entry->info.type = MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC;
8528 : : } else {
8529 : 0 : entry->info.type = MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC_VLAN;
8530 [ # # ]: 0 : entry->info.uc.vlan = rte_be_to_cpu_16(vlan_spec->hdr.vlan_tci);
8531 : : }
8532 : 0 : entry->info.uc.dmac = eth_spec->hdr.dst_addr;
8533 : :
8534 : 0 : flow_idx = mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
8535 : : &attr, items, actions, false, &error);
8536 [ # # ]: 0 : if (!flow_idx) {
8537 : 0 : mlx5_free(entry);
8538 : 0 : goto err;
8539 : : }
8540 : :
8541 : 0 : entry->flow = (struct rte_flow *)flow_idx;
8542 [ # # ]: 0 : LIST_INSERT_HEAD(&priv->hw_ctrl_flows, entry, next);
8543 : :
8544 : 0 : return 0;
8545 : :
8546 : 0 : err:
8547 : 0 : return -rte_errno;
8548 : : }
8549 : :
8550 : : /**
8551 : : * Enable a flow control configured from the control plane.
8552 : : *
8553 : : * @param dev
8554 : : * Pointer to Ethernet device.
8555 : : * @param eth_spec
8556 : : * An Ethernet flow spec to apply.
8557 : : * @param eth_mask
8558 : : * An Ethernet flow mask to apply.
8559 : : *
8560 : : * @return
8561 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
8562 : : */
8563 : : int
8564 : 0 : mlx5_ctrl_flow(struct rte_eth_dev *dev,
8565 : : struct rte_flow_item_eth *eth_spec,
8566 : : struct rte_flow_item_eth *eth_mask)
8567 : : {
8568 : 0 : return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
8569 : : }
8570 : :
8571 : : int
8572 : 0 : mlx5_legacy_dmac_flow_create(struct rte_eth_dev *dev, const struct rte_ether_addr *addr)
8573 : : {
8574 : 0 : struct rte_flow_item_eth unicast = {
8575 : : .hdr.dst_addr = *addr,
8576 : : };
8577 : 0 : struct rte_flow_item_eth unicast_mask = {
8578 : : .hdr.dst_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
8579 : : };
8580 : :
8581 : 0 : return mlx5_ctrl_flow(dev, &unicast, &unicast_mask);
8582 : : }
8583 : :
8584 : : int
8585 : 0 : mlx5_legacy_dmac_vlan_flow_create(struct rte_eth_dev *dev,
8586 : : const struct rte_ether_addr *addr,
8587 : : const uint16_t vid)
8588 : : {
8589 : 0 : struct rte_flow_item_eth unicast_spec = {
8590 : : .hdr.dst_addr = *addr,
8591 : : };
8592 : 0 : struct rte_flow_item_eth unicast_mask = {
8593 : : .hdr.dst_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
8594 : : };
8595 : 0 : struct rte_flow_item_vlan vlan_spec = {
8596 [ # # ]: 0 : .hdr.vlan_tci = rte_cpu_to_be_16(vid),
8597 : : };
8598 : 0 : struct rte_flow_item_vlan vlan_mask = rte_flow_item_vlan_mask;
8599 : :
8600 : 0 : return mlx5_ctrl_flow_vlan(dev, &unicast_spec, &unicast_mask, &vlan_spec, &vlan_mask);
8601 : : }
8602 : :
8603 : : void
8604 : 0 : mlx5_legacy_ctrl_flow_destroy(struct rte_eth_dev *dev, struct mlx5_ctrl_flow_entry *entry)
8605 : : {
8606 : : uintptr_t flow_idx;
8607 : :
8608 : 0 : flow_idx = (uintptr_t)entry->flow;
8609 : 0 : mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_CTL, flow_idx);
8610 [ # # ]: 0 : LIST_REMOVE(entry, next);
8611 : 0 : mlx5_free(entry);
8612 : 0 : }
8613 : :
8614 : : int
8615 : 0 : mlx5_legacy_dmac_flow_destroy(struct rte_eth_dev *dev, const struct rte_ether_addr *addr)
8616 : : {
8617 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8618 : : struct mlx5_ctrl_flow_entry *entry;
8619 : :
8620 [ # # ]: 0 : LIST_FOREACH(entry, &priv->hw_ctrl_flows, next) {
8621 [ # # # # ]: 0 : if (entry->info.type != MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC ||
8622 : : !rte_is_same_ether_addr(addr, &entry->info.uc.dmac))
8623 : : continue;
8624 : :
8625 : 0 : mlx5_legacy_ctrl_flow_destroy(dev, entry);
8626 : 0 : return 0;
8627 : : }
8628 : : return 0;
8629 : : }
8630 : :
8631 : : int
8632 : 0 : mlx5_legacy_dmac_vlan_flow_destroy(struct rte_eth_dev *dev,
8633 : : const struct rte_ether_addr *addr,
8634 : : const uint16_t vid)
8635 : : {
8636 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8637 : : struct mlx5_ctrl_flow_entry *entry;
8638 : :
8639 [ # # ]: 0 : LIST_FOREACH(entry, &priv->hw_ctrl_flows, next) {
8640 [ # # # # ]: 0 : if (entry->info.type != MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC_VLAN ||
8641 : 0 : !rte_is_same_ether_addr(addr, &entry->info.uc.dmac) ||
8642 [ # # ]: 0 : vid != entry->info.uc.vlan)
8643 : : continue;
8644 : :
8645 : 0 : mlx5_legacy_ctrl_flow_destroy(dev, entry);
8646 : 0 : return 0;
8647 : : }
8648 : : return 0;
8649 : : }
8650 : :
8651 : : /**
8652 : : * Create default miss flow rule matching lacp traffic
8653 : : *
8654 : : * @param dev
8655 : : * Pointer to Ethernet device.
8656 : : * @param eth_spec
8657 : : * An Ethernet flow spec to apply.
8658 : : *
8659 : : * @return
8660 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
8661 : : */
8662 : : int
8663 : 0 : mlx5_flow_lacp_miss(struct rte_eth_dev *dev)
8664 : : {
8665 : : /*
8666 : : * The LACP matching is done by only using ether type since using
8667 : : * a multicast dst mac causes kernel to give low priority to this flow.
8668 : : */
8669 : : static const struct rte_flow_item_eth lacp_spec = {
8670 : : .hdr.ether_type = RTE_BE16(0x8809),
8671 : : };
8672 : : static const struct rte_flow_item_eth lacp_mask = {
8673 : : .hdr.ether_type = 0xffff,
8674 : : };
8675 : 0 : const struct rte_flow_attr attr = {
8676 : : .ingress = 1,
8677 : : };
8678 : 0 : struct rte_flow_item items[] = {
8679 : : {
8680 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
8681 : : .spec = &lacp_spec,
8682 : : .mask = &lacp_mask,
8683 : : },
8684 : : {
8685 : : .type = RTE_FLOW_ITEM_TYPE_END,
8686 : : },
8687 : : };
8688 : 0 : struct rte_flow_action actions[] = {
8689 : : {
8690 : : .type = (enum rte_flow_action_type)
8691 : : MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
8692 : : },
8693 : : {
8694 : : .type = RTE_FLOW_ACTION_TYPE_END,
8695 : : },
8696 : : };
8697 : : struct rte_flow_error error;
8698 : 0 : uint32_t flow_idx = mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
8699 : : &attr, items, actions,
8700 : : false, &error);
8701 : :
8702 [ # # ]: 0 : if (!flow_idx)
8703 : 0 : return -rte_errno;
8704 : : return 0;
8705 : : }
8706 : :
8707 : : /**
8708 : : * Destroy a flow.
8709 : : *
8710 : : * @see rte_flow_destroy()
8711 : : * @see rte_flow_ops
8712 : : */
8713 : : int
8714 : 0 : mlx5_flow_destroy(struct rte_eth_dev *dev,
8715 : : struct rte_flow *flow,
8716 : : struct rte_flow_error *error __rte_unused)
8717 : : {
8718 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8719 : : struct rte_pmd_mlx5_flow_engine_mode_info *mode_info = &priv->mode_info;
8720 : : struct mlx5_dv_flow_info *flow_info;
8721 : :
8722 : 0 : mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN,
8723 : : (uintptr_t)(void *)flow);
8724 [ # # ]: 0 : if (unlikely(mlx5_need_cache_flow(priv, NULL))) {
8725 : 0 : flow_info = LIST_FIRST(&mode_info->hot_upgrade);
8726 [ # # ]: 0 : while (flow_info) {
8727 : : /* Romove the cache flow info. */
8728 [ # # ]: 0 : if (flow_info->flow_idx_low_prio == (uint32_t)(uintptr_t)flow) {
8729 : : MLX5_ASSERT(!flow_info->flow_idx_high_prio);
8730 [ # # ]: 0 : LIST_REMOVE(flow_info, next);
8731 : 0 : mlx5_free(flow_info->items);
8732 : 0 : mlx5_free(flow_info->actions);
8733 : 0 : mlx5_free(flow_info);
8734 : 0 : break;
8735 : : }
8736 : 0 : flow_info = LIST_NEXT(flow_info, next);
8737 : : }
8738 : : }
8739 : 0 : return 0;
8740 : : }
8741 : :
8742 : : /**
8743 : : * Destroy all flows.
8744 : : *
8745 : : * @see rte_flow_flush()
8746 : : * @see rte_flow_ops
8747 : : */
8748 : : int
8749 : 0 : mlx5_flow_flush(struct rte_eth_dev *dev,
8750 : : struct rte_flow_error *error __rte_unused)
8751 : : {
8752 : 0 : mlx5_flow_list_flush(dev, MLX5_FLOW_TYPE_GEN, false);
8753 : 0 : return 0;
8754 : : }
8755 : :
8756 : : /**
8757 : : * Isolated mode.
8758 : : *
8759 : : * @see rte_flow_isolate()
8760 : : * @see rte_flow_ops
8761 : : */
8762 : : int
8763 : 0 : mlx5_flow_isolate(struct rte_eth_dev *dev,
8764 : : int enable,
8765 : : struct rte_flow_error *error)
8766 : : {
8767 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8768 : :
8769 [ # # ]: 0 : if (dev->data->dev_started) {
8770 : 0 : rte_flow_error_set(error, EBUSY,
8771 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8772 : : NULL,
8773 : : "port must be stopped first");
8774 : 0 : return -rte_errno;
8775 : : }
8776 [ # # # # ]: 0 : if (!enable && !priv->sh->config.repr_matching)
8777 : 0 : return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
8778 : : "isolated mode cannot be disabled when "
8779 : : "representor matching is disabled");
8780 : 0 : priv->isolated = !!enable;
8781 [ # # ]: 0 : if (enable)
8782 : 0 : dev->dev_ops = &mlx5_dev_ops_isolate;
8783 : : else
8784 : 0 : dev->dev_ops = &mlx5_dev_ops;
8785 : :
8786 : 0 : dev->rx_descriptor_status = mlx5_rx_descriptor_status;
8787 : 0 : dev->tx_descriptor_status = mlx5_tx_descriptor_status;
8788 : :
8789 : 0 : return 0;
8790 : : }
8791 : :
8792 : : /**
8793 : : * Query a flow.
8794 : : *
8795 : : * @see rte_flow_query()
8796 : : * @see rte_flow_ops
8797 : : */
8798 : : static int
8799 : 0 : flow_drv_query(struct rte_eth_dev *dev,
8800 : : struct rte_flow *eflow,
8801 : : const struct rte_flow_action *actions,
8802 : : void *data,
8803 : : struct rte_flow_error *error)
8804 : : {
8805 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8806 : : const struct mlx5_flow_driver_ops *fops;
8807 : : struct rte_flow *flow = NULL;
8808 : : enum mlx5_flow_drv_type ftype = MLX5_FLOW_TYPE_MIN;
8809 : :
8810 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2) {
8811 : : #ifdef HAVE_MLX5_HWS_SUPPORT
8812 : : flow = eflow;
8813 : : ftype = MLX5_FLOW_TYPE_HW;
8814 : : #endif
8815 : : } else {
8816 : 0 : flow = (struct rte_flow *)mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
8817 : : (uintptr_t)(void *)eflow);
8818 : : }
8819 [ # # ]: 0 : if (!flow) {
8820 : 0 : return rte_flow_error_set(error, ENOENT,
8821 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8822 : : NULL,
8823 : : "invalid flow handle");
8824 : : }
8825 [ # # ]: 0 : if (ftype == MLX5_FLOW_TYPE_MIN)
8826 : 0 : ftype = flow->drv_type;
8827 : : MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX);
8828 : 0 : fops = flow_get_drv_ops(ftype);
8829 : :
8830 : 0 : return fops->query(dev, flow, actions, data, error);
8831 : : }
8832 : :
8833 : : /**
8834 : : * Query a flow.
8835 : : *
8836 : : * @see rte_flow_query()
8837 : : * @see rte_flow_ops
8838 : : */
8839 : : int
8840 : 0 : mlx5_flow_query(struct rte_eth_dev *dev,
8841 : : struct rte_flow *flow,
8842 : : const struct rte_flow_action *actions,
8843 : : void *data,
8844 : : struct rte_flow_error *error)
8845 : : {
8846 : : int ret;
8847 : :
8848 : 0 : ret = flow_drv_query(dev, flow, actions, data,
8849 : : error);
8850 : : if (ret < 0)
8851 : : return ret;
8852 : : return 0;
8853 : : }
8854 : :
8855 : : /**
8856 : : * Get rte_flow callbacks.
8857 : : *
8858 : : * @param dev
8859 : : * Pointer to Ethernet device structure.
8860 : : * @param ops
8861 : : * Pointer to operation-specific structure.
8862 : : *
8863 : : * @return 0
8864 : : */
8865 : : int
8866 : 0 : mlx5_flow_ops_get(struct rte_eth_dev *dev __rte_unused,
8867 : : const struct rte_flow_ops **ops)
8868 : : {
8869 : 0 : *ops = &mlx5_flow_ops;
8870 : 0 : return 0;
8871 : : }
8872 : :
8873 : : /**
8874 : : * Validate meter policy actions.
8875 : : * Dispatcher for action type specific validation.
8876 : : *
8877 : : * @param[in] dev
8878 : : * Pointer to the Ethernet device structure.
8879 : : * @param[in] action
8880 : : * The meter policy action object to validate.
8881 : : * @param[in] attr
8882 : : * Attributes of flow to determine steering domain.
8883 : : * @param[out] is_rss
8884 : : * Is RSS or not.
8885 : : * @param[out] domain_bitmap
8886 : : * Domain bitmap.
8887 : : * @param[out] is_def_policy
8888 : : * Is default policy or not.
8889 : : * @param[out] error
8890 : : * Perform verbose error reporting if not NULL. Initialized in case of
8891 : : * error only.
8892 : : *
8893 : : * @return
8894 : : * 0 on success, otherwise negative errno value.
8895 : : */
8896 : : int
8897 : 0 : mlx5_flow_validate_mtr_acts(struct rte_eth_dev *dev,
8898 : : const struct rte_flow_action *actions[RTE_COLORS],
8899 : : struct rte_flow_attr *attr,
8900 : : bool *is_rss,
8901 : : uint8_t *domain_bitmap,
8902 : : uint8_t *policy_mode,
8903 : : struct rte_mtr_error *error)
8904 : : {
8905 : : const struct mlx5_flow_driver_ops *fops;
8906 : :
8907 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
8908 : 0 : return fops->validate_mtr_acts(dev, actions, attr, is_rss,
8909 : : domain_bitmap, policy_mode, error);
8910 : : }
8911 : :
8912 : : /**
8913 : : * Destroy the meter table set.
8914 : : *
8915 : : * @param[in] dev
8916 : : * Pointer to Ethernet device.
8917 : : * @param[in] mtr_policy
8918 : : * Meter policy struct.
8919 : : */
8920 : : void
8921 : 0 : mlx5_flow_destroy_mtr_acts(struct rte_eth_dev *dev,
8922 : : struct mlx5_flow_meter_policy *mtr_policy)
8923 : : {
8924 : : const struct mlx5_flow_driver_ops *fops;
8925 : :
8926 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
8927 : 0 : fops->destroy_mtr_acts(dev, mtr_policy);
8928 : 0 : }
8929 : :
8930 : : /**
8931 : : * Create policy action, lock free,
8932 : : * (mutex should be acquired by caller).
8933 : : * Dispatcher for action type specific call.
8934 : : *
8935 : : * @param[in] dev
8936 : : * Pointer to the Ethernet device structure.
8937 : : * @param[in] mtr_policy
8938 : : * Meter policy struct.
8939 : : * @param[in] action
8940 : : * Action specification used to create meter actions.
8941 : : * @param[in] attr
8942 : : * Flow rule attributes.
8943 : : * @param[out] error
8944 : : * Perform verbose error reporting if not NULL. Initialized in case of
8945 : : * error only.
8946 : : *
8947 : : * @return
8948 : : * 0 on success, otherwise negative errno value.
8949 : : */
8950 : : int
8951 : 0 : mlx5_flow_create_mtr_acts(struct rte_eth_dev *dev,
8952 : : struct mlx5_flow_meter_policy *mtr_policy,
8953 : : const struct rte_flow_action *actions[RTE_COLORS],
8954 : : struct rte_flow_attr *attr,
8955 : : struct rte_mtr_error *error)
8956 : : {
8957 : : const struct mlx5_flow_driver_ops *fops;
8958 : :
8959 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
8960 : 0 : return fops->create_mtr_acts(dev, mtr_policy, actions, attr, error);
8961 : : }
8962 : :
8963 : : /**
8964 : : * Create policy rules, lock free,
8965 : : * (mutex should be acquired by caller).
8966 : : * Dispatcher for action type specific call.
8967 : : *
8968 : : * @param[in] dev
8969 : : * Pointer to the Ethernet device structure.
8970 : : * @param[in] mtr_policy
8971 : : * Meter policy struct.
8972 : : *
8973 : : * @return
8974 : : * 0 on success, -1 otherwise.
8975 : : */
8976 : : int
8977 : 0 : mlx5_flow_create_policy_rules(struct rte_eth_dev *dev,
8978 : : struct mlx5_flow_meter_policy *mtr_policy)
8979 : : {
8980 : : const struct mlx5_flow_driver_ops *fops;
8981 : :
8982 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
8983 : 0 : return fops->create_policy_rules(dev, mtr_policy);
8984 : : }
8985 : :
8986 : : /**
8987 : : * Destroy policy rules, lock free,
8988 : : * (mutex should be acquired by caller).
8989 : : * Dispatcher for action type specific call.
8990 : : *
8991 : : * @param[in] dev
8992 : : * Pointer to the Ethernet device structure.
8993 : : * @param[in] mtr_policy
8994 : : * Meter policy struct.
8995 : : */
8996 : : void
8997 : 0 : mlx5_flow_destroy_policy_rules(struct rte_eth_dev *dev,
8998 : : struct mlx5_flow_meter_policy *mtr_policy)
8999 : : {
9000 : : const struct mlx5_flow_driver_ops *fops;
9001 : :
9002 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9003 : 0 : fops->destroy_policy_rules(dev, mtr_policy);
9004 : 0 : }
9005 : :
9006 : : /**
9007 : : * Destroy the default policy table set.
9008 : : *
9009 : : * @param[in] dev
9010 : : * Pointer to Ethernet device.
9011 : : */
9012 : : void
9013 : 0 : mlx5_flow_destroy_def_policy(struct rte_eth_dev *dev)
9014 : : {
9015 : : const struct mlx5_flow_driver_ops *fops;
9016 : :
9017 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9018 : 0 : fops->destroy_def_policy(dev);
9019 : 0 : }
9020 : :
9021 : : /**
9022 : : * Destroy the default policy table set.
9023 : : *
9024 : : * @param[in] dev
9025 : : * Pointer to Ethernet device.
9026 : : *
9027 : : * @return
9028 : : * 0 on success, -1 otherwise.
9029 : : */
9030 : : int
9031 : 0 : mlx5_flow_create_def_policy(struct rte_eth_dev *dev)
9032 : : {
9033 : : const struct mlx5_flow_driver_ops *fops;
9034 : :
9035 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9036 : 0 : return fops->create_def_policy(dev);
9037 : : }
9038 : :
9039 : : /**
9040 : : * Create the needed meter and suffix tables.
9041 : : *
9042 : : * @param[in] dev
9043 : : * Pointer to Ethernet device.
9044 : : *
9045 : : * @return
9046 : : * 0 on success, -1 otherwise.
9047 : : */
9048 : : int
9049 : 0 : mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
9050 : : struct mlx5_flow_meter_info *fm,
9051 : : uint32_t mtr_idx,
9052 : : uint8_t domain_bitmap)
9053 : : {
9054 : : const struct mlx5_flow_driver_ops *fops;
9055 : :
9056 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9057 : 0 : return fops->create_mtr_tbls(dev, fm, mtr_idx, domain_bitmap);
9058 : : }
9059 : :
9060 : : /**
9061 : : * Destroy the meter table set.
9062 : : *
9063 : : * @param[in] dev
9064 : : * Pointer to Ethernet device.
9065 : : * @param[in] tbl
9066 : : * Pointer to the meter table set.
9067 : : */
9068 : : void
9069 : 0 : mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
9070 : : struct mlx5_flow_meter_info *fm)
9071 : : {
9072 : : const struct mlx5_flow_driver_ops *fops;
9073 : :
9074 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9075 : 0 : fops->destroy_mtr_tbls(dev, fm);
9076 : 0 : }
9077 : :
9078 : : /**
9079 : : * Destroy the global meter drop table.
9080 : : *
9081 : : * @param[in] dev
9082 : : * Pointer to Ethernet device.
9083 : : */
9084 : : void
9085 : 0 : mlx5_flow_destroy_mtr_drop_tbls(struct rte_eth_dev *dev)
9086 : : {
9087 : : const struct mlx5_flow_driver_ops *fops;
9088 : :
9089 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9090 : 0 : fops->destroy_mtr_drop_tbls(dev);
9091 : 0 : }
9092 : :
9093 : : /**
9094 : : * Destroy the sub policy table with RX queue.
9095 : : *
9096 : : * @param[in] dev
9097 : : * Pointer to Ethernet device.
9098 : : * @param[in] mtr_policy
9099 : : * Pointer to meter policy table.
9100 : : */
9101 : : void
9102 : 0 : mlx5_flow_destroy_sub_policy_with_rxq(struct rte_eth_dev *dev,
9103 : : struct mlx5_flow_meter_policy *mtr_policy)
9104 : : {
9105 : : const struct mlx5_flow_driver_ops *fops;
9106 : :
9107 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9108 : 0 : fops->destroy_sub_policy_with_rxq(dev, mtr_policy);
9109 : 0 : }
9110 : :
9111 : : /**
9112 : : * Allocate the needed aso flow meter id.
9113 : : *
9114 : : * @param[in] dev
9115 : : * Pointer to Ethernet device.
9116 : : *
9117 : : * @return
9118 : : * Index to aso flow meter on success, NULL otherwise.
9119 : : */
9120 : : uint32_t
9121 : 0 : mlx5_flow_mtr_alloc(struct rte_eth_dev *dev)
9122 : : {
9123 : : const struct mlx5_flow_driver_ops *fops;
9124 : :
9125 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9126 : 0 : return fops->create_meter(dev);
9127 : : }
9128 : :
9129 : : /**
9130 : : * Free the aso flow meter id.
9131 : : *
9132 : : * @param[in] dev
9133 : : * Pointer to Ethernet device.
9134 : : * @param[in] mtr_idx
9135 : : * Index to aso flow meter to be free.
9136 : : *
9137 : : * @return
9138 : : * 0 on success.
9139 : : */
9140 : : void
9141 : 0 : mlx5_flow_mtr_free(struct rte_eth_dev *dev, uint32_t mtr_idx)
9142 : : {
9143 : : const struct mlx5_flow_driver_ops *fops;
9144 : :
9145 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9146 : 0 : fops->free_meter(dev, mtr_idx);
9147 : 0 : }
9148 : :
9149 : : /**
9150 : : * Allocate a counter.
9151 : : *
9152 : : * @param[in] dev
9153 : : * Pointer to Ethernet device structure.
9154 : : *
9155 : : * @return
9156 : : * Index to allocated counter on success, 0 otherwise.
9157 : : */
9158 : : uint32_t
9159 [ # # ]: 0 : mlx5_counter_alloc(struct rte_eth_dev *dev)
9160 : : {
9161 : : struct rte_flow_attr attr = { .transfer = 0 };
9162 : :
9163 : 0 : return flow_get_drv_ops(flow_get_drv_type(dev, &attr))->counter_alloc
9164 : : (dev);
9165 : : }
9166 : :
9167 : : /**
9168 : : * Free a counter.
9169 : : *
9170 : : * @param[in] dev
9171 : : * Pointer to Ethernet device structure.
9172 : : * @param[in] cnt
9173 : : * Index to counter to be free.
9174 : : */
9175 : : void
9176 [ # # ]: 0 : mlx5_counter_free(struct rte_eth_dev *dev, uint32_t cnt)
9177 : : {
9178 : : struct rte_flow_attr attr = { .transfer = 0 };
9179 : :
9180 : 0 : flow_get_drv_ops(flow_get_drv_type(dev, &attr))->counter_free(dev, cnt);
9181 : 0 : }
9182 : :
9183 : : /**
9184 : : * Query counter statistics.
9185 : : *
9186 : : * @param[in] dev
9187 : : * Pointer to Ethernet device structure.
9188 : : * @param[in] cnt
9189 : : * Index to counter to query.
9190 : : * @param[in] clear
9191 : : * Set to clear counter statistics.
9192 : : * @param[out] pkts
9193 : : * The counter hits packets number to save.
9194 : : * @param[out] bytes
9195 : : * The counter hits bytes number to save.
9196 : : *
9197 : : * @return
9198 : : * 0 on success, a negative errno value otherwise.
9199 : : */
9200 : : int
9201 [ # # ]: 0 : mlx5_counter_query(struct rte_eth_dev *dev, uint32_t cnt,
9202 : : bool clear, uint64_t *pkts, uint64_t *bytes, void **action)
9203 : : {
9204 : : struct rte_flow_attr attr = { .transfer = 0 };
9205 : :
9206 : 0 : return flow_get_drv_ops(flow_get_drv_type(dev, &attr))->counter_query
9207 : : (dev, cnt, clear, pkts, bytes, action);
9208 : : }
9209 : :
9210 : : /**
9211 : : * Get information about HWS pre-configurable resources.
9212 : : *
9213 : : * @param[in] dev
9214 : : * Pointer to the rte_eth_dev structure.
9215 : : * @param[out] port_info
9216 : : * Pointer to port information.
9217 : : * @param[out] queue_info
9218 : : * Pointer to queue information.
9219 : : * @param[out] error
9220 : : * Pointer to error structure.
9221 : : *
9222 : : * @return
9223 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9224 : : */
9225 : : static int
9226 [ # # ]: 0 : mlx5_flow_info_get(struct rte_eth_dev *dev,
9227 : : struct rte_flow_port_info *port_info,
9228 : : struct rte_flow_queue_info *queue_info,
9229 : : struct rte_flow_error *error)
9230 : : {
9231 : : const struct mlx5_flow_driver_ops *fops;
9232 : : struct rte_flow_attr attr = {0};
9233 : :
9234 : : if (flow_get_drv_type(dev, &attr) != MLX5_FLOW_TYPE_HW)
9235 : 0 : return rte_flow_error_set(error, ENOTSUP,
9236 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9237 : : NULL,
9238 : : "info get with incorrect steering mode");
9239 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9240 : 0 : return fops->info_get(dev, port_info, queue_info, error);
9241 : : }
9242 : :
9243 : : /**
9244 : : * Configure port HWS resources.
9245 : : *
9246 : : * @param[in] dev
9247 : : * Pointer to the rte_eth_dev structure.
9248 : : * @param[in] port_attr
9249 : : * Port configuration attributes.
9250 : : * @param[in] nb_queue
9251 : : * Number of queue.
9252 : : * @param[in] queue_attr
9253 : : * Array that holds attributes for each flow queue.
9254 : : * @param[out] error
9255 : : * Pointer to error structure.
9256 : : *
9257 : : * @return
9258 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9259 : : */
9260 : : static int
9261 [ # # ]: 0 : mlx5_flow_port_configure(struct rte_eth_dev *dev,
9262 : : const struct rte_flow_port_attr *port_attr,
9263 : : uint16_t nb_queue,
9264 : : const struct rte_flow_queue_attr *queue_attr[],
9265 : : struct rte_flow_error *error)
9266 : : {
9267 : : const struct mlx5_flow_driver_ops *fops;
9268 : : struct rte_flow_attr attr = {0};
9269 : :
9270 : : if (flow_get_drv_type(dev, &attr) != MLX5_FLOW_TYPE_HW)
9271 : 0 : return rte_flow_error_set(error, ENOTSUP,
9272 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9273 : : NULL,
9274 : : "port configure with incorrect steering mode");
9275 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9276 : 0 : return fops->configure(dev, port_attr, nb_queue, queue_attr, error);
9277 : : }
9278 : :
9279 : : /**
9280 : : * Validate item template.
9281 : : *
9282 : : * @param[in] dev
9283 : : * Pointer to the rte_eth_dev structure.
9284 : : * @param[in] attr
9285 : : * Pointer to the item template attributes.
9286 : : * @param[in] items
9287 : : * The template item pattern.
9288 : : * @param[out] error
9289 : : * Pointer to error structure.
9290 : : *
9291 : : * @return
9292 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9293 : : */
9294 : : int
9295 : 0 : mlx5_flow_pattern_validate(struct rte_eth_dev *dev,
9296 : : const struct rte_flow_pattern_template_attr *attr,
9297 : : const struct rte_flow_item items[],
9298 : : struct rte_flow_error *error)
9299 : : {
9300 : : const struct mlx5_flow_driver_ops *fops;
9301 : : struct rte_flow_attr fattr = {0};
9302 [ # # ]: 0 : uint64_t item_flags = 0;
9303 : :
9304 : : if (flow_get_drv_type(dev, &fattr) != MLX5_FLOW_TYPE_HW) {
9305 : 0 : rte_flow_error_set(error, ENOTSUP,
9306 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9307 : : "pattern validate with incorrect steering mode");
9308 : 0 : return -ENOTSUP;
9309 : : }
9310 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9311 : 0 : return fops->pattern_validate(dev, attr, items, &item_flags, error);
9312 : : }
9313 : :
9314 : : /**
9315 : : * Create flow item template.
9316 : : *
9317 : : * @param[in] dev
9318 : : * Pointer to the rte_eth_dev structure.
9319 : : * @param[in] attr
9320 : : * Pointer to the item template attributes.
9321 : : * @param[in] items
9322 : : * The template item pattern.
9323 : : * @param[out] error
9324 : : * Pointer to error structure.
9325 : : *
9326 : : * @return
9327 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9328 : : */
9329 : : static struct rte_flow_pattern_template *
9330 [ # # ]: 0 : mlx5_flow_pattern_template_create(struct rte_eth_dev *dev,
9331 : : const struct rte_flow_pattern_template_attr *attr,
9332 : : const struct rte_flow_item items[],
9333 : : struct rte_flow_error *error)
9334 : : {
9335 : : const struct mlx5_flow_driver_ops *fops;
9336 : : struct rte_flow_attr fattr = {0};
9337 : :
9338 : : if (flow_get_drv_type(dev, &fattr) != MLX5_FLOW_TYPE_HW) {
9339 : 0 : rte_flow_error_set(error, ENOTSUP,
9340 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9341 : : NULL,
9342 : : "pattern create with incorrect steering mode");
9343 : 0 : return NULL;
9344 : : }
9345 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9346 : 0 : return fops->pattern_template_create(dev, attr, items, error);
9347 : : }
9348 : :
9349 : : /**
9350 : : * Destroy flow item template.
9351 : : *
9352 : : * @param[in] dev
9353 : : * Pointer to the rte_eth_dev structure.
9354 : : * @param[in] template
9355 : : * Pointer to the item template to be destroyed.
9356 : : * @param[out] error
9357 : : * Pointer to error structure.
9358 : : *
9359 : : * @return
9360 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9361 : : */
9362 : : static int
9363 [ # # ]: 0 : mlx5_flow_pattern_template_destroy(struct rte_eth_dev *dev,
9364 : : struct rte_flow_pattern_template *template,
9365 : : struct rte_flow_error *error)
9366 : : {
9367 : : const struct mlx5_flow_driver_ops *fops;
9368 : : struct rte_flow_attr attr = {0};
9369 : :
9370 : : if (flow_get_drv_type(dev, &attr) != MLX5_FLOW_TYPE_HW)
9371 : 0 : return rte_flow_error_set(error, ENOTSUP,
9372 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9373 : : NULL,
9374 : : "pattern destroy with incorrect steering mode");
9375 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9376 : 0 : return fops->pattern_template_destroy(dev, template, error);
9377 : : }
9378 : :
9379 : : /**
9380 : : * Validate flow actions template.
9381 : : *
9382 : : * @param[in] dev
9383 : : * Pointer to the rte_eth_dev structure.
9384 : : * @param[in] attr
9385 : : * Pointer to the action template attributes.
9386 : : * @param[in] actions
9387 : : * Associated actions (list terminated by the END action).
9388 : : * @param[in] masks
9389 : : * List of actions that marks which of the action's member is constant.
9390 : : * @param[out] error
9391 : : * Pointer to error structure.
9392 : : *
9393 : : * @return
9394 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9395 : : */
9396 : : int
9397 [ # # ]: 0 : mlx5_flow_actions_validate(struct rte_eth_dev *dev,
9398 : : const struct rte_flow_actions_template_attr *attr,
9399 : : const struct rte_flow_action actions[],
9400 : : const struct rte_flow_action masks[],
9401 : : struct rte_flow_error *error)
9402 : : {
9403 : : const struct mlx5_flow_driver_ops *fops;
9404 : : struct rte_flow_attr fattr = {0};
9405 : :
9406 : : if (flow_get_drv_type(dev, &fattr) != MLX5_FLOW_TYPE_HW) {
9407 : 0 : rte_flow_error_set(error, ENOTSUP,
9408 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9409 : : "actions validate with incorrect steering mode");
9410 : 0 : return -ENOTSUP;
9411 : : }
9412 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9413 : 0 : return fops->actions_validate(dev, attr, actions, masks, error);
9414 : : }
9415 : :
9416 : : /**
9417 : : * Create flow item template.
9418 : : *
9419 : : * @param[in] dev
9420 : : * Pointer to the rte_eth_dev structure.
9421 : : * @param[in] attr
9422 : : * Pointer to the action template attributes.
9423 : : * @param[in] actions
9424 : : * Associated actions (list terminated by the END action).
9425 : : * @param[in] masks
9426 : : * List of actions that marks which of the action's member is constant.
9427 : : * @param[out] error
9428 : : * Pointer to error structure.
9429 : : *
9430 : : * @return
9431 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9432 : : */
9433 : : static struct rte_flow_actions_template *
9434 [ # # ]: 0 : mlx5_flow_actions_template_create(struct rte_eth_dev *dev,
9435 : : const struct rte_flow_actions_template_attr *attr,
9436 : : const struct rte_flow_action actions[],
9437 : : const struct rte_flow_action masks[],
9438 : : struct rte_flow_error *error)
9439 : : {
9440 : : const struct mlx5_flow_driver_ops *fops;
9441 : : struct rte_flow_attr fattr = {0};
9442 : :
9443 : : if (flow_get_drv_type(dev, &fattr) != MLX5_FLOW_TYPE_HW) {
9444 : 0 : rte_flow_error_set(error, ENOTSUP,
9445 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9446 : : NULL,
9447 : : "action create with incorrect steering mode");
9448 : 0 : return NULL;
9449 : : }
9450 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9451 : 0 : return fops->actions_template_create(dev, attr, actions, masks, error);
9452 : : }
9453 : :
9454 : : /**
9455 : : * Destroy flow action template.
9456 : : *
9457 : : * @param[in] dev
9458 : : * Pointer to the rte_eth_dev structure.
9459 : : * @param[in] template
9460 : : * Pointer to the action template to be destroyed.
9461 : : * @param[out] error
9462 : : * Pointer to error structure.
9463 : : *
9464 : : * @return
9465 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9466 : : */
9467 : : static int
9468 [ # # ]: 0 : mlx5_flow_actions_template_destroy(struct rte_eth_dev *dev,
9469 : : struct rte_flow_actions_template *template,
9470 : : struct rte_flow_error *error)
9471 : : {
9472 : : const struct mlx5_flow_driver_ops *fops;
9473 : : struct rte_flow_attr attr = {0};
9474 : :
9475 : : if (flow_get_drv_type(dev, &attr) != MLX5_FLOW_TYPE_HW)
9476 : 0 : return rte_flow_error_set(error, ENOTSUP,
9477 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9478 : : NULL,
9479 : : "action destroy with incorrect steering mode");
9480 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9481 : 0 : return fops->actions_template_destroy(dev, template, error);
9482 : : }
9483 : :
9484 : : /**
9485 : : * Create flow table.
9486 : : *
9487 : : * @param[in] dev
9488 : : * Pointer to the rte_eth_dev structure.
9489 : : * @param[in] attr
9490 : : * Pointer to the table attributes.
9491 : : * @param[in] item_templates
9492 : : * Item template array to be binded to the table.
9493 : : * @param[in] nb_item_templates
9494 : : * Number of item template.
9495 : : * @param[in] action_templates
9496 : : * Action template array to be binded to the table.
9497 : : * @param[in] nb_action_templates
9498 : : * Number of action template.
9499 : : * @param[out] error
9500 : : * Pointer to error structure.
9501 : : *
9502 : : * @return
9503 : : * Table on success, NULL otherwise and rte_errno is set.
9504 : : */
9505 : : static struct rte_flow_template_table *
9506 [ # # ]: 0 : mlx5_flow_table_create(struct rte_eth_dev *dev,
9507 : : const struct rte_flow_template_table_attr *attr,
9508 : : struct rte_flow_pattern_template *item_templates[],
9509 : : uint8_t nb_item_templates,
9510 : : struct rte_flow_actions_template *action_templates[],
9511 : : uint8_t nb_action_templates,
9512 : : struct rte_flow_error *error)
9513 : : {
9514 : : const struct mlx5_flow_driver_ops *fops;
9515 : : struct rte_flow_attr fattr = {0};
9516 : :
9517 : : if (flow_get_drv_type(dev, &fattr) != MLX5_FLOW_TYPE_HW) {
9518 : 0 : rte_flow_error_set(error, ENOTSUP,
9519 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9520 : : NULL,
9521 : : "table create with incorrect steering mode");
9522 : 0 : return NULL;
9523 : : }
9524 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9525 : 0 : return fops->template_table_create(dev,
9526 : : attr,
9527 : : item_templates,
9528 : : nb_item_templates,
9529 : : action_templates,
9530 : : nb_action_templates,
9531 : : error);
9532 : : }
9533 : :
9534 : : /**
9535 : : * PMD destroy flow table.
9536 : : *
9537 : : * @param[in] dev
9538 : : * Pointer to the rte_eth_dev structure.
9539 : : * @param[in] table
9540 : : * Pointer to the table to be destroyed.
9541 : : * @param[out] error
9542 : : * Pointer to error structure.
9543 : : *
9544 : : * @return
9545 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9546 : : */
9547 : : static int
9548 [ # # ]: 0 : mlx5_flow_table_destroy(struct rte_eth_dev *dev,
9549 : : struct rte_flow_template_table *table,
9550 : : struct rte_flow_error *error)
9551 : : {
9552 : : const struct mlx5_flow_driver_ops *fops;
9553 : : struct rte_flow_attr attr = {0};
9554 : :
9555 : : if (flow_get_drv_type(dev, &attr) != MLX5_FLOW_TYPE_HW)
9556 : 0 : return rte_flow_error_set(error, ENOTSUP,
9557 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9558 : : NULL,
9559 : : "table destroy with incorrect steering mode");
9560 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9561 : 0 : return fops->template_table_destroy(dev, table, error);
9562 : : }
9563 : :
9564 : : /**
9565 : : * PMD group set miss actions.
9566 : : *
9567 : : * @param[in] dev
9568 : : * Pointer to the rte_eth_dev structure.
9569 : : * @param[in] attr
9570 : : * Pointer to group attributes
9571 : : * @param[in] actions
9572 : : * Array of actions
9573 : : * @param[out] error
9574 : : * Pointer to error structure.
9575 : : *
9576 : : * @return
9577 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9578 : : */
9579 : : static int
9580 [ # # ]: 0 : mlx5_flow_group_set_miss_actions(struct rte_eth_dev *dev,
9581 : : uint32_t group_id,
9582 : : const struct rte_flow_group_attr *attr,
9583 : : const struct rte_flow_action actions[],
9584 : : struct rte_flow_error *error)
9585 : : {
9586 : : const struct mlx5_flow_driver_ops *fops;
9587 : : struct rte_flow_attr fattr = {0};
9588 : :
9589 : : if (flow_get_drv_type(dev, &fattr) != MLX5_FLOW_TYPE_HW)
9590 : 0 : return rte_flow_error_set(error, ENOTSUP,
9591 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9592 : : NULL,
9593 : : "group set miss actions with incorrect steering mode");
9594 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9595 : 0 : return fops->group_set_miss_actions(dev, group_id, attr, actions, error);
9596 : : }
9597 : :
9598 : : /**
9599 : : * Allocate a new memory for the counter values wrapped by all the needed
9600 : : * management.
9601 : : *
9602 : : * @param[in] sh
9603 : : * Pointer to mlx5_dev_ctx_shared object.
9604 : : *
9605 : : * @return
9606 : : * 0 on success, a negative errno value otherwise.
9607 : : */
9608 : : static int
9609 : 0 : mlx5_flow_create_counter_stat_mem_mng(struct mlx5_dev_ctx_shared *sh)
9610 : : {
9611 : : struct mlx5_counter_stats_mem_mng *mem_mng;
9612 : : volatile struct flow_counter_stats *raw_data;
9613 : : int raws_n = MLX5_CNT_MR_ALLOC_BULK + MLX5_MAX_PENDING_QUERIES;
9614 : : int size = (sizeof(struct flow_counter_stats) *
9615 : : MLX5_COUNTERS_PER_POOL +
9616 : : sizeof(struct mlx5_counter_stats_raw)) * raws_n +
9617 : : sizeof(struct mlx5_counter_stats_mem_mng);
9618 : 0 : size_t pgsize = rte_mem_page_size();
9619 : : uint8_t *mem;
9620 : : int ret;
9621 : : int i;
9622 : :
9623 [ # # ]: 0 : if (pgsize == (size_t)-1) {
9624 : 0 : DRV_LOG(ERR, "Failed to get mem page size");
9625 : 0 : rte_errno = ENOMEM;
9626 : 0 : return -ENOMEM;
9627 : : }
9628 : 0 : mem = mlx5_malloc(MLX5_MEM_ZERO, size, pgsize, SOCKET_ID_ANY);
9629 [ # # ]: 0 : if (!mem) {
9630 : 0 : rte_errno = ENOMEM;
9631 : 0 : return -ENOMEM;
9632 : : }
9633 : 0 : mem_mng = (struct mlx5_counter_stats_mem_mng *)(mem + size) - 1;
9634 : : size = sizeof(*raw_data) * MLX5_COUNTERS_PER_POOL * raws_n;
9635 : 0 : ret = mlx5_os_wrapped_mkey_create(sh->cdev->ctx, sh->cdev->pd,
9636 : 0 : sh->cdev->pdn, mem, size,
9637 : : &mem_mng->wm);
9638 [ # # ]: 0 : if (ret) {
9639 : 0 : rte_errno = errno;
9640 : 0 : mlx5_free(mem);
9641 : 0 : return -rte_errno;
9642 : : }
9643 : 0 : mem_mng->raws = (struct mlx5_counter_stats_raw *)(mem + size);
9644 : : raw_data = (volatile struct flow_counter_stats *)mem;
9645 [ # # ]: 0 : for (i = 0; i < raws_n; ++i) {
9646 : 0 : mem_mng->raws[i].mem_mng = mem_mng;
9647 : 0 : mem_mng->raws[i].data = raw_data + i * MLX5_COUNTERS_PER_POOL;
9648 : : }
9649 [ # # ]: 0 : for (i = 0; i < MLX5_MAX_PENDING_QUERIES; ++i)
9650 [ # # ]: 0 : LIST_INSERT_HEAD(&sh->sws_cmng.free_stat_raws,
9651 : : mem_mng->raws + MLX5_CNT_MR_ALLOC_BULK + i,
9652 : : next);
9653 [ # # ]: 0 : LIST_INSERT_HEAD(&sh->sws_cmng.mem_mngs, mem_mng, next);
9654 : 0 : sh->sws_cmng.mem_mng = mem_mng;
9655 : 0 : return 0;
9656 : : }
9657 : :
9658 : : /**
9659 : : * Set the statistic memory to the new counter pool.
9660 : : *
9661 : : * @param[in] sh
9662 : : * Pointer to mlx5_dev_ctx_shared object.
9663 : : * @param[in] pool
9664 : : * Pointer to the pool to set the statistic memory.
9665 : : *
9666 : : * @return
9667 : : * 0 on success, a negative errno value otherwise.
9668 : : */
9669 : : static int
9670 : 0 : mlx5_flow_set_counter_stat_mem(struct mlx5_dev_ctx_shared *sh,
9671 : : struct mlx5_flow_counter_pool *pool)
9672 : : {
9673 : : struct mlx5_flow_counter_mng *cmng = &sh->sws_cmng;
9674 : : /* Resize statistic memory once used out. */
9675 [ # # # # ]: 0 : if (!(pool->index % MLX5_CNT_MR_ALLOC_BULK) &&
9676 : 0 : mlx5_flow_create_counter_stat_mem_mng(sh)) {
9677 : 0 : DRV_LOG(ERR, "Cannot resize counter stat mem.");
9678 : 0 : return -1;
9679 : : }
9680 : 0 : rte_spinlock_lock(&pool->sl);
9681 : 0 : pool->raw = cmng->mem_mng->raws + pool->index % MLX5_CNT_MR_ALLOC_BULK;
9682 : : rte_spinlock_unlock(&pool->sl);
9683 : 0 : pool->raw_hw = NULL;
9684 : 0 : return 0;
9685 : : }
9686 : :
9687 : : #define MLX5_POOL_QUERY_FREQ_US 1000000
9688 : :
9689 : : /**
9690 : : * Set the periodic procedure for triggering asynchronous batch queries for all
9691 : : * the counter pools.
9692 : : *
9693 : : * @param[in] sh
9694 : : * Pointer to mlx5_dev_ctx_shared object.
9695 : : */
9696 : : void
9697 : 0 : mlx5_set_query_alarm(struct mlx5_dev_ctx_shared *sh)
9698 : : {
9699 : : uint32_t pools_n, us;
9700 : :
9701 : 0 : pools_n = rte_atomic_load_explicit(&sh->sws_cmng.n_valid, rte_memory_order_relaxed);
9702 : 0 : us = MLX5_POOL_QUERY_FREQ_US / pools_n;
9703 : 0 : DRV_LOG(DEBUG, "Set alarm for %u pools each %u us", pools_n, us);
9704 [ # # ]: 0 : if (rte_eal_alarm_set(us, mlx5_flow_query_alarm, sh)) {
9705 : 0 : sh->sws_cmng.query_thread_on = 0;
9706 : 0 : DRV_LOG(ERR, "Cannot reinitialize query alarm");
9707 : : } else {
9708 : 0 : sh->sws_cmng.query_thread_on = 1;
9709 : : }
9710 : 0 : }
9711 : :
9712 : : /**
9713 : : * The periodic procedure for triggering asynchronous batch queries for all the
9714 : : * counter pools. This function is probably called by the host thread.
9715 : : *
9716 : : * @param[in] arg
9717 : : * The parameter for the alarm process.
9718 : : */
9719 : : void
9720 : 0 : mlx5_flow_query_alarm(void *arg)
9721 : : {
9722 : : struct mlx5_dev_ctx_shared *sh = arg;
9723 : : struct mlx5_flow_counter_mng *cmng = &sh->sws_cmng;
9724 : 0 : uint16_t pool_index = cmng->pool_index;
9725 : : struct mlx5_flow_counter_pool *pool;
9726 : : uint16_t n_valid;
9727 : : int ret;
9728 : :
9729 [ # # ]: 0 : if (cmng->pending_queries >= MLX5_MAX_PENDING_QUERIES)
9730 : 0 : goto set_alarm;
9731 : 0 : rte_spinlock_lock(&cmng->pool_update_sl);
9732 : 0 : pool = cmng->pools[pool_index];
9733 : 0 : n_valid = cmng->n_valid;
9734 : : rte_spinlock_unlock(&cmng->pool_update_sl);
9735 : : /* Set the statistic memory to the new created pool. */
9736 [ # # # # ]: 0 : if ((!pool->raw && mlx5_flow_set_counter_stat_mem(sh, pool)))
9737 : 0 : goto set_alarm;
9738 [ # # ]: 0 : if (pool->raw_hw)
9739 : : /* There is a pool query in progress. */
9740 : 0 : goto set_alarm;
9741 : 0 : pool->raw_hw = LIST_FIRST(&cmng->free_stat_raws);
9742 [ # # ]: 0 : if (!pool->raw_hw)
9743 : : /* No free counter statistics raw memory. */
9744 : 0 : goto set_alarm;
9745 : : /*
9746 : : * Identify the counters released between query trigger and query
9747 : : * handle more efficiently. The counter released in this gap period
9748 : : * should wait for a new round of query as the new arrived packets
9749 : : * will not be taken into account.
9750 : : */
9751 : 0 : pool->query_gen++;
9752 : 0 : ret = mlx5_devx_cmd_flow_counter_query(pool->min_dcs, 0,
9753 : : MLX5_COUNTERS_PER_POOL,
9754 : : NULL, NULL,
9755 : 0 : pool->raw_hw->mem_mng->wm.lkey,
9756 : : (void *)(uintptr_t)
9757 : 0 : pool->raw_hw->data,
9758 : : sh->devx_comp,
9759 : : (uint64_t)(uintptr_t)pool);
9760 [ # # ]: 0 : if (ret) {
9761 : 0 : DRV_LOG(ERR, "Failed to trigger asynchronous query for dcs ID"
9762 : : " %d", pool->min_dcs->id);
9763 : 0 : pool->raw_hw = NULL;
9764 : 0 : goto set_alarm;
9765 : : }
9766 [ # # ]: 0 : LIST_REMOVE(pool->raw_hw, next);
9767 : 0 : cmng->pending_queries++;
9768 : 0 : pool_index++;
9769 [ # # ]: 0 : if (pool_index >= n_valid)
9770 : : pool_index = 0;
9771 : 0 : set_alarm:
9772 : 0 : cmng->pool_index = pool_index;
9773 : 0 : mlx5_set_query_alarm(sh);
9774 : 0 : }
9775 : :
9776 : : /**
9777 : : * Check and callback event for new aged flow in the counter pool
9778 : : *
9779 : : * @param[in] sh
9780 : : * Pointer to mlx5_dev_ctx_shared object.
9781 : : * @param[in] pool
9782 : : * Pointer to Current counter pool.
9783 : : */
9784 : : static void
9785 : 0 : mlx5_flow_aging_check(struct mlx5_dev_ctx_shared *sh,
9786 : : struct mlx5_flow_counter_pool *pool)
9787 : : {
9788 : : struct mlx5_priv *priv;
9789 : : struct mlx5_flow_counter *cnt;
9790 : : struct mlx5_age_info *age_info;
9791 : : struct mlx5_age_param *age_param;
9792 : 0 : struct mlx5_counter_stats_raw *cur = pool->raw_hw;
9793 : 0 : struct mlx5_counter_stats_raw *prev = pool->raw;
9794 : 0 : const uint64_t curr_time = MLX5_CURR_TIME_SEC;
9795 : 0 : const uint32_t time_delta = curr_time - pool->time_of_last_age_check;
9796 : : uint16_t expected = AGE_CANDIDATE;
9797 : : uint32_t i;
9798 : :
9799 : 0 : pool->time_of_last_age_check = curr_time;
9800 [ # # ]: 0 : for (i = 0; i < MLX5_COUNTERS_PER_POOL; ++i) {
9801 [ # # ]: 0 : cnt = MLX5_POOL_GET_CNT(pool, i);
9802 : : age_param = MLX5_CNT_TO_AGE(cnt);
9803 [ # # ]: 0 : if (rte_atomic_load_explicit(&age_param->state,
9804 : : rte_memory_order_relaxed) != AGE_CANDIDATE)
9805 : 0 : continue;
9806 [ # # ]: 0 : if (cur->data[i].hits != prev->data[i].hits) {
9807 : 0 : rte_atomic_store_explicit(&age_param->sec_since_last_hit, 0,
9808 : : rte_memory_order_relaxed);
9809 : 0 : continue;
9810 : : }
9811 : 0 : if (rte_atomic_fetch_add_explicit(&age_param->sec_since_last_hit,
9812 : : time_delta,
9813 [ # # ]: 0 : rte_memory_order_relaxed) + time_delta <= age_param->timeout)
9814 : 0 : continue;
9815 : : /**
9816 : : * Hold the lock first, or if between the
9817 : : * state AGE_TMOUT and tailq operation the
9818 : : * release happened, the release procedure
9819 : : * may delete a non-existent tailq node.
9820 : : */
9821 : 0 : priv = rte_eth_devices[age_param->port_id].data->dev_private;
9822 : 0 : age_info = GET_PORT_AGE_INFO(priv);
9823 : 0 : rte_spinlock_lock(&age_info->aged_sl);
9824 [ # # ]: 0 : if (rte_atomic_compare_exchange_strong_explicit(&age_param->state, &expected,
9825 : : AGE_TMOUT,
9826 : : rte_memory_order_relaxed,
9827 : : rte_memory_order_relaxed)) {
9828 : 0 : TAILQ_INSERT_TAIL(&age_info->aged_counters, cnt, next);
9829 : 0 : MLX5_AGE_SET(age_info, MLX5_AGE_EVENT_NEW);
9830 : : }
9831 : : rte_spinlock_unlock(&age_info->aged_sl);
9832 : : }
9833 : 0 : mlx5_age_event_prepare(sh);
9834 : 0 : }
9835 : :
9836 : : /**
9837 : : * Handler for the HW respond about ready values from an asynchronous batch
9838 : : * query. This function is probably called by the host thread.
9839 : : *
9840 : : * @param[in] sh
9841 : : * The pointer to the shared device context.
9842 : : * @param[in] async_id
9843 : : * The Devx async ID.
9844 : : * @param[in] status
9845 : : * The status of the completion.
9846 : : */
9847 : : void
9848 : 0 : mlx5_flow_async_pool_query_handle(struct mlx5_dev_ctx_shared *sh,
9849 : : uint64_t async_id, int status)
9850 : : {
9851 : 0 : struct mlx5_flow_counter_pool *pool =
9852 : : (struct mlx5_flow_counter_pool *)(uintptr_t)async_id;
9853 : : struct mlx5_counter_stats_raw *raw_to_free;
9854 : 0 : uint8_t query_gen = pool->query_gen ^ 1;
9855 : : struct mlx5_flow_counter_mng *cmng = &sh->sws_cmng;
9856 : 0 : enum mlx5_counter_type cnt_type =
9857 : 0 : pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
9858 : : MLX5_COUNTER_TYPE_ORIGIN;
9859 : :
9860 [ # # ]: 0 : if (unlikely(status)) {
9861 : 0 : raw_to_free = pool->raw_hw;
9862 : : } else {
9863 : 0 : raw_to_free = pool->raw;
9864 [ # # ]: 0 : if (pool->is_aged)
9865 : 0 : mlx5_flow_aging_check(sh, pool);
9866 : 0 : rte_spinlock_lock(&pool->sl);
9867 : 0 : pool->raw = pool->raw_hw;
9868 : : rte_spinlock_unlock(&pool->sl);
9869 : : /* Be sure the new raw counters data is updated in memory. */
9870 : 0 : rte_io_wmb();
9871 [ # # ]: 0 : if (!TAILQ_EMPTY(&pool->counters[query_gen])) {
9872 : 0 : rte_spinlock_lock(&cmng->csl[cnt_type]);
9873 [ # # ]: 0 : TAILQ_CONCAT(&cmng->counters[cnt_type],
9874 : : &pool->counters[query_gen], next);
9875 : : rte_spinlock_unlock(&cmng->csl[cnt_type]);
9876 : : }
9877 : : }
9878 [ # # ]: 0 : LIST_INSERT_HEAD(&sh->sws_cmng.free_stat_raws, raw_to_free, next);
9879 : 0 : pool->raw_hw = NULL;
9880 : 0 : sh->sws_cmng.pending_queries--;
9881 : 0 : }
9882 : :
9883 : : static int
9884 : 0 : flow_group_to_table(uint32_t port_id, uint32_t group, uint32_t *table,
9885 : : const struct flow_grp_info *grp_info,
9886 : : struct rte_flow_error *error)
9887 : : {
9888 [ # # ]: 0 : if (grp_info->transfer && grp_info->external &&
9889 : : grp_info->fdb_def_rule) {
9890 [ # # ]: 0 : if (group == UINT32_MAX)
9891 : 0 : return rte_flow_error_set
9892 : : (error, EINVAL,
9893 : : RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
9894 : : NULL,
9895 : : "group index not supported");
9896 : 0 : *table = group + 1;
9897 : : } else {
9898 : 0 : *table = group;
9899 : : }
9900 : 0 : DRV_LOG(DEBUG, "port %u group=%#x table=%#x", port_id, group, *table);
9901 : 0 : return 0;
9902 : : }
9903 : :
9904 : : /**
9905 : : * Translate the rte_flow group index to HW table value.
9906 : : *
9907 : : * If tunnel offload is disabled, all group ids converted to flow table
9908 : : * id using the standard method.
9909 : : * If tunnel offload is enabled, group id can be converted using the
9910 : : * standard or tunnel conversion method. Group conversion method
9911 : : * selection depends on flags in `grp_info` parameter:
9912 : : * - Internal (grp_info.external == 0) groups conversion uses the
9913 : : * standard method.
9914 : : * - Group ids in JUMP action converted with the tunnel conversion.
9915 : : * - Group id in rule attribute conversion depends on a rule type and
9916 : : * group id value:
9917 : : * ** non zero group attributes converted with the tunnel method
9918 : : * ** zero group attribute in non-tunnel rule is converted using the
9919 : : * standard method - there's only one root table
9920 : : * ** zero group attribute in steer tunnel rule is converted with the
9921 : : * standard method - single root table
9922 : : * ** zero group attribute in match tunnel rule is a special OvS
9923 : : * case: that value is used for portability reasons. That group
9924 : : * id is converted with the tunnel conversion method.
9925 : : *
9926 : : * @param[in] dev
9927 : : * Port device
9928 : : * @param[in] tunnel
9929 : : * PMD tunnel offload object
9930 : : * @param[in] group
9931 : : * rte_flow group index value.
9932 : : * @param[out] table
9933 : : * HW table value.
9934 : : * @param[in] grp_info
9935 : : * flags used for conversion
9936 : : * @param[out] error
9937 : : * Pointer to error structure.
9938 : : *
9939 : : * @return
9940 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9941 : : */
9942 : : int
9943 : 0 : mlx5_flow_group_to_table(struct rte_eth_dev *dev,
9944 : : const struct mlx5_flow_tunnel *tunnel,
9945 : : uint32_t group, uint32_t *table,
9946 : : const struct flow_grp_info *grp_info,
9947 : : struct rte_flow_error *error)
9948 : : {
9949 : : int ret;
9950 : : bool standard_translation;
9951 : :
9952 [ # # # # ]: 0 : if (!grp_info->skip_scale && grp_info->external &&
9953 : : group < MLX5_MAX_TABLES_EXTERNAL)
9954 : 0 : group *= MLX5_FLOW_TABLE_FACTOR;
9955 [ # # ]: 0 : if (is_tunnel_offload_active(dev)) {
9956 : 0 : standard_translation = !grp_info->external ||
9957 : : grp_info->std_tbl_fix;
9958 : : } else {
9959 : : standard_translation = true;
9960 : : }
9961 [ # # ]: 0 : DRV_LOG(DEBUG,
9962 : : "port %u group=%u transfer=%d external=%d fdb_def_rule=%d translate=%s",
9963 : : dev->data->port_id, group, grp_info->transfer,
9964 : : grp_info->external, grp_info->fdb_def_rule,
9965 : : standard_translation ? "STANDARD" : "TUNNEL");
9966 [ # # ]: 0 : if (standard_translation)
9967 : 0 : ret = flow_group_to_table(dev->data->port_id, group, table,
9968 : : grp_info, error);
9969 : : else
9970 : 0 : ret = tunnel_flow_group_to_flow_table(dev, tunnel, group,
9971 : : table, error);
9972 : :
9973 : 0 : return ret;
9974 : : }
9975 : :
9976 : : /**
9977 : : * Discover availability of metadata reg_c's.
9978 : : *
9979 : : * Iteratively use test flows to check availability.
9980 : : *
9981 : : * @param[in] dev
9982 : : * Pointer to the Ethernet device structure.
9983 : : *
9984 : : * @return
9985 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9986 : : */
9987 : : int
9988 : 0 : mlx5_flow_discover_mreg_c(struct rte_eth_dev *dev)
9989 : : {
9990 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
9991 : : enum modify_reg idx;
9992 : : int n = 0;
9993 : :
9994 : : /* reg_c[0] and reg_c[1] are reserved. */
9995 : 0 : priv->sh->flow_mreg_c[n++] = REG_C_0;
9996 : 0 : priv->sh->flow_mreg_c[n++] = REG_C_1;
9997 : : /* Discover availability of other reg_c's. */
9998 [ # # ]: 0 : for (idx = REG_C_2; idx <= REG_C_7; ++idx) {
9999 : 0 : struct rte_flow_attr attr = {
10000 : : .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
10001 : : .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
10002 : : .ingress = 1,
10003 : : };
10004 : 0 : struct rte_flow_item items[] = {
10005 : : [0] = {
10006 : : .type = RTE_FLOW_ITEM_TYPE_END,
10007 : : },
10008 : : };
10009 : 0 : struct rte_flow_action actions[] = {
10010 : : [0] = {
10011 : : .type = (enum rte_flow_action_type)
10012 : : MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
10013 : 0 : .conf = &(struct mlx5_flow_action_copy_mreg){
10014 : : .src = REG_C_1,
10015 : : .dst = idx,
10016 : : },
10017 : : },
10018 : : [1] = {
10019 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
10020 : 0 : .conf = &(struct rte_flow_action_jump){
10021 : : .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
10022 : : },
10023 : : },
10024 : : [2] = {
10025 : : .type = RTE_FLOW_ACTION_TYPE_END,
10026 : : },
10027 : : };
10028 : : uint32_t flow_idx;
10029 : : struct rte_flow *flow;
10030 : : struct rte_flow_error error;
10031 : :
10032 [ # # ]: 0 : if (!priv->sh->config.dv_flow_en)
10033 : : break;
10034 : : /* Create internal flow, validation skips copy action. */
10035 : 0 : flow_idx = mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_GEN, &attr,
10036 : : items, actions, false, &error);
10037 : 0 : flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
10038 : : flow_idx);
10039 [ # # ]: 0 : if (!flow)
10040 : 0 : continue;
10041 : 0 : priv->sh->flow_mreg_c[n++] = idx;
10042 : 0 : mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN, flow_idx);
10043 : : }
10044 [ # # ]: 0 : for (; n < MLX5_MREG_C_NUM; ++n)
10045 : 0 : priv->sh->flow_mreg_c[n] = REG_NON;
10046 : 0 : priv->sh->metadata_regc_check_flag = 1;
10047 : 0 : return 0;
10048 : : }
10049 : :
10050 : : int
10051 [ # # # # ]: 0 : save_dump_file(const uint8_t *data, uint32_t size,
10052 : : uint32_t type, uint64_t id, void *arg, FILE *file)
10053 : : {
10054 : : char line[BUF_SIZE];
10055 : : uint32_t out = 0;
10056 : : uint32_t k;
10057 : : uint32_t actions_num;
10058 : : struct rte_flow_query_count *count;
10059 : :
10060 : : memset(line, 0, BUF_SIZE);
10061 [ # # # # ]: 0 : switch (type) {
10062 : 0 : case DR_DUMP_REC_TYPE_PMD_MODIFY_HDR:
10063 : 0 : actions_num = *(uint32_t *)(arg);
10064 : 0 : out += snprintf(line + out, BUF_SIZE - out, "%d,0x%" PRIx64 ",%d,",
10065 : : type, id, actions_num);
10066 : 0 : break;
10067 : 0 : case DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT:
10068 : 0 : out += snprintf(line + out, BUF_SIZE - out, "%d,0x%" PRIx64 ",",
10069 : : type, id);
10070 : 0 : break;
10071 : 0 : case DR_DUMP_REC_TYPE_PMD_COUNTER:
10072 : : count = (struct rte_flow_query_count *)arg;
10073 : 0 : fprintf(file,
10074 : : "%d,0x%" PRIx64 ",%" PRIu64 ",%" PRIu64 "\n",
10075 : : type, id, count->hits, count->bytes);
10076 : 0 : return 0;
10077 : : default:
10078 : : return -1;
10079 : : }
10080 : :
10081 [ # # ]: 0 : for (k = 0; k < size; k++) {
10082 : : /* Make sure we do not overrun the line buffer length. */
10083 [ # # ]: 0 : if (out >= BUF_SIZE - 4) {
10084 : 0 : line[out] = '\0';
10085 : 0 : break;
10086 : : }
10087 : 0 : out += snprintf(line + out, BUF_SIZE - out, "%02x",
10088 : 0 : (data[k]) & 0xff);
10089 : : }
10090 : : fprintf(file, "%s\n", line);
10091 : 0 : return 0;
10092 : : }
10093 : :
10094 : : int
10095 : 0 : mlx5_flow_query_counter(struct rte_eth_dev *dev, struct rte_flow *flow,
10096 : : struct rte_flow_query_count *count, struct rte_flow_error *error)
10097 : : {
10098 : : struct rte_flow_action action[2];
10099 : : enum mlx5_flow_drv_type ftype;
10100 : : const struct mlx5_flow_driver_ops *fops;
10101 : :
10102 [ # # ]: 0 : if (!flow) {
10103 : 0 : return rte_flow_error_set(error, ENOENT,
10104 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10105 : : NULL,
10106 : : "invalid flow handle");
10107 : : }
10108 : 0 : action[0].type = RTE_FLOW_ACTION_TYPE_COUNT;
10109 : 0 : action[1].type = RTE_FLOW_ACTION_TYPE_END;
10110 [ # # ]: 0 : if (flow->counter) {
10111 : : memset(count, 0, sizeof(struct rte_flow_query_count));
10112 : 0 : ftype = (enum mlx5_flow_drv_type)(flow->drv_type);
10113 : : MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN &&
10114 : : ftype < MLX5_FLOW_TYPE_MAX);
10115 : 0 : fops = flow_get_drv_ops(ftype);
10116 : 0 : return fops->query(dev, flow, action, count, error);
10117 : : }
10118 : : return -1;
10119 : : }
10120 : :
10121 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
10122 : : /**
10123 : : * Dump flow ipool data to file
10124 : : *
10125 : : * @param[in] dev
10126 : : * The pointer to Ethernet device.
10127 : : * @param[in] file
10128 : : * A pointer to a file for output.
10129 : : * @param[out] error
10130 : : * Perform verbose error reporting if not NULL. PMDs initialize this
10131 : : * structure in case of error only.
10132 : : * @return
10133 : : * 0 on success, a negative value otherwise.
10134 : : */
10135 : : int
10136 : 0 : mlx5_flow_dev_dump_ipool(struct rte_eth_dev *dev,
10137 : : struct rte_flow *flow, FILE *file,
10138 : : struct rte_flow_error *error)
10139 : : {
10140 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10141 : : struct mlx5_flow_dv_modify_hdr_resource *modify_hdr;
10142 : : struct mlx5_flow_dv_encap_decap_resource *encap_decap;
10143 : : uint32_t handle_idx;
10144 : : struct mlx5_flow_handle *dh;
10145 : : struct rte_flow_query_count count;
10146 : : uint32_t actions_num;
10147 : : const uint8_t *data;
10148 : : size_t size;
10149 : : uint64_t id;
10150 : : uint32_t type;
10151 : 0 : void *action = NULL;
10152 : :
10153 [ # # ]: 0 : if (!flow) {
10154 : 0 : return rte_flow_error_set(error, ENOENT,
10155 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10156 : : NULL,
10157 : : "invalid flow handle");
10158 : : }
10159 : 0 : handle_idx = flow->dev_handles;
10160 : : /* query counter */
10161 [ # # # # ]: 0 : if (flow->counter &&
10162 : 0 : (!mlx5_counter_query(dev, flow->counter, false,
10163 [ # # ]: 0 : &count.hits, &count.bytes, &action)) && action) {
10164 : 0 : id = (uint64_t)(uintptr_t)action;
10165 : : type = DR_DUMP_REC_TYPE_PMD_COUNTER;
10166 : 0 : save_dump_file(NULL, 0, type,
10167 : : id, (void *)&count, file);
10168 : : }
10169 : :
10170 [ # # ]: 0 : while (handle_idx) {
10171 : 0 : dh = mlx5_ipool_get(priv->sh->ipool
10172 : : [MLX5_IPOOL_MLX5_FLOW], handle_idx);
10173 [ # # ]: 0 : if (!dh)
10174 : 0 : continue;
10175 : 0 : handle_idx = dh->next.next;
10176 : :
10177 : : /* Get modify_hdr and encap_decap buf from ipools. */
10178 : : encap_decap = NULL;
10179 : 0 : modify_hdr = dh->dvh.modify_hdr;
10180 : :
10181 [ # # ]: 0 : if (dh->dvh.rix_encap_decap) {
10182 : 0 : encap_decap = mlx5_ipool_get(priv->sh->ipool
10183 : : [MLX5_IPOOL_DECAP_ENCAP],
10184 : : dh->dvh.rix_encap_decap);
10185 : : }
10186 [ # # ]: 0 : if (modify_hdr) {
10187 : 0 : data = (const uint8_t *)modify_hdr->actions;
10188 : 0 : size = (size_t)(modify_hdr->actions_num) * 8;
10189 : 0 : id = (uint64_t)(uintptr_t)modify_hdr->action;
10190 : 0 : actions_num = modify_hdr->actions_num;
10191 : : type = DR_DUMP_REC_TYPE_PMD_MODIFY_HDR;
10192 : 0 : save_dump_file(data, size, type, id,
10193 : : (void *)(&actions_num), file);
10194 : : }
10195 [ # # ]: 0 : if (encap_decap) {
10196 : 0 : data = encap_decap->buf;
10197 : 0 : size = encap_decap->size;
10198 : 0 : id = (uint64_t)(uintptr_t)encap_decap->action;
10199 : : type = DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT;
10200 : 0 : save_dump_file(data, size, type,
10201 : : id, NULL, file);
10202 : : }
10203 : : }
10204 : : return 0;
10205 : : }
10206 : :
10207 : : /**
10208 : : * Dump all flow's encap_decap/modify_hdr/counter data to file
10209 : : *
10210 : : * @param[in] dev
10211 : : * The pointer to Ethernet device.
10212 : : * @param[in] file
10213 : : * A pointer to a file for output.
10214 : : * @param[out] error
10215 : : * Perform verbose error reporting if not NULL. PMDs initialize this
10216 : : * structure in case of error only.
10217 : : * @return
10218 : : * 0 on success, a negative value otherwise.
10219 : : */
10220 : : static int
10221 : 0 : mlx5_flow_dev_dump_sh_all(struct rte_eth_dev *dev,
10222 : : FILE *file, struct rte_flow_error *error __rte_unused)
10223 : : {
10224 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10225 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
10226 : : struct mlx5_hlist *h;
10227 : : struct mlx5_flow_dv_modify_hdr_resource *modify_hdr;
10228 : : struct mlx5_flow_dv_encap_decap_resource *encap_decap;
10229 : : struct rte_flow_query_count count;
10230 : : uint32_t actions_num;
10231 : : const uint8_t *data;
10232 : : size_t size;
10233 : : uint64_t id;
10234 : : uint32_t type;
10235 : : uint32_t i;
10236 : : uint32_t j;
10237 : : struct mlx5_list_inconst *l_inconst;
10238 : : struct mlx5_list_entry *e;
10239 : : int lcore_index;
10240 : : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
10241 : : uint32_t max;
10242 : : void *action;
10243 : :
10244 : : /* encap_decap hlist is lcore_share, get global core cache. */
10245 : : i = MLX5_LIST_GLOBAL;
10246 : 0 : h = sh->encaps_decaps;
10247 [ # # ]: 0 : if (h) {
10248 [ # # ]: 0 : for (j = 0; j <= h->mask; j++) {
10249 : : l_inconst = &h->buckets[j].l;
10250 [ # # ]: 0 : if (!l_inconst || !l_inconst->cache[i])
10251 : 0 : continue;
10252 : :
10253 : 0 : e = LIST_FIRST(&l_inconst->cache[i]->h);
10254 [ # # ]: 0 : while (e) {
10255 : : encap_decap =
10256 : : (struct mlx5_flow_dv_encap_decap_resource *)e;
10257 : 0 : data = encap_decap->buf;
10258 : 0 : size = encap_decap->size;
10259 : 0 : id = (uint64_t)(uintptr_t)encap_decap->action;
10260 : : type = DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT;
10261 : 0 : save_dump_file(data, size, type,
10262 : : id, NULL, file);
10263 : 0 : e = LIST_NEXT(e, next);
10264 : : }
10265 : : }
10266 : : }
10267 : :
10268 : : /* get modify_hdr */
10269 : 0 : h = sh->modify_cmds;
10270 [ # # ]: 0 : if (h) {
10271 : 0 : lcore_index = rte_lcore_index(rte_lcore_id());
10272 [ # # ]: 0 : if (unlikely(lcore_index == -1)) {
10273 : : lcore_index = MLX5_LIST_NLCORE;
10274 : 0 : rte_spinlock_lock(&h->l_const.lcore_lock);
10275 : : }
10276 : 0 : i = lcore_index;
10277 : :
10278 [ # # ]: 0 : if (lcore_index == MLX5_LIST_NLCORE) {
10279 [ # # ]: 0 : for (i = 0; i <= (uint32_t)lcore_index; i++) {
10280 [ # # ]: 0 : for (j = 0; j <= h->mask; j++) {
10281 : : l_inconst = &h->buckets[j].l;
10282 [ # # ]: 0 : if (!l_inconst || !l_inconst->cache[i])
10283 : 0 : continue;
10284 : :
10285 : 0 : e = LIST_FIRST(&l_inconst->cache[i]->h);
10286 [ # # ]: 0 : while (e) {
10287 : : modify_hdr =
10288 : : (struct mlx5_flow_dv_modify_hdr_resource *)e;
10289 : 0 : data = (const uint8_t *)modify_hdr->actions;
10290 : 0 : size = (size_t)(modify_hdr->actions_num) * 8;
10291 : 0 : actions_num = modify_hdr->actions_num;
10292 : 0 : id = (uint64_t)(uintptr_t)modify_hdr->action;
10293 : : type = DR_DUMP_REC_TYPE_PMD_MODIFY_HDR;
10294 : 0 : save_dump_file(data, size, type, id,
10295 : : (void *)(&actions_num), file);
10296 : 0 : e = LIST_NEXT(e, next);
10297 : : }
10298 : : }
10299 : : }
10300 : : } else {
10301 [ # # ]: 0 : for (j = 0; j <= h->mask; j++) {
10302 : : l_inconst = &h->buckets[j].l;
10303 [ # # ]: 0 : if (!l_inconst || !l_inconst->cache[i])
10304 : 0 : continue;
10305 : :
10306 : 0 : e = LIST_FIRST(&l_inconst->cache[i]->h);
10307 [ # # ]: 0 : while (e) {
10308 : : modify_hdr =
10309 : : (struct mlx5_flow_dv_modify_hdr_resource *)e;
10310 : 0 : data = (const uint8_t *)modify_hdr->actions;
10311 : 0 : size = (size_t)(modify_hdr->actions_num) * 8;
10312 : 0 : actions_num = modify_hdr->actions_num;
10313 : 0 : id = (uint64_t)(uintptr_t)modify_hdr->action;
10314 : : type = DR_DUMP_REC_TYPE_PMD_MODIFY_HDR;
10315 : 0 : save_dump_file(data, size, type, id,
10316 : : (void *)(&actions_num), file);
10317 : 0 : e = LIST_NEXT(e, next);
10318 : : }
10319 : : }
10320 : : }
10321 : :
10322 [ # # ]: 0 : if (unlikely(lcore_index == MLX5_LIST_NLCORE))
10323 : 0 : rte_spinlock_unlock(&h->l_const.lcore_lock);
10324 : : }
10325 : :
10326 : : /* get counter */
10327 : : MLX5_ASSERT(cmng->n_valid <= MLX5_COUNTER_POOLS_MAX_NUM);
10328 : 0 : max = MLX5_COUNTERS_PER_POOL * cmng->n_valid;
10329 [ # # ]: 0 : for (j = 1; j <= max; j++) {
10330 : 0 : action = NULL;
10331 [ # # ]: 0 : if ((!mlx5_counter_query(dev, j, false, &count.hits,
10332 [ # # ]: 0 : &count.bytes, &action)) && action) {
10333 : 0 : id = (uint64_t)(uintptr_t)action;
10334 : : type = DR_DUMP_REC_TYPE_PMD_COUNTER;
10335 : 0 : save_dump_file(NULL, 0, type,
10336 : : id, (void *)&count, file);
10337 : : }
10338 : : }
10339 : 0 : return 0;
10340 : : }
10341 : : #endif
10342 : :
10343 : : /**
10344 : : * Dump flow raw hw data to file
10345 : : *
10346 : : * @param[in] dev
10347 : : * The pointer to Ethernet device.
10348 : : * @param[in] file
10349 : : * A pointer to a file for output.
10350 : : * @param[out] error
10351 : : * Perform verbose error reporting if not NULL. PMDs initialize this
10352 : : * structure in case of error only.
10353 : : * @return
10354 : : * 0 on success, a negative value otherwise.
10355 : : */
10356 : : int
10357 : 0 : mlx5_flow_dev_dump(struct rte_eth_dev *dev, struct rte_flow *flow_idx,
10358 : : FILE *file,
10359 : : struct rte_flow_error *error __rte_unused)
10360 : : {
10361 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10362 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
10363 : : uint32_t handle_idx;
10364 : : int ret;
10365 : : struct mlx5_flow_handle *dh;
10366 : : struct rte_flow *flow;
10367 : :
10368 [ # # ]: 0 : if (!sh->config.dv_flow_en) {
10369 [ # # ]: 0 : if (fputs("device dv flow disabled\n", file) <= 0)
10370 : 0 : return -errno;
10371 : : return -ENOTSUP;
10372 : : }
10373 : :
10374 : : /* dump all */
10375 [ # # ]: 0 : if (!flow_idx) {
10376 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
10377 [ # # ]: 0 : if (mlx5_flow_dev_dump_sh_all(dev, file, error))
10378 : : return -EINVAL;
10379 : :
10380 [ # # ]: 0 : if (sh->config.dv_flow_en == 2)
10381 : 0 : return mlx5dr_debug_dump(priv->dr_ctx, file);
10382 : : #endif
10383 : 0 : return mlx5_devx_cmd_flow_dump(sh->fdb_domain,
10384 : : sh->rx_domain,
10385 : : sh->tx_domain, file);
10386 : : }
10387 : : /* dump one */
10388 : 0 : flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
10389 : : (uintptr_t)(void *)flow_idx);
10390 [ # # ]: 0 : if (!flow)
10391 : : return -EINVAL;
10392 : :
10393 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
10394 : 0 : mlx5_flow_dev_dump_ipool(dev, flow, file, error);
10395 : : #endif
10396 : 0 : handle_idx = flow->dev_handles;
10397 [ # # ]: 0 : while (handle_idx) {
10398 : 0 : dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
10399 : : handle_idx);
10400 [ # # ]: 0 : if (!dh)
10401 : : return -ENOENT;
10402 [ # # ]: 0 : if (dh->drv_flow) {
10403 [ # # ]: 0 : if (sh->config.dv_flow_en == 2)
10404 : : return -ENOTSUP;
10405 : :
10406 : 0 : ret = mlx5_devx_cmd_flow_single_dump(dh->drv_flow,
10407 : : file);
10408 [ # # ]: 0 : if (ret)
10409 : : return -ENOENT;
10410 : : }
10411 : 0 : handle_idx = dh->next.next;
10412 : : }
10413 : : return 0;
10414 : : }
10415 : :
10416 : : /**
10417 : : * Get aged-out flows.
10418 : : *
10419 : : * @param[in] dev
10420 : : * Pointer to the Ethernet device structure.
10421 : : * @param[in] context
10422 : : * The address of an array of pointers to the aged-out flows contexts.
10423 : : * @param[in] nb_countexts
10424 : : * The length of context array pointers.
10425 : : * @param[out] error
10426 : : * Perform verbose error reporting if not NULL. Initialized in case of
10427 : : * error only.
10428 : : *
10429 : : * @return
10430 : : * how many contexts get in success, otherwise negative errno value.
10431 : : * if nb_contexts is 0, return the amount of all aged contexts.
10432 : : * if nb_contexts is not 0 , return the amount of aged flows reported
10433 : : * in the context array.
10434 : : */
10435 : : int
10436 [ # # ]: 0 : mlx5_flow_get_aged_flows(struct rte_eth_dev *dev, void **contexts,
10437 : : uint32_t nb_contexts, struct rte_flow_error *error)
10438 : : {
10439 : : struct rte_flow_attr attr = { .transfer = 0 };
10440 : :
10441 : 0 : return flow_get_drv_ops(flow_get_drv_type(dev, &attr))->get_aged_flows
10442 : : (dev, contexts, nb_contexts, error);
10443 : : }
10444 : :
10445 : : /**
10446 : : * Get aged-out flows per HWS queue.
10447 : : *
10448 : : * @param[in] dev
10449 : : * Pointer to the Ethernet device structure.
10450 : : * @param[in] queue_id
10451 : : * Flow queue to query.
10452 : : * @param[in] context
10453 : : * The address of an array of pointers to the aged-out flows contexts.
10454 : : * @param[in] nb_countexts
10455 : : * The length of context array pointers.
10456 : : * @param[out] error
10457 : : * Perform verbose error reporting if not NULL. Initialized in case of
10458 : : * error only.
10459 : : *
10460 : : * @return
10461 : : * how many contexts get in success, otherwise negative errno value.
10462 : : * if nb_contexts is 0, return the amount of all aged contexts.
10463 : : * if nb_contexts is not 0 , return the amount of aged flows reported
10464 : : * in the context array.
10465 : : */
10466 : : int
10467 [ # # ]: 0 : mlx5_flow_get_q_aged_flows(struct rte_eth_dev *dev, uint32_t queue_id,
10468 : : void **contexts, uint32_t nb_contexts,
10469 : : struct rte_flow_error *error)
10470 : : {
10471 : : const struct mlx5_flow_driver_ops *fops;
10472 : : struct rte_flow_attr attr = { 0 };
10473 : :
10474 : : if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_HW) {
10475 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
10476 : 0 : return fops->get_q_aged_flows(dev, queue_id, contexts,
10477 : : nb_contexts, error);
10478 : : }
10479 : 0 : DRV_LOG(ERR, "port %u queue %u get aged flows is not supported.",
10480 : : dev->data->port_id, queue_id);
10481 : 0 : return rte_flow_error_set(error, ENOTSUP,
10482 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10483 : : "get Q aged flows with incorrect steering mode");
10484 : : }
10485 : :
10486 : : /* Wrapper for driver action_validate op callback */
10487 : : static int
10488 : 0 : flow_drv_action_validate(struct rte_eth_dev *dev,
10489 : : const struct rte_flow_indir_action_conf *conf,
10490 : : const struct rte_flow_action *action,
10491 : : const struct mlx5_flow_driver_ops *fops,
10492 : : struct rte_flow_error *error)
10493 : : {
10494 : : static const char err_msg[] = "indirect action validation unsupported";
10495 : :
10496 [ # # ]: 0 : if (!fops->action_validate) {
10497 : 0 : DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
10498 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
10499 : : NULL, err_msg);
10500 : 0 : return -rte_errno;
10501 : : }
10502 : 0 : return fops->action_validate(dev, conf, action, error);
10503 : : }
10504 : :
10505 : : /**
10506 : : * Destroys the shared action by handle.
10507 : : *
10508 : : * @param dev
10509 : : * Pointer to Ethernet device structure.
10510 : : * @param[in] handle
10511 : : * Handle for the indirect action object to be destroyed.
10512 : : * @param[out] error
10513 : : * Perform verbose error reporting if not NULL. PMDs initialize this
10514 : : * structure in case of error only.
10515 : : *
10516 : : * @return
10517 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
10518 : : *
10519 : : * @note: wrapper for driver action_create op callback.
10520 : : */
10521 : : static int
10522 [ # # ]: 0 : mlx5_action_handle_destroy(struct rte_eth_dev *dev,
10523 : : struct rte_flow_action_handle *handle,
10524 : : struct rte_flow_error *error)
10525 : : {
10526 : : static const char err_msg[] = "indirect action destruction unsupported";
10527 : : struct rte_flow_attr attr = { .transfer = 0 };
10528 : 0 : const struct mlx5_flow_driver_ops *fops =
10529 : : flow_get_drv_ops(flow_get_drv_type(dev, &attr));
10530 : :
10531 [ # # ]: 0 : if (!fops->action_destroy) {
10532 : 0 : DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
10533 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
10534 : : NULL, err_msg);
10535 : 0 : return -rte_errno;
10536 : : }
10537 : 0 : return fops->action_destroy(dev, handle, error);
10538 : : }
10539 : :
10540 : : /* Wrapper for driver action_destroy op callback */
10541 : : static int
10542 : 0 : flow_drv_action_update(struct rte_eth_dev *dev,
10543 : : struct rte_flow_action_handle *handle,
10544 : : const void *update,
10545 : : const struct mlx5_flow_driver_ops *fops,
10546 : : struct rte_flow_error *error)
10547 : : {
10548 : : static const char err_msg[] = "indirect action update unsupported";
10549 : :
10550 [ # # ]: 0 : if (!fops->action_update) {
10551 : 0 : DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
10552 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
10553 : : NULL, err_msg);
10554 : 0 : return -rte_errno;
10555 : : }
10556 : 0 : return fops->action_update(dev, handle, update, error);
10557 : : }
10558 : :
10559 : : /* Wrapper for driver action_destroy op callback */
10560 : : static int
10561 : 0 : flow_drv_action_query(struct rte_eth_dev *dev,
10562 : : const struct rte_flow_action_handle *handle,
10563 : : void *data,
10564 : : const struct mlx5_flow_driver_ops *fops,
10565 : : struct rte_flow_error *error)
10566 : : {
10567 : : static const char err_msg[] = "indirect action query unsupported";
10568 : :
10569 [ # # ]: 0 : if (!fops->action_query) {
10570 : 0 : DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
10571 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
10572 : : NULL, err_msg);
10573 : 0 : return -rte_errno;
10574 : : }
10575 : 0 : return fops->action_query(dev, handle, data, error);
10576 : : }
10577 : :
10578 : : /**
10579 : : * Create indirect action for reuse in multiple flow rules.
10580 : : *
10581 : : * @param dev
10582 : : * Pointer to Ethernet device structure.
10583 : : * @param conf
10584 : : * Pointer to indirect action object configuration.
10585 : : * @param[in] action
10586 : : * Action configuration for indirect action object creation.
10587 : : * @param[out] error
10588 : : * Perform verbose error reporting if not NULL. PMDs initialize this
10589 : : * structure in case of error only.
10590 : : * @return
10591 : : * A valid handle in case of success, NULL otherwise and rte_errno is set.
10592 : : */
10593 : : static struct rte_flow_action_handle *
10594 [ # # ]: 0 : mlx5_action_handle_create(struct rte_eth_dev *dev,
10595 : : const struct rte_flow_indir_action_conf *conf,
10596 : : const struct rte_flow_action *action,
10597 : : struct rte_flow_error *error)
10598 : : {
10599 : : static const char err_msg[] = "indirect action creation unsupported";
10600 : : struct rte_flow_attr attr = { .transfer = 0 };
10601 : 0 : const struct mlx5_flow_driver_ops *fops =
10602 : : flow_get_drv_ops(flow_get_drv_type(dev, &attr));
10603 : :
10604 [ # # ]: 0 : if (flow_drv_action_validate(dev, conf, action, fops, error))
10605 : : return NULL;
10606 [ # # ]: 0 : if (!fops->action_create) {
10607 : 0 : DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
10608 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
10609 : : NULL, err_msg);
10610 : 0 : return NULL;
10611 : : }
10612 : 0 : return fops->action_create(dev, conf, action, error);
10613 : : }
10614 : :
10615 : : /**
10616 : : * Updates inplace the indirect action configuration pointed by *handle*
10617 : : * with the configuration provided as *update* argument.
10618 : : * The update of the indirect action configuration effects all flow rules
10619 : : * reusing the action via handle.
10620 : : *
10621 : : * @param dev
10622 : : * Pointer to Ethernet device structure.
10623 : : * @param[in] handle
10624 : : * Handle for the indirect action to be updated.
10625 : : * @param[in] update
10626 : : * Action specification used to modify the action pointed by handle.
10627 : : * *update* could be of same type with the action pointed by the *handle*
10628 : : * handle argument, or some other structures like a wrapper, depending on
10629 : : * the indirect action type.
10630 : : * @param[out] error
10631 : : * Perform verbose error reporting if not NULL. PMDs initialize this
10632 : : * structure in case of error only.
10633 : : *
10634 : : * @return
10635 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
10636 : : */
10637 : : static int
10638 [ # # ]: 0 : mlx5_action_handle_update(struct rte_eth_dev *dev,
10639 : : struct rte_flow_action_handle *handle,
10640 : : const void *update,
10641 : : struct rte_flow_error *error)
10642 : : {
10643 : : struct rte_flow_attr attr = { .transfer = 0 };
10644 : 0 : const struct mlx5_flow_driver_ops *fops =
10645 : : flow_get_drv_ops(flow_get_drv_type(dev, &attr));
10646 : : int ret;
10647 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
10648 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
10649 : :
10650 [ # # ]: 0 : switch (type) {
10651 : : case MLX5_INDIRECT_ACTION_TYPE_CT:
10652 : : case MLX5_INDIRECT_ACTION_TYPE_METER_MARK:
10653 : : ret = 0;
10654 : : break;
10655 : 0 : default:
10656 : 0 : ret = flow_drv_action_validate(dev, NULL,
10657 : : (const struct rte_flow_action *)update,
10658 : : fops, error);
10659 : : }
10660 [ # # ]: 0 : if (ret)
10661 : : return ret;
10662 : 0 : return flow_drv_action_update(dev, handle, update, fops,
10663 : : error);
10664 : : }
10665 : :
10666 : : /**
10667 : : * Query the indirect action by handle.
10668 : : *
10669 : : * This function allows retrieving action-specific data such as counters.
10670 : : * Data is gathered by special action which may be present/referenced in
10671 : : * more than one flow rule definition.
10672 : : *
10673 : : * see @RTE_FLOW_ACTION_TYPE_COUNT
10674 : : *
10675 : : * @param dev
10676 : : * Pointer to Ethernet device structure.
10677 : : * @param[in] handle
10678 : : * Handle for the indirect action to query.
10679 : : * @param[in, out] data
10680 : : * Pointer to storage for the associated query data type.
10681 : : * @param[out] error
10682 : : * Perform verbose error reporting if not NULL. PMDs initialize this
10683 : : * structure in case of error only.
10684 : : *
10685 : : * @return
10686 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
10687 : : */
10688 : : static int
10689 [ # # ]: 0 : mlx5_action_handle_query(struct rte_eth_dev *dev,
10690 : : const struct rte_flow_action_handle *handle,
10691 : : void *data,
10692 : : struct rte_flow_error *error)
10693 : : {
10694 : : struct rte_flow_attr attr = { .transfer = 0 };
10695 : 0 : const struct mlx5_flow_driver_ops *fops =
10696 : : flow_get_drv_ops(flow_get_drv_type(dev, &attr));
10697 : :
10698 : 0 : return flow_drv_action_query(dev, handle, data, fops, error);
10699 : : }
10700 : :
10701 : : static int
10702 [ # # ]: 0 : mlx5_action_handle_query_update(struct rte_eth_dev *dev,
10703 : : struct rte_flow_action_handle *handle,
10704 : : const void *update, void *query,
10705 : : enum rte_flow_query_update_mode qu_mode,
10706 : : struct rte_flow_error *error)
10707 : : {
10708 : : struct rte_flow_attr attr = { .transfer = 0 };
10709 : : enum mlx5_flow_drv_type drv_type = flow_get_drv_type(dev, &attr);
10710 : : const struct mlx5_flow_driver_ops *fops;
10711 : :
10712 : : if (drv_type == MLX5_FLOW_TYPE_MIN || drv_type == MLX5_FLOW_TYPE_MAX)
10713 : : return rte_flow_error_set(error, ENOTSUP,
10714 : : RTE_FLOW_ERROR_TYPE_ACTION,
10715 : : NULL, "invalid driver type");
10716 : 0 : fops = flow_get_drv_ops(drv_type);
10717 [ # # # # ]: 0 : if (!fops || !fops->action_query_update)
10718 : 0 : return rte_flow_error_set(error, ENOTSUP,
10719 : : RTE_FLOW_ERROR_TYPE_ACTION,
10720 : : NULL, "no query_update handler");
10721 : 0 : return fops->action_query_update(dev, handle, update,
10722 : : query, qu_mode, error);
10723 : : }
10724 : :
10725 : :
10726 : : #define MLX5_DRV_FOPS_OR_ERR(dev, fops, drv_cb, ret) \
10727 : : { \
10728 : : struct rte_flow_attr attr = { .transfer = 0 }; \
10729 : : enum mlx5_flow_drv_type drv_type = flow_get_drv_type((dev), &attr); \
10730 : : if (drv_type == MLX5_FLOW_TYPE_MIN || \
10731 : : drv_type == MLX5_FLOW_TYPE_MAX) { \
10732 : : rte_flow_error_set(error, ENOTSUP, \
10733 : : RTE_FLOW_ERROR_TYPE_ACTION, \
10734 : : NULL, "invalid driver type"); \
10735 : : return ret; \
10736 : : } \
10737 : : (fops) = flow_get_drv_ops(drv_type); \
10738 : : if (!(fops) || !(fops)->drv_cb) { \
10739 : : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, \
10740 : : NULL, "no action_list handler"); \
10741 : : return ret; \
10742 : : } \
10743 : : }
10744 : :
10745 : : static struct rte_flow_action_list_handle *
10746 [ # # ]: 0 : mlx5_action_list_handle_create(struct rte_eth_dev *dev,
10747 : : const struct rte_flow_indir_action_conf *conf,
10748 : : const struct rte_flow_action *actions,
10749 : : struct rte_flow_error *error)
10750 : : {
10751 : : const struct mlx5_flow_driver_ops *fops;
10752 : :
10753 [ # # # # ]: 0 : MLX5_DRV_FOPS_OR_ERR(dev, fops, action_list_handle_create, NULL);
10754 : 0 : return fops->action_list_handle_create(dev, conf, actions, error);
10755 : : }
10756 : :
10757 : : static int
10758 [ # # ]: 0 : mlx5_action_list_handle_destroy(struct rte_eth_dev *dev,
10759 : : struct rte_flow_action_list_handle *handle,
10760 : : struct rte_flow_error *error)
10761 : : {
10762 : : const struct mlx5_flow_driver_ops *fops;
10763 : :
10764 [ # # # # ]: 0 : MLX5_DRV_FOPS_OR_ERR(dev, fops, action_list_handle_destroy, ENOTSUP);
10765 : 0 : return fops->action_list_handle_destroy(dev, handle, error);
10766 : : }
10767 : :
10768 : : static int
10769 [ # # ]: 0 : mlx5_flow_action_list_handle_query_update(struct rte_eth_dev *dev,
10770 : : const
10771 : : struct rte_flow_action_list_handle *handle,
10772 : : const void **update, void **query,
10773 : : enum rte_flow_query_update_mode mode,
10774 : : struct rte_flow_error *error)
10775 : : {
10776 : : const struct mlx5_flow_driver_ops *fops;
10777 : :
10778 [ # # # # ]: 0 : MLX5_DRV_FOPS_OR_ERR(dev, fops,
10779 : : action_list_handle_query_update, ENOTSUP);
10780 : 0 : return fops->action_list_handle_query_update(dev, handle, update, query,
10781 : : mode, error);
10782 : : }
10783 : : static int
10784 [ # # ]: 0 : mlx5_flow_calc_table_hash(struct rte_eth_dev *dev,
10785 : : const struct rte_flow_template_table *table,
10786 : : const struct rte_flow_item pattern[],
10787 : : uint8_t pattern_template_index,
10788 : : uint32_t *hash, struct rte_flow_error *error)
10789 : : {
10790 : : struct rte_flow_attr attr = { .transfer = 0 };
10791 : : enum mlx5_flow_drv_type drv_type = flow_get_drv_type(dev, &attr);
10792 : : const struct mlx5_flow_driver_ops *fops;
10793 : :
10794 : : if (drv_type == MLX5_FLOW_TYPE_MIN || drv_type == MLX5_FLOW_TYPE_MAX)
10795 : : return rte_flow_error_set(error, ENOTSUP,
10796 : : RTE_FLOW_ERROR_TYPE_ACTION,
10797 : : NULL, "invalid driver type");
10798 : 0 : fops = flow_get_drv_ops(drv_type);
10799 [ # # # # ]: 0 : if (!fops || !fops->action_query_update)
10800 : 0 : return rte_flow_error_set(error, ENOTSUP,
10801 : : RTE_FLOW_ERROR_TYPE_ACTION,
10802 : : NULL, "no query_update handler");
10803 : 0 : return fops->flow_calc_table_hash(dev, table, pattern, pattern_template_index,
10804 : : hash, error);
10805 : : }
10806 : :
10807 : : static int
10808 [ # # ]: 0 : mlx5_flow_calc_encap_hash(struct rte_eth_dev *dev,
10809 : : const struct rte_flow_item pattern[],
10810 : : enum rte_flow_encap_hash_field dest_field,
10811 : : uint8_t *hash,
10812 : : struct rte_flow_error *error)
10813 : : {
10814 : : enum mlx5_flow_drv_type drv_type = flow_get_drv_type(dev, NULL);
10815 : : const struct mlx5_flow_driver_ops *fops;
10816 : :
10817 : : if (drv_type == MLX5_FLOW_TYPE_MIN || drv_type == MLX5_FLOW_TYPE_MAX)
10818 : 0 : return rte_flow_error_set(error, ENOTSUP,
10819 : : RTE_FLOW_ERROR_TYPE_ACTION,
10820 : : NULL, "invalid driver type");
10821 : 0 : fops = flow_get_drv_ops(drv_type);
10822 [ # # # # ]: 0 : if (!fops || !fops->flow_calc_encap_hash)
10823 : 0 : return rte_flow_error_set(error, ENOTSUP,
10824 : : RTE_FLOW_ERROR_TYPE_ACTION,
10825 : : NULL, "no calc encap hash handler");
10826 : 0 : return fops->flow_calc_encap_hash(dev, pattern, dest_field, hash, error);
10827 : : }
10828 : :
10829 : : static int
10830 [ # # ]: 0 : mlx5_template_table_resize(struct rte_eth_dev *dev,
10831 : : struct rte_flow_template_table *table,
10832 : : uint32_t nb_rules, struct rte_flow_error *error)
10833 : : {
10834 : : const struct mlx5_flow_driver_ops *fops;
10835 : :
10836 [ # # # # ]: 0 : MLX5_DRV_FOPS_OR_ERR(dev, fops, table_resize, ENOTSUP);
10837 : 0 : return fops->table_resize(dev, table, nb_rules, error);
10838 : : }
10839 : :
10840 : : static int
10841 [ # # ]: 0 : mlx5_table_resize_complete(struct rte_eth_dev *dev,
10842 : : struct rte_flow_template_table *table,
10843 : : struct rte_flow_error *error)
10844 : : {
10845 : : const struct mlx5_flow_driver_ops *fops;
10846 : :
10847 [ # # # # ]: 0 : MLX5_DRV_FOPS_OR_ERR(dev, fops, table_resize_complete, ENOTSUP);
10848 : 0 : return fops->table_resize_complete(dev, table, error);
10849 : : }
10850 : :
10851 : : static int
10852 [ # # ]: 0 : mlx5_flow_async_update_resized(struct rte_eth_dev *dev, uint32_t queue,
10853 : : const struct rte_flow_op_attr *op_attr,
10854 : : struct rte_flow *rule, void *user_data,
10855 : : struct rte_flow_error *error)
10856 : : {
10857 : : const struct mlx5_flow_driver_ops *fops;
10858 : :
10859 [ # # # # ]: 0 : MLX5_DRV_FOPS_OR_ERR(dev, fops, flow_update_resized, ENOTSUP);
10860 : 0 : return fops->flow_update_resized(dev, queue, op_attr, rule, user_data, error);
10861 : : }
10862 : :
10863 : : /**
10864 : : * Destroy all indirect actions (shared RSS).
10865 : : *
10866 : : * @param dev
10867 : : * Pointer to Ethernet device.
10868 : : *
10869 : : * @return
10870 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
10871 : : */
10872 : : int
10873 : 0 : mlx5_action_handle_flush(struct rte_eth_dev *dev)
10874 : : {
10875 : : struct rte_flow_error error;
10876 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10877 : : struct mlx5_shared_action_rss *shared_rss;
10878 : : int ret = 0;
10879 : : uint32_t idx;
10880 : :
10881 [ # # # # ]: 0 : ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
10882 : : priv->rss_shared_actions, idx, shared_rss, next) {
10883 [ # # ]: 0 : ret |= mlx5_action_handle_destroy(dev,
10884 : 0 : (struct rte_flow_action_handle *)(uintptr_t)idx, &error);
10885 : : }
10886 : 0 : return ret;
10887 : : }
10888 : :
10889 : : /**
10890 : : * Validate existing indirect actions against current device configuration
10891 : : * and attach them to device resources.
10892 : : *
10893 : : * @param dev
10894 : : * Pointer to Ethernet device.
10895 : : *
10896 : : * @return
10897 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
10898 : : */
10899 : : int
10900 : 0 : mlx5_action_handle_attach(struct rte_eth_dev *dev)
10901 : : {
10902 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10903 : : int ret = 0;
10904 : : struct mlx5_ind_table_obj *ind_tbl, *ind_tbl_last;
10905 : :
10906 [ # # ]: 0 : LIST_FOREACH(ind_tbl, &priv->standalone_ind_tbls, next) {
10907 : : const char *message;
10908 : : uint32_t queue_idx;
10909 : :
10910 : 0 : ret = mlx5_validate_rss_queues(dev, ind_tbl->queues,
10911 : : ind_tbl->queues_n,
10912 : : &message, &queue_idx);
10913 [ # # ]: 0 : if (ret != 0) {
10914 : 0 : DRV_LOG(ERR, "Port %u cannot use queue %u in RSS: %s",
10915 : : dev->data->port_id, ind_tbl->queues[queue_idx],
10916 : : message);
10917 : 0 : break;
10918 : : }
10919 : : }
10920 [ # # ]: 0 : if (ret != 0)
10921 : : return ret;
10922 [ # # ]: 0 : LIST_FOREACH(ind_tbl, &priv->standalone_ind_tbls, next) {
10923 : 0 : ret = mlx5_ind_table_obj_attach(dev, ind_tbl);
10924 [ # # ]: 0 : if (ret != 0) {
10925 : 0 : DRV_LOG(ERR, "Port %u could not attach "
10926 : : "indirection table obj %p",
10927 : : dev->data->port_id, (void *)ind_tbl);
10928 : 0 : goto error;
10929 : : }
10930 : : }
10931 : :
10932 : : return 0;
10933 : : error:
10934 : : ind_tbl_last = ind_tbl;
10935 [ # # ]: 0 : LIST_FOREACH(ind_tbl, &priv->standalone_ind_tbls, next) {
10936 [ # # ]: 0 : if (ind_tbl == ind_tbl_last)
10937 : : break;
10938 [ # # ]: 0 : if (mlx5_ind_table_obj_detach(dev, ind_tbl) != 0)
10939 : 0 : DRV_LOG(CRIT, "Port %u could not detach "
10940 : : "indirection table obj %p on rollback",
10941 : : dev->data->port_id, (void *)ind_tbl);
10942 : : }
10943 : : return ret;
10944 : : }
10945 : :
10946 : : /**
10947 : : * Detach indirect actions of the device from its resources.
10948 : : *
10949 : : * @param dev
10950 : : * Pointer to Ethernet device.
10951 : : *
10952 : : * @return
10953 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
10954 : : */
10955 : : int
10956 : 0 : mlx5_action_handle_detach(struct rte_eth_dev *dev)
10957 : : {
10958 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10959 : : int ret = 0;
10960 : : struct mlx5_ind_table_obj *ind_tbl, *ind_tbl_last;
10961 : :
10962 [ # # ]: 0 : LIST_FOREACH(ind_tbl, &priv->standalone_ind_tbls, next) {
10963 : 0 : ret = mlx5_ind_table_obj_detach(dev, ind_tbl);
10964 [ # # ]: 0 : if (ret != 0) {
10965 : 0 : DRV_LOG(ERR, "Port %u could not detach "
10966 : : "indirection table obj %p",
10967 : : dev->data->port_id, (void *)ind_tbl);
10968 : 0 : goto error;
10969 : : }
10970 : : }
10971 : : return 0;
10972 : : error:
10973 : : ind_tbl_last = ind_tbl;
10974 [ # # ]: 0 : LIST_FOREACH(ind_tbl, &priv->standalone_ind_tbls, next) {
10975 [ # # ]: 0 : if (ind_tbl == ind_tbl_last)
10976 : : break;
10977 [ # # ]: 0 : if (mlx5_ind_table_obj_attach(dev, ind_tbl) != 0)
10978 : 0 : DRV_LOG(CRIT, "Port %u could not attach "
10979 : : "indirection table obj %p on rollback",
10980 : : dev->data->port_id, (void *)ind_tbl);
10981 : : }
10982 : : return ret;
10983 : : }
10984 : :
10985 : : #ifndef HAVE_MLX5DV_DR
10986 : : #define MLX5_DOMAIN_SYNC_FLOW ((1 << 0) | (1 << 1))
10987 : : #else
10988 : : #define MLX5_DOMAIN_SYNC_FLOW \
10989 : : (MLX5DV_DR_DOMAIN_SYNC_FLAGS_SW | MLX5DV_DR_DOMAIN_SYNC_FLAGS_HW)
10990 : : #endif
10991 : :
10992 : 0 : int rte_pmd_mlx5_sync_flow(uint16_t port_id, uint32_t domains)
10993 : : {
10994 [ # # ]: 0 : struct rte_eth_dev *dev = &rte_eth_devices[port_id];
10995 : : const struct mlx5_flow_driver_ops *fops;
10996 : : int ret;
10997 : : struct rte_flow_attr attr = { .transfer = 0 };
10998 : :
10999 : 0 : fops = flow_get_drv_ops(flow_get_drv_type(dev, &attr));
11000 : 0 : ret = fops->sync_domain(dev, domains, MLX5_DOMAIN_SYNC_FLOW);
11001 [ # # ]: 0 : if (ret > 0)
11002 : 0 : ret = -ret;
11003 : 0 : return ret;
11004 : : }
11005 : :
11006 : : const struct mlx5_flow_tunnel *
11007 : 0 : mlx5_get_tof(const struct rte_flow_item *item,
11008 : : const struct rte_flow_action *action,
11009 : : enum mlx5_tof_rule_type *rule_type)
11010 : : {
11011 [ # # ]: 0 : for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
11012 [ # # ]: 0 : if (item->type == (typeof(item->type))
11013 : : MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL) {
11014 : 0 : *rule_type = MLX5_TUNNEL_OFFLOAD_MATCH_RULE;
11015 : 0 : return flow_items_to_tunnel(item);
11016 : : }
11017 : : }
11018 [ # # ]: 0 : for (; action->conf != RTE_FLOW_ACTION_TYPE_END; action++) {
11019 [ # # ]: 0 : if (action->type == (typeof(action->type))
11020 : : MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET) {
11021 : 0 : *rule_type = MLX5_TUNNEL_OFFLOAD_SET_RULE;
11022 : 0 : return flow_actions_to_tunnel(action);
11023 : : }
11024 : : }
11025 : : return NULL;
11026 : : }
11027 : :
11028 : : /**
11029 : : * tunnel offload functionality is defined for DV environment only
11030 : : */
11031 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
11032 : : __extension__
11033 : : union tunnel_offload_mark {
11034 : : uint32_t val;
11035 : : struct {
11036 : : uint32_t app_reserve:8;
11037 : : uint32_t table_id:15;
11038 : : uint32_t transfer:1;
11039 : : uint32_t _unused_:8;
11040 : : };
11041 : : };
11042 : :
11043 : : static bool
11044 : : mlx5_access_tunnel_offload_db
11045 : : (struct rte_eth_dev *dev,
11046 : : bool (*match)(struct rte_eth_dev *,
11047 : : struct mlx5_flow_tunnel *, const void *),
11048 : : void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
11049 : : void (*miss)(struct rte_eth_dev *, void *),
11050 : : void *ctx, bool lock_op);
11051 : :
11052 : : static int
11053 : 0 : flow_tunnel_add_default_miss(struct rte_eth_dev *dev,
11054 : : struct rte_flow *flow,
11055 : : const struct rte_flow_attr *attr,
11056 : : const struct rte_flow_action *app_actions,
11057 : : uint32_t flow_idx,
11058 : : const struct mlx5_flow_tunnel *tunnel,
11059 : : struct tunnel_default_miss_ctx *ctx,
11060 : : struct rte_flow_error *error)
11061 : : {
11062 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11063 : : struct mlx5_flow *dev_flow;
11064 : 0 : struct rte_flow_attr miss_attr = *attr;
11065 : 0 : const struct rte_flow_item miss_items[2] = {
11066 : : {
11067 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
11068 : : .spec = NULL,
11069 : : .last = NULL,
11070 : : .mask = NULL
11071 : : },
11072 : : {
11073 : : .type = RTE_FLOW_ITEM_TYPE_END,
11074 : : .spec = NULL,
11075 : : .last = NULL,
11076 : : .mask = NULL
11077 : : }
11078 : : };
11079 : : union tunnel_offload_mark mark_id;
11080 : : struct rte_flow_action_mark miss_mark;
11081 : 0 : struct rte_flow_action miss_actions[3] = {
11082 : : [0] = { .type = RTE_FLOW_ACTION_TYPE_MARK, .conf = &miss_mark },
11083 : : [2] = { .type = RTE_FLOW_ACTION_TYPE_END, .conf = NULL }
11084 : : };
11085 : : const struct rte_flow_action_jump *jump_data;
11086 : 0 : uint32_t i, flow_table = 0; /* prevent compilation warning */
11087 : 0 : struct flow_grp_info grp_info = {
11088 : : .external = 1,
11089 : 0 : .transfer = attr->transfer,
11090 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
11091 : : .std_tbl_fix = 0,
11092 : : };
11093 : : int ret;
11094 : :
11095 [ # # ]: 0 : if (!attr->transfer) {
11096 : : uint32_t q_size;
11097 : :
11098 : 0 : miss_actions[1].type = RTE_FLOW_ACTION_TYPE_RSS;
11099 : 0 : q_size = priv->reta_idx_n * sizeof(ctx->queue[0]);
11100 : 0 : ctx->queue = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, q_size,
11101 : : 0, SOCKET_ID_ANY);
11102 [ # # ]: 0 : if (!ctx->queue)
11103 : 0 : return rte_flow_error_set
11104 : : (error, ENOMEM,
11105 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
11106 : : NULL, "invalid default miss RSS");
11107 : 0 : ctx->action_rss.func = RTE_ETH_HASH_FUNCTION_DEFAULT,
11108 : 0 : ctx->action_rss.level = 0,
11109 : 0 : ctx->action_rss.types = priv->rss_conf.rss_hf,
11110 : 0 : ctx->action_rss.key_len = priv->rss_conf.rss_key_len,
11111 : 0 : ctx->action_rss.queue_num = priv->reta_idx_n,
11112 : 0 : ctx->action_rss.key = priv->rss_conf.rss_key,
11113 : 0 : ctx->action_rss.queue = ctx->queue;
11114 [ # # # # ]: 0 : if (!priv->reta_idx_n || !priv->rxqs_n)
11115 : 0 : return rte_flow_error_set
11116 : : (error, EINVAL,
11117 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
11118 : : NULL, "invalid port configuration");
11119 [ # # ]: 0 : if (!(dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG))
11120 : 0 : ctx->action_rss.types = 0;
11121 [ # # ]: 0 : for (i = 0; i != priv->reta_idx_n; ++i)
11122 : 0 : ctx->queue[i] = (*priv->reta_idx)[i];
11123 : : } else {
11124 : 0 : miss_actions[1].type = RTE_FLOW_ACTION_TYPE_JUMP;
11125 : 0 : ctx->miss_jump.group = MLX5_TNL_MISS_FDB_JUMP_GRP;
11126 : : }
11127 : 0 : miss_actions[1].conf = (typeof(miss_actions[1].conf))ctx->raw;
11128 [ # # ]: 0 : for (; app_actions->type != RTE_FLOW_ACTION_TYPE_JUMP; app_actions++);
11129 : 0 : jump_data = app_actions->conf;
11130 : 0 : miss_attr.priority = MLX5_TNL_MISS_RULE_PRIORITY;
11131 : 0 : miss_attr.group = jump_data->group;
11132 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel, jump_data->group,
11133 : : &flow_table, &grp_info, error);
11134 [ # # ]: 0 : if (ret)
11135 : 0 : return rte_flow_error_set(error, EINVAL,
11136 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
11137 : : NULL, "invalid tunnel id");
11138 : 0 : mark_id.app_reserve = 0;
11139 : 0 : mark_id.table_id = tunnel_flow_tbl_to_id(flow_table);
11140 : 0 : mark_id.transfer = !!attr->transfer;
11141 : 0 : mark_id._unused_ = 0;
11142 : 0 : miss_mark.id = mark_id.val;
11143 : : dev_flow = flow_drv_prepare(dev, flow, &miss_attr,
11144 : : miss_items, miss_actions, flow_idx, error);
11145 [ # # ]: 0 : if (!dev_flow)
11146 : 0 : return -rte_errno;
11147 : 0 : dev_flow->flow = flow;
11148 : 0 : dev_flow->external = true;
11149 : 0 : dev_flow->tunnel = tunnel;
11150 : 0 : dev_flow->tof_type = MLX5_TUNNEL_OFFLOAD_MISS_RULE;
11151 : : /* Subflow object was created, we must include one in the list. */
11152 : 0 : SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
11153 : : dev_flow->handle, next);
11154 : 0 : DRV_LOG(DEBUG,
11155 : : "port %u tunnel type=%d id=%u miss rule priority=%u group=%u",
11156 : : dev->data->port_id, tunnel->app_tunnel.type,
11157 : : tunnel->tunnel_id, miss_attr.priority, miss_attr.group);
11158 : : ret = flow_drv_translate(dev, dev_flow, &miss_attr, miss_items,
11159 : : miss_actions, error);
11160 [ # # ]: 0 : if (!ret)
11161 : 0 : ret = flow_mreg_update_copy_table(dev, flow, miss_actions,
11162 : : error);
11163 : :
11164 : : return ret;
11165 : : }
11166 : :
11167 : : static const struct mlx5_flow_tbl_data_entry *
11168 : 0 : tunnel_mark_decode(struct rte_eth_dev *dev, uint32_t mark)
11169 : : {
11170 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11171 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
11172 : : struct mlx5_list_entry *he;
11173 : 0 : union tunnel_offload_mark mbits = { .val = mark };
11174 : 0 : union mlx5_flow_tbl_key table_key = {
11175 : : {
11176 : 0 : .level = tunnel_id_to_flow_tbl(mbits.table_id),
11177 : : .id = 0,
11178 : : .reserved = 0,
11179 : : .dummy = 0,
11180 : 0 : .is_fdb = !!mbits.transfer,
11181 : : .is_egress = 0,
11182 : : }
11183 : : };
11184 : 0 : struct mlx5_flow_cb_ctx ctx = {
11185 : : .data = &table_key.v64,
11186 : : };
11187 : :
11188 : 0 : he = mlx5_hlist_lookup(sh->flow_tbls, table_key.v64, &ctx);
11189 : : return he ?
11190 [ # # ]: 0 : container_of(he, struct mlx5_flow_tbl_data_entry, entry) : NULL;
11191 : : }
11192 : :
11193 : : static void
11194 : 0 : mlx5_flow_tunnel_grp2tbl_remove_cb(void *tool_ctx,
11195 : : struct mlx5_list_entry *entry)
11196 : : {
11197 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11198 : : struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
11199 : :
11200 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
11201 : : tunnel_flow_tbl_to_id(tte->flow_table));
11202 : 0 : mlx5_free(tte);
11203 : 0 : }
11204 : :
11205 : : static int
11206 : 0 : mlx5_flow_tunnel_grp2tbl_match_cb(void *tool_ctx __rte_unused,
11207 : : struct mlx5_list_entry *entry, void *cb_ctx)
11208 : : {
11209 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11210 : : union tunnel_tbl_key tbl = {
11211 : 0 : .val = *(uint64_t *)(ctx->data),
11212 : : };
11213 : : struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
11214 : :
11215 [ # # # # ]: 0 : return tbl.tunnel_id != tte->tunnel_id || tbl.group != tte->group;
11216 : : }
11217 : :
11218 : : static struct mlx5_list_entry *
11219 : 0 : mlx5_flow_tunnel_grp2tbl_create_cb(void *tool_ctx, void *cb_ctx)
11220 : : {
11221 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11222 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11223 : : struct tunnel_tbl_entry *tte;
11224 : : union tunnel_tbl_key tbl = {
11225 : 0 : .val = *(uint64_t *)(ctx->data),
11226 : : };
11227 : :
11228 : 0 : tte = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO,
11229 : : sizeof(*tte), 0,
11230 : : SOCKET_ID_ANY);
11231 [ # # ]: 0 : if (!tte)
11232 : 0 : goto err;
11233 : 0 : mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
11234 : : &tte->flow_table);
11235 [ # # ]: 0 : if (tte->flow_table >= MLX5_MAX_TABLES) {
11236 : 0 : DRV_LOG(ERR, "Tunnel TBL ID %d exceed max limit.",
11237 : : tte->flow_table);
11238 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
11239 : : tte->flow_table);
11240 : 0 : goto err;
11241 [ # # ]: 0 : } else if (!tte->flow_table) {
11242 : 0 : goto err;
11243 : : }
11244 : 0 : tte->flow_table = tunnel_id_to_flow_tbl(tte->flow_table);
11245 : 0 : tte->tunnel_id = tbl.tunnel_id;
11246 : 0 : tte->group = tbl.group;
11247 : 0 : return &tte->hash;
11248 : 0 : err:
11249 [ # # ]: 0 : if (tte)
11250 : 0 : mlx5_free(tte);
11251 : : return NULL;
11252 : : }
11253 : :
11254 : : static struct mlx5_list_entry *
11255 : 0 : mlx5_flow_tunnel_grp2tbl_clone_cb(void *tool_ctx __rte_unused,
11256 : : struct mlx5_list_entry *oentry,
11257 : : void *cb_ctx __rte_unused)
11258 : : {
11259 : 0 : struct tunnel_tbl_entry *tte = mlx5_malloc(MLX5_MEM_SYS, sizeof(*tte),
11260 : : 0, SOCKET_ID_ANY);
11261 : :
11262 [ # # ]: 0 : if (!tte)
11263 : : return NULL;
11264 : : memcpy(tte, oentry, sizeof(*tte));
11265 : 0 : return &tte->hash;
11266 : : }
11267 : :
11268 : : static void
11269 : 0 : mlx5_flow_tunnel_grp2tbl_clone_free_cb(void *tool_ctx __rte_unused,
11270 : : struct mlx5_list_entry *entry)
11271 : : {
11272 : : struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
11273 : :
11274 : 0 : mlx5_free(tte);
11275 : 0 : }
11276 : :
11277 : : static uint32_t
11278 : 0 : tunnel_flow_group_to_flow_table(struct rte_eth_dev *dev,
11279 : : const struct mlx5_flow_tunnel *tunnel,
11280 : : uint32_t group, uint32_t *table,
11281 : : struct rte_flow_error *error)
11282 : : {
11283 : : struct mlx5_list_entry *he;
11284 : : struct tunnel_tbl_entry *tte;
11285 [ # # ]: 0 : union tunnel_tbl_key key = {
11286 [ # # ]: 0 : .tunnel_id = tunnel ? tunnel->tunnel_id : 0,
11287 : : .group = group
11288 : : };
11289 : : struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
11290 : : struct mlx5_hlist *group_hash;
11291 : 0 : struct mlx5_flow_cb_ctx ctx = {
11292 : : .data = &key.val,
11293 : : };
11294 : :
11295 [ # # ]: 0 : group_hash = tunnel ? tunnel->groups : thub->groups;
11296 : 0 : he = mlx5_hlist_register(group_hash, key.val, &ctx);
11297 [ # # ]: 0 : if (!he)
11298 : 0 : return rte_flow_error_set(error, EINVAL,
11299 : : RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
11300 : : NULL,
11301 : : "tunnel group index not supported");
11302 : : tte = container_of(he, typeof(*tte), hash);
11303 : 0 : *table = tte->flow_table;
11304 : 0 : DRV_LOG(DEBUG, "port %u tunnel %u group=%#x table=%#x",
11305 : : dev->data->port_id, key.tunnel_id, group, *table);
11306 : 0 : return 0;
11307 : : }
11308 : :
11309 : : static void
11310 : 0 : mlx5_flow_tunnel_free(struct rte_eth_dev *dev,
11311 : : struct mlx5_flow_tunnel *tunnel)
11312 : : {
11313 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11314 : : struct mlx5_indexed_pool *ipool;
11315 : :
11316 : 0 : DRV_LOG(DEBUG, "port %u release pmd tunnel id=0x%x",
11317 : : dev->data->port_id, tunnel->tunnel_id);
11318 [ # # ]: 0 : LIST_REMOVE(tunnel, chain);
11319 : 0 : mlx5_hlist_destroy(tunnel->groups);
11320 : 0 : ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
11321 : 0 : mlx5_ipool_free(ipool, tunnel->tunnel_id);
11322 : 0 : }
11323 : :
11324 : : static bool
11325 : 0 : mlx5_access_tunnel_offload_db
11326 : : (struct rte_eth_dev *dev,
11327 : : bool (*match)(struct rte_eth_dev *,
11328 : : struct mlx5_flow_tunnel *, const void *),
11329 : : void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
11330 : : void (*miss)(struct rte_eth_dev *, void *),
11331 : : void *ctx, bool lock_op)
11332 : : {
11333 : : bool verdict = false;
11334 : : struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
11335 : : struct mlx5_flow_tunnel *tunnel;
11336 : :
11337 : 0 : rte_spinlock_lock(&thub->sl);
11338 [ # # ]: 0 : LIST_FOREACH(tunnel, &thub->tunnels, chain) {
11339 : 0 : verdict = match(dev, tunnel, (const void *)ctx);
11340 [ # # ]: 0 : if (verdict)
11341 : : break;
11342 : : }
11343 [ # # ]: 0 : if (!lock_op)
11344 : : rte_spinlock_unlock(&thub->sl);
11345 [ # # ]: 0 : if (verdict && hit)
11346 : 0 : hit(dev, tunnel, ctx);
11347 [ # # ]: 0 : if (!verdict && miss)
11348 : 0 : miss(dev, ctx);
11349 [ # # ]: 0 : if (lock_op)
11350 : : rte_spinlock_unlock(&thub->sl);
11351 : :
11352 : 0 : return verdict;
11353 : : }
11354 : :
11355 : : struct tunnel_db_find_tunnel_id_ctx {
11356 : : uint32_t tunnel_id;
11357 : : struct mlx5_flow_tunnel *tunnel;
11358 : : };
11359 : :
11360 : : static bool
11361 : 0 : find_tunnel_id_match(struct rte_eth_dev *dev,
11362 : : struct mlx5_flow_tunnel *tunnel, const void *x)
11363 : : {
11364 : : const struct tunnel_db_find_tunnel_id_ctx *ctx = x;
11365 : :
11366 : : RTE_SET_USED(dev);
11367 : 0 : return tunnel->tunnel_id == ctx->tunnel_id;
11368 : : }
11369 : :
11370 : : static void
11371 : 0 : find_tunnel_id_hit(struct rte_eth_dev *dev,
11372 : : struct mlx5_flow_tunnel *tunnel, void *x)
11373 : : {
11374 : : struct tunnel_db_find_tunnel_id_ctx *ctx = x;
11375 : : RTE_SET_USED(dev);
11376 : 0 : ctx->tunnel = tunnel;
11377 : 0 : }
11378 : :
11379 : : static struct mlx5_flow_tunnel *
11380 : : mlx5_find_tunnel_id(struct rte_eth_dev *dev, uint32_t id)
11381 : : {
11382 : 0 : struct tunnel_db_find_tunnel_id_ctx ctx = {
11383 : : .tunnel_id = id,
11384 : : };
11385 : :
11386 : 0 : mlx5_access_tunnel_offload_db(dev, find_tunnel_id_match,
11387 : : find_tunnel_id_hit, NULL, &ctx, true);
11388 : :
11389 [ # # ]: 0 : return ctx.tunnel;
11390 : : }
11391 : :
11392 : : static struct mlx5_flow_tunnel *
11393 : 0 : mlx5_flow_tunnel_allocate(struct rte_eth_dev *dev,
11394 : : const struct rte_flow_tunnel *app_tunnel)
11395 : : {
11396 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11397 : : struct mlx5_indexed_pool *ipool;
11398 : : struct mlx5_flow_tunnel *tunnel;
11399 : : uint32_t id;
11400 : :
11401 : 0 : ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
11402 : 0 : tunnel = mlx5_ipool_zmalloc(ipool, &id);
11403 [ # # ]: 0 : if (!tunnel)
11404 : : return NULL;
11405 [ # # ]: 0 : if (id >= MLX5_MAX_TUNNELS) {
11406 : 0 : mlx5_ipool_free(ipool, id);
11407 : 0 : DRV_LOG(ERR, "Tunnel ID %d exceed max limit.", id);
11408 : 0 : return NULL;
11409 : : }
11410 : 0 : tunnel->groups = mlx5_hlist_create("tunnel groups", 64, false, true,
11411 : 0 : priv->sh,
11412 : : mlx5_flow_tunnel_grp2tbl_create_cb,
11413 : : mlx5_flow_tunnel_grp2tbl_match_cb,
11414 : : mlx5_flow_tunnel_grp2tbl_remove_cb,
11415 : : mlx5_flow_tunnel_grp2tbl_clone_cb,
11416 : : mlx5_flow_tunnel_grp2tbl_clone_free_cb);
11417 [ # # ]: 0 : if (!tunnel->groups) {
11418 : 0 : mlx5_ipool_free(ipool, id);
11419 : 0 : return NULL;
11420 : : }
11421 : : /* initiate new PMD tunnel */
11422 : 0 : memcpy(&tunnel->app_tunnel, app_tunnel, sizeof(*app_tunnel));
11423 : 0 : tunnel->tunnel_id = id;
11424 : 0 : tunnel->action.type = (typeof(tunnel->action.type))
11425 : : MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET;
11426 : 0 : tunnel->action.conf = tunnel;
11427 : 0 : tunnel->item.type = (typeof(tunnel->item.type))
11428 : : MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL;
11429 : 0 : tunnel->item.spec = tunnel;
11430 : 0 : tunnel->item.last = NULL;
11431 : 0 : tunnel->item.mask = NULL;
11432 : :
11433 : 0 : DRV_LOG(DEBUG, "port %u new pmd tunnel id=0x%x",
11434 : : dev->data->port_id, tunnel->tunnel_id);
11435 : :
11436 : 0 : return tunnel;
11437 : : }
11438 : :
11439 : : struct tunnel_db_get_tunnel_ctx {
11440 : : const struct rte_flow_tunnel *app_tunnel;
11441 : : struct mlx5_flow_tunnel *tunnel;
11442 : : };
11443 : :
11444 : 0 : static bool get_tunnel_match(struct rte_eth_dev *dev,
11445 : : struct mlx5_flow_tunnel *tunnel, const void *x)
11446 : : {
11447 : : const struct tunnel_db_get_tunnel_ctx *ctx = x;
11448 : :
11449 : : RTE_SET_USED(dev);
11450 : 0 : return !memcmp(ctx->app_tunnel, &tunnel->app_tunnel,
11451 : : sizeof(*ctx->app_tunnel));
11452 : : }
11453 : :
11454 : 0 : static void get_tunnel_hit(struct rte_eth_dev *dev,
11455 : : struct mlx5_flow_tunnel *tunnel, void *x)
11456 : : {
11457 : : /* called under tunnel spinlock protection */
11458 : : struct tunnel_db_get_tunnel_ctx *ctx = x;
11459 : :
11460 : : RTE_SET_USED(dev);
11461 : 0 : tunnel->refctn++;
11462 : 0 : ctx->tunnel = tunnel;
11463 : 0 : }
11464 : :
11465 : 0 : static void get_tunnel_miss(struct rte_eth_dev *dev, void *x)
11466 : : {
11467 : : /* called under tunnel spinlock protection */
11468 : : struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
11469 : : struct tunnel_db_get_tunnel_ctx *ctx = x;
11470 : :
11471 : 0 : rte_spinlock_unlock(&thub->sl);
11472 : 0 : ctx->tunnel = mlx5_flow_tunnel_allocate(dev, ctx->app_tunnel);
11473 : : rte_spinlock_lock(&thub->sl);
11474 [ # # ]: 0 : if (ctx->tunnel) {
11475 : 0 : ctx->tunnel->refctn = 1;
11476 [ # # ]: 0 : LIST_INSERT_HEAD(&thub->tunnels, ctx->tunnel, chain);
11477 : : }
11478 : 0 : }
11479 : :
11480 : :
11481 : : static int
11482 : 0 : mlx5_get_flow_tunnel(struct rte_eth_dev *dev,
11483 : : const struct rte_flow_tunnel *app_tunnel,
11484 : : struct mlx5_flow_tunnel **tunnel)
11485 : : {
11486 : 0 : struct tunnel_db_get_tunnel_ctx ctx = {
11487 : : .app_tunnel = app_tunnel,
11488 : : };
11489 : :
11490 : 0 : mlx5_access_tunnel_offload_db(dev, get_tunnel_match, get_tunnel_hit,
11491 : : get_tunnel_miss, &ctx, true);
11492 : 0 : *tunnel = ctx.tunnel;
11493 [ # # ]: 0 : return ctx.tunnel ? 0 : -ENOMEM;
11494 : : }
11495 : :
11496 : 0 : void mlx5_release_tunnel_hub(struct mlx5_dev_ctx_shared *sh, uint16_t port_id)
11497 : : {
11498 : 0 : struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
11499 : :
11500 [ # # ]: 0 : if (!thub)
11501 : : return;
11502 [ # # ]: 0 : if (!LIST_EMPTY(&thub->tunnels))
11503 : 0 : DRV_LOG(WARNING, "port %u tunnels present", port_id);
11504 : 0 : mlx5_hlist_destroy(thub->groups);
11505 : 0 : mlx5_free(thub);
11506 : : }
11507 : :
11508 : 0 : int mlx5_alloc_tunnel_hub(struct mlx5_dev_ctx_shared *sh)
11509 : : {
11510 : : int err;
11511 : : struct mlx5_flow_tunnel_hub *thub;
11512 : :
11513 : 0 : thub = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, sizeof(*thub),
11514 : : 0, SOCKET_ID_ANY);
11515 [ # # ]: 0 : if (!thub)
11516 : : return -ENOMEM;
11517 : 0 : LIST_INIT(&thub->tunnels);
11518 : : rte_spinlock_init(&thub->sl);
11519 : 0 : thub->groups = mlx5_hlist_create("flow groups", 64,
11520 : : false, true, sh,
11521 : : mlx5_flow_tunnel_grp2tbl_create_cb,
11522 : : mlx5_flow_tunnel_grp2tbl_match_cb,
11523 : : mlx5_flow_tunnel_grp2tbl_remove_cb,
11524 : : mlx5_flow_tunnel_grp2tbl_clone_cb,
11525 : : mlx5_flow_tunnel_grp2tbl_clone_free_cb);
11526 [ # # ]: 0 : if (!thub->groups) {
11527 : 0 : err = -rte_errno;
11528 : 0 : goto err;
11529 : : }
11530 : 0 : sh->tunnel_hub = thub;
11531 : :
11532 : 0 : return 0;
11533 : :
11534 : : err:
11535 : : if (thub->groups)
11536 : : mlx5_hlist_destroy(thub->groups);
11537 : : if (thub)
11538 : 0 : mlx5_free(thub);
11539 : 0 : return err;
11540 : : }
11541 : :
11542 : : static inline int
11543 : 0 : mlx5_flow_tunnel_validate(struct rte_eth_dev *dev,
11544 : : struct rte_flow_tunnel *tunnel,
11545 : : struct rte_flow_error *error)
11546 : : {
11547 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11548 : :
11549 [ # # ]: 0 : if (!priv->sh->config.dv_flow_en)
11550 : 0 : return rte_flow_error_set(error, ENOTSUP,
11551 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
11552 : : "flow DV interface is off");
11553 [ # # ]: 0 : if (!is_tunnel_offload_active(dev))
11554 : 0 : return rte_flow_error_set(error, ENOTSUP,
11555 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
11556 : : "tunnel offload was not activated, consider setting dv_xmeta_en=3");
11557 [ # # ]: 0 : if (!tunnel)
11558 : 0 : return rte_flow_error_set(error, EINVAL,
11559 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
11560 : : "no application tunnel");
11561 [ # # ]: 0 : switch (tunnel->type) {
11562 : 0 : default:
11563 : 0 : return rte_flow_error_set(error, EINVAL,
11564 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
11565 : : "unsupported tunnel type");
11566 : : case RTE_FLOW_ITEM_TYPE_VXLAN:
11567 : : case RTE_FLOW_ITEM_TYPE_GRE:
11568 : : case RTE_FLOW_ITEM_TYPE_NVGRE:
11569 : : case RTE_FLOW_ITEM_TYPE_GENEVE:
11570 : : break;
11571 : : }
11572 : : return 0;
11573 : : }
11574 : :
11575 : : static int
11576 : 0 : mlx5_flow_tunnel_decap_set(struct rte_eth_dev *dev,
11577 : : struct rte_flow_tunnel *app_tunnel,
11578 : : struct rte_flow_action **actions,
11579 : : uint32_t *num_of_actions,
11580 : : struct rte_flow_error *error)
11581 : : {
11582 : : struct mlx5_flow_tunnel *tunnel;
11583 : 0 : int ret = mlx5_flow_tunnel_validate(dev, app_tunnel, error);
11584 : :
11585 [ # # ]: 0 : if (ret)
11586 : : return ret;
11587 : 0 : ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
11588 [ # # ]: 0 : if (ret < 0) {
11589 : 0 : return rte_flow_error_set(error, ret,
11590 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
11591 : : "failed to initialize pmd tunnel");
11592 : : }
11593 : 0 : *actions = &tunnel->action;
11594 : 0 : *num_of_actions = 1;
11595 : 0 : return 0;
11596 : : }
11597 : :
11598 : : static int
11599 : 0 : mlx5_flow_tunnel_match(struct rte_eth_dev *dev,
11600 : : struct rte_flow_tunnel *app_tunnel,
11601 : : struct rte_flow_item **items,
11602 : : uint32_t *num_of_items,
11603 : : struct rte_flow_error *error)
11604 : : {
11605 : : struct mlx5_flow_tunnel *tunnel;
11606 : 0 : int ret = mlx5_flow_tunnel_validate(dev, app_tunnel, error);
11607 : :
11608 [ # # ]: 0 : if (ret)
11609 : : return ret;
11610 : 0 : ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
11611 [ # # ]: 0 : if (ret < 0) {
11612 : 0 : return rte_flow_error_set(error, ret,
11613 : : RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
11614 : : "failed to initialize pmd tunnel");
11615 : : }
11616 : 0 : *items = &tunnel->item;
11617 : 0 : *num_of_items = 1;
11618 : 0 : return 0;
11619 : : }
11620 : :
11621 : : struct tunnel_db_element_release_ctx {
11622 : : struct rte_flow_item *items;
11623 : : struct rte_flow_action *actions;
11624 : : uint32_t num_elements;
11625 : : struct rte_flow_error *error;
11626 : : int ret;
11627 : : };
11628 : :
11629 : : static bool
11630 : 0 : tunnel_element_release_match(struct rte_eth_dev *dev,
11631 : : struct mlx5_flow_tunnel *tunnel, const void *x)
11632 : : {
11633 : : const struct tunnel_db_element_release_ctx *ctx = x;
11634 : :
11635 : : RTE_SET_USED(dev);
11636 [ # # ]: 0 : if (ctx->num_elements != 1)
11637 : : return false;
11638 [ # # ]: 0 : else if (ctx->items)
11639 : 0 : return ctx->items == &tunnel->item;
11640 [ # # ]: 0 : else if (ctx->actions)
11641 : 0 : return ctx->actions == &tunnel->action;
11642 : :
11643 : : return false;
11644 : : }
11645 : :
11646 : : static void
11647 : 0 : tunnel_element_release_hit(struct rte_eth_dev *dev,
11648 : : struct mlx5_flow_tunnel *tunnel, void *x)
11649 : : {
11650 : : struct tunnel_db_element_release_ctx *ctx = x;
11651 : 0 : ctx->ret = 0;
11652 [ # # ]: 0 : if (!(rte_atomic_fetch_sub_explicit(&tunnel->refctn, 1, rte_memory_order_relaxed) - 1))
11653 : 0 : mlx5_flow_tunnel_free(dev, tunnel);
11654 : 0 : }
11655 : :
11656 : : static void
11657 : 0 : tunnel_element_release_miss(struct rte_eth_dev *dev, void *x)
11658 : : {
11659 : : struct tunnel_db_element_release_ctx *ctx = x;
11660 : : RTE_SET_USED(dev);
11661 : 0 : ctx->ret = rte_flow_error_set(ctx->error, EINVAL,
11662 : : RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
11663 : : "invalid argument");
11664 : 0 : }
11665 : :
11666 : : static int
11667 : 0 : mlx5_flow_tunnel_item_release(struct rte_eth_dev *dev,
11668 : : struct rte_flow_item *pmd_items,
11669 : : uint32_t num_items, struct rte_flow_error *err)
11670 : : {
11671 : 0 : struct tunnel_db_element_release_ctx ctx = {
11672 : : .items = pmd_items,
11673 : : .actions = NULL,
11674 : : .num_elements = num_items,
11675 : : .error = err,
11676 : : };
11677 : :
11678 : 0 : mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
11679 : : tunnel_element_release_hit,
11680 : : tunnel_element_release_miss, &ctx, false);
11681 : :
11682 : 0 : return ctx.ret;
11683 : : }
11684 : :
11685 : : static int
11686 : 0 : mlx5_flow_tunnel_action_release(struct rte_eth_dev *dev,
11687 : : struct rte_flow_action *pmd_actions,
11688 : : uint32_t num_actions, struct rte_flow_error *err)
11689 : : {
11690 : 0 : struct tunnel_db_element_release_ctx ctx = {
11691 : : .items = NULL,
11692 : : .actions = pmd_actions,
11693 : : .num_elements = num_actions,
11694 : : .error = err,
11695 : : };
11696 : :
11697 : 0 : mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
11698 : : tunnel_element_release_hit,
11699 : : tunnel_element_release_miss, &ctx, false);
11700 : :
11701 : 0 : return ctx.ret;
11702 : : }
11703 : :
11704 : : static int
11705 : 0 : mlx5_flow_tunnel_get_restore_info(struct rte_eth_dev *dev,
11706 : : struct rte_mbuf *m,
11707 : : struct rte_flow_restore_info *info,
11708 : : struct rte_flow_error *err)
11709 : : {
11710 : 0 : uint64_t ol_flags = m->ol_flags;
11711 : : const struct mlx5_flow_tbl_data_entry *tble;
11712 : : const uint64_t mask = RTE_MBUF_F_RX_FDIR | RTE_MBUF_F_RX_FDIR_ID;
11713 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11714 : :
11715 [ # # ]: 0 : if (priv->tunnel_enabled == 0)
11716 : 0 : goto err;
11717 [ # # ]: 0 : if ((ol_flags & mask) != mask)
11718 : 0 : goto err;
11719 : 0 : tble = tunnel_mark_decode(dev, m->hash.fdir.hi);
11720 [ # # ]: 0 : if (!tble) {
11721 : 0 : DRV_LOG(DEBUG, "port %u invalid miss tunnel mark %#x",
11722 : : dev->data->port_id, m->hash.fdir.hi);
11723 : 0 : goto err;
11724 : : }
11725 : : MLX5_ASSERT(tble->tunnel);
11726 : 0 : memcpy(&info->tunnel, &tble->tunnel->app_tunnel, sizeof(info->tunnel));
11727 : 0 : info->group_id = tble->group_id;
11728 : 0 : info->flags = RTE_FLOW_RESTORE_INFO_TUNNEL |
11729 : : RTE_FLOW_RESTORE_INFO_GROUP_ID |
11730 : : RTE_FLOW_RESTORE_INFO_ENCAPSULATED;
11731 : :
11732 : 0 : return 0;
11733 : :
11734 : 0 : err:
11735 : 0 : return rte_flow_error_set(err, EINVAL,
11736 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11737 : : "failed to get restore info");
11738 : : }
11739 : :
11740 : : #else /* HAVE_IBV_FLOW_DV_SUPPORT */
11741 : : static int
11742 : : mlx5_flow_tunnel_decap_set(__rte_unused struct rte_eth_dev *dev,
11743 : : __rte_unused struct rte_flow_tunnel *app_tunnel,
11744 : : __rte_unused struct rte_flow_action **actions,
11745 : : __rte_unused uint32_t *num_of_actions,
11746 : : __rte_unused struct rte_flow_error *error)
11747 : : {
11748 : : return -ENOTSUP;
11749 : : }
11750 : :
11751 : : static int
11752 : : mlx5_flow_tunnel_match(__rte_unused struct rte_eth_dev *dev,
11753 : : __rte_unused struct rte_flow_tunnel *app_tunnel,
11754 : : __rte_unused struct rte_flow_item **items,
11755 : : __rte_unused uint32_t *num_of_items,
11756 : : __rte_unused struct rte_flow_error *error)
11757 : : {
11758 : : return -ENOTSUP;
11759 : : }
11760 : :
11761 : : static int
11762 : : mlx5_flow_tunnel_item_release(__rte_unused struct rte_eth_dev *dev,
11763 : : __rte_unused struct rte_flow_item *pmd_items,
11764 : : __rte_unused uint32_t num_items,
11765 : : __rte_unused struct rte_flow_error *err)
11766 : : {
11767 : : return -ENOTSUP;
11768 : : }
11769 : :
11770 : : static int
11771 : : mlx5_flow_tunnel_action_release(__rte_unused struct rte_eth_dev *dev,
11772 : : __rte_unused struct rte_flow_action *pmd_action,
11773 : : __rte_unused uint32_t num_actions,
11774 : : __rte_unused struct rte_flow_error *err)
11775 : : {
11776 : : return -ENOTSUP;
11777 : : }
11778 : :
11779 : : static int
11780 : : mlx5_flow_tunnel_get_restore_info(__rte_unused struct rte_eth_dev *dev,
11781 : : __rte_unused struct rte_mbuf *m,
11782 : : __rte_unused struct rte_flow_restore_info *i,
11783 : : __rte_unused struct rte_flow_error *err)
11784 : : {
11785 : : return -ENOTSUP;
11786 : : }
11787 : :
11788 : : static int
11789 : : flow_tunnel_add_default_miss(__rte_unused struct rte_eth_dev *dev,
11790 : : __rte_unused struct rte_flow *flow,
11791 : : __rte_unused const struct rte_flow_attr *attr,
11792 : : __rte_unused const struct rte_flow_action *actions,
11793 : : __rte_unused uint32_t flow_idx,
11794 : : __rte_unused const struct mlx5_flow_tunnel *tunnel,
11795 : : __rte_unused struct tunnel_default_miss_ctx *ctx,
11796 : : __rte_unused struct rte_flow_error *error)
11797 : : {
11798 : : return -ENOTSUP;
11799 : : }
11800 : :
11801 : : static struct mlx5_flow_tunnel *
11802 : : mlx5_find_tunnel_id(__rte_unused struct rte_eth_dev *dev,
11803 : : __rte_unused uint32_t id)
11804 : : {
11805 : : return NULL;
11806 : : }
11807 : :
11808 : : static void
11809 : : mlx5_flow_tunnel_free(__rte_unused struct rte_eth_dev *dev,
11810 : : __rte_unused struct mlx5_flow_tunnel *tunnel)
11811 : : {
11812 : : }
11813 : :
11814 : : static uint32_t
11815 : : tunnel_flow_group_to_flow_table(__rte_unused struct rte_eth_dev *dev,
11816 : : __rte_unused const struct mlx5_flow_tunnel *t,
11817 : : __rte_unused uint32_t group,
11818 : : __rte_unused uint32_t *table,
11819 : : struct rte_flow_error *error)
11820 : : {
11821 : : return rte_flow_error_set(error, ENOTSUP,
11822 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11823 : : "tunnel offload requires DV support");
11824 : : }
11825 : :
11826 : : void
11827 : : mlx5_release_tunnel_hub(__rte_unused struct mlx5_dev_ctx_shared *sh,
11828 : : __rte_unused uint16_t port_id)
11829 : : {
11830 : : }
11831 : : #endif /* HAVE_IBV_FLOW_DV_SUPPORT */
11832 : :
11833 : : /* Flex flow item API */
11834 : : static struct rte_flow_item_flex_handle *
11835 : 0 : mlx5_flow_flex_item_create(struct rte_eth_dev *dev,
11836 : : const struct rte_flow_item_flex_conf *conf,
11837 : : struct rte_flow_error *error)
11838 : : {
11839 : : static const char err_msg[] = "flex item creation unsupported";
11840 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
11841 : : struct rte_flow_attr attr = { .transfer = 0 };
11842 : 0 : const struct mlx5_flow_driver_ops *fops =
11843 : : flow_get_drv_ops(flow_get_drv_type(dev, &attr));
11844 : :
11845 [ # # ]: 0 : if (!priv->pci_dev) {
11846 : 0 : rte_flow_error_set(error, ENOTSUP,
11847 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11848 : : "create flex item on PF only");
11849 : 0 : return NULL;
11850 : : }
11851 [ # # ]: 0 : switch (priv->pci_dev->id.device_id) {
11852 : : case PCI_DEVICE_ID_MELLANOX_BLUEFIELD2:
11853 : : case PCI_DEVICE_ID_MELLANOX_BLUEFIELD3:
11854 : : break;
11855 : 0 : default:
11856 : 0 : rte_flow_error_set(error, ENOTSUP,
11857 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11858 : : "flex item available on BlueField ports only");
11859 : 0 : return NULL;
11860 : : }
11861 [ # # ]: 0 : if (!fops->item_create) {
11862 : 0 : DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
11863 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
11864 : : NULL, err_msg);
11865 : 0 : return NULL;
11866 : : }
11867 : 0 : return fops->item_create(dev, conf, error);
11868 : : }
11869 : :
11870 : : static int
11871 [ # # ]: 0 : mlx5_flow_flex_item_release(struct rte_eth_dev *dev,
11872 : : const struct rte_flow_item_flex_handle *handle,
11873 : : struct rte_flow_error *error)
11874 : : {
11875 : : static const char err_msg[] = "flex item release unsupported";
11876 : : struct rte_flow_attr attr = { .transfer = 0 };
11877 : 0 : const struct mlx5_flow_driver_ops *fops =
11878 : : flow_get_drv_ops(flow_get_drv_type(dev, &attr));
11879 : :
11880 [ # # ]: 0 : if (!fops->item_release) {
11881 : 0 : DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
11882 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
11883 : : NULL, err_msg);
11884 : 0 : return -rte_errno;
11885 : : }
11886 : 0 : return fops->item_release(dev, handle, error);
11887 : : }
11888 : :
11889 : : static void
11890 : 0 : mlx5_dbg__print_pattern(const struct rte_flow_item *item)
11891 : : {
11892 : : int ret;
11893 : : struct rte_flow_error error;
11894 : :
11895 [ # # ]: 0 : for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
11896 : : char *item_name;
11897 : 0 : ret = rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_NAME_PTR, &item_name,
11898 : : sizeof(item_name),
11899 : 0 : (void *)(uintptr_t)item->type, &error);
11900 [ # # ]: 0 : if (ret > 0)
11901 : 0 : printf("%s ", item_name);
11902 : : else
11903 : 0 : printf("%d\n", (int)item->type);
11904 : : }
11905 : : printf("END\n");
11906 : 0 : }
11907 : :
11908 : : static int
11909 : : mlx5_flow_is_std_vxlan_port(const struct rte_flow_item *udp_item)
11910 : : {
11911 : 0 : const struct rte_flow_item_udp *spec = udp_item->spec;
11912 : 0 : const struct rte_flow_item_udp *mask = udp_item->mask;
11913 : : uint16_t udp_dport = 0;
11914 : :
11915 : 0 : if (spec != NULL) {
11916 [ # # ]: 0 : if (!mask)
11917 : : mask = &rte_flow_item_udp_mask;
11918 [ # # ]: 0 : udp_dport = rte_be_to_cpu_16(spec->hdr.dst_port &
11919 : : mask->hdr.dst_port);
11920 : : }
11921 : 0 : return (!udp_dport || udp_dport == MLX5_UDP_PORT_VXLAN);
11922 : : }
11923 : :
11924 : : static const struct mlx5_flow_expand_node *
11925 : 0 : mlx5_flow_expand_rss_adjust_node(const struct rte_flow_item *pattern,
11926 : : unsigned int item_idx,
11927 : : const struct mlx5_flow_expand_node graph[],
11928 : : const struct mlx5_flow_expand_node *node)
11929 : : {
11930 : 0 : const struct rte_flow_item *item = pattern + item_idx, *prev_item;
11931 : :
11932 [ # # # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_VXLAN &&
11933 : 0 : node != NULL &&
11934 [ # # ]: 0 : node->type == RTE_FLOW_ITEM_TYPE_VXLAN) {
11935 : : /*
11936 : : * The expansion node is VXLAN and it is also the last
11937 : : * expandable item in the pattern, so need to continue
11938 : : * expansion of the inner tunnel.
11939 : : */
11940 : : MLX5_ASSERT(item_idx > 0);
11941 [ # # ]: 0 : prev_item = pattern + item_idx - 1;
11942 : : MLX5_ASSERT(prev_item->type == RTE_FLOW_ITEM_TYPE_UDP);
11943 [ # # ]: 0 : if (mlx5_flow_is_std_vxlan_port(prev_item))
11944 : 0 : return &graph[MLX5_EXPANSION_STD_VXLAN];
11945 : 0 : return &graph[MLX5_EXPANSION_L3_VXLAN];
11946 : : }
11947 : : return node;
11948 : : }
11949 : :
11950 : : /* Map of Verbs to Flow priority with 8 Verbs priorities. */
11951 : : static const uint32_t priority_map_3[][MLX5_PRIORITY_MAP_MAX] = {
11952 : : { 0, 1, 2 }, { 2, 3, 4 }, { 5, 6, 7 },
11953 : : };
11954 : :
11955 : : /* Map of Verbs to Flow priority with 16 Verbs priorities. */
11956 : : static const uint32_t priority_map_5[][MLX5_PRIORITY_MAP_MAX] = {
11957 : : { 0, 1, 2 }, { 3, 4, 5 }, { 6, 7, 8 },
11958 : : { 9, 10, 11 }, { 12, 13, 14 },
11959 : : };
11960 : :
11961 : : /**
11962 : : * Discover the number of available flow priorities.
11963 : : *
11964 : : * @param dev
11965 : : * Ethernet device.
11966 : : *
11967 : : * @return
11968 : : * On success, number of available flow priorities.
11969 : : * On failure, a negative errno-style code and rte_errno is set.
11970 : : */
11971 : : int
11972 : 0 : mlx5_flow_discover_priorities(struct rte_eth_dev *dev)
11973 : : {
11974 : : static const uint16_t vprio[] = {8, 16};
11975 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
11976 : : const struct mlx5_flow_driver_ops *fops;
11977 : : enum mlx5_flow_drv_type type;
11978 : : int ret;
11979 : :
11980 : : type = mlx5_flow_os_get_type();
11981 : : if (type == MLX5_FLOW_TYPE_MAX) {
11982 : : type = MLX5_FLOW_TYPE_VERBS;
11983 [ # # # # ]: 0 : if (priv->sh->cdev->config.devx && priv->sh->config.dv_flow_en)
11984 : : type = MLX5_FLOW_TYPE_DV;
11985 : : }
11986 : 0 : fops = flow_get_drv_ops(type);
11987 [ # # ]: 0 : if (fops->discover_priorities == NULL) {
11988 : 0 : DRV_LOG(ERR, "Priority discovery not supported");
11989 : 0 : rte_errno = ENOTSUP;
11990 : 0 : return -rte_errno;
11991 : : }
11992 : 0 : ret = fops->discover_priorities(dev, vprio, RTE_DIM(vprio));
11993 [ # # ]: 0 : if (ret < 0)
11994 : : return ret;
11995 [ # # # ]: 0 : switch (ret) {
11996 : : case 8:
11997 : : ret = RTE_DIM(priority_map_3);
11998 : : break;
11999 : 0 : case 16:
12000 : : ret = RTE_DIM(priority_map_5);
12001 : 0 : break;
12002 : 0 : default:
12003 : 0 : rte_errno = ENOTSUP;
12004 : 0 : DRV_LOG(ERR,
12005 : : "port %u maximum priority: %d expected 8/16",
12006 : : dev->data->port_id, ret);
12007 : 0 : return -rte_errno;
12008 : : }
12009 : 0 : DRV_LOG(INFO, "port %u supported flow priorities:"
12010 : : " 0-%d for ingress or egress root table,"
12011 : : " 0-%d for non-root table or transfer root table.",
12012 : : dev->data->port_id, ret - 2,
12013 : : MLX5_NON_ROOT_FLOW_MAX_PRIO - 1);
12014 : 0 : return ret;
12015 : : }
12016 : :
12017 : : /**
12018 : : * Adjust flow priority based on the highest layer and the request priority.
12019 : : *
12020 : : * @param[in] dev
12021 : : * Pointer to the Ethernet device structure.
12022 : : * @param[in] priority
12023 : : * The rule base priority.
12024 : : * @param[in] subpriority
12025 : : * The priority based on the items.
12026 : : *
12027 : : * @return
12028 : : * The new priority.
12029 : : */
12030 : : uint32_t
12031 : 0 : mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
12032 : : uint32_t subpriority)
12033 : : {
12034 : : uint32_t res = 0;
12035 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12036 : :
12037 [ # # # ]: 0 : switch (priv->sh->flow_max_priority) {
12038 : 0 : case RTE_DIM(priority_map_3):
12039 : 0 : res = priority_map_3[priority][subpriority];
12040 : 0 : break;
12041 : 0 : case RTE_DIM(priority_map_5):
12042 : 0 : res = priority_map_5[priority][subpriority];
12043 : 0 : break;
12044 : : }
12045 : 0 : return res;
12046 : : }
12047 : :
12048 : : /**
12049 : : * Get the priority for sending traffic to kernel table.
12050 : : *
12051 : : * @param[in] dev
12052 : : * Pointer to the Ethernet device structure.
12053 : : *
12054 : : * @return
12055 : : * On success: the value of priority for sending traffic to kernel table
12056 : : * On failure: -1
12057 : : */
12058 : : uint32_t
12059 : 0 : mlx5_get_send_to_kernel_priority(struct rte_eth_dev *dev)
12060 : : {
12061 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12062 : : uint32_t res;
12063 : :
12064 [ # # # ]: 0 : switch (priv->sh->flow_max_priority) {
12065 : : case RTE_DIM(priority_map_5):
12066 : : res = 15;
12067 : : break;
12068 : 0 : case RTE_DIM(priority_map_3):
12069 : : res = 7;
12070 : 0 : break;
12071 : 0 : default:
12072 : 0 : DRV_LOG(ERR,
12073 : : "port %u maximum priority: %d expected 8/16",
12074 : : dev->data->port_id, priv->sh->flow_max_priority);
12075 : : res = (uint32_t)-1;
12076 : : }
12077 : 0 : return res;
12078 : : }
12079 : :
12080 : : /**
12081 : : * Get the E-Switch Manager vport id.
12082 : : *
12083 : : * @param[in] dev
12084 : : * Pointer to the Ethernet device structure.
12085 : : *
12086 : : * @return
12087 : : * The vport id.
12088 : : */
12089 : 0 : int16_t mlx5_flow_get_esw_manager_vport_id(struct rte_eth_dev *dev)
12090 : : {
12091 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12092 : 0 : struct mlx5_common_device *cdev = priv->sh->cdev;
12093 : :
12094 : : /* New FW exposes E-Switch Manager vport ID, can use it directly. */
12095 [ # # ]: 0 : if (cdev->config.hca_attr.esw_mgr_vport_id_valid)
12096 : 0 : return (int16_t)cdev->config.hca_attr.esw_mgr_vport_id;
12097 : :
12098 [ # # ]: 0 : if (priv->pci_dev == NULL)
12099 : : return 0;
12100 [ # # ]: 0 : switch (priv->pci_dev->id.device_id) {
12101 : : case PCI_DEVICE_ID_MELLANOX_BLUEFIELD:
12102 : : case PCI_DEVICE_ID_MELLANOX_BLUEFIELD2:
12103 : : case PCI_DEVICE_ID_MELLANOX_BLUEFIELD3:
12104 : : /*
12105 : : * In old FW which doesn't expose the E-Switch Manager vport ID in the capability,
12106 : : * only the BF embedded CPUs control the E-Switch Manager port. Hence,
12107 : : * ECPF vport ID is selected and not the host port (0) in any BF case.
12108 : : */
12109 : : return (int16_t)MLX5_ECPF_VPORT_ID;
12110 : 0 : default:
12111 : 0 : return MLX5_PF_VPORT_ID;
12112 : : }
12113 : : }
12114 : :
12115 : : /**
12116 : : * Parse item to get the vport id.
12117 : : *
12118 : : * @param[in] dev
12119 : : * Pointer to the Ethernet device structure.
12120 : : * @param[in] item
12121 : : * The src port id match item.
12122 : : * @param[out] vport_id
12123 : : * Pointer to put the vport id.
12124 : : * @param[out] all_ports
12125 : : * Indicate if the item matches all ports.
12126 : : * @param[out] error
12127 : : * Pointer to error structure.
12128 : : *
12129 : : * @return
12130 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
12131 : : */
12132 : 0 : int mlx5_flow_get_item_vport_id(struct rte_eth_dev *dev,
12133 : : const struct rte_flow_item *item,
12134 : : uint16_t *vport_id,
12135 : : bool *all_ports,
12136 : : struct rte_flow_error *error)
12137 : : {
12138 : : struct mlx5_priv *port_priv;
12139 : : const struct rte_flow_item_port_id *pid_v = NULL;
12140 : : const struct rte_flow_item_ethdev *dev_v = NULL;
12141 : : uint32_t esw_mgr_port;
12142 : : uint32_t src_port;
12143 : :
12144 [ # # ]: 0 : if (all_ports)
12145 : 0 : *all_ports = false;
12146 [ # # # # ]: 0 : switch (item->type) {
12147 : 0 : case RTE_FLOW_ITEM_TYPE_PORT_ID:
12148 : 0 : pid_v = item->spec;
12149 [ # # ]: 0 : if (!pid_v)
12150 : : return 0;
12151 : 0 : src_port = pid_v->id;
12152 : : esw_mgr_port = MLX5_PORT_ESW_MGR;
12153 : 0 : break;
12154 : 0 : case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
12155 : 0 : dev_v = item->spec;
12156 [ # # ]: 0 : if (!dev_v) {
12157 [ # # ]: 0 : if (all_ports)
12158 : 0 : *all_ports = true;
12159 : 0 : return 0;
12160 : : }
12161 : 0 : src_port = dev_v->port_id;
12162 : : esw_mgr_port = MLX5_REPRESENTED_PORT_ESW_MGR;
12163 : 0 : break;
12164 : : case RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR:
12165 : : src_port = MLX5_REPRESENTED_PORT_ESW_MGR;
12166 : : esw_mgr_port = MLX5_REPRESENTED_PORT_ESW_MGR;
12167 : : break;
12168 : 0 : default:
12169 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
12170 : : NULL, "Incorrect item type.");
12171 : : }
12172 [ # # ]: 0 : if (src_port == esw_mgr_port) {
12173 : 0 : *vport_id = mlx5_flow_get_esw_manager_vport_id(dev);
12174 : : } else {
12175 : 0 : port_priv = mlx5_port_to_eswitch_info(src_port, false);
12176 [ # # ]: 0 : if (!port_priv)
12177 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
12178 : : NULL, "Failed to get port info.");
12179 : 0 : *vport_id = port_priv->representor_id;
12180 : : }
12181 : :
12182 : : return 0;
12183 : : }
12184 : :
12185 : : int
12186 : 0 : mlx5_flow_pick_transfer_proxy(struct rte_eth_dev *dev,
12187 : : uint16_t *proxy_port_id,
12188 : : struct rte_flow_error *error)
12189 : : {
12190 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
12191 : : uint16_t port_id;
12192 : :
12193 [ # # ]: 0 : if (!priv->sh->config.dv_esw_en)
12194 : 0 : return rte_flow_error_set(error, EINVAL,
12195 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12196 : : NULL,
12197 : : "unable to provide a proxy port"
12198 : : " without E-Switch configured");
12199 [ # # ]: 0 : if (!priv->master && !priv->representor)
12200 : 0 : return rte_flow_error_set(error, EINVAL,
12201 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12202 : : NULL,
12203 : : "unable to provide a proxy port"
12204 : : " for port which is not a master"
12205 : : " or a representor port");
12206 [ # # ]: 0 : if (priv->master) {
12207 : 0 : *proxy_port_id = dev->data->port_id;
12208 : 0 : return 0;
12209 : : }
12210 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port_id, dev->device) {
12211 : 0 : const struct rte_eth_dev *port_dev = &rte_eth_devices[port_id];
12212 : 0 : const struct mlx5_priv *port_priv = port_dev->data->dev_private;
12213 : :
12214 [ # # ]: 0 : if (port_priv->master &&
12215 [ # # ]: 0 : port_priv->domain_id == priv->domain_id) {
12216 : 0 : *proxy_port_id = port_id;
12217 : 0 : return 0;
12218 : : }
12219 : : }
12220 : 0 : return rte_flow_error_set(error, ENODEV,
12221 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12222 : : NULL, "unable to find a proxy port");
12223 : : }
12224 : :
12225 : : /**
12226 : : * Discover IPv6 traffic class ID support in rdma-core and firmware.
12227 : : *
12228 : : * @param dev
12229 : : * Ethernet device.
12230 : : *
12231 : : * @return
12232 : : * 0, rdma-core is good to work with firmware.
12233 : : * -EOPNOTSUPP, rdma-core could not work with new IPv6 TC ID.
12234 : : */
12235 : : int
12236 : 0 : mlx5_flow_discover_ipv6_tc_support(struct rte_eth_dev *dev)
12237 : : {
12238 : : struct rte_flow_action_set_dscp set_dscp;
12239 : : struct rte_flow_attr attr;
12240 : : struct rte_flow_action actions[2];
12241 : : struct rte_flow_item items[3];
12242 : : struct rte_flow_error error;
12243 : : uint32_t flow_idx;
12244 : :
12245 : : memset(&attr, 0, sizeof(attr));
12246 : : memset(actions, 0, sizeof(actions));
12247 : : memset(items, 0, sizeof(items));
12248 : 0 : attr.group = 1;
12249 : 0 : attr.egress = 1;
12250 : 0 : items[0].type = RTE_FLOW_ITEM_TYPE_ETH;
12251 : 0 : items[1].type = RTE_FLOW_ITEM_TYPE_IPV6;
12252 : : items[2].type = RTE_FLOW_ITEM_TYPE_END;
12253 : : /* Random value */
12254 : 0 : set_dscp.dscp = 9;
12255 : 0 : actions[0].type = RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP;
12256 : 0 : actions[0].conf = &set_dscp;
12257 : : actions[1].type = RTE_FLOW_ACTION_TYPE_END;
12258 : :
12259 : 0 : flow_idx = mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_GEN, &attr, items,
12260 : : actions, true, &error);
12261 [ # # ]: 0 : if (!flow_idx)
12262 : : return -EOPNOTSUPP;
12263 : :
12264 : 0 : mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN, flow_idx);
12265 : 0 : return 0;
12266 : : }
12267 : :
12268 : : void *
12269 : 0 : rte_pmd_mlx5_create_geneve_tlv_parser(uint16_t port_id,
12270 : : const struct rte_pmd_mlx5_geneve_tlv tlv_list[],
12271 : : uint8_t nb_options)
12272 : : {
12273 : : #ifdef HAVE_MLX5_HWS_SUPPORT
12274 : 0 : return mlx5_geneve_tlv_parser_create(port_id, tlv_list, nb_options);
12275 : : #else
12276 : : (void)port_id;
12277 : : (void)tlv_list;
12278 : : (void)nb_options;
12279 : : DRV_LOG(ERR, "%s is not supported.", __func__);
12280 : : rte_errno = ENOTSUP;
12281 : : return NULL;
12282 : : #endif
12283 : : }
12284 : :
12285 : : int
12286 : 0 : rte_pmd_mlx5_destroy_geneve_tlv_parser(void *handle)
12287 : : {
12288 : : #ifdef HAVE_MLX5_HWS_SUPPORT
12289 : 0 : return mlx5_geneve_tlv_parser_destroy(handle);
12290 : : #else
12291 : : (void)handle;
12292 : : DRV_LOG(ERR, "%s is not supported.", __func__);
12293 : : rte_errno = ENOTSUP;
12294 : : return -rte_errno;
12295 : : #endif
12296 : : }
12297 : :
12298 : : bool
12299 : 0 : mlx5_ctrl_flow_uc_dmac_exists(struct rte_eth_dev *dev, const struct rte_ether_addr *addr)
12300 : : {
12301 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12302 : : struct mlx5_ctrl_flow_entry *entry;
12303 : : bool exists = false;
12304 : :
12305 [ # # ]: 0 : LIST_FOREACH(entry, &priv->hw_ctrl_flows, next) {
12306 [ # # # # ]: 0 : if (entry->info.type == MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC &&
12307 : : rte_is_same_ether_addr(addr, &entry->info.uc.dmac)) {
12308 : : exists = true;
12309 : : break;
12310 : : }
12311 : : }
12312 : 0 : return exists;
12313 : : }
12314 : :
12315 : : bool
12316 : 0 : mlx5_ctrl_flow_uc_dmac_vlan_exists(struct rte_eth_dev *dev,
12317 : : const struct rte_ether_addr *addr,
12318 : : const uint16_t vid)
12319 : : {
12320 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12321 : : struct mlx5_ctrl_flow_entry *entry;
12322 : : bool exists = false;
12323 : :
12324 [ # # ]: 0 : LIST_FOREACH(entry, &priv->hw_ctrl_flows, next) {
12325 [ # # # # ]: 0 : if (entry->info.type == MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC_VLAN &&
12326 : 0 : rte_is_same_ether_addr(addr, &entry->info.uc.dmac) &&
12327 [ # # ]: 0 : vid == entry->info.uc.vlan) {
12328 : : exists = true;
12329 : : break;
12330 : : }
12331 : : }
12332 : 0 : return exists;
12333 : : }
|