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 : : * 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 : : 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 : : 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 : : 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 : : 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 : : struct field_modify_info modify_ipv6_traffic_class[] = {
257 : : {1, 0, MLX5_MODI_OUT_IPV6_TRAFFIC_CLASS},
258 : : {0, 0, 0},
259 : : };
260 : :
261 : : 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 : : 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 : 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 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 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 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 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 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 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 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 flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
988 : : MLX5_MODIFICATION_TYPE_ADD, error);
989 : : }
990 : :
991 : : enum mlx5_modification_field 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(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(reg_to_field));
1040 : 0 : actions[i] = (struct mlx5_modification_cmd) {
1041 : : .action_type = MLX5_MODIFICATION_TYPE_SET,
1042 : 0 : .field = 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 : : MLX5_ASSERT((unsigned int)ret < RTE_DIM(reg_to_field));
1092 : 0 : reg_type = reg_to_field[ret];
1093 : : MLX5_ASSERT(reg_type > 0);
1094 : 0 : reg_c_x[0] = (struct field_modify_info){4, 0, reg_type};
1095 : 0 : return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1096 : : MLX5_MODIFICATION_TYPE_SET, error);
1097 : : }
1098 : :
1099 : : /**
1100 : : * Convert internal COPY_REG action to DV specification.
1101 : : *
1102 : : * @param[in] dev
1103 : : * Pointer to the rte_eth_dev structure.
1104 : : * @param[in,out] res
1105 : : * Pointer to the modify-header resource.
1106 : : * @param[in] action
1107 : : * Pointer to action specification.
1108 : : * @param[out] error
1109 : : * Pointer to the error structure.
1110 : : *
1111 : : * @return
1112 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1113 : : */
1114 : : static int
1115 : 0 : flow_dv_convert_action_copy_mreg(struct rte_eth_dev *dev,
1116 : : struct mlx5_flow_dv_modify_hdr_resource *res,
1117 : : const struct rte_flow_action *action,
1118 : : struct rte_flow_error *error)
1119 : : {
1120 : 0 : const struct mlx5_flow_action_copy_mreg *conf = action->conf;
1121 : 0 : rte_be32_t mask = RTE_BE32(UINT32_MAX);
1122 : 0 : struct rte_flow_item item = {
1123 : : .spec = NULL,
1124 : : .mask = &mask,
1125 : : };
1126 : 0 : struct field_modify_info reg_src[] = {
1127 : 0 : {4, 0, reg_to_field[conf->src]},
1128 : : {0, 0, 0},
1129 : : };
1130 : 0 : struct field_modify_info reg_dst = {
1131 : : .offset = 0,
1132 : 0 : .id = reg_to_field[conf->dst],
1133 : : };
1134 : : /* Adjust reg_c[0] usage according to reported mask. */
1135 [ # # # # ]: 0 : if (conf->dst == REG_C_0 || conf->src == REG_C_0) {
1136 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1137 : 0 : uint32_t reg_c0 = priv->sh->dv_regc0_mask;
1138 : :
1139 : : MLX5_ASSERT(reg_c0);
1140 : : MLX5_ASSERT(priv->sh->config.dv_xmeta_en !=
1141 : : MLX5_XMETA_MODE_LEGACY);
1142 [ # # ]: 0 : if (conf->dst == REG_C_0) {
1143 : : /* Copy to reg_c[0], within mask only. */
1144 : 0 : reg_dst.offset = rte_bsf32(reg_c0);
1145 [ # # ]: 0 : mask = rte_cpu_to_be_32(reg_c0 >> reg_dst.offset);
1146 : : } else {
1147 : : reg_dst.offset = 0;
1148 [ # # ]: 0 : mask = rte_cpu_to_be_32(reg_c0);
1149 : : }
1150 : : }
1151 : 0 : return flow_dv_convert_modify_action(&item,
1152 : : reg_src, ®_dst, res,
1153 : : MLX5_MODIFICATION_TYPE_COPY,
1154 : : error);
1155 : : }
1156 : :
1157 : : /**
1158 : : * Convert MARK action to DV specification. This routine is used
1159 : : * in extensive metadata only and requires metadata register to be
1160 : : * handled. In legacy mode hardware tag resource is engaged.
1161 : : *
1162 : : * @param[in] dev
1163 : : * Pointer to the rte_eth_dev structure.
1164 : : * @param[in] conf
1165 : : * Pointer to MARK action specification.
1166 : : * @param[in,out] resource
1167 : : * Pointer to the modify-header resource.
1168 : : * @param[out] error
1169 : : * Pointer to the error structure.
1170 : : *
1171 : : * @return
1172 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1173 : : */
1174 : : static int
1175 : 0 : flow_dv_convert_action_mark(struct rte_eth_dev *dev,
1176 : : const struct rte_flow_action_mark *conf,
1177 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
1178 : : struct rte_flow_error *error)
1179 : : {
1180 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1181 [ # # ]: 0 : rte_be32_t mask = rte_cpu_to_be_32(MLX5_FLOW_MARK_MASK &
1182 : : priv->sh->dv_mark_mask);
1183 [ # # ]: 0 : rte_be32_t data = rte_cpu_to_be_32(conf->id) & mask;
1184 : 0 : struct rte_flow_item item = {
1185 : : .spec = &data,
1186 : : .mask = &mask,
1187 : : };
1188 : 0 : struct field_modify_info reg_c_x[] = {
1189 : : [1] = {0, 0, 0},
1190 : : };
1191 : : int reg;
1192 : :
1193 [ # # ]: 0 : if (!mask)
1194 : 0 : return rte_flow_error_set(error, EINVAL,
1195 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1196 : : NULL, "zero mark action mask");
1197 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1198 [ # # ]: 0 : if (reg < 0)
1199 : : return reg;
1200 : : MLX5_ASSERT(reg > 0);
1201 [ # # ]: 0 : if (reg == REG_C_0) {
1202 [ # # ]: 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1203 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
1204 : :
1205 [ # # ]: 0 : data = rte_cpu_to_be_32(rte_cpu_to_be_32(data) << shl_c0);
1206 [ # # ]: 0 : mask = rte_cpu_to_be_32(mask) & msk_c0;
1207 [ # # ]: 0 : mask = rte_cpu_to_be_32(mask << shl_c0);
1208 : : }
1209 : 0 : reg_c_x[0] = (struct field_modify_info){4, 0, reg_to_field[reg]};
1210 : 0 : return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1211 : : MLX5_MODIFICATION_TYPE_SET, error);
1212 : : }
1213 : :
1214 : : /**
1215 : : * Get metadata register index for specified steering domain.
1216 : : *
1217 : : * @param[in] dev
1218 : : * Pointer to the rte_eth_dev structure.
1219 : : * @param[in] attr
1220 : : * Attributes of flow to determine steering domain.
1221 : : * @param[out] error
1222 : : * Pointer to the error structure.
1223 : : *
1224 : : * @return
1225 : : * positive index on success, a negative errno value otherwise
1226 : : * and rte_errno is set.
1227 : : */
1228 : : static enum modify_reg
1229 : 0 : flow_dv_get_metadata_reg(struct rte_eth_dev *dev,
1230 : : const struct rte_flow_attr *attr,
1231 : : struct rte_flow_error *error)
1232 : : {
1233 : : int reg =
1234 [ # # ]: 0 : mlx5_flow_get_reg_id(dev, attr->transfer ?
1235 : 0 : MLX5_METADATA_FDB :
1236 [ # # ]: 0 : attr->egress ?
1237 : : MLX5_METADATA_TX :
1238 : : MLX5_METADATA_RX, 0, error);
1239 [ # # ]: 0 : if (reg < 0)
1240 : 0 : return rte_flow_error_set(error,
1241 : : ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM,
1242 : : NULL, "unavailable "
1243 : : "metadata register");
1244 : 0 : return reg;
1245 : : }
1246 : :
1247 : : /**
1248 : : * Convert SET_META action to DV specification.
1249 : : *
1250 : : * @param[in] dev
1251 : : * Pointer to the rte_eth_dev structure.
1252 : : * @param[in,out] resource
1253 : : * Pointer to the modify-header resource.
1254 : : * @param[in] attr
1255 : : * Attributes of flow that includes this item.
1256 : : * @param[in] conf
1257 : : * Pointer to action specification.
1258 : : * @param[out] error
1259 : : * Pointer to the error structure.
1260 : : *
1261 : : * @return
1262 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1263 : : */
1264 : : static int
1265 : 0 : flow_dv_convert_action_set_meta
1266 : : (struct rte_eth_dev *dev,
1267 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
1268 : : const struct rte_flow_attr *attr,
1269 : : const struct rte_flow_action_set_meta *conf,
1270 : : struct rte_flow_error *error)
1271 : : {
1272 [ # # ]: 0 : uint32_t mask = rte_cpu_to_be_32(conf->mask);
1273 [ # # ]: 0 : uint32_t data = rte_cpu_to_be_32(conf->data) & mask;
1274 : 0 : struct rte_flow_item item = {
1275 : : .spec = &data,
1276 : : .mask = &mask,
1277 : : };
1278 : 0 : struct field_modify_info reg_c_x[] = {
1279 : : [1] = {0, 0, 0},
1280 : : };
1281 : 0 : int reg = flow_dv_get_metadata_reg(dev, attr, error);
1282 : :
1283 [ # # ]: 0 : if (reg < 0)
1284 : : return reg;
1285 : : MLX5_ASSERT(reg != REG_NON);
1286 [ # # ]: 0 : if (reg == REG_C_0) {
1287 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1288 [ # # ]: 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1289 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
1290 : :
1291 [ # # ]: 0 : data = rte_cpu_to_be_32(rte_cpu_to_be_32(data) << shl_c0);
1292 [ # # ]: 0 : mask = rte_cpu_to_be_32(mask) & msk_c0;
1293 [ # # ]: 0 : mask = rte_cpu_to_be_32(mask << shl_c0);
1294 : : }
1295 : 0 : reg_c_x[0] = (struct field_modify_info){4, 0, reg_to_field[reg]};
1296 : : /* The routine expects parameters in memory as big-endian ones. */
1297 : 0 : return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1298 : : MLX5_MODIFICATION_TYPE_SET, error);
1299 : : }
1300 : :
1301 : : /**
1302 : : * Convert modify-header set IPv4 DSCP action to DV specification.
1303 : : *
1304 : : * @param[in,out] resource
1305 : : * Pointer to the modify-header resource.
1306 : : * @param[in] action
1307 : : * Pointer to action specification.
1308 : : * @param[out] error
1309 : : * Pointer to the error structure.
1310 : : *
1311 : : * @return
1312 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1313 : : */
1314 : : static int
1315 : 0 : flow_dv_convert_action_modify_ipv4_dscp
1316 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
1317 : : const struct rte_flow_action *action,
1318 : : struct rte_flow_error *error)
1319 : : {
1320 : 0 : const struct rte_flow_action_set_dscp *conf =
1321 : : (const struct rte_flow_action_set_dscp *)(action->conf);
1322 : 0 : struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
1323 : : struct rte_flow_item_ipv4 ipv4;
1324 : : struct rte_flow_item_ipv4 ipv4_mask;
1325 : :
1326 : : memset(&ipv4, 0, sizeof(ipv4));
1327 : : memset(&ipv4_mask, 0, sizeof(ipv4_mask));
1328 : 0 : ipv4.hdr.type_of_service = conf->dscp;
1329 : 0 : ipv4_mask.hdr.type_of_service = RTE_IPV4_HDR_DSCP_MASK >> 2;
1330 : 0 : item.spec = &ipv4;
1331 : 0 : item.mask = &ipv4_mask;
1332 : 0 : return flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
1333 : : MLX5_MODIFICATION_TYPE_SET, error);
1334 : : }
1335 : :
1336 : : /**
1337 : : * Convert modify-header set IPv6 DSCP action to DV specification.
1338 : : *
1339 : : * @param[in,out] resource
1340 : : * Pointer to the modify-header resource.
1341 : : * @param[in] action
1342 : : * Pointer to action specification.
1343 : : * @param[out] error
1344 : : * Pointer to the error structure.
1345 : : *
1346 : : * @return
1347 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1348 : : */
1349 : : static int
1350 : 0 : flow_dv_convert_action_modify_ipv6_dscp
1351 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
1352 : : const struct rte_flow_action *action,
1353 : : uint32_t ipv6_tc_off,
1354 : : struct rte_flow_error *error)
1355 : : {
1356 : 0 : const struct rte_flow_action_set_dscp *conf =
1357 : : (const struct rte_flow_action_set_dscp *)(action->conf);
1358 [ # # ]: 0 : struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
1359 : : struct rte_flow_item_ipv6 ipv6;
1360 : : struct rte_flow_item_ipv6 ipv6_mask;
1361 : : struct field_modify_info *modify_info;
1362 : :
1363 : : memset(&ipv6, 0, sizeof(ipv6));
1364 : : memset(&ipv6_mask, 0, sizeof(ipv6_mask));
1365 : : /*
1366 : : * Even though the DSCP bits offset of IPv6 is not byte aligned,
1367 : : * rdma-core only accept the DSCP bits byte aligned start from
1368 : : * bit 0 to 5 as to be compatible with IPv4. No need to shift the
1369 : : * bits in IPv6 case as rdma-core requires byte aligned value.
1370 : : * IPv6 DSCP uses OUT_IPV6_TRAFFIC_CLASS as ID but it starts from 2
1371 : : * bits left. Shift the mask left for IPv6 DSCP. Do it here because
1372 : : * it's needed to distinguish DSCP from ECN in data field construct
1373 : : */
1374 : 0 : ipv6.hdr.vtc_flow = conf->dscp << ipv6_tc_off;
1375 : 0 : ipv6_mask.hdr.vtc_flow = RTE_IPV6_HDR_DSCP_MASK >> (22 - ipv6_tc_off);
1376 : 0 : item.spec = &ipv6;
1377 : 0 : item.mask = &ipv6_mask;
1378 [ # # ]: 0 : if (ipv6_tc_off)
1379 : : modify_info = modify_ipv6_traffic_class;
1380 : : else
1381 : : modify_info = modify_ipv6;
1382 : 0 : return flow_dv_convert_modify_action(&item, modify_info, NULL, resource,
1383 : : MLX5_MODIFICATION_TYPE_SET, error);
1384 : : }
1385 : :
1386 : : int
1387 : 0 : mlx5_flow_item_field_width(struct rte_eth_dev *dev,
1388 : : enum rte_flow_field_id field, int inherit,
1389 : : const struct rte_flow_attr *attr,
1390 : : struct rte_flow_error *error)
1391 : : {
1392 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1393 : :
1394 [ # # # # : 0 : switch (field) {
# # # # #
# # # # #
# # # # #
# # # ]
1395 : : case RTE_FLOW_FIELD_START:
1396 : : return 32;
1397 : 0 : case RTE_FLOW_FIELD_MAC_DST:
1398 : : case RTE_FLOW_FIELD_MAC_SRC:
1399 : 0 : return 48;
1400 : 0 : case RTE_FLOW_FIELD_VLAN_TYPE:
1401 : 0 : return 16;
1402 : 0 : case RTE_FLOW_FIELD_VLAN_ID:
1403 : 0 : return 12;
1404 : 0 : case RTE_FLOW_FIELD_MAC_TYPE:
1405 : 0 : return 16;
1406 : 0 : case RTE_FLOW_FIELD_IPV4_DSCP:
1407 : 0 : return 6;
1408 : 0 : case RTE_FLOW_FIELD_IPV4_TTL:
1409 : : case RTE_FLOW_FIELD_IPV4_PROTO:
1410 : 0 : return 8;
1411 : : case RTE_FLOW_FIELD_IPV4_SRC:
1412 : : case RTE_FLOW_FIELD_IPV4_DST:
1413 : : return 32;
1414 : 0 : case RTE_FLOW_FIELD_IPV6_DSCP:
1415 : 0 : return 6;
1416 : 0 : case RTE_FLOW_FIELD_IPV6_FLOW_LABEL:
1417 : 0 : return 20;
1418 : 0 : case RTE_FLOW_FIELD_IPV6_TRAFFIC_CLASS:
1419 : : case RTE_FLOW_FIELD_IPV6_HOPLIMIT:
1420 : : case RTE_FLOW_FIELD_IPV6_PROTO:
1421 : 0 : return 8;
1422 : 0 : case RTE_FLOW_FIELD_IPV6_SRC:
1423 : : case RTE_FLOW_FIELD_IPV6_DST:
1424 : 0 : return 128;
1425 : 0 : case RTE_FLOW_FIELD_TCP_PORT_SRC:
1426 : : case RTE_FLOW_FIELD_TCP_PORT_DST:
1427 : 0 : return 16;
1428 : : case RTE_FLOW_FIELD_TCP_SEQ_NUM:
1429 : : case RTE_FLOW_FIELD_TCP_ACK_NUM:
1430 : : return 32;
1431 : 0 : case RTE_FLOW_FIELD_TCP_FLAGS:
1432 : 0 : return 9;
1433 : 0 : case RTE_FLOW_FIELD_UDP_PORT_SRC:
1434 : : case RTE_FLOW_FIELD_UDP_PORT_DST:
1435 : 0 : return 16;
1436 : 0 : case RTE_FLOW_FIELD_VXLAN_VNI:
1437 : : case RTE_FLOW_FIELD_GENEVE_VNI:
1438 : 0 : return 24;
1439 : 0 : case RTE_FLOW_FIELD_VXLAN_LAST_RSVD:
1440 : 0 : return 8;
1441 : : case RTE_FLOW_FIELD_GTP_TEID:
1442 : : case RTE_FLOW_FIELD_MPLS:
1443 : : case RTE_FLOW_FIELD_TAG:
1444 : : case RTE_FLOW_FIELD_ESP_SPI:
1445 : : case RTE_FLOW_FIELD_ESP_SEQ_NUM:
1446 : : return 32;
1447 : 0 : case RTE_FLOW_FIELD_ESP_PROTO:
1448 : 0 : return 8;
1449 : 0 : case RTE_FLOW_FIELD_MARK:
1450 : 0 : return rte_popcount32(priv->sh->dv_mark_mask);
1451 : 0 : case RTE_FLOW_FIELD_META:
1452 : 0 : return (flow_dv_get_metadata_reg(dev, attr, error) == REG_C_0) ?
1453 [ # # ]: 0 : rte_popcount32(priv->sh->dv_meta_mask) : 32;
1454 : 0 : case RTE_FLOW_FIELD_POINTER:
1455 : : case RTE_FLOW_FIELD_VALUE:
1456 : 0 : return inherit < 0 ? 0 : inherit;
1457 : 0 : case RTE_FLOW_FIELD_IPV4_ECN:
1458 : : case RTE_FLOW_FIELD_IPV6_ECN:
1459 : : case RTE_FLOW_FIELD_METER_COLOR:
1460 : 0 : return 2;
1461 : : case RTE_FLOW_FIELD_HASH_RESULT:
1462 : : return 32;
1463 : 0 : default:
1464 : : MLX5_ASSERT(false);
1465 : : }
1466 : 0 : return 0;
1467 : : }
1468 : :
1469 : : static __rte_always_inline uint8_t
1470 : : flow_modify_info_mask_8(uint32_t length, uint32_t off)
1471 : : {
1472 : 0 : return (0xffu >> (8 - length)) << off;
1473 : : }
1474 : :
1475 : : static __rte_always_inline uint16_t
1476 : : flow_modify_info_mask_16(uint32_t length, uint32_t off)
1477 : : {
1478 [ # # # # : 0 : return rte_cpu_to_be_16((0xffffu >> (16 - length)) << off);
# # # # #
# # # # #
# # # # #
# # # ]
1479 : : }
1480 : :
1481 : : static __rte_always_inline uint32_t
1482 : : flow_modify_info_mask_32(uint32_t length, uint32_t off)
1483 : : {
1484 [ # # # # : 0 : return rte_cpu_to_be_32((0xffffffffu >> (32 - length)) << off);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1485 : : }
1486 : :
1487 : : static __rte_always_inline uint32_t
1488 : : flow_modify_info_mask_32_masked(uint32_t length, uint32_t off, uint32_t post_mask)
1489 : : {
1490 : 0 : uint32_t mask = (0xffffffffu >> (32 - length)) << off;
1491 : 0 : return rte_cpu_to_be_32(mask & post_mask);
1492 : : }
1493 : :
1494 : : static __rte_always_inline enum mlx5_modification_field
1495 : : mlx5_mpls_modi_field_get(const struct rte_flow_field_data *data)
1496 : : {
1497 : 0 : return MLX5_MODI_IN_MPLS_LABEL_0 + data->tag_index;
1498 : : }
1499 : :
1500 : : static __rte_always_inline int
1501 : : flow_geneve_opt_modi_field_get(struct mlx5_priv *priv,
1502 : : const struct rte_flow_field_data *data)
1503 : : {
1504 : : #ifdef HAVE_MLX5_HWS_SUPPORT
1505 : 0 : return mlx5_geneve_opt_modi_field_get(priv, data);
1506 : : #else
1507 : : (void)priv;
1508 : : (void)data;
1509 : : DRV_LOG(ERR, "GENEVE option modification is not supported.");
1510 : : rte_errno = ENOTSUP;
1511 : : return -rte_errno;
1512 : : #endif
1513 : : }
1514 : :
1515 : : static void
1516 : 0 : mlx5_modify_flex_item(const struct rte_eth_dev *dev,
1517 : : const struct mlx5_flex_item *flex,
1518 : : const struct rte_flow_field_data *data,
1519 : : struct field_modify_info *info,
1520 : : uint32_t *mask, uint32_t width)
1521 : : {
1522 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1523 : 0 : struct mlx5_hca_flex_attr *attr = &priv->sh->cdev->config.hca_attr.flex;
1524 : : uint32_t i, j;
1525 : : int id = 0;
1526 : 0 : uint32_t pos = 0;
1527 : : const struct mlx5_flex_pattern_field *map;
1528 : 0 : uint32_t offset = data->offset;
1529 : : uint32_t width_left = width;
1530 : : uint32_t cur_width = 0;
1531 : : uint32_t tmp_ofs;
1532 : : uint32_t idx = 0;
1533 : : struct field_modify_info tmp;
1534 : : int tmp_id;
1535 : :
1536 [ # # ]: 0 : if (!attr->query_match_sample_info) {
1537 : 0 : DRV_LOG(ERR, "FW doesn't support modify field with flex item.");
1538 : 0 : return;
1539 : : }
1540 : : /*
1541 : : * search for the mapping instance until Accumulated width is no
1542 : : * less than data->offset.
1543 : : */
1544 [ # # ]: 0 : for (i = 0; i < flex->mapnum; i++) {
1545 [ # # ]: 0 : if (flex->map[i].width + pos > data->offset)
1546 : : break;
1547 : 0 : pos += flex->map[i].width;
1548 : : }
1549 [ # # ]: 0 : if (i >= flex->mapnum)
1550 : : return;
1551 [ # # ]: 0 : tmp_ofs = pos < data->offset ? data->offset - pos : 0;
1552 [ # # # # ]: 0 : for (j = i; i < flex->mapnum && width_left > 0; ) {
1553 : 0 : map = flex->map + i;
1554 : 0 : id = mlx5_flex_get_sample_id(flex, i, &pos, false);
1555 [ # # ]: 0 : if (id == -1) {
1556 : 0 : i++;
1557 : : /* All left length is dummy */
1558 [ # # ]: 0 : if (pos >= data->offset + width)
1559 : : return;
1560 : 0 : cur_width = map->width;
1561 : : /* One mapping instance covers the whole width. */
1562 [ # # ]: 0 : } else if (pos + map->width >= (data->offset + width)) {
1563 : : cur_width = width_left;
1564 : : } else {
1565 : 0 : cur_width = cur_width + map->width - tmp_ofs;
1566 : 0 : pos += map->width;
1567 : : /*
1568 : : * Continue to search next until:
1569 : : * 1. Another flex parser ID.
1570 : : * 2. Width has been covered.
1571 : : */
1572 [ # # ]: 0 : for (j = i + 1; j < flex->mapnum; j++) {
1573 : 0 : tmp_id = mlx5_flex_get_sample_id(flex, j, &pos, false);
1574 [ # # ]: 0 : if (tmp_id == -1) {
1575 : : i = j;
1576 : 0 : pos -= flex->map[j].width;
1577 : 0 : break;
1578 : : }
1579 [ # # # # ]: 0 : if (id >= (int)flex->devx_fp->num_samples ||
1580 [ # # ]: 0 : id >= MLX5_GRAPH_NODE_SAMPLE_NUM ||
1581 [ # # ]: 0 : tmp_id >= (int)flex->devx_fp->num_samples ||
1582 : : tmp_id >= MLX5_GRAPH_NODE_SAMPLE_NUM)
1583 : : return;
1584 : 0 : if (flex->devx_fp->sample_info[id].modify_field_id !=
1585 [ # # ]: 0 : flex->devx_fp->sample_info[tmp_id].modify_field_id ||
1586 : 0 : flex->map[j].shift != flex->map[j - 1].width +
1587 [ # # ]: 0 : flex->map[j - 1].shift) {
1588 : : i = j;
1589 : : break;
1590 : : }
1591 [ # # ]: 0 : if ((pos + flex->map[j].width) >= (data->offset + width)) {
1592 : : cur_width = width_left;
1593 : : break;
1594 : : }
1595 : 0 : pos += flex->map[j].width;
1596 : 0 : cur_width += flex->map[j].width;
1597 : : }
1598 : : }
1599 [ # # ]: 0 : if (cur_width > width_left)
1600 : : cur_width = width_left;
1601 [ # # # # : 0 : else if (cur_width < width_left && (j == flex->mapnum || i == flex->mapnum))
# # ]
1602 : : return;
1603 : :
1604 : : MLX5_ASSERT(id < (int)flex->devx_fp->num_samples);
1605 [ # # # # ]: 0 : if (id >= (int)flex->devx_fp->num_samples || id >= MLX5_GRAPH_NODE_SAMPLE_NUM)
1606 : : return;
1607 : : /* Use invalid entry as placeholder for DUMMY mapping. */
1608 : 0 : info[idx] = (struct field_modify_info){cur_width / CHAR_BIT, offset / CHAR_BIT,
1609 [ # # ]: 0 : id == -1 ? MLX5_MODI_INVALID :
1610 : : (enum mlx5_modification_field)
1611 : 0 : flex->devx_fp->sample_info[id].modify_field_id,
1612 : 0 : map->shift + tmp_ofs, 1};
1613 : 0 : offset += cur_width;
1614 : 0 : width_left -= cur_width;
1615 [ # # ]: 0 : if (!mask) {
1616 : 0 : info[idx].offset = (32 - cur_width - map->shift - tmp_ofs);
1617 : 0 : info[idx].size = cur_width / CHAR_BIT + info[idx].offset / CHAR_BIT;
1618 : : }
1619 : : cur_width = 0;
1620 : : tmp_ofs = 0;
1621 : 0 : idx++;
1622 : : }
1623 [ # # ]: 0 : if (unlikely(width_left > 0)) {
1624 : : MLX5_ASSERT(false);
1625 : : return;
1626 : : }
1627 [ # # ]: 0 : if (mask)
1628 : 0 : memset(mask, 0xff, data->offset / CHAR_BIT + width / CHAR_BIT);
1629 : : /* Re-order the info to follow IPv6 address. */
1630 [ # # ]: 0 : for (i = 0; i < idx / 2; i++) {
1631 : 0 : tmp = info[i];
1632 : : MLX5_ASSERT(info[i].id);
1633 : : MLX5_ASSERT(info[idx - 1 - i].id);
1634 : 0 : info[i] = info[idx - 1 - i];
1635 : 0 : info[idx - 1 - i] = tmp;
1636 : : }
1637 : : }
1638 : :
1639 : : static inline bool
1640 : : mlx5_dv_modify_ipv6_traffic_class_supported(struct mlx5_priv *priv)
1641 : : {
1642 : 0 : return priv->sh->phdev->config.ipv6_tc_fallback == MLX5_IPV6_TC_OK;
1643 : : }
1644 : :
1645 : : void
1646 : 0 : mlx5_flow_field_id_to_modify_info
1647 : : (const struct rte_flow_field_data *data,
1648 : : struct field_modify_info *info, uint32_t *mask,
1649 : : uint32_t width, struct rte_eth_dev *dev,
1650 : : const struct rte_flow_attr *attr, struct rte_flow_error *error)
1651 : : {
1652 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1653 : : enum mlx5_modification_field modi_id;
1654 : : uint32_t idx = 0;
1655 : : uint32_t off_be = 0;
1656 : : uint32_t length = 0;
1657 : :
1658 [ # # # # : 0 : switch ((int)data->field) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
1659 : : case RTE_FLOW_FIELD_START:
1660 : : /* not supported yet */
1661 : : MLX5_ASSERT(false);
1662 : : break;
1663 : 0 : case RTE_FLOW_FIELD_MAC_DST:
1664 : : MLX5_ASSERT(data->offset + width <= 48);
1665 : 0 : off_be = 48 - (data->offset + width);
1666 [ # # ]: 0 : if (off_be < 16) {
1667 [ # # ]: 0 : modi_id = CALC_MODI_ID(DMAC_15_0, data->level);
1668 : 0 : info[idx] = (struct field_modify_info){2, 4, modi_id};
1669 [ # # ]: 0 : length = off_be + width <= 16 ? width : 16 - off_be;
1670 [ # # ]: 0 : if (mask)
1671 : 0 : mask[1] = flow_modify_info_mask_16(length,
1672 : : off_be);
1673 : : else
1674 : 0 : info[idx].offset = off_be;
1675 : 0 : width -= length;
1676 [ # # ]: 0 : if (!width)
1677 : : break;
1678 : : off_be = 0;
1679 : : idx++;
1680 : : } else {
1681 : 0 : off_be -= 16;
1682 : : }
1683 [ # # ]: 0 : modi_id = CALC_MODI_ID(DMAC_47_16, data->level);
1684 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1685 [ # # ]: 0 : if (mask)
1686 : 0 : mask[0] = flow_modify_info_mask_32(width, off_be);
1687 : : else
1688 : 0 : info[idx].offset = off_be;
1689 : : break;
1690 : 0 : case RTE_FLOW_FIELD_MAC_SRC:
1691 : : MLX5_ASSERT(data->offset + width <= 48);
1692 : 0 : off_be = 48 - (data->offset + width);
1693 [ # # ]: 0 : if (off_be < 16) {
1694 [ # # ]: 0 : modi_id = CALC_MODI_ID(SMAC_15_0, data->level);
1695 : 0 : info[idx] = (struct field_modify_info){2, 4, modi_id};
1696 [ # # ]: 0 : length = off_be + width <= 16 ? width : 16 - off_be;
1697 [ # # ]: 0 : if (mask)
1698 : 0 : mask[1] = flow_modify_info_mask_16(length,
1699 : : off_be);
1700 : : else
1701 : 0 : info[idx].offset = off_be;
1702 : 0 : width -= length;
1703 [ # # ]: 0 : if (!width)
1704 : : break;
1705 : : off_be = 0;
1706 : : idx++;
1707 : : } else {
1708 : 0 : off_be -= 16;
1709 : : }
1710 [ # # ]: 0 : modi_id = CALC_MODI_ID(SMAC_47_16, data->level);
1711 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1712 [ # # ]: 0 : if (mask)
1713 : 0 : mask[0] = flow_modify_info_mask_32(width, off_be);
1714 : : else
1715 : 0 : info[idx].offset = off_be;
1716 : : break;
1717 : : case RTE_FLOW_FIELD_VLAN_TYPE:
1718 : : /* not supported yet */
1719 : : break;
1720 : 0 : case RTE_FLOW_FIELD_VLAN_ID:
1721 : : MLX5_ASSERT(data->offset + width <= 12);
1722 : 0 : off_be = 12 - (data->offset + width);
1723 : 0 : info[idx] = (struct field_modify_info){2, 0,
1724 : : MLX5_MODI_OUT_FIRST_VID};
1725 [ # # ]: 0 : if (mask)
1726 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1727 : : else
1728 : 0 : info[idx].offset = off_be;
1729 : : break;
1730 : 0 : case RTE_FLOW_FIELD_MAC_TYPE:
1731 : : MLX5_ASSERT(data->offset + width <= 16);
1732 : 0 : off_be = 16 - (data->offset + width);
1733 [ # # ]: 0 : modi_id = CALC_MODI_ID(ETHERTYPE, data->level);
1734 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
1735 [ # # ]: 0 : if (mask)
1736 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1737 : : else
1738 : 0 : info[idx].offset = off_be;
1739 : : break;
1740 : 0 : case RTE_FLOW_FIELD_IPV4_IHL:
1741 : : MLX5_ASSERT(data->offset + width <= 4);
1742 : 0 : off_be = 4 - (data->offset + width);
1743 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV4_IHL, data->level);
1744 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
1745 [ # # ]: 0 : if (mask)
1746 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1747 : : else
1748 : 0 : info[idx].offset = off_be;
1749 : : break;
1750 : 0 : case RTE_FLOW_FIELD_IPV4_DSCP:
1751 : : MLX5_ASSERT(data->offset + width <= 6);
1752 : 0 : off_be = 6 - (data->offset + width);
1753 [ # # ]: 0 : modi_id = CALC_MODI_ID(IP_DSCP, data->level);
1754 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
1755 [ # # ]: 0 : if (mask)
1756 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1757 : : else
1758 : 0 : info[idx].offset = off_be;
1759 : : break;
1760 : 0 : case RTE_FLOW_FIELD_IPV4_TOTAL_LEN:
1761 : : MLX5_ASSERT(data->offset + width <= 16);
1762 : 0 : off_be = 16 - (data->offset + width);
1763 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV4_TOTAL_LEN, data->level);
1764 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
1765 [ # # ]: 0 : if (mask)
1766 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1767 : : else
1768 : 0 : info[idx].offset = off_be;
1769 : : break;
1770 : 0 : case RTE_FLOW_FIELD_IPV4_TTL:
1771 : : MLX5_ASSERT(data->offset + width <= 8);
1772 : 0 : off_be = 8 - (data->offset + width);
1773 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV4_TTL, data->level);
1774 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
1775 [ # # ]: 0 : if (mask)
1776 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1777 : : else
1778 : 0 : info[idx].offset = off_be;
1779 : : break;
1780 : 0 : case RTE_FLOW_FIELD_IPV4_SRC:
1781 : : MLX5_ASSERT(data->offset + width <= 32);
1782 : 0 : off_be = 32 - (data->offset + width);
1783 [ # # ]: 0 : modi_id = CALC_MODI_ID(SIPV4, data->level);
1784 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1785 [ # # ]: 0 : if (mask)
1786 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1787 : : else
1788 : 0 : info[idx].offset = off_be;
1789 : : break;
1790 : 0 : case RTE_FLOW_FIELD_IPV4_DST:
1791 : : MLX5_ASSERT(data->offset + width <= 32);
1792 : 0 : off_be = 32 - (data->offset + width);
1793 [ # # ]: 0 : modi_id = CALC_MODI_ID(DIPV4, data->level);
1794 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1795 [ # # ]: 0 : if (mask)
1796 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1797 : : else
1798 : 0 : info[idx].offset = off_be;
1799 : : break;
1800 : : case RTE_FLOW_FIELD_IPV6_DSCP:
1801 : : MLX5_ASSERT(data->offset + width <= 6);
1802 : : /*
1803 : : * IPv6 DSCP uses OUT_IPV6_TRAFFIC_CLASS as ID but it starts from 2
1804 : : * bits left. Shift the mask left for IPv6 DSCP. Do it here because
1805 : : * it's needed to distinguish DSCP from ECN in data field construct
1806 : : */
1807 [ # # ]: 0 : if (mlx5_dv_modify_ipv6_traffic_class_supported(priv)) {
1808 : 0 : off_be = 6 - (data->offset + width) + MLX5_IPV6_HDR_DSCP_SHIFT;
1809 : 0 : info[idx] = (struct field_modify_info){1, 0,
1810 : : MLX5_MODI_OUT_IPV6_TRAFFIC_CLASS};
1811 : : } else {
1812 : 0 : off_be = 6 - (data->offset + width);
1813 : 0 : info[idx] = (struct field_modify_info){1, 0,
1814 : : MLX5_MODI_OUT_IP_DSCP};
1815 : : }
1816 [ # # ]: 0 : if (mask)
1817 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1818 : : else
1819 : 0 : info[idx].offset = off_be;
1820 : : break;
1821 : 0 : case RTE_FLOW_FIELD_IPV6_TRAFFIC_CLASS:
1822 : : MLX5_ASSERT(data->offset + width <= 8);
1823 : 0 : off_be = 8 - (data->offset + width);
1824 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV6_TRAFFIC_CLASS, data->level);
1825 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
1826 [ # # ]: 0 : if (mask)
1827 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1828 : : else
1829 : 0 : info[idx].offset = off_be;
1830 : : break;
1831 : 0 : case RTE_FLOW_FIELD_IPV6_FLOW_LABEL:
1832 : : MLX5_ASSERT(data->offset + width <= 20);
1833 : 0 : off_be = 20 - (data->offset + width);
1834 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV6_FLOW_LABEL, data->level);
1835 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1836 [ # # ]: 0 : if (mask)
1837 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1838 : : else
1839 : 0 : info[idx].offset = off_be;
1840 : : break;
1841 : 0 : case RTE_FLOW_FIELD_IPV6_PAYLOAD_LEN:
1842 : : MLX5_ASSERT(data->offset + width <= 16);
1843 : 0 : off_be = 16 - (data->offset + width);
1844 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV6_PAYLOAD_LEN, data->level);
1845 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
1846 [ # # ]: 0 : if (mask)
1847 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1848 : : else
1849 : 0 : info[idx].offset = off_be;
1850 : : break;
1851 : 0 : case RTE_FLOW_FIELD_IPV6_HOPLIMIT:
1852 : : MLX5_ASSERT(data->offset + width <= 8);
1853 : 0 : off_be = 8 - (data->offset + width);
1854 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV6_HOPLIMIT, data->level);
1855 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
1856 [ # # ]: 0 : if (mask)
1857 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1858 : : else
1859 : 0 : info[idx].offset = off_be;
1860 : : break;
1861 : 0 : case RTE_FLOW_FIELD_IPV6_SRC: {
1862 : : /*
1863 : : * Fields corresponding to IPv6 source address bytes
1864 : : * arranged according to network byte ordering.
1865 : : */
1866 : 0 : struct field_modify_info fields[] = {
1867 [ # # ]: 0 : { 4, 0, CALC_MODI_ID(SIPV6_127_96, data->level)},
1868 [ # # ]: 0 : { 4, 4, CALC_MODI_ID(SIPV6_95_64, data->level)},
1869 [ # # ]: 0 : { 4, 8, CALC_MODI_ID(SIPV6_63_32, data->level)},
1870 [ # # ]: 0 : { 4, 12, CALC_MODI_ID(SIPV6_31_0, data->level)},
1871 : : };
1872 : : /* First mask to be modified is the mask of 4th address byte. */
1873 : : uint32_t midx = 3;
1874 : :
1875 : : MLX5_ASSERT(data->offset + width <= 128);
1876 : 0 : off_be = 128 - (data->offset + width);
1877 [ # # ]: 0 : while (width > 0 && midx > 0) {
1878 [ # # ]: 0 : if (off_be < 32) {
1879 : 0 : info[idx] = fields[midx];
1880 : 0 : length = off_be + width <= 32 ?
1881 [ # # ]: 0 : width : 32 - off_be;
1882 [ # # ]: 0 : if (mask)
1883 [ # # ]: 0 : mask[midx] = flow_modify_info_mask_32
1884 : : (length, off_be);
1885 : : else
1886 : 0 : info[idx].offset = off_be;
1887 : 0 : width -= length;
1888 : : off_be = 0;
1889 : 0 : idx++;
1890 : : } else {
1891 : 0 : off_be -= 32;
1892 : : }
1893 : 0 : midx--;
1894 : : }
1895 [ # # ]: 0 : if (!width)
1896 : : break;
1897 : 0 : info[idx] = fields[midx];
1898 [ # # ]: 0 : if (mask)
1899 [ # # ]: 0 : mask[midx] = flow_modify_info_mask_32(width, off_be);
1900 : : else
1901 : 0 : info[idx].offset = off_be;
1902 : : break;
1903 : : }
1904 : 0 : case RTE_FLOW_FIELD_IPV6_DST: {
1905 : : /*
1906 : : * Fields corresponding to IPv6 destination address bytes
1907 : : * arranged according to network byte ordering.
1908 : : */
1909 : 0 : struct field_modify_info fields[] = {
1910 [ # # ]: 0 : { 4, 0, CALC_MODI_ID(DIPV6_127_96, data->level)},
1911 [ # # ]: 0 : { 4, 4, CALC_MODI_ID(DIPV6_95_64, data->level)},
1912 [ # # ]: 0 : { 4, 8, CALC_MODI_ID(DIPV6_63_32, data->level)},
1913 [ # # ]: 0 : { 4, 12, CALC_MODI_ID(DIPV6_31_0, data->level)},
1914 : : };
1915 : : /* First mask to be modified is the mask of 4th address byte. */
1916 : : uint32_t midx = 3;
1917 : :
1918 : : MLX5_ASSERT(data->offset + width <= 128);
1919 : 0 : off_be = 128 - (data->offset + width);
1920 [ # # ]: 0 : while (width > 0 && midx > 0) {
1921 [ # # ]: 0 : if (off_be < 32) {
1922 : 0 : info[idx] = fields[midx];
1923 : 0 : length = off_be + width <= 32 ?
1924 [ # # ]: 0 : width : 32 - off_be;
1925 [ # # ]: 0 : if (mask)
1926 [ # # ]: 0 : mask[midx] = flow_modify_info_mask_32
1927 : : (length, off_be);
1928 : : else
1929 : 0 : info[idx].offset = off_be;
1930 : 0 : width -= length;
1931 : : off_be = 0;
1932 : 0 : idx++;
1933 : : } else {
1934 : 0 : off_be -= 32;
1935 : : }
1936 : 0 : midx--;
1937 : : }
1938 [ # # ]: 0 : if (!width)
1939 : : break;
1940 : 0 : info[idx] = fields[midx];
1941 [ # # ]: 0 : if (mask)
1942 [ # # ]: 0 : mask[midx] = flow_modify_info_mask_32(width, off_be);
1943 : : else
1944 : 0 : info[idx].offset = off_be;
1945 : : break;
1946 : : }
1947 : 0 : case RTE_FLOW_FIELD_TCP_PORT_SRC:
1948 : : MLX5_ASSERT(data->offset + width <= 16);
1949 : 0 : off_be = 16 - (data->offset + width);
1950 [ # # ]: 0 : modi_id = CALC_MODI_ID(TCP_SPORT, data->level);
1951 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
1952 [ # # ]: 0 : if (mask)
1953 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1954 : : else
1955 : 0 : info[idx].offset = off_be;
1956 : : break;
1957 : 0 : case RTE_FLOW_FIELD_TCP_PORT_DST:
1958 : : MLX5_ASSERT(data->offset + width <= 16);
1959 : 0 : off_be = 16 - (data->offset + width);
1960 [ # # ]: 0 : modi_id = CALC_MODI_ID(TCP_DPORT, data->level);
1961 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
1962 [ # # ]: 0 : if (mask)
1963 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1964 : : else
1965 : 0 : info[idx].offset = off_be;
1966 : : break;
1967 : 0 : case RTE_FLOW_FIELD_TCP_SEQ_NUM:
1968 : : MLX5_ASSERT(data->offset + width <= 32);
1969 : 0 : off_be = 32 - (data->offset + width);
1970 [ # # ]: 0 : modi_id = CALC_MODI_ID(TCP_SEQ_NUM, data->level);
1971 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1972 [ # # ]: 0 : if (mask)
1973 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1974 : : else
1975 : 0 : info[idx].offset = off_be;
1976 : : break;
1977 : 0 : case RTE_FLOW_FIELD_TCP_ACK_NUM:
1978 : : MLX5_ASSERT(data->offset + width <= 32);
1979 : 0 : off_be = 32 - (data->offset + width);
1980 [ # # ]: 0 : modi_id = CALC_MODI_ID(TCP_ACK_NUM, data->level);
1981 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1982 [ # # ]: 0 : if (mask)
1983 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1984 : : else
1985 : 0 : info[idx].offset = off_be;
1986 : : break;
1987 : 0 : case RTE_FLOW_FIELD_TCP_FLAGS:
1988 : : MLX5_ASSERT(data->offset + width <= 9);
1989 : 0 : off_be = 9 - (data->offset + width);
1990 [ # # ]: 0 : modi_id = CALC_MODI_ID(TCP_FLAGS, data->level);
1991 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
1992 [ # # ]: 0 : if (mask)
1993 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1994 : : else
1995 : 0 : info[idx].offset = off_be;
1996 : : break;
1997 : 0 : case RTE_FLOW_FIELD_TCP_DATA_OFFSET:
1998 : : MLX5_ASSERT(data->offset + width <= 4);
1999 : 0 : off_be = 4 - (data->offset + width);
2000 [ # # ]: 0 : modi_id = CALC_MODI_ID(TCP_DATA_OFFSET, data->level);
2001 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
2002 [ # # ]: 0 : if (mask)
2003 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
2004 : : else
2005 : 0 : info[idx].offset = off_be;
2006 : : break;
2007 : 0 : case RTE_FLOW_FIELD_UDP_PORT_SRC:
2008 : : MLX5_ASSERT(data->offset + width <= 16);
2009 : 0 : off_be = 16 - (data->offset + width);
2010 [ # # ]: 0 : modi_id = CALC_MODI_ID(UDP_SPORT, data->level);
2011 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
2012 [ # # ]: 0 : if (mask)
2013 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
2014 : : else
2015 : 0 : info[idx].offset = off_be;
2016 : : break;
2017 : 0 : case RTE_FLOW_FIELD_UDP_PORT_DST:
2018 : : MLX5_ASSERT(data->offset + width <= 16);
2019 : 0 : off_be = 16 - (data->offset + width);
2020 [ # # ]: 0 : modi_id = CALC_MODI_ID(UDP_DPORT, data->level);
2021 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
2022 [ # # ]: 0 : if (mask)
2023 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
2024 : : else
2025 : 0 : info[idx].offset = off_be;
2026 : : break;
2027 : 0 : case RTE_FLOW_FIELD_VXLAN_VNI:
2028 : : case RTE_FLOW_FIELD_GENEVE_VNI:
2029 : : MLX5_ASSERT(data->offset + width <= 24);
2030 : : /* VNI is on bits 31-8 of TUNNEL_HDR_DW_1. */
2031 : 0 : off_be = 24 - (data->offset + width) + 8;
2032 : 0 : info[idx] = (struct field_modify_info){4, 0,
2033 : : MLX5_MODI_TUNNEL_HDR_DW_1};
2034 [ # # ]: 0 : if (mask)
2035 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2036 : : else
2037 : 0 : info[idx].offset = off_be;
2038 : : break;
2039 : 0 : case RTE_FLOW_FIELD_VXLAN_LAST_RSVD:
2040 : : MLX5_ASSERT(data->offset + width <= 8);
2041 : : /* Last_rsvd is on bits 7-0 of TUNNEL_HDR_DW_1. */
2042 : 0 : off_be = 8 - (data->offset + width);
2043 : 0 : info[idx] = (struct field_modify_info){1, 0, MLX5_MODI_TUNNEL_HDR_DW_1};
2044 [ # # ]: 0 : if (mask)
2045 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
2046 : : else
2047 : 0 : info[idx].offset = off_be;
2048 : : break;
2049 : : case RTE_FLOW_FIELD_GENEVE_OPT_TYPE:
2050 : : MLX5_ASSERT(data->offset + width <= 8);
2051 : : modi_id = flow_geneve_opt_modi_field_get(priv, data);
2052 [ # # ]: 0 : if (modi_id < 0)
2053 : : return;
2054 : : /* Type is on bits 16-8 of GENEVE option header (DW0). */
2055 : 0 : off_be = 32 - (16 + data->offset + width);
2056 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
2057 [ # # ]: 0 : if (mask)
2058 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2059 : : else
2060 : 0 : info[idx].offset = off_be;
2061 : : break;
2062 : : case RTE_FLOW_FIELD_GENEVE_OPT_CLASS:
2063 : : MLX5_ASSERT(data->offset + width <= 16);
2064 : : modi_id = flow_geneve_opt_modi_field_get(priv, data);
2065 [ # # ]: 0 : if (modi_id < 0)
2066 : : return;
2067 : : /* Class is on bits 31-16 of GENEVE option header (DW0). */
2068 : 0 : off_be = 32 - (data->offset + width);
2069 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
2070 [ # # ]: 0 : if (mask)
2071 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2072 : : else
2073 : 0 : info[idx].offset = off_be;
2074 : : break;
2075 : 0 : case RTE_FLOW_FIELD_GENEVE_OPT_DATA:
2076 [ # # ]: 0 : if ((data->offset % 32) + width > 32) {
2077 : 0 : DRV_LOG(ERR, "Geneve TLV option data is per DW.");
2078 : 0 : return;
2079 : : }
2080 : : modi_id = flow_geneve_opt_modi_field_get(priv, data);
2081 [ # # ]: 0 : if (modi_id < 0)
2082 : : return;
2083 : : /* Use offset inside DW. */
2084 : 0 : off_be = 32 - ((data->offset % 32) + width);
2085 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
2086 [ # # ]: 0 : if (mask)
2087 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2088 : : else
2089 : 0 : info[idx].offset = off_be;
2090 : : break;
2091 : 0 : case RTE_FLOW_FIELD_GTP_TEID:
2092 : : MLX5_ASSERT(data->offset + width <= 32);
2093 : 0 : off_be = 32 - (data->offset + width);
2094 : 0 : info[idx] = (struct field_modify_info){4, 0,
2095 : : MLX5_MODI_GTP_TEID};
2096 [ # # ]: 0 : if (mask)
2097 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2098 : : else
2099 : 0 : info[idx].offset = off_be;
2100 : : break;
2101 : 0 : case RTE_FLOW_FIELD_MPLS:
2102 : : MLX5_ASSERT(data->offset + width <= 32);
2103 : 0 : off_be = 32 - (data->offset + width);
2104 : : modi_id = mlx5_mpls_modi_field_get(data);
2105 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
2106 [ # # ]: 0 : if (mask)
2107 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2108 : : else
2109 : 0 : info[idx].offset = off_be;
2110 : : break;
2111 : : case RTE_FLOW_FIELD_TAG:
2112 : : {
2113 : : MLX5_ASSERT(data->offset + width <= 32);
2114 : : uint8_t tag_index = flow_tag_index_get(data);
2115 : : int reg;
2116 : :
2117 : : off_be = (tag_index == RTE_PMD_MLX5_LINEAR_HASH_TAG_INDEX) ?
2118 [ # # ]: 0 : 16 - (data->offset + width) + 16 : data->offset;
2119 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
2120 [ # # ]: 0 : reg = flow_hw_get_reg_id(dev,
2121 : : RTE_FLOW_ITEM_TYPE_TAG,
2122 : : tag_index);
2123 : : else
2124 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG,
2125 : : tag_index, error);
2126 [ # # ]: 0 : if (reg < 0)
2127 : : return;
2128 : : MLX5_ASSERT(reg != REG_NON);
2129 : : MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
2130 : 0 : info[idx] = (struct field_modify_info){4, 0,
2131 : 0 : reg_to_field[reg]};
2132 [ # # ]: 0 : if (mask)
2133 : 0 : mask[idx] = flow_modify_info_mask_32
2134 : : (width, off_be);
2135 : : else
2136 : 0 : info[idx].offset = off_be;
2137 : : }
2138 : : break;
2139 : 0 : case RTE_FLOW_FIELD_MARK:
2140 : : {
2141 : 0 : uint32_t mark_mask = priv->sh->dv_mark_mask;
2142 : : uint32_t mark_count = rte_popcount32(mark_mask);
2143 : : RTE_SET_USED(mark_count);
2144 : : MLX5_ASSERT(data->offset + width <= mark_count);
2145 : 0 : int reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK,
2146 : : 0, error);
2147 [ # # ]: 0 : if (reg < 0)
2148 : : return;
2149 : : MLX5_ASSERT(reg != REG_NON);
2150 : : MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
2151 : 0 : info[idx] = (struct field_modify_info){4, 0,
2152 : 0 : reg_to_field[reg]};
2153 [ # # ]: 0 : if (mask)
2154 : 0 : mask[idx] = flow_modify_info_mask_32_masked
2155 [ # # ]: 0 : (width, data->offset, mark_mask);
2156 : : else
2157 : 0 : info[idx].offset = data->offset;
2158 : : }
2159 : : break;
2160 : 0 : case RTE_FLOW_FIELD_META:
2161 : : {
2162 : 0 : uint32_t meta_mask = priv->sh->dv_meta_mask;
2163 : : uint32_t meta_count = rte_popcount32(meta_mask);
2164 : : RTE_SET_USED(meta_count);
2165 : : MLX5_ASSERT(data->offset + width <= meta_count);
2166 : 0 : int reg = flow_dv_get_metadata_reg(dev, attr, error);
2167 [ # # ]: 0 : if (reg < 0)
2168 : : return;
2169 : : MLX5_ASSERT(reg != REG_NON);
2170 : : MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
2171 : 0 : info[idx] = (struct field_modify_info){4, 0,
2172 : 0 : reg_to_field[reg]};
2173 [ # # ]: 0 : if (mask)
2174 : 0 : mask[idx] = flow_modify_info_mask_32_masked
2175 [ # # ]: 0 : (width, data->offset, meta_mask);
2176 : : else
2177 : 0 : info[idx].offset = data->offset;
2178 : : }
2179 : : break;
2180 : 0 : case RTE_FLOW_FIELD_IPV4_ECN:
2181 : : MLX5_ASSERT(data->offset + width <= 2);
2182 : 0 : off_be = 2 - (data->offset + width);
2183 [ # # ]: 0 : modi_id = CALC_MODI_ID(IP_ECN, data->level);
2184 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
2185 [ # # ]: 0 : if (mask)
2186 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
2187 : : else
2188 : 0 : info[idx].offset = off_be;
2189 : : break;
2190 : 0 : case RTE_FLOW_FIELD_IPV6_ECN:
2191 : : MLX5_ASSERT(data->offset + width <= 2);
2192 : 0 : off_be = 2 - (data->offset + width);
2193 [ # # ]: 0 : if (mlx5_dv_modify_ipv6_traffic_class_supported(priv))
2194 : 0 : info[idx] = (struct field_modify_info){1, 0,
2195 : : MLX5_MODI_OUT_IPV6_TRAFFIC_CLASS};
2196 : : else
2197 : 0 : info[idx] = (struct field_modify_info){1, 0,
2198 : : MLX5_MODI_OUT_IP_ECN};
2199 [ # # ]: 0 : if (mask)
2200 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
2201 : : else
2202 : 0 : info[idx].offset = off_be;
2203 : : break;
2204 : 0 : case RTE_FLOW_FIELD_GTP_PSC_QFI:
2205 : : MLX5_ASSERT(data->offset + width <= 8);
2206 : 0 : off_be = data->offset + 8;
2207 : 0 : info[idx] = (struct field_modify_info){4, 0,
2208 : : MLX5_MODI_GTPU_FIRST_EXT_DW_0};
2209 [ # # ]: 0 : if (mask)
2210 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2211 : : else
2212 : 0 : info[idx].offset = off_be;
2213 : : break;
2214 : 0 : case MLX5_RTE_FLOW_FIELD_META_REG:
2215 : : {
2216 [ # # ]: 0 : uint32_t meta_mask = priv->sh->dv_meta_mask;
2217 : : uint32_t meta_count = rte_popcount32(meta_mask);
2218 : : uint8_t reg = flow_tag_index_get(data);
2219 : :
2220 : : RTE_SET_USED(meta_count);
2221 : : MLX5_ASSERT(data->offset + width <= meta_count);
2222 : : MLX5_ASSERT(reg != REG_NON);
2223 : : MLX5_ASSERT(reg < RTE_DIM(reg_to_field));
2224 : 0 : info[idx] = (struct field_modify_info){4, 0, reg_to_field[reg]};
2225 [ # # ]: 0 : if (mask)
2226 : 0 : mask[idx] = flow_modify_info_mask_32_masked
2227 [ # # ]: 0 : (width, data->offset, meta_mask);
2228 : : else
2229 : 0 : info[idx].offset = data->offset;
2230 : : }
2231 : : break;
2232 : 0 : case RTE_FLOW_FIELD_METER_COLOR:
2233 : : {
2234 : : const uint32_t color_mask =
2235 : : (UINT32_C(1) << MLX5_MTR_COLOR_BITS) - 1;
2236 : : int reg;
2237 : :
2238 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
2239 : : reg = flow_hw_get_reg_id
2240 : : (dev,
2241 : : RTE_FLOW_ITEM_TYPE_METER_COLOR, 0);
2242 : : else
2243 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR,
2244 : : 0, error);
2245 [ # # ]: 0 : if (reg < 0)
2246 : : return;
2247 : : MLX5_ASSERT(reg != REG_NON);
2248 : : MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
2249 : 0 : info[idx] = (struct field_modify_info){4, 0,
2250 : 0 : 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 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 : : }
3291 : : /* State change also needs to be considered. */
3292 : 0 : *item_flags |= MLX5_FLOW_LAYER_ASO_CT;
3293 : 0 : return 0;
3294 : : }
3295 : :
3296 : : /**
3297 : : * Validate the pop VLAN action.
3298 : : *
3299 : : * @param[in] dev
3300 : : * Pointer to the rte_eth_dev structure.
3301 : : * @param[in] action_flags
3302 : : * Holds the actions detected until now.
3303 : : * @param[in] action
3304 : : * Pointer to the pop vlan action.
3305 : : * @param[in] item_flags
3306 : : * The items found in this flow rule.
3307 : : * @param[in] attr
3308 : : * Pointer to flow attributes.
3309 : : * @param[out] error
3310 : : * Pointer to error structure.
3311 : : *
3312 : : * @return
3313 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3314 : : */
3315 : : static int
3316 : 0 : flow_dv_validate_action_pop_vlan(struct rte_eth_dev *dev,
3317 : : uint64_t action_flags,
3318 : : const struct rte_flow_action *action,
3319 : : uint64_t item_flags,
3320 : : const struct rte_flow_attr *attr,
3321 : : struct rte_flow_error *error)
3322 : : {
3323 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
3324 : :
3325 [ # # ]: 0 : if (!priv->sh->pop_vlan_action)
3326 : 0 : return rte_flow_error_set(error, ENOTSUP,
3327 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3328 : : NULL,
3329 : : "pop vlan action is not supported");
3330 [ # # ]: 0 : if (action_flags & MLX5_FLOW_VLAN_ACTIONS)
3331 : 0 : return rte_flow_error_set(error, ENOTSUP,
3332 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3333 : : "no support for multiple VLAN "
3334 : : "actions");
3335 : : /* Pop VLAN with preceding Decap requires inner header with VLAN. */
3336 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_DECAP) &&
3337 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_INNER_VLAN))
3338 : 0 : return rte_flow_error_set(error, ENOTSUP,
3339 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3340 : : NULL,
3341 : : "cannot pop vlan after decap without "
3342 : : "match on inner vlan in the flow");
3343 : : /* Pop VLAN without preceding Decap requires outer header with VLAN. */
3344 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_ACTION_DECAP) &&
3345 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
3346 : 0 : return rte_flow_error_set(error, ENOTSUP,
3347 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3348 : : NULL,
3349 : : "cannot pop vlan without a "
3350 : : "match on (outer) vlan in the flow");
3351 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3352 : 0 : return rte_flow_error_set(error, EINVAL,
3353 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3354 : : "wrong action order, port_id should "
3355 : : "be after pop VLAN action");
3356 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
3357 : 0 : return rte_flow_error_set(error, ENOTSUP,
3358 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3359 : : "pop vlan action for VF representor "
3360 : : "not supported on NIC table");
3361 : : return 0;
3362 : : }
3363 : :
3364 : : /**
3365 : : * Get VLAN default info from vlan match info.
3366 : : *
3367 : : * @param[in] items
3368 : : * the list of item specifications.
3369 : : * @param[out] vlan
3370 : : * pointer VLAN info to fill to.
3371 : : *
3372 : : * @return
3373 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3374 : : */
3375 : : static void
3376 : 0 : flow_dev_get_vlan_info_from_items(const struct rte_flow_item *items,
3377 : : struct rte_vlan_hdr *vlan)
3378 : : {
3379 : 0 : const struct rte_flow_item_vlan nic_mask = {
3380 : : .hdr.vlan_tci = RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK |
3381 : : MLX5DV_FLOW_VLAN_VID_MASK),
3382 : : .hdr.eth_proto = RTE_BE16(0xffff),
3383 : : };
3384 : :
3385 [ # # ]: 0 : if (items == NULL)
3386 : 0 : return;
3387 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
3388 : 0 : int type = items->type;
3389 : :
3390 : 0 : if (type == RTE_FLOW_ITEM_TYPE_VLAN ||
3391 [ # # ]: 0 : type == MLX5_RTE_FLOW_ITEM_TYPE_VLAN)
3392 : : break;
3393 : : }
3394 [ # # ]: 0 : if (items->type != RTE_FLOW_ITEM_TYPE_END) {
3395 : 0 : const struct rte_flow_item_vlan *vlan_m = items->mask;
3396 : 0 : const struct rte_flow_item_vlan *vlan_v = items->spec;
3397 : :
3398 : : /* If VLAN item in pattern doesn't contain data, return here. */
3399 [ # # ]: 0 : if (!vlan_v)
3400 : : return;
3401 [ # # ]: 0 : if (!vlan_m)
3402 : : vlan_m = &nic_mask;
3403 : : /* Only full match values are accepted */
3404 [ # # ]: 0 : if ((vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) ==
3405 : : MLX5DV_FLOW_VLAN_PCP_MASK_BE) {
3406 : 0 : vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
3407 : 0 : vlan->vlan_tci |=
3408 [ # # ]: 0 : rte_be_to_cpu_16(vlan_v->hdr.vlan_tci &
3409 : : MLX5DV_FLOW_VLAN_PCP_MASK_BE);
3410 : : }
3411 [ # # ]: 0 : if ((vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) ==
3412 : : MLX5DV_FLOW_VLAN_VID_MASK_BE) {
3413 : 0 : vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
3414 : 0 : vlan->vlan_tci |=
3415 [ # # ]: 0 : rte_be_to_cpu_16(vlan_v->hdr.vlan_tci &
3416 : : MLX5DV_FLOW_VLAN_VID_MASK_BE);
3417 : : }
3418 [ # # ]: 0 : if (vlan_m->hdr.eth_proto == nic_mask.hdr.eth_proto)
3419 [ # # ]: 0 : vlan->eth_proto = rte_be_to_cpu_16(vlan_v->hdr.eth_proto &
3420 : : vlan_m->hdr.eth_proto);
3421 : : }
3422 : : }
3423 : :
3424 : : /**
3425 : : * Validate the push VLAN action.
3426 : : *
3427 : : * @param[in] dev
3428 : : * Pointer to the rte_eth_dev structure.
3429 : : * @param[in] action_flags
3430 : : * Holds the actions detected until now.
3431 : : * @param[in] item_flags
3432 : : * The items found in this flow rule.
3433 : : * @param[in] action
3434 : : * Pointer to the action structure.
3435 : : * @param[in] attr
3436 : : * Pointer to flow attributes
3437 : : * @param[out] error
3438 : : * Pointer to error structure.
3439 : : *
3440 : : * @return
3441 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3442 : : */
3443 : : static int
3444 : 0 : flow_dv_validate_action_push_vlan(struct rte_eth_dev *dev,
3445 : : uint64_t action_flags,
3446 : : const struct rte_flow_item_vlan *vlan_m,
3447 : : const struct rte_flow_action *action,
3448 : : const struct rte_flow_attr *attr,
3449 : : struct rte_flow_error *error)
3450 : : {
3451 : 0 : const struct rte_flow_action_of_push_vlan *push_vlan = action->conf;
3452 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
3453 : :
3454 [ # # ]: 0 : if (push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_VLAN) &&
3455 : : push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_QINQ))
3456 : 0 : return rte_flow_error_set(error, EINVAL,
3457 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3458 : : "invalid vlan ethertype");
3459 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3460 : 0 : return rte_flow_error_set(error, EINVAL,
3461 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3462 : : "wrong action order, port_id should "
3463 : : "be after push VLAN");
3464 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
3465 : 0 : return rte_flow_error_set(error, ENOTSUP,
3466 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3467 : : "push vlan action for VF representor "
3468 : : "not supported on NIC table");
3469 [ # # ]: 0 : if (vlan_m &&
3470 [ # # # # ]: 0 : (vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) &&
3471 : : (vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) !=
3472 : 0 : MLX5DV_FLOW_VLAN_PCP_MASK_BE &&
3473 [ # # # # ]: 0 : !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP) &&
3474 : 0 : !(mlx5_flow_find_action
3475 : : (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP)))
3476 : 0 : return rte_flow_error_set(error, EINVAL,
3477 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3478 : : "not full match mask on VLAN PCP and "
3479 : : "there is no of_set_vlan_pcp action, "
3480 : : "push VLAN action cannot figure out "
3481 : : "PCP value");
3482 [ # # ]: 0 : if (vlan_m &&
3483 [ # # # # ]: 0 : (vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) &&
3484 : : (vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) !=
3485 : 0 : MLX5DV_FLOW_VLAN_VID_MASK_BE &&
3486 [ # # # # ]: 0 : !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID) &&
3487 : 0 : !(mlx5_flow_find_action
3488 : : (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID)))
3489 : 0 : return rte_flow_error_set(error, EINVAL,
3490 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3491 : : "not full match mask on VLAN VID and "
3492 : : "there is no of_set_vlan_vid action, "
3493 : : "push VLAN action cannot figure out "
3494 : : "VID value");
3495 : : (void)attr;
3496 : : return 0;
3497 : : }
3498 : :
3499 : : /**
3500 : : * Validate the set VLAN PCP.
3501 : : *
3502 : : * @param[in] action_flags
3503 : : * Holds the actions detected until now.
3504 : : * @param[in] actions
3505 : : * Pointer to the list of actions remaining in the flow rule.
3506 : : * @param[out] error
3507 : : * Pointer to error structure.
3508 : : *
3509 : : * @return
3510 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3511 : : */
3512 : : static int
3513 : 0 : flow_dv_validate_action_set_vlan_pcp(uint64_t action_flags,
3514 : : const struct rte_flow_action actions[],
3515 : : struct rte_flow_error *error)
3516 : : {
3517 : : const struct rte_flow_action *action = actions;
3518 : 0 : const struct rte_flow_action_of_set_vlan_pcp *conf = action->conf;
3519 : :
3520 [ # # ]: 0 : if (conf->vlan_pcp > 7)
3521 : 0 : return rte_flow_error_set(error, EINVAL,
3522 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3523 : : "VLAN PCP value is too big");
3524 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN))
3525 : 0 : return rte_flow_error_set(error, ENOTSUP,
3526 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3527 : : "set VLAN PCP action must follow "
3528 : : "the push VLAN action");
3529 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP)
3530 : 0 : return rte_flow_error_set(error, ENOTSUP,
3531 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3532 : : "Multiple VLAN PCP modification are "
3533 : : "not supported");
3534 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3535 : 0 : return rte_flow_error_set(error, EINVAL,
3536 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3537 : : "wrong action order, port_id should "
3538 : : "be after set VLAN PCP");
3539 : : return 0;
3540 : : }
3541 : :
3542 : : /**
3543 : : * Validate the set VLAN VID.
3544 : : *
3545 : : * @param[in] item_flags
3546 : : * Holds the items detected in this rule.
3547 : : * @param[in] action_flags
3548 : : * Holds the actions detected until now.
3549 : : * @param[in] actions
3550 : : * Pointer to the list of actions remaining in the flow rule.
3551 : : * @param[out] error
3552 : : * Pointer to error structure.
3553 : : *
3554 : : * @return
3555 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3556 : : */
3557 : : static int
3558 : 0 : flow_dv_validate_action_set_vlan_vid(uint64_t item_flags,
3559 : : uint64_t action_flags,
3560 : : const struct rte_flow_action actions[],
3561 : : struct rte_flow_error *error)
3562 : : {
3563 : : const struct rte_flow_action *action = actions;
3564 : 0 : const struct rte_flow_action_of_set_vlan_vid *conf = action->conf;
3565 : :
3566 [ # # # # ]: 0 : if (rte_be_to_cpu_16(conf->vlan_vid) > 0xFFE)
3567 : 0 : return rte_flow_error_set(error, EINVAL,
3568 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3569 : : "VLAN VID value is too big");
3570 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) &&
3571 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
3572 : 0 : return rte_flow_error_set(error, ENOTSUP,
3573 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3574 : : "set VLAN VID action must follow push"
3575 : : " VLAN action or match on VLAN item");
3576 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID)
3577 : 0 : return rte_flow_error_set(error, ENOTSUP,
3578 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3579 : : "Multiple VLAN VID modifications are "
3580 : : "not supported");
3581 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3582 : 0 : return rte_flow_error_set(error, EINVAL,
3583 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3584 : : "wrong action order, port_id should "
3585 : : "be after set VLAN VID");
3586 : : return 0;
3587 : : }
3588 : :
3589 : : /*
3590 : : * Validate the FLAG action.
3591 : : *
3592 : : * @param[in] dev
3593 : : * Pointer to the rte_eth_dev structure.
3594 : : * @param[in] action_flags
3595 : : * Holds the actions detected until now.
3596 : : * @param[in] attr
3597 : : * Pointer to flow attributes
3598 : : * @param[out] error
3599 : : * Pointer to error structure.
3600 : : *
3601 : : * @return
3602 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3603 : : */
3604 : : static int
3605 : 0 : flow_dv_validate_action_flag(struct rte_eth_dev *dev,
3606 : : uint64_t action_flags,
3607 : : const struct rte_flow_attr *attr,
3608 : : struct rte_flow_error *error)
3609 : : {
3610 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3611 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
3612 : : int ret;
3613 : :
3614 : : /* Fall back if no extended metadata register support. */
3615 [ # # ]: 0 : if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
3616 : 0 : return mlx5_flow_validate_action_flag(action_flags, attr,
3617 : : error);
3618 : : /* Extensive metadata mode requires registers. */
3619 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
3620 : 0 : return rte_flow_error_set(error, ENOTSUP,
3621 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3622 : : "no metadata registers "
3623 : : "to support flag action");
3624 [ # # ]: 0 : if (!(priv->sh->dv_mark_mask & MLX5_FLOW_MARK_DEFAULT))
3625 : 0 : return rte_flow_error_set(error, ENOTSUP,
3626 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3627 : : "extended metadata register"
3628 : : " isn't available");
3629 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3630 [ # # ]: 0 : if (ret < 0)
3631 : : return ret;
3632 : : MLX5_ASSERT(ret > 0);
3633 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
3634 : 0 : return rte_flow_error_set(error, EINVAL,
3635 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3636 : : "can't mark and flag in same flow");
3637 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_FLAG)
3638 : 0 : return rte_flow_error_set(error, EINVAL,
3639 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3640 : : "can't have 2 flag"
3641 : : " actions in same flow");
3642 : : return 0;
3643 : : }
3644 : :
3645 : : /**
3646 : : * Validate MARK action.
3647 : : *
3648 : : * @param[in] dev
3649 : : * Pointer to the rte_eth_dev structure.
3650 : : * @param[in] action
3651 : : * Pointer to action.
3652 : : * @param[in] action_flags
3653 : : * Holds the actions detected until now.
3654 : : * @param[in] attr
3655 : : * Pointer to flow attributes
3656 : : * @param[out] error
3657 : : * Pointer to error structure.
3658 : : *
3659 : : * @return
3660 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3661 : : */
3662 : : static int
3663 : 0 : flow_dv_validate_action_mark(struct rte_eth_dev *dev,
3664 : : const struct rte_flow_action *action,
3665 : : uint64_t action_flags,
3666 : : const struct rte_flow_attr *attr,
3667 : : struct rte_flow_error *error)
3668 : : {
3669 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3670 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
3671 [ # # ]: 0 : const struct rte_flow_action_mark *mark = action->conf;
3672 : : int ret;
3673 : :
3674 [ # # ]: 0 : if (is_tunnel_offload_active(dev))
3675 : 0 : return rte_flow_error_set(error, ENOTSUP,
3676 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3677 : : "no mark action "
3678 : : "if tunnel offload active");
3679 : : /* Fall back if no extended metadata register support. */
3680 [ # # ]: 0 : if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
3681 : 0 : return mlx5_flow_validate_action_mark(dev, action, action_flags,
3682 : : attr, error);
3683 : : /* Extensive metadata mode requires registers. */
3684 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
3685 : 0 : return rte_flow_error_set(error, ENOTSUP,
3686 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3687 : : "no metadata registers "
3688 : : "to support mark action");
3689 [ # # ]: 0 : if (!priv->sh->dv_mark_mask)
3690 : 0 : return rte_flow_error_set(error, ENOTSUP,
3691 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3692 : : "extended metadata register"
3693 : : " isn't available");
3694 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3695 [ # # ]: 0 : if (ret < 0)
3696 : : return ret;
3697 : : MLX5_ASSERT(ret > 0);
3698 [ # # ]: 0 : if (!mark)
3699 : 0 : return rte_flow_error_set(error, EINVAL,
3700 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3701 : : "configuration cannot be null");
3702 [ # # ]: 0 : if (mark->id >= (MLX5_FLOW_MARK_MAX & priv->sh->dv_mark_mask))
3703 : 0 : return rte_flow_error_set(error, EINVAL,
3704 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3705 : 0 : &mark->id,
3706 : : "mark id exceeds the limit");
3707 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_FLAG)
3708 : 0 : return rte_flow_error_set(error, EINVAL,
3709 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3710 : : "can't flag and mark in same flow");
3711 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
3712 : 0 : return rte_flow_error_set(error, EINVAL,
3713 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3714 : : "can't have 2 mark actions in same"
3715 : : " flow");
3716 : : return 0;
3717 : : }
3718 : :
3719 : : /**
3720 : : * Validate SET_META action.
3721 : : *
3722 : : * @param[in] dev
3723 : : * Pointer to the rte_eth_dev structure.
3724 : : * @param[in] action
3725 : : * Pointer to the action structure.
3726 : : * @param[in] action_flags
3727 : : * Holds the actions detected until now.
3728 : : * @param[in] attr
3729 : : * Pointer to flow attributes
3730 : : * @param[out] error
3731 : : * Pointer to error structure.
3732 : : *
3733 : : * @return
3734 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3735 : : */
3736 : : static int
3737 : 0 : flow_dv_validate_action_set_meta(struct rte_eth_dev *dev,
3738 : : const struct rte_flow_action *action,
3739 : : uint64_t action_flags __rte_unused,
3740 : : const struct rte_flow_attr *attr,
3741 : : struct rte_flow_error *error)
3742 : : {
3743 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3744 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
3745 : : const struct rte_flow_action_set_meta *conf;
3746 : : uint32_t nic_mask = UINT32_MAX;
3747 : : int reg;
3748 : :
3749 [ # # # # ]: 0 : if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
3750 : 0 : !mlx5_flow_ext_mreg_supported(dev))
3751 : 0 : return rte_flow_error_set(error, ENOTSUP,
3752 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3753 : : "extended metadata register"
3754 : : " isn't supported");
3755 : 0 : reg = flow_dv_get_metadata_reg(dev, attr, error);
3756 [ # # ]: 0 : if (reg < 0)
3757 : : return reg;
3758 [ # # ]: 0 : if (reg == REG_NON)
3759 : 0 : return rte_flow_error_set(error, ENOTSUP,
3760 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3761 : : "unavailable extended metadata register");
3762 [ # # ]: 0 : if (reg != REG_A && reg != REG_B) {
3763 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3764 : :
3765 : 0 : nic_mask = priv->sh->dv_meta_mask;
3766 : : }
3767 [ # # ]: 0 : if (!(action->conf))
3768 : 0 : return rte_flow_error_set(error, EINVAL,
3769 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3770 : : "configuration cannot be null");
3771 : : conf = (const struct rte_flow_action_set_meta *)action->conf;
3772 [ # # ]: 0 : if (!conf->mask)
3773 : 0 : return rte_flow_error_set(error, EINVAL,
3774 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3775 : : "zero mask doesn't have any effect");
3776 [ # # ]: 0 : if (conf->mask & ~nic_mask)
3777 : 0 : return rte_flow_error_set(error, EINVAL,
3778 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3779 : : "meta data must be within reg C0");
3780 : : return 0;
3781 : : }
3782 : :
3783 : : /**
3784 : : * Validate SET_TAG action.
3785 : : *
3786 : : * @param[in] dev
3787 : : * Pointer to the rte_eth_dev structure.
3788 : : * @param[in] action
3789 : : * Pointer to the action structure.
3790 : : * @param[in] action_flags
3791 : : * Holds the actions detected until now.
3792 : : * @param[in] attr
3793 : : * Pointer to flow attributes
3794 : : * @param[out] error
3795 : : * Pointer to error structure.
3796 : : *
3797 : : * @return
3798 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3799 : : */
3800 : : static int
3801 : 0 : flow_dv_validate_action_set_tag(struct rte_eth_dev *dev,
3802 : : const struct rte_flow_action *action,
3803 : : uint64_t action_flags,
3804 : : const struct rte_flow_attr *attr,
3805 : : struct rte_flow_error *error)
3806 : : {
3807 : : const struct rte_flow_action_set_tag *conf;
3808 : : const uint64_t terminal_action_flags =
3809 : : MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE |
3810 : : MLX5_FLOW_ACTION_RSS;
3811 : : int ret;
3812 : :
3813 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
3814 : 0 : return rte_flow_error_set(error, ENOTSUP,
3815 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3816 : : "extensive metadata register"
3817 : : " isn't supported");
3818 [ # # ]: 0 : if (!(action->conf))
3819 : 0 : return rte_flow_error_set(error, EINVAL,
3820 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3821 : : "configuration cannot be null");
3822 : : conf = (const struct rte_flow_action_set_tag *)action->conf;
3823 [ # # ]: 0 : if (!conf->mask)
3824 : 0 : return rte_flow_error_set(error, EINVAL,
3825 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3826 : : "zero mask doesn't have any effect");
3827 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
3828 [ # # ]: 0 : if (ret < 0)
3829 : : return ret;
3830 [ # # # # ]: 0 : if (attr->ingress && (action_flags & terminal_action_flags))
3831 : 0 : return rte_flow_error_set(error, EINVAL,
3832 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3833 : : "set_tag has no effect"
3834 : : " with terminal actions");
3835 : : return 0;
3836 : : }
3837 : :
3838 : : /**
3839 : : * Indicates whether ASO aging is supported.
3840 : : *
3841 : : * @param[in] priv
3842 : : * Pointer to device private context structure.
3843 : : * @param[in] root
3844 : : * Whether action is on root table.
3845 : : *
3846 : : * @return
3847 : : * True when ASO aging is supported, false otherwise.
3848 : : */
3849 : : static inline bool
3850 : : flow_hit_aso_supported(const struct mlx5_priv *priv, bool root)
3851 : : {
3852 : : MLX5_ASSERT(priv);
3853 [ # # # # : 0 : return (priv->sh->flow_hit_aso_en && !root);
# # # # #
# ]
3854 : : }
3855 : :
3856 : : /**
3857 : : * Validate count action.
3858 : : *
3859 : : * @param[in] dev
3860 : : * Pointer to rte_eth_dev structure.
3861 : : * @param[in] shared
3862 : : * Indicator if action is shared.
3863 : : * @param[in] action_flags
3864 : : * Holds the actions detected until now.
3865 : : * @param[in] root
3866 : : * Whether action is on root table.
3867 : : * @param[out] error
3868 : : * Pointer to error structure.
3869 : : *
3870 : : * @return
3871 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3872 : : */
3873 : : static int
3874 : 0 : flow_dv_validate_action_count(struct rte_eth_dev *dev, bool shared,
3875 : : uint64_t action_flags,
3876 : : bool root,
3877 : : struct rte_flow_error *error)
3878 : : {
3879 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3880 : :
3881 [ # # ]: 0 : if (!priv->sh->cdev->config.devx)
3882 : 0 : goto notsup_err;
3883 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_COUNT)
3884 : 0 : return rte_flow_error_set(error, EINVAL,
3885 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3886 : : "duplicate count actions set");
3887 [ # # # # : 0 : if (shared && (action_flags & MLX5_FLOW_ACTION_AGE) &&
# # ]
3888 : : !flow_hit_aso_supported(priv, root))
3889 : 0 : return rte_flow_error_set(error, EINVAL,
3890 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3891 : : "old age and indirect count combination is not supported");
3892 : : #ifdef HAVE_IBV_FLOW_DEVX_COUNTERS
3893 : : return 0;
3894 : : #endif
3895 : : notsup_err:
3896 : 0 : return rte_flow_error_set
3897 : : (error, ENOTSUP,
3898 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3899 : : NULL,
3900 : : "count action not supported");
3901 : : }
3902 : :
3903 : : /**
3904 : : * Validate the L2 encap action.
3905 : : *
3906 : : * @param[in] dev
3907 : : * Pointer to the rte_eth_dev structure.
3908 : : * @param[in] action_flags
3909 : : * Holds the actions detected until now.
3910 : : * @param[in] action
3911 : : * Pointer to the action structure.
3912 : : * @param[in] attr
3913 : : * Pointer to flow attributes.
3914 : : * @param[out] error
3915 : : * Pointer to error structure.
3916 : : *
3917 : : * @return
3918 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3919 : : */
3920 : : int
3921 : 0 : mlx5_flow_dv_validate_action_l2_encap(struct rte_eth_dev *dev,
3922 : : uint64_t action_flags,
3923 : : const struct rte_flow_action *action,
3924 : : const struct rte_flow_attr *attr,
3925 : : struct rte_flow_error *error)
3926 : : {
3927 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
3928 : :
3929 [ # # ]: 0 : if (!(action->conf))
3930 : 0 : return rte_flow_error_set(error, EINVAL,
3931 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3932 : : "configuration cannot be null");
3933 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
3934 : 0 : return rte_flow_error_set(error, EINVAL,
3935 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3936 : : "can only have a single encap action "
3937 : : "in a flow");
3938 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
3939 : 0 : return rte_flow_error_set(error, ENOTSUP,
3940 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3941 : : "encap action for VF representor "
3942 : : "not supported on NIC table");
3943 : : return 0;
3944 : : }
3945 : :
3946 : : /**
3947 : : * Validate a decap action.
3948 : : *
3949 : : * @param[in] dev
3950 : : * Pointer to the rte_eth_dev structure.
3951 : : * @param[in] action_flags
3952 : : * Holds the actions detected until now.
3953 : : * @param[in] action
3954 : : * Pointer to the action structure.
3955 : : * @param[in] item_flags
3956 : : * Holds the items detected.
3957 : : * @param[in] attr
3958 : : * Pointer to flow attributes
3959 : : * @param[out] error
3960 : : * Pointer to error structure.
3961 : : *
3962 : : * @return
3963 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3964 : : */
3965 : : int
3966 : 0 : mlx5_flow_dv_validate_action_decap(struct rte_eth_dev *dev,
3967 : : uint64_t action_flags,
3968 : : const struct rte_flow_action *action,
3969 : : const uint64_t item_flags,
3970 : : const struct rte_flow_attr *attr,
3971 : : struct rte_flow_error *error)
3972 : : {
3973 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
3974 : :
3975 [ # # ]: 0 : if (priv->sh->cdev->config.hca_attr.scatter_fcs_w_decap_disable &&
3976 [ # # ]: 0 : !priv->sh->config.decap_en)
3977 : 0 : return rte_flow_error_set(error, ENOTSUP,
3978 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3979 : : "decap is not enabled");
3980 [ # # ]: 0 : if (action_flags & MLX5_FLOW_XCAP_ACTIONS)
3981 : 0 : return rte_flow_error_set(error, ENOTSUP,
3982 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3983 [ # # ]: 0 : action_flags &
3984 : : MLX5_FLOW_ACTION_DECAP ? "can only "
3985 : : "have a single decap action" : "decap "
3986 : : "after encap is not supported");
3987 [ # # ]: 0 : if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
3988 : 0 : return rte_flow_error_set(error, EINVAL,
3989 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3990 : : "can't have decap action after"
3991 : : " modify action");
3992 [ # # ]: 0 : if (attr->egress)
3993 : 0 : return rte_flow_error_set(error, ENOTSUP,
3994 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
3995 : : NULL,
3996 : : "decap action not supported for "
3997 : : "egress");
3998 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
3999 : 0 : return rte_flow_error_set(error, ENOTSUP,
4000 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4001 : : "decap action for VF representor "
4002 : : "not supported on NIC table");
4003 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_DECAP &&
4004 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_VXLAN))
4005 : 0 : return rte_flow_error_set(error, ENOTSUP,
4006 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4007 : : "VXLAN item should be present for VXLAN decap");
4008 : : return 0;
4009 : : }
4010 : :
4011 : : const struct rte_flow_action_raw_decap empty_decap = {.data = NULL, .size = 0,};
4012 : :
4013 : : /**
4014 : : * Validate the raw encap and decap actions.
4015 : : *
4016 : : * @param[in] dev
4017 : : * Pointer to the rte_eth_dev structure.
4018 : : * @param[in] decap
4019 : : * Pointer to the decap action.
4020 : : * @param[in] encap
4021 : : * Pointer to the encap action.
4022 : : * @param[in] attr
4023 : : * Pointer to flow attributes
4024 : : * @param[in/out] action_flags
4025 : : * Holds the actions detected until now.
4026 : : * @param[out] actions_n
4027 : : * pointer to the number of actions counter.
4028 : : * @param[in] action
4029 : : * Pointer to the action structure.
4030 : : * @param[in] item_flags
4031 : : * Holds the items detected.
4032 : : * @param[out] error
4033 : : * Pointer to error structure.
4034 : : *
4035 : : * @return
4036 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4037 : : */
4038 : : int
4039 : 0 : mlx5_flow_dv_validate_action_raw_encap_decap
4040 : : (struct rte_eth_dev *dev,
4041 : : const struct rte_flow_action_raw_decap *decap,
4042 : : const struct rte_flow_action_raw_encap *encap,
4043 : : const struct rte_flow_attr *attr, uint64_t *action_flags,
4044 : : int *actions_n, const struct rte_flow_action *action,
4045 : : uint64_t item_flags, struct rte_flow_error *error)
4046 : : {
4047 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
4048 : : int ret;
4049 : :
4050 [ # # ]: 0 : if (encap) {
4051 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
4052 [ # # # # ]: 0 : if (!encap->size || !encap->data)
4053 : 0 : return rte_flow_error_set
4054 : : (error, EINVAL,
4055 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL, "raw encap data cannot be empty");
4056 : : } else {
4057 [ # # ]: 0 : if (!encap->size)
4058 : 0 : return rte_flow_error_set
4059 : : (error, EINVAL,
4060 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL, "raw encap size cannot be 0");
4061 : : }
4062 : : }
4063 [ # # ]: 0 : if (decap && encap) {
4064 [ # # ]: 0 : if (decap->size <= MLX5_ENCAPSULATION_DECISION_SIZE &&
4065 [ # # ]: 0 : encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4066 : : /* L3 encap. */
4067 : : decap = NULL;
4068 [ # # ]: 0 : else if (encap->size <=
4069 [ # # ]: 0 : MLX5_ENCAPSULATION_DECISION_SIZE &&
4070 : : decap->size >
4071 : : MLX5_ENCAPSULATION_DECISION_SIZE)
4072 : : /* L3 decap. */
4073 : : encap = NULL;
4074 [ # # ]: 0 : else if (encap->size >
4075 [ # # ]: 0 : MLX5_ENCAPSULATION_DECISION_SIZE &&
4076 : : decap->size >
4077 : : MLX5_ENCAPSULATION_DECISION_SIZE)
4078 : : /* 2 L2 actions: encap and decap. */
4079 : : ;
4080 : : else
4081 : 0 : return rte_flow_error_set(error,
4082 : : ENOTSUP,
4083 : : RTE_FLOW_ERROR_TYPE_ACTION,
4084 : : NULL, "unsupported too small "
4085 : : "raw decap and too small raw "
4086 : : "encap combination");
4087 : : }
4088 [ # # ]: 0 : if (decap) {
4089 : 0 : ret = mlx5_flow_dv_validate_action_decap(dev, *action_flags,
4090 : : action,
4091 : : item_flags, attr,
4092 : : error);
4093 [ # # ]: 0 : if (ret < 0)
4094 : : return ret;
4095 : 0 : *action_flags |= MLX5_FLOW_ACTION_DECAP;
4096 : 0 : ++(*actions_n);
4097 : : }
4098 [ # # ]: 0 : if (encap) {
4099 [ # # ]: 0 : if (encap->size <= MLX5_ENCAPSULATION_DECISION_SIZE)
4100 : 0 : return rte_flow_error_set(error, ENOTSUP,
4101 : : RTE_FLOW_ERROR_TYPE_ACTION,
4102 : : NULL,
4103 : : "small raw encap size");
4104 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_ENCAP)
4105 : 0 : return rte_flow_error_set(error, EINVAL,
4106 : : RTE_FLOW_ERROR_TYPE_ACTION,
4107 : : NULL,
4108 : : "more than one encap action");
4109 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
4110 : 0 : return rte_flow_error_set
4111 : : (error, ENOTSUP,
4112 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4113 : : "encap action for VF representor "
4114 : : "not supported on NIC table");
4115 : 0 : *action_flags |= MLX5_FLOW_ACTION_ENCAP;
4116 : 0 : ++(*actions_n);
4117 : : }
4118 : : return 0;
4119 : : }
4120 : :
4121 : : /*
4122 : : * Validate the ASO CT action.
4123 : : *
4124 : : * @param[in] dev
4125 : : * Pointer to the rte_eth_dev structure.
4126 : : * @param[in] action_flags
4127 : : * Holds the actions detected until now.
4128 : : * @param[in] item_flags
4129 : : * The items found in this flow rule.
4130 : : * @param root
4131 : : * Whether action is on root table.
4132 : : * @param[out] error
4133 : : * Pointer to error structure.
4134 : : *
4135 : : * @return
4136 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4137 : : */
4138 : : int
4139 : 0 : mlx5_flow_dv_validate_action_aso_ct(struct rte_eth_dev *dev,
4140 : : uint64_t action_flags,
4141 : : uint64_t item_flags,
4142 : : bool root,
4143 : : struct rte_flow_error *error)
4144 : : {
4145 : : RTE_SET_USED(dev);
4146 : :
4147 [ # # ]: 0 : if (root)
4148 : 0 : return rte_flow_error_set(error, ENOTSUP,
4149 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4150 : : NULL,
4151 : : "Only support non-root table");
4152 [ # # ]: 0 : if (action_flags & MLX5_FLOW_FATE_ACTIONS)
4153 : 0 : return rte_flow_error_set(error, ENOTSUP,
4154 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4155 : : "CT cannot follow a fate action");
4156 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_METER) ||
4157 : : (action_flags & MLX5_FLOW_ACTION_AGE)) {
4158 [ # # ]: 0 : if (!mlx5_hws_active(dev))
4159 : 0 : return rte_flow_error_set(error, EINVAL,
4160 : : RTE_FLOW_ERROR_TYPE_ACTION,
4161 : : NULL, "Only one ASO action is supported");
4162 : : }
4163 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
4164 : 0 : return rte_flow_error_set(error, EINVAL,
4165 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4166 : : "Encap cannot exist before CT");
4167 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP))
4168 : 0 : return rte_flow_error_set(error, EINVAL,
4169 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4170 : : "Not a outer TCP packet");
4171 : : return 0;
4172 : : }
4173 : :
4174 : : /**
4175 : : * Validate METER_COLOR item.
4176 : : *
4177 : : * @param[in] dev
4178 : : * Pointer to the rte_eth_dev structure.
4179 : : * @param[in] item
4180 : : * Item specification.
4181 : : * @param[in] attr
4182 : : * Attributes of flow that includes this item.
4183 : : * @param[out] error
4184 : : * Pointer to error structure.
4185 : : *
4186 : : * @return
4187 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4188 : : */
4189 : : static int
4190 : 0 : flow_dv_validate_item_meter_color(struct rte_eth_dev *dev,
4191 : : const struct rte_flow_item *item,
4192 : : const struct rte_flow_attr *attr __rte_unused,
4193 : : struct rte_flow_error *error)
4194 : : {
4195 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4196 : 0 : const struct rte_flow_item_meter_color *spec = item->spec;
4197 : 0 : const struct rte_flow_item_meter_color *mask = item->mask;
4198 : 0 : struct rte_flow_item_meter_color nic_mask = {
4199 : : .color = RTE_COLORS
4200 : : };
4201 : : int ret;
4202 : :
4203 [ # # ]: 0 : if (priv->sh->registers.aso_reg == REG_NON)
4204 : 0 : return rte_flow_error_set(error, ENOTSUP,
4205 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
4206 : : "meter color register"
4207 : : " isn't available");
4208 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, error);
4209 [ # # ]: 0 : if (ret < 0)
4210 : : return ret;
4211 [ # # ]: 0 : if (!spec)
4212 : 0 : return rte_flow_error_set(error, EINVAL,
4213 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4214 : 0 : item->spec,
4215 : : "data cannot be empty");
4216 [ # # ]: 0 : if (spec->color > RTE_COLORS)
4217 : 0 : return rte_flow_error_set(error, EINVAL,
4218 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4219 : 0 : &spec->color,
4220 : : "meter color is invalid");
4221 [ # # ]: 0 : if (!mask)
4222 : : mask = &rte_flow_item_meter_color_mask;
4223 [ # # ]: 0 : if (!mask->color)
4224 : 0 : return rte_flow_error_set(error, EINVAL,
4225 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
4226 : : "mask cannot be zero");
4227 : :
4228 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
4229 : : (const uint8_t *)&nic_mask,
4230 : : sizeof(struct rte_flow_item_meter_color),
4231 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
4232 : : if (ret < 0)
4233 : : return ret;
4234 : : return 0;
4235 : : }
4236 : :
4237 : : /**
4238 : : * Validate aggregated affinity item.
4239 : : *
4240 : : * @param[in] dev
4241 : : * Pointer to the rte_eth_dev structure.
4242 : : * @param[in] item
4243 : : * Item specification.
4244 : : * @param[in] attr
4245 : : * Attributes of flow that includes this item.
4246 : : * @param[out] error
4247 : : * Pointer to error structure.
4248 : : *
4249 : : * @return
4250 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4251 : : */
4252 : : static int
4253 : 0 : flow_dv_validate_item_aggr_affinity(struct rte_eth_dev *dev,
4254 : : const struct rte_flow_item *item,
4255 : : const struct rte_flow_attr *attr,
4256 : : struct rte_flow_error *error)
4257 : : {
4258 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4259 : 0 : const struct rte_flow_item_aggr_affinity *spec = item->spec;
4260 : 0 : const struct rte_flow_item_aggr_affinity *mask = item->mask;
4261 : 0 : struct rte_flow_item_aggr_affinity nic_mask = {
4262 : : .affinity = UINT8_MAX
4263 : : };
4264 : : int ret;
4265 : :
4266 [ # # ]: 0 : if (!priv->sh->lag_rx_port_affinity_en)
4267 : 0 : return rte_flow_error_set(error, EINVAL,
4268 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
4269 : : "Unsupported aggregated affinity with Older FW");
4270 [ # # # # : 0 : if ((attr->transfer && priv->fdb_def_rule) ||
# # ]
4271 [ # # ]: 0 : attr->egress || attr->group)
4272 : 0 : return rte_flow_error_set(error, ENOTSUP,
4273 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4274 : : item->spec,
4275 : : "aggregated affinity is not supported with egress or FDB on non root table");
4276 [ # # ]: 0 : if (!spec)
4277 : 0 : return rte_flow_error_set(error, EINVAL,
4278 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4279 : : item->spec,
4280 : : "data cannot be empty");
4281 [ # # ]: 0 : if (spec->affinity == 0)
4282 : 0 : return rte_flow_error_set(error, ENOTSUP,
4283 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4284 : : item->spec,
4285 : : "zero affinity number not supported");
4286 [ # # ]: 0 : if (spec->affinity > priv->num_lag_ports)
4287 : 0 : return rte_flow_error_set(error, ENOTSUP,
4288 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4289 : : item->spec,
4290 : : "exceed max affinity number in lag ports");
4291 [ # # ]: 0 : if (!mask)
4292 : : mask = &rte_flow_item_aggr_affinity_mask;
4293 [ # # ]: 0 : if (!mask->affinity)
4294 : 0 : return rte_flow_error_set(error, EINVAL,
4295 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
4296 : : "mask cannot be zero");
4297 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
4298 : : (const uint8_t *)&nic_mask,
4299 : : sizeof(struct rte_flow_item_aggr_affinity),
4300 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
4301 : : if (ret < 0)
4302 : : return ret;
4303 : : return 0;
4304 : : }
4305 : :
4306 : : int
4307 : 0 : flow_encap_decap_match_cb(void *tool_ctx __rte_unused,
4308 : : struct mlx5_list_entry *entry, void *cb_ctx)
4309 : : {
4310 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4311 : 0 : struct mlx5_flow_dv_encap_decap_resource *ctx_resource = ctx->data;
4312 : : struct mlx5_flow_dv_encap_decap_resource *resource;
4313 : :
4314 : : resource = container_of(entry, struct mlx5_flow_dv_encap_decap_resource,
4315 : : entry);
4316 [ # # ]: 0 : if (resource->reformat_type == ctx_resource->reformat_type &&
4317 : 0 : resource->ft_type == ctx_resource->ft_type &&
4318 [ # # ]: 0 : resource->flags == ctx_resource->flags &&
4319 [ # # ]: 0 : resource->size == ctx_resource->size &&
4320 : 0 : !memcmp((const void *)resource->buf,
4321 [ # # ]: 0 : (const void *)ctx_resource->buf,
4322 : : resource->size))
4323 : 0 : return 0;
4324 : : return -1;
4325 : : }
4326 : :
4327 : : struct mlx5_list_entry *
4328 : 0 : flow_encap_decap_create_cb(void *tool_ctx, void *cb_ctx)
4329 : : {
4330 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4331 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4332 : : struct mlx5dv_dr_domain *domain;
4333 : 0 : struct mlx5_flow_dv_encap_decap_resource *ctx_resource = ctx->data;
4334 : : struct mlx5_flow_dv_encap_decap_resource *resource;
4335 : : uint32_t idx;
4336 : : int ret = 0;
4337 : : #ifdef HAVE_MLX5_HWS_SUPPORT
4338 : : struct mlx5dr_action_reformat_header hdr;
4339 : : #endif
4340 : :
4341 : : /* Register new encap/decap resource. */
4342 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], &idx);
4343 [ # # ]: 0 : if (!resource) {
4344 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4345 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4346 : : "cannot allocate resource memory");
4347 : 0 : return NULL;
4348 : : }
4349 : 0 : *resource = *ctx_resource;
4350 [ # # ]: 0 : if (sh->config.dv_flow_en == 2) {
4351 : : #ifdef HAVE_MLX5_HWS_SUPPORT
4352 : 0 : hdr.sz = ctx_resource->size;
4353 : 0 : hdr.data = ctx_resource->buf;
4354 : 0 : resource->action = mlx5dr_action_create_reformat
4355 : 0 : (ctx->data2, (enum mlx5dr_action_type)ctx_resource->reformat_type, 1,
4356 : 0 : &hdr, 0, ctx_resource->flags);
4357 [ # # ]: 0 : if (!resource->action)
4358 : : ret = -1;
4359 : : #else
4360 : : ret = -1;
4361 : : #endif
4362 : : } else {
4363 [ # # ]: 0 : if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
4364 : 0 : domain = sh->fdb_domain;
4365 [ # # ]: 0 : else if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
4366 : 0 : domain = sh->rx_domain;
4367 : : else
4368 : 0 : domain = sh->tx_domain;
4369 [ # # ]: 0 : ret = mlx5_flow_os_create_flow_action_packet_reformat(sh->cdev->ctx,
4370 : : domain, resource,
4371 : : &resource->action);
4372 : : }
4373 : : if (ret) {
4374 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], idx);
4375 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4376 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4377 : : NULL, "cannot create action");
4378 : 0 : return NULL;
4379 : : }
4380 : 0 : resource->idx = idx;
4381 : 0 : return &resource->entry;
4382 : : }
4383 : :
4384 : : struct mlx5_list_entry *
4385 : 0 : flow_encap_decap_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
4386 : : void *cb_ctx)
4387 : : {
4388 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4389 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4390 : : struct mlx5_flow_dv_encap_decap_resource *cache_resource;
4391 : : uint32_t idx;
4392 : :
4393 : 0 : cache_resource = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
4394 : : &idx);
4395 [ # # ]: 0 : if (!cache_resource) {
4396 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4397 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4398 : : "cannot allocate resource memory");
4399 : 0 : return NULL;
4400 : : }
4401 : : memcpy(cache_resource, oentry, sizeof(*cache_resource));
4402 : 0 : cache_resource->idx = idx;
4403 : 0 : return &cache_resource->entry;
4404 : : }
4405 : :
4406 : : void
4407 : 0 : flow_encap_decap_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4408 : : {
4409 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4410 : : struct mlx5_flow_dv_encap_decap_resource *res =
4411 : : container_of(entry, typeof(*res), entry);
4412 : :
4413 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], res->idx);
4414 : 0 : }
4415 : :
4416 : : int
4417 : 0 : __flow_encap_decap_resource_register(struct rte_eth_dev *dev,
4418 : : struct mlx5_flow_dv_encap_decap_resource *resource,
4419 : : bool is_root,
4420 : : struct mlx5_flow_dv_encap_decap_resource **encap_decap,
4421 : : struct rte_flow_error *error)
4422 : : {
4423 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4424 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
4425 : : struct mlx5_list_entry *entry;
4426 : : union {
4427 : : struct {
4428 : : uint32_t ft_type:8;
4429 : : uint32_t refmt_type:8;
4430 : : /*
4431 : : * Header reformat actions can be shared between
4432 : : * non-root tables. One bit to indicate non-root
4433 : : * table or not.
4434 : : */
4435 : : uint32_t is_root:1;
4436 : : uint32_t reserve:15;
4437 : : };
4438 : : uint32_t v32;
4439 : 0 : } encap_decap_key = {
4440 : : {
4441 : 0 : .ft_type = resource->ft_type,
4442 : 0 : .refmt_type = resource->reformat_type,
4443 : : .is_root = is_root,
4444 : : .reserve = 0,
4445 : : }
4446 : : };
4447 : 0 : struct mlx5_flow_cb_ctx ctx = {
4448 : : .error = error,
4449 : : .data = resource,
4450 : 0 : .data2 = priv->dr_ctx,
4451 : : };
4452 : : struct mlx5_hlist *encaps_decaps;
4453 : : uint64_t key64;
4454 : :
4455 : 0 : encaps_decaps = flow_dv_hlist_prepare(sh, &sh->encaps_decaps,
4456 : : "encaps_decaps",
4457 : : MLX5_FLOW_ENCAP_DECAP_HTABLE_SZ,
4458 : : true, true, sh,
4459 : : flow_encap_decap_create_cb,
4460 : : flow_encap_decap_match_cb,
4461 : : flow_encap_decap_remove_cb,
4462 : : flow_encap_decap_clone_cb,
4463 : : flow_encap_decap_clone_free_cb,
4464 : : error);
4465 [ # # ]: 0 : if (unlikely(!encaps_decaps))
4466 : 0 : return -rte_errno;
4467 : 0 : key64 = __rte_raw_cksum(&encap_decap_key.v32,
4468 : : sizeof(encap_decap_key.v32), 0);
4469 [ # # ]: 0 : if (resource->reformat_type !=
4470 : 0 : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2 &&
4471 [ # # ]: 0 : resource->size)
4472 : 0 : key64 = __rte_raw_cksum(resource->buf, resource->size, key64);
4473 : 0 : entry = mlx5_hlist_register(encaps_decaps, key64, &ctx);
4474 [ # # ]: 0 : if (!entry)
4475 : 0 : return -rte_errno;
4476 : 0 : *encap_decap = container_of(entry, typeof(*resource), entry);
4477 : 0 : return 0;
4478 : : }
4479 : :
4480 : : /**
4481 : : * Find existing encap/decap resource or create and register a new one.
4482 : : *
4483 : : * @param[in, out] dev
4484 : : * Pointer to rte_eth_dev structure.
4485 : : * @param[in, out] resource
4486 : : * Pointer to encap/decap resource.
4487 : : * @param[in, out] dev_flow
4488 : : * Pointer to the dev_flow.
4489 : : * @param[out] error
4490 : : * pointer to error structure.
4491 : : *
4492 : : * @return
4493 : : * 0 on success otherwise -errno and errno is set.
4494 : : */
4495 : : static int
4496 : 0 : flow_dv_encap_decap_resource_register
4497 : : (struct rte_eth_dev *dev,
4498 : : struct mlx5_flow_dv_encap_decap_resource *resource,
4499 : : struct mlx5_flow *dev_flow,
4500 : : struct rte_flow_error *error)
4501 : : {
4502 : : int ret;
4503 : :
4504 : 0 : resource->flags = dev_flow->dv.group ? 0 : 1;
4505 : 0 : ret = __flow_encap_decap_resource_register(dev, resource, !!dev_flow->dv.group,
4506 : : &dev_flow->dv.encap_decap, error);
4507 [ # # ]: 0 : if (ret)
4508 : : return ret;
4509 : 0 : dev_flow->handle->dvh.rix_encap_decap = dev_flow->dv.encap_decap->idx;
4510 : 0 : return 0;
4511 : : }
4512 : :
4513 : : /**
4514 : : * Find existing table jump resource or create and register a new one.
4515 : : *
4516 : : * @param[in, out] dev
4517 : : * Pointer to rte_eth_dev structure.
4518 : : * @param[in, out] tbl
4519 : : * Pointer to flow table resource.
4520 : : * @parm[in, out] dev_flow
4521 : : * Pointer to the dev_flow.
4522 : : * @param[out] error
4523 : : * pointer to error structure.
4524 : : *
4525 : : * @return
4526 : : * 0 on success otherwise -errno and errno is set.
4527 : : */
4528 : : static int
4529 : : flow_dv_jump_tbl_resource_register
4530 : : (struct rte_eth_dev *dev __rte_unused,
4531 : : struct mlx5_flow_tbl_resource *tbl,
4532 : : struct mlx5_flow *dev_flow,
4533 : : struct rte_flow_error *error __rte_unused)
4534 : : {
4535 : : struct mlx5_flow_tbl_data_entry *tbl_data =
4536 : 0 : container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
4537 : :
4538 : : MLX5_ASSERT(tbl);
4539 : : MLX5_ASSERT(tbl_data->jump.action);
4540 : 0 : dev_flow->handle->rix_jump = tbl_data->idx;
4541 : 0 : dev_flow->dv.jump = &tbl_data->jump;
4542 : : return 0;
4543 : : }
4544 : :
4545 : : int
4546 : 0 : flow_dv_port_id_match_cb(void *tool_ctx __rte_unused,
4547 : : struct mlx5_list_entry *entry, void *cb_ctx)
4548 : : {
4549 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4550 : 0 : struct mlx5_flow_dv_port_id_action_resource *ref = ctx->data;
4551 : : struct mlx5_flow_dv_port_id_action_resource *res =
4552 : : container_of(entry, typeof(*res), entry);
4553 : :
4554 : 0 : return ref->port_id != res->port_id;
4555 : : }
4556 : :
4557 : : struct mlx5_list_entry *
4558 : 0 : flow_dv_port_id_create_cb(void *tool_ctx, void *cb_ctx)
4559 : : {
4560 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4561 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4562 : 0 : struct mlx5_flow_dv_port_id_action_resource *ref = ctx->data;
4563 : : struct mlx5_flow_dv_port_id_action_resource *resource;
4564 : : uint32_t idx;
4565 : : int ret;
4566 : :
4567 : : /* Register new port id action resource. */
4568 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID], &idx);
4569 [ # # ]: 0 : if (!resource) {
4570 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4571 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4572 : : "cannot allocate port_id action memory");
4573 : 0 : return NULL;
4574 : : }
4575 : 0 : *resource = *ref;
4576 : 0 : ret = mlx5_flow_os_create_flow_action_dest_port(sh->fdb_domain,
4577 : : ref->port_id,
4578 : : &resource->action);
4579 : : if (ret) {
4580 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], idx);
4581 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4582 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4583 : : "cannot create action");
4584 : 0 : return NULL;
4585 : : }
4586 : 0 : resource->idx = idx;
4587 : 0 : return &resource->entry;
4588 : : }
4589 : :
4590 : : struct mlx5_list_entry *
4591 : 0 : flow_dv_port_id_clone_cb(void *tool_ctx,
4592 : : struct mlx5_list_entry *entry __rte_unused,
4593 : : void *cb_ctx)
4594 : : {
4595 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4596 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4597 : : struct mlx5_flow_dv_port_id_action_resource *resource;
4598 : : uint32_t idx;
4599 : :
4600 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID], &idx);
4601 [ # # ]: 0 : if (!resource) {
4602 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4603 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4604 : : "cannot allocate port_id action memory");
4605 : 0 : return NULL;
4606 : : }
4607 : : memcpy(resource, entry, sizeof(*resource));
4608 : 0 : resource->idx = idx;
4609 : 0 : return &resource->entry;
4610 : : }
4611 : :
4612 : : void
4613 : 0 : flow_dv_port_id_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4614 : : {
4615 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4616 : : struct mlx5_flow_dv_port_id_action_resource *resource =
4617 : : container_of(entry, typeof(*resource), entry);
4618 : :
4619 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], resource->idx);
4620 : 0 : }
4621 : :
4622 : : /**
4623 : : * Find existing table port ID resource or create and register a new one.
4624 : : *
4625 : : * @param[in, out] dev
4626 : : * Pointer to rte_eth_dev structure.
4627 : : * @param[in, out] ref
4628 : : * Pointer to port ID action resource reference.
4629 : : * @parm[in, out] dev_flow
4630 : : * Pointer to the dev_flow.
4631 : : * @param[out] error
4632 : : * pointer to error structure.
4633 : : *
4634 : : * @return
4635 : : * 0 on success otherwise -errno and errno is set.
4636 : : */
4637 : : static int
4638 : 0 : flow_dv_port_id_action_resource_register
4639 : : (struct rte_eth_dev *dev,
4640 : : struct mlx5_flow_dv_port_id_action_resource *ref,
4641 : : struct mlx5_flow *dev_flow,
4642 : : struct rte_flow_error *error)
4643 : : {
4644 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4645 : : struct mlx5_list_entry *entry;
4646 : : struct mlx5_flow_dv_port_id_action_resource *resource;
4647 : 0 : struct mlx5_flow_cb_ctx ctx = {
4648 : : .error = error,
4649 : : .data = ref,
4650 : : };
4651 : :
4652 : 0 : entry = mlx5_list_register(priv->sh->port_id_action_list, &ctx);
4653 [ # # ]: 0 : if (!entry)
4654 : 0 : return -rte_errno;
4655 : : resource = container_of(entry, typeof(*resource), entry);
4656 : 0 : dev_flow->dv.port_id_action = resource;
4657 : 0 : dev_flow->handle->rix_port_id_action = resource->idx;
4658 : 0 : return 0;
4659 : : }
4660 : :
4661 : : int
4662 : 0 : flow_dv_push_vlan_match_cb(void *tool_ctx __rte_unused,
4663 : : struct mlx5_list_entry *entry, void *cb_ctx)
4664 : : {
4665 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4666 : 0 : struct mlx5_flow_dv_push_vlan_action_resource *ref = ctx->data;
4667 : : struct mlx5_flow_dv_push_vlan_action_resource *res =
4668 : : container_of(entry, typeof(*res), entry);
4669 : :
4670 : 0 : return ref->vlan_tag != res->vlan_tag || ref->ft_type != res->ft_type;
4671 : : }
4672 : :
4673 : : struct mlx5_list_entry *
4674 : 0 : flow_dv_push_vlan_create_cb(void *tool_ctx, void *cb_ctx)
4675 : : {
4676 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4677 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4678 : 0 : struct mlx5_flow_dv_push_vlan_action_resource *ref = ctx->data;
4679 : : struct mlx5_flow_dv_push_vlan_action_resource *resource;
4680 : : struct mlx5dv_dr_domain *domain;
4681 : : uint32_t idx;
4682 : : int ret;
4683 : :
4684 : : /* Register new port id action resource. */
4685 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PUSH_VLAN], &idx);
4686 [ # # ]: 0 : if (!resource) {
4687 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4688 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4689 : : "cannot allocate push_vlan action memory");
4690 : 0 : return NULL;
4691 : : }
4692 : 0 : *resource = *ref;
4693 [ # # ]: 0 : if (ref->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
4694 : 0 : domain = sh->fdb_domain;
4695 [ # # ]: 0 : else if (ref->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
4696 : 0 : domain = sh->rx_domain;
4697 : : else
4698 : 0 : domain = sh->tx_domain;
4699 : 0 : ret = mlx5_flow_os_create_flow_action_push_vlan(domain, ref->vlan_tag,
4700 : : &resource->action);
4701 : : if (ret) {
4702 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
4703 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4704 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4705 : : "cannot create push vlan action");
4706 : 0 : return NULL;
4707 : : }
4708 : 0 : resource->idx = idx;
4709 : 0 : return &resource->entry;
4710 : : }
4711 : :
4712 : : struct mlx5_list_entry *
4713 : 0 : flow_dv_push_vlan_clone_cb(void *tool_ctx,
4714 : : struct mlx5_list_entry *entry __rte_unused,
4715 : : void *cb_ctx)
4716 : : {
4717 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4718 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4719 : : struct mlx5_flow_dv_push_vlan_action_resource *resource;
4720 : : uint32_t idx;
4721 : :
4722 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PUSH_VLAN], &idx);
4723 [ # # ]: 0 : if (!resource) {
4724 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4725 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4726 : : "cannot allocate push_vlan action memory");
4727 : 0 : return NULL;
4728 : : }
4729 : : memcpy(resource, entry, sizeof(*resource));
4730 : 0 : resource->idx = idx;
4731 : 0 : return &resource->entry;
4732 : : }
4733 : :
4734 : : void
4735 : 0 : flow_dv_push_vlan_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4736 : : {
4737 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4738 : : struct mlx5_flow_dv_push_vlan_action_resource *resource =
4739 : : container_of(entry, typeof(*resource), entry);
4740 : :
4741 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], resource->idx);
4742 : 0 : }
4743 : :
4744 : : /**
4745 : : * Find existing push vlan resource or create and register a new one.
4746 : : *
4747 : : * @param [in, out] dev
4748 : : * Pointer to rte_eth_dev structure.
4749 : : * @param[in, out] ref
4750 : : * Pointer to port ID action resource reference.
4751 : : * @parm[in, out] dev_flow
4752 : : * Pointer to the dev_flow.
4753 : : * @param[out] error
4754 : : * pointer to error structure.
4755 : : *
4756 : : * @return
4757 : : * 0 on success otherwise -errno and errno is set.
4758 : : */
4759 : : static int
4760 : 0 : flow_dv_push_vlan_action_resource_register
4761 : : (struct rte_eth_dev *dev,
4762 : : struct mlx5_flow_dv_push_vlan_action_resource *ref,
4763 : : struct mlx5_flow *dev_flow,
4764 : : struct rte_flow_error *error)
4765 : : {
4766 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4767 : : struct mlx5_flow_dv_push_vlan_action_resource *resource;
4768 : : struct mlx5_list_entry *entry;
4769 : 0 : struct mlx5_flow_cb_ctx ctx = {
4770 : : .error = error,
4771 : : .data = ref,
4772 : : };
4773 : :
4774 : 0 : entry = mlx5_list_register(priv->sh->push_vlan_action_list, &ctx);
4775 [ # # ]: 0 : if (!entry)
4776 : 0 : return -rte_errno;
4777 : : resource = container_of(entry, typeof(*resource), entry);
4778 : :
4779 : 0 : dev_flow->handle->dvh.rix_push_vlan = resource->idx;
4780 : 0 : dev_flow->dv.push_vlan_res = resource;
4781 : 0 : return 0;
4782 : : }
4783 : :
4784 : : /**
4785 : : * Get the size of specific rte_flow_item_type hdr size
4786 : : *
4787 : : * @param[in] item_type
4788 : : * Tested rte_flow_item_type.
4789 : : *
4790 : : * @return
4791 : : * sizeof struct item_type, 0 if void or irrelevant.
4792 : : */
4793 : : size_t
4794 [ # # ]: 0 : flow_dv_get_item_hdr_len(const enum rte_flow_item_type item_type)
4795 : : {
4796 : : size_t retval;
4797 : :
4798 : : switch (item_type) {
4799 : : case RTE_FLOW_ITEM_TYPE_ETH:
4800 : : retval = sizeof(struct rte_ether_hdr);
4801 : : break;
4802 : : case RTE_FLOW_ITEM_TYPE_VLAN:
4803 : : retval = sizeof(struct rte_vlan_hdr);
4804 : : break;
4805 : : case RTE_FLOW_ITEM_TYPE_IPV4:
4806 : : retval = sizeof(struct rte_ipv4_hdr);
4807 : : break;
4808 : : case RTE_FLOW_ITEM_TYPE_IPV6:
4809 : : retval = sizeof(struct rte_ipv6_hdr);
4810 : : break;
4811 : : case RTE_FLOW_ITEM_TYPE_UDP:
4812 : : retval = sizeof(struct rte_udp_hdr);
4813 : : break;
4814 : : case RTE_FLOW_ITEM_TYPE_TCP:
4815 : : retval = sizeof(struct rte_tcp_hdr);
4816 : : break;
4817 : : case RTE_FLOW_ITEM_TYPE_VXLAN:
4818 : : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
4819 : : retval = sizeof(struct rte_vxlan_hdr);
4820 : : break;
4821 : : case RTE_FLOW_ITEM_TYPE_GRE:
4822 : : case RTE_FLOW_ITEM_TYPE_NVGRE:
4823 : : retval = sizeof(struct rte_gre_hdr);
4824 : : break;
4825 : : case RTE_FLOW_ITEM_TYPE_MPLS:
4826 : : retval = sizeof(struct rte_mpls_hdr);
4827 : : break;
4828 : : case RTE_FLOW_ITEM_TYPE_VOID: /* Fall through. */
4829 : : default:
4830 : : retval = 0;
4831 : : break;
4832 : : }
4833 : 0 : return retval;
4834 : : }
4835 : :
4836 : : #define MLX5_ENCAP_IPV4_VERSION 0x40
4837 : : #define MLX5_ENCAP_IPV4_IHL_MIN 0x05
4838 : : #define MLX5_ENCAP_IPV4_TTL_DEF 0x40
4839 : : #define MLX5_ENCAP_IPV6_VTC_FLOW 0x60000000
4840 : : #define MLX5_ENCAP_IPV6_HOP_LIMIT 0xff
4841 : : #define MLX5_ENCAP_VXLAN_FLAGS 0x08000000
4842 : : #define MLX5_ENCAP_VXLAN_GPE_FLAGS 0x04
4843 : :
4844 : : /**
4845 : : * Convert the encap action data from list of rte_flow_item to raw buffer
4846 : : *
4847 : : * @param[in] items
4848 : : * Pointer to rte_flow_item objects list.
4849 : : * @param[out] buf
4850 : : * Pointer to the output buffer.
4851 : : * @param[out] size
4852 : : * Pointer to the output buffer size.
4853 : : * @param[out] error
4854 : : * Pointer to the error structure.
4855 : : *
4856 : : * @return
4857 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4858 : : */
4859 : : int
4860 : 0 : flow_dv_convert_encap_data(const struct rte_flow_item *items, uint8_t *buf,
4861 : : size_t *size, struct rte_flow_error *error)
4862 : : {
4863 : : struct rte_ether_hdr *eth = NULL;
4864 : : struct rte_vlan_hdr *vlan = NULL;
4865 : : struct rte_ipv4_hdr *ipv4 = NULL;
4866 : : struct rte_ipv6_hdr *ipv6 = NULL;
4867 : : struct rte_udp_hdr *udp = NULL;
4868 : : struct rte_vxlan_hdr *vxlan = NULL;
4869 : : struct rte_vxlan_gpe_hdr *vxlan_gpe = NULL;
4870 : : struct rte_gre_hdr *gre = NULL;
4871 : : size_t len;
4872 : : size_t temp_size = 0;
4873 : :
4874 [ # # ]: 0 : if (!items)
4875 : 0 : return rte_flow_error_set(error, EINVAL,
4876 : : RTE_FLOW_ERROR_TYPE_ACTION,
4877 : : NULL, "invalid empty data");
4878 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4879 : 0 : len = flow_dv_get_item_hdr_len(items->type);
4880 [ # # ]: 0 : if (len + temp_size > MLX5_ENCAP_MAX_LEN)
4881 : 0 : return rte_flow_error_set(error, EINVAL,
4882 : : RTE_FLOW_ERROR_TYPE_ACTION,
4883 : 0 : (void *)items->type,
4884 : : "items total size is too big"
4885 : : " for encap action");
4886 [ # # ]: 0 : if (items->spec)
4887 [ # # ]: 0 : rte_memcpy(&buf[temp_size], items->spec, len);
4888 [ # # # # : 0 : switch (items->type) {
# # # # #
# ]
4889 : 0 : case RTE_FLOW_ITEM_TYPE_ETH:
4890 : 0 : eth = (struct rte_ether_hdr *)&buf[temp_size];
4891 : 0 : break;
4892 : 0 : case RTE_FLOW_ITEM_TYPE_VLAN:
4893 : 0 : vlan = (struct rte_vlan_hdr *)&buf[temp_size];
4894 [ # # ]: 0 : if (!eth)
4895 : 0 : return rte_flow_error_set(error, EINVAL,
4896 : : RTE_FLOW_ERROR_TYPE_ACTION,
4897 : : (void *)items->type,
4898 : : "eth header not found");
4899 [ # # ]: 0 : if (!eth->ether_type)
4900 : 0 : eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_VLAN);
4901 : : break;
4902 : 0 : case RTE_FLOW_ITEM_TYPE_IPV4:
4903 : 0 : ipv4 = (struct rte_ipv4_hdr *)&buf[temp_size];
4904 [ # # ]: 0 : if (!vlan && !eth)
4905 : 0 : return rte_flow_error_set(error, EINVAL,
4906 : : RTE_FLOW_ERROR_TYPE_ACTION,
4907 : : (void *)items->type,
4908 : : "neither eth nor vlan"
4909 : : " header found");
4910 [ # # # # ]: 0 : if (vlan && !vlan->eth_proto)
4911 : 0 : vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV4);
4912 [ # # # # ]: 0 : else if (eth && !eth->ether_type)
4913 : 0 : eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV4);
4914 [ # # ]: 0 : if (!ipv4->version_ihl)
4915 : 0 : ipv4->version_ihl = MLX5_ENCAP_IPV4_VERSION |
4916 : : MLX5_ENCAP_IPV4_IHL_MIN;
4917 [ # # ]: 0 : if (!ipv4->time_to_live)
4918 : 0 : ipv4->time_to_live = MLX5_ENCAP_IPV4_TTL_DEF;
4919 : : break;
4920 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6:
4921 : 0 : ipv6 = (struct rte_ipv6_hdr *)&buf[temp_size];
4922 [ # # ]: 0 : if (!vlan && !eth)
4923 : 0 : return rte_flow_error_set(error, EINVAL,
4924 : : RTE_FLOW_ERROR_TYPE_ACTION,
4925 : : (void *)items->type,
4926 : : "neither eth nor vlan"
4927 : : " header found");
4928 [ # # # # ]: 0 : if (vlan && !vlan->eth_proto)
4929 : 0 : vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV6);
4930 [ # # # # ]: 0 : else if (eth && !eth->ether_type)
4931 : 0 : eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV6);
4932 [ # # ]: 0 : if (!ipv6->vtc_flow)
4933 : 0 : ipv6->vtc_flow =
4934 : : RTE_BE32(MLX5_ENCAP_IPV6_VTC_FLOW);
4935 [ # # ]: 0 : if (!ipv6->hop_limits)
4936 : 0 : ipv6->hop_limits = MLX5_ENCAP_IPV6_HOP_LIMIT;
4937 : : break;
4938 : 0 : case RTE_FLOW_ITEM_TYPE_UDP:
4939 : 0 : udp = (struct rte_udp_hdr *)&buf[temp_size];
4940 [ # # ]: 0 : if (!ipv4 && !ipv6)
4941 : 0 : return rte_flow_error_set(error, EINVAL,
4942 : : RTE_FLOW_ERROR_TYPE_ACTION,
4943 : : (void *)items->type,
4944 : : "ip header not found");
4945 [ # # # # ]: 0 : if (ipv4 && !ipv4->next_proto_id)
4946 : 0 : ipv4->next_proto_id = IPPROTO_UDP;
4947 [ # # # # ]: 0 : else if (ipv6 && !ipv6->proto)
4948 : 0 : ipv6->proto = IPPROTO_UDP;
4949 : : break;
4950 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN:
4951 : 0 : vxlan = (struct rte_vxlan_hdr *)&buf[temp_size];
4952 [ # # ]: 0 : if (!udp)
4953 : 0 : return rte_flow_error_set(error, EINVAL,
4954 : : RTE_FLOW_ERROR_TYPE_ACTION,
4955 : : (void *)items->type,
4956 : : "udp header not found");
4957 [ # # ]: 0 : if (!udp->dst_port)
4958 : 0 : udp->dst_port = RTE_BE16(MLX5_UDP_PORT_VXLAN);
4959 [ # # ]: 0 : if (!vxlan->vx_flags)
4960 : 0 : vxlan->vx_flags =
4961 : : RTE_BE32(MLX5_ENCAP_VXLAN_FLAGS);
4962 : : break;
4963 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
4964 : 0 : vxlan_gpe = (struct rte_vxlan_gpe_hdr *)&buf[temp_size];
4965 [ # # ]: 0 : if (!udp)
4966 : 0 : return rte_flow_error_set(error, EINVAL,
4967 : : RTE_FLOW_ERROR_TYPE_ACTION,
4968 : : (void *)items->type,
4969 : : "udp header not found");
4970 [ # # ]: 0 : if (!vxlan_gpe->proto)
4971 : 0 : return rte_flow_error_set(error, EINVAL,
4972 : : RTE_FLOW_ERROR_TYPE_ACTION,
4973 : : (void *)items->type,
4974 : : "next protocol not found");
4975 [ # # ]: 0 : if (!udp->dst_port)
4976 : 0 : udp->dst_port =
4977 : : RTE_BE16(MLX5_UDP_PORT_VXLAN_GPE);
4978 [ # # ]: 0 : if (!vxlan_gpe->vx_flags)
4979 : 0 : vxlan_gpe->vx_flags =
4980 : : MLX5_ENCAP_VXLAN_GPE_FLAGS;
4981 : : break;
4982 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
4983 : : case RTE_FLOW_ITEM_TYPE_NVGRE:
4984 : 0 : gre = (struct rte_gre_hdr *)&buf[temp_size];
4985 [ # # ]: 0 : if (!gre->proto)
4986 : 0 : return rte_flow_error_set(error, EINVAL,
4987 : : RTE_FLOW_ERROR_TYPE_ACTION,
4988 : 0 : (void *)items->type,
4989 : : "next protocol not found");
4990 [ # # ]: 0 : if (!ipv4 && !ipv6)
4991 : 0 : return rte_flow_error_set(error, EINVAL,
4992 : : RTE_FLOW_ERROR_TYPE_ACTION,
4993 : 0 : (void *)items->type,
4994 : : "ip header not found");
4995 [ # # # # ]: 0 : if (ipv4 && !ipv4->next_proto_id)
4996 : 0 : ipv4->next_proto_id = IPPROTO_GRE;
4997 [ # # # # ]: 0 : else if (ipv6 && !ipv6->proto)
4998 : 0 : ipv6->proto = IPPROTO_GRE;
4999 : : break;
5000 : : case RTE_FLOW_ITEM_TYPE_VOID:
5001 : : break;
5002 : 0 : default:
5003 : 0 : return rte_flow_error_set(error, EINVAL,
5004 : : RTE_FLOW_ERROR_TYPE_ACTION,
5005 : 0 : (void *)items->type,
5006 : : "unsupported item type");
5007 : : break;
5008 : : }
5009 : : temp_size += len;
5010 : : }
5011 : 0 : *size = temp_size;
5012 : 0 : return 0;
5013 : : }
5014 : :
5015 : : static int
5016 : 0 : flow_dv_zero_encap_udp_csum(void *data, struct rte_flow_error *error)
5017 : : {
5018 : : struct rte_ether_hdr *eth = NULL;
5019 : : struct rte_vlan_hdr *vlan = NULL;
5020 : : struct rte_ipv4_hdr *ipv4 = NULL;
5021 : : struct rte_ipv6_hdr *ipv6 = NULL;
5022 : : struct rte_udp_hdr *udp = NULL;
5023 : : char *next_hdr;
5024 : : uint16_t proto;
5025 : :
5026 : : eth = (struct rte_ether_hdr *)data;
5027 : 0 : next_hdr = (char *)(eth + 1);
5028 : 0 : proto = RTE_BE16(eth->ether_type);
5029 : :
5030 : : /* VLAN skipping */
5031 [ # # ]: 0 : while (proto == RTE_ETHER_TYPE_VLAN || proto == RTE_ETHER_TYPE_QINQ) {
5032 : : vlan = (struct rte_vlan_hdr *)next_hdr;
5033 : 0 : proto = RTE_BE16(vlan->eth_proto);
5034 : 0 : next_hdr += sizeof(struct rte_vlan_hdr);
5035 : : }
5036 : :
5037 : : /* non IPv4/IPv6 header. not supported */
5038 [ # # ]: 0 : if (proto != RTE_ETHER_TYPE_IPV4 && proto != RTE_ETHER_TYPE_IPV6) {
5039 : 0 : return rte_flow_error_set(error, ENOTSUP,
5040 : : RTE_FLOW_ERROR_TYPE_ACTION,
5041 : : NULL, "Cannot offload non IPv4/IPv6");
5042 : : }
5043 : :
5044 [ # # ]: 0 : if (proto == RTE_ETHER_TYPE_IPV4) {
5045 : : ipv4 = (struct rte_ipv4_hdr *)next_hdr;
5046 : : /* ignore non UDP */
5047 [ # # ]: 0 : if (ipv4->next_proto_id != IPPROTO_UDP)
5048 : : return 0;
5049 : 0 : udp = (struct rte_udp_hdr *)(ipv4 + 1);
5050 : : } else {
5051 : : ipv6 = (struct rte_ipv6_hdr *)next_hdr;
5052 : : /* ignore non UDP */
5053 [ # # ]: 0 : if (ipv6->proto != IPPROTO_UDP)
5054 : : return 0;
5055 : 0 : udp = (struct rte_udp_hdr *)(ipv6 + 1);
5056 : : }
5057 : :
5058 : 0 : udp->dgram_cksum = 0;
5059 : :
5060 : 0 : return 0;
5061 : : }
5062 : :
5063 : : /**
5064 : : * Convert L2 encap action to DV specification.
5065 : : *
5066 : : * @param[in] dev
5067 : : * Pointer to rte_eth_dev structure.
5068 : : * @param[in] action
5069 : : * Pointer to action structure.
5070 : : * @param[in, out] dev_flow
5071 : : * Pointer to the mlx5_flow.
5072 : : * @param[in] transfer
5073 : : * Mark if the flow is E-Switch flow.
5074 : : * @param[out] error
5075 : : * Pointer to the error structure.
5076 : : *
5077 : : * @return
5078 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5079 : : */
5080 : : static int
5081 : 0 : flow_dv_create_action_l2_encap(struct rte_eth_dev *dev,
5082 : : const struct rte_flow_action *action,
5083 : : struct mlx5_flow *dev_flow,
5084 : : uint8_t transfer,
5085 : : struct rte_flow_error *error)
5086 : : {
5087 : : const struct rte_flow_item *encap_data;
5088 : : const struct rte_flow_action_raw_encap *raw_encap_data;
5089 [ # # ]: 0 : struct mlx5_flow_dv_encap_decap_resource res = {
5090 : : .reformat_type =
5091 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L2_TUNNEL,
5092 : : .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
5093 : : MLX5DV_FLOW_TABLE_TYPE_NIC_TX,
5094 : : };
5095 : :
5096 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
5097 : 0 : raw_encap_data =
5098 : : (const struct rte_flow_action_raw_encap *)action->conf;
5099 : 0 : res.size = raw_encap_data->size;
5100 : 0 : memcpy(res.buf, raw_encap_data->data, res.size);
5101 : : } else {
5102 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP)
5103 : 0 : encap_data =
5104 : : ((const struct rte_flow_action_vxlan_encap *)
5105 : 0 : action->conf)->definition;
5106 : : else
5107 : 0 : encap_data =
5108 : : ((const struct rte_flow_action_nvgre_encap *)
5109 : 0 : action->conf)->definition;
5110 [ # # ]: 0 : if (flow_dv_convert_encap_data(encap_data, res.buf,
5111 : : &res.size, error))
5112 : 0 : return -rte_errno;
5113 : : }
5114 [ # # ]: 0 : if (flow_dv_zero_encap_udp_csum(res.buf, error))
5115 : 0 : return -rte_errno;
5116 [ # # ]: 0 : if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
5117 : 0 : return rte_flow_error_set(error, EINVAL,
5118 : : RTE_FLOW_ERROR_TYPE_ACTION,
5119 : : NULL, "can't create L2 encap action");
5120 : : return 0;
5121 : : }
5122 : :
5123 : : /**
5124 : : * Convert L2 decap action to DV specification.
5125 : : *
5126 : : * @param[in] dev
5127 : : * Pointer to rte_eth_dev structure.
5128 : : * @param[in, out] dev_flow
5129 : : * Pointer to the mlx5_flow.
5130 : : * @param[in] transfer
5131 : : * Mark if the flow is E-Switch flow.
5132 : : * @param[out] error
5133 : : * Pointer to the error structure.
5134 : : *
5135 : : * @return
5136 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5137 : : */
5138 : : static int
5139 : 0 : flow_dv_create_action_l2_decap(struct rte_eth_dev *dev,
5140 : : struct mlx5_flow *dev_flow,
5141 : : uint8_t transfer,
5142 : : struct rte_flow_error *error)
5143 : : {
5144 [ # # ]: 0 : struct mlx5_flow_dv_encap_decap_resource res = {
5145 : : .size = 0,
5146 : : .reformat_type =
5147 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2,
5148 : : .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
5149 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX,
5150 : : };
5151 : :
5152 [ # # ]: 0 : if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
5153 : 0 : return rte_flow_error_set(error, EINVAL,
5154 : : RTE_FLOW_ERROR_TYPE_ACTION,
5155 : : NULL, "can't create L2 decap action");
5156 : : return 0;
5157 : : }
5158 : :
5159 : : /**
5160 : : * Convert raw decap/encap (L3 tunnel) action to DV specification.
5161 : : *
5162 : : * @param[in] dev
5163 : : * Pointer to rte_eth_dev structure.
5164 : : * @param[in] action
5165 : : * Pointer to action structure.
5166 : : * @param[in, out] dev_flow
5167 : : * Pointer to the mlx5_flow.
5168 : : * @param[in] attr
5169 : : * Pointer to the flow attributes.
5170 : : * @param[out] error
5171 : : * Pointer to the error structure.
5172 : : *
5173 : : * @return
5174 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5175 : : */
5176 : : static int
5177 [ # # ]: 0 : flow_dv_create_action_raw_encap(struct rte_eth_dev *dev,
5178 : : const struct rte_flow_action *action,
5179 : : struct mlx5_flow *dev_flow,
5180 : : const struct rte_flow_attr *attr,
5181 : : struct rte_flow_error *error)
5182 : : {
5183 : : const struct rte_flow_action_raw_encap *encap_data;
5184 : : struct mlx5_flow_dv_encap_decap_resource res;
5185 : :
5186 : : memset(&res, 0, sizeof(res));
5187 : 0 : encap_data = (const struct rte_flow_action_raw_encap *)action->conf;
5188 : 0 : res.size = encap_data->size;
5189 [ # # ]: 0 : memcpy(res.buf, encap_data->data, res.size);
5190 [ # # ]: 0 : res.reformat_type = res.size < MLX5_ENCAPSULATION_DECISION_SIZE ?
5191 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L3_TUNNEL_TO_L2 :
5192 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L3_TUNNEL;
5193 [ # # ]: 0 : if (attr->transfer)
5194 : 0 : res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
5195 : : else
5196 : 0 : res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
5197 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
5198 [ # # ]: 0 : if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
5199 : 0 : return rte_flow_error_set(error, EINVAL,
5200 : : RTE_FLOW_ERROR_TYPE_ACTION,
5201 : : NULL, "can't create encap action");
5202 : : return 0;
5203 : : }
5204 : :
5205 : : /**
5206 : : * Create action push VLAN.
5207 : : *
5208 : : * @param[in] dev
5209 : : * Pointer to rte_eth_dev structure.
5210 : : * @param[in] attr
5211 : : * Pointer to the flow attributes.
5212 : : * @param[in] vlan
5213 : : * Pointer to the vlan to push to the Ethernet header.
5214 : : * @param[in, out] dev_flow
5215 : : * Pointer to the mlx5_flow.
5216 : : * @param[out] error
5217 : : * Pointer to the error structure.
5218 : : *
5219 : : * @return
5220 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5221 : : */
5222 : : static int
5223 [ # # ]: 0 : flow_dv_create_action_push_vlan(struct rte_eth_dev *dev,
5224 : : const struct rte_flow_attr *attr,
5225 : : const struct rte_vlan_hdr *vlan,
5226 : : struct mlx5_flow *dev_flow,
5227 : : struct rte_flow_error *error)
5228 : : {
5229 : : struct mlx5_flow_dv_push_vlan_action_resource res;
5230 : :
5231 : : memset(&res, 0, sizeof(res));
5232 : 0 : res.vlan_tag =
5233 [ # # ]: 0 : rte_cpu_to_be_32(((uint32_t)vlan->eth_proto) << 16 |
5234 : : vlan->vlan_tci);
5235 [ # # ]: 0 : if (attr->transfer)
5236 : 0 : res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
5237 : : else
5238 : 0 : res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
5239 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
5240 : 0 : return flow_dv_push_vlan_action_resource_register
5241 : : (dev, &res, dev_flow, error);
5242 : : }
5243 : :
5244 : : /**
5245 : : * Validate the modify-header actions.
5246 : : *
5247 : : * @param[in] action_flags
5248 : : * Holds the actions detected until now.
5249 : : * @param[in] action
5250 : : * Pointer to the modify action.
5251 : : * @param[out] error
5252 : : * Pointer to error structure.
5253 : : *
5254 : : * @return
5255 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5256 : : */
5257 : : static int
5258 : 0 : flow_dv_validate_action_modify_hdr(const uint64_t action_flags,
5259 : : const struct rte_flow_action *action,
5260 : : struct rte_flow_error *error)
5261 : : {
5262 [ # # # # ]: 0 : if (action->type != RTE_FLOW_ACTION_TYPE_DEC_TTL && !action->conf)
5263 : 0 : return rte_flow_error_set(error, EINVAL,
5264 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5265 : : NULL, "action configuration not set");
5266 : :
5267 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
5268 : 0 : return rte_flow_error_set(error, EINVAL,
5269 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5270 : : "can't have encap action before"
5271 : : " modify action");
5272 : : return 0;
5273 : : }
5274 : :
5275 : : /**
5276 : : * Validate the modify-header MAC address actions.
5277 : : *
5278 : : * @param[in] action_flags
5279 : : * Holds the actions detected until now.
5280 : : * @param[in] action
5281 : : * Pointer to the modify action.
5282 : : * @param[in] item_flags
5283 : : * Holds the items detected.
5284 : : * @param[out] error
5285 : : * Pointer to error structure.
5286 : : *
5287 : : * @return
5288 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5289 : : */
5290 : : static int
5291 : 0 : flow_dv_validate_action_modify_mac(const uint64_t action_flags,
5292 : : const struct rte_flow_action *action,
5293 : : const uint64_t item_flags,
5294 : : struct rte_flow_error *error)
5295 : : {
5296 : : int ret = 0;
5297 : :
5298 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5299 [ # # ]: 0 : if (!ret) {
5300 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_L2))
5301 : 0 : return rte_flow_error_set(error, EINVAL,
5302 : : RTE_FLOW_ERROR_TYPE_ACTION,
5303 : : NULL,
5304 : : "no L2 item in pattern");
5305 : : }
5306 : : return ret;
5307 : : }
5308 : :
5309 : : /**
5310 : : * Validate the modify-header IPv4 address actions.
5311 : : *
5312 : : * @param[in] action_flags
5313 : : * Holds the actions detected until now.
5314 : : * @param[in] action
5315 : : * Pointer to the modify action.
5316 : : * @param[in] item_flags
5317 : : * Holds the items detected.
5318 : : * @param[out] error
5319 : : * Pointer to error structure.
5320 : : *
5321 : : * @return
5322 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5323 : : */
5324 : : static int
5325 : 0 : flow_dv_validate_action_modify_ipv4(const uint64_t action_flags,
5326 : : const struct rte_flow_action *action,
5327 : : const uint64_t item_flags,
5328 : : struct rte_flow_error *error)
5329 : : {
5330 : : int ret = 0;
5331 : : uint64_t layer;
5332 : :
5333 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5334 [ # # ]: 0 : if (!ret) {
5335 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5336 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L3_IPV4 :
5337 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4;
5338 [ # # ]: 0 : if (!(item_flags & layer))
5339 : 0 : return rte_flow_error_set(error, EINVAL,
5340 : : RTE_FLOW_ERROR_TYPE_ACTION,
5341 : : NULL,
5342 : : "no ipv4 item in pattern");
5343 : : }
5344 : : return ret;
5345 : : }
5346 : :
5347 : : /**
5348 : : * Validate the modify-header IPv6 address actions.
5349 : : *
5350 : : * @param[in] action_flags
5351 : : * Holds the actions detected until now.
5352 : : * @param[in] action
5353 : : * Pointer to the modify action.
5354 : : * @param[in] item_flags
5355 : : * Holds the items detected.
5356 : : * @param[out] error
5357 : : * Pointer to error structure.
5358 : : *
5359 : : * @return
5360 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5361 : : */
5362 : : static int
5363 : 0 : flow_dv_validate_action_modify_ipv6(const uint64_t action_flags,
5364 : : const struct rte_flow_action *action,
5365 : : const uint64_t item_flags,
5366 : : struct rte_flow_error *error)
5367 : : {
5368 : : int ret = 0;
5369 : : uint64_t layer;
5370 : :
5371 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5372 [ # # ]: 0 : if (!ret) {
5373 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5374 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L3_IPV6 :
5375 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6;
5376 [ # # ]: 0 : if (!(item_flags & layer))
5377 : 0 : return rte_flow_error_set(error, EINVAL,
5378 : : RTE_FLOW_ERROR_TYPE_ACTION,
5379 : : NULL,
5380 : : "no ipv6 item in pattern");
5381 : : }
5382 : : return ret;
5383 : : }
5384 : :
5385 : : /**
5386 : : * Validate the modify-header TP actions.
5387 : : *
5388 : : * @param[in] action_flags
5389 : : * Holds the actions detected until now.
5390 : : * @param[in] action
5391 : : * Pointer to the modify action.
5392 : : * @param[in] item_flags
5393 : : * Holds the items detected.
5394 : : * @param[out] error
5395 : : * Pointer to error structure.
5396 : : *
5397 : : * @return
5398 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5399 : : */
5400 : : static int
5401 : 0 : flow_dv_validate_action_modify_tp(const uint64_t action_flags,
5402 : : const struct rte_flow_action *action,
5403 : : const uint64_t item_flags,
5404 : : struct rte_flow_error *error)
5405 : : {
5406 : : int ret = 0;
5407 : : uint64_t layer;
5408 : :
5409 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5410 [ # # ]: 0 : if (!ret) {
5411 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5412 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L4 :
5413 : : MLX5_FLOW_LAYER_OUTER_L4;
5414 [ # # ]: 0 : if (!(item_flags & layer))
5415 : 0 : return rte_flow_error_set(error, EINVAL,
5416 : : RTE_FLOW_ERROR_TYPE_ACTION,
5417 : : NULL, "no transport layer "
5418 : : "in pattern");
5419 : : }
5420 : : return ret;
5421 : : }
5422 : :
5423 : : /**
5424 : : * Validate the modify-header actions of increment/decrement
5425 : : * TCP Sequence-number.
5426 : : *
5427 : : * @param[in] action_flags
5428 : : * Holds the actions detected until now.
5429 : : * @param[in] action
5430 : : * Pointer to the modify action.
5431 : : * @param[in] item_flags
5432 : : * Holds the items detected.
5433 : : * @param[out] error
5434 : : * Pointer to error structure.
5435 : : *
5436 : : * @return
5437 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5438 : : */
5439 : : static int
5440 : 0 : flow_dv_validate_action_modify_tcp_seq(const uint64_t action_flags,
5441 : : const struct rte_flow_action *action,
5442 : : const uint64_t item_flags,
5443 : : struct rte_flow_error *error)
5444 : : {
5445 : : int ret = 0;
5446 : : uint64_t layer;
5447 : :
5448 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5449 [ # # ]: 0 : if (!ret) {
5450 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5451 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L4_TCP :
5452 : : MLX5_FLOW_LAYER_OUTER_L4_TCP;
5453 [ # # ]: 0 : if (!(item_flags & layer))
5454 : 0 : return rte_flow_error_set(error, EINVAL,
5455 : : RTE_FLOW_ERROR_TYPE_ACTION,
5456 : : NULL, "no TCP item in"
5457 : : " pattern");
5458 [ # # ]: 0 : if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ &&
5459 [ # # # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_DEC_TCP_SEQ)) ||
5460 : 0 : (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ &&
5461 [ # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_INC_TCP_SEQ)))
5462 : 0 : return rte_flow_error_set(error, EINVAL,
5463 : : RTE_FLOW_ERROR_TYPE_ACTION,
5464 : : NULL,
5465 : : "cannot decrease and increase"
5466 : : " TCP sequence number"
5467 : : " at the same time");
5468 : : }
5469 : : return ret;
5470 : : }
5471 : :
5472 : : /**
5473 : : * Validate the modify-header actions of increment/decrement
5474 : : * TCP Acknowledgment number.
5475 : : *
5476 : : * @param[in] action_flags
5477 : : * Holds the actions detected until now.
5478 : : * @param[in] action
5479 : : * Pointer to the modify action.
5480 : : * @param[in] item_flags
5481 : : * Holds the items detected.
5482 : : * @param[out] error
5483 : : * Pointer to error structure.
5484 : : *
5485 : : * @return
5486 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5487 : : */
5488 : : static int
5489 : 0 : flow_dv_validate_action_modify_tcp_ack(const uint64_t action_flags,
5490 : : const struct rte_flow_action *action,
5491 : : const uint64_t item_flags,
5492 : : struct rte_flow_error *error)
5493 : : {
5494 : : int ret = 0;
5495 : : uint64_t layer;
5496 : :
5497 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5498 [ # # ]: 0 : if (!ret) {
5499 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5500 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L4_TCP :
5501 : : MLX5_FLOW_LAYER_OUTER_L4_TCP;
5502 [ # # ]: 0 : if (!(item_flags & layer))
5503 : 0 : return rte_flow_error_set(error, EINVAL,
5504 : : RTE_FLOW_ERROR_TYPE_ACTION,
5505 : : NULL, "no TCP item in"
5506 : : " pattern");
5507 [ # # ]: 0 : if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_ACK &&
5508 [ # # # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_DEC_TCP_ACK)) ||
5509 : 0 : (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK &&
5510 [ # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_INC_TCP_ACK)))
5511 : 0 : return rte_flow_error_set(error, EINVAL,
5512 : : RTE_FLOW_ERROR_TYPE_ACTION,
5513 : : NULL,
5514 : : "cannot decrease and increase"
5515 : : " TCP acknowledgment number"
5516 : : " at the same time");
5517 : : }
5518 : : return ret;
5519 : : }
5520 : :
5521 : : /**
5522 : : * Validate the modify-header TTL actions.
5523 : : *
5524 : : * @param[in] action_flags
5525 : : * Holds the actions detected until now.
5526 : : * @param[in] action
5527 : : * Pointer to the modify action.
5528 : : * @param[in] item_flags
5529 : : * Holds the items detected.
5530 : : * @param[out] error
5531 : : * Pointer to error structure.
5532 : : *
5533 : : * @return
5534 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5535 : : */
5536 : : static int
5537 : 0 : flow_dv_validate_action_modify_ttl(const uint64_t action_flags,
5538 : : const struct rte_flow_action *action,
5539 : : const uint64_t item_flags,
5540 : : struct rte_flow_error *error)
5541 : : {
5542 : : int ret = 0;
5543 : : uint64_t layer;
5544 : :
5545 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5546 [ # # ]: 0 : if (!ret) {
5547 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5548 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L3 :
5549 : : MLX5_FLOW_LAYER_OUTER_L3;
5550 [ # # ]: 0 : if (!(item_flags & layer))
5551 : 0 : return rte_flow_error_set(error, EINVAL,
5552 : : RTE_FLOW_ERROR_TYPE_ACTION,
5553 : : NULL,
5554 : : "no IP protocol in pattern");
5555 : : }
5556 : : return ret;
5557 : : }
5558 : :
5559 : : /**
5560 : : * Validate the generic modify field actions.
5561 : : * @param[in] dev
5562 : : * Pointer to the rte_eth_dev structure.
5563 : : * @param[in] action_flags
5564 : : * Holds the actions detected until now.
5565 : : * @param[in] action
5566 : : * Pointer to the modify action.
5567 : : * @param[in] attr
5568 : : * Pointer to the flow attributes.
5569 : : * @param root
5570 : : * Whether action is on root table.
5571 : : * @param[out] error
5572 : : * Pointer to error structure.
5573 : : *
5574 : : * @return
5575 : : * Number of header fields to modify (0 or more) on success,
5576 : : * a negative errno value otherwise and rte_errno is set.
5577 : : */
5578 : : static int
5579 : 0 : flow_dv_validate_action_modify_field(struct rte_eth_dev *dev,
5580 : : const uint64_t action_flags,
5581 : : const struct rte_flow_action *action,
5582 : : const struct rte_flow_attr *attr,
5583 : : bool root,
5584 : : struct rte_flow_error *error)
5585 : : {
5586 : : int ret = 0;
5587 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5588 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
5589 : 0 : struct mlx5_hca_attr *hca_attr = &priv->sh->cdev->config.hca_attr;
5590 : 0 : const struct rte_flow_action_modify_field *conf = action->conf;
5591 : 0 : const struct rte_flow_field_data *src_data = &conf->src;
5592 : 0 : const struct rte_flow_field_data *dst_data = &conf->dst;
5593 : 0 : uint32_t dst_width, src_width, width = conf->width;
5594 : :
5595 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5596 [ # # ]: 0 : if (ret)
5597 : : return ret;
5598 [ # # ]: 0 : if (src_data->field == RTE_FLOW_FIELD_FLEX_ITEM ||
5599 [ # # ]: 0 : dst_data->field == RTE_FLOW_FIELD_FLEX_ITEM)
5600 : 0 : return rte_flow_error_set(error, ENOTSUP,
5601 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5602 : : "flex item fields modification"
5603 : : " is not supported");
5604 : 0 : dst_width = mlx5_flow_item_field_width(dev, dst_data->field,
5605 : : -1, attr, error);
5606 : 0 : src_width = mlx5_flow_item_field_width(dev, src_data->field,
5607 : : dst_width, attr, error);
5608 [ # # ]: 0 : if (width == 0)
5609 : 0 : return rte_flow_error_set(error, EINVAL,
5610 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5611 : : "no bits are requested to be modified");
5612 [ # # ]: 0 : else if (width > dst_width || width > src_width)
5613 : 0 : return rte_flow_error_set(error, EINVAL,
5614 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5615 : : "cannot modify more bits than"
5616 : : " the width of a field");
5617 [ # # ]: 0 : if (dst_data->field != RTE_FLOW_FIELD_VALUE &&
5618 : : dst_data->field != RTE_FLOW_FIELD_POINTER) {
5619 [ # # ]: 0 : if (dst_data->offset + width > dst_width)
5620 : 0 : return rte_flow_error_set(error, EINVAL,
5621 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5622 : : "destination offset is too big");
5623 : 0 : ret = flow_validate_modify_field_level(dst_data, error);
5624 [ # # ]: 0 : if (ret)
5625 : : return ret;
5626 [ # # ]: 0 : if (dst_data->tag_index &&
5627 [ # # ]: 0 : !flow_modify_field_support_tag_array(dst_data->field))
5628 : 0 : return rte_flow_error_set(error, EINVAL,
5629 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5630 : : "destination tag index is not supported");
5631 [ # # ]: 0 : if (dst_data->class_id)
5632 : 0 : return rte_flow_error_set(error, EINVAL,
5633 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5634 : : "destination class ID is not supported");
5635 : : }
5636 [ # # ]: 0 : if (src_data->field != RTE_FLOW_FIELD_VALUE &&
5637 : : src_data->field != RTE_FLOW_FIELD_POINTER) {
5638 [ # # ]: 0 : if (root)
5639 : 0 : return rte_flow_error_set(error, ENOTSUP,
5640 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5641 : : "modify field action is not"
5642 : : " supported for group 0");
5643 [ # # ]: 0 : if (src_data->offset + width > src_width)
5644 : 0 : return rte_flow_error_set(error, EINVAL,
5645 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5646 : : "source offset is too big");
5647 : 0 : ret = flow_validate_modify_field_level(src_data, error);
5648 [ # # ]: 0 : if (ret)
5649 : : return ret;
5650 [ # # ]: 0 : if (src_data->tag_index &&
5651 [ # # ]: 0 : !flow_modify_field_support_tag_array(src_data->field))
5652 : 0 : return rte_flow_error_set(error, EINVAL,
5653 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5654 : : "source tag index is not supported");
5655 [ # # ]: 0 : if (src_data->class_id)
5656 : 0 : return rte_flow_error_set(error, EINVAL,
5657 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5658 : : "source class ID is not supported");
5659 : : }
5660 [ # # ]: 0 : if ((dst_data->field == src_data->field) &&
5661 [ # # ]: 0 : (dst_data->level == src_data->level))
5662 : 0 : return rte_flow_error_set(error, EINVAL,
5663 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5664 : : "source and destination fields"
5665 : : " cannot be the same");
5666 : 0 : if (dst_data->field == RTE_FLOW_FIELD_VALUE ||
5667 [ # # ]: 0 : dst_data->field == RTE_FLOW_FIELD_POINTER ||
5668 : : dst_data->field == RTE_FLOW_FIELD_MARK)
5669 : 0 : return rte_flow_error_set(error, EINVAL,
5670 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5671 : : "mark, immediate value or a pointer to it"
5672 : : " cannot be used as a destination");
5673 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_START ||
5674 : : src_data->field == RTE_FLOW_FIELD_START)
5675 : 0 : return rte_flow_error_set(error, ENOTSUP,
5676 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5677 : : "modifications of an arbitrary"
5678 : : " place in a packet is not supported");
5679 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_VLAN_TYPE ||
5680 : : src_data->field == RTE_FLOW_FIELD_VLAN_TYPE)
5681 : 0 : return rte_flow_error_set(error, ENOTSUP,
5682 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5683 : : "modifications of the 802.1Q Tag"
5684 : : " Identifier is not supported");
5685 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_VXLAN_VNI ||
5686 : : src_data->field == RTE_FLOW_FIELD_VXLAN_VNI)
5687 : 0 : return rte_flow_error_set(error, ENOTSUP,
5688 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5689 : : "modifications of the VXLAN Network"
5690 : : " Identifier is not supported");
5691 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_GENEVE_VNI ||
5692 : : src_data->field == RTE_FLOW_FIELD_GENEVE_VNI)
5693 : 0 : return rte_flow_error_set(error, ENOTSUP,
5694 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5695 : : "modifications of the GENEVE Network"
5696 : : " Identifier is not supported");
5697 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_GENEVE_OPT_TYPE ||
5698 : : src_data->field == RTE_FLOW_FIELD_GENEVE_OPT_TYPE)
5699 : 0 : return rte_flow_error_set(error, ENOTSUP,
5700 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5701 : : "modifications of the GENEVE option type is not supported");
5702 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_GENEVE_OPT_CLASS ||
5703 : : src_data->field == RTE_FLOW_FIELD_GENEVE_OPT_CLASS)
5704 : 0 : return rte_flow_error_set(error, ENOTSUP,
5705 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5706 : : "modifications of the GENEVE option class is not supported");
5707 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_GENEVE_OPT_DATA ||
5708 : : src_data->field == RTE_FLOW_FIELD_GENEVE_OPT_DATA)
5709 : 0 : return rte_flow_error_set(error, ENOTSUP,
5710 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5711 : : "modifications of the GENEVE option data is not supported");
5712 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_MPLS ||
5713 : : src_data->field == RTE_FLOW_FIELD_MPLS)
5714 : 0 : return rte_flow_error_set(error, ENOTSUP,
5715 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5716 : : "modifications of the MPLS header "
5717 : : "is not supported");
5718 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_RANDOM ||
5719 : : src_data->field == RTE_FLOW_FIELD_RANDOM)
5720 : 0 : return rte_flow_error_set(error, ENOTSUP,
5721 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5722 : : "modifications of random value is not supported");
5723 [ # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_MARK ||
5724 : : src_data->field == RTE_FLOW_FIELD_MARK)
5725 [ # # # # ]: 0 : if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
5726 : 0 : !mlx5_flow_ext_mreg_supported(dev))
5727 : 0 : return rte_flow_error_set(error, ENOTSUP,
5728 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5729 : : "cannot modify mark in legacy mode"
5730 : : " or without extensive registers");
5731 [ # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_META ||
5732 [ # # ]: 0 : src_data->field == RTE_FLOW_FIELD_META) {
5733 [ # # # # ]: 0 : if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
5734 : 0 : !mlx5_flow_ext_mreg_supported(dev))
5735 : 0 : return rte_flow_error_set(error, ENOTSUP,
5736 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5737 : : "cannot modify meta without"
5738 : : " extensive registers support");
5739 : 0 : ret = flow_dv_get_metadata_reg(dev, attr, error);
5740 [ # # ]: 0 : if (ret < 0 || ret == REG_NON)
5741 : 0 : return rte_flow_error_set(error, ENOTSUP,
5742 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5743 : : "cannot modify meta without"
5744 : : " extensive registers available");
5745 : : }
5746 [ # # ]: 0 : if (conf->operation == RTE_FLOW_MODIFY_SUB)
5747 : 0 : return rte_flow_error_set(error, ENOTSUP,
5748 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5749 : : "sub operations are not supported");
5750 [ # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_IPV4_ECN ||
5751 [ # # # # ]: 0 : src_data->field == RTE_FLOW_FIELD_IPV4_ECN ||
5752 [ # # ]: 0 : dst_data->field == RTE_FLOW_FIELD_IPV6_ECN ||
5753 : : src_data->field == RTE_FLOW_FIELD_IPV6_ECN)
5754 [ # # # # ]: 0 : if (!hca_attr->modify_outer_ip_ecn && root)
5755 : 0 : return rte_flow_error_set(error, ENOTSUP,
5756 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5757 : : "modifications of the ECN for current firmware is not supported");
5758 : 0 : return (width / 32) + !!(width % 32);
5759 : : }
5760 : :
5761 : : /**
5762 : : * Validate jump action.
5763 : : *
5764 : : * @param[in] action
5765 : : * Pointer to the jump action.
5766 : : * @param[in] action_flags
5767 : : * Holds the actions detected until now.
5768 : : * @param[in] attributes
5769 : : * Pointer to flow attributes
5770 : : * @param[in] external
5771 : : * Action belongs to flow rule created by request external to PMD.
5772 : : * @param[out] error
5773 : : * Pointer to error structure.
5774 : : *
5775 : : * @return
5776 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5777 : : */
5778 : : static int
5779 : 0 : flow_dv_validate_action_jump(struct rte_eth_dev *dev,
5780 : : const struct mlx5_flow_tunnel *tunnel,
5781 : : const struct rte_flow_action *action,
5782 : : uint64_t action_flags,
5783 : : const struct rte_flow_attr *attributes,
5784 : : bool external, struct rte_flow_error *error)
5785 : : {
5786 : 0 : uint32_t target_group, table = 0;
5787 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5788 : : int ret = 0;
5789 : 0 : struct flow_grp_info grp_info = {
5790 : : .external = !!external,
5791 : 0 : .transfer = !!attributes->transfer,
5792 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
5793 : : .std_tbl_fix = 0
5794 : : };
5795 [ # # ]: 0 : if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
5796 : : MLX5_FLOW_FATE_ESWITCH_ACTIONS))
5797 : 0 : return rte_flow_error_set(error, EINVAL,
5798 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5799 : : "can't have 2 fate actions in"
5800 : : " same flow");
5801 [ # # ]: 0 : if (!action->conf)
5802 : 0 : return rte_flow_error_set(error, EINVAL,
5803 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5804 : : NULL, "action configuration not set");
5805 : 0 : target_group =
5806 : : ((const struct rte_flow_action_jump *)action->conf)->group;
5807 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel, target_group, &table,
5808 : : &grp_info, error);
5809 [ # # ]: 0 : if (ret)
5810 : : return ret;
5811 [ # # ]: 0 : if (table == 0)
5812 : 0 : return rte_flow_error_set(error, EINVAL,
5813 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5814 : : NULL, "root table shouldn't be destination");
5815 : : return 0;
5816 : : }
5817 : :
5818 : : /*
5819 : : * Validate action PORT_ID / REPRESENTED_PORT.
5820 : : *
5821 : : * @param[in] dev
5822 : : * Pointer to rte_eth_dev structure.
5823 : : * @param[in] action_flags
5824 : : * Bit-fields that holds the actions detected until now.
5825 : : * @param[in] action
5826 : : * PORT_ID / REPRESENTED_PORT action structure.
5827 : : * @param[in] attr
5828 : : * Attributes of flow that includes this action.
5829 : : * @param[out] error
5830 : : * Pointer to error structure.
5831 : : *
5832 : : * @return
5833 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5834 : : */
5835 : : static int
5836 : 0 : flow_dv_validate_action_port_id(struct rte_eth_dev *dev,
5837 : : uint64_t action_flags,
5838 : : const struct rte_flow_action *action,
5839 : : const struct rte_flow_attr *attr,
5840 : : struct rte_flow_error *error)
5841 : : {
5842 : : const struct rte_flow_action_port_id *port_id;
5843 : : const struct rte_flow_action_ethdev *ethdev;
5844 : : struct mlx5_priv *act_priv;
5845 : : struct mlx5_priv *dev_priv;
5846 : : uint16_t port;
5847 : :
5848 [ # # ]: 0 : if (!attr->transfer)
5849 : 0 : return rte_flow_error_set(error, ENOTSUP,
5850 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5851 : : NULL,
5852 : : "port action is valid in transfer"
5853 : : " mode only");
5854 [ # # # # ]: 0 : if (!action || !action->conf)
5855 : 0 : return rte_flow_error_set(error, ENOTSUP,
5856 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5857 : : NULL,
5858 : : "port action parameters must be"
5859 : : " specified");
5860 [ # # ]: 0 : if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
5861 : : MLX5_FLOW_FATE_ESWITCH_ACTIONS))
5862 : 0 : return rte_flow_error_set(error, EINVAL,
5863 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5864 : : "can have only one fate actions in"
5865 : : " a flow");
5866 : 0 : dev_priv = mlx5_dev_to_eswitch_info(dev);
5867 [ # # ]: 0 : if (!dev_priv)
5868 : 0 : return rte_flow_error_set(error, rte_errno,
5869 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5870 : : NULL,
5871 : : "failed to obtain E-Switch info");
5872 [ # # # ]: 0 : switch (action->type) {
5873 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
5874 : 0 : port_id = action->conf;
5875 [ # # ]: 0 : port = port_id->original ? dev->data->port_id : port_id->id;
5876 : : break;
5877 : 0 : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
5878 : 0 : ethdev = action->conf;
5879 : 0 : port = ethdev->port_id;
5880 : 0 : break;
5881 : 0 : default:
5882 : : MLX5_ASSERT(false);
5883 : 0 : return rte_flow_error_set
5884 : : (error, EINVAL,
5885 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5886 : : "unknown E-Switch action");
5887 : : }
5888 : 0 : act_priv = mlx5_port_to_eswitch_info(port, false);
5889 [ # # ]: 0 : if (!act_priv)
5890 : 0 : return rte_flow_error_set
5891 : : (error, rte_errno,
5892 : 0 : RTE_FLOW_ERROR_TYPE_ACTION_CONF, action->conf,
5893 : : "failed to obtain E-Switch port id for port");
5894 [ # # ]: 0 : if (act_priv->domain_id != dev_priv->domain_id)
5895 : 0 : return rte_flow_error_set
5896 : : (error, EINVAL,
5897 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5898 : : "port does not belong to"
5899 : : " E-Switch being configured");
5900 : : return 0;
5901 : : }
5902 : :
5903 : : /**
5904 : : * Get the maximum number of modify header actions.
5905 : : *
5906 : : * @param dev
5907 : : * Pointer to rte_eth_dev structure.
5908 : : * @param root
5909 : : * Whether action is on root table.
5910 : : *
5911 : : * @return
5912 : : * Max number of modify header actions device can support.
5913 : : */
5914 : : static inline unsigned int
5915 : : flow_dv_modify_hdr_action_max(struct rte_eth_dev *dev __rte_unused,
5916 : : bool root)
5917 : : {
5918 : : /*
5919 : : * There's no way to directly query the max capacity from FW.
5920 : : * The maximal value on root table should be assumed to be supported.
5921 : : */
5922 [ # # ]: 0 : if (!root)
5923 : : return MLX5_MAX_MODIFY_NUM;
5924 : : else
5925 : 0 : return MLX5_ROOT_TBL_MODIFY_NUM;
5926 : : }
5927 : :
5928 : : /**
5929 : : * Validate the meter action.
5930 : : *
5931 : : * @param[in] dev
5932 : : * Pointer to rte_eth_dev structure.
5933 : : * @param[in] action_flags
5934 : : * Bit-fields that holds the actions detected until now.
5935 : : * @param[in] item_flags
5936 : : * Holds the items detected.
5937 : : * @param[in] action
5938 : : * Pointer to the meter action.
5939 : : * @param[in] attr
5940 : : * Attributes of flow that includes this action.
5941 : : * @param[in] port_id_item
5942 : : * Pointer to item indicating port id.
5943 : : * @param[out] error
5944 : : * Pointer to error structure.
5945 : : *
5946 : : * @return
5947 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5948 : : */
5949 : : static int
5950 : 0 : mlx5_flow_validate_action_meter(struct rte_eth_dev *dev,
5951 : : uint64_t action_flags, uint64_t item_flags,
5952 : : const struct rte_flow_action *action,
5953 : : const struct rte_flow_attr *attr,
5954 : : const struct rte_flow_item *port_id_item,
5955 : : bool *def_policy,
5956 : : struct rte_flow_error *error)
5957 : : {
5958 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5959 : 0 : const struct rte_flow_action_meter *am = action->conf;
5960 : : struct mlx5_flow_meter_info *fm;
5961 : : struct mlx5_flow_meter_policy *mtr_policy;
5962 : 0 : struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
5963 : 0 : uint16_t flow_src_port = priv->representor_id;
5964 : 0 : bool all_ports = false;
5965 : :
5966 [ # # ]: 0 : if (!am)
5967 : 0 : return rte_flow_error_set(error, EINVAL,
5968 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5969 : : "meter action conf is NULL");
5970 : :
5971 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_METER)
5972 : 0 : return rte_flow_error_set(error, ENOTSUP,
5973 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5974 : : "meter chaining not support");
5975 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_JUMP)
5976 : 0 : return rte_flow_error_set(error, ENOTSUP,
5977 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5978 : : "meter with jump not support");
5979 [ # # ]: 0 : if (!priv->mtr_en)
5980 : 0 : return rte_flow_error_set(error, ENOTSUP,
5981 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5982 : : NULL,
5983 : : "meter action not supported");
5984 : 0 : fm = mlx5_flow_meter_find(priv, am->mtr_id, NULL);
5985 [ # # ]: 0 : if (!fm)
5986 : 0 : return rte_flow_error_set(error, EINVAL,
5987 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5988 : : "Meter not found");
5989 : : /* aso meter can always be shared by different domains */
5990 [ # # # # ]: 0 : if (fm->ref_cnt && !priv->sh->meter_aso_en &&
5991 [ # # ]: 0 : !(fm->transfer == attr->transfer ||
5992 [ # # # # ]: 0 : (!fm->ingress && !attr->ingress && attr->egress) ||
5993 [ # # # # ]: 0 : (!fm->egress && !attr->egress && attr->ingress)))
5994 : 0 : return rte_flow_error_set(error, EINVAL,
5995 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5996 : : "Flow attributes domain are either invalid "
5997 : : "or have a domain conflict with current "
5998 : : "meter attributes");
5999 [ # # ]: 0 : if (fm->def_policy) {
6000 [ # # ]: 0 : if (!((attr->transfer &&
6001 [ # # ]: 0 : mtrmng->def_policy[MLX5_MTR_DOMAIN_TRANSFER]) ||
6002 [ # # ]: 0 : (attr->egress &&
6003 [ # # ]: 0 : mtrmng->def_policy[MLX5_MTR_DOMAIN_EGRESS]) ||
6004 [ # # ]: 0 : (attr->ingress &&
6005 [ # # ]: 0 : mtrmng->def_policy[MLX5_MTR_DOMAIN_INGRESS])))
6006 : 0 : return rte_flow_error_set(error, EINVAL,
6007 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6008 : : "Flow attributes domain "
6009 : : "have a conflict with current "
6010 : : "meter domain attributes");
6011 : 0 : *def_policy = true;
6012 : : } else {
6013 : 0 : mtr_policy = mlx5_flow_meter_policy_find(dev,
6014 : : fm->policy_id, NULL);
6015 [ # # ]: 0 : if (!mtr_policy)
6016 : 0 : return rte_flow_error_set(error, EINVAL,
6017 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6018 : : "Invalid policy id for meter ");
6019 [ # # # # ]: 0 : if (!((attr->transfer && mtr_policy->transfer) ||
6020 [ # # # # ]: 0 : (attr->egress && mtr_policy->egress) ||
6021 [ # # # # ]: 0 : (attr->ingress && mtr_policy->ingress)))
6022 : 0 : return rte_flow_error_set(error, EINVAL,
6023 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6024 : : "Flow attributes domain "
6025 : : "have a conflict with current "
6026 : : "meter domain attributes");
6027 [ # # ]: 0 : if (port_id_item) {
6028 [ # # ]: 0 : if (mlx5_flow_get_item_vport_id(dev, port_id_item, &flow_src_port,
6029 : : &all_ports, error))
6030 : 0 : return -rte_errno;
6031 : : }
6032 [ # # ]: 0 : if (attr->transfer) {
6033 : : /* When flow matching all src ports, meter should not have drop count. */
6034 [ # # # # : 0 : if (all_ports && (fm->drop_cnt || mtr_policy->hierarchy_match_port))
# # ]
6035 : 0 : return rte_flow_error_set(error, EINVAL,
6036 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
6037 : : "Meter drop count or "
6038 : : "modify_field/set_tag in meter hierarchy "
6039 : : "not supported when matching all ports.");
6040 [ # # ]: 0 : } else if (mtr_policy->is_rss) {
6041 : : struct mlx5_flow_meter_policy *fp;
6042 : : struct mlx5_meter_policy_action_container *acg;
6043 : : struct mlx5_meter_policy_action_container *acy;
6044 : : const struct rte_flow_action *rss_act;
6045 : : int ret;
6046 : :
6047 : 0 : fp = mlx5_flow_meter_hierarchy_get_final_policy(dev,
6048 : : mtr_policy);
6049 [ # # ]: 0 : if (fp == NULL)
6050 : 0 : return rte_flow_error_set(error, EINVAL,
6051 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6052 : : "Unable to get the final "
6053 : : "policy in the hierarchy");
6054 : : acg = &fp->act_cnt[RTE_COLOR_GREEN];
6055 : : acy = &fp->act_cnt[RTE_COLOR_YELLOW];
6056 : : MLX5_ASSERT(acg->fate_action ==
6057 : : MLX5_FLOW_FATE_SHARED_RSS ||
6058 : : acy->fate_action ==
6059 : : MLX5_FLOW_FATE_SHARED_RSS);
6060 [ # # ]: 0 : if (acg->fate_action == MLX5_FLOW_FATE_SHARED_RSS)
6061 : 0 : rss_act = acg->rss;
6062 : : else
6063 : 0 : rss_act = acy->rss;
6064 : 0 : ret = mlx5_flow_validate_action_rss(rss_act,
6065 : : action_flags, dev, attr,
6066 : : item_flags, error);
6067 [ # # ]: 0 : if (ret)
6068 : : return ret;
6069 : : }
6070 : 0 : *def_policy = false;
6071 : : }
6072 : : return 0;
6073 : : }
6074 : :
6075 : : /**
6076 : : * Validate the age action.
6077 : : *
6078 : : * @param[in] action_flags
6079 : : * Holds the actions detected until now.
6080 : : * @param[in] action
6081 : : * Pointer to the age action.
6082 : : * @param[in] dev
6083 : : * Pointer to the Ethernet device structure.
6084 : : * @param[out] error
6085 : : * Pointer to error structure.
6086 : : *
6087 : : * @return
6088 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
6089 : : */
6090 : : static int
6091 : 0 : flow_dv_validate_action_age(uint64_t action_flags,
6092 : : const struct rte_flow_action *action,
6093 : : struct rte_eth_dev *dev,
6094 : : struct rte_flow_error *error)
6095 : : {
6096 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6097 : 0 : const struct rte_flow_action_age *age = action->conf;
6098 : :
6099 [ # # ]: 0 : if (!priv->sh->cdev->config.devx ||
6100 [ # # # # ]: 0 : (priv->sh->sws_cmng.counter_fallback && !priv->sh->aso_age_mng))
6101 : 0 : return rte_flow_error_set(error, ENOTSUP,
6102 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6103 : : NULL,
6104 : : "age action not supported");
6105 [ # # ]: 0 : if (!(action->conf))
6106 : 0 : return rte_flow_error_set(error, EINVAL,
6107 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6108 : : "configuration cannot be null");
6109 [ # # ]: 0 : if (!(age->timeout))
6110 : 0 : return rte_flow_error_set(error, EINVAL,
6111 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6112 : : "invalid timeout value 0");
6113 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_AGE)
6114 : 0 : return rte_flow_error_set(error, EINVAL,
6115 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6116 : : "duplicate age actions set");
6117 : : return 0;
6118 : : }
6119 : :
6120 : : /**
6121 : : * Validate the modify-header IPv4 DSCP actions.
6122 : : *
6123 : : * @param[in] action_flags
6124 : : * Holds the actions detected until now.
6125 : : * @param[in] action
6126 : : * Pointer to the modify action.
6127 : : * @param[in] item_flags
6128 : : * Holds the items detected.
6129 : : * @param[out] error
6130 : : * Pointer to error structure.
6131 : : *
6132 : : * @return
6133 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
6134 : : */
6135 : : static int
6136 : 0 : flow_dv_validate_action_modify_ipv4_dscp(const uint64_t action_flags,
6137 : : const struct rte_flow_action *action,
6138 : : const uint64_t item_flags,
6139 : : struct rte_flow_error *error)
6140 : : {
6141 : : int ret = 0;
6142 : :
6143 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
6144 [ # # ]: 0 : if (!ret) {
6145 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV4))
6146 : 0 : return rte_flow_error_set(error, EINVAL,
6147 : : RTE_FLOW_ERROR_TYPE_ACTION,
6148 : : NULL,
6149 : : "no ipv4 item in pattern");
6150 : : }
6151 : : return ret;
6152 : : }
6153 : :
6154 : : /**
6155 : : * Validate the modify-header IPv6 DSCP actions.
6156 : : *
6157 : : * @param[in] action_flags
6158 : : * Holds the actions detected until now.
6159 : : * @param[in] action
6160 : : * Pointer to the modify action.
6161 : : * @param[in] item_flags
6162 : : * Holds the items detected.
6163 : : * @param[out] error
6164 : : * Pointer to error structure.
6165 : : *
6166 : : * @return
6167 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
6168 : : */
6169 : : static int
6170 : 0 : flow_dv_validate_action_modify_ipv6_dscp(const uint64_t action_flags,
6171 : : const struct rte_flow_action *action,
6172 : : const uint64_t item_flags,
6173 : : struct rte_flow_error *error)
6174 : : {
6175 : : int ret = 0;
6176 : :
6177 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
6178 [ # # ]: 0 : if (!ret) {
6179 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV6))
6180 : 0 : return rte_flow_error_set(error, EINVAL,
6181 : : RTE_FLOW_ERROR_TYPE_ACTION,
6182 : : NULL,
6183 : : "no ipv6 item in pattern");
6184 : : }
6185 : : return ret;
6186 : : }
6187 : :
6188 : : int
6189 : 0 : flow_modify_match_cb(void *tool_ctx __rte_unused,
6190 : : struct mlx5_list_entry *entry, void *cb_ctx)
6191 : : {
6192 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
6193 : 0 : struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
6194 : : struct mlx5_flow_dv_modify_hdr_resource *resource =
6195 : : container_of(entry, typeof(*resource), entry);
6196 : : uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type);
6197 : :
6198 : 0 : key_len += ref->actions_num * sizeof(ref->actions[0]);
6199 [ # # ]: 0 : return ref->actions_num != resource->actions_num ||
6200 [ # # ]: 0 : memcmp(&ref->ft_type, &resource->ft_type, key_len);
6201 : : }
6202 : :
6203 : : static struct mlx5_indexed_pool *
6204 : 0 : flow_dv_modify_ipool_get(struct mlx5_dev_ctx_shared *sh, uint8_t index)
6205 : : {
6206 : 0 : struct mlx5_indexed_pool *ipool = rte_atomic_load_explicit
6207 : : (&sh->mdh_ipools[index], rte_memory_order_seq_cst);
6208 : :
6209 [ # # ]: 0 : if (!ipool) {
6210 : : struct mlx5_indexed_pool *expected = NULL;
6211 : 0 : struct mlx5_indexed_pool_config cfg =
6212 : : (struct mlx5_indexed_pool_config) {
6213 : 0 : .size = sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
6214 : 0 : (index + 1) *
6215 : : sizeof(struct mlx5_modification_cmd),
6216 : : .trunk_size = 64,
6217 : : .grow_trunk = 3,
6218 : : .grow_shift = 2,
6219 : : .need_lock = 1,
6220 : 0 : .release_mem_en = !!sh->config.reclaim_mode,
6221 : : .per_core_cache =
6222 [ # # ]: 0 : sh->config.reclaim_mode ? 0 : (1 << 16),
6223 : : .malloc = mlx5_malloc,
6224 : : .free = mlx5_free,
6225 : : .type = "mlx5_modify_action_resource",
6226 : : };
6227 : :
6228 : 0 : cfg.size = RTE_ALIGN(cfg.size, sizeof(ipool));
6229 : 0 : ipool = mlx5_ipool_create(&cfg);
6230 [ # # ]: 0 : if (!ipool)
6231 : 0 : return NULL;
6232 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(&sh->mdh_ipools[index],
6233 : : &expected, ipool,
6234 : : rte_memory_order_seq_cst,
6235 : : rte_memory_order_seq_cst)) {
6236 : 0 : mlx5_ipool_destroy(ipool);
6237 : 0 : ipool = rte_atomic_load_explicit(&sh->mdh_ipools[index],
6238 : : rte_memory_order_seq_cst);
6239 : : }
6240 : : }
6241 : : return ipool;
6242 : : }
6243 : :
6244 : : struct mlx5_list_entry *
6245 : 0 : flow_modify_create_cb(void *tool_ctx, void *cb_ctx)
6246 : : {
6247 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
6248 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
6249 : : struct mlx5dv_dr_domain *ns;
6250 : : struct mlx5_flow_dv_modify_hdr_resource *entry;
6251 : 0 : struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
6252 : 0 : struct mlx5_indexed_pool *ipool = flow_dv_modify_ipool_get(sh,
6253 : 0 : ref->actions_num - 1);
6254 : : int ret = 0;
6255 : 0 : uint32_t data_len = ref->actions_num * sizeof(ref->actions[0]);
6256 : : uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type);
6257 : : uint32_t idx;
6258 : :
6259 [ # # ]: 0 : if (unlikely(!ipool)) {
6260 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
6261 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6262 : : NULL, "cannot allocate modify ipool");
6263 : 0 : return NULL;
6264 : : }
6265 : 0 : entry = mlx5_ipool_zmalloc(ipool, &idx);
6266 [ # # ]: 0 : if (!entry) {
6267 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
6268 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6269 : : "cannot allocate resource memory");
6270 : 0 : return NULL;
6271 : : }
6272 : 0 : rte_memcpy(&entry->ft_type,
6273 : 0 : RTE_PTR_ADD(ref, offsetof(typeof(*ref), ft_type)),
6274 [ # # ]: 0 : key_len + data_len);
6275 [ # # ]: 0 : if (sh->config.dv_flow_en == 2) {
6276 : : #ifdef HAVE_MLX5_HWS_SUPPORT
6277 : 0 : struct mlx5dr_action_mh_pattern pattern = {
6278 : : .sz = data_len,
6279 : 0 : .data = (__be64 *)ref->actions
6280 : : };
6281 : 0 : entry->action = mlx5dr_action_create_modify_header(ctx->data2,
6282 : : 1,
6283 : 0 : &pattern, 0, ref->flags);
6284 [ # # ]: 0 : if (!entry->action)
6285 : : ret = -1;
6286 : : #else
6287 : : ret = -1;
6288 : : #endif
6289 : : } else {
6290 [ # # ]: 0 : if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
6291 : 0 : ns = sh->fdb_domain;
6292 [ # # ]: 0 : else if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
6293 : 0 : ns = sh->tx_domain;
6294 : : else
6295 : 0 : ns = sh->rx_domain;
6296 : 0 : ret = mlx5_flow_os_create_flow_action_modify_header
6297 : 0 : (sh->cdev->ctx, ns, entry,
6298 : : data_len, &entry->action);
6299 : : }
6300 : : if (ret) {
6301 : 0 : mlx5_ipool_free(sh->mdh_ipools[ref->actions_num - 1], idx);
6302 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
6303 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6304 : : NULL, "cannot create modification action");
6305 : 0 : return NULL;
6306 : : }
6307 : 0 : entry->idx = idx;
6308 : 0 : return &entry->entry;
6309 : : }
6310 : :
6311 : : struct mlx5_list_entry *
6312 : 0 : flow_modify_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
6313 : : void *cb_ctx)
6314 : : {
6315 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
6316 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
6317 : : struct mlx5_flow_dv_modify_hdr_resource *entry;
6318 : 0 : struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
6319 : 0 : uint32_t data_len = ref->actions_num * sizeof(ref->actions[0]);
6320 : : uint32_t idx;
6321 : :
6322 : 0 : entry = mlx5_ipool_malloc(sh->mdh_ipools[ref->actions_num - 1],
6323 : : &idx);
6324 [ # # ]: 0 : if (!entry) {
6325 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
6326 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6327 : : "cannot allocate resource memory");
6328 : 0 : return NULL;
6329 : : }
6330 : 0 : memcpy(entry, oentry, sizeof(*entry) + data_len);
6331 : 0 : entry->idx = idx;
6332 : 0 : return &entry->entry;
6333 : : }
6334 : :
6335 : : void
6336 : 0 : flow_modify_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
6337 : : {
6338 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
6339 : : struct mlx5_flow_dv_modify_hdr_resource *res =
6340 : : container_of(entry, typeof(*res), entry);
6341 : :
6342 : 0 : mlx5_ipool_free(sh->mdh_ipools[res->actions_num - 1], res->idx);
6343 : 0 : }
6344 : :
6345 : : /**
6346 : : * Validate the sample action.
6347 : : *
6348 : : * @param[in, out] action_flags
6349 : : * Holds the actions detected until now.
6350 : : * @param[in] action
6351 : : * Pointer to the sample action.
6352 : : * @param[in] dev
6353 : : * Pointer to the Ethernet device structure.
6354 : : * @param[in] attr
6355 : : * Attributes of flow that includes this action.
6356 : : * @param[in] item_flags
6357 : : * Holds the items detected.
6358 : : * @param[in] rss
6359 : : * Pointer to the RSS action.
6360 : : * @param[out] sample_rss
6361 : : * Pointer to the RSS action in sample action list.
6362 : : * @param[out] count
6363 : : * Pointer to the COUNT action in sample action list.
6364 : : * @param[out] fdb_mirror
6365 : : * Pointer to the FDB mirror flag.
6366 : : * @param root
6367 : : * Whether action is on root table.
6368 : : * @param[out] error
6369 : : * Pointer to error structure.
6370 : : *
6371 : : * @return
6372 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
6373 : : */
6374 : : static int
6375 : 0 : flow_dv_validate_action_sample(uint64_t *action_flags,
6376 : : uint64_t *sub_action_flags,
6377 : : const struct rte_flow_action *action,
6378 : : struct rte_eth_dev *dev,
6379 : : const struct rte_flow_attr *attr,
6380 : : uint64_t item_flags,
6381 : : const struct rte_flow_action_rss *rss,
6382 : : const struct rte_flow_action_rss **sample_rss,
6383 : : const struct rte_flow_action_count **count,
6384 : : int *fdb_mirror,
6385 : : uint16_t *sample_port_id,
6386 : : bool root,
6387 : : struct rte_flow_error *error)
6388 : : {
6389 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6390 : 0 : struct mlx5_sh_config *dev_conf = &priv->sh->config;
6391 : 0 : const struct rte_flow_action_sample *sample = action->conf;
6392 : : const struct rte_flow_action_port_id *port = NULL;
6393 : : const struct rte_flow_action *act;
6394 : : uint16_t queue_index = 0xFFFF;
6395 : 0 : int actions_n = 0;
6396 : : int ret;
6397 : :
6398 [ # # ]: 0 : if (!sample)
6399 : 0 : return rte_flow_error_set(error, EINVAL,
6400 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6401 : : "configuration cannot be NULL");
6402 [ # # ]: 0 : if (sample->ratio == 0)
6403 : 0 : return rte_flow_error_set(error, EINVAL,
6404 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6405 : : "ratio value starts from 1");
6406 [ # # ]: 0 : if (!priv->sh->cdev->config.devx ||
6407 [ # # ]: 0 : (sample->ratio > 0 && !priv->sampler_en))
6408 : 0 : return rte_flow_error_set(error, ENOTSUP,
6409 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6410 : : NULL,
6411 : : "sample action not supported");
6412 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_SAMPLE)
6413 : 0 : return rte_flow_error_set(error, EINVAL,
6414 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6415 : : "Multiple sample actions not "
6416 : : "supported");
6417 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_METER)
6418 : 0 : return rte_flow_error_set(error, EINVAL,
6419 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6420 : : "wrong action order, meter should "
6421 : : "be after sample action");
6422 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_JUMP)
6423 : 0 : return rte_flow_error_set(error, EINVAL,
6424 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6425 : : "wrong action order, jump should "
6426 : : "be after sample action");
6427 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_CT)
6428 : 0 : return rte_flow_error_set(error, EINVAL,
6429 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6430 : : "Sample after CT not supported");
6431 : 0 : act = sample->actions;
6432 [ # # ]: 0 : for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++) {
6433 [ # # ]: 0 : if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
6434 : 0 : return rte_flow_error_set(error, ENOTSUP,
6435 : : RTE_FLOW_ERROR_TYPE_ACTION,
6436 : : act, "too many actions");
6437 [ # # # # : 0 : switch (act->type) {
# # # # ]
6438 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
6439 : 0 : ret = mlx5_flow_validate_action_queue(act,
6440 : : *sub_action_flags,
6441 : : dev,
6442 : : attr, error);
6443 [ # # ]: 0 : if (ret < 0)
6444 : 0 : return ret;
6445 : 0 : queue_index = ((const struct rte_flow_action_queue *)
6446 : 0 : (act->conf))->index;
6447 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_QUEUE;
6448 : 0 : ++actions_n;
6449 : 0 : break;
6450 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
6451 : 0 : *sample_rss = act->conf;
6452 : 0 : ret = mlx5_flow_validate_action_rss(act,
6453 : : *sub_action_flags,
6454 : : dev, attr,
6455 : : item_flags,
6456 : : error);
6457 [ # # ]: 0 : if (ret < 0)
6458 : 0 : return ret;
6459 [ # # # # ]: 0 : if (rss && *sample_rss &&
6460 [ # # ]: 0 : ((*sample_rss)->level != rss->level ||
6461 [ # # ]: 0 : (*sample_rss)->types != rss->types))
6462 : 0 : return rte_flow_error_set(error, ENOTSUP,
6463 : : RTE_FLOW_ERROR_TYPE_ACTION,
6464 : : NULL,
6465 : : "Can't use the different RSS types "
6466 : : "or level in the same flow");
6467 [ # # # # ]: 0 : if (*sample_rss != NULL && (*sample_rss)->queue_num)
6468 : 0 : queue_index = (*sample_rss)->queue[0];
6469 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_RSS;
6470 : 0 : ++actions_n;
6471 : 0 : break;
6472 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
6473 : 0 : ret = flow_dv_validate_action_mark(dev, act,
6474 : : *sub_action_flags,
6475 : : attr, error);
6476 [ # # ]: 0 : if (ret < 0)
6477 : 0 : return ret;
6478 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY)
6479 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_MARK |
6480 : : MLX5_FLOW_ACTION_MARK_EXT;
6481 : : else
6482 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_MARK;
6483 : 0 : ++actions_n;
6484 : 0 : break;
6485 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
6486 : 0 : ret = flow_dv_validate_action_count
6487 : 0 : (dev, false, *action_flags | *sub_action_flags,
6488 : : root, error);
6489 [ # # ]: 0 : if (ret < 0)
6490 : 0 : return ret;
6491 : 0 : *count = act->conf;
6492 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_COUNT;
6493 : 0 : *action_flags |= MLX5_FLOW_ACTION_COUNT;
6494 : 0 : ++actions_n;
6495 : 0 : break;
6496 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
6497 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
6498 : 0 : ret = flow_dv_validate_action_port_id(dev,
6499 : : *sub_action_flags,
6500 : : act,
6501 : : attr,
6502 : : error);
6503 [ # # ]: 0 : if (ret)
6504 : 0 : return ret;
6505 [ # # ]: 0 : if (act->type == RTE_FLOW_ACTION_TYPE_PORT_ID) {
6506 : 0 : port = (const struct rte_flow_action_port_id *)
6507 : : act->conf;
6508 [ # # ]: 0 : *sample_port_id = port->original ?
6509 : 0 : dev->data->port_id : port->id;
6510 : : } else {
6511 : 0 : *sample_port_id = ((const struct rte_flow_action_ethdev *)
6512 : 0 : act->conf)->port_id;
6513 : : }
6514 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_PORT_ID;
6515 : 0 : ++actions_n;
6516 : 0 : break;
6517 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
6518 : 0 : ret = mlx5_flow_dv_validate_action_raw_encap_decap
6519 : 0 : (dev, NULL, act->conf, attr, sub_action_flags,
6520 : : &actions_n, action, item_flags, error);
6521 [ # # ]: 0 : if (ret < 0)
6522 : 0 : return ret;
6523 : 0 : ++actions_n;
6524 : 0 : break;
6525 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
6526 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
6527 : 0 : ret = mlx5_flow_dv_validate_action_l2_encap(dev,
6528 : : *sub_action_flags,
6529 : : act, attr,
6530 : : error);
6531 [ # # ]: 0 : if (ret < 0)
6532 : 0 : return ret;
6533 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_ENCAP;
6534 : 0 : ++actions_n;
6535 : 0 : break;
6536 : 0 : default:
6537 : 0 : return rte_flow_error_set(error, ENOTSUP,
6538 : : RTE_FLOW_ERROR_TYPE_ACTION,
6539 : : NULL,
6540 : : "Doesn't support optional "
6541 : : "action");
6542 : : }
6543 : : }
6544 [ # # ]: 0 : if (attr->ingress) {
6545 [ # # ]: 0 : if (!(*sub_action_flags & (MLX5_FLOW_ACTION_QUEUE |
6546 : : MLX5_FLOW_ACTION_RSS)))
6547 : 0 : return rte_flow_error_set(error, EINVAL,
6548 : : RTE_FLOW_ERROR_TYPE_ACTION,
6549 : : NULL,
6550 : : "Ingress must has a dest "
6551 : : "QUEUE for Sample");
6552 [ # # ]: 0 : } else if (attr->egress) {
6553 : 0 : return rte_flow_error_set(error, ENOTSUP,
6554 : : RTE_FLOW_ERROR_TYPE_ACTION,
6555 : : NULL,
6556 : : "Sample Only support Ingress "
6557 : : "or E-Switch");
6558 [ # # ]: 0 : } else if (sample->actions->type != RTE_FLOW_ACTION_TYPE_END) {
6559 : : MLX5_ASSERT(attr->transfer);
6560 [ # # ]: 0 : if (sample->ratio > 1)
6561 : 0 : return rte_flow_error_set(error, ENOTSUP,
6562 : : RTE_FLOW_ERROR_TYPE_ACTION,
6563 : : NULL,
6564 : : "E-Switch doesn't support "
6565 : : "any optional action "
6566 : : "for sampling");
6567 [ # # ]: 0 : if (*sub_action_flags & MLX5_FLOW_ACTION_QUEUE)
6568 : 0 : return rte_flow_error_set(error, ENOTSUP,
6569 : : RTE_FLOW_ERROR_TYPE_ACTION,
6570 : : NULL,
6571 : : "unsupported action QUEUE");
6572 [ # # ]: 0 : if (*sub_action_flags & MLX5_FLOW_ACTION_RSS)
6573 : 0 : return rte_flow_error_set(error, ENOTSUP,
6574 : : RTE_FLOW_ERROR_TYPE_ACTION,
6575 : : NULL,
6576 : : "unsupported action QUEUE");
6577 [ # # ]: 0 : if (!(*sub_action_flags & MLX5_FLOW_ACTION_PORT_ID))
6578 : 0 : return rte_flow_error_set(error, EINVAL,
6579 : : RTE_FLOW_ERROR_TYPE_ACTION,
6580 : : NULL,
6581 : : "E-Switch must has a dest "
6582 : : "port for mirroring");
6583 : 0 : *fdb_mirror = 1;
6584 : : }
6585 : : /* Continue validation for Xcap actions.*/
6586 [ # # # # ]: 0 : if ((*sub_action_flags & MLX5_FLOW_XCAP_ACTIONS) &&
6587 [ # # ]: 0 : (queue_index == 0xFFFF || !mlx5_rxq_is_hairpin(dev, queue_index))) {
6588 [ # # ]: 0 : if ((*sub_action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
6589 : : MLX5_FLOW_XCAP_ACTIONS)
6590 : 0 : return rte_flow_error_set(error, ENOTSUP,
6591 : : RTE_FLOW_ERROR_TYPE_ACTION,
6592 : : NULL, "encap and decap "
6593 : : "combination aren't "
6594 : : "supported");
6595 [ # # # # ]: 0 : if (attr->ingress && (*sub_action_flags & MLX5_FLOW_ACTION_ENCAP))
6596 : 0 : return rte_flow_error_set(error, ENOTSUP,
6597 : : RTE_FLOW_ERROR_TYPE_ACTION,
6598 : : NULL, "encap is not supported"
6599 : : " for ingress traffic");
6600 : : }
6601 : : return 0;
6602 : : }
6603 : :
6604 : : int
6605 : 0 : __flow_modify_hdr_resource_register(struct rte_eth_dev *dev,
6606 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
6607 : : struct mlx5_flow_dv_modify_hdr_resource **modify,
6608 : : struct rte_flow_error *error)
6609 : : {
6610 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6611 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
6612 : 0 : uint32_t key_len = sizeof(*resource) -
6613 : : offsetof(typeof(*resource), ft_type) +
6614 : 0 : resource->actions_num * sizeof(resource->actions[0]);
6615 : : struct mlx5_list_entry *entry;
6616 : 0 : struct mlx5_flow_cb_ctx ctx = {
6617 : : .error = error,
6618 : : .data = resource,
6619 : 0 : .data2 = priv->dr_ctx,
6620 : : };
6621 : : struct mlx5_hlist *modify_cmds;
6622 : : uint64_t key64;
6623 : :
6624 : 0 : modify_cmds = flow_dv_hlist_prepare(sh, &sh->modify_cmds,
6625 : : "hdr_modify",
6626 : : MLX5_FLOW_HDR_MODIFY_HTABLE_SZ,
6627 : : true, false, sh,
6628 : : flow_modify_create_cb,
6629 : : flow_modify_match_cb,
6630 : : flow_modify_remove_cb,
6631 : : flow_modify_clone_cb,
6632 : : flow_modify_clone_free_cb,
6633 : : error);
6634 [ # # ]: 0 : if (unlikely(!modify_cmds))
6635 : 0 : return -rte_errno;
6636 [ # # ]: 0 : if (resource->actions_num > flow_dv_modify_hdr_action_max(dev,
6637 [ # # ]: 0 : resource->root))
6638 : 0 : return rte_flow_error_set(error, EOVERFLOW,
6639 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6640 : : "too many modify header items");
6641 : 0 : key64 = __rte_raw_cksum(&resource->ft_type, key_len, 0);
6642 : 0 : entry = mlx5_hlist_register(modify_cmds, key64, &ctx);
6643 [ # # ]: 0 : if (!entry)
6644 : 0 : return -rte_errno;
6645 : 0 : *modify = container_of(entry, typeof(*resource), entry);
6646 : 0 : return 0;
6647 : : }
6648 : :
6649 : : /**
6650 : : * Find existing modify-header resource or create and register a new one.
6651 : : *
6652 : : * @param dev[in, out]
6653 : : * Pointer to rte_eth_dev structure.
6654 : : * @param[in, out] resource
6655 : : * Pointer to modify-header resource.
6656 : : * @param[in, out] dev_flow
6657 : : * Pointer to the dev_flow.
6658 : : * @param[out] error
6659 : : * pointer to error structure.
6660 : : *
6661 : : * @return
6662 : : * 0 on success otherwise -errno and errno is set.
6663 : : */
6664 : : static int
6665 : : flow_dv_modify_hdr_resource_register
6666 : : (struct rte_eth_dev *dev,
6667 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
6668 : : struct mlx5_flow *dev_flow,
6669 : : struct rte_flow_error *error)
6670 : : {
6671 : 0 : resource->root = !dev_flow->dv.group;
6672 : 0 : return __flow_modify_hdr_resource_register(dev, resource,
6673 : 0 : &dev_flow->handle->dvh.modify_hdr, error);
6674 : : }
6675 : :
6676 : : /**
6677 : : * Get DV flow counter by index.
6678 : : *
6679 : : * @param[in] dev
6680 : : * Pointer to the Ethernet device structure.
6681 : : * @param[in] idx
6682 : : * mlx5 flow counter index in the container.
6683 : : * @param[out] ppool
6684 : : * mlx5 flow counter pool in the container.
6685 : : *
6686 : : * @return
6687 : : * Pointer to the counter, NULL otherwise.
6688 : : */
6689 : : static struct mlx5_flow_counter *
6690 : : flow_dv_counter_get_by_idx(struct rte_eth_dev *dev,
6691 : : uint32_t idx,
6692 : : struct mlx5_flow_counter_pool **ppool)
6693 : : {
6694 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6695 : 0 : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
6696 : : struct mlx5_flow_counter_pool *pool;
6697 : :
6698 : : /* Decrease to original index and clear shared bit. */
6699 : 0 : idx = (idx - 1) & (MLX5_CNT_SHARED_OFFSET - 1);
6700 : : MLX5_ASSERT(idx / MLX5_COUNTERS_PER_POOL < MLX5_COUNTER_POOLS_MAX_NUM);
6701 : 0 : pool = cmng->pools[idx / MLX5_COUNTERS_PER_POOL];
6702 : : MLX5_ASSERT(pool);
6703 : : if (ppool)
6704 : : *ppool = pool;
6705 [ # # # # : 0 : return MLX5_POOL_GET_CNT(pool, idx % MLX5_COUNTERS_PER_POOL);
# # # # #
# # # ]
6706 : : }
6707 : :
6708 : : /**
6709 : : * Check the devx counter belongs to the pool.
6710 : : *
6711 : : * @param[in] pool
6712 : : * Pointer to the counter pool.
6713 : : * @param[in] id
6714 : : * The counter devx ID.
6715 : : *
6716 : : * @return
6717 : : * True if counter belongs to the pool, false otherwise.
6718 : : */
6719 : : static bool
6720 : : flow_dv_is_counter_in_pool(struct mlx5_flow_counter_pool *pool, int id)
6721 : : {
6722 : 0 : int base = (pool->min_dcs->id / MLX5_COUNTERS_PER_POOL) *
6723 : : MLX5_COUNTERS_PER_POOL;
6724 : :
6725 [ # # # # ]: 0 : if (id >= base && id < base + MLX5_COUNTERS_PER_POOL)
6726 : : return true;
6727 : : return false;
6728 : : }
6729 : :
6730 : : /**
6731 : : * Get a pool by devx counter ID.
6732 : : *
6733 : : * @param[in] cmng
6734 : : * Pointer to the counter management.
6735 : : * @param[in] id
6736 : : * The counter devx ID.
6737 : : *
6738 : : * @return
6739 : : * The counter pool pointer if exists, NULL otherwise,
6740 : : */
6741 : : static struct mlx5_flow_counter_pool *
6742 : 0 : flow_dv_find_pool_by_id(struct mlx5_flow_counter_mng *cmng, int id)
6743 : : {
6744 : : uint32_t i;
6745 : : struct mlx5_flow_counter_pool *pool = NULL;
6746 : :
6747 : 0 : rte_spinlock_lock(&cmng->pool_update_sl);
6748 : : /* Check last used pool. */
6749 [ # # ]: 0 : if (cmng->last_pool_idx != POOL_IDX_INVALID &&
6750 [ # # ]: 0 : flow_dv_is_counter_in_pool(cmng->pools[cmng->last_pool_idx], id)) {
6751 : : pool = cmng->pools[cmng->last_pool_idx];
6752 : 0 : goto out;
6753 : : }
6754 : : /* ID out of range means no suitable pool in the container. */
6755 [ # # # # ]: 0 : if (id > cmng->max_id || id < cmng->min_id)
6756 : 0 : goto out;
6757 : : /*
6758 : : * Find the pool from the end of the container, since mostly counter
6759 : : * ID is sequence increasing, and the last pool should be the needed
6760 : : * one.
6761 : : */
6762 : 0 : i = cmng->n_valid;
6763 [ # # ]: 0 : while (i--) {
6764 [ # # ]: 0 : struct mlx5_flow_counter_pool *pool_tmp = cmng->pools[i];
6765 : :
6766 : : if (flow_dv_is_counter_in_pool(pool_tmp, id)) {
6767 : : pool = pool_tmp;
6768 : : break;
6769 : : }
6770 : : }
6771 : 0 : out:
6772 : : rte_spinlock_unlock(&cmng->pool_update_sl);
6773 : 0 : return pool;
6774 : : }
6775 : :
6776 : : /**
6777 : : * Query a devx flow counter.
6778 : : *
6779 : : * @param[in] dev
6780 : : * Pointer to the Ethernet device structure.
6781 : : * @param[in] counter
6782 : : * Index to the flow counter.
6783 : : * @param[out] pkts
6784 : : * The statistics value of packets.
6785 : : * @param[out] bytes
6786 : : * The statistics value of bytes.
6787 : : *
6788 : : * @return
6789 : : * 0 on success, otherwise a negative errno value and rte_errno is set.
6790 : : */
6791 : : static inline int
6792 : 0 : _flow_dv_query_count(struct rte_eth_dev *dev, uint32_t counter, uint64_t *pkts,
6793 : : uint64_t *bytes)
6794 : : {
6795 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
6796 : : struct mlx5_flow_counter_pool *pool = NULL;
6797 : : struct mlx5_flow_counter *cnt;
6798 : : int offset;
6799 : :
6800 : : cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
6801 : : MLX5_ASSERT(pool);
6802 [ # # ]: 0 : if (priv->sh->sws_cmng.counter_fallback)
6803 : 0 : return mlx5_devx_cmd_flow_counter_query(cnt->dcs_when_active, 0,
6804 : : 0, pkts, bytes, 0, NULL, NULL, 0);
6805 : 0 : rte_spinlock_lock(&pool->sl);
6806 [ # # ]: 0 : if (!pool->raw) {
6807 : 0 : *pkts = 0;
6808 : 0 : *bytes = 0;
6809 : : } else {
6810 [ # # ]: 0 : offset = MLX5_CNT_ARRAY_IDX(pool, cnt);
6811 : 0 : *pkts = rte_be_to_cpu_64(pool->raw->data[offset].hits);
6812 : 0 : *bytes = rte_be_to_cpu_64(pool->raw->data[offset].bytes);
6813 : : }
6814 : : rte_spinlock_unlock(&pool->sl);
6815 : 0 : return 0;
6816 : : }
6817 : :
6818 : : /**
6819 : : * Create and initialize a new counter pool.
6820 : : *
6821 : : * @param[in] dev
6822 : : * Pointer to the Ethernet device structure.
6823 : : * @param[out] dcs
6824 : : * The devX counter handle.
6825 : : * @param[in] age
6826 : : * Whether the pool is for counter that was allocated for aging.
6827 : : *
6828 : : * @return
6829 : : * The pool container pointer on success, NULL otherwise and rte_errno is set.
6830 : : */
6831 : : static struct mlx5_flow_counter_pool *
6832 : 0 : flow_dv_pool_create(struct rte_eth_dev *dev, struct mlx5_devx_obj *dcs,
6833 : : uint32_t age)
6834 : : {
6835 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6836 : : struct mlx5_flow_counter_pool *pool;
6837 : 0 : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
6838 : 0 : bool fallback = cmng->counter_fallback;
6839 : : uint32_t size = sizeof(*pool);
6840 : :
6841 [ # # ]: 0 : if (cmng->n_valid == MLX5_COUNTER_POOLS_MAX_NUM) {
6842 : 0 : DRV_LOG(ERR, "All counter is in used, try again later.");
6843 : 0 : rte_errno = EAGAIN;
6844 : 0 : return NULL;
6845 : : }
6846 : : size += MLX5_COUNTERS_PER_POOL * MLX5_CNT_SIZE;
6847 [ # # ]: 0 : size += (!age ? 0 : MLX5_COUNTERS_PER_POOL * MLX5_AGE_SIZE);
6848 : 0 : pool = mlx5_malloc(MLX5_MEM_ZERO, size, 0, SOCKET_ID_ANY);
6849 [ # # ]: 0 : if (!pool) {
6850 : 0 : rte_errno = ENOMEM;
6851 : 0 : return NULL;
6852 : : }
6853 : 0 : pool->raw = NULL;
6854 : 0 : pool->is_aged = !!age;
6855 : 0 : pool->query_gen = 0;
6856 : 0 : pool->min_dcs = dcs;
6857 : : rte_spinlock_init(&pool->sl);
6858 : : rte_spinlock_init(&pool->csl);
6859 : 0 : TAILQ_INIT(&pool->counters[0]);
6860 : 0 : TAILQ_INIT(&pool->counters[1]);
6861 : 0 : pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
6862 : 0 : rte_spinlock_lock(&cmng->pool_update_sl);
6863 : 0 : pool->index = cmng->n_valid;
6864 : 0 : cmng->pools[pool->index] = pool;
6865 : 0 : cmng->n_valid++;
6866 [ # # ]: 0 : if (unlikely(fallback)) {
6867 : 0 : int base = RTE_ALIGN_FLOOR(dcs->id, MLX5_COUNTERS_PER_POOL);
6868 : :
6869 [ # # ]: 0 : if (base < cmng->min_id)
6870 : 0 : cmng->min_id = base;
6871 [ # # ]: 0 : if (base > cmng->max_id)
6872 : 0 : cmng->max_id = base + MLX5_COUNTERS_PER_POOL - 1;
6873 : 0 : cmng->last_pool_idx = pool->index;
6874 : : }
6875 : : rte_spinlock_unlock(&cmng->pool_update_sl);
6876 : 0 : return pool;
6877 : : }
6878 : :
6879 : : /**
6880 : : * Prepare a new counter and/or a new counter pool.
6881 : : *
6882 : : * @param[in] dev
6883 : : * Pointer to the Ethernet device structure.
6884 : : * @param[out] cnt_free
6885 : : * Where to put the pointer of a new counter.
6886 : : * @param[in] age
6887 : : * Whether the pool is for counter that was allocated for aging.
6888 : : *
6889 : : * @return
6890 : : * The counter pool pointer and @p cnt_free is set on success,
6891 : : * NULL otherwise and rte_errno is set.
6892 : : */
6893 : : static struct mlx5_flow_counter_pool *
6894 : 0 : flow_dv_counter_pool_prepare(struct rte_eth_dev *dev,
6895 : : struct mlx5_flow_counter **cnt_free,
6896 : : uint32_t age)
6897 : : {
6898 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6899 : 0 : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
6900 : : struct mlx5_flow_counter_pool *pool;
6901 : : struct mlx5_counters tmp_tq;
6902 : : struct mlx5_devx_obj *dcs = NULL;
6903 : : struct mlx5_flow_counter *cnt;
6904 : 0 : enum mlx5_counter_type cnt_type =
6905 : 0 : age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
6906 : 0 : bool fallback = priv->sh->sws_cmng.counter_fallback;
6907 : : uint32_t i;
6908 : :
6909 [ # # ]: 0 : if (fallback) {
6910 : : /* bulk_bitmap must be 0 for single counter allocation. */
6911 : 0 : dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0);
6912 [ # # ]: 0 : if (!dcs)
6913 : : return NULL;
6914 : 0 : pool = flow_dv_find_pool_by_id(cmng, dcs->id);
6915 [ # # ]: 0 : if (!pool) {
6916 : 0 : pool = flow_dv_pool_create(dev, dcs, age);
6917 [ # # ]: 0 : if (!pool) {
6918 : 0 : mlx5_devx_cmd_destroy(dcs);
6919 : 0 : return NULL;
6920 : : }
6921 : : }
6922 : 0 : i = dcs->id % MLX5_COUNTERS_PER_POOL;
6923 [ # # ]: 0 : cnt = MLX5_POOL_GET_CNT(pool, i);
6924 : 0 : cnt->pool = pool;
6925 : 0 : cnt->dcs_when_free = dcs;
6926 : 0 : *cnt_free = cnt;
6927 : 0 : return pool;
6928 : : }
6929 : 0 : dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0x4);
6930 [ # # ]: 0 : if (!dcs) {
6931 : 0 : rte_errno = ENODATA;
6932 : 0 : return NULL;
6933 : : }
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 : 0 : TAILQ_INIT(&tmp_tq);
6940 [ # # ]: 0 : for (i = 1; i < MLX5_COUNTERS_PER_POOL; ++i) {
6941 [ # # ]: 0 : cnt = MLX5_POOL_GET_CNT(pool, i);
6942 : 0 : cnt->pool = pool;
6943 [ # # ]: 0 : TAILQ_INSERT_HEAD(&tmp_tq, cnt, next);
6944 : : }
6945 : 0 : rte_spinlock_lock(&cmng->csl[cnt_type]);
6946 [ # # ]: 0 : TAILQ_CONCAT(&cmng->counters[cnt_type], &tmp_tq, next);
6947 : : rte_spinlock_unlock(&cmng->csl[cnt_type]);
6948 : 0 : *cnt_free = MLX5_POOL_GET_CNT(pool, 0);
6949 : 0 : (*cnt_free)->pool = pool;
6950 : 0 : return pool;
6951 : : }
6952 : :
6953 : : /**
6954 : : * Allocate a flow counter.
6955 : : *
6956 : : * @param[in] dev
6957 : : * Pointer to the Ethernet device structure.
6958 : : * @param[in] age
6959 : : * Whether the counter was allocated for aging.
6960 : : *
6961 : : * @return
6962 : : * Index to flow counter on success, 0 otherwise and rte_errno is set.
6963 : : */
6964 : : static uint32_t
6965 : 0 : flow_dv_counter_alloc(struct rte_eth_dev *dev, uint32_t age)
6966 : : {
6967 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6968 : : struct mlx5_flow_counter_pool *pool = NULL;
6969 : 0 : struct mlx5_flow_counter *cnt_free = NULL;
6970 : 0 : bool fallback = priv->sh->sws_cmng.counter_fallback;
6971 : : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
6972 : 0 : enum mlx5_counter_type cnt_type =
6973 : 0 : age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
6974 : : uint32_t cnt_idx;
6975 : :
6976 [ # # ]: 0 : if (!priv->sh->cdev->config.devx) {
6977 : 0 : rte_errno = ENOTSUP;
6978 : 0 : return 0;
6979 : : }
6980 : : /* Get free counters from container. */
6981 : 0 : rte_spinlock_lock(&cmng->csl[cnt_type]);
6982 : 0 : cnt_free = TAILQ_FIRST(&cmng->counters[cnt_type]);
6983 [ # # ]: 0 : if (cnt_free)
6984 [ # # ]: 0 : TAILQ_REMOVE(&cmng->counters[cnt_type], cnt_free, next);
6985 : : rte_spinlock_unlock(&cmng->csl[cnt_type]);
6986 [ # # # # ]: 0 : if (!cnt_free && !flow_dv_counter_pool_prepare(dev, &cnt_free, age))
6987 : 0 : goto err;
6988 : 0 : pool = cnt_free->pool;
6989 [ # # ]: 0 : if (fallback)
6990 : 0 : cnt_free->dcs_when_active = cnt_free->dcs_when_free;
6991 : : /* Create a DV counter action only in the first time usage. */
6992 [ # # ]: 0 : if (!cnt_free->action) {
6993 : : uint16_t offset;
6994 : : struct mlx5_devx_obj *dcs;
6995 : : int ret;
6996 : :
6997 [ # # ]: 0 : if (!fallback) {
6998 [ # # ]: 0 : offset = MLX5_CNT_ARRAY_IDX(pool, cnt_free);
6999 : 0 : dcs = pool->min_dcs;
7000 : : } else {
7001 : : offset = 0;
7002 : 0 : dcs = cnt_free->dcs_when_free;
7003 : : }
7004 : 0 : ret = mlx5_flow_os_create_flow_action_count(dcs->obj, offset,
7005 : : &cnt_free->action);
7006 : : if (ret) {
7007 : 0 : rte_errno = errno;
7008 : 0 : goto err;
7009 : : }
7010 : : }
7011 [ # # ]: 0 : cnt_idx = MLX5_MAKE_CNT_IDX(pool->index,
7012 : : MLX5_CNT_ARRAY_IDX(pool, cnt_free));
7013 : : /* Update the counter reset values. */
7014 [ # # ]: 0 : if (_flow_dv_query_count(dev, cnt_idx, &cnt_free->hits,
7015 : : &cnt_free->bytes))
7016 : 0 : goto err;
7017 [ # # # # ]: 0 : if (!fallback && !priv->sh->sws_cmng.query_thread_on)
7018 : : /* Start the asynchronous batch query by the host thread. */
7019 : 0 : mlx5_set_query_alarm(priv->sh);
7020 : : /*
7021 : : * When the count action isn't shared (by ID), shared_info field is
7022 : : * used for indirect action API's refcnt.
7023 : : * When the counter action is not shared neither by ID nor by indirect
7024 : : * action API, shared info must be 1.
7025 : : */
7026 : 0 : cnt_free->shared_info.refcnt = 1;
7027 : 0 : return cnt_idx;
7028 : 0 : err:
7029 [ # # ]: 0 : if (cnt_free) {
7030 : 0 : cnt_free->pool = pool;
7031 [ # # ]: 0 : if (fallback)
7032 : 0 : cnt_free->dcs_when_free = cnt_free->dcs_when_active;
7033 : : rte_spinlock_lock(&cmng->csl[cnt_type]);
7034 : 0 : TAILQ_INSERT_TAIL(&cmng->counters[cnt_type], cnt_free, next);
7035 : : rte_spinlock_unlock(&cmng->csl[cnt_type]);
7036 : : }
7037 : : return 0;
7038 : : }
7039 : :
7040 : : /**
7041 : : * Get age param from counter index.
7042 : : *
7043 : : * @param[in] dev
7044 : : * Pointer to the Ethernet device structure.
7045 : : * @param[in] counter
7046 : : * Index to the counter handler.
7047 : : *
7048 : : * @return
7049 : : * The aging parameter specified for the counter index.
7050 : : */
7051 : : static struct mlx5_age_param*
7052 : : flow_dv_counter_idx_get_age(struct rte_eth_dev *dev,
7053 : : uint32_t counter)
7054 : : {
7055 : : struct mlx5_flow_counter *cnt;
7056 : : struct mlx5_flow_counter_pool *pool = NULL;
7057 : :
7058 : : flow_dv_counter_get_by_idx(dev, counter, &pool);
7059 : : counter = (counter - 1) % MLX5_COUNTERS_PER_POOL;
7060 : : cnt = MLX5_POOL_GET_CNT(pool, counter);
7061 : 0 : return MLX5_CNT_TO_AGE(cnt);
7062 : : }
7063 : :
7064 : : /**
7065 : : * Remove a flow counter from aged counter list.
7066 : : *
7067 : : * @param[in] dev
7068 : : * Pointer to the Ethernet device structure.
7069 : : * @param[in] counter
7070 : : * Index to the counter handler.
7071 : : * @param[in] cnt
7072 : : * Pointer to the counter handler.
7073 : : */
7074 : : static void
7075 : 0 : flow_dv_counter_remove_from_age(struct rte_eth_dev *dev,
7076 : : uint32_t counter, struct mlx5_flow_counter *cnt)
7077 : : {
7078 : : struct mlx5_age_info *age_info;
7079 : : struct mlx5_age_param *age_param;
7080 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7081 : : uint16_t expected = AGE_CANDIDATE;
7082 : :
7083 [ # # ]: 0 : age_info = GET_PORT_AGE_INFO(priv);
7084 : : age_param = flow_dv_counter_idx_get_age(dev, counter);
7085 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(&age_param->state, &expected,
7086 : : AGE_FREE, rte_memory_order_relaxed,
7087 : : rte_memory_order_relaxed)) {
7088 : : /**
7089 : : * We need the lock even it is age timeout,
7090 : : * since counter may still in process.
7091 : : */
7092 : 0 : rte_spinlock_lock(&age_info->aged_sl);
7093 [ # # ]: 0 : TAILQ_REMOVE(&age_info->aged_counters, cnt, next);
7094 : : rte_spinlock_unlock(&age_info->aged_sl);
7095 : 0 : rte_atomic_store_explicit(&age_param->state, AGE_FREE, rte_memory_order_relaxed);
7096 : : }
7097 : 0 : }
7098 : :
7099 : : /**
7100 : : * Release a flow counter.
7101 : : *
7102 : : * @param[in] dev
7103 : : * Pointer to the Ethernet device structure.
7104 : : * @param[in] counter
7105 : : * Index to the counter handler.
7106 : : */
7107 : : static void
7108 : 0 : flow_dv_counter_free(struct rte_eth_dev *dev, uint32_t counter)
7109 : : {
7110 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7111 : : struct mlx5_flow_counter_pool *pool = NULL;
7112 : : struct mlx5_flow_counter *cnt;
7113 : : enum mlx5_counter_type cnt_type;
7114 : :
7115 [ # # ]: 0 : if (!counter)
7116 : : return;
7117 : : cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
7118 : : MLX5_ASSERT(pool);
7119 [ # # ]: 0 : if (pool->is_aged) {
7120 : 0 : flow_dv_counter_remove_from_age(dev, counter, cnt);
7121 : : } else {
7122 : : /*
7123 : : * If the counter action is shared by indirect action API,
7124 : : * the atomic function reduces its references counter.
7125 : : * If after the reduction the action is still referenced, the
7126 : : * function returns here and does not release it.
7127 : : * When the counter action is not shared by
7128 : : * indirect action API, shared info is 1 before the reduction,
7129 : : * so this condition is failed and function doesn't return here.
7130 : : */
7131 [ # # ]: 0 : if (rte_atomic_fetch_sub_explicit(&cnt->shared_info.refcnt, 1,
7132 : : rte_memory_order_relaxed) - 1)
7133 : : return;
7134 : : }
7135 : 0 : cnt->pool = pool;
7136 : : /*
7137 : : * Put the counter back to list to be updated in none fallback mode.
7138 : : * Currently, we are using two list alternately, while one is in query,
7139 : : * add the freed counter to the other list based on the pool query_gen
7140 : : * value. After query finishes, add counter the list to the global
7141 : : * container counter list. The list changes while query starts. In
7142 : : * this case, lock will not be needed as query callback and release
7143 : : * function both operate with the different list.
7144 : : */
7145 [ # # ]: 0 : if (!priv->sh->sws_cmng.counter_fallback) {
7146 : 0 : rte_spinlock_lock(&pool->csl);
7147 : 0 : TAILQ_INSERT_TAIL(&pool->counters[pool->query_gen], cnt, next);
7148 : : rte_spinlock_unlock(&pool->csl);
7149 : : } else {
7150 : 0 : cnt->dcs_when_free = cnt->dcs_when_active;
7151 : 0 : cnt_type = pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
7152 : : MLX5_COUNTER_TYPE_ORIGIN;
7153 : 0 : rte_spinlock_lock(&priv->sh->sws_cmng.csl[cnt_type]);
7154 : 0 : TAILQ_INSERT_TAIL(&priv->sh->sws_cmng.counters[cnt_type],
7155 : : cnt, next);
7156 : 0 : rte_spinlock_unlock(&priv->sh->sws_cmng.csl[cnt_type]);
7157 : : }
7158 : : }
7159 : :
7160 : : /**
7161 : : * Resize a meter id container.
7162 : : *
7163 : : * @param[in] dev
7164 : : * Pointer to the Ethernet device structure.
7165 : : *
7166 : : * @return
7167 : : * 0 on success, otherwise negative errno value and rte_errno is set.
7168 : : */
7169 : : static int
7170 : 0 : flow_dv_mtr_container_resize(struct rte_eth_dev *dev)
7171 : : {
7172 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7173 : : struct mlx5_aso_mtr_pools_mng *pools_mng =
7174 : 0 : &priv->sh->mtrmng->pools_mng;
7175 : 0 : void *old_pools = pools_mng->pools;
7176 : 0 : uint32_t resize = pools_mng->n + MLX5_MTRS_CONTAINER_RESIZE;
7177 : 0 : uint32_t mem_size = sizeof(struct mlx5_aso_mtr_pool *) * resize;
7178 : 0 : void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
7179 : :
7180 [ # # ]: 0 : if (!pools) {
7181 : 0 : rte_errno = ENOMEM;
7182 : 0 : return -ENOMEM;
7183 : : }
7184 [ # # ]: 0 : if (!pools_mng->n)
7185 [ # # ]: 0 : if (mlx5_aso_queue_init(priv->sh, ASO_OPC_MOD_POLICER, 1)) {
7186 : 0 : mlx5_free(pools);
7187 : 0 : return -ENOMEM;
7188 : : }
7189 [ # # ]: 0 : if (old_pools)
7190 : 0 : memcpy(pools, old_pools, pools_mng->n *
7191 : : sizeof(struct mlx5_aso_mtr_pool *));
7192 : 0 : pools_mng->n = resize;
7193 : 0 : pools_mng->pools = pools;
7194 [ # # ]: 0 : if (old_pools)
7195 : 0 : mlx5_free(old_pools);
7196 : : return 0;
7197 : : }
7198 : :
7199 : : /**
7200 : : * Prepare a new meter and/or a new meter pool.
7201 : : *
7202 : : * @param[in] dev
7203 : : * Pointer to the Ethernet device structure.
7204 : : * @param[out] mtr_free
7205 : : * Where to put the pointer of a new meter.g.
7206 : : *
7207 : : * @return
7208 : : * The meter pool pointer and @mtr_free is set on success,
7209 : : * NULL otherwise and rte_errno is set.
7210 : : */
7211 : : static struct mlx5_aso_mtr_pool *
7212 : 0 : flow_dv_mtr_pool_create(struct rte_eth_dev *dev, struct mlx5_aso_mtr **mtr_free)
7213 : : {
7214 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7215 : 0 : struct mlx5_aso_mtr_pools_mng *pools_mng = &priv->sh->mtrmng->pools_mng;
7216 : : struct mlx5_aso_mtr_pool *pool = NULL;
7217 : : struct mlx5_devx_obj *dcs = NULL;
7218 : : uint32_t i;
7219 : : uint32_t log_obj_size;
7220 : :
7221 : : log_obj_size = rte_log2_u32(MLX5_ASO_MTRS_PER_POOL >> 1);
7222 : 0 : dcs = mlx5_devx_cmd_create_flow_meter_aso_obj(priv->sh->cdev->ctx,
7223 : 0 : priv->sh->cdev->pdn,
7224 : : log_obj_size);
7225 [ # # ]: 0 : if (!dcs) {
7226 : 0 : rte_errno = ENODATA;
7227 : 0 : return NULL;
7228 : : }
7229 : 0 : pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
7230 [ # # ]: 0 : if (!pool) {
7231 : 0 : rte_errno = ENOMEM;
7232 : 0 : claim_zero(mlx5_devx_cmd_destroy(dcs));
7233 : 0 : return NULL;
7234 : : }
7235 : 0 : pool->devx_obj = dcs;
7236 : 0 : rte_rwlock_write_lock(&pools_mng->resize_mtrwl);
7237 : 0 : pool->index = pools_mng->n_valid;
7238 [ # # # # ]: 0 : if (pool->index == pools_mng->n && flow_dv_mtr_container_resize(dev)) {
7239 : 0 : mlx5_free(pool);
7240 : 0 : claim_zero(mlx5_devx_cmd_destroy(dcs));
7241 : : rte_rwlock_write_unlock(&pools_mng->resize_mtrwl);
7242 : 0 : return NULL;
7243 : : }
7244 : 0 : pools_mng->pools[pool->index] = pool;
7245 : 0 : pools_mng->n_valid++;
7246 : : rte_rwlock_write_unlock(&pools_mng->resize_mtrwl);
7247 [ # # ]: 0 : for (i = 1; i < MLX5_ASO_MTRS_PER_POOL; ++i) {
7248 : 0 : pool->mtrs[i].offset = i;
7249 [ # # ]: 0 : LIST_INSERT_HEAD(&pools_mng->meters, &pool->mtrs[i], next);
7250 : : }
7251 : 0 : pool->mtrs[0].offset = 0;
7252 : 0 : *mtr_free = &pool->mtrs[0];
7253 : 0 : return pool;
7254 : : }
7255 : :
7256 : : /**
7257 : : * Release a flow meter into pool.
7258 : : *
7259 : : * @param[in] dev
7260 : : * Pointer to the Ethernet device structure.
7261 : : * @param[in] mtr_idx
7262 : : * Index to aso flow meter.
7263 : : */
7264 : : static void
7265 : 0 : flow_dv_aso_mtr_release_to_pool(struct rte_eth_dev *dev, uint32_t mtr_idx)
7266 : : {
7267 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7268 : : struct mlx5_aso_mtr_pools_mng *pools_mng =
7269 : 0 : &priv->sh->mtrmng->pools_mng;
7270 : 0 : struct mlx5_aso_mtr *aso_mtr = mlx5_aso_meter_by_idx(priv, mtr_idx);
7271 : :
7272 : : MLX5_ASSERT(aso_mtr);
7273 : 0 : rte_spinlock_lock(&pools_mng->mtrsl);
7274 [ # # ]: 0 : memset(&aso_mtr->fm, 0, sizeof(struct mlx5_flow_meter_info));
7275 : 0 : aso_mtr->state = ASO_METER_FREE;
7276 [ # # ]: 0 : LIST_INSERT_HEAD(&pools_mng->meters, aso_mtr, next);
7277 : : rte_spinlock_unlock(&pools_mng->mtrsl);
7278 : 0 : }
7279 : :
7280 : : /**
7281 : : * Allocate a aso flow meter.
7282 : : *
7283 : : * @param[in] dev
7284 : : * Pointer to the Ethernet device structure.
7285 : : *
7286 : : * @return
7287 : : * Index to aso flow meter on success, 0 otherwise and rte_errno is set.
7288 : : */
7289 : : static uint32_t
7290 : 0 : flow_dv_mtr_alloc(struct rte_eth_dev *dev)
7291 : : {
7292 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7293 : 0 : struct mlx5_aso_mtr *mtr_free = NULL;
7294 : : struct mlx5_aso_mtr_pools_mng *pools_mng =
7295 : 0 : &priv->sh->mtrmng->pools_mng;
7296 : : struct mlx5_aso_mtr_pool *pool;
7297 : : uint32_t mtr_idx = 0;
7298 : :
7299 [ # # ]: 0 : if (!priv->sh->cdev->config.devx) {
7300 : 0 : rte_errno = ENOTSUP;
7301 : 0 : return 0;
7302 : : }
7303 : : /* Allocate the flow meter memory. */
7304 : : /* Get free meters from management. */
7305 : 0 : rte_spinlock_lock(&pools_mng->mtrsl);
7306 : 0 : mtr_free = LIST_FIRST(&pools_mng->meters);
7307 [ # # ]: 0 : if (mtr_free)
7308 [ # # ]: 0 : LIST_REMOVE(mtr_free, next);
7309 [ # # # # ]: 0 : if (!mtr_free && !flow_dv_mtr_pool_create(dev, &mtr_free)) {
7310 : : rte_spinlock_unlock(&pools_mng->mtrsl);
7311 : 0 : return 0;
7312 : : }
7313 : 0 : mtr_free->state = ASO_METER_WAIT;
7314 : : rte_spinlock_unlock(&pools_mng->mtrsl);
7315 : 0 : pool = container_of(mtr_free,
7316 : : struct mlx5_aso_mtr_pool,
7317 : : mtrs[mtr_free->offset]);
7318 : 0 : mtr_idx = MLX5_MAKE_MTR_IDX(pool->index, mtr_free->offset);
7319 [ # # ]: 0 : if (!mtr_free->fm.meter_action_g) {
7320 : : #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
7321 : : struct rte_flow_error error;
7322 : : uint8_t reg_id;
7323 : :
7324 : 0 : reg_id = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &error);
7325 : 0 : mtr_free->fm.meter_action_g =
7326 : 0 : mlx5_glue->dv_create_flow_action_aso
7327 : 0 : (priv->sh->rx_domain,
7328 : 0 : pool->devx_obj->obj,
7329 : : mtr_free->offset,
7330 : : (1 << MLX5_FLOW_COLOR_GREEN),
7331 : 0 : reg_id - REG_C_0);
7332 : : #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
7333 [ # # ]: 0 : if (!mtr_free->fm.meter_action_g) {
7334 : 0 : flow_dv_aso_mtr_release_to_pool(dev, mtr_idx);
7335 : 0 : return 0;
7336 : : }
7337 : : }
7338 : : return mtr_idx;
7339 : : }
7340 : :
7341 : : /**
7342 : : * Verify the @p attributes will be correctly understood by the NIC and store
7343 : : * them in the @p flow if everything is correct.
7344 : : *
7345 : : * @param[in] dev
7346 : : * Pointer to dev struct.
7347 : : * @param[in] attributes
7348 : : * Pointer to flow attributes
7349 : : * @param[in] external
7350 : : * This flow rule is created by request external to PMD.
7351 : : * @param[out] error
7352 : : * Pointer to error structure.
7353 : : *
7354 : : * @return
7355 : : * - 0 on success and non root table.
7356 : : * - 1 on success and root table.
7357 : : * - a negative errno value otherwise and rte_errno is set.
7358 : : */
7359 : : static int
7360 : 0 : flow_dv_validate_attributes(struct rte_eth_dev *dev,
7361 : : const struct mlx5_flow_tunnel *tunnel,
7362 : : const struct rte_flow_attr *attributes,
7363 : : const struct flow_grp_info *grp_info,
7364 : : struct rte_flow_error *error)
7365 : : {
7366 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7367 : 0 : uint32_t lowest_priority = mlx5_get_lowest_priority(dev, attributes);
7368 : : int ret = 0;
7369 : :
7370 : : #ifndef HAVE_MLX5DV_DR
7371 : : RTE_SET_USED(tunnel);
7372 : : RTE_SET_USED(grp_info);
7373 : : if (attributes->group)
7374 : : return rte_flow_error_set(error, ENOTSUP,
7375 : : RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
7376 : : NULL,
7377 : : "groups are not supported");
7378 : : #else
7379 : 0 : uint32_t table = 0;
7380 : :
7381 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel, attributes->group, &table,
7382 : : grp_info, error);
7383 [ # # ]: 0 : if (ret)
7384 : : return ret;
7385 [ # # ]: 0 : if (!table)
7386 : : ret = MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL;
7387 : : #endif
7388 [ # # # # ]: 0 : if (attributes->priority != MLX5_FLOW_LOWEST_PRIO_INDICATOR &&
7389 : : attributes->priority > lowest_priority)
7390 : 0 : return rte_flow_error_set(error, ENOTSUP,
7391 : : RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
7392 : : NULL,
7393 : : "priority out of range");
7394 [ # # # # ]: 0 : if (attributes->transfer && !priv->sh->config.dv_esw_en)
7395 : 0 : return rte_flow_error_set(error, ENOTSUP,
7396 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7397 : : "E-Switch dr is not supported");
7398 [ # # ]: 0 : if (attributes->ingress + attributes->egress + attributes->transfer != 1) {
7399 : 0 : return rte_flow_error_set(error, EINVAL,
7400 : : RTE_FLOW_ERROR_TYPE_ATTR, NULL,
7401 : : "must specify exactly one of "
7402 : : "ingress, egress or transfer");
7403 : : }
7404 : : return ret;
7405 : : }
7406 : :
7407 : : static int
7408 : 0 : validate_integrity_bits(const void *arg,
7409 : : int64_t pattern_flags, uint64_t l3_flags,
7410 : : uint64_t l4_flags, uint64_t ip4_flag,
7411 : : struct rte_flow_error *error)
7412 : : {
7413 : : const struct rte_flow_item_integrity *mask = arg;
7414 : :
7415 [ # # # # ]: 0 : if (mask->l3_ok && !(pattern_flags & l3_flags))
7416 : 0 : return rte_flow_error_set(error, EINVAL,
7417 : : RTE_FLOW_ERROR_TYPE_ITEM,
7418 : : NULL, "missing L3 protocol");
7419 : :
7420 [ # # # # ]: 0 : if (mask->ipv4_csum_ok && !(pattern_flags & ip4_flag))
7421 : 0 : return rte_flow_error_set(error, EINVAL,
7422 : : RTE_FLOW_ERROR_TYPE_ITEM,
7423 : : NULL, "missing IPv4 protocol");
7424 : :
7425 [ # # # # ]: 0 : if ((mask->l4_ok || mask->l4_csum_ok) && !(pattern_flags & l4_flags))
7426 : 0 : return rte_flow_error_set(error, EINVAL,
7427 : : RTE_FLOW_ERROR_TYPE_ITEM,
7428 : : NULL, "missing L4 protocol");
7429 : :
7430 : : return 0;
7431 : : }
7432 : :
7433 : : static int
7434 : 0 : flow_dv_validate_item_integrity_post(const struct
7435 : : rte_flow_item *integrity_items[2],
7436 : : int64_t pattern_flags,
7437 : : struct rte_flow_error *error)
7438 : : {
7439 : : const struct rte_flow_item_integrity *mask;
7440 : : int ret;
7441 : :
7442 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_OUTER_INTEGRITY) {
7443 : 0 : mask = (typeof(mask))integrity_items[0]->mask;
7444 : 0 : ret = validate_integrity_bits(mask, pattern_flags,
7445 : : MLX5_FLOW_LAYER_OUTER_L3,
7446 : : MLX5_FLOW_LAYER_OUTER_L4,
7447 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4,
7448 : : error);
7449 [ # # ]: 0 : if (ret)
7450 : : return ret;
7451 : : }
7452 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_INNER_INTEGRITY) {
7453 : 0 : mask = (typeof(mask))integrity_items[1]->mask;
7454 : 0 : ret = validate_integrity_bits(mask, pattern_flags,
7455 : : MLX5_FLOW_LAYER_INNER_L3,
7456 : : MLX5_FLOW_LAYER_INNER_L4,
7457 : : MLX5_FLOW_LAYER_INNER_L3_IPV4,
7458 : : error);
7459 [ # # ]: 0 : if (ret)
7460 : 0 : return ret;
7461 : : }
7462 : : return 0;
7463 : : }
7464 : :
7465 : : static int
7466 : 0 : flow_dv_validate_item_integrity(struct rte_eth_dev *dev,
7467 : : const struct rte_flow_item *integrity_item,
7468 : : uint64_t pattern_flags, uint64_t *last_item,
7469 : : const struct rte_flow_item *integrity_items[2],
7470 : : struct rte_flow_error *error)
7471 : : {
7472 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7473 : 0 : const struct rte_flow_item_integrity *mask = (typeof(mask))
7474 : : integrity_item->mask;
7475 : 0 : const struct rte_flow_item_integrity *spec = (typeof(spec))
7476 : : integrity_item->spec;
7477 : :
7478 [ # # ]: 0 : if (!priv->sh->cdev->config.hca_attr.pkt_integrity_match)
7479 : 0 : return rte_flow_error_set(error, ENOTSUP,
7480 : : RTE_FLOW_ERROR_TYPE_ITEM,
7481 : : integrity_item,
7482 : : "packet integrity integrity_item not supported");
7483 [ # # ]: 0 : if (!spec)
7484 : 0 : return rte_flow_error_set(error, ENOTSUP,
7485 : : RTE_FLOW_ERROR_TYPE_ITEM,
7486 : : integrity_item,
7487 : : "no spec for integrity item");
7488 [ # # ]: 0 : if (!mask)
7489 : : mask = &rte_flow_item_integrity_mask;
7490 [ # # ]: 0 : if (!mlx5_validate_integrity_item(mask))
7491 : 0 : return rte_flow_error_set(error, ENOTSUP,
7492 : : RTE_FLOW_ERROR_TYPE_ITEM,
7493 : : integrity_item,
7494 : : "unsupported integrity filter");
7495 [ # # # # ]: 0 : if ((mask->l3_ok & !spec->l3_ok) || (mask->l4_ok & !spec->l4_ok) ||
7496 [ # # ]: 0 : (mask->ipv4_csum_ok & !spec->ipv4_csum_ok) ||
7497 [ # # ]: 0 : (mask->l4_csum_ok & !spec->l4_csum_ok))
7498 : 0 : return rte_flow_error_set(error, EINVAL,
7499 : : RTE_FLOW_ERROR_TYPE_ITEM,
7500 : : NULL, "negative integrity flow is not supported");
7501 [ # # ]: 0 : if (spec->level > 1) {
7502 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_INNER_INTEGRITY)
7503 : 0 : return rte_flow_error_set
7504 : : (error, ENOTSUP,
7505 : : RTE_FLOW_ERROR_TYPE_ITEM,
7506 : : NULL, "multiple inner integrity items not supported");
7507 : 0 : integrity_items[1] = integrity_item;
7508 : 0 : *last_item |= MLX5_FLOW_ITEM_INNER_INTEGRITY;
7509 : : } else {
7510 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_OUTER_INTEGRITY)
7511 : 0 : return rte_flow_error_set
7512 : : (error, ENOTSUP,
7513 : : RTE_FLOW_ERROR_TYPE_ITEM,
7514 : : NULL, "multiple outer integrity items not supported");
7515 : 0 : integrity_items[0] = integrity_item;
7516 : 0 : *last_item |= MLX5_FLOW_ITEM_OUTER_INTEGRITY;
7517 : : }
7518 : : return 0;
7519 : : }
7520 : :
7521 : : static int
7522 : 0 : flow_dv_validate_item_flex(struct rte_eth_dev *dev,
7523 : : const struct rte_flow_item *item,
7524 : : uint64_t item_flags,
7525 : : uint64_t *last_item,
7526 : : bool is_inner,
7527 : : struct rte_flow_error *error)
7528 : : {
7529 : 0 : const struct rte_flow_item_flex *flow_spec = item->spec;
7530 : 0 : const struct rte_flow_item_flex *flow_mask = item->mask;
7531 : : struct mlx5_flex_item *flex;
7532 : :
7533 [ # # ]: 0 : if (!flow_spec)
7534 : 0 : return rte_flow_error_set(error, EINVAL,
7535 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
7536 : : "flex flow item spec cannot be NULL");
7537 [ # # ]: 0 : if (!flow_mask)
7538 : 0 : return rte_flow_error_set(error, EINVAL,
7539 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
7540 : : "flex flow item mask cannot be NULL");
7541 [ # # ]: 0 : if (item->last)
7542 : 0 : return rte_flow_error_set(error, ENOTSUP,
7543 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
7544 : : "flex flow item last not supported");
7545 [ # # ]: 0 : if (mlx5_flex_acquire_index(dev, flow_spec->handle, false) < 0)
7546 : 0 : return rte_flow_error_set(error, EINVAL,
7547 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
7548 : : "invalid flex flow item handle");
7549 : 0 : flex = (struct mlx5_flex_item *)flow_spec->handle;
7550 [ # # # # : 0 : switch (flex->tunnel_mode) {
# # ]
7551 : 0 : case FLEX_TUNNEL_MODE_SINGLE:
7552 [ # # ]: 0 : if (item_flags &
7553 : : (MLX5_FLOW_ITEM_OUTER_FLEX | MLX5_FLOW_ITEM_INNER_FLEX))
7554 : 0 : rte_flow_error_set(error, EINVAL,
7555 : : RTE_FLOW_ERROR_TYPE_ITEM,
7556 : : NULL, "multiple flex items not supported");
7557 : : break;
7558 : 0 : case FLEX_TUNNEL_MODE_OUTER:
7559 [ # # ]: 0 : if (is_inner)
7560 : 0 : rte_flow_error_set(error, EINVAL,
7561 : : RTE_FLOW_ERROR_TYPE_ITEM,
7562 : : NULL, "inner flex item was not configured");
7563 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_OUTER_FLEX)
7564 : 0 : rte_flow_error_set(error, ENOTSUP,
7565 : : RTE_FLOW_ERROR_TYPE_ITEM,
7566 : : NULL, "multiple flex items not supported");
7567 : : break;
7568 : 0 : case FLEX_TUNNEL_MODE_INNER:
7569 [ # # ]: 0 : if (!is_inner)
7570 : 0 : rte_flow_error_set(error, EINVAL,
7571 : : RTE_FLOW_ERROR_TYPE_ITEM,
7572 : : NULL, "outer flex item was not configured");
7573 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_INNER_FLEX)
7574 : 0 : rte_flow_error_set(error, EINVAL,
7575 : : RTE_FLOW_ERROR_TYPE_ITEM,
7576 : : NULL, "multiple flex items not supported");
7577 : : break;
7578 : 0 : case FLEX_TUNNEL_MODE_MULTI:
7579 [ # # # # : 0 : if ((is_inner && (item_flags & MLX5_FLOW_ITEM_INNER_FLEX)) ||
# # ]
7580 [ # # ]: 0 : (!is_inner && (item_flags & MLX5_FLOW_ITEM_OUTER_FLEX))) {
7581 : 0 : rte_flow_error_set(error, EINVAL,
7582 : : RTE_FLOW_ERROR_TYPE_ITEM,
7583 : : NULL, "multiple flex items not supported");
7584 : : }
7585 : : break;
7586 : 0 : case FLEX_TUNNEL_MODE_TUNNEL:
7587 [ # # # # ]: 0 : if (is_inner || (item_flags & MLX5_FLOW_ITEM_FLEX_TUNNEL))
7588 : 0 : rte_flow_error_set(error, EINVAL,
7589 : : RTE_FLOW_ERROR_TYPE_ITEM,
7590 : : NULL, "multiple flex tunnel items not supported");
7591 : : break;
7592 : 0 : default:
7593 : 0 : rte_flow_error_set(error, EINVAL,
7594 : : RTE_FLOW_ERROR_TYPE_ITEM,
7595 : : NULL, "invalid flex item configuration");
7596 : : }
7597 : 0 : *last_item = flex->tunnel_mode == FLEX_TUNNEL_MODE_TUNNEL ?
7598 [ # # ]: 0 : MLX5_FLOW_ITEM_FLEX_TUNNEL : is_inner ?
7599 [ # # ]: 0 : MLX5_FLOW_ITEM_INNER_FLEX : MLX5_FLOW_ITEM_OUTER_FLEX;
7600 : 0 : return 0;
7601 : : }
7602 : :
7603 : : static __rte_always_inline uint8_t
7604 : : mlx5_flow_l3_next_protocol(const struct rte_flow_item *l3_item,
7605 : : enum MLX5_SET_MATCHER key_type)
7606 : : {
7607 : : #define MLX5_L3_NEXT_PROTOCOL(i, ms) \
7608 : : ((i)->type == RTE_FLOW_ITEM_TYPE_IPV4 ? \
7609 : : ((const struct rte_flow_item_ipv4 *)(i)->ms)->hdr.next_proto_id : \
7610 : : (i)->type == RTE_FLOW_ITEM_TYPE_IPV6 ? \
7611 : : ((const struct rte_flow_item_ipv6 *)(i)->ms)->hdr.proto : \
7612 : : (i)->type == RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT ? \
7613 : : ((const struct rte_flow_item_ipv6_frag_ext *)(i)->ms)->hdr.next_header :\
7614 : : 0xff)
7615 : :
7616 : : uint8_t next_protocol;
7617 : :
7618 [ # # # # : 0 : if (l3_item->mask != NULL && l3_item->spec != NULL) {
# # # # #
# # # # #
# # # # #
# # # ]
7619 [ # # # # : 0 : next_protocol = MLX5_L3_NEXT_PROTOCOL(l3_item, mask);
# # # # #
# # # ]
7620 [ # # # # : 0 : if (next_protocol)
# # # # #
# # # ]
7621 [ # # # # : 0 : next_protocol &= MLX5_L3_NEXT_PROTOCOL(l3_item, spec);
# # # # #
# # # ]
7622 : : else
7623 : : next_protocol = 0xff;
7624 [ # # # # : 0 : } else if (key_type == MLX5_SET_MATCHER_HS_M && l3_item->mask != NULL) {
# # # # #
# # # ]
7625 [ # # # # : 0 : next_protocol = MLX5_L3_NEXT_PROTOCOL(l3_item, mask);
# # ]
7626 [ # # # # : 0 : } else if (key_type == MLX5_SET_MATCHER_HS_V && l3_item->spec != NULL) {
# # # # #
# # # ]
7627 [ # # # # : 0 : next_protocol = MLX5_L3_NEXT_PROTOCOL(l3_item, spec);
# # ]
7628 : : } else {
7629 : : /* Reset for inner layer. */
7630 : : next_protocol = 0xff;
7631 : : }
7632 : : return next_protocol;
7633 : :
7634 : : #undef MLX5_L3_NEXT_PROTOCOL
7635 : : }
7636 : :
7637 : : /**
7638 : : * Validate IB BTH item.
7639 : : *
7640 : : * @param[in] dev
7641 : : * Pointer to the rte_eth_dev structure.
7642 : : * @param[in] udp_dport
7643 : : * UDP destination port
7644 : : * @param[in] item
7645 : : * Item specification.
7646 : : * @param root
7647 : : * Whether action is on root table.
7648 : : * @param[out] error
7649 : : * Pointer to the error structure.
7650 : : *
7651 : : * @return
7652 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
7653 : : */
7654 : : static int
7655 : 0 : mlx5_flow_validate_item_ib_bth(struct rte_eth_dev *dev,
7656 : : uint16_t udp_dport,
7657 : : const struct rte_flow_item *item,
7658 : : bool root,
7659 : : struct rte_flow_error *error)
7660 : : {
7661 : 0 : const struct rte_flow_item_ib_bth *mask = item->mask;
7662 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7663 : : const struct rte_flow_item_ib_bth *valid_mask;
7664 : : int ret;
7665 : :
7666 : : valid_mask = &rte_flow_item_ib_bth_mask;
7667 [ # # ]: 0 : if (udp_dport && udp_dport != MLX5_UDP_PORT_ROCEv2)
7668 : 0 : return rte_flow_error_set(error, EINVAL,
7669 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
7670 : : "protocol filtering not compatible"
7671 : : " with UDP layer");
7672 [ # # # # ]: 0 : if (mask && (mask->hdr.se || mask->hdr.m || mask->hdr.padcnt ||
7673 [ # # # # ]: 0 : mask->hdr.tver || mask->hdr.pkey || mask->hdr.f || mask->hdr.b ||
7674 [ # # ]: 0 : mask->hdr.rsvd0 || mask->hdr.a || mask->hdr.rsvd1 ||
7675 [ # # # # : 0 : mask->hdr.psn[0] || mask->hdr.psn[1] || mask->hdr.psn[2]))
# # ]
7676 : 0 : return rte_flow_error_set(error, EINVAL,
7677 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
7678 : : "only opcode and dst_qp are supported");
7679 [ # # # # ]: 0 : if (root || priv->sh->steering_format_version ==
7680 : : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5)
7681 : 0 : return rte_flow_error_set(error, EINVAL,
7682 : : RTE_FLOW_ERROR_TYPE_ITEM,
7683 : : item,
7684 : : "IB BTH item is not supported");
7685 [ # # ]: 0 : if (!mask)
7686 : : mask = &rte_flow_item_ib_bth_mask;
7687 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
7688 : : (const uint8_t *)valid_mask,
7689 : : sizeof(struct rte_flow_item_ib_bth),
7690 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
7691 : : if (ret < 0)
7692 : : return ret;
7693 : : return 0;
7694 : : }
7695 : :
7696 : : const struct rte_flow_item_ipv4 nic_ipv4_mask = {
7697 : : .hdr = {
7698 : : .src_addr = RTE_BE32(0xffffffff),
7699 : : .dst_addr = RTE_BE32(0xffffffff),
7700 : : .type_of_service = 0xff,
7701 : : .fragment_offset = RTE_BE16(0xffff),
7702 : : .next_proto_id = 0xff,
7703 : : .time_to_live = 0xff,
7704 : : },
7705 : : };
7706 : :
7707 : : const struct rte_flow_item_ipv6 nic_ipv6_mask = {
7708 : : .hdr = {
7709 : : .src_addr = RTE_IPV6_MASK_FULL,
7710 : : .dst_addr = RTE_IPV6_MASK_FULL,
7711 : : .vtc_flow = RTE_BE32(0xffffffff),
7712 : : .proto = 0xff,
7713 : : .hop_limits = 0xff,
7714 : : },
7715 : : .has_frag_ext = 1,
7716 : : };
7717 : :
7718 : : const struct rte_flow_item_tcp nic_tcp_mask = {
7719 : : .hdr = {
7720 : : .tcp_flags = 0xFF,
7721 : : .src_port = RTE_BE16(UINT16_MAX),
7722 : : .dst_port = RTE_BE16(UINT16_MAX),
7723 : : }
7724 : : };
7725 : :
7726 : : /**
7727 : : * Internal validation function. For validating both actions and items.
7728 : : *
7729 : : * @param[in] dev
7730 : : * Pointer to the rte_eth_dev structure.
7731 : : * @param[in] attr
7732 : : * Pointer to the flow attributes.
7733 : : * @param[in] items
7734 : : * Pointer to the list of items.
7735 : : * @param[in] actions
7736 : : * Pointer to the list of actions.
7737 : : * @param[in] external
7738 : : * This flow rule is created by request external to PMD.
7739 : : * @param[in] hairpin
7740 : : * Number of hairpin TX actions, 0 means classic flow.
7741 : : * @param[out] error
7742 : : * Pointer to the error structure.
7743 : : *
7744 : : * @return
7745 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
7746 : : */
7747 : : int
7748 : 0 : flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
7749 : : const struct rte_flow_item items[],
7750 : : const struct rte_flow_action actions[],
7751 : : bool external, int hairpin, struct rte_flow_error *error)
7752 : : {
7753 : : int ret;
7754 : 0 : uint64_t aso_mask, action_flags = 0;
7755 : 0 : uint64_t item_flags = 0;
7756 : 0 : uint64_t last_item = 0;
7757 : : uint8_t next_protocol = 0xff;
7758 : : uint16_t ether_type = 0;
7759 : 0 : int actions_n = 0;
7760 : : uint8_t item_ipv6_proto = 0;
7761 : 0 : int fdb_mirror = 0;
7762 : : int modify_after_mirror = 0;
7763 : : const struct rte_flow_item *geneve_item = NULL;
7764 : : const struct rte_flow_item *gre_item = NULL;
7765 : : const struct rte_flow_item *gtp_item = NULL;
7766 : : const struct rte_flow_action_raw_decap *decap;
7767 : : const struct rte_flow_action_raw_encap *encap;
7768 : : const struct rte_flow_action_rss *rss = NULL;
7769 : 0 : const struct rte_flow_action_rss *sample_rss = NULL;
7770 : 0 : const struct rte_flow_action_count *sample_count = NULL;
7771 : 0 : const struct rte_flow_item_ecpri nic_ecpri_mask = {
7772 : : .hdr = {
7773 : : .common = {
7774 : : .u32 =
7775 : : RTE_BE32(((const struct rte_ecpri_common_hdr) {
7776 : : .type = 0xFF,
7777 : : }).u32),
7778 : : },
7779 : : .dummy[0] = 0xffffffff,
7780 : : },
7781 : : };
7782 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7783 : 0 : struct mlx5_sh_config *dev_conf = &priv->sh->config;
7784 : : uint16_t queue_index = 0xFFFF;
7785 : : const struct rte_flow_item_vlan *vlan_m = NULL;
7786 : : uint32_t rw_act_num = 0;
7787 : : uint64_t is_root;
7788 : : const struct mlx5_flow_tunnel *tunnel;
7789 : : enum mlx5_tof_rule_type tof_rule_type;
7790 : 0 : struct flow_grp_info grp_info = {
7791 : : .external = !!external,
7792 : 0 : .transfer = !!attr->transfer,
7793 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
7794 : : .std_tbl_fix = true,
7795 : : };
7796 : : const struct rte_eth_hairpin_conf *conf;
7797 : 0 : const struct rte_flow_item *integrity_items[2] = {NULL, NULL};
7798 : : const struct rte_flow_item *port_id_item = NULL;
7799 : 0 : bool def_policy = false;
7800 : : bool shared_count = false;
7801 : : uint16_t udp_dport = 0;
7802 : 0 : uint32_t tag_id = 0, tag_bitmap = 0;
7803 : : const struct rte_flow_action_age *non_shared_age = NULL;
7804 : : const struct rte_flow_action_count *count = NULL;
7805 : : const struct rte_flow_action_port_id *port = NULL;
7806 : : const struct mlx5_rte_flow_item_tag *mlx5_tag;
7807 : 0 : struct mlx5_priv *act_priv = NULL;
7808 : : int aso_after_sample = 0;
7809 : : struct mlx5_priv *port_priv = NULL;
7810 : 0 : uint64_t sub_action_flags = 0;
7811 : 0 : uint16_t sample_port_id = 0;
7812 : : uint16_t port_id = 0;
7813 : :
7814 [ # # ]: 0 : if (items == NULL)
7815 : : return -1;
7816 : : tunnel = is_tunnel_offload_active(dev) ?
7817 [ # # ]: 0 : mlx5_get_tof(items, actions, &tof_rule_type) : NULL;
7818 [ # # ]: 0 : if (tunnel) {
7819 [ # # ]: 0 : if (!dev_conf->dv_flow_en)
7820 : 0 : return rte_flow_error_set
7821 : : (error, ENOTSUP,
7822 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7823 : : NULL, "tunnel offload requires DV flow interface");
7824 [ # # ]: 0 : if (priv->representor)
7825 : 0 : return rte_flow_error_set
7826 : : (error, ENOTSUP,
7827 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7828 : : NULL, "decap not supported for VF representor");
7829 [ # # ]: 0 : if (tof_rule_type == MLX5_TUNNEL_OFFLOAD_SET_RULE)
7830 : 0 : action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
7831 [ # # ]: 0 : else if (tof_rule_type == MLX5_TUNNEL_OFFLOAD_MATCH_RULE)
7832 : 0 : action_flags |= MLX5_FLOW_ACTION_TUNNEL_MATCH |
7833 : : MLX5_FLOW_ACTION_DECAP;
7834 : 0 : grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
7835 : : (dev, attr, tunnel, tof_rule_type);
7836 : : }
7837 : 0 : ret = flow_dv_validate_attributes(dev, tunnel, attr, &grp_info, error);
7838 [ # # ]: 0 : if (ret < 0)
7839 : : return ret;
7840 : 0 : is_root = (uint64_t)ret;
7841 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
7842 : : enum mlx5_l3_tunnel_detection l3_tunnel_detection;
7843 : : uint64_t l3_tunnel_flag;
7844 : 0 : int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
7845 : 0 : int type = items->type;
7846 : :
7847 : : if (!mlx5_flow_os_item_supported(type))
7848 : : return rte_flow_error_set(error, ENOTSUP,
7849 : : RTE_FLOW_ERROR_TYPE_ITEM,
7850 : : NULL, "item not supported");
7851 [ # # # # : 0 : switch (type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # #
# ]
7852 : : case RTE_FLOW_ITEM_TYPE_VOID:
7853 : : break;
7854 : 0 : case RTE_FLOW_ITEM_TYPE_ESP:
7855 : 0 : ret = mlx5_flow_os_validate_item_esp(dev, items,
7856 : : item_flags,
7857 : : next_protocol,
7858 : : error);
7859 [ # # ]: 0 : if (ret < 0)
7860 : 0 : return ret;
7861 : 0 : last_item = MLX5_FLOW_ITEM_ESP;
7862 : 0 : break;
7863 : 0 : case RTE_FLOW_ITEM_TYPE_PORT_ID:
7864 : 0 : ret = flow_dv_validate_item_port_id
7865 : : (dev, items, attr, item_flags, &act_priv, error);
7866 [ # # ]: 0 : if (ret < 0)
7867 : 0 : return ret;
7868 : 0 : last_item = MLX5_FLOW_ITEM_PORT_ID;
7869 : : port_id_item = items;
7870 : 0 : break;
7871 : 0 : case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
7872 : : case RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR:
7873 : 0 : ret = flow_dv_validate_item_represented_port
7874 : : (dev, items, attr, item_flags, &act_priv, error);
7875 [ # # ]: 0 : if (ret < 0)
7876 : 0 : return ret;
7877 : 0 : last_item = MLX5_FLOW_ITEM_REPRESENTED_PORT;
7878 : : port_id_item = items;
7879 : 0 : break;
7880 : 0 : case RTE_FLOW_ITEM_TYPE_ETH:
7881 : 0 : ret = mlx5_flow_validate_item_eth(dev, items, item_flags,
7882 : : true, error);
7883 [ # # ]: 0 : if (ret < 0)
7884 : 0 : return ret;
7885 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
7886 : : MLX5_FLOW_LAYER_OUTER_L2;
7887 [ # # # # ]: 0 : if (items->mask != NULL && items->spec != NULL) {
7888 : 0 : ether_type =
7889 : : ((const struct rte_flow_item_eth *)
7890 : : items->spec)->hdr.ether_type;
7891 : 0 : ether_type &=
7892 : : ((const struct rte_flow_item_eth *)
7893 : 0 : items->mask)->hdr.ether_type;
7894 [ # # ]: 0 : ether_type = rte_be_to_cpu_16(ether_type);
7895 : : } else {
7896 : : ether_type = 0;
7897 : : }
7898 : : break;
7899 : 0 : case RTE_FLOW_ITEM_TYPE_VLAN:
7900 : 0 : ret = mlx5_flow_dv_validate_item_vlan(items, item_flags,
7901 : : dev, error);
7902 [ # # ]: 0 : if (ret < 0)
7903 : 0 : return ret;
7904 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
7905 : : MLX5_FLOW_LAYER_OUTER_VLAN;
7906 [ # # # # ]: 0 : if (items->mask != NULL && items->spec != NULL) {
7907 : 0 : ether_type =
7908 : : ((const struct rte_flow_item_vlan *)
7909 : : items->spec)->hdr.eth_proto;
7910 : 0 : ether_type &=
7911 : : ((const struct rte_flow_item_vlan *)
7912 : 0 : items->mask)->hdr.eth_proto;
7913 [ # # ]: 0 : ether_type = rte_be_to_cpu_16(ether_type);
7914 : : } else {
7915 : : ether_type = 0;
7916 : : }
7917 : : /* Store outer VLAN mask for of_push_vlan action. */
7918 [ # # ]: 0 : if (!tunnel)
7919 : : vlan_m = items->mask;
7920 : : break;
7921 : : case RTE_FLOW_ITEM_TYPE_IPV4:
7922 : : next_protocol = mlx5_flow_l3_next_protocol
7923 : : (items, (enum MLX5_SET_MATCHER)-1);
7924 : : l3_tunnel_detection =
7925 : : mlx5_flow_tunnel_ip_check(items, next_protocol,
7926 : : item_flags,
7927 : : &l3_tunnel_flag);
7928 : : if (l3_tunnel_detection == l3_tunnel_inner) {
7929 : 0 : item_flags |= l3_tunnel_flag;
7930 : : tunnel = 1;
7931 : : }
7932 : 0 : ret = mlx5_flow_dv_validate_item_ipv4(dev, items,
7933 : : item_flags,
7934 : : last_item,
7935 : : ether_type,
7936 : : &nic_ipv4_mask,
7937 : : error);
7938 [ # # ]: 0 : if (ret < 0)
7939 : 0 : return ret;
7940 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
7941 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4;
7942 [ # # ]: 0 : if (l3_tunnel_detection == l3_tunnel_outer)
7943 : 0 : item_flags |= l3_tunnel_flag;
7944 : : break;
7945 : : case RTE_FLOW_ITEM_TYPE_IPV6:
7946 : : next_protocol = mlx5_flow_l3_next_protocol
7947 : : (items, (enum MLX5_SET_MATCHER)-1);
7948 : : l3_tunnel_detection =
7949 : : mlx5_flow_tunnel_ip_check(items, next_protocol,
7950 : : item_flags,
7951 : : &l3_tunnel_flag);
7952 : : if (l3_tunnel_detection == l3_tunnel_inner) {
7953 : 0 : item_flags |= l3_tunnel_flag;
7954 : : tunnel = 1;
7955 : : }
7956 : 0 : ret = mlx5_flow_validate_item_ipv6(dev, items,
7957 : : item_flags,
7958 : : last_item,
7959 : : ether_type,
7960 : : &nic_ipv6_mask,
7961 : : error);
7962 [ # # ]: 0 : if (ret < 0)
7963 : 0 : return ret;
7964 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
7965 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6;
7966 [ # # ]: 0 : if (l3_tunnel_detection == l3_tunnel_outer)
7967 : 0 : item_flags |= l3_tunnel_flag;
7968 : : break;
7969 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
7970 : 0 : ret = flow_dv_validate_item_ipv6_frag_ext(dev, items,
7971 : : item_flags,
7972 : : error);
7973 [ # # ]: 0 : if (ret < 0)
7974 : 0 : return ret;
7975 [ # # ]: 0 : last_item = tunnel ?
7976 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
7977 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
7978 : : next_protocol = mlx5_flow_l3_next_protocol
7979 : : (items, (enum MLX5_SET_MATCHER)-1);
7980 : : break;
7981 : 0 : case RTE_FLOW_ITEM_TYPE_TCP:
7982 : 0 : ret = mlx5_flow_validate_item_tcp
7983 : : (dev, items, item_flags,
7984 : : next_protocol,
7985 : : &nic_tcp_mask,
7986 : : error);
7987 [ # # ]: 0 : if (ret < 0)
7988 : 0 : return ret;
7989 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
7990 : : MLX5_FLOW_LAYER_OUTER_L4_TCP;
7991 : 0 : break;
7992 : 0 : case RTE_FLOW_ITEM_TYPE_UDP:
7993 : 0 : ret = mlx5_flow_validate_item_udp(dev, items, item_flags,
7994 : : next_protocol,
7995 : : error);
7996 : 0 : const struct rte_flow_item_udp *spec = items->spec;
7997 : 0 : const struct rte_flow_item_udp *mask = items->mask;
7998 [ # # ]: 0 : if (!mask)
7999 : : mask = &rte_flow_item_udp_mask;
8000 [ # # ]: 0 : if (spec != NULL)
8001 [ # # ]: 0 : udp_dport = rte_be_to_cpu_16
8002 : : (spec->hdr.dst_port &
8003 : : mask->hdr.dst_port);
8004 [ # # ]: 0 : if (ret < 0)
8005 : 0 : return ret;
8006 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
8007 : : MLX5_FLOW_LAYER_OUTER_L4_UDP;
8008 : 0 : break;
8009 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
8010 : 0 : ret = mlx5_flow_validate_item_gre(dev, items, item_flags,
8011 : : next_protocol, error);
8012 [ # # ]: 0 : if (ret < 0)
8013 : 0 : return ret;
8014 : : gre_item = items;
8015 : 0 : last_item = MLX5_FLOW_LAYER_GRE;
8016 : 0 : break;
8017 : 0 : case RTE_FLOW_ITEM_TYPE_GRE_OPTION:
8018 : 0 : ret = mlx5_flow_validate_item_gre_option(dev, items, item_flags,
8019 : : attr, gre_item, error);
8020 [ # # ]: 0 : if (ret < 0)
8021 : 0 : return ret;
8022 : 0 : last_item = MLX5_FLOW_LAYER_GRE;
8023 : 0 : break;
8024 : 0 : case RTE_FLOW_ITEM_TYPE_NVGRE:
8025 : 0 : ret = mlx5_flow_validate_item_nvgre(dev, items,
8026 : : item_flags,
8027 : : next_protocol,
8028 : : error);
8029 [ # # ]: 0 : if (ret < 0)
8030 : 0 : return ret;
8031 : 0 : last_item = MLX5_FLOW_LAYER_NVGRE;
8032 : 0 : break;
8033 : 0 : case RTE_FLOW_ITEM_TYPE_GRE_KEY:
8034 : 0 : ret = mlx5_flow_validate_item_gre_key
8035 : : (dev, items, item_flags, gre_item, error);
8036 [ # # ]: 0 : if (ret < 0)
8037 : 0 : return ret;
8038 : 0 : last_item = MLX5_FLOW_LAYER_GRE_KEY;
8039 : 0 : break;
8040 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN:
8041 : 0 : ret = mlx5_flow_validate_item_vxlan(dev, udp_dport,
8042 : : items, item_flags,
8043 : : is_root, error);
8044 [ # # ]: 0 : if (ret < 0)
8045 : 0 : return ret;
8046 : 0 : last_item = MLX5_FLOW_LAYER_VXLAN;
8047 : 0 : break;
8048 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
8049 : 0 : ret = mlx5_flow_validate_item_vxlan_gpe(items,
8050 : : item_flags, dev,
8051 : : error);
8052 [ # # ]: 0 : if (ret < 0)
8053 : 0 : return ret;
8054 : 0 : last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
8055 : 0 : break;
8056 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE:
8057 : 0 : ret = mlx5_flow_validate_item_geneve(items,
8058 : : item_flags, dev,
8059 : : error);
8060 [ # # ]: 0 : if (ret < 0)
8061 : 0 : return ret;
8062 : : geneve_item = items;
8063 : 0 : last_item = MLX5_FLOW_LAYER_GENEVE;
8064 : 0 : break;
8065 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
8066 : 0 : ret = mlx5_flow_validate_item_geneve_opt(items,
8067 : : last_item,
8068 : : geneve_item,
8069 : : dev,
8070 : : error);
8071 [ # # ]: 0 : if (ret < 0)
8072 : 0 : return ret;
8073 : 0 : last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
8074 : 0 : break;
8075 : 0 : case RTE_FLOW_ITEM_TYPE_MPLS:
8076 : 0 : ret = mlx5_flow_validate_item_mpls(dev, items,
8077 : : item_flags,
8078 : : last_item, error);
8079 [ # # ]: 0 : if (ret < 0)
8080 : 0 : return ret;
8081 : 0 : last_item = MLX5_FLOW_LAYER_MPLS;
8082 : 0 : break;
8083 : :
8084 : 0 : case RTE_FLOW_ITEM_TYPE_MARK:
8085 : 0 : ret = flow_dv_validate_item_mark(dev, items, attr,
8086 : : error);
8087 [ # # ]: 0 : if (ret < 0)
8088 : 0 : return ret;
8089 : 0 : last_item = MLX5_FLOW_ITEM_MARK;
8090 : 0 : break;
8091 : 0 : case RTE_FLOW_ITEM_TYPE_META:
8092 : 0 : ret = flow_dv_validate_item_meta(dev, items, attr,
8093 : : error);
8094 [ # # ]: 0 : if (ret < 0)
8095 : 0 : return ret;
8096 : 0 : last_item = MLX5_FLOW_ITEM_METADATA;
8097 : 0 : break;
8098 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP:
8099 : 0 : ret = mlx5_flow_validate_item_icmp(dev, items, item_flags,
8100 : : next_protocol,
8101 : : error);
8102 [ # # ]: 0 : if (ret < 0)
8103 : 0 : return ret;
8104 : 0 : last_item = MLX5_FLOW_LAYER_ICMP;
8105 : 0 : break;
8106 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6:
8107 : 0 : ret = mlx5_flow_validate_item_icmp6(dev, items, item_flags,
8108 : : next_protocol,
8109 : : error);
8110 [ # # ]: 0 : if (ret < 0)
8111 : 0 : return ret;
8112 : : item_ipv6_proto = IPPROTO_ICMPV6;
8113 : 0 : last_item = MLX5_FLOW_LAYER_ICMP6;
8114 : 0 : break;
8115 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REQUEST:
8116 : : case RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REPLY:
8117 : 0 : ret = mlx5_flow_validate_item_icmp6_echo(dev, items,
8118 : : item_flags,
8119 : : next_protocol,
8120 : : error);
8121 [ # # ]: 0 : if (ret < 0)
8122 : 0 : return ret;
8123 : : item_ipv6_proto = IPPROTO_ICMPV6;
8124 : 0 : last_item = MLX5_FLOW_LAYER_ICMP6;
8125 : 0 : break;
8126 : 0 : case RTE_FLOW_ITEM_TYPE_TAG:
8127 : 0 : ret = flow_dv_validate_item_tag(dev, items, &tag_bitmap,
8128 : : attr, error);
8129 [ # # ]: 0 : if (ret < 0)
8130 : 0 : return ret;
8131 : 0 : last_item = MLX5_FLOW_ITEM_TAG;
8132 : 0 : break;
8133 : 0 : case RTE_FLOW_ITEM_TYPE_TX_QUEUE:
8134 : : case MLX5_RTE_FLOW_ITEM_TYPE_SQ:
8135 : 0 : last_item = MLX5_FLOW_ITEM_SQ;
8136 : 0 : break;
8137 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
8138 : 0 : mlx5_tag = (const struct mlx5_rte_flow_item_tag *)items->spec;
8139 [ # # ]: 0 : if (tag_bitmap & (1 << mlx5_tag->id))
8140 : 0 : return rte_flow_error_set(error, EINVAL,
8141 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
8142 : : items->spec,
8143 : : "Duplicated tag index");
8144 : 0 : tag_bitmap |= 1 << mlx5_tag->id;
8145 : 0 : break;
8146 : 0 : case RTE_FLOW_ITEM_TYPE_GTP:
8147 : 0 : ret = mlx5_flow_dv_validate_item_gtp(dev, items,
8148 : : item_flags,
8149 : : error);
8150 [ # # ]: 0 : if (ret < 0)
8151 : 0 : return ret;
8152 : : gtp_item = items;
8153 : 0 : last_item = MLX5_FLOW_LAYER_GTP;
8154 : 0 : break;
8155 : 0 : case RTE_FLOW_ITEM_TYPE_GTP_PSC:
8156 : 0 : ret = mlx5_flow_dv_validate_item_gtp_psc(dev, items,
8157 : : last_item,
8158 : : gtp_item,
8159 : : is_root, error);
8160 [ # # ]: 0 : if (ret < 0)
8161 : 0 : return ret;
8162 : 0 : last_item = MLX5_FLOW_LAYER_GTP_PSC;
8163 : 0 : break;
8164 : 0 : case RTE_FLOW_ITEM_TYPE_ECPRI:
8165 : : /* Capacity will be checked in the translate stage. */
8166 : 0 : ret = mlx5_flow_validate_item_ecpri(dev, items,
8167 : : item_flags,
8168 : : last_item,
8169 : : ether_type,
8170 : : &nic_ecpri_mask,
8171 : : error);
8172 [ # # ]: 0 : if (ret < 0)
8173 : 0 : return ret;
8174 : 0 : last_item = MLX5_FLOW_LAYER_ECPRI;
8175 : 0 : break;
8176 : 0 : case RTE_FLOW_ITEM_TYPE_INTEGRITY:
8177 : 0 : ret = flow_dv_validate_item_integrity(dev, items,
8178 : : item_flags,
8179 : : &last_item,
8180 : : integrity_items,
8181 : : error);
8182 [ # # ]: 0 : if (ret < 0)
8183 : 0 : return ret;
8184 : : break;
8185 : 0 : case RTE_FLOW_ITEM_TYPE_CONNTRACK:
8186 : 0 : ret = mlx5_flow_dv_validate_item_aso_ct(dev, items,
8187 : : &item_flags,
8188 : : error);
8189 [ # # ]: 0 : if (ret < 0)
8190 : 0 : return ret;
8191 : 0 : last_item = MLX5_FLOW_LAYER_ASO_CT;
8192 : 0 : break;
8193 : : case MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL:
8194 : : /* tunnel offload item was processed before
8195 : : * list it here as a supported type
8196 : : */
8197 : : break;
8198 : 0 : case RTE_FLOW_ITEM_TYPE_FLEX:
8199 : 0 : ret = flow_dv_validate_item_flex(dev, items, item_flags,
8200 : : &last_item,
8201 : : tunnel != 0, error);
8202 [ # # ]: 0 : if (ret < 0)
8203 : 0 : return ret;
8204 : : /* Reset for next proto, it is unknown. */
8205 : : next_protocol = 0xff;
8206 : : break;
8207 : 0 : case RTE_FLOW_ITEM_TYPE_METER_COLOR:
8208 : 0 : ret = flow_dv_validate_item_meter_color(dev, items,
8209 : : attr, error);
8210 [ # # ]: 0 : if (ret < 0)
8211 : 0 : return ret;
8212 : 0 : last_item = MLX5_FLOW_ITEM_METER_COLOR;
8213 : 0 : break;
8214 : 0 : case RTE_FLOW_ITEM_TYPE_AGGR_AFFINITY:
8215 : 0 : ret = flow_dv_validate_item_aggr_affinity(dev, items,
8216 : : attr, error);
8217 [ # # ]: 0 : if (ret < 0)
8218 : 0 : return ret;
8219 : 0 : last_item = MLX5_FLOW_ITEM_AGGR_AFFINITY;
8220 : 0 : break;
8221 : 0 : case RTE_FLOW_ITEM_TYPE_IB_BTH:
8222 : 0 : ret = mlx5_flow_validate_item_ib_bth(dev, udp_dport,
8223 : : items, is_root, error);
8224 [ # # ]: 0 : if (ret < 0)
8225 : 0 : return ret;
8226 : :
8227 : 0 : last_item = MLX5_FLOW_ITEM_IB_BTH;
8228 : 0 : break;
8229 : 0 : case RTE_FLOW_ITEM_TYPE_NSH:
8230 : 0 : ret = mlx5_flow_validate_item_nsh(dev, items, error);
8231 [ # # ]: 0 : if (ret < 0)
8232 : 0 : return ret;
8233 : 0 : last_item = MLX5_FLOW_ITEM_NSH;
8234 : 0 : break;
8235 : 0 : default:
8236 : 0 : return rte_flow_error_set(error, ENOTSUP,
8237 : : RTE_FLOW_ERROR_TYPE_ITEM,
8238 : : NULL, "item not supported");
8239 : : }
8240 : 0 : item_flags |= last_item;
8241 : : }
8242 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_INTEGRITY) {
8243 : 0 : ret = flow_dv_validate_item_integrity_post(integrity_items,
8244 : : item_flags, error);
8245 [ # # ]: 0 : if (ret)
8246 : : return ret;
8247 : : }
8248 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
8249 : 0 : int type = actions->type;
8250 : :
8251 : : if (!mlx5_flow_os_action_supported(type))
8252 : : return rte_flow_error_set(error, ENOTSUP,
8253 : : RTE_FLOW_ERROR_TYPE_ACTION,
8254 : : actions,
8255 : : "action not supported");
8256 [ # # ]: 0 : if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
8257 : 0 : return rte_flow_error_set(error, ENOTSUP,
8258 : : RTE_FLOW_ERROR_TYPE_ACTION,
8259 : : actions, "too many actions");
8260 [ # # ]: 0 : if (action_flags &
8261 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
8262 : 0 : return rte_flow_error_set(error, ENOTSUP,
8263 : : RTE_FLOW_ERROR_TYPE_ACTION,
8264 : : NULL, "meter action with policy "
8265 : : "must be the last action");
8266 [ # # # # : 0 : switch (type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
8267 : : case RTE_FLOW_ACTION_TYPE_VOID:
8268 : : break;
8269 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
8270 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
8271 : 0 : ret = flow_dv_validate_action_port_id(dev,
8272 : : action_flags,
8273 : : actions,
8274 : : attr,
8275 : : error);
8276 [ # # ]: 0 : if (ret)
8277 : 0 : return ret;
8278 [ # # ]: 0 : if (type == RTE_FLOW_ACTION_TYPE_PORT_ID) {
8279 : 0 : port = (const struct rte_flow_action_port_id *)
8280 : : actions->conf;
8281 [ # # ]: 0 : port_id = port->original ? dev->data->port_id : port->id;
8282 : : } else {
8283 : 0 : port_id = ((const struct rte_flow_action_ethdev *)
8284 : 0 : actions->conf)->port_id;
8285 : : }
8286 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_ID;
8287 : 0 : ++actions_n;
8288 : 0 : break;
8289 : 0 : case RTE_FLOW_ACTION_TYPE_FLAG:
8290 : 0 : ret = flow_dv_validate_action_flag(dev, action_flags,
8291 : : attr, error);
8292 [ # # ]: 0 : if (ret < 0)
8293 : 0 : return ret;
8294 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
8295 : : /* Count all modify-header actions as one. */
8296 [ # # ]: 0 : if (!(action_flags &
8297 : : MLX5_FLOW_MODIFY_HDR_ACTIONS))
8298 : 0 : ++actions_n;
8299 : 0 : action_flags |= MLX5_FLOW_ACTION_FLAG |
8300 : : MLX5_FLOW_ACTION_MARK_EXT;
8301 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8302 : : modify_after_mirror = 1;
8303 : :
8304 : : } else {
8305 : 0 : action_flags |= MLX5_FLOW_ACTION_FLAG;
8306 : 0 : ++actions_n;
8307 : : }
8308 : 0 : rw_act_num += MLX5_ACT_NUM_SET_MARK;
8309 : 0 : break;
8310 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
8311 : 0 : ret = flow_dv_validate_action_mark(dev, actions,
8312 : : action_flags,
8313 : : attr, error);
8314 [ # # ]: 0 : if (ret < 0)
8315 : 0 : return ret;
8316 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
8317 : : /* Count all modify-header actions as one. */
8318 [ # # ]: 0 : if (!(action_flags &
8319 : : MLX5_FLOW_MODIFY_HDR_ACTIONS))
8320 : 0 : ++actions_n;
8321 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK |
8322 : : MLX5_FLOW_ACTION_MARK_EXT;
8323 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8324 : : modify_after_mirror = 1;
8325 : : } else {
8326 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK;
8327 : 0 : ++actions_n;
8328 : : }
8329 : 0 : rw_act_num += MLX5_ACT_NUM_SET_MARK;
8330 : 0 : break;
8331 : 0 : case RTE_FLOW_ACTION_TYPE_SET_META:
8332 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
8333 : 0 : return rte_flow_error_set(error, ENOTSUP,
8334 : : RTE_FLOW_ERROR_TYPE_ACTION,
8335 : : actions,
8336 : : "action not supported");
8337 : 0 : ret = flow_dv_validate_action_set_meta(dev, actions,
8338 : : action_flags,
8339 : : attr, error);
8340 [ # # ]: 0 : if (ret < 0)
8341 : 0 : return ret;
8342 : : /* Count all modify-header actions as one action. */
8343 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8344 : 0 : ++actions_n;
8345 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8346 : : modify_after_mirror = 1;
8347 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_META;
8348 : 0 : rw_act_num += MLX5_ACT_NUM_SET_META;
8349 : 0 : break;
8350 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TAG:
8351 : 0 : ret = flow_dv_validate_action_set_tag(dev, actions,
8352 : : action_flags,
8353 : : attr, error);
8354 [ # # ]: 0 : if (ret < 0)
8355 : 0 : return ret;
8356 : : /* Count all modify-header actions as one action. */
8357 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8358 : 0 : ++actions_n;
8359 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8360 : : modify_after_mirror = 1;
8361 : 0 : tag_id = ((const struct rte_flow_action_set_tag *)
8362 : 0 : actions->conf)->index;
8363 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
8364 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
8365 : 0 : break;
8366 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
8367 : 0 : ret = mlx5_flow_validate_action_drop(dev, is_root,
8368 : : attr, error);
8369 [ # # ]: 0 : if (ret < 0)
8370 : 0 : return ret;
8371 : 0 : action_flags |= MLX5_FLOW_ACTION_DROP;
8372 : 0 : ++actions_n;
8373 : 0 : break;
8374 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
8375 : 0 : ret = mlx5_flow_validate_action_queue(actions,
8376 : : action_flags, dev,
8377 : : attr, error);
8378 [ # # ]: 0 : if (ret < 0)
8379 : 0 : return ret;
8380 : 0 : queue_index = ((const struct rte_flow_action_queue *)
8381 : 0 : (actions->conf))->index;
8382 : 0 : action_flags |= MLX5_FLOW_ACTION_QUEUE;
8383 : 0 : ++actions_n;
8384 : 0 : break;
8385 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
8386 : 0 : rss = actions->conf;
8387 : 0 : ret = mlx5_flow_validate_action_rss(actions,
8388 : : action_flags, dev,
8389 : : attr, item_flags,
8390 : : error);
8391 [ # # ]: 0 : if (ret < 0)
8392 : 0 : return ret;
8393 [ # # ]: 0 : if (rss && sample_rss &&
8394 [ # # ]: 0 : (sample_rss->level != rss->level ||
8395 [ # # ]: 0 : sample_rss->types != rss->types))
8396 : 0 : return rte_flow_error_set(error, ENOTSUP,
8397 : : RTE_FLOW_ERROR_TYPE_ACTION,
8398 : : NULL,
8399 : : "Can't use the different RSS types "
8400 : : "or level in the same flow");
8401 [ # # # # ]: 0 : if (rss != NULL && rss->queue_num)
8402 : 0 : queue_index = rss->queue[0];
8403 : 0 : action_flags |= MLX5_FLOW_ACTION_RSS;
8404 : 0 : ++actions_n;
8405 : 0 : break;
8406 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
8407 : : ret =
8408 : 0 : mlx5_flow_validate_action_default_miss(action_flags,
8409 : : attr, error);
8410 [ # # ]: 0 : if (ret < 0)
8411 : 0 : return ret;
8412 : 0 : action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
8413 : 0 : ++actions_n;
8414 : 0 : break;
8415 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
8416 : : shared_count = true;
8417 : : /* fall-through. */
8418 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
8419 : 0 : ret = flow_dv_validate_action_count(dev, shared_count,
8420 : : action_flags,
8421 : : is_root, error);
8422 [ # # ]: 0 : if (ret < 0)
8423 : 0 : return ret;
8424 : 0 : count = actions->conf;
8425 : 0 : action_flags |= MLX5_FLOW_ACTION_COUNT;
8426 : 0 : ++actions_n;
8427 : 0 : break;
8428 : 0 : case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
8429 [ # # ]: 0 : if (flow_dv_validate_action_pop_vlan(dev,
8430 : : action_flags,
8431 : : actions,
8432 : : item_flags, attr,
8433 : : error))
8434 : 0 : return -rte_errno;
8435 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8436 : : modify_after_mirror = 1;
8437 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
8438 : 0 : ++actions_n;
8439 : 0 : break;
8440 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
8441 : 0 : ret = flow_dv_validate_action_push_vlan(dev,
8442 : : action_flags,
8443 : : vlan_m,
8444 : : actions, attr,
8445 : : error);
8446 [ # # ]: 0 : if (ret < 0)
8447 : 0 : return ret;
8448 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8449 : : modify_after_mirror = 1;
8450 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
8451 : 0 : ++actions_n;
8452 : 0 : break;
8453 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
8454 : 0 : ret = flow_dv_validate_action_set_vlan_pcp
8455 : : (action_flags, actions, error);
8456 [ # # ]: 0 : if (ret < 0)
8457 : 0 : return ret;
8458 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8459 : : modify_after_mirror = 1;
8460 : : /* Count PCP with push_vlan command. */
8461 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_PCP;
8462 : 0 : break;
8463 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
8464 : 0 : ret = flow_dv_validate_action_set_vlan_vid
8465 : : (item_flags, action_flags,
8466 : : actions, error);
8467 [ # # ]: 0 : if (ret < 0)
8468 : 0 : return ret;
8469 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8470 : : modify_after_mirror = 1;
8471 : : /* Count VID with push_vlan command. */
8472 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
8473 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_VID;
8474 : 0 : break;
8475 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
8476 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
8477 : 0 : ret = mlx5_flow_dv_validate_action_l2_encap(dev,
8478 : : action_flags,
8479 : : actions,
8480 : : attr,
8481 : : error);
8482 [ # # ]: 0 : if (ret < 0)
8483 : 0 : return ret;
8484 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
8485 : 0 : ++actions_n;
8486 : 0 : break;
8487 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
8488 : : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
8489 : 0 : ret = mlx5_flow_dv_validate_action_decap(dev,
8490 : : action_flags,
8491 : : actions,
8492 : : item_flags,
8493 : : attr, error);
8494 [ # # ]: 0 : if (ret < 0)
8495 : 0 : return ret;
8496 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8497 : : modify_after_mirror = 1;
8498 : 0 : action_flags |= MLX5_FLOW_ACTION_DECAP;
8499 : 0 : ++actions_n;
8500 : 0 : break;
8501 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
8502 : 0 : ret = mlx5_flow_dv_validate_action_raw_encap_decap
8503 : 0 : (dev, NULL, actions->conf, attr, &action_flags,
8504 : : &actions_n, actions, item_flags, error);
8505 [ # # ]: 0 : if (ret < 0)
8506 : 0 : return ret;
8507 : : break;
8508 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
8509 : 0 : decap = actions->conf;
8510 [ # # ]: 0 : while ((++actions)->type == RTE_FLOW_ACTION_TYPE_VOID)
8511 : : ;
8512 [ # # ]: 0 : if (actions->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
8513 : : encap = NULL;
8514 : : actions--;
8515 : : } else {
8516 : 0 : encap = actions->conf;
8517 : : }
8518 [ # # ]: 0 : ret = mlx5_flow_dv_validate_action_raw_encap_decap
8519 : : (dev,
8520 : : decap ? decap : &empty_decap, encap,
8521 : : attr, &action_flags, &actions_n,
8522 : : actions, item_flags, error);
8523 [ # # ]: 0 : if (ret < 0)
8524 : 0 : return ret;
8525 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_SAMPLE) &&
8526 : : (action_flags & MLX5_FLOW_ACTION_DECAP))
8527 : : modify_after_mirror = 1;
8528 : : break;
8529 : 0 : case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
8530 : : case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
8531 : 0 : ret = flow_dv_validate_action_modify_mac(action_flags,
8532 : : actions,
8533 : : item_flags,
8534 : : error);
8535 [ # # ]: 0 : if (ret < 0)
8536 : 0 : return ret;
8537 : : /* Count all modify-header actions as one action. */
8538 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8539 : 0 : ++actions_n;
8540 : 0 : action_flags |= actions->type ==
8541 : : RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
8542 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_MAC_SRC :
8543 : : MLX5_FLOW_ACTION_SET_MAC_DST;
8544 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8545 : : modify_after_mirror = 1;
8546 : : /*
8547 : : * Even if the source and destination MAC addresses have
8548 : : * overlap in the header with 4B alignment, the convert
8549 : : * function will handle them separately and 4 SW actions
8550 : : * will be created. And 2 actions will be added each
8551 : : * time no matter how many bytes of address will be set.
8552 : : */
8553 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_MAC;
8554 : 0 : break;
8555 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
8556 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
8557 : 0 : ret = flow_dv_validate_action_modify_ipv4(action_flags,
8558 : : actions,
8559 : : item_flags,
8560 : : error);
8561 [ # # ]: 0 : if (ret < 0)
8562 : 0 : return ret;
8563 : : /* Count all modify-header actions as one action. */
8564 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8565 : 0 : ++actions_n;
8566 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8567 : : modify_after_mirror = 1;
8568 : 0 : action_flags |= actions->type ==
8569 : : RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
8570 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_IPV4_SRC :
8571 : : MLX5_FLOW_ACTION_SET_IPV4_DST;
8572 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_IPV4;
8573 : 0 : break;
8574 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
8575 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
8576 : 0 : ret = flow_dv_validate_action_modify_ipv6(action_flags,
8577 : : actions,
8578 : : item_flags,
8579 : : error);
8580 [ # # ]: 0 : if (ret < 0)
8581 : 0 : return ret;
8582 [ # # ]: 0 : if (item_ipv6_proto == IPPROTO_ICMPV6)
8583 : 0 : return rte_flow_error_set(error, ENOTSUP,
8584 : : RTE_FLOW_ERROR_TYPE_ACTION,
8585 : : actions,
8586 : : "Can't change header "
8587 : : "with ICMPv6 proto");
8588 : : /* Count all modify-header actions as one action. */
8589 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8590 : 0 : ++actions_n;
8591 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8592 : : modify_after_mirror = 1;
8593 : 0 : action_flags |= actions->type ==
8594 : : RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
8595 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_IPV6_SRC :
8596 : : MLX5_FLOW_ACTION_SET_IPV6_DST;
8597 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_IPV6;
8598 : 0 : break;
8599 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
8600 : : case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
8601 : 0 : ret = flow_dv_validate_action_modify_tp(action_flags,
8602 : : actions,
8603 : : item_flags,
8604 : : error);
8605 [ # # ]: 0 : if (ret < 0)
8606 : 0 : return ret;
8607 : : /* Count all modify-header actions as one action. */
8608 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8609 : 0 : ++actions_n;
8610 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8611 : : modify_after_mirror = 1;
8612 : 0 : action_flags |= actions->type ==
8613 : : RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
8614 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_TP_SRC :
8615 : : MLX5_FLOW_ACTION_SET_TP_DST;
8616 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_PORT;
8617 : 0 : break;
8618 : 0 : case RTE_FLOW_ACTION_TYPE_DEC_TTL:
8619 : : case RTE_FLOW_ACTION_TYPE_SET_TTL:
8620 : 0 : ret = flow_dv_validate_action_modify_ttl(action_flags,
8621 : : actions,
8622 : : item_flags,
8623 : : error);
8624 [ # # ]: 0 : if (ret < 0)
8625 : 0 : return ret;
8626 : : /* Count all modify-header actions as one action. */
8627 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8628 : 0 : ++actions_n;
8629 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8630 : : modify_after_mirror = 1;
8631 : 0 : action_flags |= actions->type ==
8632 : : RTE_FLOW_ACTION_TYPE_SET_TTL ?
8633 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_TTL :
8634 : : MLX5_FLOW_ACTION_DEC_TTL;
8635 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_TTL;
8636 : 0 : break;
8637 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
8638 : 0 : ret = flow_dv_validate_action_jump(dev, tunnel, actions,
8639 : : action_flags,
8640 : : attr, external,
8641 : : error);
8642 [ # # ]: 0 : if (ret)
8643 : 0 : return ret;
8644 : 0 : ++actions_n;
8645 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP;
8646 : 0 : break;
8647 : 0 : case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
8648 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
8649 : 0 : ret = flow_dv_validate_action_modify_tcp_seq
8650 : : (action_flags,
8651 : : actions,
8652 : : item_flags,
8653 : : error);
8654 [ # # ]: 0 : if (ret < 0)
8655 : 0 : return ret;
8656 : : /* Count all modify-header actions as one action. */
8657 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8658 : 0 : ++actions_n;
8659 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8660 : : modify_after_mirror = 1;
8661 : 0 : action_flags |= actions->type ==
8662 : : RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
8663 [ # # ]: 0 : MLX5_FLOW_ACTION_INC_TCP_SEQ :
8664 : : MLX5_FLOW_ACTION_DEC_TCP_SEQ;
8665 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_TCPSEQ;
8666 : 0 : break;
8667 : 0 : case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
8668 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
8669 : 0 : ret = flow_dv_validate_action_modify_tcp_ack
8670 : : (action_flags,
8671 : : actions,
8672 : : item_flags,
8673 : : error);
8674 [ # # ]: 0 : if (ret < 0)
8675 : 0 : return ret;
8676 : : /* Count all modify-header actions as one action. */
8677 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8678 : 0 : ++actions_n;
8679 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8680 : : modify_after_mirror = 1;
8681 : 0 : action_flags |= actions->type ==
8682 : : RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
8683 [ # # ]: 0 : MLX5_FLOW_ACTION_INC_TCP_ACK :
8684 : : MLX5_FLOW_ACTION_DEC_TCP_ACK;
8685 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_TCPACK;
8686 : 0 : break;
8687 : : case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
8688 : : break;
8689 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
8690 : : case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
8691 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
8692 : 0 : break;
8693 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
8694 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
8695 : 0 : return rte_flow_error_set(error, ENOTSUP,
8696 : : RTE_FLOW_ERROR_TYPE_ACTION,
8697 : : actions,
8698 : : "action not supported");
8699 : 0 : ret = mlx5_flow_validate_action_meter(dev,
8700 : : action_flags,
8701 : : item_flags,
8702 : : actions, attr,
8703 : : port_id_item,
8704 : : &def_policy,
8705 : : error);
8706 [ # # ]: 0 : if (ret < 0)
8707 : 0 : return ret;
8708 : 0 : action_flags |= MLX5_FLOW_ACTION_METER;
8709 [ # # ]: 0 : if (!def_policy)
8710 : 0 : action_flags |=
8711 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
8712 : 0 : ++actions_n;
8713 : : /* Meter action will add one more TAG action. */
8714 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
8715 : 0 : break;
8716 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
8717 [ # # ]: 0 : if (is_root)
8718 : 0 : return rte_flow_error_set(error, ENOTSUP,
8719 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8720 : : NULL,
8721 : : "Shared ASO age action is not supported for group 0");
8722 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_AGE)
8723 : 0 : return rte_flow_error_set
8724 : : (error, EINVAL,
8725 : : RTE_FLOW_ERROR_TYPE_ACTION,
8726 : : NULL,
8727 : : "duplicate age actions set");
8728 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8729 : : aso_after_sample = 1;
8730 : 0 : action_flags |= MLX5_FLOW_ACTION_AGE;
8731 : 0 : ++actions_n;
8732 : 0 : break;
8733 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
8734 : 0 : non_shared_age = actions->conf;
8735 : 0 : ret = flow_dv_validate_action_age(action_flags,
8736 : : actions, dev,
8737 : : error);
8738 [ # # ]: 0 : if (ret < 0)
8739 : 0 : return ret;
8740 : : /*
8741 : : * Validate the regular AGE action (using counter)
8742 : : * mutual exclusion with indirect counter actions.
8743 : : */
8744 [ # # ]: 0 : if (!flow_hit_aso_supported(priv, is_root)) {
8745 [ # # ]: 0 : if (shared_count)
8746 : 0 : return rte_flow_error_set
8747 : : (error, EINVAL,
8748 : : RTE_FLOW_ERROR_TYPE_ACTION,
8749 : : NULL,
8750 : : "old age and indirect count combination is not supported");
8751 [ # # ]: 0 : if (sample_count)
8752 : 0 : return rte_flow_error_set
8753 : : (error, EINVAL,
8754 : : RTE_FLOW_ERROR_TYPE_ACTION,
8755 : : NULL,
8756 : : "old age action and count must be in the same sub flow");
8757 : : } else {
8758 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8759 : : aso_after_sample = 1;
8760 : : }
8761 : 0 : action_flags |= MLX5_FLOW_ACTION_AGE;
8762 : 0 : ++actions_n;
8763 : 0 : break;
8764 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
8765 : 0 : ret = flow_dv_validate_action_modify_ipv4_dscp
8766 : : (action_flags,
8767 : : actions,
8768 : : item_flags,
8769 : : error);
8770 [ # # ]: 0 : if (ret < 0)
8771 : 0 : return ret;
8772 : : /* Count all modify-header actions as one action. */
8773 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8774 : 0 : ++actions_n;
8775 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8776 : : modify_after_mirror = 1;
8777 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
8778 : 0 : rw_act_num += MLX5_ACT_NUM_SET_DSCP;
8779 : 0 : break;
8780 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
8781 : 0 : ret = flow_dv_validate_action_modify_ipv6_dscp
8782 : : (action_flags,
8783 : : actions,
8784 : : item_flags,
8785 : : error);
8786 [ # # ]: 0 : if (ret < 0)
8787 : 0 : return ret;
8788 : : /* Count all modify-header actions as one action. */
8789 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8790 : 0 : ++actions_n;
8791 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8792 : : modify_after_mirror = 1;
8793 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
8794 : 0 : rw_act_num += MLX5_ACT_NUM_SET_DSCP;
8795 : 0 : break;
8796 : 0 : case RTE_FLOW_ACTION_TYPE_SAMPLE:
8797 : 0 : ret = flow_dv_validate_action_sample(&action_flags,
8798 : : &sub_action_flags,
8799 : : actions, dev,
8800 : : attr, item_flags,
8801 : : rss, &sample_rss,
8802 : : &sample_count,
8803 : : &fdb_mirror,
8804 : : &sample_port_id,
8805 : : is_root,
8806 : : error);
8807 [ # # ]: 0 : if (ret < 0)
8808 : 0 : return ret;
8809 [ # # # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_SET_TAG) &&
8810 : 0 : tag_id == 0 &&
8811 [ # # ]: 0 : priv->sh->registers.aso_reg == REG_NON)
8812 : 0 : return rte_flow_error_set(error, EINVAL,
8813 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8814 : : "sample after tag action causes metadata tag index 0 corruption");
8815 : 0 : action_flags |= MLX5_FLOW_ACTION_SAMPLE;
8816 : 0 : ++actions_n;
8817 : 0 : break;
8818 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
8819 : 0 : ret = flow_dv_validate_action_modify_field(dev,
8820 : : action_flags,
8821 : : actions,
8822 : : attr,
8823 : : is_root,
8824 : : error);
8825 [ # # ]: 0 : if (ret < 0)
8826 : 0 : return ret;
8827 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8828 : : modify_after_mirror = 1;
8829 : : /* Count all modify-header actions as one action. */
8830 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8831 : 0 : ++actions_n;
8832 : 0 : action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
8833 : 0 : rw_act_num += ret;
8834 : 0 : break;
8835 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
8836 : 0 : ret = mlx5_flow_dv_validate_action_aso_ct(dev,
8837 : : action_flags,
8838 : : item_flags,
8839 : : is_root,
8840 : : error);
8841 [ # # ]: 0 : if (ret < 0)
8842 : 0 : return ret;
8843 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8844 : : aso_after_sample = 1;
8845 : 0 : action_flags |= MLX5_FLOW_ACTION_CT;
8846 : 0 : break;
8847 : : case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
8848 : : /* tunnel offload action was processed before
8849 : : * list it here as a supported type
8850 : : */
8851 : : break;
8852 : : #ifdef HAVE_MLX5DV_DR_ACTION_CREATE_DEST_ROOT_TABLE
8853 : : case RTE_FLOW_ACTION_TYPE_SEND_TO_KERNEL:
8854 : : action_flags |= MLX5_FLOW_ACTION_SEND_TO_KERNEL;
8855 : : ++actions_n;
8856 : : break;
8857 : : #endif
8858 : 0 : default:
8859 : 0 : return rte_flow_error_set(error, ENOTSUP,
8860 : : RTE_FLOW_ERROR_TYPE_ACTION,
8861 : : actions,
8862 : : "action not supported");
8863 : : }
8864 : : }
8865 : : /*
8866 : : * Validate actions in flow rules
8867 : : * - Explicit decap action is prohibited by the tunnel offload API.
8868 : : * - Drop action in tunnel steer rule is prohibited by the API.
8869 : : * - Application cannot use MARK action because it's value can mask
8870 : : * tunnel default miss notification.
8871 : : * - JUMP in tunnel match rule has no support in current PMD
8872 : : * implementation.
8873 : : * - TAG & META are reserved for future uses.
8874 : : */
8875 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_TUNNEL_SET) {
8876 : : uint64_t bad_actions_mask = MLX5_FLOW_ACTION_DECAP |
8877 : : MLX5_FLOW_ACTION_MARK |
8878 : : MLX5_FLOW_ACTION_SET_TAG |
8879 : : MLX5_FLOW_ACTION_SET_META |
8880 : : MLX5_FLOW_ACTION_DROP;
8881 : :
8882 [ # # ]: 0 : if (action_flags & bad_actions_mask)
8883 : 0 : return rte_flow_error_set
8884 : : (error, EINVAL,
8885 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8886 : : "Invalid RTE action in tunnel "
8887 : : "set decap rule");
8888 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_ACTION_JUMP))
8889 : 0 : return rte_flow_error_set
8890 : : (error, EINVAL,
8891 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8892 : : "tunnel set decap rule must terminate "
8893 : : "with JUMP");
8894 [ # # ]: 0 : if (attr->egress)
8895 : 0 : return rte_flow_error_set
8896 : : (error, EINVAL,
8897 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8898 : : "tunnel flows for ingress and transfer traffic only");
8899 : : }
8900 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_TUNNEL_MATCH) {
8901 : : uint64_t bad_actions_mask = MLX5_FLOW_ACTION_JUMP |
8902 : : MLX5_FLOW_ACTION_MARK |
8903 : : MLX5_FLOW_ACTION_SET_TAG |
8904 : : MLX5_FLOW_ACTION_SET_META;
8905 : :
8906 [ # # ]: 0 : if (action_flags & bad_actions_mask)
8907 : 0 : return rte_flow_error_set
8908 : : (error, EINVAL,
8909 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8910 : : "Invalid RTE action in tunnel "
8911 : : "set match rule");
8912 : : }
8913 : : /*
8914 : : * Validate the drop action mutual exclusion with other actions.
8915 : : * Drop action is mutually-exclusive with any other action, except for
8916 : : * Count/Sample/Age actions.
8917 : : * Drop action compatibility with tunnel offload was already validated.
8918 : : */
8919 [ # # ]: 0 : if (action_flags & (MLX5_FLOW_ACTION_TUNNEL_MATCH |
8920 : : MLX5_FLOW_ACTION_TUNNEL_MATCH));
8921 [ # # ]: 0 : else if ((action_flags & MLX5_FLOW_ACTION_DROP) &&
8922 [ # # ]: 0 : (action_flags & ~(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_DROP_INCLUSIVE_ACTIONS)))
8923 : 0 : return rte_flow_error_set(error, EINVAL,
8924 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8925 : : "Drop action is mutually-exclusive "
8926 : : "with any other action, except for "
8927 : : "Count/Sample/Age action");
8928 : : /* Eswitch has few restrictions on using items and actions */
8929 [ # # ]: 0 : if (attr->transfer) {
8930 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev) &&
8931 [ # # ]: 0 : action_flags & MLX5_FLOW_ACTION_FLAG)
8932 : 0 : return rte_flow_error_set(error, ENOTSUP,
8933 : : RTE_FLOW_ERROR_TYPE_ACTION,
8934 : : NULL,
8935 : : "unsupported action FLAG");
8936 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev) &&
8937 [ # # ]: 0 : action_flags & MLX5_FLOW_ACTION_MARK)
8938 : 0 : return rte_flow_error_set(error, ENOTSUP,
8939 : : RTE_FLOW_ERROR_TYPE_ACTION,
8940 : : NULL,
8941 : : "unsupported action MARK");
8942 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_QUEUE)
8943 : 0 : return rte_flow_error_set(error, ENOTSUP,
8944 : : RTE_FLOW_ERROR_TYPE_ACTION,
8945 : : NULL,
8946 : : "unsupported action QUEUE");
8947 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_RSS)
8948 : 0 : return rte_flow_error_set(error, ENOTSUP,
8949 : : RTE_FLOW_ERROR_TYPE_ACTION,
8950 : : NULL,
8951 : : "unsupported action RSS");
8952 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
8953 : 0 : return rte_flow_error_set(error, EINVAL,
8954 : : RTE_FLOW_ERROR_TYPE_ACTION,
8955 : : actions,
8956 : : "no fate action is found");
8957 : : } else {
8958 [ # # # # ]: 0 : if (!(action_flags & MLX5_FLOW_FATE_ACTIONS) && attr->ingress)
8959 : 0 : return rte_flow_error_set(error, EINVAL,
8960 : : RTE_FLOW_ERROR_TYPE_ACTION,
8961 : : actions,
8962 : : "no fate action is found");
8963 : : }
8964 : : /*
8965 : : * Continue validation for Xcap and VLAN actions.
8966 : : * If hairpin is working in explicit TX rule mode, there is no actions
8967 : : * splitting and the validation of hairpin ingress flow should be the
8968 : : * same as other standard flows.
8969 : : */
8970 [ # # ]: 0 : if ((action_flags & (MLX5_FLOW_XCAP_ACTIONS |
8971 [ # # ]: 0 : MLX5_FLOW_VLAN_ACTIONS)) &&
8972 [ # # # # ]: 0 : (queue_index == 0xFFFF || !mlx5_rxq_is_hairpin(dev, queue_index) ||
8973 : 0 : ((conf = mlx5_rxq_get_hairpin_conf(dev, queue_index)) != NULL &&
8974 [ # # ]: 0 : conf->tx_explicit != 0))) {
8975 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
8976 : : MLX5_FLOW_XCAP_ACTIONS)
8977 : 0 : return rte_flow_error_set(error, ENOTSUP,
8978 : : RTE_FLOW_ERROR_TYPE_ACTION,
8979 : : NULL, "encap and decap "
8980 : : "combination aren't supported");
8981 : : /* Push VLAN is not supported in ingress except for NICs newer than CX5. */
8982 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) {
8983 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
8984 : : bool direction_error = false;
8985 : :
8986 [ # # ]: 0 : if (attr->transfer) {
8987 [ # # ]: 0 : bool fdb_tx = flow_source_vport_representor(priv, act_priv);
8988 : 0 : bool is_cx5 = sh->steering_format_version ==
8989 : : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5;
8990 : :
8991 [ # # ]: 0 : if (!fdb_tx && is_cx5)
8992 : : direction_error = true;
8993 [ # # ]: 0 : } else if (attr->ingress) {
8994 : : direction_error = true;
8995 : : }
8996 : : if (direction_error)
8997 : 0 : return rte_flow_error_set(error, ENOTSUP,
8998 : : RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
8999 : : NULL,
9000 : : "push VLAN action not supported "
9001 : : "for ingress");
9002 : : }
9003 [ # # ]: 0 : if (attr->ingress) {
9004 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
9005 : 0 : return rte_flow_error_set
9006 : : (error, ENOTSUP,
9007 : : RTE_FLOW_ERROR_TYPE_ACTION,
9008 : : NULL, "encap is not supported"
9009 : : " for ingress traffic");
9010 [ # # ]: 0 : else if ((action_flags & MLX5_FLOW_VLAN_ACTIONS) ==
9011 : : MLX5_FLOW_VLAN_ACTIONS)
9012 : 0 : return rte_flow_error_set
9013 : : (error, ENOTSUP,
9014 : : RTE_FLOW_ERROR_TYPE_ACTION,
9015 : : NULL, "no support for "
9016 : : "multiple VLAN actions");
9017 : : }
9018 : : }
9019 : : /* Pop VLAN is not supported in egress except for NICs newer than CX5. */
9020 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_POP_VLAN) {
9021 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
9022 : : bool direction_error = false;
9023 : :
9024 [ # # ]: 0 : if (attr->transfer) {
9025 [ # # ]: 0 : bool fdb_tx = flow_source_vport_representor(priv, act_priv);
9026 : 0 : bool is_cx5 = sh->steering_format_version ==
9027 : : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5;
9028 : :
9029 [ # # ]: 0 : if (fdb_tx && is_cx5)
9030 : : direction_error = true;
9031 [ # # ]: 0 : } else if (attr->egress) {
9032 : : direction_error = true;
9033 : : }
9034 : : if (direction_error)
9035 : 0 : return rte_flow_error_set(error, ENOTSUP,
9036 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
9037 : : NULL,
9038 : : "pop vlan action not supported for egress");
9039 : : }
9040 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY) {
9041 [ # # ]: 0 : if ((action_flags & (MLX5_FLOW_FATE_ACTIONS &
9042 [ # # ]: 0 : ~MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)) &&
9043 : : attr->ingress)
9044 : 0 : return rte_flow_error_set
9045 : : (error, ENOTSUP,
9046 : : RTE_FLOW_ERROR_TYPE_ACTION,
9047 : : NULL, "fate action not supported for "
9048 : : "meter with policy");
9049 [ # # ]: 0 : if (attr->egress) {
9050 [ # # ]: 0 : if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
9051 : 0 : return rte_flow_error_set
9052 : : (error, ENOTSUP,
9053 : : RTE_FLOW_ERROR_TYPE_ACTION,
9054 : : NULL, "modify header action in egress "
9055 : : "cannot be done before meter action");
9056 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
9057 : 0 : return rte_flow_error_set
9058 : : (error, ENOTSUP,
9059 : : RTE_FLOW_ERROR_TYPE_ACTION,
9060 : : NULL, "encap action in egress "
9061 : : "cannot be done before meter action");
9062 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
9063 : 0 : return rte_flow_error_set
9064 : : (error, ENOTSUP,
9065 : : RTE_FLOW_ERROR_TYPE_ACTION,
9066 : : NULL, "push vlan action in egress "
9067 : : "cannot be done before meter action");
9068 : : }
9069 : : }
9070 : : /*
9071 : : * Only support one ASO action in a single flow rule.
9072 : : * non-shared AGE + counter will fallback to use HW counter, no ASO hit object.
9073 : : * Group 0 uses HW counter for AGE too even if no counter action.
9074 : : */
9075 [ # # # # ]: 0 : aso_mask = (action_flags & MLX5_FLOW_ACTION_METER && priv->sh->meter_aso_en) << 2 |
9076 [ # # # # : 0 : (action_flags & MLX5_FLOW_ACTION_CT && priv->sh->ct_aso_en) << 1 |
# # ]
9077 : 0 : (action_flags & MLX5_FLOW_ACTION_AGE &&
9078 [ # # ]: 0 : !(non_shared_age && count) &&
9079 [ # # # # : 0 : (attr->group || (attr->transfer && priv->fdb_def_rule)) &&
# # # # ]
9080 [ # # ]: 0 : priv->sh->flow_hit_aso_en);
9081 [ # # ]: 0 : if (rte_popcount64(aso_mask) > 1)
9082 : 0 : return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
9083 : : NULL, "unsupported combining AGE, METER, CT ASO actions in a single rule");
9084 : : /*
9085 : : * Hairpin flow will add one more TAG action in TX implicit mode.
9086 : : * In TX explicit mode, there will be no hairpin flow ID.
9087 : : */
9088 [ # # ]: 0 : if (hairpin > 0)
9089 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
9090 : : /* extra metadata enabled: one more TAG action will be add. */
9091 [ # # ]: 0 : if (dev_conf->dv_flow_en &&
9092 [ # # # # ]: 0 : dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
9093 : 0 : mlx5_flow_ext_mreg_supported(dev))
9094 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
9095 [ # # ]: 0 : if (rw_act_num >
9096 : : flow_dv_modify_hdr_action_max(dev, is_root)) {
9097 : 0 : return rte_flow_error_set(error, ENOTSUP,
9098 : : RTE_FLOW_ERROR_TYPE_ACTION,
9099 : : NULL, "too many header modify"
9100 : : " actions to support");
9101 : : }
9102 [ # # ]: 0 : if (fdb_mirror) {
9103 [ # # # # ]: 0 : if (!priv->sh->cdev->config.hca_attr.reg_c_preserve &&
9104 [ # # ]: 0 : flow_source_vport_representor(priv, act_priv)) {
9105 : : /* Eswitch egress mirror and modify flow has limitation on CX5 */
9106 [ # # ]: 0 : if (modify_after_mirror)
9107 : 0 : return rte_flow_error_set(error, EINVAL,
9108 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9109 : : "sample before modify action is not supported");
9110 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_JUMP)
9111 : 0 : return rte_flow_error_set(error, EINVAL,
9112 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9113 : : "sample and jump action combination is not supported");
9114 : : }
9115 [ # # ]: 0 : if (aso_mask > 0 && aso_after_sample && fdb_mirror)
9116 : 0 : return rte_flow_error_set(error, ENOTSUP,
9117 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9118 : : "sample before ASO action is not supported");
9119 [ # # ]: 0 : if (sub_action_flags & MLX5_FLOW_ACTION_PORT_ID) {
9120 : 0 : port_priv = mlx5_port_to_eswitch_info(sample_port_id, false);
9121 [ # # ]: 0 : if (flow_source_vport_representor(priv, port_priv)) {
9122 [ # # ]: 0 : if (sub_action_flags & MLX5_FLOW_ACTION_ENCAP)
9123 : 0 : return rte_flow_error_set(error, ENOTSUP,
9124 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9125 : : "mirror to rep port with encap is not supported");
9126 : : } else {
9127 [ # # ]: 0 : if (!(sub_action_flags & MLX5_FLOW_ACTION_ENCAP) &&
9128 [ # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_JUMP))
9129 : 0 : return rte_flow_error_set(error, ENOTSUP,
9130 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9131 : : "mirror to wire port without encap is not supported");
9132 : : }
9133 : : }
9134 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_PORT_ID) &&
9135 : : (action_flags & MLX5_FLOW_ACTION_ENCAP)) {
9136 : 0 : port_priv = mlx5_port_to_eswitch_info(port_id, false);
9137 [ # # ]: 0 : if (flow_source_vport_representor(priv, port_priv))
9138 : 0 : return rte_flow_error_set(error, ENOTSUP,
9139 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9140 : : "mirror to rep port with encap is not supported");
9141 : : }
9142 : : }
9143 : : /*
9144 : : * Validation the NIC Egress flow on representor, except implicit
9145 : : * hairpin default egress flow with TX_QUEUE item, other flows not
9146 : : * work due to metadata regC0 mismatch.
9147 : : */
9148 [ # # # # : 0 : if (attr->egress && priv->representor && !(item_flags & MLX5_FLOW_ITEM_SQ))
# # ]
9149 : 0 : return rte_flow_error_set(error, EINVAL,
9150 : : RTE_FLOW_ERROR_TYPE_ITEM,
9151 : : NULL,
9152 : : "NIC egress rules on representors"
9153 : : " is not supported");
9154 : : return 0;
9155 : : }
9156 : :
9157 : : /**
9158 : : * Internal preparation function. Allocates the DV flow size,
9159 : : * this size is constant.
9160 : : *
9161 : : * @param[in] dev
9162 : : * Pointer to the rte_eth_dev structure.
9163 : : * @param[in] attr
9164 : : * Pointer to the flow attributes.
9165 : : * @param[in] items
9166 : : * Pointer to the list of items.
9167 : : * @param[in] actions
9168 : : * Pointer to the list of actions.
9169 : : * @param[out] error
9170 : : * Pointer to the error structure.
9171 : : *
9172 : : * @return
9173 : : * Pointer to mlx5_flow object on success,
9174 : : * otherwise NULL and rte_errno is set.
9175 : : */
9176 : : static struct mlx5_flow *
9177 : 0 : flow_dv_prepare(struct rte_eth_dev *dev,
9178 : : const struct rte_flow_attr *attr __rte_unused,
9179 : : const struct rte_flow_item items[] __rte_unused,
9180 : : const struct rte_flow_action actions[] __rte_unused,
9181 : : struct rte_flow_error *error)
9182 : : {
9183 : 0 : uint32_t handle_idx = 0;
9184 : : struct mlx5_flow *dev_flow;
9185 : : struct mlx5_flow_handle *dev_handle;
9186 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
9187 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
9188 : :
9189 : : MLX5_ASSERT(wks);
9190 : 0 : wks->skip_matcher_reg = 0;
9191 : 0 : wks->policy = NULL;
9192 : 0 : wks->final_policy = NULL;
9193 : 0 : wks->vport_meta_tag = 0;
9194 : : /* In case of corrupting the memory. */
9195 [ # # ]: 0 : if (wks->flow_idx >= MLX5_NUM_MAX_DEV_FLOWS) {
9196 : 0 : rte_flow_error_set(error, ENOSPC,
9197 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9198 : : "not free temporary device flow");
9199 : 0 : return NULL;
9200 : : }
9201 : 0 : dev_handle = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
9202 : : &handle_idx);
9203 [ # # ]: 0 : if (!dev_handle) {
9204 : 0 : rte_flow_error_set(error, ENOMEM,
9205 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9206 : : "not enough memory to create flow handle");
9207 : 0 : return NULL;
9208 : : }
9209 : : MLX5_ASSERT(wks->flow_idx < RTE_DIM(wks->flows));
9210 : 0 : dev_flow = &wks->flows[wks->flow_idx++];
9211 : : memset(dev_flow, 0, sizeof(*dev_flow));
9212 : 0 : dev_flow->handle = dev_handle;
9213 : 0 : dev_flow->handle_idx = handle_idx;
9214 : 0 : dev_flow->dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param);
9215 : 0 : dev_flow->ingress = attr->ingress;
9216 : 0 : dev_flow->dv.transfer = attr->transfer;
9217 : 0 : return dev_flow;
9218 : : }
9219 : :
9220 : : #ifdef RTE_LIBRTE_MLX5_DEBUG
9221 : : /**
9222 : : * Sanity check for match mask and value. Similar to check_valid_spec() in
9223 : : * kernel driver. If unmasked bit is present in value, it returns failure.
9224 : : *
9225 : : * @param match_mask
9226 : : * pointer to match mask buffer.
9227 : : * @param match_value
9228 : : * pointer to match value buffer.
9229 : : *
9230 : : * @return
9231 : : * 0 if valid, -EINVAL otherwise.
9232 : : */
9233 : : static int
9234 : : flow_dv_check_valid_spec(void *match_mask, void *match_value)
9235 : : {
9236 : : uint8_t *m = match_mask;
9237 : : uint8_t *v = match_value;
9238 : : unsigned int i;
9239 : :
9240 : : for (i = 0; i < MLX5_ST_SZ_BYTES(fte_match_param); ++i) {
9241 : : if (v[i] & ~m[i]) {
9242 : : DRV_LOG(ERR,
9243 : : "match_value differs from match_criteria"
9244 : : " %p[%u] != %p[%u]",
9245 : : match_value, i, match_mask, i);
9246 : : return -EINVAL;
9247 : : }
9248 : : }
9249 : : return 0;
9250 : : }
9251 : : #endif
9252 : :
9253 : : /**
9254 : : * Add match of ip_version.
9255 : : *
9256 : : * @param[in] group
9257 : : * Flow group.
9258 : : * @param[in] headers_v
9259 : : * Values header pointer.
9260 : : * @param[in] headers_m
9261 : : * Masks header pointer.
9262 : : * @param[in] ip_version
9263 : : * The IP version to set.
9264 : : */
9265 : : static inline void
9266 : 0 : flow_dv_set_match_ip_version(uint32_t group,
9267 : : void *headers_v,
9268 : : uint32_t key_type,
9269 : : uint8_t ip_version)
9270 : : {
9271 [ # # # # ]: 0 : if (group == 0 && (key_type & MLX5_SET_MATCHER_M))
9272 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version, 0xf);
9273 : : else
9274 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version,
9275 : : ip_version);
9276 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype, 0);
9277 : 0 : }
9278 : :
9279 : : /**
9280 : : * Add Ethernet item to the value.
9281 : : *
9282 : : * @param[in, out] key
9283 : : * Flow matcher value.
9284 : : * @param[in] item
9285 : : * Flow pattern to translate.
9286 : : * @param[in] inner
9287 : : * Item is inner pattern.
9288 : : * @param[in] grpup
9289 : : * Flow matcher group.
9290 : : * @param[in] key_type
9291 : : * Set flow matcher mask or value.
9292 : : */
9293 : : static void
9294 : 0 : flow_dv_translate_item_eth(void *key, const struct rte_flow_item *item,
9295 : : int inner, uint32_t group, uint32_t key_type)
9296 : : {
9297 : 0 : const struct rte_flow_item_eth *eth_vv = item->spec;
9298 : : const struct rte_flow_item_eth *eth_m;
9299 : : const struct rte_flow_item_eth *eth_v;
9300 : 0 : const struct rte_flow_item_eth nic_mask = {
9301 : : .hdr.dst_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
9302 : : .hdr.src_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
9303 : : .hdr.ether_type = RTE_BE16(0xffff),
9304 : : .has_vlan = 0,
9305 : : };
9306 : : void *hdrs_v;
9307 : : char *l24_v;
9308 : : unsigned int i;
9309 : :
9310 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9311 : 0 : return;
9312 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, eth_v, eth_m, &nic_mask);
# # # # ]
9313 [ # # ]: 0 : if (!eth_vv)
9314 : : eth_vv = eth_v;
9315 [ # # ]: 0 : if (inner)
9316 : 0 : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9317 : : else
9318 : : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9319 : : /* The value must be in the range of the mask. */
9320 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, dmac_47_16);
9321 [ # # ]: 0 : for (i = 0; i < sizeof(eth_m->hdr.dst_addr); ++i)
9322 : 0 : l24_v[i] = eth_m->hdr.dst_addr.addr_bytes[i] & eth_v->hdr.dst_addr.addr_bytes[i];
9323 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, smac_47_16);
9324 : : /* The value must be in the range of the mask. */
9325 [ # # ]: 0 : for (i = 0; i < sizeof(eth_m->hdr.dst_addr); ++i)
9326 : 0 : l24_v[i] = eth_m->hdr.src_addr.addr_bytes[i] & eth_v->hdr.src_addr.addr_bytes[i];
9327 : : /*
9328 : : * HW supports match on one Ethertype, the Ethertype following the last
9329 : : * VLAN tag of the packet (see PRM).
9330 : : * Set match on ethertype only if ETH header is not followed by VLAN.
9331 : : * HW is optimized for IPv4/IPv6. In such cases, avoid setting
9332 : : * ethertype, and use ip_version field instead.
9333 : : * eCPRI over Ether layer will use type value 0xAEFE.
9334 : : */
9335 [ # # ]: 0 : if (eth_m->hdr.ether_type == 0xFFFF) {
9336 : 0 : rte_be16_t type = eth_v->hdr.ether_type;
9337 : :
9338 : : /*
9339 : : * When set the matcher mask, refer to the original spec
9340 : : * value.
9341 : : */
9342 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M) {
9343 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
9344 : 0 : type = eth_vv->hdr.ether_type;
9345 : : }
9346 : : /* Set cvlan_tag mask for any single\multi\un-tagged case. */
9347 [ # # # # : 0 : switch (type) {
# ]
9348 : 0 : case RTE_BE16(RTE_ETHER_TYPE_VLAN):
9349 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
9350 : 0 : return;
9351 : 0 : case RTE_BE16(RTE_ETHER_TYPE_QINQ):
9352 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
9353 : 0 : return;
9354 : 0 : case RTE_BE16(RTE_ETHER_TYPE_IPV4):
9355 : 0 : flow_dv_set_match_ip_version(group, hdrs_v, key_type,
9356 : : 4);
9357 : 0 : return;
9358 : 0 : case RTE_BE16(RTE_ETHER_TYPE_IPV6):
9359 : 0 : flow_dv_set_match_ip_version(group, hdrs_v, key_type,
9360 : : 6);
9361 : 0 : return;
9362 : : default:
9363 : : break;
9364 : : }
9365 : : }
9366 : : /*
9367 : : * Only SW steering value should refer to the mask value.
9368 : : * Other cases are using the fake masks, just ignore the mask.
9369 : : */
9370 [ # # # # ]: 0 : if (eth_v->has_vlan && eth_m->has_vlan) {
9371 : : /*
9372 : : * Here, when also has_more_vlan field in VLAN item is
9373 : : * not set, only single-tagged packets will be matched.
9374 : : */
9375 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
9376 [ # # # # ]: 0 : if (key_type != MLX5_SET_MATCHER_HS_M && eth_vv->has_vlan)
9377 : : return;
9378 : : }
9379 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, ethertype);
9380 : 0 : *(uint16_t *)(l24_v) = eth_m->hdr.ether_type & eth_v->hdr.ether_type;
9381 : : }
9382 : :
9383 : : /**
9384 : : * Add VLAN item to the value.
9385 : : *
9386 : : * @param[in, out] key
9387 : : * Flow matcher value.
9388 : : * @param[in] item
9389 : : * Flow pattern to translate.
9390 : : * @param[in] inner
9391 : : * Item is inner pattern.
9392 : : * @param[in] wks
9393 : : * Item workspace.
9394 : : * @param[in] key_type
9395 : : * Set flow matcher mask or value.
9396 : : */
9397 : : static void
9398 : 0 : flow_dv_translate_item_vlan(void *key, const struct rte_flow_item *item,
9399 : : int inner, struct mlx5_dv_matcher_workspace *wks,
9400 : : uint32_t key_type)
9401 : : {
9402 : : const struct rte_flow_item_vlan *vlan_m;
9403 : : const struct rte_flow_item_vlan *vlan_v;
9404 : 0 : const struct rte_flow_item_vlan *vlan_vv = item->spec;
9405 : : void *hdrs_v;
9406 : : uint16_t tci_v;
9407 : :
9408 [ # # ]: 0 : if (inner) {
9409 : 0 : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9410 : : } else {
9411 : : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9412 : : /*
9413 : : * This is workaround, masks are not supported,
9414 : : * and pre-validated.
9415 : : */
9416 [ # # ]: 0 : if (vlan_vv)
9417 [ # # ]: 0 : wks->vlan_tag = rte_be_to_cpu_16(vlan_vv->hdr.vlan_tci) & 0x0fff;
9418 : : }
9419 : : /*
9420 : : * When VLAN item exists in flow, mark packet as tagged,
9421 : : * even if TCI is not specified.
9422 : : */
9423 [ # # # # ]: 0 : if (!MLX5_GET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag))
9424 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
9425 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9426 : : return;
9427 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, vlan_v, vlan_m,
# # # # ]
9428 : : &rte_flow_item_vlan_mask);
9429 [ # # ]: 0 : tci_v = rte_be_to_cpu_16(vlan_m->hdr.vlan_tci & vlan_v->hdr.vlan_tci);
9430 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_vid, tci_v);
9431 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_cfi, tci_v >> 12);
9432 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_prio, tci_v >> 13);
9433 : : /*
9434 : : * HW is optimized for IPv4/IPv6. In such cases, avoid setting
9435 : : * ethertype, and use ip_version field instead.
9436 : : */
9437 [ # # ]: 0 : if (vlan_m->hdr.eth_proto == 0xFFFF) {
9438 : 0 : rte_be16_t inner_type = vlan_v->hdr.eth_proto;
9439 : :
9440 : : /*
9441 : : * When set the matcher mask, refer to the original spec
9442 : : * value.
9443 : : */
9444 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M)
9445 : 0 : inner_type = vlan_vv->hdr.eth_proto;
9446 [ # # # # ]: 0 : switch (inner_type) {
9447 : 0 : case RTE_BE16(RTE_ETHER_TYPE_VLAN):
9448 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
9449 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_V)
9450 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v,
9451 : : cvlan_tag, 0);
9452 : 0 : return;
9453 : 0 : case RTE_BE16(RTE_ETHER_TYPE_IPV4):
9454 : 0 : flow_dv_set_match_ip_version
9455 : : (wks->group, hdrs_v, key_type, 4);
9456 : 0 : return;
9457 : 0 : case RTE_BE16(RTE_ETHER_TYPE_IPV6):
9458 : 0 : flow_dv_set_match_ip_version
9459 : : (wks->group, hdrs_v, key_type, 6);
9460 : 0 : return;
9461 : : default:
9462 : : break;
9463 : : }
9464 : : }
9465 [ # # # # ]: 0 : if (vlan_m->has_more_vlan && vlan_v->has_more_vlan) {
9466 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
9467 : : /* Only one vlan_tag bit can be set. */
9468 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_V)
9469 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 0);
9470 : 0 : return;
9471 : : }
9472 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, ethertype,
9473 : : rte_be_to_cpu_16(vlan_m->hdr.eth_proto & vlan_v->hdr.eth_proto));
9474 : : }
9475 : :
9476 : : /**
9477 : : * Add IPV4 item to the value.
9478 : : *
9479 : : * @param[in, out] key
9480 : : * Flow matcher value.
9481 : : * @param[in] item
9482 : : * Flow pattern to translate.
9483 : : * @param[in] inner
9484 : : * Item is inner pattern.
9485 : : * @param[in] group
9486 : : * The group to insert the rule.
9487 : : * @param[in] key_type
9488 : : * Set flow matcher mask or value.
9489 : : */
9490 : : static void
9491 : 0 : flow_dv_translate_item_ipv4(void *key, const struct rte_flow_item *item,
9492 : : int inner, uint32_t group, uint32_t key_type)
9493 : : {
9494 : : const struct rte_flow_item_ipv4 *ipv4_m;
9495 : : const struct rte_flow_item_ipv4 *ipv4_v;
9496 : 0 : const struct rte_flow_item_ipv4 nic_mask = {
9497 : : .hdr = {
9498 : : .src_addr = RTE_BE32(0xffffffff),
9499 : : .dst_addr = RTE_BE32(0xffffffff),
9500 : : .type_of_service = 0xff,
9501 : : .next_proto_id = 0xff,
9502 : : .time_to_live = 0xff,
9503 : : },
9504 : : };
9505 : : void *headers_v;
9506 : : char *l24_v;
9507 : : uint8_t tos;
9508 : :
9509 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9510 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9511 : 0 : flow_dv_set_match_ip_version(group, headers_v, key_type, 4);
9512 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9513 : 0 : return;
9514 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, ipv4_v, ipv4_m, &nic_mask);
# # # # ]
9515 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
9516 : : dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
9517 : 0 : *(uint32_t *)l24_v = ipv4_m->hdr.dst_addr & ipv4_v->hdr.dst_addr;
9518 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
9519 : : src_ipv4_src_ipv6.ipv4_layout.ipv4);
9520 : 0 : *(uint32_t *)l24_v = ipv4_m->hdr.src_addr & ipv4_v->hdr.src_addr;
9521 : 0 : tos = ipv4_m->hdr.type_of_service & ipv4_v->hdr.type_of_service;
9522 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ipv4_ihl,
9523 : : ipv4_v->hdr.ihl & ipv4_m->hdr.ihl);
9524 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M)
9525 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn,
9526 : : ipv4_v->hdr.type_of_service);
9527 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, tos);
9528 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, tos >> 2);
9529 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
9530 : : ipv4_v->hdr.next_proto_id & ipv4_m->hdr.next_proto_id);
9531 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
9532 : : ipv4_v->hdr.time_to_live & ipv4_m->hdr.time_to_live);
9533 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
9534 : : !!(ipv4_v->hdr.fragment_offset & ipv4_m->hdr.fragment_offset));
9535 : : }
9536 : :
9537 : : /**
9538 : : * Add IPV6 item to the value.
9539 : : *
9540 : : * @param[in, out] key
9541 : : * Flow matcher value.
9542 : : * @param[in] item
9543 : : * Flow pattern to translate.
9544 : : * @param[in] inner
9545 : : * Item is inner pattern.
9546 : : * @param[in] group
9547 : : * The group to insert the rule.
9548 : : * @param[in] key_type
9549 : : * Set flow matcher mask or value.
9550 : : */
9551 : : static void
9552 : 0 : flow_dv_translate_item_ipv6(void *key, const struct rte_flow_item *item,
9553 : : int inner, uint32_t group, uint32_t key_type)
9554 : : {
9555 : : const struct rte_flow_item_ipv6 *ipv6_m;
9556 : : const struct rte_flow_item_ipv6 *ipv6_v;
9557 : 0 : const struct rte_flow_item_ipv6 nic_mask = {
9558 : : .hdr = {
9559 : : .src_addr = RTE_IPV6_MASK_FULL,
9560 : : .dst_addr = RTE_IPV6_MASK_FULL,
9561 : : .vtc_flow = RTE_BE32(0xffffffff),
9562 : : .proto = 0xff,
9563 : : .hop_limits = 0xff,
9564 : : },
9565 : : };
9566 : : void *headers_v;
9567 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9568 : : char *l24_v;
9569 : : uint32_t vtc_v;
9570 : : int i;
9571 : : int size;
9572 : :
9573 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9574 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9575 : 0 : flow_dv_set_match_ip_version(group, headers_v, key_type, 6);
9576 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9577 : 0 : return;
9578 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, ipv6_v, ipv6_m, &nic_mask);
# # # # ]
9579 : : size = sizeof(ipv6_m->hdr.dst_addr);
9580 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
9581 : : dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
9582 [ # # ]: 0 : for (i = 0; i < size; ++i)
9583 : 0 : l24_v[i] = ipv6_m->hdr.dst_addr.a[i] & ipv6_v->hdr.dst_addr.a[i];
9584 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
9585 : : src_ipv4_src_ipv6.ipv6_layout.ipv6);
9586 [ # # ]: 0 : for (i = 0; i < size; ++i)
9587 : 0 : l24_v[i] = ipv6_m->hdr.src_addr.a[i] & ipv6_v->hdr.src_addr.a[i];
9588 : : /* TOS. */
9589 [ # # ]: 0 : vtc_v = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow & ipv6_v->hdr.vtc_flow);
9590 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, vtc_v >> 20);
9591 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, vtc_v >> 22);
9592 : : /* Label. */
9593 [ # # ]: 0 : if (inner)
9594 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, inner_ipv6_flow_label,
9595 : : vtc_v);
9596 : : else
9597 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, outer_ipv6_flow_label,
9598 : : vtc_v);
9599 : : /* Protocol. */
9600 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
9601 : : ipv6_v->hdr.proto & ipv6_m->hdr.proto);
9602 : : /* Hop limit. */
9603 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
9604 : : ipv6_v->hdr.hop_limits & ipv6_m->hdr.hop_limits);
9605 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
9606 : : !!(ipv6_v->has_frag_ext & ipv6_m->has_frag_ext));
9607 : : }
9608 : :
9609 : : /**
9610 : : * Add IPV6 fragment extension item to the value.
9611 : : *
9612 : : * @param[in, out] key
9613 : : * Flow matcher value.
9614 : : * @param[in] item
9615 : : * Flow pattern to translate.
9616 : : * @param[in] inner
9617 : : * Item is inner pattern.
9618 : : * @param[in] key_type
9619 : : * Set flow matcher mask or value.
9620 : : */
9621 : : static void
9622 : 0 : flow_dv_translate_item_ipv6_frag_ext(void *key,
9623 : : const struct rte_flow_item *item,
9624 : : int inner, uint32_t key_type)
9625 : : {
9626 : : const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_m;
9627 : : const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_v;
9628 : 0 : const struct rte_flow_item_ipv6_frag_ext nic_mask = {
9629 : : .hdr = {
9630 : : .next_header = 0xff,
9631 : : .frag_data = RTE_BE16(0xffff),
9632 : : },
9633 : : };
9634 : : void *headers_v;
9635 : :
9636 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9637 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9638 : : /* IPv6 fragment extension item exists, so packet is IP fragment. */
9639 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag, 1);
9640 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9641 : 0 : return;
9642 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, ipv6_frag_ext_v,
# # # # ]
9643 : : ipv6_frag_ext_m, &nic_mask);
9644 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
9645 : : ipv6_frag_ext_v->hdr.next_header &
9646 : : ipv6_frag_ext_m->hdr.next_header);
9647 : : }
9648 : :
9649 : : /**
9650 : : * Add TCP item to the value.
9651 : : *
9652 : : * @param[in, out] key
9653 : : * Flow matcher value.
9654 : : * @param[in] item
9655 : : * Flow pattern to translate.
9656 : : * @param[in] inner
9657 : : * Item is inner pattern.
9658 : : * @param[in] key_type
9659 : : * Set flow matcher mask or value.
9660 : : */
9661 : : static void
9662 : 0 : flow_dv_translate_item_tcp(void *key, const struct rte_flow_item *item,
9663 : : int inner, uint32_t key_type)
9664 : : {
9665 : : const struct rte_flow_item_tcp *tcp_m;
9666 : : const struct rte_flow_item_tcp *tcp_v;
9667 : : void *headers_v;
9668 : :
9669 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9670 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9671 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9672 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9673 : : ip_protocol, 0xff);
9674 : : else
9675 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9676 : : ip_protocol, IPPROTO_TCP);
9677 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9678 : : return;
9679 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, tcp_v, tcp_m,
# # # # ]
9680 : : &rte_flow_item_tcp_mask);
9681 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_sport,
9682 : : rte_be_to_cpu_16(tcp_v->hdr.src_port & tcp_m->hdr.src_port));
9683 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_dport,
9684 : : rte_be_to_cpu_16(tcp_v->hdr.dst_port & tcp_m->hdr.dst_port));
9685 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_flags,
9686 : : tcp_v->hdr.tcp_flags & tcp_m->hdr.tcp_flags);
9687 : : }
9688 : :
9689 : : /**
9690 : : * Add ESP item to the value.
9691 : : *
9692 : : * @param[in, out] key
9693 : : * Flow matcher value.
9694 : : * @param[in] item
9695 : : * Flow pattern to translate.
9696 : : * @param[in] inner
9697 : : * Item is inner pattern.
9698 : : * @param[in] key_type
9699 : : * Set flow matcher mask or value.
9700 : : */
9701 : : static void
9702 : 0 : flow_dv_translate_item_esp(void *key, const struct rte_flow_item *item,
9703 : : int inner, uint32_t key_type)
9704 : : {
9705 : : const struct rte_flow_item_esp *esp_m;
9706 : : const struct rte_flow_item_esp *esp_v;
9707 : : void *headers_v;
9708 : : char *spi_v;
9709 : :
9710 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9711 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9712 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9713 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9714 : : ip_protocol, 0xff);
9715 : : else
9716 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9717 : : ip_protocol, IPPROTO_ESP);
9718 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9719 : : return;
9720 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, esp_v, esp_m,
# # # # ]
9721 : : &rte_flow_item_esp_mask);
9722 : : headers_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9723 : : spi_v = inner ? MLX5_ADDR_OF(fte_match_set_misc, headers_v,
9724 [ # # ]: 0 : inner_esp_spi) : MLX5_ADDR_OF(fte_match_set_misc
9725 : : , headers_v, outer_esp_spi);
9726 : 0 : *(uint32_t *)spi_v = esp_m->hdr.spi & esp_v->hdr.spi;
9727 : : }
9728 : :
9729 : : /**
9730 : : * Add UDP item to the value.
9731 : : *
9732 : : * @param[in, out] key
9733 : : * Flow matcher value.
9734 : : * @param[in] item
9735 : : * Flow pattern to translate.
9736 : : * @param[in] inner
9737 : : * Item is inner pattern.
9738 : : * @param[in] key_type
9739 : : * Set flow matcher mask or value.
9740 : : */
9741 : : static void
9742 : 0 : flow_dv_translate_item_udp(void *key, const struct rte_flow_item *item,
9743 : : int inner, struct mlx5_dv_matcher_workspace *wks,
9744 : : uint32_t key_type)
9745 : : {
9746 : : const struct rte_flow_item_udp *udp_m;
9747 : : const struct rte_flow_item_udp *udp_v;
9748 : : void *headers_v;
9749 : :
9750 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9751 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9752 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9753 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9754 : : ip_protocol, 0xff);
9755 : : else
9756 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9757 : : ip_protocol, IPPROTO_UDP);
9758 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9759 : : return;
9760 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, udp_v, udp_m,
# # # # ]
9761 : : &rte_flow_item_udp_mask);
9762 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_sport,
9763 : : rte_be_to_cpu_16(udp_v->hdr.src_port & udp_m->hdr.src_port));
9764 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
9765 : : rte_be_to_cpu_16(udp_v->hdr.dst_port & udp_m->hdr.dst_port));
9766 : : /* Force get UDP dport in case to be used in VXLAN translate. */
9767 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_SW) {
9768 : 0 : udp_v = item->spec;
9769 [ # # ]: 0 : wks->udp_dport = rte_be_to_cpu_16(udp_v->hdr.dst_port &
9770 : : udp_m->hdr.dst_port);
9771 : : }
9772 : : }
9773 : :
9774 : : /**
9775 : : * Add GRE optional Key item to the value.
9776 : : *
9777 : : * @param[in, out] key
9778 : : * Flow matcher value.
9779 : : * @param[in] item
9780 : : * Flow pattern to translate.
9781 : : * @param[in] inner
9782 : : * Item is inner pattern.
9783 : : */
9784 : : static void
9785 : 0 : flow_dv_translate_item_gre_key(void *key, const struct rte_flow_item *item,
9786 : : uint32_t key_type)
9787 : : {
9788 : : const rte_be32_t *key_m;
9789 : : const rte_be32_t *key_v;
9790 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9791 : 0 : rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
9792 : :
9793 : : /* GRE K bit must be on and should already be validated */
9794 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_k_present, 1);
9795 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9796 : 0 : return;
9797 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, key_v, key_m,
# # # # ]
9798 : : &gre_key_default_mask);
9799 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_key_h,
9800 : : rte_be_to_cpu_32((*key_v) & (*key_m)) >> 8);
9801 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_key_l,
9802 : : rte_be_to_cpu_32((*key_v) & (*key_m)) & 0xFF);
9803 : : }
9804 : :
9805 : : /**
9806 : : * Add GRE item to the value.
9807 : : *
9808 : : * @param[in, out] key
9809 : : * Flow matcher value.
9810 : : * @param[in] item
9811 : : * Flow pattern to translate.
9812 : : * @param[in] pattern_flags
9813 : : * Accumulated pattern flags.
9814 : : * @param[in] key_type
9815 : : * Set flow matcher mask or value.
9816 : : */
9817 : : static void
9818 : 0 : flow_dv_translate_item_gre(void *key, const struct rte_flow_item *item,
9819 : : uint64_t pattern_flags, uint32_t key_type)
9820 : : {
9821 : : static const struct rte_flow_item_gre empty_gre = {0,};
9822 : 0 : const struct rte_flow_item_gre *gre_m = item->mask;
9823 : 0 : const struct rte_flow_item_gre *gre_v = item->spec;
9824 : : void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9825 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9826 : : struct {
9827 : : union {
9828 : : __extension__
9829 : : struct {
9830 : : uint16_t version:3;
9831 : : uint16_t rsvd0:9;
9832 : : uint16_t s_present:1;
9833 : : uint16_t k_present:1;
9834 : : uint16_t rsvd_bit1:1;
9835 : : uint16_t c_present:1;
9836 : : };
9837 : : uint16_t value;
9838 : : };
9839 : : } gre_crks_rsvd0_ver_m, gre_crks_rsvd0_ver_v;
9840 : : uint16_t protocol_m, protocol_v;
9841 : :
9842 : : /* Common logic to SWS/HWS */
9843 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9844 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, 0xff);
9845 : : else
9846 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
9847 : : IPPROTO_GRE);
9848 : : /* HWS mask logic only */
9849 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_HS_M) {
9850 [ # # ]: 0 : if (!gre_m)
9851 : : gre_m = &rte_flow_item_gre_mask;
9852 : : gre_v = gre_m;
9853 [ # # ]: 0 : } else if (!gre_v) {
9854 : : gre_v = &empty_gre;
9855 : : gre_m = &empty_gre;
9856 [ # # ]: 0 : } else if (!gre_m) {
9857 : : gre_m = &rte_flow_item_gre_mask;
9858 : : }
9859 : : /* SWS logic only */
9860 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_SW_M)
9861 : : gre_v = gre_m;
9862 [ # # ]: 0 : gre_crks_rsvd0_ver_m.value = rte_be_to_cpu_16(gre_m->c_rsvd0_ver);
9863 [ # # ]: 0 : gre_crks_rsvd0_ver_v.value = rte_be_to_cpu_16(gre_v->c_rsvd0_ver);
9864 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_c_present,
9865 : : gre_crks_rsvd0_ver_v.c_present &
9866 : : gre_crks_rsvd0_ver_m.c_present);
9867 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_k_present,
9868 : : gre_crks_rsvd0_ver_v.k_present &
9869 : : gre_crks_rsvd0_ver_m.k_present);
9870 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_s_present,
9871 : : gre_crks_rsvd0_ver_v.s_present &
9872 : : gre_crks_rsvd0_ver_m.s_present);
9873 [ # # ]: 0 : protocol_m = rte_be_to_cpu_16(gre_m->protocol);
9874 [ # # ]: 0 : protocol_v = rte_be_to_cpu_16(gre_v->protocol);
9875 [ # # ]: 0 : if (!protocol_m) {
9876 : : /* Force next protocol to prevent matchers duplication */
9877 : : protocol_v = mlx5_translate_tunnel_etypes(pattern_flags);
9878 : : if (protocol_v)
9879 : : protocol_m = 0xFFFF;
9880 : : /* Restore the value to mask in mask case. */
9881 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9882 : : protocol_v = protocol_m;
9883 : : }
9884 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
9885 : : protocol_m & protocol_v);
9886 : 0 : }
9887 : :
9888 : : /**
9889 : : * Add GRE optional items to the value.
9890 : : *
9891 : : * @param[in, out] key
9892 : : * Flow matcher value.
9893 : : * @param[in] item
9894 : : * Flow pattern to translate.
9895 : : * @param[in] gre_item
9896 : : * Pointer to gre_item.
9897 : : * @param[in] pattern_flags
9898 : : * Accumulated pattern flags.
9899 : : * @param[in] key_type
9900 : : * Set flow matcher mask or value.
9901 : : */
9902 : : static void
9903 : 0 : flow_dv_translate_item_gre_option(void *key,
9904 : : const struct rte_flow_item *item,
9905 : : const struct rte_flow_item *gre_item,
9906 : : uint64_t pattern_flags, uint32_t key_type)
9907 : : {
9908 : : void *misc5_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_5);
9909 : 0 : const struct rte_flow_item_gre_opt *option_m = item->mask;
9910 : 0 : const struct rte_flow_item_gre_opt *option_v = item->spec;
9911 : 0 : const struct rte_flow_item_gre *gre_m = gre_item->mask;
9912 : 0 : const struct rte_flow_item_gre *gre_v = gre_item->spec;
9913 : : static const struct rte_flow_item_gre empty_gre = {0};
9914 : : struct rte_flow_item gre_key_item;
9915 : : uint16_t c_rsvd0_ver_m, c_rsvd0_ver_v;
9916 : : uint16_t protocol_m, protocol_v;
9917 : :
9918 : : /*
9919 : : * If only match key field, keep using misc for matching.
9920 : : * If need to match checksum or sequence, using misc5 and do
9921 : : * not need using misc.
9922 : : */
9923 [ # # ]: 0 : if (!(option_m->sequence.sequence ||
9924 [ # # ]: 0 : option_m->checksum_rsvd.checksum)) {
9925 : 0 : flow_dv_translate_item_gre(key, gre_item, pattern_flags, key_type);
9926 : 0 : gre_key_item.spec = &option_v->key.key;
9927 : 0 : gre_key_item.mask = &option_m->key.key;
9928 : 0 : flow_dv_translate_item_gre_key(key, &gre_key_item, key_type);
9929 : 0 : return;
9930 : : }
9931 [ # # ]: 0 : if (!gre_v) {
9932 : : gre_v = &empty_gre;
9933 : : gre_m = &empty_gre;
9934 : : } else {
9935 [ # # ]: 0 : if (!gre_m)
9936 : : gre_m = &rte_flow_item_gre_mask;
9937 : : }
9938 : 0 : protocol_v = gre_v->protocol;
9939 : 0 : protocol_m = gre_m->protocol;
9940 [ # # ]: 0 : if (!protocol_m) {
9941 : : /* Force next protocol to prevent matchers duplication */
9942 : : uint16_t ether_type =
9943 : : mlx5_translate_tunnel_etypes(pattern_flags);
9944 : : if (ether_type) {
9945 [ # # ]: 0 : protocol_v = rte_be_to_cpu_16(ether_type);
9946 : : protocol_m = UINT16_MAX;
9947 : : }
9948 : : }
9949 : 0 : c_rsvd0_ver_v = gre_v->c_rsvd0_ver;
9950 : 0 : c_rsvd0_ver_m = gre_m->c_rsvd0_ver;
9951 [ # # ]: 0 : if (option_m->sequence.sequence) {
9952 : 0 : c_rsvd0_ver_v |= RTE_BE16(0x1000);
9953 : 0 : c_rsvd0_ver_m |= RTE_BE16(0x1000);
9954 : : }
9955 [ # # ]: 0 : if (option_m->key.key) {
9956 : 0 : c_rsvd0_ver_v |= RTE_BE16(0x2000);
9957 : 0 : c_rsvd0_ver_m |= RTE_BE16(0x2000);
9958 : : }
9959 [ # # ]: 0 : if (option_m->checksum_rsvd.checksum) {
9960 : 0 : c_rsvd0_ver_v |= RTE_BE16(0x8000);
9961 : 0 : c_rsvd0_ver_m |= RTE_BE16(0x8000);
9962 : : }
9963 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
9964 : : c_rsvd0_ver_v = c_rsvd0_ver_m;
9965 : : protocol_v = protocol_m;
9966 : : option_v = option_m;
9967 : : }
9968 : : /*
9969 : : * Hardware parses GRE optional field into the fixed location,
9970 : : * do not need to adjust the tunnel dword indices.
9971 : : */
9972 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_0,
9973 : : rte_be_to_cpu_32((c_rsvd0_ver_v | protocol_v << 16) &
9974 : : (c_rsvd0_ver_m | protocol_m << 16)));
9975 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_1,
9976 : : rte_be_to_cpu_32(option_v->checksum_rsvd.checksum &
9977 : : option_m->checksum_rsvd.checksum));
9978 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_2,
9979 : : rte_be_to_cpu_32(option_v->key.key & option_m->key.key));
9980 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_3,
9981 : : rte_be_to_cpu_32(option_v->sequence.sequence &
9982 : : option_m->sequence.sequence));
9983 : : }
9984 : :
9985 : : /**
9986 : : * Add NVGRE item to matcher and to the value.
9987 : : *
9988 : : * @param[in, out] key
9989 : : * Flow matcher value.
9990 : : * @param[in] item
9991 : : * Flow pattern to translate.
9992 : : * @param[in] pattern_flags
9993 : : * Accumulated pattern flags.
9994 : : * @param[in] key_type
9995 : : * Set flow matcher mask or value.
9996 : : */
9997 : : static void
9998 : 0 : flow_dv_translate_item_nvgre(void *key, const struct rte_flow_item *item,
9999 : : unsigned long pattern_flags, uint32_t key_type)
10000 : : {
10001 : : const struct rte_flow_item_nvgre *nvgre_m;
10002 : : const struct rte_flow_item_nvgre *nvgre_v;
10003 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10004 : : const char *tni_flow_id_m;
10005 : : const char *tni_flow_id_v;
10006 : : char *gre_key_v;
10007 : : int size;
10008 : : int i;
10009 : :
10010 : : /* For NVGRE, GRE header fields must be set with defined values. */
10011 : 0 : const struct rte_flow_item_gre gre_spec = {
10012 : : .c_rsvd0_ver = RTE_BE16(0x2000),
10013 : : .protocol = RTE_BE16(RTE_ETHER_TYPE_TEB)
10014 : : };
10015 : 0 : const struct rte_flow_item_gre gre_mask = {
10016 : : .c_rsvd0_ver = RTE_BE16(0xB000),
10017 : : .protocol = RTE_BE16(UINT16_MAX),
10018 : : };
10019 : 0 : const struct rte_flow_item gre_item = {
10020 : : .spec = &gre_spec,
10021 : : .mask = &gre_mask,
10022 : : .last = NULL,
10023 : : };
10024 : 0 : flow_dv_translate_item_gre(key, &gre_item, pattern_flags, key_type);
10025 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10026 : 0 : return;
10027 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, nvgre_v, nvgre_m,
# # # # ]
10028 : : &rte_flow_item_nvgre_mask);
10029 : 0 : tni_flow_id_m = (const char *)nvgre_m->tni;
10030 : 0 : tni_flow_id_v = (const char *)nvgre_v->tni;
10031 : : size = sizeof(nvgre_m->tni) + sizeof(nvgre_m->flow_id);
10032 : 0 : gre_key_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, gre_key_h);
10033 [ # # ]: 0 : for (i = 0; i < size; ++i)
10034 : 0 : gre_key_v[i] = tni_flow_id_m[i] & tni_flow_id_v[i];
10035 : : }
10036 : :
10037 : : /**
10038 : : * Add VXLAN item to the value.
10039 : : *
10040 : : * @param[in] dev
10041 : : * Pointer to the Ethernet device structure.
10042 : : * @param[in] attr
10043 : : * Flow rule attributes.
10044 : : * @param[in, out] key
10045 : : * Flow matcher value.
10046 : : * @param[in] item
10047 : : * Flow pattern to translate.
10048 : : * @param[in] inner
10049 : : * Item is inner pattern.
10050 : : * @param[in] wks
10051 : : * Matcher workspace.
10052 : : * @param[in] key_type
10053 : : * Set flow matcher mask or value.
10054 : : */
10055 : : static void
10056 : 0 : flow_dv_translate_item_vxlan(struct rte_eth_dev *dev,
10057 : : const struct rte_flow_attr *attr,
10058 : : void *key, const struct rte_flow_item *item,
10059 : : int inner, struct mlx5_dv_matcher_workspace *wks,
10060 : : uint32_t key_type)
10061 : : {
10062 : : const struct rte_flow_item_vxlan *vxlan_m;
10063 : : const struct rte_flow_item_vxlan *vxlan_v;
10064 : : void *headers_v;
10065 : : void *misc_v;
10066 : : void *misc5_v;
10067 : : uint32_t tunnel_v;
10068 : : char *vni_v;
10069 : : uint16_t dport;
10070 : : int size;
10071 : : int i;
10072 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10073 : 0 : const struct rte_flow_item_vxlan nic_mask = {
10074 : : .hdr.vni = { 0xff, 0xff, 0xff },
10075 : : .hdr.rsvd1 = 0xff,
10076 : : };
10077 : :
10078 : : misc5_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_5);
10079 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
10080 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10081 [ # # ]: 0 : dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
10082 : : MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
10083 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
10084 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10085 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
10086 : : udp_dport, 0xFFFF);
10087 : : else
10088 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
10089 : : udp_dport, dport);
10090 : : }
10091 : : /*
10092 : : * Read the UDP dport to check if the value satisfies the VXLAN
10093 : : * matching with MISC5 for CX5.
10094 : : */
10095 [ # # ]: 0 : if (wks->udp_dport)
10096 : : dport = wks->udp_dport;
10097 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10098 : 0 : return;
10099 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, vxlan_v, vxlan_m, &nic_mask);
# # # # ]
10100 : : if ((item->mask == &nic_mask) &&
10101 : : ((!attr->group && !(attr->transfer && priv->fdb_def_rule) &&
10102 : : !priv->sh->tunnel_header_0_1) ||
10103 : : ((attr->group || (attr->transfer && priv->fdb_def_rule)) &&
10104 : : !priv->sh->misc5_cap)))
10105 : : vxlan_m = &rte_flow_item_vxlan_mask;
10106 [ # # ]: 0 : if ((priv->sh->steering_format_version ==
10107 [ # # ]: 0 : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5 &&
10108 : 0 : dport != MLX5_UDP_PORT_VXLAN) ||
10109 [ # # # # : 0 : (!attr->group && !(attr->transfer && priv->fdb_def_rule)) ||
# # # # ]
10110 [ # # # # ]: 0 : ((attr->group || (attr->transfer && priv->fdb_def_rule)) &&
10111 [ # # ]: 0 : !priv->sh->misc5_cap)) {
10112 : : misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10113 : : size = sizeof(vxlan_m->hdr.vni);
10114 : 0 : vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, vxlan_vni);
10115 [ # # ]: 0 : for (i = 0; i < size; ++i)
10116 : 0 : vni_v[i] = vxlan_m->hdr.vni[i] & vxlan_v->hdr.vni[i];
10117 : : return;
10118 : : }
10119 : 0 : tunnel_v = (vxlan_v->hdr.vni[0] & vxlan_m->hdr.vni[0]) |
10120 : 0 : (vxlan_v->hdr.vni[1] & vxlan_m->hdr.vni[1]) << 8 |
10121 : 0 : (vxlan_v->hdr.vni[2] & vxlan_m->hdr.vni[2]) << 16;
10122 : 0 : tunnel_v |= (vxlan_v->hdr.rsvd1 & vxlan_m->hdr.rsvd1) << 24;
10123 [ # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_1, RTE_BE32(tunnel_v));
10124 : : }
10125 : :
10126 : : /**
10127 : : * Add VXLAN-GPE item to the value.
10128 : : *
10129 : : * @param[in, out] key
10130 : : * Flow matcher value.
10131 : : * @param[in] item
10132 : : * Flow pattern to translate.
10133 : : * @param[in] pattern_flags
10134 : : * Item pattern flags.
10135 : : * @param[in] key_type
10136 : : * Set flow matcher mask or value.
10137 : : */
10138 : :
10139 : : static void
10140 : 0 : flow_dv_translate_item_vxlan_gpe(void *key, const struct rte_flow_item *item,
10141 : : const uint64_t pattern_flags,
10142 : : uint32_t key_type)
10143 : : {
10144 : : static const struct rte_flow_item_vxlan_gpe dummy_vxlan_gpe_hdr = {{{0}}};
10145 : 0 : const struct rte_flow_item_vxlan_gpe *vxlan_m = item->mask;
10146 : 0 : const struct rte_flow_item_vxlan_gpe *vxlan_v = item->spec;
10147 : : /* The item was validated to be on the outer side */
10148 : : void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10149 : : void *misc_v =
10150 : : MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
10151 : 0 : char *vni_v =
10152 : : MLX5_ADDR_OF(fte_match_set_misc3, misc_v, outer_vxlan_gpe_vni);
10153 : : int i, size = sizeof(vxlan_m->hdr.vni);
10154 : : uint8_t flags_m = 0xff;
10155 : : uint8_t flags_v = 0xc;
10156 : : uint8_t m_protocol, v_protocol;
10157 : :
10158 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
10159 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10160 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
10161 : : 0xFFFF);
10162 : : else
10163 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
10164 : : MLX5_UDP_PORT_VXLAN_GPE);
10165 : : }
10166 [ # # ]: 0 : if (!vxlan_v) {
10167 : : vxlan_v = &dummy_vxlan_gpe_hdr;
10168 : : vxlan_m = &dummy_vxlan_gpe_hdr;
10169 : : } else {
10170 [ # # ]: 0 : if (!vxlan_m)
10171 : : vxlan_m = &rte_flow_item_vxlan_gpe_mask;
10172 : : }
10173 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10174 : : vxlan_v = vxlan_m;
10175 [ # # ]: 0 : else if (key_type == MLX5_SET_MATCHER_HS_V)
10176 : : vxlan_m = vxlan_v;
10177 [ # # ]: 0 : if (vxlan_m->hdr.flags) {
10178 : : flags_m = vxlan_m->hdr.flags;
10179 : 0 : flags_v = vxlan_v->hdr.flags;
10180 : : }
10181 : 0 : m_protocol = vxlan_m->hdr.protocol;
10182 : 0 : v_protocol = vxlan_v->hdr.protocol;
10183 [ # # ]: 0 : if (!m_protocol) {
10184 : : /* Force next protocol to ensure next headers parsing. */
10185 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_NSH)
10186 : : v_protocol = RTE_VXLAN_GPE_TYPE_NSH;
10187 [ # # ]: 0 : else if (pattern_flags & MLX5_FLOW_LAYER_INNER_L2)
10188 : : v_protocol = RTE_VXLAN_GPE_TYPE_ETH;
10189 [ # # ]: 0 : else if (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV4)
10190 : : v_protocol = RTE_VXLAN_GPE_TYPE_IPV4;
10191 [ # # ]: 0 : else if (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV6)
10192 : : v_protocol = RTE_VXLAN_GPE_TYPE_IPV6;
10193 [ # # ]: 0 : if (v_protocol)
10194 : : m_protocol = 0xFF;
10195 : : /* Restore the value to mask in mask case. */
10196 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10197 : : v_protocol = m_protocol;
10198 : : }
10199 : : /*
10200 : : * If only match flags/protocol/vni field, keep using misc3 for matching.
10201 : : * If need to match rsvd0 or rsvd1, using misc5 and do not need using misc3.
10202 : : */
10203 [ # # # # : 0 : if (!(vxlan_m->hdr.rsvd0[0] || vxlan_m->hdr.rsvd0[1] || vxlan_m->hdr.rsvd1)) {
# # ]
10204 [ # # ]: 0 : for (i = 0; i < size; ++i)
10205 : 0 : vni_v[i] = vxlan_m->hdr.vni[i] & vxlan_v->hdr.vni[i];
10206 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc_v, outer_vxlan_gpe_flags,
10207 : : flags_m & flags_v);
10208 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc_v,
10209 : : outer_vxlan_gpe_next_protocol, m_protocol & v_protocol);
10210 : : } else {
10211 : : uint32_t tunnel_v;
10212 : : void *misc5_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_5);
10213 : :
10214 : 0 : tunnel_v = (flags_m & flags_v) << 24 |
10215 : 0 : (vxlan_v->hdr.rsvd0[0] & vxlan_m->hdr.rsvd0[0]) << 16 |
10216 : 0 : (vxlan_v->hdr.rsvd0[1] & vxlan_m->hdr.rsvd0[1]) << 8 |
10217 : 0 : (m_protocol & v_protocol);
10218 [ # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_0, tunnel_v);
10219 : 0 : tunnel_v = (vxlan_v->hdr.vni[0] & vxlan_m->hdr.vni[0]) << 24 |
10220 : 0 : (vxlan_v->hdr.vni[1] & vxlan_m->hdr.vni[1]) << 16 |
10221 : 0 : (vxlan_v->hdr.vni[2] & vxlan_m->hdr.vni[2]) << 8 |
10222 : 0 : (vxlan_v->hdr.rsvd1 & vxlan_m->hdr.rsvd1);
10223 [ # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_1, tunnel_v);
10224 : : }
10225 : 0 : }
10226 : :
10227 : : /**
10228 : : * Add Geneve item to the value.
10229 : : *
10230 : : * @param[in, out] key
10231 : : * Flow matcher value.
10232 : : * @param[in] item
10233 : : * Flow pattern to translate.
10234 : : * @param[in] pattern_flags
10235 : : * Item pattern flags.
10236 : : * @param[in] key_type
10237 : : * Set flow matcher mask or value.
10238 : : */
10239 : :
10240 : : static void
10241 : 0 : flow_dv_translate_item_geneve(void *key, const struct rte_flow_item *item,
10242 : : uint64_t pattern_flags, uint32_t key_type)
10243 : : {
10244 : : static const struct rte_flow_item_geneve empty_geneve = {0,};
10245 : 0 : const struct rte_flow_item_geneve *geneve_m = item->mask;
10246 : 0 : const struct rte_flow_item_geneve *geneve_v = item->spec;
10247 : : /* GENEVE flow item validation allows single tunnel item */
10248 : : void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10249 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10250 : : uint16_t gbhdr_m;
10251 : : uint16_t gbhdr_v;
10252 : 0 : char *vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, geneve_vni);
10253 : : size_t size = sizeof(geneve_m->vni), i;
10254 : : uint16_t protocol_m, protocol_v;
10255 : :
10256 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
10257 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10258 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
10259 : : 0xFFFF);
10260 : : else
10261 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
10262 : : MLX5_UDP_PORT_GENEVE);
10263 : : }
10264 [ # # ]: 0 : if (!geneve_v) {
10265 : : geneve_v = &empty_geneve;
10266 : : geneve_m = &empty_geneve;
10267 : : } else {
10268 [ # # ]: 0 : if (!geneve_m)
10269 : : geneve_m = &rte_flow_item_geneve_mask;
10270 : : }
10271 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10272 : : geneve_v = geneve_m;
10273 [ # # ]: 0 : else if (key_type == MLX5_SET_MATCHER_HS_V)
10274 : : geneve_m = geneve_v;
10275 [ # # ]: 0 : for (i = 0; i < size; ++i)
10276 : 0 : vni_v[i] = geneve_m->vni[i] & geneve_v->vni[i];
10277 [ # # ]: 0 : gbhdr_m = rte_be_to_cpu_16(geneve_m->ver_opt_len_o_c_rsvd0);
10278 [ # # ]: 0 : gbhdr_v = rte_be_to_cpu_16(geneve_v->ver_opt_len_o_c_rsvd0);
10279 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, geneve_oam,
10280 : : MLX5_GENEVE_OAMF_VAL(gbhdr_v) & MLX5_GENEVE_OAMF_VAL(gbhdr_m));
10281 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
10282 : : MLX5_GENEVE_OPTLEN_VAL(gbhdr_v) &
10283 : : MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
10284 [ # # ]: 0 : protocol_m = rte_be_to_cpu_16(geneve_m->protocol);
10285 [ # # ]: 0 : protocol_v = rte_be_to_cpu_16(geneve_v->protocol);
10286 [ # # ]: 0 : if (!protocol_m) {
10287 : : /* Force next protocol to prevent matchers duplication */
10288 : : protocol_v = mlx5_translate_tunnel_etypes(pattern_flags);
10289 : : if (protocol_v)
10290 : : protocol_m = 0xFFFF;
10291 : : /* Restore the value to mask in mask case. */
10292 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10293 : : protocol_v = protocol_m;
10294 : : }
10295 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, geneve_protocol_type,
10296 : : protocol_m & protocol_v);
10297 : 0 : }
10298 : :
10299 : : /**
10300 : : * Create Geneve TLV option resource.
10301 : : *
10302 : : * @param[in, out] dev
10303 : : * Pointer to rte_eth_dev structure.
10304 : : * @param[in] item
10305 : : * Flow pattern to translate.
10306 : : * @param[out] error
10307 : : * pointer to error structure.
10308 : : *
10309 : : * @return
10310 : : * 0 on success otherwise -errno and errno is set.
10311 : : */
10312 : : static int
10313 : 0 : flow_dev_geneve_tlv_option_resource_register(struct rte_eth_dev *dev,
10314 : : const struct rte_flow_item *item,
10315 : : struct rte_flow_error *error)
10316 : : {
10317 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10318 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
10319 : 0 : struct mlx5_geneve_tlv_option_resource *geneve_opt_resource =
10320 : : sh->geneve_tlv_option_resource;
10321 : : struct mlx5_devx_obj *obj;
10322 : 0 : const struct rte_flow_item_geneve_opt *geneve_opt_v = item->spec;
10323 : : int ret = 0;
10324 : :
10325 : : MLX5_ASSERT(sh->config.dv_flow_en == 1);
10326 [ # # ]: 0 : if (!geneve_opt_v)
10327 : : return -1;
10328 : 0 : rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
10329 [ # # ]: 0 : if (geneve_opt_resource != NULL) {
10330 : 0 : if (geneve_opt_resource->option_class ==
10331 : : geneve_opt_v->option_class &&
10332 : : geneve_opt_resource->option_type ==
10333 [ # # ]: 0 : geneve_opt_v->option_type &&
10334 : : geneve_opt_resource->length ==
10335 : : geneve_opt_v->option_len) {
10336 : 0 : rte_atomic_fetch_add_explicit(&geneve_opt_resource->refcnt, 1,
10337 : : rte_memory_order_relaxed);
10338 : : } else {
10339 : 0 : ret = rte_flow_error_set(error, ENOMEM,
10340 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10341 : : "Only one GENEVE TLV option supported");
10342 : 0 : goto exit;
10343 : : }
10344 : : } else {
10345 : 0 : struct mlx5_devx_geneve_tlv_option_attr attr = {
10346 : 0 : .option_class = geneve_opt_v->option_class,
10347 : 0 : .option_type = geneve_opt_v->option_type,
10348 : 0 : .option_data_len = geneve_opt_v->option_len,
10349 : : };
10350 : :
10351 : : /* Create a GENEVE TLV object and resource. */
10352 : 0 : obj = mlx5_devx_cmd_create_geneve_tlv_option(sh->cdev->ctx,
10353 : : &attr);
10354 [ # # ]: 0 : if (!obj) {
10355 : 0 : ret = rte_flow_error_set(error, ENODATA,
10356 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10357 : : "Failed to create GENEVE TLV Devx object");
10358 : 0 : goto exit;
10359 : : }
10360 : 0 : sh->geneve_tlv_option_resource =
10361 : 0 : mlx5_malloc(MLX5_MEM_ZERO,
10362 : : sizeof(*geneve_opt_resource),
10363 : : 0, SOCKET_ID_ANY);
10364 [ # # ]: 0 : if (!sh->geneve_tlv_option_resource) {
10365 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
10366 : 0 : ret = rte_flow_error_set(error, ENOMEM,
10367 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10368 : : "GENEVE TLV object memory allocation failed");
10369 : 0 : goto exit;
10370 : : }
10371 : : geneve_opt_resource = sh->geneve_tlv_option_resource;
10372 : 0 : geneve_opt_resource->obj = obj;
10373 : 0 : geneve_opt_resource->option_class = geneve_opt_v->option_class;
10374 : 0 : geneve_opt_resource->option_type = geneve_opt_v->option_type;
10375 : 0 : geneve_opt_resource->length = geneve_opt_v->option_len;
10376 : 0 : rte_atomic_store_explicit(&geneve_opt_resource->refcnt, 1,
10377 : : rte_memory_order_relaxed);
10378 : : }
10379 : 0 : exit:
10380 : : rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
10381 : 0 : return ret;
10382 : : }
10383 : :
10384 : : /**
10385 : : * Add Geneve TLV option item to value.
10386 : : *
10387 : : * @param[in, out] dev
10388 : : * Pointer to rte_eth_dev structure.
10389 : : * @param[in, out] key
10390 : : * Flow matcher value.
10391 : : * @param[in] item
10392 : : * Flow pattern to translate.
10393 : : * @param[in] key_type
10394 : : * Set flow matcher mask or value.
10395 : : * @param[out] error
10396 : : * Pointer to error structure.
10397 : : */
10398 : : static int
10399 : 0 : flow_dv_translate_item_geneve_opt(struct rte_eth_dev *dev, void *key,
10400 : : const struct rte_flow_item *item,
10401 : : uint32_t key_type,
10402 : : struct rte_flow_error *error)
10403 : : {
10404 : : const struct rte_flow_item_geneve_opt *geneve_opt_m;
10405 : : const struct rte_flow_item_geneve_opt *geneve_opt_v;
10406 : 0 : const struct rte_flow_item_geneve_opt *orig_spec = item->spec;
10407 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
10408 : 0 : rte_be32_t opt_data_key = 0, opt_data_mask = 0;
10409 : : size_t option_byte_len;
10410 : : int ret = 0;
10411 : :
10412 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type) || !orig_spec)
# # # # #
# # # ]
10413 : : return -1;
10414 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, geneve_opt_v, geneve_opt_m,
# # # # ]
10415 : : &rte_flow_item_geneve_opt_mask);
10416 : : /*
10417 : : * Register resource requires item spec for SW steering,
10418 : : * for HW steering resources is registered explicitly by user.
10419 : : */
10420 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_SW_V) {
10421 : 0 : ret = flow_dev_geneve_tlv_option_resource_register(dev, item,
10422 : : error);
10423 [ # # ]: 0 : if (ret) {
10424 : 0 : DRV_LOG(ERR, "Failed to create geneve_tlv_obj");
10425 : 0 : return ret;
10426 : : }
10427 : : }
10428 : : /* Convert the option length from DW to bytes for using memcpy. */
10429 : 0 : option_byte_len = RTE_MIN((size_t)(orig_spec->option_len * 4),
10430 : : sizeof(rte_be32_t));
10431 [ # # ]: 0 : if (geneve_opt_v->data) {
10432 : : memcpy(&opt_data_key, geneve_opt_v->data, option_byte_len);
10433 : 0 : memcpy(&opt_data_mask, geneve_opt_m->data, option_byte_len);
10434 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v,
10435 : : geneve_tlv_option_0_data,
10436 : : rte_be_to_cpu_32(opt_data_key & opt_data_mask));
10437 : : }
10438 : : return ret;
10439 : : }
10440 : :
10441 : : /**
10442 : : * Add MPLS item to the value.
10443 : : *
10444 : : * @param[in, out] key
10445 : : * Flow matcher value.
10446 : : * @param[in] item
10447 : : * Flow pattern to translate.
10448 : : * @param[in] prev_layer
10449 : : * The protocol layer indicated in previous item.
10450 : : * @param[in] inner
10451 : : * Item is inner pattern.
10452 : : * @param[in] key_type
10453 : : * Set flow matcher mask or value.
10454 : : */
10455 : : static void
10456 : 0 : flow_dv_translate_item_mpls(void *key, const struct rte_flow_item *item,
10457 : : uint64_t prev_layer, int inner,
10458 : : uint32_t key_type)
10459 : : {
10460 : : const uint32_t *in_mpls_m;
10461 : : const uint32_t *in_mpls_v;
10462 : : uint32_t *out_mpls_v = 0;
10463 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10464 : 0 : void *misc2_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
10465 : : void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10466 : :
10467 [ # # # ]: 0 : switch (prev_layer) {
10468 : 0 : case MLX5_FLOW_LAYER_OUTER_L4_UDP:
10469 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
10470 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10471 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
10472 : : udp_dport, 0xffff);
10473 : : else
10474 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
10475 : : udp_dport, MLX5_UDP_PORT_MPLS);
10476 : : }
10477 : : break;
10478 : 0 : case MLX5_FLOW_LAYER_GRE:
10479 : : /* Fall-through. */
10480 : : case MLX5_FLOW_LAYER_GRE_KEY:
10481 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_misc, misc_v, gre_protocol)) {
10482 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10483 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v,
10484 : : gre_protocol, 0xffff);
10485 : : else
10486 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v,
10487 : : gre_protocol, RTE_ETHER_TYPE_MPLS);
10488 : : }
10489 : : break;
10490 : : default:
10491 : : break;
10492 : : }
10493 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10494 : : return;
10495 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, in_mpls_v, in_mpls_m,
# # # # ]
10496 : : &rte_flow_item_mpls_mask);
10497 [ # # # ]: 0 : switch (prev_layer) {
10498 : 0 : case MLX5_FLOW_LAYER_OUTER_L4_UDP:
10499 : 0 : out_mpls_v =
10500 : : (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
10501 : : outer_first_mpls_over_udp);
10502 : 0 : break;
10503 : 0 : case MLX5_FLOW_LAYER_GRE:
10504 : 0 : out_mpls_v =
10505 : : (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
10506 : : outer_first_mpls_over_gre);
10507 : 0 : break;
10508 : 0 : default:
10509 : : /* Inner MPLS not over GRE is not supported. */
10510 [ # # ]: 0 : if (!inner)
10511 : : out_mpls_v =
10512 : : (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
10513 : : misc2_v,
10514 : : outer_first_mpls);
10515 : : break;
10516 : : }
10517 : : if (out_mpls_v)
10518 : 0 : *out_mpls_v = *in_mpls_v & *in_mpls_m;
10519 : : }
10520 : :
10521 : : /**
10522 : : * Add metadata register item to matcher
10523 : : *
10524 : : * @param[in, out] key
10525 : : * Flow matcher value.
10526 : : * @param[in] reg_type
10527 : : * Type of device metadata register
10528 : : * @param[in] data
10529 : : * Register data
10530 : : * @param[in] mask
10531 : : * Register mask
10532 : : */
10533 : : static void
10534 : 0 : flow_dv_match_meta_reg(void *key, enum modify_reg reg_type,
10535 : : uint32_t data, uint32_t mask)
10536 : : {
10537 : : void *misc2_v =
10538 : : MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
10539 : : uint32_t temp;
10540 : :
10541 [ # # ]: 0 : if (!key)
10542 : : return;
10543 : 0 : data &= mask;
10544 [ # # # # : 0 : switch (reg_type) {
# # # # #
# # ]
10545 : 0 : case REG_A:
10546 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_a, data);
10547 : 0 : break;
10548 : 0 : case REG_B:
10549 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_b, data);
10550 : 0 : break;
10551 : 0 : case REG_C_0:
10552 : : /*
10553 : : * The metadata register C0 field might be divided into
10554 : : * source vport index and META item value, we should set
10555 : : * this field according to specified mask, not as whole one.
10556 : : */
10557 [ # # ]: 0 : temp = MLX5_GET(fte_match_set_misc2, misc2_v, metadata_reg_c_0);
10558 [ # # ]: 0 : if (mask)
10559 : 0 : temp &= ~mask;
10560 : 0 : temp |= data;
10561 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_0, temp);
10562 : 0 : break;
10563 : 0 : case REG_C_1:
10564 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_1, data);
10565 : 0 : break;
10566 : 0 : case REG_C_2:
10567 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_2, data);
10568 : 0 : break;
10569 : 0 : case REG_C_3:
10570 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_3, data);
10571 : 0 : break;
10572 : 0 : case REG_C_4:
10573 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_4, data);
10574 : 0 : break;
10575 : 0 : case REG_C_5:
10576 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_5, data);
10577 : 0 : break;
10578 : 0 : case REG_C_6:
10579 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_6, data);
10580 : 0 : break;
10581 : 0 : case REG_C_7:
10582 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_7, data);
10583 : 0 : break;
10584 : : default:
10585 : : MLX5_ASSERT(false);
10586 : : break;
10587 : : }
10588 : : }
10589 : :
10590 : : /**
10591 : : * Add metadata register item to matcher
10592 : : *
10593 : : * @param[in, out] matcher
10594 : : * Flow matcher.
10595 : : * @param[in, out] key
10596 : : * Flow matcher value.
10597 : : * @param[in] reg_type
10598 : : * Type of device metadata register
10599 : : * @param[in] value
10600 : : * Register value
10601 : : * @param[in] mask
10602 : : * Register mask
10603 : : */
10604 : : static void
10605 : : flow_dv_match_meta_reg_all(void *matcher, void *key, enum modify_reg reg_type,
10606 : : uint32_t data, uint32_t mask)
10607 : : {
10608 : 0 : flow_dv_match_meta_reg(key, reg_type, data, mask);
10609 : 0 : flow_dv_match_meta_reg(matcher, reg_type, mask, mask);
10610 : : }
10611 : :
10612 : : /**
10613 : : * Add MARK item to matcher
10614 : : *
10615 : : * @param[in] dev
10616 : : * The device to configure through.
10617 : : * @param[in, out] key
10618 : : * Flow matcher value.
10619 : : * @param[in] item
10620 : : * Flow pattern to translate.
10621 : : * @param[in] key_type
10622 : : * Set flow matcher mask or value.
10623 : : */
10624 : : static void
10625 : 0 : flow_dv_translate_item_mark(struct rte_eth_dev *dev, void *key,
10626 : : const struct rte_flow_item *item,
10627 : : uint32_t key_type)
10628 : : {
10629 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10630 : : const struct rte_flow_item_mark *mark;
10631 : : uint32_t value;
10632 : : uint32_t mask = 0;
10633 : :
10634 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_SW) {
10635 [ # # ]: 0 : mark = item->mask ? (const void *)item->mask :
10636 : : &rte_flow_item_mark_mask;
10637 : 0 : mask = mark->id;
10638 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M) {
10639 : : value = mask;
10640 : : } else {
10641 : 0 : mark = (const void *)item->spec;
10642 : : MLX5_ASSERT(mark);
10643 : 0 : value = mark->id;
10644 : : }
10645 : : } else {
10646 [ # # ]: 0 : mark = (key_type == MLX5_SET_MATCHER_HS_V) ?
10647 : : (const void *)item->spec : (const void *)item->mask;
10648 : : MLX5_ASSERT(mark);
10649 : 0 : value = mark->id;
10650 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_HS_M)
10651 : : mask = value;
10652 : : }
10653 : 0 : mask &= priv->sh->dv_mark_mask;
10654 : 0 : value &= mask;
10655 [ # # ]: 0 : if (mask) {
10656 : : enum modify_reg reg;
10657 : :
10658 : : /* Get the metadata register index for the mark. */
10659 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, NULL);
10660 : : MLX5_ASSERT(reg > 0);
10661 [ # # ]: 0 : if (reg == REG_C_0) {
10662 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10663 : 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
10664 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
10665 : :
10666 : 0 : mask &= msk_c0;
10667 : 0 : mask <<= shl_c0;
10668 : 0 : value <<= shl_c0;
10669 : : }
10670 : 0 : flow_dv_match_meta_reg(key, reg, value, mask);
10671 : : }
10672 : 0 : }
10673 : :
10674 : : /**
10675 : : * Add META item to matcher
10676 : : *
10677 : : * @param[in] dev
10678 : : * The devich to configure through.
10679 : : * @param[in, out] key
10680 : : * Flow matcher value.
10681 : : * @param[in] attr
10682 : : * Attributes of flow that includes this item.
10683 : : * @param[in] item
10684 : : * Flow pattern to translate.
10685 : : * @param[in] key_type
10686 : : * Set flow matcher mask or value.
10687 : : */
10688 : : static void
10689 : 0 : flow_dv_translate_item_meta(struct rte_eth_dev *dev,
10690 : : void *key,
10691 : : const struct rte_flow_attr *attr,
10692 : : const struct rte_flow_item *item,
10693 : : uint32_t key_type)
10694 : : {
10695 : : const struct rte_flow_item_meta *meta_m;
10696 : : const struct rte_flow_item_meta *meta_v;
10697 : : uint32_t value;
10698 : : uint32_t mask = 0;
10699 : : int reg;
10700 : :
10701 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10702 : : return;
10703 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, meta_v, meta_m,
# # # # ]
10704 : : &rte_flow_item_meta_mask);
10705 : 0 : value = meta_v->data;
10706 : 0 : mask = meta_m->data;
10707 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_HS_M)
10708 : : mask = value;
10709 : : /*
10710 : : * In the current implementation, REG_B cannot be used to match.
10711 : : * Force to use REG_C_1 in HWS root table as other tables.
10712 : : * This map may change.
10713 : : * NIC: modify - REG_B to be present in SW
10714 : : * match - REG_C_1 when copied from FDB, different from SWS
10715 : : * FDB: modify - REG_C_1 in Xmeta mode, REG_NON in legacy mode
10716 : : * match - REG_C_1 in FDB
10717 : : */
10718 [ # # ]: 0 : if (!!(key_type & MLX5_SET_MATCHER_SW))
10719 : 0 : reg = flow_dv_get_metadata_reg(dev, attr, NULL);
10720 : : else
10721 : : reg = flow_hw_get_reg_id(dev, RTE_FLOW_ITEM_TYPE_META, 0);
10722 [ # # ]: 0 : if (reg < 0)
10723 : : return;
10724 : : MLX5_ASSERT(reg != REG_NON);
10725 [ # # ]: 0 : if (reg == REG_C_0) {
10726 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10727 : 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
10728 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
10729 : :
10730 : 0 : mask &= msk_c0;
10731 : 0 : mask <<= shl_c0;
10732 : 0 : value <<= shl_c0;
10733 : : }
10734 : 0 : flow_dv_match_meta_reg(key, reg, value, mask);
10735 : : }
10736 : :
10737 : : /**
10738 : : * Add vport metadata Reg C0 item to matcher
10739 : : *
10740 : : * @param[in, out] key
10741 : : * Flow matcher value.
10742 : : * @param[in] value
10743 : : * Register value
10744 : : * @param[in] mask
10745 : : * Register mask
10746 : : */
10747 : : static void
10748 : : flow_dv_translate_item_meta_vport(void *key, uint32_t value, uint32_t mask)
10749 : : {
10750 : 0 : flow_dv_match_meta_reg(key, REG_C_0, value, mask);
10751 : 0 : }
10752 : :
10753 : : /**
10754 : : * Add tag item to matcher
10755 : : *
10756 : : * @param[in] dev
10757 : : * The devich to configure through.
10758 : : * @param[in, out] key
10759 : : * Flow matcher value.
10760 : : * @param[in] item
10761 : : * Flow pattern to translate.
10762 : : * @param[in] key_type
10763 : : * Set flow matcher mask or value.
10764 : : */
10765 : : static void
10766 : 0 : flow_dv_translate_mlx5_item_tag(struct rte_eth_dev *dev, void *key,
10767 : : const struct rte_flow_item *item,
10768 : : uint32_t key_type)
10769 : : {
10770 : 0 : const struct mlx5_rte_flow_item_tag *tag_v = item->spec;
10771 : 0 : const struct mlx5_rte_flow_item_tag *tag_m = item->mask;
10772 : : uint32_t mask, value;
10773 : :
10774 : : MLX5_ASSERT(tag_v);
10775 : 0 : value = tag_v->data;
10776 [ # # ]: 0 : mask = tag_m ? tag_m->data : UINT32_MAX;
10777 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10778 : : value = mask;
10779 [ # # ]: 0 : if (tag_v->id == REG_C_0) {
10780 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10781 : 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
10782 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
10783 : :
10784 : 0 : mask &= msk_c0;
10785 : 0 : mask <<= shl_c0;
10786 : 0 : value <<= shl_c0;
10787 : : }
10788 : 0 : flow_dv_match_meta_reg(key, tag_v->id, value, mask);
10789 : 0 : }
10790 : :
10791 : : /**
10792 : : * Add TAG item to matcher
10793 : : *
10794 : : * @param[in] dev
10795 : : * The devich to configure through.
10796 : : * @param[in, out] key
10797 : : * Flow matcher value.
10798 : : * @param[in] item
10799 : : * Flow pattern to translate.
10800 : : * @param[in] key_type
10801 : : * Set flow matcher mask or value.
10802 : : */
10803 : : static void
10804 : 0 : flow_dv_translate_item_tag(struct rte_eth_dev *dev, void *key,
10805 : : const struct rte_flow_item *item,
10806 : : uint32_t key_type)
10807 : : {
10808 : 0 : const struct rte_flow_item_tag *tag_vv = item->spec;
10809 : : const struct rte_flow_item_tag *tag_v;
10810 : : const struct rte_flow_item_tag *tag_m;
10811 : : int reg;
10812 : : uint32_t index;
10813 : :
10814 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10815 : : return;
10816 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, tag_v, tag_m,
# # # # ]
10817 : : &rte_flow_item_tag_mask);
10818 : : /* When set mask, the index should be from spec. */
10819 [ # # ]: 0 : index = tag_vv ? tag_vv->index : tag_v->index;
10820 : : /* Get the metadata register index for the tag. */
10821 [ # # ]: 0 : if (!!(key_type & MLX5_SET_MATCHER_SW))
10822 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, index, NULL);
10823 : : else
10824 : : reg = flow_hw_get_reg_id(dev, RTE_FLOW_ITEM_TYPE_TAG, index);
10825 : : MLX5_ASSERT(reg > 0);
10826 : 0 : flow_dv_match_meta_reg(key, (enum modify_reg)reg, tag_v->data, tag_m->data);
10827 : : }
10828 : :
10829 : : /**
10830 : : * Add source vport match to the specified matcher.
10831 : : *
10832 : : * @param[in, out] key
10833 : : * Flow matcher value.
10834 : : * @param[in] port
10835 : : * Source vport value to match
10836 : : */
10837 : : static void
10838 : : flow_dv_translate_item_source_vport(void *key,
10839 : : int16_t port)
10840 : : {
10841 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10842 : :
10843 [ # # # # : 0 : MLX5_SET(fte_match_set_misc, misc_v, source_port, port);
# # ]
10844 : 0 : }
10845 : :
10846 : : /**
10847 : : * Translate port-id item to eswitch match on port-id.
10848 : : *
10849 : : * @param[in] dev
10850 : : * The devich to configure through.
10851 : : * @param[in, out] key
10852 : : * Flow matcher value.
10853 : : * @param[in] item
10854 : : * Flow pattern to translate.
10855 : : * @param[in] attr
10856 : : * Flow attributes.
10857 : : * @param[in] key_type
10858 : : * Set flow matcher mask or value.
10859 : : *
10860 : : * @return
10861 : : * 0 on success, a negative errno value otherwise.
10862 : : */
10863 : : static int
10864 : 0 : flow_dv_translate_item_port_id(struct rte_eth_dev *dev, void *key,
10865 : : const struct rte_flow_item *item,
10866 : : const struct rte_flow_attr *attr,
10867 : : uint32_t key_type)
10868 : : {
10869 [ # # ]: 0 : const struct rte_flow_item_port_id *pid_m = item ? item->mask : NULL;
10870 [ # # ]: 0 : const struct rte_flow_item_port_id *pid_v = item ? item->spec : NULL;
10871 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
10872 : : struct mlx5_priv *priv;
10873 : : uint16_t mask, id;
10874 : : uint32_t vport_meta;
10875 : :
10876 : : MLX5_ASSERT(wks);
10877 [ # # # # ]: 0 : if (pid_v && pid_v->id == MLX5_PORT_ESW_MGR) {
10878 : 0 : flow_dv_translate_item_source_vport(key,
10879 [ # # ]: 0 : key_type & MLX5_SET_MATCHER_V ?
10880 : 0 : mlx5_flow_get_esw_manager_vport_id(dev) : 0xffff);
10881 : 0 : return 0;
10882 : : }
10883 [ # # ]: 0 : mask = pid_m ? pid_m->id : 0xffff;
10884 [ # # ]: 0 : id = pid_v ? pid_v->id : dev->data->port_id;
10885 : 0 : priv = mlx5_port_to_eswitch_info(id, item == NULL);
10886 [ # # ]: 0 : if (!priv)
10887 : 0 : return -rte_errno;
10888 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
10889 : : id = mask;
10890 : 0 : vport_meta = priv->vport_meta_mask;
10891 : : } else {
10892 : 0 : id = priv->vport_id;
10893 : 0 : vport_meta = priv->vport_meta_tag;
10894 : 0 : wks->vport_meta_tag = vport_meta;
10895 : : }
10896 : : /*
10897 : : * Translate to vport field or to metadata, depending on mode.
10898 : : * Kernel can use either misc.source_port or half of C0 metadata
10899 : : * register.
10900 : : */
10901 [ # # ]: 0 : if (priv->vport_meta_mask) {
10902 : : /*
10903 : : * Provide the hint for SW steering library
10904 : : * to insert the flow into ingress domain and
10905 : : * save the extra vport match.
10906 : : */
10907 [ # # # # ]: 0 : if (mask == 0xffff && priv->vport_id == 0xffff &&
10908 [ # # # # ]: 0 : priv->pf_bond < 0 && attr->transfer)
10909 [ # # ]: 0 : flow_dv_translate_item_source_vport(key, id);
10910 : : /*
10911 : : * We should always set the vport metadata register,
10912 : : * otherwise the SW steering library can drop
10913 : : * the rule if wire vport metadata value is not zero,
10914 : : * it depends on kernel configuration.
10915 : : */
10916 : 0 : flow_dv_translate_item_meta_vport
10917 : : (key, vport_meta, priv->vport_meta_mask);
10918 : : } else {
10919 [ # # ]: 0 : flow_dv_translate_item_source_vport(key, id);
10920 : : }
10921 : : return 0;
10922 : : }
10923 : :
10924 : : /**
10925 : : * Translate port representor item to eswitch match on port id.
10926 : : *
10927 : : * @param[in] dev
10928 : : * The devich to configure through.
10929 : : * @param[in, out] key
10930 : : * Flow matcher value.
10931 : : * @param[in] key_type
10932 : : * Set flow matcher mask or value.
10933 : : *
10934 : : * @return
10935 : : * 0 on success, a negative errno value otherwise.
10936 : : */
10937 : : static int
10938 : 0 : flow_dv_translate_item_port_representor(struct rte_eth_dev *dev, void *key,
10939 : : uint32_t key_type)
10940 : : {
10941 : 0 : flow_dv_translate_item_source_vport(key,
10942 [ # # ]: 0 : key_type & MLX5_SET_MATCHER_V ?
10943 : 0 : mlx5_flow_get_esw_manager_vport_id(dev) : 0xffff);
10944 : 0 : return 0;
10945 : : }
10946 : :
10947 : : /**
10948 : : * Translate represented port item to eswitch match on port id.
10949 : : *
10950 : : * @param[in] dev
10951 : : * The devich to configure through.
10952 : : * @param[in, out] key
10953 : : * Flow matcher value.
10954 : : * @param[in] item
10955 : : * Flow pattern to translate.
10956 : : * @param[in]
10957 : : * Flow attributes.
10958 : : *
10959 : : * @return
10960 : : * 0 on success, a negative errno value otherwise.
10961 : : */
10962 : : static int
10963 : 0 : flow_dv_translate_item_represented_port(struct rte_eth_dev *dev, void *key,
10964 : : const struct rte_flow_item *item,
10965 : : const struct rte_flow_attr *attr,
10966 : : uint32_t key_type)
10967 : : {
10968 [ # # ]: 0 : const struct rte_flow_item_ethdev *pid_m = item ? item->mask : NULL;
10969 [ # # ]: 0 : const struct rte_flow_item_ethdev *pid_v = item ? item->spec : NULL;
10970 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
10971 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10972 : : uint16_t mask, id;
10973 : : uint32_t vport_meta;
10974 : : bool vport_match = false;
10975 : :
10976 : : MLX5_ASSERT(wks);
10977 : : #ifndef HAVE_IBV_DEVICE_ATTR_ESW_MGR_REG_C0
10978 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
10979 : : vport_match = true;
10980 : : #endif
10981 [ # # ]: 0 : if (!pid_m && !pid_v)
10982 : : return 0;
10983 [ # # # # ]: 0 : if (pid_v && pid_v->port_id == UINT16_MAX) {
10984 [ # # # # ]: 0 : if (priv->sh->config.dv_flow_en != 2 || vport_match) {
10985 : 0 : flow_dv_translate_item_source_vport
10986 [ # # ]: 0 : (key, key_type & MLX5_SET_MATCHER_V ?
10987 : 0 : mlx5_flow_get_esw_manager_vport_id(dev) : 0xffff);
10988 : : } else {
10989 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10990 : 0 : vport_meta = priv->sh->dev_cap.esw_info.regc_mask;
10991 : : else
10992 : 0 : vport_meta = priv->sh->dev_cap.esw_info.regc_value;
10993 : 0 : flow_dv_translate_item_meta_vport(key, vport_meta,
10994 : : priv->sh->dev_cap.esw_info.regc_mask);
10995 : : }
10996 : 0 : return 0;
10997 : : }
10998 [ # # ]: 0 : mask = pid_m ? pid_m->port_id : UINT16_MAX;
10999 [ # # ]: 0 : id = pid_v ? pid_v->port_id : dev->data->port_id;
11000 : 0 : priv = mlx5_port_to_eswitch_info(id, item == NULL);
11001 [ # # ]: 0 : if (!priv)
11002 : 0 : return -rte_errno;
11003 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
11004 : : id = mask;
11005 : 0 : vport_meta = priv->vport_meta_mask;
11006 : : } else {
11007 : 0 : id = priv->vport_id;
11008 : 0 : vport_meta = priv->vport_meta_tag;
11009 : 0 : wks->vport_meta_tag = vport_meta;
11010 : : }
11011 : : /*
11012 : : * Translate to vport field or to metadata, depending on mode.
11013 : : * Kernel can use either misc.source_port or half of C0 metadata
11014 : : * register.
11015 : : */
11016 [ # # # # ]: 0 : if (priv->vport_meta_mask && !vport_match) {
11017 : : /*
11018 : : * Provide the hint for SW steering library
11019 : : * to insert the flow into ingress domain and
11020 : : * save the extra vport match.
11021 : : */
11022 [ # # # # ]: 0 : if (mask == UINT16_MAX && priv->vport_id == UINT16_MAX &&
11023 [ # # # # ]: 0 : priv->pf_bond < 0 && attr->transfer &&
11024 [ # # ]: 0 : priv->sh->config.dv_flow_en != 2)
11025 [ # # ]: 0 : flow_dv_translate_item_source_vport(key, id);
11026 : : /*
11027 : : * We should always set the vport metadata register,
11028 : : * otherwise the SW steering library can drop
11029 : : * the rule if wire vport metadata value is not zero,
11030 : : * it depends on kernel configuration.
11031 : : */
11032 : 0 : flow_dv_translate_item_meta_vport(key, vport_meta,
11033 : : priv->vport_meta_mask);
11034 : : } else {
11035 [ # # ]: 0 : flow_dv_translate_item_source_vport(key, id);
11036 : : }
11037 : : return 0;
11038 : : }
11039 : :
11040 : : /**
11041 : : * Translate port-id item to eswitch match on port-id.
11042 : : *
11043 : : * @param[in] dev
11044 : : * The devich to configure through.
11045 : : * @param[in, out] matcher
11046 : : * Flow matcher.
11047 : : * @param[in, out] key
11048 : : * Flow matcher value.
11049 : : * @param[in] item
11050 : : * Flow pattern to translate.
11051 : : * @param[in] attr
11052 : : * Flow attributes.
11053 : : *
11054 : : * @return
11055 : : * 0 on success, a negative errno value otherwise.
11056 : : */
11057 : : static int
11058 : 0 : flow_dv_translate_item_port_id_all(struct rte_eth_dev *dev,
11059 : : void *matcher, void *key,
11060 : : const struct rte_flow_item *item,
11061 : : const struct rte_flow_attr *attr)
11062 : : {
11063 : : int ret;
11064 : :
11065 : 0 : ret = flow_dv_translate_item_port_id
11066 : : (dev, matcher, item, attr, MLX5_SET_MATCHER_SW_M);
11067 [ # # ]: 0 : if (ret)
11068 : : return ret;
11069 : 0 : ret = flow_dv_translate_item_port_id
11070 : : (dev, key, item, attr, MLX5_SET_MATCHER_SW_V);
11071 : 0 : return ret;
11072 : : }
11073 : :
11074 : :
11075 : : /**
11076 : : * Add ICMP6 item to the value.
11077 : : *
11078 : : * @param[in, out] key
11079 : : * Flow matcher value.
11080 : : * @param[in] item
11081 : : * Flow pattern to translate.
11082 : : * @param[in] inner
11083 : : * Item is inner pattern.
11084 : : * @param[in] key_type
11085 : : * Set flow matcher mask or value.
11086 : : */
11087 : : static void
11088 : 0 : flow_dv_translate_item_icmp6(void *key, const struct rte_flow_item *item,
11089 : : int inner, uint32_t key_type)
11090 : : {
11091 : : const struct rte_flow_item_icmp6 *icmp6_m;
11092 : : const struct rte_flow_item_icmp6 *icmp6_v;
11093 : : void *headers_v;
11094 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
11095 : :
11096 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
11097 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11098 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11099 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, 0xFF);
11100 : : else
11101 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
11102 : : IPPROTO_ICMPV6);
11103 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11104 : : return;
11105 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, icmp6_v, icmp6_m,
# # # # ]
11106 : : &rte_flow_item_icmp6_mask);
11107 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type,
11108 : : icmp6_v->type & icmp6_m->type);
11109 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code,
11110 : : icmp6_v->code & icmp6_m->code);
11111 : : }
11112 : :
11113 : : /**
11114 : : * Add ICMP6 echo request/reply item to the value.
11115 : : *
11116 : : * @param[in, out] key
11117 : : * Flow matcher value.
11118 : : * @param[in] item
11119 : : * Flow pattern to translate.
11120 : : * @param[in] inner
11121 : : * Item is inner pattern.
11122 : : * @param[in] key_type
11123 : : * Set flow matcher mask or value.
11124 : : */
11125 : : static void
11126 [ # # ]: 0 : flow_dv_translate_item_icmp6_echo(void *key, const struct rte_flow_item *item,
11127 : : int inner, uint32_t key_type)
11128 : : {
11129 : : const struct rte_flow_item_icmp6_echo *icmp6_m;
11130 : : const struct rte_flow_item_icmp6_echo *icmp6_v;
11131 : : uint32_t icmp6_header_data_m = 0;
11132 : : uint32_t icmp6_header_data_v = 0;
11133 : : void *headers_v;
11134 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
11135 : : uint8_t icmp6_type = 0;
11136 : : struct rte_flow_item_icmp6_echo zero_mask;
11137 : :
11138 : : memset(&zero_mask, 0, sizeof(zero_mask));
11139 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
11140 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11141 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11142 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, 0xFF);
11143 : : else
11144 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
11145 : : IPPROTO_ICMPV6);
11146 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, icmp6_v, icmp6_m, &zero_mask);
# # # # ]
11147 : : /* Set fixed type and code for icmpv6 echo request or reply */
11148 [ # # ]: 0 : icmp6_type = (item->type == RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REQUEST ?
11149 : : RTE_ICMP6_ECHO_REQUEST : RTE_ICMP6_ECHO_REPLY);
11150 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
11151 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type, 0xFF);
11152 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code, 0xFF);
11153 : : } else {
11154 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type, icmp6_type);
11155 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code, 0);
11156 : : }
11157 [ # # ]: 0 : if (icmp6_v == NULL)
11158 : 0 : return;
11159 : : /* Set icmp6 header data (identifier & sequence) accordingly */
11160 : 0 : icmp6_header_data_m =
11161 [ # # ]: 0 : (rte_be_to_cpu_16(icmp6_m->hdr.identifier) << 16) |
11162 [ # # ]: 0 : rte_be_to_cpu_16(icmp6_m->hdr.sequence);
11163 [ # # ]: 0 : if (icmp6_header_data_m) {
11164 : 0 : icmp6_header_data_v =
11165 [ # # ]: 0 : (rte_be_to_cpu_16(icmp6_v->hdr.identifier) << 16) |
11166 [ # # ]: 0 : rte_be_to_cpu_16(icmp6_v->hdr.sequence);
11167 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_header_data,
11168 : : icmp6_header_data_v & icmp6_header_data_m);
11169 : : }
11170 : : }
11171 : :
11172 : : /**
11173 : : * Add ICMP item to the value.
11174 : : *
11175 : : * @param[in, out] key
11176 : : * Flow matcher value.
11177 : : * @param[in] item
11178 : : * Flow pattern to translate.
11179 : : * @param[in] inner
11180 : : * Item is inner pattern.
11181 : : * @param[in] key_type
11182 : : * Set flow matcher mask or value.
11183 : : */
11184 : : static void
11185 : 0 : flow_dv_translate_item_icmp(void *key, const struct rte_flow_item *item,
11186 : : int inner, uint32_t key_type)
11187 : : {
11188 : : const struct rte_flow_item_icmp *icmp_m;
11189 : : const struct rte_flow_item_icmp *icmp_v;
11190 : : uint32_t icmp_header_data_m = 0;
11191 : : uint32_t icmp_header_data_v = 0;
11192 : : void *headers_v;
11193 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
11194 : :
11195 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
11196 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11197 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11198 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11199 : : ip_protocol, 0xFF);
11200 : : else
11201 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11202 : : ip_protocol, IPPROTO_ICMP);
11203 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11204 : : return;
11205 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, icmp_v, icmp_m,
# # # # ]
11206 : : &rte_flow_item_icmp_mask);
11207 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmp_type,
11208 : : icmp_v->hdr.icmp_type & icmp_m->hdr.icmp_type);
11209 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmp_code,
11210 : : icmp_v->hdr.icmp_code & icmp_m->hdr.icmp_code);
11211 [ # # ]: 0 : icmp_header_data_m = rte_be_to_cpu_16(icmp_m->hdr.icmp_seq_nb);
11212 [ # # ]: 0 : icmp_header_data_m |= rte_be_to_cpu_16(icmp_m->hdr.icmp_ident) << 16;
11213 [ # # ]: 0 : if (icmp_header_data_m) {
11214 [ # # ]: 0 : icmp_header_data_v = rte_be_to_cpu_16(icmp_v->hdr.icmp_seq_nb);
11215 : 0 : icmp_header_data_v |=
11216 [ # # ]: 0 : rte_be_to_cpu_16(icmp_v->hdr.icmp_ident) << 16;
11217 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmp_header_data,
11218 : : icmp_header_data_v & icmp_header_data_m);
11219 : : }
11220 : : }
11221 : :
11222 : : /**
11223 : : * Add GTP item to the value.
11224 : : *
11225 : : * @param[in, out] key
11226 : : * Flow matcher value.
11227 : : * @param[in] item
11228 : : * Flow pattern to translate.
11229 : : * @param[in] inner
11230 : : * Item is inner pattern.
11231 : : * @param[in] key_type
11232 : : * Set flow matcher mask or value.
11233 : : */
11234 : : static void
11235 : 0 : flow_dv_translate_item_gtp(void *key, const struct rte_flow_item *item,
11236 : : int inner, uint32_t key_type)
11237 : : {
11238 : : const struct rte_flow_item_gtp *gtp_m;
11239 : : const struct rte_flow_item_gtp *gtp_v;
11240 : : void *headers_v;
11241 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
11242 : : uint16_t dport = RTE_GTPU_UDP_PORT;
11243 : :
11244 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
11245 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11246 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
11247 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11248 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11249 : : udp_dport, 0xFFFF);
11250 : : else
11251 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11252 : : udp_dport, dport);
11253 : : }
11254 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11255 : : return;
11256 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, gtp_v, gtp_m,
# # # # ]
11257 : : &rte_flow_item_gtp_mask);
11258 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags,
11259 : : gtp_v->hdr.gtp_hdr_info & gtp_m->hdr.gtp_hdr_info);
11260 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_type,
11261 : : gtp_v->hdr.msg_type & gtp_m->hdr.msg_type);
11262 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_teid,
11263 : : rte_be_to_cpu_32(gtp_v->hdr.teid & gtp_m->hdr.teid));
11264 : : }
11265 : :
11266 : : /**
11267 : : * Add GTP PSC item to matcher.
11268 : : *
11269 : : * @param[in, out] key
11270 : : * Flow matcher value.
11271 : : * @param[in] item
11272 : : * Flow pattern to translate.
11273 : : * @param[in] key_type
11274 : : * Set flow matcher mask or value.
11275 : : */
11276 : : static int
11277 : 0 : flow_dv_translate_item_gtp_psc(void *key, const struct rte_flow_item *item,
11278 : : uint32_t key_type)
11279 : : {
11280 : : const struct rte_flow_item_gtp_psc *gtp_psc_m;
11281 : : const struct rte_flow_item_gtp_psc *gtp_psc_v;
11282 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
11283 : : union {
11284 : : uint32_t w32;
11285 : : struct {
11286 : : uint16_t seq_num;
11287 : : uint8_t npdu_num;
11288 : : uint8_t next_ext_header_type;
11289 : : };
11290 : : } dw_2;
11291 : : union {
11292 : : uint32_t w32;
11293 : : struct {
11294 : : uint8_t len;
11295 : : uint8_t type_flags;
11296 : : uint8_t qfi;
11297 : : uint8_t reserved;
11298 : : };
11299 : : } dw_0;
11300 : : uint8_t gtp_flags;
11301 : :
11302 : : /* Always set E-flag match on one, regardless of GTP item settings. */
11303 [ # # ]: 0 : gtp_flags = MLX5_GET(fte_match_set_misc3, misc3_v, gtpu_msg_flags);
11304 : 0 : gtp_flags |= MLX5_GTP_EXT_HEADER_FLAG;
11305 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags, gtp_flags);
11306 : : /*Set next extension header type. */
11307 : 0 : dw_2.seq_num = 0;
11308 : 0 : dw_2.npdu_num = 0;
11309 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11310 : 0 : dw_2.next_ext_header_type = 0xff;
11311 : : else
11312 : 0 : dw_2.next_ext_header_type = 0x85;
11313 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_dw_2,
11314 : : rte_cpu_to_be_32(dw_2.w32));
11315 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11316 : : return 0;
11317 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, gtp_psc_v,
# # # # ]
11318 : : gtp_psc_m, &rte_flow_item_gtp_psc_mask);
11319 : 0 : dw_0.w32 = 0;
11320 : 0 : dw_0.type_flags = MLX5_GTP_PDU_TYPE_SHIFT(gtp_psc_v->hdr.type &
11321 : : gtp_psc_m->hdr.type);
11322 : 0 : dw_0.qfi = gtp_psc_v->hdr.qfi & gtp_psc_m->hdr.qfi;
11323 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_first_ext_dw_0,
11324 : : rte_cpu_to_be_32(dw_0.w32));
11325 : 0 : return 0;
11326 : : }
11327 : :
11328 : : /**
11329 : : * Add eCPRI item to matcher and to the value.
11330 : : *
11331 : : * @param[in] dev
11332 : : * The devich to configure through.
11333 : : * @param[in, out] key
11334 : : * Flow matcher value.
11335 : : * @param[in] item
11336 : : * Flow pattern to translate.
11337 : : * @param[in] last_item
11338 : : * Last item flags.
11339 : : * @param[in] key_type
11340 : : * Set flow matcher mask or value.
11341 : : */
11342 : : static void
11343 : 0 : flow_dv_translate_item_ecpri(struct rte_eth_dev *dev, void *key,
11344 : : const struct rte_flow_item *item,
11345 : : uint64_t last_item, uint32_t key_type)
11346 : : {
11347 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11348 : : const struct rte_flow_item_ecpri *ecpri_m;
11349 : : const struct rte_flow_item_ecpri *ecpri_v;
11350 : 0 : const struct rte_flow_item_ecpri *ecpri_vv = item->spec;
11351 : : struct rte_ecpri_common_hdr common;
11352 : : void *misc4_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_4);
11353 : : uint32_t *samples;
11354 : : void *dw_v;
11355 : :
11356 : : /*
11357 : : * In case of eCPRI over Ethernet, if EtherType is not specified,
11358 : : * match on eCPRI EtherType implicitly.
11359 : : */
11360 [ # # ]: 0 : if (last_item & MLX5_FLOW_LAYER_OUTER_L2) {
11361 : : void *hdrs_v, *l2v;
11362 : :
11363 : : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11364 : : l2v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, ethertype);
11365 [ # # ]: 0 : if (*(uint16_t *)l2v == 0) {
11366 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11367 : 0 : *(uint16_t *)l2v = UINT16_MAX;
11368 : : else
11369 : 0 : *(uint16_t *)l2v =
11370 : : RTE_BE16(RTE_ETHER_TYPE_ECPRI);
11371 : : }
11372 : : }
11373 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11374 : 0 : return;
11375 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, ecpri_v, ecpri_m,
# # # # ]
11376 : : &rte_flow_item_ecpri_mask);
11377 : : /*
11378 : : * Maximal four DW samples are supported in a single matching now.
11379 : : * Two are used now for a eCPRI matching:
11380 : : * 1. Type: one byte, mask should be 0x00ff0000 in network order
11381 : : * 2. ID of a message: one or two bytes, mask 0xffff0000 or 0xff000000
11382 : : * if any.
11383 : : */
11384 [ # # ]: 0 : if (!ecpri_m->hdr.common.u32)
11385 : : return;
11386 : 0 : samples = priv->sh->ecpri_parser.ids;
11387 : : /* Need to take the whole DW as the mask to fill the entry. */
11388 : : dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
11389 : : prog_sample_field_value_0);
11390 : : /* Already big endian (network order) in the header. */
11391 : 0 : *(uint32_t *)dw_v = ecpri_v->hdr.common.u32 & ecpri_m->hdr.common.u32;
11392 : : /* Sample#0, used for matching type, offset 0. */
11393 : : /* It makes no sense to set the sample ID in the mask field. */
11394 [ # # ]: 0 : MLX5_SET(fte_match_set_misc4, misc4_v,
11395 : : prog_sample_field_id_0, samples[0]);
11396 : : /*
11397 : : * Checking if message body part needs to be matched.
11398 : : * Some wildcard rules only matching type field should be supported.
11399 : : */
11400 [ # # ]: 0 : if (ecpri_m->hdr.dummy[0]) {
11401 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M)
11402 [ # # ]: 0 : common.u32 = rte_be_to_cpu_32(ecpri_vv->hdr.common.u32);
11403 : : else
11404 [ # # ]: 0 : common.u32 = rte_be_to_cpu_32(ecpri_v->hdr.common.u32);
11405 [ # # ]: 0 : switch (common.type) {
11406 : 0 : case RTE_ECPRI_MSG_TYPE_IQ_DATA:
11407 : : case RTE_ECPRI_MSG_TYPE_RTC_CTRL:
11408 : : case RTE_ECPRI_MSG_TYPE_DLY_MSR:
11409 : : dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
11410 : : prog_sample_field_value_1);
11411 : 0 : *(uint32_t *)dw_v = ecpri_v->hdr.dummy[0] &
11412 : : ecpri_m->hdr.dummy[0];
11413 : : /* Sample#1, to match message body, offset 4. */
11414 [ # # ]: 0 : MLX5_SET(fte_match_set_misc4, misc4_v,
11415 : : prog_sample_field_id_1, samples[1]);
11416 : 0 : break;
11417 : : default:
11418 : : /* Others, do not match any sample ID. */
11419 : : break;
11420 : : }
11421 : : }
11422 : : }
11423 : :
11424 : : /*
11425 : : * Add connection tracking status item to matcher
11426 : : *
11427 : : * @param[in] dev
11428 : : * The devich to configure through.
11429 : : * @param[in, out] matcher
11430 : : * Flow matcher.
11431 : : * @param[in, out] key
11432 : : * Flow matcher value.
11433 : : * @param[in] item
11434 : : * Flow pattern to translate.
11435 : : */
11436 : : static void
11437 : 0 : flow_dv_translate_item_aso_ct(struct rte_eth_dev *dev,
11438 : : void *matcher, void *key,
11439 : : const struct rte_flow_item *item)
11440 : : {
11441 : : uint32_t reg_value = 0;
11442 : : int reg_id;
11443 : : /* 8LSB 0b 11/0000/11, middle 4 bits are reserved. */
11444 : : uint32_t reg_mask = 0;
11445 : 0 : const struct rte_flow_item_conntrack *spec = item->spec;
11446 : 0 : const struct rte_flow_item_conntrack *mask = item->mask;
11447 : : uint32_t flags;
11448 : : struct rte_flow_error error;
11449 : :
11450 [ # # ]: 0 : if (!mask)
11451 : : mask = &rte_flow_item_conntrack_mask;
11452 [ # # # # ]: 0 : if (!spec || !mask->flags)
11453 : 0 : return;
11454 : 0 : flags = spec->flags & mask->flags;
11455 : : /* The conflict should be checked in the validation. */
11456 : : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_VALID)
11457 : : reg_value |= MLX5_CT_SYNDROME_VALID;
11458 [ # # ]: 0 : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_CHANGED)
11459 : : reg_value |= MLX5_CT_SYNDROME_STATE_CHANGE;
11460 [ # # ]: 0 : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_INVALID)
11461 : 0 : reg_value |= MLX5_CT_SYNDROME_INVALID;
11462 [ # # ]: 0 : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED)
11463 : 0 : reg_value |= MLX5_CT_SYNDROME_TRAP;
11464 [ # # ]: 0 : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD)
11465 : 0 : reg_value |= MLX5_CT_SYNDROME_BAD_PACKET;
11466 [ # # ]: 0 : if (mask->flags & (RTE_FLOW_CONNTRACK_PKT_STATE_VALID |
11467 : : RTE_FLOW_CONNTRACK_PKT_STATE_INVALID |
11468 : : RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED))
11469 : : reg_mask |= 0xc0;
11470 [ # # ]: 0 : if (mask->flags & RTE_FLOW_CONNTRACK_PKT_STATE_CHANGED)
11471 : 0 : reg_mask |= MLX5_CT_SYNDROME_STATE_CHANGE;
11472 [ # # ]: 0 : if (mask->flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD)
11473 : 0 : reg_mask |= MLX5_CT_SYNDROME_BAD_PACKET;
11474 : : /* The REG_C_x value could be saved during startup. */
11475 : 0 : reg_id = mlx5_flow_get_reg_id(dev, MLX5_ASO_CONNTRACK, 0, &error);
11476 [ # # ]: 0 : if (reg_id == REG_NON)
11477 : : return;
11478 : 0 : flow_dv_match_meta_reg_all(matcher, key, (enum modify_reg)reg_id,
11479 : : reg_value, reg_mask);
11480 : : }
11481 : :
11482 : : static void
11483 : 0 : flow_dv_translate_item_flex(struct rte_eth_dev *dev, void *matcher, void *key,
11484 : : const struct rte_flow_item *item,
11485 : : struct mlx5_flow *dev_flow, bool is_inner)
11486 : : {
11487 : 0 : const struct rte_flow_item_flex *spec =
11488 : : (const struct rte_flow_item_flex *)item->spec;
11489 : 0 : int index = mlx5_flex_acquire_index(dev, spec->handle, false);
11490 : :
11491 : : MLX5_ASSERT(index >= 0 && index < (int)(sizeof(uint32_t) * CHAR_BIT));
11492 [ # # ]: 0 : if (index < 0)
11493 : : return;
11494 [ # # ]: 0 : if (!(dev_flow->handle->flex_item & RTE_BIT32(index))) {
11495 : : /* Don't count both inner and outer flex items in one rule. */
11496 : 0 : if (mlx5_flex_acquire_index(dev, spec->handle, true) != index)
11497 : : MLX5_ASSERT(false);
11498 : 0 : dev_flow->handle->flex_item |= (uint8_t)RTE_BIT32(index);
11499 : : }
11500 : 0 : mlx5_flex_flow_translate_item(dev, matcher, key, item, is_inner);
11501 : : }
11502 : :
11503 : : /**
11504 : : * Add METER_COLOR item to matcher
11505 : : *
11506 : : * @param[in] dev
11507 : : * The device to configure through.
11508 : : * @param[in, out] key
11509 : : * Flow matcher value.
11510 : : * @param[in] item
11511 : : * Flow pattern to translate.
11512 : : * @param[in] key_type
11513 : : * Set flow matcher mask or value.
11514 : : */
11515 : : static void
11516 : 0 : flow_dv_translate_item_meter_color(struct rte_eth_dev *dev, void *key,
11517 : : const struct rte_flow_item *item,
11518 : : uint32_t key_type)
11519 : : {
11520 : 0 : const struct rte_flow_item_meter_color *color_m = item->mask;
11521 : 0 : const struct rte_flow_item_meter_color *color_v = item->spec;
11522 : : uint32_t value, mask;
11523 : : int reg = REG_NON;
11524 : :
11525 : : MLX5_ASSERT(color_v);
11526 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11527 : : return;
11528 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, color_v, color_m,
# # # # ]
11529 : : &rte_flow_item_meter_color_mask);
11530 [ # # ]: 0 : value = rte_col_2_mlx5_col(color_v->color);
11531 : : mask = color_m ?
11532 [ # # ]: 0 : color_m->color : (UINT32_C(1) << MLX5_MTR_COLOR_BITS) - 1;
11533 [ # # ]: 0 : if (!!(key_type & MLX5_SET_MATCHER_SW))
11534 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, NULL);
11535 : : else
11536 : : reg = flow_hw_get_reg_id(dev,
11537 : : RTE_FLOW_ITEM_TYPE_METER_COLOR, 0);
11538 [ # # ]: 0 : if (reg == REG_NON)
11539 : : return;
11540 : 0 : flow_dv_match_meta_reg(key, (enum modify_reg)reg, value, mask);
11541 : : }
11542 : :
11543 : : static void
11544 : 0 : flow_dv_translate_item_aggr_affinity(void *key,
11545 : : const struct rte_flow_item *item,
11546 : : uint32_t key_type)
11547 : : {
11548 : : const struct rte_flow_item_aggr_affinity *affinity_v;
11549 : : const struct rte_flow_item_aggr_affinity *affinity_m;
11550 : : void *misc_v;
11551 : :
11552 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, affinity_v, affinity_m,
# # # # ]
11553 : : &rte_flow_item_aggr_affinity_mask);
11554 : : misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
11555 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, lag_rx_port_affinity,
11556 : : affinity_v->affinity & affinity_m->affinity);
11557 : 0 : }
11558 : :
11559 : : static void
11560 : 0 : flow_dv_translate_item_ib_bth(void *key,
11561 : : const struct rte_flow_item *item,
11562 : : int inner, uint32_t key_type)
11563 : : {
11564 : : const struct rte_flow_item_ib_bth *bth_m;
11565 : : const struct rte_flow_item_ib_bth *bth_v;
11566 : : void *headers_v, *misc_v;
11567 : : uint16_t udp_dport;
11568 : : char *qpn_v;
11569 : : int i, size;
11570 : :
11571 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
11572 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11573 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
11574 [ # # ]: 0 : udp_dport = key_type & MLX5_SET_MATCHER_M ?
11575 : : 0xFFFF : MLX5_UDP_PORT_ROCEv2;
11576 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, udp_dport);
11577 : : }
11578 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11579 : : return;
11580 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, bth_v, bth_m, &rte_flow_item_ib_bth_mask);
# # # # ]
11581 : : misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
11582 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, bth_opcode,
11583 : : bth_v->hdr.opcode & bth_m->hdr.opcode);
11584 : 0 : qpn_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, bth_dst_qp);
11585 : : size = sizeof(bth_m->hdr.dst_qp);
11586 [ # # ]: 0 : for (i = 0; i < size; ++i)
11587 : 0 : qpn_v[i] = bth_m->hdr.dst_qp[i] & bth_v->hdr.dst_qp[i];
11588 : : }
11589 : :
11590 : : static uint32_t matcher_zero[MLX5_ST_SZ_DW(fte_match_param)] = { 0 };
11591 : :
11592 : : #define HEADER_IS_ZERO(match_criteria, headers) \
11593 : : !(memcmp(MLX5_ADDR_OF(fte_match_param, match_criteria, headers), \
11594 : : matcher_zero, MLX5_FLD_SZ_BYTES(fte_match_param, headers))) \
11595 : :
11596 : : /**
11597 : : * Calculate flow matcher enable bitmap.
11598 : : *
11599 : : * @param match_criteria
11600 : : * Pointer to flow matcher criteria.
11601 : : *
11602 : : * @return
11603 : : * Bitmap of enabled fields.
11604 : : */
11605 : : static uint8_t
11606 : 0 : flow_dv_matcher_enable(uint32_t *match_criteria)
11607 : : {
11608 : : uint8_t match_criteria_enable;
11609 : :
11610 : : match_criteria_enable =
11611 : 0 : (!HEADER_IS_ZERO(match_criteria, outer_headers)) <<
11612 : : MLX5_MATCH_CRITERIA_ENABLE_OUTER_BIT;
11613 : 0 : match_criteria_enable |=
11614 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters)) <<
11615 : : MLX5_MATCH_CRITERIA_ENABLE_MISC_BIT;
11616 : 0 : match_criteria_enable |=
11617 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, inner_headers)) <<
11618 : : MLX5_MATCH_CRITERIA_ENABLE_INNER_BIT;
11619 : 0 : match_criteria_enable |=
11620 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) <<
11621 : : MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
11622 : 0 : match_criteria_enable |=
11623 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters_3)) <<
11624 : : MLX5_MATCH_CRITERIA_ENABLE_MISC3_BIT;
11625 : 0 : match_criteria_enable |=
11626 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters_4)) <<
11627 : : MLX5_MATCH_CRITERIA_ENABLE_MISC4_BIT;
11628 : 0 : match_criteria_enable |=
11629 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters_5)) <<
11630 : : MLX5_MATCH_CRITERIA_ENABLE_MISC5_BIT;
11631 : 0 : return match_criteria_enable;
11632 : : }
11633 : :
11634 : : static void
11635 : : __flow_dv_adjust_buf_size(size_t *size, uint8_t match_criteria)
11636 : : {
11637 : : /*
11638 : : * Check flow matching criteria first, subtract misc5/4 length if flow
11639 : : * doesn't own misc5/4 parameters. In some old rdma-core releases,
11640 : : * misc5/4 are not supported, and matcher creation failure is expected
11641 : : * w/o subtraction. If misc5 is provided, misc4 must be counted in since
11642 : : * misc5 is right after misc4.
11643 : : */
11644 : 0 : if (!(match_criteria & (1 << MLX5_MATCH_CRITERIA_ENABLE_MISC5_BIT))) {
11645 : 0 : *size = MLX5_ST_SZ_BYTES(fte_match_param) -
11646 : : MLX5_ST_SZ_BYTES(fte_match_set_misc5);
11647 [ # # # # : 0 : if (!(match_criteria & (1 <<
# # # # #
# # # # #
# # # # #
# ]
11648 : : MLX5_MATCH_CRITERIA_ENABLE_MISC4_BIT))) {
11649 : 0 : *size -= MLX5_ST_SZ_BYTES(fte_match_set_misc4);
11650 : : }
11651 : : }
11652 : : }
11653 : :
11654 : : struct mlx5_list_entry *
11655 : 0 : flow_matcher_clone_cb(void *tool_ctx __rte_unused,
11656 : : struct mlx5_list_entry *entry, void *cb_ctx)
11657 : : {
11658 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11659 : 0 : struct mlx5_flow_dv_matcher *ref = ctx->data;
11660 : 0 : struct mlx5_flow_tbl_data_entry *tbl = container_of(ref->tbl,
11661 : : typeof(*tbl), tbl);
11662 : 0 : struct mlx5_flow_dv_matcher *resource = mlx5_malloc(MLX5_MEM_ANY,
11663 : : sizeof(*resource),
11664 : : 0, SOCKET_ID_ANY);
11665 : :
11666 [ # # ]: 0 : if (!resource) {
11667 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
11668 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11669 : : "cannot create matcher");
11670 : 0 : return NULL;
11671 : : }
11672 : : memcpy(resource, entry, sizeof(*resource));
11673 : 0 : resource->tbl = &tbl->tbl;
11674 : 0 : return &resource->entry;
11675 : : }
11676 : :
11677 : : void
11678 : 0 : flow_matcher_clone_free_cb(void *tool_ctx __rte_unused,
11679 : : struct mlx5_list_entry *entry)
11680 : : {
11681 : 0 : mlx5_free(entry);
11682 : 0 : }
11683 : :
11684 : : struct mlx5_list_entry *
11685 : 0 : flow_dv_tbl_create_cb(void *tool_ctx, void *cb_ctx)
11686 : : {
11687 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11688 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11689 : 0 : struct rte_eth_dev *dev = ctx->dev;
11690 : : struct mlx5_flow_tbl_data_entry *tbl_data;
11691 : 0 : struct mlx5_flow_tbl_tunnel_prm *tt_prm = ctx->data2;
11692 : 0 : struct rte_flow_error *error = ctx->error;
11693 : 0 : union mlx5_flow_tbl_key key = { .v64 = *(uint64_t *)(ctx->data) };
11694 : : struct mlx5_flow_tbl_resource *tbl;
11695 : : void *domain;
11696 : 0 : uint32_t idx = 0;
11697 : : int ret;
11698 : :
11699 : 0 : tbl_data = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_JUMP], &idx);
11700 [ # # ]: 0 : if (!tbl_data) {
11701 : 0 : rte_flow_error_set(error, ENOMEM,
11702 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11703 : : NULL,
11704 : : "cannot allocate flow table data entry");
11705 : 0 : return NULL;
11706 : : }
11707 : 0 : tbl_data->idx = idx;
11708 : 0 : tbl_data->tunnel = tt_prm->tunnel;
11709 : 0 : tbl_data->group_id = tt_prm->group_id;
11710 [ # # ]: 0 : tbl_data->external = !!tt_prm->external;
11711 : 0 : tbl_data->tunnel_offload = is_tunnel_offload_active(dev);
11712 : 0 : tbl_data->is_egress = !!key.is_egress;
11713 : 0 : tbl_data->is_transfer = !!key.is_fdb;
11714 : 0 : tbl_data->dummy = !!key.dummy;
11715 : 0 : tbl_data->level = key.level;
11716 : 0 : tbl_data->id = key.id;
11717 : : tbl = &tbl_data->tbl;
11718 [ # # ]: 0 : if (key.dummy)
11719 : 0 : return &tbl_data->entry;
11720 [ # # ]: 0 : if (key.is_fdb)
11721 : 0 : domain = sh->fdb_domain;
11722 [ # # ]: 0 : else if (key.is_egress)
11723 : 0 : domain = sh->tx_domain;
11724 : : else
11725 : 0 : domain = sh->rx_domain;
11726 : : ret = mlx5_flow_os_create_flow_tbl(domain, key.level, &tbl->obj);
11727 : : if (ret) {
11728 : 0 : rte_flow_error_set(error, ENOMEM,
11729 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11730 : : NULL, "cannot create flow table object");
11731 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
11732 : 0 : return NULL;
11733 : : }
11734 [ # # ]: 0 : if (key.level != 0) {
11735 : : ret = mlx5_flow_os_create_flow_action_dest_flow_tbl
11736 : : (tbl->obj, &tbl_data->jump.action);
11737 : : if (ret) {
11738 : 0 : rte_flow_error_set(error, ENOMEM,
11739 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11740 : : NULL,
11741 : : "cannot create flow jump action");
11742 : 0 : mlx5_flow_os_destroy_flow_tbl(tbl->obj);
11743 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
11744 : 0 : return NULL;
11745 : : }
11746 : : }
11747 [ # # # # ]: 0 : MKSTR(matcher_name, "%s_%s_%u_%u_matcher_list",
11748 : : key.is_fdb ? "FDB" : "NIC", key.is_egress ? "egress" : "ingress",
11749 : : key.level, key.id);
11750 : 0 : tbl_data->matchers = mlx5_list_create(matcher_name, sh, true,
11751 : : flow_matcher_create_cb,
11752 : : flow_matcher_match_cb,
11753 : : flow_matcher_remove_cb,
11754 : : flow_matcher_clone_cb,
11755 : : flow_matcher_clone_free_cb);
11756 [ # # ]: 0 : if (!tbl_data->matchers) {
11757 : 0 : rte_flow_error_set(error, ENOMEM,
11758 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11759 : : NULL,
11760 : : "cannot create tbl matcher list");
11761 : 0 : mlx5_flow_os_destroy_flow_action(tbl_data->jump.action);
11762 : 0 : mlx5_flow_os_destroy_flow_tbl(tbl->obj);
11763 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
11764 : 0 : return NULL;
11765 : : }
11766 : 0 : return &tbl_data->entry;
11767 : : }
11768 : :
11769 : : int
11770 : 0 : flow_dv_tbl_match_cb(void *tool_ctx __rte_unused, struct mlx5_list_entry *entry,
11771 : : void *cb_ctx)
11772 : : {
11773 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11774 : : struct mlx5_flow_tbl_data_entry *tbl_data =
11775 : : container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
11776 : 0 : union mlx5_flow_tbl_key key = { .v64 = *(uint64_t *)(ctx->data) };
11777 : :
11778 : 0 : return tbl_data->level != key.level ||
11779 [ # # ]: 0 : tbl_data->id != key.id ||
11780 [ # # ]: 0 : tbl_data->dummy != key.dummy ||
11781 [ # # # # ]: 0 : tbl_data->is_transfer != !!key.is_fdb ||
11782 [ # # ]: 0 : tbl_data->is_egress != !!key.is_egress;
11783 : : }
11784 : :
11785 : : struct mlx5_list_entry *
11786 : 0 : flow_dv_tbl_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
11787 : : void *cb_ctx)
11788 : : {
11789 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11790 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11791 : : struct mlx5_flow_tbl_data_entry *tbl_data;
11792 : 0 : struct rte_flow_error *error = ctx->error;
11793 : 0 : uint32_t idx = 0;
11794 : :
11795 : 0 : tbl_data = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_JUMP], &idx);
11796 [ # # ]: 0 : if (!tbl_data) {
11797 : 0 : rte_flow_error_set(error, ENOMEM,
11798 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11799 : : NULL,
11800 : : "cannot allocate flow table data entry");
11801 : 0 : return NULL;
11802 : : }
11803 : : memcpy(tbl_data, oentry, sizeof(*tbl_data));
11804 : 0 : tbl_data->idx = idx;
11805 : 0 : return &tbl_data->entry;
11806 : : }
11807 : :
11808 : : void
11809 : 0 : flow_dv_tbl_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
11810 : : {
11811 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11812 : : struct mlx5_flow_tbl_data_entry *tbl_data =
11813 : : container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
11814 : :
11815 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], tbl_data->idx);
11816 : 0 : }
11817 : :
11818 : : /**
11819 : : * Get a flow table.
11820 : : *
11821 : : * @param[in, out] dev
11822 : : * Pointer to rte_eth_dev structure.
11823 : : * @param[in] table_level
11824 : : * Table level to use.
11825 : : * @param[in] egress
11826 : : * Direction of the table.
11827 : : * @param[in] transfer
11828 : : * E-Switch or NIC flow.
11829 : : * @param[in] dummy
11830 : : * Dummy entry for dv API.
11831 : : * @param[in] table_id
11832 : : * Table id to use.
11833 : : * @param[out] error
11834 : : * pointer to error structure.
11835 : : *
11836 : : * @return
11837 : : * Returns tables resource based on the index, NULL in case of failed.
11838 : : */
11839 : : struct mlx5_flow_tbl_resource *
11840 : 0 : flow_dv_tbl_resource_get(struct rte_eth_dev *dev,
11841 : : uint32_t table_level, uint8_t egress,
11842 : : uint8_t transfer,
11843 : : bool external,
11844 : : const struct mlx5_flow_tunnel *tunnel,
11845 : : uint32_t group_id, uint8_t dummy,
11846 : : uint32_t table_id,
11847 : : struct rte_flow_error *error)
11848 : : {
11849 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11850 : 0 : union mlx5_flow_tbl_key table_key = {
11851 : : {
11852 : : .level = table_level,
11853 : : .id = table_id,
11854 : : .reserved = 0,
11855 : 0 : .dummy = !!dummy,
11856 : 0 : .is_fdb = !!transfer,
11857 : 0 : .is_egress = !!egress,
11858 : : }
11859 : : };
11860 : 0 : struct mlx5_flow_tbl_tunnel_prm tt_prm = {
11861 : : .tunnel = tunnel,
11862 : : .group_id = group_id,
11863 : : .external = external,
11864 : : };
11865 : 0 : struct mlx5_flow_cb_ctx ctx = {
11866 : : .dev = dev,
11867 : : .error = error,
11868 : : .data = &table_key.v64,
11869 : : .data2 = &tt_prm,
11870 : : };
11871 : : struct mlx5_list_entry *entry;
11872 : : struct mlx5_flow_tbl_data_entry *tbl_data;
11873 : :
11874 : 0 : entry = mlx5_hlist_register(priv->sh->flow_tbls, table_key.v64, &ctx);
11875 [ # # ]: 0 : if (!entry) {
11876 : 0 : rte_flow_error_set(error, ENOMEM,
11877 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11878 : : "cannot get table");
11879 : 0 : return NULL;
11880 : : }
11881 [ # # ]: 0 : DRV_LOG(DEBUG, "table_level %u table_id %u "
11882 : : "tunnel %u group %u registered.",
11883 : : table_level, table_id,
11884 : : tunnel ? tunnel->tunnel_id : 0, group_id);
11885 : : tbl_data = container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
11886 : 0 : return &tbl_data->tbl;
11887 : : }
11888 : :
11889 : : void
11890 : 0 : flow_dv_tbl_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
11891 : : {
11892 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11893 : : struct mlx5_flow_tbl_data_entry *tbl_data =
11894 : : container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
11895 : :
11896 : : MLX5_ASSERT(entry && sh);
11897 [ # # ]: 0 : if (tbl_data->jump.action)
11898 : : mlx5_flow_os_destroy_flow_action(tbl_data->jump.action);
11899 [ # # ]: 0 : if (tbl_data->tbl.obj)
11900 : : mlx5_flow_os_destroy_flow_tbl(tbl_data->tbl.obj);
11901 [ # # ]: 0 : if (tbl_data->tunnel_offload && tbl_data->external) {
11902 : : struct mlx5_list_entry *he;
11903 : : struct mlx5_hlist *tunnel_grp_hash;
11904 : 0 : struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
11905 : 0 : union tunnel_tbl_key tunnel_key = {
11906 : 0 : .tunnel_id = tbl_data->tunnel ?
11907 [ # # ]: 0 : tbl_data->tunnel->tunnel_id : 0,
11908 : 0 : .group = tbl_data->group_id
11909 : : };
11910 : 0 : uint32_t table_level = tbl_data->level;
11911 : 0 : struct mlx5_flow_cb_ctx ctx = {
11912 : : .data = (void *)&tunnel_key.val,
11913 : : };
11914 : :
11915 : : tunnel_grp_hash = tbl_data->tunnel ?
11916 [ # # ]: 0 : tbl_data->tunnel->groups :
11917 : : thub->groups;
11918 : 0 : he = mlx5_hlist_lookup(tunnel_grp_hash, tunnel_key.val, &ctx);
11919 [ # # ]: 0 : if (he)
11920 : 0 : mlx5_hlist_unregister(tunnel_grp_hash, he);
11921 [ # # ]: 0 : DRV_LOG(DEBUG,
11922 : : "table_level %u id %u tunnel %u group %u released.",
11923 : : table_level,
11924 : : tbl_data->id,
11925 : : tbl_data->tunnel ?
11926 : : tbl_data->tunnel->tunnel_id : 0,
11927 : : tbl_data->group_id);
11928 : : }
11929 [ # # ]: 0 : if (tbl_data->matchers)
11930 : 0 : mlx5_list_destroy(tbl_data->matchers);
11931 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], tbl_data->idx);
11932 : 0 : }
11933 : :
11934 : : /**
11935 : : * Release a flow table.
11936 : : *
11937 : : * @param[in] sh
11938 : : * Pointer to device shared structure.
11939 : : * @param[in] tbl
11940 : : * Table resource to be released.
11941 : : *
11942 : : * @return
11943 : : * Returns 0 if table was released, else return 1;
11944 : : */
11945 : : int
11946 : 0 : flow_dv_tbl_resource_release(struct mlx5_dev_ctx_shared *sh,
11947 : : struct mlx5_flow_tbl_resource *tbl)
11948 : : {
11949 : : struct mlx5_flow_tbl_data_entry *tbl_data =
11950 : 0 : container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
11951 : :
11952 [ # # ]: 0 : if (!tbl)
11953 : : return 0;
11954 : 0 : return mlx5_hlist_unregister(sh->flow_tbls, &tbl_data->entry);
11955 : : }
11956 : :
11957 : : int
11958 : 0 : flow_matcher_match_cb(void *tool_ctx __rte_unused,
11959 : : struct mlx5_list_entry *entry, void *cb_ctx)
11960 : : {
11961 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11962 : 0 : struct mlx5_flow_dv_matcher *ref = ctx->data;
11963 : : struct mlx5_flow_dv_matcher *cur = container_of(entry, typeof(*cur),
11964 : : entry);
11965 : :
11966 : 0 : return cur->crc != ref->crc ||
11967 [ # # ]: 0 : cur->priority != ref->priority ||
11968 : 0 : memcmp((const void *)cur->mask.buf,
11969 [ # # ]: 0 : (const void *)ref->mask.buf, ref->mask.size);
11970 : : }
11971 : :
11972 : : struct mlx5_list_entry *
11973 : 0 : flow_matcher_create_cb(void *tool_ctx, void *cb_ctx)
11974 : : {
11975 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11976 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11977 : 0 : struct mlx5_flow_dv_matcher *ref = ctx->data;
11978 : : struct mlx5_flow_dv_matcher *resource;
11979 : : #ifdef HAVE_MLX5_HWS_SUPPORT
11980 : : const struct rte_flow_item *items;
11981 : : #endif
11982 : 0 : struct mlx5dv_flow_matcher_attr dv_attr = {
11983 : : .type = IBV_FLOW_ATTR_NORMAL,
11984 : 0 : .match_mask = (void *)&ref->mask,
11985 : : };
11986 : : struct mlx5_flow_tbl_data_entry *tbl;
11987 : : int ret;
11988 : :
11989 : 0 : resource = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*resource), 0,
11990 : : SOCKET_ID_ANY);
11991 [ # # ]: 0 : if (!resource) {
11992 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
11993 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11994 : : "cannot create matcher");
11995 : 0 : return NULL;
11996 : : }
11997 : 0 : *resource = *ref;
11998 [ # # ]: 0 : if (sh->config.dv_flow_en != 2) {
11999 : 0 : tbl = container_of(ref->tbl, typeof(*tbl), tbl);
12000 : 0 : dv_attr.match_criteria_enable =
12001 [ # # ]: 0 : flow_dv_matcher_enable(resource->mask.buf);
12002 : : __flow_dv_adjust_buf_size(&ref->mask.size,
12003 : : dv_attr.match_criteria_enable);
12004 : 0 : dv_attr.priority = ref->priority;
12005 [ # # ]: 0 : if (tbl->is_egress)
12006 : 0 : dv_attr.flags |= IBV_FLOW_ATTR_FLAGS_EGRESS;
12007 : 0 : ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
12008 : : tbl->tbl.obj,
12009 : : &resource->matcher_object);
12010 : : if (ret) {
12011 : 0 : mlx5_free(resource);
12012 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12013 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12014 : : "cannot create matcher");
12015 : 0 : return NULL;
12016 : : }
12017 : : } else {
12018 : : #ifdef HAVE_MLX5_HWS_SUPPORT
12019 : 0 : items = *((const struct rte_flow_item **)(ctx->data2));
12020 : 0 : resource->matcher_object = mlx5dr_bwc_matcher_create
12021 : 0 : (resource->group->tbl, resource->priority, items);
12022 [ # # ]: 0 : if (!resource->matcher_object) {
12023 : 0 : mlx5_free(resource);
12024 : 0 : return NULL;
12025 : : }
12026 : : #else
12027 : : mlx5_free(resource);
12028 : : return NULL;
12029 : : #endif
12030 : : }
12031 : 0 : return &resource->entry;
12032 : : }
12033 : :
12034 : : /**
12035 : : * Register the flow matcher.
12036 : : *
12037 : : * @param[in, out] dev
12038 : : * Pointer to rte_eth_dev structure.
12039 : : * @param[in, out] matcher
12040 : : * Pointer to flow matcher.
12041 : : * @param[in, out] key
12042 : : * Pointer to flow table key.
12043 : : * @parm[in, out] dev_flow
12044 : : * Pointer to the dev_flow.
12045 : : * @param[out] error
12046 : : * pointer to error structure.
12047 : : *
12048 : : * @return
12049 : : * 0 on success otherwise -errno and errno is set.
12050 : : */
12051 : : static int
12052 : 0 : flow_dv_matcher_register(struct rte_eth_dev *dev,
12053 : : struct mlx5_flow_dv_matcher *ref,
12054 : : union mlx5_flow_tbl_key *key,
12055 : : struct mlx5_flow *dev_flow,
12056 : : const struct mlx5_flow_tunnel *tunnel,
12057 : : uint32_t group_id,
12058 : : struct rte_flow_error *error)
12059 : : {
12060 : : struct mlx5_list_entry *entry;
12061 : : struct mlx5_flow_dv_matcher *resource;
12062 : : struct mlx5_flow_tbl_resource *tbl;
12063 : : struct mlx5_flow_tbl_data_entry *tbl_data;
12064 : 0 : struct mlx5_flow_cb_ctx ctx = {
12065 : : .error = error,
12066 : : .data = ref,
12067 : : };
12068 : : /**
12069 : : * tunnel offload API requires this registration for cases when
12070 : : * tunnel match rule was inserted before tunnel set rule.
12071 : : */
12072 : 0 : tbl = flow_dv_tbl_resource_get(dev, key->level,
12073 : 0 : key->is_egress, key->is_fdb,
12074 : 0 : dev_flow->external, tunnel,
12075 : 0 : group_id, 0, key->id, error);
12076 [ # # ]: 0 : if (!tbl)
12077 : 0 : return -rte_errno; /* No need to refill the error info */
12078 : 0 : tbl_data = container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
12079 : 0 : ref->tbl = tbl;
12080 : 0 : entry = mlx5_list_register(tbl_data->matchers, &ctx);
12081 [ # # ]: 0 : if (!entry) {
12082 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
12083 : 0 : return rte_flow_error_set(error, ENOMEM,
12084 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12085 : : "cannot allocate ref memory");
12086 : : }
12087 : : resource = container_of(entry, typeof(*resource), entry);
12088 : 0 : dev_flow->handle->dvh.matcher = resource;
12089 : 0 : return 0;
12090 : : }
12091 : :
12092 : : struct mlx5_list_entry *
12093 : 0 : flow_dv_tag_create_cb(void *tool_ctx, void *cb_ctx)
12094 : : {
12095 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
12096 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12097 : : struct mlx5_flow_dv_tag_resource *entry;
12098 : 0 : uint32_t idx = 0;
12099 : : int ret;
12100 : :
12101 : 0 : entry = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_TAG], &idx);
12102 [ # # ]: 0 : if (!entry) {
12103 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12104 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12105 : : "cannot allocate resource memory");
12106 : 0 : return NULL;
12107 : : }
12108 : 0 : entry->idx = idx;
12109 : 0 : entry->tag_id = *(uint32_t *)(ctx->data);
12110 : : ret = mlx5_flow_os_create_flow_action_tag(entry->tag_id,
12111 : : &entry->action);
12112 : : if (ret) {
12113 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], idx);
12114 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12115 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12116 : : NULL, "cannot create action");
12117 : 0 : return NULL;
12118 : : }
12119 : 0 : return &entry->entry;
12120 : : }
12121 : :
12122 : : int
12123 : 0 : flow_dv_tag_match_cb(void *tool_ctx __rte_unused, struct mlx5_list_entry *entry,
12124 : : void *cb_ctx)
12125 : : {
12126 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12127 : : struct mlx5_flow_dv_tag_resource *tag =
12128 : : container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
12129 : :
12130 : 0 : return *(uint32_t *)(ctx->data) != tag->tag_id;
12131 : : }
12132 : :
12133 : : struct mlx5_list_entry *
12134 : 0 : flow_dv_tag_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
12135 : : void *cb_ctx)
12136 : : {
12137 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
12138 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12139 : : struct mlx5_flow_dv_tag_resource *entry;
12140 : 0 : uint32_t idx = 0;
12141 : :
12142 : 0 : entry = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_TAG], &idx);
12143 [ # # ]: 0 : if (!entry) {
12144 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12145 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12146 : : "cannot allocate tag resource memory");
12147 : 0 : return NULL;
12148 : : }
12149 : : memcpy(entry, oentry, sizeof(*entry));
12150 : 0 : entry->idx = idx;
12151 : 0 : return &entry->entry;
12152 : : }
12153 : :
12154 : : void
12155 : 0 : flow_dv_tag_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
12156 : : {
12157 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
12158 : : struct mlx5_flow_dv_tag_resource *tag =
12159 : : container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
12160 : :
12161 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], tag->idx);
12162 : 0 : }
12163 : :
12164 : : /**
12165 : : * Find existing tag resource or create and register a new one.
12166 : : *
12167 : : * @param dev[in, out]
12168 : : * Pointer to rte_eth_dev structure.
12169 : : * @param[in, out] tag_be24
12170 : : * Tag value in big endian then R-shift 8.
12171 : : * @parm[in, out] dev_flow
12172 : : * Pointer to the dev_flow.
12173 : : * @param[out] error
12174 : : * pointer to error structure.
12175 : : *
12176 : : * @return
12177 : : * 0 on success otherwise -errno and errno is set.
12178 : : */
12179 : : static int
12180 : 0 : flow_dv_tag_resource_register
12181 : : (struct rte_eth_dev *dev,
12182 : : uint32_t tag_be24,
12183 : : struct mlx5_flow *dev_flow,
12184 : : struct rte_flow_error *error)
12185 : : {
12186 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12187 : : struct mlx5_flow_dv_tag_resource *resource;
12188 : : struct mlx5_list_entry *entry;
12189 : 0 : struct mlx5_flow_cb_ctx ctx = {
12190 : : .error = error,
12191 : : .data = &tag_be24,
12192 : : };
12193 : : struct mlx5_hlist *tag_table;
12194 : :
12195 : 0 : tag_table = flow_dv_hlist_prepare(priv->sh, &priv->sh->tag_table,
12196 : : "tags",
12197 : : MLX5_TAGS_HLIST_ARRAY_SIZE,
12198 : 0 : false, false, priv->sh,
12199 : : flow_dv_tag_create_cb,
12200 : : flow_dv_tag_match_cb,
12201 : : flow_dv_tag_remove_cb,
12202 : : flow_dv_tag_clone_cb,
12203 : : flow_dv_tag_clone_free_cb,
12204 : : error);
12205 [ # # ]: 0 : if (unlikely(!tag_table))
12206 : 0 : return -rte_errno;
12207 : 0 : entry = mlx5_hlist_register(tag_table, tag_be24, &ctx);
12208 [ # # ]: 0 : if (entry) {
12209 : : resource = container_of(entry, struct mlx5_flow_dv_tag_resource,
12210 : : entry);
12211 : 0 : dev_flow->handle->dvh.rix_tag = resource->idx;
12212 : 0 : dev_flow->dv.tag_resource = resource;
12213 : 0 : return 0;
12214 : : }
12215 : 0 : return -rte_errno;
12216 : : }
12217 : :
12218 : : void
12219 : 0 : flow_dv_tag_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
12220 : : {
12221 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
12222 : : struct mlx5_flow_dv_tag_resource *tag =
12223 : : container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
12224 : :
12225 : : MLX5_ASSERT(tag && sh && tag->action);
12226 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(tag->action));
12227 : 0 : DRV_LOG(DEBUG, "Tag %p: removed.", (void *)tag);
12228 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], tag->idx);
12229 : 0 : }
12230 : :
12231 : : /**
12232 : : * Release the tag.
12233 : : *
12234 : : * @param dev
12235 : : * Pointer to Ethernet device.
12236 : : * @param tag_idx
12237 : : * Tag index.
12238 : : *
12239 : : * @return
12240 : : * 1 while a reference on it exists, 0 when freed.
12241 : : */
12242 : : static int
12243 : 0 : flow_dv_tag_release(struct rte_eth_dev *dev,
12244 : : uint32_t tag_idx)
12245 : : {
12246 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12247 : : struct mlx5_flow_dv_tag_resource *tag;
12248 : :
12249 : 0 : tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG], tag_idx);
12250 [ # # ]: 0 : if (!tag)
12251 : : return 0;
12252 : 0 : DRV_LOG(DEBUG, "port %u tag %p: refcnt %d--",
12253 : : dev->data->port_id, (void *)tag, tag->entry.ref_cnt);
12254 : 0 : return mlx5_hlist_unregister(priv->sh->tag_table, &tag->entry);
12255 : : }
12256 : :
12257 : : /**
12258 : : * Translate action PORT_ID / REPRESENTED_PORT to vport.
12259 : : *
12260 : : * @param[in] dev
12261 : : * Pointer to rte_eth_dev structure.
12262 : : * @param[in] action
12263 : : * Pointer to action PORT_ID / REPRESENTED_PORT.
12264 : : * @param[out] dst_port_id
12265 : : * The target port ID.
12266 : : * @param[out] error
12267 : : * Pointer to the error structure.
12268 : : *
12269 : : * @return
12270 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
12271 : : */
12272 : : static int
12273 : 0 : flow_dv_translate_action_port_id(struct rte_eth_dev *dev,
12274 : : const struct rte_flow_action *action,
12275 : : uint32_t *dst_port_id,
12276 : : struct rte_flow_error *error)
12277 : : {
12278 : : uint32_t port;
12279 : : struct mlx5_priv *priv;
12280 : :
12281 [ # # # ]: 0 : switch (action->type) {
12282 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID: {
12283 : : const struct rte_flow_action_port_id *conf;
12284 : :
12285 : 0 : conf = (const struct rte_flow_action_port_id *)action->conf;
12286 [ # # ]: 0 : port = conf->original ? dev->data->port_id : conf->id;
12287 : : break;
12288 : : }
12289 : 0 : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT: {
12290 : : const struct rte_flow_action_ethdev *ethdev;
12291 : :
12292 : 0 : ethdev = (const struct rte_flow_action_ethdev *)action->conf;
12293 : 0 : port = ethdev->port_id;
12294 : 0 : break;
12295 : : }
12296 : 0 : default:
12297 : : MLX5_ASSERT(false);
12298 : 0 : return rte_flow_error_set(error, EINVAL,
12299 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
12300 : : "unknown E-Switch action");
12301 : : }
12302 : :
12303 : 0 : priv = mlx5_port_to_eswitch_info(port, false);
12304 [ # # ]: 0 : if (!priv)
12305 : 0 : return rte_flow_error_set(error, -rte_errno,
12306 : : RTE_FLOW_ERROR_TYPE_ACTION,
12307 : : NULL,
12308 : : "No eswitch info was found for port");
12309 : : #ifdef HAVE_MLX5DV_DR_CREATE_DEST_IB_PORT
12310 : : /*
12311 : : * This parameter is transferred to
12312 : : * mlx5dv_dr_action_create_dest_ib_port().
12313 : : */
12314 : 0 : *dst_port_id = priv->dev_port;
12315 : : #else
12316 : : /*
12317 : : * Legacy mode, no LAG configurations is supported.
12318 : : * This parameter is transferred to
12319 : : * mlx5dv_dr_action_create_dest_vport().
12320 : : */
12321 : : *dst_port_id = priv->vport_id;
12322 : : #endif
12323 : 0 : return 0;
12324 : : }
12325 : :
12326 : : /**
12327 : : * Create a counter with aging configuration.
12328 : : *
12329 : : * @param[in] dev
12330 : : * Pointer to rte_eth_dev structure.
12331 : : * @param[in] dev_flow
12332 : : * Pointer to the mlx5_flow.
12333 : : * @param[out] count
12334 : : * Pointer to the counter action configuration.
12335 : : * @param[in] age
12336 : : * Pointer to the aging action configuration.
12337 : : *
12338 : : * @return
12339 : : * Index to flow counter on success, 0 otherwise.
12340 : : */
12341 : : static uint32_t
12342 : 0 : flow_dv_translate_create_counter(struct rte_eth_dev *dev,
12343 : : struct mlx5_flow *dev_flow,
12344 : : const struct rte_flow_action_count *count
12345 : : __rte_unused,
12346 : : const struct rte_flow_action_age *age)
12347 : : {
12348 : : uint32_t counter;
12349 : : struct mlx5_age_param *age_param;
12350 : :
12351 : 0 : counter = flow_dv_counter_alloc(dev, !!age);
12352 [ # # ]: 0 : if (!counter || age == NULL)
12353 : : return counter;
12354 : : age_param = flow_dv_counter_idx_get_age(dev, counter);
12355 [ # # ]: 0 : age_param->context = age->context ? age->context :
12356 : 0 : (void *)(uintptr_t)(dev_flow->flow_idx);
12357 : 0 : age_param->timeout = age->timeout;
12358 : 0 : age_param->port_id = dev->data->port_id;
12359 : 0 : rte_atomic_store_explicit(&age_param->sec_since_last_hit, 0, rte_memory_order_relaxed);
12360 : 0 : rte_atomic_store_explicit(&age_param->state, AGE_CANDIDATE, rte_memory_order_relaxed);
12361 : 0 : return counter;
12362 : : }
12363 : :
12364 : : /**
12365 : : * Add Tx queue matcher
12366 : : *
12367 : : * @param[in] dev
12368 : : * Pointer to rte_eth_dev structure.
12369 : : * @param[in, out] key
12370 : : * Flow matcher value.
12371 : : * @param[in] item
12372 : : * Flow pattern to translate.
12373 : : * @param[in] key_type
12374 : : * Set flow matcher mask or value.
12375 : : *
12376 : : * @return
12377 : : * 0 on success otherwise -errno and errno is set.
12378 : : */
12379 : : static int
12380 : 0 : flow_dv_translate_item_tx_queue(struct rte_eth_dev *dev, void *key,
12381 : : const struct rte_flow_item *item, uint32_t key_type)
12382 : : {
12383 : : const struct rte_flow_item_tx_queue *queue_m;
12384 : : const struct rte_flow_item_tx_queue *queue_v;
12385 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
12386 : : uint32_t tx_queue;
12387 : : uint32_t sqn = 0;
12388 : : int ret;
12389 : :
12390 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, queue_v, queue_m, &rte_flow_item_tx_queue_mask);
# # # # ]
12391 [ # # ]: 0 : if (!queue_m || !queue_v)
12392 : : return -EINVAL;
12393 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_V) {
12394 : 0 : tx_queue = queue_v->tx_queue;
12395 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_V)
12396 : 0 : tx_queue &= queue_m->tx_queue;
12397 [ # # ]: 0 : ret = flow_hw_get_sqn(dev, tx_queue, &sqn);
12398 [ # # ]: 0 : if (unlikely(ret))
12399 : 0 : return -ret;
12400 : : } else {
12401 : : /* Due to tx_queue to sqn converting, only fully masked value support. */
12402 [ # # ]: 0 : if (queue_m->tx_queue != rte_flow_item_tx_queue_mask.tx_queue)
12403 : : return -EINVAL;
12404 : : sqn = UINT32_MAX;
12405 : : }
12406 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, source_sqn, sqn);
12407 : 0 : return 0;
12408 : : }
12409 : :
12410 : : /**
12411 : : * Add SQ matcher
12412 : : *
12413 : : * @param[in, out] matcher
12414 : : * Flow matcher.
12415 : : * @param[in, out] key
12416 : : * Flow matcher value.
12417 : : * @param[in] item
12418 : : * Flow pattern to translate.
12419 : : * @param[in] key_type
12420 : : * Set flow matcher mask or value.
12421 : : */
12422 : : static void
12423 : 0 : flow_dv_translate_item_sq(void *key,
12424 : : const struct rte_flow_item *item,
12425 : : uint32_t key_type)
12426 : : {
12427 : : const struct mlx5_rte_flow_item_sq *queue_m;
12428 : : const struct mlx5_rte_flow_item_sq *queue_v;
12429 : 0 : const struct mlx5_rte_flow_item_sq queue_mask = {
12430 : : .queue = UINT32_MAX,
12431 : : };
12432 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
12433 : : uint32_t queue;
12434 : :
12435 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, queue_v, queue_m, &queue_mask);
# # # # ]
12436 [ # # ]: 0 : if (!queue_m || !queue_v)
12437 : 0 : return;
12438 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_V) {
12439 : 0 : queue = queue_v->queue;
12440 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_V)
12441 : 0 : queue &= queue_m->queue;
12442 : : } else {
12443 : 0 : queue = queue_m->queue;
12444 : : }
12445 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, source_sqn, queue);
12446 : : }
12447 : :
12448 : : /**
12449 : : * Set the hash fields according to the @p flow information.
12450 : : *
12451 : : * @param[in] item_flags
12452 : : * The match pattern item flags.
12453 : : * @param[in] rss_desc
12454 : : * Pointer to the mlx5_flow_rss_desc.
12455 : : * @param[out] hash_fields
12456 : : * Pointer to the RSS hash fields.
12457 : : */
12458 : : void
12459 : 0 : flow_dv_hashfields_set(uint64_t item_flags,
12460 : : struct mlx5_flow_rss_desc *rss_desc,
12461 : : uint64_t *hash_fields)
12462 : : {
12463 : : uint64_t items = item_flags;
12464 : : uint64_t fields = 0;
12465 : : int rss_inner = 0;
12466 [ # # ]: 0 : uint64_t rss_types = rte_eth_rss_hf_refine(rss_desc->types);
12467 : :
12468 : : *hash_fields = 0;
12469 : : #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
12470 [ # # ]: 0 : if (rss_desc->level >= 2)
12471 : : rss_inner = 1;
12472 : : #endif
12473 [ # # # # ]: 0 : if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV4)) ||
12474 [ # # ]: 0 : (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV4))) {
12475 [ # # ]: 0 : if (rss_types & MLX5_IPV4_LAYER_TYPES) {
12476 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
12477 : : fields |= IBV_RX_HASH_SRC_IPV4;
12478 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
12479 : : fields |= IBV_RX_HASH_DST_IPV4;
12480 : : else
12481 : : fields |= MLX5_IPV4_IBV_RX_HASH;
12482 : : }
12483 [ # # # # : 0 : } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
# # ]
12484 [ # # ]: 0 : (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV6))) {
12485 [ # # ]: 0 : if (rss_types & MLX5_IPV6_LAYER_TYPES) {
12486 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
12487 : : fields |= IBV_RX_HASH_SRC_IPV6;
12488 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
12489 : : fields |= IBV_RX_HASH_DST_IPV6;
12490 : : else
12491 : : fields |= MLX5_IPV6_IBV_RX_HASH;
12492 : : }
12493 : : }
12494 [ # # ]: 0 : if (items & MLX5_FLOW_ITEM_ESP) {
12495 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_ESP)
12496 : 0 : fields |= IBV_RX_HASH_IPSEC_SPI;
12497 : : }
12498 [ # # ]: 0 : if ((fields & ~IBV_RX_HASH_IPSEC_SPI) == 0) {
12499 : 0 : *hash_fields = fields;
12500 : : /*
12501 : : * There is no match between the RSS types and the
12502 : : * L3 protocol (IPv4/IPv6) defined in the flow rule.
12503 : : */
12504 : 0 : return;
12505 : : }
12506 [ # # # # : 0 : if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_UDP)) ||
# # ]
12507 [ # # ]: 0 : (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_UDP))) {
12508 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_UDP) {
12509 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
12510 : 0 : fields |= IBV_RX_HASH_SRC_PORT_UDP;
12511 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
12512 : 0 : fields |= IBV_RX_HASH_DST_PORT_UDP;
12513 : : else
12514 : 0 : fields |= MLX5_UDP_IBV_RX_HASH;
12515 : : }
12516 [ # # # # : 0 : } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_TCP)) ||
# # ]
12517 [ # # ]: 0 : (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_TCP))) {
12518 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_TCP) {
12519 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
12520 : 0 : fields |= IBV_RX_HASH_SRC_PORT_TCP;
12521 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
12522 : 0 : fields |= IBV_RX_HASH_DST_PORT_TCP;
12523 : : else
12524 : 0 : fields |= MLX5_TCP_IBV_RX_HASH;
12525 : : }
12526 : : }
12527 [ # # ]: 0 : if (rss_inner)
12528 : 0 : fields |= IBV_RX_HASH_INNER;
12529 : 0 : *hash_fields = fields;
12530 : : }
12531 : :
12532 : : /**
12533 : : * Prepare an Rx Hash queue.
12534 : : *
12535 : : * @param dev
12536 : : * Pointer to Ethernet device.
12537 : : * @param[in] dev_flow
12538 : : * Pointer to the mlx5_flow.
12539 : : * @param[in] rss_desc
12540 : : * Pointer to the mlx5_flow_rss_desc.
12541 : : * @param[out] hrxq_idx
12542 : : * Hash Rx queue index.
12543 : : *
12544 : : * @return
12545 : : * The Verbs/DevX object initialised, NULL otherwise and rte_errno is set.
12546 : : */
12547 : : static struct mlx5_hrxq *
12548 : 0 : flow_dv_hrxq_prepare(struct rte_eth_dev *dev,
12549 : : struct mlx5_flow *dev_flow,
12550 : : struct mlx5_flow_rss_desc *rss_desc,
12551 : : uint32_t *hrxq_idx)
12552 : : {
12553 : 0 : struct mlx5_flow_handle *dh = dev_flow->handle;
12554 : 0 : uint32_t shared_rss = rss_desc->shared_rss;
12555 : : struct mlx5_hrxq *hrxq;
12556 : :
12557 : : MLX5_ASSERT(rss_desc->queue_num);
12558 : 0 : rss_desc->symmetric_hash_function = dev_flow->symmetric_hash_function;
12559 : 0 : rss_desc->key_len = MLX5_RSS_HASH_KEY_LEN;
12560 : 0 : rss_desc->hash_fields = dev_flow->hash_fields;
12561 : 0 : rss_desc->tunnel = !!(dh->layers & MLX5_FLOW_LAYER_TUNNEL);
12562 : 0 : rss_desc->shared_rss = 0;
12563 [ # # ]: 0 : if (rss_desc->hash_fields == 0)
12564 : 0 : rss_desc->queue_num = 1;
12565 : 0 : hrxq = mlx5_hrxq_get(dev, rss_desc);
12566 [ # # ]: 0 : *hrxq_idx = hrxq ? hrxq->idx : 0;
12567 : 0 : rss_desc->shared_rss = shared_rss;
12568 : 0 : return hrxq;
12569 : : }
12570 : :
12571 : : /**
12572 : : * Release sample sub action resource.
12573 : : *
12574 : : * @param[in, out] dev
12575 : : * Pointer to rte_eth_dev structure.
12576 : : * @param[in] act_res
12577 : : * Pointer to sample sub action resource.
12578 : : */
12579 : : static void
12580 : 0 : flow_dv_sample_sub_actions_release(struct rte_eth_dev *dev,
12581 : : struct mlx5_flow_sub_actions_idx *act_res)
12582 : : {
12583 [ # # ]: 0 : if (act_res->rix_hrxq) {
12584 : 0 : mlx5_hrxq_release(dev, act_res->rix_hrxq);
12585 : 0 : act_res->rix_hrxq = 0;
12586 : : }
12587 [ # # ]: 0 : if (act_res->rix_encap_decap) {
12588 : 0 : flow_encap_decap_resource_release(dev,
12589 : : act_res->rix_encap_decap);
12590 : 0 : act_res->rix_encap_decap = 0;
12591 : : }
12592 [ # # ]: 0 : if (act_res->rix_port_id_action) {
12593 : 0 : flow_dv_port_id_action_resource_release(dev,
12594 : : act_res->rix_port_id_action);
12595 : 0 : act_res->rix_port_id_action = 0;
12596 : : }
12597 [ # # ]: 0 : if (act_res->rix_tag) {
12598 : 0 : flow_dv_tag_release(dev, act_res->rix_tag);
12599 : 0 : act_res->rix_tag = 0;
12600 : : }
12601 [ # # ]: 0 : if (act_res->rix_jump) {
12602 : 0 : flow_dv_jump_tbl_resource_release(dev, act_res->rix_jump);
12603 : 0 : act_res->rix_jump = 0;
12604 : : }
12605 : 0 : }
12606 : :
12607 : : int
12608 : 0 : flow_dv_sample_match_cb(void *tool_ctx __rte_unused,
12609 : : struct mlx5_list_entry *entry, void *cb_ctx)
12610 : : {
12611 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12612 : 0 : struct rte_eth_dev *dev = ctx->dev;
12613 : 0 : struct mlx5_flow_dv_sample_resource *ctx_resource = ctx->data;
12614 : : struct mlx5_flow_dv_sample_resource *resource = container_of(entry,
12615 : : typeof(*resource),
12616 : : entry);
12617 : :
12618 [ # # ]: 0 : if (ctx_resource->ratio == resource->ratio &&
12619 [ # # ]: 0 : ctx_resource->ft_type == resource->ft_type &&
12620 [ # # ]: 0 : ctx_resource->ft_id == resource->ft_id &&
12621 [ # # ]: 0 : ctx_resource->set_action == resource->set_action &&
12622 : 0 : !memcmp((void *)&ctx_resource->sample_act,
12623 [ # # ]: 0 : (void *)&resource->sample_act,
12624 : : sizeof(struct mlx5_flow_sub_actions_list))) {
12625 : : /*
12626 : : * Existing sample action should release the prepared
12627 : : * sub-actions reference counter.
12628 : : */
12629 : 0 : flow_dv_sample_sub_actions_release(dev,
12630 : : &ctx_resource->sample_idx);
12631 : 0 : return 0;
12632 : : }
12633 : : return 1;
12634 : : }
12635 : :
12636 : : struct mlx5_list_entry *
12637 : 0 : flow_dv_sample_create_cb(void *tool_ctx __rte_unused, void *cb_ctx)
12638 : : {
12639 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12640 : 0 : struct rte_eth_dev *dev = ctx->dev;
12641 : 0 : struct mlx5_flow_dv_sample_resource *ctx_resource = ctx->data;
12642 : 0 : void **sample_dv_actions = ctx_resource->sub_actions;
12643 : : struct mlx5_flow_dv_sample_resource *resource;
12644 : : struct mlx5dv_dr_flow_sampler_attr sampler_attr;
12645 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12646 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
12647 : : struct mlx5_flow_tbl_resource *tbl;
12648 : 0 : uint32_t idx = 0;
12649 : : const uint32_t next_ft_step = 1;
12650 : 0 : uint32_t next_ft_id = ctx_resource->ft_id + next_ft_step;
12651 : : uint8_t is_egress = 0;
12652 : : uint8_t is_transfer = 0;
12653 : 0 : struct rte_flow_error *error = ctx->error;
12654 : :
12655 : : /* Register new sample resource. */
12656 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_SAMPLE], &idx);
12657 [ # # ]: 0 : if (!resource) {
12658 : 0 : rte_flow_error_set(error, ENOMEM,
12659 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12660 : : NULL,
12661 : : "cannot allocate resource memory");
12662 : 0 : return NULL;
12663 : : }
12664 : 0 : *resource = *ctx_resource;
12665 : : /* Create normal path table level */
12666 [ # # ]: 0 : if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
12667 : : is_transfer = 1;
12668 [ # # ]: 0 : else if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
12669 : : is_egress = 1;
12670 : 0 : tbl = flow_dv_tbl_resource_get(dev, next_ft_id,
12671 : : is_egress, is_transfer,
12672 : : true, NULL, 0, 0, 0, error);
12673 [ # # ]: 0 : if (!tbl) {
12674 : 0 : rte_flow_error_set(error, ENOMEM,
12675 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12676 : : NULL,
12677 : : "fail to create normal path table "
12678 : : "for sample");
12679 : 0 : goto error;
12680 : : }
12681 : 0 : resource->normal_path_tbl = tbl;
12682 [ # # ]: 0 : if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB) {
12683 [ # # ]: 0 : if (!sh->default_miss_action) {
12684 : 0 : rte_flow_error_set(error, ENOMEM,
12685 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12686 : : NULL,
12687 : : "default miss action was not "
12688 : : "created");
12689 : 0 : goto error;
12690 : : }
12691 : 0 : sample_dv_actions[ctx_resource->sample_act.actions_num++] =
12692 : : sh->default_miss_action;
12693 : : }
12694 : : /* Create a DR sample action */
12695 : 0 : sampler_attr.sample_ratio = resource->ratio;
12696 : 0 : sampler_attr.default_next_table = tbl->obj;
12697 : 0 : sampler_attr.num_sample_actions = ctx_resource->sample_act.actions_num;
12698 : 0 : sampler_attr.sample_actions = (struct mlx5dv_dr_action **)
12699 : : &sample_dv_actions[0];
12700 : 0 : sampler_attr.action = resource->set_action;
12701 : : if (mlx5_os_flow_dr_create_flow_action_sampler
12702 : : (&sampler_attr, &resource->verbs_action)) {
12703 : 0 : rte_flow_error_set(error, ENOMEM,
12704 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12705 : : NULL, "cannot create sample action");
12706 : 0 : goto error;
12707 : : }
12708 : 0 : resource->idx = idx;
12709 : 0 : resource->dev = dev;
12710 : 0 : return &resource->entry;
12711 : 0 : error:
12712 [ # # ]: 0 : if (resource->ft_type != MLX5DV_FLOW_TABLE_TYPE_FDB)
12713 : 0 : flow_dv_sample_sub_actions_release(dev,
12714 : : &resource->sample_idx);
12715 [ # # ]: 0 : if (resource->normal_path_tbl)
12716 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev),
12717 : : resource->normal_path_tbl);
12718 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_SAMPLE], idx);
12719 : 0 : return NULL;
12720 : :
12721 : : }
12722 : :
12723 : : struct mlx5_list_entry *
12724 : 0 : flow_dv_sample_clone_cb(void *tool_ctx __rte_unused,
12725 : : struct mlx5_list_entry *entry __rte_unused,
12726 : : void *cb_ctx)
12727 : : {
12728 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12729 : 0 : struct rte_eth_dev *dev = ctx->dev;
12730 : : struct mlx5_flow_dv_sample_resource *resource;
12731 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12732 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
12733 : 0 : uint32_t idx = 0;
12734 : :
12735 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_SAMPLE], &idx);
12736 [ # # ]: 0 : if (!resource) {
12737 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12738 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12739 : : NULL,
12740 : : "cannot allocate resource memory");
12741 : 0 : return NULL;
12742 : : }
12743 : : memcpy(resource, entry, sizeof(*resource));
12744 : 0 : resource->idx = idx;
12745 : 0 : resource->dev = dev;
12746 : 0 : return &resource->entry;
12747 : : }
12748 : :
12749 : : void
12750 : 0 : flow_dv_sample_clone_free_cb(void *tool_ctx __rte_unused,
12751 : : struct mlx5_list_entry *entry)
12752 : : {
12753 : : struct mlx5_flow_dv_sample_resource *resource =
12754 : : container_of(entry, typeof(*resource), entry);
12755 : 0 : struct rte_eth_dev *dev = resource->dev;
12756 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12757 : :
12758 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_SAMPLE], resource->idx);
12759 : 0 : }
12760 : :
12761 : : /**
12762 : : * Find existing sample resource or create and register a new one.
12763 : : *
12764 : : * @param[in, out] dev
12765 : : * Pointer to rte_eth_dev structure.
12766 : : * @param[in] ref
12767 : : * Pointer to sample resource reference.
12768 : : * @parm[in, out] dev_flow
12769 : : * Pointer to the dev_flow.
12770 : : * @param[out] error
12771 : : * pointer to error structure.
12772 : : *
12773 : : * @return
12774 : : * 0 on success otherwise -errno and errno is set.
12775 : : */
12776 : : static int
12777 : 0 : flow_dv_sample_resource_register(struct rte_eth_dev *dev,
12778 : : struct mlx5_flow_dv_sample_resource *ref,
12779 : : struct mlx5_flow *dev_flow,
12780 : : struct rte_flow_error *error)
12781 : : {
12782 : : struct mlx5_flow_dv_sample_resource *resource;
12783 : : struct mlx5_list_entry *entry;
12784 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12785 : 0 : struct mlx5_flow_cb_ctx ctx = {
12786 : : .dev = dev,
12787 : : .error = error,
12788 : : .data = ref,
12789 : : };
12790 : :
12791 : 0 : entry = mlx5_list_register(priv->sh->sample_action_list, &ctx);
12792 [ # # ]: 0 : if (!entry)
12793 : 0 : return -rte_errno;
12794 : : resource = container_of(entry, typeof(*resource), entry);
12795 : 0 : dev_flow->handle->dvh.rix_sample = resource->idx;
12796 : 0 : dev_flow->dv.sample_res = resource;
12797 : 0 : return 0;
12798 : : }
12799 : :
12800 : : int
12801 : 0 : flow_dv_dest_array_match_cb(void *tool_ctx __rte_unused,
12802 : : struct mlx5_list_entry *entry, void *cb_ctx)
12803 : : {
12804 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12805 : 0 : struct mlx5_flow_dv_dest_array_resource *ctx_resource = ctx->data;
12806 : 0 : struct rte_eth_dev *dev = ctx->dev;
12807 : : struct mlx5_flow_dv_dest_array_resource *resource =
12808 : : container_of(entry, typeof(*resource), entry);
12809 : : uint32_t idx = 0;
12810 : :
12811 [ # # ]: 0 : if (ctx_resource->num_of_dest == resource->num_of_dest &&
12812 : 0 : ctx_resource->ft_type == resource->ft_type &&
12813 : 0 : !memcmp((void *)resource->sample_act,
12814 : 0 : (void *)ctx_resource->sample_act,
12815 [ # # ]: 0 : (ctx_resource->num_of_dest *
12816 : : sizeof(struct mlx5_flow_sub_actions_list)))) {
12817 : : /*
12818 : : * Existing sample action should release the prepared
12819 : : * sub-actions reference counter.
12820 : : */
12821 [ # # ]: 0 : for (idx = 0; idx < ctx_resource->num_of_dest; idx++)
12822 : 0 : flow_dv_sample_sub_actions_release(dev,
12823 : : &ctx_resource->sample_idx[idx]);
12824 : : return 0;
12825 : : }
12826 : : return 1;
12827 : : }
12828 : :
12829 : : struct mlx5_list_entry *
12830 : 0 : flow_dv_dest_array_create_cb(void *tool_ctx __rte_unused, void *cb_ctx)
12831 : : {
12832 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12833 : 0 : struct rte_eth_dev *dev = ctx->dev;
12834 : : struct mlx5_flow_dv_dest_array_resource *resource;
12835 : 0 : struct mlx5_flow_dv_dest_array_resource *ctx_resource = ctx->data;
12836 : 0 : struct mlx5dv_dr_action_dest_attr *dest_attr[MLX5_MAX_DEST_NUM] = { 0 };
12837 : : struct mlx5dv_dr_action_dest_reformat dest_reformat[MLX5_MAX_DEST_NUM];
12838 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12839 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
12840 : : struct mlx5_flow_sub_actions_list *sample_act;
12841 : : struct mlx5dv_dr_domain *domain;
12842 : 0 : uint32_t idx = 0, res_idx = 0;
12843 : 0 : struct rte_flow_error *error = ctx->error;
12844 : : uint64_t action_flags;
12845 : : int ret;
12846 : :
12847 : : /* Register new destination array resource. */
12848 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DEST_ARRAY],
12849 : : &res_idx);
12850 [ # # ]: 0 : if (!resource) {
12851 : 0 : rte_flow_error_set(error, ENOMEM,
12852 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12853 : : NULL,
12854 : : "cannot allocate resource memory");
12855 : 0 : return NULL;
12856 : : }
12857 : 0 : *resource = *ctx_resource;
12858 [ # # ]: 0 : if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
12859 : 0 : domain = sh->fdb_domain;
12860 [ # # ]: 0 : else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
12861 : 0 : domain = sh->rx_domain;
12862 : : else
12863 : 0 : domain = sh->tx_domain;
12864 [ # # ]: 0 : for (idx = 0; idx < ctx_resource->num_of_dest; idx++) {
12865 : 0 : dest_attr[idx] = (struct mlx5dv_dr_action_dest_attr *)
12866 : 0 : mlx5_malloc(MLX5_MEM_ZERO,
12867 : : sizeof(struct mlx5dv_dr_action_dest_attr),
12868 : : 0, SOCKET_ID_ANY);
12869 [ # # ]: 0 : if (!dest_attr[idx]) {
12870 : 0 : rte_flow_error_set(error, ENOMEM,
12871 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12872 : : NULL,
12873 : : "cannot allocate resource memory");
12874 : 0 : goto error;
12875 : : }
12876 : 0 : dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST;
12877 : : sample_act = &ctx_resource->sample_act[idx];
12878 : 0 : action_flags = sample_act->action_flags;
12879 [ # # # # : 0 : switch (action_flags) {
# ]
12880 : 0 : case MLX5_FLOW_ACTION_QUEUE:
12881 : 0 : dest_attr[idx]->dest = sample_act->dr_queue_action;
12882 : 0 : break;
12883 : 0 : case (MLX5_FLOW_ACTION_PORT_ID | MLX5_FLOW_ACTION_ENCAP):
12884 : 0 : dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST_REFORMAT;
12885 : 0 : dest_attr[idx]->dest_reformat = &dest_reformat[idx];
12886 : 0 : dest_attr[idx]->dest_reformat->reformat =
12887 : 0 : sample_act->dr_encap_action;
12888 : 0 : dest_attr[idx]->dest_reformat->dest =
12889 : 0 : sample_act->dr_port_id_action;
12890 : 0 : break;
12891 : 0 : case MLX5_FLOW_ACTION_PORT_ID:
12892 : 0 : dest_attr[idx]->dest = sample_act->dr_port_id_action;
12893 : 0 : break;
12894 : 0 : case MLX5_FLOW_ACTION_JUMP:
12895 : 0 : dest_attr[idx]->dest = sample_act->dr_jump_action;
12896 : 0 : break;
12897 : 0 : default:
12898 : 0 : rte_flow_error_set(error, EINVAL,
12899 : : RTE_FLOW_ERROR_TYPE_ACTION,
12900 : : NULL,
12901 : : "unsupported actions type");
12902 : 0 : goto error;
12903 : : }
12904 : : }
12905 : : /* create a dest array action */
12906 : 0 : ret = mlx5_os_flow_dr_create_flow_action_dest_array
12907 : : (domain,
12908 : 0 : resource->num_of_dest,
12909 : : dest_attr,
12910 : : &resource->action);
12911 : : if (ret) {
12912 : 0 : rte_flow_error_set(error, ENOMEM,
12913 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12914 : : NULL,
12915 : : "cannot create destination array action");
12916 : 0 : goto error;
12917 : : }
12918 : 0 : resource->idx = res_idx;
12919 : 0 : resource->dev = dev;
12920 [ # # ]: 0 : for (idx = 0; idx < ctx_resource->num_of_dest; idx++)
12921 : 0 : mlx5_free(dest_attr[idx]);
12922 : 0 : return &resource->entry;
12923 : : error:
12924 [ # # ]: 0 : for (idx = 0; idx < ctx_resource->num_of_dest; idx++) {
12925 : 0 : flow_dv_sample_sub_actions_release(dev,
12926 : : &resource->sample_idx[idx]);
12927 [ # # ]: 0 : if (dest_attr[idx])
12928 : 0 : mlx5_free(dest_attr[idx]);
12929 : : }
12930 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DEST_ARRAY], res_idx);
12931 : 0 : return NULL;
12932 : : }
12933 : :
12934 : : struct mlx5_list_entry *
12935 : 0 : flow_dv_dest_array_clone_cb(void *tool_ctx __rte_unused,
12936 : : struct mlx5_list_entry *entry __rte_unused,
12937 : : void *cb_ctx)
12938 : : {
12939 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12940 : 0 : struct rte_eth_dev *dev = ctx->dev;
12941 : : struct mlx5_flow_dv_dest_array_resource *resource;
12942 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12943 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
12944 : 0 : uint32_t res_idx = 0;
12945 : 0 : struct rte_flow_error *error = ctx->error;
12946 : :
12947 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DEST_ARRAY],
12948 : : &res_idx);
12949 [ # # ]: 0 : if (!resource) {
12950 : 0 : rte_flow_error_set(error, ENOMEM,
12951 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12952 : : NULL,
12953 : : "cannot allocate dest-array memory");
12954 : 0 : return NULL;
12955 : : }
12956 : : memcpy(resource, entry, sizeof(*resource));
12957 : 0 : resource->idx = res_idx;
12958 : 0 : resource->dev = dev;
12959 : 0 : return &resource->entry;
12960 : : }
12961 : :
12962 : : void
12963 : 0 : flow_dv_dest_array_clone_free_cb(void *tool_ctx __rte_unused,
12964 : : struct mlx5_list_entry *entry)
12965 : : {
12966 : : struct mlx5_flow_dv_dest_array_resource *resource =
12967 : : container_of(entry, typeof(*resource), entry);
12968 : 0 : struct rte_eth_dev *dev = resource->dev;
12969 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12970 : :
12971 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY], resource->idx);
12972 : 0 : }
12973 : :
12974 : : /**
12975 : : * Find existing destination array resource or create and register a new one.
12976 : : *
12977 : : * @param[in, out] dev
12978 : : * Pointer to rte_eth_dev structure.
12979 : : * @param[in] ref
12980 : : * Pointer to destination array resource reference.
12981 : : * @parm[in, out] dev_flow
12982 : : * Pointer to the dev_flow.
12983 : : * @param[out] error
12984 : : * pointer to error structure.
12985 : : *
12986 : : * @return
12987 : : * 0 on success otherwise -errno and errno is set.
12988 : : */
12989 : : static int
12990 : 0 : flow_dv_dest_array_resource_register(struct rte_eth_dev *dev,
12991 : : struct mlx5_flow_dv_dest_array_resource *ref,
12992 : : struct mlx5_flow *dev_flow,
12993 : : struct rte_flow_error *error)
12994 : : {
12995 : : struct mlx5_flow_dv_dest_array_resource *resource;
12996 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12997 : : struct mlx5_list_entry *entry;
12998 : 0 : struct mlx5_flow_cb_ctx ctx = {
12999 : : .dev = dev,
13000 : : .error = error,
13001 : : .data = ref,
13002 : : };
13003 : :
13004 : 0 : entry = mlx5_list_register(priv->sh->dest_array_list, &ctx);
13005 [ # # ]: 0 : if (!entry)
13006 : 0 : return -rte_errno;
13007 : : resource = container_of(entry, typeof(*resource), entry);
13008 : 0 : dev_flow->handle->dvh.rix_dest_array = resource->idx;
13009 : 0 : dev_flow->dv.dest_array_res = resource;
13010 : 0 : return 0;
13011 : : }
13012 : :
13013 : : /**
13014 : : * Convert Sample action to DV specification.
13015 : : *
13016 : : * @param[in] dev
13017 : : * Pointer to rte_eth_dev structure.
13018 : : * @param[in] action
13019 : : * Pointer to sample action structure.
13020 : : * @param[in, out] dev_flow
13021 : : * Pointer to the mlx5_flow.
13022 : : * @param[in] attr
13023 : : * Pointer to the flow attributes.
13024 : : * @param[in, out] num_of_dest
13025 : : * Pointer to the num of destination.
13026 : : * @param[in, out] sample_actions
13027 : : * Pointer to sample actions list.
13028 : : * @param[in, out] res
13029 : : * Pointer to sample resource.
13030 : : * @param[out] error
13031 : : * Pointer to the error structure.
13032 : : *
13033 : : * @return
13034 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
13035 : : */
13036 : : static int
13037 : 0 : flow_dv_translate_action_sample(struct rte_eth_dev *dev,
13038 : : const struct rte_flow_action_sample *action,
13039 : : struct mlx5_flow *dev_flow,
13040 : : const struct rte_flow_attr *attr,
13041 : : uint32_t *num_of_dest,
13042 : : void **sample_actions,
13043 : : struct mlx5_flow_dv_sample_resource *res,
13044 : : struct rte_flow_error *error)
13045 : : {
13046 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13047 : : const struct rte_flow_action *sub_actions;
13048 : : struct mlx5_flow_sub_actions_list *sample_act;
13049 : : struct mlx5_flow_sub_actions_idx *sample_idx;
13050 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
13051 : 0 : struct rte_flow *flow = dev_flow->flow;
13052 : : struct mlx5_flow_rss_desc *rss_desc;
13053 : : uint64_t action_flags = 0;
13054 : :
13055 : : MLX5_ASSERT(wks);
13056 : 0 : rss_desc = &wks->rss_desc;
13057 : : sample_act = &res->sample_act;
13058 : : sample_idx = &res->sample_idx;
13059 : 0 : res->ratio = action->ratio;
13060 : 0 : sub_actions = action->actions;
13061 [ # # ]: 0 : for (; sub_actions->type != RTE_FLOW_ACTION_TYPE_END; sub_actions++) {
13062 : : int type = sub_actions->type;
13063 : : uint32_t pre_rix = 0;
13064 : : void *pre_r;
13065 [ # # # # : 0 : switch (type) {
# # # ]
13066 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
13067 : : {
13068 : : const struct rte_flow_action_queue *queue;
13069 : : struct mlx5_hrxq *hrxq;
13070 : : uint32_t hrxq_idx;
13071 : :
13072 : 0 : queue = sub_actions->conf;
13073 : 0 : rss_desc->queue_num = 1;
13074 : 0 : rss_desc->queue[0] = queue->index;
13075 : 0 : hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
13076 : : rss_desc, &hrxq_idx);
13077 [ # # ]: 0 : if (!hrxq)
13078 : 0 : return rte_flow_error_set
13079 : : (error, rte_errno,
13080 : : RTE_FLOW_ERROR_TYPE_ACTION,
13081 : : NULL,
13082 : : "cannot create fate queue");
13083 : 0 : sample_act->dr_queue_action = hrxq->action;
13084 : 0 : sample_idx->rix_hrxq = hrxq_idx;
13085 : 0 : sample_actions[sample_act->actions_num++] =
13086 : : hrxq->action;
13087 : 0 : (*num_of_dest)++;
13088 : 0 : action_flags |= MLX5_FLOW_ACTION_QUEUE;
13089 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
13090 : 0 : dev_flow->handle->rix_hrxq = hrxq_idx;
13091 : 0 : dev_flow->handle->fate_action =
13092 : : MLX5_FLOW_FATE_QUEUE;
13093 : 0 : break;
13094 : : }
13095 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
13096 : : {
13097 : : struct mlx5_hrxq *hrxq;
13098 : : uint32_t hrxq_idx;
13099 : : const struct rte_flow_action_rss *rss;
13100 : : const uint8_t *rss_key;
13101 : :
13102 : 0 : rss = sub_actions->conf;
13103 : 0 : rss_desc->symmetric_hash_function =
13104 : 0 : MLX5_RSS_IS_SYMM(rss->func);
13105 : 0 : memcpy(rss_desc->queue, rss->queue,
13106 [ # # ]: 0 : rss->queue_num * sizeof(uint16_t));
13107 : 0 : rss_desc->queue_num = rss->queue_num;
13108 : : /* NULL RSS key indicates default RSS key. */
13109 [ # # ]: 0 : rss_key = !rss->key ? rss_hash_default_key : rss->key;
13110 : 0 : memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
13111 : : /*
13112 : : * rss->level and rss.types should be set in advance
13113 : : * when expanding items for RSS.
13114 : : */
13115 : 0 : flow_dv_hashfields_set(dev_flow->handle->layers,
13116 : : rss_desc,
13117 : : &dev_flow->hash_fields);
13118 : 0 : hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
13119 : : rss_desc, &hrxq_idx);
13120 [ # # ]: 0 : if (!hrxq)
13121 : 0 : return rte_flow_error_set
13122 : : (error, rte_errno,
13123 : : RTE_FLOW_ERROR_TYPE_ACTION,
13124 : : NULL,
13125 : : "cannot create fate queue");
13126 : 0 : sample_act->dr_queue_action = hrxq->action;
13127 : 0 : sample_idx->rix_hrxq = hrxq_idx;
13128 : 0 : sample_actions[sample_act->actions_num++] =
13129 : : hrxq->action;
13130 : 0 : (*num_of_dest)++;
13131 : 0 : action_flags |= MLX5_FLOW_ACTION_RSS;
13132 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
13133 : 0 : dev_flow->handle->rix_hrxq = hrxq_idx;
13134 : 0 : dev_flow->handle->fate_action =
13135 : : MLX5_FLOW_FATE_QUEUE;
13136 : 0 : break;
13137 : : }
13138 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
13139 : : {
13140 : : uint32_t tag_be = mlx5_flow_mark_set
13141 : : (((const struct rte_flow_action_mark *)
13142 [ # # ]: 0 : (sub_actions->conf))->id);
13143 : :
13144 : 0 : wks->mark = 1;
13145 : 0 : pre_rix = dev_flow->handle->dvh.rix_tag;
13146 : : /* Save the mark resource before sample */
13147 : 0 : pre_r = dev_flow->dv.tag_resource;
13148 [ # # ]: 0 : if (flow_dv_tag_resource_register(dev, tag_be,
13149 : : dev_flow, error))
13150 : 0 : return -rte_errno;
13151 : : MLX5_ASSERT(dev_flow->dv.tag_resource);
13152 : 0 : sample_act->dr_tag_action =
13153 : 0 : dev_flow->dv.tag_resource->action;
13154 : 0 : sample_idx->rix_tag =
13155 : 0 : dev_flow->handle->dvh.rix_tag;
13156 : 0 : sample_actions[sample_act->actions_num++] =
13157 : : sample_act->dr_tag_action;
13158 : : /* Recover the mark resource after sample */
13159 : 0 : dev_flow->dv.tag_resource = pre_r;
13160 : 0 : dev_flow->handle->dvh.rix_tag = pre_rix;
13161 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK;
13162 : 0 : break;
13163 : : }
13164 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
13165 : : {
13166 [ # # ]: 0 : if (!flow->counter) {
13167 : 0 : flow->counter =
13168 : 0 : flow_dv_translate_create_counter(dev,
13169 : 0 : dev_flow, sub_actions->conf,
13170 : : 0);
13171 [ # # ]: 0 : if (!flow->counter)
13172 : 0 : return rte_flow_error_set
13173 : : (error, rte_errno,
13174 : : RTE_FLOW_ERROR_TYPE_ACTION,
13175 : : NULL,
13176 : : "cannot create counter"
13177 : : " object.");
13178 : : }
13179 : 0 : sample_act->dr_cnt_action =
13180 [ # # ]: 0 : (flow_dv_counter_get_by_idx(dev,
13181 : 0 : flow->counter, NULL))->action;
13182 : 0 : sample_actions[sample_act->actions_num++] =
13183 : : sample_act->dr_cnt_action;
13184 : 0 : action_flags |= MLX5_FLOW_ACTION_COUNT;
13185 : 0 : break;
13186 : : }
13187 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
13188 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
13189 : : {
13190 : : struct mlx5_flow_dv_port_id_action_resource
13191 : : port_id_resource;
13192 : 0 : uint32_t port_id = 0;
13193 : :
13194 : : memset(&port_id_resource, 0, sizeof(port_id_resource));
13195 : : /* Save the port id resource before sample */
13196 : 0 : pre_rix = dev_flow->handle->rix_port_id_action;
13197 : 0 : pre_r = dev_flow->dv.port_id_action;
13198 [ # # ]: 0 : if (flow_dv_translate_action_port_id(dev, sub_actions,
13199 : : &port_id, error))
13200 : 0 : return -rte_errno;
13201 : 0 : port_id_resource.port_id = port_id;
13202 [ # # ]: 0 : if (flow_dv_port_id_action_resource_register
13203 : : (dev, &port_id_resource, dev_flow, error))
13204 : 0 : return -rte_errno;
13205 : 0 : sample_act->dr_port_id_action =
13206 : 0 : dev_flow->dv.port_id_action->action;
13207 : 0 : sample_idx->rix_port_id_action =
13208 : 0 : dev_flow->handle->rix_port_id_action;
13209 : 0 : sample_actions[sample_act->actions_num++] =
13210 : : sample_act->dr_port_id_action;
13211 : : /* Recover the port id resource after sample */
13212 : 0 : dev_flow->dv.port_id_action = pre_r;
13213 : 0 : dev_flow->handle->rix_port_id_action = pre_rix;
13214 : 0 : (*num_of_dest)++;
13215 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_ID;
13216 : 0 : break;
13217 : : }
13218 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
13219 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
13220 : : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
13221 : : /* Save the encap resource before sample */
13222 : 0 : pre_rix = dev_flow->handle->dvh.rix_encap_decap;
13223 : 0 : pre_r = dev_flow->dv.encap_decap;
13224 [ # # ]: 0 : if (flow_dv_create_action_l2_encap(dev, sub_actions,
13225 : : dev_flow,
13226 : 0 : attr->transfer,
13227 : : error))
13228 : 0 : return -rte_errno;
13229 : 0 : sample_act->dr_encap_action =
13230 : 0 : dev_flow->dv.encap_decap->action;
13231 : 0 : sample_idx->rix_encap_decap =
13232 : 0 : dev_flow->handle->dvh.rix_encap_decap;
13233 : 0 : sample_actions[sample_act->actions_num++] =
13234 : : sample_act->dr_encap_action;
13235 : : /* Recover the encap resource after sample */
13236 : 0 : dev_flow->dv.encap_decap = pre_r;
13237 : 0 : dev_flow->handle->dvh.rix_encap_decap = pre_rix;
13238 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
13239 : 0 : break;
13240 : 0 : default:
13241 : 0 : return rte_flow_error_set(error, EINVAL,
13242 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13243 : : NULL,
13244 : : "Not support for sampler action");
13245 : : }
13246 : : }
13247 : 0 : sample_act->action_flags = action_flags;
13248 : 0 : res->ft_id = dev_flow->dv.group;
13249 [ # # ]: 0 : if (attr->transfer) {
13250 : : union {
13251 : : uint32_t action_in[MLX5_ST_SZ_DW(set_action_in)];
13252 : : uint64_t set_action;
13253 : : } action_ctx = { .set_action = 0 };
13254 : 0 : uint32_t vport_meta_tag = wks->vport_meta_tag ?
13255 [ # # ]: 0 : wks->vport_meta_tag :
13256 : : priv->vport_meta_tag;
13257 : :
13258 : 0 : res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
13259 : : MLX5_SET(set_action_in, action_ctx.action_in, action_type,
13260 : : MLX5_MODIFICATION_TYPE_SET);
13261 [ # # ]: 0 : MLX5_SET(set_action_in, action_ctx.action_in, field,
13262 : : MLX5_MODI_META_REG_C_0);
13263 : 0 : MLX5_SET(set_action_in, action_ctx.action_in, data,
13264 : : vport_meta_tag);
13265 : 0 : res->set_action = action_ctx.set_action;
13266 [ # # ]: 0 : } else if (attr->ingress) {
13267 : 0 : res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
13268 : : } else {
13269 : 0 : res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_TX;
13270 : : }
13271 : : return 0;
13272 : : }
13273 : :
13274 : : static void *
13275 : 0 : flow_dv_translate_action_send_to_kernel(struct rte_eth_dev *dev,
13276 : : const struct rte_flow_attr *attr,
13277 : : struct rte_flow_error *error)
13278 : : {
13279 : : struct mlx5_flow_tbl_resource *tbl;
13280 : : struct mlx5_dev_ctx_shared *sh;
13281 : : uint32_t priority;
13282 : : void *action;
13283 : : int ft_type;
13284 : : int ret;
13285 : :
13286 : 0 : sh = MLX5_SH(dev);
13287 [ # # ]: 0 : ft_type = (attr->ingress) ? MLX5DR_TABLE_TYPE_NIC_RX :
13288 [ # # ]: 0 : ((attr->transfer) ? MLX5DR_TABLE_TYPE_FDB :
13289 : : MLX5DR_TABLE_TYPE_NIC_TX);
13290 [ # # ]: 0 : if (sh->send_to_kernel_action[ft_type].action)
13291 : : return sh->send_to_kernel_action[ft_type].action;
13292 : 0 : priority = mlx5_get_send_to_kernel_priority(dev);
13293 [ # # ]: 0 : if (priority == (uint32_t)-1) {
13294 : 0 : rte_flow_error_set(error, ENOTSUP,
13295 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13296 : : "required priority is not available");
13297 : 0 : return NULL;
13298 : : }
13299 : 0 : tbl = flow_dv_tbl_resource_get(dev, 0, attr->egress, attr->transfer, false, NULL, 0, 0, 0,
13300 : : error);
13301 [ # # ]: 0 : if (!tbl) {
13302 : 0 : rte_flow_error_set(error, ENODATA,
13303 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13304 : : "cannot find destination root table");
13305 : 0 : return NULL;
13306 : : }
13307 : 0 : ret = mlx5_flow_os_create_flow_action_send_to_kernel(tbl->obj,
13308 : : priority, &action);
13309 : : if (ret) {
13310 : 0 : rte_flow_error_set(error, ENOMEM,
13311 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13312 : : "cannot create action");
13313 : 0 : goto err;
13314 : : }
13315 : : MLX5_ASSERT(action);
13316 : 0 : sh->send_to_kernel_action[ft_type].action = action;
13317 : 0 : sh->send_to_kernel_action[ft_type].tbl = tbl;
13318 : 0 : return action;
13319 : : err:
13320 : 0 : flow_dv_tbl_resource_release(sh, tbl);
13321 : 0 : return NULL;
13322 : : }
13323 : :
13324 : : /**
13325 : : * Convert Sample action to DV specification.
13326 : : *
13327 : : * @param[in] dev
13328 : : * Pointer to rte_eth_dev structure.
13329 : : * @param[in, out] dev_flow
13330 : : * Pointer to the mlx5_flow.
13331 : : * @param[in] num_of_dest
13332 : : * The num of destination.
13333 : : * @param[in, out] res
13334 : : * Pointer to sample resource.
13335 : : * @param[in, out] mdest_res
13336 : : * Pointer to destination array resource.
13337 : : * @param[in] sample_actions
13338 : : * Pointer to sample path actions list.
13339 : : * @param[in] action_flags
13340 : : * Holds the actions detected until now.
13341 : : * @param[out] error
13342 : : * Pointer to the error structure.
13343 : : *
13344 : : * @return
13345 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
13346 : : */
13347 : : static int
13348 : 0 : flow_dv_create_action_sample(struct rte_eth_dev *dev,
13349 : : struct mlx5_flow *dev_flow,
13350 : : uint32_t num_of_dest,
13351 : : struct mlx5_flow_dv_sample_resource *res,
13352 : : struct mlx5_flow_dv_dest_array_resource *mdest_res,
13353 : : void **sample_actions,
13354 : : uint64_t action_flags,
13355 : : struct rte_flow_error *error)
13356 : : {
13357 : : /* update normal path action resource into last index of array */
13358 : : uint32_t dest_index = MLX5_MAX_DEST_NUM - 1;
13359 : : struct mlx5_flow_sub_actions_list *sample_act =
13360 : : &mdest_res->sample_act[dest_index];
13361 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
13362 : : struct mlx5_flow_rss_desc *rss_desc;
13363 : : uint32_t normal_idx = 0;
13364 : : struct mlx5_hrxq *hrxq;
13365 : : uint32_t hrxq_idx;
13366 : :
13367 : : MLX5_ASSERT(wks);
13368 : 0 : rss_desc = &wks->rss_desc;
13369 [ # # ]: 0 : if (num_of_dest > 1) {
13370 [ # # ]: 0 : if (sample_act->action_flags & MLX5_FLOW_ACTION_QUEUE) {
13371 : : /* Handle QP action for mirroring */
13372 : 0 : hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
13373 : : rss_desc, &hrxq_idx);
13374 [ # # ]: 0 : if (!hrxq)
13375 : 0 : return rte_flow_error_set
13376 : : (error, rte_errno,
13377 : : RTE_FLOW_ERROR_TYPE_ACTION,
13378 : : NULL,
13379 : : "cannot create rx queue");
13380 : : normal_idx++;
13381 : 0 : mdest_res->sample_idx[dest_index].rix_hrxq = hrxq_idx;
13382 : 0 : sample_act->dr_queue_action = hrxq->action;
13383 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
13384 : 0 : dev_flow->handle->rix_hrxq = hrxq_idx;
13385 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
13386 : : }
13387 [ # # ]: 0 : if (sample_act->action_flags & MLX5_FLOW_ACTION_ENCAP) {
13388 : 0 : normal_idx++;
13389 : 0 : mdest_res->sample_idx[dest_index].rix_encap_decap =
13390 : 0 : dev_flow->handle->dvh.rix_encap_decap;
13391 : 0 : sample_act->dr_encap_action =
13392 : 0 : dev_flow->dv.encap_decap->action;
13393 : 0 : dev_flow->handle->dvh.rix_encap_decap = 0;
13394 : : }
13395 [ # # ]: 0 : if (sample_act->action_flags & MLX5_FLOW_ACTION_PORT_ID) {
13396 : 0 : normal_idx++;
13397 : 0 : mdest_res->sample_idx[dest_index].rix_port_id_action =
13398 : 0 : dev_flow->handle->rix_port_id_action;
13399 : 0 : sample_act->dr_port_id_action =
13400 : 0 : dev_flow->dv.port_id_action->action;
13401 : 0 : dev_flow->handle->rix_port_id_action = 0;
13402 : : }
13403 [ # # ]: 0 : if (sample_act->action_flags & MLX5_FLOW_ACTION_JUMP) {
13404 : 0 : normal_idx++;
13405 : 0 : mdest_res->sample_idx[dest_index].rix_jump =
13406 : 0 : dev_flow->handle->rix_jump;
13407 : 0 : sample_act->dr_jump_action =
13408 : 0 : dev_flow->dv.jump->action;
13409 : 0 : dev_flow->handle->rix_jump = 0;
13410 : : }
13411 : 0 : sample_act->actions_num = normal_idx;
13412 : : /* update sample action resource into first index of array */
13413 : 0 : mdest_res->ft_type = res->ft_type;
13414 : 0 : memcpy(&mdest_res->sample_idx[0], &res->sample_idx,
13415 : : sizeof(struct mlx5_flow_sub_actions_idx));
13416 : 0 : memcpy(&mdest_res->sample_act[0], &res->sample_act,
13417 : : sizeof(struct mlx5_flow_sub_actions_list));
13418 : 0 : mdest_res->num_of_dest = num_of_dest;
13419 [ # # ]: 0 : if (flow_dv_dest_array_resource_register(dev, mdest_res,
13420 : : dev_flow, error))
13421 : 0 : return rte_flow_error_set(error, EINVAL,
13422 : : RTE_FLOW_ERROR_TYPE_ACTION,
13423 : : NULL, "can't create sample "
13424 : : "action");
13425 : : } else {
13426 : 0 : res->sub_actions = sample_actions;
13427 [ # # ]: 0 : if (flow_dv_sample_resource_register(dev, res, dev_flow, error))
13428 : 0 : return rte_flow_error_set(error, EINVAL,
13429 : : RTE_FLOW_ERROR_TYPE_ACTION,
13430 : : NULL,
13431 : : "can't create sample action");
13432 : : }
13433 : : return 0;
13434 : : }
13435 : :
13436 : : /**
13437 : : * Remove an ASO age action from age actions list.
13438 : : *
13439 : : * @param[in] dev
13440 : : * Pointer to the Ethernet device structure.
13441 : : * @param[in] age
13442 : : * Pointer to the aso age action handler.
13443 : : */
13444 : : static void
13445 : 0 : flow_dv_aso_age_remove_from_age(struct rte_eth_dev *dev,
13446 : : struct mlx5_aso_age_action *age)
13447 : : {
13448 : : struct mlx5_age_info *age_info;
13449 : : struct mlx5_age_param *age_param = &age->age_params;
13450 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13451 : : uint16_t expected = AGE_CANDIDATE;
13452 : :
13453 : 0 : age_info = GET_PORT_AGE_INFO(priv);
13454 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(&age_param->state, &expected,
13455 : : AGE_FREE, rte_memory_order_relaxed,
13456 : : rte_memory_order_relaxed)) {
13457 : : /**
13458 : : * We need the lock even it is age timeout,
13459 : : * since age action may still in process.
13460 : : */
13461 : 0 : rte_spinlock_lock(&age_info->aged_sl);
13462 [ # # ]: 0 : LIST_REMOVE(age, next);
13463 : : rte_spinlock_unlock(&age_info->aged_sl);
13464 : 0 : rte_atomic_store_explicit(&age_param->state, AGE_FREE, rte_memory_order_relaxed);
13465 : : }
13466 : 0 : }
13467 : :
13468 : : /**
13469 : : * Release an ASO age action.
13470 : : *
13471 : : * @param[in] dev
13472 : : * Pointer to the Ethernet device structure.
13473 : : * @param[in] age_idx
13474 : : * Index of ASO age action to release.
13475 : : * @param[in] flow
13476 : : * True if the release operation is during flow destroy operation.
13477 : : * False if the release operation is during action destroy operation.
13478 : : *
13479 : : * @return
13480 : : * 0 when age action was removed, otherwise the number of references.
13481 : : */
13482 : : static int
13483 : 0 : flow_dv_aso_age_release(struct rte_eth_dev *dev, uint32_t age_idx)
13484 : : {
13485 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13486 : 0 : struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
13487 : 0 : struct mlx5_aso_age_action *age = flow_aso_age_get_by_idx(dev, age_idx);
13488 : 0 : uint32_t ret = rte_atomic_fetch_sub_explicit(&age->refcnt, 1, rte_memory_order_relaxed) - 1;
13489 : :
13490 [ # # ]: 0 : if (!ret) {
13491 : 0 : flow_dv_aso_age_remove_from_age(dev, age);
13492 : 0 : rte_spinlock_lock(&mng->free_sl);
13493 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free, age, next);
13494 : : rte_spinlock_unlock(&mng->free_sl);
13495 : : }
13496 : 0 : return ret;
13497 : : }
13498 : :
13499 : : /**
13500 : : * Resize the ASO age pools array by MLX5_ASO_AGE_CONTAINER_RESIZE pools.
13501 : : *
13502 : : * @param[in] dev
13503 : : * Pointer to the Ethernet device structure.
13504 : : *
13505 : : * @return
13506 : : * 0 on success, otherwise negative errno value and rte_errno is set.
13507 : : */
13508 : : static int
13509 : 0 : flow_dv_aso_age_pools_resize(struct rte_eth_dev *dev)
13510 : : {
13511 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13512 : 0 : struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
13513 : 0 : void *old_pools = mng->pools;
13514 : 0 : uint32_t resize = mng->n + MLX5_ASO_AGE_CONTAINER_RESIZE;
13515 : 0 : uint32_t mem_size = sizeof(struct mlx5_aso_age_pool *) * resize;
13516 : 0 : void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
13517 : :
13518 [ # # ]: 0 : if (!pools) {
13519 : 0 : rte_errno = ENOMEM;
13520 : 0 : return -ENOMEM;
13521 : : }
13522 [ # # ]: 0 : if (old_pools) {
13523 : 0 : memcpy(pools, old_pools,
13524 : 0 : mng->n * sizeof(struct mlx5_flow_counter_pool *));
13525 : 0 : mlx5_free(old_pools);
13526 : : } else {
13527 : : /* First ASO flow hit allocation - starting ASO data-path. */
13528 : 0 : int ret = mlx5_aso_flow_hit_queue_poll_start(priv->sh);
13529 : :
13530 [ # # ]: 0 : if (ret) {
13531 : 0 : mlx5_free(pools);
13532 : 0 : return ret;
13533 : : }
13534 : : }
13535 : 0 : mng->n = resize;
13536 : 0 : mng->pools = pools;
13537 : 0 : return 0;
13538 : : }
13539 : :
13540 : : /**
13541 : : * Create and initialize a new ASO aging pool.
13542 : : *
13543 : : * @param[in] dev
13544 : : * Pointer to the Ethernet device structure.
13545 : : * @param[out] age_free
13546 : : * Where to put the pointer of a new age action.
13547 : : *
13548 : : * @return
13549 : : * The age actions pool pointer and @p age_free is set on success,
13550 : : * NULL otherwise and rte_errno is set.
13551 : : */
13552 : : static struct mlx5_aso_age_pool *
13553 : 0 : flow_dv_age_pool_create(struct rte_eth_dev *dev,
13554 : : struct mlx5_aso_age_action **age_free)
13555 : : {
13556 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13557 : 0 : struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
13558 : : struct mlx5_aso_age_pool *pool = NULL;
13559 : : struct mlx5_devx_obj *obj = NULL;
13560 : : uint32_t i;
13561 : :
13562 : 0 : obj = mlx5_devx_cmd_create_flow_hit_aso_obj(priv->sh->cdev->ctx,
13563 : 0 : priv->sh->cdev->pdn);
13564 [ # # ]: 0 : if (!obj) {
13565 : 0 : rte_errno = ENODATA;
13566 : 0 : DRV_LOG(ERR, "Failed to create flow_hit_aso_obj using DevX.");
13567 : 0 : return NULL;
13568 : : }
13569 : 0 : pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
13570 [ # # ]: 0 : if (!pool) {
13571 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
13572 : 0 : rte_errno = ENOMEM;
13573 : 0 : return NULL;
13574 : : }
13575 : 0 : pool->flow_hit_aso_obj = obj;
13576 : 0 : pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
13577 : 0 : rte_rwlock_write_lock(&mng->resize_rwl);
13578 : 0 : pool->index = mng->next;
13579 : : /* Resize pools array if there is no room for the new pool in it. */
13580 [ # # # # ]: 0 : if (pool->index == mng->n && flow_dv_aso_age_pools_resize(dev)) {
13581 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
13582 : 0 : mlx5_free(pool);
13583 : : rte_rwlock_write_unlock(&mng->resize_rwl);
13584 : 0 : return NULL;
13585 : : }
13586 : 0 : mng->pools[pool->index] = pool;
13587 : 0 : mng->next++;
13588 : : rte_rwlock_write_unlock(&mng->resize_rwl);
13589 : : /* Assign the first action in the new pool, the rest go to free list. */
13590 : 0 : *age_free = &pool->actions[0];
13591 [ # # ]: 0 : for (i = 1; i < MLX5_ASO_AGE_ACTIONS_PER_POOL; i++) {
13592 : 0 : pool->actions[i].offset = i;
13593 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free, &pool->actions[i], next);
13594 : : }
13595 : : return pool;
13596 : : }
13597 : :
13598 : : /**
13599 : : * Allocate a ASO aging bit.
13600 : : *
13601 : : * @param[in] dev
13602 : : * Pointer to the Ethernet device structure.
13603 : : * @param[out] error
13604 : : * Pointer to the error structure.
13605 : : *
13606 : : * @return
13607 : : * Index to ASO age action on success, 0 otherwise and rte_errno is set.
13608 : : */
13609 : : static uint32_t
13610 : 0 : flow_dv_aso_age_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
13611 : : {
13612 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13613 : : const struct mlx5_aso_age_pool *pool;
13614 : 0 : struct mlx5_aso_age_action *age_free = NULL;
13615 : 0 : struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
13616 : :
13617 : : MLX5_ASSERT(mng);
13618 : : /* Try to get the next free age action bit. */
13619 : 0 : rte_spinlock_lock(&mng->free_sl);
13620 : 0 : age_free = LIST_FIRST(&mng->free);
13621 [ # # ]: 0 : if (age_free) {
13622 [ # # ]: 0 : LIST_REMOVE(age_free, next);
13623 [ # # ]: 0 : } else if (!flow_dv_age_pool_create(dev, &age_free)) {
13624 : : rte_spinlock_unlock(&mng->free_sl);
13625 : 0 : rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
13626 : : NULL, "failed to create ASO age pool");
13627 : 0 : return 0; /* 0 is an error. */
13628 : : }
13629 : : rte_spinlock_unlock(&mng->free_sl);
13630 : 0 : pool = container_of
13631 : : ((const struct mlx5_aso_age_action (*)[MLX5_ASO_AGE_ACTIONS_PER_POOL])
13632 : : (age_free - age_free->offset), const struct mlx5_aso_age_pool,
13633 : : actions);
13634 [ # # ]: 0 : if (!age_free->dr_action) {
13635 : 0 : int reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_FLOW_HIT, 0,
13636 : : error);
13637 : :
13638 [ # # ]: 0 : if (reg_c < 0) {
13639 : 0 : rte_flow_error_set(error, rte_errno,
13640 : : RTE_FLOW_ERROR_TYPE_ACTION,
13641 : : NULL, "failed to get reg_c "
13642 : : "for ASO flow hit");
13643 : 0 : return 0; /* 0 is an error. */
13644 : : }
13645 : : #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
13646 : 0 : age_free->dr_action = mlx5_glue->dv_create_flow_action_aso
13647 : 0 : (priv->sh->rx_domain,
13648 : 0 : pool->flow_hit_aso_obj->obj, age_free->offset,
13649 : : MLX5DV_DR_ACTION_FLAGS_ASO_FIRST_HIT_SET,
13650 : 0 : (reg_c - REG_C_0));
13651 : : #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
13652 [ # # ]: 0 : if (!age_free->dr_action) {
13653 : 0 : rte_errno = errno;
13654 : : rte_spinlock_lock(&mng->free_sl);
13655 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free, age_free, next);
13656 : : rte_spinlock_unlock(&mng->free_sl);
13657 : 0 : rte_flow_error_set(error, rte_errno,
13658 : : RTE_FLOW_ERROR_TYPE_ACTION,
13659 : : NULL, "failed to create ASO "
13660 : : "flow hit action");
13661 : 0 : return 0; /* 0 is an error. */
13662 : : }
13663 : : }
13664 : 0 : rte_atomic_store_explicit(&age_free->refcnt, 1, rte_memory_order_relaxed);
13665 : 0 : return pool->index | ((age_free->offset + 1) << 16);
13666 : : }
13667 : :
13668 : : /**
13669 : : * Initialize flow ASO age parameters.
13670 : : *
13671 : : * @param[in] dev
13672 : : * Pointer to rte_eth_dev structure.
13673 : : * @param[in] age_idx
13674 : : * Index of ASO age action.
13675 : : * @param[in] context
13676 : : * Pointer to flow counter age context.
13677 : : * @param[in] timeout
13678 : : * Aging timeout in seconds.
13679 : : *
13680 : : */
13681 : : static void
13682 : 0 : flow_dv_aso_age_params_init(struct rte_eth_dev *dev,
13683 : : uint32_t age_idx,
13684 : : void *context,
13685 : : uint32_t timeout)
13686 : : {
13687 : : struct mlx5_aso_age_action *aso_age;
13688 : :
13689 : 0 : aso_age = flow_aso_age_get_by_idx(dev, age_idx);
13690 : : MLX5_ASSERT(aso_age);
13691 : 0 : aso_age->age_params.context = context;
13692 : 0 : aso_age->age_params.timeout = timeout;
13693 : 0 : aso_age->age_params.port_id = dev->data->port_id;
13694 : 0 : rte_atomic_store_explicit(&aso_age->age_params.sec_since_last_hit, 0,
13695 : : rte_memory_order_relaxed);
13696 : 0 : rte_atomic_store_explicit(&aso_age->age_params.state, AGE_CANDIDATE,
13697 : : rte_memory_order_relaxed);
13698 : 0 : }
13699 : :
13700 : : static void
13701 : 0 : flow_dv_translate_integrity_l4(const struct rte_flow_item_integrity *mask,
13702 : : void *headers)
13703 : : {
13704 : : /*
13705 : : * In HWS mode MLX5_ITEM_UPDATE() macro assigns the same pointer to
13706 : : * both mask and value, therefore ether can be used.
13707 : : * In SWS SW_V mode mask points to item mask and value points to item
13708 : : * spec. Integrity item value is used only if matching mask is set.
13709 : : * Use mask reference here to keep SWS functionality.
13710 : : */
13711 [ # # ]: 0 : if (mask->l4_ok) {
13712 : : /* RTE l4_ok filter aggregates hardware l4_ok and
13713 : : * l4_checksum_ok filters.
13714 : : * Positive RTE l4_ok match requires hardware match on both L4
13715 : : * hardware integrity bits.
13716 : : * PMD supports positive integrity item semantics only.
13717 : : */
13718 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, l4_ok, 1);
13719 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, l4_checksum_ok, 1);
13720 [ # # ]: 0 : } else if (mask->l4_csum_ok) {
13721 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, l4_checksum_ok, 1);
13722 : : }
13723 : 0 : }
13724 : :
13725 : : static void
13726 : 0 : flow_dv_translate_integrity_l3(const struct rte_flow_item_integrity *mask,
13727 : : void *headers, bool is_ipv4)
13728 : : {
13729 : : /*
13730 : : * In HWS mode MLX5_ITEM_UPDATE() macro assigns the same pointer to
13731 : : * both mask and value, therefore ether can be used.
13732 : : * In SWS SW_V mode mask points to item mask and value points to item
13733 : : * spec. Integrity item value used only if matching mask is set.
13734 : : * Use mask reference here to keep SWS functionality.
13735 : : */
13736 [ # # ]: 0 : if (mask->l3_ok) {
13737 : : /* RTE l3_ok filter aggregates for IPv4 hardware l3_ok and
13738 : : * ipv4_csum_ok filters.
13739 : : * Positive RTE l3_ok match requires hardware match on both L3
13740 : : * hardware integrity bits.
13741 : : * PMD supports positive integrity item semantics only.
13742 : : */
13743 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, l3_ok, 1);
13744 [ # # ]: 0 : if (is_ipv4) {
13745 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers,
13746 : : ipv4_checksum_ok, 1);
13747 : : }
13748 [ # # # # ]: 0 : } else if (is_ipv4 && mask->ipv4_csum_ok) {
13749 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, ipv4_checksum_ok, 1);
13750 : : }
13751 : 0 : }
13752 : :
13753 : : static void
13754 : 0 : set_integrity_bits(void *headers, const struct rte_flow_item *integrity_item,
13755 : : bool is_l3_ip4, uint32_t key_type)
13756 : : {
13757 : : const struct rte_flow_item_integrity *spec;
13758 : : const struct rte_flow_item_integrity *mask;
13759 : :
13760 : : /* Integrity bits validation cleared spec pointer */
13761 [ # # # # : 0 : if (MLX5_ITEM_VALID(integrity_item, key_type))
# # # # #
# ]
13762 : : return;
13763 [ # # # # : 0 : MLX5_ITEM_UPDATE(integrity_item, key_type, spec, mask,
# # # # ]
13764 : : &rte_flow_item_integrity_mask);
13765 : 0 : flow_dv_translate_integrity_l3(mask, headers, is_l3_ip4);
13766 : 0 : flow_dv_translate_integrity_l4(mask, headers);
13767 : : }
13768 : :
13769 : : static void
13770 : 0 : flow_dv_translate_item_integrity_post(void *key,
13771 : : const
13772 : : struct rte_flow_item *integrity_items[2],
13773 : : uint64_t pattern_flags, uint32_t key_type)
13774 : : {
13775 : : void *headers;
13776 : : bool is_l3_ip4;
13777 : :
13778 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_INNER_INTEGRITY) {
13779 : 0 : headers = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
13780 : 0 : is_l3_ip4 = (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV4) !=
13781 : : 0;
13782 : 0 : set_integrity_bits(headers, integrity_items[1], is_l3_ip4,
13783 : : key_type);
13784 : : }
13785 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_OUTER_INTEGRITY) {
13786 : : headers = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
13787 : 0 : is_l3_ip4 = (pattern_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV4) !=
13788 : : 0;
13789 : 0 : set_integrity_bits(headers, integrity_items[0], is_l3_ip4,
13790 : : key_type);
13791 : : }
13792 : 0 : }
13793 : :
13794 : : static uint64_t
13795 : : flow_dv_translate_item_integrity(const struct rte_flow_item *item,
13796 : : struct mlx5_dv_matcher_workspace *wks,
13797 : : uint64_t key_type)
13798 : : {
13799 : 0 : if ((key_type & MLX5_SET_MATCHER_SW) != 0) {
13800 : : const struct rte_flow_item_integrity
13801 : 0 : *spec = (typeof(spec))item->spec;
13802 : :
13803 : : /* SWS integrity bits validation cleared spec pointer */
13804 [ # # ]: 0 : if (spec->level > 1) {
13805 : 0 : wks->integrity_items[1] = item;
13806 : 0 : wks->last_item |= MLX5_FLOW_ITEM_INNER_INTEGRITY;
13807 : : } else {
13808 : 0 : wks->integrity_items[0] = item;
13809 : 0 : wks->last_item |= MLX5_FLOW_ITEM_OUTER_INTEGRITY;
13810 : : }
13811 : : } else {
13812 : : /* HWS supports outer integrity only */
13813 : 0 : wks->integrity_items[0] = item;
13814 : 0 : wks->last_item |= MLX5_FLOW_ITEM_OUTER_INTEGRITY;
13815 : : }
13816 : 0 : return wks->last_item;
13817 : : }
13818 : :
13819 : : /**
13820 : : * Prepares DV flow counter with aging configuration.
13821 : : * Gets it by index when exists, creates a new one when doesn't.
13822 : : *
13823 : : * @param[in] dev
13824 : : * Pointer to rte_eth_dev structure.
13825 : : * @param[in] dev_flow
13826 : : * Pointer to the mlx5_flow.
13827 : : * @param[in, out] flow
13828 : : * Pointer to the sub flow.
13829 : : * @param[in] count
13830 : : * Pointer to the counter action configuration.
13831 : : * @param[in] age
13832 : : * Pointer to the aging action configuration.
13833 : : * @param[out] error
13834 : : * Pointer to the error structure.
13835 : : *
13836 : : * @return
13837 : : * Pointer to the counter, NULL otherwise.
13838 : : */
13839 : : static struct mlx5_flow_counter *
13840 : 0 : flow_dv_prepare_counter(struct rte_eth_dev *dev,
13841 : : struct mlx5_flow *dev_flow,
13842 : : struct rte_flow *flow,
13843 : : const struct rte_flow_action_count *count,
13844 : : const struct rte_flow_action_age *age,
13845 : : struct rte_flow_error *error)
13846 : : {
13847 [ # # ]: 0 : if (!flow->counter) {
13848 : 0 : flow->counter = flow_dv_translate_create_counter(dev, dev_flow,
13849 : : count, age);
13850 [ # # ]: 0 : if (!flow->counter) {
13851 : 0 : rte_flow_error_set(error, rte_errno,
13852 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
13853 : : "cannot create counter object.");
13854 : 0 : return NULL;
13855 : : }
13856 : : }
13857 [ # # ]: 0 : return flow_dv_counter_get_by_idx(dev, flow->counter, NULL);
13858 : : }
13859 : :
13860 : : /*
13861 : : * Release an ASO CT action by its own device.
13862 : : *
13863 : : * @param[in] dev
13864 : : * Pointer to the Ethernet device structure.
13865 : : * @param[in] idx
13866 : : * Index of ASO CT action to release.
13867 : : *
13868 : : * @return
13869 : : * 0 when CT action was removed, otherwise the number of references.
13870 : : */
13871 : : static inline int
13872 : 0 : flow_dv_aso_ct_dev_release(struct rte_eth_dev *dev, uint32_t idx)
13873 : : {
13874 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13875 : 0 : struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
13876 : : uint32_t ret;
13877 : 0 : struct mlx5_aso_ct_action *ct = flow_aso_ct_get_by_dev_idx(dev, idx);
13878 : : enum mlx5_aso_ct_state state =
13879 : 0 : rte_atomic_load_explicit(&ct->state, rte_memory_order_relaxed);
13880 : :
13881 : : /* Cannot release when CT is in the ASO SQ. */
13882 [ # # ]: 0 : if (state == ASO_CONNTRACK_WAIT || state == ASO_CONNTRACK_QUERY)
13883 : : return -1;
13884 : 0 : ret = rte_atomic_fetch_sub_explicit(&ct->refcnt, 1, rte_memory_order_relaxed) - 1;
13885 [ # # ]: 0 : if (!ret) {
13886 [ # # ]: 0 : if (ct->dr_action_orig) {
13887 : : #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
13888 : 0 : claim_zero(mlx5_glue->destroy_flow_action
13889 : : (ct->dr_action_orig));
13890 : : #endif
13891 : 0 : ct->dr_action_orig = NULL;
13892 : : }
13893 [ # # ]: 0 : if (ct->dr_action_rply) {
13894 : : #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
13895 : 0 : claim_zero(mlx5_glue->destroy_flow_action
13896 : : (ct->dr_action_rply));
13897 : : #endif
13898 : 0 : ct->dr_action_rply = NULL;
13899 : : }
13900 : : /* Clear the state to free, no need in 1st allocation. */
13901 : 0 : MLX5_ASO_CT_UPDATE_STATE(ct, ASO_CONNTRACK_FREE);
13902 : 0 : rte_spinlock_lock(&mng->ct_sl);
13903 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free_cts, ct, next);
13904 : : rte_spinlock_unlock(&mng->ct_sl);
13905 : : }
13906 : 0 : return (int)ret;
13907 : : }
13908 : :
13909 : : static inline int
13910 : 0 : flow_dv_aso_ct_release(struct rte_eth_dev *dev, uint32_t own_idx,
13911 : : struct rte_flow_error *error)
13912 : : {
13913 : 0 : uint16_t owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(own_idx);
13914 : 0 : uint32_t idx = MLX5_INDIRECT_ACT_CT_GET_IDX(own_idx);
13915 : 0 : struct rte_eth_dev *owndev = &rte_eth_devices[owner];
13916 : : int ret;
13917 : :
13918 : : MLX5_ASSERT(owner < RTE_MAX_ETHPORTS);
13919 [ # # ]: 0 : if (dev->data->dev_started != 1)
13920 : 0 : return rte_flow_error_set(error, EAGAIN,
13921 : : RTE_FLOW_ERROR_TYPE_ACTION,
13922 : : NULL,
13923 : : "Indirect CT action cannot be destroyed when the port is stopped");
13924 : 0 : ret = flow_dv_aso_ct_dev_release(owndev, idx);
13925 [ # # ]: 0 : if (ret < 0)
13926 : 0 : return rte_flow_error_set(error, EAGAIN,
13927 : : RTE_FLOW_ERROR_TYPE_ACTION,
13928 : : NULL,
13929 : : "Current state prevents indirect CT action from being destroyed");
13930 : : return ret;
13931 : : }
13932 : :
13933 : : /*
13934 : : * Resize the ASO CT pools array by 64 pools.
13935 : : *
13936 : : * @param[in] dev
13937 : : * Pointer to the Ethernet device structure.
13938 : : *
13939 : : * @return
13940 : : * 0 on success, otherwise negative errno value and rte_errno is set.
13941 : : */
13942 : : static int
13943 : 0 : flow_dv_aso_ct_pools_resize(struct rte_eth_dev *dev)
13944 : : {
13945 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13946 : 0 : struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
13947 : 0 : void *old_pools = mng->pools;
13948 : : /* Magic number now, need a macro. */
13949 : 0 : uint32_t resize = mng->n + 64;
13950 : 0 : uint32_t mem_size = sizeof(struct mlx5_aso_ct_pool *) * resize;
13951 : 0 : void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
13952 : :
13953 [ # # ]: 0 : if (!pools) {
13954 : 0 : rte_errno = ENOMEM;
13955 : 0 : return -rte_errno;
13956 : : }
13957 : 0 : rte_rwlock_write_lock(&mng->resize_rwl);
13958 : : /* ASO SQ/QP was already initialized in the startup. */
13959 [ # # ]: 0 : if (old_pools) {
13960 : : /* Realloc could be an alternative choice. */
13961 : 0 : rte_memcpy(pools, old_pools,
13962 [ # # ]: 0 : mng->n * sizeof(struct mlx5_aso_ct_pool *));
13963 : 0 : mlx5_free(old_pools);
13964 : : }
13965 : 0 : mng->n = resize;
13966 : 0 : mng->pools = pools;
13967 : : rte_rwlock_write_unlock(&mng->resize_rwl);
13968 : 0 : return 0;
13969 : : }
13970 : :
13971 : : /*
13972 : : * Create and initialize a new ASO CT pool.
13973 : : *
13974 : : * @param[in] dev
13975 : : * Pointer to the Ethernet device structure.
13976 : : * @param[out] ct_free
13977 : : * Where to put the pointer of a new CT action.
13978 : : *
13979 : : * @return
13980 : : * The CT actions pool pointer and @p ct_free is set on success,
13981 : : * NULL otherwise and rte_errno is set.
13982 : : */
13983 : : static struct mlx5_aso_ct_pool *
13984 : 0 : flow_dv_ct_pool_create(struct rte_eth_dev *dev,
13985 : : struct mlx5_aso_ct_action **ct_free)
13986 : : {
13987 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13988 : 0 : struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
13989 : : struct mlx5_aso_ct_pool *pool = NULL;
13990 : : struct mlx5_devx_obj *obj = NULL;
13991 : : uint32_t i;
13992 : : uint32_t log_obj_size = rte_log2_u32(MLX5_ASO_CT_ACTIONS_PER_POOL);
13993 : : size_t mem_size;
13994 : :
13995 : 0 : obj = mlx5_devx_cmd_create_conn_track_offload_obj(priv->sh->cdev->ctx,
13996 : 0 : priv->sh->cdev->pdn,
13997 : : log_obj_size);
13998 [ # # ]: 0 : if (!obj) {
13999 : 0 : rte_errno = ENODATA;
14000 : 0 : DRV_LOG(ERR, "Failed to create conn_track_offload_obj using DevX.");
14001 : 0 : return NULL;
14002 : : }
14003 : : mem_size = sizeof(struct mlx5_aso_ct_action) *
14004 : : MLX5_ASO_CT_ACTIONS_PER_POOL +
14005 : : sizeof(*pool);
14006 : 0 : pool = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
14007 [ # # ]: 0 : if (!pool) {
14008 : 0 : rte_errno = ENOMEM;
14009 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
14010 : 0 : return NULL;
14011 : : }
14012 : 0 : pool->devx_obj = obj;
14013 : 0 : pool->index = mng->next;
14014 : : /* Resize pools array if there is no room for the new pool in it. */
14015 [ # # # # ]: 0 : if (pool->index == mng->n && flow_dv_aso_ct_pools_resize(dev)) {
14016 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
14017 : 0 : mlx5_free(pool);
14018 : 0 : return NULL;
14019 : : }
14020 : 0 : mng->pools[pool->index] = pool;
14021 : 0 : mng->next++;
14022 : : /* Assign the first action in the new pool, the rest go to free list. */
14023 : 0 : *ct_free = &pool->actions[0];
14024 : : /* Lock outside, the list operation is safe here. */
14025 [ # # ]: 0 : for (i = 1; i < MLX5_ASO_CT_ACTIONS_PER_POOL; i++) {
14026 : : /* refcnt is 0 when allocating the memory. */
14027 : 0 : pool->actions[i].offset = i;
14028 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free_cts, &pool->actions[i], next);
14029 : : }
14030 : : return pool;
14031 : : }
14032 : :
14033 : : /*
14034 : : * Allocate a ASO CT action from free list.
14035 : : *
14036 : : * @param[in] dev
14037 : : * Pointer to the Ethernet device structure.
14038 : : * @param[out] error
14039 : : * Pointer to the error structure.
14040 : : *
14041 : : * @return
14042 : : * Index to ASO CT action on success, 0 otherwise and rte_errno is set.
14043 : : */
14044 : : static uint32_t
14045 : 0 : flow_dv_aso_ct_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
14046 : : {
14047 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14048 : 0 : struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
14049 : 0 : struct mlx5_aso_ct_action *ct = NULL;
14050 : : struct mlx5_aso_ct_pool *pool;
14051 : : uint8_t reg_c;
14052 : : uint32_t ct_idx;
14053 : :
14054 : : MLX5_ASSERT(mng);
14055 [ # # ]: 0 : if (!priv->sh->cdev->config.devx) {
14056 : 0 : rte_errno = ENOTSUP;
14057 : 0 : return 0;
14058 : : }
14059 : : /* Get a free CT action, if no, a new pool will be created. */
14060 : 0 : rte_spinlock_lock(&mng->ct_sl);
14061 : 0 : ct = LIST_FIRST(&mng->free_cts);
14062 [ # # ]: 0 : if (ct) {
14063 [ # # ]: 0 : LIST_REMOVE(ct, next);
14064 [ # # ]: 0 : } else if (!flow_dv_ct_pool_create(dev, &ct)) {
14065 : : rte_spinlock_unlock(&mng->ct_sl);
14066 : 0 : rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
14067 : : NULL, "failed to create ASO CT pool");
14068 : 0 : return 0;
14069 : : }
14070 : : rte_spinlock_unlock(&mng->ct_sl);
14071 : 0 : pool = container_of(ct, struct mlx5_aso_ct_pool, actions[ct->offset]);
14072 : 0 : ct_idx = MLX5_MAKE_CT_IDX(pool->index, ct->offset);
14073 : : /* 0: inactive, 1: created, 2+: used by flows. */
14074 : 0 : rte_atomic_store_explicit(&ct->refcnt, 1, rte_memory_order_relaxed);
14075 : 0 : reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_CONNTRACK, 0, error);
14076 [ # # ]: 0 : if (!ct->dr_action_orig) {
14077 : : #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
14078 : 0 : ct->dr_action_orig = mlx5_glue->dv_create_flow_action_aso
14079 : 0 : (priv->sh->rx_domain, pool->devx_obj->obj,
14080 : : ct->offset,
14081 : : MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_INITIATOR,
14082 : 0 : reg_c - REG_C_0);
14083 : : #else
14084 : : RTE_SET_USED(reg_c);
14085 : : #endif
14086 [ # # ]: 0 : if (!ct->dr_action_orig) {
14087 : 0 : flow_dv_aso_ct_dev_release(dev, ct_idx);
14088 : 0 : rte_flow_error_set(error, rte_errno,
14089 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14090 : : "failed to create ASO CT action");
14091 : 0 : return 0;
14092 : : }
14093 : : }
14094 [ # # ]: 0 : if (!ct->dr_action_rply) {
14095 : : #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
14096 : 0 : ct->dr_action_rply = mlx5_glue->dv_create_flow_action_aso
14097 : 0 : (priv->sh->rx_domain, pool->devx_obj->obj,
14098 : : ct->offset,
14099 : : MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_RESPONDER,
14100 : 0 : reg_c - REG_C_0);
14101 : : #endif
14102 [ # # ]: 0 : if (!ct->dr_action_rply) {
14103 : 0 : flow_dv_aso_ct_dev_release(dev, ct_idx);
14104 : 0 : rte_flow_error_set(error, rte_errno,
14105 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14106 : : "failed to create ASO CT action");
14107 : 0 : return 0;
14108 : : }
14109 : : }
14110 : : return ct_idx;
14111 : : }
14112 : :
14113 : : /*
14114 : : * Create a conntrack object with context and actions by using ASO mechanism.
14115 : : *
14116 : : * @param[in] dev
14117 : : * Pointer to rte_eth_dev structure.
14118 : : * @param[in] pro
14119 : : * Pointer to conntrack information profile.
14120 : : * @param[out] error
14121 : : * Pointer to the error structure.
14122 : : *
14123 : : * @return
14124 : : * Index to conntrack object on success, 0 otherwise.
14125 : : */
14126 : : static uint32_t
14127 : 0 : flow_dv_translate_create_conntrack(struct rte_eth_dev *dev,
14128 : : const struct rte_flow_action_conntrack *pro,
14129 : : struct rte_flow_error *error)
14130 : : {
14131 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14132 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
14133 : : struct mlx5_aso_ct_action *ct;
14134 : : uint32_t idx;
14135 : :
14136 [ # # ]: 0 : if (!sh->ct_aso_en)
14137 : 0 : return rte_flow_error_set(error, ENOTSUP,
14138 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14139 : : "Connection is not supported");
14140 [ # # ]: 0 : if (dev->data->port_id >= MLX5_INDIRECT_ACT_CT_MAX_PORT) {
14141 : 0 : rte_flow_error_set(error, EINVAL,
14142 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14143 : : "CT supports port indexes up to "
14144 : : RTE_STR(MLX5_ACTION_CTX_CT_MAX_PORT));
14145 : 0 : return 0;
14146 : : }
14147 : 0 : idx = flow_dv_aso_ct_alloc(dev, error);
14148 [ # # ]: 0 : if (!idx)
14149 : 0 : return rte_flow_error_set(error, rte_errno,
14150 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14151 : : "Failed to allocate CT object");
14152 : 0 : ct = flow_aso_ct_get_by_dev_idx(dev, idx);
14153 [ # # ]: 0 : if (mlx5_aso_ct_update_by_wqe(sh, MLX5_HW_INV_QUEUE, ct, pro, NULL, true)) {
14154 : 0 : flow_dv_aso_ct_dev_release(dev, idx);
14155 : 0 : rte_flow_error_set(error, EBUSY,
14156 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14157 : : "Failed to update CT");
14158 : 0 : return 0;
14159 : : }
14160 : 0 : ct->is_original = !!pro->is_original_dir;
14161 : 0 : ct->peer = pro->peer_port;
14162 : 0 : return idx;
14163 : : }
14164 : :
14165 : : /**
14166 : : * Fill the flow matcher with DV spec.
14167 : : *
14168 : : * @param[in] dev
14169 : : * Pointer to rte_eth_dev structure.
14170 : : * @param[in] items
14171 : : * Pointer to the list of items.
14172 : : * @param[in] wks
14173 : : * Pointer to the matcher workspace.
14174 : : * @param[in] key
14175 : : * Pointer to the flow matcher key.
14176 : : * @param[in] key_type
14177 : : * Key type.
14178 : : * @param[out] error
14179 : : * Pointer to the error structure.
14180 : : *
14181 : : * @return
14182 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14183 : : */
14184 : : static int
14185 : 0 : flow_dv_translate_items(struct rte_eth_dev *dev,
14186 : : const struct rte_flow_item *items,
14187 : : struct mlx5_dv_matcher_workspace *wks,
14188 : : void *key, uint32_t key_type,
14189 : : struct rte_flow_error *error)
14190 : : {
14191 : 0 : struct mlx5_flow_rss_desc *rss_desc = wks->rss_desc;
14192 : 0 : uint8_t next_protocol = wks->next_protocol;
14193 : 0 : int tunnel = !!(wks->item_flags & MLX5_FLOW_LAYER_TUNNEL);
14194 : 0 : int item_type = items->type;
14195 : 0 : uint64_t last_item = wks->last_item;
14196 : : enum mlx5_l3_tunnel_detection l3_tunnel_detection;
14197 : : uint64_t l3_tunnel_flag;
14198 : : int ret;
14199 : :
14200 [ # # # # : 0 : switch (item_type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
14201 : 0 : case RTE_FLOW_ITEM_TYPE_ESP:
14202 : 0 : flow_dv_translate_item_esp(key, items, tunnel, key_type);
14203 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14204 : : last_item = MLX5_FLOW_ITEM_ESP;
14205 : 0 : break;
14206 : 0 : case RTE_FLOW_ITEM_TYPE_PORT_ID:
14207 : 0 : flow_dv_translate_item_port_id
14208 : : (dev, key, items, wks->attr, key_type);
14209 : : last_item = MLX5_FLOW_ITEM_PORT_ID;
14210 : 0 : break;
14211 : 0 : case RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR:
14212 : 0 : flow_dv_translate_item_port_representor
14213 : : (dev, key, key_type);
14214 : : last_item = MLX5_FLOW_ITEM_PORT_REPRESENTOR;
14215 : 0 : break;
14216 : 0 : case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
14217 : 0 : flow_dv_translate_item_represented_port
14218 : : (dev, key, items, wks->attr, key_type);
14219 : : last_item = MLX5_FLOW_ITEM_REPRESENTED_PORT;
14220 : 0 : break;
14221 : 0 : case RTE_FLOW_ITEM_TYPE_ETH:
14222 : 0 : flow_dv_translate_item_eth(key, items, tunnel,
14223 : : wks->group, key_type);
14224 [ # # ]: 0 : wks->priority = wks->action_flags &
14225 : 0 : MLX5_FLOW_ACTION_DEFAULT_MISS &&
14226 [ # # ]: 0 : !wks->external ?
14227 : : MLX5_PRIORITY_MAP_L3 :
14228 : : MLX5_PRIORITY_MAP_L2;
14229 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
14230 : : MLX5_FLOW_LAYER_OUTER_L2;
14231 : : break;
14232 : 0 : case RTE_FLOW_ITEM_TYPE_VLAN:
14233 : 0 : flow_dv_translate_item_vlan(key, items, tunnel, wks, key_type);
14234 : 0 : wks->priority = MLX5_PRIORITY_MAP_L2;
14235 : : last_item = tunnel ? (MLX5_FLOW_LAYER_INNER_L2 |
14236 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_VLAN) :
14237 : : (MLX5_FLOW_LAYER_OUTER_L2 |
14238 : : MLX5_FLOW_LAYER_OUTER_VLAN);
14239 : : break;
14240 : : case RTE_FLOW_ITEM_TYPE_IPV4:
14241 : : next_protocol = mlx5_flow_l3_next_protocol(items, key_type);
14242 : : l3_tunnel_detection =
14243 : : mlx5_flow_tunnel_ip_check(items, next_protocol,
14244 : : wks->item_flags,
14245 : : &l3_tunnel_flag);
14246 : : if (l3_tunnel_detection == l3_tunnel_inner) {
14247 : 0 : wks->item_flags |= l3_tunnel_flag;
14248 : : tunnel = 1;
14249 : : }
14250 : 0 : flow_dv_translate_item_ipv4(key, items, tunnel,
14251 : : wks->group, key_type);
14252 : 0 : wks->priority = MLX5_PRIORITY_MAP_L3;
14253 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
14254 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4;
14255 [ # # ]: 0 : if (l3_tunnel_detection == l3_tunnel_outer)
14256 : 0 : wks->item_flags |= l3_tunnel_flag;
14257 : : break;
14258 : : case RTE_FLOW_ITEM_TYPE_IPV6:
14259 : : next_protocol = mlx5_flow_l3_next_protocol(items, key_type);
14260 : : l3_tunnel_detection =
14261 : : mlx5_flow_tunnel_ip_check(items, next_protocol,
14262 : : wks->item_flags,
14263 : : &l3_tunnel_flag);
14264 : : if (l3_tunnel_detection == l3_tunnel_inner) {
14265 : 0 : wks->item_flags |= l3_tunnel_flag;
14266 : : tunnel = 1;
14267 : : }
14268 : 0 : flow_dv_translate_item_ipv6(key, items, tunnel,
14269 : : wks->group, key_type);
14270 : 0 : wks->priority = MLX5_PRIORITY_MAP_L3;
14271 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
14272 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6;
14273 [ # # ]: 0 : if (l3_tunnel_detection == l3_tunnel_outer)
14274 : 0 : wks->item_flags |= l3_tunnel_flag;
14275 : : break;
14276 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
14277 : 0 : flow_dv_translate_item_ipv6_frag_ext
14278 : : (key, items, tunnel, key_type);
14279 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
14280 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
14281 : : next_protocol = mlx5_flow_l3_next_protocol(items, key_type);
14282 : : break;
14283 : 0 : case RTE_FLOW_ITEM_TYPE_TCP:
14284 : 0 : flow_dv_translate_item_tcp(key, items, tunnel, key_type);
14285 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14286 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
14287 : : MLX5_FLOW_LAYER_OUTER_L4_TCP;
14288 : : break;
14289 : 0 : case RTE_FLOW_ITEM_TYPE_UDP:
14290 : 0 : flow_dv_translate_item_udp(key, items, tunnel, wks, key_type);
14291 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14292 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
14293 : : MLX5_FLOW_LAYER_OUTER_L4_UDP;
14294 : : break;
14295 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
14296 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14297 : 0 : wks->tunnel_item = items;
14298 : 0 : wks->gre_item = items;
14299 : : last_item = MLX5_FLOW_LAYER_GRE;
14300 : 0 : break;
14301 : 0 : case RTE_FLOW_ITEM_TYPE_GRE_KEY:
14302 : 0 : flow_dv_translate_item_gre_key(key, items, key_type);
14303 : : last_item = MLX5_FLOW_LAYER_GRE_KEY;
14304 : 0 : break;
14305 : 0 : case RTE_FLOW_ITEM_TYPE_GRE_OPTION:
14306 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14307 : 0 : wks->tunnel_item = items;
14308 : : last_item = MLX5_FLOW_LAYER_GRE;
14309 : 0 : break;
14310 : 0 : case RTE_FLOW_ITEM_TYPE_NVGRE:
14311 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14312 : 0 : wks->tunnel_item = items;
14313 : : last_item = MLX5_FLOW_LAYER_GRE;
14314 : 0 : break;
14315 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN:
14316 : 0 : flow_dv_translate_item_vxlan(dev, wks->attr, key,
14317 : : items, tunnel, wks, key_type);
14318 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14319 : : last_item = MLX5_FLOW_LAYER_VXLAN;
14320 : 0 : break;
14321 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
14322 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14323 : 0 : wks->tunnel_item = items;
14324 : : last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
14325 : 0 : break;
14326 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE:
14327 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14328 : 0 : wks->tunnel_item = items;
14329 : : last_item = MLX5_FLOW_LAYER_GENEVE;
14330 : 0 : break;
14331 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
14332 : 0 : ret = flow_dv_translate_item_geneve_opt
14333 : : (dev, key, items, key_type, error);
14334 [ # # ]: 0 : if (ret)
14335 : 0 : return rte_flow_error_set(error, -ret,
14336 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14337 : : "cannot create GENEVE TLV option");
14338 : 0 : wks->geneve_tlv_option = 1;
14339 : : last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
14340 : 0 : break;
14341 : 0 : case RTE_FLOW_ITEM_TYPE_MPLS:
14342 : 0 : flow_dv_translate_item_mpls(key, items, last_item,
14343 : : tunnel, key_type);
14344 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14345 : : last_item = MLX5_FLOW_LAYER_MPLS;
14346 : 0 : break;
14347 : 0 : case RTE_FLOW_ITEM_TYPE_MARK:
14348 : 0 : flow_dv_translate_item_mark(dev, key, items, key_type);
14349 : : last_item = MLX5_FLOW_ITEM_MARK;
14350 : 0 : break;
14351 : 0 : case RTE_FLOW_ITEM_TYPE_META:
14352 : 0 : flow_dv_translate_item_meta
14353 : : (dev, key, wks->attr, items, key_type);
14354 : : last_item = MLX5_FLOW_ITEM_METADATA;
14355 : 0 : break;
14356 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP:
14357 : 0 : flow_dv_translate_item_icmp(key, items, tunnel, key_type);
14358 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14359 : : last_item = MLX5_FLOW_LAYER_ICMP;
14360 : 0 : break;
14361 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6:
14362 : 0 : flow_dv_translate_item_icmp6(key, items, tunnel, key_type);
14363 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14364 : : last_item = MLX5_FLOW_LAYER_ICMP6;
14365 : 0 : break;
14366 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REQUEST:
14367 : : case RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REPLY:
14368 : 0 : flow_dv_translate_item_icmp6_echo(key, items, tunnel, key_type);
14369 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14370 : : last_item = MLX5_FLOW_LAYER_ICMP6;
14371 : 0 : break;
14372 : 0 : case RTE_FLOW_ITEM_TYPE_TAG:
14373 : 0 : flow_dv_translate_item_tag(dev, key, items, key_type);
14374 : : last_item = MLX5_FLOW_ITEM_TAG;
14375 : 0 : break;
14376 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
14377 : 0 : flow_dv_translate_mlx5_item_tag(dev, key, items, key_type);
14378 : : last_item = MLX5_FLOW_ITEM_TAG;
14379 : 0 : break;
14380 : 0 : case RTE_FLOW_ITEM_TYPE_TX_QUEUE:
14381 : 0 : ret = flow_dv_translate_item_tx_queue(dev, key, items, key_type);
14382 [ # # ]: 0 : if (ret)
14383 : 0 : return rte_flow_error_set(error, -ret,
14384 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14385 : : "invalid tx_queue item");
14386 : : last_item = MLX5_FLOW_ITEM_SQ;
14387 : : break;
14388 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_SQ:
14389 : 0 : flow_dv_translate_item_sq(key, items, key_type);
14390 : : last_item = MLX5_FLOW_ITEM_SQ;
14391 : 0 : break;
14392 : 0 : case RTE_FLOW_ITEM_TYPE_GTP:
14393 : 0 : flow_dv_translate_item_gtp(key, items, tunnel, key_type);
14394 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14395 : : last_item = MLX5_FLOW_LAYER_GTP;
14396 : 0 : break;
14397 : 0 : case RTE_FLOW_ITEM_TYPE_GTP_PSC:
14398 : 0 : ret = flow_dv_translate_item_gtp_psc(key, items, key_type);
14399 [ # # ]: 0 : if (ret)
14400 : 0 : return rte_flow_error_set(error, -ret,
14401 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14402 : : "cannot create GTP PSC item");
14403 : : last_item = MLX5_FLOW_LAYER_GTP_PSC;
14404 : : break;
14405 : 0 : case RTE_FLOW_ITEM_TYPE_ECPRI:
14406 [ # # ]: 0 : if (!mlx5_flex_parser_ecpri_exist(dev)) {
14407 : : /* Create it only the first time to be used. */
14408 : 0 : ret = mlx5_flex_parser_ecpri_alloc(dev);
14409 [ # # ]: 0 : if (ret)
14410 : 0 : return rte_flow_error_set
14411 : : (error, -ret,
14412 : : RTE_FLOW_ERROR_TYPE_ITEM,
14413 : : NULL,
14414 : : "cannot create eCPRI parser");
14415 : : }
14416 : 0 : flow_dv_translate_item_ecpri
14417 : : (dev, key, items, last_item, key_type);
14418 : : /* No other protocol should follow eCPRI layer. */
14419 : : last_item = MLX5_FLOW_LAYER_ECPRI;
14420 : 0 : break;
14421 : 0 : case RTE_FLOW_ITEM_TYPE_METER_COLOR:
14422 : 0 : flow_dv_translate_item_meter_color(dev, key, items, key_type);
14423 : : last_item = MLX5_FLOW_ITEM_METER_COLOR;
14424 : 0 : break;
14425 [ # # ]: 0 : case RTE_FLOW_ITEM_TYPE_INTEGRITY:
14426 : : last_item = flow_dv_translate_item_integrity(items,
14427 : : wks, key_type);
14428 : 0 : break;
14429 : 0 : case RTE_FLOW_ITEM_TYPE_AGGR_AFFINITY:
14430 : 0 : flow_dv_translate_item_aggr_affinity(key, items, key_type);
14431 : : last_item = MLX5_FLOW_ITEM_AGGR_AFFINITY;
14432 : 0 : break;
14433 : 0 : case RTE_FLOW_ITEM_TYPE_IB_BTH:
14434 : 0 : flow_dv_translate_item_ib_bth(key, items, tunnel, key_type);
14435 : : last_item = MLX5_FLOW_ITEM_IB_BTH;
14436 : 0 : break;
14437 : 0 : case RTE_FLOW_ITEM_TYPE_NSH:
14438 : : last_item = MLX5_FLOW_ITEM_NSH;
14439 : 0 : break;
14440 : : default:
14441 : : break;
14442 : : }
14443 : 0 : wks->item_flags |= last_item;
14444 : 0 : wks->last_item = last_item;
14445 : 0 : wks->next_protocol = next_protocol;
14446 : 0 : return 0;
14447 : : }
14448 : :
14449 : : /**
14450 : : * Fill the flow matcher with DV spec for items supported in non template mode.
14451 : : *
14452 : : * @param[in] dev
14453 : : * Pointer to rte_eth_dev structure.
14454 : : * @param[in] items
14455 : : * Pointer to the list of items.
14456 : : * @param[in] wks
14457 : : * Pointer to the matcher workspace.
14458 : : * @param[in] key
14459 : : * Pointer to the flow matcher key.
14460 : : * @param[in] key_type
14461 : : * Key type.
14462 : : * @param[out] error
14463 : : * Pointer to the error structure.
14464 : : *
14465 : : * @return
14466 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14467 : : */
14468 : : static int
14469 : 0 : flow_dv_translate_items_nta(struct rte_eth_dev *dev,
14470 : : const struct rte_flow_item *items,
14471 : : struct mlx5_dv_matcher_workspace *wks,
14472 : : void *key, uint32_t key_type,
14473 : : struct rte_flow_error *error)
14474 : : {
14475 : : int item_type;
14476 : : int ret = 0;
14477 : : int tunnel;
14478 : : /* Dummy structure to enable the key calculation for flex item. */
14479 : : struct mlx5_flow_dv_match_params flex_item_key;
14480 : :
14481 : 0 : tunnel = !!(wks->item_flags & MLX5_FLOW_LAYER_TUNNEL);
14482 : 0 : item_type = items->type;
14483 [ # # # ]: 0 : switch (item_type) {
14484 : 0 : case RTE_FLOW_ITEM_TYPE_CONNTRACK:
14485 : 0 : flow_dv_translate_item_aso_ct(dev, key, NULL, items);
14486 : 0 : wks->last_item = MLX5_FLOW_LAYER_ASO_CT;
14487 : 0 : break;
14488 : : /* TODO: remove once flex item translation is added to flow_dv_translate_items. */
14489 : 0 : case RTE_FLOW_ITEM_TYPE_FLEX:
14490 : 0 : mlx5_flex_flow_translate_item(dev, key, flex_item_key.buf, items, tunnel != 0);
14491 [ # # ]: 0 : wks->last_item = tunnel ? MLX5_FLOW_ITEM_INNER_FLEX : MLX5_FLOW_ITEM_OUTER_FLEX;
14492 : 0 : break;
14493 : 0 : default:
14494 : 0 : ret = flow_dv_translate_items(dev, items, wks, key, key_type, error);
14495 [ # # ]: 0 : if (ret)
14496 : : return ret;
14497 : : break;
14498 : : }
14499 : 0 : wks->item_flags |= wks->last_item;
14500 : 0 : return 0;
14501 : : }
14502 : :
14503 : : /**
14504 : : * Fill the HW steering flow with DV spec.
14505 : : *
14506 : : * @param[in] items
14507 : : * Pointer to the list of items.
14508 : : * @param[in] attr
14509 : : * Pointer to the flow attributes.
14510 : : * @param[in] key
14511 : : * Pointer to the flow matcher key.
14512 : : * @param[in] key_type
14513 : : * Key type.
14514 : : * @param[in, out] item_flags
14515 : : * Pointer to the flow item flags.
14516 : : * @param[in, out] nt_flow
14517 : : * Non template flow.
14518 : : * @param[out] error
14519 : : * Pointer to the error structure.
14520 : : *
14521 : : * @return
14522 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14523 : : */
14524 : : int
14525 : 0 : __flow_dv_translate_items_hws(const struct rte_flow_item *items,
14526 : : struct mlx5_flow_attr *attr, void *key,
14527 : : uint32_t key_type, uint64_t *item_flags,
14528 : : uint8_t *match_criteria,
14529 : : bool nt_flow,
14530 : : struct rte_flow_error *error)
14531 : : {
14532 : 0 : struct mlx5_flow_workspace *flow_wks = mlx5_flow_push_thread_workspace();
14533 : 0 : struct mlx5_flow_rss_desc rss_desc = { .level = attr->rss_level };
14534 : 0 : struct rte_flow_attr rattr = {
14535 : 0 : .group = attr->group,
14536 : 0 : .priority = attr->priority,
14537 : 0 : .ingress = !!(attr->tbl_type == MLX5DR_TABLE_TYPE_NIC_RX),
14538 : 0 : .egress = !!(attr->tbl_type == MLX5DR_TABLE_TYPE_NIC_TX),
14539 : 0 : .transfer = !!(attr->tbl_type == MLX5DR_TABLE_TYPE_FDB),
14540 : : };
14541 : 0 : struct mlx5_dv_matcher_workspace wks = {
14542 : 0 : .action_flags = attr->act_flags,
14543 [ # # ]: 0 : .item_flags = item_flags ? *item_flags : 0,
14544 : : .external = 0,
14545 : : .next_protocol = 0xff,
14546 : : .attr = &rattr,
14547 : : .rss_desc = &rss_desc,
14548 : : .group = attr->group,
14549 : : };
14550 : : int ret = 0;
14551 : :
14552 : : RTE_SET_USED(flow_wks);
14553 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
14554 : : if (!mlx5_flow_os_item_supported(items->type)) {
14555 : : ret = rte_flow_error_set(error, ENOTSUP,
14556 : : RTE_FLOW_ERROR_TYPE_ITEM,
14557 : : NULL, "item not supported");
14558 : : goto exit;
14559 : : }
14560 : : /* Non template flow. */
14561 [ # # ]: 0 : if (nt_flow) {
14562 : 0 : ret = flow_dv_translate_items_nta(&rte_eth_devices[attr->port_id],
14563 : : items, &wks, key, key_type, NULL);
14564 [ # # ]: 0 : if (ret)
14565 : 0 : goto exit;
14566 : : } else {
14567 : 0 : ret = flow_dv_translate_items(&rte_eth_devices[attr->port_id],
14568 : : items, &wks, key, key_type, NULL);
14569 [ # # ]: 0 : if (ret)
14570 : 0 : goto exit;
14571 : : }
14572 : : }
14573 [ # # ]: 0 : if (wks.item_flags & MLX5_FLOW_ITEM_INTEGRITY) {
14574 : 0 : flow_dv_translate_item_integrity_post(key,
14575 : : wks.integrity_items,
14576 : : wks.item_flags,
14577 : : key_type);
14578 : : }
14579 [ # # ]: 0 : if (wks.item_flags & MLX5_FLOW_LAYER_VXLAN_GPE) {
14580 : 0 : flow_dv_translate_item_vxlan_gpe(key,
14581 : : wks.tunnel_item,
14582 : : wks.item_flags,
14583 : : key_type);
14584 [ # # ]: 0 : } else if (wks.item_flags & MLX5_FLOW_LAYER_GENEVE) {
14585 : 0 : flow_dv_translate_item_geneve(key,
14586 : : wks.tunnel_item,
14587 : : wks.item_flags,
14588 : : key_type);
14589 [ # # ]: 0 : } else if (wks.item_flags & MLX5_FLOW_LAYER_GRE) {
14590 [ # # ]: 0 : if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE) {
14591 : 0 : flow_dv_translate_item_gre(key,
14592 : : wks.tunnel_item,
14593 : : wks.item_flags,
14594 : : key_type);
14595 [ # # ]: 0 : } else if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE_OPTION) {
14596 : 0 : flow_dv_translate_item_gre_option(key,
14597 : : wks.tunnel_item,
14598 : : wks.gre_item,
14599 : : wks.item_flags,
14600 : : key_type);
14601 [ # # ]: 0 : } else if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_NVGRE) {
14602 : 0 : flow_dv_translate_item_nvgre(key,
14603 : : wks.tunnel_item,
14604 : : wks.item_flags,
14605 : : key_type);
14606 : : } else {
14607 : : MLX5_ASSERT(false);
14608 : : }
14609 : : }
14610 : :
14611 [ # # ]: 0 : if (match_criteria)
14612 : 0 : *match_criteria = flow_dv_matcher_enable(key);
14613 [ # # ]: 0 : if (item_flags)
14614 : 0 : *item_flags = wks.item_flags;
14615 : 0 : exit:
14616 : 0 : mlx5_flow_pop_thread_workspace();
14617 : 0 : return ret;
14618 : : }
14619 : :
14620 : : /**
14621 : : * Fill the HW steering flow with DV spec.
14622 : : * This function assumes given flow is created from template API.
14623 : : *
14624 : : * @param[in] items
14625 : : * Pointer to the list of items.
14626 : : * @param[in] attr
14627 : : * Pointer to the flow attributes.
14628 : : * @param[in] key
14629 : : * Pointer to the flow matcher key.
14630 : : * @param[in] key_type
14631 : : * Key type.
14632 : : * @param[in, out] item_flags
14633 : : * Pointer to the flow item flags.
14634 : : * @param[out] error
14635 : : * Pointer to the error structure.
14636 : : *
14637 : : * @return
14638 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14639 : : */
14640 : : int
14641 : 0 : flow_dv_translate_items_hws(const struct rte_flow_item *items,
14642 : : struct mlx5_flow_attr *attr, void *key,
14643 : : uint32_t key_type, uint64_t *item_flags,
14644 : : uint8_t *match_criteria,
14645 : : struct rte_flow_error *error)
14646 : : {
14647 : 0 : return __flow_dv_translate_items_hws(items, attr, key, key_type, item_flags, match_criteria,
14648 : : false, error);
14649 : : }
14650 : :
14651 : : /**
14652 : : * Fill the SW steering flow with DV spec.
14653 : : *
14654 : : * @param[in] dev
14655 : : * Pointer to rte_eth_dev structure.
14656 : : * @param[in, out] dev_flow
14657 : : * Pointer to the sub flow.
14658 : : * @param[in] attr
14659 : : * Pointer to the flow attributes.
14660 : : * @param[in] items
14661 : : * Pointer to the list of items.
14662 : : * @param[in, out] matcher
14663 : : * Pointer to the flow matcher.
14664 : : * @param[out] error
14665 : : * Pointer to the error structure.
14666 : : *
14667 : : * @return
14668 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14669 : : */
14670 : : static int
14671 : 0 : flow_dv_translate_items_sws(struct rte_eth_dev *dev,
14672 : : struct mlx5_flow *dev_flow,
14673 : : const struct rte_flow_attr *attr,
14674 : : const struct rte_flow_item *items,
14675 : : struct mlx5_flow_dv_matcher *matcher,
14676 : : struct rte_flow_error *error)
14677 : : {
14678 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14679 : 0 : void *match_mask = matcher->mask.buf;
14680 : 0 : void *match_value = dev_flow->dv.value.buf;
14681 : 0 : struct mlx5_dv_matcher_workspace wks = {
14682 : 0 : .action_flags = dev_flow->act_flags,
14683 : : .item_flags = 0,
14684 : 0 : .external = dev_flow->external,
14685 : : .next_protocol = 0xff,
14686 : 0 : .group = dev_flow->dv.group,
14687 : : .attr = attr,
14688 : 0 : .rss_desc = &((struct mlx5_flow_workspace *)
14689 : : mlx5_flow_get_thread_workspace())->rss_desc,
14690 : : };
14691 : 0 : struct mlx5_dv_matcher_workspace wks_m = wks;
14692 : : int item_type;
14693 : : int ret = 0;
14694 : : int tunnel;
14695 : :
14696 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
14697 : 0 : if (!mlx5_flow_os_item_supported(items->type))
14698 : : return rte_flow_error_set(error, ENOTSUP,
14699 : : RTE_FLOW_ERROR_TYPE_ITEM,
14700 : : NULL, "item not supported");
14701 : 0 : tunnel = !!(wks.item_flags & MLX5_FLOW_LAYER_TUNNEL);
14702 : : item_type = items->type;
14703 [ # # # # : 0 : switch (item_type) {
# ]
14704 : 0 : case RTE_FLOW_ITEM_TYPE_CONNTRACK:
14705 : 0 : flow_dv_translate_item_aso_ct(dev, match_mask,
14706 : : match_value, items);
14707 : 0 : wks.last_item = MLX5_FLOW_LAYER_ASO_CT;
14708 : 0 : break;
14709 : 0 : case RTE_FLOW_ITEM_TYPE_FLEX:
14710 : 0 : flow_dv_translate_item_flex(dev, match_mask,
14711 : : match_value, items,
14712 : : dev_flow, tunnel != 0);
14713 [ # # ]: 0 : wks.last_item = tunnel ? MLX5_FLOW_ITEM_INNER_FLEX :
14714 : : MLX5_FLOW_ITEM_OUTER_FLEX;
14715 : 0 : break;
14716 : 0 : case RTE_FLOW_ITEM_TYPE_TX_QUEUE:
14717 : 0 : ret = flow_dv_translate_item_tx_queue(dev, match_value, items,
14718 : : MLX5_SET_MATCHER_SW_V);
14719 [ # # ]: 0 : if (ret)
14720 : 0 : return rte_flow_error_set(error, -ret,
14721 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14722 : : "invalid tx_queue item spec");
14723 : 0 : ret = flow_dv_translate_item_tx_queue(dev, match_mask, items,
14724 : : MLX5_SET_MATCHER_SW_M);
14725 [ # # ]: 0 : if (ret)
14726 : 0 : return rte_flow_error_set(error, -ret,
14727 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14728 : : "invalid tx_queue item mask");
14729 : : break;
14730 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_SQ:
14731 : 0 : flow_dv_translate_item_sq(match_value, items,
14732 : : MLX5_SET_MATCHER_SW_V);
14733 : 0 : flow_dv_translate_item_sq(match_mask, items,
14734 : : MLX5_SET_MATCHER_SW_M);
14735 : 0 : break;
14736 : 0 : default:
14737 : 0 : ret = flow_dv_translate_items(dev, items, &wks_m,
14738 : : match_mask, MLX5_SET_MATCHER_SW_M, error);
14739 [ # # ]: 0 : if (ret)
14740 : 0 : return ret;
14741 : 0 : ret = flow_dv_translate_items(dev, items, &wks,
14742 : : match_value, MLX5_SET_MATCHER_SW_V, error);
14743 [ # # ]: 0 : if (ret)
14744 : 0 : return ret;
14745 : : break;
14746 : : }
14747 : 0 : wks.item_flags |= wks.last_item;
14748 : : }
14749 : : /*
14750 : : * When E-Switch mode is enabled, we have two cases where we need to
14751 : : * set the source port manually.
14752 : : * The first one, is in case of NIC ingress steering rule, and the
14753 : : * second is E-Switch rule where no port_id item was found.
14754 : : * In both cases the source port is set according the current port
14755 : : * in use.
14756 : : */
14757 : 0 : if (!(wks.item_flags & MLX5_FLOW_ITEM_PORT_ID) &&
14758 [ # # ]: 0 : !(wks.item_flags & MLX5_FLOW_ITEM_REPRESENTED_PORT) &&
14759 : 0 : !(wks.item_flags & MLX5_FLOW_ITEM_PORT_REPRESENTOR) &&
14760 [ # # ]: 0 : priv->sh->esw_mode &&
14761 [ # # ]: 0 : !attr->egress &&
14762 [ # # ]: 0 : attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP) {
14763 [ # # ]: 0 : if (flow_dv_translate_item_port_id_all(dev, match_mask,
14764 : : match_value, NULL, attr))
14765 : 0 : return -rte_errno;
14766 : : }
14767 [ # # ]: 0 : if (wks.item_flags & MLX5_FLOW_ITEM_INTEGRITY) {
14768 : 0 : flow_dv_translate_item_integrity_post(match_mask,
14769 : : wks_m.integrity_items,
14770 : : wks_m.item_flags,
14771 : : MLX5_SET_MATCHER_SW_M);
14772 : 0 : flow_dv_translate_item_integrity_post(match_value,
14773 : : wks.integrity_items,
14774 : : wks.item_flags,
14775 : : MLX5_SET_MATCHER_SW_V);
14776 : : }
14777 [ # # ]: 0 : if (wks.item_flags & MLX5_FLOW_LAYER_VXLAN_GPE) {
14778 : 0 : flow_dv_translate_item_vxlan_gpe(match_mask,
14779 : : wks.tunnel_item,
14780 : : wks.item_flags,
14781 : : MLX5_SET_MATCHER_SW_M);
14782 : 0 : flow_dv_translate_item_vxlan_gpe(match_value,
14783 : : wks.tunnel_item,
14784 : : wks.item_flags,
14785 : : MLX5_SET_MATCHER_SW_V);
14786 [ # # ]: 0 : } else if (wks.item_flags & MLX5_FLOW_LAYER_GENEVE) {
14787 : 0 : flow_dv_translate_item_geneve(match_mask,
14788 : : wks.tunnel_item,
14789 : : wks.item_flags,
14790 : : MLX5_SET_MATCHER_SW_M);
14791 : 0 : flow_dv_translate_item_geneve(match_value,
14792 : : wks.tunnel_item,
14793 : : wks.item_flags,
14794 : : MLX5_SET_MATCHER_SW_V);
14795 [ # # ]: 0 : } else if (wks.item_flags & MLX5_FLOW_LAYER_GRE) {
14796 [ # # ]: 0 : if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE) {
14797 : 0 : flow_dv_translate_item_gre(match_mask,
14798 : : wks.tunnel_item,
14799 : : wks.item_flags,
14800 : : MLX5_SET_MATCHER_SW_M);
14801 : 0 : flow_dv_translate_item_gre(match_value,
14802 : : wks.tunnel_item,
14803 : : wks.item_flags,
14804 : : MLX5_SET_MATCHER_SW_V);
14805 [ # # ]: 0 : } else if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_NVGRE) {
14806 : 0 : flow_dv_translate_item_nvgre(match_mask,
14807 : : wks.tunnel_item,
14808 : : wks.item_flags,
14809 : : MLX5_SET_MATCHER_SW_M);
14810 : 0 : flow_dv_translate_item_nvgre(match_value,
14811 : : wks.tunnel_item,
14812 : : wks.item_flags,
14813 : : MLX5_SET_MATCHER_SW_V);
14814 [ # # ]: 0 : } else if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE_OPTION) {
14815 : 0 : flow_dv_translate_item_gre_option(match_mask,
14816 : : wks.tunnel_item,
14817 : : wks.gre_item,
14818 : : wks.item_flags,
14819 : : MLX5_SET_MATCHER_SW_M);
14820 : 0 : flow_dv_translate_item_gre_option(match_value,
14821 : : wks.tunnel_item,
14822 : : wks.gre_item,
14823 : : wks.item_flags,
14824 : : MLX5_SET_MATCHER_SW_V);
14825 : : } else {
14826 : : MLX5_ASSERT(false);
14827 : : }
14828 : : }
14829 : 0 : dev_flow->handle->vf_vlan.tag = wks.vlan_tag;
14830 : 0 : matcher->priority = wks.priority;
14831 : : #ifdef RTE_LIBRTE_MLX5_DEBUG
14832 : : MLX5_ASSERT(!flow_dv_check_valid_spec(match_mask, match_value));
14833 : : #endif
14834 : : /*
14835 : : * Layers may be already initialized from prefix flow if this dev_flow
14836 : : * is the suffix flow.
14837 : : */
14838 : 0 : dev_flow->handle->layers |= wks.item_flags;
14839 : : /*
14840 : : * Update geneve_tlv_option flag only it is set in workspace.
14841 : : * Avoid be overwritten by other sub mlx5_flows.
14842 : : */
14843 [ # # ]: 0 : if (wks.geneve_tlv_option)
14844 : 0 : dev_flow->flow->geneve_tlv_option += wks.geneve_tlv_option;
14845 : : return 0;
14846 : : }
14847 : :
14848 : : /**
14849 : : * Fill the flow with DV spec, lock free
14850 : : * (mutex should be acquired by caller).
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] actions
14861 : : * Pointer to the list of actions.
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(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 : : const struct rte_flow_action actions[],
14874 : : struct rte_flow_error *error)
14875 : : {
14876 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14877 : 0 : struct mlx5_sh_config *dev_conf = &priv->sh->config;
14878 : 0 : struct rte_flow *flow = dev_flow->flow;
14879 : 0 : struct mlx5_flow_handle *handle = dev_flow->handle;
14880 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
14881 : : struct mlx5_flow_rss_desc *rss_desc;
14882 : : uint64_t action_flags = 0;
14883 : 0 : struct mlx5_flow_dv_matcher matcher = {
14884 : : .mask = {
14885 : : .size = sizeof(matcher.mask.buf),
14886 : : },
14887 : : };
14888 : : int actions_n = 0;
14889 : : bool actions_end = false;
14890 : : union {
14891 : : struct mlx5_flow_dv_modify_hdr_resource res;
14892 : : uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
14893 : : sizeof(struct mlx5_modification_cmd) *
14894 : : (MLX5_MAX_MODIFY_NUM + 1)];
14895 : : } mhdr_dummy;
14896 : : struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
14897 : : const struct rte_flow_action_count *count = NULL;
14898 : : const struct rte_flow_action_age *non_shared_age = NULL;
14899 : 0 : union flow_dv_attr flow_attr = { .attr = 0 };
14900 : : uint32_t tag_be;
14901 : : union mlx5_flow_tbl_key tbl_key;
14902 : : uint32_t modify_action_position = UINT32_MAX;
14903 : 0 : struct rte_vlan_hdr vlan = { 0 };
14904 : : struct mlx5_flow_dv_dest_array_resource mdest_res;
14905 : : struct mlx5_flow_dv_sample_resource sample_res;
14906 : 0 : void *sample_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
14907 : : const struct rte_flow_action_sample *sample = NULL;
14908 : : struct mlx5_flow_sub_actions_list *sample_act;
14909 : : uint32_t sample_act_pos = UINT32_MAX;
14910 : : uint32_t age_act_pos = UINT32_MAX;
14911 : : uint32_t ipv6_tc_off = 0;
14912 : 0 : uint32_t num_of_dest = 0;
14913 : : int tmp_actions_n = 0;
14914 : : uint32_t table;
14915 : : int ret = 0;
14916 : : const struct mlx5_flow_tunnel *tunnel = NULL;
14917 : 0 : struct flow_grp_info grp_info = {
14918 : 0 : .external = !!dev_flow->external,
14919 : 0 : .transfer = !!attr->transfer,
14920 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
14921 : 0 : .skip_scale = dev_flow->skip_scale &
14922 : : (1 << MLX5_SCALE_FLOW_GROUP_BIT),
14923 : : .std_tbl_fix = true,
14924 : : };
14925 : :
14926 [ # # ]: 0 : if (!wks)
14927 : 0 : return rte_flow_error_set(error, ENOMEM,
14928 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
14929 : : NULL,
14930 : : "failed to push flow workspace");
14931 [ # # ]: 0 : rss_desc = &wks->rss_desc;
14932 : : memset(&mdest_res, 0, sizeof(struct mlx5_flow_dv_dest_array_resource));
14933 : : memset(&sample_res, 0, sizeof(struct mlx5_flow_dv_sample_resource));
14934 [ # # ]: 0 : mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
14935 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
14936 : : /* update normal path action resource into last index of array */
14937 : : sample_act = &mdest_res.sample_act[MLX5_MAX_DEST_NUM - 1];
14938 [ # # ]: 0 : if (is_tunnel_offload_active(dev)) {
14939 [ # # ]: 0 : if (dev_flow->tunnel) {
14940 [ # # ]: 0 : RTE_VERIFY(dev_flow->tof_type ==
14941 : : MLX5_TUNNEL_OFFLOAD_MISS_RULE);
14942 : : tunnel = dev_flow->tunnel;
14943 : : } else {
14944 : 0 : tunnel = mlx5_get_tof(items, actions,
14945 : : &dev_flow->tof_type);
14946 : 0 : dev_flow->tunnel = tunnel;
14947 : : }
14948 [ # # ]: 0 : grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
14949 : : (dev, attr, tunnel, dev_flow->tof_type);
14950 : : }
14951 : 0 : mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
14952 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
14953 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel, attr->group, &table,
14954 : : &grp_info, error);
14955 [ # # ]: 0 : if (ret)
14956 : : return ret;
14957 : 0 : dev_flow->dv.group = table;
14958 [ # # ]: 0 : if (attr->transfer)
14959 : 0 : mhdr_res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
14960 : : /* number of actions must be set to 0 in case of dirty stack. */
14961 : 0 : mhdr_res->actions_num = 0;
14962 [ # # ]: 0 : if (is_flow_tunnel_match_rule(dev_flow->tof_type)) {
14963 : : /*
14964 : : * do not add decap action if match rule drops packet
14965 : : * HW rejects rules with decap & drop
14966 : : *
14967 : : * if tunnel match rule was inserted before matching tunnel set
14968 : : * rule flow table used in the match rule must be registered.
14969 : : * current implementation handles that in the
14970 : : * flow_dv_match_register() at the function end.
14971 : : */
14972 : : bool add_decap = true;
14973 : : const struct rte_flow_action *ptr = actions;
14974 : :
14975 [ # # ]: 0 : for (; ptr->type != RTE_FLOW_ACTION_TYPE_END; ptr++) {
14976 [ # # ]: 0 : if (ptr->type == RTE_FLOW_ACTION_TYPE_DROP) {
14977 : : add_decap = false;
14978 : : break;
14979 : : }
14980 : : }
14981 [ # # ]: 0 : if (add_decap) {
14982 [ # # ]: 0 : if (flow_dv_create_action_l2_decap(dev, dev_flow,
14983 : 0 : attr->transfer,
14984 : : error))
14985 : 0 : return -rte_errno;
14986 : 0 : dev_flow->dv.actions[actions_n++] =
14987 : 0 : dev_flow->dv.encap_decap->action;
14988 : : action_flags |= MLX5_FLOW_ACTION_DECAP;
14989 : : }
14990 : : }
14991 [ # # ]: 0 : for (; !actions_end ; actions++) {
14992 : : const struct rte_flow_action_queue *queue;
14993 : : const struct rte_flow_action_rss *rss;
14994 : : const struct rte_flow_action *action = actions;
14995 : : const uint8_t *rss_key;
14996 : : struct mlx5_flow_tbl_resource *tbl;
14997 : : struct mlx5_aso_age_action *age_act;
14998 : : struct mlx5_flow_counter *cnt_act;
14999 : 0 : uint32_t port_id = 0;
15000 : : struct mlx5_flow_dv_port_id_action_resource port_id_resource;
15001 : 0 : int action_type = actions->type;
15002 : : const struct rte_flow_action *found_action = NULL;
15003 : : uint32_t jump_group = 0;
15004 : : uint32_t owner_idx;
15005 : : struct mlx5_aso_ct_action *ct;
15006 : :
15007 : : if (!mlx5_flow_os_action_supported(action_type))
15008 : 0 : return rte_flow_error_set(error, ENOTSUP,
15009 : : RTE_FLOW_ERROR_TYPE_ACTION,
15010 : : actions,
15011 : : "action not supported");
15012 [ # # # # : 0 : switch (action_type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
15013 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
15014 : 0 : action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
15015 : 0 : break;
15016 : : case RTE_FLOW_ACTION_TYPE_VOID:
15017 : : break;
15018 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
15019 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
15020 [ # # ]: 0 : if (flow_dv_translate_action_port_id(dev, action,
15021 : : &port_id, error))
15022 : 0 : return -rte_errno;
15023 : 0 : port_id_resource.port_id = port_id;
15024 : : MLX5_ASSERT(!handle->rix_port_id_action);
15025 [ # # ]: 0 : if (flow_dv_port_id_action_resource_register
15026 : : (dev, &port_id_resource, dev_flow, error))
15027 : 0 : return -rte_errno;
15028 : 0 : dev_flow->dv.actions[actions_n++] =
15029 : 0 : dev_flow->dv.port_id_action->action;
15030 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_ID;
15031 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_PORT_ID;
15032 : 0 : sample_act->action_flags |= MLX5_FLOW_ACTION_PORT_ID;
15033 : 0 : num_of_dest++;
15034 : 0 : break;
15035 : 0 : case RTE_FLOW_ACTION_TYPE_FLAG:
15036 : 0 : action_flags |= MLX5_FLOW_ACTION_FLAG;
15037 : 0 : wks->mark = 1;
15038 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
15039 : 0 : struct rte_flow_action_mark mark = {
15040 : : .id = MLX5_FLOW_MARK_DEFAULT,
15041 : : };
15042 : :
15043 [ # # ]: 0 : if (flow_dv_convert_action_mark(dev, &mark,
15044 : : mhdr_res,
15045 : : error))
15046 : 0 : return -rte_errno;
15047 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
15048 : 0 : break;
15049 : : }
15050 : : tag_be = mlx5_flow_mark_set(MLX5_FLOW_MARK_DEFAULT);
15051 : : /*
15052 : : * Only one FLAG or MARK is supported per device flow
15053 : : * right now. So the pointer to the tag resource must be
15054 : : * zero before the register process.
15055 : : */
15056 : : MLX5_ASSERT(!handle->dvh.rix_tag);
15057 [ # # ]: 0 : if (flow_dv_tag_resource_register(dev, tag_be,
15058 : : dev_flow, error))
15059 : 0 : return -rte_errno;
15060 : : MLX5_ASSERT(dev_flow->dv.tag_resource);
15061 : 0 : dev_flow->dv.actions[actions_n++] =
15062 : 0 : dev_flow->dv.tag_resource->action;
15063 : 0 : break;
15064 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
15065 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK;
15066 : 0 : wks->mark = 1;
15067 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
15068 : 0 : const struct rte_flow_action_mark *mark =
15069 : : (const struct rte_flow_action_mark *)
15070 : : actions->conf;
15071 : :
15072 [ # # ]: 0 : if (flow_dv_convert_action_mark(dev, mark,
15073 : : mhdr_res,
15074 : : error))
15075 : 0 : return -rte_errno;
15076 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
15077 : 0 : break;
15078 : : }
15079 : : /* Fall-through */
15080 : : case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
15081 : : /* Legacy (non-extensive) MARK action. */
15082 : : tag_be = mlx5_flow_mark_set
15083 : : (((const struct rte_flow_action_mark *)
15084 [ # # ]: 0 : (actions->conf))->id);
15085 : : MLX5_ASSERT(!handle->dvh.rix_tag);
15086 [ # # ]: 0 : if (flow_dv_tag_resource_register(dev, tag_be,
15087 : : dev_flow, error))
15088 : 0 : return -rte_errno;
15089 : : MLX5_ASSERT(dev_flow->dv.tag_resource);
15090 : 0 : dev_flow->dv.actions[actions_n++] =
15091 : 0 : dev_flow->dv.tag_resource->action;
15092 : 0 : break;
15093 : 0 : case RTE_FLOW_ACTION_TYPE_SET_META:
15094 [ # # ]: 0 : if (flow_dv_convert_action_set_meta
15095 : : (dev, mhdr_res, attr,
15096 : : (const struct rte_flow_action_set_meta *)
15097 : 0 : actions->conf, error))
15098 : 0 : return -rte_errno;
15099 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_META;
15100 : 0 : break;
15101 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TAG:
15102 [ # # ]: 0 : if (flow_dv_convert_action_set_tag
15103 : : (dev, mhdr_res,
15104 : : (const struct rte_flow_action_set_tag *)
15105 : 0 : actions->conf, error))
15106 : 0 : return -rte_errno;
15107 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
15108 : 0 : break;
15109 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
15110 : 0 : action_flags |= MLX5_FLOW_ACTION_DROP;
15111 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_DROP;
15112 : 0 : break;
15113 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
15114 : 0 : queue = actions->conf;
15115 : 0 : rss_desc->queue_num = 1;
15116 : 0 : rss_desc->queue[0] = queue->index;
15117 : 0 : action_flags |= MLX5_FLOW_ACTION_QUEUE;
15118 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
15119 : 0 : sample_act->action_flags |= MLX5_FLOW_ACTION_QUEUE;
15120 : 0 : num_of_dest++;
15121 : 0 : break;
15122 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
15123 : 0 : rss = actions->conf;
15124 : 0 : rss_desc->symmetric_hash_function =
15125 : 0 : MLX5_RSS_IS_SYMM(rss->func);
15126 : 0 : memcpy(rss_desc->queue, rss->queue,
15127 [ # # ]: 0 : rss->queue_num * sizeof(uint16_t));
15128 : 0 : rss_desc->queue_num = rss->queue_num;
15129 : : /* NULL RSS key indicates default RSS key. */
15130 [ # # ]: 0 : rss_key = !rss->key ? rss_hash_default_key : rss->key;
15131 [ # # ]: 0 : memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
15132 : : /*
15133 : : * rss->level and rss.types should be set in advance
15134 : : * when expanding items for RSS.
15135 : : */
15136 : 0 : action_flags |= MLX5_FLOW_ACTION_RSS;
15137 : 0 : dev_flow->handle->fate_action = rss_desc->shared_rss ?
15138 [ # # ]: 0 : MLX5_FLOW_FATE_SHARED_RSS :
15139 : : MLX5_FLOW_FATE_QUEUE;
15140 : 0 : break;
15141 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
15142 : 0 : owner_idx = (uint32_t)(uintptr_t)action->conf;
15143 : 0 : age_act = flow_aso_age_get_by_idx(dev, owner_idx);
15144 [ # # ]: 0 : if (flow->age == 0) {
15145 : 0 : flow->age = owner_idx;
15146 : 0 : rte_atomic_fetch_add_explicit(&age_act->refcnt, 1,
15147 : : rte_memory_order_relaxed);
15148 : : }
15149 : 0 : age_act_pos = actions_n++;
15150 : 0 : action_flags |= MLX5_FLOW_ACTION_AGE;
15151 : 0 : break;
15152 : 0 : case RTE_FLOW_ACTION_TYPE_SEND_TO_KERNEL:
15153 : 0 : dev_flow->dv.actions[actions_n] =
15154 : 0 : flow_dv_translate_action_send_to_kernel(dev, attr,
15155 : : error);
15156 [ # # ]: 0 : if (!dev_flow->dv.actions[actions_n])
15157 : 0 : return -rte_errno;
15158 : 0 : actions_n++;
15159 : 0 : action_flags |= MLX5_FLOW_ACTION_SEND_TO_KERNEL;
15160 : 0 : dev_flow->handle->fate_action =
15161 : : MLX5_FLOW_FATE_SEND_TO_KERNEL;
15162 : 0 : break;
15163 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
15164 : 0 : non_shared_age = action->conf;
15165 : 0 : age_act_pos = actions_n++;
15166 : 0 : action_flags |= MLX5_FLOW_ACTION_AGE;
15167 : 0 : break;
15168 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
15169 [ # # ]: 0 : owner_idx = (uint32_t)(uintptr_t)action->conf;
15170 : : cnt_act = flow_dv_counter_get_by_idx(dev, owner_idx,
15171 : : NULL);
15172 : : MLX5_ASSERT(cnt_act != NULL);
15173 : : /**
15174 : : * When creating meter drop flow in drop table, the
15175 : : * counter should not overwrite the rte flow counter.
15176 : : */
15177 [ # # ]: 0 : if (attr->group == MLX5_FLOW_TABLE_LEVEL_METER &&
15178 [ # # ]: 0 : dev_flow->dv.table_id == MLX5_MTR_TABLE_ID_DROP) {
15179 : 0 : dev_flow->dv.actions[actions_n++] =
15180 : 0 : cnt_act->action;
15181 : : } else {
15182 [ # # ]: 0 : if (flow->counter == 0) {
15183 : 0 : flow->counter = owner_idx;
15184 : 0 : rte_atomic_fetch_add_explicit
15185 : : (&cnt_act->shared_info.refcnt,
15186 : : 1, rte_memory_order_relaxed);
15187 : : }
15188 : : /* Save information first, will apply later. */
15189 : 0 : action_flags |= MLX5_FLOW_ACTION_COUNT;
15190 : : }
15191 : : break;
15192 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
15193 [ # # ]: 0 : if (!priv->sh->cdev->config.devx) {
15194 : 0 : return rte_flow_error_set
15195 : : (error, ENOTSUP,
15196 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15197 : : NULL,
15198 : : "count action not supported");
15199 : : }
15200 : : /* Save information first, will apply later. */
15201 : 0 : count = action->conf;
15202 : 0 : action_flags |= MLX5_FLOW_ACTION_COUNT;
15203 : 0 : break;
15204 : 0 : case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
15205 : 0 : dev_flow->dv.actions[actions_n++] =
15206 : 0 : priv->sh->pop_vlan_action;
15207 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
15208 : 0 : break;
15209 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
15210 [ # # ]: 0 : if (!(action_flags &
15211 : : MLX5_FLOW_ACTION_OF_SET_VLAN_VID))
15212 : 0 : flow_dev_get_vlan_info_from_items(items, &vlan);
15213 [ # # ]: 0 : vlan.eth_proto = rte_be_to_cpu_16
15214 : : ((((const struct rte_flow_action_of_push_vlan *)
15215 : : actions->conf)->ethertype));
15216 : 0 : found_action = mlx5_flow_find_action
15217 : : (actions + 1,
15218 : : RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID);
15219 [ # # ]: 0 : if (found_action)
15220 : 0 : mlx5_update_vlan_vid_pcp(found_action, &vlan);
15221 : 0 : found_action = mlx5_flow_find_action
15222 : : (actions + 1,
15223 : : RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP);
15224 [ # # ]: 0 : if (found_action)
15225 : 0 : mlx5_update_vlan_vid_pcp(found_action, &vlan);
15226 [ # # ]: 0 : if (flow_dv_create_action_push_vlan
15227 : : (dev, attr, &vlan, dev_flow, error))
15228 : 0 : return -rte_errno;
15229 : 0 : dev_flow->dv.actions[actions_n++] =
15230 : 0 : dev_flow->dv.push_vlan_res->action;
15231 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
15232 : 0 : break;
15233 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
15234 : : /* of_vlan_push action handled this action */
15235 : : MLX5_ASSERT(action_flags &
15236 : : MLX5_FLOW_ACTION_OF_PUSH_VLAN);
15237 : : break;
15238 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
15239 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
15240 : : break;
15241 : 0 : flow_dev_get_vlan_info_from_items(items, &vlan);
15242 : 0 : mlx5_update_vlan_vid_pcp(actions, &vlan);
15243 : : /* If no VLAN push - this is a modify header action */
15244 [ # # ]: 0 : if (flow_dv_convert_action_modify_vlan_vid
15245 : : (mhdr_res, actions, error))
15246 : 0 : return -rte_errno;
15247 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
15248 : 0 : break;
15249 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
15250 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
15251 [ # # ]: 0 : if (flow_dv_create_action_l2_encap(dev, actions,
15252 : : dev_flow,
15253 : 0 : attr->transfer,
15254 : : error))
15255 : 0 : return -rte_errno;
15256 : 0 : dev_flow->dv.actions[actions_n++] =
15257 : 0 : dev_flow->dv.encap_decap->action;
15258 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
15259 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
15260 : 0 : sample_act->action_flags |=
15261 : : MLX5_FLOW_ACTION_ENCAP;
15262 : : break;
15263 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
15264 : : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
15265 [ # # ]: 0 : if (flow_dv_create_action_l2_decap(dev, dev_flow,
15266 : 0 : attr->transfer,
15267 : : error))
15268 : 0 : return -rte_errno;
15269 : 0 : dev_flow->dv.actions[actions_n++] =
15270 : 0 : dev_flow->dv.encap_decap->action;
15271 : 0 : action_flags |= MLX5_FLOW_ACTION_DECAP;
15272 : 0 : break;
15273 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
15274 : : /* Handle encap with preceding decap. */
15275 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_DECAP) {
15276 [ # # ]: 0 : if (flow_dv_create_action_raw_encap
15277 : : (dev, actions, dev_flow, attr, error))
15278 : 0 : return -rte_errno;
15279 : 0 : dev_flow->dv.actions[actions_n++] =
15280 : 0 : dev_flow->dv.encap_decap->action;
15281 : : } else {
15282 : : /* Handle encap without preceding decap. */
15283 [ # # ]: 0 : if (flow_dv_create_action_l2_encap
15284 : 0 : (dev, actions, dev_flow, attr->transfer,
15285 : : error))
15286 : 0 : return -rte_errno;
15287 : 0 : dev_flow->dv.actions[actions_n++] =
15288 : 0 : dev_flow->dv.encap_decap->action;
15289 : : }
15290 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
15291 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
15292 : 0 : sample_act->action_flags |=
15293 : : MLX5_FLOW_ACTION_ENCAP;
15294 : : break;
15295 : : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
15296 [ # # ]: 0 : while ((++action)->type == RTE_FLOW_ACTION_TYPE_VOID)
15297 : : ;
15298 [ # # ]: 0 : if (action->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
15299 [ # # ]: 0 : if (flow_dv_create_action_l2_decap
15300 : 0 : (dev, dev_flow, attr->transfer, error))
15301 : 0 : return -rte_errno;
15302 : 0 : dev_flow->dv.actions[actions_n++] =
15303 : 0 : dev_flow->dv.encap_decap->action;
15304 : : }
15305 : : /* If decap is followed by encap, handle it at encap. */
15306 : 0 : action_flags |= MLX5_FLOW_ACTION_DECAP;
15307 : 0 : break;
15308 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_JUMP:
15309 : 0 : dev_flow->dv.actions[actions_n++] =
15310 : 0 : (void *)(uintptr_t)action->conf;
15311 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP;
15312 : 0 : break;
15313 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
15314 : 0 : jump_group = ((const struct rte_flow_action_jump *)
15315 : 0 : action->conf)->group;
15316 : 0 : grp_info.std_tbl_fix = 0;
15317 [ # # ]: 0 : if (dev_flow->skip_scale &
15318 : : (1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT))
15319 : 0 : grp_info.skip_scale = 1;
15320 : : else
15321 : 0 : grp_info.skip_scale = 0;
15322 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel,
15323 : : jump_group,
15324 : : &table,
15325 : : &grp_info, error);
15326 [ # # ]: 0 : if (ret)
15327 : 0 : return ret;
15328 : 0 : tbl = flow_dv_tbl_resource_get(dev, table, attr->egress,
15329 : 0 : attr->transfer,
15330 : 0 : !!dev_flow->external,
15331 : : tunnel, jump_group, 0,
15332 : : 0, error);
15333 [ # # ]: 0 : if (!tbl)
15334 : 0 : return rte_flow_error_set
15335 : 0 : (error, errno,
15336 : : RTE_FLOW_ERROR_TYPE_ACTION,
15337 : : NULL,
15338 : : "cannot create jump action.");
15339 : : if (flow_dv_jump_tbl_resource_register
15340 : : (dev, tbl, dev_flow, error)) {
15341 : : flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
15342 : : return rte_flow_error_set
15343 : : (error, errno,
15344 : : RTE_FLOW_ERROR_TYPE_ACTION,
15345 : : NULL,
15346 : : "cannot create jump action.");
15347 : : }
15348 : 0 : dev_flow->dv.actions[actions_n++] =
15349 : 0 : dev_flow->dv.jump->action;
15350 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP;
15351 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_JUMP;
15352 : 0 : sample_act->action_flags |= MLX5_FLOW_ACTION_JUMP;
15353 : 0 : num_of_dest++;
15354 : 0 : break;
15355 : 0 : case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
15356 : : case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
15357 [ # # ]: 0 : if (flow_dv_convert_action_modify_mac
15358 : : (mhdr_res, actions, error))
15359 : 0 : return -rte_errno;
15360 : 0 : action_flags |= actions->type ==
15361 : : RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
15362 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_MAC_SRC :
15363 : : MLX5_FLOW_ACTION_SET_MAC_DST;
15364 : 0 : break;
15365 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
15366 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
15367 [ # # ]: 0 : if (flow_dv_convert_action_modify_ipv4
15368 : : (mhdr_res, actions, error))
15369 : 0 : return -rte_errno;
15370 : 0 : action_flags |= actions->type ==
15371 : : RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
15372 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_IPV4_SRC :
15373 : : MLX5_FLOW_ACTION_SET_IPV4_DST;
15374 : 0 : break;
15375 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
15376 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
15377 [ # # ]: 0 : if (flow_dv_convert_action_modify_ipv6
15378 : : (mhdr_res, actions, error))
15379 : 0 : return -rte_errno;
15380 : 0 : action_flags |= actions->type ==
15381 : : RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
15382 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_IPV6_SRC :
15383 : : MLX5_FLOW_ACTION_SET_IPV6_DST;
15384 : 0 : break;
15385 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
15386 : : case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
15387 [ # # ]: 0 : if (flow_dv_convert_action_modify_tp
15388 : : (mhdr_res, actions, items,
15389 : 0 : &flow_attr, dev_flow, !!(action_flags &
15390 : : MLX5_FLOW_ACTION_DECAP), error))
15391 : 0 : return -rte_errno;
15392 : 0 : action_flags |= actions->type ==
15393 : : RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
15394 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_TP_SRC :
15395 : : MLX5_FLOW_ACTION_SET_TP_DST;
15396 : 0 : break;
15397 : 0 : case RTE_FLOW_ACTION_TYPE_DEC_TTL:
15398 [ # # ]: 0 : if (flow_dv_convert_action_modify_dec_ttl
15399 : : (mhdr_res, items, &flow_attr, dev_flow,
15400 : 0 : !!(action_flags &
15401 : : MLX5_FLOW_ACTION_DECAP), error))
15402 : 0 : return -rte_errno;
15403 : 0 : action_flags |= MLX5_FLOW_ACTION_DEC_TTL;
15404 : 0 : break;
15405 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TTL:
15406 [ # # ]: 0 : if (flow_dv_convert_action_modify_ttl
15407 : : (mhdr_res, actions, items, &flow_attr,
15408 : 0 : dev_flow, !!(action_flags &
15409 : : MLX5_FLOW_ACTION_DECAP), error))
15410 : 0 : return -rte_errno;
15411 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TTL;
15412 : 0 : break;
15413 : 0 : case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
15414 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
15415 [ # # ]: 0 : if (flow_dv_convert_action_modify_tcp_seq
15416 : : (mhdr_res, actions, error))
15417 : 0 : return -rte_errno;
15418 : 0 : action_flags |= actions->type ==
15419 : : RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
15420 [ # # ]: 0 : MLX5_FLOW_ACTION_INC_TCP_SEQ :
15421 : : MLX5_FLOW_ACTION_DEC_TCP_SEQ;
15422 : 0 : break;
15423 : :
15424 : 0 : case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
15425 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
15426 [ # # ]: 0 : if (flow_dv_convert_action_modify_tcp_ack
15427 : : (mhdr_res, actions, error))
15428 : 0 : return -rte_errno;
15429 : 0 : action_flags |= actions->type ==
15430 : : RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
15431 [ # # ]: 0 : MLX5_FLOW_ACTION_INC_TCP_ACK :
15432 : : MLX5_FLOW_ACTION_DEC_TCP_ACK;
15433 : 0 : break;
15434 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
15435 [ # # ]: 0 : if (flow_dv_convert_action_set_reg
15436 : : (mhdr_res, actions, error))
15437 : 0 : return -rte_errno;
15438 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
15439 : 0 : break;
15440 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
15441 [ # # ]: 0 : if (flow_dv_convert_action_copy_mreg
15442 : : (dev, mhdr_res, actions, error))
15443 : 0 : return -rte_errno;
15444 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
15445 : 0 : break;
15446 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
15447 : 0 : action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
15448 : 0 : dev_flow->handle->fate_action =
15449 : : MLX5_FLOW_FATE_DEFAULT_MISS;
15450 : 0 : break;
15451 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
15452 [ # # ]: 0 : if (!wks->fm)
15453 : 0 : return rte_flow_error_set(error, rte_errno,
15454 : : RTE_FLOW_ERROR_TYPE_ACTION,
15455 : : NULL, "Failed to get meter in flow.");
15456 : : /* Set the meter action. */
15457 : 0 : dev_flow->dv.actions[actions_n++] =
15458 : 0 : wks->fm->meter_action_g;
15459 : 0 : action_flags |= MLX5_FLOW_ACTION_METER;
15460 : 0 : break;
15461 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
15462 [ # # ]: 0 : if (flow_dv_convert_action_modify_ipv4_dscp(mhdr_res,
15463 : : actions, error))
15464 : 0 : return -rte_errno;
15465 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
15466 : 0 : break;
15467 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
15468 [ # # ]: 0 : if (mlx5_dv_modify_ipv6_traffic_class_supported(priv))
15469 : : ipv6_tc_off = MLX5_IPV6_HDR_DSCP_SHIFT;
15470 : : else
15471 : : ipv6_tc_off = 0;
15472 [ # # ]: 0 : if (flow_dv_convert_action_modify_ipv6_dscp(mhdr_res,
15473 : : actions, ipv6_tc_off, error))
15474 : 0 : return -rte_errno;
15475 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
15476 : 0 : break;
15477 : 0 : case RTE_FLOW_ACTION_TYPE_SAMPLE:
15478 : 0 : sample_act_pos = actions_n;
15479 : 0 : sample = (const struct rte_flow_action_sample *)
15480 : : action->conf;
15481 : 0 : actions_n++;
15482 : 0 : action_flags |= MLX5_FLOW_ACTION_SAMPLE;
15483 : : /* put encap action into group if work with port id */
15484 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_ENCAP) &&
15485 : : (action_flags & MLX5_FLOW_ACTION_PORT_ID))
15486 : 0 : sample_act->action_flags |=
15487 : : MLX5_FLOW_ACTION_ENCAP;
15488 : : break;
15489 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
15490 [ # # ]: 0 : if (flow_dv_convert_action_modify_field
15491 : : (dev, mhdr_res, actions, attr, error))
15492 : 0 : return -rte_errno;
15493 : 0 : action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
15494 : 0 : break;
15495 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
15496 : 0 : owner_idx = (uint32_t)(uintptr_t)action->conf;
15497 : 0 : ct = flow_aso_ct_get_by_idx(dev, owner_idx);
15498 [ # # ]: 0 : if (!ct)
15499 : 0 : return rte_flow_error_set(error, EINVAL,
15500 : : RTE_FLOW_ERROR_TYPE_ACTION,
15501 : : NULL,
15502 : : "Failed to get CT object.");
15503 [ # # ]: 0 : if (mlx5_aso_ct_available(priv->sh, MLX5_HW_INV_QUEUE, ct))
15504 : 0 : return rte_flow_error_set(error, rte_errno,
15505 : : RTE_FLOW_ERROR_TYPE_ACTION,
15506 : : NULL,
15507 : : "CT is unavailable.");
15508 [ # # ]: 0 : if (ct->is_original)
15509 : 0 : dev_flow->dv.actions[actions_n] =
15510 : 0 : ct->dr_action_orig;
15511 : : else
15512 : 0 : dev_flow->dv.actions[actions_n] =
15513 : 0 : ct->dr_action_rply;
15514 [ # # ]: 0 : if (flow->ct == 0) {
15515 : 0 : flow->indirect_type =
15516 : : MLX5_INDIRECT_ACTION_TYPE_CT;
15517 : 0 : flow->ct = owner_idx;
15518 : 0 : rte_atomic_fetch_add_explicit(&ct->refcnt, 1,
15519 : : rte_memory_order_relaxed);
15520 : : }
15521 : 0 : actions_n++;
15522 : 0 : action_flags |= MLX5_FLOW_ACTION_CT;
15523 : 0 : break;
15524 : 0 : case RTE_FLOW_ACTION_TYPE_END:
15525 : : actions_end = true;
15526 [ # # ]: 0 : if (mhdr_res->actions_num) {
15527 : : /* create modify action if needed. */
15528 [ # # ]: 0 : if (flow_dv_modify_hdr_resource_register
15529 : : (dev, mhdr_res, dev_flow, error))
15530 : 0 : return -rte_errno;
15531 : 0 : dev_flow->dv.actions[modify_action_position] =
15532 : 0 : handle->dvh.modify_hdr->action;
15533 : : }
15534 : : /*
15535 : : * Handle AGE and COUNT action by single HW counter
15536 : : * when they are not shared.
15537 : : */
15538 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_AGE) {
15539 [ # # # # ]: 0 : if ((non_shared_age && count) ||
15540 [ # # ]: 0 : !flow_hit_aso_supported(priv, !dev_flow->dv.group)) {
15541 : : /* Creates age by counters. */
15542 : 0 : cnt_act = flow_dv_prepare_counter
15543 : : (dev, dev_flow,
15544 : : flow, count,
15545 : : non_shared_age,
15546 : : error);
15547 [ # # ]: 0 : if (!cnt_act)
15548 : 0 : return -rte_errno;
15549 : 0 : dev_flow->dv.actions[age_act_pos] =
15550 : 0 : cnt_act->action;
15551 : 0 : break;
15552 : : }
15553 [ # # # # ]: 0 : if (!flow->age && non_shared_age) {
15554 : 0 : flow->age = flow_dv_aso_age_alloc
15555 : : (dev, error);
15556 [ # # ]: 0 : if (!flow->age)
15557 : 0 : return -rte_errno;
15558 : 0 : flow_dv_aso_age_params_init
15559 : : (dev, flow->age,
15560 : 0 : non_shared_age->context ?
15561 : : non_shared_age->context :
15562 : 0 : (void *)(uintptr_t)
15563 : 0 : (dev_flow->flow_idx),
15564 [ # # ]: 0 : non_shared_age->timeout);
15565 : : }
15566 : 0 : age_act = flow_aso_age_get_by_idx(dev,
15567 : : flow->age);
15568 : 0 : dev_flow->dv.actions[age_act_pos] =
15569 : 0 : age_act->dr_action;
15570 : : }
15571 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_COUNT) {
15572 : : /*
15573 : : * Create one count action, to be used
15574 : : * by all sub-flows.
15575 : : */
15576 : 0 : cnt_act = flow_dv_prepare_counter(dev, dev_flow,
15577 : : flow, count,
15578 : : NULL, error);
15579 [ # # ]: 0 : if (!cnt_act)
15580 : 0 : return -rte_errno;
15581 : 0 : dev_flow->dv.actions[actions_n++] =
15582 : 0 : cnt_act->action;
15583 : : }
15584 : : default:
15585 : : break;
15586 : : }
15587 [ # # # # ]: 0 : if (mhdr_res->actions_num &&
15588 : : modify_action_position == UINT32_MAX)
15589 : 0 : modify_action_position = actions_n++;
15590 : : }
15591 : 0 : dev_flow->act_flags = action_flags;
15592 : 0 : ret = flow_dv_translate_items_sws(dev, dev_flow, attr, items, &matcher,
15593 : : error);
15594 [ # # ]: 0 : if (ret)
15595 : 0 : return -rte_errno;
15596 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_RSS) {
15597 : 0 : dev_flow->symmetric_hash_function = rss_desc->symmetric_hash_function;
15598 : 0 : flow_dv_hashfields_set(dev_flow->handle->layers,
15599 : : rss_desc,
15600 : : &dev_flow->hash_fields);
15601 : : }
15602 : : /* If has RSS action in the sample action, the Sample/Mirror resource
15603 : : * should be registered after the hash filed be update.
15604 : : */
15605 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE) {
15606 : 0 : ret = flow_dv_translate_action_sample(dev,
15607 : : sample,
15608 : : dev_flow, attr,
15609 : : &num_of_dest,
15610 : : sample_actions,
15611 : : &sample_res,
15612 : : error);
15613 [ # # ]: 0 : if (ret < 0)
15614 : : return ret;
15615 : 0 : ret = flow_dv_create_action_sample(dev,
15616 : : dev_flow,
15617 : : num_of_dest,
15618 : : &sample_res,
15619 : : &mdest_res,
15620 : : sample_actions,
15621 : : action_flags,
15622 : : error);
15623 [ # # ]: 0 : if (ret < 0)
15624 : 0 : return rte_flow_error_set
15625 : : (error, rte_errno,
15626 : : RTE_FLOW_ERROR_TYPE_ACTION,
15627 : : NULL,
15628 : : "cannot create sample action");
15629 [ # # ]: 0 : if (num_of_dest > 1) {
15630 : 0 : dev_flow->dv.actions[sample_act_pos] =
15631 : 0 : dev_flow->dv.dest_array_res->action;
15632 : : } else {
15633 : 0 : dev_flow->dv.actions[sample_act_pos] =
15634 : 0 : dev_flow->dv.sample_res->verbs_action;
15635 : : }
15636 : : }
15637 : : /*
15638 : : * For multiple destination (sample action with ratio=1), the encap
15639 : : * action and port id action will be combined into group action.
15640 : : * So need remove the original these actions in the flow and only
15641 : : * use the sample action instead of.
15642 : : */
15643 [ # # ]: 0 : if (num_of_dest > 1 &&
15644 [ # # # # ]: 0 : (sample_act->dr_port_id_action || sample_act->dr_jump_action)) {
15645 : : int i;
15646 : 0 : void *temp_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
15647 : :
15648 [ # # ]: 0 : for (i = 0; i < actions_n; i++) {
15649 [ # # ]: 0 : if ((sample_act->dr_encap_action &&
15650 : : sample_act->dr_encap_action ==
15651 [ # # # # ]: 0 : dev_flow->dv.actions[i]) ||
15652 : 0 : (sample_act->dr_port_id_action &&
15653 : : sample_act->dr_port_id_action ==
15654 [ # # ]: 0 : dev_flow->dv.actions[i]) ||
15655 [ # # ]: 0 : (sample_act->dr_jump_action &&
15656 : : sample_act->dr_jump_action ==
15657 [ # # ]: 0 : dev_flow->dv.actions[i]))
15658 : 0 : continue;
15659 : 0 : temp_actions[tmp_actions_n++] = dev_flow->dv.actions[i];
15660 : : }
15661 : 0 : memcpy((void *)dev_flow->dv.actions,
15662 : : (void *)temp_actions,
15663 : : tmp_actions_n * sizeof(void *));
15664 : : actions_n = tmp_actions_n;
15665 : : }
15666 : 0 : dev_flow->dv.actions_n = actions_n;
15667 [ # # ]: 0 : if (wks->skip_matcher_reg)
15668 : : return 0;
15669 : : /* Register matcher. */
15670 : 0 : matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
15671 : : matcher.mask.size);
15672 : 0 : matcher.priority = mlx5_get_matcher_priority(dev, attr,
15673 : 0 : matcher.priority,
15674 : 0 : dev_flow->external);
15675 : : /**
15676 : : * When creating meter drop flow in drop table, using original
15677 : : * 5-tuple match, the matcher priority should be lower than
15678 : : * mtr_id matcher.
15679 : : */
15680 [ # # ]: 0 : if (attr->group == MLX5_FLOW_TABLE_LEVEL_METER &&
15681 [ # # # # ]: 0 : dev_flow->dv.table_id == MLX5_MTR_TABLE_ID_DROP &&
15682 : : matcher.priority <= MLX5_REG_BITS)
15683 : 0 : matcher.priority += MLX5_REG_BITS;
15684 : : /* reserved field no needs to be set to 0 here. */
15685 : 0 : tbl_key.is_fdb = attr->transfer;
15686 : 0 : tbl_key.is_egress = attr->egress;
15687 : 0 : tbl_key.level = dev_flow->dv.group;
15688 : 0 : tbl_key.id = dev_flow->dv.table_id;
15689 [ # # ]: 0 : if (flow_dv_matcher_register(dev, &matcher, &tbl_key, dev_flow,
15690 : : tunnel, attr->group, error))
15691 : 0 : return -rte_errno;
15692 : : return 0;
15693 : : }
15694 : :
15695 : : /**
15696 : : * Set hash RX queue by hash fields (see enum ibv_rx_hash_fields)
15697 : : * and tunnel.
15698 : : *
15699 : : * @param[in, out] action
15700 : : * Shred RSS action holding hash RX queue objects.
15701 : : * @param[in] hash_fields
15702 : : * Defines combination of packet fields to participate in RX hash.
15703 : : * @param[in] tunnel
15704 : : * Tunnel type
15705 : : * @param[in] hrxq_idx
15706 : : * Hash RX queue index to set.
15707 : : *
15708 : : * @return
15709 : : * 0 on success, otherwise negative errno value.
15710 : : */
15711 : : static int
15712 : 0 : __flow_dv_action_rss_hrxq_set(struct mlx5_shared_action_rss *action,
15713 : : const uint64_t hash_fields,
15714 : : uint32_t hrxq_idx)
15715 : : {
15716 : : uint32_t *hrxqs = action->hrxq;
15717 : :
15718 [ # # # # : 0 : switch (hash_fields & ~IBV_RX_HASH_INNER) {
# # # # #
# # ]
15719 : 0 : case MLX5_RSS_HASH_IPV4:
15720 : : /* fall-through. */
15721 : : case MLX5_RSS_HASH_IPV4_DST_ONLY:
15722 : : /* fall-through. */
15723 : : case MLX5_RSS_HASH_IPV4_SRC_ONLY:
15724 : 0 : hrxqs[0] = hrxq_idx;
15725 : 0 : return 0;
15726 : 0 : case MLX5_RSS_HASH_IPV4_TCP:
15727 : : /* fall-through. */
15728 : : case MLX5_RSS_HASH_IPV4_TCP_DST_ONLY:
15729 : : /* fall-through. */
15730 : : case MLX5_RSS_HASH_IPV4_TCP_SRC_ONLY:
15731 : 0 : hrxqs[1] = hrxq_idx;
15732 : 0 : return 0;
15733 : 0 : case MLX5_RSS_HASH_IPV4_UDP:
15734 : : /* fall-through. */
15735 : : case MLX5_RSS_HASH_IPV4_UDP_DST_ONLY:
15736 : : /* fall-through. */
15737 : : case MLX5_RSS_HASH_IPV4_UDP_SRC_ONLY:
15738 : 0 : hrxqs[2] = hrxq_idx;
15739 : 0 : return 0;
15740 : 0 : case MLX5_RSS_HASH_IPV6:
15741 : : /* fall-through. */
15742 : : case MLX5_RSS_HASH_IPV6_DST_ONLY:
15743 : : /* fall-through. */
15744 : : case MLX5_RSS_HASH_IPV6_SRC_ONLY:
15745 : 0 : hrxqs[3] = hrxq_idx;
15746 : 0 : return 0;
15747 : 0 : case MLX5_RSS_HASH_IPV6_TCP:
15748 : : /* fall-through. */
15749 : : case MLX5_RSS_HASH_IPV6_TCP_DST_ONLY:
15750 : : /* fall-through. */
15751 : : case MLX5_RSS_HASH_IPV6_TCP_SRC_ONLY:
15752 : 0 : hrxqs[4] = hrxq_idx;
15753 : 0 : return 0;
15754 : 0 : case MLX5_RSS_HASH_IPV6_UDP:
15755 : : /* fall-through. */
15756 : : case MLX5_RSS_HASH_IPV6_UDP_DST_ONLY:
15757 : : /* fall-through. */
15758 : : case MLX5_RSS_HASH_IPV6_UDP_SRC_ONLY:
15759 : 0 : hrxqs[5] = hrxq_idx;
15760 : 0 : return 0;
15761 : 0 : case MLX5_RSS_HASH_NONE:
15762 : 0 : hrxqs[6] = hrxq_idx;
15763 : 0 : return 0;
15764 : 0 : case MLX5_RSS_HASH_IPV4_ESP:
15765 : 0 : hrxqs[7] = hrxq_idx;
15766 : 0 : return 0;
15767 : 0 : case MLX5_RSS_HASH_IPV6_ESP:
15768 : 0 : hrxqs[8] = hrxq_idx;
15769 : 0 : return 0;
15770 : 0 : case MLX5_RSS_HASH_ESP_SPI:
15771 : 0 : hrxqs[9] = hrxq_idx;
15772 : 0 : return 0;
15773 : : default:
15774 : : return -1;
15775 : : }
15776 : : }
15777 : :
15778 : : /**
15779 : : * Look up for hash RX queue by hash fields (see enum ibv_rx_hash_fields)
15780 : : * and tunnel.
15781 : : *
15782 : : * @param[in] dev
15783 : : * Pointer to the Ethernet device structure.
15784 : : * @param[in] idx
15785 : : * Shared RSS action ID holding hash RX queue objects.
15786 : : * @param[in] hash_fields
15787 : : * Defines combination of packet fields to participate in RX hash.
15788 : : * @param[in] tunnel
15789 : : * Tunnel type
15790 : : *
15791 : : * @return
15792 : : * Valid hash RX queue index, otherwise 0.
15793 : : */
15794 : : uint32_t
15795 : 0 : flow_dv_action_rss_hrxq_lookup(struct rte_eth_dev *dev, uint32_t idx,
15796 : : const uint64_t hash_fields)
15797 : : {
15798 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15799 : : struct mlx5_shared_action_rss *shared_rss =
15800 : 0 : mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
15801 : : const uint32_t *hrxqs = shared_rss->hrxq;
15802 : :
15803 [ # # # # : 0 : switch (hash_fields & ~IBV_RX_HASH_INNER) {
# # # # #
# # ]
15804 : 0 : case MLX5_RSS_HASH_IPV4:
15805 : : /* fall-through. */
15806 : : case MLX5_RSS_HASH_IPV4_DST_ONLY:
15807 : : /* fall-through. */
15808 : : case MLX5_RSS_HASH_IPV4_SRC_ONLY:
15809 : 0 : return hrxqs[0];
15810 : 0 : case MLX5_RSS_HASH_IPV4_TCP:
15811 : : /* fall-through. */
15812 : : case MLX5_RSS_HASH_IPV4_TCP_DST_ONLY:
15813 : : /* fall-through. */
15814 : : case MLX5_RSS_HASH_IPV4_TCP_SRC_ONLY:
15815 : 0 : return hrxqs[1];
15816 : 0 : case MLX5_RSS_HASH_IPV4_UDP:
15817 : : /* fall-through. */
15818 : : case MLX5_RSS_HASH_IPV4_UDP_DST_ONLY:
15819 : : /* fall-through. */
15820 : : case MLX5_RSS_HASH_IPV4_UDP_SRC_ONLY:
15821 : 0 : return hrxqs[2];
15822 : 0 : case MLX5_RSS_HASH_IPV6:
15823 : : /* fall-through. */
15824 : : case MLX5_RSS_HASH_IPV6_DST_ONLY:
15825 : : /* fall-through. */
15826 : : case MLX5_RSS_HASH_IPV6_SRC_ONLY:
15827 : 0 : return hrxqs[3];
15828 : 0 : case MLX5_RSS_HASH_IPV6_TCP:
15829 : : /* fall-through. */
15830 : : case MLX5_RSS_HASH_IPV6_TCP_DST_ONLY:
15831 : : /* fall-through. */
15832 : : case MLX5_RSS_HASH_IPV6_TCP_SRC_ONLY:
15833 : 0 : return hrxqs[4];
15834 : 0 : case MLX5_RSS_HASH_IPV6_UDP:
15835 : : /* fall-through. */
15836 : : case MLX5_RSS_HASH_IPV6_UDP_DST_ONLY:
15837 : : /* fall-through. */
15838 : : case MLX5_RSS_HASH_IPV6_UDP_SRC_ONLY:
15839 : 0 : return hrxqs[5];
15840 : 0 : case MLX5_RSS_HASH_NONE:
15841 : 0 : return hrxqs[6];
15842 : 0 : case MLX5_RSS_HASH_IPV4_ESP:
15843 : 0 : return hrxqs[7];
15844 : 0 : case MLX5_RSS_HASH_IPV6_ESP:
15845 : 0 : return hrxqs[8];
15846 : 0 : case MLX5_RSS_HASH_ESP_SPI:
15847 : 0 : return hrxqs[9];
15848 : : default:
15849 : : return 0;
15850 : : }
15851 : :
15852 : : }
15853 : :
15854 : : /**
15855 : : * Apply the flow to the NIC, lock free,
15856 : : * (mutex should be acquired by caller).
15857 : : *
15858 : : * @param[in] dev
15859 : : * Pointer to the Ethernet device structure.
15860 : : * @param[in, out] flow
15861 : : * Pointer to flow structure.
15862 : : * @param[out] error
15863 : : * Pointer to error structure.
15864 : : *
15865 : : * @return
15866 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
15867 : : */
15868 : : static int
15869 : 0 : flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
15870 : : struct rte_flow_error *error)
15871 : : {
15872 : : struct mlx5_flow_dv_workspace *dv;
15873 : : struct mlx5_flow_handle *dh;
15874 : : struct mlx5_flow_handle_dv *dv_h;
15875 : : struct mlx5_flow *dev_flow;
15876 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15877 : : uint32_t handle_idx;
15878 : : int n;
15879 : : int err;
15880 : : int idx;
15881 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
15882 : 0 : struct mlx5_flow_rss_desc *rss_desc = &wks->rss_desc;
15883 : : uint8_t misc_mask;
15884 : :
15885 : : MLX5_ASSERT(wks);
15886 [ # # ]: 0 : for (idx = wks->flow_idx - 1; idx >= 0; idx--) {
15887 : 0 : dev_flow = &wks->flows[idx];
15888 : : dv = &dev_flow->dv;
15889 : 0 : dh = dev_flow->handle;
15890 : : dv_h = &dh->dvh;
15891 : 0 : n = dv->actions_n;
15892 [ # # ]: 0 : if (dh->fate_action == MLX5_FLOW_FATE_DROP) {
15893 [ # # ]: 0 : if (dv->transfer) {
15894 : : MLX5_ASSERT(priv->sh->dr_drop_action);
15895 : 0 : dv->actions[n++] = priv->sh->dr_drop_action;
15896 : : } else {
15897 : : #ifdef HAVE_MLX5DV_DR
15898 : : /* DR supports drop action placeholder. */
15899 : : MLX5_ASSERT(priv->sh->dr_drop_action);
15900 : 0 : dv->actions[n++] = dv->group ?
15901 [ # # ]: 0 : priv->sh->dr_drop_action :
15902 : : priv->root_drop_action;
15903 : : #else
15904 : : /* For DV we use the explicit drop queue. */
15905 : : MLX5_ASSERT(priv->drop_queue.hrxq);
15906 : : dv->actions[n++] =
15907 : : priv->drop_queue.hrxq->action;
15908 : : #endif
15909 : : }
15910 [ # # ]: 0 : } else if ((dh->fate_action == MLX5_FLOW_FATE_QUEUE &&
15911 [ # # # # ]: 0 : !dv_h->rix_sample && !dv_h->rix_dest_array)) {
15912 : : struct mlx5_hrxq *hrxq;
15913 : : uint32_t hrxq_idx;
15914 : :
15915 : 0 : hrxq = flow_dv_hrxq_prepare(dev, dev_flow, rss_desc,
15916 : : &hrxq_idx);
15917 [ # # ]: 0 : if (!hrxq) {
15918 : 0 : rte_flow_error_set
15919 : : (error, rte_errno,
15920 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
15921 : : "cannot get hash queue");
15922 : 0 : goto error;
15923 : : }
15924 : 0 : dh->rix_hrxq = hrxq_idx;
15925 : 0 : dv->actions[n++] = hrxq->action;
15926 [ # # ]: 0 : } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
15927 : : struct mlx5_hrxq *hrxq = NULL;
15928 : : uint32_t hrxq_idx;
15929 : :
15930 : 0 : hrxq_idx = flow_dv_action_rss_hrxq_lookup(dev,
15931 : : rss_desc->shared_rss,
15932 : : dev_flow->hash_fields);
15933 [ # # ]: 0 : if (hrxq_idx)
15934 : 0 : hrxq = mlx5_ipool_get
15935 : 0 : (priv->sh->ipool[MLX5_IPOOL_HRXQ],
15936 : : hrxq_idx);
15937 [ # # ]: 0 : if (!hrxq) {
15938 : 0 : rte_flow_error_set
15939 : : (error, rte_errno,
15940 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
15941 : : "cannot get hash queue");
15942 : 0 : goto error;
15943 : : }
15944 : 0 : dh->rix_srss = rss_desc->shared_rss;
15945 : 0 : dv->actions[n++] = hrxq->action;
15946 [ # # ]: 0 : } else if (dh->fate_action == MLX5_FLOW_FATE_DEFAULT_MISS) {
15947 [ # # ]: 0 : if (!priv->sh->default_miss_action) {
15948 : 0 : rte_flow_error_set
15949 : : (error, rte_errno,
15950 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
15951 : : "default miss action not be created.");
15952 : 0 : goto error;
15953 : : }
15954 : 0 : dv->actions[n++] = priv->sh->default_miss_action;
15955 : : }
15956 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(dv_h->matcher->mask.buf);
15957 : : __flow_dv_adjust_buf_size(&dv->value.size, misc_mask);
15958 : 0 : err = mlx5_flow_os_create_flow(dv_h->matcher->matcher_object,
15959 : 0 : (void *)&dv->value, n,
15960 : 0 : dv->actions, &dh->drv_flow);
15961 : : if (err) {
15962 : 0 : rte_flow_error_set
15963 : 0 : (error, errno,
15964 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15965 : : NULL,
15966 [ # # ]: 0 : (!priv->sh->config.allow_duplicate_pattern &&
15967 [ # # ]: 0 : errno == EEXIST) ?
15968 : : "duplicating pattern is not allowed" :
15969 : : "hardware refuses to create flow");
15970 : 0 : goto error;
15971 : : }
15972 [ # # ]: 0 : if (priv->vmwa_context &&
15973 [ # # # # ]: 0 : dh->vf_vlan.tag && !dh->vf_vlan.created) {
15974 : : /*
15975 : : * The rule contains the VLAN pattern.
15976 : : * For VF we are going to create VLAN
15977 : : * interface to make hypervisor set correct
15978 : : * e-Switch vport context.
15979 : : */
15980 : 0 : mlx5_vlan_vmwa_acquire(dev, &dh->vf_vlan);
15981 : : }
15982 : : }
15983 : : return 0;
15984 : 0 : error:
15985 : 0 : err = rte_errno; /* Save rte_errno before cleanup. */
15986 [ # # # # : 0 : SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
# # ]
15987 : : handle_idx, dh, next) {
15988 : : /* hrxq is union, don't clear it if the flag is not set. */
15989 [ # # # # ]: 0 : if (dh->fate_action == MLX5_FLOW_FATE_QUEUE && dh->rix_hrxq &&
15990 [ # # # # ]: 0 : !dh->dvh.rix_sample && !dh->dvh.rix_dest_array) {
15991 : 0 : mlx5_hrxq_release(dev, dh->rix_hrxq);
15992 : 0 : dh->rix_hrxq = 0;
15993 [ # # ]: 0 : } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
15994 : 0 : dh->rix_srss = 0;
15995 : : }
15996 [ # # # # ]: 0 : if (dh->vf_vlan.tag && dh->vf_vlan.created)
15997 : 0 : mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
15998 : : }
15999 : 0 : rte_errno = err; /* Restore rte_errno. */
16000 : 0 : return -rte_errno;
16001 : : }
16002 : :
16003 : : void
16004 : 0 : flow_matcher_remove_cb(void *tool_ctx __rte_unused,
16005 : : struct mlx5_list_entry *entry)
16006 : : {
16007 : : struct mlx5_flow_dv_matcher *resource = container_of(entry,
16008 : : typeof(*resource),
16009 : : entry);
16010 : : #ifdef HAVE_MLX5_HWS_SUPPORT
16011 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
16012 : :
16013 [ # # ]: 0 : if (sh->config.dv_flow_en == 2)
16014 : 0 : claim_zero(mlx5dr_bwc_matcher_destroy((struct mlx5dr_bwc_matcher *)
16015 : : resource->matcher_object));
16016 : : else
16017 : : #endif
16018 : 0 : claim_zero(mlx5_flow_os_destroy_flow_matcher(resource->matcher_object));
16019 : 0 : mlx5_free(resource);
16020 : 0 : }
16021 : :
16022 : : /**
16023 : : * Release the flow matcher.
16024 : : *
16025 : : * @param dev
16026 : : * Pointer to Ethernet device.
16027 : : * @param port_id
16028 : : * Index to port ID action resource.
16029 : : *
16030 : : * @return
16031 : : * 1 while a reference on it exists, 0 when freed.
16032 : : */
16033 : : static int
16034 : 0 : flow_dv_matcher_release(struct rte_eth_dev *dev,
16035 : : struct mlx5_flow_handle *handle)
16036 : : {
16037 : 0 : struct mlx5_flow_dv_matcher *matcher = handle->dvh.matcher;
16038 : 0 : struct mlx5_flow_tbl_data_entry *tbl = container_of(matcher->tbl,
16039 : : typeof(*tbl), tbl);
16040 : : int ret;
16041 : :
16042 : : MLX5_ASSERT(matcher->matcher_object);
16043 : 0 : ret = mlx5_list_unregister(tbl->matchers, &matcher->entry);
16044 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl->tbl);
16045 : 0 : return ret;
16046 : : }
16047 : :
16048 : : void
16049 : 0 : flow_encap_decap_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
16050 : : {
16051 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
16052 : : struct mlx5_flow_dv_encap_decap_resource *res =
16053 : : container_of(entry, typeof(*res), entry);
16054 : :
16055 : : #ifdef HAVE_MLX5_HWS_SUPPORT
16056 [ # # ]: 0 : if (sh->config.dv_flow_en == 2)
16057 : 0 : claim_zero(mlx5dr_action_destroy(res->action));
16058 : : else
16059 : : #endif
16060 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
16061 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], res->idx);
16062 : 0 : }
16063 : :
16064 : : /**
16065 : : * Release an encap/decap resource.
16066 : : *
16067 : : * @param dev
16068 : : * Pointer to Ethernet device.
16069 : : * @param encap_decap_idx
16070 : : * Index of encap decap resource.
16071 : : *
16072 : : * @return
16073 : : * 1 while a reference on it exists, 0 when freed.
16074 : : */
16075 : : int
16076 : 0 : flow_encap_decap_resource_release(struct rte_eth_dev *dev,
16077 : : uint32_t encap_decap_idx)
16078 : : {
16079 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16080 : : struct mlx5_flow_dv_encap_decap_resource *resource;
16081 : :
16082 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
16083 : : encap_decap_idx);
16084 [ # # ]: 0 : if (!resource)
16085 : : return 0;
16086 : : MLX5_ASSERT(resource->action);
16087 : 0 : return mlx5_hlist_unregister(priv->sh->encaps_decaps, &resource->entry);
16088 : : }
16089 : :
16090 : : /**
16091 : : * Release an jump to table action resource.
16092 : : *
16093 : : * @param dev
16094 : : * Pointer to Ethernet device.
16095 : : * @param rix_jump
16096 : : * Index to the jump action resource.
16097 : : *
16098 : : * @return
16099 : : * 1 while a reference on it exists, 0 when freed.
16100 : : */
16101 : : static int
16102 : 0 : flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev,
16103 : : uint32_t rix_jump)
16104 : : {
16105 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16106 : : struct mlx5_flow_tbl_data_entry *tbl_data;
16107 : :
16108 : 0 : tbl_data = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_JUMP],
16109 : : rix_jump);
16110 [ # # ]: 0 : if (!tbl_data)
16111 : : return 0;
16112 : 0 : return flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl_data->tbl);
16113 : : }
16114 : :
16115 : : void
16116 : 0 : flow_modify_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
16117 : : {
16118 : : struct mlx5_flow_dv_modify_hdr_resource *res =
16119 : : container_of(entry, typeof(*res), entry);
16120 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
16121 : :
16122 : : #ifdef HAVE_MLX5_HWS_SUPPORT
16123 [ # # ]: 0 : if (sh->config.dv_flow_en == 2)
16124 : 0 : claim_zero(mlx5dr_action_destroy(res->action));
16125 : : else
16126 : : #endif
16127 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
16128 : 0 : mlx5_ipool_free(sh->mdh_ipools[res->actions_num - 1], res->idx);
16129 : 0 : }
16130 : :
16131 : : /**
16132 : : * Release a modify-header resource.
16133 : : *
16134 : : * @param dev
16135 : : * Pointer to Ethernet device.
16136 : : * @param handle
16137 : : * Pointer to mlx5_flow_handle.
16138 : : *
16139 : : * @return
16140 : : * 1 while a reference on it exists, 0 when freed.
16141 : : */
16142 : : static int
16143 : : flow_dv_modify_hdr_resource_release(struct rte_eth_dev *dev,
16144 : : struct mlx5_flow_handle *handle)
16145 : : {
16146 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16147 : : struct mlx5_flow_dv_modify_hdr_resource *entry = handle->dvh.modify_hdr;
16148 : :
16149 : : MLX5_ASSERT(entry->action);
16150 : 0 : return mlx5_hlist_unregister(priv->sh->modify_cmds, &entry->entry);
16151 : : }
16152 : :
16153 : : void
16154 : 0 : flow_dv_port_id_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
16155 : : {
16156 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
16157 : : struct mlx5_flow_dv_port_id_action_resource *resource =
16158 : : container_of(entry, typeof(*resource), entry);
16159 : :
16160 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
16161 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], resource->idx);
16162 : 0 : }
16163 : :
16164 : : /**
16165 : : * Release port ID action resource.
16166 : : *
16167 : : * @param dev
16168 : : * Pointer to Ethernet device.
16169 : : * @param handle
16170 : : * Pointer to mlx5_flow_handle.
16171 : : *
16172 : : * @return
16173 : : * 1 while a reference on it exists, 0 when freed.
16174 : : */
16175 : : static int
16176 : 0 : flow_dv_port_id_action_resource_release(struct rte_eth_dev *dev,
16177 : : uint32_t port_id)
16178 : : {
16179 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16180 : : struct mlx5_flow_dv_port_id_action_resource *resource;
16181 : :
16182 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PORT_ID], port_id);
16183 [ # # ]: 0 : if (!resource)
16184 : : return 0;
16185 : : MLX5_ASSERT(resource->action);
16186 : 0 : return mlx5_list_unregister(priv->sh->port_id_action_list,
16187 : : &resource->entry);
16188 : : }
16189 : :
16190 : : /**
16191 : : * Release shared RSS action resource.
16192 : : *
16193 : : * @param dev
16194 : : * Pointer to Ethernet device.
16195 : : * @param srss
16196 : : * Shared RSS action index.
16197 : : */
16198 : : static void
16199 : 0 : flow_dv_shared_rss_action_release(struct rte_eth_dev *dev, uint32_t srss)
16200 : : {
16201 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16202 : : struct mlx5_shared_action_rss *shared_rss;
16203 : :
16204 : 0 : shared_rss = mlx5_ipool_get
16205 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], srss);
16206 : 0 : rte_atomic_fetch_sub_explicit(&shared_rss->refcnt, 1, rte_memory_order_relaxed);
16207 : 0 : }
16208 : :
16209 : : void
16210 : 0 : flow_dv_push_vlan_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
16211 : : {
16212 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
16213 : : struct mlx5_flow_dv_push_vlan_action_resource *resource =
16214 : : container_of(entry, typeof(*resource), entry);
16215 : :
16216 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
16217 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], resource->idx);
16218 : 0 : }
16219 : :
16220 : : /**
16221 : : * Release push vlan action resource.
16222 : : *
16223 : : * @param dev
16224 : : * Pointer to Ethernet device.
16225 : : * @param handle
16226 : : * Pointer to mlx5_flow_handle.
16227 : : *
16228 : : * @return
16229 : : * 1 while a reference on it exists, 0 when freed.
16230 : : */
16231 : : static int
16232 : 0 : flow_dv_push_vlan_action_resource_release(struct rte_eth_dev *dev,
16233 : : struct mlx5_flow_handle *handle)
16234 : : {
16235 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16236 : : struct mlx5_flow_dv_push_vlan_action_resource *resource;
16237 : 0 : uint32_t idx = handle->dvh.rix_push_vlan;
16238 : :
16239 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
16240 [ # # ]: 0 : if (!resource)
16241 : : return 0;
16242 : : MLX5_ASSERT(resource->action);
16243 : 0 : return mlx5_list_unregister(priv->sh->push_vlan_action_list,
16244 : : &resource->entry);
16245 : : }
16246 : :
16247 : : /**
16248 : : * Release the fate resource.
16249 : : *
16250 : : * @param dev
16251 : : * Pointer to Ethernet device.
16252 : : * @param handle
16253 : : * Pointer to mlx5_flow_handle.
16254 : : */
16255 : : static void
16256 : 0 : flow_dv_fate_resource_release(struct rte_eth_dev *dev,
16257 : : struct mlx5_flow_handle *handle)
16258 : : {
16259 [ # # ]: 0 : if (!handle->rix_fate)
16260 : : return;
16261 [ # # # # : 0 : switch (handle->fate_action) {
# ]
16262 : 0 : case MLX5_FLOW_FATE_QUEUE:
16263 [ # # # # ]: 0 : if (!handle->dvh.rix_sample && !handle->dvh.rix_dest_array)
16264 : 0 : mlx5_hrxq_release(dev, handle->rix_hrxq);
16265 : : break;
16266 : 0 : case MLX5_FLOW_FATE_JUMP:
16267 : 0 : flow_dv_jump_tbl_resource_release(dev, handle->rix_jump);
16268 : 0 : break;
16269 : 0 : case MLX5_FLOW_FATE_PORT_ID:
16270 : 0 : flow_dv_port_id_action_resource_release(dev,
16271 : : handle->rix_port_id_action);
16272 : 0 : break;
16273 : : case MLX5_FLOW_FATE_SEND_TO_KERNEL:
16274 : : /* In case of send_to_kernel action the actual release of
16275 : : * resource is done when all shared DR resources are released
16276 : : * since this resource is created once and always reused.
16277 : : */
16278 : : break;
16279 : 0 : default:
16280 : 0 : DRV_LOG(DEBUG, "Incorrect fate action:%d", handle->fate_action);
16281 : 0 : break;
16282 : : }
16283 : 0 : handle->rix_fate = 0;
16284 : : }
16285 : :
16286 : : void
16287 : 0 : flow_dv_sample_remove_cb(void *tool_ctx __rte_unused,
16288 : : struct mlx5_list_entry *entry)
16289 : : {
16290 : : struct mlx5_flow_dv_sample_resource *resource = container_of(entry,
16291 : : typeof(*resource),
16292 : : entry);
16293 : 0 : struct rte_eth_dev *dev = resource->dev;
16294 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16295 : :
16296 [ # # ]: 0 : if (resource->verbs_action)
16297 : : claim_zero(mlx5_flow_os_destroy_flow_action
16298 : : (resource->verbs_action));
16299 [ # # ]: 0 : if (resource->normal_path_tbl)
16300 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev),
16301 : : resource->normal_path_tbl);
16302 : 0 : flow_dv_sample_sub_actions_release(dev, &resource->sample_idx);
16303 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_SAMPLE], resource->idx);
16304 : 0 : DRV_LOG(DEBUG, "sample resource %p: removed", (void *)resource);
16305 : 0 : }
16306 : :
16307 : : /**
16308 : : * Release an sample resource.
16309 : : *
16310 : : * @param dev
16311 : : * Pointer to Ethernet device.
16312 : : * @param handle
16313 : : * Pointer to mlx5_flow_handle.
16314 : : *
16315 : : * @return
16316 : : * 1 while a reference on it exists, 0 when freed.
16317 : : */
16318 : : static int
16319 : 0 : flow_dv_sample_resource_release(struct rte_eth_dev *dev,
16320 : : struct mlx5_flow_handle *handle)
16321 : : {
16322 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16323 : : struct mlx5_flow_dv_sample_resource *resource;
16324 : :
16325 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_SAMPLE],
16326 : : handle->dvh.rix_sample);
16327 [ # # ]: 0 : if (!resource)
16328 : : return 0;
16329 : : MLX5_ASSERT(resource->verbs_action);
16330 : 0 : return mlx5_list_unregister(priv->sh->sample_action_list,
16331 : : &resource->entry);
16332 : : }
16333 : :
16334 : : void
16335 : 0 : flow_dv_dest_array_remove_cb(void *tool_ctx __rte_unused,
16336 : : struct mlx5_list_entry *entry)
16337 : : {
16338 : : struct mlx5_flow_dv_dest_array_resource *resource =
16339 : : container_of(entry, typeof(*resource), entry);
16340 : 0 : struct rte_eth_dev *dev = resource->dev;
16341 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16342 : : uint32_t i = 0;
16343 : :
16344 : : MLX5_ASSERT(resource->action);
16345 [ # # ]: 0 : if (resource->action)
16346 : : claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
16347 [ # # ]: 0 : for (; i < resource->num_of_dest; i++)
16348 : 0 : flow_dv_sample_sub_actions_release(dev,
16349 : : &resource->sample_idx[i]);
16350 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY], resource->idx);
16351 : 0 : DRV_LOG(DEBUG, "destination array resource %p: removed",
16352 : : (void *)resource);
16353 : 0 : }
16354 : :
16355 : : /**
16356 : : * Release an destination array resource.
16357 : : *
16358 : : * @param dev
16359 : : * Pointer to Ethernet device.
16360 : : * @param handle
16361 : : * Pointer to mlx5_flow_handle.
16362 : : *
16363 : : * @return
16364 : : * 1 while a reference on it exists, 0 when freed.
16365 : : */
16366 : : static int
16367 : 0 : flow_dv_dest_array_resource_release(struct rte_eth_dev *dev,
16368 : : struct mlx5_flow_handle *handle)
16369 : : {
16370 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16371 : : struct mlx5_flow_dv_dest_array_resource *resource;
16372 : :
16373 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY],
16374 : : handle->dvh.rix_dest_array);
16375 [ # # ]: 0 : if (!resource)
16376 : : return 0;
16377 : : MLX5_ASSERT(resource->action);
16378 : 0 : return mlx5_list_unregister(priv->sh->dest_array_list,
16379 : : &resource->entry);
16380 : : }
16381 : :
16382 : : static void
16383 : 0 : flow_dev_geneve_tlv_option_resource_release(struct mlx5_dev_ctx_shared *sh)
16384 : : {
16385 : 0 : struct mlx5_geneve_tlv_option_resource *geneve_opt_resource =
16386 : : sh->geneve_tlv_option_resource;
16387 : 0 : rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
16388 [ # # ]: 0 : if (geneve_opt_resource) {
16389 [ # # ]: 0 : if (!(rte_atomic_fetch_sub_explicit(&geneve_opt_resource->refcnt, 1,
16390 : : rte_memory_order_relaxed) - 1)) {
16391 : 0 : claim_zero(mlx5_devx_cmd_destroy
16392 : : (geneve_opt_resource->obj));
16393 : 0 : mlx5_free(sh->geneve_tlv_option_resource);
16394 : 0 : sh->geneve_tlv_option_resource = NULL;
16395 : : }
16396 : : }
16397 : : rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
16398 : 0 : }
16399 : :
16400 : : /**
16401 : : * Remove the flow from the NIC but keeps it in memory.
16402 : : * Lock free, (mutex should be acquired by caller).
16403 : : *
16404 : : * @param[in] dev
16405 : : * Pointer to Ethernet device.
16406 : : * @param[in, out] flow
16407 : : * Pointer to flow structure.
16408 : : */
16409 : : static void
16410 : 0 : flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
16411 : : {
16412 : : struct mlx5_flow_handle *dh;
16413 : : uint32_t handle_idx;
16414 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16415 : :
16416 [ # # ]: 0 : if (!flow)
16417 : : return;
16418 : 0 : handle_idx = flow->dev_handles;
16419 [ # # ]: 0 : while (handle_idx) {
16420 : 0 : dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
16421 : : handle_idx);
16422 [ # # ]: 0 : if (!dh)
16423 : : return;
16424 [ # # ]: 0 : if (dh->drv_flow) {
16425 : : claim_zero(mlx5_flow_os_destroy_flow(dh->drv_flow));
16426 : 0 : dh->drv_flow = NULL;
16427 : : }
16428 [ # # ]: 0 : if (dh->fate_action == MLX5_FLOW_FATE_QUEUE)
16429 : 0 : flow_dv_fate_resource_release(dev, dh);
16430 [ # # # # ]: 0 : if (dh->vf_vlan.tag && dh->vf_vlan.created)
16431 : 0 : mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
16432 : 0 : handle_idx = dh->next.next;
16433 : : }
16434 : : }
16435 : :
16436 : : /**
16437 : : * Remove the flow from the NIC and the memory.
16438 : : * Lock free, (mutex should be acquired by caller).
16439 : : *
16440 : : * @param[in] dev
16441 : : * Pointer to the Ethernet device structure.
16442 : : * @param[in, out] flow
16443 : : * Pointer to flow structure.
16444 : : */
16445 : : static void
16446 : 0 : flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
16447 : : {
16448 : : struct mlx5_flow_handle *dev_handle;
16449 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16450 : : struct mlx5_flow_meter_info *fm = NULL;
16451 : : uint32_t srss = 0;
16452 : :
16453 [ # # ]: 0 : if (!flow)
16454 : : return;
16455 : 0 : flow_dv_remove(dev, flow);
16456 [ # # ]: 0 : if (flow->counter) {
16457 : 0 : flow_dv_counter_free(dev, flow->counter);
16458 : 0 : flow->counter = 0;
16459 : : }
16460 [ # # ]: 0 : if (flow->meter) {
16461 : 0 : fm = flow_dv_meter_find_by_idx(priv, flow->meter);
16462 [ # # ]: 0 : if (fm)
16463 : 0 : mlx5_flow_meter_detach(priv, fm);
16464 : 0 : flow->meter = 0;
16465 : : }
16466 : : /* Keep the current age handling by default. */
16467 [ # # # # ]: 0 : if (flow->indirect_type == MLX5_INDIRECT_ACTION_TYPE_CT && flow->ct)
16468 : 0 : flow_dv_aso_ct_release(dev, flow->ct, NULL);
16469 [ # # ]: 0 : else if (flow->age)
16470 : 0 : flow_dv_aso_age_release(dev, flow->age);
16471 [ # # ]: 0 : while (flow->geneve_tlv_option) {
16472 : 0 : flow_dev_geneve_tlv_option_resource_release(priv->sh);
16473 : 0 : flow->geneve_tlv_option--;
16474 : : }
16475 [ # # ]: 0 : while (flow->dev_handles) {
16476 : : uint32_t tmp_idx = flow->dev_handles;
16477 : :
16478 : 0 : dev_handle = mlx5_ipool_get(priv->sh->ipool
16479 : : [MLX5_IPOOL_MLX5_FLOW], tmp_idx);
16480 [ # # ]: 0 : if (!dev_handle)
16481 : : return;
16482 : 0 : flow->dev_handles = dev_handle->next.next;
16483 [ # # ]: 0 : while (dev_handle->flex_item) {
16484 : 0 : int index = rte_bsf32(dev_handle->flex_item);
16485 : :
16486 : 0 : mlx5_flex_release_index(dev, index);
16487 : 0 : dev_handle->flex_item &= ~(uint8_t)RTE_BIT32(index);
16488 : : }
16489 [ # # ]: 0 : if (dev_handle->dvh.matcher)
16490 : 0 : flow_dv_matcher_release(dev, dev_handle);
16491 [ # # ]: 0 : if (dev_handle->dvh.rix_sample)
16492 : 0 : flow_dv_sample_resource_release(dev, dev_handle);
16493 [ # # ]: 0 : if (dev_handle->dvh.rix_dest_array)
16494 : 0 : flow_dv_dest_array_resource_release(dev, dev_handle);
16495 [ # # ]: 0 : if (dev_handle->dvh.rix_encap_decap)
16496 : 0 : flow_encap_decap_resource_release(dev,
16497 : : dev_handle->dvh.rix_encap_decap);
16498 [ # # ]: 0 : if (dev_handle->dvh.modify_hdr)
16499 : : flow_dv_modify_hdr_resource_release(dev, dev_handle);
16500 [ # # ]: 0 : if (dev_handle->dvh.rix_push_vlan)
16501 : 0 : flow_dv_push_vlan_action_resource_release(dev,
16502 : : dev_handle);
16503 [ # # ]: 0 : if (dev_handle->dvh.rix_tag)
16504 : 0 : flow_dv_tag_release(dev,
16505 : : dev_handle->dvh.rix_tag);
16506 [ # # ]: 0 : if (dev_handle->fate_action != MLX5_FLOW_FATE_SHARED_RSS)
16507 : 0 : flow_dv_fate_resource_release(dev, dev_handle);
16508 [ # # ]: 0 : else if (!srss)
16509 : 0 : srss = dev_handle->rix_srss;
16510 [ # # # # ]: 0 : if (fm && dev_handle->is_meter_flow_id &&
16511 [ # # ]: 0 : dev_handle->split_flow_id)
16512 : 0 : mlx5_ipool_free(fm->flow_ipool,
16513 : : dev_handle->split_flow_id);
16514 [ # # ]: 0 : else if (dev_handle->split_flow_id &&
16515 [ # # ]: 0 : !dev_handle->is_meter_flow_id)
16516 : 0 : mlx5_ipool_free(priv->sh->ipool
16517 : : [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
16518 : : dev_handle->split_flow_id);
16519 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
16520 : : tmp_idx);
16521 : : }
16522 [ # # ]: 0 : if (srss)
16523 : 0 : flow_dv_shared_rss_action_release(dev, srss);
16524 : : }
16525 : :
16526 : : /**
16527 : : * Release array of hash RX queue objects.
16528 : : * Helper function.
16529 : : *
16530 : : * @param[in] dev
16531 : : * Pointer to the Ethernet device structure.
16532 : : * @param[in, out] hrxqs
16533 : : * Array of hash RX queue objects.
16534 : : *
16535 : : * @return
16536 : : * Total number of references to hash RX queue objects in *hrxqs* array
16537 : : * after this operation.
16538 : : */
16539 : : static int
16540 : 0 : __flow_dv_hrxqs_release(struct rte_eth_dev *dev,
16541 : : uint32_t (*hrxqs)[MLX5_RSS_HASH_FIELDS_LEN])
16542 : : {
16543 : : size_t i;
16544 : : int remaining = 0;
16545 : :
16546 [ # # ]: 0 : for (i = 0; i < RTE_DIM(*hrxqs); i++) {
16547 : 0 : int ret = mlx5_hrxq_release(dev, (*hrxqs)[i]);
16548 : :
16549 [ # # ]: 0 : if (!ret)
16550 : 0 : (*hrxqs)[i] = 0;
16551 : 0 : remaining += ret;
16552 : : }
16553 : 0 : return remaining;
16554 : : }
16555 : :
16556 : : /**
16557 : : * Release all hash RX queue objects representing shared RSS action.
16558 : : *
16559 : : * @param[in] dev
16560 : : * Pointer to the Ethernet device structure.
16561 : : * @param[in, out] action
16562 : : * Shared RSS action to remove hash RX queue objects from.
16563 : : *
16564 : : * @return
16565 : : * Total number of references to hash RX queue objects stored in *action*
16566 : : * after this operation.
16567 : : * Expected to be 0 if no external references held.
16568 : : */
16569 : : static int
16570 : : __flow_dv_action_rss_hrxqs_release(struct rte_eth_dev *dev,
16571 : : struct mlx5_shared_action_rss *shared_rss)
16572 : : {
16573 : 0 : return __flow_dv_hrxqs_release(dev, &shared_rss->hrxq);
16574 : : }
16575 : :
16576 : : /**
16577 : : * Adjust L3/L4 hash value of pre-created shared RSS hrxq according to
16578 : : * user input.
16579 : : *
16580 : : * Only one hash value is available for one L3+L4 combination:
16581 : : * for example:
16582 : : * MLX5_RSS_HASH_IPV4, MLX5_RSS_HASH_IPV4_SRC_ONLY, and
16583 : : * MLX5_RSS_HASH_IPV4_DST_ONLY are mutually exclusive so they can share
16584 : : * same slot in mlx5_rss_hash_fields.
16585 : : *
16586 : : * @param[in] orig_rss_types
16587 : : * RSS type as provided in shared RSS action.
16588 : : * @param[in, out] hash_field
16589 : : * hash_field variable needed to be adjusted.
16590 : : *
16591 : : * @return
16592 : : * void
16593 : : */
16594 : : void
16595 [ # # ]: 0 : flow_dv_action_rss_l34_hash_adjust(uint64_t orig_rss_types,
16596 : : uint64_t *hash_field)
16597 : : {
16598 : : uint64_t rss_types = rte_eth_rss_hf_refine(orig_rss_types);
16599 : :
16600 [ # # # # : 0 : switch (*hash_field & ~IBV_RX_HASH_INNER) {
# ]
16601 : 0 : case MLX5_RSS_HASH_IPV4:
16602 [ # # ]: 0 : if (rss_types & MLX5_IPV4_LAYER_TYPES) {
16603 : 0 : *hash_field &= ~MLX5_RSS_HASH_IPV4;
16604 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
16605 : 0 : *hash_field |= IBV_RX_HASH_DST_IPV4;
16606 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
16607 : 0 : *hash_field |= IBV_RX_HASH_SRC_IPV4;
16608 : : else
16609 : 0 : *hash_field |= MLX5_RSS_HASH_IPV4;
16610 : : }
16611 : : return;
16612 : 0 : case MLX5_RSS_HASH_IPV6:
16613 [ # # ]: 0 : if (rss_types & MLX5_IPV6_LAYER_TYPES) {
16614 : 0 : *hash_field &= ~MLX5_RSS_HASH_IPV6;
16615 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
16616 : 0 : *hash_field |= IBV_RX_HASH_DST_IPV6;
16617 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
16618 : 0 : *hash_field |= IBV_RX_HASH_SRC_IPV6;
16619 : : else
16620 : 0 : *hash_field |= MLX5_RSS_HASH_IPV6;
16621 : : }
16622 : : return;
16623 : 0 : case MLX5_RSS_HASH_IPV4_UDP:
16624 : : /* fall-through. */
16625 : : case MLX5_RSS_HASH_IPV6_UDP:
16626 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_UDP) {
16627 : 0 : *hash_field &= ~MLX5_UDP_IBV_RX_HASH;
16628 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
16629 : 0 : *hash_field |= IBV_RX_HASH_DST_PORT_UDP;
16630 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
16631 : 0 : *hash_field |= IBV_RX_HASH_SRC_PORT_UDP;
16632 : : else
16633 : 0 : *hash_field |= MLX5_UDP_IBV_RX_HASH;
16634 : : }
16635 : : return;
16636 : 0 : case MLX5_RSS_HASH_IPV4_TCP:
16637 : : /* fall-through. */
16638 : : case MLX5_RSS_HASH_IPV6_TCP:
16639 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_TCP) {
16640 : 0 : *hash_field &= ~MLX5_TCP_IBV_RX_HASH;
16641 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
16642 : 0 : *hash_field |= IBV_RX_HASH_DST_PORT_TCP;
16643 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
16644 : 0 : *hash_field |= IBV_RX_HASH_SRC_PORT_TCP;
16645 : : else
16646 : 0 : *hash_field |= MLX5_TCP_IBV_RX_HASH;
16647 : : }
16648 : : return;
16649 : : default:
16650 : : return;
16651 : : }
16652 : : }
16653 : :
16654 : : /**
16655 : : * Setup shared RSS action.
16656 : : * Prepare set of hash RX queue objects sufficient to handle all valid
16657 : : * hash_fields combinations (see enum ibv_rx_hash_fields).
16658 : : *
16659 : : * @param[in] dev
16660 : : * Pointer to the Ethernet device structure.
16661 : : * @param[in] action_idx
16662 : : * Shared RSS action ipool index.
16663 : : * @param[in, out] action
16664 : : * Partially initialized shared RSS action.
16665 : : * @param[out] error
16666 : : * Perform verbose error reporting if not NULL. Initialized in case of
16667 : : * error only.
16668 : : *
16669 : : * @return
16670 : : * 0 on success, otherwise negative errno value.
16671 : : */
16672 : : static int
16673 : 0 : __flow_dv_action_rss_setup(struct rte_eth_dev *dev,
16674 : : uint32_t action_idx,
16675 : : struct mlx5_shared_action_rss *shared_rss,
16676 : : struct rte_flow_error *error)
16677 : : {
16678 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16679 : 0 : struct mlx5_flow_rss_desc rss_desc = { 0 };
16680 : : size_t i;
16681 : : int err;
16682 : :
16683 : 0 : shared_rss->ind_tbl = mlx5_ind_table_obj_new
16684 : : (dev, shared_rss->origin.queue,
16685 : : shared_rss->origin.queue_num,
16686 : : true,
16687 : 0 : !!dev->data->dev_started);
16688 [ # # ]: 0 : if (!shared_rss->ind_tbl)
16689 : 0 : return rte_flow_error_set(error, rte_errno,
16690 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16691 : : "cannot setup indirection table");
16692 : 0 : memcpy(rss_desc.key, shared_rss->origin.key, MLX5_RSS_HASH_KEY_LEN);
16693 : 0 : rss_desc.key_len = MLX5_RSS_HASH_KEY_LEN;
16694 : 0 : rss_desc.symmetric_hash_function =
16695 : 0 : MLX5_RSS_IS_SYMM(shared_rss->origin.func);
16696 : 0 : rss_desc.const_q = shared_rss->origin.queue;
16697 : 0 : rss_desc.queue_num = shared_rss->origin.queue_num;
16698 : : /* Set non-zero value to indicate a shared RSS. */
16699 : 0 : rss_desc.shared_rss = action_idx;
16700 : 0 : rss_desc.ind_tbl = shared_rss->ind_tbl;
16701 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
16702 : 0 : rss_desc.hws_flags = MLX5DR_ACTION_FLAG_HWS_RX;
16703 [ # # ]: 0 : for (i = 0; i < MLX5_RSS_HASH_FIELDS_LEN; i++) {
16704 : : struct mlx5_hrxq *hrxq;
16705 : 0 : uint64_t hash_fields = mlx5_rss_hash_fields[i];
16706 : : int tunnel = 0;
16707 : :
16708 : 0 : flow_dv_action_rss_l34_hash_adjust(shared_rss->origin.types,
16709 : : &hash_fields);
16710 [ # # ]: 0 : if (shared_rss->origin.level > 1) {
16711 : 0 : hash_fields |= IBV_RX_HASH_INNER;
16712 : : tunnel = 1;
16713 : : }
16714 : 0 : rss_desc.tunnel = tunnel;
16715 : 0 : rss_desc.hash_fields = hash_fields;
16716 : 0 : hrxq = mlx5_hrxq_get(dev, &rss_desc);
16717 [ # # ]: 0 : if (!hrxq) {
16718 : 0 : rte_flow_error_set
16719 : : (error, rte_errno,
16720 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16721 : : "cannot get hash queue");
16722 : 0 : goto error_hrxq_new;
16723 : : }
16724 : 0 : err = __flow_dv_action_rss_hrxq_set
16725 : : (shared_rss, hash_fields, hrxq->idx);
16726 : : MLX5_ASSERT(!err);
16727 : : }
16728 : : return 0;
16729 : : error_hrxq_new:
16730 : 0 : err = rte_errno;
16731 : : __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
16732 [ # # ]: 0 : if (!mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl, true))
16733 : 0 : shared_rss->ind_tbl = NULL;
16734 : 0 : rte_errno = err;
16735 : 0 : return -rte_errno;
16736 : : }
16737 : :
16738 : : /**
16739 : : * Create shared RSS action.
16740 : : *
16741 : : * @param[in] dev
16742 : : * Pointer to the Ethernet device structure.
16743 : : * @param[in] conf
16744 : : * Shared action configuration.
16745 : : * @param[in] rss
16746 : : * RSS action specification used to create shared action.
16747 : : * @param[out] error
16748 : : * Perform verbose error reporting if not NULL. Initialized in case of
16749 : : * error only.
16750 : : *
16751 : : * @return
16752 : : * A valid shared action ID in case of success, 0 otherwise and
16753 : : * rte_errno is set.
16754 : : */
16755 : : static uint32_t
16756 : 0 : __flow_dv_action_rss_create(struct rte_eth_dev *dev,
16757 : : const struct rte_flow_indir_action_conf *conf,
16758 : : const struct rte_flow_action_rss *rss,
16759 : : struct rte_flow_error *error)
16760 : : {
16761 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16762 : : struct mlx5_shared_action_rss *shared_rss = NULL;
16763 : : struct rte_flow_action_rss *origin;
16764 : : const uint8_t *rss_key;
16765 : : uint32_t idx;
16766 : :
16767 : : RTE_SET_USED(conf);
16768 : 0 : shared_rss = mlx5_ipool_zmalloc
16769 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], &idx);
16770 [ # # ]: 0 : if (!shared_rss) {
16771 : 0 : rte_flow_error_set(error, ENOMEM,
16772 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16773 : : "cannot allocate resource memory");
16774 : 0 : goto error_rss_init;
16775 : : }
16776 [ # # ]: 0 : if (idx > (1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET)) {
16777 : 0 : rte_flow_error_set(error, E2BIG,
16778 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16779 : : "rss action number out of range");
16780 : 0 : goto error_rss_init;
16781 : : }
16782 : : origin = &shared_rss->origin;
16783 : 0 : origin->func = rss->func;
16784 : 0 : origin->level = rss->level;
16785 : : /* RSS type 0 indicates default RSS type (RTE_ETH_RSS_IP). */
16786 [ # # ]: 0 : origin->types = !rss->types ? RTE_ETH_RSS_IP : rss->types;
16787 : : /* NULL RSS key indicates default RSS key. */
16788 [ # # ]: 0 : rss_key = !rss->key ? rss_hash_default_key : rss->key;
16789 : 0 : memcpy(shared_rss->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
16790 : 0 : origin->key = &shared_rss->key[0];
16791 : 0 : origin->key_len = MLX5_RSS_HASH_KEY_LEN;
16792 : 0 : origin->queue = rss->queue;
16793 : 0 : origin->queue_num = rss->queue_num;
16794 [ # # ]: 0 : if (__flow_dv_action_rss_setup(dev, idx, shared_rss, error))
16795 : 0 : goto error_rss_init;
16796 : : /* Update queue with indirect table queue memoyr. */
16797 : 0 : origin->queue = shared_rss->ind_tbl->queues;
16798 : : rte_spinlock_init(&shared_rss->action_rss_sl);
16799 : 0 : rte_atomic_fetch_add_explicit(&shared_rss->refcnt, 1, rte_memory_order_relaxed);
16800 : 0 : rte_spinlock_lock(&priv->shared_act_sl);
16801 [ # # # # ]: 0 : ILIST_INSERT(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
16802 : : &priv->rss_shared_actions, idx, shared_rss, next);
16803 : : rte_spinlock_unlock(&priv->shared_act_sl);
16804 : 0 : return idx;
16805 : 0 : error_rss_init:
16806 [ # # ]: 0 : if (shared_rss) {
16807 [ # # ]: 0 : if (shared_rss->ind_tbl)
16808 : 0 : mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl,
16809 : 0 : !!dev->data->dev_started);
16810 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
16811 : : idx);
16812 : : }
16813 : : return 0;
16814 : : }
16815 : :
16816 : : /**
16817 : : * Destroy the shared RSS action.
16818 : : * Release related hash RX queue objects.
16819 : : *
16820 : : * @param[in] dev
16821 : : * Pointer to the Ethernet device structure.
16822 : : * @param[in] idx
16823 : : * The shared RSS action object ID to be removed.
16824 : : * @param[out] error
16825 : : * Perform verbose error reporting if not NULL. Initialized in case of
16826 : : * error only.
16827 : : *
16828 : : * @return
16829 : : * 0 on success, otherwise negative errno value.
16830 : : */
16831 : : static int
16832 : 0 : __flow_dv_action_rss_release(struct rte_eth_dev *dev, uint32_t idx,
16833 : : struct rte_flow_error *error)
16834 : : {
16835 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16836 : : struct mlx5_shared_action_rss *shared_rss =
16837 : 0 : mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
16838 : : uint32_t old_refcnt = 1;
16839 : : int remaining;
16840 : :
16841 [ # # ]: 0 : if (!shared_rss)
16842 : 0 : return rte_flow_error_set(error, EINVAL,
16843 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
16844 : : "invalid shared action");
16845 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(&shared_rss->refcnt, &old_refcnt,
16846 : : 0, rte_memory_order_acquire,
16847 : : rte_memory_order_relaxed))
16848 : 0 : return rte_flow_error_set(error, EBUSY,
16849 : : RTE_FLOW_ERROR_TYPE_ACTION,
16850 : : NULL,
16851 : : "shared rss has references");
16852 : : remaining = __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
16853 [ # # ]: 0 : if (remaining)
16854 : 0 : return rte_flow_error_set(error, EBUSY,
16855 : : RTE_FLOW_ERROR_TYPE_ACTION,
16856 : : NULL,
16857 : : "shared rss hrxq has references");
16858 : 0 : remaining = mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl,
16859 : 0 : !!dev->data->dev_started);
16860 [ # # ]: 0 : if (remaining)
16861 : 0 : return rte_flow_error_set(error, EBUSY,
16862 : : RTE_FLOW_ERROR_TYPE_ACTION,
16863 : : NULL,
16864 : : "shared rss indirection table has"
16865 : : " references");
16866 : 0 : rte_spinlock_lock(&priv->shared_act_sl);
16867 [ # # # # : 0 : ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
# # # # #
# ]
16868 : : &priv->rss_shared_actions, idx, shared_rss, next);
16869 : : rte_spinlock_unlock(&priv->shared_act_sl);
16870 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
16871 : : idx);
16872 : 0 : return 0;
16873 : : }
16874 : :
16875 : : /**
16876 : : * Create indirect action, lock free,
16877 : : * (mutex should be acquired by caller).
16878 : : * Dispatcher for action type specific call.
16879 : : *
16880 : : * @param[in] dev
16881 : : * Pointer to the Ethernet device structure.
16882 : : * @param[in] conf
16883 : : * Shared action configuration.
16884 : : * @param[in] action
16885 : : * Action specification used to create indirect action.
16886 : : * @param[out] error
16887 : : * Perform verbose error reporting if not NULL. Initialized in case of
16888 : : * error only.
16889 : : *
16890 : : * @return
16891 : : * A valid shared action handle in case of success, NULL otherwise and
16892 : : * rte_errno is set.
16893 : : */
16894 : : struct rte_flow_action_handle *
16895 : 0 : flow_dv_action_create(struct rte_eth_dev *dev,
16896 : : const struct rte_flow_indir_action_conf *conf,
16897 : : const struct rte_flow_action *action,
16898 : : struct rte_flow_error *err)
16899 : : {
16900 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16901 : : uint32_t age_idx = 0;
16902 : : uint32_t idx = 0;
16903 : : uint32_t ret = 0;
16904 : :
16905 [ # # # # : 0 : switch (action->type) {
# ]
16906 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
16907 : 0 : ret = __flow_dv_action_rss_create(dev, conf, action->conf, err);
16908 : : idx = (MLX5_INDIRECT_ACTION_TYPE_RSS <<
16909 : : MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
16910 : 0 : break;
16911 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
16912 : 0 : age_idx = flow_dv_aso_age_alloc(dev, err);
16913 [ # # ]: 0 : if (!age_idx) {
16914 : 0 : ret = -rte_errno;
16915 : 0 : break;
16916 : : }
16917 : 0 : idx = (MLX5_INDIRECT_ACTION_TYPE_AGE <<
16918 : : MLX5_INDIRECT_ACTION_TYPE_OFFSET) | age_idx;
16919 : 0 : flow_dv_aso_age_params_init(dev, age_idx,
16920 : : ((const struct rte_flow_action_age *)
16921 : 0 : action->conf)->context ?
16922 : : ((const struct rte_flow_action_age *)
16923 : : action->conf)->context :
16924 : 0 : (void *)(uintptr_t)idx,
16925 : : ((const struct rte_flow_action_age *)
16926 [ # # ]: 0 : action->conf)->timeout);
16927 : : ret = age_idx;
16928 : 0 : break;
16929 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
16930 : 0 : ret = flow_dv_translate_create_counter(dev, NULL, NULL, NULL);
16931 : 0 : idx = (MLX5_INDIRECT_ACTION_TYPE_COUNT <<
16932 : : MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
16933 : 0 : break;
16934 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
16935 : 0 : ret = flow_dv_translate_create_conntrack(dev, action->conf,
16936 : : err);
16937 [ # # ]: 0 : if (!ret)
16938 : : break;
16939 : 0 : idx = MLX5_INDIRECT_ACT_CT_GEN_IDX(PORT_ID(priv), ret);
16940 : 0 : break;
16941 : 0 : default:
16942 : 0 : rte_flow_error_set(err, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
16943 : : NULL, "action type not supported");
16944 : : break;
16945 : : }
16946 [ # # ]: 0 : return ret ? (struct rte_flow_action_handle *)(uintptr_t)idx : NULL;
16947 : : }
16948 : :
16949 : : /**
16950 : : * Destroy the indirect action.
16951 : : * Release action related resources on the NIC and the memory.
16952 : : * Lock free, (mutex should be acquired by caller).
16953 : : * Dispatcher for action type specific call.
16954 : : *
16955 : : * @param[in] dev
16956 : : * Pointer to the Ethernet device structure.
16957 : : * @param[in] handle
16958 : : * The indirect action object handle to be removed.
16959 : : * @param[out] error
16960 : : * Perform verbose error reporting if not NULL. Initialized in case of
16961 : : * error only.
16962 : : *
16963 : : * @return
16964 : : * 0 on success, otherwise negative errno value.
16965 : : */
16966 : : int
16967 : 0 : flow_dv_action_destroy(struct rte_eth_dev *dev,
16968 : : struct rte_flow_action_handle *handle,
16969 : : struct rte_flow_error *error)
16970 : : {
16971 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
16972 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
16973 : 0 : uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
16974 : : struct mlx5_flow_counter *cnt;
16975 : : uint32_t no_flow_refcnt = 1;
16976 : : int ret;
16977 : :
16978 [ # # # # : 0 : switch (type) {
# ]
16979 : 0 : case MLX5_INDIRECT_ACTION_TYPE_RSS:
16980 : 0 : return __flow_dv_action_rss_release(dev, idx, error);
16981 : : case MLX5_INDIRECT_ACTION_TYPE_COUNT:
16982 : : cnt = flow_dv_counter_get_by_idx(dev, idx, NULL);
16983 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(&cnt->shared_info.refcnt,
16984 : : &no_flow_refcnt, 1,
16985 : : rte_memory_order_acquire,
16986 : : rte_memory_order_relaxed))
16987 : 0 : return rte_flow_error_set(error, EBUSY,
16988 : : RTE_FLOW_ERROR_TYPE_ACTION,
16989 : : NULL,
16990 : : "Indirect count action has references");
16991 : 0 : flow_dv_counter_free(dev, idx);
16992 : 0 : return 0;
16993 : 0 : case MLX5_INDIRECT_ACTION_TYPE_AGE:
16994 : 0 : ret = flow_dv_aso_age_release(dev, idx);
16995 [ # # ]: 0 : if (ret)
16996 : : /*
16997 : : * In this case, the last flow has a reference will
16998 : : * actually release the age action.
16999 : : */
17000 : 0 : DRV_LOG(DEBUG, "Indirect age action %" PRIu32 " was"
17001 : : " released with references %d.", idx, ret);
17002 : : return 0;
17003 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
17004 : 0 : ret = flow_dv_aso_ct_release(dev, idx, error);
17005 [ # # ]: 0 : if (ret < 0)
17006 : : return ret;
17007 [ # # ]: 0 : if (ret > 0)
17008 : 0 : DRV_LOG(DEBUG, "Connection tracking object %u still "
17009 : : "has references %d.", idx, ret);
17010 : : return 0;
17011 : 0 : default:
17012 : 0 : return rte_flow_error_set(error, ENOTSUP,
17013 : : RTE_FLOW_ERROR_TYPE_ACTION,
17014 : : NULL,
17015 : : "action type not supported");
17016 : : }
17017 : : }
17018 : :
17019 : : /**
17020 : : * Updates in place shared RSS action configuration.
17021 : : *
17022 : : * @param[in] dev
17023 : : * Pointer to the Ethernet device structure.
17024 : : * @param[in] idx
17025 : : * The shared RSS action object ID to be updated.
17026 : : * @param[in] action_conf
17027 : : * RSS action specification used to modify *shared_rss*.
17028 : : * @param[out] error
17029 : : * Perform verbose error reporting if not NULL. Initialized in case of
17030 : : * error only.
17031 : : *
17032 : : * @return
17033 : : * 0 on success, otherwise negative errno value.
17034 : : * @note: currently only support update of RSS queues.
17035 : : */
17036 : : static int
17037 : 0 : __flow_dv_action_rss_update(struct rte_eth_dev *dev, uint32_t idx,
17038 : : const struct rte_flow_action_rss *action_conf,
17039 : : struct rte_flow_error *error)
17040 : : {
17041 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17042 : : struct mlx5_shared_action_rss *shared_rss =
17043 : 0 : mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
17044 : : int ret = 0;
17045 : : void *queue = NULL;
17046 : : void *queue_i = NULL;
17047 : 0 : uint32_t queue_size = action_conf->queue_num * sizeof(uint16_t);
17048 : 0 : bool dev_started = !!dev->data->dev_started;
17049 : :
17050 [ # # ]: 0 : if (!shared_rss)
17051 : 0 : return rte_flow_error_set(error, EINVAL,
17052 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
17053 : : "invalid shared action to update");
17054 [ # # ]: 0 : if (priv->obj_ops.ind_table_modify == NULL)
17055 : 0 : return rte_flow_error_set(error, ENOTSUP,
17056 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
17057 : : "cannot modify indirection table");
17058 : 0 : queue = mlx5_malloc(MLX5_MEM_ZERO,
17059 : 0 : RTE_ALIGN_CEIL(queue_size, sizeof(void *)),
17060 : : 0, SOCKET_ID_ANY);
17061 [ # # ]: 0 : if (!queue)
17062 : 0 : return rte_flow_error_set(error, ENOMEM,
17063 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17064 : : NULL,
17065 : : "cannot allocate resource memory");
17066 : 0 : memcpy(queue, action_conf->queue, queue_size);
17067 : : MLX5_ASSERT(shared_rss->ind_tbl);
17068 : 0 : rte_spinlock_lock(&shared_rss->action_rss_sl);
17069 : 0 : queue_i = shared_rss->ind_tbl->queues;
17070 : 0 : ret = mlx5_ind_table_obj_modify(dev, shared_rss->ind_tbl,
17071 : 0 : queue, action_conf->queue_num,
17072 : : true /* standalone */,
17073 : : dev_started /* ref_new_qs */,
17074 : : dev_started /* deref_old_qs */);
17075 [ # # ]: 0 : if (ret) {
17076 : 0 : ret = rte_flow_error_set(error, rte_errno,
17077 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
17078 : : "cannot update indirection table");
17079 : : } else {
17080 : : /* Restore the queue to indirect table internal queue. */
17081 : : memcpy(queue_i, queue, queue_size);
17082 : 0 : shared_rss->ind_tbl->queues = queue_i;
17083 : 0 : shared_rss->origin.queue_num = action_conf->queue_num;
17084 : : }
17085 : 0 : mlx5_free(queue);
17086 : : rte_spinlock_unlock(&shared_rss->action_rss_sl);
17087 : 0 : return ret;
17088 : : }
17089 : :
17090 : : /*
17091 : : * Updates in place conntrack context or direction.
17092 : : * Context update should be synchronized.
17093 : : *
17094 : : * @param[in] dev
17095 : : * Pointer to the Ethernet device structure.
17096 : : * @param[in] idx
17097 : : * The conntrack object ID to be updated.
17098 : : * @param[in] update
17099 : : * Pointer to the structure of information to update.
17100 : : * @param[out] error
17101 : : * Perform verbose error reporting if not NULL. Initialized in case of
17102 : : * error only.
17103 : : *
17104 : : * @return
17105 : : * 0 on success, otherwise negative errno value.
17106 : : */
17107 : : static int
17108 : 0 : __flow_dv_action_ct_update(struct rte_eth_dev *dev, uint32_t idx,
17109 : : const struct rte_flow_modify_conntrack *update,
17110 : : struct rte_flow_error *error)
17111 : : {
17112 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17113 : : struct mlx5_aso_ct_action *ct;
17114 : : const struct rte_flow_action_conntrack *new_prf;
17115 : : int ret = 0;
17116 : 0 : uint16_t owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(idx);
17117 : : uint32_t dev_idx;
17118 : :
17119 [ # # ]: 0 : if (PORT_ID(priv) != owner)
17120 : 0 : return rte_flow_error_set(error, EACCES,
17121 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17122 : : NULL,
17123 : : "CT object owned by another port");
17124 : 0 : dev_idx = MLX5_INDIRECT_ACT_CT_GET_IDX(idx);
17125 : 0 : ct = flow_aso_ct_get_by_dev_idx(dev, dev_idx);
17126 [ # # ]: 0 : if (!ct->refcnt)
17127 : 0 : return rte_flow_error_set(error, ENOMEM,
17128 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17129 : : NULL,
17130 : : "CT object is inactive");
17131 : 0 : new_prf = &update->new_ct;
17132 [ # # ]: 0 : if (update->direction)
17133 : 0 : ct->is_original = !!new_prf->is_original_dir;
17134 [ # # ]: 0 : if (update->state) {
17135 : : /* Only validate the profile when it needs to be updated. */
17136 : 0 : ret = mlx5_validate_action_ct(dev, new_prf, error);
17137 [ # # ]: 0 : if (ret)
17138 : : return ret;
17139 : 0 : ret = mlx5_aso_ct_update_by_wqe(priv->sh, MLX5_HW_INV_QUEUE,
17140 : : ct, new_prf, NULL, true);
17141 [ # # ]: 0 : if (ret)
17142 : 0 : return rte_flow_error_set(error, EIO,
17143 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17144 : : NULL,
17145 : : "Failed to send CT context update WQE");
17146 : : /* Block until ready or a failure, default is asynchronous. */
17147 : 0 : ret = mlx5_aso_ct_available(priv->sh, MLX5_HW_INV_QUEUE, ct);
17148 [ # # ]: 0 : if (ret)
17149 : 0 : rte_flow_error_set(error, rte_errno,
17150 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17151 : : NULL,
17152 : : "Timeout to get the CT update");
17153 : : }
17154 : : return ret;
17155 : : }
17156 : :
17157 : : /**
17158 : : * Updates in place shared action configuration, lock free,
17159 : : * (mutex should be acquired by caller).
17160 : : *
17161 : : * @param[in] dev
17162 : : * Pointer to the Ethernet device structure.
17163 : : * @param[in] handle
17164 : : * The indirect action object handle to be updated.
17165 : : * @param[in] update
17166 : : * Action specification used to modify the action pointed by *handle*.
17167 : : * *update* could be of same type with the action pointed by the *handle*
17168 : : * handle argument, or some other structures like a wrapper, depending on
17169 : : * the indirect action type.
17170 : : * @param[out] error
17171 : : * Perform verbose error reporting if not NULL. Initialized in case of
17172 : : * error only.
17173 : : *
17174 : : * @return
17175 : : * 0 on success, otherwise negative errno value.
17176 : : */
17177 : : int
17178 : 0 : flow_dv_action_update(struct rte_eth_dev *dev,
17179 : : struct rte_flow_action_handle *handle,
17180 : : const void *update,
17181 : : struct rte_flow_error *err)
17182 : : {
17183 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
17184 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
17185 : 0 : uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
17186 : : const void *action_conf;
17187 : :
17188 [ # # # ]: 0 : switch (type) {
17189 : 0 : case MLX5_INDIRECT_ACTION_TYPE_RSS:
17190 : 0 : action_conf = ((const struct rte_flow_action *)update)->conf;
17191 : 0 : return __flow_dv_action_rss_update(dev, idx, action_conf, err);
17192 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
17193 : 0 : return __flow_dv_action_ct_update(dev, idx, update, err);
17194 : 0 : default:
17195 : 0 : return rte_flow_error_set(err, ENOTSUP,
17196 : : RTE_FLOW_ERROR_TYPE_ACTION,
17197 : : NULL,
17198 : : "action type update not supported");
17199 : : }
17200 : : }
17201 : :
17202 : : /**
17203 : : * Destroy the meter sub policy table rules.
17204 : : * Lock free, (mutex should be acquired by caller).
17205 : : *
17206 : : * @param[in] dev
17207 : : * Pointer to Ethernet device.
17208 : : * @param[in] sub_policy
17209 : : * Pointer to meter sub policy table.
17210 : : */
17211 : : static void
17212 : 0 : __flow_dv_destroy_sub_policy_rules(struct rte_eth_dev *dev,
17213 : : struct mlx5_flow_meter_sub_policy *sub_policy)
17214 : : {
17215 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17216 : : struct mlx5_flow_tbl_data_entry *tbl;
17217 : 0 : struct mlx5_flow_meter_policy *policy = sub_policy->main_policy;
17218 : : struct mlx5_flow_meter_info *next_fm;
17219 : : struct mlx5_sub_policy_color_rule *color_rule;
17220 : : void *tmp;
17221 : : uint32_t i;
17222 : :
17223 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
17224 : : next_fm = NULL;
17225 [ # # ]: 0 : if (i <= RTE_COLOR_YELLOW && policy &&
17226 [ # # ]: 0 : policy->act_cnt[i].fate_action == MLX5_FLOW_FATE_MTR)
17227 : 0 : next_fm = mlx5_flow_meter_find(priv,
17228 : : policy->act_cnt[i].next_mtr_id, NULL);
17229 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(color_rule, &sub_policy->color_rules[i],
17230 : : next_port, tmp) {
17231 : 0 : claim_zero(mlx5_flow_os_destroy_flow(color_rule->rule));
17232 : 0 : tbl = container_of(color_rule->matcher->tbl,
17233 : : typeof(*tbl), tbl);
17234 : 0 : mlx5_list_unregister(tbl->matchers,
17235 : : &color_rule->matcher->entry);
17236 [ # # ]: 0 : TAILQ_REMOVE(&sub_policy->color_rules[i],
17237 : : color_rule, next_port);
17238 : 0 : mlx5_free(color_rule);
17239 [ # # ]: 0 : if (next_fm)
17240 : 0 : mlx5_flow_meter_detach(priv, next_fm);
17241 : : }
17242 : : }
17243 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
17244 [ # # ]: 0 : if (sub_policy->rix_hrxq[i]) {
17245 [ # # # # ]: 0 : if (policy && !policy->is_hierarchy)
17246 : 0 : mlx5_hrxq_release(dev, sub_policy->rix_hrxq[i]);
17247 : 0 : sub_policy->rix_hrxq[i] = 0;
17248 : : }
17249 [ # # ]: 0 : if (sub_policy->jump_tbl[i]) {
17250 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev),
17251 : : sub_policy->jump_tbl[i]);
17252 : 0 : sub_policy->jump_tbl[i] = NULL;
17253 : : }
17254 : : }
17255 [ # # ]: 0 : if (sub_policy->tbl_rsc) {
17256 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev),
17257 : : sub_policy->tbl_rsc);
17258 : 0 : sub_policy->tbl_rsc = NULL;
17259 : : }
17260 : 0 : }
17261 : :
17262 : : /**
17263 : : * Destroy policy rules, lock free,
17264 : : * (mutex should be acquired by caller).
17265 : : * Dispatcher for action type specific call.
17266 : : *
17267 : : * @param[in] dev
17268 : : * Pointer to the Ethernet device structure.
17269 : : * @param[in] mtr_policy
17270 : : * Meter policy struct.
17271 : : */
17272 : : static void
17273 : 0 : flow_dv_destroy_policy_rules(struct rte_eth_dev *dev,
17274 : : struct mlx5_flow_meter_policy *mtr_policy)
17275 : : {
17276 : : uint32_t i, j;
17277 : : struct mlx5_flow_meter_sub_policy *sub_policy;
17278 : : uint16_t sub_policy_num;
17279 : :
17280 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
17281 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
17282 : 0 : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
17283 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
17284 [ # # ]: 0 : for (j = 0; j < sub_policy_num; j++) {
17285 : 0 : sub_policy = mtr_policy->sub_policys[i][j];
17286 [ # # ]: 0 : if (sub_policy)
17287 : 0 : __flow_dv_destroy_sub_policy_rules(dev,
17288 : : sub_policy);
17289 : : }
17290 : : }
17291 : 0 : }
17292 : :
17293 : : /**
17294 : : * Destroy policy action, lock free,
17295 : : * (mutex should be acquired by caller).
17296 : : * Dispatcher for action type specific call.
17297 : : *
17298 : : * @param[in] dev
17299 : : * Pointer to the Ethernet device structure.
17300 : : * @param[in] mtr_policy
17301 : : * Meter policy struct.
17302 : : */
17303 : : static void
17304 : 0 : flow_dv_destroy_mtr_policy_acts(struct rte_eth_dev *dev,
17305 : : struct mlx5_flow_meter_policy *mtr_policy)
17306 : : {
17307 : : struct rte_flow_action *rss_action;
17308 : : struct mlx5_flow_handle dev_handle;
17309 : : uint32_t i, j;
17310 : :
17311 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
17312 [ # # ]: 0 : if (mtr_policy->act_cnt[i].rix_mark) {
17313 : 0 : flow_dv_tag_release(dev,
17314 : : mtr_policy->act_cnt[i].rix_mark);
17315 : 0 : mtr_policy->act_cnt[i].rix_mark = 0;
17316 : : }
17317 [ # # ]: 0 : if (mtr_policy->act_cnt[i].modify_hdr) {
17318 : : dev_handle.dvh.modify_hdr =
17319 : : mtr_policy->act_cnt[i].modify_hdr;
17320 : : flow_dv_modify_hdr_resource_release(dev, &dev_handle);
17321 : : }
17322 [ # # # # ]: 0 : switch (mtr_policy->act_cnt[i].fate_action) {
17323 : 0 : case MLX5_FLOW_FATE_SHARED_RSS:
17324 : 0 : rss_action = mtr_policy->act_cnt[i].rss;
17325 : 0 : mlx5_free(rss_action);
17326 : 0 : break;
17327 : 0 : case MLX5_FLOW_FATE_PORT_ID:
17328 [ # # ]: 0 : if (mtr_policy->act_cnt[i].rix_port_id_action) {
17329 : 0 : flow_dv_port_id_action_resource_release(dev,
17330 : : mtr_policy->act_cnt[i].rix_port_id_action);
17331 : 0 : mtr_policy->act_cnt[i].rix_port_id_action = 0;
17332 : : }
17333 : : break;
17334 : : case MLX5_FLOW_FATE_DROP:
17335 : : case MLX5_FLOW_FATE_JUMP:
17336 [ # # ]: 0 : for (j = 0; j < MLX5_MTR_DOMAIN_MAX; j++)
17337 : 0 : mtr_policy->act_cnt[i].dr_jump_action[j] =
17338 : : NULL;
17339 : : break;
17340 : : default:
17341 : : /*Queue action do nothing*/
17342 : : break;
17343 : : }
17344 : : }
17345 [ # # ]: 0 : for (j = 0; j < MLX5_MTR_DOMAIN_MAX; j++)
17346 : 0 : mtr_policy->dr_drop_action[j] = NULL;
17347 : 0 : }
17348 : :
17349 : : /**
17350 : : * Create yellow action for color aware meter.
17351 : : *
17352 : : * @param[in] dev
17353 : : * Pointer to the Ethernet device structure.
17354 : : * @param[in] fm
17355 : : * Meter information table.
17356 : : * @param[out] error
17357 : : * Perform verbose error reporting if not NULL. Initialized in case of
17358 : : * error only.
17359 : : *
17360 : : * @return
17361 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
17362 : : */
17363 : : static int
17364 : 0 : __flow_dv_create_mtr_yellow_action(struct rte_eth_dev *dev,
17365 : : struct mlx5_flow_meter_info *fm,
17366 : : struct rte_mtr_error *error)
17367 : : {
17368 : : #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
17369 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17370 : : struct rte_flow_error flow_err;
17371 : : struct mlx5_aso_mtr *aso_mtr;
17372 : : struct mlx5_aso_mtr_pool *pool;
17373 : : uint8_t reg_id;
17374 : :
17375 : 0 : aso_mtr = container_of(fm, struct mlx5_aso_mtr, fm);
17376 : 0 : pool = container_of(aso_mtr, struct mlx5_aso_mtr_pool, mtrs[aso_mtr->offset]);
17377 : 0 : reg_id = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &flow_err);
17378 : 0 : fm->meter_action_y =
17379 : 0 : mlx5_glue->dv_create_flow_action_aso(priv->sh->rx_domain,
17380 : 0 : pool->devx_obj->obj,
17381 : : aso_mtr->offset,
17382 : : (1 << MLX5_FLOW_COLOR_YELLOW),
17383 : 0 : reg_id - REG_C_0);
17384 : : #else
17385 : : RTE_SET_USED(dev);
17386 : : #endif
17387 [ # # ]: 0 : if (!fm->meter_action_y) {
17388 : 0 : return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
17389 : : "Fail to create yellow meter action.");
17390 : : }
17391 : : return 0;
17392 : : }
17393 : :
17394 : : /**
17395 : : * Create policy action per domain, lock free,
17396 : : * (mutex should be acquired by caller).
17397 : : * Dispatcher for action type specific call.
17398 : : *
17399 : : * @param[in] dev
17400 : : * Pointer to the Ethernet device structure.
17401 : : * @param[in] mtr_policy
17402 : : * Meter policy struct.
17403 : : * @param[in] action
17404 : : * Action specification used to create meter actions.
17405 : : * @param[in] attr
17406 : : * Pointer to the flow attributes.
17407 : : * @param[out] error
17408 : : * Perform verbose error reporting if not NULL. Initialized in case of
17409 : : * error only.
17410 : : *
17411 : : * @return
17412 : : * 0 on success, otherwise negative errno value.
17413 : : */
17414 : : static int
17415 : 0 : __flow_dv_create_domain_policy_acts(struct rte_eth_dev *dev,
17416 : : struct mlx5_flow_meter_policy *mtr_policy,
17417 : : const struct rte_flow_action *actions[RTE_COLORS],
17418 : : struct rte_flow_attr *attr,
17419 : : enum mlx5_meter_domain domain,
17420 : : struct rte_mtr_error *error)
17421 : : {
17422 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17423 : : struct rte_flow_error flow_err;
17424 : : const struct rte_flow_action *act;
17425 : : uint64_t action_flags;
17426 : : struct mlx5_flow_handle dh;
17427 : : struct mlx5_flow dev_flow;
17428 : : struct mlx5_flow_dv_port_id_action_resource port_id_action;
17429 : : int i, ret;
17430 : : uint8_t egress, transfer;
17431 : : struct mlx5_meter_policy_action_container *act_cnt = NULL;
17432 : : union {
17433 : : struct mlx5_flow_dv_modify_hdr_resource res;
17434 : : uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
17435 : : sizeof(struct mlx5_modification_cmd) *
17436 : : (MLX5_MAX_MODIFY_NUM + 1)];
17437 : : } mhdr_dummy;
17438 : : struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
17439 : :
17440 : 0 : egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
17441 [ # # ]: 0 : transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
17442 : : memset(&dh, 0, sizeof(struct mlx5_flow_handle));
17443 : : memset(&dev_flow, 0, sizeof(struct mlx5_flow));
17444 : : memset(&port_id_action, 0,
17445 : : sizeof(struct mlx5_flow_dv_port_id_action_resource));
17446 : : memset(mhdr_res, 0, sizeof(*mhdr_res));
17447 [ # # ]: 0 : mhdr_res->ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
17448 : : (egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
17449 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX);
17450 : 0 : dev_flow.handle = &dh;
17451 : 0 : dev_flow.dv.port_id_action = &port_id_action;
17452 : 0 : dev_flow.external = true;
17453 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
17454 [ # # ]: 0 : if (i < MLX5_MTR_RTE_COLORS)
17455 : 0 : act_cnt = &mtr_policy->act_cnt[i];
17456 : : /* Skip the color policy actions creation. */
17457 [ # # # # : 0 : if ((i == RTE_COLOR_YELLOW && mtr_policy->skip_y) ||
# # ]
17458 [ # # ]: 0 : (i == RTE_COLOR_GREEN && mtr_policy->skip_g))
17459 : 0 : continue;
17460 : : action_flags = 0;
17461 : 0 : for (act = actions[i];
17462 [ # # # # ]: 0 : act && act->type != RTE_FLOW_ACTION_TYPE_END; act++) {
17463 [ # # # # : 0 : switch (act->type) {
# # # # #
# ]
17464 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
17465 : : {
17466 : : uint32_t tag_be = mlx5_flow_mark_set
17467 : : (((const struct rte_flow_action_mark *)
17468 [ # # ]: 0 : (act->conf))->id);
17469 : :
17470 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17471 : 0 : return -rte_mtr_error_set(error,
17472 : : ENOTSUP,
17473 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17474 : : NULL,
17475 : : "cannot create policy "
17476 : : "mark action for this color");
17477 [ # # ]: 0 : if (flow_dv_tag_resource_register(dev, tag_be,
17478 : : &dev_flow, &flow_err))
17479 : 0 : return -rte_mtr_error_set(error,
17480 : : ENOTSUP,
17481 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17482 : : NULL,
17483 : : "cannot setup policy mark action");
17484 : : MLX5_ASSERT(dev_flow.dv.tag_resource);
17485 : 0 : act_cnt->rix_mark =
17486 : 0 : dev_flow.handle->dvh.rix_tag;
17487 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK;
17488 : 0 : mtr_policy->mark = 1;
17489 : 0 : break;
17490 : : }
17491 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TAG:
17492 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17493 : 0 : return -rte_mtr_error_set(error,
17494 : : ENOTSUP,
17495 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17496 : : NULL,
17497 : : "cannot create policy "
17498 : : "set tag action for this color");
17499 [ # # ]: 0 : if (flow_dv_convert_action_set_tag
17500 : : (dev, mhdr_res,
17501 : : (const struct rte_flow_action_set_tag *)
17502 : 0 : act->conf, &flow_err))
17503 : 0 : return -rte_mtr_error_set(error,
17504 : : ENOTSUP,
17505 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17506 : : NULL, "cannot convert policy "
17507 : : "set tag action");
17508 [ # # ]: 0 : if (!mhdr_res->actions_num)
17509 : 0 : return -rte_mtr_error_set(error,
17510 : : ENOTSUP,
17511 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17512 : : NULL, "cannot find policy "
17513 : : "set tag action");
17514 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
17515 : 0 : break;
17516 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
17517 : : {
17518 : 0 : struct mlx5_flow_mtr_mng *mtrmng =
17519 : 0 : priv->sh->mtrmng;
17520 : : struct mlx5_flow_tbl_data_entry *tbl_data;
17521 : :
17522 : : /*
17523 : : * Create the drop table with
17524 : : * METER DROP level.
17525 : : */
17526 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
17527 : 0 : mtrmng->drop_tbl[domain] =
17528 : 0 : flow_dv_tbl_resource_get(dev,
17529 : : MLX5_FLOW_TABLE_LEVEL_METER,
17530 : : egress, transfer, false, NULL, 0,
17531 : : 0, MLX5_MTR_TABLE_ID_DROP, &flow_err);
17532 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain])
17533 : 0 : return -rte_mtr_error_set
17534 : : (error, ENOTSUP,
17535 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17536 : : NULL,
17537 : : "Failed to create meter drop table");
17538 : : }
17539 : 0 : tbl_data = container_of
17540 : : (mtrmng->drop_tbl[domain],
17541 : : struct mlx5_flow_tbl_data_entry, tbl);
17542 [ # # ]: 0 : if (i < MLX5_MTR_RTE_COLORS) {
17543 : 0 : act_cnt->dr_jump_action[domain] =
17544 : 0 : tbl_data->jump.action;
17545 : 0 : act_cnt->fate_action =
17546 : : MLX5_FLOW_FATE_DROP;
17547 : : }
17548 [ # # ]: 0 : if (i == RTE_COLOR_RED)
17549 : 0 : mtr_policy->dr_drop_action[domain] =
17550 : 0 : tbl_data->jump.action;
17551 : 0 : action_flags |= MLX5_FLOW_ACTION_DROP;
17552 : 0 : break;
17553 : : }
17554 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
17555 : : {
17556 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17557 : 0 : return -rte_mtr_error_set(error,
17558 : : ENOTSUP,
17559 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17560 : : NULL, "cannot create policy "
17561 : : "fate queue for this color");
17562 : 0 : act_cnt->queue =
17563 : : ((const struct rte_flow_action_queue *)
17564 : 0 : (act->conf))->index;
17565 : 0 : act_cnt->fate_action =
17566 : : MLX5_FLOW_FATE_QUEUE;
17567 : 0 : dev_flow.handle->fate_action =
17568 : : MLX5_FLOW_FATE_QUEUE;
17569 : 0 : mtr_policy->is_queue = 1;
17570 : 0 : action_flags |= MLX5_FLOW_ACTION_QUEUE;
17571 : 0 : break;
17572 : : }
17573 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
17574 : : {
17575 : : int rss_size;
17576 : :
17577 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17578 : 0 : return -rte_mtr_error_set(error,
17579 : : ENOTSUP,
17580 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17581 : : NULL,
17582 : : "cannot create policy "
17583 : : "rss action for this color");
17584 : : /*
17585 : : * Save RSS conf into policy struct
17586 : : * for translate stage.
17587 : : */
17588 : 0 : rss_size = (int)rte_flow_conv
17589 : : (RTE_FLOW_CONV_OP_ACTION,
17590 : : NULL, 0, act, &flow_err);
17591 [ # # ]: 0 : if (rss_size <= 0)
17592 : 0 : return -rte_mtr_error_set(error,
17593 : : ENOTSUP,
17594 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17595 : : NULL, "Get the wrong "
17596 : : "rss action struct size");
17597 : 0 : act_cnt->rss = mlx5_malloc(MLX5_MEM_ZERO,
17598 : : rss_size, 0, SOCKET_ID_ANY);
17599 [ # # ]: 0 : if (!act_cnt->rss)
17600 : 0 : return -rte_mtr_error_set(error,
17601 : : ENOTSUP,
17602 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17603 : : NULL,
17604 : : "Fail to malloc rss action memory");
17605 : 0 : ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTION,
17606 : : act_cnt->rss, rss_size,
17607 : : act, &flow_err);
17608 [ # # ]: 0 : if (ret < 0)
17609 : 0 : return -rte_mtr_error_set(error,
17610 : : ENOTSUP,
17611 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17612 : : NULL, "Fail to save "
17613 : : "rss action into policy struct");
17614 : 0 : act_cnt->fate_action =
17615 : : MLX5_FLOW_FATE_SHARED_RSS;
17616 : 0 : action_flags |= MLX5_FLOW_ACTION_RSS;
17617 : 0 : break;
17618 : : }
17619 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
17620 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
17621 : : {
17622 : : struct mlx5_flow_dv_port_id_action_resource
17623 : : port_id_resource;
17624 : 0 : uint32_t port_id = 0;
17625 : :
17626 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17627 : 0 : return -rte_mtr_error_set(error,
17628 : : ENOTSUP,
17629 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17630 : : NULL, "cannot create policy "
17631 : : "port action for this color");
17632 : : memset(&port_id_resource, 0,
17633 : : sizeof(port_id_resource));
17634 [ # # ]: 0 : if (flow_dv_translate_action_port_id(dev, act,
17635 : : &port_id, &flow_err))
17636 : 0 : return -rte_mtr_error_set(error,
17637 : : ENOTSUP,
17638 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17639 : : NULL, "cannot translate "
17640 : : "policy port action");
17641 : 0 : port_id_resource.port_id = port_id;
17642 [ # # ]: 0 : if (flow_dv_port_id_action_resource_register
17643 : : (dev, &port_id_resource,
17644 : : &dev_flow, &flow_err))
17645 : 0 : return -rte_mtr_error_set(error,
17646 : : ENOTSUP,
17647 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17648 : : NULL, "cannot setup "
17649 : : "policy port action");
17650 : 0 : act_cnt->rix_port_id_action =
17651 : 0 : dev_flow.handle->rix_port_id_action;
17652 : 0 : act_cnt->fate_action =
17653 : : MLX5_FLOW_FATE_PORT_ID;
17654 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_ID;
17655 : 0 : break;
17656 : : }
17657 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
17658 : : {
17659 : : uint32_t jump_group = 0;
17660 : 0 : uint32_t table = 0;
17661 : : struct mlx5_flow_tbl_data_entry *tbl_data;
17662 : 0 : struct flow_grp_info grp_info = {
17663 : 0 : .external = !!dev_flow.external,
17664 : : .transfer = !!transfer,
17665 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
17666 : : .std_tbl_fix = 0,
17667 : 0 : .skip_scale = dev_flow.skip_scale &
17668 : : (1 << MLX5_SCALE_FLOW_GROUP_BIT),
17669 : : };
17670 : 0 : struct mlx5_flow_meter_sub_policy *sub_policy =
17671 : 0 : mtr_policy->sub_policys[domain][0];
17672 : :
17673 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17674 : 0 : return -rte_mtr_error_set(error,
17675 : : ENOTSUP,
17676 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17677 : : NULL,
17678 : : "cannot create policy "
17679 : : "jump action for this color");
17680 : 0 : jump_group =
17681 : : ((const struct rte_flow_action_jump *)
17682 : 0 : act->conf)->group;
17683 [ # # ]: 0 : if (mlx5_flow_group_to_table(dev, NULL,
17684 : : jump_group,
17685 : : &table,
17686 : : &grp_info, &flow_err))
17687 : 0 : return -rte_mtr_error_set(error,
17688 : : ENOTSUP,
17689 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17690 : : NULL, "cannot setup "
17691 : : "policy jump action");
17692 : 0 : sub_policy->jump_tbl[i] =
17693 : 0 : flow_dv_tbl_resource_get(dev,
17694 : : table, egress,
17695 : : transfer,
17696 : : !!dev_flow.external,
17697 : : NULL, jump_group, 0,
17698 : : 0, &flow_err);
17699 : : if
17700 [ # # ]: 0 : (!sub_policy->jump_tbl[i])
17701 : 0 : return -rte_mtr_error_set(error,
17702 : : ENOTSUP,
17703 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17704 : : NULL, "cannot create jump action.");
17705 : 0 : tbl_data = container_of
17706 : : (sub_policy->jump_tbl[i],
17707 : : struct mlx5_flow_tbl_data_entry, tbl);
17708 : 0 : act_cnt->dr_jump_action[domain] =
17709 : 0 : tbl_data->jump.action;
17710 : 0 : act_cnt->fate_action =
17711 : : MLX5_FLOW_FATE_JUMP;
17712 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP;
17713 : 0 : break;
17714 : : }
17715 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
17716 : : {
17717 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17718 : 0 : return -rte_mtr_error_set(error,
17719 : : ENOTSUP,
17720 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17721 : : NULL,
17722 : : "cannot create policy modify field for this color");
17723 [ # # ]: 0 : if (flow_dv_convert_action_modify_field
17724 : : (dev, mhdr_res, act, attr, &flow_err))
17725 : 0 : return -rte_mtr_error_set(error,
17726 : : ENOTSUP,
17727 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17728 : : NULL, "cannot setup policy modify field action");
17729 [ # # ]: 0 : if (!mhdr_res->actions_num)
17730 : 0 : return -rte_mtr_error_set(error,
17731 : : ENOTSUP,
17732 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17733 : : NULL, "cannot find policy modify field action");
17734 : 0 : action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
17735 : 0 : break;
17736 : : }
17737 : : /*
17738 : : * No need to check meter hierarchy for R colors
17739 : : * here since it is done in the validation stage.
17740 : : */
17741 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
17742 : : {
17743 : : const struct rte_flow_action_meter *mtr;
17744 : : struct mlx5_flow_meter_info *next_fm;
17745 : : struct mlx5_flow_meter_policy *next_policy;
17746 : : struct rte_flow_action tag_action;
17747 : : struct mlx5_rte_flow_action_set_tag set_tag;
17748 : 0 : uint32_t next_mtr_idx = 0;
17749 : :
17750 : 0 : mtr = act->conf;
17751 : 0 : next_fm = mlx5_flow_meter_find(priv,
17752 : 0 : mtr->mtr_id,
17753 : : &next_mtr_idx);
17754 [ # # ]: 0 : if (!next_fm)
17755 : 0 : return -rte_mtr_error_set(error, EINVAL,
17756 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
17757 : : "Fail to find next meter.");
17758 [ # # ]: 0 : if (next_fm->def_policy)
17759 : 0 : return -rte_mtr_error_set(error, EINVAL,
17760 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
17761 : : "Hierarchy only supports termination meter.");
17762 : 0 : next_policy = mlx5_flow_meter_policy_find(dev,
17763 : : next_fm->policy_id, NULL);
17764 : : MLX5_ASSERT(next_policy);
17765 [ # # ]: 0 : if (next_fm->drop_cnt) {
17766 : 0 : set_tag.id =
17767 : 0 : (enum modify_reg)
17768 : 0 : mlx5_flow_get_reg_id(dev,
17769 : : MLX5_MTR_ID,
17770 : : 0,
17771 : : (struct rte_flow_error *)error);
17772 : 0 : set_tag.offset = (priv->mtr_reg_share ?
17773 : 0 : MLX5_MTR_COLOR_BITS : 0);
17774 [ # # ]: 0 : set_tag.length = (priv->mtr_reg_share ?
17775 : : MLX5_MTR_IDLE_BITS_IN_COLOR_REG :
17776 : : MLX5_REG_BITS);
17777 : 0 : set_tag.data = next_mtr_idx;
17778 : 0 : tag_action.type =
17779 : : (enum rte_flow_action_type)
17780 : : MLX5_RTE_FLOW_ACTION_TYPE_TAG;
17781 : 0 : tag_action.conf = &set_tag;
17782 [ # # ]: 0 : if (flow_dv_convert_action_set_reg
17783 : : (mhdr_res, &tag_action,
17784 : : (struct rte_flow_error *)error))
17785 : 0 : return -rte_errno;
17786 : 0 : action_flags |=
17787 : : MLX5_FLOW_ACTION_SET_TAG;
17788 : : }
17789 [ # # # # ]: 0 : if (i == RTE_COLOR_YELLOW && next_fm->color_aware &&
17790 [ # # ]: 0 : !next_fm->meter_action_y)
17791 [ # # ]: 0 : if (__flow_dv_create_mtr_yellow_action(dev, next_fm, error))
17792 : 0 : return -rte_errno;
17793 : 0 : act_cnt->fate_action = MLX5_FLOW_FATE_MTR;
17794 : 0 : act_cnt->next_mtr_id = next_fm->meter_id;
17795 : 0 : act_cnt->next_sub_policy = NULL;
17796 : 0 : mtr_policy->is_hierarchy = 1;
17797 [ # # ]: 0 : if (next_policy->mark)
17798 : 0 : mtr_policy->mark = 1;
17799 : 0 : mtr_policy->hierarchy_match_port =
17800 : 0 : next_policy->hierarchy_match_port;
17801 : 0 : action_flags |=
17802 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
17803 : 0 : break;
17804 : : }
17805 : : default:
17806 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
17807 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17808 : : NULL, "action type not supported");
17809 : : }
17810 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_SET_TAG) ||
17811 : : (action_flags & MLX5_FLOW_ACTION_MODIFY_FIELD)) {
17812 : : /* create modify action if needed. */
17813 : 0 : dev_flow.dv.group = 1;
17814 [ # # ]: 0 : if (flow_dv_modify_hdr_resource_register
17815 : : (dev, mhdr_res, &dev_flow, &flow_err))
17816 : 0 : return -rte_mtr_error_set(error,
17817 : : ENOTSUP,
17818 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17819 : : NULL, "cannot register policy set tag/modify field action");
17820 : 0 : act_cnt->modify_hdr =
17821 : 0 : dev_flow.handle->dvh.modify_hdr;
17822 : : }
17823 : : }
17824 : : }
17825 : : return 0;
17826 : : }
17827 : :
17828 : : /**
17829 : : * Create policy action per domain, lock free,
17830 : : * (mutex should be acquired by caller).
17831 : : * Dispatcher for action type specific call.
17832 : : *
17833 : : * @param[in] dev
17834 : : * Pointer to the Ethernet device structure.
17835 : : * @param[in] mtr_policy
17836 : : * Meter policy struct.
17837 : : * @param[in] action
17838 : : * Action specification used to create meter actions.
17839 : : * @param[in] attr
17840 : : * Pointer to the flow attributes.
17841 : : * @param[out] error
17842 : : * Perform verbose error reporting if not NULL. Initialized in case of
17843 : : * error only.
17844 : : *
17845 : : * @return
17846 : : * 0 on success, otherwise negative errno value.
17847 : : */
17848 : : static int
17849 : 0 : flow_dv_create_mtr_policy_acts(struct rte_eth_dev *dev,
17850 : : struct mlx5_flow_meter_policy *mtr_policy,
17851 : : const struct rte_flow_action *actions[RTE_COLORS],
17852 : : struct rte_flow_attr *attr,
17853 : : struct rte_mtr_error *error)
17854 : : {
17855 : : int ret, i;
17856 : : uint16_t sub_policy_num;
17857 : :
17858 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
17859 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
17860 : 0 : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
17861 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
17862 [ # # ]: 0 : if (sub_policy_num) {
17863 : 0 : ret = __flow_dv_create_domain_policy_acts(dev,
17864 : : mtr_policy, actions, attr,
17865 : : (enum mlx5_meter_domain)i, error);
17866 : : /* Cleaning resource is done in the caller level. */
17867 [ # # ]: 0 : if (ret)
17868 : 0 : return ret;
17869 : : }
17870 : : }
17871 : : return 0;
17872 : : }
17873 : :
17874 : : /**
17875 : : * Query a DV flow rule for its statistics via DevX.
17876 : : *
17877 : : * @param[in] dev
17878 : : * Pointer to Ethernet device.
17879 : : * @param[in] cnt_idx
17880 : : * Index to the flow counter.
17881 : : * @param[out] data
17882 : : * Data retrieved by the query.
17883 : : * @param[out] error
17884 : : * Perform verbose error reporting if not NULL.
17885 : : *
17886 : : * @return
17887 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
17888 : : */
17889 : : static int
17890 : 0 : flow_dv_query_count(struct rte_eth_dev *dev, uint32_t cnt_idx, void *data,
17891 : : struct rte_flow_error *error)
17892 : : {
17893 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17894 : : struct rte_flow_query_count *qc = data;
17895 : :
17896 [ # # ]: 0 : if (!priv->sh->cdev->config.devx)
17897 : 0 : return rte_flow_error_set(error, ENOTSUP,
17898 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17899 : : NULL,
17900 : : "counters are not supported");
17901 [ # # ]: 0 : if (cnt_idx) {
17902 : : uint64_t pkts, bytes;
17903 : : struct mlx5_flow_counter *cnt;
17904 : 0 : int err = _flow_dv_query_count(dev, cnt_idx, &pkts, &bytes);
17905 : :
17906 [ # # ]: 0 : if (err)
17907 : 0 : return rte_flow_error_set(error, -err,
17908 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17909 : : NULL, "cannot read counters");
17910 : : cnt = flow_dv_counter_get_by_idx(dev, cnt_idx, NULL);
17911 : 0 : qc->hits_set = 1;
17912 : 0 : qc->bytes_set = 1;
17913 : 0 : qc->hits = pkts - cnt->hits;
17914 : 0 : qc->bytes = bytes - cnt->bytes;
17915 [ # # ]: 0 : if (qc->reset) {
17916 : 0 : cnt->hits = pkts;
17917 : 0 : cnt->bytes = bytes;
17918 : : }
17919 : 0 : return 0;
17920 : : }
17921 : 0 : return rte_flow_error_set(error, EINVAL,
17922 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17923 : : NULL,
17924 : : "counters are not available");
17925 : : }
17926 : :
17927 : : int
17928 : 0 : flow_dv_action_query(struct rte_eth_dev *dev,
17929 : : const struct rte_flow_action_handle *handle, void *data,
17930 : : struct rte_flow_error *error)
17931 : : {
17932 : : struct mlx5_age_param *age_param;
17933 : : struct rte_flow_query_age *resp;
17934 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
17935 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
17936 : 0 : uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
17937 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17938 : : struct mlx5_aso_ct_action *ct;
17939 : : uint16_t owner;
17940 : : uint32_t dev_idx;
17941 : :
17942 [ # # # # ]: 0 : switch (type) {
17943 : 0 : case MLX5_INDIRECT_ACTION_TYPE_AGE:
17944 : 0 : age_param = &flow_aso_age_get_by_idx(dev, idx)->age_params;
17945 : : resp = data;
17946 : 0 : resp->aged = rte_atomic_load_explicit(&age_param->state,
17947 : : rte_memory_order_relaxed) == AGE_TMOUT ?
17948 : 0 : 1 : 0;
17949 : 0 : resp->sec_since_last_hit_valid = !resp->aged;
17950 [ # # ]: 0 : if (resp->sec_since_last_hit_valid)
17951 : 0 : resp->sec_since_last_hit = rte_atomic_load_explicit
17952 : : (&age_param->sec_since_last_hit, rte_memory_order_relaxed);
17953 : : return 0;
17954 : 0 : case MLX5_INDIRECT_ACTION_TYPE_COUNT:
17955 : 0 : return flow_dv_query_count(dev, idx, data, error);
17956 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
17957 : 0 : owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(idx);
17958 [ # # ]: 0 : if (owner != PORT_ID(priv))
17959 : 0 : return rte_flow_error_set(error, EACCES,
17960 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17961 : : NULL,
17962 : : "CT object owned by another port");
17963 : 0 : dev_idx = MLX5_INDIRECT_ACT_CT_GET_IDX(idx);
17964 : 0 : ct = flow_aso_ct_get_by_dev_idx(dev, dev_idx);
17965 : : MLX5_ASSERT(ct);
17966 [ # # ]: 0 : if (!ct->refcnt)
17967 : 0 : return rte_flow_error_set(error, EFAULT,
17968 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17969 : : NULL,
17970 : : "CT object is inactive");
17971 : 0 : ((struct rte_flow_action_conntrack *)data)->peer_port =
17972 : 0 : ct->peer;
17973 : 0 : ((struct rte_flow_action_conntrack *)data)->is_original_dir =
17974 : 0 : ct->is_original;
17975 [ # # ]: 0 : if (mlx5_aso_ct_query_by_wqe(priv->sh, MLX5_HW_INV_QUEUE, ct,
17976 : : data, NULL, true))
17977 : 0 : return rte_flow_error_set(error, EIO,
17978 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17979 : : NULL,
17980 : : "Failed to query CT context");
17981 : : return 0;
17982 : 0 : default:
17983 : 0 : return rte_flow_error_set(error, ENOTSUP,
17984 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
17985 : : "action type query not supported");
17986 : : }
17987 : : }
17988 : :
17989 : : /**
17990 : : * Query a flow rule AGE action for aging information.
17991 : : *
17992 : : * @param[in] dev
17993 : : * Pointer to Ethernet device.
17994 : : * @param[in] flow
17995 : : * Pointer to the sub flow.
17996 : : * @param[out] data
17997 : : * data retrieved by the query.
17998 : : * @param[out] error
17999 : : * Perform verbose error reporting if not NULL.
18000 : : *
18001 : : * @return
18002 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
18003 : : */
18004 : : static int
18005 : 0 : flow_dv_query_age(struct rte_eth_dev *dev, struct rte_flow *flow,
18006 : : void *data, struct rte_flow_error *error)
18007 : : {
18008 : : struct rte_flow_query_age *resp = data;
18009 : : struct mlx5_age_param *age_param;
18010 : :
18011 [ # # ]: 0 : if (flow->age) {
18012 : : struct mlx5_aso_age_action *act =
18013 : 0 : flow_aso_age_get_by_idx(dev, flow->age);
18014 : :
18015 : 0 : age_param = &act->age_params;
18016 [ # # ]: 0 : } else if (flow->counter) {
18017 : : age_param = flow_dv_counter_idx_get_age(dev, flow->counter);
18018 : :
18019 [ # # ]: 0 : if (!age_param || !age_param->timeout)
18020 : 0 : return rte_flow_error_set
18021 : : (error, EINVAL,
18022 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18023 : : NULL, "cannot read age data");
18024 : : } else {
18025 : 0 : return rte_flow_error_set(error, EINVAL,
18026 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18027 : : NULL, "age data not available");
18028 : : }
18029 : 0 : resp->aged = rte_atomic_load_explicit(&age_param->state, rte_memory_order_relaxed) ==
18030 : 0 : AGE_TMOUT ? 1 : 0;
18031 : 0 : resp->sec_since_last_hit_valid = !resp->aged;
18032 [ # # ]: 0 : if (resp->sec_since_last_hit_valid)
18033 : 0 : resp->sec_since_last_hit = rte_atomic_load_explicit
18034 : : (&age_param->sec_since_last_hit, rte_memory_order_relaxed);
18035 : : return 0;
18036 : : }
18037 : :
18038 : : /**
18039 : : * Query a flow.
18040 : : *
18041 : : * @see rte_flow_query()
18042 : : * @see rte_flow_ops
18043 : : */
18044 : : static int
18045 : 0 : flow_dv_query(struct rte_eth_dev *dev,
18046 : : struct rte_flow *flow __rte_unused,
18047 : : const struct rte_flow_action *actions __rte_unused,
18048 : : void *data __rte_unused,
18049 : : struct rte_flow_error *error __rte_unused)
18050 : : {
18051 : : int ret = -EINVAL;
18052 : :
18053 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
18054 [ # # # # ]: 0 : switch (actions->type) {
18055 : : case RTE_FLOW_ACTION_TYPE_VOID:
18056 : : break;
18057 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
18058 : 0 : ret = flow_dv_query_count(dev, flow->counter, data,
18059 : : error);
18060 : 0 : break;
18061 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
18062 : 0 : ret = flow_dv_query_age(dev, flow, data, error);
18063 : 0 : break;
18064 : 0 : default:
18065 : 0 : return rte_flow_error_set(error, ENOTSUP,
18066 : : RTE_FLOW_ERROR_TYPE_ACTION,
18067 : : actions,
18068 : : "action not supported");
18069 : : }
18070 : : }
18071 : : return ret;
18072 : : }
18073 : :
18074 : : /**
18075 : : * Destroy the meter table set.
18076 : : * Lock free, (mutex should be acquired by caller).
18077 : : *
18078 : : * @param[in] dev
18079 : : * Pointer to Ethernet device.
18080 : : * @param[in] fm
18081 : : * Meter information table.
18082 : : */
18083 : : static void
18084 : 0 : flow_dv_destroy_mtr_tbls(struct rte_eth_dev *dev,
18085 : : struct mlx5_flow_meter_info *fm)
18086 : : {
18087 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18088 : : int i;
18089 : :
18090 [ # # # # ]: 0 : if (!fm || !priv->sh->config.dv_flow_en)
18091 : : return;
18092 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
18093 [ # # ]: 0 : if (fm->drop_rule[i]) {
18094 : : claim_zero(mlx5_flow_os_destroy_flow(fm->drop_rule[i]));
18095 : 0 : fm->drop_rule[i] = NULL;
18096 : : }
18097 : : }
18098 : : }
18099 : :
18100 : : static void
18101 : 0 : flow_dv_destroy_mtr_drop_tbls(struct rte_eth_dev *dev)
18102 : : {
18103 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18104 : 0 : struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
18105 : : struct mlx5_flow_tbl_data_entry *tbl;
18106 : : int i, j;
18107 : :
18108 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
18109 [ # # ]: 0 : if (mtrmng->def_rule[i]) {
18110 : : claim_zero(mlx5_flow_os_destroy_flow
18111 : : (mtrmng->def_rule[i]));
18112 : 0 : mtrmng->def_rule[i] = NULL;
18113 : : }
18114 [ # # ]: 0 : if (mtrmng->def_matcher[i]) {
18115 : 0 : tbl = container_of(mtrmng->def_matcher[i]->tbl,
18116 : : struct mlx5_flow_tbl_data_entry, tbl);
18117 : 0 : mlx5_list_unregister(tbl->matchers,
18118 : : &mtrmng->def_matcher[i]->entry);
18119 : 0 : mtrmng->def_matcher[i] = NULL;
18120 : : }
18121 [ # # ]: 0 : for (j = 0; j < MLX5_REG_BITS; j++) {
18122 [ # # ]: 0 : if (mtrmng->drop_matcher[i][j]) {
18123 : : tbl =
18124 : 0 : container_of(mtrmng->drop_matcher[i][j]->tbl,
18125 : : struct mlx5_flow_tbl_data_entry,
18126 : : tbl);
18127 : 0 : mlx5_list_unregister(tbl->matchers,
18128 : : &mtrmng->drop_matcher[i][j]->entry);
18129 : 0 : mtrmng->drop_matcher[i][j] = NULL;
18130 : : }
18131 : : }
18132 [ # # ]: 0 : if (mtrmng->drop_tbl[i]) {
18133 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev),
18134 : : mtrmng->drop_tbl[i]);
18135 : 0 : mtrmng->drop_tbl[i] = NULL;
18136 : : }
18137 : : }
18138 : 0 : }
18139 : :
18140 : : /* Number of meter flow actions, count and jump or count and drop. */
18141 : : #define METER_ACTIONS 2
18142 : :
18143 : : static void
18144 : 0 : __flow_dv_destroy_domain_def_policy(struct rte_eth_dev *dev,
18145 : : enum mlx5_meter_domain domain)
18146 : : {
18147 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18148 : 0 : struct mlx5_flow_meter_def_policy *def_policy =
18149 : 0 : priv->sh->mtrmng->def_policy[domain];
18150 : :
18151 : 0 : __flow_dv_destroy_sub_policy_rules(dev, &def_policy->sub_policy);
18152 : 0 : mlx5_free(def_policy);
18153 : 0 : priv->sh->mtrmng->def_policy[domain] = NULL;
18154 : 0 : }
18155 : :
18156 : : /**
18157 : : * Destroy the default policy table set.
18158 : : *
18159 : : * @param[in] dev
18160 : : * Pointer to Ethernet device.
18161 : : */
18162 : : static void
18163 : 0 : flow_dv_destroy_def_policy(struct rte_eth_dev *dev)
18164 : : {
18165 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18166 : : int i;
18167 : :
18168 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++)
18169 [ # # ]: 0 : if (priv->sh->mtrmng->def_policy[i])
18170 : 0 : __flow_dv_destroy_domain_def_policy(dev,
18171 : : (enum mlx5_meter_domain)i);
18172 : 0 : priv->sh->mtrmng->def_policy_id = MLX5_INVALID_POLICY_ID;
18173 : 0 : }
18174 : :
18175 : : static int
18176 : 0 : __flow_dv_create_policy_flow(struct rte_eth_dev *dev,
18177 : : uint32_t color_reg_c_idx,
18178 : : enum rte_color color, struct mlx5_flow_dv_matcher *matcher,
18179 : : int actions_n, void *actions,
18180 : : bool match_src_port, const struct rte_flow_item *item,
18181 : : void **rule, const struct rte_flow_attr *attr)
18182 : : {
18183 : : int ret;
18184 : 0 : struct mlx5_flow_dv_match_params value = {
18185 : : .size = sizeof(value.buf),
18186 : : };
18187 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18188 : : uint8_t misc_mask;
18189 : :
18190 [ # # # # ]: 0 : if (match_src_port && priv->sh->esw_mode) {
18191 [ # # # # ]: 0 : if (item && item->type == RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT)
18192 : 0 : ret = flow_dv_translate_item_represented_port(dev, value.buf,
18193 : : item, attr, MLX5_SET_MATCHER_SW_V);
18194 [ # # # # ]: 0 : else if (item && item->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR)
18195 : 0 : ret = flow_dv_translate_item_port_representor(dev, value.buf,
18196 : : MLX5_SET_MATCHER_SW_V);
18197 : : else
18198 : 0 : ret = flow_dv_translate_item_port_id(dev, value.buf,
18199 : : item, attr, MLX5_SET_MATCHER_SW_V);
18200 [ # # ]: 0 : if (ret) {
18201 : 0 : DRV_LOG(ERR, "Failed to create meter policy%d flow's"
18202 : : " value with port.", color);
18203 : 0 : return -1;
18204 : : }
18205 : : }
18206 : 0 : flow_dv_match_meta_reg(value.buf, (enum modify_reg)color_reg_c_idx,
18207 : : rte_col_2_mlx5_col(color), UINT32_MAX);
18208 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(matcher->mask.buf);
18209 : : __flow_dv_adjust_buf_size(&value.size, misc_mask);
18210 : 0 : ret = mlx5_flow_os_create_flow(matcher->matcher_object, (void *)&value,
18211 : : actions_n, actions, rule);
18212 : : if (ret) {
18213 : 0 : DRV_LOG(ERR, "Failed to create meter policy%d flow.", color);
18214 : 0 : return -1;
18215 : : }
18216 : : return 0;
18217 : : }
18218 : :
18219 : : static int
18220 : 0 : __flow_dv_create_policy_matcher(struct rte_eth_dev *dev,
18221 : : uint32_t color_reg_c_idx,
18222 : : uint16_t priority,
18223 : : struct mlx5_flow_meter_sub_policy *sub_policy,
18224 : : const struct rte_flow_attr *attr,
18225 : : bool match_src_port,
18226 : : const struct rte_flow_item *item,
18227 : : struct mlx5_flow_dv_matcher **policy_matcher,
18228 : : struct rte_flow_error *error)
18229 : : {
18230 : : struct mlx5_list_entry *entry;
18231 : 0 : struct mlx5_flow_tbl_resource *tbl_rsc = sub_policy->tbl_rsc;
18232 : 0 : struct mlx5_flow_dv_matcher matcher = {
18233 : : .mask = {
18234 : : .size = sizeof(matcher.mask.buf),
18235 : : },
18236 : : .tbl = tbl_rsc,
18237 : : };
18238 : 0 : struct mlx5_flow_cb_ctx ctx = {
18239 : : .error = error,
18240 : : .data = &matcher,
18241 : : };
18242 : : struct mlx5_flow_tbl_data_entry *tbl_data;
18243 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18244 : : const uint32_t color_mask = (UINT32_C(1) << MLX5_MTR_COLOR_BITS) - 1;
18245 : : int ret;
18246 : :
18247 [ # # # # ]: 0 : if (match_src_port && priv->sh->esw_mode) {
18248 [ # # # # ]: 0 : if (item && item->type == RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT)
18249 : 0 : ret = flow_dv_translate_item_represented_port(dev, matcher.mask.buf,
18250 : : item, attr, MLX5_SET_MATCHER_SW_M);
18251 [ # # # # ]: 0 : else if (item && item->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR)
18252 : 0 : ret = flow_dv_translate_item_port_representor(dev, matcher.mask.buf,
18253 : : MLX5_SET_MATCHER_SW_M);
18254 : : else
18255 : 0 : ret = flow_dv_translate_item_port_id(dev, matcher.mask.buf,
18256 : : item, attr, MLX5_SET_MATCHER_SW_M);
18257 [ # # ]: 0 : if (ret) {
18258 : 0 : DRV_LOG(ERR, "Failed to register meter policy%d matcher"
18259 : : " with port.", priority);
18260 : 0 : return -1;
18261 : : }
18262 : : }
18263 : 0 : tbl_data = container_of(tbl_rsc, struct mlx5_flow_tbl_data_entry, tbl);
18264 : 0 : flow_dv_match_meta_reg(matcher.mask.buf,
18265 : : (enum modify_reg)color_reg_c_idx, color_mask, color_mask);
18266 : 0 : matcher.priority = priority;
18267 : 0 : matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
18268 : : matcher.mask.size);
18269 : 0 : entry = mlx5_list_register(tbl_data->matchers, &ctx);
18270 [ # # ]: 0 : if (!entry) {
18271 : 0 : DRV_LOG(ERR, "Failed to register meter drop matcher.");
18272 : 0 : return -1;
18273 : : }
18274 : 0 : *policy_matcher =
18275 : : container_of(entry, struct mlx5_flow_dv_matcher, entry);
18276 : 0 : return 0;
18277 : : }
18278 : :
18279 : : /**
18280 : : * Create the policy rules per domain.
18281 : : *
18282 : : * @param[in] dev
18283 : : * Pointer to Ethernet device.
18284 : : * @param[in] sub_policy
18285 : : * Pointer to sub policy table..
18286 : : * @param[in] egress
18287 : : * Direction of the table.
18288 : : * @param[in] transfer
18289 : : * E-Switch or NIC flow.
18290 : : * @param[in] acts
18291 : : * Pointer to policy action list per color.
18292 : : *
18293 : : * @return
18294 : : * 0 on success, -1 otherwise.
18295 : : */
18296 : : static int
18297 : 0 : __flow_dv_create_domain_policy_rules(struct rte_eth_dev *dev,
18298 : : struct mlx5_flow_meter_sub_policy *sub_policy,
18299 : : uint8_t egress, uint8_t transfer, bool *match_src_port,
18300 : : struct mlx5_meter_policy_acts acts[RTE_COLORS])
18301 : : {
18302 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18303 : : struct rte_flow_error flow_err;
18304 : : uint32_t color_reg_c_idx;
18305 : 0 : struct rte_flow_attr attr = {
18306 : : .group = MLX5_FLOW_TABLE_LEVEL_POLICY,
18307 : : .priority = 0,
18308 : : .ingress = 0,
18309 : 0 : .egress = !!egress,
18310 : 0 : .transfer = !!transfer,
18311 : : .reserved = 0,
18312 : : };
18313 : : int i;
18314 : : uint16_t priority;
18315 : 0 : int ret = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &flow_err);
18316 : : struct mlx5_sub_policy_color_rule *color_rule;
18317 : 0 : struct mlx5_sub_policy_color_rule *tmp_rules[RTE_COLORS] = {NULL};
18318 : :
18319 [ # # ]: 0 : if (ret < 0)
18320 : : return -1;
18321 : : /* Create policy table with POLICY level. */
18322 [ # # ]: 0 : if (!sub_policy->tbl_rsc)
18323 : 0 : sub_policy->tbl_rsc = flow_dv_tbl_resource_get(dev,
18324 : : MLX5_FLOW_TABLE_LEVEL_POLICY,
18325 : : egress, transfer, false, NULL, 0, 0,
18326 : 0 : sub_policy->idx, &flow_err);
18327 [ # # ]: 0 : if (!sub_policy->tbl_rsc) {
18328 : 0 : DRV_LOG(ERR,
18329 : : "Failed to create meter sub policy table.");
18330 : 0 : return -1;
18331 : : }
18332 : : /* Prepare matchers. */
18333 : 0 : color_reg_c_idx = ret;
18334 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
18335 : 0 : TAILQ_INIT(&sub_policy->color_rules[i]);
18336 [ # # ]: 0 : if (!acts[i].actions_n)
18337 : 0 : continue;
18338 : 0 : color_rule = mlx5_malloc(MLX5_MEM_ZERO,
18339 : : sizeof(struct mlx5_sub_policy_color_rule),
18340 : : 0, SOCKET_ID_ANY);
18341 [ # # ]: 0 : if (!color_rule) {
18342 : 0 : DRV_LOG(ERR, "No memory to create color rule.");
18343 : 0 : goto err_exit;
18344 : : }
18345 : 0 : tmp_rules[i] = color_rule;
18346 : 0 : TAILQ_INSERT_TAIL(&sub_policy->color_rules[i],
18347 : : color_rule, next_port);
18348 : 0 : color_rule->src_port = priv->representor_id;
18349 : 0 : priority = (match_src_port[i] == match_src_port[RTE_COLOR_GREEN]) ?
18350 : 0 : MLX5_MTR_POLICY_MATCHER_PRIO : (MLX5_MTR_POLICY_MATCHER_PRIO + 1);
18351 : : /* Create matchers for colors. */
18352 [ # # ]: 0 : if (__flow_dv_create_policy_matcher(dev, color_reg_c_idx,
18353 : : priority, sub_policy,
18354 : : &attr, match_src_port[i], NULL,
18355 : : &color_rule->matcher, &flow_err)) {
18356 : 0 : DRV_LOG(ERR, "Failed to create color%u matcher.", i);
18357 : 0 : goto err_exit;
18358 : : }
18359 : : /* Create flow, matching color. */
18360 [ # # ]: 0 : if (__flow_dv_create_policy_flow(dev,
18361 : : color_reg_c_idx, (enum rte_color)i,
18362 : : color_rule->matcher,
18363 : 0 : acts[i].actions_n, acts[i].dv_actions,
18364 : 0 : match_src_port[i], NULL, &color_rule->rule,
18365 : : &attr)) {
18366 : 0 : DRV_LOG(ERR, "Failed to create color%u rule.", i);
18367 : 0 : goto err_exit;
18368 : : }
18369 : : }
18370 : : return 0;
18371 : : err_exit:
18372 : : /* All the policy rules will be cleared. */
18373 : : do {
18374 : 0 : color_rule = tmp_rules[i];
18375 [ # # ]: 0 : if (color_rule) {
18376 [ # # ]: 0 : if (color_rule->rule)
18377 : : mlx5_flow_os_destroy_flow(color_rule->rule);
18378 [ # # ]: 0 : if (color_rule->matcher) {
18379 : : struct mlx5_flow_tbl_data_entry *tbl =
18380 : 0 : container_of(color_rule->matcher->tbl,
18381 : : typeof(*tbl), tbl);
18382 : 0 : mlx5_list_unregister(tbl->matchers,
18383 : : &color_rule->matcher->entry);
18384 : : }
18385 [ # # ]: 0 : TAILQ_REMOVE(&sub_policy->color_rules[i],
18386 : : color_rule, next_port);
18387 : 0 : mlx5_free(color_rule);
18388 : : }
18389 [ # # ]: 0 : } while (i--);
18390 : : return -1;
18391 : : }
18392 : :
18393 : : static int
18394 : 0 : __flow_dv_create_policy_acts_rules(struct rte_eth_dev *dev,
18395 : : struct mlx5_flow_meter_policy *mtr_policy,
18396 : : struct mlx5_flow_meter_sub_policy *sub_policy,
18397 : : uint32_t domain)
18398 : : {
18399 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18400 : : struct mlx5_meter_policy_acts acts[RTE_COLORS];
18401 : : struct mlx5_flow_dv_tag_resource *tag;
18402 : : struct mlx5_flow_dv_port_id_action_resource *port_action;
18403 : : struct mlx5_hrxq *hrxq;
18404 : 0 : struct mlx5_flow_meter_info *next_fm[RTE_COLORS] = {NULL};
18405 : : struct mlx5_flow_meter_policy *next_policy;
18406 : : struct mlx5_flow_meter_sub_policy *next_sub_policy;
18407 : : struct mlx5_flow_tbl_data_entry *tbl_data;
18408 : : struct rte_flow_error error;
18409 : 0 : uint8_t egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
18410 : 0 : uint8_t transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
18411 [ # # # # : 0 : bool mtr_first = egress || (transfer && priv->representor_id != UINT16_MAX);
# # ]
18412 : 0 : bool match_src_port[RTE_COLORS] = {false};
18413 : : int i;
18414 : :
18415 : : /* If RSS or Queue, no previous actions / rules is created. */
18416 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
18417 : 0 : acts[i].actions_n = 0;
18418 [ # # ]: 0 : if (i == RTE_COLOR_RED) {
18419 : : /* Only support drop on red. */
18420 : 0 : acts[i].dv_actions[0] =
18421 : 0 : mtr_policy->dr_drop_action[domain];
18422 : 0 : acts[i].actions_n = 1;
18423 : 0 : continue;
18424 : : }
18425 [ # # ]: 0 : if (mtr_policy->act_cnt[i].fate_action == MLX5_FLOW_FATE_MTR) {
18426 : 0 : struct rte_flow_attr attr = {
18427 : : .transfer = transfer
18428 : : };
18429 : :
18430 : 0 : next_fm[i] = mlx5_flow_meter_find(priv,
18431 : : mtr_policy->act_cnt[i].next_mtr_id,
18432 : : NULL);
18433 [ # # ]: 0 : if (!next_fm[i]) {
18434 : 0 : DRV_LOG(ERR,
18435 : : "Failed to get next hierarchy meter.");
18436 : 0 : goto err_exit;
18437 : : }
18438 [ # # ]: 0 : if (mlx5_flow_meter_attach(priv, next_fm[i],
18439 : : &attr, &error)) {
18440 : 0 : DRV_LOG(ERR, "%s", error.message);
18441 : 0 : next_fm[i] = NULL;
18442 : 0 : goto err_exit;
18443 : : }
18444 : : /* Meter action must be the first for TX. */
18445 [ # # ]: 0 : if (mtr_first) {
18446 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18447 [ # # ]: 0 : (next_fm[i]->color_aware && i == RTE_COLOR_YELLOW) ?
18448 [ # # ]: 0 : next_fm[i]->meter_action_y :
18449 : : next_fm[i]->meter_action_g;
18450 : 0 : acts[i].actions_n++;
18451 : : }
18452 : : }
18453 [ # # ]: 0 : if (mtr_policy->act_cnt[i].rix_mark) {
18454 : 0 : tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG],
18455 : : mtr_policy->act_cnt[i].rix_mark);
18456 [ # # ]: 0 : if (!tag) {
18457 : 0 : DRV_LOG(ERR, "Failed to find "
18458 : : "mark action for policy.");
18459 : 0 : goto err_exit;
18460 : : }
18461 : 0 : acts[i].dv_actions[acts[i].actions_n] = tag->action;
18462 : 0 : acts[i].actions_n++;
18463 : : }
18464 [ # # ]: 0 : if (mtr_policy->act_cnt[i].modify_hdr) {
18465 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18466 : 0 : mtr_policy->act_cnt[i].modify_hdr->action;
18467 : 0 : acts[i].actions_n++;
18468 : : }
18469 [ # # ]: 0 : if (mtr_policy->act_cnt[i].fate_action) {
18470 [ # # # # : 0 : switch (mtr_policy->act_cnt[i].fate_action) {
# ]
18471 : 0 : case MLX5_FLOW_FATE_PORT_ID:
18472 : 0 : port_action = mlx5_ipool_get
18473 : 0 : (priv->sh->ipool[MLX5_IPOOL_PORT_ID],
18474 : : mtr_policy->act_cnt[i].rix_port_id_action);
18475 [ # # ]: 0 : if (!port_action) {
18476 : 0 : DRV_LOG(ERR, "Failed to find "
18477 : : "port action for policy.");
18478 : 0 : goto err_exit;
18479 : : }
18480 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18481 : 0 : port_action->action;
18482 : 0 : acts[i].actions_n++;
18483 : 0 : match_src_port[i] = true;
18484 : 0 : break;
18485 : 0 : case MLX5_FLOW_FATE_DROP:
18486 : : case MLX5_FLOW_FATE_JUMP:
18487 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18488 : 0 : mtr_policy->act_cnt[i].dr_jump_action[domain];
18489 : 0 : acts[i].actions_n++;
18490 : 0 : break;
18491 : 0 : case MLX5_FLOW_FATE_SHARED_RSS:
18492 : : case MLX5_FLOW_FATE_QUEUE:
18493 : 0 : hrxq = mlx5_ipool_get
18494 : 0 : (priv->sh->ipool[MLX5_IPOOL_HRXQ],
18495 : : sub_policy->rix_hrxq[i]);
18496 [ # # ]: 0 : if (!hrxq) {
18497 : 0 : DRV_LOG(ERR, "Failed to find "
18498 : : "queue action for policy.");
18499 : 0 : goto err_exit;
18500 : : }
18501 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18502 : 0 : hrxq->action;
18503 : 0 : acts[i].actions_n++;
18504 : 0 : break;
18505 : 0 : case MLX5_FLOW_FATE_MTR:
18506 [ # # ]: 0 : if (!next_fm[i]) {
18507 : 0 : DRV_LOG(ERR,
18508 : : "No next hierarchy meter.");
18509 : 0 : goto err_exit;
18510 : : }
18511 [ # # ]: 0 : if (!mtr_first) {
18512 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18513 [ # # ]: 0 : (next_fm[i]->color_aware && i == RTE_COLOR_YELLOW) ?
18514 [ # # ]: 0 : next_fm[i]->meter_action_y :
18515 : : next_fm[i]->meter_action_g;
18516 : 0 : acts[i].actions_n++;
18517 : : }
18518 [ # # ]: 0 : if (mtr_policy->act_cnt[i].next_sub_policy) {
18519 : : next_sub_policy =
18520 : : mtr_policy->act_cnt[i].next_sub_policy;
18521 : : } else {
18522 : : next_policy =
18523 : 0 : mlx5_flow_meter_policy_find(dev,
18524 : : next_fm[i]->policy_id, NULL);
18525 : : MLX5_ASSERT(next_policy);
18526 : 0 : next_sub_policy =
18527 : 0 : next_policy->sub_policys[domain][0];
18528 : : }
18529 : : tbl_data =
18530 : 0 : container_of(next_sub_policy->tbl_rsc,
18531 : : struct mlx5_flow_tbl_data_entry, tbl);
18532 : 0 : acts[i].dv_actions[acts[i].actions_n++] =
18533 : 0 : tbl_data->jump.action;
18534 [ # # ]: 0 : if (mtr_policy->act_cnt[i].modify_hdr)
18535 : 0 : match_src_port[i] = !!transfer;
18536 : : break;
18537 : : default:
18538 : : /*Queue action do nothing*/
18539 : : break;
18540 : : }
18541 : : }
18542 : : }
18543 [ # # ]: 0 : if (__flow_dv_create_domain_policy_rules(dev, sub_policy,
18544 : : egress, transfer, match_src_port, acts)) {
18545 : 0 : DRV_LOG(ERR,
18546 : : "Failed to create policy rules per domain.");
18547 : 0 : goto err_exit;
18548 : : }
18549 [ # # # # ]: 0 : if (match_src_port[RTE_COLOR_GREEN] || match_src_port[RTE_COLOR_YELLOW]) {
18550 : 0 : mtr_policy->match_port = 1;
18551 : 0 : mtr_policy->hierarchy_match_port = 1;
18552 : : }
18553 : : return 0;
18554 : : err_exit:
18555 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++)
18556 [ # # ]: 0 : if (next_fm[i])
18557 : 0 : mlx5_flow_meter_detach(priv, next_fm[i]);
18558 : : return -1;
18559 : : }
18560 : :
18561 : : /**
18562 : : * Create the policy rules.
18563 : : *
18564 : : * @param[in] dev
18565 : : * Pointer to Ethernet device.
18566 : : * @param[in,out] mtr_policy
18567 : : * Pointer to meter policy table.
18568 : : *
18569 : : * @return
18570 : : * 0 on success, -1 otherwise.
18571 : : */
18572 : : static int
18573 : 0 : flow_dv_create_policy_rules(struct rte_eth_dev *dev,
18574 : : struct mlx5_flow_meter_policy *mtr_policy)
18575 : : {
18576 : : int i;
18577 : : int ret = 0;
18578 : : uint16_t sub_policy_num;
18579 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_push_thread_workspace();
18580 : :
18581 : : RTE_SET_USED(wks);
18582 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
18583 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
18584 : 0 : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
18585 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
18586 [ # # ]: 0 : if (!sub_policy_num)
18587 : 0 : continue;
18588 : : /* Prepare actions list and create policy rules. */
18589 [ # # ]: 0 : if (__flow_dv_create_policy_acts_rules(dev, mtr_policy,
18590 : 0 : mtr_policy->sub_policys[i][0], i)) {
18591 : 0 : DRV_LOG(ERR, "Failed to create policy action "
18592 : : "list per domain.");
18593 : : ret = -1;
18594 : 0 : goto exit;
18595 : : }
18596 : : }
18597 : 0 : exit:
18598 : 0 : mlx5_flow_pop_thread_workspace();
18599 : 0 : return ret;
18600 : : }
18601 : :
18602 : : static int
18603 : 0 : __flow_dv_create_domain_def_policy(struct rte_eth_dev *dev, uint32_t domain)
18604 : : {
18605 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18606 : 0 : struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
18607 : : struct mlx5_flow_meter_def_policy *def_policy;
18608 : : struct mlx5_flow_tbl_resource *jump_tbl;
18609 : : struct mlx5_flow_tbl_data_entry *tbl_data;
18610 : : uint8_t egress, transfer;
18611 : : struct rte_flow_error error;
18612 : : struct mlx5_meter_policy_acts acts[RTE_COLORS];
18613 : 0 : bool match_src_port[RTE_COLORS] = {false};
18614 : : int ret;
18615 : :
18616 : 0 : egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
18617 : 0 : transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
18618 : 0 : def_policy = mtrmng->def_policy[domain];
18619 [ # # ]: 0 : if (!def_policy) {
18620 : 0 : def_policy = mlx5_malloc(MLX5_MEM_ZERO,
18621 : : sizeof(struct mlx5_flow_meter_def_policy),
18622 : : RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
18623 [ # # ]: 0 : if (!def_policy) {
18624 : 0 : DRV_LOG(ERR, "Failed to alloc default policy table.");
18625 : 0 : goto def_policy_error;
18626 : : }
18627 : 0 : mtrmng->def_policy[domain] = def_policy;
18628 : : /* Create the meter suffix table with SUFFIX level. */
18629 : 0 : jump_tbl = flow_dv_tbl_resource_get(dev,
18630 : : MLX5_FLOW_TABLE_LEVEL_METER,
18631 : : egress, transfer, false, NULL, 0,
18632 : : 0, MLX5_MTR_TABLE_ID_SUFFIX, &error);
18633 [ # # ]: 0 : if (!jump_tbl) {
18634 : 0 : DRV_LOG(ERR,
18635 : : "Failed to create meter suffix table.");
18636 : 0 : goto def_policy_error;
18637 : : }
18638 : 0 : def_policy->sub_policy.jump_tbl[RTE_COLOR_GREEN] = jump_tbl;
18639 : 0 : tbl_data = container_of(jump_tbl,
18640 : : struct mlx5_flow_tbl_data_entry, tbl);
18641 : 0 : def_policy->dr_jump_action[RTE_COLOR_GREEN] =
18642 : 0 : tbl_data->jump.action;
18643 : 0 : acts[RTE_COLOR_GREEN].dv_actions[0] = tbl_data->jump.action;
18644 : 0 : acts[RTE_COLOR_GREEN].actions_n = 1;
18645 : : /*
18646 : : * YELLOW has the same default policy as GREEN does.
18647 : : * G & Y share the same table and action. The 2nd time of table
18648 : : * resource getting is just to update the reference count for
18649 : : * the releasing stage.
18650 : : */
18651 : 0 : jump_tbl = flow_dv_tbl_resource_get(dev,
18652 : : MLX5_FLOW_TABLE_LEVEL_METER,
18653 : : egress, transfer, false, NULL, 0,
18654 : : 0, MLX5_MTR_TABLE_ID_SUFFIX, &error);
18655 [ # # ]: 0 : if (!jump_tbl) {
18656 : 0 : DRV_LOG(ERR,
18657 : : "Failed to get meter suffix table.");
18658 : 0 : goto def_policy_error;
18659 : : }
18660 : 0 : def_policy->sub_policy.jump_tbl[RTE_COLOR_YELLOW] = jump_tbl;
18661 : 0 : tbl_data = container_of(jump_tbl,
18662 : : struct mlx5_flow_tbl_data_entry, tbl);
18663 : 0 : def_policy->dr_jump_action[RTE_COLOR_YELLOW] =
18664 : 0 : tbl_data->jump.action;
18665 : 0 : acts[RTE_COLOR_YELLOW].dv_actions[0] = tbl_data->jump.action;
18666 : 0 : acts[RTE_COLOR_YELLOW].actions_n = 1;
18667 : : /* Create jump action to the drop table. */
18668 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
18669 : 0 : mtrmng->drop_tbl[domain] = flow_dv_tbl_resource_get
18670 : : (dev, MLX5_FLOW_TABLE_LEVEL_METER,
18671 : : egress, transfer, false, NULL, 0,
18672 : : 0, MLX5_MTR_TABLE_ID_DROP, &error);
18673 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
18674 : 0 : DRV_LOG(ERR, "Failed to create meter "
18675 : : "drop table for default policy.");
18676 : 0 : goto def_policy_error;
18677 : : }
18678 : : }
18679 : : /* all RED: unique Drop table for jump action. */
18680 : 0 : tbl_data = container_of(mtrmng->drop_tbl[domain],
18681 : : struct mlx5_flow_tbl_data_entry, tbl);
18682 : 0 : def_policy->dr_jump_action[RTE_COLOR_RED] =
18683 : 0 : tbl_data->jump.action;
18684 : 0 : acts[RTE_COLOR_RED].dv_actions[0] = tbl_data->jump.action;
18685 : 0 : acts[RTE_COLOR_RED].actions_n = 1;
18686 : : /* Create default policy rules. */
18687 : 0 : ret = __flow_dv_create_domain_policy_rules(dev,
18688 : : &def_policy->sub_policy,
18689 : : egress, transfer, match_src_port, acts);
18690 [ # # ]: 0 : if (ret) {
18691 : 0 : DRV_LOG(ERR, "Failed to create default policy rules.");
18692 : 0 : goto def_policy_error;
18693 : : }
18694 : : }
18695 : : return 0;
18696 : 0 : def_policy_error:
18697 : 0 : __flow_dv_destroy_domain_def_policy(dev,
18698 : : (enum mlx5_meter_domain)domain);
18699 : 0 : return -1;
18700 : : }
18701 : :
18702 : : /**
18703 : : * Create the default policy table set.
18704 : : *
18705 : : * @param[in] dev
18706 : : * Pointer to Ethernet device.
18707 : : * @return
18708 : : * 0 on success, -1 otherwise.
18709 : : */
18710 : : static int
18711 : 0 : flow_dv_create_def_policy(struct rte_eth_dev *dev)
18712 : : {
18713 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18714 : : int i;
18715 : :
18716 : : /* Non-termination policy table. */
18717 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
18718 [ # # # # ]: 0 : if (!priv->sh->config.dv_esw_en &&
18719 : : i == MLX5_MTR_DOMAIN_TRANSFER)
18720 : 0 : continue;
18721 [ # # ]: 0 : if (__flow_dv_create_domain_def_policy(dev, i)) {
18722 : 0 : DRV_LOG(ERR, "Failed to create default policy");
18723 : : /* Rollback the created default policies for others. */
18724 : 0 : flow_dv_destroy_def_policy(dev);
18725 : 0 : return -1;
18726 : : }
18727 : : }
18728 : : return 0;
18729 : : }
18730 : :
18731 : : /**
18732 : : * Create the needed meter tables.
18733 : : * Lock free, (mutex should be acquired by caller).
18734 : : *
18735 : : * @param[in] dev
18736 : : * Pointer to Ethernet device.
18737 : : * @param[in] fm
18738 : : * Meter information table.
18739 : : * @param[in] mtr_idx
18740 : : * Meter index.
18741 : : * @param[in] domain_bitmap
18742 : : * Domain bitmap.
18743 : : * @return
18744 : : * 0 on success, -1 otherwise.
18745 : : */
18746 : : static int
18747 : 0 : flow_dv_create_mtr_tbls(struct rte_eth_dev *dev,
18748 : : struct mlx5_flow_meter_info *fm,
18749 : : uint32_t mtr_idx,
18750 : : uint8_t domain_bitmap)
18751 : : {
18752 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18753 : 0 : struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
18754 : : struct rte_flow_error error;
18755 : : struct mlx5_flow_tbl_data_entry *tbl_data;
18756 : : uint8_t egress, transfer;
18757 : : void *actions[METER_ACTIONS];
18758 : : int domain, ret, i;
18759 : : struct mlx5_flow_counter *cnt;
18760 : 0 : struct mlx5_flow_dv_match_params value = {
18761 : : .size = sizeof(value.buf),
18762 : : };
18763 : 0 : struct mlx5_flow_dv_match_params matcher_para = {
18764 : : .size = sizeof(matcher_para.buf),
18765 : : };
18766 : 0 : int mtr_id_reg_c = mlx5_flow_get_reg_id(dev, MLX5_MTR_ID,
18767 : : 0, &error);
18768 : 0 : uint32_t mtr_id_mask = (UINT32_C(1) << mtrmng->max_mtr_bits) - 1;
18769 : 0 : uint8_t mtr_id_offset = priv->mtr_reg_share ? MLX5_MTR_COLOR_BITS : 0;
18770 : : struct mlx5_list_entry *entry;
18771 : 0 : struct mlx5_flow_dv_matcher matcher = {
18772 : : .mask = {
18773 : : .size = sizeof(matcher.mask.buf),
18774 : : },
18775 : : };
18776 : : struct mlx5_flow_dv_matcher *drop_matcher;
18777 : 0 : struct mlx5_flow_cb_ctx ctx = {
18778 : : .error = &error,
18779 : : .data = &matcher,
18780 : : };
18781 : : uint8_t misc_mask;
18782 : :
18783 [ # # # # ]: 0 : if (!priv->mtr_en || mtr_id_reg_c < 0) {
18784 : 0 : rte_errno = ENOTSUP;
18785 : 0 : return -1;
18786 : : }
18787 [ # # ]: 0 : for (domain = 0; domain < MLX5_MTR_DOMAIN_MAX; domain++) {
18788 [ # # ]: 0 : if (!(domain_bitmap & (1 << domain)) ||
18789 [ # # # # ]: 0 : (mtrmng->def_rule[domain] && !fm->drop_cnt))
18790 : 0 : continue;
18791 : 0 : egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
18792 : 0 : transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
18793 : : /* Create the drop table with METER DROP level. */
18794 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
18795 : 0 : mtrmng->drop_tbl[domain] = flow_dv_tbl_resource_get(dev,
18796 : : MLX5_FLOW_TABLE_LEVEL_METER,
18797 : : egress, transfer, false, NULL, 0,
18798 : : 0, MLX5_MTR_TABLE_ID_DROP, &error);
18799 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
18800 : 0 : DRV_LOG(ERR, "Failed to create meter drop table.");
18801 : 0 : goto policy_error;
18802 : : }
18803 : : }
18804 : : /* Create default matcher in drop table. */
18805 : 0 : matcher.tbl = mtrmng->drop_tbl[domain],
18806 : 0 : tbl_data = container_of(mtrmng->drop_tbl[domain],
18807 : : struct mlx5_flow_tbl_data_entry, tbl);
18808 [ # # ]: 0 : if (!mtrmng->def_matcher[domain]) {
18809 : 0 : flow_dv_match_meta_reg_all(matcher.mask.buf, value.buf,
18810 : : (enum modify_reg)mtr_id_reg_c,
18811 : : 0, 0);
18812 : 0 : matcher.priority = MLX5_MTRS_DEFAULT_RULE_PRIORITY;
18813 : 0 : matcher.crc = rte_raw_cksum
18814 : : ((const void *)matcher.mask.buf,
18815 : : matcher.mask.size);
18816 : 0 : entry = mlx5_list_register(tbl_data->matchers, &ctx);
18817 [ # # ]: 0 : if (!entry) {
18818 : 0 : DRV_LOG(ERR, "Failed to register meter "
18819 : : "drop default matcher.");
18820 : 0 : goto policy_error;
18821 : : }
18822 : 0 : mtrmng->def_matcher[domain] = container_of(entry,
18823 : : struct mlx5_flow_dv_matcher, entry);
18824 : : }
18825 : : /* Create default rule in drop table. */
18826 [ # # ]: 0 : if (!mtrmng->def_rule[domain]) {
18827 : : i = 0;
18828 : 0 : actions[i++] = priv->sh->dr_drop_action;
18829 : 0 : flow_dv_match_meta_reg_all(matcher_para.buf, value.buf,
18830 : : (enum modify_reg)mtr_id_reg_c, 0, 0);
18831 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(mtrmng->def_matcher[domain]->mask.buf);
18832 : : __flow_dv_adjust_buf_size(&value.size, misc_mask);
18833 : 0 : ret = mlx5_flow_os_create_flow
18834 : : (mtrmng->def_matcher[domain]->matcher_object,
18835 : : (void *)&value, i, actions,
18836 : : &mtrmng->def_rule[domain]);
18837 : : if (ret) {
18838 : 0 : DRV_LOG(ERR, "Failed to create meter "
18839 : : "default drop rule for drop table.");
18840 : 0 : goto policy_error;
18841 : : }
18842 : : }
18843 [ # # ]: 0 : if (!fm->drop_cnt)
18844 : 0 : continue;
18845 : : MLX5_ASSERT(mtrmng->max_mtr_bits);
18846 [ # # ]: 0 : if (!mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1]) {
18847 : : /* Create matchers for Drop. */
18848 : 0 : flow_dv_match_meta_reg_all(matcher.mask.buf, value.buf,
18849 : : (enum modify_reg)mtr_id_reg_c, 0,
18850 : : (mtr_id_mask << mtr_id_offset));
18851 : 0 : matcher.priority = MLX5_REG_BITS - mtrmng->max_mtr_bits;
18852 : 0 : matcher.crc = rte_raw_cksum
18853 : : ((const void *)matcher.mask.buf,
18854 : : matcher.mask.size);
18855 : 0 : entry = mlx5_list_register(tbl_data->matchers, &ctx);
18856 [ # # ]: 0 : if (!entry) {
18857 : 0 : DRV_LOG(ERR,
18858 : : "Failed to register meter drop matcher.");
18859 : 0 : goto policy_error;
18860 : : }
18861 : 0 : mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1] =
18862 : : container_of(entry, struct mlx5_flow_dv_matcher,
18863 : : entry);
18864 : : }
18865 : 0 : drop_matcher =
18866 : 0 : mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1];
18867 : : /* Create drop rule, matching meter_id only. */
18868 : 0 : flow_dv_match_meta_reg_all(matcher_para.buf, value.buf,
18869 : : (enum modify_reg)mtr_id_reg_c,
18870 : : (mtr_idx << mtr_id_offset), UINT32_MAX);
18871 : : i = 0;
18872 [ # # ]: 0 : cnt = flow_dv_counter_get_by_idx(dev,
18873 : : fm->drop_cnt, NULL);
18874 : 0 : actions[i++] = cnt->action;
18875 : 0 : actions[i++] = priv->sh->dr_drop_action;
18876 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(drop_matcher->mask.buf);
18877 : : __flow_dv_adjust_buf_size(&value.size, misc_mask);
18878 : 0 : ret = mlx5_flow_os_create_flow(drop_matcher->matcher_object,
18879 : : (void *)&value, i, actions,
18880 : : &fm->drop_rule[domain]);
18881 : : if (ret) {
18882 : 0 : DRV_LOG(ERR, "Failed to create meter "
18883 : : "drop rule for drop table.");
18884 : 0 : goto policy_error;
18885 : : }
18886 : : }
18887 : : return 0;
18888 : : policy_error:
18889 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
18890 [ # # ]: 0 : if (fm->drop_rule[i]) {
18891 : : claim_zero(mlx5_flow_os_destroy_flow
18892 : : (fm->drop_rule[i]));
18893 : 0 : fm->drop_rule[i] = NULL;
18894 : : }
18895 : : }
18896 : : return -1;
18897 : : }
18898 : :
18899 : : static struct mlx5_flow_meter_sub_policy *
18900 : 0 : __flow_dv_meter_get_rss_sub_policy(struct rte_eth_dev *dev,
18901 : : struct mlx5_flow_meter_policy *mtr_policy,
18902 : : struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS],
18903 : : struct mlx5_flow_meter_sub_policy *next_sub_policy,
18904 : : bool *is_reuse)
18905 : : {
18906 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18907 : : struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
18908 : 0 : uint32_t sub_policy_idx = 0;
18909 : 0 : uint32_t hrxq_idx[MLX5_MTR_RTE_COLORS] = {0};
18910 : : uint32_t i, j;
18911 : : struct mlx5_hrxq *hrxq;
18912 : : struct mlx5_flow_handle dh;
18913 : : struct mlx5_meter_policy_action_container *act_cnt;
18914 : : uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
18915 : : uint16_t sub_policy_num;
18916 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
18917 : :
18918 : : MLX5_ASSERT(wks);
18919 : 0 : rte_spinlock_lock(&mtr_policy->sl);
18920 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
18921 [ # # ]: 0 : if (!rss_desc[i])
18922 : 0 : continue;
18923 : 0 : hrxq = mlx5_hrxq_get(dev, rss_desc[i]);
18924 [ # # ]: 0 : if (!hrxq) {
18925 : : rte_spinlock_unlock(&mtr_policy->sl);
18926 : 0 : return NULL;
18927 : : }
18928 : 0 : hrxq_idx[i] = hrxq->idx;
18929 : : }
18930 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
18931 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
18932 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
18933 [ # # ]: 0 : for (j = 0; j < sub_policy_num; j++) {
18934 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
18935 [ # # ]: 0 : if (rss_desc[i] &&
18936 : 0 : hrxq_idx[i] !=
18937 [ # # ]: 0 : mtr_policy->sub_policys[domain][j]->rix_hrxq[i])
18938 : : break;
18939 : : }
18940 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS) {
18941 : : /*
18942 : : * Found the sub policy table with
18943 : : * the same queue per color.
18944 : : */
18945 : : rte_spinlock_unlock(&mtr_policy->sl);
18946 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++)
18947 : 0 : mlx5_hrxq_release(dev, hrxq_idx[i]);
18948 : 0 : *is_reuse = true;
18949 : 0 : return mtr_policy->sub_policys[domain][j];
18950 : : }
18951 : : }
18952 : : /* Create sub policy. */
18953 [ # # ]: 0 : if (!mtr_policy->sub_policys[domain][0]->rix_hrxq[RTE_COLOR_GREEN] &&
18954 : : !mtr_policy->sub_policys[domain][0]->rix_hrxq[RTE_COLOR_YELLOW]) {
18955 : : /* Reuse the first pre-allocated sub_policy. */
18956 : : sub_policy = mtr_policy->sub_policys[domain][0];
18957 : 0 : sub_policy_idx = sub_policy->idx;
18958 : : } else {
18959 : 0 : sub_policy = mlx5_ipool_zmalloc
18960 : 0 : (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
18961 : : &sub_policy_idx);
18962 [ # # ]: 0 : if (!sub_policy ||
18963 [ # # ]: 0 : sub_policy_idx > MLX5_MAX_SUB_POLICY_TBL_NUM) {
18964 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++)
18965 : 0 : mlx5_hrxq_release(dev, hrxq_idx[i]);
18966 : 0 : goto rss_sub_policy_error;
18967 : : }
18968 : 0 : sub_policy->idx = sub_policy_idx;
18969 : 0 : sub_policy->main_policy = mtr_policy;
18970 : : }
18971 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
18972 [ # # ]: 0 : if (!rss_desc[i])
18973 : 0 : continue;
18974 : 0 : sub_policy->rix_hrxq[i] = hrxq_idx[i];
18975 [ # # ]: 0 : if (mtr_policy->is_hierarchy) {
18976 : : act_cnt = &mtr_policy->act_cnt[i];
18977 : 0 : act_cnt->next_sub_policy = next_sub_policy;
18978 : 0 : mlx5_hrxq_release(dev, hrxq_idx[i]);
18979 : : } else {
18980 : : /*
18981 : : * Overwrite the last action from
18982 : : * RSS action to Queue action.
18983 : : */
18984 : 0 : hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
18985 : : hrxq_idx[i]);
18986 [ # # ]: 0 : if (!hrxq) {
18987 : 0 : DRV_LOG(ERR, "Failed to get policy hrxq");
18988 : 0 : goto rss_sub_policy_error;
18989 : : }
18990 : : act_cnt = &mtr_policy->act_cnt[i];
18991 [ # # # # ]: 0 : if (act_cnt->rix_mark || act_cnt->modify_hdr) {
18992 : : memset(&dh, 0, sizeof(struct mlx5_flow_handle));
18993 [ # # ]: 0 : if (act_cnt->rix_mark)
18994 : 0 : wks->mark = 1;
18995 : 0 : dh.fate_action = MLX5_FLOW_FATE_QUEUE;
18996 : 0 : dh.rix_hrxq = hrxq_idx[i];
18997 : 0 : flow_drv_rxq_flags_set(dev, &dh);
18998 : : }
18999 : : }
19000 : : }
19001 [ # # ]: 0 : if (__flow_dv_create_policy_acts_rules(dev, mtr_policy,
19002 : : sub_policy, domain)) {
19003 : 0 : DRV_LOG(ERR, "Failed to create policy "
19004 : : "rules for ingress domain.");
19005 : 0 : goto rss_sub_policy_error;
19006 : : }
19007 [ # # ]: 0 : if (sub_policy != mtr_policy->sub_policys[domain][0]) {
19008 : 0 : i = (mtr_policy->sub_policy_num >>
19009 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
19010 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
19011 [ # # ]: 0 : if (i >= MLX5_MTR_RSS_MAX_SUB_POLICY) {
19012 : 0 : DRV_LOG(ERR, "No free sub-policy slot.");
19013 : 0 : goto rss_sub_policy_error;
19014 : : }
19015 : 0 : mtr_policy->sub_policys[domain][i] = sub_policy;
19016 : 0 : i++;
19017 : 0 : mtr_policy->sub_policy_num &= ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
19018 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain));
19019 : 0 : mtr_policy->sub_policy_num |=
19020 : 0 : (i & MLX5_MTR_SUB_POLICY_NUM_MASK) <<
19021 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain);
19022 : : }
19023 : : rte_spinlock_unlock(&mtr_policy->sl);
19024 : 0 : *is_reuse = false;
19025 : 0 : return sub_policy;
19026 : 0 : rss_sub_policy_error:
19027 [ # # ]: 0 : if (sub_policy) {
19028 : 0 : __flow_dv_destroy_sub_policy_rules(dev, sub_policy);
19029 [ # # ]: 0 : if (sub_policy != mtr_policy->sub_policys[domain][0]) {
19030 : 0 : i = (mtr_policy->sub_policy_num >>
19031 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
19032 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
19033 : 0 : mtr_policy->sub_policys[domain][i] = NULL;
19034 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
19035 : 0 : sub_policy->idx);
19036 : : }
19037 : : }
19038 : : rte_spinlock_unlock(&mtr_policy->sl);
19039 : 0 : return NULL;
19040 : : }
19041 : :
19042 : : /**
19043 : : * Find the policy table for prefix table with RSS.
19044 : : *
19045 : : * @param[in] dev
19046 : : * Pointer to Ethernet device.
19047 : : * @param[in] mtr_policy
19048 : : * Pointer to meter policy table.
19049 : : * @param[in] rss_desc
19050 : : * Pointer to rss_desc
19051 : : * @return
19052 : : * Pointer to table set on success, NULL otherwise and rte_errno is set.
19053 : : */
19054 : : static struct mlx5_flow_meter_sub_policy *
19055 : 0 : flow_dv_meter_sub_policy_rss_prepare(struct rte_eth_dev *dev,
19056 : : struct mlx5_flow_meter_policy *mtr_policy,
19057 : : struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS])
19058 : : {
19059 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19060 : : struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
19061 : : struct mlx5_flow_meter_info *next_fm;
19062 : : struct mlx5_flow_meter_policy *next_policy;
19063 : : struct mlx5_flow_meter_sub_policy *next_sub_policy = NULL;
19064 : : struct mlx5_flow_meter_policy *policies[MLX5_MTR_CHAIN_MAX_NUM];
19065 : : struct mlx5_flow_meter_sub_policy *sub_policies[MLX5_MTR_CHAIN_MAX_NUM];
19066 : : uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
19067 : : bool reuse_sub_policy;
19068 : : uint32_t i = 0;
19069 : : uint32_t j = 0;
19070 : :
19071 : : while (true) {
19072 : : /* Iterate hierarchy to get all policies in this hierarchy. */
19073 : 0 : policies[i++] = mtr_policy;
19074 [ # # ]: 0 : if (!mtr_policy->is_hierarchy)
19075 : : break;
19076 [ # # ]: 0 : if (i >= MLX5_MTR_CHAIN_MAX_NUM) {
19077 : 0 : DRV_LOG(ERR, "Exceed max meter number in hierarchy.");
19078 : 0 : return NULL;
19079 : : }
19080 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19081 : 0 : next_fm = mlx5_flow_meter_hierarchy_next_meter(priv, mtr_policy, NULL);
19082 : : rte_spinlock_unlock(&mtr_policy->sl);
19083 [ # # ]: 0 : if (!next_fm) {
19084 : 0 : DRV_LOG(ERR, "Failed to get next meter in hierarchy.");
19085 : 0 : return NULL;
19086 : : }
19087 : : next_policy =
19088 : 0 : mlx5_flow_meter_policy_find(dev, next_fm->policy_id,
19089 : : NULL);
19090 : : MLX5_ASSERT(next_policy);
19091 : : mtr_policy = next_policy;
19092 : : }
19093 [ # # ]: 0 : while (i) {
19094 : : /**
19095 : : * From last policy to the first one in hierarchy,
19096 : : * create / get the sub policy for each of them.
19097 : : */
19098 : 0 : sub_policy = __flow_dv_meter_get_rss_sub_policy(dev,
19099 : : policies[--i],
19100 : : rss_desc,
19101 : : next_sub_policy,
19102 : : &reuse_sub_policy);
19103 [ # # ]: 0 : if (!sub_policy) {
19104 : 0 : DRV_LOG(ERR, "Failed to get the sub policy.");
19105 : 0 : goto err_exit;
19106 : : }
19107 [ # # ]: 0 : if (!reuse_sub_policy)
19108 : 0 : sub_policies[j++] = sub_policy;
19109 : : next_sub_policy = sub_policy;
19110 : : }
19111 : : return sub_policy;
19112 : : err_exit:
19113 [ # # ]: 0 : while (j) {
19114 : : uint16_t sub_policy_num;
19115 : :
19116 : 0 : sub_policy = sub_policies[--j];
19117 : 0 : mtr_policy = sub_policy->main_policy;
19118 : 0 : __flow_dv_destroy_sub_policy_rules(dev, sub_policy);
19119 [ # # ]: 0 : if (sub_policy != mtr_policy->sub_policys[domain][0]) {
19120 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
19121 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
19122 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
19123 : 0 : mtr_policy->sub_policys[domain][sub_policy_num - 1] =
19124 : : NULL;
19125 : 0 : sub_policy_num--;
19126 : 0 : mtr_policy->sub_policy_num &=
19127 : 0 : ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
19128 : 0 : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i));
19129 : 0 : mtr_policy->sub_policy_num |=
19130 : 0 : (sub_policy_num & MLX5_MTR_SUB_POLICY_NUM_MASK) <<
19131 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i);
19132 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
19133 : 0 : sub_policy->idx);
19134 : : }
19135 : : }
19136 : : return NULL;
19137 : : }
19138 : :
19139 : : /**
19140 : : * Check if need to create hierarchy tag rule.
19141 : : *
19142 : : * @param[in] priv
19143 : : * Pointer to mlx5_priv.
19144 : : * @param[in] mtr_policy
19145 : : * Pointer to current meter policy.
19146 : : * @param[in] src_port
19147 : : * The src port this extra rule should use.
19148 : : * @param[out] next_fm
19149 : : * Pointer to next meter in hierarchy.
19150 : : * @param[out] skip
19151 : : * Indicate if skip the tag rule creation.
19152 : : * @param[out] error
19153 : : * Perform verbose error reporting if not NULL.
19154 : : * @return
19155 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
19156 : : */
19157 : : static int
19158 : 0 : mlx5_meter_hierarchy_skip_tag_rule(struct mlx5_priv *priv,
19159 : : struct mlx5_flow_meter_policy *mtr_policy,
19160 : : int32_t src_port,
19161 : : struct mlx5_flow_meter_info **next_fm,
19162 : : bool *skip,
19163 : : struct rte_flow_error *error)
19164 : : {
19165 : : struct mlx5_flow_meter_sub_policy *sub_policy;
19166 : : struct mlx5_sub_policy_color_rule *color_rule;
19167 : : uint32_t domain = MLX5_MTR_DOMAIN_TRANSFER;
19168 : : int ret = 0;
19169 : : int i;
19170 : :
19171 : 0 : *next_fm = NULL;
19172 : 0 : *skip = false;
19173 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19174 [ # # ]: 0 : if (mtr_policy->is_hierarchy) {
19175 : 0 : *next_fm = mlx5_flow_meter_hierarchy_next_meter(priv, mtr_policy, NULL);
19176 [ # # ]: 0 : if (!*next_fm) {
19177 : 0 : ret = rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
19178 : : NULL, "Failed to find next meter in hierarchy.");
19179 : 0 : goto exit;
19180 : : }
19181 : : }
19182 [ # # ]: 0 : if (!mtr_policy->match_port) {
19183 : 0 : *skip = true;
19184 : 0 : goto exit;
19185 : : }
19186 : 0 : sub_policy = mtr_policy->sub_policys[domain][0];
19187 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
19188 [ # # ]: 0 : if (mtr_policy->act_cnt[i].fate_action != MLX5_FLOW_FATE_MTR &&
19189 : : mtr_policy->act_cnt[i].fate_action != MLX5_FLOW_FATE_PORT_ID)
19190 : 0 : continue;
19191 [ # # ]: 0 : TAILQ_FOREACH(color_rule, &sub_policy->color_rules[i], next_port)
19192 [ # # ]: 0 : if (color_rule->src_port == src_port) {
19193 : 0 : *skip = true;
19194 : 0 : goto exit;
19195 : : }
19196 : : }
19197 : 0 : exit:
19198 : : rte_spinlock_unlock(&mtr_policy->sl);
19199 : 0 : return ret;
19200 : : }
19201 : :
19202 : : /**
19203 : : * Create the sub policy tag rule for all meters in hierarchy.
19204 : : *
19205 : : * @param[in] dev
19206 : : * Pointer to Ethernet device.
19207 : : * @param[in] fm
19208 : : * Meter information table.
19209 : : * @param[in] src_port
19210 : : * The src port this extra rule should use.
19211 : : * @param[in] item
19212 : : * The src port match item.
19213 : : * @param[out] error
19214 : : * Perform verbose error reporting if not NULL.
19215 : : * @return
19216 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
19217 : : */
19218 : : static int
19219 : 0 : flow_dv_meter_hierarchy_rule_create(struct rte_eth_dev *dev,
19220 : : struct mlx5_flow_meter_info *fm,
19221 : : int32_t src_port,
19222 : : const struct rte_flow_item *item,
19223 : : struct rte_flow_error *error)
19224 : : {
19225 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19226 : : struct mlx5_flow_meter_policy *mtr_policy;
19227 : : struct mlx5_flow_meter_sub_policy *sub_policy;
19228 : 0 : struct mlx5_flow_meter_info *next_fm = NULL;
19229 : : struct mlx5_flow_meter_policy *next_policy;
19230 : : struct mlx5_flow_meter_sub_policy *next_sub_policy;
19231 : : struct mlx5_flow_tbl_data_entry *tbl_data;
19232 : : struct mlx5_sub_policy_color_rule *color_rule;
19233 : : struct mlx5_meter_policy_acts acts;
19234 : : uint32_t color_reg_c_idx;
19235 : : bool mtr_first = (src_port != UINT16_MAX) ? true : false;
19236 : 0 : struct rte_flow_attr attr = {
19237 : : .group = MLX5_FLOW_TABLE_LEVEL_POLICY,
19238 : : .priority = 0,
19239 : : .ingress = 0,
19240 : : .egress = 0,
19241 : : .transfer = 1,
19242 : : .reserved = 0,
19243 : : };
19244 : : uint32_t domain = MLX5_MTR_DOMAIN_TRANSFER;
19245 : : struct {
19246 : : struct mlx5_flow_meter_policy *fm_policy;
19247 : : struct mlx5_flow_meter_info *next_fm;
19248 : : struct mlx5_sub_policy_color_rule *tag_rule[RTE_COLORS];
19249 : 0 : } fm_info[MLX5_MTR_CHAIN_MAX_NUM] = { {0} };
19250 : : uint32_t fm_cnt = 0;
19251 : : uint32_t i, j;
19252 : :
19253 : 0 : color_reg_c_idx = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, error);
19254 : : /* Get all fms who need to create the tag color rule. */
19255 : : do {
19256 : 0 : bool skip = false;
19257 : :
19258 : 0 : mtr_policy = mlx5_flow_meter_policy_find(dev, fm->policy_id, NULL);
19259 : : MLX5_ASSERT(mtr_policy);
19260 [ # # ]: 0 : if (mlx5_meter_hierarchy_skip_tag_rule(priv, mtr_policy, src_port,
19261 : : &next_fm, &skip, error))
19262 : 0 : goto err_exit;
19263 [ # # ]: 0 : if (!skip) {
19264 : 0 : fm_info[fm_cnt].fm_policy = mtr_policy;
19265 : 0 : fm_info[fm_cnt].next_fm = next_fm;
19266 [ # # ]: 0 : if (++fm_cnt >= MLX5_MTR_CHAIN_MAX_NUM) {
19267 : 0 : rte_flow_error_set(error, errno,
19268 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
19269 : : "Exceed max meter number in hierarchy.");
19270 : 0 : goto err_exit;
19271 : : }
19272 : : }
19273 : 0 : fm = next_fm;
19274 [ # # ]: 0 : } while (fm);
19275 : : /* Create tag color rules for all needed fms. */
19276 [ # # ]: 0 : for (i = 0; i < fm_cnt; i++) {
19277 : : void *mtr_action;
19278 : :
19279 : 0 : mtr_policy = fm_info[i].fm_policy;
19280 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19281 : 0 : sub_policy = mtr_policy->sub_policys[domain][0];
19282 [ # # ]: 0 : for (j = 0; j < RTE_COLORS; j++) {
19283 : : uint8_t act_n = 0;
19284 : : struct mlx5_flow_dv_modify_hdr_resource *modify_hdr = NULL;
19285 : : struct mlx5_flow_dv_port_id_action_resource *port_action;
19286 : : uint8_t fate_action;
19287 : :
19288 [ # # ]: 0 : if (j == RTE_COLOR_RED) {
19289 : : fate_action = MLX5_FLOW_FATE_DROP;
19290 : : } else {
19291 : 0 : fate_action = mtr_policy->act_cnt[j].fate_action;
19292 : 0 : modify_hdr = mtr_policy->act_cnt[j].modify_hdr;
19293 : 0 : if (fate_action != MLX5_FLOW_FATE_MTR &&
19294 [ # # # # ]: 0 : fate_action != MLX5_FLOW_FATE_PORT_ID &&
19295 : : fate_action != MLX5_FLOW_FATE_DROP)
19296 : 0 : continue;
19297 : : }
19298 : 0 : color_rule = mlx5_malloc(MLX5_MEM_ZERO,
19299 : : sizeof(struct mlx5_sub_policy_color_rule),
19300 : : 0, SOCKET_ID_ANY);
19301 [ # # ]: 0 : if (!color_rule) {
19302 : : rte_spinlock_unlock(&mtr_policy->sl);
19303 : 0 : rte_flow_error_set(error, ENOMEM,
19304 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
19305 : : "No memory to create tag color rule.");
19306 : 0 : goto err_exit;
19307 : : }
19308 : 0 : color_rule->src_port = src_port;
19309 : : /* Prepare to create color rule. */
19310 [ # # ]: 0 : if (fate_action == MLX5_FLOW_FATE_MTR) {
19311 : 0 : next_fm = fm_info[i].next_fm;
19312 [ # # ]: 0 : if (mlx5_flow_meter_attach(priv, next_fm, &attr, error)) {
19313 : 0 : mlx5_free(color_rule);
19314 : : rte_spinlock_unlock(&mtr_policy->sl);
19315 : 0 : goto err_exit;
19316 : : }
19317 [ # # ]: 0 : mtr_action = (next_fm->color_aware && j == RTE_COLOR_YELLOW) ?
19318 [ # # ]: 0 : next_fm->meter_action_y :
19319 : : next_fm->meter_action_g;
19320 : 0 : next_policy = mlx5_flow_meter_policy_find(dev, next_fm->policy_id,
19321 : : NULL);
19322 : : MLX5_ASSERT(next_policy);
19323 : 0 : next_sub_policy = next_policy->sub_policys[domain][0];
19324 : 0 : tbl_data = container_of(next_sub_policy->tbl_rsc,
19325 : : struct mlx5_flow_tbl_data_entry, tbl);
19326 [ # # ]: 0 : if (mtr_first) {
19327 : 0 : acts.dv_actions[act_n++] = mtr_action;
19328 [ # # ]: 0 : if (modify_hdr)
19329 : 0 : acts.dv_actions[act_n++] = modify_hdr->action;
19330 : : } else {
19331 [ # # ]: 0 : if (modify_hdr)
19332 : 0 : acts.dv_actions[act_n++] = modify_hdr->action;
19333 : 0 : acts.dv_actions[act_n++] = mtr_action;
19334 : : }
19335 : 0 : acts.dv_actions[act_n++] = tbl_data->jump.action;
19336 : 0 : acts.actions_n = act_n;
19337 [ # # ]: 0 : } else if (fate_action == MLX5_FLOW_FATE_PORT_ID) {
19338 : : port_action =
19339 : 0 : mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PORT_ID],
19340 : : mtr_policy->act_cnt[j].rix_port_id_action);
19341 [ # # ]: 0 : if (!port_action) {
19342 : 0 : mlx5_free(color_rule);
19343 : : rte_spinlock_unlock(&mtr_policy->sl);
19344 : 0 : goto err_exit;
19345 : : }
19346 [ # # ]: 0 : if (modify_hdr)
19347 : 0 : acts.dv_actions[act_n++] = modify_hdr->action;
19348 : 0 : acts.dv_actions[act_n++] = port_action->action;
19349 : 0 : acts.actions_n = act_n;
19350 : : } else {
19351 : 0 : acts.dv_actions[act_n++] = mtr_policy->dr_drop_action[domain];
19352 : 0 : acts.actions_n = act_n;
19353 : : }
19354 : 0 : fm_info[i].tag_rule[j] = color_rule;
19355 : 0 : TAILQ_INSERT_TAIL(&sub_policy->color_rules[j], color_rule, next_port);
19356 [ # # ]: 0 : if (__flow_dv_create_policy_matcher(dev, color_reg_c_idx,
19357 : : MLX5_MTR_POLICY_MATCHER_PRIO, sub_policy,
19358 : : &attr, true, item, &color_rule->matcher, error)) {
19359 : : rte_spinlock_unlock(&mtr_policy->sl);
19360 : 0 : rte_flow_error_set(error, errno,
19361 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
19362 : : "Failed to create hierarchy meter matcher.");
19363 : 0 : goto err_exit;
19364 : : }
19365 [ # # ]: 0 : if (__flow_dv_create_policy_flow(dev, color_reg_c_idx, (enum rte_color)j,
19366 : : color_rule->matcher,
19367 : 0 : acts.actions_n, acts.dv_actions,
19368 : : true, item, &color_rule->rule, &attr)) {
19369 : : rte_spinlock_unlock(&mtr_policy->sl);
19370 : 0 : rte_flow_error_set(error, errno,
19371 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
19372 : : "Failed to create hierarchy meter rule.");
19373 : 0 : goto err_exit;
19374 : : }
19375 : : }
19376 : : rte_spinlock_unlock(&mtr_policy->sl);
19377 : : }
19378 : : return 0;
19379 : 0 : err_exit:
19380 [ # # ]: 0 : for (i = 0; i < fm_cnt; i++) {
19381 : 0 : mtr_policy = fm_info[i].fm_policy;
19382 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19383 : 0 : sub_policy = mtr_policy->sub_policys[domain][0];
19384 [ # # ]: 0 : for (j = 0; j < RTE_COLORS; j++) {
19385 : 0 : color_rule = fm_info[i].tag_rule[j];
19386 [ # # ]: 0 : if (!color_rule)
19387 : 0 : continue;
19388 [ # # ]: 0 : if (color_rule->rule)
19389 : : mlx5_flow_os_destroy_flow(color_rule->rule);
19390 [ # # ]: 0 : if (color_rule->matcher) {
19391 : : struct mlx5_flow_tbl_data_entry *tbl =
19392 : 0 : container_of(color_rule->matcher->tbl, typeof(*tbl), tbl);
19393 : 0 : mlx5_list_unregister(tbl->matchers, &color_rule->matcher->entry);
19394 : : }
19395 [ # # ]: 0 : if (fm_info[i].next_fm)
19396 : 0 : mlx5_flow_meter_detach(priv, fm_info[i].next_fm);
19397 [ # # ]: 0 : TAILQ_REMOVE(&sub_policy->color_rules[j], color_rule, next_port);
19398 : 0 : mlx5_free(color_rule);
19399 : : }
19400 : : rte_spinlock_unlock(&mtr_policy->sl);
19401 : : }
19402 : 0 : return -rte_errno;
19403 : : }
19404 : :
19405 : : /**
19406 : : * Destroy the sub policy table with RX queue.
19407 : : *
19408 : : * @param[in] dev
19409 : : * Pointer to Ethernet device.
19410 : : * @param[in] mtr_policy
19411 : : * Pointer to meter policy table.
19412 : : */
19413 : : static void
19414 : 0 : flow_dv_destroy_sub_policy_with_rxq(struct rte_eth_dev *dev,
19415 : : struct mlx5_flow_meter_policy *mtr_policy)
19416 : : {
19417 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19418 : : struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
19419 : : uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
19420 : : uint32_t i, j;
19421 : : uint16_t sub_policy_num, new_policy_num;
19422 : :
19423 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19424 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
19425 [ # # # ]: 0 : switch (mtr_policy->act_cnt[i].fate_action) {
19426 : 0 : case MLX5_FLOW_FATE_SHARED_RSS:
19427 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
19428 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
19429 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
19430 : : new_policy_num = sub_policy_num;
19431 [ # # ]: 0 : for (j = 0; j < sub_policy_num; j++) {
19432 : 0 : sub_policy =
19433 : 0 : mtr_policy->sub_policys[domain][j];
19434 [ # # ]: 0 : if (sub_policy) {
19435 : 0 : __flow_dv_destroy_sub_policy_rules(dev,
19436 : : sub_policy);
19437 : 0 : if (sub_policy !=
19438 [ # # ]: 0 : mtr_policy->sub_policys[domain][0]) {
19439 : 0 : mtr_policy->sub_policys[domain][j] =
19440 : : NULL;
19441 : 0 : mlx5_ipool_free
19442 : 0 : (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
19443 : 0 : sub_policy->idx);
19444 : 0 : new_policy_num--;
19445 : : }
19446 : : }
19447 : : }
19448 [ # # ]: 0 : if (new_policy_num != sub_policy_num) {
19449 : 0 : mtr_policy->sub_policy_num &=
19450 : : ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
19451 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain));
19452 : 0 : mtr_policy->sub_policy_num |=
19453 : : (new_policy_num &
19454 : : MLX5_MTR_SUB_POLICY_NUM_MASK) <<
19455 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain);
19456 : : }
19457 : : break;
19458 : 0 : case MLX5_FLOW_FATE_QUEUE:
19459 : 0 : sub_policy = mtr_policy->sub_policys[domain][0];
19460 : 0 : __flow_dv_destroy_sub_policy_rules(dev,
19461 : : sub_policy);
19462 : 0 : break;
19463 : : default:
19464 : : /*Other actions without queue and do nothing*/
19465 : : break;
19466 : : }
19467 : : }
19468 : : rte_spinlock_unlock(&mtr_policy->sl);
19469 : 0 : }
19470 : : /**
19471 : : * Check whether the DR drop action is supported on the root table or not.
19472 : : *
19473 : : * Create a simple flow with DR drop action on root table to validate
19474 : : * if DR drop action on root table is supported or not.
19475 : : *
19476 : : * @param[in] dev
19477 : : * Pointer to rte_eth_dev structure.
19478 : : *
19479 : : * @return
19480 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
19481 : : */
19482 : : int
19483 : 0 : mlx5_flow_discover_dr_action_support(struct rte_eth_dev *dev)
19484 : : {
19485 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19486 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
19487 : 0 : struct mlx5_flow_dv_match_params mask = {
19488 : : .size = sizeof(mask.buf),
19489 : : };
19490 : 0 : struct mlx5_flow_dv_match_params value = {
19491 : : .size = sizeof(value.buf),
19492 : : };
19493 : 0 : struct mlx5dv_flow_matcher_attr dv_attr = {
19494 : : .type = IBV_FLOW_ATTR_NORMAL,
19495 : : .priority = 0,
19496 : : .match_criteria_enable = 0,
19497 : : .match_mask = (void *)&mask,
19498 : : };
19499 : : struct mlx5_flow_tbl_resource *tbl = NULL;
19500 : : void *matcher = NULL;
19501 : : void *flow = NULL;
19502 : : int ret = -1;
19503 : :
19504 : 0 : tbl = flow_dv_tbl_resource_get(dev, 0, 0, 0, false, NULL,
19505 : : 0, 0, 0, NULL);
19506 [ # # ]: 0 : if (!tbl)
19507 : 0 : goto err;
19508 [ # # ]: 0 : dv_attr.match_criteria_enable = flow_dv_matcher_enable(mask.buf);
19509 : : __flow_dv_adjust_buf_size(&mask.size, dv_attr.match_criteria_enable);
19510 : 0 : ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
19511 : : tbl->obj, &matcher);
19512 : : if (ret)
19513 : 0 : goto err;
19514 [ # # ]: 0 : __flow_dv_adjust_buf_size(&value.size, dv_attr.match_criteria_enable);
19515 : 0 : ret = mlx5_flow_os_create_flow(matcher, (void *)&value, 1,
19516 : : &sh->dr_drop_action, &flow);
19517 : 0 : err:
19518 : : /*
19519 : : * If DR drop action is not supported on root table, flow create will
19520 : : * be failed with EOPNOTSUPP or EPROTONOSUPPORT.
19521 : : */
19522 [ # # ]: 0 : if (!flow) {
19523 [ # # ]: 0 : if (matcher &&
19524 [ # # ]: 0 : (errno == EPROTONOSUPPORT || errno == EOPNOTSUPP))
19525 : 0 : DRV_LOG(INFO, "DR drop action is not supported in root table.");
19526 : : else
19527 : 0 : DRV_LOG(ERR, "Unexpected error in DR drop action support detection");
19528 : : ret = -1;
19529 : : } else {
19530 : : claim_zero(mlx5_flow_os_destroy_flow(flow));
19531 : : }
19532 [ # # ]: 0 : if (matcher)
19533 : : claim_zero(mlx5_flow_os_destroy_flow_matcher(matcher));
19534 [ # # ]: 0 : if (tbl)
19535 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
19536 : 0 : return ret;
19537 : : }
19538 : :
19539 : : /**
19540 : : * Validate the batch counter support in root table.
19541 : : *
19542 : : * Create a simple flow with invalid counter and drop action on root table to
19543 : : * validate if batch counter with offset on root table is supported or not.
19544 : : *
19545 : : * @param[in] dev
19546 : : * Pointer to rte_eth_dev structure.
19547 : : *
19548 : : * @return
19549 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
19550 : : */
19551 : : int
19552 : 0 : mlx5_flow_dv_discover_counter_offset_support(struct rte_eth_dev *dev)
19553 : : {
19554 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19555 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
19556 : 0 : struct mlx5_flow_dv_match_params mask = {
19557 : : .size = sizeof(mask.buf),
19558 : : };
19559 : 0 : struct mlx5_flow_dv_match_params value = {
19560 : : .size = sizeof(value.buf),
19561 : : };
19562 : 0 : struct mlx5dv_flow_matcher_attr dv_attr = {
19563 : : .type = IBV_FLOW_ATTR_NORMAL | IBV_FLOW_ATTR_FLAGS_EGRESS,
19564 : : .priority = 0,
19565 : : .match_criteria_enable = 0,
19566 : : .match_mask = (void *)&mask,
19567 : : };
19568 : 0 : void *actions[2] = { 0 };
19569 : : struct mlx5_flow_tbl_resource *tbl = NULL;
19570 : : struct mlx5_devx_obj *dcs = NULL;
19571 : : void *matcher = NULL;
19572 : : void *flow = NULL;
19573 : : int ret = -1;
19574 : :
19575 : 0 : tbl = flow_dv_tbl_resource_get(dev, 0, 1, 0, false, NULL,
19576 : : 0, 0, 0, NULL);
19577 [ # # ]: 0 : if (!tbl)
19578 : 0 : goto err;
19579 : 0 : dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0x4);
19580 [ # # ]: 0 : if (!dcs)
19581 : 0 : goto err;
19582 : 0 : ret = mlx5_flow_os_create_flow_action_count(dcs->obj, UINT16_MAX,
19583 : : &actions[0]);
19584 : : if (ret)
19585 : 0 : goto err;
19586 [ # # ]: 0 : dv_attr.match_criteria_enable = flow_dv_matcher_enable(mask.buf);
19587 : : __flow_dv_adjust_buf_size(&mask.size, dv_attr.match_criteria_enable);
19588 : 0 : ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
19589 : : tbl->obj, &matcher);
19590 : : if (ret)
19591 : 0 : goto err;
19592 [ # # ]: 0 : __flow_dv_adjust_buf_size(&value.size, dv_attr.match_criteria_enable);
19593 : : ret = mlx5_flow_os_create_flow(matcher, (void *)&value, 1,
19594 : : actions, &flow);
19595 : 0 : err:
19596 : : /*
19597 : : * If batch counter with offset is not supported, the driver will not
19598 : : * validate the invalid offset value, flow create should success.
19599 : : * In this case, it means batch counter is not supported in root table.
19600 : : *
19601 : : * Otherwise, if flow create is failed, counter offset is supported.
19602 : : */
19603 [ # # ]: 0 : if (flow) {
19604 : 0 : DRV_LOG(INFO, "Batch counter is not supported in root "
19605 : : "table. Switch to fallback mode.");
19606 : 0 : rte_errno = ENOTSUP;
19607 : : ret = -rte_errno;
19608 : : claim_zero(mlx5_flow_os_destroy_flow(flow));
19609 : : } else {
19610 : : /* Check matcher to make sure validate fail at flow create. */
19611 [ # # # # ]: 0 : if (!matcher || (matcher && errno != EINVAL))
19612 : 0 : DRV_LOG(ERR, "Unexpected error in counter offset "
19613 : : "support detection");
19614 : : ret = 0;
19615 : : }
19616 [ # # ]: 0 : if (actions[0])
19617 : : claim_zero(mlx5_flow_os_destroy_flow_action(actions[0]));
19618 [ # # ]: 0 : if (matcher)
19619 : : claim_zero(mlx5_flow_os_destroy_flow_matcher(matcher));
19620 [ # # ]: 0 : if (tbl)
19621 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
19622 [ # # ]: 0 : if (dcs)
19623 : 0 : claim_zero(mlx5_devx_cmd_destroy(dcs));
19624 : 0 : return ret;
19625 : : }
19626 : :
19627 : : /**
19628 : : * Query a devx counter.
19629 : : *
19630 : : * @param[in] dev
19631 : : * Pointer to the Ethernet device structure.
19632 : : * @param[in] cnt
19633 : : * Index to the flow counter.
19634 : : * @param[in] clear
19635 : : * Set to clear the counter statistics.
19636 : : * @param[out] pkts
19637 : : * The statistics value of packets.
19638 : : * @param[out] bytes
19639 : : * The statistics value of bytes.
19640 : : *
19641 : : * @return
19642 : : * 0 on success, otherwise return -1.
19643 : : */
19644 : : static int
19645 : 0 : flow_dv_counter_query(struct rte_eth_dev *dev, uint32_t counter, bool clear,
19646 : : uint64_t *pkts, uint64_t *bytes, void **action)
19647 : : {
19648 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19649 : : struct mlx5_flow_counter *cnt;
19650 : : uint64_t inn_pkts, inn_bytes;
19651 : : int ret;
19652 : :
19653 [ # # ]: 0 : if (!priv->sh->cdev->config.devx)
19654 : : return -1;
19655 : :
19656 : 0 : ret = _flow_dv_query_count(dev, counter, &inn_pkts, &inn_bytes);
19657 [ # # ]: 0 : if (ret)
19658 : : return -1;
19659 : : cnt = flow_dv_counter_get_by_idx(dev, counter, NULL);
19660 [ # # ]: 0 : if (cnt && action)
19661 : 0 : *action = cnt->action;
19662 : :
19663 : 0 : *pkts = inn_pkts - cnt->hits;
19664 : 0 : *bytes = inn_bytes - cnt->bytes;
19665 [ # # ]: 0 : if (clear) {
19666 : 0 : cnt->hits = inn_pkts;
19667 : 0 : cnt->bytes = inn_bytes;
19668 : : }
19669 : : return 0;
19670 : : }
19671 : :
19672 : : /**
19673 : : * Get aged-out flows.
19674 : : *
19675 : : * @param[in] dev
19676 : : * Pointer to the Ethernet device structure.
19677 : : * @param[in] context
19678 : : * The address of an array of pointers to the aged-out flows contexts.
19679 : : * @param[in] nb_contexts
19680 : : * The length of context array pointers.
19681 : : * @param[out] error
19682 : : * Perform verbose error reporting if not NULL. Initialized in case of
19683 : : * error only.
19684 : : *
19685 : : * @return
19686 : : * how many contexts get in success, otherwise negative errno value.
19687 : : * if nb_contexts is 0, return the amount of all aged contexts.
19688 : : * if nb_contexts is not 0 , return the amount of aged flows reported
19689 : : * in the context array.
19690 : : * @note: only stub for now
19691 : : */
19692 : : static int
19693 : 0 : flow_dv_get_aged_flows(struct rte_eth_dev *dev,
19694 : : void **context,
19695 : : uint32_t nb_contexts,
19696 : : struct rte_flow_error *error)
19697 : : {
19698 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19699 : : struct mlx5_age_info *age_info;
19700 : : struct mlx5_age_param *age_param;
19701 : : struct mlx5_flow_counter *counter;
19702 : : struct mlx5_aso_age_action *act;
19703 : : int nb_flows = 0;
19704 : :
19705 [ # # ]: 0 : if (nb_contexts && !context)
19706 : 0 : return rte_flow_error_set(error, EINVAL,
19707 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
19708 : : NULL, "empty context");
19709 : 0 : age_info = GET_PORT_AGE_INFO(priv);
19710 : 0 : rte_spinlock_lock(&age_info->aged_sl);
19711 [ # # ]: 0 : LIST_FOREACH(act, &age_info->aged_aso, next) {
19712 : 0 : nb_flows++;
19713 [ # # ]: 0 : if (nb_contexts) {
19714 : 0 : context[nb_flows - 1] = act->age_params.context;
19715 [ # # ]: 0 : if (!(--nb_contexts))
19716 : : break;
19717 : : }
19718 : : }
19719 [ # # ]: 0 : TAILQ_FOREACH(counter, &age_info->aged_counters, next) {
19720 : 0 : nb_flows++;
19721 [ # # ]: 0 : if (nb_contexts) {
19722 : : age_param = MLX5_CNT_TO_AGE(counter);
19723 : 0 : context[nb_flows - 1] = age_param->context;
19724 [ # # ]: 0 : if (!(--nb_contexts))
19725 : : break;
19726 : : }
19727 : : }
19728 : : rte_spinlock_unlock(&age_info->aged_sl);
19729 : 0 : MLX5_AGE_SET(age_info, MLX5_AGE_TRIGGER);
19730 : 0 : return nb_flows;
19731 : : }
19732 : :
19733 : : /*
19734 : : * Mutex-protected thunk to lock-free flow_dv_counter_alloc().
19735 : : */
19736 : : static uint32_t
19737 : 0 : flow_dv_counter_allocate(struct rte_eth_dev *dev)
19738 : : {
19739 : 0 : return flow_dv_counter_alloc(dev, 0);
19740 : : }
19741 : :
19742 : : /**
19743 : : * Validate indirect action.
19744 : : * Dispatcher for action type specific validation.
19745 : : *
19746 : : * @param[in] dev
19747 : : * Pointer to the Ethernet device structure.
19748 : : * @param[in] conf
19749 : : * Indirect action configuration.
19750 : : * @param[in] action
19751 : : * The indirect action object to validate.
19752 : : * @param[out] error
19753 : : * Perform verbose error reporting if not NULL. Initialized in case of
19754 : : * error only.
19755 : : *
19756 : : * @return
19757 : : * 0 on success, otherwise negative errno value.
19758 : : */
19759 : : int
19760 : 0 : flow_dv_action_validate(struct rte_eth_dev *dev,
19761 : : const struct rte_flow_indir_action_conf *conf,
19762 : : const struct rte_flow_action *action,
19763 : : struct rte_flow_error *err)
19764 : : {
19765 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19766 : : /* called from RTE API */
19767 : :
19768 : : RTE_SET_USED(conf);
19769 [ # # # # : 0 : switch (action->type) {
# ]
19770 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
19771 : : /*
19772 : : * priv->obj_ops is set according to driver capabilities.
19773 : : * When DevX capabilities are
19774 : : * sufficient, it is set to devx_obj_ops.
19775 : : * Otherwise, it is set to ibv_obj_ops.
19776 : : * ibv_obj_ops doesn't support ind_table_modify operation.
19777 : : * In this case the indirect RSS action can't be used.
19778 : : */
19779 [ # # ]: 0 : if (priv->obj_ops.ind_table_modify == NULL)
19780 : 0 : return rte_flow_error_set
19781 : : (err, ENOTSUP,
19782 : : RTE_FLOW_ERROR_TYPE_ACTION,
19783 : : NULL,
19784 : : "Indirect RSS action not supported");
19785 : 0 : return mlx5_validate_action_rss(dev, action, err);
19786 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
19787 [ # # ]: 0 : if (!priv->sh->aso_age_mng)
19788 : 0 : return rte_flow_error_set(err, ENOTSUP,
19789 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
19790 : : NULL,
19791 : : "Indirect age action not supported");
19792 : 0 : return flow_dv_validate_action_age(0, action, dev, err);
19793 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
19794 : 0 : return flow_dv_validate_action_count(dev, true, 0, false, err);
19795 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
19796 [ # # ]: 0 : if (!priv->sh->ct_aso_en)
19797 : 0 : return rte_flow_error_set(err, ENOTSUP,
19798 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
19799 : : "ASO CT is not supported");
19800 : 0 : return mlx5_validate_action_ct(dev, action->conf, err);
19801 : 0 : default:
19802 : 0 : return rte_flow_error_set(err, ENOTSUP,
19803 : : RTE_FLOW_ERROR_TYPE_ACTION,
19804 : : NULL,
19805 : : "action type not supported");
19806 : : }
19807 : : }
19808 : :
19809 : : /*
19810 : : * Check if the RSS configurations for colors of a meter policy match
19811 : : * each other, except the queues.
19812 : : *
19813 : : * @param[in] r1
19814 : : * Pointer to the first RSS flow action.
19815 : : * @param[in] r2
19816 : : * Pointer to the second RSS flow action.
19817 : : *
19818 : : * @return
19819 : : * 0 on match, 1 on conflict.
19820 : : */
19821 : : static inline int
19822 : 0 : flow_dv_mtr_policy_rss_compare(const struct rte_flow_action_rss *r1,
19823 : : const struct rte_flow_action_rss *r2)
19824 : : {
19825 [ # # ]: 0 : if (r1 == NULL || r2 == NULL)
19826 : : return 0;
19827 [ # # # # : 0 : if (!(r1->level <= 1 && r2->level <= 1) &&
# # ]
19828 [ # # ]: 0 : !(r1->level > 1 && r2->level > 1))
19829 : : return 1;
19830 [ # # ]: 0 : if (r1->func != r2->func)
19831 : : return 1;
19832 [ # # ]: 0 : if (r1->types != r2->types &&
19833 [ # # ]: 0 : !((r1->types == 0 || r1->types == RTE_ETH_RSS_IP) &&
19834 [ # # ]: 0 : (r2->types == 0 || r2->types == RTE_ETH_RSS_IP)))
19835 : : return 1;
19836 [ # # # # ]: 0 : if (r1->key || r2->key) {
19837 [ # # ]: 0 : const void *key1 = r1->key ? r1->key : rss_hash_default_key;
19838 [ # # ]: 0 : const void *key2 = r2->key ? r2->key : rss_hash_default_key;
19839 : :
19840 [ # # ]: 0 : if (memcmp(key1, key2, MLX5_RSS_HASH_KEY_LEN))
19841 : 0 : return 1;
19842 : : }
19843 : : return 0;
19844 : : }
19845 : :
19846 : : /**
19847 : : * Validate the meter hierarchy chain for meter policy.
19848 : : *
19849 : : * @param[in] dev
19850 : : * Pointer to the Ethernet device structure.
19851 : : * @param[in] meter_id
19852 : : * Meter id.
19853 : : * @param[in] action_flags
19854 : : * Holds the actions detected until now.
19855 : : * @param[out] is_rss
19856 : : * Is RSS or not.
19857 : : * @param[out] hierarchy_domain
19858 : : * The domain bitmap for hierarchy policy.
19859 : : * @param[out] error
19860 : : * Perform verbose error reporting if not NULL. Initialized in case of
19861 : : * error only.
19862 : : *
19863 : : * @return
19864 : : * 0 on success, otherwise negative errno value with error set.
19865 : : */
19866 : : static int
19867 : 0 : flow_dv_validate_policy_mtr_hierarchy(struct rte_eth_dev *dev,
19868 : : uint32_t meter_id,
19869 : : uint64_t action_flags,
19870 : : bool *is_rss,
19871 : : uint8_t *hierarchy_domain,
19872 : : struct rte_mtr_error *error)
19873 : : {
19874 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19875 : : struct mlx5_flow_meter_info *fm;
19876 : : struct mlx5_flow_meter_policy *policy;
19877 : : uint8_t cnt = 1;
19878 : :
19879 [ # # ]: 0 : if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
19880 : : MLX5_FLOW_FATE_ESWITCH_ACTIONS))
19881 : 0 : return -rte_mtr_error_set(error, EINVAL,
19882 : : RTE_MTR_ERROR_TYPE_POLICER_ACTION_GREEN,
19883 : : NULL,
19884 : : "Multiple fate actions not supported.");
19885 : 0 : *hierarchy_domain = 0;
19886 : 0 : fm = mlx5_flow_meter_find(priv, meter_id, NULL);
19887 : : while (true) {
19888 [ # # ]: 0 : if (!fm)
19889 : 0 : return -rte_mtr_error_set(error, EINVAL,
19890 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
19891 : : "Meter not found in meter hierarchy.");
19892 [ # # ]: 0 : if (fm->def_policy)
19893 : 0 : return -rte_mtr_error_set(error, EINVAL,
19894 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
19895 : : "Non termination meter not supported in hierarchy.");
19896 [ # # ]: 0 : if (!fm->shared)
19897 : 0 : return -rte_mtr_error_set(error, EINVAL,
19898 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
19899 : : "Only shared meter supported in hierarchy.");
19900 : 0 : policy = mlx5_flow_meter_policy_find(dev, fm->policy_id, NULL);
19901 : : MLX5_ASSERT(policy);
19902 : : /**
19903 : : * Only inherit the supported domains of the first meter in
19904 : : * hierarchy.
19905 : : * One meter supports at least one domain.
19906 : : */
19907 [ # # ]: 0 : if (!*hierarchy_domain) {
19908 [ # # ]: 0 : if (policy->transfer)
19909 : 0 : *hierarchy_domain |=
19910 : : MLX5_MTR_DOMAIN_TRANSFER_BIT;
19911 [ # # ]: 0 : if (policy->ingress)
19912 : 0 : *hierarchy_domain |=
19913 : : MLX5_MTR_DOMAIN_INGRESS_BIT;
19914 [ # # ]: 0 : if (policy->egress)
19915 : 0 : *hierarchy_domain |= MLX5_MTR_DOMAIN_EGRESS_BIT;
19916 : : }
19917 [ # # ]: 0 : if (!policy->is_hierarchy) {
19918 : 0 : *is_rss = policy->is_rss;
19919 : : break;
19920 : : }
19921 : 0 : rte_spinlock_lock(&policy->sl);
19922 : 0 : fm = mlx5_flow_meter_hierarchy_next_meter(priv, policy, NULL);
19923 : : rte_spinlock_unlock(&policy->sl);
19924 [ # # ]: 0 : if (++cnt >= MLX5_MTR_CHAIN_MAX_NUM)
19925 : 0 : return -rte_mtr_error_set(error, EINVAL,
19926 : : RTE_MTR_ERROR_TYPE_METER_POLICY, NULL,
19927 : : "Exceed max hierarchy meter number.");
19928 : : }
19929 : 0 : return 0;
19930 : : }
19931 : :
19932 : : /**
19933 : : * Validate meter policy actions.
19934 : : * Dispatcher for action type specific validation.
19935 : : *
19936 : : * @param[in] dev
19937 : : * Pointer to the Ethernet device structure.
19938 : : * @param[in] action
19939 : : * The meter policy action object to validate.
19940 : : * @param[in] attr
19941 : : * Attributes of flow to determine steering domain.
19942 : : * @param[out] error
19943 : : * Perform verbose error reporting if not NULL. Initialized in case of
19944 : : * error only.
19945 : : *
19946 : : * @return
19947 : : * 0 on success, otherwise negative errno value.
19948 : : */
19949 : : static int
19950 : 0 : flow_dv_validate_mtr_policy_acts(struct rte_eth_dev *dev,
19951 : : const struct rte_flow_action *actions[RTE_COLORS],
19952 : : struct rte_flow_attr *attr,
19953 : : bool *is_rss,
19954 : : uint8_t *domain_bitmap,
19955 : : uint8_t *policy_mode,
19956 : : struct rte_mtr_error *error)
19957 : : {
19958 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19959 : 0 : struct mlx5_sh_config *dev_conf = &priv->sh->config;
19960 : : const struct rte_flow_action *act;
19961 : 0 : uint64_t action_flags[RTE_COLORS] = {0};
19962 : : int actions_n;
19963 : : int i, ret;
19964 : : struct rte_flow_error flow_err;
19965 : 0 : uint8_t domain_color[RTE_COLORS] = {0};
19966 : : uint8_t def_domain = MLX5_MTR_ALL_DOMAIN_BIT;
19967 : 0 : uint8_t hierarchy_domain = 0;
19968 : : const struct rte_flow_action_meter *mtr;
19969 : : const struct rte_flow_action_meter *next_mtr = NULL;
19970 : : bool def_green = false;
19971 : : bool def_yellow = false;
19972 : 0 : const struct rte_flow_action_rss *rss_color[RTE_COLORS] = {NULL};
19973 : : /* Called from RTE API */
19974 [ # # # # : 0 : bool is_root = !(attr->group || (attr->transfer && priv->fdb_def_rule));
# # ]
19975 : :
19976 [ # # ]: 0 : if (!dev_conf->dv_esw_en)
19977 : : def_domain &= ~MLX5_MTR_DOMAIN_TRANSFER_BIT;
19978 : 0 : *domain_bitmap = def_domain;
19979 : : /* Red color could only support DROP action. */
19980 [ # # ]: 0 : if (!actions[RTE_COLOR_RED] ||
19981 [ # # ]: 0 : actions[RTE_COLOR_RED]->type != RTE_FLOW_ACTION_TYPE_DROP)
19982 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
19983 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
19984 : : NULL, "Red color only supports drop action.");
19985 : : /*
19986 : : * Check default policy actions:
19987 : : * Green / Yellow: no action, Red: drop action
19988 : : * Either G or Y will trigger default policy actions to be created.
19989 : : */
19990 [ # # ]: 0 : if (!actions[RTE_COLOR_GREEN] ||
19991 [ # # ]: 0 : actions[RTE_COLOR_GREEN]->type == RTE_FLOW_ACTION_TYPE_END)
19992 : : def_green = true;
19993 [ # # ]: 0 : if (!actions[RTE_COLOR_YELLOW] ||
19994 [ # # ]: 0 : actions[RTE_COLOR_YELLOW]->type == RTE_FLOW_ACTION_TYPE_END)
19995 : : def_yellow = true;
19996 [ # # ]: 0 : if (def_green && def_yellow) {
19997 : 0 : *policy_mode = MLX5_MTR_POLICY_MODE_DEF;
19998 : 0 : return 0;
19999 [ # # ]: 0 : } else if (!def_green && def_yellow) {
20000 : 0 : *policy_mode = MLX5_MTR_POLICY_MODE_OG;
20001 [ # # ]: 0 : } else if (def_green && !def_yellow) {
20002 : 0 : *policy_mode = MLX5_MTR_POLICY_MODE_OY;
20003 : : } else {
20004 : 0 : *policy_mode = MLX5_MTR_POLICY_MODE_ALL;
20005 : : }
20006 : : /* Set to empty string in case of NULL pointer access by user. */
20007 : 0 : flow_err.message = "";
20008 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
20009 : 0 : act = actions[i];
20010 : 0 : for (action_flags[i] = 0, actions_n = 0;
20011 [ # # # # ]: 0 : act && act->type != RTE_FLOW_ACTION_TYPE_END;
20012 : 0 : act++) {
20013 [ # # ]: 0 : if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
20014 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20015 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20016 : : NULL, "too many actions");
20017 [ # # # # : 0 : switch (act->type) {
# # # # #
# ]
20018 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
20019 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
20020 [ # # ]: 0 : if (!dev_conf->dv_esw_en)
20021 : 0 : return -rte_mtr_error_set(error,
20022 : : ENOTSUP,
20023 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20024 : : NULL, "PORT action validate check"
20025 : : " fail for ESW disable");
20026 : 0 : ret = flow_dv_validate_action_port_id(dev,
20027 : : action_flags[i],
20028 : : act, attr, &flow_err);
20029 [ # # ]: 0 : if (ret)
20030 : 0 : return -rte_mtr_error_set(error,
20031 : : ENOTSUP,
20032 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20033 [ # # ]: 0 : NULL, flow_err.message ?
20034 : : flow_err.message :
20035 : : "PORT action validate check fail");
20036 : 0 : ++actions_n;
20037 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_PORT_ID;
20038 : 0 : break;
20039 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
20040 : 0 : ret = flow_dv_validate_action_mark(dev, act,
20041 : : action_flags[i],
20042 : : attr, &flow_err);
20043 [ # # ]: 0 : if (ret < 0)
20044 : 0 : return -rte_mtr_error_set(error,
20045 : : ENOTSUP,
20046 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20047 [ # # ]: 0 : NULL, flow_err.message ?
20048 : : flow_err.message :
20049 : : "Mark action validate check fail");
20050 [ # # ]: 0 : if (dev_conf->dv_xmeta_en !=
20051 : : MLX5_XMETA_MODE_LEGACY)
20052 : 0 : return -rte_mtr_error_set(error,
20053 : : ENOTSUP,
20054 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20055 : : NULL, "Extend MARK action is "
20056 : : "not supported. Please try use "
20057 : : "default policy for meter.");
20058 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_MARK;
20059 : 0 : ++actions_n;
20060 : 0 : break;
20061 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TAG:
20062 : 0 : ret = flow_dv_validate_action_set_tag(dev,
20063 : : act, action_flags[i],
20064 : : attr, &flow_err);
20065 [ # # ]: 0 : if (ret)
20066 : 0 : return -rte_mtr_error_set(error,
20067 : : ENOTSUP,
20068 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20069 [ # # ]: 0 : NULL, flow_err.message ?
20070 : : flow_err.message :
20071 : : "Set tag action validate check fail");
20072 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_SET_TAG;
20073 : 0 : ++actions_n;
20074 : 0 : break;
20075 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
20076 : 0 : ret = mlx5_flow_validate_action_drop
20077 : : (dev, false, attr, &flow_err);
20078 [ # # ]: 0 : if (ret < 0)
20079 : 0 : return -rte_mtr_error_set(error,
20080 : : ENOTSUP,
20081 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20082 [ # # ]: 0 : NULL, flow_err.message ?
20083 : : flow_err.message :
20084 : : "Drop action validate check fail");
20085 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_DROP;
20086 : 0 : ++actions_n;
20087 : 0 : break;
20088 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
20089 : : /*
20090 : : * Check whether extensive
20091 : : * metadata feature is engaged.
20092 : : */
20093 [ # # ]: 0 : if (dev_conf->dv_flow_en &&
20094 [ # # ]: 0 : (dev_conf->dv_xmeta_en !=
20095 [ # # ]: 0 : MLX5_XMETA_MODE_LEGACY) &&
20096 : 0 : mlx5_flow_ext_mreg_supported(dev))
20097 : 0 : return -rte_mtr_error_set(error,
20098 : : ENOTSUP,
20099 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20100 : : NULL, "Queue action with meta "
20101 : : "is not supported. Please try use "
20102 : : "default policy for meter.");
20103 : 0 : ret = mlx5_flow_validate_action_queue(act,
20104 : : action_flags[i], dev,
20105 : : attr, &flow_err);
20106 [ # # ]: 0 : if (ret < 0)
20107 : 0 : return -rte_mtr_error_set(error,
20108 : : ENOTSUP,
20109 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20110 [ # # ]: 0 : NULL, flow_err.message ?
20111 : : flow_err.message :
20112 : : "Queue action validate check fail");
20113 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_QUEUE;
20114 : 0 : ++actions_n;
20115 : 0 : break;
20116 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
20117 [ # # ]: 0 : if (dev_conf->dv_flow_en &&
20118 [ # # ]: 0 : (dev_conf->dv_xmeta_en !=
20119 [ # # ]: 0 : MLX5_XMETA_MODE_LEGACY) &&
20120 : 0 : mlx5_flow_ext_mreg_supported(dev))
20121 : 0 : return -rte_mtr_error_set(error,
20122 : : ENOTSUP,
20123 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20124 : : NULL, "RSS action with meta "
20125 : : "is not supported. Please try use "
20126 : : "default policy for meter.");
20127 : 0 : ret = mlx5_validate_action_rss(dev, act,
20128 : : &flow_err);
20129 [ # # ]: 0 : if (ret < 0)
20130 : 0 : return -rte_mtr_error_set(error,
20131 : : ENOTSUP,
20132 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20133 [ # # ]: 0 : NULL, flow_err.message ?
20134 : : flow_err.message :
20135 : : "RSS action validate check fail");
20136 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_RSS;
20137 : 0 : ++actions_n;
20138 : : /* Either G or Y will set the RSS. */
20139 : 0 : rss_color[i] = act->conf;
20140 : 0 : break;
20141 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
20142 : 0 : ret = flow_dv_validate_action_jump(dev,
20143 : : NULL, act, action_flags[i],
20144 : : attr, true, &flow_err);
20145 [ # # ]: 0 : if (ret)
20146 : 0 : return -rte_mtr_error_set(error,
20147 : : ENOTSUP,
20148 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20149 [ # # ]: 0 : NULL, flow_err.message ?
20150 : : flow_err.message :
20151 : : "Jump action validate check fail");
20152 : 0 : ++actions_n;
20153 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_JUMP;
20154 : 0 : break;
20155 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
20156 : 0 : mtr = act->conf;
20157 [ # # # # ]: 0 : if (next_mtr && next_mtr->mtr_id != mtr->mtr_id)
20158 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20159 : : RTE_MTR_ERROR_TYPE_METER_POLICY, NULL,
20160 : : "Green and Yellow must use the same meter.");
20161 : 0 : ret = flow_dv_validate_policy_mtr_hierarchy(dev,
20162 : 0 : mtr->mtr_id,
20163 : : action_flags[i],
20164 : : is_rss,
20165 : : &hierarchy_domain,
20166 : : error);
20167 [ # # ]: 0 : if (ret)
20168 : 0 : return ret;
20169 : 0 : ++actions_n;
20170 : 0 : action_flags[i] |=
20171 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
20172 : : next_mtr = mtr;
20173 : 0 : break;
20174 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
20175 : 0 : ret = flow_dv_validate_action_modify_field(dev,
20176 : : action_flags[i], act, attr, is_root, &flow_err);
20177 [ # # ]: 0 : if (ret < 0)
20178 : 0 : return -rte_mtr_error_set(error,
20179 : : ENOTSUP,
20180 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20181 [ # # ]: 0 : NULL, flow_err.message ?
20182 : : flow_err.message :
20183 : : "Modify field action validate check fail");
20184 : 0 : ++actions_n;
20185 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_MODIFY_FIELD;
20186 : 0 : break;
20187 : : default:
20188 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20189 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20190 : : NULL,
20191 : : "Doesn't support optional action");
20192 : : }
20193 : : }
20194 [ # # ]: 0 : if (action_flags[i] & MLX5_FLOW_ACTION_PORT_ID) {
20195 : 0 : domain_color[i] = MLX5_MTR_DOMAIN_TRANSFER_BIT;
20196 [ # # ]: 0 : } else if ((action_flags[i] &
20197 : 0 : (MLX5_FLOW_ACTION_RSS | MLX5_FLOW_ACTION_QUEUE)) ||
20198 [ # # ]: 0 : (action_flags[i] & MLX5_FLOW_ACTION_MARK)) {
20199 : : /*
20200 : : * Only support MLX5_XMETA_MODE_LEGACY
20201 : : * so MARK action is only in ingress domain.
20202 : : */
20203 : 0 : domain_color[i] = MLX5_MTR_DOMAIN_INGRESS_BIT;
20204 : : } else {
20205 : 0 : domain_color[i] = def_domain;
20206 [ # # ]: 0 : if (action_flags[i] &&
20207 [ # # ]: 0 : !(action_flags[i] & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
20208 : 0 : domain_color[i] &=
20209 : : ~MLX5_MTR_DOMAIN_TRANSFER_BIT;
20210 : : }
20211 [ # # ]: 0 : if (action_flags[i] &
20212 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
20213 : 0 : domain_color[i] &= hierarchy_domain;
20214 : : /*
20215 : : * Non-termination actions only support NIC Tx domain.
20216 : : * The adjustion should be skipped when there is no
20217 : : * action or only END is provided. The default domains
20218 : : * bit-mask is set to find the MIN intersection.
20219 : : * The action flags checking should also be skipped.
20220 : : */
20221 [ # # ]: 0 : if ((def_green && i == RTE_COLOR_GREEN) ||
20222 [ # # ]: 0 : (def_yellow && i == RTE_COLOR_YELLOW))
20223 : 0 : continue;
20224 : : /*
20225 : : * Validate the drop action mutual exclusion
20226 : : * with other actions. Drop action is mutually-exclusive
20227 : : * with any other action, except for Count action.
20228 : : */
20229 [ # # ]: 0 : if ((action_flags[i] & MLX5_FLOW_ACTION_DROP) &&
20230 [ # # ]: 0 : (action_flags[i] & ~MLX5_FLOW_ACTION_DROP)) {
20231 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20232 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20233 : : NULL, "Drop action is mutually-exclusive "
20234 : : "with any other action");
20235 : : }
20236 : : /* Eswitch has few restrictions on using items and actions */
20237 [ # # ]: 0 : if (domain_color[i] & MLX5_MTR_DOMAIN_TRANSFER_BIT) {
20238 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev) &&
20239 [ # # ]: 0 : action_flags[i] & MLX5_FLOW_ACTION_MARK)
20240 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20241 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20242 : : NULL, "unsupported action MARK");
20243 [ # # ]: 0 : if (action_flags[i] & MLX5_FLOW_ACTION_QUEUE)
20244 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20245 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20246 : : NULL, "unsupported action QUEUE");
20247 [ # # ]: 0 : if (action_flags[i] & MLX5_FLOW_ACTION_RSS)
20248 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20249 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20250 : : NULL, "unsupported action RSS");
20251 [ # # ]: 0 : if (!(action_flags[i] & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
20252 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20253 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20254 : : NULL, "no fate action is found");
20255 : : } else {
20256 [ # # # # ]: 0 : if (!(action_flags[i] & MLX5_FLOW_FATE_ACTIONS) &&
20257 : : (domain_color[i] & MLX5_MTR_DOMAIN_INGRESS_BIT)) {
20258 [ # # ]: 0 : if ((domain_color[i] &
20259 : : MLX5_MTR_DOMAIN_EGRESS_BIT))
20260 : 0 : domain_color[i] =
20261 : : MLX5_MTR_DOMAIN_EGRESS_BIT;
20262 : : else
20263 : 0 : return -rte_mtr_error_set(error,
20264 : : ENOTSUP,
20265 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20266 : : NULL,
20267 : : "no fate action is found");
20268 : : }
20269 : : }
20270 : : }
20271 [ # # # # ]: 0 : if (next_mtr && *policy_mode == MLX5_MTR_POLICY_MODE_ALL) {
20272 : : uint64_t hierarchy_type_flag =
20273 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY | MLX5_FLOW_ACTION_JUMP;
20274 [ # # ]: 0 : if (!(action_flags[RTE_COLOR_GREEN] & hierarchy_type_flag) ||
20275 [ # # ]: 0 : !(action_flags[RTE_COLOR_YELLOW] & hierarchy_type_flag))
20276 : 0 : return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_METER_POLICY,
20277 : : NULL,
20278 : : "Unsupported action in meter hierarchy.");
20279 : : }
20280 : : /* If both colors have RSS, the attributes should be the same. */
20281 [ # # ]: 0 : if (flow_dv_mtr_policy_rss_compare(rss_color[RTE_COLOR_GREEN],
20282 : : rss_color[RTE_COLOR_YELLOW]))
20283 : 0 : return -rte_mtr_error_set(error, EINVAL,
20284 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20285 : : NULL, "policy RSS attr conflict");
20286 [ # # # # ]: 0 : if (rss_color[RTE_COLOR_GREEN] || rss_color[RTE_COLOR_YELLOW])
20287 : 0 : *is_rss = true;
20288 : : /* "domain_color[C]" is non-zero for each color, default is ALL. */
20289 [ # # ]: 0 : if (!def_green && !def_yellow &&
20290 [ # # ]: 0 : domain_color[RTE_COLOR_GREEN] != domain_color[RTE_COLOR_YELLOW] &&
20291 [ # # ]: 0 : !(action_flags[RTE_COLOR_GREEN] & MLX5_FLOW_ACTION_DROP) &&
20292 [ # # ]: 0 : !(action_flags[RTE_COLOR_YELLOW] & MLX5_FLOW_ACTION_DROP))
20293 : 0 : return -rte_mtr_error_set(error, EINVAL,
20294 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20295 : : NULL, "policy domains conflict");
20296 : : /*
20297 : : * At least one color policy is listed in the actions, the domains
20298 : : * to be supported should be the intersection.
20299 : : */
20300 : 0 : *domain_bitmap = domain_color[RTE_COLOR_GREEN] &
20301 : 0 : domain_color[RTE_COLOR_YELLOW];
20302 : 0 : return 0;
20303 : : }
20304 : :
20305 : : static int
20306 : 0 : flow_dv_sync_domain(struct rte_eth_dev *dev, uint32_t domains, uint32_t flags)
20307 : : {
20308 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
20309 : : int ret = 0;
20310 : :
20311 [ # # # # ]: 0 : if ((domains & RTE_PMD_MLX5_DOMAIN_BIT_NIC_RX) && priv->sh->rx_domain != NULL) {
20312 : : ret = mlx5_os_flow_dr_sync_domain(priv->sh->rx_domain,
20313 : : flags);
20314 [ # # ]: 0 : if (ret != 0)
20315 : : return ret;
20316 : : }
20317 [ # # # # ]: 0 : if ((domains & RTE_PMD_MLX5_DOMAIN_BIT_NIC_TX) && priv->sh->tx_domain != NULL) {
20318 : : ret = mlx5_os_flow_dr_sync_domain(priv->sh->tx_domain, flags);
20319 [ # # ]: 0 : if (ret != 0)
20320 : : return ret;
20321 : : }
20322 [ # # # # ]: 0 : if ((domains & RTE_PMD_MLX5_DOMAIN_BIT_FDB) && priv->sh->fdb_domain != NULL) {
20323 : : ret = mlx5_os_flow_dr_sync_domain(priv->sh->fdb_domain, flags);
20324 [ # # ]: 0 : if (ret != 0)
20325 : 0 : return ret;
20326 : : }
20327 : : return 0;
20328 : : }
20329 : :
20330 : : /**
20331 : : * Discover the number of available flow priorities
20332 : : * by trying to create a flow with the highest priority value
20333 : : * for each possible number.
20334 : : *
20335 : : * @param[in] dev
20336 : : * Ethernet device.
20337 : : * @param[in] vprio
20338 : : * List of possible number of available priorities.
20339 : : * @param[in] vprio_n
20340 : : * Size of @p vprio array.
20341 : : * @return
20342 : : * On success, number of available flow priorities.
20343 : : * On failure, a negative errno-style code and rte_errno is set.
20344 : : */
20345 : : static int
20346 : 0 : flow_dv_discover_priorities(struct rte_eth_dev *dev,
20347 : : const uint16_t *vprio, int vprio_n)
20348 : : {
20349 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
20350 : 0 : struct mlx5_indexed_pool *pool = priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW];
20351 : : struct rte_flow_item_eth eth;
20352 : 0 : struct rte_flow_item item = {
20353 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
20354 : : .spec = ð,
20355 : : .mask = ð,
20356 : : };
20357 : 0 : struct mlx5_flow_dv_matcher matcher = {
20358 : : .mask = {
20359 : : .size = sizeof(matcher.mask.buf),
20360 : : },
20361 : : };
20362 : : union mlx5_flow_tbl_key tbl_key;
20363 : : struct mlx5_flow flow;
20364 : : void *action;
20365 : : struct rte_flow_error error;
20366 : : uint8_t misc_mask;
20367 : : int i, err, ret = -ENOTSUP;
20368 : :
20369 : : /*
20370 : : * Prepare a flow with a catch-all pattern and a drop action.
20371 : : * Use drop queue, because shared drop action may be unavailable.
20372 : : */
20373 : 0 : action = priv->drop_queue.hrxq->action;
20374 [ # # ]: 0 : if (action == NULL) {
20375 : 0 : DRV_LOG(ERR, "Priority discovery requires a drop action");
20376 : 0 : rte_errno = ENOTSUP;
20377 : 0 : return -rte_errno;
20378 : : }
20379 : : memset(&flow, 0, sizeof(flow));
20380 : 0 : flow.handle = mlx5_ipool_zmalloc(pool, &flow.handle_idx);
20381 [ # # ]: 0 : if (flow.handle == NULL) {
20382 : 0 : DRV_LOG(ERR, "Cannot create flow handle");
20383 : 0 : rte_errno = ENOMEM;
20384 : 0 : return -rte_errno;
20385 : : }
20386 : 0 : flow.ingress = true;
20387 : 0 : flow.dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param);
20388 : 0 : flow.dv.actions[0] = action;
20389 : 0 : flow.dv.actions_n = 1;
20390 : : memset(ð, 0, sizeof(eth));
20391 : 0 : flow_dv_translate_item_eth(matcher.mask.buf, &item,
20392 : : /* inner */ false, /* group */ 0,
20393 : : MLX5_SET_MATCHER_SW_M);
20394 : 0 : flow_dv_translate_item_eth(flow.dv.value.buf, &item,
20395 : : /* inner */ false, /* group */ 0,
20396 : : MLX5_SET_MATCHER_SW_V);
20397 : 0 : matcher.crc = rte_raw_cksum(matcher.mask.buf, matcher.mask.size);
20398 [ # # ]: 0 : for (i = 0; i < vprio_n; i++) {
20399 : : /* Configure the next proposed maximum priority. */
20400 : 0 : matcher.priority = vprio[i] - 1;
20401 : : memset(&tbl_key, 0, sizeof(tbl_key));
20402 : 0 : err = flow_dv_matcher_register(dev, &matcher, &tbl_key, &flow,
20403 : : /* tunnel */ NULL,
20404 : : /* group */ 0,
20405 : : &error);
20406 [ # # ]: 0 : if (err != 0) {
20407 : : /* This action is pure SW and must always succeed. */
20408 : 0 : DRV_LOG(ERR, "Cannot register matcher");
20409 : 0 : ret = -rte_errno;
20410 : 0 : break;
20411 : : }
20412 : : /* Try to apply the flow to HW. */
20413 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(flow.handle->dvh.matcher->mask.buf);
20414 : : __flow_dv_adjust_buf_size(&flow.dv.value.size, misc_mask);
20415 : 0 : err = mlx5_flow_os_create_flow
20416 : : (flow.handle->dvh.matcher->matcher_object,
20417 : 0 : (void *)&flow.dv.value, flow.dv.actions_n,
20418 : : flow.dv.actions, &flow.handle->drv_flow);
20419 : : if (err == 0) {
20420 : 0 : claim_zero(mlx5_flow_os_destroy_flow
20421 : : (flow.handle->drv_flow));
20422 : 0 : flow.handle->drv_flow = NULL;
20423 : : }
20424 : 0 : claim_zero(flow_dv_matcher_release(dev, flow.handle));
20425 [ # # ]: 0 : if (err != 0)
20426 : : break;
20427 : 0 : ret = vprio[i];
20428 : : }
20429 : 0 : mlx5_ipool_free(pool, flow.handle_idx);
20430 : : /* Set rte_errno if no expected priority value matched. */
20431 [ # # ]: 0 : if (ret < 0)
20432 : 0 : rte_errno = -ret;
20433 : : return ret;
20434 : : }
20435 : :
20436 : : const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops = {
20437 : : .list_create = flow_legacy_list_create,
20438 : : .list_destroy = flow_legacy_list_destroy,
20439 : : .validate = flow_dv_validate,
20440 : : .prepare = flow_dv_prepare,
20441 : : .translate = flow_dv_translate,
20442 : : .apply = flow_dv_apply,
20443 : : .remove = flow_dv_remove,
20444 : : .destroy = flow_dv_destroy,
20445 : : .query = flow_dv_query,
20446 : : .create_mtr_tbls = flow_dv_create_mtr_tbls,
20447 : : .destroy_mtr_tbls = flow_dv_destroy_mtr_tbls,
20448 : : .destroy_mtr_drop_tbls = flow_dv_destroy_mtr_drop_tbls,
20449 : : .create_meter = flow_dv_mtr_alloc,
20450 : : .free_meter = flow_dv_aso_mtr_release_to_pool,
20451 : : .validate_mtr_acts = flow_dv_validate_mtr_policy_acts,
20452 : : .create_mtr_acts = flow_dv_create_mtr_policy_acts,
20453 : : .destroy_mtr_acts = flow_dv_destroy_mtr_policy_acts,
20454 : : .create_policy_rules = flow_dv_create_policy_rules,
20455 : : .destroy_policy_rules = flow_dv_destroy_policy_rules,
20456 : : .create_def_policy = flow_dv_create_def_policy,
20457 : : .destroy_def_policy = flow_dv_destroy_def_policy,
20458 : : .meter_sub_policy_rss_prepare = flow_dv_meter_sub_policy_rss_prepare,
20459 : : .meter_hierarchy_rule_create = flow_dv_meter_hierarchy_rule_create,
20460 : : .destroy_sub_policy_with_rxq = flow_dv_destroy_sub_policy_with_rxq,
20461 : : .counter_alloc = flow_dv_counter_allocate,
20462 : : .counter_free = flow_dv_counter_free,
20463 : : .counter_query = flow_dv_counter_query,
20464 : : .get_aged_flows = flow_dv_get_aged_flows,
20465 : : .action_validate = flow_dv_action_validate,
20466 : : .action_create = flow_dv_action_create,
20467 : : .action_destroy = flow_dv_action_destroy,
20468 : : .action_update = flow_dv_action_update,
20469 : : .action_query = flow_dv_action_query,
20470 : : .sync_domain = flow_dv_sync_domain,
20471 : : .discover_priorities = flow_dv_discover_priorities,
20472 : : .item_create = flow_dv_item_create,
20473 : : .item_release = flow_dv_item_release,
20474 : : };
20475 : :
20476 : : #endif /* HAVE_IBV_FLOW_DV_SUPPORT */
|