Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright 2016 6WIND S.A.
3 : : * Copyright 2016 Mellanox Technologies, Ltd
4 : : */
5 : :
6 : : #include <stdalign.h>
7 : : #include <stdint.h>
8 : : #include <string.h>
9 : : #include <stdbool.h>
10 : : #include <sys/queue.h>
11 : :
12 : : #include <eal_export.h>
13 : : #include <rte_common.h>
14 : : #include <rte_ether.h>
15 : : #include <ethdev_driver.h>
16 : : #include <rte_eal_paging.h>
17 : : #include <rte_flow.h>
18 : : #include <rte_cycles.h>
19 : : #include <rte_flow_driver.h>
20 : : #include <rte_malloc.h>
21 : : #include <rte_ip.h>
22 : :
23 : : #include <mlx5_glue.h>
24 : : #include <mlx5_devx_cmds.h>
25 : : #include <mlx5_prm.h>
26 : : #include <mlx5_malloc.h>
27 : :
28 : : #include "mlx5_defs.h"
29 : : #include "mlx5.h"
30 : : #include "mlx5_flow.h"
31 : : #include "mlx5_flow_os.h"
32 : : #include "mlx5_rx.h"
33 : : #include "mlx5_tx.h"
34 : : #include "mlx5_common_os.h"
35 : : #include "rte_pmd_mlx5.h"
36 : :
37 : : const uint64_t mlx5_rss_hash_fields[] = {
38 : : [MLX5_RSS_HASH_IDX_IPV4] = MLX5_RSS_HASH_IPV4,
39 : : [MLX5_RSS_HASH_IDX_IPV4_TCP] = MLX5_RSS_HASH_IPV4_TCP,
40 : : [MLX5_RSS_HASH_IDX_IPV4_UDP] = MLX5_RSS_HASH_IPV4_UDP,
41 : : [MLX5_RSS_HASH_IDX_IPV4_ESP] = MLX5_RSS_HASH_IPV4_ESP,
42 : : [MLX5_RSS_HASH_IDX_IPV6] = MLX5_RSS_HASH_IPV6,
43 : : [MLX5_RSS_HASH_IDX_IPV6_TCP] = MLX5_RSS_HASH_IPV6_TCP,
44 : : [MLX5_RSS_HASH_IDX_IPV6_UDP] = MLX5_RSS_HASH_IPV6_UDP,
45 : : [MLX5_RSS_HASH_IDX_IPV6_ESP] = MLX5_RSS_HASH_IPV6_ESP,
46 : : [MLX5_RSS_HASH_IDX_TCP] = MLX5_TCP_IBV_RX_HASH,
47 : : [MLX5_RSS_HASH_IDX_UDP] = MLX5_UDP_IBV_RX_HASH,
48 : : [MLX5_RSS_HASH_IDX_ESP_SPI] = MLX5_RSS_HASH_ESP_SPI,
49 : : [MLX5_RSS_HASH_IDX_NONE] = MLX5_RSS_HASH_NONE,
50 : : };
51 : :
52 : : /*
53 : : * Shared array for quick translation between port_id and vport mask/values
54 : : * used for HWS rules.
55 : : */
56 : : struct flow_hw_port_info mlx5_flow_hw_port_infos[RTE_MAX_ETHPORTS];
57 : :
58 : : struct tunnel_default_miss_ctx {
59 : : uint16_t *queue;
60 : : __extension__
61 : : union {
62 : : struct rte_flow_action_rss action_rss;
63 : : struct rte_flow_action_queue miss_queue;
64 : : struct rte_flow_action_jump miss_jump;
65 : : uint8_t raw[0];
66 : : };
67 : : };
68 : :
69 : : void
70 : 0 : mlx5_indirect_list_handles_release(struct rte_eth_dev *dev)
71 : : {
72 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
73 : : #ifdef HAVE_MLX5_HWS_SUPPORT
74 : : struct rte_flow_error error;
75 : : #endif
76 : :
77 [ # # ]: 0 : while (!LIST_EMPTY(&priv->indirect_list_head)) {
78 : : struct mlx5_indirect_list *e =
79 : : LIST_FIRST(&priv->indirect_list_head);
80 : :
81 [ # # ]: 0 : LIST_REMOVE(e, entry);
82 [ # # # # ]: 0 : switch (e->type) {
83 : : #ifdef HAVE_MLX5_HWS_SUPPORT
84 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_MIRROR:
85 : 0 : mlx5_hw_mirror_destroy(dev, (struct mlx5_mirror *)e);
86 : 0 : break;
87 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_LEGACY:
88 : 0 : mlx5_destroy_legacy_indirect(dev, e);
89 : 0 : break;
90 : 0 : case MLX5_INDIRECT_ACTION_LIST_TYPE_REFORMAT:
91 : 0 : mlx5_reformat_action_destroy(dev,
92 : : (struct rte_flow_action_list_handle *)e, &error);
93 : 0 : break;
94 : : #endif
95 : 0 : default:
96 : 0 : DRV_LOG(ERR, "invalid indirect list type");
97 : : MLX5_ASSERT(false);
98 : 0 : break;
99 : : }
100 : : }
101 : 0 : }
102 : :
103 : : static int
104 : : flow_tunnel_add_default_miss(struct rte_eth_dev *dev,
105 : : struct rte_flow *flow,
106 : : const struct rte_flow_attr *attr,
107 : : const struct rte_flow_action *app_actions,
108 : : uint32_t flow_idx,
109 : : const struct mlx5_flow_tunnel *tunnel,
110 : : struct tunnel_default_miss_ctx *ctx,
111 : : struct rte_flow_error *error);
112 : : static struct mlx5_flow_tunnel *
113 : : mlx5_find_tunnel_id(struct rte_eth_dev *dev, uint32_t id);
114 : : static void
115 : : mlx5_flow_tunnel_free(struct rte_eth_dev *dev, struct mlx5_flow_tunnel *tunnel);
116 : : static uint32_t
117 : : tunnel_flow_group_to_flow_table(struct rte_eth_dev *dev,
118 : : const struct mlx5_flow_tunnel *tunnel,
119 : : uint32_t group, uint32_t *table,
120 : : struct rte_flow_error *error);
121 : :
122 : : /** Device flow drivers. */
123 : : extern const struct mlx5_flow_driver_ops mlx5_flow_verbs_drv_ops;
124 : :
125 : : const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops;
126 : :
127 : : static const struct mlx5_flow_driver_ops *flow_drv_ops[] = {
128 : : [MLX5_FLOW_TYPE_MIN] = &mlx5_flow_null_drv_ops,
129 : : #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
130 : : [MLX5_FLOW_TYPE_DV] = &mlx5_flow_dv_drv_ops,
131 : : #endif
132 : : #ifdef HAVE_MLX5_HWS_SUPPORT
133 : : [MLX5_FLOW_TYPE_HW] = &mlx5_flow_hw_drv_ops,
134 : : #endif
135 : : [MLX5_FLOW_TYPE_VERBS] = &mlx5_flow_verbs_drv_ops,
136 : : [MLX5_FLOW_TYPE_MAX] = &mlx5_flow_null_drv_ops
137 : : };
138 : :
139 : : /** Helper macro to build input graph for mlx5_flow_expand_rss(). */
140 : : #define MLX5_FLOW_EXPAND_RSS_NEXT(...) \
141 : : (const int []){ \
142 : : __VA_ARGS__, 0, \
143 : : }
144 : :
145 : : /** Node object of input graph for mlx5_flow_expand_rss(). */
146 : : struct mlx5_flow_expand_node {
147 : : const int *const next;
148 : : /**<
149 : : * List of next node indexes. Index 0 is interpreted as a terminator.
150 : : */
151 : : const enum rte_flow_item_type type;
152 : : /**< Pattern item type of current node. */
153 : : uint64_t rss_types;
154 : : /**<
155 : : * RSS types bit-field associated with this node
156 : : * (see RTE_ETH_RSS_* definitions).
157 : : */
158 : : uint64_t node_flags;
159 : : /**<
160 : : * Bit-fields that define how the node is used in the expansion.
161 : : * (see MLX5_EXPANSION_NODE_* definitions).
162 : : */
163 : : };
164 : :
165 : : /** Keep same format with mlx5_flow_expand_rss to share the buffer for expansion. */
166 : : struct mlx5_flow_expand_sqn {
167 : : uint32_t entries; /** Number of entries */
168 : : struct {
169 : : struct rte_flow_item *pattern; /**< Expanded pattern array. */
170 : : uint32_t priority; /**< Priority offset for each expansion. */
171 : : } entry[];
172 : : };
173 : :
174 : : /* Optional expand field. The expansion alg will not go deeper. */
175 : : #define MLX5_EXPANSION_NODE_OPTIONAL (UINT64_C(1) << 0)
176 : :
177 : : /* The node is not added implicitly as expansion to the flow pattern.
178 : : * If the node type does not match the flow pattern item type, the
179 : : * expansion alg will go deeper to its next items.
180 : : * In the current implementation, the list of next nodes indexes can
181 : : * have up to one node with this flag set and it has to be the last
182 : : * node index (before the list terminator).
183 : : */
184 : : #define MLX5_EXPANSION_NODE_EXPLICIT (UINT64_C(1) << 1)
185 : :
186 : : /** Object returned by mlx5_flow_expand_rss(). */
187 : : struct mlx5_flow_expand_rss {
188 : : uint32_t entries;
189 : : /**< Number of entries @p patterns and @p priorities. */
190 : : struct {
191 : : struct rte_flow_item *pattern; /**< Expanded pattern array. */
192 : : uint32_t priority; /**< Priority offset for each expansion. */
193 : : } entry[];
194 : : };
195 : :
196 : : static void
197 : : mlx5_dbg__print_pattern(const struct rte_flow_item *item);
198 : :
199 : : static const struct mlx5_flow_expand_node *
200 : : mlx5_flow_expand_rss_adjust_node(const struct rte_flow_item *pattern,
201 : : unsigned int item_idx,
202 : : const struct mlx5_flow_expand_node graph[],
203 : : const struct mlx5_flow_expand_node *node);
204 : :
205 : : static __rte_always_inline int
206 : : mlx5_need_cache_flow(const struct mlx5_priv *priv,
207 : : const struct rte_flow_attr *attr)
208 : : {
209 [ # # # # : 0 : return priv->isolated && priv->sh->config.dv_flow_en == 1 &&
# # # # ]
210 [ # # # # ]: 0 : (attr ? !attr->group : true) &&
211 [ # # # # : 0 : priv->mode_info.mode == RTE_PMD_MLX5_FLOW_ENGINE_MODE_STANDBY &&
# # # # #
# # # # #
# # ]
212 [ # # # # : 0 : (!priv->sh->config.dv_esw_en || !priv->sh->config.fdb_def_rule);
# # # # ]
213 : : }
214 : :
215 : : static bool
216 : 0 : mlx5_flow_is_rss_expandable_item(const struct rte_flow_item *item)
217 : : {
218 [ # # ]: 0 : switch (item->type) {
219 : : case RTE_FLOW_ITEM_TYPE_ETH:
220 : : case RTE_FLOW_ITEM_TYPE_VLAN:
221 : : case RTE_FLOW_ITEM_TYPE_IPV4:
222 : : case RTE_FLOW_ITEM_TYPE_IPV6:
223 : : case RTE_FLOW_ITEM_TYPE_UDP:
224 : : case RTE_FLOW_ITEM_TYPE_TCP:
225 : : case RTE_FLOW_ITEM_TYPE_ESP:
226 : : case RTE_FLOW_ITEM_TYPE_ICMP:
227 : : case RTE_FLOW_ITEM_TYPE_ICMP6:
228 : : case RTE_FLOW_ITEM_TYPE_VXLAN:
229 : : case RTE_FLOW_ITEM_TYPE_NVGRE:
230 : : case RTE_FLOW_ITEM_TYPE_GRE:
231 : : case RTE_FLOW_ITEM_TYPE_GENEVE:
232 : : case RTE_FLOW_ITEM_TYPE_MPLS:
233 : : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
234 : : case RTE_FLOW_ITEM_TYPE_GRE_KEY:
235 : : case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
236 : : case RTE_FLOW_ITEM_TYPE_GTP:
237 : : return true;
238 : : default:
239 : : break;
240 : : }
241 : 0 : return false;
242 : : }
243 : :
244 : : /**
245 : : * Network Service Header (NSH) and its next protocol values
246 : : * are described in RFC-8393.
247 : : */
248 : : static enum rte_flow_item_type
249 : : mlx5_nsh_proto_to_item_type(uint8_t proto_spec, uint8_t proto_mask)
250 : : {
251 : : enum rte_flow_item_type type;
252 : :
253 : 0 : switch (proto_mask & proto_spec) {
254 : : case 0:
255 : : type = RTE_FLOW_ITEM_TYPE_VOID;
256 : : break;
257 : : case RTE_VXLAN_GPE_TYPE_IPV4:
258 : : type = RTE_FLOW_ITEM_TYPE_IPV4;
259 : : break;
260 : : case RTE_VXLAN_GPE_TYPE_IPV6:
261 : : type = RTE_VXLAN_GPE_TYPE_IPV6;
262 : : break;
263 : : case RTE_VXLAN_GPE_TYPE_ETH:
264 : : type = RTE_FLOW_ITEM_TYPE_ETH;
265 : : break;
266 : : default:
267 : : type = RTE_FLOW_ITEM_TYPE_END;
268 : : }
269 : : return type;
270 : : }
271 : :
272 : : static enum rte_flow_item_type
273 : : mlx5_inet_proto_to_item_type(uint8_t proto_spec, uint8_t proto_mask)
274 : : {
275 : : enum rte_flow_item_type type;
276 : :
277 [ # # # # : 0 : switch (proto_mask & proto_spec) {
# # # # #
# # # #
# ]
278 : : case 0:
279 : : type = RTE_FLOW_ITEM_TYPE_VOID;
280 : : break;
281 : 0 : case IPPROTO_UDP:
282 : : type = RTE_FLOW_ITEM_TYPE_UDP;
283 : 0 : break;
284 : 0 : case IPPROTO_TCP:
285 : : type = RTE_FLOW_ITEM_TYPE_TCP;
286 : 0 : break;
287 : 0 : case IPPROTO_IPIP:
288 : : type = RTE_FLOW_ITEM_TYPE_IPV4;
289 : 0 : break;
290 : 0 : case IPPROTO_IPV6:
291 : : type = RTE_FLOW_ITEM_TYPE_IPV6;
292 : 0 : break;
293 : 0 : case IPPROTO_ESP:
294 : : type = RTE_FLOW_ITEM_TYPE_ESP;
295 : 0 : break;
296 : 0 : default:
297 : : type = RTE_FLOW_ITEM_TYPE_END;
298 : : }
299 : : return type;
300 : : }
301 : :
302 : : static enum rte_flow_item_type
303 : : mlx5_ethertype_to_item_type(rte_be16_t type_spec,
304 : : rte_be16_t type_mask, bool is_tunnel)
305 : : {
306 : : enum rte_flow_item_type type;
307 : :
308 [ # # # # : 0 : switch (rte_be_to_cpu_16(type_spec & type_mask)) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
309 : : case 0:
310 : : type = RTE_FLOW_ITEM_TYPE_VOID;
311 : : break;
312 : 0 : case RTE_ETHER_TYPE_TEB:
313 : : type = is_tunnel ?
314 : : RTE_FLOW_ITEM_TYPE_ETH : RTE_FLOW_ITEM_TYPE_END;
315 : : break;
316 : 0 : case RTE_ETHER_TYPE_VLAN:
317 : : type = !is_tunnel ?
318 : : RTE_FLOW_ITEM_TYPE_VLAN : RTE_FLOW_ITEM_TYPE_END;
319 : : break;
320 : 0 : case RTE_ETHER_TYPE_IPV4:
321 : : type = RTE_FLOW_ITEM_TYPE_IPV4;
322 : 0 : break;
323 : 0 : case RTE_ETHER_TYPE_IPV6:
324 : : type = RTE_FLOW_ITEM_TYPE_IPV6;
325 : 0 : break;
326 : 0 : default:
327 : : type = RTE_FLOW_ITEM_TYPE_END;
328 : : }
329 : : return type;
330 : : }
331 : :
332 : : static enum rte_flow_item_type
333 : 0 : mlx5_flow_expand_rss_item_complete(const struct rte_flow_item *item)
334 : : {
335 : : #define MLX5_XSET_ITEM_MASK_SPEC(type, fld) \
336 : : do { \
337 : : const void *m = item->mask; \
338 : : const void *s = item->spec; \
339 : : mask = m ? \
340 : : ((const struct rte_flow_item_##type *)m)->fld : \
341 : : rte_flow_item_##type##_mask.fld; \
342 : : spec = ((const struct rte_flow_item_##type *)s)->fld; \
343 : : } while (0)
344 : :
345 : : enum rte_flow_item_type ret;
346 : : uint16_t spec, mask;
347 : :
348 [ # # # # ]: 0 : if (item == NULL || item->spec == NULL)
349 : : return RTE_FLOW_ITEM_TYPE_VOID;
350 [ # # # # : 0 : switch (item->type) {
# # # # ]
351 : 0 : case RTE_FLOW_ITEM_TYPE_ETH:
352 [ # # ]: 0 : MLX5_XSET_ITEM_MASK_SPEC(eth, hdr.ether_type);
353 [ # # ]: 0 : if (!mask)
354 : : return RTE_FLOW_ITEM_TYPE_VOID;
355 : : ret = mlx5_ethertype_to_item_type(spec, mask, false);
356 : : break;
357 : 0 : case RTE_FLOW_ITEM_TYPE_VLAN:
358 [ # # ]: 0 : MLX5_XSET_ITEM_MASK_SPEC(vlan, hdr.eth_proto);
359 [ # # ]: 0 : if (!mask)
360 : : return RTE_FLOW_ITEM_TYPE_VOID;
361 : : ret = mlx5_ethertype_to_item_type(spec, mask, false);
362 : : break;
363 : 0 : case RTE_FLOW_ITEM_TYPE_IPV4:
364 [ # # ]: 0 : MLX5_XSET_ITEM_MASK_SPEC(ipv4, hdr.next_proto_id);
365 [ # # ]: 0 : if (!mask)
366 : : return RTE_FLOW_ITEM_TYPE_VOID;
367 : : ret = mlx5_inet_proto_to_item_type(spec, mask);
368 : : break;
369 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6:
370 [ # # ]: 0 : MLX5_XSET_ITEM_MASK_SPEC(ipv6, hdr.proto);
371 [ # # ]: 0 : if (!mask)
372 : : return RTE_FLOW_ITEM_TYPE_VOID;
373 : : ret = mlx5_inet_proto_to_item_type(spec, mask);
374 : : break;
375 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE:
376 [ # # # # ]: 0 : MLX5_XSET_ITEM_MASK_SPEC(geneve, protocol);
377 : : ret = mlx5_ethertype_to_item_type(spec, mask, true);
378 : : break;
379 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
380 [ # # # # ]: 0 : MLX5_XSET_ITEM_MASK_SPEC(gre, protocol);
381 : : ret = mlx5_ethertype_to_item_type(spec, mask, true);
382 : : break;
383 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
384 [ # # ]: 0 : MLX5_XSET_ITEM_MASK_SPEC(vxlan_gpe, hdr.proto);
385 [ # # ]: 0 : ret = mlx5_nsh_proto_to_item_type(spec, mask);
386 : : break;
387 : : default:
388 : : ret = RTE_FLOW_ITEM_TYPE_VOID;
389 : : break;
390 : : }
391 : : return ret;
392 : : #undef MLX5_XSET_ITEM_MASK_SPEC
393 : : }
394 : :
395 : : static const int *
396 : : mlx5_flow_expand_rss_skip_explicit(const struct mlx5_flow_expand_node graph[],
397 : : const int *next_node)
398 : : {
399 : : const struct mlx5_flow_expand_node *node = NULL;
400 : : const int *next = next_node;
401 : :
402 [ # # # # : 0 : while (next && *next) {
# # # # #
# # # # #
# # ]
403 : : /*
404 : : * Skip the nodes with the MLX5_EXPANSION_NODE_EXPLICIT
405 : : * flag set, because they were not found in the flow pattern.
406 : : */
407 : 0 : node = &graph[*next];
408 [ # # # # : 0 : if (!(node->node_flags & MLX5_EXPANSION_NODE_EXPLICIT))
# # # # ]
409 : : break;
410 : 0 : next = node->next;
411 : : }
412 : : return next;
413 : : }
414 : :
415 : : #define MLX5_RSS_EXP_ELT_N 32
416 : :
417 : : /**
418 : : * Expand RSS flows into several possible flows according to the RSS hash
419 : : * fields requested and the driver capabilities.
420 : : *
421 : : * @param[out] buf
422 : : * Buffer to store the result expansion.
423 : : * @param[in] size
424 : : * Buffer size in bytes. If 0, @p buf can be NULL.
425 : : * @param[in] pattern
426 : : * User flow pattern.
427 : : * @param[in] types
428 : : * RSS types to expand (see RTE_ETH_RSS_* definitions).
429 : : * @param[in] graph
430 : : * Input graph to expand @p pattern according to @p types.
431 : : * @param[in] graph_root_index
432 : : * Index of root node in @p graph, typically 0.
433 : : *
434 : : * @return
435 : : * A positive value representing the size of @p buf in bytes regardless of
436 : : * @p size on success, a negative errno value otherwise and rte_errno is
437 : : * set, the following errors are defined:
438 : : *
439 : : * -E2BIG: graph-depth @p graph is too deep.
440 : : * -EINVAL: @p size has not enough space for expanded pattern.
441 : : */
442 : : static int
443 : 0 : mlx5_flow_expand_rss(struct mlx5_flow_expand_rss *buf, size_t size,
444 : : const struct rte_flow_item *pattern, uint64_t types,
445 : : const struct mlx5_flow_expand_node graph[],
446 : : int graph_root_index)
447 : : {
448 : : const struct rte_flow_item *item;
449 [ # # ]: 0 : const struct mlx5_flow_expand_node *node = &graph[graph_root_index];
450 : : const int *next_node;
451 : : const int *stack[MLX5_RSS_EXP_ELT_N];
452 : : int stack_pos = 0;
453 : : struct rte_flow_item flow_items[MLX5_RSS_EXP_ELT_N];
454 : : unsigned int i, item_idx, last_expand_item_idx = 0;
455 : : size_t lsize;
456 : : size_t user_pattern_size = 0;
457 : : void *addr = NULL;
458 : : const struct mlx5_flow_expand_node *next = NULL;
459 : : struct rte_flow_item missed_item;
460 : : int missed = 0;
461 : : int elt = 0;
462 : : const struct rte_flow_item *last_expand_item = NULL;
463 : :
464 : : memset(&missed_item, 0, sizeof(missed_item));
465 : : lsize = offsetof(struct mlx5_flow_expand_rss, entry) +
466 : : MLX5_RSS_EXP_ELT_N * sizeof(buf->entry[0]);
467 [ # # ]: 0 : if (lsize > size)
468 : : return -EINVAL;
469 : 0 : buf->entry[0].priority = 0;
470 : 0 : buf->entry[0].pattern = (void *)&buf->entry[MLX5_RSS_EXP_ELT_N];
471 : 0 : buf->entries = 0;
472 : : addr = buf->entry[0].pattern;
473 : 0 : for (item = pattern, item_idx = 0;
474 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_END;
475 : 0 : item++, item_idx++) {
476 [ # # ]: 0 : if (!mlx5_flow_is_rss_expandable_item(item)) {
477 : 0 : user_pattern_size += sizeof(*item);
478 : 0 : continue;
479 : : }
480 : : last_expand_item = item;
481 : : last_expand_item_idx = item_idx;
482 : : i = 0;
483 [ # # # # ]: 0 : while (node->next && node->next[i]) {
484 : 0 : next = &graph[node->next[i]];
485 [ # # ]: 0 : if (next->type == item->type)
486 : : break;
487 [ # # ]: 0 : if (next->node_flags & MLX5_EXPANSION_NODE_EXPLICIT) {
488 : : node = next;
489 : : i = 0;
490 : : } else {
491 : 0 : ++i;
492 : : }
493 : : }
494 [ # # ]: 0 : if (next)
495 : : node = next;
496 : 0 : user_pattern_size += sizeof(*item);
497 : : }
498 : 0 : user_pattern_size += sizeof(*item); /* Handle END item. */
499 : 0 : lsize += user_pattern_size;
500 [ # # ]: 0 : if (lsize > size)
501 : : return -EINVAL;
502 : : /* Copy the user pattern in the first entry of the buffer. */
503 : : rte_memcpy(addr, pattern, user_pattern_size);
504 : 0 : addr = (void *)(((uintptr_t)addr) + user_pattern_size);
505 : 0 : buf->entries = 1;
506 : : /* Start expanding. */
507 : : memset(flow_items, 0, sizeof(flow_items));
508 : : user_pattern_size -= sizeof(*item);
509 : : /*
510 : : * Check if the last valid item has spec set, need complete pattern,
511 : : * and the pattern can be used for expansion.
512 : : */
513 : 0 : missed_item.type = mlx5_flow_expand_rss_item_complete(last_expand_item);
514 [ # # ]: 0 : if (missed_item.type == RTE_FLOW_ITEM_TYPE_END) {
515 : : /* Item type END indicates expansion is not required. */
516 : 0 : return lsize;
517 : : }
518 [ # # ]: 0 : if (missed_item.type != RTE_FLOW_ITEM_TYPE_VOID) {
519 : : next = NULL;
520 : : missed = 1;
521 : : i = 0;
522 [ # # # # ]: 0 : while (node->next && node->next[i]) {
523 : 0 : next = &graph[node->next[i]];
524 [ # # ]: 0 : if (next->type == missed_item.type) {
525 : 0 : flow_items[0].type = missed_item.type;
526 : : flow_items[1].type = RTE_FLOW_ITEM_TYPE_END;
527 : 0 : break;
528 : : }
529 [ # # ]: 0 : if (next->node_flags & MLX5_EXPANSION_NODE_EXPLICIT) {
530 : : node = next;
531 : : i = 0;
532 : : } else {
533 : 0 : ++i;
534 : : }
535 : : next = NULL;
536 : : }
537 : : }
538 [ # # ]: 0 : if (next && missed) {
539 : : elt = 2; /* missed item + item end. */
540 : : node = next;
541 : 0 : lsize += elt * sizeof(*item) + user_pattern_size;
542 [ # # ]: 0 : if (lsize > size)
543 : : return -EINVAL;
544 [ # # ]: 0 : if (node->rss_types & types) {
545 : 0 : buf->entry[buf->entries].priority = 1;
546 : 0 : buf->entry[buf->entries].pattern = addr;
547 : 0 : buf->entries++;
548 [ # # ]: 0 : rte_memcpy(addr, buf->entry[0].pattern,
549 : : user_pattern_size);
550 [ # # ]: 0 : addr = (void *)(((uintptr_t)addr) + user_pattern_size);
551 : : rte_memcpy(addr, flow_items, elt * sizeof(*item));
552 : 0 : addr = (void *)(((uintptr_t)addr) +
553 : : elt * sizeof(*item));
554 : : }
555 [ # # ]: 0 : } else if (last_expand_item != NULL) {
556 : 0 : node = mlx5_flow_expand_rss_adjust_node(pattern,
557 : : last_expand_item_idx, graph, node);
558 : : }
559 : : memset(flow_items, 0, sizeof(flow_items));
560 : : next_node = mlx5_flow_expand_rss_skip_explicit(graph,
561 : 0 : node->next);
562 : 0 : stack[stack_pos] = next_node;
563 [ # # ]: 0 : node = next_node ? &graph[*next_node] : NULL;
564 [ # # ]: 0 : while (node) {
565 : 0 : flow_items[stack_pos].type = node->type;
566 [ # # ]: 0 : if (node->rss_types & types) {
567 : : size_t n;
568 : : /*
569 : : * compute the number of items to copy from the
570 : : * expansion and copy it.
571 : : * When the stack_pos is 0, there are 1 element in it,
572 : : * plus the addition END item.
573 : : */
574 : 0 : elt = stack_pos + 2;
575 : 0 : flow_items[stack_pos + 1].type = RTE_FLOW_ITEM_TYPE_END;
576 : 0 : lsize += elt * sizeof(*item) + user_pattern_size;
577 [ # # ]: 0 : if (lsize > size)
578 : : return -EINVAL;
579 : : n = elt * sizeof(*item);
580 : : MLX5_ASSERT((buf->entries) < MLX5_RSS_EXP_ELT_N);
581 : 0 : buf->entry[buf->entries].priority =
582 : 0 : stack_pos + 1 + missed;
583 : 0 : buf->entry[buf->entries].pattern = addr;
584 : 0 : buf->entries++;
585 [ # # ]: 0 : rte_memcpy(addr, buf->entry[0].pattern,
586 : : user_pattern_size);
587 : 0 : addr = (void *)(((uintptr_t)addr) +
588 : : user_pattern_size);
589 [ # # ]: 0 : rte_memcpy(addr, &missed_item,
590 : : missed * sizeof(*item));
591 [ # # ]: 0 : addr = (void *)(((uintptr_t)addr) +
592 : : missed * sizeof(*item));
593 : : rte_memcpy(addr, flow_items, n);
594 : 0 : addr = (void *)(((uintptr_t)addr) + n);
595 : : }
596 : : /* Go deeper. */
597 [ # # ]: 0 : if (!(node->node_flags & MLX5_EXPANSION_NODE_OPTIONAL) &&
598 [ # # ]: 0 : node->next) {
599 : : next_node = mlx5_flow_expand_rss_skip_explicit(graph,
600 : : node->next);
601 [ # # ]: 0 : if (stack_pos++ == MLX5_RSS_EXP_ELT_N) {
602 : 0 : rte_errno = E2BIG;
603 : 0 : return -rte_errno;
604 : : }
605 : 0 : stack[stack_pos] = next_node;
606 [ # # ]: 0 : } else if (*(next_node + 1)) {
607 : : /* Follow up with the next possibility. */
608 : 0 : next_node = mlx5_flow_expand_rss_skip_explicit(graph,
609 : : ++next_node);
610 [ # # ]: 0 : } else if (!stack_pos) {
611 : : /*
612 : : * Completing the traverse over the different paths.
613 : : * The next_node is advanced to the terminator.
614 : : */
615 : 0 : ++next_node;
616 : : } else {
617 : : /* Move to the next path. */
618 [ # # ]: 0 : while (stack_pos) {
619 : 0 : next_node = stack[--stack_pos];
620 : 0 : next_node++;
621 [ # # ]: 0 : if (*next_node)
622 : : break;
623 : : }
624 : : next_node = mlx5_flow_expand_rss_skip_explicit(graph,
625 : : next_node);
626 : 0 : stack[stack_pos] = next_node;
627 : : }
628 [ # # # # ]: 0 : node = next_node && *next_node ? &graph[*next_node] : NULL;
629 : : };
630 : 0 : return lsize;
631 : : }
632 : :
633 : : /**
634 : : * Expand SQN flows into several possible flows according to the Tx queue
635 : : * number
636 : : *
637 : : * @param[in] buf
638 : : * Buffer to store the result expansion.
639 : : * @param[in] size
640 : : * Buffer size in bytes. If 0, @p buf can be NULL.
641 : : * @param[in] pattern
642 : : * User flow pattern.
643 : : * @param[in] sq_specs
644 : : * Buffer to store sq spec.
645 : : *
646 : : * @return
647 : : * 0 for success and negative value for failure
648 : : *
649 : : */
650 : : static int
651 : 0 : mlx5_flow_expand_sqn(struct mlx5_flow_expand_sqn *buf, size_t size,
652 : : const struct rte_flow_item *pattern,
653 : : struct mlx5_rte_flow_item_sq *sq_specs)
654 : : {
655 : : const struct rte_flow_item *item;
656 : : bool port_representor = false;
657 : : size_t user_pattern_size = 0;
658 : : struct rte_eth_dev *dev;
659 : : struct mlx5_priv *priv;
660 : : void *addr = NULL;
661 : : uint16_t port_id;
662 : : size_t lsize;
663 : : int elt = 2;
664 : : uint16_t i;
665 : :
666 : 0 : buf->entries = 0;
667 [ # # ]: 0 : for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
668 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR) {
669 : 0 : const struct rte_flow_item_ethdev *pid_v = item->spec;
670 : :
671 [ # # ]: 0 : if (!pid_v)
672 : : return 0;
673 : 0 : port_id = pid_v->port_id;
674 : : port_representor = true;
675 : : }
676 : 0 : user_pattern_size += sizeof(*item);
677 : : }
678 [ # # ]: 0 : if (!port_representor)
679 : : return 0;
680 : 0 : dev = &rte_eth_devices[port_id];
681 : 0 : priv = dev->data->dev_private;
682 : 0 : buf->entry[0].pattern = (void *)&buf->entry[priv->txqs_n];
683 : 0 : lsize = offsetof(struct mlx5_flow_expand_sqn, entry) +
684 : 0 : sizeof(buf->entry[0]) * priv->txqs_n;
685 [ # # ]: 0 : if (lsize + (user_pattern_size + sizeof(struct rte_flow_item) * elt) * priv->txqs_n > size)
686 : : return -EINVAL;
687 : : addr = buf->entry[0].pattern;
688 [ # # ]: 0 : for (i = 0; i != priv->txqs_n; ++i) {
689 : 0 : struct rte_flow_item pattern_add[] = {
690 : : {
691 : : .type = (enum rte_flow_item_type)
692 : : MLX5_RTE_FLOW_ITEM_TYPE_SQ,
693 : 0 : .spec = &sq_specs[i],
694 : : },
695 : : {
696 : : .type = RTE_FLOW_ITEM_TYPE_END,
697 : : },
698 : : };
699 : 0 : struct mlx5_txq_ctrl *txq = mlx5_txq_get(dev, i);
700 : :
701 [ # # ]: 0 : if (txq == NULL)
702 : 0 : return -EINVAL;
703 : 0 : buf->entry[i].pattern = addr;
704 : 0 : sq_specs[i].queue = mlx5_txq_get_sqn(txq);
705 : 0 : mlx5_txq_release(dev, i);
706 : : rte_memcpy(addr, pattern, user_pattern_size);
707 [ # # ]: 0 : addr = (void *)(((uintptr_t)addr) + user_pattern_size);
708 : : rte_memcpy(addr, pattern_add, sizeof(struct rte_flow_item) * elt);
709 : 0 : addr = (void *)(((uintptr_t)addr) + sizeof(struct rte_flow_item) * elt);
710 : 0 : buf->entries++;
711 : : }
712 : : return 0;
713 : : }
714 : :
715 : : enum mlx5_expansion {
716 : : MLX5_EXPANSION_ROOT,
717 : : MLX5_EXPANSION_ROOT_OUTER,
718 : : MLX5_EXPANSION_OUTER_ETH,
719 : : MLX5_EXPANSION_OUTER_VLAN,
720 : : MLX5_EXPANSION_OUTER_IPV4,
721 : : MLX5_EXPANSION_OUTER_IPV4_UDP,
722 : : MLX5_EXPANSION_OUTER_IPV4_TCP,
723 : : MLX5_EXPANSION_OUTER_IPV4_ESP,
724 : : MLX5_EXPANSION_OUTER_IPV4_ICMP,
725 : : MLX5_EXPANSION_OUTER_IPV6,
726 : : MLX5_EXPANSION_OUTER_IPV6_UDP,
727 : : MLX5_EXPANSION_OUTER_IPV6_TCP,
728 : : MLX5_EXPANSION_OUTER_IPV6_ESP,
729 : : MLX5_EXPANSION_OUTER_IPV6_ICMP6,
730 : : MLX5_EXPANSION_VXLAN,
731 : : MLX5_EXPANSION_STD_VXLAN,
732 : : MLX5_EXPANSION_L3_VXLAN,
733 : : MLX5_EXPANSION_VXLAN_GPE,
734 : : MLX5_EXPANSION_GRE,
735 : : MLX5_EXPANSION_NVGRE,
736 : : MLX5_EXPANSION_GRE_KEY,
737 : : MLX5_EXPANSION_MPLS,
738 : : MLX5_EXPANSION_ETH,
739 : : MLX5_EXPANSION_VLAN,
740 : : MLX5_EXPANSION_IPV4,
741 : : MLX5_EXPANSION_IPV4_UDP,
742 : : MLX5_EXPANSION_IPV4_TCP,
743 : : MLX5_EXPANSION_IPV4_ESP,
744 : : MLX5_EXPANSION_IPV4_ICMP,
745 : : MLX5_EXPANSION_IPV6,
746 : : MLX5_EXPANSION_IPV6_UDP,
747 : : MLX5_EXPANSION_IPV6_TCP,
748 : : MLX5_EXPANSION_IPV6_ESP,
749 : : MLX5_EXPANSION_IPV6_ICMP6,
750 : : MLX5_EXPANSION_IPV6_FRAG_EXT,
751 : : MLX5_EXPANSION_GTP,
752 : : MLX5_EXPANSION_GENEVE,
753 : : };
754 : :
755 : : /** Supported expansion of items. */
756 : : static const struct mlx5_flow_expand_node mlx5_support_expansion[] = {
757 : : [MLX5_EXPANSION_ROOT] = {
758 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
759 : : MLX5_EXPANSION_IPV4,
760 : : MLX5_EXPANSION_IPV6),
761 : : .type = RTE_FLOW_ITEM_TYPE_END,
762 : : },
763 : : [MLX5_EXPANSION_ROOT_OUTER] = {
764 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH,
765 : : MLX5_EXPANSION_OUTER_IPV4,
766 : : MLX5_EXPANSION_OUTER_IPV6),
767 : : .type = RTE_FLOW_ITEM_TYPE_END,
768 : : },
769 : : [MLX5_EXPANSION_OUTER_ETH] = {
770 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_VLAN),
771 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
772 : : .rss_types = 0,
773 : : },
774 : : [MLX5_EXPANSION_OUTER_VLAN] = {
775 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
776 : : MLX5_EXPANSION_OUTER_IPV6),
777 : : .type = RTE_FLOW_ITEM_TYPE_VLAN,
778 : : .node_flags = MLX5_EXPANSION_NODE_EXPLICIT,
779 : : },
780 : : [MLX5_EXPANSION_OUTER_IPV4] = {
781 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT
782 : : (MLX5_EXPANSION_OUTER_IPV4_UDP,
783 : : MLX5_EXPANSION_OUTER_IPV4_TCP,
784 : : MLX5_EXPANSION_OUTER_IPV4_ESP,
785 : : MLX5_EXPANSION_OUTER_IPV4_ICMP,
786 : : MLX5_EXPANSION_GRE,
787 : : MLX5_EXPANSION_NVGRE,
788 : : MLX5_EXPANSION_IPV4,
789 : : MLX5_EXPANSION_IPV6),
790 : : .type = RTE_FLOW_ITEM_TYPE_IPV4,
791 : : .rss_types = RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_FRAG_IPV4 |
792 : : RTE_ETH_RSS_NONFRAG_IPV4_OTHER,
793 : : },
794 : : [MLX5_EXPANSION_OUTER_IPV4_UDP] = {
795 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
796 : : MLX5_EXPANSION_VXLAN_GPE,
797 : : MLX5_EXPANSION_MPLS,
798 : : MLX5_EXPANSION_GENEVE,
799 : : MLX5_EXPANSION_GTP),
800 : : .type = RTE_FLOW_ITEM_TYPE_UDP,
801 : : .rss_types = RTE_ETH_RSS_NONFRAG_IPV4_UDP,
802 : : },
803 : : [MLX5_EXPANSION_OUTER_IPV4_TCP] = {
804 : : .type = RTE_FLOW_ITEM_TYPE_TCP,
805 : : .rss_types = RTE_ETH_RSS_NONFRAG_IPV4_TCP,
806 : : },
807 : : [MLX5_EXPANSION_OUTER_IPV4_ESP] = {
808 : : .type = RTE_FLOW_ITEM_TYPE_ESP,
809 : : .rss_types = RTE_ETH_RSS_ESP,
810 : : },
811 : : [MLX5_EXPANSION_OUTER_IPV4_ICMP] = {
812 : : .type = RTE_FLOW_ITEM_TYPE_ICMP,
813 : : },
814 : : [MLX5_EXPANSION_OUTER_IPV6] = {
815 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT
816 : : (MLX5_EXPANSION_OUTER_IPV6_UDP,
817 : : MLX5_EXPANSION_OUTER_IPV6_TCP,
818 : : MLX5_EXPANSION_OUTER_IPV6_ESP,
819 : : MLX5_EXPANSION_OUTER_IPV6_ICMP6,
820 : : MLX5_EXPANSION_IPV4,
821 : : MLX5_EXPANSION_IPV6,
822 : : MLX5_EXPANSION_GRE,
823 : : MLX5_EXPANSION_NVGRE),
824 : : .type = RTE_FLOW_ITEM_TYPE_IPV6,
825 : : .rss_types = RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_FRAG_IPV6 |
826 : : RTE_ETH_RSS_NONFRAG_IPV6_OTHER,
827 : : },
828 : : [MLX5_EXPANSION_OUTER_IPV6_UDP] = {
829 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
830 : : MLX5_EXPANSION_VXLAN_GPE,
831 : : MLX5_EXPANSION_MPLS,
832 : : MLX5_EXPANSION_GENEVE,
833 : : MLX5_EXPANSION_GTP),
834 : : .type = RTE_FLOW_ITEM_TYPE_UDP,
835 : : .rss_types = RTE_ETH_RSS_NONFRAG_IPV6_UDP,
836 : : },
837 : : [MLX5_EXPANSION_OUTER_IPV6_TCP] = {
838 : : .type = RTE_FLOW_ITEM_TYPE_TCP,
839 : : .rss_types = RTE_ETH_RSS_NONFRAG_IPV6_TCP,
840 : : },
841 : : [MLX5_EXPANSION_OUTER_IPV6_ESP] = {
842 : : .type = RTE_FLOW_ITEM_TYPE_ESP,
843 : : .rss_types = RTE_ETH_RSS_ESP,
844 : : },
845 : : [MLX5_EXPANSION_OUTER_IPV6_ICMP6] = {
846 : : .type = RTE_FLOW_ITEM_TYPE_ICMP6,
847 : : },
848 : : [MLX5_EXPANSION_VXLAN] = {
849 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
850 : : MLX5_EXPANSION_IPV4,
851 : : MLX5_EXPANSION_IPV6),
852 : : .type = RTE_FLOW_ITEM_TYPE_VXLAN,
853 : : },
854 : : [MLX5_EXPANSION_STD_VXLAN] = {
855 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH),
856 : : .type = RTE_FLOW_ITEM_TYPE_VXLAN,
857 : : },
858 : : [MLX5_EXPANSION_L3_VXLAN] = {
859 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
860 : : MLX5_EXPANSION_IPV6),
861 : : .type = RTE_FLOW_ITEM_TYPE_VXLAN,
862 : : },
863 : : [MLX5_EXPANSION_VXLAN_GPE] = {
864 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
865 : : MLX5_EXPANSION_IPV4,
866 : : MLX5_EXPANSION_IPV6),
867 : : .type = RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
868 : : },
869 : : [MLX5_EXPANSION_GRE] = {
870 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
871 : : MLX5_EXPANSION_IPV4,
872 : : MLX5_EXPANSION_IPV6,
873 : : MLX5_EXPANSION_GRE_KEY,
874 : : MLX5_EXPANSION_MPLS),
875 : : .type = RTE_FLOW_ITEM_TYPE_GRE,
876 : : },
877 : : [MLX5_EXPANSION_GRE_KEY] = {
878 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
879 : : MLX5_EXPANSION_IPV6,
880 : : MLX5_EXPANSION_MPLS),
881 : : .type = RTE_FLOW_ITEM_TYPE_GRE_KEY,
882 : : .node_flags = MLX5_EXPANSION_NODE_OPTIONAL,
883 : : },
884 : : [MLX5_EXPANSION_NVGRE] = {
885 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH),
886 : : .type = RTE_FLOW_ITEM_TYPE_NVGRE,
887 : : },
888 : : [MLX5_EXPANSION_MPLS] = {
889 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
890 : : MLX5_EXPANSION_IPV6,
891 : : MLX5_EXPANSION_ETH),
892 : : .type = RTE_FLOW_ITEM_TYPE_MPLS,
893 : : .node_flags = MLX5_EXPANSION_NODE_OPTIONAL,
894 : : },
895 : : [MLX5_EXPANSION_ETH] = {
896 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VLAN),
897 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
898 : : },
899 : : [MLX5_EXPANSION_VLAN] = {
900 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
901 : : MLX5_EXPANSION_IPV6),
902 : : .type = RTE_FLOW_ITEM_TYPE_VLAN,
903 : : .node_flags = MLX5_EXPANSION_NODE_EXPLICIT,
904 : : },
905 : : [MLX5_EXPANSION_IPV4] = {
906 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4_UDP,
907 : : MLX5_EXPANSION_IPV4_TCP,
908 : : MLX5_EXPANSION_IPV4_ESP,
909 : : MLX5_EXPANSION_IPV4_ICMP),
910 : : .type = RTE_FLOW_ITEM_TYPE_IPV4,
911 : : .rss_types = RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_FRAG_IPV4 |
912 : : RTE_ETH_RSS_NONFRAG_IPV4_OTHER,
913 : : },
914 : : [MLX5_EXPANSION_IPV4_UDP] = {
915 : : .type = RTE_FLOW_ITEM_TYPE_UDP,
916 : : .rss_types = RTE_ETH_RSS_NONFRAG_IPV4_UDP,
917 : : },
918 : : [MLX5_EXPANSION_IPV4_TCP] = {
919 : : .type = RTE_FLOW_ITEM_TYPE_TCP,
920 : : .rss_types = RTE_ETH_RSS_NONFRAG_IPV4_TCP,
921 : : },
922 : : [MLX5_EXPANSION_IPV4_ESP] = {
923 : : .type = RTE_FLOW_ITEM_TYPE_ESP,
924 : : .rss_types = RTE_ETH_RSS_ESP,
925 : : },
926 : : [MLX5_EXPANSION_IPV4_ICMP] = {
927 : : .type = RTE_FLOW_ITEM_TYPE_ICMP,
928 : : },
929 : : [MLX5_EXPANSION_IPV6] = {
930 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV6_UDP,
931 : : MLX5_EXPANSION_IPV6_TCP,
932 : : MLX5_EXPANSION_IPV6_ESP,
933 : : MLX5_EXPANSION_IPV6_ICMP6,
934 : : MLX5_EXPANSION_IPV6_FRAG_EXT),
935 : : .type = RTE_FLOW_ITEM_TYPE_IPV6,
936 : : .rss_types = RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_FRAG_IPV6 |
937 : : RTE_ETH_RSS_NONFRAG_IPV6_OTHER,
938 : : },
939 : : [MLX5_EXPANSION_IPV6_UDP] = {
940 : : .type = RTE_FLOW_ITEM_TYPE_UDP,
941 : : .rss_types = RTE_ETH_RSS_NONFRAG_IPV6_UDP,
942 : : },
943 : : [MLX5_EXPANSION_IPV6_TCP] = {
944 : : .type = RTE_FLOW_ITEM_TYPE_TCP,
945 : : .rss_types = RTE_ETH_RSS_NONFRAG_IPV6_TCP,
946 : : },
947 : : [MLX5_EXPANSION_IPV6_ESP] = {
948 : : .type = RTE_FLOW_ITEM_TYPE_ESP,
949 : : .rss_types = RTE_ETH_RSS_ESP,
950 : : },
951 : : [MLX5_EXPANSION_IPV6_FRAG_EXT] = {
952 : : .type = RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT,
953 : : },
954 : : [MLX5_EXPANSION_IPV6_ICMP6] = {
955 : : .type = RTE_FLOW_ITEM_TYPE_ICMP6,
956 : : },
957 : : [MLX5_EXPANSION_GTP] = {
958 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
959 : : MLX5_EXPANSION_IPV6),
960 : : .type = RTE_FLOW_ITEM_TYPE_GTP,
961 : : },
962 : : [MLX5_EXPANSION_GENEVE] = {
963 : : .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
964 : : MLX5_EXPANSION_IPV4,
965 : : MLX5_EXPANSION_IPV6),
966 : : .type = RTE_FLOW_ITEM_TYPE_GENEVE,
967 : : },
968 : : };
969 : :
970 : : static struct rte_flow_action_handle *
971 : : mlx5_action_handle_create(struct rte_eth_dev *dev,
972 : : const struct rte_flow_indir_action_conf *conf,
973 : : const struct rte_flow_action *action,
974 : : struct rte_flow_error *error);
975 : : static int mlx5_action_handle_destroy
976 : : (struct rte_eth_dev *dev,
977 : : struct rte_flow_action_handle *handle,
978 : : struct rte_flow_error *error);
979 : : static int mlx5_action_handle_update
980 : : (struct rte_eth_dev *dev,
981 : : struct rte_flow_action_handle *handle,
982 : : const void *update,
983 : : struct rte_flow_error *error);
984 : : static int mlx5_action_handle_query
985 : : (struct rte_eth_dev *dev,
986 : : const struct rte_flow_action_handle *handle,
987 : : void *data,
988 : : struct rte_flow_error *error);
989 : : static int
990 : : mlx5_flow_tunnel_decap_set(struct rte_eth_dev *dev,
991 : : struct rte_flow_tunnel *app_tunnel,
992 : : struct rte_flow_action **actions,
993 : : uint32_t *num_of_actions,
994 : : struct rte_flow_error *error);
995 : : static int
996 : : mlx5_flow_tunnel_match(struct rte_eth_dev *dev,
997 : : struct rte_flow_tunnel *app_tunnel,
998 : : struct rte_flow_item **items,
999 : : uint32_t *num_of_items,
1000 : : struct rte_flow_error *error);
1001 : : static int
1002 : : mlx5_flow_tunnel_item_release(struct rte_eth_dev *dev,
1003 : : struct rte_flow_item *pmd_items,
1004 : : uint32_t num_items, struct rte_flow_error *err);
1005 : : static int
1006 : : mlx5_flow_tunnel_action_release(struct rte_eth_dev *dev,
1007 : : struct rte_flow_action *pmd_actions,
1008 : : uint32_t num_actions,
1009 : : struct rte_flow_error *err);
1010 : : static int
1011 : : mlx5_flow_tunnel_get_restore_info(struct rte_eth_dev *dev,
1012 : : struct rte_mbuf *m,
1013 : : struct rte_flow_restore_info *info,
1014 : : struct rte_flow_error *err);
1015 : : static struct rte_flow_item_flex_handle *
1016 : : mlx5_flow_flex_item_create(struct rte_eth_dev *dev,
1017 : : const struct rte_flow_item_flex_conf *conf,
1018 : : struct rte_flow_error *error);
1019 : : static int
1020 : : mlx5_flow_flex_item_release(struct rte_eth_dev *dev,
1021 : : const struct rte_flow_item_flex_handle *handle,
1022 : : struct rte_flow_error *error);
1023 : : static int
1024 : : mlx5_flow_info_get(struct rte_eth_dev *dev,
1025 : : struct rte_flow_port_info *port_info,
1026 : : struct rte_flow_queue_info *queue_info,
1027 : : struct rte_flow_error *error);
1028 : : static int
1029 : : mlx5_flow_port_configure(struct rte_eth_dev *dev,
1030 : : const struct rte_flow_port_attr *port_attr,
1031 : : uint16_t nb_queue,
1032 : : const struct rte_flow_queue_attr *queue_attr[],
1033 : : struct rte_flow_error *err);
1034 : :
1035 : : static struct rte_flow_pattern_template *
1036 : : mlx5_flow_pattern_template_create(struct rte_eth_dev *dev,
1037 : : const struct rte_flow_pattern_template_attr *attr,
1038 : : const struct rte_flow_item items[],
1039 : : struct rte_flow_error *error);
1040 : :
1041 : : static int
1042 : : mlx5_flow_pattern_template_destroy(struct rte_eth_dev *dev,
1043 : : struct rte_flow_pattern_template *template,
1044 : : struct rte_flow_error *error);
1045 : : static struct rte_flow_actions_template *
1046 : : mlx5_flow_actions_template_create(struct rte_eth_dev *dev,
1047 : : const struct rte_flow_actions_template_attr *attr,
1048 : : const struct rte_flow_action actions[],
1049 : : const struct rte_flow_action masks[],
1050 : : struct rte_flow_error *error);
1051 : : static int
1052 : : mlx5_flow_actions_template_destroy(struct rte_eth_dev *dev,
1053 : : struct rte_flow_actions_template *template,
1054 : : struct rte_flow_error *error);
1055 : :
1056 : : static struct rte_flow_template_table *
1057 : : mlx5_flow_table_create(struct rte_eth_dev *dev,
1058 : : const struct rte_flow_template_table_attr *attr,
1059 : : struct rte_flow_pattern_template *item_templates[],
1060 : : uint8_t nb_item_templates,
1061 : : struct rte_flow_actions_template *action_templates[],
1062 : : uint8_t nb_action_templates,
1063 : : struct rte_flow_error *error);
1064 : : static int
1065 : : mlx5_flow_table_destroy(struct rte_eth_dev *dev,
1066 : : struct rte_flow_template_table *table,
1067 : : struct rte_flow_error *error);
1068 : : static int
1069 : : mlx5_flow_group_set_miss_actions(struct rte_eth_dev *dev,
1070 : : uint32_t group_id,
1071 : : const struct rte_flow_group_attr *attr,
1072 : : const struct rte_flow_action actions[],
1073 : : struct rte_flow_error *error);
1074 : :
1075 : : static int
1076 : : mlx5_action_handle_query_update(struct rte_eth_dev *dev,
1077 : : struct rte_flow_action_handle *handle,
1078 : : const void *update, void *query,
1079 : : enum rte_flow_query_update_mode qu_mode,
1080 : : struct rte_flow_error *error);
1081 : :
1082 : : static struct rte_flow_action_list_handle *
1083 : : mlx5_action_list_handle_create(struct rte_eth_dev *dev,
1084 : : const struct rte_flow_indir_action_conf *conf,
1085 : : const struct rte_flow_action *actions,
1086 : : struct rte_flow_error *error);
1087 : :
1088 : : static int
1089 : : mlx5_action_list_handle_destroy(struct rte_eth_dev *dev,
1090 : : struct rte_flow_action_list_handle *handle,
1091 : : struct rte_flow_error *error);
1092 : :
1093 : : static int
1094 : : mlx5_flow_action_list_handle_query_update(struct rte_eth_dev *dev,
1095 : : const
1096 : : struct rte_flow_action_list_handle *handle,
1097 : : const void **update, void **query,
1098 : : enum rte_flow_query_update_mode mode,
1099 : : struct rte_flow_error *error);
1100 : :
1101 : : static int
1102 : : mlx5_flow_calc_table_hash(struct rte_eth_dev *dev,
1103 : : const struct rte_flow_template_table *table,
1104 : : const struct rte_flow_item pattern[],
1105 : : uint8_t pattern_template_index,
1106 : : uint32_t *hash, struct rte_flow_error *error);
1107 : : static int
1108 : : mlx5_flow_calc_encap_hash(struct rte_eth_dev *dev,
1109 : : const struct rte_flow_item pattern[],
1110 : : enum rte_flow_encap_hash_field dest_field,
1111 : : uint8_t *hash,
1112 : : struct rte_flow_error *error);
1113 : :
1114 : : static int
1115 : : mlx5_template_table_resize(struct rte_eth_dev *dev,
1116 : : struct rte_flow_template_table *table,
1117 : : uint32_t nb_rules, struct rte_flow_error *error);
1118 : : static int
1119 : : mlx5_flow_async_update_resized(struct rte_eth_dev *dev, uint32_t queue,
1120 : : const struct rte_flow_op_attr *attr,
1121 : : struct rte_flow *rule, void *user_data,
1122 : : struct rte_flow_error *error);
1123 : : static int
1124 : : mlx5_table_resize_complete(struct rte_eth_dev *dev,
1125 : : struct rte_flow_template_table *table,
1126 : : struct rte_flow_error *error);
1127 : :
1128 : : static const struct rte_flow_ops mlx5_flow_ops = {
1129 : : .validate = mlx5_flow_validate,
1130 : : .create = mlx5_flow_create,
1131 : : .destroy = mlx5_flow_destroy,
1132 : : .flush = mlx5_flow_flush,
1133 : : .isolate = mlx5_flow_isolate,
1134 : : .query = mlx5_flow_query,
1135 : : .dev_dump = mlx5_flow_dev_dump,
1136 : : .get_q_aged_flows = mlx5_flow_get_q_aged_flows,
1137 : : .get_aged_flows = mlx5_flow_get_aged_flows,
1138 : : .action_handle_create = mlx5_action_handle_create,
1139 : : .action_handle_destroy = mlx5_action_handle_destroy,
1140 : : .action_handle_update = mlx5_action_handle_update,
1141 : : .action_handle_query = mlx5_action_handle_query,
1142 : : .action_handle_query_update = mlx5_action_handle_query_update,
1143 : : .action_list_handle_create = mlx5_action_list_handle_create,
1144 : : .action_list_handle_destroy = mlx5_action_list_handle_destroy,
1145 : : .tunnel_decap_set = mlx5_flow_tunnel_decap_set,
1146 : : .tunnel_match = mlx5_flow_tunnel_match,
1147 : : .tunnel_action_decap_release = mlx5_flow_tunnel_action_release,
1148 : : .tunnel_item_release = mlx5_flow_tunnel_item_release,
1149 : : .get_restore_info = mlx5_flow_tunnel_get_restore_info,
1150 : : .flex_item_create = mlx5_flow_flex_item_create,
1151 : : .flex_item_release = mlx5_flow_flex_item_release,
1152 : : .info_get = mlx5_flow_info_get,
1153 : : .pick_transfer_proxy = mlx5_flow_pick_transfer_proxy,
1154 : : .configure = mlx5_flow_port_configure,
1155 : : .pattern_template_create = mlx5_flow_pattern_template_create,
1156 : : .pattern_template_destroy = mlx5_flow_pattern_template_destroy,
1157 : : .actions_template_create = mlx5_flow_actions_template_create,
1158 : : .actions_template_destroy = mlx5_flow_actions_template_destroy,
1159 : : .template_table_create = mlx5_flow_table_create,
1160 : : .template_table_destroy = mlx5_flow_table_destroy,
1161 : : .group_set_miss_actions = mlx5_flow_group_set_miss_actions,
1162 : : .action_list_handle_query_update =
1163 : : mlx5_flow_action_list_handle_query_update,
1164 : : .flow_calc_table_hash = mlx5_flow_calc_table_hash,
1165 : : .flow_calc_encap_hash = mlx5_flow_calc_encap_hash,
1166 : : .flow_template_table_resize = mlx5_template_table_resize,
1167 : : .flow_update_resized = mlx5_flow_async_update_resized,
1168 : : .flow_template_table_resize_complete = mlx5_table_resize_complete,
1169 : : };
1170 : :
1171 : : /* Tunnel information. */
1172 : : struct mlx5_flow_tunnel_info {
1173 : : uint64_t tunnel; /**< Tunnel bit (see MLX5_FLOW_*). */
1174 : : uint32_t ptype; /**< Tunnel Ptype (see RTE_PTYPE_*). */
1175 : : };
1176 : :
1177 : : static struct mlx5_flow_tunnel_info tunnels_info[] = {
1178 : : {
1179 : : .tunnel = MLX5_FLOW_LAYER_VXLAN,
1180 : : .ptype = RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_L4_UDP,
1181 : : },
1182 : : {
1183 : : .tunnel = MLX5_FLOW_LAYER_GENEVE,
1184 : : .ptype = RTE_PTYPE_TUNNEL_GENEVE | RTE_PTYPE_L4_UDP,
1185 : : },
1186 : : {
1187 : : .tunnel = MLX5_FLOW_LAYER_VXLAN_GPE,
1188 : : .ptype = RTE_PTYPE_TUNNEL_VXLAN_GPE | RTE_PTYPE_L4_UDP,
1189 : : },
1190 : : {
1191 : : .tunnel = MLX5_FLOW_LAYER_GRE,
1192 : : .ptype = RTE_PTYPE_TUNNEL_GRE,
1193 : : },
1194 : : {
1195 : : .tunnel = MLX5_FLOW_LAYER_MPLS | MLX5_FLOW_LAYER_OUTER_L4_UDP,
1196 : : .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_UDP | RTE_PTYPE_L4_UDP,
1197 : : },
1198 : : {
1199 : : .tunnel = MLX5_FLOW_LAYER_MPLS,
1200 : : .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE,
1201 : : },
1202 : : {
1203 : : .tunnel = MLX5_FLOW_LAYER_NVGRE,
1204 : : .ptype = RTE_PTYPE_TUNNEL_NVGRE,
1205 : : },
1206 : : {
1207 : : .tunnel = MLX5_FLOW_LAYER_IPIP,
1208 : : .ptype = RTE_PTYPE_TUNNEL_IP,
1209 : : },
1210 : : {
1211 : : .tunnel = MLX5_FLOW_LAYER_IPV6_ENCAP,
1212 : : .ptype = RTE_PTYPE_TUNNEL_IP,
1213 : : },
1214 : : {
1215 : : .tunnel = MLX5_FLOW_LAYER_GTP,
1216 : : .ptype = RTE_PTYPE_TUNNEL_GTPU,
1217 : : },
1218 : : };
1219 : :
1220 : :
1221 : :
1222 : : /**
1223 : : * Translate tag ID to register.
1224 : : *
1225 : : * @param[in] dev
1226 : : * Pointer to the Ethernet device structure.
1227 : : * @param[in] feature
1228 : : * The feature that request the register.
1229 : : * @param[in] id
1230 : : * The request register ID.
1231 : : * @param[out] error
1232 : : * Error description in case of any.
1233 : : *
1234 : : * @return
1235 : : * The request register on success, a negative errno
1236 : : * value otherwise and rte_errno is set.
1237 : : */
1238 : : int
1239 : 0 : mlx5_flow_get_reg_id(struct rte_eth_dev *dev,
1240 : : enum mlx5_feature_name feature,
1241 : : uint32_t id,
1242 : : struct rte_flow_error *error)
1243 : : {
1244 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1245 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
1246 : : struct mlx5_dev_registers *reg = &priv->sh->registers;
1247 : : enum modify_reg start_reg;
1248 : : bool skip_mtr_reg = false;
1249 : :
1250 [ # # # # : 0 : switch (feature) {
# # # # #
# # ]
1251 : : case MLX5_HAIRPIN_RX:
1252 : : return REG_B;
1253 : 0 : case MLX5_HAIRPIN_TX:
1254 : 0 : return REG_A;
1255 : 0 : case MLX5_METADATA_RX:
1256 [ # # ]: 0 : if (mlx5_vport_rx_metadata_passing_enabled(priv->sh)) {
1257 : : return REG_C_1;
1258 : : } else {
1259 [ # # # # : 0 : switch (config->dv_xmeta_en) {
# ]
1260 : : case MLX5_XMETA_MODE_LEGACY:
1261 : : return REG_B;
1262 : 0 : case MLX5_XMETA_MODE_META16:
1263 : 0 : return REG_C_0;
1264 : 0 : case MLX5_XMETA_MODE_META32:
1265 : 0 : return REG_C_1;
1266 : 0 : case MLX5_XMETA_MODE_META32_HWS:
1267 : 0 : return REG_C_1;
1268 : : }
1269 : : }
1270 : : break;
1271 : 0 : case MLX5_METADATA_TX:
1272 [ # # ]: 0 : if ((config->dv_flow_en == 2 &&
1273 [ # # ]: 0 : config->dv_xmeta_en == MLX5_XMETA_MODE_META32_HWS) ||
1274 : 0 : mlx5_vport_tx_metadata_passing_enabled(priv->sh)) {
1275 : 0 : return REG_C_1;
1276 : : } else {
1277 : : return REG_A;
1278 : : }
1279 : 0 : case MLX5_METADATA_FDB:
1280 [ # # ]: 0 : if (mlx5_esw_metadata_passing_enabled(priv->sh)) {
1281 : : return REG_C_1;
1282 : : } else {
1283 [ # # # # : 0 : switch (config->dv_xmeta_en) {
# ]
1284 : : case MLX5_XMETA_MODE_LEGACY:
1285 : : return REG_NON;
1286 : 0 : case MLX5_XMETA_MODE_META16:
1287 : 0 : return REG_C_0;
1288 : 0 : case MLX5_XMETA_MODE_META32:
1289 : 0 : return REG_C_1;
1290 : 0 : case MLX5_XMETA_MODE_META32_HWS:
1291 : 0 : return REG_C_1;
1292 : : }
1293 : : }
1294 : : break;
1295 : 0 : case MLX5_FLOW_MARK:
1296 [ # # # # ]: 0 : switch (config->dv_xmeta_en) {
1297 : : case MLX5_XMETA_MODE_LEGACY:
1298 : : case MLX5_XMETA_MODE_META32_HWS:
1299 : : return REG_NON;
1300 : 0 : case MLX5_XMETA_MODE_META16:
1301 : 0 : return REG_C_1;
1302 : 0 : case MLX5_XMETA_MODE_META32:
1303 : 0 : return REG_C_0;
1304 : : }
1305 : : break;
1306 : 0 : case MLX5_MTR_ID:
1307 : : /*
1308 : : * If meter color and meter id share one register, flow match
1309 : : * should use the meter color register for match.
1310 : : */
1311 [ # # ]: 0 : if (priv->mtr_reg_share)
1312 : 0 : return reg->aso_reg;
1313 : : else
1314 [ # # ]: 0 : return reg->aso_reg != REG_C_2 ? REG_C_2 :
1315 : : REG_C_3;
1316 : 0 : case MLX5_MTR_COLOR:
1317 : : case MLX5_ASO_FLOW_HIT:
1318 : : case MLX5_ASO_CONNTRACK:
1319 : : case MLX5_SAMPLE_ID:
1320 : : /* All features use the same REG_C. */
1321 : : MLX5_ASSERT(reg->aso_reg != REG_NON);
1322 : 0 : return reg->aso_reg;
1323 : 0 : case MLX5_COPY_MARK:
1324 : : /*
1325 : : * Metadata COPY_MARK register using is in meter suffix sub
1326 : : * flow while with meter. It's safe to share the same register.
1327 : : */
1328 [ # # ]: 0 : return reg->aso_reg != REG_C_2 ? REG_C_2 : REG_C_3;
1329 : 0 : case MLX5_APP_TAG:
1330 : : /*
1331 : : * If meter is enable, it will engage the register for color
1332 : : * match and flow match. If meter color match is not using the
1333 : : * REG_C_2, need to skip the REG_C_x be used by meter color
1334 : : * match.
1335 : : * If meter is disable, free to use all available registers.
1336 : : */
1337 [ # # ]: 0 : start_reg = reg->aso_reg != REG_C_2 ? REG_C_2 :
1338 [ # # ]: 0 : (priv->mtr_reg_share ? REG_C_3 : REG_C_4);
1339 [ # # # # ]: 0 : skip_mtr_reg = !!(priv->mtr_en && start_reg == REG_C_2);
1340 [ # # ]: 0 : if (id > (uint32_t)(REG_C_7 - start_reg))
1341 : 0 : return rte_flow_error_set(error, EINVAL,
1342 : : RTE_FLOW_ERROR_TYPE_ITEM,
1343 : : NULL, "invalid tag id");
1344 [ # # ]: 0 : if (priv->sh->flow_mreg_c[id + start_reg - REG_C_0] == REG_NON)
1345 : 0 : return rte_flow_error_set(error, ENOTSUP,
1346 : : RTE_FLOW_ERROR_TYPE_ITEM,
1347 : : NULL, "unsupported tag id");
1348 : : /*
1349 : : * This case means meter is using the REG_C_x great than 2.
1350 : : * Take care not to conflict with meter color REG_C_x.
1351 : : * If the available index REG_C_y >= REG_C_x, skip the
1352 : : * color register.
1353 : : */
1354 [ # # # # ]: 0 : if (skip_mtr_reg && priv->sh->flow_mreg_c
1355 : : [id + start_reg - REG_C_0] >= reg->aso_reg) {
1356 [ # # ]: 0 : if (id >= (uint32_t)(REG_C_7 - start_reg))
1357 : 0 : return rte_flow_error_set(error, EINVAL,
1358 : : RTE_FLOW_ERROR_TYPE_ITEM,
1359 : : NULL, "invalid tag id");
1360 : 0 : if (priv->sh->flow_mreg_c
1361 [ # # ]: 0 : [id + 1 + start_reg - REG_C_0] != REG_NON)
1362 : : return priv->sh->flow_mreg_c
1363 : 0 : [id + 1 + start_reg - REG_C_0];
1364 : 0 : return rte_flow_error_set(error, ENOTSUP,
1365 : : RTE_FLOW_ERROR_TYPE_ITEM,
1366 : : NULL, "unsupported tag id");
1367 : : }
1368 : 0 : return priv->sh->flow_mreg_c[id + start_reg - REG_C_0];
1369 : : }
1370 : : MLX5_ASSERT(false);
1371 : 0 : return rte_flow_error_set(error, EINVAL,
1372 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1373 : : NULL, "invalid feature name");
1374 : : }
1375 : :
1376 : : /**
1377 : : * Check extensive flow metadata register support.
1378 : : *
1379 : : * @param dev
1380 : : * Pointer to rte_eth_dev structure.
1381 : : *
1382 : : * @return
1383 : : * True if device supports extensive flow metadata register, otherwise false.
1384 : : */
1385 : : bool
1386 : 0 : mlx5_flow_ext_mreg_supported(struct rte_eth_dev *dev)
1387 : : {
1388 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1389 : :
1390 : : /*
1391 : : * Having available reg_c can be regarded inclusively as supporting
1392 : : * extensive flow metadata register, which could mean,
1393 : : * - metadata register copy action by modify header.
1394 : : * - 16 modify header actions is supported.
1395 : : * - reg_c's are preserved across different domain (FDB and NIC) on
1396 : : * packet loopback by flow lookup miss.
1397 : : */
1398 : 0 : return priv->sh->flow_mreg_c[2] != REG_NON;
1399 : : }
1400 : :
1401 : : /**
1402 : : * Get the lowest priority.
1403 : : *
1404 : : * @param[in] dev
1405 : : * Pointer to the Ethernet device structure.
1406 : : * @param[in] attributes
1407 : : * Pointer to device flow rule attributes.
1408 : : *
1409 : : * @return
1410 : : * The value of lowest priority of flow.
1411 : : */
1412 : : uint32_t
1413 : 0 : mlx5_get_lowest_priority(struct rte_eth_dev *dev,
1414 : : const struct rte_flow_attr *attr)
1415 : : {
1416 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1417 : :
1418 [ # # # # : 0 : if (!attr->group && !(attr->transfer && priv->fdb_def_rule))
# # ]
1419 : 0 : return priv->sh->flow_max_priority - 2;
1420 : : return MLX5_NON_ROOT_FLOW_MAX_PRIO - 1;
1421 : : }
1422 : :
1423 : : /**
1424 : : * Calculate matcher priority of the flow.
1425 : : *
1426 : : * @param[in] dev
1427 : : * Pointer to the Ethernet device structure.
1428 : : * @param[in] attr
1429 : : * Pointer to device flow rule attributes.
1430 : : * @param[in] subpriority
1431 : : * The priority based on the items.
1432 : : * @param[in] external
1433 : : * Flow is user flow.
1434 : : * @return
1435 : : * The matcher priority of the flow.
1436 : : */
1437 : : uint16_t
1438 : 0 : mlx5_get_matcher_priority(struct rte_eth_dev *dev,
1439 : : const struct rte_flow_attr *attr,
1440 : : uint32_t subpriority, bool external)
1441 : : {
1442 : 0 : uint16_t priority = (uint16_t)attr->priority;
1443 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1444 : :
1445 : : /* NIC root rules */
1446 [ # # # # ]: 0 : if (!attr->group && !attr->transfer) {
1447 [ # # ]: 0 : if (attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)
1448 : 0 : priority = priv->sh->flow_max_priority - 1;
1449 : 0 : return mlx5_os_flow_adjust_priority(dev, priority, subpriority);
1450 : : /* FDB root rules */
1451 [ # # # # : 0 : } else if (attr->transfer && (!external || !priv->fdb_def_rule) &&
# # # # ]
1452 [ # # ]: 0 : attr->group == 0 &&
1453 : : attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR) {
1454 : 0 : return (priv->sh->flow_max_priority - 1) * 3;
1455 : : }
1456 [ # # ]: 0 : if (attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)
1457 : : priority = MLX5_NON_ROOT_FLOW_MAX_PRIO;
1458 : 0 : return priority * 3 + subpriority;
1459 : : }
1460 : :
1461 : : /**
1462 : : * Verify the @p item specifications (spec, last, mask) are compatible with the
1463 : : * NIC capabilities.
1464 : : *
1465 : : * @param[in] item
1466 : : * Item specification.
1467 : : * @param[in] mask
1468 : : * @p item->mask or flow default bit-masks.
1469 : : * @param[in] nic_mask
1470 : : * Bit-masks covering supported fields by the NIC to compare with user mask.
1471 : : * @param[in] size
1472 : : * Bit-masks size in bytes.
1473 : : * @param[in] range_accepted
1474 : : * True if range of values is accepted for specific fields, false otherwise.
1475 : : * @param[out] error
1476 : : * Pointer to error structure.
1477 : : *
1478 : : * @return
1479 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1480 : : */
1481 : : int
1482 : 0 : mlx5_flow_item_acceptable(const struct rte_eth_dev *dev,
1483 : : const struct rte_flow_item *item,
1484 : : const uint8_t *mask,
1485 : : const uint8_t *nic_mask,
1486 : : unsigned int size,
1487 : : bool range_accepted,
1488 : : struct rte_flow_error *error)
1489 : : {
1490 : : unsigned int i;
1491 : :
1492 : : MLX5_ASSERT(nic_mask);
1493 [ # # ]: 0 : for (i = 0; i < size; ++i)
1494 [ # # ]: 0 : if ((nic_mask[i] | mask[i]) != nic_mask[i])
1495 : 0 : return rte_flow_error_set(error, ENOTSUP,
1496 : : RTE_FLOW_ERROR_TYPE_ITEM,
1497 : : item,
1498 : : "mask enables non supported"
1499 : : " bits");
1500 [ # # ]: 0 : if (mlx5_hws_active(dev))
1501 : : return 0;
1502 [ # # # # : 0 : if (!item->spec && (item->mask || item->last))
# # ]
1503 : 0 : return rte_flow_error_set(error, EINVAL,
1504 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
1505 : : "mask/last without a spec is not"
1506 : : " supported");
1507 [ # # # # : 0 : if (item->spec && item->last && !range_accepted) {
# # ]
1508 : 0 : uint8_t *spec = alloca(size);
1509 : 0 : uint8_t *last = alloca(size);
1510 : : unsigned int i;
1511 : : int ret;
1512 : :
1513 [ # # ]: 0 : for (i = 0; i < size; ++i) {
1514 : 0 : spec[i] = ((const uint8_t *)item->spec)[i] & mask[i];
1515 : 0 : last[i] = ((const uint8_t *)item->last)[i] & mask[i];
1516 : : }
1517 : 0 : ret = memcmp(spec, last, size);
1518 [ # # ]: 0 : if (ret != 0)
1519 : 0 : return rte_flow_error_set(error, EINVAL,
1520 : : RTE_FLOW_ERROR_TYPE_ITEM,
1521 : : item,
1522 : : "range is not valid");
1523 : : }
1524 : : return 0;
1525 : : }
1526 : :
1527 : : /**
1528 : : * Adjust the hash fields according to the @p flow information.
1529 : : *
1530 : : * @param[in] dev_flow.
1531 : : * Pointer to the mlx5_flow.
1532 : : * @param[in] tunnel
1533 : : * 1 when the hash field is for a tunnel item.
1534 : : * @param[in] layer_types
1535 : : * RTE_ETH_RSS_* types.
1536 : : * @param[in] hash_fields
1537 : : * Item hash fields.
1538 : : *
1539 : : * @return
1540 : : * The hash fields that should be used.
1541 : : */
1542 : : uint64_t
1543 : 0 : mlx5_flow_hashfields_adjust(struct mlx5_flow_rss_desc *rss_desc,
1544 : : int tunnel __rte_unused, uint64_t layer_types,
1545 : : uint64_t hash_fields)
1546 : : {
1547 : : #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
1548 : 0 : int rss_request_inner = rss_desc->level >= 2;
1549 : :
1550 : : /* Check RSS hash level for tunnel. */
1551 [ # # ]: 0 : if (tunnel && rss_request_inner)
1552 : 0 : hash_fields |= IBV_RX_HASH_INNER;
1553 [ # # ]: 0 : else if (tunnel || rss_request_inner)
1554 : : return 0;
1555 : : #endif
1556 : : /* Check if requested layer matches RSS hash fields. */
1557 [ # # ]: 0 : if (!(rss_desc->types & layer_types))
1558 : 0 : return 0;
1559 : : return hash_fields;
1560 : : }
1561 : :
1562 : : /**
1563 : : * Lookup and set the ptype in the data Rx part. A single Ptype can be used,
1564 : : * if several tunnel rules are used on this queue, the tunnel ptype will be
1565 : : * cleared.
1566 : : *
1567 : : * @param rxq_ctrl
1568 : : * Rx queue to update.
1569 : : */
1570 : : static void
1571 : : flow_rxq_tunnel_ptype_update(struct mlx5_rxq_ctrl *rxq_ctrl)
1572 : : {
1573 : : unsigned int i;
1574 : : uint32_t tunnel_ptype = 0;
1575 : :
1576 : : /* Look up for the ptype to use. */
1577 [ # # # # ]: 0 : for (i = 0; i != MLX5_FLOW_TUNNEL; ++i) {
1578 [ # # # # ]: 0 : if (!rxq_ctrl->flow_tunnels_n[i])
1579 : 0 : continue;
1580 [ # # # # ]: 0 : if (!tunnel_ptype) {
1581 : 0 : tunnel_ptype = tunnels_info[i].ptype;
1582 : : } else {
1583 : : tunnel_ptype = 0;
1584 : : break;
1585 : : }
1586 : : }
1587 : 0 : rxq_ctrl->rxq.tunnel = tunnel_ptype;
1588 : 0 : }
1589 : :
1590 : : /**
1591 : : * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) according to the device
1592 : : * flow.
1593 : : *
1594 : : * @param[in] dev
1595 : : * Pointer to the Ethernet device structure.
1596 : : * @param[in] dev_handle
1597 : : * Pointer to device flow handle structure.
1598 : : */
1599 : : void
1600 : 0 : mlx5_flow_drv_rxq_flags_set(struct rte_eth_dev *dev,
1601 : : struct mlx5_flow_handle *dev_handle)
1602 : : {
1603 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1604 : 0 : const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1605 : : struct mlx5_ind_table_obj *ind_tbl = NULL;
1606 : : unsigned int i;
1607 : :
1608 [ # # ]: 0 : if (dev_handle->fate_action == MLX5_FLOW_FATE_QUEUE) {
1609 : : struct mlx5_hrxq *hrxq;
1610 : :
1611 : 0 : hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1612 : : dev_handle->rix_hrxq);
1613 [ # # ]: 0 : if (hrxq)
1614 : 0 : ind_tbl = hrxq->ind_table;
1615 [ # # ]: 0 : } else if (dev_handle->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
1616 : : struct mlx5_shared_action_rss *shared_rss;
1617 : :
1618 : 0 : shared_rss = mlx5_ipool_get
1619 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
1620 : : dev_handle->rix_srss);
1621 [ # # ]: 0 : if (shared_rss)
1622 : 0 : ind_tbl = shared_rss->ind_tbl;
1623 : : }
1624 [ # # ]: 0 : if (!ind_tbl)
1625 : 0 : return;
1626 [ # # ]: 0 : for (i = 0; i != ind_tbl->queues_n; ++i) {
1627 [ # # ]: 0 : int idx = ind_tbl->queues[i];
1628 : : struct mlx5_rxq_ctrl *rxq_ctrl;
1629 : :
1630 [ # # ]: 0 : if (mlx5_is_external_rxq(dev, idx))
1631 : 0 : continue;
1632 : 0 : rxq_ctrl = mlx5_rxq_ctrl_get(dev, idx);
1633 : : MLX5_ASSERT(rxq_ctrl != NULL);
1634 [ # # ]: 0 : if (rxq_ctrl == NULL)
1635 : 0 : continue;
1636 : : /*
1637 : : * To support metadata register copy on Tx loopback,
1638 : : * this must be always enabled (metadata may arive
1639 : : * from other port - not from local flows only.
1640 : : */
1641 [ # # ]: 0 : if (tunnel) {
1642 : : unsigned int j;
1643 : :
1644 : : /* Increase the counter matching the flow. */
1645 [ # # ]: 0 : for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1646 : 0 : if ((tunnels_info[j].tunnel &
1647 [ # # ]: 0 : dev_handle->layers) ==
1648 : : tunnels_info[j].tunnel) {
1649 : 0 : rxq_ctrl->flow_tunnels_n[j]++;
1650 : 0 : break;
1651 : : }
1652 : : }
1653 : : flow_rxq_tunnel_ptype_update(rxq_ctrl);
1654 : : }
1655 : : }
1656 : : }
1657 : :
1658 : : void
1659 : 0 : mlx5_flow_rxq_mark_flag_set(struct rte_eth_dev *dev)
1660 : : {
1661 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1662 : : struct mlx5_rxq_ctrl *rxq_ctrl;
1663 : : uint16_t port_id;
1664 : :
1665 [ # # ]: 0 : if (priv->sh->shared_mark_enabled)
1666 : : return;
1667 [ # # ]: 0 : if (priv->master || priv->representor) {
1668 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port_id, dev->device) {
1669 : 0 : struct mlx5_priv *opriv =
1670 : 0 : rte_eth_devices[port_id].data->dev_private;
1671 : :
1672 [ # # ]: 0 : if (!opriv ||
1673 [ # # ]: 0 : opriv->sh != priv->sh ||
1674 [ # # # # ]: 0 : opriv->domain_id != priv->domain_id ||
1675 : : opriv->mark_enabled)
1676 : 0 : continue;
1677 [ # # ]: 0 : LIST_FOREACH(rxq_ctrl, &opriv->rxqsctrl, next) {
1678 : 0 : rxq_ctrl->rxq.mark = 1;
1679 : : }
1680 [ # # ]: 0 : LIST_FOREACH(rxq_ctrl, &opriv->sh->shared_rxqs, next) {
1681 : 0 : rxq_ctrl->rxq.mark = 1;
1682 : : }
1683 : 0 : opriv->mark_enabled = 1;
1684 : : }
1685 : : } else {
1686 [ # # ]: 0 : LIST_FOREACH(rxq_ctrl, &priv->rxqsctrl, next) {
1687 : 0 : rxq_ctrl->rxq.mark = 1;
1688 : : }
1689 [ # # ]: 0 : LIST_FOREACH(rxq_ctrl, &priv->sh->shared_rxqs, next) {
1690 : 0 : rxq_ctrl->rxq.mark = 1;
1691 : : }
1692 : 0 : priv->mark_enabled = 1;
1693 : : }
1694 : 0 : priv->sh->shared_mark_enabled = 1;
1695 : : }
1696 : :
1697 : : /**
1698 : : * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) for a flow
1699 : : *
1700 : : * @param[in] dev
1701 : : * Pointer to the Ethernet device structure.
1702 : : * @param[in] flow
1703 : : * Pointer to flow structure.
1704 : : */
1705 : : static void
1706 : 0 : flow_rxq_flags_set(struct rte_eth_dev *dev, struct rte_flow *flow)
1707 : : {
1708 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1709 : : uint32_t handle_idx;
1710 : : struct mlx5_flow_handle *dev_handle;
1711 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
1712 : :
1713 : : MLX5_ASSERT(wks);
1714 [ # # ]: 0 : if (wks->mark)
1715 : 0 : mlx5_flow_rxq_mark_flag_set(dev);
1716 [ # # # # : 0 : SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
# # ]
1717 : : handle_idx, dev_handle, next)
1718 : 0 : mlx5_flow_drv_rxq_flags_set(dev, dev_handle);
1719 : 0 : }
1720 : :
1721 : : /**
1722 : : * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1723 : : * device flow if no other flow uses it with the same kind of request.
1724 : : *
1725 : : * @param dev
1726 : : * Pointer to Ethernet device.
1727 : : * @param[in] dev_handle
1728 : : * Pointer to the device flow handle structure.
1729 : : */
1730 : : static void
1731 : 0 : flow_drv_rxq_flags_trim(struct rte_eth_dev *dev,
1732 : : struct mlx5_flow_handle *dev_handle)
1733 : : {
1734 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1735 : 0 : const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
1736 : : struct mlx5_ind_table_obj *ind_tbl = NULL;
1737 : : unsigned int i;
1738 : :
1739 [ # # ]: 0 : if (dev_handle->fate_action == MLX5_FLOW_FATE_QUEUE) {
1740 : : struct mlx5_hrxq *hrxq;
1741 : :
1742 : 0 : hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
1743 : : dev_handle->rix_hrxq);
1744 [ # # ]: 0 : if (hrxq)
1745 : 0 : ind_tbl = hrxq->ind_table;
1746 [ # # ]: 0 : } else if (dev_handle->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
1747 : : struct mlx5_shared_action_rss *shared_rss;
1748 : :
1749 : 0 : shared_rss = mlx5_ipool_get
1750 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
1751 : : dev_handle->rix_srss);
1752 [ # # ]: 0 : if (shared_rss)
1753 : 0 : ind_tbl = shared_rss->ind_tbl;
1754 : : }
1755 [ # # ]: 0 : if (!ind_tbl)
1756 : 0 : return;
1757 : : MLX5_ASSERT(dev->data->dev_started);
1758 [ # # ]: 0 : for (i = 0; i != ind_tbl->queues_n; ++i) {
1759 [ # # ]: 0 : int idx = ind_tbl->queues[i];
1760 : : struct mlx5_rxq_ctrl *rxq_ctrl;
1761 : :
1762 [ # # ]: 0 : if (mlx5_is_external_rxq(dev, idx))
1763 : 0 : continue;
1764 : 0 : rxq_ctrl = mlx5_rxq_ctrl_get(dev, idx);
1765 : : MLX5_ASSERT(rxq_ctrl != NULL);
1766 [ # # ]: 0 : if (rxq_ctrl == NULL)
1767 : 0 : continue;
1768 [ # # ]: 0 : if (tunnel) {
1769 : : unsigned int j;
1770 : :
1771 : : /* Decrease the counter matching the flow. */
1772 [ # # ]: 0 : for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
1773 : 0 : if ((tunnels_info[j].tunnel &
1774 [ # # ]: 0 : dev_handle->layers) ==
1775 : : tunnels_info[j].tunnel) {
1776 : 0 : rxq_ctrl->flow_tunnels_n[j]--;
1777 : 0 : break;
1778 : : }
1779 : : }
1780 : : flow_rxq_tunnel_ptype_update(rxq_ctrl);
1781 : : }
1782 : : }
1783 : : }
1784 : :
1785 : : /**
1786 : : * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
1787 : : * @p flow if no other flow uses it with the same kind of request.
1788 : : *
1789 : : * @param dev
1790 : : * Pointer to Ethernet device.
1791 : : * @param[in] flow
1792 : : * Pointer to the flow.
1793 : : */
1794 : : static void
1795 : 0 : flow_rxq_flags_trim(struct rte_eth_dev *dev, struct rte_flow *flow)
1796 : : {
1797 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1798 : : uint32_t handle_idx;
1799 : : struct mlx5_flow_handle *dev_handle;
1800 : :
1801 [ # # # # : 0 : SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
# # ]
1802 : : handle_idx, dev_handle, next)
1803 : 0 : flow_drv_rxq_flags_trim(dev, dev_handle);
1804 : 0 : }
1805 : :
1806 : : /**
1807 : : * Clear the Mark/Flag and Tunnel ptype information in all Rx queues.
1808 : : *
1809 : : * @param dev
1810 : : * Pointer to Ethernet device.
1811 : : */
1812 : : void
1813 : 0 : mlx5_flow_rxq_flags_clear(struct rte_eth_dev *dev)
1814 : : {
1815 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1816 : : unsigned int i;
1817 : :
1818 [ # # ]: 0 : for (i = 0; i != priv->rxqs_n; ++i) {
1819 : 0 : struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, i);
1820 : : unsigned int j;
1821 : :
1822 [ # # # # ]: 0 : if (rxq == NULL || rxq->ctrl == NULL)
1823 : 0 : continue;
1824 : 0 : rxq->ctrl->rxq.mark = 0;
1825 [ # # ]: 0 : for (j = 0; j != MLX5_FLOW_TUNNEL; ++j)
1826 : 0 : rxq->ctrl->flow_tunnels_n[j] = 0;
1827 : 0 : rxq->ctrl->rxq.tunnel = 0;
1828 : : }
1829 : 0 : priv->mark_enabled = 0;
1830 : 0 : priv->sh->shared_mark_enabled = 0;
1831 : 0 : }
1832 : :
1833 : : static uint64_t mlx5_restore_info_dynflag;
1834 : :
1835 : : int
1836 : 0 : mlx5_flow_rx_metadata_negotiate(struct rte_eth_dev *dev, uint64_t *features)
1837 : : {
1838 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
1839 : : uint64_t supported = 0;
1840 : :
1841 [ # # ]: 0 : if (!is_tunnel_offload_active(dev)) {
1842 : : supported |= RTE_ETH_RX_METADATA_USER_FLAG;
1843 : : supported |= RTE_ETH_RX_METADATA_USER_MARK;
1844 [ # # ]: 0 : if ((*features & RTE_ETH_RX_METADATA_TUNNEL_ID) != 0) {
1845 : 0 : DRV_LOG(DEBUG,
1846 : : "tunnel offload was not activated, consider setting dv_xmeta_en=%d",
1847 : : MLX5_XMETA_MODE_MISS_INFO);
1848 : : }
1849 : : } else {
1850 : : supported |= RTE_ETH_RX_METADATA_TUNNEL_ID;
1851 [ # # ]: 0 : if ((*features & RTE_ETH_RX_METADATA_TUNNEL_ID) != 0 &&
1852 [ # # ]: 0 : mlx5_restore_info_dynflag == 0)
1853 : 0 : mlx5_restore_info_dynflag = rte_flow_restore_info_dynflag();
1854 : : }
1855 : :
1856 [ # # ]: 0 : if (((*features & supported) & RTE_ETH_RX_METADATA_TUNNEL_ID) != 0)
1857 : 0 : priv->tunnel_enabled = 1;
1858 : : else
1859 : 0 : priv->tunnel_enabled = 0;
1860 : :
1861 : 0 : *features &= supported;
1862 : 0 : return 0;
1863 : : }
1864 : :
1865 : : /**
1866 : : * Set the Rx queue dynamic metadata (mask and offset) for a flow
1867 : : *
1868 : : * @param[in] dev
1869 : : * Pointer to the Ethernet device structure.
1870 : : */
1871 : : void
1872 : 0 : mlx5_flow_rxq_dynf_set(struct rte_eth_dev *dev)
1873 : : {
1874 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1875 : : uint64_t mark_flag = RTE_MBUF_F_RX_FDIR_ID;
1876 : : unsigned int i;
1877 : :
1878 [ # # ]: 0 : if (priv->tunnel_enabled)
1879 : 0 : mark_flag |= mlx5_restore_info_dynflag;
1880 : :
1881 [ # # ]: 0 : for (i = 0; i != priv->rxqs_n; ++i) {
1882 : 0 : struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, i);
1883 : : struct mlx5_rxq_data *data;
1884 : :
1885 [ # # # # ]: 0 : if (rxq == NULL || rxq->ctrl == NULL)
1886 : 0 : continue;
1887 : : data = &rxq->ctrl->rxq;
1888 [ # # # # ]: 0 : if (!data->shared || !rxq->ctrl->started) {
1889 [ # # ]: 0 : if (!rte_flow_dynf_metadata_avail()) {
1890 : 0 : data->dynf_meta = 0;
1891 : 0 : data->flow_meta_mask = 0;
1892 : 0 : data->flow_meta_offset = -1;
1893 : 0 : data->flow_meta_port_mask = 0;
1894 : : } else {
1895 : 0 : data->dynf_meta = 1;
1896 : 0 : data->flow_meta_mask = rte_flow_dynf_metadata_mask;
1897 : 0 : data->flow_meta_offset = rte_flow_dynf_metadata_offs;
1898 : 0 : data->flow_meta_port_mask = priv->sh->dv_meta_mask;
1899 : : }
1900 : : }
1901 : 0 : data->mark = !!priv->mark_enabled;
1902 : 0 : data->mark_flag = mark_flag;
1903 : : }
1904 : 0 : }
1905 : :
1906 : : /*
1907 : : * return a pointer to the desired action in the list of actions.
1908 : : *
1909 : : * @param[in] actions
1910 : : * The list of actions to search the action in.
1911 : : * @param[in] action
1912 : : * The action to find.
1913 : : *
1914 : : * @return
1915 : : * Pointer to the action in the list, if found. NULL otherwise.
1916 : : */
1917 : : const struct rte_flow_action *
1918 : 0 : mlx5_flow_find_action(const struct rte_flow_action *actions,
1919 : : enum rte_flow_action_type action)
1920 : : {
1921 [ # # ]: 0 : if (actions == NULL)
1922 : : return NULL;
1923 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++)
1924 [ # # ]: 0 : if (actions->type == action)
1925 : 0 : return actions;
1926 : : return NULL;
1927 : : }
1928 : :
1929 : : /*
1930 : : * Validate the flag action.
1931 : : *
1932 : : * @param[in] action_flags
1933 : : * Bit-fields that holds the actions detected until now.
1934 : : * @param[in] attr
1935 : : * Attributes of flow that includes this action.
1936 : : * @param[out] error
1937 : : * Pointer to error structure.
1938 : : *
1939 : : * @return
1940 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1941 : : */
1942 : : int
1943 : 0 : mlx5_flow_validate_action_flag(uint64_t action_flags,
1944 : : const struct rte_flow_attr *attr,
1945 : : struct rte_flow_error *error)
1946 : : {
1947 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
1948 : 0 : return rte_flow_error_set(error, EINVAL,
1949 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1950 : : "can't mark and flag in same flow");
1951 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_FLAG)
1952 : 0 : return rte_flow_error_set(error, EINVAL,
1953 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1954 : : "can't have 2 flag"
1955 : : " actions in same flow");
1956 [ # # ]: 0 : if (attr->egress)
1957 : 0 : return rte_flow_error_set(error, ENOTSUP,
1958 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
1959 : : "flag action not supported for "
1960 : : "egress");
1961 : : return 0;
1962 : : }
1963 : :
1964 : : /*
1965 : : * Validate the mark action.
1966 : : *
1967 : : * @param[in] action
1968 : : * Pointer to the queue action.
1969 : : * @param[in] action_flags
1970 : : * Bit-fields that holds the actions detected until now.
1971 : : * @param[in] attr
1972 : : * Attributes of flow that includes this action.
1973 : : * @param[out] error
1974 : : * Pointer to error structure.
1975 : : *
1976 : : * @return
1977 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1978 : : */
1979 : : int
1980 : 0 : mlx5_flow_validate_action_mark(__rte_unused struct rte_eth_dev *dev,
1981 : : const struct rte_flow_action *action,
1982 : : uint64_t action_flags,
1983 : : const struct rte_flow_attr *attr,
1984 : : struct rte_flow_error *error)
1985 : : {
1986 : 0 : const struct rte_flow_action_mark *mark = action->conf;
1987 : :
1988 [ # # ]: 0 : if (!mark)
1989 : 0 : return rte_flow_error_set(error, EINVAL,
1990 : : RTE_FLOW_ERROR_TYPE_ACTION,
1991 : : action,
1992 : : "configuration cannot be null");
1993 [ # # ]: 0 : if (mark->id >= MLX5_FLOW_MARK_MAX)
1994 : 0 : return rte_flow_error_set(error, EINVAL,
1995 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1996 : 0 : &mark->id,
1997 : : "mark id must in 0 <= id < "
1998 : : RTE_STR(MLX5_FLOW_MARK_MAX));
1999 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_FLAG)
2000 : 0 : return rte_flow_error_set(error, EINVAL,
2001 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2002 : : "can't flag and mark in same flow");
2003 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
2004 : 0 : return rte_flow_error_set(error, EINVAL,
2005 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2006 : : "can't have 2 mark actions in same"
2007 : : " flow");
2008 [ # # ]: 0 : if (attr->egress)
2009 : 0 : return rte_flow_error_set(error, ENOTSUP,
2010 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
2011 : : "mark action not supported for "
2012 : : "egress");
2013 : : return 0;
2014 : : }
2015 : :
2016 : : /*
2017 : : * Validate the drop action.
2018 : : *
2019 : : * @param[in] dev
2020 : : * Pointer to the Ethernet device structure.
2021 : : * @param[in] is_root
2022 : : * True if flow is validated for root table. False otherwise.
2023 : : * @param[in] attr
2024 : : * Attributes of flow that includes this action.
2025 : : * @param[out] error
2026 : : * Pointer to error structure.
2027 : : *
2028 : : * @return
2029 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2030 : : */
2031 : : int
2032 : 0 : mlx5_flow_validate_action_drop(struct rte_eth_dev *dev,
2033 : : bool is_root,
2034 : : const struct rte_flow_attr *attr,
2035 : : struct rte_flow_error *error)
2036 : : {
2037 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2038 : :
2039 [ # # # # ]: 0 : if (priv->sh->config.dv_flow_en == 0 && attr->egress)
2040 : 0 : return rte_flow_error_set(error, ENOTSUP,
2041 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
2042 : : "drop action not supported for "
2043 : : "egress");
2044 [ # # # # : 0 : if (priv->sh->config.dv_flow_en == 1 && is_root && (attr->egress || attr->transfer) &&
# # ]
2045 [ # # ]: 0 : !priv->sh->dr_root_drop_action_en) {
2046 : 0 : return rte_flow_error_set(error, ENOTSUP,
2047 : : RTE_FLOW_ERROR_TYPE_ATTR, NULL,
2048 : : "drop action not supported for "
2049 : : "egress and transfer on group 0");
2050 : : }
2051 : : return 0;
2052 : : }
2053 : :
2054 : : /*
2055 : : * Check if a queue specified in the queue action is valid.
2056 : : *
2057 : : * @param[in] dev
2058 : : * Pointer to the Ethernet device structure.
2059 : : * @param[in] action
2060 : : * Pointer to the queue action.
2061 : : * @param[out] error
2062 : : * Pointer to error structure.
2063 : : *
2064 : : * @return
2065 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2066 : : */
2067 : : int
2068 : 0 : mlx5_flow_validate_target_queue(struct rte_eth_dev *dev,
2069 : : const struct rte_flow_action *action,
2070 : : struct rte_flow_error *error)
2071 : : {
2072 : 0 : const struct rte_flow_action_queue *queue = action->conf;
2073 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2074 : :
2075 [ # # # # ]: 0 : if (mlx5_is_external_rxq(dev, queue->index))
2076 : : return 0;
2077 [ # # ]: 0 : if (!priv->rxqs_n)
2078 : 0 : return rte_flow_error_set(error, EINVAL,
2079 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2080 : : NULL, "No Rx queues configured");
2081 [ # # ]: 0 : if (queue->index >= priv->rxqs_n)
2082 : 0 : return rte_flow_error_set(error, EINVAL,
2083 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2084 : 0 : &queue->index,
2085 : : "queue index out of range");
2086 [ # # ]: 0 : if (mlx5_rxq_get(dev, queue->index) == NULL)
2087 : 0 : return rte_flow_error_set(error, EINVAL,
2088 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2089 : 0 : &queue->index,
2090 : : "queue is not configured");
2091 : : return 0;
2092 : : }
2093 : :
2094 : : /*
2095 : : * Validate the queue action.
2096 : : *
2097 : : * @param[in] action
2098 : : * Pointer to the queue action.
2099 : : * @param[in] action_flags
2100 : : * Bit-fields that holds the actions detected until now.
2101 : : * @param[in] dev
2102 : : * Pointer to the Ethernet device structure.
2103 : : * @param[in] attr
2104 : : * Attributes of flow that includes this action.
2105 : : * @param[out] error
2106 : : * Pointer to error structure.
2107 : : *
2108 : : * @return
2109 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2110 : : */
2111 : : int
2112 : 0 : mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
2113 : : uint64_t action_flags,
2114 : : struct rte_eth_dev *dev,
2115 : : const struct rte_flow_attr *attr,
2116 : : struct rte_flow_error *error)
2117 : : {
2118 : 0 : const struct rte_flow_action_queue *queue = action->conf;
2119 : :
2120 [ # # ]: 0 : if (!queue)
2121 : 0 : return rte_flow_error_set(error, EINVAL,
2122 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
2123 : : "no QUEUE action configuration");
2124 [ # # ]: 0 : if (action_flags & MLX5_FLOW_FATE_ACTIONS)
2125 : 0 : return rte_flow_error_set(error, EINVAL,
2126 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2127 : : "can't have 2 fate actions in"
2128 : : " same flow");
2129 [ # # ]: 0 : if (attr->egress)
2130 : 0 : return rte_flow_error_set(error, ENOTSUP,
2131 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
2132 : : "queue action not supported for egress.");
2133 : 0 : return mlx5_flow_validate_target_queue(dev, action, error);
2134 : : }
2135 : :
2136 : : /**
2137 : : * Validate queue numbers for device RSS.
2138 : : *
2139 : : * @param[in] dev
2140 : : * Configured device.
2141 : : * @param[in] queues
2142 : : * Array of queue numbers.
2143 : : * @param[in] queues_n
2144 : : * Size of the @p queues array.
2145 : : * @param[out] error
2146 : : * On error, filled with a textual error description.
2147 : : * @param[out] queue_idx
2148 : : * On error, filled with an offending queue index in @p queues array.
2149 : : *
2150 : : * @return
2151 : : * 0 on success, a negative errno code on error.
2152 : : */
2153 : : static int
2154 : 0 : mlx5_validate_rss_queues(struct rte_eth_dev *dev,
2155 : : const uint16_t *queues, uint32_t queues_n,
2156 : : const char **error, uint32_t *queue_idx)
2157 : : {
2158 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
2159 : : bool is_hairpin = false;
2160 : : bool is_ext_rss = false;
2161 : : uint32_t i;
2162 : :
2163 [ # # ]: 0 : for (i = 0; i != queues_n; ++i) {
2164 : : struct mlx5_rxq_ctrl *rxq_ctrl;
2165 : :
2166 [ # # # # ]: 0 : if (mlx5_is_external_rxq(dev, queues[0])) {
2167 : : is_ext_rss = true;
2168 : 0 : continue;
2169 : : }
2170 [ # # ]: 0 : if (is_ext_rss) {
2171 : 0 : *error = "Combining external and regular RSS queues is not supported";
2172 : 0 : *queue_idx = i;
2173 : 0 : return -ENOTSUP;
2174 : : }
2175 [ # # ]: 0 : if (queues[i] >= priv->rxqs_n) {
2176 : 0 : *error = "queue index out of range";
2177 : 0 : *queue_idx = i;
2178 : 0 : return -EINVAL;
2179 : : }
2180 : 0 : rxq_ctrl = mlx5_rxq_ctrl_get(dev, queues[i]);
2181 [ # # ]: 0 : if (rxq_ctrl == NULL) {
2182 : 0 : *error = "queue is not configured";
2183 : 0 : *queue_idx = i;
2184 : 0 : return -EINVAL;
2185 : : }
2186 [ # # # # ]: 0 : if (i == 0 && rxq_ctrl->is_hairpin)
2187 : : is_hairpin = true;
2188 [ # # ]: 0 : if (is_hairpin != rxq_ctrl->is_hairpin) {
2189 : 0 : *error = "combining hairpin and regular RSS queues is not supported";
2190 : 0 : *queue_idx = i;
2191 : 0 : return -ENOTSUP;
2192 : : }
2193 : : }
2194 : : return 0;
2195 : : }
2196 : :
2197 : : /*
2198 : : * Validate the rss action.
2199 : : *
2200 : : * @param[in] dev
2201 : : * Pointer to the Ethernet device structure.
2202 : : * @param[in] action
2203 : : * Pointer to the queue action.
2204 : : * @param[out] error
2205 : : * Pointer to error structure.
2206 : : *
2207 : : * @return
2208 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2209 : : */
2210 : : int
2211 : 0 : mlx5_validate_action_rss(struct rte_eth_dev *dev,
2212 : : const struct rte_flow_action *action,
2213 : : struct rte_flow_error *error)
2214 : : {
2215 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2216 : 0 : const struct rte_flow_action_rss *rss = action->conf;
2217 : : int ret;
2218 : : const char *message;
2219 : : uint32_t queue_idx;
2220 : :
2221 [ # # ]: 0 : if (!rss)
2222 : 0 : return rte_flow_error_set
2223 : : (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
2224 : : action, "no RSS action configuration");
2225 [ # # ]: 0 : if (rss->func == RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ) {
2226 : 0 : DRV_LOG(WARNING, "port %u symmetric RSS supported with SORT",
2227 : : dev->data->port_id);
2228 [ # # ]: 0 : } else if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
2229 : : rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
2230 : 0 : return rte_flow_error_set(error, ENOTSUP,
2231 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2232 : 0 : &rss->func,
2233 : : "RSS hash function not supported");
2234 : : #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
2235 [ # # ]: 0 : if (rss->level > 2)
2236 : : #else
2237 : : if (rss->level > 1)
2238 : : #endif
2239 : 0 : return rte_flow_error_set(error, ENOTSUP,
2240 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2241 : 0 : &rss->level,
2242 : : "tunnel RSS is not supported");
2243 : : /* allow RSS key_len 0 in case of NULL (default) RSS key. */
2244 [ # # # # ]: 0 : if (rss->key_len == 0 && rss->key != NULL)
2245 : 0 : return rte_flow_error_set(error, ENOTSUP,
2246 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2247 : 0 : &rss->key_len,
2248 : : "RSS hash key length 0");
2249 [ # # ]: 0 : if (rss->key_len > 0 && rss->key_len < MLX5_RSS_HASH_KEY_LEN)
2250 : 0 : return rte_flow_error_set(error, ENOTSUP,
2251 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2252 : 0 : &rss->key_len,
2253 : : "RSS hash key too small");
2254 [ # # ]: 0 : if (rss->key_len > MLX5_RSS_HASH_KEY_LEN)
2255 : 0 : return rte_flow_error_set(error, ENOTSUP,
2256 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2257 : 0 : &rss->key_len,
2258 : : "RSS hash key too large");
2259 [ # # ]: 0 : if (rss->queue_num > priv->sh->dev_cap.ind_table_max_size)
2260 : 0 : return rte_flow_error_set(error, ENOTSUP,
2261 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2262 : 0 : &rss->queue_num,
2263 : : "number of queues too large");
2264 [ # # ]: 0 : if (rss->types & MLX5_RSS_HF_MASK)
2265 : 0 : return rte_flow_error_set(error, ENOTSUP,
2266 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2267 : 0 : &rss->types,
2268 : : "some RSS protocols are not"
2269 : : " supported");
2270 [ # # ]: 0 : if ((rss->types & (RTE_ETH_RSS_L3_SRC_ONLY | RTE_ETH_RSS_L3_DST_ONLY)) &&
2271 [ # # ]: 0 : !(rss->types & RTE_ETH_RSS_IP))
2272 : 0 : return rte_flow_error_set(error, EINVAL,
2273 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
2274 : : "L3 partial RSS requested but L3 RSS"
2275 : : " type not specified");
2276 [ # # ]: 0 : if ((rss->types & (RTE_ETH_RSS_L4_SRC_ONLY | RTE_ETH_RSS_L4_DST_ONLY)) &&
2277 [ # # ]: 0 : !(rss->types & (RTE_ETH_RSS_UDP | RTE_ETH_RSS_TCP)))
2278 : 0 : return rte_flow_error_set(error, EINVAL,
2279 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
2280 : : "L4 partial RSS requested but L4 RSS"
2281 : : " type not specified");
2282 [ # # # # ]: 0 : if (!priv->rxqs_n && priv->ext_rxqs == NULL)
2283 : 0 : return rte_flow_error_set(error, EINVAL,
2284 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2285 : : NULL, "No Rx queues configured");
2286 [ # # ]: 0 : if (!rss->queue_num)
2287 : 0 : return rte_flow_error_set(error, EINVAL,
2288 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2289 : : NULL, "No queues configured");
2290 : 0 : ret = mlx5_validate_rss_queues(dev, rss->queue, rss->queue_num,
2291 : : &message, &queue_idx);
2292 [ # # ]: 0 : if (ret != 0) {
2293 : 0 : return rte_flow_error_set(error, -ret,
2294 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2295 : 0 : &rss->queue[queue_idx], message);
2296 : : }
2297 : : return 0;
2298 : : }
2299 : :
2300 : : /*
2301 : : * Validate the rss action.
2302 : : *
2303 : : * @param[in] action
2304 : : * Pointer to the queue action.
2305 : : * @param[in] action_flags
2306 : : * Bit-fields that holds the actions detected until now.
2307 : : * @param[in] dev
2308 : : * Pointer to the Ethernet device structure.
2309 : : * @param[in] attr
2310 : : * Attributes of flow that includes this action.
2311 : : * @param[in] item_flags
2312 : : * Items that were detected.
2313 : : * @param[out] error
2314 : : * Pointer to error structure.
2315 : : *
2316 : : * @return
2317 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2318 : : */
2319 : : int
2320 : 0 : mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
2321 : : uint64_t action_flags,
2322 : : struct rte_eth_dev *dev,
2323 : : const struct rte_flow_attr *attr,
2324 : : uint64_t item_flags,
2325 : : struct rte_flow_error *error)
2326 : : {
2327 : 0 : const struct rte_flow_action_rss *rss = action->conf;
2328 : 0 : int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2329 : : int ret;
2330 : :
2331 [ # # ]: 0 : if (action_flags & MLX5_FLOW_FATE_ACTIONS)
2332 : 0 : return rte_flow_error_set(error, EINVAL,
2333 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2334 : : "can't have 2 fate actions"
2335 : : " in same flow");
2336 : 0 : ret = mlx5_validate_action_rss(dev, action, error);
2337 [ # # ]: 0 : if (ret)
2338 : : return ret;
2339 [ # # ]: 0 : if (attr->egress)
2340 : 0 : return rte_flow_error_set(error, ENOTSUP,
2341 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
2342 : : "rss action not supported for "
2343 : : "egress");
2344 [ # # # # ]: 0 : if (rss->level > 1 && !tunnel)
2345 : 0 : return rte_flow_error_set(error, EINVAL,
2346 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
2347 : : "inner RSS is not supported for "
2348 : : "non-tunnel flows");
2349 [ # # ]: 0 : if ((item_flags & MLX5_FLOW_LAYER_ECPRI) &&
2350 : : !(item_flags & MLX5_FLOW_LAYER_INNER_L4_UDP)) {
2351 : 0 : return rte_flow_error_set(error, EINVAL,
2352 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
2353 : : "RSS on eCPRI is not supported now");
2354 : : }
2355 [ # # ]: 0 : if ((item_flags & MLX5_FLOW_LAYER_MPLS) &&
2356 : : !(item_flags &
2357 [ # # ]: 0 : (MLX5_FLOW_LAYER_INNER_L2 | MLX5_FLOW_LAYER_INNER_L3)) &&
2358 : : rss->level > 1)
2359 : 0 : return rte_flow_error_set(error, EINVAL,
2360 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2361 : : "MPLS inner RSS needs to specify inner L2/L3 items after MPLS in pattern");
2362 : : return 0;
2363 : : }
2364 : :
2365 : : /*
2366 : : * Validate the default miss action.
2367 : : *
2368 : : * @param[in] action_flags
2369 : : * Bit-fields that holds the actions detected until now.
2370 : : * @param[out] error
2371 : : * Pointer to error structure.
2372 : : *
2373 : : * @return
2374 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2375 : : */
2376 : : int
2377 : 0 : mlx5_flow_validate_action_default_miss(uint64_t action_flags,
2378 : : const struct rte_flow_attr *attr,
2379 : : struct rte_flow_error *error)
2380 : : {
2381 [ # # ]: 0 : if (action_flags & MLX5_FLOW_FATE_ACTIONS)
2382 : 0 : return rte_flow_error_set(error, EINVAL,
2383 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2384 : : "can't have 2 fate actions in"
2385 : : " same flow");
2386 [ # # ]: 0 : if (attr->egress)
2387 : 0 : return rte_flow_error_set(error, ENOTSUP,
2388 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
2389 : : "default miss action not supported "
2390 : : "for egress");
2391 [ # # ]: 0 : if (attr->group)
2392 : 0 : return rte_flow_error_set(error, ENOTSUP,
2393 : : RTE_FLOW_ERROR_TYPE_ATTR_GROUP, NULL,
2394 : : "only group 0 is supported");
2395 [ # # ]: 0 : if (attr->transfer)
2396 : 0 : return rte_flow_error_set(error, ENOTSUP,
2397 : : RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
2398 : : NULL, "transfer is not supported");
2399 : : return 0;
2400 : : }
2401 : :
2402 : : /*
2403 : : * Validate the count action.
2404 : : *
2405 : : * @param[in] dev
2406 : : * Pointer to the Ethernet device structure.
2407 : : * @param[in] attr
2408 : : * Attributes of flow that includes this action.
2409 : : * @param[out] error
2410 : : * Pointer to error structure.
2411 : : *
2412 : : * @return
2413 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2414 : : */
2415 : : int
2416 : 0 : mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,
2417 : : const struct rte_flow_attr *attr,
2418 : : struct rte_flow_error *error)
2419 : : {
2420 [ # # ]: 0 : if (attr->egress)
2421 : 0 : return rte_flow_error_set(error, ENOTSUP,
2422 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
2423 : : "count action not supported for "
2424 : : "egress");
2425 : : return 0;
2426 : : }
2427 : :
2428 : : /*
2429 : : * Validate the ASO CT action.
2430 : : *
2431 : : * @param[in] dev
2432 : : * Pointer to the Ethernet device structure.
2433 : : * @param[in] conntrack
2434 : : * Pointer to the CT action profile.
2435 : : * @param[out] error
2436 : : * Pointer to error structure.
2437 : : *
2438 : : * @return
2439 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2440 : : */
2441 : : int
2442 : 0 : mlx5_validate_action_ct(struct rte_eth_dev *dev,
2443 : : const struct rte_flow_action_conntrack *conntrack,
2444 : : struct rte_flow_error *error)
2445 : : {
2446 : : RTE_SET_USED(dev);
2447 : :
2448 [ # # ]: 0 : if (conntrack->state > RTE_FLOW_CONNTRACK_STATE_TIME_WAIT)
2449 : 0 : return rte_flow_error_set(error, EINVAL,
2450 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2451 : : "Invalid CT state");
2452 [ # # ]: 0 : if (conntrack->last_index > RTE_FLOW_CONNTRACK_FLAG_RST)
2453 : 0 : return rte_flow_error_set(error, EINVAL,
2454 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2455 : : "Invalid last TCP packet flag");
2456 : : return 0;
2457 : : }
2458 : :
2459 : : /**
2460 : : * Validate the level value for modify field action.
2461 : : *
2462 : : * @param[in] data
2463 : : * Pointer to the rte_flow_field_data structure either src or dst.
2464 : : * @param[out] error
2465 : : * Pointer to error structure.
2466 : : *
2467 : : * @return
2468 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2469 : : */
2470 : : int
2471 : 0 : mlx5_flow_validate_modify_field_level(const struct rte_flow_field_data *data,
2472 : : struct rte_flow_error *error)
2473 : : {
2474 [ # # # # ]: 0 : if (data->level == 0 || data->field == RTE_FLOW_FIELD_FLEX_ITEM)
2475 : : return 0;
2476 [ # # ]: 0 : if (data->field != RTE_FLOW_FIELD_TAG &&
2477 : : data->field != (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG) {
2478 [ # # ]: 0 : if (data->level > 1)
2479 : 0 : return rte_flow_error_set(error, ENOTSUP,
2480 : : RTE_FLOW_ERROR_TYPE_ACTION,
2481 : : NULL,
2482 : : "inner header fields modification is not supported");
2483 : : return 0;
2484 : : }
2485 [ # # ]: 0 : if (data->tag_index != 0)
2486 : 0 : return rte_flow_error_set(error, EINVAL,
2487 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2488 : : "tag array can be provided using 'level' or 'tag_index' fields, not both");
2489 : : /*
2490 : : * The tag array for RTE_FLOW_FIELD_TAG type is provided using
2491 : : * 'tag_index' field. In old API, it was provided using 'level' field
2492 : : * and it is still supported for backwards compatibility.
2493 : : */
2494 : 0 : DRV_LOG(DEBUG, "tag array provided in 'level' field instead of 'tag_index' field.");
2495 : 0 : return 0;
2496 : : }
2497 : :
2498 : : /**
2499 : : * Validate ICMP6 item.
2500 : : *
2501 : : * @param[in] item
2502 : : * Item specification.
2503 : : * @param[in] item_flags
2504 : : * Bit-fields that holds the items detected until now.
2505 : : * @param[in] ext_vlan_sup
2506 : : * Whether extended VLAN features are supported or not.
2507 : : * @param[out] error
2508 : : * Pointer to error structure.
2509 : : *
2510 : : * @return
2511 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2512 : : */
2513 : : int
2514 : 0 : mlx5_flow_validate_item_icmp6(const struct rte_eth_dev *dev,
2515 : : const struct rte_flow_item *item,
2516 : : uint64_t item_flags,
2517 : : uint8_t target_protocol,
2518 : : struct rte_flow_error *error)
2519 : : {
2520 : 0 : const struct rte_flow_item_icmp6 *mask = item->mask;
2521 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2522 [ # # ]: 0 : const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
2523 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6;
2524 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2525 : : MLX5_FLOW_LAYER_OUTER_L4;
2526 : : int ret;
2527 : :
2528 [ # # ]: 0 : if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMPV6)
2529 : 0 : return rte_flow_error_set(error, EINVAL,
2530 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2531 : : "protocol filtering not compatible"
2532 : : " with ICMP6 layer");
2533 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
2534 [ # # ]: 0 : if (!(item_flags & l3m))
2535 : 0 : return rte_flow_error_set(error, EINVAL,
2536 : : RTE_FLOW_ERROR_TYPE_ITEM,
2537 : : item, "IPv6 is mandatory to filter on ICMP6");
2538 : : }
2539 [ # # ]: 0 : if (item_flags & l4m)
2540 : 0 : return rte_flow_error_set(error, EINVAL,
2541 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2542 : : "multiple L4 layers not supported");
2543 [ # # ]: 0 : if (!mask)
2544 : : mask = &rte_flow_item_icmp6_mask;
2545 : 0 : ret = mlx5_flow_item_acceptable
2546 : : (dev, item, (const uint8_t *)mask,
2547 : : (const uint8_t *)&rte_flow_item_icmp6_mask,
2548 : : sizeof(struct rte_flow_item_icmp6),
2549 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2550 : : if (ret < 0)
2551 : : return ret;
2552 : : return 0;
2553 : : }
2554 : :
2555 : : /**
2556 : : * Validate ICMP6 echo request/reply item.
2557 : : *
2558 : : * @param[in] item
2559 : : * Item specification.
2560 : : * @param[in] item_flags
2561 : : * Bit-fields that holds the items detected until now.
2562 : : * @param[in] ext_vlan_sup
2563 : : * Whether extended VLAN features are supported or not.
2564 : : * @param[out] error
2565 : : * Pointer to error structure.
2566 : : *
2567 : : * @return
2568 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2569 : : */
2570 : : int
2571 : 0 : mlx5_flow_validate_item_icmp6_echo(const struct rte_eth_dev *dev,
2572 : : const struct rte_flow_item *item,
2573 : : uint64_t item_flags,
2574 : : uint8_t target_protocol,
2575 : : struct rte_flow_error *error)
2576 : : {
2577 : 0 : const struct rte_flow_item_icmp6_echo *mask = item->mask;
2578 : 0 : const struct rte_flow_item_icmp6_echo nic_mask = {
2579 : : .hdr.base.type = 0xff,
2580 : : .hdr.base.code = 0xff,
2581 : : .hdr.identifier = RTE_BE16(0xffff),
2582 : : .hdr.sequence = RTE_BE16(0xffff),
2583 : : };
2584 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2585 [ # # ]: 0 : const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
2586 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6;
2587 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2588 : : MLX5_FLOW_LAYER_OUTER_L4;
2589 : : int ret;
2590 : :
2591 [ # # ]: 0 : if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMPV6)
2592 : 0 : return rte_flow_error_set(error, EINVAL,
2593 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2594 : : "protocol filtering not compatible"
2595 : : " with ICMP6 layer");
2596 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
2597 [ # # ]: 0 : if (!(item_flags & l3m))
2598 : 0 : return rte_flow_error_set(error, EINVAL,
2599 : : RTE_FLOW_ERROR_TYPE_ITEM,
2600 : : item, "IPv6 is mandatory to filter on ICMP6");
2601 : : }
2602 [ # # ]: 0 : if (item_flags & l4m)
2603 : 0 : return rte_flow_error_set(error, EINVAL,
2604 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2605 : : "multiple L4 layers not supported");
2606 [ # # ]: 0 : if (!mask)
2607 : : mask = &nic_mask;
2608 : 0 : ret = mlx5_flow_item_acceptable
2609 : : (dev, item, (const uint8_t *)mask,
2610 : : (const uint8_t *)&nic_mask,
2611 : : sizeof(struct rte_flow_item_icmp6_echo),
2612 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2613 : : if (ret < 0)
2614 : : return ret;
2615 : : return 0;
2616 : : }
2617 : :
2618 : : /**
2619 : : * Validate ICMP item.
2620 : : *
2621 : : * @param[in] item
2622 : : * Item specification.
2623 : : * @param[in] item_flags
2624 : : * Bit-fields that holds the items detected until now.
2625 : : * @param[out] error
2626 : : * Pointer to error structure.
2627 : : *
2628 : : * @return
2629 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2630 : : */
2631 : : int
2632 : 0 : mlx5_flow_validate_item_icmp(const struct rte_eth_dev *dev,
2633 : : const struct rte_flow_item *item,
2634 : : uint64_t item_flags,
2635 : : uint8_t target_protocol,
2636 : : struct rte_flow_error *error)
2637 : : {
2638 : 0 : const struct rte_flow_item_icmp *mask = item->mask;
2639 : 0 : const struct rte_flow_item_icmp nic_mask = {
2640 : : .hdr.icmp_type = 0xff,
2641 : : .hdr.icmp_code = 0xff,
2642 : : .hdr.icmp_ident = RTE_BE16(0xffff),
2643 : : .hdr.icmp_seq_nb = RTE_BE16(0xffff),
2644 : : };
2645 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2646 [ # # ]: 0 : const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
2647 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4;
2648 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2649 : : MLX5_FLOW_LAYER_OUTER_L4;
2650 : : int ret;
2651 : :
2652 [ # # ]: 0 : if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMP)
2653 : 0 : return rte_flow_error_set(error, EINVAL,
2654 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2655 : : "protocol filtering not compatible"
2656 : : " with ICMP layer");
2657 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
2658 [ # # ]: 0 : if (!(item_flags & l3m))
2659 : 0 : return rte_flow_error_set(error, EINVAL,
2660 : : RTE_FLOW_ERROR_TYPE_ITEM,
2661 : : item, "IPv4 is mandatory to filter on ICMP");
2662 : : }
2663 [ # # ]: 0 : if (item_flags & l4m)
2664 : 0 : return rte_flow_error_set(error, EINVAL,
2665 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2666 : : "multiple L4 layers not supported");
2667 [ # # ]: 0 : if (!mask)
2668 : : mask = &nic_mask;
2669 : 0 : ret = mlx5_flow_item_acceptable
2670 : : (dev, item, (const uint8_t *)mask,
2671 : : (const uint8_t *)&nic_mask,
2672 : : sizeof(struct rte_flow_item_icmp),
2673 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2674 : : if (ret < 0)
2675 : : return ret;
2676 : : return 0;
2677 : : }
2678 : :
2679 : : /**
2680 : : * Validate Ethernet item.
2681 : : *
2682 : : * @param[in] item
2683 : : * Item specification.
2684 : : * @param[in] item_flags
2685 : : * Bit-fields that holds the items detected until now.
2686 : : * @param[out] error
2687 : : * Pointer to error structure.
2688 : : *
2689 : : * @return
2690 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2691 : : */
2692 : : int
2693 : 0 : mlx5_flow_validate_item_eth(const struct rte_eth_dev *dev,
2694 : : const struct rte_flow_item *item,
2695 : : uint64_t item_flags, bool ext_vlan_sup,
2696 : : struct rte_flow_error *error)
2697 : : {
2698 : 0 : const struct rte_flow_item_eth *mask = item->mask;
2699 : 0 : const struct rte_flow_item_eth nic_mask = {
2700 : : .hdr.dst_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
2701 : : .hdr.src_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
2702 : : .hdr.ether_type = RTE_BE16(0xffff),
2703 : : .has_vlan = ext_vlan_sup ? 1 : 0,
2704 : : };
2705 : : int ret;
2706 : 0 : int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2707 [ # # ]: 0 : const uint64_t ethm = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
2708 : : MLX5_FLOW_LAYER_OUTER_L2;
2709 : :
2710 [ # # ]: 0 : if (item_flags & ethm)
2711 : 0 : return rte_flow_error_set(error, ENOTSUP,
2712 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2713 : : "multiple L2 layers not supported");
2714 [ # # # # : 0 : if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_L3)) ||
# # ]
2715 [ # # ]: 0 : (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_L3)))
2716 : 0 : return rte_flow_error_set(error, EINVAL,
2717 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2718 : : "L2 layer should not follow "
2719 : : "L3 layers");
2720 [ # # # # : 0 : if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_VLAN)) ||
# # ]
2721 [ # # ]: 0 : (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_VLAN)))
2722 : 0 : return rte_flow_error_set(error, EINVAL,
2723 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2724 : : "L2 layer should not follow VLAN");
2725 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_GTP)
2726 : 0 : return rte_flow_error_set(error, EINVAL,
2727 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2728 : : "L2 layer should not follow GTP");
2729 [ # # ]: 0 : if (!mask)
2730 : : mask = &rte_flow_item_eth_mask;
2731 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2732 : : (const uint8_t *)&nic_mask,
2733 : : sizeof(struct rte_flow_item_eth),
2734 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2735 : 0 : return ret;
2736 : : }
2737 : :
2738 : : /**
2739 : : * Validate VLAN item.
2740 : : *
2741 : : * @param[in] item
2742 : : * Item specification.
2743 : : * @param[in] item_flags
2744 : : * Bit-fields that holds the items detected until now.
2745 : : * @param[in] dev
2746 : : * Ethernet device flow is being created on.
2747 : : * @param[out] error
2748 : : * Pointer to error structure.
2749 : : *
2750 : : * @return
2751 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2752 : : */
2753 : : int
2754 : 0 : mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
2755 : : uint64_t item_flags,
2756 : : struct rte_eth_dev *dev,
2757 : : struct rte_flow_error *error)
2758 : : {
2759 : 0 : const struct rte_flow_item_vlan *spec = item->spec;
2760 : 0 : const struct rte_flow_item_vlan *mask = item->mask;
2761 : 0 : const struct rte_flow_item_vlan nic_mask = {
2762 : : .hdr.vlan_tci = RTE_BE16(UINT16_MAX),
2763 : : .hdr.eth_proto = RTE_BE16(UINT16_MAX),
2764 : : };
2765 : : uint16_t vlan_tag = 0;
2766 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2767 : : int ret;
2768 : : const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
2769 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L4) :
2770 : : (MLX5_FLOW_LAYER_OUTER_L3 |
2771 : : MLX5_FLOW_LAYER_OUTER_L4);
2772 [ # # ]: 0 : const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
2773 : : MLX5_FLOW_LAYER_OUTER_VLAN;
2774 : :
2775 [ # # ]: 0 : if (item_flags & vlanm)
2776 : 0 : return rte_flow_error_set(error, EINVAL,
2777 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2778 : : "multiple VLAN layers not supported");
2779 [ # # ]: 0 : else if ((item_flags & l34m) != 0)
2780 : 0 : return rte_flow_error_set(error, EINVAL,
2781 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2782 : : "VLAN cannot follow L3/L4 layer");
2783 [ # # ]: 0 : if (!mask)
2784 : : mask = &rte_flow_item_vlan_mask;
2785 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2786 : : (const uint8_t *)&nic_mask,
2787 : : sizeof(struct rte_flow_item_vlan),
2788 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2789 [ # # ]: 0 : if (ret)
2790 : : return ret;
2791 [ # # # # ]: 0 : if (!tunnel && mask->hdr.vlan_tci != RTE_BE16(0x0fff)) {
2792 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2793 : :
2794 [ # # ]: 0 : if (priv->vmwa_context) {
2795 : : /*
2796 : : * Non-NULL context means we have a virtual machine
2797 : : * and SR-IOV enabled, we have to create VLAN interface
2798 : : * to make hypervisor to setup E-Switch vport
2799 : : * context correctly. We avoid creating the multiple
2800 : : * VLAN interfaces, so we cannot support VLAN tag mask.
2801 : : */
2802 : 0 : return rte_flow_error_set(error, EINVAL,
2803 : : RTE_FLOW_ERROR_TYPE_ITEM,
2804 : : item,
2805 : : "VLAN tag mask is not"
2806 : : " supported in virtual"
2807 : : " environment");
2808 : : }
2809 : : }
2810 [ # # ]: 0 : if (spec) {
2811 : 0 : vlan_tag = spec->hdr.vlan_tci;
2812 : 0 : vlan_tag &= mask->hdr.vlan_tci;
2813 : : }
2814 : : /*
2815 : : * From verbs perspective an empty VLAN is equivalent
2816 : : * to a packet without VLAN layer.
2817 : : */
2818 [ # # ]: 0 : if (!vlan_tag)
2819 : 0 : return rte_flow_error_set(error, EINVAL,
2820 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2821 : 0 : item->spec,
2822 : : "VLAN cannot be empty");
2823 : : return 0;
2824 : : }
2825 : :
2826 : : /**
2827 : : * Validate IPV4 item.
2828 : : *
2829 : : * @param[in] item
2830 : : * Item specification.
2831 : : * @param[in] item_flags
2832 : : * Bit-fields that holds the items detected until now.
2833 : : * @param[in] last_item
2834 : : * Previous validated item in the pattern items.
2835 : : * @param[in] ether_type
2836 : : * Type in the ethernet layer header (including dot1q).
2837 : : * @param[in] acc_mask
2838 : : * Acceptable mask, if NULL default internal default mask
2839 : : * will be used to check whether item fields are supported.
2840 : : * @param[in] range_accepted
2841 : : * True if range of values is accepted for specific fields, false otherwise.
2842 : : * @param[out] error
2843 : : * Pointer to error structure.
2844 : : *
2845 : : * @return
2846 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2847 : : */
2848 : : int
2849 : 0 : mlx5_flow_validate_item_ipv4(const struct rte_eth_dev *dev,
2850 : : const struct rte_flow_item *item,
2851 : : uint64_t item_flags,
2852 : : uint64_t last_item,
2853 : : uint16_t ether_type,
2854 : : const struct rte_flow_item_ipv4 *acc_mask,
2855 : : bool range_accepted,
2856 : : struct rte_flow_error *error)
2857 : : {
2858 : 0 : const struct rte_flow_item_ipv4 *mask = item->mask;
2859 : 0 : const struct rte_flow_item_ipv4 *spec = item->spec;
2860 : 0 : const struct rte_flow_item_ipv4 nic_mask = {
2861 : : .hdr = {
2862 : : .src_addr = RTE_BE32(0xffffffff),
2863 : : .dst_addr = RTE_BE32(0xffffffff),
2864 : : .type_of_service = 0xff,
2865 : : .next_proto_id = 0xff,
2866 : : },
2867 : : };
2868 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2869 [ # # ]: 0 : const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2870 : : MLX5_FLOW_LAYER_OUTER_L3;
2871 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2872 : : MLX5_FLOW_LAYER_OUTER_L4;
2873 : : int ret;
2874 : : uint8_t next_proto = 0xFF;
2875 : : const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2876 : : MLX5_FLOW_LAYER_OUTER_VLAN |
2877 : : MLX5_FLOW_LAYER_INNER_VLAN);
2878 : :
2879 [ # # ]: 0 : if ((last_item & l2_vlan) && ether_type &&
2880 [ # # ]: 0 : ether_type != RTE_ETHER_TYPE_IPV4)
2881 : 0 : return rte_flow_error_set(error, EINVAL,
2882 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2883 : : "IPv4 cannot follow L2/VLAN layer "
2884 : : "which ether type is not IPv4");
2885 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_IPIP) {
2886 [ # # ]: 0 : if (mask && spec)
2887 : 0 : next_proto = mask->hdr.next_proto_id &
2888 : 0 : spec->hdr.next_proto_id;
2889 [ # # ]: 0 : if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2890 : 0 : return rte_flow_error_set(error, EINVAL,
2891 : : RTE_FLOW_ERROR_TYPE_ITEM,
2892 : : item,
2893 : : "multiple tunnel "
2894 : : "not supported");
2895 : : }
2896 [ # # ]: 0 : if (item_flags & l3m)
2897 : 0 : return rte_flow_error_set(error, ENOTSUP,
2898 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2899 : : "multiple L3 layers not supported");
2900 [ # # ]: 0 : else if (item_flags & l4m)
2901 : 0 : return rte_flow_error_set(error, EINVAL,
2902 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2903 : : "L3 cannot follow an L4 layer.");
2904 [ # # ]: 0 : else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
2905 : : !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
2906 : 0 : return rte_flow_error_set(error, EINVAL,
2907 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2908 : : "L3 cannot follow an NVGRE layer.");
2909 [ # # ]: 0 : if (!mask)
2910 : : mask = &rte_flow_item_ipv4_mask;
2911 [ # # ]: 0 : else if (mask->hdr.next_proto_id != 0 &&
2912 : : mask->hdr.next_proto_id != 0xff)
2913 : 0 : return rte_flow_error_set(error, EINVAL,
2914 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2915 : : "partial mask is not supported"
2916 : : " for protocol");
2917 [ # # ]: 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2918 : : acc_mask ? (const uint8_t *)acc_mask
2919 : : : (const uint8_t *)&nic_mask,
2920 : : sizeof(struct rte_flow_item_ipv4),
2921 : : range_accepted, error);
2922 : : if (ret < 0)
2923 : : return ret;
2924 : : return 0;
2925 : : }
2926 : :
2927 : : /**
2928 : : * Validate IPV6 item.
2929 : : *
2930 : : * @param[in] item
2931 : : * Item specification.
2932 : : * @param[in] item_flags
2933 : : * Bit-fields that holds the items detected until now.
2934 : : * @param[in] last_item
2935 : : * Previous validated item in the pattern items.
2936 : : * @param[in] ether_type
2937 : : * Type in the ethernet layer header (including dot1q).
2938 : : * @param[in] acc_mask
2939 : : * Acceptable mask, if NULL default internal default mask
2940 : : * will be used to check whether item fields are supported.
2941 : : * @param[out] error
2942 : : * Pointer to error structure.
2943 : : *
2944 : : * @return
2945 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2946 : : */
2947 : : int
2948 : 0 : mlx5_flow_validate_item_ipv6(const struct rte_eth_dev *dev,
2949 : : const struct rte_flow_item *item,
2950 : : uint64_t item_flags,
2951 : : uint64_t last_item,
2952 : : uint16_t ether_type,
2953 : : const struct rte_flow_item_ipv6 *acc_mask,
2954 : : struct rte_flow_error *error)
2955 : : {
2956 : 0 : const struct rte_flow_item_ipv6 *mask = item->mask;
2957 : 0 : const struct rte_flow_item_ipv6 *spec = item->spec;
2958 : 0 : const struct rte_flow_item_ipv6 nic_mask = {
2959 : : .hdr = {
2960 : : .src_addr = RTE_IPV6_MASK_FULL,
2961 : : .dst_addr = RTE_IPV6_MASK_FULL,
2962 : : .vtc_flow = RTE_BE32(0xffffffff),
2963 : : .proto = 0xff,
2964 : : },
2965 : : };
2966 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2967 [ # # ]: 0 : const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
2968 : : MLX5_FLOW_LAYER_OUTER_L3;
2969 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
2970 : : MLX5_FLOW_LAYER_OUTER_L4;
2971 : : int ret;
2972 : : uint8_t next_proto = 0xFF;
2973 : : const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
2974 : : MLX5_FLOW_LAYER_OUTER_VLAN |
2975 : : MLX5_FLOW_LAYER_INNER_VLAN);
2976 : :
2977 [ # # ]: 0 : if ((last_item & l2_vlan) && ether_type &&
2978 [ # # ]: 0 : ether_type != RTE_ETHER_TYPE_IPV6)
2979 : 0 : return rte_flow_error_set(error, EINVAL,
2980 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2981 : : "IPv6 cannot follow L2/VLAN layer "
2982 : : "which ether type is not IPv6");
2983 [ # # # # : 0 : if (mask && mask->hdr.proto == UINT8_MAX && spec)
# # ]
2984 : 0 : next_proto = spec->hdr.proto;
2985 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_IPIP) {
2986 [ # # ]: 0 : if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
2987 : 0 : return rte_flow_error_set(error, EINVAL,
2988 : : RTE_FLOW_ERROR_TYPE_ITEM,
2989 : : item,
2990 : : "multiple tunnel "
2991 : : "not supported");
2992 : : }
2993 : 0 : if (next_proto == IPPROTO_HOPOPTS ||
2994 [ # # ]: 0 : next_proto == IPPROTO_ROUTING ||
2995 : : next_proto == IPPROTO_FRAGMENT ||
2996 : : next_proto == IPPROTO_AH ||
2997 [ # # ]: 0 : next_proto == IPPROTO_DSTOPTS ||
2998 [ # # ]: 0 : (!mlx5_hws_active(dev) && next_proto == IPPROTO_ESP))
2999 : 0 : return rte_flow_error_set(error, EINVAL,
3000 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3001 : : "IPv6 proto (next header) should "
3002 : : "not be set as extension header");
3003 [ # # ]: 0 : if (item_flags & l3m)
3004 : 0 : return rte_flow_error_set(error, ENOTSUP,
3005 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3006 : : "multiple L3 layers not supported");
3007 [ # # ]: 0 : else if (item_flags & l4m)
3008 : 0 : return rte_flow_error_set(error, EINVAL,
3009 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3010 : : "L3 cannot follow an L4 layer.");
3011 [ # # ]: 0 : else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
3012 : : !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
3013 : 0 : return rte_flow_error_set(error, EINVAL,
3014 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3015 : : "L3 cannot follow an NVGRE layer.");
3016 [ # # ]: 0 : if (!mask)
3017 : : mask = &rte_flow_item_ipv6_mask;
3018 [ # # ]: 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
3019 : : acc_mask ? (const uint8_t *)acc_mask
3020 : : : (const uint8_t *)&nic_mask,
3021 : : sizeof(struct rte_flow_item_ipv6),
3022 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3023 : : if (ret < 0)
3024 : : return ret;
3025 : : return 0;
3026 : : }
3027 : :
3028 : : /**
3029 : : * Validate UDP item.
3030 : : *
3031 : : * @param[in] item
3032 : : * Item specification.
3033 : : * @param[in] item_flags
3034 : : * Bit-fields that holds the items detected until now.
3035 : : * @param[in] target_protocol
3036 : : * The next protocol in the previous item.
3037 : : * @param[in] flow_mask
3038 : : * mlx5 flow-specific (DV, verbs, etc.) supported header fields mask.
3039 : : * @param[out] error
3040 : : * Pointer to error structure.
3041 : : *
3042 : : * @return
3043 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3044 : : */
3045 : : int
3046 : 0 : mlx5_flow_validate_item_udp(const struct rte_eth_dev *dev,
3047 : : const struct rte_flow_item *item,
3048 : : uint64_t item_flags,
3049 : : uint8_t target_protocol,
3050 : : struct rte_flow_error *error)
3051 : : {
3052 : 0 : const struct rte_flow_item_udp *mask = item->mask;
3053 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
3054 [ # # ]: 0 : const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
3055 : : MLX5_FLOW_LAYER_OUTER_L3;
3056 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
3057 : : MLX5_FLOW_LAYER_OUTER_L4;
3058 : : int ret;
3059 : :
3060 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
3061 [ # # ]: 0 : if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
3062 : 0 : return rte_flow_error_set(error, EINVAL,
3063 : : RTE_FLOW_ERROR_TYPE_ITEM,
3064 : : item, "protocol filtering not compatible with UDP layer");
3065 [ # # ]: 0 : if (!(item_flags & l3m))
3066 : 0 : return rte_flow_error_set(error, EINVAL,
3067 : : RTE_FLOW_ERROR_TYPE_ITEM,
3068 : : item,
3069 : : "L3 is mandatory to filter on L4");
3070 : : }
3071 [ # # ]: 0 : if (item_flags & l4m)
3072 : 0 : return rte_flow_error_set(error, EINVAL,
3073 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3074 : : "multiple L4 layers not supported");
3075 [ # # ]: 0 : if (!mask)
3076 : : mask = &rte_flow_item_udp_mask;
3077 : 0 : ret = mlx5_flow_item_acceptable
3078 : : (dev, item, (const uint8_t *)mask,
3079 : : (const uint8_t *)&rte_flow_item_udp_mask,
3080 : : sizeof(struct rte_flow_item_udp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
3081 : : error);
3082 : : if (ret < 0)
3083 : : return ret;
3084 : : return 0;
3085 : : }
3086 : :
3087 : : /**
3088 : : * Validate TCP item.
3089 : : *
3090 : : * @param[in] item
3091 : : * Item specification.
3092 : : * @param[in] item_flags
3093 : : * Bit-fields that holds the items detected until now.
3094 : : * @param[in] target_protocol
3095 : : * The next protocol in the previous item.
3096 : : * @param[out] error
3097 : : * Pointer to error structure.
3098 : : *
3099 : : * @return
3100 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3101 : : */
3102 : : int
3103 : 0 : mlx5_flow_validate_item_tcp(const struct rte_eth_dev *dev,
3104 : : const struct rte_flow_item *item,
3105 : : uint64_t item_flags,
3106 : : uint8_t target_protocol,
3107 : : const struct rte_flow_item_tcp *flow_mask,
3108 : : struct rte_flow_error *error)
3109 : : {
3110 : 0 : const struct rte_flow_item_tcp *mask = item->mask;
3111 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
3112 [ # # ]: 0 : const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
3113 : : MLX5_FLOW_LAYER_OUTER_L3;
3114 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
3115 : : MLX5_FLOW_LAYER_OUTER_L4;
3116 : : int ret;
3117 : :
3118 : : MLX5_ASSERT(flow_mask);
3119 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
3120 [ # # ]: 0 : if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
3121 : 0 : return rte_flow_error_set(error, EINVAL,
3122 : : RTE_FLOW_ERROR_TYPE_ITEM,
3123 : : item, "protocol filtering not compatible with TCP layer");
3124 [ # # ]: 0 : if (!(item_flags & l3m))
3125 : 0 : return rte_flow_error_set(error, EINVAL,
3126 : : RTE_FLOW_ERROR_TYPE_ITEM,
3127 : : item, "L3 is mandatory to filter on L4");
3128 : : }
3129 [ # # ]: 0 : if (item_flags & l4m)
3130 : 0 : return rte_flow_error_set(error, EINVAL,
3131 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3132 : : "multiple L4 layers not supported");
3133 [ # # ]: 0 : if (!mask)
3134 : : mask = &rte_flow_item_tcp_mask;
3135 : 0 : ret = mlx5_flow_item_acceptable
3136 : : (dev, item, (const uint8_t *)mask,
3137 : : (const uint8_t *)flow_mask,
3138 : : sizeof(struct rte_flow_item_tcp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
3139 : : error);
3140 : : if (ret < 0)
3141 : : return ret;
3142 : : return 0;
3143 : : }
3144 : :
3145 : : /**
3146 : : * Validate VXLAN item.
3147 : : *
3148 : : * @param[in] dev
3149 : : * Pointer to the Ethernet device structure.
3150 : : * @param[in] udp_dport
3151 : : * UDP destination port
3152 : : * @param[in] item
3153 : : * Item specification.
3154 : : * @param[in] item_flags
3155 : : * Bit-fields that holds the items detected until now.
3156 : : * @param root
3157 : : * Whether action is on root table.
3158 : : * @param[out] error
3159 : : * Pointer to error structure.
3160 : : *
3161 : : * @return
3162 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3163 : : */
3164 : : int
3165 : 0 : mlx5_flow_validate_item_vxlan(struct rte_eth_dev *dev,
3166 : : uint16_t udp_dport,
3167 : : const struct rte_flow_item *item,
3168 : : uint64_t item_flags,
3169 : : bool root,
3170 : : struct rte_flow_error *error)
3171 : : {
3172 : 0 : const struct rte_flow_item_vxlan *spec = item->spec;
3173 : 0 : const struct rte_flow_item_vxlan *mask = item->mask;
3174 : : int ret;
3175 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3176 : : union vni {
3177 : : uint32_t vlan_id;
3178 : : uint8_t vni[4];
3179 : 0 : } id = { .vlan_id = 0, };
3180 : 0 : const struct rte_flow_item_vxlan nic_mask = {
3181 : : .hdr.vni = { 0xff, 0xff, 0xff },
3182 : : .hdr.rsvd1 = 0xff,
3183 : : };
3184 : : const struct rte_flow_item_vxlan *valid_mask;
3185 : :
3186 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3187 : 0 : return rte_flow_error_set(error, ENOTSUP,
3188 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3189 : : "multiple tunnel layers not"
3190 : : " supported");
3191 : : /* HWS can match entire VXLAN, VXLAN-GBP and VXLAN-GPE headers */
3192 [ # # ]: 0 : if (mlx5_hws_active(dev))
3193 : : return 0;
3194 : : valid_mask = &rte_flow_item_vxlan_mask;
3195 : : /*
3196 : : * Verify only UDPv4 is present as defined in
3197 : : * https://tools.ietf.org/html/rfc7348
3198 : : */
3199 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
3200 : 0 : return rte_flow_error_set(error, EINVAL,
3201 : : RTE_FLOW_ERROR_TYPE_ITEM,
3202 : : item, "no outer UDP layer found");
3203 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
3204 : 0 : return rte_flow_error_set(error, ENOTSUP,
3205 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3206 : : "VXLAN tunnel must be fully defined");
3207 [ # # ]: 0 : if (!mask)
3208 : : mask = &rte_flow_item_vxlan_mask;
3209 : :
3210 [ # # ]: 0 : if (priv->sh->steering_format_version !=
3211 : : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5 ||
3212 [ # # ]: 0 : !udp_dport || udp_dport == MLX5_UDP_PORT_VXLAN) {
3213 : : /* non-root table */
3214 [ # # # # ]: 0 : if (!root && priv->sh->misc5_cap)
3215 : : valid_mask = &nic_mask;
3216 : : /* Group zero in NIC domain */
3217 [ # # # # ]: 0 : if (!root && priv->sh->tunnel_header_0_1)
3218 : : valid_mask = &nic_mask;
3219 : : }
3220 : 0 : ret = mlx5_flow_item_acceptable
3221 : : (dev, item, (const uint8_t *)mask,
3222 : : (const uint8_t *)valid_mask,
3223 : : sizeof(struct rte_flow_item_vxlan),
3224 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3225 : : if (ret < 0)
3226 : : return ret;
3227 : : if (spec) {
3228 : : memcpy(&id.vni[1], spec->hdr.vni, 3);
3229 : : memcpy(&id.vni[1], mask->hdr.vni, 3);
3230 : : }
3231 : : return 0;
3232 : : }
3233 : :
3234 : : /**
3235 : : * Validate VXLAN_GPE item.
3236 : : *
3237 : : * @param[in] item
3238 : : * Item specification.
3239 : : * @param[in] item_flags
3240 : : * Bit-fields that holds the items detected until now.
3241 : : * @param[in] priv
3242 : : * Pointer to the private data structure.
3243 : : * @param[in] target_protocol
3244 : : * The next protocol in the previous item.
3245 : : * @param[out] error
3246 : : * Pointer to error structure.
3247 : : *
3248 : : * @return
3249 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3250 : : */
3251 : : int
3252 : 0 : mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
3253 : : uint64_t item_flags,
3254 : : struct rte_eth_dev *dev,
3255 : : struct rte_flow_error *error)
3256 : : {
3257 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3258 : : const struct rte_flow_item_vxlan_gpe *spec = item->spec;
3259 : 0 : const struct rte_flow_item_vxlan_gpe *mask = item->mask;
3260 : : int ret;
3261 : : union vni {
3262 : : uint32_t vlan_id;
3263 : : uint8_t vni[4];
3264 : 0 : } id = { .vlan_id = 0, };
3265 : :
3266 : 0 : struct rte_flow_item_vxlan_gpe nic_mask = {
3267 : : .vni = { 0xff, 0xff, 0xff },
3268 : : .protocol = 0xff,
3269 : : .flags = 0xff,
3270 : : };
3271 : :
3272 [ # # ]: 0 : if (!priv->sh->config.l3_vxlan_en)
3273 : 0 : return rte_flow_error_set(error, ENOTSUP,
3274 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3275 : : "L3 VXLAN is not enabled by device"
3276 : : " parameter and/or not configured in"
3277 : : " firmware");
3278 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3279 : 0 : return rte_flow_error_set(error, ENOTSUP,
3280 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3281 : : "multiple tunnel layers not"
3282 : : " supported");
3283 : : /*
3284 : : * Verify only UDPv4 is present as defined in
3285 : : * https://tools.ietf.org/html/rfc7348
3286 : : */
3287 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
3288 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
3289 : 0 : return rte_flow_error_set(error, EINVAL,
3290 : : RTE_FLOW_ERROR_TYPE_ITEM,
3291 : : item, "no outer UDP layer found");
3292 : : }
3293 [ # # ]: 0 : if (!mask)
3294 : : mask = &rte_flow_item_vxlan_gpe_mask;
3295 [ # # ]: 0 : if (mlx5_hws_active(dev) ||
3296 [ # # ]: 0 : (priv->sh->misc5_cap && priv->sh->tunnel_header_0_1)) {
3297 : 0 : nic_mask.rsvd0[0] = 0xff;
3298 : 0 : nic_mask.rsvd0[1] = 0xff;
3299 : 0 : nic_mask.rsvd1 = 0xff;
3300 : : }
3301 : 0 : ret = mlx5_flow_item_acceptable
3302 : : (dev, item, (const uint8_t *)mask,
3303 : : (const uint8_t *)&nic_mask,
3304 : : sizeof(struct rte_flow_item_vxlan_gpe),
3305 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3306 [ # # ]: 0 : if (ret < 0)
3307 : : return ret;
3308 : : if (spec) {
3309 : : memcpy(&id.vni[1], spec->hdr.vni, 3);
3310 : : memcpy(&id.vni[1], mask->hdr.vni, 3);
3311 : : }
3312 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
3313 : 0 : return rte_flow_error_set(error, ENOTSUP,
3314 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3315 : : "VXLAN-GPE tunnel must be fully"
3316 : : " defined");
3317 : : return 0;
3318 : : }
3319 : : /**
3320 : : * Validate GRE Key item.
3321 : : *
3322 : : * @param[in] item
3323 : : * Item specification.
3324 : : * @param[in] item_flags
3325 : : * Bit flags to mark detected items.
3326 : : * @param[in] gre_item
3327 : : * Pointer to gre_item
3328 : : * @param[out] error
3329 : : * Pointer to error structure.
3330 : : *
3331 : : * @return
3332 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3333 : : */
3334 : : int
3335 : 0 : mlx5_flow_validate_item_gre_key(const struct rte_eth_dev *dev,
3336 : : const struct rte_flow_item *item,
3337 : : uint64_t item_flags,
3338 : : const struct rte_flow_item *gre_item,
3339 : : struct rte_flow_error *error)
3340 : : {
3341 : 0 : const rte_be32_t *mask = item->mask;
3342 : : int ret = 0;
3343 : 0 : rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
3344 : : const struct rte_flow_item_gre *gre_spec;
3345 : : const struct rte_flow_item_gre *gre_mask;
3346 : :
3347 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_GRE_KEY)
3348 : 0 : return rte_flow_error_set(error, ENOTSUP,
3349 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3350 : : "Multiple GRE key not support");
3351 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_GRE))
3352 : 0 : return rte_flow_error_set(error, ENOTSUP,
3353 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3354 : : "No preceding GRE header");
3355 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_INNER)
3356 : 0 : return rte_flow_error_set(error, ENOTSUP,
3357 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3358 : : "GRE key following a wrong item");
3359 [ # # ]: 0 : gre_mask = gre_item ? gre_item->mask : NULL;
3360 [ # # ]: 0 : if (!gre_mask)
3361 : : gre_mask = &rte_flow_item_gre_mask;
3362 [ # # ]: 0 : gre_spec = gre_item ? gre_item->spec : NULL;
3363 [ # # # # ]: 0 : if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
3364 [ # # ]: 0 : !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
3365 : 0 : return rte_flow_error_set(error, EINVAL,
3366 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3367 : : "Key bit must be on");
3368 : :
3369 [ # # ]: 0 : if (!mask)
3370 : : mask = &gre_key_default_mask;
3371 : 0 : ret = mlx5_flow_item_acceptable
3372 : : (dev, item, (const uint8_t *)mask,
3373 : : (const uint8_t *)&gre_key_default_mask,
3374 : : sizeof(rte_be32_t), MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3375 : 0 : return ret;
3376 : : }
3377 : :
3378 : : /**
3379 : : * Validate GRE optional item.
3380 : : *
3381 : : * @param[in] dev
3382 : : * Pointer to the Ethernet device structure.
3383 : : * @param[in] item
3384 : : * Item specification.
3385 : : * @param[in] item_flags
3386 : : * Bit flags to mark detected items.
3387 : : * @param[in] attr
3388 : : * Flow rule attributes.
3389 : : * @param[in] gre_item
3390 : : * Pointer to gre_item
3391 : : * @param[out] error
3392 : : * Pointer to error structure.
3393 : : *
3394 : : * @return
3395 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3396 : : */
3397 : : int
3398 : 0 : mlx5_flow_validate_item_gre_option(struct rte_eth_dev *dev,
3399 : : const struct rte_flow_item *item,
3400 : : uint64_t item_flags,
3401 : : const struct rte_flow_attr *attr,
3402 : : const struct rte_flow_item *gre_item,
3403 : : struct rte_flow_error *error)
3404 : : {
3405 [ # # ]: 0 : const struct rte_flow_item_gre *gre_spec = gre_item ? gre_item->spec : NULL;
3406 [ # # ]: 0 : const struct rte_flow_item_gre *gre_mask = gre_item ? gre_item->mask : NULL;
3407 : 0 : const struct rte_flow_item_gre_opt *spec = item->spec;
3408 : 0 : const struct rte_flow_item_gre_opt *mask = item->mask;
3409 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3410 : : int ret = 0;
3411 : 0 : struct rte_flow_item_gre_opt nic_mask = {
3412 : : .checksum_rsvd = {
3413 : : .checksum = RTE_BE16(UINT16_MAX),
3414 : : .reserved1 = 0x0,
3415 : : },
3416 : : .key = {
3417 : : .key = RTE_BE32(UINT32_MAX),
3418 : : },
3419 : : .sequence = {
3420 : : .sequence = RTE_BE32(UINT32_MAX),
3421 : : },
3422 : : };
3423 : :
3424 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_GRE))
3425 : 0 : return rte_flow_error_set(error, ENOTSUP,
3426 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3427 : : "No preceding GRE header");
3428 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_INNER)
3429 : 0 : return rte_flow_error_set(error, ENOTSUP,
3430 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3431 : : "GRE option following a wrong item");
3432 [ # # # # : 0 : if ((!spec && !mlx5_hws_active(dev)) || !mask)
# # ]
3433 : 0 : return rte_flow_error_set(error, EINVAL,
3434 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3435 : : "At least one field gre_option(checksum/key/sequence) must be specified");
3436 [ # # ]: 0 : if (!gre_mask)
3437 : : gre_mask = &rte_flow_item_gre_mask;
3438 [ # # ]: 0 : if (mask->checksum_rsvd.checksum)
3439 [ # # # # ]: 0 : if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x8000)) &&
3440 [ # # ]: 0 : !(gre_spec->c_rsvd0_ver & RTE_BE16(0x8000)))
3441 : 0 : return rte_flow_error_set(error, EINVAL,
3442 : : RTE_FLOW_ERROR_TYPE_ITEM,
3443 : : item,
3444 : : "Checksum bit must be on");
3445 [ # # ]: 0 : if (mask->key.key)
3446 [ # # # # ]: 0 : if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
3447 [ # # ]: 0 : !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
3448 : 0 : return rte_flow_error_set(error, EINVAL,
3449 : : RTE_FLOW_ERROR_TYPE_ITEM,
3450 : : item, "Key bit must be on");
3451 [ # # ]: 0 : if (mask->sequence.sequence)
3452 [ # # # # ]: 0 : if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x1000)) &&
3453 [ # # ]: 0 : !(gre_spec->c_rsvd0_ver & RTE_BE16(0x1000)))
3454 : 0 : return rte_flow_error_set(error, EINVAL,
3455 : : RTE_FLOW_ERROR_TYPE_ITEM,
3456 : : item,
3457 : : "Sequence bit must be on");
3458 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
3459 [ # # # # ]: 0 : if (mask->checksum_rsvd.checksum || mask->sequence.sequence) {
3460 [ # # ]: 0 : if (priv->sh->steering_format_version ==
3461 : 0 : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5 ||
3462 [ # # ]: 0 : ((attr->group ||
3463 [ # # # # ]: 0 : (attr->transfer && priv->fdb_def_rule)) &&
3464 [ # # ]: 0 : !priv->sh->misc5_cap) ||
3465 [ # # ]: 0 : (!(priv->sh->tunnel_header_0_1 &&
3466 [ # # ]: 0 : priv->sh->tunnel_header_2_3) &&
3467 : 0 : !attr->group &&
3468 [ # # # # ]: 0 : (!attr->transfer || !priv->fdb_def_rule)))
3469 : 0 : return rte_flow_error_set
3470 : : (error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM,
3471 : : item, "Checksum/Sequence not supported");
3472 : : }
3473 : : }
3474 : 0 : ret = mlx5_flow_item_acceptable
3475 : : (dev, item, (const uint8_t *)mask,
3476 : : (const uint8_t *)&nic_mask,
3477 : : sizeof(struct rte_flow_item_gre_opt),
3478 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3479 : 0 : return ret;
3480 : : }
3481 : :
3482 : : /**
3483 : : * Validate GRE item.
3484 : : *
3485 : : * @param[in] item
3486 : : * Item specification.
3487 : : * @param[in] item_flags
3488 : : * Bit flags to mark detected items.
3489 : : * @param[in] target_protocol
3490 : : * The next protocol in the previous item.
3491 : : * @param[out] error
3492 : : * Pointer to error structure.
3493 : : *
3494 : : * @return
3495 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3496 : : */
3497 : : int
3498 : 0 : mlx5_flow_validate_item_gre(const struct rte_eth_dev *dev,
3499 : : const struct rte_flow_item *item,
3500 : : uint64_t item_flags,
3501 : : uint8_t target_protocol,
3502 : : struct rte_flow_error *error)
3503 : : {
3504 : : const struct rte_flow_item_gre *spec __rte_unused = item->spec;
3505 : 0 : const struct rte_flow_item_gre *mask = item->mask;
3506 : : int ret;
3507 : 0 : const struct rte_flow_item_gre nic_mask = {
3508 : : .c_rsvd0_ver = RTE_BE16(0xB000),
3509 : : .protocol = RTE_BE16(UINT16_MAX),
3510 : : };
3511 : :
3512 [ # # ]: 0 : if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
3513 : 0 : return rte_flow_error_set(error, EINVAL,
3514 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3515 : : "protocol filtering not compatible"
3516 : : " with this GRE layer");
3517 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3518 : 0 : return rte_flow_error_set(error, ENOTSUP,
3519 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3520 : : "multiple tunnel layers not"
3521 : : " supported");
3522 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
3523 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
3524 : 0 : return rte_flow_error_set(error, ENOTSUP,
3525 : : RTE_FLOW_ERROR_TYPE_ITEM,
3526 : : item, "L3 Layer is missing");
3527 : : }
3528 [ # # ]: 0 : if (!mask)
3529 : : mask = &rte_flow_item_gre_mask;
3530 : 0 : ret = mlx5_flow_item_acceptable
3531 : : (dev, item, (const uint8_t *)mask,
3532 : : (const uint8_t *)&nic_mask,
3533 : : sizeof(struct rte_flow_item_gre), MLX5_ITEM_RANGE_NOT_ACCEPTED,
3534 : : error);
3535 : : if (ret < 0)
3536 : : return ret;
3537 : : #ifndef HAVE_MLX5DV_DR
3538 : : #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
3539 : : if (spec && (spec->protocol & mask->protocol))
3540 : : return rte_flow_error_set(error, ENOTSUP,
3541 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3542 : : "without MPLS support the"
3543 : : " specification cannot be used for"
3544 : : " filtering");
3545 : : #endif
3546 : : #endif
3547 : : return 0;
3548 : : }
3549 : :
3550 : : /**
3551 : : * Validate Geneve item.
3552 : : *
3553 : : * @param[in] item
3554 : : * Item specification.
3555 : : * @param[in] itemFlags
3556 : : * Bit-fields that holds the items detected until now.
3557 : : * @param[in] enPriv
3558 : : * Pointer to the private data structure.
3559 : : * @param[out] error
3560 : : * Pointer to error structure.
3561 : : *
3562 : : * @return
3563 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3564 : : */
3565 : :
3566 : : int
3567 : 0 : mlx5_flow_validate_item_geneve(const struct rte_flow_item *item,
3568 : : uint64_t item_flags,
3569 : : struct rte_eth_dev *dev,
3570 : : struct rte_flow_error *error)
3571 : : {
3572 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3573 : 0 : const struct rte_flow_item_geneve *spec = item->spec;
3574 : 0 : const struct rte_flow_item_geneve *mask = item->mask;
3575 : : int ret;
3576 : : uint16_t gbhdr;
3577 [ # # ]: 0 : uint8_t opt_len = priv->sh->cdev->config.hca_attr.geneve_max_opt_len ?
3578 : : MLX5_GENEVE_OPT_LEN_1 : MLX5_GENEVE_OPT_LEN_0;
3579 : 0 : const struct rte_flow_item_geneve nic_mask = {
3580 : : .ver_opt_len_o_c_rsvd0 = RTE_BE16(0x3f80),
3581 : : .vni = { 0xff, 0xff, 0xff },
3582 : : .protocol = RTE_BE16(UINT16_MAX),
3583 : : };
3584 : :
3585 [ # # ]: 0 : if (!priv->sh->cdev->config.hca_attr.tunnel_stateless_geneve_rx)
3586 : 0 : return rte_flow_error_set(error, ENOTSUP,
3587 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3588 : : "L3 Geneve is not enabled by device"
3589 : : " parameter and/or not configured in"
3590 : : " firmware");
3591 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3592 : 0 : return rte_flow_error_set(error, ENOTSUP,
3593 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3594 : : "multiple tunnel layers not"
3595 : : " supported");
3596 : : /*
3597 : : * Verify only UDPv4 is present as defined in
3598 : : * https://tools.ietf.org/html/rfc7348
3599 : : */
3600 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
3601 : 0 : return rte_flow_error_set(error, EINVAL,
3602 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3603 : : "no outer UDP layer found");
3604 [ # # ]: 0 : if (!mask)
3605 : : mask = &rte_flow_item_geneve_mask;
3606 : 0 : ret = mlx5_flow_item_acceptable
3607 : : (dev, item, (const uint8_t *)mask,
3608 : : (const uint8_t *)&nic_mask,
3609 : : sizeof(struct rte_flow_item_geneve),
3610 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3611 [ # # ]: 0 : if (ret)
3612 : : return ret;
3613 [ # # ]: 0 : if (spec) {
3614 [ # # ]: 0 : gbhdr = rte_be_to_cpu_16(spec->ver_opt_len_o_c_rsvd0);
3615 [ # # ]: 0 : if (MLX5_GENEVE_VER_VAL(gbhdr) ||
3616 [ # # # # ]: 0 : MLX5_GENEVE_CRITO_VAL(gbhdr) ||
3617 [ # # ]: 0 : MLX5_GENEVE_RSVD_VAL(gbhdr) || spec->rsvd1)
3618 : 0 : return rte_flow_error_set(error, ENOTSUP,
3619 : : RTE_FLOW_ERROR_TYPE_ITEM,
3620 : : item,
3621 : : "Geneve protocol unsupported"
3622 : : " fields are being used");
3623 [ # # ]: 0 : if (MLX5_GENEVE_OPTLEN_VAL(gbhdr) > opt_len)
3624 : 0 : return rte_flow_error_set
3625 : : (error, ENOTSUP,
3626 : : RTE_FLOW_ERROR_TYPE_ITEM,
3627 : : item,
3628 : : "Unsupported Geneve options length");
3629 : : }
3630 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
3631 : 0 : return rte_flow_error_set
3632 : : (error, ENOTSUP,
3633 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3634 : : "Geneve tunnel must be fully defined");
3635 : : return 0;
3636 : : }
3637 : :
3638 : : /**
3639 : : * Validate Geneve TLV option item.
3640 : : *
3641 : : * @param[in] item
3642 : : * Item specification.
3643 : : * @param[in] last_item
3644 : : * Previous validated item in the pattern items.
3645 : : * @param[in] geneve_item
3646 : : * Previous GENEVE item specification.
3647 : : * @param[in] dev
3648 : : * Pointer to the rte_eth_dev structure.
3649 : : * @param[out] error
3650 : : * Pointer to error structure.
3651 : : *
3652 : : * @return
3653 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3654 : : */
3655 : : int
3656 : 0 : mlx5_flow_validate_item_geneve_opt(const struct rte_flow_item *item,
3657 : : uint64_t last_item,
3658 : : const struct rte_flow_item *geneve_item,
3659 : : struct rte_eth_dev *dev,
3660 : : struct rte_flow_error *error)
3661 : : {
3662 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3663 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
3664 : : struct mlx5_geneve_tlv_option_resource *geneve_opt_resource;
3665 : 0 : struct mlx5_hca_attr *hca_attr = &sh->cdev->config.hca_attr;
3666 : 0 : uint8_t data_max_supported =
3667 : 0 : hca_attr->max_geneve_tlv_option_data_len * 4;
3668 : : const struct rte_flow_item_geneve *geneve_spec;
3669 : : const struct rte_flow_item_geneve *geneve_mask;
3670 : 0 : const struct rte_flow_item_geneve_opt *spec = item->spec;
3671 : 0 : const struct rte_flow_item_geneve_opt *mask = item->mask;
3672 : : unsigned int i;
3673 : : unsigned int data_len;
3674 : : uint8_t tlv_option_len;
3675 : : uint16_t optlen_m, optlen_v;
3676 : : const struct rte_flow_item_geneve_opt full_mask = {
3677 : : .option_class = RTE_BE16(0xffff),
3678 : : .option_type = 0xff,
3679 : : .option_len = 0x1f,
3680 : : };
3681 : :
3682 [ # # ]: 0 : if (!mask)
3683 : : mask = &rte_flow_item_geneve_opt_mask;
3684 [ # # ]: 0 : if (!spec)
3685 : 0 : return rte_flow_error_set
3686 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3687 : : "Geneve TLV opt class/type/length must be specified");
3688 [ # # ]: 0 : if ((uint32_t)spec->option_len > MLX5_GENEVE_OPTLEN_MASK)
3689 : 0 : return rte_flow_error_set
3690 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3691 : : "Geneve TLV opt length exceeds the limit (31)");
3692 : : /* Check if class type and length masks are full. */
3693 [ # # ]: 0 : if (full_mask.option_class != mask->option_class ||
3694 : 0 : full_mask.option_type != mask->option_type ||
3695 [ # # ]: 0 : full_mask.option_len != (mask->option_len & full_mask.option_len))
3696 : 0 : return rte_flow_error_set
3697 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3698 : : "Geneve TLV opt class/type/length masks must be full");
3699 : : /* Check if length is supported */
3700 [ # # ]: 0 : if ((uint32_t)spec->option_len >
3701 : : hca_attr->max_geneve_tlv_option_data_len)
3702 : 0 : return rte_flow_error_set
3703 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3704 : : "Geneve TLV opt length not supported");
3705 [ # # ]: 0 : if (hca_attr->max_geneve_tlv_options > 1)
3706 : 0 : DRV_LOG(DEBUG,
3707 : : "max_geneve_tlv_options supports more than 1 option");
3708 : : /* Check GENEVE item preceding. */
3709 [ # # # # ]: 0 : if (!geneve_item || !(last_item & MLX5_FLOW_LAYER_GENEVE))
3710 : 0 : return rte_flow_error_set
3711 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3712 : : "Geneve opt item must be preceded with Geneve item");
3713 : 0 : geneve_spec = geneve_item->spec;
3714 [ # # ]: 0 : geneve_mask = geneve_item->mask ? geneve_item->mask :
3715 : : &rte_flow_item_geneve_mask;
3716 : : /* Check if GENEVE TLV option size doesn't exceed option length */
3717 [ # # # # ]: 0 : if (geneve_spec && (geneve_mask->ver_opt_len_o_c_rsvd0 ||
3718 [ # # ]: 0 : geneve_spec->ver_opt_len_o_c_rsvd0)) {
3719 : 0 : tlv_option_len = spec->option_len & mask->option_len;
3720 [ # # ]: 0 : optlen_v = rte_be_to_cpu_16(geneve_spec->ver_opt_len_o_c_rsvd0);
3721 : 0 : optlen_v = MLX5_GENEVE_OPTLEN_VAL(optlen_v);
3722 [ # # ]: 0 : optlen_m = rte_be_to_cpu_16(geneve_mask->ver_opt_len_o_c_rsvd0);
3723 : 0 : optlen_m = MLX5_GENEVE_OPTLEN_VAL(optlen_m);
3724 [ # # ]: 0 : if ((optlen_v & optlen_m) <= tlv_option_len)
3725 : 0 : return rte_flow_error_set
3726 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3727 : : "GENEVE TLV option length exceeds optlen");
3728 : : }
3729 : : /* Check if length is 0 or data is 0. */
3730 [ # # # # ]: 0 : if (spec->data == NULL || spec->option_len == 0)
3731 : 0 : return rte_flow_error_set
3732 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3733 : : "Geneve TLV opt with zero data/length not supported");
3734 : : /* Check not all data & mask are 0. */
3735 : 0 : data_len = spec->option_len * 4;
3736 [ # # ]: 0 : if (mask->data == NULL) {
3737 [ # # ]: 0 : for (i = 0; i < data_len; i++)
3738 [ # # ]: 0 : if (spec->data[i])
3739 : : break;
3740 [ # # ]: 0 : if (i == data_len)
3741 : 0 : return rte_flow_error_set(error, ENOTSUP,
3742 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3743 : : "Can't match on Geneve option data 0");
3744 : : } else {
3745 [ # # ]: 0 : for (i = 0; i < data_len; i++)
3746 [ # # ]: 0 : if (spec->data[i] & mask->data[i])
3747 : : break;
3748 [ # # ]: 0 : if (i == data_len)
3749 : 0 : return rte_flow_error_set(error, ENOTSUP,
3750 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3751 : : "Can't match on Geneve option data and mask 0");
3752 : : /* Check data mask supported. */
3753 [ # # ]: 0 : for (i = data_max_supported; i < data_len ; i++)
3754 [ # # ]: 0 : if (mask->data[i])
3755 : 0 : return rte_flow_error_set(error, ENOTSUP,
3756 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3757 : : "Data mask is of unsupported size");
3758 : : }
3759 : : /* Check GENEVE option is supported in NIC. */
3760 [ # # ]: 0 : if (!hca_attr->geneve_tlv_opt)
3761 : 0 : return rte_flow_error_set
3762 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
3763 : : "Geneve TLV opt not supported");
3764 : : /* Check if we already have geneve option with different type/class. */
3765 : 0 : rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
3766 : 0 : geneve_opt_resource = sh->geneve_tlv_option_resource;
3767 [ # # ]: 0 : if (geneve_opt_resource != NULL)
3768 : 0 : if (geneve_opt_resource->option_class != spec->option_class ||
3769 [ # # ]: 0 : geneve_opt_resource->option_type != spec->option_type ||
3770 : : geneve_opt_resource->length != spec->option_len) {
3771 : : rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
3772 : 0 : return rte_flow_error_set(error, ENOTSUP,
3773 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3774 : : "Only one Geneve TLV option supported");
3775 : : }
3776 : : rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
3777 : 0 : return 0;
3778 : : }
3779 : :
3780 : : /**
3781 : : * Validate MPLS item.
3782 : : *
3783 : : * @param[in] dev
3784 : : * Pointer to the rte_eth_dev structure.
3785 : : * @param[in] item
3786 : : * Item specification.
3787 : : * @param[in] item_flags
3788 : : * Bit-fields that holds the items detected until now.
3789 : : * @param[in] prev_layer
3790 : : * The protocol layer indicated in previous item.
3791 : : * @param[out] error
3792 : : * Pointer to error structure.
3793 : : *
3794 : : * @return
3795 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3796 : : */
3797 : : int
3798 : 0 : mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev __rte_unused,
3799 : : const struct rte_flow_item *item __rte_unused,
3800 : : uint64_t item_flags __rte_unused,
3801 : : uint64_t prev_layer __rte_unused,
3802 : : struct rte_flow_error *error)
3803 : : {
3804 : : #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
3805 [ # # ]: 0 : const struct rte_flow_item_mpls hws_nic_mask = {
3806 : : .label_tc_s = {0xff, 0xff, 0xff},
3807 : : .ttl = 0xff
3808 : : };
3809 : : const struct rte_flow_item_mpls *nic_mask = !mlx5_hws_active(dev) ?
3810 [ # # ]: 0 : &rte_flow_item_mpls_mask : &hws_nic_mask;
3811 : 0 : const struct rte_flow_item_mpls *mask = item->mask;
3812 : : struct mlx5_priv *priv = dev->data->dev_private;
3813 : : int ret;
3814 : :
3815 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
3816 : : /* MPLS has HW support in HWS */
3817 [ # # ]: 0 : if (!priv->sh->dev_cap.mpls_en)
3818 : 0 : return rte_flow_error_set(error, ENOTSUP,
3819 : : RTE_FLOW_ERROR_TYPE_ITEM,
3820 : : item, "MPLS not supported or disabled in firmware configuration.");
3821 : : /* MPLS over UDP, GRE is allowed */
3822 [ # # ]: 0 : if (!(prev_layer & (MLX5_FLOW_LAYER_OUTER_L4_UDP |
3823 : : MLX5_FLOW_LAYER_GRE |
3824 : : MLX5_FLOW_LAYER_GRE_KEY)))
3825 : 0 : return rte_flow_error_set(error, EINVAL,
3826 : : RTE_FLOW_ERROR_TYPE_ITEM,
3827 : : item, "protocol filtering not compatible with MPLS layer");
3828 : : /* Multi-tunnel isn't allowed but MPLS over GRE is an exception. */
3829 [ # # ]: 0 : if ((item_flags & MLX5_FLOW_LAYER_TUNNEL) &&
3830 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_GRE))
3831 : 0 : return rte_flow_error_set(error, ENOTSUP,
3832 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3833 : : "multiple tunnel layers not supported");
3834 : : }
3835 [ # # ]: 0 : if (!mask)
3836 : : mask = nic_mask;
3837 : 0 : ret = mlx5_flow_item_acceptable
3838 : : (dev, item, (const uint8_t *)mask,
3839 : : (const uint8_t *)nic_mask,
3840 : : sizeof(struct rte_flow_item_mpls),
3841 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3842 : : if (ret < 0)
3843 : : return ret;
3844 : : return 0;
3845 : : #else
3846 : : return rte_flow_error_set(error, ENOTSUP,
3847 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3848 : : "MPLS is not supported by Verbs, please"
3849 : : " update.");
3850 : : #endif
3851 : : }
3852 : :
3853 : : /**
3854 : : * Validate NVGRE item.
3855 : : *
3856 : : * @param[in] item
3857 : : * Item specification.
3858 : : * @param[in] item_flags
3859 : : * Bit flags to mark detected items.
3860 : : * @param[in] target_protocol
3861 : : * The next protocol in the previous item.
3862 : : * @param[out] error
3863 : : * Pointer to error structure.
3864 : : *
3865 : : * @return
3866 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3867 : : */
3868 : : int
3869 : 0 : mlx5_flow_validate_item_nvgre(const struct rte_eth_dev *dev,
3870 : : const struct rte_flow_item *item,
3871 : : uint64_t item_flags,
3872 : : uint8_t target_protocol,
3873 : : struct rte_flow_error *error)
3874 : : {
3875 : 0 : const struct rte_flow_item_nvgre *mask = item->mask;
3876 : : int ret;
3877 : :
3878 [ # # ]: 0 : const struct rte_flow_item_nvgre hws_nic_mask = {
3879 : : .c_k_s_rsvd0_ver = RTE_BE16(0xB000),
3880 : : .protocol = RTE_BE16(UINT16_MAX),
3881 : : .tni = {0xff, 0xff, 0xff},
3882 : : .flow_id = 0xff
3883 : : };
3884 : : const struct rte_flow_item_nvgre *nic_mask = !mlx5_hws_active(dev) ?
3885 [ # # ]: 0 : &rte_flow_item_nvgre_mask : &hws_nic_mask;
3886 : :
3887 [ # # ]: 0 : if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
3888 : 0 : return rte_flow_error_set(error, EINVAL,
3889 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3890 : : "protocol filtering not compatible"
3891 : : " with this GRE layer");
3892 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3893 : 0 : return rte_flow_error_set(error, ENOTSUP,
3894 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3895 : : "multiple tunnel layers not"
3896 : : " supported");
3897 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
3898 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
3899 : 0 : return rte_flow_error_set(error, ENOTSUP,
3900 : : RTE_FLOW_ERROR_TYPE_ITEM,
3901 : : item, "L3 Layer is missing");
3902 : : }
3903 [ # # ]: 0 : if (!mask)
3904 : : mask = nic_mask;
3905 : 0 : ret = mlx5_flow_item_acceptable
3906 : : (dev, item, (const uint8_t *)mask,
3907 : : (const uint8_t *)nic_mask,
3908 : : sizeof(struct rte_flow_item_nvgre),
3909 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3910 : : if (ret < 0)
3911 : : return ret;
3912 : : return 0;
3913 : : }
3914 : :
3915 : : /**
3916 : : * Validate eCPRI item.
3917 : : *
3918 : : * @param[in] item
3919 : : * Item specification.
3920 : : * @param[in] item_flags
3921 : : * Bit-fields that holds the items detected until now.
3922 : : * @param[in] last_item
3923 : : * Previous validated item in the pattern items.
3924 : : * @param[in] ether_type
3925 : : * Type in the ethernet layer header (including dot1q).
3926 : : * @param[in] acc_mask
3927 : : * Acceptable mask, if NULL default internal default mask
3928 : : * will be used to check whether item fields are supported.
3929 : : * @param[out] error
3930 : : * Pointer to error structure.
3931 : : *
3932 : : * @return
3933 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3934 : : */
3935 : : int
3936 : 0 : mlx5_flow_validate_item_ecpri(const struct rte_eth_dev *dev,
3937 : : const struct rte_flow_item *item,
3938 : : uint64_t item_flags,
3939 : : uint64_t last_item,
3940 : : uint16_t ether_type,
3941 : : const struct rte_flow_item_ecpri *acc_mask,
3942 : : struct rte_flow_error *error)
3943 : : {
3944 : 0 : const struct rte_flow_item_ecpri *mask = item->mask;
3945 : 0 : const struct rte_flow_item_ecpri nic_mask = {
3946 : : .hdr = {
3947 : : .common = {
3948 : : .u32 =
3949 : : RTE_BE32(((const struct rte_ecpri_common_hdr) {
3950 : : .type = 0xFF,
3951 : : }).u32),
3952 : : },
3953 : : .dummy[0] = 0xFFFFFFFF,
3954 : : },
3955 : : };
3956 : : const uint64_t outer_l2_vlan = (MLX5_FLOW_LAYER_OUTER_L2 |
3957 : : MLX5_FLOW_LAYER_OUTER_VLAN);
3958 : : struct rte_flow_item_ecpri mask_lo;
3959 : :
3960 [ # # # # ]: 0 : if (!(last_item & outer_l2_vlan) &&
3961 : : last_item != MLX5_FLOW_LAYER_OUTER_L4_UDP)
3962 : 0 : return rte_flow_error_set(error, EINVAL,
3963 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3964 : : "eCPRI can only follow L2/VLAN layer or UDP layer");
3965 [ # # ]: 0 : if ((last_item & outer_l2_vlan) && ether_type &&
3966 [ # # ]: 0 : ether_type != RTE_ETHER_TYPE_ECPRI)
3967 : 0 : return rte_flow_error_set(error, EINVAL,
3968 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3969 : : "eCPRI cannot follow L2/VLAN layer which ether type is not 0xAEFE");
3970 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
3971 : 0 : return rte_flow_error_set(error, EINVAL,
3972 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3973 : : "eCPRI with tunnel is not supported right now");
3974 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_OUTER_L3)
3975 : 0 : return rte_flow_error_set(error, ENOTSUP,
3976 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3977 : : "multiple L3 layers not supported");
3978 [ # # ]: 0 : else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP)
3979 : 0 : return rte_flow_error_set(error, EINVAL,
3980 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3981 : : "eCPRI cannot coexist with a TCP layer");
3982 : : /* In specification, eCPRI could be over UDP layer. */
3983 [ # # ]: 0 : else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP)
3984 : 0 : return rte_flow_error_set(error, EINVAL,
3985 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3986 : : "eCPRI over UDP layer is not yet supported right now");
3987 : : /* Mask for type field in common header could be zero. */
3988 [ # # ]: 0 : if (!mask)
3989 : : mask = &rte_flow_item_ecpri_mask;
3990 [ # # ]: 0 : mask_lo.hdr.common.u32 = rte_be_to_cpu_32(mask->hdr.common.u32);
3991 : : /* Input mask is in big-endian format. */
3992 [ # # ]: 0 : if (mask_lo.hdr.common.type != 0 && mask_lo.hdr.common.type != 0xff)
3993 : 0 : return rte_flow_error_set(error, EINVAL,
3994 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
3995 : : "partial mask is not supported for protocol");
3996 [ # # # # ]: 0 : else if (mask_lo.hdr.common.type == 0 && mask->hdr.dummy[0] != 0)
3997 : 0 : return rte_flow_error_set(error, EINVAL,
3998 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
3999 : : "message header mask must be after a type mask");
4000 [ # # ]: 0 : return mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
4001 : : acc_mask ? (const uint8_t *)acc_mask
4002 : : : (const uint8_t *)&nic_mask,
4003 : : sizeof(struct rte_flow_item_ecpri),
4004 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
4005 : : }
4006 : :
4007 : : /**
4008 : : * Validate the NSH item.
4009 : : *
4010 : : * @param[in] dev
4011 : : * Pointer to Ethernet device on which flow rule is being created on.
4012 : : * @param[out] error
4013 : : * Pointer to error structure.
4014 : : *
4015 : : * @return
4016 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4017 : : */
4018 : : int
4019 : 0 : mlx5_flow_validate_item_nsh(struct rte_eth_dev *dev,
4020 : : const struct rte_flow_item *item,
4021 : : struct rte_flow_error *error)
4022 : : {
4023 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4024 : :
4025 [ # # ]: 0 : if (item->mask) {
4026 : 0 : return rte_flow_error_set(error, ENOTSUP,
4027 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
4028 : : "NSH fields matching is not supported");
4029 : : }
4030 : :
4031 [ # # ]: 0 : if (!priv->sh->config.dv_flow_en) {
4032 : 0 : return rte_flow_error_set(error, ENOTSUP,
4033 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4034 : : NULL, "NSH support requires DV flow interface");
4035 : : }
4036 : :
4037 [ # # ]: 0 : if (!priv->sh->cdev->config.hca_attr.tunnel_stateless_vxlan_gpe_nsh) {
4038 : 0 : return rte_flow_error_set(error, ENOTSUP,
4039 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
4040 : : "Current FW does not support matching on NSH");
4041 : : }
4042 : :
4043 : : return 0;
4044 : : }
4045 : :
4046 : : static uintptr_t
4047 : 0 : flow_null_list_create(struct rte_eth_dev *dev __rte_unused,
4048 : : enum mlx5_flow_type type __rte_unused,
4049 : : const struct rte_flow_attr *attr __rte_unused,
4050 : : const struct rte_flow_item items[] __rte_unused,
4051 : : const struct rte_flow_action actions[] __rte_unused,
4052 : : bool external __rte_unused,
4053 : : struct rte_flow_error *error)
4054 : : {
4055 : 0 : rte_flow_error_set(error, ENOTSUP,
4056 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
4057 : 0 : return 0;
4058 : : }
4059 : :
4060 : : static int
4061 : 0 : flow_null_validate(struct rte_eth_dev *dev __rte_unused,
4062 : : const struct rte_flow_attr *attr __rte_unused,
4063 : : const struct rte_flow_item items[] __rte_unused,
4064 : : const struct rte_flow_action actions[] __rte_unused,
4065 : : bool external __rte_unused,
4066 : : int hairpin __rte_unused,
4067 : : struct rte_flow_error *error)
4068 : : {
4069 : 0 : return rte_flow_error_set(error, ENOTSUP,
4070 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
4071 : : }
4072 : :
4073 : : static struct mlx5_flow *
4074 : 0 : flow_null_prepare(struct rte_eth_dev *dev __rte_unused,
4075 : : const struct rte_flow_attr *attr __rte_unused,
4076 : : const struct rte_flow_item items[] __rte_unused,
4077 : : const struct rte_flow_action actions[] __rte_unused,
4078 : : struct rte_flow_error *error)
4079 : : {
4080 : 0 : rte_flow_error_set(error, ENOTSUP,
4081 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
4082 : 0 : return NULL;
4083 : : }
4084 : :
4085 : : static int
4086 : 0 : flow_null_translate(struct rte_eth_dev *dev __rte_unused,
4087 : : struct mlx5_flow *dev_flow __rte_unused,
4088 : : const struct rte_flow_attr *attr __rte_unused,
4089 : : const struct rte_flow_item items[] __rte_unused,
4090 : : const struct rte_flow_action actions[] __rte_unused,
4091 : : struct rte_flow_error *error)
4092 : : {
4093 : 0 : return rte_flow_error_set(error, ENOTSUP,
4094 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
4095 : : }
4096 : :
4097 : : static int
4098 : 0 : flow_null_apply(struct rte_eth_dev *dev __rte_unused,
4099 : : struct rte_flow *flow __rte_unused,
4100 : : struct rte_flow_error *error)
4101 : : {
4102 : 0 : return rte_flow_error_set(error, ENOTSUP,
4103 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
4104 : : }
4105 : :
4106 : : static void
4107 : 0 : flow_null_remove(struct rte_eth_dev *dev __rte_unused,
4108 : : struct rte_flow *flow __rte_unused)
4109 : : {
4110 : 0 : }
4111 : :
4112 : : static void
4113 : 0 : flow_null_destroy(struct rte_eth_dev *dev __rte_unused,
4114 : : struct rte_flow *flow __rte_unused)
4115 : : {
4116 : 0 : }
4117 : :
4118 : : static int
4119 : 0 : flow_null_query(struct rte_eth_dev *dev __rte_unused,
4120 : : struct rte_flow *flow __rte_unused,
4121 : : const struct rte_flow_action *actions __rte_unused,
4122 : : void *data __rte_unused,
4123 : : struct rte_flow_error *error)
4124 : : {
4125 : 0 : return rte_flow_error_set(error, ENOTSUP,
4126 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
4127 : : }
4128 : :
4129 : : static int
4130 : 0 : flow_null_sync_domain(struct rte_eth_dev *dev __rte_unused,
4131 : : uint32_t domains __rte_unused,
4132 : : uint32_t flags __rte_unused)
4133 : : {
4134 : 0 : return 0;
4135 : : }
4136 : :
4137 : : int
4138 : 0 : mlx5_flow_null_get_aged_flows(struct rte_eth_dev *dev,
4139 : : void **context __rte_unused,
4140 : : uint32_t nb_contexts __rte_unused,
4141 : : struct rte_flow_error *error __rte_unused)
4142 : : {
4143 : 0 : DRV_LOG(ERR, "port %u get aged flows is not supported.",
4144 : : dev->data->port_id);
4145 : 0 : return -ENOTSUP;
4146 : : }
4147 : :
4148 : : uint32_t
4149 : 0 : mlx5_flow_null_counter_allocate(struct rte_eth_dev *dev)
4150 : : {
4151 : 0 : DRV_LOG(ERR, "port %u counter allocate is not supported.",
4152 : : dev->data->port_id);
4153 : 0 : return 0;
4154 : : }
4155 : :
4156 : : void
4157 : 0 : mlx5_flow_null_counter_free(struct rte_eth_dev *dev,
4158 : : uint32_t counter __rte_unused)
4159 : : {
4160 : 0 : DRV_LOG(ERR, "port %u counter free is not supported.",
4161 : : dev->data->port_id);
4162 : 0 : }
4163 : :
4164 : : int
4165 : 0 : mlx5_flow_null_counter_query(struct rte_eth_dev *dev,
4166 : : uint32_t counter __rte_unused,
4167 : : bool clear __rte_unused,
4168 : : uint64_t *pkts __rte_unused,
4169 : : uint64_t *bytes __rte_unused,
4170 : : void **action __rte_unused)
4171 : : {
4172 : 0 : DRV_LOG(ERR, "port %u counter query is not supported.",
4173 : : dev->data->port_id);
4174 : 0 : return -ENOTSUP;
4175 : : }
4176 : :
4177 : : /* Void driver to protect from null pointer reference. */
4178 : : const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
4179 : : .list_create = flow_null_list_create,
4180 : : .validate = flow_null_validate,
4181 : : .prepare = flow_null_prepare,
4182 : : .translate = flow_null_translate,
4183 : : .apply = flow_null_apply,
4184 : : .remove = flow_null_remove,
4185 : : .destroy = flow_null_destroy,
4186 : : .query = flow_null_query,
4187 : : .sync_domain = flow_null_sync_domain,
4188 : : .get_aged_flows = mlx5_flow_null_get_aged_flows,
4189 : : .counter_alloc = mlx5_flow_null_counter_allocate,
4190 : : .counter_free = mlx5_flow_null_counter_free,
4191 : : .counter_query = mlx5_flow_null_counter_query
4192 : : };
4193 : :
4194 : : /**
4195 : : * Select flow driver type according to flow attributes and device
4196 : : * configuration.
4197 : : *
4198 : : * @param[in] dev
4199 : : * Pointer to the dev structure.
4200 : : * @param[in] attr
4201 : : * Pointer to the flow attributes.
4202 : : *
4203 : : * @return
4204 : : * flow driver type, MLX5_FLOW_TYPE_MAX otherwise.
4205 : : */
4206 : : static enum mlx5_flow_drv_type
4207 : 0 : flow_get_drv_type(struct rte_eth_dev *dev, const struct rte_flow_attr *attr)
4208 : : {
4209 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4210 : : /* The OS can determine first a specific flow type (DV, VERBS) */
4211 : : enum mlx5_flow_drv_type type = mlx5_flow_os_get_type();
4212 : :
4213 : : if (type != MLX5_FLOW_TYPE_MAX)
4214 : : return type;
4215 : : /*
4216 : : * Currently when dv_flow_en == 2, only HW steering engine is
4217 : : * supported. New engines can also be chosen here if ready.
4218 : : */
4219 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
4220 : : return MLX5_FLOW_TYPE_HW;
4221 [ # # ]: 0 : if (!attr)
4222 : : return MLX5_FLOW_TYPE_MIN;
4223 : : /* If no OS specific type - continue with DV/VERBS selection */
4224 [ # # # # ]: 0 : if (attr->transfer && priv->sh->config.dv_esw_en)
4225 : : type = MLX5_FLOW_TYPE_DV;
4226 [ # # ]: 0 : if (!attr->transfer)
4227 [ # # # # : 0 : type = priv->sh->config.dv_flow_en ? MLX5_FLOW_TYPE_DV :
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
4228 : : MLX5_FLOW_TYPE_VERBS;
4229 : : return type;
4230 : : }
4231 : :
4232 : : #define flow_get_drv_ops(type) flow_drv_ops[type]
4233 : :
4234 : : /**
4235 : : * Flow driver validation API. This abstracts calling driver specific functions.
4236 : : * The type of flow driver is determined according to flow attributes.
4237 : : *
4238 : : * @param[in] dev
4239 : : * Pointer to the dev structure.
4240 : : * @param[in] attr
4241 : : * Pointer to the flow attributes.
4242 : : * @param[in] items
4243 : : * Pointer to the list of items.
4244 : : * @param[in] actions
4245 : : * Pointer to the list of actions.
4246 : : * @param[in] external
4247 : : * This flow rule is created by request external to PMD.
4248 : : * @param[in] hairpin
4249 : : * Number of hairpin TX actions, 0 means classic flow.
4250 : : * @param[out] error
4251 : : * Pointer to the error structure.
4252 : : *
4253 : : * @return
4254 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4255 : : */
4256 : : static inline int
4257 : 0 : flow_drv_validate(struct rte_eth_dev *dev,
4258 : : const struct rte_flow_attr *attr,
4259 : : const struct rte_flow_item items[],
4260 : : const struct rte_flow_action actions[],
4261 : : bool external, int hairpin, struct rte_flow_error *error)
4262 : : {
4263 : : const struct mlx5_flow_driver_ops *fops;
4264 : 0 : enum mlx5_flow_drv_type type = flow_get_drv_type(dev, attr);
4265 : :
4266 : 0 : fops = flow_get_drv_ops(type);
4267 : 0 : return fops->validate(dev, attr, items, actions, external,
4268 : : hairpin, error);
4269 : : }
4270 : :
4271 : : /**
4272 : : * Flow driver preparation API. This abstracts calling driver specific
4273 : : * functions. Parent flow (rte_flow) should have driver type (drv_type). It
4274 : : * calculates the size of memory required for device flow, allocates the memory,
4275 : : * initializes the device flow and returns the pointer.
4276 : : *
4277 : : * @note
4278 : : * This function initializes device flow structure such as dv or verbs in
4279 : : * struct mlx5_flow. However, it is caller's responsibility to initialize the
4280 : : * rest. For example, adding returning device flow to flow->dev_flow list and
4281 : : * setting backward reference to the flow should be done out of this function.
4282 : : * layers field is not filled either.
4283 : : *
4284 : : * @param[in] dev
4285 : : * Pointer to the dev structure.
4286 : : * @param[in] attr
4287 : : * Pointer to the flow attributes.
4288 : : * @param[in] items
4289 : : * Pointer to the list of items.
4290 : : * @param[in] actions
4291 : : * Pointer to the list of actions.
4292 : : * @param[in] flow_idx
4293 : : * This memory pool index to the flow.
4294 : : * @param[out] error
4295 : : * Pointer to the error structure.
4296 : : *
4297 : : * @return
4298 : : * Pointer to device flow on success, otherwise NULL and rte_errno is set.
4299 : : */
4300 : : static inline struct mlx5_flow *
4301 : : flow_drv_prepare(struct rte_eth_dev *dev,
4302 : : const struct rte_flow *flow,
4303 : : const struct rte_flow_attr *attr,
4304 : : const struct rte_flow_item items[],
4305 : : const struct rte_flow_action actions[],
4306 : : uint32_t flow_idx,
4307 : : struct rte_flow_error *error)
4308 : : {
4309 : : const struct mlx5_flow_driver_ops *fops;
4310 : 0 : enum mlx5_flow_drv_type type = flow->drv_type;
4311 : : struct mlx5_flow *mlx5_flow = NULL;
4312 : :
4313 : : MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
4314 : 0 : fops = flow_get_drv_ops(type);
4315 : 0 : mlx5_flow = fops->prepare(dev, attr, items, actions, error);
4316 [ # # # # : 0 : if (mlx5_flow)
# # ]
4317 : 0 : mlx5_flow->flow_idx = flow_idx;
4318 : : return mlx5_flow;
4319 : : }
4320 : :
4321 : : /**
4322 : : * Flow driver translation API. This abstracts calling driver specific
4323 : : * functions. Parent flow (rte_flow) should have driver type (drv_type). It
4324 : : * translates a generic flow into a driver flow. flow_drv_prepare() must
4325 : : * precede.
4326 : : *
4327 : : * @note
4328 : : * dev_flow->layers could be filled as a result of parsing during translation
4329 : : * if needed by flow_drv_apply(). dev_flow->flow->actions can also be filled
4330 : : * if necessary. As a flow can have multiple dev_flows by RSS flow expansion,
4331 : : * flow->actions could be overwritten even though all the expanded dev_flows
4332 : : * have the same actions.
4333 : : *
4334 : : * @param[in] dev
4335 : : * Pointer to the rte dev structure.
4336 : : * @param[in, out] dev_flow
4337 : : * Pointer to the mlx5 flow.
4338 : : * @param[in] attr
4339 : : * Pointer to the flow attributes.
4340 : : * @param[in] items
4341 : : * Pointer to the list of items.
4342 : : * @param[in] actions
4343 : : * Pointer to the list of actions.
4344 : : * @param[out] error
4345 : : * Pointer to the error structure.
4346 : : *
4347 : : * @return
4348 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4349 : : */
4350 : : static inline int
4351 : : flow_drv_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
4352 : : const struct rte_flow_attr *attr,
4353 : : const struct rte_flow_item items[],
4354 : : const struct rte_flow_action actions[],
4355 : : struct rte_flow_error *error)
4356 : : {
4357 : : const struct mlx5_flow_driver_ops *fops;
4358 : 0 : enum mlx5_flow_drv_type type = dev_flow->flow->drv_type;
4359 : :
4360 : : MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
4361 : 0 : fops = flow_get_drv_ops(type);
4362 : 0 : return fops->translate(dev, dev_flow, attr, items, actions, error);
4363 : : }
4364 : :
4365 : : /**
4366 : : * Flow driver apply API. This abstracts calling driver specific functions.
4367 : : * Parent flow (rte_flow) should have driver type (drv_type). It applies
4368 : : * translated driver flows on to device. flow_drv_translate() must precede.
4369 : : *
4370 : : * @param[in] dev
4371 : : * Pointer to Ethernet device structure.
4372 : : * @param[in, out] flow
4373 : : * Pointer to flow structure.
4374 : : * @param[out] error
4375 : : * Pointer to error structure.
4376 : : *
4377 : : * @return
4378 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4379 : : */
4380 : : static inline int
4381 : : flow_drv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
4382 : : struct rte_flow_error *error)
4383 : : {
4384 : : const struct mlx5_flow_driver_ops *fops;
4385 : 0 : enum mlx5_flow_drv_type type = flow->drv_type;
4386 : :
4387 : : MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
4388 : 0 : fops = flow_get_drv_ops(type);
4389 : 0 : return fops->apply(dev, flow, error);
4390 : : }
4391 : :
4392 : : /**
4393 : : * Flow driver destroy API. This abstracts calling driver specific functions.
4394 : : * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
4395 : : * on device and releases resources of the flow.
4396 : : *
4397 : : * @param[in] dev
4398 : : * Pointer to Ethernet device.
4399 : : * @param[in, out] flow
4400 : : * Pointer to flow structure.
4401 : : */
4402 : : static inline void
4403 : : flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
4404 : : {
4405 : : const struct mlx5_flow_driver_ops *fops;
4406 : 0 : enum mlx5_flow_drv_type type = flow->drv_type;
4407 : :
4408 : : MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
4409 : 0 : fops = flow_get_drv_ops(type);
4410 : 0 : fops->destroy(dev, flow);
4411 : : }
4412 : :
4413 : : /**
4414 : : * Flow driver find RSS policy tbl API. This abstracts calling driver
4415 : : * specific functions. Parent flow (rte_flow) should have driver
4416 : : * type (drv_type). It will find the RSS policy table that has the rss_desc.
4417 : : *
4418 : : * @param[in] dev
4419 : : * Pointer to Ethernet device.
4420 : : * @param[in, out] flow
4421 : : * Pointer to flow structure.
4422 : : * @param[in] policy
4423 : : * Pointer to meter policy table.
4424 : : * @param[in] rss_desc
4425 : : * Pointer to rss_desc
4426 : : */
4427 : : static struct mlx5_flow_meter_sub_policy *
4428 : : flow_drv_meter_sub_policy_rss_prepare(struct rte_eth_dev *dev,
4429 : : struct rte_flow *flow,
4430 : : struct mlx5_flow_meter_policy *policy,
4431 : : struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS])
4432 : : {
4433 : : const struct mlx5_flow_driver_ops *fops;
4434 : 0 : enum mlx5_flow_drv_type type = flow->drv_type;
4435 : :
4436 : : MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
4437 : 0 : fops = flow_get_drv_ops(type);
4438 : 0 : return fops->meter_sub_policy_rss_prepare(dev, policy, rss_desc);
4439 : : }
4440 : :
4441 : : /**
4442 : : * Flow driver color tag rule API. This abstracts calling driver
4443 : : * specific functions. Parent flow (rte_flow) should have driver
4444 : : * type (drv_type). It will create the color tag rules in hierarchy meter.
4445 : : *
4446 : : * @param[in] dev
4447 : : * Pointer to Ethernet device.
4448 : : * @param[in, out] flow
4449 : : * Pointer to flow structure.
4450 : : * @param[in] fm
4451 : : * Pointer to flow meter structure.
4452 : : * @param[in] src_port
4453 : : * The src port this extra rule should use.
4454 : : * @param[in] item
4455 : : * The src port id match item.
4456 : : * @param[out] error
4457 : : * Pointer to error structure.
4458 : : */
4459 : : static int
4460 : : flow_drv_mtr_hierarchy_rule_create(struct rte_eth_dev *dev,
4461 : : struct rte_flow *flow,
4462 : : struct mlx5_flow_meter_info *fm,
4463 : : int32_t src_port,
4464 : : const struct rte_flow_item *item,
4465 : : struct rte_flow_error *error)
4466 : : {
4467 : : const struct mlx5_flow_driver_ops *fops;
4468 : 0 : enum mlx5_flow_drv_type type = flow->drv_type;
4469 : :
4470 : : MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
4471 : 0 : fops = flow_get_drv_ops(type);
4472 : 0 : return fops->meter_hierarchy_rule_create(dev, fm,
4473 : : src_port, item, error);
4474 : : }
4475 : :
4476 : : /**
4477 : : * Get RSS action from the action list.
4478 : : *
4479 : : * @param[in] dev
4480 : : * Pointer to Ethernet device.
4481 : : * @param[in] actions
4482 : : * Pointer to the list of actions.
4483 : : * @param[in] flow
4484 : : * Parent flow structure pointer.
4485 : : *
4486 : : * @return
4487 : : * Pointer to the RSS action if exist, else return NULL.
4488 : : */
4489 : : static const struct rte_flow_action_rss*
4490 : 0 : flow_get_rss_action(struct rte_eth_dev *dev,
4491 : : const struct rte_flow_action actions[])
4492 : : {
4493 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4494 : : const struct rte_flow_action_rss *rss = NULL;
4495 : : struct mlx5_meter_policy_action_container *acg;
4496 : : struct mlx5_meter_policy_action_container *acy;
4497 : :
4498 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4499 [ # # # # ]: 0 : switch (actions->type) {
4500 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
4501 : 0 : rss = actions->conf;
4502 : 0 : break;
4503 : 0 : case RTE_FLOW_ACTION_TYPE_SAMPLE:
4504 : : {
4505 : 0 : const struct rte_flow_action_sample *sample =
4506 : : actions->conf;
4507 : 0 : const struct rte_flow_action *act = sample->actions;
4508 [ # # ]: 0 : for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++)
4509 [ # # ]: 0 : if (act->type == RTE_FLOW_ACTION_TYPE_RSS)
4510 : 0 : rss = act->conf;
4511 : : break;
4512 : : }
4513 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
4514 : : {
4515 : : uint32_t mtr_idx;
4516 : : struct mlx5_flow_meter_info *fm;
4517 : : struct mlx5_flow_meter_policy *policy;
4518 : 0 : const struct rte_flow_action_meter *mtr = actions->conf;
4519 : :
4520 : 0 : fm = mlx5_flow_meter_find(priv, mtr->mtr_id, &mtr_idx);
4521 [ # # # # ]: 0 : if (fm && !fm->def_policy) {
4522 : 0 : policy = mlx5_flow_meter_policy_find(dev,
4523 : : fm->policy_id, NULL);
4524 : : MLX5_ASSERT(policy);
4525 [ # # ]: 0 : if (policy->is_hierarchy) {
4526 : : policy =
4527 : 0 : mlx5_flow_meter_hierarchy_get_final_policy(dev,
4528 : : policy);
4529 [ # # ]: 0 : if (!policy)
4530 : 0 : return NULL;
4531 : : }
4532 [ # # ]: 0 : if (policy->is_rss) {
4533 : : acg =
4534 : : &policy->act_cnt[RTE_COLOR_GREEN];
4535 : : acy =
4536 : : &policy->act_cnt[RTE_COLOR_YELLOW];
4537 [ # # ]: 0 : if (acg->fate_action ==
4538 : : MLX5_FLOW_FATE_SHARED_RSS)
4539 : 0 : rss = acg->rss->conf;
4540 [ # # ]: 0 : else if (acy->fate_action ==
4541 : : MLX5_FLOW_FATE_SHARED_RSS)
4542 : 0 : rss = acy->rss->conf;
4543 : : }
4544 : : }
4545 : 0 : break;
4546 : : }
4547 : : default:
4548 : : break;
4549 : : }
4550 : : }
4551 : : return rss;
4552 : : }
4553 : :
4554 : : /**
4555 : : * Get ASO age action by index.
4556 : : *
4557 : : * @param[in] dev
4558 : : * Pointer to the Ethernet device structure.
4559 : : * @param[in] age_idx
4560 : : * Index to the ASO age action.
4561 : : *
4562 : : * @return
4563 : : * The specified ASO age action.
4564 : : */
4565 : : struct mlx5_aso_age_action*
4566 : 0 : mlx5_flow_aso_age_get_by_idx(struct rte_eth_dev *dev, uint32_t age_idx)
4567 : : {
4568 : 0 : uint16_t pool_idx = age_idx & UINT16_MAX;
4569 : 0 : uint16_t offset = (age_idx >> 16) & UINT16_MAX;
4570 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4571 : 0 : struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
4572 : : struct mlx5_aso_age_pool *pool;
4573 : :
4574 : 0 : rte_rwlock_read_lock(&mng->resize_rwl);
4575 : 0 : pool = mng->pools[pool_idx];
4576 : : rte_rwlock_read_unlock(&mng->resize_rwl);
4577 : 0 : return &pool->actions[offset - 1];
4578 : : }
4579 : :
4580 : : /* maps indirect action to translated direct in some actions array */
4581 : : struct mlx5_translated_action_handle {
4582 : : struct rte_flow_action_handle *action; /**< Indirect action handle. */
4583 : : int index; /**< Index in related array of rte_flow_action. */
4584 : : };
4585 : :
4586 : : /**
4587 : : * Translates actions of type RTE_FLOW_ACTION_TYPE_INDIRECT to related
4588 : : * direct action if translation possible.
4589 : : * This functionality used to run same execution path for both direct and
4590 : : * indirect actions on flow create. All necessary preparations for indirect
4591 : : * action handling should be performed on *handle* actions list returned
4592 : : * from this call.
4593 : : *
4594 : : * @param[in] dev
4595 : : * Pointer to Ethernet device.
4596 : : * @param[in] actions
4597 : : * List of actions to translate.
4598 : : * @param[out] handle
4599 : : * List to store translated indirect action object handles.
4600 : : * @param[in, out] indir_n
4601 : : * Size of *handle* array. On return should be updated with number of
4602 : : * indirect actions retrieved from the *actions* list.
4603 : : * @param[out] translated_actions
4604 : : * List of actions where all indirect actions were translated to direct
4605 : : * if possible. NULL if no translation took place.
4606 : : * @param[out] error
4607 : : * Pointer to the error structure.
4608 : : *
4609 : : * @return
4610 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4611 : : */
4612 : : static int
4613 : 0 : flow_action_handles_translate(struct rte_eth_dev *dev,
4614 : : const struct rte_flow_action actions[],
4615 : : struct mlx5_translated_action_handle *handle,
4616 : : int *indir_n,
4617 : : struct rte_flow_action **translated_actions,
4618 : : struct rte_flow_error *error)
4619 : : {
4620 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4621 : : struct rte_flow_action *translated = NULL;
4622 : : size_t actions_size;
4623 : : int n;
4624 : : int copied_n = 0;
4625 : : struct mlx5_translated_action_handle *handle_end = NULL;
4626 : :
4627 [ # # ]: 0 : for (n = 0; actions[n].type != RTE_FLOW_ACTION_TYPE_END; n++) {
4628 [ # # ]: 0 : if (actions[n].type != RTE_FLOW_ACTION_TYPE_INDIRECT)
4629 : 0 : continue;
4630 [ # # ]: 0 : if (copied_n == *indir_n) {
4631 : 0 : return rte_flow_error_set
4632 : : (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_NUM,
4633 : : NULL, "too many shared actions");
4634 : : }
4635 [ # # ]: 0 : rte_memcpy(&handle[copied_n].action, &actions[n].conf,
4636 : : sizeof(actions[n].conf));
4637 : 0 : handle[copied_n].index = n;
4638 : 0 : copied_n++;
4639 : : }
4640 : 0 : n++;
4641 : 0 : *indir_n = copied_n;
4642 [ # # ]: 0 : if (!copied_n)
4643 : : return 0;
4644 : 0 : actions_size = sizeof(struct rte_flow_action) * n;
4645 : 0 : translated = mlx5_malloc(MLX5_MEM_ZERO, actions_size, 0, SOCKET_ID_ANY);
4646 [ # # ]: 0 : if (!translated) {
4647 : 0 : rte_errno = ENOMEM;
4648 : 0 : return -ENOMEM;
4649 : : }
4650 : : memcpy(translated, actions, actions_size);
4651 [ # # ]: 0 : for (handle_end = handle + copied_n; handle < handle_end; handle++) {
4652 : : struct mlx5_shared_action_rss *shared_rss;
4653 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle->action;
4654 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
4655 : 0 : uint32_t idx = act_idx &
4656 : : ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
4657 : :
4658 [ # # # # : 0 : switch (type) {
# # ]
4659 : 0 : case MLX5_INDIRECT_ACTION_TYPE_RSS:
4660 : 0 : shared_rss = mlx5_ipool_get
4661 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
4662 : 0 : translated[handle->index].type =
4663 : : RTE_FLOW_ACTION_TYPE_RSS;
4664 : 0 : translated[handle->index].conf =
4665 : 0 : &shared_rss->origin;
4666 : 0 : break;
4667 : 0 : case MLX5_INDIRECT_ACTION_TYPE_COUNT:
4668 : 0 : translated[handle->index].type =
4669 : : (enum rte_flow_action_type)
4670 : : MLX5_RTE_FLOW_ACTION_TYPE_COUNT;
4671 : 0 : translated[handle->index].conf = (void *)(uintptr_t)idx;
4672 : 0 : break;
4673 : 0 : case MLX5_INDIRECT_ACTION_TYPE_METER_MARK:
4674 : 0 : translated[handle->index].type =
4675 : : (enum rte_flow_action_type)
4676 : : MLX5_RTE_FLOW_ACTION_TYPE_METER_MARK;
4677 : 0 : translated[handle->index].conf = (void *)(uintptr_t)idx;
4678 : 0 : break;
4679 : 0 : case MLX5_INDIRECT_ACTION_TYPE_AGE:
4680 [ # # ]: 0 : if (priv->sh->flow_hit_aso_en) {
4681 : 0 : translated[handle->index].type =
4682 : : (enum rte_flow_action_type)
4683 : : MLX5_RTE_FLOW_ACTION_TYPE_AGE;
4684 : 0 : translated[handle->index].conf =
4685 : 0 : (void *)(uintptr_t)idx;
4686 : 0 : break;
4687 : : }
4688 : : /* Fall-through */
4689 : : case MLX5_INDIRECT_ACTION_TYPE_CT:
4690 [ # # ]: 0 : if (priv->sh->ct_aso_en) {
4691 : 0 : translated[handle->index].type =
4692 : : RTE_FLOW_ACTION_TYPE_CONNTRACK;
4693 : 0 : translated[handle->index].conf =
4694 : 0 : (void *)(uintptr_t)idx;
4695 : 0 : break;
4696 : : }
4697 : : /* Fall-through */
4698 : : default:
4699 : 0 : mlx5_free(translated);
4700 : 0 : return rte_flow_error_set
4701 : : (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
4702 : : NULL, "invalid indirect action type");
4703 : : }
4704 : : }
4705 : 0 : *translated_actions = translated;
4706 : 0 : return 0;
4707 : : }
4708 : :
4709 : : /**
4710 : : * Get Shared RSS action from the action list.
4711 : : *
4712 : : * @param[in] dev
4713 : : * Pointer to Ethernet device.
4714 : : * @param[in] shared
4715 : : * Pointer to the list of actions.
4716 : : * @param[in] shared_n
4717 : : * Actions list length.
4718 : : *
4719 : : * @return
4720 : : * The MLX5 RSS action ID if exists, otherwise return 0.
4721 : : */
4722 : : static uint32_t
4723 : 0 : flow_get_shared_rss_action(struct rte_eth_dev *dev,
4724 : : struct mlx5_translated_action_handle *handle,
4725 : : int shared_n)
4726 : : {
4727 : : struct mlx5_translated_action_handle *handle_end;
4728 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4729 : : struct mlx5_shared_action_rss *shared_rss;
4730 : :
4731 : :
4732 [ # # ]: 0 : for (handle_end = handle + shared_n; handle < handle_end; handle++) {
4733 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle->action;
4734 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
4735 : 0 : uint32_t idx = act_idx &
4736 : : ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
4737 [ # # ]: 0 : switch (type) {
4738 : 0 : case MLX5_INDIRECT_ACTION_TYPE_RSS:
4739 : 0 : shared_rss = mlx5_ipool_get
4740 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
4741 : : idx);
4742 : 0 : rte_atomic_fetch_add_explicit(&shared_rss->refcnt, 1,
4743 : : rte_memory_order_relaxed);
4744 : 0 : return idx;
4745 : : default:
4746 : : break;
4747 : : }
4748 : : }
4749 : : return 0;
4750 : : }
4751 : :
4752 : : static unsigned int
4753 : : find_graph_root(uint32_t rss_level)
4754 : : {
4755 : 0 : return rss_level < 2 ? MLX5_EXPANSION_ROOT :
4756 : : MLX5_EXPANSION_ROOT_OUTER;
4757 : : }
4758 : :
4759 : : /**
4760 : : * Get layer flags from the prefix flow.
4761 : : *
4762 : : * Some flows may be split to several subflows, the prefix subflow gets the
4763 : : * match items and the suffix sub flow gets the actions.
4764 : : * Some actions need the user defined match item flags to get the detail for
4765 : : * the action.
4766 : : * This function helps the suffix flow to get the item layer flags from prefix
4767 : : * subflow.
4768 : : *
4769 : : * @param[in] dev_flow
4770 : : * Pointer the created prefix subflow.
4771 : : *
4772 : : * @return
4773 : : * The layers get from prefix subflow.
4774 : : */
4775 : : static inline uint64_t
4776 : 0 : flow_get_prefix_layer_flags(struct mlx5_flow *dev_flow)
4777 : : {
4778 : : uint64_t layers = 0;
4779 : :
4780 : : /*
4781 : : * Layers bits could be localization, but usually the compiler will
4782 : : * help to do the optimization work for source code.
4783 : : * If no decap actions, use the layers directly.
4784 : : */
4785 [ # # ]: 0 : if (!(dev_flow->act_flags & MLX5_FLOW_ACTION_DECAP))
4786 : 0 : return dev_flow->handle->layers;
4787 : : /* Convert L3 layers with decap action. */
4788 [ # # ]: 0 : if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV4)
4789 : : layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV4;
4790 [ # # ]: 0 : else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV6)
4791 : : layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
4792 : : /* Convert L4 layers with decap action. */
4793 [ # # ]: 0 : if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_TCP)
4794 : 0 : layers |= MLX5_FLOW_LAYER_OUTER_L4_TCP;
4795 [ # # ]: 0 : else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_UDP)
4796 : 0 : layers |= MLX5_FLOW_LAYER_OUTER_L4_UDP;
4797 : : return layers;
4798 : : }
4799 : :
4800 : : /**
4801 : : * Get metadata split action information.
4802 : : *
4803 : : * @param[in] actions
4804 : : * Pointer to the list of actions.
4805 : : * @param[out] qrss
4806 : : * Pointer to the return pointer.
4807 : : * @param[out] qrss_type
4808 : : * Pointer to the action type to return. RTE_FLOW_ACTION_TYPE_END is returned
4809 : : * if no QUEUE/RSS is found.
4810 : : * @param[out] encap_idx
4811 : : * Pointer to the index of the encap action if exists, otherwise the last
4812 : : * action index.
4813 : : *
4814 : : * @return
4815 : : * Total number of actions.
4816 : : */
4817 : : static int
4818 : 0 : flow_parse_metadata_split_actions_info(const struct rte_flow_action actions[],
4819 : : const struct rte_flow_action **qrss,
4820 : : int *encap_idx)
4821 : : {
4822 : : const struct rte_flow_action_raw_encap *raw_encap;
4823 : : int actions_n = 0;
4824 : : int raw_decap_idx = -1;
4825 : :
4826 : 0 : *encap_idx = -1;
4827 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4828 [ # # # # : 0 : switch (actions->type) {
# ]
4829 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4830 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4831 : 0 : *encap_idx = actions_n;
4832 : 0 : break;
4833 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4834 : : raw_decap_idx = actions_n;
4835 : 0 : break;
4836 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4837 : 0 : raw_encap = actions->conf;
4838 [ # # ]: 0 : if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4839 : 0 : *encap_idx = raw_decap_idx != -1 ?
4840 [ # # ]: 0 : raw_decap_idx : actions_n;
4841 : : break;
4842 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
4843 : : case RTE_FLOW_ACTION_TYPE_RSS:
4844 : 0 : *qrss = actions;
4845 : 0 : break;
4846 : : default:
4847 : : break;
4848 : : }
4849 : 0 : actions_n++;
4850 : : }
4851 [ # # ]: 0 : if (*encap_idx == -1)
4852 : 0 : *encap_idx = actions_n;
4853 : : /* Count RTE_FLOW_ACTION_TYPE_END. */
4854 : 0 : return actions_n + 1;
4855 : : }
4856 : :
4857 : : /**
4858 : : * Check if the action will change packet.
4859 : : *
4860 : : * @param dev
4861 : : * Pointer to Ethernet device.
4862 : : * @param[in] type
4863 : : * action type.
4864 : : *
4865 : : * @return
4866 : : * true if action will change packet, false otherwise.
4867 : : */
4868 : 0 : static bool flow_check_modify_action_type(struct rte_eth_dev *dev,
4869 : : enum rte_flow_action_type type)
4870 : : {
4871 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4872 : :
4873 [ # # # ]: 0 : switch (type) {
4874 : : case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
4875 : : case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
4876 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
4877 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
4878 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
4879 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
4880 : : case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
4881 : : case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
4882 : : case RTE_FLOW_ACTION_TYPE_DEC_TTL:
4883 : : case RTE_FLOW_ACTION_TYPE_SET_TTL:
4884 : : case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
4885 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
4886 : : case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
4887 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
4888 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
4889 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
4890 : : case RTE_FLOW_ACTION_TYPE_SET_META:
4891 : : case RTE_FLOW_ACTION_TYPE_SET_TAG:
4892 : : case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
4893 : : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
4894 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
4895 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
4896 : : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
4897 : : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
4898 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
4899 : : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
4900 : : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
4901 : : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
4902 : : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
4903 : : return true;
4904 : 0 : case RTE_FLOW_ACTION_TYPE_FLAG:
4905 : : case RTE_FLOW_ACTION_TYPE_MARK:
4906 [ # # ]: 0 : if (priv->sh->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
4907 : : priv->sh->config.dv_xmeta_en != MLX5_XMETA_MODE_META32_HWS)
4908 : : return true;
4909 : : else
4910 : 0 : return false;
4911 : 0 : default:
4912 : 0 : return false;
4913 : : }
4914 : : }
4915 : :
4916 : : /**
4917 : : * Check meter action from the action list.
4918 : : *
4919 : : * @param dev
4920 : : * Pointer to Ethernet device.
4921 : : * @param[in] actions
4922 : : * Pointer to the list of actions.
4923 : : * @param[out] has_mtr
4924 : : * Pointer to the meter exist flag.
4925 : : * @param[out] has_modify
4926 : : * Pointer to the flag showing there's packet change action.
4927 : : * @param[out] meter_id
4928 : : * Pointer to the meter id.
4929 : : *
4930 : : * @return
4931 : : * Total number of actions.
4932 : : */
4933 : : static int
4934 : 0 : flow_check_meter_action(struct rte_eth_dev *dev,
4935 : : const struct rte_flow_action actions[],
4936 : : bool *has_mtr, bool *has_modify, uint32_t *meter_id)
4937 : : {
4938 : : const struct rte_flow_action_meter *mtr = NULL;
4939 : : int actions_n = 0;
4940 : :
4941 : : MLX5_ASSERT(has_mtr);
4942 : 0 : *has_mtr = false;
4943 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4944 [ # # ]: 0 : switch (actions->type) {
4945 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
4946 : 0 : mtr = actions->conf;
4947 : 0 : *meter_id = mtr->mtr_id;
4948 : 0 : *has_mtr = true;
4949 : 0 : break;
4950 : : default:
4951 : : break;
4952 : : }
4953 [ # # ]: 0 : if (!*has_mtr)
4954 : 0 : *has_modify |= flow_check_modify_action_type(dev,
4955 : 0 : actions->type);
4956 : 0 : actions_n++;
4957 : : }
4958 : : /* Count RTE_FLOW_ACTION_TYPE_END. */
4959 : 0 : return actions_n + 1;
4960 : : }
4961 : :
4962 : : /**
4963 : : * Check if the flow should be split due to hairpin.
4964 : : * The reason for the split is that in current HW we can't
4965 : : * support encap and push-vlan on Rx, so if a flow contains
4966 : : * these actions we move it to Tx.
4967 : : *
4968 : : * @param dev
4969 : : * Pointer to Ethernet device.
4970 : : * @param[in] attr
4971 : : * Flow rule attributes.
4972 : : * @param[in] actions
4973 : : * Associated actions (list terminated by the END action).
4974 : : *
4975 : : * @return
4976 : : * > 0 the number of actions and the flow should be split,
4977 : : * 0 when no split required.
4978 : : */
4979 : : static int
4980 : 0 : flow_check_hairpin_split(struct rte_eth_dev *dev,
4981 : : const struct rte_flow_attr *attr,
4982 : : const struct rte_flow_action actions[])
4983 : : {
4984 : : int queue_action = 0;
4985 : : int action_n = 0;
4986 : : int split = 0;
4987 : : int push_vlan = 0;
4988 : : const struct rte_flow_action_queue *queue;
4989 : : const struct rte_flow_action_rss *rss;
4990 : : const struct rte_flow_action_raw_encap *raw_encap;
4991 : : const struct rte_eth_hairpin_conf *conf;
4992 : :
4993 [ # # ]: 0 : if (!attr->ingress)
4994 : : return 0;
4995 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
4996 [ # # ]: 0 : if (actions->type == RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN)
4997 : : push_vlan = 1;
4998 [ # # # # : 0 : switch (actions->type) {
# # ]
4999 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
5000 : 0 : queue = actions->conf;
5001 [ # # ]: 0 : if (queue == NULL)
5002 : : return 0;
5003 : 0 : conf = mlx5_rxq_get_hairpin_conf(dev, queue->index);
5004 [ # # # # ]: 0 : if (conf == NULL || conf->tx_explicit != 0)
5005 : : return 0;
5006 : : queue_action = 1;
5007 : 0 : action_n++;
5008 : 0 : break;
5009 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
5010 : 0 : rss = actions->conf;
5011 [ # # # # ]: 0 : if (rss == NULL || rss->queue_num == 0)
5012 : : return 0;
5013 : 0 : conf = mlx5_rxq_get_hairpin_conf(dev, rss->queue[0]);
5014 [ # # # # ]: 0 : if (conf == NULL || conf->tx_explicit != 0)
5015 : : return 0;
5016 : : queue_action = 1;
5017 : 0 : action_n++;
5018 : 0 : break;
5019 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
5020 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
5021 : : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
5022 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
5023 : 0 : split++;
5024 : 0 : action_n++;
5025 : 0 : break;
5026 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
5027 [ # # ]: 0 : if (push_vlan)
5028 : 0 : split++;
5029 : 0 : action_n++;
5030 : 0 : break;
5031 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
5032 : 0 : raw_encap = actions->conf;
5033 [ # # ]: 0 : if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
5034 : 0 : split++;
5035 : 0 : action_n++;
5036 : 0 : break;
5037 : 0 : default:
5038 : 0 : action_n++;
5039 : 0 : break;
5040 : : }
5041 : : }
5042 [ # # ]: 0 : if (split && queue_action)
5043 : 0 : return action_n;
5044 : : return 0;
5045 : : }
5046 : :
5047 : : int
5048 : 0 : mlx5_flow_dv_mreg_match_cb(void *tool_ctx __rte_unused,
5049 : : struct mlx5_list_entry *entry, void *cb_ctx)
5050 : : {
5051 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
5052 : : struct mlx5_flow_mreg_copy_resource *mcp_res =
5053 : : container_of(entry, typeof(*mcp_res), hlist_ent);
5054 : :
5055 : 0 : return mcp_res->mark_id != *(uint32_t *)(ctx->data);
5056 : : }
5057 : :
5058 : : struct mlx5_list_entry *
5059 : 0 : mlx5_flow_dv_mreg_create_cb(void *tool_ctx, void *cb_ctx)
5060 : : {
5061 : : struct rte_eth_dev *dev = tool_ctx;
5062 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5063 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
5064 : : struct mlx5_flow_mreg_copy_resource *mcp_res;
5065 : 0 : struct rte_flow_error *error = ctx->error;
5066 : 0 : uint32_t idx = 0;
5067 : : int ret;
5068 : 0 : uint32_t mark_id = *(uint32_t *)(ctx->data);
5069 : 0 : struct rte_flow_attr attr = {
5070 : : .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
5071 : : .ingress = 1,
5072 : : };
5073 : 0 : struct mlx5_rte_flow_item_tag tag_spec = {
5074 : : .data = mark_id,
5075 : : };
5076 : 0 : struct rte_flow_item items[] = {
5077 : : [1] = { .type = RTE_FLOW_ITEM_TYPE_END, },
5078 : : };
5079 : 0 : struct rte_flow_action_mark ftag = {
5080 : : .id = mark_id,
5081 : : };
5082 : 0 : struct mlx5_flow_action_copy_mreg cp_mreg = {
5083 : : .dst = REG_B,
5084 : : .src = REG_NON,
5085 : : };
5086 : 0 : struct rte_flow_action_jump jump = {
5087 : : .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
5088 : : };
5089 : 0 : struct rte_flow_action actions[] = {
5090 : : [3] = { .type = RTE_FLOW_ACTION_TYPE_END, },
5091 : : };
5092 : :
5093 : : /* Fill the register fields in the flow. */
5094 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
5095 [ # # ]: 0 : if (ret < 0)
5096 : : return NULL;
5097 : 0 : tag_spec.id = ret;
5098 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
5099 [ # # ]: 0 : if (ret < 0)
5100 : : return NULL;
5101 : 0 : cp_mreg.src = ret;
5102 : : /* Provide the full width of FLAG specific value. */
5103 [ # # ]: 0 : if (mark_id == (priv->sh->dv_regc0_mask & MLX5_FLOW_MARK_DEFAULT))
5104 : 0 : tag_spec.data = MLX5_FLOW_MARK_DEFAULT;
5105 : : /* Build a new flow. */
5106 [ # # ]: 0 : if (mark_id != MLX5_DEFAULT_COPY_ID) {
5107 : 0 : items[0] = (struct rte_flow_item){
5108 : : .type = (enum rte_flow_item_type)
5109 : : MLX5_RTE_FLOW_ITEM_TYPE_TAG,
5110 : : .spec = &tag_spec,
5111 : : };
5112 : 0 : items[1] = (struct rte_flow_item){
5113 : : .type = RTE_FLOW_ITEM_TYPE_END,
5114 : : };
5115 : 0 : actions[0] = (struct rte_flow_action){
5116 : : .type = (enum rte_flow_action_type)
5117 : : MLX5_RTE_FLOW_ACTION_TYPE_MARK,
5118 : : .conf = &ftag,
5119 : : };
5120 : 0 : actions[1] = (struct rte_flow_action){
5121 : : .type = (enum rte_flow_action_type)
5122 : : MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5123 : : .conf = &cp_mreg,
5124 : : };
5125 : 0 : actions[2] = (struct rte_flow_action){
5126 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
5127 : : .conf = &jump,
5128 : : };
5129 : 0 : actions[3] = (struct rte_flow_action){
5130 : : .type = RTE_FLOW_ACTION_TYPE_END,
5131 : : };
5132 : : } else {
5133 : : /* Default rule, wildcard match. */
5134 : 0 : attr.priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR;
5135 : 0 : items[0] = (struct rte_flow_item){
5136 : : .type = RTE_FLOW_ITEM_TYPE_END,
5137 : : };
5138 : 0 : actions[0] = (struct rte_flow_action){
5139 : : .type = (enum rte_flow_action_type)
5140 : : MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
5141 : : .conf = &cp_mreg,
5142 : : };
5143 : 0 : actions[1] = (struct rte_flow_action){
5144 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
5145 : : .conf = &jump,
5146 : : };
5147 : 0 : actions[2] = (struct rte_flow_action){
5148 : : .type = RTE_FLOW_ACTION_TYPE_END,
5149 : : };
5150 : : }
5151 : : /* Build a new entry. */
5152 : 0 : mcp_res = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
5153 [ # # ]: 0 : if (!mcp_res) {
5154 : 0 : rte_errno = ENOMEM;
5155 : 0 : return NULL;
5156 : : }
5157 : 0 : mcp_res->idx = idx;
5158 : 0 : mcp_res->mark_id = mark_id;
5159 : : /*
5160 : : * The copy Flows are not included in any list. There
5161 : : * ones are referenced from other Flows and can not
5162 : : * be applied, removed, deleted in arbitrary order
5163 : : * by list traversing.
5164 : : */
5165 : 0 : mcp_res->rix_flow = mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_MCP,
5166 : : &attr, items, actions, false, error);
5167 [ # # ]: 0 : if (!mcp_res->rix_flow) {
5168 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], idx);
5169 : 0 : return NULL;
5170 : : }
5171 : 0 : return &mcp_res->hlist_ent;
5172 : : }
5173 : :
5174 : : struct mlx5_list_entry *
5175 : 0 : mlx5_flow_dv_mreg_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
5176 : : void *cb_ctx __rte_unused)
5177 : : {
5178 : : struct rte_eth_dev *dev = tool_ctx;
5179 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5180 : : struct mlx5_flow_mreg_copy_resource *mcp_res;
5181 : 0 : uint32_t idx = 0;
5182 : :
5183 : 0 : mcp_res = mlx5_ipool_malloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
5184 [ # # ]: 0 : if (!mcp_res) {
5185 : 0 : rte_errno = ENOMEM;
5186 : 0 : return NULL;
5187 : : }
5188 : : memcpy(mcp_res, oentry, sizeof(*mcp_res));
5189 : 0 : mcp_res->idx = idx;
5190 : 0 : return &mcp_res->hlist_ent;
5191 : : }
5192 : :
5193 : : void
5194 : 0 : mlx5_flow_dv_mreg_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
5195 : : {
5196 : : struct mlx5_flow_mreg_copy_resource *mcp_res =
5197 : : container_of(entry, typeof(*mcp_res), hlist_ent);
5198 : : struct rte_eth_dev *dev = tool_ctx;
5199 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5200 : :
5201 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
5202 : 0 : }
5203 : :
5204 : : /**
5205 : : * Add a flow of copying flow metadata registers in RX_CP_TBL.
5206 : : *
5207 : : * As mark_id is unique, if there's already a registered flow for the mark_id,
5208 : : * return by increasing the reference counter of the resource. Otherwise, create
5209 : : * the resource (mcp_res) and flow.
5210 : : *
5211 : : * Flow looks like,
5212 : : * - If ingress port is ANY and reg_c[1] is mark_id,
5213 : : * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
5214 : : *
5215 : : * For default flow (zero mark_id), flow is like,
5216 : : * - If ingress port is ANY,
5217 : : * reg_b := reg_c[0] and jump to RX_ACT_TBL.
5218 : : *
5219 : : * @param dev
5220 : : * Pointer to Ethernet device.
5221 : : * @param mark_id
5222 : : * ID of MARK action, zero means default flow for META.
5223 : : * @param[out] error
5224 : : * Perform verbose error reporting if not NULL.
5225 : : *
5226 : : * @return
5227 : : * Associated resource on success, NULL otherwise and rte_errno is set.
5228 : : */
5229 : : static struct mlx5_flow_mreg_copy_resource *
5230 : 0 : flow_mreg_add_copy_action(struct rte_eth_dev *dev, uint32_t mark_id,
5231 : : struct rte_flow_error *error)
5232 : : {
5233 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5234 : : struct mlx5_list_entry *entry;
5235 : 0 : struct mlx5_flow_cb_ctx ctx = {
5236 : : .dev = dev,
5237 : : .error = error,
5238 : : .data = &mark_id,
5239 : : };
5240 : :
5241 : : /* Check if already registered. */
5242 : : MLX5_ASSERT(priv->sh->mreg_cp_tbl);
5243 : 0 : entry = mlx5_hlist_register(priv->sh->mreg_cp_tbl, mark_id, &ctx);
5244 [ # # ]: 0 : if (!entry)
5245 : 0 : return NULL;
5246 : : return container_of(entry, struct mlx5_flow_mreg_copy_resource,
5247 : : hlist_ent);
5248 : : }
5249 : :
5250 : : void
5251 : 0 : mlx5_flow_dv_mreg_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
5252 : : {
5253 : : struct mlx5_flow_mreg_copy_resource *mcp_res =
5254 : : container_of(entry, typeof(*mcp_res), hlist_ent);
5255 : : struct rte_eth_dev *dev = tool_ctx;
5256 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5257 : :
5258 : : MLX5_ASSERT(mcp_res->rix_flow);
5259 : 0 : mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_MCP, mcp_res->rix_flow);
5260 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
5261 : 0 : }
5262 : :
5263 : : /**
5264 : : * Release flow in RX_CP_TBL.
5265 : : *
5266 : : * @param dev
5267 : : * Pointer to Ethernet device.
5268 : : * @flow
5269 : : * Parent flow for wich copying is provided.
5270 : : */
5271 : : static void
5272 : 0 : flow_mreg_del_copy_action(struct rte_eth_dev *dev,
5273 : : struct rte_flow *flow)
5274 : : {
5275 : : struct mlx5_flow_mreg_copy_resource *mcp_res;
5276 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5277 : :
5278 [ # # ]: 0 : if (!flow->rix_mreg_copy)
5279 : : return;
5280 : 0 : mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
5281 : : flow->rix_mreg_copy);
5282 [ # # # # ]: 0 : if (!mcp_res || !priv->sh->mreg_cp_tbl)
5283 : : return;
5284 : : MLX5_ASSERT(mcp_res->rix_flow);
5285 : 0 : mlx5_hlist_unregister(priv->sh->mreg_cp_tbl, &mcp_res->hlist_ent);
5286 : 0 : flow->rix_mreg_copy = 0;
5287 : : }
5288 : :
5289 : : /**
5290 : : * Remove the default copy action from RX_CP_TBL.
5291 : : *
5292 : : * This functions is called in the mlx5_dev_start(). No thread safe
5293 : : * is guaranteed.
5294 : : *
5295 : : * @param dev
5296 : : * Pointer to Ethernet device.
5297 : : */
5298 : : static void
5299 : 0 : flow_mreg_del_default_copy_action(struct rte_eth_dev *dev)
5300 : : {
5301 : : struct mlx5_list_entry *entry;
5302 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5303 : : struct mlx5_flow_cb_ctx ctx;
5304 : : uint32_t mark_id;
5305 : :
5306 : : /* Check if default flow is registered. */
5307 [ # # ]: 0 : if (!priv->sh->mreg_cp_tbl)
5308 : 0 : return;
5309 : 0 : mark_id = MLX5_DEFAULT_COPY_ID;
5310 : 0 : ctx.data = &mark_id;
5311 : 0 : entry = mlx5_hlist_lookup(priv->sh->mreg_cp_tbl, mark_id, &ctx);
5312 [ # # ]: 0 : if (!entry)
5313 : : return;
5314 : 0 : mlx5_hlist_unregister(priv->sh->mreg_cp_tbl, entry);
5315 : : }
5316 : :
5317 : : /**
5318 : : * Add the default copy action in RX_CP_TBL.
5319 : : *
5320 : : * This functions is called in the mlx5_dev_start(). No thread safe
5321 : : * is guaranteed.
5322 : : *
5323 : : * @param dev
5324 : : * Pointer to Ethernet device.
5325 : : * @param[out] error
5326 : : * Perform verbose error reporting if not NULL.
5327 : : *
5328 : : * @return
5329 : : * 0 for success, negative value otherwise and rte_errno is set.
5330 : : */
5331 : : static int
5332 : 0 : flow_mreg_add_default_copy_action(struct rte_eth_dev *dev,
5333 : : struct rte_flow_error *error)
5334 : : {
5335 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5336 : : struct mlx5_flow_mreg_copy_resource *mcp_res;
5337 : : struct mlx5_flow_cb_ctx ctx;
5338 : : uint32_t mark_id;
5339 : :
5340 : : /* Check whether extensive metadata feature is engaged. */
5341 [ # # ]: 0 : if (!priv->sh->config.dv_flow_en ||
5342 [ # # # # ]: 0 : priv->sh->config.dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
5343 : 0 : !mlx5_flow_ext_mreg_supported(dev) ||
5344 [ # # ]: 0 : !priv->sh->dv_regc0_mask)
5345 : 0 : return 0;
5346 : : /*
5347 : : * Add default mreg copy flow may be called multiple time, but
5348 : : * only be called once in stop. Avoid register it twice.
5349 : : */
5350 : 0 : mark_id = MLX5_DEFAULT_COPY_ID;
5351 : 0 : ctx.data = &mark_id;
5352 [ # # ]: 0 : if (mlx5_hlist_lookup(priv->sh->mreg_cp_tbl, mark_id, &ctx))
5353 : : return 0;
5354 : 0 : mcp_res = flow_mreg_add_copy_action(dev, mark_id, error);
5355 [ # # ]: 0 : if (!mcp_res)
5356 : 0 : return -rte_errno;
5357 : : return 0;
5358 : : }
5359 : :
5360 : : /**
5361 : : * Add a flow of copying flow metadata registers in RX_CP_TBL.
5362 : : *
5363 : : * All the flow having Q/RSS action should be split by
5364 : : * flow_mreg_split_qrss_prep() to pass by RX_CP_TBL. A flow in the RX_CP_TBL
5365 : : * performs the following,
5366 : : * - CQE->flow_tag := reg_c[1] (MARK)
5367 : : * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
5368 : : * As CQE's flow_tag is not a register, it can't be simply copied from reg_c[1]
5369 : : * but there should be a flow per each MARK ID set by MARK action.
5370 : : *
5371 : : * For the aforementioned reason, if there's a MARK action in flow's action
5372 : : * list, a corresponding flow should be added to the RX_CP_TBL in order to copy
5373 : : * the MARK ID to CQE's flow_tag like,
5374 : : * - If reg_c[1] is mark_id,
5375 : : * flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
5376 : : *
5377 : : * For SET_META action which stores value in reg_c[0], as the destination is
5378 : : * also a flow metadata register (reg_b), adding a default flow is enough. Zero
5379 : : * MARK ID means the default flow. The default flow looks like,
5380 : : * - For all flow, reg_b := reg_c[0] and jump to RX_ACT_TBL.
5381 : : *
5382 : : * @param dev
5383 : : * Pointer to Ethernet device.
5384 : : * @param flow
5385 : : * Pointer to flow structure.
5386 : : * @param[in] actions
5387 : : * Pointer to the list of actions.
5388 : : * @param[out] error
5389 : : * Perform verbose error reporting if not NULL.
5390 : : *
5391 : : * @return
5392 : : * 0 on success, negative value otherwise and rte_errno is set.
5393 : : */
5394 : : static int
5395 : 0 : flow_mreg_update_copy_table(struct rte_eth_dev *dev,
5396 : : struct rte_flow *flow,
5397 : : const struct rte_flow_action *actions,
5398 : : struct rte_flow_error *error)
5399 : : {
5400 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5401 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
5402 : : struct mlx5_flow_mreg_copy_resource *mcp_res;
5403 : : const struct rte_flow_action_mark *mark;
5404 : :
5405 : : /* Check whether extensive metadata feature is engaged. */
5406 [ # # ]: 0 : if (!config->dv_flow_en ||
5407 [ # # # # ]: 0 : config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
5408 : 0 : !mlx5_flow_ext_mreg_supported(dev) ||
5409 [ # # ]: 0 : !priv->sh->dv_regc0_mask)
5410 : 0 : return 0;
5411 : : /* Find MARK action. */
5412 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
5413 [ # # # ]: 0 : switch (actions->type) {
5414 : 0 : case RTE_FLOW_ACTION_TYPE_FLAG:
5415 : 0 : mcp_res = flow_mreg_add_copy_action
5416 : : (dev, MLX5_FLOW_MARK_DEFAULT, error);
5417 [ # # ]: 0 : if (!mcp_res)
5418 : 0 : return -rte_errno;
5419 : 0 : flow->rix_mreg_copy = mcp_res->idx;
5420 : 0 : return 0;
5421 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
5422 : 0 : mark = (const struct rte_flow_action_mark *)
5423 : : actions->conf;
5424 : : mcp_res =
5425 : 0 : flow_mreg_add_copy_action(dev, mark->id, error);
5426 [ # # ]: 0 : if (!mcp_res)
5427 : 0 : return -rte_errno;
5428 : 0 : flow->rix_mreg_copy = mcp_res->idx;
5429 : 0 : return 0;
5430 : : default:
5431 : : break;
5432 : : }
5433 : : }
5434 : : return 0;
5435 : : }
5436 : :
5437 : : #define MLX5_MAX_SPLIT_ACTIONS 24
5438 : : #define MLX5_MAX_SPLIT_ITEMS 24
5439 : :
5440 : : /**
5441 : : * Split the hairpin flow.
5442 : : * Since HW can't support encap and push-vlan on Rx, we move these
5443 : : * actions to Tx.
5444 : : * If the count action is after the encap then we also
5445 : : * move the count action. in this case the count will also measure
5446 : : * the outer bytes.
5447 : : *
5448 : : * @param dev
5449 : : * Pointer to Ethernet device.
5450 : : * @param[in] actions
5451 : : * Associated actions (list terminated by the END action).
5452 : : * @param[out] actions_rx
5453 : : * Rx flow actions.
5454 : : * @param[out] actions_tx
5455 : : * Tx flow actions..
5456 : : * @param[out] pattern_tx
5457 : : * The pattern items for the Tx flow.
5458 : : * @param[out] flow_id
5459 : : * The flow ID connected to this flow.
5460 : : *
5461 : : * @return
5462 : : * 0 on success.
5463 : : */
5464 : : static int
5465 : 0 : flow_hairpin_split(struct rte_eth_dev *dev,
5466 : : const struct rte_flow_action actions[],
5467 : : struct rte_flow_action actions_rx[],
5468 : : struct rte_flow_action actions_tx[],
5469 : : struct rte_flow_item pattern_tx[],
5470 : : uint32_t flow_id)
5471 : : {
5472 : : const struct rte_flow_action_raw_encap *raw_encap;
5473 : : const struct rte_flow_action_raw_decap *raw_decap;
5474 : : struct mlx5_rte_flow_action_set_tag *set_tag;
5475 : : struct rte_flow_action *tag_action;
5476 : : struct mlx5_rte_flow_item_tag *tag_item;
5477 : : struct rte_flow_item *item;
5478 : : char *addr;
5479 : : int push_vlan = 0;
5480 : : int encap = 0;
5481 : :
5482 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
5483 [ # # ]: 0 : if (actions->type == RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN)
5484 : : push_vlan = 1;
5485 [ # # # # : 0 : switch (actions->type) {
# # ]
5486 : : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
5487 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
5488 : : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
5489 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
5490 : : rte_memcpy(actions_tx, actions,
5491 : : sizeof(struct rte_flow_action));
5492 : 0 : actions_tx++;
5493 : 0 : break;
5494 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
5495 [ # # ]: 0 : if (push_vlan) {
5496 : : rte_memcpy(actions_tx, actions,
5497 : : sizeof(struct rte_flow_action));
5498 : 0 : actions_tx++;
5499 : : } else {
5500 : : rte_memcpy(actions_rx, actions,
5501 : : sizeof(struct rte_flow_action));
5502 : 0 : actions_rx++;
5503 : : }
5504 : : break;
5505 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
5506 : : case RTE_FLOW_ACTION_TYPE_AGE:
5507 [ # # ]: 0 : if (encap) {
5508 : : rte_memcpy(actions_tx, actions,
5509 : : sizeof(struct rte_flow_action));
5510 : 0 : actions_tx++;
5511 : : } else {
5512 : : rte_memcpy(actions_rx, actions,
5513 : : sizeof(struct rte_flow_action));
5514 : 0 : actions_rx++;
5515 : : }
5516 : : break;
5517 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
5518 : 0 : raw_encap = actions->conf;
5519 [ # # ]: 0 : if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE) {
5520 : : memcpy(actions_tx, actions,
5521 : : sizeof(struct rte_flow_action));
5522 : 0 : actions_tx++;
5523 : : encap = 1;
5524 : : } else {
5525 : : rte_memcpy(actions_rx, actions,
5526 : : sizeof(struct rte_flow_action));
5527 : 0 : actions_rx++;
5528 : : }
5529 : : break;
5530 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
5531 : 0 : raw_decap = actions->conf;
5532 [ # # ]: 0 : if (raw_decap->size < MLX5_ENCAPSULATION_DECISION_SIZE) {
5533 : : memcpy(actions_tx, actions,
5534 : : sizeof(struct rte_flow_action));
5535 : 0 : actions_tx++;
5536 : : } else {
5537 : : rte_memcpy(actions_rx, actions,
5538 : : sizeof(struct rte_flow_action));
5539 : 0 : actions_rx++;
5540 : : }
5541 : : break;
5542 : : default:
5543 : : rte_memcpy(actions_rx, actions,
5544 : : sizeof(struct rte_flow_action));
5545 : 0 : actions_rx++;
5546 : 0 : break;
5547 : : }
5548 : : }
5549 : : /* Add set meta action and end action for the Rx flow. */
5550 : : tag_action = actions_rx;
5551 : 0 : tag_action->type = (enum rte_flow_action_type)
5552 : : MLX5_RTE_FLOW_ACTION_TYPE_TAG;
5553 [ # # ]: 0 : actions_rx++;
5554 : : rte_memcpy(actions_rx, actions, sizeof(struct rte_flow_action));
5555 : 0 : actions_rx++;
5556 : : set_tag = (void *)actions_rx;
5557 : 0 : *set_tag = (struct mlx5_rte_flow_action_set_tag) {
5558 : 0 : .id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_RX, 0, NULL),
5559 : : .data = flow_id,
5560 : : };
5561 : : MLX5_ASSERT(set_tag->id > REG_NON);
5562 [ # # ]: 0 : tag_action->conf = set_tag;
5563 : : /* Create Tx item list. */
5564 : : rte_memcpy(actions_tx, actions, sizeof(struct rte_flow_action));
5565 : 0 : addr = (void *)&pattern_tx[2];
5566 : : item = pattern_tx;
5567 : 0 : item->type = (enum rte_flow_item_type)
5568 : : MLX5_RTE_FLOW_ITEM_TYPE_TAG;
5569 : : tag_item = (void *)addr;
5570 : 0 : tag_item->data = flow_id;
5571 : 0 : tag_item->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_TX, 0, NULL);
5572 : : MLX5_ASSERT(set_tag->id > REG_NON);
5573 : 0 : item->spec = tag_item;
5574 : 0 : addr += sizeof(struct mlx5_rte_flow_item_tag);
5575 : : tag_item = (void *)addr;
5576 : 0 : tag_item->data = UINT32_MAX;
5577 : 0 : tag_item->id = UINT16_MAX;
5578 : 0 : item->mask = tag_item;
5579 : 0 : item->last = NULL;
5580 : : item++;
5581 : 0 : item->type = RTE_FLOW_ITEM_TYPE_END;
5582 : 0 : return 0;
5583 : : }
5584 : :
5585 : : /**
5586 : : * The last stage of splitting chain, just creates the subflow
5587 : : * without any modification.
5588 : : *
5589 : : * @param[in] dev
5590 : : * Pointer to Ethernet device.
5591 : : * @param[in] flow
5592 : : * Parent flow structure pointer.
5593 : : * @param[in, out] sub_flow
5594 : : * Pointer to return the created subflow, may be NULL.
5595 : : * @param[in] attr
5596 : : * Flow rule attributes.
5597 : : * @param[in] items
5598 : : * Pattern specification (list terminated by the END pattern item).
5599 : : * @param[in] actions
5600 : : * Associated actions (list terminated by the END action).
5601 : : * @param[in] flow_split_info
5602 : : * Pointer to flow split info structure.
5603 : : * @param[out] error
5604 : : * Perform verbose error reporting if not NULL.
5605 : : * @return
5606 : : * 0 on success, negative value otherwise
5607 : : */
5608 : : static int
5609 : 0 : flow_create_split_inner(struct rte_eth_dev *dev,
5610 : : struct rte_flow *flow,
5611 : : struct mlx5_flow **sub_flow,
5612 : : const struct rte_flow_attr *attr,
5613 : : const struct rte_flow_item items[],
5614 : : const struct rte_flow_action actions[],
5615 : : struct mlx5_flow_split_info *flow_split_info,
5616 : : struct rte_flow_error *error)
5617 : : {
5618 : : struct mlx5_flow *dev_flow;
5619 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
5620 : :
5621 : 0 : dev_flow = flow_drv_prepare(dev, flow, attr, items, actions,
5622 : : flow_split_info->flow_idx, error);
5623 [ # # ]: 0 : if (!dev_flow)
5624 : 0 : return -rte_errno;
5625 : 0 : dev_flow->flow = flow;
5626 : 0 : dev_flow->external = flow_split_info->external;
5627 : 0 : dev_flow->skip_scale = flow_split_info->skip_scale;
5628 : : /* Subflow object was created, we must include one in the list. */
5629 : 0 : SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
5630 : : dev_flow->handle, next);
5631 : : /*
5632 : : * If dev_flow is as one of the suffix flow, some actions in suffix
5633 : : * flow may need some user defined item layer flags, and pass the
5634 : : * Metadata rxq mark flag to suffix flow as well.
5635 : : */
5636 [ # # ]: 0 : if (flow_split_info->prefix_layers)
5637 : 0 : dev_flow->handle->layers = flow_split_info->prefix_layers;
5638 [ # # ]: 0 : if (flow_split_info->prefix_mark) {
5639 : : MLX5_ASSERT(wks);
5640 : 0 : wks->mark = 1;
5641 : : }
5642 [ # # ]: 0 : if (sub_flow)
5643 : 0 : *sub_flow = dev_flow;
5644 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
5645 : 0 : dev_flow->dv.table_id = flow_split_info->table_id;
5646 : : #endif
5647 : 0 : return flow_drv_translate(dev, dev_flow, attr, items, actions, error);
5648 : : }
5649 : :
5650 : : /**
5651 : : * Get the sub policy of a meter.
5652 : : *
5653 : : * @param[in] dev
5654 : : * Pointer to Ethernet device.
5655 : : * @param[in] flow
5656 : : * Parent flow structure pointer.
5657 : : * @param wks
5658 : : * Pointer to thread flow work space.
5659 : : * @param[in] attr
5660 : : * Flow rule attributes.
5661 : : * @param[in] items
5662 : : * Pattern specification (list terminated by the END pattern item).
5663 : : * @param[out] error
5664 : : * Perform verbose error reporting if not NULL.
5665 : : *
5666 : : * @return
5667 : : * Pointer to the meter sub policy, NULL otherwise and rte_errno is set.
5668 : : */
5669 : : static struct mlx5_flow_meter_sub_policy *
5670 : 0 : get_meter_sub_policy(struct rte_eth_dev *dev,
5671 : : struct rte_flow *flow,
5672 : : struct mlx5_flow_workspace *wks,
5673 : : const struct rte_flow_attr *attr,
5674 : : const struct rte_flow_item items[],
5675 : : struct rte_flow_error *error)
5676 : : {
5677 : : struct mlx5_flow_meter_policy *policy;
5678 : : struct mlx5_flow_meter_policy *final_policy;
5679 : : struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
5680 : :
5681 : 0 : policy = wks->policy;
5682 [ # # ]: 0 : final_policy = policy->is_hierarchy ? wks->final_policy : policy;
5683 [ # # ]: 0 : if (final_policy->is_rss || final_policy->is_queue) {
5684 : : struct mlx5_flow_rss_desc rss_desc_v[MLX5_MTR_RTE_COLORS];
5685 : 0 : struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS] = {0};
5686 : : uint32_t i;
5687 : :
5688 : : /*
5689 : : * This is a tmp dev_flow,
5690 : : * no need to register any matcher for it in translate.
5691 : : */
5692 : 0 : wks->skip_matcher_reg = 1;
5693 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
5694 : 0 : struct mlx5_flow dev_flow = {0};
5695 : 0 : struct mlx5_flow_handle dev_handle = { {0} };
5696 : 0 : uint8_t fate = final_policy->act_cnt[i].fate_action;
5697 : :
5698 [ # # ]: 0 : if (fate == MLX5_FLOW_FATE_SHARED_RSS) {
5699 : 0 : const struct rte_flow_action_rss *rss_act =
5700 : 0 : final_policy->act_cnt[i].rss->conf;
5701 : 0 : struct rte_flow_action rss_actions[2] = {
5702 : : [0] = {
5703 : : .type = RTE_FLOW_ACTION_TYPE_RSS,
5704 : : .conf = rss_act,
5705 : : },
5706 : : [1] = {
5707 : : .type = RTE_FLOW_ACTION_TYPE_END,
5708 : : .conf = NULL,
5709 : : }
5710 : : };
5711 : :
5712 : 0 : dev_flow.handle = &dev_handle;
5713 : 0 : dev_flow.ingress = attr->ingress;
5714 : 0 : dev_flow.flow = flow;
5715 : : dev_flow.external = 0;
5716 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
5717 : 0 : dev_flow.dv.transfer = attr->transfer;
5718 : : #endif
5719 : : /**
5720 : : * Translate RSS action to get rss hash fields.
5721 : : */
5722 [ # # ]: 0 : if (flow_drv_translate(dev, &dev_flow, attr,
5723 : : items, rss_actions, error))
5724 : 0 : goto exit;
5725 : 0 : rss_desc_v[i] = wks->rss_desc;
5726 : 0 : rss_desc_v[i].symmetric_hash_function =
5727 : 0 : dev_flow.symmetric_hash_function;
5728 : 0 : rss_desc_v[i].key_len = MLX5_RSS_HASH_KEY_LEN;
5729 : 0 : rss_desc_v[i].hash_fields =
5730 : 0 : dev_flow.hash_fields;
5731 : 0 : rss_desc_v[i].queue_num =
5732 : : rss_desc_v[i].hash_fields ?
5733 [ # # ]: 0 : rss_desc_v[i].queue_num : 1;
5734 : 0 : rss_desc_v[i].tunnel =
5735 : 0 : !!(dev_flow.handle->layers &
5736 : : MLX5_FLOW_LAYER_TUNNEL);
5737 : : /* Use the RSS queues in the containers. */
5738 : 0 : rss_desc_v[i].queue =
5739 : 0 : (uint16_t *)(uintptr_t)rss_act->queue;
5740 : 0 : rss_desc[i] = &rss_desc_v[i];
5741 [ # # ]: 0 : } else if (fate == MLX5_FLOW_FATE_QUEUE) {
5742 : : /* This is queue action. */
5743 : 0 : rss_desc_v[i] = wks->rss_desc;
5744 : 0 : rss_desc_v[i].key_len = 0;
5745 : 0 : rss_desc_v[i].hash_fields = 0;
5746 : 0 : rss_desc_v[i].queue =
5747 : 0 : &final_policy->act_cnt[i].queue;
5748 : 0 : rss_desc_v[i].queue_num = 1;
5749 : 0 : rss_desc[i] = &rss_desc_v[i];
5750 : : } else {
5751 : 0 : rss_desc[i] = NULL;
5752 : : }
5753 : : }
5754 : : sub_policy = flow_drv_meter_sub_policy_rss_prepare(dev,
5755 : : flow, policy, rss_desc);
5756 : : } else {
5757 : : enum mlx5_meter_domain mtr_domain =
5758 [ # # ]: 0 : attr->transfer ? MLX5_MTR_DOMAIN_TRANSFER :
5759 : 0 : (attr->egress ? MLX5_MTR_DOMAIN_EGRESS :
5760 : : MLX5_MTR_DOMAIN_INGRESS);
5761 : 0 : sub_policy = policy->sub_policys[mtr_domain][0];
5762 : : }
5763 [ # # ]: 0 : if (!sub_policy)
5764 : 0 : rte_flow_error_set(error, EINVAL,
5765 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5766 : : "Failed to get meter sub-policy.");
5767 : 0 : exit:
5768 : 0 : return sub_policy;
5769 : : }
5770 : :
5771 : : /**
5772 : : * Split the meter flow.
5773 : : *
5774 : : * As meter flow will split to three sub flow, other than meter
5775 : : * action, the other actions make sense to only meter accepts
5776 : : * the packet. If it need to be dropped, no other additional
5777 : : * actions should be take.
5778 : : *
5779 : : * One kind of special action which decapsulates the L3 tunnel
5780 : : * header will be in the prefix sub flow, as not to take the
5781 : : * L3 tunnel header into account.
5782 : : *
5783 : : * @param[in] dev
5784 : : * Pointer to Ethernet device.
5785 : : * @param[in] flow
5786 : : * Parent flow structure pointer.
5787 : : * @param wks
5788 : : * Pointer to thread flow work space.
5789 : : * @param[in] attr
5790 : : * Flow rule attributes.
5791 : : * @param[in] items
5792 : : * Pattern specification (list terminated by the END pattern item).
5793 : : * @param[out] sfx_items
5794 : : * Suffix flow match items (list terminated by the END pattern item).
5795 : : * @param[in] actions
5796 : : * Associated actions (list terminated by the END action).
5797 : : * @param[out] actions_sfx
5798 : : * Suffix flow actions.
5799 : : * @param[out] actions_pre
5800 : : * Prefix flow actions.
5801 : : * @param[out] mtr_flow_id
5802 : : * Pointer to meter flow id.
5803 : : * @param[out] error
5804 : : * Perform verbose error reporting if not NULL.
5805 : : *
5806 : : * @return
5807 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5808 : : */
5809 : : static int
5810 : 0 : flow_meter_split_prep(struct rte_eth_dev *dev,
5811 : : struct rte_flow *flow,
5812 : : struct mlx5_flow_workspace *wks,
5813 : : const struct rte_flow_attr *attr,
5814 : : const struct rte_flow_item items[],
5815 : : struct rte_flow_item sfx_items[],
5816 : : const struct rte_flow_action actions[],
5817 : : struct rte_flow_action actions_sfx[],
5818 : : struct rte_flow_action actions_pre[],
5819 : : uint32_t *mtr_flow_id,
5820 : : struct rte_flow_error *error)
5821 : : {
5822 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5823 : 0 : struct mlx5_flow_meter_info *fm = wks->fm;
5824 : : struct rte_flow_action *tag_action = NULL;
5825 : : struct rte_flow_item *tag_item;
5826 : : struct mlx5_rte_flow_action_set_tag *set_tag;
5827 : : const struct rte_flow_action_raw_encap *raw_encap;
5828 : : const struct rte_flow_action_raw_decap *raw_decap;
5829 : : struct mlx5_rte_flow_item_tag *tag_item_spec;
5830 : : struct mlx5_rte_flow_item_tag *tag_item_mask;
5831 : 0 : uint32_t tag_id = 0;
5832 : : bool vlan_actions;
5833 : : struct rte_flow_item *orig_sfx_items = sfx_items;
5834 : : const struct rte_flow_item *orig_items = items;
5835 : : struct rte_flow_action *hw_mtr_action;
5836 : : struct rte_flow_action *action_pre_head = NULL;
5837 : 0 : uint16_t flow_src_port = priv->representor_id;
5838 : : bool mtr_first;
5839 : 0 : uint8_t mtr_id_offset = priv->mtr_reg_share ? MLX5_MTR_COLOR_BITS : 0;
5840 [ # # ]: 0 : uint8_t mtr_reg_bits = priv->mtr_reg_share ?
5841 : : MLX5_MTR_IDLE_BITS_IN_COLOR_REG : MLX5_REG_BITS;
5842 : : uint32_t flow_id = 0;
5843 : : uint32_t flow_id_reversed = 0;
5844 : : uint8_t flow_id_bits = 0;
5845 : : bool after_meter = false;
5846 : : int shift;
5847 : :
5848 : : /* Prepare the suffix subflow items. */
5849 : 0 : tag_item = sfx_items++;
5850 : 0 : tag_item->type = (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_TAG;
5851 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
5852 : : int item_type = items->type;
5853 : :
5854 [ # # # ]: 0 : switch (item_type) {
5855 : 0 : case RTE_FLOW_ITEM_TYPE_PORT_ID:
5856 : : case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
5857 : : case RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR:
5858 [ # # ]: 0 : if (mlx5_flow_get_item_vport_id(dev, items, &flow_src_port, NULL, error))
5859 : 0 : return -rte_errno;
5860 [ # # # # ]: 0 : if (!fm->def_policy && wks->policy->hierarchy_match_port &&
5861 [ # # ]: 0 : flow_src_port != priv->representor_id) {
5862 [ # # ]: 0 : if (flow_drv_mtr_hierarchy_rule_create(dev,
5863 : : flow, fm,
5864 : : flow_src_port,
5865 : : items,
5866 : : error))
5867 : 0 : return -rte_errno;
5868 : : }
5869 : : memcpy(sfx_items, items, sizeof(*sfx_items));
5870 : 0 : sfx_items++;
5871 : 0 : break;
5872 : : case RTE_FLOW_ITEM_TYPE_VLAN:
5873 : : /*
5874 : : * Copy VLAN items in case VLAN actions are performed.
5875 : : * If there are no VLAN actions, these items will be VOID.
5876 : : */
5877 : : memcpy(sfx_items, items, sizeof(*sfx_items));
5878 : 0 : sfx_items->type = (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_VLAN;
5879 : 0 : sfx_items++;
5880 : 0 : break;
5881 : : default:
5882 : : break;
5883 : : }
5884 : : }
5885 : 0 : sfx_items->type = RTE_FLOW_ITEM_TYPE_END;
5886 : 0 : sfx_items++;
5887 [ # # ]: 0 : mtr_first = priv->sh->meter_aso_en &&
5888 [ # # # # : 0 : (attr->egress || (attr->transfer && flow_src_port != UINT16_MAX));
# # ]
5889 : : /* For ASO meter, meter must be before tag in TX direction. */
5890 [ # # ]: 0 : if (mtr_first) {
5891 : 0 : action_pre_head = actions_pre++;
5892 : : /* Leave space for tag action. */
5893 : 0 : tag_action = actions_pre++;
5894 : : }
5895 : : /* Prepare the actions for prefix and suffix flow. */
5896 : : vlan_actions = false;
5897 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
5898 : : struct rte_flow_action *action_cur = NULL;
5899 : :
5900 [ # # # # : 0 : switch (actions->type) {
# # # ]
5901 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
5902 [ # # ]: 0 : if (mtr_first) {
5903 : : action_cur = action_pre_head;
5904 : : } else {
5905 : : /* Leave space for tag action. */
5906 : 0 : tag_action = actions_pre++;
5907 : 0 : action_cur = actions_pre++;
5908 : : }
5909 : : after_meter = true;
5910 : : break;
5911 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
5912 : : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
5913 : 0 : action_cur = actions_pre++;
5914 : 0 : break;
5915 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
5916 : 0 : raw_encap = actions->conf;
5917 [ # # ]: 0 : if (raw_encap->size < MLX5_ENCAPSULATION_DECISION_SIZE)
5918 : 0 : action_cur = actions_pre++;
5919 : : break;
5920 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
5921 : 0 : raw_decap = actions->conf;
5922 [ # # ]: 0 : if (raw_decap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
5923 : 0 : action_cur = actions_pre++;
5924 : : break;
5925 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
5926 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
5927 : : vlan_actions = true;
5928 : 0 : break;
5929 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
5930 [ # # ]: 0 : if (fm->def_policy)
5931 : : action_cur = after_meter ?
5932 [ # # ]: 0 : actions_sfx++ : actions_pre++;
5933 : : break;
5934 : : default:
5935 : : break;
5936 : : }
5937 [ # # ]: 0 : if (!action_cur)
5938 : 0 : action_cur = (fm->def_policy) ?
5939 [ # # ]: 0 : actions_sfx++ : actions_pre++;
5940 : : memcpy(action_cur, actions, sizeof(struct rte_flow_action));
5941 : : }
5942 : : /* If there are no VLAN actions, convert VLAN items to VOID in suffix flow items. */
5943 [ # # ]: 0 : if (!vlan_actions) {
5944 : : struct rte_flow_item *it = orig_sfx_items;
5945 : :
5946 [ # # ]: 0 : for (; it->type != RTE_FLOW_ITEM_TYPE_END; it++)
5947 [ # # ]: 0 : if (it->type == (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_VLAN)
5948 : 0 : it->type = RTE_FLOW_ITEM_TYPE_VOID;
5949 : : }
5950 : : /* Add end action to the actions. */
5951 : 0 : actions_sfx->type = RTE_FLOW_ACTION_TYPE_END;
5952 [ # # ]: 0 : if (priv->sh->meter_aso_en) {
5953 : : /**
5954 : : * For ASO meter, need to add an extra jump action explicitly,
5955 : : * to jump from meter to policer table.
5956 : : */
5957 : : struct mlx5_flow_meter_sub_policy *sub_policy;
5958 : : struct mlx5_flow_tbl_data_entry *tbl_data;
5959 : :
5960 [ # # ]: 0 : if (!fm->def_policy) {
5961 : 0 : sub_policy = get_meter_sub_policy(dev, flow, wks,
5962 : : attr, orig_items,
5963 : : error);
5964 [ # # ]: 0 : if (!sub_policy)
5965 : 0 : return -rte_errno;
5966 : : } else {
5967 : : enum mlx5_meter_domain mtr_domain =
5968 [ # # ]: 0 : attr->transfer ? MLX5_MTR_DOMAIN_TRANSFER :
5969 : 0 : (attr->egress ? MLX5_MTR_DOMAIN_EGRESS :
5970 : : MLX5_MTR_DOMAIN_INGRESS);
5971 : :
5972 : 0 : sub_policy =
5973 : 0 : &priv->sh->mtrmng->def_policy[mtr_domain]->sub_policy;
5974 : : }
5975 : 0 : tbl_data = container_of(sub_policy->tbl_rsc,
5976 : : struct mlx5_flow_tbl_data_entry, tbl);
5977 : 0 : hw_mtr_action = actions_pre++;
5978 : 0 : hw_mtr_action->type = (enum rte_flow_action_type)
5979 : : MLX5_RTE_FLOW_ACTION_TYPE_JUMP;
5980 : 0 : hw_mtr_action->conf = tbl_data->jump.action;
5981 : : }
5982 : 0 : actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
5983 : 0 : actions_pre++;
5984 [ # # ]: 0 : if (!tag_action)
5985 : 0 : return rte_flow_error_set(error, ENOMEM,
5986 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5987 : : NULL, "No tag action space.");
5988 [ # # ]: 0 : if (!mtr_flow_id) {
5989 : 0 : tag_action->type = RTE_FLOW_ACTION_TYPE_VOID;
5990 : 0 : goto exit;
5991 : : }
5992 : : /* Only default-policy Meter creates mtr flow id. */
5993 [ # # ]: 0 : if (fm->def_policy) {
5994 : 0 : mlx5_ipool_malloc(fm->flow_ipool, &tag_id);
5995 [ # # ]: 0 : if (!tag_id)
5996 : 0 : return rte_flow_error_set(error, ENOMEM,
5997 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
5998 : : "Failed to allocate meter flow id.");
5999 : 0 : flow_id = tag_id - 1;
6000 [ # # ]: 0 : flow_id_bits = (!flow_id) ? 1 :
6001 : 0 : (MLX5_REG_BITS - rte_clz32(flow_id));
6002 [ # # ]: 0 : if ((flow_id_bits + priv->sh->mtrmng->max_mtr_bits) >
6003 : : mtr_reg_bits) {
6004 : 0 : mlx5_ipool_free(fm->flow_ipool, tag_id);
6005 : 0 : return rte_flow_error_set(error, EINVAL,
6006 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6007 : : "Meter flow id exceeds max limit.");
6008 : : }
6009 [ # # ]: 0 : if (flow_id_bits > priv->sh->mtrmng->max_mtr_flow_bits)
6010 : 0 : priv->sh->mtrmng->max_mtr_flow_bits = flow_id_bits;
6011 : : }
6012 : : /* Build tag actions and items for meter_id/meter flow_id. */
6013 : : set_tag = (struct mlx5_rte_flow_action_set_tag *)actions_pre;
6014 : : tag_item_spec = (struct mlx5_rte_flow_item_tag *)sfx_items;
6015 : 0 : tag_item_mask = tag_item_spec + 1;
6016 : : /* Both flow_id and meter_id share the same register. */
6017 : 0 : *set_tag = (struct mlx5_rte_flow_action_set_tag) {
6018 : 0 : .id = (enum modify_reg)mlx5_flow_get_reg_id(dev, MLX5_MTR_ID,
6019 : : 0, error),
6020 : : .offset = mtr_id_offset,
6021 : : .length = mtr_reg_bits,
6022 : 0 : .data = flow->meter,
6023 : : };
6024 : : /*
6025 : : * The color Reg bits used by flow_id are growing from
6026 : : * msb to lsb, so must do bit reverse for flow_id val in RegC.
6027 : : */
6028 [ # # ]: 0 : for (shift = 0; shift < flow_id_bits; shift++)
6029 : 0 : flow_id_reversed = (flow_id_reversed << 1) |
6030 : 0 : ((flow_id >> shift) & 0x1);
6031 : 0 : set_tag->data |=
6032 : 0 : flow_id_reversed << (mtr_reg_bits - flow_id_bits);
6033 : 0 : tag_item_spec->id = set_tag->id;
6034 : 0 : tag_item_spec->data = set_tag->data << mtr_id_offset;
6035 : 0 : tag_item_mask->data = UINT32_MAX << mtr_id_offset;
6036 : 0 : tag_action->type = (enum rte_flow_action_type)
6037 : : MLX5_RTE_FLOW_ACTION_TYPE_TAG;
6038 : 0 : tag_action->conf = set_tag;
6039 : 0 : tag_item->spec = tag_item_spec;
6040 : 0 : tag_item->last = NULL;
6041 : 0 : tag_item->mask = tag_item_mask;
6042 : 0 : exit:
6043 [ # # ]: 0 : if (mtr_flow_id)
6044 : 0 : *mtr_flow_id = tag_id;
6045 : : return 0;
6046 : : }
6047 : :
6048 : : /**
6049 : : * Split action list having QUEUE/RSS for metadata register copy.
6050 : : *
6051 : : * Once Q/RSS action is detected in user's action list, the flow action
6052 : : * should be split in order to copy metadata registers, which will happen in
6053 : : * RX_CP_TBL like,
6054 : : * - CQE->flow_tag := reg_c[1] (MARK)
6055 : : * - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
6056 : : * The Q/RSS action will be performed on RX_ACT_TBL after passing by RX_CP_TBL.
6057 : : * This is because the last action of each flow must be a terminal action
6058 : : * (QUEUE, RSS or DROP).
6059 : : *
6060 : : * Flow ID must be allocated to identify actions in the RX_ACT_TBL and it is
6061 : : * stored and kept in the mlx5_flow structure per each sub_flow.
6062 : : *
6063 : : * The Q/RSS action is replaced with,
6064 : : * - SET_TAG, setting the allocated flow ID to reg_c[2].
6065 : : * And the following JUMP action is added at the end,
6066 : : * - JUMP, to RX_CP_TBL.
6067 : : *
6068 : : * A flow to perform remained Q/RSS action will be created in RX_ACT_TBL by
6069 : : * flow_create_split_metadata() routine. The flow will look like,
6070 : : * - If flow ID matches (reg_c[2]), perform Q/RSS.
6071 : : *
6072 : : * @param dev
6073 : : * Pointer to Ethernet device.
6074 : : * @param[out] split_actions
6075 : : * Pointer to store split actions to jump to CP_TBL.
6076 : : * @param[in] actions
6077 : : * Pointer to the list of original flow actions.
6078 : : * @param[in] qrss
6079 : : * Pointer to the Q/RSS action.
6080 : : * @param[in] actions_n
6081 : : * Number of original actions.
6082 : : * @param[in] mtr_sfx
6083 : : * Check if it is in meter suffix table.
6084 : : * @param[out] error
6085 : : * Perform verbose error reporting if not NULL.
6086 : : *
6087 : : * @return
6088 : : * non-zero unique flow_id on success, otherwise 0 and
6089 : : * error/rte_error are set.
6090 : : */
6091 : : static uint32_t
6092 : 0 : flow_mreg_split_qrss_prep(struct rte_eth_dev *dev,
6093 : : struct rte_flow_action *split_actions,
6094 : : const struct rte_flow_action *actions,
6095 : : const struct rte_flow_action *qrss,
6096 : : int actions_n, int mtr_sfx,
6097 : : struct rte_flow_error *error)
6098 : : {
6099 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6100 : : struct mlx5_rte_flow_action_set_tag *set_tag;
6101 : : struct rte_flow_action_jump *jump;
6102 : 0 : const int qrss_idx = qrss - actions;
6103 : 0 : uint32_t flow_id = 0;
6104 : : int ret = 0;
6105 : :
6106 : : /*
6107 : : * Given actions will be split
6108 : : * - Replace QUEUE/RSS action with SET_TAG to set flow ID.
6109 : : * - Add jump to mreg CP_TBL.
6110 : : * As a result, there will be one more action.
6111 : : */
6112 [ # # ]: 0 : memcpy(split_actions, actions, sizeof(*split_actions) * actions_n);
6113 : : /* Count MLX5_RTE_FLOW_ACTION_TYPE_TAG. */
6114 : 0 : ++actions_n;
6115 : 0 : set_tag = (void *)(split_actions + actions_n);
6116 : : /*
6117 : : * If we are not the meter suffix flow, add the tag action.
6118 : : * Since meter suffix flow already has the tag added.
6119 : : */
6120 [ # # ]: 0 : if (!mtr_sfx) {
6121 : : /*
6122 : : * Allocate the new subflow ID. This one is unique within
6123 : : * device and not shared with representors. Otherwise,
6124 : : * we would have to resolve multi-thread access synch
6125 : : * issue. Each flow on the shared device is appended
6126 : : * with source vport identifier, so the resulting
6127 : : * flows will be unique in the shared (by master and
6128 : : * representors) domain even if they have coinciding
6129 : : * IDs.
6130 : : */
6131 : 0 : mlx5_ipool_malloc(priv->sh->ipool
6132 : : [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &flow_id);
6133 [ # # ]: 0 : if (!flow_id)
6134 : 0 : return rte_flow_error_set(error, ENOMEM,
6135 : : RTE_FLOW_ERROR_TYPE_ACTION,
6136 : : NULL, "can't allocate id "
6137 : : "for split Q/RSS subflow");
6138 : : /* Internal SET_TAG action to set flow ID. */
6139 : 0 : *set_tag = (struct mlx5_rte_flow_action_set_tag){
6140 : : .data = flow_id,
6141 : : };
6142 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0, error);
6143 [ # # ]: 0 : if (ret < 0)
6144 : 0 : return ret;
6145 : 0 : set_tag->id = ret;
6146 : : /* Construct new actions array. */
6147 : : /* Replace QUEUE/RSS action. */
6148 : 0 : split_actions[qrss_idx] = (struct rte_flow_action){
6149 : : .type = (enum rte_flow_action_type)
6150 : : MLX5_RTE_FLOW_ACTION_TYPE_TAG,
6151 : : .conf = set_tag,
6152 : : };
6153 : : } else {
6154 : : /*
6155 : : * If we are the suffix flow of meter, tag already exist.
6156 : : * Set the QUEUE/RSS action to void.
6157 : : */
6158 : 0 : split_actions[qrss_idx].type = RTE_FLOW_ACTION_TYPE_VOID;
6159 : : }
6160 : : /* JUMP action to jump to mreg copy table (CP_TBL). */
6161 : 0 : jump = (void *)(set_tag + 1);
6162 : 0 : *jump = (struct rte_flow_action_jump){
6163 : : .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
6164 : : };
6165 : 0 : split_actions[actions_n - 2] = (struct rte_flow_action){
6166 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
6167 : : .conf = jump,
6168 : : };
6169 : 0 : split_actions[actions_n - 1] = (struct rte_flow_action){
6170 : : .type = RTE_FLOW_ACTION_TYPE_END,
6171 : : };
6172 : 0 : return flow_id;
6173 : : }
6174 : :
6175 : : /**
6176 : : * Extend the given action list for Tx metadata copy.
6177 : : *
6178 : : * Copy the given action list to the ext_actions and add flow metadata register
6179 : : * copy action in order to copy reg_a set by WQE to reg_c[0].
6180 : : *
6181 : : * @param[out] ext_actions
6182 : : * Pointer to the extended action list.
6183 : : * @param[in] actions
6184 : : * Pointer to the list of actions.
6185 : : * @param[in] actions_n
6186 : : * Number of actions in the list.
6187 : : * @param[out] error
6188 : : * Perform verbose error reporting if not NULL.
6189 : : * @param[in] encap_idx
6190 : : * The encap action index.
6191 : : *
6192 : : * @return
6193 : : * 0 on success, negative value otherwise
6194 : : */
6195 : : static int
6196 : 0 : flow_mreg_tx_copy_prep(struct rte_eth_dev *dev,
6197 : : struct rte_flow_action *ext_actions,
6198 : : const struct rte_flow_action *actions,
6199 : : int actions_n, struct rte_flow_error *error,
6200 : : int encap_idx)
6201 : : {
6202 : 0 : struct mlx5_flow_action_copy_mreg *cp_mreg =
6203 : : (struct mlx5_flow_action_copy_mreg *)
6204 : 0 : (ext_actions + actions_n + 1);
6205 : : int ret;
6206 : :
6207 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
6208 [ # # ]: 0 : if (ret < 0)
6209 : : return ret;
6210 : 0 : cp_mreg->dst = ret;
6211 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_TX, 0, error);
6212 [ # # ]: 0 : if (ret < 0)
6213 : : return ret;
6214 : 0 : cp_mreg->src = ret;
6215 [ # # ]: 0 : if (encap_idx != 0)
6216 : 0 : memcpy(ext_actions, actions, sizeof(*ext_actions) * encap_idx);
6217 [ # # ]: 0 : if (encap_idx == actions_n - 1) {
6218 : 0 : ext_actions[actions_n - 1] = (struct rte_flow_action){
6219 : : .type = (enum rte_flow_action_type)
6220 : : MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
6221 : : .conf = cp_mreg,
6222 : : };
6223 : 0 : ext_actions[actions_n] = (struct rte_flow_action){
6224 : : .type = RTE_FLOW_ACTION_TYPE_END,
6225 : : };
6226 : : } else {
6227 : 0 : ext_actions[encap_idx] = (struct rte_flow_action){
6228 : : .type = (enum rte_flow_action_type)
6229 : : MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
6230 : : .conf = cp_mreg,
6231 : : };
6232 : 0 : memcpy(ext_actions + encap_idx + 1, actions + encap_idx,
6233 : 0 : sizeof(*ext_actions) * (actions_n - encap_idx));
6234 : : }
6235 : : return 0;
6236 : : }
6237 : :
6238 : : /**
6239 : : * Check the match action from the action list.
6240 : : *
6241 : : * @param[in] actions
6242 : : * Pointer to the list of actions.
6243 : : * @param[in] attr
6244 : : * Flow rule attributes.
6245 : : * @param[in] action
6246 : : * The action to be check if exist.
6247 : : * @param[out] match_action_pos
6248 : : * Pointer to the position of the matched action if exists, otherwise is -1.
6249 : : * @param[out] qrss_action_pos
6250 : : * Pointer to the position of the Queue/RSS action if exists, otherwise is -1.
6251 : : * @param[out] modify_after_mirror
6252 : : * Pointer to the flag of modify action after FDB mirroring.
6253 : : *
6254 : : * @return
6255 : : * > 0 the total number of actions.
6256 : : * 0 if not found match action in action list.
6257 : : */
6258 : : static int
6259 : 0 : flow_check_match_action(const struct rte_flow_action actions[],
6260 : : const struct rte_flow_attr *attr,
6261 : : enum rte_flow_action_type action,
6262 : : int *match_action_pos, int *qrss_action_pos,
6263 : : int *modify_after_mirror)
6264 : : {
6265 : : const struct rte_flow_action_sample *sample;
6266 : : const struct rte_flow_action_raw_decap *decap;
6267 : : const struct rte_flow_action *action_cur = NULL;
6268 : : int actions_n = 0;
6269 : : uint32_t ratio = 0;
6270 : : int sub_type = 0;
6271 : : int flag = 0;
6272 : : int fdb_mirror = 0;
6273 : :
6274 : 0 : *match_action_pos = -1;
6275 : 0 : *qrss_action_pos = -1;
6276 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
6277 [ # # ]: 0 : if (actions->type == action) {
6278 : : flag = 1;
6279 : 0 : *match_action_pos = actions_n;
6280 : : }
6281 [ # # # # : 0 : switch (actions->type) {
# ]
6282 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
6283 : : case RTE_FLOW_ACTION_TYPE_RSS:
6284 : 0 : *qrss_action_pos = actions_n;
6285 : 0 : break;
6286 : 0 : case RTE_FLOW_ACTION_TYPE_SAMPLE:
6287 : 0 : sample = actions->conf;
6288 : 0 : ratio = sample->ratio;
6289 : 0 : sub_type = ((const struct rte_flow_action *)
6290 : 0 : (sample->actions))->type;
6291 [ # # # # : 0 : if (ratio == 1 && attr->transfer &&
# # ]
6292 : : sub_type != RTE_FLOW_ACTION_TYPE_END)
6293 : : fdb_mirror = 1;
6294 : : break;
6295 : 0 : case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
6296 : : case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
6297 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
6298 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
6299 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
6300 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
6301 : : case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
6302 : : case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
6303 : : case RTE_FLOW_ACTION_TYPE_DEC_TTL:
6304 : : case RTE_FLOW_ACTION_TYPE_SET_TTL:
6305 : : case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
6306 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
6307 : : case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
6308 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
6309 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
6310 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
6311 : : case RTE_FLOW_ACTION_TYPE_FLAG:
6312 : : case RTE_FLOW_ACTION_TYPE_MARK:
6313 : : case RTE_FLOW_ACTION_TYPE_SET_META:
6314 : : case RTE_FLOW_ACTION_TYPE_SET_TAG:
6315 : : case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
6316 : : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
6317 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
6318 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
6319 : : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
6320 : : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
6321 : : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
6322 : : case RTE_FLOW_ACTION_TYPE_METER:
6323 [ # # ]: 0 : if (fdb_mirror)
6324 : 0 : *modify_after_mirror = 1;
6325 : : break;
6326 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
6327 : 0 : decap = actions->conf;
6328 : : action_cur = actions;
6329 [ # # ]: 0 : while ((++action_cur)->type == RTE_FLOW_ACTION_TYPE_VOID)
6330 : : ;
6331 [ # # ]: 0 : if (action_cur->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
6332 : 0 : const struct rte_flow_action_raw_encap *encap =
6333 : : action_cur->conf;
6334 [ # # ]: 0 : if (decap->size <=
6335 : 0 : MLX5_ENCAPSULATION_DECISION_SIZE &&
6336 [ # # ]: 0 : encap->size >
6337 : : MLX5_ENCAPSULATION_DECISION_SIZE)
6338 : : /* L3 encap. */
6339 : : break;
6340 : : }
6341 [ # # ]: 0 : if (fdb_mirror)
6342 : 0 : *modify_after_mirror = 1;
6343 : : break;
6344 : : default:
6345 : : break;
6346 : : }
6347 : 0 : actions_n++;
6348 : : }
6349 [ # # # # ]: 0 : if (flag && fdb_mirror && !*modify_after_mirror) {
6350 : : /* FDB mirroring uses the destination array to implement
6351 : : * instead of FLOW_SAMPLER object.
6352 : : */
6353 [ # # ]: 0 : if (sub_type != RTE_FLOW_ACTION_TYPE_END)
6354 : : flag = 0;
6355 : : }
6356 : : /* Count RTE_FLOW_ACTION_TYPE_END. */
6357 [ # # ]: 0 : return flag ? actions_n + 1 : 0;
6358 : : }
6359 : :
6360 : : #define SAMPLE_SUFFIX_ITEM 3
6361 : :
6362 : : /**
6363 : : * Split the sample flow.
6364 : : *
6365 : : * As sample flow will split to two sub flow, sample flow with
6366 : : * sample action, the other actions will move to new suffix flow.
6367 : : *
6368 : : * Also add unique tag id with tag action in the sample flow,
6369 : : * the same tag id will be as match in the suffix flow.
6370 : : *
6371 : : * @param dev
6372 : : * Pointer to Ethernet device.
6373 : : * @param[in] add_tag
6374 : : * Add extra tag action flag.
6375 : : * @param[out] sfx_items
6376 : : * Suffix flow match items (list terminated by the END pattern item).
6377 : : * @param[in] actions
6378 : : * Associated actions (list terminated by the END action).
6379 : : * @param[out] actions_sfx
6380 : : * Suffix flow actions.
6381 : : * @param[out] actions_pre
6382 : : * Prefix flow actions.
6383 : : * @param[in] actions_n
6384 : : * The total number of actions.
6385 : : * @param[in] sample_action_pos
6386 : : * The sample action position.
6387 : : * @param[in] qrss_action_pos
6388 : : * The Queue/RSS action position.
6389 : : * @param[in] jump_table
6390 : : * Add extra jump action flag.
6391 : : * @param[out] error
6392 : : * Perform verbose error reporting if not NULL.
6393 : : *
6394 : : * @return
6395 : : * 0 on success, or unique flow_id, a negative errno value
6396 : : * otherwise and rte_errno is set.
6397 : : */
6398 : : static int
6399 : 0 : flow_sample_split_prep(struct rte_eth_dev *dev,
6400 : : int add_tag,
6401 : : const struct rte_flow_item items[],
6402 : : struct rte_flow_item sfx_items[],
6403 : : const struct rte_flow_action actions[],
6404 : : struct rte_flow_action actions_sfx[],
6405 : : struct rte_flow_action actions_pre[],
6406 : : int actions_n,
6407 : : int sample_action_pos,
6408 : : int qrss_action_pos,
6409 : : int jump_table,
6410 : : struct rte_flow_error *error)
6411 : : {
6412 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6413 : : struct mlx5_rte_flow_action_set_tag *set_tag;
6414 : : struct mlx5_rte_flow_item_tag *tag_spec;
6415 : : struct mlx5_rte_flow_item_tag *tag_mask;
6416 : : struct rte_flow_action_jump *jump_action;
6417 : 0 : uint32_t tag_id = 0;
6418 : : int append_index = 0;
6419 : : int set_tag_idx = -1;
6420 : : int index;
6421 : : int ret;
6422 : :
6423 [ # # ]: 0 : if (sample_action_pos < 0)
6424 : 0 : return rte_flow_error_set(error, EINVAL,
6425 : : RTE_FLOW_ERROR_TYPE_ACTION,
6426 : : NULL, "invalid position of sample "
6427 : : "action in list");
6428 : : /* Prepare the actions for prefix and suffix flow. */
6429 [ # # ]: 0 : if (add_tag) {
6430 : : /* Update the new added tag action index preceding
6431 : : * the PUSH_VLAN or ENCAP action.
6432 : : */
6433 : : const struct rte_flow_action_raw_encap *raw_encap;
6434 : : const struct rte_flow_action *action = actions;
6435 : : int encap_idx;
6436 : : int action_idx = 0;
6437 : : int raw_decap_idx = -1;
6438 : : int push_vlan_idx = -1;
6439 [ # # ]: 0 : for (; action->type != RTE_FLOW_ACTION_TYPE_END; action++) {
6440 [ # # # # : 0 : switch (action->type) {
# ]
6441 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
6442 : : raw_decap_idx = action_idx;
6443 : 0 : break;
6444 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
6445 : 0 : raw_encap = action->conf;
6446 [ # # ]: 0 : if (raw_encap->size >
6447 : : MLX5_ENCAPSULATION_DECISION_SIZE) {
6448 : : encap_idx = raw_decap_idx != -1 ?
6449 [ # # ]: 0 : raw_decap_idx : action_idx;
6450 : 0 : if (encap_idx < sample_action_pos &&
6451 [ # # ]: 0 : push_vlan_idx == -1)
6452 : : set_tag_idx = encap_idx;
6453 : : }
6454 : : break;
6455 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
6456 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
6457 : : encap_idx = action_idx;
6458 : 0 : if (encap_idx < sample_action_pos &&
6459 [ # # ]: 0 : push_vlan_idx == -1)
6460 : : set_tag_idx = encap_idx;
6461 : : break;
6462 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
6463 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
6464 : 0 : if (action_idx < sample_action_pos &&
6465 [ # # ]: 0 : push_vlan_idx == -1) {
6466 : : set_tag_idx = action_idx;
6467 : : push_vlan_idx = action_idx;
6468 : : }
6469 : : break;
6470 : : default:
6471 : : break;
6472 : : }
6473 : 0 : action_idx++;
6474 : : }
6475 : : }
6476 : : /* Prepare the actions for prefix and suffix flow. */
6477 [ # # ]: 0 : if (qrss_action_pos >= 0 && qrss_action_pos < sample_action_pos) {
6478 : : index = qrss_action_pos;
6479 : : /* Put the preceding the Queue/RSS action into prefix flow. */
6480 [ # # ]: 0 : if (index != 0)
6481 : 0 : memcpy(actions_pre, actions,
6482 : : sizeof(struct rte_flow_action) * index);
6483 : : /* Put others preceding the sample action into prefix flow. */
6484 [ # # ]: 0 : if (sample_action_pos > index + 1)
6485 : 0 : memcpy(actions_pre + index, actions + index + 1,
6486 : : sizeof(struct rte_flow_action) *
6487 : 0 : (sample_action_pos - index - 1));
6488 : 0 : index = sample_action_pos - 1;
6489 : : /* Put Queue/RSS action into Suffix flow. */
6490 : 0 : memcpy(actions_sfx, actions + qrss_action_pos,
6491 : : sizeof(struct rte_flow_action));
6492 : 0 : actions_sfx++;
6493 [ # # ]: 0 : } else if (add_tag && set_tag_idx >= 0) {
6494 [ # # ]: 0 : if (set_tag_idx > 0)
6495 : 0 : memcpy(actions_pre, actions,
6496 : : sizeof(struct rte_flow_action) * set_tag_idx);
6497 : 0 : memcpy(actions_pre + set_tag_idx + 1, actions + set_tag_idx,
6498 : : sizeof(struct rte_flow_action) *
6499 : 0 : (sample_action_pos - set_tag_idx));
6500 : : index = sample_action_pos;
6501 : : } else {
6502 : : index = sample_action_pos;
6503 [ # # ]: 0 : if (index != 0)
6504 : 0 : memcpy(actions_pre, actions,
6505 : : sizeof(struct rte_flow_action) * index);
6506 : : }
6507 : : /* For CX5, add an extra tag action for NIC-RX and E-Switch ingress.
6508 : : * For CX6DX and above, metadata registers Cx preserve their value,
6509 : : * add an extra tag action for NIC-RX and E-Switch Domain.
6510 : : */
6511 [ # # ]: 0 : if (add_tag) {
6512 : : /* Prepare the prefix tag action. */
6513 : : append_index++;
6514 : 0 : set_tag = (void *)(actions_pre + actions_n + append_index);
6515 : : /* Trust VF/SF on CX5 not supported meter so that the reserved
6516 : : * metadata regC is REG_NON, back to use application tag
6517 : : * index 0.
6518 : : */
6519 [ # # ]: 0 : if (unlikely(priv->sh->registers.aso_reg == REG_NON))
6520 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, 0, error);
6521 : : else
6522 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_SAMPLE_ID, 0, error);
6523 [ # # ]: 0 : if (ret < 0)
6524 : : return ret;
6525 : 0 : mlx5_ipool_malloc(priv->sh->ipool
6526 : : [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &tag_id);
6527 : 0 : *set_tag = (struct mlx5_rte_flow_action_set_tag) {
6528 : : .id = ret,
6529 : : .data = tag_id,
6530 : : };
6531 : : /* Prepare the suffix subflow items. */
6532 : 0 : tag_spec = (void *)(sfx_items + SAMPLE_SUFFIX_ITEM);
6533 : 0 : tag_spec->data = tag_id;
6534 : 0 : tag_spec->id = set_tag->id;
6535 : 0 : tag_mask = tag_spec + 1;
6536 : 0 : tag_mask->data = UINT32_MAX;
6537 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
6538 [ # # ]: 0 : if (items->type == RTE_FLOW_ITEM_TYPE_PORT_ID ||
6539 : : items->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR ||
6540 : : items->type == RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT) {
6541 : : memcpy(sfx_items, items, sizeof(*sfx_items));
6542 : 0 : sfx_items++;
6543 : 0 : break;
6544 : : }
6545 : : }
6546 : 0 : sfx_items[0] = (struct rte_flow_item){
6547 : : .type = (enum rte_flow_item_type)
6548 : : MLX5_RTE_FLOW_ITEM_TYPE_TAG,
6549 : : .spec = tag_spec,
6550 : : .last = NULL,
6551 : : .mask = tag_mask,
6552 : : };
6553 : 0 : sfx_items[1] = (struct rte_flow_item){
6554 : : .type = (enum rte_flow_item_type)
6555 : : RTE_FLOW_ITEM_TYPE_END,
6556 : : };
6557 : : /* Prepare the tag action in prefix subflow. */
6558 [ # # ]: 0 : set_tag_idx = (set_tag_idx == -1) ? index : set_tag_idx;
6559 : 0 : actions_pre[set_tag_idx] =
6560 : : (struct rte_flow_action){
6561 : : .type = (enum rte_flow_action_type)
6562 : : MLX5_RTE_FLOW_ACTION_TYPE_TAG,
6563 : : .conf = set_tag,
6564 : : };
6565 : : /* Update next sample position due to add one tag action */
6566 : 0 : index += 1;
6567 : : }
6568 : : /* Copy the sample action into prefix flow. */
6569 [ # # ]: 0 : memcpy(actions_pre + index, actions + sample_action_pos,
6570 : : sizeof(struct rte_flow_action));
6571 : 0 : index += 1;
6572 : : /* For the modify action after the sample action in E-Switch mirroring,
6573 : : * Add the extra jump action in prefix subflow and jump into the next
6574 : : * table, then do the modify action in the new table.
6575 : : */
6576 [ # # ]: 0 : if (jump_table) {
6577 : : /* Prepare the prefix jump action. */
6578 : 0 : append_index++;
6579 : 0 : jump_action = (void *)(actions_pre + actions_n + append_index);
6580 : 0 : jump_action->group = jump_table;
6581 : 0 : actions_pre[index++] =
6582 : : (struct rte_flow_action){
6583 : : .type = (enum rte_flow_action_type)
6584 : : RTE_FLOW_ACTION_TYPE_JUMP,
6585 : : .conf = jump_action,
6586 : : };
6587 : : }
6588 : 0 : actions_pre[index] = (struct rte_flow_action){
6589 : : .type = (enum rte_flow_action_type)
6590 : : RTE_FLOW_ACTION_TYPE_END,
6591 : : };
6592 : : /* Put the actions after sample into Suffix flow. */
6593 : 0 : memcpy(actions_sfx, actions + sample_action_pos + 1,
6594 : : sizeof(struct rte_flow_action) *
6595 : 0 : (actions_n - sample_action_pos - 1));
6596 : 0 : return tag_id;
6597 : : }
6598 : :
6599 : : /**
6600 : : * The splitting for metadata feature.
6601 : : *
6602 : : * - Q/RSS action on NIC Rx should be split in order to pass by
6603 : : * the mreg copy table (RX_CP_TBL) and then it jumps to the
6604 : : * action table (RX_ACT_TBL) which has the split Q/RSS action.
6605 : : *
6606 : : * - All the actions on NIC Tx should have a mreg copy action to
6607 : : * copy reg_a from WQE to reg_c[0].
6608 : : *
6609 : : * @param dev
6610 : : * Pointer to Ethernet device.
6611 : : * @param[in] flow
6612 : : * Parent flow structure pointer.
6613 : : * @param[in] attr
6614 : : * Flow rule attributes.
6615 : : * @param[in] items
6616 : : * Pattern specification (list terminated by the END pattern item).
6617 : : * @param[in] actions
6618 : : * Associated actions (list terminated by the END action).
6619 : : * @param[in] flow_split_info
6620 : : * Pointer to flow split info structure.
6621 : : * @param[out] error
6622 : : * Perform verbose error reporting if not NULL.
6623 : : * @return
6624 : : * 0 on success, negative value otherwise
6625 : : */
6626 : : static int
6627 : 0 : flow_create_split_metadata(struct rte_eth_dev *dev,
6628 : : struct rte_flow *flow,
6629 : : const struct rte_flow_attr *attr,
6630 : : const struct rte_flow_item items[],
6631 : : const struct rte_flow_action actions[],
6632 : : struct mlx5_flow_split_info *flow_split_info,
6633 : : struct rte_flow_error *error)
6634 : : {
6635 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6636 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
6637 : 0 : const struct rte_flow_action *qrss = NULL;
6638 : : struct rte_flow_action *ext_actions = NULL;
6639 : 0 : struct mlx5_flow *dev_flow = NULL;
6640 : : uint32_t qrss_id = 0;
6641 : : int mtr_sfx = 0;
6642 : : size_t act_size;
6643 : : int actions_n;
6644 : : int encap_idx;
6645 : : int ret;
6646 : :
6647 : : /* Check whether extensive metadata feature is engaged. */
6648 [ # # ]: 0 : if (!config->dv_flow_en ||
6649 [ # # # # ]: 0 : config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
6650 : 0 : !mlx5_flow_ext_mreg_supported(dev))
6651 : 0 : return flow_create_split_inner(dev, flow, NULL, attr, items,
6652 : : actions, flow_split_info, error);
6653 : 0 : actions_n = flow_parse_metadata_split_actions_info(actions, &qrss,
6654 : : &encap_idx);
6655 [ # # ]: 0 : if (qrss) {
6656 : : /* Exclude hairpin flows from splitting. */
6657 [ # # ]: 0 : if (qrss->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
6658 : : const struct rte_flow_action_queue *queue;
6659 : :
6660 : 0 : queue = qrss->conf;
6661 [ # # ]: 0 : if (mlx5_rxq_is_hairpin(dev, queue->index))
6662 : 0 : qrss = NULL;
6663 [ # # ]: 0 : } else if (qrss->type == RTE_FLOW_ACTION_TYPE_RSS) {
6664 : : const struct rte_flow_action_rss *rss;
6665 : :
6666 : 0 : rss = qrss->conf;
6667 [ # # ]: 0 : if (mlx5_rxq_is_hairpin(dev, rss->queue[0]))
6668 : 0 : qrss = NULL;
6669 : : }
6670 : : }
6671 [ # # ]: 0 : if (qrss) {
6672 : : /* Check if it is in meter suffix table. */
6673 : 0 : mtr_sfx = attr->group ==
6674 [ # # ]: 0 : ((attr->transfer && priv->fdb_def_rule) ?
6675 [ # # ]: 0 : (MLX5_FLOW_TABLE_LEVEL_METER - 1) :
6676 : : MLX5_FLOW_TABLE_LEVEL_METER);
6677 : : /*
6678 : : * Q/RSS action on NIC Rx should be split in order to pass by
6679 : : * the mreg copy table (RX_CP_TBL) and then it jumps to the
6680 : : * action table (RX_ACT_TBL) which has the split Q/RSS action.
6681 : : */
6682 : 0 : act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
6683 : 0 : sizeof(struct rte_flow_action_set_tag) +
6684 : : sizeof(struct rte_flow_action_jump);
6685 : 0 : ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
6686 : : SOCKET_ID_ANY);
6687 [ # # ]: 0 : if (!ext_actions)
6688 : 0 : return rte_flow_error_set(error, ENOMEM,
6689 : : RTE_FLOW_ERROR_TYPE_ACTION,
6690 : : NULL, "no memory to split "
6691 : : "metadata flow");
6692 : : /*
6693 : : * Create the new actions list with removed Q/RSS action
6694 : : * and appended set tag and jump to register copy table
6695 : : * (RX_CP_TBL). We should preallocate unique tag ID here
6696 : : * in advance, because it is needed for set tag action.
6697 : : */
6698 : 0 : qrss_id = flow_mreg_split_qrss_prep(dev, ext_actions, actions,
6699 : : qrss, actions_n,
6700 : : mtr_sfx, error);
6701 [ # # ]: 0 : if (!mtr_sfx && !qrss_id) {
6702 : 0 : ret = -rte_errno;
6703 : 0 : goto exit;
6704 : : }
6705 [ # # ]: 0 : } else if (attr->egress) {
6706 : : /*
6707 : : * All the actions on NIC Tx should have a metadata register
6708 : : * copy action to copy reg_a from WQE to reg_c[meta]
6709 : : */
6710 : 0 : act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
6711 : : sizeof(struct mlx5_flow_action_copy_mreg);
6712 : 0 : ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
6713 : : SOCKET_ID_ANY);
6714 [ # # ]: 0 : if (!ext_actions)
6715 : 0 : return rte_flow_error_set(error, ENOMEM,
6716 : : RTE_FLOW_ERROR_TYPE_ACTION,
6717 : : NULL, "no memory to split "
6718 : : "metadata flow");
6719 : : /* Create the action list appended with copy register. */
6720 : 0 : ret = flow_mreg_tx_copy_prep(dev, ext_actions, actions,
6721 : : actions_n, error, encap_idx);
6722 [ # # ]: 0 : if (ret < 0)
6723 : 0 : goto exit;
6724 : : }
6725 : : /* Add the unmodified original or prefix subflow. */
6726 [ # # ]: 0 : ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
6727 : : items, ext_actions ? ext_actions :
6728 : : actions, flow_split_info, error);
6729 [ # # ]: 0 : if (ret < 0)
6730 : 0 : goto exit;
6731 : : MLX5_ASSERT(dev_flow);
6732 [ # # ]: 0 : if (qrss) {
6733 : 0 : const struct rte_flow_attr q_attr = {
6734 : : .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
6735 : : .ingress = 1,
6736 : : };
6737 : : /* Internal PMD action to set register. */
6738 : 0 : struct mlx5_rte_flow_item_tag q_tag_spec = {
6739 : : .data = qrss_id,
6740 : : .id = REG_NON,
6741 : : };
6742 : 0 : struct rte_flow_item q_items[] = {
6743 : : {
6744 : : .type = (enum rte_flow_item_type)
6745 : : MLX5_RTE_FLOW_ITEM_TYPE_TAG,
6746 : : .spec = &q_tag_spec,
6747 : : .last = NULL,
6748 : : .mask = NULL,
6749 : : },
6750 : : {
6751 : : .type = RTE_FLOW_ITEM_TYPE_END,
6752 : : },
6753 : : };
6754 : 0 : struct rte_flow_action q_actions[] = {
6755 : : {
6756 : 0 : .type = qrss->type,
6757 : 0 : .conf = qrss->conf,
6758 : : },
6759 : : {
6760 : : .type = RTE_FLOW_ACTION_TYPE_END,
6761 : : },
6762 : : };
6763 : 0 : uint64_t layers = flow_get_prefix_layer_flags(dev_flow);
6764 : :
6765 : : /*
6766 : : * Configure the tag item only if there is no meter subflow.
6767 : : * Since tag is already marked in the meter suffix subflow
6768 : : * we can just use the meter suffix items as is.
6769 : : */
6770 [ # # ]: 0 : if (qrss_id) {
6771 : : /* Not meter subflow. */
6772 : : MLX5_ASSERT(!mtr_sfx);
6773 : : /*
6774 : : * Put unique id in prefix flow due to it is destroyed
6775 : : * after suffix flow and id will be freed after there
6776 : : * is no actual flows with this id and identifier
6777 : : * reallocation becomes possible (for example, for
6778 : : * other flows in other threads).
6779 : : */
6780 : 0 : dev_flow->handle->split_flow_id = qrss_id;
6781 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0,
6782 : : error);
6783 [ # # ]: 0 : if (ret < 0)
6784 : 0 : goto exit;
6785 : 0 : q_tag_spec.id = ret;
6786 : : }
6787 : 0 : dev_flow = NULL;
6788 : : /* Add suffix subflow to execute Q/RSS. */
6789 : 0 : flow_split_info->prefix_layers = layers;
6790 : 0 : flow_split_info->prefix_mark = 0;
6791 : 0 : flow_split_info->table_id = 0;
6792 [ # # ]: 0 : ret = flow_create_split_inner(dev, flow, &dev_flow,
6793 : : &q_attr, mtr_sfx ? items :
6794 : : q_items, q_actions,
6795 : : flow_split_info, error);
6796 [ # # ]: 0 : if (ret < 0)
6797 : 0 : goto exit;
6798 : : /* qrss ID should be freed if failed. */
6799 : : qrss_id = 0;
6800 : : MLX5_ASSERT(dev_flow);
6801 : : }
6802 : :
6803 : 0 : exit:
6804 : : /*
6805 : : * We do not destroy the partially created sub_flows in case of error.
6806 : : * These ones are included into parent flow list and will be destroyed
6807 : : * by flow_drv_destroy.
6808 : : */
6809 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
6810 : : qrss_id);
6811 : 0 : mlx5_free(ext_actions);
6812 : 0 : return ret;
6813 : : }
6814 : :
6815 : : /**
6816 : : * Create meter internal drop flow with the original pattern.
6817 : : *
6818 : : * @param dev
6819 : : * Pointer to Ethernet device.
6820 : : * @param[in] flow
6821 : : * Parent flow structure pointer.
6822 : : * @param[in] attr
6823 : : * Flow rule attributes.
6824 : : * @param[in] items
6825 : : * Pattern specification (list terminated by the END pattern item).
6826 : : * @param[in] flow_split_info
6827 : : * Pointer to flow split info structure.
6828 : : * @param[in] fm
6829 : : * Pointer to flow meter structure.
6830 : : * @param[out] error
6831 : : * Perform verbose error reporting if not NULL.
6832 : : * @return
6833 : : * 0 on success, negative value otherwise
6834 : : */
6835 : : static uint32_t
6836 : 0 : flow_meter_create_drop_flow_with_org_pattern(struct rte_eth_dev *dev,
6837 : : struct rte_flow *flow,
6838 : : const struct rte_flow_attr *attr,
6839 : : const struct rte_flow_item items[],
6840 : : struct mlx5_flow_split_info *flow_split_info,
6841 : : struct mlx5_flow_meter_info *fm,
6842 : : struct rte_flow_error *error)
6843 : : {
6844 : 0 : struct mlx5_flow *dev_flow = NULL;
6845 : 0 : struct rte_flow_attr drop_attr = *attr;
6846 : : struct rte_flow_action drop_actions[3];
6847 : 0 : struct mlx5_flow_split_info drop_split_info = *flow_split_info;
6848 : :
6849 : : MLX5_ASSERT(fm->drop_cnt);
6850 : 0 : drop_actions[0].type =
6851 : : (enum rte_flow_action_type)MLX5_RTE_FLOW_ACTION_TYPE_COUNT;
6852 : 0 : drop_actions[0].conf = (void *)(uintptr_t)fm->drop_cnt;
6853 : 0 : drop_actions[1].type = RTE_FLOW_ACTION_TYPE_DROP;
6854 : 0 : drop_actions[1].conf = NULL;
6855 : 0 : drop_actions[2].type = RTE_FLOW_ACTION_TYPE_END;
6856 : 0 : drop_actions[2].conf = NULL;
6857 : 0 : drop_split_info.external = false;
6858 : 0 : drop_split_info.skip_scale |= 1 << MLX5_SCALE_FLOW_GROUP_BIT;
6859 : 0 : drop_split_info.table_id = MLX5_MTR_TABLE_ID_DROP;
6860 : 0 : drop_attr.group = MLX5_FLOW_TABLE_LEVEL_METER;
6861 : 0 : return flow_create_split_inner(dev, flow, &dev_flow,
6862 : : &drop_attr, items, drop_actions,
6863 : : &drop_split_info, error);
6864 : : }
6865 : :
6866 : : static int
6867 : : flow_count_vlan_items(const struct rte_flow_item items[])
6868 : : {
6869 : : int items_n = 0;
6870 : :
6871 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
6872 [ # # ]: 0 : if (items->type == RTE_FLOW_ITEM_TYPE_VLAN ||
6873 : : items->type == (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_VLAN)
6874 : 0 : items_n++;
6875 : : }
6876 : : return items_n;
6877 : : }
6878 : :
6879 : : /**
6880 : : * The splitting for meter feature.
6881 : : *
6882 : : * - The meter flow will be split to two flows as prefix and
6883 : : * suffix flow. The packets make sense only it pass the prefix
6884 : : * meter action.
6885 : : *
6886 : : * - Reg_C_5 is used for the packet to match betweend prefix and
6887 : : * suffix flow.
6888 : : *
6889 : : * @param dev
6890 : : * Pointer to Ethernet device.
6891 : : * @param[in] flow
6892 : : * Parent flow structure pointer.
6893 : : * @param[in] attr
6894 : : * Flow rule attributes.
6895 : : * @param[in] items
6896 : : * Pattern specification (list terminated by the END pattern item).
6897 : : * @param[in] actions
6898 : : * Associated actions (list terminated by the END action).
6899 : : * @param[in] flow_split_info
6900 : : * Pointer to flow split info structure.
6901 : : * @param[out] error
6902 : : * Perform verbose error reporting if not NULL.
6903 : : * @return
6904 : : * 0 on success, negative value otherwise
6905 : : */
6906 : : static int
6907 : 0 : flow_create_split_meter(struct rte_eth_dev *dev,
6908 : : struct rte_flow *flow,
6909 : : const struct rte_flow_attr *attr,
6910 : : const struct rte_flow_item items[],
6911 : : const struct rte_flow_action actions[],
6912 : : struct mlx5_flow_split_info *flow_split_info,
6913 : : struct rte_flow_error *error)
6914 : : {
6915 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6916 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
6917 : : struct rte_flow_action *sfx_actions = NULL;
6918 : : struct rte_flow_action *pre_actions = NULL;
6919 : : struct rte_flow_item *sfx_items = NULL;
6920 : 0 : struct mlx5_flow *dev_flow = NULL;
6921 : 0 : struct rte_flow_attr sfx_attr = *attr;
6922 : : struct mlx5_flow_meter_info *fm = NULL;
6923 : : uint8_t skip_scale_restore;
6924 : 0 : bool has_mtr = false;
6925 : 0 : bool has_modify = false;
6926 : : bool set_mtr_reg = true;
6927 : : bool is_mtr_hierarchy = false;
6928 : 0 : uint32_t meter_id = 0;
6929 : 0 : uint32_t mtr_idx = 0;
6930 : 0 : uint32_t mtr_flow_id = 0;
6931 : : size_t act_size;
6932 : : size_t item_size;
6933 : : int actions_n = 0;
6934 : : int vlan_items_n = 0;
6935 : : int ret = 0;
6936 : :
6937 [ # # ]: 0 : if (priv->mtr_en)
6938 : 0 : actions_n = flow_check_meter_action(dev, actions, &has_mtr,
6939 : : &has_modify, &meter_id);
6940 [ # # ]: 0 : if (has_mtr) {
6941 [ # # ]: 0 : if (flow->meter) {
6942 : 0 : fm = mlx5_flow_dv_meter_find_by_idx(priv, flow->meter);
6943 [ # # ]: 0 : if (!fm)
6944 : 0 : return rte_flow_error_set(error, EINVAL,
6945 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6946 : : NULL, "Meter not found.");
6947 : : } else {
6948 : 0 : fm = mlx5_flow_meter_find(priv, meter_id, &mtr_idx);
6949 [ # # ]: 0 : if (!fm)
6950 : 0 : return rte_flow_error_set(error, EINVAL,
6951 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6952 : : NULL, "Meter not found.");
6953 : 0 : ret = mlx5_flow_meter_attach(priv, fm,
6954 : : &sfx_attr, error);
6955 [ # # ]: 0 : if (ret)
6956 : 0 : return -rte_errno;
6957 : 0 : flow->meter = mtr_idx;
6958 : : }
6959 : : MLX5_ASSERT(wks);
6960 : 0 : wks->fm = fm;
6961 [ # # ]: 0 : if (!fm->def_policy) {
6962 : 0 : wks->policy = mlx5_flow_meter_policy_find(dev,
6963 : : fm->policy_id,
6964 : : NULL);
6965 : : MLX5_ASSERT(wks->policy);
6966 [ # # ]: 0 : if (wks->policy->mark)
6967 : 0 : wks->mark = 1;
6968 [ # # ]: 0 : if (wks->policy->is_hierarchy) {
6969 : 0 : wks->final_policy =
6970 : 0 : mlx5_flow_meter_hierarchy_get_final_policy(dev,
6971 : : wks->policy);
6972 [ # # ]: 0 : if (!wks->final_policy)
6973 : 0 : return rte_flow_error_set(error,
6974 : : EINVAL,
6975 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6976 : : "Failed to find terminal policy of hierarchy.");
6977 : : is_mtr_hierarchy = true;
6978 : : }
6979 : : }
6980 : : /*
6981 : : * If it isn't default-policy Meter, and
6982 : : * 1. Not meter hierarchy and there's no action in flow to change
6983 : : * packet (modify/encap/decap etc.), OR
6984 : : * 2. No drop count needed for this meter.
6985 : : * Then no need to use regC to save meter id anymore.
6986 : : */
6987 [ # # # # : 0 : if (!fm->def_policy && ((!has_modify && !is_mtr_hierarchy) || !fm->drop_cnt))
# # # # ]
6988 : : set_mtr_reg = false;
6989 : : /* Prefix actions: meter, decap, encap, tag, jump, end, cnt. */
6990 : : #define METER_PREFIX_ACTION 7
6991 : 0 : act_size = (sizeof(struct rte_flow_action) *
6992 : 0 : (actions_n + METER_PREFIX_ACTION)) +
6993 : : sizeof(struct mlx5_rte_flow_action_set_tag);
6994 : : /* Flow can have multiple VLAN items. Account for them in suffix items. */
6995 : : vlan_items_n = flow_count_vlan_items(items);
6996 : : /* Suffix items: tag, [vlans], port id, end. */
6997 : : #define METER_SUFFIX_ITEM 3
6998 : 0 : item_size = sizeof(struct rte_flow_item) * (METER_SUFFIX_ITEM + vlan_items_n) +
6999 : : sizeof(struct mlx5_rte_flow_item_tag) * 2;
7000 : 0 : sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size + item_size),
7001 : : 0, SOCKET_ID_ANY);
7002 [ # # ]: 0 : if (!sfx_actions)
7003 : 0 : return rte_flow_error_set(error, ENOMEM,
7004 : : RTE_FLOW_ERROR_TYPE_ACTION,
7005 : : NULL, "no memory to split "
7006 : : "meter flow");
7007 : 0 : sfx_items = (struct rte_flow_item *)((char *)sfx_actions +
7008 : : act_size);
7009 : : /* There's no suffix flow for meter of non-default policy. */
7010 [ # # ]: 0 : if (!fm->def_policy)
7011 : 0 : pre_actions = sfx_actions + 1;
7012 : : else
7013 : 0 : pre_actions = sfx_actions + actions_n;
7014 [ # # ]: 0 : ret = flow_meter_split_prep(dev, flow, wks, &sfx_attr,
7015 : : items, sfx_items, actions,
7016 : : sfx_actions, pre_actions,
7017 : : (set_mtr_reg ? &mtr_flow_id : NULL),
7018 : : error);
7019 [ # # ]: 0 : if (ret) {
7020 : 0 : ret = -rte_errno;
7021 : 0 : goto exit;
7022 : : }
7023 : : /* Add the prefix subflow. */
7024 : 0 : skip_scale_restore = flow_split_info->skip_scale;
7025 : 0 : flow_split_info->skip_scale |=
7026 : : 1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT;
7027 : 0 : ret = flow_create_split_inner(dev, flow, &dev_flow,
7028 : : attr, items, pre_actions,
7029 : : flow_split_info, error);
7030 : 0 : flow_split_info->skip_scale = skip_scale_restore;
7031 [ # # ]: 0 : if (ret) {
7032 [ # # ]: 0 : if (mtr_flow_id)
7033 : 0 : mlx5_ipool_free(fm->flow_ipool, mtr_flow_id);
7034 : 0 : ret = -rte_errno;
7035 : 0 : goto exit;
7036 : : }
7037 [ # # ]: 0 : if (mtr_flow_id) {
7038 : 0 : dev_flow->handle->split_flow_id = mtr_flow_id;
7039 : 0 : dev_flow->handle->is_meter_flow_id = 1;
7040 : : }
7041 [ # # ]: 0 : if (!fm->def_policy) {
7042 [ # # # # ]: 0 : if (!set_mtr_reg && fm->drop_cnt)
7043 : 0 : ret =
7044 : 0 : flow_meter_create_drop_flow_with_org_pattern(dev, flow,
7045 : : &sfx_attr, items,
7046 : : flow_split_info,
7047 : : fm, error);
7048 : 0 : goto exit;
7049 : : }
7050 : : /* Setting the sfx group atrr. */
7051 : 0 : sfx_attr.group = sfx_attr.transfer ?
7052 [ # # ]: 0 : (MLX5_FLOW_TABLE_LEVEL_METER - 1) :
7053 : : MLX5_FLOW_TABLE_LEVEL_METER;
7054 : 0 : flow_split_info->prefix_layers =
7055 : 0 : flow_get_prefix_layer_flags(dev_flow);
7056 : 0 : flow_split_info->prefix_mark |= wks->mark;
7057 : 0 : flow_split_info->table_id = MLX5_MTR_TABLE_ID_SUFFIX;
7058 : : }
7059 : : /* Add the prefix subflow. */
7060 [ # # ]: 0 : ret = flow_create_split_metadata(dev, flow,
7061 : : &sfx_attr, sfx_items ?
7062 : : sfx_items : items,
7063 : : sfx_actions ? sfx_actions : actions,
7064 : : flow_split_info, error);
7065 : 0 : exit:
7066 [ # # ]: 0 : if (sfx_actions)
7067 : 0 : mlx5_free(sfx_actions);
7068 : : return ret;
7069 : : }
7070 : :
7071 : : /**
7072 : : * The splitting for sample feature.
7073 : : *
7074 : : * Once Sample action is detected in the action list, the flow actions should
7075 : : * be split into prefix sub flow and suffix sub flow.
7076 : : *
7077 : : * The original items remain in the prefix sub flow, all actions preceding the
7078 : : * sample action and the sample action itself will be copied to the prefix
7079 : : * sub flow, the actions following the sample action will be copied to the
7080 : : * suffix sub flow, Queue action always be located in the suffix sub flow.
7081 : : *
7082 : : * In order to make the packet from prefix sub flow matches with suffix sub
7083 : : * flow, an extra tag action be added into prefix sub flow, and the suffix sub
7084 : : * flow uses tag item with the unique flow id.
7085 : : *
7086 : : * @param dev
7087 : : * Pointer to Ethernet device.
7088 : : * @param[in] flow
7089 : : * Parent flow structure pointer.
7090 : : * @param[in] attr
7091 : : * Flow rule attributes.
7092 : : * @param[in] items
7093 : : * Pattern specification (list terminated by the END pattern item).
7094 : : * @param[in] actions
7095 : : * Associated actions (list terminated by the END action).
7096 : : * @param[in] flow_split_info
7097 : : * Pointer to flow split info structure.
7098 : : * @param[out] error
7099 : : * Perform verbose error reporting if not NULL.
7100 : : * @return
7101 : : * 0 on success, negative value otherwise
7102 : : */
7103 : : static int
7104 : 0 : flow_create_split_sample(struct rte_eth_dev *dev,
7105 : : struct rte_flow *flow,
7106 : : const struct rte_flow_attr *attr,
7107 : : const struct rte_flow_item items[],
7108 : : const struct rte_flow_action actions[],
7109 : : struct mlx5_flow_split_info *flow_split_info,
7110 : : struct rte_flow_error *error)
7111 : : {
7112 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7113 : : struct rte_flow_action *sfx_actions = NULL;
7114 : : struct rte_flow_action *pre_actions = NULL;
7115 : : struct rte_flow_item *sfx_items = NULL;
7116 : 0 : struct mlx5_flow *dev_flow = NULL;
7117 : 0 : struct rte_flow_attr sfx_attr = *attr;
7118 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
7119 : : struct mlx5_flow_dv_sample_resource *sample_res;
7120 : : struct mlx5_flow_tbl_data_entry *sfx_tbl_data;
7121 : : struct mlx5_flow_tbl_resource *sfx_tbl;
7122 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
7123 : : #endif
7124 : : size_t act_size;
7125 : : size_t item_size;
7126 : : uint32_t fdb_tx = 0;
7127 : : int32_t tag_id = 0;
7128 : : int actions_n = 0;
7129 : : int sample_action_pos;
7130 : : int qrss_action_pos;
7131 : : int add_tag = 0;
7132 : 0 : int modify_after_mirror = 0;
7133 : : uint16_t jump_table = 0;
7134 : : const uint32_t next_ft_step = 1;
7135 : : int ret = 0;
7136 : : struct mlx5_priv *item_port_priv = NULL;
7137 : : const struct rte_flow_item *item;
7138 : :
7139 [ # # ]: 0 : if (priv->sampler_en)
7140 : 0 : actions_n = flow_check_match_action(actions, attr,
7141 : : RTE_FLOW_ACTION_TYPE_SAMPLE,
7142 : : &sample_action_pos, &qrss_action_pos,
7143 : : &modify_after_mirror);
7144 [ # # ]: 0 : if (actions_n) {
7145 : : /* The prefix actions must includes sample, tag, end. */
7146 : 0 : act_size = sizeof(struct rte_flow_action) * (actions_n * 2 + 1)
7147 : : + sizeof(struct mlx5_rte_flow_action_set_tag);
7148 : : item_size = sizeof(struct rte_flow_item) * SAMPLE_SUFFIX_ITEM +
7149 : : sizeof(struct mlx5_rte_flow_item_tag) * 2;
7150 : 0 : sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size +
7151 : : item_size), 0, SOCKET_ID_ANY);
7152 [ # # ]: 0 : if (!sfx_actions)
7153 : 0 : return rte_flow_error_set(error, ENOMEM,
7154 : : RTE_FLOW_ERROR_TYPE_ACTION,
7155 : : NULL, "no memory to split "
7156 : : "sample flow");
7157 [ # # ]: 0 : for (item = items; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
7158 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_PORT_ID) {
7159 : : const struct rte_flow_item_port_id *spec;
7160 : :
7161 : 0 : spec = (const struct rte_flow_item_port_id *)item->spec;
7162 [ # # ]: 0 : if (spec)
7163 : : item_port_priv =
7164 : 0 : mlx5_port_to_eswitch_info(spec->id, true);
7165 : : break;
7166 [ # # ]: 0 : } else if (item->type == RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT) {
7167 : : const struct rte_flow_item_ethdev *spec;
7168 : :
7169 : 0 : spec = (const struct rte_flow_item_ethdev *)item->spec;
7170 [ # # ]: 0 : if (spec)
7171 : : item_port_priv =
7172 : 0 : mlx5_port_to_eswitch_info(spec->port_id, true);
7173 : : break;
7174 [ # # ]: 0 : } else if (item->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR) {
7175 : : const struct rte_flow_item_ethdev *spec;
7176 : :
7177 : 0 : spec = (const struct rte_flow_item_ethdev *)item->spec;
7178 [ # # ]: 0 : if (spec)
7179 : : item_port_priv =
7180 : 0 : mlx5_port_to_eswitch_info(spec->port_id, true);
7181 : : break;
7182 : : }
7183 : : }
7184 : : /* The representor_id is UINT16_MAX for uplink. */
7185 [ # # # # ]: 0 : fdb_tx = (attr->transfer &&
7186 : : flow_source_vport_representor(priv, item_port_priv));
7187 : : /*
7188 : : * When reg_c_preserve is set, metadata registers Cx preserve
7189 : : * their value even through packet duplication.
7190 : : */
7191 : 0 : add_tag = (!fdb_tx ||
7192 [ # # ]: 0 : priv->sh->cdev->config.hca_attr.reg_c_preserve);
7193 : : if (add_tag)
7194 : 0 : sfx_items = (struct rte_flow_item *)((char *)sfx_actions
7195 : : + act_size);
7196 [ # # ]: 0 : if (modify_after_mirror)
7197 : 0 : jump_table = attr->group * MLX5_FLOW_TABLE_FACTOR +
7198 : : next_ft_step;
7199 : 0 : pre_actions = sfx_actions + actions_n;
7200 : 0 : tag_id = flow_sample_split_prep(dev, add_tag, items, sfx_items,
7201 : : actions, sfx_actions,
7202 : : pre_actions, actions_n,
7203 : : sample_action_pos,
7204 : : qrss_action_pos, jump_table,
7205 : : error);
7206 [ # # # # ]: 0 : if (tag_id < 0 || (add_tag && !tag_id)) {
7207 : 0 : ret = -rte_errno;
7208 : 0 : goto exit;
7209 : : }
7210 [ # # ]: 0 : if (modify_after_mirror)
7211 : 0 : flow_split_info->skip_scale =
7212 : : 1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT;
7213 : : /* Add the prefix subflow. */
7214 : 0 : ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
7215 : : items, pre_actions,
7216 : : flow_split_info, error);
7217 [ # # ]: 0 : if (ret) {
7218 : 0 : ret = -rte_errno;
7219 : 0 : goto exit;
7220 : : }
7221 : 0 : dev_flow->handle->split_flow_id = tag_id;
7222 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
7223 [ # # ]: 0 : if (!modify_after_mirror) {
7224 : : /* Set the sfx group attr. */
7225 : 0 : sample_res = (struct mlx5_flow_dv_sample_resource *)
7226 : : dev_flow->dv.sample_res;
7227 : 0 : sfx_tbl = (struct mlx5_flow_tbl_resource *)
7228 : : sample_res->normal_path_tbl;
7229 : 0 : sfx_tbl_data = container_of(sfx_tbl,
7230 : : struct mlx5_flow_tbl_data_entry,
7231 : : tbl);
7232 : 0 : sfx_attr.group = sfx_attr.transfer ?
7233 [ # # ]: 0 : (sfx_tbl_data->level - 1) : sfx_tbl_data->level;
7234 : : } else {
7235 : : MLX5_ASSERT(attr->transfer);
7236 : 0 : sfx_attr.group = jump_table;
7237 : : }
7238 : 0 : flow_split_info->prefix_layers =
7239 : 0 : flow_get_prefix_layer_flags(dev_flow);
7240 : : MLX5_ASSERT(wks);
7241 : 0 : flow_split_info->prefix_mark |= wks->mark;
7242 : : /* Suffix group level already be scaled with factor, set
7243 : : * MLX5_SCALE_FLOW_GROUP_BIT of skip_scale to 1 to avoid scale
7244 : : * again in translation.
7245 : : */
7246 : 0 : flow_split_info->skip_scale = 1 << MLX5_SCALE_FLOW_GROUP_BIT;
7247 : : #endif
7248 : : }
7249 : : /* Add the suffix subflow. */
7250 [ # # # # ]: 0 : ret = flow_create_split_meter(dev, flow, &sfx_attr,
7251 : : sfx_items ? sfx_items : items,
7252 : : sfx_actions ? sfx_actions : actions,
7253 : : flow_split_info, error);
7254 : 0 : exit:
7255 [ # # ]: 0 : if (sfx_actions)
7256 : 0 : mlx5_free(sfx_actions);
7257 : : return ret;
7258 : : }
7259 : :
7260 : : /**
7261 : : * Split the flow to subflow set. The splitters might be linked
7262 : : * in the chain, like this:
7263 : : * flow_create_split_outer() calls:
7264 : : * flow_create_split_meter() calls:
7265 : : * flow_create_split_metadata(meter_subflow_0) calls:
7266 : : * flow_create_split_inner(metadata_subflow_0)
7267 : : * flow_create_split_inner(metadata_subflow_1)
7268 : : * flow_create_split_inner(metadata_subflow_2)
7269 : : * flow_create_split_metadata(meter_subflow_1) 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 : : *
7274 : : * This provide flexible way to add new levels of flow splitting.
7275 : : * The all of successfully created subflows are included to the
7276 : : * parent flow dev_flow list.
7277 : : *
7278 : : * @param dev
7279 : : * Pointer to Ethernet device.
7280 : : * @param[in] flow
7281 : : * Parent flow structure pointer.
7282 : : * @param[in] attr
7283 : : * Flow rule attributes.
7284 : : * @param[in] items
7285 : : * Pattern specification (list terminated by the END pattern item).
7286 : : * @param[in] actions
7287 : : * Associated actions (list terminated by the END action).
7288 : : * @param[in] flow_split_info
7289 : : * Pointer to flow split info structure.
7290 : : * @param[out] error
7291 : : * Perform verbose error reporting if not NULL.
7292 : : * @return
7293 : : * 0 on success, negative value otherwise
7294 : : */
7295 : : static int
7296 : : flow_create_split_outer(struct rte_eth_dev *dev,
7297 : : struct rte_flow *flow,
7298 : : const struct rte_flow_attr *attr,
7299 : : const struct rte_flow_item items[],
7300 : : const struct rte_flow_action actions[],
7301 : : struct mlx5_flow_split_info *flow_split_info,
7302 : : struct rte_flow_error *error)
7303 : : {
7304 : : int ret;
7305 : :
7306 : 0 : ret = flow_create_split_sample(dev, flow, attr, items,
7307 : : actions, flow_split_info, error);
7308 : : MLX5_ASSERT(ret <= 0);
7309 : : return ret;
7310 : : }
7311 : :
7312 : : static inline struct mlx5_flow_tunnel *
7313 : : flow_tunnel_from_rule(const struct mlx5_flow *flow)
7314 : : {
7315 : : struct mlx5_flow_tunnel *tunnel;
7316 : :
7317 : 0 : tunnel = RTE_PTR_UNQUAL(flow->tunnel);
7318 : :
7319 : : return tunnel;
7320 : : }
7321 : :
7322 : : /**
7323 : : * Create a flow and add it to @p list.
7324 : : *
7325 : : * @param dev
7326 : : * Pointer to Ethernet device.
7327 : : * @param list
7328 : : * Pointer to a TAILQ flow list. If this parameter NULL,
7329 : : * no list insertion occurred, flow is just created,
7330 : : * this is caller's responsibility to track the
7331 : : * created flow.
7332 : : * @param[in] attr
7333 : : * Flow rule attributes.
7334 : : * @param[in] items
7335 : : * Pattern specification (list terminated by the END pattern item).
7336 : : * @param[in] actions
7337 : : * Associated actions (list terminated by the END action).
7338 : : * @param[in] external
7339 : : * This flow rule is created by request external to PMD.
7340 : : * @param[out] error
7341 : : * Perform verbose error reporting if not NULL.
7342 : : *
7343 : : * @return
7344 : : * A flow index on success, 0 otherwise and rte_errno is set.
7345 : : */
7346 : : uintptr_t
7347 : 0 : mlx5_flow_legacy_list_create(struct rte_eth_dev *dev, enum mlx5_flow_type type,
7348 : : const struct rte_flow_attr *attr,
7349 : : const struct rte_flow_item items[],
7350 : : const struct rte_flow_action original_actions[],
7351 : : bool external, struct rte_flow_error *error)
7352 : : {
7353 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7354 : : struct rte_flow *flow = NULL;
7355 : : struct mlx5_flow *dev_flow;
7356 : : const struct rte_flow_action_rss *rss = NULL;
7357 : : struct mlx5_translated_action_handle
7358 : : indir_actions[MLX5_MAX_INDIRECT_ACTIONS];
7359 : 0 : int indir_actions_n = MLX5_MAX_INDIRECT_ACTIONS;
7360 : : union {
7361 : : struct mlx5_flow_expand_rss buf;
7362 : : uint8_t buffer[8192];
7363 : : } expand_buffer;
7364 : : union {
7365 : : struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
7366 : : uint8_t buffer[2048];
7367 : : } actions_rx;
7368 : : union {
7369 : : struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
7370 : : uint8_t buffer[2048];
7371 : : } actions_hairpin_tx;
7372 : : union {
7373 : : struct rte_flow_item items[MLX5_MAX_SPLIT_ITEMS];
7374 : : uint8_t buffer[2048];
7375 : : } items_tx;
7376 : : struct mlx5_rte_flow_item_sq sq_specs[RTE_MAX_QUEUES_PER_PORT];
7377 : : struct mlx5_flow_expand_rss *buf = &expand_buffer.buf;
7378 : : struct mlx5_flow_rss_desc *rss_desc;
7379 : : const struct rte_flow_action *p_actions_rx;
7380 : : uint32_t i;
7381 : 0 : uint32_t idx = 0;
7382 : : int hairpin_flow;
7383 : 0 : struct rte_flow_attr attr_tx = { .priority = 0 };
7384 : : const struct rte_flow_action *actions;
7385 : 0 : struct rte_flow_action *translated_actions = NULL;
7386 : : struct mlx5_flow_tunnel *tunnel;
7387 : 0 : struct tunnel_default_miss_ctx default_miss_ctx = { 0, };
7388 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_push_thread_workspace();
7389 : 0 : struct mlx5_flow_split_info flow_split_info = {
7390 : : .external = !!external,
7391 : : .skip_scale = 0,
7392 : : .flow_idx = 0,
7393 : : .prefix_mark = 0,
7394 : : .prefix_layers = 0,
7395 : : .table_id = 0
7396 : : };
7397 : : int ret;
7398 : : struct mlx5_shared_action_rss *shared_rss_action;
7399 : :
7400 [ # # ]: 0 : if (!wks)
7401 : 0 : return rte_flow_error_set(error, ENOMEM,
7402 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7403 : : NULL,
7404 : : "failed to push flow workspace");
7405 : : memset(indir_actions, 0, sizeof(indir_actions));
7406 : 0 : rss_desc = &wks->rss_desc;
7407 : 0 : ret = flow_action_handles_translate(dev, original_actions,
7408 : : indir_actions,
7409 : : &indir_actions_n,
7410 : : &translated_actions, error);
7411 [ # # ]: 0 : if (ret < 0) {
7412 : : MLX5_ASSERT(translated_actions == NULL);
7413 : : return 0;
7414 : : }
7415 [ # # ]: 0 : actions = translated_actions ? translated_actions : original_actions;
7416 : : p_actions_rx = actions;
7417 : 0 : hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
7418 : 0 : ret = flow_drv_validate(dev, attr, items, p_actions_rx,
7419 : : external, hairpin_flow, error);
7420 [ # # ]: 0 : if (ret < 0)
7421 : 0 : goto error_before_hairpin_split;
7422 : 0 : flow = mlx5_ipool_zmalloc(priv->flows[type], &idx);
7423 [ # # ]: 0 : if (!flow) {
7424 : 0 : rte_errno = ENOMEM;
7425 : 0 : goto error_before_hairpin_split;
7426 : : }
7427 [ # # ]: 0 : if (hairpin_flow > 0) {
7428 [ # # ]: 0 : if (hairpin_flow > MLX5_MAX_SPLIT_ACTIONS) {
7429 : 0 : rte_errno = EINVAL;
7430 : 0 : goto error_before_hairpin_split;
7431 : : }
7432 : 0 : flow_hairpin_split(dev, actions, actions_rx.actions,
7433 : : actions_hairpin_tx.actions, items_tx.items,
7434 : : idx);
7435 : : p_actions_rx = actions_rx.actions;
7436 : : }
7437 : 0 : flow_split_info.flow_idx = idx;
7438 [ # # ]: 0 : flow->drv_type = flow_get_drv_type(dev, attr);
7439 : : /* drv_type upper limit does not require range check since it's only 2b size. */
7440 : : MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN);
7441 : : memset(rss_desc, 0, offsetof(struct mlx5_flow_rss_desc, queue));
7442 : : /* RSS Action only works on NIC RX domain */
7443 [ # # ]: 0 : if (attr->ingress)
7444 : 0 : rss = flow_get_rss_action(dev, p_actions_rx);
7445 [ # # ]: 0 : if (rss) {
7446 : : MLX5_ASSERT(rss->queue_num <= RTE_ETH_RSS_RETA_SIZE_512);
7447 : 0 : rss_desc->symmetric_hash_function = MLX5_RSS_IS_SYMM(rss->func);
7448 : : /*
7449 : : * The following information is required by
7450 : : * mlx5_flow_hashfields_adjust() in advance.
7451 : : */
7452 : 0 : rss_desc->level = rss->level;
7453 : : /* RSS type 0 indicates default RSS type (RTE_ETH_RSS_IP). */
7454 [ # # ]: 0 : rss_desc->types = !rss->types ? RTE_ETH_RSS_IP : rss->types;
7455 : : }
7456 : 0 : flow->dev_handles = 0;
7457 [ # # # # ]: 0 : if (rss && rss->types) {
7458 : : unsigned int graph_root;
7459 : :
7460 : 0 : graph_root = find_graph_root(rss->level);
7461 : 0 : ret = mlx5_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
7462 : : items, rss->types,
7463 : : mlx5_support_expansion, graph_root);
7464 : : MLX5_ASSERT(ret > 0 &&
7465 : : (unsigned int)ret < sizeof(expand_buffer.buffer));
7466 [ # # ]: 0 : if (rte_log_can_log(mlx5_logtype, RTE_LOG_DEBUG)) {
7467 [ # # ]: 0 : for (i = 0; i < buf->entries; ++i)
7468 : 0 : mlx5_dbg__print_pattern(buf->entry[i].pattern);
7469 : : }
7470 : : } else {
7471 : 0 : ret = mlx5_flow_expand_sqn((struct mlx5_flow_expand_sqn *)buf,
7472 : : sizeof(expand_buffer.buffer),
7473 : : items, sq_specs);
7474 [ # # ]: 0 : if (ret) {
7475 : 0 : rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_HANDLE,
7476 : : NULL, "not enough memory for rte_flow");
7477 : 0 : goto error;
7478 : : }
7479 [ # # ]: 0 : if (buf->entries == 0) {
7480 : 0 : buf->entries = 1;
7481 : 0 : buf->entry[0].pattern = (void *)(uintptr_t)items;
7482 : : }
7483 : : }
7484 : 0 : rss_desc->shared_rss = flow_get_shared_rss_action(dev, indir_actions,
7485 : : indir_actions_n);
7486 [ # # ]: 0 : for (i = 0; i < buf->entries; ++i) {
7487 : : /* Initialize flow split data. */
7488 : 0 : flow_split_info.prefix_layers = 0;
7489 : 0 : flow_split_info.prefix_mark = 0;
7490 : 0 : flow_split_info.skip_scale = 0;
7491 : : /*
7492 : : * The splitter may create multiple dev_flows,
7493 : : * depending on configuration. In the simplest
7494 : : * case it just creates unmodified original flow.
7495 : : */
7496 : : ret = flow_create_split_outer(dev, flow, attr,
7497 : 0 : buf->entry[i].pattern,
7498 : : p_actions_rx, &flow_split_info,
7499 : : error);
7500 [ # # ]: 0 : if (ret < 0)
7501 : 0 : goto error;
7502 [ # # ]: 0 : if (is_flow_tunnel_steer_rule(wks->flows[0].tof_type)) {
7503 : 0 : ret = flow_tunnel_add_default_miss(dev, flow, attr,
7504 : : p_actions_rx,
7505 : : idx,
7506 : : wks->flows[0].tunnel,
7507 : : &default_miss_ctx,
7508 : : error);
7509 [ # # ]: 0 : if (ret < 0) {
7510 : 0 : mlx5_free(default_miss_ctx.queue);
7511 : 0 : goto error;
7512 : : }
7513 : : }
7514 : : }
7515 : : /* Create the tx flow. */
7516 [ # # ]: 0 : if (hairpin_flow) {
7517 : 0 : attr_tx.group = MLX5_HAIRPIN_TX_TABLE;
7518 : 0 : attr_tx.ingress = 0;
7519 : 0 : attr_tx.egress = 1;
7520 : 0 : dev_flow = flow_drv_prepare(dev, flow, &attr_tx, items_tx.items,
7521 : : actions_hairpin_tx.actions,
7522 : : idx, error);
7523 [ # # ]: 0 : if (!dev_flow)
7524 : 0 : goto error;
7525 : 0 : dev_flow->flow = flow;
7526 : 0 : dev_flow->external = 0;
7527 : 0 : SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
7528 : : dev_flow->handle, next);
7529 : : ret = flow_drv_translate(dev, dev_flow, &attr_tx,
7530 : : items_tx.items,
7531 : : actions_hairpin_tx.actions, error);
7532 [ # # ]: 0 : if (ret < 0)
7533 : 0 : goto error;
7534 : : }
7535 : : /*
7536 : : * Update the metadata register copy table. If extensive
7537 : : * metadata feature is enabled and registers are supported
7538 : : * we might create the extra rte_flow for each unique
7539 : : * MARK/FLAG action ID.
7540 : : *
7541 : : * The table is updated for ingress and transfer flows only, because
7542 : : * the egress Flows belong to the different device and
7543 : : * copy table should be updated in peer NIC Rx domain.
7544 : : */
7545 [ # # # # ]: 0 : if ((attr->ingress || attr->transfer) &&
7546 [ # # ]: 0 : (external || attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
7547 : 0 : ret = flow_mreg_update_copy_table(dev, flow, actions, error);
7548 [ # # ]: 0 : if (ret)
7549 : 0 : goto error;
7550 : : }
7551 : : /*
7552 : : * If the flow is external (from application) OR device is started,
7553 : : * OR mreg discover, then apply immediately.
7554 : : */
7555 [ # # # # ]: 0 : if (external || dev->data->dev_started ||
7556 [ # # ]: 0 : (attr->group == MLX5_FLOW_MREG_CP_TABLE_GROUP &&
7557 [ # # ]: 0 : attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)) {
7558 : : ret = flow_drv_apply(dev, flow, error);
7559 [ # # ]: 0 : if (ret < 0)
7560 : 0 : goto error;
7561 : : }
7562 : 0 : flow->type = type;
7563 : 0 : flow_rxq_flags_set(dev, flow);
7564 : 0 : rte_free(translated_actions);
7565 : : tunnel = flow_tunnel_from_rule(wks->flows);
7566 [ # # ]: 0 : if (tunnel) {
7567 : 0 : flow->tunnel = 1;
7568 : 0 : flow->tunnel_id = tunnel->tunnel_id;
7569 : 0 : rte_atomic_fetch_add_explicit(&tunnel->refctn, 1, rte_memory_order_relaxed);
7570 : 0 : mlx5_free(default_miss_ctx.queue);
7571 : : }
7572 : 0 : mlx5_flow_pop_thread_workspace();
7573 : 0 : return idx;
7574 : 0 : error:
7575 : : MLX5_ASSERT(flow);
7576 : 0 : ret = rte_errno; /* Save rte_errno before cleanup. */
7577 : 0 : flow_mreg_del_copy_action(dev, flow);
7578 : : flow_drv_destroy(dev, flow);
7579 : :
7580 [ # # ]: 0 : if (rss_desc->shared_rss) {
7581 : : shared_rss_action = (struct mlx5_shared_action_rss *)
7582 : 0 : mlx5_ipool_get
7583 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
7584 : : rss_desc->shared_rss);
7585 [ # # ]: 0 : if (shared_rss_action)
7586 : 0 : rte_atomic_fetch_sub_explicit(&(shared_rss_action)->refcnt, 1,
7587 : : rte_memory_order_relaxed);
7588 : : }
7589 : 0 : mlx5_ipool_free(priv->flows[type], idx);
7590 : 0 : rte_errno = ret; /* Restore rte_errno. */
7591 : : ret = rte_errno;
7592 : : rte_errno = ret;
7593 : 0 : error_before_hairpin_split:
7594 : 0 : mlx5_flow_pop_thread_workspace();
7595 : 0 : rte_free(translated_actions);
7596 : 0 : return 0;
7597 : : }
7598 : :
7599 : : /**
7600 : : * Create a dedicated flow rule on e-switch table 0 (root table), to direct all
7601 : : * incoming packets to table 1.
7602 : : *
7603 : : * Other flow rules, requested for group n, will be created in
7604 : : * e-switch table n+1.
7605 : : * Jump action to e-switch group n will be created to group n+1.
7606 : : *
7607 : : * Used when working in switchdev mode, to utilise advantages of table 1
7608 : : * and above.
7609 : : *
7610 : : * @param dev
7611 : : * Pointer to Ethernet device.
7612 : : *
7613 : : * @return
7614 : : * Pointer to flow on success, NULL otherwise and rte_errno is set.
7615 : : */
7616 : : struct rte_flow *
7617 : 0 : mlx5_flow_create_esw_table_zero_flow(struct rte_eth_dev *dev)
7618 : : {
7619 : 0 : const struct rte_flow_attr attr = {
7620 : : .group = 0,
7621 : : .priority = 0,
7622 : : .ingress = 0,
7623 : : .egress = 0,
7624 : : .transfer = 1,
7625 : : };
7626 : 0 : const struct rte_flow_item pattern = {
7627 : : .type = RTE_FLOW_ITEM_TYPE_END,
7628 : : };
7629 : 0 : struct rte_flow_action_jump jump = {
7630 : : .group = 1,
7631 : : };
7632 : 0 : const struct rte_flow_action actions[] = {
7633 : : {
7634 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
7635 : : .conf = &jump,
7636 : : },
7637 : : {
7638 : : .type = RTE_FLOW_ACTION_TYPE_END,
7639 : : },
7640 : : };
7641 : : struct rte_flow_error error;
7642 : :
7643 : 0 : return (void *)(uintptr_t)mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
7644 : : &attr, &pattern,
7645 : : actions, false, &error);
7646 : : }
7647 : :
7648 : : /**
7649 : : * Create a dedicated flow rule on e-switch table 1, matches ESW manager
7650 : : * and sq number, directs all packets to peer vport.
7651 : : *
7652 : : * @param dev
7653 : : * Pointer to Ethernet device.
7654 : : * @param sq_num
7655 : : * SQ number.
7656 : : *
7657 : : * @return
7658 : : * Flow ID on success, 0 otherwise and rte_errno is set.
7659 : : */
7660 : : uint32_t
7661 : 0 : mlx5_flow_create_devx_sq_miss_flow(struct rte_eth_dev *dev, uint32_t sq_num)
7662 : : {
7663 : 0 : struct rte_flow_attr attr = {
7664 : : .group = 0,
7665 : : .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
7666 : : .ingress = 0,
7667 : : .egress = 0,
7668 : : .transfer = 1,
7669 : : };
7670 : 0 : struct rte_flow_item_port_id port_spec = {
7671 : : .id = MLX5_PORT_ESW_MGR,
7672 : : };
7673 : 0 : struct mlx5_rte_flow_item_sq sq_spec = {
7674 : : .queue = sq_num,
7675 : : };
7676 : 0 : struct rte_flow_item pattern[] = {
7677 : : {
7678 : : .type = RTE_FLOW_ITEM_TYPE_PORT_ID,
7679 : : .spec = &port_spec,
7680 : : },
7681 : : {
7682 : : .type = (enum rte_flow_item_type)
7683 : : MLX5_RTE_FLOW_ITEM_TYPE_SQ,
7684 : : .spec = &sq_spec,
7685 : : },
7686 : : {
7687 : : .type = RTE_FLOW_ITEM_TYPE_END,
7688 : : },
7689 : : };
7690 : 0 : struct rte_flow_action_jump jump = {
7691 : : .group = 1,
7692 : : };
7693 : 0 : struct rte_flow_action_port_id port = {
7694 : 0 : .id = dev->data->port_id,
7695 : : };
7696 : 0 : struct rte_flow_action actions[] = {
7697 : : {
7698 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
7699 : : .conf = &jump,
7700 : : },
7701 : : {
7702 : : .type = RTE_FLOW_ACTION_TYPE_END,
7703 : : },
7704 : : };
7705 : : struct rte_flow_error error;
7706 : :
7707 : : /*
7708 : : * Creates group 0, highest priority jump flow.
7709 : : * Matches txq to bypass kernel packets.
7710 : : */
7711 [ # # ]: 0 : if (mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_CTL, &attr, pattern, actions,
7712 : : false, &error) == 0)
7713 : : return 0;
7714 : : /* Create group 1, lowest priority redirect flow for txq. */
7715 : 0 : attr.group = 1;
7716 : 0 : actions[0].conf = &port;
7717 : 0 : actions[0].type = RTE_FLOW_ACTION_TYPE_PORT_ID;
7718 : 0 : return mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_CTL, &attr, pattern,
7719 : : actions, false, &error);
7720 : : }
7721 : :
7722 : : /**
7723 : : * Validate a flow supported by the NIC.
7724 : : *
7725 : : * @see rte_flow_validate()
7726 : : * @see rte_flow_ops
7727 : : */
7728 : : int
7729 : 0 : mlx5_flow_validate(struct rte_eth_dev *dev,
7730 : : const struct rte_flow_attr *attr,
7731 : : const struct rte_flow_item items[],
7732 : : const struct rte_flow_action original_actions[],
7733 : : struct rte_flow_error *error)
7734 : : {
7735 : : int hairpin_flow;
7736 : : struct mlx5_translated_action_handle
7737 : : indir_actions[MLX5_MAX_INDIRECT_ACTIONS];
7738 : 0 : int indir_actions_n = MLX5_MAX_INDIRECT_ACTIONS;
7739 : : const struct rte_flow_action *actions;
7740 : 0 : struct rte_flow_action *translated_actions = NULL;
7741 : 0 : int ret = flow_action_handles_translate(dev, original_actions,
7742 : : indir_actions,
7743 : : &indir_actions_n,
7744 : : &translated_actions, error);
7745 : :
7746 [ # # ]: 0 : if (ret)
7747 : : return ret;
7748 [ # # ]: 0 : actions = translated_actions ? translated_actions : original_actions;
7749 : 0 : hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
7750 : 0 : ret = flow_drv_validate(dev, attr, items, actions,
7751 : : true, hairpin_flow, error);
7752 : 0 : rte_free(translated_actions);
7753 : 0 : return ret;
7754 : : }
7755 : :
7756 : : static int
7757 : 0 : mlx5_flow_cache_flow_info(struct rte_eth_dev *dev,
7758 : : const struct rte_flow_attr *attr,
7759 : : const uint32_t orig_prio,
7760 : : const struct rte_flow_item *items,
7761 : : const struct rte_flow_action *actions,
7762 : : uint32_t flow_idx)
7763 : : {
7764 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7765 : : struct rte_pmd_mlx5_flow_engine_mode_info *mode_info = &priv->mode_info;
7766 : : struct mlx5_dv_flow_info *flow_info, *tmp_info;
7767 : : struct rte_flow_error error;
7768 : : int len, ret;
7769 : :
7770 : 0 : flow_info = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*flow_info), 0, SOCKET_ID_ANY);
7771 [ # # ]: 0 : if (!flow_info) {
7772 : 0 : DRV_LOG(ERR, "No enough memory for flow_info caching.");
7773 : 0 : return -1;
7774 : : }
7775 : 0 : flow_info->orig_prio = orig_prio;
7776 : 0 : flow_info->attr = *attr;
7777 : : /* Standby mode rule awlays saves it in low priority entry. */
7778 : 0 : flow_info->flow_idx_low_prio = flow_idx;
7779 : :
7780 : : /* Store matching items. */
7781 : 0 : ret = rte_flow_conv(RTE_FLOW_CONV_OP_PATTERN, NULL, 0, items, &error);
7782 [ # # ]: 0 : if (ret <= 0) {
7783 : 0 : DRV_LOG(ERR, "Can't get items length.");
7784 : 0 : goto end;
7785 : : }
7786 : 0 : len = RTE_ALIGN(ret, 16);
7787 : 0 : flow_info->items = mlx5_malloc(MLX5_MEM_ZERO, len, 0, SOCKET_ID_ANY);
7788 [ # # ]: 0 : if (!flow_info->items) {
7789 : 0 : DRV_LOG(ERR, "No enough memory for items caching.");
7790 : 0 : goto end;
7791 : : }
7792 : 0 : ret = rte_flow_conv(RTE_FLOW_CONV_OP_PATTERN, flow_info->items, ret, items, &error);
7793 [ # # ]: 0 : if (ret <= 0) {
7794 : 0 : DRV_LOG(ERR, "Can't duplicate items.");
7795 : 0 : goto end;
7796 : : }
7797 : :
7798 : : /* Store flow actions. */
7799 : 0 : ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTIONS, NULL, 0, actions, &error);
7800 [ # # ]: 0 : if (ret <= 0) {
7801 : 0 : DRV_LOG(ERR, "Can't get actions length.");
7802 : 0 : goto end;
7803 : : }
7804 : 0 : len = RTE_ALIGN(ret, 16);
7805 : 0 : flow_info->actions = mlx5_malloc(MLX5_MEM_ZERO, len, 0, SOCKET_ID_ANY);
7806 [ # # ]: 0 : if (!flow_info->actions) {
7807 : 0 : DRV_LOG(ERR, "No enough memory for actions caching.");
7808 : 0 : goto end;
7809 : : }
7810 : 0 : ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTIONS, flow_info->actions, ret, actions, &error);
7811 [ # # ]: 0 : if (ret <= 0) {
7812 : 0 : DRV_LOG(ERR, "Can't duplicate actions.");
7813 : 0 : goto end;
7814 : : }
7815 : :
7816 : : /* Insert to the list end. */
7817 [ # # ]: 0 : if (LIST_EMPTY(&mode_info->hot_upgrade)) {
7818 : 0 : LIST_INSERT_HEAD(&mode_info->hot_upgrade, flow_info, next);
7819 : : } else {
7820 : : tmp_info = LIST_FIRST(&mode_info->hot_upgrade);
7821 [ # # ]: 0 : while (LIST_NEXT(tmp_info, next))
7822 : : tmp_info = LIST_NEXT(tmp_info, next);
7823 : 0 : LIST_INSERT_AFTER(tmp_info, flow_info, next);
7824 : : }
7825 : : return 0;
7826 : 0 : end:
7827 [ # # ]: 0 : if (flow_info->items)
7828 : 0 : mlx5_free(flow_info->items);
7829 [ # # ]: 0 : if (flow_info->actions)
7830 : 0 : mlx5_free(flow_info->actions);
7831 : 0 : mlx5_free(flow_info);
7832 : 0 : return -1;
7833 : : }
7834 : :
7835 : : static int
7836 : 0 : mlx5_flow_cache_flow_toggle(struct rte_eth_dev *dev, bool orig_prio)
7837 : : {
7838 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7839 : : struct rte_pmd_mlx5_flow_engine_mode_info *mode_info = &priv->mode_info;
7840 : : struct mlx5_dv_flow_info *flow_info;
7841 : : struct rte_flow_attr attr;
7842 : : struct rte_flow_error error;
7843 : : struct rte_flow *high, *low;
7844 : :
7845 : 0 : flow_info = LIST_FIRST(&mode_info->hot_upgrade);
7846 [ # # ]: 0 : while (flow_info) {
7847 : : /* DUP flow may have the same priority. */
7848 [ # # ]: 0 : if (flow_info->orig_prio != flow_info->attr.priority) {
7849 : 0 : attr = flow_info->attr;
7850 [ # # ]: 0 : if (orig_prio)
7851 : 0 : attr.priority = flow_info->orig_prio;
7852 : 0 : flow_info->flow_idx_high_prio = mlx5_flow_list_create(dev,
7853 : : MLX5_FLOW_TYPE_GEN, &attr,
7854 : 0 : flow_info->items, flow_info->actions,
7855 : : true, &error);
7856 [ # # ]: 0 : if (!flow_info->flow_idx_high_prio) {
7857 : 0 : DRV_LOG(ERR, "Priority toggle failed internally.");
7858 : 0 : goto err;
7859 : : }
7860 : : }
7861 : 0 : flow_info = LIST_NEXT(flow_info, next);
7862 : : }
7863 : : /* Delete the low priority rules and swap the flow handle. */
7864 : 0 : flow_info = LIST_FIRST(&mode_info->hot_upgrade);
7865 [ # # ]: 0 : while (flow_info) {
7866 : : MLX5_ASSERT(flow_info->flow_idx_low_prio);
7867 [ # # ]: 0 : if (flow_info->orig_prio != flow_info->attr.priority) {
7868 : 0 : high = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
7869 : : flow_info->flow_idx_high_prio);
7870 : 0 : low = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
7871 : : flow_info->flow_idx_low_prio);
7872 [ # # ]: 0 : if (high && low) {
7873 : 0 : RTE_SWAP(*low, *high);
7874 : 0 : mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN,
7875 : 0 : flow_info->flow_idx_low_prio);
7876 : 0 : flow_info->flow_idx_high_prio = 0;
7877 : : }
7878 : : }
7879 : 0 : flow_info = LIST_NEXT(flow_info, next);
7880 : : }
7881 : : return 0;
7882 : : err:
7883 : : /* Destroy preceding successful high priority rules. */
7884 : 0 : flow_info = LIST_FIRST(&mode_info->hot_upgrade);
7885 [ # # ]: 0 : while (flow_info) {
7886 [ # # ]: 0 : if (flow_info->orig_prio != flow_info->attr.priority) {
7887 [ # # ]: 0 : if (flow_info->flow_idx_high_prio)
7888 : 0 : mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN,
7889 : : flow_info->flow_idx_high_prio);
7890 : : else
7891 : : break;
7892 : 0 : flow_info->flow_idx_high_prio = 0;
7893 : : }
7894 : 0 : flow_info = LIST_NEXT(flow_info, next);
7895 : : }
7896 : : return -1;
7897 : : }
7898 : :
7899 : : /**
7900 : : * Set the mode of the flow engine of a process to active or standby during live migration.
7901 : : *
7902 : : * @param[in] mode
7903 : : * MLX5 flow engine mode, @see `enum rte_pmd_mlx5_flow_engine_mode`.
7904 : : * @param[in] flags
7905 : : * Flow engine mode specific flags.
7906 : : *
7907 : : * @return
7908 : : * Negative value on error, positive on success.
7909 : : */
7910 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_mlx5_flow_engine_set_mode, 23.03)
7911 : : int
7912 : 0 : rte_pmd_mlx5_flow_engine_set_mode(enum rte_pmd_mlx5_flow_engine_mode mode, uint32_t flags)
7913 : : {
7914 : : struct mlx5_priv *priv;
7915 : : struct rte_pmd_mlx5_flow_engine_mode_info *mode_info;
7916 : : struct mlx5_dv_flow_info *flow_info, *tmp_info;
7917 : : uint16_t port, port_id;
7918 : : uint16_t toggle_num = 0;
7919 : : struct rte_eth_dev *dev;
7920 : : enum rte_pmd_mlx5_flow_engine_mode orig_mode;
7921 : : uint32_t orig_flags;
7922 : : bool need_toggle = false;
7923 : :
7924 : : /* Check if flags combinations are supported. */
7925 [ # # ]: 0 : if (flags && flags != RTE_PMD_MLX5_FLOW_ENGINE_FLAG_STANDBY_DUP_INGRESS) {
7926 : 0 : DRV_LOG(ERR, "Doesn't support such flags %u", flags);
7927 : 0 : return -1;
7928 : : }
7929 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port, NULL) {
7930 : 0 : dev = &rte_eth_devices[port];
7931 : 0 : priv = dev->data->dev_private;
7932 : : mode_info = &priv->mode_info;
7933 : : /* No mode change. Assume all devices hold the same mode. */
7934 [ # # ]: 0 : if (mode_info->mode == mode) {
7935 : 0 : DRV_LOG(INFO, "Process flow engine has been in mode %u", mode);
7936 [ # # # # ]: 0 : if (mode_info->mode_flag != flags && !LIST_EMPTY(&mode_info->hot_upgrade)) {
7937 : 0 : DRV_LOG(ERR, "Port %u has rule cache with different flag %u\n",
7938 : : port, mode_info->mode_flag);
7939 : 0 : orig_mode = mode_info->mode;
7940 : 0 : orig_flags = mode_info->mode_flag;
7941 : 0 : goto err;
7942 : : }
7943 : 0 : mode_info->mode_flag = flags;
7944 : 0 : toggle_num++;
7945 : 0 : continue;
7946 : : }
7947 : : /* Active -> standby. */
7948 [ # # ]: 0 : if (mode == RTE_PMD_MLX5_FLOW_ENGINE_MODE_STANDBY) {
7949 [ # # ]: 0 : if (!LIST_EMPTY(&mode_info->hot_upgrade)) {
7950 : 0 : DRV_LOG(ERR, "Cached rule existed");
7951 : 0 : orig_mode = mode_info->mode;
7952 : 0 : orig_flags = mode_info->mode_flag;
7953 : 0 : goto err;
7954 : : }
7955 : 0 : mode_info->mode_flag = flags;
7956 : 0 : mode_info->mode = mode;
7957 : 0 : toggle_num++;
7958 : : /* Standby -> active. */
7959 [ # # ]: 0 : } else if (mode == RTE_PMD_MLX5_FLOW_ENGINE_MODE_ACTIVE) {
7960 [ # # ]: 0 : if (LIST_EMPTY(&mode_info->hot_upgrade)) {
7961 : 0 : DRV_LOG(INFO, "No cached rule existed");
7962 : : } else {
7963 [ # # ]: 0 : if (mlx5_flow_cache_flow_toggle(dev, true)) {
7964 : 0 : orig_mode = mode_info->mode;
7965 : 0 : orig_flags = mode_info->mode_flag;
7966 : : need_toggle = true;
7967 : 0 : goto err;
7968 : : }
7969 : : }
7970 : 0 : toggle_num++;
7971 : : }
7972 : : }
7973 [ # # ]: 0 : if (mode == RTE_PMD_MLX5_FLOW_ENGINE_MODE_ACTIVE) {
7974 : : /* Clear cache flow rules. */
7975 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port, NULL) {
7976 : 0 : priv = rte_eth_devices[port].data->dev_private;
7977 : : mode_info = &priv->mode_info;
7978 : 0 : flow_info = LIST_FIRST(&mode_info->hot_upgrade);
7979 [ # # ]: 0 : while (flow_info) {
7980 : 0 : tmp_info = LIST_NEXT(flow_info, next);
7981 [ # # ]: 0 : LIST_REMOVE(flow_info, next);
7982 : 0 : mlx5_free(flow_info->actions);
7983 : 0 : mlx5_free(flow_info->items);
7984 : 0 : mlx5_free(flow_info);
7985 : : flow_info = tmp_info;
7986 : : }
7987 : : MLX5_ASSERT(LIST_EMPTY(&mode_info->hot_upgrade));
7988 : : }
7989 : : }
7990 : 0 : return toggle_num;
7991 : 0 : err:
7992 : : /* Rollback all preceding successful ports. */
7993 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port_id, NULL) {
7994 [ # # ]: 0 : if (port_id == port)
7995 : : break;
7996 : 0 : priv = rte_eth_devices[port_id].data->dev_private;
7997 : : mode_info = &priv->mode_info;
7998 [ # # # # : 0 : if (need_toggle && !LIST_EMPTY(&mode_info->hot_upgrade) &&
# # ]
7999 : 0 : mlx5_flow_cache_flow_toggle(dev, false))
8000 : : return -EPERM;
8001 : 0 : mode_info->mode = orig_mode;
8002 : 0 : mode_info->mode_flag = orig_flags;
8003 : : }
8004 : : return -EINVAL;
8005 : : }
8006 : : /**
8007 : : * Create a flow.
8008 : : *
8009 : : * @see rte_flow_create()
8010 : : * @see rte_flow_ops
8011 : : */
8012 : : struct rte_flow *
8013 : 0 : mlx5_flow_create(struct rte_eth_dev *dev,
8014 : : const struct rte_flow_attr *attr,
8015 : : const struct rte_flow_item items[],
8016 : : const struct rte_flow_action actions[],
8017 : : struct rte_flow_error *error)
8018 : : {
8019 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8020 : : struct rte_flow_attr *new_attr = (void *)(uintptr_t)attr;
8021 : 0 : uint32_t prio = attr->priority;
8022 : : uintptr_t flow_idx;
8023 : :
8024 : : /*
8025 : : * If the device is not started yet, it is not allowed to created a
8026 : : * flow from application. PMD default flows and traffic control flows
8027 : : * are not affected.
8028 : : */
8029 [ # # ]: 0 : if (unlikely(!dev->data->dev_started)) {
8030 : 0 : DRV_LOG(DEBUG, "port %u is not started when "
8031 : : "inserting a flow", dev->data->port_id);
8032 : 0 : rte_flow_error_set(error, ENODEV,
8033 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8034 : : NULL,
8035 : : "port not started");
8036 : 0 : return NULL;
8037 : : }
8038 [ # # ]: 0 : if (unlikely(mlx5_need_cache_flow(priv, attr))) {
8039 [ # # ]: 0 : if (attr->transfer ||
8040 [ # # # # ]: 0 : (attr->ingress && !(priv->mode_info.mode_flag &
8041 : : RTE_PMD_MLX5_FLOW_ENGINE_FLAG_STANDBY_DUP_INGRESS)))
8042 : 0 : new_attr->priority += 1;
8043 : : }
8044 : 0 : flow_idx = mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_GEN, attr, items, actions,
8045 : : true, error);
8046 [ # # ]: 0 : if (!flow_idx)
8047 : : return NULL;
8048 [ # # ]: 0 : if (unlikely(mlx5_need_cache_flow(priv, attr))) {
8049 [ # # ]: 0 : if (mlx5_flow_cache_flow_info(dev, attr, prio, items, actions, flow_idx)) {
8050 : 0 : mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN, flow_idx);
8051 : : flow_idx = 0;
8052 : : }
8053 : : }
8054 : 0 : return (void *)(uintptr_t)flow_idx;
8055 : : }
8056 : :
8057 : : uintptr_t
8058 : 0 : mlx5_flow_list_create(struct rte_eth_dev *dev, enum mlx5_flow_type type,
8059 : : const struct rte_flow_attr *attr,
8060 : : const struct rte_flow_item items[],
8061 : : const struct rte_flow_action actions[],
8062 : : bool external, struct rte_flow_error *error)
8063 : : {
8064 : : const struct mlx5_flow_driver_ops *fops;
8065 : 0 : enum mlx5_flow_drv_type drv_type = flow_get_drv_type(dev, attr);
8066 : :
8067 : 0 : fops = flow_get_drv_ops(drv_type);
8068 : 0 : return fops->list_create(dev, type, attr, items, actions, external,
8069 : : error);
8070 : : }
8071 : :
8072 : : /**
8073 : : * Destroy a flow in a list.
8074 : : *
8075 : : * @param dev
8076 : : * Pointer to Ethernet device.
8077 : : * @param[in] flow_idx
8078 : : * Index of flow to destroy.
8079 : : */
8080 : : void
8081 : 0 : mlx5_flow_legacy_list_destroy(struct rte_eth_dev *dev, enum mlx5_flow_type type,
8082 : : uintptr_t flow_idx)
8083 : : {
8084 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8085 : 0 : struct rte_flow *flow = mlx5_ipool_get(priv->flows[type], (uint32_t)flow_idx);
8086 : :
8087 [ # # ]: 0 : if (!flow)
8088 : : return;
8089 : : MLX5_ASSERT(type < MLX5_FLOW_TYPE_MAXI);
8090 : : MLX5_ASSERT(flow->type == type);
8091 : : /*
8092 : : * Update RX queue flags only if port is started, otherwise it is
8093 : : * already clean.
8094 : : */
8095 [ # # ]: 0 : if (dev->data->dev_started)
8096 : 0 : flow_rxq_flags_trim(dev, flow);
8097 : : flow_drv_destroy(dev, flow);
8098 [ # # ]: 0 : if (flow->tunnel) {
8099 : : struct mlx5_flow_tunnel *tunnel;
8100 : :
8101 : 0 : tunnel = mlx5_find_tunnel_id(dev, flow->tunnel_id);
8102 : 0 : RTE_VERIFY(tunnel);
8103 [ # # ]: 0 : if (!(rte_atomic_fetch_sub_explicit(&tunnel->refctn, 1,
8104 : : rte_memory_order_relaxed) - 1))
8105 : 0 : mlx5_flow_tunnel_free(dev, tunnel);
8106 : : }
8107 : 0 : flow_mreg_del_copy_action(dev, flow);
8108 : 0 : mlx5_ipool_free(priv->flows[type], flow_idx);
8109 : : }
8110 : :
8111 : : void
8112 [ # # ]: 0 : mlx5_flow_list_destroy(struct rte_eth_dev *dev, enum mlx5_flow_type type,
8113 : : uintptr_t flow_idx)
8114 : : {
8115 : : const struct mlx5_flow_driver_ops *fops;
8116 : : struct rte_flow_attr attr = { .transfer = 0 };
8117 : : enum mlx5_flow_drv_type drv_type = flow_get_drv_type(dev, &attr);
8118 : :
8119 : 0 : fops = flow_get_drv_ops(drv_type);
8120 : 0 : fops->list_destroy(dev, type, flow_idx);
8121 : 0 : }
8122 : :
8123 : : /**
8124 : : * Destroy all flows.
8125 : : *
8126 : : * @param dev
8127 : : * Pointer to Ethernet device.
8128 : : * @param type
8129 : : * Flow type to be flushed.
8130 : : * @param active
8131 : : * If flushing is called actively.
8132 : : */
8133 : : void
8134 : 0 : mlx5_flow_list_flush(struct rte_eth_dev *dev, enum mlx5_flow_type type,
8135 : : bool active)
8136 : : {
8137 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8138 : 0 : uint32_t num_flushed = 0, fidx = 1;
8139 : : struct rte_flow *flow;
8140 : : struct rte_pmd_mlx5_flow_engine_mode_info *mode_info = &priv->mode_info;
8141 : : struct mlx5_dv_flow_info *flow_info;
8142 : :
8143 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
8144 [ # # # # ]: 0 : if (priv->sh->config.dv_flow_en == 2 &&
8145 : : type == MLX5_FLOW_TYPE_GEN) {
8146 : 0 : priv->hws_rule_flushing = true;
8147 : 0 : mlx5_flow_hw_q_flow_flush(dev, NULL);
8148 : 0 : priv->hws_rule_flushing = false;
8149 : : }
8150 : : #endif
8151 [ # # ]: 0 : MLX5_IPOOL_FOREACH(priv->flows[type], fidx, flow) {
8152 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2) {
8153 : 0 : mlx5_flow_list_destroy(dev, type, (uintptr_t)flow);
8154 : : } else {
8155 : 0 : mlx5_flow_list_destroy(dev, type, fidx);
8156 : : }
8157 [ # # # # ]: 0 : if (unlikely(mlx5_need_cache_flow(priv, NULL) && type == MLX5_FLOW_TYPE_GEN)) {
8158 : 0 : flow_info = LIST_FIRST(&mode_info->hot_upgrade);
8159 [ # # ]: 0 : while (flow_info) {
8160 : : /* Romove the cache flow info. */
8161 [ # # ]: 0 : if (flow_info->flow_idx_low_prio == (uint32_t)(uintptr_t)fidx) {
8162 : : MLX5_ASSERT(!flow_info->flow_idx_high_prio);
8163 [ # # ]: 0 : LIST_REMOVE(flow_info, next);
8164 : 0 : mlx5_free(flow_info->items);
8165 : 0 : mlx5_free(flow_info->actions);
8166 : 0 : mlx5_free(flow_info);
8167 : 0 : break;
8168 : : }
8169 : 0 : flow_info = LIST_NEXT(flow_info, next);
8170 : : }
8171 : : }
8172 : 0 : num_flushed++;
8173 : : }
8174 [ # # ]: 0 : if (active) {
8175 : 0 : DRV_LOG(INFO, "port %u: %u flows flushed before stopping",
8176 : : dev->data->port_id, num_flushed);
8177 : : }
8178 : 0 : }
8179 : :
8180 : : /**
8181 : : * Stop all default actions for flows.
8182 : : *
8183 : : * @param dev
8184 : : * Pointer to Ethernet device.
8185 : : */
8186 : : void
8187 : 0 : mlx5_flow_stop_default(struct rte_eth_dev *dev)
8188 : : {
8189 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8190 : :
8191 [ # # ]: 0 : if (mlx5_flow_is_steering_disabled())
8192 : : return;
8193 : :
8194 : : #ifdef HAVE_MLX5_HWS_SUPPORT
8195 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2) {
8196 : 0 : mlx5_flow_nta_del_default_copy_action(dev);
8197 [ # # ]: 0 : if (!rte_atomic_load_explicit(&priv->hws_mark_refcnt,
8198 : : rte_memory_order_relaxed))
8199 : 0 : mlx5_flow_hw_rxq_flag_set(dev, false);
8200 : 0 : return;
8201 : : }
8202 : : #else
8203 : : RTE_SET_USED(priv);
8204 : : #endif
8205 : 0 : flow_mreg_del_default_copy_action(dev);
8206 : 0 : mlx5_flow_rxq_flags_clear(dev);
8207 : : }
8208 : :
8209 : : /**
8210 : : * Set rxq flag.
8211 : : *
8212 : : * @param[in] dev
8213 : : * Pointer to the rte_eth_dev structure.
8214 : : * @param[in] enable
8215 : : * Flag to enable or not.
8216 : : */
8217 : : void
8218 : 0 : mlx5_flow_hw_rxq_flag_set(struct rte_eth_dev *dev, bool enable)
8219 : : {
8220 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8221 : : unsigned int i;
8222 : :
8223 [ # # # # : 0 : if ((!priv->mark_enabled && !enable) ||
# # ]
8224 [ # # ]: 0 : (priv->mark_enabled && enable))
8225 : : return;
8226 [ # # ]: 0 : for (i = 0; i < priv->rxqs_n; ++i) {
8227 : 0 : struct mlx5_rxq_ctrl *rxq_ctrl = mlx5_rxq_ctrl_get(dev, i);
8228 : :
8229 : : /* With RXQ start/stop feature, RXQ might be stopped. */
8230 [ # # ]: 0 : if (!rxq_ctrl)
8231 : 0 : continue;
8232 : 0 : rxq_ctrl->rxq.mark = enable;
8233 : : }
8234 : 0 : priv->mark_enabled = enable;
8235 : : }
8236 : :
8237 : : /**
8238 : : * Start all default actions for flows.
8239 : : *
8240 : : * @param dev
8241 : : * Pointer to Ethernet device.
8242 : : * @return
8243 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
8244 : : */
8245 : : int
8246 : 0 : mlx5_flow_start_default(struct rte_eth_dev *dev)
8247 : : {
8248 : : struct rte_flow_error error;
8249 : :
8250 [ # # ]: 0 : if (mlx5_flow_is_steering_disabled())
8251 : : return 0;
8252 : :
8253 : : #ifdef HAVE_MLX5_HWS_SUPPORT
8254 [ # # ]: 0 : if (MLX5_SH(dev)->config.dv_flow_en == 2) {
8255 : : /*
8256 : : * Ignore this failure, if the proxy port is not started, other
8257 : : * default jump actions are not created and this rule will not
8258 : : * be hit.
8259 : : */
8260 [ # # ]: 0 : if (mlx5_flow_nta_add_default_copy_action(dev, &error)) {
8261 : 0 : DRV_LOG(DEBUG, "port %u failed to start default copy action: %s",
8262 : : dev->data->port_id, strerror(rte_errno));
8263 : 0 : return 0;
8264 : : }
8265 : : }
8266 : : #endif
8267 : : /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
8268 : 0 : return flow_mreg_add_default_copy_action(dev, &error);
8269 : : }
8270 : :
8271 : : /**
8272 : : * Release key of thread specific flow workspace data.
8273 : : */
8274 : : void
8275 : 0 : mlx5_flow_release_workspace(void *data)
8276 : : {
8277 : : struct mlx5_flow_workspace *wks = data;
8278 : : struct mlx5_flow_workspace *next;
8279 : :
8280 [ # # ]: 0 : while (wks) {
8281 : 0 : next = wks->next;
8282 : 0 : free(wks);
8283 : : wks = next;
8284 : : }
8285 : 0 : }
8286 : :
8287 : : /**
8288 : : * Get thread specific current flow workspace.
8289 : : *
8290 : : * @return pointer to thread specific flow workspace data, NULL on error.
8291 : : */
8292 : : struct mlx5_flow_workspace*
8293 : 0 : mlx5_flow_get_thread_workspace(void)
8294 : : {
8295 : : struct mlx5_flow_workspace *data;
8296 : :
8297 : 0 : data = mlx5_flow_os_get_specific_workspace();
8298 : : MLX5_ASSERT(data && data->inuse);
8299 [ # # # # ]: 0 : if (!data || !data->inuse)
8300 : 0 : DRV_LOG(ERR, "flow workspace not initialized.");
8301 : 0 : return data;
8302 : : }
8303 : :
8304 : : /**
8305 : : * Allocate and init new flow workspace.
8306 : : *
8307 : : * @return pointer to flow workspace data, NULL on error.
8308 : : */
8309 : : static struct mlx5_flow_workspace*
8310 : 0 : flow_alloc_thread_workspace(void)
8311 : : {
8312 : : size_t data_size = RTE_ALIGN(sizeof(struct mlx5_flow_workspace), sizeof(long));
8313 : : size_t rss_queue_array_size = sizeof(uint16_t) * RTE_ETH_RSS_RETA_SIZE_512;
8314 : : size_t alloc_size = data_size + rss_queue_array_size;
8315 : : #ifdef HAVE_MLX5_HWS_SUPPORT
8316 : : /* Dummy table size for the non-template API. */
8317 : : alloc_size += sizeof(struct rte_flow_template_table);
8318 : : #endif
8319 : 0 : struct mlx5_flow_workspace *data = calloc(1, alloc_size);
8320 : :
8321 [ # # ]: 0 : if (!data) {
8322 : 0 : DRV_LOG(ERR, "Failed to allocate flow workspace memory.");
8323 : 0 : return NULL;
8324 : : }
8325 : 0 : data->rss_desc.queue = RTE_PTR_ADD(data, data_size);
8326 : : #ifdef HAVE_MLX5_HWS_SUPPORT
8327 : 0 : data->table = RTE_PTR_ADD(data->rss_desc.queue, rss_queue_array_size);
8328 : : #endif
8329 : 0 : return data;
8330 : : }
8331 : :
8332 : : /**
8333 : : * Get new thread specific flow workspace.
8334 : : *
8335 : : * If current workspace inuse, create new one and set as current.
8336 : : *
8337 : : * @return pointer to thread specific flow workspace data, NULL on error.
8338 : : */
8339 : : struct mlx5_flow_workspace*
8340 : 0 : mlx5_flow_push_thread_workspace(void)
8341 : : {
8342 : : struct mlx5_flow_workspace *curr;
8343 : : struct mlx5_flow_workspace *data;
8344 : :
8345 : 0 : curr = mlx5_flow_os_get_specific_workspace();
8346 [ # # ]: 0 : if (!curr) {
8347 : 0 : data = flow_alloc_thread_workspace();
8348 [ # # ]: 0 : if (!data)
8349 : : return NULL;
8350 : 0 : mlx5_flow_os_workspace_gc_add(data);
8351 [ # # ]: 0 : } else if (!curr->inuse) {
8352 : : data = curr;
8353 [ # # ]: 0 : } else if (curr->next) {
8354 : : data = curr->next;
8355 : : } else {
8356 : 0 : data = flow_alloc_thread_workspace();
8357 [ # # ]: 0 : if (!data)
8358 : : return NULL;
8359 : 0 : curr->next = data;
8360 : 0 : data->prev = curr;
8361 : : }
8362 : 0 : data->inuse = 1;
8363 : 0 : data->flow_idx = 0;
8364 : : /* Set as current workspace */
8365 [ # # ]: 0 : if (mlx5_flow_os_set_specific_workspace(data))
8366 : 0 : DRV_LOG(ERR, "Failed to set flow workspace to thread.");
8367 : : return data;
8368 : : }
8369 : :
8370 : : /**
8371 : : * Close current thread specific flow workspace.
8372 : : *
8373 : : * If previous workspace available, set it as current.
8374 : : *
8375 : : * @return pointer to thread specific flow workspace data, NULL on error.
8376 : : */
8377 : : void
8378 : 0 : mlx5_flow_pop_thread_workspace(void)
8379 : : {
8380 : 0 : struct mlx5_flow_workspace *data = mlx5_flow_get_thread_workspace();
8381 : :
8382 [ # # ]: 0 : if (!data)
8383 : : return;
8384 [ # # ]: 0 : if (!data->inuse) {
8385 : 0 : DRV_LOG(ERR, "Failed to close unused flow workspace.");
8386 : 0 : return;
8387 : : }
8388 : 0 : data->inuse = 0;
8389 [ # # ]: 0 : if (!data->prev)
8390 : : return;
8391 [ # # ]: 0 : if (mlx5_flow_os_set_specific_workspace(data->prev))
8392 : 0 : DRV_LOG(ERR, "Failed to set flow workspace to thread.");
8393 : : }
8394 : :
8395 : : /**
8396 : : * Verify the flow list is empty
8397 : : *
8398 : : * @param dev
8399 : : * Pointer to Ethernet device.
8400 : : *
8401 : : * @return the number of flows not released.
8402 : : */
8403 : : int
8404 : 0 : mlx5_flow_verify(struct rte_eth_dev *dev __rte_unused)
8405 : : {
8406 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8407 : : struct rte_flow *flow;
8408 : : uint32_t idx = 0;
8409 : : int ret = 0, i;
8410 : :
8411 [ # # ]: 0 : for (i = 0; i < MLX5_FLOW_TYPE_MAXI; i++) {
8412 [ # # ]: 0 : MLX5_IPOOL_FOREACH(priv->flows[i], idx, flow) {
8413 : 0 : DRV_LOG(DEBUG, "port %u flow %p still referenced",
8414 : : dev->data->port_id, (void *)flow);
8415 : 0 : ret++;
8416 : : }
8417 : : }
8418 : 0 : return ret;
8419 : : }
8420 : :
8421 : : /**
8422 : : * Enable default hairpin egress flow.
8423 : : *
8424 : : * @param dev
8425 : : * Pointer to Ethernet device.
8426 : : * @param sq_num
8427 : : * The SQ hw number.
8428 : : *
8429 : : * @return
8430 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
8431 : : */
8432 : : int
8433 : 0 : mlx5_ctrl_flow_source_queue(struct rte_eth_dev *dev,
8434 : : uint32_t sq_num)
8435 : : {
8436 : 0 : const struct rte_flow_attr attr = {
8437 : : .egress = 1,
8438 : : .priority = 0,
8439 : : };
8440 : 0 : struct mlx5_rte_flow_item_sq queue_spec = {
8441 : : .queue = sq_num,
8442 : : };
8443 : 0 : struct mlx5_rte_flow_item_sq queue_mask = {
8444 : : .queue = UINT32_MAX,
8445 : : };
8446 : 0 : struct rte_flow_item items[] = {
8447 : : {
8448 : : .type = (enum rte_flow_item_type)
8449 : : MLX5_RTE_FLOW_ITEM_TYPE_SQ,
8450 : : .spec = &queue_spec,
8451 : : .last = NULL,
8452 : : .mask = &queue_mask,
8453 : : },
8454 : : {
8455 : : .type = RTE_FLOW_ITEM_TYPE_END,
8456 : : },
8457 : : };
8458 : 0 : struct rte_flow_action_jump jump = {
8459 : : .group = MLX5_HAIRPIN_TX_TABLE,
8460 : : };
8461 : : struct rte_flow_action actions[2];
8462 : : uint32_t flow_idx;
8463 : : struct rte_flow_error error;
8464 : :
8465 : 0 : actions[0].type = RTE_FLOW_ACTION_TYPE_JUMP;
8466 : 0 : actions[0].conf = &jump;
8467 : 0 : actions[1].type = RTE_FLOW_ACTION_TYPE_END;
8468 : 0 : flow_idx = mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
8469 : : &attr, items, actions, false, &error);
8470 [ # # ]: 0 : if (!flow_idx) {
8471 [ # # ]: 0 : DRV_LOG(DEBUG,
8472 : : "Failed to create ctrl flow: rte_errno(%d),"
8473 : : " type(%d), message(%s)",
8474 : : rte_errno, error.type,
8475 : : error.message ? error.message : " (no stated reason)");
8476 : 0 : return -rte_errno;
8477 : : }
8478 : : return 0;
8479 : : }
8480 : :
8481 : : /**
8482 : : * Enable a control flow configured from the control plane.
8483 : : *
8484 : : * @param dev
8485 : : * Pointer to Ethernet device.
8486 : : * @param eth_spec
8487 : : * An Ethernet flow spec to apply.
8488 : : * @param eth_mask
8489 : : * An Ethernet flow mask to apply.
8490 : : * @param vlan_spec
8491 : : * A VLAN flow spec to apply.
8492 : : * @param vlan_mask
8493 : : * A VLAN flow mask to apply.
8494 : : *
8495 : : * @return
8496 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
8497 : : */
8498 : : int
8499 : 0 : mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
8500 : : struct rte_flow_item_eth *eth_spec,
8501 : : struct rte_flow_item_eth *eth_mask,
8502 : : struct rte_flow_item_vlan *vlan_spec,
8503 : : struct rte_flow_item_vlan *vlan_mask)
8504 : : {
8505 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8506 : 0 : const struct rte_flow_attr attr = {
8507 : : .ingress = 1,
8508 : : .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
8509 : : };
8510 : 0 : struct rte_flow_item items[] = {
8511 : : {
8512 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
8513 : : .spec = eth_spec,
8514 : : .last = NULL,
8515 : : .mask = eth_mask,
8516 : : },
8517 : : {
8518 [ # # ]: 0 : .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
8519 : : RTE_FLOW_ITEM_TYPE_END,
8520 : : .spec = vlan_spec,
8521 : : .last = NULL,
8522 : : .mask = vlan_mask,
8523 : : },
8524 : : {
8525 : : .type = RTE_FLOW_ITEM_TYPE_END,
8526 : : },
8527 : : };
8528 : 0 : uint16_t *queue = alloca(sizeof(uint16_t) * priv->reta_idx_n);
8529 : 0 : struct rte_flow_action_rss action_rss = {
8530 : : .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
8531 : : .level = 0,
8532 : 0 : .types = priv->rss_conf.rss_hf,
8533 : 0 : .key_len = priv->rss_conf.rss_key_len,
8534 : : .queue_num = priv->reta_idx_n,
8535 : 0 : .key = priv->rss_conf.rss_key,
8536 : : .queue = queue,
8537 : : };
8538 : 0 : struct rte_flow_action actions[] = {
8539 : : {
8540 : : .type = RTE_FLOW_ACTION_TYPE_RSS,
8541 : : .conf = &action_rss,
8542 : : },
8543 : : {
8544 : : .type = RTE_FLOW_ACTION_TYPE_END,
8545 : : },
8546 : : };
8547 : : uintptr_t flow_idx;
8548 : : struct rte_flow_error error;
8549 : : struct mlx5_ctrl_flow_entry *entry;
8550 : : unsigned int i;
8551 : :
8552 [ # # # # ]: 0 : if (!priv->reta_idx_n || !priv->rxqs_n) {
8553 : : return 0;
8554 : : }
8555 [ # # ]: 0 : if (!(dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG))
8556 : 0 : action_rss.types = 0;
8557 [ # # ]: 0 : for (i = 0; i != priv->reta_idx_n; ++i)
8558 : 0 : queue[i] = (*priv->reta_idx)[i];
8559 : :
8560 : 0 : entry = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*entry), alignof(typeof(*entry)), SOCKET_ID_ANY);
8561 [ # # ]: 0 : if (entry == NULL) {
8562 : 0 : rte_errno = ENOMEM;
8563 : 0 : goto err;
8564 : : }
8565 : :
8566 : 0 : entry->owner_dev = dev;
8567 [ # # ]: 0 : if (vlan_spec == NULL) {
8568 : 0 : entry->info.type = MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC;
8569 : : } else {
8570 : 0 : entry->info.type = MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC_VLAN;
8571 [ # # ]: 0 : entry->info.uc.vlan = rte_be_to_cpu_16(vlan_spec->hdr.vlan_tci);
8572 : : }
8573 : 0 : entry->info.uc.dmac = eth_spec->hdr.dst_addr;
8574 : :
8575 : 0 : flow_idx = mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
8576 : : &attr, items, actions, false, &error);
8577 [ # # ]: 0 : if (!flow_idx) {
8578 : 0 : mlx5_free(entry);
8579 : 0 : goto err;
8580 : : }
8581 : :
8582 : 0 : entry->flow = (struct rte_flow *)flow_idx;
8583 [ # # ]: 0 : LIST_INSERT_HEAD(&priv->hw_ctrl_flows, entry, next);
8584 : :
8585 : 0 : return 0;
8586 : :
8587 : 0 : err:
8588 : 0 : return -rte_errno;
8589 : : }
8590 : :
8591 : : /**
8592 : : * Enable a flow control configured from the control plane.
8593 : : *
8594 : : * @param dev
8595 : : * Pointer to Ethernet device.
8596 : : * @param eth_spec
8597 : : * An Ethernet flow spec to apply.
8598 : : * @param eth_mask
8599 : : * An Ethernet flow mask to apply.
8600 : : *
8601 : : * @return
8602 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
8603 : : */
8604 : : int
8605 : 0 : mlx5_ctrl_flow(struct rte_eth_dev *dev,
8606 : : struct rte_flow_item_eth *eth_spec,
8607 : : struct rte_flow_item_eth *eth_mask)
8608 : : {
8609 : 0 : return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
8610 : : }
8611 : :
8612 : : int
8613 : 0 : mlx5_legacy_dmac_flow_create(struct rte_eth_dev *dev, const struct rte_ether_addr *addr)
8614 : : {
8615 : 0 : struct rte_flow_item_eth unicast = {
8616 : : .hdr.dst_addr = *addr,
8617 : : };
8618 : 0 : struct rte_flow_item_eth unicast_mask = {
8619 : : .hdr.dst_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
8620 : : };
8621 : :
8622 : 0 : return mlx5_ctrl_flow(dev, &unicast, &unicast_mask);
8623 : : }
8624 : :
8625 : : int
8626 : 0 : mlx5_legacy_dmac_vlan_flow_create(struct rte_eth_dev *dev,
8627 : : const struct rte_ether_addr *addr,
8628 : : const uint16_t vid)
8629 : : {
8630 : 0 : struct rte_flow_item_eth unicast_spec = {
8631 : : .hdr.dst_addr = *addr,
8632 : : };
8633 : 0 : struct rte_flow_item_eth unicast_mask = {
8634 : : .hdr.dst_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
8635 : : };
8636 : 0 : struct rte_flow_item_vlan vlan_spec = {
8637 [ # # ]: 0 : .hdr.vlan_tci = rte_cpu_to_be_16(vid),
8638 : : };
8639 : 0 : struct rte_flow_item_vlan vlan_mask = rte_flow_item_vlan_mask;
8640 : :
8641 : 0 : return mlx5_ctrl_flow_vlan(dev, &unicast_spec, &unicast_mask, &vlan_spec, &vlan_mask);
8642 : : }
8643 : :
8644 : : void
8645 : 0 : mlx5_legacy_ctrl_flow_destroy(struct rte_eth_dev *dev, struct mlx5_ctrl_flow_entry *entry)
8646 : : {
8647 : : uintptr_t flow_idx;
8648 : :
8649 : 0 : flow_idx = (uintptr_t)entry->flow;
8650 : 0 : mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_CTL, flow_idx);
8651 [ # # ]: 0 : LIST_REMOVE(entry, next);
8652 : 0 : mlx5_free(entry);
8653 : 0 : }
8654 : :
8655 : : int
8656 : 0 : mlx5_legacy_dmac_flow_destroy(struct rte_eth_dev *dev, const struct rte_ether_addr *addr)
8657 : : {
8658 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8659 : : struct mlx5_ctrl_flow_entry *entry;
8660 : :
8661 [ # # ]: 0 : LIST_FOREACH(entry, &priv->hw_ctrl_flows, next) {
8662 [ # # # # ]: 0 : if (entry->info.type != MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC ||
8663 : : !rte_is_same_ether_addr(addr, &entry->info.uc.dmac))
8664 : : continue;
8665 : :
8666 : 0 : mlx5_legacy_ctrl_flow_destroy(dev, entry);
8667 : 0 : return 0;
8668 : : }
8669 : : return 0;
8670 : : }
8671 : :
8672 : : int
8673 : 0 : mlx5_legacy_dmac_vlan_flow_destroy(struct rte_eth_dev *dev,
8674 : : const struct rte_ether_addr *addr,
8675 : : const uint16_t vid)
8676 : : {
8677 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8678 : : struct mlx5_ctrl_flow_entry *entry;
8679 : :
8680 [ # # ]: 0 : LIST_FOREACH(entry, &priv->hw_ctrl_flows, next) {
8681 [ # # # # ]: 0 : if (entry->info.type != MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC_VLAN ||
8682 : 0 : !rte_is_same_ether_addr(addr, &entry->info.uc.dmac) ||
8683 [ # # ]: 0 : vid != entry->info.uc.vlan)
8684 : : continue;
8685 : :
8686 : 0 : mlx5_legacy_ctrl_flow_destroy(dev, entry);
8687 : 0 : return 0;
8688 : : }
8689 : : return 0;
8690 : : }
8691 : :
8692 : : /**
8693 : : * Create default miss flow rule matching lacp traffic
8694 : : *
8695 : : * @param dev
8696 : : * Pointer to Ethernet device.
8697 : : * @param eth_spec
8698 : : * An Ethernet flow spec to apply.
8699 : : *
8700 : : * @return
8701 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
8702 : : */
8703 : : int
8704 : 0 : mlx5_flow_lacp_miss(struct rte_eth_dev *dev)
8705 : : {
8706 : : /*
8707 : : * The LACP matching is done by only using ether type since using
8708 : : * a multicast dst mac causes kernel to give low priority to this flow.
8709 : : */
8710 : : static const struct rte_flow_item_eth lacp_spec = {
8711 : : .hdr.ether_type = RTE_BE16(0x8809),
8712 : : };
8713 : : static const struct rte_flow_item_eth lacp_mask = {
8714 : : .hdr.ether_type = 0xffff,
8715 : : };
8716 : 0 : const struct rte_flow_attr attr = {
8717 : : .ingress = 1,
8718 : : };
8719 : 0 : struct rte_flow_item items[] = {
8720 : : {
8721 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
8722 : : .spec = &lacp_spec,
8723 : : .mask = &lacp_mask,
8724 : : },
8725 : : {
8726 : : .type = RTE_FLOW_ITEM_TYPE_END,
8727 : : },
8728 : : };
8729 : 0 : struct rte_flow_action actions[] = {
8730 : : {
8731 : : .type = (enum rte_flow_action_type)
8732 : : MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
8733 : : },
8734 : : {
8735 : : .type = RTE_FLOW_ACTION_TYPE_END,
8736 : : },
8737 : : };
8738 : : struct rte_flow_error error;
8739 : 0 : uint32_t flow_idx = mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
8740 : : &attr, items, actions,
8741 : : false, &error);
8742 : :
8743 [ # # ]: 0 : if (!flow_idx)
8744 : 0 : return -rte_errno;
8745 : : return 0;
8746 : : }
8747 : :
8748 : : /**
8749 : : * Destroy a flow.
8750 : : *
8751 : : * @see rte_flow_destroy()
8752 : : * @see rte_flow_ops
8753 : : */
8754 : : int
8755 : 0 : mlx5_flow_destroy(struct rte_eth_dev *dev,
8756 : : struct rte_flow *flow,
8757 : : struct rte_flow_error *error __rte_unused)
8758 : : {
8759 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8760 : : struct rte_pmd_mlx5_flow_engine_mode_info *mode_info = &priv->mode_info;
8761 : : struct mlx5_dv_flow_info *flow_info;
8762 : :
8763 : 0 : mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN,
8764 : : (uintptr_t)(void *)flow);
8765 [ # # ]: 0 : if (unlikely(mlx5_need_cache_flow(priv, NULL))) {
8766 : 0 : flow_info = LIST_FIRST(&mode_info->hot_upgrade);
8767 [ # # ]: 0 : while (flow_info) {
8768 : : /* Romove the cache flow info. */
8769 [ # # ]: 0 : if (flow_info->flow_idx_low_prio == (uint32_t)(uintptr_t)flow) {
8770 : : MLX5_ASSERT(!flow_info->flow_idx_high_prio);
8771 [ # # ]: 0 : LIST_REMOVE(flow_info, next);
8772 : 0 : mlx5_free(flow_info->items);
8773 : 0 : mlx5_free(flow_info->actions);
8774 : 0 : mlx5_free(flow_info);
8775 : 0 : break;
8776 : : }
8777 : 0 : flow_info = LIST_NEXT(flow_info, next);
8778 : : }
8779 : : }
8780 : 0 : return 0;
8781 : : }
8782 : :
8783 : : /**
8784 : : * Destroy all flows.
8785 : : *
8786 : : * @see rte_flow_flush()
8787 : : * @see rte_flow_ops
8788 : : */
8789 : : int
8790 : 0 : mlx5_flow_flush(struct rte_eth_dev *dev,
8791 : : struct rte_flow_error *error __rte_unused)
8792 : : {
8793 : 0 : mlx5_flow_list_flush(dev, MLX5_FLOW_TYPE_GEN, false);
8794 : 0 : return 0;
8795 : : }
8796 : :
8797 : : /**
8798 : : * Isolated mode.
8799 : : *
8800 : : * @see rte_flow_isolate()
8801 : : * @see rte_flow_ops
8802 : : */
8803 : : int
8804 : 0 : mlx5_flow_isolate(struct rte_eth_dev *dev,
8805 : : int enable,
8806 : : struct rte_flow_error *error)
8807 : : {
8808 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8809 : :
8810 [ # # ]: 0 : if (dev->data->dev_started) {
8811 : 0 : rte_flow_error_set(error, EBUSY,
8812 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8813 : : NULL,
8814 : : "port must be stopped first");
8815 : 0 : return -rte_errno;
8816 : : }
8817 : :
8818 : 0 : priv->isolated = !!enable;
8819 [ # # ]: 0 : if (enable)
8820 : 0 : dev->dev_ops = &mlx5_dev_ops_isolate;
8821 : : else
8822 : 0 : dev->dev_ops = &mlx5_dev_ops;
8823 : :
8824 : 0 : dev->rx_descriptor_status = mlx5_rx_descriptor_status;
8825 : 0 : dev->tx_descriptor_status = mlx5_tx_descriptor_status;
8826 : :
8827 : 0 : return 0;
8828 : : }
8829 : :
8830 : : /**
8831 : : * Query a flow.
8832 : : *
8833 : : * @see rte_flow_query()
8834 : : * @see rte_flow_ops
8835 : : */
8836 : : static int
8837 : 0 : flow_drv_query(struct rte_eth_dev *dev,
8838 : : struct rte_flow *eflow,
8839 : : const struct rte_flow_action *actions,
8840 : : void *data,
8841 : : struct rte_flow_error *error)
8842 : : {
8843 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
8844 : : const struct mlx5_flow_driver_ops *fops;
8845 : : struct rte_flow *flow = NULL;
8846 : : enum mlx5_flow_drv_type ftype = MLX5_FLOW_TYPE_MIN;
8847 : :
8848 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2) {
8849 : : #ifdef HAVE_MLX5_HWS_SUPPORT
8850 : : flow = eflow;
8851 : : ftype = MLX5_FLOW_TYPE_HW;
8852 : : #endif
8853 : : } else {
8854 : 0 : flow = (struct rte_flow *)mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
8855 : : (uintptr_t)(void *)eflow);
8856 : : }
8857 [ # # ]: 0 : if (!flow) {
8858 : 0 : return rte_flow_error_set(error, ENOENT,
8859 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8860 : : NULL,
8861 : : "invalid flow handle");
8862 : : }
8863 [ # # ]: 0 : if (ftype == MLX5_FLOW_TYPE_MIN)
8864 : 0 : ftype = flow->drv_type;
8865 : : MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX);
8866 : 0 : fops = flow_get_drv_ops(ftype);
8867 : :
8868 : 0 : return fops->query(dev, flow, actions, data, error);
8869 : : }
8870 : :
8871 : : /**
8872 : : * Query a flow.
8873 : : *
8874 : : * @see rte_flow_query()
8875 : : * @see rte_flow_ops
8876 : : */
8877 : : int
8878 : 0 : mlx5_flow_query(struct rte_eth_dev *dev,
8879 : : struct rte_flow *flow,
8880 : : const struct rte_flow_action *actions,
8881 : : void *data,
8882 : : struct rte_flow_error *error)
8883 : : {
8884 : : int ret;
8885 : :
8886 : 0 : ret = flow_drv_query(dev, flow, actions, data,
8887 : : error);
8888 : : if (ret < 0)
8889 : : return ret;
8890 : : return 0;
8891 : : }
8892 : :
8893 : : /**
8894 : : * Get rte_flow callbacks.
8895 : : *
8896 : : * @param dev
8897 : : * Pointer to Ethernet device structure.
8898 : : * @param ops
8899 : : * Pointer to operation-specific structure.
8900 : : *
8901 : : * @return 0
8902 : : */
8903 : : int
8904 : 0 : mlx5_flow_ops_get(struct rte_eth_dev *dev __rte_unused,
8905 : : const struct rte_flow_ops **ops)
8906 : : {
8907 [ # # ]: 0 : if (mlx5_flow_is_steering_disabled()) {
8908 : 0 : DRV_LOG(WARNING, "port %u flow API is not supported since steering was disabled",
8909 : : dev->data->port_id);
8910 : 0 : *ops = NULL;
8911 : 0 : return 0;
8912 : : }
8913 : :
8914 : 0 : *ops = &mlx5_flow_ops;
8915 : 0 : return 0;
8916 : : }
8917 : :
8918 : : /**
8919 : : * Validate meter policy actions.
8920 : : * Dispatcher for action type specific validation.
8921 : : *
8922 : : * @param[in] dev
8923 : : * Pointer to the Ethernet device structure.
8924 : : * @param[in] action
8925 : : * The meter policy action object to validate.
8926 : : * @param[in] attr
8927 : : * Attributes of flow to determine steering domain.
8928 : : * @param[out] is_rss
8929 : : * Is RSS or not.
8930 : : * @param[out] domain_bitmap
8931 : : * Domain bitmap.
8932 : : * @param[out] is_def_policy
8933 : : * Is default policy or not.
8934 : : * @param[out] error
8935 : : * Perform verbose error reporting if not NULL. Initialized in case of
8936 : : * error only.
8937 : : *
8938 : : * @return
8939 : : * 0 on success, otherwise negative errno value.
8940 : : */
8941 : : int
8942 : 0 : mlx5_flow_validate_mtr_acts(struct rte_eth_dev *dev,
8943 : : const struct rte_flow_action *actions[RTE_COLORS],
8944 : : struct rte_flow_attr *attr,
8945 : : bool *is_rss,
8946 : : uint8_t *domain_bitmap,
8947 : : uint8_t *policy_mode,
8948 : : struct rte_mtr_error *error)
8949 : : {
8950 : : const struct mlx5_flow_driver_ops *fops;
8951 : :
8952 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
8953 : 0 : return fops->validate_mtr_acts(dev, actions, attr, is_rss,
8954 : : domain_bitmap, policy_mode, error);
8955 : : }
8956 : :
8957 : : /**
8958 : : * Destroy the meter table set.
8959 : : *
8960 : : * @param[in] dev
8961 : : * Pointer to Ethernet device.
8962 : : * @param[in] mtr_policy
8963 : : * Meter policy struct.
8964 : : */
8965 : : void
8966 : 0 : mlx5_flow_destroy_mtr_acts(struct rte_eth_dev *dev,
8967 : : struct mlx5_flow_meter_policy *mtr_policy)
8968 : : {
8969 : : const struct mlx5_flow_driver_ops *fops;
8970 : :
8971 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
8972 : 0 : fops->destroy_mtr_acts(dev, mtr_policy);
8973 : 0 : }
8974 : :
8975 : : /**
8976 : : * Create policy action, lock free,
8977 : : * (mutex should be acquired by caller).
8978 : : * Dispatcher for action type specific call.
8979 : : *
8980 : : * @param[in] dev
8981 : : * Pointer to the Ethernet device structure.
8982 : : * @param[in] mtr_policy
8983 : : * Meter policy struct.
8984 : : * @param[in] action
8985 : : * Action specification used to create meter actions.
8986 : : * @param[in] attr
8987 : : * Flow rule attributes.
8988 : : * @param[out] error
8989 : : * Perform verbose error reporting if not NULL. Initialized in case of
8990 : : * error only.
8991 : : *
8992 : : * @return
8993 : : * 0 on success, otherwise negative errno value.
8994 : : */
8995 : : int
8996 : 0 : mlx5_flow_create_mtr_acts(struct rte_eth_dev *dev,
8997 : : struct mlx5_flow_meter_policy *mtr_policy,
8998 : : const struct rte_flow_action *actions[RTE_COLORS],
8999 : : struct rte_flow_attr *attr,
9000 : : struct rte_mtr_error *error)
9001 : : {
9002 : : const struct mlx5_flow_driver_ops *fops;
9003 : :
9004 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9005 : 0 : return fops->create_mtr_acts(dev, mtr_policy, actions, attr, error);
9006 : : }
9007 : :
9008 : : /**
9009 : : * Create policy rules, lock free,
9010 : : * (mutex should be acquired by caller).
9011 : : * Dispatcher for action type specific call.
9012 : : *
9013 : : * @param[in] dev
9014 : : * Pointer to the Ethernet device structure.
9015 : : * @param[in] mtr_policy
9016 : : * Meter policy struct.
9017 : : *
9018 : : * @return
9019 : : * 0 on success, -1 otherwise.
9020 : : */
9021 : : int
9022 : 0 : mlx5_flow_create_policy_rules(struct rte_eth_dev *dev,
9023 : : struct mlx5_flow_meter_policy *mtr_policy)
9024 : : {
9025 : : const struct mlx5_flow_driver_ops *fops;
9026 : :
9027 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9028 : 0 : return fops->create_policy_rules(dev, mtr_policy);
9029 : : }
9030 : :
9031 : : /**
9032 : : * Destroy policy rules, lock free,
9033 : : * (mutex should be acquired by caller).
9034 : : * Dispatcher for action type specific call.
9035 : : *
9036 : : * @param[in] dev
9037 : : * Pointer to the Ethernet device structure.
9038 : : * @param[in] mtr_policy
9039 : : * Meter policy struct.
9040 : : */
9041 : : void
9042 : 0 : mlx5_flow_destroy_policy_rules(struct rte_eth_dev *dev,
9043 : : struct mlx5_flow_meter_policy *mtr_policy)
9044 : : {
9045 : : const struct mlx5_flow_driver_ops *fops;
9046 : :
9047 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9048 : 0 : fops->destroy_policy_rules(dev, mtr_policy);
9049 : 0 : }
9050 : :
9051 : : /**
9052 : : * Destroy the default policy table set.
9053 : : *
9054 : : * @param[in] dev
9055 : : * Pointer to Ethernet device.
9056 : : */
9057 : : void
9058 : 0 : mlx5_flow_destroy_def_policy(struct rte_eth_dev *dev)
9059 : : {
9060 : : const struct mlx5_flow_driver_ops *fops;
9061 : :
9062 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9063 : 0 : fops->destroy_def_policy(dev);
9064 : 0 : }
9065 : :
9066 : : /**
9067 : : * Destroy the default policy table set.
9068 : : *
9069 : : * @param[in] dev
9070 : : * Pointer to Ethernet device.
9071 : : *
9072 : : * @return
9073 : : * 0 on success, -1 otherwise.
9074 : : */
9075 : : int
9076 : 0 : mlx5_flow_create_def_policy(struct rte_eth_dev *dev)
9077 : : {
9078 : : const struct mlx5_flow_driver_ops *fops;
9079 : :
9080 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9081 : 0 : return fops->create_def_policy(dev);
9082 : : }
9083 : :
9084 : : /**
9085 : : * Create the needed meter and suffix tables.
9086 : : *
9087 : : * @param[in] dev
9088 : : * Pointer to Ethernet device.
9089 : : *
9090 : : * @return
9091 : : * 0 on success, -1 otherwise.
9092 : : */
9093 : : int
9094 : 0 : mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
9095 : : struct mlx5_flow_meter_info *fm,
9096 : : uint32_t mtr_idx,
9097 : : uint8_t domain_bitmap)
9098 : : {
9099 : : const struct mlx5_flow_driver_ops *fops;
9100 : :
9101 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9102 : 0 : return fops->create_mtr_tbls(dev, fm, mtr_idx, domain_bitmap);
9103 : : }
9104 : :
9105 : : /**
9106 : : * Destroy the meter table set.
9107 : : *
9108 : : * @param[in] dev
9109 : : * Pointer to Ethernet device.
9110 : : * @param[in] tbl
9111 : : * Pointer to the meter table set.
9112 : : */
9113 : : void
9114 : 0 : mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
9115 : : struct mlx5_flow_meter_info *fm)
9116 : : {
9117 : : const struct mlx5_flow_driver_ops *fops;
9118 : :
9119 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9120 : 0 : fops->destroy_mtr_tbls(dev, fm);
9121 : 0 : }
9122 : :
9123 : : /**
9124 : : * Destroy the global meter drop table.
9125 : : *
9126 : : * @param[in] dev
9127 : : * Pointer to Ethernet device.
9128 : : */
9129 : : void
9130 : 0 : mlx5_flow_destroy_mtr_drop_tbls(struct rte_eth_dev *dev)
9131 : : {
9132 : : const struct mlx5_flow_driver_ops *fops;
9133 : :
9134 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9135 : 0 : fops->destroy_mtr_drop_tbls(dev);
9136 : 0 : }
9137 : :
9138 : : /**
9139 : : * Destroy the sub policy table with RX queue.
9140 : : *
9141 : : * @param[in] dev
9142 : : * Pointer to Ethernet device.
9143 : : * @param[in] mtr_policy
9144 : : * Pointer to meter policy table.
9145 : : */
9146 : : void
9147 : 0 : mlx5_flow_destroy_sub_policy_with_rxq(struct rte_eth_dev *dev,
9148 : : struct mlx5_flow_meter_policy *mtr_policy)
9149 : : {
9150 : : const struct mlx5_flow_driver_ops *fops;
9151 : :
9152 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9153 : 0 : fops->destroy_sub_policy_with_rxq(dev, mtr_policy);
9154 : 0 : }
9155 : :
9156 : : /**
9157 : : * Allocate the needed aso flow meter id.
9158 : : *
9159 : : * @param[in] dev
9160 : : * Pointer to Ethernet device.
9161 : : *
9162 : : * @return
9163 : : * Index to aso flow meter on success, NULL otherwise.
9164 : : */
9165 : : uint32_t
9166 : 0 : mlx5_flow_mtr_alloc(struct rte_eth_dev *dev)
9167 : : {
9168 : : const struct mlx5_flow_driver_ops *fops;
9169 : :
9170 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9171 : 0 : return fops->create_meter(dev);
9172 : : }
9173 : :
9174 : : /**
9175 : : * Free the aso flow meter id.
9176 : : *
9177 : : * @param[in] dev
9178 : : * Pointer to Ethernet device.
9179 : : * @param[in] mtr_idx
9180 : : * Index to aso flow meter to be free.
9181 : : *
9182 : : * @return
9183 : : * 0 on success.
9184 : : */
9185 : : void
9186 : 0 : mlx5_flow_mtr_free(struct rte_eth_dev *dev, uint32_t mtr_idx)
9187 : : {
9188 : : const struct mlx5_flow_driver_ops *fops;
9189 : :
9190 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
9191 : 0 : fops->free_meter(dev, mtr_idx);
9192 : 0 : }
9193 : :
9194 : : /**
9195 : : * Allocate a counter.
9196 : : *
9197 : : * @param[in] dev
9198 : : * Pointer to Ethernet device structure.
9199 : : *
9200 : : * @return
9201 : : * Index to allocated counter on success, 0 otherwise.
9202 : : */
9203 : : uint32_t
9204 [ # # ]: 0 : mlx5_counter_alloc(struct rte_eth_dev *dev)
9205 : : {
9206 : : struct rte_flow_attr attr = { .transfer = 0 };
9207 : :
9208 : 0 : return flow_get_drv_ops(flow_get_drv_type(dev, &attr))->counter_alloc
9209 : : (dev);
9210 : : }
9211 : :
9212 : : /**
9213 : : * Free a counter.
9214 : : *
9215 : : * @param[in] dev
9216 : : * Pointer to Ethernet device structure.
9217 : : * @param[in] cnt
9218 : : * Index to counter to be free.
9219 : : */
9220 : : void
9221 [ # # ]: 0 : mlx5_counter_free(struct rte_eth_dev *dev, uint32_t cnt)
9222 : : {
9223 : : struct rte_flow_attr attr = { .transfer = 0 };
9224 : :
9225 : 0 : flow_get_drv_ops(flow_get_drv_type(dev, &attr))->counter_free(dev, cnt);
9226 : 0 : }
9227 : :
9228 : : /**
9229 : : * Query counter statistics.
9230 : : *
9231 : : * @param[in] dev
9232 : : * Pointer to Ethernet device structure.
9233 : : * @param[in] cnt
9234 : : * Index to counter to query.
9235 : : * @param[in] clear
9236 : : * Set to clear counter statistics.
9237 : : * @param[out] pkts
9238 : : * The counter hits packets number to save.
9239 : : * @param[out] bytes
9240 : : * The counter hits bytes number to save.
9241 : : *
9242 : : * @return
9243 : : * 0 on success, a negative errno value otherwise.
9244 : : */
9245 : : int
9246 [ # # ]: 0 : mlx5_counter_query(struct rte_eth_dev *dev, uint32_t cnt,
9247 : : bool clear, uint64_t *pkts, uint64_t *bytes, void **action)
9248 : : {
9249 : : struct rte_flow_attr attr = { .transfer = 0 };
9250 : :
9251 : 0 : return flow_get_drv_ops(flow_get_drv_type(dev, &attr))->counter_query
9252 : : (dev, cnt, clear, pkts, bytes, action);
9253 : : }
9254 : :
9255 : : /**
9256 : : * Get information about HWS pre-configurable resources.
9257 : : *
9258 : : * @param[in] dev
9259 : : * Pointer to the rte_eth_dev structure.
9260 : : * @param[out] port_info
9261 : : * Pointer to port information.
9262 : : * @param[out] queue_info
9263 : : * Pointer to queue information.
9264 : : * @param[out] error
9265 : : * Pointer to error structure.
9266 : : *
9267 : : * @return
9268 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9269 : : */
9270 : : static int
9271 [ # # ]: 0 : mlx5_flow_info_get(struct rte_eth_dev *dev,
9272 : : struct rte_flow_port_info *port_info,
9273 : : struct rte_flow_queue_info *queue_info,
9274 : : struct rte_flow_error *error)
9275 : : {
9276 : : const struct mlx5_flow_driver_ops *fops;
9277 : : struct rte_flow_attr attr = {0};
9278 : :
9279 : : if (flow_get_drv_type(dev, &attr) != MLX5_FLOW_TYPE_HW)
9280 : 0 : return rte_flow_error_set(error, ENOTSUP,
9281 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9282 : : NULL,
9283 : : "info get with incorrect steering mode");
9284 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9285 : 0 : return fops->info_get(dev, port_info, queue_info, error);
9286 : : }
9287 : :
9288 : : /**
9289 : : * Configure port HWS resources.
9290 : : *
9291 : : * @param[in] dev
9292 : : * Pointer to the rte_eth_dev structure.
9293 : : * @param[in] port_attr
9294 : : * Port configuration attributes.
9295 : : * @param[in] nb_queue
9296 : : * Number of queue.
9297 : : * @param[in] queue_attr
9298 : : * Array that holds attributes for each flow queue.
9299 : : * @param[out] error
9300 : : * Pointer to error structure.
9301 : : *
9302 : : * @return
9303 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9304 : : */
9305 : : static int
9306 [ # # ]: 0 : mlx5_flow_port_configure(struct rte_eth_dev *dev,
9307 : : const struct rte_flow_port_attr *port_attr,
9308 : : uint16_t nb_queue,
9309 : : const struct rte_flow_queue_attr *queue_attr[],
9310 : : struct rte_flow_error *error)
9311 : : {
9312 : : const struct mlx5_flow_driver_ops *fops;
9313 : : struct rte_flow_attr attr = {0};
9314 : :
9315 : : if (flow_get_drv_type(dev, &attr) != MLX5_FLOW_TYPE_HW)
9316 : 0 : return rte_flow_error_set(error, ENOTSUP,
9317 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9318 : : NULL,
9319 : : "port configure with incorrect steering mode");
9320 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9321 : 0 : return fops->configure(dev, port_attr, nb_queue, queue_attr, error);
9322 : : }
9323 : :
9324 : : /**
9325 : : * Validate item template.
9326 : : *
9327 : : * @param[in] dev
9328 : : * Pointer to the rte_eth_dev structure.
9329 : : * @param[in] attr
9330 : : * Pointer to the item template attributes.
9331 : : * @param[in] items
9332 : : * The template item pattern.
9333 : : * @param[out] error
9334 : : * Pointer to error structure.
9335 : : *
9336 : : * @return
9337 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9338 : : */
9339 : : int
9340 : 0 : mlx5_flow_pattern_validate(struct rte_eth_dev *dev,
9341 : : const struct rte_flow_pattern_template_attr *attr,
9342 : : const struct rte_flow_item items[],
9343 : : struct rte_flow_error *error)
9344 : : {
9345 : : const struct mlx5_flow_driver_ops *fops;
9346 : : struct rte_flow_attr fattr = {0};
9347 [ # # ]: 0 : uint64_t item_flags = 0;
9348 : :
9349 : : if (flow_get_drv_type(dev, &fattr) != MLX5_FLOW_TYPE_HW) {
9350 : 0 : rte_flow_error_set(error, ENOTSUP,
9351 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9352 : : "pattern validate with incorrect steering mode");
9353 : 0 : return -ENOTSUP;
9354 : : }
9355 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9356 : 0 : return fops->pattern_validate(dev, attr, items, &item_flags, error);
9357 : : }
9358 : :
9359 : : /**
9360 : : * Create flow item template.
9361 : : *
9362 : : * @param[in] dev
9363 : : * Pointer to the rte_eth_dev structure.
9364 : : * @param[in] attr
9365 : : * Pointer to the item template attributes.
9366 : : * @param[in] items
9367 : : * The template item pattern.
9368 : : * @param[out] error
9369 : : * Pointer to error structure.
9370 : : *
9371 : : * @return
9372 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9373 : : */
9374 : : static struct rte_flow_pattern_template *
9375 [ # # ]: 0 : mlx5_flow_pattern_template_create(struct rte_eth_dev *dev,
9376 : : const struct rte_flow_pattern_template_attr *attr,
9377 : : const struct rte_flow_item items[],
9378 : : struct rte_flow_error *error)
9379 : : {
9380 : : const struct mlx5_flow_driver_ops *fops;
9381 : : struct rte_flow_attr fattr = {0};
9382 : :
9383 : : if (flow_get_drv_type(dev, &fattr) != MLX5_FLOW_TYPE_HW) {
9384 : 0 : rte_flow_error_set(error, ENOTSUP,
9385 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9386 : : NULL,
9387 : : "pattern create with incorrect steering mode");
9388 : 0 : return NULL;
9389 : : }
9390 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9391 : 0 : return fops->pattern_template_create(dev, attr, items, error);
9392 : : }
9393 : :
9394 : : /**
9395 : : * Destroy flow item template.
9396 : : *
9397 : : * @param[in] dev
9398 : : * Pointer to the rte_eth_dev structure.
9399 : : * @param[in] template
9400 : : * Pointer to the item template to be destroyed.
9401 : : * @param[out] error
9402 : : * Pointer to error structure.
9403 : : *
9404 : : * @return
9405 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9406 : : */
9407 : : static int
9408 [ # # ]: 0 : mlx5_flow_pattern_template_destroy(struct rte_eth_dev *dev,
9409 : : struct rte_flow_pattern_template *template,
9410 : : struct rte_flow_error *error)
9411 : : {
9412 : : const struct mlx5_flow_driver_ops *fops;
9413 : : struct rte_flow_attr attr = {0};
9414 : :
9415 : : if (flow_get_drv_type(dev, &attr) != MLX5_FLOW_TYPE_HW)
9416 : 0 : return rte_flow_error_set(error, ENOTSUP,
9417 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9418 : : NULL,
9419 : : "pattern destroy with incorrect steering mode");
9420 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9421 : 0 : return fops->pattern_template_destroy(dev, template, error);
9422 : : }
9423 : :
9424 : : /**
9425 : : * Validate flow actions template.
9426 : : *
9427 : : * @param[in] dev
9428 : : * Pointer to the rte_eth_dev structure.
9429 : : * @param[in] attr
9430 : : * Pointer to the action template attributes.
9431 : : * @param[in] actions
9432 : : * Associated actions (list terminated by the END action).
9433 : : * @param[in] masks
9434 : : * List of actions that marks which of the action's member is constant.
9435 : : * @param[out] error
9436 : : * Pointer to error structure.
9437 : : *
9438 : : * @return
9439 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9440 : : */
9441 : : int
9442 [ # # ]: 0 : mlx5_flow_actions_validate(struct rte_eth_dev *dev,
9443 : : const struct rte_flow_actions_template_attr *attr,
9444 : : const struct rte_flow_action actions[],
9445 : : const struct rte_flow_action masks[],
9446 : : struct rte_flow_error *error)
9447 : : {
9448 : : const struct mlx5_flow_driver_ops *fops;
9449 : : struct rte_flow_attr fattr = {0};
9450 : :
9451 : : if (flow_get_drv_type(dev, &fattr) != MLX5_FLOW_TYPE_HW) {
9452 : 0 : rte_flow_error_set(error, ENOTSUP,
9453 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9454 : : "actions validate with incorrect steering mode");
9455 : 0 : return -ENOTSUP;
9456 : : }
9457 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9458 : 0 : return fops->actions_validate(dev, attr, actions, masks, error);
9459 : : }
9460 : :
9461 : : /**
9462 : : * Create flow item template.
9463 : : *
9464 : : * @param[in] dev
9465 : : * Pointer to the rte_eth_dev structure.
9466 : : * @param[in] attr
9467 : : * Pointer to the action template attributes.
9468 : : * @param[in] actions
9469 : : * Associated actions (list terminated by the END action).
9470 : : * @param[in] masks
9471 : : * List of actions that marks which of the action's member is constant.
9472 : : * @param[out] error
9473 : : * Pointer to error structure.
9474 : : *
9475 : : * @return
9476 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9477 : : */
9478 : : static struct rte_flow_actions_template *
9479 [ # # ]: 0 : mlx5_flow_actions_template_create(struct rte_eth_dev *dev,
9480 : : const struct rte_flow_actions_template_attr *attr,
9481 : : const struct rte_flow_action actions[],
9482 : : const struct rte_flow_action masks[],
9483 : : struct rte_flow_error *error)
9484 : : {
9485 : : const struct mlx5_flow_driver_ops *fops;
9486 : : struct rte_flow_attr fattr = {0};
9487 : :
9488 : : if (flow_get_drv_type(dev, &fattr) != MLX5_FLOW_TYPE_HW) {
9489 : 0 : rte_flow_error_set(error, ENOTSUP,
9490 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9491 : : NULL,
9492 : : "action create with incorrect steering mode");
9493 : 0 : return NULL;
9494 : : }
9495 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9496 : 0 : return fops->actions_template_create(dev, attr, actions, masks, error);
9497 : : }
9498 : :
9499 : : /**
9500 : : * Destroy flow action template.
9501 : : *
9502 : : * @param[in] dev
9503 : : * Pointer to the rte_eth_dev structure.
9504 : : * @param[in] template
9505 : : * Pointer to the action template to be destroyed.
9506 : : * @param[out] error
9507 : : * Pointer to error structure.
9508 : : *
9509 : : * @return
9510 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9511 : : */
9512 : : static int
9513 [ # # ]: 0 : mlx5_flow_actions_template_destroy(struct rte_eth_dev *dev,
9514 : : struct rte_flow_actions_template *template,
9515 : : struct rte_flow_error *error)
9516 : : {
9517 : : const struct mlx5_flow_driver_ops *fops;
9518 : : struct rte_flow_attr attr = {0};
9519 : :
9520 : : if (flow_get_drv_type(dev, &attr) != MLX5_FLOW_TYPE_HW)
9521 : 0 : return rte_flow_error_set(error, ENOTSUP,
9522 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9523 : : NULL,
9524 : : "action destroy with incorrect steering mode");
9525 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9526 : 0 : return fops->actions_template_destroy(dev, template, error);
9527 : : }
9528 : :
9529 : : /**
9530 : : * Create flow table.
9531 : : *
9532 : : * @param[in] dev
9533 : : * Pointer to the rte_eth_dev structure.
9534 : : * @param[in] attr
9535 : : * Pointer to the table attributes.
9536 : : * @param[in] item_templates
9537 : : * Item template array to be binded to the table.
9538 : : * @param[in] nb_item_templates
9539 : : * Number of item template.
9540 : : * @param[in] action_templates
9541 : : * Action template array to be binded to the table.
9542 : : * @param[in] nb_action_templates
9543 : : * Number of action template.
9544 : : * @param[out] error
9545 : : * Pointer to error structure.
9546 : : *
9547 : : * @return
9548 : : * Table on success, NULL otherwise and rte_errno is set.
9549 : : */
9550 : : static struct rte_flow_template_table *
9551 [ # # ]: 0 : mlx5_flow_table_create(struct rte_eth_dev *dev,
9552 : : const struct rte_flow_template_table_attr *attr,
9553 : : struct rte_flow_pattern_template *item_templates[],
9554 : : uint8_t nb_item_templates,
9555 : : struct rte_flow_actions_template *action_templates[],
9556 : : uint8_t nb_action_templates,
9557 : : struct rte_flow_error *error)
9558 : : {
9559 : : const struct mlx5_flow_driver_ops *fops;
9560 : : struct rte_flow_attr fattr = {0};
9561 : :
9562 : : if (flow_get_drv_type(dev, &fattr) != MLX5_FLOW_TYPE_HW) {
9563 : 0 : rte_flow_error_set(error, ENOTSUP,
9564 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9565 : : NULL,
9566 : : "table create with incorrect steering mode");
9567 : 0 : return NULL;
9568 : : }
9569 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9570 : 0 : return fops->template_table_create(dev,
9571 : : attr,
9572 : : item_templates,
9573 : : nb_item_templates,
9574 : : action_templates,
9575 : : nb_action_templates,
9576 : : error);
9577 : : }
9578 : :
9579 : : /**
9580 : : * PMD destroy flow table.
9581 : : *
9582 : : * @param[in] dev
9583 : : * Pointer to the rte_eth_dev structure.
9584 : : * @param[in] table
9585 : : * Pointer to the table to be destroyed.
9586 : : * @param[out] error
9587 : : * Pointer to error structure.
9588 : : *
9589 : : * @return
9590 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9591 : : */
9592 : : static int
9593 [ # # ]: 0 : mlx5_flow_table_destroy(struct rte_eth_dev *dev,
9594 : : struct rte_flow_template_table *table,
9595 : : struct rte_flow_error *error)
9596 : : {
9597 : : const struct mlx5_flow_driver_ops *fops;
9598 : : struct rte_flow_attr attr = {0};
9599 : :
9600 : : if (flow_get_drv_type(dev, &attr) != MLX5_FLOW_TYPE_HW)
9601 : 0 : return rte_flow_error_set(error, ENOTSUP,
9602 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9603 : : NULL,
9604 : : "table destroy with incorrect steering mode");
9605 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9606 : 0 : return fops->template_table_destroy(dev, table, error);
9607 : : }
9608 : :
9609 : : /**
9610 : : * PMD group set miss actions.
9611 : : *
9612 : : * @param[in] dev
9613 : : * Pointer to the rte_eth_dev structure.
9614 : : * @param[in] attr
9615 : : * Pointer to group attributes
9616 : : * @param[in] actions
9617 : : * Array of actions
9618 : : * @param[out] error
9619 : : * Pointer to error structure.
9620 : : *
9621 : : * @return
9622 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9623 : : */
9624 : : static int
9625 [ # # ]: 0 : mlx5_flow_group_set_miss_actions(struct rte_eth_dev *dev,
9626 : : uint32_t group_id,
9627 : : const struct rte_flow_group_attr *attr,
9628 : : const struct rte_flow_action actions[],
9629 : : struct rte_flow_error *error)
9630 : : {
9631 : : const struct mlx5_flow_driver_ops *fops;
9632 : : struct rte_flow_attr fattr = {0};
9633 : :
9634 : : if (flow_get_drv_type(dev, &fattr) != MLX5_FLOW_TYPE_HW)
9635 : 0 : return rte_flow_error_set(error, ENOTSUP,
9636 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
9637 : : NULL,
9638 : : "group set miss actions with incorrect steering mode");
9639 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
9640 : 0 : return fops->group_set_miss_actions(dev, group_id, attr, actions, error);
9641 : : }
9642 : :
9643 : : /**
9644 : : * Allocate a new memory for the counter values wrapped by all the needed
9645 : : * management.
9646 : : *
9647 : : * @param[in] sh
9648 : : * Pointer to mlx5_dev_ctx_shared object.
9649 : : *
9650 : : * @return
9651 : : * 0 on success, a negative errno value otherwise.
9652 : : */
9653 : : static int
9654 : 0 : mlx5_flow_create_counter_stat_mem_mng(struct mlx5_dev_ctx_shared *sh)
9655 : : {
9656 : : struct mlx5_counter_stats_mem_mng *mem_mng;
9657 : : volatile struct flow_counter_stats *raw_data;
9658 : : int raws_n = MLX5_CNT_MR_ALLOC_BULK + MLX5_MAX_PENDING_QUERIES;
9659 : : int size = (sizeof(struct flow_counter_stats) *
9660 : : MLX5_COUNTERS_PER_POOL +
9661 : : sizeof(struct mlx5_counter_stats_raw)) * raws_n +
9662 : : sizeof(struct mlx5_counter_stats_mem_mng);
9663 : 0 : size_t pgsize = rte_mem_page_size();
9664 : : uint8_t *mem;
9665 : : int ret;
9666 : : int i;
9667 : :
9668 [ # # ]: 0 : if (pgsize == (size_t)-1) {
9669 : 0 : DRV_LOG(ERR, "Failed to get mem page size");
9670 : 0 : rte_errno = ENOMEM;
9671 : 0 : return -ENOMEM;
9672 : : }
9673 : 0 : mem = mlx5_malloc(MLX5_MEM_ZERO, size, pgsize, SOCKET_ID_ANY);
9674 [ # # ]: 0 : if (!mem) {
9675 : 0 : rte_errno = ENOMEM;
9676 : 0 : return -ENOMEM;
9677 : : }
9678 : 0 : mem_mng = (struct mlx5_counter_stats_mem_mng *)(mem + size) - 1;
9679 : : size = sizeof(*raw_data) * MLX5_COUNTERS_PER_POOL * raws_n;
9680 : 0 : ret = mlx5_os_wrapped_mkey_create(sh->cdev->ctx, sh->cdev->pd,
9681 : 0 : sh->cdev->pdn, mem, size,
9682 : : &mem_mng->wm);
9683 [ # # ]: 0 : if (ret) {
9684 : 0 : rte_errno = errno;
9685 : 0 : mlx5_free(mem);
9686 : 0 : return -rte_errno;
9687 : : }
9688 : 0 : mem_mng->raws = (struct mlx5_counter_stats_raw *)(mem + size);
9689 : : raw_data = (volatile struct flow_counter_stats *)mem;
9690 [ # # ]: 0 : for (i = 0; i < raws_n; ++i) {
9691 : 0 : mem_mng->raws[i].mem_mng = mem_mng;
9692 : 0 : mem_mng->raws[i].data = raw_data + i * MLX5_COUNTERS_PER_POOL;
9693 : : }
9694 [ # # ]: 0 : for (i = 0; i < MLX5_MAX_PENDING_QUERIES; ++i)
9695 [ # # ]: 0 : LIST_INSERT_HEAD(&sh->sws_cmng.free_stat_raws,
9696 : : mem_mng->raws + MLX5_CNT_MR_ALLOC_BULK + i,
9697 : : next);
9698 [ # # ]: 0 : LIST_INSERT_HEAD(&sh->sws_cmng.mem_mngs, mem_mng, next);
9699 : 0 : sh->sws_cmng.mem_mng = mem_mng;
9700 : 0 : return 0;
9701 : : }
9702 : :
9703 : : /**
9704 : : * Set the statistic memory to the new counter pool.
9705 : : *
9706 : : * @param[in] sh
9707 : : * Pointer to mlx5_dev_ctx_shared object.
9708 : : * @param[in] pool
9709 : : * Pointer to the pool to set the statistic memory.
9710 : : *
9711 : : * @return
9712 : : * 0 on success, a negative errno value otherwise.
9713 : : */
9714 : : static int
9715 : 0 : mlx5_flow_set_counter_stat_mem(struct mlx5_dev_ctx_shared *sh,
9716 : : struct mlx5_flow_counter_pool *pool)
9717 : : {
9718 : : struct mlx5_flow_counter_mng *cmng = &sh->sws_cmng;
9719 : : /* Resize statistic memory once used out. */
9720 [ # # # # ]: 0 : if (!(pool->index % MLX5_CNT_MR_ALLOC_BULK) &&
9721 : 0 : mlx5_flow_create_counter_stat_mem_mng(sh)) {
9722 : 0 : DRV_LOG(ERR, "Cannot resize counter stat mem.");
9723 : 0 : return -1;
9724 : : }
9725 : 0 : rte_spinlock_lock(&pool->sl);
9726 : 0 : pool->raw = cmng->mem_mng->raws + pool->index % MLX5_CNT_MR_ALLOC_BULK;
9727 : : rte_spinlock_unlock(&pool->sl);
9728 : 0 : pool->raw_hw = NULL;
9729 : 0 : return 0;
9730 : : }
9731 : :
9732 : : #define MLX5_POOL_QUERY_FREQ_US 1000000
9733 : :
9734 : : /**
9735 : : * Set the periodic procedure for triggering asynchronous batch queries for all
9736 : : * the counter pools.
9737 : : *
9738 : : * @param[in] sh
9739 : : * Pointer to mlx5_dev_ctx_shared object.
9740 : : */
9741 : : void
9742 : 0 : mlx5_set_query_alarm(struct mlx5_dev_ctx_shared *sh)
9743 : : {
9744 : : uint32_t pools_n, us;
9745 : :
9746 : 0 : pools_n = rte_atomic_load_explicit(&sh->sws_cmng.n_valid, rte_memory_order_relaxed);
9747 : 0 : us = MLX5_POOL_QUERY_FREQ_US / pools_n;
9748 : 0 : DRV_LOG(DEBUG, "Set alarm for %u pools each %u us", pools_n, us);
9749 [ # # ]: 0 : if (rte_eal_alarm_set(us, mlx5_flow_query_alarm, sh)) {
9750 : 0 : sh->sws_cmng.query_thread_on = 0;
9751 : 0 : DRV_LOG(ERR, "Cannot reinitialize query alarm");
9752 : : } else {
9753 : 0 : sh->sws_cmng.query_thread_on = 1;
9754 : : }
9755 : 0 : }
9756 : :
9757 : : /**
9758 : : * The periodic procedure for triggering asynchronous batch queries for all the
9759 : : * counter pools. This function is probably called by the host thread.
9760 : : *
9761 : : * @param[in] arg
9762 : : * The parameter for the alarm process.
9763 : : */
9764 : : void
9765 : 0 : mlx5_flow_query_alarm(void *arg)
9766 : : {
9767 : : struct mlx5_dev_ctx_shared *sh = arg;
9768 : : struct mlx5_flow_counter_mng *cmng = &sh->sws_cmng;
9769 : 0 : uint16_t pool_index = cmng->pool_index;
9770 : : struct mlx5_flow_counter_pool *pool;
9771 : : uint16_t n_valid;
9772 : : int ret;
9773 : :
9774 [ # # ]: 0 : if (cmng->pending_queries >= MLX5_MAX_PENDING_QUERIES)
9775 : 0 : goto set_alarm;
9776 : 0 : rte_spinlock_lock(&cmng->pool_update_sl);
9777 : 0 : pool = cmng->pools[pool_index];
9778 : 0 : n_valid = cmng->n_valid;
9779 : : rte_spinlock_unlock(&cmng->pool_update_sl);
9780 : : /* Set the statistic memory to the new created pool. */
9781 [ # # # # ]: 0 : if ((!pool->raw && mlx5_flow_set_counter_stat_mem(sh, pool)))
9782 : 0 : goto set_alarm;
9783 [ # # ]: 0 : if (pool->raw_hw)
9784 : : /* There is a pool query in progress. */
9785 : 0 : goto set_alarm;
9786 : 0 : pool->raw_hw = LIST_FIRST(&cmng->free_stat_raws);
9787 [ # # ]: 0 : if (!pool->raw_hw)
9788 : : /* No free counter statistics raw memory. */
9789 : 0 : goto set_alarm;
9790 : : /*
9791 : : * Identify the counters released between query trigger and query
9792 : : * handle more efficiently. The counter released in this gap period
9793 : : * should wait for a new round of query as the new arrived packets
9794 : : * will not be taken into account.
9795 : : */
9796 : 0 : pool->query_gen++;
9797 : 0 : ret = mlx5_devx_cmd_flow_counter_query(pool->min_dcs, 0,
9798 : : MLX5_COUNTERS_PER_POOL,
9799 : : NULL, NULL,
9800 : 0 : pool->raw_hw->mem_mng->wm.lkey,
9801 : : (void *)(uintptr_t)
9802 : 0 : pool->raw_hw->data,
9803 : : sh->devx_comp,
9804 : : (uint64_t)(uintptr_t)pool);
9805 [ # # ]: 0 : if (ret) {
9806 : 0 : DRV_LOG(ERR, "Failed to trigger asynchronous query for dcs ID"
9807 : : " %d", pool->min_dcs->id);
9808 : 0 : pool->raw_hw = NULL;
9809 : 0 : goto set_alarm;
9810 : : }
9811 [ # # ]: 0 : LIST_REMOVE(pool->raw_hw, next);
9812 : 0 : cmng->pending_queries++;
9813 : 0 : pool_index++;
9814 [ # # ]: 0 : if (pool_index >= n_valid)
9815 : : pool_index = 0;
9816 : 0 : set_alarm:
9817 : 0 : cmng->pool_index = pool_index;
9818 : 0 : mlx5_set_query_alarm(sh);
9819 : 0 : }
9820 : :
9821 : : /**
9822 : : * Check and callback event for new aged flow in the counter pool
9823 : : *
9824 : : * @param[in] sh
9825 : : * Pointer to mlx5_dev_ctx_shared object.
9826 : : * @param[in] pool
9827 : : * Pointer to Current counter pool.
9828 : : */
9829 : : static void
9830 : 0 : mlx5_flow_aging_check(struct mlx5_dev_ctx_shared *sh,
9831 : : struct mlx5_flow_counter_pool *pool)
9832 : : {
9833 : : struct mlx5_priv *priv;
9834 : : struct mlx5_flow_counter *cnt;
9835 : : struct mlx5_age_info *age_info;
9836 : : struct mlx5_age_param *age_param;
9837 : 0 : struct mlx5_counter_stats_raw *cur = pool->raw_hw;
9838 : 0 : struct mlx5_counter_stats_raw *prev = pool->raw;
9839 : 0 : const uint64_t curr_time = MLX5_CURR_TIME_SEC;
9840 : 0 : const uint32_t time_delta = curr_time - pool->time_of_last_age_check;
9841 : : uint16_t expected = AGE_CANDIDATE;
9842 : : uint32_t i;
9843 : :
9844 : 0 : pool->time_of_last_age_check = curr_time;
9845 [ # # ]: 0 : for (i = 0; i < MLX5_COUNTERS_PER_POOL; ++i) {
9846 [ # # ]: 0 : cnt = MLX5_POOL_GET_CNT(pool, i);
9847 : : age_param = MLX5_CNT_TO_AGE(cnt);
9848 [ # # ]: 0 : if (rte_atomic_load_explicit(&age_param->state,
9849 : : rte_memory_order_relaxed) != AGE_CANDIDATE)
9850 : 0 : continue;
9851 [ # # ]: 0 : if (cur->data[i].hits != prev->data[i].hits) {
9852 : 0 : rte_atomic_store_explicit(&age_param->sec_since_last_hit, 0,
9853 : : rte_memory_order_relaxed);
9854 : 0 : continue;
9855 : : }
9856 : 0 : if (rte_atomic_fetch_add_explicit(&age_param->sec_since_last_hit,
9857 : : time_delta,
9858 [ # # ]: 0 : rte_memory_order_relaxed) + time_delta <= age_param->timeout)
9859 : 0 : continue;
9860 : : /**
9861 : : * Hold the lock first, or if between the
9862 : : * state AGE_TMOUT and tailq operation the
9863 : : * release happened, the release procedure
9864 : : * may delete a non-existent tailq node.
9865 : : */
9866 : 0 : priv = rte_eth_devices[age_param->port_id].data->dev_private;
9867 : 0 : age_info = GET_PORT_AGE_INFO(priv);
9868 : 0 : rte_spinlock_lock(&age_info->aged_sl);
9869 [ # # ]: 0 : if (rte_atomic_compare_exchange_strong_explicit(&age_param->state, &expected,
9870 : : AGE_TMOUT,
9871 : : rte_memory_order_relaxed,
9872 : : rte_memory_order_relaxed)) {
9873 : 0 : TAILQ_INSERT_TAIL(&age_info->aged_counters, cnt, next);
9874 : 0 : MLX5_AGE_SET(age_info, MLX5_AGE_EVENT_NEW);
9875 : : }
9876 : : rte_spinlock_unlock(&age_info->aged_sl);
9877 : : }
9878 : 0 : mlx5_age_event_prepare(sh);
9879 : 0 : }
9880 : :
9881 : : /**
9882 : : * Handler for the HW respond about ready values from an asynchronous batch
9883 : : * query. This function is probably called by the host thread.
9884 : : *
9885 : : * @param[in] sh
9886 : : * The pointer to the shared device context.
9887 : : * @param[in] async_id
9888 : : * The Devx async ID.
9889 : : * @param[in] status
9890 : : * The status of the completion.
9891 : : */
9892 : : void
9893 : 0 : mlx5_flow_async_pool_query_handle(struct mlx5_dev_ctx_shared *sh,
9894 : : uint64_t async_id, int status)
9895 : : {
9896 : 0 : struct mlx5_flow_counter_pool *pool =
9897 : : (struct mlx5_flow_counter_pool *)(uintptr_t)async_id;
9898 : : struct mlx5_counter_stats_raw *raw_to_free;
9899 : 0 : uint8_t query_gen = pool->query_gen ^ 1;
9900 : : struct mlx5_flow_counter_mng *cmng = &sh->sws_cmng;
9901 : 0 : enum mlx5_counter_type cnt_type =
9902 : 0 : pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
9903 : : MLX5_COUNTER_TYPE_ORIGIN;
9904 : :
9905 [ # # ]: 0 : if (unlikely(status)) {
9906 : 0 : raw_to_free = pool->raw_hw;
9907 : : } else {
9908 : 0 : raw_to_free = pool->raw;
9909 [ # # ]: 0 : if (pool->is_aged)
9910 : 0 : mlx5_flow_aging_check(sh, pool);
9911 : 0 : rte_spinlock_lock(&pool->sl);
9912 : 0 : pool->raw = pool->raw_hw;
9913 : : rte_spinlock_unlock(&pool->sl);
9914 : : /* Be sure the new raw counters data is updated in memory. */
9915 : 0 : rte_io_wmb();
9916 [ # # ]: 0 : if (!TAILQ_EMPTY(&pool->counters[query_gen])) {
9917 : 0 : rte_spinlock_lock(&cmng->csl[cnt_type]);
9918 [ # # ]: 0 : TAILQ_CONCAT(&cmng->counters[cnt_type],
9919 : : &pool->counters[query_gen], next);
9920 : : rte_spinlock_unlock(&cmng->csl[cnt_type]);
9921 : : }
9922 : : }
9923 [ # # ]: 0 : LIST_INSERT_HEAD(&sh->sws_cmng.free_stat_raws, raw_to_free, next);
9924 : 0 : pool->raw_hw = NULL;
9925 : 0 : sh->sws_cmng.pending_queries--;
9926 : 0 : }
9927 : :
9928 : : static int
9929 : 0 : flow_group_to_table(uint32_t port_id, uint32_t group, uint32_t *table,
9930 : : const struct flow_grp_info *grp_info,
9931 : : struct rte_flow_error *error)
9932 : : {
9933 [ # # ]: 0 : if (grp_info->transfer && grp_info->external &&
9934 : : grp_info->fdb_def_rule) {
9935 [ # # ]: 0 : if (group == UINT32_MAX)
9936 : 0 : return rte_flow_error_set
9937 : : (error, EINVAL,
9938 : : RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
9939 : : NULL,
9940 : : "group index not supported");
9941 : 0 : *table = group + 1;
9942 : : } else {
9943 : 0 : *table = group;
9944 : : }
9945 : 0 : DRV_LOG(DEBUG, "port %u group=%#x table=%#x", port_id, group, *table);
9946 : 0 : return 0;
9947 : : }
9948 : :
9949 : : /**
9950 : : * Translate the rte_flow group index to HW table value.
9951 : : *
9952 : : * If tunnel offload is disabled, all group ids converted to flow table
9953 : : * id using the standard method.
9954 : : * If tunnel offload is enabled, group id can be converted using the
9955 : : * standard or tunnel conversion method. Group conversion method
9956 : : * selection depends on flags in `grp_info` parameter:
9957 : : * - Internal (grp_info.external == 0) groups conversion uses the
9958 : : * standard method.
9959 : : * - Group ids in JUMP action converted with the tunnel conversion.
9960 : : * - Group id in rule attribute conversion depends on a rule type and
9961 : : * group id value:
9962 : : * ** non zero group attributes converted with the tunnel method
9963 : : * ** zero group attribute in non-tunnel rule is converted using the
9964 : : * standard method - there's only one root table
9965 : : * ** zero group attribute in steer tunnel rule is converted with the
9966 : : * standard method - single root table
9967 : : * ** zero group attribute in match tunnel rule is a special OvS
9968 : : * case: that value is used for portability reasons. That group
9969 : : * id is converted with the tunnel conversion method.
9970 : : *
9971 : : * @param[in] dev
9972 : : * Port device
9973 : : * @param[in] tunnel
9974 : : * PMD tunnel offload object
9975 : : * @param[in] group
9976 : : * rte_flow group index value.
9977 : : * @param[out] table
9978 : : * HW table value.
9979 : : * @param[in] grp_info
9980 : : * flags used for conversion
9981 : : * @param[out] error
9982 : : * Pointer to error structure.
9983 : : *
9984 : : * @return
9985 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
9986 : : */
9987 : : int
9988 : 0 : mlx5_flow_group_to_table(struct rte_eth_dev *dev,
9989 : : const struct mlx5_flow_tunnel *tunnel,
9990 : : uint32_t group, uint32_t *table,
9991 : : const struct flow_grp_info *grp_info,
9992 : : struct rte_flow_error *error)
9993 : : {
9994 : : int ret;
9995 : : bool standard_translation;
9996 : :
9997 [ # # # # ]: 0 : if (!grp_info->skip_scale && grp_info->external &&
9998 : : group < MLX5_MAX_TABLES_EXTERNAL)
9999 : 0 : group *= MLX5_FLOW_TABLE_FACTOR;
10000 [ # # ]: 0 : if (is_tunnel_offload_active(dev)) {
10001 : 0 : standard_translation = !grp_info->external ||
10002 : : grp_info->std_tbl_fix;
10003 : : } else {
10004 : : standard_translation = true;
10005 : : }
10006 [ # # ]: 0 : DRV_LOG(DEBUG,
10007 : : "port %u group=%u transfer=%d external=%d fdb_def_rule=%d translate=%s",
10008 : : dev->data->port_id, group, grp_info->transfer,
10009 : : grp_info->external, grp_info->fdb_def_rule,
10010 : : standard_translation ? "STANDARD" : "TUNNEL");
10011 [ # # ]: 0 : if (standard_translation)
10012 : 0 : ret = flow_group_to_table(dev->data->port_id, group, table,
10013 : : grp_info, error);
10014 : : else
10015 : 0 : ret = tunnel_flow_group_to_flow_table(dev, tunnel, group,
10016 : : table, error);
10017 : :
10018 : 0 : return ret;
10019 : : }
10020 : :
10021 : : /**
10022 : : * Discover availability of metadata reg_c's.
10023 : : *
10024 : : * Iteratively use test flows to check availability.
10025 : : *
10026 : : * @param[in] dev
10027 : : * Pointer to the Ethernet device structure.
10028 : : *
10029 : : * @return
10030 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
10031 : : */
10032 : : int
10033 : 0 : mlx5_flow_discover_mreg_c(struct rte_eth_dev *dev)
10034 : : {
10035 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10036 : : enum modify_reg idx;
10037 : : int n = 0;
10038 : :
10039 : : /* reg_c[0] and reg_c[1] are reserved. */
10040 : 0 : priv->sh->flow_mreg_c[n++] = REG_C_0;
10041 : 0 : priv->sh->flow_mreg_c[n++] = REG_C_1;
10042 : : /* Discover availability of other reg_c's. */
10043 [ # # ]: 0 : for (idx = REG_C_2; idx <= REG_C_7; ++idx) {
10044 : 0 : struct rte_flow_attr attr = {
10045 : : .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
10046 : : .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
10047 : : .ingress = 1,
10048 : : };
10049 : 0 : struct rte_flow_item items[] = {
10050 : : [0] = {
10051 : : .type = RTE_FLOW_ITEM_TYPE_END,
10052 : : },
10053 : : };
10054 : 0 : struct rte_flow_action actions[] = {
10055 : : [0] = {
10056 : : .type = (enum rte_flow_action_type)
10057 : : MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
10058 : 0 : .conf = &(struct mlx5_flow_action_copy_mreg){
10059 : : .src = REG_C_1,
10060 : : .dst = idx,
10061 : : },
10062 : : },
10063 : : [1] = {
10064 : : .type = RTE_FLOW_ACTION_TYPE_JUMP,
10065 : 0 : .conf = &(struct rte_flow_action_jump){
10066 : : .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
10067 : : },
10068 : : },
10069 : : [2] = {
10070 : : .type = RTE_FLOW_ACTION_TYPE_END,
10071 : : },
10072 : : };
10073 : : uint32_t flow_idx;
10074 : : struct rte_flow *flow;
10075 : : struct rte_flow_error error;
10076 : :
10077 [ # # ]: 0 : if (!priv->sh->config.dv_flow_en)
10078 : : break;
10079 : : /* Create internal flow, validation skips copy action. */
10080 : 0 : flow_idx = mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_GEN, &attr,
10081 : : items, actions, false, &error);
10082 : 0 : flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
10083 : : flow_idx);
10084 [ # # ]: 0 : if (!flow)
10085 : 0 : continue;
10086 : 0 : priv->sh->flow_mreg_c[n++] = idx;
10087 : 0 : mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN, flow_idx);
10088 : : }
10089 [ # # ]: 0 : for (; n < MLX5_MREG_C_NUM; ++n)
10090 : 0 : priv->sh->flow_mreg_c[n] = REG_NON;
10091 : 0 : priv->sh->metadata_regc_check_flag = 1;
10092 : 0 : return 0;
10093 : : }
10094 : :
10095 : : int
10096 [ # # # # ]: 0 : mlx5_save_dump_file(const uint8_t *data, uint32_t size,
10097 : : uint32_t type, uint64_t id, void *arg, FILE *file)
10098 : : {
10099 : : char line[BUF_SIZE];
10100 : : uint32_t out = 0;
10101 : : uint32_t k;
10102 : : uint32_t actions_num;
10103 : : struct rte_flow_query_count *count;
10104 : :
10105 : : memset(line, 0, BUF_SIZE);
10106 [ # # # # ]: 0 : switch (type) {
10107 : 0 : case DR_DUMP_REC_TYPE_PMD_MODIFY_HDR:
10108 : 0 : actions_num = *(uint32_t *)(arg);
10109 : 0 : out += snprintf(line + out, BUF_SIZE - out, "%d,0x%" PRIx64 ",%d,",
10110 : : type, id, actions_num);
10111 : 0 : break;
10112 : 0 : case DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT:
10113 : 0 : out += snprintf(line + out, BUF_SIZE - out, "%d,0x%" PRIx64 ",",
10114 : : type, id);
10115 : 0 : break;
10116 : 0 : case DR_DUMP_REC_TYPE_PMD_COUNTER:
10117 : : count = (struct rte_flow_query_count *)arg;
10118 : 0 : fprintf(file,
10119 : : "%d,0x%" PRIx64 ",%" PRIu64 ",%" PRIu64 "\n",
10120 : : type, id, count->hits, count->bytes);
10121 : 0 : return 0;
10122 : : default:
10123 : : return -1;
10124 : : }
10125 : :
10126 [ # # ]: 0 : for (k = 0; k < size; k++) {
10127 : : /* Make sure we do not overrun the line buffer length. */
10128 [ # # ]: 0 : if (out >= BUF_SIZE - 4) {
10129 : 0 : line[out] = '\0';
10130 : 0 : break;
10131 : : }
10132 : 0 : out += snprintf(line + out, BUF_SIZE - out, "%02x",
10133 : 0 : (data[k]) & 0xff);
10134 : : }
10135 : : fprintf(file, "%s\n", line);
10136 : 0 : return 0;
10137 : : }
10138 : :
10139 : : int
10140 : 0 : mlx5_flow_query_counter(struct rte_eth_dev *dev, struct rte_flow *flow,
10141 : : struct rte_flow_query_count *count, struct rte_flow_error *error)
10142 : : {
10143 : : struct rte_flow_action action[2];
10144 : : enum mlx5_flow_drv_type ftype;
10145 : : const struct mlx5_flow_driver_ops *fops;
10146 : :
10147 [ # # ]: 0 : if (!flow) {
10148 : 0 : return rte_flow_error_set(error, ENOENT,
10149 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10150 : : NULL,
10151 : : "invalid flow handle");
10152 : : }
10153 : 0 : action[0].type = RTE_FLOW_ACTION_TYPE_COUNT;
10154 : 0 : action[1].type = RTE_FLOW_ACTION_TYPE_END;
10155 [ # # ]: 0 : if (flow->counter) {
10156 : : memset(count, 0, sizeof(struct rte_flow_query_count));
10157 : 0 : ftype = (enum mlx5_flow_drv_type)(flow->drv_type);
10158 : : MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN &&
10159 : : ftype < MLX5_FLOW_TYPE_MAX);
10160 : 0 : fops = flow_get_drv_ops(ftype);
10161 : 0 : return fops->query(dev, flow, action, count, error);
10162 : : }
10163 : : return -1;
10164 : : }
10165 : :
10166 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
10167 : : /**
10168 : : * Dump flow ipool data to file
10169 : : *
10170 : : * @param[in] dev
10171 : : * The pointer to Ethernet device.
10172 : : * @param[in] file
10173 : : * A pointer to a file for output.
10174 : : * @param[out] error
10175 : : * Perform verbose error reporting if not NULL. PMDs initialize this
10176 : : * structure in case of error only.
10177 : : * @return
10178 : : * 0 on success, a negative value otherwise.
10179 : : */
10180 : : int
10181 : 0 : mlx5_flow_dev_dump_ipool(struct rte_eth_dev *dev,
10182 : : struct rte_flow *flow, FILE *file,
10183 : : struct rte_flow_error *error)
10184 : : {
10185 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10186 : : struct mlx5_flow_dv_modify_hdr_resource *modify_hdr;
10187 : : struct mlx5_flow_dv_encap_decap_resource *encap_decap;
10188 : : uint32_t handle_idx;
10189 : : struct mlx5_flow_handle *dh;
10190 : : struct rte_flow_query_count count;
10191 : : uint32_t actions_num;
10192 : : const uint8_t *data;
10193 : : size_t size;
10194 : : uint64_t id;
10195 : : uint32_t type;
10196 : 0 : void *action = NULL;
10197 : :
10198 [ # # ]: 0 : if (!flow) {
10199 : 0 : return rte_flow_error_set(error, ENOENT,
10200 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
10201 : : NULL,
10202 : : "invalid flow handle");
10203 : : }
10204 : 0 : handle_idx = flow->dev_handles;
10205 : : /* query counter */
10206 [ # # # # ]: 0 : if (flow->counter &&
10207 : 0 : (!mlx5_counter_query(dev, flow->counter, false,
10208 [ # # ]: 0 : &count.hits, &count.bytes, &action)) && action) {
10209 : 0 : id = (uint64_t)(uintptr_t)action;
10210 : : type = DR_DUMP_REC_TYPE_PMD_COUNTER;
10211 : 0 : mlx5_save_dump_file(NULL, 0, type,
10212 : : id, (void *)&count, file);
10213 : : }
10214 : :
10215 [ # # ]: 0 : while (handle_idx) {
10216 : 0 : dh = mlx5_ipool_get(priv->sh->ipool
10217 : : [MLX5_IPOOL_MLX5_FLOW], handle_idx);
10218 [ # # ]: 0 : if (!dh)
10219 : 0 : continue;
10220 : 0 : handle_idx = dh->next.next;
10221 : :
10222 : : /* Get modify_hdr and encap_decap buf from ipools. */
10223 : : encap_decap = NULL;
10224 : 0 : modify_hdr = dh->dvh.modify_hdr;
10225 : :
10226 [ # # ]: 0 : if (dh->dvh.rix_encap_decap) {
10227 : 0 : encap_decap = mlx5_ipool_get(priv->sh->ipool
10228 : : [MLX5_IPOOL_DECAP_ENCAP],
10229 : : dh->dvh.rix_encap_decap);
10230 : : }
10231 [ # # ]: 0 : if (modify_hdr) {
10232 : 0 : data = (const uint8_t *)modify_hdr->actions;
10233 : 0 : size = (size_t)(modify_hdr->actions_num) * 8;
10234 : 0 : id = (uint64_t)(uintptr_t)modify_hdr->action;
10235 : 0 : actions_num = modify_hdr->actions_num;
10236 : : type = DR_DUMP_REC_TYPE_PMD_MODIFY_HDR;
10237 : 0 : mlx5_save_dump_file(data, size, type, id,
10238 : : (void *)(&actions_num), file);
10239 : : }
10240 [ # # ]: 0 : if (encap_decap) {
10241 : 0 : data = encap_decap->buf;
10242 : 0 : size = encap_decap->size;
10243 : 0 : id = (uint64_t)(uintptr_t)encap_decap->action;
10244 : : type = DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT;
10245 : 0 : mlx5_save_dump_file(data, size, type,
10246 : : id, NULL, file);
10247 : : }
10248 : : }
10249 : : return 0;
10250 : : }
10251 : :
10252 : : /**
10253 : : * Dump all flow's encap_decap/modify_hdr/counter data to file
10254 : : *
10255 : : * @param[in] dev
10256 : : * The pointer to Ethernet device.
10257 : : * @param[in] file
10258 : : * A pointer to a file for output.
10259 : : * @param[out] error
10260 : : * Perform verbose error reporting if not NULL. PMDs initialize this
10261 : : * structure in case of error only.
10262 : : * @return
10263 : : * 0 on success, a negative value otherwise.
10264 : : */
10265 : : static int
10266 : 0 : mlx5_flow_dev_dump_sh_all(struct rte_eth_dev *dev,
10267 : : FILE *file, struct rte_flow_error *error __rte_unused)
10268 : : {
10269 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10270 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
10271 : : struct mlx5_hlist *h;
10272 : : struct mlx5_flow_dv_modify_hdr_resource *modify_hdr;
10273 : : struct mlx5_flow_dv_encap_decap_resource *encap_decap;
10274 : : struct rte_flow_query_count count;
10275 : : uint32_t actions_num;
10276 : : const uint8_t *data;
10277 : : size_t size;
10278 : : uint64_t id;
10279 : : uint32_t type;
10280 : : uint32_t i;
10281 : : uint32_t j;
10282 : : struct mlx5_list_inconst *l_inconst;
10283 : : struct mlx5_list_entry *e;
10284 : : int lcore_index;
10285 : : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
10286 : : uint32_t max;
10287 : : void *action;
10288 : :
10289 : : /* encap_decap hlist is lcore_share, get global core cache. */
10290 : : i = MLX5_LIST_GLOBAL;
10291 : 0 : h = sh->encaps_decaps;
10292 [ # # ]: 0 : if (h) {
10293 [ # # ]: 0 : for (j = 0; j <= h->mask; j++) {
10294 : : l_inconst = &h->buckets[j].l;
10295 [ # # ]: 0 : if (!l_inconst || !l_inconst->cache[i])
10296 : 0 : continue;
10297 : :
10298 : 0 : e = LIST_FIRST(&l_inconst->cache[i]->h);
10299 [ # # ]: 0 : while (e) {
10300 : : encap_decap =
10301 : : (struct mlx5_flow_dv_encap_decap_resource *)e;
10302 : 0 : data = encap_decap->buf;
10303 : 0 : size = encap_decap->size;
10304 : 0 : id = (uint64_t)(uintptr_t)encap_decap->action;
10305 : : type = DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT;
10306 : 0 : mlx5_save_dump_file(data, size, type,
10307 : : id, NULL, file);
10308 : 0 : e = LIST_NEXT(e, next);
10309 : : }
10310 : : }
10311 : : }
10312 : :
10313 : : /* get modify_hdr */
10314 : 0 : h = sh->modify_cmds;
10315 [ # # ]: 0 : if (h) {
10316 : 0 : lcore_index = rte_lcore_index(rte_lcore_id());
10317 [ # # ]: 0 : if (unlikely(lcore_index == -1)) {
10318 : : lcore_index = MLX5_LIST_NLCORE;
10319 : 0 : rte_spinlock_lock(&h->l_const.lcore_lock);
10320 : : }
10321 : 0 : i = lcore_index;
10322 : :
10323 [ # # ]: 0 : if (lcore_index == MLX5_LIST_NLCORE) {
10324 [ # # ]: 0 : for (i = 0; i <= (uint32_t)lcore_index; i++) {
10325 [ # # ]: 0 : for (j = 0; j <= h->mask; j++) {
10326 : : l_inconst = &h->buckets[j].l;
10327 [ # # ]: 0 : if (!l_inconst || !l_inconst->cache[i])
10328 : 0 : continue;
10329 : :
10330 : 0 : e = LIST_FIRST(&l_inconst->cache[i]->h);
10331 [ # # ]: 0 : while (e) {
10332 : : modify_hdr =
10333 : : (struct mlx5_flow_dv_modify_hdr_resource *)e;
10334 : 0 : data = (const uint8_t *)modify_hdr->actions;
10335 : 0 : size = (size_t)(modify_hdr->actions_num) * 8;
10336 : 0 : actions_num = modify_hdr->actions_num;
10337 : 0 : id = (uint64_t)(uintptr_t)modify_hdr->action;
10338 : : type = DR_DUMP_REC_TYPE_PMD_MODIFY_HDR;
10339 : 0 : mlx5_save_dump_file(data, size, type, id,
10340 : : (void *)(&actions_num), file);
10341 : 0 : e = LIST_NEXT(e, next);
10342 : : }
10343 : : }
10344 : : }
10345 : : } else {
10346 [ # # ]: 0 : for (j = 0; j <= h->mask; j++) {
10347 : : l_inconst = &h->buckets[j].l;
10348 [ # # ]: 0 : if (!l_inconst || !l_inconst->cache[i])
10349 : 0 : continue;
10350 : :
10351 : 0 : e = LIST_FIRST(&l_inconst->cache[i]->h);
10352 [ # # ]: 0 : while (e) {
10353 : : modify_hdr =
10354 : : (struct mlx5_flow_dv_modify_hdr_resource *)e;
10355 : 0 : data = (const uint8_t *)modify_hdr->actions;
10356 : 0 : size = (size_t)(modify_hdr->actions_num) * 8;
10357 : 0 : actions_num = modify_hdr->actions_num;
10358 : 0 : id = (uint64_t)(uintptr_t)modify_hdr->action;
10359 : : type = DR_DUMP_REC_TYPE_PMD_MODIFY_HDR;
10360 : 0 : mlx5_save_dump_file(data, size, type, id,
10361 : : (void *)(&actions_num), file);
10362 : 0 : e = LIST_NEXT(e, next);
10363 : : }
10364 : : }
10365 : : }
10366 : :
10367 [ # # ]: 0 : if (unlikely(lcore_index == MLX5_LIST_NLCORE))
10368 : 0 : rte_spinlock_unlock(&h->l_const.lcore_lock);
10369 : : }
10370 : :
10371 : : /* get counter */
10372 : : MLX5_ASSERT(cmng->n_valid <= MLX5_COUNTER_POOLS_MAX_NUM);
10373 : 0 : max = MLX5_COUNTERS_PER_POOL * cmng->n_valid;
10374 [ # # ]: 0 : for (j = 1; j <= max; j++) {
10375 : 0 : action = NULL;
10376 [ # # ]: 0 : if ((!mlx5_counter_query(dev, j, false, &count.hits,
10377 [ # # ]: 0 : &count.bytes, &action)) && action) {
10378 : 0 : id = (uint64_t)(uintptr_t)action;
10379 : : type = DR_DUMP_REC_TYPE_PMD_COUNTER;
10380 : 0 : mlx5_save_dump_file(NULL, 0, type,
10381 : : id, (void *)&count, file);
10382 : : }
10383 : : }
10384 : 0 : return 0;
10385 : : }
10386 : : #endif
10387 : :
10388 : : /**
10389 : : * Dump flow raw hw data to file
10390 : : *
10391 : : * @param[in] dev
10392 : : * The pointer to Ethernet device.
10393 : : * @param[in] file
10394 : : * A pointer to a file for output.
10395 : : * @param[out] error
10396 : : * Perform verbose error reporting if not NULL. PMDs initialize this
10397 : : * structure in case of error only.
10398 : : * @return
10399 : : * 0 on success, a negative value otherwise.
10400 : : */
10401 : : int
10402 : 0 : mlx5_flow_dev_dump(struct rte_eth_dev *dev, struct rte_flow *flow_idx,
10403 : : FILE *file,
10404 : : struct rte_flow_error *error __rte_unused)
10405 : : {
10406 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10407 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
10408 : : uint32_t handle_idx;
10409 : : int ret;
10410 : : struct mlx5_flow_handle *dh;
10411 : : struct rte_flow *flow;
10412 : :
10413 [ # # ]: 0 : if (!sh->config.dv_flow_en) {
10414 [ # # ]: 0 : if (fputs("device dv flow disabled\n", file) <= 0)
10415 : 0 : return -errno;
10416 : : return -ENOTSUP;
10417 : : }
10418 : :
10419 : : /* dump all */
10420 [ # # ]: 0 : if (!flow_idx) {
10421 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
10422 [ # # ]: 0 : if (mlx5_flow_dev_dump_sh_all(dev, file, error))
10423 : : return -EINVAL;
10424 : :
10425 [ # # ]: 0 : if (sh->config.dv_flow_en == 2)
10426 : 0 : return mlx5dr_debug_dump(priv->dr_ctx, file);
10427 : : #endif
10428 : 0 : return mlx5_devx_cmd_flow_dump(sh->fdb_domain,
10429 : : sh->rx_domain,
10430 : : sh->tx_domain, file);
10431 : : }
10432 : : /* dump one */
10433 : 0 : flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
10434 : : (uintptr_t)(void *)flow_idx);
10435 [ # # ]: 0 : if (!flow)
10436 : : return -EINVAL;
10437 : :
10438 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
10439 : 0 : mlx5_flow_dev_dump_ipool(dev, flow, file, error);
10440 : : #endif
10441 : 0 : handle_idx = flow->dev_handles;
10442 [ # # ]: 0 : while (handle_idx) {
10443 : 0 : dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
10444 : : handle_idx);
10445 [ # # ]: 0 : if (!dh)
10446 : : return -ENOENT;
10447 [ # # ]: 0 : if (dh->drv_flow) {
10448 [ # # ]: 0 : if (sh->config.dv_flow_en == 2)
10449 : : return -ENOTSUP;
10450 : :
10451 : 0 : ret = mlx5_devx_cmd_flow_single_dump(dh->drv_flow,
10452 : : file);
10453 [ # # ]: 0 : if (ret)
10454 : : return -ENOENT;
10455 : : }
10456 : 0 : handle_idx = dh->next.next;
10457 : : }
10458 : : return 0;
10459 : : }
10460 : :
10461 : : /**
10462 : : * Get aged-out flows.
10463 : : *
10464 : : * @param[in] dev
10465 : : * Pointer to the Ethernet device structure.
10466 : : * @param[in] context
10467 : : * The address of an array of pointers to the aged-out flows contexts.
10468 : : * @param[in] nb_countexts
10469 : : * The length of context array pointers.
10470 : : * @param[out] error
10471 : : * Perform verbose error reporting if not NULL. Initialized in case of
10472 : : * error only.
10473 : : *
10474 : : * @return
10475 : : * how many contexts get in success, otherwise negative errno value.
10476 : : * if nb_contexts is 0, return the amount of all aged contexts.
10477 : : * if nb_contexts is not 0 , return the amount of aged flows reported
10478 : : * in the context array.
10479 : : */
10480 : : int
10481 [ # # ]: 0 : mlx5_flow_get_aged_flows(struct rte_eth_dev *dev, void **contexts,
10482 : : uint32_t nb_contexts, struct rte_flow_error *error)
10483 : : {
10484 : : struct rte_flow_attr attr = { .transfer = 0 };
10485 : :
10486 : 0 : return flow_get_drv_ops(flow_get_drv_type(dev, &attr))->get_aged_flows
10487 : : (dev, contexts, nb_contexts, error);
10488 : : }
10489 : :
10490 : : /**
10491 : : * Get aged-out flows per HWS queue.
10492 : : *
10493 : : * @param[in] dev
10494 : : * Pointer to the Ethernet device structure.
10495 : : * @param[in] queue_id
10496 : : * Flow queue to query.
10497 : : * @param[in] context
10498 : : * The address of an array of pointers to the aged-out flows contexts.
10499 : : * @param[in] nb_countexts
10500 : : * The length of context array pointers.
10501 : : * @param[out] error
10502 : : * Perform verbose error reporting if not NULL. Initialized in case of
10503 : : * error only.
10504 : : *
10505 : : * @return
10506 : : * how many contexts get in success, otherwise negative errno value.
10507 : : * if nb_contexts is 0, return the amount of all aged contexts.
10508 : : * if nb_contexts is not 0 , return the amount of aged flows reported
10509 : : * in the context array.
10510 : : */
10511 : : int
10512 [ # # ]: 0 : mlx5_flow_get_q_aged_flows(struct rte_eth_dev *dev, uint32_t queue_id,
10513 : : void **contexts, uint32_t nb_contexts,
10514 : : struct rte_flow_error *error)
10515 : : {
10516 : : const struct mlx5_flow_driver_ops *fops;
10517 : : struct rte_flow_attr attr = { 0 };
10518 : :
10519 : : if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_HW) {
10520 : 0 : fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
10521 : 0 : return fops->get_q_aged_flows(dev, queue_id, contexts,
10522 : : nb_contexts, error);
10523 : : }
10524 : 0 : DRV_LOG(ERR, "port %u queue %u get aged flows is not supported.",
10525 : : dev->data->port_id, queue_id);
10526 : 0 : return rte_flow_error_set(error, ENOTSUP,
10527 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10528 : : "get Q aged flows with incorrect steering mode");
10529 : : }
10530 : :
10531 : : /* Wrapper for driver action_validate op callback */
10532 : : static int
10533 : 0 : flow_drv_action_validate(struct rte_eth_dev *dev,
10534 : : const struct rte_flow_indir_action_conf *conf,
10535 : : const struct rte_flow_action *action,
10536 : : const struct mlx5_flow_driver_ops *fops,
10537 : : struct rte_flow_error *error)
10538 : : {
10539 : : static const char err_msg[] = "indirect action validation unsupported";
10540 : :
10541 [ # # ]: 0 : if (!fops->action_validate) {
10542 : 0 : DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
10543 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
10544 : : NULL, err_msg);
10545 : 0 : return -rte_errno;
10546 : : }
10547 : 0 : return fops->action_validate(dev, conf, action, error);
10548 : : }
10549 : :
10550 : : /**
10551 : : * Destroys the shared action by handle.
10552 : : *
10553 : : * @param dev
10554 : : * Pointer to Ethernet device structure.
10555 : : * @param[in] handle
10556 : : * Handle for the indirect action object to be destroyed.
10557 : : * @param[out] error
10558 : : * Perform verbose error reporting if not NULL. PMDs initialize this
10559 : : * structure in case of error only.
10560 : : *
10561 : : * @return
10562 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
10563 : : *
10564 : : * @note: wrapper for driver action_create op callback.
10565 : : */
10566 : : static int
10567 [ # # ]: 0 : mlx5_action_handle_destroy(struct rte_eth_dev *dev,
10568 : : struct rte_flow_action_handle *handle,
10569 : : struct rte_flow_error *error)
10570 : : {
10571 : : static const char err_msg[] = "indirect action destruction unsupported";
10572 : : struct rte_flow_attr attr = { .transfer = 0 };
10573 : 0 : const struct mlx5_flow_driver_ops *fops =
10574 : : flow_get_drv_ops(flow_get_drv_type(dev, &attr));
10575 : :
10576 [ # # ]: 0 : if (!fops->action_destroy) {
10577 : 0 : DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
10578 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
10579 : : NULL, err_msg);
10580 : 0 : return -rte_errno;
10581 : : }
10582 : 0 : return fops->action_destroy(dev, handle, error);
10583 : : }
10584 : :
10585 : : /* Wrapper for driver action_destroy op callback */
10586 : : static int
10587 : 0 : flow_drv_action_update(struct rte_eth_dev *dev,
10588 : : struct rte_flow_action_handle *handle,
10589 : : const void *update,
10590 : : const struct mlx5_flow_driver_ops *fops,
10591 : : struct rte_flow_error *error)
10592 : : {
10593 : : static const char err_msg[] = "indirect action update unsupported";
10594 : :
10595 [ # # ]: 0 : if (!fops->action_update) {
10596 : 0 : DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
10597 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
10598 : : NULL, err_msg);
10599 : 0 : return -rte_errno;
10600 : : }
10601 : 0 : return fops->action_update(dev, handle, update, error);
10602 : : }
10603 : :
10604 : : /* Wrapper for driver action_destroy op callback */
10605 : : static int
10606 : 0 : flow_drv_action_query(struct rte_eth_dev *dev,
10607 : : const struct rte_flow_action_handle *handle,
10608 : : void *data,
10609 : : const struct mlx5_flow_driver_ops *fops,
10610 : : struct rte_flow_error *error)
10611 : : {
10612 : : static const char err_msg[] = "indirect action query unsupported";
10613 : :
10614 [ # # ]: 0 : if (!fops->action_query) {
10615 : 0 : DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
10616 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
10617 : : NULL, err_msg);
10618 : 0 : return -rte_errno;
10619 : : }
10620 : 0 : return fops->action_query(dev, handle, data, error);
10621 : : }
10622 : :
10623 : : /**
10624 : : * Create indirect action for reuse in multiple flow rules.
10625 : : *
10626 : : * @param dev
10627 : : * Pointer to Ethernet device structure.
10628 : : * @param conf
10629 : : * Pointer to indirect action object configuration.
10630 : : * @param[in] action
10631 : : * Action configuration for indirect action object creation.
10632 : : * @param[out] error
10633 : : * Perform verbose error reporting if not NULL. PMDs initialize this
10634 : : * structure in case of error only.
10635 : : * @return
10636 : : * A valid handle in case of success, NULL otherwise and rte_errno is set.
10637 : : */
10638 : : static struct rte_flow_action_handle *
10639 [ # # ]: 0 : mlx5_action_handle_create(struct rte_eth_dev *dev,
10640 : : const struct rte_flow_indir_action_conf *conf,
10641 : : const struct rte_flow_action *action,
10642 : : struct rte_flow_error *error)
10643 : : {
10644 : : static const char err_msg[] = "indirect action creation unsupported";
10645 : : struct rte_flow_attr attr = { .transfer = 0 };
10646 : 0 : const struct mlx5_flow_driver_ops *fops =
10647 : : flow_get_drv_ops(flow_get_drv_type(dev, &attr));
10648 : :
10649 [ # # ]: 0 : if (flow_drv_action_validate(dev, conf, action, fops, error))
10650 : : return NULL;
10651 [ # # ]: 0 : if (!fops->action_create) {
10652 : 0 : DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
10653 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
10654 : : NULL, err_msg);
10655 : 0 : return NULL;
10656 : : }
10657 : 0 : return fops->action_create(dev, conf, action, error);
10658 : : }
10659 : :
10660 : : /**
10661 : : * Updates inplace the indirect action configuration pointed by *handle*
10662 : : * with the configuration provided as *update* argument.
10663 : : * The update of the indirect action configuration effects all flow rules
10664 : : * reusing the action via handle.
10665 : : *
10666 : : * @param dev
10667 : : * Pointer to Ethernet device structure.
10668 : : * @param[in] handle
10669 : : * Handle for the indirect action to be updated.
10670 : : * @param[in] update
10671 : : * Action specification used to modify the action pointed by handle.
10672 : : * *update* could be of same type with the action pointed by the *handle*
10673 : : * handle argument, or some other structures like a wrapper, depending on
10674 : : * the indirect action type.
10675 : : * @param[out] error
10676 : : * Perform verbose error reporting if not NULL. PMDs initialize this
10677 : : * structure in case of error only.
10678 : : *
10679 : : * @return
10680 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
10681 : : */
10682 : : static int
10683 [ # # ]: 0 : mlx5_action_handle_update(struct rte_eth_dev *dev,
10684 : : struct rte_flow_action_handle *handle,
10685 : : const void *update,
10686 : : struct rte_flow_error *error)
10687 : : {
10688 : : struct rte_flow_attr attr = { .transfer = 0 };
10689 : 0 : const struct mlx5_flow_driver_ops *fops =
10690 : : flow_get_drv_ops(flow_get_drv_type(dev, &attr));
10691 : : int ret;
10692 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
10693 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
10694 : :
10695 [ # # ]: 0 : switch (type) {
10696 : : case MLX5_INDIRECT_ACTION_TYPE_CT:
10697 : : case MLX5_INDIRECT_ACTION_TYPE_METER_MARK:
10698 : : ret = 0;
10699 : : break;
10700 : 0 : default:
10701 : 0 : ret = flow_drv_action_validate(dev, NULL,
10702 : : (const struct rte_flow_action *)update,
10703 : : fops, error);
10704 : : }
10705 [ # # ]: 0 : if (ret)
10706 : : return ret;
10707 : 0 : return flow_drv_action_update(dev, handle, update, fops,
10708 : : error);
10709 : : }
10710 : :
10711 : : /**
10712 : : * Query the indirect action by handle.
10713 : : *
10714 : : * This function allows retrieving action-specific data such as counters.
10715 : : * Data is gathered by special action which may be present/referenced in
10716 : : * more than one flow rule definition.
10717 : : *
10718 : : * see @RTE_FLOW_ACTION_TYPE_COUNT
10719 : : *
10720 : : * @param dev
10721 : : * Pointer to Ethernet device structure.
10722 : : * @param[in] handle
10723 : : * Handle for the indirect action to query.
10724 : : * @param[in, out] data
10725 : : * Pointer to storage for the associated query data type.
10726 : : * @param[out] error
10727 : : * Perform verbose error reporting if not NULL. PMDs initialize this
10728 : : * structure in case of error only.
10729 : : *
10730 : : * @return
10731 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
10732 : : */
10733 : : static int
10734 [ # # ]: 0 : mlx5_action_handle_query(struct rte_eth_dev *dev,
10735 : : const struct rte_flow_action_handle *handle,
10736 : : void *data,
10737 : : struct rte_flow_error *error)
10738 : : {
10739 : : struct rte_flow_attr attr = { .transfer = 0 };
10740 : 0 : const struct mlx5_flow_driver_ops *fops =
10741 : : flow_get_drv_ops(flow_get_drv_type(dev, &attr));
10742 : :
10743 : 0 : return flow_drv_action_query(dev, handle, data, fops, error);
10744 : : }
10745 : :
10746 : : static int
10747 [ # # ]: 0 : mlx5_action_handle_query_update(struct rte_eth_dev *dev,
10748 : : struct rte_flow_action_handle *handle,
10749 : : const void *update, void *query,
10750 : : enum rte_flow_query_update_mode qu_mode,
10751 : : struct rte_flow_error *error)
10752 : : {
10753 : : struct rte_flow_attr attr = { .transfer = 0 };
10754 : : enum mlx5_flow_drv_type drv_type = flow_get_drv_type(dev, &attr);
10755 : : const struct mlx5_flow_driver_ops *fops;
10756 : :
10757 : : if (drv_type == MLX5_FLOW_TYPE_MIN || drv_type == MLX5_FLOW_TYPE_MAX)
10758 : : return rte_flow_error_set(error, ENOTSUP,
10759 : : RTE_FLOW_ERROR_TYPE_ACTION,
10760 : : NULL, "invalid driver type");
10761 : 0 : fops = flow_get_drv_ops(drv_type);
10762 [ # # # # ]: 0 : if (!fops || !fops->action_query_update)
10763 : 0 : return rte_flow_error_set(error, ENOTSUP,
10764 : : RTE_FLOW_ERROR_TYPE_ACTION,
10765 : : NULL, "no query_update handler");
10766 : 0 : return fops->action_query_update(dev, handle, update,
10767 : : query, qu_mode, error);
10768 : : }
10769 : :
10770 : :
10771 : : #define MLX5_DRV_FOPS_OR_ERR(dev, fops, drv_cb, ret) \
10772 : : { \
10773 : : struct rte_flow_attr attr = { .transfer = 0 }; \
10774 : : enum mlx5_flow_drv_type drv_type = flow_get_drv_type((dev), &attr); \
10775 : : if (drv_type == MLX5_FLOW_TYPE_MIN || \
10776 : : drv_type == MLX5_FLOW_TYPE_MAX) { \
10777 : : rte_flow_error_set(error, ENOTSUP, \
10778 : : RTE_FLOW_ERROR_TYPE_ACTION, \
10779 : : NULL, "invalid driver type"); \
10780 : : return ret; \
10781 : : } \
10782 : : (fops) = flow_get_drv_ops(drv_type); \
10783 : : if (!(fops) || !(fops)->drv_cb) { \
10784 : : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, \
10785 : : NULL, "no action_list handler"); \
10786 : : return ret; \
10787 : : } \
10788 : : }
10789 : :
10790 : : static struct rte_flow_action_list_handle *
10791 [ # # ]: 0 : mlx5_action_list_handle_create(struct rte_eth_dev *dev,
10792 : : const struct rte_flow_indir_action_conf *conf,
10793 : : const struct rte_flow_action *actions,
10794 : : struct rte_flow_error *error)
10795 : : {
10796 : : const struct mlx5_flow_driver_ops *fops;
10797 : :
10798 [ # # # # ]: 0 : MLX5_DRV_FOPS_OR_ERR(dev, fops, action_list_handle_create, NULL);
10799 : 0 : return fops->action_list_handle_create(dev, conf, actions, error);
10800 : : }
10801 : :
10802 : : static int
10803 [ # # ]: 0 : mlx5_action_list_handle_destroy(struct rte_eth_dev *dev,
10804 : : struct rte_flow_action_list_handle *handle,
10805 : : struct rte_flow_error *error)
10806 : : {
10807 : : const struct mlx5_flow_driver_ops *fops;
10808 : :
10809 [ # # # # ]: 0 : MLX5_DRV_FOPS_OR_ERR(dev, fops, action_list_handle_destroy, ENOTSUP);
10810 : 0 : return fops->action_list_handle_destroy(dev, handle, error);
10811 : : }
10812 : :
10813 : : static int
10814 [ # # ]: 0 : mlx5_flow_action_list_handle_query_update(struct rte_eth_dev *dev,
10815 : : const
10816 : : struct rte_flow_action_list_handle *handle,
10817 : : const void **update, void **query,
10818 : : enum rte_flow_query_update_mode mode,
10819 : : struct rte_flow_error *error)
10820 : : {
10821 : : const struct mlx5_flow_driver_ops *fops;
10822 : :
10823 [ # # # # ]: 0 : MLX5_DRV_FOPS_OR_ERR(dev, fops,
10824 : : action_list_handle_query_update, ENOTSUP);
10825 : 0 : return fops->action_list_handle_query_update(dev, handle, update, query,
10826 : : mode, error);
10827 : : }
10828 : : static int
10829 [ # # ]: 0 : mlx5_flow_calc_table_hash(struct rte_eth_dev *dev,
10830 : : const struct rte_flow_template_table *table,
10831 : : const struct rte_flow_item pattern[],
10832 : : uint8_t pattern_template_index,
10833 : : uint32_t *hash, struct rte_flow_error *error)
10834 : : {
10835 : : struct rte_flow_attr attr = { .transfer = 0 };
10836 : : enum mlx5_flow_drv_type drv_type = flow_get_drv_type(dev, &attr);
10837 : : const struct mlx5_flow_driver_ops *fops;
10838 : :
10839 : : if (drv_type == MLX5_FLOW_TYPE_MIN || drv_type == MLX5_FLOW_TYPE_MAX)
10840 : : return rte_flow_error_set(error, ENOTSUP,
10841 : : RTE_FLOW_ERROR_TYPE_ACTION,
10842 : : NULL, "invalid driver type");
10843 : 0 : fops = flow_get_drv_ops(drv_type);
10844 [ # # # # ]: 0 : if (!fops || !fops->action_query_update)
10845 : 0 : return rte_flow_error_set(error, ENOTSUP,
10846 : : RTE_FLOW_ERROR_TYPE_ACTION,
10847 : : NULL, "no query_update handler");
10848 : 0 : return fops->flow_calc_table_hash(dev, table, pattern, pattern_template_index,
10849 : : hash, error);
10850 : : }
10851 : :
10852 : : static int
10853 [ # # ]: 0 : mlx5_flow_calc_encap_hash(struct rte_eth_dev *dev,
10854 : : const struct rte_flow_item pattern[],
10855 : : enum rte_flow_encap_hash_field dest_field,
10856 : : uint8_t *hash,
10857 : : struct rte_flow_error *error)
10858 : : {
10859 : : enum mlx5_flow_drv_type drv_type = flow_get_drv_type(dev, NULL);
10860 : : const struct mlx5_flow_driver_ops *fops;
10861 : :
10862 : : if (drv_type == MLX5_FLOW_TYPE_MIN || drv_type == MLX5_FLOW_TYPE_MAX)
10863 : 0 : return rte_flow_error_set(error, ENOTSUP,
10864 : : RTE_FLOW_ERROR_TYPE_ACTION,
10865 : : NULL, "invalid driver type");
10866 : 0 : fops = flow_get_drv_ops(drv_type);
10867 [ # # # # ]: 0 : if (!fops || !fops->flow_calc_encap_hash)
10868 : 0 : return rte_flow_error_set(error, ENOTSUP,
10869 : : RTE_FLOW_ERROR_TYPE_ACTION,
10870 : : NULL, "no calc encap hash handler");
10871 : 0 : return fops->flow_calc_encap_hash(dev, pattern, dest_field, hash, error);
10872 : : }
10873 : :
10874 : : static int
10875 [ # # ]: 0 : mlx5_template_table_resize(struct rte_eth_dev *dev,
10876 : : struct rte_flow_template_table *table,
10877 : : uint32_t nb_rules, struct rte_flow_error *error)
10878 : : {
10879 : : const struct mlx5_flow_driver_ops *fops;
10880 : :
10881 [ # # # # ]: 0 : MLX5_DRV_FOPS_OR_ERR(dev, fops, table_resize, ENOTSUP);
10882 : 0 : return fops->table_resize(dev, table, nb_rules, error);
10883 : : }
10884 : :
10885 : : static int
10886 [ # # ]: 0 : mlx5_table_resize_complete(struct rte_eth_dev *dev,
10887 : : struct rte_flow_template_table *table,
10888 : : struct rte_flow_error *error)
10889 : : {
10890 : : const struct mlx5_flow_driver_ops *fops;
10891 : :
10892 [ # # # # ]: 0 : MLX5_DRV_FOPS_OR_ERR(dev, fops, table_resize_complete, ENOTSUP);
10893 : 0 : return fops->table_resize_complete(dev, table, error);
10894 : : }
10895 : :
10896 : : static int
10897 [ # # ]: 0 : mlx5_flow_async_update_resized(struct rte_eth_dev *dev, uint32_t queue,
10898 : : const struct rte_flow_op_attr *op_attr,
10899 : : struct rte_flow *rule, void *user_data,
10900 : : struct rte_flow_error *error)
10901 : : {
10902 : : const struct mlx5_flow_driver_ops *fops;
10903 : :
10904 [ # # # # ]: 0 : MLX5_DRV_FOPS_OR_ERR(dev, fops, flow_update_resized, ENOTSUP);
10905 : 0 : return fops->flow_update_resized(dev, queue, op_attr, rule, user_data, error);
10906 : : }
10907 : :
10908 : : /**
10909 : : * Destroy all indirect actions (shared RSS).
10910 : : *
10911 : : * @param dev
10912 : : * Pointer to Ethernet device.
10913 : : *
10914 : : * @return
10915 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
10916 : : */
10917 : : int
10918 : 0 : mlx5_action_handle_flush(struct rte_eth_dev *dev)
10919 : : {
10920 : : struct rte_flow_error error;
10921 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10922 : : struct mlx5_shared_action_rss *shared_rss;
10923 : : int ret = 0;
10924 : : uint32_t idx;
10925 : :
10926 [ # # # # ]: 0 : ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
10927 : : priv->rss_shared_actions, idx, shared_rss, next) {
10928 [ # # ]: 0 : ret |= mlx5_action_handle_destroy(dev,
10929 : 0 : (struct rte_flow_action_handle *)(uintptr_t)idx, &error);
10930 : : }
10931 : 0 : return ret;
10932 : : }
10933 : :
10934 : : /**
10935 : : * Validate existing indirect actions against current device configuration
10936 : : * and attach them to device resources.
10937 : : *
10938 : : * @param dev
10939 : : * Pointer to Ethernet device.
10940 : : *
10941 : : * @return
10942 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
10943 : : */
10944 : : int
10945 : 0 : mlx5_action_handle_attach(struct rte_eth_dev *dev)
10946 : : {
10947 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10948 : : int ret = 0;
10949 : : struct mlx5_ind_table_obj *ind_tbl, *ind_tbl_last;
10950 : :
10951 [ # # ]: 0 : LIST_FOREACH(ind_tbl, &priv->standalone_ind_tbls, next) {
10952 : : const char *message;
10953 : : uint32_t queue_idx;
10954 : :
10955 : 0 : ret = mlx5_validate_rss_queues(dev, ind_tbl->queues,
10956 : : ind_tbl->queues_n,
10957 : : &message, &queue_idx);
10958 [ # # ]: 0 : if (ret != 0) {
10959 : 0 : DRV_LOG(ERR, "Port %u cannot use queue %u in RSS: %s",
10960 : : dev->data->port_id, ind_tbl->queues[queue_idx],
10961 : : message);
10962 : 0 : break;
10963 : : }
10964 : : }
10965 [ # # ]: 0 : if (ret != 0)
10966 : : return ret;
10967 [ # # ]: 0 : LIST_FOREACH(ind_tbl, &priv->standalone_ind_tbls, next) {
10968 : 0 : ret = mlx5_ind_table_obj_attach(dev, ind_tbl);
10969 [ # # ]: 0 : if (ret != 0) {
10970 : 0 : DRV_LOG(ERR, "Port %u could not attach "
10971 : : "indirection table obj %p",
10972 : : dev->data->port_id, (void *)ind_tbl);
10973 : 0 : goto error;
10974 : : }
10975 : : }
10976 : :
10977 : : return 0;
10978 : : error:
10979 : : ind_tbl_last = ind_tbl;
10980 [ # # ]: 0 : LIST_FOREACH(ind_tbl, &priv->standalone_ind_tbls, next) {
10981 [ # # ]: 0 : if (ind_tbl == ind_tbl_last)
10982 : : break;
10983 [ # # ]: 0 : if (mlx5_ind_table_obj_detach(dev, ind_tbl) != 0)
10984 : 0 : DRV_LOG(CRIT, "Port %u could not detach "
10985 : : "indirection table obj %p on rollback",
10986 : : dev->data->port_id, (void *)ind_tbl);
10987 : : }
10988 : : return ret;
10989 : : }
10990 : :
10991 : : /**
10992 : : * Detach indirect actions of the device from its resources.
10993 : : *
10994 : : * @param dev
10995 : : * Pointer to Ethernet device.
10996 : : *
10997 : : * @return
10998 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
10999 : : */
11000 : : int
11001 : 0 : mlx5_action_handle_detach(struct rte_eth_dev *dev)
11002 : : {
11003 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11004 : : int ret = 0;
11005 : : struct mlx5_ind_table_obj *ind_tbl, *ind_tbl_last;
11006 : :
11007 [ # # ]: 0 : LIST_FOREACH(ind_tbl, &priv->standalone_ind_tbls, next) {
11008 : 0 : ret = mlx5_ind_table_obj_detach(dev, ind_tbl);
11009 [ # # ]: 0 : if (ret != 0) {
11010 : 0 : DRV_LOG(ERR, "Port %u could not detach "
11011 : : "indirection table obj %p",
11012 : : dev->data->port_id, (void *)ind_tbl);
11013 : 0 : goto error;
11014 : : }
11015 : : }
11016 : : return 0;
11017 : : error:
11018 : : ind_tbl_last = ind_tbl;
11019 [ # # ]: 0 : LIST_FOREACH(ind_tbl, &priv->standalone_ind_tbls, next) {
11020 [ # # ]: 0 : if (ind_tbl == ind_tbl_last)
11021 : : break;
11022 [ # # ]: 0 : if (mlx5_ind_table_obj_attach(dev, ind_tbl) != 0)
11023 : 0 : DRV_LOG(CRIT, "Port %u could not attach "
11024 : : "indirection table obj %p on rollback",
11025 : : dev->data->port_id, (void *)ind_tbl);
11026 : : }
11027 : : return ret;
11028 : : }
11029 : :
11030 : : #ifndef HAVE_MLX5DV_DR
11031 : : #define MLX5_DOMAIN_SYNC_FLOW ((1 << 0) | (1 << 1))
11032 : : #else
11033 : : #define MLX5_DOMAIN_SYNC_FLOW \
11034 : : (MLX5DV_DR_DOMAIN_SYNC_FLAGS_SW | MLX5DV_DR_DOMAIN_SYNC_FLAGS_HW)
11035 : : #endif
11036 : :
11037 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_mlx5_sync_flow, 20.11)
11038 : 0 : int rte_pmd_mlx5_sync_flow(uint16_t port_id, uint32_t domains)
11039 : : {
11040 [ # # ]: 0 : struct rte_eth_dev *dev = &rte_eth_devices[port_id];
11041 : : const struct mlx5_flow_driver_ops *fops;
11042 : : int ret;
11043 : : struct rte_flow_attr attr = { .transfer = 0 };
11044 : :
11045 : 0 : fops = flow_get_drv_ops(flow_get_drv_type(dev, &attr));
11046 : 0 : ret = fops->sync_domain(dev, domains, MLX5_DOMAIN_SYNC_FLOW);
11047 [ # # ]: 0 : if (ret > 0)
11048 : 0 : ret = -ret;
11049 : 0 : return ret;
11050 : : }
11051 : :
11052 : : const struct mlx5_flow_tunnel *
11053 : 0 : mlx5_get_tof(const struct rte_flow_item *item,
11054 : : const struct rte_flow_action *action,
11055 : : enum mlx5_tof_rule_type *rule_type)
11056 : : {
11057 [ # # ]: 0 : for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
11058 [ # # ]: 0 : if (item->type == (typeof(item->type))
11059 : : MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL) {
11060 : 0 : *rule_type = MLX5_TUNNEL_OFFLOAD_MATCH_RULE;
11061 : 0 : return flow_items_to_tunnel(item);
11062 : : }
11063 : : }
11064 [ # # ]: 0 : for (; action->conf != RTE_FLOW_ACTION_TYPE_END; action++) {
11065 [ # # ]: 0 : if (action->type == (typeof(action->type))
11066 : : MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET) {
11067 : 0 : *rule_type = MLX5_TUNNEL_OFFLOAD_SET_RULE;
11068 : 0 : return flow_actions_to_tunnel(action);
11069 : : }
11070 : : }
11071 : : return NULL;
11072 : : }
11073 : :
11074 : : /**
11075 : : * tunnel offload functionality is defined for DV environment only
11076 : : */
11077 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
11078 : : __extension__
11079 : : union tunnel_offload_mark {
11080 : : uint32_t val;
11081 : : struct {
11082 : : uint32_t app_reserve:8;
11083 : : uint32_t table_id:15;
11084 : : uint32_t transfer:1;
11085 : : uint32_t _unused_:8;
11086 : : };
11087 : : };
11088 : :
11089 : : static bool
11090 : : mlx5_access_tunnel_offload_db
11091 : : (struct rte_eth_dev *dev,
11092 : : bool (*match)(struct rte_eth_dev *,
11093 : : struct mlx5_flow_tunnel *, const void *),
11094 : : void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
11095 : : void (*miss)(struct rte_eth_dev *, void *),
11096 : : void *ctx, bool lock_op);
11097 : :
11098 : : static int
11099 : 0 : flow_tunnel_add_default_miss(struct rte_eth_dev *dev,
11100 : : struct rte_flow *flow,
11101 : : const struct rte_flow_attr *attr,
11102 : : const struct rte_flow_action *app_actions,
11103 : : uint32_t flow_idx,
11104 : : const struct mlx5_flow_tunnel *tunnel,
11105 : : struct tunnel_default_miss_ctx *ctx,
11106 : : struct rte_flow_error *error)
11107 : : {
11108 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11109 : : struct mlx5_flow *dev_flow;
11110 : 0 : struct rte_flow_attr miss_attr = *attr;
11111 : 0 : const struct rte_flow_item miss_items[2] = {
11112 : : {
11113 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
11114 : : .spec = NULL,
11115 : : .last = NULL,
11116 : : .mask = NULL
11117 : : },
11118 : : {
11119 : : .type = RTE_FLOW_ITEM_TYPE_END,
11120 : : .spec = NULL,
11121 : : .last = NULL,
11122 : : .mask = NULL
11123 : : }
11124 : : };
11125 : : union tunnel_offload_mark mark_id;
11126 : : struct rte_flow_action_mark miss_mark;
11127 : 0 : struct rte_flow_action miss_actions[3] = {
11128 : : [0] = { .type = RTE_FLOW_ACTION_TYPE_MARK, .conf = &miss_mark },
11129 : : [2] = { .type = RTE_FLOW_ACTION_TYPE_END, .conf = NULL }
11130 : : };
11131 : : const struct rte_flow_action_jump *jump_data;
11132 : 0 : uint32_t i, flow_table = 0; /* prevent compilation warning */
11133 : 0 : struct flow_grp_info grp_info = {
11134 : : .external = 1,
11135 : 0 : .transfer = attr->transfer,
11136 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
11137 : : .std_tbl_fix = 0,
11138 : : };
11139 : : int ret;
11140 : :
11141 [ # # ]: 0 : if (!attr->transfer) {
11142 : : uint32_t q_size;
11143 : :
11144 : 0 : miss_actions[1].type = RTE_FLOW_ACTION_TYPE_RSS;
11145 : 0 : q_size = priv->reta_idx_n * sizeof(ctx->queue[0]);
11146 : 0 : ctx->queue = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, q_size,
11147 : : 0, SOCKET_ID_ANY);
11148 [ # # ]: 0 : if (!ctx->queue)
11149 : 0 : return rte_flow_error_set
11150 : : (error, ENOMEM,
11151 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
11152 : : NULL, "invalid default miss RSS");
11153 : 0 : ctx->action_rss.func = RTE_ETH_HASH_FUNCTION_DEFAULT;
11154 : 0 : ctx->action_rss.level = 0;
11155 : 0 : ctx->action_rss.types = priv->rss_conf.rss_hf;
11156 : 0 : ctx->action_rss.key_len = priv->rss_conf.rss_key_len;
11157 : 0 : ctx->action_rss.queue_num = priv->reta_idx_n;
11158 : 0 : ctx->action_rss.key = priv->rss_conf.rss_key;
11159 : 0 : ctx->action_rss.queue = ctx->queue;
11160 [ # # # # ]: 0 : if (!priv->reta_idx_n || !priv->rxqs_n)
11161 : 0 : return rte_flow_error_set
11162 : : (error, EINVAL,
11163 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
11164 : : NULL, "invalid port configuration");
11165 [ # # ]: 0 : if (!(dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG))
11166 : 0 : ctx->action_rss.types = 0;
11167 [ # # ]: 0 : for (i = 0; i != priv->reta_idx_n; ++i)
11168 : 0 : ctx->queue[i] = (*priv->reta_idx)[i];
11169 : : } else {
11170 : 0 : miss_actions[1].type = RTE_FLOW_ACTION_TYPE_JUMP;
11171 : 0 : ctx->miss_jump.group = MLX5_TNL_MISS_FDB_JUMP_GRP;
11172 : : }
11173 : 0 : miss_actions[1].conf = (typeof(miss_actions[1].conf))ctx->raw;
11174 [ # # ]: 0 : for (; app_actions->type != RTE_FLOW_ACTION_TYPE_JUMP; app_actions++);
11175 : 0 : jump_data = app_actions->conf;
11176 : 0 : miss_attr.priority = MLX5_TNL_MISS_RULE_PRIORITY;
11177 : 0 : miss_attr.group = jump_data->group;
11178 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel, jump_data->group,
11179 : : &flow_table, &grp_info, error);
11180 [ # # ]: 0 : if (ret)
11181 : 0 : return rte_flow_error_set(error, EINVAL,
11182 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
11183 : : NULL, "invalid tunnel id");
11184 : 0 : mark_id.app_reserve = 0;
11185 : 0 : mark_id.table_id = tunnel_flow_tbl_to_id(flow_table);
11186 : 0 : mark_id.transfer = !!attr->transfer;
11187 : 0 : mark_id._unused_ = 0;
11188 : 0 : miss_mark.id = mark_id.val;
11189 : : dev_flow = flow_drv_prepare(dev, flow, &miss_attr,
11190 : : miss_items, miss_actions, flow_idx, error);
11191 [ # # ]: 0 : if (!dev_flow)
11192 : 0 : return -rte_errno;
11193 : 0 : dev_flow->flow = flow;
11194 : 0 : dev_flow->external = true;
11195 : 0 : dev_flow->tunnel = tunnel;
11196 : 0 : dev_flow->tof_type = MLX5_TUNNEL_OFFLOAD_MISS_RULE;
11197 : : /* Subflow object was created, we must include one in the list. */
11198 : 0 : SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
11199 : : dev_flow->handle, next);
11200 : 0 : DRV_LOG(DEBUG,
11201 : : "port %u tunnel type=%d id=%u miss rule priority=%u group=%u",
11202 : : dev->data->port_id, tunnel->app_tunnel.type,
11203 : : tunnel->tunnel_id, miss_attr.priority, miss_attr.group);
11204 : : ret = flow_drv_translate(dev, dev_flow, &miss_attr, miss_items,
11205 : : miss_actions, error);
11206 [ # # ]: 0 : if (!ret)
11207 : 0 : ret = flow_mreg_update_copy_table(dev, flow, miss_actions,
11208 : : error);
11209 : :
11210 : : return ret;
11211 : : }
11212 : :
11213 : : static const struct mlx5_flow_tbl_data_entry *
11214 : 0 : tunnel_mark_decode(struct rte_eth_dev *dev, uint32_t mark)
11215 : : {
11216 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11217 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
11218 : : struct mlx5_list_entry *he;
11219 : 0 : union tunnel_offload_mark mbits = { .val = mark };
11220 : 0 : union mlx5_flow_tbl_key table_key = {
11221 : : {
11222 : 0 : .level = tunnel_id_to_flow_tbl(mbits.table_id),
11223 : : .id = 0,
11224 : : .reserved = 0,
11225 : : .dummy = 0,
11226 : 0 : .is_fdb = !!mbits.transfer,
11227 : : .is_egress = 0,
11228 : : }
11229 : : };
11230 : 0 : struct mlx5_flow_cb_ctx ctx = {
11231 : : .data = &table_key.v64,
11232 : : };
11233 : :
11234 : 0 : he = mlx5_hlist_lookup(sh->flow_tbls, table_key.v64, &ctx);
11235 : : return he ?
11236 [ # # ]: 0 : container_of(he, struct mlx5_flow_tbl_data_entry, entry) : NULL;
11237 : : }
11238 : :
11239 : : static void
11240 : 0 : mlx5_flow_tunnel_grp2tbl_remove_cb(void *tool_ctx,
11241 : : struct mlx5_list_entry *entry)
11242 : : {
11243 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11244 : : struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
11245 : :
11246 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
11247 : : tunnel_flow_tbl_to_id(tte->flow_table));
11248 : 0 : mlx5_free(tte);
11249 : 0 : }
11250 : :
11251 : : static int
11252 : 0 : mlx5_flow_tunnel_grp2tbl_match_cb(void *tool_ctx __rte_unused,
11253 : : struct mlx5_list_entry *entry, void *cb_ctx)
11254 : : {
11255 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11256 : : union tunnel_tbl_key tbl = {
11257 : 0 : .val = *(uint64_t *)(ctx->data),
11258 : : };
11259 : : struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
11260 : :
11261 [ # # # # ]: 0 : return tbl.tunnel_id != tte->tunnel_id || tbl.group != tte->group;
11262 : : }
11263 : :
11264 : : static struct mlx5_list_entry *
11265 : 0 : mlx5_flow_tunnel_grp2tbl_create_cb(void *tool_ctx, void *cb_ctx)
11266 : : {
11267 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11268 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11269 : : struct tunnel_tbl_entry *tte;
11270 : : union tunnel_tbl_key tbl = {
11271 : 0 : .val = *(uint64_t *)(ctx->data),
11272 : : };
11273 : :
11274 : 0 : tte = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO,
11275 : : sizeof(*tte), 0,
11276 : : SOCKET_ID_ANY);
11277 [ # # ]: 0 : if (!tte)
11278 : 0 : goto err;
11279 : 0 : mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
11280 : : &tte->flow_table);
11281 [ # # ]: 0 : if (tte->flow_table >= MLX5_MAX_TABLES) {
11282 : 0 : DRV_LOG(ERR, "Tunnel TBL ID %d exceed max limit.",
11283 : : tte->flow_table);
11284 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
11285 : : tte->flow_table);
11286 : 0 : goto err;
11287 [ # # ]: 0 : } else if (!tte->flow_table) {
11288 : 0 : goto err;
11289 : : }
11290 : 0 : tte->flow_table = tunnel_id_to_flow_tbl(tte->flow_table);
11291 : 0 : tte->tunnel_id = tbl.tunnel_id;
11292 : 0 : tte->group = tbl.group;
11293 : 0 : return &tte->hash;
11294 : 0 : err:
11295 [ # # ]: 0 : if (tte)
11296 : 0 : mlx5_free(tte);
11297 : : return NULL;
11298 : : }
11299 : :
11300 : : static struct mlx5_list_entry *
11301 : 0 : mlx5_flow_tunnel_grp2tbl_clone_cb(void *tool_ctx __rte_unused,
11302 : : struct mlx5_list_entry *oentry,
11303 : : void *cb_ctx __rte_unused)
11304 : : {
11305 : 0 : struct tunnel_tbl_entry *tte = mlx5_malloc(MLX5_MEM_SYS, sizeof(*tte),
11306 : : 0, SOCKET_ID_ANY);
11307 : :
11308 [ # # ]: 0 : if (!tte)
11309 : : return NULL;
11310 : : memcpy(tte, oentry, sizeof(*tte));
11311 : 0 : return &tte->hash;
11312 : : }
11313 : :
11314 : : static void
11315 : 0 : mlx5_flow_tunnel_grp2tbl_clone_free_cb(void *tool_ctx __rte_unused,
11316 : : struct mlx5_list_entry *entry)
11317 : : {
11318 : : struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
11319 : :
11320 : 0 : mlx5_free(tte);
11321 : 0 : }
11322 : :
11323 : : static uint32_t
11324 : 0 : tunnel_flow_group_to_flow_table(struct rte_eth_dev *dev,
11325 : : const struct mlx5_flow_tunnel *tunnel,
11326 : : uint32_t group, uint32_t *table,
11327 : : struct rte_flow_error *error)
11328 : : {
11329 : : struct mlx5_list_entry *he;
11330 : : struct tunnel_tbl_entry *tte;
11331 [ # # ]: 0 : union tunnel_tbl_key key = {
11332 [ # # ]: 0 : .tunnel_id = tunnel ? tunnel->tunnel_id : 0,
11333 : : .group = group
11334 : : };
11335 : : struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
11336 : : struct mlx5_hlist *group_hash;
11337 : 0 : struct mlx5_flow_cb_ctx ctx = {
11338 : : .data = &key.val,
11339 : : };
11340 : :
11341 [ # # ]: 0 : group_hash = tunnel ? tunnel->groups : thub->groups;
11342 : 0 : he = mlx5_hlist_register(group_hash, key.val, &ctx);
11343 [ # # ]: 0 : if (!he)
11344 : 0 : return rte_flow_error_set(error, EINVAL,
11345 : : RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
11346 : : NULL,
11347 : : "tunnel group index not supported");
11348 : : tte = container_of(he, typeof(*tte), hash);
11349 : 0 : *table = tte->flow_table;
11350 : 0 : DRV_LOG(DEBUG, "port %u tunnel %u group=%#x table=%#x",
11351 : : dev->data->port_id, key.tunnel_id, group, *table);
11352 : 0 : return 0;
11353 : : }
11354 : :
11355 : : static void
11356 : 0 : mlx5_flow_tunnel_free(struct rte_eth_dev *dev,
11357 : : struct mlx5_flow_tunnel *tunnel)
11358 : : {
11359 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11360 : : struct mlx5_indexed_pool *ipool;
11361 : :
11362 : 0 : DRV_LOG(DEBUG, "port %u release pmd tunnel id=0x%x",
11363 : : dev->data->port_id, tunnel->tunnel_id);
11364 [ # # ]: 0 : LIST_REMOVE(tunnel, chain);
11365 : 0 : mlx5_hlist_destroy(tunnel->groups);
11366 : 0 : ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
11367 : 0 : mlx5_ipool_free(ipool, tunnel->tunnel_id);
11368 : 0 : }
11369 : :
11370 : : static bool
11371 : 0 : mlx5_access_tunnel_offload_db
11372 : : (struct rte_eth_dev *dev,
11373 : : bool (*match)(struct rte_eth_dev *,
11374 : : struct mlx5_flow_tunnel *, const void *),
11375 : : void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
11376 : : void (*miss)(struct rte_eth_dev *, void *),
11377 : : void *ctx, bool lock_op)
11378 : : {
11379 : : bool verdict = false;
11380 : : struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
11381 : : struct mlx5_flow_tunnel *tunnel;
11382 : :
11383 : 0 : rte_spinlock_lock(&thub->sl);
11384 [ # # ]: 0 : LIST_FOREACH(tunnel, &thub->tunnels, chain) {
11385 : 0 : verdict = match(dev, tunnel, (const void *)ctx);
11386 [ # # ]: 0 : if (verdict)
11387 : : break;
11388 : : }
11389 [ # # ]: 0 : if (!lock_op)
11390 : : rte_spinlock_unlock(&thub->sl);
11391 [ # # ]: 0 : if (verdict && hit)
11392 : 0 : hit(dev, tunnel, ctx);
11393 [ # # ]: 0 : if (!verdict && miss)
11394 : 0 : miss(dev, ctx);
11395 [ # # ]: 0 : if (lock_op)
11396 : : rte_spinlock_unlock(&thub->sl);
11397 : :
11398 : 0 : return verdict;
11399 : : }
11400 : :
11401 : : struct tunnel_db_find_tunnel_id_ctx {
11402 : : uint32_t tunnel_id;
11403 : : struct mlx5_flow_tunnel *tunnel;
11404 : : };
11405 : :
11406 : : static bool
11407 : 0 : find_tunnel_id_match(struct rte_eth_dev *dev,
11408 : : struct mlx5_flow_tunnel *tunnel, const void *x)
11409 : : {
11410 : : const struct tunnel_db_find_tunnel_id_ctx *ctx = x;
11411 : :
11412 : : RTE_SET_USED(dev);
11413 : 0 : return tunnel->tunnel_id == ctx->tunnel_id;
11414 : : }
11415 : :
11416 : : static void
11417 : 0 : find_tunnel_id_hit(struct rte_eth_dev *dev,
11418 : : struct mlx5_flow_tunnel *tunnel, void *x)
11419 : : {
11420 : : struct tunnel_db_find_tunnel_id_ctx *ctx = x;
11421 : : RTE_SET_USED(dev);
11422 : 0 : ctx->tunnel = tunnel;
11423 : 0 : }
11424 : :
11425 : : static struct mlx5_flow_tunnel *
11426 : : mlx5_find_tunnel_id(struct rte_eth_dev *dev, uint32_t id)
11427 : : {
11428 : 0 : struct tunnel_db_find_tunnel_id_ctx ctx = {
11429 : : .tunnel_id = id,
11430 : : };
11431 : :
11432 : 0 : mlx5_access_tunnel_offload_db(dev, find_tunnel_id_match,
11433 : : find_tunnel_id_hit, NULL, &ctx, true);
11434 : :
11435 [ # # ]: 0 : return ctx.tunnel;
11436 : : }
11437 : :
11438 : : static struct mlx5_flow_tunnel *
11439 : 0 : mlx5_flow_tunnel_allocate(struct rte_eth_dev *dev,
11440 : : const struct rte_flow_tunnel *app_tunnel)
11441 : : {
11442 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11443 : : struct mlx5_indexed_pool *ipool;
11444 : : struct mlx5_flow_tunnel *tunnel;
11445 : : uint32_t id;
11446 : :
11447 : 0 : ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
11448 : 0 : tunnel = mlx5_ipool_zmalloc(ipool, &id);
11449 [ # # ]: 0 : if (!tunnel)
11450 : : return NULL;
11451 [ # # ]: 0 : if (id >= MLX5_MAX_TUNNELS) {
11452 : 0 : mlx5_ipool_free(ipool, id);
11453 : 0 : DRV_LOG(ERR, "Tunnel ID %d exceed max limit.", id);
11454 : 0 : return NULL;
11455 : : }
11456 : 0 : tunnel->groups = mlx5_hlist_create("tunnel groups", 64, false, true,
11457 : 0 : priv->sh,
11458 : : mlx5_flow_tunnel_grp2tbl_create_cb,
11459 : : mlx5_flow_tunnel_grp2tbl_match_cb,
11460 : : mlx5_flow_tunnel_grp2tbl_remove_cb,
11461 : : mlx5_flow_tunnel_grp2tbl_clone_cb,
11462 : : mlx5_flow_tunnel_grp2tbl_clone_free_cb);
11463 [ # # ]: 0 : if (!tunnel->groups) {
11464 : 0 : mlx5_ipool_free(ipool, id);
11465 : 0 : return NULL;
11466 : : }
11467 : : /* initiate new PMD tunnel */
11468 : 0 : memcpy(&tunnel->app_tunnel, app_tunnel, sizeof(*app_tunnel));
11469 : 0 : tunnel->tunnel_id = id;
11470 : 0 : tunnel->action.type = (typeof(tunnel->action.type))
11471 : : MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET;
11472 : 0 : tunnel->action.conf = tunnel;
11473 : 0 : tunnel->item.type = (typeof(tunnel->item.type))
11474 : : MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL;
11475 : 0 : tunnel->item.spec = tunnel;
11476 : 0 : tunnel->item.last = NULL;
11477 : 0 : tunnel->item.mask = NULL;
11478 : :
11479 : 0 : DRV_LOG(DEBUG, "port %u new pmd tunnel id=0x%x",
11480 : : dev->data->port_id, tunnel->tunnel_id);
11481 : :
11482 : 0 : return tunnel;
11483 : : }
11484 : :
11485 : : struct tunnel_db_get_tunnel_ctx {
11486 : : const struct rte_flow_tunnel *app_tunnel;
11487 : : struct mlx5_flow_tunnel *tunnel;
11488 : : };
11489 : :
11490 : 0 : static bool get_tunnel_match(struct rte_eth_dev *dev,
11491 : : struct mlx5_flow_tunnel *tunnel, const void *x)
11492 : : {
11493 : : const struct tunnel_db_get_tunnel_ctx *ctx = x;
11494 : :
11495 : : RTE_SET_USED(dev);
11496 : 0 : return !memcmp(ctx->app_tunnel, &tunnel->app_tunnel,
11497 : : sizeof(*ctx->app_tunnel));
11498 : : }
11499 : :
11500 : 0 : static void get_tunnel_hit(struct rte_eth_dev *dev,
11501 : : struct mlx5_flow_tunnel *tunnel, void *x)
11502 : : {
11503 : : /* called under tunnel spinlock protection */
11504 : : struct tunnel_db_get_tunnel_ctx *ctx = x;
11505 : :
11506 : : RTE_SET_USED(dev);
11507 : 0 : tunnel->refctn++;
11508 : 0 : ctx->tunnel = tunnel;
11509 : 0 : }
11510 : :
11511 : 0 : static void get_tunnel_miss(struct rte_eth_dev *dev, void *x)
11512 : : {
11513 : : /* called under tunnel spinlock protection */
11514 : : struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
11515 : : struct tunnel_db_get_tunnel_ctx *ctx = x;
11516 : :
11517 : 0 : rte_spinlock_unlock(&thub->sl);
11518 : 0 : ctx->tunnel = mlx5_flow_tunnel_allocate(dev, ctx->app_tunnel);
11519 : : rte_spinlock_lock(&thub->sl);
11520 [ # # ]: 0 : if (ctx->tunnel) {
11521 : 0 : ctx->tunnel->refctn = 1;
11522 [ # # ]: 0 : LIST_INSERT_HEAD(&thub->tunnels, ctx->tunnel, chain);
11523 : : }
11524 : 0 : }
11525 : :
11526 : :
11527 : : static int
11528 : 0 : mlx5_get_flow_tunnel(struct rte_eth_dev *dev,
11529 : : const struct rte_flow_tunnel *app_tunnel,
11530 : : struct mlx5_flow_tunnel **tunnel)
11531 : : {
11532 : 0 : struct tunnel_db_get_tunnel_ctx ctx = {
11533 : : .app_tunnel = app_tunnel,
11534 : : };
11535 : :
11536 : 0 : mlx5_access_tunnel_offload_db(dev, get_tunnel_match, get_tunnel_hit,
11537 : : get_tunnel_miss, &ctx, true);
11538 : 0 : *tunnel = ctx.tunnel;
11539 [ # # ]: 0 : return ctx.tunnel ? 0 : -ENOMEM;
11540 : : }
11541 : :
11542 : 0 : void mlx5_release_tunnel_hub(struct mlx5_dev_ctx_shared *sh, uint16_t port_id)
11543 : : {
11544 : 0 : struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
11545 : :
11546 [ # # ]: 0 : if (!thub)
11547 : : return;
11548 [ # # ]: 0 : if (!LIST_EMPTY(&thub->tunnels))
11549 : 0 : DRV_LOG(WARNING, "port %u tunnels present", port_id);
11550 : 0 : mlx5_hlist_destroy(thub->groups);
11551 : 0 : mlx5_free(thub);
11552 : : }
11553 : :
11554 : 0 : int mlx5_alloc_tunnel_hub(struct mlx5_dev_ctx_shared *sh)
11555 : : {
11556 : : int err;
11557 : : struct mlx5_flow_tunnel_hub *thub;
11558 : :
11559 : 0 : thub = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, sizeof(*thub),
11560 : : 0, SOCKET_ID_ANY);
11561 [ # # ]: 0 : if (!thub)
11562 : : return -ENOMEM;
11563 : 0 : LIST_INIT(&thub->tunnels);
11564 : : rte_spinlock_init(&thub->sl);
11565 : 0 : thub->groups = mlx5_hlist_create("flow groups", 64,
11566 : : false, true, sh,
11567 : : mlx5_flow_tunnel_grp2tbl_create_cb,
11568 : : mlx5_flow_tunnel_grp2tbl_match_cb,
11569 : : mlx5_flow_tunnel_grp2tbl_remove_cb,
11570 : : mlx5_flow_tunnel_grp2tbl_clone_cb,
11571 : : mlx5_flow_tunnel_grp2tbl_clone_free_cb);
11572 [ # # ]: 0 : if (!thub->groups) {
11573 : 0 : err = -rte_errno;
11574 : 0 : goto err;
11575 : : }
11576 : 0 : sh->tunnel_hub = thub;
11577 : :
11578 : 0 : return 0;
11579 : :
11580 : : err:
11581 : : if (thub->groups)
11582 : : mlx5_hlist_destroy(thub->groups);
11583 : : if (thub)
11584 : 0 : mlx5_free(thub);
11585 : 0 : return err;
11586 : : }
11587 : :
11588 : : static inline int
11589 : 0 : mlx5_flow_tunnel_validate(struct rte_eth_dev *dev,
11590 : : struct rte_flow_tunnel *tunnel,
11591 : : struct rte_flow_error *error)
11592 : : {
11593 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11594 : :
11595 [ # # ]: 0 : if (!priv->sh->config.dv_flow_en)
11596 : 0 : return rte_flow_error_set(error, ENOTSUP,
11597 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
11598 : : "flow DV interface is off");
11599 [ # # ]: 0 : if (!is_tunnel_offload_active(dev))
11600 : 0 : return rte_flow_error_set(error, ENOTSUP,
11601 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
11602 : : "tunnel offload was not activated, consider setting dv_xmeta_en=3");
11603 [ # # ]: 0 : if (!tunnel)
11604 : 0 : return rte_flow_error_set(error, EINVAL,
11605 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
11606 : : "no application tunnel");
11607 [ # # ]: 0 : switch (tunnel->type) {
11608 : 0 : default:
11609 : 0 : return rte_flow_error_set(error, EINVAL,
11610 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
11611 : : "unsupported tunnel type");
11612 : : case RTE_FLOW_ITEM_TYPE_VXLAN:
11613 : : case RTE_FLOW_ITEM_TYPE_GRE:
11614 : : case RTE_FLOW_ITEM_TYPE_NVGRE:
11615 : : case RTE_FLOW_ITEM_TYPE_GENEVE:
11616 : : break;
11617 : : }
11618 : : return 0;
11619 : : }
11620 : :
11621 : : static int
11622 : 0 : mlx5_flow_tunnel_decap_set(struct rte_eth_dev *dev,
11623 : : struct rte_flow_tunnel *app_tunnel,
11624 : : struct rte_flow_action **actions,
11625 : : uint32_t *num_of_actions,
11626 : : struct rte_flow_error *error)
11627 : : {
11628 : : struct mlx5_flow_tunnel *tunnel;
11629 : 0 : int ret = mlx5_flow_tunnel_validate(dev, app_tunnel, error);
11630 : :
11631 [ # # ]: 0 : if (ret)
11632 : : return ret;
11633 : 0 : ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
11634 [ # # ]: 0 : if (ret < 0) {
11635 : 0 : return rte_flow_error_set(error, ret,
11636 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
11637 : : "failed to initialize pmd tunnel");
11638 : : }
11639 : 0 : *actions = &tunnel->action;
11640 : 0 : *num_of_actions = 1;
11641 : 0 : return 0;
11642 : : }
11643 : :
11644 : : static int
11645 : 0 : mlx5_flow_tunnel_match(struct rte_eth_dev *dev,
11646 : : struct rte_flow_tunnel *app_tunnel,
11647 : : struct rte_flow_item **items,
11648 : : uint32_t *num_of_items,
11649 : : struct rte_flow_error *error)
11650 : : {
11651 : : struct mlx5_flow_tunnel *tunnel;
11652 : 0 : int ret = mlx5_flow_tunnel_validate(dev, app_tunnel, error);
11653 : :
11654 [ # # ]: 0 : if (ret)
11655 : : return ret;
11656 : 0 : ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
11657 [ # # ]: 0 : if (ret < 0) {
11658 : 0 : return rte_flow_error_set(error, ret,
11659 : : RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
11660 : : "failed to initialize pmd tunnel");
11661 : : }
11662 : 0 : *items = &tunnel->item;
11663 : 0 : *num_of_items = 1;
11664 : 0 : return 0;
11665 : : }
11666 : :
11667 : : struct tunnel_db_element_release_ctx {
11668 : : struct rte_flow_item *items;
11669 : : struct rte_flow_action *actions;
11670 : : uint32_t num_elements;
11671 : : struct rte_flow_error *error;
11672 : : int ret;
11673 : : };
11674 : :
11675 : : static bool
11676 : 0 : tunnel_element_release_match(struct rte_eth_dev *dev,
11677 : : struct mlx5_flow_tunnel *tunnel, const void *x)
11678 : : {
11679 : : const struct tunnel_db_element_release_ctx *ctx = x;
11680 : :
11681 : : RTE_SET_USED(dev);
11682 [ # # ]: 0 : if (ctx->num_elements != 1)
11683 : : return false;
11684 [ # # ]: 0 : else if (ctx->items)
11685 : 0 : return ctx->items == &tunnel->item;
11686 [ # # ]: 0 : else if (ctx->actions)
11687 : 0 : return ctx->actions == &tunnel->action;
11688 : :
11689 : : return false;
11690 : : }
11691 : :
11692 : : static void
11693 : 0 : tunnel_element_release_hit(struct rte_eth_dev *dev,
11694 : : struct mlx5_flow_tunnel *tunnel, void *x)
11695 : : {
11696 : : struct tunnel_db_element_release_ctx *ctx = x;
11697 : 0 : ctx->ret = 0;
11698 [ # # ]: 0 : if (!(rte_atomic_fetch_sub_explicit(&tunnel->refctn, 1, rte_memory_order_relaxed) - 1))
11699 : 0 : mlx5_flow_tunnel_free(dev, tunnel);
11700 : 0 : }
11701 : :
11702 : : static void
11703 : 0 : tunnel_element_release_miss(struct rte_eth_dev *dev, void *x)
11704 : : {
11705 : : struct tunnel_db_element_release_ctx *ctx = x;
11706 : : RTE_SET_USED(dev);
11707 : 0 : ctx->ret = rte_flow_error_set(ctx->error, EINVAL,
11708 : : RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
11709 : : "invalid argument");
11710 : 0 : }
11711 : :
11712 : : static int
11713 : 0 : mlx5_flow_tunnel_item_release(struct rte_eth_dev *dev,
11714 : : struct rte_flow_item *pmd_items,
11715 : : uint32_t num_items, struct rte_flow_error *err)
11716 : : {
11717 : 0 : struct tunnel_db_element_release_ctx ctx = {
11718 : : .items = pmd_items,
11719 : : .actions = NULL,
11720 : : .num_elements = num_items,
11721 : : .error = err,
11722 : : };
11723 : :
11724 : 0 : mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
11725 : : tunnel_element_release_hit,
11726 : : tunnel_element_release_miss, &ctx, false);
11727 : :
11728 : 0 : return ctx.ret;
11729 : : }
11730 : :
11731 : : static int
11732 : 0 : mlx5_flow_tunnel_action_release(struct rte_eth_dev *dev,
11733 : : struct rte_flow_action *pmd_actions,
11734 : : uint32_t num_actions, struct rte_flow_error *err)
11735 : : {
11736 : 0 : struct tunnel_db_element_release_ctx ctx = {
11737 : : .items = NULL,
11738 : : .actions = pmd_actions,
11739 : : .num_elements = num_actions,
11740 : : .error = err,
11741 : : };
11742 : :
11743 : 0 : mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
11744 : : tunnel_element_release_hit,
11745 : : tunnel_element_release_miss, &ctx, false);
11746 : :
11747 : 0 : return ctx.ret;
11748 : : }
11749 : :
11750 : : static int
11751 : 0 : mlx5_flow_tunnel_get_restore_info(struct rte_eth_dev *dev,
11752 : : struct rte_mbuf *m,
11753 : : struct rte_flow_restore_info *info,
11754 : : struct rte_flow_error *err)
11755 : : {
11756 : 0 : uint64_t ol_flags = m->ol_flags;
11757 : : const struct mlx5_flow_tbl_data_entry *tble;
11758 : : const uint64_t mask = RTE_MBUF_F_RX_FDIR | RTE_MBUF_F_RX_FDIR_ID;
11759 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11760 : :
11761 [ # # ]: 0 : if (priv->tunnel_enabled == 0)
11762 : 0 : goto err;
11763 [ # # ]: 0 : if ((ol_flags & mask) != mask)
11764 : 0 : goto err;
11765 : 0 : tble = tunnel_mark_decode(dev, m->hash.fdir.hi);
11766 [ # # ]: 0 : if (!tble) {
11767 : 0 : DRV_LOG(DEBUG, "port %u invalid miss tunnel mark %#x",
11768 : : dev->data->port_id, m->hash.fdir.hi);
11769 : 0 : goto err;
11770 : : }
11771 : : MLX5_ASSERT(tble->tunnel);
11772 : 0 : memcpy(&info->tunnel, &tble->tunnel->app_tunnel, sizeof(info->tunnel));
11773 : 0 : info->group_id = tble->group_id;
11774 : 0 : info->flags = RTE_FLOW_RESTORE_INFO_TUNNEL |
11775 : : RTE_FLOW_RESTORE_INFO_GROUP_ID |
11776 : : RTE_FLOW_RESTORE_INFO_ENCAPSULATED;
11777 : :
11778 : 0 : return 0;
11779 : :
11780 : 0 : err:
11781 : 0 : return rte_flow_error_set(err, EINVAL,
11782 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11783 : : "failed to get restore info");
11784 : : }
11785 : :
11786 : : #else /* HAVE_IBV_FLOW_DV_SUPPORT */
11787 : : static int
11788 : : mlx5_flow_tunnel_decap_set(__rte_unused struct rte_eth_dev *dev,
11789 : : __rte_unused struct rte_flow_tunnel *app_tunnel,
11790 : : __rte_unused struct rte_flow_action **actions,
11791 : : __rte_unused uint32_t *num_of_actions,
11792 : : __rte_unused struct rte_flow_error *error)
11793 : : {
11794 : : return -ENOTSUP;
11795 : : }
11796 : :
11797 : : static int
11798 : : mlx5_flow_tunnel_match(__rte_unused struct rte_eth_dev *dev,
11799 : : __rte_unused struct rte_flow_tunnel *app_tunnel,
11800 : : __rte_unused struct rte_flow_item **items,
11801 : : __rte_unused uint32_t *num_of_items,
11802 : : __rte_unused struct rte_flow_error *error)
11803 : : {
11804 : : return -ENOTSUP;
11805 : : }
11806 : :
11807 : : static int
11808 : : mlx5_flow_tunnel_item_release(__rte_unused struct rte_eth_dev *dev,
11809 : : __rte_unused struct rte_flow_item *pmd_items,
11810 : : __rte_unused uint32_t num_items,
11811 : : __rte_unused struct rte_flow_error *err)
11812 : : {
11813 : : return -ENOTSUP;
11814 : : }
11815 : :
11816 : : static int
11817 : : mlx5_flow_tunnel_action_release(__rte_unused struct rte_eth_dev *dev,
11818 : : __rte_unused struct rte_flow_action *pmd_action,
11819 : : __rte_unused uint32_t num_actions,
11820 : : __rte_unused struct rte_flow_error *err)
11821 : : {
11822 : : return -ENOTSUP;
11823 : : }
11824 : :
11825 : : static int
11826 : : mlx5_flow_tunnel_get_restore_info(__rte_unused struct rte_eth_dev *dev,
11827 : : __rte_unused struct rte_mbuf *m,
11828 : : __rte_unused struct rte_flow_restore_info *i,
11829 : : __rte_unused struct rte_flow_error *err)
11830 : : {
11831 : : return -ENOTSUP;
11832 : : }
11833 : :
11834 : : static int
11835 : : flow_tunnel_add_default_miss(__rte_unused struct rte_eth_dev *dev,
11836 : : __rte_unused struct rte_flow *flow,
11837 : : __rte_unused const struct rte_flow_attr *attr,
11838 : : __rte_unused const struct rte_flow_action *actions,
11839 : : __rte_unused uint32_t flow_idx,
11840 : : __rte_unused const struct mlx5_flow_tunnel *tunnel,
11841 : : __rte_unused struct tunnel_default_miss_ctx *ctx,
11842 : : __rte_unused struct rte_flow_error *error)
11843 : : {
11844 : : return -ENOTSUP;
11845 : : }
11846 : :
11847 : : static struct mlx5_flow_tunnel *
11848 : : mlx5_find_tunnel_id(__rte_unused struct rte_eth_dev *dev,
11849 : : __rte_unused uint32_t id)
11850 : : {
11851 : : return NULL;
11852 : : }
11853 : :
11854 : : static void
11855 : : mlx5_flow_tunnel_free(__rte_unused struct rte_eth_dev *dev,
11856 : : __rte_unused struct mlx5_flow_tunnel *tunnel)
11857 : : {
11858 : : }
11859 : :
11860 : : static uint32_t
11861 : : tunnel_flow_group_to_flow_table(__rte_unused struct rte_eth_dev *dev,
11862 : : __rte_unused const struct mlx5_flow_tunnel *t,
11863 : : __rte_unused uint32_t group,
11864 : : __rte_unused uint32_t *table,
11865 : : struct rte_flow_error *error)
11866 : : {
11867 : : return rte_flow_error_set(error, ENOTSUP,
11868 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11869 : : "tunnel offload requires DV support");
11870 : : }
11871 : :
11872 : : void
11873 : : mlx5_release_tunnel_hub(__rte_unused struct mlx5_dev_ctx_shared *sh,
11874 : : __rte_unused uint16_t port_id)
11875 : : {
11876 : : }
11877 : : #endif /* HAVE_IBV_FLOW_DV_SUPPORT */
11878 : :
11879 : : /* Flex flow item API */
11880 : : static struct rte_flow_item_flex_handle *
11881 : 0 : mlx5_flow_flex_item_create(struct rte_eth_dev *dev,
11882 : : const struct rte_flow_item_flex_conf *conf,
11883 : : struct rte_flow_error *error)
11884 : : {
11885 : : static const char err_msg[] = "flex item creation unsupported";
11886 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
11887 : : struct rte_flow_attr attr = { .transfer = 0 };
11888 : 0 : const struct mlx5_flow_driver_ops *fops =
11889 : : flow_get_drv_ops(flow_get_drv_type(dev, &attr));
11890 : :
11891 [ # # ]: 0 : if (!priv->pci_dev) {
11892 : 0 : rte_flow_error_set(error, ENOTSUP,
11893 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11894 : : "create flex item on PF only");
11895 : 0 : return NULL;
11896 : : }
11897 [ # # ]: 0 : switch (priv->pci_dev->id.device_id) {
11898 : : case PCI_DEVICE_ID_MELLANOX_BLUEFIELD2:
11899 : : case PCI_DEVICE_ID_MELLANOX_BLUEFIELD3:
11900 : : break;
11901 : 0 : default:
11902 : 0 : rte_flow_error_set(error, ENOTSUP,
11903 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11904 : : "flex item available on BlueField ports only");
11905 : 0 : return NULL;
11906 : : }
11907 [ # # ]: 0 : if (!priv->sh->cdev->config.hca_attr.parse_graph_flex_node) {
11908 : 0 : rte_flow_error_set(error, ENOTSUP,
11909 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11910 : : "flex item not supported on current FW");
11911 : 0 : return NULL;
11912 : : }
11913 [ # # ]: 0 : if (!fops->item_create) {
11914 : 0 : DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
11915 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
11916 : : NULL, err_msg);
11917 : 0 : return NULL;
11918 : : }
11919 : 0 : return fops->item_create(dev, conf, error);
11920 : : }
11921 : :
11922 : : static int
11923 [ # # ]: 0 : mlx5_flow_flex_item_release(struct rte_eth_dev *dev,
11924 : : const struct rte_flow_item_flex_handle *handle,
11925 : : struct rte_flow_error *error)
11926 : : {
11927 : : static const char err_msg[] = "flex item release unsupported";
11928 : : struct rte_flow_attr attr = { .transfer = 0 };
11929 : 0 : const struct mlx5_flow_driver_ops *fops =
11930 : : flow_get_drv_ops(flow_get_drv_type(dev, &attr));
11931 : :
11932 [ # # ]: 0 : if (!fops->item_release) {
11933 : 0 : DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
11934 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
11935 : : NULL, err_msg);
11936 : 0 : return -rte_errno;
11937 : : }
11938 : 0 : return fops->item_release(dev, handle, error);
11939 : : }
11940 : :
11941 : : static void
11942 : 0 : mlx5_dbg__print_pattern(const struct rte_flow_item *item)
11943 : : {
11944 : : int ret;
11945 : : struct rte_flow_error error;
11946 : :
11947 [ # # ]: 0 : for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
11948 : : char *item_name;
11949 : 0 : ret = rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_NAME_PTR, &item_name,
11950 : : sizeof(item_name),
11951 : 0 : (void *)(uintptr_t)item->type, &error);
11952 [ # # ]: 0 : if (ret > 0)
11953 : 0 : printf("%s ", item_name);
11954 : : else
11955 : 0 : printf("%d\n", (int)item->type);
11956 : : }
11957 : : printf("END\n");
11958 : 0 : }
11959 : :
11960 : : static int
11961 : : mlx5_flow_is_std_vxlan_port(const struct rte_flow_item *udp_item)
11962 : : {
11963 : 0 : const struct rte_flow_item_udp *spec = udp_item->spec;
11964 : 0 : const struct rte_flow_item_udp *mask = udp_item->mask;
11965 : : uint16_t udp_dport = 0;
11966 : :
11967 : 0 : if (spec != NULL) {
11968 [ # # ]: 0 : if (!mask)
11969 : : mask = &rte_flow_item_udp_mask;
11970 [ # # ]: 0 : udp_dport = rte_be_to_cpu_16(spec->hdr.dst_port &
11971 : : mask->hdr.dst_port);
11972 : : }
11973 : 0 : return (!udp_dport || udp_dport == MLX5_UDP_PORT_VXLAN);
11974 : : }
11975 : :
11976 : : static const struct mlx5_flow_expand_node *
11977 : 0 : mlx5_flow_expand_rss_adjust_node(const struct rte_flow_item *pattern,
11978 : : unsigned int item_idx,
11979 : : const struct mlx5_flow_expand_node graph[],
11980 : : const struct mlx5_flow_expand_node *node)
11981 : : {
11982 : 0 : const struct rte_flow_item *item = pattern + item_idx, *prev_item;
11983 : :
11984 [ # # # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_VXLAN &&
11985 : 0 : node != NULL &&
11986 [ # # ]: 0 : node->type == RTE_FLOW_ITEM_TYPE_VXLAN) {
11987 : : /*
11988 : : * The expansion node is VXLAN and it is also the last
11989 : : * expandable item in the pattern, so need to continue
11990 : : * expansion of the inner tunnel.
11991 : : */
11992 : : MLX5_ASSERT(item_idx > 0);
11993 [ # # ]: 0 : prev_item = pattern + item_idx - 1;
11994 : : MLX5_ASSERT(prev_item->type == RTE_FLOW_ITEM_TYPE_UDP);
11995 [ # # ]: 0 : if (mlx5_flow_is_std_vxlan_port(prev_item))
11996 : 0 : return &graph[MLX5_EXPANSION_STD_VXLAN];
11997 : 0 : return &graph[MLX5_EXPANSION_L3_VXLAN];
11998 : : }
11999 : : return node;
12000 : : }
12001 : :
12002 : : /* Map of Verbs to Flow priority with 8 Verbs priorities. */
12003 : : static const uint32_t priority_map_3[][MLX5_PRIORITY_MAP_MAX] = {
12004 : : { 0, 1, 2 }, { 2, 3, 4 }, { 5, 6, 7 },
12005 : : };
12006 : :
12007 : : /* Map of Verbs to Flow priority with 16 Verbs priorities. */
12008 : : static const uint32_t priority_map_5[][MLX5_PRIORITY_MAP_MAX] = {
12009 : : { 0, 1, 2 }, { 3, 4, 5 }, { 6, 7, 8 },
12010 : : { 9, 10, 11 }, { 12, 13, 14 },
12011 : : };
12012 : :
12013 : : /**
12014 : : * Discover the number of available flow priorities.
12015 : : *
12016 : : * @param dev
12017 : : * Ethernet device.
12018 : : *
12019 : : * @return
12020 : : * On success, number of available flow priorities.
12021 : : * On failure, a negative errno-style code and rte_errno is set.
12022 : : */
12023 : : int
12024 : 0 : mlx5_flow_discover_priorities(struct rte_eth_dev *dev)
12025 : : {
12026 : : static const uint16_t vprio[] = {8, 16};
12027 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
12028 : : const struct mlx5_flow_driver_ops *fops;
12029 : : enum mlx5_flow_drv_type type;
12030 : : int ret;
12031 : :
12032 : : type = mlx5_flow_os_get_type();
12033 : : if (type == MLX5_FLOW_TYPE_MAX) {
12034 : : type = MLX5_FLOW_TYPE_VERBS;
12035 [ # # # # ]: 0 : if (priv->sh->cdev->config.devx && priv->sh->config.dv_flow_en)
12036 : : type = MLX5_FLOW_TYPE_DV;
12037 : : }
12038 : 0 : fops = flow_get_drv_ops(type);
12039 [ # # ]: 0 : if (fops->discover_priorities == NULL) {
12040 : 0 : DRV_LOG(ERR, "Priority discovery not supported");
12041 : 0 : rte_errno = ENOTSUP;
12042 : 0 : return -rte_errno;
12043 : : }
12044 : 0 : ret = fops->discover_priorities(dev, vprio, RTE_DIM(vprio));
12045 [ # # ]: 0 : if (ret < 0)
12046 : : return ret;
12047 [ # # # ]: 0 : switch (ret) {
12048 : : case 8:
12049 : : ret = RTE_DIM(priority_map_3);
12050 : : break;
12051 : 0 : case 16:
12052 : : ret = RTE_DIM(priority_map_5);
12053 : 0 : break;
12054 : 0 : default:
12055 : 0 : rte_errno = ENOTSUP;
12056 : 0 : DRV_LOG(ERR,
12057 : : "port %u maximum priority: %d expected 8/16",
12058 : : dev->data->port_id, ret);
12059 : 0 : return -rte_errno;
12060 : : }
12061 : 0 : DRV_LOG(INFO, "port %u supported flow priorities:"
12062 : : " 0-%d for ingress or egress root table,"
12063 : : " 0-%d for non-root table or transfer root table.",
12064 : : dev->data->port_id, ret - 2,
12065 : : MLX5_NON_ROOT_FLOW_MAX_PRIO - 1);
12066 : 0 : return ret;
12067 : : }
12068 : :
12069 : : /**
12070 : : * Adjust flow priority based on the highest layer and the request priority.
12071 : : *
12072 : : * @param[in] dev
12073 : : * Pointer to the Ethernet device structure.
12074 : : * @param[in] priority
12075 : : * The rule base priority.
12076 : : * @param[in] subpriority
12077 : : * The priority based on the items.
12078 : : *
12079 : : * @return
12080 : : * The new priority.
12081 : : */
12082 : : uint32_t
12083 : 0 : mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
12084 : : uint32_t subpriority)
12085 : : {
12086 : : uint32_t res = 0;
12087 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12088 : :
12089 [ # # # ]: 0 : switch (priv->sh->flow_max_priority) {
12090 : 0 : case RTE_DIM(priority_map_3):
12091 : 0 : res = priority_map_3[priority][subpriority];
12092 : 0 : break;
12093 : 0 : case RTE_DIM(priority_map_5):
12094 : 0 : res = priority_map_5[priority][subpriority];
12095 : 0 : break;
12096 : : }
12097 : 0 : return res;
12098 : : }
12099 : :
12100 : : /**
12101 : : * Get the priority for sending traffic to kernel table.
12102 : : *
12103 : : * @param[in] dev
12104 : : * Pointer to the Ethernet device structure.
12105 : : *
12106 : : * @return
12107 : : * On success: the value of priority for sending traffic to kernel table
12108 : : * On failure: -1
12109 : : */
12110 : : uint32_t
12111 : 0 : mlx5_get_send_to_kernel_priority(struct rte_eth_dev *dev)
12112 : : {
12113 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12114 : : uint32_t res;
12115 : :
12116 [ # # # ]: 0 : switch (priv->sh->flow_max_priority) {
12117 : : case RTE_DIM(priority_map_5):
12118 : : res = 15;
12119 : : break;
12120 : 0 : case RTE_DIM(priority_map_3):
12121 : : res = 7;
12122 : 0 : break;
12123 : 0 : default:
12124 : 0 : DRV_LOG(ERR,
12125 : : "port %u maximum priority: %d expected 8/16",
12126 : : dev->data->port_id, priv->sh->flow_max_priority);
12127 : : res = (uint32_t)-1;
12128 : : }
12129 : 0 : return res;
12130 : : }
12131 : :
12132 : : /**
12133 : : * Get the E-Switch Manager vport id.
12134 : : *
12135 : : * @param[in] dev
12136 : : * Pointer to the Ethernet device structure.
12137 : : *
12138 : : * @return
12139 : : * The vport id.
12140 : : */
12141 : 0 : int16_t mlx5_flow_get_esw_manager_vport_id(struct rte_eth_dev *dev)
12142 : : {
12143 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12144 : 0 : struct mlx5_common_device *cdev = priv->sh->cdev;
12145 : :
12146 : : /* New FW exposes E-Switch Manager vport ID, can use it directly. */
12147 [ # # ]: 0 : if (cdev->config.hca_attr.esw_mgr_vport_id_valid)
12148 : 0 : return (int16_t)cdev->config.hca_attr.esw_mgr_vport_id;
12149 : :
12150 [ # # ]: 0 : if (priv->pci_dev == NULL)
12151 : : return 0;
12152 [ # # ]: 0 : switch (priv->pci_dev->id.device_id) {
12153 : : case PCI_DEVICE_ID_MELLANOX_BLUEFIELD:
12154 : : case PCI_DEVICE_ID_MELLANOX_BLUEFIELD2:
12155 : : case PCI_DEVICE_ID_MELLANOX_BLUEFIELD3:
12156 : : /*
12157 : : * In old FW which doesn't expose the E-Switch Manager vport ID in the capability,
12158 : : * only the BF embedded CPUs control the E-Switch Manager port. Hence,
12159 : : * ECPF vport ID is selected and not the host port (0) in any BF case.
12160 : : */
12161 : : return (int16_t)MLX5_ECPF_VPORT_ID;
12162 : 0 : default:
12163 : 0 : return MLX5_PF_VPORT_ID;
12164 : : }
12165 : : }
12166 : :
12167 : : /**
12168 : : * Parse item to get the vport id.
12169 : : *
12170 : : * @param[in] dev
12171 : : * Pointer to the Ethernet device structure.
12172 : : * @param[in] item
12173 : : * The src port id match item.
12174 : : * @param[out] vport_id
12175 : : * Pointer to put the vport id.
12176 : : * @param[out] all_ports
12177 : : * Indicate if the item matches all ports.
12178 : : * @param[out] error
12179 : : * Pointer to error structure.
12180 : : *
12181 : : * @return
12182 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
12183 : : */
12184 : 0 : int mlx5_flow_get_item_vport_id(struct rte_eth_dev *dev,
12185 : : const struct rte_flow_item *item,
12186 : : uint16_t *vport_id,
12187 : : bool *all_ports,
12188 : : struct rte_flow_error *error)
12189 : : {
12190 : : struct mlx5_priv *port_priv;
12191 : : const struct rte_flow_item_port_id *pid_v = NULL;
12192 : : const struct rte_flow_item_ethdev *dev_v = NULL;
12193 : : uint32_t esw_mgr_port;
12194 : : uint32_t src_port;
12195 : :
12196 [ # # ]: 0 : if (all_ports)
12197 : 0 : *all_ports = false;
12198 [ # # # # ]: 0 : switch (item->type) {
12199 : 0 : case RTE_FLOW_ITEM_TYPE_PORT_ID:
12200 : 0 : pid_v = item->spec;
12201 [ # # ]: 0 : if (!pid_v)
12202 : : return 0;
12203 : 0 : src_port = pid_v->id;
12204 : : esw_mgr_port = MLX5_PORT_ESW_MGR;
12205 : 0 : break;
12206 : 0 : case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
12207 : 0 : dev_v = item->spec;
12208 [ # # ]: 0 : if (!dev_v) {
12209 [ # # ]: 0 : if (all_ports)
12210 : 0 : *all_ports = true;
12211 : 0 : return 0;
12212 : : }
12213 : 0 : src_port = dev_v->port_id;
12214 : : esw_mgr_port = MLX5_REPRESENTED_PORT_ESW_MGR;
12215 : 0 : break;
12216 : : case RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR:
12217 : : src_port = MLX5_REPRESENTED_PORT_ESW_MGR;
12218 : : esw_mgr_port = MLX5_REPRESENTED_PORT_ESW_MGR;
12219 : : break;
12220 : 0 : default:
12221 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
12222 : : NULL, "Incorrect item type.");
12223 : : }
12224 [ # # ]: 0 : if (src_port == esw_mgr_port) {
12225 : 0 : *vport_id = mlx5_flow_get_esw_manager_vport_id(dev);
12226 : : } else {
12227 : 0 : port_priv = mlx5_port_to_eswitch_info(src_port, false);
12228 [ # # ]: 0 : if (!port_priv)
12229 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
12230 : : NULL, "Failed to get port info.");
12231 : 0 : *vport_id = port_priv->representor_id;
12232 : : }
12233 : :
12234 : : return 0;
12235 : : }
12236 : :
12237 : : int
12238 : 0 : mlx5_flow_pick_transfer_proxy(struct rte_eth_dev *dev,
12239 : : uint16_t *proxy_port_id,
12240 : : struct rte_flow_error *error)
12241 : : {
12242 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
12243 : : uint16_t port_id;
12244 : :
12245 [ # # ]: 0 : if (!priv->sh->config.dv_esw_en)
12246 : 0 : return rte_flow_error_set(error, EINVAL,
12247 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12248 : : NULL,
12249 : : "unable to provide a proxy port"
12250 : : " without E-Switch configured");
12251 [ # # ]: 0 : if (!priv->master && !priv->representor)
12252 : 0 : return rte_flow_error_set(error, EINVAL,
12253 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12254 : : NULL,
12255 : : "unable to provide a proxy port"
12256 : : " for port which is not a master"
12257 : : " or a representor port");
12258 [ # # ]: 0 : if (priv->master) {
12259 : 0 : *proxy_port_id = dev->data->port_id;
12260 : 0 : return 0;
12261 : : }
12262 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port_id, dev->device) {
12263 : 0 : const struct rte_eth_dev *port_dev = &rte_eth_devices[port_id];
12264 : 0 : const struct mlx5_priv *port_priv = port_dev->data->dev_private;
12265 : :
12266 [ # # ]: 0 : if (port_priv->master &&
12267 [ # # ]: 0 : port_priv->domain_id == priv->domain_id) {
12268 : 0 : *proxy_port_id = port_id;
12269 : 0 : return 0;
12270 : : }
12271 : : }
12272 : 0 : return rte_flow_error_set(error, ENODEV,
12273 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12274 : : NULL, "unable to find a proxy port");
12275 : : }
12276 : :
12277 : : /**
12278 : : * Discover IPv6 traffic class ID support in rdma-core and firmware.
12279 : : *
12280 : : * @param dev
12281 : : * Ethernet device.
12282 : : *
12283 : : * @return
12284 : : * 0, rdma-core is good to work with firmware.
12285 : : * -EOPNOTSUPP, rdma-core could not work with new IPv6 TC ID.
12286 : : */
12287 : : int
12288 : 0 : mlx5_flow_discover_ipv6_tc_support(struct rte_eth_dev *dev)
12289 : : {
12290 : : struct rte_flow_action_set_dscp set_dscp;
12291 : : struct rte_flow_attr attr;
12292 : : struct rte_flow_action actions[2];
12293 : : struct rte_flow_item items[3];
12294 : : struct rte_flow_error error;
12295 : : uint32_t flow_idx;
12296 : :
12297 : : memset(&attr, 0, sizeof(attr));
12298 : : memset(actions, 0, sizeof(actions));
12299 : : memset(items, 0, sizeof(items));
12300 : 0 : attr.group = 1;
12301 : 0 : attr.egress = 1;
12302 : 0 : items[0].type = RTE_FLOW_ITEM_TYPE_ETH;
12303 : 0 : items[1].type = RTE_FLOW_ITEM_TYPE_IPV6;
12304 : : items[2].type = RTE_FLOW_ITEM_TYPE_END;
12305 : : /* Random value */
12306 : 0 : set_dscp.dscp = 9;
12307 : 0 : actions[0].type = RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP;
12308 : 0 : actions[0].conf = &set_dscp;
12309 : : actions[1].type = RTE_FLOW_ACTION_TYPE_END;
12310 : :
12311 : 0 : flow_idx = mlx5_flow_list_create(dev, MLX5_FLOW_TYPE_GEN, &attr, items,
12312 : : actions, true, &error);
12313 [ # # ]: 0 : if (!flow_idx)
12314 : : return -EOPNOTSUPP;
12315 : :
12316 : 0 : mlx5_flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN, flow_idx);
12317 : 0 : return 0;
12318 : : }
12319 : :
12320 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_mlx5_create_geneve_tlv_parser, 24.03)
12321 : : void *
12322 : 0 : rte_pmd_mlx5_create_geneve_tlv_parser(uint16_t port_id,
12323 : : const struct rte_pmd_mlx5_geneve_tlv tlv_list[],
12324 : : uint8_t nb_options)
12325 : : {
12326 : : #ifdef HAVE_MLX5_HWS_SUPPORT
12327 : 0 : return mlx5_geneve_tlv_parser_create(port_id, tlv_list, nb_options);
12328 : : #else
12329 : : (void)port_id;
12330 : : (void)tlv_list;
12331 : : (void)nb_options;
12332 : : DRV_LOG(ERR, "%s is not supported.", __func__);
12333 : : rte_errno = ENOTSUP;
12334 : : return NULL;
12335 : : #endif
12336 : : }
12337 : :
12338 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_mlx5_destroy_geneve_tlv_parser, 24.03)
12339 : : int
12340 : 0 : rte_pmd_mlx5_destroy_geneve_tlv_parser(void *handle)
12341 : : {
12342 : : #ifdef HAVE_MLX5_HWS_SUPPORT
12343 : 0 : return mlx5_geneve_tlv_parser_destroy(handle);
12344 : : #else
12345 : : (void)handle;
12346 : : DRV_LOG(ERR, "%s is not supported.", __func__);
12347 : : rte_errno = ENOTSUP;
12348 : : return -rte_errno;
12349 : : #endif
12350 : : }
12351 : :
12352 : : bool
12353 : 0 : mlx5_ctrl_flow_uc_dmac_exists(struct rte_eth_dev *dev, const struct rte_ether_addr *addr)
12354 : : {
12355 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12356 : : struct mlx5_ctrl_flow_entry *entry;
12357 : : bool exists = false;
12358 : :
12359 [ # # ]: 0 : LIST_FOREACH(entry, &priv->hw_ctrl_flows, next) {
12360 [ # # # # ]: 0 : if (entry->info.type == MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC &&
12361 : : rte_is_same_ether_addr(addr, &entry->info.uc.dmac)) {
12362 : : exists = true;
12363 : : break;
12364 : : }
12365 : : }
12366 : 0 : return exists;
12367 : : }
12368 : :
12369 : : bool
12370 : 0 : mlx5_ctrl_flow_uc_dmac_vlan_exists(struct rte_eth_dev *dev,
12371 : : const struct rte_ether_addr *addr,
12372 : : const uint16_t vid)
12373 : : {
12374 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12375 : : struct mlx5_ctrl_flow_entry *entry;
12376 : : bool exists = false;
12377 : :
12378 [ # # ]: 0 : LIST_FOREACH(entry, &priv->hw_ctrl_flows, next) {
12379 [ # # # # ]: 0 : if (entry->info.type == MLX5_CTRL_FLOW_TYPE_DEFAULT_RX_RSS_UNICAST_DMAC_VLAN &&
12380 : 0 : rte_is_same_ether_addr(addr, &entry->info.uc.dmac) &&
12381 [ # # ]: 0 : vid == entry->info.uc.vlan) {
12382 : : exists = true;
12383 : : break;
12384 : : }
12385 : : }
12386 : 0 : return exists;
12387 : : }
12388 : :
12389 : : static bool mlx5_steering_disabled;
12390 : :
12391 : : bool
12392 : 0 : mlx5_flow_is_steering_disabled(void)
12393 : : {
12394 : 0 : return mlx5_steering_disabled;
12395 : : }
12396 : :
12397 : : static void
12398 : 0 : flow_disable_steering_flush(struct rte_eth_dev *dev)
12399 : : {
12400 : : /*
12401 : : * This repeats the steps done in mlx5_dev_stop(), with a small difference:
12402 : : * - mlx5_flow_hw_cleanup_ctrl_rx_templates() and mlx5_action_handle_detach()
12403 : : * They are rearranged to make it work with different dev->data->dev_started.
12404 : : * Please see a TODO note in mlx5_dev_stop().
12405 : : */
12406 : :
12407 : 0 : mlx5_flow_stop_default(dev);
12408 : 0 : mlx5_traffic_disable(dev);
12409 : 0 : mlx5_flow_list_flush(dev, MLX5_FLOW_TYPE_GEN, true);
12410 : 0 : mlx5_flow_meter_rxq_flush(dev);
12411 : : #ifdef HAVE_MLX5_HWS_SUPPORT
12412 : 0 : mlx5_flow_hw_cleanup_ctrl_rx_templates(dev);
12413 : : #endif
12414 : 0 : mlx5_action_handle_detach(dev);
12415 : 0 : }
12416 : :
12417 : : static void
12418 : 0 : flow_disable_steering_cleanup(struct rte_eth_dev *dev)
12419 : : {
12420 : : /*
12421 : : * See mlx5_dev_close(). Only steps not done on mlx5_dev_stop() are executed here.
12422 : : * Necessary steps are copied as is because steering resource cleanup in mlx5_dev_close()
12423 : : * is interleaved with other steps.
12424 : : * TODO: Rework steering resource cleanup in mlx5_dev_close() to allow code reuse.
12425 : : */
12426 : :
12427 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12428 : :
12429 : 0 : mlx5_action_handle_flush(dev);
12430 : 0 : mlx5_flow_meter_flush(dev, NULL);
12431 : 0 : mlx5_flex_parser_ecpri_release(dev);
12432 : 0 : mlx5_flex_item_port_cleanup(dev);
12433 : 0 : mlx5_indirect_list_handles_release(dev);
12434 : : #ifdef HAVE_MLX5_HWS_SUPPORT
12435 : 0 : mlx5_flow_hw_destroy_vport_action(dev);
12436 : 0 : mlx5_flow_hw_resource_release(dev);
12437 : 0 : mlx5_flow_hw_clear_port_info(dev);
12438 [ # # ]: 0 : if (priv->tlv_options != NULL) {
12439 : : /* Free the GENEVE TLV parser resource. */
12440 : 0 : claim_zero(mlx5_geneve_tlv_options_destroy(priv->tlv_options, priv->sh->phdev));
12441 : 0 : priv->tlv_options = NULL;
12442 : : }
12443 [ # # ]: 0 : if (priv->ptype_rss_groups) {
12444 : 0 : mlx5_ipool_destroy(priv->ptype_rss_groups);
12445 : 0 : priv->ptype_rss_groups = NULL;
12446 : : }
12447 [ # # ]: 0 : if (priv->dr_ctx) {
12448 : 0 : claim_zero(mlx5dr_context_close(priv->dr_ctx));
12449 : 0 : priv->dr_ctx = NULL;
12450 : : }
12451 : : #else
12452 : : RTE_SET_USED(priv);
12453 : : #endif
12454 : 0 : }
12455 : :
12456 : : typedef void (*run_on_related_cb_t)(struct rte_eth_dev *dev);
12457 : :
12458 : : static void
12459 : 0 : flow_disable_steering_run_on_related(struct rte_eth_dev *dev,
12460 : : run_on_related_cb_t cb)
12461 : : {
12462 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12463 : : uint16_t other_port_id;
12464 : : uint16_t proxy_port_id;
12465 : : uint16_t port_id;
12466 : : int ret __rte_unused;
12467 : :
12468 [ # # ]: 0 : if (priv->sh->config.dv_esw_en) {
12469 : 0 : ret = mlx5_flow_pick_transfer_proxy(dev, &proxy_port_id, NULL);
12470 [ # # ]: 0 : if (ret != 0) {
12471 : : /*
12472 : : * This case should not happen because E-Switch is enabled.
12473 : : * However, in any case, release resources on the given port
12474 : : * and log the misconfigured port.
12475 : : */
12476 : 0 : DRV_LOG(ERR, "port %u unable to find transfer proxy port ret=%d",
12477 : : priv->dev_data->port_id, ret);
12478 : 0 : cb(dev);
12479 : 0 : return;
12480 : : }
12481 : :
12482 : : /* Run callback on representors. */
12483 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(other_port_id, dev->device) {
12484 : 0 : struct rte_eth_dev *other_dev = &rte_eth_devices[other_port_id];
12485 : :
12486 [ # # ]: 0 : if (other_port_id != proxy_port_id)
12487 : 0 : cb(other_dev);
12488 : : }
12489 : :
12490 : : /* Run callback on proxy port. */
12491 : 0 : cb(&rte_eth_devices[proxy_port_id]);
12492 [ # # ]: 0 : } else if (rte_atomic_load_explicit(&priv->shared_refcnt, rte_memory_order_relaxed) > 0) {
12493 : : /* Run callback on guest ports. */
12494 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port_id, NULL) {
12495 : 0 : struct rte_eth_dev *other_dev = &rte_eth_devices[port_id];
12496 : 0 : struct mlx5_priv *other_priv = other_dev->data->dev_private;
12497 : :
12498 [ # # ]: 0 : if (other_priv->shared_host == dev)
12499 : 0 : cb(other_dev);
12500 : : }
12501 : :
12502 : : /* Run callback on host port. */
12503 : 0 : cb(dev);
12504 : : } else {
12505 : 0 : cb(dev);
12506 : : }
12507 : : }
12508 : :
12509 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_mlx5_disable_steering, 25.11)
12510 : : void
12511 : 0 : rte_pmd_mlx5_disable_steering(void)
12512 : : {
12513 : : uint16_t port_id;
12514 : :
12515 [ # # ]: 0 : if (mlx5_steering_disabled)
12516 : : return;
12517 : :
12518 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port_id, NULL) {
12519 [ # # ]: 0 : struct rte_eth_dev *dev = &rte_eth_devices[port_id];
12520 : :
12521 [ # # ]: 0 : if (mlx5_hws_active(dev)) {
12522 : 0 : flow_disable_steering_run_on_related(dev, flow_disable_steering_flush);
12523 : 0 : flow_disable_steering_run_on_related(dev, flow_disable_steering_cleanup);
12524 : : } else {
12525 : 0 : flow_disable_steering_flush(dev);
12526 : 0 : flow_disable_steering_cleanup(dev);
12527 : : }
12528 : :
12529 : 0 : mlx5_flow_rxq_mark_flag_set(dev);
12530 : : }
12531 : :
12532 : 0 : mlx5_steering_disabled = true;
12533 : : }
12534 : :
12535 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_mlx5_enable_steering, 25.11)
12536 : : int
12537 : 0 : rte_pmd_mlx5_enable_steering(void)
12538 : : {
12539 : : uint16_t port_id;
12540 : :
12541 [ # # ]: 0 : if (!mlx5_steering_disabled)
12542 : : return 0;
12543 : :
12544 : : /* If any mlx5 port is probed, disallow enabling steering. */
12545 : 0 : port_id = mlx5_eth_find_next(0, NULL);
12546 [ # # ]: 0 : if (port_id != RTE_MAX_ETHPORTS)
12547 : : return -EBUSY;
12548 : :
12549 : 0 : mlx5_steering_disabled = false;
12550 : :
12551 : 0 : return 0;
12552 : : }
12553 : :
12554 : : bool
12555 : 0 : mlx5_vport_rx_metadata_passing_enabled(const struct mlx5_dev_ctx_shared *sh)
12556 : : {
12557 : : const struct mlx5_sh_config *dev_config = &sh->config;
12558 : 0 : const struct mlx5_hca_attr *hca_attr = &sh->cdev->config.hca_attr;
12559 : :
12560 [ # # # # ]: 0 : return !dev_config->dv_esw_en && hca_attr->fdb_to_vport_metadata;
12561 : : }
12562 : :
12563 : : bool
12564 : 0 : mlx5_vport_tx_metadata_passing_enabled(const struct mlx5_dev_ctx_shared *sh)
12565 : : {
12566 : : const struct mlx5_sh_config *dev_config = &sh->config;
12567 : 0 : const struct mlx5_hca_attr *hca_attr = &sh->cdev->config.hca_attr;
12568 : :
12569 [ # # # # ]: 0 : return !dev_config->dv_esw_en && hca_attr->vport_to_fdb_metadata;
12570 : : }
12571 : :
12572 : : bool
12573 : 0 : mlx5_esw_metadata_passing_enabled(const struct mlx5_dev_ctx_shared *sh)
12574 : : {
12575 : : const struct mlx5_sh_config *dev_config = &sh->config;
12576 : 0 : const struct mlx5_hca_attr *hca_attr = &sh->cdev->config.hca_attr;
12577 : 0 : bool fdb_to_vport_metadata_on = (hca_attr->fdb_to_vport_reg_c_id &
12578 : : RTE_BIT32(MLX5_ESW_VPORT_METADATA_REG_C_1)) != 0;
12579 : :
12580 [ # # # # ]: 0 : return dev_config->dv_esw_en && hca_attr->fdb_to_vport_reg_c && fdb_to_vport_metadata_on &&
12581 [ # # # # ]: 0 : hca_attr->vport_to_fdb_metadata && hca_attr->fdb_to_vport_metadata;
12582 : : }
|