Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright 2016 6WIND S.A.
3 : : * Copyright 2016 Mellanox Technologies, Ltd
4 : : */
5 : :
6 : : #include <stdalign.h>
7 : : #include <stdint.h>
8 : : #include <string.h>
9 : : #include <stdbool.h>
10 : : #include <sys/queue.h>
11 : :
12 : : #include <eal_export.h>
13 : : #include <rte_common.h>
14 : : #include <rte_ether.h>
15 : : #include <ethdev_driver.h>
16 : : #include <rte_eal_paging.h>
17 : : #include <rte_flow.h>
18 : : #include <rte_cycles.h>
19 : : #include <rte_flow_driver.h>
20 : : #include <rte_malloc.h>
21 : : #include <rte_ip.h>
22 : :
23 : : #include <mlx5_glue.h>
24 : : #include <mlx5_devx_cmds.h>
25 : : #include <mlx5_prm.h>
26 : : #include <mlx5_malloc.h>
27 : :
28 : : #include "mlx5_defs.h"
29 : : #include "mlx5.h"
30 : : #include "mlx5_flow.h"
31 : : #include "mlx5_flow_os.h"
32 : : #include "mlx5_rx.h"
33 : : #include "mlx5_tx.h"
34 : : #include "mlx5_common_os.h"
35 : : #include "rte_pmd_mlx5.h"
36 : :
37 : : const uint64_t mlx5_rss_hash_fields[] = {
38 : : [MLX5_RSS_HASH_IDX_IPV4] = MLX5_RSS_HASH_IPV4,
39 : : [MLX5_RSS_HASH_IDX_IPV4_TCP] = MLX5_RSS_HASH_IPV4_TCP,
40 : : [MLX5_RSS_HASH_IDX_IPV4_UDP] = MLX5_RSS_HASH_IPV4_UDP,
41 : : [MLX5_RSS_HASH_IDX_IPV4_ESP] = MLX5_RSS_HASH_IPV4_ESP,
42 : : [MLX5_RSS_HASH_IDX_IPV6] = MLX5_RSS_HASH_IPV6,
43 : : [MLX5_RSS_HASH_IDX_IPV6_TCP] = MLX5_RSS_HASH_IPV6_TCP,
44 : : [MLX5_RSS_HASH_IDX_IPV6_UDP] = MLX5_RSS_HASH_IPV6_UDP,
45 : : [MLX5_RSS_HASH_IDX_IPV6_ESP] = MLX5_RSS_HASH_IPV6_ESP,
46 : : [MLX5_RSS_HASH_IDX_TCP] = MLX5_TCP_IBV_RX_HASH,
47 : : [MLX5_RSS_HASH_IDX_UDP] = MLX5_UDP_IBV_RX_HASH,
48 : : [MLX5_RSS_HASH_IDX_ESP_SPI] = MLX5_RSS_HASH_ESP_SPI,
49 : : [MLX5_RSS_HASH_IDX_NONE] = MLX5_RSS_HASH_NONE,
50 : : };
51 : :
52 : : /*
53 : : * Shared array for quick translation between port_id and vport mask/values
54 : : * used for HWS rules.
55 : : */
56 : : struct flow_hw_port_info mlx5_flow_hw_port_infos[RTE_MAX_ETHPORTS];
57 : :
58 : : struct tunnel_default_miss_ctx {
59 : : uint16_t *queue;
60 : : __extension__
61 : : union {
62 : : struct rte_flow_action_rss action_rss;
63 : : struct rte_flow_action_queue miss_queue;
64 : : struct rte_flow_action_jump miss_jump;
65 : : uint8_t raw[0];
66 : : };
67 : : };
68 : :
69 : : void
70 : 0 : mlx5_indirect_list_handles_release(struct rte_eth_dev *dev)
71 : : {
72 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
73 : : #ifdef HAVE_MLX5_HWS_SUPPORT
74 : : struct rte_flow_error error;
75 : : #endif
76 : :
77 [ # # ]: 0 : while (!LIST_EMPTY(&priv->indirect_list_head)) {
78 : : struct mlx5_indirect_list *e =
79 : : LIST_FIRST(&priv->indirect_list_head);
80 : :
81 [ # # ]: 0 : LIST_REMOVE(e, entry);
82 [ # # # # ]: 0 : switch (e->type) {
83 : : #ifdef HAVE_MLX5_HWS_SUPPORT
84 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_MIRROR:
85 : 0 : mlx5_hw_mirror_destroy(dev, (struct mlx5_mirror *)e);
86 : 0 : break;
87 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_LEGACY:
88 : 0 : mlx5_destroy_legacy_indirect(dev, e);
89 : 0 : break;
90 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_REFORMAT:
91 : 0 : mlx5_reformat_action_destroy(dev,
92 : : (struct rte_flow_action_list_handle *)e, &error);
93 : 0 : break;
94 : : #endif
95 : 0 : default:
96 : 0 : DRV_LOG(ERR, "invalid indirect list type");
97 : : MLX5_ASSERT(false);
98 : 0 : break;
99 : : }
100 : : }
101 : 0 : }
102 : :
103 : : static int
104 : : flow_tunnel_add_default_miss(struct rte_eth_dev *dev,
105 : : struct rte_flow *flow,
106 : : const struct rte_flow_attr *attr,
107 : : const struct rte_flow_action *app_actions,
108 : : uint32_t flow_idx,
109 : : const struct mlx5_flow_tunnel *tunnel,
110 : : struct tunnel_default_miss_ctx *ctx,
111 : : struct rte_flow_error *error);
112 : : static struct mlx5_flow_tunnel *
113 : : mlx5_find_tunnel_id(struct rte_eth_dev *dev, uint32_t id);
114 : : static void
115 : : mlx5_flow_tunnel_free(struct rte_eth_dev *dev, struct mlx5_flow_tunnel *tunnel);
116 : : static uint32_t
117 : : tunnel_flow_group_to_flow_table(struct rte_eth_dev *dev,
118 : : const struct mlx5_flow_tunnel *tunnel,
119 : : uint32_t group, uint32_t *table,
120 : : struct rte_flow_error *error);
121 : :
122 : : /** Device flow drivers. */
123 : : extern const struct mlx5_flow_driver_ops mlx5_flow_verbs_drv_ops;
124 : :
125 : : const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops;
126 : :
127 : : const struct mlx5_flow_driver_ops *flow_drv_ops[] = {
128 : : [MLX5_FLOW_TYPE_MIN] = &mlx5_flow_null_drv_ops,
129 : : #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
130 : : [MLX5_FLOW_TYPE_DV] = &mlx5_flow_dv_drv_ops,
131 : : #endif
132 : : #ifdef HAVE_MLX5_HWS_SUPPORT
133 : : [MLX5_FLOW_TYPE_HW] = &mlx5_flow_hw_drv_ops,
134 : : #endif
135 : : [MLX5_FLOW_TYPE_VERBS] = &mlx5_flow_verbs_drv_ops,
136 : : [MLX5_FLOW_TYPE_MAX] = &mlx5_flow_null_drv_ops
137 : : };
138 : :
139 : : /** Helper macro to build input graph for mlx5_flow_expand_rss(). */
140 : : #define MLX5_FLOW_EXPAND_RSS_NEXT(...) \
141 : : (const int []){ \
142 : : __VA_ARGS__, 0, \
143 : : }
144 : :
145 : : /** Node object of input graph for mlx5_flow_expand_rss(). */
146 : : struct mlx5_flow_expand_node {
147 : : const int *const next;
148 : : /**<
149 : : * List of next node indexes. Index 0 is interpreted as a terminator.
150 : : */
151 : : const enum rte_flow_item_type type;
152 : : /**< Pattern item type of current node. */
153 : : uint64_t rss_types;
154 : : /**<
155 : : * RSS types bit-field associated with this node
156 : : * (see RTE_ETH_RSS_* definitions).
157 : : */
158 : : uint64_t node_flags;
159 : : /**<
160 : : * Bit-fields that define how the node is used in the expansion.
161 : : * (see MLX5_EXPANSION_NODE_* definitions).
162 : : */
163 : : };
164 : :
165 : : /** Keep same format with mlx5_flow_expand_rss to share the buffer for expansion. */
166 : : struct mlx5_flow_expand_sqn {
167 : : uint32_t entries; /** Number of entries */
168 : : struct {
169 : : struct rte_flow_item *pattern; /**< Expanded pattern array. */
170 : : uint32_t priority; /**< Priority offset for each expansion. */
171 : : } entry[];
172 : : };
173 : :
174 : : /* Optional expand field. The expansion alg will not go deeper. */
175 : : #define MLX5_EXPANSION_NODE_OPTIONAL (UINT64_C(1) << 0)
176 : :
177 : : /* The node is not added implicitly as expansion to the flow pattern.
178 : : * If the node type does not match the flow pattern item type, the
179 : : * expansion alg will go deeper to its next items.
180 : : * In the current implementation, the list of next nodes indexes can
181 : : * have up to one node with this flag set and it has to be the last
182 : : * node index (before the list terminator).
183 : : */
184 : : #define MLX5_EXPANSION_NODE_EXPLICIT (UINT64_C(1) << 1)
185 : :
186 : : /** Object returned by mlx5_flow_expand_rss(). */
187 : : struct mlx5_flow_expand_rss {
188 : : uint32_t entries;
189 : : /**< Number of entries @p patterns and @p priorities. */
190 : : struct {
191 : : struct rte_flow_item *pattern; /**< Expanded pattern array. */
192 : : uint32_t priority; /**< Priority offset for each expansion. */
193 : : } entry[];
194 : : };
195 : :
196 : : static void
197 : : mlx5_dbg__print_pattern(const struct rte_flow_item *item);
198 : :
199 : : static const struct mlx5_flow_expand_node *
200 : : mlx5_flow_expand_rss_adjust_node(const struct rte_flow_item *pattern,
201 : : unsigned int item_idx,
202 : : const struct mlx5_flow_expand_node graph[],
203 : : const struct mlx5_flow_expand_node *node);
204 : :
205 : : static __rte_always_inline int
206 : : mlx5_need_cache_flow(const struct mlx5_priv *priv,
207 : : const struct rte_flow_attr *attr)
208 : : {
209 [ # # # # : 0 : return priv->isolated && priv->sh->config.dv_flow_en == 1 &&
# # # # ]
210 [ # # # # ]: 0 : (attr ? !attr->group : true) &&
211 [ # # # # : 0 : priv->mode_info.mode == RTE_PMD_MLX5_FLOW_ENGINE_MODE_STANDBY &&
# # # # #
# # # # #
# # ]
212 [ # # # # : 0 : (!priv->sh->config.dv_esw_en || !priv->sh->config.fdb_def_rule);
# # # # ]
213 : : }
214 : :
215 : : static bool
216 : 0 : mlx5_flow_is_rss_expandable_item(const struct rte_flow_item *item)
217 : : {
218 [ # # ]: 0 : switch (item->type) {
219 : : case RTE_FLOW_ITEM_TYPE_ETH:
220 : : case RTE_FLOW_ITEM_TYPE_VLAN:
221 : : case RTE_FLOW_ITEM_TYPE_IPV4:
222 : : case RTE_FLOW_ITEM_TYPE_IPV6:
223 : : case RTE_FLOW_ITEM_TYPE_UDP:
224 : : case RTE_FLOW_ITEM_TYPE_TCP:
225 : : case RTE_FLOW_ITEM_TYPE_ESP:
226 : : case RTE_FLOW_ITEM_TYPE_ICMP:
227 : : case RTE_FLOW_ITEM_TYPE_ICMP6:
228 : : case RTE_FLOW_ITEM_TYPE_VXLAN:
229 : : case RTE_FLOW_ITEM_TYPE_NVGRE:
230 : : case RTE_FLOW_ITEM_TYPE_GRE:
231 : : case RTE_FLOW_ITEM_TYPE_GENEVE:
232 : : case RTE_FLOW_ITEM_TYPE_MPLS:
233 : : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
234 : : case RTE_FLOW_ITEM_TYPE_GRE_KEY:
235 : : case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
236 : : case RTE_FLOW_ITEM_TYPE_GTP:
237 : : return true;
238 : : default:
239 : : break;
240 : : }
241 : 0 : return false;
242 : : }
243 : :
244 : : /**
245 : : * Network Service Header (NSH) and its next protocol values
246 : : * are described in RFC-8393.
247 : : */
248 : : static enum rte_flow_item_type
249 : : mlx5_nsh_proto_to_item_type(uint8_t proto_spec, uint8_t proto_mask)
250 : : {
251 : : enum rte_flow_item_type type;
252 : :
253 : 0 : switch (proto_mask & proto_spec) {
254 : : case 0:
255 : : type = RTE_FLOW_ITEM_TYPE_VOID;
256 : : break;
257 : : case RTE_VXLAN_GPE_TYPE_IPV4:
258 : : type = RTE_FLOW_ITEM_TYPE_IPV4;
259 : : break;
260 : : case RTE_VXLAN_GPE_TYPE_IPV6:
261 : : type = RTE_VXLAN_GPE_TYPE_IPV6;
262 : : break;
263 : : case RTE_VXLAN_GPE_TYPE_ETH:
264 : : type = RTE_FLOW_ITEM_TYPE_ETH;
265 : : break;
266 : : default:
267 : : type = RTE_FLOW_ITEM_TYPE_END;
268 : : }
269 : : return type;
270 : : }
271 : :
272 : : static enum rte_flow_item_type
273 : : mlx5_inet_proto_to_item_type(uint8_t proto_spec, uint8_t proto_mask)
274 : : {
275 : : enum rte_flow_item_type type;
276 : :
277 [ # # # # : 0 : switch (proto_mask & proto_spec) {
# # # # #
# # # #
# ]
278 : : case 0:
279 : : type = RTE_FLOW_ITEM_TYPE_VOID;
280 : : break;
281 : 0 : case IPPROTO_UDP:
282 : : type = RTE_FLOW_ITEM_TYPE_UDP;
283 : 0 : break;
284 : 0 : case IPPROTO_TCP:
285 : : type = RTE_FLOW_ITEM_TYPE_TCP;
286 : 0 : break;
287 : 0 : case IPPROTO_IPIP:
288 : : type = RTE_FLOW_ITEM_TYPE_IPV4;
289 : 0 : break;
290 : 0 : case IPPROTO_IPV6:
291 : : type = RTE_FLOW_ITEM_TYPE_IPV6;
292 : 0 : break;
293 : 0 : case IPPROTO_ESP:
294 : : type = RTE_FLOW_ITEM_TYPE_ESP;
295 : 0 : break;
296 : 0 : default:
297 : : type = RTE_FLOW_ITEM_TYPE_END;
298 : : }
299 : : return type;
300 : : }
301 : :
302 : : static enum rte_flow_item_type
303 : : mlx5_ethertype_to_item_type(rte_be16_t type_spec,
304 : : rte_be16_t type_mask, bool is_tunnel)
305 : : {
306 : : enum rte_flow_item_type type;
307 : :
308 [ # # # # : 0 : switch (rte_be_to_cpu_16(type_spec & type_mask)) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
309 : : case 0:
310 : : type = RTE_FLOW_ITEM_TYPE_VOID;
311 : : break;
312 : 0 : case RTE_ETHER_TYPE_TEB:
313 : : type = is_tunnel ?
314 : : RTE_FLOW_ITEM_TYPE_ETH : RTE_FLOW_ITEM_TYPE_END;
315 : : break;
316 : 0 : case RTE_ETHER_TYPE_VLAN:
317 : : type = !is_tunnel ?
318 : : RTE_FLOW_ITEM_TYPE_VLAN : RTE_FLOW_ITEM_TYPE_END;
319 : : break;
320 : 0 : case RTE_ETHER_TYPE_IPV4:
321 : : type = RTE_FLOW_ITEM_TYPE_IPV4;
322 : 0 : break;
323 : 0 : case RTE_ETHER_TYPE_IPV6:
324 : : type = RTE_FLOW_ITEM_TYPE_IPV6;
325 : 0 : break;
326 : 0 : default:
327 : : type = RTE_FLOW_ITEM_TYPE_END;
328 : : }
329 : : return type;
330 : : }
331 : :
332 : : static enum rte_flow_item_type
333 : 0 : mlx5_flow_expand_rss_item_complete(const struct rte_flow_item *item)
334 : : {
335 : : #define MLX5_XSET_ITEM_MASK_SPEC(type, fld) \
336 : : do { \
337 : : const void *m = item->mask; \
338 : : const void *s = item->spec; \
339 : : mask = m ? \
340 : : ((const struct rte_flow_item_##type *)m)->fld : \
341 : : rte_flow_item_##type##_mask.fld; \
342 : : spec = ((const struct rte_flow_item_##type *)s)->fld; \
343 : : } while (0)
344 : :
345 : : enum rte_flow_item_type ret;
346 : : uint16_t spec, mask;
347 : :
348 [ # # # # ]: 0 : if (item == NULL || item->spec == NULL)
349 : : return RTE_FLOW_ITEM_TYPE_VOID;
350 [ # # # # : 0 : switch (item->type) {
# # # # ]
351 : 0 : case RTE_FLOW_ITEM_TYPE_ETH:
352 [ # # ]: 0 : MLX5_XSET_ITEM_MASK_SPEC(eth, hdr.ether_type);
353 [ # # ]: 0 : if (!mask)
354 : : return RTE_FLOW_ITEM_TYPE_VOID;
355 : : ret = mlx5_ethertype_to_item_type(spec, mask, false);
356 : : break;
357 : 0 : case RTE_FLOW_ITEM_TYPE_VLAN:
358 [ # # ]: 0 : MLX5_XSET_ITEM_MASK_SPEC(vlan, hdr.eth_proto);
359 [ # # ]: 0 : if (!mask)
360 : : return RTE_FLOW_ITEM_TYPE_VOID;
361 : : ret = mlx5_ethertype_to_item_type(spec, mask, false);
362 : : break;
363 : 0 : case RTE_FLOW_ITEM_TYPE_IPV4:
364 [ # # ]: 0 : MLX5_XSET_ITEM_MASK_SPEC(ipv4, hdr.next_proto_id);
365 [ # # ]: 0 : if (!mask)
366 : : return RTE_FLOW_ITEM_TYPE_VOID;
367 : : ret = mlx5_inet_proto_to_item_type(spec, mask);
368 : : break;
369 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6:
370 [ # # ]: 0 : MLX5_XSET_ITEM_MASK_SPEC(ipv6, hdr.proto);
371 [ # # ]: 0 : if (!mask)
372 : : return RTE_FLOW_ITEM_TYPE_VOID;
373 : : ret = mlx5_inet_proto_to_item_type(spec, mask);
374 : : break;
375 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE:
376 [ # # # # ]: 0 : MLX5_XSET_ITEM_MASK_SPEC(geneve, protocol);
377 : : ret = mlx5_ethertype_to_item_type(spec, mask, true);
378 : : break;
379 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
380 [ # # # # ]: 0 : MLX5_XSET_ITEM_MASK_SPEC(gre, protocol);
381 : : ret = mlx5_ethertype_to_item_type(spec, mask, true);
382 : : break;
383 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
384 [ # # ]: 0 : MLX5_XSET_ITEM_MASK_SPEC(vxlan_gpe, hdr.proto);
385 [ # # ]: 0 : ret = mlx5_nsh_proto_to_item_type(spec, mask);
386 : : break;
387 : : default:
388 : : ret = RTE_FLOW_ITEM_TYPE_VOID;
389 : : break;
390 : : }
391 : : return ret;
392 : : #undef MLX5_XSET_ITEM_MASK_SPEC
393 : : }
394 : :
395 : : static const int *
396 : : mlx5_flow_expand_rss_skip_explicit(const struct mlx5_flow_expand_node graph[],
397 : : const int *next_node)
398 : : {
399 : : const struct mlx5_flow_expand_node *node = NULL;
400 : : const int *next = next_node;
401 : :
402 [ # # # # : 0 : while (next && *next) {
# # # # #
# # # # #
# # ]
403 : : /*
404 : : * Skip the nodes with the MLX5_EXPANSION_NODE_EXPLICIT
405 : : * flag set, because they were not found in the flow pattern.
406 : : */
407 : 0 : node = &graph[*next];
408 [ # # # # : 0 : if (!(node->node_flags & MLX5_EXPANSION_NODE_EXPLICIT))
# # # # ]
409 : : break;
410 : 0 : next = node->next;
411 : : }
412 : : return next;
413 : : }
414 : :
415 : : #define MLX5_RSS_EXP_ELT_N 32
416 : :
417 : : /**
418 : : * Expand RSS flows into several possible flows according to the RSS hash
419 : : * fields requested and the driver capabilities.
420 : : *
421 : : * @param[out] buf
422 : : * Buffer to store the result expansion.
423 : : * @param[in] size
424 : : * Buffer size in bytes. If 0, @p buf can be NULL.
425 : : * @param[in] pattern
426 : : * User flow pattern.
427 : : * @param[in] types
428 : : * RSS types to expand (see RTE_ETH_RSS_* definitions).
429 : : * @param[in] graph
430 : : * Input graph to expand @p pattern according to @p types.
431 : : * @param[in] graph_root_index
432 : : * Index of root node in @p graph, typically 0.
433 : : *
434 : : * @return
435 : : * A positive value representing the size of @p buf in bytes regardless of
436 : : * @p size on success, a negative errno value otherwise and rte_errno is
437 : : * set, the following errors are defined:
438 : : *
439 : : * -E2BIG: graph-depth @p graph is too deep.
440 : : * -EINVAL: @p size has not enough space for expanded pattern.
441 : : */
442 : : static int
443 : 0 : mlx5_flow_expand_rss(struct mlx5_flow_expand_rss *buf, size_t size,
444 : : const struct rte_flow_item *pattern, uint64_t types,
445 : : const struct mlx5_flow_expand_node graph[],
446 : : int graph_root_index)
447 : : {
448 : : const struct rte_flow_item *item;
449 [ # # ]: 0 : const struct mlx5_flow_expand_node *node = &graph[graph_root_index];
450 : : const int *next_node;
451 : : const int *stack[MLX5_RSS_EXP_ELT_N];
452 : : int stack_pos = 0;
453 : : struct rte_flow_item flow_items[MLX5_RSS_EXP_ELT_N];
454 : : unsigned int i, item_idx, last_expand_item_idx = 0;
455 : : size_t lsize;
456 : : size_t user_pattern_size = 0;
457 : : void *addr = NULL;
458 : : const struct mlx5_flow_expand_node *next = NULL;
459 : : struct rte_flow_item missed_item;
460 : : int missed = 0;
461 : : int elt = 0;
462 : : const struct rte_flow_item *last_expand_item = NULL;
463 : :
464 : : memset(&missed_item, 0, sizeof(missed_item));
465 : : lsize = offsetof(struct mlx5_flow_expand_rss, entry) +
466 : : MLX5_RSS_EXP_ELT_N * sizeof(buf->entry[0]);
467 [ # # ]: 0 : if (lsize > size)
468 : : return -EINVAL;
469 : 0 : buf->entry[0].priority = 0;
470 : 0 : buf->entry[0].pattern = (void *)&buf->entry[MLX5_RSS_EXP_ELT_N];
471 : 0 : buf->entries = 0;
472 : : addr = buf->entry[0].pattern;
473 : 0 : for (item = pattern, item_idx = 0;
474 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_END;
475 : 0 : item++, item_idx++) {
476 [ # # ]: 0 : if (!mlx5_flow_is_rss_expandable_item(item)) {
477 : 0 : user_pattern_size += sizeof(*item);
478 : 0 : continue;
479 : : }
480 : : last_expand_item = item;
481 : : last_expand_item_idx = item_idx;
482 : : i = 0;
483 [ # # # # ]: 0 : while (node->next && node->next[i]) {
484 : 0 : next = &graph[node->next[i]];
485 [ # # ]: 0 : if (next->type == item->type)
486 : : break;
487 [ # # ]: 0 : if (next->node_flags & MLX5_EXPANSION_NODE_EXPLICIT) {
488 : : node = next;
489 : : i = 0;
490 : : } else {
491 : 0 : ++i;
492 : : }
493 : : }
494 [ # # ]: 0 : if (next)
495 : : node = next;
496 : 0 : user_pattern_size += sizeof(*item);
497 : : }
498 : 0 : user_pattern_size += sizeof(*item); /* Handle END item. */
499 : 0 : lsize += user_pattern_size;
500 [ # # ]: 0 : if (lsize > size)
501 : : return -EINVAL;
502 : : /* Copy the user pattern in the first entry of the buffer. */
503 : : rte_memcpy(addr, pattern, user_pattern_size);
504 : 0 : addr = (void *)(((uintptr_t)addr) + user_pattern_size);
505 : 0 : buf->entries = 1;
506 : : /* Start expanding. */
507 : : memset(flow_items, 0, sizeof(flow_items));
508 : : user_pattern_size -= sizeof(*item);
509 : : /*
510 : : * Check if the last valid item has spec set, need complete pattern,
511 : : * and the pattern can be used for expansion.
512 : : */
513 : 0 : missed_item.type = mlx5_flow_expand_rss_item_complete(last_expand_item);
514 [ # # ]: 0 : if (missed_item.type == RTE_FLOW_ITEM_TYPE_END) {
515 : : /* Item type END indicates expansion is not required. */
516 : 0 : return lsize;
517 : : }
518 [ # # ]: 0 : if (missed_item.type != RTE_FLOW_ITEM_TYPE_VOID) {
519 : : next = NULL;
520 : : missed = 1;
521 : : i = 0;
522 [ # # # # ]: 0 : while (node->next && node->next[i]) {
523 : 0 : next = &graph[node->next[i]];
524 [ # # ]: 0 : if (next->type == missed_item.type) {
525 : 0 : flow_items[0].type = missed_item.type;
526 : : flow_items[1].type = RTE_FLOW_ITEM_TYPE_END;
527 : 0 : break;
528 : : }
529 [ # # ]: 0 : if (next->node_flags & MLX5_EXPANSION_NODE_EXPLICIT) {
530 : : node = next;
531 : : i = 0;
532 : : } else {
533 : 0 : ++i;
534 : : }
535 : : next = NULL;
536 : : }
537 : : }
538 [ # # ]: 0 : if (next && missed) {
539 : : elt = 2; /* missed item + item end. */
540 : : node = next;
541 : 0 : lsize += elt * sizeof(*item) + user_pattern_size;
542 [ # # ]: 0 : if (lsize > size)
543 : : return -EINVAL;
544 [ # # ]: 0 : if (node->rss_types & types) {
545 : 0 : buf->entry[buf->entries].priority = 1;
546 : 0 : buf->entry[buf->entries].pattern = addr;
547 : 0 : buf->entries++;
548 [ # # ]: 0 : rte_memcpy(addr, buf->entry[0].pattern,
549 : : user_pattern_size);
550 [ # # ]: 0 : addr = (void *)(((uintptr_t)addr) + user_pattern_size);
551 : : rte_memcpy(addr, flow_items, elt * sizeof(*item));
552 : 0 : addr = (void *)(((uintptr_t)addr) +
553 : : elt * sizeof(*item));
554 : : }
555 [ # # ]: 0 : } else if (last_expand_item != NULL) {
556 : 0 : node = mlx5_flow_expand_rss_adjust_node(pattern,
557 : : last_expand_item_idx, graph, node);
558 : : }
559 : : memset(flow_items, 0, sizeof(flow_items));
560 : : next_node = mlx5_flow_expand_rss_skip_explicit(graph,
561 : 0 : node->next);
562 : 0 : stack[stack_pos] = next_node;
563 [ # # ]: 0 : node = next_node ? &graph[*next_node] : NULL;
564 [ # # ]: 0 : while (node) {
565 : 0 : flow_items[stack_pos].type = node->type;
566 [ # # ]: 0 : if (node->rss_types & types) {
567 : : size_t n;
568 : : /*
569 : : * compute the number of items to copy from the
570 : : * expansion and copy it.
571 : : * When the stack_pos is 0, there are 1 element in it,
572 : : * plus the addition END item.
573 : : */
574 : 0 : elt = stack_pos + 2;
575 : 0 : flow_items[stack_pos + 1].type = RTE_FLOW_ITEM_TYPE_END;
576 : 0 : lsize += elt * sizeof(*item) + user_pattern_size;
577 [ # # ]: 0 : if (lsize > size)
578 : : return -EINVAL;
579 : : n = elt * sizeof(*item);
580 : : MLX5_ASSERT((buf->entries) < MLX5_RSS_EXP_ELT_N);
581 : 0 : buf->entry[buf->entries].priority =
582 : 0 : stack_pos + 1 + missed;
583 : 0 : buf->entry[buf->entries].pattern = addr;
584 : 0 : buf->entries++;
585 [ # # ]: 0 : rte_memcpy(addr, buf->entry[0].pattern,
586 : : user_pattern_size);
587 : 0 : addr = (void *)(((uintptr_t)addr) +
588 : : user_pattern_size);
589 [ # # ]: 0 : rte_memcpy(addr, &missed_item,
590 : : missed * sizeof(*item));
591 [ # # ]: 0 : addr = (void *)(((uintptr_t)addr) +
592 : : missed * sizeof(*item));
593 : : rte_memcpy(addr, flow_items, n);
594 : 0 : addr = (void *)(((uintptr_t)addr) + n);
595 : : }
596 : : /* Go deeper. */
597 [ # # ]: 0 : if (!(node->node_flags & MLX5_EXPANSION_NODE_OPTIONAL) &&
598 [ # # ]: 0 : node->next) {
599 : : next_node = mlx5_flow_expand_rss_skip_explicit(graph,
600 : : node->next);
601 [ # # ]: 0 : if (stack_pos++ == MLX5_RSS_EXP_ELT_N) {
602 : 0 : rte_errno = E2BIG;
603 : 0 : return -rte_errno;
604 : : }
605 : 0 : stack[stack_pos] = next_node;
606 [ # # ]: 0 : } else if (*(next_node + 1)) {
607 : : /* Follow up with the next possibility. */
608 : 0 : next_node = mlx5_flow_expand_rss_skip_explicit(graph,
609 : : ++next_node);
610 [ # # ]: 0 : } else if (!stack_pos) {
611 : : /*
612 : : * Completing the traverse over the different paths.
613 : : * The next_node is advanced to the terminator.
614 : : */
615 : 0 : ++next_node;
616 : : } else {
617 : : /* Move to the next path. */
618 [ # # ]: 0 : while (stack_pos) {
619 : 0 : next_node = stack[--stack_pos];
620 : 0 : next_node++;
621 [ # # ]: 0 : if (*next_node)
622 : : break;
623 : : }
624 : : next_node = mlx5_flow_expand_rss_skip_explicit(graph,
625 : : next_node);
626 : 0 : stack[stack_pos] = next_node;
627 : : }
628 [ # # # # ]: 0 : node = next_node && *next_node ? &graph[*next_node] : NULL;
629 : : };
630 : 0 : return lsize;
631 : : }
632 : :
633 : : /**
634 : : * Expand SQN flows into several possible flows according to the Tx queue
635 : : * number
636 : : *
637 : : * @param[in] buf
638 : : * Buffer to store the result expansion.
639 : : * @param[in] size
640 : : * Buffer size in bytes. If 0, @p buf can be NULL.
641 : : * @param[in] pattern
642 : : * User flow pattern.
643 : : * @param[in] sq_specs
644 : : * Buffer to store sq spec.
645 : : *
646 : : * @return
647 : : * 0 for success and negative value for failure
648 : : *
649 : : */
650 : : static int
651 : 0 : mlx5_flow_expand_sqn(struct mlx5_flow_expand_sqn *buf, size_t size,
652 : : const struct rte_flow_item *pattern,
653 : : struct mlx5_rte_flow_item_sq *sq_specs)
654 : : {
655 : : const struct rte_flow_item *item;
656 : : bool port_representor = false;
657 : : size_t user_pattern_size = 0;
658 : : struct rte_eth_dev *dev;
659 : : struct mlx5_priv *priv;
660 : : void *addr = NULL;
661 : : uint16_t port_id;
662 : : size_t lsize;
663 : : int elt = 2;
664 : : uint16_t i;
665 : :
666 : 0 : buf->entries = 0;
667 [ # # ]: 0 : for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
668 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR) {
669 : 0 : const struct rte_flow_item_ethdev *pid_v = item->spec;
670 : :
671 [ # # ]: 0 : if (!pid_v)
672 : : return 0;
673 : 0 : port_id = pid_v->port_id;
674 : : port_representor = true;
675 : : }
676 : 0 : user_pattern_size += sizeof(*item);
677 : : }
678 [ # # ]: 0 : if (!port_representor)
679 : : return 0;
680 : 0 : dev = &rte_eth_devices[port_id];
681 : 0 : priv = dev->data->dev_private;
682 : 0 : buf->entry[0].pattern = (void *)&buf->entry[priv->txqs_n];
683 : 0 : lsize = offsetof(struct mlx5_flow_expand_sqn, entry) +
684 : 0 : sizeof(buf->entry[0]) * priv->txqs_n;
685 [ # # ]: 0 : if (lsize + (user_pattern_size + sizeof(struct rte_flow_item) * elt) * priv->txqs_n > size)
686 : : return -EINVAL;
687 : : addr = buf->entry[0].pattern;
688 [ # # ]: 0 : for (i = 0; i != priv->txqs_n; ++i) {
689 : 0 : struct rte_flow_item pattern_add[] = {
690 : : {
691 : : .type = (enum rte_flow_item_type)
692 : : MLX5_RTE_FLOW_ITEM_TYPE_SQ,
693 : 0 : .spec = &sq_specs[i],
694 : : },
695 : : {
696 : : .type = RTE_FLOW_ITEM_TYPE_END,
697 : : },
698 : : };
699 : 0 : struct mlx5_txq_ctrl *txq = mlx5_txq_get(dev, i);
700 : :
701 [ # # ]: 0 : if (txq == NULL)
702 : 0 : return -EINVAL;
703 : 0 : buf->entry[i].pattern = addr;
704 : 0 : sq_specs[i].queue = mlx5_txq_get_sqn(txq);
705 : 0 : mlx5_txq_release(dev, i);
706 : : rte_memcpy(addr, pattern, user_pattern_size);
707 [ # # ]: 0 : addr = (void *)(((uintptr_t)addr) + user_pattern_size);
708 : : rte_memcpy(addr, pattern_add, sizeof(struct rte_flow_item) * elt);
709 : 0 : addr = (void *)(((uintptr_t)addr) + sizeof(struct rte_flow_item) * elt);
710 : 0 : buf->entries++;
711 : : }
712 : : return 0;
713 : : }
714 : :
715 : : enum mlx5_expansion {
716 : : MLX5_EXPANSION_ROOT,
717 : : MLX5_EXPANSION_ROOT_OUTER,
718 : : MLX5_EXPANSION_OUTER_ETH,
719 : : MLX5_EXPANSION_OUTER_VLAN,
720 : : MLX5_EXPANSION_OUTER_IPV4,
721 : : MLX5_EXPANSION_OUTER_IPV4_UDP,
722 : : MLX5_EXPANSION_OUTER_IPV4_TCP,
723 : : MLX5_EXPANSION_OUTER_IPV4_ESP,
724 : : MLX5_EXPANSION_OUTER_IPV4_ICMP,
725 : : MLX5_EXPANSION_OUTER_IPV6,
726 : : MLX5_EXPANSION_OUTER_IPV6_UDP,
727 : : MLX5_EXPANSION_OUTER_IPV6_TCP,
728 : : MLX5_EXPANSION_OUTER_IPV6_ESP,
729 : : MLX5_EXPANSION_OUTER_IPV6_ICMP6,
730 : : MLX5_EXPANSION_VXLAN,
731 : : MLX5_EXPANSION_STD_VXLAN,
732 : : MLX5_EXPANSION_L3_VXLAN,
733 : : MLX5_EXPANSION_VXLAN_GPE,
734 : : MLX5_EXPANSION_GRE,
735 : : MLX5_EXPANSION_NVGRE,
736 : : MLX5_EXPANSION_GRE_KEY,
737 : : MLX5_EXPANSION_MPLS,
738 : : MLX5_EXPANSION_ETH,
739 : : MLX5_EXPANSION_VLAN,
740 : : MLX5_EXPANSION_IPV4,
741 : : MLX5_EXPANSION_IPV4_UDP,
742 : : MLX5_EXPANSION_IPV4_TCP,
743 : : MLX5_EXPANSION_IPV4_ESP,
744 : : MLX5_EXPANSION_IPV4_ICMP,
745 : : MLX5_EXPANSION_IPV6,
746 : : MLX5_EXPANSION_IPV6_UDP,
747 : : MLX5_EXPANSION_IPV6_TCP,
748 : : MLX5_EXPANSION_IPV6_ESP,
749 : : MLX5_EXPANSION_IPV6_ICMP6,
750 : : MLX5_EXPANSION_IPV6_FRAG_EXT,
751 : : MLX5_EXPANSION_GTP,
752 : : MLX5_EXPANSION_GENEVE,
753 : : };
754 : :
755 : : /** Supported expansion of items. */
756 : : static const struct mlx5_flow_expand_node mlx5_support_expansion[] = {
757 : : [MLX5_EXPANSION_ROOT] = {
758 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
759 : : MLX5_EXPANSION_IPV4,
760 : : MLX5_EXPANSION_IPV6),
761 : : .type = RTE_FLOW_ITEM_TYPE_END,
762 : : },
763 : : [MLX5_EXPANSION_ROOT_OUTER] = {
764 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH,
765 : : MLX5_EXPANSION_OUTER_IPV4,
766 : : MLX5_EXPANSION_OUTER_IPV6),
767 : : .type = RTE_FLOW_ITEM_TYPE_END,
768 : : },
769 : : [MLX5_EXPANSION_OUTER_ETH] = {
770 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_VLAN),
771 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
772 : : .rss_types = 0,
773 : : },
774 : : [MLX5_EXPANSION_OUTER_VLAN] = {
775 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
776 : : MLX5_EXPANSION_OUTER_IPV6),
777 : : .type = RTE_FLOW_ITEM_TYPE_VLAN,
778 : : .node_flags = MLX5_EXPANSION_NODE_EXPLICIT,
779 : : },
780 : : [MLX5_EXPANSION_OUTER_IPV4] = {
781 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT
782 : : (MLX5_EXPANSION_OUTER_IPV4_UDP,
783 : : MLX5_EXPANSION_OUTER_IPV4_TCP,
784 : : MLX5_EXPANSION_OUTER_IPV4_ESP,
785 : : MLX5_EXPANSION_OUTER_IPV4_ICMP,
786 : : MLX5_EXPANSION_GRE,
787 : : MLX5_EXPANSION_NVGRE,
788 : : MLX5_EXPANSION_IPV4,
789 : : MLX5_EXPANSION_IPV6),
790 : : .type = RTE_FLOW_ITEM_TYPE_IPV4,
791 : : .rss_types = RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_FRAG_IPV4 |
792 : : RTE_ETH_RSS_NONFRAG_IPV4_OTHER,
793 : : },
794 : : [MLX5_EXPANSION_OUTER_IPV4_UDP] = {
795 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
796 : : MLX5_EXPANSION_VXLAN_GPE,
797 : : MLX5_EXPANSION_MPLS,
798 : : MLX5_EXPANSION_GENEVE,
799 : : MLX5_EXPANSION_GTP),
800 : : .type = RTE_FLOW_ITEM_TYPE_UDP,
801 : : .rss_types = RTE_ETH_RSS_NONFRAG_IPV4_UDP,
802 : : },
803 : : [MLX5_EXPANSION_OUTER_IPV4_TCP] = {
804 : : .type = RTE_FLOW_ITEM_TYPE_TCP,
805 : : .rss_types = RTE_ETH_RSS_NONFRAG_IPV4_TCP,
806 : : },
807 : : [MLX5_EXPANSION_OUTER_IPV4_ESP] = {
808 : : .type = RTE_FLOW_ITEM_TYPE_ESP,
809 : : .rss_types = RTE_ETH_RSS_ESP,
810 : : },
811 : : [MLX5_EXPANSION_OUTER_IPV4_ICMP] = {
812 : : .type = RTE_FLOW_ITEM_TYPE_ICMP,
813 : : },
814 : : [MLX5_EXPANSION_OUTER_IPV6] = {
815 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT
816 : : (MLX5_EXPANSION_OUTER_IPV6_UDP,
817 : : MLX5_EXPANSION_OUTER_IPV6_TCP,
818 : : MLX5_EXPANSION_OUTER_IPV6_ESP,
819 : : MLX5_EXPANSION_OUTER_IPV6_ICMP6,
820 : : MLX5_EXPANSION_IPV4,
821 : : MLX5_EXPANSION_IPV6,
822 : : MLX5_EXPANSION_GRE,
823 : : MLX5_EXPANSION_NVGRE),
824 : : .type = RTE_FLOW_ITEM_TYPE_IPV6,
825 : : .rss_types = RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_FRAG_IPV6 |
826 : : RTE_ETH_RSS_NONFRAG_IPV6_OTHER,
827 : : },
828 : : [MLX5_EXPANSION_OUTER_IPV6_UDP] = {
829 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
830 : : MLX5_EXPANSION_VXLAN_GPE,
831 : : MLX5_EXPANSION_MPLS,
832 : : MLX5_EXPANSION_GENEVE,
833 : : MLX5_EXPANSION_GTP),
834 : : .type = RTE_FLOW_ITEM_TYPE_UDP,
835 : : .rss_types = RTE_ETH_RSS_NONFRAG_IPV6_UDP,
836 : : },
837 : : [MLX5_EXPANSION_OUTER_IPV6_TCP] = {
838 : : .type = RTE_FLOW_ITEM_TYPE_TCP,
839 : : .rss_types = RTE_ETH_RSS_NONFRAG_IPV6_TCP,
840 : : },
841 : : [MLX5_EXPANSION_OUTER_IPV6_ESP] = {
842 : : .type = RTE_FLOW_ITEM_TYPE_ESP,
843 : : .rss_types = RTE_ETH_RSS_ESP,
844 : : },
845 : : [MLX5_EXPANSION_OUTER_IPV6_ICMP6] = {
846 : : .type = RTE_FLOW_ITEM_TYPE_ICMP6,
847 : : },
848 : : [MLX5_EXPANSION_VXLAN] = {
849 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
850 : : MLX5_EXPANSION_IPV4,
851 : : MLX5_EXPANSION_IPV6),
852 : : .type = RTE_FLOW_ITEM_TYPE_VXLAN,
853 : : },
854 : : [MLX5_EXPANSION_STD_VXLAN] = {
855 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH),
856 : : .type = RTE_FLOW_ITEM_TYPE_VXLAN,
857 : : },
858 : : [MLX5_EXPANSION_L3_VXLAN] = {
859 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
860 : : MLX5_EXPANSION_IPV6),
861 : : .type = RTE_FLOW_ITEM_TYPE_VXLAN,
862 : : },
863 : : [MLX5_EXPANSION_VXLAN_GPE] = {
864 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
865 : : MLX5_EXPANSION_IPV4,
866 : : MLX5_EXPANSION_IPV6),
867 : : .type = RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
868 : : },
869 : : [MLX5_EXPANSION_GRE] = {
870 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
871 : : MLX5_EXPANSION_IPV4,
872 : : MLX5_EXPANSION_IPV6,
873 : : MLX5_EXPANSION_GRE_KEY,
874 : : MLX5_EXPANSION_MPLS),
875 : : .type = RTE_FLOW_ITEM_TYPE_GRE,
876 : : },
877 : : [MLX5_EXPANSION_GRE_KEY] = {
878 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
879 : : MLX5_EXPANSION_IPV6,
880 : : MLX5_EXPANSION_MPLS),
881 : : .type = RTE_FLOW_ITEM_TYPE_GRE_KEY,
882 : : .node_flags = MLX5_EXPANSION_NODE_OPTIONAL,
883 : : },
884 : : [MLX5_EXPANSION_NVGRE] = {
885 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH),
886 : : .type = RTE_FLOW_ITEM_TYPE_NVGRE,
887 : : },
888 : : [MLX5_EXPANSION_MPLS] = {
889 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
890 : : MLX5_EXPANSION_IPV6,
891 : : MLX5_EXPANSION_ETH),
892 : : .type = RTE_FLOW_ITEM_TYPE_MPLS,
893 : : .node_flags = MLX5_EXPANSION_NODE_OPTIONAL,
894 : : },
895 : : [MLX5_EXPANSION_ETH] = {
896 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VLAN),
897 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
898 : : },
899 : : [MLX5_EXPANSION_VLAN] = {
900 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
901 : : MLX5_EXPANSION_IPV6),
902 : : .type = RTE_FLOW_ITEM_TYPE_VLAN,
903 : : .node_flags = MLX5_EXPANSION_NODE_EXPLICIT,
904 : : },
905 : : [MLX5_EXPANSION_IPV4] = {
906 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4_UDP,
907 : : MLX5_EXPANSION_IPV4_TCP,
908 : : MLX5_EXPANSION_IPV4_ESP,
909 : : MLX5_EXPANSION_IPV4_ICMP),
910 : : .type = RTE_FLOW_ITEM_TYPE_IPV4,
911 : : .rss_types = RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_FRAG_IPV4 |
912 : : RTE_ETH_RSS_NONFRAG_IPV4_OTHER,
913 : : },
914 : : [MLX5_EXPANSION_IPV4_UDP] = {
915 : : .type = RTE_FLOW_ITEM_TYPE_UDP,
916 : : .rss_types = RTE_ETH_RSS_NONFRAG_IPV4_UDP,
917 : : },
918 : : [MLX5_EXPANSION_IPV4_TCP] = {
919 : : .type = RTE_FLOW_ITEM_TYPE_TCP,
920 : : .rss_types = RTE_ETH_RSS_NONFRAG_IPV4_TCP,
921 : : },
922 : : [MLX5_EXPANSION_IPV4_ESP] = {
923 : : .type = RTE_FLOW_ITEM_TYPE_ESP,
924 : : .rss_types = RTE_ETH_RSS_ESP,
925 : : },
926 : : [MLX5_EXPANSION_IPV4_ICMP] = {
927 : : .type = RTE_FLOW_ITEM_TYPE_ICMP,
928 : : },
929 : : [MLX5_EXPANSION_IPV6] = {
930 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV6_UDP,
931 : : MLX5_EXPANSION_IPV6_TCP,
932 : : MLX5_EXPANSION_IPV6_ESP,
933 : : MLX5_EXPANSION_IPV6_ICMP6,
934 : : MLX5_EXPANSION_IPV6_FRAG_EXT),
935 : : .type = RTE_FLOW_ITEM_TYPE_IPV6,
936 : : .rss_types = RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_FRAG_IPV6 |
937 : : RTE_ETH_RSS_NONFRAG_IPV6_OTHER,
938 : : },
939 : : [MLX5_EXPANSION_IPV6_UDP] = {
940 : : .type = RTE_FLOW_ITEM_TYPE_UDP,
941 : : .rss_types = RTE_ETH_RSS_NONFRAG_IPV6_UDP,
942 : : },
943 : : [MLX5_EXPANSION_IPV6_TCP] = {
944 : : .type = RTE_FLOW_ITEM_TYPE_TCP,
945 : : .rss_types = RTE_ETH_RSS_NONFRAG_IPV6_TCP,
946 : : },
947 : : [MLX5_EXPANSION_IPV6_ESP] = {
948 : : .type = RTE_FLOW_ITEM_TYPE_ESP,
949 : : .rss_types = RTE_ETH_RSS_ESP,
950 : : },
951 : : [MLX5_EXPANSION_IPV6_FRAG_EXT] = {
952 : : .type = RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT,
953 : : },
954 : : [MLX5_EXPANSION_IPV6_ICMP6] = {
955 : : .type = RTE_FLOW_ITEM_TYPE_ICMP6,
956 : : },
957 : : [MLX5_EXPANSION_GTP] = {
958 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
959 : : MLX5_EXPANSION_IPV6),
960 : : .type = RTE_FLOW_ITEM_TYPE_GTP,
961 : : },
962 : : [MLX5_EXPANSION_GENEVE] = {
963 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
964 : : MLX5_EXPANSION_IPV4,
965 : : MLX5_EXPANSION_IPV6),
966 : : .type = RTE_FLOW_ITEM_TYPE_GENEVE,
967 : : },
968 : : };
969 : :
970 : : static struct rte_flow_action_handle *
971 : : mlx5_action_handle_create(struct rte_eth_dev *dev,
972 : : const struct rte_flow_indir_action_conf *conf,
973 : : const struct rte_flow_action *action,
974 : : struct rte_flow_error *error);
975 : : static int mlx5_action_handle_destroy
976 : : (struct rte_eth_dev *dev,
977 : : struct rte_flow_action_handle *handle,
978 : : struct rte_flow_error *error);
979 : : static int mlx5_action_handle_update
980 : : (struct rte_eth_dev *dev,
981 : : struct rte_flow_action_handle *handle,
982 : : const void *update,
983 : : struct rte_flow_error *error);
984 : : static int mlx5_action_handle_query
985 : : (struct rte_eth_dev *dev,
986 : : const struct rte_flow_action_handle *handle,
987 : : void *data,
988 : : struct rte_flow_error *error);
989 : : static int
990 : : mlx5_flow_tunnel_decap_set(struct rte_eth_dev *dev,
991 : : struct rte_flow_tunnel *app_tunnel,
992 : : struct rte_flow_action **actions,
993 : : uint32_t *num_of_actions,
994 : : struct rte_flow_error *error);
995 : : static int
996 : : mlx5_flow_tunnel_match(struct rte_eth_dev *dev,
997 : : struct rte_flow_tunnel *app_tunnel,
998 : : struct rte_flow_item **items,
999 : : uint32_t *num_of_items,
1000 : : struct rte_flow_error *error);
1001 : : static int
1002 : : mlx5_flow_tunnel_item_release(struct rte_eth_dev *dev,
1003 : : struct rte_flow_item *pmd_items,
1004 : : uint32_t num_items, struct rte_flow_error *err);
1005 : : static int
1006 : : mlx5_flow_tunnel_action_release(struct rte_eth_dev *dev,
1007 : : struct rte_flow_action *pmd_actions,
1008 : : uint32_t num_actions,
1009 : : struct rte_flow_error *err);
1010 : : static int
1011 : : mlx5_flow_tunnel_get_restore_info(struct rte_eth_dev *dev,
1012 : : struct rte_mbuf *m,
1013 : : struct rte_flow_restore_info *info,
1014 : : struct rte_flow_error *err);
1015 : : static struct rte_flow_item_flex_handle *
1016 : : mlx5_flow_flex_item_create(struct rte_eth_dev *dev,
1017 : : const struct rte_flow_item_flex_conf *conf,
1018 : : struct rte_flow_error *error);
1019 : : static int
1020 : : mlx5_flow_flex_item_release(struct rte_eth_dev *dev,
1021 : : const struct rte_flow_item_flex_handle *handle,
1022 : : struct rte_flow_error *error);
1023 : : static int
1024 : : mlx5_flow_info_get(struct rte_eth_dev *dev,
1025 : : struct rte_flow_port_info *port_info,
1026 : : struct rte_flow_queue_info *queue_info,
1027 : : struct rte_flow_error *error);
1028 : : static int
1029 : : mlx5_flow_port_configure(struct rte_eth_dev *dev,
1030 : : const struct rte_flow_port_attr *port_attr,
1031 : : uint16_t nb_queue,
1032 : : const struct rte_flow_queue_attr *queue_attr[],
1033 : : struct rte_flow_error *err);
1034 : :
1035 : : static struct rte_flow_pattern_template *
1036 : : mlx5_flow_pattern_template_create(struct rte_eth_dev *dev,
1037 : : const struct rte_flow_pattern_template_attr *attr,
1038 : : const struct rte_flow_item items[],
1039 : : struct rte_flow_error *error);
1040 : :
1041 : : static int
1042 : : mlx5_flow_pattern_template_destroy(struct rte_eth_dev *dev,
1043 : : struct rte_flow_pattern_template *template,
1044 : : struct rte_flow_error *error);
1045 : : static struct rte_flow_actions_template *
1046 : : mlx5_flow_actions_template_create(struct rte_eth_dev *dev,
1047 : : const struct rte_flow_actions_template_attr *attr,
1048 : : const struct rte_flow_action actions[],
1049 : : const struct rte_flow_action masks[],
1050 : : struct rte_flow_error *error);
1051 : : static int
1052 : : mlx5_flow_actions_template_destroy(struct rte_eth_dev *dev,
1053 : : struct rte_flow_actions_template *template,
1054 : : struct rte_flow_error *error);
1055 : :
1056 : : static struct rte_flow_template_table *
1057 : : mlx5_flow_table_create(struct rte_eth_dev *dev,
1058 : : const struct rte_flow_template_table_attr *attr,
1059 : : struct rte_flow_pattern_template *item_templates[],
1060 : : uint8_t nb_item_templates,
1061 : : struct rte_flow_actions_template *action_templates[],
1062 : : uint8_t nb_action_templates,
1063 : : struct rte_flow_error *error);
1064 : : static int
1065 : : mlx5_flow_table_destroy(struct rte_eth_dev *dev,
1066 : : struct rte_flow_template_table *table,
1067 : : struct rte_flow_error *error);
1068 : : static int
1069 : : mlx5_flow_group_set_miss_actions(struct rte_eth_dev *dev,
1070 : : uint32_t group_id,
1071 : : const struct rte_flow_group_attr *attr,
1072 : : const struct rte_flow_action actions[],
1073 : : struct rte_flow_error *error);
1074 : :
1075 : : static int
1076 : : mlx5_action_handle_query_update(struct rte_eth_dev *dev,
1077 : : struct rte_flow_action_handle *handle,
1078 : : const void *update, void *query,
1079 : : enum rte_flow_query_update_mode qu_mode,
1080 : : struct rte_flow_error *error);
1081 : :
1082 : : static struct rte_flow_action_list_handle *
1083 : : mlx5_action_list_handle_create(struct rte_eth_dev *dev,
1084 : : const struct rte_flow_indir_action_conf *conf,
1085 : : const struct rte_flow_action *actions,
1086 : : struct rte_flow_error *error);
1087 : :
1088 : : static int
1089 : : mlx5_action_list_handle_destroy(struct rte_eth_dev *dev,
1090 : : struct rte_flow_action_list_handle *handle,
1091 : : struct rte_flow_error *error);
1092 : :
1093 : : static int
1094 : : mlx5_flow_action_list_handle_query_update(struct rte_eth_dev *dev,
1095 : : const
1096 : : struct rte_flow_action_list_handle *handle,
1097 : : const void **update, void **query,
1098 : : enum rte_flow_query_update_mode mode,
1099 : : struct rte_flow_error *error);
1100 : :
1101 : : static int
1102 : : mlx5_flow_calc_table_hash(struct rte_eth_dev *dev,
1103 : : const struct rte_flow_template_table *table,
1104 : : const struct rte_flow_item pattern[],
1105 : : uint8_t pattern_template_index,
1106 : : uint32_t *hash, struct rte_flow_error *error);
1107 : : static int
1108 : : mlx5_flow_calc_encap_hash(struct rte_eth_dev *dev,
1109 : : const struct rte_flow_item pattern[],
1110 : : enum rte_flow_encap_hash_field dest_field,
1111 : : uint8_t *hash,
1112 : : struct rte_flow_error *error);
1113 : :
1114 : : static int
1115 : : mlx5_template_table_resize(struct rte_eth_dev *dev,
1116 : : struct rte_flow_template_table *table,
1117 : : uint32_t nb_rules, struct rte_flow_error *error);
1118 : : static int
1119 : : mlx5_flow_async_update_resized(struct rte_eth_dev *dev, uint32_t queue,
1120 : : const struct rte_flow_op_attr *attr,
1121 : : struct rte_flow *rule, void *user_data,
1122 : : struct rte_flow_error *error);
1123 : : static int
1124 : : mlx5_table_resize_complete(struct rte_eth_dev *dev,
1125 : : struct rte_flow_template_table *table,
1126 : : struct rte_flow_error *error);
1127 : :
1128 : : static const struct rte_flow_ops mlx5_flow_ops = {
1129 : : .validate = mlx5_flow_validate,
1130 : : .create = mlx5_flow_create,
1131 : : .destroy = mlx5_flow_destroy,
1132 : : .flush = mlx5_flow_flush,
1133 : : .isolate = mlx5_flow_isolate,
1134 : : .query = mlx5_flow_query,
1135 : : .dev_dump = mlx5_flow_dev_dump,
1136 : : .get_q_aged_flows = mlx5_flow_get_q_aged_flows,
1137 : : .get_aged_flows = mlx5_flow_get_aged_flows,
1138 : : .action_handle_create = mlx5_action_handle_create,
1139 : : .action_handle_destroy = mlx5_action_handle_destroy,
1140 : : .action_handle_update = mlx5_action_handle_update,
1141 : : .action_handle_query = mlx5_action_handle_query,
1142 : : .action_handle_query_update = mlx5_action_handle_query_update,
1143 : : .action_list_handle_create = mlx5_action_list_handle_create,
1144 : : .action_list_handle_destroy = mlx5_action_list_handle_destroy,
1145 : : .tunnel_decap_set = mlx5_flow_tunnel_decap_set,
1146 : : .tunnel_match = mlx5_flow_tunnel_match,
1147 : : .tunnel_action_decap_release = mlx5_flow_tunnel_action_release,
1148 : : .tunnel_item_release = mlx5_flow_tunnel_item_release,
1149 : : .get_restore_info = mlx5_flow_tunnel_get_restore_info,
1150 : : .flex_item_create = mlx5_flow_flex_item_create,
1151 : : .flex_item_release = mlx5_flow_flex_item_release,
1152 : : .info_get = mlx5_flow_info_get,
1153 : : .pick_transfer_proxy = mlx5_flow_pick_transfer_proxy,
1154 : : .configure = mlx5_flow_port_configure,
1155 : : .pattern_template_create = mlx5_flow_pattern_template_create,
1156 : : .pattern_template_destroy = mlx5_flow_pattern_template_destroy,
1157 : : .actions_template_create = mlx5_flow_actions_template_create,
1158 : : .actions_template_destroy = mlx5_flow_actions_template_destroy,
1159 : : .template_table_create = mlx5_flow_table_create,
1160 : : .template_table_destroy = mlx5_flow_table_destroy,
1161 : : .group_set_miss_actions = mlx5_flow_group_set_miss_actions,
1162 : : .action_list_handle_query_update =
1163 : : mlx5_flow_action_list_handle_query_update,
1164 : : .flow_calc_table_hash = mlx5_flow_calc_table_hash,
1165 : : .flow_calc_encap_hash = mlx5_flow_calc_encap_hash,
1166 : : .flow_template_table_resize = mlx5_template_table_resize,
1167 : : .flow_update_resized = mlx5_flow_async_update_resized,
1168 : : .flow_template_table_resize_complete = mlx5_table_resize_complete,
1169 : : };
1170 : :
1171 : : /* Tunnel information. */
1172 : : struct mlx5_flow_tunnel_info {
1173 : : uint64_t tunnel; /**< Tunnel bit (see MLX5_FLOW_*). */
1174 : : uint32_t ptype; /**< Tunnel Ptype (see RTE_PTYPE_*). */
1175 : : };
1176 : :
1177 : : static struct mlx5_flow_tunnel_info tunnels_info[] = {
1178 : : {
1179 : : .tunnel = MLX5_FLOW_LAYER_VXLAN,
1180 : : .ptype = RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_L4_UDP,
1181 : : },
1182 : : {
1183 : : .tunnel = MLX5_FLOW_LAYER_GENEVE,
1184 : : .ptype = RTE_PTYPE_TUNNEL_GENEVE | RTE_PTYPE_L4_UDP,
1185 : : },
1186 : : {
1187 : : .tunnel = MLX5_FLOW_LAYER_VXLAN_GPE,
1188 : : .ptype = RTE_PTYPE_TUNNEL_VXLAN_GPE | RTE_PTYPE_L4_UDP,
1189 : : },
1190 : : {
1191 : : .tunnel = MLX5_FLOW_LAYER_GRE,
1192 : : .ptype = RTE_PTYPE_TUNNEL_GRE,
1193 : : },
1194 : : {
1195 : : .tunnel = MLX5_FLOW_LAYER_MPLS | MLX5_FLOW_LAYER_OUTER_L4_UDP,
1196 : : .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_UDP | RTE_PTYPE_L4_UDP,
1197 : : },
1198 : : {
1199 : : .tunnel = MLX5_FLOW_LAYER_MPLS,
1200 : : .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE,
1201 : : },
1202 : : {
1203 : : .tunnel = MLX5_FLOW_LAYER_NVGRE,
1204 : : .ptype = RTE_PTYPE_TUNNEL_NVGRE,
1205 : : },
1206 : : {
1207 : : .tunnel = MLX5_FLOW_LAYER_IPIP,
1208 : : .ptype = RTE_PTYPE_TUNNEL_IP,
1209 : : },
1210 : : {
1211 : : .tunnel = MLX5_FLOW_LAYER_IPV6_ENCAP,
1212 : : .ptype = RTE_PTYPE_TUNNEL_IP,
1213 : : },
1214 : : {
1215 : : .tunnel = MLX5_FLOW_LAYER_GTP,
1216 : : .ptype = RTE_PTYPE_TUNNEL_GTPU,
1217 : : },
1218 : : };
1219 : :
1220 : :
1221 : :
1222 : : /**
1223 : : * Translate tag ID to register.
1224 : : *
1225 : : * @param[in] dev
1226 : : * Pointer to the Ethernet device structure.
1227 : : * @param[in] feature
1228 : : * The feature that request the register.
1229 : : * @param[in] id
1230 : : * The request register ID.
1231 : : * @param[out] error
1232 : : * Error description in case of any.
1233 : : *
1234 : : * @return
1235 : : * The request register on success, a negative errno
1236 : : * value otherwise and rte_errno is set.
1237 : : */
1238 : : int
1239 : 0 : mlx5_flow_get_reg_id(struct rte_eth_dev *dev,
1240 : : enum mlx5_feature_name feature,
1241 : : uint32_t id,
1242 : : struct rte_flow_error *error)
1243 : : {
1244 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1245 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
1246 : : struct mlx5_dev_registers *reg = &priv->sh->registers;
1247 : : enum modify_reg start_reg;
1248 : : bool skip_mtr_reg = false;
1249 : :
1250 [ # # # # : 0 : switch (feature) {
# # # # #
# # ]
1251 : : case MLX5_HAIRPIN_RX:
1252 : : return REG_B;
1253 : 0 : case MLX5_HAIRPIN_TX:
1254 : 0 : return REG_A;
1255 : 0 : case MLX5_METADATA_RX:
1256 [ # # ]: 0 : if (mlx5_vport_rx_metadata_passing_enabled(priv->sh)) {
1257 : : return REG_C_1;
1258 : : } else {
1259 [ # # # # : 0 : switch (config->dv_xmeta_en) {
# ]
1260 : : case MLX5_XMETA_MODE_LEGACY:
1261 : : return REG_B;
1262 : 0 : case MLX5_XMETA_MODE_META16:
1263 : 0 : return REG_C_0;
1264 : 0 : case MLX5_XMETA_MODE_META32:
1265 : 0 : return REG_C_1;
1266 : 0 : case MLX5_XMETA_MODE_META32_HWS:
1267 : 0 : return REG_C_1;
1268 : : }
1269 : : }
1270 : : break;
1271 : 0 : case MLX5_METADATA_TX:
1272 [ # # ]: 0 : if ((config->dv_flow_en == 2 &&
1273 [ # # ]: 0 : config->dv_xmeta_en == MLX5_XMETA_MODE_META32_HWS) ||
1274 : 0 : mlx5_vport_tx_metadata_passing_enabled(priv->sh)) {
1275 : 0 : return REG_C_1;
1276 : : } else {
1277 : : return REG_A;
1278 : : }
1279 : 0 : case MLX5_METADATA_FDB:
1280 [ # # ]: 0 : if (mlx5_esw_metadata_passing_enabled(priv->sh)) {
1281 : : return REG_C_1;
1282 : : } else {
1283 [ # # # # : 0 : switch (config->dv_xmeta_en) {
# ]
1284 : : case MLX5_XMETA_MODE_LEGACY:
1285 : : return REG_NON;
1286 : 0 : case MLX5_XMETA_MODE_META16:
1287 : 0 : return REG_C_0;
1288 : 0 : case MLX5_XMETA_MODE_META32:
1289 : 0 : return REG_C_1;
1290 : 0 : case MLX5_XMETA_MODE_META32_HWS:
1291 : 0 : return REG_C_1;
1292 : : }
1293 : : }
1294 : : break;
1295 : 0 : case MLX5_FLOW_MARK:
1296 [ # # # # ]: 0 : switch (config->dv_xmeta_en) {
1297 : : case MLX5_XMETA_MODE_LEGACY:
1298 : : case MLX5_XMETA_MODE_META32_HWS:
1299 : : return REG_NON;
1300 : 0 : case MLX5_XMETA_MODE_META16:
1301 : 0 : return REG_C_1;
1302 : 0 : case MLX5_XMETA_MODE_META32:
1303 : 0 : return REG_C_0;
1304 : : }
1305 : : break;
1306 : 0 : case MLX5_MTR_ID:
1307 : : /*
1308 : : * If meter color and meter id share one register, flow match
1309 : : * should use the meter color register for match.
1310 : : */
1311 [ # # ]: 0 : if (priv->mtr_reg_share)
1312 : 0 : return reg->aso_reg;
1313 : : else
1314 [ # # ]: 0 : return reg->aso_reg != REG_C_2 ? REG_C_2 :
1315 : : REG_C_3;
1316 : 0 : case MLX5_MTR_COLOR:
1317 : : case MLX5_ASO_FLOW_HIT:
1318 : : case MLX5_ASO_CONNTRACK:
1319 : : case MLX5_SAMPLE_ID:
1320 : : /* All features use the same REG_C. */
1321 : : MLX5_ASSERT(reg->aso_reg != REG_NON);
1322 : 0 : return reg->aso_reg;
1323 : 0 : case MLX5_COPY_MARK:
1324 : : /*
1325 : : * Metadata COPY_MARK register using is in meter suffix sub
1326 : : * flow while with meter. It's safe to share the same register.
1327 : : */
1328 [ # # ]: 0 : return reg->aso_reg != REG_C_2 ? REG_C_2 : REG_C_3;
1329 : 0 : case MLX5_APP_TAG:
1330 : : /*
1331 : : * If meter is enable, it will engage the register for color
1332 : : * match and flow match. If meter color match is not using the
1333 : : * REG_C_2, need to skip the REG_C_x be used by meter color
1334 : : * match.
1335 : : * If meter is disable, free to use all available registers.
1336 : : */
1337 [ # # ]: 0 : start_reg = reg->aso_reg != REG_C_2 ? REG_C_2 :
1338 [ # # ]: 0 : (priv->mtr_reg_share ? REG_C_3 : REG_C_4);
1339 [ # # # # ]: 0 : skip_mtr_reg = !!(priv->mtr_en && start_reg == REG_C_2);
1340 [ # # ]: 0 : if (id > (uint32_t)(REG_C_7 - start_reg))
1341 : 0 : return rte_flow_error_set(error, EINVAL,
1342 : : RTE_FLOW_ERROR_TYPE_ITEM,
1343 : : NULL, "invalid tag id");
1344 [ # # ]: 0 : if (priv->sh->flow_mreg_c[id + start_reg - REG_C_0] == REG_NON)
1345 : 0 : return rte_flow_error_set(error, ENOTSUP,
1346 : : RTE_FLOW_ERROR_TYPE_ITEM,
1347 : : NULL, "unsupported tag id");
1348 : : /*
1349 : : * This case means meter is using the REG_C_x great than 2.
1350 : : * Take care not to conflict with meter color REG_C_x.
1351 : : * If the available index REG_C_y >= REG_C_x, skip the
1352 : : * color register.
1353 : : */
1354 [ # # # # ]: 0 : if (skip_mtr_reg && priv->sh->flow_mreg_c
1355 : : [id + start_reg - REG_C_0] >= reg->aso_reg) {
1356 [ # # ]: 0 : if (id >= (uint32_t)(REG_C_7 - start_reg))
1357 : 0 : return rte_flow_error_set(error, EINVAL,
1358 : : RTE_FLOW_ERROR_TYPE_ITEM,
1359 : : NULL, "invalid tag id");
1360 : 0 : if (priv->sh->flow_mreg_c
1361 [ # # ]: 0 : [id + 1 + start_reg - REG_C_0] != REG_NON)
1362 : : return priv->sh->flow_mreg_c
1363 : 0 : [id + 1 + start_reg - REG_C_0];
1364 : 0 : return rte_flow_error_set(error, ENOTSUP,
1365 : : RTE_FLOW_ERROR_TYPE_ITEM,
1366 : : NULL, "unsupported tag id");
1367 : : }
1368 : 0 : return priv->sh->flow_mreg_c[id + start_reg - REG_C_0];
1369 : : }
1370 : : MLX5_ASSERT(false);
1371 : 0 : return rte_flow_error_set(error, EINVAL,
1372 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1373 : : NULL, "invalid feature name");
1374 : : }
1375 : :
1376 : : /**
1377 : : * Check extensive flow metadata register support.
1378 : : *
1379 : : * @param dev
1380 : : * Pointer to rte_eth_dev structure.
1381 : : *
1382 : : * @return
1383 : : * True if device supports extensive flow metadata register, otherwise false.
1384 : : */
1385 : : bool
1386 : 0 : mlx5_flow_ext_mreg_supported(struct rte_eth_dev *dev)
1387 : : {
1388 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1389 : :
1390 : : /*
1391 : : * Having available reg_c can be regarded inclusively as supporting
1392 : : * extensive flow metadata register, which could mean,
1393 : : * - metadata register copy action by modify header.
1394 : : * - 16 modify header actions is supported.
1395 : : * - reg_c's are preserved across different domain (FDB and NIC) on
1396 : : * packet loopback by flow lookup miss.
1397 : : */
1398 : 0 : return priv->sh->flow_mreg_c[2] != REG_NON;
1399 : : }
1400 : :
1401 : : /**
1402 : : * Get the lowest priority.
1403 : : *
1404 : : * @param[in] dev
1405 : : * Pointer to the Ethernet device structure.
1406 : : * @param[in] attributes
1407 : : * Pointer to device flow rule attributes.
1408 : : *
1409 : : * @return
1410 : : * The value of lowest priority of flow.
1411 : : */
1412 : : uint32_t
1413 : 0 : mlx5_get_lowest_priority(struct rte_eth_dev *dev,
1414 : : const struct rte_flow_attr *attr)
1415 : : {
1416 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1417 : :
1418 [ # # # # : 0 : if (!attr->group && !(attr->transfer && priv->fdb_def_rule))
# # ]
1419 : 0 : return priv->sh->flow_max_priority - 2;
1420 : : return MLX5_NON_ROOT_FLOW_MAX_PRIO - 1;
1421 : : }
1422 : :
1423 : : /**
1424 : : * Calculate matcher priority of the flow.
1425 : : *
1426 : : * @param[in] dev
1427 : : * Pointer to the Ethernet device structure.
1428 : : * @param[in] attr
1429 : : * Pointer to device flow rule attributes.
1430 : : * @param[in] subpriority
1431 : : * The priority based on the items.
1432 : : * @param[in] external
1433 : : * Flow is user flow.
1434 : : * @return
1435 : : * The matcher priority of the flow.
1436 : : */
1437 : : uint16_t
1438 : 0 : mlx5_get_matcher_priority(struct rte_eth_dev *dev,
1439 : : const struct rte_flow_attr *attr,
1440 : : uint32_t subpriority, bool external)
1441 : : {
1442 : 0 : uint16_t priority = (uint16_t)attr->priority;
1443 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1444 : :
1445 : : /* NIC root rules */
1446 [ # # # # ]: 0 : if (!attr->group && !attr->transfer) {
1447 [ # # ]: 0 : if (attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)
1448 : 0 : priority = priv->sh->flow_max_priority - 1;
1449 : 0 : return mlx5_os_flow_adjust_priority(dev, priority, subpriority);
1450 : : /* FDB root rules */
1451 [ # # # # : 0 : } else if (attr->transfer && (!external || !priv->fdb_def_rule) &&
# # # # ]
1452 [ # # ]: 0 : attr->group == 0 &&
1453 : : attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR) {
1454 : 0 : return (priv->sh->flow_max_priority - 1) * 3;
1455 : : }
1456 [ # # ]: 0 : if (attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)
1457 : : priority = MLX5_NON_ROOT_FLOW_MAX_PRIO;
1458 : 0 : return priority * 3 + subpriority;
1459 : : }
1460 : :
1461 : : /**
1462 : : * Verify the @p item specifications (spec, last, mask) are compatible with the
1463 : : * NIC capabilities.
1464 : : *
1465 : : * @param[in] item
1466 : : * Item specification.
1467 : : * @param[in] mask
1468 : : * @p item->mask or flow default bit-masks.
1469 : : * @param[in] nic_mask
1470 : : * Bit-masks covering supported fields by the NIC to compare with user mask.
1471 : : * @param[in] size
1472 : : * Bit-masks size in bytes.
1473 : : * @param[in] range_accepted
1474 : : * True if range of values is accepted for specific fields, false otherwise.
1475 : : * @param[out] error
1476 : : * Pointer to error structure.
1477 : : *
1478 : : * @return
1479 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1480 : : */
1481 : : int
1482 : 0 : mlx5_flow_item_acceptable(const struct rte_eth_dev *dev,
1483 : : const struct rte_flow_item *item,
1484 : : const uint8_t *mask,
1485 : : const uint8_t *nic_mask,
1486 : : unsigned int size,
1487 : : bool range_accepted,
1488 : : struct rte_flow_error *error)
1489 : : {
1490 : : unsigned int i;
1491 : :
1492 : : MLX5_ASSERT(nic_mask);
1493 [ # # ]: 0 : for (i = 0; i < size; ++i)
1494 [ # # ]: 0 : if ((nic_mask[i] | mask[i]) != nic_mask[i])
1495 : 0 : return rte_flow_error_set(error, ENOTSUP,
1496 : : RTE_FLOW_ERROR_TYPE_ITEM,
1497 : : item,
1498 : : "mask enables non supported"
1499 : : " bits");
1500 [ # # ]: 0 : if (mlx5_hws_active(dev))
1501 : : return 0;
1502 [ # # # # : 0 : if (!item->spec && (item->mask || item->last))
# # ]
1503 : 0 : return rte_flow_error_set(error, EINVAL,
1504 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
1505 : : "mask/last without a spec is not"
1506 : : " supported");
1507 [ # # # # : 0 : if (item->spec && item->last && !range_accepted) {
# # ]
1508 : 0 : uint8_t *spec = alloca(size);
1509 : 0 : uint8_t *last = alloca(size);
1510 : : unsigned int i;
1511 : : int ret;
1512 : :
1513 [ # # ]: 0 : for (i = 0; i < size; ++i) {
1514 : 0 : spec[i] = ((const uint8_t *)item->spec)[i] & mask[i];
1515 : 0 : last[i] = ((const uint8_t *)item->last)[i] & mask[i];
1516 : : }
1517 : 0 : ret = memcmp(spec, last, size);
1518 [ # # ]: 0 : if (ret != 0)
1519 : 0 : return rte_flow_error_set(error, EINVAL,
1520 : : RTE_FLOW_ERROR_TYPE_ITEM,
1521 : : item,
1522 : : "range is not valid");
1523 : : }
1524 : : return 0;
1525 : : }
1526 : :
1527 : : /**
1528 : : * Adjust the hash fields according to the @p flow information.
1529 : : *
1530 : : * @param[in] dev_flow.
1531 : : * Pointer to the mlx5_flow.
1532 : : * @param[in] tunnel
1533 : : * 1 when the hash field is for a tunnel item.
1534 : : * @param[in] layer_types
1535 : : * RTE_ETH_RSS_* types.
1536 : : * @param[in] hash_fields
1537 : : * Item hash fields.
1538 : : *
1539 : : * @return
1540 : : * The hash fields that should be used.
1541 : : */
1542 : : uint64_t
1543 : 0 : mlx5_flow_hashfields_adjust(struct mlx5_flow_rss_desc *rss_desc,
1544 : : int tunnel __rte_unused, uint64_t layer_types,
1545 : : uint64_t hash_fields)
1546 : : {
1547 : : #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1548 : 0 : int rss_request_inner = rss_desc->level >= 2;
1549 : :
1550 : : /* Check RSS hash level for tunnel. */
1551 [ # # ]: 0 : if (tunnel && rss_request_inner)
1552 : 0 : hash_fields |= IBV_RX_HASH_INNER;
1553 [ # # ]: 0 : else if (tunnel || rss_request_inner)
1554 : : return 0;
1555 : : #endif
1556 : : /* Check if requested layer matches RSS hash fields. */
1557 [ # # ]: 0 : if (!(rss_desc->types & layer_types))
1558 : 0 : return 0;
1559 : : return hash_fields;
1560 : : }
1561 : :
1562 : : /**
1563 : : * Lookup and set the ptype in the data Rx part. A single Ptype can be used,
1564 : : * if several tunnel rules are used on this queue, the tunnel ptype will be
1565 : : * cleared.
1566 : : *
1567 : : * @param rxq_ctrl
1568 : : * Rx queue to update.
1569 : : */
1570 : : static void
1571 : : flow_rxq_tunnel_ptype_update(struct mlx5_rxq_ctrl *rxq_ctrl)
1572 : : {
1573 : : unsigned int i;
1574 : : uint32_t tunnel_ptype = 0;
1575 : :
1576 : : /* Look up for the ptype to use. */
1577 [ # # # # ]: 0 : for (i = 0; i != MLX5_FLOW_TUNNEL; ++i) {
1578 [ # # # # ]: 0 : if (!rxq_ctrl->flow_tunnels_n[i])
1579 : 0 : continue;
1580 [ # # # # ]: 0 : if (!tunnel_ptype) {
1581 : 0 : tunnel_ptype = tunnels_info[i].ptype;
1582 : : } else {
1583 : : tunnel_ptype = 0;
1584 : : break;
1585 : : }
1586 : : }
1587 : 0 : rxq_ctrl->rxq.tunnel = tunnel_ptype;
1588 : 0 : }
1589 : :
1590 : : /**
1591 : : * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) according to the device
1592 : : * flow.
1593 : : *
1594 : : * @param[in] dev
1595 : : * Pointer to the Ethernet device structure.
1596 : : * @param[in] dev_handle
1597 : : * Pointer to device flow handle structure.
1598 : : */
1599 : : void
1600 : 0 : flow_drv_rxq_flags_set(struct rte_eth_dev *dev,
1601 : : struct mlx5_flow_handle *dev_handle)
1602 : : {
1603 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1604 : 0 : const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1605 : : struct mlx5_ind_table_obj *ind_tbl = NULL;
1606 : : unsigned int i;
1607 : :
1608 [ # # ]: 0 : if (dev_handle->fate_action == MLX5_FLOW_FATE_QUEUE) {
1609 : : struct mlx5_hrxq *hrxq;
1610 : :
1611 : 0 : hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1612 : : dev_handle->rix_hrxq);
1613 [ # # ]: 0 : if (hrxq)
1614 : 0 : ind_tbl = hrxq->ind_table;
1615 [ # # ]: 0 : } else if (dev_handle->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
1616 : : struct mlx5_shared_action_rss *shared_rss;
1617 : :
1618 : 0 : shared_rss = mlx5_ipool_get
1619 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
1620 : : dev_handle->rix_srss);
1621 [ # # ]: 0 : if (shared_rss)
1622 : 0 : ind_tbl = shared_rss->ind_tbl;
1623 : : }
1624 [ # # ]: 0 : if (!ind_tbl)
1625 : 0 : return;
1626 [ # # ]: 0 : for (i = 0; i != ind_tbl->queues_n; ++i) {
1627 [ # # ]: 0 : int idx = ind_tbl->queues[i];
1628 : : struct mlx5_rxq_ctrl *rxq_ctrl;
1629 : :
1630 [ # # ]: 0 : if (mlx5_is_external_rxq(dev, idx))
1631 : 0 : continue;
1632 : 0 : rxq_ctrl = mlx5_rxq_ctrl_get(dev, idx);
1633 : : MLX5_ASSERT(rxq_ctrl != NULL);
1634 [ # # ]: 0 : if (rxq_ctrl == NULL)
1635 : 0 : continue;
1636 : : /*
1637 : : * To support metadata register copy on Tx loopback,
1638 : : * this must be always enabled (metadata may arive
1639 : : * from other port - not from local flows only.
1640 : : */
1641 [ # # ]: 0 : if (tunnel) {
1642 : : unsigned int j;
1643 : :
1644 : : /* Increase the counter matching the flow. */
1645 [ # # ]: 0 : for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1646 : 0 : if ((tunnels_info[j].tunnel &
1647 [ # # ]: 0 : dev_handle->layers) ==
1648 : : tunnels_info[j].tunnel) {
1649 : 0 : rxq_ctrl->flow_tunnels_n[j]++;
1650 : 0 : break;
1651 : : }
1652 : : }
1653 : : flow_rxq_tunnel_ptype_update(rxq_ctrl);
1654 : : }
1655 : : }
1656 : : }
1657 : :
1658 : : void
1659 : 0 : mlx5_flow_rxq_mark_flag_set(struct rte_eth_dev *dev)
1660 : : {
1661 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1662 : : struct mlx5_rxq_ctrl *rxq_ctrl;
1663 : : uint16_t port_id;
1664 : :
1665 [ # # ]: 0 : if (priv->sh->shared_mark_enabled)
1666 : : return;
1667 [ # # ]: 0 : if (priv->master || priv->representor) {
1668 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port_id, dev->device) {
1669 : 0 : struct mlx5_priv *opriv =
1670 : 0 : rte_eth_devices[port_id].data->dev_private;
1671 : :
1672 [ # # ]: 0 : if (!opriv ||
1673 [ # # ]: 0 : opriv->sh != priv->sh ||
1674 [ # # # # ]: 0 : opriv->domain_id != priv->domain_id ||
1675 : : opriv->mark_enabled)
1676 : 0 : continue;
1677 [ # # ]: 0 : LIST_FOREACH(rxq_ctrl, &opriv->rxqsctrl, next) {
1678 : 0 : rxq_ctrl->rxq.mark = 1;
1679 : : }
1680 [ # # ]: 0 : LIST_FOREACH(rxq_ctrl, &opriv->sh->shared_rxqs, next) {
1681 : 0 : rxq_ctrl->rxq.mark = 1;
1682 : : }
1683 : 0 : opriv->mark_enabled = 1;
1684 : : }
1685 : : } else {
1686 [ # # ]: 0 : LIST_FOREACH(rxq_ctrl, &priv->rxqsctrl, next) {
1687 : 0 : rxq_ctrl->rxq.mark = 1;
1688 : : }
1689 [ # # ]: 0 : LIST_FOREACH(rxq_ctrl, &priv->sh->shared_rxqs, next) {
1690 : 0 : rxq_ctrl->rxq.mark = 1;
1691 : : }
1692 : 0 : priv->mark_enabled = 1;
1693 : : }
1694 : 0 : priv->sh->shared_mark_enabled = 1;
1695 : : }
1696 : :
1697 : : /**
1698 : : * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) for a flow
1699 : : *
1700 : : * @param[in] dev
1701 : : * Pointer to the Ethernet device structure.
1702 : : * @param[in] flow
1703 : : * Pointer to flow structure.
1704 : : */
1705 : : static void
1706 : 0 : flow_rxq_flags_set(struct rte_eth_dev *dev, struct rte_flow *flow)
1707 : : {
1708 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1709 : : uint32_t handle_idx;
1710 : : struct mlx5_flow_handle *dev_handle;
1711 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
1712 : :
1713 : : MLX5_ASSERT(wks);
1714 [ # # ]: 0 : if (wks->mark)
1715 : 0 : mlx5_flow_rxq_mark_flag_set(dev);
1716 [ # # # # : 0 : SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
# # ]
1717 : : handle_idx, dev_handle, next)
1718 : 0 : flow_drv_rxq_flags_set(dev, dev_handle);
1719 : 0 : }
1720 : :
1721 : : /**
1722 : : * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1723 : : * device flow if no other flow uses it with the same kind of request.
1724 : : *
1725 : : * @param dev
1726 : : * Pointer to Ethernet device.
1727 : : * @param[in] dev_handle
1728 : : * Pointer to the device flow handle structure.
1729 : : */
1730 : : static void
1731 : 0 : flow_drv_rxq_flags_trim(struct rte_eth_dev *dev,
1732 : : struct mlx5_flow_handle *dev_handle)
1733 : : {
1734 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1735 : 0 : const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1736 : : struct mlx5_ind_table_obj *ind_tbl = NULL;
1737 : : unsigned int i;
1738 : :
1739 [ # # ]: 0 : if (dev_handle->fate_action == MLX5_FLOW_FATE_QUEUE) {
1740 : : struct mlx5_hrxq *hrxq;
1741 : :
1742 : 0 : hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1743 : : dev_handle->rix_hrxq);
1744 [ # # ]: 0 : if (hrxq)
1745 : 0 : ind_tbl = hrxq->ind_table;
1746 [ # # ]: 0 : } else if (dev_handle->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
1747 : : struct mlx5_shared_action_rss *shared_rss;
1748 : :
1749 : 0 : shared_rss = mlx5_ipool_get
1750 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
1751 : : dev_handle->rix_srss);
1752 [ # # ]: 0 : if (shared_rss)
1753 : 0 : ind_tbl = shared_rss->ind_tbl;
1754 : : }
1755 [ # # ]: 0 : if (!ind_tbl)
1756 : 0 : return;
1757 : : MLX5_ASSERT(dev->data->dev_started);
1758 [ # # ]: 0 : for (i = 0; i != ind_tbl->queues_n; ++i) {
1759 [ # # ]: 0 : int idx = ind_tbl->queues[i];
1760 : : struct mlx5_rxq_ctrl *rxq_ctrl;
1761 : :
1762 [ # # ]: 0 : if (mlx5_is_external_rxq(dev, idx))
1763 : 0 : continue;
1764 : 0 : rxq_ctrl = mlx5_rxq_ctrl_get(dev, idx);
1765 : : MLX5_ASSERT(rxq_ctrl != NULL);
1766 [ # # ]: 0 : if (rxq_ctrl == NULL)
1767 : 0 : continue;
1768 [ # # ]: 0 : if (tunnel) {
1769 : : unsigned int j;
1770 : :
1771 : : /* Decrease the counter matching the flow. */
1772 [ # # ]: 0 : for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1773 : 0 : if ((tunnels_info[j].tunnel &
1774 [ # # ]: 0 : dev_handle->layers) ==
1775 : : tunnels_info[j].tunnel) {
1776 : 0 : rxq_ctrl->flow_tunnels_n[j]--;
1777 : 0 : break;
1778 : : }
1779 : : }
1780 : : flow_rxq_tunnel_ptype_update(rxq_ctrl);
1781 : : }
1782 : : }
1783 : : }
1784 : :
1785 : : /**
1786 : : * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1787 : : * @p flow if no other flow uses it with the same kind of request.
1788 : : *
1789 : : * @param dev
1790 : : * Pointer to Ethernet device.
1791 : : * @param[in] flow
1792 : : * Pointer to the flow.
1793 : : */
1794 : : static void
1795 : 0 : flow_rxq_flags_trim(struct rte_eth_dev *dev, struct rte_flow *flow)
1796 : : {
1797 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1798 : : uint32_t handle_idx;
1799 : : struct mlx5_flow_handle *dev_handle;
1800 : :
1801 [ # # # # : 0 : SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
# # ]
1802 : : handle_idx, dev_handle, next)
1803 : 0 : flow_drv_rxq_flags_trim(dev, dev_handle);
1804 : 0 : }
1805 : :
1806 : : /**
1807 : : * Clear the Mark/Flag and Tunnel ptype information in all Rx queues.
1808 : : *
1809 : : * @param dev
1810 : : * Pointer to Ethernet device.
1811 : : */
1812 : : void
1813 : 0 : mlx5_flow_rxq_flags_clear(struct rte_eth_dev *dev)
1814 : : {
1815 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1816 : : unsigned int i;
1817 : :
1818 [ # # ]: 0 : for (i = 0; i != priv->rxqs_n; ++i) {
1819 : 0 : struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, i);
1820 : : unsigned int j;
1821 : :
1822 [ # # # # ]: 0 : if (rxq == NULL || rxq->ctrl == NULL)
1823 : 0 : continue;
1824 : 0 : rxq->ctrl->rxq.mark = 0;
1825 [ # # ]: 0 : for (j = 0; j != MLX5_FLOW_TUNNEL; ++j)
1826 : 0 : rxq->ctrl->flow_tunnels_n[j] = 0;
1827 : 0 : rxq->ctrl->rxq.tunnel = 0;
1828 : : }
1829 : 0 : priv->mark_enabled = 0;
1830 : 0 : priv->sh->shared_mark_enabled = 0;
1831 : 0 : }
1832 : :
1833 : : static uint64_t mlx5_restore_info_dynflag;
1834 : :
1835 : : int
1836 : 0 : mlx5_flow_rx_metadata_negotiate(struct rte_eth_dev *dev, uint64_t *features)
1837 : : {
1838 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
1839 : : uint64_t supported = 0;
1840 : :
1841 [ # # ]: 0 : if (!is_tunnel_offload_active(dev)) {
1842 : : supported |= RTE_ETH_RX_METADATA_USER_FLAG;
1843 : : supported |= RTE_ETH_RX_METADATA_USER_MARK;
1844 [ # # ]: 0 : if ((*features & RTE_ETH_RX_METADATA_TUNNEL_ID) != 0) {
1845 : 0 : DRV_LOG(DEBUG,
1846 : : "tunnel offload was not activated, consider setting dv_xmeta_en=%d",
1847 : : MLX5_XMETA_MODE_MISS_INFO);
1848 : : }
1849 : : } else {
1850 : : supported |= RTE_ETH_RX_METADATA_TUNNEL_ID;
1851 [ # # ]: 0 : if ((*features & RTE_ETH_RX_METADATA_TUNNEL_ID) != 0 &&
1852 [ # # ]: 0 : mlx5_restore_info_dynflag == 0)
1853 : 0 : mlx5_restore_info_dynflag = rte_flow_restore_info_dynflag();
1854 : : }
1855 : :
1856 [ # # ]: 0 : if (((*features & supported) & RTE_ETH_RX_METADATA_TUNNEL_ID) != 0)
1857 : 0 : priv->tunnel_enabled = 1;
1858 : : else
1859 : 0 : priv->tunnel_enabled = 0;
1860 : :
1861 : 0 : *features &= supported;
1862 : 0 : return 0;
1863 : : }
1864 : :
1865 : : /**
1866 : : * Set the Rx queue dynamic metadata (mask and offset) for a flow
1867 : : *
1868 : : * @param[in] dev
1869 : : * Pointer to the Ethernet device structure.
1870 : : */
1871 : : void
1872 : 0 : mlx5_flow_rxq_dynf_set(struct rte_eth_dev *dev)
1873 : : {
1874 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1875 : : uint64_t mark_flag = RTE_MBUF_F_RX_FDIR_ID;
1876 : : unsigned int i;
1877 : :
1878 [ # # ]: 0 : if (priv->tunnel_enabled)
1879 : 0 : mark_flag |= mlx5_restore_info_dynflag;
1880 : :
1881 [ # # ]: 0 : for (i = 0; i != priv->rxqs_n; ++i) {
1882 : 0 : struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, i);
1883 : : struct mlx5_rxq_data *data;
1884 : :
1885 [ # # # # ]: 0 : if (rxq == NULL || rxq->ctrl == NULL)
1886 : 0 : continue;
1887 : : data = &rxq->ctrl->rxq;
1888 [ # # # # ]: 0 : if (!data->shared || !rxq->ctrl->started) {
1889 [ # # ]: 0 : if (!rte_flow_dynf_metadata_avail()) {
1890 : 0 : data->dynf_meta = 0;
1891 : 0 : data->flow_meta_mask = 0;
1892 : 0 : data->flow_meta_offset = -1;
1893 : 0 : data->flow_meta_port_mask = 0;
1894 : : } else {
1895 : 0 : data->dynf_meta = 1;
1896 : 0 : data->flow_meta_mask = rte_flow_dynf_metadata_mask;
1897 : 0 : data->flow_meta_offset = rte_flow_dynf_metadata_offs;
1898 : 0 : data->flow_meta_port_mask = priv->sh->dv_meta_mask;
1899 : : }
1900 : : }
1901 : 0 : data->mark_flag = mark_flag;
1902 : : }
1903 : 0 : }
1904 : :
1905 : : /*
1906 : : * return a pointer to the desired action in the list of actions.
1907 : : *
1908 : : * @param[in] actions
1909 : : * The list of actions to search the action in.
1910 : : * @param[in] action
1911 : : * The action to find.
1912 : : *
1913 : : * @return
1914 : : * Pointer to the action in the list, if found. NULL otherwise.
1915 : : */
1916 : : const struct rte_flow_action *
1917 : 0 : mlx5_flow_find_action(const struct rte_flow_action *actions,
1918 : : enum rte_flow_action_type action)
1919 : : {
1920 [ # # ]: 0 : if (actions == NULL)
1921 : : return NULL;
1922 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++)
1923 [ # # ]: 0 : if (actions->type == action)
1924 : 0 : return actions;
1925 : : return NULL;
1926 : : }
1927 : :
1928 : : /*
1929 : : * Validate the flag action.
1930 : : *
1931 : : * @param[in] action_flags
1932 : : * Bit-fields that holds the actions detected until now.
1933 : : * @param[in] attr
1934 : : * Attributes of flow that includes this action.
1935 : : * @param[out] error
1936 : : * Pointer to error structure.
1937 : : *
1938 : : * @return
1939 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1940 : : */
1941 : : int
1942 : 0 : mlx5_flow_validate_action_flag(uint64_t action_flags,
1943 : : const struct rte_flow_attr *attr,
1944 : : struct rte_flow_error *error)
1945 : : {
1946 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
1947 : 0 : return rte_flow_error_set(error, EINVAL,
1948 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1949 : : "can't mark and flag in same flow");
1950 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_FLAG)
1951 : 0 : return rte_flow_error_set(error, EINVAL,
1952 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1953 : : "can't have 2 flag"
1954 : : " actions in same flow");
1955 [ # # ]: 0 : if (attr->egress)
1956 : 0 : return rte_flow_error_set(error, ENOTSUP,
1957 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1958 : : "flag action not supported for "
1959 : : "egress");
1960 : : return 0;
1961 : : }
1962 : :
1963 : : /*
1964 : : * Validate the mark action.
1965 : : *
1966 : : * @param[in] action
1967 : : * Pointer to the queue action.
1968 : : * @param[in] action_flags
1969 : : * Bit-fields that holds the actions detected until now.
1970 : : * @param[in] attr
1971 : : * Attributes of flow that includes this action.
1972 : : * @param[out] error
1973 : : * Pointer to error structure.
1974 : : *
1975 : : * @return
1976 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1977 : : */
1978 : : int
1979 : 0 : mlx5_flow_validate_action_mark(__rte_unused struct rte_eth_dev *dev,
1980 : : const struct rte_flow_action *action,
1981 : : uint64_t action_flags,
1982 : : const struct rte_flow_attr *attr,
1983 : : struct rte_flow_error *error)
1984 : : {
1985 : 0 : const struct rte_flow_action_mark *mark = action->conf;
1986 : :
1987 [ # # ]: 0 : if (!mark)
1988 : 0 : return rte_flow_error_set(error, EINVAL,
1989 : : RTE_FLOW_ERROR_TYPE_ACTION,
1990 : : action,
1991 : : "configuration cannot be null");
1992 [ # # ]: 0 : if (mark->id >= MLX5_FLOW_MARK_MAX)
1993 : 0 : return rte_flow_error_set(error, EINVAL,
1994 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1995 : 0 : &mark->id,
1996 : : "mark id must in 0 <= id < "
1997 : : RTE_STR(MLX5_FLOW_MARK_MAX));
1998 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_FLAG)
1999 : 0 : return rte_flow_error_set(error, EINVAL,
2000 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2001 : : "can't flag and mark in same flow");
2002 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
2003 : 0 : return rte_flow_error_set(error, EINVAL,
2004 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2005 : : "can't have 2 mark actions in same"
2006 : : " flow");
2007 [ # # ]: 0 : if (attr->egress)
2008 : 0 : return rte_flow_error_set(error, ENOTSUP,
2009 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
2010 : : "mark action not supported for "
2011 : : "egress");
2012 : : return 0;
2013 : : }
2014 : :
2015 : : /*
2016 : : * Validate the drop action.
2017 : : *
2018 : : * @param[in] dev
2019 : : * Pointer to the Ethernet device structure.
2020 : : * @param[in] is_root
2021 : : * True if flow is validated for root table. False otherwise.
2022 : : * @param[in] attr
2023 : : * Attributes of flow that includes this action.
2024 : : * @param[out] error
2025 : : * Pointer to error structure.
2026 : : *
2027 : : * @return
2028 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2029 : : */
2030 : : int
2031 : 0 : mlx5_flow_validate_action_drop(struct rte_eth_dev *dev,
2032 : : bool is_root,
2033 : : const struct rte_flow_attr *attr,
2034 : : struct rte_flow_error *error)
2035 : : {
2036 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2037 : :
2038 [ # # # # ]: 0 : if (priv->sh->config.dv_flow_en == 0 && attr->egress)
2039 : 0 : return rte_flow_error_set(error, ENOTSUP,
2040 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
2041 : : "drop action not supported for "
2042 : : "egress");
2043 [ # # # # : 0 : if (priv->sh->config.dv_flow_en == 1 && is_root && (attr->egress || attr->transfer) &&
# # ]
2044 [ # # ]: 0 : !priv->sh->dr_root_drop_action_en) {
2045 : 0 : return rte_flow_error_set(error, ENOTSUP,
2046 : : RTE_FLOW_ERROR_TYPE_ATTR, NULL,
2047 : : "drop action not supported for "
2048 : : "egress and transfer on group 0");
2049 : : }
2050 : : return 0;
2051 : : }
2052 : :
2053 : : /*
2054 : : * Check if a queue specified in the queue action is valid.
2055 : : *
2056 : : * @param[in] dev
2057 : : * Pointer to the Ethernet device structure.
2058 : : * @param[in] action
2059 : : * Pointer to the queue action.
2060 : : * @param[out] error
2061 : : * Pointer to error structure.
2062 : : *
2063 : : * @return
2064 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2065 : : */
2066 : : int
2067 : 0 : mlx5_flow_validate_target_queue(struct rte_eth_dev *dev,
2068 : : const struct rte_flow_action *action,
2069 : : struct rte_flow_error *error)
2070 : : {
2071 : 0 : const struct rte_flow_action_queue *queue = action->conf;
2072 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2073 : :
2074 [ # # # # ]: 0 : if (mlx5_is_external_rxq(dev, queue->index))
2075 : : return 0;
2076 [ # # ]: 0 : if (!priv->rxqs_n)
2077 : 0 : return rte_flow_error_set(error, EINVAL,
2078 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2079 : : NULL, "No Rx queues configured");
2080 [ # # ]: 0 : if (queue->index >= priv->rxqs_n)
2081 : 0 : return rte_flow_error_set(error, EINVAL,
2082 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2083 : 0 : &queue->index,
2084 : : "queue index out of range");
2085 [ # # ]: 0 : if (mlx5_rxq_get(dev, queue->index) == NULL)
2086 : 0 : return rte_flow_error_set(error, EINVAL,
2087 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2088 : 0 : &queue->index,
2089 : : "queue is not configured");
2090 : : return 0;
2091 : : }
2092 : :
2093 : : /*
2094 : : * Validate the queue action.
2095 : : *
2096 : : * @param[in] action
2097 : : * Pointer to the queue action.
2098 : : * @param[in] action_flags
2099 : : * Bit-fields that holds the actions detected until now.
2100 : : * @param[in] dev
2101 : : * Pointer to the Ethernet device structure.
2102 : : * @param[in] attr
2103 : : * Attributes of flow that includes this action.
2104 : : * @param[out] error
2105 : : * Pointer to error structure.
2106 : : *
2107 : : * @return
2108 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2109 : : */
2110 : : int
2111 : 0 : mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
2112 : : uint64_t action_flags,
2113 : : struct rte_eth_dev *dev,
2114 : : const struct rte_flow_attr *attr,
2115 : : struct rte_flow_error *error)
2116 : : {
2117 : 0 : const struct rte_flow_action_queue *queue = action->conf;
2118 : :
2119 [ # # ]: 0 : if (!queue)
2120 : 0 : return rte_flow_error_set(error, EINVAL,
2121 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
2122 : : "no QUEUE action configuration");
2123 [ # # ]: 0 : if (action_flags & MLX5_FLOW_FATE_ACTIONS)
2124 : 0 : return rte_flow_error_set(error, EINVAL,
2125 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2126 : : "can't have 2 fate actions in"
2127 : : " same flow");
2128 [ # # ]: 0 : if (attr->egress)
2129 : 0 : return rte_flow_error_set(error, ENOTSUP,
2130 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
2131 : : "queue action not supported for egress.");
2132 : 0 : return mlx5_flow_validate_target_queue(dev, action, error);
2133 : : }
2134 : :
2135 : : /**
2136 : : * Validate queue numbers for device RSS.
2137 : : *
2138 : : * @param[in] dev
2139 : : * Configured device.
2140 : : * @param[in] queues
2141 : : * Array of queue numbers.
2142 : : * @param[in] queues_n
2143 : : * Size of the @p queues array.
2144 : : * @param[out] error
2145 : : * On error, filled with a textual error description.
2146 : : * @param[out] queue_idx
2147 : : * On error, filled with an offending queue index in @p queues array.
2148 : : *
2149 : : * @return
2150 : : * 0 on success, a negative errno code on error.
2151 : : */
2152 : : static int
2153 : 0 : mlx5_validate_rss_queues(struct rte_eth_dev *dev,
2154 : : const uint16_t *queues, uint32_t queues_n,
2155 : : const char **error, uint32_t *queue_idx)
2156 : : {
2157 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
2158 : : bool is_hairpin = false;
2159 : : bool is_ext_rss = false;
2160 : : uint32_t i;
2161 : :
2162 [ # # ]: 0 : for (i = 0; i != queues_n; ++i) {
2163 : : struct mlx5_rxq_ctrl *rxq_ctrl;
2164 : :
2165 [ # # # # ]: 0 : if (mlx5_is_external_rxq(dev, queues[0])) {
2166 : : is_ext_rss = true;
2167 : 0 : continue;
2168 : : }
2169 [ # # ]: 0 : if (is_ext_rss) {
2170 : 0 : *error = "Combining external and regular RSS queues is not supported";
2171 : 0 : *queue_idx = i;
2172 : 0 : return -ENOTSUP;
2173 : : }
2174 [ # # ]: 0 : if (queues[i] >= priv->rxqs_n) {
2175 : 0 : *error = "queue index out of range";
2176 : 0 : *queue_idx = i;
2177 : 0 : return -EINVAL;
2178 : : }
2179 : 0 : rxq_ctrl = mlx5_rxq_ctrl_get(dev, queues[i]);
2180 [ # # ]: 0 : if (rxq_ctrl == NULL) {
2181 : 0 : *error = "queue is not configured";
2182 : 0 : *queue_idx = i;
2183 : 0 : return -EINVAL;
2184 : : }
2185 [ # # # # ]: 0 : if (i == 0 && rxq_ctrl->is_hairpin)
2186 : : is_hairpin = true;
2187 [ # # ]: 0 : if (is_hairpin != rxq_ctrl->is_hairpin) {
2188 : 0 : *error = "combining hairpin and regular RSS queues is not supported";
2189 : 0 : *queue_idx = i;
2190 : 0 : return -ENOTSUP;
2191 : : }
2192 : : }
2193 : : return 0;
2194 : : }
2195 : :
2196 : : /*
2197 : : * Validate the rss action.
2198 : : *
2199 : : * @param[in] dev
2200 : : * Pointer to the Ethernet device structure.
2201 : : * @param[in] action
2202 : : * Pointer to the queue action.
2203 : : * @param[out] error
2204 : : * Pointer to error structure.
2205 : : *
2206 : : * @return
2207 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2208 : : */
2209 : : int
2210 : 0 : mlx5_validate_action_rss(struct rte_eth_dev *dev,
2211 : : const struct rte_flow_action *action,
2212 : : struct rte_flow_error *error)
2213 : : {
2214 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2215 : 0 : const struct rte_flow_action_rss *rss = action->conf;
2216 : : int ret;
2217 : : const char *message;
2218 : : uint32_t queue_idx;
2219 : :
2220 [ # # ]: 0 : if (!rss)
2221 : 0 : return rte_flow_error_set
2222 : : (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
2223 : : action, "no RSS action configuration");
2224 [ # # ]: 0 : if (rss->func == RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ) {
2225 : 0 : DRV_LOG(WARNING, "port %u symmetric RSS supported with SORT",
2226 : : dev->data->port_id);
2227 [ # # ]: 0 : } else if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
2228 : : rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
2229 : 0 : return rte_flow_error_set(error, ENOTSUP,
2230 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2231 : 0 : &rss->func,
2232 : : "RSS hash function not supported");
2233 : : #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
2234 [ # # ]: 0 : if (rss->level > 2)
2235 : : #else
2236 : : if (rss->level > 1)
2237 : : #endif
2238 : 0 : return rte_flow_error_set(error, ENOTSUP,
2239 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2240 : 0 : &rss->level,
2241 : : "tunnel RSS is not supported");
2242 : : /* allow RSS key_len 0 in case of NULL (default) RSS key. */
2243 [ # # # # ]: 0 : if (rss->key_len == 0 && rss->key != NULL)
2244 : 0 : return rte_flow_error_set(error, ENOTSUP,
2245 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2246 : 0 : &rss->key_len,
2247 : : "RSS hash key length 0");
2248 [ # # ]: 0 : if (rss->key_len > 0 && rss->key_len < MLX5_RSS_HASH_KEY_LEN)
2249 : 0 : return rte_flow_error_set(error, ENOTSUP,
2250 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2251 : 0 : &rss->key_len,
2252 : : "RSS hash key too small");
2253 [ # # ]: 0 : if (rss->key_len > MLX5_RSS_HASH_KEY_LEN)
2254 : 0 : return rte_flow_error_set(error, ENOTSUP,
2255 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2256 : 0 : &rss->key_len,
2257 : : "RSS hash key too large");
2258 [ # # ]: 0 : if (rss->queue_num > priv->sh->dev_cap.ind_table_max_size)
2259 : 0 : return rte_flow_error_set(error, ENOTSUP,
2260 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2261 : 0 : &rss->queue_num,
2262 : : "number of queues too large");
2263 [ # # ]: 0 : if (rss->types & MLX5_RSS_HF_MASK)
2264 : 0 : return rte_flow_error_set(error, ENOTSUP,
2265 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2266 : 0 : &rss->types,
2267 : : "some RSS protocols are not"
2268 : : " supported");
2269 [ # # ]: 0 : if ((rss->types & (RTE_ETH_RSS_L3_SRC_ONLY | RTE_ETH_RSS_L3_DST_ONLY)) &&
2270 [ # # ]: 0 : !(rss->types & RTE_ETH_RSS_IP))
2271 : 0 : return rte_flow_error_set(error, EINVAL,
2272 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
2273 : : "L3 partial RSS requested but L3 RSS"
2274 : : " type not specified");
2275 [ # # ]: 0 : if ((rss->types & (RTE_ETH_RSS_L4_SRC_ONLY | RTE_ETH_RSS_L4_DST_ONLY)) &&
2276 [ # # ]: 0 : !(rss->types & (RTE_ETH_RSS_UDP | RTE_ETH_RSS_TCP)))
2277 : 0 : return rte_flow_error_set(error, EINVAL,
2278 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
2279 : : "L4 partial RSS requested but L4 RSS"
2280 : : " type not specified");
2281 [ # # # # ]: 0 : if (!priv->rxqs_n && priv->ext_rxqs == NULL)
2282 : 0 : return rte_flow_error_set(error, EINVAL,
2283 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2284 : : NULL, "No Rx queues configured");
2285 [ # # ]: 0 : if (!rss->queue_num)
2286 : 0 : return rte_flow_error_set(error, EINVAL,
2287 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2288 : : NULL, "No queues configured");
2289 : 0 : ret = mlx5_validate_rss_queues(dev, rss->queue, rss->queue_num,
2290 : : &message, &queue_idx);
2291 [ # # ]: 0 : if (ret != 0) {
2292 : 0 : return rte_flow_error_set(error, -ret,
2293 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2294 : 0 : &rss->queue[queue_idx], message);
2295 : : }
2296 : : return 0;
2297 : : }
2298 : :
2299 : : /*
2300 : : * Validate the rss action.
2301 : : *
2302 : : * @param[in] action
2303 : : * Pointer to the queue action.
2304 : : * @param[in] action_flags
2305 : : * Bit-fields that holds the actions detected until now.
2306 : : * @param[in] dev
2307 : : * Pointer to the Ethernet device structure.
2308 : : * @param[in] attr
2309 : : * Attributes of flow that includes this action.
2310 : : * @param[in] item_flags
2311 : : * Items that were detected.
2312 : : * @param[out] error
2313 : : * Pointer to error structure.
2314 : : *
2315 : : * @return
2316 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2317 : : */
2318 : : int
2319 : 0 : mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
2320 : : uint64_t action_flags,
2321 : : struct rte_eth_dev *dev,
2322 : : const struct rte_flow_attr *attr,
2323 : : uint64_t item_flags,
2324 : : struct rte_flow_error *error)
2325 : : {
2326 : 0 : const struct rte_flow_action_rss *rss = action->conf;
2327 : 0 : int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2328 : : int ret;
2329 : :
2330 [ # # ]: 0 : if (action_flags & MLX5_FLOW_FATE_ACTIONS)
2331 : 0 : return rte_flow_error_set(error, EINVAL,
2332 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2333 : : "can't have 2 fate actions"
2334 : : " in same flow");
2335 : 0 : ret = mlx5_validate_action_rss(dev, action, error);
2336 [ # # ]: 0 : if (ret)
2337 : : return ret;
2338 [ # # ]: 0 : if (attr->egress)
2339 : 0 : return rte_flow_error_set(error, ENOTSUP,
2340 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
2341 : : "rss action not supported for "
2342 : : "egress");
2343 [ # # # # ]: 0 : if (rss->level > 1 && !tunnel)
2344 : 0 : return rte_flow_error_set(error, EINVAL,
2345 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
2346 : : "inner RSS is not supported for "
2347 : : "non-tunnel flows");
2348 [ # # ]: 0 : if ((item_flags & MLX5_FLOW_LAYER_ECPRI) &&
2349 : : !(item_flags & MLX5_FLOW_LAYER_INNER_L4_UDP)) {
2350 : 0 : return rte_flow_error_set(error, EINVAL,
2351 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
2352 : : "RSS on eCPRI is not supported now");
2353 : : }
2354 [ # # ]: 0 : if ((item_flags & MLX5_FLOW_LAYER_MPLS) &&
2355 : : !(item_flags &
2356 [ # # ]: 0 : (MLX5_FLOW_LAYER_INNER_L2 | MLX5_FLOW_LAYER_INNER_L3)) &&
2357 : : rss->level > 1)
2358 : 0 : return rte_flow_error_set(error, EINVAL,
2359 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2360 : : "MPLS inner RSS needs to specify inner L2/L3 items after MPLS in pattern");
2361 : : return 0;
2362 : : }
2363 : :
2364 : : /*
2365 : : * Validate the default miss action.
2366 : : *
2367 : : * @param[in] action_flags
2368 : : * Bit-fields that holds the actions detected until now.
2369 : : * @param[out] error
2370 : : * Pointer to error structure.
2371 : : *
2372 : : * @return
2373 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2374 : : */
2375 : : int
2376 : 0 : mlx5_flow_validate_action_default_miss(uint64_t action_flags,
2377 : : const struct rte_flow_attr *attr,
2378 : : struct rte_flow_error *error)
2379 : : {
2380 [ # # ]: 0 : if (action_flags & MLX5_FLOW_FATE_ACTIONS)
2381 : 0 : return rte_flow_error_set(error, EINVAL,
2382 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2383 : : "can't have 2 fate actions in"
2384 : : " same flow");
2385 [ # # ]: 0 : if (attr->egress)
2386 : 0 : return rte_flow_error_set(error, ENOTSUP,
2387 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
2388 : : "default miss action not supported "
2389 : : "for egress");
2390 [ # # ]: 0 : if (attr->group)
2391 : 0 : return rte_flow_error_set(error, ENOTSUP,
2392 : : RTE_FLOW_ERROR_TYPE_ATTR_GROUP, NULL,
2393 : : "only group 0 is supported");
2394 [ # # ]: 0 : if (attr->transfer)
2395 : 0 : return rte_flow_error_set(error, ENOTSUP,
2396 : : RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
2397 : : NULL, "transfer is not supported");
2398 : : return 0;
2399 : : }
2400 : :
2401 : : /*
2402 : : * Validate the count action.
2403 : : *
2404 : : * @param[in] dev
2405 : : * Pointer to the Ethernet device structure.
2406 : : * @param[in] attr
2407 : : * Attributes of flow that includes this action.
2408 : : * @param[out] error
2409 : : * Pointer to error structure.
2410 : : *
2411 : : * @return
2412 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2413 : : */
2414 : : int
2415 : 0 : mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,
2416 : : const struct rte_flow_attr *attr,
2417 : : struct rte_flow_error *error)
2418 : : {
2419 [ # # ]: 0 : if (attr->egress)
2420 : 0 : return rte_flow_error_set(error, ENOTSUP,
2421 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
2422 : : "count action not supported for "
2423 : : "egress");
2424 : : return 0;
2425 : : }
2426 : :
2427 : : /*
2428 : : * Validate the ASO CT action.
2429 : : *
2430 : : * @param[in] dev
2431 : : * Pointer to the Ethernet device structure.
2432 : : * @param[in] conntrack
2433 : : * Pointer to the CT action profile.
2434 : : * @param[out] error
2435 : : * Pointer to error structure.
2436 : : *
2437 : : * @return
2438 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2439 : : */
2440 : : int
2441 : 0 : mlx5_validate_action_ct(struct rte_eth_dev *dev,
2442 : : const struct rte_flow_action_conntrack *conntrack,
2443 : : struct rte_flow_error *error)
2444 : : {
2445 : : RTE_SET_USED(dev);
2446 : :
2447 [ # # ]: 0 : if (conntrack->state > RTE_FLOW_CONNTRACK_STATE_TIME_WAIT)
2448 : 0 : return rte_flow_error_set(error, EINVAL,
2449 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2450 : : "Invalid CT state");
2451 [ # # ]: 0 : if (conntrack->last_index > RTE_FLOW_CONNTRACK_FLAG_RST)
2452 : 0 : return rte_flow_error_set(error, EINVAL,
2453 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2454 : : "Invalid last TCP packet flag");
2455 : : return 0;
2456 : : }
2457 : :
2458 : : /**
2459 : : * Validate the level value for modify field action.
2460 : : *
2461 : : * @param[in] data
2462 : : * Pointer to the rte_flow_field_data structure either src or dst.
2463 : : * @param[out] error
2464 : : * Pointer to error structure.
2465 : : *
2466 : : * @return
2467 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2468 : : */
2469 : : int
2470 : 0 : flow_validate_modify_field_level(const struct rte_flow_field_data *data,
2471 : : struct rte_flow_error *error)
2472 : : {
2473 [ # # # # ]: 0 : if (data->level == 0 || data->field == RTE_FLOW_FIELD_FLEX_ITEM)
2474 : : return 0;
2475 [ # # ]: 0 : if (data->field != RTE_FLOW_FIELD_TAG &&
2476 : : data->field != (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG) {
2477 [ # # ]: 0 : if (data->level > 1)
2478 : 0 : return rte_flow_error_set(error, ENOTSUP,
2479 : : RTE_FLOW_ERROR_TYPE_ACTION,
2480 : : NULL,
2481 : : "inner header fields modification is not supported");
2482 : : return 0;
2483 : : }
2484 [ # # ]: 0 : if (data->tag_index != 0)
2485 : 0 : return rte_flow_error_set(error, EINVAL,
2486 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2487 : : "tag array can be provided using 'level' or 'tag_index' fields, not both");
2488 : : /*
2489 : : * The tag array for RTE_FLOW_FIELD_TAG type is provided using
2490 : : * 'tag_index' field. In old API, it was provided using 'level' field
2491 : : * and it is still supported for backwards compatibility.
2492 : : */
2493 : 0 : DRV_LOG(DEBUG, "tag array provided in 'level' field instead of 'tag_index' field.");
2494 : 0 : return 0;
2495 : : }
2496 : :
2497 : : /**
2498 : : * Validate ICMP6 item.
2499 : : *
2500 : : * @param[in] item
2501 : : * Item specification.
2502 : : * @param[in] item_flags
2503 : : * Bit-fields that holds the items detected until now.
2504 : : * @param[in] ext_vlan_sup
2505 : : * Whether extended VLAN features are supported or not.
2506 : : * @param[out] error
2507 : : * Pointer to error structure.
2508 : : *
2509 : : * @return
2510 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2511 : : */
2512 : : int
2513 : 0 : mlx5_flow_validate_item_icmp6(const struct rte_eth_dev *dev,
2514 : : const struct rte_flow_item *item,
2515 : : uint64_t item_flags,
2516 : : uint8_t target_protocol,
2517 : : struct rte_flow_error *error)
2518 : : {
2519 : 0 : const struct rte_flow_item_icmp6 *mask = item->mask;
2520 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2521 [ # # ]: 0 : const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
2522 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6;
2523 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2524 : : MLX5_FLOW_LAYER_OUTER_L4;
2525 : : int ret;
2526 : :
2527 [ # # ]: 0 : if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMPV6)
2528 : 0 : return rte_flow_error_set(error, EINVAL,
2529 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2530 : : "protocol filtering not compatible"
2531 : : " with ICMP6 layer");
2532 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
2533 [ # # ]: 0 : if (!(item_flags & l3m))
2534 : 0 : return rte_flow_error_set(error, EINVAL,
2535 : : RTE_FLOW_ERROR_TYPE_ITEM,
2536 : : item, "IPv6 is mandatory to filter on ICMP6");
2537 : : }
2538 [ # # ]: 0 : if (item_flags & l4m)
2539 : 0 : return rte_flow_error_set(error, EINVAL,
2540 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2541 : : "multiple L4 layers not supported");
2542 [ # # ]: 0 : if (!mask)
2543 : : mask = &rte_flow_item_icmp6_mask;
2544 : 0 : ret = mlx5_flow_item_acceptable
2545 : : (dev, item, (const uint8_t *)mask,
2546 : : (const uint8_t *)&rte_flow_item_icmp6_mask,
2547 : : sizeof(struct rte_flow_item_icmp6),
2548 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2549 : : if (ret < 0)
2550 : : return ret;
2551 : : return 0;
2552 : : }
2553 : :
2554 : : /**
2555 : : * Validate ICMP6 echo request/reply item.
2556 : : *
2557 : : * @param[in] item
2558 : : * Item specification.
2559 : : * @param[in] item_flags
2560 : : * Bit-fields that holds the items detected until now.
2561 : : * @param[in] ext_vlan_sup
2562 : : * Whether extended VLAN features are supported or not.
2563 : : * @param[out] error
2564 : : * Pointer to error structure.
2565 : : *
2566 : : * @return
2567 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2568 : : */
2569 : : int
2570 : 0 : mlx5_flow_validate_item_icmp6_echo(const struct rte_eth_dev *dev,
2571 : : const struct rte_flow_item *item,
2572 : : uint64_t item_flags,
2573 : : uint8_t target_protocol,
2574 : : struct rte_flow_error *error)
2575 : : {
2576 : 0 : const struct rte_flow_item_icmp6_echo *mask = item->mask;
2577 : 0 : const struct rte_flow_item_icmp6_echo nic_mask = {
2578 : : .hdr.base.type = 0xff,
2579 : : .hdr.base.code = 0xff,
2580 : : .hdr.identifier = RTE_BE16(0xffff),
2581 : : .hdr.sequence = RTE_BE16(0xffff),
2582 : : };
2583 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2584 [ # # ]: 0 : const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
2585 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6;
2586 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2587 : : MLX5_FLOW_LAYER_OUTER_L4;
2588 : : int ret;
2589 : :
2590 [ # # ]: 0 : if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMPV6)
2591 : 0 : return rte_flow_error_set(error, EINVAL,
2592 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2593 : : "protocol filtering not compatible"
2594 : : " with ICMP6 layer");
2595 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
2596 [ # # ]: 0 : if (!(item_flags & l3m))
2597 : 0 : return rte_flow_error_set(error, EINVAL,
2598 : : RTE_FLOW_ERROR_TYPE_ITEM,
2599 : : item, "IPv6 is mandatory to filter on ICMP6");
2600 : : }
2601 [ # # ]: 0 : if (item_flags & l4m)
2602 : 0 : return rte_flow_error_set(error, EINVAL,
2603 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2604 : : "multiple L4 layers not supported");
2605 [ # # ]: 0 : if (!mask)
2606 : : mask = &nic_mask;
2607 : 0 : ret = mlx5_flow_item_acceptable
2608 : : (dev, item, (const uint8_t *)mask,
2609 : : (const uint8_t *)&nic_mask,
2610 : : sizeof(struct rte_flow_item_icmp6_echo),
2611 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2612 : : if (ret < 0)
2613 : : return ret;
2614 : : return 0;
2615 : : }
2616 : :
2617 : : /**
2618 : : * Validate ICMP item.
2619 : : *
2620 : : * @param[in] item
2621 : : * Item specification.
2622 : : * @param[in] item_flags
2623 : : * Bit-fields that holds the items detected until now.
2624 : : * @param[out] error
2625 : : * Pointer to error structure.
2626 : : *
2627 : : * @return
2628 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2629 : : */
2630 : : int
2631 : 0 : mlx5_flow_validate_item_icmp(const struct rte_eth_dev *dev,
2632 : : const struct rte_flow_item *item,
2633 : : uint64_t item_flags,
2634 : : uint8_t target_protocol,
2635 : : struct rte_flow_error *error)
2636 : : {
2637 : 0 : const struct rte_flow_item_icmp *mask = item->mask;
2638 : 0 : const struct rte_flow_item_icmp nic_mask = {
2639 : : .hdr.icmp_type = 0xff,
2640 : : .hdr.icmp_code = 0xff,
2641 : : .hdr.icmp_ident = RTE_BE16(0xffff),
2642 : : .hdr.icmp_seq_nb = RTE_BE16(0xffff),
2643 : : };
2644 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2645 [ # # ]: 0 : const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
2646 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4;
2647 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2648 : : MLX5_FLOW_LAYER_OUTER_L4;
2649 : : int ret;
2650 : :
2651 [ # # ]: 0 : if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMP)
2652 : 0 : return rte_flow_error_set(error, EINVAL,
2653 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2654 : : "protocol filtering not compatible"
2655 : : " with ICMP layer");
2656 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
2657 [ # # ]: 0 : if (!(item_flags & l3m))
2658 : 0 : return rte_flow_error_set(error, EINVAL,
2659 : : RTE_FLOW_ERROR_TYPE_ITEM,
2660 : : item, "IPv4 is mandatory to filter on ICMP");
2661 : : }
2662 [ # # ]: 0 : if (item_flags & l4m)
2663 : 0 : return rte_flow_error_set(error, EINVAL,
2664 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2665 : : "multiple L4 layers not supported");
2666 [ # # ]: 0 : if (!mask)
2667 : : mask = &nic_mask;
2668 : 0 : ret = mlx5_flow_item_acceptable
2669 : : (dev, item, (const uint8_t *)mask,
2670 : : (const uint8_t *)&nic_mask,
2671 : : sizeof(struct rte_flow_item_icmp),
2672 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2673 : : if (ret < 0)
2674 : : return ret;
2675 : : return 0;
2676 : : }
2677 : :
2678 : : /**
2679 : : * Validate Ethernet item.
2680 : : *
2681 : : * @param[in] item
2682 : : * Item specification.
2683 : : * @param[in] item_flags
2684 : : * Bit-fields that holds the items detected until now.
2685 : : * @param[out] error
2686 : : * Pointer to error structure.
2687 : : *
2688 : : * @return
2689 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2690 : : */
2691 : : int
2692 : 0 : mlx5_flow_validate_item_eth(const struct rte_eth_dev *dev,
2693 : : const struct rte_flow_item *item,
2694 : : uint64_t item_flags, bool ext_vlan_sup,
2695 : : struct rte_flow_error *error)
2696 : : {
2697 : 0 : const struct rte_flow_item_eth *mask = item->mask;
2698 : 0 : const struct rte_flow_item_eth nic_mask = {
2699 : : .hdr.dst_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
2700 : : .hdr.src_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
2701 : : .hdr.ether_type = RTE_BE16(0xffff),
2702 : : .has_vlan = ext_vlan_sup ? 1 : 0,
2703 : : };
2704 : : int ret;
2705 : 0 : int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2706 [ # # ]: 0 : const uint64_t ethm = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
2707 : : MLX5_FLOW_LAYER_OUTER_L2;
2708 : :
2709 [ # # ]: 0 : if (item_flags & ethm)
2710 : 0 : return rte_flow_error_set(error, ENOTSUP,
2711 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2712 : : "multiple L2 layers not supported");
2713 [ # # # # : 0 : if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_L3)) ||
# # ]
2714 [ # # ]: 0 : (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_L3)))
2715 : 0 : return rte_flow_error_set(error, EINVAL,
2716 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2717 : : "L2 layer should not follow "
2718 : : "L3 layers");
2719 [ # # # # : 0 : if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_VLAN)) ||
# # ]
2720 [ # # ]: 0 : (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_VLAN)))
2721 : 0 : return rte_flow_error_set(error, EINVAL,
2722 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2723 : : "L2 layer should not follow VLAN");
2724 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_GTP)
2725 : 0 : return rte_flow_error_set(error, EINVAL,
2726 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2727 : : "L2 layer should not follow GTP");
2728 [ # # ]: 0 : if (!mask)
2729 : : mask = &rte_flow_item_eth_mask;
2730 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2731 : : (const uint8_t *)&nic_mask,
2732 : : sizeof(struct rte_flow_item_eth),
2733 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2734 : 0 : return ret;
2735 : : }
2736 : :
2737 : : /**
2738 : : * Validate VLAN item.
2739 : : *
2740 : : * @param[in] item
2741 : : * Item specification.
2742 : : * @param[in] item_flags
2743 : : * Bit-fields that holds the items detected until now.
2744 : : * @param[in] dev
2745 : : * Ethernet device flow is being created on.
2746 : : * @param[out] error
2747 : : * Pointer to error structure.
2748 : : *
2749 : : * @return
2750 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2751 : : */
2752 : : int
2753 : 0 : mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
2754 : : uint64_t item_flags,
2755 : : struct rte_eth_dev *dev,
2756 : : struct rte_flow_error *error)
2757 : : {
2758 : 0 : const struct rte_flow_item_vlan *spec = item->spec;
2759 : 0 : const struct rte_flow_item_vlan *mask = item->mask;
2760 : 0 : const struct rte_flow_item_vlan nic_mask = {
2761 : : .hdr.vlan_tci = RTE_BE16(UINT16_MAX),
2762 : : .hdr.eth_proto = RTE_BE16(UINT16_MAX),
2763 : : };
2764 : : uint16_t vlan_tag = 0;
2765 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2766 : : int ret;
2767 : : const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
2768 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L4) :
2769 : : (MLX5_FLOW_LAYER_OUTER_L3 |
2770 : : MLX5_FLOW_LAYER_OUTER_L4);
2771 [ # # ]: 0 : const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
2772 : : MLX5_FLOW_LAYER_OUTER_VLAN;
2773 : :
2774 [ # # ]: 0 : if (item_flags & vlanm)
2775 : 0 : return rte_flow_error_set(error, EINVAL,
2776 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2777 : : "multiple VLAN layers not supported");
2778 [ # # ]: 0 : else if ((item_flags & l34m) != 0)
2779 : 0 : return rte_flow_error_set(error, EINVAL,
2780 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2781 : : "VLAN cannot follow L3/L4 layer");
2782 [ # # ]: 0 : if (!mask)
2783 : : mask = &rte_flow_item_vlan_mask;
2784 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2785 : : (const uint8_t *)&nic_mask,
2786 : : sizeof(struct rte_flow_item_vlan),
2787 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2788 [ # # ]: 0 : if (ret)
2789 : : return ret;
2790 [ # # # # ]: 0 : if (!tunnel && mask->hdr.vlan_tci != RTE_BE16(0x0fff)) {
2791 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2792 : :
2793 [ # # ]: 0 : if (priv->vmwa_context) {
2794 : : /*
2795 : : * Non-NULL context means we have a virtual machine
2796 : : * and SR-IOV enabled, we have to create VLAN interface
2797 : : * to make hypervisor to setup E-Switch vport
2798 : : * context correctly. We avoid creating the multiple
2799 : : * VLAN interfaces, so we cannot support VLAN tag mask.
2800 : : */
2801 : 0 : return rte_flow_error_set(error, EINVAL,
2802 : : RTE_FLOW_ERROR_TYPE_ITEM,
2803 : : item,
2804 : : "VLAN tag mask is not"
2805 : : " supported in virtual"
2806 : : " environment");
2807 : : }
2808 : : }
2809 [ # # ]: 0 : if (spec) {
2810 : 0 : vlan_tag = spec->hdr.vlan_tci;
2811 : 0 : vlan_tag &= mask->hdr.vlan_tci;
2812 : : }
2813 : : /*
2814 : : * From verbs perspective an empty VLAN is equivalent
2815 : : * to a packet without VLAN layer.
2816 : : */
2817 [ # # ]: 0 : if (!vlan_tag)
2818 : 0 : return rte_flow_error_set(error, EINVAL,
2819 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2820 : 0 : item->spec,
2821 : : "VLAN cannot be empty");
2822 : : return 0;
2823 : : }
2824 : :
2825 : : /**
2826 : : * Validate IPV4 item.
2827 : : *
2828 : : * @param[in] item
2829 : : * Item specification.
2830 : : * @param[in] item_flags
2831 : : * Bit-fields that holds the items detected until now.
2832 : : * @param[in] last_item
2833 : : * Previous validated item in the pattern items.
2834 : : * @param[in] ether_type
2835 : : * Type in the ethernet layer header (including dot1q).
2836 : : * @param[in] acc_mask
2837 : : * Acceptable mask, if NULL default internal default mask
2838 : : * will be used to check whether item fields are supported.
2839 : : * @param[in] range_accepted
2840 : : * True if range of values is accepted for specific fields, false otherwise.
2841 : : * @param[out] error
2842 : : * Pointer to error structure.
2843 : : *
2844 : : * @return
2845 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2846 : : */
2847 : : int
2848 : 0 : mlx5_flow_validate_item_ipv4(const struct rte_eth_dev *dev,
2849 : : const struct rte_flow_item *item,
2850 : : uint64_t item_flags,
2851 : : uint64_t last_item,
2852 : : uint16_t ether_type,
2853 : : const struct rte_flow_item_ipv4 *acc_mask,
2854 : : bool range_accepted,
2855 : : struct rte_flow_error *error)
2856 : : {
2857 : 0 : const struct rte_flow_item_ipv4 *mask = item->mask;
2858 : 0 : const struct rte_flow_item_ipv4 *spec = item->spec;
2859 : 0 : const struct rte_flow_item_ipv4 nic_mask = {
2860 : : .hdr = {
2861 : : .src_addr = RTE_BE32(0xffffffff),
2862 : : .dst_addr = RTE_BE32(0xffffffff),
2863 : : .type_of_service = 0xff,
2864 : : .next_proto_id = 0xff,
2865 : : },
2866 : : };
2867 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2868 [ # # ]: 0 : const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2869 : : MLX5_FLOW_LAYER_OUTER_L3;
2870 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2871 : : MLX5_FLOW_LAYER_OUTER_L4;
2872 : : int ret;
2873 : : uint8_t next_proto = 0xFF;
2874 : : const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2875 : : MLX5_FLOW_LAYER_OUTER_VLAN |
2876 : : MLX5_FLOW_LAYER_INNER_VLAN);
2877 : :
2878 [ # # ]: 0 : if ((last_item & l2_vlan) && ether_type &&
2879 [ # # ]: 0 : ether_type != RTE_ETHER_TYPE_IPV4)
2880 : 0 : return rte_flow_error_set(error, EINVAL,
2881 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2882 : : "IPv4 cannot follow L2/VLAN layer "
2883 : : "which ether type is not IPv4");
2884 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_IPIP) {
2885 [ # # ]: 0 : if (mask && spec)
2886 : 0 : next_proto = mask->hdr.next_proto_id &
2887 : 0 : spec->hdr.next_proto_id;
2888 [ # # ]: 0 : if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2889 : 0 : return rte_flow_error_set(error, EINVAL,
2890 : : RTE_FLOW_ERROR_TYPE_ITEM,
2891 : : item,
2892 : : "multiple tunnel "
2893 : : "not supported");
2894 : : }
2895 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP)
2896 : 0 : return rte_flow_error_set(error, EINVAL,
2897 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2898 : : "wrong tunnel type - IPv6 specified "
2899 : : "but IPv4 item provided");
2900 [ # # ]: 0 : if (item_flags & l3m)
2901 : 0 : return rte_flow_error_set(error, ENOTSUP,
2902 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2903 : : "multiple L3 layers not supported");
2904 [ # # ]: 0 : else if (item_flags & l4m)
2905 : 0 : return rte_flow_error_set(error, EINVAL,
2906 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2907 : : "L3 cannot follow an L4 layer.");
2908 [ # # ]: 0 : else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2909 : : !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2910 : 0 : return rte_flow_error_set(error, EINVAL,
2911 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2912 : : "L3 cannot follow an NVGRE layer.");
2913 [ # # ]: 0 : if (!mask)
2914 : : mask = &rte_flow_item_ipv4_mask;
2915 [ # # ]: 0 : else if (mask->hdr.next_proto_id != 0 &&
2916 : : mask->hdr.next_proto_id != 0xff)
2917 : 0 : return rte_flow_error_set(error, EINVAL,
2918 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2919 : : "partial mask is not supported"
2920 : : " for protocol");
2921 [ # # ]: 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2922 : : acc_mask ? (const uint8_t *)acc_mask
2923 : : : (const uint8_t *)&nic_mask,
2924 : : sizeof(struct rte_flow_item_ipv4),
2925 : : range_accepted, error);
2926 : : if (ret < 0)
2927 : : return ret;
2928 : : return 0;
2929 : : }
2930 : :
2931 : : /**
2932 : : * Validate IPV6 item.
2933 : : *
2934 : : * @param[in] item
2935 : : * Item specification.
2936 : : * @param[in] item_flags
2937 : : * Bit-fields that holds the items detected until now.
2938 : : * @param[in] last_item
2939 : : * Previous validated item in the pattern items.
2940 : : * @param[in] ether_type
2941 : : * Type in the ethernet layer header (including dot1q).
2942 : : * @param[in] acc_mask
2943 : : * Acceptable mask, if NULL default internal default mask
2944 : : * will be used to check whether item fields are supported.
2945 : : * @param[out] error
2946 : : * Pointer to error structure.
2947 : : *
2948 : : * @return
2949 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2950 : : */
2951 : : int
2952 : 0 : mlx5_flow_validate_item_ipv6(const struct rte_eth_dev *dev,
2953 : : const struct rte_flow_item *item,
2954 : : uint64_t item_flags,
2955 : : uint64_t last_item,
2956 : : uint16_t ether_type,
2957 : : const struct rte_flow_item_ipv6 *acc_mask,
2958 : : struct rte_flow_error *error)
2959 : : {
2960 : 0 : const struct rte_flow_item_ipv6 *mask = item->mask;
2961 : 0 : const struct rte_flow_item_ipv6 *spec = item->spec;
2962 : 0 : const struct rte_flow_item_ipv6 nic_mask = {
2963 : : .hdr = {
2964 : : .src_addr = RTE_IPV6_MASK_FULL,
2965 : : .dst_addr = RTE_IPV6_MASK_FULL,
2966 : : .vtc_flow = RTE_BE32(0xffffffff),
2967 : : .proto = 0xff,
2968 : : },
2969 : : };
2970 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2971 [ # # ]: 0 : const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2972 : : MLX5_FLOW_LAYER_OUTER_L3;
2973 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2974 : : MLX5_FLOW_LAYER_OUTER_L4;
2975 : : int ret;
2976 : : uint8_t next_proto = 0xFF;
2977 : : const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2978 : : MLX5_FLOW_LAYER_OUTER_VLAN |
2979 : : MLX5_FLOW_LAYER_INNER_VLAN);
2980 : :
2981 [ # # ]: 0 : if ((last_item & l2_vlan) && ether_type &&
2982 [ # # ]: 0 : ether_type != RTE_ETHER_TYPE_IPV6)
2983 : 0 : return rte_flow_error_set(error, EINVAL,
2984 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2985 : : "IPv6 cannot follow L2/VLAN layer "
2986 : : "which ether type is not IPv6");
2987 [ # # # # : 0 : if (mask && mask->hdr.proto == UINT8_MAX && spec)
# # ]
2988 : 0 : next_proto = spec->hdr.proto;
2989 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_IPIP) {
2990 [ # # ]: 0 : if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2991 : 0 : return rte_flow_error_set(error, EINVAL,
2992 : : RTE_FLOW_ERROR_TYPE_ITEM,
2993 : : item,
2994 : : "multiple tunnel "
2995 : : "not supported");
2996 : : }
2997 : 0 : if (next_proto == IPPROTO_HOPOPTS ||
2998 [ # # ]: 0 : next_proto == IPPROTO_ROUTING ||
2999 : : next_proto == IPPROTO_FRAGMENT ||
3000 : : next_proto == IPPROTO_AH ||
3001 [ # # ]: 0 : next_proto == IPPROTO_DSTOPTS ||
3002 [ # # ]: 0 : (!mlx5_hws_active(dev) && next_proto == IPPROTO_ESP))
3003 : 0 : return rte_flow_error_set(error, EINVAL,
3004 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3005 : : "IPv6 proto (next header) should "
3006 : : "not be set as extension header");
3007 [ # # ]: 0 : if (item_flags & l3m)
3008 : 0 : return rte_flow_error_set(error, ENOTSUP,
3009 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3010 : : "multiple L3 layers not supported");
3011 [ # # ]: 0 : else if (item_flags & l4m)
3012 : 0 : return rte_flow_error_set(error, EINVAL,
3013 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3014 : : "L3 cannot follow an L4 layer.");
3015 [ # # ]: 0 : else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
3016 : : !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
3017 : 0 : return rte_flow_error_set(error, EINVAL,
3018 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3019 : : "L3 cannot follow an NVGRE layer.");
3020 [ # # ]: 0 : if (!mask)
3021 : : mask = &rte_flow_item_ipv6_mask;
3022 [ # # ]: 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
3023 : : acc_mask ? (const uint8_t *)acc_mask
3024 : : : (const uint8_t *)&nic_mask,
3025 : : sizeof(struct rte_flow_item_ipv6),
3026 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3027 : : if (ret < 0)
3028 : : return ret;
3029 : : return 0;
3030 : : }
3031 : :
3032 : : /**
3033 : : * Validate UDP item.
3034 : : *
3035 : : * @param[in] item
3036 : : * Item specification.
3037 : : * @param[in] item_flags
3038 : : * Bit-fields that holds the items detected until now.
3039 : : * @param[in] target_protocol
3040 : : * The next protocol in the previous item.
3041 : : * @param[in] flow_mask
3042 : : * mlx5 flow-specific (DV, verbs, etc.) supported header fields mask.
3043 : : * @param[out] error
3044 : : * Pointer to error structure.
3045 : : *
3046 : : * @return
3047 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3048 : : */
3049 : : int
3050 : 0 : mlx5_flow_validate_item_udp(const struct rte_eth_dev *dev,
3051 : : const struct rte_flow_item *item,
3052 : : uint64_t item_flags,
3053 : : uint8_t target_protocol,
3054 : : struct rte_flow_error *error)
3055 : : {
3056 : 0 : const struct rte_flow_item_udp *mask = item->mask;
3057 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
3058 [ # # ]: 0 : const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
3059 : : MLX5_FLOW_LAYER_OUTER_L3;
3060 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
3061 : : MLX5_FLOW_LAYER_OUTER_L4;
3062 : : int ret;
3063 : :
3064 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
3065 [ # # ]: 0 : if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
3066 : 0 : return rte_flow_error_set(error, EINVAL,
3067 : : RTE_FLOW_ERROR_TYPE_ITEM,
3068 : : item, "protocol filtering not compatible with UDP layer");
3069 [ # # ]: 0 : if (!(item_flags & l3m))
3070 : 0 : return rte_flow_error_set(error, EINVAL,
3071 : : RTE_FLOW_ERROR_TYPE_ITEM,
3072 : : item,
3073 : : "L3 is mandatory to filter on L4");
3074 : : }
3075 [ # # ]: 0 : if (item_flags & l4m)
3076 : 0 : return rte_flow_error_set(error, EINVAL,
3077 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3078 : : "multiple L4 layers not supported");
3079 [ # # ]: 0 : if (!mask)
3080 : : mask = &rte_flow_item_udp_mask;
3081 : 0 : ret = mlx5_flow_item_acceptable
3082 : : (dev, item, (const uint8_t *)mask,
3083 : : (const uint8_t *)&rte_flow_item_udp_mask,
3084 : : sizeof(struct rte_flow_item_udp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
3085 : : error);
3086 : : if (ret < 0)
3087 : : return ret;
3088 : : return 0;
3089 : : }
3090 : :
3091 : : /**
3092 : : * Validate TCP item.
3093 : : *
3094 : : * @param[in] item
3095 : : * Item specification.
3096 : : * @param[in] item_flags
3097 : : * Bit-fields that holds the items detected until now.
3098 : : * @param[in] target_protocol
3099 : : * The next protocol in the previous item.
3100 : : * @param[out] error
3101 : : * Pointer to error structure.
3102 : : *
3103 : : * @return
3104 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3105 : : */
3106 : : int
3107 : 0 : mlx5_flow_validate_item_tcp(const struct rte_eth_dev *dev,
3108 : : const struct rte_flow_item *item,
3109 : : uint64_t item_flags,
3110 : : uint8_t target_protocol,
3111 : : const struct rte_flow_item_tcp *flow_mask,
3112 : : struct rte_flow_error *error)
3113 : : {
3114 : 0 : const struct rte_flow_item_tcp *mask = item->mask;
3115 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
3116 [ # # ]: 0 : const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
3117 : : MLX5_FLOW_LAYER_OUTER_L3;
3118 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
3119 : : MLX5_FLOW_LAYER_OUTER_L4;
3120 : : int ret;
3121 : :
3122 : : MLX5_ASSERT(flow_mask);
3123 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
3124 [ # # ]: 0 : if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
3125 : 0 : return rte_flow_error_set(error, EINVAL,
3126 : : RTE_FLOW_ERROR_TYPE_ITEM,
3127 : : item, "protocol filtering not compatible with TCP layer");
3128 [ # # ]: 0 : if (!(item_flags & l3m))
3129 : 0 : return rte_flow_error_set(error, EINVAL,
3130 : : RTE_FLOW_ERROR_TYPE_ITEM,
3131 : : item, "L3 is mandatory to filter on L4");
3132 : : }
3133 [ # # ]: 0 : if (item_flags & l4m)
3134 : 0 : return rte_flow_error_set(error, EINVAL,
3135 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3136 : : "multiple L4 layers not supported");
3137 [ # # ]: 0 : if (!mask)
3138 : : mask = &rte_flow_item_tcp_mask;
3139 : 0 : ret = mlx5_flow_item_acceptable
3140 : : (dev, item, (const uint8_t *)mask,
3141 : : (const uint8_t *)flow_mask,
3142 : : sizeof(struct rte_flow_item_tcp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
3143 : : error);
3144 : : if (ret < 0)
3145 : : return ret;
3146 : : return 0;
3147 : : }
3148 : :
3149 : : /**
3150 : : * Validate VXLAN item.
3151 : : *
3152 : : * @param[in] dev
3153 : : * Pointer to the Ethernet device structure.
3154 : : * @param[in] udp_dport
3155 : : * UDP destination port
3156 : : * @param[in] item
3157 : : * Item specification.
3158 : : * @param[in] item_flags
3159 : : * Bit-fields that holds the items detected until now.
3160 : : * @param root
3161 : : * Whether action is on root table.
3162 : : * @param[out] error
3163 : : * Pointer to error structure.
3164 : : *
3165 : : * @return
3166 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3167 : : */
3168 : : int
3169 : 0 : mlx5_flow_validate_item_vxlan(struct rte_eth_dev *dev,
3170 : : uint16_t udp_dport,
3171 : : const struct rte_flow_item *item,
3172 : : uint64_t item_flags,
3173 : : bool root,
3174 : : struct rte_flow_error *error)
3175 : : {
3176 : 0 : const struct rte_flow_item_vxlan *spec = item->spec;
3177 : 0 : const struct rte_flow_item_vxlan *mask = item->mask;
3178 : : int ret;
3179 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3180 : : union vni {
3181 : : uint32_t vlan_id;
3182 : : uint8_t vni[4];
3183 : 0 : } id = { .vlan_id = 0, };
3184 : 0 : const struct rte_flow_item_vxlan nic_mask = {
3185 : : .hdr.vni = { 0xff, 0xff, 0xff },
3186 : : .hdr.rsvd1 = 0xff,
3187 : : };
3188 : : const struct rte_flow_item_vxlan *valid_mask;
3189 : :
3190 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3191 : 0 : return rte_flow_error_set(error, ENOTSUP,
3192 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3193 : : "multiple tunnel layers not"
3194 : : " supported");
3195 : : /* HWS can match entire VXLAN, VXLAN-GBP and VXLAN-GPE headers */
3196 [ # # ]: 0 : if (mlx5_hws_active(dev))
3197 : : return 0;
3198 : : valid_mask = &rte_flow_item_vxlan_mask;
3199 : : /*
3200 : : * Verify only UDPv4 is present as defined in
3201 : : * https://tools.ietf.org/html/rfc7348
3202 : : */
3203 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
3204 : 0 : return rte_flow_error_set(error, EINVAL,
3205 : : RTE_FLOW_ERROR_TYPE_ITEM,
3206 : : item, "no outer UDP layer found");
3207 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
3208 : 0 : return rte_flow_error_set(error, ENOTSUP,
3209 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3210 : : "VXLAN tunnel must be fully defined");
3211 [ # # ]: 0 : if (!mask)
3212 : : mask = &rte_flow_item_vxlan_mask;
3213 : :
3214 [ # # ]: 0 : if (priv->sh->steering_format_version !=
3215 : : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5 ||
3216 [ # # ]: 0 : !udp_dport || udp_dport == MLX5_UDP_PORT_VXLAN) {
3217 : : /* non-root table */
3218 [ # # # # ]: 0 : if (!root && priv->sh->misc5_cap)
3219 : : valid_mask = &nic_mask;
3220 : : /* Group zero in NIC domain */
3221 [ # # # # ]: 0 : if (!root && priv->sh->tunnel_header_0_1)
3222 : : valid_mask = &nic_mask;
3223 : : }
3224 : 0 : ret = mlx5_flow_item_acceptable
3225 : : (dev, item, (const uint8_t *)mask,
3226 : : (const uint8_t *)valid_mask,
3227 : : sizeof(struct rte_flow_item_vxlan),
3228 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3229 : : if (ret < 0)
3230 : : return ret;
3231 : : if (spec) {
3232 : : memcpy(&id.vni[1], spec->hdr.vni, 3);
3233 : : memcpy(&id.vni[1], mask->hdr.vni, 3);
3234 : : }
3235 : : return 0;
3236 : : }
3237 : :
3238 : : /**
3239 : : * Validate VXLAN_GPE item.
3240 : : *
3241 : : * @param[in] item
3242 : : * Item specification.
3243 : : * @param[in] item_flags
3244 : : * Bit-fields that holds the items detected until now.
3245 : : * @param[in] priv
3246 : : * Pointer to the private data structure.
3247 : : * @param[in] target_protocol
3248 : : * The next protocol in the previous item.
3249 : : * @param[out] error
3250 : : * Pointer to error structure.
3251 : : *
3252 : : * @return
3253 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3254 : : */
3255 : : int
3256 : 0 : mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
3257 : : uint64_t item_flags,
3258 : : struct rte_eth_dev *dev,
3259 : : struct rte_flow_error *error)
3260 : : {
3261 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3262 : : const struct rte_flow_item_vxlan_gpe *spec = item->spec;
3263 : 0 : const struct rte_flow_item_vxlan_gpe *mask = item->mask;
3264 : : int ret;
3265 : : union vni {
3266 : : uint32_t vlan_id;
3267 : : uint8_t vni[4];
3268 : 0 : } id = { .vlan_id = 0, };
3269 : :
3270 : 0 : struct rte_flow_item_vxlan_gpe nic_mask = {
3271 : : .vni = { 0xff, 0xff, 0xff },
3272 : : .protocol = 0xff,
3273 : : .flags = 0xff,
3274 : : };
3275 : :
3276 [ # # ]: 0 : if (!priv->sh->config.l3_vxlan_en)
3277 : 0 : return rte_flow_error_set(error, ENOTSUP,
3278 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3279 : : "L3 VXLAN is not enabled by device"
3280 : : " parameter and/or not configured in"
3281 : : " firmware");
3282 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3283 : 0 : return rte_flow_error_set(error, ENOTSUP,
3284 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3285 : : "multiple tunnel layers not"
3286 : : " supported");
3287 : : /*
3288 : : * Verify only UDPv4 is present as defined in
3289 : : * https://tools.ietf.org/html/rfc7348
3290 : : */
3291 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
3292 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
3293 : 0 : return rte_flow_error_set(error, EINVAL,
3294 : : RTE_FLOW_ERROR_TYPE_ITEM,
3295 : : item, "no outer UDP layer found");
3296 : : }
3297 [ # # ]: 0 : if (!mask)
3298 : : mask = &rte_flow_item_vxlan_gpe_mask;
3299 [ # # ]: 0 : if (mlx5_hws_active(dev) ||
3300 [ # # ]: 0 : (priv->sh->misc5_cap && priv->sh->tunnel_header_0_1)) {
3301 : 0 : nic_mask.rsvd0[0] = 0xff;
3302 : 0 : nic_mask.rsvd0[1] = 0xff;
3303 : 0 : nic_mask.rsvd1 = 0xff;
3304 : : }
3305 : 0 : ret = mlx5_flow_item_acceptable
3306 : : (dev, item, (const uint8_t *)mask,
3307 : : (const uint8_t *)&nic_mask,
3308 : : sizeof(struct rte_flow_item_vxlan_gpe),
3309 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3310 [ # # ]: 0 : if (ret < 0)
3311 : : return ret;
3312 : : if (spec) {
3313 : : memcpy(&id.vni[1], spec->hdr.vni, 3);
3314 : : memcpy(&id.vni[1], mask->hdr.vni, 3);
3315 : : }
3316 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
3317 : 0 : return rte_flow_error_set(error, ENOTSUP,
3318 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3319 : : "VXLAN-GPE tunnel must be fully"
3320 : : " defined");
3321 : : return 0;
3322 : : }
3323 : : /**
3324 : : * Validate GRE Key item.
3325 : : *
3326 : : * @param[in] item
3327 : : * Item specification.
3328 : : * @param[in] item_flags
3329 : : * Bit flags to mark detected items.
3330 : : * @param[in] gre_item
3331 : : * Pointer to gre_item
3332 : : * @param[out] error
3333 : : * Pointer to error structure.
3334 : : *
3335 : : * @return
3336 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3337 : : */
3338 : : int
3339 : 0 : mlx5_flow_validate_item_gre_key(const struct rte_eth_dev *dev,
3340 : : const struct rte_flow_item *item,
3341 : : uint64_t item_flags,
3342 : : const struct rte_flow_item *gre_item,
3343 : : struct rte_flow_error *error)
3344 : : {
3345 : 0 : const rte_be32_t *mask = item->mask;
3346 : : int ret = 0;
3347 : 0 : rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
3348 : : const struct rte_flow_item_gre *gre_spec;
3349 : : const struct rte_flow_item_gre *gre_mask;
3350 : :
3351 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_GRE_KEY)
3352 : 0 : return rte_flow_error_set(error, ENOTSUP,
3353 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3354 : : "Multiple GRE key not support");
3355 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_GRE))
3356 : 0 : return rte_flow_error_set(error, ENOTSUP,
3357 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3358 : : "No preceding GRE header");
3359 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_INNER)
3360 : 0 : return rte_flow_error_set(error, ENOTSUP,
3361 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3362 : : "GRE key following a wrong item");
3363 [ # # ]: 0 : gre_mask = gre_item ? gre_item->mask : NULL;
3364 [ # # ]: 0 : if (!gre_mask)
3365 : : gre_mask = &rte_flow_item_gre_mask;
3366 [ # # ]: 0 : gre_spec = gre_item ? gre_item->spec : NULL;
3367 [ # # # # ]: 0 : if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
3368 [ # # ]: 0 : !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
3369 : 0 : return rte_flow_error_set(error, EINVAL,
3370 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3371 : : "Key bit must be on");
3372 : :
3373 [ # # ]: 0 : if (!mask)
3374 : : mask = &gre_key_default_mask;
3375 : 0 : ret = mlx5_flow_item_acceptable
3376 : : (dev, item, (const uint8_t *)mask,
3377 : : (const uint8_t *)&gre_key_default_mask,
3378 : : sizeof(rte_be32_t), MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3379 : 0 : return ret;
3380 : : }
3381 : :
3382 : : /**
3383 : : * Validate GRE optional item.
3384 : : *
3385 : : * @param[in] dev
3386 : : * Pointer to the Ethernet device structure.
3387 : : * @param[in] item
3388 : : * Item specification.
3389 : : * @param[in] item_flags
3390 : : * Bit flags to mark detected items.
3391 : : * @param[in] attr
3392 : : * Flow rule attributes.
3393 : : * @param[in] gre_item
3394 : : * Pointer to gre_item
3395 : : * @param[out] error
3396 : : * Pointer to error structure.
3397 : : *
3398 : : * @return
3399 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3400 : : */
3401 : : int
3402 : 0 : mlx5_flow_validate_item_gre_option(struct rte_eth_dev *dev,
3403 : : const struct rte_flow_item *item,
3404 : : uint64_t item_flags,
3405 : : const struct rte_flow_attr *attr,
3406 : : const struct rte_flow_item *gre_item,
3407 : : struct rte_flow_error *error)
3408 : : {
3409 [ # # ]: 0 : const struct rte_flow_item_gre *gre_spec = gre_item ? gre_item->spec : NULL;
3410 [ # # ]: 0 : const struct rte_flow_item_gre *gre_mask = gre_item ? gre_item->mask : NULL;
3411 : 0 : const struct rte_flow_item_gre_opt *spec = item->spec;
3412 : 0 : const struct rte_flow_item_gre_opt *mask = item->mask;
3413 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3414 : : int ret = 0;
3415 : 0 : struct rte_flow_item_gre_opt nic_mask = {
3416 : : .checksum_rsvd = {
3417 : : .checksum = RTE_BE16(UINT16_MAX),
3418 : : .reserved1 = 0x0,
3419 : : },
3420 : : .key = {
3421 : : .key = RTE_BE32(UINT32_MAX),
3422 : : },
3423 : : .sequence = {
3424 : : .sequence = RTE_BE32(UINT32_MAX),
3425 : : },
3426 : : };
3427 : :
3428 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_GRE))
3429 : 0 : return rte_flow_error_set(error, ENOTSUP,
3430 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3431 : : "No preceding GRE header");
3432 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_INNER)
3433 : 0 : return rte_flow_error_set(error, ENOTSUP,
3434 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3435 : : "GRE option following a wrong item");
3436 [ # # # # : 0 : if ((!spec && !mlx5_hws_active(dev)) || !mask)
# # ]
3437 : 0 : return rte_flow_error_set(error, EINVAL,
3438 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3439 : : "At least one field gre_option(checksum/key/sequence) must be specified");
3440 [ # # ]: 0 : if (!gre_mask)
3441 : : gre_mask = &rte_flow_item_gre_mask;
3442 [ # # ]: 0 : if (mask->checksum_rsvd.checksum)
3443 [ # # # # ]: 0 : if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x8000)) &&
3444 [ # # ]: 0 : !(gre_spec->c_rsvd0_ver & RTE_BE16(0x8000)))
3445 : 0 : return rte_flow_error_set(error, EINVAL,
3446 : : RTE_FLOW_ERROR_TYPE_ITEM,
3447 : : item,
3448 : : "Checksum bit must be on");
3449 [ # # ]: 0 : if (mask->key.key)
3450 [ # # # # ]: 0 : if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
3451 [ # # ]: 0 : !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
3452 : 0 : return rte_flow_error_set(error, EINVAL,
3453 : : RTE_FLOW_ERROR_TYPE_ITEM,
3454 : : item, "Key bit must be on");
3455 [ # # ]: 0 : if (mask->sequence.sequence)
3456 [ # # # # ]: 0 : if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x1000)) &&
3457 [ # # ]: 0 : !(gre_spec->c_rsvd0_ver & RTE_BE16(0x1000)))
3458 : 0 : return rte_flow_error_set(error, EINVAL,
3459 : : RTE_FLOW_ERROR_TYPE_ITEM,
3460 : : item,
3461 : : "Sequence bit must be on");
3462 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
3463 [ # # # # ]: 0 : if (mask->checksum_rsvd.checksum || mask->sequence.sequence) {
3464 [ # # ]: 0 : if (priv->sh->steering_format_version ==
3465 : 0 : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5 ||
3466 [ # # ]: 0 : ((attr->group ||
3467 [ # # # # ]: 0 : (attr->transfer && priv->fdb_def_rule)) &&
3468 [ # # ]: 0 : !priv->sh->misc5_cap) ||
3469 [ # # ]: 0 : (!(priv->sh->tunnel_header_0_1 &&
3470 [ # # ]: 0 : priv->sh->tunnel_header_2_3) &&
3471 : 0 : !attr->group &&
3472 [ # # # # ]: 0 : (!attr->transfer || !priv->fdb_def_rule)))
3473 : 0 : return rte_flow_error_set
3474 : : (error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM,
3475 : : item, "Checksum/Sequence not supported");
3476 : : }
3477 : : }
3478 : 0 : ret = mlx5_flow_item_acceptable
3479 : : (dev, item, (const uint8_t *)mask,
3480 : : (const uint8_t *)&nic_mask,
3481 : : sizeof(struct rte_flow_item_gre_opt),
3482 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3483 : 0 : return ret;
3484 : : }
3485 : :
3486 : : /**
3487 : : * Validate GRE item.
3488 : : *
3489 : : * @param[in] item
3490 : : * Item specification.
3491 : : * @param[in] item_flags
3492 : : * Bit flags to mark detected items.
3493 : : * @param[in] target_protocol
3494 : : * The next protocol in the previous item.
3495 : : * @param[out] error
3496 : : * Pointer to error structure.
3497 : : *
3498 : : * @return
3499 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3500 : : */
3501 : : int
3502 : 0 : mlx5_flow_validate_item_gre(const struct rte_eth_dev *dev,
3503 : : const struct rte_flow_item *item,
3504 : : uint64_t item_flags,
3505 : : uint8_t target_protocol,
3506 : : struct rte_flow_error *error)
3507 : : {
3508 : : const struct rte_flow_item_gre *spec __rte_unused = item->spec;
3509 : 0 : const struct rte_flow_item_gre *mask = item->mask;
3510 : : int ret;
3511 : 0 : const struct rte_flow_item_gre nic_mask = {
3512 : : .c_rsvd0_ver = RTE_BE16(0xB000),
3513 : : .protocol = RTE_BE16(UINT16_MAX),
3514 : : };
3515 : :
3516 [ # # ]: 0 : if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
3517 : 0 : return rte_flow_error_set(error, EINVAL,
3518 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3519 : : "protocol filtering not compatible"
3520 : : " with this GRE layer");
3521 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3522 : 0 : return rte_flow_error_set(error, ENOTSUP,
3523 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3524 : : "multiple tunnel layers not"
3525 : : " supported");
3526 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
3527 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
3528 : 0 : return rte_flow_error_set(error, ENOTSUP,
3529 : : RTE_FLOW_ERROR_TYPE_ITEM,
3530 : : item, "L3 Layer is missing");
3531 : : }
3532 [ # # ]: 0 : if (!mask)
3533 : : mask = &rte_flow_item_gre_mask;
3534 : 0 : ret = mlx5_flow_item_acceptable
3535 : : (dev, item, (const uint8_t *)mask,
3536 : : (const uint8_t *)&nic_mask,
3537 : : sizeof(struct rte_flow_item_gre), MLX5_ITEM_RANGE_NOT_ACCEPTED,
3538 : : error);
3539 : : if (ret < 0)
3540 : : return ret;
3541 : : #ifndef HAVE_MLX5DV_DR
3542 : : #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
3543 : : if (spec && (spec->protocol & mask->protocol))
3544 : : return rte_flow_error_set(error, ENOTSUP,
3545 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3546 : : "without MPLS support the"
3547 : : " specification cannot be used for"
3548 : : " filtering");
3549 : : #endif
3550 : : #endif
3551 : : return 0;
3552 : : }
3553 : :
3554 : : /**
3555 : : * Validate Geneve item.
3556 : : *
3557 : : * @param[in] item
3558 : : * Item specification.
3559 : : * @param[in] itemFlags
3560 : : * Bit-fields that holds the items detected until now.
3561 : : * @param[in] enPriv
3562 : : * Pointer to the private data structure.
3563 : : * @param[out] error
3564 : : * Pointer to error structure.
3565 : : *
3566 : : * @return
3567 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3568 : : */
3569 : :
3570 : : int
3571 : 0 : mlx5_flow_validate_item_geneve(const struct rte_flow_item *item,
3572 : : uint64_t item_flags,
3573 : : struct rte_eth_dev *dev,
3574 : : struct rte_flow_error *error)
3575 : : {
3576 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3577 : 0 : const struct rte_flow_item_geneve *spec = item->spec;
3578 : 0 : const struct rte_flow_item_geneve *mask = item->mask;
3579 : : int ret;
3580 : : uint16_t gbhdr;
3581 [ # # ]: 0 : uint8_t opt_len = priv->sh->cdev->config.hca_attr.geneve_max_opt_len ?
3582 : : MLX5_GENEVE_OPT_LEN_1 : MLX5_GENEVE_OPT_LEN_0;
3583 : 0 : const struct rte_flow_item_geneve nic_mask = {
3584 : : .ver_opt_len_o_c_rsvd0 = RTE_BE16(0x3f80),
3585 : : .vni = { 0xff, 0xff, 0xff },
3586 : : .protocol = RTE_BE16(UINT16_MAX),
3587 : : };
3588 : :
3589 [ # # ]: 0 : if (!priv->sh->cdev->config.hca_attr.tunnel_stateless_geneve_rx)
3590 : 0 : return rte_flow_error_set(error, ENOTSUP,
3591 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3592 : : "L3 Geneve is not enabled by device"
3593 : : " parameter and/or not configured in"
3594 : : " firmware");
3595 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3596 : 0 : return rte_flow_error_set(error, ENOTSUP,
3597 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3598 : : "multiple tunnel layers not"
3599 : : " supported");
3600 : : /*
3601 : : * Verify only UDPv4 is present as defined in
3602 : : * https://tools.ietf.org/html/rfc7348
3603 : : */
3604 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
3605 : 0 : return rte_flow_error_set(error, EINVAL,
3606 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3607 : : "no outer UDP layer found");
3608 [ # # ]: 0 : if (!mask)
3609 : : mask = &rte_flow_item_geneve_mask;
3610 : 0 : ret = mlx5_flow_item_acceptable
3611 : : (dev, item, (const uint8_t *)mask,
3612 : : (const uint8_t *)&nic_mask,
3613 : : sizeof(struct rte_flow_item_geneve),
3614 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3615 [ # # ]: 0 : if (ret)
3616 : : return ret;
3617 [ # # ]: 0 : if (spec) {
3618 [ # # ]: 0 : gbhdr = rte_be_to_cpu_16(spec->ver_opt_len_o_c_rsvd0);
3619 [ # # ]: 0 : if (MLX5_GENEVE_VER_VAL(gbhdr) ||
3620 [ # # # # ]: 0 : MLX5_GENEVE_CRITO_VAL(gbhdr) ||
3621 [ # # ]: 0 : MLX5_GENEVE_RSVD_VAL(gbhdr) || spec->rsvd1)
3622 : 0 : return rte_flow_error_set(error, ENOTSUP,
3623 : : RTE_FLOW_ERROR_TYPE_ITEM,
3624 : : item,
3625 : : "Geneve protocol unsupported"
3626 : : " fields are being used");
3627 [ # # ]: 0 : if (MLX5_GENEVE_OPTLEN_VAL(gbhdr) > opt_len)
3628 : 0 : return rte_flow_error_set
3629 : : (error, ENOTSUP,
3630 : : RTE_FLOW_ERROR_TYPE_ITEM,
3631 : : item,
3632 : : "Unsupported Geneve options length");
3633 : : }
3634 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
3635 : 0 : return rte_flow_error_set
3636 : : (error, ENOTSUP,
3637 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3638 : : "Geneve tunnel must be fully defined");
3639 : : return 0;
3640 : : }
3641 : :
3642 : : /**
3643 : : * Validate Geneve TLV option item.
3644 : : *
3645 : : * @param[in] item
3646 : : * Item specification.
3647 : : * @param[in] last_item
3648 : : * Previous validated item in the pattern items.
3649 : : * @param[in] geneve_item
3650 : : * Previous GENEVE item specification.
3651 : : * @param[in] dev
3652 : : * Pointer to the rte_eth_dev structure.
3653 : : * @param[out] error
3654 : : * Pointer to error structure.
3655 : : *
3656 : : * @return
3657 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3658 : : */
3659 : : int
3660 : 0 : mlx5_flow_validate_item_geneve_opt(const struct rte_flow_item *item,
3661 : : uint64_t last_item,
3662 : : const struct rte_flow_item *geneve_item,
3663 : : struct rte_eth_dev *dev,
3664 : : struct rte_flow_error *error)
3665 : : {
3666 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3667 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
3668 : : struct mlx5_geneve_tlv_option_resource *geneve_opt_resource;
3669 : 0 : struct mlx5_hca_attr *hca_attr = &sh->cdev->config.hca_attr;
3670 : 0 : uint8_t data_max_supported =
3671 : 0 : hca_attr->max_geneve_tlv_option_data_len * 4;
3672 : : const struct rte_flow_item_geneve *geneve_spec;
3673 : : const struct rte_flow_item_geneve *geneve_mask;
3674 : 0 : const struct rte_flow_item_geneve_opt *spec = item->spec;
3675 : 0 : const struct rte_flow_item_geneve_opt *mask = item->mask;
3676 : : unsigned int i;
3677 : : unsigned int data_len;
3678 : : uint8_t tlv_option_len;
3679 : : uint16_t optlen_m, optlen_v;
3680 : : const struct rte_flow_item_geneve_opt full_mask = {
3681 : : .option_class = RTE_BE16(0xffff),
3682 : : .option_type = 0xff,
3683 : : .option_len = 0x1f,
3684 : : };
3685 : :
3686 [ # # ]: 0 : if (!mask)
3687 : : mask = &rte_flow_item_geneve_opt_mask;
3688 [ # # ]: 0 : if (!spec)
3689 : 0 : return rte_flow_error_set
3690 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3691 : : "Geneve TLV opt class/type/length must be specified");
3692 [ # # ]: 0 : if ((uint32_t)spec->option_len > MLX5_GENEVE_OPTLEN_MASK)
3693 : 0 : return rte_flow_error_set
3694 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3695 : : "Geneve TLV opt length exceeds the limit (31)");
3696 : : /* Check if class type and length masks are full. */
3697 [ # # ]: 0 : if (full_mask.option_class != mask->option_class ||
3698 : 0 : full_mask.option_type != mask->option_type ||
3699 [ # # ]: 0 : full_mask.option_len != (mask->option_len & full_mask.option_len))
3700 : 0 : return rte_flow_error_set
3701 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3702 : : "Geneve TLV opt class/type/length masks must be full");
3703 : : /* Check if length is supported */
3704 [ # # ]: 0 : if ((uint32_t)spec->option_len >
3705 : : hca_attr->max_geneve_tlv_option_data_len)
3706 : 0 : return rte_flow_error_set
3707 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3708 : : "Geneve TLV opt length not supported");
3709 [ # # ]: 0 : if (hca_attr->max_geneve_tlv_options > 1)
3710 : 0 : DRV_LOG(DEBUG,
3711 : : "max_geneve_tlv_options supports more than 1 option");
3712 : : /* Check GENEVE item preceding. */
3713 [ # # # # ]: 0 : if (!geneve_item || !(last_item & MLX5_FLOW_LAYER_GENEVE))
3714 : 0 : return rte_flow_error_set
3715 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3716 : : "Geneve opt item must be preceded with Geneve item");
3717 : 0 : geneve_spec = geneve_item->spec;
3718 [ # # ]: 0 : geneve_mask = geneve_item->mask ? geneve_item->mask :
3719 : : &rte_flow_item_geneve_mask;
3720 : : /* Check if GENEVE TLV option size doesn't exceed option length */
3721 [ # # # # ]: 0 : if (geneve_spec && (geneve_mask->ver_opt_len_o_c_rsvd0 ||
3722 [ # # ]: 0 : geneve_spec->ver_opt_len_o_c_rsvd0)) {
3723 : 0 : tlv_option_len = spec->option_len & mask->option_len;
3724 [ # # ]: 0 : optlen_v = rte_be_to_cpu_16(geneve_spec->ver_opt_len_o_c_rsvd0);
3725 : 0 : optlen_v = MLX5_GENEVE_OPTLEN_VAL(optlen_v);
3726 [ # # ]: 0 : optlen_m = rte_be_to_cpu_16(geneve_mask->ver_opt_len_o_c_rsvd0);
3727 : 0 : optlen_m = MLX5_GENEVE_OPTLEN_VAL(optlen_m);
3728 [ # # ]: 0 : if ((optlen_v & optlen_m) <= tlv_option_len)
3729 : 0 : return rte_flow_error_set
3730 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3731 : : "GENEVE TLV option length exceeds optlen");
3732 : : }
3733 : : /* Check if length is 0 or data is 0. */
3734 [ # # # # ]: 0 : if (spec->data == NULL || spec->option_len == 0)
3735 : 0 : return rte_flow_error_set
3736 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3737 : : "Geneve TLV opt with zero data/length not supported");
3738 : : /* Check not all data & mask are 0. */
3739 : 0 : data_len = spec->option_len * 4;
3740 [ # # ]: 0 : if (mask->data == NULL) {
3741 [ # # ]: 0 : for (i = 0; i < data_len; i++)
3742 [ # # ]: 0 : if (spec->data[i])
3743 : : break;
3744 [ # # ]: 0 : if (i == data_len)
3745 : 0 : return rte_flow_error_set(error, ENOTSUP,
3746 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3747 : : "Can't match on Geneve option data 0");
3748 : : } else {
3749 [ # # ]: 0 : for (i = 0; i < data_len; i++)
3750 [ # # ]: 0 : if (spec->data[i] & mask->data[i])
3751 : : break;
3752 [ # # ]: 0 : if (i == data_len)
3753 : 0 : return rte_flow_error_set(error, ENOTSUP,
3754 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3755 : : "Can't match on Geneve option data and mask 0");
3756 : : /* Check data mask supported. */
3757 [ # # ]: 0 : for (i = data_max_supported; i < data_len ; i++)
3758 [ # # ]: 0 : if (mask->data[i])
3759 : 0 : return rte_flow_error_set(error, ENOTSUP,
3760 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3761 : : "Data mask is of unsupported size");
3762 : : }
3763 : : /* Check GENEVE option is supported in NIC. */
3764 [ # # ]: 0 : if (!hca_attr->geneve_tlv_opt)
3765 : 0 : return rte_flow_error_set
3766 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3767 : : "Geneve TLV opt not supported");
3768 : : /* Check if we already have geneve option with different type/class. */
3769 : 0 : rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
3770 : 0 : geneve_opt_resource = sh->geneve_tlv_option_resource;
3771 [ # # ]: 0 : if (geneve_opt_resource != NULL)
3772 : 0 : if (geneve_opt_resource->option_class != spec->option_class ||
3773 [ # # ]: 0 : geneve_opt_resource->option_type != spec->option_type ||
3774 : : geneve_opt_resource->length != spec->option_len) {
3775 : : rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
3776 : 0 : return rte_flow_error_set(error, ENOTSUP,
3777 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3778 : : "Only one Geneve TLV option supported");
3779 : : }
3780 : : rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
3781 : 0 : return 0;
3782 : : }
3783 : :
3784 : : /**
3785 : : * Validate MPLS item.
3786 : : *
3787 : : * @param[in] dev
3788 : : * Pointer to the rte_eth_dev structure.
3789 : : * @param[in] item
3790 : : * Item specification.
3791 : : * @param[in] item_flags
3792 : : * Bit-fields that holds the items detected until now.
3793 : : * @param[in] prev_layer
3794 : : * The protocol layer indicated in previous item.
3795 : : * @param[out] error
3796 : : * Pointer to error structure.
3797 : : *
3798 : : * @return
3799 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3800 : : */
3801 : : int
3802 : 0 : mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev __rte_unused,
3803 : : const struct rte_flow_item *item __rte_unused,
3804 : : uint64_t item_flags __rte_unused,
3805 : : uint64_t prev_layer __rte_unused,
3806 : : struct rte_flow_error *error)
3807 : : {
3808 : : #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
3809 [ # # ]: 0 : const struct rte_flow_item_mpls hws_nic_mask = {
3810 : : .label_tc_s = {0xff, 0xff, 0xff},
3811 : : .ttl = 0xff
3812 : : };
3813 : : const struct rte_flow_item_mpls *nic_mask = !mlx5_hws_active(dev) ?
3814 [ # # ]: 0 : &rte_flow_item_mpls_mask : &hws_nic_mask;
3815 : 0 : const struct rte_flow_item_mpls *mask = item->mask;
3816 : : struct mlx5_priv *priv = dev->data->dev_private;
3817 : : int ret;
3818 : :
3819 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
3820 : : /* MPLS has HW support in HWS */
3821 [ # # ]: 0 : if (!priv->sh->dev_cap.mpls_en)
3822 : 0 : return rte_flow_error_set(error, ENOTSUP,
3823 : : RTE_FLOW_ERROR_TYPE_ITEM,
3824 : : item, "MPLS not supported or disabled in firmware configuration.");
3825 : : /* MPLS over UDP, GRE is allowed */
3826 [ # # ]: 0 : if (!(prev_layer & (MLX5_FLOW_LAYER_OUTER_L4_UDP |
3827 : : MLX5_FLOW_LAYER_GRE |
3828 : : MLX5_FLOW_LAYER_GRE_KEY)))
3829 : 0 : return rte_flow_error_set(error, EINVAL,
3830 : : RTE_FLOW_ERROR_TYPE_ITEM,
3831 : : item, "protocol filtering not compatible with MPLS layer");
3832 : : /* Multi-tunnel isn't allowed but MPLS over GRE is an exception. */
3833 [ # # ]: 0 : if ((item_flags & MLX5_FLOW_LAYER_TUNNEL) &&
3834 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_GRE))
3835 : 0 : return rte_flow_error_set(error, ENOTSUP,
3836 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3837 : : "multiple tunnel layers not supported");
3838 : : }
3839 [ # # ]: 0 : if (!mask)
3840 : : mask = nic_mask;
3841 : 0 : ret = mlx5_flow_item_acceptable
3842 : : (dev, item, (const uint8_t *)mask,
3843 : : (const uint8_t *)nic_mask,
3844 : : sizeof(struct rte_flow_item_mpls),
3845 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3846 : : if (ret < 0)
3847 : : return ret;
3848 : : return 0;
3849 : : #else
3850 : : return rte_flow_error_set(error, ENOTSUP,
3851 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3852 : : "MPLS is not supported by Verbs, please"
3853 : : " update.");
3854 : : #endif
3855 : : }
3856 : :
3857 : : /**
3858 : : * Validate NVGRE item.
3859 : : *
3860 : : * @param[in] item
3861 : : * Item specification.
3862 : : * @param[in] item_flags
3863 : : * Bit flags to mark detected items.
3864 : : * @param[in] target_protocol
3865 : : * The next protocol in the previous item.
3866 : : * @param[out] error
3867 : : * Pointer to error structure.
3868 : : *
3869 : : * @return
3870 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3871 : : */
3872 : : int
3873 : 0 : mlx5_flow_validate_item_nvgre(const struct rte_eth_dev *dev,
3874 : : const struct rte_flow_item *item,
3875 : : uint64_t item_flags,
3876 : : uint8_t target_protocol,
3877 : : struct rte_flow_error *error)
3878 : : {
3879 : 0 : const struct rte_flow_item_nvgre *mask = item->mask;
3880 : : int ret;
3881 : :
3882 [ # # ]: 0 : const struct rte_flow_item_nvgre hws_nic_mask = {
3883 : : .c_k_s_rsvd0_ver = RTE_BE16(0xB000),
3884 : : .protocol = RTE_BE16(UINT16_MAX),
3885 : : .tni = {0xff, 0xff, 0xff},
3886 : : .flow_id = 0xff
3887 : : };
3888 : : const struct rte_flow_item_nvgre *nic_mask = !mlx5_hws_active(dev) ?
3889 [ # # ]: 0 : &rte_flow_item_nvgre_mask : &hws_nic_mask;
3890 : :
3891 [ # # ]: 0 : if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
3892 : 0 : return rte_flow_error_set(error, EINVAL,
3893 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3894 : : "protocol filtering not compatible"
3895 : : " with this GRE layer");
3896 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3897 : 0 : return rte_flow_error_set(error, ENOTSUP,
3898 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3899 : : "multiple tunnel layers not"
3900 : : " supported");
3901 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
3902 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
3903 : 0 : return rte_flow_error_set(error, ENOTSUP,
3904 : : RTE_FLOW_ERROR_TYPE_ITEM,
3905 : : item, "L3 Layer is missing");
3906 : : }
3907 [ # # ]: 0 : if (!mask)
3908 : : mask = nic_mask;
3909 : 0 : ret = mlx5_flow_item_acceptable
3910 : : (dev, item, (const uint8_t *)mask,
3911 : : (const uint8_t *)nic_mask,
3912 : : sizeof(struct rte_flow_item_nvgre),
3913 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3914 : : if (ret < 0)
3915 : : return ret;
3916 : : return 0;
3917 : : }
3918 : :
3919 : : /**
3920 : : * Validate eCPRI item.
3921 : : *
3922 : : * @param[in] item
3923 : : * Item specification.
3924 : : * @param[in] item_flags
3925 : : * Bit-fields that holds the items detected until now.
3926 : : * @param[in] last_item
3927 : : * Previous validated item in the pattern items.
3928 : : * @param[in] ether_type
3929 : : * Type in the ethernet layer header (including dot1q).
3930 : : * @param[in] acc_mask
3931 : : * Acceptable mask, if NULL default internal default mask
3932 : : * will be used to check whether item fields are supported.
3933 : : * @param[out] error
3934 : : * Pointer to error structure.
3935 : : *
3936 : : * @return
3937 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3938 : : */
3939 : : int
3940 : 0 : mlx5_flow_validate_item_ecpri(const struct rte_eth_dev *dev,
3941 : : const struct rte_flow_item *item,
3942 : : uint64_t item_flags,
3943 : : uint64_t last_item,
3944 : : uint16_t ether_type,
3945 : : const struct rte_flow_item_ecpri *acc_mask,
3946 : : struct rte_flow_error *error)
3947 : : {
3948 : 0 : const struct rte_flow_item_ecpri *mask = item->mask;
3949 : 0 : const struct rte_flow_item_ecpri nic_mask = {
3950 : : .hdr = {
3951 : : .common = {
3952 : : .u32 =
3953 : : RTE_BE32(((const struct rte_ecpri_common_hdr) {
3954 : : .type = 0xFF,
3955 : : }).u32),
3956 : : },
3957 : : .dummy[0] = 0xFFFFFFFF,
3958 : : },
3959 : : };
3960 : : const uint64_t outer_l2_vlan = (MLX5_FLOW_LAYER_OUTER_L2 |
3961 : : MLX5_FLOW_LAYER_OUTER_VLAN);
3962 : : struct rte_flow_item_ecpri mask_lo;
3963 : :
3964 [ # # # # ]: 0 : if (!(last_item & outer_l2_vlan) &&
3965 : : last_item != MLX5_FLOW_LAYER_OUTER_L4_UDP)
3966 : 0 : return rte_flow_error_set(error, EINVAL,
3967 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3968 : : "eCPRI can only follow L2/VLAN layer or UDP layer");
3969 [ # # ]: 0 : if ((last_item & outer_l2_vlan) && ether_type &&
3970 [ # # ]: 0 : ether_type != RTE_ETHER_TYPE_ECPRI)
3971 : 0 : return rte_flow_error_set(error, EINVAL,
3972 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3973 : : "eCPRI cannot follow L2/VLAN layer which ether type is not 0xAEFE");
3974 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3975 : 0 : return rte_flow_error_set(error, EINVAL,
3976 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3977 : : "eCPRI with tunnel is not supported right now");
3978 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_OUTER_L3)
3979 : 0 : return rte_flow_error_set(error, ENOTSUP,
3980 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3981 : : "multiple L3 layers not supported");
3982 [ # # ]: 0 : else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP)
3983 : 0 : return rte_flow_error_set(error, EINVAL,
3984 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3985 : : "eCPRI cannot coexist with a TCP layer");
3986 : : /* In specification, eCPRI could be over UDP layer. */
3987 [ # # ]: 0 : else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP)
3988 : 0 : return rte_flow_error_set(error, EINVAL,
3989 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3990 : : "eCPRI over UDP layer is not yet supported right now");
3991 : : /* Mask for type field in common header could be zero. */
3992 [ # # ]: 0 : if (!mask)
3993 : : mask = &rte_flow_item_ecpri_mask;
3994 [ # # ]: 0 : mask_lo.hdr.common.u32 = rte_be_to_cpu_32(mask->hdr.common.u32);
3995 : : /* Input mask is in big-endian format. */
3996 [ # # ]: 0 : if (mask_lo.hdr.common.type != 0 && mask_lo.hdr.common.type != 0xff)
3997 : 0 : return rte_flow_error_set(error, EINVAL,
3998 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
3999 : : "partial mask is not supported for protocol");
4000 [ # # # # ]: 0 : else if (mask_lo.hdr.common.type == 0 && mask->hdr.dummy[0] != 0)
4001 : 0 : return rte_flow_error_set(error, EINVAL,
4002 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
4003 : : "message header mask must be after a type mask");
4004 [ # # ]: 0 : return mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
4005 : : acc_mask ? (const uint8_t *)acc_mask
4006 : : : (const uint8_t *)&nic_mask,
4007 : : sizeof(struct rte_flow_item_ecpri),
4008 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
4009 : : }
4010 : :
4011 : : /**
4012 : : * Validate the NSH item.
4013 : : *
4014 : : * @param[in] dev
4015 : : * Pointer to Ethernet device on which flow rule is being created on.
4016 : : * @param[out] error
4017 : : * Pointer to error structure.
4018 : : *
4019 : : * @return
4020 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4021 : : */
4022 : : int
4023 : 0 : mlx5_flow_validate_item_nsh(struct rte_eth_dev *dev,
4024 : : const struct rte_flow_item *item,
4025 : : struct rte_flow_error *error)
4026 : : {
4027 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4028 : :
4029 [ # # ]: 0 : if (item->mask) {
4030 : 0 : return rte_flow_error_set(error, ENOTSUP,
4031 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
4032 : : "NSH fields matching is not supported");
4033 : : }
4034 : :
4035 [ # # ]: 0 : if (!priv->sh->config.dv_flow_en) {
4036 : 0 : return rte_flow_error_set(error, ENOTSUP,
4037 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4038 : : NULL, "NSH support requires DV flow interface");
4039 : : }
4040 : :
4041 [ # # ]: 0 : if (!priv->sh->cdev->config.hca_attr.tunnel_stateless_vxlan_gpe_nsh) {
4042 : 0 : return rte_flow_error_set(error, ENOTSUP,
4043 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
4044 : : "Current FW does not support matching on NSH");
4045 : : }
4046 : :
4047 : : return 0;
4048 : : }
4049 : :
4050 : : static uintptr_t
4051 : 0 : flow_null_list_create(struct rte_eth_dev *dev __rte_unused,
4052 : : enum mlx5_flow_type type __rte_unused,
4053 : : const struct rte_flow_attr *attr __rte_unused,
4054 : : const struct rte_flow_item items[] __rte_unused,
4055 : : const struct rte_flow_action actions[] __rte_unused,
4056 : : bool external __rte_unused,
4057 : : struct rte_flow_error *error)
4058 : : {
4059 : 0 : rte_flow_error_set(error, ENOTSUP,
4060 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
4061 : 0 : return 0;
4062 : : }
4063 : :
4064 : : static int
4065 : 0 : flow_null_validate(struct rte_eth_dev *dev __rte_unused,
4066 : : const struct rte_flow_attr *attr __rte_unused,
4067 : : const struct rte_flow_item items[] __rte_unused,
4068 : : const struct rte_flow_action actions[] __rte_unused,
4069 : : bool external __rte_unused,
4070 : : int hairpin __rte_unused,
4071 : : struct rte_flow_error *error)
4072 : : {
4073 : 0 : return rte_flow_error_set(error, ENOTSUP,
4074 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
4075 : : }
4076 : :
4077 : : static struct mlx5_flow *
4078 : 0 : flow_null_prepare(struct rte_eth_dev *dev __rte_unused,
4079 : : const struct rte_flow_attr *attr __rte_unused,
4080 : : const struct rte_flow_item items[] __rte_unused,
4081 : : const struct rte_flow_action actions[] __rte_unused,
4082 : : struct rte_flow_error *error)
4083 : : {
4084 : 0 : rte_flow_error_set(error, ENOTSUP,
4085 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
4086 : 0 : return NULL;
4087 : : }
4088 : :
4089 : : static int
4090 : 0 : flow_null_translate(struct rte_eth_dev *dev __rte_unused,
4091 : : struct mlx5_flow *dev_flow __rte_unused,
4092 : : const struct rte_flow_attr *attr __rte_unused,
4093 : : const struct rte_flow_item items[] __rte_unused,
4094 : : const struct rte_flow_action actions[] __rte_unused,
4095 : : struct rte_flow_error *error)
4096 : : {
4097 : 0 : return rte_flow_error_set(error, ENOTSUP,
4098 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
4099 : : }
4100 : :
4101 : : static int
4102 : 0 : flow_null_apply(struct rte_eth_dev *dev __rte_unused,
4103 : : struct rte_flow *flow __rte_unused,
4104 : : struct rte_flow_error *error)
4105 : : {
4106 : 0 : return rte_flow_error_set(error, ENOTSUP,
4107 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
4108 : : }
4109 : :
4110 : : static void
4111 : 0 : flow_null_remove(struct rte_eth_dev *dev __rte_unused,
4112 : : struct rte_flow *flow __rte_unused)
4113 : : {
4114 : 0 : }
4115 : :
4116 : : static void
4117 : 0 : flow_null_destroy(struct rte_eth_dev *dev __rte_unused,
4118 : : struct rte_flow *flow __rte_unused)
4119 : : {
4120 : 0 : }
4121 : :
4122 : : static int
4123 : 0 : flow_null_query(struct rte_eth_dev *dev __rte_unused,
4124 : : struct rte_flow *flow __rte_unused,
4125 : : const struct rte_flow_action *actions __rte_unused,
4126 : : void *data __rte_unused,
4127 : : struct rte_flow_error *error)
4128 : : {
4129 : 0 : return rte_flow_error_set(error, ENOTSUP,
4130 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
4131 : : }
4132 : :
4133 : : static int
4134 : 0 : flow_null_sync_domain(struct rte_eth_dev *dev __rte_unused,
4135 : : uint32_t domains __rte_unused,
4136 : : uint32_t flags __rte_unused)
4137 : : {
4138 : 0 : return 0;
4139 : : }
4140 : :
4141 : : int
4142 : 0 : flow_null_get_aged_flows(struct rte_eth_dev *dev,
4143 : : void **context __rte_unused,
4144 : : uint32_t nb_contexts __rte_unused,
4145 : : struct rte_flow_error *error __rte_unused)
4146 : : {
4147 : 0 : DRV_LOG(ERR, "port %u get aged flows is not supported.",
4148 : : dev->data->port_id);
4149 : 0 : return -ENOTSUP;
4150 : : }
4151 : :
4152 : : uint32_t
4153 : 0 : flow_null_counter_allocate(struct rte_eth_dev *dev)
4154 : : {
4155 : 0 : DRV_LOG(ERR, "port %u counter allocate is not supported.",
4156 : : dev->data->port_id);
4157 : 0 : return 0;
4158 : : }
4159 : :
4160 : : void
4161 : 0 : flow_null_counter_free(struct rte_eth_dev *dev,
4162 : : uint32_t counter __rte_unused)
4163 : : {
4164 : 0 : DRV_LOG(ERR, "port %u counter free is not supported.",
4165 : : dev->data->port_id);
4166 : 0 : }
4167 : :
4168 : : int
4169 : 0 : flow_null_counter_query(struct rte_eth_dev *dev,
4170 : : uint32_t counter __rte_unused,
4171 : : bool clear __rte_unused,
4172 : : uint64_t *pkts __rte_unused,
4173 : : uint64_t *bytes __rte_unused,
4174 : : void **action __rte_unused)
4175 : : {
4176 : 0 : DRV_LOG(ERR, "port %u counter query is not supported.",
4177 : : dev->data->port_id);
4178 : 0 : return -ENOTSUP;
4179 : : }
4180 : :
4181 : : /* Void driver to protect from null pointer reference. */
4182 : : const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
4183 : : .list_create = flow_null_list_create,
4184 : : .validate = flow_null_validate,
4185 : : .prepare = flow_null_prepare,
4186 : : .translate = flow_null_translate,
4187 : : .apply = flow_null_apply,
4188 : : .remove = flow_null_remove,
4189 : : .destroy = flow_null_destroy,
4190 : : .query = flow_null_query,
4191 : : .sync_domain = flow_null_sync_domain,
4192 : : .get_aged_flows = flow_null_get_aged_flows,
4193 : : .counter_alloc = flow_null_counter_allocate,
4194 : : .counter_free = flow_null_counter_free,
4195 : : .counter_query = flow_null_counter_query
4196 : : };
4197 : :
4198 : : /**
4199 : : * Select flow driver type according to flow attributes and device
4200 : : * configuration.
4201 : : *
4202 : : * @param[in] dev
4203 : : * Pointer to the dev structure.
4204 : : * @param[in] attr
4205 : : * Pointer to the flow attributes.
4206 : : *
4207 : : * @return
4208 : : * flow driver type, MLX5_FLOW_TYPE_MAX otherwise.
4209 : : */
4210 : : static enum mlx5_flow_drv_type
4211 : 0 : flow_get_drv_type(struct rte_eth_dev *dev, const struct rte_flow_attr *attr)
4212 : : {
4213 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4214 : : /* The OS can determine first a specific flow type (DV, VERBS) */
4215 : : enum mlx5_flow_drv_type type = mlx5_flow_os_get_type();
4216 : :
4217 : : if (type != MLX5_FLOW_TYPE_MAX)
4218 : : return type;
4219 : : /*
4220 : : * Currently when dv_flow_en == 2, only HW steering engine is
4221 : : * supported. New engines can also be chosen here if ready.
4222 : : */
4223 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
4224 : : return MLX5_FLOW_TYPE_HW;
4225 [ # # ]: 0 : if (!attr)
4226 : : return MLX5_FLOW_TYPE_MIN;
4227 : : /* If no OS specific type - continue with DV/VERBS selection */
4228 [ # # # # ]: 0 : if (attr->transfer && priv->sh->config.dv_esw_en)
4229 : : type = MLX5_FLOW_TYPE_DV;
4230 [ # # ]: 0 : if (!attr->transfer)
4231 [ # # # # : 0 : type = priv->sh->config.dv_flow_en ? MLX5_FLOW_TYPE_DV :
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
4232 : : MLX5_FLOW_TYPE_VERBS;
4233 : : return type;
4234 : : }
4235 : :
4236 : : #define flow_get_drv_ops(type) flow_drv_ops[type]
4237 : :
4238 : : /**
4239 : : * Flow driver validation API. This abstracts calling driver specific functions.
4240 : : * The type of flow driver is determined according to flow attributes.
4241 : : *
4242 : : * @param[in] dev
4243 : : * Pointer to the dev structure.
4244 : : * @param[in] attr
4245 : : * Pointer to the flow attributes.
4246 : : * @param[in] items
4247 : : * Pointer to the list of items.
4248 : : * @param[in] actions
4249 : : * Pointer to the list of actions.
4250 : : * @param[in] external
4251 : : * This flow rule is created by request external to PMD.
4252 : : * @param[in] hairpin
4253 : : * Number of hairpin TX actions, 0 means classic flow.
4254 : : * @param[out] error
4255 : : * Pointer to the error structure.
4256 : : *
4257 : : * @return
4258 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4259 : : */
4260 : : static inline int
4261 : 0 : flow_drv_validate(struct rte_eth_dev *dev,
4262 : : const struct rte_flow_attr *attr,
4263 : : const struct rte_flow_item items[],
4264 : : const struct rte_flow_action actions[],
4265 : : bool external, int hairpin, struct rte_flow_error *error)
4266 : : {
4267 : : const struct mlx5_flow_driver_ops *fops;
4268 : 0 : enum mlx5_flow_drv_type type = flow_get_drv_type(dev, attr);
4269 : :
4270 : 0 : fops = flow_get_drv_ops(type);
4271 : 0 : return fops->validate(dev, attr, items, actions, external,
4272 : : hairpin, error);
4273 : : }
4274 : :
4275 : : /**
4276 : : * Flow driver preparation API. This abstracts calling driver specific
4277 : : * functions. Parent flow (rte_flow) should have driver type (drv_type). It
4278 : : * calculates the size of memory required for device flow, allocates the memory,
4279 : : * initializes the device flow and returns the pointer.
4280 : : *
4281 : : * @note
4282 : : * This function initializes device flow structure such as dv or verbs in
4283 : : * struct mlx5_flow. However, it is caller's responsibility to initialize the
4284 : : * rest. For example, adding returning device flow to flow->dev_flow list and
4285 : : * setting backward reference to the flow should be done out of this function.
4286 : : * layers field is not filled either.
4287 : : *
4288 : : * @param[in] dev
4289 : : * Pointer to the dev structure.
4290 : : * @param[in] attr
4291 : : * Pointer to the flow attributes.
4292 : : * @param[in] items
4293 : : * Pointer to the list of items.
4294 : : * @param[in] actions
4295 : : * Pointer to the list of actions.
4296 : : * @param[in] flow_idx
4297 : : * This memory pool index to the flow.
4298 : : * @param[out] error
4299 : : * Pointer to the error structure.
4300 : : *
4301 : : * @return
4302 : : * Pointer to device flow on success, otherwise NULL and rte_errno is set.
4303 : : */
4304 : : static inline struct mlx5_flow *
4305 : : flow_drv_prepare(struct rte_eth_dev *dev,
4306 : : const struct rte_flow *flow,
4307 : : const struct rte_flow_attr *attr,
4308 : : const struct rte_flow_item items[],
4309 : : const struct rte_flow_action actions[],
4310 : : uint32_t flow_idx,
4311 : : struct rte_flow_error *error)
4312 : : {
4313 : : const struct mlx5_flow_driver_ops *fops;
4314 : 0 : enum mlx5_flow_drv_type type = flow->drv_type;
4315 : : struct mlx5_flow *mlx5_flow = NULL;
4316 : :
4317 : : MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
4318 : 0 : fops = flow_get_drv_ops(type);
4319 : 0 : mlx5_flow = fops->prepare(dev, attr, items, actions, error);
4320 [ # # # # : 0 : if (mlx5_flow)
# # ]
4321 : 0 : mlx5_flow->flow_idx = flow_idx;
4322 : : return mlx5_flow;
4323 : : }
4324 : :
4325 : : /**
4326 : : * Flow driver translation API. This abstracts calling driver specific
4327 : : * functions. Parent flow (rte_flow) should have driver type (drv_type). It
4328 : : * translates a generic flow into a driver flow. flow_drv_prepare() must
4329 : : * precede.
4330 : : *
4331 : : * @note
4332 : : * dev_flow->layers could be filled as a result of parsing during translation
4333 : : * if needed by flow_drv_apply(). dev_flow->flow->actions can also be filled
4334 : : * if necessary. As a flow can have multiple dev_flows by RSS flow expansion,
4335 : : * flow->actions could be overwritten even though all the expanded dev_flows
4336 : : * have the same actions.
4337 : : *
4338 : : * @param[in] dev
4339 : : * Pointer to the rte dev structure.
4340 : : * @param[in, out] dev_flow
4341 : : * Pointer to the mlx5 flow.
4342 : : * @param[in] attr
4343 : : * Pointer to the flow attributes.
4344 : : * @param[in] items
4345 : : * Pointer to the list of items.
4346 : : * @param[in] actions
4347 : : * Pointer to the list of actions.
4348 : : * @param[out] error
4349 : : * Pointer to the error structure.
4350 : : *
4351 : : * @return
4352 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4353 : : */
4354 : : static inline int
4355 : : flow_drv_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
4356 : : const struct rte_flow_attr *attr,
4357 : : const struct rte_flow_item items[],
4358 : : const struct rte_flow_action actions[],
4359 : : struct rte_flow_error *error)
4360 : : {
4361 : : const struct mlx5_flow_driver_ops *fops;
4362 : 0 : enum mlx5_flow_drv_type type = dev_flow->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->translate(dev, dev_flow, attr, items, actions, error);
4367 : : }
4368 : :
4369 : : /**
4370 : : * Flow driver apply API. This abstracts calling driver specific functions.
4371 : : * Parent flow (rte_flow) should have driver type (drv_type). It applies
4372 : : * translated driver flows on to device. flow_drv_translate() must precede.
4373 : : *
4374 : : * @param[in] dev
4375 : : * Pointer to Ethernet device structure.
4376 : : * @param[in, out] flow
4377 : : * Pointer to flow structure.
4378 : : * @param[out] error
4379 : : * Pointer to error structure.
4380 : : *
4381 : : * @return
4382 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4383 : : */
4384 : : static inline int
4385 : : flow_drv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
4386 : : struct rte_flow_error *error)
4387 : : {
4388 : : const struct mlx5_flow_driver_ops *fops;
4389 : 0 : enum mlx5_flow_drv_type type = flow->drv_type;
4390 : :
4391 : : MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
4392 : 0 : fops = flow_get_drv_ops(type);
4393 : 0 : return fops->apply(dev, flow, error);
4394 : : }
4395 : :
4396 : : /**
4397 : : * Flow driver destroy API. This abstracts calling driver specific functions.
4398 : : * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
4399 : : * on device and releases resources of the flow.
4400 : : *
4401 : : * @param[in] dev
4402 : : * Pointer to Ethernet device.
4403 : : * @param[in, out] flow
4404 : : * Pointer to flow structure.
4405 : : */
4406 : : static inline void
4407 : : flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
4408 : : {
4409 : : const struct mlx5_flow_driver_ops *fops;
4410 : 0 : enum mlx5_flow_drv_type type = flow->drv_type;
4411 : :
4412 : : MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
4413 : 0 : fops = flow_get_drv_ops(type);
4414 : 0 : fops->destroy(dev, flow);
4415 : : }
4416 : :
4417 : : /**
4418 : : * Flow driver find RSS policy tbl API. This abstracts calling driver
4419 : : * specific functions. Parent flow (rte_flow) should have driver
4420 : : * type (drv_type). It will find the RSS policy table that has the rss_desc.
4421 : : *
4422 : : * @param[in] dev
4423 : : * Pointer to Ethernet device.
4424 : : * @param[in, out] flow
4425 : : * Pointer to flow structure.
4426 : : * @param[in] policy
4427 : : * Pointer to meter policy table.
4428 : : * @param[in] rss_desc
4429 : : * Pointer to rss_desc
4430 : : */
4431 : : static struct mlx5_flow_meter_sub_policy *
4432 : : flow_drv_meter_sub_policy_rss_prepare(struct rte_eth_dev *dev,
4433 : : struct rte_flow *flow,
4434 : : struct mlx5_flow_meter_policy *policy,
4435 : : struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS])
4436 : : {
4437 : : const struct mlx5_flow_driver_ops *fops;
4438 : 0 : enum mlx5_flow_drv_type type = flow->drv_type;
4439 : :
4440 : : MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
4441 : 0 : fops = flow_get_drv_ops(type);
4442 : 0 : return fops->meter_sub_policy_rss_prepare(dev, policy, rss_desc);
4443 : : }
4444 : :
4445 : : /**
4446 : : * Flow driver color tag rule API. This abstracts calling driver
4447 : : * specific functions. Parent flow (rte_flow) should have driver
4448 : : * type (drv_type). It will create the color tag rules in hierarchy meter.
4449 : : *
4450 : : * @param[in] dev
4451 : : * Pointer to Ethernet device.
4452 : : * @param[in, out] flow
4453 : : * Pointer to flow structure.
4454 : : * @param[in] fm
4455 : : * Pointer to flow meter structure.
4456 : : * @param[in] src_port
4457 : : * The src port this extra rule should use.
4458 : : * @param[in] item
4459 : : * The src port id match item.
4460 : : * @param[out] error
4461 : : * Pointer to error structure.
4462 : : */
4463 : : static int
4464 : : flow_drv_mtr_hierarchy_rule_create(struct rte_eth_dev *dev,
4465 : : struct rte_flow *flow,
4466 : : struct mlx5_flow_meter_info *fm,
4467 : : int32_t src_port,
4468 : : const struct rte_flow_item *item,
4469 : : struct rte_flow_error *error)
4470 : : {
4471 : : const struct mlx5_flow_driver_ops *fops;
4472 : 0 : enum mlx5_flow_drv_type type = flow->drv_type;
4473 : :
4474 : : MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
4475 : 0 : fops = flow_get_drv_ops(type);
4476 : 0 : return fops->meter_hierarchy_rule_create(dev, fm,
4477 : : src_port, item, error);
4478 : : }
4479 : :
4480 : : /**
4481 : : * Get RSS action from the action list.
4482 : : *
4483 : : * @param[in] dev
4484 : : * Pointer to Ethernet device.
4485 : : * @param[in] actions
4486 : : * Pointer to the list of actions.
4487 : : * @param[in] flow
4488 : : * Parent flow structure pointer.
4489 : : *
4490 : : * @return
4491 : : * Pointer to the RSS action if exist, else return NULL.
4492 : : */
4493 : : static const struct rte_flow_action_rss*
4494 : 0 : flow_get_rss_action(struct rte_eth_dev *dev,
4495 : : const struct rte_flow_action actions[])
4496 : : {
4497 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4498 : : const struct rte_flow_action_rss *rss = NULL;
4499 : : struct mlx5_meter_policy_action_container *acg;
4500 : : struct mlx5_meter_policy_action_container *acy;
4501 : :
4502 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4503 [ # # # # ]: 0 : switch (actions->type) {
4504 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
4505 : 0 : rss = actions->conf;
4506 : 0 : break;
4507 : 0 : case RTE_FLOW_ACTION_TYPE_SAMPLE:
4508 : : {
4509 : 0 : const struct rte_flow_action_sample *sample =
4510 : : actions->conf;
4511 : 0 : const struct rte_flow_action *act = sample->actions;
4512 [ # # ]: 0 : for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++)
4513 [ # # ]: 0 : if (act->type == RTE_FLOW_ACTION_TYPE_RSS)
4514 : 0 : rss = act->conf;
4515 : : break;
4516 : : }
4517 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
4518 : : {
4519 : : uint32_t mtr_idx;
4520 : : struct mlx5_flow_meter_info *fm;
4521 : : struct mlx5_flow_meter_policy *policy;
4522 : 0 : const struct rte_flow_action_meter *mtr = actions->conf;
4523 : :
4524 : 0 : fm = mlx5_flow_meter_find(priv, mtr->mtr_id, &mtr_idx);
4525 [ # # # # ]: 0 : if (fm && !fm->def_policy) {
4526 : 0 : policy = mlx5_flow_meter_policy_find(dev,
4527 : : fm->policy_id, NULL);
4528 : : MLX5_ASSERT(policy);
4529 [ # # ]: 0 : if (policy->is_hierarchy) {
4530 : : policy =
4531 : 0 : mlx5_flow_meter_hierarchy_get_final_policy(dev,
4532 : : policy);
4533 [ # # ]: 0 : if (!policy)
4534 : 0 : return NULL;
4535 : : }
4536 [ # # ]: 0 : if (policy->is_rss) {
4537 : : acg =
4538 : : &policy->act_cnt[RTE_COLOR_GREEN];
4539 : : acy =
4540 : : &policy->act_cnt[RTE_COLOR_YELLOW];
4541 [ # # ]: 0 : if (acg->fate_action ==
4542 : : MLX5_FLOW_FATE_SHARED_RSS)
4543 : 0 : rss = acg->rss->conf;
4544 [ # # ]: 0 : else if (acy->fate_action ==
4545 : : MLX5_FLOW_FATE_SHARED_RSS)
4546 : 0 : rss = acy->rss->conf;
4547 : : }
4548 : : }
4549 : 0 : break;
4550 : : }
4551 : : default:
4552 : : break;
4553 : : }
4554 : : }
4555 : : return rss;
4556 : : }
4557 : :
4558 : : /**
4559 : : * Get ASO age action by index.
4560 : : *
4561 : : * @param[in] dev
4562 : : * Pointer to the Ethernet device structure.
4563 : : * @param[in] age_idx
4564 : : * Index to the ASO age action.
4565 : : *
4566 : : * @return
4567 : : * The specified ASO age action.
4568 : : */
4569 : : struct mlx5_aso_age_action*
4570 : 0 : flow_aso_age_get_by_idx(struct rte_eth_dev *dev, uint32_t age_idx)
4571 : : {
4572 : 0 : uint16_t pool_idx = age_idx & UINT16_MAX;
4573 : 0 : uint16_t offset = (age_idx >> 16) & UINT16_MAX;
4574 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4575 : 0 : struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
4576 : : struct mlx5_aso_age_pool *pool;
4577 : :
4578 : 0 : rte_rwlock_read_lock(&mng->resize_rwl);
4579 : 0 : pool = mng->pools[pool_idx];
4580 : : rte_rwlock_read_unlock(&mng->resize_rwl);
4581 : 0 : return &pool->actions[offset - 1];
4582 : : }
4583 : :
4584 : : /* maps indirect action to translated direct in some actions array */
4585 : : struct mlx5_translated_action_handle {
4586 : : struct rte_flow_action_handle *action; /**< Indirect action handle. */
4587 : : int index; /**< Index in related array of rte_flow_action. */
4588 : : };
4589 : :
4590 : : /**
4591 : : * Translates actions of type RTE_FLOW_ACTION_TYPE_INDIRECT to related
4592 : : * direct action if translation possible.
4593 : : * This functionality used to run same execution path for both direct and
4594 : : * indirect actions on flow create. All necessary preparations for indirect
4595 : : * action handling should be performed on *handle* actions list returned
4596 : : * from this call.
4597 : : *
4598 : : * @param[in] dev
4599 : : * Pointer to Ethernet device.
4600 : : * @param[in] actions
4601 : : * List of actions to translate.
4602 : : * @param[out] handle
4603 : : * List to store translated indirect action object handles.
4604 : : * @param[in, out] indir_n
4605 : : * Size of *handle* array. On return should be updated with number of
4606 : : * indirect actions retrieved from the *actions* list.
4607 : : * @param[out] translated_actions
4608 : : * List of actions where all indirect actions were translated to direct
4609 : : * if possible. NULL if no translation took place.
4610 : : * @param[out] error
4611 : : * Pointer to the error structure.
4612 : : *
4613 : : * @return
4614 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4615 : : */
4616 : : static int
4617 : 0 : flow_action_handles_translate(struct rte_eth_dev *dev,
4618 : : const struct rte_flow_action actions[],
4619 : : struct mlx5_translated_action_handle *handle,
4620 : : int *indir_n,
4621 : : struct rte_flow_action **translated_actions,
4622 : : struct rte_flow_error *error)
4623 : : {
4624 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4625 : : struct rte_flow_action *translated = NULL;
4626 : : size_t actions_size;
4627 : : int n;
4628 : : int copied_n = 0;
4629 : : struct mlx5_translated_action_handle *handle_end = NULL;
4630 : :
4631 [ # # ]: 0 : for (n = 0; actions[n].type != RTE_FLOW_ACTION_TYPE_END; n++) {
4632 [ # # ]: 0 : if (actions[n].type != RTE_FLOW_ACTION_TYPE_INDIRECT)
4633 : 0 : continue;
4634 [ # # ]: 0 : if (copied_n == *indir_n) {
4635 : 0 : return rte_flow_error_set
4636 : : (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_NUM,
4637 : : NULL, "too many shared actions");
4638 : : }
4639 [ # # ]: 0 : rte_memcpy(&handle[copied_n].action, &actions[n].conf,
4640 : : sizeof(actions[n].conf));
4641 : 0 : handle[copied_n].index = n;
4642 : 0 : copied_n++;
4643 : : }
4644 : 0 : n++;
4645 : 0 : *indir_n = copied_n;
4646 [ # # ]: 0 : if (!copied_n)
4647 : : return 0;
4648 : 0 : actions_size = sizeof(struct rte_flow_action) * n;
4649 : 0 : translated = mlx5_malloc(MLX5_MEM_ZERO, actions_size, 0, SOCKET_ID_ANY);
4650 [ # # ]: 0 : if (!translated) {
4651 : 0 : rte_errno = ENOMEM;
4652 : 0 : return -ENOMEM;
4653 : : }
4654 : : memcpy(translated, actions, actions_size);
4655 [ # # ]: 0 : for (handle_end = handle + copied_n; handle < handle_end; handle++) {
4656 : : struct mlx5_shared_action_rss *shared_rss;
4657 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle->action;
4658 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
4659 : 0 : uint32_t idx = act_idx &
4660 : : ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
4661 : :
4662 [ # # # # : 0 : switch (type) {
# # ]
4663 : 0 : case MLX5_INDIRECT_ACTION_TYPE_RSS:
4664 : 0 : shared_rss = mlx5_ipool_get
4665 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
4666 : 0 : translated[handle->index].type =
4667 : : RTE_FLOW_ACTION_TYPE_RSS;
4668 : 0 : translated[handle->index].conf =
4669 : 0 : &shared_rss->origin;
4670 : 0 : break;
4671 : 0 : case MLX5_INDIRECT_ACTION_TYPE_COUNT:
4672 : 0 : translated[handle->index].type =
4673 : : (enum rte_flow_action_type)
4674 : : MLX5_RTE_FLOW_ACTION_TYPE_COUNT;
4675 : 0 : translated[handle->index].conf = (void *)(uintptr_t)idx;
4676 : 0 : break;
4677 : 0 : case MLX5_INDIRECT_ACTION_TYPE_METER_MARK:
4678 : 0 : translated[handle->index].type =
4679 : : (enum rte_flow_action_type)
4680 : : MLX5_RTE_FLOW_ACTION_TYPE_METER_MARK;
4681 : 0 : translated[handle->index].conf = (void *)(uintptr_t)idx;
4682 : 0 : break;
4683 : 0 : case MLX5_INDIRECT_ACTION_TYPE_AGE:
4684 [ # # ]: 0 : if (priv->sh->flow_hit_aso_en) {
4685 : 0 : translated[handle->index].type =
4686 : : (enum rte_flow_action_type)
4687 : : MLX5_RTE_FLOW_ACTION_TYPE_AGE;
4688 : 0 : translated[handle->index].conf =
4689 : 0 : (void *)(uintptr_t)idx;
4690 : 0 : break;
4691 : : }
4692 : : /* Fall-through */
4693 : : case MLX5_INDIRECT_ACTION_TYPE_CT:
4694 [ # # ]: 0 : if (priv->sh->ct_aso_en) {
4695 : 0 : translated[handle->index].type =
4696 : : RTE_FLOW_ACTION_TYPE_CONNTRACK;
4697 : 0 : translated[handle->index].conf =
4698 : 0 : (void *)(uintptr_t)idx;
4699 : 0 : break;
4700 : : }
4701 : : /* Fall-through */
4702 : : default:
4703 : 0 : mlx5_free(translated);
4704 : 0 : return rte_flow_error_set
4705 : : (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
4706 : : NULL, "invalid indirect action type");
4707 : : }
4708 : : }
4709 : 0 : *translated_actions = translated;
4710 : 0 : return 0;
4711 : : }
4712 : :
4713 : : /**
4714 : : * Get Shared RSS action from the action list.
4715 : : *
4716 : : * @param[in] dev
4717 : : * Pointer to Ethernet device.
4718 : : * @param[in] shared
4719 : : * Pointer to the list of actions.
4720 : : * @param[in] shared_n
4721 : : * Actions list length.
4722 : : *
4723 : : * @return
4724 : : * The MLX5 RSS action ID if exists, otherwise return 0.
4725 : : */
4726 : : static uint32_t
4727 : 0 : flow_get_shared_rss_action(struct rte_eth_dev *dev,
4728 : : struct mlx5_translated_action_handle *handle,
4729 : : int shared_n)
4730 : : {
4731 : : struct mlx5_translated_action_handle *handle_end;
4732 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4733 : : struct mlx5_shared_action_rss *shared_rss;
4734 : :
4735 : :
4736 [ # # ]: 0 : for (handle_end = handle + shared_n; handle < handle_end; handle++) {
4737 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle->action;
4738 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
4739 : 0 : uint32_t idx = act_idx &
4740 : : ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
4741 [ # # ]: 0 : switch (type) {
4742 : 0 : case MLX5_INDIRECT_ACTION_TYPE_RSS:
4743 : 0 : shared_rss = mlx5_ipool_get
4744 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
4745 : : idx);
4746 : 0 : rte_atomic_fetch_add_explicit(&shared_rss->refcnt, 1,
4747 : : rte_memory_order_relaxed);
4748 : 0 : return idx;
4749 : : default:
4750 : : break;
4751 : : }
4752 : : }
4753 : : return 0;
4754 : : }
4755 : :
4756 : : static unsigned int
4757 : : find_graph_root(uint32_t rss_level)
4758 : : {
4759 : 0 : return rss_level < 2 ? MLX5_EXPANSION_ROOT :
4760 : : MLX5_EXPANSION_ROOT_OUTER;
4761 : : }
4762 : :
4763 : : /**
4764 : : * Get layer flags from the prefix flow.
4765 : : *
4766 : : * Some flows may be split to several subflows, the prefix subflow gets the
4767 : : * match items and the suffix sub flow gets the actions.
4768 : : * Some actions need the user defined match item flags to get the detail for
4769 : : * the action.
4770 : : * This function helps the suffix flow to get the item layer flags from prefix
4771 : : * subflow.
4772 : : *
4773 : : * @param[in] dev_flow
4774 : : * Pointer the created prefix subflow.
4775 : : *
4776 : : * @return
4777 : : * The layers get from prefix subflow.
4778 : : */
4779 : : static inline uint64_t
4780 : 0 : flow_get_prefix_layer_flags(struct mlx5_flow *dev_flow)
4781 : : {
4782 : : uint64_t layers = 0;
4783 : :
4784 : : /*
4785 : : * Layers bits could be localization, but usually the compiler will
4786 : : * help to do the optimization work for source code.
4787 : : * If no decap actions, use the layers directly.
4788 : : */
4789 [ # # ]: 0 : if (!(dev_flow->act_flags & MLX5_FLOW_ACTION_DECAP))
4790 : 0 : return dev_flow->handle->layers;
4791 : : /* Convert L3 layers with decap action. */
4792 [ # # ]: 0 : if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV4)
4793 : : layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV4;
4794 [ # # ]: 0 : else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV6)
4795 : : layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
4796 : : /* Convert L4 layers with decap action. */
4797 [ # # ]: 0 : if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_TCP)
4798 : 0 : layers |= MLX5_FLOW_LAYER_OUTER_L4_TCP;
4799 [ # # ]: 0 : else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_UDP)
4800 : 0 : layers |= MLX5_FLOW_LAYER_OUTER_L4_UDP;
4801 : : return layers;
4802 : : }
4803 : :
4804 : : /**
4805 : : * Get metadata split action information.
4806 : : *
4807 : : * @param[in] actions
4808 : : * Pointer to the list of actions.
4809 : : * @param[out] qrss
4810 : : * Pointer to the return pointer.
4811 : : * @param[out] qrss_type
4812 : : * Pointer to the action type to return. RTE_FLOW_ACTION_TYPE_END is returned
4813 : : * if no QUEUE/RSS is found.
4814 : : * @param[out] encap_idx
4815 : : * Pointer to the index of the encap action if exists, otherwise the last
4816 : : * action index.
4817 : : *
4818 : : * @return
4819 : : * Total number of actions.
4820 : : */
4821 : : static int
4822 : 0 : flow_parse_metadata_split_actions_info(const struct rte_flow_action actions[],
4823 : : const struct rte_flow_action **qrss,
4824 : : int *encap_idx)
4825 : : {
4826 : : const struct rte_flow_action_raw_encap *raw_encap;
4827 : : int actions_n = 0;
4828 : : int raw_decap_idx = -1;
4829 : :
4830 : 0 : *encap_idx = -1;
4831 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4832 [ # # # # : 0 : switch (actions->type) {
# ]
4833 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4834 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4835 : 0 : *encap_idx = actions_n;
4836 : 0 : break;
4837 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4838 : : raw_decap_idx = actions_n;
4839 : 0 : break;
4840 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4841 : 0 : raw_encap = actions->conf;
4842 [ # # ]: 0 : if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4843 : 0 : *encap_idx = raw_decap_idx != -1 ?
4844 [ # # ]: 0 : raw_decap_idx : actions_n;
4845 : : break;
4846 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
4847 : : case RTE_FLOW_ACTION_TYPE_RSS:
4848 : 0 : *qrss = actions;
4849 : 0 : break;
4850 : : default:
4851 : : break;
4852 : : }
4853 : 0 : actions_n++;
4854 : : }
4855 [ # # ]: 0 : if (*encap_idx == -1)
4856 : 0 : *encap_idx = actions_n;
4857 : : /* Count RTE_FLOW_ACTION_TYPE_END. */
4858 : 0 : return actions_n + 1;
4859 : : }
4860 : :
4861 : : /**
4862 : : * Check if the action will change packet.
4863 : : *
4864 : : * @param dev
4865 : : * Pointer to Ethernet device.
4866 : : * @param[in] type
4867 : : * action type.
4868 : : *
4869 : : * @return
4870 : : * true if action will change packet, false otherwise.
4871 : : */
4872 : 0 : static bool flow_check_modify_action_type(struct rte_eth_dev *dev,
4873 : : enum rte_flow_action_type type)
4874 : : {
4875 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4876 : :
4877 [ # # # ]: 0 : switch (type) {
4878 : : case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
4879 : : case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
4880 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
4881 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
4882 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
4883 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
4884 : : case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
4885 : : case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
4886 : : case RTE_FLOW_ACTION_TYPE_DEC_TTL:
4887 : : case RTE_FLOW_ACTION_TYPE_SET_TTL:
4888 : : case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
4889 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
4890 : : case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
4891 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
4892 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
4893 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
4894 : : case RTE_FLOW_ACTION_TYPE_SET_META:
4895 : : case RTE_FLOW_ACTION_TYPE_SET_TAG:
4896 : : case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
4897 : : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4898 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4899 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
4900 : : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4901 : : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
4902 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4903 : : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
4904 : : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4905 : : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4906 : : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
4907 : : return true;
4908 : 0 : case RTE_FLOW_ACTION_TYPE_FLAG:
4909 : : case RTE_FLOW_ACTION_TYPE_MARK:
4910 [ # # ]: 0 : if (priv->sh->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
4911 : : priv->sh->config.dv_xmeta_en != MLX5_XMETA_MODE_META32_HWS)
4912 : : return true;
4913 : : else
4914 : 0 : return false;
4915 : 0 : default:
4916 : 0 : return false;
4917 : : }
4918 : : }
4919 : :
4920 : : /**
4921 : : * Check meter action from the action list.
4922 : : *
4923 : : * @param dev
4924 : : * Pointer to Ethernet device.
4925 : : * @param[in] actions
4926 : : * Pointer to the list of actions.
4927 : : * @param[out] has_mtr
4928 : : * Pointer to the meter exist flag.
4929 : : * @param[out] has_modify
4930 : : * Pointer to the flag showing there's packet change action.
4931 : : * @param[out] meter_id
4932 : : * Pointer to the meter id.
4933 : : *
4934 : : * @return
4935 : : * Total number of actions.
4936 : : */
4937 : : static int
4938 : 0 : flow_check_meter_action(struct rte_eth_dev *dev,
4939 : : const struct rte_flow_action actions[],
4940 : : bool *has_mtr, bool *has_modify, uint32_t *meter_id)
4941 : : {
4942 : : const struct rte_flow_action_meter *mtr = NULL;
4943 : : int actions_n = 0;
4944 : :
4945 : : MLX5_ASSERT(has_mtr);
4946 : 0 : *has_mtr = false;
4947 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4948 [ # # ]: 0 : switch (actions->type) {
4949 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
4950 : 0 : mtr = actions->conf;
4951 : 0 : *meter_id = mtr->mtr_id;
4952 : 0 : *has_mtr = true;
4953 : 0 : break;
4954 : : default:
4955 : : break;
4956 : : }
4957 [ # # ]: 0 : if (!*has_mtr)
4958 : 0 : *has_modify |= flow_check_modify_action_type(dev,
4959 : 0 : actions->type);
4960 : 0 : actions_n++;
4961 : : }
4962 : : /* Count RTE_FLOW_ACTION_TYPE_END. */
4963 : 0 : return actions_n + 1;
4964 : : }
4965 : :
4966 : : /**
4967 : : * Check if the flow should be split due to hairpin.
4968 : : * The reason for the split is that in current HW we can't
4969 : : * support encap and push-vlan on Rx, so if a flow contains
4970 : : * these actions we move it to Tx.
4971 : : *
4972 : : * @param dev
4973 : : * Pointer to Ethernet device.
4974 : : * @param[in] attr
4975 : : * Flow rule attributes.
4976 : : * @param[in] actions
4977 : : * Associated actions (list terminated by the END action).
4978 : : *
4979 : : * @return
4980 : : * > 0 the number of actions and the flow should be split,
4981 : : * 0 when no split required.
4982 : : */
4983 : : static int
4984 : 0 : flow_check_hairpin_split(struct rte_eth_dev *dev,
4985 : : const struct rte_flow_attr *attr,
4986 : : const struct rte_flow_action actions[])
4987 : : {
4988 : : int queue_action = 0;
4989 : : int action_n = 0;
4990 : : int split = 0;
4991 : : int push_vlan = 0;
4992 : : const struct rte_flow_action_queue *queue;
4993 : : const struct rte_flow_action_rss *rss;
4994 : : const struct rte_flow_action_raw_encap *raw_encap;
4995 : : const struct rte_eth_hairpin_conf *conf;
4996 : :
4997 [ # # ]: 0 : if (!attr->ingress)
4998 : : return 0;
4999 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
5000 [ # # ]: 0 : if (actions->type == RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN)
5001 : : push_vlan = 1;
5002 [ # # # # : 0 : switch (actions->type) {
# # ]
5003 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
5004 : 0 : queue = actions->conf;
5005 [ # # ]: 0 : if (queue == NULL)
5006 : : return 0;
5007 : 0 : conf = mlx5_rxq_get_hairpin_conf(dev, queue->index);
5008 [ # # # # ]: 0 : if (conf == NULL || conf->tx_explicit != 0)
5009 : : return 0;
5010 : : queue_action = 1;
5011 : 0 : action_n++;
5012 : 0 : break;
5013 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
5014 : 0 : rss = actions->conf;
5015 [ # # # # ]: 0 : if (rss == NULL || rss->queue_num == 0)
5016 : : return 0;
5017 : 0 : conf = mlx5_rxq_get_hairpin_conf(dev, rss->queue[0]);
5018 [ # # # # ]: 0 : if (conf == NULL || conf->tx_explicit != 0)
5019 : : return 0;
5020 : : queue_action = 1;
5021 : 0 : action_n++;
5022 : 0 : break;
5023 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
5024 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
5025 : : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
5026 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
5027 : 0 : split++;
5028 : 0 : action_n++;
5029 : 0 : break;
5030 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
5031 [ # # ]: 0 : if (push_vlan)
5032 : 0 : split++;
5033 : 0 : action_n++;
5034 : 0 : break;
5035 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
5036 : 0 : raw_encap = actions->conf;
5037 [ # # ]: 0 : if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
5038 : 0 : split++;
5039 : 0 : action_n++;
5040 : 0 : break;
5041 : 0 : default:
5042 : 0 : action_n++;
5043 : 0 : break;
5044 : : }
5045 : : }
5046 [ # # ]: 0 : if (split && queue_action)
5047 : 0 : return action_n;
5048 : : return 0;
5049 : : }
5050 : :
5051 : : int
5052 : 0 : flow_dv_mreg_match_cb(void *tool_ctx __rte_unused,
5053 : : struct mlx5_list_entry *entry, void *cb_ctx)
5054 : : {
5055 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
5056 : : struct mlx5_flow_mreg_copy_resource *mcp_res =
5057 : : container_of(entry, typeof(*mcp_res), hlist_ent);
5058 : :
5059 : 0 : return mcp_res->mark_id != *(uint32_t *)(ctx->data);
5060 : : }
5061 : :
5062 : : struct mlx5_list_entry *
5063 : 0 : flow_dv_mreg_create_cb(void *tool_ctx, void *cb_ctx)
5064 : : {
5065 : : struct rte_eth_dev *dev = tool_ctx;
5066 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5067 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
5068 : : struct mlx5_flow_mreg_copy_resource *mcp_res;
5069 : 0 : struct rte_flow_error *error = ctx->error;
5070 : 0 : uint32_t idx = 0;
5071 : : int ret;
5072 : 0 : uint32_t mark_id = *(uint32_t *)(ctx->data);
5073 : 0 : struct rte_flow_attr attr = {
5074 : : .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
5075 : : .ingress = 1,
5076 : : };
5077 : 0 : struct mlx5_rte_flow_item_tag tag_spec = {
5078 : : .data = mark_id,
5079 : : };
5080 : 0 : struct rte_flow_item items[] = {
5081 : : [1] = { .type = RTE_FLOW_ITEM_TYPE_END, },
5082 : : };
5083 : 0 : struct rte_flow_action_mark ftag = {
5084 : : .id = mark_id,
5085 : : };
5086 : 0 : struct mlx5_flow_action_copy_mreg cp_mreg = {
5087 : : .dst = REG_B,
5088 : : .src = REG_NON,
5089 : : };
5090 : 0 : struct rte_flow_action_jump jump = {
5091 : : .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
5092 : : };
5093 : 0 : struct rte_flow_action actions[] = {
5094 : : [3] = { .type = RTE_FLOW_ACTION_TYPE_END, },
5095 : : };
5096 : :
5097 : : /* Fill the register fields in the flow. */
5098 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
5099 [ # # ]: 0 : if (ret < 0)
5100 : : return NULL;
5101 : 0 : tag_spec.id = ret;
5102 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
5103 [ # # ]: 0 : if (ret < 0)
5104 : : return NULL;
5105 : 0 : cp_mreg.src = ret;
5106 : : /* Provide the full width of FLAG specific value. */
5107 [ # # ]: 0 : if (mark_id == (priv->sh->dv_regc0_mask & MLX5_FLOW_MARK_DEFAULT))
5108 : 0 : tag_spec.data = MLX5_FLOW_MARK_DEFAULT;
5109 : : /* Build a new flow. */
5110 [ # # ]: 0 : if (mark_id != MLX5_DEFAULT_COPY_ID) {
5111 : 0 : items[0] = (struct rte_flow_item){
5112 : : .type = (enum rte_flow_item_type)
5113 : : MLX5_RTE_FLOW_ITEM_TYPE_TAG,
5114 : : .spec = &tag_spec,
5115 : : };
5116 : 0 : items[1] = (struct rte_flow_item){
5117 : : .type = RTE_FLOW_ITEM_TYPE_END,
5118 : : };
5119 : 0 : actions[0] = (struct rte_flow_action){
5120 : : .type = (enum rte_flow_action_type)
5121 : : MLX5_RTE_FLOW_ACTION_TYPE_MARK,
5122 : : .conf = &ftag,
5123 : : };
5124 : 0 : actions[1] = (struct rte_flow_action){
5125 : : .type = (enum rte_flow_action_type)
5126 : : MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5127 : : .conf = &cp_mreg,
5128 : : };
5129 : 0 : actions[2] = (struct rte_flow_action){
5130 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
5131 : : .conf = &jump,
5132 : : };
5133 : 0 : actions[3] = (struct rte_flow_action){
5134 : : .type = RTE_FLOW_ACTION_TYPE_END,
5135 : : };
5136 : : } else {
5137 : : /* Default rule, wildcard match. */
5138 : 0 : attr.priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR;
5139 : 0 : items[0] = (struct rte_flow_item){
5140 : : .type = RTE_FLOW_ITEM_TYPE_END,
5141 : : };
5142 : 0 : actions[0] = (struct rte_flow_action){
5143 : : .type = (enum rte_flow_action_type)
5144 : : MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5145 : : .conf = &cp_mreg,
5146 : : };
5147 : 0 : actions[1] = (struct rte_flow_action){
5148 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
5149 : : .conf = &jump,
5150 : : };
5151 : 0 : actions[2] = (struct rte_flow_action){
5152 : : .type = RTE_FLOW_ACTION_TYPE_END,
5153 : : };
5154 : : }
5155 : : /* Build a new entry. */
5156 : 0 : mcp_res = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
5157 [ # # ]: 0 : if (!mcp_res) {
5158 : 0 : rte_errno = ENOMEM;
5159 : 0 : return NULL;
5160 : : }
5161 : 0 : mcp_res->idx = idx;
5162 : 0 : mcp_res->mark_id = mark_id;
5163 : : /*
5164 : : * The copy Flows are not included in any list. There
5165 : : * ones are referenced from other Flows and can not
5166 : : * be applied, removed, deleted in arbitrary order
5167 : : * by list traversing.
5168 : : */
5169 : 0 : mcp_res->rix_flow = mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_MCP,
5170 : : &attr, items, actions, false, error);
5171 [ # # ]: 0 : if (!mcp_res->rix_flow) {
5172 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], idx);
5173 : 0 : return NULL;
5174 : : }
5175 : 0 : return &mcp_res->hlist_ent;
5176 : : }
5177 : :
5178 : : struct mlx5_list_entry *
5179 : 0 : flow_dv_mreg_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
5180 : : void *cb_ctx __rte_unused)
5181 : : {
5182 : : struct rte_eth_dev *dev = tool_ctx;
5183 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5184 : : struct mlx5_flow_mreg_copy_resource *mcp_res;
5185 : 0 : uint32_t idx = 0;
5186 : :
5187 : 0 : mcp_res = mlx5_ipool_malloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
5188 [ # # ]: 0 : if (!mcp_res) {
5189 : 0 : rte_errno = ENOMEM;
5190 : 0 : return NULL;
5191 : : }
5192 : : memcpy(mcp_res, oentry, sizeof(*mcp_res));
5193 : 0 : mcp_res->idx = idx;
5194 : 0 : return &mcp_res->hlist_ent;
5195 : : }
5196 : :
5197 : : void
5198 : 0 : flow_dv_mreg_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
5199 : : {
5200 : : struct mlx5_flow_mreg_copy_resource *mcp_res =
5201 : : container_of(entry, typeof(*mcp_res), hlist_ent);
5202 : : struct rte_eth_dev *dev = tool_ctx;
5203 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5204 : :
5205 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
5206 : 0 : }
5207 : :
5208 : : /**
5209 : : * Add a flow of copying flow metadata registers in RX_CP_TBL.
5210 : : *
5211 : : * As mark_id is unique, if there's already a registered flow for the mark_id,
5212 : : * return by increasing the reference counter of the resource. Otherwise, create
5213 : : * the resource (mcp_res) and flow.
5214 : : *
5215 : : * Flow looks like,
5216 : : * - If ingress port is ANY and reg_c[1] is mark_id,
5217 : : * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
5218 : : *
5219 : : * For default flow (zero mark_id), flow is like,
5220 : : * - If ingress port is ANY,
5221 : : * reg_b := reg_c[0] and jump to RX_ACT_TBL.
5222 : : *
5223 : : * @param dev
5224 : : * Pointer to Ethernet device.
5225 : : * @param mark_id
5226 : : * ID of MARK action, zero means default flow for META.
5227 : : * @param[out] error
5228 : : * Perform verbose error reporting if not NULL.
5229 : : *
5230 : : * @return
5231 : : * Associated resource on success, NULL otherwise and rte_errno is set.
5232 : : */
5233 : : static struct mlx5_flow_mreg_copy_resource *
5234 : 0 : flow_mreg_add_copy_action(struct rte_eth_dev *dev, uint32_t mark_id,
5235 : : struct rte_flow_error *error)
5236 : : {
5237 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5238 : : struct mlx5_list_entry *entry;
5239 : 0 : struct mlx5_flow_cb_ctx ctx = {
5240 : : .dev = dev,
5241 : : .error = error,
5242 : : .data = &mark_id,
5243 : : };
5244 : :
5245 : : /* Check if already registered. */
5246 : : MLX5_ASSERT(priv->sh->mreg_cp_tbl);
5247 : 0 : entry = mlx5_hlist_register(priv->sh->mreg_cp_tbl, mark_id, &ctx);
5248 [ # # ]: 0 : if (!entry)
5249 : 0 : return NULL;
5250 : : return container_of(entry, struct mlx5_flow_mreg_copy_resource,
5251 : : hlist_ent);
5252 : : }
5253 : :
5254 : : void
5255 : 0 : flow_dv_mreg_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
5256 : : {
5257 : : struct mlx5_flow_mreg_copy_resource *mcp_res =
5258 : : container_of(entry, typeof(*mcp_res), hlist_ent);
5259 : : struct rte_eth_dev *dev = tool_ctx;
5260 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5261 : :
5262 : : MLX5_ASSERT(mcp_res->rix_flow);
5263 : 0 : mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_MCP, mcp_res->rix_flow);
5264 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
5265 : 0 : }
5266 : :
5267 : : /**
5268 : : * Release flow in RX_CP_TBL.
5269 : : *
5270 : : * @param dev
5271 : : * Pointer to Ethernet device.
5272 : : * @flow
5273 : : * Parent flow for wich copying is provided.
5274 : : */
5275 : : static void
5276 : 0 : flow_mreg_del_copy_action(struct rte_eth_dev *dev,
5277 : : struct rte_flow *flow)
5278 : : {
5279 : : struct mlx5_flow_mreg_copy_resource *mcp_res;
5280 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5281 : :
5282 [ # # ]: 0 : if (!flow->rix_mreg_copy)
5283 : : return;
5284 : 0 : mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
5285 : : flow->rix_mreg_copy);
5286 [ # # # # ]: 0 : if (!mcp_res || !priv->sh->mreg_cp_tbl)
5287 : : return;
5288 : : MLX5_ASSERT(mcp_res->rix_flow);
5289 : 0 : mlx5_hlist_unregister(priv->sh->mreg_cp_tbl, &mcp_res->hlist_ent);
5290 : 0 : flow->rix_mreg_copy = 0;
5291 : : }
5292 : :
5293 : : /**
5294 : : * Remove the default copy action from RX_CP_TBL.
5295 : : *
5296 : : * This functions is called in the mlx5_dev_start(). No thread safe
5297 : : * is guaranteed.
5298 : : *
5299 : : * @param dev
5300 : : * Pointer to Ethernet device.
5301 : : */
5302 : : static void
5303 : 0 : flow_mreg_del_default_copy_action(struct rte_eth_dev *dev)
5304 : : {
5305 : : struct mlx5_list_entry *entry;
5306 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5307 : : struct mlx5_flow_cb_ctx ctx;
5308 : : uint32_t mark_id;
5309 : :
5310 : : /* Check if default flow is registered. */
5311 [ # # ]: 0 : if (!priv->sh->mreg_cp_tbl)
5312 : 0 : return;
5313 : 0 : mark_id = MLX5_DEFAULT_COPY_ID;
5314 : 0 : ctx.data = &mark_id;
5315 : 0 : entry = mlx5_hlist_lookup(priv->sh->mreg_cp_tbl, mark_id, &ctx);
5316 [ # # ]: 0 : if (!entry)
5317 : : return;
5318 : 0 : mlx5_hlist_unregister(priv->sh->mreg_cp_tbl, entry);
5319 : : }
5320 : :
5321 : : /**
5322 : : * Add the default copy action in RX_CP_TBL.
5323 : : *
5324 : : * This functions is called in the mlx5_dev_start(). No thread safe
5325 : : * is guaranteed.
5326 : : *
5327 : : * @param dev
5328 : : * Pointer to Ethernet device.
5329 : : * @param[out] error
5330 : : * Perform verbose error reporting if not NULL.
5331 : : *
5332 : : * @return
5333 : : * 0 for success, negative value otherwise and rte_errno is set.
5334 : : */
5335 : : static int
5336 : 0 : flow_mreg_add_default_copy_action(struct rte_eth_dev *dev,
5337 : : struct rte_flow_error *error)
5338 : : {
5339 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5340 : : struct mlx5_flow_mreg_copy_resource *mcp_res;
5341 : : struct mlx5_flow_cb_ctx ctx;
5342 : : uint32_t mark_id;
5343 : :
5344 : : /* Check whether extensive metadata feature is engaged. */
5345 [ # # ]: 0 : if (!priv->sh->config.dv_flow_en ||
5346 [ # # # # ]: 0 : priv->sh->config.dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
5347 : 0 : !mlx5_flow_ext_mreg_supported(dev) ||
5348 [ # # ]: 0 : !priv->sh->dv_regc0_mask)
5349 : 0 : return 0;
5350 : : /*
5351 : : * Add default mreg copy flow may be called multiple time, but
5352 : : * only be called once in stop. Avoid register it twice.
5353 : : */
5354 : 0 : mark_id = MLX5_DEFAULT_COPY_ID;
5355 : 0 : ctx.data = &mark_id;
5356 [ # # ]: 0 : if (mlx5_hlist_lookup(priv->sh->mreg_cp_tbl, mark_id, &ctx))
5357 : : return 0;
5358 : 0 : mcp_res = flow_mreg_add_copy_action(dev, mark_id, error);
5359 [ # # ]: 0 : if (!mcp_res)
5360 : 0 : return -rte_errno;
5361 : : return 0;
5362 : : }
5363 : :
5364 : : /**
5365 : : * Add a flow of copying flow metadata registers in RX_CP_TBL.
5366 : : *
5367 : : * All the flow having Q/RSS action should be split by
5368 : : * flow_mreg_split_qrss_prep() to pass by RX_CP_TBL. A flow in the RX_CP_TBL
5369 : : * performs the following,
5370 : : * - CQE->flow_tag := reg_c[1] (MARK)
5371 : : * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
5372 : : * As CQE's flow_tag is not a register, it can't be simply copied from reg_c[1]
5373 : : * but there should be a flow per each MARK ID set by MARK action.
5374 : : *
5375 : : * For the aforementioned reason, if there's a MARK action in flow's action
5376 : : * list, a corresponding flow should be added to the RX_CP_TBL in order to copy
5377 : : * the MARK ID to CQE's flow_tag like,
5378 : : * - If reg_c[1] is mark_id,
5379 : : * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
5380 : : *
5381 : : * For SET_META action which stores value in reg_c[0], as the destination is
5382 : : * also a flow metadata register (reg_b), adding a default flow is enough. Zero
5383 : : * MARK ID means the default flow. The default flow looks like,
5384 : : * - For all flow, reg_b := reg_c[0] and jump to RX_ACT_TBL.
5385 : : *
5386 : : * @param dev
5387 : : * Pointer to Ethernet device.
5388 : : * @param flow
5389 : : * Pointer to flow structure.
5390 : : * @param[in] actions
5391 : : * Pointer to the list of actions.
5392 : : * @param[out] error
5393 : : * Perform verbose error reporting if not NULL.
5394 : : *
5395 : : * @return
5396 : : * 0 on success, negative value otherwise and rte_errno is set.
5397 : : */
5398 : : static int
5399 : 0 : flow_mreg_update_copy_table(struct rte_eth_dev *dev,
5400 : : struct rte_flow *flow,
5401 : : const struct rte_flow_action *actions,
5402 : : struct rte_flow_error *error)
5403 : : {
5404 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5405 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
5406 : : struct mlx5_flow_mreg_copy_resource *mcp_res;
5407 : : const struct rte_flow_action_mark *mark;
5408 : :
5409 : : /* Check whether extensive metadata feature is engaged. */
5410 [ # # ]: 0 : if (!config->dv_flow_en ||
5411 [ # # # # ]: 0 : config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
5412 : 0 : !mlx5_flow_ext_mreg_supported(dev) ||
5413 [ # # ]: 0 : !priv->sh->dv_regc0_mask)
5414 : 0 : return 0;
5415 : : /* Find MARK action. */
5416 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
5417 [ # # # ]: 0 : switch (actions->type) {
5418 : 0 : case RTE_FLOW_ACTION_TYPE_FLAG:
5419 : 0 : mcp_res = flow_mreg_add_copy_action
5420 : : (dev, MLX5_FLOW_MARK_DEFAULT, error);
5421 [ # # ]: 0 : if (!mcp_res)
5422 : 0 : return -rte_errno;
5423 : 0 : flow->rix_mreg_copy = mcp_res->idx;
5424 : 0 : return 0;
5425 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
5426 : 0 : mark = (const struct rte_flow_action_mark *)
5427 : : actions->conf;
5428 : : mcp_res =
5429 : 0 : flow_mreg_add_copy_action(dev, mark->id, error);
5430 [ # # ]: 0 : if (!mcp_res)
5431 : 0 : return -rte_errno;
5432 : 0 : flow->rix_mreg_copy = mcp_res->idx;
5433 : 0 : return 0;
5434 : : default:
5435 : : break;
5436 : : }
5437 : : }
5438 : : return 0;
5439 : : }
5440 : :
5441 : : #define MLX5_MAX_SPLIT_ACTIONS 24
5442 : : #define MLX5_MAX_SPLIT_ITEMS 24
5443 : :
5444 : : /**
5445 : : * Split the hairpin flow.
5446 : : * Since HW can't support encap and push-vlan on Rx, we move these
5447 : : * actions to Tx.
5448 : : * If the count action is after the encap then we also
5449 : : * move the count action. in this case the count will also measure
5450 : : * the outer bytes.
5451 : : *
5452 : : * @param dev
5453 : : * Pointer to Ethernet device.
5454 : : * @param[in] actions
5455 : : * Associated actions (list terminated by the END action).
5456 : : * @param[out] actions_rx
5457 : : * Rx flow actions.
5458 : : * @param[out] actions_tx
5459 : : * Tx flow actions..
5460 : : * @param[out] pattern_tx
5461 : : * The pattern items for the Tx flow.
5462 : : * @param[out] flow_id
5463 : : * The flow ID connected to this flow.
5464 : : *
5465 : : * @return
5466 : : * 0 on success.
5467 : : */
5468 : : static int
5469 : 0 : flow_hairpin_split(struct rte_eth_dev *dev,
5470 : : const struct rte_flow_action actions[],
5471 : : struct rte_flow_action actions_rx[],
5472 : : struct rte_flow_action actions_tx[],
5473 : : struct rte_flow_item pattern_tx[],
5474 : : uint32_t flow_id)
5475 : : {
5476 : : const struct rte_flow_action_raw_encap *raw_encap;
5477 : : const struct rte_flow_action_raw_decap *raw_decap;
5478 : : struct mlx5_rte_flow_action_set_tag *set_tag;
5479 : : struct rte_flow_action *tag_action;
5480 : : struct mlx5_rte_flow_item_tag *tag_item;
5481 : : struct rte_flow_item *item;
5482 : : char *addr;
5483 : : int push_vlan = 0;
5484 : : int encap = 0;
5485 : :
5486 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
5487 [ # # ]: 0 : if (actions->type == RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN)
5488 : : push_vlan = 1;
5489 [ # # # # : 0 : switch (actions->type) {
# # ]
5490 : : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
5491 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
5492 : : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
5493 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
5494 : : rte_memcpy(actions_tx, actions,
5495 : : sizeof(struct rte_flow_action));
5496 : 0 : actions_tx++;
5497 : 0 : break;
5498 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
5499 [ # # ]: 0 : if (push_vlan) {
5500 : : rte_memcpy(actions_tx, actions,
5501 : : sizeof(struct rte_flow_action));
5502 : 0 : actions_tx++;
5503 : : } else {
5504 : : rte_memcpy(actions_rx, actions,
5505 : : sizeof(struct rte_flow_action));
5506 : 0 : actions_rx++;
5507 : : }
5508 : : break;
5509 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
5510 : : case RTE_FLOW_ACTION_TYPE_AGE:
5511 [ # # ]: 0 : if (encap) {
5512 : : rte_memcpy(actions_tx, actions,
5513 : : sizeof(struct rte_flow_action));
5514 : 0 : actions_tx++;
5515 : : } else {
5516 : : rte_memcpy(actions_rx, actions,
5517 : : sizeof(struct rte_flow_action));
5518 : 0 : actions_rx++;
5519 : : }
5520 : : break;
5521 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
5522 : 0 : raw_encap = actions->conf;
5523 [ # # ]: 0 : if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE) {
5524 : : memcpy(actions_tx, actions,
5525 : : sizeof(struct rte_flow_action));
5526 : 0 : actions_tx++;
5527 : : encap = 1;
5528 : : } else {
5529 : : rte_memcpy(actions_rx, actions,
5530 : : sizeof(struct rte_flow_action));
5531 : 0 : actions_rx++;
5532 : : }
5533 : : break;
5534 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
5535 : 0 : raw_decap = actions->conf;
5536 [ # # ]: 0 : if (raw_decap->size < MLX5_ENCAPSULATION_DECISION_SIZE) {
5537 : : memcpy(actions_tx, actions,
5538 : : sizeof(struct rte_flow_action));
5539 : 0 : actions_tx++;
5540 : : } else {
5541 : : rte_memcpy(actions_rx, actions,
5542 : : sizeof(struct rte_flow_action));
5543 : 0 : actions_rx++;
5544 : : }
5545 : : break;
5546 : : default:
5547 : : rte_memcpy(actions_rx, actions,
5548 : : sizeof(struct rte_flow_action));
5549 : 0 : actions_rx++;
5550 : 0 : break;
5551 : : }
5552 : : }
5553 : : /* Add set meta action and end action for the Rx flow. */
5554 : : tag_action = actions_rx;
5555 : 0 : tag_action->type = (enum rte_flow_action_type)
5556 : : MLX5_RTE_FLOW_ACTION_TYPE_TAG;
5557 [ # # ]: 0 : actions_rx++;
5558 : : rte_memcpy(actions_rx, actions, sizeof(struct rte_flow_action));
5559 : 0 : actions_rx++;
5560 : : set_tag = (void *)actions_rx;
5561 : 0 : *set_tag = (struct mlx5_rte_flow_action_set_tag) {
5562 : 0 : .id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_RX, 0, NULL),
5563 : : .data = flow_id,
5564 : : };
5565 : : MLX5_ASSERT(set_tag->id > REG_NON);
5566 [ # # ]: 0 : tag_action->conf = set_tag;
5567 : : /* Create Tx item list. */
5568 : : rte_memcpy(actions_tx, actions, sizeof(struct rte_flow_action));
5569 : 0 : addr = (void *)&pattern_tx[2];
5570 : : item = pattern_tx;
5571 : 0 : item->type = (enum rte_flow_item_type)
5572 : : MLX5_RTE_FLOW_ITEM_TYPE_TAG;
5573 : : tag_item = (void *)addr;
5574 : 0 : tag_item->data = flow_id;
5575 : 0 : tag_item->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_TX, 0, NULL);
5576 : : MLX5_ASSERT(set_tag->id > REG_NON);
5577 : 0 : item->spec = tag_item;
5578 : 0 : addr += sizeof(struct mlx5_rte_flow_item_tag);
5579 : : tag_item = (void *)addr;
5580 : 0 : tag_item->data = UINT32_MAX;
5581 : 0 : tag_item->id = UINT16_MAX;
5582 : 0 : item->mask = tag_item;
5583 : 0 : item->last = NULL;
5584 : : item++;
5585 : 0 : item->type = RTE_FLOW_ITEM_TYPE_END;
5586 : 0 : return 0;
5587 : : }
5588 : :
5589 : : /**
5590 : : * The last stage of splitting chain, just creates the subflow
5591 : : * without any modification.
5592 : : *
5593 : : * @param[in] dev
5594 : : * Pointer to Ethernet device.
5595 : : * @param[in] flow
5596 : : * Parent flow structure pointer.
5597 : : * @param[in, out] sub_flow
5598 : : * Pointer to return the created subflow, may be NULL.
5599 : : * @param[in] attr
5600 : : * Flow rule attributes.
5601 : : * @param[in] items
5602 : : * Pattern specification (list terminated by the END pattern item).
5603 : : * @param[in] actions
5604 : : * Associated actions (list terminated by the END action).
5605 : : * @param[in] flow_split_info
5606 : : * Pointer to flow split info structure.
5607 : : * @param[out] error
5608 : : * Perform verbose error reporting if not NULL.
5609 : : * @return
5610 : : * 0 on success, negative value otherwise
5611 : : */
5612 : : static int
5613 : 0 : flow_create_split_inner(struct rte_eth_dev *dev,
5614 : : struct rte_flow *flow,
5615 : : struct mlx5_flow **sub_flow,
5616 : : const struct rte_flow_attr *attr,
5617 : : const struct rte_flow_item items[],
5618 : : const struct rte_flow_action actions[],
5619 : : struct mlx5_flow_split_info *flow_split_info,
5620 : : struct rte_flow_error *error)
5621 : : {
5622 : : struct mlx5_flow *dev_flow;
5623 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
5624 : :
5625 : 0 : dev_flow = flow_drv_prepare(dev, flow, attr, items, actions,
5626 : : flow_split_info->flow_idx, error);
5627 [ # # ]: 0 : if (!dev_flow)
5628 : 0 : return -rte_errno;
5629 : 0 : dev_flow->flow = flow;
5630 : 0 : dev_flow->external = flow_split_info->external;
5631 : 0 : dev_flow->skip_scale = flow_split_info->skip_scale;
5632 : : /* Subflow object was created, we must include one in the list. */
5633 : 0 : SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
5634 : : dev_flow->handle, next);
5635 : : /*
5636 : : * If dev_flow is as one of the suffix flow, some actions in suffix
5637 : : * flow may need some user defined item layer flags, and pass the
5638 : : * Metadata rxq mark flag to suffix flow as well.
5639 : : */
5640 [ # # ]: 0 : if (flow_split_info->prefix_layers)
5641 : 0 : dev_flow->handle->layers = flow_split_info->prefix_layers;
5642 [ # # ]: 0 : if (flow_split_info->prefix_mark) {
5643 : : MLX5_ASSERT(wks);
5644 : 0 : wks->mark = 1;
5645 : : }
5646 [ # # ]: 0 : if (sub_flow)
5647 : 0 : *sub_flow = dev_flow;
5648 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
5649 : 0 : dev_flow->dv.table_id = flow_split_info->table_id;
5650 : : #endif
5651 : 0 : return flow_drv_translate(dev, dev_flow, attr, items, actions, error);
5652 : : }
5653 : :
5654 : : /**
5655 : : * Get the sub policy of a meter.
5656 : : *
5657 : : * @param[in] dev
5658 : : * Pointer to Ethernet device.
5659 : : * @param[in] flow
5660 : : * Parent flow structure pointer.
5661 : : * @param wks
5662 : : * Pointer to thread flow work space.
5663 : : * @param[in] attr
5664 : : * Flow rule attributes.
5665 : : * @param[in] items
5666 : : * Pattern specification (list terminated by the END pattern item).
5667 : : * @param[out] error
5668 : : * Perform verbose error reporting if not NULL.
5669 : : *
5670 : : * @return
5671 : : * Pointer to the meter sub policy, NULL otherwise and rte_errno is set.
5672 : : */
5673 : : static struct mlx5_flow_meter_sub_policy *
5674 : 0 : get_meter_sub_policy(struct rte_eth_dev *dev,
5675 : : struct rte_flow *flow,
5676 : : struct mlx5_flow_workspace *wks,
5677 : : const struct rte_flow_attr *attr,
5678 : : const struct rte_flow_item items[],
5679 : : struct rte_flow_error *error)
5680 : : {
5681 : : struct mlx5_flow_meter_policy *policy;
5682 : : struct mlx5_flow_meter_policy *final_policy;
5683 : : struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
5684 : :
5685 : 0 : policy = wks->policy;
5686 [ # # ]: 0 : final_policy = policy->is_hierarchy ? wks->final_policy : policy;
5687 [ # # ]: 0 : if (final_policy->is_rss || final_policy->is_queue) {
5688 : : struct mlx5_flow_rss_desc rss_desc_v[MLX5_MTR_RTE_COLORS];
5689 : 0 : struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS] = {0};
5690 : : uint32_t i;
5691 : :
5692 : : /*
5693 : : * This is a tmp dev_flow,
5694 : : * no need to register any matcher for it in translate.
5695 : : */
5696 : 0 : wks->skip_matcher_reg = 1;
5697 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
5698 : 0 : struct mlx5_flow dev_flow = {0};
5699 : 0 : struct mlx5_flow_handle dev_handle = { {0} };
5700 : 0 : uint8_t fate = final_policy->act_cnt[i].fate_action;
5701 : :
5702 [ # # ]: 0 : if (fate == MLX5_FLOW_FATE_SHARED_RSS) {
5703 : 0 : const struct rte_flow_action_rss *rss_act =
5704 : 0 : final_policy->act_cnt[i].rss->conf;
5705 : 0 : struct rte_flow_action rss_actions[2] = {
5706 : : [0] = {
5707 : : .type = RTE_FLOW_ACTION_TYPE_RSS,
5708 : : .conf = rss_act,
5709 : : },
5710 : : [1] = {
5711 : : .type = RTE_FLOW_ACTION_TYPE_END,
5712 : : .conf = NULL,
5713 : : }
5714 : : };
5715 : :
5716 : 0 : dev_flow.handle = &dev_handle;
5717 : 0 : dev_flow.ingress = attr->ingress;
5718 : 0 : dev_flow.flow = flow;
5719 : : dev_flow.external = 0;
5720 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
5721 : 0 : dev_flow.dv.transfer = attr->transfer;
5722 : : #endif
5723 : : /**
5724 : : * Translate RSS action to get rss hash fields.
5725 : : */
5726 [ # # ]: 0 : if (flow_drv_translate(dev, &dev_flow, attr,
5727 : : items, rss_actions, error))
5728 : 0 : goto exit;
5729 : 0 : rss_desc_v[i] = wks->rss_desc;
5730 : 0 : rss_desc_v[i].symmetric_hash_function =
5731 : 0 : dev_flow.symmetric_hash_function;
5732 : 0 : rss_desc_v[i].key_len = MLX5_RSS_HASH_KEY_LEN;
5733 : 0 : rss_desc_v[i].hash_fields =
5734 : 0 : dev_flow.hash_fields;
5735 : 0 : rss_desc_v[i].queue_num =
5736 : : rss_desc_v[i].hash_fields ?
5737 [ # # ]: 0 : rss_desc_v[i].queue_num : 1;
5738 : 0 : rss_desc_v[i].tunnel =
5739 : 0 : !!(dev_flow.handle->layers &
5740 : : MLX5_FLOW_LAYER_TUNNEL);
5741 : : /* Use the RSS queues in the containers. */
5742 : 0 : rss_desc_v[i].queue =
5743 : 0 : (uint16_t *)(uintptr_t)rss_act->queue;
5744 : 0 : rss_desc[i] = &rss_desc_v[i];
5745 [ # # ]: 0 : } else if (fate == MLX5_FLOW_FATE_QUEUE) {
5746 : : /* This is queue action. */
5747 : 0 : rss_desc_v[i] = wks->rss_desc;
5748 : 0 : rss_desc_v[i].key_len = 0;
5749 : 0 : rss_desc_v[i].hash_fields = 0;
5750 : 0 : rss_desc_v[i].queue =
5751 : 0 : &final_policy->act_cnt[i].queue;
5752 : 0 : rss_desc_v[i].queue_num = 1;
5753 : 0 : rss_desc[i] = &rss_desc_v[i];
5754 : : } else {
5755 : 0 : rss_desc[i] = NULL;
5756 : : }
5757 : : }
5758 : : sub_policy = flow_drv_meter_sub_policy_rss_prepare(dev,
5759 : : flow, policy, rss_desc);
5760 : : } else {
5761 : : enum mlx5_meter_domain mtr_domain =
5762 [ # # ]: 0 : attr->transfer ? MLX5_MTR_DOMAIN_TRANSFER :
5763 : 0 : (attr->egress ? MLX5_MTR_DOMAIN_EGRESS :
5764 : : MLX5_MTR_DOMAIN_INGRESS);
5765 : 0 : sub_policy = policy->sub_policys[mtr_domain][0];
5766 : : }
5767 [ # # ]: 0 : if (!sub_policy)
5768 : 0 : rte_flow_error_set(error, EINVAL,
5769 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5770 : : "Failed to get meter sub-policy.");
5771 : 0 : exit:
5772 : 0 : return sub_policy;
5773 : : }
5774 : :
5775 : : /**
5776 : : * Split the meter flow.
5777 : : *
5778 : : * As meter flow will split to three sub flow, other than meter
5779 : : * action, the other actions make sense to only meter accepts
5780 : : * the packet. If it need to be dropped, no other additional
5781 : : * actions should be take.
5782 : : *
5783 : : * One kind of special action which decapsulates the L3 tunnel
5784 : : * header will be in the prefix sub flow, as not to take the
5785 : : * L3 tunnel header into account.
5786 : : *
5787 : : * @param[in] dev
5788 : : * Pointer to Ethernet device.
5789 : : * @param[in] flow
5790 : : * Parent flow structure pointer.
5791 : : * @param wks
5792 : : * Pointer to thread flow work space.
5793 : : * @param[in] attr
5794 : : * Flow rule attributes.
5795 : : * @param[in] items
5796 : : * Pattern specification (list terminated by the END pattern item).
5797 : : * @param[out] sfx_items
5798 : : * Suffix flow match items (list terminated by the END pattern item).
5799 : : * @param[in] actions
5800 : : * Associated actions (list terminated by the END action).
5801 : : * @param[out] actions_sfx
5802 : : * Suffix flow actions.
5803 : : * @param[out] actions_pre
5804 : : * Prefix flow actions.
5805 : : * @param[out] mtr_flow_id
5806 : : * Pointer to meter flow id.
5807 : : * @param[out] error
5808 : : * Perform verbose error reporting if not NULL.
5809 : : *
5810 : : * @return
5811 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5812 : : */
5813 : : static int
5814 : 0 : flow_meter_split_prep(struct rte_eth_dev *dev,
5815 : : struct rte_flow *flow,
5816 : : struct mlx5_flow_workspace *wks,
5817 : : const struct rte_flow_attr *attr,
5818 : : const struct rte_flow_item items[],
5819 : : struct rte_flow_item sfx_items[],
5820 : : const struct rte_flow_action actions[],
5821 : : struct rte_flow_action actions_sfx[],
5822 : : struct rte_flow_action actions_pre[],
5823 : : uint32_t *mtr_flow_id,
5824 : : struct rte_flow_error *error)
5825 : : {
5826 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5827 : 0 : struct mlx5_flow_meter_info *fm = wks->fm;
5828 : : struct rte_flow_action *tag_action = NULL;
5829 : : struct rte_flow_item *tag_item;
5830 : : struct mlx5_rte_flow_action_set_tag *set_tag;
5831 : : const struct rte_flow_action_raw_encap *raw_encap;
5832 : : const struct rte_flow_action_raw_decap *raw_decap;
5833 : : struct mlx5_rte_flow_item_tag *tag_item_spec;
5834 : : struct mlx5_rte_flow_item_tag *tag_item_mask;
5835 : 0 : uint32_t tag_id = 0;
5836 : : bool vlan_actions;
5837 : : struct rte_flow_item *orig_sfx_items = sfx_items;
5838 : : const struct rte_flow_item *orig_items = items;
5839 : : struct rte_flow_action *hw_mtr_action;
5840 : : struct rte_flow_action *action_pre_head = NULL;
5841 : 0 : uint16_t flow_src_port = priv->representor_id;
5842 : : bool mtr_first;
5843 : 0 : uint8_t mtr_id_offset = priv->mtr_reg_share ? MLX5_MTR_COLOR_BITS : 0;
5844 [ # # ]: 0 : uint8_t mtr_reg_bits = priv->mtr_reg_share ?
5845 : : MLX5_MTR_IDLE_BITS_IN_COLOR_REG : MLX5_REG_BITS;
5846 : : uint32_t flow_id = 0;
5847 : : uint32_t flow_id_reversed = 0;
5848 : : uint8_t flow_id_bits = 0;
5849 : : bool after_meter = false;
5850 : : int shift;
5851 : :
5852 : : /* Prepare the suffix subflow items. */
5853 : 0 : tag_item = sfx_items++;
5854 : 0 : tag_item->type = (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_TAG;
5855 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
5856 : : int item_type = items->type;
5857 : :
5858 [ # # # ]: 0 : switch (item_type) {
5859 : 0 : case RTE_FLOW_ITEM_TYPE_PORT_ID:
5860 : : case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
5861 : : case RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR:
5862 [ # # ]: 0 : if (mlx5_flow_get_item_vport_id(dev, items, &flow_src_port, NULL, error))
5863 : 0 : return -rte_errno;
5864 [ # # # # ]: 0 : if (!fm->def_policy && wks->policy->hierarchy_match_port &&
5865 [ # # ]: 0 : flow_src_port != priv->representor_id) {
5866 [ # # ]: 0 : if (flow_drv_mtr_hierarchy_rule_create(dev,
5867 : : flow, fm,
5868 : : flow_src_port,
5869 : : items,
5870 : : error))
5871 : 0 : return -rte_errno;
5872 : : }
5873 : : memcpy(sfx_items, items, sizeof(*sfx_items));
5874 : 0 : sfx_items++;
5875 : 0 : break;
5876 : : case RTE_FLOW_ITEM_TYPE_VLAN:
5877 : : /*
5878 : : * Copy VLAN items in case VLAN actions are performed.
5879 : : * If there are no VLAN actions, these items will be VOID.
5880 : : */
5881 : : memcpy(sfx_items, items, sizeof(*sfx_items));
5882 : 0 : sfx_items->type = (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_VLAN;
5883 : 0 : sfx_items++;
5884 : 0 : break;
5885 : : default:
5886 : : break;
5887 : : }
5888 : : }
5889 : 0 : sfx_items->type = RTE_FLOW_ITEM_TYPE_END;
5890 : 0 : sfx_items++;
5891 [ # # ]: 0 : mtr_first = priv->sh->meter_aso_en &&
5892 [ # # # # : 0 : (attr->egress || (attr->transfer && flow_src_port != UINT16_MAX));
# # ]
5893 : : /* For ASO meter, meter must be before tag in TX direction. */
5894 [ # # ]: 0 : if (mtr_first) {
5895 : 0 : action_pre_head = actions_pre++;
5896 : : /* Leave space for tag action. */
5897 : 0 : tag_action = actions_pre++;
5898 : : }
5899 : : /* Prepare the actions for prefix and suffix flow. */
5900 : : vlan_actions = false;
5901 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
5902 : : struct rte_flow_action *action_cur = NULL;
5903 : :
5904 [ # # # # : 0 : switch (actions->type) {
# # # ]
5905 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
5906 [ # # ]: 0 : if (mtr_first) {
5907 : : action_cur = action_pre_head;
5908 : : } else {
5909 : : /* Leave space for tag action. */
5910 : 0 : tag_action = actions_pre++;
5911 : 0 : action_cur = actions_pre++;
5912 : : }
5913 : : after_meter = true;
5914 : : break;
5915 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
5916 : : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
5917 : 0 : action_cur = actions_pre++;
5918 : 0 : break;
5919 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
5920 : 0 : raw_encap = actions->conf;
5921 [ # # ]: 0 : if (raw_encap->size < MLX5_ENCAPSULATION_DECISION_SIZE)
5922 : 0 : action_cur = actions_pre++;
5923 : : break;
5924 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
5925 : 0 : raw_decap = actions->conf;
5926 [ # # ]: 0 : if (raw_decap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
5927 : 0 : action_cur = actions_pre++;
5928 : : break;
5929 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
5930 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
5931 : : vlan_actions = true;
5932 : 0 : break;
5933 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
5934 [ # # ]: 0 : if (fm->def_policy)
5935 : : action_cur = after_meter ?
5936 [ # # ]: 0 : actions_sfx++ : actions_pre++;
5937 : : break;
5938 : : default:
5939 : : break;
5940 : : }
5941 [ # # ]: 0 : if (!action_cur)
5942 : 0 : action_cur = (fm->def_policy) ?
5943 [ # # ]: 0 : actions_sfx++ : actions_pre++;
5944 : : memcpy(action_cur, actions, sizeof(struct rte_flow_action));
5945 : : }
5946 : : /* If there are no VLAN actions, convert VLAN items to VOID in suffix flow items. */
5947 [ # # ]: 0 : if (!vlan_actions) {
5948 : : struct rte_flow_item *it = orig_sfx_items;
5949 : :
5950 [ # # ]: 0 : for (; it->type != RTE_FLOW_ITEM_TYPE_END; it++)
5951 [ # # ]: 0 : if (it->type == (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_VLAN)
5952 : 0 : it->type = RTE_FLOW_ITEM_TYPE_VOID;
5953 : : }
5954 : : /* Add end action to the actions. */
5955 : 0 : actions_sfx->type = RTE_FLOW_ACTION_TYPE_END;
5956 [ # # ]: 0 : if (priv->sh->meter_aso_en) {
5957 : : /**
5958 : : * For ASO meter, need to add an extra jump action explicitly,
5959 : : * to jump from meter to policer table.
5960 : : */
5961 : : struct mlx5_flow_meter_sub_policy *sub_policy;
5962 : : struct mlx5_flow_tbl_data_entry *tbl_data;
5963 : :
5964 [ # # ]: 0 : if (!fm->def_policy) {
5965 : 0 : sub_policy = get_meter_sub_policy(dev, flow, wks,
5966 : : attr, orig_items,
5967 : : error);
5968 [ # # ]: 0 : if (!sub_policy)
5969 : 0 : return -rte_errno;
5970 : : } else {
5971 : : enum mlx5_meter_domain mtr_domain =
5972 [ # # ]: 0 : attr->transfer ? MLX5_MTR_DOMAIN_TRANSFER :
5973 : 0 : (attr->egress ? MLX5_MTR_DOMAIN_EGRESS :
5974 : : MLX5_MTR_DOMAIN_INGRESS);
5975 : :
5976 : 0 : sub_policy =
5977 : 0 : &priv->sh->mtrmng->def_policy[mtr_domain]->sub_policy;
5978 : : }
5979 : 0 : tbl_data = container_of(sub_policy->tbl_rsc,
5980 : : struct mlx5_flow_tbl_data_entry, tbl);
5981 : 0 : hw_mtr_action = actions_pre++;
5982 : 0 : hw_mtr_action->type = (enum rte_flow_action_type)
5983 : : MLX5_RTE_FLOW_ACTION_TYPE_JUMP;
5984 : 0 : hw_mtr_action->conf = tbl_data->jump.action;
5985 : : }
5986 : 0 : actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
5987 : 0 : actions_pre++;
5988 [ # # ]: 0 : if (!tag_action)
5989 : 0 : return rte_flow_error_set(error, ENOMEM,
5990 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5991 : : NULL, "No tag action space.");
5992 [ # # ]: 0 : if (!mtr_flow_id) {
5993 : 0 : tag_action->type = RTE_FLOW_ACTION_TYPE_VOID;
5994 : 0 : goto exit;
5995 : : }
5996 : : /* Only default-policy Meter creates mtr flow id. */
5997 [ # # ]: 0 : if (fm->def_policy) {
5998 : 0 : mlx5_ipool_malloc(fm->flow_ipool, &tag_id);
5999 [ # # ]: 0 : if (!tag_id)
6000 : 0 : return rte_flow_error_set(error, ENOMEM,
6001 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6002 : : "Failed to allocate meter flow id.");
6003 : 0 : flow_id = tag_id - 1;
6004 [ # # ]: 0 : flow_id_bits = (!flow_id) ? 1 :
6005 : 0 : (MLX5_REG_BITS - rte_clz32(flow_id));
6006 [ # # ]: 0 : if ((flow_id_bits + priv->sh->mtrmng->max_mtr_bits) >
6007 : : mtr_reg_bits) {
6008 : 0 : mlx5_ipool_free(fm->flow_ipool, tag_id);
6009 : 0 : return rte_flow_error_set(error, EINVAL,
6010 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6011 : : "Meter flow id exceeds max limit.");
6012 : : }
6013 [ # # ]: 0 : if (flow_id_bits > priv->sh->mtrmng->max_mtr_flow_bits)
6014 : 0 : priv->sh->mtrmng->max_mtr_flow_bits = flow_id_bits;
6015 : : }
6016 : : /* Build tag actions and items for meter_id/meter flow_id. */
6017 : : set_tag = (struct mlx5_rte_flow_action_set_tag *)actions_pre;
6018 : : tag_item_spec = (struct mlx5_rte_flow_item_tag *)sfx_items;
6019 : 0 : tag_item_mask = tag_item_spec + 1;
6020 : : /* Both flow_id and meter_id share the same register. */
6021 : 0 : *set_tag = (struct mlx5_rte_flow_action_set_tag) {
6022 : 0 : .id = (enum modify_reg)mlx5_flow_get_reg_id(dev, MLX5_MTR_ID,
6023 : : 0, error),
6024 : : .offset = mtr_id_offset,
6025 : : .length = mtr_reg_bits,
6026 : 0 : .data = flow->meter,
6027 : : };
6028 : : /*
6029 : : * The color Reg bits used by flow_id are growing from
6030 : : * msb to lsb, so must do bit reverse for flow_id val in RegC.
6031 : : */
6032 [ # # ]: 0 : for (shift = 0; shift < flow_id_bits; shift++)
6033 : 0 : flow_id_reversed = (flow_id_reversed << 1) |
6034 : 0 : ((flow_id >> shift) & 0x1);
6035 : 0 : set_tag->data |=
6036 : 0 : flow_id_reversed << (mtr_reg_bits - flow_id_bits);
6037 : 0 : tag_item_spec->id = set_tag->id;
6038 : 0 : tag_item_spec->data = set_tag->data << mtr_id_offset;
6039 : 0 : tag_item_mask->data = UINT32_MAX << mtr_id_offset;
6040 : 0 : tag_action->type = (enum rte_flow_action_type)
6041 : : MLX5_RTE_FLOW_ACTION_TYPE_TAG;
6042 : 0 : tag_action->conf = set_tag;
6043 : 0 : tag_item->spec = tag_item_spec;
6044 : 0 : tag_item->last = NULL;
6045 : 0 : tag_item->mask = tag_item_mask;
6046 : 0 : exit:
6047 [ # # ]: 0 : if (mtr_flow_id)
6048 : 0 : *mtr_flow_id = tag_id;
6049 : : return 0;
6050 : : }
6051 : :
6052 : : /**
6053 : : * Split action list having QUEUE/RSS for metadata register copy.
6054 : : *
6055 : : * Once Q/RSS action is detected in user's action list, the flow action
6056 : : * should be split in order to copy metadata registers, which will happen in
6057 : : * RX_CP_TBL like,
6058 : : * - CQE->flow_tag := reg_c[1] (MARK)
6059 : : * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
6060 : : * The Q/RSS action will be performed on RX_ACT_TBL after passing by RX_CP_TBL.
6061 : : * This is because the last action of each flow must be a terminal action
6062 : : * (QUEUE, RSS or DROP).
6063 : : *
6064 : : * Flow ID must be allocated to identify actions in the RX_ACT_TBL and it is
6065 : : * stored and kept in the mlx5_flow structure per each sub_flow.
6066 : : *
6067 : : * The Q/RSS action is replaced with,
6068 : : * - SET_TAG, setting the allocated flow ID to reg_c[2].
6069 : : * And the following JUMP action is added at the end,
6070 : : * - JUMP, to RX_CP_TBL.
6071 : : *
6072 : : * A flow to perform remained Q/RSS action will be created in RX_ACT_TBL by
6073 : : * flow_create_split_metadata() routine. The flow will look like,
6074 : : * - If flow ID matches (reg_c[2]), perform Q/RSS.
6075 : : *
6076 : : * @param dev
6077 : : * Pointer to Ethernet device.
6078 : : * @param[out] split_actions
6079 : : * Pointer to store split actions to jump to CP_TBL.
6080 : : * @param[in] actions
6081 : : * Pointer to the list of original flow actions.
6082 : : * @param[in] qrss
6083 : : * Pointer to the Q/RSS action.
6084 : : * @param[in] actions_n
6085 : : * Number of original actions.
6086 : : * @param[in] mtr_sfx
6087 : : * Check if it is in meter suffix table.
6088 : : * @param[out] error
6089 : : * Perform verbose error reporting if not NULL.
6090 : : *
6091 : : * @return
6092 : : * non-zero unique flow_id on success, otherwise 0 and
6093 : : * error/rte_error are set.
6094 : : */
6095 : : static uint32_t
6096 : 0 : flow_mreg_split_qrss_prep(struct rte_eth_dev *dev,
6097 : : struct rte_flow_action *split_actions,
6098 : : const struct rte_flow_action *actions,
6099 : : const struct rte_flow_action *qrss,
6100 : : int actions_n, int mtr_sfx,
6101 : : struct rte_flow_error *error)
6102 : : {
6103 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6104 : : struct mlx5_rte_flow_action_set_tag *set_tag;
6105 : : struct rte_flow_action_jump *jump;
6106 : 0 : const int qrss_idx = qrss - actions;
6107 : 0 : uint32_t flow_id = 0;
6108 : : int ret = 0;
6109 : :
6110 : : /*
6111 : : * Given actions will be split
6112 : : * - Replace QUEUE/RSS action with SET_TAG to set flow ID.
6113 : : * - Add jump to mreg CP_TBL.
6114 : : * As a result, there will be one more action.
6115 : : */
6116 [ # # ]: 0 : memcpy(split_actions, actions, sizeof(*split_actions) * actions_n);
6117 : : /* Count MLX5_RTE_FLOW_ACTION_TYPE_TAG. */
6118 : 0 : ++actions_n;
6119 : 0 : set_tag = (void *)(split_actions + actions_n);
6120 : : /*
6121 : : * If we are not the meter suffix flow, add the tag action.
6122 : : * Since meter suffix flow already has the tag added.
6123 : : */
6124 [ # # ]: 0 : if (!mtr_sfx) {
6125 : : /*
6126 : : * Allocate the new subflow ID. This one is unique within
6127 : : * device and not shared with representors. Otherwise,
6128 : : * we would have to resolve multi-thread access synch
6129 : : * issue. Each flow on the shared device is appended
6130 : : * with source vport identifier, so the resulting
6131 : : * flows will be unique in the shared (by master and
6132 : : * representors) domain even if they have coinciding
6133 : : * IDs.
6134 : : */
6135 : 0 : mlx5_ipool_malloc(priv->sh->ipool
6136 : : [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &flow_id);
6137 [ # # ]: 0 : if (!flow_id)
6138 : 0 : return rte_flow_error_set(error, ENOMEM,
6139 : : RTE_FLOW_ERROR_TYPE_ACTION,
6140 : : NULL, "can't allocate id "
6141 : : "for split Q/RSS subflow");
6142 : : /* Internal SET_TAG action to set flow ID. */
6143 : 0 : *set_tag = (struct mlx5_rte_flow_action_set_tag){
6144 : : .data = flow_id,
6145 : : };
6146 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0, error);
6147 [ # # ]: 0 : if (ret < 0)
6148 : 0 : return ret;
6149 : 0 : set_tag->id = ret;
6150 : : /* Construct new actions array. */
6151 : : /* Replace QUEUE/RSS action. */
6152 : 0 : split_actions[qrss_idx] = (struct rte_flow_action){
6153 : : .type = (enum rte_flow_action_type)
6154 : : MLX5_RTE_FLOW_ACTION_TYPE_TAG,
6155 : : .conf = set_tag,
6156 : : };
6157 : : } else {
6158 : : /*
6159 : : * If we are the suffix flow of meter, tag already exist.
6160 : : * Set the QUEUE/RSS action to void.
6161 : : */
6162 : 0 : split_actions[qrss_idx].type = RTE_FLOW_ACTION_TYPE_VOID;
6163 : : }
6164 : : /* JUMP action to jump to mreg copy table (CP_TBL). */
6165 : 0 : jump = (void *)(set_tag + 1);
6166 : 0 : *jump = (struct rte_flow_action_jump){
6167 : : .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
6168 : : };
6169 : 0 : split_actions[actions_n - 2] = (struct rte_flow_action){
6170 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
6171 : : .conf = jump,
6172 : : };
6173 : 0 : split_actions[actions_n - 1] = (struct rte_flow_action){
6174 : : .type = RTE_FLOW_ACTION_TYPE_END,
6175 : : };
6176 : 0 : return flow_id;
6177 : : }
6178 : :
6179 : : /**
6180 : : * Extend the given action list for Tx metadata copy.
6181 : : *
6182 : : * Copy the given action list to the ext_actions and add flow metadata register
6183 : : * copy action in order to copy reg_a set by WQE to reg_c[0].
6184 : : *
6185 : : * @param[out] ext_actions
6186 : : * Pointer to the extended action list.
6187 : : * @param[in] actions
6188 : : * Pointer to the list of actions.
6189 : : * @param[in] actions_n
6190 : : * Number of actions in the list.
6191 : : * @param[out] error
6192 : : * Perform verbose error reporting if not NULL.
6193 : : * @param[in] encap_idx
6194 : : * The encap action index.
6195 : : *
6196 : : * @return
6197 : : * 0 on success, negative value otherwise
6198 : : */
6199 : : static int
6200 : 0 : flow_mreg_tx_copy_prep(struct rte_eth_dev *dev,
6201 : : struct rte_flow_action *ext_actions,
6202 : : const struct rte_flow_action *actions,
6203 : : int actions_n, struct rte_flow_error *error,
6204 : : int encap_idx)
6205 : : {
6206 : 0 : struct mlx5_flow_action_copy_mreg *cp_mreg =
6207 : : (struct mlx5_flow_action_copy_mreg *)
6208 : 0 : (ext_actions + actions_n + 1);
6209 : : int ret;
6210 : :
6211 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
6212 [ # # ]: 0 : if (ret < 0)
6213 : : return ret;
6214 : 0 : cp_mreg->dst = ret;
6215 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_TX, 0, error);
6216 [ # # ]: 0 : if (ret < 0)
6217 : : return ret;
6218 : 0 : cp_mreg->src = ret;
6219 [ # # ]: 0 : if (encap_idx != 0)
6220 : 0 : memcpy(ext_actions, actions, sizeof(*ext_actions) * encap_idx);
6221 [ # # ]: 0 : if (encap_idx == actions_n - 1) {
6222 : 0 : ext_actions[actions_n - 1] = (struct rte_flow_action){
6223 : : .type = (enum rte_flow_action_type)
6224 : : MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
6225 : : .conf = cp_mreg,
6226 : : };
6227 : 0 : ext_actions[actions_n] = (struct rte_flow_action){
6228 : : .type = RTE_FLOW_ACTION_TYPE_END,
6229 : : };
6230 : : } else {
6231 : 0 : ext_actions[encap_idx] = (struct rte_flow_action){
6232 : : .type = (enum rte_flow_action_type)
6233 : : MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
6234 : : .conf = cp_mreg,
6235 : : };
6236 : 0 : memcpy(ext_actions + encap_idx + 1, actions + encap_idx,
6237 : 0 : sizeof(*ext_actions) * (actions_n - encap_idx));
6238 : : }
6239 : : return 0;
6240 : : }
6241 : :
6242 : : /**
6243 : : * Check the match action from the action list.
6244 : : *
6245 : : * @param[in] actions
6246 : : * Pointer to the list of actions.
6247 : : * @param[in] attr
6248 : : * Flow rule attributes.
6249 : : * @param[in] action
6250 : : * The action to be check if exist.
6251 : : * @param[out] match_action_pos
6252 : : * Pointer to the position of the matched action if exists, otherwise is -1.
6253 : : * @param[out] qrss_action_pos
6254 : : * Pointer to the position of the Queue/RSS action if exists, otherwise is -1.
6255 : : * @param[out] modify_after_mirror
6256 : : * Pointer to the flag of modify action after FDB mirroring.
6257 : : *
6258 : : * @return
6259 : : * > 0 the total number of actions.
6260 : : * 0 if not found match action in action list.
6261 : : */
6262 : : static int
6263 : 0 : flow_check_match_action(const struct rte_flow_action actions[],
6264 : : const struct rte_flow_attr *attr,
6265 : : enum rte_flow_action_type action,
6266 : : int *match_action_pos, int *qrss_action_pos,
6267 : : int *modify_after_mirror)
6268 : : {
6269 : : const struct rte_flow_action_sample *sample;
6270 : : const struct rte_flow_action_raw_decap *decap;
6271 : : const struct rte_flow_action *action_cur = NULL;
6272 : : int actions_n = 0;
6273 : : uint32_t ratio = 0;
6274 : : int sub_type = 0;
6275 : : int flag = 0;
6276 : : int fdb_mirror = 0;
6277 : :
6278 : 0 : *match_action_pos = -1;
6279 : 0 : *qrss_action_pos = -1;
6280 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
6281 [ # # ]: 0 : if (actions->type == action) {
6282 : : flag = 1;
6283 : 0 : *match_action_pos = actions_n;
6284 : : }
6285 [ # # # # : 0 : switch (actions->type) {
# ]
6286 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
6287 : : case RTE_FLOW_ACTION_TYPE_RSS:
6288 : 0 : *qrss_action_pos = actions_n;
6289 : 0 : break;
6290 : 0 : case RTE_FLOW_ACTION_TYPE_SAMPLE:
6291 : 0 : sample = actions->conf;
6292 : 0 : ratio = sample->ratio;
6293 : 0 : sub_type = ((const struct rte_flow_action *)
6294 : 0 : (sample->actions))->type;
6295 [ # # # # : 0 : if (ratio == 1 && attr->transfer &&
# # ]
6296 : : sub_type != RTE_FLOW_ACTION_TYPE_END)
6297 : : fdb_mirror = 1;
6298 : : break;
6299 : 0 : case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
6300 : : case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
6301 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
6302 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
6303 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
6304 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
6305 : : case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
6306 : : case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
6307 : : case RTE_FLOW_ACTION_TYPE_DEC_TTL:
6308 : : case RTE_FLOW_ACTION_TYPE_SET_TTL:
6309 : : case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
6310 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
6311 : : case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
6312 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
6313 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
6314 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
6315 : : case RTE_FLOW_ACTION_TYPE_FLAG:
6316 : : case RTE_FLOW_ACTION_TYPE_MARK:
6317 : : case RTE_FLOW_ACTION_TYPE_SET_META:
6318 : : case RTE_FLOW_ACTION_TYPE_SET_TAG:
6319 : : case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
6320 : : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
6321 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
6322 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
6323 : : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
6324 : : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
6325 : : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
6326 : : case RTE_FLOW_ACTION_TYPE_METER:
6327 [ # # ]: 0 : if (fdb_mirror)
6328 : 0 : *modify_after_mirror = 1;
6329 : : break;
6330 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
6331 : 0 : decap = actions->conf;
6332 : : action_cur = actions;
6333 [ # # ]: 0 : while ((++action_cur)->type == RTE_FLOW_ACTION_TYPE_VOID)
6334 : : ;
6335 [ # # ]: 0 : if (action_cur->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
6336 : 0 : const struct rte_flow_action_raw_encap *encap =
6337 : : action_cur->conf;
6338 [ # # ]: 0 : if (decap->size <=
6339 : 0 : MLX5_ENCAPSULATION_DECISION_SIZE &&
6340 [ # # ]: 0 : encap->size >
6341 : : MLX5_ENCAPSULATION_DECISION_SIZE)
6342 : : /* L3 encap. */
6343 : : break;
6344 : : }
6345 [ # # ]: 0 : if (fdb_mirror)
6346 : 0 : *modify_after_mirror = 1;
6347 : : break;
6348 : : default:
6349 : : break;
6350 : : }
6351 : 0 : actions_n++;
6352 : : }
6353 [ # # # # ]: 0 : if (flag && fdb_mirror && !*modify_after_mirror) {
6354 : : /* FDB mirroring uses the destination array to implement
6355 : : * instead of FLOW_SAMPLER object.
6356 : : */
6357 [ # # ]: 0 : if (sub_type != RTE_FLOW_ACTION_TYPE_END)
6358 : : flag = 0;
6359 : : }
6360 : : /* Count RTE_FLOW_ACTION_TYPE_END. */
6361 [ # # ]: 0 : return flag ? actions_n + 1 : 0;
6362 : : }
6363 : :
6364 : : #define SAMPLE_SUFFIX_ITEM 3
6365 : :
6366 : : /**
6367 : : * Split the sample flow.
6368 : : *
6369 : : * As sample flow will split to two sub flow, sample flow with
6370 : : * sample action, the other actions will move to new suffix flow.
6371 : : *
6372 : : * Also add unique tag id with tag action in the sample flow,
6373 : : * the same tag id will be as match in the suffix flow.
6374 : : *
6375 : : * @param dev
6376 : : * Pointer to Ethernet device.
6377 : : * @param[in] add_tag
6378 : : * Add extra tag action flag.
6379 : : * @param[out] sfx_items
6380 : : * Suffix flow match items (list terminated by the END pattern item).
6381 : : * @param[in] actions
6382 : : * Associated actions (list terminated by the END action).
6383 : : * @param[out] actions_sfx
6384 : : * Suffix flow actions.
6385 : : * @param[out] actions_pre
6386 : : * Prefix flow actions.
6387 : : * @param[in] actions_n
6388 : : * The total number of actions.
6389 : : * @param[in] sample_action_pos
6390 : : * The sample action position.
6391 : : * @param[in] qrss_action_pos
6392 : : * The Queue/RSS action position.
6393 : : * @param[in] jump_table
6394 : : * Add extra jump action flag.
6395 : : * @param[out] error
6396 : : * Perform verbose error reporting if not NULL.
6397 : : *
6398 : : * @return
6399 : : * 0 on success, or unique flow_id, a negative errno value
6400 : : * otherwise and rte_errno is set.
6401 : : */
6402 : : static int
6403 : 0 : flow_sample_split_prep(struct rte_eth_dev *dev,
6404 : : int add_tag,
6405 : : const struct rte_flow_item items[],
6406 : : struct rte_flow_item sfx_items[],
6407 : : const struct rte_flow_action actions[],
6408 : : struct rte_flow_action actions_sfx[],
6409 : : struct rte_flow_action actions_pre[],
6410 : : int actions_n,
6411 : : int sample_action_pos,
6412 : : int qrss_action_pos,
6413 : : int jump_table,
6414 : : struct rte_flow_error *error)
6415 : : {
6416 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6417 : : struct mlx5_rte_flow_action_set_tag *set_tag;
6418 : : struct mlx5_rte_flow_item_tag *tag_spec;
6419 : : struct mlx5_rte_flow_item_tag *tag_mask;
6420 : : struct rte_flow_action_jump *jump_action;
6421 : 0 : uint32_t tag_id = 0;
6422 : : int append_index = 0;
6423 : : int set_tag_idx = -1;
6424 : : int index;
6425 : : int ret;
6426 : :
6427 [ # # ]: 0 : if (sample_action_pos < 0)
6428 : 0 : return rte_flow_error_set(error, EINVAL,
6429 : : RTE_FLOW_ERROR_TYPE_ACTION,
6430 : : NULL, "invalid position of sample "
6431 : : "action in list");
6432 : : /* Prepare the actions for prefix and suffix flow. */
6433 [ # # ]: 0 : if (add_tag) {
6434 : : /* Update the new added tag action index preceding
6435 : : * the PUSH_VLAN or ENCAP action.
6436 : : */
6437 : : const struct rte_flow_action_raw_encap *raw_encap;
6438 : : const struct rte_flow_action *action = actions;
6439 : : int encap_idx;
6440 : : int action_idx = 0;
6441 : : int raw_decap_idx = -1;
6442 : : int push_vlan_idx = -1;
6443 [ # # ]: 0 : for (; action->type != RTE_FLOW_ACTION_TYPE_END; action++) {
6444 [ # # # # : 0 : switch (action->type) {
# ]
6445 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
6446 : : raw_decap_idx = action_idx;
6447 : 0 : break;
6448 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
6449 : 0 : raw_encap = action->conf;
6450 [ # # ]: 0 : if (raw_encap->size >
6451 : : MLX5_ENCAPSULATION_DECISION_SIZE) {
6452 : : encap_idx = raw_decap_idx != -1 ?
6453 [ # # ]: 0 : raw_decap_idx : action_idx;
6454 : 0 : if (encap_idx < sample_action_pos &&
6455 [ # # ]: 0 : push_vlan_idx == -1)
6456 : : set_tag_idx = encap_idx;
6457 : : }
6458 : : break;
6459 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
6460 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
6461 : : encap_idx = action_idx;
6462 : 0 : if (encap_idx < sample_action_pos &&
6463 [ # # ]: 0 : push_vlan_idx == -1)
6464 : : set_tag_idx = encap_idx;
6465 : : break;
6466 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
6467 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
6468 : 0 : if (action_idx < sample_action_pos &&
6469 [ # # ]: 0 : push_vlan_idx == -1) {
6470 : : set_tag_idx = action_idx;
6471 : : push_vlan_idx = action_idx;
6472 : : }
6473 : : break;
6474 : : default:
6475 : : break;
6476 : : }
6477 : 0 : action_idx++;
6478 : : }
6479 : : }
6480 : : /* Prepare the actions for prefix and suffix flow. */
6481 [ # # ]: 0 : if (qrss_action_pos >= 0 && qrss_action_pos < sample_action_pos) {
6482 : : index = qrss_action_pos;
6483 : : /* Put the preceding the Queue/RSS action into prefix flow. */
6484 [ # # ]: 0 : if (index != 0)
6485 : 0 : memcpy(actions_pre, actions,
6486 : : sizeof(struct rte_flow_action) * index);
6487 : : /* Put others preceding the sample action into prefix flow. */
6488 [ # # ]: 0 : if (sample_action_pos > index + 1)
6489 : 0 : memcpy(actions_pre + index, actions + index + 1,
6490 : : sizeof(struct rte_flow_action) *
6491 : 0 : (sample_action_pos - index - 1));
6492 : 0 : index = sample_action_pos - 1;
6493 : : /* Put Queue/RSS action into Suffix flow. */
6494 : 0 : memcpy(actions_sfx, actions + qrss_action_pos,
6495 : : sizeof(struct rte_flow_action));
6496 : 0 : actions_sfx++;
6497 [ # # ]: 0 : } else if (add_tag && set_tag_idx >= 0) {
6498 [ # # ]: 0 : if (set_tag_idx > 0)
6499 : 0 : memcpy(actions_pre, actions,
6500 : : sizeof(struct rte_flow_action) * set_tag_idx);
6501 : 0 : memcpy(actions_pre + set_tag_idx + 1, actions + set_tag_idx,
6502 : : sizeof(struct rte_flow_action) *
6503 : 0 : (sample_action_pos - set_tag_idx));
6504 : : index = sample_action_pos;
6505 : : } else {
6506 : : index = sample_action_pos;
6507 [ # # ]: 0 : if (index != 0)
6508 : 0 : memcpy(actions_pre, actions,
6509 : : sizeof(struct rte_flow_action) * index);
6510 : : }
6511 : : /* For CX5, add an extra tag action for NIC-RX and E-Switch ingress.
6512 : : * For CX6DX and above, metadata registers Cx preserve their value,
6513 : : * add an extra tag action for NIC-RX and E-Switch Domain.
6514 : : */
6515 [ # # ]: 0 : if (add_tag) {
6516 : : /* Prepare the prefix tag action. */
6517 : : append_index++;
6518 : 0 : set_tag = (void *)(actions_pre + actions_n + append_index);
6519 : : /* Trust VF/SF on CX5 not supported meter so that the reserved
6520 : : * metadata regC is REG_NON, back to use application tag
6521 : : * index 0.
6522 : : */
6523 [ # # ]: 0 : if (unlikely(priv->sh->registers.aso_reg == REG_NON))
6524 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, 0, error);
6525 : : else
6526 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_SAMPLE_ID, 0, error);
6527 [ # # ]: 0 : if (ret < 0)
6528 : : return ret;
6529 : 0 : mlx5_ipool_malloc(priv->sh->ipool
6530 : : [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &tag_id);
6531 : 0 : *set_tag = (struct mlx5_rte_flow_action_set_tag) {
6532 : : .id = ret,
6533 : : .data = tag_id,
6534 : : };
6535 : : /* Prepare the suffix subflow items. */
6536 : 0 : tag_spec = (void *)(sfx_items + SAMPLE_SUFFIX_ITEM);
6537 : 0 : tag_spec->data = tag_id;
6538 : 0 : tag_spec->id = set_tag->id;
6539 : 0 : tag_mask = tag_spec + 1;
6540 : 0 : tag_mask->data = UINT32_MAX;
6541 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
6542 [ # # ]: 0 : if (items->type == RTE_FLOW_ITEM_TYPE_PORT_ID ||
6543 : : items->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR ||
6544 : : items->type == RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT) {
6545 : : memcpy(sfx_items, items, sizeof(*sfx_items));
6546 : 0 : sfx_items++;
6547 : 0 : break;
6548 : : }
6549 : : }
6550 : 0 : sfx_items[0] = (struct rte_flow_item){
6551 : : .type = (enum rte_flow_item_type)
6552 : : MLX5_RTE_FLOW_ITEM_TYPE_TAG,
6553 : : .spec = tag_spec,
6554 : : .last = NULL,
6555 : : .mask = tag_mask,
6556 : : };
6557 : 0 : sfx_items[1] = (struct rte_flow_item){
6558 : : .type = (enum rte_flow_item_type)
6559 : : RTE_FLOW_ITEM_TYPE_END,
6560 : : };
6561 : : /* Prepare the tag action in prefix subflow. */
6562 [ # # ]: 0 : set_tag_idx = (set_tag_idx == -1) ? index : set_tag_idx;
6563 : 0 : actions_pre[set_tag_idx] =
6564 : : (struct rte_flow_action){
6565 : : .type = (enum rte_flow_action_type)
6566 : : MLX5_RTE_FLOW_ACTION_TYPE_TAG,
6567 : : .conf = set_tag,
6568 : : };
6569 : : /* Update next sample position due to add one tag action */
6570 : 0 : index += 1;
6571 : : }
6572 : : /* Copy the sample action into prefix flow. */
6573 [ # # ]: 0 : memcpy(actions_pre + index, actions + sample_action_pos,
6574 : : sizeof(struct rte_flow_action));
6575 : 0 : index += 1;
6576 : : /* For the modify action after the sample action in E-Switch mirroring,
6577 : : * Add the extra jump action in prefix subflow and jump into the next
6578 : : * table, then do the modify action in the new table.
6579 : : */
6580 [ # # ]: 0 : if (jump_table) {
6581 : : /* Prepare the prefix jump action. */
6582 : 0 : append_index++;
6583 : 0 : jump_action = (void *)(actions_pre + actions_n + append_index);
6584 : 0 : jump_action->group = jump_table;
6585 : 0 : actions_pre[index++] =
6586 : : (struct rte_flow_action){
6587 : : .type = (enum rte_flow_action_type)
6588 : : RTE_FLOW_ACTION_TYPE_JUMP,
6589 : : .conf = jump_action,
6590 : : };
6591 : : }
6592 : 0 : actions_pre[index] = (struct rte_flow_action){
6593 : : .type = (enum rte_flow_action_type)
6594 : : RTE_FLOW_ACTION_TYPE_END,
6595 : : };
6596 : : /* Put the actions after sample into Suffix flow. */
6597 : 0 : memcpy(actions_sfx, actions + sample_action_pos + 1,
6598 : : sizeof(struct rte_flow_action) *
6599 : 0 : (actions_n - sample_action_pos - 1));
6600 : 0 : return tag_id;
6601 : : }
6602 : :
6603 : : /**
6604 : : * The splitting for metadata feature.
6605 : : *
6606 : : * - Q/RSS action on NIC Rx should be split in order to pass by
6607 : : * the mreg copy table (RX_CP_TBL) and then it jumps to the
6608 : : * action table (RX_ACT_TBL) which has the split Q/RSS action.
6609 : : *
6610 : : * - All the actions on NIC Tx should have a mreg copy action to
6611 : : * copy reg_a from WQE to reg_c[0].
6612 : : *
6613 : : * @param dev
6614 : : * Pointer to Ethernet device.
6615 : : * @param[in] flow
6616 : : * Parent flow structure pointer.
6617 : : * @param[in] attr
6618 : : * Flow rule attributes.
6619 : : * @param[in] items
6620 : : * Pattern specification (list terminated by the END pattern item).
6621 : : * @param[in] actions
6622 : : * Associated actions (list terminated by the END action).
6623 : : * @param[in] flow_split_info
6624 : : * Pointer to flow split info structure.
6625 : : * @param[out] error
6626 : : * Perform verbose error reporting if not NULL.
6627 : : * @return
6628 : : * 0 on success, negative value otherwise
6629 : : */
6630 : : static int
6631 : 0 : flow_create_split_metadata(struct rte_eth_dev *dev,
6632 : : struct rte_flow *flow,
6633 : : const struct rte_flow_attr *attr,
6634 : : const struct rte_flow_item items[],
6635 : : const struct rte_flow_action actions[],
6636 : : struct mlx5_flow_split_info *flow_split_info,
6637 : : struct rte_flow_error *error)
6638 : : {
6639 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6640 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
6641 : 0 : const struct rte_flow_action *qrss = NULL;
6642 : : struct rte_flow_action *ext_actions = NULL;
6643 : 0 : struct mlx5_flow *dev_flow = NULL;
6644 : : uint32_t qrss_id = 0;
6645 : : int mtr_sfx = 0;
6646 : : size_t act_size;
6647 : : int actions_n;
6648 : : int encap_idx;
6649 : : int ret;
6650 : :
6651 : : /* Check whether extensive metadata feature is engaged. */
6652 [ # # ]: 0 : if (!config->dv_flow_en ||
6653 [ # # # # ]: 0 : config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
6654 : 0 : !mlx5_flow_ext_mreg_supported(dev))
6655 : 0 : return flow_create_split_inner(dev, flow, NULL, attr, items,
6656 : : actions, flow_split_info, error);
6657 : 0 : actions_n = flow_parse_metadata_split_actions_info(actions, &qrss,
6658 : : &encap_idx);
6659 [ # # ]: 0 : if (qrss) {
6660 : : /* Exclude hairpin flows from splitting. */
6661 [ # # ]: 0 : if (qrss->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
6662 : : const struct rte_flow_action_queue *queue;
6663 : :
6664 : 0 : queue = qrss->conf;
6665 [ # # ]: 0 : if (mlx5_rxq_is_hairpin(dev, queue->index))
6666 : 0 : qrss = NULL;
6667 [ # # ]: 0 : } else if (qrss->type == RTE_FLOW_ACTION_TYPE_RSS) {
6668 : : const struct rte_flow_action_rss *rss;
6669 : :
6670 : 0 : rss = qrss->conf;
6671 [ # # ]: 0 : if (mlx5_rxq_is_hairpin(dev, rss->queue[0]))
6672 : 0 : qrss = NULL;
6673 : : }
6674 : : }
6675 [ # # ]: 0 : if (qrss) {
6676 : : /* Check if it is in meter suffix table. */
6677 : 0 : mtr_sfx = attr->group ==
6678 [ # # ]: 0 : ((attr->transfer && priv->fdb_def_rule) ?
6679 [ # # ]: 0 : (MLX5_FLOW_TABLE_LEVEL_METER - 1) :
6680 : : MLX5_FLOW_TABLE_LEVEL_METER);
6681 : : /*
6682 : : * Q/RSS action on NIC Rx should be split in order to pass by
6683 : : * the mreg copy table (RX_CP_TBL) and then it jumps to the
6684 : : * action table (RX_ACT_TBL) which has the split Q/RSS action.
6685 : : */
6686 : 0 : act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
6687 : 0 : sizeof(struct rte_flow_action_set_tag) +
6688 : : sizeof(struct rte_flow_action_jump);
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 : : /*
6697 : : * Create the new actions list with removed Q/RSS action
6698 : : * and appended set tag and jump to register copy table
6699 : : * (RX_CP_TBL). We should preallocate unique tag ID here
6700 : : * in advance, because it is needed for set tag action.
6701 : : */
6702 : 0 : qrss_id = flow_mreg_split_qrss_prep(dev, ext_actions, actions,
6703 : : qrss, actions_n,
6704 : : mtr_sfx, error);
6705 [ # # ]: 0 : if (!mtr_sfx && !qrss_id) {
6706 : 0 : ret = -rte_errno;
6707 : 0 : goto exit;
6708 : : }
6709 [ # # ]: 0 : } else if (attr->egress) {
6710 : : /*
6711 : : * All the actions on NIC Tx should have a metadata register
6712 : : * copy action to copy reg_a from WQE to reg_c[meta]
6713 : : */
6714 : 0 : act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
6715 : : sizeof(struct mlx5_flow_action_copy_mreg);
6716 : 0 : ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
6717 : : SOCKET_ID_ANY);
6718 [ # # ]: 0 : if (!ext_actions)
6719 : 0 : return rte_flow_error_set(error, ENOMEM,
6720 : : RTE_FLOW_ERROR_TYPE_ACTION,
6721 : : NULL, "no memory to split "
6722 : : "metadata flow");
6723 : : /* Create the action list appended with copy register. */
6724 : 0 : ret = flow_mreg_tx_copy_prep(dev, ext_actions, actions,
6725 : : actions_n, error, encap_idx);
6726 [ # # ]: 0 : if (ret < 0)
6727 : 0 : goto exit;
6728 : : }
6729 : : /* Add the unmodified original or prefix subflow. */
6730 [ # # ]: 0 : ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
6731 : : items, ext_actions ? ext_actions :
6732 : : actions, flow_split_info, error);
6733 [ # # ]: 0 : if (ret < 0)
6734 : 0 : goto exit;
6735 : : MLX5_ASSERT(dev_flow);
6736 [ # # ]: 0 : if (qrss) {
6737 : 0 : const struct rte_flow_attr q_attr = {
6738 : : .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
6739 : : .ingress = 1,
6740 : : };
6741 : : /* Internal PMD action to set register. */
6742 : 0 : struct mlx5_rte_flow_item_tag q_tag_spec = {
6743 : : .data = qrss_id,
6744 : : .id = REG_NON,
6745 : : };
6746 : 0 : struct rte_flow_item q_items[] = {
6747 : : {
6748 : : .type = (enum rte_flow_item_type)
6749 : : MLX5_RTE_FLOW_ITEM_TYPE_TAG,
6750 : : .spec = &q_tag_spec,
6751 : : .last = NULL,
6752 : : .mask = NULL,
6753 : : },
6754 : : {
6755 : : .type = RTE_FLOW_ITEM_TYPE_END,
6756 : : },
6757 : : };
6758 : 0 : struct rte_flow_action q_actions[] = {
6759 : : {
6760 : 0 : .type = qrss->type,
6761 : 0 : .conf = qrss->conf,
6762 : : },
6763 : : {
6764 : : .type = RTE_FLOW_ACTION_TYPE_END,
6765 : : },
6766 : : };
6767 : 0 : uint64_t layers = flow_get_prefix_layer_flags(dev_flow);
6768 : :
6769 : : /*
6770 : : * Configure the tag item only if there is no meter subflow.
6771 : : * Since tag is already marked in the meter suffix subflow
6772 : : * we can just use the meter suffix items as is.
6773 : : */
6774 [ # # ]: 0 : if (qrss_id) {
6775 : : /* Not meter subflow. */
6776 : : MLX5_ASSERT(!mtr_sfx);
6777 : : /*
6778 : : * Put unique id in prefix flow due to it is destroyed
6779 : : * after suffix flow and id will be freed after there
6780 : : * is no actual flows with this id and identifier
6781 : : * reallocation becomes possible (for example, for
6782 : : * other flows in other threads).
6783 : : */
6784 : 0 : dev_flow->handle->split_flow_id = qrss_id;
6785 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0,
6786 : : error);
6787 [ # # ]: 0 : if (ret < 0)
6788 : 0 : goto exit;
6789 : 0 : q_tag_spec.id = ret;
6790 : : }
6791 : 0 : dev_flow = NULL;
6792 : : /* Add suffix subflow to execute Q/RSS. */
6793 : 0 : flow_split_info->prefix_layers = layers;
6794 : 0 : flow_split_info->prefix_mark = 0;
6795 : 0 : flow_split_info->table_id = 0;
6796 [ # # ]: 0 : ret = flow_create_split_inner(dev, flow, &dev_flow,
6797 : : &q_attr, mtr_sfx ? items :
6798 : : q_items, q_actions,
6799 : : flow_split_info, error);
6800 [ # # ]: 0 : if (ret < 0)
6801 : 0 : goto exit;
6802 : : /* qrss ID should be freed if failed. */
6803 : : qrss_id = 0;
6804 : : MLX5_ASSERT(dev_flow);
6805 : : }
6806 : :
6807 : 0 : exit:
6808 : : /*
6809 : : * We do not destroy the partially created sub_flows in case of error.
6810 : : * These ones are included into parent flow list and will be destroyed
6811 : : * by flow_drv_destroy.
6812 : : */
6813 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
6814 : : qrss_id);
6815 : 0 : mlx5_free(ext_actions);
6816 : 0 : return ret;
6817 : : }
6818 : :
6819 : : /**
6820 : : * Create meter internal drop flow with the original pattern.
6821 : : *
6822 : : * @param dev
6823 : : * Pointer to Ethernet device.
6824 : : * @param[in] flow
6825 : : * Parent flow structure pointer.
6826 : : * @param[in] attr
6827 : : * Flow rule attributes.
6828 : : * @param[in] items
6829 : : * Pattern specification (list terminated by the END pattern item).
6830 : : * @param[in] flow_split_info
6831 : : * Pointer to flow split info structure.
6832 : : * @param[in] fm
6833 : : * Pointer to flow meter structure.
6834 : : * @param[out] error
6835 : : * Perform verbose error reporting if not NULL.
6836 : : * @return
6837 : : * 0 on success, negative value otherwise
6838 : : */
6839 : : static uint32_t
6840 : 0 : flow_meter_create_drop_flow_with_org_pattern(struct rte_eth_dev *dev,
6841 : : struct rte_flow *flow,
6842 : : const struct rte_flow_attr *attr,
6843 : : const struct rte_flow_item items[],
6844 : : struct mlx5_flow_split_info *flow_split_info,
6845 : : struct mlx5_flow_meter_info *fm,
6846 : : struct rte_flow_error *error)
6847 : : {
6848 : 0 : struct mlx5_flow *dev_flow = NULL;
6849 : 0 : struct rte_flow_attr drop_attr = *attr;
6850 : : struct rte_flow_action drop_actions[3];
6851 : 0 : struct mlx5_flow_split_info drop_split_info = *flow_split_info;
6852 : :
6853 : : MLX5_ASSERT(fm->drop_cnt);
6854 : 0 : drop_actions[0].type =
6855 : : (enum rte_flow_action_type)MLX5_RTE_FLOW_ACTION_TYPE_COUNT;
6856 : 0 : drop_actions[0].conf = (void *)(uintptr_t)fm->drop_cnt;
6857 : 0 : drop_actions[1].type = RTE_FLOW_ACTION_TYPE_DROP;
6858 : 0 : drop_actions[1].conf = NULL;
6859 : 0 : drop_actions[2].type = RTE_FLOW_ACTION_TYPE_END;
6860 : 0 : drop_actions[2].conf = NULL;
6861 : 0 : drop_split_info.external = false;
6862 : 0 : drop_split_info.skip_scale |= 1 << MLX5_SCALE_FLOW_GROUP_BIT;
6863 : 0 : drop_split_info.table_id = MLX5_MTR_TABLE_ID_DROP;
6864 : 0 : drop_attr.group = MLX5_FLOW_TABLE_LEVEL_METER;
6865 : 0 : return flow_create_split_inner(dev, flow, &dev_flow,
6866 : : &drop_attr, items, drop_actions,
6867 : : &drop_split_info, error);
6868 : : }
6869 : :
6870 : : static int
6871 : : flow_count_vlan_items(const struct rte_flow_item items[])
6872 : : {
6873 : : int items_n = 0;
6874 : :
6875 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
6876 [ # # ]: 0 : if (items->type == RTE_FLOW_ITEM_TYPE_VLAN ||
6877 : : items->type == (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_VLAN)
6878 : 0 : items_n++;
6879 : : }
6880 : : return items_n;
6881 : : }
6882 : :
6883 : : /**
6884 : : * The splitting for meter feature.
6885 : : *
6886 : : * - The meter flow will be split to two flows as prefix and
6887 : : * suffix flow. The packets make sense only it pass the prefix
6888 : : * meter action.
6889 : : *
6890 : : * - Reg_C_5 is used for the packet to match betweend prefix and
6891 : : * suffix flow.
6892 : : *
6893 : : * @param dev
6894 : : * Pointer to Ethernet device.
6895 : : * @param[in] flow
6896 : : * Parent flow structure pointer.
6897 : : * @param[in] attr
6898 : : * Flow rule attributes.
6899 : : * @param[in] items
6900 : : * Pattern specification (list terminated by the END pattern item).
6901 : : * @param[in] actions
6902 : : * Associated actions (list terminated by the END action).
6903 : : * @param[in] flow_split_info
6904 : : * Pointer to flow split info structure.
6905 : : * @param[out] error
6906 : : * Perform verbose error reporting if not NULL.
6907 : : * @return
6908 : : * 0 on success, negative value otherwise
6909 : : */
6910 : : static int
6911 : 0 : flow_create_split_meter(struct rte_eth_dev *dev,
6912 : : struct rte_flow *flow,
6913 : : const struct rte_flow_attr *attr,
6914 : : const struct rte_flow_item items[],
6915 : : const struct rte_flow_action actions[],
6916 : : struct mlx5_flow_split_info *flow_split_info,
6917 : : struct rte_flow_error *error)
6918 : : {
6919 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6920 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
6921 : : struct rte_flow_action *sfx_actions = NULL;
6922 : : struct rte_flow_action *pre_actions = NULL;
6923 : : struct rte_flow_item *sfx_items = NULL;
6924 : 0 : struct mlx5_flow *dev_flow = NULL;
6925 : 0 : struct rte_flow_attr sfx_attr = *attr;
6926 : : struct mlx5_flow_meter_info *fm = NULL;
6927 : : uint8_t skip_scale_restore;
6928 : 0 : bool has_mtr = false;
6929 : 0 : bool has_modify = false;
6930 : : bool set_mtr_reg = true;
6931 : : bool is_mtr_hierarchy = false;
6932 : 0 : uint32_t meter_id = 0;
6933 : 0 : uint32_t mtr_idx = 0;
6934 : 0 : uint32_t mtr_flow_id = 0;
6935 : : size_t act_size;
6936 : : size_t item_size;
6937 : : int actions_n = 0;
6938 : : int vlan_items_n = 0;
6939 : : int ret = 0;
6940 : :
6941 [ # # ]: 0 : if (priv->mtr_en)
6942 : 0 : actions_n = flow_check_meter_action(dev, actions, &has_mtr,
6943 : : &has_modify, &meter_id);
6944 [ # # ]: 0 : if (has_mtr) {
6945 [ # # ]: 0 : if (flow->meter) {
6946 : 0 : fm = flow_dv_meter_find_by_idx(priv, flow->meter);
6947 [ # # ]: 0 : if (!fm)
6948 : 0 : return rte_flow_error_set(error, EINVAL,
6949 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6950 : : NULL, "Meter not found.");
6951 : : } else {
6952 : 0 : fm = mlx5_flow_meter_find(priv, meter_id, &mtr_idx);
6953 [ # # ]: 0 : if (!fm)
6954 : 0 : return rte_flow_error_set(error, EINVAL,
6955 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6956 : : NULL, "Meter not found.");
6957 : 0 : ret = mlx5_flow_meter_attach(priv, fm,
6958 : : &sfx_attr, error);
6959 [ # # ]: 0 : if (ret)
6960 : 0 : return -rte_errno;
6961 : 0 : flow->meter = mtr_idx;
6962 : : }
6963 : : MLX5_ASSERT(wks);
6964 : 0 : wks->fm = fm;
6965 [ # # ]: 0 : if (!fm->def_policy) {
6966 : 0 : wks->policy = mlx5_flow_meter_policy_find(dev,
6967 : : fm->policy_id,
6968 : : NULL);
6969 : : MLX5_ASSERT(wks->policy);
6970 [ # # ]: 0 : if (wks->policy->mark)
6971 : 0 : wks->mark = 1;
6972 [ # # ]: 0 : if (wks->policy->is_hierarchy) {
6973 : 0 : wks->final_policy =
6974 : 0 : mlx5_flow_meter_hierarchy_get_final_policy(dev,
6975 : : wks->policy);
6976 [ # # ]: 0 : if (!wks->final_policy)
6977 : 0 : return rte_flow_error_set(error,
6978 : : EINVAL,
6979 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6980 : : "Failed to find terminal policy of hierarchy.");
6981 : : is_mtr_hierarchy = true;
6982 : : }
6983 : : }
6984 : : /*
6985 : : * If it isn't default-policy Meter, and
6986 : : * 1. Not meter hierarchy and there's no action in flow to change
6987 : : * packet (modify/encap/decap etc.), OR
6988 : : * 2. No drop count needed for this meter.
6989 : : * Then no need to use regC to save meter id anymore.
6990 : : */
6991 [ # # # # : 0 : if (!fm->def_policy && ((!has_modify && !is_mtr_hierarchy) || !fm->drop_cnt))
# # # # ]
6992 : : set_mtr_reg = false;
6993 : : /* Prefix actions: meter, decap, encap, tag, jump, end, cnt. */
6994 : : #define METER_PREFIX_ACTION 7
6995 : 0 : act_size = (sizeof(struct rte_flow_action) *
6996 : 0 : (actions_n + METER_PREFIX_ACTION)) +
6997 : : sizeof(struct mlx5_rte_flow_action_set_tag);
6998 : : /* Flow can have multiple VLAN items. Account for them in suffix items. */
6999 : : vlan_items_n = flow_count_vlan_items(items);
7000 : : /* Suffix items: tag, [vlans], port id, end. */
7001 : : #define METER_SUFFIX_ITEM 3
7002 : 0 : item_size = sizeof(struct rte_flow_item) * (METER_SUFFIX_ITEM + vlan_items_n) +
7003 : : sizeof(struct mlx5_rte_flow_item_tag) * 2;
7004 : 0 : sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size + item_size),
7005 : : 0, SOCKET_ID_ANY);
7006 [ # # ]: 0 : if (!sfx_actions)
7007 : 0 : return rte_flow_error_set(error, ENOMEM,
7008 : : RTE_FLOW_ERROR_TYPE_ACTION,
7009 : : NULL, "no memory to split "
7010 : : "meter flow");
7011 : 0 : sfx_items = (struct rte_flow_item *)((char *)sfx_actions +
7012 : : act_size);
7013 : : /* There's no suffix flow for meter of non-default policy. */
7014 [ # # ]: 0 : if (!fm->def_policy)
7015 : 0 : pre_actions = sfx_actions + 1;
7016 : : else
7017 : 0 : pre_actions = sfx_actions + actions_n;
7018 [ # # ]: 0 : ret = flow_meter_split_prep(dev, flow, wks, &sfx_attr,
7019 : : items, sfx_items, actions,
7020 : : sfx_actions, pre_actions,
7021 : : (set_mtr_reg ? &mtr_flow_id : NULL),
7022 : : error);
7023 [ # # ]: 0 : if (ret) {
7024 : 0 : ret = -rte_errno;
7025 : 0 : goto exit;
7026 : : }
7027 : : /* Add the prefix subflow. */
7028 : 0 : skip_scale_restore = flow_split_info->skip_scale;
7029 : 0 : flow_split_info->skip_scale |=
7030 : : 1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT;
7031 : 0 : ret = flow_create_split_inner(dev, flow, &dev_flow,
7032 : : attr, items, pre_actions,
7033 : : flow_split_info, error);
7034 : 0 : flow_split_info->skip_scale = skip_scale_restore;
7035 [ # # ]: 0 : if (ret) {
7036 [ # # ]: 0 : if (mtr_flow_id)
7037 : 0 : mlx5_ipool_free(fm->flow_ipool, mtr_flow_id);
7038 : 0 : ret = -rte_errno;
7039 : 0 : goto exit;
7040 : : }
7041 [ # # ]: 0 : if (mtr_flow_id) {
7042 : 0 : dev_flow->handle->split_flow_id = mtr_flow_id;
7043 : 0 : dev_flow->handle->is_meter_flow_id = 1;
7044 : : }
7045 [ # # ]: 0 : if (!fm->def_policy) {
7046 [ # # # # ]: 0 : if (!set_mtr_reg && fm->drop_cnt)
7047 : 0 : ret =
7048 : 0 : flow_meter_create_drop_flow_with_org_pattern(dev, flow,
7049 : : &sfx_attr, items,
7050 : : flow_split_info,
7051 : : fm, error);
7052 : 0 : goto exit;
7053 : : }
7054 : : /* Setting the sfx group atrr. */
7055 : 0 : sfx_attr.group = sfx_attr.transfer ?
7056 [ # # ]: 0 : (MLX5_FLOW_TABLE_LEVEL_METER - 1) :
7057 : : MLX5_FLOW_TABLE_LEVEL_METER;
7058 : 0 : flow_split_info->prefix_layers =
7059 : 0 : flow_get_prefix_layer_flags(dev_flow);
7060 : 0 : flow_split_info->prefix_mark |= wks->mark;
7061 : 0 : flow_split_info->table_id = MLX5_MTR_TABLE_ID_SUFFIX;
7062 : : }
7063 : : /* Add the prefix subflow. */
7064 [ # # ]: 0 : ret = flow_create_split_metadata(dev, flow,
7065 : : &sfx_attr, sfx_items ?
7066 : : sfx_items : items,
7067 : : sfx_actions ? sfx_actions : actions,
7068 : : flow_split_info, error);
7069 : 0 : exit:
7070 [ # # ]: 0 : if (sfx_actions)
7071 : 0 : mlx5_free(sfx_actions);
7072 : : return ret;
7073 : : }
7074 : :
7075 : : /**
7076 : : * The splitting for sample feature.
7077 : : *
7078 : : * Once Sample action is detected in the action list, the flow actions should
7079 : : * be split into prefix sub flow and suffix sub flow.
7080 : : *
7081 : : * The original items remain in the prefix sub flow, all actions preceding the
7082 : : * sample action and the sample action itself will be copied to the prefix
7083 : : * sub flow, the actions following the sample action will be copied to the
7084 : : * suffix sub flow, Queue action always be located in the suffix sub flow.
7085 : : *
7086 : : * In order to make the packet from prefix sub flow matches with suffix sub
7087 : : * flow, an extra tag action be added into prefix sub flow, and the suffix sub
7088 : : * flow uses tag item with the unique flow id.
7089 : : *
7090 : : * @param dev
7091 : : * Pointer to Ethernet device.
7092 : : * @param[in] flow
7093 : : * Parent flow structure pointer.
7094 : : * @param[in] attr
7095 : : * Flow rule attributes.
7096 : : * @param[in] items
7097 : : * Pattern specification (list terminated by the END pattern item).
7098 : : * @param[in] actions
7099 : : * Associated actions (list terminated by the END action).
7100 : : * @param[in] flow_split_info
7101 : : * Pointer to flow split info structure.
7102 : : * @param[out] error
7103 : : * Perform verbose error reporting if not NULL.
7104 : : * @return
7105 : : * 0 on success, negative value otherwise
7106 : : */
7107 : : static int
7108 : 0 : flow_create_split_sample(struct rte_eth_dev *dev,
7109 : : struct rte_flow *flow,
7110 : : const struct rte_flow_attr *attr,
7111 : : const struct rte_flow_item items[],
7112 : : const struct rte_flow_action actions[],
7113 : : struct mlx5_flow_split_info *flow_split_info,
7114 : : struct rte_flow_error *error)
7115 : : {
7116 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7117 : : struct rte_flow_action *sfx_actions = NULL;
7118 : : struct rte_flow_action *pre_actions = NULL;
7119 : : struct rte_flow_item *sfx_items = NULL;
7120 : 0 : struct mlx5_flow *dev_flow = NULL;
7121 : 0 : struct rte_flow_attr sfx_attr = *attr;
7122 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
7123 : : struct mlx5_flow_dv_sample_resource *sample_res;
7124 : : struct mlx5_flow_tbl_data_entry *sfx_tbl_data;
7125 : : struct mlx5_flow_tbl_resource *sfx_tbl;
7126 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
7127 : : #endif
7128 : : size_t act_size;
7129 : : size_t item_size;
7130 : : uint32_t fdb_tx = 0;
7131 : : int32_t tag_id = 0;
7132 : : int actions_n = 0;
7133 : : int sample_action_pos;
7134 : : int qrss_action_pos;
7135 : : int add_tag = 0;
7136 : 0 : int modify_after_mirror = 0;
7137 : : uint16_t jump_table = 0;
7138 : : const uint32_t next_ft_step = 1;
7139 : : int ret = 0;
7140 : : struct mlx5_priv *item_port_priv = NULL;
7141 : : const struct rte_flow_item *item;
7142 : :
7143 [ # # ]: 0 : if (priv->sampler_en)
7144 : 0 : actions_n = flow_check_match_action(actions, attr,
7145 : : RTE_FLOW_ACTION_TYPE_SAMPLE,
7146 : : &sample_action_pos, &qrss_action_pos,
7147 : : &modify_after_mirror);
7148 [ # # ]: 0 : if (actions_n) {
7149 : : /* The prefix actions must includes sample, tag, end. */
7150 : 0 : act_size = sizeof(struct rte_flow_action) * (actions_n * 2 + 1)
7151 : : + sizeof(struct mlx5_rte_flow_action_set_tag);
7152 : : item_size = sizeof(struct rte_flow_item) * SAMPLE_SUFFIX_ITEM +
7153 : : sizeof(struct mlx5_rte_flow_item_tag) * 2;
7154 : 0 : sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size +
7155 : : item_size), 0, SOCKET_ID_ANY);
7156 [ # # ]: 0 : if (!sfx_actions)
7157 : 0 : return rte_flow_error_set(error, ENOMEM,
7158 : : RTE_FLOW_ERROR_TYPE_ACTION,
7159 : : NULL, "no memory to split "
7160 : : "sample flow");
7161 [ # # ]: 0 : for (item = items; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
7162 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_PORT_ID) {
7163 : : const struct rte_flow_item_port_id *spec;
7164 : :
7165 : 0 : spec = (const struct rte_flow_item_port_id *)item->spec;
7166 [ # # ]: 0 : if (spec)
7167 : : item_port_priv =
7168 : 0 : mlx5_port_to_eswitch_info(spec->id, true);
7169 : : break;
7170 [ # # ]: 0 : } else if (item->type == RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT) {
7171 : : const struct rte_flow_item_ethdev *spec;
7172 : :
7173 : 0 : spec = (const struct rte_flow_item_ethdev *)item->spec;
7174 [ # # ]: 0 : if (spec)
7175 : : item_port_priv =
7176 : 0 : mlx5_port_to_eswitch_info(spec->port_id, true);
7177 : : break;
7178 [ # # ]: 0 : } else if (item->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR) {
7179 : : const struct rte_flow_item_ethdev *spec;
7180 : :
7181 : 0 : spec = (const struct rte_flow_item_ethdev *)item->spec;
7182 [ # # ]: 0 : if (spec)
7183 : : item_port_priv =
7184 : 0 : mlx5_port_to_eswitch_info(spec->port_id, true);
7185 : : break;
7186 : : }
7187 : : }
7188 : : /* The representor_id is UINT16_MAX for uplink. */
7189 [ # # # # ]: 0 : fdb_tx = (attr->transfer &&
7190 : : flow_source_vport_representor(priv, item_port_priv));
7191 : : /*
7192 : : * When reg_c_preserve is set, metadata registers Cx preserve
7193 : : * their value even through packet duplication.
7194 : : */
7195 : 0 : add_tag = (!fdb_tx ||
7196 [ # # ]: 0 : priv->sh->cdev->config.hca_attr.reg_c_preserve);
7197 : : if (add_tag)
7198 : 0 : sfx_items = (struct rte_flow_item *)((char *)sfx_actions
7199 : : + act_size);
7200 [ # # ]: 0 : if (modify_after_mirror)
7201 : 0 : jump_table = attr->group * MLX5_FLOW_TABLE_FACTOR +
7202 : : next_ft_step;
7203 : 0 : pre_actions = sfx_actions + actions_n;
7204 : 0 : tag_id = flow_sample_split_prep(dev, add_tag, items, sfx_items,
7205 : : actions, sfx_actions,
7206 : : pre_actions, actions_n,
7207 : : sample_action_pos,
7208 : : qrss_action_pos, jump_table,
7209 : : error);
7210 [ # # # # ]: 0 : if (tag_id < 0 || (add_tag && !tag_id)) {
7211 : 0 : ret = -rte_errno;
7212 : 0 : goto exit;
7213 : : }
7214 [ # # ]: 0 : if (modify_after_mirror)
7215 : 0 : flow_split_info->skip_scale =
7216 : : 1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT;
7217 : : /* Add the prefix subflow. */
7218 : 0 : ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
7219 : : items, pre_actions,
7220 : : flow_split_info, error);
7221 [ # # ]: 0 : if (ret) {
7222 : 0 : ret = -rte_errno;
7223 : 0 : goto exit;
7224 : : }
7225 : 0 : dev_flow->handle->split_flow_id = tag_id;
7226 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
7227 [ # # ]: 0 : if (!modify_after_mirror) {
7228 : : /* Set the sfx group attr. */
7229 : 0 : sample_res = (struct mlx5_flow_dv_sample_resource *)
7230 : : dev_flow->dv.sample_res;
7231 : 0 : sfx_tbl = (struct mlx5_flow_tbl_resource *)
7232 : : sample_res->normal_path_tbl;
7233 : 0 : sfx_tbl_data = container_of(sfx_tbl,
7234 : : struct mlx5_flow_tbl_data_entry,
7235 : : tbl);
7236 : 0 : sfx_attr.group = sfx_attr.transfer ?
7237 [ # # ]: 0 : (sfx_tbl_data->level - 1) : sfx_tbl_data->level;
7238 : : } else {
7239 : : MLX5_ASSERT(attr->transfer);
7240 : 0 : sfx_attr.group = jump_table;
7241 : : }
7242 : 0 : flow_split_info->prefix_layers =
7243 : 0 : flow_get_prefix_layer_flags(dev_flow);
7244 : : MLX5_ASSERT(wks);
7245 : 0 : flow_split_info->prefix_mark |= wks->mark;
7246 : : /* Suffix group level already be scaled with factor, set
7247 : : * MLX5_SCALE_FLOW_GROUP_BIT of skip_scale to 1 to avoid scale
7248 : : * again in translation.
7249 : : */
7250 : 0 : flow_split_info->skip_scale = 1 << MLX5_SCALE_FLOW_GROUP_BIT;
7251 : : #endif
7252 : : }
7253 : : /* Add the suffix subflow. */
7254 [ # # # # ]: 0 : ret = flow_create_split_meter(dev, flow, &sfx_attr,
7255 : : sfx_items ? sfx_items : items,
7256 : : sfx_actions ? sfx_actions : actions,
7257 : : flow_split_info, error);
7258 : 0 : exit:
7259 [ # # ]: 0 : if (sfx_actions)
7260 : 0 : mlx5_free(sfx_actions);
7261 : : return ret;
7262 : : }
7263 : :
7264 : : /**
7265 : : * Split the flow to subflow set. The splitters might be linked
7266 : : * in the chain, like this:
7267 : : * flow_create_split_outer() calls:
7268 : : * flow_create_split_meter() calls:
7269 : : * flow_create_split_metadata(meter_subflow_0) calls:
7270 : : * flow_create_split_inner(metadata_subflow_0)
7271 : : * flow_create_split_inner(metadata_subflow_1)
7272 : : * flow_create_split_inner(metadata_subflow_2)
7273 : : * flow_create_split_metadata(meter_subflow_1) calls:
7274 : : * flow_create_split_inner(metadata_subflow_0)
7275 : : * flow_create_split_inner(metadata_subflow_1)
7276 : : * flow_create_split_inner(metadata_subflow_2)
7277 : : *
7278 : : * This provide flexible way to add new levels of flow splitting.
7279 : : * The all of successfully created subflows are included to the
7280 : : * parent flow dev_flow list.
7281 : : *
7282 : : * @param dev
7283 : : * Pointer to Ethernet device.
7284 : : * @param[in] flow
7285 : : * Parent flow structure pointer.
7286 : : * @param[in] attr
7287 : : * Flow rule attributes.
7288 : : * @param[in] items
7289 : : * Pattern specification (list terminated by the END pattern item).
7290 : : * @param[in] actions
7291 : : * Associated actions (list terminated by the END action).
7292 : : * @param[in] flow_split_info
7293 : : * Pointer to flow split info structure.
7294 : : * @param[out] error
7295 : : * Perform verbose error reporting if not NULL.
7296 : : * @return
7297 : : * 0 on success, negative value otherwise
7298 : : */
7299 : : static int
7300 : : flow_create_split_outer(struct rte_eth_dev *dev,
7301 : : struct rte_flow *flow,
7302 : : const struct rte_flow_attr *attr,
7303 : : const struct rte_flow_item items[],
7304 : : const struct rte_flow_action actions[],
7305 : : struct mlx5_flow_split_info *flow_split_info,
7306 : : struct rte_flow_error *error)
7307 : : {
7308 : : int ret;
7309 : :
7310 : 0 : ret = flow_create_split_sample(dev, flow, attr, items,
7311 : : actions, flow_split_info, error);
7312 : : MLX5_ASSERT(ret <= 0);
7313 : : return ret;
7314 : : }
7315 : :
7316 : : static inline struct mlx5_flow_tunnel *
7317 : : flow_tunnel_from_rule(const struct mlx5_flow *flow)
7318 : : {
7319 : : struct mlx5_flow_tunnel *tunnel;
7320 : :
7321 : 0 : tunnel = RTE_PTR_UNQUAL(flow->tunnel);
7322 : :
7323 : : return tunnel;
7324 : : }
7325 : :
7326 : : /**
7327 : : * Create a flow and add it to @p list.
7328 : : *
7329 : : * @param dev
7330 : : * Pointer to Ethernet device.
7331 : : * @param list
7332 : : * Pointer to a TAILQ flow list. If this parameter NULL,
7333 : : * no list insertion occurred, flow is just created,
7334 : : * this is caller's responsibility to track the
7335 : : * created flow.
7336 : : * @param[in] attr
7337 : : * Flow rule attributes.
7338 : : * @param[in] items
7339 : : * Pattern specification (list terminated by the END pattern item).
7340 : : * @param[in] actions
7341 : : * Associated actions (list terminated by the END action).
7342 : : * @param[in] external
7343 : : * This flow rule is created by request external to PMD.
7344 : : * @param[out] error
7345 : : * Perform verbose error reporting if not NULL.
7346 : : *
7347 : : * @return
7348 : : * A flow index on success, 0 otherwise and rte_errno is set.
7349 : : */
7350 : : uintptr_t
7351 : 0 : flow_legacy_list_create(struct rte_eth_dev *dev, enum mlx5_flow_type type,
7352 : : const struct rte_flow_attr *attr,
7353 : : const struct rte_flow_item items[],
7354 : : const struct rte_flow_action original_actions[],
7355 : : bool external, struct rte_flow_error *error)
7356 : : {
7357 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7358 : : struct rte_flow *flow = NULL;
7359 : : struct mlx5_flow *dev_flow;
7360 : : const struct rte_flow_action_rss *rss = NULL;
7361 : : struct mlx5_translated_action_handle
7362 : : indir_actions[MLX5_MAX_INDIRECT_ACTIONS];
7363 : 0 : int indir_actions_n = MLX5_MAX_INDIRECT_ACTIONS;
7364 : : union {
7365 : : struct mlx5_flow_expand_rss buf;
7366 : : uint8_t buffer[8192];
7367 : : } expand_buffer;
7368 : : union {
7369 : : struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
7370 : : uint8_t buffer[2048];
7371 : : } actions_rx;
7372 : : union {
7373 : : struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
7374 : : uint8_t buffer[2048];
7375 : : } actions_hairpin_tx;
7376 : : union {
7377 : : struct rte_flow_item items[MLX5_MAX_SPLIT_ITEMS];
7378 : : uint8_t buffer[2048];
7379 : : } items_tx;
7380 : : struct mlx5_rte_flow_item_sq sq_specs[RTE_MAX_QUEUES_PER_PORT];
7381 : : struct mlx5_flow_expand_rss *buf = &expand_buffer.buf;
7382 : : struct mlx5_flow_rss_desc *rss_desc;
7383 : : const struct rte_flow_action *p_actions_rx;
7384 : : uint32_t i;
7385 : 0 : uint32_t idx = 0;
7386 : : int hairpin_flow;
7387 : 0 : struct rte_flow_attr attr_tx = { .priority = 0 };
7388 : : const struct rte_flow_action *actions;
7389 : 0 : struct rte_flow_action *translated_actions = NULL;
7390 : : struct mlx5_flow_tunnel *tunnel;
7391 : 0 : struct tunnel_default_miss_ctx default_miss_ctx = { 0, };
7392 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_push_thread_workspace();
7393 : 0 : struct mlx5_flow_split_info flow_split_info = {
7394 : : .external = !!external,
7395 : : .skip_scale = 0,
7396 : : .flow_idx = 0,
7397 : : .prefix_mark = 0,
7398 : : .prefix_layers = 0,
7399 : : .table_id = 0
7400 : : };
7401 : : int ret;
7402 : : struct mlx5_shared_action_rss *shared_rss_action;
7403 : :
7404 [ # # ]: 0 : if (!wks)
7405 : 0 : return rte_flow_error_set(error, ENOMEM,
7406 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7407 : : NULL,
7408 : : "failed to push flow workspace");
7409 : : memset(indir_actions, 0, sizeof(indir_actions));
7410 : 0 : rss_desc = &wks->rss_desc;
7411 : 0 : ret = flow_action_handles_translate(dev, original_actions,
7412 : : indir_actions,
7413 : : &indir_actions_n,
7414 : : &translated_actions, error);
7415 [ # # ]: 0 : if (ret < 0) {
7416 : : MLX5_ASSERT(translated_actions == NULL);
7417 : : return 0;
7418 : : }
7419 [ # # ]: 0 : actions = translated_actions ? translated_actions : original_actions;
7420 : : p_actions_rx = actions;
7421 : 0 : hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
7422 : 0 : ret = flow_drv_validate(dev, attr, items, p_actions_rx,
7423 : : external, hairpin_flow, error);
7424 [ # # ]: 0 : if (ret < 0)
7425 : 0 : goto error_before_hairpin_split;
7426 : 0 : flow = mlx5_ipool_zmalloc(priv->flows[type], &idx);
7427 [ # # ]: 0 : if (!flow) {
7428 : 0 : rte_errno = ENOMEM;
7429 : 0 : goto error_before_hairpin_split;
7430 : : }
7431 [ # # ]: 0 : if (hairpin_flow > 0) {
7432 [ # # ]: 0 : if (hairpin_flow > MLX5_MAX_SPLIT_ACTIONS) {
7433 : 0 : rte_errno = EINVAL;
7434 : 0 : goto error_before_hairpin_split;
7435 : : }
7436 : 0 : flow_hairpin_split(dev, actions, actions_rx.actions,
7437 : : actions_hairpin_tx.actions, items_tx.items,
7438 : : idx);
7439 : : p_actions_rx = actions_rx.actions;
7440 : : }
7441 : 0 : flow_split_info.flow_idx = idx;
7442 [ # # ]: 0 : flow->drv_type = flow_get_drv_type(dev, attr);
7443 : : MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
7444 : : flow->drv_type < MLX5_FLOW_TYPE_MAX);
7445 : : memset(rss_desc, 0, offsetof(struct mlx5_flow_rss_desc, queue));
7446 : : /* RSS Action only works on NIC RX domain */
7447 [ # # ]: 0 : if (attr->ingress)
7448 : 0 : rss = flow_get_rss_action(dev, p_actions_rx);
7449 [ # # ]: 0 : if (rss) {
7450 : : MLX5_ASSERT(rss->queue_num <= RTE_ETH_RSS_RETA_SIZE_512);
7451 : 0 : rss_desc->symmetric_hash_function = MLX5_RSS_IS_SYMM(rss->func);
7452 : : /*
7453 : : * The following information is required by
7454 : : * mlx5_flow_hashfields_adjust() in advance.
7455 : : */
7456 : 0 : rss_desc->level = rss->level;
7457 : : /* RSS type 0 indicates default RSS type (RTE_ETH_RSS_IP). */
7458 [ # # ]: 0 : rss_desc->types = !rss->types ? RTE_ETH_RSS_IP : rss->types;
7459 : : }
7460 : 0 : flow->dev_handles = 0;
7461 [ # # # # ]: 0 : if (rss && rss->types) {
7462 : : unsigned int graph_root;
7463 : :
7464 : 0 : graph_root = find_graph_root(rss->level);
7465 : 0 : ret = mlx5_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
7466 : : items, rss->types,
7467 : : mlx5_support_expansion, graph_root);
7468 : : MLX5_ASSERT(ret > 0 &&
7469 : : (unsigned int)ret < sizeof(expand_buffer.buffer));
7470 [ # # ]: 0 : if (rte_log_can_log(mlx5_logtype, RTE_LOG_DEBUG)) {
7471 [ # # ]: 0 : for (i = 0; i < buf->entries; ++i)
7472 : 0 : mlx5_dbg__print_pattern(buf->entry[i].pattern);
7473 : : }
7474 : : } else {
7475 : 0 : ret = mlx5_flow_expand_sqn((struct mlx5_flow_expand_sqn *)buf,
7476 : : sizeof(expand_buffer.buffer),
7477 : : items, sq_specs);
7478 [ # # ]: 0 : if (ret) {
7479 : 0 : rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_HANDLE,
7480 : : NULL, "not enough memory for rte_flow");
7481 : 0 : goto error;
7482 : : }
7483 [ # # ]: 0 : if (buf->entries == 0) {
7484 : 0 : buf->entries = 1;
7485 : 0 : buf->entry[0].pattern = (void *)(uintptr_t)items;
7486 : : }
7487 : : }
7488 : 0 : rss_desc->shared_rss = flow_get_shared_rss_action(dev, indir_actions,
7489 : : indir_actions_n);
7490 [ # # ]: 0 : for (i = 0; i < buf->entries; ++i) {
7491 : : /* Initialize flow split data. */
7492 : 0 : flow_split_info.prefix_layers = 0;
7493 : 0 : flow_split_info.prefix_mark = 0;
7494 : 0 : flow_split_info.skip_scale = 0;
7495 : : /*
7496 : : * The splitter may create multiple dev_flows,
7497 : : * depending on configuration. In the simplest
7498 : : * case it just creates unmodified original flow.
7499 : : */
7500 : : ret = flow_create_split_outer(dev, flow, attr,
7501 : 0 : buf->entry[i].pattern,
7502 : : p_actions_rx, &flow_split_info,
7503 : : error);
7504 [ # # ]: 0 : if (ret < 0)
7505 : 0 : goto error;
7506 [ # # ]: 0 : if (is_flow_tunnel_steer_rule(wks->flows[0].tof_type)) {
7507 : 0 : ret = flow_tunnel_add_default_miss(dev, flow, attr,
7508 : : p_actions_rx,
7509 : : idx,
7510 : : wks->flows[0].tunnel,
7511 : : &default_miss_ctx,
7512 : : error);
7513 [ # # ]: 0 : if (ret < 0) {
7514 : 0 : mlx5_free(default_miss_ctx.queue);
7515 : 0 : goto error;
7516 : : }
7517 : : }
7518 : : }
7519 : : /* Create the tx flow. */
7520 [ # # ]: 0 : if (hairpin_flow) {
7521 : 0 : attr_tx.group = MLX5_HAIRPIN_TX_TABLE;
7522 : 0 : attr_tx.ingress = 0;
7523 : 0 : attr_tx.egress = 1;
7524 : 0 : dev_flow = flow_drv_prepare(dev, flow, &attr_tx, items_tx.items,
7525 : : actions_hairpin_tx.actions,
7526 : : idx, error);
7527 [ # # ]: 0 : if (!dev_flow)
7528 : 0 : goto error;
7529 : 0 : dev_flow->flow = flow;
7530 : 0 : dev_flow->external = 0;
7531 : 0 : SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
7532 : : dev_flow->handle, next);
7533 : : ret = flow_drv_translate(dev, dev_flow, &attr_tx,
7534 : : items_tx.items,
7535 : : actions_hairpin_tx.actions, error);
7536 [ # # ]: 0 : if (ret < 0)
7537 : 0 : goto error;
7538 : : }
7539 : : /*
7540 : : * Update the metadata register copy table. If extensive
7541 : : * metadata feature is enabled and registers are supported
7542 : : * we might create the extra rte_flow for each unique
7543 : : * MARK/FLAG action ID.
7544 : : *
7545 : : * The table is updated for ingress and transfer flows only, because
7546 : : * the egress Flows belong to the different device and
7547 : : * copy table should be updated in peer NIC Rx domain.
7548 : : */
7549 [ # # # # ]: 0 : if ((attr->ingress || attr->transfer) &&
7550 [ # # ]: 0 : (external || attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
7551 : 0 : ret = flow_mreg_update_copy_table(dev, flow, actions, error);
7552 [ # # ]: 0 : if (ret)
7553 : 0 : goto error;
7554 : : }
7555 : : /*
7556 : : * If the flow is external (from application) OR device is started,
7557 : : * OR mreg discover, then apply immediately.
7558 : : */
7559 [ # # # # ]: 0 : if (external || dev->data->dev_started ||
7560 [ # # ]: 0 : (attr->group == MLX5_FLOW_MREG_CP_TABLE_GROUP &&
7561 [ # # ]: 0 : attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)) {
7562 : : ret = flow_drv_apply(dev, flow, error);
7563 [ # # ]: 0 : if (ret < 0)
7564 : 0 : goto error;
7565 : : }
7566 : 0 : flow->type = type;
7567 : 0 : flow_rxq_flags_set(dev, flow);
7568 : 0 : rte_free(translated_actions);
7569 : : tunnel = flow_tunnel_from_rule(wks->flows);
7570 [ # # ]: 0 : if (tunnel) {
7571 : 0 : flow->tunnel = 1;
7572 : 0 : flow->tunnel_id = tunnel->tunnel_id;
7573 : 0 : rte_atomic_fetch_add_explicit(&tunnel->refctn, 1, rte_memory_order_relaxed);
7574 : 0 : mlx5_free(default_miss_ctx.queue);
7575 : : }
7576 : 0 : mlx5_flow_pop_thread_workspace();
7577 : 0 : return idx;
7578 : 0 : error:
7579 : : MLX5_ASSERT(flow);
7580 : 0 : ret = rte_errno; /* Save rte_errno before cleanup. */
7581 : 0 : flow_mreg_del_copy_action(dev, flow);
7582 : : flow_drv_destroy(dev, flow);
7583 : :
7584 [ # # ]: 0 : if (rss_desc->shared_rss) {
7585 : : shared_rss_action = (struct mlx5_shared_action_rss *)
7586 : 0 : mlx5_ipool_get
7587 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
7588 : : rss_desc->shared_rss);
7589 [ # # ]: 0 : if (shared_rss_action)
7590 : 0 : rte_atomic_fetch_sub_explicit(&(shared_rss_action)->refcnt, 1,
7591 : : rte_memory_order_relaxed);
7592 : : }
7593 : 0 : mlx5_ipool_free(priv->flows[type], idx);
7594 : 0 : rte_errno = ret; /* Restore rte_errno. */
7595 : : ret = rte_errno;
7596 : : rte_errno = ret;
7597 : 0 : error_before_hairpin_split:
7598 : 0 : mlx5_flow_pop_thread_workspace();
7599 : 0 : rte_free(translated_actions);
7600 : 0 : return 0;
7601 : : }
7602 : :
7603 : : /**
7604 : : * Create a dedicated flow rule on e-switch table 0 (root table), to direct all
7605 : : * incoming packets to table 1.
7606 : : *
7607 : : * Other flow rules, requested for group n, will be created in
7608 : : * e-switch table n+1.
7609 : : * Jump action to e-switch group n will be created to group n+1.
7610 : : *
7611 : : * Used when working in switchdev mode, to utilise advantages of table 1
7612 : : * and above.
7613 : : *
7614 : : * @param dev
7615 : : * Pointer to Ethernet device.
7616 : : *
7617 : : * @return
7618 : : * Pointer to flow on success, NULL otherwise and rte_errno is set.
7619 : : */
7620 : : struct rte_flow *
7621 : 0 : mlx5_flow_create_esw_table_zero_flow(struct rte_eth_dev *dev)
7622 : : {
7623 : 0 : const struct rte_flow_attr attr = {
7624 : : .group = 0,
7625 : : .priority = 0,
7626 : : .ingress = 0,
7627 : : .egress = 0,
7628 : : .transfer = 1,
7629 : : };
7630 : 0 : const struct rte_flow_item pattern = {
7631 : : .type = RTE_FLOW_ITEM_TYPE_END,
7632 : : };
7633 : 0 : struct rte_flow_action_jump jump = {
7634 : : .group = 1,
7635 : : };
7636 : 0 : const struct rte_flow_action actions[] = {
7637 : : {
7638 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
7639 : : .conf = &jump,
7640 : : },
7641 : : {
7642 : : .type = RTE_FLOW_ACTION_TYPE_END,
7643 : : },
7644 : : };
7645 : : struct rte_flow_error error;
7646 : :
7647 : 0 : return (void *)(uintptr_t)mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
7648 : : &attr, &pattern,
7649 : : actions, false, &error);
7650 : : }
7651 : :
7652 : : /**
7653 : : * Create a dedicated flow rule on e-switch table 1, matches ESW manager
7654 : : * and sq number, directs all packets to peer vport.
7655 : : *
7656 : : * @param dev
7657 : : * Pointer to Ethernet device.
7658 : : * @param sq_num
7659 : : * SQ number.
7660 : : *
7661 : : * @return
7662 : : * Flow ID on success, 0 otherwise and rte_errno is set.
7663 : : */
7664 : : uint32_t
7665 : 0 : mlx5_flow_create_devx_sq_miss_flow(struct rte_eth_dev *dev, uint32_t sq_num)
7666 : : {
7667 : 0 : struct rte_flow_attr attr = {
7668 : : .group = 0,
7669 : : .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
7670 : : .ingress = 0,
7671 : : .egress = 0,
7672 : : .transfer = 1,
7673 : : };
7674 : 0 : struct rte_flow_item_port_id port_spec = {
7675 : : .id = MLX5_PORT_ESW_MGR,
7676 : : };
7677 : 0 : struct mlx5_rte_flow_item_sq sq_spec = {
7678 : : .queue = sq_num,
7679 : : };
7680 : 0 : struct rte_flow_item pattern[] = {
7681 : : {
7682 : : .type = RTE_FLOW_ITEM_TYPE_PORT_ID,
7683 : : .spec = &port_spec,
7684 : : },
7685 : : {
7686 : : .type = (enum rte_flow_item_type)
7687 : : MLX5_RTE_FLOW_ITEM_TYPE_SQ,
7688 : : .spec = &sq_spec,
7689 : : },
7690 : : {
7691 : : .type = RTE_FLOW_ITEM_TYPE_END,
7692 : : },
7693 : : };
7694 : 0 : struct rte_flow_action_jump jump = {
7695 : : .group = 1,
7696 : : };
7697 : 0 : struct rte_flow_action_port_id port = {
7698 : 0 : .id = dev->data->port_id,
7699 : : };
7700 : 0 : struct rte_flow_action actions[] = {
7701 : : {
7702 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
7703 : : .conf = &jump,
7704 : : },
7705 : : {
7706 : : .type = RTE_FLOW_ACTION_TYPE_END,
7707 : : },
7708 : : };
7709 : : struct rte_flow_error error;
7710 : :
7711 : : /*
7712 : : * Creates group 0, highest priority jump flow.
7713 : : * Matches txq to bypass kernel packets.
7714 : : */
7715 [ # # ]: 0 : if (mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_CTL, &attr, pattern, actions,
7716 : : false, &error) == 0)
7717 : : return 0;
7718 : : /* Create group 1, lowest priority redirect flow for txq. */
7719 : 0 : attr.group = 1;
7720 : 0 : actions[0].conf = &port;
7721 : 0 : actions[0].type = RTE_FLOW_ACTION_TYPE_PORT_ID;
7722 : 0 : return mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_CTL, &attr, pattern,
7723 : : actions, false, &error);
7724 : : }
7725 : :
7726 : : /**
7727 : : * Validate a flow supported by the NIC.
7728 : : *
7729 : : * @see rte_flow_validate()
7730 : : * @see rte_flow_ops
7731 : : */
7732 : : int
7733 : 0 : mlx5_flow_validate(struct rte_eth_dev *dev,
7734 : : const struct rte_flow_attr *attr,
7735 : : const struct rte_flow_item items[],
7736 : : const struct rte_flow_action original_actions[],
7737 : : struct rte_flow_error *error)
7738 : : {
7739 : : int hairpin_flow;
7740 : : struct mlx5_translated_action_handle
7741 : : indir_actions[MLX5_MAX_INDIRECT_ACTIONS];
7742 : 0 : int indir_actions_n = MLX5_MAX_INDIRECT_ACTIONS;
7743 : : const struct rte_flow_action *actions;
7744 : 0 : struct rte_flow_action *translated_actions = NULL;
7745 : 0 : int ret = flow_action_handles_translate(dev, original_actions,
7746 : : indir_actions,
7747 : : &indir_actions_n,
7748 : : &translated_actions, error);
7749 : :
7750 [ # # ]: 0 : if (ret)
7751 : : return ret;
7752 [ # # ]: 0 : actions = translated_actions ? translated_actions : original_actions;
7753 : 0 : hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
7754 : 0 : ret = flow_drv_validate(dev, attr, items, actions,
7755 : : true, hairpin_flow, error);
7756 : 0 : rte_free(translated_actions);
7757 : 0 : return ret;
7758 : : }
7759 : :
7760 : : static int
7761 : 0 : mlx5_flow_cache_flow_info(struct rte_eth_dev *dev,
7762 : : const struct rte_flow_attr *attr,
7763 : : const uint32_t orig_prio,
7764 : : const struct rte_flow_item *items,
7765 : : const struct rte_flow_action *actions,
7766 : : uint32_t flow_idx)
7767 : : {
7768 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7769 : : struct rte_pmd_mlx5_flow_engine_mode_info *mode_info = &priv->mode_info;
7770 : : struct mlx5_dv_flow_info *flow_info, *tmp_info;
7771 : : struct rte_flow_error error;
7772 : : int len, ret;
7773 : :
7774 : 0 : flow_info = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*flow_info), 0, SOCKET_ID_ANY);
7775 [ # # ]: 0 : if (!flow_info) {
7776 : 0 : DRV_LOG(ERR, "No enough memory for flow_info caching.");
7777 : 0 : return -1;
7778 : : }
7779 : 0 : flow_info->orig_prio = orig_prio;
7780 : 0 : flow_info->attr = *attr;
7781 : : /* Standby mode rule awlays saves it in low priority entry. */
7782 : 0 : flow_info->flow_idx_low_prio = flow_idx;
7783 : :
7784 : : /* Store matching items. */
7785 : 0 : ret = rte_flow_conv(RTE_FLOW_CONV_OP_PATTERN, NULL, 0, items, &error);
7786 [ # # ]: 0 : if (ret <= 0) {
7787 : 0 : DRV_LOG(ERR, "Can't get items length.");
7788 : 0 : goto end;
7789 : : }
7790 : 0 : len = RTE_ALIGN(ret, 16);
7791 : 0 : flow_info->items = mlx5_malloc(MLX5_MEM_ZERO, len, 0, SOCKET_ID_ANY);
7792 [ # # ]: 0 : if (!flow_info->items) {
7793 : 0 : DRV_LOG(ERR, "No enough memory for items caching.");
7794 : 0 : goto end;
7795 : : }
7796 : 0 : ret = rte_flow_conv(RTE_FLOW_CONV_OP_PATTERN, flow_info->items, ret, items, &error);
7797 [ # # ]: 0 : if (ret <= 0) {
7798 : 0 : DRV_LOG(ERR, "Can't duplicate items.");
7799 : 0 : goto end;
7800 : : }
7801 : :
7802 : : /* Store flow actions. */
7803 : 0 : ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTIONS, NULL, 0, actions, &error);
7804 [ # # ]: 0 : if (ret <= 0) {
7805 : 0 : DRV_LOG(ERR, "Can't get actions length.");
7806 : 0 : goto end;
7807 : : }
7808 : 0 : len = RTE_ALIGN(ret, 16);
7809 : 0 : flow_info->actions = mlx5_malloc(MLX5_MEM_ZERO, len, 0, SOCKET_ID_ANY);
7810 [ # # ]: 0 : if (!flow_info->actions) {
7811 : 0 : DRV_LOG(ERR, "No enough memory for actions caching.");
7812 : 0 : goto end;
7813 : : }
7814 : 0 : ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTIONS, flow_info->actions, ret, actions, &error);
7815 [ # # ]: 0 : if (ret <= 0) {
7816 : 0 : DRV_LOG(ERR, "Can't duplicate actions.");
7817 : 0 : goto end;
7818 : : }
7819 : :
7820 : : /* Insert to the list end. */
7821 [ # # ]: 0 : if (LIST_EMPTY(&mode_info->hot_upgrade)) {
7822 : 0 : LIST_INSERT_HEAD(&mode_info->hot_upgrade, flow_info, next);
7823 : : } else {
7824 : : tmp_info = LIST_FIRST(&mode_info->hot_upgrade);
7825 [ # # ]: 0 : while (LIST_NEXT(tmp_info, next))
7826 : : tmp_info = LIST_NEXT(tmp_info, next);
7827 : 0 : LIST_INSERT_AFTER(tmp_info, flow_info, next);
7828 : : }
7829 : : return 0;
7830 : 0 : end:
7831 [ # # ]: 0 : if (flow_info->items)
7832 : 0 : mlx5_free(flow_info->items);
7833 [ # # ]: 0 : if (flow_info->actions)
7834 : 0 : mlx5_free(flow_info->actions);
7835 : 0 : mlx5_free(flow_info);
7836 : 0 : return -1;
7837 : : }
7838 : :
7839 : : static int
7840 : 0 : mlx5_flow_cache_flow_toggle(struct rte_eth_dev *dev, bool orig_prio)
7841 : : {
7842 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7843 : : struct rte_pmd_mlx5_flow_engine_mode_info *mode_info = &priv->mode_info;
7844 : : struct mlx5_dv_flow_info *flow_info;
7845 : : struct rte_flow_attr attr;
7846 : : struct rte_flow_error error;
7847 : : struct rte_flow *high, *low;
7848 : :
7849 : 0 : flow_info = LIST_FIRST(&mode_info->hot_upgrade);
7850 [ # # ]: 0 : while (flow_info) {
7851 : : /* DUP flow may have the same priority. */
7852 [ # # ]: 0 : if (flow_info->orig_prio != flow_info->attr.priority) {
7853 : 0 : attr = flow_info->attr;
7854 [ # # ]: 0 : if (orig_prio)
7855 : 0 : attr.priority = flow_info->orig_prio;
7856 : 0 : flow_info->flow_idx_high_prio = mlx5_flow_list_create(dev,
7857 : : MLX5_FLOW_TYPE_GEN, &attr,
7858 : 0 : flow_info->items, flow_info->actions,
7859 : : true, &error);
7860 [ # # ]: 0 : if (!flow_info->flow_idx_high_prio) {
7861 : 0 : DRV_LOG(ERR, "Priority toggle failed internally.");
7862 : 0 : goto err;
7863 : : }
7864 : : }
7865 : 0 : flow_info = LIST_NEXT(flow_info, next);
7866 : : }
7867 : : /* Delete the low priority rules and swap the flow handle. */
7868 : 0 : flow_info = LIST_FIRST(&mode_info->hot_upgrade);
7869 [ # # ]: 0 : while (flow_info) {
7870 : : MLX5_ASSERT(flow_info->flow_idx_low_prio);
7871 [ # # ]: 0 : if (flow_info->orig_prio != flow_info->attr.priority) {
7872 : 0 : high = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
7873 : : flow_info->flow_idx_high_prio);
7874 : 0 : low = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
7875 : : flow_info->flow_idx_low_prio);
7876 [ # # ]: 0 : if (high && low) {
7877 : 0 : RTE_SWAP(*low, *high);
7878 : 0 : mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN,
7879 : 0 : flow_info->flow_idx_low_prio);
7880 : 0 : flow_info->flow_idx_high_prio = 0;
7881 : : }
7882 : : }
7883 : 0 : flow_info = LIST_NEXT(flow_info, next);
7884 : : }
7885 : : return 0;
7886 : : err:
7887 : : /* Destroy preceding successful high priority rules. */
7888 : 0 : flow_info = LIST_FIRST(&mode_info->hot_upgrade);
7889 [ # # ]: 0 : while (flow_info) {
7890 [ # # ]: 0 : if (flow_info->orig_prio != flow_info->attr.priority) {
7891 [ # # ]: 0 : if (flow_info->flow_idx_high_prio)
7892 : 0 : mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN,
7893 : : flow_info->flow_idx_high_prio);
7894 : : else
7895 : : break;
7896 : 0 : flow_info->flow_idx_high_prio = 0;
7897 : : }
7898 : 0 : flow_info = LIST_NEXT(flow_info, next);
7899 : : }
7900 : : return -1;
7901 : : }
7902 : :
7903 : : /**
7904 : : * Set the mode of the flow engine of a process to active or standby during live migration.
7905 : : *
7906 : : * @param[in] mode
7907 : : * MLX5 flow engine mode, @see `enum rte_pmd_mlx5_flow_engine_mode`.
7908 : : * @param[in] flags
7909 : : * Flow engine mode specific flags.
7910 : : *
7911 : : * @return
7912 : : * Negative value on error, positive on success.
7913 : : */
7914 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_mlx5_flow_engine_set_mode, 23.03)
7915 : : int
7916 : 0 : rte_pmd_mlx5_flow_engine_set_mode(enum rte_pmd_mlx5_flow_engine_mode mode, uint32_t flags)
7917 : : {
7918 : : struct mlx5_priv *priv;
7919 : : struct rte_pmd_mlx5_flow_engine_mode_info *mode_info;
7920 : : struct mlx5_dv_flow_info *flow_info, *tmp_info;
7921 : : uint16_t port, port_id;
7922 : : uint16_t toggle_num = 0;
7923 : : struct rte_eth_dev *dev;
7924 : : enum rte_pmd_mlx5_flow_engine_mode orig_mode;
7925 : : uint32_t orig_flags;
7926 : : bool need_toggle = false;
7927 : :
7928 : : /* Check if flags combinations are supported. */
7929 [ # # ]: 0 : if (flags && flags != RTE_PMD_MLX5_FLOW_ENGINE_FLAG_STANDBY_DUP_INGRESS) {
7930 : 0 : DRV_LOG(ERR, "Doesn't support such flags %u", flags);
7931 : 0 : return -1;
7932 : : }
7933 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port, NULL) {
7934 : 0 : dev = &rte_eth_devices[port];
7935 : 0 : priv = dev->data->dev_private;
7936 : : mode_info = &priv->mode_info;
7937 : : /* No mode change. Assume all devices hold the same mode. */
7938 [ # # ]: 0 : if (mode_info->mode == mode) {
7939 : 0 : DRV_LOG(INFO, "Process flow engine has been in mode %u", mode);
7940 [ # # # # ]: 0 : if (mode_info->mode_flag != flags && !LIST_EMPTY(&mode_info->hot_upgrade)) {
7941 : 0 : DRV_LOG(ERR, "Port %u has rule cache with different flag %u\n",
7942 : : port, mode_info->mode_flag);
7943 : 0 : orig_mode = mode_info->mode;
7944 : 0 : orig_flags = mode_info->mode_flag;
7945 : 0 : goto err;
7946 : : }
7947 : 0 : mode_info->mode_flag = flags;
7948 : 0 : toggle_num++;
7949 : 0 : continue;
7950 : : }
7951 : : /* Active -> standby. */
7952 [ # # ]: 0 : if (mode == RTE_PMD_MLX5_FLOW_ENGINE_MODE_STANDBY) {
7953 [ # # ]: 0 : if (!LIST_EMPTY(&mode_info->hot_upgrade)) {
7954 : 0 : DRV_LOG(ERR, "Cached rule existed");
7955 : 0 : orig_mode = mode_info->mode;
7956 : 0 : orig_flags = mode_info->mode_flag;
7957 : 0 : goto err;
7958 : : }
7959 : 0 : mode_info->mode_flag = flags;
7960 : 0 : mode_info->mode = mode;
7961 : 0 : toggle_num++;
7962 : : /* Standby -> active. */
7963 [ # # ]: 0 : } else if (mode == RTE_PMD_MLX5_FLOW_ENGINE_MODE_ACTIVE) {
7964 [ # # ]: 0 : if (LIST_EMPTY(&mode_info->hot_upgrade)) {
7965 : 0 : DRV_LOG(INFO, "No cached rule existed");
7966 : : } else {
7967 [ # # ]: 0 : if (mlx5_flow_cache_flow_toggle(dev, true)) {
7968 : 0 : orig_mode = mode_info->mode;
7969 : 0 : orig_flags = mode_info->mode_flag;
7970 : : need_toggle = true;
7971 : 0 : goto err;
7972 : : }
7973 : : }
7974 : 0 : toggle_num++;
7975 : : }
7976 : : }
7977 [ # # ]: 0 : if (mode == RTE_PMD_MLX5_FLOW_ENGINE_MODE_ACTIVE) {
7978 : : /* Clear cache flow rules. */
7979 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port, NULL) {
7980 : 0 : priv = rte_eth_devices[port].data->dev_private;
7981 : : mode_info = &priv->mode_info;
7982 : 0 : flow_info = LIST_FIRST(&mode_info->hot_upgrade);
7983 [ # # ]: 0 : while (flow_info) {
7984 : 0 : tmp_info = LIST_NEXT(flow_info, next);
7985 [ # # ]: 0 : LIST_REMOVE(flow_info, next);
7986 : 0 : mlx5_free(flow_info->actions);
7987 : 0 : mlx5_free(flow_info->items);
7988 : 0 : mlx5_free(flow_info);
7989 : : flow_info = tmp_info;
7990 : : }
7991 : : MLX5_ASSERT(LIST_EMPTY(&mode_info->hot_upgrade));
7992 : : }
7993 : : }
7994 : 0 : return toggle_num;
7995 : 0 : err:
7996 : : /* Rollback all preceding successful ports. */
7997 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port_id, NULL) {
7998 [ # # ]: 0 : if (port_id == port)
7999 : : break;
8000 : 0 : priv = rte_eth_devices[port_id].data->dev_private;
8001 : : mode_info = &priv->mode_info;
8002 [ # # # # : 0 : if (need_toggle && !LIST_EMPTY(&mode_info->hot_upgrade) &&
# # ]
8003 : 0 : mlx5_flow_cache_flow_toggle(dev, false))
8004 : : return -EPERM;
8005 : 0 : mode_info->mode = orig_mode;
8006 : 0 : mode_info->mode_flag = orig_flags;
8007 : : }
8008 : : return -EINVAL;
8009 : : }
8010 : : /**
8011 : : * Create a flow.
8012 : : *
8013 : : * @see rte_flow_create()
8014 : : * @see rte_flow_ops
8015 : : */
8016 : : struct rte_flow *
8017 : 0 : mlx5_flow_create(struct rte_eth_dev *dev,
8018 : : const struct rte_flow_attr *attr,
8019 : : const struct rte_flow_item items[],
8020 : : const struct rte_flow_action actions[],
8021 : : struct rte_flow_error *error)
8022 : : {
8023 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8024 : : struct rte_flow_attr *new_attr = (void *)(uintptr_t)attr;
8025 : 0 : uint32_t prio = attr->priority;
8026 : : uintptr_t flow_idx;
8027 : :
8028 : : /*
8029 : : * If the device is not started yet, it is not allowed to created a
8030 : : * flow from application. PMD default flows and traffic control flows
8031 : : * are not affected.
8032 : : */
8033 [ # # ]: 0 : if (unlikely(!dev->data->dev_started)) {
8034 : 0 : DRV_LOG(DEBUG, "port %u is not started when "
8035 : : "inserting a flow", dev->data->port_id);
8036 : 0 : rte_flow_error_set(error, ENODEV,
8037 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8038 : : NULL,
8039 : : "port not started");
8040 : 0 : return NULL;
8041 : : }
8042 [ # # ]: 0 : if (unlikely(mlx5_need_cache_flow(priv, attr))) {
8043 [ # # ]: 0 : if (attr->transfer ||
8044 [ # # # # ]: 0 : (attr->ingress && !(priv->mode_info.mode_flag &
8045 : : RTE_PMD_MLX5_FLOW_ENGINE_FLAG_STANDBY_DUP_INGRESS)))
8046 : 0 : new_attr->priority += 1;
8047 : : }
8048 : 0 : flow_idx = mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_GEN, attr, items, actions,
8049 : : true, error);
8050 [ # # ]: 0 : if (!flow_idx)
8051 : : return NULL;
8052 [ # # ]: 0 : if (unlikely(mlx5_need_cache_flow(priv, attr))) {
8053 [ # # ]: 0 : if (mlx5_flow_cache_flow_info(dev, attr, prio, items, actions, flow_idx)) {
8054 : 0 : mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN, flow_idx);
8055 : : flow_idx = 0;
8056 : : }
8057 : : }
8058 : 0 : return (void *)(uintptr_t)flow_idx;
8059 : : }
8060 : :
8061 : : uintptr_t
8062 : 0 : mlx5_flow_list_create(struct rte_eth_dev *dev, enum mlx5_flow_type type,
8063 : : const struct rte_flow_attr *attr,
8064 : : const struct rte_flow_item items[],
8065 : : const struct rte_flow_action actions[],
8066 : : bool external, struct rte_flow_error *error)
8067 : : {
8068 : : const struct mlx5_flow_driver_ops *fops;
8069 : 0 : enum mlx5_flow_drv_type drv_type = flow_get_drv_type(dev, attr);
8070 : :
8071 : 0 : fops = flow_get_drv_ops(drv_type);
8072 : 0 : return fops->list_create(dev, type, attr, items, actions, external,
8073 : : error);
8074 : : }
8075 : :
8076 : : /**
8077 : : * Destroy a flow in a list.
8078 : : *
8079 : : * @param dev
8080 : : * Pointer to Ethernet device.
8081 : : * @param[in] flow_idx
8082 : : * Index of flow to destroy.
8083 : : */
8084 : : void
8085 : 0 : flow_legacy_list_destroy(struct rte_eth_dev *dev, enum mlx5_flow_type type,
8086 : : uintptr_t flow_idx)
8087 : : {
8088 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8089 : 0 : struct rte_flow *flow = mlx5_ipool_get(priv->flows[type], (uint32_t)flow_idx);
8090 : :
8091 [ # # ]: 0 : if (!flow)
8092 : : return;
8093 : : MLX5_ASSERT((type >= MLX5_FLOW_TYPE_CTL) && (type < MLX5_FLOW_TYPE_MAXI));
8094 : : MLX5_ASSERT(flow->type == type);
8095 : : /*
8096 : : * Update RX queue flags only if port is started, otherwise it is
8097 : : * already clean.
8098 : : */
8099 [ # # ]: 0 : if (dev->data->dev_started)
8100 : 0 : flow_rxq_flags_trim(dev, flow);
8101 : : flow_drv_destroy(dev, flow);
8102 [ # # ]: 0 : if (flow->tunnel) {
8103 : : struct mlx5_flow_tunnel *tunnel;
8104 : :
8105 : 0 : tunnel = mlx5_find_tunnel_id(dev, flow->tunnel_id);
8106 : 0 : RTE_VERIFY(tunnel);
8107 [ # # ]: 0 : if (!(rte_atomic_fetch_sub_explicit(&tunnel->refctn, 1,
8108 : : rte_memory_order_relaxed) - 1))
8109 : 0 : mlx5_flow_tunnel_free(dev, tunnel);
8110 : : }
8111 : 0 : flow_mreg_del_copy_action(dev, flow);
8112 : 0 : mlx5_ipool_free(priv->flows[type], flow_idx);
8113 : : }
8114 : :
8115 : : void
8116 [ # # ]: 0 : mlx5_flow_list_destroy(struct rte_eth_dev *dev, enum mlx5_flow_type type,
8117 : : uintptr_t flow_idx)
8118 : : {
8119 : : const struct mlx5_flow_driver_ops *fops;
8120 : : struct rte_flow_attr attr = { .transfer = 0 };
8121 : : enum mlx5_flow_drv_type drv_type = flow_get_drv_type(dev, &attr);
8122 : :
8123 : 0 : fops = flow_get_drv_ops(drv_type);
8124 : 0 : fops->list_destroy(dev, type, flow_idx);
8125 : 0 : }
8126 : :
8127 : : /**
8128 : : * Destroy all flows.
8129 : : *
8130 : : * @param dev
8131 : : * Pointer to Ethernet device.
8132 : : * @param type
8133 : : * Flow type to be flushed.
8134 : : * @param active
8135 : : * If flushing is called actively.
8136 : : */
8137 : : void
8138 : 0 : mlx5_flow_list_flush(struct rte_eth_dev *dev, enum mlx5_flow_type type,
8139 : : bool active)
8140 : : {
8141 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8142 : 0 : uint32_t num_flushed = 0, fidx = 1;
8143 : : struct rte_flow *flow;
8144 : : struct rte_pmd_mlx5_flow_engine_mode_info *mode_info = &priv->mode_info;
8145 : : struct mlx5_dv_flow_info *flow_info;
8146 : :
8147 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8148 [ # # # # ]: 0 : if (priv->sh->config.dv_flow_en == 2 &&
8149 : : type == MLX5_FLOW_TYPE_GEN) {
8150 : 0 : priv->hws_rule_flushing = true;
8151 : 0 : flow_hw_q_flow_flush(dev, NULL);
8152 : 0 : priv->hws_rule_flushing = false;
8153 : : }
8154 : : #endif
8155 [ # # ]: 0 : MLX5_IPOOL_FOREACH(priv->flows[type], fidx, flow) {
8156 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2) {
8157 : 0 : mlx5_flow_list_destroy(dev, type, (uintptr_t)flow);
8158 : : } else {
8159 : 0 : mlx5_flow_list_destroy(dev, type, fidx);
8160 : : }
8161 [ # # # # ]: 0 : if (unlikely(mlx5_need_cache_flow(priv, NULL) && type == MLX5_FLOW_TYPE_GEN)) {
8162 : 0 : flow_info = LIST_FIRST(&mode_info->hot_upgrade);
8163 [ # # ]: 0 : while (flow_info) {
8164 : : /* Romove the cache flow info. */
8165 [ # # ]: 0 : if (flow_info->flow_idx_low_prio == (uint32_t)(uintptr_t)fidx) {
8166 : : MLX5_ASSERT(!flow_info->flow_idx_high_prio);
8167 [ # # ]: 0 : LIST_REMOVE(flow_info, next);
8168 : 0 : mlx5_free(flow_info->items);
8169 : 0 : mlx5_free(flow_info->actions);
8170 : 0 : mlx5_free(flow_info);
8171 : 0 : break;
8172 : : }
8173 : 0 : flow_info = LIST_NEXT(flow_info, next);
8174 : : }
8175 : : }
8176 : 0 : num_flushed++;
8177 : : }
8178 [ # # ]: 0 : if (active) {
8179 : 0 : DRV_LOG(INFO, "port %u: %u flows flushed before stopping",
8180 : : dev->data->port_id, num_flushed);
8181 : : }
8182 : 0 : }
8183 : :
8184 : : /**
8185 : : * Stop all default actions for flows.
8186 : : *
8187 : : * @param dev
8188 : : * Pointer to Ethernet device.
8189 : : */
8190 : : void
8191 : 0 : mlx5_flow_stop_default(struct rte_eth_dev *dev)
8192 : : {
8193 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8194 : :
8195 [ # # ]: 0 : if (mlx5_flow_is_steering_disabled())
8196 : : return;
8197 : :
8198 : : #ifdef HAVE_MLX5_HWS_SUPPORT
8199 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2) {
8200 : 0 : mlx5_flow_nta_del_default_copy_action(dev);
8201 [ # # ]: 0 : if (!rte_atomic_load_explicit(&priv->hws_mark_refcnt,
8202 : : rte_memory_order_relaxed))
8203 : 0 : flow_hw_rxq_flag_set(dev, false);
8204 : 0 : return;
8205 : : }
8206 : : #else
8207 : : RTE_SET_USED(priv);
8208 : : #endif
8209 : 0 : flow_mreg_del_default_copy_action(dev);
8210 : 0 : mlx5_flow_rxq_flags_clear(dev);
8211 : : }
8212 : :
8213 : : /**
8214 : : * Set rxq flag.
8215 : : *
8216 : : * @param[in] dev
8217 : : * Pointer to the rte_eth_dev structure.
8218 : : * @param[in] enable
8219 : : * Flag to enable or not.
8220 : : */
8221 : : void
8222 : 0 : flow_hw_rxq_flag_set(struct rte_eth_dev *dev, bool enable)
8223 : : {
8224 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8225 : : unsigned int i;
8226 : :
8227 [ # # # # : 0 : if ((!priv->mark_enabled && !enable) ||
# # ]
8228 [ # # ]: 0 : (priv->mark_enabled && enable))
8229 : : return;
8230 [ # # ]: 0 : for (i = 0; i < priv->rxqs_n; ++i) {
8231 : 0 : struct mlx5_rxq_ctrl *rxq_ctrl = mlx5_rxq_ctrl_get(dev, i);
8232 : :
8233 : : /* With RXQ start/stop feature, RXQ might be stopped. */
8234 [ # # ]: 0 : if (!rxq_ctrl)
8235 : 0 : continue;
8236 : 0 : rxq_ctrl->rxq.mark = enable;
8237 : : }
8238 : 0 : priv->mark_enabled = enable;
8239 : : }
8240 : :
8241 : : /**
8242 : : * Start all default actions for flows.
8243 : : *
8244 : : * @param dev
8245 : : * Pointer to Ethernet device.
8246 : : * @return
8247 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
8248 : : */
8249 : : int
8250 : 0 : mlx5_flow_start_default(struct rte_eth_dev *dev)
8251 : : {
8252 : : struct rte_flow_error error;
8253 : :
8254 [ # # ]: 0 : if (mlx5_flow_is_steering_disabled())
8255 : : return 0;
8256 : :
8257 : : #ifdef HAVE_MLX5_HWS_SUPPORT
8258 [ # # ]: 0 : if (MLX5_SH(dev)->config.dv_flow_en == 2) {
8259 : : /*
8260 : : * Ignore this failure, if the proxy port is not started, other
8261 : : * default jump actions are not created and this rule will not
8262 : : * be hit.
8263 : : */
8264 [ # # ]: 0 : if (mlx5_flow_nta_add_default_copy_action(dev, &error)) {
8265 : 0 : DRV_LOG(DEBUG, "port %u failed to start default copy action: %s",
8266 : : dev->data->port_id, strerror(rte_errno));
8267 : 0 : return 0;
8268 : : }
8269 : : }
8270 : : #endif
8271 : : /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
8272 : 0 : return flow_mreg_add_default_copy_action(dev, &error);
8273 : : }
8274 : :
8275 : : /**
8276 : : * Release key of thread specific flow workspace data.
8277 : : */
8278 : : void
8279 : 0 : flow_release_workspace(void *data)
8280 : : {
8281 : : struct mlx5_flow_workspace *wks = data;
8282 : : struct mlx5_flow_workspace *next;
8283 : :
8284 [ # # ]: 0 : while (wks) {
8285 : 0 : next = wks->next;
8286 : 0 : free(wks);
8287 : : wks = next;
8288 : : }
8289 : 0 : }
8290 : :
8291 : : /**
8292 : : * Get thread specific current flow workspace.
8293 : : *
8294 : : * @return pointer to thread specific flow workspace data, NULL on error.
8295 : : */
8296 : : struct mlx5_flow_workspace*
8297 : 0 : mlx5_flow_get_thread_workspace(void)
8298 : : {
8299 : : struct mlx5_flow_workspace *data;
8300 : :
8301 : 0 : data = mlx5_flow_os_get_specific_workspace();
8302 : : MLX5_ASSERT(data && data->inuse);
8303 [ # # # # ]: 0 : if (!data || !data->inuse)
8304 : 0 : DRV_LOG(ERR, "flow workspace not initialized.");
8305 : 0 : return data;
8306 : : }
8307 : :
8308 : : /**
8309 : : * Allocate and init new flow workspace.
8310 : : *
8311 : : * @return pointer to flow workspace data, NULL on error.
8312 : : */
8313 : : static struct mlx5_flow_workspace*
8314 : 0 : flow_alloc_thread_workspace(void)
8315 : : {
8316 : : size_t data_size = RTE_ALIGN(sizeof(struct mlx5_flow_workspace), sizeof(long));
8317 : : size_t rss_queue_array_size = sizeof(uint16_t) * RTE_ETH_RSS_RETA_SIZE_512;
8318 : : size_t alloc_size = data_size + rss_queue_array_size;
8319 : : #ifdef HAVE_MLX5_HWS_SUPPORT
8320 : : /* Dummy table size for the non-template API. */
8321 : : alloc_size += sizeof(struct rte_flow_template_table);
8322 : : #endif
8323 : 0 : struct mlx5_flow_workspace *data = calloc(1, alloc_size);
8324 : :
8325 [ # # ]: 0 : if (!data) {
8326 : 0 : DRV_LOG(ERR, "Failed to allocate flow workspace memory.");
8327 : 0 : return NULL;
8328 : : }
8329 : 0 : data->rss_desc.queue = RTE_PTR_ADD(data, data_size);
8330 : : #ifdef HAVE_MLX5_HWS_SUPPORT
8331 : 0 : data->table = RTE_PTR_ADD(data->rss_desc.queue, rss_queue_array_size);
8332 : : #endif
8333 : 0 : return data;
8334 : : }
8335 : :
8336 : : /**
8337 : : * Get new thread specific flow workspace.
8338 : : *
8339 : : * If current workspace inuse, create new one and set as current.
8340 : : *
8341 : : * @return pointer to thread specific flow workspace data, NULL on error.
8342 : : */
8343 : : struct mlx5_flow_workspace*
8344 : 0 : mlx5_flow_push_thread_workspace(void)
8345 : : {
8346 : : struct mlx5_flow_workspace *curr;
8347 : : struct mlx5_flow_workspace *data;
8348 : :
8349 : 0 : curr = mlx5_flow_os_get_specific_workspace();
8350 [ # # ]: 0 : if (!curr) {
8351 : 0 : data = flow_alloc_thread_workspace();
8352 [ # # ]: 0 : if (!data)
8353 : : return NULL;
8354 : 0 : mlx5_flow_os_workspace_gc_add(data);
8355 [ # # ]: 0 : } else if (!curr->inuse) {
8356 : : data = curr;
8357 [ # # ]: 0 : } else if (curr->next) {
8358 : : data = curr->next;
8359 : : } else {
8360 : 0 : data = flow_alloc_thread_workspace();
8361 [ # # ]: 0 : if (!data)
8362 : : return NULL;
8363 : 0 : curr->next = data;
8364 : 0 : data->prev = curr;
8365 : : }
8366 : 0 : data->inuse = 1;
8367 : 0 : data->flow_idx = 0;
8368 : : /* Set as current workspace */
8369 [ # # ]: 0 : if (mlx5_flow_os_set_specific_workspace(data))
8370 : 0 : DRV_LOG(ERR, "Failed to set flow workspace to thread.");
8371 : : return data;
8372 : : }
8373 : :
8374 : : /**
8375 : : * Close current thread specific flow workspace.
8376 : : *
8377 : : * If previous workspace available, set it as current.
8378 : : *
8379 : : * @return pointer to thread specific flow workspace data, NULL on error.
8380 : : */
8381 : : void
8382 : 0 : mlx5_flow_pop_thread_workspace(void)
8383 : : {
8384 : 0 : struct mlx5_flow_workspace *data = mlx5_flow_get_thread_workspace();
8385 : :
8386 [ # # ]: 0 : if (!data)
8387 : : return;
8388 [ # # ]: 0 : if (!data->inuse) {
8389 : 0 : DRV_LOG(ERR, "Failed to close unused flow workspace.");
8390 : 0 : return;
8391 : : }
8392 : 0 : data->inuse = 0;
8393 [ # # ]: 0 : if (!data->prev)
8394 : : return;
8395 [ # # ]: 0 : if (mlx5_flow_os_set_specific_workspace(data->prev))
8396 : 0 : DRV_LOG(ERR, "Failed to set flow workspace to thread.");
8397 : : }
8398 : :
8399 : : /**
8400 : : * Verify the flow list is empty
8401 : : *
8402 : : * @param dev
8403 : : * Pointer to Ethernet device.
8404 : : *
8405 : : * @return the number of flows not released.
8406 : : */
8407 : : int
8408 : 0 : mlx5_flow_verify(struct rte_eth_dev *dev __rte_unused)
8409 : : {
8410 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8411 : : struct rte_flow *flow;
8412 : : uint32_t idx = 0;
8413 : : int ret = 0, i;
8414 : :
8415 [ # # ]: 0 : for (i = 0; i < MLX5_FLOW_TYPE_MAXI; i++) {
8416 [ # # ]: 0 : MLX5_IPOOL_FOREACH(priv->flows[i], idx, flow) {
8417 : 0 : DRV_LOG(DEBUG, "port %u flow %p still referenced",
8418 : : dev->data->port_id, (void *)flow);
8419 : 0 : ret++;
8420 : : }
8421 : : }
8422 : 0 : return ret;
8423 : : }
8424 : :
8425 : : /**
8426 : : * Enable default hairpin egress flow.
8427 : : *
8428 : : * @param dev
8429 : : * Pointer to Ethernet device.
8430 : : * @param sq_num
8431 : : * The SQ hw number.
8432 : : *
8433 : : * @return
8434 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
8435 : : */
8436 : : int
8437 : 0 : mlx5_ctrl_flow_source_queue(struct rte_eth_dev *dev,
8438 : : uint32_t sq_num)
8439 : : {
8440 : 0 : const struct rte_flow_attr attr = {
8441 : : .egress = 1,
8442 : : .priority = 0,
8443 : : };
8444 : 0 : struct mlx5_rte_flow_item_sq queue_spec = {
8445 : : .queue = sq_num,
8446 : : };
8447 : 0 : struct mlx5_rte_flow_item_sq queue_mask = {
8448 : : .queue = UINT32_MAX,
8449 : : };
8450 : 0 : struct rte_flow_item items[] = {
8451 : : {
8452 : : .type = (enum rte_flow_item_type)
8453 : : MLX5_RTE_FLOW_ITEM_TYPE_SQ,
8454 : : .spec = &queue_spec,
8455 : : .last = NULL,
8456 : : .mask = &queue_mask,
8457 : : },
8458 : : {
8459 : : .type = RTE_FLOW_ITEM_TYPE_END,
8460 : : },
8461 : : };
8462 : 0 : struct rte_flow_action_jump jump = {
8463 : : .group = MLX5_HAIRPIN_TX_TABLE,
8464 : : };
8465 : : struct rte_flow_action actions[2];
8466 : : uint32_t flow_idx;
8467 : : struct rte_flow_error error;
8468 : :
8469 : 0 : actions[0].type = RTE_FLOW_ACTION_TYPE_JUMP;
8470 : 0 : actions[0].conf = &jump;
8471 : 0 : actions[1].type = RTE_FLOW_ACTION_TYPE_END;
8472 : 0 : flow_idx = mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
8473 : : &attr, items, actions, false, &error);
8474 [ # # ]: 0 : if (!flow_idx) {
8475 [ # # ]: 0 : DRV_LOG(DEBUG,
8476 : : "Failed to create ctrl flow: rte_errno(%d),"
8477 : : " type(%d), message(%s)",
8478 : : rte_errno, error.type,
8479 : : error.message ? error.message : " (no stated reason)");
8480 : 0 : return -rte_errno;
8481 : : }
8482 : : return 0;
8483 : : }
8484 : :
8485 : : /**
8486 : : * Enable a control flow configured from the control plane.
8487 : : *
8488 : : * @param dev
8489 : : * Pointer to Ethernet device.
8490 : : * @param eth_spec
8491 : : * An Ethernet flow spec to apply.
8492 : : * @param eth_mask
8493 : : * An Ethernet flow mask to apply.
8494 : : * @param vlan_spec
8495 : : * A VLAN flow spec to apply.
8496 : : * @param vlan_mask
8497 : : * A VLAN flow mask to apply.
8498 : : *
8499 : : * @return
8500 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
8501 : : */
8502 : : int
8503 : 0 : mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
8504 : : struct rte_flow_item_eth *eth_spec,
8505 : : struct rte_flow_item_eth *eth_mask,
8506 : : struct rte_flow_item_vlan *vlan_spec,
8507 : : struct rte_flow_item_vlan *vlan_mask)
8508 : : {
8509 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8510 : 0 : const struct rte_flow_attr attr = {
8511 : : .ingress = 1,
8512 : : .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
8513 : : };
8514 : 0 : struct rte_flow_item items[] = {
8515 : : {
8516 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
8517 : : .spec = eth_spec,
8518 : : .last = NULL,
8519 : : .mask = eth_mask,
8520 : : },
8521 : : {
8522 [ # # ]: 0 : .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
8523 : : RTE_FLOW_ITEM_TYPE_END,
8524 : : .spec = vlan_spec,
8525 : : .last = NULL,
8526 : : .mask = vlan_mask,
8527 : : },
8528 : : {
8529 : : .type = RTE_FLOW_ITEM_TYPE_END,
8530 : : },
8531 : : };
8532 : 0 : uint16_t *queue = alloca(sizeof(uint16_t) * priv->reta_idx_n);
8533 : 0 : struct rte_flow_action_rss action_rss = {
8534 : : .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
8535 : : .level = 0,
8536 : 0 : .types = priv->rss_conf.rss_hf,
8537 : 0 : .key_len = priv->rss_conf.rss_key_len,
8538 : : .queue_num = priv->reta_idx_n,
8539 : 0 : .key = priv->rss_conf.rss_key,
8540 : : .queue = queue,
8541 : : };
8542 : 0 : struct rte_flow_action actions[] = {
8543 : : {
8544 : : .type = RTE_FLOW_ACTION_TYPE_RSS,
8545 : : .conf = &action_rss,
8546 : : },
8547 : : {
8548 : : .type = RTE_FLOW_ACTION_TYPE_END,
8549 : : },
8550 : : };
8551 : : uintptr_t flow_idx;
8552 : : struct rte_flow_error error;
8553 : : struct mlx5_ctrl_flow_entry *entry;
8554 : : unsigned int i;
8555 : :
8556 [ # # # # ]: 0 : if (!priv->reta_idx_n || !priv->rxqs_n) {
8557 : : return 0;
8558 : : }
8559 [ # # ]: 0 : if (!(dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG))
8560 : 0 : action_rss.types = 0;
8561 [ # # ]: 0 : for (i = 0; i != priv->reta_idx_n; ++i)
8562 : 0 : queue[i] = (*priv->reta_idx)[i];
8563 : :
8564 : 0 : entry = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*entry), alignof(typeof(*entry)), SOCKET_ID_ANY);
8565 [ # # ]: 0 : if (entry == NULL) {
8566 : 0 : rte_errno = ENOMEM;
8567 : 0 : goto err;
8568 : : }
8569 : :
8570 : 0 : entry->owner_dev = dev;
8571 [ # # ]: 0 : if (vlan_spec == NULL) {
8572 : 0 : entry->info.type = MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC;
8573 : : } else {
8574 : 0 : entry->info.type = MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC_VLAN;
8575 [ # # ]: 0 : entry->info.uc.vlan = rte_be_to_cpu_16(vlan_spec->hdr.vlan_tci);
8576 : : }
8577 : 0 : entry->info.uc.dmac = eth_spec->hdr.dst_addr;
8578 : :
8579 : 0 : flow_idx = mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
8580 : : &attr, items, actions, false, &error);
8581 [ # # ]: 0 : if (!flow_idx) {
8582 : 0 : mlx5_free(entry);
8583 : 0 : goto err;
8584 : : }
8585 : :
8586 : 0 : entry->flow = (struct rte_flow *)flow_idx;
8587 [ # # ]: 0 : LIST_INSERT_HEAD(&priv->hw_ctrl_flows, entry, next);
8588 : :
8589 : 0 : return 0;
8590 : :
8591 : 0 : err:
8592 : 0 : return -rte_errno;
8593 : : }
8594 : :
8595 : : /**
8596 : : * Enable a flow control configured from the control plane.
8597 : : *
8598 : : * @param dev
8599 : : * Pointer to Ethernet device.
8600 : : * @param eth_spec
8601 : : * An Ethernet flow spec to apply.
8602 : : * @param eth_mask
8603 : : * An Ethernet flow mask to apply.
8604 : : *
8605 : : * @return
8606 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
8607 : : */
8608 : : int
8609 : 0 : mlx5_ctrl_flow(struct rte_eth_dev *dev,
8610 : : struct rte_flow_item_eth *eth_spec,
8611 : : struct rte_flow_item_eth *eth_mask)
8612 : : {
8613 : 0 : return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
8614 : : }
8615 : :
8616 : : int
8617 : 0 : mlx5_legacy_dmac_flow_create(struct rte_eth_dev *dev, const struct rte_ether_addr *addr)
8618 : : {
8619 : 0 : struct rte_flow_item_eth unicast = {
8620 : : .hdr.dst_addr = *addr,
8621 : : };
8622 : 0 : struct rte_flow_item_eth unicast_mask = {
8623 : : .hdr.dst_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
8624 : : };
8625 : :
8626 : 0 : return mlx5_ctrl_flow(dev, &unicast, &unicast_mask);
8627 : : }
8628 : :
8629 : : int
8630 : 0 : mlx5_legacy_dmac_vlan_flow_create(struct rte_eth_dev *dev,
8631 : : const struct rte_ether_addr *addr,
8632 : : const uint16_t vid)
8633 : : {
8634 : 0 : struct rte_flow_item_eth unicast_spec = {
8635 : : .hdr.dst_addr = *addr,
8636 : : };
8637 : 0 : struct rte_flow_item_eth unicast_mask = {
8638 : : .hdr.dst_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
8639 : : };
8640 : 0 : struct rte_flow_item_vlan vlan_spec = {
8641 [ # # ]: 0 : .hdr.vlan_tci = rte_cpu_to_be_16(vid),
8642 : : };
8643 : 0 : struct rte_flow_item_vlan vlan_mask = rte_flow_item_vlan_mask;
8644 : :
8645 : 0 : return mlx5_ctrl_flow_vlan(dev, &unicast_spec, &unicast_mask, &vlan_spec, &vlan_mask);
8646 : : }
8647 : :
8648 : : void
8649 : 0 : mlx5_legacy_ctrl_flow_destroy(struct rte_eth_dev *dev, struct mlx5_ctrl_flow_entry *entry)
8650 : : {
8651 : : uintptr_t flow_idx;
8652 : :
8653 : 0 : flow_idx = (uintptr_t)entry->flow;
8654 : 0 : mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_CTL, flow_idx);
8655 [ # # ]: 0 : LIST_REMOVE(entry, next);
8656 : 0 : mlx5_free(entry);
8657 : 0 : }
8658 : :
8659 : : int
8660 : 0 : mlx5_legacy_dmac_flow_destroy(struct rte_eth_dev *dev, const struct rte_ether_addr *addr)
8661 : : {
8662 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8663 : : struct mlx5_ctrl_flow_entry *entry;
8664 : :
8665 [ # # ]: 0 : LIST_FOREACH(entry, &priv->hw_ctrl_flows, next) {
8666 [ # # # # ]: 0 : if (entry->info.type != MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC ||
8667 : : !rte_is_same_ether_addr(addr, &entry->info.uc.dmac))
8668 : : continue;
8669 : :
8670 : 0 : mlx5_legacy_ctrl_flow_destroy(dev, entry);
8671 : 0 : return 0;
8672 : : }
8673 : : return 0;
8674 : : }
8675 : :
8676 : : int
8677 : 0 : mlx5_legacy_dmac_vlan_flow_destroy(struct rte_eth_dev *dev,
8678 : : const struct rte_ether_addr *addr,
8679 : : const uint16_t vid)
8680 : : {
8681 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8682 : : struct mlx5_ctrl_flow_entry *entry;
8683 : :
8684 [ # # ]: 0 : LIST_FOREACH(entry, &priv->hw_ctrl_flows, next) {
8685 [ # # # # ]: 0 : if (entry->info.type != MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC_VLAN ||
8686 : 0 : !rte_is_same_ether_addr(addr, &entry->info.uc.dmac) ||
8687 [ # # ]: 0 : vid != entry->info.uc.vlan)
8688 : : continue;
8689 : :
8690 : 0 : mlx5_legacy_ctrl_flow_destroy(dev, entry);
8691 : 0 : return 0;
8692 : : }
8693 : : return 0;
8694 : : }
8695 : :
8696 : : /**
8697 : : * Create default miss flow rule matching lacp traffic
8698 : : *
8699 : : * @param dev
8700 : : * Pointer to Ethernet device.
8701 : : * @param eth_spec
8702 : : * An Ethernet flow spec to apply.
8703 : : *
8704 : : * @return
8705 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
8706 : : */
8707 : : int
8708 : 0 : mlx5_flow_lacp_miss(struct rte_eth_dev *dev)
8709 : : {
8710 : : /*
8711 : : * The LACP matching is done by only using ether type since using
8712 : : * a multicast dst mac causes kernel to give low priority to this flow.
8713 : : */
8714 : : static const struct rte_flow_item_eth lacp_spec = {
8715 : : .hdr.ether_type = RTE_BE16(0x8809),
8716 : : };
8717 : : static const struct rte_flow_item_eth lacp_mask = {
8718 : : .hdr.ether_type = 0xffff,
8719 : : };
8720 : 0 : const struct rte_flow_attr attr = {
8721 : : .ingress = 1,
8722 : : };
8723 : 0 : struct rte_flow_item items[] = {
8724 : : {
8725 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
8726 : : .spec = &lacp_spec,
8727 : : .mask = &lacp_mask,
8728 : : },
8729 : : {
8730 : : .type = RTE_FLOW_ITEM_TYPE_END,
8731 : : },
8732 : : };
8733 : 0 : struct rte_flow_action actions[] = {
8734 : : {
8735 : : .type = (enum rte_flow_action_type)
8736 : : MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
8737 : : },
8738 : : {
8739 : : .type = RTE_FLOW_ACTION_TYPE_END,
8740 : : },
8741 : : };
8742 : : struct rte_flow_error error;
8743 : 0 : uint32_t flow_idx = mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
8744 : : &attr, items, actions,
8745 : : false, &error);
8746 : :
8747 [ # # ]: 0 : if (!flow_idx)
8748 : 0 : return -rte_errno;
8749 : : return 0;
8750 : : }
8751 : :
8752 : : /**
8753 : : * Destroy a flow.
8754 : : *
8755 : : * @see rte_flow_destroy()
8756 : : * @see rte_flow_ops
8757 : : */
8758 : : int
8759 : 0 : mlx5_flow_destroy(struct rte_eth_dev *dev,
8760 : : struct rte_flow *flow,
8761 : : struct rte_flow_error *error __rte_unused)
8762 : : {
8763 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8764 : : struct rte_pmd_mlx5_flow_engine_mode_info *mode_info = &priv->mode_info;
8765 : : struct mlx5_dv_flow_info *flow_info;
8766 : :
8767 : 0 : mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN,
8768 : : (uintptr_t)(void *)flow);
8769 [ # # ]: 0 : if (unlikely(mlx5_need_cache_flow(priv, NULL))) {
8770 : 0 : flow_info = LIST_FIRST(&mode_info->hot_upgrade);
8771 [ # # ]: 0 : while (flow_info) {
8772 : : /* Romove the cache flow info. */
8773 [ # # ]: 0 : if (flow_info->flow_idx_low_prio == (uint32_t)(uintptr_t)flow) {
8774 : : MLX5_ASSERT(!flow_info->flow_idx_high_prio);
8775 [ # # ]: 0 : LIST_REMOVE(flow_info, next);
8776 : 0 : mlx5_free(flow_info->items);
8777 : 0 : mlx5_free(flow_info->actions);
8778 : 0 : mlx5_free(flow_info);
8779 : 0 : break;
8780 : : }
8781 : 0 : flow_info = LIST_NEXT(flow_info, next);
8782 : : }
8783 : : }
8784 : 0 : return 0;
8785 : : }
8786 : :
8787 : : /**
8788 : : * Destroy all flows.
8789 : : *
8790 : : * @see rte_flow_flush()
8791 : : * @see rte_flow_ops
8792 : : */
8793 : : int
8794 : 0 : mlx5_flow_flush(struct rte_eth_dev *dev,
8795 : : struct rte_flow_error *error __rte_unused)
8796 : : {
8797 : 0 : mlx5_flow_list_flush(dev, MLX5_FLOW_TYPE_GEN, false);
8798 : 0 : return 0;
8799 : : }
8800 : :
8801 : : /**
8802 : : * Isolated mode.
8803 : : *
8804 : : * @see rte_flow_isolate()
8805 : : * @see rte_flow_ops
8806 : : */
8807 : : int
8808 : 0 : mlx5_flow_isolate(struct rte_eth_dev *dev,
8809 : : int enable,
8810 : : struct rte_flow_error *error)
8811 : : {
8812 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8813 : :
8814 [ # # ]: 0 : if (dev->data->dev_started) {
8815 : 0 : rte_flow_error_set(error, EBUSY,
8816 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8817 : : NULL,
8818 : : "port must be stopped first");
8819 : 0 : return -rte_errno;
8820 : : }
8821 : :
8822 : 0 : priv->isolated = !!enable;
8823 [ # # ]: 0 : if (enable)
8824 : 0 : dev->dev_ops = &mlx5_dev_ops_isolate;
8825 : : else
8826 : 0 : dev->dev_ops = &mlx5_dev_ops;
8827 : :
8828 : 0 : dev->rx_descriptor_status = mlx5_rx_descriptor_status;
8829 : 0 : dev->tx_descriptor_status = mlx5_tx_descriptor_status;
8830 : :
8831 : 0 : return 0;
8832 : : }
8833 : :
8834 : : /**
8835 : : * Query a flow.
8836 : : *
8837 : : * @see rte_flow_query()
8838 : : * @see rte_flow_ops
8839 : : */
8840 : : static int
8841 : 0 : flow_drv_query(struct rte_eth_dev *dev,
8842 : : struct rte_flow *eflow,
8843 : : const struct rte_flow_action *actions,
8844 : : void *data,
8845 : : struct rte_flow_error *error)
8846 : : {
8847 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8848 : : const struct mlx5_flow_driver_ops *fops;
8849 : : struct rte_flow *flow = NULL;
8850 : : enum mlx5_flow_drv_type ftype = MLX5_FLOW_TYPE_MIN;
8851 : :
8852 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2) {
8853 : : #ifdef HAVE_MLX5_HWS_SUPPORT
8854 : : flow = eflow;
8855 : : ftype = MLX5_FLOW_TYPE_HW;
8856 : : #endif
8857 : : } else {
8858 : 0 : flow = (struct rte_flow *)mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
8859 : : (uintptr_t)(void *)eflow);
8860 : : }
8861 [ # # ]: 0 : if (!flow) {
8862 : 0 : return rte_flow_error_set(error, ENOENT,
8863 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8864 : : NULL,
8865 : : "invalid flow handle");
8866 : : }
8867 [ # # ]: 0 : if (ftype == MLX5_FLOW_TYPE_MIN)
8868 : 0 : ftype = flow->drv_type;
8869 : : MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX);
8870 : 0 : fops = flow_get_drv_ops(ftype);
8871 : :
8872 : 0 : return fops->query(dev, flow, actions, data, error);
8873 : : }
8874 : :
8875 : : /**
8876 : : * Query a flow.
8877 : : *
8878 : : * @see rte_flow_query()
8879 : : * @see rte_flow_ops
8880 : : */
8881 : : int
8882 : 0 : mlx5_flow_query(struct rte_eth_dev *dev,
8883 : : struct rte_flow *flow,
8884 : : const struct rte_flow_action *actions,
8885 : : void *data,
8886 : : struct rte_flow_error *error)
8887 : : {
8888 : : int ret;
8889 : :
8890 : 0 : ret = flow_drv_query(dev, flow, actions, data,
8891 : : error);
8892 : : if (ret < 0)
8893 : : return ret;
8894 : : return 0;
8895 : : }
8896 : :
8897 : : /**
8898 : : * Get rte_flow callbacks.
8899 : : *
8900 : : * @param dev
8901 : : * Pointer to Ethernet device structure.
8902 : : * @param ops
8903 : : * Pointer to operation-specific structure.
8904 : : *
8905 : : * @return 0
8906 : : */
8907 : : int
8908 : 0 : mlx5_flow_ops_get(struct rte_eth_dev *dev __rte_unused,
8909 : : const struct rte_flow_ops **ops)
8910 : : {
8911 [ # # ]: 0 : if (mlx5_flow_is_steering_disabled()) {
8912 : 0 : DRV_LOG(WARNING, "port %u flow API is not supported since steering was disabled",
8913 : : dev->data->port_id);
8914 : 0 : *ops = NULL;
8915 : 0 : return 0;
8916 : : }
8917 : :
8918 : 0 : *ops = &mlx5_flow_ops;
8919 : 0 : return 0;
8920 : : }
8921 : :
8922 : : /**
8923 : : * Validate meter policy actions.
8924 : : * Dispatcher for action type specific validation.
8925 : : *
8926 : : * @param[in] dev
8927 : : * Pointer to the Ethernet device structure.
8928 : : * @param[in] action
8929 : : * The meter policy action object to validate.
8930 : : * @param[in] attr
8931 : : * Attributes of flow to determine steering domain.
8932 : : * @param[out] is_rss
8933 : : * Is RSS or not.
8934 : : * @param[out] domain_bitmap
8935 : : * Domain bitmap.
8936 : : * @param[out] is_def_policy
8937 : : * Is default policy or not.
8938 : : * @param[out] error
8939 : : * Perform verbose error reporting if not NULL. Initialized in case of
8940 : : * error only.
8941 : : *
8942 : : * @return
8943 : : * 0 on success, otherwise negative errno value.
8944 : : */
8945 : : int
8946 : 0 : mlx5_flow_validate_mtr_acts(struct rte_eth_dev *dev,
8947 : : const struct rte_flow_action *actions[RTE_COLORS],
8948 : : struct rte_flow_attr *attr,
8949 : : bool *is_rss,
8950 : : uint8_t *domain_bitmap,
8951 : : uint8_t *policy_mode,
8952 : : struct rte_mtr_error *error)
8953 : : {
8954 : : const struct mlx5_flow_driver_ops *fops;
8955 : :
8956 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
8957 : 0 : return fops->validate_mtr_acts(dev, actions, attr, is_rss,
8958 : : domain_bitmap, policy_mode, error);
8959 : : }
8960 : :
8961 : : /**
8962 : : * Destroy the meter table set.
8963 : : *
8964 : : * @param[in] dev
8965 : : * Pointer to Ethernet device.
8966 : : * @param[in] mtr_policy
8967 : : * Meter policy struct.
8968 : : */
8969 : : void
8970 : 0 : mlx5_flow_destroy_mtr_acts(struct rte_eth_dev *dev,
8971 : : struct mlx5_flow_meter_policy *mtr_policy)
8972 : : {
8973 : : const struct mlx5_flow_driver_ops *fops;
8974 : :
8975 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
8976 : 0 : fops->destroy_mtr_acts(dev, mtr_policy);
8977 : 0 : }
8978 : :
8979 : : /**
8980 : : * Create policy action, lock free,
8981 : : * (mutex should be acquired by caller).
8982 : : * Dispatcher for action type specific call.
8983 : : *
8984 : : * @param[in] dev
8985 : : * Pointer to the Ethernet device structure.
8986 : : * @param[in] mtr_policy
8987 : : * Meter policy struct.
8988 : : * @param[in] action
8989 : : * Action specification used to create meter actions.
8990 : : * @param[in] attr
8991 : : * Flow rule attributes.
8992 : : * @param[out] error
8993 : : * Perform verbose error reporting if not NULL. Initialized in case of
8994 : : * error only.
8995 : : *
8996 : : * @return
8997 : : * 0 on success, otherwise negative errno value.
8998 : : */
8999 : : int
9000 : 0 : mlx5_flow_create_mtr_acts(struct rte_eth_dev *dev,
9001 : : struct mlx5_flow_meter_policy *mtr_policy,
9002 : : const struct rte_flow_action *actions[RTE_COLORS],
9003 : : struct rte_flow_attr *attr,
9004 : : struct rte_mtr_error *error)
9005 : : {
9006 : : const struct mlx5_flow_driver_ops *fops;
9007 : :
9008 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9009 : 0 : return fops->create_mtr_acts(dev, mtr_policy, actions, attr, error);
9010 : : }
9011 : :
9012 : : /**
9013 : : * Create policy rules, lock free,
9014 : : * (mutex should be acquired by caller).
9015 : : * Dispatcher for action type specific call.
9016 : : *
9017 : : * @param[in] dev
9018 : : * Pointer to the Ethernet device structure.
9019 : : * @param[in] mtr_policy
9020 : : * Meter policy struct.
9021 : : *
9022 : : * @return
9023 : : * 0 on success, -1 otherwise.
9024 : : */
9025 : : int
9026 : 0 : mlx5_flow_create_policy_rules(struct rte_eth_dev *dev,
9027 : : struct mlx5_flow_meter_policy *mtr_policy)
9028 : : {
9029 : : const struct mlx5_flow_driver_ops *fops;
9030 : :
9031 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9032 : 0 : return fops->create_policy_rules(dev, mtr_policy);
9033 : : }
9034 : :
9035 : : /**
9036 : : * Destroy policy rules, lock free,
9037 : : * (mutex should be acquired by caller).
9038 : : * Dispatcher for action type specific call.
9039 : : *
9040 : : * @param[in] dev
9041 : : * Pointer to the Ethernet device structure.
9042 : : * @param[in] mtr_policy
9043 : : * Meter policy struct.
9044 : : */
9045 : : void
9046 : 0 : mlx5_flow_destroy_policy_rules(struct rte_eth_dev *dev,
9047 : : struct mlx5_flow_meter_policy *mtr_policy)
9048 : : {
9049 : : const struct mlx5_flow_driver_ops *fops;
9050 : :
9051 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9052 : 0 : fops->destroy_policy_rules(dev, mtr_policy);
9053 : 0 : }
9054 : :
9055 : : /**
9056 : : * Destroy the default policy table set.
9057 : : *
9058 : : * @param[in] dev
9059 : : * Pointer to Ethernet device.
9060 : : */
9061 : : void
9062 : 0 : mlx5_flow_destroy_def_policy(struct rte_eth_dev *dev)
9063 : : {
9064 : : const struct mlx5_flow_driver_ops *fops;
9065 : :
9066 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9067 : 0 : fops->destroy_def_policy(dev);
9068 : 0 : }
9069 : :
9070 : : /**
9071 : : * Destroy the default policy table set.
9072 : : *
9073 : : * @param[in] dev
9074 : : * Pointer to Ethernet device.
9075 : : *
9076 : : * @return
9077 : : * 0 on success, -1 otherwise.
9078 : : */
9079 : : int
9080 : 0 : mlx5_flow_create_def_policy(struct rte_eth_dev *dev)
9081 : : {
9082 : : const struct mlx5_flow_driver_ops *fops;
9083 : :
9084 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9085 : 0 : return fops->create_def_policy(dev);
9086 : : }
9087 : :
9088 : : /**
9089 : : * Create the needed meter and suffix tables.
9090 : : *
9091 : : * @param[in] dev
9092 : : * Pointer to Ethernet device.
9093 : : *
9094 : : * @return
9095 : : * 0 on success, -1 otherwise.
9096 : : */
9097 : : int
9098 : 0 : mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
9099 : : struct mlx5_flow_meter_info *fm,
9100 : : uint32_t mtr_idx,
9101 : : uint8_t domain_bitmap)
9102 : : {
9103 : : const struct mlx5_flow_driver_ops *fops;
9104 : :
9105 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9106 : 0 : return fops->create_mtr_tbls(dev, fm, mtr_idx, domain_bitmap);
9107 : : }
9108 : :
9109 : : /**
9110 : : * Destroy the meter table set.
9111 : : *
9112 : : * @param[in] dev
9113 : : * Pointer to Ethernet device.
9114 : : * @param[in] tbl
9115 : : * Pointer to the meter table set.
9116 : : */
9117 : : void
9118 : 0 : mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
9119 : : struct mlx5_flow_meter_info *fm)
9120 : : {
9121 : : const struct mlx5_flow_driver_ops *fops;
9122 : :
9123 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9124 : 0 : fops->destroy_mtr_tbls(dev, fm);
9125 : 0 : }
9126 : :
9127 : : /**
9128 : : * Destroy the global meter drop table.
9129 : : *
9130 : : * @param[in] dev
9131 : : * Pointer to Ethernet device.
9132 : : */
9133 : : void
9134 : 0 : mlx5_flow_destroy_mtr_drop_tbls(struct rte_eth_dev *dev)
9135 : : {
9136 : : const struct mlx5_flow_driver_ops *fops;
9137 : :
9138 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9139 : 0 : fops->destroy_mtr_drop_tbls(dev);
9140 : 0 : }
9141 : :
9142 : : /**
9143 : : * Destroy the sub policy table with RX queue.
9144 : : *
9145 : : * @param[in] dev
9146 : : * Pointer to Ethernet device.
9147 : : * @param[in] mtr_policy
9148 : : * Pointer to meter policy table.
9149 : : */
9150 : : void
9151 : 0 : mlx5_flow_destroy_sub_policy_with_rxq(struct rte_eth_dev *dev,
9152 : : struct mlx5_flow_meter_policy *mtr_policy)
9153 : : {
9154 : : const struct mlx5_flow_driver_ops *fops;
9155 : :
9156 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9157 : 0 : fops->destroy_sub_policy_with_rxq(dev, mtr_policy);
9158 : 0 : }
9159 : :
9160 : : /**
9161 : : * Allocate the needed aso flow meter id.
9162 : : *
9163 : : * @param[in] dev
9164 : : * Pointer to Ethernet device.
9165 : : *
9166 : : * @return
9167 : : * Index to aso flow meter on success, NULL otherwise.
9168 : : */
9169 : : uint32_t
9170 : 0 : mlx5_flow_mtr_alloc(struct rte_eth_dev *dev)
9171 : : {
9172 : : const struct mlx5_flow_driver_ops *fops;
9173 : :
9174 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9175 : 0 : return fops->create_meter(dev);
9176 : : }
9177 : :
9178 : : /**
9179 : : * Free the aso flow meter id.
9180 : : *
9181 : : * @param[in] dev
9182 : : * Pointer to Ethernet device.
9183 : : * @param[in] mtr_idx
9184 : : * Index to aso flow meter to be free.
9185 : : *
9186 : : * @return
9187 : : * 0 on success.
9188 : : */
9189 : : void
9190 : 0 : mlx5_flow_mtr_free(struct rte_eth_dev *dev, uint32_t mtr_idx)
9191 : : {
9192 : : const struct mlx5_flow_driver_ops *fops;
9193 : :
9194 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9195 : 0 : fops->free_meter(dev, mtr_idx);
9196 : 0 : }
9197 : :
9198 : : /**
9199 : : * Allocate a counter.
9200 : : *
9201 : : * @param[in] dev
9202 : : * Pointer to Ethernet device structure.
9203 : : *
9204 : : * @return
9205 : : * Index to allocated counter on success, 0 otherwise.
9206 : : */
9207 : : uint32_t
9208 [ # # ]: 0 : mlx5_counter_alloc(struct rte_eth_dev *dev)
9209 : : {
9210 : : struct rte_flow_attr attr = { .transfer = 0 };
9211 : :
9212 : 0 : return flow_get_drv_ops(flow_get_drv_type(dev, &attr))->counter_alloc
9213 : : (dev);
9214 : : }
9215 : :
9216 : : /**
9217 : : * Free a counter.
9218 : : *
9219 : : * @param[in] dev
9220 : : * Pointer to Ethernet device structure.
9221 : : * @param[in] cnt
9222 : : * Index to counter to be free.
9223 : : */
9224 : : void
9225 [ # # ]: 0 : mlx5_counter_free(struct rte_eth_dev *dev, uint32_t cnt)
9226 : : {
9227 : : struct rte_flow_attr attr = { .transfer = 0 };
9228 : :
9229 : 0 : flow_get_drv_ops(flow_get_drv_type(dev, &attr))->counter_free(dev, cnt);
9230 : 0 : }
9231 : :
9232 : : /**
9233 : : * Query counter statistics.
9234 : : *
9235 : : * @param[in] dev
9236 : : * Pointer to Ethernet device structure.
9237 : : * @param[in] cnt
9238 : : * Index to counter to query.
9239 : : * @param[in] clear
9240 : : * Set to clear counter statistics.
9241 : : * @param[out] pkts
9242 : : * The counter hits packets number to save.
9243 : : * @param[out] bytes
9244 : : * The counter hits bytes number to save.
9245 : : *
9246 : : * @return
9247 : : * 0 on success, a negative errno value otherwise.
9248 : : */
9249 : : int
9250 [ # # ]: 0 : mlx5_counter_query(struct rte_eth_dev *dev, uint32_t cnt,
9251 : : bool clear, uint64_t *pkts, uint64_t *bytes, void **action)
9252 : : {
9253 : : struct rte_flow_attr attr = { .transfer = 0 };
9254 : :
9255 : 0 : return flow_get_drv_ops(flow_get_drv_type(dev, &attr))->counter_query
9256 : : (dev, cnt, clear, pkts, bytes, action);
9257 : : }
9258 : :
9259 : : /**
9260 : : * Get information about HWS pre-configurable resources.
9261 : : *
9262 : : * @param[in] dev
9263 : : * Pointer to the rte_eth_dev structure.
9264 : : * @param[out] port_info
9265 : : * Pointer to port information.
9266 : : * @param[out] queue_info
9267 : : * Pointer to queue information.
9268 : : * @param[out] error
9269 : : * Pointer to error structure.
9270 : : *
9271 : : * @return
9272 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9273 : : */
9274 : : static int
9275 [ # # ]: 0 : mlx5_flow_info_get(struct rte_eth_dev *dev,
9276 : : struct rte_flow_port_info *port_info,
9277 : : struct rte_flow_queue_info *queue_info,
9278 : : struct rte_flow_error *error)
9279 : : {
9280 : : const struct mlx5_flow_driver_ops *fops;
9281 : : struct rte_flow_attr attr = {0};
9282 : :
9283 : : if (flow_get_drv_type(dev, &attr) != MLX5_FLOW_TYPE_HW)
9284 : 0 : return rte_flow_error_set(error, ENOTSUP,
9285 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9286 : : NULL,
9287 : : "info get with incorrect steering mode");
9288 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9289 : 0 : return fops->info_get(dev, port_info, queue_info, error);
9290 : : }
9291 : :
9292 : : /**
9293 : : * Configure port HWS resources.
9294 : : *
9295 : : * @param[in] dev
9296 : : * Pointer to the rte_eth_dev structure.
9297 : : * @param[in] port_attr
9298 : : * Port configuration attributes.
9299 : : * @param[in] nb_queue
9300 : : * Number of queue.
9301 : : * @param[in] queue_attr
9302 : : * Array that holds attributes for each flow queue.
9303 : : * @param[out] error
9304 : : * Pointer to error structure.
9305 : : *
9306 : : * @return
9307 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9308 : : */
9309 : : static int
9310 [ # # ]: 0 : mlx5_flow_port_configure(struct rte_eth_dev *dev,
9311 : : const struct rte_flow_port_attr *port_attr,
9312 : : uint16_t nb_queue,
9313 : : const struct rte_flow_queue_attr *queue_attr[],
9314 : : struct rte_flow_error *error)
9315 : : {
9316 : : const struct mlx5_flow_driver_ops *fops;
9317 : : struct rte_flow_attr attr = {0};
9318 : :
9319 : : if (flow_get_drv_type(dev, &attr) != MLX5_FLOW_TYPE_HW)
9320 : 0 : return rte_flow_error_set(error, ENOTSUP,
9321 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9322 : : NULL,
9323 : : "port configure with incorrect steering mode");
9324 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9325 : 0 : return fops->configure(dev, port_attr, nb_queue, queue_attr, error);
9326 : : }
9327 : :
9328 : : /**
9329 : : * Validate item template.
9330 : : *
9331 : : * @param[in] dev
9332 : : * Pointer to the rte_eth_dev structure.
9333 : : * @param[in] attr
9334 : : * Pointer to the item template attributes.
9335 : : * @param[in] items
9336 : : * The template item pattern.
9337 : : * @param[out] error
9338 : : * Pointer to error structure.
9339 : : *
9340 : : * @return
9341 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9342 : : */
9343 : : int
9344 : 0 : mlx5_flow_pattern_validate(struct rte_eth_dev *dev,
9345 : : const struct rte_flow_pattern_template_attr *attr,
9346 : : const struct rte_flow_item items[],
9347 : : struct rte_flow_error *error)
9348 : : {
9349 : : const struct mlx5_flow_driver_ops *fops;
9350 : : struct rte_flow_attr fattr = {0};
9351 [ # # ]: 0 : uint64_t item_flags = 0;
9352 : :
9353 : : if (flow_get_drv_type(dev, &fattr) != MLX5_FLOW_TYPE_HW) {
9354 : 0 : rte_flow_error_set(error, ENOTSUP,
9355 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9356 : : "pattern validate with incorrect steering mode");
9357 : 0 : return -ENOTSUP;
9358 : : }
9359 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9360 : 0 : return fops->pattern_validate(dev, attr, items, &item_flags, error);
9361 : : }
9362 : :
9363 : : /**
9364 : : * Create flow item template.
9365 : : *
9366 : : * @param[in] dev
9367 : : * Pointer to the rte_eth_dev structure.
9368 : : * @param[in] attr
9369 : : * Pointer to the item template attributes.
9370 : : * @param[in] items
9371 : : * The template item pattern.
9372 : : * @param[out] error
9373 : : * Pointer to error structure.
9374 : : *
9375 : : * @return
9376 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9377 : : */
9378 : : static struct rte_flow_pattern_template *
9379 [ # # ]: 0 : mlx5_flow_pattern_template_create(struct rte_eth_dev *dev,
9380 : : const struct rte_flow_pattern_template_attr *attr,
9381 : : const struct rte_flow_item items[],
9382 : : struct rte_flow_error *error)
9383 : : {
9384 : : const struct mlx5_flow_driver_ops *fops;
9385 : : struct rte_flow_attr fattr = {0};
9386 : :
9387 : : if (flow_get_drv_type(dev, &fattr) != MLX5_FLOW_TYPE_HW) {
9388 : 0 : rte_flow_error_set(error, ENOTSUP,
9389 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9390 : : NULL,
9391 : : "pattern create with incorrect steering mode");
9392 : 0 : return NULL;
9393 : : }
9394 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9395 : 0 : return fops->pattern_template_create(dev, attr, items, error);
9396 : : }
9397 : :
9398 : : /**
9399 : : * Destroy flow item template.
9400 : : *
9401 : : * @param[in] dev
9402 : : * Pointer to the rte_eth_dev structure.
9403 : : * @param[in] template
9404 : : * Pointer to the item template to be destroyed.
9405 : : * @param[out] error
9406 : : * Pointer to error structure.
9407 : : *
9408 : : * @return
9409 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9410 : : */
9411 : : static int
9412 [ # # ]: 0 : mlx5_flow_pattern_template_destroy(struct rte_eth_dev *dev,
9413 : : struct rte_flow_pattern_template *template,
9414 : : struct rte_flow_error *error)
9415 : : {
9416 : : const struct mlx5_flow_driver_ops *fops;
9417 : : struct rte_flow_attr attr = {0};
9418 : :
9419 : : if (flow_get_drv_type(dev, &attr) != MLX5_FLOW_TYPE_HW)
9420 : 0 : return rte_flow_error_set(error, ENOTSUP,
9421 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9422 : : NULL,
9423 : : "pattern destroy with incorrect steering mode");
9424 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9425 : 0 : return fops->pattern_template_destroy(dev, template, error);
9426 : : }
9427 : :
9428 : : /**
9429 : : * Validate flow actions template.
9430 : : *
9431 : : * @param[in] dev
9432 : : * Pointer to the rte_eth_dev structure.
9433 : : * @param[in] attr
9434 : : * Pointer to the action template attributes.
9435 : : * @param[in] actions
9436 : : * Associated actions (list terminated by the END action).
9437 : : * @param[in] masks
9438 : : * List of actions that marks which of the action's member is constant.
9439 : : * @param[out] error
9440 : : * Pointer to error structure.
9441 : : *
9442 : : * @return
9443 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9444 : : */
9445 : : int
9446 [ # # ]: 0 : mlx5_flow_actions_validate(struct rte_eth_dev *dev,
9447 : : const struct rte_flow_actions_template_attr *attr,
9448 : : const struct rte_flow_action actions[],
9449 : : const struct rte_flow_action masks[],
9450 : : struct rte_flow_error *error)
9451 : : {
9452 : : const struct mlx5_flow_driver_ops *fops;
9453 : : struct rte_flow_attr fattr = {0};
9454 : :
9455 : : if (flow_get_drv_type(dev, &fattr) != MLX5_FLOW_TYPE_HW) {
9456 : 0 : rte_flow_error_set(error, ENOTSUP,
9457 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9458 : : "actions validate with incorrect steering mode");
9459 : 0 : return -ENOTSUP;
9460 : : }
9461 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9462 : 0 : return fops->actions_validate(dev, attr, actions, masks, error);
9463 : : }
9464 : :
9465 : : /**
9466 : : * Create flow item template.
9467 : : *
9468 : : * @param[in] dev
9469 : : * Pointer to the rte_eth_dev structure.
9470 : : * @param[in] attr
9471 : : * Pointer to the action template attributes.
9472 : : * @param[in] actions
9473 : : * Associated actions (list terminated by the END action).
9474 : : * @param[in] masks
9475 : : * List of actions that marks which of the action's member is constant.
9476 : : * @param[out] error
9477 : : * Pointer to error structure.
9478 : : *
9479 : : * @return
9480 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9481 : : */
9482 : : static struct rte_flow_actions_template *
9483 [ # # ]: 0 : mlx5_flow_actions_template_create(struct rte_eth_dev *dev,
9484 : : const struct rte_flow_actions_template_attr *attr,
9485 : : const struct rte_flow_action actions[],
9486 : : const struct rte_flow_action masks[],
9487 : : struct rte_flow_error *error)
9488 : : {
9489 : : const struct mlx5_flow_driver_ops *fops;
9490 : : struct rte_flow_attr fattr = {0};
9491 : :
9492 : : if (flow_get_drv_type(dev, &fattr) != MLX5_FLOW_TYPE_HW) {
9493 : 0 : rte_flow_error_set(error, ENOTSUP,
9494 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9495 : : NULL,
9496 : : "action create with incorrect steering mode");
9497 : 0 : return NULL;
9498 : : }
9499 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9500 : 0 : return fops->actions_template_create(dev, attr, actions, masks, error);
9501 : : }
9502 : :
9503 : : /**
9504 : : * Destroy flow action template.
9505 : : *
9506 : : * @param[in] dev
9507 : : * Pointer to the rte_eth_dev structure.
9508 : : * @param[in] template
9509 : : * Pointer to the action template to be destroyed.
9510 : : * @param[out] error
9511 : : * Pointer to error structure.
9512 : : *
9513 : : * @return
9514 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9515 : : */
9516 : : static int
9517 [ # # ]: 0 : mlx5_flow_actions_template_destroy(struct rte_eth_dev *dev,
9518 : : struct rte_flow_actions_template *template,
9519 : : struct rte_flow_error *error)
9520 : : {
9521 : : const struct mlx5_flow_driver_ops *fops;
9522 : : struct rte_flow_attr attr = {0};
9523 : :
9524 : : if (flow_get_drv_type(dev, &attr) != MLX5_FLOW_TYPE_HW)
9525 : 0 : return rte_flow_error_set(error, ENOTSUP,
9526 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9527 : : NULL,
9528 : : "action destroy with incorrect steering mode");
9529 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9530 : 0 : return fops->actions_template_destroy(dev, template, error);
9531 : : }
9532 : :
9533 : : /**
9534 : : * Create flow table.
9535 : : *
9536 : : * @param[in] dev
9537 : : * Pointer to the rte_eth_dev structure.
9538 : : * @param[in] attr
9539 : : * Pointer to the table attributes.
9540 : : * @param[in] item_templates
9541 : : * Item template array to be binded to the table.
9542 : : * @param[in] nb_item_templates
9543 : : * Number of item template.
9544 : : * @param[in] action_templates
9545 : : * Action template array to be binded to the table.
9546 : : * @param[in] nb_action_templates
9547 : : * Number of action template.
9548 : : * @param[out] error
9549 : : * Pointer to error structure.
9550 : : *
9551 : : * @return
9552 : : * Table on success, NULL otherwise and rte_errno is set.
9553 : : */
9554 : : static struct rte_flow_template_table *
9555 [ # # ]: 0 : mlx5_flow_table_create(struct rte_eth_dev *dev,
9556 : : const struct rte_flow_template_table_attr *attr,
9557 : : struct rte_flow_pattern_template *item_templates[],
9558 : : uint8_t nb_item_templates,
9559 : : struct rte_flow_actions_template *action_templates[],
9560 : : uint8_t nb_action_templates,
9561 : : struct rte_flow_error *error)
9562 : : {
9563 : : const struct mlx5_flow_driver_ops *fops;
9564 : : struct rte_flow_attr fattr = {0};
9565 : :
9566 : : if (flow_get_drv_type(dev, &fattr) != MLX5_FLOW_TYPE_HW) {
9567 : 0 : rte_flow_error_set(error, ENOTSUP,
9568 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9569 : : NULL,
9570 : : "table create with incorrect steering mode");
9571 : 0 : return NULL;
9572 : : }
9573 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9574 : 0 : return fops->template_table_create(dev,
9575 : : attr,
9576 : : item_templates,
9577 : : nb_item_templates,
9578 : : action_templates,
9579 : : nb_action_templates,
9580 : : error);
9581 : : }
9582 : :
9583 : : /**
9584 : : * PMD destroy flow table.
9585 : : *
9586 : : * @param[in] dev
9587 : : * Pointer to the rte_eth_dev structure.
9588 : : * @param[in] table
9589 : : * Pointer to the table to be destroyed.
9590 : : * @param[out] error
9591 : : * Pointer to error structure.
9592 : : *
9593 : : * @return
9594 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9595 : : */
9596 : : static int
9597 [ # # ]: 0 : mlx5_flow_table_destroy(struct rte_eth_dev *dev,
9598 : : struct rte_flow_template_table *table,
9599 : : struct rte_flow_error *error)
9600 : : {
9601 : : const struct mlx5_flow_driver_ops *fops;
9602 : : struct rte_flow_attr attr = {0};
9603 : :
9604 : : if (flow_get_drv_type(dev, &attr) != MLX5_FLOW_TYPE_HW)
9605 : 0 : return rte_flow_error_set(error, ENOTSUP,
9606 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9607 : : NULL,
9608 : : "table destroy with incorrect steering mode");
9609 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9610 : 0 : return fops->template_table_destroy(dev, table, error);
9611 : : }
9612 : :
9613 : : /**
9614 : : * PMD group set miss actions.
9615 : : *
9616 : : * @param[in] dev
9617 : : * Pointer to the rte_eth_dev structure.
9618 : : * @param[in] attr
9619 : : * Pointer to group attributes
9620 : : * @param[in] actions
9621 : : * Array of actions
9622 : : * @param[out] error
9623 : : * Pointer to error structure.
9624 : : *
9625 : : * @return
9626 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9627 : : */
9628 : : static int
9629 [ # # ]: 0 : mlx5_flow_group_set_miss_actions(struct rte_eth_dev *dev,
9630 : : uint32_t group_id,
9631 : : const struct rte_flow_group_attr *attr,
9632 : : const struct rte_flow_action actions[],
9633 : : struct rte_flow_error *error)
9634 : : {
9635 : : const struct mlx5_flow_driver_ops *fops;
9636 : : struct rte_flow_attr fattr = {0};
9637 : :
9638 : : if (flow_get_drv_type(dev, &fattr) != MLX5_FLOW_TYPE_HW)
9639 : 0 : return rte_flow_error_set(error, ENOTSUP,
9640 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9641 : : NULL,
9642 : : "group set miss actions with incorrect steering mode");
9643 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9644 : 0 : return fops->group_set_miss_actions(dev, group_id, attr, actions, error);
9645 : : }
9646 : :
9647 : : /**
9648 : : * Allocate a new memory for the counter values wrapped by all the needed
9649 : : * management.
9650 : : *
9651 : : * @param[in] sh
9652 : : * Pointer to mlx5_dev_ctx_shared object.
9653 : : *
9654 : : * @return
9655 : : * 0 on success, a negative errno value otherwise.
9656 : : */
9657 : : static int
9658 : 0 : mlx5_flow_create_counter_stat_mem_mng(struct mlx5_dev_ctx_shared *sh)
9659 : : {
9660 : : struct mlx5_counter_stats_mem_mng *mem_mng;
9661 : : volatile struct flow_counter_stats *raw_data;
9662 : : int raws_n = MLX5_CNT_MR_ALLOC_BULK + MLX5_MAX_PENDING_QUERIES;
9663 : : int size = (sizeof(struct flow_counter_stats) *
9664 : : MLX5_COUNTERS_PER_POOL +
9665 : : sizeof(struct mlx5_counter_stats_raw)) * raws_n +
9666 : : sizeof(struct mlx5_counter_stats_mem_mng);
9667 : 0 : size_t pgsize = rte_mem_page_size();
9668 : : uint8_t *mem;
9669 : : int ret;
9670 : : int i;
9671 : :
9672 [ # # ]: 0 : if (pgsize == (size_t)-1) {
9673 : 0 : DRV_LOG(ERR, "Failed to get mem page size");
9674 : 0 : rte_errno = ENOMEM;
9675 : 0 : return -ENOMEM;
9676 : : }
9677 : 0 : mem = mlx5_malloc(MLX5_MEM_ZERO, size, pgsize, SOCKET_ID_ANY);
9678 [ # # ]: 0 : if (!mem) {
9679 : 0 : rte_errno = ENOMEM;
9680 : 0 : return -ENOMEM;
9681 : : }
9682 : 0 : mem_mng = (struct mlx5_counter_stats_mem_mng *)(mem + size) - 1;
9683 : : size = sizeof(*raw_data) * MLX5_COUNTERS_PER_POOL * raws_n;
9684 : 0 : ret = mlx5_os_wrapped_mkey_create(sh->cdev->ctx, sh->cdev->pd,
9685 : 0 : sh->cdev->pdn, mem, size,
9686 : : &mem_mng->wm);
9687 [ # # ]: 0 : if (ret) {
9688 : 0 : rte_errno = errno;
9689 : 0 : mlx5_free(mem);
9690 : 0 : return -rte_errno;
9691 : : }
9692 : 0 : mem_mng->raws = (struct mlx5_counter_stats_raw *)(mem + size);
9693 : : raw_data = (volatile struct flow_counter_stats *)mem;
9694 [ # # ]: 0 : for (i = 0; i < raws_n; ++i) {
9695 : 0 : mem_mng->raws[i].mem_mng = mem_mng;
9696 : 0 : mem_mng->raws[i].data = raw_data + i * MLX5_COUNTERS_PER_POOL;
9697 : : }
9698 [ # # ]: 0 : for (i = 0; i < MLX5_MAX_PENDING_QUERIES; ++i)
9699 [ # # ]: 0 : LIST_INSERT_HEAD(&sh->sws_cmng.free_stat_raws,
9700 : : mem_mng->raws + MLX5_CNT_MR_ALLOC_BULK + i,
9701 : : next);
9702 [ # # ]: 0 : LIST_INSERT_HEAD(&sh->sws_cmng.mem_mngs, mem_mng, next);
9703 : 0 : sh->sws_cmng.mem_mng = mem_mng;
9704 : 0 : return 0;
9705 : : }
9706 : :
9707 : : /**
9708 : : * Set the statistic memory to the new counter pool.
9709 : : *
9710 : : * @param[in] sh
9711 : : * Pointer to mlx5_dev_ctx_shared object.
9712 : : * @param[in] pool
9713 : : * Pointer to the pool to set the statistic memory.
9714 : : *
9715 : : * @return
9716 : : * 0 on success, a negative errno value otherwise.
9717 : : */
9718 : : static int
9719 : 0 : mlx5_flow_set_counter_stat_mem(struct mlx5_dev_ctx_shared *sh,
9720 : : struct mlx5_flow_counter_pool *pool)
9721 : : {
9722 : : struct mlx5_flow_counter_mng *cmng = &sh->sws_cmng;
9723 : : /* Resize statistic memory once used out. */
9724 [ # # # # ]: 0 : if (!(pool->index % MLX5_CNT_MR_ALLOC_BULK) &&
9725 : 0 : mlx5_flow_create_counter_stat_mem_mng(sh)) {
9726 : 0 : DRV_LOG(ERR, "Cannot resize counter stat mem.");
9727 : 0 : return -1;
9728 : : }
9729 : 0 : rte_spinlock_lock(&pool->sl);
9730 : 0 : pool->raw = cmng->mem_mng->raws + pool->index % MLX5_CNT_MR_ALLOC_BULK;
9731 : : rte_spinlock_unlock(&pool->sl);
9732 : 0 : pool->raw_hw = NULL;
9733 : 0 : return 0;
9734 : : }
9735 : :
9736 : : #define MLX5_POOL_QUERY_FREQ_US 1000000
9737 : :
9738 : : /**
9739 : : * Set the periodic procedure for triggering asynchronous batch queries for all
9740 : : * the counter pools.
9741 : : *
9742 : : * @param[in] sh
9743 : : * Pointer to mlx5_dev_ctx_shared object.
9744 : : */
9745 : : void
9746 : 0 : mlx5_set_query_alarm(struct mlx5_dev_ctx_shared *sh)
9747 : : {
9748 : : uint32_t pools_n, us;
9749 : :
9750 : 0 : pools_n = rte_atomic_load_explicit(&sh->sws_cmng.n_valid, rte_memory_order_relaxed);
9751 : 0 : us = MLX5_POOL_QUERY_FREQ_US / pools_n;
9752 : 0 : DRV_LOG(DEBUG, "Set alarm for %u pools each %u us", pools_n, us);
9753 [ # # ]: 0 : if (rte_eal_alarm_set(us, mlx5_flow_query_alarm, sh)) {
9754 : 0 : sh->sws_cmng.query_thread_on = 0;
9755 : 0 : DRV_LOG(ERR, "Cannot reinitialize query alarm");
9756 : : } else {
9757 : 0 : sh->sws_cmng.query_thread_on = 1;
9758 : : }
9759 : 0 : }
9760 : :
9761 : : /**
9762 : : * The periodic procedure for triggering asynchronous batch queries for all the
9763 : : * counter pools. This function is probably called by the host thread.
9764 : : *
9765 : : * @param[in] arg
9766 : : * The parameter for the alarm process.
9767 : : */
9768 : : void
9769 : 0 : mlx5_flow_query_alarm(void *arg)
9770 : : {
9771 : : struct mlx5_dev_ctx_shared *sh = arg;
9772 : : struct mlx5_flow_counter_mng *cmng = &sh->sws_cmng;
9773 : 0 : uint16_t pool_index = cmng->pool_index;
9774 : : struct mlx5_flow_counter_pool *pool;
9775 : : uint16_t n_valid;
9776 : : int ret;
9777 : :
9778 [ # # ]: 0 : if (cmng->pending_queries >= MLX5_MAX_PENDING_QUERIES)
9779 : 0 : goto set_alarm;
9780 : 0 : rte_spinlock_lock(&cmng->pool_update_sl);
9781 : 0 : pool = cmng->pools[pool_index];
9782 : 0 : n_valid = cmng->n_valid;
9783 : : rte_spinlock_unlock(&cmng->pool_update_sl);
9784 : : /* Set the statistic memory to the new created pool. */
9785 [ # # # # ]: 0 : if ((!pool->raw && mlx5_flow_set_counter_stat_mem(sh, pool)))
9786 : 0 : goto set_alarm;
9787 [ # # ]: 0 : if (pool->raw_hw)
9788 : : /* There is a pool query in progress. */
9789 : 0 : goto set_alarm;
9790 : 0 : pool->raw_hw = LIST_FIRST(&cmng->free_stat_raws);
9791 [ # # ]: 0 : if (!pool->raw_hw)
9792 : : /* No free counter statistics raw memory. */
9793 : 0 : goto set_alarm;
9794 : : /*
9795 : : * Identify the counters released between query trigger and query
9796 : : * handle more efficiently. The counter released in this gap period
9797 : : * should wait for a new round of query as the new arrived packets
9798 : : * will not be taken into account.
9799 : : */
9800 : 0 : pool->query_gen++;
9801 : 0 : ret = mlx5_devx_cmd_flow_counter_query(pool->min_dcs, 0,
9802 : : MLX5_COUNTERS_PER_POOL,
9803 : : NULL, NULL,
9804 : 0 : pool->raw_hw->mem_mng->wm.lkey,
9805 : : (void *)(uintptr_t)
9806 : 0 : pool->raw_hw->data,
9807 : : sh->devx_comp,
9808 : : (uint64_t)(uintptr_t)pool);
9809 [ # # ]: 0 : if (ret) {
9810 : 0 : DRV_LOG(ERR, "Failed to trigger asynchronous query for dcs ID"
9811 : : " %d", pool->min_dcs->id);
9812 : 0 : pool->raw_hw = NULL;
9813 : 0 : goto set_alarm;
9814 : : }
9815 [ # # ]: 0 : LIST_REMOVE(pool->raw_hw, next);
9816 : 0 : cmng->pending_queries++;
9817 : 0 : pool_index++;
9818 [ # # ]: 0 : if (pool_index >= n_valid)
9819 : : pool_index = 0;
9820 : 0 : set_alarm:
9821 : 0 : cmng->pool_index = pool_index;
9822 : 0 : mlx5_set_query_alarm(sh);
9823 : 0 : }
9824 : :
9825 : : /**
9826 : : * Check and callback event for new aged flow in the counter pool
9827 : : *
9828 : : * @param[in] sh
9829 : : * Pointer to mlx5_dev_ctx_shared object.
9830 : : * @param[in] pool
9831 : : * Pointer to Current counter pool.
9832 : : */
9833 : : static void
9834 : 0 : mlx5_flow_aging_check(struct mlx5_dev_ctx_shared *sh,
9835 : : struct mlx5_flow_counter_pool *pool)
9836 : : {
9837 : : struct mlx5_priv *priv;
9838 : : struct mlx5_flow_counter *cnt;
9839 : : struct mlx5_age_info *age_info;
9840 : : struct mlx5_age_param *age_param;
9841 : 0 : struct mlx5_counter_stats_raw *cur = pool->raw_hw;
9842 : 0 : struct mlx5_counter_stats_raw *prev = pool->raw;
9843 : 0 : const uint64_t curr_time = MLX5_CURR_TIME_SEC;
9844 : 0 : const uint32_t time_delta = curr_time - pool->time_of_last_age_check;
9845 : : uint16_t expected = AGE_CANDIDATE;
9846 : : uint32_t i;
9847 : :
9848 : 0 : pool->time_of_last_age_check = curr_time;
9849 [ # # ]: 0 : for (i = 0; i < MLX5_COUNTERS_PER_POOL; ++i) {
9850 [ # # ]: 0 : cnt = MLX5_POOL_GET_CNT(pool, i);
9851 : : age_param = MLX5_CNT_TO_AGE(cnt);
9852 [ # # ]: 0 : if (rte_atomic_load_explicit(&age_param->state,
9853 : : rte_memory_order_relaxed) != AGE_CANDIDATE)
9854 : 0 : continue;
9855 [ # # ]: 0 : if (cur->data[i].hits != prev->data[i].hits) {
9856 : 0 : rte_atomic_store_explicit(&age_param->sec_since_last_hit, 0,
9857 : : rte_memory_order_relaxed);
9858 : 0 : continue;
9859 : : }
9860 : 0 : if (rte_atomic_fetch_add_explicit(&age_param->sec_since_last_hit,
9861 : : time_delta,
9862 [ # # ]: 0 : rte_memory_order_relaxed) + time_delta <= age_param->timeout)
9863 : 0 : continue;
9864 : : /**
9865 : : * Hold the lock first, or if between the
9866 : : * state AGE_TMOUT and tailq operation the
9867 : : * release happened, the release procedure
9868 : : * may delete a non-existent tailq node.
9869 : : */
9870 : 0 : priv = rte_eth_devices[age_param->port_id].data->dev_private;
9871 : 0 : age_info = GET_PORT_AGE_INFO(priv);
9872 : 0 : rte_spinlock_lock(&age_info->aged_sl);
9873 [ # # ]: 0 : if (rte_atomic_compare_exchange_strong_explicit(&age_param->state, &expected,
9874 : : AGE_TMOUT,
9875 : : rte_memory_order_relaxed,
9876 : : rte_memory_order_relaxed)) {
9877 : 0 : TAILQ_INSERT_TAIL(&age_info->aged_counters, cnt, next);
9878 : 0 : MLX5_AGE_SET(age_info, MLX5_AGE_EVENT_NEW);
9879 : : }
9880 : : rte_spinlock_unlock(&age_info->aged_sl);
9881 : : }
9882 : 0 : mlx5_age_event_prepare(sh);
9883 : 0 : }
9884 : :
9885 : : /**
9886 : : * Handler for the HW respond about ready values from an asynchronous batch
9887 : : * query. This function is probably called by the host thread.
9888 : : *
9889 : : * @param[in] sh
9890 : : * The pointer to the shared device context.
9891 : : * @param[in] async_id
9892 : : * The Devx async ID.
9893 : : * @param[in] status
9894 : : * The status of the completion.
9895 : : */
9896 : : void
9897 : 0 : mlx5_flow_async_pool_query_handle(struct mlx5_dev_ctx_shared *sh,
9898 : : uint64_t async_id, int status)
9899 : : {
9900 : 0 : struct mlx5_flow_counter_pool *pool =
9901 : : (struct mlx5_flow_counter_pool *)(uintptr_t)async_id;
9902 : : struct mlx5_counter_stats_raw *raw_to_free;
9903 : 0 : uint8_t query_gen = pool->query_gen ^ 1;
9904 : : struct mlx5_flow_counter_mng *cmng = &sh->sws_cmng;
9905 : 0 : enum mlx5_counter_type cnt_type =
9906 : 0 : pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
9907 : : MLX5_COUNTER_TYPE_ORIGIN;
9908 : :
9909 [ # # ]: 0 : if (unlikely(status)) {
9910 : 0 : raw_to_free = pool->raw_hw;
9911 : : } else {
9912 : 0 : raw_to_free = pool->raw;
9913 [ # # ]: 0 : if (pool->is_aged)
9914 : 0 : mlx5_flow_aging_check(sh, pool);
9915 : 0 : rte_spinlock_lock(&pool->sl);
9916 : 0 : pool->raw = pool->raw_hw;
9917 : : rte_spinlock_unlock(&pool->sl);
9918 : : /* Be sure the new raw counters data is updated in memory. */
9919 : 0 : rte_io_wmb();
9920 [ # # ]: 0 : if (!TAILQ_EMPTY(&pool->counters[query_gen])) {
9921 : 0 : rte_spinlock_lock(&cmng->csl[cnt_type]);
9922 [ # # ]: 0 : TAILQ_CONCAT(&cmng->counters[cnt_type],
9923 : : &pool->counters[query_gen], next);
9924 : : rte_spinlock_unlock(&cmng->csl[cnt_type]);
9925 : : }
9926 : : }
9927 [ # # ]: 0 : LIST_INSERT_HEAD(&sh->sws_cmng.free_stat_raws, raw_to_free, next);
9928 : 0 : pool->raw_hw = NULL;
9929 : 0 : sh->sws_cmng.pending_queries--;
9930 : 0 : }
9931 : :
9932 : : static int
9933 : 0 : flow_group_to_table(uint32_t port_id, uint32_t group, uint32_t *table,
9934 : : const struct flow_grp_info *grp_info,
9935 : : struct rte_flow_error *error)
9936 : : {
9937 [ # # ]: 0 : if (grp_info->transfer && grp_info->external &&
9938 : : grp_info->fdb_def_rule) {
9939 [ # # ]: 0 : if (group == UINT32_MAX)
9940 : 0 : return rte_flow_error_set
9941 : : (error, EINVAL,
9942 : : RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
9943 : : NULL,
9944 : : "group index not supported");
9945 : 0 : *table = group + 1;
9946 : : } else {
9947 : 0 : *table = group;
9948 : : }
9949 : 0 : DRV_LOG(DEBUG, "port %u group=%#x table=%#x", port_id, group, *table);
9950 : 0 : return 0;
9951 : : }
9952 : :
9953 : : /**
9954 : : * Translate the rte_flow group index to HW table value.
9955 : : *
9956 : : * If tunnel offload is disabled, all group ids converted to flow table
9957 : : * id using the standard method.
9958 : : * If tunnel offload is enabled, group id can be converted using the
9959 : : * standard or tunnel conversion method. Group conversion method
9960 : : * selection depends on flags in `grp_info` parameter:
9961 : : * - Internal (grp_info.external == 0) groups conversion uses the
9962 : : * standard method.
9963 : : * - Group ids in JUMP action converted with the tunnel conversion.
9964 : : * - Group id in rule attribute conversion depends on a rule type and
9965 : : * group id value:
9966 : : * ** non zero group attributes converted with the tunnel method
9967 : : * ** zero group attribute in non-tunnel rule is converted using the
9968 : : * standard method - there's only one root table
9969 : : * ** zero group attribute in steer tunnel rule is converted with the
9970 : : * standard method - single root table
9971 : : * ** zero group attribute in match tunnel rule is a special OvS
9972 : : * case: that value is used for portability reasons. That group
9973 : : * id is converted with the tunnel conversion method.
9974 : : *
9975 : : * @param[in] dev
9976 : : * Port device
9977 : : * @param[in] tunnel
9978 : : * PMD tunnel offload object
9979 : : * @param[in] group
9980 : : * rte_flow group index value.
9981 : : * @param[out] table
9982 : : * HW table value.
9983 : : * @param[in] grp_info
9984 : : * flags used for conversion
9985 : : * @param[out] error
9986 : : * Pointer to error structure.
9987 : : *
9988 : : * @return
9989 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9990 : : */
9991 : : int
9992 : 0 : mlx5_flow_group_to_table(struct rte_eth_dev *dev,
9993 : : const struct mlx5_flow_tunnel *tunnel,
9994 : : uint32_t group, uint32_t *table,
9995 : : const struct flow_grp_info *grp_info,
9996 : : struct rte_flow_error *error)
9997 : : {
9998 : : int ret;
9999 : : bool standard_translation;
10000 : :
10001 [ # # # # ]: 0 : if (!grp_info->skip_scale && grp_info->external &&
10002 : : group < MLX5_MAX_TABLES_EXTERNAL)
10003 : 0 : group *= MLX5_FLOW_TABLE_FACTOR;
10004 [ # # ]: 0 : if (is_tunnel_offload_active(dev)) {
10005 : 0 : standard_translation = !grp_info->external ||
10006 : : grp_info->std_tbl_fix;
10007 : : } else {
10008 : : standard_translation = true;
10009 : : }
10010 [ # # ]: 0 : DRV_LOG(DEBUG,
10011 : : "port %u group=%u transfer=%d external=%d fdb_def_rule=%d translate=%s",
10012 : : dev->data->port_id, group, grp_info->transfer,
10013 : : grp_info->external, grp_info->fdb_def_rule,
10014 : : standard_translation ? "STANDARD" : "TUNNEL");
10015 [ # # ]: 0 : if (standard_translation)
10016 : 0 : ret = flow_group_to_table(dev->data->port_id, group, table,
10017 : : grp_info, error);
10018 : : else
10019 : 0 : ret = tunnel_flow_group_to_flow_table(dev, tunnel, group,
10020 : : table, error);
10021 : :
10022 : 0 : return ret;
10023 : : }
10024 : :
10025 : : /**
10026 : : * Discover availability of metadata reg_c's.
10027 : : *
10028 : : * Iteratively use test flows to check availability.
10029 : : *
10030 : : * @param[in] dev
10031 : : * Pointer to the Ethernet device structure.
10032 : : *
10033 : : * @return
10034 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
10035 : : */
10036 : : int
10037 : 0 : mlx5_flow_discover_mreg_c(struct rte_eth_dev *dev)
10038 : : {
10039 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10040 : : enum modify_reg idx;
10041 : : int n = 0;
10042 : :
10043 : : /* reg_c[0] and reg_c[1] are reserved. */
10044 : 0 : priv->sh->flow_mreg_c[n++] = REG_C_0;
10045 : 0 : priv->sh->flow_mreg_c[n++] = REG_C_1;
10046 : : /* Discover availability of other reg_c's. */
10047 [ # # ]: 0 : for (idx = REG_C_2; idx <= REG_C_7; ++idx) {
10048 : 0 : struct rte_flow_attr attr = {
10049 : : .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
10050 : : .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
10051 : : .ingress = 1,
10052 : : };
10053 : 0 : struct rte_flow_item items[] = {
10054 : : [0] = {
10055 : : .type = RTE_FLOW_ITEM_TYPE_END,
10056 : : },
10057 : : };
10058 : 0 : struct rte_flow_action actions[] = {
10059 : : [0] = {
10060 : : .type = (enum rte_flow_action_type)
10061 : : MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
10062 : 0 : .conf = &(struct mlx5_flow_action_copy_mreg){
10063 : : .src = REG_C_1,
10064 : : .dst = idx,
10065 : : },
10066 : : },
10067 : : [1] = {
10068 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
10069 : 0 : .conf = &(struct rte_flow_action_jump){
10070 : : .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
10071 : : },
10072 : : },
10073 : : [2] = {
10074 : : .type = RTE_FLOW_ACTION_TYPE_END,
10075 : : },
10076 : : };
10077 : : uint32_t flow_idx;
10078 : : struct rte_flow *flow;
10079 : : struct rte_flow_error error;
10080 : :
10081 [ # # ]: 0 : if (!priv->sh->config.dv_flow_en)
10082 : : break;
10083 : : /* Create internal flow, validation skips copy action. */
10084 : 0 : flow_idx = mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_GEN, &attr,
10085 : : items, actions, false, &error);
10086 : 0 : flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
10087 : : flow_idx);
10088 [ # # ]: 0 : if (!flow)
10089 : 0 : continue;
10090 : 0 : priv->sh->flow_mreg_c[n++] = idx;
10091 : 0 : mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN, flow_idx);
10092 : : }
10093 [ # # ]: 0 : for (; n < MLX5_MREG_C_NUM; ++n)
10094 : 0 : priv->sh->flow_mreg_c[n] = REG_NON;
10095 : 0 : priv->sh->metadata_regc_check_flag = 1;
10096 : 0 : return 0;
10097 : : }
10098 : :
10099 : : int
10100 [ # # # # ]: 0 : save_dump_file(const uint8_t *data, uint32_t size,
10101 : : uint32_t type, uint64_t id, void *arg, FILE *file)
10102 : : {
10103 : : char line[BUF_SIZE];
10104 : : uint32_t out = 0;
10105 : : uint32_t k;
10106 : : uint32_t actions_num;
10107 : : struct rte_flow_query_count *count;
10108 : :
10109 : : memset(line, 0, BUF_SIZE);
10110 [ # # # # ]: 0 : switch (type) {
10111 : 0 : case DR_DUMP_REC_TYPE_PMD_MODIFY_HDR:
10112 : 0 : actions_num = *(uint32_t *)(arg);
10113 : 0 : out += snprintf(line + out, BUF_SIZE - out, "%d,0x%" PRIx64 ",%d,",
10114 : : type, id, actions_num);
10115 : 0 : break;
10116 : 0 : case DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT:
10117 : 0 : out += snprintf(line + out, BUF_SIZE - out, "%d,0x%" PRIx64 ",",
10118 : : type, id);
10119 : 0 : break;
10120 : 0 : case DR_DUMP_REC_TYPE_PMD_COUNTER:
10121 : : count = (struct rte_flow_query_count *)arg;
10122 : 0 : fprintf(file,
10123 : : "%d,0x%" PRIx64 ",%" PRIu64 ",%" PRIu64 "\n",
10124 : : type, id, count->hits, count->bytes);
10125 : 0 : return 0;
10126 : : default:
10127 : : return -1;
10128 : : }
10129 : :
10130 [ # # ]: 0 : for (k = 0; k < size; k++) {
10131 : : /* Make sure we do not overrun the line buffer length. */
10132 [ # # ]: 0 : if (out >= BUF_SIZE - 4) {
10133 : 0 : line[out] = '\0';
10134 : 0 : break;
10135 : : }
10136 : 0 : out += snprintf(line + out, BUF_SIZE - out, "%02x",
10137 : 0 : (data[k]) & 0xff);
10138 : : }
10139 : : fprintf(file, "%s\n", line);
10140 : 0 : return 0;
10141 : : }
10142 : :
10143 : : int
10144 : 0 : mlx5_flow_query_counter(struct rte_eth_dev *dev, struct rte_flow *flow,
10145 : : struct rte_flow_query_count *count, struct rte_flow_error *error)
10146 : : {
10147 : : struct rte_flow_action action[2];
10148 : : enum mlx5_flow_drv_type ftype;
10149 : : const struct mlx5_flow_driver_ops *fops;
10150 : :
10151 [ # # ]: 0 : if (!flow) {
10152 : 0 : return rte_flow_error_set(error, ENOENT,
10153 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10154 : : NULL,
10155 : : "invalid flow handle");
10156 : : }
10157 : 0 : action[0].type = RTE_FLOW_ACTION_TYPE_COUNT;
10158 : 0 : action[1].type = RTE_FLOW_ACTION_TYPE_END;
10159 [ # # ]: 0 : if (flow->counter) {
10160 : : memset(count, 0, sizeof(struct rte_flow_query_count));
10161 : 0 : ftype = (enum mlx5_flow_drv_type)(flow->drv_type);
10162 : : MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN &&
10163 : : ftype < MLX5_FLOW_TYPE_MAX);
10164 : 0 : fops = flow_get_drv_ops(ftype);
10165 : 0 : return fops->query(dev, flow, action, count, error);
10166 : : }
10167 : : return -1;
10168 : : }
10169 : :
10170 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
10171 : : /**
10172 : : * Dump flow ipool data to file
10173 : : *
10174 : : * @param[in] dev
10175 : : * The pointer to Ethernet device.
10176 : : * @param[in] file
10177 : : * A pointer to a file for output.
10178 : : * @param[out] error
10179 : : * Perform verbose error reporting if not NULL. PMDs initialize this
10180 : : * structure in case of error only.
10181 : : * @return
10182 : : * 0 on success, a negative value otherwise.
10183 : : */
10184 : : int
10185 : 0 : mlx5_flow_dev_dump_ipool(struct rte_eth_dev *dev,
10186 : : struct rte_flow *flow, FILE *file,
10187 : : struct rte_flow_error *error)
10188 : : {
10189 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10190 : : struct mlx5_flow_dv_modify_hdr_resource *modify_hdr;
10191 : : struct mlx5_flow_dv_encap_decap_resource *encap_decap;
10192 : : uint32_t handle_idx;
10193 : : struct mlx5_flow_handle *dh;
10194 : : struct rte_flow_query_count count;
10195 : : uint32_t actions_num;
10196 : : const uint8_t *data;
10197 : : size_t size;
10198 : : uint64_t id;
10199 : : uint32_t type;
10200 : 0 : void *action = NULL;
10201 : :
10202 [ # # ]: 0 : if (!flow) {
10203 : 0 : return rte_flow_error_set(error, ENOENT,
10204 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10205 : : NULL,
10206 : : "invalid flow handle");
10207 : : }
10208 : 0 : handle_idx = flow->dev_handles;
10209 : : /* query counter */
10210 [ # # # # ]: 0 : if (flow->counter &&
10211 : 0 : (!mlx5_counter_query(dev, flow->counter, false,
10212 [ # # ]: 0 : &count.hits, &count.bytes, &action)) && action) {
10213 : 0 : id = (uint64_t)(uintptr_t)action;
10214 : : type = DR_DUMP_REC_TYPE_PMD_COUNTER;
10215 : 0 : save_dump_file(NULL, 0, type,
10216 : : id, (void *)&count, file);
10217 : : }
10218 : :
10219 [ # # ]: 0 : while (handle_idx) {
10220 : 0 : dh = mlx5_ipool_get(priv->sh->ipool
10221 : : [MLX5_IPOOL_MLX5_FLOW], handle_idx);
10222 [ # # ]: 0 : if (!dh)
10223 : 0 : continue;
10224 : 0 : handle_idx = dh->next.next;
10225 : :
10226 : : /* Get modify_hdr and encap_decap buf from ipools. */
10227 : : encap_decap = NULL;
10228 : 0 : modify_hdr = dh->dvh.modify_hdr;
10229 : :
10230 [ # # ]: 0 : if (dh->dvh.rix_encap_decap) {
10231 : 0 : encap_decap = mlx5_ipool_get(priv->sh->ipool
10232 : : [MLX5_IPOOL_DECAP_ENCAP],
10233 : : dh->dvh.rix_encap_decap);
10234 : : }
10235 [ # # ]: 0 : if (modify_hdr) {
10236 : 0 : data = (const uint8_t *)modify_hdr->actions;
10237 : 0 : size = (size_t)(modify_hdr->actions_num) * 8;
10238 : 0 : id = (uint64_t)(uintptr_t)modify_hdr->action;
10239 : 0 : actions_num = modify_hdr->actions_num;
10240 : : type = DR_DUMP_REC_TYPE_PMD_MODIFY_HDR;
10241 : 0 : save_dump_file(data, size, type, id,
10242 : : (void *)(&actions_num), file);
10243 : : }
10244 [ # # ]: 0 : if (encap_decap) {
10245 : 0 : data = encap_decap->buf;
10246 : 0 : size = encap_decap->size;
10247 : 0 : id = (uint64_t)(uintptr_t)encap_decap->action;
10248 : : type = DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT;
10249 : 0 : save_dump_file(data, size, type,
10250 : : id, NULL, file);
10251 : : }
10252 : : }
10253 : : return 0;
10254 : : }
10255 : :
10256 : : /**
10257 : : * Dump all flow's encap_decap/modify_hdr/counter data to file
10258 : : *
10259 : : * @param[in] dev
10260 : : * The pointer to Ethernet device.
10261 : : * @param[in] file
10262 : : * A pointer to a file for output.
10263 : : * @param[out] error
10264 : : * Perform verbose error reporting if not NULL. PMDs initialize this
10265 : : * structure in case of error only.
10266 : : * @return
10267 : : * 0 on success, a negative value otherwise.
10268 : : */
10269 : : static int
10270 : 0 : mlx5_flow_dev_dump_sh_all(struct rte_eth_dev *dev,
10271 : : FILE *file, struct rte_flow_error *error __rte_unused)
10272 : : {
10273 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10274 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
10275 : : struct mlx5_hlist *h;
10276 : : struct mlx5_flow_dv_modify_hdr_resource *modify_hdr;
10277 : : struct mlx5_flow_dv_encap_decap_resource *encap_decap;
10278 : : struct rte_flow_query_count count;
10279 : : uint32_t actions_num;
10280 : : const uint8_t *data;
10281 : : size_t size;
10282 : : uint64_t id;
10283 : : uint32_t type;
10284 : : uint32_t i;
10285 : : uint32_t j;
10286 : : struct mlx5_list_inconst *l_inconst;
10287 : : struct mlx5_list_entry *e;
10288 : : int lcore_index;
10289 : : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
10290 : : uint32_t max;
10291 : : void *action;
10292 : :
10293 : : /* encap_decap hlist is lcore_share, get global core cache. */
10294 : : i = MLX5_LIST_GLOBAL;
10295 : 0 : h = sh->encaps_decaps;
10296 [ # # ]: 0 : if (h) {
10297 [ # # ]: 0 : for (j = 0; j <= h->mask; j++) {
10298 : : l_inconst = &h->buckets[j].l;
10299 [ # # ]: 0 : if (!l_inconst || !l_inconst->cache[i])
10300 : 0 : continue;
10301 : :
10302 : 0 : e = LIST_FIRST(&l_inconst->cache[i]->h);
10303 [ # # ]: 0 : while (e) {
10304 : : encap_decap =
10305 : : (struct mlx5_flow_dv_encap_decap_resource *)e;
10306 : 0 : data = encap_decap->buf;
10307 : 0 : size = encap_decap->size;
10308 : 0 : id = (uint64_t)(uintptr_t)encap_decap->action;
10309 : : type = DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT;
10310 : 0 : save_dump_file(data, size, type,
10311 : : id, NULL, file);
10312 : 0 : e = LIST_NEXT(e, next);
10313 : : }
10314 : : }
10315 : : }
10316 : :
10317 : : /* get modify_hdr */
10318 : 0 : h = sh->modify_cmds;
10319 [ # # ]: 0 : if (h) {
10320 : 0 : lcore_index = rte_lcore_index(rte_lcore_id());
10321 [ # # ]: 0 : if (unlikely(lcore_index == -1)) {
10322 : : lcore_index = MLX5_LIST_NLCORE;
10323 : 0 : rte_spinlock_lock(&h->l_const.lcore_lock);
10324 : : }
10325 : 0 : i = lcore_index;
10326 : :
10327 [ # # ]: 0 : if (lcore_index == MLX5_LIST_NLCORE) {
10328 [ # # ]: 0 : for (i = 0; i <= (uint32_t)lcore_index; i++) {
10329 [ # # ]: 0 : for (j = 0; j <= h->mask; j++) {
10330 : : l_inconst = &h->buckets[j].l;
10331 [ # # ]: 0 : if (!l_inconst || !l_inconst->cache[i])
10332 : 0 : continue;
10333 : :
10334 : 0 : e = LIST_FIRST(&l_inconst->cache[i]->h);
10335 [ # # ]: 0 : while (e) {
10336 : : modify_hdr =
10337 : : (struct mlx5_flow_dv_modify_hdr_resource *)e;
10338 : 0 : data = (const uint8_t *)modify_hdr->actions;
10339 : 0 : size = (size_t)(modify_hdr->actions_num) * 8;
10340 : 0 : actions_num = modify_hdr->actions_num;
10341 : 0 : id = (uint64_t)(uintptr_t)modify_hdr->action;
10342 : : type = DR_DUMP_REC_TYPE_PMD_MODIFY_HDR;
10343 : 0 : save_dump_file(data, size, type, id,
10344 : : (void *)(&actions_num), file);
10345 : 0 : e = LIST_NEXT(e, next);
10346 : : }
10347 : : }
10348 : : }
10349 : : } else {
10350 [ # # ]: 0 : for (j = 0; j <= h->mask; j++) {
10351 : : l_inconst = &h->buckets[j].l;
10352 [ # # ]: 0 : if (!l_inconst || !l_inconst->cache[i])
10353 : 0 : continue;
10354 : :
10355 : 0 : e = LIST_FIRST(&l_inconst->cache[i]->h);
10356 [ # # ]: 0 : while (e) {
10357 : : modify_hdr =
10358 : : (struct mlx5_flow_dv_modify_hdr_resource *)e;
10359 : 0 : data = (const uint8_t *)modify_hdr->actions;
10360 : 0 : size = (size_t)(modify_hdr->actions_num) * 8;
10361 : 0 : actions_num = modify_hdr->actions_num;
10362 : 0 : id = (uint64_t)(uintptr_t)modify_hdr->action;
10363 : : type = DR_DUMP_REC_TYPE_PMD_MODIFY_HDR;
10364 : 0 : save_dump_file(data, size, type, id,
10365 : : (void *)(&actions_num), file);
10366 : 0 : e = LIST_NEXT(e, next);
10367 : : }
10368 : : }
10369 : : }
10370 : :
10371 [ # # ]: 0 : if (unlikely(lcore_index == MLX5_LIST_NLCORE))
10372 : 0 : rte_spinlock_unlock(&h->l_const.lcore_lock);
10373 : : }
10374 : :
10375 : : /* get counter */
10376 : : MLX5_ASSERT(cmng->n_valid <= MLX5_COUNTER_POOLS_MAX_NUM);
10377 : 0 : max = MLX5_COUNTERS_PER_POOL * cmng->n_valid;
10378 [ # # ]: 0 : for (j = 1; j <= max; j++) {
10379 : 0 : action = NULL;
10380 [ # # ]: 0 : if ((!mlx5_counter_query(dev, j, false, &count.hits,
10381 [ # # ]: 0 : &count.bytes, &action)) && action) {
10382 : 0 : id = (uint64_t)(uintptr_t)action;
10383 : : type = DR_DUMP_REC_TYPE_PMD_COUNTER;
10384 : 0 : save_dump_file(NULL, 0, type,
10385 : : id, (void *)&count, file);
10386 : : }
10387 : : }
10388 : 0 : return 0;
10389 : : }
10390 : : #endif
10391 : :
10392 : : /**
10393 : : * Dump flow raw hw data to file
10394 : : *
10395 : : * @param[in] dev
10396 : : * The pointer to Ethernet device.
10397 : : * @param[in] file
10398 : : * A pointer to a file for output.
10399 : : * @param[out] error
10400 : : * Perform verbose error reporting if not NULL. PMDs initialize this
10401 : : * structure in case of error only.
10402 : : * @return
10403 : : * 0 on success, a negative value otherwise.
10404 : : */
10405 : : int
10406 : 0 : mlx5_flow_dev_dump(struct rte_eth_dev *dev, struct rte_flow *flow_idx,
10407 : : FILE *file,
10408 : : struct rte_flow_error *error __rte_unused)
10409 : : {
10410 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10411 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
10412 : : uint32_t handle_idx;
10413 : : int ret;
10414 : : struct mlx5_flow_handle *dh;
10415 : : struct rte_flow *flow;
10416 : :
10417 [ # # ]: 0 : if (!sh->config.dv_flow_en) {
10418 [ # # ]: 0 : if (fputs("device dv flow disabled\n", file) <= 0)
10419 : 0 : return -errno;
10420 : : return -ENOTSUP;
10421 : : }
10422 : :
10423 : : /* dump all */
10424 [ # # ]: 0 : if (!flow_idx) {
10425 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
10426 [ # # ]: 0 : if (mlx5_flow_dev_dump_sh_all(dev, file, error))
10427 : : return -EINVAL;
10428 : :
10429 [ # # ]: 0 : if (sh->config.dv_flow_en == 2)
10430 : 0 : return mlx5dr_debug_dump(priv->dr_ctx, file);
10431 : : #endif
10432 : 0 : return mlx5_devx_cmd_flow_dump(sh->fdb_domain,
10433 : : sh->rx_domain,
10434 : : sh->tx_domain, file);
10435 : : }
10436 : : /* dump one */
10437 : 0 : flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
10438 : : (uintptr_t)(void *)flow_idx);
10439 [ # # ]: 0 : if (!flow)
10440 : : return -EINVAL;
10441 : :
10442 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
10443 : 0 : mlx5_flow_dev_dump_ipool(dev, flow, file, error);
10444 : : #endif
10445 : 0 : handle_idx = flow->dev_handles;
10446 [ # # ]: 0 : while (handle_idx) {
10447 : 0 : dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
10448 : : handle_idx);
10449 [ # # ]: 0 : if (!dh)
10450 : : return -ENOENT;
10451 [ # # ]: 0 : if (dh->drv_flow) {
10452 [ # # ]: 0 : if (sh->config.dv_flow_en == 2)
10453 : : return -ENOTSUP;
10454 : :
10455 : 0 : ret = mlx5_devx_cmd_flow_single_dump(dh->drv_flow,
10456 : : file);
10457 [ # # ]: 0 : if (ret)
10458 : : return -ENOENT;
10459 : : }
10460 : 0 : handle_idx = dh->next.next;
10461 : : }
10462 : : return 0;
10463 : : }
10464 : :
10465 : : /**
10466 : : * Get aged-out flows.
10467 : : *
10468 : : * @param[in] dev
10469 : : * Pointer to the Ethernet device structure.
10470 : : * @param[in] context
10471 : : * The address of an array of pointers to the aged-out flows contexts.
10472 : : * @param[in] nb_countexts
10473 : : * The length of context array pointers.
10474 : : * @param[out] error
10475 : : * Perform verbose error reporting if not NULL. Initialized in case of
10476 : : * error only.
10477 : : *
10478 : : * @return
10479 : : * how many contexts get in success, otherwise negative errno value.
10480 : : * if nb_contexts is 0, return the amount of all aged contexts.
10481 : : * if nb_contexts is not 0 , return the amount of aged flows reported
10482 : : * in the context array.
10483 : : */
10484 : : int
10485 [ # # ]: 0 : mlx5_flow_get_aged_flows(struct rte_eth_dev *dev, void **contexts,
10486 : : uint32_t nb_contexts, struct rte_flow_error *error)
10487 : : {
10488 : : struct rte_flow_attr attr = { .transfer = 0 };
10489 : :
10490 : 0 : return flow_get_drv_ops(flow_get_drv_type(dev, &attr))->get_aged_flows
10491 : : (dev, contexts, nb_contexts, error);
10492 : : }
10493 : :
10494 : : /**
10495 : : * Get aged-out flows per HWS queue.
10496 : : *
10497 : : * @param[in] dev
10498 : : * Pointer to the Ethernet device structure.
10499 : : * @param[in] queue_id
10500 : : * Flow queue to query.
10501 : : * @param[in] context
10502 : : * The address of an array of pointers to the aged-out flows contexts.
10503 : : * @param[in] nb_countexts
10504 : : * The length of context array pointers.
10505 : : * @param[out] error
10506 : : * Perform verbose error reporting if not NULL. Initialized in case of
10507 : : * error only.
10508 : : *
10509 : : * @return
10510 : : * how many contexts get in success, otherwise negative errno value.
10511 : : * if nb_contexts is 0, return the amount of all aged contexts.
10512 : : * if nb_contexts is not 0 , return the amount of aged flows reported
10513 : : * in the context array.
10514 : : */
10515 : : int
10516 [ # # ]: 0 : mlx5_flow_get_q_aged_flows(struct rte_eth_dev *dev, uint32_t queue_id,
10517 : : void **contexts, uint32_t nb_contexts,
10518 : : struct rte_flow_error *error)
10519 : : {
10520 : : const struct mlx5_flow_driver_ops *fops;
10521 : : struct rte_flow_attr attr = { 0 };
10522 : :
10523 : : if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_HW) {
10524 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
10525 : 0 : return fops->get_q_aged_flows(dev, queue_id, contexts,
10526 : : nb_contexts, error);
10527 : : }
10528 : 0 : DRV_LOG(ERR, "port %u queue %u get aged flows is not supported.",
10529 : : dev->data->port_id, queue_id);
10530 : 0 : return rte_flow_error_set(error, ENOTSUP,
10531 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10532 : : "get Q aged flows with incorrect steering mode");
10533 : : }
10534 : :
10535 : : /* Wrapper for driver action_validate op callback */
10536 : : static int
10537 : 0 : flow_drv_action_validate(struct rte_eth_dev *dev,
10538 : : const struct rte_flow_indir_action_conf *conf,
10539 : : const struct rte_flow_action *action,
10540 : : const struct mlx5_flow_driver_ops *fops,
10541 : : struct rte_flow_error *error)
10542 : : {
10543 : : static const char err_msg[] = "indirect action validation unsupported";
10544 : :
10545 [ # # ]: 0 : if (!fops->action_validate) {
10546 : 0 : DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
10547 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
10548 : : NULL, err_msg);
10549 : 0 : return -rte_errno;
10550 : : }
10551 : 0 : return fops->action_validate(dev, conf, action, error);
10552 : : }
10553 : :
10554 : : /**
10555 : : * Destroys the shared action by handle.
10556 : : *
10557 : : * @param dev
10558 : : * Pointer to Ethernet device structure.
10559 : : * @param[in] handle
10560 : : * Handle for the indirect action object to be destroyed.
10561 : : * @param[out] error
10562 : : * Perform verbose error reporting if not NULL. PMDs initialize this
10563 : : * structure in case of error only.
10564 : : *
10565 : : * @return
10566 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
10567 : : *
10568 : : * @note: wrapper for driver action_create op callback.
10569 : : */
10570 : : static int
10571 [ # # ]: 0 : mlx5_action_handle_destroy(struct rte_eth_dev *dev,
10572 : : struct rte_flow_action_handle *handle,
10573 : : struct rte_flow_error *error)
10574 : : {
10575 : : static const char err_msg[] = "indirect action destruction unsupported";
10576 : : struct rte_flow_attr attr = { .transfer = 0 };
10577 : 0 : const struct mlx5_flow_driver_ops *fops =
10578 : : flow_get_drv_ops(flow_get_drv_type(dev, &attr));
10579 : :
10580 [ # # ]: 0 : if (!fops->action_destroy) {
10581 : 0 : DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
10582 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
10583 : : NULL, err_msg);
10584 : 0 : return -rte_errno;
10585 : : }
10586 : 0 : return fops->action_destroy(dev, handle, error);
10587 : : }
10588 : :
10589 : : /* Wrapper for driver action_destroy op callback */
10590 : : static int
10591 : 0 : flow_drv_action_update(struct rte_eth_dev *dev,
10592 : : struct rte_flow_action_handle *handle,
10593 : : const void *update,
10594 : : const struct mlx5_flow_driver_ops *fops,
10595 : : struct rte_flow_error *error)
10596 : : {
10597 : : static const char err_msg[] = "indirect action update unsupported";
10598 : :
10599 [ # # ]: 0 : if (!fops->action_update) {
10600 : 0 : DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
10601 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
10602 : : NULL, err_msg);
10603 : 0 : return -rte_errno;
10604 : : }
10605 : 0 : return fops->action_update(dev, handle, update, error);
10606 : : }
10607 : :
10608 : : /* Wrapper for driver action_destroy op callback */
10609 : : static int
10610 : 0 : flow_drv_action_query(struct rte_eth_dev *dev,
10611 : : const struct rte_flow_action_handle *handle,
10612 : : void *data,
10613 : : const struct mlx5_flow_driver_ops *fops,
10614 : : struct rte_flow_error *error)
10615 : : {
10616 : : static const char err_msg[] = "indirect action query unsupported";
10617 : :
10618 [ # # ]: 0 : if (!fops->action_query) {
10619 : 0 : DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
10620 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
10621 : : NULL, err_msg);
10622 : 0 : return -rte_errno;
10623 : : }
10624 : 0 : return fops->action_query(dev, handle, data, error);
10625 : : }
10626 : :
10627 : : /**
10628 : : * Create indirect action for reuse in multiple flow rules.
10629 : : *
10630 : : * @param dev
10631 : : * Pointer to Ethernet device structure.
10632 : : * @param conf
10633 : : * Pointer to indirect action object configuration.
10634 : : * @param[in] action
10635 : : * Action configuration for indirect action object creation.
10636 : : * @param[out] error
10637 : : * Perform verbose error reporting if not NULL. PMDs initialize this
10638 : : * structure in case of error only.
10639 : : * @return
10640 : : * A valid handle in case of success, NULL otherwise and rte_errno is set.
10641 : : */
10642 : : static struct rte_flow_action_handle *
10643 [ # # ]: 0 : mlx5_action_handle_create(struct rte_eth_dev *dev,
10644 : : const struct rte_flow_indir_action_conf *conf,
10645 : : const struct rte_flow_action *action,
10646 : : struct rte_flow_error *error)
10647 : : {
10648 : : static const char err_msg[] = "indirect action creation unsupported";
10649 : : struct rte_flow_attr attr = { .transfer = 0 };
10650 : 0 : const struct mlx5_flow_driver_ops *fops =
10651 : : flow_get_drv_ops(flow_get_drv_type(dev, &attr));
10652 : :
10653 [ # # ]: 0 : if (flow_drv_action_validate(dev, conf, action, fops, error))
10654 : : return NULL;
10655 [ # # ]: 0 : if (!fops->action_create) {
10656 : 0 : DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
10657 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
10658 : : NULL, err_msg);
10659 : 0 : return NULL;
10660 : : }
10661 : 0 : return fops->action_create(dev, conf, action, error);
10662 : : }
10663 : :
10664 : : /**
10665 : : * Updates inplace the indirect action configuration pointed by *handle*
10666 : : * with the configuration provided as *update* argument.
10667 : : * The update of the indirect action configuration effects all flow rules
10668 : : * reusing the action via handle.
10669 : : *
10670 : : * @param dev
10671 : : * Pointer to Ethernet device structure.
10672 : : * @param[in] handle
10673 : : * Handle for the indirect action to be updated.
10674 : : * @param[in] update
10675 : : * Action specification used to modify the action pointed by handle.
10676 : : * *update* could be of same type with the action pointed by the *handle*
10677 : : * handle argument, or some other structures like a wrapper, depending on
10678 : : * the indirect action type.
10679 : : * @param[out] error
10680 : : * Perform verbose error reporting if not NULL. PMDs initialize this
10681 : : * structure in case of error only.
10682 : : *
10683 : : * @return
10684 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
10685 : : */
10686 : : static int
10687 [ # # ]: 0 : mlx5_action_handle_update(struct rte_eth_dev *dev,
10688 : : struct rte_flow_action_handle *handle,
10689 : : const void *update,
10690 : : struct rte_flow_error *error)
10691 : : {
10692 : : struct rte_flow_attr attr = { .transfer = 0 };
10693 : 0 : const struct mlx5_flow_driver_ops *fops =
10694 : : flow_get_drv_ops(flow_get_drv_type(dev, &attr));
10695 : : int ret;
10696 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
10697 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
10698 : :
10699 [ # # ]: 0 : switch (type) {
10700 : : case MLX5_INDIRECT_ACTION_TYPE_CT:
10701 : : case MLX5_INDIRECT_ACTION_TYPE_METER_MARK:
10702 : : ret = 0;
10703 : : break;
10704 : 0 : default:
10705 : 0 : ret = flow_drv_action_validate(dev, NULL,
10706 : : (const struct rte_flow_action *)update,
10707 : : fops, error);
10708 : : }
10709 [ # # ]: 0 : if (ret)
10710 : : return ret;
10711 : 0 : return flow_drv_action_update(dev, handle, update, fops,
10712 : : error);
10713 : : }
10714 : :
10715 : : /**
10716 : : * Query the indirect action by handle.
10717 : : *
10718 : : * This function allows retrieving action-specific data such as counters.
10719 : : * Data is gathered by special action which may be present/referenced in
10720 : : * more than one flow rule definition.
10721 : : *
10722 : : * see @RTE_FLOW_ACTION_TYPE_COUNT
10723 : : *
10724 : : * @param dev
10725 : : * Pointer to Ethernet device structure.
10726 : : * @param[in] handle
10727 : : * Handle for the indirect action to query.
10728 : : * @param[in, out] data
10729 : : * Pointer to storage for the associated query data type.
10730 : : * @param[out] error
10731 : : * Perform verbose error reporting if not NULL. PMDs initialize this
10732 : : * structure in case of error only.
10733 : : *
10734 : : * @return
10735 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
10736 : : */
10737 : : static int
10738 [ # # ]: 0 : mlx5_action_handle_query(struct rte_eth_dev *dev,
10739 : : const struct rte_flow_action_handle *handle,
10740 : : void *data,
10741 : : struct rte_flow_error *error)
10742 : : {
10743 : : struct rte_flow_attr attr = { .transfer = 0 };
10744 : 0 : const struct mlx5_flow_driver_ops *fops =
10745 : : flow_get_drv_ops(flow_get_drv_type(dev, &attr));
10746 : :
10747 : 0 : return flow_drv_action_query(dev, handle, data, fops, error);
10748 : : }
10749 : :
10750 : : static int
10751 [ # # ]: 0 : mlx5_action_handle_query_update(struct rte_eth_dev *dev,
10752 : : struct rte_flow_action_handle *handle,
10753 : : const void *update, void *query,
10754 : : enum rte_flow_query_update_mode qu_mode,
10755 : : struct rte_flow_error *error)
10756 : : {
10757 : : struct rte_flow_attr attr = { .transfer = 0 };
10758 : : enum mlx5_flow_drv_type drv_type = flow_get_drv_type(dev, &attr);
10759 : : const struct mlx5_flow_driver_ops *fops;
10760 : :
10761 : : if (drv_type == MLX5_FLOW_TYPE_MIN || drv_type == MLX5_FLOW_TYPE_MAX)
10762 : : return rte_flow_error_set(error, ENOTSUP,
10763 : : RTE_FLOW_ERROR_TYPE_ACTION,
10764 : : NULL, "invalid driver type");
10765 : 0 : fops = flow_get_drv_ops(drv_type);
10766 [ # # # # ]: 0 : if (!fops || !fops->action_query_update)
10767 : 0 : return rte_flow_error_set(error, ENOTSUP,
10768 : : RTE_FLOW_ERROR_TYPE_ACTION,
10769 : : NULL, "no query_update handler");
10770 : 0 : return fops->action_query_update(dev, handle, update,
10771 : : query, qu_mode, error);
10772 : : }
10773 : :
10774 : :
10775 : : #define MLX5_DRV_FOPS_OR_ERR(dev, fops, drv_cb, ret) \
10776 : : { \
10777 : : struct rte_flow_attr attr = { .transfer = 0 }; \
10778 : : enum mlx5_flow_drv_type drv_type = flow_get_drv_type((dev), &attr); \
10779 : : if (drv_type == MLX5_FLOW_TYPE_MIN || \
10780 : : drv_type == MLX5_FLOW_TYPE_MAX) { \
10781 : : rte_flow_error_set(error, ENOTSUP, \
10782 : : RTE_FLOW_ERROR_TYPE_ACTION, \
10783 : : NULL, "invalid driver type"); \
10784 : : return ret; \
10785 : : } \
10786 : : (fops) = flow_get_drv_ops(drv_type); \
10787 : : if (!(fops) || !(fops)->drv_cb) { \
10788 : : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, \
10789 : : NULL, "no action_list handler"); \
10790 : : return ret; \
10791 : : } \
10792 : : }
10793 : :
10794 : : static struct rte_flow_action_list_handle *
10795 [ # # ]: 0 : mlx5_action_list_handle_create(struct rte_eth_dev *dev,
10796 : : const struct rte_flow_indir_action_conf *conf,
10797 : : const struct rte_flow_action *actions,
10798 : : struct rte_flow_error *error)
10799 : : {
10800 : : const struct mlx5_flow_driver_ops *fops;
10801 : :
10802 [ # # # # ]: 0 : MLX5_DRV_FOPS_OR_ERR(dev, fops, action_list_handle_create, NULL);
10803 : 0 : return fops->action_list_handle_create(dev, conf, actions, error);
10804 : : }
10805 : :
10806 : : static int
10807 [ # # ]: 0 : mlx5_action_list_handle_destroy(struct rte_eth_dev *dev,
10808 : : struct rte_flow_action_list_handle *handle,
10809 : : struct rte_flow_error *error)
10810 : : {
10811 : : const struct mlx5_flow_driver_ops *fops;
10812 : :
10813 [ # # # # ]: 0 : MLX5_DRV_FOPS_OR_ERR(dev, fops, action_list_handle_destroy, ENOTSUP);
10814 : 0 : return fops->action_list_handle_destroy(dev, handle, error);
10815 : : }
10816 : :
10817 : : static int
10818 [ # # ]: 0 : mlx5_flow_action_list_handle_query_update(struct rte_eth_dev *dev,
10819 : : const
10820 : : struct rte_flow_action_list_handle *handle,
10821 : : const void **update, void **query,
10822 : : enum rte_flow_query_update_mode mode,
10823 : : struct rte_flow_error *error)
10824 : : {
10825 : : const struct mlx5_flow_driver_ops *fops;
10826 : :
10827 [ # # # # ]: 0 : MLX5_DRV_FOPS_OR_ERR(dev, fops,
10828 : : action_list_handle_query_update, ENOTSUP);
10829 : 0 : return fops->action_list_handle_query_update(dev, handle, update, query,
10830 : : mode, error);
10831 : : }
10832 : : static int
10833 [ # # ]: 0 : mlx5_flow_calc_table_hash(struct rte_eth_dev *dev,
10834 : : const struct rte_flow_template_table *table,
10835 : : const struct rte_flow_item pattern[],
10836 : : uint8_t pattern_template_index,
10837 : : uint32_t *hash, struct rte_flow_error *error)
10838 : : {
10839 : : struct rte_flow_attr attr = { .transfer = 0 };
10840 : : enum mlx5_flow_drv_type drv_type = flow_get_drv_type(dev, &attr);
10841 : : const struct mlx5_flow_driver_ops *fops;
10842 : :
10843 : : if (drv_type == MLX5_FLOW_TYPE_MIN || drv_type == MLX5_FLOW_TYPE_MAX)
10844 : : return rte_flow_error_set(error, ENOTSUP,
10845 : : RTE_FLOW_ERROR_TYPE_ACTION,
10846 : : NULL, "invalid driver type");
10847 : 0 : fops = flow_get_drv_ops(drv_type);
10848 [ # # # # ]: 0 : if (!fops || !fops->action_query_update)
10849 : 0 : return rte_flow_error_set(error, ENOTSUP,
10850 : : RTE_FLOW_ERROR_TYPE_ACTION,
10851 : : NULL, "no query_update handler");
10852 : 0 : return fops->flow_calc_table_hash(dev, table, pattern, pattern_template_index,
10853 : : hash, error);
10854 : : }
10855 : :
10856 : : static int
10857 [ # # ]: 0 : mlx5_flow_calc_encap_hash(struct rte_eth_dev *dev,
10858 : : const struct rte_flow_item pattern[],
10859 : : enum rte_flow_encap_hash_field dest_field,
10860 : : uint8_t *hash,
10861 : : struct rte_flow_error *error)
10862 : : {
10863 : : enum mlx5_flow_drv_type drv_type = flow_get_drv_type(dev, NULL);
10864 : : const struct mlx5_flow_driver_ops *fops;
10865 : :
10866 : : if (drv_type == MLX5_FLOW_TYPE_MIN || drv_type == MLX5_FLOW_TYPE_MAX)
10867 : 0 : return rte_flow_error_set(error, ENOTSUP,
10868 : : RTE_FLOW_ERROR_TYPE_ACTION,
10869 : : NULL, "invalid driver type");
10870 : 0 : fops = flow_get_drv_ops(drv_type);
10871 [ # # # # ]: 0 : if (!fops || !fops->flow_calc_encap_hash)
10872 : 0 : return rte_flow_error_set(error, ENOTSUP,
10873 : : RTE_FLOW_ERROR_TYPE_ACTION,
10874 : : NULL, "no calc encap hash handler");
10875 : 0 : return fops->flow_calc_encap_hash(dev, pattern, dest_field, hash, error);
10876 : : }
10877 : :
10878 : : static int
10879 [ # # ]: 0 : mlx5_template_table_resize(struct rte_eth_dev *dev,
10880 : : struct rte_flow_template_table *table,
10881 : : uint32_t nb_rules, struct rte_flow_error *error)
10882 : : {
10883 : : const struct mlx5_flow_driver_ops *fops;
10884 : :
10885 [ # # # # ]: 0 : MLX5_DRV_FOPS_OR_ERR(dev, fops, table_resize, ENOTSUP);
10886 : 0 : return fops->table_resize(dev, table, nb_rules, error);
10887 : : }
10888 : :
10889 : : static int
10890 [ # # ]: 0 : mlx5_table_resize_complete(struct rte_eth_dev *dev,
10891 : : struct rte_flow_template_table *table,
10892 : : struct rte_flow_error *error)
10893 : : {
10894 : : const struct mlx5_flow_driver_ops *fops;
10895 : :
10896 [ # # # # ]: 0 : MLX5_DRV_FOPS_OR_ERR(dev, fops, table_resize_complete, ENOTSUP);
10897 : 0 : return fops->table_resize_complete(dev, table, error);
10898 : : }
10899 : :
10900 : : static int
10901 [ # # ]: 0 : mlx5_flow_async_update_resized(struct rte_eth_dev *dev, uint32_t queue,
10902 : : const struct rte_flow_op_attr *op_attr,
10903 : : struct rte_flow *rule, void *user_data,
10904 : : struct rte_flow_error *error)
10905 : : {
10906 : : const struct mlx5_flow_driver_ops *fops;
10907 : :
10908 [ # # # # ]: 0 : MLX5_DRV_FOPS_OR_ERR(dev, fops, flow_update_resized, ENOTSUP);
10909 : 0 : return fops->flow_update_resized(dev, queue, op_attr, rule, user_data, error);
10910 : : }
10911 : :
10912 : : /**
10913 : : * Destroy all indirect actions (shared RSS).
10914 : : *
10915 : : * @param dev
10916 : : * Pointer to Ethernet device.
10917 : : *
10918 : : * @return
10919 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
10920 : : */
10921 : : int
10922 : 0 : mlx5_action_handle_flush(struct rte_eth_dev *dev)
10923 : : {
10924 : : struct rte_flow_error error;
10925 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10926 : : struct mlx5_shared_action_rss *shared_rss;
10927 : : int ret = 0;
10928 : : uint32_t idx;
10929 : :
10930 [ # # # # ]: 0 : ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
10931 : : priv->rss_shared_actions, idx, shared_rss, next) {
10932 [ # # ]: 0 : ret |= mlx5_action_handle_destroy(dev,
10933 : 0 : (struct rte_flow_action_handle *)(uintptr_t)idx, &error);
10934 : : }
10935 : 0 : return ret;
10936 : : }
10937 : :
10938 : : /**
10939 : : * Validate existing indirect actions against current device configuration
10940 : : * and attach them to device resources.
10941 : : *
10942 : : * @param dev
10943 : : * Pointer to Ethernet device.
10944 : : *
10945 : : * @return
10946 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
10947 : : */
10948 : : int
10949 : 0 : mlx5_action_handle_attach(struct rte_eth_dev *dev)
10950 : : {
10951 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10952 : : int ret = 0;
10953 : : struct mlx5_ind_table_obj *ind_tbl, *ind_tbl_last;
10954 : :
10955 [ # # ]: 0 : LIST_FOREACH(ind_tbl, &priv->standalone_ind_tbls, next) {
10956 : : const char *message;
10957 : : uint32_t queue_idx;
10958 : :
10959 : 0 : ret = mlx5_validate_rss_queues(dev, ind_tbl->queues,
10960 : : ind_tbl->queues_n,
10961 : : &message, &queue_idx);
10962 [ # # ]: 0 : if (ret != 0) {
10963 : 0 : DRV_LOG(ERR, "Port %u cannot use queue %u in RSS: %s",
10964 : : dev->data->port_id, ind_tbl->queues[queue_idx],
10965 : : message);
10966 : 0 : break;
10967 : : }
10968 : : }
10969 [ # # ]: 0 : if (ret != 0)
10970 : : return ret;
10971 [ # # ]: 0 : LIST_FOREACH(ind_tbl, &priv->standalone_ind_tbls, next) {
10972 : 0 : ret = mlx5_ind_table_obj_attach(dev, ind_tbl);
10973 [ # # ]: 0 : if (ret != 0) {
10974 : 0 : DRV_LOG(ERR, "Port %u could not attach "
10975 : : "indirection table obj %p",
10976 : : dev->data->port_id, (void *)ind_tbl);
10977 : 0 : goto error;
10978 : : }
10979 : : }
10980 : :
10981 : : return 0;
10982 : : error:
10983 : : ind_tbl_last = ind_tbl;
10984 [ # # ]: 0 : LIST_FOREACH(ind_tbl, &priv->standalone_ind_tbls, next) {
10985 [ # # ]: 0 : if (ind_tbl == ind_tbl_last)
10986 : : break;
10987 [ # # ]: 0 : if (mlx5_ind_table_obj_detach(dev, ind_tbl) != 0)
10988 : 0 : DRV_LOG(CRIT, "Port %u could not detach "
10989 : : "indirection table obj %p on rollback",
10990 : : dev->data->port_id, (void *)ind_tbl);
10991 : : }
10992 : : return ret;
10993 : : }
10994 : :
10995 : : /**
10996 : : * Detach indirect actions of the device from its resources.
10997 : : *
10998 : : * @param dev
10999 : : * Pointer to Ethernet device.
11000 : : *
11001 : : * @return
11002 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
11003 : : */
11004 : : int
11005 : 0 : mlx5_action_handle_detach(struct rte_eth_dev *dev)
11006 : : {
11007 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11008 : : int ret = 0;
11009 : : struct mlx5_ind_table_obj *ind_tbl, *ind_tbl_last;
11010 : :
11011 [ # # ]: 0 : LIST_FOREACH(ind_tbl, &priv->standalone_ind_tbls, next) {
11012 : 0 : ret = mlx5_ind_table_obj_detach(dev, ind_tbl);
11013 [ # # ]: 0 : if (ret != 0) {
11014 : 0 : DRV_LOG(ERR, "Port %u could not detach "
11015 : : "indirection table obj %p",
11016 : : dev->data->port_id, (void *)ind_tbl);
11017 : 0 : goto error;
11018 : : }
11019 : : }
11020 : : return 0;
11021 : : error:
11022 : : ind_tbl_last = ind_tbl;
11023 [ # # ]: 0 : LIST_FOREACH(ind_tbl, &priv->standalone_ind_tbls, next) {
11024 [ # # ]: 0 : if (ind_tbl == ind_tbl_last)
11025 : : break;
11026 [ # # ]: 0 : if (mlx5_ind_table_obj_attach(dev, ind_tbl) != 0)
11027 : 0 : DRV_LOG(CRIT, "Port %u could not attach "
11028 : : "indirection table obj %p on rollback",
11029 : : dev->data->port_id, (void *)ind_tbl);
11030 : : }
11031 : : return ret;
11032 : : }
11033 : :
11034 : : #ifndef HAVE_MLX5DV_DR
11035 : : #define MLX5_DOMAIN_SYNC_FLOW ((1 << 0) | (1 << 1))
11036 : : #else
11037 : : #define MLX5_DOMAIN_SYNC_FLOW \
11038 : : (MLX5DV_DR_DOMAIN_SYNC_FLAGS_SW | MLX5DV_DR_DOMAIN_SYNC_FLAGS_HW)
11039 : : #endif
11040 : :
11041 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_mlx5_sync_flow, 20.11)
11042 : 0 : int rte_pmd_mlx5_sync_flow(uint16_t port_id, uint32_t domains)
11043 : : {
11044 [ # # ]: 0 : struct rte_eth_dev *dev = &rte_eth_devices[port_id];
11045 : : const struct mlx5_flow_driver_ops *fops;
11046 : : int ret;
11047 : : struct rte_flow_attr attr = { .transfer = 0 };
11048 : :
11049 : 0 : fops = flow_get_drv_ops(flow_get_drv_type(dev, &attr));
11050 : 0 : ret = fops->sync_domain(dev, domains, MLX5_DOMAIN_SYNC_FLOW);
11051 [ # # ]: 0 : if (ret > 0)
11052 : 0 : ret = -ret;
11053 : 0 : return ret;
11054 : : }
11055 : :
11056 : : const struct mlx5_flow_tunnel *
11057 : 0 : mlx5_get_tof(const struct rte_flow_item *item,
11058 : : const struct rte_flow_action *action,
11059 : : enum mlx5_tof_rule_type *rule_type)
11060 : : {
11061 [ # # ]: 0 : for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
11062 [ # # ]: 0 : if (item->type == (typeof(item->type))
11063 : : MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL) {
11064 : 0 : *rule_type = MLX5_TUNNEL_OFFLOAD_MATCH_RULE;
11065 : 0 : return flow_items_to_tunnel(item);
11066 : : }
11067 : : }
11068 [ # # ]: 0 : for (; action->conf != RTE_FLOW_ACTION_TYPE_END; action++) {
11069 [ # # ]: 0 : if (action->type == (typeof(action->type))
11070 : : MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET) {
11071 : 0 : *rule_type = MLX5_TUNNEL_OFFLOAD_SET_RULE;
11072 : 0 : return flow_actions_to_tunnel(action);
11073 : : }
11074 : : }
11075 : : return NULL;
11076 : : }
11077 : :
11078 : : /**
11079 : : * tunnel offload functionality is defined for DV environment only
11080 : : */
11081 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
11082 : : __extension__
11083 : : union tunnel_offload_mark {
11084 : : uint32_t val;
11085 : : struct {
11086 : : uint32_t app_reserve:8;
11087 : : uint32_t table_id:15;
11088 : : uint32_t transfer:1;
11089 : : uint32_t _unused_:8;
11090 : : };
11091 : : };
11092 : :
11093 : : static bool
11094 : : mlx5_access_tunnel_offload_db
11095 : : (struct rte_eth_dev *dev,
11096 : : bool (*match)(struct rte_eth_dev *,
11097 : : struct mlx5_flow_tunnel *, const void *),
11098 : : void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
11099 : : void (*miss)(struct rte_eth_dev *, void *),
11100 : : void *ctx, bool lock_op);
11101 : :
11102 : : static int
11103 : 0 : flow_tunnel_add_default_miss(struct rte_eth_dev *dev,
11104 : : struct rte_flow *flow,
11105 : : const struct rte_flow_attr *attr,
11106 : : const struct rte_flow_action *app_actions,
11107 : : uint32_t flow_idx,
11108 : : const struct mlx5_flow_tunnel *tunnel,
11109 : : struct tunnel_default_miss_ctx *ctx,
11110 : : struct rte_flow_error *error)
11111 : : {
11112 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11113 : : struct mlx5_flow *dev_flow;
11114 : 0 : struct rte_flow_attr miss_attr = *attr;
11115 : 0 : const struct rte_flow_item miss_items[2] = {
11116 : : {
11117 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
11118 : : .spec = NULL,
11119 : : .last = NULL,
11120 : : .mask = NULL
11121 : : },
11122 : : {
11123 : : .type = RTE_FLOW_ITEM_TYPE_END,
11124 : : .spec = NULL,
11125 : : .last = NULL,
11126 : : .mask = NULL
11127 : : }
11128 : : };
11129 : : union tunnel_offload_mark mark_id;
11130 : : struct rte_flow_action_mark miss_mark;
11131 : 0 : struct rte_flow_action miss_actions[3] = {
11132 : : [0] = { .type = RTE_FLOW_ACTION_TYPE_MARK, .conf = &miss_mark },
11133 : : [2] = { .type = RTE_FLOW_ACTION_TYPE_END, .conf = NULL }
11134 : : };
11135 : : const struct rte_flow_action_jump *jump_data;
11136 : 0 : uint32_t i, flow_table = 0; /* prevent compilation warning */
11137 : 0 : struct flow_grp_info grp_info = {
11138 : : .external = 1,
11139 : 0 : .transfer = attr->transfer,
11140 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
11141 : : .std_tbl_fix = 0,
11142 : : };
11143 : : int ret;
11144 : :
11145 [ # # ]: 0 : if (!attr->transfer) {
11146 : : uint32_t q_size;
11147 : :
11148 : 0 : miss_actions[1].type = RTE_FLOW_ACTION_TYPE_RSS;
11149 : 0 : q_size = priv->reta_idx_n * sizeof(ctx->queue[0]);
11150 : 0 : ctx->queue = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, q_size,
11151 : : 0, SOCKET_ID_ANY);
11152 [ # # ]: 0 : if (!ctx->queue)
11153 : 0 : return rte_flow_error_set
11154 : : (error, ENOMEM,
11155 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
11156 : : NULL, "invalid default miss RSS");
11157 : 0 : ctx->action_rss.func = RTE_ETH_HASH_FUNCTION_DEFAULT;
11158 : 0 : ctx->action_rss.level = 0;
11159 : 0 : ctx->action_rss.types = priv->rss_conf.rss_hf;
11160 : 0 : ctx->action_rss.key_len = priv->rss_conf.rss_key_len;
11161 : 0 : ctx->action_rss.queue_num = priv->reta_idx_n;
11162 : 0 : ctx->action_rss.key = priv->rss_conf.rss_key;
11163 : 0 : ctx->action_rss.queue = ctx->queue;
11164 [ # # # # ]: 0 : if (!priv->reta_idx_n || !priv->rxqs_n)
11165 : 0 : return rte_flow_error_set
11166 : : (error, EINVAL,
11167 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
11168 : : NULL, "invalid port configuration");
11169 [ # # ]: 0 : if (!(dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG))
11170 : 0 : ctx->action_rss.types = 0;
11171 [ # # ]: 0 : for (i = 0; i != priv->reta_idx_n; ++i)
11172 : 0 : ctx->queue[i] = (*priv->reta_idx)[i];
11173 : : } else {
11174 : 0 : miss_actions[1].type = RTE_FLOW_ACTION_TYPE_JUMP;
11175 : 0 : ctx->miss_jump.group = MLX5_TNL_MISS_FDB_JUMP_GRP;
11176 : : }
11177 : 0 : miss_actions[1].conf = (typeof(miss_actions[1].conf))ctx->raw;
11178 [ # # ]: 0 : for (; app_actions->type != RTE_FLOW_ACTION_TYPE_JUMP; app_actions++);
11179 : 0 : jump_data = app_actions->conf;
11180 : 0 : miss_attr.priority = MLX5_TNL_MISS_RULE_PRIORITY;
11181 : 0 : miss_attr.group = jump_data->group;
11182 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel, jump_data->group,
11183 : : &flow_table, &grp_info, error);
11184 [ # # ]: 0 : if (ret)
11185 : 0 : return rte_flow_error_set(error, EINVAL,
11186 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
11187 : : NULL, "invalid tunnel id");
11188 : 0 : mark_id.app_reserve = 0;
11189 : 0 : mark_id.table_id = tunnel_flow_tbl_to_id(flow_table);
11190 : 0 : mark_id.transfer = !!attr->transfer;
11191 : 0 : mark_id._unused_ = 0;
11192 : 0 : miss_mark.id = mark_id.val;
11193 : : dev_flow = flow_drv_prepare(dev, flow, &miss_attr,
11194 : : miss_items, miss_actions, flow_idx, error);
11195 [ # # ]: 0 : if (!dev_flow)
11196 : 0 : return -rte_errno;
11197 : 0 : dev_flow->flow = flow;
11198 : 0 : dev_flow->external = true;
11199 : 0 : dev_flow->tunnel = tunnel;
11200 : 0 : dev_flow->tof_type = MLX5_TUNNEL_OFFLOAD_MISS_RULE;
11201 : : /* Subflow object was created, we must include one in the list. */
11202 : 0 : SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
11203 : : dev_flow->handle, next);
11204 : 0 : DRV_LOG(DEBUG,
11205 : : "port %u tunnel type=%d id=%u miss rule priority=%u group=%u",
11206 : : dev->data->port_id, tunnel->app_tunnel.type,
11207 : : tunnel->tunnel_id, miss_attr.priority, miss_attr.group);
11208 : : ret = flow_drv_translate(dev, dev_flow, &miss_attr, miss_items,
11209 : : miss_actions, error);
11210 [ # # ]: 0 : if (!ret)
11211 : 0 : ret = flow_mreg_update_copy_table(dev, flow, miss_actions,
11212 : : error);
11213 : :
11214 : : return ret;
11215 : : }
11216 : :
11217 : : static const struct mlx5_flow_tbl_data_entry *
11218 : 0 : tunnel_mark_decode(struct rte_eth_dev *dev, uint32_t mark)
11219 : : {
11220 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11221 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
11222 : : struct mlx5_list_entry *he;
11223 : 0 : union tunnel_offload_mark mbits = { .val = mark };
11224 : 0 : union mlx5_flow_tbl_key table_key = {
11225 : : {
11226 : 0 : .level = tunnel_id_to_flow_tbl(mbits.table_id),
11227 : : .id = 0,
11228 : : .reserved = 0,
11229 : : .dummy = 0,
11230 : 0 : .is_fdb = !!mbits.transfer,
11231 : : .is_egress = 0,
11232 : : }
11233 : : };
11234 : 0 : struct mlx5_flow_cb_ctx ctx = {
11235 : : .data = &table_key.v64,
11236 : : };
11237 : :
11238 : 0 : he = mlx5_hlist_lookup(sh->flow_tbls, table_key.v64, &ctx);
11239 : : return he ?
11240 [ # # ]: 0 : container_of(he, struct mlx5_flow_tbl_data_entry, entry) : NULL;
11241 : : }
11242 : :
11243 : : static void
11244 : 0 : mlx5_flow_tunnel_grp2tbl_remove_cb(void *tool_ctx,
11245 : : struct mlx5_list_entry *entry)
11246 : : {
11247 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11248 : : struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
11249 : :
11250 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
11251 : : tunnel_flow_tbl_to_id(tte->flow_table));
11252 : 0 : mlx5_free(tte);
11253 : 0 : }
11254 : :
11255 : : static int
11256 : 0 : mlx5_flow_tunnel_grp2tbl_match_cb(void *tool_ctx __rte_unused,
11257 : : struct mlx5_list_entry *entry, void *cb_ctx)
11258 : : {
11259 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11260 : : union tunnel_tbl_key tbl = {
11261 : 0 : .val = *(uint64_t *)(ctx->data),
11262 : : };
11263 : : struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
11264 : :
11265 [ # # # # ]: 0 : return tbl.tunnel_id != tte->tunnel_id || tbl.group != tte->group;
11266 : : }
11267 : :
11268 : : static struct mlx5_list_entry *
11269 : 0 : mlx5_flow_tunnel_grp2tbl_create_cb(void *tool_ctx, void *cb_ctx)
11270 : : {
11271 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11272 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11273 : : struct tunnel_tbl_entry *tte;
11274 : : union tunnel_tbl_key tbl = {
11275 : 0 : .val = *(uint64_t *)(ctx->data),
11276 : : };
11277 : :
11278 : 0 : tte = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO,
11279 : : sizeof(*tte), 0,
11280 : : SOCKET_ID_ANY);
11281 [ # # ]: 0 : if (!tte)
11282 : 0 : goto err;
11283 : 0 : mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
11284 : : &tte->flow_table);
11285 [ # # ]: 0 : if (tte->flow_table >= MLX5_MAX_TABLES) {
11286 : 0 : DRV_LOG(ERR, "Tunnel TBL ID %d exceed max limit.",
11287 : : tte->flow_table);
11288 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
11289 : : tte->flow_table);
11290 : 0 : goto err;
11291 [ # # ]: 0 : } else if (!tte->flow_table) {
11292 : 0 : goto err;
11293 : : }
11294 : 0 : tte->flow_table = tunnel_id_to_flow_tbl(tte->flow_table);
11295 : 0 : tte->tunnel_id = tbl.tunnel_id;
11296 : 0 : tte->group = tbl.group;
11297 : 0 : return &tte->hash;
11298 : 0 : err:
11299 [ # # ]: 0 : if (tte)
11300 : 0 : mlx5_free(tte);
11301 : : return NULL;
11302 : : }
11303 : :
11304 : : static struct mlx5_list_entry *
11305 : 0 : mlx5_flow_tunnel_grp2tbl_clone_cb(void *tool_ctx __rte_unused,
11306 : : struct mlx5_list_entry *oentry,
11307 : : void *cb_ctx __rte_unused)
11308 : : {
11309 : 0 : struct tunnel_tbl_entry *tte = mlx5_malloc(MLX5_MEM_SYS, sizeof(*tte),
11310 : : 0, SOCKET_ID_ANY);
11311 : :
11312 [ # # ]: 0 : if (!tte)
11313 : : return NULL;
11314 : : memcpy(tte, oentry, sizeof(*tte));
11315 : 0 : return &tte->hash;
11316 : : }
11317 : :
11318 : : static void
11319 : 0 : mlx5_flow_tunnel_grp2tbl_clone_free_cb(void *tool_ctx __rte_unused,
11320 : : struct mlx5_list_entry *entry)
11321 : : {
11322 : : struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
11323 : :
11324 : 0 : mlx5_free(tte);
11325 : 0 : }
11326 : :
11327 : : static uint32_t
11328 : 0 : tunnel_flow_group_to_flow_table(struct rte_eth_dev *dev,
11329 : : const struct mlx5_flow_tunnel *tunnel,
11330 : : uint32_t group, uint32_t *table,
11331 : : struct rte_flow_error *error)
11332 : : {
11333 : : struct mlx5_list_entry *he;
11334 : : struct tunnel_tbl_entry *tte;
11335 [ # # ]: 0 : union tunnel_tbl_key key = {
11336 [ # # ]: 0 : .tunnel_id = tunnel ? tunnel->tunnel_id : 0,
11337 : : .group = group
11338 : : };
11339 : : struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
11340 : : struct mlx5_hlist *group_hash;
11341 : 0 : struct mlx5_flow_cb_ctx ctx = {
11342 : : .data = &key.val,
11343 : : };
11344 : :
11345 [ # # ]: 0 : group_hash = tunnel ? tunnel->groups : thub->groups;
11346 : 0 : he = mlx5_hlist_register(group_hash, key.val, &ctx);
11347 [ # # ]: 0 : if (!he)
11348 : 0 : return rte_flow_error_set(error, EINVAL,
11349 : : RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
11350 : : NULL,
11351 : : "tunnel group index not supported");
11352 : : tte = container_of(he, typeof(*tte), hash);
11353 : 0 : *table = tte->flow_table;
11354 : 0 : DRV_LOG(DEBUG, "port %u tunnel %u group=%#x table=%#x",
11355 : : dev->data->port_id, key.tunnel_id, group, *table);
11356 : 0 : return 0;
11357 : : }
11358 : :
11359 : : static void
11360 : 0 : mlx5_flow_tunnel_free(struct rte_eth_dev *dev,
11361 : : struct mlx5_flow_tunnel *tunnel)
11362 : : {
11363 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11364 : : struct mlx5_indexed_pool *ipool;
11365 : :
11366 : 0 : DRV_LOG(DEBUG, "port %u release pmd tunnel id=0x%x",
11367 : : dev->data->port_id, tunnel->tunnel_id);
11368 [ # # ]: 0 : LIST_REMOVE(tunnel, chain);
11369 : 0 : mlx5_hlist_destroy(tunnel->groups);
11370 : 0 : ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
11371 : 0 : mlx5_ipool_free(ipool, tunnel->tunnel_id);
11372 : 0 : }
11373 : :
11374 : : static bool
11375 : 0 : mlx5_access_tunnel_offload_db
11376 : : (struct rte_eth_dev *dev,
11377 : : bool (*match)(struct rte_eth_dev *,
11378 : : struct mlx5_flow_tunnel *, const void *),
11379 : : void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
11380 : : void (*miss)(struct rte_eth_dev *, void *),
11381 : : void *ctx, bool lock_op)
11382 : : {
11383 : : bool verdict = false;
11384 : : struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
11385 : : struct mlx5_flow_tunnel *tunnel;
11386 : :
11387 : 0 : rte_spinlock_lock(&thub->sl);
11388 [ # # ]: 0 : LIST_FOREACH(tunnel, &thub->tunnels, chain) {
11389 : 0 : verdict = match(dev, tunnel, (const void *)ctx);
11390 [ # # ]: 0 : if (verdict)
11391 : : break;
11392 : : }
11393 [ # # ]: 0 : if (!lock_op)
11394 : : rte_spinlock_unlock(&thub->sl);
11395 [ # # ]: 0 : if (verdict && hit)
11396 : 0 : hit(dev, tunnel, ctx);
11397 [ # # ]: 0 : if (!verdict && miss)
11398 : 0 : miss(dev, ctx);
11399 [ # # ]: 0 : if (lock_op)
11400 : : rte_spinlock_unlock(&thub->sl);
11401 : :
11402 : 0 : return verdict;
11403 : : }
11404 : :
11405 : : struct tunnel_db_find_tunnel_id_ctx {
11406 : : uint32_t tunnel_id;
11407 : : struct mlx5_flow_tunnel *tunnel;
11408 : : };
11409 : :
11410 : : static bool
11411 : 0 : find_tunnel_id_match(struct rte_eth_dev *dev,
11412 : : struct mlx5_flow_tunnel *tunnel, const void *x)
11413 : : {
11414 : : const struct tunnel_db_find_tunnel_id_ctx *ctx = x;
11415 : :
11416 : : RTE_SET_USED(dev);
11417 : 0 : return tunnel->tunnel_id == ctx->tunnel_id;
11418 : : }
11419 : :
11420 : : static void
11421 : 0 : find_tunnel_id_hit(struct rte_eth_dev *dev,
11422 : : struct mlx5_flow_tunnel *tunnel, void *x)
11423 : : {
11424 : : struct tunnel_db_find_tunnel_id_ctx *ctx = x;
11425 : : RTE_SET_USED(dev);
11426 : 0 : ctx->tunnel = tunnel;
11427 : 0 : }
11428 : :
11429 : : static struct mlx5_flow_tunnel *
11430 : : mlx5_find_tunnel_id(struct rte_eth_dev *dev, uint32_t id)
11431 : : {
11432 : 0 : struct tunnel_db_find_tunnel_id_ctx ctx = {
11433 : : .tunnel_id = id,
11434 : : };
11435 : :
11436 : 0 : mlx5_access_tunnel_offload_db(dev, find_tunnel_id_match,
11437 : : find_tunnel_id_hit, NULL, &ctx, true);
11438 : :
11439 [ # # ]: 0 : return ctx.tunnel;
11440 : : }
11441 : :
11442 : : static struct mlx5_flow_tunnel *
11443 : 0 : mlx5_flow_tunnel_allocate(struct rte_eth_dev *dev,
11444 : : const struct rte_flow_tunnel *app_tunnel)
11445 : : {
11446 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11447 : : struct mlx5_indexed_pool *ipool;
11448 : : struct mlx5_flow_tunnel *tunnel;
11449 : : uint32_t id;
11450 : :
11451 : 0 : ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
11452 : 0 : tunnel = mlx5_ipool_zmalloc(ipool, &id);
11453 [ # # ]: 0 : if (!tunnel)
11454 : : return NULL;
11455 [ # # ]: 0 : if (id >= MLX5_MAX_TUNNELS) {
11456 : 0 : mlx5_ipool_free(ipool, id);
11457 : 0 : DRV_LOG(ERR, "Tunnel ID %d exceed max limit.", id);
11458 : 0 : return NULL;
11459 : : }
11460 : 0 : tunnel->groups = mlx5_hlist_create("tunnel groups", 64, false, true,
11461 : 0 : priv->sh,
11462 : : mlx5_flow_tunnel_grp2tbl_create_cb,
11463 : : mlx5_flow_tunnel_grp2tbl_match_cb,
11464 : : mlx5_flow_tunnel_grp2tbl_remove_cb,
11465 : : mlx5_flow_tunnel_grp2tbl_clone_cb,
11466 : : mlx5_flow_tunnel_grp2tbl_clone_free_cb);
11467 [ # # ]: 0 : if (!tunnel->groups) {
11468 : 0 : mlx5_ipool_free(ipool, id);
11469 : 0 : return NULL;
11470 : : }
11471 : : /* initiate new PMD tunnel */
11472 : 0 : memcpy(&tunnel->app_tunnel, app_tunnel, sizeof(*app_tunnel));
11473 : 0 : tunnel->tunnel_id = id;
11474 : 0 : tunnel->action.type = (typeof(tunnel->action.type))
11475 : : MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET;
11476 : 0 : tunnel->action.conf = tunnel;
11477 : 0 : tunnel->item.type = (typeof(tunnel->item.type))
11478 : : MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL;
11479 : 0 : tunnel->item.spec = tunnel;
11480 : 0 : tunnel->item.last = NULL;
11481 : 0 : tunnel->item.mask = NULL;
11482 : :
11483 : 0 : DRV_LOG(DEBUG, "port %u new pmd tunnel id=0x%x",
11484 : : dev->data->port_id, tunnel->tunnel_id);
11485 : :
11486 : 0 : return tunnel;
11487 : : }
11488 : :
11489 : : struct tunnel_db_get_tunnel_ctx {
11490 : : const struct rte_flow_tunnel *app_tunnel;
11491 : : struct mlx5_flow_tunnel *tunnel;
11492 : : };
11493 : :
11494 : 0 : static bool get_tunnel_match(struct rte_eth_dev *dev,
11495 : : struct mlx5_flow_tunnel *tunnel, const void *x)
11496 : : {
11497 : : const struct tunnel_db_get_tunnel_ctx *ctx = x;
11498 : :
11499 : : RTE_SET_USED(dev);
11500 : 0 : return !memcmp(ctx->app_tunnel, &tunnel->app_tunnel,
11501 : : sizeof(*ctx->app_tunnel));
11502 : : }
11503 : :
11504 : 0 : static void get_tunnel_hit(struct rte_eth_dev *dev,
11505 : : struct mlx5_flow_tunnel *tunnel, void *x)
11506 : : {
11507 : : /* called under tunnel spinlock protection */
11508 : : struct tunnel_db_get_tunnel_ctx *ctx = x;
11509 : :
11510 : : RTE_SET_USED(dev);
11511 : 0 : tunnel->refctn++;
11512 : 0 : ctx->tunnel = tunnel;
11513 : 0 : }
11514 : :
11515 : 0 : static void get_tunnel_miss(struct rte_eth_dev *dev, void *x)
11516 : : {
11517 : : /* called under tunnel spinlock protection */
11518 : : struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
11519 : : struct tunnel_db_get_tunnel_ctx *ctx = x;
11520 : :
11521 : 0 : rte_spinlock_unlock(&thub->sl);
11522 : 0 : ctx->tunnel = mlx5_flow_tunnel_allocate(dev, ctx->app_tunnel);
11523 : : rte_spinlock_lock(&thub->sl);
11524 [ # # ]: 0 : if (ctx->tunnel) {
11525 : 0 : ctx->tunnel->refctn = 1;
11526 [ # # ]: 0 : LIST_INSERT_HEAD(&thub->tunnels, ctx->tunnel, chain);
11527 : : }
11528 : 0 : }
11529 : :
11530 : :
11531 : : static int
11532 : 0 : mlx5_get_flow_tunnel(struct rte_eth_dev *dev,
11533 : : const struct rte_flow_tunnel *app_tunnel,
11534 : : struct mlx5_flow_tunnel **tunnel)
11535 : : {
11536 : 0 : struct tunnel_db_get_tunnel_ctx ctx = {
11537 : : .app_tunnel = app_tunnel,
11538 : : };
11539 : :
11540 : 0 : mlx5_access_tunnel_offload_db(dev, get_tunnel_match, get_tunnel_hit,
11541 : : get_tunnel_miss, &ctx, true);
11542 : 0 : *tunnel = ctx.tunnel;
11543 [ # # ]: 0 : return ctx.tunnel ? 0 : -ENOMEM;
11544 : : }
11545 : :
11546 : 0 : void mlx5_release_tunnel_hub(struct mlx5_dev_ctx_shared *sh, uint16_t port_id)
11547 : : {
11548 : 0 : struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
11549 : :
11550 [ # # ]: 0 : if (!thub)
11551 : : return;
11552 [ # # ]: 0 : if (!LIST_EMPTY(&thub->tunnels))
11553 : 0 : DRV_LOG(WARNING, "port %u tunnels present", port_id);
11554 : 0 : mlx5_hlist_destroy(thub->groups);
11555 : 0 : mlx5_free(thub);
11556 : : }
11557 : :
11558 : 0 : int mlx5_alloc_tunnel_hub(struct mlx5_dev_ctx_shared *sh)
11559 : : {
11560 : : int err;
11561 : : struct mlx5_flow_tunnel_hub *thub;
11562 : :
11563 : 0 : thub = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, sizeof(*thub),
11564 : : 0, SOCKET_ID_ANY);
11565 [ # # ]: 0 : if (!thub)
11566 : : return -ENOMEM;
11567 : 0 : LIST_INIT(&thub->tunnels);
11568 : : rte_spinlock_init(&thub->sl);
11569 : 0 : thub->groups = mlx5_hlist_create("flow groups", 64,
11570 : : false, true, sh,
11571 : : mlx5_flow_tunnel_grp2tbl_create_cb,
11572 : : mlx5_flow_tunnel_grp2tbl_match_cb,
11573 : : mlx5_flow_tunnel_grp2tbl_remove_cb,
11574 : : mlx5_flow_tunnel_grp2tbl_clone_cb,
11575 : : mlx5_flow_tunnel_grp2tbl_clone_free_cb);
11576 [ # # ]: 0 : if (!thub->groups) {
11577 : 0 : err = -rte_errno;
11578 : 0 : goto err;
11579 : : }
11580 : 0 : sh->tunnel_hub = thub;
11581 : :
11582 : 0 : return 0;
11583 : :
11584 : : err:
11585 : : if (thub->groups)
11586 : : mlx5_hlist_destroy(thub->groups);
11587 : : if (thub)
11588 : 0 : mlx5_free(thub);
11589 : 0 : return err;
11590 : : }
11591 : :
11592 : : static inline int
11593 : 0 : mlx5_flow_tunnel_validate(struct rte_eth_dev *dev,
11594 : : struct rte_flow_tunnel *tunnel,
11595 : : struct rte_flow_error *error)
11596 : : {
11597 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11598 : :
11599 [ # # ]: 0 : if (!priv->sh->config.dv_flow_en)
11600 : 0 : return rte_flow_error_set(error, ENOTSUP,
11601 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
11602 : : "flow DV interface is off");
11603 [ # # ]: 0 : if (!is_tunnel_offload_active(dev))
11604 : 0 : return rte_flow_error_set(error, ENOTSUP,
11605 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
11606 : : "tunnel offload was not activated, consider setting dv_xmeta_en=3");
11607 [ # # ]: 0 : if (!tunnel)
11608 : 0 : return rte_flow_error_set(error, EINVAL,
11609 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
11610 : : "no application tunnel");
11611 [ # # ]: 0 : switch (tunnel->type) {
11612 : 0 : default:
11613 : 0 : return rte_flow_error_set(error, EINVAL,
11614 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
11615 : : "unsupported tunnel type");
11616 : : case RTE_FLOW_ITEM_TYPE_VXLAN:
11617 : : case RTE_FLOW_ITEM_TYPE_GRE:
11618 : : case RTE_FLOW_ITEM_TYPE_NVGRE:
11619 : : case RTE_FLOW_ITEM_TYPE_GENEVE:
11620 : : break;
11621 : : }
11622 : : return 0;
11623 : : }
11624 : :
11625 : : static int
11626 : 0 : mlx5_flow_tunnel_decap_set(struct rte_eth_dev *dev,
11627 : : struct rte_flow_tunnel *app_tunnel,
11628 : : struct rte_flow_action **actions,
11629 : : uint32_t *num_of_actions,
11630 : : struct rte_flow_error *error)
11631 : : {
11632 : : struct mlx5_flow_tunnel *tunnel;
11633 : 0 : int ret = mlx5_flow_tunnel_validate(dev, app_tunnel, error);
11634 : :
11635 [ # # ]: 0 : if (ret)
11636 : : return ret;
11637 : 0 : ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
11638 [ # # ]: 0 : if (ret < 0) {
11639 : 0 : return rte_flow_error_set(error, ret,
11640 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
11641 : : "failed to initialize pmd tunnel");
11642 : : }
11643 : 0 : *actions = &tunnel->action;
11644 : 0 : *num_of_actions = 1;
11645 : 0 : return 0;
11646 : : }
11647 : :
11648 : : static int
11649 : 0 : mlx5_flow_tunnel_match(struct rte_eth_dev *dev,
11650 : : struct rte_flow_tunnel *app_tunnel,
11651 : : struct rte_flow_item **items,
11652 : : uint32_t *num_of_items,
11653 : : struct rte_flow_error *error)
11654 : : {
11655 : : struct mlx5_flow_tunnel *tunnel;
11656 : 0 : int ret = mlx5_flow_tunnel_validate(dev, app_tunnel, error);
11657 : :
11658 [ # # ]: 0 : if (ret)
11659 : : return ret;
11660 : 0 : ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
11661 [ # # ]: 0 : if (ret < 0) {
11662 : 0 : return rte_flow_error_set(error, ret,
11663 : : RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
11664 : : "failed to initialize pmd tunnel");
11665 : : }
11666 : 0 : *items = &tunnel->item;
11667 : 0 : *num_of_items = 1;
11668 : 0 : return 0;
11669 : : }
11670 : :
11671 : : struct tunnel_db_element_release_ctx {
11672 : : struct rte_flow_item *items;
11673 : : struct rte_flow_action *actions;
11674 : : uint32_t num_elements;
11675 : : struct rte_flow_error *error;
11676 : : int ret;
11677 : : };
11678 : :
11679 : : static bool
11680 : 0 : tunnel_element_release_match(struct rte_eth_dev *dev,
11681 : : struct mlx5_flow_tunnel *tunnel, const void *x)
11682 : : {
11683 : : const struct tunnel_db_element_release_ctx *ctx = x;
11684 : :
11685 : : RTE_SET_USED(dev);
11686 [ # # ]: 0 : if (ctx->num_elements != 1)
11687 : : return false;
11688 [ # # ]: 0 : else if (ctx->items)
11689 : 0 : return ctx->items == &tunnel->item;
11690 [ # # ]: 0 : else if (ctx->actions)
11691 : 0 : return ctx->actions == &tunnel->action;
11692 : :
11693 : : return false;
11694 : : }
11695 : :
11696 : : static void
11697 : 0 : tunnel_element_release_hit(struct rte_eth_dev *dev,
11698 : : struct mlx5_flow_tunnel *tunnel, void *x)
11699 : : {
11700 : : struct tunnel_db_element_release_ctx *ctx = x;
11701 : 0 : ctx->ret = 0;
11702 [ # # ]: 0 : if (!(rte_atomic_fetch_sub_explicit(&tunnel->refctn, 1, rte_memory_order_relaxed) - 1))
11703 : 0 : mlx5_flow_tunnel_free(dev, tunnel);
11704 : 0 : }
11705 : :
11706 : : static void
11707 : 0 : tunnel_element_release_miss(struct rte_eth_dev *dev, void *x)
11708 : : {
11709 : : struct tunnel_db_element_release_ctx *ctx = x;
11710 : : RTE_SET_USED(dev);
11711 : 0 : ctx->ret = rte_flow_error_set(ctx->error, EINVAL,
11712 : : RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
11713 : : "invalid argument");
11714 : 0 : }
11715 : :
11716 : : static int
11717 : 0 : mlx5_flow_tunnel_item_release(struct rte_eth_dev *dev,
11718 : : struct rte_flow_item *pmd_items,
11719 : : uint32_t num_items, struct rte_flow_error *err)
11720 : : {
11721 : 0 : struct tunnel_db_element_release_ctx ctx = {
11722 : : .items = pmd_items,
11723 : : .actions = NULL,
11724 : : .num_elements = num_items,
11725 : : .error = err,
11726 : : };
11727 : :
11728 : 0 : mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
11729 : : tunnel_element_release_hit,
11730 : : tunnel_element_release_miss, &ctx, false);
11731 : :
11732 : 0 : return ctx.ret;
11733 : : }
11734 : :
11735 : : static int
11736 : 0 : mlx5_flow_tunnel_action_release(struct rte_eth_dev *dev,
11737 : : struct rte_flow_action *pmd_actions,
11738 : : uint32_t num_actions, struct rte_flow_error *err)
11739 : : {
11740 : 0 : struct tunnel_db_element_release_ctx ctx = {
11741 : : .items = NULL,
11742 : : .actions = pmd_actions,
11743 : : .num_elements = num_actions,
11744 : : .error = err,
11745 : : };
11746 : :
11747 : 0 : mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
11748 : : tunnel_element_release_hit,
11749 : : tunnel_element_release_miss, &ctx, false);
11750 : :
11751 : 0 : return ctx.ret;
11752 : : }
11753 : :
11754 : : static int
11755 : 0 : mlx5_flow_tunnel_get_restore_info(struct rte_eth_dev *dev,
11756 : : struct rte_mbuf *m,
11757 : : struct rte_flow_restore_info *info,
11758 : : struct rte_flow_error *err)
11759 : : {
11760 : 0 : uint64_t ol_flags = m->ol_flags;
11761 : : const struct mlx5_flow_tbl_data_entry *tble;
11762 : : const uint64_t mask = RTE_MBUF_F_RX_FDIR | RTE_MBUF_F_RX_FDIR_ID;
11763 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11764 : :
11765 [ # # ]: 0 : if (priv->tunnel_enabled == 0)
11766 : 0 : goto err;
11767 [ # # ]: 0 : if ((ol_flags & mask) != mask)
11768 : 0 : goto err;
11769 : 0 : tble = tunnel_mark_decode(dev, m->hash.fdir.hi);
11770 [ # # ]: 0 : if (!tble) {
11771 : 0 : DRV_LOG(DEBUG, "port %u invalid miss tunnel mark %#x",
11772 : : dev->data->port_id, m->hash.fdir.hi);
11773 : 0 : goto err;
11774 : : }
11775 : : MLX5_ASSERT(tble->tunnel);
11776 : 0 : memcpy(&info->tunnel, &tble->tunnel->app_tunnel, sizeof(info->tunnel));
11777 : 0 : info->group_id = tble->group_id;
11778 : 0 : info->flags = RTE_FLOW_RESTORE_INFO_TUNNEL |
11779 : : RTE_FLOW_RESTORE_INFO_GROUP_ID |
11780 : : RTE_FLOW_RESTORE_INFO_ENCAPSULATED;
11781 : :
11782 : 0 : return 0;
11783 : :
11784 : 0 : err:
11785 : 0 : return rte_flow_error_set(err, EINVAL,
11786 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11787 : : "failed to get restore info");
11788 : : }
11789 : :
11790 : : #else /* HAVE_IBV_FLOW_DV_SUPPORT */
11791 : : static int
11792 : : mlx5_flow_tunnel_decap_set(__rte_unused struct rte_eth_dev *dev,
11793 : : __rte_unused struct rte_flow_tunnel *app_tunnel,
11794 : : __rte_unused struct rte_flow_action **actions,
11795 : : __rte_unused uint32_t *num_of_actions,
11796 : : __rte_unused struct rte_flow_error *error)
11797 : : {
11798 : : return -ENOTSUP;
11799 : : }
11800 : :
11801 : : static int
11802 : : mlx5_flow_tunnel_match(__rte_unused struct rte_eth_dev *dev,
11803 : : __rte_unused struct rte_flow_tunnel *app_tunnel,
11804 : : __rte_unused struct rte_flow_item **items,
11805 : : __rte_unused uint32_t *num_of_items,
11806 : : __rte_unused struct rte_flow_error *error)
11807 : : {
11808 : : return -ENOTSUP;
11809 : : }
11810 : :
11811 : : static int
11812 : : mlx5_flow_tunnel_item_release(__rte_unused struct rte_eth_dev *dev,
11813 : : __rte_unused struct rte_flow_item *pmd_items,
11814 : : __rte_unused uint32_t num_items,
11815 : : __rte_unused struct rte_flow_error *err)
11816 : : {
11817 : : return -ENOTSUP;
11818 : : }
11819 : :
11820 : : static int
11821 : : mlx5_flow_tunnel_action_release(__rte_unused struct rte_eth_dev *dev,
11822 : : __rte_unused struct rte_flow_action *pmd_action,
11823 : : __rte_unused uint32_t num_actions,
11824 : : __rte_unused struct rte_flow_error *err)
11825 : : {
11826 : : return -ENOTSUP;
11827 : : }
11828 : :
11829 : : static int
11830 : : mlx5_flow_tunnel_get_restore_info(__rte_unused struct rte_eth_dev *dev,
11831 : : __rte_unused struct rte_mbuf *m,
11832 : : __rte_unused struct rte_flow_restore_info *i,
11833 : : __rte_unused struct rte_flow_error *err)
11834 : : {
11835 : : return -ENOTSUP;
11836 : : }
11837 : :
11838 : : static int
11839 : : flow_tunnel_add_default_miss(__rte_unused struct rte_eth_dev *dev,
11840 : : __rte_unused struct rte_flow *flow,
11841 : : __rte_unused const struct rte_flow_attr *attr,
11842 : : __rte_unused const struct rte_flow_action *actions,
11843 : : __rte_unused uint32_t flow_idx,
11844 : : __rte_unused const struct mlx5_flow_tunnel *tunnel,
11845 : : __rte_unused struct tunnel_default_miss_ctx *ctx,
11846 : : __rte_unused struct rte_flow_error *error)
11847 : : {
11848 : : return -ENOTSUP;
11849 : : }
11850 : :
11851 : : static struct mlx5_flow_tunnel *
11852 : : mlx5_find_tunnel_id(__rte_unused struct rte_eth_dev *dev,
11853 : : __rte_unused uint32_t id)
11854 : : {
11855 : : return NULL;
11856 : : }
11857 : :
11858 : : static void
11859 : : mlx5_flow_tunnel_free(__rte_unused struct rte_eth_dev *dev,
11860 : : __rte_unused struct mlx5_flow_tunnel *tunnel)
11861 : : {
11862 : : }
11863 : :
11864 : : static uint32_t
11865 : : tunnel_flow_group_to_flow_table(__rte_unused struct rte_eth_dev *dev,
11866 : : __rte_unused const struct mlx5_flow_tunnel *t,
11867 : : __rte_unused uint32_t group,
11868 : : __rte_unused uint32_t *table,
11869 : : struct rte_flow_error *error)
11870 : : {
11871 : : return rte_flow_error_set(error, ENOTSUP,
11872 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11873 : : "tunnel offload requires DV support");
11874 : : }
11875 : :
11876 : : void
11877 : : mlx5_release_tunnel_hub(__rte_unused struct mlx5_dev_ctx_shared *sh,
11878 : : __rte_unused uint16_t port_id)
11879 : : {
11880 : : }
11881 : : #endif /* HAVE_IBV_FLOW_DV_SUPPORT */
11882 : :
11883 : : /* Flex flow item API */
11884 : : static struct rte_flow_item_flex_handle *
11885 : 0 : mlx5_flow_flex_item_create(struct rte_eth_dev *dev,
11886 : : const struct rte_flow_item_flex_conf *conf,
11887 : : struct rte_flow_error *error)
11888 : : {
11889 : : static const char err_msg[] = "flex item creation unsupported";
11890 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
11891 : : struct rte_flow_attr attr = { .transfer = 0 };
11892 : 0 : const struct mlx5_flow_driver_ops *fops =
11893 : : flow_get_drv_ops(flow_get_drv_type(dev, &attr));
11894 : :
11895 [ # # ]: 0 : if (!priv->pci_dev) {
11896 : 0 : rte_flow_error_set(error, ENOTSUP,
11897 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11898 : : "create flex item on PF only");
11899 : 0 : return NULL;
11900 : : }
11901 [ # # ]: 0 : switch (priv->pci_dev->id.device_id) {
11902 : : case PCI_DEVICE_ID_MELLANOX_BLUEFIELD2:
11903 : : case PCI_DEVICE_ID_MELLANOX_BLUEFIELD3:
11904 : : break;
11905 : 0 : default:
11906 : 0 : rte_flow_error_set(error, ENOTSUP,
11907 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11908 : : "flex item available on BlueField ports only");
11909 : 0 : return NULL;
11910 : : }
11911 [ # # ]: 0 : if (!fops->item_create) {
11912 : 0 : DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
11913 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
11914 : : NULL, err_msg);
11915 : 0 : return NULL;
11916 : : }
11917 : 0 : return fops->item_create(dev, conf, error);
11918 : : }
11919 : :
11920 : : static int
11921 [ # # ]: 0 : mlx5_flow_flex_item_release(struct rte_eth_dev *dev,
11922 : : const struct rte_flow_item_flex_handle *handle,
11923 : : struct rte_flow_error *error)
11924 : : {
11925 : : static const char err_msg[] = "flex item release unsupported";
11926 : : struct rte_flow_attr attr = { .transfer = 0 };
11927 : 0 : const struct mlx5_flow_driver_ops *fops =
11928 : : flow_get_drv_ops(flow_get_drv_type(dev, &attr));
11929 : :
11930 [ # # ]: 0 : if (!fops->item_release) {
11931 : 0 : DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
11932 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
11933 : : NULL, err_msg);
11934 : 0 : return -rte_errno;
11935 : : }
11936 : 0 : return fops->item_release(dev, handle, error);
11937 : : }
11938 : :
11939 : : static void
11940 : 0 : mlx5_dbg__print_pattern(const struct rte_flow_item *item)
11941 : : {
11942 : : int ret;
11943 : : struct rte_flow_error error;
11944 : :
11945 [ # # ]: 0 : for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
11946 : : char *item_name;
11947 : 0 : ret = rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_NAME_PTR, &item_name,
11948 : : sizeof(item_name),
11949 : 0 : (void *)(uintptr_t)item->type, &error);
11950 [ # # ]: 0 : if (ret > 0)
11951 : 0 : printf("%s ", item_name);
11952 : : else
11953 : 0 : printf("%d\n", (int)item->type);
11954 : : }
11955 : : printf("END\n");
11956 : 0 : }
11957 : :
11958 : : static int
11959 : : mlx5_flow_is_std_vxlan_port(const struct rte_flow_item *udp_item)
11960 : : {
11961 : 0 : const struct rte_flow_item_udp *spec = udp_item->spec;
11962 : 0 : const struct rte_flow_item_udp *mask = udp_item->mask;
11963 : : uint16_t udp_dport = 0;
11964 : :
11965 : 0 : if (spec != NULL) {
11966 [ # # ]: 0 : if (!mask)
11967 : : mask = &rte_flow_item_udp_mask;
11968 [ # # ]: 0 : udp_dport = rte_be_to_cpu_16(spec->hdr.dst_port &
11969 : : mask->hdr.dst_port);
11970 : : }
11971 : 0 : return (!udp_dport || udp_dport == MLX5_UDP_PORT_VXLAN);
11972 : : }
11973 : :
11974 : : static const struct mlx5_flow_expand_node *
11975 : 0 : mlx5_flow_expand_rss_adjust_node(const struct rte_flow_item *pattern,
11976 : : unsigned int item_idx,
11977 : : const struct mlx5_flow_expand_node graph[],
11978 : : const struct mlx5_flow_expand_node *node)
11979 : : {
11980 : 0 : const struct rte_flow_item *item = pattern + item_idx, *prev_item;
11981 : :
11982 [ # # # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_VXLAN &&
11983 : 0 : node != NULL &&
11984 [ # # ]: 0 : node->type == RTE_FLOW_ITEM_TYPE_VXLAN) {
11985 : : /*
11986 : : * The expansion node is VXLAN and it is also the last
11987 : : * expandable item in the pattern, so need to continue
11988 : : * expansion of the inner tunnel.
11989 : : */
11990 : : MLX5_ASSERT(item_idx > 0);
11991 [ # # ]: 0 : prev_item = pattern + item_idx - 1;
11992 : : MLX5_ASSERT(prev_item->type == RTE_FLOW_ITEM_TYPE_UDP);
11993 [ # # ]: 0 : if (mlx5_flow_is_std_vxlan_port(prev_item))
11994 : 0 : return &graph[MLX5_EXPANSION_STD_VXLAN];
11995 : 0 : return &graph[MLX5_EXPANSION_L3_VXLAN];
11996 : : }
11997 : : return node;
11998 : : }
11999 : :
12000 : : /* Map of Verbs to Flow priority with 8 Verbs priorities. */
12001 : : static const uint32_t priority_map_3[][MLX5_PRIORITY_MAP_MAX] = {
12002 : : { 0, 1, 2 }, { 2, 3, 4 }, { 5, 6, 7 },
12003 : : };
12004 : :
12005 : : /* Map of Verbs to Flow priority with 16 Verbs priorities. */
12006 : : static const uint32_t priority_map_5[][MLX5_PRIORITY_MAP_MAX] = {
12007 : : { 0, 1, 2 }, { 3, 4, 5 }, { 6, 7, 8 },
12008 : : { 9, 10, 11 }, { 12, 13, 14 },
12009 : : };
12010 : :
12011 : : /**
12012 : : * Discover the number of available flow priorities.
12013 : : *
12014 : : * @param dev
12015 : : * Ethernet device.
12016 : : *
12017 : : * @return
12018 : : * On success, number of available flow priorities.
12019 : : * On failure, a negative errno-style code and rte_errno is set.
12020 : : */
12021 : : int
12022 : 0 : mlx5_flow_discover_priorities(struct rte_eth_dev *dev)
12023 : : {
12024 : : static const uint16_t vprio[] = {8, 16};
12025 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
12026 : : const struct mlx5_flow_driver_ops *fops;
12027 : : enum mlx5_flow_drv_type type;
12028 : : int ret;
12029 : :
12030 : : type = mlx5_flow_os_get_type();
12031 : : if (type == MLX5_FLOW_TYPE_MAX) {
12032 : : type = MLX5_FLOW_TYPE_VERBS;
12033 [ # # # # ]: 0 : if (priv->sh->cdev->config.devx && priv->sh->config.dv_flow_en)
12034 : : type = MLX5_FLOW_TYPE_DV;
12035 : : }
12036 : 0 : fops = flow_get_drv_ops(type);
12037 [ # # ]: 0 : if (fops->discover_priorities == NULL) {
12038 : 0 : DRV_LOG(ERR, "Priority discovery not supported");
12039 : 0 : rte_errno = ENOTSUP;
12040 : 0 : return -rte_errno;
12041 : : }
12042 : 0 : ret = fops->discover_priorities(dev, vprio, RTE_DIM(vprio));
12043 [ # # ]: 0 : if (ret < 0)
12044 : : return ret;
12045 [ # # # ]: 0 : switch (ret) {
12046 : : case 8:
12047 : : ret = RTE_DIM(priority_map_3);
12048 : : break;
12049 : 0 : case 16:
12050 : : ret = RTE_DIM(priority_map_5);
12051 : 0 : break;
12052 : 0 : default:
12053 : 0 : rte_errno = ENOTSUP;
12054 : 0 : DRV_LOG(ERR,
12055 : : "port %u maximum priority: %d expected 8/16",
12056 : : dev->data->port_id, ret);
12057 : 0 : return -rte_errno;
12058 : : }
12059 : 0 : DRV_LOG(INFO, "port %u supported flow priorities:"
12060 : : " 0-%d for ingress or egress root table,"
12061 : : " 0-%d for non-root table or transfer root table.",
12062 : : dev->data->port_id, ret - 2,
12063 : : MLX5_NON_ROOT_FLOW_MAX_PRIO - 1);
12064 : 0 : return ret;
12065 : : }
12066 : :
12067 : : /**
12068 : : * Adjust flow priority based on the highest layer and the request priority.
12069 : : *
12070 : : * @param[in] dev
12071 : : * Pointer to the Ethernet device structure.
12072 : : * @param[in] priority
12073 : : * The rule base priority.
12074 : : * @param[in] subpriority
12075 : : * The priority based on the items.
12076 : : *
12077 : : * @return
12078 : : * The new priority.
12079 : : */
12080 : : uint32_t
12081 : 0 : mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
12082 : : uint32_t subpriority)
12083 : : {
12084 : : uint32_t res = 0;
12085 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12086 : :
12087 [ # # # ]: 0 : switch (priv->sh->flow_max_priority) {
12088 : 0 : case RTE_DIM(priority_map_3):
12089 : 0 : res = priority_map_3[priority][subpriority];
12090 : 0 : break;
12091 : 0 : case RTE_DIM(priority_map_5):
12092 : 0 : res = priority_map_5[priority][subpriority];
12093 : 0 : break;
12094 : : }
12095 : 0 : return res;
12096 : : }
12097 : :
12098 : : /**
12099 : : * Get the priority for sending traffic to kernel table.
12100 : : *
12101 : : * @param[in] dev
12102 : : * Pointer to the Ethernet device structure.
12103 : : *
12104 : : * @return
12105 : : * On success: the value of priority for sending traffic to kernel table
12106 : : * On failure: -1
12107 : : */
12108 : : uint32_t
12109 : 0 : mlx5_get_send_to_kernel_priority(struct rte_eth_dev *dev)
12110 : : {
12111 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12112 : : uint32_t res;
12113 : :
12114 [ # # # ]: 0 : switch (priv->sh->flow_max_priority) {
12115 : : case RTE_DIM(priority_map_5):
12116 : : res = 15;
12117 : : break;
12118 : 0 : case RTE_DIM(priority_map_3):
12119 : : res = 7;
12120 : 0 : break;
12121 : 0 : default:
12122 : 0 : DRV_LOG(ERR,
12123 : : "port %u maximum priority: %d expected 8/16",
12124 : : dev->data->port_id, priv->sh->flow_max_priority);
12125 : : res = (uint32_t)-1;
12126 : : }
12127 : 0 : return res;
12128 : : }
12129 : :
12130 : : /**
12131 : : * Get the E-Switch Manager vport id.
12132 : : *
12133 : : * @param[in] dev
12134 : : * Pointer to the Ethernet device structure.
12135 : : *
12136 : : * @return
12137 : : * The vport id.
12138 : : */
12139 : 0 : int16_t mlx5_flow_get_esw_manager_vport_id(struct rte_eth_dev *dev)
12140 : : {
12141 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12142 : 0 : struct mlx5_common_device *cdev = priv->sh->cdev;
12143 : :
12144 : : /* New FW exposes E-Switch Manager vport ID, can use it directly. */
12145 [ # # ]: 0 : if (cdev->config.hca_attr.esw_mgr_vport_id_valid)
12146 : 0 : return (int16_t)cdev->config.hca_attr.esw_mgr_vport_id;
12147 : :
12148 [ # # ]: 0 : if (priv->pci_dev == NULL)
12149 : : return 0;
12150 [ # # ]: 0 : switch (priv->pci_dev->id.device_id) {
12151 : : case PCI_DEVICE_ID_MELLANOX_BLUEFIELD:
12152 : : case PCI_DEVICE_ID_MELLANOX_BLUEFIELD2:
12153 : : case PCI_DEVICE_ID_MELLANOX_BLUEFIELD3:
12154 : : /*
12155 : : * In old FW which doesn't expose the E-Switch Manager vport ID in the capability,
12156 : : * only the BF embedded CPUs control the E-Switch Manager port. Hence,
12157 : : * ECPF vport ID is selected and not the host port (0) in any BF case.
12158 : : */
12159 : : return (int16_t)MLX5_ECPF_VPORT_ID;
12160 : 0 : default:
12161 : 0 : return MLX5_PF_VPORT_ID;
12162 : : }
12163 : : }
12164 : :
12165 : : /**
12166 : : * Parse item to get the vport id.
12167 : : *
12168 : : * @param[in] dev
12169 : : * Pointer to the Ethernet device structure.
12170 : : * @param[in] item
12171 : : * The src port id match item.
12172 : : * @param[out] vport_id
12173 : : * Pointer to put the vport id.
12174 : : * @param[out] all_ports
12175 : : * Indicate if the item matches all ports.
12176 : : * @param[out] error
12177 : : * Pointer to error structure.
12178 : : *
12179 : : * @return
12180 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
12181 : : */
12182 : 0 : int mlx5_flow_get_item_vport_id(struct rte_eth_dev *dev,
12183 : : const struct rte_flow_item *item,
12184 : : uint16_t *vport_id,
12185 : : bool *all_ports,
12186 : : struct rte_flow_error *error)
12187 : : {
12188 : : struct mlx5_priv *port_priv;
12189 : : const struct rte_flow_item_port_id *pid_v = NULL;
12190 : : const struct rte_flow_item_ethdev *dev_v = NULL;
12191 : : uint32_t esw_mgr_port;
12192 : : uint32_t src_port;
12193 : :
12194 [ # # ]: 0 : if (all_ports)
12195 : 0 : *all_ports = false;
12196 [ # # # # ]: 0 : switch (item->type) {
12197 : 0 : case RTE_FLOW_ITEM_TYPE_PORT_ID:
12198 : 0 : pid_v = item->spec;
12199 [ # # ]: 0 : if (!pid_v)
12200 : : return 0;
12201 : 0 : src_port = pid_v->id;
12202 : : esw_mgr_port = MLX5_PORT_ESW_MGR;
12203 : 0 : break;
12204 : 0 : case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
12205 : 0 : dev_v = item->spec;
12206 [ # # ]: 0 : if (!dev_v) {
12207 [ # # ]: 0 : if (all_ports)
12208 : 0 : *all_ports = true;
12209 : 0 : return 0;
12210 : : }
12211 : 0 : src_port = dev_v->port_id;
12212 : : esw_mgr_port = MLX5_REPRESENTED_PORT_ESW_MGR;
12213 : 0 : break;
12214 : : case RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR:
12215 : : src_port = MLX5_REPRESENTED_PORT_ESW_MGR;
12216 : : esw_mgr_port = MLX5_REPRESENTED_PORT_ESW_MGR;
12217 : : break;
12218 : 0 : default:
12219 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
12220 : : NULL, "Incorrect item type.");
12221 : : }
12222 [ # # ]: 0 : if (src_port == esw_mgr_port) {
12223 : 0 : *vport_id = mlx5_flow_get_esw_manager_vport_id(dev);
12224 : : } else {
12225 : 0 : port_priv = mlx5_port_to_eswitch_info(src_port, false);
12226 [ # # ]: 0 : if (!port_priv)
12227 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
12228 : : NULL, "Failed to get port info.");
12229 : 0 : *vport_id = port_priv->representor_id;
12230 : : }
12231 : :
12232 : : return 0;
12233 : : }
12234 : :
12235 : : int
12236 : 0 : mlx5_flow_pick_transfer_proxy(struct rte_eth_dev *dev,
12237 : : uint16_t *proxy_port_id,
12238 : : struct rte_flow_error *error)
12239 : : {
12240 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
12241 : : uint16_t port_id;
12242 : :
12243 [ # # ]: 0 : if (!priv->sh->config.dv_esw_en)
12244 : 0 : return rte_flow_error_set(error, EINVAL,
12245 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12246 : : NULL,
12247 : : "unable to provide a proxy port"
12248 : : " without E-Switch configured");
12249 [ # # ]: 0 : if (!priv->master && !priv->representor)
12250 : 0 : return rte_flow_error_set(error, EINVAL,
12251 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12252 : : NULL,
12253 : : "unable to provide a proxy port"
12254 : : " for port which is not a master"
12255 : : " or a representor port");
12256 [ # # ]: 0 : if (priv->master) {
12257 : 0 : *proxy_port_id = dev->data->port_id;
12258 : 0 : return 0;
12259 : : }
12260 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port_id, dev->device) {
12261 : 0 : const struct rte_eth_dev *port_dev = &rte_eth_devices[port_id];
12262 : 0 : const struct mlx5_priv *port_priv = port_dev->data->dev_private;
12263 : :
12264 [ # # ]: 0 : if (port_priv->master &&
12265 [ # # ]: 0 : port_priv->domain_id == priv->domain_id) {
12266 : 0 : *proxy_port_id = port_id;
12267 : 0 : return 0;
12268 : : }
12269 : : }
12270 : 0 : return rte_flow_error_set(error, ENODEV,
12271 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12272 : : NULL, "unable to find a proxy port");
12273 : : }
12274 : :
12275 : : /**
12276 : : * Discover IPv6 traffic class ID support in rdma-core and firmware.
12277 : : *
12278 : : * @param dev
12279 : : * Ethernet device.
12280 : : *
12281 : : * @return
12282 : : * 0, rdma-core is good to work with firmware.
12283 : : * -EOPNOTSUPP, rdma-core could not work with new IPv6 TC ID.
12284 : : */
12285 : : int
12286 : 0 : mlx5_flow_discover_ipv6_tc_support(struct rte_eth_dev *dev)
12287 : : {
12288 : : struct rte_flow_action_set_dscp set_dscp;
12289 : : struct rte_flow_attr attr;
12290 : : struct rte_flow_action actions[2];
12291 : : struct rte_flow_item items[3];
12292 : : struct rte_flow_error error;
12293 : : uint32_t flow_idx;
12294 : :
12295 : : memset(&attr, 0, sizeof(attr));
12296 : : memset(actions, 0, sizeof(actions));
12297 : : memset(items, 0, sizeof(items));
12298 : 0 : attr.group = 1;
12299 : 0 : attr.egress = 1;
12300 : 0 : items[0].type = RTE_FLOW_ITEM_TYPE_ETH;
12301 : 0 : items[1].type = RTE_FLOW_ITEM_TYPE_IPV6;
12302 : : items[2].type = RTE_FLOW_ITEM_TYPE_END;
12303 : : /* Random value */
12304 : 0 : set_dscp.dscp = 9;
12305 : 0 : actions[0].type = RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP;
12306 : 0 : actions[0].conf = &set_dscp;
12307 : : actions[1].type = RTE_FLOW_ACTION_TYPE_END;
12308 : :
12309 : 0 : flow_idx = mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_GEN, &attr, items,
12310 : : actions, true, &error);
12311 [ # # ]: 0 : if (!flow_idx)
12312 : : return -EOPNOTSUPP;
12313 : :
12314 : 0 : mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN, flow_idx);
12315 : 0 : return 0;
12316 : : }
12317 : :
12318 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_mlx5_create_geneve_tlv_parser, 24.03)
12319 : : void *
12320 : 0 : rte_pmd_mlx5_create_geneve_tlv_parser(uint16_t port_id,
12321 : : const struct rte_pmd_mlx5_geneve_tlv tlv_list[],
12322 : : uint8_t nb_options)
12323 : : {
12324 : : #ifdef HAVE_MLX5_HWS_SUPPORT
12325 : 0 : return mlx5_geneve_tlv_parser_create(port_id, tlv_list, nb_options);
12326 : : #else
12327 : : (void)port_id;
12328 : : (void)tlv_list;
12329 : : (void)nb_options;
12330 : : DRV_LOG(ERR, "%s is not supported.", __func__);
12331 : : rte_errno = ENOTSUP;
12332 : : return NULL;
12333 : : #endif
12334 : : }
12335 : :
12336 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_mlx5_destroy_geneve_tlv_parser, 24.03)
12337 : : int
12338 : 0 : rte_pmd_mlx5_destroy_geneve_tlv_parser(void *handle)
12339 : : {
12340 : : #ifdef HAVE_MLX5_HWS_SUPPORT
12341 : 0 : return mlx5_geneve_tlv_parser_destroy(handle);
12342 : : #else
12343 : : (void)handle;
12344 : : DRV_LOG(ERR, "%s is not supported.", __func__);
12345 : : rte_errno = ENOTSUP;
12346 : : return -rte_errno;
12347 : : #endif
12348 : : }
12349 : :
12350 : : bool
12351 : 0 : mlx5_ctrl_flow_uc_dmac_exists(struct rte_eth_dev *dev, const struct rte_ether_addr *addr)
12352 : : {
12353 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12354 : : struct mlx5_ctrl_flow_entry *entry;
12355 : : bool exists = false;
12356 : :
12357 [ # # ]: 0 : LIST_FOREACH(entry, &priv->hw_ctrl_flows, next) {
12358 [ # # # # ]: 0 : if (entry->info.type == MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC &&
12359 : : rte_is_same_ether_addr(addr, &entry->info.uc.dmac)) {
12360 : : exists = true;
12361 : : break;
12362 : : }
12363 : : }
12364 : 0 : return exists;
12365 : : }
12366 : :
12367 : : bool
12368 : 0 : mlx5_ctrl_flow_uc_dmac_vlan_exists(struct rte_eth_dev *dev,
12369 : : const struct rte_ether_addr *addr,
12370 : : const uint16_t vid)
12371 : : {
12372 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12373 : : struct mlx5_ctrl_flow_entry *entry;
12374 : : bool exists = false;
12375 : :
12376 [ # # ]: 0 : LIST_FOREACH(entry, &priv->hw_ctrl_flows, next) {
12377 [ # # # # ]: 0 : if (entry->info.type == MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC_VLAN &&
12378 : 0 : rte_is_same_ether_addr(addr, &entry->info.uc.dmac) &&
12379 [ # # ]: 0 : vid == entry->info.uc.vlan) {
12380 : : exists = true;
12381 : : break;
12382 : : }
12383 : : }
12384 : 0 : return exists;
12385 : : }
12386 : :
12387 : : static bool mlx5_steering_disabled;
12388 : :
12389 : : bool
12390 : 0 : mlx5_flow_is_steering_disabled(void)
12391 : : {
12392 : 0 : return mlx5_steering_disabled;
12393 : : }
12394 : :
12395 : : static void
12396 : 0 : flow_disable_steering_flush(struct rte_eth_dev *dev)
12397 : : {
12398 : : /*
12399 : : * This repeats the steps done in mlx5_dev_stop(), with a small difference:
12400 : : * - mlx5_flow_hw_cleanup_ctrl_rx_templates() and mlx5_action_handle_detach()
12401 : : * They are rearranged to make it work with different dev->data->dev_started.
12402 : : * Please see a TODO note in mlx5_dev_stop().
12403 : : */
12404 : :
12405 : 0 : mlx5_flow_stop_default(dev);
12406 : 0 : mlx5_traffic_disable(dev);
12407 : 0 : mlx5_flow_list_flush(dev, MLX5_FLOW_TYPE_GEN, true);
12408 : 0 : mlx5_flow_meter_rxq_flush(dev);
12409 : : #ifdef HAVE_MLX5_HWS_SUPPORT
12410 : 0 : mlx5_flow_hw_cleanup_ctrl_rx_templates(dev);
12411 : : #endif
12412 : 0 : mlx5_action_handle_detach(dev);
12413 : 0 : }
12414 : :
12415 : : static void
12416 : 0 : flow_disable_steering_cleanup(struct rte_eth_dev *dev)
12417 : : {
12418 : : /*
12419 : : * See mlx5_dev_close(). Only steps not done on mlx5_dev_stop() are executed here.
12420 : : * Necessary steps are copied as is because steering resource cleanup in mlx5_dev_close()
12421 : : * is interleaved with other steps.
12422 : : * TODO: Rework steering resource cleanup in mlx5_dev_close() to allow code reuse.
12423 : : */
12424 : :
12425 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12426 : :
12427 : 0 : mlx5_action_handle_flush(dev);
12428 : 0 : mlx5_flow_meter_flush(dev, NULL);
12429 : 0 : mlx5_flex_parser_ecpri_release(dev);
12430 : 0 : mlx5_flex_item_port_cleanup(dev);
12431 : 0 : mlx5_indirect_list_handles_release(dev);
12432 : : #ifdef HAVE_MLX5_HWS_SUPPORT
12433 : 0 : flow_hw_destroy_vport_action(dev);
12434 : 0 : flow_hw_resource_release(dev);
12435 : 0 : flow_hw_clear_port_info(dev);
12436 [ # # ]: 0 : if (priv->tlv_options != NULL) {
12437 : : /* Free the GENEVE TLV parser resource. */
12438 : 0 : claim_zero(mlx5_geneve_tlv_options_destroy(priv->tlv_options, priv->sh->phdev));
12439 : 0 : priv->tlv_options = NULL;
12440 : : }
12441 [ # # ]: 0 : if (priv->ptype_rss_groups) {
12442 : 0 : mlx5_ipool_destroy(priv->ptype_rss_groups);
12443 : 0 : priv->ptype_rss_groups = NULL;
12444 : : }
12445 [ # # ]: 0 : if (priv->dr_ctx) {
12446 : 0 : claim_zero(mlx5dr_context_close(priv->dr_ctx));
12447 : 0 : priv->dr_ctx = NULL;
12448 : : }
12449 : : #else
12450 : : RTE_SET_USED(priv);
12451 : : #endif
12452 : 0 : }
12453 : :
12454 : : typedef void (*run_on_related_cb_t)(struct rte_eth_dev *dev);
12455 : :
12456 : : static void
12457 : 0 : flow_disable_steering_run_on_related(struct rte_eth_dev *dev,
12458 : : run_on_related_cb_t cb)
12459 : : {
12460 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12461 : : uint16_t other_port_id;
12462 : : uint16_t proxy_port_id;
12463 : : uint16_t port_id;
12464 : : int ret __rte_unused;
12465 : :
12466 [ # # ]: 0 : if (priv->sh->config.dv_esw_en) {
12467 : 0 : ret = mlx5_flow_pick_transfer_proxy(dev, &proxy_port_id, NULL);
12468 [ # # ]: 0 : if (ret != 0) {
12469 : : /*
12470 : : * This case should not happen because E-Switch is enabled.
12471 : : * However, in any case, release resources on the given port
12472 : : * and log the misconfigured port.
12473 : : */
12474 : 0 : DRV_LOG(ERR, "port %u unable to find transfer proxy port ret=%d",
12475 : : priv->dev_data->port_id, ret);
12476 : 0 : cb(dev);
12477 : 0 : return;
12478 : : }
12479 : :
12480 : : /* Run callback on representors. */
12481 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(other_port_id, dev->device) {
12482 : 0 : struct rte_eth_dev *other_dev = &rte_eth_devices[other_port_id];
12483 : :
12484 [ # # ]: 0 : if (other_port_id != proxy_port_id)
12485 : 0 : cb(other_dev);
12486 : : }
12487 : :
12488 : : /* Run callback on proxy port. */
12489 : 0 : cb(&rte_eth_devices[proxy_port_id]);
12490 [ # # ]: 0 : } else if (rte_atomic_load_explicit(&priv->shared_refcnt, rte_memory_order_relaxed) > 0) {
12491 : : /* Run callback on guest ports. */
12492 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port_id, NULL) {
12493 : 0 : struct rte_eth_dev *other_dev = &rte_eth_devices[port_id];
12494 : 0 : struct mlx5_priv *other_priv = other_dev->data->dev_private;
12495 : :
12496 [ # # ]: 0 : if (other_priv->shared_host == dev)
12497 : 0 : cb(other_dev);
12498 : : }
12499 : :
12500 : : /* Run callback on host port. */
12501 : 0 : cb(dev);
12502 : : } else {
12503 : 0 : cb(dev);
12504 : : }
12505 : : }
12506 : :
12507 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_mlx5_disable_steering, 25.11)
12508 : : void
12509 : 0 : rte_pmd_mlx5_disable_steering(void)
12510 : : {
12511 : : uint16_t port_id;
12512 : :
12513 [ # # ]: 0 : if (mlx5_steering_disabled)
12514 : : return;
12515 : :
12516 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port_id, NULL) {
12517 [ # # ]: 0 : struct rte_eth_dev *dev = &rte_eth_devices[port_id];
12518 : :
12519 [ # # ]: 0 : if (mlx5_hws_active(dev)) {
12520 : 0 : flow_disable_steering_run_on_related(dev, flow_disable_steering_flush);
12521 : 0 : flow_disable_steering_run_on_related(dev, flow_disable_steering_cleanup);
12522 : : } else {
12523 : 0 : flow_disable_steering_flush(dev);
12524 : 0 : flow_disable_steering_cleanup(dev);
12525 : : }
12526 : :
12527 : 0 : mlx5_flow_rxq_mark_flag_set(dev);
12528 : : }
12529 : :
12530 : 0 : mlx5_steering_disabled = true;
12531 : : }
12532 : :
12533 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_mlx5_enable_steering, 25.11)
12534 : : int
12535 : 0 : rte_pmd_mlx5_enable_steering(void)
12536 : : {
12537 : : uint16_t port_id;
12538 : :
12539 [ # # ]: 0 : if (!mlx5_steering_disabled)
12540 : : return 0;
12541 : :
12542 : : /* If any mlx5 port is probed, disallow enabling steering. */
12543 : 0 : port_id = mlx5_eth_find_next(0, NULL);
12544 [ # # ]: 0 : if (port_id != RTE_MAX_ETHPORTS)
12545 : : return -EBUSY;
12546 : :
12547 : 0 : mlx5_steering_disabled = false;
12548 : :
12549 : 0 : return 0;
12550 : : }
12551 : :
12552 : : bool
12553 : 0 : mlx5_vport_rx_metadata_passing_enabled(const struct mlx5_dev_ctx_shared *sh)
12554 : : {
12555 : : const struct mlx5_sh_config *dev_config = &sh->config;
12556 : 0 : const struct mlx5_hca_attr *hca_attr = &sh->cdev->config.hca_attr;
12557 : :
12558 [ # # # # ]: 0 : return !dev_config->dv_esw_en && hca_attr->fdb_to_vport_metadata;
12559 : : }
12560 : :
12561 : : bool
12562 : 0 : mlx5_vport_tx_metadata_passing_enabled(const struct mlx5_dev_ctx_shared *sh)
12563 : : {
12564 : : const struct mlx5_sh_config *dev_config = &sh->config;
12565 : 0 : const struct mlx5_hca_attr *hca_attr = &sh->cdev->config.hca_attr;
12566 : :
12567 [ # # # # ]: 0 : return !dev_config->dv_esw_en && hca_attr->vport_to_fdb_metadata;
12568 : : }
12569 : :
12570 : : bool
12571 : 0 : mlx5_esw_metadata_passing_enabled(const struct mlx5_dev_ctx_shared *sh)
12572 : : {
12573 : : const struct mlx5_sh_config *dev_config = &sh->config;
12574 : 0 : const struct mlx5_hca_attr *hca_attr = &sh->cdev->config.hca_attr;
12575 : 0 : bool fdb_to_vport_metadata_on = (hca_attr->fdb_to_vport_reg_c_id &
12576 : : RTE_BIT32(MLX5_ESW_VPORT_METADATA_REG_C_1)) != 0;
12577 : :
12578 [ # # # # ]: 0 : return dev_config->dv_esw_en && hca_attr->fdb_to_vport_reg_c && fdb_to_vport_metadata_on &&
12579 [ # # # # ]: 0 : hca_attr->vport_to_fdb_metadata && hca_attr->fdb_to_vport_metadata;
12580 : : }
|