Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright 2018 Mellanox Technologies, Ltd
3 : : */
4 : :
5 : : #include <sys/queue.h>
6 : : #include <stdalign.h>
7 : : #include <stdint.h>
8 : : #include <string.h>
9 : : #include <unistd.h>
10 : :
11 : : #include <rte_bitops.h>
12 : : #include <rte_common.h>
13 : : #include <rte_ether.h>
14 : : #include <ethdev_driver.h>
15 : : #include <rte_flow.h>
16 : : #include <rte_flow_driver.h>
17 : : #include <rte_malloc.h>
18 : : #include <rte_cycles.h>
19 : : #include <bus_pci_driver.h>
20 : : #include <rte_ip.h>
21 : : #include <rte_gre.h>
22 : : #include <rte_vxlan.h>
23 : : #include <rte_gtp.h>
24 : : #include <rte_eal_paging.h>
25 : : #include <rte_mpls.h>
26 : : #include <rte_mtr.h>
27 : : #include <rte_mtr_driver.h>
28 : : #include <rte_tailq.h>
29 : :
30 : : #include <mlx5_glue.h>
31 : : #include <mlx5_devx_cmds.h>
32 : : #include <mlx5_prm.h>
33 : : #include <mlx5_malloc.h>
34 : :
35 : : #include "mlx5_defs.h"
36 : : #include "mlx5.h"
37 : : #include "mlx5_common_os.h"
38 : : #include "mlx5_flow.h"
39 : : #include "mlx5_flow_os.h"
40 : : #include "mlx5_rx.h"
41 : : #include "mlx5_tx.h"
42 : : #include "rte_pmd_mlx5.h"
43 : :
44 : : #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
45 : :
46 : : #ifndef HAVE_IBV_FLOW_DEVX_COUNTERS
47 : : #define MLX5DV_FLOW_ACTION_COUNTERS_DEVX 0
48 : : #endif
49 : :
50 : : #ifndef HAVE_MLX5DV_DR_ESWITCH
51 : : #ifndef MLX5DV_FLOW_TABLE_TYPE_FDB
52 : : #define MLX5DV_FLOW_TABLE_TYPE_FDB 0
53 : : #endif
54 : : #endif
55 : :
56 : : #ifndef HAVE_MLX5DV_DR
57 : : #define MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL 1
58 : : #endif
59 : :
60 : : /* VLAN header definitions */
61 : : #define MLX5DV_FLOW_VLAN_PCP_SHIFT 13
62 : : #define MLX5DV_FLOW_VLAN_PCP_MASK (0x7 << MLX5DV_FLOW_VLAN_PCP_SHIFT)
63 : : #define MLX5DV_FLOW_VLAN_VID_MASK 0x0fff
64 : : #define MLX5DV_FLOW_VLAN_PCP_MASK_BE RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK)
65 : : #define MLX5DV_FLOW_VLAN_VID_MASK_BE RTE_BE16(MLX5DV_FLOW_VLAN_VID_MASK)
66 : :
67 : : #define MLX5_ITEM_VALID(item, key_type) \
68 : : (((MLX5_SET_MATCHER_SW & (key_type)) && !((item)->spec)) || \
69 : : ((MLX5_SET_MATCHER_HS_V == (key_type)) && !((item)->spec)) || \
70 : : ((MLX5_SET_MATCHER_HS_M == (key_type)) && !((item)->mask)))
71 : :
72 : : #define MLX5_ITEM_UPDATE(item, key_type, v, m, gm) \
73 : : do { \
74 : : if ((key_type) == MLX5_SET_MATCHER_SW_V) { \
75 : : v = (item)->spec; \
76 : : m = (item)->mask ? (item)->mask : (gm); \
77 : : } else if ((key_type) == MLX5_SET_MATCHER_HS_V) { \
78 : : v = (item)->spec; \
79 : : m = (v); \
80 : : } else { \
81 : : v = (item)->mask ? (item)->mask : (gm); \
82 : : m = (v); \
83 : : } \
84 : : } while (0)
85 : :
86 : : #define CALC_MODI_ID(field, level) \
87 : : (((level) > 1) ? MLX5_MODI_IN_##field : MLX5_MODI_OUT_##field)
88 : :
89 : : union flow_dv_attr {
90 : : struct {
91 : : uint32_t valid:1;
92 : : uint32_t ipv4:1;
93 : : uint32_t ipv6:1;
94 : : uint32_t tcp:1;
95 : : uint32_t udp:1;
96 : : uint32_t reserved:27;
97 : : };
98 : : uint32_t attr;
99 : : };
100 : :
101 : : static int
102 : : flow_dv_port_id_action_resource_release(struct rte_eth_dev *dev,
103 : : uint32_t port_id);
104 : : static void
105 : : flow_dv_shared_rss_action_release(struct rte_eth_dev *dev, uint32_t srss);
106 : :
107 : : static int
108 : : flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev,
109 : : uint32_t rix_jump);
110 : :
111 : : /**
112 : : * Initialize flow attributes structure according to flow items' types.
113 : : *
114 : : * mlx5_flow_dv_validate() avoids multiple L3/L4 layers cases other than tunnel
115 : : * mode. For tunnel mode, the items to be modified are the outermost ones.
116 : : *
117 : : * @param[in] item
118 : : * Pointer to item specification.
119 : : * @param[out] attr
120 : : * Pointer to flow attributes structure.
121 : : * @param[in] dev_flow
122 : : * Pointer to the sub flow.
123 : : * @param[in] tunnel_decap
124 : : * Whether action is after tunnel decapsulation.
125 : : */
126 : : static void
127 : 0 : flow_dv_attr_init(const struct rte_flow_item *item, union flow_dv_attr *attr,
128 : : struct mlx5_flow *dev_flow, bool tunnel_decap)
129 : : {
130 : 0 : uint64_t layers = dev_flow->handle->layers;
131 : : bool tunnel_match = false;
132 : :
133 : : /*
134 : : * If layers is already initialized, it means this dev_flow is the
135 : : * suffix flow, the layers flags is set by the prefix flow. Need to
136 : : * use the layer flags from prefix flow as the suffix flow may not
137 : : * have the user defined items as the flow is split.
138 : : */
139 [ # # ]: 0 : if (layers) {
140 [ # # ]: 0 : if (tunnel_decap) {
141 : : /*
142 : : * If decap action before modify, it means the driver
143 : : * should take the inner as outer for the modify actions.
144 : : */
145 : 0 : layers = ((layers >> 6) & MLX5_FLOW_LAYER_OUTER);
146 : : }
147 [ # # ]: 0 : if (layers & MLX5_FLOW_LAYER_OUTER_L3_IPV4)
148 : 0 : attr->ipv4 = 1;
149 [ # # ]: 0 : else if (layers & MLX5_FLOW_LAYER_OUTER_L3_IPV6)
150 : 0 : attr->ipv6 = 1;
151 [ # # ]: 0 : if (layers & MLX5_FLOW_LAYER_OUTER_L4_TCP)
152 : 0 : attr->tcp = 1;
153 [ # # ]: 0 : else if (layers & MLX5_FLOW_LAYER_OUTER_L4_UDP)
154 : 0 : attr->udp = 1;
155 : 0 : attr->valid = 1;
156 : 0 : return;
157 : : }
158 [ # # ]: 0 : for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
159 : : uint8_t next_protocol = 0xff;
160 [ # # # # : 0 : switch (item->type) {
# # ]
161 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
162 : : case RTE_FLOW_ITEM_TYPE_NVGRE:
163 : : case RTE_FLOW_ITEM_TYPE_VXLAN:
164 : : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
165 : : case RTE_FLOW_ITEM_TYPE_GENEVE:
166 : : case RTE_FLOW_ITEM_TYPE_MPLS:
167 : : case RTE_FLOW_ITEM_TYPE_GTP:
168 [ # # ]: 0 : if (tunnel_decap) {
169 : 0 : attr->attr = 0;
170 : : tunnel_match = true;
171 : : }
172 : : break;
173 : 0 : case RTE_FLOW_ITEM_TYPE_IPV4:
174 [ # # ]: 0 : if (!attr->ipv6)
175 : 0 : attr->ipv4 = 1;
176 [ # # ]: 0 : if (item->mask != NULL &&
177 : : ((const struct rte_flow_item_ipv4 *)
178 [ # # ]: 0 : item->mask)->hdr.next_proto_id)
179 : 0 : next_protocol =
180 : : ((const struct rte_flow_item_ipv4 *)
181 : 0 : (item->spec))->hdr.next_proto_id &
182 : : ((const struct rte_flow_item_ipv4 *)
183 : : (item->mask))->hdr.next_proto_id;
184 : 0 : if ((next_protocol == IPPROTO_IPIP ||
185 [ # # ]: 0 : next_protocol == IPPROTO_IPV6) && tunnel_decap &&
186 [ # # ]: 0 : !tunnel_match)
187 : 0 : attr->attr = 0;
188 : : break;
189 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6:
190 [ # # ]: 0 : if (!attr->ipv4)
191 : 0 : attr->ipv6 = 1;
192 [ # # ]: 0 : if (item->mask != NULL &&
193 : : ((const struct rte_flow_item_ipv6 *)
194 [ # # ]: 0 : item->mask)->hdr.proto)
195 : 0 : next_protocol =
196 : : ((const struct rte_flow_item_ipv6 *)
197 : 0 : (item->spec))->hdr.proto &
198 : : ((const struct rte_flow_item_ipv6 *)
199 : : (item->mask))->hdr.proto;
200 : 0 : if ((next_protocol == IPPROTO_IPIP ||
201 [ # # ]: 0 : next_protocol == IPPROTO_IPV6) && tunnel_decap &&
202 [ # # ]: 0 : !tunnel_match)
203 : 0 : attr->attr = 0;
204 : : break;
205 : 0 : case RTE_FLOW_ITEM_TYPE_UDP:
206 [ # # ]: 0 : if (!attr->tcp)
207 : 0 : attr->udp = 1;
208 : : break;
209 : 0 : case RTE_FLOW_ITEM_TYPE_TCP:
210 [ # # ]: 0 : if (!attr->udp)
211 : 0 : attr->tcp = 1;
212 : : break;
213 : : default:
214 : : break;
215 : : }
216 : : }
217 : 0 : attr->valid = 1;
218 : : }
219 : :
220 : : static struct field_modify_info modify_eth[] = {
221 : : {4, 0, MLX5_MODI_OUT_DMAC_47_16},
222 : : {2, 4, MLX5_MODI_OUT_DMAC_15_0},
223 : : {4, 6, MLX5_MODI_OUT_SMAC_47_16},
224 : : {2, 10, MLX5_MODI_OUT_SMAC_15_0},
225 : : {0, 0, 0},
226 : : };
227 : :
228 : : static struct field_modify_info modify_vlan_out_first_vid[] = {
229 : : /* Size in bits !!! */
230 : : {12, 0, MLX5_MODI_OUT_FIRST_VID},
231 : : {0, 0, 0},
232 : : };
233 : :
234 : : static struct field_modify_info modify_ipv4[] = {
235 : : {1, 1, MLX5_MODI_OUT_IP_DSCP},
236 : : {1, 8, MLX5_MODI_OUT_IPV4_TTL},
237 : : {4, 12, MLX5_MODI_OUT_SIPV4},
238 : : {4, 16, MLX5_MODI_OUT_DIPV4},
239 : : {0, 0, 0},
240 : : };
241 : :
242 : : static struct field_modify_info modify_ipv6[] = {
243 : : {1, 0, MLX5_MODI_OUT_IP_DSCP},
244 : : {1, 7, MLX5_MODI_OUT_IPV6_HOPLIMIT},
245 : : {4, 8, MLX5_MODI_OUT_SIPV6_127_96},
246 : : {4, 12, MLX5_MODI_OUT_SIPV6_95_64},
247 : : {4, 16, MLX5_MODI_OUT_SIPV6_63_32},
248 : : {4, 20, MLX5_MODI_OUT_SIPV6_31_0},
249 : : {4, 24, MLX5_MODI_OUT_DIPV6_127_96},
250 : : {4, 28, MLX5_MODI_OUT_DIPV6_95_64},
251 : : {4, 32, MLX5_MODI_OUT_DIPV6_63_32},
252 : : {4, 36, MLX5_MODI_OUT_DIPV6_31_0},
253 : : {0, 0, 0},
254 : : };
255 : :
256 : : static struct field_modify_info modify_ipv6_traffic_class[] = {
257 : : {1, 0, MLX5_MODI_OUT_IPV6_TRAFFIC_CLASS},
258 : : {0, 0, 0},
259 : : };
260 : :
261 : : static struct field_modify_info modify_udp[] = {
262 : : {2, 0, MLX5_MODI_OUT_UDP_SPORT},
263 : : {2, 2, MLX5_MODI_OUT_UDP_DPORT},
264 : : {0, 0, 0},
265 : : };
266 : :
267 : : static struct field_modify_info modify_tcp[] = {
268 : : {2, 0, MLX5_MODI_OUT_TCP_SPORT},
269 : : {2, 2, MLX5_MODI_OUT_TCP_DPORT},
270 : : {4, 4, MLX5_MODI_OUT_TCP_SEQ_NUM},
271 : : {4, 8, MLX5_MODI_OUT_TCP_ACK_NUM},
272 : : {0, 0, 0},
273 : : };
274 : :
275 : : enum mlx5_l3_tunnel_detection {
276 : : l3_tunnel_none,
277 : : l3_tunnel_outer,
278 : : l3_tunnel_inner
279 : : };
280 : :
281 : : static enum mlx5_l3_tunnel_detection
282 : : mlx5_flow_tunnel_ip_check(const struct rte_flow_item *item __rte_unused,
283 : : uint8_t next_protocol, uint64_t item_flags,
284 : : uint64_t *l3_tunnel_flag)
285 : : {
286 : : enum mlx5_l3_tunnel_detection td = l3_tunnel_none;
287 : :
288 : : MLX5_ASSERT(item->type == RTE_FLOW_ITEM_TYPE_IPV4 ||
289 : : item->type == RTE_FLOW_ITEM_TYPE_IPV6);
290 [ # # # # : 0 : if ((item_flags & MLX5_FLOW_LAYER_OUTER_L3) == 0) {
# # # # ]
291 [ # # # # : 0 : switch (next_protocol) {
# # # # #
# # # ]
292 : : case IPPROTO_IPIP:
293 : : td = l3_tunnel_outer;
294 : : *l3_tunnel_flag = MLX5_FLOW_LAYER_IPIP;
295 : : break;
296 : : case IPPROTO_IPV6:
297 : : td = l3_tunnel_outer;
298 : : *l3_tunnel_flag = MLX5_FLOW_LAYER_IPV6_ENCAP;
299 : : break;
300 : : default:
301 : : break;
302 : : }
303 : : } else {
304 : : td = l3_tunnel_inner;
305 : : *l3_tunnel_flag = item->type == RTE_FLOW_ITEM_TYPE_IPV4 ?
306 : : MLX5_FLOW_LAYER_IPIP :
307 : : MLX5_FLOW_LAYER_IPV6_ENCAP;
308 : : }
309 : : return td;
310 : : }
311 : :
312 : : static inline struct mlx5_hlist *
313 : 0 : flow_dv_hlist_prepare(struct mlx5_dev_ctx_shared *sh, RTE_ATOMIC(struct mlx5_hlist *) *phl,
314 : : const char *name, uint32_t size, bool direct_key,
315 : : bool lcores_share, void *ctx,
316 : : mlx5_list_create_cb cb_create,
317 : : mlx5_list_match_cb cb_match,
318 : : mlx5_list_remove_cb cb_remove,
319 : : mlx5_list_clone_cb cb_clone,
320 : : mlx5_list_clone_free_cb cb_clone_free,
321 : : struct rte_flow_error *error)
322 : : {
323 : : struct mlx5_hlist *hl;
324 : : struct mlx5_hlist *expected = NULL;
325 : : char s[MLX5_NAME_SIZE];
326 : :
327 : 0 : hl = rte_atomic_load_explicit(phl, rte_memory_order_seq_cst);
328 [ # # ]: 0 : if (likely(hl))
329 : : return hl;
330 : 0 : snprintf(s, sizeof(s), "%s_%s", sh->ibdev_name, name);
331 : 0 : hl = mlx5_hlist_create(s, size, direct_key, lcores_share,
332 : : ctx, cb_create, cb_match, cb_remove, cb_clone,
333 : : cb_clone_free);
334 [ # # ]: 0 : if (!hl) {
335 : 0 : DRV_LOG(ERR, "%s hash creation failed", name);
336 : 0 : rte_flow_error_set(error, ENOMEM,
337 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
338 : : "cannot allocate resource memory");
339 : 0 : return NULL;
340 : : }
341 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(phl, &expected, hl,
342 : : rte_memory_order_seq_cst,
343 : : rte_memory_order_seq_cst)) {
344 : 0 : mlx5_hlist_destroy(hl);
345 : 0 : hl = rte_atomic_load_explicit(phl, rte_memory_order_seq_cst);
346 : : }
347 : : return hl;
348 : : }
349 : :
350 : : /* Update VLAN's VID/PCP based on input rte_flow_action.
351 : : *
352 : : * @param[in] action
353 : : * Pointer to struct rte_flow_action.
354 : : * @param[out] vlan
355 : : * Pointer to struct rte_vlan_hdr.
356 : : */
357 : : static void
358 : 0 : mlx5_update_vlan_vid_pcp(const struct rte_flow_action *action,
359 : : struct rte_vlan_hdr *vlan)
360 : : {
361 : : uint16_t vlan_tci;
362 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP) {
363 : 0 : vlan_tci =
364 : : ((const struct rte_flow_action_of_set_vlan_pcp *)
365 : 0 : action->conf)->vlan_pcp;
366 : 0 : vlan_tci = vlan_tci << MLX5DV_FLOW_VLAN_PCP_SHIFT;
367 : 0 : vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
368 : 0 : vlan->vlan_tci |= vlan_tci;
369 [ # # ]: 0 : } else if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID) {
370 : 0 : vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
371 [ # # ]: 0 : vlan->vlan_tci |= rte_be_to_cpu_16
372 : : (((const struct rte_flow_action_of_set_vlan_vid *)
373 : : action->conf)->vlan_vid);
374 : : }
375 : 0 : }
376 : :
377 : : /**
378 : : * Convert modify-header action to DV specification.
379 : : *
380 : : * Data length of each action is determined by provided field description
381 : : * and the item mask. Data bit offset and width of each action is determined
382 : : * by provided item mask.
383 : : *
384 : : * @param[in] item
385 : : * Pointer to item specification.
386 : : * @param[in] field
387 : : * Pointer to field modification information.
388 : : * For MLX5_MODIFICATION_TYPE_SET specifies destination field.
389 : : * For MLX5_MODIFICATION_TYPE_ADD specifies destination field.
390 : : * For MLX5_MODIFICATION_TYPE_COPY specifies source field.
391 : : * For MLX5_MODIFICATION_TYPE_ADD_FIELD specifies source field.
392 : : * @param[in] dest
393 : : * Destination field info for MLX5_MODIFICATION_TYPE_COPY and
394 : : * MLX5_MODIFICATION_TYPE_ADD_FIELD in @type.
395 : : * Negative offset value sets the same offset as source offset.
396 : : * size field is ignored, value is taken from source field.
397 : : * @param[in,out] resource
398 : : * Pointer to the modify-header resource.
399 : : * @param[in] type
400 : : * Type of modification.
401 : : * @param[out] error
402 : : * Pointer to the error structure.
403 : : *
404 : : * @return
405 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
406 : : */
407 : : int
408 : 0 : mlx5_flow_dv_convert_modify_action(struct rte_flow_item *item,
409 : : struct field_modify_info *field,
410 : : struct field_modify_info *dest,
411 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
412 : : uint32_t type, struct rte_flow_error *error)
413 : : {
414 : 0 : uint32_t i = resource->actions_num;
415 : 0 : struct mlx5_modification_cmd *actions = resource->actions;
416 : : uint32_t carry_b = 0;
417 : : bool to_dest;
418 : :
419 : : /*
420 : : * The item and mask are provided in big-endian format.
421 : : * The fields should be presented as in big-endian format either.
422 : : * Mask must be always present, it defines the actual field width.
423 : : */
424 : : MLX5_ASSERT(item->mask);
425 : : MLX5_ASSERT(field->size);
426 : 0 : to_dest = type == MLX5_MODIFICATION_TYPE_COPY ||
427 : 0 : type == MLX5_MODIFICATION_TYPE_ADD_FIELD;
428 : : do {
429 : : uint32_t size_b;
430 : : uint32_t off_b;
431 : : uint32_t mask;
432 : : uint32_t data;
433 : : bool next_field = true;
434 : : bool next_dest = true;
435 : :
436 [ # # ]: 0 : if (i >= MLX5_MAX_MODIFY_NUM)
437 : 0 : return rte_flow_error_set(error, EINVAL,
438 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
439 : : "too many items to modify");
440 : : /* Fetch variable byte size mask from the array. */
441 : 0 : mask = flow_dv_fetch_field((const uint8_t *)item->mask +
442 : 0 : field->offset, field->size);
443 [ # # ]: 0 : if (!mask) {
444 : 0 : ++field;
445 : : continue;
446 : : }
447 [ # # # # ]: 0 : if (to_dest && field->is_flex) {
448 : 0 : off_b = 32 - field->shift + carry_b - field->size * CHAR_BIT;
449 : 0 : size_b = field->size * CHAR_BIT - carry_b;
450 : : } else {
451 : : /* Deduce actual data width in bits from mask value. */
452 : 0 : off_b = rte_bsf32(mask) + carry_b;
453 : 0 : size_b = sizeof(uint32_t) * CHAR_BIT -
454 : 0 : off_b - rte_clz32(mask);
455 : : }
456 : : MLX5_ASSERT(size_b);
457 : 0 : actions[i] = (struct mlx5_modification_cmd) {
458 : : .action_type = type,
459 : 0 : .field = field->id,
460 : : .offset = off_b,
461 : : .length = (size_b == sizeof(uint32_t) * CHAR_BIT) ?
462 [ # # ]: 0 : 0 : size_b,
463 : : };
464 [ # # ]: 0 : if (to_dest) {
465 : : MLX5_ASSERT(dest);
466 : 0 : actions[i].dst_field = dest->id;
467 : 0 : actions[i].dst_offset =
468 [ # # ]: 0 : (int)dest->offset < 0 ? off_b : dest->offset;
469 : : /* Convert entire record to big-endian format. */
470 [ # # ]: 0 : actions[i].data1 = rte_cpu_to_be_32(actions[i].data1);
471 : : /*
472 : : * Destination field overflow. Copy leftovers of
473 : : * a source field to the next destination field.
474 : : */
475 [ # # # # ]: 0 : if ((size_b > dest->size * CHAR_BIT - dest->offset) &&
476 : : dest->size != 0) {
477 : 0 : actions[i].length =
478 : 0 : dest->size * CHAR_BIT - dest->offset;
479 : 0 : carry_b += actions[i].length;
480 : 0 : next_field = false;
481 : : } else {
482 : : carry_b = 0;
483 : : }
484 : : /*
485 : : * Not enough bits in a source filed to fill a
486 : : * destination field. Switch to the next source.
487 : : */
488 [ # # ]: 0 : if ((size_b < dest->size * CHAR_BIT - dest->offset) &&
489 [ # # ]: 0 : ((size_b == field->size * CHAR_BIT - off_b) ||
490 [ # # ]: 0 : field->is_flex)) {
491 : 0 : actions[i].length = size_b;
492 : 0 : dest->offset += actions[i].length;
493 : : next_dest = false;
494 : : }
495 : : } else {
496 : : MLX5_ASSERT(item->spec);
497 : 0 : data = flow_dv_fetch_field((const uint8_t *)item->spec +
498 : : field->offset, field->size);
499 : : /* Shift out the trailing masked bits from data. */
500 : 0 : data = (data & mask) >> off_b;
501 [ # # ]: 0 : if (field->is_flex)
502 : 0 : actions[i].offset = 32 - field->shift - field->size * CHAR_BIT;
503 [ # # ]: 0 : actions[i].data1 = rte_cpu_to_be_32(data);
504 : : }
505 : : /* Convert entire record to expected big-endian format. */
506 [ # # ]: 0 : actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
507 [ # # ]: 0 : if ((!to_dest ||
508 [ # # # # ]: 0 : dest->id != (enum mlx5_modification_field)UINT32_MAX) &&
509 : : field->id != (enum mlx5_modification_field)UINT32_MAX)
510 : 0 : ++i;
511 [ # # ]: 0 : if (next_dest && to_dest)
512 : 0 : ++dest;
513 [ # # ]: 0 : if (next_field)
514 : 0 : ++field;
515 [ # # ]: 0 : } while (field->size);
516 [ # # ]: 0 : if (resource->actions_num == i)
517 : 0 : return rte_flow_error_set(error, EINVAL,
518 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
519 : : "invalid modification flow item");
520 : 0 : resource->actions_num = i;
521 : 0 : return 0;
522 : : }
523 : :
524 : : /**
525 : : * Convert modify-header set IPv4 address action to DV specification.
526 : : *
527 : : * @param[in,out] resource
528 : : * Pointer to the modify-header resource.
529 : : * @param[in] action
530 : : * Pointer to action specification.
531 : : * @param[out] error
532 : : * Pointer to the error structure.
533 : : *
534 : : * @return
535 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
536 : : */
537 : : static int
538 : 0 : flow_dv_convert_action_modify_ipv4
539 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
540 : : const struct rte_flow_action *action,
541 : : struct rte_flow_error *error)
542 : : {
543 : 0 : const struct rte_flow_action_set_ipv4 *conf =
544 : : (const struct rte_flow_action_set_ipv4 *)(action->conf);
545 [ # # ]: 0 : struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
546 : : struct rte_flow_item_ipv4 ipv4;
547 : : struct rte_flow_item_ipv4 ipv4_mask;
548 : :
549 : : memset(&ipv4, 0, sizeof(ipv4));
550 : : memset(&ipv4_mask, 0, sizeof(ipv4_mask));
551 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC) {
552 : 0 : ipv4.hdr.src_addr = conf->ipv4_addr;
553 : 0 : ipv4_mask.hdr.src_addr = rte_flow_item_ipv4_mask.hdr.src_addr;
554 : : } else {
555 : 0 : ipv4.hdr.dst_addr = conf->ipv4_addr;
556 : 0 : ipv4_mask.hdr.dst_addr = rte_flow_item_ipv4_mask.hdr.dst_addr;
557 : : }
558 : 0 : item.spec = &ipv4;
559 : 0 : item.mask = &ipv4_mask;
560 : 0 : return mlx5_flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
561 : : MLX5_MODIFICATION_TYPE_SET, error);
562 : : }
563 : :
564 : : /**
565 : : * Convert modify-header set IPv6 address action to DV specification.
566 : : *
567 : : * @param[in,out] resource
568 : : * Pointer to the modify-header resource.
569 : : * @param[in] action
570 : : * Pointer to action specification.
571 : : * @param[out] error
572 : : * Pointer to the error structure.
573 : : *
574 : : * @return
575 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
576 : : */
577 : : static int
578 : 0 : flow_dv_convert_action_modify_ipv6
579 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
580 : : const struct rte_flow_action *action,
581 : : struct rte_flow_error *error)
582 : : {
583 : 0 : const struct rte_flow_action_set_ipv6 *conf =
584 : : (const struct rte_flow_action_set_ipv6 *)(action->conf);
585 [ # # ]: 0 : struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
586 : : struct rte_flow_item_ipv6 ipv6;
587 : : struct rte_flow_item_ipv6 ipv6_mask;
588 : :
589 : : memset(&ipv6, 0, sizeof(ipv6));
590 : : memset(&ipv6_mask, 0, sizeof(ipv6_mask));
591 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC) {
592 : : memcpy(&ipv6.hdr.src_addr, &conf->ipv6_addr,
593 : : sizeof(ipv6.hdr.src_addr));
594 : : memcpy(&ipv6_mask.hdr.src_addr,
595 : : &rte_flow_item_ipv6_mask.hdr.src_addr,
596 : : sizeof(ipv6.hdr.src_addr));
597 : : } else {
598 : : memcpy(&ipv6.hdr.dst_addr, &conf->ipv6_addr,
599 : : sizeof(ipv6.hdr.dst_addr));
600 : : memcpy(&ipv6_mask.hdr.dst_addr,
601 : : &rte_flow_item_ipv6_mask.hdr.dst_addr,
602 : : sizeof(ipv6.hdr.dst_addr));
603 : : }
604 : 0 : item.spec = &ipv6;
605 : 0 : item.mask = &ipv6_mask;
606 : 0 : return mlx5_flow_dv_convert_modify_action(&item, modify_ipv6, NULL, resource,
607 : : MLX5_MODIFICATION_TYPE_SET, error);
608 : : }
609 : :
610 : : /**
611 : : * Convert modify-header set MAC address action to DV specification.
612 : : *
613 : : * @param[in,out] resource
614 : : * Pointer to the modify-header resource.
615 : : * @param[in] action
616 : : * Pointer to action specification.
617 : : * @param[out] error
618 : : * Pointer to the error structure.
619 : : *
620 : : * @return
621 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
622 : : */
623 : : static int
624 : 0 : flow_dv_convert_action_modify_mac
625 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
626 : : const struct rte_flow_action *action,
627 : : struct rte_flow_error *error)
628 : : {
629 : 0 : const struct rte_flow_action_set_mac *conf =
630 : : (const struct rte_flow_action_set_mac *)(action->conf);
631 [ # # ]: 0 : struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_ETH };
632 : : struct rte_flow_item_eth eth;
633 : : struct rte_flow_item_eth eth_mask;
634 : :
635 : : memset(ð, 0, sizeof(eth));
636 : : memset(ð_mask, 0, sizeof(eth_mask));
637 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_SET_MAC_SRC) {
638 : : memcpy(ð.hdr.src_addr.addr_bytes, &conf->mac_addr,
639 : : sizeof(eth.hdr.src_addr.addr_bytes));
640 : : memcpy(ð_mask.hdr.src_addr.addr_bytes,
641 : : &rte_flow_item_eth_mask.hdr.src_addr.addr_bytes,
642 : : sizeof(eth_mask.hdr.src_addr.addr_bytes));
643 : : } else {
644 : : memcpy(ð.hdr.dst_addr.addr_bytes, &conf->mac_addr,
645 : : sizeof(eth.hdr.dst_addr.addr_bytes));
646 : : memcpy(ð_mask.hdr.dst_addr.addr_bytes,
647 : : &rte_flow_item_eth_mask.hdr.dst_addr.addr_bytes,
648 : : sizeof(eth_mask.hdr.dst_addr.addr_bytes));
649 : : }
650 : 0 : item.spec = ð
651 : 0 : item.mask = ð_mask;
652 : 0 : return mlx5_flow_dv_convert_modify_action(&item, modify_eth, NULL, resource,
653 : : MLX5_MODIFICATION_TYPE_SET, error);
654 : : }
655 : :
656 : : /**
657 : : * Convert modify-header set VLAN VID action to DV specification.
658 : : *
659 : : * @param[in,out] resource
660 : : * Pointer to the modify-header resource.
661 : : * @param[in] action
662 : : * Pointer to action specification.
663 : : * @param[out] error
664 : : * Pointer to the error structure.
665 : : *
666 : : * @return
667 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
668 : : */
669 : : static int
670 : 0 : flow_dv_convert_action_modify_vlan_vid
671 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
672 : : const struct rte_flow_action *action,
673 : : struct rte_flow_error *error)
674 : : {
675 : 0 : const struct rte_flow_action_of_set_vlan_vid *conf =
676 : : (const struct rte_flow_action_of_set_vlan_vid *)(action->conf);
677 : 0 : int i = resource->actions_num;
678 : 0 : struct mlx5_modification_cmd *actions = resource->actions;
679 : : struct field_modify_info *field = modify_vlan_out_first_vid;
680 : :
681 [ # # ]: 0 : if (i >= MLX5_MAX_MODIFY_NUM)
682 : 0 : return rte_flow_error_set(error, EINVAL,
683 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
684 : : "too many items to modify");
685 : 0 : actions[i] = (struct mlx5_modification_cmd) {
686 : : .action_type = MLX5_MODIFICATION_TYPE_SET,
687 : 0 : .field = field->id,
688 : 0 : .length = field->size,
689 : 0 : .offset = field->offset,
690 : : };
691 [ # # ]: 0 : actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
692 : 0 : actions[i].data1 = conf->vlan_vid;
693 : 0 : actions[i].data1 = actions[i].data1 << 16;
694 : 0 : resource->actions_num = ++i;
695 : 0 : return 0;
696 : : }
697 : :
698 : : /**
699 : : * Convert modify-header set TP action to DV specification.
700 : : *
701 : : * @param[in,out] resource
702 : : * Pointer to the modify-header resource.
703 : : * @param[in] action
704 : : * Pointer to action specification.
705 : : * @param[in] items
706 : : * Pointer to rte_flow_item objects list.
707 : : * @param[in] attr
708 : : * Pointer to flow attributes structure.
709 : : * @param[in] dev_flow
710 : : * Pointer to the sub flow.
711 : : * @param[in] tunnel_decap
712 : : * Whether action is after tunnel decapsulation.
713 : : * @param[out] error
714 : : * Pointer to the error structure.
715 : : *
716 : : * @return
717 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
718 : : */
719 : : static int
720 : 0 : flow_dv_convert_action_modify_tp
721 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
722 : : const struct rte_flow_action *action,
723 : : const struct rte_flow_item *items,
724 : : union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
725 : : bool tunnel_decap, struct rte_flow_error *error)
726 : : {
727 : 0 : const struct rte_flow_action_set_tp *conf =
728 : : (const struct rte_flow_action_set_tp *)(action->conf);
729 : : struct rte_flow_item item;
730 : : struct rte_flow_item_udp udp;
731 : : struct rte_flow_item_udp udp_mask;
732 : : struct rte_flow_item_tcp tcp;
733 : : struct rte_flow_item_tcp tcp_mask;
734 : : struct field_modify_info *field;
735 : :
736 [ # # ]: 0 : if (!attr->valid)
737 : 0 : flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
738 [ # # ]: 0 : if (attr->udp) {
739 : : memset(&udp, 0, sizeof(udp));
740 : : memset(&udp_mask, 0, sizeof(udp_mask));
741 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
742 : 0 : udp.hdr.src_port = conf->port;
743 : 0 : udp_mask.hdr.src_port =
744 : : rte_flow_item_udp_mask.hdr.src_port;
745 : : } else {
746 : 0 : udp.hdr.dst_port = conf->port;
747 : 0 : udp_mask.hdr.dst_port =
748 : : rte_flow_item_udp_mask.hdr.dst_port;
749 : : }
750 : 0 : item.type = RTE_FLOW_ITEM_TYPE_UDP;
751 : 0 : item.spec = &udp;
752 : 0 : item.mask = &udp_mask;
753 : : field = modify_udp;
754 : : } else {
755 : : MLX5_ASSERT(attr->tcp);
756 : : memset(&tcp, 0, sizeof(tcp));
757 : : memset(&tcp_mask, 0, sizeof(tcp_mask));
758 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
759 : 0 : tcp.hdr.src_port = conf->port;
760 : 0 : tcp_mask.hdr.src_port =
761 : : rte_flow_item_tcp_mask.hdr.src_port;
762 : : } else {
763 : 0 : tcp.hdr.dst_port = conf->port;
764 : 0 : tcp_mask.hdr.dst_port =
765 : : rte_flow_item_tcp_mask.hdr.dst_port;
766 : : }
767 : 0 : item.type = RTE_FLOW_ITEM_TYPE_TCP;
768 : 0 : item.spec = &tcp;
769 : 0 : item.mask = &tcp_mask;
770 : : field = modify_tcp;
771 : : }
772 : 0 : return mlx5_flow_dv_convert_modify_action(&item, field, NULL, resource,
773 : : MLX5_MODIFICATION_TYPE_SET, error);
774 : : }
775 : :
776 : : /**
777 : : * Convert modify-header set TTL action to DV specification.
778 : : *
779 : : * @param[in,out] resource
780 : : * Pointer to the modify-header resource.
781 : : * @param[in] action
782 : : * Pointer to action specification.
783 : : * @param[in] items
784 : : * Pointer to rte_flow_item objects list.
785 : : * @param[in] attr
786 : : * Pointer to flow attributes structure.
787 : : * @param[in] dev_flow
788 : : * Pointer to the sub flow.
789 : : * @param[in] tunnel_decap
790 : : * Whether action is after tunnel decapsulation.
791 : : * @param[out] error
792 : : * Pointer to the error structure.
793 : : *
794 : : * @return
795 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
796 : : */
797 : : static int
798 : 0 : flow_dv_convert_action_modify_ttl
799 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
800 : : const struct rte_flow_action *action,
801 : : const struct rte_flow_item *items,
802 : : union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
803 : : bool tunnel_decap, struct rte_flow_error *error)
804 : : {
805 : 0 : const struct rte_flow_action_set_ttl *conf =
806 : : (const struct rte_flow_action_set_ttl *)(action->conf);
807 : : struct rte_flow_item item;
808 : : struct rte_flow_item_ipv4 ipv4;
809 : : struct rte_flow_item_ipv4 ipv4_mask;
810 : : struct rte_flow_item_ipv6 ipv6;
811 : : struct rte_flow_item_ipv6 ipv6_mask;
812 : : struct field_modify_info *field;
813 : :
814 [ # # ]: 0 : if (!attr->valid)
815 : 0 : flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
816 [ # # ]: 0 : if (attr->ipv4) {
817 : : memset(&ipv4, 0, sizeof(ipv4));
818 : : memset(&ipv4_mask, 0, sizeof(ipv4_mask));
819 : 0 : ipv4.hdr.time_to_live = conf->ttl_value;
820 : 0 : ipv4_mask.hdr.time_to_live = 0xFF;
821 : 0 : item.type = RTE_FLOW_ITEM_TYPE_IPV4;
822 : 0 : item.spec = &ipv4;
823 : 0 : item.mask = &ipv4_mask;
824 : : field = modify_ipv4;
825 : : } else {
826 : : MLX5_ASSERT(attr->ipv6);
827 : : memset(&ipv6, 0, sizeof(ipv6));
828 : : memset(&ipv6_mask, 0, sizeof(ipv6_mask));
829 : 0 : ipv6.hdr.hop_limits = conf->ttl_value;
830 : 0 : ipv6_mask.hdr.hop_limits = 0xFF;
831 : 0 : item.type = RTE_FLOW_ITEM_TYPE_IPV6;
832 : 0 : item.spec = &ipv6;
833 : 0 : item.mask = &ipv6_mask;
834 : : field = modify_ipv6;
835 : : }
836 : 0 : return mlx5_flow_dv_convert_modify_action(&item, field, NULL, resource,
837 : : MLX5_MODIFICATION_TYPE_SET, error);
838 : : }
839 : :
840 : : /**
841 : : * Convert modify-header decrement TTL action to DV specification.
842 : : *
843 : : * @param[in,out] resource
844 : : * Pointer to the modify-header resource.
845 : : * @param[in] action
846 : : * Pointer to action specification.
847 : : * @param[in] items
848 : : * Pointer to rte_flow_item objects list.
849 : : * @param[in] attr
850 : : * Pointer to flow attributes structure.
851 : : * @param[in] dev_flow
852 : : * Pointer to the sub flow.
853 : : * @param[in] tunnel_decap
854 : : * Whether action is after tunnel decapsulation.
855 : : * @param[out] error
856 : : * Pointer to the error structure.
857 : : *
858 : : * @return
859 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
860 : : */
861 : : static int
862 : 0 : flow_dv_convert_action_modify_dec_ttl
863 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
864 : : const struct rte_flow_item *items,
865 : : union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
866 : : bool tunnel_decap, struct rte_flow_error *error)
867 : : {
868 : : struct rte_flow_item item;
869 : : struct rte_flow_item_ipv4 ipv4;
870 : : struct rte_flow_item_ipv4 ipv4_mask;
871 : : struct rte_flow_item_ipv6 ipv6;
872 : : struct rte_flow_item_ipv6 ipv6_mask;
873 : : struct field_modify_info *field;
874 : :
875 [ # # ]: 0 : if (!attr->valid)
876 : 0 : flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
877 [ # # ]: 0 : if (attr->ipv4) {
878 : : memset(&ipv4, 0, sizeof(ipv4));
879 : : memset(&ipv4_mask, 0, sizeof(ipv4_mask));
880 : 0 : ipv4.hdr.time_to_live = 0xFF;
881 : 0 : ipv4_mask.hdr.time_to_live = 0xFF;
882 : 0 : item.type = RTE_FLOW_ITEM_TYPE_IPV4;
883 : 0 : item.spec = &ipv4;
884 : 0 : item.mask = &ipv4_mask;
885 : : field = modify_ipv4;
886 : : } else {
887 : : MLX5_ASSERT(attr->ipv6);
888 : : memset(&ipv6, 0, sizeof(ipv6));
889 : : memset(&ipv6_mask, 0, sizeof(ipv6_mask));
890 : 0 : ipv6.hdr.hop_limits = 0xFF;
891 : 0 : ipv6_mask.hdr.hop_limits = 0xFF;
892 : 0 : item.type = RTE_FLOW_ITEM_TYPE_IPV6;
893 : 0 : item.spec = &ipv6;
894 : 0 : item.mask = &ipv6_mask;
895 : : field = modify_ipv6;
896 : : }
897 : 0 : return mlx5_flow_dv_convert_modify_action(&item, field, NULL, resource,
898 : : MLX5_MODIFICATION_TYPE_ADD, error);
899 : : }
900 : :
901 : : /**
902 : : * Convert modify-header increment/decrement TCP Sequence number
903 : : * to DV specification.
904 : : *
905 : : * @param[in,out] resource
906 : : * Pointer to the modify-header resource.
907 : : * @param[in] action
908 : : * Pointer to action specification.
909 : : * @param[out] error
910 : : * Pointer to the error structure.
911 : : *
912 : : * @return
913 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
914 : : */
915 : : static int
916 : 0 : flow_dv_convert_action_modify_tcp_seq
917 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
918 : : const struct rte_flow_action *action,
919 : : struct rte_flow_error *error)
920 : : {
921 : 0 : const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
922 [ # # ]: 0 : uint64_t value = rte_be_to_cpu_32(*conf);
923 : : struct rte_flow_item item;
924 : : struct rte_flow_item_tcp tcp;
925 : : struct rte_flow_item_tcp tcp_mask;
926 : :
927 : : memset(&tcp, 0, sizeof(tcp));
928 : : memset(&tcp_mask, 0, sizeof(tcp_mask));
929 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ)
930 : : /*
931 : : * The HW has no decrement operation, only increment operation.
932 : : * To simulate decrement X from Y using increment operation
933 : : * we need to add UINT32_MAX X times to Y.
934 : : * Each adding of UINT32_MAX decrements Y by 1.
935 : : */
936 : 0 : value *= UINT32_MAX;
937 [ # # ]: 0 : tcp.hdr.sent_seq = rte_cpu_to_be_32((uint32_t)value);
938 : 0 : tcp_mask.hdr.sent_seq = RTE_BE32(UINT32_MAX);
939 : 0 : item.type = RTE_FLOW_ITEM_TYPE_TCP;
940 : 0 : item.spec = &tcp;
941 : 0 : item.mask = &tcp_mask;
942 : 0 : return mlx5_flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
943 : : MLX5_MODIFICATION_TYPE_ADD, error);
944 : : }
945 : :
946 : : /**
947 : : * Convert modify-header increment/decrement TCP Acknowledgment number
948 : : * to DV specification.
949 : : *
950 : : * @param[in,out] resource
951 : : * Pointer to the modify-header resource.
952 : : * @param[in] action
953 : : * Pointer to action specification.
954 : : * @param[out] error
955 : : * Pointer to the error structure.
956 : : *
957 : : * @return
958 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
959 : : */
960 : : static int
961 : 0 : flow_dv_convert_action_modify_tcp_ack
962 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
963 : : const struct rte_flow_action *action,
964 : : struct rte_flow_error *error)
965 : : {
966 : 0 : const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
967 [ # # ]: 0 : uint64_t value = rte_be_to_cpu_32(*conf);
968 : : struct rte_flow_item item;
969 : : struct rte_flow_item_tcp tcp;
970 : : struct rte_flow_item_tcp tcp_mask;
971 : :
972 : : memset(&tcp, 0, sizeof(tcp));
973 : : memset(&tcp_mask, 0, sizeof(tcp_mask));
974 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK)
975 : : /*
976 : : * The HW has no decrement operation, only increment operation.
977 : : * To simulate decrement X from Y using increment operation
978 : : * we need to add UINT32_MAX X times to Y.
979 : : * Each adding of UINT32_MAX decrements Y by 1.
980 : : */
981 : 0 : value *= UINT32_MAX;
982 [ # # ]: 0 : tcp.hdr.recv_ack = rte_cpu_to_be_32((uint32_t)value);
983 : 0 : tcp_mask.hdr.recv_ack = RTE_BE32(UINT32_MAX);
984 : 0 : item.type = RTE_FLOW_ITEM_TYPE_TCP;
985 : 0 : item.spec = &tcp;
986 : 0 : item.mask = &tcp_mask;
987 : 0 : return mlx5_flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
988 : : MLX5_MODIFICATION_TYPE_ADD, error);
989 : : }
990 : :
991 : : enum mlx5_modification_field mlx5_reg_to_field[] = {
992 : : [REG_NON] = MLX5_MODI_OUT_NONE,
993 : : [REG_A] = MLX5_MODI_META_DATA_REG_A,
994 : : [REG_B] = MLX5_MODI_META_DATA_REG_B,
995 : : [REG_C_0] = MLX5_MODI_META_REG_C_0,
996 : : [REG_C_1] = MLX5_MODI_META_REG_C_1,
997 : : [REG_C_2] = MLX5_MODI_META_REG_C_2,
998 : : [REG_C_3] = MLX5_MODI_META_REG_C_3,
999 : : [REG_C_4] = MLX5_MODI_META_REG_C_4,
1000 : : [REG_C_5] = MLX5_MODI_META_REG_C_5,
1001 : : [REG_C_6] = MLX5_MODI_META_REG_C_6,
1002 : : [REG_C_7] = MLX5_MODI_META_REG_C_7,
1003 : : [REG_C_8] = MLX5_MODI_META_REG_C_8,
1004 : : [REG_C_9] = MLX5_MODI_META_REG_C_9,
1005 : : [REG_C_10] = MLX5_MODI_META_REG_C_10,
1006 : : [REG_C_11] = MLX5_MODI_META_REG_C_11,
1007 : : };
1008 : :
1009 : : const size_t mlx5_mod_reg_size = RTE_DIM(mlx5_reg_to_field);
1010 : :
1011 : : /**
1012 : : * Convert register set to DV specification.
1013 : : *
1014 : : * @param[in,out] resource
1015 : : * Pointer to the modify-header resource.
1016 : : * @param[in] action
1017 : : * Pointer to action specification.
1018 : : * @param[out] error
1019 : : * Pointer to the error structure.
1020 : : *
1021 : : * @return
1022 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1023 : : */
1024 : : static int
1025 : 0 : flow_dv_convert_action_set_reg
1026 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
1027 : : const struct rte_flow_action *action,
1028 : : struct rte_flow_error *error)
1029 : : {
1030 : 0 : const struct mlx5_rte_flow_action_set_tag *conf = action->conf;
1031 : 0 : struct mlx5_modification_cmd *actions = resource->actions;
1032 : 0 : uint32_t i = resource->actions_num;
1033 : :
1034 [ # # ]: 0 : if (i >= MLX5_MAX_MODIFY_NUM)
1035 : 0 : return rte_flow_error_set(error, EINVAL,
1036 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1037 : : "too many items to modify");
1038 : : MLX5_ASSERT(conf->id != REG_NON);
1039 : : MLX5_ASSERT(conf->id < (enum modify_reg)RTE_DIM(mlx5_reg_to_field));
1040 : 0 : actions[i] = (struct mlx5_modification_cmd) {
1041 : : .action_type = MLX5_MODIFICATION_TYPE_SET,
1042 : 0 : .field = mlx5_reg_to_field[conf->id],
1043 : 0 : .offset = conf->offset,
1044 : 0 : .length = conf->length,
1045 : : };
1046 [ # # ]: 0 : actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
1047 [ # # ]: 0 : actions[i].data1 = rte_cpu_to_be_32(conf->data);
1048 : : ++i;
1049 : 0 : resource->actions_num = i;
1050 : 0 : return 0;
1051 : : }
1052 : :
1053 : : /**
1054 : : * Convert SET_TAG action to DV specification.
1055 : : *
1056 : : * @param[in] dev
1057 : : * Pointer to the rte_eth_dev structure.
1058 : : * @param[in,out] resource
1059 : : * Pointer to the modify-header resource.
1060 : : * @param[in] conf
1061 : : * Pointer to action specification.
1062 : : * @param[out] error
1063 : : * Pointer to the error structure.
1064 : : *
1065 : : * @return
1066 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1067 : : */
1068 : : static int
1069 : 0 : flow_dv_convert_action_set_tag
1070 : : (struct rte_eth_dev *dev,
1071 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
1072 : : const struct rte_flow_action_set_tag *conf,
1073 : : struct rte_flow_error *error)
1074 : : {
1075 [ # # ]: 0 : rte_be32_t data = rte_cpu_to_be_32(conf->data);
1076 [ # # ]: 0 : rte_be32_t mask = rte_cpu_to_be_32(conf->mask);
1077 : 0 : struct rte_flow_item item = {
1078 : : .spec = &data,
1079 : : .mask = &mask,
1080 : : };
1081 : 0 : struct field_modify_info reg_c_x[] = {
1082 : : [1] = {0, 0, 0},
1083 : : };
1084 : : enum mlx5_modification_field reg_type;
1085 : : int ret;
1086 : :
1087 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
1088 [ # # ]: 0 : if (ret < 0)
1089 : : return ret;
1090 : : MLX5_ASSERT(ret != REG_NON);
1091 [ # # ]: 0 : if ((unsigned int)ret >= RTE_DIM(mlx5_reg_to_field))
1092 : 0 : return rte_flow_error_set(error, EINVAL,
1093 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1094 : : NULL, "invalid register index");
1095 : 0 : reg_type = mlx5_reg_to_field[ret];
1096 : : MLX5_ASSERT(reg_type > 0);
1097 : 0 : reg_c_x[0] = (struct field_modify_info){4, 0, reg_type};
1098 : 0 : return mlx5_flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1099 : : MLX5_MODIFICATION_TYPE_SET, error);
1100 : : }
1101 : :
1102 : : /**
1103 : : * Convert internal COPY_REG action to DV specification.
1104 : : *
1105 : : * @param[in] dev
1106 : : * Pointer to the rte_eth_dev structure.
1107 : : * @param[in,out] res
1108 : : * Pointer to the modify-header resource.
1109 : : * @param[in] action
1110 : : * Pointer to action specification.
1111 : : * @param[out] error
1112 : : * Pointer to the error structure.
1113 : : *
1114 : : * @return
1115 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1116 : : */
1117 : : static int
1118 : 0 : flow_dv_convert_action_copy_mreg(struct rte_eth_dev *dev,
1119 : : struct mlx5_flow_dv_modify_hdr_resource *res,
1120 : : const struct rte_flow_action *action,
1121 : : struct rte_flow_error *error)
1122 : : {
1123 : 0 : const struct mlx5_flow_action_copy_mreg *conf = action->conf;
1124 : 0 : rte_be32_t mask = RTE_BE32(UINT32_MAX);
1125 : 0 : struct rte_flow_item item = {
1126 : : .spec = NULL,
1127 : : .mask = &mask,
1128 : : };
1129 : 0 : struct field_modify_info reg_src[] = {
1130 : 0 : {4, 0, mlx5_reg_to_field[conf->src]},
1131 : : {0, 0, 0},
1132 : : };
1133 : 0 : struct field_modify_info reg_dst = {
1134 : : .offset = 0,
1135 : 0 : .id = mlx5_reg_to_field[conf->dst],
1136 : : };
1137 : : /* Adjust reg_c[0] usage according to reported mask. */
1138 [ # # # # ]: 0 : if (conf->dst == REG_C_0 || conf->src == REG_C_0) {
1139 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1140 : 0 : uint32_t reg_c0 = priv->sh->dv_regc0_mask;
1141 : :
1142 : : MLX5_ASSERT(reg_c0);
1143 : : MLX5_ASSERT(priv->sh->config.dv_xmeta_en !=
1144 : : MLX5_XMETA_MODE_LEGACY);
1145 [ # # ]: 0 : if (conf->dst == REG_C_0) {
1146 : : /* Copy to reg_c[0], within mask only. */
1147 : 0 : reg_dst.offset = rte_bsf32(reg_c0);
1148 [ # # ]: 0 : mask = rte_cpu_to_be_32(reg_c0 >> reg_dst.offset);
1149 : : } else {
1150 : : reg_dst.offset = 0;
1151 [ # # ]: 0 : mask = rte_cpu_to_be_32(reg_c0);
1152 : : }
1153 : : }
1154 : 0 : return mlx5_flow_dv_convert_modify_action(&item,
1155 : : reg_src, ®_dst, res,
1156 : : MLX5_MODIFICATION_TYPE_COPY,
1157 : : error);
1158 : : }
1159 : :
1160 : : /**
1161 : : * Convert MARK action to DV specification. This routine is used
1162 : : * in extensive metadata only and requires metadata register to be
1163 : : * handled. In legacy mode hardware tag resource is engaged.
1164 : : *
1165 : : * @param[in] dev
1166 : : * Pointer to the rte_eth_dev structure.
1167 : : * @param[in] conf
1168 : : * Pointer to MARK action specification.
1169 : : * @param[in,out] resource
1170 : : * Pointer to the modify-header resource.
1171 : : * @param[out] error
1172 : : * Pointer to the error structure.
1173 : : *
1174 : : * @return
1175 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1176 : : */
1177 : : static int
1178 : 0 : flow_dv_convert_action_mark(struct rte_eth_dev *dev,
1179 : : const struct rte_flow_action_mark *conf,
1180 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
1181 : : struct rte_flow_error *error)
1182 : : {
1183 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1184 [ # # ]: 0 : rte_be32_t mask = rte_cpu_to_be_32(MLX5_FLOW_MARK_MASK &
1185 : : priv->sh->dv_mark_mask);
1186 [ # # ]: 0 : rte_be32_t data = rte_cpu_to_be_32(conf->id) & mask;
1187 : 0 : struct rte_flow_item item = {
1188 : : .spec = &data,
1189 : : .mask = &mask,
1190 : : };
1191 : 0 : struct field_modify_info reg_c_x[] = {
1192 : : [1] = {0, 0, 0},
1193 : : };
1194 : : int reg;
1195 : :
1196 [ # # ]: 0 : if (!mask)
1197 : 0 : return rte_flow_error_set(error, EINVAL,
1198 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1199 : : NULL, "zero mark action mask");
1200 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1201 [ # # ]: 0 : if (reg < 0)
1202 : : return reg;
1203 : : MLX5_ASSERT(reg > 0);
1204 [ # # ]: 0 : if (reg == REG_C_0) {
1205 [ # # ]: 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1206 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
1207 : :
1208 [ # # ]: 0 : data = rte_cpu_to_be_32(rte_cpu_to_be_32(data) << shl_c0);
1209 [ # # ]: 0 : mask = rte_cpu_to_be_32(mask) & msk_c0;
1210 [ # # ]: 0 : mask = rte_cpu_to_be_32(mask << shl_c0);
1211 : : }
1212 : 0 : reg_c_x[0] = (struct field_modify_info){4, 0, mlx5_reg_to_field[reg]};
1213 : 0 : return mlx5_flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1214 : : MLX5_MODIFICATION_TYPE_SET, error);
1215 : : }
1216 : :
1217 : : /**
1218 : : * Get metadata register index for specified steering domain.
1219 : : *
1220 : : * @param[in] dev
1221 : : * Pointer to the rte_eth_dev structure.
1222 : : * @param[in] attr
1223 : : * Attributes of flow to determine steering domain.
1224 : : * @param[out] error
1225 : : * Pointer to the error structure.
1226 : : *
1227 : : * @return
1228 : : * positive index on success, a negative errno value otherwise
1229 : : * and rte_errno is set.
1230 : : */
1231 : : static enum modify_reg
1232 : 0 : flow_dv_get_metadata_reg(struct rte_eth_dev *dev,
1233 : : const struct rte_flow_attr *attr,
1234 : : struct rte_flow_error *error)
1235 : : {
1236 : : int reg =
1237 [ # # ]: 0 : mlx5_flow_get_reg_id(dev, attr->transfer ?
1238 : 0 : MLX5_METADATA_FDB :
1239 [ # # ]: 0 : attr->egress ?
1240 : : MLX5_METADATA_TX :
1241 : : MLX5_METADATA_RX, 0, error);
1242 [ # # ]: 0 : if (reg < 0)
1243 : 0 : return rte_flow_error_set(error,
1244 : : ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM,
1245 : : NULL, "unavailable "
1246 : : "metadata register");
1247 : 0 : return reg;
1248 : : }
1249 : :
1250 : : /**
1251 : : * Convert SET_META action to DV specification.
1252 : : *
1253 : : * @param[in] dev
1254 : : * Pointer to the rte_eth_dev structure.
1255 : : * @param[in,out] resource
1256 : : * Pointer to the modify-header resource.
1257 : : * @param[in] attr
1258 : : * Attributes of flow that includes this item.
1259 : : * @param[in] conf
1260 : : * Pointer to action specification.
1261 : : * @param[out] error
1262 : : * Pointer to the error structure.
1263 : : *
1264 : : * @return
1265 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1266 : : */
1267 : : static int
1268 : 0 : flow_dv_convert_action_set_meta
1269 : : (struct rte_eth_dev *dev,
1270 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
1271 : : const struct rte_flow_attr *attr,
1272 : : const struct rte_flow_action_set_meta *conf,
1273 : : struct rte_flow_error *error)
1274 : : {
1275 [ # # ]: 0 : uint32_t mask = rte_cpu_to_be_32(conf->mask);
1276 [ # # ]: 0 : uint32_t data = rte_cpu_to_be_32(conf->data) & mask;
1277 : 0 : struct rte_flow_item item = {
1278 : : .spec = &data,
1279 : : .mask = &mask,
1280 : : };
1281 : 0 : struct field_modify_info reg_c_x[] = {
1282 : : [1] = {0, 0, 0},
1283 : : };
1284 : 0 : int reg = flow_dv_get_metadata_reg(dev, attr, error);
1285 : :
1286 [ # # ]: 0 : if (reg < 0)
1287 : : return reg;
1288 : : MLX5_ASSERT(reg != REG_NON);
1289 [ # # ]: 0 : if (reg == REG_C_0) {
1290 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1291 [ # # ]: 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1292 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
1293 : :
1294 [ # # ]: 0 : data = rte_cpu_to_be_32(rte_cpu_to_be_32(data) << shl_c0);
1295 [ # # ]: 0 : mask = rte_cpu_to_be_32(mask) & msk_c0;
1296 [ # # ]: 0 : mask = rte_cpu_to_be_32(mask << shl_c0);
1297 : : }
1298 : 0 : reg_c_x[0] = (struct field_modify_info){4, 0, mlx5_reg_to_field[reg]};
1299 : : /* The routine expects parameters in memory as big-endian ones. */
1300 : 0 : return mlx5_flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1301 : : MLX5_MODIFICATION_TYPE_SET, error);
1302 : : }
1303 : :
1304 : : /**
1305 : : * Convert modify-header set IPv4 DSCP action to DV specification.
1306 : : *
1307 : : * @param[in,out] resource
1308 : : * Pointer to the modify-header resource.
1309 : : * @param[in] action
1310 : : * Pointer to action specification.
1311 : : * @param[out] error
1312 : : * Pointer to the error structure.
1313 : : *
1314 : : * @return
1315 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1316 : : */
1317 : : static int
1318 : 0 : flow_dv_convert_action_modify_ipv4_dscp
1319 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
1320 : : const struct rte_flow_action *action,
1321 : : struct rte_flow_error *error)
1322 : : {
1323 : 0 : const struct rte_flow_action_set_dscp *conf =
1324 : : (const struct rte_flow_action_set_dscp *)(action->conf);
1325 : 0 : struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
1326 : : struct rte_flow_item_ipv4 ipv4;
1327 : : struct rte_flow_item_ipv4 ipv4_mask;
1328 : :
1329 : : memset(&ipv4, 0, sizeof(ipv4));
1330 : : memset(&ipv4_mask, 0, sizeof(ipv4_mask));
1331 : 0 : ipv4.hdr.type_of_service = conf->dscp;
1332 : 0 : ipv4_mask.hdr.type_of_service = RTE_IPV4_HDR_DSCP_MASK >> 2;
1333 : 0 : item.spec = &ipv4;
1334 : 0 : item.mask = &ipv4_mask;
1335 : 0 : return mlx5_flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
1336 : : MLX5_MODIFICATION_TYPE_SET, error);
1337 : : }
1338 : :
1339 : : /**
1340 : : * Convert modify-header set IPv6 DSCP action to DV specification.
1341 : : *
1342 : : * @param[in,out] resource
1343 : : * Pointer to the modify-header resource.
1344 : : * @param[in] action
1345 : : * Pointer to action specification.
1346 : : * @param[out] error
1347 : : * Pointer to the error structure.
1348 : : *
1349 : : * @return
1350 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1351 : : */
1352 : : static int
1353 : 0 : flow_dv_convert_action_modify_ipv6_dscp
1354 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
1355 : : const struct rte_flow_action *action,
1356 : : uint32_t ipv6_tc_off,
1357 : : struct rte_flow_error *error)
1358 : : {
1359 : 0 : const struct rte_flow_action_set_dscp *conf =
1360 : : (const struct rte_flow_action_set_dscp *)(action->conf);
1361 [ # # ]: 0 : struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
1362 : : struct rte_flow_item_ipv6 ipv6;
1363 : : struct rte_flow_item_ipv6 ipv6_mask;
1364 : : struct field_modify_info *modify_info;
1365 : :
1366 : : memset(&ipv6, 0, sizeof(ipv6));
1367 : : memset(&ipv6_mask, 0, sizeof(ipv6_mask));
1368 : : /*
1369 : : * Even though the DSCP bits offset of IPv6 is not byte aligned,
1370 : : * rdma-core only accept the DSCP bits byte aligned start from
1371 : : * bit 0 to 5 as to be compatible with IPv4. No need to shift the
1372 : : * bits in IPv6 case as rdma-core requires byte aligned value.
1373 : : * IPv6 DSCP uses OUT_IPV6_TRAFFIC_CLASS as ID but it starts from 2
1374 : : * bits left. Shift the mask left for IPv6 DSCP. Do it here because
1375 : : * it's needed to distinguish DSCP from ECN in data field construct
1376 : : */
1377 : 0 : ipv6.hdr.vtc_flow = conf->dscp << ipv6_tc_off;
1378 : 0 : ipv6_mask.hdr.vtc_flow = RTE_IPV6_HDR_DSCP_MASK >> (22 - ipv6_tc_off);
1379 : 0 : item.spec = &ipv6;
1380 : 0 : item.mask = &ipv6_mask;
1381 [ # # ]: 0 : if (ipv6_tc_off)
1382 : : modify_info = modify_ipv6_traffic_class;
1383 : : else
1384 : : modify_info = modify_ipv6;
1385 : 0 : return mlx5_flow_dv_convert_modify_action(&item, modify_info, NULL, resource,
1386 : : MLX5_MODIFICATION_TYPE_SET, error);
1387 : : }
1388 : :
1389 : : int
1390 : 0 : mlx5_flow_item_field_width(struct rte_eth_dev *dev,
1391 : : enum rte_flow_field_id field, int inherit,
1392 : : const struct rte_flow_attr *attr,
1393 : : struct rte_flow_error *error)
1394 : : {
1395 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1396 : :
1397 [ # # # # : 0 : switch (field) {
# # # # #
# # # # #
# # # # #
# # # # ]
1398 : : case RTE_FLOW_FIELD_START:
1399 : : return 32;
1400 : 0 : case RTE_FLOW_FIELD_MAC_DST:
1401 : : case RTE_FLOW_FIELD_MAC_SRC:
1402 : 0 : return 48;
1403 : 0 : case RTE_FLOW_FIELD_VLAN_TYPE:
1404 : 0 : return 16;
1405 : 0 : case RTE_FLOW_FIELD_VLAN_ID:
1406 : 0 : return 12;
1407 : 0 : case RTE_FLOW_FIELD_MAC_TYPE:
1408 : 0 : return 16;
1409 : 0 : case RTE_FLOW_FIELD_IPV4_DSCP:
1410 : 0 : return 6;
1411 : 0 : case RTE_FLOW_FIELD_IPV4_TTL:
1412 : : case RTE_FLOW_FIELD_IPV4_PROTO:
1413 : 0 : return 8;
1414 : : case RTE_FLOW_FIELD_IPV4_SRC:
1415 : : case RTE_FLOW_FIELD_IPV4_DST:
1416 : : return 32;
1417 : 0 : case RTE_FLOW_FIELD_IPV6_DSCP:
1418 : 0 : return 6;
1419 : 0 : case RTE_FLOW_FIELD_IPV6_FLOW_LABEL:
1420 : 0 : return 20;
1421 : 0 : case RTE_FLOW_FIELD_IPV6_TRAFFIC_CLASS:
1422 : : case RTE_FLOW_FIELD_IPV6_HOPLIMIT:
1423 : : case RTE_FLOW_FIELD_IPV6_PROTO:
1424 : 0 : return 8;
1425 : 0 : case RTE_FLOW_FIELD_IPV6_SRC:
1426 : : case RTE_FLOW_FIELD_IPV6_DST:
1427 : 0 : return 128;
1428 : 0 : case RTE_FLOW_FIELD_TCP_PORT_SRC:
1429 : : case RTE_FLOW_FIELD_TCP_PORT_DST:
1430 : 0 : return 16;
1431 : : case RTE_FLOW_FIELD_TCP_SEQ_NUM:
1432 : : case RTE_FLOW_FIELD_TCP_ACK_NUM:
1433 : : return 32;
1434 : 0 : case RTE_FLOW_FIELD_TCP_FLAGS:
1435 : 0 : return 9;
1436 : 0 : case RTE_FLOW_FIELD_UDP_PORT_SRC:
1437 : : case RTE_FLOW_FIELD_UDP_PORT_DST:
1438 : 0 : return 16;
1439 : 0 : case RTE_FLOW_FIELD_VXLAN_VNI:
1440 : : case RTE_FLOW_FIELD_GENEVE_VNI:
1441 : 0 : return 24;
1442 : 0 : case RTE_FLOW_FIELD_VXLAN_LAST_RSVD:
1443 : 0 : return 8;
1444 : : case RTE_FLOW_FIELD_GTP_TEID:
1445 : : case RTE_FLOW_FIELD_MPLS:
1446 : : case RTE_FLOW_FIELD_TAG:
1447 : : case RTE_FLOW_FIELD_ESP_SPI:
1448 : : case RTE_FLOW_FIELD_ESP_SEQ_NUM:
1449 : : return 32;
1450 : 0 : case RTE_FLOW_FIELD_ESP_PROTO:
1451 : 0 : return 8;
1452 : 0 : case RTE_FLOW_FIELD_MARK:
1453 : 0 : return rte_popcount32(priv->sh->dv_mark_mask);
1454 : 0 : case RTE_FLOW_FIELD_META:
1455 : 0 : return (flow_dv_get_metadata_reg(dev, attr, error) == REG_C_0) ?
1456 [ # # ]: 0 : rte_popcount32(priv->sh->dv_meta_mask) : 32;
1457 : 0 : case RTE_FLOW_FIELD_GTP_PSC_QFI:
1458 : 0 : return 6;
1459 : 0 : case RTE_FLOW_FIELD_POINTER:
1460 : : case RTE_FLOW_FIELD_VALUE:
1461 : 0 : return inherit < 0 ? 0 : inherit;
1462 : 0 : case RTE_FLOW_FIELD_IPV4_ECN:
1463 : : case RTE_FLOW_FIELD_IPV6_ECN:
1464 : : case RTE_FLOW_FIELD_METER_COLOR:
1465 : 0 : return 2;
1466 : : case RTE_FLOW_FIELD_HASH_RESULT:
1467 : : return 32;
1468 : 0 : default:
1469 : : MLX5_ASSERT(false);
1470 : : }
1471 : 0 : return 0;
1472 : : }
1473 : :
1474 : : static __rte_always_inline uint8_t
1475 : : flow_modify_info_mask_8(uint32_t length, uint32_t off)
1476 : : {
1477 : 0 : return (0xffu >> (8 - length)) << off;
1478 : : }
1479 : :
1480 : : static __rte_always_inline uint16_t
1481 : : flow_modify_info_mask_16(uint32_t length, uint32_t off)
1482 : : {
1483 [ # # # # : 0 : return rte_cpu_to_be_16((0xffffu >> (16 - length)) << off);
# # # # #
# # # # #
# # # # #
# # # ]
1484 : : }
1485 : :
1486 : : static __rte_always_inline uint32_t
1487 : : flow_modify_info_mask_32(uint32_t length, uint32_t off)
1488 : : {
1489 [ # # # # : 0 : return rte_cpu_to_be_32((0xffffffffu >> (32 - length)) << off);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1490 : : }
1491 : :
1492 : : static __rte_always_inline uint32_t
1493 : : flow_modify_info_mask_32_masked(uint32_t length, uint32_t off, uint32_t post_mask)
1494 : : {
1495 : 0 : uint32_t mask = (0xffffffffu >> (32 - length)) << off;
1496 : 0 : return rte_cpu_to_be_32(mask & post_mask);
1497 : : }
1498 : :
1499 : : static __rte_always_inline enum mlx5_modification_field
1500 : : mlx5_mpls_modi_field_get(const struct rte_flow_field_data *data)
1501 : : {
1502 : 0 : return MLX5_MODI_IN_MPLS_LABEL_0 + data->tag_index;
1503 : : }
1504 : :
1505 : : static __rte_always_inline int
1506 : : flow_geneve_opt_modi_field_get(struct mlx5_priv *priv,
1507 : : const struct rte_flow_field_data *data)
1508 : : {
1509 : : #ifdef HAVE_MLX5_HWS_SUPPORT
1510 : 0 : return mlx5_geneve_opt_modi_field_get(priv, data);
1511 : : #else
1512 : : (void)priv;
1513 : : (void)data;
1514 : : DRV_LOG(ERR, "GENEVE option modification is not supported.");
1515 : : rte_errno = ENOTSUP;
1516 : : return -rte_errno;
1517 : : #endif
1518 : : }
1519 : :
1520 : : static void
1521 : 0 : mlx5_modify_flex_item(const struct rte_eth_dev *dev,
1522 : : const struct mlx5_flex_item *flex,
1523 : : const struct rte_flow_field_data *data,
1524 : : struct field_modify_info *info,
1525 : : uint32_t *mask, uint32_t width)
1526 : : {
1527 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1528 : 0 : struct mlx5_hca_flex_attr *attr = &priv->sh->cdev->config.hca_attr.flex;
1529 : : uint32_t i, j;
1530 : : int id = 0;
1531 : 0 : uint32_t pos = 0;
1532 : : const struct mlx5_flex_pattern_field *map;
1533 : 0 : uint32_t offset = data->offset;
1534 : : uint32_t width_left = width;
1535 : : uint32_t cur_width = 0;
1536 : : uint32_t tmp_ofs;
1537 : : uint32_t idx = 0;
1538 : : struct field_modify_info tmp;
1539 : : int tmp_id;
1540 : :
1541 [ # # ]: 0 : if (!attr->query_match_sample_info) {
1542 : 0 : DRV_LOG(ERR, "FW doesn't support modify field with flex item.");
1543 : 0 : return;
1544 : : }
1545 : : /*
1546 : : * search for the mapping instance until Accumulated width is no
1547 : : * less than data->offset.
1548 : : */
1549 [ # # ]: 0 : for (i = 0; i < flex->mapnum; i++) {
1550 [ # # ]: 0 : if (flex->map[i].width + pos > data->offset)
1551 : : break;
1552 : 0 : pos += flex->map[i].width;
1553 : : }
1554 [ # # ]: 0 : if (i >= flex->mapnum)
1555 : : return;
1556 [ # # ]: 0 : tmp_ofs = pos < data->offset ? data->offset - pos : 0;
1557 [ # # # # ]: 0 : for (j = i; i < flex->mapnum && width_left > 0; ) {
1558 : 0 : map = flex->map + i;
1559 : 0 : id = mlx5_flex_get_sample_id(flex, i, &pos, false);
1560 [ # # ]: 0 : if (id == -1) {
1561 : 0 : i++;
1562 : : /* All left length is dummy */
1563 [ # # ]: 0 : if (pos >= data->offset + width)
1564 : : return;
1565 : 0 : cur_width = map->width;
1566 : : /* One mapping instance covers the whole width. */
1567 [ # # ]: 0 : } else if (pos + map->width >= (data->offset + width)) {
1568 : : cur_width = width_left;
1569 : : } else {
1570 : 0 : cur_width = cur_width + map->width - tmp_ofs;
1571 : 0 : pos += map->width;
1572 : : /*
1573 : : * Continue to search next until:
1574 : : * 1. Another flex parser ID.
1575 : : * 2. Width has been covered.
1576 : : */
1577 [ # # ]: 0 : for (j = i + 1; j < flex->mapnum; j++) {
1578 : 0 : tmp_id = mlx5_flex_get_sample_id(flex, j, &pos, false);
1579 [ # # ]: 0 : if (tmp_id == -1) {
1580 : : i = j;
1581 : 0 : pos -= flex->map[j].width;
1582 : 0 : break;
1583 : : }
1584 [ # # # # ]: 0 : if (id >= (int)flex->devx_fp->num_samples ||
1585 [ # # ]: 0 : id >= MLX5_GRAPH_NODE_SAMPLE_NUM ||
1586 [ # # ]: 0 : tmp_id >= (int)flex->devx_fp->num_samples ||
1587 : : tmp_id >= MLX5_GRAPH_NODE_SAMPLE_NUM)
1588 : : return;
1589 : 0 : if (flex->devx_fp->sample_info[id].modify_field_id !=
1590 [ # # ]: 0 : flex->devx_fp->sample_info[tmp_id].modify_field_id ||
1591 : 0 : flex->map[j].shift != flex->map[j - 1].width +
1592 [ # # ]: 0 : flex->map[j - 1].shift) {
1593 : : i = j;
1594 : : break;
1595 : : }
1596 [ # # ]: 0 : if ((pos + flex->map[j].width) >= (data->offset + width)) {
1597 : : cur_width = width_left;
1598 : : break;
1599 : : }
1600 : 0 : pos += flex->map[j].width;
1601 : 0 : cur_width += flex->map[j].width;
1602 : : }
1603 : : }
1604 [ # # ]: 0 : if (cur_width > width_left)
1605 : : cur_width = width_left;
1606 [ # # # # : 0 : else if (cur_width < width_left && (j == flex->mapnum || i == flex->mapnum))
# # ]
1607 : : return;
1608 : :
1609 : : MLX5_ASSERT(id < (int)flex->devx_fp->num_samples);
1610 [ # # # # ]: 0 : if (id >= (int)flex->devx_fp->num_samples || id >= MLX5_GRAPH_NODE_SAMPLE_NUM)
1611 : : return;
1612 : : /* Use invalid entry as placeholder for DUMMY mapping. */
1613 : 0 : info[idx] = (struct field_modify_info){cur_width / CHAR_BIT, offset / CHAR_BIT,
1614 [ # # ]: 0 : id == -1 ? MLX5_MODI_INVALID :
1615 : : (enum mlx5_modification_field)
1616 : 0 : flex->devx_fp->sample_info[id].modify_field_id,
1617 : 0 : map->shift + tmp_ofs, 1};
1618 : 0 : offset += cur_width;
1619 : 0 : width_left -= cur_width;
1620 [ # # ]: 0 : if (!mask) {
1621 : 0 : info[idx].offset = (32 - cur_width - map->shift - tmp_ofs);
1622 : 0 : info[idx].size = cur_width / CHAR_BIT + info[idx].offset / CHAR_BIT;
1623 : : }
1624 : : cur_width = 0;
1625 : : tmp_ofs = 0;
1626 : 0 : idx++;
1627 : : }
1628 [ # # ]: 0 : if (unlikely(width_left > 0)) {
1629 : : MLX5_ASSERT(false);
1630 : : return;
1631 : : }
1632 [ # # ]: 0 : if (mask)
1633 : 0 : memset(mask, 0xff, data->offset / CHAR_BIT + width / CHAR_BIT);
1634 : : /* Re-order the info to follow IPv6 address. */
1635 [ # # ]: 0 : for (i = 0; i < idx / 2; i++) {
1636 : 0 : tmp = info[i];
1637 : : MLX5_ASSERT(info[i].id);
1638 : : MLX5_ASSERT(info[idx - 1 - i].id);
1639 : 0 : info[i] = info[idx - 1 - i];
1640 : 0 : info[idx - 1 - i] = tmp;
1641 : : }
1642 : : }
1643 : :
1644 : : void
1645 : 0 : mlx5_flow_field_id_to_modify_info
1646 : : (const struct rte_flow_field_data *data,
1647 : : struct field_modify_info *info, uint32_t *mask,
1648 : : uint32_t width, struct rte_eth_dev *dev,
1649 : : const struct rte_flow_attr *attr, struct rte_flow_error *error)
1650 : : {
1651 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1652 : : enum mlx5_modification_field modi_id;
1653 : : uint32_t idx = 0;
1654 : : uint32_t off_be = 0;
1655 : : uint32_t length = 0;
1656 : :
1657 [ # # # # : 0 : switch ((int)data->field) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
1658 : : case RTE_FLOW_FIELD_START:
1659 : : /* not supported yet */
1660 : : MLX5_ASSERT(false);
1661 : : break;
1662 : 0 : case RTE_FLOW_FIELD_MAC_DST:
1663 : : MLX5_ASSERT(data->offset + width <= 48);
1664 : 0 : off_be = 48 - (data->offset + width);
1665 [ # # ]: 0 : if (off_be < 16) {
1666 [ # # ]: 0 : modi_id = CALC_MODI_ID(DMAC_15_0, data->level);
1667 : 0 : info[idx] = (struct field_modify_info){2, 4, modi_id};
1668 [ # # ]: 0 : length = off_be + width <= 16 ? width : 16 - off_be;
1669 [ # # ]: 0 : if (mask)
1670 : 0 : mask[1] = flow_modify_info_mask_16(length,
1671 : : off_be);
1672 : : else
1673 : 0 : info[idx].offset = off_be;
1674 : 0 : width -= length;
1675 [ # # ]: 0 : if (!width)
1676 : : break;
1677 : : off_be = 0;
1678 : : idx++;
1679 : : } else {
1680 : 0 : off_be -= 16;
1681 : : }
1682 [ # # ]: 0 : modi_id = CALC_MODI_ID(DMAC_47_16, data->level);
1683 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1684 [ # # ]: 0 : if (mask)
1685 : 0 : mask[0] = flow_modify_info_mask_32(width, off_be);
1686 : : else
1687 : 0 : info[idx].offset = off_be;
1688 : : break;
1689 : 0 : case RTE_FLOW_FIELD_MAC_SRC:
1690 : : MLX5_ASSERT(data->offset + width <= 48);
1691 : 0 : off_be = 48 - (data->offset + width);
1692 [ # # ]: 0 : if (off_be < 16) {
1693 [ # # ]: 0 : modi_id = CALC_MODI_ID(SMAC_15_0, data->level);
1694 : 0 : info[idx] = (struct field_modify_info){2, 4, modi_id};
1695 [ # # ]: 0 : length = off_be + width <= 16 ? width : 16 - off_be;
1696 [ # # ]: 0 : if (mask)
1697 : 0 : mask[1] = flow_modify_info_mask_16(length,
1698 : : off_be);
1699 : : else
1700 : 0 : info[idx].offset = off_be;
1701 : 0 : width -= length;
1702 [ # # ]: 0 : if (!width)
1703 : : break;
1704 : : off_be = 0;
1705 : : idx++;
1706 : : } else {
1707 : 0 : off_be -= 16;
1708 : : }
1709 [ # # ]: 0 : modi_id = CALC_MODI_ID(SMAC_47_16, data->level);
1710 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1711 [ # # ]: 0 : if (mask)
1712 : 0 : mask[0] = flow_modify_info_mask_32(width, off_be);
1713 : : else
1714 : 0 : info[idx].offset = off_be;
1715 : : break;
1716 : : case RTE_FLOW_FIELD_VLAN_TYPE:
1717 : : /* not supported yet */
1718 : : break;
1719 : 0 : case RTE_FLOW_FIELD_VLAN_ID:
1720 : : MLX5_ASSERT(data->offset + width <= 12);
1721 : 0 : off_be = 12 - (data->offset + width);
1722 : 0 : info[idx] = (struct field_modify_info){2, 0,
1723 : : MLX5_MODI_OUT_FIRST_VID};
1724 [ # # ]: 0 : if (mask)
1725 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1726 : : else
1727 : 0 : info[idx].offset = off_be;
1728 : : break;
1729 : 0 : case RTE_FLOW_FIELD_MAC_TYPE:
1730 : : MLX5_ASSERT(data->offset + width <= 16);
1731 : 0 : off_be = 16 - (data->offset + width);
1732 [ # # ]: 0 : modi_id = CALC_MODI_ID(ETHERTYPE, data->level);
1733 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
1734 [ # # ]: 0 : if (mask)
1735 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1736 : : else
1737 : 0 : info[idx].offset = off_be;
1738 : : break;
1739 : 0 : case RTE_FLOW_FIELD_IPV4_IHL:
1740 : : MLX5_ASSERT(data->offset + width <= 4);
1741 : 0 : off_be = 4 - (data->offset + width);
1742 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV4_IHL, data->level);
1743 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
1744 [ # # ]: 0 : if (mask)
1745 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1746 : : else
1747 : 0 : info[idx].offset = off_be;
1748 : : break;
1749 : 0 : case RTE_FLOW_FIELD_IPV4_DSCP:
1750 : : MLX5_ASSERT(data->offset + width <= 6);
1751 : 0 : off_be = 6 - (data->offset + width);
1752 [ # # ]: 0 : modi_id = CALC_MODI_ID(IP_DSCP, data->level);
1753 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
1754 [ # # ]: 0 : if (mask)
1755 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1756 : : else
1757 : 0 : info[idx].offset = off_be;
1758 : : break;
1759 : 0 : case RTE_FLOW_FIELD_IPV4_TOTAL_LEN:
1760 : : MLX5_ASSERT(data->offset + width <= 16);
1761 : 0 : off_be = 16 - (data->offset + width);
1762 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV4_TOTAL_LEN, data->level);
1763 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
1764 [ # # ]: 0 : if (mask)
1765 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1766 : : else
1767 : 0 : info[idx].offset = off_be;
1768 : : break;
1769 : 0 : case RTE_FLOW_FIELD_IPV4_TTL:
1770 : : MLX5_ASSERT(data->offset + width <= 8);
1771 : 0 : off_be = 8 - (data->offset + width);
1772 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV4_TTL, data->level);
1773 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
1774 [ # # ]: 0 : if (mask)
1775 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1776 : : else
1777 : 0 : info[idx].offset = off_be;
1778 : : break;
1779 : 0 : case RTE_FLOW_FIELD_IPV4_SRC:
1780 : : MLX5_ASSERT(data->offset + width <= 32);
1781 : 0 : off_be = 32 - (data->offset + width);
1782 [ # # ]: 0 : modi_id = CALC_MODI_ID(SIPV4, data->level);
1783 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1784 [ # # ]: 0 : if (mask)
1785 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1786 : : else
1787 : 0 : info[idx].offset = off_be;
1788 : : break;
1789 : 0 : case RTE_FLOW_FIELD_IPV4_DST:
1790 : : MLX5_ASSERT(data->offset + width <= 32);
1791 : 0 : off_be = 32 - (data->offset + width);
1792 [ # # ]: 0 : modi_id = CALC_MODI_ID(DIPV4, data->level);
1793 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1794 [ # # ]: 0 : if (mask)
1795 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1796 : : else
1797 : 0 : info[idx].offset = off_be;
1798 : : break;
1799 : : case RTE_FLOW_FIELD_IPV6_DSCP:
1800 : : MLX5_ASSERT(data->offset + width <= 6);
1801 : : /*
1802 : : * IPv6 DSCP uses OUT_IPV6_TRAFFIC_CLASS as ID but it starts from 2
1803 : : * bits left. Shift the mask left for IPv6 DSCP. Do it here because
1804 : : * it's needed to distinguish DSCP from ECN in data field construct
1805 : : */
1806 [ # # ]: 0 : if (mlx5_dv_modify_ipv6_traffic_class_supported(priv)) {
1807 : 0 : off_be = 6 - (data->offset + width) + MLX5_IPV6_HDR_DSCP_SHIFT;
1808 : 0 : info[idx] = (struct field_modify_info){1, 0,
1809 : : MLX5_MODI_OUT_IPV6_TRAFFIC_CLASS};
1810 : : } else {
1811 : 0 : off_be = 6 - (data->offset + width);
1812 : 0 : info[idx] = (struct field_modify_info){1, 0,
1813 : : MLX5_MODI_OUT_IP_DSCP};
1814 : : }
1815 [ # # ]: 0 : if (mask)
1816 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1817 : : else
1818 : 0 : info[idx].offset = off_be;
1819 : : break;
1820 : 0 : case RTE_FLOW_FIELD_IPV6_TRAFFIC_CLASS:
1821 : : MLX5_ASSERT(data->offset + width <= 8);
1822 : 0 : off_be = 8 - (data->offset + width);
1823 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV6_TRAFFIC_CLASS, data->level);
1824 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
1825 [ # # ]: 0 : if (mask)
1826 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1827 : : else
1828 : 0 : info[idx].offset = off_be;
1829 : : break;
1830 : 0 : case RTE_FLOW_FIELD_IPV6_FLOW_LABEL:
1831 : : MLX5_ASSERT(data->offset + width <= 20);
1832 : 0 : off_be = 20 - (data->offset + width);
1833 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV6_FLOW_LABEL, data->level);
1834 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1835 [ # # ]: 0 : if (mask)
1836 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1837 : : else
1838 : 0 : info[idx].offset = off_be;
1839 : : break;
1840 : 0 : case RTE_FLOW_FIELD_IPV6_PAYLOAD_LEN:
1841 : : MLX5_ASSERT(data->offset + width <= 16);
1842 : 0 : off_be = 16 - (data->offset + width);
1843 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV6_PAYLOAD_LEN, data->level);
1844 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
1845 [ # # ]: 0 : if (mask)
1846 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1847 : : else
1848 : 0 : info[idx].offset = off_be;
1849 : : break;
1850 : 0 : case RTE_FLOW_FIELD_IPV6_HOPLIMIT:
1851 : : MLX5_ASSERT(data->offset + width <= 8);
1852 : 0 : off_be = 8 - (data->offset + width);
1853 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV6_HOPLIMIT, data->level);
1854 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
1855 [ # # ]: 0 : if (mask)
1856 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1857 : : else
1858 : 0 : info[idx].offset = off_be;
1859 : : break;
1860 : 0 : case RTE_FLOW_FIELD_IPV6_SRC: {
1861 : : /*
1862 : : * Fields corresponding to IPv6 source address bytes
1863 : : * arranged according to network byte ordering.
1864 : : */
1865 : 0 : struct field_modify_info fields[] = {
1866 [ # # ]: 0 : { 4, 0, CALC_MODI_ID(SIPV6_127_96, data->level)},
1867 [ # # ]: 0 : { 4, 4, CALC_MODI_ID(SIPV6_95_64, data->level)},
1868 [ # # ]: 0 : { 4, 8, CALC_MODI_ID(SIPV6_63_32, data->level)},
1869 [ # # ]: 0 : { 4, 12, CALC_MODI_ID(SIPV6_31_0, data->level)},
1870 : : };
1871 : : /* First mask to be modified is the mask of 4th address byte. */
1872 : : uint32_t midx = 3;
1873 : :
1874 : : MLX5_ASSERT(data->offset + width <= 128);
1875 : 0 : off_be = 128 - (data->offset + width);
1876 [ # # ]: 0 : while (width > 0 && midx > 0) {
1877 [ # # ]: 0 : if (off_be < 32) {
1878 : 0 : info[idx] = fields[midx];
1879 : 0 : length = off_be + width <= 32 ?
1880 [ # # ]: 0 : width : 32 - off_be;
1881 [ # # ]: 0 : if (mask)
1882 [ # # ]: 0 : mask[midx] = flow_modify_info_mask_32
1883 : : (length, off_be);
1884 : : else
1885 : 0 : info[idx].offset = off_be;
1886 : 0 : width -= length;
1887 : : off_be = 0;
1888 : 0 : idx++;
1889 : : } else {
1890 : 0 : off_be -= 32;
1891 : : }
1892 : 0 : midx--;
1893 : : }
1894 [ # # ]: 0 : if (!width)
1895 : : break;
1896 : 0 : info[idx] = fields[midx];
1897 [ # # ]: 0 : if (mask)
1898 [ # # ]: 0 : mask[midx] = flow_modify_info_mask_32(width, off_be);
1899 : : else
1900 : 0 : info[idx].offset = off_be;
1901 : : break;
1902 : : }
1903 : 0 : case RTE_FLOW_FIELD_IPV6_DST: {
1904 : : /*
1905 : : * Fields corresponding to IPv6 destination address bytes
1906 : : * arranged according to network byte ordering.
1907 : : */
1908 : 0 : struct field_modify_info fields[] = {
1909 [ # # ]: 0 : { 4, 0, CALC_MODI_ID(DIPV6_127_96, data->level)},
1910 [ # # ]: 0 : { 4, 4, CALC_MODI_ID(DIPV6_95_64, data->level)},
1911 [ # # ]: 0 : { 4, 8, CALC_MODI_ID(DIPV6_63_32, data->level)},
1912 [ # # ]: 0 : { 4, 12, CALC_MODI_ID(DIPV6_31_0, data->level)},
1913 : : };
1914 : : /* First mask to be modified is the mask of 4th address byte. */
1915 : : uint32_t midx = 3;
1916 : :
1917 : : MLX5_ASSERT(data->offset + width <= 128);
1918 : 0 : off_be = 128 - (data->offset + width);
1919 [ # # ]: 0 : while (width > 0 && midx > 0) {
1920 [ # # ]: 0 : if (off_be < 32) {
1921 : 0 : info[idx] = fields[midx];
1922 : 0 : length = off_be + width <= 32 ?
1923 [ # # ]: 0 : width : 32 - off_be;
1924 [ # # ]: 0 : if (mask)
1925 [ # # ]: 0 : mask[midx] = flow_modify_info_mask_32
1926 : : (length, off_be);
1927 : : else
1928 : 0 : info[idx].offset = off_be;
1929 : 0 : width -= length;
1930 : : off_be = 0;
1931 : 0 : idx++;
1932 : : } else {
1933 : 0 : off_be -= 32;
1934 : : }
1935 : 0 : midx--;
1936 : : }
1937 [ # # ]: 0 : if (!width)
1938 : : break;
1939 : 0 : info[idx] = fields[midx];
1940 [ # # ]: 0 : if (mask)
1941 [ # # ]: 0 : mask[midx] = flow_modify_info_mask_32(width, off_be);
1942 : : else
1943 : 0 : info[idx].offset = off_be;
1944 : : break;
1945 : : }
1946 : 0 : case RTE_FLOW_FIELD_TCP_PORT_SRC:
1947 : : MLX5_ASSERT(data->offset + width <= 16);
1948 : 0 : off_be = 16 - (data->offset + width);
1949 [ # # ]: 0 : modi_id = CALC_MODI_ID(TCP_SPORT, data->level);
1950 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
1951 [ # # ]: 0 : if (mask)
1952 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1953 : : else
1954 : 0 : info[idx].offset = off_be;
1955 : : break;
1956 : 0 : case RTE_FLOW_FIELD_TCP_PORT_DST:
1957 : : MLX5_ASSERT(data->offset + width <= 16);
1958 : 0 : off_be = 16 - (data->offset + width);
1959 [ # # ]: 0 : modi_id = CALC_MODI_ID(TCP_DPORT, data->level);
1960 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
1961 [ # # ]: 0 : if (mask)
1962 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1963 : : else
1964 : 0 : info[idx].offset = off_be;
1965 : : break;
1966 : 0 : case RTE_FLOW_FIELD_TCP_SEQ_NUM:
1967 : : MLX5_ASSERT(data->offset + width <= 32);
1968 : 0 : off_be = 32 - (data->offset + width);
1969 [ # # ]: 0 : modi_id = CALC_MODI_ID(TCP_SEQ_NUM, data->level);
1970 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1971 [ # # ]: 0 : if (mask)
1972 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1973 : : else
1974 : 0 : info[idx].offset = off_be;
1975 : : break;
1976 : 0 : case RTE_FLOW_FIELD_TCP_ACK_NUM:
1977 : : MLX5_ASSERT(data->offset + width <= 32);
1978 : 0 : off_be = 32 - (data->offset + width);
1979 [ # # ]: 0 : modi_id = CALC_MODI_ID(TCP_ACK_NUM, data->level);
1980 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1981 [ # # ]: 0 : if (mask)
1982 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1983 : : else
1984 : 0 : info[idx].offset = off_be;
1985 : : break;
1986 : 0 : case RTE_FLOW_FIELD_TCP_FLAGS:
1987 : : MLX5_ASSERT(data->offset + width <= 9);
1988 : 0 : off_be = 9 - (data->offset + width);
1989 [ # # ]: 0 : modi_id = CALC_MODI_ID(TCP_FLAGS, data->level);
1990 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
1991 [ # # ]: 0 : if (mask)
1992 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1993 : : else
1994 : 0 : info[idx].offset = off_be;
1995 : : break;
1996 : 0 : case RTE_FLOW_FIELD_TCP_DATA_OFFSET:
1997 : : MLX5_ASSERT(data->offset + width <= 4);
1998 : 0 : off_be = 4 - (data->offset + width);
1999 [ # # ]: 0 : modi_id = CALC_MODI_ID(TCP_DATA_OFFSET, data->level);
2000 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
2001 [ # # ]: 0 : if (mask)
2002 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
2003 : : else
2004 : 0 : info[idx].offset = off_be;
2005 : : break;
2006 : 0 : case RTE_FLOW_FIELD_UDP_PORT_SRC:
2007 : : MLX5_ASSERT(data->offset + width <= 16);
2008 : 0 : off_be = 16 - (data->offset + width);
2009 [ # # ]: 0 : modi_id = CALC_MODI_ID(UDP_SPORT, data->level);
2010 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
2011 [ # # ]: 0 : if (mask)
2012 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
2013 : : else
2014 : 0 : info[idx].offset = off_be;
2015 : : break;
2016 : 0 : case RTE_FLOW_FIELD_UDP_PORT_DST:
2017 : : MLX5_ASSERT(data->offset + width <= 16);
2018 : 0 : off_be = 16 - (data->offset + width);
2019 [ # # ]: 0 : modi_id = CALC_MODI_ID(UDP_DPORT, data->level);
2020 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
2021 [ # # ]: 0 : if (mask)
2022 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
2023 : : else
2024 : 0 : info[idx].offset = off_be;
2025 : : break;
2026 : 0 : case RTE_FLOW_FIELD_VXLAN_VNI:
2027 : : case RTE_FLOW_FIELD_GENEVE_VNI:
2028 : : MLX5_ASSERT(data->offset + width <= 24);
2029 : : /* VNI is on bits 31-8 of TUNNEL_HDR_DW_1. */
2030 : 0 : off_be = 24 - (data->offset + width) + 8;
2031 : 0 : info[idx] = (struct field_modify_info){4, 0,
2032 : : MLX5_MODI_TUNNEL_HDR_DW_1};
2033 [ # # ]: 0 : if (mask)
2034 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2035 : : else
2036 : 0 : info[idx].offset = off_be;
2037 : : break;
2038 : 0 : case RTE_FLOW_FIELD_VXLAN_LAST_RSVD:
2039 : : MLX5_ASSERT(data->offset + width <= 8);
2040 : : /* Last_rsvd is on bits 7-0 of TUNNEL_HDR_DW_1. */
2041 : 0 : off_be = 8 - (data->offset + width);
2042 : 0 : info[idx] = (struct field_modify_info){1, 0, MLX5_MODI_TUNNEL_HDR_DW_1};
2043 [ # # ]: 0 : if (mask)
2044 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
2045 : : else
2046 : 0 : info[idx].offset = off_be;
2047 : : break;
2048 : : case RTE_FLOW_FIELD_GENEVE_OPT_TYPE:
2049 : : MLX5_ASSERT(data->offset + width <= 8);
2050 : : modi_id = flow_geneve_opt_modi_field_get(priv, data);
2051 [ # # ]: 0 : if (modi_id < 0)
2052 : : return;
2053 : : /* Type is on bits 16-8 of GENEVE option header (DW0). */
2054 : 0 : off_be = 32 - (16 + data->offset + width);
2055 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
2056 [ # # ]: 0 : if (mask)
2057 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2058 : : else
2059 : 0 : info[idx].offset = off_be;
2060 : : break;
2061 : : case RTE_FLOW_FIELD_GENEVE_OPT_CLASS:
2062 : : MLX5_ASSERT(data->offset + width <= 16);
2063 : : modi_id = flow_geneve_opt_modi_field_get(priv, data);
2064 [ # # ]: 0 : if (modi_id < 0)
2065 : : return;
2066 : : /* Class is on bits 31-16 of GENEVE option header (DW0). */
2067 : 0 : off_be = 32 - (data->offset + width);
2068 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
2069 [ # # ]: 0 : if (mask)
2070 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2071 : : else
2072 : 0 : info[idx].offset = off_be;
2073 : : break;
2074 : 0 : case RTE_FLOW_FIELD_GENEVE_OPT_DATA:
2075 [ # # ]: 0 : if ((data->offset % 32) + width > 32) {
2076 : 0 : DRV_LOG(ERR, "Geneve TLV option data is per DW.");
2077 : 0 : return;
2078 : : }
2079 : : modi_id = flow_geneve_opt_modi_field_get(priv, data);
2080 [ # # ]: 0 : if (modi_id < 0)
2081 : : return;
2082 : : /* Use offset inside DW. */
2083 : 0 : off_be = 32 - ((data->offset % 32) + width);
2084 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
2085 [ # # ]: 0 : if (mask)
2086 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2087 : : else
2088 : 0 : info[idx].offset = off_be;
2089 : : break;
2090 : 0 : case RTE_FLOW_FIELD_GTP_TEID:
2091 : : MLX5_ASSERT(data->offset + width <= 32);
2092 : 0 : off_be = 32 - (data->offset + width);
2093 : 0 : info[idx] = (struct field_modify_info){4, 0,
2094 : : MLX5_MODI_GTP_TEID};
2095 [ # # ]: 0 : if (mask)
2096 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2097 : : else
2098 : 0 : info[idx].offset = off_be;
2099 : : break;
2100 : 0 : case RTE_FLOW_FIELD_MPLS:
2101 : : MLX5_ASSERT(data->offset + width <= 32);
2102 : 0 : off_be = 32 - (data->offset + width);
2103 : : modi_id = mlx5_mpls_modi_field_get(data);
2104 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
2105 [ # # ]: 0 : if (mask)
2106 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2107 : : else
2108 : 0 : info[idx].offset = off_be;
2109 : : break;
2110 : : case RTE_FLOW_FIELD_TAG:
2111 : : {
2112 : : MLX5_ASSERT(data->offset + width <= 32);
2113 : : uint8_t tag_index = flow_tag_index_get(data);
2114 : : int reg;
2115 : :
2116 : : off_be = (tag_index == RTE_PMD_MLX5_LINEAR_HASH_TAG_INDEX) ?
2117 [ # # ]: 0 : 16 - (data->offset + width) + 16 : data->offset;
2118 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
2119 [ # # ]: 0 : reg = flow_hw_get_reg_id(dev,
2120 : : RTE_FLOW_ITEM_TYPE_TAG,
2121 : : tag_index);
2122 : : else
2123 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG,
2124 : : tag_index, error);
2125 [ # # ]: 0 : if (reg < 0)
2126 : : return;
2127 : : MLX5_ASSERT(reg != REG_NON);
2128 [ # # ]: 0 : if ((unsigned int)reg >= RTE_DIM(mlx5_reg_to_field))
2129 : : return;
2130 : 0 : info[idx] = (struct field_modify_info){4, 0,
2131 : 0 : mlx5_reg_to_field[reg]};
2132 [ # # ]: 0 : if (mask)
2133 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2134 : : else
2135 : 0 : info[idx].offset = off_be;
2136 : : }
2137 : : break;
2138 : 0 : case RTE_FLOW_FIELD_MARK:
2139 : : {
2140 : 0 : uint32_t mark_mask = priv->sh->dv_mark_mask;
2141 : : uint32_t mark_count = rte_popcount32(mark_mask);
2142 : : RTE_SET_USED(mark_count);
2143 : : MLX5_ASSERT(data->offset + width <= mark_count);
2144 : 0 : int reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK,
2145 : : 0, error);
2146 [ # # ]: 0 : if (reg < 0)
2147 : : return;
2148 : : MLX5_ASSERT(reg != REG_NON);
2149 : : MLX5_ASSERT((unsigned int)reg < RTE_DIM(mlx5_reg_to_field));
2150 : 0 : info[idx] = (struct field_modify_info){4, 0,
2151 : 0 : mlx5_reg_to_field[reg]};
2152 [ # # ]: 0 : if (mask)
2153 : 0 : mask[idx] = flow_modify_info_mask_32_masked
2154 [ # # ]: 0 : (width, data->offset, mark_mask);
2155 : : else
2156 : 0 : info[idx].offset = data->offset;
2157 : : }
2158 : : break;
2159 : 0 : case RTE_FLOW_FIELD_META:
2160 : : {
2161 : 0 : uint32_t meta_mask = priv->sh->dv_meta_mask;
2162 : : uint32_t meta_count = rte_popcount32(meta_mask);
2163 : : RTE_SET_USED(meta_count);
2164 : : MLX5_ASSERT(data->offset + width <= meta_count);
2165 : 0 : int reg = flow_dv_get_metadata_reg(dev, attr, error);
2166 [ # # ]: 0 : if (reg < 0)
2167 : : return;
2168 : : MLX5_ASSERT(reg != REG_NON);
2169 : : MLX5_ASSERT((unsigned int)reg < RTE_DIM(mlx5_reg_to_field));
2170 : 0 : info[idx] = (struct field_modify_info){4, 0,
2171 : 0 : mlx5_reg_to_field[reg]};
2172 [ # # ]: 0 : if (mask)
2173 : 0 : mask[idx] = flow_modify_info_mask_32_masked
2174 [ # # ]: 0 : (width, data->offset, meta_mask);
2175 : : else
2176 : 0 : info[idx].offset = data->offset;
2177 : : }
2178 : : break;
2179 : 0 : case RTE_FLOW_FIELD_IPV4_ECN:
2180 : : MLX5_ASSERT(data->offset + width <= 2);
2181 : 0 : off_be = 2 - (data->offset + width);
2182 [ # # ]: 0 : modi_id = CALC_MODI_ID(IP_ECN, data->level);
2183 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
2184 [ # # ]: 0 : if (mask)
2185 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
2186 : : else
2187 : 0 : info[idx].offset = off_be;
2188 : : break;
2189 : 0 : case RTE_FLOW_FIELD_IPV6_ECN:
2190 : : MLX5_ASSERT(data->offset + width <= 2);
2191 [ # # ]: 0 : off_be = 2 - (data->offset + width);
2192 [ # # ]: 0 : if (mlx5_dv_modify_ipv6_traffic_class_supported(priv))
2193 : 0 : info[idx] = (struct field_modify_info){1, 0,
2194 : : MLX5_MODI_OUT_IPV6_TRAFFIC_CLASS};
2195 : : else
2196 : 0 : info[idx] = (struct field_modify_info){1, 0,
2197 : : MLX5_MODI_OUT_IP_ECN};
2198 [ # # ]: 0 : if (mask)
2199 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
2200 : : else
2201 : 0 : info[idx].offset = off_be;
2202 : : break;
2203 : 0 : case RTE_FLOW_FIELD_GTP_PSC_QFI:
2204 : : MLX5_ASSERT(data->offset + width <= 8);
2205 : 0 : off_be = data->offset + 8;
2206 : 0 : info[idx] = (struct field_modify_info){4, 0,
2207 : : MLX5_MODI_GTPU_FIRST_EXT_DW_0};
2208 [ # # ]: 0 : if (mask)
2209 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2210 : : else
2211 : 0 : info[idx].offset = off_be;
2212 : : break;
2213 : 0 : case MLX5_RTE_FLOW_FIELD_META_REG:
2214 : : {
2215 [ # # ]: 0 : uint32_t meta_mask = priv->sh->dv_meta_mask;
2216 : : uint32_t meta_count = rte_popcount32(meta_mask);
2217 : : uint8_t reg = flow_tag_index_get(data);
2218 : :
2219 : : RTE_SET_USED(meta_count);
2220 : : MLX5_ASSERT(data->offset + width <= meta_count);
2221 : : MLX5_ASSERT(reg != REG_NON);
2222 : : MLX5_ASSERT(reg < RTE_DIM(mlx5_reg_to_field));
2223 : 0 : info[idx] = (struct field_modify_info){4, 0, mlx5_reg_to_field[reg]};
2224 [ # # ]: 0 : if (mask)
2225 : 0 : mask[idx] = flow_modify_info_mask_32_masked
2226 [ # # ]: 0 : (width, data->offset, meta_mask);
2227 : : else
2228 : 0 : info[idx].offset = data->offset;
2229 : : }
2230 : : break;
2231 : 0 : case RTE_FLOW_FIELD_METER_COLOR:
2232 : : {
2233 : : const uint32_t color_mask =
2234 : : (UINT32_C(1) << MLX5_MTR_COLOR_BITS) - 1;
2235 : : int reg;
2236 : :
2237 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
2238 : : reg = flow_hw_get_reg_id
2239 : : (dev,
2240 : : RTE_FLOW_ITEM_TYPE_METER_COLOR, 0);
2241 : : else
2242 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR,
2243 : : 0, error);
2244 [ # # ]: 0 : if (reg < 0)
2245 : : return;
2246 : : MLX5_ASSERT(reg != REG_NON);
2247 [ # # ]: 0 : if ((unsigned int)reg >= RTE_DIM(mlx5_reg_to_field))
2248 : : return;
2249 : 0 : info[idx] = (struct field_modify_info){4, 0,
2250 : 0 : mlx5_reg_to_field[reg]};
2251 [ # # ]: 0 : if (mask)
2252 : 0 : mask[idx] = flow_modify_info_mask_32_masked
2253 [ # # ]: 0 : (width, data->offset, color_mask);
2254 : : else
2255 : 0 : info[idx].offset = data->offset;
2256 : : }
2257 : : break;
2258 : 0 : case RTE_FLOW_FIELD_IPV4_PROTO: /* Fall-through. */
2259 : : case RTE_FLOW_FIELD_IPV6_PROTO:
2260 : : MLX5_ASSERT(data->offset + width <= 8);
2261 : 0 : off_be = 8 - (data->offset + width);
2262 : 0 : info[idx] = (struct field_modify_info){1, 0, MLX5_MODI_OUT_IP_PROTOCOL};
2263 [ # # ]: 0 : if (mask)
2264 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
2265 : : else
2266 : 0 : info[idx].offset = off_be;
2267 : : break;
2268 : 0 : case RTE_FLOW_FIELD_ESP_PROTO:
2269 : : MLX5_ASSERT(data->offset + width <= 8);
2270 : 0 : off_be = 8 - (data->offset + width);
2271 : 0 : info[idx] = (struct field_modify_info){1, 0, MLX5_MODI_OUT_IPSEC_NEXT_HDR};
2272 [ # # ]: 0 : if (mask)
2273 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
2274 : : else
2275 : 0 : info[idx].offset = off_be;
2276 : : break;
2277 : 0 : case RTE_FLOW_FIELD_ESP_SPI:
2278 : : MLX5_ASSERT(data->offset + width <= 32);
2279 : 0 : off_be = 32 - (data->offset + width);
2280 [ # # ]: 0 : modi_id = CALC_MODI_ID(ESP_SPI, data->level);
2281 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
2282 [ # # ]: 0 : if (mask)
2283 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2284 : : else
2285 : 0 : info[idx].offset = off_be;
2286 : : break;
2287 : 0 : case RTE_FLOW_FIELD_ESP_SEQ_NUM:
2288 : : MLX5_ASSERT(data->offset + width <= 32);
2289 : 0 : off_be = 32 - (data->offset + width);
2290 [ # # ]: 0 : modi_id = CALC_MODI_ID(ESP_SEQ_NUM, data->level);
2291 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
2292 [ # # ]: 0 : if (mask)
2293 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2294 : : else
2295 : 0 : info[idx].offset = off_be;
2296 : : break;
2297 : 0 : case RTE_FLOW_FIELD_FLEX_ITEM:
2298 : : MLX5_ASSERT(data->flex_handle != NULL && !(data->offset & 0x7));
2299 : 0 : mlx5_modify_flex_item(dev, (const struct mlx5_flex_item *)data->flex_handle,
2300 : : data, info, mask, width);
2301 : 0 : break;
2302 : 0 : case RTE_FLOW_FIELD_HASH_RESULT:
2303 : : MLX5_ASSERT(data->offset + width <= 32);
2304 : 0 : off_be = 32 - (data->offset + width);
2305 : 0 : info[idx] = (struct field_modify_info){4, 0,
2306 : : MLX5_MODI_HASH_RESULT};
2307 [ # # ]: 0 : if (mask)
2308 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2309 : : else
2310 : 0 : info[idx].offset = off_be;
2311 : : break;
2312 : : case RTE_FLOW_FIELD_POINTER:
2313 : : case RTE_FLOW_FIELD_VALUE:
2314 : : default:
2315 : : MLX5_ASSERT(false);
2316 : : break;
2317 : : }
2318 : : }
2319 : :
2320 : : /**
2321 : : * Convert modify_field action to DV specification.
2322 : : *
2323 : : * @param[in] dev
2324 : : * Pointer to the rte_eth_dev structure.
2325 : : * @param[in,out] resource
2326 : : * Pointer to the modify-header resource.
2327 : : * @param[in] action
2328 : : * Pointer to action specification.
2329 : : * @param[in] attr
2330 : : * Attributes of flow that includes this item.
2331 : : * @param[out] error
2332 : : * Pointer to the error structure.
2333 : : *
2334 : : * @return
2335 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2336 : : */
2337 : : static int
2338 : 0 : flow_dv_convert_action_modify_field
2339 : : (struct rte_eth_dev *dev,
2340 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
2341 : : const struct rte_flow_action *action,
2342 : : const struct rte_flow_attr *attr,
2343 : : struct rte_flow_error *error)
2344 : : {
2345 : 0 : const struct rte_flow_action_modify_field *conf =
2346 : : (const struct rte_flow_action_modify_field *)(action->conf);
2347 : 0 : struct rte_flow_item item = {
2348 : : .spec = NULL,
2349 : : .mask = NULL
2350 : : };
2351 : 0 : struct field_modify_info field[MLX5_ACT_MAX_MOD_FIELDS] = {
2352 : : {0, 0, 0} };
2353 : 0 : struct field_modify_info dcopy[MLX5_ACT_MAX_MOD_FIELDS] = {
2354 : : {0, 0, 0} };
2355 : 0 : uint32_t mask[MLX5_ACT_MAX_MOD_FIELDS] = {0, 0, 0, 0, 0};
2356 : 0 : uint32_t type, meta = 0, dscp = 0;
2357 : :
2358 [ # # ]: 0 : if (conf->src.field == RTE_FLOW_FIELD_POINTER ||
2359 : : conf->src.field == RTE_FLOW_FIELD_VALUE) {
2360 : 0 : type = conf->operation == RTE_FLOW_MODIFY_SET ?
2361 [ # # ]: 0 : MLX5_MODIFICATION_TYPE_SET : MLX5_MODIFICATION_TYPE_ADD;
2362 : : /** For SET fill the destination field (field) first. */
2363 : 0 : mlx5_flow_field_id_to_modify_info(&conf->dst, field, mask,
2364 : 0 : conf->width, dev,
2365 : : attr, error);
2366 : 0 : item.spec = conf->src.field == RTE_FLOW_FIELD_POINTER ?
2367 [ # # ]: 0 : (void *)(uintptr_t)conf->src.pvalue :
2368 : : (void *)(uintptr_t)&conf->src.value;
2369 [ # # ]: 0 : if (conf->dst.field == RTE_FLOW_FIELD_META ||
2370 [ # # ]: 0 : conf->dst.field == RTE_FLOW_FIELD_TAG ||
2371 : : conf->dst.field == RTE_FLOW_FIELD_METER_COLOR) {
2372 : 0 : meta = *(const unaligned_uint32_t *)item.spec;
2373 [ # # ]: 0 : meta = rte_cpu_to_be_32(meta);
2374 : 0 : item.spec = &meta;
2375 : : }
2376 [ # # # # ]: 0 : if (mlx5_dv_modify_ipv6_traffic_class_supported(dev->data->dev_private) &&
2377 : 0 : conf->dst.field == RTE_FLOW_FIELD_IPV6_DSCP &&
2378 [ # # ]: 0 : !(mask[0] & MLX5_IPV6_HDR_ECN_MASK)) {
2379 : 0 : dscp = *(const unaligned_uint32_t *)item.spec;
2380 : : /*
2381 : : * IPv6 DSCP uses OUT_IPV6_TRAFFIC_CLASS as ID but it starts from 2
2382 : : * bits left. Shift the data left for IPv6 DSCP
2383 : : */
2384 : 0 : dscp <<= MLX5_IPV6_HDR_DSCP_SHIFT;
2385 : 0 : item.spec = &dscp;
2386 : : }
2387 : : } else {
2388 : : type = MLX5_MODIFICATION_TYPE_COPY;
2389 : : /** For COPY fill the destination field (dcopy) without mask. */
2390 : 0 : mlx5_flow_field_id_to_modify_info(&conf->dst, dcopy, NULL,
2391 : 0 : conf->width, dev,
2392 : : attr, error);
2393 : : /** Then construct the source field (field) with mask. */
2394 : 0 : mlx5_flow_field_id_to_modify_info(&conf->src, field, mask,
2395 : 0 : conf->width, dev,
2396 : : attr, error);
2397 : : }
2398 : 0 : item.mask = &mask;
2399 : 0 : return mlx5_flow_dv_convert_modify_action(&item,
2400 : : field, dcopy, resource, type, error);
2401 : : }
2402 : :
2403 : : /**
2404 : : * Validate MARK item.
2405 : : *
2406 : : * @param[in] dev
2407 : : * Pointer to the rte_eth_dev structure.
2408 : : * @param[in] item
2409 : : * Item specification.
2410 : : * @param[in] attr
2411 : : * Attributes of flow that includes this item.
2412 : : * @param[out] error
2413 : : * Pointer to error structure.
2414 : : *
2415 : : * @return
2416 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2417 : : */
2418 : : static int
2419 : 0 : flow_dv_validate_item_mark(struct rte_eth_dev *dev,
2420 : : const struct rte_flow_item *item,
2421 : : const struct rte_flow_attr *attr __rte_unused,
2422 : : struct rte_flow_error *error)
2423 : : {
2424 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2425 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
2426 : 0 : const struct rte_flow_item_mark *spec = item->spec;
2427 : 0 : const struct rte_flow_item_mark *mask = item->mask;
2428 : 0 : const struct rte_flow_item_mark nic_mask = {
2429 : 0 : .id = priv->sh->dv_mark_mask,
2430 : : };
2431 : : int ret;
2432 : :
2433 [ # # ]: 0 : if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
2434 : 0 : return rte_flow_error_set(error, ENOTSUP,
2435 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2436 : : "extended metadata feature"
2437 : : " isn't enabled");
2438 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
2439 : 0 : return rte_flow_error_set(error, ENOTSUP,
2440 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2441 : : "extended metadata register"
2442 : : " isn't supported");
2443 [ # # ]: 0 : if (!nic_mask.id)
2444 : 0 : return rte_flow_error_set(error, ENOTSUP,
2445 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2446 : : "extended metadata register"
2447 : : " isn't available");
2448 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
2449 [ # # ]: 0 : if (ret < 0)
2450 : : return ret;
2451 [ # # ]: 0 : if (!spec)
2452 : 0 : return rte_flow_error_set(error, EINVAL,
2453 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2454 : 0 : item->spec,
2455 : : "data cannot be empty");
2456 [ # # ]: 0 : if (spec->id >= (MLX5_FLOW_MARK_MAX & nic_mask.id))
2457 : 0 : return rte_flow_error_set(error, EINVAL,
2458 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2459 : 0 : &spec->id,
2460 : : "mark id exceeds the limit");
2461 [ # # ]: 0 : if (!mask)
2462 : : mask = &nic_mask;
2463 [ # # ]: 0 : if (!mask->id)
2464 : 0 : return rte_flow_error_set(error, EINVAL,
2465 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2466 : : "mask cannot be zero");
2467 : :
2468 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2469 : : (const uint8_t *)&nic_mask,
2470 : : sizeof(struct rte_flow_item_mark),
2471 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2472 : : if (ret < 0)
2473 : : return ret;
2474 : : return 0;
2475 : : }
2476 : :
2477 : : /**
2478 : : * Validate META item.
2479 : : *
2480 : : * @param[in] dev
2481 : : * Pointer to the rte_eth_dev structure.
2482 : : * @param[in] item
2483 : : * Item specification.
2484 : : * @param[in] attr
2485 : : * Attributes of flow that includes this item.
2486 : : * @param[out] error
2487 : : * Pointer to error structure.
2488 : : *
2489 : : * @return
2490 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2491 : : */
2492 : : static int
2493 : 0 : flow_dv_validate_item_meta(struct rte_eth_dev *dev __rte_unused,
2494 : : const struct rte_flow_item *item,
2495 : : const struct rte_flow_attr *attr,
2496 : : struct rte_flow_error *error)
2497 : : {
2498 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2499 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
2500 : 0 : const struct rte_flow_item_meta *spec = item->spec;
2501 : 0 : const struct rte_flow_item_meta *mask = item->mask;
2502 : 0 : struct rte_flow_item_meta nic_mask = {
2503 : : .data = UINT32_MAX
2504 : : };
2505 : : int reg;
2506 : : int ret;
2507 : :
2508 [ # # ]: 0 : if (!spec)
2509 : 0 : return rte_flow_error_set(error, EINVAL,
2510 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2511 : : item->spec,
2512 : : "data cannot be empty");
2513 [ # # ]: 0 : if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
2514 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
2515 : 0 : return rte_flow_error_set(error, ENOTSUP,
2516 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2517 : : "extended metadata register"
2518 : : " isn't supported");
2519 : 0 : reg = flow_dv_get_metadata_reg(dev, attr, error);
2520 [ # # ]: 0 : if (reg < 0)
2521 : : return reg;
2522 [ # # ]: 0 : if (reg == REG_NON)
2523 : 0 : return rte_flow_error_set(error, ENOTSUP,
2524 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2525 : : "unavailable extended metadata register");
2526 [ # # ]: 0 : if (reg == REG_B)
2527 : 0 : return rte_flow_error_set(error, ENOTSUP,
2528 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2529 : : "match on reg_b "
2530 : : "isn't supported");
2531 [ # # ]: 0 : if (reg != REG_A)
2532 : 0 : nic_mask.data = priv->sh->dv_meta_mask;
2533 : : } else {
2534 [ # # ]: 0 : if (attr->transfer)
2535 : 0 : return rte_flow_error_set(error, ENOTSUP,
2536 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2537 : : "extended metadata feature "
2538 : : "should be enabled when "
2539 : : "meta item is requested "
2540 : : "with e-switch mode ");
2541 [ # # ]: 0 : if (attr->ingress)
2542 : 0 : return rte_flow_error_set(error, ENOTSUP,
2543 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2544 : : "match on metadata for ingress "
2545 : : "is not supported in legacy "
2546 : : "metadata mode");
2547 : : }
2548 [ # # ]: 0 : if (!mask)
2549 : : mask = &rte_flow_item_meta_mask;
2550 [ # # ]: 0 : if (!mask->data)
2551 : 0 : return rte_flow_error_set(error, EINVAL,
2552 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2553 : : "mask cannot be zero");
2554 : :
2555 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2556 : : (const uint8_t *)&nic_mask,
2557 : : sizeof(struct rte_flow_item_meta),
2558 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2559 : 0 : return ret;
2560 : : }
2561 : :
2562 : : /**
2563 : : * Validate TAG item.
2564 : : *
2565 : : * @param[in] dev
2566 : : * Pointer to the rte_eth_dev structure.
2567 : : * @param[in] item
2568 : : * Item specification.
2569 : : * @param[in] tag_bitmap
2570 : : * Tag index bitmap.
2571 : : * @param[in] attr
2572 : : * Attributes of flow that includes this item.
2573 : : * @param[out] error
2574 : : * Pointer to error structure.
2575 : : *
2576 : : * @return
2577 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2578 : : */
2579 : : static int
2580 : 0 : flow_dv_validate_item_tag(struct rte_eth_dev *dev,
2581 : : const struct rte_flow_item *item,
2582 : : uint32_t *tag_bitmap,
2583 : : const struct rte_flow_attr *attr __rte_unused,
2584 : : struct rte_flow_error *error)
2585 : : {
2586 : 0 : const struct rte_flow_item_tag *spec = item->spec;
2587 : 0 : const struct rte_flow_item_tag *mask = item->mask;
2588 : 0 : const struct rte_flow_item_tag nic_mask = {
2589 : : .data = RTE_BE32(UINT32_MAX),
2590 : : .index = 0xff,
2591 : : };
2592 : : int ret;
2593 : :
2594 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
2595 : 0 : return rte_flow_error_set(error, ENOTSUP,
2596 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2597 : : "extensive metadata register"
2598 : : " isn't supported");
2599 [ # # ]: 0 : if (!spec)
2600 : 0 : return rte_flow_error_set(error, EINVAL,
2601 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2602 : 0 : item->spec,
2603 : : "data cannot be empty");
2604 [ # # ]: 0 : if (!mask)
2605 : : mask = &rte_flow_item_tag_mask;
2606 [ # # ]: 0 : if (!mask->data)
2607 : 0 : return rte_flow_error_set(error, EINVAL,
2608 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2609 : : "mask cannot be zero");
2610 : :
2611 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2612 : : (const uint8_t *)&nic_mask,
2613 : : sizeof(struct rte_flow_item_tag),
2614 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2615 [ # # ]: 0 : if (ret < 0)
2616 : : return ret;
2617 [ # # ]: 0 : if (mask->index != 0xff)
2618 : 0 : return rte_flow_error_set(error, EINVAL,
2619 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2620 : : "partial mask for tag index"
2621 : : " is not supported");
2622 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, spec->index, error);
2623 [ # # ]: 0 : if (ret < 0)
2624 : : return ret;
2625 : : MLX5_ASSERT(ret != REG_NON);
2626 [ # # ]: 0 : if (*tag_bitmap & (1 << ret))
2627 : 0 : return rte_flow_error_set(error, EINVAL,
2628 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2629 : 0 : item->spec,
2630 : : "Duplicated tag index");
2631 : 0 : *tag_bitmap |= 1 << ret;
2632 : 0 : return 0;
2633 : : }
2634 : :
2635 : : /**
2636 : : * Validate vport item.
2637 : : *
2638 : : * @param[in] dev
2639 : : * Pointer to the rte_eth_dev structure.
2640 : : * @param[in] item
2641 : : * Item specification.
2642 : : * @param[in] attr
2643 : : * Attributes of flow that includes this item.
2644 : : * @param[in] item_flags
2645 : : * Bit-fields that holds the items detected until now.
2646 : : * @param[out] error
2647 : : * Pointer to error structure.
2648 : : *
2649 : : * @return
2650 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2651 : : */
2652 : : static int
2653 : 0 : flow_dv_validate_item_port_id(struct rte_eth_dev *dev,
2654 : : const struct rte_flow_item *item,
2655 : : const struct rte_flow_attr *attr,
2656 : : uint64_t item_flags,
2657 : : struct mlx5_priv **act_priv,
2658 : : struct rte_flow_error *error)
2659 : : {
2660 : 0 : const struct rte_flow_item_port_id *spec = item->spec;
2661 : 0 : const struct rte_flow_item_port_id *mask = item->mask;
2662 : 0 : const struct rte_flow_item_port_id switch_mask = {
2663 : : .id = 0xffffffff,
2664 : : };
2665 : : struct mlx5_priv *esw_priv;
2666 : : struct mlx5_priv *dev_priv;
2667 : : int ret;
2668 : :
2669 [ # # ]: 0 : if (!attr->transfer)
2670 : 0 : return rte_flow_error_set(error, EINVAL,
2671 : : RTE_FLOW_ERROR_TYPE_ITEM,
2672 : : NULL,
2673 : : "match on port id is valid only"
2674 : : " when transfer flag is enabled");
2675 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_PORT_ID)
2676 : 0 : return rte_flow_error_set(error, ENOTSUP,
2677 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2678 : : "multiple source ports are not"
2679 : : " supported");
2680 [ # # ]: 0 : if (!mask)
2681 : : mask = &switch_mask;
2682 [ # # ]: 0 : if (mask->id != 0xffffffff)
2683 : 0 : return rte_flow_error_set(error, ENOTSUP,
2684 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK,
2685 : : mask,
2686 : : "no support for partial mask on"
2687 : : " \"id\" field");
2688 : 0 : ret = mlx5_flow_item_acceptable
2689 : : (dev, item, (const uint8_t *)mask,
2690 : : (const uint8_t *)&rte_flow_item_port_id_mask,
2691 : : sizeof(struct rte_flow_item_port_id),
2692 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2693 [ # # ]: 0 : if (ret)
2694 : : return ret;
2695 [ # # ]: 0 : if (!spec)
2696 : : return 0;
2697 [ # # ]: 0 : if (spec->id == MLX5_PORT_ESW_MGR)
2698 : : return 0;
2699 : 0 : esw_priv = mlx5_port_to_eswitch_info(spec->id, false);
2700 [ # # ]: 0 : if (!esw_priv)
2701 : 0 : return rte_flow_error_set(error, rte_errno,
2702 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2703 : : "failed to obtain E-Switch info for"
2704 : : " port");
2705 : 0 : dev_priv = mlx5_dev_to_eswitch_info(dev);
2706 [ # # ]: 0 : if (!dev_priv)
2707 : 0 : return rte_flow_error_set(error, rte_errno,
2708 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2709 : : NULL,
2710 : : "failed to obtain E-Switch info");
2711 [ # # ]: 0 : if (esw_priv->domain_id != dev_priv->domain_id)
2712 : 0 : return rte_flow_error_set(error, EINVAL,
2713 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2714 : : "cannot match on a port from a"
2715 : : " different E-Switch");
2716 : 0 : *act_priv = esw_priv;
2717 : 0 : return 0;
2718 : : }
2719 : :
2720 : : /**
2721 : : * Validate represented port item.
2722 : : *
2723 : : * @param[in] dev
2724 : : * Pointer to the rte_eth_dev structure.
2725 : : * @param[in] item
2726 : : * Item specification.
2727 : : * @param[in] attr
2728 : : * Attributes of flow that includes this item.
2729 : : * @param[in] item_flags
2730 : : * Bit-fields that holds the items detected until now.
2731 : : * @param[out] error
2732 : : * Pointer to error structure.
2733 : : *
2734 : : * @return
2735 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2736 : : */
2737 : : static int
2738 : 0 : flow_dv_validate_item_represented_port(struct rte_eth_dev *dev,
2739 : : const struct rte_flow_item *item,
2740 : : const struct rte_flow_attr *attr,
2741 : : uint64_t item_flags,
2742 : : struct mlx5_priv **act_priv,
2743 : : struct rte_flow_error *error)
2744 : : {
2745 : 0 : const struct rte_flow_item_ethdev *spec = item->spec;
2746 : 0 : const struct rte_flow_item_ethdev *mask = item->mask;
2747 : 0 : const struct rte_flow_item_ethdev switch_mask = {
2748 : : .port_id = UINT16_MAX,
2749 : : };
2750 : : struct mlx5_priv *esw_priv;
2751 : : struct mlx5_priv *dev_priv;
2752 : : int ret;
2753 : :
2754 [ # # ]: 0 : if (!attr->transfer)
2755 : 0 : return rte_flow_error_set(error, EINVAL,
2756 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2757 : : "match on port id is valid only when transfer flag is enabled");
2758 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_REPRESENTED_PORT)
2759 : 0 : return rte_flow_error_set(error, ENOTSUP,
2760 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2761 : : "multiple source ports are not supported");
2762 [ # # ]: 0 : if (!mask)
2763 : : mask = &switch_mask;
2764 [ # # ]: 0 : if (mask->port_id != UINT16_MAX)
2765 : 0 : return rte_flow_error_set(error, ENOTSUP,
2766 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2767 : : "no support for partial mask on \"id\" field");
2768 : 0 : ret = mlx5_flow_item_acceptable
2769 : : (dev, item, (const uint8_t *)mask,
2770 : : (const uint8_t *)&rte_flow_item_ethdev_mask,
2771 : : sizeof(struct rte_flow_item_ethdev),
2772 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2773 [ # # ]: 0 : if (ret)
2774 : : return ret;
2775 [ # # # # ]: 0 : if (!spec || spec->port_id == UINT16_MAX)
2776 : : return 0;
2777 : 0 : esw_priv = mlx5_port_to_eswitch_info(spec->port_id, false);
2778 [ # # ]: 0 : if (!esw_priv)
2779 : 0 : return rte_flow_error_set(error, rte_errno,
2780 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2781 : : "failed to obtain E-Switch info for port");
2782 : 0 : dev_priv = mlx5_dev_to_eswitch_info(dev);
2783 [ # # ]: 0 : if (!dev_priv)
2784 : 0 : return rte_flow_error_set(error, rte_errno,
2785 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2786 : : NULL,
2787 : : "failed to obtain E-Switch info");
2788 [ # # ]: 0 : if (esw_priv->domain_id != dev_priv->domain_id)
2789 : 0 : return rte_flow_error_set(error, EINVAL,
2790 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2791 : : "cannot match on a port from a different E-Switch");
2792 : 0 : *act_priv = esw_priv;
2793 : 0 : return 0;
2794 : : }
2795 : :
2796 : : /**
2797 : : * Validate VLAN item.
2798 : : *
2799 : : * @param[in] item
2800 : : * Item specification.
2801 : : * @param[in] item_flags
2802 : : * Bit-fields that holds the items detected until now.
2803 : : * @param[in] dev
2804 : : * Ethernet device flow is being created on.
2805 : : * @param[out] error
2806 : : * Pointer to error structure.
2807 : : *
2808 : : * @return
2809 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2810 : : */
2811 : : int
2812 : 0 : mlx5_flow_dv_validate_item_vlan(const struct rte_flow_item *item,
2813 : : uint64_t item_flags,
2814 : : struct rte_eth_dev *dev,
2815 : : struct rte_flow_error *error)
2816 : : {
2817 : 0 : const struct rte_flow_item_vlan *mask = item->mask;
2818 : 0 : const struct rte_flow_item_vlan nic_mask = {
2819 : : .hdr.vlan_tci = RTE_BE16(UINT16_MAX),
2820 : : .hdr.eth_proto = RTE_BE16(UINT16_MAX),
2821 : : .has_more_vlan = 1,
2822 : : };
2823 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2824 : : int ret;
2825 : : const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
2826 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L4) :
2827 : : (MLX5_FLOW_LAYER_OUTER_L3 |
2828 : : MLX5_FLOW_LAYER_OUTER_L4);
2829 [ # # ]: 0 : const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
2830 : : MLX5_FLOW_LAYER_OUTER_VLAN;
2831 : :
2832 [ # # ]: 0 : if (item_flags & vlanm)
2833 : 0 : return rte_flow_error_set(error, EINVAL,
2834 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2835 : : "multiple VLAN layers not supported");
2836 [ # # ]: 0 : else if ((item_flags & l34m) != 0)
2837 : 0 : return rte_flow_error_set(error, EINVAL,
2838 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2839 : : "VLAN cannot follow L3/L4 layer");
2840 [ # # ]: 0 : if (!mask)
2841 : : mask = &rte_flow_item_vlan_mask;
2842 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2843 : : (const uint8_t *)&nic_mask,
2844 : : sizeof(struct rte_flow_item_vlan),
2845 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2846 [ # # ]: 0 : if (ret)
2847 : : return ret;
2848 [ # # # # ]: 0 : if (!tunnel && mask->hdr.vlan_tci != RTE_BE16(0x0fff)) {
2849 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2850 : :
2851 [ # # ]: 0 : if (priv->vmwa_context) {
2852 : : /*
2853 : : * Non-NULL context means we have a virtual machine
2854 : : * and SR-IOV enabled, we have to create VLAN interface
2855 : : * to make hypervisor to setup E-Switch vport
2856 : : * context correctly. We avoid creating the multiple
2857 : : * VLAN interfaces, so we cannot support VLAN tag mask.
2858 : : */
2859 : 0 : return rte_flow_error_set(error, EINVAL,
2860 : : RTE_FLOW_ERROR_TYPE_ITEM,
2861 : : item,
2862 : : "VLAN tag mask is not"
2863 : : " supported in virtual"
2864 : : " environment");
2865 : : }
2866 : : }
2867 : : return 0;
2868 : : }
2869 : :
2870 : : /*
2871 : : * GTP flags are contained in 1 byte of the format:
2872 : : * -------------------------------------------
2873 : : * | bit | 0 - 2 | 3 | 4 | 5 | 6 | 7 |
2874 : : * |-----------------------------------------|
2875 : : * | value | Version | PT | Res | E | S | PN |
2876 : : * -------------------------------------------
2877 : : *
2878 : : * Matching is supported only for GTP flags E, S, PN.
2879 : : */
2880 : : #define MLX5_GTP_FLAGS_MASK 0x07
2881 : :
2882 : : /**
2883 : : * Validate GTP item.
2884 : : *
2885 : : * @param[in] dev
2886 : : * Pointer to the rte_eth_dev structure.
2887 : : * @param[in] item
2888 : : * Item specification.
2889 : : * @param[in] item_flags
2890 : : * Bit-fields that holds the items detected until now.
2891 : : * @param[out] error
2892 : : * Pointer to error structure.
2893 : : *
2894 : : * @return
2895 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2896 : : */
2897 : : int
2898 : 0 : mlx5_flow_dv_validate_item_gtp(struct rte_eth_dev *dev,
2899 : : const struct rte_flow_item *item,
2900 : : uint64_t item_flags,
2901 : : struct rte_flow_error *error)
2902 : : {
2903 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2904 : 0 : const struct rte_flow_item_gtp *spec = item->spec;
2905 : 0 : const struct rte_flow_item_gtp *mask = item->mask;
2906 : 0 : const struct rte_flow_item_gtp nic_mask = {
2907 : : .hdr.gtp_hdr_info = MLX5_GTP_FLAGS_MASK,
2908 : : .hdr.msg_type = 0xff,
2909 : : .hdr.teid = RTE_BE32(0xffffffff),
2910 : : };
2911 : :
2912 [ # # ]: 0 : if (!priv->sh->cdev->config.hca_attr.tunnel_stateless_gtp)
2913 : 0 : return rte_flow_error_set(error, ENOTSUP,
2914 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2915 : : "GTP support is not enabled");
2916 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2917 : 0 : return rte_flow_error_set(error, ENOTSUP,
2918 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2919 : : "multiple tunnel layers not"
2920 : : " supported");
2921 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
2922 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2923 : 0 : return rte_flow_error_set(error, EINVAL,
2924 : : RTE_FLOW_ERROR_TYPE_ITEM,
2925 : : item, "no outer UDP layer found");
2926 : : }
2927 [ # # ]: 0 : if (!mask)
2928 : : mask = &rte_flow_item_gtp_mask;
2929 [ # # # # ]: 0 : if (spec && spec->hdr.gtp_hdr_info & ~MLX5_GTP_FLAGS_MASK)
2930 : 0 : return rte_flow_error_set(error, ENOTSUP,
2931 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2932 : : "Match is supported for GTP"
2933 : : " flags only");
2934 : 0 : return mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2935 : : (const uint8_t *)&nic_mask,
2936 : : sizeof(struct rte_flow_item_gtp),
2937 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2938 : : }
2939 : :
2940 : : /**
2941 : : * Validate GTP PSC item.
2942 : : *
2943 : : * @param[in] item
2944 : : * Item specification.
2945 : : * @param[in] last_item
2946 : : * Previous validated item in the pattern items.
2947 : : * @param[in] gtp_item
2948 : : * Previous GTP item specification.
2949 : : * @param root
2950 : : * Whether action is on root table.
2951 : : * @param[out] error
2952 : : * Pointer to error structure.
2953 : : *
2954 : : * @return
2955 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2956 : : */
2957 : : int
2958 : 0 : mlx5_flow_dv_validate_item_gtp_psc(const struct rte_eth_dev *dev,
2959 : : const struct rte_flow_item *item,
2960 : : uint64_t last_item,
2961 : : const struct rte_flow_item *gtp_item,
2962 : : bool root,
2963 : : struct rte_flow_error *error)
2964 : : {
2965 : : const struct rte_flow_item_gtp *gtp_spec;
2966 : : const struct rte_flow_item_gtp *gtp_mask;
2967 : : const struct rte_flow_item_gtp_psc *mask;
2968 : 0 : const struct rte_flow_item_gtp_psc nic_mask = {
2969 : : .hdr.type = 0xF,
2970 : : .hdr.qfi = 0x3F,
2971 : : };
2972 : :
2973 [ # # # # ]: 0 : if (!gtp_item || !(last_item & MLX5_FLOW_LAYER_GTP))
2974 : 0 : return rte_flow_error_set
2975 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2976 : : "GTP PSC item must be preceded with GTP item");
2977 : 0 : gtp_spec = gtp_item->spec;
2978 [ # # ]: 0 : gtp_mask = gtp_item->mask ? gtp_item->mask : &rte_flow_item_gtp_mask;
2979 : : /* GTP spec and E flag is requested to match zero. */
2980 [ # # ]: 0 : if (gtp_spec &&
2981 : 0 : (gtp_mask->hdr.gtp_hdr_info &
2982 [ # # ]: 0 : ~gtp_spec->hdr.gtp_hdr_info & MLX5_GTP_EXT_HEADER_FLAG))
2983 : 0 : return rte_flow_error_set
2984 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2985 : : "GTP E flag must be 1 to match GTP PSC");
2986 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
2987 : : /* Check the flow is not created in group zero. */
2988 [ # # ]: 0 : if (root)
2989 : 0 : return rte_flow_error_set
2990 : : (error, ENOTSUP,
2991 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2992 : : "GTP PSC is not supported for group 0");
2993 : : /* GTP spec is here and E flag is requested to match zero. */
2994 [ # # ]: 0 : if (!item->spec)
2995 : : return 0;
2996 : : }
2997 [ # # ]: 0 : mask = item->mask ? item->mask : &rte_flow_item_gtp_psc_mask;
2998 : 0 : return mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2999 : : (const uint8_t *)&nic_mask,
3000 : : sizeof(struct rte_flow_item_gtp_psc),
3001 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3002 : : }
3003 : :
3004 : : /*
3005 : : * Validate IPV4 item.
3006 : : * Use existing validation function mlx5_flow_validate_item_ipv4(), and
3007 : : * add specific validation of fragment_offset field,
3008 : : *
3009 : : * @param[in] dev
3010 : : * Pointer to the rte_eth_dev structure.
3011 : : * @param[in] item
3012 : : * Item specification.
3013 : : * @param[in] item_flags
3014 : : * Bit-fields that holds the items detected until now.
3015 : : * @param[in] last_item
3016 : : * Previous validated item in the pattern items.
3017 : : * @param[in] ether_type
3018 : : * Type in the ethernet layer header (including dot1q).
3019 : : * @param[in] acc_mask
3020 : : * Default acceptable mask (will be adjusted).
3021 : : * @param[out] error
3022 : : * Pointer to error structure.
3023 : : *
3024 : : * @return
3025 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3026 : : */
3027 : : int
3028 : 0 : mlx5_flow_dv_validate_item_ipv4(struct rte_eth_dev *dev,
3029 : : const struct rte_flow_item *item,
3030 : : uint64_t item_flags,
3031 : : uint64_t last_item,
3032 : : uint16_t ether_type,
3033 : : const struct rte_flow_item_ipv4 *acc_mask,
3034 : : struct rte_flow_error *error)
3035 : : {
3036 : : int ret;
3037 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3038 : 0 : struct mlx5_hca_attr *attr = &priv->sh->cdev->config.hca_attr;
3039 : 0 : const struct rte_flow_item_ipv4 *spec = item->spec;
3040 : 0 : const struct rte_flow_item_ipv4 *last = item->last;
3041 : 0 : const struct rte_flow_item_ipv4 *mask = item->mask;
3042 : : rte_be16_t fragment_offset_spec = 0;
3043 : : rte_be16_t fragment_offset_last = 0;
3044 : 0 : struct rte_flow_item_ipv4 actual_ipv4_mask = *acc_mask;
3045 : :
3046 [ # # # # ]: 0 : if (mask && (mask->hdr.version_ihl & RTE_IPV4_HDR_IHL_MASK)) {
3047 : 0 : int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
3048 : : bool ihl_cap = !tunnel ?
3049 [ # # ]: 0 : attr->outer_ipv4_ihl : attr->inner_ipv4_ihl;
3050 [ # # ]: 0 : if (!ihl_cap)
3051 : 0 : return rte_flow_error_set(error, ENOTSUP,
3052 : : RTE_FLOW_ERROR_TYPE_ITEM,
3053 : : item,
3054 : : "IPV4 ihl offload not supported");
3055 : 0 : actual_ipv4_mask.hdr.version_ihl = mask->hdr.version_ihl;
3056 : : }
3057 : 0 : ret = mlx5_flow_validate_item_ipv4(dev, item, item_flags, last_item,
3058 : : ether_type, &actual_ipv4_mask,
3059 : : MLX5_ITEM_RANGE_ACCEPTED, error);
3060 [ # # ]: 0 : if (ret < 0)
3061 : : return ret;
3062 [ # # ]: 0 : if (spec && mask)
3063 : 0 : fragment_offset_spec = spec->hdr.fragment_offset &
3064 : 0 : mask->hdr.fragment_offset;
3065 [ # # ]: 0 : if (!fragment_offset_spec)
3066 : : return 0;
3067 : : /*
3068 : : * spec and mask are valid, enforce using full mask to make sure the
3069 : : * complete value is used correctly.
3070 : : */
3071 [ # # ]: 0 : if ((mask->hdr.fragment_offset & RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
3072 : : != RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
3073 : 0 : return rte_flow_error_set(error, EINVAL,
3074 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK,
3075 : : item, "must use full mask for"
3076 : : " fragment_offset");
3077 : : /*
3078 : : * Match on fragment_offset 0x2000 means MF is 1 and frag-offset is 0,
3079 : : * indicating this is 1st fragment of fragmented packet.
3080 : : * This is not yet supported in MLX5, return appropriate error message.
3081 : : */
3082 [ # # ]: 0 : if (fragment_offset_spec == RTE_BE16(RTE_IPV4_HDR_MF_FLAG))
3083 : 0 : return rte_flow_error_set(error, ENOTSUP,
3084 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3085 : : "match on first fragment not "
3086 : : "supported");
3087 [ # # ]: 0 : if (fragment_offset_spec && !last)
3088 : 0 : return rte_flow_error_set(error, ENOTSUP,
3089 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3090 : : "specified value not supported");
3091 : : /* spec and last are valid, validate the specified range. */
3092 : 0 : fragment_offset_last = last->hdr.fragment_offset &
3093 : : mask->hdr.fragment_offset;
3094 : : /*
3095 : : * Match on fragment_offset spec 0x2001 and last 0x3fff
3096 : : * means MF is 1 and frag-offset is > 0.
3097 : : * This packet is fragment 2nd and onward, excluding last.
3098 : : * This is not yet supported in MLX5, return appropriate
3099 : : * error message.
3100 : : */
3101 : 0 : if (fragment_offset_spec == RTE_BE16(RTE_IPV4_HDR_MF_FLAG + 1) &&
3102 [ # # ]: 0 : fragment_offset_last == RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
3103 : 0 : return rte_flow_error_set(error, ENOTSUP,
3104 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST,
3105 : : last, "match on following "
3106 : : "fragments not supported");
3107 : : /*
3108 : : * Match on fragment_offset spec 0x0001 and last 0x1fff
3109 : : * means MF is 0 and frag-offset is > 0.
3110 : : * This packet is last fragment of fragmented packet.
3111 : : * This is not yet supported in MLX5, return appropriate
3112 : : * error message.
3113 : : */
3114 : 0 : if (fragment_offset_spec == RTE_BE16(1) &&
3115 [ # # ]: 0 : fragment_offset_last == RTE_BE16(RTE_IPV4_HDR_OFFSET_MASK))
3116 : 0 : return rte_flow_error_set(error, ENOTSUP,
3117 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST,
3118 : : last, "match on last "
3119 : : "fragment not supported");
3120 : : /*
3121 : : * Match on fragment_offset spec 0x0001 and last 0x3fff
3122 : : * means MF and/or frag-offset is not 0.
3123 : : * This is a fragmented packet.
3124 : : * Other range values are invalid and rejected.
3125 : : */
3126 : 0 : if (!(fragment_offset_spec == RTE_BE16(1) &&
3127 [ # # ]: 0 : fragment_offset_last == RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK)))
3128 : 0 : return rte_flow_error_set(error, ENOTSUP,
3129 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST, last,
3130 : : "specified range not supported");
3131 : : return 0;
3132 : : }
3133 : :
3134 : : /**
3135 : : * Validate IPV6 fragment extension item.
3136 : : *
3137 : : * @param[in] item
3138 : : * Item specification.
3139 : : * @param[in] item_flags
3140 : : * Bit-fields that holds the items detected until now.
3141 : : * @param[out] error
3142 : : * Pointer to error structure.
3143 : : *
3144 : : * @return
3145 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3146 : : */
3147 : : static int
3148 : 0 : flow_dv_validate_item_ipv6_frag_ext(const struct rte_eth_dev *dev,
3149 : : const struct rte_flow_item *item,
3150 : : uint64_t item_flags,
3151 : : struct rte_flow_error *error)
3152 : : {
3153 : 0 : const struct rte_flow_item_ipv6_frag_ext *spec = item->spec;
3154 : 0 : const struct rte_flow_item_ipv6_frag_ext *last = item->last;
3155 : 0 : const struct rte_flow_item_ipv6_frag_ext *mask = item->mask;
3156 : : rte_be16_t frag_data_spec = 0;
3157 : : rte_be16_t frag_data_last = 0;
3158 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
3159 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
3160 : : MLX5_FLOW_LAYER_OUTER_L4;
3161 : : int ret = 0;
3162 : 0 : struct rte_flow_item_ipv6_frag_ext nic_mask = {
3163 : : .hdr = {
3164 : : .next_header = 0xff,
3165 : : .frag_data = RTE_BE16(0xffff),
3166 : : },
3167 : : };
3168 : :
3169 [ # # ]: 0 : if (item_flags & l4m)
3170 : 0 : return rte_flow_error_set(error, EINVAL,
3171 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3172 : : "ipv6 fragment extension item cannot "
3173 : : "follow L4 item.");
3174 [ # # # # : 0 : if ((tunnel && !(item_flags & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
# # ]
3175 [ # # ]: 0 : (!tunnel && !(item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV6)))
3176 : 0 : return rte_flow_error_set(error, EINVAL,
3177 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3178 : : "ipv6 fragment extension item must "
3179 : : "follow ipv6 item");
3180 [ # # ]: 0 : if (spec && mask)
3181 : 0 : frag_data_spec = spec->hdr.frag_data & mask->hdr.frag_data;
3182 [ # # ]: 0 : if (!frag_data_spec)
3183 : : return 0;
3184 : : /*
3185 : : * spec and mask are valid, enforce using full mask to make sure the
3186 : : * complete value is used correctly.
3187 : : */
3188 [ # # ]: 0 : if ((mask->hdr.frag_data & RTE_BE16(RTE_IPV6_FRAG_USED_MASK)) !=
3189 : : RTE_BE16(RTE_IPV6_FRAG_USED_MASK))
3190 : 0 : return rte_flow_error_set(error, EINVAL,
3191 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK,
3192 : : item, "must use full mask for"
3193 : : " frag_data");
3194 : : /*
3195 : : * Match on frag_data 0x00001 means M is 1 and frag-offset is 0.
3196 : : * This is 1st fragment of fragmented packet.
3197 : : */
3198 [ # # ]: 0 : if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_MF_MASK))
3199 : 0 : return rte_flow_error_set(error, ENOTSUP,
3200 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3201 : : "match on first fragment not "
3202 : : "supported");
3203 [ # # ]: 0 : if (frag_data_spec && !last)
3204 : 0 : return rte_flow_error_set(error, EINVAL,
3205 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3206 : : "specified value not supported");
3207 : 0 : ret = mlx5_flow_item_acceptable
3208 : : (dev, item, (const uint8_t *)mask,
3209 : : (const uint8_t *)&nic_mask,
3210 : : sizeof(struct rte_flow_item_ipv6_frag_ext),
3211 : : MLX5_ITEM_RANGE_ACCEPTED, error);
3212 [ # # ]: 0 : if (ret)
3213 : : return ret;
3214 : : /* spec and last are valid, validate the specified range. */
3215 : 0 : frag_data_last = last->hdr.frag_data & mask->hdr.frag_data;
3216 : : /*
3217 : : * Match on frag_data spec 0x0009 and last 0xfff9
3218 : : * means M is 1 and frag-offset is > 0.
3219 : : * This packet is fragment 2nd and onward, excluding last.
3220 : : * This is not yet supported in MLX5, return appropriate
3221 : : * error message.
3222 : : */
3223 : 0 : if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_FO_ALIGN |
3224 : 0 : RTE_IPV6_EHDR_MF_MASK) &&
3225 [ # # ]: 0 : frag_data_last == RTE_BE16(RTE_IPV6_FRAG_USED_MASK))
3226 : 0 : return rte_flow_error_set(error, ENOTSUP,
3227 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST,
3228 : : last, "match on following "
3229 : : "fragments not supported");
3230 : : /*
3231 : : * Match on frag_data spec 0x0008 and last 0xfff8
3232 : : * means M is 0 and frag-offset is > 0.
3233 : : * This packet is last fragment of fragmented packet.
3234 : : * This is not yet supported in MLX5, return appropriate
3235 : : * error message.
3236 : : */
3237 : 0 : if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_FO_ALIGN) &&
3238 [ # # ]: 0 : frag_data_last == RTE_BE16(RTE_IPV6_EHDR_FO_MASK))
3239 : 0 : return rte_flow_error_set(error, ENOTSUP,
3240 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST,
3241 : : last, "match on last "
3242 : : "fragment not supported");
3243 : : /* Other range values are invalid and rejected. */
3244 : 0 : return rte_flow_error_set(error, EINVAL,
3245 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST, last,
3246 : : "specified range not supported");
3247 : : }
3248 : :
3249 : : /*
3250 : : * Validate ASO CT item.
3251 : : *
3252 : : * @param[in] dev
3253 : : * Pointer to the rte_eth_dev structure.
3254 : : * @param[in] item
3255 : : * Item specification.
3256 : : * @param[in] item_flags
3257 : : * Pointer to bit-fields that holds the items detected until now.
3258 : : * @param[out] error
3259 : : * Pointer to error structure.
3260 : : *
3261 : : * @return
3262 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3263 : : */
3264 : : int
3265 : 0 : mlx5_flow_dv_validate_item_aso_ct(struct rte_eth_dev *dev,
3266 : : const struct rte_flow_item *item,
3267 : : uint64_t *item_flags,
3268 : : struct rte_flow_error *error)
3269 : : {
3270 : 0 : const struct rte_flow_item_conntrack *spec = item->spec;
3271 : 0 : const struct rte_flow_item_conntrack *mask = item->mask;
3272 : : uint32_t flags;
3273 : :
3274 [ # # ]: 0 : if (*item_flags & MLX5_FLOW_LAYER_ASO_CT)
3275 : 0 : return rte_flow_error_set(error, EINVAL,
3276 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
3277 : : "Only one CT is supported");
3278 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
3279 [ # # ]: 0 : if (!mask)
3280 : : mask = &rte_flow_item_conntrack_mask;
3281 : 0 : flags = spec->flags & mask->flags;
3282 [ # # ]: 0 : if ((flags & RTE_FLOW_CONNTRACK_PKT_STATE_VALID) &&
3283 : : ((flags & RTE_FLOW_CONNTRACK_PKT_STATE_INVALID) ||
3284 [ # # ]: 0 : (flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD) ||
3285 : : (flags & RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED)))
3286 : 0 : return rte_flow_error_set(error, EINVAL,
3287 : : RTE_FLOW_ERROR_TYPE_ITEM,
3288 : : NULL,
3289 : : "Conflict status bits");
3290 [ # # ]: 0 : if (spec->flags & ~MLX5_FLOW_CONNTRACK_PKT_STATE_ALL)
3291 : 0 : return rte_flow_error_set(error, EINVAL,
3292 : : RTE_FLOW_ERROR_TYPE_ITEM,
3293 : : NULL,
3294 : : "Invalid CT item flags");
3295 : : }
3296 : : /* State change also needs to be considered. */
3297 : 0 : *item_flags |= MLX5_FLOW_LAYER_ASO_CT;
3298 : 0 : return 0;
3299 : : }
3300 : :
3301 : : /**
3302 : : * Validate the pop VLAN action.
3303 : : *
3304 : : * @param[in] dev
3305 : : * Pointer to the rte_eth_dev structure.
3306 : : * @param[in] action_flags
3307 : : * Holds the actions detected until now.
3308 : : * @param[in] action
3309 : : * Pointer to the pop vlan action.
3310 : : * @param[in] item_flags
3311 : : * The items found in this flow rule.
3312 : : * @param[in] attr
3313 : : * Pointer to flow attributes.
3314 : : * @param[out] error
3315 : : * Pointer to error structure.
3316 : : *
3317 : : * @return
3318 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3319 : : */
3320 : : static int
3321 : 0 : flow_dv_validate_action_pop_vlan(struct rte_eth_dev *dev,
3322 : : uint64_t action_flags,
3323 : : const struct rte_flow_action *action,
3324 : : uint64_t item_flags,
3325 : : const struct rte_flow_attr *attr,
3326 : : struct rte_flow_error *error)
3327 : : {
3328 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
3329 : :
3330 [ # # ]: 0 : if (!priv->sh->pop_vlan_action)
3331 : 0 : return rte_flow_error_set(error, ENOTSUP,
3332 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3333 : : NULL,
3334 : : "pop vlan action is not supported");
3335 [ # # ]: 0 : if (action_flags & MLX5_FLOW_VLAN_ACTIONS)
3336 : 0 : return rte_flow_error_set(error, ENOTSUP,
3337 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3338 : : "no support for multiple VLAN "
3339 : : "actions");
3340 : : /* Pop VLAN with preceding Decap requires inner header with VLAN. */
3341 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_DECAP) &&
3342 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_INNER_VLAN))
3343 : 0 : return rte_flow_error_set(error, ENOTSUP,
3344 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3345 : : NULL,
3346 : : "cannot pop vlan after decap without "
3347 : : "match on inner vlan in the flow");
3348 : : /* Pop VLAN without preceding Decap requires outer header with VLAN. */
3349 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_ACTION_DECAP) &&
3350 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
3351 : 0 : return rte_flow_error_set(error, ENOTSUP,
3352 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3353 : : NULL,
3354 : : "cannot pop vlan without a "
3355 : : "match on (outer) vlan in the flow");
3356 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3357 : 0 : return rte_flow_error_set(error, EINVAL,
3358 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3359 : : "wrong action order, port_id should "
3360 : : "be after pop VLAN action");
3361 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
3362 : 0 : return rte_flow_error_set(error, ENOTSUP,
3363 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3364 : : "pop vlan action for VF representor "
3365 : : "not supported on NIC table");
3366 : : return 0;
3367 : : }
3368 : :
3369 : : /**
3370 : : * Get VLAN default info from vlan match info.
3371 : : *
3372 : : * @param[in] items
3373 : : * the list of item specifications.
3374 : : * @param[out] vlan
3375 : : * pointer VLAN info to fill to.
3376 : : *
3377 : : * @return
3378 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3379 : : */
3380 : : static void
3381 : 0 : flow_dev_get_vlan_info_from_items(const struct rte_flow_item *items,
3382 : : struct rte_vlan_hdr *vlan)
3383 : : {
3384 : 0 : const struct rte_flow_item_vlan nic_mask = {
3385 : : .hdr.vlan_tci = RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK |
3386 : : MLX5DV_FLOW_VLAN_VID_MASK),
3387 : : .hdr.eth_proto = RTE_BE16(0xffff),
3388 : : };
3389 : :
3390 [ # # ]: 0 : if (items == NULL)
3391 : 0 : return;
3392 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
3393 : 0 : int type = items->type;
3394 : :
3395 : 0 : if (type == RTE_FLOW_ITEM_TYPE_VLAN ||
3396 [ # # ]: 0 : type == MLX5_RTE_FLOW_ITEM_TYPE_VLAN)
3397 : : break;
3398 : : }
3399 [ # # ]: 0 : if (items->type != RTE_FLOW_ITEM_TYPE_END) {
3400 : 0 : const struct rte_flow_item_vlan *vlan_m = items->mask;
3401 : 0 : const struct rte_flow_item_vlan *vlan_v = items->spec;
3402 : :
3403 : : /* If VLAN item in pattern doesn't contain data, return here. */
3404 [ # # ]: 0 : if (!vlan_v)
3405 : : return;
3406 [ # # ]: 0 : if (!vlan_m)
3407 : : vlan_m = &nic_mask;
3408 : : /* Only full match values are accepted */
3409 [ # # ]: 0 : if ((vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) ==
3410 : : MLX5DV_FLOW_VLAN_PCP_MASK_BE) {
3411 : 0 : vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
3412 : 0 : vlan->vlan_tci |=
3413 [ # # ]: 0 : rte_be_to_cpu_16(vlan_v->hdr.vlan_tci &
3414 : : MLX5DV_FLOW_VLAN_PCP_MASK_BE);
3415 : : }
3416 [ # # ]: 0 : if ((vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) ==
3417 : : MLX5DV_FLOW_VLAN_VID_MASK_BE) {
3418 : 0 : vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
3419 : 0 : vlan->vlan_tci |=
3420 [ # # ]: 0 : rte_be_to_cpu_16(vlan_v->hdr.vlan_tci &
3421 : : MLX5DV_FLOW_VLAN_VID_MASK_BE);
3422 : : }
3423 [ # # ]: 0 : if (vlan_m->hdr.eth_proto == nic_mask.hdr.eth_proto)
3424 [ # # ]: 0 : vlan->eth_proto = rte_be_to_cpu_16(vlan_v->hdr.eth_proto &
3425 : : vlan_m->hdr.eth_proto);
3426 : : }
3427 : : }
3428 : :
3429 : : /**
3430 : : * Validate the push VLAN action.
3431 : : *
3432 : : * @param[in] dev
3433 : : * Pointer to the rte_eth_dev structure.
3434 : : * @param[in] action_flags
3435 : : * Holds the actions detected until now.
3436 : : * @param[in] item_flags
3437 : : * The items found in this flow rule.
3438 : : * @param[in] action
3439 : : * Pointer to the action structure.
3440 : : * @param[in] attr
3441 : : * Pointer to flow attributes
3442 : : * @param[out] error
3443 : : * Pointer to error structure.
3444 : : *
3445 : : * @return
3446 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3447 : : */
3448 : : static int
3449 : 0 : flow_dv_validate_action_push_vlan(struct rte_eth_dev *dev,
3450 : : uint64_t action_flags,
3451 : : const struct rte_flow_item_vlan *vlan_m,
3452 : : const struct rte_flow_action *action,
3453 : : const struct rte_flow_attr *attr,
3454 : : struct rte_flow_error *error)
3455 : : {
3456 : 0 : const struct rte_flow_action_of_push_vlan *push_vlan = action->conf;
3457 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
3458 : :
3459 [ # # ]: 0 : if (push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_VLAN) &&
3460 : : push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_QINQ))
3461 : 0 : return rte_flow_error_set(error, EINVAL,
3462 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3463 : : "invalid vlan ethertype");
3464 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3465 : 0 : return rte_flow_error_set(error, EINVAL,
3466 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3467 : : "wrong action order, port_id should "
3468 : : "be after push VLAN");
3469 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
3470 : 0 : return rte_flow_error_set(error, ENOTSUP,
3471 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3472 : : "push vlan action for VF representor "
3473 : : "not supported on NIC table");
3474 [ # # ]: 0 : if (vlan_m &&
3475 [ # # # # ]: 0 : (vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) &&
3476 : : (vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) !=
3477 : 0 : MLX5DV_FLOW_VLAN_PCP_MASK_BE &&
3478 [ # # # # ]: 0 : !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP) &&
3479 : 0 : !(mlx5_flow_find_action
3480 : : (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP)))
3481 : 0 : return rte_flow_error_set(error, EINVAL,
3482 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3483 : : "not full match mask on VLAN PCP and "
3484 : : "there is no of_set_vlan_pcp action, "
3485 : : "push VLAN action cannot figure out "
3486 : : "PCP value");
3487 [ # # ]: 0 : if (vlan_m &&
3488 [ # # # # ]: 0 : (vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) &&
3489 : : (vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) !=
3490 : 0 : MLX5DV_FLOW_VLAN_VID_MASK_BE &&
3491 [ # # # # ]: 0 : !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID) &&
3492 : 0 : !(mlx5_flow_find_action
3493 : : (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID)))
3494 : 0 : return rte_flow_error_set(error, EINVAL,
3495 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3496 : : "not full match mask on VLAN VID and "
3497 : : "there is no of_set_vlan_vid action, "
3498 : : "push VLAN action cannot figure out "
3499 : : "VID value");
3500 : : (void)attr;
3501 : : return 0;
3502 : : }
3503 : :
3504 : : /**
3505 : : * Validate the set VLAN PCP.
3506 : : *
3507 : : * @param[in] action_flags
3508 : : * Holds the actions detected until now.
3509 : : * @param[in] actions
3510 : : * Pointer to the list of actions remaining in the flow rule.
3511 : : * @param[out] error
3512 : : * Pointer to error structure.
3513 : : *
3514 : : * @return
3515 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3516 : : */
3517 : : static int
3518 : 0 : flow_dv_validate_action_set_vlan_pcp(uint64_t action_flags,
3519 : : const struct rte_flow_action actions[],
3520 : : struct rte_flow_error *error)
3521 : : {
3522 : : const struct rte_flow_action *action = actions;
3523 : 0 : const struct rte_flow_action_of_set_vlan_pcp *conf = action->conf;
3524 : :
3525 [ # # ]: 0 : if (conf->vlan_pcp > 7)
3526 : 0 : return rte_flow_error_set(error, EINVAL,
3527 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3528 : : "VLAN PCP value is too big");
3529 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN))
3530 : 0 : return rte_flow_error_set(error, ENOTSUP,
3531 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3532 : : "set VLAN PCP action must follow "
3533 : : "the push VLAN action");
3534 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP)
3535 : 0 : return rte_flow_error_set(error, ENOTSUP,
3536 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3537 : : "Multiple VLAN PCP modification are "
3538 : : "not supported");
3539 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3540 : 0 : return rte_flow_error_set(error, EINVAL,
3541 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3542 : : "wrong action order, port_id should "
3543 : : "be after set VLAN PCP");
3544 : : return 0;
3545 : : }
3546 : :
3547 : : /**
3548 : : * Validate the set VLAN VID.
3549 : : *
3550 : : * @param[in] item_flags
3551 : : * Holds the items detected in this rule.
3552 : : * @param[in] action_flags
3553 : : * Holds the actions detected until now.
3554 : : * @param[in] actions
3555 : : * Pointer to the list of actions remaining in the flow rule.
3556 : : * @param[out] error
3557 : : * Pointer to error structure.
3558 : : *
3559 : : * @return
3560 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3561 : : */
3562 : : static int
3563 : 0 : flow_dv_validate_action_set_vlan_vid(uint64_t item_flags,
3564 : : uint64_t action_flags,
3565 : : const struct rte_flow_action actions[],
3566 : : struct rte_flow_error *error)
3567 : : {
3568 : : const struct rte_flow_action *action = actions;
3569 : 0 : const struct rte_flow_action_of_set_vlan_vid *conf = action->conf;
3570 : :
3571 [ # # # # ]: 0 : if (rte_be_to_cpu_16(conf->vlan_vid) > 0xFFE)
3572 : 0 : return rte_flow_error_set(error, EINVAL,
3573 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3574 : : "VLAN VID value is too big");
3575 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) &&
3576 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
3577 : 0 : return rte_flow_error_set(error, ENOTSUP,
3578 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3579 : : "set VLAN VID action must follow push"
3580 : : " VLAN action or match on VLAN item");
3581 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID)
3582 : 0 : return rte_flow_error_set(error, ENOTSUP,
3583 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3584 : : "Multiple VLAN VID modifications are "
3585 : : "not supported");
3586 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3587 : 0 : return rte_flow_error_set(error, EINVAL,
3588 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3589 : : "wrong action order, port_id should "
3590 : : "be after set VLAN VID");
3591 : : return 0;
3592 : : }
3593 : :
3594 : : /*
3595 : : * Validate the FLAG action.
3596 : : *
3597 : : * @param[in] dev
3598 : : * Pointer to the rte_eth_dev structure.
3599 : : * @param[in] action_flags
3600 : : * Holds the actions detected until now.
3601 : : * @param[in] attr
3602 : : * Pointer to flow attributes
3603 : : * @param[out] error
3604 : : * Pointer to error structure.
3605 : : *
3606 : : * @return
3607 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3608 : : */
3609 : : static int
3610 : 0 : flow_dv_validate_action_flag(struct rte_eth_dev *dev,
3611 : : uint64_t action_flags,
3612 : : const struct rte_flow_attr *attr,
3613 : : struct rte_flow_error *error)
3614 : : {
3615 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3616 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
3617 : : int ret;
3618 : :
3619 : : /* Fall back if no extended metadata register support. */
3620 [ # # ]: 0 : if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
3621 : 0 : return mlx5_flow_validate_action_flag(action_flags, attr,
3622 : : error);
3623 : : /* Extensive metadata mode requires registers. */
3624 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
3625 : 0 : return rte_flow_error_set(error, ENOTSUP,
3626 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3627 : : "no metadata registers "
3628 : : "to support flag action");
3629 [ # # ]: 0 : if (!(priv->sh->dv_mark_mask & MLX5_FLOW_MARK_DEFAULT))
3630 : 0 : return rte_flow_error_set(error, ENOTSUP,
3631 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3632 : : "extended metadata register"
3633 : : " isn't available");
3634 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3635 [ # # ]: 0 : if (ret < 0)
3636 : : return ret;
3637 : : MLX5_ASSERT(ret > 0);
3638 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
3639 : 0 : return rte_flow_error_set(error, EINVAL,
3640 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3641 : : "can't mark and flag in same flow");
3642 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_FLAG)
3643 : 0 : return rte_flow_error_set(error, EINVAL,
3644 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3645 : : "can't have 2 flag"
3646 : : " actions in same flow");
3647 : : return 0;
3648 : : }
3649 : :
3650 : : /**
3651 : : * Validate MARK action.
3652 : : *
3653 : : * @param[in] dev
3654 : : * Pointer to the rte_eth_dev structure.
3655 : : * @param[in] action
3656 : : * Pointer to action.
3657 : : * @param[in] action_flags
3658 : : * Holds the actions detected until now.
3659 : : * @param[in] attr
3660 : : * Pointer to flow attributes
3661 : : * @param[out] error
3662 : : * Pointer to error structure.
3663 : : *
3664 : : * @return
3665 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3666 : : */
3667 : : static int
3668 : 0 : flow_dv_validate_action_mark(struct rte_eth_dev *dev,
3669 : : const struct rte_flow_action *action,
3670 : : uint64_t action_flags,
3671 : : const struct rte_flow_attr *attr,
3672 : : struct rte_flow_error *error)
3673 : : {
3674 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3675 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
3676 [ # # ]: 0 : const struct rte_flow_action_mark *mark = action->conf;
3677 : : int ret;
3678 : :
3679 [ # # ]: 0 : if (is_tunnel_offload_active(dev))
3680 : 0 : return rte_flow_error_set(error, ENOTSUP,
3681 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3682 : : "no mark action "
3683 : : "if tunnel offload active");
3684 : : /* Fall back if no extended metadata register support. */
3685 [ # # ]: 0 : if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
3686 : 0 : return mlx5_flow_validate_action_mark(dev, action, action_flags,
3687 : : attr, error);
3688 : : /* Extensive metadata mode requires registers. */
3689 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
3690 : 0 : return rte_flow_error_set(error, ENOTSUP,
3691 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3692 : : "no metadata registers "
3693 : : "to support mark action");
3694 [ # # ]: 0 : if (!priv->sh->dv_mark_mask)
3695 : 0 : return rte_flow_error_set(error, ENOTSUP,
3696 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3697 : : "extended metadata register"
3698 : : " isn't available");
3699 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3700 [ # # ]: 0 : if (ret < 0)
3701 : : return ret;
3702 : : MLX5_ASSERT(ret > 0);
3703 [ # # ]: 0 : if (!mark)
3704 : 0 : return rte_flow_error_set(error, EINVAL,
3705 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3706 : : "configuration cannot be null");
3707 [ # # ]: 0 : if (mark->id >= (MLX5_FLOW_MARK_MAX & priv->sh->dv_mark_mask))
3708 : 0 : return rte_flow_error_set(error, EINVAL,
3709 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3710 : 0 : &mark->id,
3711 : : "mark id exceeds the limit");
3712 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_FLAG)
3713 : 0 : return rte_flow_error_set(error, EINVAL,
3714 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3715 : : "can't flag and mark in same flow");
3716 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
3717 : 0 : return rte_flow_error_set(error, EINVAL,
3718 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3719 : : "can't have 2 mark actions in same"
3720 : : " flow");
3721 : : return 0;
3722 : : }
3723 : :
3724 : : /**
3725 : : * Validate SET_META action.
3726 : : *
3727 : : * @param[in] dev
3728 : : * Pointer to the rte_eth_dev structure.
3729 : : * @param[in] action
3730 : : * Pointer to the action structure.
3731 : : * @param[in] action_flags
3732 : : * Holds the actions detected until now.
3733 : : * @param[in] attr
3734 : : * Pointer to flow attributes
3735 : : * @param[out] error
3736 : : * Pointer to error structure.
3737 : : *
3738 : : * @return
3739 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3740 : : */
3741 : : static int
3742 : 0 : flow_dv_validate_action_set_meta(struct rte_eth_dev *dev,
3743 : : const struct rte_flow_action *action,
3744 : : uint64_t action_flags __rte_unused,
3745 : : const struct rte_flow_attr *attr,
3746 : : struct rte_flow_error *error)
3747 : : {
3748 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3749 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
3750 : : const struct rte_flow_action_set_meta *conf;
3751 : : uint32_t nic_mask = UINT32_MAX;
3752 : : int reg;
3753 : :
3754 [ # # # # ]: 0 : if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
3755 : 0 : !mlx5_flow_ext_mreg_supported(dev))
3756 : 0 : return rte_flow_error_set(error, ENOTSUP,
3757 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3758 : : "extended metadata register"
3759 : : " isn't supported");
3760 : 0 : reg = flow_dv_get_metadata_reg(dev, attr, error);
3761 [ # # ]: 0 : if (reg < 0)
3762 : : return reg;
3763 [ # # ]: 0 : if (reg == REG_NON)
3764 : 0 : return rte_flow_error_set(error, ENOTSUP,
3765 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3766 : : "unavailable extended metadata register");
3767 [ # # ]: 0 : if (reg != REG_A && reg != REG_B) {
3768 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3769 : :
3770 : 0 : nic_mask = priv->sh->dv_meta_mask;
3771 : : }
3772 [ # # ]: 0 : if (!(action->conf))
3773 : 0 : return rte_flow_error_set(error, EINVAL,
3774 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3775 : : "configuration cannot be null");
3776 : : conf = (const struct rte_flow_action_set_meta *)action->conf;
3777 [ # # ]: 0 : if (!conf->mask)
3778 : 0 : return rte_flow_error_set(error, EINVAL,
3779 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3780 : : "zero mask doesn't have any effect");
3781 [ # # ]: 0 : if (conf->mask & ~nic_mask)
3782 : 0 : return rte_flow_error_set(error, EINVAL,
3783 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3784 : : "meta data must be within reg C0");
3785 : : return 0;
3786 : : }
3787 : :
3788 : : /**
3789 : : * Validate SET_TAG action.
3790 : : *
3791 : : * @param[in] dev
3792 : : * Pointer to the rte_eth_dev structure.
3793 : : * @param[in] action
3794 : : * Pointer to the action structure.
3795 : : * @param[in] action_flags
3796 : : * Holds the actions detected until now.
3797 : : * @param[in] attr
3798 : : * Pointer to flow attributes
3799 : : * @param[out] error
3800 : : * Pointer to error structure.
3801 : : *
3802 : : * @return
3803 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3804 : : */
3805 : : static int
3806 : 0 : flow_dv_validate_action_set_tag(struct rte_eth_dev *dev,
3807 : : const struct rte_flow_action *action,
3808 : : uint64_t action_flags,
3809 : : const struct rte_flow_attr *attr,
3810 : : struct rte_flow_error *error)
3811 : : {
3812 : : const struct rte_flow_action_set_tag *conf;
3813 : : const uint64_t terminal_action_flags =
3814 : : MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE |
3815 : : MLX5_FLOW_ACTION_RSS;
3816 : : int ret;
3817 : :
3818 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
3819 : 0 : return rte_flow_error_set(error, ENOTSUP,
3820 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3821 : : "extensive metadata register"
3822 : : " isn't supported");
3823 [ # # ]: 0 : if (!(action->conf))
3824 : 0 : return rte_flow_error_set(error, EINVAL,
3825 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3826 : : "configuration cannot be null");
3827 : : conf = (const struct rte_flow_action_set_tag *)action->conf;
3828 [ # # ]: 0 : if (!conf->mask)
3829 : 0 : return rte_flow_error_set(error, EINVAL,
3830 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3831 : : "zero mask doesn't have any effect");
3832 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
3833 [ # # ]: 0 : if (ret < 0)
3834 : : return ret;
3835 [ # # # # ]: 0 : if (attr->ingress && (action_flags & terminal_action_flags))
3836 : 0 : return rte_flow_error_set(error, EINVAL,
3837 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3838 : : "set_tag has no effect"
3839 : : " with terminal actions");
3840 : : return 0;
3841 : : }
3842 : :
3843 : : /**
3844 : : * Indicates whether ASO aging is supported.
3845 : : *
3846 : : * @param[in] priv
3847 : : * Pointer to device private context structure.
3848 : : * @param[in] root
3849 : : * Whether action is on root table.
3850 : : *
3851 : : * @return
3852 : : * True when ASO aging is supported, false otherwise.
3853 : : */
3854 : : static inline bool
3855 : : flow_hit_aso_supported(const struct mlx5_priv *priv, bool root)
3856 : : {
3857 : : MLX5_ASSERT(priv);
3858 [ # # # # : 0 : return (priv->sh->flow_hit_aso_en && !root);
# # # # #
# ]
3859 : : }
3860 : :
3861 : : /**
3862 : : * Validate count action.
3863 : : *
3864 : : * @param[in] dev
3865 : : * Pointer to rte_eth_dev structure.
3866 : : * @param[in] shared
3867 : : * Indicator if action is shared.
3868 : : * @param[in] action_flags
3869 : : * Holds the actions detected until now.
3870 : : * @param[in] root
3871 : : * Whether action is on root table.
3872 : : * @param[out] error
3873 : : * Pointer to error structure.
3874 : : *
3875 : : * @return
3876 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3877 : : */
3878 : : static int
3879 : 0 : flow_dv_validate_action_count(struct rte_eth_dev *dev, bool shared,
3880 : : uint64_t action_flags,
3881 : : bool root,
3882 : : struct rte_flow_error *error)
3883 : : {
3884 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3885 : :
3886 [ # # ]: 0 : if (!priv->sh->cdev->config.devx)
3887 : 0 : goto notsup_err;
3888 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_COUNT)
3889 : 0 : return rte_flow_error_set(error, EINVAL,
3890 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3891 : : "duplicate count actions set");
3892 [ # # # # : 0 : if (shared && (action_flags & MLX5_FLOW_ACTION_AGE) &&
# # ]
3893 : : !flow_hit_aso_supported(priv, root))
3894 : 0 : return rte_flow_error_set(error, EINVAL,
3895 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3896 : : "old age and indirect count combination is not supported");
3897 : : #ifdef HAVE_IBV_FLOW_DEVX_COUNTERS
3898 : : return 0;
3899 : : #endif
3900 : : notsup_err:
3901 : 0 : return rte_flow_error_set
3902 : : (error, ENOTSUP,
3903 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3904 : : NULL,
3905 : : "count action not supported");
3906 : : }
3907 : :
3908 : : /**
3909 : : * Validate the L2 encap action.
3910 : : *
3911 : : * @param[in] dev
3912 : : * Pointer to the rte_eth_dev structure.
3913 : : * @param[in] action_flags
3914 : : * Holds the actions detected until now.
3915 : : * @param[in] action
3916 : : * Pointer to the action structure.
3917 : : * @param[in] attr
3918 : : * Pointer to flow attributes.
3919 : : * @param[out] error
3920 : : * Pointer to error structure.
3921 : : *
3922 : : * @return
3923 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3924 : : */
3925 : : int
3926 : 0 : mlx5_flow_dv_validate_action_l2_encap(struct rte_eth_dev *dev,
3927 : : uint64_t action_flags,
3928 : : const struct rte_flow_action *action,
3929 : : const struct rte_flow_attr *attr,
3930 : : struct rte_flow_error *error)
3931 : : {
3932 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
3933 : :
3934 [ # # ]: 0 : if (!(action->conf))
3935 : 0 : return rte_flow_error_set(error, EINVAL,
3936 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3937 : : "configuration cannot be null");
3938 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
3939 : 0 : return rte_flow_error_set(error, EINVAL,
3940 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3941 : : "can only have a single encap action "
3942 : : "in a flow");
3943 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
3944 : 0 : return rte_flow_error_set(error, ENOTSUP,
3945 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3946 : : "encap action for VF representor "
3947 : : "not supported on NIC table");
3948 : : return 0;
3949 : : }
3950 : :
3951 : : /**
3952 : : * Validate a decap action.
3953 : : *
3954 : : * @param[in] dev
3955 : : * Pointer to the rte_eth_dev structure.
3956 : : * @param[in] action_flags
3957 : : * Holds the actions detected until now.
3958 : : * @param[in] action
3959 : : * Pointer to the action structure.
3960 : : * @param[in] item_flags
3961 : : * Holds the items detected.
3962 : : * @param[in] attr
3963 : : * Pointer to flow attributes
3964 : : * @param[out] error
3965 : : * Pointer to error structure.
3966 : : *
3967 : : * @return
3968 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3969 : : */
3970 : : int
3971 : 0 : mlx5_flow_dv_validate_action_decap(struct rte_eth_dev *dev,
3972 : : uint64_t action_flags,
3973 : : const struct rte_flow_action *action,
3974 : : const uint64_t item_flags,
3975 : : const struct rte_flow_attr *attr,
3976 : : struct rte_flow_error *error)
3977 : : {
3978 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
3979 : :
3980 [ # # ]: 0 : if (priv->sh->cdev->config.hca_attr.scatter_fcs_w_decap_disable &&
3981 [ # # ]: 0 : !priv->sh->config.decap_en)
3982 : 0 : return rte_flow_error_set(error, ENOTSUP,
3983 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3984 : : "decap is not enabled");
3985 [ # # ]: 0 : if (action_flags & MLX5_FLOW_XCAP_ACTIONS)
3986 : 0 : return rte_flow_error_set(error, ENOTSUP,
3987 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3988 [ # # ]: 0 : action_flags &
3989 : : MLX5_FLOW_ACTION_DECAP ? "can only "
3990 : : "have a single decap action" : "decap "
3991 : : "after encap is not supported");
3992 [ # # ]: 0 : if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
3993 : 0 : return rte_flow_error_set(error, EINVAL,
3994 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3995 : : "can't have decap action after"
3996 : : " modify action");
3997 [ # # ]: 0 : if (attr->egress)
3998 : 0 : return rte_flow_error_set(error, ENOTSUP,
3999 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
4000 : : NULL,
4001 : : "decap action not supported for "
4002 : : "egress");
4003 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
4004 : 0 : return rte_flow_error_set(error, ENOTSUP,
4005 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4006 : : "decap action for VF representor "
4007 : : "not supported on NIC table");
4008 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_DECAP &&
4009 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_VXLAN))
4010 : 0 : return rte_flow_error_set(error, ENOTSUP,
4011 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4012 : : "VXLAN item should be present for VXLAN decap");
4013 : : return 0;
4014 : : }
4015 : :
4016 : : const struct rte_flow_action_raw_decap empty_decap = {.data = NULL, .size = 0,};
4017 : :
4018 : : /**
4019 : : * Validate the raw encap and decap actions.
4020 : : *
4021 : : * @param[in] dev
4022 : : * Pointer to the rte_eth_dev structure.
4023 : : * @param[in] decap
4024 : : * Pointer to the decap action.
4025 : : * @param[in] encap
4026 : : * Pointer to the encap action.
4027 : : * @param[in] attr
4028 : : * Pointer to flow attributes
4029 : : * @param[in/out] action_flags
4030 : : * Holds the actions detected until now.
4031 : : * @param[out] actions_n
4032 : : * pointer to the number of actions counter.
4033 : : * @param[in] action
4034 : : * Pointer to the action structure.
4035 : : * @param[in] item_flags
4036 : : * Holds the items detected.
4037 : : * @param[out] error
4038 : : * Pointer to error structure.
4039 : : *
4040 : : * @return
4041 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4042 : : */
4043 : : int
4044 : 0 : mlx5_flow_dv_validate_action_raw_encap_decap
4045 : : (struct rte_eth_dev *dev,
4046 : : const struct rte_flow_action_raw_decap *decap,
4047 : : const struct rte_flow_action_raw_encap *encap,
4048 : : const struct rte_flow_attr *attr, uint64_t *action_flags,
4049 : : int *actions_n, const struct rte_flow_action *action,
4050 : : uint64_t item_flags, struct rte_flow_error *error)
4051 : : {
4052 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
4053 : : int ret;
4054 : :
4055 [ # # ]: 0 : if (encap) {
4056 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
4057 [ # # # # ]: 0 : if (!encap->size || !encap->data)
4058 : 0 : return rte_flow_error_set
4059 : : (error, EINVAL,
4060 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL, "raw encap data cannot be empty");
4061 : : } else {
4062 [ # # ]: 0 : if (!encap->size)
4063 : 0 : return rte_flow_error_set
4064 : : (error, EINVAL,
4065 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL, "raw encap size cannot be 0");
4066 : : }
4067 : : }
4068 [ # # ]: 0 : if (decap && encap) {
4069 [ # # ]: 0 : if (decap->size <= MLX5_ENCAPSULATION_DECISION_SIZE &&
4070 [ # # ]: 0 : encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4071 : : /* L3 encap. */
4072 : : decap = NULL;
4073 [ # # ]: 0 : else if (encap->size <=
4074 [ # # ]: 0 : MLX5_ENCAPSULATION_DECISION_SIZE &&
4075 : : decap->size >
4076 : : MLX5_ENCAPSULATION_DECISION_SIZE)
4077 : : /* L3 decap. */
4078 : : encap = NULL;
4079 [ # # ]: 0 : else if (encap->size >
4080 [ # # ]: 0 : MLX5_ENCAPSULATION_DECISION_SIZE &&
4081 : : decap->size >
4082 : : MLX5_ENCAPSULATION_DECISION_SIZE)
4083 : : /* 2 L2 actions: encap and decap. */
4084 : : ;
4085 : : else
4086 : 0 : return rte_flow_error_set(error,
4087 : : ENOTSUP,
4088 : : RTE_FLOW_ERROR_TYPE_ACTION,
4089 : : NULL, "unsupported too small "
4090 : : "raw decap and too small raw "
4091 : : "encap combination");
4092 : : }
4093 [ # # ]: 0 : if (decap) {
4094 : 0 : ret = mlx5_flow_dv_validate_action_decap(dev, *action_flags,
4095 : : action,
4096 : : item_flags, attr,
4097 : : error);
4098 [ # # ]: 0 : if (ret < 0)
4099 : : return ret;
4100 : 0 : *action_flags |= MLX5_FLOW_ACTION_DECAP;
4101 : 0 : ++(*actions_n);
4102 : : }
4103 [ # # ]: 0 : if (encap) {
4104 [ # # ]: 0 : if (encap->size <= MLX5_ENCAPSULATION_DECISION_SIZE)
4105 : 0 : return rte_flow_error_set(error, ENOTSUP,
4106 : : RTE_FLOW_ERROR_TYPE_ACTION,
4107 : : NULL,
4108 : : "small raw encap size");
4109 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_ENCAP)
4110 : 0 : return rte_flow_error_set(error, EINVAL,
4111 : : RTE_FLOW_ERROR_TYPE_ACTION,
4112 : : NULL,
4113 : : "more than one encap action");
4114 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
4115 : 0 : return rte_flow_error_set
4116 : : (error, ENOTSUP,
4117 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4118 : : "encap action for VF representor "
4119 : : "not supported on NIC table");
4120 : 0 : *action_flags |= MLX5_FLOW_ACTION_ENCAP;
4121 : 0 : ++(*actions_n);
4122 : : }
4123 : : return 0;
4124 : : }
4125 : :
4126 : : /*
4127 : : * Validate the ASO CT action.
4128 : : *
4129 : : * @param[in] dev
4130 : : * Pointer to the rte_eth_dev structure.
4131 : : * @param[in] action_flags
4132 : : * Holds the actions detected until now.
4133 : : * @param[in] item_flags
4134 : : * The items found in this flow rule.
4135 : : * @param root
4136 : : * Whether action is on root table.
4137 : : * @param[out] error
4138 : : * Pointer to error structure.
4139 : : *
4140 : : * @return
4141 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4142 : : */
4143 : : int
4144 : 0 : mlx5_flow_dv_validate_action_aso_ct(struct rte_eth_dev *dev,
4145 : : uint64_t action_flags,
4146 : : uint64_t item_flags,
4147 : : bool root,
4148 : : struct rte_flow_error *error)
4149 : : {
4150 : : RTE_SET_USED(dev);
4151 : :
4152 [ # # ]: 0 : if (root)
4153 : 0 : return rte_flow_error_set(error, ENOTSUP,
4154 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4155 : : NULL,
4156 : : "Only support non-root table");
4157 [ # # ]: 0 : if (action_flags & MLX5_FLOW_FATE_ACTIONS)
4158 : 0 : return rte_flow_error_set(error, ENOTSUP,
4159 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4160 : : "CT cannot follow a fate action");
4161 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_METER) ||
4162 : : (action_flags & MLX5_FLOW_ACTION_AGE)) {
4163 [ # # ]: 0 : if (!mlx5_hws_active(dev))
4164 : 0 : return rte_flow_error_set(error, EINVAL,
4165 : : RTE_FLOW_ERROR_TYPE_ACTION,
4166 : : NULL, "Only one ASO action is supported");
4167 : : }
4168 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
4169 : 0 : return rte_flow_error_set(error, EINVAL,
4170 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4171 : : "Encap cannot exist before CT");
4172 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP))
4173 : 0 : return rte_flow_error_set(error, EINVAL,
4174 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4175 : : "Not a outer TCP packet");
4176 : : return 0;
4177 : : }
4178 : :
4179 : : /**
4180 : : * Validate METER_COLOR item.
4181 : : *
4182 : : * @param[in] dev
4183 : : * Pointer to the rte_eth_dev structure.
4184 : : * @param[in] item
4185 : : * Item specification.
4186 : : * @param[in] attr
4187 : : * Attributes of flow that includes this item.
4188 : : * @param[out] error
4189 : : * Pointer to error structure.
4190 : : *
4191 : : * @return
4192 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4193 : : */
4194 : : static int
4195 : 0 : flow_dv_validate_item_meter_color(struct rte_eth_dev *dev,
4196 : : const struct rte_flow_item *item,
4197 : : const struct rte_flow_attr *attr __rte_unused,
4198 : : struct rte_flow_error *error)
4199 : : {
4200 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4201 : 0 : const struct rte_flow_item_meter_color *spec = item->spec;
4202 : 0 : const struct rte_flow_item_meter_color *mask = item->mask;
4203 : 0 : struct rte_flow_item_meter_color nic_mask = {
4204 : : .color = RTE_COLORS
4205 : : };
4206 : : int ret;
4207 : :
4208 [ # # ]: 0 : if (priv->sh->registers.aso_reg == REG_NON)
4209 : 0 : return rte_flow_error_set(error, ENOTSUP,
4210 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
4211 : : "meter color register"
4212 : : " isn't available");
4213 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, error);
4214 [ # # ]: 0 : if (ret < 0)
4215 : : return ret;
4216 [ # # ]: 0 : if (!spec)
4217 : 0 : return rte_flow_error_set(error, EINVAL,
4218 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4219 : 0 : item->spec,
4220 : : "data cannot be empty");
4221 [ # # ]: 0 : if (spec->color > RTE_COLORS)
4222 : 0 : return rte_flow_error_set(error, EINVAL,
4223 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4224 : 0 : &spec->color,
4225 : : "meter color is invalid");
4226 [ # # ]: 0 : if (!mask)
4227 : : mask = &rte_flow_item_meter_color_mask;
4228 [ # # ]: 0 : if (!mask->color)
4229 : 0 : return rte_flow_error_set(error, EINVAL,
4230 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
4231 : : "mask cannot be zero");
4232 : :
4233 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
4234 : : (const uint8_t *)&nic_mask,
4235 : : sizeof(struct rte_flow_item_meter_color),
4236 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
4237 : : if (ret < 0)
4238 : : return ret;
4239 : : return 0;
4240 : : }
4241 : :
4242 : : /**
4243 : : * Validate aggregated affinity item.
4244 : : *
4245 : : * @param[in] dev
4246 : : * Pointer to the rte_eth_dev structure.
4247 : : * @param[in] item
4248 : : * Item specification.
4249 : : * @param[in] attr
4250 : : * Attributes of flow that includes this item.
4251 : : * @param[out] error
4252 : : * Pointer to error structure.
4253 : : *
4254 : : * @return
4255 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4256 : : */
4257 : : static int
4258 : 0 : flow_dv_validate_item_aggr_affinity(struct rte_eth_dev *dev,
4259 : : const struct rte_flow_item *item,
4260 : : const struct rte_flow_attr *attr,
4261 : : struct rte_flow_error *error)
4262 : : {
4263 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4264 : 0 : const struct rte_flow_item_aggr_affinity *spec = item->spec;
4265 : 0 : const struct rte_flow_item_aggr_affinity *mask = item->mask;
4266 : 0 : struct rte_flow_item_aggr_affinity nic_mask = {
4267 : : .affinity = UINT8_MAX
4268 : : };
4269 : : int ret;
4270 : :
4271 [ # # ]: 0 : if (!priv->sh->lag_rx_port_affinity_en)
4272 : 0 : return rte_flow_error_set(error, EINVAL,
4273 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
4274 : : "Unsupported aggregated affinity with Older FW");
4275 [ # # # # : 0 : if ((attr->transfer && priv->fdb_def_rule) ||
# # ]
4276 [ # # ]: 0 : attr->egress || attr->group)
4277 : 0 : return rte_flow_error_set(error, ENOTSUP,
4278 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4279 : : item->spec,
4280 : : "aggregated affinity is not supported with egress or FDB on non root table");
4281 [ # # ]: 0 : if (!spec)
4282 : 0 : return rte_flow_error_set(error, EINVAL,
4283 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4284 : : item->spec,
4285 : : "data cannot be empty");
4286 [ # # ]: 0 : if (spec->affinity == 0)
4287 : 0 : return rte_flow_error_set(error, ENOTSUP,
4288 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4289 : : item->spec,
4290 : : "zero affinity number not supported");
4291 [ # # ]: 0 : if (spec->affinity > priv->num_lag_ports)
4292 : 0 : return rte_flow_error_set(error, ENOTSUP,
4293 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4294 : : item->spec,
4295 : : "exceed max affinity number in lag ports");
4296 [ # # ]: 0 : if (!mask)
4297 : : mask = &rte_flow_item_aggr_affinity_mask;
4298 [ # # ]: 0 : if (!mask->affinity)
4299 : 0 : return rte_flow_error_set(error, EINVAL,
4300 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
4301 : : "mask cannot be zero");
4302 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
4303 : : (const uint8_t *)&nic_mask,
4304 : : sizeof(struct rte_flow_item_aggr_affinity),
4305 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
4306 : : if (ret < 0)
4307 : : return ret;
4308 : : return 0;
4309 : : }
4310 : :
4311 : : int
4312 : 0 : mlx5_flow_encap_decap_match_cb(void *tool_ctx __rte_unused,
4313 : : struct mlx5_list_entry *entry, void *cb_ctx)
4314 : : {
4315 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4316 : 0 : struct mlx5_flow_dv_encap_decap_resource *ctx_resource = ctx->data;
4317 : : struct mlx5_flow_dv_encap_decap_resource *resource;
4318 : :
4319 : : resource = container_of(entry, struct mlx5_flow_dv_encap_decap_resource,
4320 : : entry);
4321 [ # # ]: 0 : if (resource->reformat_type == ctx_resource->reformat_type &&
4322 : 0 : resource->ft_type == ctx_resource->ft_type &&
4323 [ # # ]: 0 : resource->flags == ctx_resource->flags &&
4324 [ # # ]: 0 : resource->size == ctx_resource->size &&
4325 : 0 : !memcmp((const void *)resource->buf,
4326 [ # # ]: 0 : (const void *)ctx_resource->buf,
4327 : : resource->size))
4328 : 0 : return 0;
4329 : : return -1;
4330 : : }
4331 : :
4332 : : struct mlx5_list_entry *
4333 : 0 : mlx5_flow_encap_decap_create_cb(void *tool_ctx, void *cb_ctx)
4334 : : {
4335 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4336 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4337 : : struct mlx5dv_dr_domain *domain;
4338 : 0 : struct mlx5_flow_dv_encap_decap_resource *ctx_resource = ctx->data;
4339 : : struct mlx5_flow_dv_encap_decap_resource *resource;
4340 : : uint32_t idx;
4341 : : int ret = 0;
4342 : : #ifdef HAVE_MLX5_HWS_SUPPORT
4343 : : struct mlx5dr_action_reformat_header hdr;
4344 : : #endif
4345 : :
4346 : : /* Register new encap/decap resource. */
4347 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], &idx);
4348 [ # # ]: 0 : if (!resource) {
4349 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4350 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4351 : : "cannot allocate resource memory");
4352 : 0 : return NULL;
4353 : : }
4354 : 0 : *resource = *ctx_resource;
4355 [ # # ]: 0 : if (sh->config.dv_flow_en == 2) {
4356 : : #ifdef HAVE_MLX5_HWS_SUPPORT
4357 : 0 : hdr.sz = ctx_resource->size;
4358 : 0 : hdr.data = ctx_resource->buf;
4359 : 0 : resource->action = mlx5dr_action_create_reformat
4360 : 0 : (ctx->data2, (enum mlx5dr_action_type)ctx_resource->reformat_type, 1,
4361 : 0 : &hdr, 0, ctx_resource->flags);
4362 [ # # ]: 0 : if (!resource->action)
4363 : : ret = -1;
4364 : : #else
4365 : : ret = -1;
4366 : : #endif
4367 : : } else {
4368 [ # # ]: 0 : if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
4369 : 0 : domain = sh->fdb_domain;
4370 [ # # ]: 0 : else if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
4371 : 0 : domain = sh->rx_domain;
4372 : : else
4373 : 0 : domain = sh->tx_domain;
4374 [ # # ]: 0 : ret = mlx5_flow_os_create_flow_action_packet_reformat(sh->cdev->ctx,
4375 : : domain, resource,
4376 : : &resource->action);
4377 : : }
4378 : : if (ret) {
4379 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], idx);
4380 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4381 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4382 : : NULL, "cannot create action");
4383 : 0 : return NULL;
4384 : : }
4385 : 0 : resource->idx = idx;
4386 : 0 : return &resource->entry;
4387 : : }
4388 : :
4389 : : struct mlx5_list_entry *
4390 : 0 : mlx5_flow_encap_decap_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
4391 : : void *cb_ctx)
4392 : : {
4393 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4394 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4395 : : struct mlx5_flow_dv_encap_decap_resource *cache_resource;
4396 : : struct mlx5_flow_dv_encap_decap_resource *old_resource;
4397 : : uint32_t idx;
4398 : :
4399 : 0 : cache_resource = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
4400 : : &idx);
4401 [ # # ]: 0 : if (!cache_resource) {
4402 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4403 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4404 : : "cannot allocate resource memory");
4405 : 0 : return NULL;
4406 : : }
4407 : : old_resource = container_of(oentry, typeof(*old_resource), entry);
4408 : : memcpy(cache_resource, old_resource, sizeof(*cache_resource));
4409 : 0 : cache_resource->idx = idx;
4410 : 0 : return &cache_resource->entry;
4411 : : }
4412 : :
4413 : : void
4414 : 0 : mlx5_flow_encap_decap_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4415 : : {
4416 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4417 : : struct mlx5_flow_dv_encap_decap_resource *res =
4418 : : container_of(entry, typeof(*res), entry);
4419 : :
4420 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], res->idx);
4421 : 0 : }
4422 : :
4423 : : int
4424 : 0 : mlx5_flow_encap_decap_resource_register(struct rte_eth_dev *dev,
4425 : : struct mlx5_flow_dv_encap_decap_resource *resource,
4426 : : bool is_root,
4427 : : struct mlx5_flow_dv_encap_decap_resource **encap_decap,
4428 : : struct rte_flow_error *error)
4429 : : {
4430 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4431 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
4432 : : struct mlx5_list_entry *entry;
4433 : : union {
4434 : : struct {
4435 : : uint32_t ft_type:8;
4436 : : uint32_t refmt_type:8;
4437 : : /*
4438 : : * Header reformat actions can be shared between
4439 : : * non-root tables. One bit to indicate non-root
4440 : : * table or not.
4441 : : */
4442 : : uint32_t is_root:1;
4443 : : uint32_t reserve:15;
4444 : : };
4445 : : uint32_t v32;
4446 : 0 : } encap_decap_key = {
4447 : : {
4448 : 0 : .ft_type = resource->ft_type,
4449 : 0 : .refmt_type = resource->reformat_type,
4450 : : .is_root = is_root,
4451 : : .reserve = 0,
4452 : : }
4453 : : };
4454 : 0 : struct mlx5_flow_cb_ctx ctx = {
4455 : : .error = error,
4456 : : .data = resource,
4457 : 0 : .data2 = priv->dr_ctx,
4458 : : };
4459 : : struct mlx5_hlist *encaps_decaps;
4460 : : uint64_t key64;
4461 : :
4462 : 0 : encaps_decaps = flow_dv_hlist_prepare(sh, &sh->encaps_decaps,
4463 : : "encaps_decaps",
4464 : : MLX5_FLOW_ENCAP_DECAP_HTABLE_SZ,
4465 : : true, true, sh,
4466 : : mlx5_flow_encap_decap_create_cb,
4467 : : mlx5_flow_encap_decap_match_cb,
4468 : : mlx5_flow_encap_decap_remove_cb,
4469 : : mlx5_flow_encap_decap_clone_cb,
4470 : : mlx5_flow_encap_decap_clone_free_cb,
4471 : : error);
4472 [ # # ]: 0 : if (unlikely(!encaps_decaps))
4473 : 0 : return -rte_errno;
4474 : 0 : key64 = __rte_raw_cksum(&encap_decap_key.v32,
4475 : : sizeof(encap_decap_key.v32), 0);
4476 [ # # ]: 0 : if (resource->reformat_type !=
4477 : 0 : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2 &&
4478 [ # # ]: 0 : resource->size)
4479 : 0 : key64 = __rte_raw_cksum(resource->buf, resource->size, key64);
4480 : 0 : entry = mlx5_hlist_register(encaps_decaps, key64, &ctx);
4481 [ # # ]: 0 : if (!entry)
4482 : 0 : return -rte_errno;
4483 : 0 : *encap_decap = container_of(entry, typeof(*resource), entry);
4484 : 0 : return 0;
4485 : : }
4486 : :
4487 : : /**
4488 : : * Find existing encap/decap resource or create and register a new one.
4489 : : *
4490 : : * @param[in, out] dev
4491 : : * Pointer to rte_eth_dev structure.
4492 : : * @param[in, out] resource
4493 : : * Pointer to encap/decap resource.
4494 : : * @param[in, out] dev_flow
4495 : : * Pointer to the dev_flow.
4496 : : * @param[out] error
4497 : : * pointer to error structure.
4498 : : *
4499 : : * @return
4500 : : * 0 on success otherwise -errno and errno is set.
4501 : : */
4502 : : static int
4503 : 0 : flow_dv_encap_decap_resource_register
4504 : : (struct rte_eth_dev *dev,
4505 : : struct mlx5_flow_dv_encap_decap_resource *resource,
4506 : : struct mlx5_flow *dev_flow,
4507 : : struct rte_flow_error *error)
4508 : : {
4509 : : int ret;
4510 : :
4511 : 0 : resource->flags = dev_flow->dv.group ? 0 : 1;
4512 : 0 : ret = mlx5_flow_encap_decap_resource_register(dev, resource, !!dev_flow->dv.group,
4513 : : &dev_flow->dv.encap_decap, error);
4514 [ # # ]: 0 : if (ret)
4515 : : return ret;
4516 : 0 : dev_flow->handle->dvh.rix_encap_decap = dev_flow->dv.encap_decap->idx;
4517 : 0 : return 0;
4518 : : }
4519 : :
4520 : : /**
4521 : : * Find existing table jump resource or create and register a new one.
4522 : : *
4523 : : * @param[in, out] dev
4524 : : * Pointer to rte_eth_dev structure.
4525 : : * @param[in, out] tbl
4526 : : * Pointer to flow table resource.
4527 : : * @parm[in, out] dev_flow
4528 : : * Pointer to the dev_flow.
4529 : : * @param[out] error
4530 : : * pointer to error structure.
4531 : : *
4532 : : * @return
4533 : : * 0 on success otherwise -errno and errno is set.
4534 : : */
4535 : : static int
4536 : : flow_dv_jump_tbl_resource_register
4537 : : (struct rte_eth_dev *dev __rte_unused,
4538 : : struct mlx5_flow_tbl_resource *tbl,
4539 : : struct mlx5_flow *dev_flow,
4540 : : struct rte_flow_error *error __rte_unused)
4541 : : {
4542 : : struct mlx5_flow_tbl_data_entry *tbl_data =
4543 : 0 : container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
4544 : :
4545 : : MLX5_ASSERT(tbl);
4546 : : MLX5_ASSERT(tbl_data->jump.action);
4547 : 0 : dev_flow->handle->rix_jump = tbl_data->idx;
4548 : 0 : dev_flow->dv.jump = &tbl_data->jump;
4549 : : return 0;
4550 : : }
4551 : :
4552 : : int
4553 : 0 : mlx5_flow_dv_port_id_match_cb(void *tool_ctx __rte_unused,
4554 : : struct mlx5_list_entry *entry, void *cb_ctx)
4555 : : {
4556 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4557 : 0 : struct mlx5_flow_dv_port_id_action_resource *ref = ctx->data;
4558 : : struct mlx5_flow_dv_port_id_action_resource *res =
4559 : : container_of(entry, typeof(*res), entry);
4560 : :
4561 : 0 : return ref->port_id != res->port_id;
4562 : : }
4563 : :
4564 : : struct mlx5_list_entry *
4565 : 0 : mlx5_flow_dv_port_id_create_cb(void *tool_ctx, void *cb_ctx)
4566 : : {
4567 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4568 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4569 : 0 : struct mlx5_flow_dv_port_id_action_resource *ref = ctx->data;
4570 : : struct mlx5_flow_dv_port_id_action_resource *resource;
4571 : : uint32_t idx;
4572 : : int ret;
4573 : :
4574 : : /* Register new port id action resource. */
4575 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID], &idx);
4576 [ # # ]: 0 : if (!resource) {
4577 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4578 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4579 : : "cannot allocate port_id action memory");
4580 : 0 : return NULL;
4581 : : }
4582 : 0 : *resource = *ref;
4583 : 0 : ret = mlx5_flow_os_create_flow_action_dest_port(sh->fdb_domain,
4584 : : ref->port_id,
4585 : : &resource->action);
4586 : : if (ret) {
4587 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], idx);
4588 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4589 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4590 : : "cannot create action");
4591 : 0 : return NULL;
4592 : : }
4593 : 0 : resource->idx = idx;
4594 : 0 : return &resource->entry;
4595 : : }
4596 : :
4597 : : struct mlx5_list_entry *
4598 : 0 : mlx5_flow_dv_port_id_clone_cb(void *tool_ctx,
4599 : : struct mlx5_list_entry *entry __rte_unused,
4600 : : void *cb_ctx)
4601 : : {
4602 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4603 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4604 : : struct mlx5_flow_dv_port_id_action_resource *resource;
4605 : : struct mlx5_flow_dv_port_id_action_resource *old_resource;
4606 : : uint32_t idx;
4607 : :
4608 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID], &idx);
4609 [ # # ]: 0 : if (!resource) {
4610 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4611 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4612 : : "cannot allocate port_id action memory");
4613 : 0 : return NULL;
4614 : : }
4615 : : old_resource = container_of(entry, typeof(*old_resource), entry);
4616 : : memcpy(resource, old_resource, sizeof(*old_resource));
4617 : 0 : resource->idx = idx;
4618 : 0 : return &resource->entry;
4619 : : }
4620 : :
4621 : : void
4622 : 0 : mlx5_flow_dv_port_id_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4623 : : {
4624 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4625 : : struct mlx5_flow_dv_port_id_action_resource *resource =
4626 : : container_of(entry, typeof(*resource), entry);
4627 : :
4628 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], resource->idx);
4629 : 0 : }
4630 : :
4631 : : /**
4632 : : * Find existing table port ID resource or create and register a new one.
4633 : : *
4634 : : * @param[in, out] dev
4635 : : * Pointer to rte_eth_dev structure.
4636 : : * @param[in, out] ref
4637 : : * Pointer to port ID action resource reference.
4638 : : * @parm[in, out] dev_flow
4639 : : * Pointer to the dev_flow.
4640 : : * @param[out] error
4641 : : * pointer to error structure.
4642 : : *
4643 : : * @return
4644 : : * 0 on success otherwise -errno and errno is set.
4645 : : */
4646 : : static int
4647 : 0 : flow_dv_port_id_action_resource_register
4648 : : (struct rte_eth_dev *dev,
4649 : : struct mlx5_flow_dv_port_id_action_resource *ref,
4650 : : struct mlx5_flow *dev_flow,
4651 : : struct rte_flow_error *error)
4652 : : {
4653 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4654 : : struct mlx5_list_entry *entry;
4655 : : struct mlx5_flow_dv_port_id_action_resource *resource;
4656 : 0 : struct mlx5_flow_cb_ctx ctx = {
4657 : : .error = error,
4658 : : .data = ref,
4659 : : };
4660 : :
4661 : 0 : entry = mlx5_list_register(priv->sh->port_id_action_list, &ctx);
4662 [ # # ]: 0 : if (!entry)
4663 : 0 : return -rte_errno;
4664 : : resource = container_of(entry, typeof(*resource), entry);
4665 : 0 : dev_flow->dv.port_id_action = resource;
4666 : 0 : dev_flow->handle->rix_port_id_action = resource->idx;
4667 : 0 : return 0;
4668 : : }
4669 : :
4670 : : int
4671 : 0 : mlx5_flow_dv_push_vlan_match_cb(void *tool_ctx __rte_unused,
4672 : : struct mlx5_list_entry *entry, void *cb_ctx)
4673 : : {
4674 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4675 : 0 : struct mlx5_flow_dv_push_vlan_action_resource *ref = ctx->data;
4676 : : struct mlx5_flow_dv_push_vlan_action_resource *res =
4677 : : container_of(entry, typeof(*res), entry);
4678 : :
4679 : 0 : return ref->vlan_tag != res->vlan_tag || ref->ft_type != res->ft_type;
4680 : : }
4681 : :
4682 : : struct mlx5_list_entry *
4683 : 0 : mlx5_flow_dv_push_vlan_create_cb(void *tool_ctx, void *cb_ctx)
4684 : : {
4685 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4686 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4687 : 0 : struct mlx5_flow_dv_push_vlan_action_resource *ref = ctx->data;
4688 : : struct mlx5_flow_dv_push_vlan_action_resource *resource;
4689 : : struct mlx5dv_dr_domain *domain;
4690 : : uint32_t idx;
4691 : : int ret;
4692 : :
4693 : : /* Register new port id action resource. */
4694 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PUSH_VLAN], &idx);
4695 [ # # ]: 0 : if (!resource) {
4696 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4697 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4698 : : "cannot allocate push_vlan action memory");
4699 : 0 : return NULL;
4700 : : }
4701 : 0 : *resource = *ref;
4702 [ # # ]: 0 : if (ref->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
4703 : 0 : domain = sh->fdb_domain;
4704 [ # # ]: 0 : else if (ref->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
4705 : 0 : domain = sh->rx_domain;
4706 : : else
4707 : 0 : domain = sh->tx_domain;
4708 : 0 : ret = mlx5_flow_os_create_flow_action_push_vlan(domain, ref->vlan_tag,
4709 : : &resource->action);
4710 : : if (ret) {
4711 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
4712 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4713 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4714 : : "cannot create push vlan action");
4715 : 0 : return NULL;
4716 : : }
4717 : 0 : resource->idx = idx;
4718 : 0 : return &resource->entry;
4719 : : }
4720 : :
4721 : : struct mlx5_list_entry *
4722 : 0 : mlx5_flow_dv_push_vlan_clone_cb(void *tool_ctx,
4723 : : struct mlx5_list_entry *entry __rte_unused,
4724 : : void *cb_ctx)
4725 : : {
4726 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4727 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4728 : : struct mlx5_flow_dv_push_vlan_action_resource *resource;
4729 : : struct mlx5_flow_dv_push_vlan_action_resource *old_resource;
4730 : : uint32_t idx;
4731 : :
4732 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PUSH_VLAN], &idx);
4733 [ # # ]: 0 : if (!resource) {
4734 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4735 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4736 : : "cannot allocate push_vlan action memory");
4737 : 0 : return NULL;
4738 : : }
4739 : : old_resource = container_of(entry, typeof(*old_resource), entry);
4740 : : memcpy(resource, old_resource, sizeof(*old_resource));
4741 : 0 : resource->idx = idx;
4742 : 0 : return &resource->entry;
4743 : : }
4744 : :
4745 : : void
4746 : 0 : mlx5_flow_dv_push_vlan_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4747 : : {
4748 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4749 : : struct mlx5_flow_dv_push_vlan_action_resource *resource =
4750 : : container_of(entry, typeof(*resource), entry);
4751 : :
4752 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], resource->idx);
4753 : 0 : }
4754 : :
4755 : : /**
4756 : : * Find existing push vlan resource or create and register a new one.
4757 : : *
4758 : : * @param [in, out] dev
4759 : : * Pointer to rte_eth_dev structure.
4760 : : * @param[in, out] ref
4761 : : * Pointer to port ID action resource reference.
4762 : : * @parm[in, out] dev_flow
4763 : : * Pointer to the dev_flow.
4764 : : * @param[out] error
4765 : : * pointer to error structure.
4766 : : *
4767 : : * @return
4768 : : * 0 on success otherwise -errno and errno is set.
4769 : : */
4770 : : static int
4771 : 0 : flow_dv_push_vlan_action_resource_register
4772 : : (struct rte_eth_dev *dev,
4773 : : struct mlx5_flow_dv_push_vlan_action_resource *ref,
4774 : : struct mlx5_flow *dev_flow,
4775 : : struct rte_flow_error *error)
4776 : : {
4777 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4778 : : struct mlx5_flow_dv_push_vlan_action_resource *resource;
4779 : : struct mlx5_list_entry *entry;
4780 : 0 : struct mlx5_flow_cb_ctx ctx = {
4781 : : .error = error,
4782 : : .data = ref,
4783 : : };
4784 : :
4785 : 0 : entry = mlx5_list_register(priv->sh->push_vlan_action_list, &ctx);
4786 [ # # ]: 0 : if (!entry)
4787 : 0 : return -rte_errno;
4788 : : resource = container_of(entry, typeof(*resource), entry);
4789 : :
4790 : 0 : dev_flow->handle->dvh.rix_push_vlan = resource->idx;
4791 : 0 : dev_flow->dv.push_vlan_res = resource;
4792 : 0 : return 0;
4793 : : }
4794 : :
4795 : : /**
4796 : : * Get the size of specific rte_flow_item_type hdr size
4797 : : *
4798 : : * @param[in] item_type
4799 : : * Tested rte_flow_item_type.
4800 : : *
4801 : : * @return
4802 : : * sizeof struct item_type, 0 if void or irrelevant.
4803 : : */
4804 : : size_t
4805 [ # # ]: 0 : mlx5_flow_dv_get_item_hdr_len(const enum rte_flow_item_type item_type)
4806 : : {
4807 : : size_t retval;
4808 : :
4809 : : switch (item_type) {
4810 : : case RTE_FLOW_ITEM_TYPE_ETH:
4811 : : retval = sizeof(struct rte_ether_hdr);
4812 : : break;
4813 : : case RTE_FLOW_ITEM_TYPE_VLAN:
4814 : : retval = sizeof(struct rte_vlan_hdr);
4815 : : break;
4816 : : case RTE_FLOW_ITEM_TYPE_IPV4:
4817 : : retval = sizeof(struct rte_ipv4_hdr);
4818 : : break;
4819 : : case RTE_FLOW_ITEM_TYPE_IPV6:
4820 : : retval = sizeof(struct rte_ipv6_hdr);
4821 : : break;
4822 : : case RTE_FLOW_ITEM_TYPE_UDP:
4823 : : retval = sizeof(struct rte_udp_hdr);
4824 : : break;
4825 : : case RTE_FLOW_ITEM_TYPE_TCP:
4826 : : retval = sizeof(struct rte_tcp_hdr);
4827 : : break;
4828 : : case RTE_FLOW_ITEM_TYPE_VXLAN:
4829 : : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
4830 : : retval = sizeof(struct rte_vxlan_hdr);
4831 : : break;
4832 : : case RTE_FLOW_ITEM_TYPE_GRE:
4833 : : case RTE_FLOW_ITEM_TYPE_NVGRE:
4834 : : retval = sizeof(struct rte_gre_hdr);
4835 : : break;
4836 : : case RTE_FLOW_ITEM_TYPE_MPLS:
4837 : : retval = sizeof(struct rte_mpls_hdr);
4838 : : break;
4839 : : case RTE_FLOW_ITEM_TYPE_VOID: /* Fall through. */
4840 : : default:
4841 : : retval = 0;
4842 : : break;
4843 : : }
4844 : 0 : return retval;
4845 : : }
4846 : :
4847 : : #define MLX5_ENCAP_IPV4_VERSION 0x40
4848 : : #define MLX5_ENCAP_IPV4_IHL_MIN 0x05
4849 : : #define MLX5_ENCAP_IPV4_TTL_DEF 0x40
4850 : : #define MLX5_ENCAP_IPV6_VTC_FLOW 0x60000000
4851 : : #define MLX5_ENCAP_IPV6_HOP_LIMIT 0xff
4852 : : #define MLX5_ENCAP_VXLAN_FLAGS 0x08000000
4853 : : #define MLX5_ENCAP_VXLAN_GPE_FLAGS 0x04
4854 : :
4855 : : /**
4856 : : * Convert the encap action data from list of rte_flow_item to raw buffer
4857 : : *
4858 : : * @param[in] items
4859 : : * Pointer to rte_flow_item objects list.
4860 : : * @param[out] buf
4861 : : * Pointer to the output buffer.
4862 : : * @param[out] size
4863 : : * Pointer to the output buffer size.
4864 : : * @param[out] error
4865 : : * Pointer to the error structure.
4866 : : *
4867 : : * @return
4868 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4869 : : */
4870 : : int
4871 : 0 : mlx5_flow_dv_convert_encap_data(const struct rte_flow_item *items, uint8_t *buf,
4872 : : size_t *size, struct rte_flow_error *error)
4873 : : {
4874 : : struct rte_ether_hdr *eth = NULL;
4875 : : struct rte_vlan_hdr *vlan = NULL;
4876 : : struct rte_ipv4_hdr *ipv4 = NULL;
4877 : : struct rte_ipv6_hdr *ipv6 = NULL;
4878 : : struct rte_udp_hdr *udp = NULL;
4879 : : struct rte_vxlan_hdr *vxlan = NULL;
4880 : : struct rte_vxlan_gpe_hdr *vxlan_gpe = NULL;
4881 : : struct rte_gre_hdr *gre = NULL;
4882 : : size_t len;
4883 : : size_t temp_size = 0;
4884 : :
4885 [ # # ]: 0 : if (!items)
4886 : 0 : return rte_flow_error_set(error, EINVAL,
4887 : : RTE_FLOW_ERROR_TYPE_ACTION,
4888 : : NULL, "invalid empty data");
4889 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4890 : 0 : len = mlx5_flow_dv_get_item_hdr_len(items->type);
4891 [ # # ]: 0 : if (len + temp_size > MLX5_ENCAP_MAX_LEN)
4892 : 0 : return rte_flow_error_set(error, EINVAL,
4893 : : RTE_FLOW_ERROR_TYPE_ACTION,
4894 : 0 : (void *)items->type,
4895 : : "items total size is too big"
4896 : : " for encap action");
4897 [ # # ]: 0 : if (items->spec)
4898 [ # # ]: 0 : rte_memcpy(&buf[temp_size], items->spec, len);
4899 [ # # # # : 0 : switch (items->type) {
# # # # #
# ]
4900 : 0 : case RTE_FLOW_ITEM_TYPE_ETH:
4901 : 0 : eth = (struct rte_ether_hdr *)&buf[temp_size];
4902 : 0 : break;
4903 : 0 : case RTE_FLOW_ITEM_TYPE_VLAN:
4904 : 0 : vlan = (struct rte_vlan_hdr *)&buf[temp_size];
4905 [ # # ]: 0 : if (!eth)
4906 : 0 : return rte_flow_error_set(error, EINVAL,
4907 : : RTE_FLOW_ERROR_TYPE_ACTION,
4908 : : (void *)items->type,
4909 : : "eth header not found");
4910 [ # # ]: 0 : if (!eth->ether_type)
4911 : 0 : eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_VLAN);
4912 : : break;
4913 : 0 : case RTE_FLOW_ITEM_TYPE_IPV4:
4914 : 0 : ipv4 = (struct rte_ipv4_hdr *)&buf[temp_size];
4915 [ # # ]: 0 : if (!vlan && !eth)
4916 : 0 : return rte_flow_error_set(error, EINVAL,
4917 : : RTE_FLOW_ERROR_TYPE_ACTION,
4918 : : (void *)items->type,
4919 : : "neither eth nor vlan"
4920 : : " header found");
4921 [ # # # # ]: 0 : if (vlan && !vlan->eth_proto)
4922 : 0 : vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV4);
4923 [ # # # # ]: 0 : else if (eth && !eth->ether_type)
4924 : 0 : eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV4);
4925 [ # # ]: 0 : if (!ipv4->version_ihl)
4926 : 0 : ipv4->version_ihl = MLX5_ENCAP_IPV4_VERSION |
4927 : : MLX5_ENCAP_IPV4_IHL_MIN;
4928 [ # # ]: 0 : if (!ipv4->time_to_live)
4929 : 0 : ipv4->time_to_live = MLX5_ENCAP_IPV4_TTL_DEF;
4930 : : break;
4931 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6:
4932 : 0 : ipv6 = (struct rte_ipv6_hdr *)&buf[temp_size];
4933 [ # # ]: 0 : if (!vlan && !eth)
4934 : 0 : return rte_flow_error_set(error, EINVAL,
4935 : : RTE_FLOW_ERROR_TYPE_ACTION,
4936 : : (void *)items->type,
4937 : : "neither eth nor vlan"
4938 : : " header found");
4939 [ # # # # ]: 0 : if (vlan && !vlan->eth_proto)
4940 : 0 : vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV6);
4941 [ # # # # ]: 0 : else if (eth && !eth->ether_type)
4942 : 0 : eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV6);
4943 [ # # ]: 0 : if (!ipv6->vtc_flow)
4944 : 0 : ipv6->vtc_flow =
4945 : : RTE_BE32(MLX5_ENCAP_IPV6_VTC_FLOW);
4946 [ # # ]: 0 : if (!ipv6->hop_limits)
4947 : 0 : ipv6->hop_limits = MLX5_ENCAP_IPV6_HOP_LIMIT;
4948 : : break;
4949 : 0 : case RTE_FLOW_ITEM_TYPE_UDP:
4950 : 0 : udp = (struct rte_udp_hdr *)&buf[temp_size];
4951 [ # # ]: 0 : if (!ipv4 && !ipv6)
4952 : 0 : return rte_flow_error_set(error, EINVAL,
4953 : : RTE_FLOW_ERROR_TYPE_ACTION,
4954 : : (void *)items->type,
4955 : : "ip header not found");
4956 [ # # # # ]: 0 : if (ipv4 && !ipv4->next_proto_id)
4957 : 0 : ipv4->next_proto_id = IPPROTO_UDP;
4958 [ # # # # ]: 0 : else if (ipv6 && !ipv6->proto)
4959 : 0 : ipv6->proto = IPPROTO_UDP;
4960 : : break;
4961 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN:
4962 : 0 : vxlan = (struct rte_vxlan_hdr *)&buf[temp_size];
4963 [ # # ]: 0 : if (!udp)
4964 : 0 : return rte_flow_error_set(error, EINVAL,
4965 : : RTE_FLOW_ERROR_TYPE_ACTION,
4966 : : (void *)items->type,
4967 : : "udp header not found");
4968 [ # # ]: 0 : if (!udp->dst_port)
4969 : 0 : udp->dst_port = RTE_BE16(MLX5_UDP_PORT_VXLAN);
4970 [ # # ]: 0 : if (!vxlan->vx_flags)
4971 : 0 : vxlan->vx_flags =
4972 : : RTE_BE32(MLX5_ENCAP_VXLAN_FLAGS);
4973 : : break;
4974 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
4975 : 0 : vxlan_gpe = (struct rte_vxlan_gpe_hdr *)&buf[temp_size];
4976 [ # # ]: 0 : if (!udp)
4977 : 0 : return rte_flow_error_set(error, EINVAL,
4978 : : RTE_FLOW_ERROR_TYPE_ACTION,
4979 : : (void *)items->type,
4980 : : "udp header not found");
4981 [ # # ]: 0 : if (!vxlan_gpe->proto)
4982 : 0 : return rte_flow_error_set(error, EINVAL,
4983 : : RTE_FLOW_ERROR_TYPE_ACTION,
4984 : : (void *)items->type,
4985 : : "next protocol not found");
4986 [ # # ]: 0 : if (!udp->dst_port)
4987 : 0 : udp->dst_port =
4988 : : RTE_BE16(MLX5_UDP_PORT_VXLAN_GPE);
4989 [ # # ]: 0 : if (!vxlan_gpe->vx_flags)
4990 : 0 : vxlan_gpe->vx_flags =
4991 : : MLX5_ENCAP_VXLAN_GPE_FLAGS;
4992 : : break;
4993 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
4994 : : case RTE_FLOW_ITEM_TYPE_NVGRE:
4995 : 0 : gre = (struct rte_gre_hdr *)&buf[temp_size];
4996 [ # # ]: 0 : if (!gre->proto)
4997 : 0 : return rte_flow_error_set(error, EINVAL,
4998 : : RTE_FLOW_ERROR_TYPE_ACTION,
4999 : 0 : (void *)items->type,
5000 : : "next protocol not found");
5001 [ # # ]: 0 : if (!ipv4 && !ipv6)
5002 : 0 : return rte_flow_error_set(error, EINVAL,
5003 : : RTE_FLOW_ERROR_TYPE_ACTION,
5004 : 0 : (void *)items->type,
5005 : : "ip header not found");
5006 [ # # # # ]: 0 : if (ipv4 && !ipv4->next_proto_id)
5007 : 0 : ipv4->next_proto_id = IPPROTO_GRE;
5008 [ # # # # ]: 0 : else if (ipv6 && !ipv6->proto)
5009 : 0 : ipv6->proto = IPPROTO_GRE;
5010 : : break;
5011 : : case RTE_FLOW_ITEM_TYPE_VOID:
5012 : : break;
5013 : 0 : default:
5014 : 0 : return rte_flow_error_set(error, EINVAL,
5015 : : RTE_FLOW_ERROR_TYPE_ACTION,
5016 : 0 : (void *)items->type,
5017 : : "unsupported item type");
5018 : : break;
5019 : : }
5020 : : temp_size += len;
5021 : : }
5022 : 0 : *size = temp_size;
5023 : 0 : return 0;
5024 : : }
5025 : :
5026 : : static int
5027 : 0 : flow_dv_zero_encap_udp_csum(void *data, struct rte_flow_error *error)
5028 : : {
5029 : : struct rte_ether_hdr *eth = NULL;
5030 : : struct rte_vlan_hdr *vlan = NULL;
5031 : : struct rte_ipv4_hdr *ipv4 = NULL;
5032 : : struct rte_ipv6_hdr *ipv6 = NULL;
5033 : : struct rte_udp_hdr *udp = NULL;
5034 : : char *next_hdr;
5035 : : uint16_t proto;
5036 : :
5037 : : eth = (struct rte_ether_hdr *)data;
5038 : 0 : next_hdr = (char *)(eth + 1);
5039 : 0 : proto = RTE_BE16(eth->ether_type);
5040 : :
5041 : : /* VLAN skipping */
5042 [ # # ]: 0 : while (proto == RTE_ETHER_TYPE_VLAN || proto == RTE_ETHER_TYPE_QINQ) {
5043 : : vlan = (struct rte_vlan_hdr *)next_hdr;
5044 : 0 : proto = RTE_BE16(vlan->eth_proto);
5045 : 0 : next_hdr += sizeof(struct rte_vlan_hdr);
5046 : : }
5047 : :
5048 : : /* non IPv4/IPv6 header. not supported */
5049 [ # # ]: 0 : if (proto != RTE_ETHER_TYPE_IPV4 && proto != RTE_ETHER_TYPE_IPV6) {
5050 : 0 : return rte_flow_error_set(error, ENOTSUP,
5051 : : RTE_FLOW_ERROR_TYPE_ACTION,
5052 : : NULL, "Cannot offload non IPv4/IPv6");
5053 : : }
5054 : :
5055 [ # # ]: 0 : if (proto == RTE_ETHER_TYPE_IPV4) {
5056 : : ipv4 = (struct rte_ipv4_hdr *)next_hdr;
5057 : : /* ignore non UDP */
5058 [ # # ]: 0 : if (ipv4->next_proto_id != IPPROTO_UDP)
5059 : : return 0;
5060 : 0 : udp = (struct rte_udp_hdr *)(ipv4 + 1);
5061 : : } else {
5062 : : ipv6 = (struct rte_ipv6_hdr *)next_hdr;
5063 : : /* ignore non UDP */
5064 [ # # ]: 0 : if (ipv6->proto != IPPROTO_UDP)
5065 : : return 0;
5066 : 0 : udp = (struct rte_udp_hdr *)(ipv6 + 1);
5067 : : }
5068 : :
5069 : 0 : udp->dgram_cksum = 0;
5070 : :
5071 : 0 : return 0;
5072 : : }
5073 : :
5074 : : /**
5075 : : * Convert L2 encap action to DV specification.
5076 : : *
5077 : : * @param[in] dev
5078 : : * Pointer to rte_eth_dev structure.
5079 : : * @param[in] action
5080 : : * Pointer to action structure.
5081 : : * @param[in, out] dev_flow
5082 : : * Pointer to the mlx5_flow.
5083 : : * @param[in] transfer
5084 : : * Mark if the flow is E-Switch flow.
5085 : : * @param[out] error
5086 : : * Pointer to the error structure.
5087 : : *
5088 : : * @return
5089 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5090 : : */
5091 : : static int
5092 : 0 : flow_dv_create_action_l2_encap(struct rte_eth_dev *dev,
5093 : : const struct rte_flow_action *action,
5094 : : struct mlx5_flow *dev_flow,
5095 : : uint8_t transfer,
5096 : : struct rte_flow_error *error)
5097 : : {
5098 : : const struct rte_flow_item *encap_data;
5099 : : const struct rte_flow_action_raw_encap *raw_encap_data;
5100 [ # # ]: 0 : struct mlx5_flow_dv_encap_decap_resource res = {
5101 : : .reformat_type =
5102 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L2_TUNNEL,
5103 : : .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
5104 : : MLX5DV_FLOW_TABLE_TYPE_NIC_TX,
5105 : : };
5106 : :
5107 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
5108 : 0 : raw_encap_data =
5109 : : (const struct rte_flow_action_raw_encap *)action->conf;
5110 : 0 : res.size = raw_encap_data->size;
5111 : 0 : memcpy(res.buf, raw_encap_data->data, res.size);
5112 : : } else {
5113 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP)
5114 : 0 : encap_data =
5115 : : ((const struct rte_flow_action_vxlan_encap *)
5116 : 0 : action->conf)->definition;
5117 : : else
5118 : 0 : encap_data =
5119 : : ((const struct rte_flow_action_nvgre_encap *)
5120 : 0 : action->conf)->definition;
5121 [ # # ]: 0 : if (mlx5_flow_dv_convert_encap_data(encap_data, res.buf,
5122 : : &res.size, error))
5123 : 0 : return -rte_errno;
5124 : : }
5125 [ # # ]: 0 : if (flow_dv_zero_encap_udp_csum(res.buf, error))
5126 : 0 : return -rte_errno;
5127 [ # # ]: 0 : if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
5128 : 0 : return rte_flow_error_set(error, EINVAL,
5129 : : RTE_FLOW_ERROR_TYPE_ACTION,
5130 : : NULL, "can't create L2 encap action");
5131 : : return 0;
5132 : : }
5133 : :
5134 : : /**
5135 : : * Convert L2 decap action to DV specification.
5136 : : *
5137 : : * @param[in] dev
5138 : : * Pointer to rte_eth_dev structure.
5139 : : * @param[in, out] dev_flow
5140 : : * Pointer to the mlx5_flow.
5141 : : * @param[in] transfer
5142 : : * Mark if the flow is E-Switch flow.
5143 : : * @param[out] error
5144 : : * Pointer to the error structure.
5145 : : *
5146 : : * @return
5147 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5148 : : */
5149 : : static int
5150 : 0 : flow_dv_create_action_l2_decap(struct rte_eth_dev *dev,
5151 : : struct mlx5_flow *dev_flow,
5152 : : uint8_t transfer,
5153 : : struct rte_flow_error *error)
5154 : : {
5155 [ # # ]: 0 : struct mlx5_flow_dv_encap_decap_resource res = {
5156 : : .size = 0,
5157 : : .reformat_type =
5158 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2,
5159 : : .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
5160 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX,
5161 : : };
5162 : :
5163 [ # # ]: 0 : if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
5164 : 0 : return rte_flow_error_set(error, EINVAL,
5165 : : RTE_FLOW_ERROR_TYPE_ACTION,
5166 : : NULL, "can't create L2 decap action");
5167 : : return 0;
5168 : : }
5169 : :
5170 : : /**
5171 : : * Convert raw decap/encap (L3 tunnel) action to DV specification.
5172 : : *
5173 : : * @param[in] dev
5174 : : * Pointer to rte_eth_dev structure.
5175 : : * @param[in] action
5176 : : * Pointer to action structure.
5177 : : * @param[in, out] dev_flow
5178 : : * Pointer to the mlx5_flow.
5179 : : * @param[in] attr
5180 : : * Pointer to the flow attributes.
5181 : : * @param[out] error
5182 : : * Pointer to the error structure.
5183 : : *
5184 : : * @return
5185 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5186 : : */
5187 : : static int
5188 [ # # ]: 0 : flow_dv_create_action_raw_encap(struct rte_eth_dev *dev,
5189 : : const struct rte_flow_action *action,
5190 : : struct mlx5_flow *dev_flow,
5191 : : const struct rte_flow_attr *attr,
5192 : : struct rte_flow_error *error)
5193 : : {
5194 : : const struct rte_flow_action_raw_encap *encap_data;
5195 : : struct mlx5_flow_dv_encap_decap_resource res;
5196 : :
5197 : : memset(&res, 0, sizeof(res));
5198 : 0 : encap_data = (const struct rte_flow_action_raw_encap *)action->conf;
5199 : 0 : res.size = encap_data->size;
5200 [ # # ]: 0 : memcpy(res.buf, encap_data->data, res.size);
5201 [ # # ]: 0 : res.reformat_type = res.size < MLX5_ENCAPSULATION_DECISION_SIZE ?
5202 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L3_TUNNEL_TO_L2 :
5203 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L3_TUNNEL;
5204 [ # # ]: 0 : if (attr->transfer)
5205 : 0 : res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
5206 : : else
5207 : 0 : res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
5208 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
5209 [ # # ]: 0 : if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
5210 : 0 : return rte_flow_error_set(error, EINVAL,
5211 : : RTE_FLOW_ERROR_TYPE_ACTION,
5212 : : NULL, "can't create encap action");
5213 : : return 0;
5214 : : }
5215 : :
5216 : : /**
5217 : : * Create action push VLAN.
5218 : : *
5219 : : * @param[in] dev
5220 : : * Pointer to rte_eth_dev structure.
5221 : : * @param[in] attr
5222 : : * Pointer to the flow attributes.
5223 : : * @param[in] vlan
5224 : : * Pointer to the vlan to push to the Ethernet header.
5225 : : * @param[in, out] dev_flow
5226 : : * Pointer to the mlx5_flow.
5227 : : * @param[out] error
5228 : : * Pointer to the error structure.
5229 : : *
5230 : : * @return
5231 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5232 : : */
5233 : : static int
5234 [ # # ]: 0 : flow_dv_create_action_push_vlan(struct rte_eth_dev *dev,
5235 : : const struct rte_flow_attr *attr,
5236 : : const struct rte_vlan_hdr *vlan,
5237 : : struct mlx5_flow *dev_flow,
5238 : : struct rte_flow_error *error)
5239 : : {
5240 : : struct mlx5_flow_dv_push_vlan_action_resource res;
5241 : :
5242 : : memset(&res, 0, sizeof(res));
5243 : 0 : res.vlan_tag =
5244 [ # # ]: 0 : rte_cpu_to_be_32(((uint32_t)vlan->eth_proto) << 16 |
5245 : : vlan->vlan_tci);
5246 [ # # ]: 0 : if (attr->transfer)
5247 : 0 : res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
5248 : : else
5249 : 0 : res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
5250 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
5251 : 0 : return flow_dv_push_vlan_action_resource_register
5252 : : (dev, &res, dev_flow, error);
5253 : : }
5254 : :
5255 : : /**
5256 : : * Validate the modify-header actions.
5257 : : *
5258 : : * @param[in] action_flags
5259 : : * Holds the actions detected until now.
5260 : : * @param[in] action
5261 : : * Pointer to the modify action.
5262 : : * @param[out] error
5263 : : * Pointer to error structure.
5264 : : *
5265 : : * @return
5266 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5267 : : */
5268 : : static int
5269 : 0 : flow_dv_validate_action_modify_hdr(const uint64_t action_flags,
5270 : : const struct rte_flow_action *action,
5271 : : struct rte_flow_error *error)
5272 : : {
5273 [ # # # # ]: 0 : if (action->type != RTE_FLOW_ACTION_TYPE_DEC_TTL && !action->conf)
5274 : 0 : return rte_flow_error_set(error, EINVAL,
5275 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5276 : : NULL, "action configuration not set");
5277 : :
5278 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
5279 : 0 : return rte_flow_error_set(error, EINVAL,
5280 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5281 : : "can't have encap action before"
5282 : : " modify action");
5283 : : return 0;
5284 : : }
5285 : :
5286 : : /**
5287 : : * Validate the modify-header MAC address actions.
5288 : : *
5289 : : * @param[in] action_flags
5290 : : * Holds the actions detected until now.
5291 : : * @param[in] action
5292 : : * Pointer to the modify action.
5293 : : * @param[in] item_flags
5294 : : * Holds the items detected.
5295 : : * @param[out] error
5296 : : * Pointer to error structure.
5297 : : *
5298 : : * @return
5299 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5300 : : */
5301 : : static int
5302 : 0 : flow_dv_validate_action_modify_mac(const uint64_t action_flags,
5303 : : const struct rte_flow_action *action,
5304 : : const uint64_t item_flags,
5305 : : struct rte_flow_error *error)
5306 : : {
5307 : : int ret = 0;
5308 : :
5309 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5310 [ # # ]: 0 : if (!ret) {
5311 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_L2))
5312 : 0 : return rte_flow_error_set(error, EINVAL,
5313 : : RTE_FLOW_ERROR_TYPE_ACTION,
5314 : : NULL,
5315 : : "no L2 item in pattern");
5316 : : }
5317 : : return ret;
5318 : : }
5319 : :
5320 : : /**
5321 : : * Validate the modify-header IPv4 address actions.
5322 : : *
5323 : : * @param[in] action_flags
5324 : : * Holds the actions detected until now.
5325 : : * @param[in] action
5326 : : * Pointer to the modify action.
5327 : : * @param[in] item_flags
5328 : : * Holds the items detected.
5329 : : * @param[out] error
5330 : : * Pointer to error structure.
5331 : : *
5332 : : * @return
5333 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5334 : : */
5335 : : static int
5336 : 0 : flow_dv_validate_action_modify_ipv4(const uint64_t action_flags,
5337 : : const struct rte_flow_action *action,
5338 : : const uint64_t item_flags,
5339 : : struct rte_flow_error *error)
5340 : : {
5341 : : int ret = 0;
5342 : : uint64_t layer;
5343 : :
5344 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5345 [ # # ]: 0 : if (!ret) {
5346 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5347 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L3_IPV4 :
5348 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4;
5349 [ # # ]: 0 : if (!(item_flags & layer))
5350 : 0 : return rte_flow_error_set(error, EINVAL,
5351 : : RTE_FLOW_ERROR_TYPE_ACTION,
5352 : : NULL,
5353 : : "no ipv4 item in pattern");
5354 : : }
5355 : : return ret;
5356 : : }
5357 : :
5358 : : /**
5359 : : * Validate the modify-header IPv6 address actions.
5360 : : *
5361 : : * @param[in] action_flags
5362 : : * Holds the actions detected until now.
5363 : : * @param[in] action
5364 : : * Pointer to the modify action.
5365 : : * @param[in] item_flags
5366 : : * Holds the items detected.
5367 : : * @param[out] error
5368 : : * Pointer to error structure.
5369 : : *
5370 : : * @return
5371 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5372 : : */
5373 : : static int
5374 : 0 : flow_dv_validate_action_modify_ipv6(const uint64_t action_flags,
5375 : : const struct rte_flow_action *action,
5376 : : const uint64_t item_flags,
5377 : : struct rte_flow_error *error)
5378 : : {
5379 : : int ret = 0;
5380 : : uint64_t layer;
5381 : :
5382 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5383 [ # # ]: 0 : if (!ret) {
5384 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5385 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L3_IPV6 :
5386 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6;
5387 [ # # ]: 0 : if (!(item_flags & layer))
5388 : 0 : return rte_flow_error_set(error, EINVAL,
5389 : : RTE_FLOW_ERROR_TYPE_ACTION,
5390 : : NULL,
5391 : : "no ipv6 item in pattern");
5392 : : }
5393 : : return ret;
5394 : : }
5395 : :
5396 : : /**
5397 : : * Validate the modify-header TP actions.
5398 : : *
5399 : : * @param[in] action_flags
5400 : : * Holds the actions detected until now.
5401 : : * @param[in] action
5402 : : * Pointer to the modify action.
5403 : : * @param[in] item_flags
5404 : : * Holds the items detected.
5405 : : * @param[out] error
5406 : : * Pointer to error structure.
5407 : : *
5408 : : * @return
5409 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5410 : : */
5411 : : static int
5412 : 0 : flow_dv_validate_action_modify_tp(const uint64_t action_flags,
5413 : : const struct rte_flow_action *action,
5414 : : const uint64_t item_flags,
5415 : : struct rte_flow_error *error)
5416 : : {
5417 : : int ret = 0;
5418 : : uint64_t layer;
5419 : :
5420 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5421 [ # # ]: 0 : if (!ret) {
5422 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5423 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L4 :
5424 : : MLX5_FLOW_LAYER_OUTER_L4;
5425 [ # # ]: 0 : if (!(item_flags & layer))
5426 : 0 : return rte_flow_error_set(error, EINVAL,
5427 : : RTE_FLOW_ERROR_TYPE_ACTION,
5428 : : NULL, "no transport layer "
5429 : : "in pattern");
5430 : : }
5431 : : return ret;
5432 : : }
5433 : :
5434 : : /**
5435 : : * Validate the modify-header actions of increment/decrement
5436 : : * TCP Sequence-number.
5437 : : *
5438 : : * @param[in] action_flags
5439 : : * Holds the actions detected until now.
5440 : : * @param[in] action
5441 : : * Pointer to the modify action.
5442 : : * @param[in] item_flags
5443 : : * Holds the items detected.
5444 : : * @param[out] error
5445 : : * Pointer to error structure.
5446 : : *
5447 : : * @return
5448 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5449 : : */
5450 : : static int
5451 : 0 : flow_dv_validate_action_modify_tcp_seq(const uint64_t action_flags,
5452 : : const struct rte_flow_action *action,
5453 : : const uint64_t item_flags,
5454 : : struct rte_flow_error *error)
5455 : : {
5456 : : int ret = 0;
5457 : : uint64_t layer;
5458 : :
5459 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5460 [ # # ]: 0 : if (!ret) {
5461 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5462 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L4_TCP :
5463 : : MLX5_FLOW_LAYER_OUTER_L4_TCP;
5464 [ # # ]: 0 : if (!(item_flags & layer))
5465 : 0 : return rte_flow_error_set(error, EINVAL,
5466 : : RTE_FLOW_ERROR_TYPE_ACTION,
5467 : : NULL, "no TCP item in"
5468 : : " pattern");
5469 [ # # ]: 0 : if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ &&
5470 [ # # # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_DEC_TCP_SEQ)) ||
5471 : 0 : (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ &&
5472 [ # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_INC_TCP_SEQ)))
5473 : 0 : return rte_flow_error_set(error, EINVAL,
5474 : : RTE_FLOW_ERROR_TYPE_ACTION,
5475 : : NULL,
5476 : : "cannot decrease and increase"
5477 : : " TCP sequence number"
5478 : : " at the same time");
5479 : : }
5480 : : return ret;
5481 : : }
5482 : :
5483 : : /**
5484 : : * Validate the modify-header actions of increment/decrement
5485 : : * TCP Acknowledgment number.
5486 : : *
5487 : : * @param[in] action_flags
5488 : : * Holds the actions detected until now.
5489 : : * @param[in] action
5490 : : * Pointer to the modify action.
5491 : : * @param[in] item_flags
5492 : : * Holds the items detected.
5493 : : * @param[out] error
5494 : : * Pointer to error structure.
5495 : : *
5496 : : * @return
5497 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5498 : : */
5499 : : static int
5500 : 0 : flow_dv_validate_action_modify_tcp_ack(const uint64_t action_flags,
5501 : : const struct rte_flow_action *action,
5502 : : const uint64_t item_flags,
5503 : : struct rte_flow_error *error)
5504 : : {
5505 : : int ret = 0;
5506 : : uint64_t layer;
5507 : :
5508 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5509 [ # # ]: 0 : if (!ret) {
5510 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5511 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L4_TCP :
5512 : : MLX5_FLOW_LAYER_OUTER_L4_TCP;
5513 [ # # ]: 0 : if (!(item_flags & layer))
5514 : 0 : return rte_flow_error_set(error, EINVAL,
5515 : : RTE_FLOW_ERROR_TYPE_ACTION,
5516 : : NULL, "no TCP item in"
5517 : : " pattern");
5518 [ # # ]: 0 : if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_ACK &&
5519 [ # # # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_DEC_TCP_ACK)) ||
5520 : 0 : (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK &&
5521 [ # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_INC_TCP_ACK)))
5522 : 0 : return rte_flow_error_set(error, EINVAL,
5523 : : RTE_FLOW_ERROR_TYPE_ACTION,
5524 : : NULL,
5525 : : "cannot decrease and increase"
5526 : : " TCP acknowledgment number"
5527 : : " at the same time");
5528 : : }
5529 : : return ret;
5530 : : }
5531 : :
5532 : : /**
5533 : : * Validate the modify-header TTL actions.
5534 : : *
5535 : : * @param[in] action_flags
5536 : : * Holds the actions detected until now.
5537 : : * @param[in] action
5538 : : * Pointer to the modify action.
5539 : : * @param[in] item_flags
5540 : : * Holds the items detected.
5541 : : * @param[out] error
5542 : : * Pointer to error structure.
5543 : : *
5544 : : * @return
5545 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5546 : : */
5547 : : static int
5548 : 0 : flow_dv_validate_action_modify_ttl(const uint64_t action_flags,
5549 : : const struct rte_flow_action *action,
5550 : : const uint64_t item_flags,
5551 : : struct rte_flow_error *error)
5552 : : {
5553 : : int ret = 0;
5554 : : uint64_t layer;
5555 : :
5556 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5557 [ # # ]: 0 : if (!ret) {
5558 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5559 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L3 :
5560 : : MLX5_FLOW_LAYER_OUTER_L3;
5561 [ # # ]: 0 : if (!(item_flags & layer))
5562 : 0 : return rte_flow_error_set(error, EINVAL,
5563 : : RTE_FLOW_ERROR_TYPE_ACTION,
5564 : : NULL,
5565 : : "no IP protocol in pattern");
5566 : : }
5567 : : return ret;
5568 : : }
5569 : :
5570 : : /**
5571 : : * Validate the generic modify field actions.
5572 : : * @param[in] dev
5573 : : * Pointer to the rte_eth_dev structure.
5574 : : * @param[in] action_flags
5575 : : * Holds the actions detected until now.
5576 : : * @param[in] action
5577 : : * Pointer to the modify action.
5578 : : * @param[in] attr
5579 : : * Pointer to the flow attributes.
5580 : : * @param root
5581 : : * Whether action is on root table.
5582 : : * @param[out] error
5583 : : * Pointer to error structure.
5584 : : *
5585 : : * @return
5586 : : * Number of header fields to modify (0 or more) on success,
5587 : : * a negative errno value otherwise and rte_errno is set.
5588 : : */
5589 : : static int
5590 : 0 : flow_dv_validate_action_modify_field(struct rte_eth_dev *dev,
5591 : : const uint64_t action_flags,
5592 : : const struct rte_flow_action *action,
5593 : : const struct rte_flow_attr *attr,
5594 : : bool root,
5595 : : struct rte_flow_error *error)
5596 : : {
5597 : : int ret = 0;
5598 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5599 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
5600 : 0 : struct mlx5_hca_attr *hca_attr = &priv->sh->cdev->config.hca_attr;
5601 : 0 : const struct rte_flow_action_modify_field *conf = action->conf;
5602 : 0 : const struct rte_flow_field_data *src_data = &conf->src;
5603 : 0 : const struct rte_flow_field_data *dst_data = &conf->dst;
5604 : 0 : uint32_t dst_width, src_width, width = conf->width;
5605 : :
5606 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5607 [ # # ]: 0 : if (ret)
5608 : : return ret;
5609 [ # # ]: 0 : if (src_data->field == RTE_FLOW_FIELD_FLEX_ITEM ||
5610 [ # # ]: 0 : dst_data->field == RTE_FLOW_FIELD_FLEX_ITEM)
5611 : 0 : return rte_flow_error_set(error, ENOTSUP,
5612 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5613 : : "flex item fields modification"
5614 : : " is not supported");
5615 : 0 : dst_width = mlx5_flow_item_field_width(dev, dst_data->field,
5616 : : -1, attr, error);
5617 : 0 : src_width = mlx5_flow_item_field_width(dev, src_data->field,
5618 : : dst_width, attr, error);
5619 [ # # ]: 0 : if (width == 0)
5620 : 0 : return rte_flow_error_set(error, EINVAL,
5621 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5622 : : "no bits are requested to be modified");
5623 [ # # ]: 0 : else if (width > dst_width || width > src_width)
5624 : 0 : return rte_flow_error_set(error, EINVAL,
5625 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5626 : : "cannot modify more bits than"
5627 : : " the width of a field");
5628 [ # # ]: 0 : if (dst_data->field != RTE_FLOW_FIELD_VALUE &&
5629 : : dst_data->field != RTE_FLOW_FIELD_POINTER) {
5630 [ # # ]: 0 : if (dst_data->offset + width > dst_width)
5631 : 0 : return rte_flow_error_set(error, EINVAL,
5632 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5633 : : "destination offset is too big");
5634 : 0 : ret = mlx5_flow_validate_modify_field_level(dst_data, error);
5635 [ # # ]: 0 : if (ret)
5636 : : return ret;
5637 [ # # ]: 0 : if (dst_data->tag_index &&
5638 [ # # ]: 0 : !flow_modify_field_support_tag_array(dst_data->field))
5639 : 0 : return rte_flow_error_set(error, EINVAL,
5640 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5641 : : "destination tag index is not supported");
5642 [ # # ]: 0 : if (dst_data->class_id)
5643 : 0 : return rte_flow_error_set(error, EINVAL,
5644 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5645 : : "destination class ID is not supported");
5646 : : }
5647 [ # # ]: 0 : if (src_data->field != RTE_FLOW_FIELD_VALUE &&
5648 : : src_data->field != RTE_FLOW_FIELD_POINTER) {
5649 [ # # ]: 0 : if (conf->operation != RTE_FLOW_MODIFY_SET)
5650 : 0 : return rte_flow_error_set(error, ENOTSUP,
5651 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5652 : 0 : &conf->operation,
5653 : : "modify field action type add is not"
5654 : : " supported when src field type is"
5655 : : " not value/pointer");
5656 [ # # ]: 0 : if (root)
5657 : 0 : return rte_flow_error_set(error, ENOTSUP,
5658 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5659 : : "modify field action is not"
5660 : : " supported for group 0");
5661 [ # # ]: 0 : if (src_data->offset + width > src_width)
5662 : 0 : return rte_flow_error_set(error, EINVAL,
5663 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5664 : : "source offset is too big");
5665 : 0 : ret = mlx5_flow_validate_modify_field_level(src_data, error);
5666 [ # # ]: 0 : if (ret)
5667 : : return ret;
5668 [ # # ]: 0 : if (src_data->tag_index &&
5669 [ # # ]: 0 : !flow_modify_field_support_tag_array(src_data->field))
5670 : 0 : return rte_flow_error_set(error, EINVAL,
5671 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5672 : : "source tag index is not supported");
5673 [ # # ]: 0 : if (src_data->class_id)
5674 : 0 : return rte_flow_error_set(error, EINVAL,
5675 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5676 : : "source class ID is not supported");
5677 : : }
5678 [ # # ]: 0 : if ((dst_data->field == src_data->field) &&
5679 [ # # ]: 0 : (dst_data->level == src_data->level))
5680 : 0 : return rte_flow_error_set(error, EINVAL,
5681 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5682 : : "source and destination fields"
5683 : : " cannot be the same");
5684 : 0 : if (dst_data->field == RTE_FLOW_FIELD_VALUE ||
5685 [ # # ]: 0 : dst_data->field == RTE_FLOW_FIELD_POINTER ||
5686 : : dst_data->field == RTE_FLOW_FIELD_MARK)
5687 : 0 : return rte_flow_error_set(error, EINVAL,
5688 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5689 : : "mark, immediate value or a pointer to it"
5690 : : " cannot be used as a destination");
5691 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_START ||
5692 : : src_data->field == RTE_FLOW_FIELD_START)
5693 : 0 : return rte_flow_error_set(error, ENOTSUP,
5694 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5695 : : "modifications of an arbitrary"
5696 : : " place in a packet is not supported");
5697 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_VLAN_TYPE ||
5698 : : src_data->field == RTE_FLOW_FIELD_VLAN_TYPE)
5699 : 0 : return rte_flow_error_set(error, ENOTSUP,
5700 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5701 : : "modifications of the 802.1Q Tag"
5702 : : " Identifier is not supported");
5703 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_VXLAN_VNI ||
5704 : : src_data->field == RTE_FLOW_FIELD_VXLAN_VNI)
5705 : 0 : return rte_flow_error_set(error, ENOTSUP,
5706 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5707 : : "modifications of the VXLAN Network"
5708 : : " Identifier is not supported");
5709 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_GENEVE_VNI ||
5710 : : src_data->field == RTE_FLOW_FIELD_GENEVE_VNI)
5711 : 0 : return rte_flow_error_set(error, ENOTSUP,
5712 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5713 : : "modifications of the GENEVE Network"
5714 : : " Identifier is not supported");
5715 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_GENEVE_OPT_TYPE ||
5716 : : src_data->field == RTE_FLOW_FIELD_GENEVE_OPT_TYPE)
5717 : 0 : return rte_flow_error_set(error, ENOTSUP,
5718 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5719 : : "modifications of the GENEVE option type is not supported");
5720 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_GENEVE_OPT_CLASS ||
5721 : : src_data->field == RTE_FLOW_FIELD_GENEVE_OPT_CLASS)
5722 : 0 : return rte_flow_error_set(error, ENOTSUP,
5723 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5724 : : "modifications of the GENEVE option class is not supported");
5725 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_GENEVE_OPT_DATA ||
5726 : : src_data->field == RTE_FLOW_FIELD_GENEVE_OPT_DATA)
5727 : 0 : return rte_flow_error_set(error, ENOTSUP,
5728 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5729 : : "modifications of the GENEVE option data is not supported");
5730 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_MPLS ||
5731 : : src_data->field == RTE_FLOW_FIELD_MPLS)
5732 : 0 : return rte_flow_error_set(error, ENOTSUP,
5733 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5734 : : "modifications of the MPLS header "
5735 : : "is not supported");
5736 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_RANDOM ||
5737 : : src_data->field == RTE_FLOW_FIELD_RANDOM)
5738 : 0 : return rte_flow_error_set(error, ENOTSUP,
5739 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5740 : : "modifications of random value is not supported");
5741 [ # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_MARK ||
5742 : : src_data->field == RTE_FLOW_FIELD_MARK)
5743 [ # # # # ]: 0 : if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
5744 : 0 : !mlx5_flow_ext_mreg_supported(dev))
5745 : 0 : return rte_flow_error_set(error, ENOTSUP,
5746 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5747 : : "cannot modify mark in legacy mode"
5748 : : " or without extensive registers");
5749 [ # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_META ||
5750 [ # # ]: 0 : src_data->field == RTE_FLOW_FIELD_META) {
5751 [ # # # # ]: 0 : if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
5752 : 0 : !mlx5_flow_ext_mreg_supported(dev))
5753 : 0 : return rte_flow_error_set(error, ENOTSUP,
5754 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5755 : : "cannot modify meta without"
5756 : : " extensive registers support");
5757 : 0 : ret = flow_dv_get_metadata_reg(dev, attr, error);
5758 [ # # ]: 0 : if (ret < 0 || ret == REG_NON)
5759 : 0 : return rte_flow_error_set(error, ENOTSUP,
5760 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5761 : : "cannot modify meta without"
5762 : : " extensive registers available");
5763 : : }
5764 [ # # ]: 0 : if (conf->operation == RTE_FLOW_MODIFY_SUB)
5765 : 0 : return rte_flow_error_set(error, ENOTSUP,
5766 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5767 : : "sub operations are not supported");
5768 [ # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_IPV4_ECN ||
5769 [ # # # # ]: 0 : src_data->field == RTE_FLOW_FIELD_IPV4_ECN ||
5770 [ # # ]: 0 : dst_data->field == RTE_FLOW_FIELD_IPV6_ECN ||
5771 : : src_data->field == RTE_FLOW_FIELD_IPV6_ECN)
5772 [ # # # # ]: 0 : if (!hca_attr->modify_outer_ip_ecn && root)
5773 : 0 : return rte_flow_error_set(error, ENOTSUP,
5774 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5775 : : "modifications of the ECN for current firmware is not supported");
5776 : 0 : return (width / 32) + !!(width % 32);
5777 : : }
5778 : :
5779 : : /**
5780 : : * Validate jump action.
5781 : : *
5782 : : * @param[in] action
5783 : : * Pointer to the jump action.
5784 : : * @param[in] action_flags
5785 : : * Holds the actions detected until now.
5786 : : * @param[in] attributes
5787 : : * Pointer to flow attributes
5788 : : * @param[in] external
5789 : : * Action belongs to flow rule created by request external to PMD.
5790 : : * @param[out] error
5791 : : * Pointer to error structure.
5792 : : *
5793 : : * @return
5794 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5795 : : */
5796 : : static int
5797 : 0 : flow_dv_validate_action_jump(struct rte_eth_dev *dev,
5798 : : const struct mlx5_flow_tunnel *tunnel,
5799 : : const struct rte_flow_action *action,
5800 : : uint64_t action_flags,
5801 : : const struct rte_flow_attr *attributes,
5802 : : bool external, struct rte_flow_error *error)
5803 : : {
5804 : 0 : uint32_t target_group, table = 0;
5805 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5806 : : int ret = 0;
5807 : 0 : struct flow_grp_info grp_info = {
5808 : : .external = !!external,
5809 : 0 : .transfer = !!attributes->transfer,
5810 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
5811 : : .std_tbl_fix = 0
5812 : : };
5813 [ # # ]: 0 : if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
5814 : : MLX5_FLOW_FATE_ESWITCH_ACTIONS))
5815 : 0 : return rte_flow_error_set(error, EINVAL,
5816 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5817 : : "can't have 2 fate actions in"
5818 : : " same flow");
5819 [ # # ]: 0 : if (!action->conf)
5820 : 0 : return rte_flow_error_set(error, EINVAL,
5821 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5822 : : NULL, "action configuration not set");
5823 : 0 : target_group =
5824 : : ((const struct rte_flow_action_jump *)action->conf)->group;
5825 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel, target_group, &table,
5826 : : &grp_info, error);
5827 [ # # ]: 0 : if (ret)
5828 : : return ret;
5829 [ # # ]: 0 : if (table == 0)
5830 : 0 : return rte_flow_error_set(error, EINVAL,
5831 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5832 : : NULL, "root table shouldn't be destination");
5833 : : return 0;
5834 : : }
5835 : :
5836 : : /*
5837 : : * Validate action PORT_ID / REPRESENTED_PORT.
5838 : : *
5839 : : * @param[in] dev
5840 : : * Pointer to rte_eth_dev structure.
5841 : : * @param[in] action_flags
5842 : : * Bit-fields that holds the actions detected until now.
5843 : : * @param[in] action
5844 : : * PORT_ID / REPRESENTED_PORT action structure.
5845 : : * @param[in] attr
5846 : : * Attributes of flow that includes this action.
5847 : : * @param[out] error
5848 : : * Pointer to error structure.
5849 : : *
5850 : : * @return
5851 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5852 : : */
5853 : : static int
5854 : 0 : flow_dv_validate_action_port_id(struct rte_eth_dev *dev,
5855 : : uint64_t action_flags,
5856 : : const struct rte_flow_action *action,
5857 : : const struct rte_flow_attr *attr,
5858 : : struct rte_flow_error *error)
5859 : : {
5860 : : const struct rte_flow_action_port_id *port_id;
5861 : : const struct rte_flow_action_ethdev *ethdev;
5862 : : struct mlx5_priv *act_priv;
5863 : : struct mlx5_priv *dev_priv;
5864 : : uint16_t port;
5865 : :
5866 [ # # ]: 0 : if (!attr->transfer)
5867 : 0 : return rte_flow_error_set(error, ENOTSUP,
5868 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5869 : : NULL,
5870 : : "port action is valid in transfer"
5871 : : " mode only");
5872 [ # # # # ]: 0 : if (!action || !action->conf)
5873 : 0 : return rte_flow_error_set(error, ENOTSUP,
5874 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5875 : : NULL,
5876 : : "port action parameters must be"
5877 : : " specified");
5878 [ # # ]: 0 : if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
5879 : : MLX5_FLOW_FATE_ESWITCH_ACTIONS))
5880 : 0 : return rte_flow_error_set(error, EINVAL,
5881 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5882 : : "can have only one fate actions in"
5883 : : " a flow");
5884 : 0 : dev_priv = mlx5_dev_to_eswitch_info(dev);
5885 [ # # ]: 0 : if (!dev_priv)
5886 : 0 : return rte_flow_error_set(error, rte_errno,
5887 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5888 : : NULL,
5889 : : "failed to obtain E-Switch info");
5890 [ # # # ]: 0 : switch (action->type) {
5891 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
5892 : 0 : port_id = action->conf;
5893 [ # # ]: 0 : port = port_id->original ? dev->data->port_id : port_id->id;
5894 : : break;
5895 : 0 : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
5896 : 0 : ethdev = action->conf;
5897 : 0 : port = ethdev->port_id;
5898 : 0 : break;
5899 : 0 : default:
5900 : : MLX5_ASSERT(false);
5901 : 0 : return rte_flow_error_set
5902 : : (error, EINVAL,
5903 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5904 : : "unknown E-Switch action");
5905 : : }
5906 : 0 : act_priv = mlx5_port_to_eswitch_info(port, false);
5907 [ # # ]: 0 : if (!act_priv)
5908 : 0 : return rte_flow_error_set
5909 : : (error, rte_errno,
5910 : 0 : RTE_FLOW_ERROR_TYPE_ACTION_CONF, action->conf,
5911 : : "failed to obtain E-Switch port id for port");
5912 [ # # ]: 0 : if (act_priv->domain_id != dev_priv->domain_id)
5913 : 0 : return rte_flow_error_set
5914 : : (error, EINVAL,
5915 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5916 : : "port does not belong to"
5917 : : " E-Switch being configured");
5918 : : return 0;
5919 : : }
5920 : :
5921 : : /**
5922 : : * Get the maximum number of modify header actions.
5923 : : *
5924 : : * @param dev
5925 : : * Pointer to rte_eth_dev structure.
5926 : : * @param root
5927 : : * Whether action is on root table.
5928 : : *
5929 : : * @return
5930 : : * Max number of modify header actions device can support.
5931 : : */
5932 : : static inline unsigned int
5933 : : flow_dv_modify_hdr_action_max(struct rte_eth_dev *dev __rte_unused,
5934 : : bool root)
5935 : : {
5936 : : /*
5937 : : * There's no way to directly query the max capacity from FW.
5938 : : * The maximal value on root table should be assumed to be supported.
5939 : : */
5940 [ # # ]: 0 : if (!root)
5941 : : return MLX5_MAX_MODIFY_NUM;
5942 : : else
5943 : 0 : return MLX5_ROOT_TBL_MODIFY_NUM;
5944 : : }
5945 : :
5946 : : /**
5947 : : * Validate the meter action.
5948 : : *
5949 : : * @param[in] dev
5950 : : * Pointer to rte_eth_dev structure.
5951 : : * @param[in] action_flags
5952 : : * Bit-fields that holds the actions detected until now.
5953 : : * @param[in] item_flags
5954 : : * Holds the items detected.
5955 : : * @param[in] action
5956 : : * Pointer to the meter action.
5957 : : * @param[in] attr
5958 : : * Attributes of flow that includes this action.
5959 : : * @param[in] port_id_item
5960 : : * Pointer to item indicating port id.
5961 : : * @param[out] error
5962 : : * Pointer to error structure.
5963 : : *
5964 : : * @return
5965 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5966 : : */
5967 : : static int
5968 : 0 : mlx5_flow_validate_action_meter(struct rte_eth_dev *dev,
5969 : : uint64_t action_flags, uint64_t item_flags,
5970 : : const struct rte_flow_action *action,
5971 : : const struct rte_flow_attr *attr,
5972 : : const struct rte_flow_item *port_id_item,
5973 : : bool *def_policy,
5974 : : struct rte_flow_error *error)
5975 : : {
5976 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5977 : 0 : const struct rte_flow_action_meter *am = action->conf;
5978 : : struct mlx5_flow_meter_info *fm;
5979 : : struct mlx5_flow_meter_policy *mtr_policy;
5980 : 0 : struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
5981 : 0 : uint16_t flow_src_port = priv->representor_id;
5982 : 0 : bool all_ports = false;
5983 : :
5984 [ # # ]: 0 : if (!am)
5985 : 0 : return rte_flow_error_set(error, EINVAL,
5986 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5987 : : "meter action conf is NULL");
5988 : :
5989 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_METER)
5990 : 0 : return rte_flow_error_set(error, ENOTSUP,
5991 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5992 : : "meter chaining not support");
5993 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_JUMP)
5994 : 0 : return rte_flow_error_set(error, ENOTSUP,
5995 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5996 : : "meter with jump not support");
5997 [ # # ]: 0 : if (!priv->mtr_en)
5998 : 0 : return rte_flow_error_set(error, ENOTSUP,
5999 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6000 : : NULL,
6001 : : "meter action not supported");
6002 : 0 : fm = mlx5_flow_meter_find(priv, am->mtr_id, NULL);
6003 [ # # ]: 0 : if (!fm)
6004 : 0 : return rte_flow_error_set(error, EINVAL,
6005 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6006 : : "Meter not found");
6007 : : /* aso meter can always be shared by different domains */
6008 [ # # # # ]: 0 : if (fm->ref_cnt && !priv->sh->meter_aso_en &&
6009 [ # # ]: 0 : !(fm->transfer == attr->transfer ||
6010 [ # # # # ]: 0 : (!fm->ingress && !attr->ingress && attr->egress) ||
6011 [ # # # # ]: 0 : (!fm->egress && !attr->egress && attr->ingress)))
6012 : 0 : return rte_flow_error_set(error, EINVAL,
6013 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6014 : : "Flow attributes domain are either invalid "
6015 : : "or have a domain conflict with current "
6016 : : "meter attributes");
6017 [ # # ]: 0 : if (fm->def_policy) {
6018 [ # # ]: 0 : if (!((attr->transfer &&
6019 [ # # ]: 0 : mtrmng->def_policy[MLX5_MTR_DOMAIN_TRANSFER]) ||
6020 [ # # ]: 0 : (attr->egress &&
6021 [ # # ]: 0 : mtrmng->def_policy[MLX5_MTR_DOMAIN_EGRESS]) ||
6022 [ # # ]: 0 : (attr->ingress &&
6023 [ # # ]: 0 : mtrmng->def_policy[MLX5_MTR_DOMAIN_INGRESS])))
6024 : 0 : return rte_flow_error_set(error, EINVAL,
6025 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6026 : : "Flow attributes domain "
6027 : : "have a conflict with current "
6028 : : "meter domain attributes");
6029 : 0 : *def_policy = true;
6030 : : } else {
6031 : 0 : mtr_policy = mlx5_flow_meter_policy_find(dev,
6032 : : fm->policy_id, NULL);
6033 [ # # ]: 0 : if (!mtr_policy)
6034 : 0 : return rte_flow_error_set(error, EINVAL,
6035 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6036 : : "Invalid policy id for meter ");
6037 [ # # # # ]: 0 : if (!((attr->transfer && mtr_policy->transfer) ||
6038 [ # # # # ]: 0 : (attr->egress && mtr_policy->egress) ||
6039 [ # # # # ]: 0 : (attr->ingress && mtr_policy->ingress)))
6040 : 0 : return rte_flow_error_set(error, EINVAL,
6041 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6042 : : "Flow attributes domain "
6043 : : "have a conflict with current "
6044 : : "meter domain attributes");
6045 [ # # ]: 0 : if (port_id_item) {
6046 [ # # ]: 0 : if (mlx5_flow_get_item_vport_id(dev, port_id_item, &flow_src_port,
6047 : : &all_ports, error))
6048 : 0 : return -rte_errno;
6049 : : }
6050 [ # # ]: 0 : if (attr->transfer) {
6051 : : /* When flow matching all src ports, meter should not have drop count. */
6052 [ # # # # : 0 : if (all_ports && (fm->drop_cnt || mtr_policy->hierarchy_match_port))
# # ]
6053 : 0 : return rte_flow_error_set(error, EINVAL,
6054 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
6055 : : "Meter drop count or "
6056 : : "modify_field/set_tag in meter hierarchy "
6057 : : "not supported when matching all ports.");
6058 [ # # ]: 0 : } else if (mtr_policy->is_rss) {
6059 : : struct mlx5_flow_meter_policy *fp;
6060 : : struct mlx5_meter_policy_action_container *acg;
6061 : : struct mlx5_meter_policy_action_container *acy;
6062 : : const struct rte_flow_action *rss_act;
6063 : : int ret;
6064 : :
6065 : 0 : fp = mlx5_flow_meter_hierarchy_get_final_policy(dev,
6066 : : mtr_policy);
6067 [ # # ]: 0 : if (fp == NULL)
6068 : 0 : return rte_flow_error_set(error, EINVAL,
6069 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6070 : : "Unable to get the final "
6071 : : "policy in the hierarchy");
6072 : : acg = &fp->act_cnt[RTE_COLOR_GREEN];
6073 : : acy = &fp->act_cnt[RTE_COLOR_YELLOW];
6074 : : MLX5_ASSERT(acg->fate_action ==
6075 : : MLX5_FLOW_FATE_SHARED_RSS ||
6076 : : acy->fate_action ==
6077 : : MLX5_FLOW_FATE_SHARED_RSS);
6078 [ # # ]: 0 : if (acg->fate_action == MLX5_FLOW_FATE_SHARED_RSS)
6079 : 0 : rss_act = acg->rss;
6080 : : else
6081 : 0 : rss_act = acy->rss;
6082 : 0 : ret = mlx5_flow_validate_action_rss(rss_act,
6083 : : action_flags, dev, attr,
6084 : : item_flags, error);
6085 [ # # ]: 0 : if (ret)
6086 : : return ret;
6087 : : }
6088 : 0 : *def_policy = false;
6089 : : }
6090 : : return 0;
6091 : : }
6092 : :
6093 : : /**
6094 : : * Validate the age action.
6095 : : *
6096 : : * @param[in] action_flags
6097 : : * Holds the actions detected until now.
6098 : : * @param[in] action
6099 : : * Pointer to the age action.
6100 : : * @param[in] dev
6101 : : * Pointer to the Ethernet device structure.
6102 : : * @param[out] error
6103 : : * Pointer to error structure.
6104 : : *
6105 : : * @return
6106 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
6107 : : */
6108 : : static int
6109 : 0 : flow_dv_validate_action_age(uint64_t action_flags,
6110 : : const struct rte_flow_action *action,
6111 : : struct rte_eth_dev *dev,
6112 : : struct rte_flow_error *error)
6113 : : {
6114 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6115 : 0 : const struct rte_flow_action_age *age = action->conf;
6116 : :
6117 [ # # ]: 0 : if (!priv->sh->cdev->config.devx ||
6118 [ # # # # ]: 0 : (priv->sh->sws_cmng.counter_fallback && !priv->sh->aso_age_mng))
6119 : 0 : return rte_flow_error_set(error, ENOTSUP,
6120 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6121 : : NULL,
6122 : : "age action not supported");
6123 [ # # ]: 0 : if (!(action->conf))
6124 : 0 : return rte_flow_error_set(error, EINVAL,
6125 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6126 : : "configuration cannot be null");
6127 [ # # ]: 0 : if (!(age->timeout))
6128 : 0 : return rte_flow_error_set(error, EINVAL,
6129 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6130 : : "invalid timeout value 0");
6131 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_AGE)
6132 : 0 : return rte_flow_error_set(error, EINVAL,
6133 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6134 : : "duplicate age actions set");
6135 : : return 0;
6136 : : }
6137 : :
6138 : : /**
6139 : : * Validate the modify-header IPv4 DSCP actions.
6140 : : *
6141 : : * @param[in] action_flags
6142 : : * Holds the actions detected until now.
6143 : : * @param[in] action
6144 : : * Pointer to the modify action.
6145 : : * @param[in] item_flags
6146 : : * Holds the items detected.
6147 : : * @param[out] error
6148 : : * Pointer to error structure.
6149 : : *
6150 : : * @return
6151 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
6152 : : */
6153 : : static int
6154 : 0 : flow_dv_validate_action_modify_ipv4_dscp(const uint64_t action_flags,
6155 : : const struct rte_flow_action *action,
6156 : : const uint64_t item_flags,
6157 : : struct rte_flow_error *error)
6158 : : {
6159 : : int ret = 0;
6160 : :
6161 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
6162 [ # # ]: 0 : if (!ret) {
6163 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV4))
6164 : 0 : return rte_flow_error_set(error, EINVAL,
6165 : : RTE_FLOW_ERROR_TYPE_ACTION,
6166 : : NULL,
6167 : : "no ipv4 item in pattern");
6168 : : }
6169 : : return ret;
6170 : : }
6171 : :
6172 : : /**
6173 : : * Validate the modify-header IPv6 DSCP actions.
6174 : : *
6175 : : * @param[in] action_flags
6176 : : * Holds the actions detected until now.
6177 : : * @param[in] action
6178 : : * Pointer to the modify action.
6179 : : * @param[in] item_flags
6180 : : * Holds the items detected.
6181 : : * @param[out] error
6182 : : * Pointer to error structure.
6183 : : *
6184 : : * @return
6185 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
6186 : : */
6187 : : static int
6188 : 0 : flow_dv_validate_action_modify_ipv6_dscp(const uint64_t action_flags,
6189 : : const struct rte_flow_action *action,
6190 : : const uint64_t item_flags,
6191 : : struct rte_flow_error *error)
6192 : : {
6193 : : int ret = 0;
6194 : :
6195 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
6196 [ # # ]: 0 : if (!ret) {
6197 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV6))
6198 : 0 : return rte_flow_error_set(error, EINVAL,
6199 : : RTE_FLOW_ERROR_TYPE_ACTION,
6200 : : NULL,
6201 : : "no ipv6 item in pattern");
6202 : : }
6203 : : return ret;
6204 : : }
6205 : :
6206 : : int
6207 : 0 : mlx5_flow_modify_match_cb(void *tool_ctx __rte_unused,
6208 : : struct mlx5_list_entry *entry, void *cb_ctx)
6209 : : {
6210 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
6211 : 0 : struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
6212 : : struct mlx5_flow_dv_modify_hdr_resource *resource =
6213 : : container_of(entry, typeof(*resource), entry);
6214 : : uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type);
6215 : :
6216 : 0 : key_len += ref->actions_num * sizeof(ref->actions[0]);
6217 [ # # ]: 0 : return ref->actions_num != resource->actions_num ||
6218 [ # # ]: 0 : memcmp(&ref->ft_type, &resource->ft_type, key_len);
6219 : : }
6220 : :
6221 : : static struct mlx5_indexed_pool *
6222 : 0 : flow_dv_modify_ipool_get(struct mlx5_dev_ctx_shared *sh, uint8_t index)
6223 : : {
6224 : 0 : struct mlx5_indexed_pool *ipool = rte_atomic_load_explicit
6225 : : (&sh->mdh_ipools[index], rte_memory_order_seq_cst);
6226 : :
6227 [ # # ]: 0 : if (!ipool) {
6228 : : struct mlx5_indexed_pool *expected = NULL;
6229 : 0 : struct mlx5_indexed_pool_config cfg =
6230 : : (struct mlx5_indexed_pool_config) {
6231 : 0 : .size = sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
6232 : 0 : (index + 1) *
6233 : : sizeof(struct mlx5_modification_cmd),
6234 : : .trunk_size = 64,
6235 : : .grow_trunk = 3,
6236 : : .grow_shift = 2,
6237 : : .need_lock = 1,
6238 : 0 : .release_mem_en = !!sh->config.reclaim_mode,
6239 : : .per_core_cache =
6240 [ # # ]: 0 : sh->config.reclaim_mode ? 0 : (1 << 16),
6241 : : .malloc = mlx5_malloc,
6242 : : .free = mlx5_free,
6243 : : .type = "mlx5_modify_action_resource",
6244 : : };
6245 : :
6246 : 0 : cfg.size = RTE_ALIGN(cfg.size, sizeof(ipool));
6247 : 0 : ipool = mlx5_ipool_create(&cfg);
6248 [ # # ]: 0 : if (!ipool)
6249 : 0 : return NULL;
6250 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(&sh->mdh_ipools[index],
6251 : : &expected, ipool,
6252 : : rte_memory_order_seq_cst,
6253 : : rte_memory_order_seq_cst)) {
6254 : 0 : mlx5_ipool_destroy(ipool);
6255 : 0 : ipool = rte_atomic_load_explicit(&sh->mdh_ipools[index],
6256 : : rte_memory_order_seq_cst);
6257 : : }
6258 : : }
6259 : : return ipool;
6260 : : }
6261 : :
6262 : : struct mlx5_list_entry *
6263 : 0 : mlx5_flow_modify_create_cb(void *tool_ctx, void *cb_ctx)
6264 : : {
6265 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
6266 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
6267 : : struct mlx5dv_dr_domain *ns;
6268 : : struct mlx5_flow_dv_modify_hdr_resource *entry;
6269 : 0 : struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
6270 : 0 : struct mlx5_indexed_pool *ipool = flow_dv_modify_ipool_get(sh,
6271 : 0 : ref->actions_num - 1);
6272 : : int ret = 0;
6273 : 0 : uint32_t data_len = ref->actions_num * sizeof(ref->actions[0]);
6274 : : uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type);
6275 : : uint32_t idx;
6276 : :
6277 [ # # ]: 0 : if (unlikely(!ipool)) {
6278 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
6279 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6280 : : NULL, "cannot allocate modify ipool");
6281 : 0 : return NULL;
6282 : : }
6283 : 0 : entry = mlx5_ipool_zmalloc(ipool, &idx);
6284 [ # # ]: 0 : if (!entry) {
6285 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
6286 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6287 : : "cannot allocate resource memory");
6288 : 0 : return NULL;
6289 : : }
6290 : 0 : rte_memcpy(&entry->ft_type,
6291 : 0 : RTE_PTR_ADD(ref, offsetof(typeof(*ref), ft_type)),
6292 [ # # ]: 0 : key_len + data_len);
6293 [ # # ]: 0 : if (sh->config.dv_flow_en == 2) {
6294 : : #ifdef HAVE_MLX5_HWS_SUPPORT
6295 : 0 : struct mlx5dr_action_mh_pattern pattern = {
6296 : : .sz = data_len,
6297 : 0 : .data = (rte_be64_t *)ref->actions
6298 : : };
6299 : 0 : entry->action = mlx5dr_action_create_modify_header(ctx->data2,
6300 : : 1,
6301 : 0 : &pattern, 0, ref->flags);
6302 [ # # ]: 0 : if (!entry->action)
6303 : : ret = -1;
6304 : : #else
6305 : : ret = -1;
6306 : : #endif
6307 : : } else {
6308 [ # # ]: 0 : if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
6309 : 0 : ns = sh->fdb_domain;
6310 [ # # ]: 0 : else if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
6311 : 0 : ns = sh->tx_domain;
6312 : : else
6313 : 0 : ns = sh->rx_domain;
6314 : 0 : ret = mlx5_flow_os_create_flow_action_modify_header
6315 : 0 : (sh->cdev->ctx, ns, entry,
6316 : : data_len, &entry->action);
6317 : : }
6318 : : if (ret) {
6319 : 0 : mlx5_ipool_free(sh->mdh_ipools[ref->actions_num - 1], idx);
6320 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
6321 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6322 : : NULL, "cannot create modification action");
6323 : 0 : return NULL;
6324 : : }
6325 : 0 : entry->idx = idx;
6326 : 0 : return &entry->entry;
6327 : : }
6328 : :
6329 : : struct mlx5_list_entry *
6330 : 0 : mlx5_flow_modify_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
6331 : : void *cb_ctx)
6332 : : {
6333 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
6334 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
6335 : : struct mlx5_flow_dv_modify_hdr_resource *entry;
6336 : 0 : struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
6337 : 0 : uint32_t data_len = ref->actions_num * sizeof(ref->actions[0]);
6338 : : uint32_t idx;
6339 : :
6340 : 0 : entry = mlx5_ipool_malloc(sh->mdh_ipools[ref->actions_num - 1],
6341 : : &idx);
6342 [ # # ]: 0 : if (!entry) {
6343 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
6344 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6345 : : "cannot allocate resource memory");
6346 : 0 : return NULL;
6347 : : }
6348 : 0 : memcpy(entry, oentry, sizeof(*entry) + data_len);
6349 : 0 : entry->idx = idx;
6350 : 0 : return &entry->entry;
6351 : : }
6352 : :
6353 : : void
6354 : 0 : mlx5_flow_modify_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
6355 : : {
6356 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
6357 : : struct mlx5_flow_dv_modify_hdr_resource *res =
6358 : : container_of(entry, typeof(*res), entry);
6359 : :
6360 : 0 : mlx5_ipool_free(sh->mdh_ipools[res->actions_num - 1], res->idx);
6361 : 0 : }
6362 : :
6363 : : /**
6364 : : * Validate the sample action.
6365 : : *
6366 : : * @param[in, out] action_flags
6367 : : * Holds the actions detected until now.
6368 : : * @param[in] action
6369 : : * Pointer to the sample action.
6370 : : * @param[in] dev
6371 : : * Pointer to the Ethernet device structure.
6372 : : * @param[in] attr
6373 : : * Attributes of flow that includes this action.
6374 : : * @param[in] item_flags
6375 : : * Holds the items detected.
6376 : : * @param[in] rss
6377 : : * Pointer to the RSS action.
6378 : : * @param[out] sample_rss
6379 : : * Pointer to the RSS action in sample action list.
6380 : : * @param[out] count
6381 : : * Pointer to the COUNT action in sample action list.
6382 : : * @param[out] fdb_mirror
6383 : : * Pointer to the FDB mirror flag.
6384 : : * @param root
6385 : : * Whether action is on root table.
6386 : : * @param[out] error
6387 : : * Pointer to error structure.
6388 : : *
6389 : : * @return
6390 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
6391 : : */
6392 : : static int
6393 : 0 : flow_dv_validate_action_sample(uint64_t *action_flags,
6394 : : uint64_t *sub_action_flags,
6395 : : const struct rte_flow_action *action,
6396 : : struct rte_eth_dev *dev,
6397 : : const struct rte_flow_attr *attr,
6398 : : uint64_t item_flags,
6399 : : const struct rte_flow_action_rss *rss,
6400 : : const struct rte_flow_action_rss **sample_rss,
6401 : : const struct rte_flow_action_count **count,
6402 : : int *fdb_mirror,
6403 : : uint16_t *sample_port_id,
6404 : : bool root,
6405 : : struct rte_flow_error *error)
6406 : : {
6407 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6408 : 0 : struct mlx5_sh_config *dev_conf = &priv->sh->config;
6409 : 0 : const struct rte_flow_action_sample *sample = action->conf;
6410 : : const struct rte_flow_action_port_id *port = NULL;
6411 : : const struct rte_flow_action *act;
6412 : : uint16_t queue_index = 0xFFFF;
6413 : 0 : int actions_n = 0;
6414 : : int ret;
6415 : :
6416 [ # # ]: 0 : if (!sample)
6417 : 0 : return rte_flow_error_set(error, EINVAL,
6418 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6419 : : "configuration cannot be NULL");
6420 [ # # ]: 0 : if (sample->ratio == 0)
6421 : 0 : return rte_flow_error_set(error, EINVAL,
6422 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6423 : : "ratio value starts from 1");
6424 [ # # ]: 0 : if (!priv->sh->cdev->config.devx ||
6425 [ # # ]: 0 : (sample->ratio > 0 && !priv->sampler_en))
6426 : 0 : return rte_flow_error_set(error, ENOTSUP,
6427 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6428 : : NULL,
6429 : : "sample action not supported");
6430 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_SAMPLE)
6431 : 0 : return rte_flow_error_set(error, EINVAL,
6432 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6433 : : "Multiple sample actions not "
6434 : : "supported");
6435 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_METER)
6436 : 0 : return rte_flow_error_set(error, EINVAL,
6437 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6438 : : "wrong action order, meter should "
6439 : : "be after sample action");
6440 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_JUMP)
6441 : 0 : return rte_flow_error_set(error, EINVAL,
6442 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6443 : : "wrong action order, jump should "
6444 : : "be after sample action");
6445 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_CT)
6446 : 0 : return rte_flow_error_set(error, EINVAL,
6447 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6448 : : "Sample after CT not supported");
6449 : 0 : act = sample->actions;
6450 [ # # ]: 0 : for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++) {
6451 [ # # ]: 0 : if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
6452 : 0 : return rte_flow_error_set(error, ENOTSUP,
6453 : : RTE_FLOW_ERROR_TYPE_ACTION,
6454 : : act, "too many actions");
6455 [ # # # # : 0 : switch (act->type) {
# # # # ]
6456 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
6457 : 0 : ret = mlx5_flow_validate_action_queue(act,
6458 : : *sub_action_flags,
6459 : : dev,
6460 : : attr, error);
6461 [ # # ]: 0 : if (ret < 0)
6462 : 0 : return ret;
6463 : 0 : queue_index = ((const struct rte_flow_action_queue *)
6464 : 0 : (act->conf))->index;
6465 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_QUEUE;
6466 : 0 : ++actions_n;
6467 : 0 : break;
6468 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
6469 : 0 : *sample_rss = act->conf;
6470 : 0 : ret = mlx5_flow_validate_action_rss(act,
6471 : : *sub_action_flags,
6472 : : dev, attr,
6473 : : item_flags,
6474 : : error);
6475 [ # # ]: 0 : if (ret < 0)
6476 : 0 : return ret;
6477 [ # # # # ]: 0 : if (rss && *sample_rss &&
6478 [ # # ]: 0 : ((*sample_rss)->level != rss->level ||
6479 [ # # ]: 0 : (*sample_rss)->types != rss->types))
6480 : 0 : return rte_flow_error_set(error, ENOTSUP,
6481 : : RTE_FLOW_ERROR_TYPE_ACTION,
6482 : : NULL,
6483 : : "Can't use the different RSS types "
6484 : : "or level in the same flow");
6485 [ # # # # ]: 0 : if (*sample_rss != NULL && (*sample_rss)->queue_num)
6486 : 0 : queue_index = (*sample_rss)->queue[0];
6487 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_RSS;
6488 : 0 : ++actions_n;
6489 : 0 : break;
6490 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
6491 : 0 : ret = flow_dv_validate_action_mark(dev, act,
6492 : : *sub_action_flags,
6493 : : attr, error);
6494 [ # # ]: 0 : if (ret < 0)
6495 : 0 : return ret;
6496 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY)
6497 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_MARK |
6498 : : MLX5_FLOW_ACTION_MARK_EXT;
6499 : : else
6500 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_MARK;
6501 : 0 : ++actions_n;
6502 : 0 : break;
6503 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
6504 : 0 : ret = flow_dv_validate_action_count
6505 : 0 : (dev, false, *action_flags | *sub_action_flags,
6506 : : root, error);
6507 [ # # ]: 0 : if (ret < 0)
6508 : 0 : return ret;
6509 : 0 : *count = act->conf;
6510 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_COUNT;
6511 : 0 : *action_flags |= MLX5_FLOW_ACTION_COUNT;
6512 : 0 : ++actions_n;
6513 : 0 : break;
6514 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
6515 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
6516 : 0 : ret = flow_dv_validate_action_port_id(dev,
6517 : : *sub_action_flags,
6518 : : act,
6519 : : attr,
6520 : : error);
6521 [ # # ]: 0 : if (ret)
6522 : 0 : return ret;
6523 [ # # ]: 0 : if (act->type == RTE_FLOW_ACTION_TYPE_PORT_ID) {
6524 : 0 : port = (const struct rte_flow_action_port_id *)
6525 : : act->conf;
6526 [ # # ]: 0 : *sample_port_id = port->original ?
6527 : 0 : dev->data->port_id : port->id;
6528 : : } else {
6529 : 0 : *sample_port_id = ((const struct rte_flow_action_ethdev *)
6530 : 0 : act->conf)->port_id;
6531 : : }
6532 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_PORT_ID;
6533 : 0 : ++actions_n;
6534 : 0 : break;
6535 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
6536 : 0 : ret = mlx5_flow_dv_validate_action_raw_encap_decap
6537 : 0 : (dev, NULL, act->conf, attr, sub_action_flags,
6538 : : &actions_n, action, item_flags, error);
6539 [ # # ]: 0 : if (ret < 0)
6540 : 0 : return ret;
6541 : 0 : ++actions_n;
6542 : 0 : break;
6543 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
6544 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
6545 : 0 : ret = mlx5_flow_dv_validate_action_l2_encap(dev,
6546 : : *sub_action_flags,
6547 : : act, attr,
6548 : : error);
6549 [ # # ]: 0 : if (ret < 0)
6550 : 0 : return ret;
6551 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_ENCAP;
6552 : 0 : ++actions_n;
6553 : 0 : break;
6554 : 0 : default:
6555 : 0 : return rte_flow_error_set(error, ENOTSUP,
6556 : : RTE_FLOW_ERROR_TYPE_ACTION,
6557 : : NULL,
6558 : : "Doesn't support optional "
6559 : : "action");
6560 : : }
6561 : : }
6562 [ # # ]: 0 : if (attr->ingress) {
6563 [ # # ]: 0 : if (!(*sub_action_flags & (MLX5_FLOW_ACTION_QUEUE |
6564 : : MLX5_FLOW_ACTION_RSS)))
6565 : 0 : return rte_flow_error_set(error, EINVAL,
6566 : : RTE_FLOW_ERROR_TYPE_ACTION,
6567 : : NULL,
6568 : : "Ingress must has a dest "
6569 : : "QUEUE for Sample");
6570 [ # # ]: 0 : } else if (attr->egress) {
6571 : 0 : return rte_flow_error_set(error, ENOTSUP,
6572 : : RTE_FLOW_ERROR_TYPE_ACTION,
6573 : : NULL,
6574 : : "Sample Only support Ingress "
6575 : : "or E-Switch");
6576 [ # # ]: 0 : } else if (sample->actions->type != RTE_FLOW_ACTION_TYPE_END) {
6577 : : MLX5_ASSERT(attr->transfer);
6578 [ # # ]: 0 : if (sample->ratio > 1)
6579 : 0 : return rte_flow_error_set(error, ENOTSUP,
6580 : : RTE_FLOW_ERROR_TYPE_ACTION,
6581 : : NULL,
6582 : : "E-Switch doesn't support "
6583 : : "any optional action "
6584 : : "for sampling");
6585 [ # # ]: 0 : if (*sub_action_flags & MLX5_FLOW_ACTION_QUEUE)
6586 : 0 : return rte_flow_error_set(error, ENOTSUP,
6587 : : RTE_FLOW_ERROR_TYPE_ACTION,
6588 : : NULL,
6589 : : "unsupported action QUEUE");
6590 [ # # ]: 0 : if (*sub_action_flags & MLX5_FLOW_ACTION_RSS)
6591 : 0 : return rte_flow_error_set(error, ENOTSUP,
6592 : : RTE_FLOW_ERROR_TYPE_ACTION,
6593 : : NULL,
6594 : : "unsupported action QUEUE");
6595 [ # # ]: 0 : if (!(*sub_action_flags & MLX5_FLOW_ACTION_PORT_ID))
6596 : 0 : return rte_flow_error_set(error, EINVAL,
6597 : : RTE_FLOW_ERROR_TYPE_ACTION,
6598 : : NULL,
6599 : : "E-Switch must has a dest "
6600 : : "port for mirroring");
6601 : 0 : *fdb_mirror = 1;
6602 : : }
6603 : : /* Continue validation for Xcap actions.*/
6604 [ # # # # ]: 0 : if ((*sub_action_flags & MLX5_FLOW_XCAP_ACTIONS) &&
6605 [ # # ]: 0 : (queue_index == 0xFFFF || !mlx5_rxq_is_hairpin(dev, queue_index))) {
6606 [ # # ]: 0 : if ((*sub_action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
6607 : : MLX5_FLOW_XCAP_ACTIONS)
6608 : 0 : return rte_flow_error_set(error, ENOTSUP,
6609 : : RTE_FLOW_ERROR_TYPE_ACTION,
6610 : : NULL, "encap and decap "
6611 : : "combination aren't "
6612 : : "supported");
6613 [ # # # # ]: 0 : if (attr->ingress && (*sub_action_flags & MLX5_FLOW_ACTION_ENCAP))
6614 : 0 : return rte_flow_error_set(error, ENOTSUP,
6615 : : RTE_FLOW_ERROR_TYPE_ACTION,
6616 : : NULL, "encap is not supported"
6617 : : " for ingress traffic");
6618 : : }
6619 : : return 0;
6620 : : }
6621 : :
6622 : : int
6623 : 0 : mlx5_flow_modify_hdr_resource_register(struct rte_eth_dev *dev,
6624 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
6625 : : struct mlx5_flow_dv_modify_hdr_resource **modify,
6626 : : struct rte_flow_error *error)
6627 : : {
6628 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6629 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
6630 : 0 : uint32_t key_len = sizeof(*resource) -
6631 : : offsetof(typeof(*resource), ft_type) +
6632 : 0 : resource->actions_num * sizeof(resource->actions[0]);
6633 : : struct mlx5_list_entry *entry;
6634 : 0 : struct mlx5_flow_cb_ctx ctx = {
6635 : : .error = error,
6636 : : .data = resource,
6637 : 0 : .data2 = priv->dr_ctx,
6638 : : };
6639 : : struct mlx5_hlist *modify_cmds;
6640 : : uint64_t key64;
6641 : :
6642 : 0 : modify_cmds = flow_dv_hlist_prepare(sh, &sh->modify_cmds,
6643 : : "hdr_modify",
6644 : : MLX5_FLOW_HDR_MODIFY_HTABLE_SZ,
6645 : : true, false, sh,
6646 : : mlx5_flow_modify_create_cb,
6647 : : mlx5_flow_modify_match_cb,
6648 : : mlx5_flow_modify_remove_cb,
6649 : : mlx5_flow_modify_clone_cb,
6650 : : mlx5_flow_modify_clone_free_cb,
6651 : : error);
6652 [ # # ]: 0 : if (unlikely(!modify_cmds))
6653 : 0 : return -rte_errno;
6654 [ # # ]: 0 : if (resource->actions_num > flow_dv_modify_hdr_action_max(dev,
6655 [ # # ]: 0 : resource->root))
6656 : 0 : return rte_flow_error_set(error, EOVERFLOW,
6657 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6658 : : "too many modify header items");
6659 : 0 : key64 = __rte_raw_cksum(&resource->ft_type, key_len, 0);
6660 : 0 : entry = mlx5_hlist_register(modify_cmds, key64, &ctx);
6661 [ # # ]: 0 : if (!entry)
6662 : 0 : return -rte_errno;
6663 : 0 : *modify = container_of(entry, typeof(*resource), entry);
6664 : 0 : return 0;
6665 : : }
6666 : :
6667 : : /**
6668 : : * Find existing modify-header resource or create and register a new one.
6669 : : *
6670 : : * @param dev[in, out]
6671 : : * Pointer to rte_eth_dev structure.
6672 : : * @param[in, out] resource
6673 : : * Pointer to modify-header resource.
6674 : : * @param[in, out] dev_flow
6675 : : * Pointer to the dev_flow.
6676 : : * @param[out] error
6677 : : * pointer to error structure.
6678 : : *
6679 : : * @return
6680 : : * 0 on success otherwise -errno and errno is set.
6681 : : */
6682 : : static int
6683 : : flow_dv_modify_hdr_resource_register
6684 : : (struct rte_eth_dev *dev,
6685 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
6686 : : struct mlx5_flow *dev_flow,
6687 : : struct rte_flow_error *error)
6688 : : {
6689 : 0 : resource->root = !dev_flow->dv.group;
6690 : 0 : return mlx5_flow_modify_hdr_resource_register(dev, resource,
6691 : 0 : &dev_flow->handle->dvh.modify_hdr, error);
6692 : : }
6693 : :
6694 : : /**
6695 : : * Get DV flow counter by index.
6696 : : *
6697 : : * @param[in] dev
6698 : : * Pointer to the Ethernet device structure.
6699 : : * @param[in] idx
6700 : : * mlx5 flow counter index in the container.
6701 : : * @param[out] ppool
6702 : : * mlx5 flow counter pool in the container.
6703 : : *
6704 : : * @return
6705 : : * Pointer to the counter, NULL otherwise.
6706 : : */
6707 : : static struct mlx5_flow_counter *
6708 : : flow_dv_counter_get_by_idx(struct rte_eth_dev *dev,
6709 : : uint32_t idx,
6710 : : struct mlx5_flow_counter_pool **ppool)
6711 : : {
6712 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6713 : 0 : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
6714 : : struct mlx5_flow_counter_pool *pool;
6715 : :
6716 : : /* Decrease to original index and clear shared bit. */
6717 : 0 : idx = (idx - 1) & (MLX5_CNT_SHARED_OFFSET - 1);
6718 : : MLX5_ASSERT(idx / MLX5_COUNTERS_PER_POOL < MLX5_COUNTER_POOLS_MAX_NUM);
6719 : 0 : pool = cmng->pools[idx / MLX5_COUNTERS_PER_POOL];
6720 : : MLX5_ASSERT(pool);
6721 : : if (ppool)
6722 : : *ppool = pool;
6723 [ # # # # : 0 : return MLX5_POOL_GET_CNT(pool, idx % MLX5_COUNTERS_PER_POOL);
# # # # #
# # # ]
6724 : : }
6725 : :
6726 : : /**
6727 : : * Check the devx counter belongs to the pool.
6728 : : *
6729 : : * @param[in] pool
6730 : : * Pointer to the counter pool.
6731 : : * @param[in] id
6732 : : * The counter devx ID.
6733 : : *
6734 : : * @return
6735 : : * True if counter belongs to the pool, false otherwise.
6736 : : */
6737 : : static bool
6738 : : flow_dv_is_counter_in_pool(struct mlx5_flow_counter_pool *pool, int id)
6739 : : {
6740 : 0 : int base = (pool->min_dcs->id / MLX5_COUNTERS_PER_POOL) *
6741 : : MLX5_COUNTERS_PER_POOL;
6742 : :
6743 [ # # # # ]: 0 : if (id >= base && id < base + MLX5_COUNTERS_PER_POOL)
6744 : : return true;
6745 : : return false;
6746 : : }
6747 : :
6748 : : /**
6749 : : * Get a pool by devx counter ID.
6750 : : *
6751 : : * @param[in] cmng
6752 : : * Pointer to the counter management.
6753 : : * @param[in] id
6754 : : * The counter devx ID.
6755 : : *
6756 : : * @return
6757 : : * The counter pool pointer if exists, NULL otherwise,
6758 : : */
6759 : : static struct mlx5_flow_counter_pool *
6760 : 0 : flow_dv_find_pool_by_id(struct mlx5_flow_counter_mng *cmng, int id)
6761 : : {
6762 : : uint32_t i;
6763 : : struct mlx5_flow_counter_pool *pool = NULL;
6764 : :
6765 : 0 : rte_spinlock_lock(&cmng->pool_update_sl);
6766 : : /* Check last used pool. */
6767 [ # # ]: 0 : if (cmng->last_pool_idx != POOL_IDX_INVALID &&
6768 [ # # ]: 0 : flow_dv_is_counter_in_pool(cmng->pools[cmng->last_pool_idx], id)) {
6769 : : pool = cmng->pools[cmng->last_pool_idx];
6770 : 0 : goto out;
6771 : : }
6772 : : /* ID out of range means no suitable pool in the container. */
6773 [ # # # # ]: 0 : if (id > cmng->max_id || id < cmng->min_id)
6774 : 0 : goto out;
6775 : : /*
6776 : : * Find the pool from the end of the container, since mostly counter
6777 : : * ID is sequence increasing, and the last pool should be the needed
6778 : : * one.
6779 : : */
6780 : 0 : i = cmng->n_valid;
6781 [ # # ]: 0 : while (i--) {
6782 [ # # ]: 0 : struct mlx5_flow_counter_pool *pool_tmp = cmng->pools[i];
6783 : :
6784 : : if (flow_dv_is_counter_in_pool(pool_tmp, id)) {
6785 : : pool = pool_tmp;
6786 : : break;
6787 : : }
6788 : : }
6789 : 0 : out:
6790 : : rte_spinlock_unlock(&cmng->pool_update_sl);
6791 : 0 : return pool;
6792 : : }
6793 : :
6794 : : /**
6795 : : * Query a devx flow counter.
6796 : : *
6797 : : * @param[in] dev
6798 : : * Pointer to the Ethernet device structure.
6799 : : * @param[in] counter
6800 : : * Index to the flow counter.
6801 : : * @param[out] pkts
6802 : : * The statistics value of packets.
6803 : : * @param[out] bytes
6804 : : * The statistics value of bytes.
6805 : : *
6806 : : * @return
6807 : : * 0 on success, otherwise a negative errno value and rte_errno is set.
6808 : : */
6809 : : static inline int
6810 : 0 : _flow_dv_query_count(struct rte_eth_dev *dev, uint32_t counter, uint64_t *pkts,
6811 : : uint64_t *bytes)
6812 : : {
6813 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
6814 : : struct mlx5_flow_counter_pool *pool = NULL;
6815 : : struct mlx5_flow_counter *cnt;
6816 : : int offset;
6817 : :
6818 : : cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
6819 : : MLX5_ASSERT(pool);
6820 [ # # ]: 0 : if (priv->sh->sws_cmng.counter_fallback)
6821 : 0 : return mlx5_devx_cmd_flow_counter_query(cnt->dcs_when_active, 0,
6822 : : 0, pkts, bytes, 0, NULL, NULL, 0);
6823 : 0 : rte_spinlock_lock(&pool->sl);
6824 [ # # ]: 0 : if (!pool->raw) {
6825 : 0 : *pkts = 0;
6826 : 0 : *bytes = 0;
6827 : : } else {
6828 [ # # ]: 0 : offset = MLX5_CNT_ARRAY_IDX(pool, cnt);
6829 : 0 : *pkts = rte_be_to_cpu_64(pool->raw->data[offset].hits);
6830 : 0 : *bytes = rte_be_to_cpu_64(pool->raw->data[offset].bytes);
6831 : : }
6832 : : rte_spinlock_unlock(&pool->sl);
6833 : 0 : return 0;
6834 : : }
6835 : :
6836 : : /**
6837 : : * Create and initialize a new counter pool.
6838 : : *
6839 : : * @param[in] dev
6840 : : * Pointer to the Ethernet device structure.
6841 : : * @param[out] dcs
6842 : : * The devX counter handle.
6843 : : * @param[in] age
6844 : : * Whether the pool is for counter that was allocated for aging.
6845 : : *
6846 : : * @return
6847 : : * The pool container pointer on success, NULL otherwise and rte_errno is set.
6848 : : */
6849 : : static struct mlx5_flow_counter_pool *
6850 : 0 : flow_dv_pool_create(struct rte_eth_dev *dev, struct mlx5_devx_obj *dcs,
6851 : : uint32_t age)
6852 : : {
6853 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6854 : : struct mlx5_flow_counter_pool *pool;
6855 : 0 : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
6856 : 0 : bool fallback = cmng->counter_fallback;
6857 : : uint32_t size = sizeof(*pool);
6858 : :
6859 [ # # ]: 0 : if (cmng->n_valid == MLX5_COUNTER_POOLS_MAX_NUM) {
6860 : 0 : DRV_LOG(ERR, "All counter is in used, try again later.");
6861 : 0 : rte_errno = EAGAIN;
6862 : 0 : return NULL;
6863 : : }
6864 : : size += MLX5_COUNTERS_PER_POOL * MLX5_CNT_SIZE;
6865 [ # # ]: 0 : size += (!age ? 0 : MLX5_COUNTERS_PER_POOL * MLX5_AGE_SIZE);
6866 : 0 : pool = mlx5_malloc(MLX5_MEM_ZERO, size, 0, SOCKET_ID_ANY);
6867 [ # # ]: 0 : if (!pool) {
6868 : 0 : rte_errno = ENOMEM;
6869 : 0 : return NULL;
6870 : : }
6871 : 0 : pool->raw = NULL;
6872 : 0 : pool->is_aged = !!age;
6873 : 0 : pool->query_gen = 0;
6874 : 0 : pool->min_dcs = dcs;
6875 : : rte_spinlock_init(&pool->sl);
6876 : : rte_spinlock_init(&pool->csl);
6877 : 0 : TAILQ_INIT(&pool->counters[0]);
6878 : 0 : TAILQ_INIT(&pool->counters[1]);
6879 : 0 : pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
6880 : 0 : rte_spinlock_lock(&cmng->pool_update_sl);
6881 : 0 : pool->index = cmng->n_valid;
6882 : 0 : cmng->pools[pool->index] = pool;
6883 : 0 : cmng->n_valid++;
6884 [ # # ]: 0 : if (unlikely(fallback)) {
6885 : 0 : int base = RTE_ALIGN_FLOOR(dcs->id, MLX5_COUNTERS_PER_POOL);
6886 : :
6887 [ # # ]: 0 : if (base < cmng->min_id)
6888 : 0 : cmng->min_id = base;
6889 [ # # ]: 0 : if (base > cmng->max_id)
6890 : 0 : cmng->max_id = base + MLX5_COUNTERS_PER_POOL - 1;
6891 : 0 : cmng->last_pool_idx = pool->index;
6892 : : }
6893 : : rte_spinlock_unlock(&cmng->pool_update_sl);
6894 : 0 : return pool;
6895 : : }
6896 : :
6897 : : /**
6898 : : * Prepare a new counter and/or a new counter pool.
6899 : : *
6900 : : * @param[in] dev
6901 : : * Pointer to the Ethernet device structure.
6902 : : * @param[out] cnt_free
6903 : : * Where to put the pointer of a new counter.
6904 : : * @param[in] age
6905 : : * Whether the pool is for counter that was allocated for aging.
6906 : : *
6907 : : * @return
6908 : : * The counter pool pointer and @p cnt_free is set on success,
6909 : : * NULL otherwise and rte_errno is set.
6910 : : */
6911 : : static struct mlx5_flow_counter_pool *
6912 : 0 : flow_dv_counter_pool_prepare(struct rte_eth_dev *dev,
6913 : : struct mlx5_flow_counter **cnt_free,
6914 : : uint32_t age)
6915 : : {
6916 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6917 : 0 : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
6918 : : struct mlx5_flow_counter_pool *pool;
6919 : : struct mlx5_counters tmp_tq;
6920 : : struct mlx5_devx_obj *dcs = NULL;
6921 : : struct mlx5_flow_counter *cnt;
6922 : 0 : enum mlx5_counter_type cnt_type =
6923 : 0 : age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
6924 : 0 : bool fallback = priv->sh->sws_cmng.counter_fallback;
6925 : : uint32_t i;
6926 : :
6927 [ # # ]: 0 : if (fallback) {
6928 : : /* bulk_bitmap must be 0 for single counter allocation. */
6929 : 0 : dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0);
6930 [ # # ]: 0 : if (!dcs)
6931 : : return NULL;
6932 : 0 : pool = flow_dv_find_pool_by_id(cmng, dcs->id);
6933 [ # # ]: 0 : if (!pool) {
6934 : 0 : pool = flow_dv_pool_create(dev, dcs, age);
6935 [ # # ]: 0 : if (!pool) {
6936 : 0 : mlx5_devx_cmd_destroy(dcs);
6937 : 0 : return NULL;
6938 : : }
6939 : : }
6940 : 0 : i = dcs->id % MLX5_COUNTERS_PER_POOL;
6941 [ # # ]: 0 : cnt = MLX5_POOL_GET_CNT(pool, i);
6942 : 0 : cnt->pool = pool;
6943 : 0 : cnt->dcs_when_free = dcs;
6944 : 0 : *cnt_free = cnt;
6945 : 0 : return pool;
6946 : : }
6947 : 0 : dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0x4);
6948 [ # # ]: 0 : if (!dcs) {
6949 : 0 : rte_errno = ENODATA;
6950 : 0 : return NULL;
6951 : : }
6952 : 0 : pool = flow_dv_pool_create(dev, dcs, age);
6953 [ # # ]: 0 : if (!pool) {
6954 : 0 : mlx5_devx_cmd_destroy(dcs);
6955 : 0 : return NULL;
6956 : : }
6957 : 0 : TAILQ_INIT(&tmp_tq);
6958 [ # # ]: 0 : for (i = 1; i < MLX5_COUNTERS_PER_POOL; ++i) {
6959 [ # # ]: 0 : cnt = MLX5_POOL_GET_CNT(pool, i);
6960 : 0 : cnt->pool = pool;
6961 [ # # ]: 0 : TAILQ_INSERT_HEAD(&tmp_tq, cnt, next);
6962 : : }
6963 : 0 : rte_spinlock_lock(&cmng->csl[cnt_type]);
6964 [ # # ]: 0 : TAILQ_CONCAT(&cmng->counters[cnt_type], &tmp_tq, next);
6965 : : rte_spinlock_unlock(&cmng->csl[cnt_type]);
6966 : 0 : *cnt_free = MLX5_POOL_GET_CNT(pool, 0);
6967 : 0 : (*cnt_free)->pool = pool;
6968 : 0 : return pool;
6969 : : }
6970 : :
6971 : : /**
6972 : : * Allocate a flow counter.
6973 : : *
6974 : : * @param[in] dev
6975 : : * Pointer to the Ethernet device structure.
6976 : : * @param[in] age
6977 : : * Whether the counter was allocated for aging.
6978 : : *
6979 : : * @return
6980 : : * Index to flow counter on success, 0 otherwise and rte_errno is set.
6981 : : */
6982 : : static uint32_t
6983 : 0 : flow_dv_counter_alloc(struct rte_eth_dev *dev, uint32_t age)
6984 : : {
6985 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6986 : : struct mlx5_flow_counter_pool *pool = NULL;
6987 : 0 : struct mlx5_flow_counter *cnt_free = NULL;
6988 : 0 : bool fallback = priv->sh->sws_cmng.counter_fallback;
6989 : : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
6990 : 0 : enum mlx5_counter_type cnt_type =
6991 : 0 : age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
6992 : : uint32_t cnt_idx;
6993 : :
6994 [ # # ]: 0 : if (!priv->sh->cdev->config.devx) {
6995 : 0 : rte_errno = ENOTSUP;
6996 : 0 : return 0;
6997 : : }
6998 : : /* Get free counters from container. */
6999 : 0 : rte_spinlock_lock(&cmng->csl[cnt_type]);
7000 : 0 : cnt_free = TAILQ_FIRST(&cmng->counters[cnt_type]);
7001 [ # # ]: 0 : if (cnt_free)
7002 [ # # ]: 0 : TAILQ_REMOVE(&cmng->counters[cnt_type], cnt_free, next);
7003 : : rte_spinlock_unlock(&cmng->csl[cnt_type]);
7004 [ # # # # ]: 0 : if (!cnt_free && !flow_dv_counter_pool_prepare(dev, &cnt_free, age))
7005 : 0 : goto err;
7006 : 0 : pool = cnt_free->pool;
7007 [ # # ]: 0 : if (fallback)
7008 : 0 : cnt_free->dcs_when_active = cnt_free->dcs_when_free;
7009 : : /* Create a DV counter action only in the first time usage. */
7010 [ # # ]: 0 : if (!cnt_free->action) {
7011 : : uint16_t offset;
7012 : : struct mlx5_devx_obj *dcs;
7013 : : int ret;
7014 : :
7015 [ # # ]: 0 : if (!fallback) {
7016 [ # # ]: 0 : offset = MLX5_CNT_ARRAY_IDX(pool, cnt_free);
7017 : 0 : dcs = pool->min_dcs;
7018 : : } else {
7019 : : offset = 0;
7020 : 0 : dcs = cnt_free->dcs_when_free;
7021 : : }
7022 : 0 : ret = mlx5_flow_os_create_flow_action_count(dcs->obj, offset,
7023 : : &cnt_free->action);
7024 : : if (ret) {
7025 : 0 : rte_errno = errno;
7026 : 0 : goto err;
7027 : : }
7028 : : }
7029 [ # # ]: 0 : cnt_idx = MLX5_MAKE_CNT_IDX(pool->index,
7030 : : MLX5_CNT_ARRAY_IDX(pool, cnt_free));
7031 : : /* Update the counter reset values. */
7032 [ # # ]: 0 : if (_flow_dv_query_count(dev, cnt_idx, &cnt_free->hits,
7033 : : &cnt_free->bytes))
7034 : 0 : goto err;
7035 [ # # # # ]: 0 : if (!fallback && !priv->sh->sws_cmng.query_thread_on)
7036 : : /* Start the asynchronous batch query by the host thread. */
7037 : 0 : mlx5_set_query_alarm(priv->sh);
7038 : : /*
7039 : : * When the count action isn't shared (by ID), shared_info field is
7040 : : * used for indirect action API's refcnt.
7041 : : * When the counter action is not shared neither by ID nor by indirect
7042 : : * action API, shared info must be 1.
7043 : : */
7044 : 0 : cnt_free->shared_info.refcnt = 1;
7045 : 0 : return cnt_idx;
7046 : 0 : err:
7047 [ # # ]: 0 : if (cnt_free) {
7048 : 0 : cnt_free->pool = pool;
7049 [ # # ]: 0 : if (fallback)
7050 : 0 : cnt_free->dcs_when_free = cnt_free->dcs_when_active;
7051 : : rte_spinlock_lock(&cmng->csl[cnt_type]);
7052 : 0 : TAILQ_INSERT_TAIL(&cmng->counters[cnt_type], cnt_free, next);
7053 : : rte_spinlock_unlock(&cmng->csl[cnt_type]);
7054 : : }
7055 : : return 0;
7056 : : }
7057 : :
7058 : : /**
7059 : : * Get age param from counter index.
7060 : : *
7061 : : * @param[in] dev
7062 : : * Pointer to the Ethernet device structure.
7063 : : * @param[in] counter
7064 : : * Index to the counter handler.
7065 : : *
7066 : : * @return
7067 : : * The aging parameter specified for the counter index.
7068 : : */
7069 : : static struct mlx5_age_param*
7070 : : flow_dv_counter_idx_get_age(struct rte_eth_dev *dev,
7071 : : uint32_t counter)
7072 : : {
7073 : : struct mlx5_flow_counter *cnt;
7074 : : struct mlx5_flow_counter_pool *pool = NULL;
7075 : :
7076 : : flow_dv_counter_get_by_idx(dev, counter, &pool);
7077 : : counter = (counter - 1) % MLX5_COUNTERS_PER_POOL;
7078 : : cnt = MLX5_POOL_GET_CNT(pool, counter);
7079 : 0 : return MLX5_CNT_TO_AGE(cnt);
7080 : : }
7081 : :
7082 : : /**
7083 : : * Remove a flow counter from aged counter list.
7084 : : *
7085 : : * @param[in] dev
7086 : : * Pointer to the Ethernet device structure.
7087 : : * @param[in] counter
7088 : : * Index to the counter handler.
7089 : : * @param[in] cnt
7090 : : * Pointer to the counter handler.
7091 : : */
7092 : : static void
7093 : 0 : flow_dv_counter_remove_from_age(struct rte_eth_dev *dev,
7094 : : uint32_t counter, struct mlx5_flow_counter *cnt)
7095 : : {
7096 : : struct mlx5_age_info *age_info;
7097 : : struct mlx5_age_param *age_param;
7098 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7099 : : uint16_t expected = AGE_CANDIDATE;
7100 : :
7101 [ # # ]: 0 : age_info = GET_PORT_AGE_INFO(priv);
7102 : : age_param = flow_dv_counter_idx_get_age(dev, counter);
7103 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(&age_param->state, &expected,
7104 : : AGE_FREE, rte_memory_order_relaxed,
7105 : : rte_memory_order_relaxed)) {
7106 : : /**
7107 : : * We need the lock even it is age timeout,
7108 : : * since counter may still in process.
7109 : : */
7110 : 0 : rte_spinlock_lock(&age_info->aged_sl);
7111 [ # # ]: 0 : TAILQ_REMOVE(&age_info->aged_counters, cnt, next);
7112 : : rte_spinlock_unlock(&age_info->aged_sl);
7113 : 0 : rte_atomic_store_explicit(&age_param->state, AGE_FREE, rte_memory_order_relaxed);
7114 : : }
7115 : 0 : }
7116 : :
7117 : : /**
7118 : : * Release a flow counter.
7119 : : *
7120 : : * @param[in] dev
7121 : : * Pointer to the Ethernet device structure.
7122 : : * @param[in] counter
7123 : : * Index to the counter handler.
7124 : : */
7125 : : static void
7126 : 0 : flow_dv_counter_free(struct rte_eth_dev *dev, uint32_t counter)
7127 : : {
7128 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7129 : : struct mlx5_flow_counter_pool *pool = NULL;
7130 : : struct mlx5_flow_counter *cnt;
7131 : : enum mlx5_counter_type cnt_type;
7132 : :
7133 [ # # ]: 0 : if (!counter)
7134 : : return;
7135 : : cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
7136 : : MLX5_ASSERT(pool);
7137 [ # # ]: 0 : if (pool->is_aged) {
7138 : 0 : flow_dv_counter_remove_from_age(dev, counter, cnt);
7139 : : } else {
7140 : : /*
7141 : : * If the counter action is shared by indirect action API,
7142 : : * the atomic function reduces its references counter.
7143 : : * If after the reduction the action is still referenced, the
7144 : : * function returns here and does not release it.
7145 : : * When the counter action is not shared by
7146 : : * indirect action API, shared info is 1 before the reduction,
7147 : : * so this condition is failed and function doesn't return here.
7148 : : */
7149 [ # # ]: 0 : if (rte_atomic_fetch_sub_explicit(&cnt->shared_info.refcnt, 1,
7150 : : rte_memory_order_relaxed) - 1)
7151 : : return;
7152 : : }
7153 : 0 : cnt->pool = pool;
7154 : : /*
7155 : : * Put the counter back to list to be updated in none fallback mode.
7156 : : * Currently, we are using two list alternately, while one is in query,
7157 : : * add the freed counter to the other list based on the pool query_gen
7158 : : * value. After query finishes, add counter the list to the global
7159 : : * container counter list. The list changes while query starts. In
7160 : : * this case, lock will not be needed as query callback and release
7161 : : * function both operate with the different list.
7162 : : */
7163 [ # # ]: 0 : if (!priv->sh->sws_cmng.counter_fallback) {
7164 : 0 : rte_spinlock_lock(&pool->csl);
7165 : 0 : TAILQ_INSERT_TAIL(&pool->counters[pool->query_gen], cnt, next);
7166 : : rte_spinlock_unlock(&pool->csl);
7167 : : } else {
7168 : 0 : cnt->dcs_when_free = cnt->dcs_when_active;
7169 : 0 : cnt_type = pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
7170 : : MLX5_COUNTER_TYPE_ORIGIN;
7171 : 0 : rte_spinlock_lock(&priv->sh->sws_cmng.csl[cnt_type]);
7172 : 0 : TAILQ_INSERT_TAIL(&priv->sh->sws_cmng.counters[cnt_type],
7173 : : cnt, next);
7174 : 0 : rte_spinlock_unlock(&priv->sh->sws_cmng.csl[cnt_type]);
7175 : : }
7176 : : }
7177 : :
7178 : : /**
7179 : : * Resize a meter id container.
7180 : : *
7181 : : * @param[in] dev
7182 : : * Pointer to the Ethernet device structure.
7183 : : *
7184 : : * @return
7185 : : * 0 on success, otherwise negative errno value and rte_errno is set.
7186 : : */
7187 : : static int
7188 : 0 : flow_dv_mtr_container_resize(struct rte_eth_dev *dev)
7189 : : {
7190 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7191 : : struct mlx5_aso_mtr_pools_mng *pools_mng =
7192 : 0 : &priv->sh->mtrmng->pools_mng;
7193 : 0 : void *old_pools = pools_mng->pools;
7194 : 0 : uint32_t resize = pools_mng->n + MLX5_MTRS_CONTAINER_RESIZE;
7195 : 0 : uint32_t mem_size = sizeof(struct mlx5_aso_mtr_pool *) * resize;
7196 : 0 : void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
7197 : :
7198 [ # # ]: 0 : if (!pools) {
7199 : 0 : rte_errno = ENOMEM;
7200 : 0 : return -ENOMEM;
7201 : : }
7202 [ # # ]: 0 : if (!pools_mng->n)
7203 [ # # ]: 0 : if (mlx5_aso_queue_init(priv->sh, ASO_OPC_MOD_POLICER, 1)) {
7204 : 0 : mlx5_free(pools);
7205 : 0 : return -ENOMEM;
7206 : : }
7207 [ # # ]: 0 : if (old_pools)
7208 : 0 : memcpy(pools, old_pools, pools_mng->n *
7209 : : sizeof(struct mlx5_aso_mtr_pool *));
7210 : 0 : pools_mng->n = resize;
7211 : 0 : pools_mng->pools = pools;
7212 [ # # ]: 0 : if (old_pools)
7213 : 0 : mlx5_free(old_pools);
7214 : : return 0;
7215 : : }
7216 : :
7217 : : /**
7218 : : * Prepare a new meter and/or a new meter pool.
7219 : : *
7220 : : * @param[in] dev
7221 : : * Pointer to the Ethernet device structure.
7222 : : * @param[out] mtr_free
7223 : : * Where to put the pointer of a new meter.g.
7224 : : *
7225 : : * @return
7226 : : * The meter pool pointer and @mtr_free is set on success,
7227 : : * NULL otherwise and rte_errno is set.
7228 : : */
7229 : : static struct mlx5_aso_mtr_pool *
7230 : 0 : flow_dv_mtr_pool_create(struct rte_eth_dev *dev, struct mlx5_aso_mtr **mtr_free)
7231 : : {
7232 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7233 : 0 : struct mlx5_aso_mtr_pools_mng *pools_mng = &priv->sh->mtrmng->pools_mng;
7234 : : struct mlx5_aso_mtr_pool *pool = NULL;
7235 : : struct mlx5_devx_obj *dcs = NULL;
7236 : : uint32_t i;
7237 : : uint32_t log_obj_size;
7238 : :
7239 : : log_obj_size = rte_log2_u32(MLX5_ASO_MTRS_PER_POOL >> 1);
7240 : 0 : dcs = mlx5_devx_cmd_create_flow_meter_aso_obj(priv->sh->cdev->ctx,
7241 : 0 : priv->sh->cdev->pdn,
7242 : : log_obj_size);
7243 [ # # ]: 0 : if (!dcs) {
7244 : 0 : rte_errno = ENODATA;
7245 : 0 : return NULL;
7246 : : }
7247 : 0 : pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
7248 [ # # ]: 0 : if (!pool) {
7249 : 0 : rte_errno = ENOMEM;
7250 : 0 : claim_zero(mlx5_devx_cmd_destroy(dcs));
7251 : 0 : return NULL;
7252 : : }
7253 : 0 : pool->devx_obj = dcs;
7254 : 0 : rte_rwlock_write_lock(&pools_mng->resize_mtrwl);
7255 : 0 : pool->index = pools_mng->n_valid;
7256 [ # # # # ]: 0 : if (pool->index == pools_mng->n && flow_dv_mtr_container_resize(dev)) {
7257 : 0 : mlx5_free(pool);
7258 : 0 : claim_zero(mlx5_devx_cmd_destroy(dcs));
7259 : : rte_rwlock_write_unlock(&pools_mng->resize_mtrwl);
7260 : 0 : return NULL;
7261 : : }
7262 : 0 : pools_mng->pools[pool->index] = pool;
7263 : 0 : pools_mng->n_valid++;
7264 : : rte_rwlock_write_unlock(&pools_mng->resize_mtrwl);
7265 [ # # ]: 0 : for (i = 1; i < MLX5_ASO_MTRS_PER_POOL; ++i) {
7266 : 0 : pool->mtrs[i].offset = i;
7267 [ # # ]: 0 : LIST_INSERT_HEAD(&pools_mng->meters, &pool->mtrs[i], next);
7268 : : }
7269 : 0 : pool->mtrs[0].offset = 0;
7270 : 0 : *mtr_free = &pool->mtrs[0];
7271 : 0 : return pool;
7272 : : }
7273 : :
7274 : : /**
7275 : : * Release a flow meter into pool.
7276 : : *
7277 : : * @param[in] dev
7278 : : * Pointer to the Ethernet device structure.
7279 : : * @param[in] mtr_idx
7280 : : * Index to aso flow meter.
7281 : : */
7282 : : static void
7283 : 0 : flow_dv_aso_mtr_release_to_pool(struct rte_eth_dev *dev, uint32_t mtr_idx)
7284 : : {
7285 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7286 : : struct mlx5_aso_mtr_pools_mng *pools_mng =
7287 : 0 : &priv->sh->mtrmng->pools_mng;
7288 : 0 : struct mlx5_aso_mtr *aso_mtr = mlx5_aso_meter_by_idx(priv, mtr_idx);
7289 : : void *meter_action_g;
7290 : : void *meter_action_y;
7291 : :
7292 : : MLX5_ASSERT(aso_mtr);
7293 : 0 : rte_spinlock_lock(&pools_mng->mtrsl);
7294 : 0 : meter_action_g = aso_mtr->fm.meter_action_g;
7295 : 0 : meter_action_y = aso_mtr->fm.meter_action_y;
7296 [ # # ]: 0 : memset(&aso_mtr->fm, 0, sizeof(struct mlx5_flow_meter_info));
7297 : 0 : aso_mtr->fm.meter_action_g = meter_action_g;
7298 : 0 : aso_mtr->fm.meter_action_y = meter_action_y;
7299 : 0 : aso_mtr->state = ASO_METER_FREE;
7300 [ # # ]: 0 : LIST_INSERT_HEAD(&pools_mng->meters, aso_mtr, next);
7301 : : rte_spinlock_unlock(&pools_mng->mtrsl);
7302 : 0 : }
7303 : :
7304 : : /**
7305 : : * Allocate a aso flow meter.
7306 : : *
7307 : : * @param[in] dev
7308 : : * Pointer to the Ethernet device structure.
7309 : : *
7310 : : * @return
7311 : : * Index to aso flow meter on success, 0 otherwise and rte_errno is set.
7312 : : */
7313 : : static uint32_t
7314 : 0 : flow_dv_mtr_alloc(struct rte_eth_dev *dev)
7315 : : {
7316 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7317 : 0 : struct mlx5_aso_mtr *mtr_free = NULL;
7318 : : struct mlx5_aso_mtr_pools_mng *pools_mng =
7319 : 0 : &priv->sh->mtrmng->pools_mng;
7320 : : struct mlx5_aso_mtr_pool *pool;
7321 : : uint32_t mtr_idx = 0;
7322 : :
7323 [ # # ]: 0 : if (!priv->sh->cdev->config.devx) {
7324 : 0 : rte_errno = ENOTSUP;
7325 : 0 : return 0;
7326 : : }
7327 : : /* Allocate the flow meter memory. */
7328 : : /* Get free meters from management. */
7329 : 0 : rte_spinlock_lock(&pools_mng->mtrsl);
7330 : 0 : mtr_free = LIST_FIRST(&pools_mng->meters);
7331 [ # # ]: 0 : if (mtr_free)
7332 [ # # ]: 0 : LIST_REMOVE(mtr_free, next);
7333 [ # # # # ]: 0 : if (!mtr_free && !flow_dv_mtr_pool_create(dev, &mtr_free)) {
7334 : : rte_spinlock_unlock(&pools_mng->mtrsl);
7335 : 0 : return 0;
7336 : : }
7337 : 0 : mtr_free->state = ASO_METER_WAIT;
7338 : : rte_spinlock_unlock(&pools_mng->mtrsl);
7339 : 0 : pool = container_of(mtr_free,
7340 : : struct mlx5_aso_mtr_pool,
7341 : : mtrs[mtr_free->offset]);
7342 : 0 : mtr_idx = MLX5_MAKE_MTR_IDX(pool->index, mtr_free->offset);
7343 [ # # ]: 0 : if (!mtr_free->fm.meter_action_g) {
7344 : : #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
7345 : : struct rte_flow_error error;
7346 : : uint8_t reg_id;
7347 : :
7348 : 0 : reg_id = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &error);
7349 : 0 : mtr_free->fm.meter_action_g =
7350 : 0 : mlx5_glue->dv_create_flow_action_aso
7351 : 0 : (priv->sh->rx_domain,
7352 : 0 : pool->devx_obj->obj,
7353 : : mtr_free->offset,
7354 : : (1 << MLX5_FLOW_COLOR_GREEN),
7355 : 0 : reg_id - REG_C_0);
7356 : : #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
7357 [ # # ]: 0 : if (!mtr_free->fm.meter_action_g) {
7358 : 0 : flow_dv_aso_mtr_release_to_pool(dev, mtr_idx);
7359 : 0 : return 0;
7360 : : }
7361 : : }
7362 : : return mtr_idx;
7363 : : }
7364 : :
7365 : : /**
7366 : : * Verify the @p attributes will be correctly understood by the NIC and store
7367 : : * them in the @p flow if everything is correct.
7368 : : *
7369 : : * @param[in] dev
7370 : : * Pointer to dev struct.
7371 : : * @param[in] attributes
7372 : : * Pointer to flow attributes
7373 : : * @param[in] external
7374 : : * This flow rule is created by request external to PMD.
7375 : : * @param[out] error
7376 : : * Pointer to error structure.
7377 : : *
7378 : : * @return
7379 : : * - 0 on success and non root table.
7380 : : * - 1 on success and root table.
7381 : : * - a negative errno value otherwise and rte_errno is set.
7382 : : */
7383 : : static int
7384 : 0 : flow_dv_validate_attributes(struct rte_eth_dev *dev,
7385 : : const struct mlx5_flow_tunnel *tunnel,
7386 : : const struct rte_flow_attr *attributes,
7387 : : const struct flow_grp_info *grp_info,
7388 : : struct rte_flow_error *error)
7389 : : {
7390 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7391 : 0 : uint32_t lowest_priority = mlx5_get_lowest_priority(dev, attributes);
7392 : : int ret = 0;
7393 : :
7394 : : #ifndef HAVE_MLX5DV_DR
7395 : : RTE_SET_USED(tunnel);
7396 : : RTE_SET_USED(grp_info);
7397 : : if (attributes->group)
7398 : : return rte_flow_error_set(error, ENOTSUP,
7399 : : RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
7400 : : NULL,
7401 : : "groups are not supported");
7402 : : #else
7403 : 0 : uint32_t table = 0;
7404 : :
7405 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel, attributes->group, &table,
7406 : : grp_info, error);
7407 [ # # ]: 0 : if (ret)
7408 : : return ret;
7409 [ # # ]: 0 : if (!table)
7410 : : ret = MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL;
7411 : : #endif
7412 [ # # # # ]: 0 : if (attributes->priority != MLX5_FLOW_LOWEST_PRIO_INDICATOR &&
7413 : : attributes->priority > lowest_priority)
7414 : 0 : return rte_flow_error_set(error, ENOTSUP,
7415 : : RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
7416 : : NULL,
7417 : : "priority out of range");
7418 [ # # # # ]: 0 : if (attributes->transfer && !priv->sh->config.dv_esw_en)
7419 : 0 : return rte_flow_error_set(error, ENOTSUP,
7420 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7421 : : "E-Switch dr is not supported");
7422 [ # # ]: 0 : if (attributes->ingress + attributes->egress + attributes->transfer != 1) {
7423 : 0 : return rte_flow_error_set(error, EINVAL,
7424 : : RTE_FLOW_ERROR_TYPE_ATTR, NULL,
7425 : : "must specify exactly one of "
7426 : : "ingress, egress or transfer");
7427 : : }
7428 : : return ret;
7429 : : }
7430 : :
7431 : : static int
7432 : 0 : validate_integrity_bits(const void *arg,
7433 : : int64_t pattern_flags, uint64_t l3_flags,
7434 : : uint64_t l4_flags, uint64_t ip4_flag,
7435 : : struct rte_flow_error *error)
7436 : : {
7437 : : const struct rte_flow_item_integrity *mask = arg;
7438 : :
7439 [ # # # # ]: 0 : if (mask->l3_ok && !(pattern_flags & l3_flags))
7440 : 0 : return rte_flow_error_set(error, EINVAL,
7441 : : RTE_FLOW_ERROR_TYPE_ITEM,
7442 : : NULL, "missing L3 protocol");
7443 : :
7444 [ # # # # ]: 0 : if (mask->ipv4_csum_ok && !(pattern_flags & ip4_flag))
7445 : 0 : return rte_flow_error_set(error, EINVAL,
7446 : : RTE_FLOW_ERROR_TYPE_ITEM,
7447 : : NULL, "missing IPv4 protocol");
7448 : :
7449 [ # # # # ]: 0 : if ((mask->l4_ok || mask->l4_csum_ok) && !(pattern_flags & l4_flags))
7450 : 0 : return rte_flow_error_set(error, EINVAL,
7451 : : RTE_FLOW_ERROR_TYPE_ITEM,
7452 : : NULL, "missing L4 protocol");
7453 : :
7454 : : return 0;
7455 : : }
7456 : :
7457 : : static int
7458 : 0 : flow_dv_validate_item_integrity_post(const struct
7459 : : rte_flow_item *integrity_items[2],
7460 : : int64_t pattern_flags,
7461 : : struct rte_flow_error *error)
7462 : : {
7463 : : const struct rte_flow_item_integrity *mask;
7464 : : int ret;
7465 : :
7466 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_OUTER_INTEGRITY) {
7467 : 0 : mask = (typeof(mask))integrity_items[0]->mask;
7468 : 0 : ret = validate_integrity_bits(mask, pattern_flags,
7469 : : MLX5_FLOW_LAYER_OUTER_L3,
7470 : : MLX5_FLOW_LAYER_OUTER_L4,
7471 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4,
7472 : : error);
7473 [ # # ]: 0 : if (ret)
7474 : : return ret;
7475 : : }
7476 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_INNER_INTEGRITY) {
7477 : 0 : mask = (typeof(mask))integrity_items[1]->mask;
7478 : 0 : ret = validate_integrity_bits(mask, pattern_flags,
7479 : : MLX5_FLOW_LAYER_INNER_L3,
7480 : : MLX5_FLOW_LAYER_INNER_L4,
7481 : : MLX5_FLOW_LAYER_INNER_L3_IPV4,
7482 : : error);
7483 [ # # ]: 0 : if (ret)
7484 : 0 : return ret;
7485 : : }
7486 : : return 0;
7487 : : }
7488 : :
7489 : : static int
7490 : 0 : flow_dv_validate_item_integrity(struct rte_eth_dev *dev,
7491 : : const struct rte_flow_item *integrity_item,
7492 : : uint64_t pattern_flags, uint64_t *last_item,
7493 : : const struct rte_flow_item *integrity_items[2],
7494 : : struct rte_flow_error *error)
7495 : : {
7496 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7497 : 0 : const struct rte_flow_item_integrity *mask = (typeof(mask))
7498 : : integrity_item->mask;
7499 : 0 : const struct rte_flow_item_integrity *spec = (typeof(spec))
7500 : : integrity_item->spec;
7501 : :
7502 [ # # ]: 0 : if (!priv->sh->cdev->config.hca_attr.pkt_integrity_match)
7503 : 0 : return rte_flow_error_set(error, ENOTSUP,
7504 : : RTE_FLOW_ERROR_TYPE_ITEM,
7505 : : integrity_item,
7506 : : "packet integrity integrity_item not supported");
7507 [ # # ]: 0 : if (!spec)
7508 : 0 : return rte_flow_error_set(error, ENOTSUP,
7509 : : RTE_FLOW_ERROR_TYPE_ITEM,
7510 : : integrity_item,
7511 : : "no spec for integrity item");
7512 [ # # ]: 0 : if (!mask)
7513 : : mask = &rte_flow_item_integrity_mask;
7514 [ # # ]: 0 : if (!mlx5_validate_integrity_item(mask))
7515 : 0 : return rte_flow_error_set(error, ENOTSUP,
7516 : : RTE_FLOW_ERROR_TYPE_ITEM,
7517 : : integrity_item,
7518 : : "unsupported integrity filter");
7519 [ # # # # ]: 0 : if ((mask->l3_ok & !spec->l3_ok) || (mask->l4_ok & !spec->l4_ok) ||
7520 [ # # ]: 0 : (mask->ipv4_csum_ok & !spec->ipv4_csum_ok) ||
7521 [ # # ]: 0 : (mask->l4_csum_ok & !spec->l4_csum_ok))
7522 : 0 : return rte_flow_error_set(error, EINVAL,
7523 : : RTE_FLOW_ERROR_TYPE_ITEM,
7524 : : NULL, "negative integrity flow is not supported");
7525 [ # # ]: 0 : if (spec->level > 1) {
7526 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_INNER_INTEGRITY)
7527 : 0 : return rte_flow_error_set
7528 : : (error, ENOTSUP,
7529 : : RTE_FLOW_ERROR_TYPE_ITEM,
7530 : : NULL, "multiple inner integrity items not supported");
7531 : 0 : integrity_items[1] = integrity_item;
7532 : 0 : *last_item |= MLX5_FLOW_ITEM_INNER_INTEGRITY;
7533 : : } else {
7534 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_OUTER_INTEGRITY)
7535 : 0 : return rte_flow_error_set
7536 : : (error, ENOTSUP,
7537 : : RTE_FLOW_ERROR_TYPE_ITEM,
7538 : : NULL, "multiple outer integrity items not supported");
7539 : 0 : integrity_items[0] = integrity_item;
7540 : 0 : *last_item |= MLX5_FLOW_ITEM_OUTER_INTEGRITY;
7541 : : }
7542 : : return 0;
7543 : : }
7544 : :
7545 : : static int
7546 : 0 : flow_dv_validate_item_flex(struct rte_eth_dev *dev,
7547 : : const struct rte_flow_item *item,
7548 : : uint64_t item_flags,
7549 : : uint64_t *last_item,
7550 : : bool is_inner,
7551 : : struct rte_flow_error *error)
7552 : : {
7553 : 0 : const struct rte_flow_item_flex *flow_spec = item->spec;
7554 : 0 : const struct rte_flow_item_flex *flow_mask = item->mask;
7555 : : struct mlx5_flex_item *flex;
7556 : :
7557 [ # # ]: 0 : if (!flow_spec)
7558 : 0 : return rte_flow_error_set(error, EINVAL,
7559 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
7560 : : "flex flow item spec cannot be NULL");
7561 [ # # ]: 0 : if (!flow_mask)
7562 : 0 : return rte_flow_error_set(error, EINVAL,
7563 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
7564 : : "flex flow item mask cannot be NULL");
7565 [ # # ]: 0 : if (item->last)
7566 : 0 : return rte_flow_error_set(error, ENOTSUP,
7567 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
7568 : : "flex flow item last not supported");
7569 [ # # ]: 0 : if (mlx5_flex_acquire_index(dev, flow_spec->handle, false) < 0)
7570 : 0 : return rte_flow_error_set(error, EINVAL,
7571 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
7572 : : "invalid flex flow item handle");
7573 : 0 : flex = (struct mlx5_flex_item *)flow_spec->handle;
7574 [ # # # # : 0 : switch (flex->tunnel_mode) {
# # ]
7575 : 0 : case FLEX_TUNNEL_MODE_SINGLE:
7576 [ # # ]: 0 : if (item_flags &
7577 : : (MLX5_FLOW_ITEM_OUTER_FLEX | MLX5_FLOW_ITEM_INNER_FLEX))
7578 : 0 : rte_flow_error_set(error, EINVAL,
7579 : : RTE_FLOW_ERROR_TYPE_ITEM,
7580 : : NULL, "multiple flex items not supported");
7581 : : break;
7582 : 0 : case FLEX_TUNNEL_MODE_OUTER:
7583 [ # # ]: 0 : if (is_inner)
7584 : 0 : rte_flow_error_set(error, EINVAL,
7585 : : RTE_FLOW_ERROR_TYPE_ITEM,
7586 : : NULL, "inner flex item was not configured");
7587 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_OUTER_FLEX)
7588 : 0 : rte_flow_error_set(error, ENOTSUP,
7589 : : RTE_FLOW_ERROR_TYPE_ITEM,
7590 : : NULL, "multiple flex items not supported");
7591 : : break;
7592 : 0 : case FLEX_TUNNEL_MODE_INNER:
7593 [ # # ]: 0 : if (!is_inner)
7594 : 0 : rte_flow_error_set(error, EINVAL,
7595 : : RTE_FLOW_ERROR_TYPE_ITEM,
7596 : : NULL, "outer flex item was not configured");
7597 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_INNER_FLEX)
7598 : 0 : rte_flow_error_set(error, EINVAL,
7599 : : RTE_FLOW_ERROR_TYPE_ITEM,
7600 : : NULL, "multiple flex items not supported");
7601 : : break;
7602 : 0 : case FLEX_TUNNEL_MODE_MULTI:
7603 [ # # # # : 0 : if ((is_inner && (item_flags & MLX5_FLOW_ITEM_INNER_FLEX)) ||
# # ]
7604 [ # # ]: 0 : (!is_inner && (item_flags & MLX5_FLOW_ITEM_OUTER_FLEX))) {
7605 : 0 : rte_flow_error_set(error, EINVAL,
7606 : : RTE_FLOW_ERROR_TYPE_ITEM,
7607 : : NULL, "multiple flex items not supported");
7608 : : }
7609 : : break;
7610 : 0 : case FLEX_TUNNEL_MODE_TUNNEL:
7611 [ # # # # ]: 0 : if (is_inner || (item_flags & MLX5_FLOW_ITEM_FLEX_TUNNEL))
7612 : 0 : rte_flow_error_set(error, EINVAL,
7613 : : RTE_FLOW_ERROR_TYPE_ITEM,
7614 : : NULL, "multiple flex tunnel items not supported");
7615 : : break;
7616 : 0 : default:
7617 : 0 : rte_flow_error_set(error, EINVAL,
7618 : : RTE_FLOW_ERROR_TYPE_ITEM,
7619 : : NULL, "invalid flex item configuration");
7620 : : }
7621 : 0 : *last_item = flex->tunnel_mode == FLEX_TUNNEL_MODE_TUNNEL ?
7622 [ # # ]: 0 : MLX5_FLOW_ITEM_FLEX_TUNNEL : is_inner ?
7623 [ # # ]: 0 : MLX5_FLOW_ITEM_INNER_FLEX : MLX5_FLOW_ITEM_OUTER_FLEX;
7624 : 0 : return 0;
7625 : : }
7626 : :
7627 : : static __rte_always_inline uint8_t
7628 : : mlx5_flow_l3_next_protocol(const struct rte_flow_item *l3_item,
7629 : : enum MLX5_SET_MATCHER key_type)
7630 : : {
7631 : : #define MLX5_L3_NEXT_PROTOCOL(i, ms) \
7632 : : ((i)->type == RTE_FLOW_ITEM_TYPE_IPV4 ? \
7633 : : ((const struct rte_flow_item_ipv4 *)(i)->ms)->hdr.next_proto_id : \
7634 : : (i)->type == RTE_FLOW_ITEM_TYPE_IPV6 ? \
7635 : : ((const struct rte_flow_item_ipv6 *)(i)->ms)->hdr.proto : \
7636 : : (i)->type == RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT ? \
7637 : : ((const struct rte_flow_item_ipv6_frag_ext *)(i)->ms)->hdr.next_header :\
7638 : : 0xff)
7639 : :
7640 : : uint8_t next_protocol;
7641 : :
7642 [ # # # # : 0 : if (l3_item->mask != NULL && l3_item->spec != NULL) {
# # # # #
# # # # #
# # # # #
# # # ]
7643 [ # # # # : 0 : next_protocol = MLX5_L3_NEXT_PROTOCOL(l3_item, mask);
# # # # #
# # # ]
7644 [ # # # # : 0 : if (next_protocol)
# # # # #
# # # ]
7645 [ # # # # : 0 : next_protocol &= MLX5_L3_NEXT_PROTOCOL(l3_item, spec);
# # # # #
# # # ]
7646 : : else
7647 : : next_protocol = 0xff;
7648 [ # # # # : 0 : } else if (key_type == MLX5_SET_MATCHER_HS_M && l3_item->mask != NULL) {
# # # # #
# # # ]
7649 [ # # # # : 0 : next_protocol = MLX5_L3_NEXT_PROTOCOL(l3_item, mask);
# # ]
7650 [ # # # # : 0 : } else if (key_type == MLX5_SET_MATCHER_HS_V && l3_item->spec != NULL) {
# # # # #
# # # ]
7651 [ # # # # : 0 : next_protocol = MLX5_L3_NEXT_PROTOCOL(l3_item, spec);
# # ]
7652 : : } else {
7653 : : /* Reset for inner layer. */
7654 : : next_protocol = 0xff;
7655 : : }
7656 : : return next_protocol;
7657 : :
7658 : : #undef MLX5_L3_NEXT_PROTOCOL
7659 : : }
7660 : :
7661 : : /**
7662 : : * Validate IB BTH item.
7663 : : *
7664 : : * @param[in] dev
7665 : : * Pointer to the rte_eth_dev structure.
7666 : : * @param[in] udp_dport
7667 : : * UDP destination port
7668 : : * @param[in] item
7669 : : * Item specification.
7670 : : * @param root
7671 : : * Whether action is on root table.
7672 : : * @param[out] error
7673 : : * Pointer to the error structure.
7674 : : *
7675 : : * @return
7676 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
7677 : : */
7678 : : static int
7679 : 0 : mlx5_flow_validate_item_ib_bth(struct rte_eth_dev *dev,
7680 : : uint16_t udp_dport,
7681 : : const struct rte_flow_item *item,
7682 : : bool root,
7683 : : struct rte_flow_error *error)
7684 : : {
7685 : 0 : const struct rte_flow_item_ib_bth *mask = item->mask;
7686 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7687 : : const struct rte_flow_item_ib_bth *valid_mask;
7688 : : int ret;
7689 : :
7690 : : valid_mask = &rte_flow_item_ib_bth_mask;
7691 [ # # ]: 0 : if (udp_dport && udp_dport != MLX5_UDP_PORT_ROCEv2)
7692 : 0 : return rte_flow_error_set(error, EINVAL,
7693 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
7694 : : "protocol filtering not compatible"
7695 : : " with UDP layer");
7696 [ # # # # ]: 0 : if (mask && (mask->hdr.se || mask->hdr.m || mask->hdr.padcnt ||
7697 [ # # # # ]: 0 : mask->hdr.tver || mask->hdr.pkey || mask->hdr.f || mask->hdr.b ||
7698 [ # # ]: 0 : mask->hdr.rsvd0 || mask->hdr.a || mask->hdr.rsvd1 ||
7699 [ # # # # : 0 : mask->hdr.psn[0] || mask->hdr.psn[1] || mask->hdr.psn[2]))
# # ]
7700 : 0 : return rte_flow_error_set(error, EINVAL,
7701 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
7702 : : "only opcode and dst_qp are supported");
7703 [ # # # # ]: 0 : if (root || priv->sh->steering_format_version ==
7704 : : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5)
7705 : 0 : return rte_flow_error_set(error, EINVAL,
7706 : : RTE_FLOW_ERROR_TYPE_ITEM,
7707 : : item,
7708 : : "IB BTH item is not supported");
7709 [ # # ]: 0 : if (!mask)
7710 : : mask = &rte_flow_item_ib_bth_mask;
7711 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
7712 : : (const uint8_t *)valid_mask,
7713 : : sizeof(struct rte_flow_item_ib_bth),
7714 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
7715 : : if (ret < 0)
7716 : : return ret;
7717 : : return 0;
7718 : : }
7719 : :
7720 : : const struct rte_flow_item_ipv4 nic_ipv4_mask = {
7721 : : .hdr = {
7722 : : .src_addr = RTE_BE32(0xffffffff),
7723 : : .dst_addr = RTE_BE32(0xffffffff),
7724 : : .type_of_service = 0xff,
7725 : : .fragment_offset = RTE_BE16(0xffff),
7726 : : .next_proto_id = 0xff,
7727 : : .time_to_live = 0xff,
7728 : : },
7729 : : };
7730 : :
7731 : : const struct rte_flow_item_ipv6 nic_ipv6_mask = {
7732 : : .hdr = {
7733 : : .src_addr = RTE_IPV6_MASK_FULL,
7734 : : .dst_addr = RTE_IPV6_MASK_FULL,
7735 : : .vtc_flow = RTE_BE32(0xffffffff),
7736 : : .proto = 0xff,
7737 : : .hop_limits = 0xff,
7738 : : },
7739 : : .has_frag_ext = 1,
7740 : : };
7741 : :
7742 : : const struct rte_flow_item_tcp nic_tcp_mask = {
7743 : : .hdr = {
7744 : : .tcp_flags = 0xFF,
7745 : : .src_port = RTE_BE16(UINT16_MAX),
7746 : : .dst_port = RTE_BE16(UINT16_MAX),
7747 : : }
7748 : : };
7749 : :
7750 : : /**
7751 : : * Internal validation function. For validating both actions and items.
7752 : : *
7753 : : * @param[in] dev
7754 : : * Pointer to the rte_eth_dev structure.
7755 : : * @param[in] attr
7756 : : * Pointer to the flow attributes.
7757 : : * @param[in] items
7758 : : * Pointer to the list of items.
7759 : : * @param[in] actions
7760 : : * Pointer to the list of actions.
7761 : : * @param[in] external
7762 : : * This flow rule is created by request external to PMD.
7763 : : * @param[in] hairpin
7764 : : * Number of hairpin TX actions, 0 means classic flow.
7765 : : * @param[out] error
7766 : : * Pointer to the error structure.
7767 : : *
7768 : : * @return
7769 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
7770 : : */
7771 : : int
7772 : 0 : mlx5_flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
7773 : : const struct rte_flow_item items[],
7774 : : const struct rte_flow_action actions[],
7775 : : bool external, int hairpin, struct rte_flow_error *error)
7776 : : {
7777 : : int ret;
7778 : 0 : uint64_t aso_mask, action_flags = 0;
7779 : 0 : uint64_t item_flags = 0;
7780 : 0 : uint64_t last_item = 0;
7781 : : uint8_t next_protocol = 0xff;
7782 : : uint16_t ether_type = 0;
7783 : 0 : int actions_n = 0;
7784 : : uint8_t item_ipv6_proto = 0;
7785 : 0 : int fdb_mirror = 0;
7786 : : int modify_after_mirror = 0;
7787 : : const struct rte_flow_item *geneve_item = NULL;
7788 : : const struct rte_flow_item *gre_item = NULL;
7789 : : const struct rte_flow_item *gtp_item = NULL;
7790 : : const struct rte_flow_action_raw_decap *decap;
7791 : : const struct rte_flow_action_raw_encap *encap;
7792 : : const struct rte_flow_action_rss *rss = NULL;
7793 : 0 : const struct rte_flow_action_rss *sample_rss = NULL;
7794 : 0 : const struct rte_flow_action_count *sample_count = NULL;
7795 : 0 : const struct rte_flow_item_ecpri nic_ecpri_mask = {
7796 : : .hdr = {
7797 : : .common = {
7798 : : .u32 =
7799 : : RTE_BE32(((const struct rte_ecpri_common_hdr) {
7800 : : .type = 0xFF,
7801 : : }).u32),
7802 : : },
7803 : : .dummy[0] = 0xffffffff,
7804 : : },
7805 : : };
7806 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7807 : 0 : struct mlx5_sh_config *dev_conf = &priv->sh->config;
7808 : : uint16_t queue_index = 0xFFFF;
7809 : : const struct rte_flow_item_vlan *vlan_m = NULL;
7810 : : uint32_t rw_act_num = 0;
7811 : : uint64_t is_root;
7812 : : const struct mlx5_flow_tunnel *tunnel;
7813 : : enum mlx5_tof_rule_type tof_rule_type;
7814 : 0 : struct flow_grp_info grp_info = {
7815 : : .external = !!external,
7816 : 0 : .transfer = !!attr->transfer,
7817 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
7818 : : .std_tbl_fix = true,
7819 : : };
7820 : : const struct rte_eth_hairpin_conf *conf;
7821 : 0 : const struct rte_flow_item *integrity_items[2] = {NULL, NULL};
7822 : : const struct rte_flow_item *port_id_item = NULL;
7823 : 0 : bool def_policy = false;
7824 : : bool shared_count = false;
7825 : : uint16_t udp_dport = 0;
7826 : 0 : uint32_t tag_id = 0, tag_bitmap = 0;
7827 : : const struct rte_flow_action_age *non_shared_age = NULL;
7828 : : const struct rte_flow_action_count *count = NULL;
7829 : : const struct rte_flow_action_port_id *port = NULL;
7830 : : const struct mlx5_rte_flow_item_tag *mlx5_tag;
7831 : 0 : struct mlx5_priv *act_priv = NULL;
7832 : : int aso_after_sample = 0;
7833 : : struct mlx5_priv *port_priv = NULL;
7834 : 0 : uint64_t sub_action_flags = 0;
7835 : 0 : uint16_t sample_port_id = 0;
7836 : : uint16_t port_id = 0;
7837 : :
7838 [ # # ]: 0 : if (items == NULL)
7839 : : return -1;
7840 : : tunnel = is_tunnel_offload_active(dev) ?
7841 [ # # ]: 0 : mlx5_get_tof(items, actions, &tof_rule_type) : NULL;
7842 [ # # ]: 0 : if (tunnel) {
7843 [ # # ]: 0 : if (!dev_conf->dv_flow_en)
7844 : 0 : return rte_flow_error_set
7845 : : (error, ENOTSUP,
7846 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7847 : : NULL, "tunnel offload requires DV flow interface");
7848 [ # # ]: 0 : if (priv->representor)
7849 : 0 : return rte_flow_error_set
7850 : : (error, ENOTSUP,
7851 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7852 : : NULL, "decap not supported for VF representor");
7853 [ # # ]: 0 : if (tof_rule_type == MLX5_TUNNEL_OFFLOAD_SET_RULE)
7854 : 0 : action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
7855 [ # # ]: 0 : else if (tof_rule_type == MLX5_TUNNEL_OFFLOAD_MATCH_RULE)
7856 : 0 : action_flags |= MLX5_FLOW_ACTION_TUNNEL_MATCH |
7857 : : MLX5_FLOW_ACTION_DECAP;
7858 : 0 : grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
7859 : : (dev, attr, tunnel, tof_rule_type);
7860 : : }
7861 : 0 : ret = flow_dv_validate_attributes(dev, tunnel, attr, &grp_info, error);
7862 [ # # ]: 0 : if (ret < 0)
7863 : : return ret;
7864 : 0 : is_root = (uint64_t)ret;
7865 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
7866 : : enum mlx5_l3_tunnel_detection l3_tunnel_detection;
7867 : : uint64_t l3_tunnel_flag;
7868 : 0 : int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
7869 : 0 : int type = items->type;
7870 : :
7871 : : if (!mlx5_flow_os_item_supported(type))
7872 : : return rte_flow_error_set(error, ENOTSUP,
7873 : : RTE_FLOW_ERROR_TYPE_ITEM,
7874 : : NULL, "item not supported");
7875 [ # # # # : 0 : switch (type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # #
# ]
7876 : : case RTE_FLOW_ITEM_TYPE_VOID:
7877 : : break;
7878 : 0 : case RTE_FLOW_ITEM_TYPE_ESP:
7879 : 0 : ret = mlx5_flow_os_validate_item_esp(dev, items, item_flags,
7880 : : next_protocol, false, error);
7881 [ # # ]: 0 : if (ret < 0)
7882 : 0 : return ret;
7883 : 0 : last_item = MLX5_FLOW_ITEM_ESP;
7884 : 0 : break;
7885 : 0 : case RTE_FLOW_ITEM_TYPE_PORT_ID:
7886 : 0 : ret = flow_dv_validate_item_port_id
7887 : : (dev, items, attr, item_flags, &act_priv, error);
7888 [ # # ]: 0 : if (ret < 0)
7889 : 0 : return ret;
7890 : 0 : last_item = MLX5_FLOW_ITEM_PORT_ID;
7891 : : port_id_item = items;
7892 : 0 : break;
7893 : 0 : case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
7894 : : case RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR:
7895 : 0 : ret = flow_dv_validate_item_represented_port
7896 : : (dev, items, attr, item_flags, &act_priv, error);
7897 [ # # ]: 0 : if (ret < 0)
7898 : 0 : return ret;
7899 : 0 : last_item = MLX5_FLOW_ITEM_REPRESENTED_PORT;
7900 : : port_id_item = items;
7901 : 0 : break;
7902 : 0 : case RTE_FLOW_ITEM_TYPE_ETH:
7903 : 0 : ret = mlx5_flow_validate_item_eth(dev, items, item_flags,
7904 : : true, error);
7905 [ # # ]: 0 : if (ret < 0)
7906 : 0 : return ret;
7907 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
7908 : : MLX5_FLOW_LAYER_OUTER_L2;
7909 [ # # # # ]: 0 : if (items->mask != NULL && items->spec != NULL) {
7910 : 0 : ether_type =
7911 : : ((const struct rte_flow_item_eth *)
7912 : : items->spec)->hdr.ether_type;
7913 : 0 : ether_type &=
7914 : : ((const struct rte_flow_item_eth *)
7915 : 0 : items->mask)->hdr.ether_type;
7916 [ # # ]: 0 : ether_type = rte_be_to_cpu_16(ether_type);
7917 : : } else {
7918 : : ether_type = 0;
7919 : : }
7920 : : break;
7921 : 0 : case RTE_FLOW_ITEM_TYPE_VLAN:
7922 : 0 : ret = mlx5_flow_dv_validate_item_vlan(items, item_flags,
7923 : : dev, error);
7924 [ # # ]: 0 : if (ret < 0)
7925 : 0 : return ret;
7926 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
7927 : : MLX5_FLOW_LAYER_OUTER_VLAN;
7928 [ # # # # ]: 0 : if (items->mask != NULL && items->spec != NULL) {
7929 : 0 : ether_type =
7930 : : ((const struct rte_flow_item_vlan *)
7931 : : items->spec)->hdr.eth_proto;
7932 : 0 : ether_type &=
7933 : : ((const struct rte_flow_item_vlan *)
7934 : 0 : items->mask)->hdr.eth_proto;
7935 [ # # ]: 0 : ether_type = rte_be_to_cpu_16(ether_type);
7936 : : } else {
7937 : : ether_type = 0;
7938 : : }
7939 : : /* Store outer VLAN mask for of_push_vlan action. */
7940 [ # # ]: 0 : if (!tunnel)
7941 : : vlan_m = items->mask;
7942 : : break;
7943 : : case RTE_FLOW_ITEM_TYPE_IPV4:
7944 : : next_protocol = mlx5_flow_l3_next_protocol
7945 : : (items, (enum MLX5_SET_MATCHER)-1);
7946 : : l3_tunnel_detection =
7947 : : mlx5_flow_tunnel_ip_check(items, next_protocol,
7948 : : item_flags,
7949 : : &l3_tunnel_flag);
7950 : : /*
7951 : : * explicitly allow inner IPIP match
7952 : : */
7953 : : if (l3_tunnel_detection == l3_tunnel_outer) {
7954 : 0 : item_flags |= l3_tunnel_flag;
7955 : : tunnel = 1;
7956 : : }
7957 : 0 : ret = mlx5_flow_dv_validate_item_ipv4(dev, items,
7958 : : item_flags,
7959 : : last_item,
7960 : : ether_type,
7961 : : &nic_ipv4_mask,
7962 : : error);
7963 [ # # ]: 0 : if (ret < 0)
7964 : 0 : return ret;
7965 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
7966 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4;
7967 [ # # ]: 0 : if (l3_tunnel_detection == l3_tunnel_outer)
7968 : 0 : item_flags |= l3_tunnel_flag;
7969 : : break;
7970 : : case RTE_FLOW_ITEM_TYPE_IPV6:
7971 : : next_protocol = mlx5_flow_l3_next_protocol
7972 : : (items, (enum MLX5_SET_MATCHER)-1);
7973 : : l3_tunnel_detection =
7974 : : mlx5_flow_tunnel_ip_check(items, next_protocol,
7975 : : item_flags,
7976 : : &l3_tunnel_flag);
7977 : : /*
7978 : : * explicitly allow inner IPIP match
7979 : : */
7980 : : if (l3_tunnel_detection == l3_tunnel_outer) {
7981 : 0 : item_flags |= l3_tunnel_flag;
7982 : : tunnel = 1;
7983 : : }
7984 : 0 : ret = mlx5_flow_validate_item_ipv6(dev, items,
7985 : : item_flags,
7986 : : last_item,
7987 : : ether_type,
7988 : : &nic_ipv6_mask,
7989 : : error);
7990 [ # # ]: 0 : if (ret < 0)
7991 : 0 : return ret;
7992 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
7993 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6;
7994 [ # # ]: 0 : if (l3_tunnel_detection == l3_tunnel_outer)
7995 : 0 : item_flags |= l3_tunnel_flag;
7996 : : break;
7997 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
7998 : 0 : ret = flow_dv_validate_item_ipv6_frag_ext(dev, items,
7999 : : item_flags,
8000 : : error);
8001 [ # # ]: 0 : if (ret < 0)
8002 : 0 : return ret;
8003 [ # # ]: 0 : last_item = tunnel ?
8004 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
8005 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
8006 : : next_protocol = mlx5_flow_l3_next_protocol
8007 : : (items, (enum MLX5_SET_MATCHER)-1);
8008 : : break;
8009 : 0 : case RTE_FLOW_ITEM_TYPE_TCP:
8010 : 0 : ret = mlx5_flow_validate_item_tcp
8011 : : (dev, items, item_flags,
8012 : : next_protocol,
8013 : : &nic_tcp_mask,
8014 : : error);
8015 [ # # ]: 0 : if (ret < 0)
8016 : 0 : return ret;
8017 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
8018 : : MLX5_FLOW_LAYER_OUTER_L4_TCP;
8019 : 0 : break;
8020 : 0 : case RTE_FLOW_ITEM_TYPE_UDP:
8021 : 0 : ret = mlx5_flow_validate_item_udp(dev, items, item_flags,
8022 : : next_protocol,
8023 : : error);
8024 : 0 : const struct rte_flow_item_udp *spec = items->spec;
8025 : 0 : const struct rte_flow_item_udp *mask = items->mask;
8026 [ # # ]: 0 : if (!mask)
8027 : : mask = &rte_flow_item_udp_mask;
8028 [ # # ]: 0 : if (spec != NULL)
8029 [ # # ]: 0 : udp_dport = rte_be_to_cpu_16
8030 : : (spec->hdr.dst_port &
8031 : : mask->hdr.dst_port);
8032 [ # # ]: 0 : if (ret < 0)
8033 : 0 : return ret;
8034 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
8035 : : MLX5_FLOW_LAYER_OUTER_L4_UDP;
8036 : 0 : break;
8037 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
8038 : 0 : ret = mlx5_flow_validate_item_gre(dev, items, item_flags,
8039 : : next_protocol, error);
8040 [ # # ]: 0 : if (ret < 0)
8041 : 0 : return ret;
8042 : : gre_item = items;
8043 : 0 : last_item = MLX5_FLOW_LAYER_GRE;
8044 : 0 : break;
8045 : 0 : case RTE_FLOW_ITEM_TYPE_GRE_OPTION:
8046 : 0 : ret = mlx5_flow_validate_item_gre_option(dev, items, item_flags,
8047 : : attr, gre_item, error);
8048 [ # # ]: 0 : if (ret < 0)
8049 : 0 : return ret;
8050 : 0 : last_item = MLX5_FLOW_LAYER_GRE;
8051 : 0 : break;
8052 : 0 : case RTE_FLOW_ITEM_TYPE_NVGRE:
8053 : 0 : ret = mlx5_flow_validate_item_nvgre(dev, items,
8054 : : item_flags,
8055 : : next_protocol,
8056 : : error);
8057 [ # # ]: 0 : if (ret < 0)
8058 : 0 : return ret;
8059 : 0 : last_item = MLX5_FLOW_LAYER_NVGRE;
8060 : 0 : break;
8061 : 0 : case RTE_FLOW_ITEM_TYPE_GRE_KEY:
8062 : 0 : ret = mlx5_flow_validate_item_gre_key
8063 : : (dev, items, item_flags, gre_item, error);
8064 [ # # ]: 0 : if (ret < 0)
8065 : 0 : return ret;
8066 : 0 : last_item = MLX5_FLOW_LAYER_GRE_KEY;
8067 : 0 : break;
8068 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN:
8069 : 0 : ret = mlx5_flow_validate_item_vxlan(dev, udp_dport,
8070 : : items, item_flags,
8071 : : is_root, error);
8072 [ # # ]: 0 : if (ret < 0)
8073 : 0 : return ret;
8074 : 0 : last_item = MLX5_FLOW_LAYER_VXLAN;
8075 : 0 : break;
8076 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
8077 : 0 : ret = mlx5_flow_validate_item_vxlan_gpe(items,
8078 : : item_flags, dev,
8079 : : error);
8080 [ # # ]: 0 : if (ret < 0)
8081 : 0 : return ret;
8082 : 0 : last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
8083 : 0 : break;
8084 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE:
8085 : 0 : ret = mlx5_flow_validate_item_geneve(items,
8086 : : item_flags, dev,
8087 : : error);
8088 [ # # ]: 0 : if (ret < 0)
8089 : 0 : return ret;
8090 : : geneve_item = items;
8091 : 0 : last_item = MLX5_FLOW_LAYER_GENEVE;
8092 : 0 : break;
8093 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
8094 : 0 : ret = mlx5_flow_validate_item_geneve_opt(items,
8095 : : last_item,
8096 : : geneve_item,
8097 : : dev,
8098 : : error);
8099 [ # # ]: 0 : if (ret < 0)
8100 : 0 : return ret;
8101 : 0 : last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
8102 : 0 : break;
8103 : 0 : case RTE_FLOW_ITEM_TYPE_MPLS:
8104 : 0 : ret = mlx5_flow_validate_item_mpls(dev, items,
8105 : : item_flags,
8106 : : last_item, error);
8107 [ # # ]: 0 : if (ret < 0)
8108 : 0 : return ret;
8109 : 0 : last_item = MLX5_FLOW_LAYER_MPLS;
8110 : 0 : break;
8111 : :
8112 : 0 : case RTE_FLOW_ITEM_TYPE_MARK:
8113 : 0 : ret = flow_dv_validate_item_mark(dev, items, attr,
8114 : : error);
8115 [ # # ]: 0 : if (ret < 0)
8116 : 0 : return ret;
8117 : 0 : last_item = MLX5_FLOW_ITEM_MARK;
8118 : 0 : break;
8119 : 0 : case RTE_FLOW_ITEM_TYPE_META:
8120 : 0 : ret = flow_dv_validate_item_meta(dev, items, attr,
8121 : : error);
8122 [ # # ]: 0 : if (ret < 0)
8123 : 0 : return ret;
8124 : 0 : last_item = MLX5_FLOW_ITEM_METADATA;
8125 : 0 : break;
8126 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP:
8127 : 0 : ret = mlx5_flow_validate_item_icmp(dev, items, item_flags,
8128 : : next_protocol,
8129 : : error);
8130 [ # # ]: 0 : if (ret < 0)
8131 : 0 : return ret;
8132 : 0 : last_item = MLX5_FLOW_LAYER_ICMP;
8133 : 0 : break;
8134 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6:
8135 : 0 : ret = mlx5_flow_validate_item_icmp6(dev, items, item_flags,
8136 : : next_protocol,
8137 : : error);
8138 [ # # ]: 0 : if (ret < 0)
8139 : 0 : return ret;
8140 : : item_ipv6_proto = IPPROTO_ICMPV6;
8141 : 0 : last_item = MLX5_FLOW_LAYER_ICMP6;
8142 : 0 : break;
8143 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REQUEST:
8144 : : case RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REPLY:
8145 : 0 : ret = mlx5_flow_validate_item_icmp6_echo(dev, items,
8146 : : item_flags,
8147 : : next_protocol,
8148 : : error);
8149 [ # # ]: 0 : if (ret < 0)
8150 : 0 : return ret;
8151 : : item_ipv6_proto = IPPROTO_ICMPV6;
8152 : 0 : last_item = MLX5_FLOW_LAYER_ICMP6;
8153 : 0 : break;
8154 : 0 : case RTE_FLOW_ITEM_TYPE_TAG:
8155 : 0 : ret = flow_dv_validate_item_tag(dev, items, &tag_bitmap,
8156 : : attr, error);
8157 [ # # ]: 0 : if (ret < 0)
8158 : 0 : return ret;
8159 : 0 : last_item = MLX5_FLOW_ITEM_TAG;
8160 : 0 : break;
8161 : 0 : case RTE_FLOW_ITEM_TYPE_TX_QUEUE:
8162 : : case MLX5_RTE_FLOW_ITEM_TYPE_SQ:
8163 : 0 : last_item = MLX5_FLOW_ITEM_SQ;
8164 : 0 : break;
8165 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
8166 : 0 : mlx5_tag = (const struct mlx5_rte_flow_item_tag *)items->spec;
8167 [ # # ]: 0 : if (tag_bitmap & (1 << mlx5_tag->id))
8168 : 0 : return rte_flow_error_set(error, EINVAL,
8169 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
8170 : : items->spec,
8171 : : "Duplicated tag index");
8172 : 0 : tag_bitmap |= 1 << mlx5_tag->id;
8173 : 0 : break;
8174 : 0 : case RTE_FLOW_ITEM_TYPE_GTP:
8175 : 0 : ret = mlx5_flow_dv_validate_item_gtp(dev, items,
8176 : : item_flags,
8177 : : error);
8178 [ # # ]: 0 : if (ret < 0)
8179 : 0 : return ret;
8180 : : gtp_item = items;
8181 : 0 : last_item = MLX5_FLOW_LAYER_GTP;
8182 : 0 : break;
8183 : 0 : case RTE_FLOW_ITEM_TYPE_GTP_PSC:
8184 : 0 : ret = mlx5_flow_dv_validate_item_gtp_psc(dev, items,
8185 : : last_item,
8186 : : gtp_item,
8187 : : is_root, error);
8188 [ # # ]: 0 : if (ret < 0)
8189 : 0 : return ret;
8190 : 0 : last_item = MLX5_FLOW_LAYER_GTP_PSC;
8191 : 0 : break;
8192 : 0 : case RTE_FLOW_ITEM_TYPE_ECPRI:
8193 : : /* Capacity will be checked in the translate stage. */
8194 : 0 : ret = mlx5_flow_validate_item_ecpri(dev, items,
8195 : : item_flags,
8196 : : last_item,
8197 : : ether_type,
8198 : : &nic_ecpri_mask,
8199 : : error);
8200 [ # # ]: 0 : if (ret < 0)
8201 : 0 : return ret;
8202 : 0 : last_item = MLX5_FLOW_LAYER_ECPRI;
8203 : 0 : break;
8204 : 0 : case RTE_FLOW_ITEM_TYPE_INTEGRITY:
8205 : 0 : ret = flow_dv_validate_item_integrity(dev, items,
8206 : : item_flags,
8207 : : &last_item,
8208 : : integrity_items,
8209 : : error);
8210 [ # # ]: 0 : if (ret < 0)
8211 : 0 : return ret;
8212 : : break;
8213 : 0 : case RTE_FLOW_ITEM_TYPE_CONNTRACK:
8214 : 0 : ret = mlx5_flow_dv_validate_item_aso_ct(dev, items,
8215 : : &item_flags,
8216 : : error);
8217 [ # # ]: 0 : if (ret < 0)
8218 : 0 : return ret;
8219 : 0 : last_item = MLX5_FLOW_LAYER_ASO_CT;
8220 : 0 : break;
8221 : : case MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL:
8222 : : /* tunnel offload item was processed before
8223 : : * list it here as a supported type
8224 : : */
8225 : : break;
8226 : 0 : case RTE_FLOW_ITEM_TYPE_FLEX:
8227 : 0 : ret = flow_dv_validate_item_flex(dev, items, item_flags,
8228 : : &last_item,
8229 : : tunnel != 0, error);
8230 [ # # ]: 0 : if (ret < 0)
8231 : 0 : return ret;
8232 : : /* Reset for next proto, it is unknown. */
8233 : : next_protocol = 0xff;
8234 : : break;
8235 : 0 : case RTE_FLOW_ITEM_TYPE_METER_COLOR:
8236 : 0 : ret = flow_dv_validate_item_meter_color(dev, items,
8237 : : attr, error);
8238 [ # # ]: 0 : if (ret < 0)
8239 : 0 : return ret;
8240 : 0 : last_item = MLX5_FLOW_ITEM_METER_COLOR;
8241 : 0 : break;
8242 : 0 : case RTE_FLOW_ITEM_TYPE_AGGR_AFFINITY:
8243 : 0 : ret = flow_dv_validate_item_aggr_affinity(dev, items,
8244 : : attr, error);
8245 [ # # ]: 0 : if (ret < 0)
8246 : 0 : return ret;
8247 : 0 : last_item = MLX5_FLOW_ITEM_AGGR_AFFINITY;
8248 : 0 : break;
8249 : 0 : case RTE_FLOW_ITEM_TYPE_IB_BTH:
8250 : 0 : ret = mlx5_flow_validate_item_ib_bth(dev, udp_dport,
8251 : : items, is_root, error);
8252 [ # # ]: 0 : if (ret < 0)
8253 : 0 : return ret;
8254 : :
8255 : 0 : last_item = MLX5_FLOW_ITEM_IB_BTH;
8256 : 0 : break;
8257 : 0 : case RTE_FLOW_ITEM_TYPE_NSH:
8258 : 0 : ret = mlx5_flow_validate_item_nsh(dev, items, error);
8259 [ # # ]: 0 : if (ret < 0)
8260 : 0 : return ret;
8261 : 0 : last_item = MLX5_FLOW_ITEM_NSH;
8262 : 0 : break;
8263 : 0 : default:
8264 : 0 : return rte_flow_error_set(error, ENOTSUP,
8265 : : RTE_FLOW_ERROR_TYPE_ITEM,
8266 : : NULL, "item not supported");
8267 : : }
8268 : 0 : item_flags |= last_item;
8269 : : }
8270 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_INTEGRITY) {
8271 : 0 : ret = flow_dv_validate_item_integrity_post(integrity_items,
8272 : : item_flags, error);
8273 [ # # ]: 0 : if (ret)
8274 : : return ret;
8275 : : }
8276 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
8277 : 0 : int type = actions->type;
8278 : :
8279 : : if (!mlx5_flow_os_action_supported(type))
8280 : : return rte_flow_error_set(error, ENOTSUP,
8281 : : RTE_FLOW_ERROR_TYPE_ACTION,
8282 : : actions,
8283 : : "action not supported");
8284 [ # # ]: 0 : if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
8285 : 0 : return rte_flow_error_set(error, ENOTSUP,
8286 : : RTE_FLOW_ERROR_TYPE_ACTION,
8287 : : actions, "too many actions");
8288 [ # # ]: 0 : if (action_flags &
8289 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
8290 : 0 : return rte_flow_error_set(error, ENOTSUP,
8291 : : RTE_FLOW_ERROR_TYPE_ACTION,
8292 : : NULL, "meter action with policy "
8293 : : "must be the last action");
8294 [ # # # # : 0 : switch (type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
8295 : : case RTE_FLOW_ACTION_TYPE_VOID:
8296 : : break;
8297 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
8298 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
8299 : 0 : ret = flow_dv_validate_action_port_id(dev,
8300 : : action_flags,
8301 : : actions,
8302 : : attr,
8303 : : error);
8304 [ # # ]: 0 : if (ret)
8305 : 0 : return ret;
8306 [ # # ]: 0 : if (type == RTE_FLOW_ACTION_TYPE_PORT_ID) {
8307 : 0 : port = (const struct rte_flow_action_port_id *)
8308 : : actions->conf;
8309 [ # # ]: 0 : port_id = port->original ? dev->data->port_id : port->id;
8310 : : } else {
8311 : 0 : port_id = ((const struct rte_flow_action_ethdev *)
8312 : 0 : actions->conf)->port_id;
8313 : : }
8314 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_ID;
8315 : 0 : ++actions_n;
8316 : 0 : break;
8317 : 0 : case RTE_FLOW_ACTION_TYPE_FLAG:
8318 : 0 : ret = flow_dv_validate_action_flag(dev, action_flags,
8319 : : attr, error);
8320 [ # # ]: 0 : if (ret < 0)
8321 : 0 : return ret;
8322 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
8323 : : /* Count all modify-header actions as one. */
8324 [ # # ]: 0 : if (!(action_flags &
8325 : : MLX5_FLOW_MODIFY_HDR_ACTIONS))
8326 : 0 : ++actions_n;
8327 : 0 : action_flags |= MLX5_FLOW_ACTION_FLAG |
8328 : : MLX5_FLOW_ACTION_MARK_EXT;
8329 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8330 : : modify_after_mirror = 1;
8331 : :
8332 : : } else {
8333 : 0 : action_flags |= MLX5_FLOW_ACTION_FLAG;
8334 : 0 : ++actions_n;
8335 : : }
8336 : 0 : rw_act_num += MLX5_ACT_NUM_SET_MARK;
8337 : 0 : break;
8338 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
8339 : 0 : ret = flow_dv_validate_action_mark(dev, actions,
8340 : : action_flags,
8341 : : attr, error);
8342 [ # # ]: 0 : if (ret < 0)
8343 : 0 : return ret;
8344 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
8345 : : /* Count all modify-header actions as one. */
8346 [ # # ]: 0 : if (!(action_flags &
8347 : : MLX5_FLOW_MODIFY_HDR_ACTIONS))
8348 : 0 : ++actions_n;
8349 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK |
8350 : : MLX5_FLOW_ACTION_MARK_EXT;
8351 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8352 : : modify_after_mirror = 1;
8353 : : } else {
8354 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK;
8355 : 0 : ++actions_n;
8356 : : }
8357 : 0 : rw_act_num += MLX5_ACT_NUM_SET_MARK;
8358 : 0 : break;
8359 : 0 : case RTE_FLOW_ACTION_TYPE_SET_META:
8360 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
8361 : 0 : return rte_flow_error_set(error, ENOTSUP,
8362 : : RTE_FLOW_ERROR_TYPE_ACTION,
8363 : : actions,
8364 : : "action not supported");
8365 : 0 : ret = flow_dv_validate_action_set_meta(dev, actions,
8366 : : action_flags,
8367 : : attr, error);
8368 [ # # ]: 0 : if (ret < 0)
8369 : 0 : return ret;
8370 : : /* Count all modify-header actions as one action. */
8371 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8372 : 0 : ++actions_n;
8373 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8374 : : modify_after_mirror = 1;
8375 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_META;
8376 : 0 : rw_act_num += MLX5_ACT_NUM_SET_META;
8377 : 0 : break;
8378 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TAG:
8379 : 0 : ret = flow_dv_validate_action_set_tag(dev, actions,
8380 : : action_flags,
8381 : : attr, error);
8382 [ # # ]: 0 : if (ret < 0)
8383 : 0 : return ret;
8384 : : /* Count all modify-header actions as one action. */
8385 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8386 : 0 : ++actions_n;
8387 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8388 : : modify_after_mirror = 1;
8389 : 0 : tag_id = ((const struct rte_flow_action_set_tag *)
8390 : 0 : actions->conf)->index;
8391 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
8392 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
8393 : 0 : break;
8394 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
8395 : 0 : ret = mlx5_flow_validate_action_drop(dev, is_root,
8396 : : attr, error);
8397 [ # # ]: 0 : if (ret < 0)
8398 : 0 : return ret;
8399 : 0 : action_flags |= MLX5_FLOW_ACTION_DROP;
8400 : 0 : ++actions_n;
8401 : 0 : break;
8402 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
8403 : 0 : ret = mlx5_flow_validate_action_queue(actions,
8404 : : action_flags, dev,
8405 : : attr, error);
8406 [ # # ]: 0 : if (ret < 0)
8407 : 0 : return ret;
8408 : 0 : queue_index = ((const struct rte_flow_action_queue *)
8409 : 0 : (actions->conf))->index;
8410 : 0 : action_flags |= MLX5_FLOW_ACTION_QUEUE;
8411 : 0 : ++actions_n;
8412 : 0 : break;
8413 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
8414 : 0 : rss = actions->conf;
8415 : 0 : ret = mlx5_flow_validate_action_rss(actions,
8416 : : action_flags, dev,
8417 : : attr, item_flags,
8418 : : error);
8419 [ # # ]: 0 : if (ret < 0)
8420 : 0 : return ret;
8421 [ # # ]: 0 : if (rss && sample_rss &&
8422 [ # # ]: 0 : (sample_rss->level != rss->level ||
8423 [ # # ]: 0 : sample_rss->types != rss->types))
8424 : 0 : return rte_flow_error_set(error, ENOTSUP,
8425 : : RTE_FLOW_ERROR_TYPE_ACTION,
8426 : : NULL,
8427 : : "Can't use the different RSS types "
8428 : : "or level in the same flow");
8429 [ # # # # ]: 0 : if (rss != NULL && rss->queue_num)
8430 : 0 : queue_index = rss->queue[0];
8431 : 0 : action_flags |= MLX5_FLOW_ACTION_RSS;
8432 : 0 : ++actions_n;
8433 : 0 : break;
8434 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
8435 : : ret =
8436 : 0 : mlx5_flow_validate_action_default_miss(action_flags,
8437 : : attr, error);
8438 [ # # ]: 0 : if (ret < 0)
8439 : 0 : return ret;
8440 : 0 : action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
8441 : 0 : ++actions_n;
8442 : 0 : break;
8443 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
8444 : : shared_count = true;
8445 : : /* fall-through. */
8446 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
8447 : 0 : ret = flow_dv_validate_action_count(dev, shared_count,
8448 : : action_flags,
8449 : : is_root, error);
8450 [ # # ]: 0 : if (ret < 0)
8451 : 0 : return ret;
8452 : 0 : count = actions->conf;
8453 : 0 : action_flags |= MLX5_FLOW_ACTION_COUNT;
8454 : 0 : ++actions_n;
8455 : 0 : break;
8456 : 0 : case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
8457 [ # # ]: 0 : if (flow_dv_validate_action_pop_vlan(dev,
8458 : : action_flags,
8459 : : actions,
8460 : : item_flags, attr,
8461 : : error))
8462 : 0 : return -rte_errno;
8463 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8464 : : modify_after_mirror = 1;
8465 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
8466 : 0 : ++actions_n;
8467 : 0 : break;
8468 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
8469 : 0 : ret = flow_dv_validate_action_push_vlan(dev,
8470 : : action_flags,
8471 : : vlan_m,
8472 : : actions, attr,
8473 : : error);
8474 [ # # ]: 0 : if (ret < 0)
8475 : 0 : return ret;
8476 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8477 : : modify_after_mirror = 1;
8478 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
8479 : 0 : ++actions_n;
8480 : 0 : break;
8481 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
8482 : 0 : ret = flow_dv_validate_action_set_vlan_pcp
8483 : : (action_flags, actions, error);
8484 [ # # ]: 0 : if (ret < 0)
8485 : 0 : return ret;
8486 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8487 : : modify_after_mirror = 1;
8488 : : /* Count PCP with push_vlan command. */
8489 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_PCP;
8490 : 0 : break;
8491 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
8492 : 0 : ret = flow_dv_validate_action_set_vlan_vid
8493 : : (item_flags, action_flags,
8494 : : actions, error);
8495 [ # # ]: 0 : if (ret < 0)
8496 : 0 : return ret;
8497 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8498 : : modify_after_mirror = 1;
8499 : : /* Count VID with push_vlan command. */
8500 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
8501 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_VID;
8502 : 0 : break;
8503 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
8504 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
8505 : 0 : ret = mlx5_flow_dv_validate_action_l2_encap(dev,
8506 : : action_flags,
8507 : : actions,
8508 : : attr,
8509 : : error);
8510 [ # # ]: 0 : if (ret < 0)
8511 : 0 : return ret;
8512 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
8513 : 0 : ++actions_n;
8514 : 0 : break;
8515 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
8516 : : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
8517 : 0 : ret = mlx5_flow_dv_validate_action_decap(dev,
8518 : : action_flags,
8519 : : actions,
8520 : : item_flags,
8521 : : attr, error);
8522 [ # # ]: 0 : if (ret < 0)
8523 : 0 : return ret;
8524 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8525 : : modify_after_mirror = 1;
8526 : 0 : action_flags |= MLX5_FLOW_ACTION_DECAP;
8527 : 0 : ++actions_n;
8528 : 0 : break;
8529 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
8530 : 0 : ret = mlx5_flow_dv_validate_action_raw_encap_decap
8531 : 0 : (dev, NULL, actions->conf, attr, &action_flags,
8532 : : &actions_n, actions, item_flags, error);
8533 [ # # ]: 0 : if (ret < 0)
8534 : 0 : return ret;
8535 : : break;
8536 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
8537 : 0 : decap = actions->conf;
8538 [ # # ]: 0 : while ((++actions)->type == RTE_FLOW_ACTION_TYPE_VOID)
8539 : : ;
8540 [ # # ]: 0 : if (actions->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
8541 : : encap = NULL;
8542 : : actions--;
8543 : : } else {
8544 : 0 : encap = actions->conf;
8545 : : }
8546 [ # # ]: 0 : ret = mlx5_flow_dv_validate_action_raw_encap_decap
8547 : : (dev,
8548 : : decap ? decap : &empty_decap, encap,
8549 : : attr, &action_flags, &actions_n,
8550 : : actions, item_flags, error);
8551 [ # # ]: 0 : if (ret < 0)
8552 : 0 : return ret;
8553 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_SAMPLE) &&
8554 : : (action_flags & MLX5_FLOW_ACTION_DECAP))
8555 : : modify_after_mirror = 1;
8556 : : break;
8557 : 0 : case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
8558 : : case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
8559 : 0 : ret = flow_dv_validate_action_modify_mac(action_flags,
8560 : : actions,
8561 : : item_flags,
8562 : : error);
8563 [ # # ]: 0 : if (ret < 0)
8564 : 0 : return ret;
8565 : : /* Count all modify-header actions as one action. */
8566 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8567 : 0 : ++actions_n;
8568 : 0 : action_flags |= actions->type ==
8569 : : RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
8570 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_MAC_SRC :
8571 : : MLX5_FLOW_ACTION_SET_MAC_DST;
8572 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8573 : : modify_after_mirror = 1;
8574 : : /*
8575 : : * Even if the source and destination MAC addresses have
8576 : : * overlap in the header with 4B alignment, the convert
8577 : : * function will handle them separately and 4 SW actions
8578 : : * will be created. And 2 actions will be added each
8579 : : * time no matter how many bytes of address will be set.
8580 : : */
8581 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_MAC;
8582 : 0 : break;
8583 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
8584 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
8585 : 0 : ret = flow_dv_validate_action_modify_ipv4(action_flags,
8586 : : actions,
8587 : : item_flags,
8588 : : error);
8589 [ # # ]: 0 : if (ret < 0)
8590 : 0 : return ret;
8591 : : /* Count all modify-header actions as one action. */
8592 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8593 : 0 : ++actions_n;
8594 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8595 : : modify_after_mirror = 1;
8596 : 0 : action_flags |= actions->type ==
8597 : : RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
8598 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_IPV4_SRC :
8599 : : MLX5_FLOW_ACTION_SET_IPV4_DST;
8600 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_IPV4;
8601 : 0 : break;
8602 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
8603 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
8604 : 0 : ret = flow_dv_validate_action_modify_ipv6(action_flags,
8605 : : actions,
8606 : : item_flags,
8607 : : error);
8608 [ # # ]: 0 : if (ret < 0)
8609 : 0 : return ret;
8610 [ # # ]: 0 : if (item_ipv6_proto == IPPROTO_ICMPV6)
8611 : 0 : return rte_flow_error_set(error, ENOTSUP,
8612 : : RTE_FLOW_ERROR_TYPE_ACTION,
8613 : : actions,
8614 : : "Can't change header "
8615 : : "with ICMPv6 proto");
8616 : : /* Count all modify-header actions as one action. */
8617 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8618 : 0 : ++actions_n;
8619 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8620 : : modify_after_mirror = 1;
8621 : 0 : action_flags |= actions->type ==
8622 : : RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
8623 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_IPV6_SRC :
8624 : : MLX5_FLOW_ACTION_SET_IPV6_DST;
8625 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_IPV6;
8626 : 0 : break;
8627 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
8628 : : case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
8629 : 0 : ret = flow_dv_validate_action_modify_tp(action_flags,
8630 : : actions,
8631 : : item_flags,
8632 : : error);
8633 [ # # ]: 0 : if (ret < 0)
8634 : 0 : return ret;
8635 : : /* Count all modify-header actions as one action. */
8636 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8637 : 0 : ++actions_n;
8638 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8639 : : modify_after_mirror = 1;
8640 : 0 : action_flags |= actions->type ==
8641 : : RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
8642 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_TP_SRC :
8643 : : MLX5_FLOW_ACTION_SET_TP_DST;
8644 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_PORT;
8645 : 0 : break;
8646 : 0 : case RTE_FLOW_ACTION_TYPE_DEC_TTL:
8647 : : case RTE_FLOW_ACTION_TYPE_SET_TTL:
8648 : 0 : ret = flow_dv_validate_action_modify_ttl(action_flags,
8649 : : actions,
8650 : : item_flags,
8651 : : error);
8652 [ # # ]: 0 : if (ret < 0)
8653 : 0 : return ret;
8654 : : /* Count all modify-header actions as one action. */
8655 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8656 : 0 : ++actions_n;
8657 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8658 : : modify_after_mirror = 1;
8659 : 0 : action_flags |= actions->type ==
8660 : : RTE_FLOW_ACTION_TYPE_SET_TTL ?
8661 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_TTL :
8662 : : MLX5_FLOW_ACTION_DEC_TTL;
8663 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_TTL;
8664 : 0 : break;
8665 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
8666 : 0 : ret = flow_dv_validate_action_jump(dev, tunnel, actions,
8667 : : action_flags,
8668 : : attr, external,
8669 : : error);
8670 [ # # ]: 0 : if (ret)
8671 : 0 : return ret;
8672 : 0 : ++actions_n;
8673 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP;
8674 : 0 : break;
8675 : 0 : case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
8676 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
8677 : 0 : ret = flow_dv_validate_action_modify_tcp_seq
8678 : : (action_flags,
8679 : : actions,
8680 : : item_flags,
8681 : : error);
8682 [ # # ]: 0 : if (ret < 0)
8683 : 0 : return ret;
8684 : : /* Count all modify-header actions as one action. */
8685 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8686 : 0 : ++actions_n;
8687 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8688 : : modify_after_mirror = 1;
8689 : 0 : action_flags |= actions->type ==
8690 : : RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
8691 [ # # ]: 0 : MLX5_FLOW_ACTION_INC_TCP_SEQ :
8692 : : MLX5_FLOW_ACTION_DEC_TCP_SEQ;
8693 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_TCPSEQ;
8694 : 0 : break;
8695 : 0 : case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
8696 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
8697 : 0 : ret = flow_dv_validate_action_modify_tcp_ack
8698 : : (action_flags,
8699 : : actions,
8700 : : item_flags,
8701 : : error);
8702 [ # # ]: 0 : if (ret < 0)
8703 : 0 : return ret;
8704 : : /* Count all modify-header actions as one action. */
8705 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8706 : 0 : ++actions_n;
8707 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8708 : : modify_after_mirror = 1;
8709 : 0 : action_flags |= actions->type ==
8710 : : RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
8711 [ # # ]: 0 : MLX5_FLOW_ACTION_INC_TCP_ACK :
8712 : : MLX5_FLOW_ACTION_DEC_TCP_ACK;
8713 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_TCPACK;
8714 : 0 : break;
8715 : : case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
8716 : : break;
8717 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
8718 : : case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
8719 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
8720 : 0 : break;
8721 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
8722 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
8723 : 0 : return rte_flow_error_set(error, ENOTSUP,
8724 : : RTE_FLOW_ERROR_TYPE_ACTION,
8725 : : actions,
8726 : : "action not supported");
8727 : 0 : ret = mlx5_flow_validate_action_meter(dev,
8728 : : action_flags,
8729 : : item_flags,
8730 : : actions, attr,
8731 : : port_id_item,
8732 : : &def_policy,
8733 : : error);
8734 [ # # ]: 0 : if (ret < 0)
8735 : 0 : return ret;
8736 : 0 : action_flags |= MLX5_FLOW_ACTION_METER;
8737 [ # # ]: 0 : if (!def_policy)
8738 : 0 : action_flags |=
8739 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
8740 : 0 : ++actions_n;
8741 : : /* Meter action will add one more TAG action. */
8742 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
8743 : 0 : break;
8744 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
8745 [ # # ]: 0 : if (is_root)
8746 : 0 : return rte_flow_error_set(error, ENOTSUP,
8747 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8748 : : NULL,
8749 : : "Shared ASO age action is not supported for group 0");
8750 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_AGE)
8751 : 0 : return rte_flow_error_set
8752 : : (error, EINVAL,
8753 : : RTE_FLOW_ERROR_TYPE_ACTION,
8754 : : NULL,
8755 : : "duplicate age actions set");
8756 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8757 : : aso_after_sample = 1;
8758 : 0 : action_flags |= MLX5_FLOW_ACTION_AGE;
8759 : 0 : ++actions_n;
8760 : 0 : break;
8761 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
8762 : 0 : non_shared_age = actions->conf;
8763 : 0 : ret = flow_dv_validate_action_age(action_flags,
8764 : : actions, dev,
8765 : : error);
8766 [ # # ]: 0 : if (ret < 0)
8767 : 0 : return ret;
8768 : : /*
8769 : : * Validate the regular AGE action (using counter)
8770 : : * mutual exclusion with indirect counter actions.
8771 : : */
8772 [ # # ]: 0 : if (!flow_hit_aso_supported(priv, is_root)) {
8773 [ # # ]: 0 : if (shared_count)
8774 : 0 : return rte_flow_error_set
8775 : : (error, EINVAL,
8776 : : RTE_FLOW_ERROR_TYPE_ACTION,
8777 : : NULL,
8778 : : "old age and indirect count combination is not supported");
8779 [ # # ]: 0 : if (sample_count)
8780 : 0 : return rte_flow_error_set
8781 : : (error, EINVAL,
8782 : : RTE_FLOW_ERROR_TYPE_ACTION,
8783 : : NULL,
8784 : : "old age action and count must be in the same sub flow");
8785 : : } else {
8786 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8787 : : aso_after_sample = 1;
8788 : : }
8789 : 0 : action_flags |= MLX5_FLOW_ACTION_AGE;
8790 : 0 : ++actions_n;
8791 : 0 : break;
8792 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
8793 : 0 : ret = flow_dv_validate_action_modify_ipv4_dscp
8794 : : (action_flags,
8795 : : actions,
8796 : : item_flags,
8797 : : error);
8798 [ # # ]: 0 : if (ret < 0)
8799 : 0 : return ret;
8800 : : /* Count all modify-header actions as one action. */
8801 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8802 : 0 : ++actions_n;
8803 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8804 : : modify_after_mirror = 1;
8805 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
8806 : 0 : rw_act_num += MLX5_ACT_NUM_SET_DSCP;
8807 : 0 : break;
8808 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
8809 : 0 : ret = flow_dv_validate_action_modify_ipv6_dscp
8810 : : (action_flags,
8811 : : actions,
8812 : : item_flags,
8813 : : error);
8814 [ # # ]: 0 : if (ret < 0)
8815 : 0 : return ret;
8816 : : /* Count all modify-header actions as one action. */
8817 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8818 : 0 : ++actions_n;
8819 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8820 : : modify_after_mirror = 1;
8821 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
8822 : 0 : rw_act_num += MLX5_ACT_NUM_SET_DSCP;
8823 : 0 : break;
8824 : 0 : case RTE_FLOW_ACTION_TYPE_SAMPLE:
8825 : 0 : ret = flow_dv_validate_action_sample(&action_flags,
8826 : : &sub_action_flags,
8827 : : actions, dev,
8828 : : attr, item_flags,
8829 : : rss, &sample_rss,
8830 : : &sample_count,
8831 : : &fdb_mirror,
8832 : : &sample_port_id,
8833 : : is_root,
8834 : : error);
8835 [ # # ]: 0 : if (ret < 0)
8836 : 0 : return ret;
8837 [ # # # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_SET_TAG) &&
8838 : 0 : tag_id == 0 &&
8839 [ # # ]: 0 : priv->sh->registers.aso_reg == REG_NON)
8840 : 0 : return rte_flow_error_set(error, EINVAL,
8841 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8842 : : "sample after tag action causes metadata tag index 0 corruption");
8843 : 0 : action_flags |= MLX5_FLOW_ACTION_SAMPLE;
8844 : 0 : ++actions_n;
8845 : 0 : break;
8846 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
8847 : 0 : ret = flow_dv_validate_action_modify_field(dev,
8848 : : action_flags,
8849 : : actions,
8850 : : attr,
8851 : : is_root,
8852 : : error);
8853 [ # # ]: 0 : if (ret < 0)
8854 : 0 : return ret;
8855 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8856 : : modify_after_mirror = 1;
8857 : : /* Count all modify-header actions as one action. */
8858 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8859 : 0 : ++actions_n;
8860 : 0 : action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
8861 : 0 : rw_act_num += ret;
8862 : 0 : break;
8863 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
8864 : 0 : ret = mlx5_flow_dv_validate_action_aso_ct(dev,
8865 : : action_flags,
8866 : : item_flags,
8867 : : is_root,
8868 : : error);
8869 [ # # ]: 0 : if (ret < 0)
8870 : 0 : return ret;
8871 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8872 : : aso_after_sample = 1;
8873 : 0 : action_flags |= MLX5_FLOW_ACTION_CT;
8874 : 0 : break;
8875 : : case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
8876 : : /* tunnel offload action was processed before
8877 : : * list it here as a supported type
8878 : : */
8879 : : break;
8880 : : #ifdef HAVE_MLX5DV_DR_ACTION_CREATE_DEST_ROOT_TABLE
8881 : : case RTE_FLOW_ACTION_TYPE_SEND_TO_KERNEL:
8882 : : action_flags |= MLX5_FLOW_ACTION_SEND_TO_KERNEL;
8883 : : ++actions_n;
8884 : : break;
8885 : : #endif
8886 : 0 : default:
8887 : 0 : return rte_flow_error_set(error, ENOTSUP,
8888 : : RTE_FLOW_ERROR_TYPE_ACTION,
8889 : : actions,
8890 : : "action not supported");
8891 : : }
8892 : : }
8893 : : /*
8894 : : * Validate actions in flow rules
8895 : : * - Explicit decap action is prohibited by the tunnel offload API.
8896 : : * - Drop action in tunnel steer rule is prohibited by the API.
8897 : : * - Application cannot use MARK action because it's value can mask
8898 : : * tunnel default miss notification.
8899 : : * - JUMP in tunnel match rule has no support in current PMD
8900 : : * implementation.
8901 : : * - TAG & META are reserved for future uses.
8902 : : */
8903 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_TUNNEL_SET) {
8904 : : uint64_t bad_actions_mask = MLX5_FLOW_ACTION_DECAP |
8905 : : MLX5_FLOW_ACTION_MARK |
8906 : : MLX5_FLOW_ACTION_SET_TAG |
8907 : : MLX5_FLOW_ACTION_SET_META |
8908 : : MLX5_FLOW_ACTION_DROP;
8909 : :
8910 [ # # ]: 0 : if (action_flags & bad_actions_mask)
8911 : 0 : return rte_flow_error_set
8912 : : (error, EINVAL,
8913 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8914 : : "Invalid RTE action in tunnel "
8915 : : "set decap rule");
8916 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_ACTION_JUMP))
8917 : 0 : return rte_flow_error_set
8918 : : (error, EINVAL,
8919 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8920 : : "tunnel set decap rule must terminate "
8921 : : "with JUMP");
8922 [ # # ]: 0 : if (attr->egress)
8923 : 0 : return rte_flow_error_set
8924 : : (error, EINVAL,
8925 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8926 : : "tunnel flows for ingress and transfer traffic only");
8927 : : }
8928 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_TUNNEL_MATCH) {
8929 : : uint64_t bad_actions_mask = MLX5_FLOW_ACTION_JUMP |
8930 : : MLX5_FLOW_ACTION_MARK |
8931 : : MLX5_FLOW_ACTION_SET_TAG |
8932 : : MLX5_FLOW_ACTION_SET_META;
8933 : :
8934 [ # # ]: 0 : if (action_flags & bad_actions_mask)
8935 : 0 : return rte_flow_error_set
8936 : : (error, EINVAL,
8937 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8938 : : "Invalid RTE action in tunnel "
8939 : : "set match rule");
8940 : : }
8941 : : /*
8942 : : * Validate the drop action mutual exclusion with other actions.
8943 : : * Drop action is mutually-exclusive with any other action, except for
8944 : : * Count/Sample/Age actions.
8945 : : * Drop action compatibility with tunnel offload was already validated.
8946 : : */
8947 [ # # ]: 0 : if (action_flags & (MLX5_FLOW_ACTION_TUNNEL_MATCH |
8948 : : MLX5_FLOW_ACTION_TUNNEL_MATCH));
8949 [ # # ]: 0 : else if ((action_flags & MLX5_FLOW_ACTION_DROP) &&
8950 [ # # ]: 0 : (action_flags & ~(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_DROP_INCLUSIVE_ACTIONS)))
8951 : 0 : return rte_flow_error_set(error, EINVAL,
8952 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8953 : : "Drop action is mutually-exclusive "
8954 : : "with any other action, except for "
8955 : : "Count/Sample/Age action");
8956 : : /* Eswitch has few restrictions on using items and actions */
8957 [ # # ]: 0 : if (attr->transfer) {
8958 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev) &&
8959 [ # # ]: 0 : action_flags & MLX5_FLOW_ACTION_FLAG)
8960 : 0 : return rte_flow_error_set(error, ENOTSUP,
8961 : : RTE_FLOW_ERROR_TYPE_ACTION,
8962 : : NULL,
8963 : : "unsupported action FLAG");
8964 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev) &&
8965 [ # # ]: 0 : action_flags & MLX5_FLOW_ACTION_MARK)
8966 : 0 : return rte_flow_error_set(error, ENOTSUP,
8967 : : RTE_FLOW_ERROR_TYPE_ACTION,
8968 : : NULL,
8969 : : "unsupported action MARK");
8970 [ # # ]: 0 : if (!priv->jump_fdb_rx_en) {
8971 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_QUEUE)
8972 : 0 : return rte_flow_error_set(error, ENOTSUP,
8973 : : RTE_FLOW_ERROR_TYPE_ACTION,
8974 : : NULL,
8975 : : "unsupported action QUEUE");
8976 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_RSS)
8977 : 0 : return rte_flow_error_set(error, ENOTSUP,
8978 : : RTE_FLOW_ERROR_TYPE_ACTION,
8979 : : NULL,
8980 : : "unsupported action RSS");
8981 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
8982 : 0 : return rte_flow_error_set(error, EINVAL,
8983 : : RTE_FLOW_ERROR_TYPE_ACTION,
8984 : : actions,
8985 : : "no fate action is found");
8986 : : }
8987 : : } else {
8988 [ # # # # ]: 0 : if (!(action_flags & MLX5_FLOW_FATE_ACTIONS) && attr->ingress)
8989 : 0 : return rte_flow_error_set(error, EINVAL,
8990 : : RTE_FLOW_ERROR_TYPE_ACTION,
8991 : : actions,
8992 : : "no fate action is found");
8993 : : }
8994 : : /*
8995 : : * Continue validation for Xcap and VLAN actions.
8996 : : * If hairpin is working in explicit TX rule mode, there is no actions
8997 : : * splitting and the validation of hairpin ingress flow should be the
8998 : : * same as other standard flows.
8999 : : */
9000 [ # # ]: 0 : if ((action_flags & (MLX5_FLOW_XCAP_ACTIONS |
9001 [ # # ]: 0 : MLX5_FLOW_VLAN_ACTIONS)) &&
9002 [ # # # # ]: 0 : (queue_index == 0xFFFF || !mlx5_rxq_is_hairpin(dev, queue_index) ||
9003 : 0 : ((conf = mlx5_rxq_get_hairpin_conf(dev, queue_index)) != NULL &&
9004 [ # # ]: 0 : conf->tx_explicit != 0))) {
9005 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
9006 : : MLX5_FLOW_XCAP_ACTIONS)
9007 : 0 : return rte_flow_error_set(error, ENOTSUP,
9008 : : RTE_FLOW_ERROR_TYPE_ACTION,
9009 : : NULL, "encap and decap "
9010 : : "combination aren't supported");
9011 : : /* Push VLAN is not supported in ingress except for NICs newer than CX5. */
9012 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) {
9013 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
9014 : : bool direction_error = false;
9015 : :
9016 [ # # ]: 0 : if (attr->transfer) {
9017 [ # # ]: 0 : bool fdb_tx = flow_source_vport_representor(priv, act_priv);
9018 : 0 : bool is_cx5 = sh->steering_format_version ==
9019 : : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5;
9020 : :
9021 [ # # ]: 0 : if (!fdb_tx && is_cx5)
9022 : : direction_error = true;
9023 [ # # ]: 0 : } else if (attr->ingress) {
9024 : : direction_error = true;
9025 : : }
9026 : : if (direction_error)
9027 : 0 : return rte_flow_error_set(error, ENOTSUP,
9028 : : RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
9029 : : NULL,
9030 : : "push VLAN action not supported "
9031 : : "for ingress");
9032 : : }
9033 [ # # ]: 0 : if (attr->ingress) {
9034 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
9035 : 0 : return rte_flow_error_set
9036 : : (error, ENOTSUP,
9037 : : RTE_FLOW_ERROR_TYPE_ACTION,
9038 : : NULL, "encap is not supported"
9039 : : " for ingress traffic");
9040 [ # # ]: 0 : else if ((action_flags & MLX5_FLOW_VLAN_ACTIONS) ==
9041 : : MLX5_FLOW_VLAN_ACTIONS)
9042 : 0 : return rte_flow_error_set
9043 : : (error, ENOTSUP,
9044 : : RTE_FLOW_ERROR_TYPE_ACTION,
9045 : : NULL, "no support for "
9046 : : "multiple VLAN actions");
9047 : : }
9048 : : }
9049 : : /* Pop VLAN is not supported in egress except for NICs newer than CX5. */
9050 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_POP_VLAN) {
9051 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
9052 : : bool direction_error = false;
9053 : :
9054 [ # # ]: 0 : if (attr->transfer) {
9055 [ # # ]: 0 : bool fdb_tx = flow_source_vport_representor(priv, act_priv);
9056 : 0 : bool is_cx5 = sh->steering_format_version ==
9057 : : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5;
9058 : :
9059 [ # # ]: 0 : if (fdb_tx && is_cx5)
9060 : : direction_error = true;
9061 [ # # ]: 0 : } else if (attr->egress) {
9062 : : direction_error = true;
9063 : : }
9064 : : if (direction_error)
9065 : 0 : return rte_flow_error_set(error, ENOTSUP,
9066 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
9067 : : NULL,
9068 : : "pop vlan action not supported for egress");
9069 : : }
9070 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY) {
9071 [ # # ]: 0 : if ((action_flags & (MLX5_FLOW_FATE_ACTIONS &
9072 [ # # ]: 0 : ~MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)) &&
9073 : : attr->ingress)
9074 : 0 : return rte_flow_error_set
9075 : : (error, ENOTSUP,
9076 : : RTE_FLOW_ERROR_TYPE_ACTION,
9077 : : NULL, "fate action not supported for "
9078 : : "meter with policy");
9079 [ # # ]: 0 : if (attr->egress) {
9080 [ # # ]: 0 : if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
9081 : 0 : return rte_flow_error_set
9082 : : (error, ENOTSUP,
9083 : : RTE_FLOW_ERROR_TYPE_ACTION,
9084 : : NULL, "modify header action in egress "
9085 : : "cannot be done before meter action");
9086 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
9087 : 0 : return rte_flow_error_set
9088 : : (error, ENOTSUP,
9089 : : RTE_FLOW_ERROR_TYPE_ACTION,
9090 : : NULL, "encap action in egress "
9091 : : "cannot be done before meter action");
9092 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
9093 : 0 : return rte_flow_error_set
9094 : : (error, ENOTSUP,
9095 : : RTE_FLOW_ERROR_TYPE_ACTION,
9096 : : NULL, "push vlan action in egress "
9097 : : "cannot be done before meter action");
9098 : : }
9099 : : }
9100 : : /*
9101 : : * Only support one ASO action in a single flow rule.
9102 : : * non-shared AGE + counter will fallback to use HW counter, no ASO hit object.
9103 : : * Group 0 uses HW counter for AGE too even if no counter action.
9104 : : */
9105 [ # # # # ]: 0 : aso_mask = (action_flags & MLX5_FLOW_ACTION_METER && priv->sh->meter_aso_en) << 2 |
9106 [ # # # # : 0 : (action_flags & MLX5_FLOW_ACTION_CT && priv->sh->ct_aso_en) << 1 |
# # ]
9107 : 0 : (action_flags & MLX5_FLOW_ACTION_AGE &&
9108 [ # # ]: 0 : !(non_shared_age && count) &&
9109 [ # # # # : 0 : (attr->group || (attr->transfer && priv->fdb_def_rule)) &&
# # # # ]
9110 [ # # ]: 0 : priv->sh->flow_hit_aso_en);
9111 [ # # ]: 0 : if (rte_popcount64(aso_mask) > 1)
9112 : 0 : return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
9113 : : NULL, "unsupported combining AGE, METER, CT ASO actions in a single rule");
9114 : : /*
9115 : : * Hairpin flow will add one more TAG action in TX implicit mode.
9116 : : * In TX explicit mode, there will be no hairpin flow ID.
9117 : : */
9118 [ # # ]: 0 : if (hairpin > 0)
9119 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
9120 : : /* extra metadata enabled: one more TAG action will be add. */
9121 [ # # ]: 0 : if (dev_conf->dv_flow_en &&
9122 [ # # # # ]: 0 : dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
9123 : 0 : mlx5_flow_ext_mreg_supported(dev))
9124 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
9125 [ # # ]: 0 : if (rw_act_num >
9126 : : flow_dv_modify_hdr_action_max(dev, is_root)) {
9127 : 0 : return rte_flow_error_set(error, ENOTSUP,
9128 : : RTE_FLOW_ERROR_TYPE_ACTION,
9129 : : NULL, "too many header modify"
9130 : : " actions to support");
9131 : : }
9132 [ # # ]: 0 : if (fdb_mirror) {
9133 [ # # # # ]: 0 : if (!priv->sh->cdev->config.hca_attr.reg_c_preserve &&
9134 [ # # ]: 0 : flow_source_vport_representor(priv, act_priv)) {
9135 : : /* Eswitch egress mirror and modify flow has limitation on CX5 */
9136 [ # # ]: 0 : if (modify_after_mirror)
9137 : 0 : return rte_flow_error_set(error, EINVAL,
9138 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9139 : : "sample before modify action is not supported");
9140 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_JUMP)
9141 : 0 : return rte_flow_error_set(error, EINVAL,
9142 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9143 : : "sample and jump action combination is not supported");
9144 : : }
9145 [ # # ]: 0 : if (aso_mask > 0 && aso_after_sample && fdb_mirror)
9146 : 0 : return rte_flow_error_set(error, ENOTSUP,
9147 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9148 : : "sample before ASO action is not supported");
9149 [ # # ]: 0 : if (sub_action_flags & MLX5_FLOW_ACTION_PORT_ID) {
9150 : 0 : port_priv = mlx5_port_to_eswitch_info(sample_port_id, false);
9151 [ # # ]: 0 : if (flow_source_vport_representor(priv, port_priv)) {
9152 [ # # ]: 0 : if (sub_action_flags & MLX5_FLOW_ACTION_ENCAP)
9153 : 0 : return rte_flow_error_set(error, ENOTSUP,
9154 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9155 : : "mirror to rep port with encap is not supported");
9156 : : } else {
9157 [ # # ]: 0 : if (!(sub_action_flags & MLX5_FLOW_ACTION_ENCAP) &&
9158 [ # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_JUMP))
9159 : 0 : return rte_flow_error_set(error, ENOTSUP,
9160 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9161 : : "mirror to wire port without encap is not supported");
9162 : : }
9163 : : }
9164 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_PORT_ID) &&
9165 : : (action_flags & MLX5_FLOW_ACTION_ENCAP)) {
9166 : 0 : port_priv = mlx5_port_to_eswitch_info(port_id, false);
9167 [ # # ]: 0 : if (flow_source_vport_representor(priv, port_priv))
9168 : 0 : return rte_flow_error_set(error, ENOTSUP,
9169 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9170 : : "mirror to rep port with encap is not supported");
9171 : : }
9172 : : }
9173 : : /*
9174 : : * Validation the NIC Egress flow on representor, except implicit
9175 : : * hairpin default egress flow with TX_QUEUE item, other flows not
9176 : : * work due to metadata regC0 mismatch.
9177 : : */
9178 [ # # # # : 0 : if (attr->egress && priv->representor && !(item_flags & MLX5_FLOW_ITEM_SQ))
# # ]
9179 : 0 : return rte_flow_error_set(error, EINVAL,
9180 : : RTE_FLOW_ERROR_TYPE_ITEM,
9181 : : NULL,
9182 : : "NIC egress rules on representors"
9183 : : " is not supported");
9184 : : return 0;
9185 : : }
9186 : :
9187 : : /**
9188 : : * Internal preparation function. Allocates the DV flow size,
9189 : : * this size is constant.
9190 : : *
9191 : : * @param[in] dev
9192 : : * Pointer to the rte_eth_dev structure.
9193 : : * @param[in] attr
9194 : : * Pointer to the flow attributes.
9195 : : * @param[in] items
9196 : : * Pointer to the list of items.
9197 : : * @param[in] actions
9198 : : * Pointer to the list of actions.
9199 : : * @param[out] error
9200 : : * Pointer to the error structure.
9201 : : *
9202 : : * @return
9203 : : * Pointer to mlx5_flow object on success,
9204 : : * otherwise NULL and rte_errno is set.
9205 : : */
9206 : : static struct mlx5_flow *
9207 : 0 : flow_dv_prepare(struct rte_eth_dev *dev,
9208 : : const struct rte_flow_attr *attr __rte_unused,
9209 : : const struct rte_flow_item items[] __rte_unused,
9210 : : const struct rte_flow_action actions[] __rte_unused,
9211 : : struct rte_flow_error *error)
9212 : : {
9213 : 0 : uint32_t handle_idx = 0;
9214 : : struct mlx5_flow *dev_flow;
9215 : : struct mlx5_flow_handle *dev_handle;
9216 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
9217 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
9218 : :
9219 : : MLX5_ASSERT(wks);
9220 : 0 : wks->skip_matcher_reg = 0;
9221 : 0 : wks->policy = NULL;
9222 : 0 : wks->final_policy = NULL;
9223 : 0 : wks->vport_meta_tag = 0;
9224 : : /* In case of corrupting the memory. */
9225 [ # # ]: 0 : if (wks->flow_idx >= MLX5_NUM_MAX_DEV_FLOWS) {
9226 : 0 : rte_flow_error_set(error, ENOSPC,
9227 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9228 : : "not free temporary device flow");
9229 : 0 : return NULL;
9230 : : }
9231 : 0 : dev_handle = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
9232 : : &handle_idx);
9233 [ # # ]: 0 : if (!dev_handle) {
9234 : 0 : rte_flow_error_set(error, ENOMEM,
9235 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9236 : : "not enough memory to create flow handle");
9237 : 0 : return NULL;
9238 : : }
9239 : : MLX5_ASSERT(wks->flow_idx < RTE_DIM(wks->flows));
9240 : 0 : dev_flow = &wks->flows[wks->flow_idx++];
9241 : : memset(dev_flow, 0, sizeof(*dev_flow));
9242 : 0 : dev_flow->handle = dev_handle;
9243 : 0 : dev_flow->handle_idx = handle_idx;
9244 : 0 : dev_flow->dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param);
9245 : 0 : dev_flow->ingress = attr->ingress;
9246 : 0 : dev_flow->dv.transfer = attr->transfer;
9247 : 0 : return dev_flow;
9248 : : }
9249 : :
9250 : : #ifdef RTE_PMD_MLX5_DEBUG
9251 : : /**
9252 : : * Sanity check for match mask and value. Similar to check_valid_spec() in
9253 : : * kernel driver. If unmasked bit is present in value, it returns failure.
9254 : : *
9255 : : * @param match_mask
9256 : : * pointer to match mask buffer.
9257 : : * @param match_value
9258 : : * pointer to match value buffer.
9259 : : *
9260 : : * @return
9261 : : * 0 if valid, -EINVAL otherwise.
9262 : : */
9263 : : static int
9264 : : flow_dv_check_valid_spec(void *match_mask, void *match_value)
9265 : : {
9266 : : uint8_t *m = match_mask;
9267 : : uint8_t *v = match_value;
9268 : : unsigned int i;
9269 : :
9270 : : for (i = 0; i < MLX5_ST_SZ_BYTES(fte_match_param); ++i) {
9271 : : if (v[i] & ~m[i]) {
9272 : : DRV_LOG(ERR,
9273 : : "match_value differs from match_criteria"
9274 : : " %p[%u] != %p[%u]",
9275 : : match_value, i, match_mask, i);
9276 : : return -EINVAL;
9277 : : }
9278 : : }
9279 : : return 0;
9280 : : }
9281 : : #endif
9282 : :
9283 : : /**
9284 : : * Add match of ip_version.
9285 : : *
9286 : : * @param[in] group
9287 : : * Flow group.
9288 : : * @param[in] headers_v
9289 : : * Values header pointer.
9290 : : * @param[in] headers_m
9291 : : * Masks header pointer.
9292 : : * @param[in] ip_version
9293 : : * The IP version to set.
9294 : : */
9295 : : static inline void
9296 : 0 : flow_dv_set_match_ip_version(uint32_t group,
9297 : : void *headers_v,
9298 : : uint32_t key_type,
9299 : : uint8_t ip_version)
9300 : : {
9301 [ # # # # ]: 0 : if (group == 0 && (key_type & MLX5_SET_MATCHER_M))
9302 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version, 0xf);
9303 : : else
9304 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version,
9305 : : ip_version);
9306 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype, 0);
9307 : 0 : }
9308 : :
9309 : : /**
9310 : : * Add Ethernet item to the value.
9311 : : *
9312 : : * @param[in, out] key
9313 : : * Flow matcher value.
9314 : : * @param[in] item
9315 : : * Flow pattern to translate.
9316 : : * @param[in] inner
9317 : : * Item is inner pattern.
9318 : : * @param[in] grpup
9319 : : * Flow matcher group.
9320 : : * @param[in] key_type
9321 : : * Set flow matcher mask or value.
9322 : : */
9323 : : static void
9324 : 0 : flow_dv_translate_item_eth(void *key, const struct rte_flow_item *item,
9325 : : int inner, uint32_t group, uint32_t key_type)
9326 : : {
9327 : 0 : const struct rte_flow_item_eth *eth_vv = item->spec;
9328 : : const struct rte_flow_item_eth *eth_m;
9329 : : const struct rte_flow_item_eth *eth_v;
9330 : 0 : const struct rte_flow_item_eth nic_mask = {
9331 : : .hdr.dst_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
9332 : : .hdr.src_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
9333 : : .hdr.ether_type = RTE_BE16(0xffff),
9334 : : .has_vlan = 0,
9335 : : };
9336 : : void *hdrs_v;
9337 : : char *l24_v;
9338 : : unsigned int i;
9339 : :
9340 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9341 : 0 : return;
9342 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, eth_v, eth_m, &nic_mask);
# # # # ]
9343 [ # # ]: 0 : if (!eth_vv)
9344 : : eth_vv = eth_v;
9345 [ # # ]: 0 : if (inner)
9346 : 0 : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9347 : : else
9348 : : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9349 : : /* The value must be in the range of the mask. */
9350 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, dmac_47_16);
9351 [ # # ]: 0 : for (i = 0; i < sizeof(eth_m->hdr.dst_addr); ++i)
9352 : 0 : l24_v[i] = eth_m->hdr.dst_addr.addr_bytes[i] & eth_v->hdr.dst_addr.addr_bytes[i];
9353 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, smac_47_16);
9354 : : /* The value must be in the range of the mask. */
9355 [ # # ]: 0 : for (i = 0; i < sizeof(eth_m->hdr.dst_addr); ++i)
9356 : 0 : l24_v[i] = eth_m->hdr.src_addr.addr_bytes[i] & eth_v->hdr.src_addr.addr_bytes[i];
9357 : : /*
9358 : : * HW supports match on one Ethertype, the Ethertype following the last
9359 : : * VLAN tag of the packet (see PRM).
9360 : : * Set match on ethertype only if ETH header is not followed by VLAN.
9361 : : * HW is optimized for IPv4/IPv6. In such cases, avoid setting
9362 : : * ethertype, and use ip_version field instead.
9363 : : * eCPRI over Ether layer will use type value 0xAEFE.
9364 : : */
9365 [ # # ]: 0 : if (eth_m->hdr.ether_type == 0xFFFF) {
9366 : 0 : rte_be16_t type = eth_v->hdr.ether_type;
9367 : :
9368 : : /*
9369 : : * When set the matcher mask, refer to the original spec
9370 : : * value.
9371 : : */
9372 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M) {
9373 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
9374 : 0 : type = eth_vv->hdr.ether_type;
9375 : : }
9376 : : /* Set cvlan_tag mask for any single\multi\un-tagged case. */
9377 [ # # # # : 0 : switch (type) {
# ]
9378 : 0 : case RTE_BE16(RTE_ETHER_TYPE_VLAN):
9379 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
9380 : 0 : return;
9381 : 0 : case RTE_BE16(RTE_ETHER_TYPE_QINQ):
9382 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
9383 : 0 : return;
9384 : 0 : case RTE_BE16(RTE_ETHER_TYPE_IPV4):
9385 : 0 : flow_dv_set_match_ip_version(group, hdrs_v, key_type,
9386 : : 4);
9387 : 0 : return;
9388 : 0 : case RTE_BE16(RTE_ETHER_TYPE_IPV6):
9389 : 0 : flow_dv_set_match_ip_version(group, hdrs_v, key_type,
9390 : : 6);
9391 : 0 : return;
9392 : : default:
9393 : : break;
9394 : : }
9395 : : }
9396 : : /*
9397 : : * Only SW steering value should refer to the mask value.
9398 : : * Other cases are using the fake masks, just ignore the mask.
9399 : : */
9400 [ # # # # ]: 0 : if (eth_v->has_vlan && eth_m->has_vlan) {
9401 : : /*
9402 : : * Here, when also has_more_vlan field in VLAN item is
9403 : : * not set, only single-tagged packets will be matched.
9404 : : */
9405 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
9406 [ # # # # ]: 0 : if (key_type != MLX5_SET_MATCHER_HS_M && eth_vv->has_vlan)
9407 : : return;
9408 : : }
9409 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, ethertype);
9410 : 0 : *(uint16_t *)(l24_v) = eth_m->hdr.ether_type & eth_v->hdr.ether_type;
9411 : : }
9412 : :
9413 : : /**
9414 : : * Add VLAN item to the value.
9415 : : *
9416 : : * @param[in, out] key
9417 : : * Flow matcher value.
9418 : : * @param[in] item
9419 : : * Flow pattern to translate.
9420 : : * @param[in] inner
9421 : : * Item is inner pattern.
9422 : : * @param[in] wks
9423 : : * Item workspace.
9424 : : * @param[in] key_type
9425 : : * Set flow matcher mask or value.
9426 : : */
9427 : : static void
9428 : 0 : flow_dv_translate_item_vlan(void *key, const struct rte_flow_item *item,
9429 : : int inner, struct mlx5_dv_matcher_workspace *wks,
9430 : : uint32_t key_type)
9431 : : {
9432 : : const struct rte_flow_item_vlan *vlan_m;
9433 : : const struct rte_flow_item_vlan *vlan_v;
9434 : 0 : const struct rte_flow_item_vlan *vlan_vv = item->spec;
9435 : : void *hdrs_v;
9436 : : uint16_t tci_v;
9437 : :
9438 [ # # ]: 0 : if (inner) {
9439 : 0 : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9440 : : } else {
9441 : : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9442 : : /*
9443 : : * This is workaround, masks are not supported,
9444 : : * and pre-validated.
9445 : : */
9446 [ # # ]: 0 : if (vlan_vv)
9447 [ # # ]: 0 : wks->vlan_tag = rte_be_to_cpu_16(vlan_vv->hdr.vlan_tci) & 0x0fff;
9448 : : }
9449 : : /*
9450 : : * When VLAN item exists in flow, mark packet as tagged,
9451 : : * even if TCI is not specified.
9452 : : */
9453 [ # # # # ]: 0 : if (!MLX5_GET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag))
9454 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
9455 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9456 : : return;
9457 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, vlan_v, vlan_m,
# # # # ]
9458 : : &rte_flow_item_vlan_mask);
9459 [ # # ]: 0 : tci_v = rte_be_to_cpu_16(vlan_m->hdr.vlan_tci & vlan_v->hdr.vlan_tci);
9460 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_vid, tci_v);
9461 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_cfi, tci_v >> 12);
9462 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_prio, tci_v >> 13);
9463 : : /*
9464 : : * HW is optimized for IPv4/IPv6. In such cases, avoid setting
9465 : : * ethertype, and use ip_version field instead.
9466 : : */
9467 [ # # ]: 0 : if (vlan_m->hdr.eth_proto == 0xFFFF) {
9468 : 0 : rte_be16_t inner_type = vlan_v->hdr.eth_proto;
9469 : :
9470 : : /*
9471 : : * When set the matcher mask, refer to the original spec
9472 : : * value.
9473 : : */
9474 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M)
9475 : 0 : inner_type = vlan_vv->hdr.eth_proto;
9476 [ # # # # ]: 0 : switch (inner_type) {
9477 : 0 : case RTE_BE16(RTE_ETHER_TYPE_VLAN):
9478 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
9479 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_V)
9480 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v,
9481 : : cvlan_tag, 0);
9482 : 0 : return;
9483 : 0 : case RTE_BE16(RTE_ETHER_TYPE_IPV4):
9484 : 0 : flow_dv_set_match_ip_version
9485 : : (wks->group, hdrs_v, key_type, 4);
9486 : 0 : return;
9487 : 0 : case RTE_BE16(RTE_ETHER_TYPE_IPV6):
9488 : 0 : flow_dv_set_match_ip_version
9489 : : (wks->group, hdrs_v, key_type, 6);
9490 : 0 : return;
9491 : : default:
9492 : : break;
9493 : : }
9494 : : }
9495 [ # # # # ]: 0 : if (vlan_m->has_more_vlan && vlan_v->has_more_vlan) {
9496 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
9497 : : /* Only one vlan_tag bit can be set. */
9498 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_V)
9499 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 0);
9500 : 0 : return;
9501 : : }
9502 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, ethertype,
9503 : : rte_be_to_cpu_16(vlan_m->hdr.eth_proto & vlan_v->hdr.eth_proto));
9504 : : }
9505 : :
9506 : : /**
9507 : : * Add IPV4 item to the value.
9508 : : *
9509 : : * @param[in, out] key
9510 : : * Flow matcher value.
9511 : : * @param[in] item
9512 : : * Flow pattern to translate.
9513 : : * @param[in] inner
9514 : : * Item is inner pattern.
9515 : : * @param[in] group
9516 : : * The group to insert the rule.
9517 : : * @param[in] key_type
9518 : : * Set flow matcher mask or value.
9519 : : */
9520 : : static void
9521 : 0 : flow_dv_translate_item_ipv4(void *key, const struct rte_flow_item *item,
9522 : : int inner, uint32_t group, uint32_t key_type)
9523 : : {
9524 : : const struct rte_flow_item_ipv4 *ipv4_m;
9525 : : const struct rte_flow_item_ipv4 *ipv4_v;
9526 : 0 : const struct rte_flow_item_ipv4 nic_mask = {
9527 : : .hdr = {
9528 : : .src_addr = RTE_BE32(0xffffffff),
9529 : : .dst_addr = RTE_BE32(0xffffffff),
9530 : : .type_of_service = 0xff,
9531 : : .next_proto_id = 0xff,
9532 : : .time_to_live = 0xff,
9533 : : },
9534 : : };
9535 : : void *headers_v;
9536 : : char *l24_v;
9537 : : uint8_t tos;
9538 : :
9539 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9540 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9541 : 0 : flow_dv_set_match_ip_version(group, headers_v, key_type, 4);
9542 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9543 : 0 : return;
9544 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, ipv4_v, ipv4_m, &nic_mask);
# # # # ]
9545 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
9546 : : dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
9547 : 0 : *(uint32_t *)l24_v = ipv4_m->hdr.dst_addr & ipv4_v->hdr.dst_addr;
9548 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
9549 : : src_ipv4_src_ipv6.ipv4_layout.ipv4);
9550 : 0 : *(uint32_t *)l24_v = ipv4_m->hdr.src_addr & ipv4_v->hdr.src_addr;
9551 : 0 : tos = ipv4_m->hdr.type_of_service & ipv4_v->hdr.type_of_service;
9552 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ipv4_ihl,
9553 : : ipv4_v->hdr.ihl & ipv4_m->hdr.ihl);
9554 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M)
9555 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn,
9556 : : ipv4_v->hdr.type_of_service);
9557 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, tos);
9558 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, tos >> 2);
9559 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
9560 : : ipv4_v->hdr.next_proto_id & ipv4_m->hdr.next_proto_id);
9561 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
9562 : : ipv4_v->hdr.time_to_live & ipv4_m->hdr.time_to_live);
9563 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
9564 : : !!(ipv4_v->hdr.fragment_offset & ipv4_m->hdr.fragment_offset));
9565 : : }
9566 : :
9567 : : /**
9568 : : * Add IPV6 item to the value.
9569 : : *
9570 : : * @param[in, out] key
9571 : : * Flow matcher value.
9572 : : * @param[in] item
9573 : : * Flow pattern to translate.
9574 : : * @param[in] inner
9575 : : * Item is inner pattern.
9576 : : * @param[in] group
9577 : : * The group to insert the rule.
9578 : : * @param[in] key_type
9579 : : * Set flow matcher mask or value.
9580 : : */
9581 : : static void
9582 : 0 : flow_dv_translate_item_ipv6(void *key, const struct rte_flow_item *item,
9583 : : int inner, uint32_t group, uint32_t key_type)
9584 : : {
9585 : : const struct rte_flow_item_ipv6 *ipv6_m;
9586 : : const struct rte_flow_item_ipv6 *ipv6_v;
9587 : 0 : const struct rte_flow_item_ipv6 nic_mask = {
9588 : : .hdr = {
9589 : : .src_addr = RTE_IPV6_MASK_FULL,
9590 : : .dst_addr = RTE_IPV6_MASK_FULL,
9591 : : .vtc_flow = RTE_BE32(0xffffffff),
9592 : : .proto = 0xff,
9593 : : .hop_limits = 0xff,
9594 : : },
9595 : : };
9596 : : void *headers_v;
9597 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9598 : : char *l24_v;
9599 : : uint32_t vtc_v;
9600 : : int i;
9601 : : int size;
9602 : :
9603 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9604 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9605 : 0 : flow_dv_set_match_ip_version(group, headers_v, key_type, 6);
9606 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9607 : 0 : return;
9608 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, ipv6_v, ipv6_m, &nic_mask);
# # # # ]
9609 : : size = sizeof(ipv6_m->hdr.dst_addr);
9610 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
9611 : : dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
9612 [ # # ]: 0 : for (i = 0; i < size; ++i)
9613 : 0 : l24_v[i] = ipv6_m->hdr.dst_addr.a[i] & ipv6_v->hdr.dst_addr.a[i];
9614 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
9615 : : src_ipv4_src_ipv6.ipv6_layout.ipv6);
9616 [ # # ]: 0 : for (i = 0; i < size; ++i)
9617 : 0 : l24_v[i] = ipv6_m->hdr.src_addr.a[i] & ipv6_v->hdr.src_addr.a[i];
9618 : : /* TOS. */
9619 [ # # ]: 0 : vtc_v = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow & ipv6_v->hdr.vtc_flow);
9620 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, vtc_v >> 20);
9621 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, vtc_v >> 22);
9622 : : /* Label. */
9623 [ # # ]: 0 : if (inner)
9624 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, inner_ipv6_flow_label,
9625 : : vtc_v);
9626 : : else
9627 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, outer_ipv6_flow_label,
9628 : : vtc_v);
9629 : : /* Protocol. */
9630 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
9631 : : ipv6_v->hdr.proto & ipv6_m->hdr.proto);
9632 : : /* Hop limit. */
9633 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
9634 : : ipv6_v->hdr.hop_limits & ipv6_m->hdr.hop_limits);
9635 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
9636 : : !!(ipv6_v->has_frag_ext & ipv6_m->has_frag_ext));
9637 : : }
9638 : :
9639 : : /**
9640 : : * Add IPV6 fragment extension item to the value.
9641 : : *
9642 : : * @param[in, out] key
9643 : : * Flow matcher value.
9644 : : * @param[in] item
9645 : : * Flow pattern to translate.
9646 : : * @param[in] inner
9647 : : * Item is inner pattern.
9648 : : * @param[in] key_type
9649 : : * Set flow matcher mask or value.
9650 : : */
9651 : : static void
9652 : 0 : flow_dv_translate_item_ipv6_frag_ext(void *key,
9653 : : const struct rte_flow_item *item,
9654 : : int inner, uint32_t key_type)
9655 : : {
9656 : : const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_m;
9657 : : const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_v;
9658 : 0 : const struct rte_flow_item_ipv6_frag_ext nic_mask = {
9659 : : .hdr = {
9660 : : .next_header = 0xff,
9661 : : .frag_data = RTE_BE16(0xffff),
9662 : : },
9663 : : };
9664 : : void *headers_v;
9665 : :
9666 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9667 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9668 : : /* IPv6 fragment extension item exists, so packet is IP fragment. */
9669 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag, 1);
9670 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9671 : 0 : return;
9672 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, ipv6_frag_ext_v,
# # # # ]
9673 : : ipv6_frag_ext_m, &nic_mask);
9674 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
9675 : : ipv6_frag_ext_v->hdr.next_header &
9676 : : ipv6_frag_ext_m->hdr.next_header);
9677 : : }
9678 : :
9679 : : /**
9680 : : * Add TCP item to the value.
9681 : : *
9682 : : * @param[in, out] key
9683 : : * Flow matcher value.
9684 : : * @param[in] item
9685 : : * Flow pattern to translate.
9686 : : * @param[in] inner
9687 : : * Item is inner pattern.
9688 : : * @param[in] key_type
9689 : : * Set flow matcher mask or value.
9690 : : */
9691 : : static void
9692 : 0 : flow_dv_translate_item_tcp(void *key, const struct rte_flow_item *item,
9693 : : int inner, uint32_t key_type)
9694 : : {
9695 : : const struct rte_flow_item_tcp *tcp_m;
9696 : : const struct rte_flow_item_tcp *tcp_v;
9697 : : void *headers_v;
9698 : :
9699 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9700 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9701 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9702 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9703 : : ip_protocol, 0xff);
9704 : : else
9705 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9706 : : ip_protocol, IPPROTO_TCP);
9707 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9708 : : return;
9709 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, tcp_v, tcp_m,
# # # # ]
9710 : : &rte_flow_item_tcp_mask);
9711 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_sport,
9712 : : rte_be_to_cpu_16(tcp_v->hdr.src_port & tcp_m->hdr.src_port));
9713 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_dport,
9714 : : rte_be_to_cpu_16(tcp_v->hdr.dst_port & tcp_m->hdr.dst_port));
9715 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_flags,
9716 : : tcp_v->hdr.tcp_flags & tcp_m->hdr.tcp_flags);
9717 : : }
9718 : :
9719 : : /**
9720 : : * Add ESP item to the value.
9721 : : *
9722 : : * @param[in, out] key
9723 : : * Flow matcher value.
9724 : : * @param[in] item
9725 : : * Flow pattern to translate.
9726 : : * @param[in] inner
9727 : : * Item is inner pattern.
9728 : : * @param[in] key_type
9729 : : * Set flow matcher mask or value.
9730 : : */
9731 : : static void
9732 : 0 : flow_dv_translate_item_esp(void *key, const struct rte_flow_item *item,
9733 : : int inner, uint32_t key_type, uint64_t item_flags)
9734 : : {
9735 : : const struct rte_flow_item_esp *esp_m;
9736 : : const struct rte_flow_item_esp *esp_v;
9737 : : void *headers_v;
9738 : : char *spi_v;
9739 [ # # ]: 0 : bool over_udp = item_flags & (inner ? MLX5_FLOW_LAYER_INNER_L4_UDP :
9740 : : MLX5_FLOW_LAYER_OUTER_L4_UDP);
9741 : :
9742 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9743 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9744 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
9745 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, 0xff);
9746 [ # # # # : 0 : if (over_udp && !MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport))
# # ]
9747 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, 0xFFFF);
9748 : : } else {
9749 [ # # ]: 0 : if (!over_udp)
9750 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ESP);
9751 : : else
9752 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport))
9753 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
9754 : : MLX5_UDP_PORT_ESP);
9755 : : }
9756 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9757 : : return;
9758 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, esp_v, esp_m, &rte_flow_item_esp_mask);
# # # # ]
9759 : : headers_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9760 [ # # ]: 0 : spi_v = inner ? MLX5_ADDR_OF(fte_match_set_misc, headers_v, inner_esp_spi) :
9761 : : MLX5_ADDR_OF(fte_match_set_misc, headers_v, outer_esp_spi);
9762 : 0 : *(uint32_t *)spi_v = esp_m->hdr.spi & esp_v->hdr.spi;
9763 : : }
9764 : :
9765 : : /**
9766 : : * Add UDP item to the value.
9767 : : *
9768 : : * @param[in, out] key
9769 : : * Flow matcher value.
9770 : : * @param[in] item
9771 : : * Flow pattern to translate.
9772 : : * @param[in] inner
9773 : : * Item is inner pattern.
9774 : : * @param[in] key_type
9775 : : * Set flow matcher mask or value.
9776 : : */
9777 : : static void
9778 : 0 : flow_dv_translate_item_udp(void *key, const struct rte_flow_item *item,
9779 : : int inner, struct mlx5_dv_matcher_workspace *wks,
9780 : : uint32_t key_type)
9781 : : {
9782 : : const struct rte_flow_item_udp *udp_m;
9783 : : const struct rte_flow_item_udp *udp_v;
9784 : : void *headers_v;
9785 : :
9786 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9787 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9788 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9789 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9790 : : ip_protocol, 0xff);
9791 : : else
9792 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9793 : : ip_protocol, IPPROTO_UDP);
9794 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9795 : : return;
9796 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, udp_v, udp_m,
# # # # ]
9797 : : &rte_flow_item_udp_mask);
9798 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_sport,
9799 : : rte_be_to_cpu_16(udp_v->hdr.src_port & udp_m->hdr.src_port));
9800 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
9801 : : rte_be_to_cpu_16(udp_v->hdr.dst_port & udp_m->hdr.dst_port));
9802 : : /* Force get UDP dport in case to be used in VXLAN translate. */
9803 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_SW) {
9804 : 0 : udp_v = item->spec;
9805 [ # # ]: 0 : wks->udp_dport = rte_be_to_cpu_16(udp_v->hdr.dst_port &
9806 : : udp_m->hdr.dst_port);
9807 : : }
9808 : : }
9809 : :
9810 : : /**
9811 : : * Add GRE optional Key item to the value.
9812 : : *
9813 : : * @param[in, out] key
9814 : : * Flow matcher value.
9815 : : * @param[in] item
9816 : : * Flow pattern to translate.
9817 : : * @param[in] inner
9818 : : * Item is inner pattern.
9819 : : */
9820 : : static void
9821 : 0 : flow_dv_translate_item_gre_key(void *key, const struct rte_flow_item *item,
9822 : : uint32_t key_type)
9823 : : {
9824 : : const rte_be32_t *key_m;
9825 : : const rte_be32_t *key_v;
9826 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9827 : 0 : rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
9828 : :
9829 : : /* GRE K bit must be on and should already be validated */
9830 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_k_present, 1);
9831 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9832 : 0 : return;
9833 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, key_v, key_m,
# # # # ]
9834 : : &gre_key_default_mask);
9835 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_key_h,
9836 : : rte_be_to_cpu_32((*key_v) & (*key_m)) >> 8);
9837 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_key_l,
9838 : : rte_be_to_cpu_32((*key_v) & (*key_m)) & 0xFF);
9839 : : }
9840 : :
9841 : : /**
9842 : : * Add GRE item to the value.
9843 : : *
9844 : : * @param[in, out] key
9845 : : * Flow matcher value.
9846 : : * @param[in] item
9847 : : * Flow pattern to translate.
9848 : : * @param[in] pattern_flags
9849 : : * Accumulated pattern flags.
9850 : : * @param[in] key_type
9851 : : * Set flow matcher mask or value.
9852 : : */
9853 : : static void
9854 : 0 : flow_dv_translate_item_gre(void *key, const struct rte_flow_item *item,
9855 : : uint64_t pattern_flags, uint32_t key_type)
9856 : : {
9857 : : static const struct rte_flow_item_gre empty_gre = {0,};
9858 : 0 : const struct rte_flow_item_gre *gre_m = item->mask;
9859 : 0 : const struct rte_flow_item_gre *gre_v = item->spec;
9860 : : void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9861 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9862 : : struct {
9863 : : union {
9864 : : __extension__
9865 : : struct {
9866 : : uint16_t version:3;
9867 : : uint16_t rsvd0:9;
9868 : : uint16_t s_present:1;
9869 : : uint16_t k_present:1;
9870 : : uint16_t rsvd_bit1:1;
9871 : : uint16_t c_present:1;
9872 : : };
9873 : : uint16_t value;
9874 : : };
9875 : : } gre_crks_rsvd0_ver_m, gre_crks_rsvd0_ver_v;
9876 : : uint16_t protocol_m, protocol_v;
9877 : :
9878 : : /* Common logic to SWS/HWS */
9879 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9880 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, 0xff);
9881 : : else
9882 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
9883 : : IPPROTO_GRE);
9884 : : /* HWS mask logic only */
9885 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_HS_M) {
9886 [ # # ]: 0 : if (!gre_m)
9887 : : gre_m = &empty_gre;
9888 : : gre_v = gre_m;
9889 [ # # ]: 0 : } else if (!gre_v) {
9890 : : gre_v = &empty_gre;
9891 : : gre_m = &empty_gre;
9892 [ # # ]: 0 : } else if (!gre_m) {
9893 : : gre_m = &rte_flow_item_gre_mask;
9894 : : }
9895 : : /* SWS logic only */
9896 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_SW_M)
9897 : : gre_v = gre_m;
9898 [ # # ]: 0 : gre_crks_rsvd0_ver_m.value = rte_be_to_cpu_16(gre_m->c_rsvd0_ver);
9899 [ # # ]: 0 : gre_crks_rsvd0_ver_v.value = rte_be_to_cpu_16(gre_v->c_rsvd0_ver);
9900 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_c_present,
9901 : : gre_crks_rsvd0_ver_v.c_present &
9902 : : gre_crks_rsvd0_ver_m.c_present);
9903 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_k_present,
9904 : : gre_crks_rsvd0_ver_v.k_present &
9905 : : gre_crks_rsvd0_ver_m.k_present);
9906 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_s_present,
9907 : : gre_crks_rsvd0_ver_v.s_present &
9908 : : gre_crks_rsvd0_ver_m.s_present);
9909 [ # # ]: 0 : protocol_m = rte_be_to_cpu_16(gre_m->protocol);
9910 [ # # ]: 0 : protocol_v = rte_be_to_cpu_16(gre_v->protocol);
9911 [ # # ]: 0 : if (!protocol_m) {
9912 : : /* Force next protocol to prevent matchers duplication */
9913 : : protocol_v = mlx5_translate_tunnel_etypes(pattern_flags);
9914 : : if (protocol_v)
9915 : : protocol_m = 0xFFFF;
9916 : : /* Restore the value to mask in mask case. */
9917 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9918 : : protocol_v = protocol_m;
9919 : : }
9920 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
9921 : : protocol_m & protocol_v);
9922 : 0 : }
9923 : :
9924 : : /**
9925 : : * Add GRE optional items to the value.
9926 : : *
9927 : : * @param[in, out] key
9928 : : * Flow matcher value.
9929 : : * @param[in] item
9930 : : * Flow pattern to translate.
9931 : : * @param[in] gre_item
9932 : : * Pointer to gre_item.
9933 : : * @param[in] pattern_flags
9934 : : * Accumulated pattern flags.
9935 : : * @param[in] key_type
9936 : : * Set flow matcher mask or value.
9937 : : */
9938 : : static void
9939 : 0 : flow_dv_translate_item_gre_option(void *key,
9940 : : const struct rte_flow_item *item,
9941 : : const struct rte_flow_item *gre_item,
9942 : : uint64_t pattern_flags, uint32_t key_type)
9943 : : {
9944 : : void *misc5_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_5);
9945 : 0 : const struct rte_flow_item_gre_opt *option_m = item->mask;
9946 : 0 : const struct rte_flow_item_gre_opt *option_v = item->spec;
9947 : 0 : const struct rte_flow_item_gre *gre_m = gre_item->mask;
9948 : 0 : const struct rte_flow_item_gre *gre_v = gre_item->spec;
9949 : : static const struct rte_flow_item_gre empty_gre = {0};
9950 : : struct rte_flow_item gre_key_item;
9951 : : uint16_t c_rsvd0_ver_m, c_rsvd0_ver_v;
9952 : : uint16_t protocol_m, protocol_v;
9953 : :
9954 : : /*
9955 : : * If only match key field, keep using misc for matching.
9956 : : * If need to match checksum or sequence, using misc5 and do
9957 : : * not need using misc.
9958 : : */
9959 [ # # ]: 0 : if (!(option_m->sequence.sequence ||
9960 [ # # ]: 0 : option_m->checksum_rsvd.checksum)) {
9961 : 0 : flow_dv_translate_item_gre(key, gre_item, pattern_flags, key_type);
9962 : 0 : gre_key_item.spec = &option_v->key.key;
9963 : 0 : gre_key_item.mask = &option_m->key.key;
9964 : 0 : flow_dv_translate_item_gre_key(key, &gre_key_item, key_type);
9965 : 0 : return;
9966 : : }
9967 [ # # ]: 0 : if (!gre_v) {
9968 : : gre_v = &empty_gre;
9969 : : gre_m = &empty_gre;
9970 : : } else {
9971 [ # # ]: 0 : if (!gre_m)
9972 : : gre_m = &rte_flow_item_gre_mask;
9973 : : }
9974 : 0 : protocol_v = gre_v->protocol;
9975 : 0 : protocol_m = gre_m->protocol;
9976 [ # # ]: 0 : if (!protocol_m) {
9977 : : /* Force next protocol to prevent matchers duplication */
9978 : : uint16_t ether_type =
9979 : : mlx5_translate_tunnel_etypes(pattern_flags);
9980 : : if (ether_type) {
9981 [ # # ]: 0 : protocol_v = rte_be_to_cpu_16(ether_type);
9982 : : protocol_m = UINT16_MAX;
9983 : : }
9984 : : }
9985 : 0 : c_rsvd0_ver_v = gre_v->c_rsvd0_ver;
9986 : 0 : c_rsvd0_ver_m = gre_m->c_rsvd0_ver;
9987 [ # # ]: 0 : if (option_m->sequence.sequence) {
9988 : 0 : c_rsvd0_ver_v |= RTE_BE16(0x1000);
9989 : 0 : c_rsvd0_ver_m |= RTE_BE16(0x1000);
9990 : : }
9991 [ # # ]: 0 : if (option_m->key.key) {
9992 : 0 : c_rsvd0_ver_v |= RTE_BE16(0x2000);
9993 : 0 : c_rsvd0_ver_m |= RTE_BE16(0x2000);
9994 : : }
9995 [ # # ]: 0 : if (option_m->checksum_rsvd.checksum) {
9996 : 0 : c_rsvd0_ver_v |= RTE_BE16(0x8000);
9997 : 0 : c_rsvd0_ver_m |= RTE_BE16(0x8000);
9998 : : }
9999 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
10000 : : c_rsvd0_ver_v = c_rsvd0_ver_m;
10001 : : protocol_v = protocol_m;
10002 : : option_v = option_m;
10003 : : }
10004 : : /*
10005 : : * Hardware parses GRE optional field into the fixed location,
10006 : : * do not need to adjust the tunnel dword indices.
10007 : : */
10008 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_0,
10009 : : rte_be_to_cpu_32((c_rsvd0_ver_v | protocol_v << 16) &
10010 : : (c_rsvd0_ver_m | protocol_m << 16)));
10011 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_1,
10012 : : rte_be_to_cpu_32(option_v->checksum_rsvd.checksum &
10013 : : option_m->checksum_rsvd.checksum));
10014 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_2,
10015 : : rte_be_to_cpu_32(option_v->key.key & option_m->key.key));
10016 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_3,
10017 : : rte_be_to_cpu_32(option_v->sequence.sequence &
10018 : : option_m->sequence.sequence));
10019 : : }
10020 : :
10021 : : /**
10022 : : * Add NVGRE item to matcher and to the value.
10023 : : *
10024 : : * @param[in, out] key
10025 : : * Flow matcher value.
10026 : : * @param[in] item
10027 : : * Flow pattern to translate.
10028 : : * @param[in] pattern_flags
10029 : : * Accumulated pattern flags.
10030 : : * @param[in] key_type
10031 : : * Set flow matcher mask or value.
10032 : : */
10033 : : static void
10034 : 0 : flow_dv_translate_item_nvgre(void *key, const struct rte_flow_item *item,
10035 : : unsigned long pattern_flags, uint32_t key_type)
10036 : : {
10037 : : const struct rte_flow_item_nvgre *nvgre_m;
10038 : : const struct rte_flow_item_nvgre *nvgre_v;
10039 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10040 : : const char *tni_flow_id_m;
10041 : : const char *tni_flow_id_v;
10042 : : char *gre_key_v;
10043 : : int size;
10044 : : int i;
10045 : :
10046 : : /* For NVGRE, GRE header fields must be set with defined values. */
10047 : 0 : const struct rte_flow_item_gre gre_spec = {
10048 : : .c_rsvd0_ver = RTE_BE16(0x2000),
10049 : : .protocol = RTE_BE16(RTE_ETHER_TYPE_TEB)
10050 : : };
10051 : 0 : const struct rte_flow_item_gre gre_mask = {
10052 : : .c_rsvd0_ver = RTE_BE16(0xB000),
10053 : : .protocol = RTE_BE16(UINT16_MAX),
10054 : : };
10055 : 0 : const struct rte_flow_item gre_item = {
10056 : : .spec = &gre_spec,
10057 : : .mask = &gre_mask,
10058 : : .last = NULL,
10059 : : };
10060 : 0 : flow_dv_translate_item_gre(key, &gre_item, pattern_flags, key_type);
10061 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10062 : 0 : return;
10063 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, nvgre_v, nvgre_m,
# # # # ]
10064 : : &rte_flow_item_nvgre_mask);
10065 : 0 : tni_flow_id_m = (const char *)nvgre_m->tni;
10066 : 0 : tni_flow_id_v = (const char *)nvgre_v->tni;
10067 : : size = sizeof(nvgre_m->tni) + sizeof(nvgre_m->flow_id);
10068 : 0 : gre_key_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, gre_key_h);
10069 [ # # ]: 0 : for (i = 0; i < size; ++i)
10070 : 0 : gre_key_v[i] = tni_flow_id_m[i] & tni_flow_id_v[i];
10071 : : }
10072 : :
10073 : : /**
10074 : : * Add VXLAN item to the value.
10075 : : *
10076 : : * @param[in] dev
10077 : : * Pointer to the Ethernet device structure.
10078 : : * @param[in] attr
10079 : : * Flow rule attributes.
10080 : : * @param[in, out] key
10081 : : * Flow matcher value.
10082 : : * @param[in] item
10083 : : * Flow pattern to translate.
10084 : : * @param[in] inner
10085 : : * Item is inner pattern.
10086 : : * @param[in] wks
10087 : : * Matcher workspace.
10088 : : * @param[in] key_type
10089 : : * Set flow matcher mask or value.
10090 : : */
10091 : : static void
10092 : 0 : flow_dv_translate_item_vxlan(struct rte_eth_dev *dev,
10093 : : const struct rte_flow_attr *attr,
10094 : : void *key, const struct rte_flow_item *item,
10095 : : int inner, struct mlx5_dv_matcher_workspace *wks,
10096 : : uint32_t key_type)
10097 : : {
10098 : : const struct rte_flow_item_vxlan *vxlan_m;
10099 : : const struct rte_flow_item_vxlan *vxlan_v;
10100 : : void *headers_v;
10101 : : void *misc_v;
10102 : : void *misc5_v;
10103 : : uint32_t tunnel_v;
10104 : : char *vni_v;
10105 : : uint16_t dport;
10106 : : int size;
10107 : : int i;
10108 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10109 : 0 : const struct rte_flow_item_vxlan nic_mask = {
10110 : : .hdr.vni = { 0xff, 0xff, 0xff },
10111 : : .hdr.rsvd1 = 0xff,
10112 : : };
10113 : :
10114 : : misc5_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_5);
10115 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
10116 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10117 [ # # ]: 0 : dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
10118 : : MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
10119 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
10120 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10121 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
10122 : : udp_dport, 0xFFFF);
10123 : : else
10124 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
10125 : : udp_dport, dport);
10126 : : }
10127 : : /*
10128 : : * Read the UDP dport to check if the value satisfies the VXLAN
10129 : : * matching with MISC5 for CX5.
10130 : : */
10131 [ # # ]: 0 : if (wks->udp_dport)
10132 : : dport = wks->udp_dport;
10133 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10134 : 0 : return;
10135 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, vxlan_v, vxlan_m, &nic_mask);
# # # # ]
10136 : : if ((item->mask == &nic_mask) &&
10137 : : ((!attr->group && !(attr->transfer && priv->fdb_def_rule) &&
10138 : : !priv->sh->tunnel_header_0_1) ||
10139 : : ((attr->group || (attr->transfer && priv->fdb_def_rule)) &&
10140 : : !priv->sh->misc5_cap)))
10141 : : vxlan_m = &rte_flow_item_vxlan_mask;
10142 [ # # ]: 0 : if ((priv->sh->steering_format_version ==
10143 [ # # ]: 0 : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5 &&
10144 : 0 : dport != MLX5_UDP_PORT_VXLAN) ||
10145 [ # # # # : 0 : (!attr->group && !(attr->transfer && priv->fdb_def_rule)) ||
# # # # ]
10146 [ # # # # ]: 0 : ((attr->group || (attr->transfer && priv->fdb_def_rule)) &&
10147 [ # # ]: 0 : !priv->sh->misc5_cap)) {
10148 : : misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10149 : : size = sizeof(vxlan_m->hdr.vni);
10150 : 0 : vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, vxlan_vni);
10151 [ # # ]: 0 : for (i = 0; i < size; ++i)
10152 : 0 : vni_v[i] = vxlan_m->hdr.vni[i] & vxlan_v->hdr.vni[i];
10153 : : return;
10154 : : }
10155 : 0 : tunnel_v = (vxlan_v->hdr.vni[0] & vxlan_m->hdr.vni[0]) |
10156 : 0 : (vxlan_v->hdr.vni[1] & vxlan_m->hdr.vni[1]) << 8 |
10157 : 0 : (vxlan_v->hdr.vni[2] & vxlan_m->hdr.vni[2]) << 16;
10158 : 0 : tunnel_v |= (vxlan_v->hdr.rsvd1 & vxlan_m->hdr.rsvd1) << 24;
10159 [ # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_1, RTE_BE32(tunnel_v));
10160 : : }
10161 : :
10162 : : /**
10163 : : * Add VXLAN-GPE item to the value.
10164 : : *
10165 : : * @param[in, out] key
10166 : : * Flow matcher value.
10167 : : * @param[in] item
10168 : : * Flow pattern to translate.
10169 : : * @param[in] pattern_flags
10170 : : * Item pattern flags.
10171 : : * @param[in] key_type
10172 : : * Set flow matcher mask or value.
10173 : : */
10174 : :
10175 : : static void
10176 : 0 : flow_dv_translate_item_vxlan_gpe(void *key, const struct rte_flow_item *item,
10177 : : const uint64_t pattern_flags,
10178 : : uint32_t key_type)
10179 : : {
10180 : : static const struct rte_flow_item_vxlan_gpe dummy_vxlan_gpe_hdr = {{{0}}};
10181 : 0 : const struct rte_flow_item_vxlan_gpe *vxlan_m = item->mask;
10182 : 0 : const struct rte_flow_item_vxlan_gpe *vxlan_v = item->spec;
10183 : : /* The item was validated to be on the outer side */
10184 : : void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10185 : : void *misc_v =
10186 : : MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
10187 : 0 : char *vni_v =
10188 : : MLX5_ADDR_OF(fte_match_set_misc3, misc_v, outer_vxlan_gpe_vni);
10189 : : int i, size = sizeof(vxlan_m->hdr.vni);
10190 : : uint8_t flags_m = 0xff;
10191 : : uint8_t flags_v = 0xc;
10192 : : uint8_t m_protocol, v_protocol;
10193 : :
10194 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
10195 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10196 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
10197 : : 0xFFFF);
10198 : : else
10199 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
10200 : : MLX5_UDP_PORT_VXLAN_GPE);
10201 : : }
10202 [ # # ]: 0 : if (!vxlan_v) {
10203 : : vxlan_v = &dummy_vxlan_gpe_hdr;
10204 : : vxlan_m = &dummy_vxlan_gpe_hdr;
10205 : : } else {
10206 [ # # ]: 0 : if (!vxlan_m)
10207 : : vxlan_m = &rte_flow_item_vxlan_gpe_mask;
10208 : : }
10209 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10210 : : vxlan_v = vxlan_m;
10211 [ # # ]: 0 : else if (key_type == MLX5_SET_MATCHER_HS_V)
10212 : : vxlan_m = vxlan_v;
10213 [ # # ]: 0 : if (vxlan_m->hdr.flags) {
10214 : : flags_m = vxlan_m->hdr.flags;
10215 : 0 : flags_v = vxlan_v->hdr.flags;
10216 : : }
10217 : 0 : m_protocol = vxlan_m->hdr.protocol;
10218 : 0 : v_protocol = vxlan_v->hdr.protocol;
10219 [ # # ]: 0 : if (!m_protocol) {
10220 : : /* Force next protocol to ensure next headers parsing. */
10221 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_NSH)
10222 : : v_protocol = RTE_VXLAN_GPE_TYPE_NSH;
10223 [ # # ]: 0 : else if (pattern_flags & MLX5_FLOW_LAYER_INNER_L2)
10224 : : v_protocol = RTE_VXLAN_GPE_TYPE_ETH;
10225 [ # # ]: 0 : else if (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV4)
10226 : : v_protocol = RTE_VXLAN_GPE_TYPE_IPV4;
10227 [ # # ]: 0 : else if (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV6)
10228 : : v_protocol = RTE_VXLAN_GPE_TYPE_IPV6;
10229 [ # # ]: 0 : if (v_protocol)
10230 : : m_protocol = 0xFF;
10231 : : /* Restore the value to mask in mask case. */
10232 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10233 : : v_protocol = m_protocol;
10234 : : }
10235 : : /*
10236 : : * If only match flags/protocol/vni field, keep using misc3 for matching.
10237 : : * If need to match rsvd0 or rsvd1, using misc5 and do not need using misc3.
10238 : : */
10239 [ # # # # : 0 : if (!(vxlan_m->hdr.rsvd0[0] || vxlan_m->hdr.rsvd0[1] || vxlan_m->hdr.rsvd1)) {
# # ]
10240 [ # # ]: 0 : for (i = 0; i < size; ++i)
10241 : 0 : vni_v[i] = vxlan_m->hdr.vni[i] & vxlan_v->hdr.vni[i];
10242 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc_v, outer_vxlan_gpe_flags,
10243 : : flags_m & flags_v);
10244 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc_v,
10245 : : outer_vxlan_gpe_next_protocol, m_protocol & v_protocol);
10246 : : } else {
10247 : : uint32_t tunnel_v;
10248 : : void *misc5_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_5);
10249 : :
10250 : 0 : tunnel_v = (flags_m & flags_v) << 24 |
10251 : 0 : (vxlan_v->hdr.rsvd0[0] & vxlan_m->hdr.rsvd0[0]) << 16 |
10252 : 0 : (vxlan_v->hdr.rsvd0[1] & vxlan_m->hdr.rsvd0[1]) << 8 |
10253 : 0 : (m_protocol & v_protocol);
10254 [ # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_0, tunnel_v);
10255 : 0 : tunnel_v = (vxlan_v->hdr.vni[0] & vxlan_m->hdr.vni[0]) << 24 |
10256 : 0 : (vxlan_v->hdr.vni[1] & vxlan_m->hdr.vni[1]) << 16 |
10257 : 0 : (vxlan_v->hdr.vni[2] & vxlan_m->hdr.vni[2]) << 8 |
10258 : 0 : (vxlan_v->hdr.rsvd1 & vxlan_m->hdr.rsvd1);
10259 [ # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_1, tunnel_v);
10260 : : }
10261 : 0 : }
10262 : :
10263 : : /**
10264 : : * Add Geneve item to the value.
10265 : : *
10266 : : * @param[in, out] key
10267 : : * Flow matcher value.
10268 : : * @param[in] item
10269 : : * Flow pattern to translate.
10270 : : * @param[in] pattern_flags
10271 : : * Item pattern flags.
10272 : : * @param[in] key_type
10273 : : * Set flow matcher mask or value.
10274 : : */
10275 : :
10276 : : static void
10277 : 0 : flow_dv_translate_item_geneve(void *key, const struct rte_flow_item *item,
10278 : : uint64_t pattern_flags, uint32_t key_type)
10279 : : {
10280 : : static const struct rte_flow_item_geneve empty_geneve = {0,};
10281 : 0 : const struct rte_flow_item_geneve *geneve_m = item->mask;
10282 : 0 : const struct rte_flow_item_geneve *geneve_v = item->spec;
10283 : : /* GENEVE flow item validation allows single tunnel item */
10284 : : void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10285 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10286 : : uint16_t gbhdr_m;
10287 : : uint16_t gbhdr_v;
10288 : 0 : char *vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, geneve_vni);
10289 : : size_t size = sizeof(geneve_m->vni), i;
10290 : : uint16_t protocol_m, protocol_v;
10291 : :
10292 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
10293 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10294 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
10295 : : 0xFFFF);
10296 : : else
10297 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
10298 : : MLX5_UDP_PORT_GENEVE);
10299 : : }
10300 [ # # ]: 0 : if (!geneve_v) {
10301 : : geneve_v = &empty_geneve;
10302 : : geneve_m = &empty_geneve;
10303 : : } else {
10304 [ # # ]: 0 : if (!geneve_m)
10305 : : geneve_m = &rte_flow_item_geneve_mask;
10306 : : }
10307 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10308 : : geneve_v = geneve_m;
10309 [ # # ]: 0 : else if (key_type == MLX5_SET_MATCHER_HS_V)
10310 : : geneve_m = geneve_v;
10311 [ # # ]: 0 : for (i = 0; i < size; ++i)
10312 : 0 : vni_v[i] = geneve_m->vni[i] & geneve_v->vni[i];
10313 [ # # ]: 0 : gbhdr_m = rte_be_to_cpu_16(geneve_m->ver_opt_len_o_c_rsvd0);
10314 [ # # ]: 0 : gbhdr_v = rte_be_to_cpu_16(geneve_v->ver_opt_len_o_c_rsvd0);
10315 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, geneve_oam,
10316 : : MLX5_GENEVE_OAMF_VAL(gbhdr_v) & MLX5_GENEVE_OAMF_VAL(gbhdr_m));
10317 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
10318 : : MLX5_GENEVE_OPTLEN_VAL(gbhdr_v) &
10319 : : MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
10320 [ # # ]: 0 : protocol_m = rte_be_to_cpu_16(geneve_m->protocol);
10321 [ # # ]: 0 : protocol_v = rte_be_to_cpu_16(geneve_v->protocol);
10322 [ # # ]: 0 : if (!protocol_m) {
10323 : : /* Force next protocol to prevent matchers duplication */
10324 : : protocol_v = mlx5_translate_tunnel_etypes(pattern_flags);
10325 : : if (protocol_v)
10326 : : protocol_m = 0xFFFF;
10327 : : /* Restore the value to mask in mask case. */
10328 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10329 : : protocol_v = protocol_m;
10330 : : }
10331 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, geneve_protocol_type,
10332 : : protocol_m & protocol_v);
10333 : 0 : }
10334 : :
10335 : : /**
10336 : : * Create Geneve TLV option resource.
10337 : : *
10338 : : * @param[in, out] dev
10339 : : * Pointer to rte_eth_dev structure.
10340 : : * @param[in] item
10341 : : * Flow pattern to translate.
10342 : : * @param[out] error
10343 : : * pointer to error structure.
10344 : : *
10345 : : * @return
10346 : : * 0 on success otherwise -errno and errno is set.
10347 : : */
10348 : : static int
10349 : 0 : flow_dev_geneve_tlv_option_resource_register(struct rte_eth_dev *dev,
10350 : : const struct rte_flow_item *item,
10351 : : struct rte_flow_error *error)
10352 : : {
10353 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10354 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
10355 : 0 : struct mlx5_geneve_tlv_option_resource *geneve_opt_resource =
10356 : : sh->geneve_tlv_option_resource;
10357 : : struct mlx5_devx_obj *obj;
10358 : 0 : const struct rte_flow_item_geneve_opt *geneve_opt_v = item->spec;
10359 : : int ret = 0;
10360 : :
10361 : : MLX5_ASSERT(sh->config.dv_flow_en == 1);
10362 [ # # ]: 0 : if (!geneve_opt_v)
10363 : : return -1;
10364 : 0 : rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
10365 [ # # ]: 0 : if (geneve_opt_resource != NULL) {
10366 : 0 : if (geneve_opt_resource->option_class ==
10367 : : geneve_opt_v->option_class &&
10368 : : geneve_opt_resource->option_type ==
10369 [ # # ]: 0 : geneve_opt_v->option_type &&
10370 : : geneve_opt_resource->length ==
10371 : : geneve_opt_v->option_len) {
10372 : 0 : rte_atomic_fetch_add_explicit(&geneve_opt_resource->refcnt, 1,
10373 : : rte_memory_order_relaxed);
10374 : : } else {
10375 : 0 : ret = rte_flow_error_set(error, ENOMEM,
10376 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10377 : : "Only one GENEVE TLV option supported");
10378 : 0 : goto exit;
10379 : : }
10380 : : } else {
10381 : 0 : struct mlx5_devx_geneve_tlv_option_attr attr = {
10382 : 0 : .option_class = geneve_opt_v->option_class,
10383 : 0 : .option_type = geneve_opt_v->option_type,
10384 : 0 : .option_data_len = geneve_opt_v->option_len,
10385 : : };
10386 : :
10387 : : /* Create a GENEVE TLV object and resource. */
10388 : 0 : obj = mlx5_devx_cmd_create_geneve_tlv_option(sh->cdev->ctx,
10389 : : &attr);
10390 [ # # ]: 0 : if (!obj) {
10391 : 0 : ret = rte_flow_error_set(error, ENODATA,
10392 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10393 : : "Failed to create GENEVE TLV Devx object");
10394 : 0 : goto exit;
10395 : : }
10396 : 0 : sh->geneve_tlv_option_resource =
10397 : 0 : mlx5_malloc(MLX5_MEM_ZERO,
10398 : : sizeof(*geneve_opt_resource),
10399 : : 0, SOCKET_ID_ANY);
10400 [ # # ]: 0 : if (!sh->geneve_tlv_option_resource) {
10401 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
10402 : 0 : ret = rte_flow_error_set(error, ENOMEM,
10403 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10404 : : "GENEVE TLV object memory allocation failed");
10405 : 0 : goto exit;
10406 : : }
10407 : : geneve_opt_resource = sh->geneve_tlv_option_resource;
10408 : 0 : geneve_opt_resource->obj = obj;
10409 : 0 : geneve_opt_resource->option_class = geneve_opt_v->option_class;
10410 : 0 : geneve_opt_resource->option_type = geneve_opt_v->option_type;
10411 : 0 : geneve_opt_resource->length = geneve_opt_v->option_len;
10412 : 0 : rte_atomic_store_explicit(&geneve_opt_resource->refcnt, 1,
10413 : : rte_memory_order_relaxed);
10414 : : }
10415 : 0 : exit:
10416 : : rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
10417 : 0 : return ret;
10418 : : }
10419 : :
10420 : : /**
10421 : : * Add Geneve TLV option item to value.
10422 : : *
10423 : : * @param[in, out] dev
10424 : : * Pointer to rte_eth_dev structure.
10425 : : * @param[in, out] key
10426 : : * Flow matcher value.
10427 : : * @param[in] item
10428 : : * Flow pattern to translate.
10429 : : * @param[in] key_type
10430 : : * Set flow matcher mask or value.
10431 : : * @param[out] error
10432 : : * Pointer to error structure.
10433 : : */
10434 : : static int
10435 : 0 : flow_dv_translate_item_geneve_opt(struct rte_eth_dev *dev, void *key,
10436 : : const struct rte_flow_item *item,
10437 : : uint32_t key_type,
10438 : : struct rte_flow_error *error)
10439 : : {
10440 : : const struct rte_flow_item_geneve_opt *geneve_opt_m;
10441 : : const struct rte_flow_item_geneve_opt *geneve_opt_v;
10442 : 0 : const struct rte_flow_item_geneve_opt *orig_spec = item->spec;
10443 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
10444 : 0 : rte_be32_t opt_data_key = 0, opt_data_mask = 0;
10445 : : size_t option_byte_len;
10446 : : int ret = 0;
10447 : :
10448 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type) || !orig_spec)
# # # # #
# # # ]
10449 : : return -1;
10450 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, geneve_opt_v, geneve_opt_m,
# # # # ]
10451 : : &rte_flow_item_geneve_opt_mask);
10452 : : /*
10453 : : * Register resource requires item spec for SW steering,
10454 : : * for HW steering resources is registered explicitly by user.
10455 : : */
10456 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_SW_V) {
10457 : 0 : ret = flow_dev_geneve_tlv_option_resource_register(dev, item,
10458 : : error);
10459 [ # # ]: 0 : if (ret) {
10460 : 0 : DRV_LOG(ERR, "Failed to create geneve_tlv_obj");
10461 : 0 : return ret;
10462 : : }
10463 : : }
10464 : : /* Convert the option length from DW to bytes for using memcpy. */
10465 : 0 : option_byte_len = RTE_MIN((size_t)(orig_spec->option_len * 4),
10466 : : sizeof(rte_be32_t));
10467 [ # # ]: 0 : if (geneve_opt_v->data) {
10468 : : memcpy(&opt_data_key, geneve_opt_v->data, option_byte_len);
10469 : 0 : memcpy(&opt_data_mask, geneve_opt_m->data, option_byte_len);
10470 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v,
10471 : : geneve_tlv_option_0_data,
10472 : : rte_be_to_cpu_32(opt_data_key & opt_data_mask));
10473 : : }
10474 : : return ret;
10475 : : }
10476 : :
10477 : : /**
10478 : : * Add MPLS item to the value.
10479 : : *
10480 : : * @param[in, out] key
10481 : : * Flow matcher value.
10482 : : * @param[in] item
10483 : : * Flow pattern to translate.
10484 : : * @param[in] prev_layer
10485 : : * The protocol layer indicated in previous item.
10486 : : * @param[in] inner
10487 : : * Item is inner pattern.
10488 : : * @param[in] key_type
10489 : : * Set flow matcher mask or value.
10490 : : */
10491 : : static void
10492 : 0 : flow_dv_translate_item_mpls(void *key, const struct rte_flow_item *item,
10493 : : uint64_t prev_layer, int inner,
10494 : : uint32_t key_type)
10495 : : {
10496 : : const uint32_t *in_mpls_m;
10497 : : const uint32_t *in_mpls_v;
10498 : : uint32_t *out_mpls_v = 0;
10499 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10500 : 0 : void *misc2_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
10501 : : void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10502 : :
10503 [ # # # ]: 0 : switch (prev_layer) {
10504 : 0 : case MLX5_FLOW_LAYER_OUTER_L4_UDP:
10505 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
10506 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10507 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
10508 : : udp_dport, 0xffff);
10509 : : else
10510 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
10511 : : udp_dport, MLX5_UDP_PORT_MPLS);
10512 : : }
10513 : : break;
10514 : 0 : case MLX5_FLOW_LAYER_GRE:
10515 : : /* Fall-through. */
10516 : : case MLX5_FLOW_LAYER_GRE_KEY:
10517 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_misc, misc_v, gre_protocol)) {
10518 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10519 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v,
10520 : : gre_protocol, 0xffff);
10521 : : else
10522 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v,
10523 : : gre_protocol, RTE_ETHER_TYPE_MPLS);
10524 : : }
10525 : : break;
10526 : : default:
10527 : : break;
10528 : : }
10529 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10530 : : return;
10531 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, in_mpls_v, in_mpls_m,
# # # # ]
10532 : : &rte_flow_item_mpls_mask);
10533 [ # # # ]: 0 : switch (prev_layer) {
10534 : 0 : case MLX5_FLOW_LAYER_OUTER_L4_UDP:
10535 : 0 : out_mpls_v =
10536 : : (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
10537 : : outer_first_mpls_over_udp);
10538 : 0 : break;
10539 : 0 : case MLX5_FLOW_LAYER_GRE:
10540 : 0 : out_mpls_v =
10541 : : (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
10542 : : outer_first_mpls_over_gre);
10543 : 0 : break;
10544 : 0 : default:
10545 : : /* Inner MPLS not over GRE is not supported. */
10546 [ # # ]: 0 : if (!inner)
10547 : : out_mpls_v =
10548 : : (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
10549 : : misc2_v,
10550 : : outer_first_mpls);
10551 : : break;
10552 : : }
10553 : : if (out_mpls_v)
10554 : 0 : *out_mpls_v = *in_mpls_v & *in_mpls_m;
10555 : : }
10556 : :
10557 : : /**
10558 : : * Add metadata register item to matcher
10559 : : *
10560 : : * @param[in, out] key
10561 : : * Flow matcher value.
10562 : : * @param[in] reg_type
10563 : : * Type of device metadata register
10564 : : * @param[in] data
10565 : : * Register data
10566 : : * @param[in] mask
10567 : : * Register mask
10568 : : */
10569 : : static void
10570 : 0 : flow_dv_match_meta_reg(void *key, enum modify_reg reg_type,
10571 : : uint32_t data, uint32_t mask)
10572 : : {
10573 : : void *misc2_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
10574 : : void *misc5_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_5);
10575 : : uint32_t temp;
10576 : :
10577 [ # # ]: 0 : if (!key)
10578 : : return;
10579 : 0 : data &= mask;
10580 [ # # # # : 0 : switch (reg_type) {
# # # # #
# # # # #
# ]
10581 : 0 : case REG_A:
10582 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_a, data);
10583 : 0 : break;
10584 : 0 : case REG_B:
10585 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_b, data);
10586 : 0 : break;
10587 : 0 : case REG_C_0:
10588 : : /*
10589 : : * The metadata register C0 field might be divided into
10590 : : * source vport index and META item value, we should set
10591 : : * this field according to specified mask, not as whole one.
10592 : : */
10593 [ # # ]: 0 : temp = MLX5_GET(fte_match_set_misc2, misc2_v, metadata_reg_c_0);
10594 [ # # ]: 0 : if (mask)
10595 : 0 : temp &= ~mask;
10596 : 0 : temp |= data;
10597 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_0, temp);
10598 : 0 : break;
10599 : 0 : case REG_C_1:
10600 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_1, data);
10601 : 0 : break;
10602 : 0 : case REG_C_2:
10603 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_2, data);
10604 : 0 : break;
10605 : 0 : case REG_C_3:
10606 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_3, data);
10607 : 0 : break;
10608 : 0 : case REG_C_4:
10609 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_4, data);
10610 : 0 : break;
10611 : 0 : case REG_C_5:
10612 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_5, data);
10613 : 0 : break;
10614 : 0 : case REG_C_6:
10615 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_6, data);
10616 : 0 : break;
10617 : 0 : case REG_C_7:
10618 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_7, data);
10619 : 0 : break;
10620 : 0 : case REG_C_8:
10621 [ # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, metadata_reg_c_8, data);
10622 : 0 : break;
10623 : 0 : case REG_C_9:
10624 [ # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, metadata_reg_c_9, data);
10625 : 0 : break;
10626 : 0 : case REG_C_10:
10627 [ # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, metadata_reg_c_10, data);
10628 : 0 : break;
10629 : 0 : case REG_C_11:
10630 [ # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, metadata_reg_c_11, data);
10631 : 0 : break;
10632 : : default:
10633 : : MLX5_ASSERT(false);
10634 : : break;
10635 : : }
10636 : : }
10637 : :
10638 : : /**
10639 : : * Add metadata register item to matcher
10640 : : *
10641 : : * @param[in, out] matcher
10642 : : * Flow matcher.
10643 : : * @param[in, out] key
10644 : : * Flow matcher value.
10645 : : * @param[in] reg_type
10646 : : * Type of device metadata register
10647 : : * @param[in] value
10648 : : * Register value
10649 : : * @param[in] mask
10650 : : * Register mask
10651 : : */
10652 : : static void
10653 : : flow_dv_match_meta_reg_all(void *matcher, void *key, enum modify_reg reg_type,
10654 : : uint32_t data, uint32_t mask)
10655 : : {
10656 : 0 : flow_dv_match_meta_reg(key, reg_type, data, mask);
10657 : 0 : flow_dv_match_meta_reg(matcher, reg_type, mask, mask);
10658 : : }
10659 : :
10660 : : /**
10661 : : * Add MARK item to matcher
10662 : : *
10663 : : * @param[in] dev
10664 : : * The device to configure through.
10665 : : * @param[in, out] key
10666 : : * Flow matcher value.
10667 : : * @param[in] item
10668 : : * Flow pattern to translate.
10669 : : * @param[in] key_type
10670 : : * Set flow matcher mask or value.
10671 : : */
10672 : : static void
10673 : 0 : flow_dv_translate_item_mark(struct rte_eth_dev *dev, void *key,
10674 : : const struct rte_flow_item *item,
10675 : : uint32_t key_type)
10676 : : {
10677 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10678 : : const struct rte_flow_item_mark *mark;
10679 : : uint32_t value;
10680 : : uint32_t mask = 0;
10681 : :
10682 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_SW) {
10683 [ # # ]: 0 : mark = item->mask ? (const void *)item->mask :
10684 : : &rte_flow_item_mark_mask;
10685 : 0 : mask = mark->id;
10686 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M) {
10687 : : value = mask;
10688 : : } else {
10689 : 0 : mark = (const void *)item->spec;
10690 : : MLX5_ASSERT(mark);
10691 : 0 : value = mark->id;
10692 : : }
10693 : : } else {
10694 [ # # ]: 0 : mark = (key_type == MLX5_SET_MATCHER_HS_V) ?
10695 : : (const void *)item->spec : (const void *)item->mask;
10696 : : MLX5_ASSERT(mark);
10697 : 0 : value = mark->id;
10698 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_HS_M)
10699 : : mask = value;
10700 : : }
10701 : 0 : mask &= priv->sh->dv_mark_mask;
10702 : 0 : value &= mask;
10703 [ # # ]: 0 : if (mask) {
10704 : : enum modify_reg reg;
10705 : :
10706 : : /* Get the metadata register index for the mark. */
10707 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, NULL);
10708 : : MLX5_ASSERT(reg > 0);
10709 [ # # ]: 0 : if (reg == REG_C_0) {
10710 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10711 : 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
10712 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
10713 : :
10714 : 0 : mask &= msk_c0;
10715 : 0 : mask <<= shl_c0;
10716 : 0 : value <<= shl_c0;
10717 : : }
10718 : 0 : flow_dv_match_meta_reg(key, reg, value, mask);
10719 : : }
10720 : 0 : }
10721 : :
10722 : : /**
10723 : : * Add META item to matcher
10724 : : *
10725 : : * @param[in] dev
10726 : : * The devich to configure through.
10727 : : * @param[in, out] key
10728 : : * Flow matcher value.
10729 : : * @param[in] attr
10730 : : * Attributes of flow that includes this item.
10731 : : * @param[in] item
10732 : : * Flow pattern to translate.
10733 : : * @param[in] key_type
10734 : : * Set flow matcher mask or value.
10735 : : */
10736 : : static void
10737 : 0 : flow_dv_translate_item_meta(struct rte_eth_dev *dev,
10738 : : void *key,
10739 : : const struct rte_flow_attr *attr,
10740 : : const struct rte_flow_item *item,
10741 : : uint32_t key_type)
10742 : : {
10743 : : const struct rte_flow_item_meta *meta_m;
10744 : : const struct rte_flow_item_meta *meta_v;
10745 : : uint32_t value;
10746 : : uint32_t mask = 0;
10747 : : int reg;
10748 : :
10749 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10750 : : return;
10751 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, meta_v, meta_m,
# # # # ]
10752 : : &rte_flow_item_meta_mask);
10753 : 0 : value = meta_v->data;
10754 : 0 : mask = meta_m->data;
10755 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_HS_M)
10756 : : mask = value;
10757 : : /*
10758 : : * In the current implementation, REG_B cannot be used to match.
10759 : : * Force to use REG_C_1 in HWS root table as other tables.
10760 : : * This map may change.
10761 : : * NIC: modify - REG_B to be present in SW
10762 : : * match - REG_C_1 when copied from FDB, different from SWS
10763 : : * FDB: modify - REG_C_1 in Xmeta mode, REG_NON in legacy mode
10764 : : * match - REG_C_1 in FDB
10765 : : */
10766 [ # # ]: 0 : if (!!(key_type & MLX5_SET_MATCHER_SW))
10767 : 0 : reg = flow_dv_get_metadata_reg(dev, attr, NULL);
10768 : : else
10769 : : reg = flow_hw_get_reg_id(dev, RTE_FLOW_ITEM_TYPE_META, 0);
10770 [ # # ]: 0 : if (reg < 0)
10771 : : return;
10772 : : MLX5_ASSERT(reg != REG_NON);
10773 [ # # ]: 0 : if (reg == REG_C_0) {
10774 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10775 : 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
10776 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
10777 : :
10778 : 0 : mask &= msk_c0;
10779 : 0 : mask <<= shl_c0;
10780 : 0 : value <<= shl_c0;
10781 : : }
10782 : 0 : flow_dv_match_meta_reg(key, reg, value, mask);
10783 : : }
10784 : :
10785 : : /**
10786 : : * Add vport metadata Reg C0 item to matcher
10787 : : *
10788 : : * @param[in, out] key
10789 : : * Flow matcher value.
10790 : : * @param[in] value
10791 : : * Register value
10792 : : * @param[in] mask
10793 : : * Register mask
10794 : : */
10795 : : static void
10796 : : flow_dv_translate_item_meta_vport(void *key, uint32_t value, uint32_t mask)
10797 : : {
10798 : 0 : flow_dv_match_meta_reg(key, REG_C_0, value, mask);
10799 : 0 : }
10800 : :
10801 : : /**
10802 : : * Add tag item to matcher
10803 : : *
10804 : : * @param[in] dev
10805 : : * The devich to configure through.
10806 : : * @param[in, out] key
10807 : : * Flow matcher value.
10808 : : * @param[in] item
10809 : : * Flow pattern to translate.
10810 : : * @param[in] key_type
10811 : : * Set flow matcher mask or value.
10812 : : */
10813 : : static void
10814 : 0 : flow_dv_translate_mlx5_item_tag(struct rte_eth_dev *dev, void *key,
10815 : : const struct rte_flow_item *item,
10816 : : uint32_t key_type)
10817 : : {
10818 : 0 : const struct mlx5_rte_flow_item_tag *tag_v = item->spec;
10819 : 0 : const struct mlx5_rte_flow_item_tag *tag_m = item->mask;
10820 : : uint32_t mask, value;
10821 : :
10822 : : MLX5_ASSERT(tag_v);
10823 : 0 : value = tag_v->data;
10824 [ # # ]: 0 : mask = tag_m ? tag_m->data : UINT32_MAX;
10825 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10826 : : value = mask;
10827 [ # # ]: 0 : if (tag_v->id == REG_C_0) {
10828 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10829 : 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
10830 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
10831 : :
10832 : 0 : mask &= msk_c0;
10833 : 0 : mask <<= shl_c0;
10834 : 0 : value <<= shl_c0;
10835 : : }
10836 : 0 : flow_dv_match_meta_reg(key, tag_v->id, value, mask);
10837 : 0 : }
10838 : :
10839 : : /**
10840 : : * Add TAG item to matcher
10841 : : *
10842 : : * @param[in] dev
10843 : : * The devich to configure through.
10844 : : * @param[in, out] key
10845 : : * Flow matcher value.
10846 : : * @param[in] item
10847 : : * Flow pattern to translate.
10848 : : * @param[in] key_type
10849 : : * Set flow matcher mask or value.
10850 : : *
10851 : : * @return
10852 : : * 0 on success. Negative errno value otherwise.
10853 : : */
10854 : : static int
10855 : 0 : flow_dv_translate_item_tag(struct rte_eth_dev *dev, void *key,
10856 : : const struct rte_flow_item *item,
10857 : : uint32_t key_type)
10858 : : {
10859 : 0 : const struct rte_flow_item_tag *tag_vv = item->spec;
10860 : : const struct rte_flow_item_tag *tag_v;
10861 : : const struct rte_flow_item_tag *tag_m;
10862 : : int reg;
10863 : : uint32_t index;
10864 : :
10865 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10866 : : return 0;
10867 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, tag_v, tag_m,
# # # # ]
10868 : : &rte_flow_item_tag_mask);
10869 : : /* When set mask, the index should be from spec. */
10870 [ # # ]: 0 : index = tag_vv ? tag_vv->index : tag_v->index;
10871 : : /* Get the metadata register index for the tag. */
10872 [ # # ]: 0 : if (!!(key_type & MLX5_SET_MATCHER_SW))
10873 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, index, NULL);
10874 : : else
10875 : : reg = flow_hw_get_reg_id(dev, RTE_FLOW_ITEM_TYPE_TAG, index);
10876 [ # # ]: 0 : if (reg < 0) {
10877 : 0 : DRV_LOG(ERR, "port %u tag index %u does not map to correct register",
10878 : : dev->data->port_id, index);
10879 : 0 : return -EINVAL;
10880 : : }
10881 [ # # ]: 0 : if (reg == REG_NON) {
10882 : 0 : DRV_LOG(ERR, "port %u tag index %u maps to unsupported register",
10883 : : dev->data->port_id, index);
10884 : 0 : return -ENOTSUP;
10885 : : }
10886 : 0 : flow_dv_match_meta_reg(key, (enum modify_reg)reg, tag_v->data, tag_m->data);
10887 : 0 : return 0;
10888 : : }
10889 : :
10890 : : /**
10891 : : * Add source vport match to the specified matcher.
10892 : : *
10893 : : * @param[in, out] key
10894 : : * Flow matcher value.
10895 : : * @param[in] port
10896 : : * Source vport value to match
10897 : : */
10898 : : static void
10899 : : flow_dv_translate_item_source_vport(void *key,
10900 : : int16_t port)
10901 : : {
10902 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10903 : :
10904 [ # # # # : 0 : MLX5_SET(fte_match_set_misc, misc_v, source_port, port);
# # ]
10905 : 0 : }
10906 : :
10907 : : /**
10908 : : * Translate port-id item to eswitch match on port-id.
10909 : : *
10910 : : * @param[in] dev
10911 : : * The devich to configure through.
10912 : : * @param[in, out] key
10913 : : * Flow matcher value.
10914 : : * @param[in] item
10915 : : * Flow pattern to translate.
10916 : : * @param[in] attr
10917 : : * Flow attributes.
10918 : : * @param[in] key_type
10919 : : * Set flow matcher mask or value.
10920 : : *
10921 : : * @return
10922 : : * 0 on success, a negative errno value otherwise.
10923 : : */
10924 : : static int
10925 : 0 : flow_dv_translate_item_port_id(struct rte_eth_dev *dev, void *key,
10926 : : const struct rte_flow_item *item,
10927 : : const struct rte_flow_attr *attr,
10928 : : uint32_t key_type)
10929 : : {
10930 [ # # ]: 0 : const struct rte_flow_item_port_id *pid_m = item ? item->mask : NULL;
10931 [ # # ]: 0 : const struct rte_flow_item_port_id *pid_v = item ? item->spec : NULL;
10932 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
10933 : : struct mlx5_priv *priv;
10934 : : uint16_t mask, id;
10935 : : uint32_t vport_meta;
10936 : :
10937 : : MLX5_ASSERT(wks);
10938 [ # # # # ]: 0 : if (pid_v && pid_v->id == MLX5_PORT_ESW_MGR) {
10939 : 0 : priv = dev->data->dev_private;
10940 [ # # ]: 0 : if (priv->sh->dev_cap.esw_info.regc_mask) {
10941 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
10942 : : vport_meta = priv->sh->dev_cap.esw_info.regc_mask;
10943 : : } else {
10944 : 0 : vport_meta = priv->sh->dev_cap.esw_info.regc_value;
10945 : 0 : wks->vport_meta_tag = vport_meta;
10946 : : }
10947 : : flow_dv_translate_item_meta_vport(key, vport_meta,
10948 : : priv->sh->dev_cap.esw_info.regc_mask);
10949 : : } else {
10950 : 0 : flow_dv_translate_item_source_vport(key,
10951 [ # # ]: 0 : key_type & MLX5_SET_MATCHER_V ?
10952 : 0 : mlx5_flow_get_esw_manager_vport_id(dev) : 0xffff);
10953 : : }
10954 : 0 : return 0;
10955 : : }
10956 [ # # ]: 0 : mask = pid_m ? pid_m->id : 0xffff;
10957 [ # # ]: 0 : id = pid_v ? pid_v->id : dev->data->port_id;
10958 : 0 : priv = mlx5_port_to_eswitch_info(id, item == NULL);
10959 [ # # ]: 0 : if (!priv)
10960 : 0 : return -rte_errno;
10961 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
10962 : : id = mask;
10963 : 0 : vport_meta = priv->vport_meta_mask;
10964 : : } else {
10965 : 0 : id = priv->vport_id;
10966 : 0 : vport_meta = priv->vport_meta_tag;
10967 : 0 : wks->vport_meta_tag = vport_meta;
10968 : : }
10969 : : /*
10970 : : * Translate to vport field or to metadata, depending on mode.
10971 : : * Kernel can use either misc.source_port or half of C0 metadata
10972 : : * register.
10973 : : */
10974 [ # # ]: 0 : if (priv->vport_meta_mask) {
10975 : : /*
10976 : : * Provide the hint for SW steering library
10977 : : * to insert the flow into ingress domain and
10978 : : * save the extra vport match.
10979 : : */
10980 [ # # # # ]: 0 : if (mask == 0xffff && priv->vport_id == 0xffff &&
10981 [ # # # # ]: 0 : priv->pf_bond < 0 && attr->transfer)
10982 [ # # ]: 0 : flow_dv_translate_item_source_vport(key, id);
10983 : : /*
10984 : : * We should always set the vport metadata register,
10985 : : * otherwise the SW steering library can drop
10986 : : * the rule if wire vport metadata value is not zero,
10987 : : * it depends on kernel configuration.
10988 : : */
10989 : 0 : flow_dv_translate_item_meta_vport
10990 : : (key, vport_meta, priv->vport_meta_mask);
10991 : : } else {
10992 [ # # ]: 0 : flow_dv_translate_item_source_vport(key, id);
10993 : : }
10994 : : return 0;
10995 : : }
10996 : :
10997 : : /**
10998 : : * Translate port representor item to eswitch match on port id.
10999 : : *
11000 : : * @param[in] dev
11001 : : * The devich to configure through.
11002 : : * @param[in, out] key
11003 : : * Flow matcher value.
11004 : : * @param[in] key_type
11005 : : * Set flow matcher mask or value.
11006 : : *
11007 : : * @return
11008 : : * 0 on success, a negative errno value otherwise.
11009 : : */
11010 : : static int
11011 : 0 : flow_dv_translate_item_port_representor(struct rte_eth_dev *dev, void *key,
11012 : : uint32_t key_type)
11013 : : {
11014 : 0 : flow_dv_translate_item_source_vport(key,
11015 [ # # ]: 0 : key_type & MLX5_SET_MATCHER_V ?
11016 : 0 : mlx5_flow_get_esw_manager_vport_id(dev) : 0xffff);
11017 : 0 : return 0;
11018 : : }
11019 : :
11020 : : /**
11021 : : * Translate represented port item to eswitch match on port id.
11022 : : *
11023 : : * @param[in] dev
11024 : : * The devich to configure through.
11025 : : * @param[in, out] key
11026 : : * Flow matcher value.
11027 : : * @param[in] item
11028 : : * Flow pattern to translate.
11029 : : * @param[in]
11030 : : * Flow attributes.
11031 : : *
11032 : : * @return
11033 : : * 0 on success, a negative errno value otherwise.
11034 : : */
11035 : : static int
11036 : 0 : flow_dv_translate_item_represented_port(struct rte_eth_dev *dev, void *key,
11037 : : const struct rte_flow_item *item,
11038 : : const struct rte_flow_attr *attr,
11039 : : uint32_t key_type)
11040 : : {
11041 [ # # ]: 0 : const struct rte_flow_item_ethdev *pid_m = item ? item->mask : NULL;
11042 [ # # ]: 0 : const struct rte_flow_item_ethdev *pid_v = item ? item->spec : NULL;
11043 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
11044 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11045 : : uint16_t mask, id;
11046 : : uint32_t vport_meta;
11047 : : bool vport_match = false;
11048 : :
11049 : : MLX5_ASSERT(wks);
11050 : : #ifndef HAVE_IBV_DEVICE_ATTR_ESW_MGR_REG_C0
11051 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
11052 : : vport_match = true;
11053 : : #else
11054 : : if (priv->sh->config.dv_flow_en == 2)
11055 : : vport_match = !!priv->vport_match;
11056 : : #endif
11057 [ # # ]: 0 : if (!pid_m && !pid_v)
11058 : : return 0;
11059 [ # # # # ]: 0 : if (pid_v && pid_v->port_id == UINT16_MAX) {
11060 [ # # # # ]: 0 : if (priv->sh->config.dv_flow_en != 2 || vport_match) {
11061 : 0 : flow_dv_translate_item_source_vport
11062 [ # # ]: 0 : (key, key_type & MLX5_SET_MATCHER_V ?
11063 : 0 : mlx5_flow_get_esw_manager_vport_id(dev) : 0xffff);
11064 : : } else {
11065 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11066 : 0 : vport_meta = priv->sh->dev_cap.esw_info.regc_mask;
11067 : : else
11068 : 0 : vport_meta = priv->sh->dev_cap.esw_info.regc_value;
11069 : 0 : flow_dv_translate_item_meta_vport(key, vport_meta,
11070 : : priv->sh->dev_cap.esw_info.regc_mask);
11071 : : }
11072 : 0 : return 0;
11073 : : }
11074 [ # # ]: 0 : mask = pid_m ? pid_m->port_id : UINT16_MAX;
11075 [ # # ]: 0 : id = pid_v ? pid_v->port_id : dev->data->port_id;
11076 : 0 : priv = mlx5_port_to_eswitch_info(id, item == NULL);
11077 [ # # ]: 0 : if (!priv)
11078 : 0 : return -rte_errno;
11079 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
11080 : : id = mask;
11081 : 0 : vport_meta = priv->vport_meta_mask;
11082 : : } else {
11083 : 0 : id = priv->vport_id;
11084 : 0 : vport_meta = priv->vport_meta_tag;
11085 : 0 : wks->vport_meta_tag = vport_meta;
11086 : : }
11087 : : /*
11088 : : * Translate to vport field or to metadata, depending on mode.
11089 : : * Kernel can use either misc.source_port or half of C0 metadata
11090 : : * register.
11091 : : */
11092 [ # # # # ]: 0 : if (priv->vport_meta_mask && !vport_match) {
11093 : : /*
11094 : : * Provide the hint for SW steering library
11095 : : * to insert the flow into ingress domain and
11096 : : * save the extra vport match.
11097 : : */
11098 [ # # # # ]: 0 : if (mask == UINT16_MAX && priv->vport_id == UINT16_MAX &&
11099 [ # # # # ]: 0 : priv->pf_bond < 0 && attr->transfer &&
11100 [ # # ]: 0 : priv->sh->config.dv_flow_en != 2)
11101 [ # # ]: 0 : flow_dv_translate_item_source_vport(key, id);
11102 : : /*
11103 : : * We should always set the vport metadata register,
11104 : : * otherwise the SW steering library can drop
11105 : : * the rule if wire vport metadata value is not zero,
11106 : : * it depends on kernel configuration.
11107 : : */
11108 : 0 : flow_dv_translate_item_meta_vport(key, vport_meta,
11109 : : priv->vport_meta_mask);
11110 : : } else {
11111 [ # # ]: 0 : flow_dv_translate_item_source_vport(key, id);
11112 : : }
11113 : : return 0;
11114 : : }
11115 : :
11116 : : /**
11117 : : * Translate port-id item to eswitch match on port-id.
11118 : : *
11119 : : * @param[in] dev
11120 : : * The devich to configure through.
11121 : : * @param[in, out] matcher
11122 : : * Flow matcher.
11123 : : * @param[in, out] key
11124 : : * Flow matcher value.
11125 : : * @param[in] item
11126 : : * Flow pattern to translate.
11127 : : * @param[in] attr
11128 : : * Flow attributes.
11129 : : *
11130 : : * @return
11131 : : * 0 on success, a negative errno value otherwise.
11132 : : */
11133 : : static int
11134 : 0 : flow_dv_translate_item_port_id_all(struct rte_eth_dev *dev,
11135 : : void *matcher, void *key,
11136 : : const struct rte_flow_item *item,
11137 : : const struct rte_flow_attr *attr)
11138 : : {
11139 : : int ret;
11140 : :
11141 : 0 : ret = flow_dv_translate_item_port_id
11142 : : (dev, matcher, item, attr, MLX5_SET_MATCHER_SW_M);
11143 [ # # ]: 0 : if (ret)
11144 : : return ret;
11145 : 0 : ret = flow_dv_translate_item_port_id
11146 : : (dev, key, item, attr, MLX5_SET_MATCHER_SW_V);
11147 : 0 : return ret;
11148 : : }
11149 : :
11150 : :
11151 : : /**
11152 : : * Add ICMP6 item to the value.
11153 : : *
11154 : : * @param[in, out] key
11155 : : * Flow matcher value.
11156 : : * @param[in] item
11157 : : * Flow pattern to translate.
11158 : : * @param[in] inner
11159 : : * Item is inner pattern.
11160 : : * @param[in] key_type
11161 : : * Set flow matcher mask or value.
11162 : : */
11163 : : static void
11164 : 0 : flow_dv_translate_item_icmp6(void *key, const struct rte_flow_item *item,
11165 : : int inner, uint32_t key_type)
11166 : : {
11167 : : const struct rte_flow_item_icmp6 *icmp6_m;
11168 : : const struct rte_flow_item_icmp6 *icmp6_v;
11169 : : void *headers_v;
11170 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
11171 : :
11172 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
11173 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11174 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11175 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, 0xFF);
11176 : : else
11177 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
11178 : : IPPROTO_ICMPV6);
11179 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11180 : : return;
11181 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, icmp6_v, icmp6_m,
# # # # ]
11182 : : &rte_flow_item_icmp6_mask);
11183 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type,
11184 : : icmp6_v->type & icmp6_m->type);
11185 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code,
11186 : : icmp6_v->code & icmp6_m->code);
11187 : : }
11188 : :
11189 : : /**
11190 : : * Add ICMP6 echo request/reply item to the value.
11191 : : *
11192 : : * @param[in, out] key
11193 : : * Flow matcher value.
11194 : : * @param[in] item
11195 : : * Flow pattern to translate.
11196 : : * @param[in] inner
11197 : : * Item is inner pattern.
11198 : : * @param[in] key_type
11199 : : * Set flow matcher mask or value.
11200 : : */
11201 : : static void
11202 [ # # ]: 0 : flow_dv_translate_item_icmp6_echo(void *key, const struct rte_flow_item *item,
11203 : : int inner, uint32_t key_type)
11204 : : {
11205 : : const struct rte_flow_item_icmp6_echo *icmp6_m;
11206 : : const struct rte_flow_item_icmp6_echo *icmp6_v;
11207 : : uint32_t icmp6_header_data_m = 0;
11208 : : uint32_t icmp6_header_data_v = 0;
11209 : : void *headers_v;
11210 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
11211 : : uint8_t icmp6_type = 0;
11212 : : struct rte_flow_item_icmp6_echo zero_mask;
11213 : :
11214 : : memset(&zero_mask, 0, sizeof(zero_mask));
11215 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
11216 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11217 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11218 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, 0xFF);
11219 : : else
11220 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
11221 : : IPPROTO_ICMPV6);
11222 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, icmp6_v, icmp6_m, &zero_mask);
# # # # ]
11223 : : /* Set fixed type and code for icmpv6 echo request or reply */
11224 [ # # ]: 0 : icmp6_type = (item->type == RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REQUEST ?
11225 : : RTE_ICMP6_ECHO_REQUEST : RTE_ICMP6_ECHO_REPLY);
11226 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
11227 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type, 0xFF);
11228 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code, 0xFF);
11229 : : } else {
11230 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type, icmp6_type);
11231 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code, 0);
11232 : : }
11233 [ # # ]: 0 : if (icmp6_v == NULL)
11234 : 0 : return;
11235 : : /* Set icmp6 header data (identifier & sequence) accordingly */
11236 : 0 : icmp6_header_data_m =
11237 [ # # ]: 0 : (rte_be_to_cpu_16(icmp6_m->hdr.identifier) << 16) |
11238 [ # # ]: 0 : rte_be_to_cpu_16(icmp6_m->hdr.sequence);
11239 [ # # ]: 0 : if (icmp6_header_data_m) {
11240 : 0 : icmp6_header_data_v =
11241 [ # # ]: 0 : (rte_be_to_cpu_16(icmp6_v->hdr.identifier) << 16) |
11242 [ # # ]: 0 : rte_be_to_cpu_16(icmp6_v->hdr.sequence);
11243 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_header_data,
11244 : : icmp6_header_data_v & icmp6_header_data_m);
11245 : : }
11246 : : }
11247 : :
11248 : : /**
11249 : : * Add ICMP item to the value.
11250 : : *
11251 : : * @param[in, out] key
11252 : : * Flow matcher value.
11253 : : * @param[in] item
11254 : : * Flow pattern to translate.
11255 : : * @param[in] inner
11256 : : * Item is inner pattern.
11257 : : * @param[in] key_type
11258 : : * Set flow matcher mask or value.
11259 : : */
11260 : : static void
11261 : 0 : flow_dv_translate_item_icmp(void *key, const struct rte_flow_item *item,
11262 : : int inner, uint32_t key_type)
11263 : : {
11264 : : const struct rte_flow_item_icmp *icmp_m;
11265 : : const struct rte_flow_item_icmp *icmp_v;
11266 : : uint32_t icmp_header_data_m = 0;
11267 : : uint32_t icmp_header_data_v = 0;
11268 : : void *headers_v;
11269 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
11270 : :
11271 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
11272 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11273 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11274 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11275 : : ip_protocol, 0xFF);
11276 : : else
11277 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11278 : : ip_protocol, IPPROTO_ICMP);
11279 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11280 : : return;
11281 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, icmp_v, icmp_m,
# # # # ]
11282 : : &rte_flow_item_icmp_mask);
11283 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmp_type,
11284 : : icmp_v->hdr.icmp_type & icmp_m->hdr.icmp_type);
11285 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmp_code,
11286 : : icmp_v->hdr.icmp_code & icmp_m->hdr.icmp_code);
11287 [ # # ]: 0 : icmp_header_data_m = rte_be_to_cpu_16(icmp_m->hdr.icmp_seq_nb);
11288 [ # # ]: 0 : icmp_header_data_m |= rte_be_to_cpu_16(icmp_m->hdr.icmp_ident) << 16;
11289 [ # # ]: 0 : if (icmp_header_data_m) {
11290 [ # # ]: 0 : icmp_header_data_v = rte_be_to_cpu_16(icmp_v->hdr.icmp_seq_nb);
11291 : 0 : icmp_header_data_v |=
11292 [ # # ]: 0 : rte_be_to_cpu_16(icmp_v->hdr.icmp_ident) << 16;
11293 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmp_header_data,
11294 : : icmp_header_data_v & icmp_header_data_m);
11295 : : }
11296 : : }
11297 : :
11298 : : /**
11299 : : * Add GTP item to the value.
11300 : : *
11301 : : * @param[in, out] key
11302 : : * Flow matcher value.
11303 : : * @param[in] item
11304 : : * Flow pattern to translate.
11305 : : * @param[in] inner
11306 : : * Item is inner pattern.
11307 : : * @param[in] key_type
11308 : : * Set flow matcher mask or value.
11309 : : */
11310 : : static void
11311 : 0 : flow_dv_translate_item_gtp(void *key, const struct rte_flow_item *item,
11312 : : int inner, uint32_t key_type)
11313 : : {
11314 : : const struct rte_flow_item_gtp *gtp_m;
11315 : : const struct rte_flow_item_gtp *gtp_v;
11316 : : void *headers_v;
11317 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
11318 : : uint16_t dport = RTE_GTPU_UDP_PORT;
11319 : :
11320 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
11321 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11322 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
11323 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11324 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11325 : : udp_dport, 0xFFFF);
11326 : : else
11327 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11328 : : udp_dport, dport);
11329 : : }
11330 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11331 : : return;
11332 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, gtp_v, gtp_m,
# # # # ]
11333 : : &rte_flow_item_gtp_mask);
11334 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags,
11335 : : gtp_v->hdr.gtp_hdr_info & gtp_m->hdr.gtp_hdr_info);
11336 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_type,
11337 : : gtp_v->hdr.msg_type & gtp_m->hdr.msg_type);
11338 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_teid,
11339 : : rte_be_to_cpu_32(gtp_v->hdr.teid & gtp_m->hdr.teid));
11340 : : }
11341 : :
11342 : : /**
11343 : : * Add GTP PSC item to matcher.
11344 : : *
11345 : : * @param[in, out] key
11346 : : * Flow matcher value.
11347 : : * @param[in] item
11348 : : * Flow pattern to translate.
11349 : : * @param[in] key_type
11350 : : * Set flow matcher mask or value.
11351 : : */
11352 : : static int
11353 : 0 : flow_dv_translate_item_gtp_psc(void *key, const struct rte_flow_item *item,
11354 : : uint32_t key_type)
11355 : : {
11356 : : const struct rte_flow_item_gtp_psc *gtp_psc_m;
11357 : : const struct rte_flow_item_gtp_psc *gtp_psc_v;
11358 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
11359 : : union {
11360 : : uint32_t w32;
11361 : : struct {
11362 : : uint16_t seq_num;
11363 : : uint8_t npdu_num;
11364 : : uint8_t next_ext_header_type;
11365 : : };
11366 : : } dw_2;
11367 : : union {
11368 : : uint32_t w32;
11369 : : struct {
11370 : : uint8_t len;
11371 : : uint8_t type_flags;
11372 : : uint8_t qfi;
11373 : : uint8_t reserved;
11374 : : };
11375 : : } dw_0;
11376 : : uint8_t gtp_flags;
11377 : :
11378 : : /* Always set E-flag match on one, regardless of GTP item settings. */
11379 [ # # ]: 0 : gtp_flags = MLX5_GET(fte_match_set_misc3, misc3_v, gtpu_msg_flags);
11380 : 0 : gtp_flags |= MLX5_GTP_EXT_HEADER_FLAG;
11381 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags, gtp_flags);
11382 : : /*Set next extension header type. */
11383 : 0 : dw_2.seq_num = 0;
11384 : 0 : dw_2.npdu_num = 0;
11385 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11386 : 0 : dw_2.next_ext_header_type = 0xff;
11387 : : else
11388 : 0 : dw_2.next_ext_header_type = 0x85;
11389 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_dw_2,
11390 : : rte_cpu_to_be_32(dw_2.w32));
11391 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11392 : : return 0;
11393 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, gtp_psc_v,
# # # # ]
11394 : : gtp_psc_m, &rte_flow_item_gtp_psc_mask);
11395 : 0 : dw_0.w32 = 0;
11396 : 0 : dw_0.type_flags = MLX5_GTP_PDU_TYPE_SHIFT(gtp_psc_v->hdr.type &
11397 : : gtp_psc_m->hdr.type);
11398 : 0 : dw_0.qfi = gtp_psc_v->hdr.qfi & gtp_psc_m->hdr.qfi;
11399 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_first_ext_dw_0,
11400 : : rte_cpu_to_be_32(dw_0.w32));
11401 : 0 : return 0;
11402 : : }
11403 : :
11404 : :
11405 : : static inline void
11406 : : flow_dv_set_ecpri_sample1(void *misc4_v,
11407 : : const struct rte_flow_item_ecpri *ecpri_m,
11408 : : const struct rte_flow_item_ecpri *ecpri_v,
11409 : : uint32_t sample1)
11410 : : {
11411 : : void *dw_v;
11412 : : dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v, prog_sample_field_value_1);
11413 : 0 : *(uint32_t *)dw_v = ecpri_v->hdr.dummy[0] & ecpri_m->hdr.dummy[0];
11414 : : /* Sample#1, to match message body, offset 4. */
11415 : 0 : MLX5_SET(fte_match_set_misc4, misc4_v, prog_sample_field_id_1, sample1);
11416 : 0 : }
11417 : :
11418 : : /**
11419 : : * Add eCPRI item to matcher and to the value.
11420 : : *
11421 : : * @param[in] dev
11422 : : * The devich to configure through.
11423 : : * @param[in, out] key
11424 : : * Flow matcher value.
11425 : : * @param[in] item
11426 : : * Flow pattern to translate.
11427 : : * @param[in] last_item
11428 : : * Last item flags.
11429 : : * @param[in] key_type
11430 : : * Set flow matcher mask or value.
11431 : : */
11432 : : static void
11433 : 0 : flow_dv_translate_item_ecpri(struct rte_eth_dev *dev, void *key,
11434 : : const struct rte_flow_item *item,
11435 : : struct mlx5_dv_matcher_workspace *wks,
11436 : : uint64_t last_item, uint32_t key_type)
11437 : : {
11438 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11439 : : const struct rte_flow_item_ecpri *ecpri_m;
11440 : : const struct rte_flow_item_ecpri *ecpri_v;
11441 : 0 : const struct rte_flow_item_ecpri *ecpri_vv = item->spec;
11442 : : struct rte_ecpri_common_hdr common;
11443 : : void *misc4_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_4);
11444 : : uint32_t *samples;
11445 : : void *dw_v;
11446 : :
11447 : : /*
11448 : : * In case of eCPRI over Ethernet, if EtherType is not specified,
11449 : : * match on eCPRI EtherType implicitly.
11450 : : */
11451 [ # # ]: 0 : if (last_item & MLX5_FLOW_LAYER_OUTER_L2) {
11452 : : void *hdrs_v, *l2v;
11453 : :
11454 : : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11455 : : l2v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, ethertype);
11456 [ # # ]: 0 : if (*(uint16_t *)l2v == 0) {
11457 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11458 : 0 : *(uint16_t *)l2v = UINT16_MAX;
11459 : : else
11460 : 0 : *(uint16_t *)l2v =
11461 : : RTE_BE16(RTE_ETHER_TYPE_ECPRI);
11462 : : }
11463 : : }
11464 : : /* HWS matcher does need a non-empty mask. */
11465 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11466 : 0 : return;
11467 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, ecpri_v, ecpri_m, &rte_flow_item_ecpri_mask);
# # # # ]
11468 : : /*
11469 : : * Maximal four DW samples are supported in a single matching now.
11470 : : * Two are used now for a eCPRI matching:
11471 : : * 1. Type: one byte, mask should be 0x00ff0000 in network order
11472 : : * 2. ID of a message: one or two bytes, mask 0xffff0000 or 0xff000000
11473 : : * if any.
11474 : : * Translation also handles the following cases.
11475 : : * 1. HWS mode may face a case with NULL mask and value all zeros.
11476 : : * 2. Matching all eCPRI packets will be done in ETH / VLAN item.
11477 : : * 3. If type is not masked, then message body will not be masked either, forcefully.
11478 : : */
11479 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_HS_M) {
11480 [ # # ]: 0 : if (!ecpri_m->hdr.common.u32) {
11481 : 0 : *wks->p_root_flags |= MLX5_EMPTY_ECPRI_TYPE_MASK;
11482 : 0 : return;
11483 : : }
11484 : : /* Initialized with 0, this should not hit. */
11485 : 0 : *wks->p_root_flags &= ~MLX5_EMPTY_ECPRI_TYPE_MASK;
11486 : : }
11487 [ # # # # ]: 0 : if (key_type == MLX5_SET_MATCHER_HS_V && (*wks->p_root_flags & MLX5_EMPTY_ECPRI_TYPE_MASK))
11488 : : return;
11489 [ # # # # ]: 0 : if ((key_type & MLX5_SET_MATCHER_SW) && !ecpri_m->hdr.common.u32)
11490 : : return;
11491 : 0 : samples = priv->sh->ecpri_parser.ids;
11492 : : /* Need to take the whole DW as the mask to fill the entry. */
11493 : : dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
11494 : : prog_sample_field_value_0);
11495 : : /* Already big endian (network order) in the header. */
11496 : 0 : *(uint32_t *)dw_v = ecpri_v->hdr.common.u32 & ecpri_m->hdr.common.u32;
11497 : : /* Sample#0, used for matching type, offset 0. */
11498 : : /* It makes no sense to set the sample ID in the mask field. */
11499 [ # # ]: 0 : MLX5_SET(fte_match_set_misc4, misc4_v,
11500 : : prog_sample_field_id_0, samples[0]);
11501 : : /*
11502 : : * Checking if message body part needs to be matched.
11503 : : * Some wildcard rules only matching type field should be supported.
11504 : : */
11505 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_HS_M) {
11506 [ # # ]: 0 : if (!ecpri_m->hdr.dummy[0]) {
11507 : 0 : *wks->p_root_flags |= MLX5_EMPTY_ECPRI_BODY_MASK;
11508 : 0 : return;
11509 : : }
11510 : 0 : *wks->p_root_flags &= ~MLX5_EMPTY_ECPRI_BODY_MASK;
11511 : : }
11512 [ # # # # ]: 0 : if (key_type == MLX5_SET_MATCHER_HS_V && (*wks->p_root_flags & MLX5_EMPTY_ECPRI_BODY_MASK))
11513 : : return;
11514 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_SW) {
11515 [ # # ]: 0 : if (!ecpri_m->hdr.dummy[0])
11516 : : return;
11517 [ # # ]: 0 : common.u32 = rte_be_to_cpu_32(ecpri_vv->hdr.common.u32);
11518 [ # # ]: 0 : } else if (key_type == MLX5_SET_MATCHER_HS_V) {
11519 [ # # ]: 0 : common.u32 = rte_be_to_cpu_32(ecpri_v->hdr.common.u32);
11520 : : }
11521 [ # # ]: 0 : if (key_type != MLX5_SET_MATCHER_HS_M) {
11522 [ # # ]: 0 : switch (common.type) {
11523 : 0 : case RTE_ECPRI_MSG_TYPE_IQ_DATA:
11524 : : case RTE_ECPRI_MSG_TYPE_RTC_CTRL:
11525 : : case RTE_ECPRI_MSG_TYPE_DLY_MSR:
11526 [ # # ]: 0 : flow_dv_set_ecpri_sample1(misc4_v, ecpri_v, ecpri_m, samples[1]);
11527 : : break;
11528 : : default:
11529 : : /* Others, do not match any sample ID. */
11530 : : break;
11531 : : }
11532 : : } else {
11533 : : /* When MLX5_SET_MATCHER_HS_M on root table (default value),
11534 : : * the sample ID and mask should be set, or else prog_sample_field_id_1 will
11535 : : * be zero and a mismatch with the HWS rule.
11536 : : * Empty body mask for a matcher returns directly in the previous lines.
11537 : : */
11538 [ # # ]: 0 : flow_dv_set_ecpri_sample1(misc4_v, ecpri_v, ecpri_m, samples[1]);
11539 : : }
11540 : : }
11541 : :
11542 : : /*
11543 : : * Add connection tracking status item to matcher
11544 : : *
11545 : : * @param[in] dev
11546 : : * The devich to configure through.
11547 : : * @param[in, out] matcher
11548 : : * Flow matcher.
11549 : : * @param[in, out] key
11550 : : * Flow matcher value.
11551 : : * @param[in] item
11552 : : * Flow pattern to translate.
11553 : : */
11554 : : static void
11555 : 0 : flow_dv_translate_item_aso_ct(struct rte_eth_dev *dev,
11556 : : void *matcher, void *key,
11557 : : const struct rte_flow_item *item)
11558 : : {
11559 : : uint32_t reg_value = 0;
11560 : : int reg_id;
11561 : : /* 8LSB 0b 11/0000/11, middle 4 bits are reserved. */
11562 : : uint32_t reg_mask = 0;
11563 : 0 : const struct rte_flow_item_conntrack *spec = item->spec;
11564 : 0 : const struct rte_flow_item_conntrack *mask = item->mask;
11565 : : uint32_t flags;
11566 : : struct rte_flow_error error;
11567 : :
11568 [ # # ]: 0 : if (!mask)
11569 : : mask = &rte_flow_item_conntrack_mask;
11570 [ # # # # ]: 0 : if (!spec || !mask->flags)
11571 : 0 : return;
11572 : 0 : flags = spec->flags & mask->flags;
11573 : : /* The conflict should be checked in the validation. */
11574 : : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_VALID)
11575 : : reg_value |= MLX5_CT_SYNDROME_VALID;
11576 [ # # ]: 0 : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_CHANGED)
11577 : : reg_value |= MLX5_CT_SYNDROME_STATE_CHANGE;
11578 [ # # ]: 0 : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_INVALID)
11579 : 0 : reg_value |= MLX5_CT_SYNDROME_INVALID;
11580 [ # # ]: 0 : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED)
11581 : 0 : reg_value |= MLX5_CT_SYNDROME_TRAP;
11582 [ # # ]: 0 : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD)
11583 : 0 : reg_value |= MLX5_CT_SYNDROME_BAD_PACKET;
11584 [ # # ]: 0 : if (mask->flags & (RTE_FLOW_CONNTRACK_PKT_STATE_VALID |
11585 : : RTE_FLOW_CONNTRACK_PKT_STATE_INVALID |
11586 : : RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED))
11587 : : reg_mask |= 0xc0;
11588 [ # # ]: 0 : if (mask->flags & RTE_FLOW_CONNTRACK_PKT_STATE_CHANGED)
11589 : 0 : reg_mask |= MLX5_CT_SYNDROME_STATE_CHANGE;
11590 [ # # ]: 0 : if (mask->flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD)
11591 : 0 : reg_mask |= MLX5_CT_SYNDROME_BAD_PACKET;
11592 : : /* The REG_C_x value could be saved during startup. */
11593 : 0 : reg_id = mlx5_flow_get_reg_id(dev, MLX5_ASO_CONNTRACK, 0, &error);
11594 [ # # ]: 0 : if (reg_id == REG_NON)
11595 : : return;
11596 : 0 : flow_dv_match_meta_reg_all(matcher, key, (enum modify_reg)reg_id,
11597 : : reg_value, reg_mask);
11598 : : }
11599 : :
11600 : : static void
11601 : 0 : flow_dv_translate_item_flex(struct rte_eth_dev *dev, void *matcher, void *key,
11602 : : const struct rte_flow_item *item,
11603 : : struct mlx5_flow *dev_flow, bool is_inner)
11604 : : {
11605 : 0 : const struct rte_flow_item_flex *spec =
11606 : : (const struct rte_flow_item_flex *)item->spec;
11607 : 0 : int index = mlx5_flex_acquire_index(dev, spec->handle, false);
11608 : :
11609 : : MLX5_ASSERT(index >= 0 && index < (int)(sizeof(uint32_t) * CHAR_BIT));
11610 [ # # ]: 0 : if (index < 0)
11611 : : return;
11612 [ # # ]: 0 : if (!(dev_flow->handle->flex_item & RTE_BIT32(index))) {
11613 : : /* Don't count both inner and outer flex items in one rule. */
11614 : 0 : if (mlx5_flex_acquire_index(dev, spec->handle, true) != index)
11615 : : MLX5_ASSERT(false);
11616 : 0 : dev_flow->handle->flex_item |= (uint8_t)RTE_BIT32(index);
11617 : : }
11618 : 0 : mlx5_flex_flow_translate_item(dev, matcher, key, item, is_inner);
11619 : : }
11620 : :
11621 : : /**
11622 : : * Add METER_COLOR item to matcher
11623 : : *
11624 : : * @param[in] dev
11625 : : * The device to configure through.
11626 : : * @param[in, out] key
11627 : : * Flow matcher value.
11628 : : * @param[in] item
11629 : : * Flow pattern to translate.
11630 : : * @param[in] key_type
11631 : : * Set flow matcher mask or value.
11632 : : */
11633 : : static void
11634 : 0 : flow_dv_translate_item_meter_color(struct rte_eth_dev *dev, void *key,
11635 : : const struct rte_flow_item *item,
11636 : : uint32_t key_type)
11637 : : {
11638 : 0 : const struct rte_flow_item_meter_color *color_m = item->mask;
11639 : 0 : const struct rte_flow_item_meter_color *color_v = item->spec;
11640 : : uint32_t value, mask;
11641 : : int reg = REG_NON;
11642 : :
11643 : : MLX5_ASSERT(color_v);
11644 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11645 : : return;
11646 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, color_v, color_m,
# # # # ]
11647 : : &rte_flow_item_meter_color_mask);
11648 [ # # ]: 0 : value = rte_col_2_mlx5_col(color_v->color);
11649 : : mask = color_m ?
11650 [ # # ]: 0 : color_m->color : (UINT32_C(1) << MLX5_MTR_COLOR_BITS) - 1;
11651 [ # # ]: 0 : if (!!(key_type & MLX5_SET_MATCHER_SW))
11652 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, NULL);
11653 : : else
11654 : : reg = flow_hw_get_reg_id(dev,
11655 : : RTE_FLOW_ITEM_TYPE_METER_COLOR, 0);
11656 [ # # ]: 0 : if (reg == REG_NON)
11657 : : return;
11658 : 0 : flow_dv_match_meta_reg(key, (enum modify_reg)reg, value, mask);
11659 : : }
11660 : :
11661 : : static void
11662 : 0 : flow_dv_translate_item_aggr_affinity(void *key,
11663 : : const struct rte_flow_item *item,
11664 : : uint32_t key_type)
11665 : : {
11666 : : const struct rte_flow_item_aggr_affinity *affinity_v;
11667 : : const struct rte_flow_item_aggr_affinity *affinity_m;
11668 : : void *misc_v;
11669 : :
11670 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, affinity_v, affinity_m,
# # # # ]
11671 : : &rte_flow_item_aggr_affinity_mask);
11672 : : misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
11673 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, lag_rx_port_affinity,
11674 : : affinity_v->affinity & affinity_m->affinity);
11675 : 0 : }
11676 : :
11677 : : static void
11678 : 0 : flow_dv_translate_item_ib_bth(void *key,
11679 : : const struct rte_flow_item *item,
11680 : : int inner, uint32_t key_type)
11681 : : {
11682 : : const struct rte_flow_item_ib_bth *bth_m;
11683 : : const struct rte_flow_item_ib_bth *bth_v;
11684 : : void *headers_v, *misc_v;
11685 : : uint16_t udp_dport;
11686 : : char *qpn_v;
11687 : : int i, size;
11688 : :
11689 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
11690 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11691 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
11692 [ # # ]: 0 : udp_dport = key_type & MLX5_SET_MATCHER_M ?
11693 : : 0xFFFF : MLX5_UDP_PORT_ROCEv2;
11694 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, udp_dport);
11695 : : }
11696 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11697 : : return;
11698 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, bth_v, bth_m, &rte_flow_item_ib_bth_mask);
# # # # ]
11699 : : misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
11700 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, bth_opcode,
11701 : : bth_v->hdr.opcode & bth_m->hdr.opcode);
11702 : 0 : qpn_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, bth_dst_qp);
11703 : : size = sizeof(bth_m->hdr.dst_qp);
11704 [ # # ]: 0 : for (i = 0; i < size; ++i)
11705 : 0 : qpn_v[i] = bth_m->hdr.dst_qp[i] & bth_v->hdr.dst_qp[i];
11706 : : }
11707 : :
11708 : : static uint32_t matcher_zero[MLX5_ST_SZ_DW(fte_match_param)] = { 0 };
11709 : :
11710 : : #define HEADER_IS_ZERO(match_criteria, headers) \
11711 : : !(memcmp(MLX5_ADDR_OF(fte_match_param, match_criteria, headers), \
11712 : : matcher_zero, MLX5_FLD_SZ_BYTES(fte_match_param, headers))) \
11713 : :
11714 : : /**
11715 : : * Calculate flow matcher enable bitmap.
11716 : : *
11717 : : * @param match_criteria
11718 : : * Pointer to flow matcher criteria.
11719 : : *
11720 : : * @return
11721 : : * Bitmap of enabled fields.
11722 : : */
11723 : : static uint8_t
11724 : 0 : flow_dv_matcher_enable(uint32_t *match_criteria)
11725 : : {
11726 : : uint8_t match_criteria_enable;
11727 : :
11728 : : match_criteria_enable =
11729 : 0 : (!HEADER_IS_ZERO(match_criteria, outer_headers)) <<
11730 : : MLX5_MATCH_CRITERIA_ENABLE_OUTER_BIT;
11731 : 0 : match_criteria_enable |=
11732 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters)) <<
11733 : : MLX5_MATCH_CRITERIA_ENABLE_MISC_BIT;
11734 : 0 : match_criteria_enable |=
11735 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, inner_headers)) <<
11736 : : MLX5_MATCH_CRITERIA_ENABLE_INNER_BIT;
11737 : 0 : match_criteria_enable |=
11738 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) <<
11739 : : MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
11740 : 0 : match_criteria_enable |=
11741 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters_3)) <<
11742 : : MLX5_MATCH_CRITERIA_ENABLE_MISC3_BIT;
11743 : 0 : match_criteria_enable |=
11744 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters_4)) <<
11745 : : MLX5_MATCH_CRITERIA_ENABLE_MISC4_BIT;
11746 : 0 : match_criteria_enable |=
11747 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters_5)) <<
11748 : : MLX5_MATCH_CRITERIA_ENABLE_MISC5_BIT;
11749 : 0 : return match_criteria_enable;
11750 : : }
11751 : :
11752 : : static void
11753 : : __flow_dv_adjust_buf_size(size_t *size, uint8_t match_criteria)
11754 : : {
11755 : : /*
11756 : : * Check flow matching criteria first, subtract misc5/4 length if flow
11757 : : * doesn't own misc5/4 parameters. In some old rdma-core releases,
11758 : : * misc5/4 are not supported, and matcher creation failure is expected
11759 : : * w/o subtraction. If misc5 is provided, misc4 must be counted in since
11760 : : * misc5 is right after misc4.
11761 : : */
11762 : 0 : if (!(match_criteria & (1 << MLX5_MATCH_CRITERIA_ENABLE_MISC5_BIT))) {
11763 : 0 : *size = MLX5_ST_SZ_BYTES(fte_match_param) -
11764 : : MLX5_ST_SZ_BYTES(fte_match_set_misc5);
11765 [ # # # # : 0 : if (!(match_criteria & (1 <<
# # # # #
# # # # #
# # # # #
# ]
11766 : : MLX5_MATCH_CRITERIA_ENABLE_MISC4_BIT))) {
11767 : 0 : *size -= MLX5_ST_SZ_BYTES(fte_match_set_misc4);
11768 : : }
11769 : : }
11770 : : }
11771 : :
11772 : : struct mlx5_list_entry *
11773 : 0 : mlx5_flow_matcher_clone_cb(void *tool_ctx __rte_unused,
11774 : : struct mlx5_list_entry *entry, void *cb_ctx)
11775 : : {
11776 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11777 : 0 : struct mlx5_flow_dv_matcher *ref = ctx->data;
11778 : : struct mlx5_flow_dv_matcher *old_resource;
11779 : 0 : struct mlx5_flow_tbl_data_entry *tbl = container_of(ref->tbl,
11780 : : typeof(*tbl), tbl);
11781 : 0 : struct mlx5_flow_dv_matcher *resource = mlx5_malloc(MLX5_MEM_ANY,
11782 : : sizeof(*resource),
11783 : : 0, SOCKET_ID_ANY);
11784 : :
11785 [ # # ]: 0 : if (!resource) {
11786 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
11787 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11788 : : "cannot create matcher");
11789 : 0 : return NULL;
11790 : : }
11791 : : old_resource = container_of(entry, typeof(*old_resource), entry);
11792 : : memcpy(resource, old_resource, sizeof(*resource));
11793 : 0 : resource->tbl = &tbl->tbl;
11794 : 0 : return &resource->entry;
11795 : : }
11796 : :
11797 : : void
11798 : 0 : mlx5_flow_matcher_clone_free_cb(void *tool_ctx __rte_unused,
11799 : : struct mlx5_list_entry *entry)
11800 : : {
11801 : 0 : mlx5_free(entry);
11802 : 0 : }
11803 : :
11804 : : struct mlx5_list_entry *
11805 : 0 : mlx5_flow_dv_tbl_create_cb(void *tool_ctx, void *cb_ctx)
11806 : : {
11807 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11808 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11809 : 0 : struct rte_eth_dev *dev = ctx->dev;
11810 : : struct mlx5_flow_tbl_data_entry *tbl_data;
11811 : 0 : struct mlx5_flow_tbl_tunnel_prm *tt_prm = ctx->data2;
11812 : 0 : struct rte_flow_error *error = ctx->error;
11813 : 0 : union mlx5_flow_tbl_key key = { .v64 = *(uint64_t *)(ctx->data) };
11814 : : struct mlx5_flow_tbl_resource *tbl;
11815 : : void *domain;
11816 : 0 : uint32_t idx = 0;
11817 : : int ret;
11818 : :
11819 : 0 : tbl_data = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_JUMP], &idx);
11820 [ # # ]: 0 : if (!tbl_data) {
11821 : 0 : rte_flow_error_set(error, ENOMEM,
11822 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11823 : : NULL,
11824 : : "cannot allocate flow table data entry");
11825 : 0 : return NULL;
11826 : : }
11827 : 0 : tbl_data->idx = idx;
11828 : 0 : tbl_data->tunnel = tt_prm->tunnel;
11829 : 0 : tbl_data->group_id = tt_prm->group_id;
11830 [ # # ]: 0 : tbl_data->external = !!tt_prm->external;
11831 : 0 : tbl_data->tunnel_offload = is_tunnel_offload_active(dev);
11832 : 0 : tbl_data->is_egress = !!key.is_egress;
11833 : 0 : tbl_data->is_transfer = !!key.is_fdb;
11834 : 0 : tbl_data->dummy = !!key.dummy;
11835 : 0 : tbl_data->level = key.level;
11836 : 0 : tbl_data->id = key.id;
11837 : : tbl = &tbl_data->tbl;
11838 [ # # ]: 0 : if (key.dummy)
11839 : 0 : return &tbl_data->entry;
11840 [ # # ]: 0 : if (key.is_fdb)
11841 : 0 : domain = sh->fdb_domain;
11842 [ # # ]: 0 : else if (key.is_egress)
11843 : 0 : domain = sh->tx_domain;
11844 : : else
11845 : 0 : domain = sh->rx_domain;
11846 : : ret = mlx5_flow_os_create_flow_tbl(domain, key.level, &tbl->obj);
11847 : : if (ret) {
11848 : 0 : rte_flow_error_set(error, ENOMEM,
11849 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11850 : : NULL, "cannot create flow table object");
11851 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
11852 : 0 : return NULL;
11853 : : }
11854 [ # # ]: 0 : if (key.level != 0) {
11855 : : ret = mlx5_flow_os_create_flow_action_dest_flow_tbl
11856 : : (tbl->obj, &tbl_data->jump.action);
11857 : : if (ret) {
11858 : 0 : rte_flow_error_set(error, ENOMEM,
11859 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11860 : : NULL,
11861 : : "cannot create flow jump action");
11862 : 0 : mlx5_flow_os_destroy_flow_tbl(tbl->obj);
11863 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
11864 : 0 : return NULL;
11865 : : }
11866 : : }
11867 [ # # # # ]: 0 : MKSTR(matcher_name, "%s_%s_%u_%u_matcher_list",
11868 : : key.is_fdb ? "FDB" : "NIC", key.is_egress ? "egress" : "ingress",
11869 : : key.level, key.id);
11870 : 0 : tbl_data->matchers = mlx5_list_create(matcher_name, sh, true,
11871 : : mlx5_flow_matcher_create_cb,
11872 : : mlx5_flow_matcher_match_cb,
11873 : : mlx5_flow_matcher_remove_cb,
11874 : : mlx5_flow_matcher_clone_cb,
11875 : : mlx5_flow_matcher_clone_free_cb);
11876 [ # # ]: 0 : if (!tbl_data->matchers) {
11877 : 0 : rte_flow_error_set(error, ENOMEM,
11878 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11879 : : NULL,
11880 : : "cannot create tbl matcher list");
11881 : 0 : mlx5_flow_os_destroy_flow_action(tbl_data->jump.action);
11882 : 0 : mlx5_flow_os_destroy_flow_tbl(tbl->obj);
11883 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
11884 : 0 : return NULL;
11885 : : }
11886 : 0 : return &tbl_data->entry;
11887 : : }
11888 : :
11889 : : int
11890 : 0 : mlx5_flow_dv_tbl_match_cb(void *tool_ctx __rte_unused, struct mlx5_list_entry *entry,
11891 : : void *cb_ctx)
11892 : : {
11893 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11894 : : struct mlx5_flow_tbl_data_entry *tbl_data =
11895 : : container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
11896 : 0 : union mlx5_flow_tbl_key key = { .v64 = *(uint64_t *)(ctx->data) };
11897 : :
11898 : 0 : return tbl_data->level != key.level ||
11899 [ # # ]: 0 : tbl_data->id != key.id ||
11900 [ # # ]: 0 : tbl_data->dummy != key.dummy ||
11901 [ # # # # ]: 0 : tbl_data->is_transfer != !!key.is_fdb ||
11902 [ # # ]: 0 : tbl_data->is_egress != !!key.is_egress;
11903 : : }
11904 : :
11905 : : struct mlx5_list_entry *
11906 : 0 : mlx5_flow_dv_tbl_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
11907 : : void *cb_ctx)
11908 : : {
11909 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11910 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11911 : : struct mlx5_flow_tbl_data_entry *tbl_data;
11912 : 0 : struct rte_flow_error *error = ctx->error;
11913 : 0 : uint32_t idx = 0;
11914 : : struct mlx5_flow_tbl_data_entry *old_resource;
11915 : :
11916 : 0 : tbl_data = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_JUMP], &idx);
11917 [ # # ]: 0 : if (!tbl_data) {
11918 : 0 : rte_flow_error_set(error, ENOMEM,
11919 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11920 : : NULL,
11921 : : "cannot allocate flow table data entry");
11922 : 0 : return NULL;
11923 : : }
11924 : : old_resource = container_of(oentry, typeof(*old_resource), entry);
11925 : : memcpy(tbl_data, old_resource, sizeof(*tbl_data));
11926 : 0 : tbl_data->idx = idx;
11927 : 0 : return &tbl_data->entry;
11928 : : }
11929 : :
11930 : : void
11931 : 0 : mlx5_flow_dv_tbl_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
11932 : : {
11933 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11934 : : struct mlx5_flow_tbl_data_entry *tbl_data =
11935 : : container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
11936 : :
11937 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], tbl_data->idx);
11938 : 0 : }
11939 : :
11940 : : /**
11941 : : * Get a flow table.
11942 : : *
11943 : : * @param[in, out] dev
11944 : : * Pointer to rte_eth_dev structure.
11945 : : * @param[in] table_level
11946 : : * Table level to use.
11947 : : * @param[in] egress
11948 : : * Direction of the table.
11949 : : * @param[in] transfer
11950 : : * E-Switch or NIC flow.
11951 : : * @param[in] dummy
11952 : : * Dummy entry for dv API.
11953 : : * @param[in] table_id
11954 : : * Table id to use.
11955 : : * @param[out] error
11956 : : * pointer to error structure.
11957 : : *
11958 : : * @return
11959 : : * Returns tables resource based on the index, NULL in case of failed.
11960 : : */
11961 : : struct mlx5_flow_tbl_resource *
11962 : 0 : mlx5_flow_dv_tbl_resource_get(struct rte_eth_dev *dev,
11963 : : uint32_t table_level, uint8_t egress,
11964 : : uint8_t transfer,
11965 : : bool external,
11966 : : const struct mlx5_flow_tunnel *tunnel,
11967 : : uint32_t group_id, uint8_t dummy,
11968 : : uint32_t table_id,
11969 : : struct rte_flow_error *error)
11970 : : {
11971 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11972 : 0 : union mlx5_flow_tbl_key table_key = {
11973 : : {
11974 : : .level = table_level,
11975 : : .id = table_id,
11976 : : .reserved = 0,
11977 : 0 : .dummy = !!dummy,
11978 : 0 : .is_fdb = !!transfer,
11979 : 0 : .is_egress = !!egress,
11980 : : }
11981 : : };
11982 : 0 : struct mlx5_flow_tbl_tunnel_prm tt_prm = {
11983 : : .tunnel = tunnel,
11984 : : .group_id = group_id,
11985 : : .external = external,
11986 : : };
11987 : 0 : struct mlx5_flow_cb_ctx ctx = {
11988 : : .dev = dev,
11989 : : .error = error,
11990 : : .data = &table_key.v64,
11991 : : .data2 = &tt_prm,
11992 : : };
11993 : : struct mlx5_list_entry *entry;
11994 : : struct mlx5_flow_tbl_data_entry *tbl_data;
11995 : :
11996 : 0 : entry = mlx5_hlist_register(priv->sh->flow_tbls, table_key.v64, &ctx);
11997 [ # # ]: 0 : if (!entry) {
11998 : 0 : rte_flow_error_set(error, ENOMEM,
11999 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12000 : : "cannot get table");
12001 : 0 : return NULL;
12002 : : }
12003 [ # # ]: 0 : DRV_LOG(DEBUG, "table_level %u table_id %u "
12004 : : "tunnel %u group %u registered.",
12005 : : table_level, table_id,
12006 : : tunnel ? tunnel->tunnel_id : 0, group_id);
12007 : : tbl_data = container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
12008 : 0 : return &tbl_data->tbl;
12009 : : }
12010 : :
12011 : : void
12012 : 0 : mlx5_flow_dv_tbl_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
12013 : : {
12014 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
12015 : : struct mlx5_flow_tbl_data_entry *tbl_data =
12016 : : container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
12017 : :
12018 : : MLX5_ASSERT(entry && sh);
12019 [ # # ]: 0 : if (tbl_data->jump.action)
12020 : : mlx5_flow_os_destroy_flow_action(tbl_data->jump.action);
12021 [ # # ]: 0 : if (tbl_data->tbl.obj)
12022 : : mlx5_flow_os_destroy_flow_tbl(tbl_data->tbl.obj);
12023 [ # # ]: 0 : if (tbl_data->tunnel_offload && tbl_data->external) {
12024 : : struct mlx5_list_entry *he;
12025 : : struct mlx5_hlist *tunnel_grp_hash;
12026 : 0 : struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
12027 : 0 : union tunnel_tbl_key tunnel_key = {
12028 : 0 : .tunnel_id = tbl_data->tunnel ?
12029 [ # # ]: 0 : tbl_data->tunnel->tunnel_id : 0,
12030 : 0 : .group = tbl_data->group_id
12031 : : };
12032 : 0 : uint32_t table_level = tbl_data->level;
12033 : 0 : struct mlx5_flow_cb_ctx ctx = {
12034 : : .data = (void *)&tunnel_key.val,
12035 : : };
12036 : :
12037 : : tunnel_grp_hash = tbl_data->tunnel ?
12038 [ # # ]: 0 : tbl_data->tunnel->groups :
12039 : : thub->groups;
12040 : 0 : he = mlx5_hlist_lookup(tunnel_grp_hash, tunnel_key.val, &ctx);
12041 [ # # ]: 0 : if (he)
12042 : 0 : mlx5_hlist_unregister(tunnel_grp_hash, he);
12043 [ # # ]: 0 : DRV_LOG(DEBUG,
12044 : : "table_level %u id %u tunnel %u group %u released.",
12045 : : table_level,
12046 : : tbl_data->id,
12047 : : tbl_data->tunnel ?
12048 : : tbl_data->tunnel->tunnel_id : 0,
12049 : : tbl_data->group_id);
12050 : : }
12051 [ # # ]: 0 : if (tbl_data->matchers)
12052 : 0 : mlx5_list_destroy(tbl_data->matchers);
12053 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], tbl_data->idx);
12054 : 0 : }
12055 : :
12056 : : /**
12057 : : * Release a flow table.
12058 : : *
12059 : : * @param[in] sh
12060 : : * Pointer to device shared structure.
12061 : : * @param[in] tbl
12062 : : * Table resource to be released.
12063 : : *
12064 : : * @return
12065 : : * Returns 0 if table was released, else return 1;
12066 : : */
12067 : : int
12068 : 0 : mlx5_flow_dv_tbl_resource_release(struct mlx5_dev_ctx_shared *sh,
12069 : : struct mlx5_flow_tbl_resource *tbl)
12070 : : {
12071 : : struct mlx5_flow_tbl_data_entry *tbl_data =
12072 : 0 : container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
12073 : :
12074 [ # # ]: 0 : if (!tbl)
12075 : : return 0;
12076 : 0 : return mlx5_hlist_unregister(sh->flow_tbls, &tbl_data->entry);
12077 : : }
12078 : :
12079 : : int
12080 : 0 : mlx5_flow_matcher_match_cb(void *tool_ctx __rte_unused,
12081 : : struct mlx5_list_entry *entry, void *cb_ctx)
12082 : : {
12083 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12084 : 0 : struct mlx5_flow_dv_matcher *ref = ctx->data;
12085 : : struct mlx5_flow_dv_matcher *cur = container_of(entry, typeof(*cur),
12086 : : entry);
12087 : :
12088 : 0 : return cur->crc != ref->crc ||
12089 [ # # ]: 0 : cur->priority != ref->priority ||
12090 : 0 : memcmp((const void *)cur->mask.buf,
12091 [ # # ]: 0 : (const void *)ref->mask.buf, ref->mask.size);
12092 : : }
12093 : :
12094 : : struct mlx5_list_entry *
12095 : 0 : mlx5_flow_matcher_create_cb(void *tool_ctx, void *cb_ctx)
12096 : : {
12097 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
12098 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12099 : 0 : struct mlx5_flow_dv_matcher *ref = ctx->data;
12100 : : struct mlx5_flow_dv_matcher *resource;
12101 : : #ifdef HAVE_MLX5_HWS_SUPPORT
12102 : : const struct rte_flow_item *items;
12103 : : #endif
12104 : 0 : struct mlx5dv_flow_matcher_attr dv_attr = {
12105 : : .type = IBV_FLOW_ATTR_NORMAL,
12106 : 0 : .match_mask = (void *)&ref->mask,
12107 : : };
12108 : : struct mlx5_flow_tbl_data_entry *tbl;
12109 : : int ret;
12110 : :
12111 : 0 : resource = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*resource), 0,
12112 : : SOCKET_ID_ANY);
12113 [ # # ]: 0 : if (!resource) {
12114 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12115 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12116 : : "cannot create matcher");
12117 : 0 : return NULL;
12118 : : }
12119 : 0 : *resource = *ref;
12120 [ # # ]: 0 : if (sh->config.dv_flow_en != 2) {
12121 : 0 : tbl = container_of(ref->tbl, typeof(*tbl), tbl);
12122 : 0 : dv_attr.match_criteria_enable =
12123 [ # # ]: 0 : flow_dv_matcher_enable(resource->mask.buf);
12124 : : __flow_dv_adjust_buf_size(&ref->mask.size,
12125 : : dv_attr.match_criteria_enable);
12126 : 0 : dv_attr.priority = ref->priority;
12127 [ # # ]: 0 : if (tbl->is_egress)
12128 : 0 : dv_attr.flags |= IBV_FLOW_ATTR_FLAGS_EGRESS;
12129 : 0 : ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
12130 : : tbl->tbl.obj,
12131 : : &resource->matcher_object);
12132 : : if (ret) {
12133 : 0 : mlx5_free(resource);
12134 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12135 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12136 : : "cannot create matcher");
12137 : 0 : return NULL;
12138 : : }
12139 : : } else {
12140 : : #ifdef HAVE_MLX5_HWS_SUPPORT
12141 : 0 : items = *((const struct rte_flow_item **)(ctx->data2));
12142 [ # # ]: 0 : if (!items)
12143 : 0 : goto error;
12144 : 0 : resource->matcher_object = mlx5dr_bwc_matcher_create
12145 : 0 : (resource->group->tbl, resource->priority, items);
12146 [ # # ]: 0 : if (!resource->matcher_object)
12147 : 0 : goto error;
12148 : : #else
12149 : : goto error;
12150 : : #endif
12151 : : }
12152 : 0 : return &resource->entry;
12153 : 0 : error:
12154 : 0 : mlx5_free(resource);
12155 : 0 : return NULL;
12156 : : }
12157 : :
12158 : : /**
12159 : : * Register the flow matcher.
12160 : : *
12161 : : * @param[in, out] dev
12162 : : * Pointer to rte_eth_dev structure.
12163 : : * @param[in, out] matcher
12164 : : * Pointer to flow matcher.
12165 : : * @param[in, out] key
12166 : : * Pointer to flow table key.
12167 : : * @parm[in, out] dev_flow
12168 : : * Pointer to the dev_flow.
12169 : : * @param[out] error
12170 : : * pointer to error structure.
12171 : : *
12172 : : * @return
12173 : : * 0 on success otherwise -errno and errno is set.
12174 : : */
12175 : : static int
12176 : 0 : flow_dv_matcher_register(struct rte_eth_dev *dev,
12177 : : struct mlx5_flow_dv_matcher *ref,
12178 : : union mlx5_flow_tbl_key *key,
12179 : : struct mlx5_flow *dev_flow,
12180 : : const struct mlx5_flow_tunnel *tunnel,
12181 : : uint32_t group_id,
12182 : : struct rte_flow_error *error)
12183 : : {
12184 : : struct mlx5_list_entry *entry;
12185 : : struct mlx5_flow_dv_matcher *resource;
12186 : : struct mlx5_flow_tbl_resource *tbl;
12187 : : struct mlx5_flow_tbl_data_entry *tbl_data;
12188 : 0 : struct mlx5_flow_cb_ctx ctx = {
12189 : : .error = error,
12190 : : .data = ref,
12191 : : };
12192 : : /**
12193 : : * tunnel offload API requires this registration for cases when
12194 : : * tunnel match rule was inserted before tunnel set rule.
12195 : : */
12196 : 0 : tbl = mlx5_flow_dv_tbl_resource_get(dev, key->level,
12197 : 0 : key->is_egress, key->is_fdb,
12198 : 0 : dev_flow->external, tunnel,
12199 : 0 : group_id, 0, key->id, error);
12200 [ # # ]: 0 : if (!tbl)
12201 : 0 : return -rte_errno; /* No need to refill the error info */
12202 : 0 : tbl_data = container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
12203 : 0 : ref->tbl = tbl;
12204 : 0 : entry = mlx5_list_register(tbl_data->matchers, &ctx);
12205 [ # # ]: 0 : if (!entry) {
12206 : 0 : mlx5_flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
12207 : 0 : return rte_flow_error_set(error, ENOMEM,
12208 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12209 : : "cannot allocate ref memory");
12210 : : }
12211 : : resource = container_of(entry, typeof(*resource), entry);
12212 : 0 : dev_flow->handle->dvh.matcher = resource;
12213 : 0 : return 0;
12214 : : }
12215 : :
12216 : : struct mlx5_list_entry *
12217 : 0 : mlx5_flow_dv_tag_create_cb(void *tool_ctx, void *cb_ctx)
12218 : : {
12219 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
12220 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12221 : : struct mlx5_flow_dv_tag_resource *entry;
12222 : 0 : uint32_t idx = 0;
12223 : : int ret;
12224 : :
12225 : 0 : entry = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_TAG], &idx);
12226 [ # # ]: 0 : if (!entry) {
12227 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12228 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12229 : : "cannot allocate resource memory");
12230 : 0 : return NULL;
12231 : : }
12232 : 0 : entry->idx = idx;
12233 : 0 : entry->tag_id = *(uint32_t *)(ctx->data);
12234 : : ret = mlx5_flow_os_create_flow_action_tag(entry->tag_id,
12235 : : &entry->action);
12236 : : if (ret) {
12237 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], idx);
12238 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12239 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12240 : : NULL, "cannot create action");
12241 : 0 : return NULL;
12242 : : }
12243 : 0 : return &entry->entry;
12244 : : }
12245 : :
12246 : : int
12247 : 0 : mlx5_flow_dv_tag_match_cb(void *tool_ctx __rte_unused, struct mlx5_list_entry *entry,
12248 : : void *cb_ctx)
12249 : : {
12250 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12251 : : struct mlx5_flow_dv_tag_resource *tag =
12252 : : container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
12253 : :
12254 : 0 : return *(uint32_t *)(ctx->data) != tag->tag_id;
12255 : : }
12256 : :
12257 : : struct mlx5_list_entry *
12258 : 0 : mlx5_flow_dv_tag_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
12259 : : void *cb_ctx)
12260 : : {
12261 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
12262 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12263 : : struct mlx5_flow_dv_tag_resource *entry;
12264 : : struct mlx5_flow_dv_tag_resource *old_entry;
12265 : 0 : uint32_t idx = 0;
12266 : :
12267 : 0 : entry = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_TAG], &idx);
12268 [ # # ]: 0 : if (!entry) {
12269 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12270 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12271 : : "cannot allocate tag resource memory");
12272 : 0 : return NULL;
12273 : : }
12274 : : old_entry = container_of(oentry, typeof(*old_entry), entry);
12275 : : memcpy(entry, old_entry, sizeof(*entry));
12276 : 0 : entry->idx = idx;
12277 : 0 : return &entry->entry;
12278 : : }
12279 : :
12280 : : void
12281 : 0 : mlx5_flow_dv_tag_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
12282 : : {
12283 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
12284 : : struct mlx5_flow_dv_tag_resource *tag =
12285 : : container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
12286 : :
12287 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], tag->idx);
12288 : 0 : }
12289 : :
12290 : : /**
12291 : : * Find existing tag resource or create and register a new one.
12292 : : *
12293 : : * @param dev[in, out]
12294 : : * Pointer to rte_eth_dev structure.
12295 : : * @param[in, out] tag_be24
12296 : : * Tag value in big endian then R-shift 8.
12297 : : * @parm[in, out] dev_flow
12298 : : * Pointer to the dev_flow.
12299 : : * @param[out] error
12300 : : * pointer to error structure.
12301 : : *
12302 : : * @return
12303 : : * 0 on success otherwise -errno and errno is set.
12304 : : */
12305 : : static int
12306 : 0 : flow_dv_tag_resource_register
12307 : : (struct rte_eth_dev *dev,
12308 : : uint32_t tag_be24,
12309 : : struct mlx5_flow *dev_flow,
12310 : : struct rte_flow_error *error)
12311 : : {
12312 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12313 : : struct mlx5_flow_dv_tag_resource *resource;
12314 : : struct mlx5_list_entry *entry;
12315 : 0 : struct mlx5_flow_cb_ctx ctx = {
12316 : : .error = error,
12317 : : .data = &tag_be24,
12318 : : };
12319 : : struct mlx5_hlist *tag_table;
12320 : :
12321 : 0 : tag_table = flow_dv_hlist_prepare(priv->sh, &priv->sh->tag_table,
12322 : : "tags",
12323 : : MLX5_TAGS_HLIST_ARRAY_SIZE,
12324 : 0 : false, false, priv->sh,
12325 : : mlx5_flow_dv_tag_create_cb,
12326 : : mlx5_flow_dv_tag_match_cb,
12327 : : mlx5_flow_dv_tag_remove_cb,
12328 : : mlx5_flow_dv_tag_clone_cb,
12329 : : mlx5_flow_dv_tag_clone_free_cb,
12330 : : error);
12331 [ # # ]: 0 : if (unlikely(!tag_table))
12332 : 0 : return -rte_errno;
12333 : 0 : entry = mlx5_hlist_register(tag_table, tag_be24, &ctx);
12334 [ # # ]: 0 : if (entry) {
12335 : : resource = container_of(entry, struct mlx5_flow_dv_tag_resource,
12336 : : entry);
12337 : 0 : dev_flow->handle->dvh.rix_tag = resource->idx;
12338 : 0 : dev_flow->dv.tag_resource = resource;
12339 : 0 : return 0;
12340 : : }
12341 : 0 : return -rte_errno;
12342 : : }
12343 : :
12344 : : void
12345 : 0 : mlx5_flow_dv_tag_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
12346 : : {
12347 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
12348 : : struct mlx5_flow_dv_tag_resource *tag =
12349 : : container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
12350 : :
12351 : : MLX5_ASSERT(tag && sh && tag->action);
12352 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(tag->action));
12353 : 0 : DRV_LOG(DEBUG, "Tag %p: removed.", (void *)tag);
12354 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], tag->idx);
12355 : 0 : }
12356 : :
12357 : : /**
12358 : : * Release the tag.
12359 : : *
12360 : : * @param dev
12361 : : * Pointer to Ethernet device.
12362 : : * @param tag_idx
12363 : : * Tag index.
12364 : : *
12365 : : * @return
12366 : : * 1 while a reference on it exists, 0 when freed.
12367 : : */
12368 : : static int
12369 : 0 : flow_dv_tag_release(struct rte_eth_dev *dev,
12370 : : uint32_t tag_idx)
12371 : : {
12372 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12373 : : struct mlx5_flow_dv_tag_resource *tag;
12374 : :
12375 : 0 : tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG], tag_idx);
12376 [ # # ]: 0 : if (!tag)
12377 : : return 0;
12378 : 0 : DRV_LOG(DEBUG, "port %u tag %p: refcnt %d--",
12379 : : dev->data->port_id, (void *)tag, tag->entry.ref_cnt);
12380 : 0 : return mlx5_hlist_unregister(priv->sh->tag_table, &tag->entry);
12381 : : }
12382 : :
12383 : : /**
12384 : : * Translate action PORT_ID / REPRESENTED_PORT to vport.
12385 : : *
12386 : : * @param[in] dev
12387 : : * Pointer to rte_eth_dev structure.
12388 : : * @param[in] action
12389 : : * Pointer to action PORT_ID / REPRESENTED_PORT.
12390 : : * @param[out] dst_port_id
12391 : : * The target port ID.
12392 : : * @param[out] error
12393 : : * Pointer to the error structure.
12394 : : *
12395 : : * @return
12396 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
12397 : : */
12398 : : static int
12399 : 0 : flow_dv_translate_action_port_id(struct rte_eth_dev *dev,
12400 : : const struct rte_flow_action *action,
12401 : : uint32_t *dst_port_id,
12402 : : struct rte_flow_error *error)
12403 : : {
12404 : : uint32_t port;
12405 : : struct mlx5_priv *priv;
12406 : :
12407 [ # # # ]: 0 : switch (action->type) {
12408 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID: {
12409 : : const struct rte_flow_action_port_id *conf;
12410 : :
12411 : 0 : conf = (const struct rte_flow_action_port_id *)action->conf;
12412 [ # # ]: 0 : port = conf->original ? dev->data->port_id : conf->id;
12413 : : break;
12414 : : }
12415 : 0 : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT: {
12416 : : const struct rte_flow_action_ethdev *ethdev;
12417 : :
12418 : 0 : ethdev = (const struct rte_flow_action_ethdev *)action->conf;
12419 : 0 : port = ethdev->port_id;
12420 : 0 : break;
12421 : : }
12422 : 0 : default:
12423 : : MLX5_ASSERT(false);
12424 : 0 : return rte_flow_error_set(error, EINVAL,
12425 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
12426 : : "unknown E-Switch action");
12427 : : }
12428 : :
12429 : 0 : priv = mlx5_port_to_eswitch_info(port, false);
12430 [ # # ]: 0 : if (!priv)
12431 : 0 : return rte_flow_error_set(error, -rte_errno,
12432 : : RTE_FLOW_ERROR_TYPE_ACTION,
12433 : : NULL,
12434 : : "No eswitch info was found for port");
12435 : : #ifdef HAVE_MLX5DV_DR_CREATE_DEST_IB_PORT
12436 : : /*
12437 : : * This parameter is transferred to
12438 : : * mlx5dv_dr_action_create_dest_ib_port().
12439 : : */
12440 : 0 : *dst_port_id = priv->dev_port;
12441 : : #else
12442 : : /*
12443 : : * Legacy mode, no LAG configurations is supported.
12444 : : * This parameter is transferred to
12445 : : * mlx5dv_dr_action_create_dest_vport().
12446 : : */
12447 : : *dst_port_id = priv->vport_id;
12448 : : #endif
12449 : 0 : return 0;
12450 : : }
12451 : :
12452 : : /**
12453 : : * Create a counter with aging configuration.
12454 : : *
12455 : : * @param[in] dev
12456 : : * Pointer to rte_eth_dev structure.
12457 : : * @param[in] dev_flow
12458 : : * Pointer to the mlx5_flow.
12459 : : * @param[out] count
12460 : : * Pointer to the counter action configuration.
12461 : : * @param[in] age
12462 : : * Pointer to the aging action configuration.
12463 : : *
12464 : : * @return
12465 : : * Index to flow counter on success, 0 otherwise.
12466 : : */
12467 : : static uint32_t
12468 : 0 : flow_dv_translate_create_counter(struct rte_eth_dev *dev,
12469 : : struct mlx5_flow *dev_flow,
12470 : : const struct rte_flow_action_count *count
12471 : : __rte_unused,
12472 : : const struct rte_flow_action_age *age)
12473 : : {
12474 : : uint32_t counter;
12475 : : struct mlx5_age_param *age_param;
12476 : :
12477 : 0 : counter = flow_dv_counter_alloc(dev, !!age);
12478 [ # # ]: 0 : if (!counter || age == NULL)
12479 : : return counter;
12480 : : age_param = flow_dv_counter_idx_get_age(dev, counter);
12481 [ # # ]: 0 : age_param->context = age->context ? age->context :
12482 : 0 : (void *)(uintptr_t)(dev_flow->flow_idx);
12483 : 0 : age_param->timeout = age->timeout;
12484 : 0 : age_param->port_id = dev->data->port_id;
12485 : 0 : rte_atomic_store_explicit(&age_param->sec_since_last_hit, 0, rte_memory_order_relaxed);
12486 : 0 : rte_atomic_store_explicit(&age_param->state, AGE_CANDIDATE, rte_memory_order_relaxed);
12487 : 0 : return counter;
12488 : : }
12489 : :
12490 : : /**
12491 : : * Add Tx queue matcher
12492 : : *
12493 : : * @param[in] dev
12494 : : * Pointer to rte_eth_dev structure.
12495 : : * @param[in, out] key
12496 : : * Flow matcher value.
12497 : : * @param[in] item
12498 : : * Flow pattern to translate.
12499 : : * @param[in] key_type
12500 : : * Set flow matcher mask or value.
12501 : : *
12502 : : * @return
12503 : : * 0 on success otherwise -errno and errno is set.
12504 : : */
12505 : : static int
12506 : 0 : flow_dv_translate_item_tx_queue(struct rte_eth_dev *dev, void *key,
12507 : : const struct rte_flow_item *item, uint32_t key_type)
12508 : : {
12509 : : const struct rte_flow_item_tx_queue *queue_m;
12510 : : const struct rte_flow_item_tx_queue *queue_v;
12511 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
12512 : : uint32_t tx_queue;
12513 : : uint32_t sqn = 0;
12514 : : int ret;
12515 : :
12516 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, queue_v, queue_m, &rte_flow_item_tx_queue_mask);
# # # # ]
12517 [ # # ]: 0 : if (!queue_m || !queue_v)
12518 : : return -EINVAL;
12519 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_V) {
12520 : 0 : tx_queue = queue_v->tx_queue;
12521 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_V)
12522 : 0 : tx_queue &= queue_m->tx_queue;
12523 [ # # ]: 0 : ret = flow_hw_get_sqn(dev, tx_queue, &sqn);
12524 [ # # ]: 0 : if (unlikely(ret))
12525 : 0 : return -ret;
12526 : : } else {
12527 : : /* Due to tx_queue to sqn converting, only fully masked value support. */
12528 [ # # ]: 0 : if (queue_m->tx_queue != rte_flow_item_tx_queue_mask.tx_queue)
12529 : : return -EINVAL;
12530 : : sqn = UINT32_MAX;
12531 : : }
12532 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, source_sqn, sqn);
12533 : 0 : return 0;
12534 : : }
12535 : :
12536 : : /**
12537 : : * Add SQ matcher
12538 : : *
12539 : : * @param[in, out] matcher
12540 : : * Flow matcher.
12541 : : * @param[in, out] key
12542 : : * Flow matcher value.
12543 : : * @param[in] item
12544 : : * Flow pattern to translate.
12545 : : * @param[in] key_type
12546 : : * Set flow matcher mask or value.
12547 : : */
12548 : : static void
12549 : 0 : flow_dv_translate_item_sq(void *key,
12550 : : const struct rte_flow_item *item,
12551 : : uint32_t key_type)
12552 : : {
12553 : : const struct mlx5_rte_flow_item_sq *queue_m;
12554 : : const struct mlx5_rte_flow_item_sq *queue_v;
12555 : 0 : const struct mlx5_rte_flow_item_sq queue_mask = {
12556 : : .queue = UINT32_MAX,
12557 : : };
12558 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
12559 : : uint32_t queue;
12560 : :
12561 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, queue_v, queue_m, &queue_mask);
# # # # ]
12562 [ # # ]: 0 : if (!queue_m || !queue_v)
12563 : 0 : return;
12564 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_V) {
12565 : 0 : queue = queue_v->queue;
12566 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_V)
12567 : 0 : queue &= queue_m->queue;
12568 : : } else {
12569 : 0 : queue = queue_m->queue;
12570 : : }
12571 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, source_sqn, queue);
12572 : : }
12573 : :
12574 : : /**
12575 : : * Set the hash fields according to the @p flow information.
12576 : : *
12577 : : * @param[in] item_flags
12578 : : * The match pattern item flags.
12579 : : * @param[in] rss_desc
12580 : : * Pointer to the mlx5_flow_rss_desc.
12581 : : * @param[out] hash_fields
12582 : : * Pointer to the RSS hash fields.
12583 : : */
12584 : : void
12585 : 0 : mlx5_flow_dv_hashfields_set(uint64_t item_flags,
12586 : : struct mlx5_flow_rss_desc *rss_desc,
12587 : : uint64_t *hash_fields)
12588 : : {
12589 : : uint64_t items = item_flags;
12590 : : uint64_t fields = 0;
12591 : : int rss_inner = 0;
12592 [ # # ]: 0 : uint64_t rss_types = rte_eth_rss_hf_refine(rss_desc->types);
12593 : :
12594 : : *hash_fields = 0;
12595 : : #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
12596 [ # # ]: 0 : if (rss_desc->level >= 2)
12597 : : rss_inner = 1;
12598 : : #endif
12599 [ # # # # ]: 0 : if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV4)) ||
12600 [ # # ]: 0 : (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV4))) {
12601 [ # # ]: 0 : if (rss_types & MLX5_IPV4_LAYER_TYPES) {
12602 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
12603 : : fields |= IBV_RX_HASH_SRC_IPV4;
12604 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
12605 : : fields |= IBV_RX_HASH_DST_IPV4;
12606 : : else
12607 : : fields |= MLX5_IPV4_IBV_RX_HASH;
12608 : : }
12609 [ # # # # : 0 : } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
# # ]
12610 [ # # ]: 0 : (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV6))) {
12611 [ # # ]: 0 : if (rss_types & MLX5_IPV6_LAYER_TYPES) {
12612 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
12613 : : fields |= IBV_RX_HASH_SRC_IPV6;
12614 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
12615 : : fields |= IBV_RX_HASH_DST_IPV6;
12616 : : else
12617 : : fields |= MLX5_IPV6_IBV_RX_HASH;
12618 : : }
12619 : : }
12620 [ # # ]: 0 : if (items & MLX5_FLOW_ITEM_ESP) {
12621 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_ESP)
12622 : 0 : fields |= IBV_RX_HASH_IPSEC_SPI;
12623 : : }
12624 [ # # ]: 0 : if ((fields & ~IBV_RX_HASH_IPSEC_SPI) == 0) {
12625 : 0 : *hash_fields = fields;
12626 : : /*
12627 : : * There is no match between the RSS types and the
12628 : : * L3 protocol (IPv4/IPv6) defined in the flow rule.
12629 : : */
12630 : 0 : return;
12631 : : }
12632 [ # # # # : 0 : if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_UDP)) ||
# # ]
12633 [ # # ]: 0 : (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_UDP))) {
12634 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_UDP) {
12635 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
12636 : 0 : fields |= IBV_RX_HASH_SRC_PORT_UDP;
12637 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
12638 : 0 : fields |= IBV_RX_HASH_DST_PORT_UDP;
12639 : : else
12640 : 0 : fields |= MLX5_UDP_IBV_RX_HASH;
12641 : : }
12642 [ # # # # : 0 : } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_TCP)) ||
# # ]
12643 [ # # ]: 0 : (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_TCP))) {
12644 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_TCP) {
12645 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
12646 : 0 : fields |= IBV_RX_HASH_SRC_PORT_TCP;
12647 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
12648 : 0 : fields |= IBV_RX_HASH_DST_PORT_TCP;
12649 : : else
12650 : 0 : fields |= MLX5_TCP_IBV_RX_HASH;
12651 : : }
12652 : : }
12653 [ # # ]: 0 : if (rss_inner)
12654 : 0 : fields |= IBV_RX_HASH_INNER;
12655 : 0 : *hash_fields = fields;
12656 : : }
12657 : :
12658 : : /**
12659 : : * Prepare an Rx Hash queue.
12660 : : *
12661 : : * @param dev
12662 : : * Pointer to Ethernet device.
12663 : : * @param[in] dev_flow
12664 : : * Pointer to the mlx5_flow.
12665 : : * @param[in] rss_desc
12666 : : * Pointer to the mlx5_flow_rss_desc.
12667 : : * @param[out] hrxq_idx
12668 : : * Hash Rx queue index.
12669 : : *
12670 : : * @return
12671 : : * The Verbs/DevX object initialised, NULL otherwise and rte_errno is set.
12672 : : */
12673 : : static struct mlx5_hrxq *
12674 : 0 : flow_dv_hrxq_prepare(struct rte_eth_dev *dev,
12675 : : struct mlx5_flow *dev_flow,
12676 : : struct mlx5_flow_rss_desc *rss_desc,
12677 : : uint32_t *hrxq_idx)
12678 : : {
12679 : 0 : struct mlx5_flow_handle *dh = dev_flow->handle;
12680 : 0 : uint32_t shared_rss = rss_desc->shared_rss;
12681 : : struct mlx5_hrxq *hrxq;
12682 : :
12683 : : MLX5_ASSERT(rss_desc->queue_num);
12684 : 0 : rss_desc->symmetric_hash_function = dev_flow->symmetric_hash_function;
12685 : 0 : rss_desc->key_len = MLX5_RSS_HASH_KEY_LEN;
12686 : 0 : rss_desc->hash_fields = dev_flow->hash_fields;
12687 : 0 : rss_desc->tunnel = !!(dh->layers & MLX5_FLOW_LAYER_TUNNEL);
12688 : 0 : rss_desc->shared_rss = 0;
12689 [ # # ]: 0 : if (rss_desc->hash_fields == 0)
12690 : 0 : rss_desc->queue_num = 1;
12691 : 0 : hrxq = mlx5_hrxq_get(dev, rss_desc);
12692 [ # # ]: 0 : *hrxq_idx = hrxq ? hrxq->idx : 0;
12693 : 0 : rss_desc->shared_rss = shared_rss;
12694 : 0 : return hrxq;
12695 : : }
12696 : :
12697 : : /**
12698 : : * Release sample sub action resource.
12699 : : *
12700 : : * @param[in, out] dev
12701 : : * Pointer to rte_eth_dev structure.
12702 : : * @param[in] act_res
12703 : : * Pointer to sample sub action resource.
12704 : : */
12705 : : static void
12706 : 0 : flow_dv_sample_sub_actions_release(struct rte_eth_dev *dev,
12707 : : struct mlx5_flow_sub_actions_idx *act_res)
12708 : : {
12709 [ # # ]: 0 : if (act_res->rix_hrxq) {
12710 : 0 : mlx5_hrxq_release(dev, act_res->rix_hrxq);
12711 : 0 : act_res->rix_hrxq = 0;
12712 : : }
12713 [ # # ]: 0 : if (act_res->rix_encap_decap) {
12714 : 0 : mlx5_flow_encap_decap_resource_release(dev, act_res->rix_encap_decap);
12715 : 0 : act_res->rix_encap_decap = 0;
12716 : : }
12717 [ # # ]: 0 : if (act_res->rix_port_id_action) {
12718 : 0 : flow_dv_port_id_action_resource_release(dev,
12719 : : act_res->rix_port_id_action);
12720 : 0 : act_res->rix_port_id_action = 0;
12721 : : }
12722 [ # # ]: 0 : if (act_res->rix_tag) {
12723 : 0 : flow_dv_tag_release(dev, act_res->rix_tag);
12724 : 0 : act_res->rix_tag = 0;
12725 : : }
12726 [ # # ]: 0 : if (act_res->rix_jump) {
12727 : 0 : flow_dv_jump_tbl_resource_release(dev, act_res->rix_jump);
12728 : 0 : act_res->rix_jump = 0;
12729 : : }
12730 : 0 : }
12731 : :
12732 : : int
12733 : 0 : mlx5_flow_dv_sample_match_cb(void *tool_ctx __rte_unused,
12734 : : struct mlx5_list_entry *entry, void *cb_ctx)
12735 : : {
12736 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12737 : 0 : struct rte_eth_dev *dev = ctx->dev;
12738 : 0 : struct mlx5_flow_dv_sample_resource *ctx_resource = ctx->data;
12739 : : struct mlx5_flow_dv_sample_resource *resource = container_of(entry,
12740 : : typeof(*resource),
12741 : : entry);
12742 : :
12743 [ # # ]: 0 : if (ctx_resource->ratio == resource->ratio &&
12744 [ # # ]: 0 : ctx_resource->ft_type == resource->ft_type &&
12745 [ # # ]: 0 : ctx_resource->ft_id == resource->ft_id &&
12746 [ # # ]: 0 : ctx_resource->set_action == resource->set_action &&
12747 : 0 : !memcmp((void *)&ctx_resource->sample_act,
12748 [ # # ]: 0 : (void *)&resource->sample_act,
12749 : : sizeof(struct mlx5_flow_sub_actions_list))) {
12750 : : /*
12751 : : * Existing sample action should release the prepared
12752 : : * sub-actions reference counter.
12753 : : */
12754 : 0 : flow_dv_sample_sub_actions_release(dev,
12755 : : &ctx_resource->sample_idx);
12756 : 0 : return 0;
12757 : : }
12758 : : return 1;
12759 : : }
12760 : :
12761 : : struct mlx5_list_entry *
12762 : 0 : mlx5_flow_dv_sample_create_cb(void *tool_ctx __rte_unused, void *cb_ctx)
12763 : : {
12764 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12765 : 0 : struct rte_eth_dev *dev = ctx->dev;
12766 : 0 : struct mlx5_flow_dv_sample_resource *ctx_resource = ctx->data;
12767 : 0 : void **sample_dv_actions = ctx_resource->sub_actions;
12768 : : struct mlx5_flow_dv_sample_resource *resource;
12769 : : struct mlx5dv_dr_flow_sampler_attr sampler_attr;
12770 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12771 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
12772 : : struct mlx5_flow_tbl_resource *tbl;
12773 : 0 : uint32_t idx = 0;
12774 : : const uint32_t next_ft_step = 1;
12775 : 0 : uint32_t next_ft_id = ctx_resource->ft_id + next_ft_step;
12776 : : uint8_t is_egress = 0;
12777 : : uint8_t is_transfer = 0;
12778 : 0 : struct rte_flow_error *error = ctx->error;
12779 : :
12780 : : /* Register new sample resource. */
12781 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_SAMPLE], &idx);
12782 [ # # ]: 0 : if (!resource) {
12783 : 0 : rte_flow_error_set(error, ENOMEM,
12784 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12785 : : NULL,
12786 : : "cannot allocate resource memory");
12787 : 0 : return NULL;
12788 : : }
12789 : 0 : *resource = *ctx_resource;
12790 : : /* Create normal path table level */
12791 [ # # ]: 0 : if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
12792 : : is_transfer = 1;
12793 [ # # ]: 0 : else if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
12794 : : is_egress = 1;
12795 : 0 : tbl = mlx5_flow_dv_tbl_resource_get(dev, next_ft_id,
12796 : : is_egress, is_transfer,
12797 : : true, NULL, 0, 0, 0, error);
12798 [ # # ]: 0 : if (!tbl) {
12799 : 0 : rte_flow_error_set(error, ENOMEM,
12800 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12801 : : NULL,
12802 : : "fail to create normal path table "
12803 : : "for sample");
12804 : 0 : goto error;
12805 : : }
12806 : 0 : resource->normal_path_tbl = tbl;
12807 [ # # ]: 0 : if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB) {
12808 [ # # ]: 0 : if (!sh->default_miss_action) {
12809 : 0 : rte_flow_error_set(error, ENOMEM,
12810 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12811 : : NULL,
12812 : : "default miss action was not "
12813 : : "created");
12814 : 0 : goto error;
12815 : : }
12816 : 0 : sample_dv_actions[ctx_resource->sample_act.actions_num++] =
12817 : : sh->default_miss_action;
12818 : : }
12819 : : /* Create a DR sample action */
12820 : 0 : sampler_attr.sample_ratio = resource->ratio;
12821 : 0 : sampler_attr.default_next_table = tbl->obj;
12822 : 0 : sampler_attr.num_sample_actions = ctx_resource->sample_act.actions_num;
12823 : 0 : sampler_attr.sample_actions = (struct mlx5dv_dr_action **)
12824 : : &sample_dv_actions[0];
12825 : 0 : sampler_attr.action = resource->set_action;
12826 : : if (mlx5_os_flow_dr_create_flow_action_sampler
12827 : : (&sampler_attr, &resource->verbs_action)) {
12828 : 0 : rte_flow_error_set(error, ENOMEM,
12829 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12830 : : NULL, "cannot create sample action");
12831 : 0 : goto error;
12832 : : }
12833 : 0 : resource->idx = idx;
12834 : 0 : resource->dev = dev;
12835 : 0 : return &resource->entry;
12836 : 0 : error:
12837 [ # # ]: 0 : if (resource->ft_type != MLX5DV_FLOW_TABLE_TYPE_FDB)
12838 : 0 : flow_dv_sample_sub_actions_release(dev,
12839 : : &resource->sample_idx);
12840 [ # # ]: 0 : if (resource->normal_path_tbl)
12841 : 0 : mlx5_flow_dv_tbl_resource_release(MLX5_SH(dev), resource->normal_path_tbl);
12842 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_SAMPLE], idx);
12843 : 0 : return NULL;
12844 : :
12845 : : }
12846 : :
12847 : : struct mlx5_list_entry *
12848 : 0 : mlx5_flow_dv_sample_clone_cb(void *tool_ctx __rte_unused,
12849 : : struct mlx5_list_entry *entry __rte_unused,
12850 : : void *cb_ctx)
12851 : : {
12852 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12853 : 0 : struct rte_eth_dev *dev = ctx->dev;
12854 : : struct mlx5_flow_dv_sample_resource *resource;
12855 : : struct mlx5_flow_dv_sample_resource *old_resource;
12856 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12857 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
12858 : 0 : uint32_t idx = 0;
12859 : :
12860 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_SAMPLE], &idx);
12861 [ # # ]: 0 : if (!resource) {
12862 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12863 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12864 : : NULL,
12865 : : "cannot allocate resource memory");
12866 : 0 : return NULL;
12867 : : }
12868 : : old_resource = container_of(entry, typeof(*old_resource), entry);
12869 : : memcpy(resource, old_resource, sizeof(*resource));
12870 : 0 : resource->idx = idx;
12871 : 0 : resource->dev = dev;
12872 : 0 : return &resource->entry;
12873 : : }
12874 : :
12875 : : void
12876 : 0 : mlx5_flow_dv_sample_clone_free_cb(void *tool_ctx __rte_unused,
12877 : : struct mlx5_list_entry *entry)
12878 : : {
12879 : : struct mlx5_flow_dv_sample_resource *resource =
12880 : : container_of(entry, typeof(*resource), entry);
12881 : 0 : struct rte_eth_dev *dev = resource->dev;
12882 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12883 : :
12884 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_SAMPLE], resource->idx);
12885 : 0 : }
12886 : :
12887 : : /**
12888 : : * Find existing sample resource or create and register a new one.
12889 : : *
12890 : : * @param[in, out] dev
12891 : : * Pointer to rte_eth_dev structure.
12892 : : * @param[in] ref
12893 : : * Pointer to sample resource reference.
12894 : : * @parm[in, out] dev_flow
12895 : : * Pointer to the dev_flow.
12896 : : * @param[out] error
12897 : : * pointer to error structure.
12898 : : *
12899 : : * @return
12900 : : * 0 on success otherwise -errno and errno is set.
12901 : : */
12902 : : static int
12903 : 0 : flow_dv_sample_resource_register(struct rte_eth_dev *dev,
12904 : : struct mlx5_flow_dv_sample_resource *ref,
12905 : : struct mlx5_flow *dev_flow,
12906 : : struct rte_flow_error *error)
12907 : : {
12908 : : struct mlx5_flow_dv_sample_resource *resource;
12909 : : struct mlx5_list_entry *entry;
12910 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12911 : 0 : struct mlx5_flow_cb_ctx ctx = {
12912 : : .dev = dev,
12913 : : .error = error,
12914 : : .data = ref,
12915 : : };
12916 : :
12917 : 0 : entry = mlx5_list_register(priv->sh->sample_action_list, &ctx);
12918 [ # # ]: 0 : if (!entry)
12919 : 0 : return -rte_errno;
12920 : : resource = container_of(entry, typeof(*resource), entry);
12921 : 0 : dev_flow->handle->dvh.rix_sample = resource->idx;
12922 : 0 : dev_flow->dv.sample_res = resource;
12923 : 0 : return 0;
12924 : : }
12925 : :
12926 : : int
12927 : 0 : mlx5_flow_dv_dest_array_match_cb(void *tool_ctx __rte_unused,
12928 : : struct mlx5_list_entry *entry, void *cb_ctx)
12929 : : {
12930 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12931 : 0 : struct mlx5_flow_dv_dest_array_resource *ctx_resource = ctx->data;
12932 : 0 : struct rte_eth_dev *dev = ctx->dev;
12933 : : struct mlx5_flow_dv_dest_array_resource *resource =
12934 : : container_of(entry, typeof(*resource), entry);
12935 : : uint32_t idx = 0;
12936 : :
12937 [ # # ]: 0 : if (ctx_resource->num_of_dest == resource->num_of_dest &&
12938 : 0 : ctx_resource->ft_type == resource->ft_type &&
12939 : 0 : !memcmp((void *)resource->sample_act,
12940 : 0 : (void *)ctx_resource->sample_act,
12941 [ # # ]: 0 : (ctx_resource->num_of_dest *
12942 : : sizeof(struct mlx5_flow_sub_actions_list)))) {
12943 : : /*
12944 : : * Existing sample action should release the prepared
12945 : : * sub-actions reference counter.
12946 : : */
12947 [ # # ]: 0 : for (idx = 0; idx < ctx_resource->num_of_dest; idx++)
12948 : 0 : flow_dv_sample_sub_actions_release(dev,
12949 : : &ctx_resource->sample_idx[idx]);
12950 : : return 0;
12951 : : }
12952 : : return 1;
12953 : : }
12954 : :
12955 : : struct mlx5_list_entry *
12956 : 0 : mlx5_flow_dv_dest_array_create_cb(void *tool_ctx __rte_unused, void *cb_ctx)
12957 : : {
12958 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12959 : 0 : struct rte_eth_dev *dev = ctx->dev;
12960 : : struct mlx5_flow_dv_dest_array_resource *resource;
12961 : 0 : struct mlx5_flow_dv_dest_array_resource *ctx_resource = ctx->data;
12962 : 0 : struct mlx5dv_dr_action_dest_attr *dest_attr[MLX5_MAX_DEST_NUM] = { 0 };
12963 : : struct mlx5dv_dr_action_dest_reformat dest_reformat[MLX5_MAX_DEST_NUM];
12964 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12965 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
12966 : : struct mlx5_flow_sub_actions_list *sample_act;
12967 : : struct mlx5dv_dr_domain *domain;
12968 : 0 : uint32_t idx = 0, res_idx = 0;
12969 : 0 : struct rte_flow_error *error = ctx->error;
12970 : : uint64_t action_flags;
12971 : : int ret;
12972 : :
12973 : : /* Register new destination array resource. */
12974 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DEST_ARRAY],
12975 : : &res_idx);
12976 [ # # ]: 0 : if (!resource) {
12977 : 0 : rte_flow_error_set(error, ENOMEM,
12978 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12979 : : NULL,
12980 : : "cannot allocate resource memory");
12981 : 0 : return NULL;
12982 : : }
12983 : 0 : *resource = *ctx_resource;
12984 [ # # ]: 0 : if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
12985 : 0 : domain = sh->fdb_domain;
12986 [ # # ]: 0 : else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
12987 : 0 : domain = sh->rx_domain;
12988 : : else
12989 : 0 : domain = sh->tx_domain;
12990 [ # # ]: 0 : for (idx = 0; idx < ctx_resource->num_of_dest; idx++) {
12991 : 0 : dest_attr[idx] = (struct mlx5dv_dr_action_dest_attr *)
12992 : 0 : mlx5_malloc(MLX5_MEM_ZERO,
12993 : : sizeof(struct mlx5dv_dr_action_dest_attr),
12994 : : 0, SOCKET_ID_ANY);
12995 [ # # ]: 0 : if (!dest_attr[idx]) {
12996 : 0 : rte_flow_error_set(error, ENOMEM,
12997 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12998 : : NULL,
12999 : : "cannot allocate resource memory");
13000 : 0 : goto error;
13001 : : }
13002 : 0 : dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST;
13003 : : sample_act = &ctx_resource->sample_act[idx];
13004 : 0 : action_flags = sample_act->action_flags;
13005 [ # # # # : 0 : switch (action_flags) {
# ]
13006 : 0 : case MLX5_FLOW_ACTION_QUEUE:
13007 : 0 : dest_attr[idx]->dest = sample_act->dr_queue_action;
13008 : 0 : break;
13009 : 0 : case (MLX5_FLOW_ACTION_PORT_ID | MLX5_FLOW_ACTION_ENCAP):
13010 : 0 : dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST_REFORMAT;
13011 : 0 : dest_attr[idx]->dest_reformat = &dest_reformat[idx];
13012 : 0 : dest_attr[idx]->dest_reformat->reformat =
13013 : 0 : sample_act->dr_encap_action;
13014 : 0 : dest_attr[idx]->dest_reformat->dest =
13015 : 0 : sample_act->dr_port_id_action;
13016 : 0 : break;
13017 : 0 : case MLX5_FLOW_ACTION_PORT_ID:
13018 : 0 : dest_attr[idx]->dest = sample_act->dr_port_id_action;
13019 : 0 : break;
13020 : 0 : case MLX5_FLOW_ACTION_JUMP:
13021 : 0 : dest_attr[idx]->dest = sample_act->dr_jump_action;
13022 : 0 : break;
13023 : 0 : default:
13024 : 0 : rte_flow_error_set(error, EINVAL,
13025 : : RTE_FLOW_ERROR_TYPE_ACTION,
13026 : : NULL,
13027 : : "unsupported actions type");
13028 : 0 : goto error;
13029 : : }
13030 : : }
13031 : : /* create a dest array action */
13032 : 0 : ret = mlx5_os_flow_dr_create_flow_action_dest_array
13033 : : (domain,
13034 : 0 : resource->num_of_dest,
13035 : : dest_attr,
13036 : : &resource->action);
13037 : : if (ret) {
13038 : 0 : rte_flow_error_set(error, ENOMEM,
13039 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13040 : : NULL,
13041 : : "cannot create destination array action");
13042 : 0 : goto error;
13043 : : }
13044 : 0 : resource->idx = res_idx;
13045 : 0 : resource->dev = dev;
13046 [ # # ]: 0 : for (idx = 0; idx < ctx_resource->num_of_dest; idx++)
13047 : 0 : mlx5_free(dest_attr[idx]);
13048 : 0 : return &resource->entry;
13049 : : error:
13050 [ # # ]: 0 : for (idx = 0; idx < ctx_resource->num_of_dest; idx++) {
13051 : 0 : flow_dv_sample_sub_actions_release(dev,
13052 : : &resource->sample_idx[idx]);
13053 [ # # ]: 0 : if (dest_attr[idx])
13054 : 0 : mlx5_free(dest_attr[idx]);
13055 : : }
13056 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DEST_ARRAY], res_idx);
13057 : 0 : return NULL;
13058 : : }
13059 : :
13060 : : struct mlx5_list_entry *
13061 : 0 : mlx5_flow_dv_dest_array_clone_cb(void *tool_ctx __rte_unused,
13062 : : struct mlx5_list_entry *entry __rte_unused,
13063 : : void *cb_ctx)
13064 : : {
13065 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
13066 : 0 : struct rte_eth_dev *dev = ctx->dev;
13067 : : struct mlx5_flow_dv_dest_array_resource *resource;
13068 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13069 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
13070 : 0 : uint32_t res_idx = 0;
13071 : 0 : struct rte_flow_error *error = ctx->error;
13072 : :
13073 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DEST_ARRAY],
13074 : : &res_idx);
13075 [ # # ]: 0 : if (!resource) {
13076 : 0 : rte_flow_error_set(error, ENOMEM,
13077 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13078 : : NULL,
13079 : : "cannot allocate dest-array memory");
13080 : 0 : return NULL;
13081 : : }
13082 : : memcpy(resource, entry, sizeof(*resource));
13083 : 0 : resource->idx = res_idx;
13084 : 0 : resource->dev = dev;
13085 : 0 : return &resource->entry;
13086 : : }
13087 : :
13088 : : void
13089 : 0 : mlx5_flow_dv_dest_array_clone_free_cb(void *tool_ctx __rte_unused,
13090 : : struct mlx5_list_entry *entry)
13091 : : {
13092 : : struct mlx5_flow_dv_dest_array_resource *resource =
13093 : : container_of(entry, typeof(*resource), entry);
13094 : 0 : struct rte_eth_dev *dev = resource->dev;
13095 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13096 : :
13097 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY], resource->idx);
13098 : 0 : }
13099 : :
13100 : : /**
13101 : : * Find existing destination array resource or create and register a new one.
13102 : : *
13103 : : * @param[in, out] dev
13104 : : * Pointer to rte_eth_dev structure.
13105 : : * @param[in] ref
13106 : : * Pointer to destination array resource reference.
13107 : : * @parm[in, out] dev_flow
13108 : : * Pointer to the dev_flow.
13109 : : * @param[out] error
13110 : : * pointer to error structure.
13111 : : *
13112 : : * @return
13113 : : * 0 on success otherwise -errno and errno is set.
13114 : : */
13115 : : static int
13116 : 0 : flow_dv_dest_array_resource_register(struct rte_eth_dev *dev,
13117 : : struct mlx5_flow_dv_dest_array_resource *ref,
13118 : : struct mlx5_flow *dev_flow,
13119 : : struct rte_flow_error *error)
13120 : : {
13121 : : struct mlx5_flow_dv_dest_array_resource *resource;
13122 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13123 : : struct mlx5_list_entry *entry;
13124 : 0 : struct mlx5_flow_cb_ctx ctx = {
13125 : : .dev = dev,
13126 : : .error = error,
13127 : : .data = ref,
13128 : : };
13129 : :
13130 : 0 : entry = mlx5_list_register(priv->sh->dest_array_list, &ctx);
13131 [ # # ]: 0 : if (!entry)
13132 : 0 : return -rte_errno;
13133 : : resource = container_of(entry, typeof(*resource), entry);
13134 : 0 : dev_flow->handle->dvh.rix_dest_array = resource->idx;
13135 : 0 : dev_flow->dv.dest_array_res = resource;
13136 : 0 : return 0;
13137 : : }
13138 : :
13139 : : /**
13140 : : * Convert Sample action to DV specification.
13141 : : *
13142 : : * @param[in] dev
13143 : : * Pointer to rte_eth_dev structure.
13144 : : * @param[in] action
13145 : : * Pointer to sample action structure.
13146 : : * @param[in, out] dev_flow
13147 : : * Pointer to the mlx5_flow.
13148 : : * @param[in] attr
13149 : : * Pointer to the flow attributes.
13150 : : * @param[in, out] num_of_dest
13151 : : * Pointer to the num of destination.
13152 : : * @param[in, out] sample_actions
13153 : : * Pointer to sample actions list.
13154 : : * @param[in, out] res
13155 : : * Pointer to sample resource.
13156 : : * @param[out] error
13157 : : * Pointer to the error structure.
13158 : : *
13159 : : * @return
13160 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
13161 : : */
13162 : : static int
13163 : 0 : flow_dv_translate_action_sample(struct rte_eth_dev *dev,
13164 : : const struct rte_flow_action_sample *action,
13165 : : struct mlx5_flow *dev_flow,
13166 : : const struct rte_flow_attr *attr,
13167 : : uint32_t *num_of_dest,
13168 : : void **sample_actions,
13169 : : struct mlx5_flow_dv_sample_resource *res,
13170 : : struct rte_flow_error *error)
13171 : : {
13172 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13173 : : const struct rte_flow_action *sub_actions;
13174 : : struct mlx5_flow_sub_actions_list *sample_act;
13175 : : struct mlx5_flow_sub_actions_idx *sample_idx;
13176 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
13177 : 0 : struct rte_flow *flow = dev_flow->flow;
13178 : : struct mlx5_flow_rss_desc *rss_desc;
13179 : : uint64_t action_flags = 0;
13180 : :
13181 : : MLX5_ASSERT(wks);
13182 : 0 : rss_desc = &wks->rss_desc;
13183 : : sample_act = &res->sample_act;
13184 : : sample_idx = &res->sample_idx;
13185 : 0 : res->ratio = action->ratio;
13186 : 0 : sub_actions = action->actions;
13187 [ # # ]: 0 : for (; sub_actions->type != RTE_FLOW_ACTION_TYPE_END; sub_actions++) {
13188 : : int type = sub_actions->type;
13189 : : uint32_t pre_rix = 0;
13190 : : void *pre_r;
13191 [ # # # # : 0 : switch (type) {
# # # ]
13192 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
13193 : : {
13194 : : const struct rte_flow_action_queue *queue;
13195 : : struct mlx5_hrxq *hrxq;
13196 : : uint32_t hrxq_idx;
13197 : :
13198 : 0 : queue = sub_actions->conf;
13199 : 0 : rss_desc->queue_num = 1;
13200 : 0 : rss_desc->queue[0] = queue->index;
13201 : 0 : hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
13202 : : rss_desc, &hrxq_idx);
13203 [ # # ]: 0 : if (!hrxq)
13204 : 0 : return rte_flow_error_set
13205 : : (error, rte_errno,
13206 : : RTE_FLOW_ERROR_TYPE_ACTION,
13207 : : NULL,
13208 : : "cannot create fate queue");
13209 : 0 : sample_act->dr_queue_action = hrxq->action;
13210 : 0 : sample_idx->rix_hrxq = hrxq_idx;
13211 : 0 : sample_actions[sample_act->actions_num++] =
13212 : : hrxq->action;
13213 : 0 : (*num_of_dest)++;
13214 : 0 : action_flags |= MLX5_FLOW_ACTION_QUEUE;
13215 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
13216 : 0 : dev_flow->handle->rix_hrxq = hrxq_idx;
13217 : 0 : dev_flow->handle->fate_action =
13218 : : MLX5_FLOW_FATE_QUEUE;
13219 : 0 : break;
13220 : : }
13221 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
13222 : : {
13223 : : struct mlx5_hrxq *hrxq;
13224 : : uint32_t hrxq_idx;
13225 : : const struct rte_flow_action_rss *rss;
13226 : : const uint8_t *rss_key;
13227 : :
13228 : 0 : rss = sub_actions->conf;
13229 : 0 : rss_desc->symmetric_hash_function =
13230 : 0 : MLX5_RSS_IS_SYMM(rss->func);
13231 : 0 : memcpy(rss_desc->queue, rss->queue,
13232 [ # # ]: 0 : rss->queue_num * sizeof(uint16_t));
13233 : 0 : rss_desc->queue_num = rss->queue_num;
13234 : : /* NULL RSS key indicates default RSS key. */
13235 [ # # ]: 0 : rss_key = !rss->key ? mlx5_rss_hash_default_key : rss->key;
13236 : 0 : memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
13237 : : /*
13238 : : * rss->level and rss.types should be set in advance
13239 : : * when expanding items for RSS.
13240 : : */
13241 : 0 : mlx5_flow_dv_hashfields_set(dev_flow->handle->layers,
13242 : : rss_desc,
13243 : : &dev_flow->hash_fields);
13244 : 0 : hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
13245 : : rss_desc, &hrxq_idx);
13246 [ # # ]: 0 : if (!hrxq)
13247 : 0 : return rte_flow_error_set
13248 : : (error, rte_errno,
13249 : : RTE_FLOW_ERROR_TYPE_ACTION,
13250 : : NULL,
13251 : : "cannot create fate queue");
13252 : 0 : sample_act->dr_queue_action = hrxq->action;
13253 : 0 : sample_idx->rix_hrxq = hrxq_idx;
13254 : 0 : sample_actions[sample_act->actions_num++] =
13255 : : hrxq->action;
13256 : 0 : (*num_of_dest)++;
13257 : 0 : action_flags |= MLX5_FLOW_ACTION_RSS;
13258 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
13259 : 0 : dev_flow->handle->rix_hrxq = hrxq_idx;
13260 : 0 : dev_flow->handle->fate_action =
13261 : : MLX5_FLOW_FATE_QUEUE;
13262 : 0 : break;
13263 : : }
13264 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
13265 : : {
13266 : : uint32_t tag_be = mlx5_flow_mark_set
13267 : : (((const struct rte_flow_action_mark *)
13268 [ # # ]: 0 : (sub_actions->conf))->id);
13269 : :
13270 : 0 : wks->mark = 1;
13271 : 0 : pre_rix = dev_flow->handle->dvh.rix_tag;
13272 : : /* Save the mark resource before sample */
13273 : 0 : pre_r = dev_flow->dv.tag_resource;
13274 [ # # ]: 0 : if (flow_dv_tag_resource_register(dev, tag_be,
13275 : : dev_flow, error))
13276 : 0 : return -rte_errno;
13277 : : MLX5_ASSERT(dev_flow->dv.tag_resource);
13278 : 0 : sample_act->dr_tag_action =
13279 : 0 : dev_flow->dv.tag_resource->action;
13280 : 0 : sample_idx->rix_tag =
13281 : 0 : dev_flow->handle->dvh.rix_tag;
13282 : 0 : sample_actions[sample_act->actions_num++] =
13283 : : sample_act->dr_tag_action;
13284 : : /* Recover the mark resource after sample */
13285 : 0 : dev_flow->dv.tag_resource = pre_r;
13286 : 0 : dev_flow->handle->dvh.rix_tag = pre_rix;
13287 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK;
13288 : 0 : break;
13289 : : }
13290 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
13291 : : {
13292 [ # # ]: 0 : if (!flow->counter) {
13293 : 0 : flow->counter =
13294 : 0 : flow_dv_translate_create_counter(dev,
13295 : 0 : dev_flow, sub_actions->conf,
13296 : : 0);
13297 [ # # ]: 0 : if (!flow->counter)
13298 : 0 : return rte_flow_error_set
13299 : : (error, rte_errno,
13300 : : RTE_FLOW_ERROR_TYPE_ACTION,
13301 : : NULL,
13302 : : "cannot create counter"
13303 : : " object.");
13304 : : }
13305 : 0 : sample_act->dr_cnt_action =
13306 [ # # ]: 0 : (flow_dv_counter_get_by_idx(dev,
13307 : 0 : flow->counter, NULL))->action;
13308 : 0 : sample_actions[sample_act->actions_num++] =
13309 : : sample_act->dr_cnt_action;
13310 : 0 : action_flags |= MLX5_FLOW_ACTION_COUNT;
13311 : 0 : break;
13312 : : }
13313 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
13314 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
13315 : : {
13316 : : struct mlx5_flow_dv_port_id_action_resource
13317 : : port_id_resource;
13318 : 0 : uint32_t port_id = 0;
13319 : :
13320 : : memset(&port_id_resource, 0, sizeof(port_id_resource));
13321 : : /* Save the port id resource before sample */
13322 : 0 : pre_rix = dev_flow->handle->rix_port_id_action;
13323 : 0 : pre_r = dev_flow->dv.port_id_action;
13324 [ # # ]: 0 : if (flow_dv_translate_action_port_id(dev, sub_actions,
13325 : : &port_id, error))
13326 : 0 : return -rte_errno;
13327 : 0 : port_id_resource.port_id = port_id;
13328 [ # # ]: 0 : if (flow_dv_port_id_action_resource_register
13329 : : (dev, &port_id_resource, dev_flow, error))
13330 : 0 : return -rte_errno;
13331 : 0 : sample_act->dr_port_id_action =
13332 : 0 : dev_flow->dv.port_id_action->action;
13333 : 0 : sample_idx->rix_port_id_action =
13334 : 0 : dev_flow->handle->rix_port_id_action;
13335 : 0 : sample_actions[sample_act->actions_num++] =
13336 : : sample_act->dr_port_id_action;
13337 : : /* Recover the port id resource after sample */
13338 : 0 : dev_flow->dv.port_id_action = pre_r;
13339 : 0 : dev_flow->handle->rix_port_id_action = pre_rix;
13340 : 0 : (*num_of_dest)++;
13341 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_ID;
13342 : 0 : break;
13343 : : }
13344 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
13345 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
13346 : : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
13347 : : /* Save the encap resource before sample */
13348 : 0 : pre_rix = dev_flow->handle->dvh.rix_encap_decap;
13349 : 0 : pre_r = dev_flow->dv.encap_decap;
13350 [ # # ]: 0 : if (flow_dv_create_action_l2_encap(dev, sub_actions,
13351 : : dev_flow,
13352 : 0 : attr->transfer,
13353 : : error))
13354 : 0 : return -rte_errno;
13355 : 0 : sample_act->dr_encap_action =
13356 : 0 : dev_flow->dv.encap_decap->action;
13357 : 0 : sample_idx->rix_encap_decap =
13358 : 0 : dev_flow->handle->dvh.rix_encap_decap;
13359 : 0 : sample_actions[sample_act->actions_num++] =
13360 : : sample_act->dr_encap_action;
13361 : : /* Recover the encap resource after sample */
13362 : 0 : dev_flow->dv.encap_decap = pre_r;
13363 : 0 : dev_flow->handle->dvh.rix_encap_decap = pre_rix;
13364 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
13365 : 0 : break;
13366 : 0 : default:
13367 : 0 : return rte_flow_error_set(error, EINVAL,
13368 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13369 : : NULL,
13370 : : "Not support for sampler action");
13371 : : }
13372 : : }
13373 : 0 : sample_act->action_flags = action_flags;
13374 : 0 : res->ft_id = dev_flow->dv.group;
13375 [ # # ]: 0 : if (attr->transfer) {
13376 : : union {
13377 : : uint32_t action_in[MLX5_ST_SZ_DW(set_action_in)];
13378 : : uint64_t set_action;
13379 : : } action_ctx = { .set_action = 0 };
13380 : 0 : uint32_t vport_meta_tag = wks->vport_meta_tag ?
13381 [ # # ]: 0 : wks->vport_meta_tag :
13382 : : priv->vport_meta_tag;
13383 : :
13384 : 0 : res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
13385 : : MLX5_SET(set_action_in, action_ctx.action_in, action_type,
13386 : : MLX5_MODIFICATION_TYPE_SET);
13387 [ # # ]: 0 : MLX5_SET(set_action_in, action_ctx.action_in, field,
13388 : : MLX5_MODI_META_REG_C_0);
13389 : 0 : MLX5_SET(set_action_in, action_ctx.action_in, data,
13390 : : vport_meta_tag);
13391 : 0 : res->set_action = action_ctx.set_action;
13392 [ # # ]: 0 : } else if (attr->ingress) {
13393 : 0 : res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
13394 : : } else {
13395 : 0 : res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_TX;
13396 : : }
13397 : : return 0;
13398 : : }
13399 : :
13400 : : static void *
13401 : 0 : flow_dv_translate_action_send_to_kernel(struct rte_eth_dev *dev,
13402 : : const struct rte_flow_attr *attr,
13403 : : struct rte_flow_error *error)
13404 : : {
13405 : : struct mlx5_flow_tbl_resource *tbl;
13406 : : struct mlx5_dev_ctx_shared *sh;
13407 : : uint32_t priority;
13408 : : void *action;
13409 : : int ft_type;
13410 : : int ret;
13411 : :
13412 : 0 : sh = MLX5_SH(dev);
13413 [ # # ]: 0 : ft_type = (attr->ingress) ? MLX5DR_TABLE_TYPE_NIC_RX :
13414 [ # # ]: 0 : ((attr->transfer) ? MLX5DR_TABLE_TYPE_FDB :
13415 : : MLX5DR_TABLE_TYPE_NIC_TX);
13416 [ # # ]: 0 : if (sh->send_to_kernel_action[ft_type].action)
13417 : : return sh->send_to_kernel_action[ft_type].action;
13418 : 0 : priority = mlx5_get_send_to_kernel_priority(dev);
13419 [ # # ]: 0 : if (priority == (uint32_t)-1) {
13420 : 0 : rte_flow_error_set(error, ENOTSUP,
13421 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13422 : : "required priority is not available");
13423 : 0 : return NULL;
13424 : : }
13425 : 0 : tbl = mlx5_flow_dv_tbl_resource_get(dev, 0, attr->egress, attr->transfer,
13426 : : false, NULL, 0, 0, 0, error);
13427 [ # # ]: 0 : if (!tbl) {
13428 : 0 : rte_flow_error_set(error, ENODATA,
13429 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13430 : : "cannot find destination root table");
13431 : 0 : return NULL;
13432 : : }
13433 : 0 : ret = mlx5_flow_os_create_flow_action_send_to_kernel(tbl->obj,
13434 : : priority, &action);
13435 : : if (ret) {
13436 : 0 : rte_flow_error_set(error, ENOMEM,
13437 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13438 : : "cannot create action");
13439 : 0 : goto err;
13440 : : }
13441 : : MLX5_ASSERT(action);
13442 : 0 : sh->send_to_kernel_action[ft_type].action = action;
13443 : 0 : sh->send_to_kernel_action[ft_type].tbl = tbl;
13444 : 0 : return action;
13445 : : err:
13446 : 0 : mlx5_flow_dv_tbl_resource_release(sh, tbl);
13447 : 0 : return NULL;
13448 : : }
13449 : :
13450 : : /**
13451 : : * Convert Sample action to DV specification.
13452 : : *
13453 : : * @param[in] dev
13454 : : * Pointer to rte_eth_dev structure.
13455 : : * @param[in, out] dev_flow
13456 : : * Pointer to the mlx5_flow.
13457 : : * @param[in] num_of_dest
13458 : : * The num of destination.
13459 : : * @param[in, out] res
13460 : : * Pointer to sample resource.
13461 : : * @param[in, out] mdest_res
13462 : : * Pointer to destination array resource.
13463 : : * @param[in] sample_actions
13464 : : * Pointer to sample path actions list.
13465 : : * @param[in] action_flags
13466 : : * Holds the actions detected until now.
13467 : : * @param[out] error
13468 : : * Pointer to the error structure.
13469 : : *
13470 : : * @return
13471 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
13472 : : */
13473 : : static int
13474 : 0 : flow_dv_create_action_sample(struct rte_eth_dev *dev,
13475 : : struct mlx5_flow *dev_flow,
13476 : : uint32_t num_of_dest,
13477 : : struct mlx5_flow_dv_sample_resource *res,
13478 : : struct mlx5_flow_dv_dest_array_resource *mdest_res,
13479 : : void **sample_actions,
13480 : : uint64_t action_flags,
13481 : : struct rte_flow_error *error)
13482 : : {
13483 : : /* update normal path action resource into last index of array */
13484 : : uint32_t dest_index = MLX5_MAX_DEST_NUM - 1;
13485 : : struct mlx5_flow_sub_actions_list *sample_act =
13486 : : &mdest_res->sample_act[dest_index];
13487 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
13488 : : struct mlx5_flow_rss_desc *rss_desc;
13489 : : uint32_t normal_idx = 0;
13490 : : struct mlx5_hrxq *hrxq;
13491 : : uint32_t hrxq_idx;
13492 : :
13493 : : MLX5_ASSERT(wks);
13494 : 0 : rss_desc = &wks->rss_desc;
13495 [ # # ]: 0 : if (num_of_dest > 1) {
13496 [ # # ]: 0 : if (sample_act->action_flags & MLX5_FLOW_ACTION_QUEUE) {
13497 : : /* Handle QP action for mirroring */
13498 : 0 : hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
13499 : : rss_desc, &hrxq_idx);
13500 [ # # ]: 0 : if (!hrxq)
13501 : 0 : return rte_flow_error_set
13502 : : (error, rte_errno,
13503 : : RTE_FLOW_ERROR_TYPE_ACTION,
13504 : : NULL,
13505 : : "cannot create rx queue");
13506 : : normal_idx++;
13507 : 0 : mdest_res->sample_idx[dest_index].rix_hrxq = hrxq_idx;
13508 : 0 : sample_act->dr_queue_action = hrxq->action;
13509 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
13510 : 0 : dev_flow->handle->rix_hrxq = hrxq_idx;
13511 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
13512 : : }
13513 [ # # ]: 0 : if (sample_act->action_flags & MLX5_FLOW_ACTION_ENCAP) {
13514 : 0 : normal_idx++;
13515 : 0 : mdest_res->sample_idx[dest_index].rix_encap_decap =
13516 : 0 : dev_flow->handle->dvh.rix_encap_decap;
13517 : 0 : sample_act->dr_encap_action =
13518 : 0 : dev_flow->dv.encap_decap->action;
13519 : 0 : dev_flow->handle->dvh.rix_encap_decap = 0;
13520 : : }
13521 [ # # ]: 0 : if (sample_act->action_flags & MLX5_FLOW_ACTION_PORT_ID) {
13522 : 0 : normal_idx++;
13523 : 0 : mdest_res->sample_idx[dest_index].rix_port_id_action =
13524 : 0 : dev_flow->handle->rix_port_id_action;
13525 : 0 : sample_act->dr_port_id_action =
13526 : 0 : dev_flow->dv.port_id_action->action;
13527 : 0 : dev_flow->handle->rix_port_id_action = 0;
13528 : : }
13529 [ # # ]: 0 : if (sample_act->action_flags & MLX5_FLOW_ACTION_JUMP) {
13530 : 0 : normal_idx++;
13531 : 0 : mdest_res->sample_idx[dest_index].rix_jump =
13532 : 0 : dev_flow->handle->rix_jump;
13533 : 0 : sample_act->dr_jump_action =
13534 : 0 : dev_flow->dv.jump->action;
13535 : 0 : dev_flow->handle->rix_jump = 0;
13536 : : }
13537 : 0 : sample_act->actions_num = normal_idx;
13538 : : /* update sample action resource into first index of array */
13539 : 0 : mdest_res->ft_type = res->ft_type;
13540 : 0 : memcpy(&mdest_res->sample_idx[0], &res->sample_idx,
13541 : : sizeof(struct mlx5_flow_sub_actions_idx));
13542 : 0 : memcpy(&mdest_res->sample_act[0], &res->sample_act,
13543 : : sizeof(struct mlx5_flow_sub_actions_list));
13544 : 0 : mdest_res->num_of_dest = num_of_dest;
13545 [ # # ]: 0 : if (flow_dv_dest_array_resource_register(dev, mdest_res,
13546 : : dev_flow, error))
13547 : 0 : return rte_flow_error_set(error, EINVAL,
13548 : : RTE_FLOW_ERROR_TYPE_ACTION,
13549 : : NULL, "can't create sample "
13550 : : "action");
13551 : : } else {
13552 : 0 : res->sub_actions = sample_actions;
13553 [ # # ]: 0 : if (flow_dv_sample_resource_register(dev, res, dev_flow, error))
13554 : 0 : return rte_flow_error_set(error, EINVAL,
13555 : : RTE_FLOW_ERROR_TYPE_ACTION,
13556 : : NULL,
13557 : : "can't create sample action");
13558 : : }
13559 : : return 0;
13560 : : }
13561 : :
13562 : : /**
13563 : : * Remove an ASO age action from age actions list.
13564 : : *
13565 : : * @param[in] dev
13566 : : * Pointer to the Ethernet device structure.
13567 : : * @param[in] age
13568 : : * Pointer to the aso age action handler.
13569 : : */
13570 : : static void
13571 : 0 : flow_dv_aso_age_remove_from_age(struct rte_eth_dev *dev,
13572 : : struct mlx5_aso_age_action *age)
13573 : : {
13574 : : struct mlx5_age_info *age_info;
13575 : : struct mlx5_age_param *age_param = &age->age_params;
13576 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13577 : : uint16_t expected = AGE_CANDIDATE;
13578 : :
13579 : 0 : age_info = GET_PORT_AGE_INFO(priv);
13580 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(&age_param->state, &expected,
13581 : : AGE_FREE, rte_memory_order_relaxed,
13582 : : rte_memory_order_relaxed)) {
13583 : : /**
13584 : : * We need the lock even it is age timeout,
13585 : : * since age action may still in process.
13586 : : */
13587 : 0 : rte_spinlock_lock(&age_info->aged_sl);
13588 [ # # ]: 0 : LIST_REMOVE(age, next);
13589 : : rte_spinlock_unlock(&age_info->aged_sl);
13590 : 0 : rte_atomic_store_explicit(&age_param->state, AGE_FREE, rte_memory_order_relaxed);
13591 : : }
13592 : 0 : }
13593 : :
13594 : : /**
13595 : : * Release an ASO age action.
13596 : : *
13597 : : * @param[in] dev
13598 : : * Pointer to the Ethernet device structure.
13599 : : * @param[in] age_idx
13600 : : * Index of ASO age action to release.
13601 : : * @param[in] flow
13602 : : * True if the release operation is during flow destroy operation.
13603 : : * False if the release operation is during action destroy operation.
13604 : : *
13605 : : * @return
13606 : : * 0 when age action was removed, otherwise the number of references.
13607 : : */
13608 : : static int
13609 : 0 : flow_dv_aso_age_release(struct rte_eth_dev *dev, uint32_t age_idx)
13610 : : {
13611 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13612 : 0 : struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
13613 : 0 : struct mlx5_aso_age_action *age = mlx5_flow_aso_age_get_by_idx(dev, age_idx);
13614 : 0 : uint32_t ret = rte_atomic_fetch_sub_explicit(&age->refcnt, 1, rte_memory_order_relaxed) - 1;
13615 : :
13616 [ # # ]: 0 : if (!ret) {
13617 : 0 : flow_dv_aso_age_remove_from_age(dev, age);
13618 : 0 : rte_spinlock_lock(&mng->free_sl);
13619 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free, age, next);
13620 : : rte_spinlock_unlock(&mng->free_sl);
13621 : : }
13622 : 0 : return ret;
13623 : : }
13624 : :
13625 : : /**
13626 : : * Resize the ASO age pools array by MLX5_ASO_AGE_CONTAINER_RESIZE pools.
13627 : : *
13628 : : * @param[in] dev
13629 : : * Pointer to the Ethernet device structure.
13630 : : *
13631 : : * @return
13632 : : * 0 on success, otherwise negative errno value and rte_errno is set.
13633 : : */
13634 : : static int
13635 : 0 : flow_dv_aso_age_pools_resize(struct rte_eth_dev *dev)
13636 : : {
13637 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13638 : 0 : struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
13639 : 0 : void *old_pools = mng->pools;
13640 : 0 : uint32_t resize = mng->n + MLX5_ASO_AGE_CONTAINER_RESIZE;
13641 : 0 : uint32_t mem_size = sizeof(struct mlx5_aso_age_pool *) * resize;
13642 : 0 : void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
13643 : :
13644 [ # # ]: 0 : if (!pools) {
13645 : 0 : rte_errno = ENOMEM;
13646 : 0 : return -ENOMEM;
13647 : : }
13648 [ # # ]: 0 : if (old_pools) {
13649 : 0 : memcpy(pools, old_pools,
13650 : 0 : mng->n * sizeof(struct mlx5_flow_counter_pool *));
13651 : 0 : mlx5_free(old_pools);
13652 : : } else {
13653 : : /* First ASO flow hit allocation - starting ASO data-path. */
13654 : 0 : int ret = mlx5_aso_flow_hit_queue_poll_start(priv->sh);
13655 : :
13656 [ # # ]: 0 : if (ret) {
13657 : 0 : mlx5_free(pools);
13658 : 0 : return ret;
13659 : : }
13660 : : }
13661 : 0 : mng->n = resize;
13662 : 0 : mng->pools = pools;
13663 : 0 : return 0;
13664 : : }
13665 : :
13666 : : /**
13667 : : * Create and initialize a new ASO aging pool.
13668 : : *
13669 : : * @param[in] dev
13670 : : * Pointer to the Ethernet device structure.
13671 : : * @param[out] age_free
13672 : : * Where to put the pointer of a new age action.
13673 : : *
13674 : : * @return
13675 : : * The age actions pool pointer and @p age_free is set on success,
13676 : : * NULL otherwise and rte_errno is set.
13677 : : */
13678 : : static struct mlx5_aso_age_pool *
13679 : 0 : flow_dv_age_pool_create(struct rte_eth_dev *dev,
13680 : : struct mlx5_aso_age_action **age_free)
13681 : : {
13682 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13683 : 0 : struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
13684 : : struct mlx5_aso_age_pool *pool = NULL;
13685 : : struct mlx5_devx_obj *obj = NULL;
13686 : : uint32_t i;
13687 : :
13688 : 0 : obj = mlx5_devx_cmd_create_flow_hit_aso_obj(priv->sh->cdev->ctx,
13689 : 0 : priv->sh->cdev->pdn);
13690 [ # # ]: 0 : if (!obj) {
13691 : 0 : rte_errno = ENODATA;
13692 : 0 : DRV_LOG(ERR, "Failed to create flow_hit_aso_obj using DevX.");
13693 : 0 : return NULL;
13694 : : }
13695 : 0 : pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
13696 [ # # ]: 0 : if (!pool) {
13697 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
13698 : 0 : rte_errno = ENOMEM;
13699 : 0 : return NULL;
13700 : : }
13701 : 0 : pool->flow_hit_aso_obj = obj;
13702 : 0 : pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
13703 : 0 : rte_rwlock_write_lock(&mng->resize_rwl);
13704 : 0 : pool->index = mng->next;
13705 : : /* Resize pools array if there is no room for the new pool in it. */
13706 [ # # # # ]: 0 : if (pool->index == mng->n && flow_dv_aso_age_pools_resize(dev)) {
13707 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
13708 : 0 : mlx5_free(pool);
13709 : : rte_rwlock_write_unlock(&mng->resize_rwl);
13710 : 0 : return NULL;
13711 : : }
13712 : 0 : mng->pools[pool->index] = pool;
13713 : 0 : mng->next++;
13714 : : rte_rwlock_write_unlock(&mng->resize_rwl);
13715 : : /* Assign the first action in the new pool, the rest go to free list. */
13716 : 0 : *age_free = &pool->actions[0];
13717 [ # # ]: 0 : for (i = 1; i < MLX5_ASO_AGE_ACTIONS_PER_POOL; i++) {
13718 : 0 : pool->actions[i].offset = i;
13719 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free, &pool->actions[i], next);
13720 : : }
13721 : : return pool;
13722 : : }
13723 : :
13724 : : /**
13725 : : * Allocate a ASO aging bit.
13726 : : *
13727 : : * @param[in] dev
13728 : : * Pointer to the Ethernet device structure.
13729 : : * @param[out] error
13730 : : * Pointer to the error structure.
13731 : : *
13732 : : * @return
13733 : : * Index to ASO age action on success, 0 otherwise and rte_errno is set.
13734 : : */
13735 : : static uint32_t
13736 : 0 : flow_dv_aso_age_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
13737 : : {
13738 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13739 : : const struct mlx5_aso_age_pool *pool;
13740 : 0 : struct mlx5_aso_age_action *age_free = NULL;
13741 : 0 : struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
13742 : :
13743 : : MLX5_ASSERT(mng);
13744 : : /* Try to get the next free age action bit. */
13745 : 0 : rte_spinlock_lock(&mng->free_sl);
13746 : 0 : age_free = LIST_FIRST(&mng->free);
13747 [ # # ]: 0 : if (age_free) {
13748 [ # # ]: 0 : LIST_REMOVE(age_free, next);
13749 [ # # ]: 0 : } else if (!flow_dv_age_pool_create(dev, &age_free)) {
13750 : : rte_spinlock_unlock(&mng->free_sl);
13751 : 0 : rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
13752 : : NULL, "failed to create ASO age pool");
13753 : 0 : return 0; /* 0 is an error. */
13754 : : }
13755 : : rte_spinlock_unlock(&mng->free_sl);
13756 : 0 : pool = container_of
13757 : : ((const struct mlx5_aso_age_action (*)[MLX5_ASO_AGE_ACTIONS_PER_POOL])
13758 : : (age_free - age_free->offset), const struct mlx5_aso_age_pool,
13759 : : actions);
13760 [ # # ]: 0 : if (!age_free->dr_action) {
13761 : 0 : int reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_FLOW_HIT, 0,
13762 : : error);
13763 : :
13764 [ # # ]: 0 : if (reg_c < 0) {
13765 : 0 : rte_flow_error_set(error, rte_errno,
13766 : : RTE_FLOW_ERROR_TYPE_ACTION,
13767 : : NULL, "failed to get reg_c "
13768 : : "for ASO flow hit");
13769 : 0 : return 0; /* 0 is an error. */
13770 : : }
13771 : : #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
13772 : 0 : age_free->dr_action = mlx5_glue->dv_create_flow_action_aso
13773 : 0 : (priv->sh->rx_domain,
13774 : 0 : pool->flow_hit_aso_obj->obj, age_free->offset,
13775 : : MLX5DV_DR_ACTION_FLAGS_ASO_FIRST_HIT_SET,
13776 : 0 : (reg_c - REG_C_0));
13777 : : #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
13778 [ # # ]: 0 : if (!age_free->dr_action) {
13779 : 0 : rte_errno = errno;
13780 : : rte_spinlock_lock(&mng->free_sl);
13781 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free, age_free, next);
13782 : : rte_spinlock_unlock(&mng->free_sl);
13783 : 0 : rte_flow_error_set(error, rte_errno,
13784 : : RTE_FLOW_ERROR_TYPE_ACTION,
13785 : : NULL, "failed to create ASO "
13786 : : "flow hit action");
13787 : 0 : return 0; /* 0 is an error. */
13788 : : }
13789 : : }
13790 : 0 : rte_atomic_store_explicit(&age_free->refcnt, 1, rte_memory_order_relaxed);
13791 : 0 : return pool->index | ((age_free->offset + 1) << 16);
13792 : : }
13793 : :
13794 : : /**
13795 : : * Initialize flow ASO age parameters.
13796 : : *
13797 : : * @param[in] dev
13798 : : * Pointer to rte_eth_dev structure.
13799 : : * @param[in] age_idx
13800 : : * Index of ASO age action.
13801 : : * @param[in] context
13802 : : * Pointer to flow counter age context.
13803 : : * @param[in] timeout
13804 : : * Aging timeout in seconds.
13805 : : *
13806 : : */
13807 : : static void
13808 : 0 : flow_dv_aso_age_params_init(struct rte_eth_dev *dev,
13809 : : uint32_t age_idx,
13810 : : void *context,
13811 : : uint32_t timeout)
13812 : : {
13813 : : struct mlx5_aso_age_action *aso_age;
13814 : :
13815 : 0 : aso_age = mlx5_flow_aso_age_get_by_idx(dev, age_idx);
13816 : : MLX5_ASSERT(aso_age);
13817 : 0 : aso_age->age_params.context = context;
13818 : 0 : aso_age->age_params.timeout = timeout;
13819 : 0 : aso_age->age_params.port_id = dev->data->port_id;
13820 : 0 : rte_atomic_store_explicit(&aso_age->age_params.sec_since_last_hit, 0,
13821 : : rte_memory_order_relaxed);
13822 : 0 : rte_atomic_store_explicit(&aso_age->age_params.state, AGE_CANDIDATE,
13823 : : rte_memory_order_relaxed);
13824 : 0 : }
13825 : :
13826 : : static void
13827 : 0 : flow_dv_translate_integrity_l4(const struct rte_flow_item_integrity *mask,
13828 : : void *headers)
13829 : : {
13830 : : /*
13831 : : * In HWS mode MLX5_ITEM_UPDATE() macro assigns the same pointer to
13832 : : * both mask and value, therefore ether can be used.
13833 : : * In SWS SW_V mode mask points to item mask and value points to item
13834 : : * spec. Integrity item value is used only if matching mask is set.
13835 : : * Use mask reference here to keep SWS functionality.
13836 : : */
13837 [ # # ]: 0 : if (mask->l4_ok) {
13838 : : /* RTE l4_ok filter aggregates hardware l4_ok and
13839 : : * l4_checksum_ok filters.
13840 : : * Positive RTE l4_ok match requires hardware match on both L4
13841 : : * hardware integrity bits.
13842 : : * PMD supports positive integrity item semantics only.
13843 : : */
13844 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, l4_ok, 1);
13845 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, l4_checksum_ok, 1);
13846 [ # # ]: 0 : } else if (mask->l4_csum_ok) {
13847 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, l4_checksum_ok, 1);
13848 : : }
13849 : 0 : }
13850 : :
13851 : : static void
13852 : 0 : flow_dv_translate_integrity_l3(const struct rte_flow_item_integrity *mask,
13853 : : void *headers, bool is_ipv4)
13854 : : {
13855 : : /*
13856 : : * In HWS mode MLX5_ITEM_UPDATE() macro assigns the same pointer to
13857 : : * both mask and value, therefore ether can be used.
13858 : : * In SWS SW_V mode mask points to item mask and value points to item
13859 : : * spec. Integrity item value used only if matching mask is set.
13860 : : * Use mask reference here to keep SWS functionality.
13861 : : */
13862 [ # # ]: 0 : if (mask->l3_ok) {
13863 : : /* RTE l3_ok filter aggregates for IPv4 hardware l3_ok and
13864 : : * ipv4_csum_ok filters.
13865 : : * Positive RTE l3_ok match requires hardware match on both L3
13866 : : * hardware integrity bits.
13867 : : * PMD supports positive integrity item semantics only.
13868 : : */
13869 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, l3_ok, 1);
13870 [ # # ]: 0 : if (is_ipv4) {
13871 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers,
13872 : : ipv4_checksum_ok, 1);
13873 : : }
13874 [ # # # # ]: 0 : } else if (is_ipv4 && mask->ipv4_csum_ok) {
13875 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, ipv4_checksum_ok, 1);
13876 : : }
13877 : 0 : }
13878 : :
13879 : : static void
13880 : 0 : set_integrity_bits(void *headers, const struct rte_flow_item *integrity_item,
13881 : : bool is_l3_ip4, uint32_t key_type)
13882 : : {
13883 : : const struct rte_flow_item_integrity *spec;
13884 : : const struct rte_flow_item_integrity *mask;
13885 : :
13886 : : /* Integrity bits validation cleared spec pointer */
13887 [ # # # # : 0 : if (MLX5_ITEM_VALID(integrity_item, key_type))
# # # # #
# ]
13888 : : return;
13889 [ # # # # : 0 : MLX5_ITEM_UPDATE(integrity_item, key_type, spec, mask,
# # # # ]
13890 : : &rte_flow_item_integrity_mask);
13891 : 0 : flow_dv_translate_integrity_l3(mask, headers, is_l3_ip4);
13892 : 0 : flow_dv_translate_integrity_l4(mask, headers);
13893 : : }
13894 : :
13895 : : static void
13896 : 0 : flow_dv_translate_item_integrity_post(void *key,
13897 : : const
13898 : : struct rte_flow_item *integrity_items[2],
13899 : : uint64_t pattern_flags, uint32_t key_type)
13900 : : {
13901 : : void *headers;
13902 : : bool is_l3_ip4;
13903 : :
13904 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_INNER_INTEGRITY) {
13905 : 0 : headers = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
13906 : 0 : is_l3_ip4 = (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV4) !=
13907 : : 0;
13908 : 0 : set_integrity_bits(headers, integrity_items[1], is_l3_ip4,
13909 : : key_type);
13910 : : }
13911 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_OUTER_INTEGRITY) {
13912 : : headers = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
13913 : 0 : is_l3_ip4 = (pattern_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV4) !=
13914 : : 0;
13915 : 0 : set_integrity_bits(headers, integrity_items[0], is_l3_ip4,
13916 : : key_type);
13917 : : }
13918 : 0 : }
13919 : :
13920 : : static uint64_t
13921 : : flow_dv_translate_item_integrity(const struct rte_flow_item *item,
13922 : : struct mlx5_dv_matcher_workspace *wks,
13923 : : uint64_t key_type)
13924 : : {
13925 : 0 : if ((key_type & MLX5_SET_MATCHER_SW) != 0) {
13926 : : const struct rte_flow_item_integrity
13927 : 0 : *spec = (typeof(spec))item->spec;
13928 : :
13929 : : /* SWS integrity bits validation cleared spec pointer */
13930 [ # # ]: 0 : if (spec->level > 1) {
13931 : 0 : wks->integrity_items[1] = item;
13932 : 0 : wks->last_item |= MLX5_FLOW_ITEM_INNER_INTEGRITY;
13933 : : } else {
13934 : 0 : wks->integrity_items[0] = item;
13935 : 0 : wks->last_item |= MLX5_FLOW_ITEM_OUTER_INTEGRITY;
13936 : : }
13937 : : } else {
13938 : : /* HWS supports outer integrity only */
13939 : 0 : wks->integrity_items[0] = item;
13940 : 0 : wks->last_item |= MLX5_FLOW_ITEM_OUTER_INTEGRITY;
13941 : : }
13942 : 0 : return wks->last_item;
13943 : : }
13944 : :
13945 : : /**
13946 : : * Prepares DV flow counter with aging configuration.
13947 : : * Gets it by index when exists, creates a new one when doesn't.
13948 : : *
13949 : : * @param[in] dev
13950 : : * Pointer to rte_eth_dev structure.
13951 : : * @param[in] dev_flow
13952 : : * Pointer to the mlx5_flow.
13953 : : * @param[in, out] flow
13954 : : * Pointer to the sub flow.
13955 : : * @param[in] count
13956 : : * Pointer to the counter action configuration.
13957 : : * @param[in] age
13958 : : * Pointer to the aging action configuration.
13959 : : * @param[out] error
13960 : : * Pointer to the error structure.
13961 : : *
13962 : : * @return
13963 : : * Pointer to the counter, NULL otherwise.
13964 : : */
13965 : : static struct mlx5_flow_counter *
13966 : 0 : flow_dv_prepare_counter(struct rte_eth_dev *dev,
13967 : : struct mlx5_flow *dev_flow,
13968 : : struct rte_flow *flow,
13969 : : const struct rte_flow_action_count *count,
13970 : : const struct rte_flow_action_age *age,
13971 : : struct rte_flow_error *error)
13972 : : {
13973 [ # # ]: 0 : if (!flow->counter) {
13974 : 0 : flow->counter = flow_dv_translate_create_counter(dev, dev_flow,
13975 : : count, age);
13976 [ # # ]: 0 : if (!flow->counter) {
13977 : 0 : rte_flow_error_set(error, rte_errno,
13978 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
13979 : : "cannot create counter object.");
13980 : 0 : return NULL;
13981 : : }
13982 : : }
13983 [ # # ]: 0 : return flow_dv_counter_get_by_idx(dev, flow->counter, NULL);
13984 : : }
13985 : :
13986 : : /*
13987 : : * Release an ASO CT action by its own device.
13988 : : *
13989 : : * @param[in] dev
13990 : : * Pointer to the Ethernet device structure.
13991 : : * @param[in] idx
13992 : : * Index of ASO CT action to release.
13993 : : *
13994 : : * @return
13995 : : * 0 when CT action was removed, otherwise the number of references.
13996 : : */
13997 : : static inline int
13998 : 0 : flow_dv_aso_ct_dev_release(struct rte_eth_dev *dev, uint32_t idx)
13999 : : {
14000 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14001 : 0 : struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
14002 : : uint32_t ret;
14003 : 0 : struct mlx5_aso_ct_action *ct = flow_aso_ct_get_by_dev_idx(dev, idx);
14004 : : enum mlx5_aso_ct_state state =
14005 : 0 : rte_atomic_load_explicit(&ct->state, rte_memory_order_relaxed);
14006 : :
14007 : : /* Cannot release when CT is in the ASO SQ. */
14008 [ # # ]: 0 : if (state == ASO_CONNTRACK_WAIT || state == ASO_CONNTRACK_QUERY)
14009 : : return -1;
14010 : 0 : ret = rte_atomic_fetch_sub_explicit(&ct->refcnt, 1, rte_memory_order_relaxed) - 1;
14011 [ # # ]: 0 : if (!ret) {
14012 [ # # ]: 0 : if (ct->dr_action_orig) {
14013 : : #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
14014 : 0 : claim_zero(mlx5_glue->destroy_flow_action
14015 : : (ct->dr_action_orig));
14016 : : #endif
14017 : 0 : ct->dr_action_orig = NULL;
14018 : : }
14019 [ # # ]: 0 : if (ct->dr_action_rply) {
14020 : : #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
14021 : 0 : claim_zero(mlx5_glue->destroy_flow_action
14022 : : (ct->dr_action_rply));
14023 : : #endif
14024 : 0 : ct->dr_action_rply = NULL;
14025 : : }
14026 : : /* Clear the state to free, no need in 1st allocation. */
14027 : 0 : MLX5_ASO_CT_UPDATE_STATE(ct, ASO_CONNTRACK_FREE);
14028 : 0 : rte_spinlock_lock(&mng->ct_sl);
14029 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free_cts, ct, next);
14030 : : rte_spinlock_unlock(&mng->ct_sl);
14031 : : }
14032 : 0 : return (int)ret;
14033 : : }
14034 : :
14035 : : static inline int
14036 : 0 : flow_dv_aso_ct_release(struct rte_eth_dev *dev, uint32_t own_idx,
14037 : : struct rte_flow_error *error)
14038 : : {
14039 : 0 : uint16_t owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(own_idx);
14040 : 0 : uint32_t idx = MLX5_INDIRECT_ACT_CT_GET_IDX(own_idx);
14041 : 0 : struct rte_eth_dev *owndev = &rte_eth_devices[owner];
14042 : : int ret;
14043 : :
14044 : : MLX5_ASSERT(owner < RTE_MAX_ETHPORTS);
14045 [ # # ]: 0 : if (dev->data->dev_started != 1)
14046 : 0 : return rte_flow_error_set(error, EAGAIN,
14047 : : RTE_FLOW_ERROR_TYPE_ACTION,
14048 : : NULL,
14049 : : "Indirect CT action cannot be destroyed when the port is stopped");
14050 : 0 : ret = flow_dv_aso_ct_dev_release(owndev, idx);
14051 [ # # ]: 0 : if (ret < 0)
14052 : 0 : return rte_flow_error_set(error, EAGAIN,
14053 : : RTE_FLOW_ERROR_TYPE_ACTION,
14054 : : NULL,
14055 : : "Current state prevents indirect CT action from being destroyed");
14056 : : return ret;
14057 : : }
14058 : :
14059 : : /*
14060 : : * Resize the ASO CT pools array by 64 pools.
14061 : : *
14062 : : * @param[in] dev
14063 : : * Pointer to the Ethernet device structure.
14064 : : *
14065 : : * @return
14066 : : * 0 on success, otherwise negative errno value and rte_errno is set.
14067 : : */
14068 : : static int
14069 : 0 : flow_dv_aso_ct_pools_resize(struct rte_eth_dev *dev)
14070 : : {
14071 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14072 : 0 : struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
14073 : 0 : void *old_pools = mng->pools;
14074 : : /* Magic number now, need a macro. */
14075 : 0 : uint32_t resize = mng->n + 64;
14076 : 0 : uint32_t mem_size = sizeof(struct mlx5_aso_ct_pool *) * resize;
14077 : 0 : void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
14078 : :
14079 [ # # ]: 0 : if (!pools) {
14080 : 0 : rte_errno = ENOMEM;
14081 : 0 : return -rte_errno;
14082 : : }
14083 : 0 : rte_rwlock_write_lock(&mng->resize_rwl);
14084 : : /* ASO SQ/QP was already initialized in the startup. */
14085 [ # # ]: 0 : if (old_pools) {
14086 : : /* Realloc could be an alternative choice. */
14087 : 0 : rte_memcpy(pools, old_pools,
14088 [ # # ]: 0 : mng->n * sizeof(struct mlx5_aso_ct_pool *));
14089 : 0 : mlx5_free(old_pools);
14090 : : }
14091 : 0 : mng->n = resize;
14092 : 0 : mng->pools = pools;
14093 : : rte_rwlock_write_unlock(&mng->resize_rwl);
14094 : 0 : return 0;
14095 : : }
14096 : :
14097 : : /*
14098 : : * Create and initialize a new ASO CT pool.
14099 : : *
14100 : : * @param[in] dev
14101 : : * Pointer to the Ethernet device structure.
14102 : : * @param[out] ct_free
14103 : : * Where to put the pointer of a new CT action.
14104 : : *
14105 : : * @return
14106 : : * The CT actions pool pointer and @p ct_free is set on success,
14107 : : * NULL otherwise and rte_errno is set.
14108 : : */
14109 : : static struct mlx5_aso_ct_pool *
14110 : 0 : flow_dv_ct_pool_create(struct rte_eth_dev *dev,
14111 : : struct mlx5_aso_ct_action **ct_free)
14112 : : {
14113 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14114 : 0 : struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
14115 : : struct mlx5_aso_ct_pool *pool = NULL;
14116 : : struct mlx5_devx_obj *obj = NULL;
14117 : : uint32_t i;
14118 : : uint32_t log_obj_size = rte_log2_u32(MLX5_ASO_CT_ACTIONS_PER_POOL);
14119 : : size_t mem_size;
14120 : :
14121 : 0 : obj = mlx5_devx_cmd_create_conn_track_offload_obj(priv->sh->cdev->ctx,
14122 : 0 : priv->sh->cdev->pdn,
14123 : : log_obj_size);
14124 [ # # ]: 0 : if (!obj) {
14125 : 0 : rte_errno = ENODATA;
14126 : 0 : DRV_LOG(ERR, "Failed to create conn_track_offload_obj using DevX.");
14127 : 0 : return NULL;
14128 : : }
14129 : : mem_size = sizeof(struct mlx5_aso_ct_action) *
14130 : : MLX5_ASO_CT_ACTIONS_PER_POOL +
14131 : : sizeof(*pool);
14132 : 0 : pool = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
14133 [ # # ]: 0 : if (!pool) {
14134 : 0 : rte_errno = ENOMEM;
14135 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
14136 : 0 : return NULL;
14137 : : }
14138 : 0 : pool->devx_obj = obj;
14139 : 0 : pool->index = mng->next;
14140 : : /* Resize pools array if there is no room for the new pool in it. */
14141 [ # # # # ]: 0 : if (pool->index == mng->n && flow_dv_aso_ct_pools_resize(dev)) {
14142 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
14143 : 0 : mlx5_free(pool);
14144 : 0 : return NULL;
14145 : : }
14146 : 0 : mng->pools[pool->index] = pool;
14147 : 0 : mng->next++;
14148 : : /* Assign the first action in the new pool, the rest go to free list. */
14149 : 0 : *ct_free = &pool->actions[0];
14150 : : /* Lock outside, the list operation is safe here. */
14151 [ # # ]: 0 : for (i = 1; i < MLX5_ASO_CT_ACTIONS_PER_POOL; i++) {
14152 : : /* refcnt is 0 when allocating the memory. */
14153 : 0 : pool->actions[i].offset = i;
14154 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free_cts, &pool->actions[i], next);
14155 : : }
14156 : : return pool;
14157 : : }
14158 : :
14159 : : /*
14160 : : * Allocate a ASO CT action from free list.
14161 : : *
14162 : : * @param[in] dev
14163 : : * Pointer to the Ethernet device structure.
14164 : : * @param[out] error
14165 : : * Pointer to the error structure.
14166 : : *
14167 : : * @return
14168 : : * Index to ASO CT action on success, 0 otherwise and rte_errno is set.
14169 : : */
14170 : : static uint32_t
14171 : 0 : flow_dv_aso_ct_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
14172 : : {
14173 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14174 : 0 : struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
14175 : 0 : struct mlx5_aso_ct_action *ct = NULL;
14176 : : struct mlx5_aso_ct_pool *pool;
14177 : : uint8_t reg_c;
14178 : : uint32_t ct_idx;
14179 : :
14180 : : MLX5_ASSERT(mng);
14181 [ # # ]: 0 : if (!priv->sh->cdev->config.devx) {
14182 : 0 : rte_errno = ENOTSUP;
14183 : 0 : return 0;
14184 : : }
14185 : : /* Get a free CT action, if no, a new pool will be created. */
14186 : 0 : rte_spinlock_lock(&mng->ct_sl);
14187 : 0 : ct = LIST_FIRST(&mng->free_cts);
14188 [ # # ]: 0 : if (ct) {
14189 [ # # ]: 0 : LIST_REMOVE(ct, next);
14190 [ # # ]: 0 : } else if (!flow_dv_ct_pool_create(dev, &ct)) {
14191 : : rte_spinlock_unlock(&mng->ct_sl);
14192 : 0 : rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
14193 : : NULL, "failed to create ASO CT pool");
14194 : 0 : return 0;
14195 : : }
14196 : : rte_spinlock_unlock(&mng->ct_sl);
14197 : 0 : pool = container_of(ct, struct mlx5_aso_ct_pool, actions[ct->offset]);
14198 : 0 : ct_idx = MLX5_MAKE_CT_IDX(pool->index, ct->offset);
14199 : : /* 0: inactive, 1: created, 2+: used by flows. */
14200 : 0 : rte_atomic_store_explicit(&ct->refcnt, 1, rte_memory_order_relaxed);
14201 : 0 : reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_CONNTRACK, 0, error);
14202 [ # # ]: 0 : if (!ct->dr_action_orig) {
14203 : : #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
14204 : 0 : ct->dr_action_orig = mlx5_glue->dv_create_flow_action_aso
14205 : 0 : (priv->sh->rx_domain, pool->devx_obj->obj,
14206 : : ct->offset,
14207 : : MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_INITIATOR,
14208 : 0 : reg_c - REG_C_0);
14209 : : #else
14210 : : RTE_SET_USED(reg_c);
14211 : : #endif
14212 [ # # ]: 0 : if (!ct->dr_action_orig) {
14213 : 0 : flow_dv_aso_ct_dev_release(dev, ct_idx);
14214 : 0 : rte_flow_error_set(error, rte_errno,
14215 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14216 : : "failed to create ASO CT action");
14217 : 0 : return 0;
14218 : : }
14219 : : }
14220 [ # # ]: 0 : if (!ct->dr_action_rply) {
14221 : : #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
14222 : 0 : ct->dr_action_rply = mlx5_glue->dv_create_flow_action_aso
14223 : 0 : (priv->sh->rx_domain, pool->devx_obj->obj,
14224 : : ct->offset,
14225 : : MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_RESPONDER,
14226 : 0 : reg_c - REG_C_0);
14227 : : #endif
14228 [ # # ]: 0 : if (!ct->dr_action_rply) {
14229 : 0 : flow_dv_aso_ct_dev_release(dev, ct_idx);
14230 : 0 : rte_flow_error_set(error, rte_errno,
14231 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14232 : : "failed to create ASO CT action");
14233 : 0 : return 0;
14234 : : }
14235 : : }
14236 : : return ct_idx;
14237 : : }
14238 : :
14239 : : /*
14240 : : * Create a conntrack object with context and actions by using ASO mechanism.
14241 : : *
14242 : : * @param[in] dev
14243 : : * Pointer to rte_eth_dev structure.
14244 : : * @param[in] pro
14245 : : * Pointer to conntrack information profile.
14246 : : * @param[out] error
14247 : : * Pointer to the error structure.
14248 : : *
14249 : : * @return
14250 : : * Index to conntrack object on success, 0 otherwise.
14251 : : */
14252 : : static uint32_t
14253 : 0 : flow_dv_translate_create_conntrack(struct rte_eth_dev *dev,
14254 : : const struct rte_flow_action_conntrack *pro,
14255 : : struct rte_flow_error *error)
14256 : : {
14257 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14258 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
14259 : : struct mlx5_aso_ct_action *ct;
14260 : : uint32_t idx;
14261 : :
14262 [ # # ]: 0 : if (!sh->ct_aso_en)
14263 : 0 : return rte_flow_error_set(error, ENOTSUP,
14264 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14265 : : "Connection is not supported");
14266 [ # # ]: 0 : if (dev->data->port_id >= MLX5_INDIRECT_ACT_CT_MAX_PORT) {
14267 : 0 : rte_flow_error_set(error, EINVAL,
14268 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14269 : : "CT supports port indexes up to "
14270 : : RTE_STR(MLX5_ACTION_CTX_CT_MAX_PORT));
14271 : 0 : return 0;
14272 : : }
14273 : 0 : idx = flow_dv_aso_ct_alloc(dev, error);
14274 [ # # ]: 0 : if (!idx)
14275 : 0 : return rte_flow_error_set(error, rte_errno,
14276 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14277 : : "Failed to allocate CT object");
14278 : 0 : ct = flow_aso_ct_get_by_dev_idx(dev, idx);
14279 [ # # ]: 0 : if (mlx5_aso_ct_update_by_wqe(sh, MLX5_HW_INV_QUEUE, ct, pro, NULL, true)) {
14280 : 0 : flow_dv_aso_ct_dev_release(dev, idx);
14281 : 0 : rte_flow_error_set(error, EBUSY,
14282 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14283 : : "Failed to update CT");
14284 : 0 : return 0;
14285 : : }
14286 : 0 : ct->is_original = !!pro->is_original_dir;
14287 : 0 : ct->peer = pro->peer_port;
14288 : 0 : return idx;
14289 : : }
14290 : :
14291 : : /**
14292 : : * Fill the flow matcher with DV spec.
14293 : : *
14294 : : * @param[in] dev
14295 : : * Pointer to rte_eth_dev structure.
14296 : : * @param[in] items
14297 : : * Pointer to the list of items.
14298 : : * @param[in] wks
14299 : : * Pointer to the matcher workspace.
14300 : : * @param[in] key
14301 : : * Pointer to the flow matcher key.
14302 : : * @param[in] key_type
14303 : : * Key type.
14304 : : * @param[out] error
14305 : : * Pointer to the error structure.
14306 : : *
14307 : : * @return
14308 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14309 : : */
14310 : : static int
14311 : 0 : flow_dv_translate_items(struct rte_eth_dev *dev,
14312 : : const struct rte_flow_item *items,
14313 : : struct mlx5_dv_matcher_workspace *wks,
14314 : : void *key, uint32_t key_type,
14315 : : struct rte_flow_error *error)
14316 : : {
14317 : 0 : struct mlx5_flow_rss_desc *rss_desc = wks->rss_desc;
14318 : 0 : uint8_t next_protocol = wks->next_protocol;
14319 : 0 : int tunnel = !!(wks->item_flags & MLX5_FLOW_LAYER_TUNNEL);
14320 : 0 : int item_type = items->type;
14321 : 0 : uint64_t last_item = wks->last_item;
14322 : : enum mlx5_l3_tunnel_detection l3_tunnel_detection;
14323 : : uint64_t l3_tunnel_flag;
14324 : : int ret;
14325 : :
14326 [ # # # # : 0 : switch (item_type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
14327 : 0 : case RTE_FLOW_ITEM_TYPE_ESP:
14328 : 0 : flow_dv_translate_item_esp(key, items, tunnel, key_type, wks->item_flags);
14329 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14330 : : last_item = MLX5_FLOW_ITEM_ESP;
14331 : 0 : break;
14332 : 0 : case RTE_FLOW_ITEM_TYPE_PORT_ID:
14333 : 0 : flow_dv_translate_item_port_id
14334 : : (dev, key, items, wks->attr, key_type);
14335 : : last_item = MLX5_FLOW_ITEM_PORT_ID;
14336 : 0 : break;
14337 : 0 : case RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR:
14338 : 0 : flow_dv_translate_item_port_representor
14339 : : (dev, key, key_type);
14340 : : last_item = MLX5_FLOW_ITEM_PORT_REPRESENTOR;
14341 : 0 : break;
14342 : 0 : case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
14343 : 0 : flow_dv_translate_item_represented_port
14344 : : (dev, key, items, wks->attr, key_type);
14345 : : last_item = MLX5_FLOW_ITEM_REPRESENTED_PORT;
14346 : 0 : break;
14347 : 0 : case RTE_FLOW_ITEM_TYPE_ETH:
14348 : 0 : flow_dv_translate_item_eth(key, items, tunnel,
14349 : : wks->group, key_type);
14350 [ # # ]: 0 : wks->priority = wks->action_flags &
14351 : 0 : MLX5_FLOW_ACTION_DEFAULT_MISS &&
14352 [ # # ]: 0 : !wks->external ?
14353 : : MLX5_PRIORITY_MAP_L3 :
14354 : : MLX5_PRIORITY_MAP_L2;
14355 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
14356 : : MLX5_FLOW_LAYER_OUTER_L2;
14357 : : break;
14358 : 0 : case RTE_FLOW_ITEM_TYPE_VLAN:
14359 : 0 : flow_dv_translate_item_vlan(key, items, tunnel, wks, key_type);
14360 : 0 : wks->priority = MLX5_PRIORITY_MAP_L2;
14361 : : last_item = tunnel ? (MLX5_FLOW_LAYER_INNER_L2 |
14362 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_VLAN) :
14363 : : (MLX5_FLOW_LAYER_OUTER_L2 |
14364 : : MLX5_FLOW_LAYER_OUTER_VLAN);
14365 : : break;
14366 : : case RTE_FLOW_ITEM_TYPE_IPV4:
14367 : : next_protocol = mlx5_flow_l3_next_protocol(items, key_type);
14368 : : l3_tunnel_detection =
14369 : : mlx5_flow_tunnel_ip_check(items, next_protocol,
14370 : : wks->item_flags,
14371 : : &l3_tunnel_flag);
14372 : : if (l3_tunnel_detection == l3_tunnel_inner) {
14373 : 0 : wks->item_flags |= l3_tunnel_flag;
14374 : : tunnel = 1;
14375 : : }
14376 : 0 : flow_dv_translate_item_ipv4(key, items, tunnel,
14377 : : wks->group, key_type);
14378 : 0 : wks->priority = MLX5_PRIORITY_MAP_L3;
14379 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
14380 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4;
14381 [ # # ]: 0 : if (l3_tunnel_detection == l3_tunnel_outer)
14382 : 0 : wks->item_flags |= l3_tunnel_flag;
14383 : : break;
14384 : : case RTE_FLOW_ITEM_TYPE_IPV6:
14385 : : next_protocol = mlx5_flow_l3_next_protocol(items, key_type);
14386 : : l3_tunnel_detection =
14387 : : mlx5_flow_tunnel_ip_check(items, next_protocol,
14388 : : wks->item_flags,
14389 : : &l3_tunnel_flag);
14390 : : if (l3_tunnel_detection == l3_tunnel_inner) {
14391 : 0 : wks->item_flags |= l3_tunnel_flag;
14392 : : tunnel = 1;
14393 : : }
14394 : 0 : flow_dv_translate_item_ipv6(key, items, tunnel,
14395 : : wks->group, key_type);
14396 : 0 : wks->priority = MLX5_PRIORITY_MAP_L3;
14397 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
14398 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6;
14399 [ # # ]: 0 : if (l3_tunnel_detection == l3_tunnel_outer)
14400 : 0 : wks->item_flags |= l3_tunnel_flag;
14401 : : break;
14402 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
14403 : 0 : flow_dv_translate_item_ipv6_frag_ext
14404 : : (key, items, tunnel, key_type);
14405 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
14406 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
14407 : : next_protocol = mlx5_flow_l3_next_protocol(items, key_type);
14408 : : break;
14409 : 0 : case RTE_FLOW_ITEM_TYPE_TCP:
14410 : 0 : flow_dv_translate_item_tcp(key, items, tunnel, key_type);
14411 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14412 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
14413 : : MLX5_FLOW_LAYER_OUTER_L4_TCP;
14414 : : break;
14415 : 0 : case RTE_FLOW_ITEM_TYPE_UDP:
14416 : 0 : flow_dv_translate_item_udp(key, items, tunnel, wks, key_type);
14417 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14418 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
14419 : : MLX5_FLOW_LAYER_OUTER_L4_UDP;
14420 : : break;
14421 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
14422 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14423 : 0 : wks->tunnel_item = items;
14424 : 0 : wks->gre_item = items;
14425 : : last_item = MLX5_FLOW_LAYER_GRE;
14426 : 0 : break;
14427 : 0 : case RTE_FLOW_ITEM_TYPE_GRE_KEY:
14428 : 0 : flow_dv_translate_item_gre_key(key, items, key_type);
14429 : : last_item = MLX5_FLOW_LAYER_GRE_KEY;
14430 : 0 : break;
14431 : 0 : case RTE_FLOW_ITEM_TYPE_GRE_OPTION:
14432 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14433 : 0 : wks->tunnel_item = items;
14434 : : last_item = MLX5_FLOW_LAYER_GRE;
14435 : 0 : break;
14436 : 0 : case RTE_FLOW_ITEM_TYPE_NVGRE:
14437 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14438 : 0 : wks->tunnel_item = items;
14439 : : last_item = MLX5_FLOW_LAYER_GRE;
14440 : 0 : break;
14441 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN:
14442 : 0 : flow_dv_translate_item_vxlan(dev, wks->attr, key,
14443 : : items, tunnel, wks, key_type);
14444 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14445 : : last_item = MLX5_FLOW_LAYER_VXLAN;
14446 : 0 : break;
14447 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
14448 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14449 : 0 : wks->tunnel_item = items;
14450 : : last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
14451 : 0 : break;
14452 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE:
14453 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14454 : 0 : wks->tunnel_item = items;
14455 : : last_item = MLX5_FLOW_LAYER_GENEVE;
14456 : 0 : break;
14457 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
14458 : 0 : ret = flow_dv_translate_item_geneve_opt
14459 : : (dev, key, items, key_type, error);
14460 [ # # ]: 0 : if (ret)
14461 : 0 : return rte_flow_error_set(error, -ret,
14462 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14463 : : "cannot create GENEVE TLV option");
14464 : 0 : wks->geneve_tlv_option = 1;
14465 : : last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
14466 : 0 : break;
14467 : 0 : case RTE_FLOW_ITEM_TYPE_MPLS:
14468 : 0 : flow_dv_translate_item_mpls(key, items, last_item,
14469 : : tunnel, key_type);
14470 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14471 : : last_item = MLX5_FLOW_LAYER_MPLS;
14472 : 0 : break;
14473 : 0 : case RTE_FLOW_ITEM_TYPE_MARK:
14474 : 0 : flow_dv_translate_item_mark(dev, key, items, key_type);
14475 : : last_item = MLX5_FLOW_ITEM_MARK;
14476 : 0 : break;
14477 : 0 : case RTE_FLOW_ITEM_TYPE_META:
14478 : 0 : flow_dv_translate_item_meta
14479 : : (dev, key, wks->attr, items, key_type);
14480 : : last_item = MLX5_FLOW_ITEM_METADATA;
14481 : 0 : break;
14482 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP:
14483 : 0 : flow_dv_translate_item_icmp(key, items, tunnel, key_type);
14484 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14485 : : last_item = MLX5_FLOW_LAYER_ICMP;
14486 : 0 : break;
14487 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6:
14488 : 0 : flow_dv_translate_item_icmp6(key, items, tunnel, key_type);
14489 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14490 : : last_item = MLX5_FLOW_LAYER_ICMP6;
14491 : 0 : break;
14492 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REQUEST:
14493 : : case RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REPLY:
14494 : 0 : flow_dv_translate_item_icmp6_echo(key, items, tunnel, key_type);
14495 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14496 : : last_item = MLX5_FLOW_LAYER_ICMP6;
14497 : 0 : break;
14498 : 0 : case RTE_FLOW_ITEM_TYPE_TAG:
14499 : 0 : ret = flow_dv_translate_item_tag(dev, key, items, key_type);
14500 [ # # ]: 0 : if (ret < 0)
14501 : 0 : return rte_flow_error_set(error, -ret, RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14502 : : "invalid flow tag item");
14503 : : last_item = MLX5_FLOW_ITEM_TAG;
14504 : : break;
14505 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
14506 : 0 : flow_dv_translate_mlx5_item_tag(dev, key, items, key_type);
14507 : : last_item = MLX5_FLOW_ITEM_TAG;
14508 : 0 : break;
14509 : 0 : case RTE_FLOW_ITEM_TYPE_TX_QUEUE:
14510 : 0 : ret = flow_dv_translate_item_tx_queue(dev, key, items, key_type);
14511 [ # # ]: 0 : if (ret)
14512 : 0 : return rte_flow_error_set(error, -ret,
14513 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14514 : : "invalid tx_queue item");
14515 : : last_item = MLX5_FLOW_ITEM_SQ;
14516 : : break;
14517 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_SQ:
14518 : 0 : flow_dv_translate_item_sq(key, items, key_type);
14519 : : last_item = MLX5_FLOW_ITEM_SQ;
14520 : 0 : break;
14521 : 0 : case RTE_FLOW_ITEM_TYPE_GTP:
14522 : 0 : flow_dv_translate_item_gtp(key, items, tunnel, key_type);
14523 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14524 : : last_item = MLX5_FLOW_LAYER_GTP;
14525 : 0 : break;
14526 : 0 : case RTE_FLOW_ITEM_TYPE_GTP_PSC:
14527 : 0 : ret = flow_dv_translate_item_gtp_psc(key, items, key_type);
14528 [ # # ]: 0 : if (ret)
14529 : 0 : return rte_flow_error_set(error, -ret,
14530 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14531 : : "cannot create GTP PSC item");
14532 : : last_item = MLX5_FLOW_LAYER_GTP_PSC;
14533 : : break;
14534 : 0 : case RTE_FLOW_ITEM_TYPE_ECPRI:
14535 [ # # ]: 0 : if (!mlx5_flex_parser_ecpri_exist(dev)) {
14536 : : /* Create it only the first time to be used. */
14537 : 0 : ret = mlx5_flex_parser_ecpri_alloc(dev);
14538 [ # # ]: 0 : if (ret)
14539 : 0 : return rte_flow_error_set
14540 : : (error, -ret,
14541 : : RTE_FLOW_ERROR_TYPE_ITEM,
14542 : : NULL,
14543 : : "cannot create eCPRI parser");
14544 : : }
14545 : 0 : flow_dv_translate_item_ecpri
14546 : : (dev, key, items, wks, last_item, key_type);
14547 : : /* No other protocol should follow eCPRI layer. */
14548 : : last_item = MLX5_FLOW_LAYER_ECPRI;
14549 : 0 : break;
14550 : 0 : case RTE_FLOW_ITEM_TYPE_METER_COLOR:
14551 : 0 : flow_dv_translate_item_meter_color(dev, key, items, key_type);
14552 : : last_item = MLX5_FLOW_ITEM_METER_COLOR;
14553 : 0 : break;
14554 [ # # ]: 0 : case RTE_FLOW_ITEM_TYPE_INTEGRITY:
14555 : : last_item = flow_dv_translate_item_integrity(items,
14556 : : wks, key_type);
14557 : 0 : break;
14558 : 0 : case RTE_FLOW_ITEM_TYPE_AGGR_AFFINITY:
14559 : 0 : flow_dv_translate_item_aggr_affinity(key, items, key_type);
14560 : : last_item = MLX5_FLOW_ITEM_AGGR_AFFINITY;
14561 : 0 : break;
14562 : 0 : case RTE_FLOW_ITEM_TYPE_IB_BTH:
14563 : 0 : flow_dv_translate_item_ib_bth(key, items, tunnel, key_type);
14564 : : last_item = MLX5_FLOW_ITEM_IB_BTH;
14565 : 0 : break;
14566 : 0 : case RTE_FLOW_ITEM_TYPE_NSH:
14567 : : last_item = MLX5_FLOW_ITEM_NSH;
14568 : 0 : break;
14569 : : default:
14570 : : break;
14571 : : }
14572 : 0 : wks->item_flags |= last_item;
14573 : 0 : wks->last_item = last_item;
14574 : 0 : wks->next_protocol = next_protocol;
14575 : 0 : return 0;
14576 : : }
14577 : :
14578 : : static int
14579 : 0 : flow_dv_translate_items_geneve_opt_nta(struct rte_eth_dev *dev,
14580 : : const struct rte_flow_item *items,
14581 : : struct mlx5_flow_attr *attr,
14582 : : struct rte_flow_error *error)
14583 : : {
14584 : 0 : rte_be32_t geneve_mask = 0xffffffff;
14585 : 0 : struct rte_pmd_mlx5_geneve_tlv geneve_tlv = {
14586 : : /* Take from item spec, if changed, destroy and add new parser. */
14587 : : .option_class = 0,
14588 : : /* Take from item spec, if changed, destroy and add new parser. */
14589 : : .option_type = 0,
14590 : : /* 1DW is supported. */
14591 : : .option_len = 1,
14592 : : .match_on_class_mode = 1,
14593 : : .offset = 0,
14594 : : .sample_len = 1,
14595 : : .match_data_mask = &geneve_mask
14596 : : };
14597 : 0 : const struct rte_flow_item_geneve_opt *geneve_opt_v = items->spec;
14598 : 0 : const struct rte_flow_item_geneve_opt *geneve_opt_m = items->mask;
14599 : : void *geneve_parser;
14600 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14601 : : #ifdef RTE_PMD_MLX5_DEBUG
14602 : : struct mlx5_geneve_tlv_option *option;
14603 : : #endif
14604 : :
14605 : : /* option length is not as supported. */
14606 [ # # ]: 0 : if ((geneve_opt_v->option_len & geneve_opt_m->option_len) > geneve_tlv.option_len)
14607 : 0 : return rte_flow_error_set(error, ENOTSUP,
14608 : : RTE_FLOW_ERROR_TYPE_ITEM, items,
14609 : : " GENEVE OPT length is not supported ");
14610 : 0 : geneve_tlv.option_class = geneve_opt_v->option_class & geneve_opt_m->option_class;
14611 : 0 : geneve_tlv.option_type = geneve_opt_v->option_type & geneve_opt_m->option_type;
14612 : : /* if parser doesn't exist */
14613 [ # # ]: 0 : if (!priv->tlv_options) {
14614 : : /* Create a GENEVE option parser. */
14615 : 0 : geneve_parser = mlx5_geneve_tlv_parser_create(attr->port_id,
14616 : : &geneve_tlv, 1);
14617 [ # # ]: 0 : if (!geneve_parser)
14618 : 0 : return rte_flow_error_set(error, EINVAL,
14619 : : RTE_FLOW_ERROR_TYPE_ITEM, items,
14620 : : " GENEVE OPT parser creation failed ");
14621 : : #ifdef RTE_PMD_MLX5_DEBUG
14622 : : } else {
14623 : : /* Check if option exist in current parser. */
14624 : : option = mlx5_geneve_tlv_option_get(priv,
14625 : : geneve_tlv.option_type,
14626 : : geneve_tlv.option_class);
14627 : : if (!option)
14628 : : return rte_flow_error_set(error, EINVAL,
14629 : : RTE_FLOW_ERROR_TYPE_ITEM, items,
14630 : : " GENEVE OPT configured does not match this rule class/type");
14631 : : #endif
14632 : : }
14633 : : return 0;
14634 : : }
14635 : :
14636 : : /**
14637 : : * Fill the flow matcher with DV spec for items supported in non template mode.
14638 : : *
14639 : : * @param[in] dev
14640 : : * Pointer to rte_eth_dev structure.
14641 : : * @param[in] items
14642 : : * Pointer to the list of items.
14643 : : * @param[in] wks
14644 : : * Pointer to the matcher workspace.
14645 : : * @param[in] key
14646 : : * Pointer to the flow matcher key.
14647 : : * @param[in] key_type
14648 : : * Key type.
14649 : : * @param[out] error
14650 : : * Pointer to the error structure.
14651 : : *
14652 : : * @return
14653 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14654 : : */
14655 : : static int
14656 : 0 : flow_dv_translate_items_nta(struct rte_eth_dev *dev,
14657 : : const struct rte_flow_item *items,
14658 : : struct mlx5_dv_matcher_workspace *wks,
14659 : : void *key, uint32_t key_type,
14660 : : struct mlx5_flow_attr *attr,
14661 : : struct rte_flow_error *error)
14662 : : {
14663 : : int item_type;
14664 : : int ret = 0;
14665 : : int tunnel;
14666 : : /* Dummy structure to enable the key calculation for flex item. */
14667 : : struct mlx5_flow_dv_match_params flex_item_key;
14668 : :
14669 : 0 : tunnel = !!(wks->item_flags & MLX5_FLOW_LAYER_TUNNEL);
14670 : 0 : item_type = items->type;
14671 [ # # # # ]: 0 : switch (item_type) {
14672 : 0 : case RTE_FLOW_ITEM_TYPE_CONNTRACK:
14673 : 0 : flow_dv_translate_item_aso_ct(dev, key, NULL, items);
14674 : 0 : wks->last_item = MLX5_FLOW_LAYER_ASO_CT;
14675 : 0 : break;
14676 : : /* TODO: remove once flex item translation is added to flow_dv_translate_items. */
14677 : 0 : case RTE_FLOW_ITEM_TYPE_FLEX:
14678 : 0 : mlx5_flex_flow_translate_item(dev, key, flex_item_key.buf, items, tunnel != 0);
14679 [ # # ]: 0 : wks->last_item = tunnel ? MLX5_FLOW_ITEM_INNER_FLEX : MLX5_FLOW_ITEM_OUTER_FLEX;
14680 : 0 : break;
14681 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
14682 : 0 : ret = flow_dv_translate_items_geneve_opt_nta(dev, items, attr, error);
14683 [ # # ]: 0 : if (ret)
14684 : : return ret;
14685 : 0 : wks->last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
14686 : 0 : break;
14687 : 0 : default:
14688 : 0 : ret = flow_dv_translate_items(dev, items, wks, key, key_type, error);
14689 [ # # ]: 0 : if (ret)
14690 : : return ret;
14691 : : break;
14692 : : }
14693 : 0 : wks->item_flags |= wks->last_item;
14694 : 0 : return 0;
14695 : : }
14696 : :
14697 : : /**
14698 : : * Fill the HW steering flow with DV spec.
14699 : : *
14700 : : * @param[in] items
14701 : : * Pointer to the list of items.
14702 : : * @param[in] attr
14703 : : * Pointer to the flow attributes.
14704 : : * @param[in] key
14705 : : * Pointer to the flow matcher key.
14706 : : * @param[in] key_type
14707 : : * Key type.
14708 : : * @param[in, out] item_flags
14709 : : * Pointer to the flow item flags.
14710 : : * @param[in, out] nt_flow
14711 : : * Non template flow.
14712 : : * @param[out] error
14713 : : * Pointer to the error structure.
14714 : : *
14715 : : * @return
14716 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14717 : : */
14718 : : int
14719 : 0 : mlx5_flow_dv_translate_items_hws_impl(const struct rte_flow_item *items,
14720 : : struct mlx5_flow_attr *attr, void *key,
14721 : : uint32_t key_type, uint64_t *item_flags,
14722 : : uint8_t *match_criteria,
14723 : : bool nt_flow,
14724 : : struct rte_flow_error *error)
14725 : : {
14726 : 0 : struct mlx5_flow_workspace *flow_wks = mlx5_flow_push_thread_workspace();
14727 : 0 : struct mlx5_flow_rss_desc rss_desc = { .level = attr->rss_level };
14728 : 0 : struct rte_flow_attr rattr = {
14729 : 0 : .group = attr->group,
14730 : 0 : .priority = attr->priority,
14731 : 0 : .ingress = !!(attr->tbl_type == MLX5DR_TABLE_TYPE_NIC_RX),
14732 : 0 : .egress = !!(attr->tbl_type == MLX5DR_TABLE_TYPE_NIC_TX),
14733 : 0 : .transfer = !!(attr->tbl_type == MLX5DR_TABLE_TYPE_FDB),
14734 : : };
14735 : 0 : struct mlx5_dv_matcher_workspace wks = {
14736 : 0 : .action_flags = attr->act_flags,
14737 [ # # ]: 0 : .item_flags = item_flags ? *item_flags : 0,
14738 : : .external = 0,
14739 : : .next_protocol = 0xff,
14740 : : .attr = &rattr,
14741 : : .rss_desc = &rss_desc,
14742 : : .group = attr->group,
14743 : 0 : .p_root_flags = &attr->hws_root_match_flags,
14744 : : };
14745 : : int ret = 0;
14746 : :
14747 : : RTE_SET_USED(flow_wks);
14748 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
14749 : : if (!mlx5_flow_os_item_supported(items->type)) {
14750 : : ret = rte_flow_error_set(error, ENOTSUP,
14751 : : RTE_FLOW_ERROR_TYPE_ITEM,
14752 : : NULL, "item not supported");
14753 : : goto exit;
14754 : : }
14755 : : /* Non template flow. */
14756 [ # # ]: 0 : if (nt_flow) {
14757 : 0 : ret = flow_dv_translate_items_nta(&rte_eth_devices[attr->port_id],
14758 : : items, &wks, key, key_type, attr, error);
14759 [ # # ]: 0 : if (ret)
14760 : 0 : goto exit;
14761 : : } else {
14762 : 0 : ret = flow_dv_translate_items(&rte_eth_devices[attr->port_id],
14763 : : items, &wks, key, key_type, error);
14764 [ # # ]: 0 : if (ret)
14765 : 0 : goto exit;
14766 : : }
14767 : : }
14768 [ # # ]: 0 : if (wks.item_flags & MLX5_FLOW_ITEM_INTEGRITY) {
14769 : 0 : flow_dv_translate_item_integrity_post(key,
14770 : : wks.integrity_items,
14771 : : wks.item_flags,
14772 : : key_type);
14773 : : }
14774 [ # # ]: 0 : if (wks.item_flags & MLX5_FLOW_LAYER_VXLAN_GPE) {
14775 [ # # ]: 0 : if (wks.tunnel_item)
14776 : 0 : flow_dv_translate_item_vxlan_gpe(key,
14777 : : wks.tunnel_item,
14778 : : wks.item_flags,
14779 : : key_type);
14780 [ # # ]: 0 : } else if (wks.item_flags & MLX5_FLOW_LAYER_GENEVE) {
14781 [ # # ]: 0 : if (wks.tunnel_item)
14782 : 0 : flow_dv_translate_item_geneve(key,
14783 : : wks.tunnel_item,
14784 : : wks.item_flags,
14785 : : key_type);
14786 [ # # ]: 0 : } else if (wks.item_flags & MLX5_FLOW_LAYER_GRE) {
14787 [ # # # # ]: 0 : if (wks.tunnel_item && wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE) {
14788 : 0 : flow_dv_translate_item_gre(key,
14789 : : wks.tunnel_item,
14790 : : wks.item_flags,
14791 : : key_type);
14792 [ # # ]: 0 : } else if (wks.tunnel_item &&
14793 [ # # ]: 0 : wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE_OPTION) {
14794 : 0 : flow_dv_translate_item_gre_option(key,
14795 : : wks.tunnel_item,
14796 : : wks.gre_item,
14797 : : wks.item_flags,
14798 : : key_type);
14799 [ # # # # ]: 0 : } else if (wks.tunnel_item && wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_NVGRE) {
14800 : 0 : flow_dv_translate_item_nvgre(key,
14801 : : wks.tunnel_item,
14802 : : wks.item_flags,
14803 : : key_type);
14804 : : } else {
14805 : : MLX5_ASSERT(false);
14806 : : }
14807 : : }
14808 : :
14809 [ # # ]: 0 : if (match_criteria)
14810 : 0 : *match_criteria = flow_dv_matcher_enable(key);
14811 [ # # ]: 0 : if (item_flags)
14812 : 0 : *item_flags = wks.item_flags;
14813 : 0 : exit:
14814 : 0 : mlx5_flow_pop_thread_workspace();
14815 : 0 : return ret;
14816 : : }
14817 : :
14818 : : /**
14819 : : * Fill the HW steering flow with DV spec.
14820 : : * This function assumes given flow is created from template API.
14821 : : *
14822 : : * @param[in] items
14823 : : * Pointer to the list of items.
14824 : : * @param[in] attr
14825 : : * Pointer to the flow attributes.
14826 : : * @param[in] key
14827 : : * Pointer to the flow matcher key.
14828 : : * @param[in] key_type
14829 : : * Key type.
14830 : : * @param[in, out] item_flags
14831 : : * Pointer to the flow item flags.
14832 : : * @param[out] error
14833 : : * Pointer to the error structure.
14834 : : *
14835 : : * @return
14836 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14837 : : */
14838 : : int
14839 : 0 : mlx5_flow_dv_translate_items_hws(const struct rte_flow_item *items,
14840 : : struct mlx5_flow_attr *attr, void *key,
14841 : : uint32_t key_type, uint64_t *item_flags,
14842 : : uint8_t *match_criteria,
14843 : : struct rte_flow_error *error)
14844 : : {
14845 : 0 : return mlx5_flow_dv_translate_items_hws_impl(items, attr, key, key_type, item_flags,
14846 : : match_criteria, false, error);
14847 : : }
14848 : :
14849 : : /**
14850 : : * Fill the SW steering flow with DV spec.
14851 : : *
14852 : : * @param[in] dev
14853 : : * Pointer to rte_eth_dev structure.
14854 : : * @param[in, out] dev_flow
14855 : : * Pointer to the sub flow.
14856 : : * @param[in] attr
14857 : : * Pointer to the flow attributes.
14858 : : * @param[in] items
14859 : : * Pointer to the list of items.
14860 : : * @param[in, out] matcher
14861 : : * Pointer to the flow matcher.
14862 : : * @param[out] error
14863 : : * Pointer to the error structure.
14864 : : *
14865 : : * @return
14866 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14867 : : */
14868 : : static int
14869 : 0 : flow_dv_translate_items_sws(struct rte_eth_dev *dev,
14870 : : struct mlx5_flow *dev_flow,
14871 : : const struct rte_flow_attr *attr,
14872 : : const struct rte_flow_item *items,
14873 : : struct mlx5_flow_dv_matcher *matcher,
14874 : : struct rte_flow_error *error)
14875 : : {
14876 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14877 : 0 : void *match_mask = matcher->mask.buf;
14878 : 0 : void *match_value = dev_flow->dv.value.buf;
14879 : 0 : struct mlx5_dv_matcher_workspace wks = {
14880 : 0 : .action_flags = dev_flow->act_flags,
14881 : : .item_flags = 0,
14882 : 0 : .external = dev_flow->external,
14883 : : .next_protocol = 0xff,
14884 : 0 : .group = dev_flow->dv.group,
14885 : : .attr = attr,
14886 : 0 : .rss_desc = &((struct mlx5_flow_workspace *)
14887 : : mlx5_flow_get_thread_workspace())->rss_desc,
14888 : : };
14889 : 0 : struct mlx5_dv_matcher_workspace wks_m = wks;
14890 : : int item_type;
14891 : : int ret = 0;
14892 : : int tunnel;
14893 : :
14894 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
14895 : 0 : if (!mlx5_flow_os_item_supported(items->type))
14896 : : return rte_flow_error_set(error, ENOTSUP,
14897 : : RTE_FLOW_ERROR_TYPE_ITEM,
14898 : : NULL, "item not supported");
14899 : 0 : tunnel = !!(wks.item_flags & MLX5_FLOW_LAYER_TUNNEL);
14900 : : item_type = items->type;
14901 [ # # # # : 0 : switch (item_type) {
# ]
14902 : 0 : case RTE_FLOW_ITEM_TYPE_CONNTRACK:
14903 : 0 : flow_dv_translate_item_aso_ct(dev, match_mask,
14904 : : match_value, items);
14905 : 0 : wks.last_item = MLX5_FLOW_LAYER_ASO_CT;
14906 : 0 : break;
14907 : 0 : case RTE_FLOW_ITEM_TYPE_FLEX:
14908 : 0 : flow_dv_translate_item_flex(dev, match_mask,
14909 : : match_value, items,
14910 : : dev_flow, tunnel != 0);
14911 [ # # ]: 0 : wks.last_item = tunnel ? MLX5_FLOW_ITEM_INNER_FLEX :
14912 : : MLX5_FLOW_ITEM_OUTER_FLEX;
14913 : 0 : break;
14914 : 0 : case RTE_FLOW_ITEM_TYPE_TX_QUEUE:
14915 : 0 : ret = flow_dv_translate_item_tx_queue(dev, match_value, items,
14916 : : MLX5_SET_MATCHER_SW_V);
14917 [ # # ]: 0 : if (ret)
14918 : 0 : return rte_flow_error_set(error, -ret,
14919 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14920 : : "invalid tx_queue item spec");
14921 : 0 : ret = flow_dv_translate_item_tx_queue(dev, match_mask, items,
14922 : : MLX5_SET_MATCHER_SW_M);
14923 [ # # ]: 0 : if (ret)
14924 : 0 : return rte_flow_error_set(error, -ret,
14925 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14926 : : "invalid tx_queue item mask");
14927 : : break;
14928 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_SQ:
14929 : 0 : flow_dv_translate_item_sq(match_value, items,
14930 : : MLX5_SET_MATCHER_SW_V);
14931 : 0 : flow_dv_translate_item_sq(match_mask, items,
14932 : : MLX5_SET_MATCHER_SW_M);
14933 : 0 : break;
14934 : 0 : default:
14935 : 0 : ret = flow_dv_translate_items(dev, items, &wks_m,
14936 : : match_mask, MLX5_SET_MATCHER_SW_M, error);
14937 [ # # ]: 0 : if (ret)
14938 : 0 : return ret;
14939 : 0 : ret = flow_dv_translate_items(dev, items, &wks,
14940 : : match_value, MLX5_SET_MATCHER_SW_V, error);
14941 [ # # ]: 0 : if (ret)
14942 : 0 : return ret;
14943 : : break;
14944 : : }
14945 : 0 : wks.item_flags |= wks.last_item;
14946 : : }
14947 : : /*
14948 : : * When E-Switch mode is enabled, we have two cases where we need to
14949 : : * set the source port manually.
14950 : : * The first one, is in case of NIC ingress steering rule, and the
14951 : : * second is E-Switch rule where no port_id item was found.
14952 : : * In both cases the source port is set according the current port
14953 : : * in use.
14954 : : */
14955 : 0 : if (!(wks.item_flags & MLX5_FLOW_ITEM_PORT_ID) &&
14956 [ # # ]: 0 : !(wks.item_flags & MLX5_FLOW_ITEM_REPRESENTED_PORT) &&
14957 : 0 : !(wks.item_flags & MLX5_FLOW_ITEM_PORT_REPRESENTOR) &&
14958 [ # # ]: 0 : priv->sh->esw_mode &&
14959 [ # # ]: 0 : !attr->egress &&
14960 [ # # ]: 0 : attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP) {
14961 [ # # ]: 0 : if (flow_dv_translate_item_port_id_all(dev, match_mask,
14962 : : match_value, NULL, attr))
14963 : 0 : return -rte_errno;
14964 : : }
14965 [ # # ]: 0 : if (wks.item_flags & MLX5_FLOW_ITEM_INTEGRITY) {
14966 : 0 : flow_dv_translate_item_integrity_post(match_mask,
14967 : : wks_m.integrity_items,
14968 : : wks_m.item_flags,
14969 : : MLX5_SET_MATCHER_SW_M);
14970 : 0 : flow_dv_translate_item_integrity_post(match_value,
14971 : : wks.integrity_items,
14972 : : wks.item_flags,
14973 : : MLX5_SET_MATCHER_SW_V);
14974 : : }
14975 [ # # ]: 0 : if (wks.item_flags & MLX5_FLOW_LAYER_VXLAN_GPE) {
14976 : 0 : flow_dv_translate_item_vxlan_gpe(match_mask,
14977 : : wks.tunnel_item,
14978 : : wks.item_flags,
14979 : : MLX5_SET_MATCHER_SW_M);
14980 : 0 : flow_dv_translate_item_vxlan_gpe(match_value,
14981 : : wks.tunnel_item,
14982 : : wks.item_flags,
14983 : : MLX5_SET_MATCHER_SW_V);
14984 [ # # ]: 0 : } else if (wks.item_flags & MLX5_FLOW_LAYER_GENEVE) {
14985 : 0 : flow_dv_translate_item_geneve(match_mask,
14986 : : wks.tunnel_item,
14987 : : wks.item_flags,
14988 : : MLX5_SET_MATCHER_SW_M);
14989 : 0 : flow_dv_translate_item_geneve(match_value,
14990 : : wks.tunnel_item,
14991 : : wks.item_flags,
14992 : : MLX5_SET_MATCHER_SW_V);
14993 [ # # ]: 0 : } else if (wks.item_flags & MLX5_FLOW_LAYER_GRE) {
14994 [ # # ]: 0 : if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE) {
14995 : 0 : flow_dv_translate_item_gre(match_mask,
14996 : : wks.tunnel_item,
14997 : : wks.item_flags,
14998 : : MLX5_SET_MATCHER_SW_M);
14999 : 0 : flow_dv_translate_item_gre(match_value,
15000 : : wks.tunnel_item,
15001 : : wks.item_flags,
15002 : : MLX5_SET_MATCHER_SW_V);
15003 [ # # ]: 0 : } else if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_NVGRE) {
15004 : 0 : flow_dv_translate_item_nvgre(match_mask,
15005 : : wks.tunnel_item,
15006 : : wks.item_flags,
15007 : : MLX5_SET_MATCHER_SW_M);
15008 : 0 : flow_dv_translate_item_nvgre(match_value,
15009 : : wks.tunnel_item,
15010 : : wks.item_flags,
15011 : : MLX5_SET_MATCHER_SW_V);
15012 [ # # ]: 0 : } else if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE_OPTION) {
15013 : 0 : flow_dv_translate_item_gre_option(match_mask,
15014 : : wks.tunnel_item,
15015 : : wks.gre_item,
15016 : : wks.item_flags,
15017 : : MLX5_SET_MATCHER_SW_M);
15018 : 0 : flow_dv_translate_item_gre_option(match_value,
15019 : : wks.tunnel_item,
15020 : : wks.gre_item,
15021 : : wks.item_flags,
15022 : : MLX5_SET_MATCHER_SW_V);
15023 : : } else {
15024 : : MLX5_ASSERT(false);
15025 : : }
15026 : : }
15027 : 0 : dev_flow->handle->vf_vlan.tag = wks.vlan_tag;
15028 : 0 : matcher->priority = wks.priority;
15029 : : #ifdef RTE_PMD_MLX5_DEBUG
15030 : : MLX5_ASSERT(!flow_dv_check_valid_spec(match_mask, match_value));
15031 : : #endif
15032 : : /*
15033 : : * Layers may be already initialized from prefix flow if this dev_flow
15034 : : * is the suffix flow.
15035 : : */
15036 : 0 : dev_flow->handle->layers |= wks.item_flags;
15037 : : /*
15038 : : * Update geneve_tlv_option flag only it is set in workspace.
15039 : : * Avoid be overwritten by other sub mlx5_flows.
15040 : : */
15041 [ # # ]: 0 : if (wks.geneve_tlv_option)
15042 : 0 : dev_flow->flow->geneve_tlv_option += wks.geneve_tlv_option;
15043 : : return 0;
15044 : : }
15045 : :
15046 : : /**
15047 : : * Fill the flow with DV spec, lock free
15048 : : * (mutex should be acquired by caller).
15049 : : *
15050 : : * @param[in] dev
15051 : : * Pointer to rte_eth_dev structure.
15052 : : * @param[in, out] dev_flow
15053 : : * Pointer to the sub flow.
15054 : : * @param[in] attr
15055 : : * Pointer to the flow attributes.
15056 : : * @param[in] items
15057 : : * Pointer to the list of items.
15058 : : * @param[in] actions
15059 : : * Pointer to the list of actions.
15060 : : * @param[out] error
15061 : : * Pointer to the error structure.
15062 : : *
15063 : : * @return
15064 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
15065 : : */
15066 : : static int
15067 : 0 : flow_dv_translate(struct rte_eth_dev *dev,
15068 : : struct mlx5_flow *dev_flow,
15069 : : const struct rte_flow_attr *attr,
15070 : : const struct rte_flow_item items[],
15071 : : const struct rte_flow_action actions[],
15072 : : struct rte_flow_error *error)
15073 : : {
15074 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15075 : 0 : struct mlx5_sh_config *dev_conf = &priv->sh->config;
15076 : 0 : struct rte_flow *flow = dev_flow->flow;
15077 : 0 : struct mlx5_flow_handle *handle = dev_flow->handle;
15078 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
15079 : : struct mlx5_flow_rss_desc *rss_desc;
15080 : : uint64_t action_flags = 0;
15081 : 0 : struct mlx5_flow_dv_matcher matcher = {
15082 : : .mask = {
15083 : : .size = sizeof(matcher.mask.buf),
15084 : : },
15085 : : };
15086 : : int actions_n = 0;
15087 : : bool actions_end = false;
15088 : : union {
15089 : : struct mlx5_flow_dv_modify_hdr_resource res;
15090 : : uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
15091 : : sizeof(struct mlx5_modification_cmd) *
15092 : : (MLX5_MAX_MODIFY_NUM + 1)];
15093 : : } mhdr_dummy;
15094 : : struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
15095 : : const struct rte_flow_action_count *count = NULL;
15096 : : const struct rte_flow_action_age *non_shared_age = NULL;
15097 : 0 : union flow_dv_attr flow_attr = { .attr = 0 };
15098 : : uint32_t tag_be;
15099 : : union mlx5_flow_tbl_key tbl_key;
15100 : : uint32_t modify_action_position = UINT32_MAX;
15101 : 0 : struct rte_vlan_hdr vlan = { 0 };
15102 : : struct mlx5_flow_dv_dest_array_resource mdest_res;
15103 : : struct mlx5_flow_dv_sample_resource sample_res;
15104 : 0 : void *sample_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
15105 : : const struct rte_flow_action_sample *sample = NULL;
15106 : : struct mlx5_flow_sub_actions_list *sample_act;
15107 : : uint32_t sample_act_pos = UINT32_MAX;
15108 : : uint32_t age_act_pos = UINT32_MAX;
15109 : : uint32_t ipv6_tc_off = 0;
15110 : 0 : uint32_t num_of_dest = 0;
15111 : : int tmp_actions_n = 0;
15112 : : uint32_t table;
15113 : : int ret = 0;
15114 : : const struct mlx5_flow_tunnel *tunnel = NULL;
15115 : 0 : struct flow_grp_info grp_info = {
15116 : 0 : .external = !!dev_flow->external,
15117 : 0 : .transfer = !!attr->transfer,
15118 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
15119 : 0 : .skip_scale = dev_flow->skip_scale &
15120 : : (1 << MLX5_SCALE_FLOW_GROUP_BIT),
15121 : : .std_tbl_fix = true,
15122 : : };
15123 : :
15124 [ # # ]: 0 : if (!wks)
15125 : 0 : return rte_flow_error_set(error, ENOMEM,
15126 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15127 : : NULL,
15128 : : "failed to push flow workspace");
15129 [ # # ]: 0 : rss_desc = &wks->rss_desc;
15130 : : memset(&mdest_res, 0, sizeof(struct mlx5_flow_dv_dest_array_resource));
15131 : : memset(&sample_res, 0, sizeof(struct mlx5_flow_dv_sample_resource));
15132 [ # # ]: 0 : mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
15133 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
15134 : : /* update normal path action resource into last index of array */
15135 : : sample_act = &mdest_res.sample_act[MLX5_MAX_DEST_NUM - 1];
15136 [ # # ]: 0 : if (is_tunnel_offload_active(dev)) {
15137 [ # # ]: 0 : if (dev_flow->tunnel) {
15138 [ # # ]: 0 : RTE_VERIFY(dev_flow->tof_type ==
15139 : : MLX5_TUNNEL_OFFLOAD_MISS_RULE);
15140 : : tunnel = dev_flow->tunnel;
15141 : : } else {
15142 : 0 : tunnel = mlx5_get_tof(items, actions,
15143 : : &dev_flow->tof_type);
15144 : 0 : dev_flow->tunnel = tunnel;
15145 : : }
15146 [ # # ]: 0 : grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
15147 : : (dev, attr, tunnel, dev_flow->tof_type);
15148 : : }
15149 : 0 : mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
15150 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
15151 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel, attr->group, &table,
15152 : : &grp_info, error);
15153 [ # # ]: 0 : if (ret)
15154 : : return ret;
15155 : 0 : dev_flow->dv.group = table;
15156 [ # # ]: 0 : if (attr->transfer)
15157 : 0 : mhdr_res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
15158 : : /* number of actions must be set to 0 in case of dirty stack. */
15159 : 0 : mhdr_res->actions_num = 0;
15160 [ # # ]: 0 : if (is_flow_tunnel_match_rule(dev_flow->tof_type)) {
15161 : : /*
15162 : : * do not add decap action if match rule drops packet
15163 : : * HW rejects rules with decap & drop
15164 : : *
15165 : : * if tunnel match rule was inserted before matching tunnel set
15166 : : * rule flow table used in the match rule must be registered.
15167 : : * current implementation handles that in the
15168 : : * flow_dv_match_register() at the function end.
15169 : : */
15170 : : bool add_decap = true;
15171 : : const struct rte_flow_action *ptr = actions;
15172 : :
15173 [ # # ]: 0 : for (; ptr->type != RTE_FLOW_ACTION_TYPE_END; ptr++) {
15174 [ # # ]: 0 : if (ptr->type == RTE_FLOW_ACTION_TYPE_DROP) {
15175 : : add_decap = false;
15176 : : break;
15177 : : }
15178 : : }
15179 [ # # ]: 0 : if (add_decap) {
15180 [ # # ]: 0 : if (flow_dv_create_action_l2_decap(dev, dev_flow,
15181 : 0 : attr->transfer,
15182 : : error))
15183 : 0 : return -rte_errno;
15184 : 0 : dev_flow->dv.actions[actions_n++] =
15185 : 0 : dev_flow->dv.encap_decap->action;
15186 : : action_flags |= MLX5_FLOW_ACTION_DECAP;
15187 : : }
15188 : : }
15189 [ # # ]: 0 : for (; !actions_end ; actions++) {
15190 : : const struct rte_flow_action_queue *queue;
15191 : : const struct rte_flow_action_rss *rss;
15192 : : const struct rte_flow_action *action = actions;
15193 : : const uint8_t *rss_key;
15194 : : struct mlx5_flow_tbl_resource *tbl;
15195 : : struct mlx5_aso_age_action *age_act;
15196 : : struct mlx5_flow_counter *cnt_act;
15197 : 0 : uint32_t port_id = 0;
15198 : : struct mlx5_flow_dv_port_id_action_resource port_id_resource;
15199 : 0 : int action_type = actions->type;
15200 : : const struct rte_flow_action *found_action = NULL;
15201 : : uint32_t jump_group = 0;
15202 : : uint32_t owner_idx;
15203 : : struct mlx5_aso_ct_action *ct;
15204 : :
15205 : : if (!mlx5_flow_os_action_supported(action_type))
15206 : 0 : return rte_flow_error_set(error, ENOTSUP,
15207 : : RTE_FLOW_ERROR_TYPE_ACTION,
15208 : : actions,
15209 : : "action not supported");
15210 [ # # # # : 0 : switch (action_type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
15211 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
15212 : 0 : action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
15213 : 0 : break;
15214 : : case RTE_FLOW_ACTION_TYPE_VOID:
15215 : : break;
15216 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
15217 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
15218 [ # # ]: 0 : if (flow_dv_translate_action_port_id(dev, action,
15219 : : &port_id, error))
15220 : 0 : return -rte_errno;
15221 : 0 : port_id_resource.port_id = port_id;
15222 : : MLX5_ASSERT(!handle->rix_port_id_action);
15223 [ # # ]: 0 : if (flow_dv_port_id_action_resource_register
15224 : : (dev, &port_id_resource, dev_flow, error))
15225 : 0 : return -rte_errno;
15226 : 0 : dev_flow->dv.actions[actions_n++] =
15227 : 0 : dev_flow->dv.port_id_action->action;
15228 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_ID;
15229 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_PORT_ID;
15230 : 0 : sample_act->action_flags |= MLX5_FLOW_ACTION_PORT_ID;
15231 : 0 : num_of_dest++;
15232 : 0 : break;
15233 : 0 : case RTE_FLOW_ACTION_TYPE_FLAG:
15234 : 0 : action_flags |= MLX5_FLOW_ACTION_FLAG;
15235 : 0 : wks->mark = 1;
15236 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
15237 : 0 : struct rte_flow_action_mark mark = {
15238 : : .id = MLX5_FLOW_MARK_DEFAULT,
15239 : : };
15240 : :
15241 [ # # ]: 0 : if (flow_dv_convert_action_mark(dev, &mark,
15242 : : mhdr_res,
15243 : : error))
15244 : 0 : return -rte_errno;
15245 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
15246 : 0 : break;
15247 : : }
15248 : : tag_be = mlx5_flow_mark_set(MLX5_FLOW_MARK_DEFAULT);
15249 : : /*
15250 : : * Only one FLAG or MARK is supported per device flow
15251 : : * right now. So the pointer to the tag resource must be
15252 : : * zero before the register process.
15253 : : */
15254 : : MLX5_ASSERT(!handle->dvh.rix_tag);
15255 [ # # ]: 0 : if (flow_dv_tag_resource_register(dev, tag_be,
15256 : : dev_flow, error))
15257 : 0 : return -rte_errno;
15258 : : MLX5_ASSERT(dev_flow->dv.tag_resource);
15259 : 0 : dev_flow->dv.actions[actions_n++] =
15260 : 0 : dev_flow->dv.tag_resource->action;
15261 : 0 : break;
15262 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
15263 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK;
15264 : 0 : wks->mark = 1;
15265 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
15266 : 0 : const struct rte_flow_action_mark *mark =
15267 : : (const struct rte_flow_action_mark *)
15268 : : actions->conf;
15269 : :
15270 [ # # ]: 0 : if (flow_dv_convert_action_mark(dev, mark,
15271 : : mhdr_res,
15272 : : error))
15273 : 0 : return -rte_errno;
15274 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
15275 : 0 : break;
15276 : : }
15277 : : /* Fall-through */
15278 : : case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
15279 : : /* Legacy (non-extensive) MARK action. */
15280 : : tag_be = mlx5_flow_mark_set
15281 : : (((const struct rte_flow_action_mark *)
15282 [ # # ]: 0 : (actions->conf))->id);
15283 : : MLX5_ASSERT(!handle->dvh.rix_tag);
15284 [ # # ]: 0 : if (flow_dv_tag_resource_register(dev, tag_be,
15285 : : dev_flow, error))
15286 : 0 : return -rte_errno;
15287 : : MLX5_ASSERT(dev_flow->dv.tag_resource);
15288 : 0 : dev_flow->dv.actions[actions_n++] =
15289 : 0 : dev_flow->dv.tag_resource->action;
15290 : 0 : break;
15291 : 0 : case RTE_FLOW_ACTION_TYPE_SET_META:
15292 [ # # ]: 0 : if (flow_dv_convert_action_set_meta
15293 : : (dev, mhdr_res, attr,
15294 : : (const struct rte_flow_action_set_meta *)
15295 : 0 : actions->conf, error))
15296 : 0 : return -rte_errno;
15297 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_META;
15298 : 0 : break;
15299 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TAG:
15300 [ # # ]: 0 : if (flow_dv_convert_action_set_tag
15301 : : (dev, mhdr_res,
15302 : : (const struct rte_flow_action_set_tag *)
15303 : 0 : actions->conf, error))
15304 : 0 : return -rte_errno;
15305 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
15306 : 0 : break;
15307 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
15308 : 0 : action_flags |= MLX5_FLOW_ACTION_DROP;
15309 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_DROP;
15310 : 0 : break;
15311 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
15312 : 0 : queue = actions->conf;
15313 : 0 : rss_desc->queue_num = 1;
15314 : 0 : rss_desc->queue[0] = queue->index;
15315 : 0 : action_flags |= MLX5_FLOW_ACTION_QUEUE;
15316 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
15317 : 0 : sample_act->action_flags |= MLX5_FLOW_ACTION_QUEUE;
15318 : 0 : num_of_dest++;
15319 : 0 : break;
15320 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
15321 : 0 : rss = actions->conf;
15322 : 0 : rss_desc->symmetric_hash_function =
15323 : 0 : MLX5_RSS_IS_SYMM(rss->func);
15324 : 0 : memcpy(rss_desc->queue, rss->queue,
15325 [ # # ]: 0 : rss->queue_num * sizeof(uint16_t));
15326 : 0 : rss_desc->queue_num = rss->queue_num;
15327 : : /* NULL RSS key indicates default RSS key. */
15328 [ # # ]: 0 : rss_key = !rss->key ? mlx5_rss_hash_default_key : rss->key;
15329 [ # # ]: 0 : memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
15330 : : /*
15331 : : * rss->level and rss.types should be set in advance
15332 : : * when expanding items for RSS.
15333 : : */
15334 : 0 : action_flags |= MLX5_FLOW_ACTION_RSS;
15335 : 0 : dev_flow->handle->fate_action = rss_desc->shared_rss ?
15336 [ # # ]: 0 : MLX5_FLOW_FATE_SHARED_RSS :
15337 : : MLX5_FLOW_FATE_QUEUE;
15338 : 0 : break;
15339 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
15340 : 0 : owner_idx = (uint32_t)(uintptr_t)action->conf;
15341 : 0 : age_act = mlx5_flow_aso_age_get_by_idx(dev, owner_idx);
15342 [ # # ]: 0 : if (flow->age == 0) {
15343 : 0 : flow->age = owner_idx;
15344 : 0 : rte_atomic_fetch_add_explicit(&age_act->refcnt, 1,
15345 : : rte_memory_order_relaxed);
15346 : : }
15347 : 0 : age_act_pos = actions_n++;
15348 : 0 : action_flags |= MLX5_FLOW_ACTION_AGE;
15349 : 0 : break;
15350 : 0 : case RTE_FLOW_ACTION_TYPE_SEND_TO_KERNEL:
15351 : 0 : dev_flow->dv.actions[actions_n] =
15352 : 0 : flow_dv_translate_action_send_to_kernel(dev, attr,
15353 : : error);
15354 [ # # ]: 0 : if (!dev_flow->dv.actions[actions_n])
15355 : 0 : return -rte_errno;
15356 : 0 : actions_n++;
15357 : 0 : action_flags |= MLX5_FLOW_ACTION_SEND_TO_KERNEL;
15358 : 0 : dev_flow->handle->fate_action =
15359 : : MLX5_FLOW_FATE_SEND_TO_KERNEL;
15360 : 0 : break;
15361 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
15362 : 0 : non_shared_age = action->conf;
15363 : 0 : age_act_pos = actions_n++;
15364 : 0 : action_flags |= MLX5_FLOW_ACTION_AGE;
15365 : 0 : break;
15366 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
15367 [ # # ]: 0 : owner_idx = (uint32_t)(uintptr_t)action->conf;
15368 : : cnt_act = flow_dv_counter_get_by_idx(dev, owner_idx,
15369 : : NULL);
15370 : : MLX5_ASSERT(cnt_act != NULL);
15371 : : /**
15372 : : * When creating meter drop flow in drop table, the
15373 : : * counter should not overwrite the rte flow counter.
15374 : : */
15375 [ # # ]: 0 : if (attr->group == MLX5_FLOW_TABLE_LEVEL_METER &&
15376 [ # # ]: 0 : dev_flow->dv.table_id == MLX5_MTR_TABLE_ID_DROP) {
15377 : 0 : dev_flow->dv.actions[actions_n++] =
15378 : 0 : cnt_act->action;
15379 : : } else {
15380 [ # # ]: 0 : if (flow->counter == 0) {
15381 : 0 : flow->counter = owner_idx;
15382 : 0 : rte_atomic_fetch_add_explicit
15383 : : (&cnt_act->shared_info.refcnt,
15384 : : 1, rte_memory_order_relaxed);
15385 : : }
15386 : : /* Save information first, will apply later. */
15387 : 0 : action_flags |= MLX5_FLOW_ACTION_COUNT;
15388 : : }
15389 : : break;
15390 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
15391 [ # # ]: 0 : if (!priv->sh->cdev->config.devx) {
15392 : 0 : return rte_flow_error_set
15393 : : (error, ENOTSUP,
15394 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15395 : : NULL,
15396 : : "count action not supported");
15397 : : }
15398 : : /* Save information first, will apply later. */
15399 : 0 : count = action->conf;
15400 : 0 : action_flags |= MLX5_FLOW_ACTION_COUNT;
15401 : 0 : break;
15402 : 0 : case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
15403 : 0 : dev_flow->dv.actions[actions_n++] =
15404 : 0 : priv->sh->pop_vlan_action;
15405 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
15406 : 0 : break;
15407 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
15408 [ # # ]: 0 : if (!(action_flags &
15409 : : MLX5_FLOW_ACTION_OF_SET_VLAN_VID))
15410 : 0 : flow_dev_get_vlan_info_from_items(items, &vlan);
15411 [ # # ]: 0 : vlan.eth_proto = rte_be_to_cpu_16
15412 : : ((((const struct rte_flow_action_of_push_vlan *)
15413 : : actions->conf)->ethertype));
15414 : 0 : found_action = mlx5_flow_find_action
15415 : : (actions + 1,
15416 : : RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID);
15417 [ # # ]: 0 : if (found_action)
15418 : 0 : mlx5_update_vlan_vid_pcp(found_action, &vlan);
15419 : 0 : found_action = mlx5_flow_find_action
15420 : : (actions + 1,
15421 : : RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP);
15422 [ # # ]: 0 : if (found_action)
15423 : 0 : mlx5_update_vlan_vid_pcp(found_action, &vlan);
15424 [ # # ]: 0 : if (flow_dv_create_action_push_vlan
15425 : : (dev, attr, &vlan, dev_flow, error))
15426 : 0 : return -rte_errno;
15427 : 0 : dev_flow->dv.actions[actions_n++] =
15428 : 0 : dev_flow->dv.push_vlan_res->action;
15429 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
15430 : 0 : break;
15431 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
15432 : : /* of_vlan_push action handled this action */
15433 : : MLX5_ASSERT(action_flags &
15434 : : MLX5_FLOW_ACTION_OF_PUSH_VLAN);
15435 : : break;
15436 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
15437 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
15438 : : break;
15439 : 0 : flow_dev_get_vlan_info_from_items(items, &vlan);
15440 : 0 : mlx5_update_vlan_vid_pcp(actions, &vlan);
15441 : : /* If no VLAN push - this is a modify header action */
15442 [ # # ]: 0 : if (flow_dv_convert_action_modify_vlan_vid
15443 : : (mhdr_res, actions, error))
15444 : 0 : return -rte_errno;
15445 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
15446 : 0 : break;
15447 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
15448 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
15449 [ # # ]: 0 : if (flow_dv_create_action_l2_encap(dev, actions,
15450 : : dev_flow,
15451 : 0 : attr->transfer,
15452 : : error))
15453 : 0 : return -rte_errno;
15454 : 0 : dev_flow->dv.actions[actions_n++] =
15455 : 0 : dev_flow->dv.encap_decap->action;
15456 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
15457 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
15458 : 0 : sample_act->action_flags |=
15459 : : MLX5_FLOW_ACTION_ENCAP;
15460 : : break;
15461 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
15462 : : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
15463 [ # # ]: 0 : if (flow_dv_create_action_l2_decap(dev, dev_flow,
15464 : 0 : attr->transfer,
15465 : : error))
15466 : 0 : return -rte_errno;
15467 : 0 : dev_flow->dv.actions[actions_n++] =
15468 : 0 : dev_flow->dv.encap_decap->action;
15469 : 0 : action_flags |= MLX5_FLOW_ACTION_DECAP;
15470 : 0 : break;
15471 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
15472 : : /* Handle encap with preceding decap. */
15473 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_DECAP) {
15474 [ # # ]: 0 : if (flow_dv_create_action_raw_encap
15475 : : (dev, actions, dev_flow, attr, error))
15476 : 0 : return -rte_errno;
15477 : 0 : dev_flow->dv.actions[actions_n++] =
15478 : 0 : dev_flow->dv.encap_decap->action;
15479 : : } else {
15480 : : /* Handle encap without preceding decap. */
15481 [ # # ]: 0 : if (flow_dv_create_action_l2_encap
15482 : 0 : (dev, actions, dev_flow, attr->transfer,
15483 : : error))
15484 : 0 : return -rte_errno;
15485 : 0 : dev_flow->dv.actions[actions_n++] =
15486 : 0 : dev_flow->dv.encap_decap->action;
15487 : : }
15488 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
15489 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
15490 : 0 : sample_act->action_flags |=
15491 : : MLX5_FLOW_ACTION_ENCAP;
15492 : : break;
15493 : : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
15494 [ # # ]: 0 : while ((++action)->type == RTE_FLOW_ACTION_TYPE_VOID)
15495 : : ;
15496 [ # # ]: 0 : if (action->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
15497 [ # # ]: 0 : if (flow_dv_create_action_l2_decap
15498 : 0 : (dev, dev_flow, attr->transfer, error))
15499 : 0 : return -rte_errno;
15500 : 0 : dev_flow->dv.actions[actions_n++] =
15501 : 0 : dev_flow->dv.encap_decap->action;
15502 : : }
15503 : : /* If decap is followed by encap, handle it at encap. */
15504 : 0 : action_flags |= MLX5_FLOW_ACTION_DECAP;
15505 : 0 : break;
15506 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_JUMP:
15507 : 0 : dev_flow->dv.actions[actions_n++] =
15508 : 0 : (void *)(uintptr_t)action->conf;
15509 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP;
15510 : 0 : break;
15511 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
15512 : 0 : jump_group = ((const struct rte_flow_action_jump *)
15513 : 0 : action->conf)->group;
15514 : 0 : grp_info.std_tbl_fix = 0;
15515 [ # # ]: 0 : if (dev_flow->skip_scale &
15516 : : (1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT))
15517 : 0 : grp_info.skip_scale = 1;
15518 : : else
15519 : 0 : grp_info.skip_scale = 0;
15520 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel,
15521 : : jump_group,
15522 : : &table,
15523 : : &grp_info, error);
15524 [ # # ]: 0 : if (ret)
15525 : 0 : return ret;
15526 : 0 : tbl = mlx5_flow_dv_tbl_resource_get(dev, table, attr->egress,
15527 : 0 : attr->transfer,
15528 : 0 : dev_flow->external,
15529 : : tunnel, jump_group, 0,
15530 : : 0, error);
15531 [ # # ]: 0 : if (!tbl)
15532 : 0 : return rte_flow_error_set
15533 : 0 : (error, errno,
15534 : : RTE_FLOW_ERROR_TYPE_ACTION,
15535 : : NULL,
15536 : : "cannot create jump action.");
15537 : : if (flow_dv_jump_tbl_resource_register
15538 : : (dev, tbl, dev_flow, error)) {
15539 : : mlx5_flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
15540 : : return rte_flow_error_set
15541 : : (error, errno,
15542 : : RTE_FLOW_ERROR_TYPE_ACTION,
15543 : : NULL,
15544 : : "cannot create jump action.");
15545 : : }
15546 : 0 : dev_flow->dv.actions[actions_n++] =
15547 : 0 : dev_flow->dv.jump->action;
15548 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP;
15549 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_JUMP;
15550 : 0 : sample_act->action_flags |= MLX5_FLOW_ACTION_JUMP;
15551 : 0 : num_of_dest++;
15552 : 0 : break;
15553 : 0 : case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
15554 : : case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
15555 [ # # ]: 0 : if (flow_dv_convert_action_modify_mac
15556 : : (mhdr_res, actions, error))
15557 : 0 : return -rte_errno;
15558 : 0 : action_flags |= actions->type ==
15559 : : RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
15560 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_MAC_SRC :
15561 : : MLX5_FLOW_ACTION_SET_MAC_DST;
15562 : 0 : break;
15563 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
15564 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
15565 [ # # ]: 0 : if (flow_dv_convert_action_modify_ipv4
15566 : : (mhdr_res, actions, error))
15567 : 0 : return -rte_errno;
15568 : 0 : action_flags |= actions->type ==
15569 : : RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
15570 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_IPV4_SRC :
15571 : : MLX5_FLOW_ACTION_SET_IPV4_DST;
15572 : 0 : break;
15573 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
15574 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
15575 [ # # ]: 0 : if (flow_dv_convert_action_modify_ipv6
15576 : : (mhdr_res, actions, error))
15577 : 0 : return -rte_errno;
15578 : 0 : action_flags |= actions->type ==
15579 : : RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
15580 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_IPV6_SRC :
15581 : : MLX5_FLOW_ACTION_SET_IPV6_DST;
15582 : 0 : break;
15583 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
15584 : : case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
15585 [ # # ]: 0 : if (flow_dv_convert_action_modify_tp
15586 : : (mhdr_res, actions, items,
15587 : 0 : &flow_attr, dev_flow, !!(action_flags &
15588 : : MLX5_FLOW_ACTION_DECAP), error))
15589 : 0 : return -rte_errno;
15590 : 0 : action_flags |= actions->type ==
15591 : : RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
15592 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_TP_SRC :
15593 : : MLX5_FLOW_ACTION_SET_TP_DST;
15594 : 0 : break;
15595 : 0 : case RTE_FLOW_ACTION_TYPE_DEC_TTL:
15596 [ # # ]: 0 : if (flow_dv_convert_action_modify_dec_ttl
15597 : : (mhdr_res, items, &flow_attr, dev_flow,
15598 : 0 : !!(action_flags &
15599 : : MLX5_FLOW_ACTION_DECAP), error))
15600 : 0 : return -rte_errno;
15601 : 0 : action_flags |= MLX5_FLOW_ACTION_DEC_TTL;
15602 : 0 : break;
15603 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TTL:
15604 [ # # ]: 0 : if (flow_dv_convert_action_modify_ttl
15605 : : (mhdr_res, actions, items, &flow_attr,
15606 : 0 : dev_flow, !!(action_flags &
15607 : : MLX5_FLOW_ACTION_DECAP), error))
15608 : 0 : return -rte_errno;
15609 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TTL;
15610 : 0 : break;
15611 : 0 : case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
15612 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
15613 [ # # ]: 0 : if (flow_dv_convert_action_modify_tcp_seq
15614 : : (mhdr_res, actions, error))
15615 : 0 : return -rte_errno;
15616 : 0 : action_flags |= actions->type ==
15617 : : RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
15618 [ # # ]: 0 : MLX5_FLOW_ACTION_INC_TCP_SEQ :
15619 : : MLX5_FLOW_ACTION_DEC_TCP_SEQ;
15620 : 0 : break;
15621 : :
15622 : 0 : case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
15623 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
15624 [ # # ]: 0 : if (flow_dv_convert_action_modify_tcp_ack
15625 : : (mhdr_res, actions, error))
15626 : 0 : return -rte_errno;
15627 : 0 : action_flags |= actions->type ==
15628 : : RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
15629 [ # # ]: 0 : MLX5_FLOW_ACTION_INC_TCP_ACK :
15630 : : MLX5_FLOW_ACTION_DEC_TCP_ACK;
15631 : 0 : break;
15632 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
15633 [ # # ]: 0 : if (flow_dv_convert_action_set_reg
15634 : : (mhdr_res, actions, error))
15635 : 0 : return -rte_errno;
15636 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
15637 : 0 : break;
15638 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
15639 [ # # ]: 0 : if (flow_dv_convert_action_copy_mreg
15640 : : (dev, mhdr_res, actions, error))
15641 : 0 : return -rte_errno;
15642 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
15643 : 0 : break;
15644 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
15645 : 0 : action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
15646 : 0 : dev_flow->handle->fate_action =
15647 : : MLX5_FLOW_FATE_DEFAULT_MISS;
15648 : 0 : break;
15649 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
15650 [ # # ]: 0 : if (!wks->fm)
15651 : 0 : return rte_flow_error_set(error, rte_errno,
15652 : : RTE_FLOW_ERROR_TYPE_ACTION,
15653 : : NULL, "Failed to get meter in flow.");
15654 : : /* Set the meter action. */
15655 : 0 : dev_flow->dv.actions[actions_n++] =
15656 : 0 : wks->fm->meter_action_g;
15657 : 0 : action_flags |= MLX5_FLOW_ACTION_METER;
15658 : 0 : break;
15659 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
15660 [ # # ]: 0 : if (flow_dv_convert_action_modify_ipv4_dscp(mhdr_res,
15661 : : actions, error))
15662 : 0 : return -rte_errno;
15663 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
15664 : 0 : break;
15665 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
15666 [ # # ]: 0 : if (mlx5_dv_modify_ipv6_traffic_class_supported(priv))
15667 : : ipv6_tc_off = MLX5_IPV6_HDR_DSCP_SHIFT;
15668 : : else
15669 : : ipv6_tc_off = 0;
15670 [ # # ]: 0 : if (flow_dv_convert_action_modify_ipv6_dscp(mhdr_res,
15671 : : actions, ipv6_tc_off, error))
15672 : 0 : return -rte_errno;
15673 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
15674 : 0 : break;
15675 : 0 : case RTE_FLOW_ACTION_TYPE_SAMPLE:
15676 : 0 : sample_act_pos = actions_n;
15677 : 0 : sample = (const struct rte_flow_action_sample *)
15678 : : action->conf;
15679 : 0 : actions_n++;
15680 : 0 : action_flags |= MLX5_FLOW_ACTION_SAMPLE;
15681 : : /* put encap action into group if work with port id */
15682 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_ENCAP) &&
15683 : : (action_flags & MLX5_FLOW_ACTION_PORT_ID))
15684 : 0 : sample_act->action_flags |=
15685 : : MLX5_FLOW_ACTION_ENCAP;
15686 : : break;
15687 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
15688 [ # # ]: 0 : if (flow_dv_convert_action_modify_field
15689 : : (dev, mhdr_res, actions, attr, error))
15690 : 0 : return -rte_errno;
15691 : 0 : action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
15692 : 0 : break;
15693 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
15694 : 0 : owner_idx = (uint32_t)(uintptr_t)action->conf;
15695 : 0 : ct = flow_aso_ct_get_by_idx(dev, owner_idx);
15696 [ # # ]: 0 : if (!ct)
15697 : 0 : return rte_flow_error_set(error, EINVAL,
15698 : : RTE_FLOW_ERROR_TYPE_ACTION,
15699 : : NULL,
15700 : : "Failed to get CT object.");
15701 [ # # ]: 0 : if (mlx5_aso_ct_available(priv->sh, MLX5_HW_INV_QUEUE, ct))
15702 : 0 : return rte_flow_error_set(error, rte_errno,
15703 : : RTE_FLOW_ERROR_TYPE_ACTION,
15704 : : NULL,
15705 : : "CT is unavailable.");
15706 [ # # ]: 0 : if (ct->is_original)
15707 : 0 : dev_flow->dv.actions[actions_n] =
15708 : 0 : ct->dr_action_orig;
15709 : : else
15710 : 0 : dev_flow->dv.actions[actions_n] =
15711 : 0 : ct->dr_action_rply;
15712 [ # # ]: 0 : if (flow->ct == 0) {
15713 : 0 : flow->indirect_type =
15714 : : MLX5_INDIRECT_ACTION_TYPE_CT;
15715 : 0 : flow->ct = owner_idx;
15716 : 0 : rte_atomic_fetch_add_explicit(&ct->refcnt, 1,
15717 : : rte_memory_order_relaxed);
15718 : : }
15719 : 0 : actions_n++;
15720 : 0 : action_flags |= MLX5_FLOW_ACTION_CT;
15721 : 0 : break;
15722 : 0 : case RTE_FLOW_ACTION_TYPE_END:
15723 : : actions_end = true;
15724 [ # # ]: 0 : if (mhdr_res->actions_num) {
15725 : : /* create modify action if needed. */
15726 [ # # ]: 0 : if (flow_dv_modify_hdr_resource_register
15727 : : (dev, mhdr_res, dev_flow, error))
15728 : 0 : return -rte_errno;
15729 : 0 : dev_flow->dv.actions[modify_action_position] =
15730 : 0 : handle->dvh.modify_hdr->action;
15731 : : }
15732 : : /*
15733 : : * Handle AGE and COUNT action by single HW counter
15734 : : * when they are not shared.
15735 : : */
15736 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_AGE) {
15737 [ # # # # ]: 0 : if ((non_shared_age && count) ||
15738 [ # # ]: 0 : !flow_hit_aso_supported(priv, !dev_flow->dv.group)) {
15739 : : /* Creates age by counters. */
15740 : 0 : cnt_act = flow_dv_prepare_counter
15741 : : (dev, dev_flow,
15742 : : flow, count,
15743 : : non_shared_age,
15744 : : error);
15745 [ # # ]: 0 : if (!cnt_act)
15746 : 0 : return -rte_errno;
15747 : 0 : dev_flow->dv.actions[age_act_pos] =
15748 : 0 : cnt_act->action;
15749 : 0 : break;
15750 : : }
15751 [ # # # # ]: 0 : if (!flow->age && non_shared_age) {
15752 : 0 : flow->age = flow_dv_aso_age_alloc
15753 : : (dev, error);
15754 [ # # ]: 0 : if (!flow->age)
15755 : 0 : return -rte_errno;
15756 : 0 : flow_dv_aso_age_params_init
15757 : : (dev, flow->age,
15758 : 0 : non_shared_age->context ?
15759 : : non_shared_age->context :
15760 : 0 : (void *)(uintptr_t)
15761 : 0 : (dev_flow->flow_idx),
15762 [ # # ]: 0 : non_shared_age->timeout);
15763 : : }
15764 : 0 : age_act = mlx5_flow_aso_age_get_by_idx(dev, flow->age);
15765 : 0 : dev_flow->dv.actions[age_act_pos] =
15766 : 0 : age_act->dr_action;
15767 : : }
15768 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_COUNT) {
15769 : : /*
15770 : : * Create one count action, to be used
15771 : : * by all sub-flows.
15772 : : */
15773 : 0 : cnt_act = flow_dv_prepare_counter(dev, dev_flow,
15774 : : flow, count,
15775 : : NULL, error);
15776 [ # # ]: 0 : if (!cnt_act)
15777 : 0 : return -rte_errno;
15778 : 0 : dev_flow->dv.actions[actions_n++] =
15779 : 0 : cnt_act->action;
15780 : : }
15781 : : default:
15782 : : break;
15783 : : }
15784 [ # # # # ]: 0 : if (mhdr_res->actions_num &&
15785 : : modify_action_position == UINT32_MAX)
15786 : 0 : modify_action_position = actions_n++;
15787 : : }
15788 : 0 : dev_flow->act_flags = action_flags;
15789 : 0 : ret = flow_dv_translate_items_sws(dev, dev_flow, attr, items, &matcher,
15790 : : error);
15791 [ # # ]: 0 : if (ret)
15792 : 0 : return -rte_errno;
15793 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_RSS) {
15794 : 0 : dev_flow->symmetric_hash_function = rss_desc->symmetric_hash_function;
15795 : 0 : mlx5_flow_dv_hashfields_set(dev_flow->handle->layers,
15796 : : rss_desc,
15797 : : &dev_flow->hash_fields);
15798 : : }
15799 : : /* If has RSS action in the sample action, the Sample/Mirror resource
15800 : : * should be registered after the hash filed be update.
15801 : : */
15802 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE) {
15803 : 0 : ret = flow_dv_translate_action_sample(dev,
15804 : : sample,
15805 : : dev_flow, attr,
15806 : : &num_of_dest,
15807 : : sample_actions,
15808 : : &sample_res,
15809 : : error);
15810 [ # # ]: 0 : if (ret < 0)
15811 : : return ret;
15812 : 0 : ret = flow_dv_create_action_sample(dev,
15813 : : dev_flow,
15814 : : num_of_dest,
15815 : : &sample_res,
15816 : : &mdest_res,
15817 : : sample_actions,
15818 : : action_flags,
15819 : : error);
15820 [ # # ]: 0 : if (ret < 0)
15821 : 0 : return rte_flow_error_set
15822 : : (error, rte_errno,
15823 : : RTE_FLOW_ERROR_TYPE_ACTION,
15824 : : NULL,
15825 : : "cannot create sample action");
15826 [ # # ]: 0 : if (num_of_dest > 1) {
15827 : 0 : dev_flow->dv.actions[sample_act_pos] =
15828 : 0 : dev_flow->dv.dest_array_res->action;
15829 : : } else {
15830 : 0 : dev_flow->dv.actions[sample_act_pos] =
15831 : 0 : dev_flow->dv.sample_res->verbs_action;
15832 : : }
15833 : : }
15834 : : /*
15835 : : * For multiple destination (sample action with ratio=1), the encap
15836 : : * action and port id action will be combined into group action.
15837 : : * So need remove the original these actions in the flow and only
15838 : : * use the sample action instead of.
15839 : : */
15840 [ # # ]: 0 : if (num_of_dest > 1 &&
15841 [ # # # # ]: 0 : (sample_act->dr_port_id_action || sample_act->dr_jump_action)) {
15842 : : int i;
15843 : 0 : void *temp_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
15844 : :
15845 [ # # ]: 0 : for (i = 0; i < actions_n; i++) {
15846 [ # # ]: 0 : if ((sample_act->dr_encap_action &&
15847 : : sample_act->dr_encap_action ==
15848 [ # # # # ]: 0 : dev_flow->dv.actions[i]) ||
15849 : 0 : (sample_act->dr_port_id_action &&
15850 : : sample_act->dr_port_id_action ==
15851 [ # # ]: 0 : dev_flow->dv.actions[i]) ||
15852 [ # # ]: 0 : (sample_act->dr_jump_action &&
15853 : : sample_act->dr_jump_action ==
15854 [ # # ]: 0 : dev_flow->dv.actions[i]))
15855 : 0 : continue;
15856 : 0 : temp_actions[tmp_actions_n++] = dev_flow->dv.actions[i];
15857 : : }
15858 : 0 : memcpy((void *)dev_flow->dv.actions,
15859 : : (void *)temp_actions,
15860 : : tmp_actions_n * sizeof(void *));
15861 : : actions_n = tmp_actions_n;
15862 : : }
15863 : 0 : dev_flow->dv.actions_n = actions_n;
15864 [ # # ]: 0 : if (wks->skip_matcher_reg)
15865 : : return 0;
15866 : : /* Register matcher. */
15867 : 0 : matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
15868 : : matcher.mask.size);
15869 : 0 : matcher.priority = mlx5_get_matcher_priority(dev, attr,
15870 : 0 : matcher.priority,
15871 : 0 : dev_flow->external);
15872 : : /**
15873 : : * When creating meter drop flow in drop table, using original
15874 : : * 5-tuple match, the matcher priority should be lower than
15875 : : * mtr_id matcher.
15876 : : */
15877 [ # # ]: 0 : if (attr->group == MLX5_FLOW_TABLE_LEVEL_METER &&
15878 [ # # # # ]: 0 : dev_flow->dv.table_id == MLX5_MTR_TABLE_ID_DROP &&
15879 : : matcher.priority <= MLX5_REG_BITS)
15880 : 0 : matcher.priority += MLX5_REG_BITS;
15881 : : /* reserved field no needs to be set to 0 here. */
15882 : 0 : tbl_key.is_fdb = attr->transfer;
15883 : 0 : tbl_key.is_egress = attr->egress;
15884 : 0 : tbl_key.level = dev_flow->dv.group;
15885 : 0 : tbl_key.id = dev_flow->dv.table_id;
15886 [ # # ]: 0 : if (flow_dv_matcher_register(dev, &matcher, &tbl_key, dev_flow,
15887 : : tunnel, attr->group, error))
15888 : 0 : return -rte_errno;
15889 : : return 0;
15890 : : }
15891 : :
15892 : : /*
15893 : : * Protocol selector bitmap
15894 : : * Each flag is used as an indicator that given protocol is specified in given RSS hash fields.
15895 : : */
15896 : : #define RX_HASH_SELECTOR_IPV4 RTE_BIT32(0)
15897 : : #define RX_HASH_SELECTOR_IPV6 RTE_BIT32(1)
15898 : : #define RX_HASH_SELECTOR_UDP RTE_BIT32(2)
15899 : : #define RX_HASH_SELECTOR_TCP RTE_BIT32(3)
15900 : : #define RX_HASH_SELECTOR_ESP_SPI RTE_BIT32(4)
15901 : : #define RX_HASH_SELECTOR_NONE (0)
15902 : :
15903 : : #define RX_HASH_SELECTOR_IPV4_TCP (RX_HASH_SELECTOR_IPV4 | RX_HASH_SELECTOR_TCP)
15904 : : #define RX_HASH_SELECTOR_IPV4_UDP (RX_HASH_SELECTOR_IPV4 | RX_HASH_SELECTOR_UDP)
15905 : : #define RX_HASH_SELECTOR_IPV4_ESP (RX_HASH_SELECTOR_IPV4 | RX_HASH_SELECTOR_ESP_SPI)
15906 : :
15907 : : #define RX_HASH_SELECTOR_IPV6_TCP (RX_HASH_SELECTOR_IPV6 | RX_HASH_SELECTOR_TCP)
15908 : : #define RX_HASH_SELECTOR_IPV6_UDP (RX_HASH_SELECTOR_IPV6 | RX_HASH_SELECTOR_UDP)
15909 : : #define RX_HASH_SELECTOR_IPV6_ESP (RX_HASH_SELECTOR_IPV6 | RX_HASH_SELECTOR_ESP_SPI)
15910 : :
15911 : : static bool
15912 : : rx_hash_selector_has_valid_l3(const uint32_t selectors)
15913 : : {
15914 : : /* In TIR configuration, RSS hashing on both IPv4 and IPv6 is mutually exclusive. */
15915 : : return !((selectors & RX_HASH_SELECTOR_IPV4) && (selectors & RX_HASH_SELECTOR_IPV6));
15916 : : }
15917 : :
15918 : : static bool
15919 : : rx_hash_selector_has_valid_l4(const uint32_t selectors)
15920 : : {
15921 : : /* In TIR configuration, RSS hashing on both UDP and TCP is mutually exclusive. */
15922 : 0 : return !((selectors & RX_HASH_SELECTOR_UDP) && (selectors & RX_HASH_SELECTOR_TCP));
15923 : : }
15924 : :
15925 : : static bool
15926 : : rx_hash_selector_has_valid_esp(const uint32_t selectors)
15927 : : {
15928 : : /* In TIR configuration, RSS hashing on ESP and other L4 protocol is mutually exclusive. */
15929 [ # # ]: 0 : if (selectors & RX_HASH_SELECTOR_ESP_SPI)
15930 : 0 : return !((selectors & RX_HASH_SELECTOR_UDP) || (selectors & RX_HASH_SELECTOR_TCP));
15931 : :
15932 : : return true;
15933 : : }
15934 : :
15935 : : /**
15936 : : * Calculate protocol combination based on provided RSS hashing fields.
15937 : : *
15938 : : * @param[in] hash_fields
15939 : : * Requested RSS hashing fields specified as a flags bitmap, based on ibv_rx_hash_fields.
15940 : : * @param[out] selectors_out
15941 : : * Calculated protocol combination will be written here.
15942 : : * Result will be a bitmap of RX_HASH_SELECTOR_* flags.
15943 : : *
15944 : : * @return
15945 : : * 0 if conversion is successful and protocol combination written to @p selectors_out.
15946 : : * (-EINVAL) otherwise.
15947 : : */
15948 : : static int
15949 : 0 : rx_hash_calc_selector(const uint64_t hash_fields, uint32_t *selectors_out)
15950 : : {
15951 : : const uint64_t filtered_hf = hash_fields & ~IBV_RX_HASH_INNER;
15952 : : uint32_t selectors = 0;
15953 : :
15954 [ # # ]: 0 : if (filtered_hf & MLX5_RSS_HASH_IPV4)
15955 : : selectors |= RX_HASH_SELECTOR_IPV4;
15956 [ # # ]: 0 : if (filtered_hf & MLX5_RSS_HASH_IPV6)
15957 : 0 : selectors |= RX_HASH_SELECTOR_IPV6;
15958 [ # # ]: 0 : if (!rx_hash_selector_has_valid_l3(selectors)) {
15959 : 0 : DRV_LOG(NOTICE, "hrxq hashing on both IPv4 and IPv6 is invalid: "
15960 : : "selectors=0x%" PRIx32, selectors);
15961 : 0 : return -EINVAL;
15962 : : }
15963 : :
15964 [ # # ]: 0 : if (filtered_hf & MLX5_UDP_IBV_RX_HASH)
15965 : 0 : selectors |= RX_HASH_SELECTOR_UDP;
15966 [ # # ]: 0 : if (filtered_hf & MLX5_TCP_IBV_RX_HASH)
15967 : 0 : selectors |= RX_HASH_SELECTOR_TCP;
15968 [ # # ]: 0 : if (!rx_hash_selector_has_valid_l4(selectors)) {
15969 : 0 : DRV_LOG(NOTICE, "hrxq hashing on both UDP and TCP is invalid: "
15970 : : "selectors=0x%" PRIx32, selectors);
15971 : 0 : return -EINVAL;
15972 : : }
15973 : :
15974 [ # # ]: 0 : if (filtered_hf & MLX5_RSS_HASH_ESP_SPI)
15975 : 0 : selectors |= RX_HASH_SELECTOR_ESP_SPI;
15976 [ # # ]: 0 : if (!rx_hash_selector_has_valid_esp(selectors)) {
15977 : 0 : DRV_LOG(NOTICE, "hrxq hashing on ESP SPI and UDP or TCP is mutually exclusive: "
15978 : : "selectors=0x%" PRIx32, selectors);
15979 : 0 : return -EINVAL;
15980 : : }
15981 : :
15982 : 0 : *selectors_out = selectors;
15983 : 0 : return 0;
15984 : : }
15985 : :
15986 : : /**
15987 : : * Calculate the hrxq object index based on protocol combination.
15988 : : *
15989 : : * @param[in] selectors
15990 : : * Protocol combination specified as bitmap of RX_HASH_SELECTOR_* flags.
15991 : : *
15992 : : * @return
15993 : : * Index into hrxq array in #mlx5_shared_action_rss based on ginve protocol combination.
15994 : : * (-EINVAL) if given protocol combination is not supported or is invalid.
15995 : : */
15996 : : static int
15997 : 0 : get_rss_hash_idx(const uint32_t selectors)
15998 : : {
15999 [ # # # # : 0 : switch (selectors) {
# # # # #
# # # # ]
16000 : : case RX_HASH_SELECTOR_IPV4:
16001 : : return MLX5_RSS_HASH_IDX_IPV4;
16002 : 0 : case RX_HASH_SELECTOR_IPV4_TCP:
16003 : 0 : return MLX5_RSS_HASH_IDX_IPV4_TCP;
16004 : 0 : case RX_HASH_SELECTOR_IPV4_UDP:
16005 : 0 : return MLX5_RSS_HASH_IDX_IPV4_UDP;
16006 : 0 : case RX_HASH_SELECTOR_IPV4_ESP:
16007 : 0 : return MLX5_RSS_HASH_IDX_IPV4_ESP;
16008 : 0 : case RX_HASH_SELECTOR_IPV6:
16009 : 0 : return MLX5_RSS_HASH_IDX_IPV6;
16010 : 0 : case RX_HASH_SELECTOR_IPV6_TCP:
16011 : 0 : return MLX5_RSS_HASH_IDX_IPV6_TCP;
16012 : 0 : case RX_HASH_SELECTOR_IPV6_UDP:
16013 : 0 : return MLX5_RSS_HASH_IDX_IPV6_UDP;
16014 : 0 : case RX_HASH_SELECTOR_IPV6_ESP:
16015 : 0 : return MLX5_RSS_HASH_IDX_IPV6_ESP;
16016 : 0 : case RX_HASH_SELECTOR_TCP:
16017 : 0 : return MLX5_RSS_HASH_IDX_TCP;
16018 : 0 : case RX_HASH_SELECTOR_UDP:
16019 : 0 : return MLX5_RSS_HASH_IDX_UDP;
16020 : 0 : case RX_HASH_SELECTOR_ESP_SPI:
16021 : 0 : return MLX5_RSS_HASH_IDX_ESP_SPI;
16022 : 0 : case RX_HASH_SELECTOR_NONE:
16023 : 0 : return MLX5_RSS_HASH_IDX_NONE;
16024 : 0 : default:
16025 : 0 : DRV_LOG(ERR, "invalid hrxq hash fields combination: "
16026 : : "selectors=0x%" PRIx32, selectors);
16027 : 0 : return -EINVAL;
16028 : : }
16029 : : }
16030 : :
16031 : : /**
16032 : : * Set hash RX queue by hash fields (see enum ibv_rx_hash_fields)
16033 : : * and tunnel.
16034 : : *
16035 : : * @param[in, out] action
16036 : : * Shred RSS action holding hash RX queue objects.
16037 : : * @param[in] hash_fields
16038 : : * Defines combination of packet fields to participate in RX hash,
16039 : : * specified as a bitmap of #ibv_rx_hash_fields flags.
16040 : : * @param[in] tunnel
16041 : : * Tunnel type
16042 : : * @param[in] hrxq_idx
16043 : : * Hash RX queue index to set.
16044 : : *
16045 : : * @return
16046 : : * 0 on success, otherwise negative errno value.
16047 : : */
16048 : : static int
16049 : 0 : __flow_dv_action_rss_hrxq_set(struct mlx5_shared_action_rss *action,
16050 : : const uint64_t hash_fields,
16051 : : uint32_t hrxq_idx)
16052 : : {
16053 : 0 : uint32_t *hrxqs = action->hrxq;
16054 : 0 : uint32_t selectors = 0;
16055 : : int ret;
16056 : :
16057 : 0 : ret = rx_hash_calc_selector(hash_fields, &selectors);
16058 : : /*
16059 : : * Hash fields passed to this function are constructed internally.
16060 : : * If this fails, then this is a PMD bug.
16061 : : */
16062 : : MLX5_ASSERT(ret == 0);
16063 : :
16064 : 0 : ret = get_rss_hash_idx(selectors);
16065 : : /*
16066 : : * Based on above assert, selectors should always yield correct index
16067 : : * in mlx5_rss_hash_fields array.
16068 : : * If this fails, then this is a PMD bug.
16069 : : */
16070 : : MLX5_ASSERT(ret >= 0 && ret < MLX5_RSS_HASH_IDX_MAX);
16071 : 0 : hrxqs[ret] = hrxq_idx;
16072 : :
16073 : 0 : return 0;
16074 : : }
16075 : :
16076 : : /**
16077 : : * Look up for hash RX queue by hash fields (see enum ibv_rx_hash_fields)
16078 : : * and tunnel.
16079 : : *
16080 : : * @param[in] dev
16081 : : * Pointer to the Ethernet device structure.
16082 : : * @param[in] idx
16083 : : * Shared RSS action ID holding hash RX queue objects.
16084 : : * @param[in] hash_fields
16085 : : * Defines combination of packet fields to participate in RX hash,
16086 : : * specified as a bitmap of #ibv_rx_hash_fields flags.
16087 : : * @param[in] tunnel
16088 : : * Tunnel type
16089 : : *
16090 : : * @return
16091 : : * Valid hash RX queue index, otherwise 0.
16092 : : */
16093 : : uint32_t
16094 : 0 : mlx5_flow_dv_action_rss_hrxq_lookup(struct rte_eth_dev *dev, uint32_t idx,
16095 : : const uint64_t hash_fields)
16096 : : {
16097 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16098 : : struct mlx5_shared_action_rss *shared_rss =
16099 : 0 : mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
16100 : : const uint32_t *hrxqs;
16101 : 0 : uint32_t selectors = 0;
16102 : : int ret;
16103 : :
16104 [ # # ]: 0 : if (!shared_rss) {
16105 : 0 : DRV_LOG(ERR, "port %u cannot get RSS action: rss_act_idx=%u",
16106 : : dev->data->port_id, idx);
16107 : 0 : return 0;
16108 : : }
16109 : 0 : hrxqs = shared_rss->hrxq;
16110 : :
16111 : 0 : ret = rx_hash_calc_selector(hash_fields, &selectors);
16112 [ # # ]: 0 : if (ret < 0) {
16113 : 0 : DRV_LOG(ERR, "port %u Rx hash selector calculation failed: "
16114 : : "rss_act_idx=%u hash_fields=0x%" PRIx64 " selectors=0x%" PRIx32,
16115 : : dev->data->port_id, idx, hash_fields, selectors);
16116 : 0 : return 0;
16117 : : }
16118 : :
16119 : 0 : ret = get_rss_hash_idx(selectors);
16120 [ # # ]: 0 : if (ret < 0) {
16121 : 0 : DRV_LOG(ERR, "port %u failed hrxq index lookup: "
16122 : : "rss_act_idx=%u hash_fields=0x%" PRIx64 " selectors=0x%" PRIx32,
16123 : : dev->data->port_id, idx, hash_fields, selectors);
16124 : 0 : return 0;
16125 : : }
16126 : :
16127 : 0 : return hrxqs[ret];
16128 : : }
16129 : :
16130 : : /**
16131 : : * Apply the flow to the NIC, lock free,
16132 : : * (mutex should be acquired by caller).
16133 : : *
16134 : : * @param[in] dev
16135 : : * Pointer to the Ethernet device structure.
16136 : : * @param[in, out] flow
16137 : : * Pointer to flow structure.
16138 : : * @param[out] error
16139 : : * Pointer to error structure.
16140 : : *
16141 : : * @return
16142 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
16143 : : */
16144 : : static int
16145 : 0 : flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
16146 : : struct rte_flow_error *error)
16147 : : {
16148 : : struct mlx5_flow_dv_workspace *dv;
16149 : : struct mlx5_flow_handle *dh;
16150 : : struct mlx5_flow_handle_dv *dv_h;
16151 : : struct mlx5_flow *dev_flow;
16152 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16153 : : uint32_t handle_idx;
16154 : : int n;
16155 : : int err;
16156 : : int idx;
16157 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
16158 : 0 : struct mlx5_flow_rss_desc *rss_desc = &wks->rss_desc;
16159 : : uint8_t misc_mask;
16160 : :
16161 : : MLX5_ASSERT(wks);
16162 [ # # ]: 0 : for (idx = wks->flow_idx - 1; idx >= 0; idx--) {
16163 : 0 : dev_flow = &wks->flows[idx];
16164 : : dv = &dev_flow->dv;
16165 : 0 : dh = dev_flow->handle;
16166 : : dv_h = &dh->dvh;
16167 : 0 : n = dv->actions_n;
16168 [ # # ]: 0 : if (dh->fate_action == MLX5_FLOW_FATE_DROP) {
16169 [ # # ]: 0 : if (dv->transfer) {
16170 : : MLX5_ASSERT(priv->sh->dr_drop_action);
16171 : 0 : dv->actions[n++] = priv->sh->dr_drop_action;
16172 : : } else {
16173 : : #ifdef HAVE_MLX5DV_DR
16174 : : /* DR supports drop action placeholder. */
16175 : : MLX5_ASSERT(priv->sh->dr_drop_action);
16176 : 0 : dv->actions[n++] = dv->group ?
16177 [ # # ]: 0 : priv->sh->dr_drop_action :
16178 : : priv->root_drop_action;
16179 : : #else
16180 : : /* For DV we use the explicit drop queue. */
16181 : : MLX5_ASSERT(priv->drop_queue.hrxq);
16182 : : dv->actions[n++] =
16183 : : priv->drop_queue.hrxq->action;
16184 : : #endif
16185 : : }
16186 [ # # ]: 0 : } else if ((dh->fate_action == MLX5_FLOW_FATE_QUEUE &&
16187 [ # # # # ]: 0 : !dv_h->rix_sample && !dv_h->rix_dest_array)) {
16188 : : struct mlx5_hrxq *hrxq;
16189 : : uint32_t hrxq_idx;
16190 : :
16191 : 0 : hrxq = flow_dv_hrxq_prepare(dev, dev_flow, rss_desc,
16192 : : &hrxq_idx);
16193 [ # # ]: 0 : if (!hrxq) {
16194 : 0 : rte_flow_error_set
16195 : : (error, rte_errno,
16196 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16197 : : "cannot get hash queue");
16198 : 0 : goto error;
16199 : : }
16200 : 0 : dh->rix_hrxq = hrxq_idx;
16201 : 0 : dv->actions[n++] = hrxq->action;
16202 [ # # ]: 0 : } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
16203 : : struct mlx5_hrxq *hrxq = NULL;
16204 : : uint32_t hrxq_idx;
16205 : :
16206 : 0 : hrxq_idx = mlx5_flow_dv_action_rss_hrxq_lookup(dev,
16207 : : rss_desc->shared_rss,
16208 : : dev_flow->hash_fields);
16209 [ # # ]: 0 : if (hrxq_idx)
16210 : 0 : hrxq = mlx5_ipool_get
16211 : 0 : (priv->sh->ipool[MLX5_IPOOL_HRXQ],
16212 : : hrxq_idx);
16213 [ # # ]: 0 : if (!hrxq) {
16214 : 0 : rte_flow_error_set
16215 : : (error, rte_errno,
16216 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16217 : : "cannot get hash queue");
16218 : 0 : goto error;
16219 : : }
16220 : 0 : dh->rix_srss = rss_desc->shared_rss;
16221 : 0 : dv->actions[n++] = hrxq->action;
16222 [ # # ]: 0 : } else if (dh->fate_action == MLX5_FLOW_FATE_DEFAULT_MISS) {
16223 [ # # ]: 0 : if (!priv->sh->default_miss_action) {
16224 : 0 : rte_flow_error_set
16225 : : (error, rte_errno,
16226 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16227 : : "default miss action not be created.");
16228 : 0 : goto error;
16229 : : }
16230 : 0 : dv->actions[n++] = priv->sh->default_miss_action;
16231 : : }
16232 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(dv_h->matcher->mask.buf);
16233 : : __flow_dv_adjust_buf_size(&dv->value.size, misc_mask);
16234 : 0 : err = mlx5_flow_os_create_flow(dv_h->matcher->matcher_object,
16235 : 0 : (void *)&dv->value, n,
16236 : 0 : dv->actions, &dh->drv_flow);
16237 : : if (err) {
16238 : 0 : rte_flow_error_set
16239 : 0 : (error, errno,
16240 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
16241 : : NULL,
16242 [ # # ]: 0 : (!priv->sh->config.allow_duplicate_pattern &&
16243 [ # # ]: 0 : errno == EEXIST) ?
16244 : : "duplicating pattern is not allowed" :
16245 : : "hardware refuses to create flow");
16246 : 0 : goto error;
16247 : : }
16248 [ # # ]: 0 : if (priv->vmwa_context &&
16249 [ # # # # ]: 0 : dh->vf_vlan.tag && !dh->vf_vlan.created) {
16250 : : /*
16251 : : * The rule contains the VLAN pattern.
16252 : : * For VF we are going to create VLAN
16253 : : * interface to make hypervisor set correct
16254 : : * e-Switch vport context.
16255 : : */
16256 : 0 : mlx5_vlan_vmwa_acquire(dev, &dh->vf_vlan);
16257 : : }
16258 : : }
16259 : : return 0;
16260 : 0 : error:
16261 : 0 : err = rte_errno; /* Save rte_errno before cleanup. */
16262 [ # # # # : 0 : SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
# # ]
16263 : : handle_idx, dh, next) {
16264 : : /* hrxq is union, don't clear it if the flag is not set. */
16265 [ # # # # ]: 0 : if (dh->fate_action == MLX5_FLOW_FATE_QUEUE && dh->rix_hrxq &&
16266 [ # # # # ]: 0 : !dh->dvh.rix_sample && !dh->dvh.rix_dest_array) {
16267 : 0 : mlx5_hrxq_release(dev, dh->rix_hrxq);
16268 : 0 : dh->rix_hrxq = 0;
16269 [ # # ]: 0 : } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
16270 : 0 : dh->rix_srss = 0;
16271 : : }
16272 [ # # # # ]: 0 : if (dh->vf_vlan.tag && dh->vf_vlan.created)
16273 : 0 : mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
16274 : : }
16275 : 0 : rte_errno = err; /* Restore rte_errno. */
16276 : 0 : return -rte_errno;
16277 : : }
16278 : :
16279 : : void
16280 : 0 : mlx5_flow_matcher_remove_cb(void *tool_ctx __rte_unused,
16281 : : struct mlx5_list_entry *entry)
16282 : : {
16283 : : struct mlx5_flow_dv_matcher *resource = container_of(entry,
16284 : : typeof(*resource),
16285 : : entry);
16286 : : #ifdef HAVE_MLX5_HWS_SUPPORT
16287 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
16288 : :
16289 [ # # ]: 0 : if (sh->config.dv_flow_en == 2)
16290 : 0 : claim_zero(mlx5dr_bwc_matcher_destroy((struct mlx5dr_bwc_matcher *)
16291 : : resource->matcher_object));
16292 : : else
16293 : : #endif
16294 : 0 : claim_zero(mlx5_flow_os_destroy_flow_matcher(resource->matcher_object));
16295 : 0 : mlx5_free(resource);
16296 : 0 : }
16297 : :
16298 : : /**
16299 : : * Release the flow matcher.
16300 : : *
16301 : : * @param dev
16302 : : * Pointer to Ethernet device.
16303 : : * @param port_id
16304 : : * Index to port ID action resource.
16305 : : *
16306 : : * @return
16307 : : * 1 while a reference on it exists, 0 when freed.
16308 : : */
16309 : : static int
16310 : 0 : flow_dv_matcher_release(struct rte_eth_dev *dev,
16311 : : struct mlx5_flow_handle *handle)
16312 : : {
16313 : 0 : struct mlx5_flow_dv_matcher *matcher = handle->dvh.matcher;
16314 : 0 : struct mlx5_flow_tbl_data_entry *tbl = container_of(matcher->tbl,
16315 : : typeof(*tbl), tbl);
16316 : : int ret;
16317 : :
16318 : : MLX5_ASSERT(matcher->matcher_object);
16319 : 0 : ret = mlx5_list_unregister(tbl->matchers, &matcher->entry);
16320 : 0 : mlx5_flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl->tbl);
16321 : 0 : return ret;
16322 : : }
16323 : :
16324 : : void
16325 : 0 : mlx5_flow_encap_decap_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
16326 : : {
16327 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
16328 : : struct mlx5_flow_dv_encap_decap_resource *res =
16329 : : container_of(entry, typeof(*res), entry);
16330 : :
16331 : : #ifdef HAVE_MLX5_HWS_SUPPORT
16332 [ # # ]: 0 : if (sh->config.dv_flow_en == 2)
16333 : 0 : claim_zero(mlx5dr_action_destroy(res->action));
16334 : : else
16335 : : #endif
16336 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
16337 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], res->idx);
16338 : 0 : }
16339 : :
16340 : : /**
16341 : : * Release an encap/decap resource.
16342 : : *
16343 : : * @param dev
16344 : : * Pointer to Ethernet device.
16345 : : * @param encap_decap_idx
16346 : : * Index of encap decap resource.
16347 : : *
16348 : : * @return
16349 : : * 1 while a reference on it exists, 0 when freed.
16350 : : */
16351 : : int
16352 : 0 : mlx5_flow_encap_decap_resource_release(struct rte_eth_dev *dev,
16353 : : uint32_t encap_decap_idx)
16354 : : {
16355 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16356 : : struct mlx5_flow_dv_encap_decap_resource *resource;
16357 : :
16358 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
16359 : : encap_decap_idx);
16360 [ # # ]: 0 : if (!resource)
16361 : : return 0;
16362 : : MLX5_ASSERT(resource->action);
16363 : 0 : return mlx5_hlist_unregister(priv->sh->encaps_decaps, &resource->entry);
16364 : : }
16365 : :
16366 : : /**
16367 : : * Release an jump to table action resource.
16368 : : *
16369 : : * @param dev
16370 : : * Pointer to Ethernet device.
16371 : : * @param rix_jump
16372 : : * Index to the jump action resource.
16373 : : *
16374 : : * @return
16375 : : * 1 while a reference on it exists, 0 when freed.
16376 : : */
16377 : : static int
16378 : 0 : flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev,
16379 : : uint32_t rix_jump)
16380 : : {
16381 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16382 : : struct mlx5_flow_tbl_data_entry *tbl_data;
16383 : :
16384 : 0 : tbl_data = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_JUMP],
16385 : : rix_jump);
16386 [ # # ]: 0 : if (!tbl_data)
16387 : : return 0;
16388 : 0 : return mlx5_flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl_data->tbl);
16389 : : }
16390 : :
16391 : : void
16392 : 0 : mlx5_flow_modify_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
16393 : : {
16394 : : struct mlx5_flow_dv_modify_hdr_resource *res =
16395 : : container_of(entry, typeof(*res), entry);
16396 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
16397 : :
16398 : : #ifdef HAVE_MLX5_HWS_SUPPORT
16399 [ # # ]: 0 : if (sh->config.dv_flow_en == 2)
16400 : 0 : claim_zero(mlx5dr_action_destroy(res->action));
16401 : : else
16402 : : #endif
16403 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
16404 : 0 : mlx5_ipool_free(sh->mdh_ipools[res->actions_num - 1], res->idx);
16405 : 0 : }
16406 : :
16407 : : /**
16408 : : * Release a modify-header resource.
16409 : : *
16410 : : * @param dev
16411 : : * Pointer to Ethernet device.
16412 : : * @param handle
16413 : : * Pointer to mlx5_flow_handle.
16414 : : *
16415 : : * @return
16416 : : * 1 while a reference on it exists, 0 when freed.
16417 : : */
16418 : : static int
16419 : : flow_dv_modify_hdr_resource_release(struct rte_eth_dev *dev,
16420 : : struct mlx5_flow_handle *handle)
16421 : : {
16422 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16423 : : struct mlx5_flow_dv_modify_hdr_resource *entry = handle->dvh.modify_hdr;
16424 : :
16425 : : MLX5_ASSERT(entry->action);
16426 : 0 : return mlx5_hlist_unregister(priv->sh->modify_cmds, &entry->entry);
16427 : : }
16428 : :
16429 : : void
16430 : 0 : mlx5_flow_dv_port_id_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
16431 : : {
16432 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
16433 : : struct mlx5_flow_dv_port_id_action_resource *resource =
16434 : : container_of(entry, typeof(*resource), entry);
16435 : :
16436 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
16437 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], resource->idx);
16438 : 0 : }
16439 : :
16440 : : /**
16441 : : * Release port ID action resource.
16442 : : *
16443 : : * @param dev
16444 : : * Pointer to Ethernet device.
16445 : : * @param handle
16446 : : * Pointer to mlx5_flow_handle.
16447 : : *
16448 : : * @return
16449 : : * 1 while a reference on it exists, 0 when freed.
16450 : : */
16451 : : static int
16452 : 0 : flow_dv_port_id_action_resource_release(struct rte_eth_dev *dev,
16453 : : uint32_t port_id)
16454 : : {
16455 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16456 : : struct mlx5_flow_dv_port_id_action_resource *resource;
16457 : :
16458 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PORT_ID], port_id);
16459 [ # # ]: 0 : if (!resource)
16460 : : return 0;
16461 : : MLX5_ASSERT(resource->action);
16462 : 0 : return mlx5_list_unregister(priv->sh->port_id_action_list,
16463 : : &resource->entry);
16464 : : }
16465 : :
16466 : : /**
16467 : : * Release shared RSS action resource.
16468 : : *
16469 : : * @param dev
16470 : : * Pointer to Ethernet device.
16471 : : * @param srss
16472 : : * Shared RSS action index.
16473 : : */
16474 : : static void
16475 : 0 : flow_dv_shared_rss_action_release(struct rte_eth_dev *dev, uint32_t srss)
16476 : : {
16477 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16478 : : struct mlx5_shared_action_rss *shared_rss;
16479 : :
16480 : 0 : shared_rss = mlx5_ipool_get
16481 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], srss);
16482 : 0 : rte_atomic_fetch_sub_explicit(&shared_rss->refcnt, 1, rte_memory_order_relaxed);
16483 : 0 : }
16484 : :
16485 : : void
16486 : 0 : mlx5_flow_dv_push_vlan_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
16487 : : {
16488 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
16489 : : struct mlx5_flow_dv_push_vlan_action_resource *resource =
16490 : : container_of(entry, typeof(*resource), entry);
16491 : :
16492 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
16493 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], resource->idx);
16494 : 0 : }
16495 : :
16496 : : /**
16497 : : * Release push vlan action resource.
16498 : : *
16499 : : * @param dev
16500 : : * Pointer to Ethernet device.
16501 : : * @param handle
16502 : : * Pointer to mlx5_flow_handle.
16503 : : *
16504 : : * @return
16505 : : * 1 while a reference on it exists, 0 when freed.
16506 : : */
16507 : : static int
16508 : 0 : flow_dv_push_vlan_action_resource_release(struct rte_eth_dev *dev,
16509 : : struct mlx5_flow_handle *handle)
16510 : : {
16511 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16512 : : struct mlx5_flow_dv_push_vlan_action_resource *resource;
16513 : 0 : uint32_t idx = handle->dvh.rix_push_vlan;
16514 : :
16515 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
16516 [ # # ]: 0 : if (!resource)
16517 : : return 0;
16518 : : MLX5_ASSERT(resource->action);
16519 : 0 : return mlx5_list_unregister(priv->sh->push_vlan_action_list,
16520 : : &resource->entry);
16521 : : }
16522 : :
16523 : : /**
16524 : : * Release the fate resource.
16525 : : *
16526 : : * @param dev
16527 : : * Pointer to Ethernet device.
16528 : : * @param handle
16529 : : * Pointer to mlx5_flow_handle.
16530 : : */
16531 : : static void
16532 : 0 : flow_dv_fate_resource_release(struct rte_eth_dev *dev,
16533 : : struct mlx5_flow_handle *handle)
16534 : : {
16535 [ # # ]: 0 : if (!handle->rix_fate)
16536 : : return;
16537 [ # # # # : 0 : switch (handle->fate_action) {
# ]
16538 : 0 : case MLX5_FLOW_FATE_QUEUE:
16539 [ # # # # ]: 0 : if (!handle->dvh.rix_sample && !handle->dvh.rix_dest_array)
16540 : 0 : mlx5_hrxq_release(dev, handle->rix_hrxq);
16541 : : break;
16542 : 0 : case MLX5_FLOW_FATE_JUMP:
16543 : 0 : flow_dv_jump_tbl_resource_release(dev, handle->rix_jump);
16544 : 0 : break;
16545 : 0 : case MLX5_FLOW_FATE_PORT_ID:
16546 : 0 : flow_dv_port_id_action_resource_release(dev, handle->rix_port_id_action);
16547 : 0 : break;
16548 : : case MLX5_FLOW_FATE_SEND_TO_KERNEL:
16549 : : /* In case of send_to_kernel action the actual release of
16550 : : * resource is done when all shared DR resources are released
16551 : : * since this resource is created once and always reused.
16552 : : */
16553 : : break;
16554 : 0 : default:
16555 : 0 : DRV_LOG(DEBUG, "Incorrect fate action:%d", handle->fate_action);
16556 : 0 : break;
16557 : : }
16558 : 0 : handle->rix_fate = 0;
16559 : : }
16560 : :
16561 : : void
16562 : 0 : mlx5_flow_dv_sample_remove_cb(void *tool_ctx __rte_unused,
16563 : : struct mlx5_list_entry *entry)
16564 : : {
16565 : : struct mlx5_flow_dv_sample_resource *resource = container_of(entry,
16566 : : typeof(*resource),
16567 : : entry);
16568 : 0 : struct rte_eth_dev *dev = resource->dev;
16569 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16570 : :
16571 [ # # ]: 0 : if (resource->verbs_action)
16572 : : claim_zero(mlx5_flow_os_destroy_flow_action
16573 : : (resource->verbs_action));
16574 [ # # ]: 0 : if (resource->normal_path_tbl)
16575 : 0 : mlx5_flow_dv_tbl_resource_release(MLX5_SH(dev), resource->normal_path_tbl);
16576 : 0 : flow_dv_sample_sub_actions_release(dev, &resource->sample_idx);
16577 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_SAMPLE], resource->idx);
16578 : 0 : DRV_LOG(DEBUG, "sample resource %p: removed", (void *)resource);
16579 : 0 : }
16580 : :
16581 : : /**
16582 : : * Release an sample resource.
16583 : : *
16584 : : * @param dev
16585 : : * Pointer to Ethernet device.
16586 : : * @param handle
16587 : : * Pointer to mlx5_flow_handle.
16588 : : *
16589 : : * @return
16590 : : * 1 while a reference on it exists, 0 when freed.
16591 : : */
16592 : : static int
16593 : 0 : flow_dv_sample_resource_release(struct rte_eth_dev *dev,
16594 : : struct mlx5_flow_handle *handle)
16595 : : {
16596 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16597 : : struct mlx5_flow_dv_sample_resource *resource;
16598 : :
16599 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_SAMPLE],
16600 : : handle->dvh.rix_sample);
16601 [ # # ]: 0 : if (!resource)
16602 : : return 0;
16603 : : MLX5_ASSERT(resource->verbs_action);
16604 : 0 : return mlx5_list_unregister(priv->sh->sample_action_list,
16605 : : &resource->entry);
16606 : : }
16607 : :
16608 : : void
16609 : 0 : mlx5_flow_dv_dest_array_remove_cb(void *tool_ctx __rte_unused,
16610 : : struct mlx5_list_entry *entry)
16611 : : {
16612 : : struct mlx5_flow_dv_dest_array_resource *resource =
16613 : : container_of(entry, typeof(*resource), entry);
16614 : 0 : struct rte_eth_dev *dev = resource->dev;
16615 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16616 : : uint32_t i = 0;
16617 : :
16618 : : MLX5_ASSERT(resource->action);
16619 [ # # ]: 0 : if (resource->action)
16620 : : claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
16621 [ # # ]: 0 : for (; i < resource->num_of_dest; i++)
16622 : 0 : flow_dv_sample_sub_actions_release(dev,
16623 : : &resource->sample_idx[i]);
16624 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY], resource->idx);
16625 : 0 : DRV_LOG(DEBUG, "destination array resource %p: removed",
16626 : : (void *)resource);
16627 : 0 : }
16628 : :
16629 : : /**
16630 : : * Release an destination array resource.
16631 : : *
16632 : : * @param dev
16633 : : * Pointer to Ethernet device.
16634 : : * @param handle
16635 : : * Pointer to mlx5_flow_handle.
16636 : : *
16637 : : * @return
16638 : : * 1 while a reference on it exists, 0 when freed.
16639 : : */
16640 : : static int
16641 : 0 : flow_dv_dest_array_resource_release(struct rte_eth_dev *dev,
16642 : : struct mlx5_flow_handle *handle)
16643 : : {
16644 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16645 : : struct mlx5_flow_dv_dest_array_resource *resource;
16646 : :
16647 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY],
16648 : : handle->dvh.rix_dest_array);
16649 [ # # ]: 0 : if (!resource)
16650 : : return 0;
16651 : : MLX5_ASSERT(resource->action);
16652 : 0 : return mlx5_list_unregister(priv->sh->dest_array_list,
16653 : : &resource->entry);
16654 : : }
16655 : :
16656 : : static void
16657 : 0 : flow_dev_geneve_tlv_option_resource_release(struct mlx5_dev_ctx_shared *sh)
16658 : : {
16659 : 0 : struct mlx5_geneve_tlv_option_resource *geneve_opt_resource =
16660 : : sh->geneve_tlv_option_resource;
16661 : 0 : rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
16662 [ # # ]: 0 : if (geneve_opt_resource) {
16663 [ # # ]: 0 : if (!(rte_atomic_fetch_sub_explicit(&geneve_opt_resource->refcnt, 1,
16664 : : rte_memory_order_relaxed) - 1)) {
16665 : 0 : claim_zero(mlx5_devx_cmd_destroy
16666 : : (geneve_opt_resource->obj));
16667 : 0 : mlx5_free(sh->geneve_tlv_option_resource);
16668 : 0 : sh->geneve_tlv_option_resource = NULL;
16669 : : }
16670 : : }
16671 : : rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
16672 : 0 : }
16673 : :
16674 : : /**
16675 : : * Remove the flow from the NIC but keeps it in memory.
16676 : : * Lock free, (mutex should be acquired by caller).
16677 : : *
16678 : : * @param[in] dev
16679 : : * Pointer to Ethernet device.
16680 : : * @param[in, out] flow
16681 : : * Pointer to flow structure.
16682 : : */
16683 : : static void
16684 : 0 : flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
16685 : : {
16686 : : struct mlx5_flow_handle *dh;
16687 : : uint32_t handle_idx;
16688 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16689 : :
16690 [ # # ]: 0 : if (!flow)
16691 : : return;
16692 : 0 : handle_idx = flow->dev_handles;
16693 [ # # ]: 0 : while (handle_idx) {
16694 : 0 : dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
16695 : : handle_idx);
16696 [ # # ]: 0 : if (!dh)
16697 : : return;
16698 [ # # ]: 0 : if (dh->drv_flow) {
16699 : : claim_zero(mlx5_flow_os_destroy_flow(dh->drv_flow));
16700 : 0 : dh->drv_flow = NULL;
16701 : : }
16702 [ # # ]: 0 : if (dh->fate_action == MLX5_FLOW_FATE_QUEUE)
16703 : 0 : flow_dv_fate_resource_release(dev, dh);
16704 [ # # # # ]: 0 : if (dh->vf_vlan.tag && dh->vf_vlan.created)
16705 : 0 : mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
16706 : 0 : handle_idx = dh->next.next;
16707 : : }
16708 : : }
16709 : :
16710 : : /**
16711 : : * Remove the flow from the NIC and the memory.
16712 : : * Lock free, (mutex should be acquired by caller).
16713 : : *
16714 : : * @param[in] dev
16715 : : * Pointer to the Ethernet device structure.
16716 : : * @param[in, out] flow
16717 : : * Pointer to flow structure.
16718 : : */
16719 : : static void
16720 : 0 : flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
16721 : : {
16722 : : struct mlx5_flow_handle *dev_handle;
16723 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16724 : : struct mlx5_flow_meter_info *fm = NULL;
16725 : : uint32_t srss = 0;
16726 : :
16727 [ # # ]: 0 : if (!flow)
16728 : : return;
16729 : 0 : flow_dv_remove(dev, flow);
16730 [ # # ]: 0 : if (flow->counter) {
16731 : 0 : flow_dv_counter_free(dev, flow->counter);
16732 : 0 : flow->counter = 0;
16733 : : }
16734 [ # # ]: 0 : if (flow->meter) {
16735 : 0 : fm = mlx5_flow_dv_meter_find_by_idx(priv, flow->meter);
16736 [ # # ]: 0 : if (fm)
16737 : 0 : mlx5_flow_meter_detach(priv, fm);
16738 : 0 : flow->meter = 0;
16739 : : }
16740 : : /* Keep the current age handling by default. */
16741 [ # # # # ]: 0 : if (flow->indirect_type == MLX5_INDIRECT_ACTION_TYPE_CT && flow->ct)
16742 : 0 : flow_dv_aso_ct_release(dev, flow->ct, NULL);
16743 [ # # ]: 0 : else if (flow->age)
16744 : 0 : flow_dv_aso_age_release(dev, flow->age);
16745 [ # # ]: 0 : while (flow->geneve_tlv_option) {
16746 : 0 : flow_dev_geneve_tlv_option_resource_release(priv->sh);
16747 : 0 : flow->geneve_tlv_option--;
16748 : : }
16749 [ # # ]: 0 : while (flow->dev_handles) {
16750 : : uint32_t tmp_idx = flow->dev_handles;
16751 : :
16752 : 0 : dev_handle = mlx5_ipool_get(priv->sh->ipool
16753 : : [MLX5_IPOOL_MLX5_FLOW], tmp_idx);
16754 [ # # ]: 0 : if (!dev_handle)
16755 : : return;
16756 : 0 : flow->dev_handles = dev_handle->next.next;
16757 [ # # ]: 0 : while (dev_handle->flex_item) {
16758 : 0 : int index = rte_bsf32(dev_handle->flex_item);
16759 : :
16760 : 0 : mlx5_flex_release_index(dev, index);
16761 : 0 : dev_handle->flex_item &= ~(uint8_t)RTE_BIT32(index);
16762 : : }
16763 [ # # ]: 0 : if (dev_handle->dvh.matcher)
16764 : 0 : flow_dv_matcher_release(dev, dev_handle);
16765 [ # # ]: 0 : if (dev_handle->dvh.rix_sample)
16766 : 0 : flow_dv_sample_resource_release(dev, dev_handle);
16767 [ # # ]: 0 : if (dev_handle->dvh.rix_dest_array)
16768 : 0 : flow_dv_dest_array_resource_release(dev, dev_handle);
16769 [ # # ]: 0 : if (dev_handle->dvh.rix_encap_decap)
16770 : 0 : mlx5_flow_encap_decap_resource_release(dev,
16771 : : dev_handle->dvh.rix_encap_decap);
16772 [ # # ]: 0 : if (dev_handle->dvh.modify_hdr)
16773 : : flow_dv_modify_hdr_resource_release(dev, dev_handle);
16774 [ # # ]: 0 : if (dev_handle->dvh.rix_push_vlan)
16775 : 0 : flow_dv_push_vlan_action_resource_release(dev,
16776 : : dev_handle);
16777 [ # # ]: 0 : if (dev_handle->dvh.rix_tag)
16778 : 0 : flow_dv_tag_release(dev,
16779 : : dev_handle->dvh.rix_tag);
16780 [ # # ]: 0 : if (dev_handle->fate_action != MLX5_FLOW_FATE_SHARED_RSS)
16781 : 0 : flow_dv_fate_resource_release(dev, dev_handle);
16782 [ # # ]: 0 : else if (!srss)
16783 : 0 : srss = dev_handle->rix_srss;
16784 [ # # # # ]: 0 : if (fm && dev_handle->is_meter_flow_id &&
16785 [ # # ]: 0 : dev_handle->split_flow_id)
16786 : 0 : mlx5_ipool_free(fm->flow_ipool,
16787 : : dev_handle->split_flow_id);
16788 [ # # ]: 0 : else if (dev_handle->split_flow_id &&
16789 [ # # ]: 0 : !dev_handle->is_meter_flow_id)
16790 : 0 : mlx5_ipool_free(priv->sh->ipool
16791 : : [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
16792 : : dev_handle->split_flow_id);
16793 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
16794 : : tmp_idx);
16795 : : }
16796 [ # # ]: 0 : if (srss)
16797 : 0 : flow_dv_shared_rss_action_release(dev, srss);
16798 : : }
16799 : :
16800 : : /**
16801 : : * Release array of hash RX queue objects.
16802 : : * Helper function.
16803 : : *
16804 : : * @param[in] dev
16805 : : * Pointer to the Ethernet device structure.
16806 : : * @param[in, out] hrxqs
16807 : : * Array of hash RX queue objects.
16808 : : *
16809 : : * @return
16810 : : * Total number of references to hash RX queue objects in *hrxqs* array
16811 : : * after this operation.
16812 : : */
16813 : : static int
16814 : 0 : __flow_dv_hrxqs_release(struct rte_eth_dev *dev,
16815 : : uint32_t (*hrxqs)[MLX5_RSS_HASH_IDX_MAX])
16816 : : {
16817 : : size_t i;
16818 : : int remaining = 0;
16819 : :
16820 [ # # ]: 0 : for (i = 0; i < RTE_DIM(*hrxqs); i++) {
16821 : 0 : int ret = mlx5_hrxq_release(dev, (*hrxqs)[i]);
16822 : :
16823 [ # # ]: 0 : if (!ret)
16824 : 0 : (*hrxqs)[i] = 0;
16825 : 0 : remaining += ret;
16826 : : }
16827 : 0 : return remaining;
16828 : : }
16829 : :
16830 : : /**
16831 : : * Release all hash RX queue objects representing shared RSS action.
16832 : : *
16833 : : * @param[in] dev
16834 : : * Pointer to the Ethernet device structure.
16835 : : * @param[in, out] action
16836 : : * Shared RSS action to remove hash RX queue objects from.
16837 : : *
16838 : : * @return
16839 : : * Total number of references to hash RX queue objects stored in *action*
16840 : : * after this operation.
16841 : : * Expected to be 0 if no external references held.
16842 : : */
16843 : : static int
16844 : : __flow_dv_action_rss_hrxqs_release(struct rte_eth_dev *dev,
16845 : : struct mlx5_shared_action_rss *shared_rss)
16846 : : {
16847 : 0 : return __flow_dv_hrxqs_release(dev, &shared_rss->hrxq);
16848 : : }
16849 : :
16850 : : static inline void
16851 : : filter_ipv4_types(uint64_t rss_types, uint64_t *hash_fields)
16852 : : {
16853 [ # # ]: 0 : if (rss_types & MLX5_IPV4_LAYER_TYPES) {
16854 : 0 : *hash_fields &= ~MLX5_RSS_HASH_IPV4;
16855 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
16856 : 0 : *hash_fields |= IBV_RX_HASH_DST_IPV4;
16857 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
16858 : 0 : *hash_fields |= IBV_RX_HASH_SRC_IPV4;
16859 : : else
16860 : 0 : *hash_fields |= MLX5_RSS_HASH_IPV4;
16861 : : }
16862 : : }
16863 : :
16864 : : static inline void
16865 : : filter_ipv6_types(uint64_t rss_types, uint64_t *hash_fields)
16866 : : {
16867 [ # # ]: 0 : if (rss_types & MLX5_IPV6_LAYER_TYPES) {
16868 : 0 : *hash_fields &= ~MLX5_RSS_HASH_IPV6;
16869 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
16870 : 0 : *hash_fields |= IBV_RX_HASH_DST_IPV6;
16871 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
16872 : 0 : *hash_fields |= IBV_RX_HASH_SRC_IPV6;
16873 : : else
16874 : 0 : *hash_fields |= MLX5_RSS_HASH_IPV6;
16875 : : }
16876 : : }
16877 : :
16878 : : static inline void
16879 : : filter_udp_types(uint64_t rss_types, uint64_t *hash_fields)
16880 : : {
16881 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_UDP) {
16882 : 0 : *hash_fields &= ~MLX5_UDP_IBV_RX_HASH;
16883 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
16884 : 0 : *hash_fields |= IBV_RX_HASH_DST_PORT_UDP;
16885 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
16886 : 0 : *hash_fields |= IBV_RX_HASH_SRC_PORT_UDP;
16887 : : else
16888 : 0 : *hash_fields |= MLX5_UDP_IBV_RX_HASH;
16889 : : }
16890 : : }
16891 : :
16892 : : static inline void
16893 : : filter_tcp_types(uint64_t rss_types, uint64_t *hash_fields)
16894 : : {
16895 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_TCP) {
16896 : 0 : *hash_fields &= ~MLX5_TCP_IBV_RX_HASH;
16897 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
16898 : 0 : *hash_fields |= IBV_RX_HASH_DST_PORT_TCP;
16899 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
16900 : 0 : *hash_fields |= IBV_RX_HASH_SRC_PORT_TCP;
16901 : : else
16902 : 0 : *hash_fields |= MLX5_TCP_IBV_RX_HASH;
16903 : : }
16904 : : }
16905 : :
16906 : : /**
16907 : : * Adjust L3/L4 hash value of pre-created shared RSS hrxq according to
16908 : : * user input.
16909 : : *
16910 : : * Only one hash value is available for one L3+L4 combination:
16911 : : * for example:
16912 : : * MLX5_RSS_HASH_IPV4, MLX5_RSS_HASH_IPV4_SRC_ONLY, and
16913 : : * MLX5_RSS_HASH_IPV4_DST_ONLY are mutually exclusive so they can share
16914 : : * same slot in mlx5_rss_hash_fields.
16915 : : *
16916 : : * @param[in] orig_rss_types
16917 : : * RSS type as provided in shared RSS action, specified as a bitmap of RTE_ETH_RSS_* flags.
16918 : : * @param[in, out] hash_field
16919 : : * hash_field variable needed to be adjusted, specified as a bitmap of #ibv_rx_hash_fields flags.
16920 : : *
16921 : : * @return
16922 : : * void
16923 : : */
16924 : : void
16925 : 0 : mlx5_flow_dv_action_rss_l34_hash_adjust(uint64_t orig_rss_types,
16926 : : uint64_t *hash_field)
16927 : : {
16928 [ # # ]: 0 : uint64_t hash_field_protos = *hash_field & ~IBV_RX_HASH_INNER;
16929 : : uint64_t rss_types = rte_eth_rss_hf_refine(orig_rss_types);
16930 : :
16931 [ # # ]: 0 : if (hash_field_protos & MLX5_RSS_HASH_IPV4)
16932 : : filter_ipv4_types(rss_types, hash_field);
16933 [ # # ]: 0 : else if (hash_field_protos & MLX5_RSS_HASH_IPV6)
16934 : : filter_ipv6_types(rss_types, hash_field);
16935 : :
16936 [ # # ]: 0 : if (hash_field_protos & MLX5_UDP_IBV_RX_HASH)
16937 : : filter_udp_types(rss_types, hash_field);
16938 [ # # ]: 0 : else if (hash_field_protos & MLX5_TCP_IBV_RX_HASH)
16939 : : filter_tcp_types(rss_types, hash_field);
16940 : 0 : }
16941 : :
16942 : : /**
16943 : : * Setup shared RSS action.
16944 : : * Prepare set of hash RX queue objects sufficient to handle all valid
16945 : : * hash_fields combinations (see enum ibv_rx_hash_fields).
16946 : : *
16947 : : * @param[in] dev
16948 : : * Pointer to the Ethernet device structure.
16949 : : * @param[in] action_idx
16950 : : * Shared RSS action ipool index.
16951 : : * @param[in, out] action
16952 : : * Partially initialized shared RSS action.
16953 : : * @param[out] error
16954 : : * Perform verbose error reporting if not NULL. Initialized in case of
16955 : : * error only.
16956 : : *
16957 : : * @return
16958 : : * 0 on success, otherwise negative errno value.
16959 : : */
16960 : : static int
16961 : 0 : __flow_dv_action_rss_setup(struct rte_eth_dev *dev,
16962 : : uint32_t action_idx,
16963 : : struct mlx5_shared_action_rss *shared_rss,
16964 : : struct rte_flow_error *error)
16965 : : {
16966 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16967 : 0 : struct mlx5_flow_rss_desc rss_desc = { 0 };
16968 : : size_t i;
16969 : : int err;
16970 : :
16971 : 0 : shared_rss->ind_tbl = mlx5_ind_table_obj_new
16972 : : (dev, shared_rss->origin.queue,
16973 : : shared_rss->origin.queue_num,
16974 : : true,
16975 : 0 : !!dev->data->dev_started);
16976 [ # # ]: 0 : if (!shared_rss->ind_tbl)
16977 : 0 : return rte_flow_error_set(error, rte_errno,
16978 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16979 : : "cannot setup indirection table");
16980 : 0 : memcpy(rss_desc.key, shared_rss->origin.key, MLX5_RSS_HASH_KEY_LEN);
16981 : 0 : rss_desc.key_len = MLX5_RSS_HASH_KEY_LEN;
16982 : 0 : rss_desc.symmetric_hash_function =
16983 : 0 : MLX5_RSS_IS_SYMM(shared_rss->origin.func);
16984 : 0 : rss_desc.const_q = shared_rss->origin.queue;
16985 : 0 : rss_desc.queue_num = shared_rss->origin.queue_num;
16986 : : /* Set non-zero value to indicate a shared RSS. */
16987 : 0 : rss_desc.shared_rss = action_idx;
16988 : 0 : rss_desc.ind_tbl = shared_rss->ind_tbl;
16989 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
16990 : 0 : rss_desc.hws_flags = MLX5DR_ACTION_FLAG_HWS_RX;
16991 [ # # ]: 0 : for (i = 0; i < MLX5_RSS_HASH_IDX_MAX; i++) {
16992 : : struct mlx5_hrxq *hrxq;
16993 : 0 : uint64_t hash_fields = mlx5_rss_hash_fields[i];
16994 : : int tunnel = 0;
16995 : :
16996 : 0 : mlx5_flow_dv_action_rss_l34_hash_adjust(shared_rss->origin.types,
16997 : : &hash_fields);
16998 [ # # ]: 0 : if (shared_rss->origin.level > 1) {
16999 : 0 : hash_fields |= IBV_RX_HASH_INNER;
17000 : : tunnel = 1;
17001 : : }
17002 : 0 : rss_desc.tunnel = tunnel;
17003 : 0 : rss_desc.hash_fields = hash_fields;
17004 : 0 : hrxq = mlx5_hrxq_get(dev, &rss_desc);
17005 [ # # ]: 0 : if (!hrxq) {
17006 : 0 : rte_flow_error_set
17007 : : (error, rte_errno,
17008 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
17009 : : "cannot get hash queue");
17010 : 0 : goto error_hrxq_new;
17011 : : }
17012 : 0 : err = __flow_dv_action_rss_hrxq_set
17013 : : (shared_rss, hash_fields, hrxq->idx);
17014 : : MLX5_ASSERT(!err);
17015 : : }
17016 : : return 0;
17017 : : error_hrxq_new:
17018 : 0 : err = rte_errno;
17019 : : __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
17020 [ # # ]: 0 : if (!mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl, true))
17021 : 0 : shared_rss->ind_tbl = NULL;
17022 : 0 : rte_errno = err;
17023 : 0 : return -rte_errno;
17024 : : }
17025 : :
17026 : : /**
17027 : : * Create shared RSS action.
17028 : : *
17029 : : * @param[in] dev
17030 : : * Pointer to the Ethernet device structure.
17031 : : * @param[in] conf
17032 : : * Shared action configuration.
17033 : : * @param[in] rss
17034 : : * RSS action specification used to create shared action.
17035 : : * @param[out] error
17036 : : * Perform verbose error reporting if not NULL. Initialized in case of
17037 : : * error only.
17038 : : *
17039 : : * @return
17040 : : * A valid shared action ID in case of success, 0 otherwise and
17041 : : * rte_errno is set.
17042 : : */
17043 : : static uint32_t
17044 : 0 : __flow_dv_action_rss_create(struct rte_eth_dev *dev,
17045 : : const struct rte_flow_indir_action_conf *conf,
17046 : : const struct rte_flow_action_rss *rss,
17047 : : struct rte_flow_error *error)
17048 : : {
17049 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17050 : : struct mlx5_shared_action_rss *shared_rss = NULL;
17051 : : struct rte_flow_action_rss *origin;
17052 : : const uint8_t *rss_key;
17053 : : uint32_t idx;
17054 : :
17055 : : RTE_SET_USED(conf);
17056 : 0 : shared_rss = mlx5_ipool_zmalloc
17057 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], &idx);
17058 [ # # ]: 0 : if (!shared_rss) {
17059 : 0 : rte_flow_error_set(error, ENOMEM,
17060 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
17061 : : "cannot allocate resource memory");
17062 : 0 : goto error_rss_init;
17063 : : }
17064 [ # # ]: 0 : if (idx > (1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET)) {
17065 : 0 : rte_flow_error_set(error, E2BIG,
17066 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
17067 : : "rss action number out of range");
17068 : 0 : goto error_rss_init;
17069 : : }
17070 : : origin = &shared_rss->origin;
17071 : 0 : origin->func = rss->func;
17072 : 0 : origin->level = rss->level;
17073 : : /* RSS type 0 indicates default RSS type (RTE_ETH_RSS_IP). */
17074 [ # # ]: 0 : origin->types = !rss->types ? RTE_ETH_RSS_IP : rss->types;
17075 : : /* NULL RSS key indicates default RSS key. */
17076 [ # # ]: 0 : rss_key = !rss->key ? mlx5_rss_hash_default_key : rss->key;
17077 : 0 : memcpy(shared_rss->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
17078 : 0 : origin->key = &shared_rss->key[0];
17079 : 0 : origin->key_len = MLX5_RSS_HASH_KEY_LEN;
17080 : 0 : origin->queue = rss->queue;
17081 : 0 : origin->queue_num = rss->queue_num;
17082 [ # # ]: 0 : if (__flow_dv_action_rss_setup(dev, idx, shared_rss, error))
17083 : 0 : goto error_rss_init;
17084 : : /* Update queue with indirect table queue memoyr. */
17085 : 0 : origin->queue = shared_rss->ind_tbl->queues;
17086 : : rte_spinlock_init(&shared_rss->action_rss_sl);
17087 : 0 : rte_atomic_fetch_add_explicit(&shared_rss->refcnt, 1, rte_memory_order_relaxed);
17088 : 0 : rte_spinlock_lock(&priv->shared_act_sl);
17089 [ # # # # ]: 0 : ILIST_INSERT(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
17090 : : &priv->rss_shared_actions, idx, shared_rss, next);
17091 : : rte_spinlock_unlock(&priv->shared_act_sl);
17092 : 0 : return idx;
17093 : 0 : error_rss_init:
17094 [ # # ]: 0 : if (shared_rss) {
17095 [ # # ]: 0 : if (shared_rss->ind_tbl)
17096 : 0 : mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl,
17097 : 0 : !!dev->data->dev_started);
17098 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
17099 : : idx);
17100 : : }
17101 : : return 0;
17102 : : }
17103 : :
17104 : : /**
17105 : : * Destroy the shared RSS action.
17106 : : * Release related hash RX queue objects.
17107 : : *
17108 : : * @param[in] dev
17109 : : * Pointer to the Ethernet device structure.
17110 : : * @param[in] idx
17111 : : * The shared RSS action object ID to be removed.
17112 : : * @param[out] error
17113 : : * Perform verbose error reporting if not NULL. Initialized in case of
17114 : : * error only.
17115 : : *
17116 : : * @return
17117 : : * 0 on success, otherwise negative errno value.
17118 : : */
17119 : : static int
17120 : 0 : __flow_dv_action_rss_release(struct rte_eth_dev *dev, uint32_t idx,
17121 : : struct rte_flow_error *error)
17122 : : {
17123 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17124 : : struct mlx5_shared_action_rss *shared_rss =
17125 : 0 : mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
17126 : : uint32_t old_refcnt = 1;
17127 : : int remaining;
17128 : :
17129 [ # # ]: 0 : if (!shared_rss)
17130 : 0 : return rte_flow_error_set(error, EINVAL,
17131 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
17132 : : "invalid shared action");
17133 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(&shared_rss->refcnt, &old_refcnt,
17134 : : 0, rte_memory_order_acquire,
17135 : : rte_memory_order_relaxed))
17136 : 0 : return rte_flow_error_set(error, EBUSY,
17137 : : RTE_FLOW_ERROR_TYPE_ACTION,
17138 : : NULL,
17139 : : "shared rss has references");
17140 : : remaining = __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
17141 [ # # ]: 0 : if (remaining)
17142 : 0 : return rte_flow_error_set(error, EBUSY,
17143 : : RTE_FLOW_ERROR_TYPE_ACTION,
17144 : : NULL,
17145 : : "shared rss hrxq has references");
17146 : 0 : remaining = mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl,
17147 : 0 : !!dev->data->dev_started);
17148 [ # # ]: 0 : if (remaining)
17149 : 0 : return rte_flow_error_set(error, EBUSY,
17150 : : RTE_FLOW_ERROR_TYPE_ACTION,
17151 : : NULL,
17152 : : "shared rss indirection table has"
17153 : : " references");
17154 : 0 : rte_spinlock_lock(&priv->shared_act_sl);
17155 [ # # # # : 0 : ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
# # # # #
# ]
17156 : : &priv->rss_shared_actions, idx, shared_rss, next);
17157 : : rte_spinlock_unlock(&priv->shared_act_sl);
17158 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
17159 : : idx);
17160 : 0 : return 0;
17161 : : }
17162 : :
17163 : : /**
17164 : : * Create indirect action, lock free,
17165 : : * (mutex should be acquired by caller).
17166 : : * Dispatcher for action type specific call.
17167 : : *
17168 : : * @param[in] dev
17169 : : * Pointer to the Ethernet device structure.
17170 : : * @param[in] conf
17171 : : * Shared action configuration.
17172 : : * @param[in] action
17173 : : * Action specification used to create indirect action.
17174 : : * @param[out] error
17175 : : * Perform verbose error reporting if not NULL. Initialized in case of
17176 : : * error only.
17177 : : *
17178 : : * @return
17179 : : * A valid shared action handle in case of success, NULL otherwise and
17180 : : * rte_errno is set.
17181 : : */
17182 : : struct rte_flow_action_handle *
17183 : 0 : mlx5_flow_dv_action_create(struct rte_eth_dev *dev,
17184 : : const struct rte_flow_indir_action_conf *conf,
17185 : : const struct rte_flow_action *action,
17186 : : struct rte_flow_error *err)
17187 : : {
17188 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17189 : : uint32_t age_idx = 0;
17190 : : uint32_t idx = 0;
17191 : : uint32_t ret = 0;
17192 : :
17193 [ # # # # : 0 : switch (action->type) {
# ]
17194 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
17195 : 0 : ret = __flow_dv_action_rss_create(dev, conf, action->conf, err);
17196 : : idx = (MLX5_INDIRECT_ACTION_TYPE_RSS <<
17197 : : MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
17198 : 0 : break;
17199 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
17200 : 0 : age_idx = flow_dv_aso_age_alloc(dev, err);
17201 [ # # ]: 0 : if (!age_idx) {
17202 : 0 : ret = -rte_errno;
17203 : 0 : break;
17204 : : }
17205 : 0 : idx = (MLX5_INDIRECT_ACTION_TYPE_AGE <<
17206 : : MLX5_INDIRECT_ACTION_TYPE_OFFSET) | age_idx;
17207 : 0 : flow_dv_aso_age_params_init(dev, age_idx,
17208 : : ((const struct rte_flow_action_age *)
17209 : 0 : action->conf)->context ?
17210 : : ((const struct rte_flow_action_age *)
17211 : : action->conf)->context :
17212 : 0 : (void *)(uintptr_t)idx,
17213 : : ((const struct rte_flow_action_age *)
17214 [ # # ]: 0 : action->conf)->timeout);
17215 : : ret = age_idx;
17216 : 0 : break;
17217 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
17218 : 0 : ret = flow_dv_translate_create_counter(dev, NULL, NULL, NULL);
17219 : 0 : idx = (MLX5_INDIRECT_ACTION_TYPE_COUNT <<
17220 : : MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
17221 : 0 : break;
17222 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
17223 : 0 : ret = flow_dv_translate_create_conntrack(dev, action->conf,
17224 : : err);
17225 [ # # ]: 0 : if (!ret)
17226 : : break;
17227 : 0 : idx = MLX5_INDIRECT_ACT_CT_GEN_IDX(PORT_ID(priv), ret);
17228 : 0 : break;
17229 : 0 : default:
17230 : 0 : rte_flow_error_set(err, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
17231 : : NULL, "action type not supported");
17232 : : break;
17233 : : }
17234 [ # # ]: 0 : return ret ? (struct rte_flow_action_handle *)(uintptr_t)idx : NULL;
17235 : : }
17236 : :
17237 : : /**
17238 : : * Destroy the indirect action.
17239 : : * Release action related resources on the NIC and the memory.
17240 : : * Lock free, (mutex should be acquired by caller).
17241 : : * Dispatcher for action type specific call.
17242 : : *
17243 : : * @param[in] dev
17244 : : * Pointer to the Ethernet device structure.
17245 : : * @param[in] handle
17246 : : * The indirect action object handle to be removed.
17247 : : * @param[out] error
17248 : : * Perform verbose error reporting if not NULL. Initialized in case of
17249 : : * error only.
17250 : : *
17251 : : * @return
17252 : : * 0 on success, otherwise negative errno value.
17253 : : */
17254 : : int
17255 : 0 : mlx5_flow_dv_action_destroy(struct rte_eth_dev *dev,
17256 : : struct rte_flow_action_handle *handle,
17257 : : struct rte_flow_error *error)
17258 : : {
17259 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
17260 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
17261 : 0 : uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
17262 : : struct mlx5_flow_counter *cnt;
17263 : : uint32_t no_flow_refcnt = 1;
17264 : : int ret;
17265 : :
17266 [ # # # # : 0 : switch (type) {
# ]
17267 : 0 : case MLX5_INDIRECT_ACTION_TYPE_RSS:
17268 : 0 : return __flow_dv_action_rss_release(dev, idx, error);
17269 : : case MLX5_INDIRECT_ACTION_TYPE_COUNT:
17270 : : cnt = flow_dv_counter_get_by_idx(dev, idx, NULL);
17271 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(&cnt->shared_info.refcnt,
17272 : : &no_flow_refcnt, 1,
17273 : : rte_memory_order_acquire,
17274 : : rte_memory_order_relaxed))
17275 : 0 : return rte_flow_error_set(error, EBUSY,
17276 : : RTE_FLOW_ERROR_TYPE_ACTION,
17277 : : NULL,
17278 : : "Indirect count action has references");
17279 : 0 : flow_dv_counter_free(dev, idx);
17280 : 0 : return 0;
17281 : 0 : case MLX5_INDIRECT_ACTION_TYPE_AGE:
17282 : 0 : ret = flow_dv_aso_age_release(dev, idx);
17283 [ # # ]: 0 : if (ret)
17284 : : /*
17285 : : * In this case, the last flow has a reference will
17286 : : * actually release the age action.
17287 : : */
17288 : 0 : DRV_LOG(DEBUG, "Indirect age action %" PRIu32 " was"
17289 : : " released with references %d.", idx, ret);
17290 : : return 0;
17291 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
17292 : 0 : ret = flow_dv_aso_ct_release(dev, idx, error);
17293 [ # # ]: 0 : if (ret < 0)
17294 : : return ret;
17295 [ # # ]: 0 : if (ret > 0)
17296 : 0 : DRV_LOG(DEBUG, "Connection tracking object %u still "
17297 : : "has references %d.", idx, ret);
17298 : : return 0;
17299 : 0 : default:
17300 : 0 : return rte_flow_error_set(error, ENOTSUP,
17301 : : RTE_FLOW_ERROR_TYPE_ACTION,
17302 : : NULL,
17303 : : "action type not supported");
17304 : : }
17305 : : }
17306 : :
17307 : : /**
17308 : : * Updates in place shared RSS action configuration.
17309 : : *
17310 : : * @param[in] dev
17311 : : * Pointer to the Ethernet device structure.
17312 : : * @param[in] idx
17313 : : * The shared RSS action object ID to be updated.
17314 : : * @param[in] action_conf
17315 : : * RSS action specification used to modify *shared_rss*.
17316 : : * @param[out] error
17317 : : * Perform verbose error reporting if not NULL. Initialized in case of
17318 : : * error only.
17319 : : *
17320 : : * @return
17321 : : * 0 on success, otherwise negative errno value.
17322 : : * @note: currently only support update of RSS queues.
17323 : : */
17324 : : static int
17325 : 0 : __flow_dv_action_rss_update(struct rte_eth_dev *dev, uint32_t idx,
17326 : : const struct rte_flow_action_rss *action_conf,
17327 : : struct rte_flow_error *error)
17328 : : {
17329 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17330 : : struct mlx5_shared_action_rss *shared_rss =
17331 : 0 : mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
17332 : : int ret = 0;
17333 : : void *queue = NULL;
17334 : : void *queue_i = NULL;
17335 : 0 : uint32_t queue_size = action_conf->queue_num * sizeof(uint16_t);
17336 : 0 : bool dev_started = !!dev->data->dev_started;
17337 : :
17338 [ # # ]: 0 : if (!shared_rss)
17339 : 0 : return rte_flow_error_set(error, EINVAL,
17340 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
17341 : : "invalid shared action to update");
17342 [ # # ]: 0 : if (priv->obj_ops.ind_table_modify == NULL)
17343 : 0 : return rte_flow_error_set(error, ENOTSUP,
17344 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
17345 : : "cannot modify indirection table");
17346 : 0 : queue = mlx5_malloc(MLX5_MEM_ZERO,
17347 : 0 : RTE_ALIGN_CEIL(queue_size, sizeof(void *)),
17348 : : 0, SOCKET_ID_ANY);
17349 [ # # ]: 0 : if (!queue)
17350 : 0 : return rte_flow_error_set(error, ENOMEM,
17351 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17352 : : NULL,
17353 : : "cannot allocate resource memory");
17354 : 0 : memcpy(queue, action_conf->queue, queue_size);
17355 : : MLX5_ASSERT(shared_rss->ind_tbl);
17356 : 0 : rte_spinlock_lock(&shared_rss->action_rss_sl);
17357 : 0 : queue_i = shared_rss->ind_tbl->queues;
17358 : 0 : ret = mlx5_ind_table_obj_modify(dev, shared_rss->ind_tbl,
17359 : 0 : queue, action_conf->queue_num,
17360 : : true /* standalone */,
17361 : : dev_started /* ref_new_qs */,
17362 : : dev_started /* deref_old_qs */);
17363 [ # # ]: 0 : if (ret) {
17364 : 0 : ret = rte_flow_error_set(error, rte_errno,
17365 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
17366 : : "cannot update indirection table");
17367 : : } else {
17368 : : /* Restore the queue to indirect table internal queue. */
17369 : : memcpy(queue_i, queue, queue_size);
17370 : 0 : shared_rss->ind_tbl->queues = queue_i;
17371 : 0 : shared_rss->origin.queue_num = action_conf->queue_num;
17372 : : }
17373 : 0 : mlx5_free(queue);
17374 : : rte_spinlock_unlock(&shared_rss->action_rss_sl);
17375 : 0 : return ret;
17376 : : }
17377 : :
17378 : : /*
17379 : : * Updates in place conntrack context or direction.
17380 : : * Context update should be synchronized.
17381 : : *
17382 : : * @param[in] dev
17383 : : * Pointer to the Ethernet device structure.
17384 : : * @param[in] idx
17385 : : * The conntrack object ID to be updated.
17386 : : * @param[in] update
17387 : : * Pointer to the structure of information to update.
17388 : : * @param[out] error
17389 : : * Perform verbose error reporting if not NULL. Initialized in case of
17390 : : * error only.
17391 : : *
17392 : : * @return
17393 : : * 0 on success, otherwise negative errno value.
17394 : : */
17395 : : static int
17396 : 0 : __flow_dv_action_ct_update(struct rte_eth_dev *dev, uint32_t idx,
17397 : : const struct rte_flow_modify_conntrack *update,
17398 : : struct rte_flow_error *error)
17399 : : {
17400 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17401 : : struct mlx5_aso_ct_action *ct;
17402 : : const struct rte_flow_action_conntrack *new_prf;
17403 : : int ret = 0;
17404 : 0 : uint16_t owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(idx);
17405 : : uint32_t dev_idx;
17406 : :
17407 [ # # ]: 0 : if (PORT_ID(priv) != owner)
17408 : 0 : return rte_flow_error_set(error, EACCES,
17409 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17410 : : NULL,
17411 : : "CT object owned by another port");
17412 : 0 : dev_idx = MLX5_INDIRECT_ACT_CT_GET_IDX(idx);
17413 : 0 : ct = flow_aso_ct_get_by_dev_idx(dev, dev_idx);
17414 [ # # ]: 0 : if (!ct->refcnt)
17415 : 0 : return rte_flow_error_set(error, ENOMEM,
17416 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17417 : : NULL,
17418 : : "CT object is inactive");
17419 : 0 : new_prf = &update->new_ct;
17420 [ # # ]: 0 : if (update->direction)
17421 : 0 : ct->is_original = !!new_prf->is_original_dir;
17422 [ # # ]: 0 : if (update->state) {
17423 : : /* Only validate the profile when it needs to be updated. */
17424 : 0 : ret = mlx5_validate_action_ct(dev, new_prf, error);
17425 [ # # ]: 0 : if (ret)
17426 : : return ret;
17427 : 0 : ret = mlx5_aso_ct_update_by_wqe(priv->sh, MLX5_HW_INV_QUEUE,
17428 : : ct, new_prf, NULL, true);
17429 [ # # ]: 0 : if (ret)
17430 : 0 : return rte_flow_error_set(error, EIO,
17431 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17432 : : NULL,
17433 : : "Failed to send CT context update WQE");
17434 : : /* Block until ready or a failure, default is asynchronous. */
17435 : 0 : ret = mlx5_aso_ct_available(priv->sh, MLX5_HW_INV_QUEUE, ct);
17436 [ # # ]: 0 : if (ret)
17437 : 0 : rte_flow_error_set(error, rte_errno,
17438 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17439 : : NULL,
17440 : : "Timeout to get the CT update");
17441 : : }
17442 : : return ret;
17443 : : }
17444 : :
17445 : : /**
17446 : : * Updates in place shared action configuration, lock free,
17447 : : * (mutex should be acquired by caller).
17448 : : *
17449 : : * @param[in] dev
17450 : : * Pointer to the Ethernet device structure.
17451 : : * @param[in] handle
17452 : : * The indirect action object handle to be updated.
17453 : : * @param[in] update
17454 : : * Action specification used to modify the action pointed by *handle*.
17455 : : * *update* could be of same type with the action pointed by the *handle*
17456 : : * handle argument, or some other structures like a wrapper, depending on
17457 : : * the indirect action type.
17458 : : * @param[out] error
17459 : : * Perform verbose error reporting if not NULL. Initialized in case of
17460 : : * error only.
17461 : : *
17462 : : * @return
17463 : : * 0 on success, otherwise negative errno value.
17464 : : */
17465 : : int
17466 : 0 : mlx5_flow_dv_action_update(struct rte_eth_dev *dev,
17467 : : struct rte_flow_action_handle *handle,
17468 : : const void *update,
17469 : : struct rte_flow_error *err)
17470 : : {
17471 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
17472 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
17473 : 0 : uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
17474 : : const void *action_conf;
17475 : :
17476 [ # # # ]: 0 : switch (type) {
17477 : 0 : case MLX5_INDIRECT_ACTION_TYPE_RSS:
17478 : 0 : action_conf = ((const struct rte_flow_action *)update)->conf;
17479 : 0 : return __flow_dv_action_rss_update(dev, idx, action_conf, err);
17480 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
17481 : 0 : return __flow_dv_action_ct_update(dev, idx, update, err);
17482 : 0 : default:
17483 : 0 : return rte_flow_error_set(err, ENOTSUP,
17484 : : RTE_FLOW_ERROR_TYPE_ACTION,
17485 : : NULL,
17486 : : "action type update not supported");
17487 : : }
17488 : : }
17489 : :
17490 : : /**
17491 : : * Destroy the meter sub policy table rules.
17492 : : * Lock free, (mutex should be acquired by caller).
17493 : : *
17494 : : * @param[in] dev
17495 : : * Pointer to Ethernet device.
17496 : : * @param[in] sub_policy
17497 : : * Pointer to meter sub policy table.
17498 : : */
17499 : : static void
17500 : 0 : __flow_dv_destroy_sub_policy_rules(struct rte_eth_dev *dev,
17501 : : struct mlx5_flow_meter_sub_policy *sub_policy)
17502 : : {
17503 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17504 : : struct mlx5_flow_tbl_data_entry *tbl;
17505 : 0 : struct mlx5_flow_meter_policy *policy = sub_policy->main_policy;
17506 : : struct mlx5_flow_meter_info *next_fm;
17507 : : struct mlx5_sub_policy_color_rule *color_rule;
17508 : : void *tmp;
17509 : : uint32_t i;
17510 : :
17511 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
17512 : : next_fm = NULL;
17513 [ # # ]: 0 : if (i <= RTE_COLOR_YELLOW && policy &&
17514 [ # # ]: 0 : policy->act_cnt[i].fate_action == MLX5_FLOW_FATE_MTR)
17515 : 0 : next_fm = mlx5_flow_meter_find(priv,
17516 : : policy->act_cnt[i].next_mtr_id, NULL);
17517 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(color_rule, &sub_policy->color_rules[i],
17518 : : next_port, tmp) {
17519 : 0 : claim_zero(mlx5_flow_os_destroy_flow(color_rule->rule));
17520 : 0 : tbl = container_of(color_rule->matcher->tbl,
17521 : : typeof(*tbl), tbl);
17522 : 0 : mlx5_list_unregister(tbl->matchers,
17523 : : &color_rule->matcher->entry);
17524 [ # # ]: 0 : TAILQ_REMOVE(&sub_policy->color_rules[i],
17525 : : color_rule, next_port);
17526 : 0 : mlx5_free(color_rule);
17527 [ # # ]: 0 : if (next_fm)
17528 : 0 : mlx5_flow_meter_detach(priv, next_fm);
17529 : : }
17530 : : }
17531 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
17532 [ # # ]: 0 : if (sub_policy->rix_hrxq[i]) {
17533 [ # # # # ]: 0 : if (policy && !policy->is_hierarchy)
17534 : 0 : mlx5_hrxq_release(dev, sub_policy->rix_hrxq[i]);
17535 : 0 : sub_policy->rix_hrxq[i] = 0;
17536 : : }
17537 [ # # ]: 0 : if (sub_policy->jump_tbl[i]) {
17538 : 0 : mlx5_flow_dv_tbl_resource_release(MLX5_SH(dev), sub_policy->jump_tbl[i]);
17539 : 0 : sub_policy->jump_tbl[i] = NULL;
17540 : : }
17541 : : }
17542 [ # # ]: 0 : if (sub_policy->tbl_rsc) {
17543 : 0 : mlx5_flow_dv_tbl_resource_release(MLX5_SH(dev), sub_policy->tbl_rsc);
17544 : 0 : sub_policy->tbl_rsc = NULL;
17545 : : }
17546 : 0 : }
17547 : :
17548 : : /**
17549 : : * Destroy policy rules, lock free,
17550 : : * (mutex should be acquired by caller).
17551 : : * Dispatcher for action type specific call.
17552 : : *
17553 : : * @param[in] dev
17554 : : * Pointer to the Ethernet device structure.
17555 : : * @param[in] mtr_policy
17556 : : * Meter policy struct.
17557 : : */
17558 : : static void
17559 : 0 : flow_dv_destroy_policy_rules(struct rte_eth_dev *dev,
17560 : : struct mlx5_flow_meter_policy *mtr_policy)
17561 : : {
17562 : : uint32_t i, j;
17563 : : struct mlx5_flow_meter_sub_policy *sub_policy;
17564 : : uint16_t sub_policy_num;
17565 : :
17566 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
17567 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
17568 : 0 : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
17569 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
17570 [ # # ]: 0 : for (j = 0; j < sub_policy_num; j++) {
17571 : 0 : sub_policy = mtr_policy->sub_policys[i][j];
17572 [ # # ]: 0 : if (sub_policy)
17573 : 0 : __flow_dv_destroy_sub_policy_rules(dev,
17574 : : sub_policy);
17575 : : }
17576 : : }
17577 : 0 : }
17578 : :
17579 : : /**
17580 : : * Destroy policy action, lock free,
17581 : : * (mutex should be acquired by caller).
17582 : : * Dispatcher for action type specific call.
17583 : : *
17584 : : * @param[in] dev
17585 : : * Pointer to the Ethernet device structure.
17586 : : * @param[in] mtr_policy
17587 : : * Meter policy struct.
17588 : : */
17589 : : static void
17590 : 0 : flow_dv_destroy_mtr_policy_acts(struct rte_eth_dev *dev,
17591 : : struct mlx5_flow_meter_policy *mtr_policy)
17592 : : {
17593 : : struct rte_flow_action *rss_action;
17594 : : struct mlx5_flow_handle dev_handle;
17595 : : uint32_t i, j;
17596 : :
17597 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
17598 [ # # ]: 0 : if (mtr_policy->act_cnt[i].rix_mark) {
17599 : 0 : flow_dv_tag_release(dev,
17600 : : mtr_policy->act_cnt[i].rix_mark);
17601 : 0 : mtr_policy->act_cnt[i].rix_mark = 0;
17602 : : }
17603 [ # # ]: 0 : if (mtr_policy->act_cnt[i].modify_hdr) {
17604 : : dev_handle.dvh.modify_hdr =
17605 : : mtr_policy->act_cnt[i].modify_hdr;
17606 : : flow_dv_modify_hdr_resource_release(dev, &dev_handle);
17607 : : }
17608 [ # # # # ]: 0 : switch (mtr_policy->act_cnt[i].fate_action) {
17609 : 0 : case MLX5_FLOW_FATE_SHARED_RSS:
17610 : 0 : rss_action = mtr_policy->act_cnt[i].rss;
17611 : 0 : mlx5_free(rss_action);
17612 : 0 : break;
17613 : 0 : case MLX5_FLOW_FATE_PORT_ID:
17614 [ # # ]: 0 : if (mtr_policy->act_cnt[i].rix_port_id_action) {
17615 : 0 : flow_dv_port_id_action_resource_release(dev,
17616 : : mtr_policy->act_cnt[i].rix_port_id_action);
17617 : 0 : mtr_policy->act_cnt[i].rix_port_id_action = 0;
17618 : : }
17619 : : break;
17620 : : case MLX5_FLOW_FATE_DROP:
17621 : : case MLX5_FLOW_FATE_JUMP:
17622 [ # # ]: 0 : for (j = 0; j < MLX5_MTR_DOMAIN_MAX; j++)
17623 : 0 : mtr_policy->act_cnt[i].dr_jump_action[j] =
17624 : : NULL;
17625 : : break;
17626 : : default:
17627 : : /*Queue action do nothing*/
17628 : : break;
17629 : : }
17630 : : }
17631 [ # # ]: 0 : for (j = 0; j < MLX5_MTR_DOMAIN_MAX; j++)
17632 : 0 : mtr_policy->dr_drop_action[j] = NULL;
17633 : 0 : }
17634 : :
17635 : : /**
17636 : : * Create yellow action for color aware meter.
17637 : : *
17638 : : * @param[in] dev
17639 : : * Pointer to the Ethernet device structure.
17640 : : * @param[in] fm
17641 : : * Meter information table.
17642 : : * @param[out] error
17643 : : * Perform verbose error reporting if not NULL. Initialized in case of
17644 : : * error only.
17645 : : *
17646 : : * @return
17647 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
17648 : : */
17649 : : static int
17650 : 0 : __flow_dv_create_mtr_yellow_action(struct rte_eth_dev *dev,
17651 : : struct mlx5_flow_meter_info *fm,
17652 : : struct rte_mtr_error *error)
17653 : : {
17654 : : #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
17655 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17656 : : struct rte_flow_error flow_err;
17657 : : struct mlx5_aso_mtr *aso_mtr;
17658 : : struct mlx5_aso_mtr_pool *pool;
17659 : : uint8_t reg_id;
17660 : :
17661 : 0 : aso_mtr = container_of(fm, struct mlx5_aso_mtr, fm);
17662 : 0 : pool = container_of(aso_mtr, struct mlx5_aso_mtr_pool, mtrs[aso_mtr->offset]);
17663 : 0 : reg_id = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &flow_err);
17664 : 0 : fm->meter_action_y =
17665 : 0 : mlx5_glue->dv_create_flow_action_aso(priv->sh->rx_domain,
17666 : 0 : pool->devx_obj->obj,
17667 : : aso_mtr->offset,
17668 : : (1 << MLX5_FLOW_COLOR_YELLOW),
17669 : 0 : reg_id - REG_C_0);
17670 : : #else
17671 : : RTE_SET_USED(dev);
17672 : : #endif
17673 [ # # ]: 0 : if (!fm->meter_action_y) {
17674 : 0 : return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
17675 : : "Fail to create yellow meter action.");
17676 : : }
17677 : : return 0;
17678 : : }
17679 : :
17680 : : /**
17681 : : * Create policy action per domain, lock free,
17682 : : * (mutex should be acquired by caller).
17683 : : * Dispatcher for action type specific call.
17684 : : *
17685 : : * @param[in] dev
17686 : : * Pointer to the Ethernet device structure.
17687 : : * @param[in] mtr_policy
17688 : : * Meter policy struct.
17689 : : * @param[in] action
17690 : : * Action specification used to create meter actions.
17691 : : * @param[in] attr
17692 : : * Pointer to the flow attributes.
17693 : : * @param[out] error
17694 : : * Perform verbose error reporting if not NULL. Initialized in case of
17695 : : * error only.
17696 : : *
17697 : : * @return
17698 : : * 0 on success, otherwise negative errno value.
17699 : : */
17700 : : static int
17701 : 0 : __flow_dv_create_domain_policy_acts(struct rte_eth_dev *dev,
17702 : : struct mlx5_flow_meter_policy *mtr_policy,
17703 : : const struct rte_flow_action *actions[RTE_COLORS],
17704 : : struct rte_flow_attr *attr,
17705 : : enum mlx5_meter_domain domain,
17706 : : struct rte_mtr_error *error)
17707 : : {
17708 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17709 : : struct rte_flow_error flow_err;
17710 : : const struct rte_flow_action *act;
17711 : : uint64_t action_flags;
17712 : : struct mlx5_flow_handle dh;
17713 : : struct mlx5_flow dev_flow;
17714 : : struct mlx5_flow_dv_port_id_action_resource port_id_action;
17715 : : int i, ret;
17716 : : uint8_t egress, transfer;
17717 : : struct mlx5_meter_policy_action_container *act_cnt = NULL;
17718 : : union {
17719 : : struct mlx5_flow_dv_modify_hdr_resource res;
17720 : : uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
17721 : : sizeof(struct mlx5_modification_cmd) *
17722 : : (MLX5_MAX_MODIFY_NUM + 1)];
17723 : : } mhdr_dummy;
17724 : : struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
17725 : :
17726 : 0 : egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
17727 [ # # ]: 0 : transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
17728 : : memset(&dh, 0, sizeof(struct mlx5_flow_handle));
17729 : : memset(&dev_flow, 0, sizeof(struct mlx5_flow));
17730 : : memset(&port_id_action, 0,
17731 : : sizeof(struct mlx5_flow_dv_port_id_action_resource));
17732 : : memset(mhdr_res, 0, sizeof(*mhdr_res));
17733 [ # # ]: 0 : mhdr_res->ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
17734 : : (egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
17735 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX);
17736 : 0 : dev_flow.handle = &dh;
17737 : 0 : dev_flow.dv.port_id_action = &port_id_action;
17738 : 0 : dev_flow.external = true;
17739 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
17740 [ # # ]: 0 : if (i < MLX5_MTR_RTE_COLORS)
17741 : 0 : act_cnt = &mtr_policy->act_cnt[i];
17742 : : /* Skip the color policy actions creation. */
17743 [ # # # # : 0 : if ((i == RTE_COLOR_YELLOW && mtr_policy->skip_y) ||
# # ]
17744 [ # # ]: 0 : (i == RTE_COLOR_GREEN && mtr_policy->skip_g))
17745 : 0 : continue;
17746 : : action_flags = 0;
17747 : 0 : for (act = actions[i];
17748 [ # # # # ]: 0 : act && act->type != RTE_FLOW_ACTION_TYPE_END; act++) {
17749 [ # # # # : 0 : switch (act->type) {
# # # # #
# ]
17750 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
17751 : : {
17752 : : uint32_t tag_be = mlx5_flow_mark_set
17753 : : (((const struct rte_flow_action_mark *)
17754 [ # # ]: 0 : (act->conf))->id);
17755 : :
17756 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17757 : 0 : return -rte_mtr_error_set(error,
17758 : : ENOTSUP,
17759 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17760 : : NULL,
17761 : : "cannot create policy "
17762 : : "mark action for this color");
17763 [ # # ]: 0 : if (flow_dv_tag_resource_register(dev, tag_be,
17764 : : &dev_flow, &flow_err))
17765 : 0 : return -rte_mtr_error_set(error,
17766 : : ENOTSUP,
17767 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17768 : : NULL,
17769 : : "cannot setup policy mark action");
17770 : : MLX5_ASSERT(dev_flow.dv.tag_resource);
17771 : 0 : act_cnt->rix_mark =
17772 : 0 : dev_flow.handle->dvh.rix_tag;
17773 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK;
17774 : 0 : mtr_policy->mark = 1;
17775 : 0 : break;
17776 : : }
17777 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TAG:
17778 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17779 : 0 : return -rte_mtr_error_set(error,
17780 : : ENOTSUP,
17781 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17782 : : NULL,
17783 : : "cannot create policy "
17784 : : "set tag action for this color");
17785 [ # # ]: 0 : if (flow_dv_convert_action_set_tag
17786 : : (dev, mhdr_res,
17787 : : (const struct rte_flow_action_set_tag *)
17788 : 0 : act->conf, &flow_err))
17789 : 0 : return -rte_mtr_error_set(error,
17790 : : ENOTSUP,
17791 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17792 : : NULL, "cannot convert policy "
17793 : : "set tag action");
17794 [ # # ]: 0 : if (!mhdr_res->actions_num)
17795 : 0 : return -rte_mtr_error_set(error,
17796 : : ENOTSUP,
17797 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17798 : : NULL, "cannot find policy "
17799 : : "set tag action");
17800 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
17801 : 0 : break;
17802 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
17803 : : {
17804 : 0 : struct mlx5_flow_mtr_mng *mtrmng =
17805 : 0 : priv->sh->mtrmng;
17806 : : struct mlx5_flow_tbl_data_entry *tbl_data;
17807 : :
17808 : : /*
17809 : : * Create the drop table with
17810 : : * METER DROP level.
17811 : : */
17812 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
17813 : 0 : mtrmng->drop_tbl[domain] =
17814 : 0 : mlx5_flow_dv_tbl_resource_get(dev,
17815 : : MLX5_FLOW_TABLE_LEVEL_METER,
17816 : : egress, transfer, false,
17817 : : NULL, 0,
17818 : : 0, MLX5_MTR_TABLE_ID_DROP,
17819 : : &flow_err);
17820 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain])
17821 : 0 : return -rte_mtr_error_set
17822 : : (error, ENOTSUP,
17823 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17824 : : NULL,
17825 : : "Failed to create meter drop table");
17826 : : }
17827 : 0 : tbl_data = container_of
17828 : : (mtrmng->drop_tbl[domain],
17829 : : struct mlx5_flow_tbl_data_entry, tbl);
17830 [ # # ]: 0 : if (i < MLX5_MTR_RTE_COLORS) {
17831 : 0 : act_cnt->dr_jump_action[domain] =
17832 : 0 : tbl_data->jump.action;
17833 : 0 : act_cnt->fate_action =
17834 : : MLX5_FLOW_FATE_DROP;
17835 : : }
17836 [ # # ]: 0 : if (i == RTE_COLOR_RED)
17837 : 0 : mtr_policy->dr_drop_action[domain] =
17838 : 0 : tbl_data->jump.action;
17839 : 0 : action_flags |= MLX5_FLOW_ACTION_DROP;
17840 : 0 : break;
17841 : : }
17842 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
17843 : : {
17844 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17845 : 0 : return -rte_mtr_error_set(error,
17846 : : ENOTSUP,
17847 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17848 : : NULL, "cannot create policy "
17849 : : "fate queue for this color");
17850 : 0 : act_cnt->queue =
17851 : : ((const struct rte_flow_action_queue *)
17852 : 0 : (act->conf))->index;
17853 : 0 : act_cnt->fate_action =
17854 : : MLX5_FLOW_FATE_QUEUE;
17855 : 0 : dev_flow.handle->fate_action =
17856 : : MLX5_FLOW_FATE_QUEUE;
17857 : 0 : mtr_policy->is_queue = 1;
17858 : 0 : action_flags |= MLX5_FLOW_ACTION_QUEUE;
17859 : 0 : break;
17860 : : }
17861 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
17862 : : {
17863 : : int rss_size;
17864 : :
17865 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17866 : 0 : return -rte_mtr_error_set(error,
17867 : : ENOTSUP,
17868 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17869 : : NULL,
17870 : : "cannot create policy "
17871 : : "rss action for this color");
17872 : : /*
17873 : : * Save RSS conf into policy struct
17874 : : * for translate stage.
17875 : : */
17876 : 0 : rss_size = (int)rte_flow_conv
17877 : : (RTE_FLOW_CONV_OP_ACTION,
17878 : : NULL, 0, act, &flow_err);
17879 [ # # ]: 0 : if (rss_size <= 0)
17880 : 0 : return -rte_mtr_error_set(error,
17881 : : ENOTSUP,
17882 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17883 : : NULL, "Get the wrong "
17884 : : "rss action struct size");
17885 : 0 : act_cnt->rss = mlx5_malloc(MLX5_MEM_ZERO,
17886 : : rss_size, 0, SOCKET_ID_ANY);
17887 [ # # ]: 0 : if (!act_cnt->rss)
17888 : 0 : return -rte_mtr_error_set(error,
17889 : : ENOTSUP,
17890 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17891 : : NULL,
17892 : : "Fail to malloc rss action memory");
17893 : 0 : ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTION,
17894 : : act_cnt->rss, rss_size,
17895 : : act, &flow_err);
17896 [ # # ]: 0 : if (ret < 0)
17897 : 0 : return -rte_mtr_error_set(error,
17898 : : ENOTSUP,
17899 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17900 : : NULL, "Fail to save "
17901 : : "rss action into policy struct");
17902 : 0 : act_cnt->fate_action =
17903 : : MLX5_FLOW_FATE_SHARED_RSS;
17904 : 0 : action_flags |= MLX5_FLOW_ACTION_RSS;
17905 : 0 : break;
17906 : : }
17907 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
17908 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
17909 : : {
17910 : : struct mlx5_flow_dv_port_id_action_resource
17911 : : port_id_resource;
17912 : 0 : uint32_t port_id = 0;
17913 : :
17914 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17915 : 0 : return -rte_mtr_error_set(error,
17916 : : ENOTSUP,
17917 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17918 : : NULL, "cannot create policy "
17919 : : "port action for this color");
17920 : : memset(&port_id_resource, 0,
17921 : : sizeof(port_id_resource));
17922 [ # # ]: 0 : if (flow_dv_translate_action_port_id(dev, act,
17923 : : &port_id, &flow_err))
17924 : 0 : return -rte_mtr_error_set(error,
17925 : : ENOTSUP,
17926 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17927 : : NULL, "cannot translate "
17928 : : "policy port action");
17929 : 0 : port_id_resource.port_id = port_id;
17930 [ # # ]: 0 : if (flow_dv_port_id_action_resource_register
17931 : : (dev, &port_id_resource,
17932 : : &dev_flow, &flow_err))
17933 : 0 : return -rte_mtr_error_set(error,
17934 : : ENOTSUP,
17935 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17936 : : NULL, "cannot setup "
17937 : : "policy port action");
17938 : 0 : act_cnt->rix_port_id_action =
17939 : 0 : dev_flow.handle->rix_port_id_action;
17940 : 0 : act_cnt->fate_action =
17941 : : MLX5_FLOW_FATE_PORT_ID;
17942 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_ID;
17943 : 0 : break;
17944 : : }
17945 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
17946 : : {
17947 : : uint32_t jump_group = 0;
17948 : 0 : uint32_t table = 0;
17949 : : struct mlx5_flow_tbl_data_entry *tbl_data;
17950 : 0 : struct flow_grp_info grp_info = {
17951 : 0 : .external = !!dev_flow.external,
17952 : : .transfer = !!transfer,
17953 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
17954 : : .std_tbl_fix = 0,
17955 : 0 : .skip_scale = dev_flow.skip_scale &
17956 : : (1 << MLX5_SCALE_FLOW_GROUP_BIT),
17957 : : };
17958 : 0 : struct mlx5_flow_meter_sub_policy *sub_policy =
17959 : 0 : mtr_policy->sub_policys[domain][0];
17960 : :
17961 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17962 : 0 : return -rte_mtr_error_set(error,
17963 : : ENOTSUP,
17964 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17965 : : NULL,
17966 : : "cannot create policy "
17967 : : "jump action for this color");
17968 : 0 : jump_group =
17969 : : ((const struct rte_flow_action_jump *)
17970 : 0 : act->conf)->group;
17971 [ # # ]: 0 : if (mlx5_flow_group_to_table(dev, NULL,
17972 : : jump_group,
17973 : : &table,
17974 : : &grp_info, &flow_err))
17975 : 0 : return -rte_mtr_error_set(error,
17976 : : ENOTSUP,
17977 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17978 : : NULL, "cannot setup "
17979 : : "policy jump action");
17980 : 0 : sub_policy->jump_tbl[i] =
17981 : 0 : mlx5_flow_dv_tbl_resource_get(dev,
17982 : : table, egress,
17983 : : transfer, !!dev_flow.external,
17984 : : NULL, jump_group, 0,
17985 : : 0, &flow_err);
17986 : : if
17987 [ # # ]: 0 : (!sub_policy->jump_tbl[i])
17988 : 0 : return -rte_mtr_error_set(error,
17989 : : ENOTSUP,
17990 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17991 : : NULL, "cannot create jump action.");
17992 : 0 : tbl_data = container_of
17993 : : (sub_policy->jump_tbl[i],
17994 : : struct mlx5_flow_tbl_data_entry, tbl);
17995 : 0 : act_cnt->dr_jump_action[domain] =
17996 : 0 : tbl_data->jump.action;
17997 : 0 : act_cnt->fate_action =
17998 : : MLX5_FLOW_FATE_JUMP;
17999 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP;
18000 : 0 : break;
18001 : : }
18002 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
18003 : : {
18004 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
18005 : 0 : return -rte_mtr_error_set(error,
18006 : : ENOTSUP,
18007 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
18008 : : NULL,
18009 : : "cannot create policy modify field for this color");
18010 [ # # ]: 0 : if (flow_dv_convert_action_modify_field
18011 : : (dev, mhdr_res, act, attr, &flow_err))
18012 : 0 : return -rte_mtr_error_set(error,
18013 : : ENOTSUP,
18014 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
18015 : : NULL, "cannot setup policy modify field action");
18016 [ # # ]: 0 : if (!mhdr_res->actions_num)
18017 : 0 : return -rte_mtr_error_set(error,
18018 : : ENOTSUP,
18019 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
18020 : : NULL, "cannot find policy modify field action");
18021 : 0 : action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
18022 : 0 : break;
18023 : : }
18024 : : /*
18025 : : * No need to check meter hierarchy for R colors
18026 : : * here since it is done in the validation stage.
18027 : : */
18028 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
18029 : : {
18030 : : const struct rte_flow_action_meter *mtr;
18031 : : struct mlx5_flow_meter_info *next_fm;
18032 : : struct mlx5_flow_meter_policy *next_policy;
18033 : : struct rte_flow_action tag_action;
18034 : : struct mlx5_rte_flow_action_set_tag set_tag;
18035 : 0 : uint32_t next_mtr_idx = 0;
18036 : :
18037 : 0 : mtr = act->conf;
18038 : 0 : next_fm = mlx5_flow_meter_find(priv,
18039 : 0 : mtr->mtr_id,
18040 : : &next_mtr_idx);
18041 [ # # ]: 0 : if (!next_fm)
18042 : 0 : return -rte_mtr_error_set(error, EINVAL,
18043 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
18044 : : "Fail to find next meter.");
18045 [ # # ]: 0 : if (next_fm->def_policy)
18046 : 0 : return -rte_mtr_error_set(error, EINVAL,
18047 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
18048 : : "Hierarchy only supports termination meter.");
18049 : 0 : next_policy = mlx5_flow_meter_policy_find(dev,
18050 : : next_fm->policy_id, NULL);
18051 : : MLX5_ASSERT(next_policy);
18052 [ # # ]: 0 : if (next_fm->drop_cnt) {
18053 : 0 : set_tag.id =
18054 : 0 : (enum modify_reg)
18055 : 0 : mlx5_flow_get_reg_id(dev,
18056 : : MLX5_MTR_ID,
18057 : : 0,
18058 : : (struct rte_flow_error *)error);
18059 : 0 : set_tag.offset = (priv->mtr_reg_share ?
18060 : 0 : MLX5_MTR_COLOR_BITS : 0);
18061 [ # # ]: 0 : set_tag.length = (priv->mtr_reg_share ?
18062 : : MLX5_MTR_IDLE_BITS_IN_COLOR_REG :
18063 : : MLX5_REG_BITS);
18064 : 0 : set_tag.data = next_mtr_idx;
18065 : 0 : tag_action.type =
18066 : : (enum rte_flow_action_type)
18067 : : MLX5_RTE_FLOW_ACTION_TYPE_TAG;
18068 : 0 : tag_action.conf = &set_tag;
18069 [ # # ]: 0 : if (flow_dv_convert_action_set_reg
18070 : : (mhdr_res, &tag_action,
18071 : : (struct rte_flow_error *)error))
18072 : 0 : return -rte_errno;
18073 : 0 : action_flags |=
18074 : : MLX5_FLOW_ACTION_SET_TAG;
18075 : : }
18076 [ # # # # ]: 0 : if (i == RTE_COLOR_YELLOW && next_fm->color_aware &&
18077 [ # # ]: 0 : !next_fm->meter_action_y)
18078 [ # # ]: 0 : if (__flow_dv_create_mtr_yellow_action(dev, next_fm, error))
18079 : 0 : return -rte_errno;
18080 : 0 : act_cnt->fate_action = MLX5_FLOW_FATE_MTR;
18081 : 0 : act_cnt->next_mtr_id = next_fm->meter_id;
18082 : 0 : act_cnt->next_sub_policy = NULL;
18083 : 0 : mtr_policy->is_hierarchy = 1;
18084 [ # # ]: 0 : if (next_policy->mark)
18085 : 0 : mtr_policy->mark = 1;
18086 : 0 : mtr_policy->hierarchy_match_port =
18087 : 0 : next_policy->hierarchy_match_port;
18088 : 0 : action_flags |=
18089 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
18090 : 0 : break;
18091 : : }
18092 : : default:
18093 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
18094 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
18095 : : NULL, "action type not supported");
18096 : : }
18097 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_SET_TAG) ||
18098 : : (action_flags & MLX5_FLOW_ACTION_MODIFY_FIELD)) {
18099 : : /* create modify action if needed. */
18100 : 0 : dev_flow.dv.group = 1;
18101 [ # # ]: 0 : if (flow_dv_modify_hdr_resource_register
18102 : : (dev, mhdr_res, &dev_flow, &flow_err))
18103 : 0 : return -rte_mtr_error_set(error,
18104 : : ENOTSUP,
18105 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
18106 : : NULL, "cannot register policy set tag/modify field action");
18107 : 0 : act_cnt->modify_hdr =
18108 : 0 : dev_flow.handle->dvh.modify_hdr;
18109 : : }
18110 : : }
18111 : : }
18112 : : return 0;
18113 : : }
18114 : :
18115 : : /**
18116 : : * Create policy action per domain, lock free,
18117 : : * (mutex should be acquired by caller).
18118 : : * Dispatcher for action type specific call.
18119 : : *
18120 : : * @param[in] dev
18121 : : * Pointer to the Ethernet device structure.
18122 : : * @param[in] mtr_policy
18123 : : * Meter policy struct.
18124 : : * @param[in] action
18125 : : * Action specification used to create meter actions.
18126 : : * @param[in] attr
18127 : : * Pointer to the flow attributes.
18128 : : * @param[out] error
18129 : : * Perform verbose error reporting if not NULL. Initialized in case of
18130 : : * error only.
18131 : : *
18132 : : * @return
18133 : : * 0 on success, otherwise negative errno value.
18134 : : */
18135 : : static int
18136 : 0 : flow_dv_create_mtr_policy_acts(struct rte_eth_dev *dev,
18137 : : struct mlx5_flow_meter_policy *mtr_policy,
18138 : : const struct rte_flow_action *actions[RTE_COLORS],
18139 : : struct rte_flow_attr *attr,
18140 : : struct rte_mtr_error *error)
18141 : : {
18142 : : int ret, i;
18143 : : uint16_t sub_policy_num;
18144 : :
18145 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
18146 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
18147 : 0 : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
18148 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
18149 [ # # ]: 0 : if (sub_policy_num) {
18150 : 0 : ret = __flow_dv_create_domain_policy_acts(dev,
18151 : : mtr_policy, actions, attr,
18152 : : (enum mlx5_meter_domain)i, error);
18153 : : /* Cleaning resource is done in the caller level. */
18154 [ # # ]: 0 : if (ret)
18155 : 0 : return ret;
18156 : : }
18157 : : }
18158 : : return 0;
18159 : : }
18160 : :
18161 : : /**
18162 : : * Query a DV flow rule for its statistics via DevX.
18163 : : *
18164 : : * @param[in] dev
18165 : : * Pointer to Ethernet device.
18166 : : * @param[in] cnt_idx
18167 : : * Index to the flow counter.
18168 : : * @param[out] data
18169 : : * Data retrieved by the query.
18170 : : * @param[out] error
18171 : : * Perform verbose error reporting if not NULL.
18172 : : *
18173 : : * @return
18174 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
18175 : : */
18176 : : static int
18177 : 0 : flow_dv_query_count(struct rte_eth_dev *dev, uint32_t cnt_idx, void *data,
18178 : : struct rte_flow_error *error)
18179 : : {
18180 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18181 : : struct rte_flow_query_count *qc = data;
18182 : :
18183 [ # # ]: 0 : if (!priv->sh->cdev->config.devx)
18184 : 0 : return rte_flow_error_set(error, ENOTSUP,
18185 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18186 : : NULL,
18187 : : "counters are not supported");
18188 [ # # ]: 0 : if (cnt_idx) {
18189 : : uint64_t pkts, bytes;
18190 : : struct mlx5_flow_counter *cnt;
18191 : 0 : int err = _flow_dv_query_count(dev, cnt_idx, &pkts, &bytes);
18192 : :
18193 [ # # ]: 0 : if (err)
18194 : 0 : return rte_flow_error_set(error, -err,
18195 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18196 : : NULL, "cannot read counters");
18197 : : cnt = flow_dv_counter_get_by_idx(dev, cnt_idx, NULL);
18198 : 0 : qc->hits_set = 1;
18199 : 0 : qc->bytes_set = 1;
18200 : 0 : qc->hits = pkts - cnt->hits;
18201 : 0 : qc->bytes = bytes - cnt->bytes;
18202 [ # # ]: 0 : if (qc->reset) {
18203 : 0 : cnt->hits = pkts;
18204 : 0 : cnt->bytes = bytes;
18205 : : }
18206 : 0 : return 0;
18207 : : }
18208 : 0 : return rte_flow_error_set(error, EINVAL,
18209 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18210 : : NULL,
18211 : : "counters are not available");
18212 : : }
18213 : :
18214 : : int
18215 : 0 : mlx5_flow_dv_action_query(struct rte_eth_dev *dev,
18216 : : const struct rte_flow_action_handle *handle, void *data,
18217 : : struct rte_flow_error *error)
18218 : : {
18219 : : struct mlx5_age_param *age_param;
18220 : : struct rte_flow_query_age *resp;
18221 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
18222 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
18223 : 0 : uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
18224 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18225 : : struct mlx5_aso_ct_action *ct;
18226 : : uint16_t owner;
18227 : : uint32_t dev_idx;
18228 : :
18229 [ # # # # ]: 0 : switch (type) {
18230 : 0 : case MLX5_INDIRECT_ACTION_TYPE_AGE:
18231 : 0 : age_param = &mlx5_flow_aso_age_get_by_idx(dev, idx)->age_params;
18232 : : resp = data;
18233 : 0 : resp->aged = rte_atomic_load_explicit(&age_param->state,
18234 : : rte_memory_order_relaxed) == AGE_TMOUT ?
18235 : 0 : 1 : 0;
18236 : 0 : resp->sec_since_last_hit_valid = !resp->aged;
18237 [ # # ]: 0 : if (resp->sec_since_last_hit_valid)
18238 : 0 : resp->sec_since_last_hit = rte_atomic_load_explicit
18239 : : (&age_param->sec_since_last_hit, rte_memory_order_relaxed);
18240 : : return 0;
18241 : 0 : case MLX5_INDIRECT_ACTION_TYPE_COUNT:
18242 : 0 : return flow_dv_query_count(dev, idx, data, error);
18243 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
18244 : 0 : owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(idx);
18245 [ # # ]: 0 : if (owner != PORT_ID(priv))
18246 : 0 : return rte_flow_error_set(error, EACCES,
18247 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18248 : : NULL,
18249 : : "CT object owned by another port");
18250 : 0 : dev_idx = MLX5_INDIRECT_ACT_CT_GET_IDX(idx);
18251 : 0 : ct = flow_aso_ct_get_by_dev_idx(dev, dev_idx);
18252 : : MLX5_ASSERT(ct);
18253 [ # # ]: 0 : if (!ct->refcnt)
18254 : 0 : return rte_flow_error_set(error, EFAULT,
18255 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18256 : : NULL,
18257 : : "CT object is inactive");
18258 : 0 : ((struct rte_flow_action_conntrack *)data)->peer_port =
18259 : 0 : ct->peer;
18260 : 0 : ((struct rte_flow_action_conntrack *)data)->is_original_dir =
18261 : 0 : ct->is_original;
18262 [ # # ]: 0 : if (mlx5_aso_ct_query_by_wqe(priv->sh, MLX5_HW_INV_QUEUE, ct,
18263 : : data, NULL, true))
18264 : 0 : return rte_flow_error_set(error, EIO,
18265 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18266 : : NULL,
18267 : : "Failed to query CT context");
18268 : : return 0;
18269 : 0 : default:
18270 : 0 : return rte_flow_error_set(error, ENOTSUP,
18271 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
18272 : : "action type query not supported");
18273 : : }
18274 : : }
18275 : :
18276 : : /**
18277 : : * Query a flow rule AGE action for aging information.
18278 : : *
18279 : : * @param[in] dev
18280 : : * Pointer to Ethernet device.
18281 : : * @param[in] flow
18282 : : * Pointer to the sub flow.
18283 : : * @param[out] data
18284 : : * data retrieved by the query.
18285 : : * @param[out] error
18286 : : * Perform verbose error reporting if not NULL.
18287 : : *
18288 : : * @return
18289 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
18290 : : */
18291 : : static int
18292 : 0 : flow_dv_query_age(struct rte_eth_dev *dev, struct rte_flow *flow,
18293 : : void *data, struct rte_flow_error *error)
18294 : : {
18295 : : struct rte_flow_query_age *resp = data;
18296 : : struct mlx5_age_param *age_param;
18297 : :
18298 [ # # ]: 0 : if (flow->age) {
18299 : : struct mlx5_aso_age_action *act =
18300 : 0 : mlx5_flow_aso_age_get_by_idx(dev, flow->age);
18301 : :
18302 : 0 : age_param = &act->age_params;
18303 [ # # ]: 0 : } else if (flow->counter) {
18304 : : age_param = flow_dv_counter_idx_get_age(dev, flow->counter);
18305 : :
18306 [ # # ]: 0 : if (!age_param || !age_param->timeout)
18307 : 0 : return rte_flow_error_set
18308 : : (error, EINVAL,
18309 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18310 : : NULL, "cannot read age data");
18311 : : } else {
18312 : 0 : return rte_flow_error_set(error, EINVAL,
18313 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18314 : : NULL, "age data not available");
18315 : : }
18316 : 0 : resp->aged = rte_atomic_load_explicit(&age_param->state, rte_memory_order_relaxed) ==
18317 : 0 : AGE_TMOUT ? 1 : 0;
18318 : 0 : resp->sec_since_last_hit_valid = !resp->aged;
18319 [ # # ]: 0 : if (resp->sec_since_last_hit_valid)
18320 : 0 : resp->sec_since_last_hit = rte_atomic_load_explicit
18321 : : (&age_param->sec_since_last_hit, rte_memory_order_relaxed);
18322 : : return 0;
18323 : : }
18324 : :
18325 : : /**
18326 : : * Query a flow.
18327 : : *
18328 : : * @see rte_flow_query()
18329 : : * @see rte_flow_ops
18330 : : */
18331 : : static int
18332 : 0 : flow_dv_query(struct rte_eth_dev *dev,
18333 : : struct rte_flow *flow __rte_unused,
18334 : : const struct rte_flow_action *actions __rte_unused,
18335 : : void *data __rte_unused,
18336 : : struct rte_flow_error *error __rte_unused)
18337 : : {
18338 : : int ret = -EINVAL;
18339 : :
18340 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
18341 [ # # # # ]: 0 : switch (actions->type) {
18342 : : case RTE_FLOW_ACTION_TYPE_VOID:
18343 : : break;
18344 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
18345 : 0 : ret = flow_dv_query_count(dev, flow->counter, data,
18346 : : error);
18347 : 0 : break;
18348 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
18349 [ # # ]: 0 : if (flow->indirect_type == MLX5_INDIRECT_ACTION_TYPE_CT)
18350 : 0 : return rte_flow_error_set(error, ENOTSUP,
18351 : : RTE_FLOW_ERROR_TYPE_ACTION,
18352 : : actions,
18353 : : "age not available");
18354 : 0 : ret = flow_dv_query_age(dev, flow, data, error);
18355 : 0 : break;
18356 : 0 : default:
18357 : 0 : return rte_flow_error_set(error, ENOTSUP,
18358 : : RTE_FLOW_ERROR_TYPE_ACTION,
18359 : : actions,
18360 : : "action not supported");
18361 : : }
18362 : : }
18363 : : return ret;
18364 : : }
18365 : :
18366 : : /**
18367 : : * Destroy the meter table set.
18368 : : * Lock free, (mutex should be acquired by caller).
18369 : : *
18370 : : * @param[in] dev
18371 : : * Pointer to Ethernet device.
18372 : : * @param[in] fm
18373 : : * Meter information table.
18374 : : */
18375 : : static void
18376 : 0 : flow_dv_destroy_mtr_tbls(struct rte_eth_dev *dev,
18377 : : struct mlx5_flow_meter_info *fm)
18378 : : {
18379 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18380 : : int i;
18381 : :
18382 [ # # # # ]: 0 : if (!fm || !priv->sh->config.dv_flow_en)
18383 : : return;
18384 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
18385 [ # # ]: 0 : if (fm->drop_rule[i]) {
18386 : : claim_zero(mlx5_flow_os_destroy_flow(fm->drop_rule[i]));
18387 : 0 : fm->drop_rule[i] = NULL;
18388 : : }
18389 : : }
18390 : : }
18391 : :
18392 : : static void
18393 : 0 : flow_dv_destroy_mtr_drop_tbls(struct rte_eth_dev *dev)
18394 : : {
18395 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18396 : 0 : struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
18397 : : struct mlx5_flow_tbl_data_entry *tbl;
18398 : : int i, j;
18399 : :
18400 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
18401 [ # # ]: 0 : if (mtrmng->def_rule[i]) {
18402 : : claim_zero(mlx5_flow_os_destroy_flow
18403 : : (mtrmng->def_rule[i]));
18404 : 0 : mtrmng->def_rule[i] = NULL;
18405 : : }
18406 [ # # ]: 0 : if (mtrmng->def_matcher[i]) {
18407 : 0 : tbl = container_of(mtrmng->def_matcher[i]->tbl,
18408 : : struct mlx5_flow_tbl_data_entry, tbl);
18409 : 0 : mlx5_list_unregister(tbl->matchers,
18410 : : &mtrmng->def_matcher[i]->entry);
18411 : 0 : mtrmng->def_matcher[i] = NULL;
18412 : : }
18413 [ # # ]: 0 : for (j = 0; j < MLX5_REG_BITS; j++) {
18414 [ # # ]: 0 : if (mtrmng->drop_matcher[i][j]) {
18415 : : tbl =
18416 : 0 : container_of(mtrmng->drop_matcher[i][j]->tbl,
18417 : : struct mlx5_flow_tbl_data_entry,
18418 : : tbl);
18419 : 0 : mlx5_list_unregister(tbl->matchers,
18420 : : &mtrmng->drop_matcher[i][j]->entry);
18421 : 0 : mtrmng->drop_matcher[i][j] = NULL;
18422 : : }
18423 : : }
18424 [ # # ]: 0 : if (mtrmng->drop_tbl[i]) {
18425 : 0 : mlx5_flow_dv_tbl_resource_release(MLX5_SH(dev), mtrmng->drop_tbl[i]);
18426 : 0 : mtrmng->drop_tbl[i] = NULL;
18427 : : }
18428 : : }
18429 : 0 : }
18430 : :
18431 : : /* Number of meter flow actions, count and jump or count and drop. */
18432 : : #define METER_ACTIONS 2
18433 : :
18434 : : static void
18435 : 0 : __flow_dv_destroy_domain_def_policy(struct rte_eth_dev *dev,
18436 : : enum mlx5_meter_domain domain)
18437 : : {
18438 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18439 : 0 : struct mlx5_flow_meter_def_policy *def_policy =
18440 : 0 : priv->sh->mtrmng->def_policy[domain];
18441 : :
18442 : 0 : __flow_dv_destroy_sub_policy_rules(dev, &def_policy->sub_policy);
18443 : 0 : mlx5_free(def_policy);
18444 : 0 : priv->sh->mtrmng->def_policy[domain] = NULL;
18445 : 0 : }
18446 : :
18447 : : /**
18448 : : * Destroy the default policy table set.
18449 : : *
18450 : : * @param[in] dev
18451 : : * Pointer to Ethernet device.
18452 : : */
18453 : : static void
18454 : 0 : flow_dv_destroy_def_policy(struct rte_eth_dev *dev)
18455 : : {
18456 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18457 : : int i;
18458 : :
18459 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++)
18460 [ # # ]: 0 : if (priv->sh->mtrmng->def_policy[i])
18461 : 0 : __flow_dv_destroy_domain_def_policy(dev,
18462 : : (enum mlx5_meter_domain)i);
18463 : 0 : priv->sh->mtrmng->def_policy_id = MLX5_INVALID_POLICY_ID;
18464 : 0 : }
18465 : :
18466 : : static int
18467 : 0 : __flow_dv_create_policy_flow(struct rte_eth_dev *dev,
18468 : : uint32_t color_reg_c_idx,
18469 : : enum rte_color color, struct mlx5_flow_dv_matcher *matcher,
18470 : : int actions_n, void *actions,
18471 : : bool match_src_port, const struct rte_flow_item *item,
18472 : : void **rule, const struct rte_flow_attr *attr)
18473 : : {
18474 : : int ret;
18475 : 0 : struct mlx5_flow_dv_match_params value = {
18476 : : .size = sizeof(value.buf),
18477 : : };
18478 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18479 : : uint8_t misc_mask;
18480 : :
18481 [ # # # # ]: 0 : if (match_src_port && priv->sh->esw_mode) {
18482 [ # # # # ]: 0 : if (item && item->type == RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT)
18483 : 0 : ret = flow_dv_translate_item_represented_port(dev, value.buf,
18484 : : item, attr, MLX5_SET_MATCHER_SW_V);
18485 [ # # # # ]: 0 : else if (item && item->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR)
18486 : 0 : ret = flow_dv_translate_item_port_representor(dev, value.buf,
18487 : : MLX5_SET_MATCHER_SW_V);
18488 : : else
18489 : 0 : ret = flow_dv_translate_item_port_id(dev, value.buf,
18490 : : item, attr, MLX5_SET_MATCHER_SW_V);
18491 [ # # ]: 0 : if (ret) {
18492 : 0 : DRV_LOG(ERR, "Failed to create meter policy%d flow's"
18493 : : " value with port.", color);
18494 : 0 : return -1;
18495 : : }
18496 : : }
18497 : 0 : flow_dv_match_meta_reg(value.buf, (enum modify_reg)color_reg_c_idx,
18498 : : rte_col_2_mlx5_col(color), UINT32_MAX);
18499 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(matcher->mask.buf);
18500 : : __flow_dv_adjust_buf_size(&value.size, misc_mask);
18501 : 0 : ret = mlx5_flow_os_create_flow(matcher->matcher_object, (void *)&value,
18502 : : actions_n, actions, rule);
18503 : : if (ret) {
18504 : 0 : DRV_LOG(ERR, "Failed to create meter policy%d flow.", color);
18505 : 0 : return -1;
18506 : : }
18507 : : return 0;
18508 : : }
18509 : :
18510 : : static int
18511 : 0 : __flow_dv_create_policy_matcher(struct rte_eth_dev *dev,
18512 : : uint32_t color_reg_c_idx,
18513 : : uint16_t priority,
18514 : : struct mlx5_flow_meter_sub_policy *sub_policy,
18515 : : const struct rte_flow_attr *attr,
18516 : : bool match_src_port,
18517 : : const struct rte_flow_item *item,
18518 : : struct mlx5_flow_dv_matcher **policy_matcher,
18519 : : struct rte_flow_error *error)
18520 : : {
18521 : : struct mlx5_list_entry *entry;
18522 : 0 : struct mlx5_flow_tbl_resource *tbl_rsc = sub_policy->tbl_rsc;
18523 : 0 : struct mlx5_flow_dv_matcher matcher = {
18524 : : .mask = {
18525 : : .size = sizeof(matcher.mask.buf),
18526 : : },
18527 : : .tbl = tbl_rsc,
18528 : : };
18529 : 0 : struct mlx5_flow_cb_ctx ctx = {
18530 : : .error = error,
18531 : : .data = &matcher,
18532 : : };
18533 : : struct mlx5_flow_tbl_data_entry *tbl_data;
18534 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18535 : : const uint32_t color_mask = (UINT32_C(1) << MLX5_MTR_COLOR_BITS) - 1;
18536 : : int ret;
18537 : :
18538 [ # # # # ]: 0 : if (match_src_port && priv->sh->esw_mode) {
18539 [ # # # # ]: 0 : if (item && item->type == RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT)
18540 : 0 : ret = flow_dv_translate_item_represented_port(dev, matcher.mask.buf,
18541 : : item, attr, MLX5_SET_MATCHER_SW_M);
18542 [ # # # # ]: 0 : else if (item && item->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR)
18543 : 0 : ret = flow_dv_translate_item_port_representor(dev, matcher.mask.buf,
18544 : : MLX5_SET_MATCHER_SW_M);
18545 : : else
18546 : 0 : ret = flow_dv_translate_item_port_id(dev, matcher.mask.buf,
18547 : : item, attr, MLX5_SET_MATCHER_SW_M);
18548 [ # # ]: 0 : if (ret) {
18549 : 0 : DRV_LOG(ERR, "Failed to register meter policy%d matcher"
18550 : : " with port.", priority);
18551 : 0 : return -1;
18552 : : }
18553 : : }
18554 : 0 : tbl_data = container_of(tbl_rsc, struct mlx5_flow_tbl_data_entry, tbl);
18555 : 0 : flow_dv_match_meta_reg(matcher.mask.buf,
18556 : : (enum modify_reg)color_reg_c_idx, color_mask, color_mask);
18557 : 0 : matcher.priority = priority;
18558 : 0 : matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
18559 : : matcher.mask.size);
18560 : 0 : entry = mlx5_list_register(tbl_data->matchers, &ctx);
18561 [ # # ]: 0 : if (!entry) {
18562 : 0 : DRV_LOG(ERR, "Failed to register meter drop matcher.");
18563 : 0 : return -1;
18564 : : }
18565 : 0 : *policy_matcher =
18566 : : container_of(entry, struct mlx5_flow_dv_matcher, entry);
18567 : 0 : return 0;
18568 : : }
18569 : :
18570 : : /**
18571 : : * Create the policy rules per domain.
18572 : : *
18573 : : * @param[in] dev
18574 : : * Pointer to Ethernet device.
18575 : : * @param[in] sub_policy
18576 : : * Pointer to sub policy table..
18577 : : * @param[in] egress
18578 : : * Direction of the table.
18579 : : * @param[in] transfer
18580 : : * E-Switch or NIC flow.
18581 : : * @param[in] acts
18582 : : * Pointer to policy action list per color.
18583 : : *
18584 : : * @return
18585 : : * 0 on success, -1 otherwise.
18586 : : */
18587 : : static int
18588 : 0 : __flow_dv_create_domain_policy_rules(struct rte_eth_dev *dev,
18589 : : struct mlx5_flow_meter_sub_policy *sub_policy,
18590 : : uint8_t egress, uint8_t transfer, bool *match_src_port,
18591 : : struct mlx5_meter_policy_acts acts[RTE_COLORS])
18592 : : {
18593 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18594 : : struct rte_flow_error flow_err;
18595 : : uint32_t color_reg_c_idx;
18596 : 0 : struct rte_flow_attr attr = {
18597 : : .group = MLX5_FLOW_TABLE_LEVEL_POLICY,
18598 : : .priority = 0,
18599 : : .ingress = 0,
18600 : 0 : .egress = !!egress,
18601 : 0 : .transfer = !!transfer,
18602 : : .reserved = 0,
18603 : : };
18604 : : int i;
18605 : : uint16_t priority;
18606 : 0 : int ret = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &flow_err);
18607 : : struct mlx5_sub_policy_color_rule *color_rule;
18608 : 0 : struct mlx5_sub_policy_color_rule *tmp_rules[RTE_COLORS] = {NULL};
18609 : :
18610 [ # # ]: 0 : if (ret < 0)
18611 : : return -1;
18612 : : /* Create policy table with POLICY level. */
18613 [ # # ]: 0 : if (!sub_policy->tbl_rsc)
18614 : 0 : sub_policy->tbl_rsc = mlx5_flow_dv_tbl_resource_get(dev,
18615 : : MLX5_FLOW_TABLE_LEVEL_POLICY,
18616 : : egress, transfer, false,
18617 : : NULL, 0, 0,
18618 : 0 : sub_policy->idx, &flow_err);
18619 [ # # ]: 0 : if (!sub_policy->tbl_rsc) {
18620 : 0 : DRV_LOG(ERR,
18621 : : "Failed to create meter sub policy table.");
18622 : 0 : return -1;
18623 : : }
18624 : : /* Prepare matchers. */
18625 : 0 : color_reg_c_idx = ret;
18626 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
18627 : 0 : TAILQ_INIT(&sub_policy->color_rules[i]);
18628 [ # # ]: 0 : if (!acts[i].actions_n)
18629 : 0 : continue;
18630 : 0 : color_rule = mlx5_malloc(MLX5_MEM_ZERO,
18631 : : sizeof(struct mlx5_sub_policy_color_rule),
18632 : : 0, SOCKET_ID_ANY);
18633 [ # # ]: 0 : if (!color_rule) {
18634 : 0 : DRV_LOG(ERR, "No memory to create color rule.");
18635 : 0 : goto err_exit;
18636 : : }
18637 : 0 : tmp_rules[i] = color_rule;
18638 : 0 : TAILQ_INSERT_TAIL(&sub_policy->color_rules[i],
18639 : : color_rule, next_port);
18640 : 0 : color_rule->src_port = priv->representor_id;
18641 : 0 : priority = (match_src_port[i] == match_src_port[RTE_COLOR_GREEN]) ?
18642 : 0 : MLX5_MTR_POLICY_MATCHER_PRIO : (MLX5_MTR_POLICY_MATCHER_PRIO + 1);
18643 : : /* Create matchers for colors. */
18644 [ # # ]: 0 : if (__flow_dv_create_policy_matcher(dev, color_reg_c_idx,
18645 : : priority, sub_policy,
18646 : : &attr, match_src_port[i], NULL,
18647 : : &color_rule->matcher, &flow_err)) {
18648 : 0 : DRV_LOG(ERR, "Failed to create color%u matcher.", i);
18649 : 0 : goto err_exit;
18650 : : }
18651 : : /* Create flow, matching color. */
18652 [ # # ]: 0 : if (__flow_dv_create_policy_flow(dev,
18653 : : color_reg_c_idx, (enum rte_color)i,
18654 : : color_rule->matcher,
18655 : 0 : acts[i].actions_n, acts[i].dv_actions,
18656 : 0 : match_src_port[i], NULL, &color_rule->rule,
18657 : : &attr)) {
18658 : 0 : DRV_LOG(ERR, "Failed to create color%u rule.", i);
18659 : 0 : goto err_exit;
18660 : : }
18661 : : }
18662 : : return 0;
18663 : : err_exit:
18664 : : /* All the policy rules will be cleared. */
18665 : : do {
18666 : 0 : color_rule = tmp_rules[i];
18667 [ # # ]: 0 : if (color_rule) {
18668 [ # # ]: 0 : if (color_rule->rule)
18669 : : mlx5_flow_os_destroy_flow(color_rule->rule);
18670 [ # # ]: 0 : if (color_rule->matcher) {
18671 : : struct mlx5_flow_tbl_data_entry *tbl =
18672 : 0 : container_of(color_rule->matcher->tbl,
18673 : : typeof(*tbl), tbl);
18674 : 0 : mlx5_list_unregister(tbl->matchers,
18675 : : &color_rule->matcher->entry);
18676 : : }
18677 [ # # ]: 0 : TAILQ_REMOVE(&sub_policy->color_rules[i],
18678 : : color_rule, next_port);
18679 : 0 : mlx5_free(color_rule);
18680 : : }
18681 [ # # ]: 0 : } while (i--);
18682 : : return -1;
18683 : : }
18684 : :
18685 : : static int
18686 : 0 : __flow_dv_create_policy_acts_rules(struct rte_eth_dev *dev,
18687 : : struct mlx5_flow_meter_policy *mtr_policy,
18688 : : struct mlx5_flow_meter_sub_policy *sub_policy,
18689 : : uint32_t domain)
18690 : : {
18691 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18692 : : struct mlx5_meter_policy_acts acts[RTE_COLORS];
18693 : : struct mlx5_flow_dv_tag_resource *tag;
18694 : : struct mlx5_flow_dv_port_id_action_resource *port_action;
18695 : : struct mlx5_hrxq *hrxq;
18696 : 0 : struct mlx5_flow_meter_info *next_fm[RTE_COLORS] = {NULL};
18697 : : struct mlx5_flow_meter_policy *next_policy;
18698 : : struct mlx5_flow_meter_sub_policy *next_sub_policy;
18699 : : struct mlx5_flow_tbl_data_entry *tbl_data;
18700 : : struct rte_flow_error error;
18701 : 0 : uint8_t egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
18702 : 0 : uint8_t transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
18703 [ # # # # : 0 : bool mtr_first = egress || (transfer && priv->representor_id != UINT16_MAX);
# # ]
18704 : 0 : bool match_src_port[RTE_COLORS] = {false};
18705 : : int i;
18706 : :
18707 : : /* If RSS or Queue, no previous actions / rules is created. */
18708 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
18709 : 0 : acts[i].actions_n = 0;
18710 [ # # ]: 0 : if (i == RTE_COLOR_RED) {
18711 : : /* Only support drop on red. */
18712 : 0 : acts[i].dv_actions[0] =
18713 : 0 : mtr_policy->dr_drop_action[domain];
18714 : 0 : acts[i].actions_n = 1;
18715 : 0 : continue;
18716 : : }
18717 [ # # ]: 0 : if (mtr_policy->act_cnt[i].fate_action == MLX5_FLOW_FATE_MTR) {
18718 : 0 : struct rte_flow_attr attr = {
18719 : : .transfer = transfer
18720 : : };
18721 : :
18722 : 0 : next_fm[i] = mlx5_flow_meter_find(priv,
18723 : : mtr_policy->act_cnt[i].next_mtr_id,
18724 : : NULL);
18725 [ # # ]: 0 : if (!next_fm[i]) {
18726 : 0 : DRV_LOG(ERR,
18727 : : "Failed to get next hierarchy meter.");
18728 : 0 : goto err_exit;
18729 : : }
18730 [ # # ]: 0 : if (mlx5_flow_meter_attach(priv, next_fm[i],
18731 : : &attr, &error)) {
18732 : 0 : DRV_LOG(ERR, "%s", error.message);
18733 : 0 : next_fm[i] = NULL;
18734 : 0 : goto err_exit;
18735 : : }
18736 : : /* Meter action must be the first for TX. */
18737 [ # # ]: 0 : if (mtr_first) {
18738 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18739 [ # # ]: 0 : (next_fm[i]->color_aware && i == RTE_COLOR_YELLOW) ?
18740 [ # # ]: 0 : next_fm[i]->meter_action_y :
18741 : : next_fm[i]->meter_action_g;
18742 : 0 : acts[i].actions_n++;
18743 : : }
18744 : : }
18745 [ # # ]: 0 : if (mtr_policy->act_cnt[i].rix_mark) {
18746 : 0 : tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG],
18747 : : mtr_policy->act_cnt[i].rix_mark);
18748 [ # # ]: 0 : if (!tag) {
18749 : 0 : DRV_LOG(ERR, "Failed to find "
18750 : : "mark action for policy.");
18751 : 0 : goto err_exit;
18752 : : }
18753 : 0 : acts[i].dv_actions[acts[i].actions_n] = tag->action;
18754 : 0 : acts[i].actions_n++;
18755 : : }
18756 [ # # ]: 0 : if (mtr_policy->act_cnt[i].modify_hdr) {
18757 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18758 : 0 : mtr_policy->act_cnt[i].modify_hdr->action;
18759 : 0 : acts[i].actions_n++;
18760 : : }
18761 [ # # ]: 0 : if (mtr_policy->act_cnt[i].fate_action) {
18762 [ # # # # : 0 : switch (mtr_policy->act_cnt[i].fate_action) {
# ]
18763 : 0 : case MLX5_FLOW_FATE_PORT_ID:
18764 : 0 : port_action = mlx5_ipool_get
18765 : 0 : (priv->sh->ipool[MLX5_IPOOL_PORT_ID],
18766 : : mtr_policy->act_cnt[i].rix_port_id_action);
18767 [ # # ]: 0 : if (!port_action) {
18768 : 0 : DRV_LOG(ERR, "Failed to find "
18769 : : "port action for policy.");
18770 : 0 : goto err_exit;
18771 : : }
18772 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18773 : 0 : port_action->action;
18774 : 0 : acts[i].actions_n++;
18775 : 0 : match_src_port[i] = true;
18776 : 0 : break;
18777 : 0 : case MLX5_FLOW_FATE_DROP:
18778 : : case MLX5_FLOW_FATE_JUMP:
18779 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18780 : 0 : mtr_policy->act_cnt[i].dr_jump_action[domain];
18781 : 0 : acts[i].actions_n++;
18782 : 0 : break;
18783 : 0 : case MLX5_FLOW_FATE_SHARED_RSS:
18784 : : case MLX5_FLOW_FATE_QUEUE:
18785 : 0 : hrxq = mlx5_ipool_get
18786 : 0 : (priv->sh->ipool[MLX5_IPOOL_HRXQ],
18787 : : sub_policy->rix_hrxq[i]);
18788 [ # # ]: 0 : if (!hrxq) {
18789 : 0 : DRV_LOG(ERR, "Failed to find "
18790 : : "queue action for policy.");
18791 : 0 : goto err_exit;
18792 : : }
18793 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18794 : 0 : hrxq->action;
18795 : 0 : acts[i].actions_n++;
18796 : 0 : break;
18797 : 0 : case MLX5_FLOW_FATE_MTR:
18798 [ # # ]: 0 : if (!next_fm[i]) {
18799 : 0 : DRV_LOG(ERR,
18800 : : "No next hierarchy meter.");
18801 : 0 : goto err_exit;
18802 : : }
18803 [ # # ]: 0 : if (!mtr_first) {
18804 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18805 [ # # ]: 0 : (next_fm[i]->color_aware && i == RTE_COLOR_YELLOW) ?
18806 [ # # ]: 0 : next_fm[i]->meter_action_y :
18807 : : next_fm[i]->meter_action_g;
18808 : 0 : acts[i].actions_n++;
18809 : : }
18810 [ # # ]: 0 : if (mtr_policy->act_cnt[i].next_sub_policy) {
18811 : : next_sub_policy =
18812 : : mtr_policy->act_cnt[i].next_sub_policy;
18813 : : } else {
18814 : : next_policy =
18815 : 0 : mlx5_flow_meter_policy_find(dev,
18816 : : next_fm[i]->policy_id, NULL);
18817 : : MLX5_ASSERT(next_policy);
18818 : 0 : next_sub_policy =
18819 : 0 : next_policy->sub_policys[domain][0];
18820 : : }
18821 : : tbl_data =
18822 : 0 : container_of(next_sub_policy->tbl_rsc,
18823 : : struct mlx5_flow_tbl_data_entry, tbl);
18824 : 0 : acts[i].dv_actions[acts[i].actions_n++] =
18825 : 0 : tbl_data->jump.action;
18826 [ # # ]: 0 : if (mtr_policy->act_cnt[i].modify_hdr)
18827 : 0 : match_src_port[i] = !!transfer;
18828 : : break;
18829 : : default:
18830 : : /*Queue action do nothing*/
18831 : : break;
18832 : : }
18833 : : }
18834 : : }
18835 [ # # ]: 0 : if (__flow_dv_create_domain_policy_rules(dev, sub_policy,
18836 : : egress, transfer, match_src_port, acts)) {
18837 : 0 : DRV_LOG(ERR,
18838 : : "Failed to create policy rules per domain.");
18839 : 0 : goto err_exit;
18840 : : }
18841 [ # # # # ]: 0 : if (match_src_port[RTE_COLOR_GREEN] || match_src_port[RTE_COLOR_YELLOW]) {
18842 : 0 : mtr_policy->match_port = 1;
18843 : 0 : mtr_policy->hierarchy_match_port = 1;
18844 : : }
18845 : : return 0;
18846 : : err_exit:
18847 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++)
18848 [ # # ]: 0 : if (next_fm[i])
18849 : 0 : mlx5_flow_meter_detach(priv, next_fm[i]);
18850 : : return -1;
18851 : : }
18852 : :
18853 : : /**
18854 : : * Create the policy rules.
18855 : : *
18856 : : * @param[in] dev
18857 : : * Pointer to Ethernet device.
18858 : : * @param[in,out] mtr_policy
18859 : : * Pointer to meter policy table.
18860 : : *
18861 : : * @return
18862 : : * 0 on success, -1 otherwise.
18863 : : */
18864 : : static int
18865 : 0 : flow_dv_create_policy_rules(struct rte_eth_dev *dev,
18866 : : struct mlx5_flow_meter_policy *mtr_policy)
18867 : : {
18868 : : int i;
18869 : : int ret = 0;
18870 : : uint16_t sub_policy_num;
18871 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_push_thread_workspace();
18872 : :
18873 : : RTE_SET_USED(wks);
18874 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
18875 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
18876 : 0 : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
18877 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
18878 [ # # ]: 0 : if (!sub_policy_num)
18879 : 0 : continue;
18880 : : /* Prepare actions list and create policy rules. */
18881 [ # # ]: 0 : if (__flow_dv_create_policy_acts_rules(dev, mtr_policy,
18882 : 0 : mtr_policy->sub_policys[i][0], i)) {
18883 : 0 : DRV_LOG(ERR, "Failed to create policy action "
18884 : : "list per domain.");
18885 : : ret = -1;
18886 : 0 : goto exit;
18887 : : }
18888 : : }
18889 : 0 : exit:
18890 : 0 : mlx5_flow_pop_thread_workspace();
18891 : 0 : return ret;
18892 : : }
18893 : :
18894 : : static int
18895 : 0 : __flow_dv_create_domain_def_policy(struct rte_eth_dev *dev, uint32_t domain)
18896 : : {
18897 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18898 : 0 : struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
18899 : : struct mlx5_flow_meter_def_policy *def_policy;
18900 : : struct mlx5_flow_tbl_resource *jump_tbl;
18901 : : struct mlx5_flow_tbl_data_entry *tbl_data;
18902 : : uint8_t egress, transfer;
18903 : : struct rte_flow_error error;
18904 : : struct mlx5_meter_policy_acts acts[RTE_COLORS];
18905 : 0 : bool match_src_port[RTE_COLORS] = {false};
18906 : : int ret;
18907 : :
18908 : 0 : egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
18909 : 0 : transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
18910 : 0 : def_policy = mtrmng->def_policy[domain];
18911 [ # # ]: 0 : if (!def_policy) {
18912 : 0 : def_policy = mlx5_malloc(MLX5_MEM_ZERO,
18913 : : sizeof(struct mlx5_flow_meter_def_policy),
18914 : : RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
18915 [ # # ]: 0 : if (!def_policy) {
18916 : 0 : DRV_LOG(ERR, "Failed to alloc default policy table.");
18917 : 0 : goto def_policy_error;
18918 : : }
18919 : 0 : mtrmng->def_policy[domain] = def_policy;
18920 : : /* Create the meter suffix table with SUFFIX level. */
18921 : 0 : jump_tbl = mlx5_flow_dv_tbl_resource_get(dev,
18922 : : MLX5_FLOW_TABLE_LEVEL_METER,
18923 : : egress, transfer, false, NULL, 0,
18924 : : 0, MLX5_MTR_TABLE_ID_SUFFIX, &error);
18925 [ # # ]: 0 : if (!jump_tbl) {
18926 : 0 : DRV_LOG(ERR,
18927 : : "Failed to create meter suffix table.");
18928 : 0 : goto def_policy_error;
18929 : : }
18930 : 0 : def_policy->sub_policy.jump_tbl[RTE_COLOR_GREEN] = jump_tbl;
18931 : 0 : tbl_data = container_of(jump_tbl,
18932 : : struct mlx5_flow_tbl_data_entry, tbl);
18933 : 0 : def_policy->dr_jump_action[RTE_COLOR_GREEN] =
18934 : 0 : tbl_data->jump.action;
18935 : 0 : acts[RTE_COLOR_GREEN].dv_actions[0] = tbl_data->jump.action;
18936 : 0 : acts[RTE_COLOR_GREEN].actions_n = 1;
18937 : : /*
18938 : : * YELLOW has the same default policy as GREEN does.
18939 : : * G & Y share the same table and action. The 2nd time of table
18940 : : * resource getting is just to update the reference count for
18941 : : * the releasing stage.
18942 : : */
18943 : 0 : jump_tbl = mlx5_flow_dv_tbl_resource_get(dev,
18944 : : MLX5_FLOW_TABLE_LEVEL_METER,
18945 : : egress, transfer, false, NULL, 0,
18946 : : 0, MLX5_MTR_TABLE_ID_SUFFIX, &error);
18947 [ # # ]: 0 : if (!jump_tbl) {
18948 : 0 : DRV_LOG(ERR,
18949 : : "Failed to get meter suffix table.");
18950 : 0 : goto def_policy_error;
18951 : : }
18952 : 0 : def_policy->sub_policy.jump_tbl[RTE_COLOR_YELLOW] = jump_tbl;
18953 : 0 : tbl_data = container_of(jump_tbl,
18954 : : struct mlx5_flow_tbl_data_entry, tbl);
18955 : 0 : def_policy->dr_jump_action[RTE_COLOR_YELLOW] =
18956 : 0 : tbl_data->jump.action;
18957 : 0 : acts[RTE_COLOR_YELLOW].dv_actions[0] = tbl_data->jump.action;
18958 : 0 : acts[RTE_COLOR_YELLOW].actions_n = 1;
18959 : : /* Create jump action to the drop table. */
18960 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
18961 : 0 : mtrmng->drop_tbl[domain] = mlx5_flow_dv_tbl_resource_get
18962 : : (dev, MLX5_FLOW_TABLE_LEVEL_METER,
18963 : : egress, transfer, false, NULL, 0,
18964 : : 0, MLX5_MTR_TABLE_ID_DROP, &error);
18965 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
18966 : 0 : DRV_LOG(ERR, "Failed to create meter "
18967 : : "drop table for default policy.");
18968 : 0 : goto def_policy_error;
18969 : : }
18970 : : }
18971 : : /* all RED: unique Drop table for jump action. */
18972 : 0 : tbl_data = container_of(mtrmng->drop_tbl[domain],
18973 : : struct mlx5_flow_tbl_data_entry, tbl);
18974 : 0 : def_policy->dr_jump_action[RTE_COLOR_RED] =
18975 : 0 : tbl_data->jump.action;
18976 : 0 : acts[RTE_COLOR_RED].dv_actions[0] = tbl_data->jump.action;
18977 : 0 : acts[RTE_COLOR_RED].actions_n = 1;
18978 : : /* Create default policy rules. */
18979 : 0 : ret = __flow_dv_create_domain_policy_rules(dev,
18980 : : &def_policy->sub_policy,
18981 : : egress, transfer, match_src_port, acts);
18982 [ # # ]: 0 : if (ret) {
18983 : 0 : DRV_LOG(ERR, "Failed to create default policy rules.");
18984 : 0 : goto def_policy_error;
18985 : : }
18986 : : }
18987 : : return 0;
18988 : 0 : def_policy_error:
18989 : 0 : __flow_dv_destroy_domain_def_policy(dev,
18990 : : (enum mlx5_meter_domain)domain);
18991 : 0 : return -1;
18992 : : }
18993 : :
18994 : : /**
18995 : : * Create the default policy table set.
18996 : : *
18997 : : * @param[in] dev
18998 : : * Pointer to Ethernet device.
18999 : : * @return
19000 : : * 0 on success, -1 otherwise.
19001 : : */
19002 : : static int
19003 : 0 : flow_dv_create_def_policy(struct rte_eth_dev *dev)
19004 : : {
19005 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19006 : : int i;
19007 : :
19008 : : /* Non-termination policy table. */
19009 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
19010 [ # # # # ]: 0 : if (!priv->sh->config.dv_esw_en &&
19011 : : i == MLX5_MTR_DOMAIN_TRANSFER)
19012 : 0 : continue;
19013 [ # # ]: 0 : if (__flow_dv_create_domain_def_policy(dev, i)) {
19014 : 0 : DRV_LOG(ERR, "Failed to create default policy");
19015 : : /* Rollback the created default policies for others. */
19016 : 0 : flow_dv_destroy_def_policy(dev);
19017 : 0 : return -1;
19018 : : }
19019 : : }
19020 : : return 0;
19021 : : }
19022 : :
19023 : : /**
19024 : : * Create the needed meter tables.
19025 : : * Lock free, (mutex should be acquired by caller).
19026 : : *
19027 : : * @param[in] dev
19028 : : * Pointer to Ethernet device.
19029 : : * @param[in] fm
19030 : : * Meter information table.
19031 : : * @param[in] mtr_idx
19032 : : * Meter index.
19033 : : * @param[in] domain_bitmap
19034 : : * Domain bitmap.
19035 : : * @return
19036 : : * 0 on success, -1 otherwise.
19037 : : */
19038 : : static int
19039 : 0 : flow_dv_create_mtr_tbls(struct rte_eth_dev *dev,
19040 : : struct mlx5_flow_meter_info *fm,
19041 : : uint32_t mtr_idx,
19042 : : uint8_t domain_bitmap)
19043 : : {
19044 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19045 : 0 : struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
19046 : : struct rte_flow_error error;
19047 : : struct mlx5_flow_tbl_data_entry *tbl_data;
19048 : : uint8_t egress, transfer;
19049 : : void *actions[METER_ACTIONS];
19050 : : int domain, ret, i;
19051 : : struct mlx5_flow_counter *cnt;
19052 : 0 : struct mlx5_flow_dv_match_params value = {
19053 : : .size = sizeof(value.buf),
19054 : : };
19055 : 0 : struct mlx5_flow_dv_match_params matcher_para = {
19056 : : .size = sizeof(matcher_para.buf),
19057 : : };
19058 : 0 : int mtr_id_reg_c = mlx5_flow_get_reg_id(dev, MLX5_MTR_ID,
19059 : : 0, &error);
19060 : 0 : uint32_t mtr_id_mask = (UINT32_C(1) << mtrmng->max_mtr_bits) - 1;
19061 : 0 : uint8_t mtr_id_offset = priv->mtr_reg_share ? MLX5_MTR_COLOR_BITS : 0;
19062 : : struct mlx5_list_entry *entry;
19063 : 0 : struct mlx5_flow_dv_matcher matcher = {
19064 : : .mask = {
19065 : : .size = sizeof(matcher.mask.buf),
19066 : : },
19067 : : };
19068 : : struct mlx5_flow_dv_matcher *drop_matcher;
19069 : 0 : struct mlx5_flow_cb_ctx ctx = {
19070 : : .error = &error,
19071 : : .data = &matcher,
19072 : : };
19073 : : uint8_t misc_mask;
19074 : :
19075 [ # # # # ]: 0 : if (!priv->mtr_en || mtr_id_reg_c < 0) {
19076 : 0 : rte_errno = ENOTSUP;
19077 : 0 : return -1;
19078 : : }
19079 [ # # ]: 0 : for (domain = 0; domain < MLX5_MTR_DOMAIN_MAX; domain++) {
19080 [ # # ]: 0 : if (!(domain_bitmap & (1 << domain)) ||
19081 [ # # # # ]: 0 : (mtrmng->def_rule[domain] && !fm->drop_cnt))
19082 : 0 : continue;
19083 : 0 : egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
19084 : 0 : transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
19085 : : /* Create the drop table with METER DROP level. */
19086 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
19087 : 0 : mtrmng->drop_tbl[domain] = mlx5_flow_dv_tbl_resource_get(dev,
19088 : : MLX5_FLOW_TABLE_LEVEL_METER,
19089 : : egress, transfer, false, NULL, 0,
19090 : : 0, MLX5_MTR_TABLE_ID_DROP, &error);
19091 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
19092 : 0 : DRV_LOG(ERR, "Failed to create meter drop table.");
19093 : 0 : goto policy_error;
19094 : : }
19095 : : }
19096 : : /* Create default matcher in drop table. */
19097 : 0 : matcher.tbl = mtrmng->drop_tbl[domain];
19098 : 0 : tbl_data = container_of(mtrmng->drop_tbl[domain],
19099 : : struct mlx5_flow_tbl_data_entry, tbl);
19100 [ # # ]: 0 : if (!mtrmng->def_matcher[domain]) {
19101 : 0 : flow_dv_match_meta_reg_all(matcher.mask.buf, value.buf,
19102 : : (enum modify_reg)mtr_id_reg_c,
19103 : : 0, 0);
19104 : 0 : matcher.priority = MLX5_MTRS_DEFAULT_RULE_PRIORITY;
19105 : 0 : matcher.crc = rte_raw_cksum
19106 : : ((const void *)matcher.mask.buf,
19107 : : matcher.mask.size);
19108 : 0 : entry = mlx5_list_register(tbl_data->matchers, &ctx);
19109 [ # # ]: 0 : if (!entry) {
19110 : 0 : DRV_LOG(ERR, "Failed to register meter "
19111 : : "drop default matcher.");
19112 : 0 : goto policy_error;
19113 : : }
19114 : 0 : mtrmng->def_matcher[domain] = container_of(entry,
19115 : : struct mlx5_flow_dv_matcher, entry);
19116 : : }
19117 : : /* Create default rule in drop table. */
19118 [ # # ]: 0 : if (!mtrmng->def_rule[domain]) {
19119 : : i = 0;
19120 : 0 : actions[i++] = priv->sh->dr_drop_action;
19121 : 0 : flow_dv_match_meta_reg_all(matcher_para.buf, value.buf,
19122 : : (enum modify_reg)mtr_id_reg_c, 0, 0);
19123 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(mtrmng->def_matcher[domain]->mask.buf);
19124 : : __flow_dv_adjust_buf_size(&value.size, misc_mask);
19125 : 0 : ret = mlx5_flow_os_create_flow
19126 : : (mtrmng->def_matcher[domain]->matcher_object,
19127 : : (void *)&value, i, actions,
19128 : : &mtrmng->def_rule[domain]);
19129 : : if (ret) {
19130 : 0 : DRV_LOG(ERR, "Failed to create meter "
19131 : : "default drop rule for drop table.");
19132 : 0 : goto policy_error;
19133 : : }
19134 : : }
19135 [ # # ]: 0 : if (!fm->drop_cnt)
19136 : 0 : continue;
19137 : : MLX5_ASSERT(mtrmng->max_mtr_bits);
19138 [ # # ]: 0 : if (!mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1]) {
19139 : : /* Create matchers for Drop. */
19140 : 0 : flow_dv_match_meta_reg_all(matcher.mask.buf, value.buf,
19141 : : (enum modify_reg)mtr_id_reg_c, 0,
19142 : : (mtr_id_mask << mtr_id_offset));
19143 : 0 : matcher.priority = MLX5_REG_BITS - mtrmng->max_mtr_bits;
19144 : 0 : matcher.crc = rte_raw_cksum
19145 : : ((const void *)matcher.mask.buf,
19146 : : matcher.mask.size);
19147 : 0 : entry = mlx5_list_register(tbl_data->matchers, &ctx);
19148 [ # # ]: 0 : if (!entry) {
19149 : 0 : DRV_LOG(ERR,
19150 : : "Failed to register meter drop matcher.");
19151 : 0 : goto policy_error;
19152 : : }
19153 : 0 : mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1] =
19154 : : container_of(entry, struct mlx5_flow_dv_matcher,
19155 : : entry);
19156 : : }
19157 : 0 : drop_matcher =
19158 : 0 : mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1];
19159 : : /* Create drop rule, matching meter_id only. */
19160 : 0 : flow_dv_match_meta_reg_all(matcher_para.buf, value.buf,
19161 : : (enum modify_reg)mtr_id_reg_c,
19162 : : (mtr_idx << mtr_id_offset), UINT32_MAX);
19163 : : i = 0;
19164 [ # # ]: 0 : cnt = flow_dv_counter_get_by_idx(dev,
19165 : : fm->drop_cnt, NULL);
19166 : 0 : actions[i++] = cnt->action;
19167 : 0 : actions[i++] = priv->sh->dr_drop_action;
19168 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(drop_matcher->mask.buf);
19169 : : __flow_dv_adjust_buf_size(&value.size, misc_mask);
19170 : 0 : ret = mlx5_flow_os_create_flow(drop_matcher->matcher_object,
19171 : : (void *)&value, i, actions,
19172 : : &fm->drop_rule[domain]);
19173 : : if (ret) {
19174 : 0 : DRV_LOG(ERR, "Failed to create meter "
19175 : : "drop rule for drop table.");
19176 : 0 : goto policy_error;
19177 : : }
19178 : : }
19179 : : return 0;
19180 : : policy_error:
19181 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
19182 [ # # ]: 0 : if (fm->drop_rule[i]) {
19183 : : claim_zero(mlx5_flow_os_destroy_flow
19184 : : (fm->drop_rule[i]));
19185 : 0 : fm->drop_rule[i] = NULL;
19186 : : }
19187 : : }
19188 : : return -1;
19189 : : }
19190 : :
19191 : : static struct mlx5_flow_meter_sub_policy *
19192 : 0 : __flow_dv_meter_get_rss_sub_policy(struct rte_eth_dev *dev,
19193 : : struct mlx5_flow_meter_policy *mtr_policy,
19194 : : struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS],
19195 : : struct mlx5_flow_meter_sub_policy *next_sub_policy,
19196 : : bool *is_reuse)
19197 : : {
19198 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19199 : : struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
19200 : 0 : uint32_t sub_policy_idx = 0;
19201 : 0 : uint32_t hrxq_idx[MLX5_MTR_RTE_COLORS] = {0};
19202 : : uint32_t i, j;
19203 : : struct mlx5_hrxq *hrxq;
19204 : : struct mlx5_flow_handle dh;
19205 : : struct mlx5_meter_policy_action_container *act_cnt;
19206 : : uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
19207 : : uint16_t sub_policy_num;
19208 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
19209 : :
19210 : : MLX5_ASSERT(wks);
19211 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19212 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
19213 [ # # ]: 0 : if (!rss_desc[i])
19214 : 0 : continue;
19215 : 0 : hrxq = mlx5_hrxq_get(dev, rss_desc[i]);
19216 [ # # ]: 0 : if (!hrxq) {
19217 : : rte_spinlock_unlock(&mtr_policy->sl);
19218 : 0 : return NULL;
19219 : : }
19220 : 0 : hrxq_idx[i] = hrxq->idx;
19221 : : }
19222 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
19223 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
19224 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
19225 [ # # ]: 0 : for (j = 0; j < sub_policy_num; j++) {
19226 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
19227 [ # # ]: 0 : if (rss_desc[i] &&
19228 : 0 : hrxq_idx[i] !=
19229 [ # # ]: 0 : mtr_policy->sub_policys[domain][j]->rix_hrxq[i])
19230 : : break;
19231 : : }
19232 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS) {
19233 : : /*
19234 : : * Found the sub policy table with
19235 : : * the same queue per color.
19236 : : */
19237 : : rte_spinlock_unlock(&mtr_policy->sl);
19238 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++)
19239 : 0 : mlx5_hrxq_release(dev, hrxq_idx[i]);
19240 : 0 : *is_reuse = true;
19241 : 0 : return mtr_policy->sub_policys[domain][j];
19242 : : }
19243 : : }
19244 : : /* Create sub policy. */
19245 [ # # ]: 0 : if (!mtr_policy->sub_policys[domain][0]->rix_hrxq[RTE_COLOR_GREEN] &&
19246 : : !mtr_policy->sub_policys[domain][0]->rix_hrxq[RTE_COLOR_YELLOW]) {
19247 : : /* Reuse the first pre-allocated sub_policy. */
19248 : : sub_policy = mtr_policy->sub_policys[domain][0];
19249 : 0 : sub_policy_idx = sub_policy->idx;
19250 : : } else {
19251 : 0 : sub_policy = mlx5_ipool_zmalloc
19252 : 0 : (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
19253 : : &sub_policy_idx);
19254 [ # # ]: 0 : if (!sub_policy ||
19255 [ # # ]: 0 : sub_policy_idx > MLX5_MAX_SUB_POLICY_TBL_NUM) {
19256 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++)
19257 : 0 : mlx5_hrxq_release(dev, hrxq_idx[i]);
19258 : 0 : goto rss_sub_policy_error;
19259 : : }
19260 : 0 : sub_policy->idx = sub_policy_idx;
19261 : 0 : sub_policy->main_policy = mtr_policy;
19262 : : }
19263 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
19264 [ # # ]: 0 : if (!rss_desc[i])
19265 : 0 : continue;
19266 : 0 : sub_policy->rix_hrxq[i] = hrxq_idx[i];
19267 [ # # ]: 0 : if (mtr_policy->is_hierarchy) {
19268 : : act_cnt = &mtr_policy->act_cnt[i];
19269 : 0 : act_cnt->next_sub_policy = next_sub_policy;
19270 : 0 : mlx5_hrxq_release(dev, hrxq_idx[i]);
19271 : : } else {
19272 : : /*
19273 : : * Overwrite the last action from
19274 : : * RSS action to Queue action.
19275 : : */
19276 : 0 : hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
19277 : : hrxq_idx[i]);
19278 [ # # ]: 0 : if (!hrxq) {
19279 : 0 : DRV_LOG(ERR, "Failed to get policy hrxq");
19280 : 0 : goto rss_sub_policy_error;
19281 : : }
19282 : : act_cnt = &mtr_policy->act_cnt[i];
19283 [ # # # # ]: 0 : if (act_cnt->rix_mark || act_cnt->modify_hdr) {
19284 : : memset(&dh, 0, sizeof(struct mlx5_flow_handle));
19285 [ # # ]: 0 : if (act_cnt->rix_mark)
19286 : 0 : wks->mark = 1;
19287 : 0 : dh.fate_action = MLX5_FLOW_FATE_QUEUE;
19288 : 0 : dh.rix_hrxq = hrxq_idx[i];
19289 : 0 : mlx5_flow_drv_rxq_flags_set(dev, &dh);
19290 : : }
19291 : : }
19292 : : }
19293 [ # # ]: 0 : if (__flow_dv_create_policy_acts_rules(dev, mtr_policy,
19294 : : sub_policy, domain)) {
19295 : 0 : DRV_LOG(ERR, "Failed to create policy "
19296 : : "rules for ingress domain.");
19297 : 0 : goto rss_sub_policy_error;
19298 : : }
19299 [ # # ]: 0 : if (sub_policy != mtr_policy->sub_policys[domain][0]) {
19300 : 0 : i = (mtr_policy->sub_policy_num >>
19301 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
19302 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
19303 [ # # ]: 0 : if (i >= MLX5_MTR_RSS_MAX_SUB_POLICY) {
19304 : 0 : DRV_LOG(ERR, "No free sub-policy slot.");
19305 : 0 : goto rss_sub_policy_error;
19306 : : }
19307 : 0 : mtr_policy->sub_policys[domain][i] = sub_policy;
19308 : 0 : i++;
19309 : 0 : mtr_policy->sub_policy_num &= ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
19310 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain));
19311 : 0 : mtr_policy->sub_policy_num |=
19312 : 0 : (i & MLX5_MTR_SUB_POLICY_NUM_MASK) <<
19313 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain);
19314 : : }
19315 : : rte_spinlock_unlock(&mtr_policy->sl);
19316 : 0 : *is_reuse = false;
19317 : 0 : return sub_policy;
19318 : 0 : rss_sub_policy_error:
19319 [ # # ]: 0 : if (sub_policy) {
19320 : 0 : __flow_dv_destroy_sub_policy_rules(dev, sub_policy);
19321 [ # # ]: 0 : if (sub_policy != mtr_policy->sub_policys[domain][0]) {
19322 : 0 : i = (mtr_policy->sub_policy_num >>
19323 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
19324 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
19325 : 0 : mtr_policy->sub_policys[domain][i] = NULL;
19326 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
19327 : 0 : sub_policy->idx);
19328 : : }
19329 : : }
19330 : : rte_spinlock_unlock(&mtr_policy->sl);
19331 : 0 : return NULL;
19332 : : }
19333 : :
19334 : : /**
19335 : : * Find the policy table for prefix table with RSS.
19336 : : *
19337 : : * @param[in] dev
19338 : : * Pointer to Ethernet device.
19339 : : * @param[in] mtr_policy
19340 : : * Pointer to meter policy table.
19341 : : * @param[in] rss_desc
19342 : : * Pointer to rss_desc
19343 : : * @return
19344 : : * Pointer to table set on success, NULL otherwise and rte_errno is set.
19345 : : */
19346 : : static struct mlx5_flow_meter_sub_policy *
19347 : 0 : flow_dv_meter_sub_policy_rss_prepare(struct rte_eth_dev *dev,
19348 : : struct mlx5_flow_meter_policy *mtr_policy,
19349 : : struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS])
19350 : : {
19351 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19352 : : struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
19353 : : struct mlx5_flow_meter_info *next_fm;
19354 : : struct mlx5_flow_meter_policy *next_policy;
19355 : : struct mlx5_flow_meter_sub_policy *next_sub_policy = NULL;
19356 : : struct mlx5_flow_meter_policy *policies[MLX5_MTR_CHAIN_MAX_NUM];
19357 : : struct mlx5_flow_meter_sub_policy *sub_policies[MLX5_MTR_CHAIN_MAX_NUM];
19358 : : uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
19359 : : bool reuse_sub_policy;
19360 : : uint32_t i = 0;
19361 : : uint32_t j = 0;
19362 : :
19363 : : while (true) {
19364 : : /* Iterate hierarchy to get all policies in this hierarchy. */
19365 : 0 : policies[i++] = mtr_policy;
19366 [ # # ]: 0 : if (!mtr_policy->is_hierarchy)
19367 : : break;
19368 [ # # ]: 0 : if (i >= MLX5_MTR_CHAIN_MAX_NUM) {
19369 : 0 : DRV_LOG(ERR, "Exceed max meter number in hierarchy.");
19370 : 0 : return NULL;
19371 : : }
19372 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19373 : 0 : next_fm = mlx5_flow_meter_hierarchy_next_meter(priv, mtr_policy, NULL);
19374 : : rte_spinlock_unlock(&mtr_policy->sl);
19375 [ # # ]: 0 : if (!next_fm) {
19376 : 0 : DRV_LOG(ERR, "Failed to get next meter in hierarchy.");
19377 : 0 : return NULL;
19378 : : }
19379 : : next_policy =
19380 : 0 : mlx5_flow_meter_policy_find(dev, next_fm->policy_id,
19381 : : NULL);
19382 : : MLX5_ASSERT(next_policy);
19383 : : mtr_policy = next_policy;
19384 : : }
19385 [ # # ]: 0 : while (i) {
19386 : : /**
19387 : : * From last policy to the first one in hierarchy,
19388 : : * create / get the sub policy for each of them.
19389 : : */
19390 : 0 : sub_policy = __flow_dv_meter_get_rss_sub_policy(dev,
19391 : : policies[--i],
19392 : : rss_desc,
19393 : : next_sub_policy,
19394 : : &reuse_sub_policy);
19395 [ # # ]: 0 : if (!sub_policy) {
19396 : 0 : DRV_LOG(ERR, "Failed to get the sub policy.");
19397 : 0 : goto err_exit;
19398 : : }
19399 [ # # ]: 0 : if (!reuse_sub_policy)
19400 : 0 : sub_policies[j++] = sub_policy;
19401 : : next_sub_policy = sub_policy;
19402 : : }
19403 : : return sub_policy;
19404 : : err_exit:
19405 [ # # ]: 0 : while (j) {
19406 : : uint16_t sub_policy_num;
19407 : :
19408 : 0 : sub_policy = sub_policies[--j];
19409 : 0 : mtr_policy = sub_policy->main_policy;
19410 : 0 : __flow_dv_destroy_sub_policy_rules(dev, sub_policy);
19411 [ # # ]: 0 : if (sub_policy != mtr_policy->sub_policys[domain][0]) {
19412 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
19413 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
19414 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
19415 : 0 : mtr_policy->sub_policys[domain][sub_policy_num - 1] =
19416 : : NULL;
19417 : 0 : sub_policy_num--;
19418 : 0 : mtr_policy->sub_policy_num &=
19419 : 0 : ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
19420 : 0 : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i));
19421 : 0 : mtr_policy->sub_policy_num |=
19422 : 0 : (sub_policy_num & MLX5_MTR_SUB_POLICY_NUM_MASK) <<
19423 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i);
19424 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
19425 : 0 : sub_policy->idx);
19426 : : }
19427 : : }
19428 : : return NULL;
19429 : : }
19430 : :
19431 : : /**
19432 : : * Check if need to create hierarchy tag rule.
19433 : : *
19434 : : * @param[in] priv
19435 : : * Pointer to mlx5_priv.
19436 : : * @param[in] mtr_policy
19437 : : * Pointer to current meter policy.
19438 : : * @param[in] src_port
19439 : : * The src port this extra rule should use.
19440 : : * @param[out] next_fm
19441 : : * Pointer to next meter in hierarchy.
19442 : : * @param[out] skip
19443 : : * Indicate if skip the tag rule creation.
19444 : : * @param[out] error
19445 : : * Perform verbose error reporting if not NULL.
19446 : : * @return
19447 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
19448 : : */
19449 : : static int
19450 : 0 : mlx5_meter_hierarchy_skip_tag_rule(struct mlx5_priv *priv,
19451 : : struct mlx5_flow_meter_policy *mtr_policy,
19452 : : int32_t src_port,
19453 : : struct mlx5_flow_meter_info **next_fm,
19454 : : bool *skip,
19455 : : struct rte_flow_error *error)
19456 : : {
19457 : : struct mlx5_flow_meter_sub_policy *sub_policy;
19458 : : struct mlx5_sub_policy_color_rule *color_rule;
19459 : : uint32_t domain = MLX5_MTR_DOMAIN_TRANSFER;
19460 : : int ret = 0;
19461 : : int i;
19462 : :
19463 : 0 : *next_fm = NULL;
19464 : 0 : *skip = false;
19465 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19466 [ # # ]: 0 : if (mtr_policy->is_hierarchy) {
19467 : 0 : *next_fm = mlx5_flow_meter_hierarchy_next_meter(priv, mtr_policy, NULL);
19468 [ # # ]: 0 : if (!*next_fm) {
19469 : 0 : ret = rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
19470 : : NULL, "Failed to find next meter in hierarchy.");
19471 : 0 : goto exit;
19472 : : }
19473 : : }
19474 [ # # ]: 0 : if (!mtr_policy->match_port) {
19475 : 0 : *skip = true;
19476 : 0 : goto exit;
19477 : : }
19478 : 0 : sub_policy = mtr_policy->sub_policys[domain][0];
19479 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
19480 [ # # ]: 0 : if (mtr_policy->act_cnt[i].fate_action != MLX5_FLOW_FATE_MTR &&
19481 : : mtr_policy->act_cnt[i].fate_action != MLX5_FLOW_FATE_PORT_ID)
19482 : 0 : continue;
19483 [ # # ]: 0 : TAILQ_FOREACH(color_rule, &sub_policy->color_rules[i], next_port)
19484 [ # # ]: 0 : if (color_rule->src_port == src_port) {
19485 : 0 : *skip = true;
19486 : 0 : goto exit;
19487 : : }
19488 : : }
19489 : 0 : exit:
19490 : : rte_spinlock_unlock(&mtr_policy->sl);
19491 : 0 : return ret;
19492 : : }
19493 : :
19494 : : /**
19495 : : * Create the sub policy tag rule for all meters in hierarchy.
19496 : : *
19497 : : * @param[in] dev
19498 : : * Pointer to Ethernet device.
19499 : : * @param[in] fm
19500 : : * Meter information table.
19501 : : * @param[in] src_port
19502 : : * The src port this extra rule should use.
19503 : : * @param[in] item
19504 : : * The src port match item.
19505 : : * @param[out] error
19506 : : * Perform verbose error reporting if not NULL.
19507 : : * @return
19508 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
19509 : : */
19510 : : static int
19511 : 0 : flow_dv_meter_hierarchy_rule_create(struct rte_eth_dev *dev,
19512 : : struct mlx5_flow_meter_info *fm,
19513 : : int32_t src_port,
19514 : : const struct rte_flow_item *item,
19515 : : struct rte_flow_error *error)
19516 : : {
19517 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19518 : : struct mlx5_flow_meter_policy *mtr_policy;
19519 : : struct mlx5_flow_meter_sub_policy *sub_policy;
19520 : 0 : struct mlx5_flow_meter_info *next_fm = NULL;
19521 : : struct mlx5_flow_meter_policy *next_policy;
19522 : : struct mlx5_flow_meter_sub_policy *next_sub_policy;
19523 : : struct mlx5_flow_tbl_data_entry *tbl_data;
19524 : : struct mlx5_sub_policy_color_rule *color_rule;
19525 : : struct mlx5_meter_policy_acts acts;
19526 : : uint32_t color_reg_c_idx;
19527 : : bool mtr_first = (src_port != UINT16_MAX) ? true : false;
19528 : 0 : struct rte_flow_attr attr = {
19529 : : .group = MLX5_FLOW_TABLE_LEVEL_POLICY,
19530 : : .priority = 0,
19531 : : .ingress = 0,
19532 : : .egress = 0,
19533 : : .transfer = 1,
19534 : : .reserved = 0,
19535 : : };
19536 : : uint32_t domain = MLX5_MTR_DOMAIN_TRANSFER;
19537 : : struct {
19538 : : struct mlx5_flow_meter_policy *fm_policy;
19539 : : struct mlx5_flow_meter_info *next_fm;
19540 : : struct mlx5_sub_policy_color_rule *tag_rule[RTE_COLORS];
19541 : 0 : } fm_info[MLX5_MTR_CHAIN_MAX_NUM] = { {0} };
19542 : : uint32_t fm_cnt = 0;
19543 : : uint32_t i, j;
19544 : :
19545 : 0 : color_reg_c_idx = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, error);
19546 : : /* Get all fms who need to create the tag color rule. */
19547 : : do {
19548 : 0 : bool skip = false;
19549 : :
19550 : 0 : mtr_policy = mlx5_flow_meter_policy_find(dev, fm->policy_id, NULL);
19551 : : MLX5_ASSERT(mtr_policy);
19552 [ # # ]: 0 : if (mlx5_meter_hierarchy_skip_tag_rule(priv, mtr_policy, src_port,
19553 : : &next_fm, &skip, error))
19554 : 0 : goto err_exit;
19555 [ # # ]: 0 : if (!skip) {
19556 : 0 : fm_info[fm_cnt].fm_policy = mtr_policy;
19557 : 0 : fm_info[fm_cnt].next_fm = next_fm;
19558 [ # # ]: 0 : if (++fm_cnt >= MLX5_MTR_CHAIN_MAX_NUM) {
19559 : 0 : rte_flow_error_set(error, errno,
19560 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
19561 : : "Exceed max meter number in hierarchy.");
19562 : 0 : goto err_exit;
19563 : : }
19564 : : }
19565 : 0 : fm = next_fm;
19566 [ # # ]: 0 : } while (fm);
19567 : : /* Create tag color rules for all needed fms. */
19568 [ # # ]: 0 : for (i = 0; i < fm_cnt; i++) {
19569 : : void *mtr_action;
19570 : :
19571 : 0 : mtr_policy = fm_info[i].fm_policy;
19572 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19573 : 0 : sub_policy = mtr_policy->sub_policys[domain][0];
19574 [ # # ]: 0 : for (j = 0; j < RTE_COLORS; j++) {
19575 : : uint8_t act_n = 0;
19576 : : struct mlx5_flow_dv_modify_hdr_resource *modify_hdr = NULL;
19577 : : struct mlx5_flow_dv_port_id_action_resource *port_action;
19578 : : uint8_t fate_action;
19579 : :
19580 [ # # ]: 0 : if (j == RTE_COLOR_RED) {
19581 : : fate_action = MLX5_FLOW_FATE_DROP;
19582 : : } else {
19583 : 0 : fate_action = mtr_policy->act_cnt[j].fate_action;
19584 : 0 : modify_hdr = mtr_policy->act_cnt[j].modify_hdr;
19585 : 0 : if (fate_action != MLX5_FLOW_FATE_MTR &&
19586 [ # # # # ]: 0 : fate_action != MLX5_FLOW_FATE_PORT_ID &&
19587 : : fate_action != MLX5_FLOW_FATE_DROP)
19588 : 0 : continue;
19589 : : }
19590 : 0 : color_rule = mlx5_malloc(MLX5_MEM_ZERO,
19591 : : sizeof(struct mlx5_sub_policy_color_rule),
19592 : : 0, SOCKET_ID_ANY);
19593 [ # # ]: 0 : if (!color_rule) {
19594 : : rte_spinlock_unlock(&mtr_policy->sl);
19595 : 0 : rte_flow_error_set(error, ENOMEM,
19596 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
19597 : : "No memory to create tag color rule.");
19598 : 0 : goto err_exit;
19599 : : }
19600 : 0 : color_rule->src_port = src_port;
19601 : : /* Prepare to create color rule. */
19602 [ # # ]: 0 : if (fate_action == MLX5_FLOW_FATE_MTR) {
19603 : 0 : next_fm = fm_info[i].next_fm;
19604 [ # # ]: 0 : if (mlx5_flow_meter_attach(priv, next_fm, &attr, error)) {
19605 : 0 : mlx5_free(color_rule);
19606 : : rte_spinlock_unlock(&mtr_policy->sl);
19607 : 0 : goto err_exit;
19608 : : }
19609 [ # # ]: 0 : mtr_action = (next_fm->color_aware && j == RTE_COLOR_YELLOW) ?
19610 [ # # ]: 0 : next_fm->meter_action_y :
19611 : : next_fm->meter_action_g;
19612 : 0 : next_policy = mlx5_flow_meter_policy_find(dev, next_fm->policy_id,
19613 : : NULL);
19614 : : MLX5_ASSERT(next_policy);
19615 : 0 : next_sub_policy = next_policy->sub_policys[domain][0];
19616 : 0 : tbl_data = container_of(next_sub_policy->tbl_rsc,
19617 : : struct mlx5_flow_tbl_data_entry, tbl);
19618 [ # # ]: 0 : if (mtr_first) {
19619 : 0 : acts.dv_actions[act_n++] = mtr_action;
19620 [ # # ]: 0 : if (modify_hdr)
19621 : 0 : acts.dv_actions[act_n++] = modify_hdr->action;
19622 : : } else {
19623 [ # # ]: 0 : if (modify_hdr)
19624 : 0 : acts.dv_actions[act_n++] = modify_hdr->action;
19625 : 0 : acts.dv_actions[act_n++] = mtr_action;
19626 : : }
19627 : 0 : acts.dv_actions[act_n++] = tbl_data->jump.action;
19628 : 0 : acts.actions_n = act_n;
19629 [ # # ]: 0 : } else if (fate_action == MLX5_FLOW_FATE_PORT_ID) {
19630 : : port_action =
19631 : 0 : mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PORT_ID],
19632 : : mtr_policy->act_cnt[j].rix_port_id_action);
19633 [ # # ]: 0 : if (!port_action) {
19634 : 0 : mlx5_free(color_rule);
19635 : : rte_spinlock_unlock(&mtr_policy->sl);
19636 : 0 : goto err_exit;
19637 : : }
19638 [ # # ]: 0 : if (modify_hdr)
19639 : 0 : acts.dv_actions[act_n++] = modify_hdr->action;
19640 : 0 : acts.dv_actions[act_n++] = port_action->action;
19641 : 0 : acts.actions_n = act_n;
19642 : : } else {
19643 : 0 : acts.dv_actions[act_n++] = mtr_policy->dr_drop_action[domain];
19644 : 0 : acts.actions_n = act_n;
19645 : : }
19646 : 0 : fm_info[i].tag_rule[j] = color_rule;
19647 : 0 : TAILQ_INSERT_TAIL(&sub_policy->color_rules[j], color_rule, next_port);
19648 [ # # ]: 0 : if (__flow_dv_create_policy_matcher(dev, color_reg_c_idx,
19649 : : MLX5_MTR_POLICY_MATCHER_PRIO, sub_policy,
19650 : : &attr, true, item, &color_rule->matcher, error)) {
19651 : : rte_spinlock_unlock(&mtr_policy->sl);
19652 : 0 : rte_flow_error_set(error, errno,
19653 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
19654 : : "Failed to create hierarchy meter matcher.");
19655 : 0 : goto err_exit;
19656 : : }
19657 [ # # ]: 0 : if (__flow_dv_create_policy_flow(dev, color_reg_c_idx, (enum rte_color)j,
19658 : : color_rule->matcher,
19659 : 0 : acts.actions_n, acts.dv_actions,
19660 : : true, item, &color_rule->rule, &attr)) {
19661 : : rte_spinlock_unlock(&mtr_policy->sl);
19662 : 0 : rte_flow_error_set(error, errno,
19663 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
19664 : : "Failed to create hierarchy meter rule.");
19665 : 0 : goto err_exit;
19666 : : }
19667 : : }
19668 : : rte_spinlock_unlock(&mtr_policy->sl);
19669 : : }
19670 : : return 0;
19671 : 0 : err_exit:
19672 [ # # ]: 0 : for (i = 0; i < fm_cnt; i++) {
19673 : 0 : mtr_policy = fm_info[i].fm_policy;
19674 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19675 : 0 : sub_policy = mtr_policy->sub_policys[domain][0];
19676 [ # # ]: 0 : for (j = 0; j < RTE_COLORS; j++) {
19677 : 0 : color_rule = fm_info[i].tag_rule[j];
19678 [ # # ]: 0 : if (!color_rule)
19679 : 0 : continue;
19680 [ # # ]: 0 : if (color_rule->rule)
19681 : : mlx5_flow_os_destroy_flow(color_rule->rule);
19682 [ # # ]: 0 : if (color_rule->matcher) {
19683 : : struct mlx5_flow_tbl_data_entry *tbl =
19684 : 0 : container_of(color_rule->matcher->tbl, typeof(*tbl), tbl);
19685 : 0 : mlx5_list_unregister(tbl->matchers, &color_rule->matcher->entry);
19686 : : }
19687 [ # # ]: 0 : if (fm_info[i].next_fm)
19688 : 0 : mlx5_flow_meter_detach(priv, fm_info[i].next_fm);
19689 [ # # ]: 0 : TAILQ_REMOVE(&sub_policy->color_rules[j], color_rule, next_port);
19690 : 0 : mlx5_free(color_rule);
19691 : : }
19692 : : rte_spinlock_unlock(&mtr_policy->sl);
19693 : : }
19694 : 0 : return -rte_errno;
19695 : : }
19696 : :
19697 : : /**
19698 : : * Destroy the sub policy table with RX queue.
19699 : : *
19700 : : * @param[in] dev
19701 : : * Pointer to Ethernet device.
19702 : : * @param[in] mtr_policy
19703 : : * Pointer to meter policy table.
19704 : : */
19705 : : static void
19706 : 0 : flow_dv_destroy_sub_policy_with_rxq(struct rte_eth_dev *dev,
19707 : : struct mlx5_flow_meter_policy *mtr_policy)
19708 : : {
19709 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19710 : : struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
19711 : : uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
19712 : : uint32_t i, j;
19713 : : uint16_t sub_policy_num, new_policy_num;
19714 : :
19715 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19716 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
19717 [ # # # ]: 0 : switch (mtr_policy->act_cnt[i].fate_action) {
19718 : 0 : case MLX5_FLOW_FATE_SHARED_RSS:
19719 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
19720 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
19721 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
19722 : : new_policy_num = sub_policy_num;
19723 [ # # ]: 0 : for (j = 0; j < sub_policy_num; j++) {
19724 : 0 : sub_policy =
19725 : 0 : mtr_policy->sub_policys[domain][j];
19726 [ # # ]: 0 : if (sub_policy) {
19727 : 0 : __flow_dv_destroy_sub_policy_rules(dev,
19728 : : sub_policy);
19729 : 0 : if (sub_policy !=
19730 [ # # ]: 0 : mtr_policy->sub_policys[domain][0]) {
19731 : 0 : mtr_policy->sub_policys[domain][j] =
19732 : : NULL;
19733 : 0 : mlx5_ipool_free
19734 : 0 : (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
19735 : 0 : sub_policy->idx);
19736 : 0 : new_policy_num--;
19737 : : }
19738 : : }
19739 : : }
19740 [ # # ]: 0 : if (new_policy_num != sub_policy_num) {
19741 : 0 : mtr_policy->sub_policy_num &=
19742 : : ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
19743 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain));
19744 : 0 : mtr_policy->sub_policy_num |=
19745 : : (new_policy_num &
19746 : : MLX5_MTR_SUB_POLICY_NUM_MASK) <<
19747 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain);
19748 : : }
19749 : : break;
19750 : 0 : case MLX5_FLOW_FATE_QUEUE:
19751 : 0 : sub_policy = mtr_policy->sub_policys[domain][0];
19752 : 0 : __flow_dv_destroy_sub_policy_rules(dev,
19753 : : sub_policy);
19754 : 0 : break;
19755 : : default:
19756 : : /*Other actions without queue and do nothing*/
19757 : : break;
19758 : : }
19759 : : }
19760 : : rte_spinlock_unlock(&mtr_policy->sl);
19761 : 0 : }
19762 : : /**
19763 : : * Check whether the DR drop action is supported on the root table or not.
19764 : : *
19765 : : * Create a simple flow with DR drop action on root table to validate
19766 : : * if DR drop action on root table is supported or not.
19767 : : *
19768 : : * @param[in] dev
19769 : : * Pointer to rte_eth_dev structure.
19770 : : *
19771 : : * @return
19772 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
19773 : : */
19774 : : int
19775 : 0 : mlx5_flow_discover_dr_action_support(struct rte_eth_dev *dev)
19776 : : {
19777 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19778 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
19779 : 0 : struct mlx5_flow_dv_match_params mask = {
19780 : : .size = sizeof(mask.buf),
19781 : : };
19782 : 0 : struct mlx5_flow_dv_match_params value = {
19783 : : .size = sizeof(value.buf),
19784 : : };
19785 : 0 : struct mlx5dv_flow_matcher_attr dv_attr = {
19786 : : .type = IBV_FLOW_ATTR_NORMAL,
19787 : : .priority = 0,
19788 : : .match_criteria_enable = 0,
19789 : : .match_mask = (void *)&mask,
19790 : : };
19791 : : struct mlx5_flow_tbl_resource *tbl = NULL;
19792 : : void *matcher = NULL;
19793 : : void *flow = NULL;
19794 : : int ret = -1;
19795 : :
19796 : 0 : tbl = mlx5_flow_dv_tbl_resource_get(dev, 0, 0, 0, false, NULL,
19797 : : 0, 0, 0, NULL);
19798 [ # # ]: 0 : if (!tbl)
19799 : 0 : goto err;
19800 [ # # ]: 0 : dv_attr.match_criteria_enable = flow_dv_matcher_enable(mask.buf);
19801 : : __flow_dv_adjust_buf_size(&mask.size, dv_attr.match_criteria_enable);
19802 : 0 : ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
19803 : : tbl->obj, &matcher);
19804 : : if (ret)
19805 : 0 : goto err;
19806 [ # # ]: 0 : __flow_dv_adjust_buf_size(&value.size, dv_attr.match_criteria_enable);
19807 : 0 : ret = mlx5_flow_os_create_flow(matcher, (void *)&value, 1,
19808 : : &sh->dr_drop_action, &flow);
19809 : 0 : err:
19810 : : /*
19811 : : * If DR drop action is not supported on root table, flow create will
19812 : : * be failed with EOPNOTSUPP or EPROTONOSUPPORT.
19813 : : */
19814 [ # # ]: 0 : if (!flow) {
19815 [ # # ]: 0 : if (matcher &&
19816 [ # # ]: 0 : (errno == EPROTONOSUPPORT || errno == EOPNOTSUPP))
19817 : 0 : DRV_LOG(INFO, "DR drop action is not supported in root table.");
19818 : : else
19819 : 0 : DRV_LOG(ERR, "Unexpected error in DR drop action support detection");
19820 : : ret = -1;
19821 : : } else {
19822 : : claim_zero(mlx5_flow_os_destroy_flow(flow));
19823 : : }
19824 [ # # ]: 0 : if (matcher)
19825 : : claim_zero(mlx5_flow_os_destroy_flow_matcher(matcher));
19826 [ # # ]: 0 : if (tbl)
19827 : 0 : mlx5_flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
19828 : 0 : return ret;
19829 : : }
19830 : :
19831 : : /**
19832 : : * Validate the batch counter support in root table.
19833 : : *
19834 : : * Create a simple flow with invalid counter and drop action on root table to
19835 : : * validate if batch counter with offset on root table is supported or not.
19836 : : *
19837 : : * @param[in] dev
19838 : : * Pointer to rte_eth_dev structure.
19839 : : *
19840 : : * @return
19841 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
19842 : : */
19843 : : int
19844 : 0 : mlx5_flow_dv_discover_counter_offset_support(struct rte_eth_dev *dev)
19845 : : {
19846 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19847 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
19848 : 0 : struct mlx5_flow_dv_match_params mask = {
19849 : : .size = sizeof(mask.buf),
19850 : : };
19851 : 0 : struct mlx5_flow_dv_match_params value = {
19852 : : .size = sizeof(value.buf),
19853 : : };
19854 : 0 : struct mlx5dv_flow_matcher_attr dv_attr = {
19855 : : .type = IBV_FLOW_ATTR_NORMAL,
19856 : : .flags = IBV_FLOW_ATTR_FLAGS_EGRESS,
19857 : : .priority = 0,
19858 : : .match_criteria_enable = 0,
19859 : : .match_mask = (void *)&mask,
19860 : : };
19861 : 0 : void *actions[2] = { 0 };
19862 : : struct mlx5_flow_tbl_resource *tbl = NULL;
19863 : : struct mlx5_devx_obj *dcs = NULL;
19864 : : void *matcher = NULL;
19865 : : void *flow = NULL;
19866 : : int ret = -1;
19867 : :
19868 : 0 : tbl = mlx5_flow_dv_tbl_resource_get(dev, 0, 1, 0, false, NULL,
19869 : : 0, 0, 0, NULL);
19870 [ # # ]: 0 : if (!tbl)
19871 : 0 : goto err;
19872 : 0 : dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0x4);
19873 [ # # ]: 0 : if (!dcs)
19874 : 0 : goto err;
19875 : 0 : ret = mlx5_flow_os_create_flow_action_count(dcs->obj, UINT16_MAX,
19876 : : &actions[0]);
19877 : : if (ret)
19878 : 0 : goto err;
19879 [ # # ]: 0 : dv_attr.match_criteria_enable = flow_dv_matcher_enable(mask.buf);
19880 : : __flow_dv_adjust_buf_size(&mask.size, dv_attr.match_criteria_enable);
19881 : 0 : ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
19882 : : tbl->obj, &matcher);
19883 : : if (ret)
19884 : 0 : goto err;
19885 [ # # ]: 0 : __flow_dv_adjust_buf_size(&value.size, dv_attr.match_criteria_enable);
19886 : : ret = mlx5_flow_os_create_flow(matcher, (void *)&value, 1,
19887 : : actions, &flow);
19888 : 0 : err:
19889 : : /*
19890 : : * If batch counter with offset is not supported, the driver will not
19891 : : * validate the invalid offset value, flow create should success.
19892 : : * In this case, it means batch counter is not supported in root table.
19893 : : *
19894 : : * Otherwise, if flow create is failed, counter offset is supported.
19895 : : */
19896 [ # # ]: 0 : if (flow) {
19897 : 0 : DRV_LOG(INFO, "Batch counter is not supported in root "
19898 : : "table. Switch to fallback mode.");
19899 : 0 : rte_errno = ENOTSUP;
19900 : : ret = -rte_errno;
19901 : : claim_zero(mlx5_flow_os_destroy_flow(flow));
19902 : : } else {
19903 : : /* Check matcher to make sure validate fail at flow create. */
19904 [ # # # # ]: 0 : if (!matcher || (matcher && errno != EINVAL))
19905 : 0 : DRV_LOG(ERR, "Unexpected error in counter offset "
19906 : : "support detection");
19907 : : ret = 0;
19908 : : }
19909 [ # # ]: 0 : if (actions[0])
19910 : : claim_zero(mlx5_flow_os_destroy_flow_action(actions[0]));
19911 [ # # ]: 0 : if (matcher)
19912 : : claim_zero(mlx5_flow_os_destroy_flow_matcher(matcher));
19913 [ # # ]: 0 : if (tbl)
19914 : 0 : mlx5_flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
19915 [ # # ]: 0 : if (dcs)
19916 : 0 : claim_zero(mlx5_devx_cmd_destroy(dcs));
19917 : 0 : return ret;
19918 : : }
19919 : :
19920 : : /**
19921 : : * Query a devx counter.
19922 : : *
19923 : : * @param[in] dev
19924 : : * Pointer to the Ethernet device structure.
19925 : : * @param[in] cnt
19926 : : * Index to the flow counter.
19927 : : * @param[in] clear
19928 : : * Set to clear the counter statistics.
19929 : : * @param[out] pkts
19930 : : * The statistics value of packets.
19931 : : * @param[out] bytes
19932 : : * The statistics value of bytes.
19933 : : *
19934 : : * @return
19935 : : * 0 on success, otherwise return -1.
19936 : : */
19937 : : static int
19938 : 0 : flow_dv_counter_query(struct rte_eth_dev *dev, uint32_t counter, bool clear,
19939 : : uint64_t *pkts, uint64_t *bytes, void **action)
19940 : : {
19941 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19942 : : struct mlx5_flow_counter *cnt;
19943 : : uint64_t inn_pkts, inn_bytes;
19944 : : int ret;
19945 : :
19946 [ # # ]: 0 : if (!priv->sh->cdev->config.devx)
19947 : : return -1;
19948 : :
19949 : 0 : ret = _flow_dv_query_count(dev, counter, &inn_pkts, &inn_bytes);
19950 [ # # ]: 0 : if (ret)
19951 : : return -1;
19952 : : cnt = flow_dv_counter_get_by_idx(dev, counter, NULL);
19953 [ # # ]: 0 : if (cnt && action)
19954 : 0 : *action = cnt->action;
19955 : :
19956 : 0 : *pkts = inn_pkts - cnt->hits;
19957 : 0 : *bytes = inn_bytes - cnt->bytes;
19958 [ # # ]: 0 : if (clear) {
19959 : 0 : cnt->hits = inn_pkts;
19960 : 0 : cnt->bytes = inn_bytes;
19961 : : }
19962 : : return 0;
19963 : : }
19964 : :
19965 : : /**
19966 : : * Get aged-out flows.
19967 : : *
19968 : : * @param[in] dev
19969 : : * Pointer to the Ethernet device structure.
19970 : : * @param[in] context
19971 : : * The address of an array of pointers to the aged-out flows contexts.
19972 : : * @param[in] nb_contexts
19973 : : * The length of context array pointers.
19974 : : * @param[out] error
19975 : : * Perform verbose error reporting if not NULL. Initialized in case of
19976 : : * error only.
19977 : : *
19978 : : * @return
19979 : : * how many contexts get in success, otherwise negative errno value.
19980 : : * if nb_contexts is 0, return the amount of all aged contexts.
19981 : : * if nb_contexts is not 0 , return the amount of aged flows reported
19982 : : * in the context array.
19983 : : * @note: only stub for now
19984 : : */
19985 : : static int
19986 : 0 : flow_dv_get_aged_flows(struct rte_eth_dev *dev,
19987 : : void **context,
19988 : : uint32_t nb_contexts,
19989 : : struct rte_flow_error *error)
19990 : : {
19991 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19992 : : struct mlx5_age_info *age_info;
19993 : : struct mlx5_age_param *age_param;
19994 : : struct mlx5_flow_counter *counter;
19995 : : struct mlx5_aso_age_action *act;
19996 : : int nb_flows = 0;
19997 : :
19998 [ # # ]: 0 : if (nb_contexts && !context)
19999 : 0 : return rte_flow_error_set(error, EINVAL,
20000 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
20001 : : NULL, "empty context");
20002 : 0 : age_info = GET_PORT_AGE_INFO(priv);
20003 : 0 : rte_spinlock_lock(&age_info->aged_sl);
20004 [ # # ]: 0 : LIST_FOREACH(act, &age_info->aged_aso, next) {
20005 : 0 : nb_flows++;
20006 [ # # ]: 0 : if (nb_contexts) {
20007 : 0 : context[nb_flows - 1] = act->age_params.context;
20008 [ # # ]: 0 : if (!(--nb_contexts))
20009 : : break;
20010 : : }
20011 : : }
20012 [ # # ]: 0 : TAILQ_FOREACH(counter, &age_info->aged_counters, next) {
20013 : 0 : nb_flows++;
20014 [ # # ]: 0 : if (nb_contexts) {
20015 : : age_param = MLX5_CNT_TO_AGE(counter);
20016 : 0 : context[nb_flows - 1] = age_param->context;
20017 [ # # ]: 0 : if (!(--nb_contexts))
20018 : : break;
20019 : : }
20020 : : }
20021 : : rte_spinlock_unlock(&age_info->aged_sl);
20022 : 0 : MLX5_AGE_SET(age_info, MLX5_AGE_TRIGGER);
20023 : 0 : return nb_flows;
20024 : : }
20025 : :
20026 : : /*
20027 : : * Mutex-protected thunk to lock-free flow_dv_counter_alloc().
20028 : : */
20029 : : static uint32_t
20030 : 0 : flow_dv_counter_allocate(struct rte_eth_dev *dev)
20031 : : {
20032 : 0 : return flow_dv_counter_alloc(dev, 0);
20033 : : }
20034 : :
20035 : : /**
20036 : : * Validate indirect action.
20037 : : * Dispatcher for action type specific validation.
20038 : : *
20039 : : * @param[in] dev
20040 : : * Pointer to the Ethernet device structure.
20041 : : * @param[in] conf
20042 : : * Indirect action configuration.
20043 : : * @param[in] action
20044 : : * The indirect action object to validate.
20045 : : * @param[out] error
20046 : : * Perform verbose error reporting if not NULL. Initialized in case of
20047 : : * error only.
20048 : : *
20049 : : * @return
20050 : : * 0 on success, otherwise negative errno value.
20051 : : */
20052 : : int
20053 : 0 : mlx5_flow_dv_action_validate(struct rte_eth_dev *dev,
20054 : : const struct rte_flow_indir_action_conf *conf,
20055 : : const struct rte_flow_action *action,
20056 : : struct rte_flow_error *err)
20057 : : {
20058 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
20059 : : /* called from RTE API */
20060 : :
20061 : : RTE_SET_USED(conf);
20062 [ # # # # : 0 : switch (action->type) {
# ]
20063 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
20064 : : /*
20065 : : * priv->obj_ops is set according to driver capabilities.
20066 : : * When DevX capabilities are
20067 : : * sufficient, it is set to mlx5_devx_obj_ops.
20068 : : * Otherwise, it is set to mlx5_ibv_obj_ops.
20069 : : * mlx5_ibv_obj_ops doesn't support ind_table_modify operation.
20070 : : * In this case the indirect RSS action can't be used.
20071 : : */
20072 [ # # ]: 0 : if (priv->obj_ops.ind_table_modify == NULL)
20073 : 0 : return rte_flow_error_set
20074 : : (err, ENOTSUP,
20075 : : RTE_FLOW_ERROR_TYPE_ACTION,
20076 : : NULL,
20077 : : "Indirect RSS action not supported");
20078 : 0 : return mlx5_validate_action_rss(dev, action, err);
20079 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
20080 [ # # ]: 0 : if (!priv->sh->aso_age_mng)
20081 : 0 : return rte_flow_error_set(err, ENOTSUP,
20082 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
20083 : : NULL,
20084 : : "Indirect age action not supported");
20085 : 0 : return flow_dv_validate_action_age(0, action, dev, err);
20086 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
20087 : 0 : return flow_dv_validate_action_count(dev, true, 0, false, err);
20088 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
20089 [ # # ]: 0 : if (!priv->sh->ct_aso_en)
20090 : 0 : return rte_flow_error_set(err, ENOTSUP,
20091 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
20092 : : "ASO CT is not supported");
20093 : 0 : return mlx5_validate_action_ct(dev, action->conf, err);
20094 : 0 : default:
20095 : 0 : return rte_flow_error_set(err, ENOTSUP,
20096 : : RTE_FLOW_ERROR_TYPE_ACTION,
20097 : : NULL,
20098 : : "action type not supported");
20099 : : }
20100 : : }
20101 : :
20102 : : /*
20103 : : * Check if the RSS configurations for colors of a meter policy match
20104 : : * each other, except the queues.
20105 : : *
20106 : : * @param[in] r1
20107 : : * Pointer to the first RSS flow action.
20108 : : * @param[in] r2
20109 : : * Pointer to the second RSS flow action.
20110 : : *
20111 : : * @return
20112 : : * 0 on match, 1 on conflict.
20113 : : */
20114 : : static inline int
20115 : 0 : flow_dv_mtr_policy_rss_compare(const struct rte_flow_action_rss *r1,
20116 : : const struct rte_flow_action_rss *r2)
20117 : : {
20118 [ # # ]: 0 : if (r1 == NULL || r2 == NULL)
20119 : : return 0;
20120 [ # # # # : 0 : if (!(r1->level <= 1 && r2->level <= 1) &&
# # ]
20121 [ # # ]: 0 : !(r1->level > 1 && r2->level > 1))
20122 : : return 1;
20123 [ # # ]: 0 : if (r1->func != r2->func)
20124 : : return 1;
20125 [ # # ]: 0 : if (r1->types != r2->types &&
20126 [ # # ]: 0 : !((r1->types == 0 || r1->types == RTE_ETH_RSS_IP) &&
20127 [ # # ]: 0 : (r2->types == 0 || r2->types == RTE_ETH_RSS_IP)))
20128 : : return 1;
20129 [ # # # # ]: 0 : if (r1->key || r2->key) {
20130 [ # # ]: 0 : const void *key1 = r1->key ? r1->key : mlx5_rss_hash_default_key;
20131 [ # # ]: 0 : const void *key2 = r2->key ? r2->key : mlx5_rss_hash_default_key;
20132 : :
20133 [ # # ]: 0 : if (memcmp(key1, key2, MLX5_RSS_HASH_KEY_LEN))
20134 : 0 : return 1;
20135 : : }
20136 : : return 0;
20137 : : }
20138 : :
20139 : : /**
20140 : : * Validate the meter hierarchy chain for meter policy.
20141 : : *
20142 : : * @param[in] dev
20143 : : * Pointer to the Ethernet device structure.
20144 : : * @param[in] meter_id
20145 : : * Meter id.
20146 : : * @param[in] action_flags
20147 : : * Holds the actions detected until now.
20148 : : * @param[out] is_rss
20149 : : * Is RSS or not.
20150 : : * @param[out] hierarchy_domain
20151 : : * The domain bitmap for hierarchy policy.
20152 : : * @param[out] error
20153 : : * Perform verbose error reporting if not NULL. Initialized in case of
20154 : : * error only.
20155 : : *
20156 : : * @return
20157 : : * 0 on success, otherwise negative errno value with error set.
20158 : : */
20159 : : static int
20160 : 0 : flow_dv_validate_policy_mtr_hierarchy(struct rte_eth_dev *dev,
20161 : : uint32_t meter_id,
20162 : : uint64_t action_flags,
20163 : : bool *is_rss,
20164 : : uint8_t *hierarchy_domain,
20165 : : struct rte_mtr_error *error)
20166 : : {
20167 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
20168 : : struct mlx5_flow_meter_info *fm;
20169 : : struct mlx5_flow_meter_policy *policy;
20170 : : uint8_t cnt = 1;
20171 : :
20172 [ # # ]: 0 : if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
20173 : : MLX5_FLOW_FATE_ESWITCH_ACTIONS))
20174 : 0 : return -rte_mtr_error_set(error, EINVAL,
20175 : : RTE_MTR_ERROR_TYPE_POLICER_ACTION_GREEN,
20176 : : NULL,
20177 : : "Multiple fate actions not supported.");
20178 : 0 : *hierarchy_domain = 0;
20179 : 0 : fm = mlx5_flow_meter_find(priv, meter_id, NULL);
20180 : : while (true) {
20181 [ # # ]: 0 : if (!fm)
20182 : 0 : return -rte_mtr_error_set(error, EINVAL,
20183 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
20184 : : "Meter not found in meter hierarchy.");
20185 [ # # ]: 0 : if (fm->def_policy)
20186 : 0 : return -rte_mtr_error_set(error, EINVAL,
20187 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
20188 : : "Non termination meter not supported in hierarchy.");
20189 [ # # ]: 0 : if (!fm->shared)
20190 : 0 : return -rte_mtr_error_set(error, EINVAL,
20191 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
20192 : : "Only shared meter supported in hierarchy.");
20193 : 0 : policy = mlx5_flow_meter_policy_find(dev, fm->policy_id, NULL);
20194 : : MLX5_ASSERT(policy);
20195 : : /**
20196 : : * Only inherit the supported domains of the first meter in
20197 : : * hierarchy.
20198 : : * One meter supports at least one domain.
20199 : : */
20200 [ # # ]: 0 : if (!*hierarchy_domain) {
20201 [ # # ]: 0 : if (policy->transfer)
20202 : 0 : *hierarchy_domain |=
20203 : : MLX5_MTR_DOMAIN_TRANSFER_BIT;
20204 [ # # ]: 0 : if (policy->ingress)
20205 : 0 : *hierarchy_domain |=
20206 : : MLX5_MTR_DOMAIN_INGRESS_BIT;
20207 [ # # ]: 0 : if (policy->egress)
20208 : 0 : *hierarchy_domain |= MLX5_MTR_DOMAIN_EGRESS_BIT;
20209 : : }
20210 [ # # ]: 0 : if (!policy->is_hierarchy) {
20211 : 0 : *is_rss = policy->is_rss;
20212 : : break;
20213 : : }
20214 : 0 : rte_spinlock_lock(&policy->sl);
20215 : 0 : fm = mlx5_flow_meter_hierarchy_next_meter(priv, policy, NULL);
20216 : : rte_spinlock_unlock(&policy->sl);
20217 [ # # ]: 0 : if (++cnt >= MLX5_MTR_CHAIN_MAX_NUM)
20218 : 0 : return -rte_mtr_error_set(error, EINVAL,
20219 : : RTE_MTR_ERROR_TYPE_METER_POLICY, NULL,
20220 : : "Exceed max hierarchy meter number.");
20221 : : }
20222 : 0 : return 0;
20223 : : }
20224 : :
20225 : : /**
20226 : : * Validate meter policy actions.
20227 : : * Dispatcher for action type specific validation.
20228 : : *
20229 : : * @param[in] dev
20230 : : * Pointer to the Ethernet device structure.
20231 : : * @param[in] action
20232 : : * The meter policy action object to validate.
20233 : : * @param[in] attr
20234 : : * Attributes of flow to determine steering domain.
20235 : : * @param[out] error
20236 : : * Perform verbose error reporting if not NULL. Initialized in case of
20237 : : * error only.
20238 : : *
20239 : : * @return
20240 : : * 0 on success, otherwise negative errno value.
20241 : : */
20242 : : static int
20243 : 0 : flow_dv_validate_mtr_policy_acts(struct rte_eth_dev *dev,
20244 : : const struct rte_flow_action *actions[RTE_COLORS],
20245 : : struct rte_flow_attr *attr,
20246 : : bool *is_rss,
20247 : : uint8_t *domain_bitmap,
20248 : : uint8_t *policy_mode,
20249 : : struct rte_mtr_error *error)
20250 : : {
20251 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
20252 : 0 : struct mlx5_sh_config *dev_conf = &priv->sh->config;
20253 : : const struct rte_flow_action *act;
20254 : 0 : uint64_t action_flags[RTE_COLORS] = {0};
20255 : : int actions_n;
20256 : : int i, ret;
20257 : : struct rte_flow_error flow_err;
20258 : 0 : uint8_t domain_color[RTE_COLORS] = {0};
20259 : : uint8_t def_domain = MLX5_MTR_ALL_DOMAIN_BIT;
20260 : 0 : uint8_t hierarchy_domain = 0;
20261 : : const struct rte_flow_action_meter *mtr;
20262 : : const struct rte_flow_action_meter *next_mtr = NULL;
20263 : : bool def_green = false;
20264 : : bool def_yellow = false;
20265 : 0 : const struct rte_flow_action_rss *rss_color[RTE_COLORS] = {NULL};
20266 : : /* Called from RTE API */
20267 [ # # # # : 0 : bool is_root = !(attr->group || (attr->transfer && priv->fdb_def_rule));
# # ]
20268 : :
20269 [ # # ]: 0 : if (!dev_conf->dv_esw_en)
20270 : : def_domain &= ~MLX5_MTR_DOMAIN_TRANSFER_BIT;
20271 : 0 : *domain_bitmap = def_domain;
20272 : : /* Red color could only support DROP action. */
20273 [ # # ]: 0 : if (!actions[RTE_COLOR_RED] ||
20274 [ # # ]: 0 : actions[RTE_COLOR_RED]->type != RTE_FLOW_ACTION_TYPE_DROP)
20275 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20276 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20277 : : NULL, "Red color only supports drop action.");
20278 : : /*
20279 : : * Check default policy actions:
20280 : : * Green / Yellow: no action, Red: drop action
20281 : : * Either G or Y will trigger default policy actions to be created.
20282 : : */
20283 [ # # ]: 0 : if (!actions[RTE_COLOR_GREEN] ||
20284 [ # # ]: 0 : actions[RTE_COLOR_GREEN]->type == RTE_FLOW_ACTION_TYPE_END)
20285 : : def_green = true;
20286 [ # # ]: 0 : if (!actions[RTE_COLOR_YELLOW] ||
20287 [ # # ]: 0 : actions[RTE_COLOR_YELLOW]->type == RTE_FLOW_ACTION_TYPE_END)
20288 : : def_yellow = true;
20289 [ # # ]: 0 : if (def_green && def_yellow) {
20290 : 0 : *policy_mode = MLX5_MTR_POLICY_MODE_DEF;
20291 : 0 : return 0;
20292 [ # # ]: 0 : } else if (!def_green && def_yellow) {
20293 : 0 : *policy_mode = MLX5_MTR_POLICY_MODE_OG;
20294 [ # # ]: 0 : } else if (def_green && !def_yellow) {
20295 : 0 : *policy_mode = MLX5_MTR_POLICY_MODE_OY;
20296 : : } else {
20297 : 0 : *policy_mode = MLX5_MTR_POLICY_MODE_ALL;
20298 : : }
20299 : : /* Set to empty string in case of NULL pointer access by user. */
20300 : 0 : flow_err.message = "";
20301 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
20302 : 0 : act = actions[i];
20303 : 0 : for (action_flags[i] = 0, actions_n = 0;
20304 [ # # # # ]: 0 : act && act->type != RTE_FLOW_ACTION_TYPE_END;
20305 : 0 : act++) {
20306 [ # # ]: 0 : if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
20307 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20308 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20309 : : NULL, "too many actions");
20310 [ # # # # : 0 : switch (act->type) {
# # # # #
# ]
20311 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
20312 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
20313 [ # # ]: 0 : if (!dev_conf->dv_esw_en)
20314 : 0 : return -rte_mtr_error_set(error,
20315 : : ENOTSUP,
20316 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20317 : : NULL, "PORT action validate check"
20318 : : " fail for ESW disable");
20319 : 0 : ret = flow_dv_validate_action_port_id(dev,
20320 : : action_flags[i],
20321 : : act, attr, &flow_err);
20322 [ # # ]: 0 : if (ret)
20323 : 0 : return -rte_mtr_error_set(error,
20324 : : ENOTSUP,
20325 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20326 [ # # ]: 0 : NULL, flow_err.message ?
20327 : : flow_err.message :
20328 : : "PORT action validate check fail");
20329 : 0 : ++actions_n;
20330 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_PORT_ID;
20331 : 0 : break;
20332 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
20333 : 0 : ret = flow_dv_validate_action_mark(dev, act,
20334 : : action_flags[i],
20335 : : attr, &flow_err);
20336 [ # # ]: 0 : if (ret < 0)
20337 : 0 : return -rte_mtr_error_set(error,
20338 : : ENOTSUP,
20339 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20340 [ # # ]: 0 : NULL, flow_err.message ?
20341 : : flow_err.message :
20342 : : "Mark action validate check fail");
20343 [ # # ]: 0 : if (dev_conf->dv_xmeta_en !=
20344 : : MLX5_XMETA_MODE_LEGACY)
20345 : 0 : return -rte_mtr_error_set(error,
20346 : : ENOTSUP,
20347 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20348 : : NULL, "Extend MARK action is "
20349 : : "not supported. Please try use "
20350 : : "default policy for meter.");
20351 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_MARK;
20352 : 0 : ++actions_n;
20353 : 0 : break;
20354 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TAG:
20355 : 0 : ret = flow_dv_validate_action_set_tag(dev,
20356 : : act, action_flags[i],
20357 : : attr, &flow_err);
20358 [ # # ]: 0 : if (ret)
20359 : 0 : return -rte_mtr_error_set(error,
20360 : : ENOTSUP,
20361 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20362 [ # # ]: 0 : NULL, flow_err.message ?
20363 : : flow_err.message :
20364 : : "Set tag action validate check fail");
20365 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_SET_TAG;
20366 : 0 : ++actions_n;
20367 : 0 : break;
20368 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
20369 : 0 : ret = mlx5_flow_validate_action_drop
20370 : : (dev, false, attr, &flow_err);
20371 [ # # ]: 0 : if (ret < 0)
20372 : 0 : return -rte_mtr_error_set(error,
20373 : : ENOTSUP,
20374 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20375 [ # # ]: 0 : NULL, flow_err.message ?
20376 : : flow_err.message :
20377 : : "Drop action validate check fail");
20378 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_DROP;
20379 : 0 : ++actions_n;
20380 : 0 : break;
20381 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
20382 : : /*
20383 : : * Check whether extensive
20384 : : * metadata feature is engaged.
20385 : : */
20386 [ # # ]: 0 : if (dev_conf->dv_flow_en &&
20387 [ # # ]: 0 : (dev_conf->dv_xmeta_en !=
20388 [ # # ]: 0 : MLX5_XMETA_MODE_LEGACY) &&
20389 : 0 : mlx5_flow_ext_mreg_supported(dev))
20390 : 0 : return -rte_mtr_error_set(error,
20391 : : ENOTSUP,
20392 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20393 : : NULL, "Queue action with meta "
20394 : : "is not supported. Please try use "
20395 : : "default policy for meter.");
20396 : 0 : ret = mlx5_flow_validate_action_queue(act,
20397 : : action_flags[i], dev,
20398 : : attr, &flow_err);
20399 [ # # ]: 0 : if (ret < 0)
20400 : 0 : return -rte_mtr_error_set(error,
20401 : : ENOTSUP,
20402 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20403 [ # # ]: 0 : NULL, flow_err.message ?
20404 : : flow_err.message :
20405 : : "Queue action validate check fail");
20406 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_QUEUE;
20407 : 0 : ++actions_n;
20408 : 0 : break;
20409 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
20410 [ # # ]: 0 : if (dev_conf->dv_flow_en &&
20411 [ # # ]: 0 : (dev_conf->dv_xmeta_en !=
20412 [ # # ]: 0 : MLX5_XMETA_MODE_LEGACY) &&
20413 : 0 : mlx5_flow_ext_mreg_supported(dev))
20414 : 0 : return -rte_mtr_error_set(error,
20415 : : ENOTSUP,
20416 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20417 : : NULL, "RSS action with meta "
20418 : : "is not supported. Please try use "
20419 : : "default policy for meter.");
20420 : 0 : ret = mlx5_validate_action_rss(dev, act,
20421 : : &flow_err);
20422 [ # # ]: 0 : if (ret < 0)
20423 : 0 : return -rte_mtr_error_set(error,
20424 : : ENOTSUP,
20425 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20426 [ # # ]: 0 : NULL, flow_err.message ?
20427 : : flow_err.message :
20428 : : "RSS action validate check fail");
20429 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_RSS;
20430 : 0 : ++actions_n;
20431 : : /* Either G or Y will set the RSS. */
20432 : 0 : rss_color[i] = act->conf;
20433 : 0 : break;
20434 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
20435 : 0 : ret = flow_dv_validate_action_jump(dev,
20436 : : NULL, act, action_flags[i],
20437 : : attr, true, &flow_err);
20438 [ # # ]: 0 : if (ret)
20439 : 0 : return -rte_mtr_error_set(error,
20440 : : ENOTSUP,
20441 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20442 [ # # ]: 0 : NULL, flow_err.message ?
20443 : : flow_err.message :
20444 : : "Jump action validate check fail");
20445 : 0 : ++actions_n;
20446 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_JUMP;
20447 : 0 : break;
20448 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
20449 : 0 : mtr = act->conf;
20450 [ # # # # ]: 0 : if (next_mtr && next_mtr->mtr_id != mtr->mtr_id)
20451 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20452 : : RTE_MTR_ERROR_TYPE_METER_POLICY, NULL,
20453 : : "Green and Yellow must use the same meter.");
20454 : 0 : ret = flow_dv_validate_policy_mtr_hierarchy(dev,
20455 : 0 : mtr->mtr_id,
20456 : : action_flags[i],
20457 : : is_rss,
20458 : : &hierarchy_domain,
20459 : : error);
20460 [ # # ]: 0 : if (ret)
20461 : 0 : return ret;
20462 : 0 : ++actions_n;
20463 : 0 : action_flags[i] |=
20464 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
20465 : : next_mtr = mtr;
20466 : 0 : break;
20467 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
20468 : 0 : ret = flow_dv_validate_action_modify_field(dev,
20469 : : action_flags[i], act, attr, is_root, &flow_err);
20470 [ # # ]: 0 : if (ret < 0)
20471 : 0 : return -rte_mtr_error_set(error,
20472 : : ENOTSUP,
20473 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20474 [ # # ]: 0 : NULL, flow_err.message ?
20475 : : flow_err.message :
20476 : : "Modify field action validate check fail");
20477 : 0 : ++actions_n;
20478 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_MODIFY_FIELD;
20479 : 0 : break;
20480 : : default:
20481 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20482 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20483 : : NULL,
20484 : : "Doesn't support optional action");
20485 : : }
20486 : : }
20487 [ # # ]: 0 : if (action_flags[i] & MLX5_FLOW_ACTION_PORT_ID) {
20488 : 0 : domain_color[i] = MLX5_MTR_DOMAIN_TRANSFER_BIT;
20489 [ # # ]: 0 : } else if ((action_flags[i] &
20490 : 0 : (MLX5_FLOW_ACTION_RSS | MLX5_FLOW_ACTION_QUEUE)) ||
20491 [ # # ]: 0 : (action_flags[i] & MLX5_FLOW_ACTION_MARK)) {
20492 : : /*
20493 : : * Only support MLX5_XMETA_MODE_LEGACY
20494 : : * so MARK action is only in ingress domain.
20495 : : */
20496 : 0 : domain_color[i] = MLX5_MTR_DOMAIN_INGRESS_BIT;
20497 : : } else {
20498 : 0 : domain_color[i] = def_domain;
20499 [ # # ]: 0 : if (action_flags[i] &&
20500 [ # # ]: 0 : !(action_flags[i] & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
20501 : 0 : domain_color[i] &=
20502 : : ~MLX5_MTR_DOMAIN_TRANSFER_BIT;
20503 : : }
20504 [ # # ]: 0 : if (action_flags[i] &
20505 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
20506 : 0 : domain_color[i] &= hierarchy_domain;
20507 : : /*
20508 : : * Non-termination actions only support NIC Tx domain.
20509 : : * The adjustion should be skipped when there is no
20510 : : * action or only END is provided. The default domains
20511 : : * bit-mask is set to find the MIN intersection.
20512 : : * The action flags checking should also be skipped.
20513 : : */
20514 [ # # ]: 0 : if ((def_green && i == RTE_COLOR_GREEN) ||
20515 [ # # ]: 0 : (def_yellow && i == RTE_COLOR_YELLOW))
20516 : 0 : continue;
20517 : : /*
20518 : : * Validate the drop action mutual exclusion
20519 : : * with other actions. Drop action is mutually-exclusive
20520 : : * with any other action, except for Count action.
20521 : : */
20522 [ # # ]: 0 : if ((action_flags[i] & MLX5_FLOW_ACTION_DROP) &&
20523 [ # # ]: 0 : (action_flags[i] & ~MLX5_FLOW_ACTION_DROP)) {
20524 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20525 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20526 : : NULL, "Drop action is mutually-exclusive "
20527 : : "with any other action");
20528 : : }
20529 : : /* Eswitch has few restrictions on using items and actions */
20530 [ # # ]: 0 : if (domain_color[i] & MLX5_MTR_DOMAIN_TRANSFER_BIT) {
20531 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev) &&
20532 [ # # ]: 0 : action_flags[i] & MLX5_FLOW_ACTION_MARK)
20533 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20534 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20535 : : NULL, "unsupported action MARK");
20536 [ # # ]: 0 : if (action_flags[i] & MLX5_FLOW_ACTION_QUEUE)
20537 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20538 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20539 : : NULL, "unsupported action QUEUE");
20540 [ # # ]: 0 : if (action_flags[i] & MLX5_FLOW_ACTION_RSS)
20541 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20542 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20543 : : NULL, "unsupported action RSS");
20544 [ # # ]: 0 : if (!(action_flags[i] & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
20545 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20546 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20547 : : NULL, "no fate action is found");
20548 : : } else {
20549 [ # # # # ]: 0 : if (!(action_flags[i] & MLX5_FLOW_FATE_ACTIONS) &&
20550 : : (domain_color[i] & MLX5_MTR_DOMAIN_INGRESS_BIT)) {
20551 [ # # ]: 0 : if ((domain_color[i] &
20552 : : MLX5_MTR_DOMAIN_EGRESS_BIT))
20553 : 0 : domain_color[i] =
20554 : : MLX5_MTR_DOMAIN_EGRESS_BIT;
20555 : : else
20556 : 0 : return -rte_mtr_error_set(error,
20557 : : ENOTSUP,
20558 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20559 : : NULL,
20560 : : "no fate action is found");
20561 : : }
20562 : : }
20563 : : }
20564 [ # # # # ]: 0 : if (next_mtr && *policy_mode == MLX5_MTR_POLICY_MODE_ALL) {
20565 : : uint64_t hierarchy_type_flag =
20566 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY | MLX5_FLOW_ACTION_JUMP;
20567 [ # # ]: 0 : if (!(action_flags[RTE_COLOR_GREEN] & hierarchy_type_flag) ||
20568 [ # # ]: 0 : !(action_flags[RTE_COLOR_YELLOW] & hierarchy_type_flag))
20569 : 0 : return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_METER_POLICY,
20570 : : NULL,
20571 : : "Unsupported action in meter hierarchy.");
20572 : : }
20573 : : /* If both colors have RSS, the attributes should be the same. */
20574 [ # # ]: 0 : if (flow_dv_mtr_policy_rss_compare(rss_color[RTE_COLOR_GREEN],
20575 : : rss_color[RTE_COLOR_YELLOW]))
20576 : 0 : return -rte_mtr_error_set(error, EINVAL,
20577 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20578 : : NULL, "policy RSS attr conflict");
20579 [ # # # # ]: 0 : if (rss_color[RTE_COLOR_GREEN] || rss_color[RTE_COLOR_YELLOW])
20580 : 0 : *is_rss = true;
20581 : : /* "domain_color[C]" is non-zero for each color, default is ALL. */
20582 [ # # ]: 0 : if (!def_green && !def_yellow &&
20583 [ # # ]: 0 : domain_color[RTE_COLOR_GREEN] != domain_color[RTE_COLOR_YELLOW] &&
20584 [ # # ]: 0 : !(action_flags[RTE_COLOR_GREEN] & MLX5_FLOW_ACTION_DROP) &&
20585 [ # # ]: 0 : !(action_flags[RTE_COLOR_YELLOW] & MLX5_FLOW_ACTION_DROP))
20586 : 0 : return -rte_mtr_error_set(error, EINVAL,
20587 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20588 : : NULL, "policy domains conflict");
20589 : : /*
20590 : : * At least one color policy is listed in the actions, the domains
20591 : : * to be supported should be the intersection.
20592 : : */
20593 : 0 : *domain_bitmap = domain_color[RTE_COLOR_GREEN] &
20594 : 0 : domain_color[RTE_COLOR_YELLOW];
20595 : 0 : return 0;
20596 : : }
20597 : :
20598 : : static int
20599 : 0 : flow_dv_sync_domain(struct rte_eth_dev *dev, uint32_t domains, uint32_t flags)
20600 : : {
20601 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
20602 : : int ret = 0;
20603 : :
20604 [ # # # # ]: 0 : if ((domains & RTE_PMD_MLX5_DOMAIN_BIT_NIC_RX) && priv->sh->rx_domain != NULL) {
20605 : : ret = mlx5_os_flow_dr_sync_domain(priv->sh->rx_domain,
20606 : : flags);
20607 [ # # ]: 0 : if (ret != 0)
20608 : : return ret;
20609 : : }
20610 [ # # # # ]: 0 : if ((domains & RTE_PMD_MLX5_DOMAIN_BIT_NIC_TX) && priv->sh->tx_domain != NULL) {
20611 : : ret = mlx5_os_flow_dr_sync_domain(priv->sh->tx_domain, flags);
20612 [ # # ]: 0 : if (ret != 0)
20613 : : return ret;
20614 : : }
20615 [ # # # # ]: 0 : if ((domains & RTE_PMD_MLX5_DOMAIN_BIT_FDB) && priv->sh->fdb_domain != NULL) {
20616 : : ret = mlx5_os_flow_dr_sync_domain(priv->sh->fdb_domain, flags);
20617 [ # # ]: 0 : if (ret != 0)
20618 : 0 : return ret;
20619 : : }
20620 : : return 0;
20621 : : }
20622 : :
20623 : : /**
20624 : : * Discover the number of available flow priorities
20625 : : * by trying to create a flow with the highest priority value
20626 : : * for each possible number.
20627 : : *
20628 : : * @param[in] dev
20629 : : * Ethernet device.
20630 : : * @param[in] vprio
20631 : : * List of possible number of available priorities.
20632 : : * @param[in] vprio_n
20633 : : * Size of @p vprio array.
20634 : : * @return
20635 : : * On success, number of available flow priorities.
20636 : : * On failure, a negative errno-style code and rte_errno is set.
20637 : : */
20638 : : static int
20639 : 0 : flow_dv_discover_priorities(struct rte_eth_dev *dev,
20640 : : const uint16_t *vprio, int vprio_n)
20641 : : {
20642 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
20643 : 0 : struct mlx5_indexed_pool *pool = priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW];
20644 : : struct rte_flow_item_eth eth;
20645 : 0 : struct rte_flow_item item = {
20646 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
20647 : : .spec = ð,
20648 : : .mask = ð,
20649 : : };
20650 : 0 : struct mlx5_flow_dv_matcher matcher = {
20651 : : .mask = {
20652 : : .size = sizeof(matcher.mask.buf),
20653 : : },
20654 : : };
20655 : : union mlx5_flow_tbl_key tbl_key;
20656 : : struct mlx5_flow flow;
20657 : : void *action;
20658 : : struct rte_flow_error error;
20659 : : uint8_t misc_mask;
20660 : : int i, err, ret = -ENOTSUP;
20661 : :
20662 : : /*
20663 : : * Prepare a flow with a catch-all pattern and a drop action.
20664 : : * Use drop queue, because shared drop action may be unavailable.
20665 : : */
20666 : 0 : action = priv->drop_queue.hrxq->action;
20667 [ # # ]: 0 : if (action == NULL) {
20668 : 0 : DRV_LOG(ERR, "Priority discovery requires a drop action");
20669 : 0 : rte_errno = ENOTSUP;
20670 : 0 : return -rte_errno;
20671 : : }
20672 : : memset(&flow, 0, sizeof(flow));
20673 : 0 : flow.handle = mlx5_ipool_zmalloc(pool, &flow.handle_idx);
20674 [ # # ]: 0 : if (flow.handle == NULL) {
20675 : 0 : DRV_LOG(ERR, "Cannot create flow handle");
20676 : 0 : rte_errno = ENOMEM;
20677 : 0 : return -rte_errno;
20678 : : }
20679 : 0 : flow.ingress = true;
20680 : 0 : flow.dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param);
20681 : 0 : flow.dv.actions[0] = action;
20682 : 0 : flow.dv.actions_n = 1;
20683 : : memset(ð, 0, sizeof(eth));
20684 : 0 : flow_dv_translate_item_eth(matcher.mask.buf, &item,
20685 : : /* inner */ false, /* group */ 0,
20686 : : MLX5_SET_MATCHER_SW_M);
20687 : 0 : flow_dv_translate_item_eth(flow.dv.value.buf, &item,
20688 : : /* inner */ false, /* group */ 0,
20689 : : MLX5_SET_MATCHER_SW_V);
20690 : 0 : matcher.crc = rte_raw_cksum(matcher.mask.buf, matcher.mask.size);
20691 [ # # ]: 0 : for (i = 0; i < vprio_n; i++) {
20692 : : /* Configure the next proposed maximum priority. */
20693 : 0 : matcher.priority = vprio[i] - 1;
20694 : : memset(&tbl_key, 0, sizeof(tbl_key));
20695 : 0 : err = flow_dv_matcher_register(dev, &matcher, &tbl_key, &flow,
20696 : : /* tunnel */ NULL,
20697 : : /* group */ 0,
20698 : : &error);
20699 [ # # ]: 0 : if (err != 0) {
20700 : : /* This action is pure SW and must always succeed. */
20701 : 0 : DRV_LOG(ERR, "Cannot register matcher");
20702 : 0 : ret = -rte_errno;
20703 : 0 : break;
20704 : : }
20705 : : /* Try to apply the flow to HW. */
20706 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(flow.handle->dvh.matcher->mask.buf);
20707 : : __flow_dv_adjust_buf_size(&flow.dv.value.size, misc_mask);
20708 : 0 : err = mlx5_flow_os_create_flow
20709 : : (flow.handle->dvh.matcher->matcher_object,
20710 : 0 : (void *)&flow.dv.value, flow.dv.actions_n,
20711 : : flow.dv.actions, &flow.handle->drv_flow);
20712 : : if (err == 0) {
20713 : 0 : claim_zero(mlx5_flow_os_destroy_flow
20714 : : (flow.handle->drv_flow));
20715 : 0 : flow.handle->drv_flow = NULL;
20716 : : }
20717 : 0 : claim_zero(flow_dv_matcher_release(dev, flow.handle));
20718 [ # # ]: 0 : if (err != 0)
20719 : : break;
20720 : 0 : ret = vprio[i];
20721 : : }
20722 : 0 : mlx5_ipool_free(pool, flow.handle_idx);
20723 : : /* Set rte_errno if no expected priority value matched. */
20724 [ # # ]: 0 : if (ret < 0)
20725 : 0 : rte_errno = -ret;
20726 : : return ret;
20727 : : }
20728 : :
20729 : : const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops = {
20730 : : .list_create = mlx5_flow_legacy_list_create,
20731 : : .list_destroy = mlx5_flow_legacy_list_destroy,
20732 : : .validate = mlx5_flow_dv_validate,
20733 : : .prepare = flow_dv_prepare,
20734 : : .translate = flow_dv_translate,
20735 : : .apply = flow_dv_apply,
20736 : : .remove = flow_dv_remove,
20737 : : .destroy = flow_dv_destroy,
20738 : : .query = flow_dv_query,
20739 : : .create_mtr_tbls = flow_dv_create_mtr_tbls,
20740 : : .destroy_mtr_tbls = flow_dv_destroy_mtr_tbls,
20741 : : .destroy_mtr_drop_tbls = flow_dv_destroy_mtr_drop_tbls,
20742 : : .create_meter = flow_dv_mtr_alloc,
20743 : : .free_meter = flow_dv_aso_mtr_release_to_pool,
20744 : : .validate_mtr_acts = flow_dv_validate_mtr_policy_acts,
20745 : : .create_mtr_acts = flow_dv_create_mtr_policy_acts,
20746 : : .destroy_mtr_acts = flow_dv_destroy_mtr_policy_acts,
20747 : : .create_policy_rules = flow_dv_create_policy_rules,
20748 : : .destroy_policy_rules = flow_dv_destroy_policy_rules,
20749 : : .create_def_policy = flow_dv_create_def_policy,
20750 : : .destroy_def_policy = flow_dv_destroy_def_policy,
20751 : : .meter_sub_policy_rss_prepare = flow_dv_meter_sub_policy_rss_prepare,
20752 : : .meter_hierarchy_rule_create = flow_dv_meter_hierarchy_rule_create,
20753 : : .destroy_sub_policy_with_rxq = flow_dv_destroy_sub_policy_with_rxq,
20754 : : .counter_alloc = flow_dv_counter_allocate,
20755 : : .counter_free = flow_dv_counter_free,
20756 : : .counter_query = flow_dv_counter_query,
20757 : : .get_aged_flows = flow_dv_get_aged_flows,
20758 : : .action_validate = mlx5_flow_dv_action_validate,
20759 : : .action_create = mlx5_flow_dv_action_create,
20760 : : .action_destroy = mlx5_flow_dv_action_destroy,
20761 : : .action_update = mlx5_flow_dv_action_update,
20762 : : .action_query = mlx5_flow_dv_action_query,
20763 : : .sync_domain = flow_dv_sync_domain,
20764 : : .discover_priorities = flow_dv_discover_priorities,
20765 : : .item_create = mlx5_flow_dv_item_create,
20766 : : .item_release = mlx5_flow_dv_item_release,
20767 : : };
20768 : :
20769 : : #endif /* HAVE_IBV_FLOW_DV_SUPPORT */
|