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_GTP_PSC_QFI:
1455 : 0 : return 6;
1456 : 0 : case RTE_FLOW_FIELD_POINTER:
1457 : : case RTE_FLOW_FIELD_VALUE:
1458 : 0 : return inherit < 0 ? 0 : inherit;
1459 : 0 : case RTE_FLOW_FIELD_IPV4_ECN:
1460 : : case RTE_FLOW_FIELD_IPV6_ECN:
1461 : : case RTE_FLOW_FIELD_METER_COLOR:
1462 : 0 : return 2;
1463 : : case RTE_FLOW_FIELD_HASH_RESULT:
1464 : : return 32;
1465 : 0 : default:
1466 : : MLX5_ASSERT(false);
1467 : : }
1468 : 0 : return 0;
1469 : : }
1470 : :
1471 : : static __rte_always_inline uint8_t
1472 : : flow_modify_info_mask_8(uint32_t length, uint32_t off)
1473 : : {
1474 : 0 : return (0xffu >> (8 - length)) << off;
1475 : : }
1476 : :
1477 : : static __rte_always_inline uint16_t
1478 : : flow_modify_info_mask_16(uint32_t length, uint32_t off)
1479 : : {
1480 [ # # # # : 0 : return rte_cpu_to_be_16((0xffffu >> (16 - length)) << off);
# # # # #
# # # # #
# # # # #
# # # ]
1481 : : }
1482 : :
1483 : : static __rte_always_inline uint32_t
1484 : : flow_modify_info_mask_32(uint32_t length, uint32_t off)
1485 : : {
1486 [ # # # # : 0 : return rte_cpu_to_be_32((0xffffffffu >> (32 - length)) << off);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1487 : : }
1488 : :
1489 : : static __rte_always_inline uint32_t
1490 : : flow_modify_info_mask_32_masked(uint32_t length, uint32_t off, uint32_t post_mask)
1491 : : {
1492 : 0 : uint32_t mask = (0xffffffffu >> (32 - length)) << off;
1493 : 0 : return rte_cpu_to_be_32(mask & post_mask);
1494 : : }
1495 : :
1496 : : static __rte_always_inline enum mlx5_modification_field
1497 : : mlx5_mpls_modi_field_get(const struct rte_flow_field_data *data)
1498 : : {
1499 : 0 : return MLX5_MODI_IN_MPLS_LABEL_0 + data->tag_index;
1500 : : }
1501 : :
1502 : : static __rte_always_inline int
1503 : : flow_geneve_opt_modi_field_get(struct mlx5_priv *priv,
1504 : : const struct rte_flow_field_data *data)
1505 : : {
1506 : : #ifdef HAVE_MLX5_HWS_SUPPORT
1507 : 0 : return mlx5_geneve_opt_modi_field_get(priv, data);
1508 : : #else
1509 : : (void)priv;
1510 : : (void)data;
1511 : : DRV_LOG(ERR, "GENEVE option modification is not supported.");
1512 : : rte_errno = ENOTSUP;
1513 : : return -rte_errno;
1514 : : #endif
1515 : : }
1516 : :
1517 : : static void
1518 : 0 : mlx5_modify_flex_item(const struct rte_eth_dev *dev,
1519 : : const struct mlx5_flex_item *flex,
1520 : : const struct rte_flow_field_data *data,
1521 : : struct field_modify_info *info,
1522 : : uint32_t *mask, uint32_t width)
1523 : : {
1524 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1525 : 0 : struct mlx5_hca_flex_attr *attr = &priv->sh->cdev->config.hca_attr.flex;
1526 : : uint32_t i, j;
1527 : : int id = 0;
1528 : 0 : uint32_t pos = 0;
1529 : : const struct mlx5_flex_pattern_field *map;
1530 : 0 : uint32_t offset = data->offset;
1531 : : uint32_t width_left = width;
1532 : : uint32_t cur_width = 0;
1533 : : uint32_t tmp_ofs;
1534 : : uint32_t idx = 0;
1535 : : struct field_modify_info tmp;
1536 : : int tmp_id;
1537 : :
1538 [ # # ]: 0 : if (!attr->query_match_sample_info) {
1539 : 0 : DRV_LOG(ERR, "FW doesn't support modify field with flex item.");
1540 : 0 : return;
1541 : : }
1542 : : /*
1543 : : * search for the mapping instance until Accumulated width is no
1544 : : * less than data->offset.
1545 : : */
1546 [ # # ]: 0 : for (i = 0; i < flex->mapnum; i++) {
1547 [ # # ]: 0 : if (flex->map[i].width + pos > data->offset)
1548 : : break;
1549 : 0 : pos += flex->map[i].width;
1550 : : }
1551 [ # # ]: 0 : if (i >= flex->mapnum)
1552 : : return;
1553 [ # # ]: 0 : tmp_ofs = pos < data->offset ? data->offset - pos : 0;
1554 [ # # # # ]: 0 : for (j = i; i < flex->mapnum && width_left > 0; ) {
1555 : 0 : map = flex->map + i;
1556 : 0 : id = mlx5_flex_get_sample_id(flex, i, &pos, false);
1557 [ # # ]: 0 : if (id == -1) {
1558 : 0 : i++;
1559 : : /* All left length is dummy */
1560 [ # # ]: 0 : if (pos >= data->offset + width)
1561 : : return;
1562 : 0 : cur_width = map->width;
1563 : : /* One mapping instance covers the whole width. */
1564 [ # # ]: 0 : } else if (pos + map->width >= (data->offset + width)) {
1565 : : cur_width = width_left;
1566 : : } else {
1567 : 0 : cur_width = cur_width + map->width - tmp_ofs;
1568 : 0 : pos += map->width;
1569 : : /*
1570 : : * Continue to search next until:
1571 : : * 1. Another flex parser ID.
1572 : : * 2. Width has been covered.
1573 : : */
1574 [ # # ]: 0 : for (j = i + 1; j < flex->mapnum; j++) {
1575 : 0 : tmp_id = mlx5_flex_get_sample_id(flex, j, &pos, false);
1576 [ # # ]: 0 : if (tmp_id == -1) {
1577 : : i = j;
1578 : 0 : pos -= flex->map[j].width;
1579 : 0 : break;
1580 : : }
1581 [ # # # # ]: 0 : if (id >= (int)flex->devx_fp->num_samples ||
1582 [ # # ]: 0 : id >= MLX5_GRAPH_NODE_SAMPLE_NUM ||
1583 [ # # ]: 0 : tmp_id >= (int)flex->devx_fp->num_samples ||
1584 : : tmp_id >= MLX5_GRAPH_NODE_SAMPLE_NUM)
1585 : : return;
1586 : 0 : if (flex->devx_fp->sample_info[id].modify_field_id !=
1587 [ # # ]: 0 : flex->devx_fp->sample_info[tmp_id].modify_field_id ||
1588 : 0 : flex->map[j].shift != flex->map[j - 1].width +
1589 [ # # ]: 0 : flex->map[j - 1].shift) {
1590 : : i = j;
1591 : : break;
1592 : : }
1593 [ # # ]: 0 : if ((pos + flex->map[j].width) >= (data->offset + width)) {
1594 : : cur_width = width_left;
1595 : : break;
1596 : : }
1597 : 0 : pos += flex->map[j].width;
1598 : 0 : cur_width += flex->map[j].width;
1599 : : }
1600 : : }
1601 [ # # ]: 0 : if (cur_width > width_left)
1602 : : cur_width = width_left;
1603 [ # # # # : 0 : else if (cur_width < width_left && (j == flex->mapnum || i == flex->mapnum))
# # ]
1604 : : return;
1605 : :
1606 : : MLX5_ASSERT(id < (int)flex->devx_fp->num_samples);
1607 [ # # # # ]: 0 : if (id >= (int)flex->devx_fp->num_samples || id >= MLX5_GRAPH_NODE_SAMPLE_NUM)
1608 : : return;
1609 : : /* Use invalid entry as placeholder for DUMMY mapping. */
1610 : 0 : info[idx] = (struct field_modify_info){cur_width / CHAR_BIT, offset / CHAR_BIT,
1611 [ # # ]: 0 : id == -1 ? MLX5_MODI_INVALID :
1612 : : (enum mlx5_modification_field)
1613 : 0 : flex->devx_fp->sample_info[id].modify_field_id,
1614 : 0 : map->shift + tmp_ofs, 1};
1615 : 0 : offset += cur_width;
1616 : 0 : width_left -= cur_width;
1617 [ # # ]: 0 : if (!mask) {
1618 : 0 : info[idx].offset = (32 - cur_width - map->shift - tmp_ofs);
1619 : 0 : info[idx].size = cur_width / CHAR_BIT + info[idx].offset / CHAR_BIT;
1620 : : }
1621 : : cur_width = 0;
1622 : : tmp_ofs = 0;
1623 : 0 : idx++;
1624 : : }
1625 [ # # ]: 0 : if (unlikely(width_left > 0)) {
1626 : : MLX5_ASSERT(false);
1627 : : return;
1628 : : }
1629 [ # # ]: 0 : if (mask)
1630 : 0 : memset(mask, 0xff, data->offset / CHAR_BIT + width / CHAR_BIT);
1631 : : /* Re-order the info to follow IPv6 address. */
1632 [ # # ]: 0 : for (i = 0; i < idx / 2; i++) {
1633 : 0 : tmp = info[i];
1634 : : MLX5_ASSERT(info[i].id);
1635 : : MLX5_ASSERT(info[idx - 1 - i].id);
1636 : 0 : info[i] = info[idx - 1 - i];
1637 : 0 : info[idx - 1 - i] = tmp;
1638 : : }
1639 : : }
1640 : :
1641 : : void
1642 : 0 : mlx5_flow_field_id_to_modify_info
1643 : : (const struct rte_flow_field_data *data,
1644 : : struct field_modify_info *info, uint32_t *mask,
1645 : : uint32_t width, struct rte_eth_dev *dev,
1646 : : const struct rte_flow_attr *attr, struct rte_flow_error *error)
1647 : : {
1648 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1649 : : enum mlx5_modification_field modi_id;
1650 : : uint32_t idx = 0;
1651 : : uint32_t off_be = 0;
1652 : : uint32_t length = 0;
1653 : :
1654 [ # # # # : 0 : switch ((int)data->field) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
1655 : : case RTE_FLOW_FIELD_START:
1656 : : /* not supported yet */
1657 : : MLX5_ASSERT(false);
1658 : : break;
1659 : 0 : case RTE_FLOW_FIELD_MAC_DST:
1660 : : MLX5_ASSERT(data->offset + width <= 48);
1661 : 0 : off_be = 48 - (data->offset + width);
1662 [ # # ]: 0 : if (off_be < 16) {
1663 [ # # ]: 0 : modi_id = CALC_MODI_ID(DMAC_15_0, data->level);
1664 : 0 : info[idx] = (struct field_modify_info){2, 4, modi_id};
1665 [ # # ]: 0 : length = off_be + width <= 16 ? width : 16 - off_be;
1666 [ # # ]: 0 : if (mask)
1667 : 0 : mask[1] = flow_modify_info_mask_16(length,
1668 : : off_be);
1669 : : else
1670 : 0 : info[idx].offset = off_be;
1671 : 0 : width -= length;
1672 [ # # ]: 0 : if (!width)
1673 : : break;
1674 : : off_be = 0;
1675 : : idx++;
1676 : : } else {
1677 : 0 : off_be -= 16;
1678 : : }
1679 [ # # ]: 0 : modi_id = CALC_MODI_ID(DMAC_47_16, data->level);
1680 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1681 [ # # ]: 0 : if (mask)
1682 : 0 : mask[0] = flow_modify_info_mask_32(width, off_be);
1683 : : else
1684 : 0 : info[idx].offset = off_be;
1685 : : break;
1686 : 0 : case RTE_FLOW_FIELD_MAC_SRC:
1687 : : MLX5_ASSERT(data->offset + width <= 48);
1688 : 0 : off_be = 48 - (data->offset + width);
1689 [ # # ]: 0 : if (off_be < 16) {
1690 [ # # ]: 0 : modi_id = CALC_MODI_ID(SMAC_15_0, data->level);
1691 : 0 : info[idx] = (struct field_modify_info){2, 4, modi_id};
1692 [ # # ]: 0 : length = off_be + width <= 16 ? width : 16 - off_be;
1693 [ # # ]: 0 : if (mask)
1694 : 0 : mask[1] = flow_modify_info_mask_16(length,
1695 : : off_be);
1696 : : else
1697 : 0 : info[idx].offset = off_be;
1698 : 0 : width -= length;
1699 [ # # ]: 0 : if (!width)
1700 : : break;
1701 : : off_be = 0;
1702 : : idx++;
1703 : : } else {
1704 : 0 : off_be -= 16;
1705 : : }
1706 [ # # ]: 0 : modi_id = CALC_MODI_ID(SMAC_47_16, data->level);
1707 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1708 [ # # ]: 0 : if (mask)
1709 : 0 : mask[0] = flow_modify_info_mask_32(width, off_be);
1710 : : else
1711 : 0 : info[idx].offset = off_be;
1712 : : break;
1713 : : case RTE_FLOW_FIELD_VLAN_TYPE:
1714 : : /* not supported yet */
1715 : : break;
1716 : 0 : case RTE_FLOW_FIELD_VLAN_ID:
1717 : : MLX5_ASSERT(data->offset + width <= 12);
1718 : 0 : off_be = 12 - (data->offset + width);
1719 : 0 : info[idx] = (struct field_modify_info){2, 0,
1720 : : MLX5_MODI_OUT_FIRST_VID};
1721 [ # # ]: 0 : if (mask)
1722 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1723 : : else
1724 : 0 : info[idx].offset = off_be;
1725 : : break;
1726 : 0 : case RTE_FLOW_FIELD_MAC_TYPE:
1727 : : MLX5_ASSERT(data->offset + width <= 16);
1728 : 0 : off_be = 16 - (data->offset + width);
1729 [ # # ]: 0 : modi_id = CALC_MODI_ID(ETHERTYPE, data->level);
1730 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
1731 [ # # ]: 0 : if (mask)
1732 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1733 : : else
1734 : 0 : info[idx].offset = off_be;
1735 : : break;
1736 : 0 : case RTE_FLOW_FIELD_IPV4_IHL:
1737 : : MLX5_ASSERT(data->offset + width <= 4);
1738 : 0 : off_be = 4 - (data->offset + width);
1739 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV4_IHL, data->level);
1740 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
1741 [ # # ]: 0 : if (mask)
1742 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1743 : : else
1744 : 0 : info[idx].offset = off_be;
1745 : : break;
1746 : 0 : case RTE_FLOW_FIELD_IPV4_DSCP:
1747 : : MLX5_ASSERT(data->offset + width <= 6);
1748 : 0 : off_be = 6 - (data->offset + width);
1749 [ # # ]: 0 : modi_id = CALC_MODI_ID(IP_DSCP, data->level);
1750 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
1751 [ # # ]: 0 : if (mask)
1752 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1753 : : else
1754 : 0 : info[idx].offset = off_be;
1755 : : break;
1756 : 0 : case RTE_FLOW_FIELD_IPV4_TOTAL_LEN:
1757 : : MLX5_ASSERT(data->offset + width <= 16);
1758 : 0 : off_be = 16 - (data->offset + width);
1759 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV4_TOTAL_LEN, data->level);
1760 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
1761 [ # # ]: 0 : if (mask)
1762 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1763 : : else
1764 : 0 : info[idx].offset = off_be;
1765 : : break;
1766 : 0 : case RTE_FLOW_FIELD_IPV4_TTL:
1767 : : MLX5_ASSERT(data->offset + width <= 8);
1768 : 0 : off_be = 8 - (data->offset + width);
1769 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV4_TTL, data->level);
1770 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
1771 [ # # ]: 0 : if (mask)
1772 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1773 : : else
1774 : 0 : info[idx].offset = off_be;
1775 : : break;
1776 : 0 : case RTE_FLOW_FIELD_IPV4_SRC:
1777 : : MLX5_ASSERT(data->offset + width <= 32);
1778 : 0 : off_be = 32 - (data->offset + width);
1779 [ # # ]: 0 : modi_id = CALC_MODI_ID(SIPV4, data->level);
1780 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1781 [ # # ]: 0 : if (mask)
1782 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1783 : : else
1784 : 0 : info[idx].offset = off_be;
1785 : : break;
1786 : 0 : case RTE_FLOW_FIELD_IPV4_DST:
1787 : : MLX5_ASSERT(data->offset + width <= 32);
1788 : 0 : off_be = 32 - (data->offset + width);
1789 [ # # ]: 0 : modi_id = CALC_MODI_ID(DIPV4, data->level);
1790 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1791 [ # # ]: 0 : if (mask)
1792 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1793 : : else
1794 : 0 : info[idx].offset = off_be;
1795 : : break;
1796 : : case RTE_FLOW_FIELD_IPV6_DSCP:
1797 : : MLX5_ASSERT(data->offset + width <= 6);
1798 : : /*
1799 : : * IPv6 DSCP uses OUT_IPV6_TRAFFIC_CLASS as ID but it starts from 2
1800 : : * bits left. Shift the mask left for IPv6 DSCP. Do it here because
1801 : : * it's needed to distinguish DSCP from ECN in data field construct
1802 : : */
1803 [ # # ]: 0 : if (mlx5_dv_modify_ipv6_traffic_class_supported(priv)) {
1804 : 0 : off_be = 6 - (data->offset + width) + MLX5_IPV6_HDR_DSCP_SHIFT;
1805 : 0 : info[idx] = (struct field_modify_info){1, 0,
1806 : : MLX5_MODI_OUT_IPV6_TRAFFIC_CLASS};
1807 : : } else {
1808 : 0 : off_be = 6 - (data->offset + width);
1809 : 0 : info[idx] = (struct field_modify_info){1, 0,
1810 : : MLX5_MODI_OUT_IP_DSCP};
1811 : : }
1812 [ # # ]: 0 : if (mask)
1813 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1814 : : else
1815 : 0 : info[idx].offset = off_be;
1816 : : break;
1817 : 0 : case RTE_FLOW_FIELD_IPV6_TRAFFIC_CLASS:
1818 : : MLX5_ASSERT(data->offset + width <= 8);
1819 : 0 : off_be = 8 - (data->offset + width);
1820 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV6_TRAFFIC_CLASS, data->level);
1821 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
1822 [ # # ]: 0 : if (mask)
1823 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1824 : : else
1825 : 0 : info[idx].offset = off_be;
1826 : : break;
1827 : 0 : case RTE_FLOW_FIELD_IPV6_FLOW_LABEL:
1828 : : MLX5_ASSERT(data->offset + width <= 20);
1829 : 0 : off_be = 20 - (data->offset + width);
1830 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV6_FLOW_LABEL, data->level);
1831 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1832 [ # # ]: 0 : if (mask)
1833 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1834 : : else
1835 : 0 : info[idx].offset = off_be;
1836 : : break;
1837 : 0 : case RTE_FLOW_FIELD_IPV6_PAYLOAD_LEN:
1838 : : MLX5_ASSERT(data->offset + width <= 16);
1839 : 0 : off_be = 16 - (data->offset + width);
1840 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV6_PAYLOAD_LEN, data->level);
1841 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
1842 [ # # ]: 0 : if (mask)
1843 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1844 : : else
1845 : 0 : info[idx].offset = off_be;
1846 : : break;
1847 : 0 : case RTE_FLOW_FIELD_IPV6_HOPLIMIT:
1848 : : MLX5_ASSERT(data->offset + width <= 8);
1849 : 0 : off_be = 8 - (data->offset + width);
1850 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV6_HOPLIMIT, data->level);
1851 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
1852 [ # # ]: 0 : if (mask)
1853 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1854 : : else
1855 : 0 : info[idx].offset = off_be;
1856 : : break;
1857 : 0 : case RTE_FLOW_FIELD_IPV6_SRC: {
1858 : : /*
1859 : : * Fields corresponding to IPv6 source address bytes
1860 : : * arranged according to network byte ordering.
1861 : : */
1862 : 0 : struct field_modify_info fields[] = {
1863 [ # # ]: 0 : { 4, 0, CALC_MODI_ID(SIPV6_127_96, data->level)},
1864 [ # # ]: 0 : { 4, 4, CALC_MODI_ID(SIPV6_95_64, data->level)},
1865 [ # # ]: 0 : { 4, 8, CALC_MODI_ID(SIPV6_63_32, data->level)},
1866 [ # # ]: 0 : { 4, 12, CALC_MODI_ID(SIPV6_31_0, data->level)},
1867 : : };
1868 : : /* First mask to be modified is the mask of 4th address byte. */
1869 : : uint32_t midx = 3;
1870 : :
1871 : : MLX5_ASSERT(data->offset + width <= 128);
1872 : 0 : off_be = 128 - (data->offset + width);
1873 [ # # ]: 0 : while (width > 0 && midx > 0) {
1874 [ # # ]: 0 : if (off_be < 32) {
1875 : 0 : info[idx] = fields[midx];
1876 : 0 : length = off_be + width <= 32 ?
1877 [ # # ]: 0 : width : 32 - off_be;
1878 [ # # ]: 0 : if (mask)
1879 [ # # ]: 0 : mask[midx] = flow_modify_info_mask_32
1880 : : (length, off_be);
1881 : : else
1882 : 0 : info[idx].offset = off_be;
1883 : 0 : width -= length;
1884 : : off_be = 0;
1885 : 0 : idx++;
1886 : : } else {
1887 : 0 : off_be -= 32;
1888 : : }
1889 : 0 : midx--;
1890 : : }
1891 [ # # ]: 0 : if (!width)
1892 : : break;
1893 : 0 : info[idx] = fields[midx];
1894 [ # # ]: 0 : if (mask)
1895 [ # # ]: 0 : mask[midx] = flow_modify_info_mask_32(width, off_be);
1896 : : else
1897 : 0 : info[idx].offset = off_be;
1898 : : break;
1899 : : }
1900 : 0 : case RTE_FLOW_FIELD_IPV6_DST: {
1901 : : /*
1902 : : * Fields corresponding to IPv6 destination address bytes
1903 : : * arranged according to network byte ordering.
1904 : : */
1905 : 0 : struct field_modify_info fields[] = {
1906 [ # # ]: 0 : { 4, 0, CALC_MODI_ID(DIPV6_127_96, data->level)},
1907 [ # # ]: 0 : { 4, 4, CALC_MODI_ID(DIPV6_95_64, data->level)},
1908 [ # # ]: 0 : { 4, 8, CALC_MODI_ID(DIPV6_63_32, data->level)},
1909 [ # # ]: 0 : { 4, 12, CALC_MODI_ID(DIPV6_31_0, data->level)},
1910 : : };
1911 : : /* First mask to be modified is the mask of 4th address byte. */
1912 : : uint32_t midx = 3;
1913 : :
1914 : : MLX5_ASSERT(data->offset + width <= 128);
1915 : 0 : off_be = 128 - (data->offset + width);
1916 [ # # ]: 0 : while (width > 0 && midx > 0) {
1917 [ # # ]: 0 : if (off_be < 32) {
1918 : 0 : info[idx] = fields[midx];
1919 : 0 : length = off_be + width <= 32 ?
1920 [ # # ]: 0 : width : 32 - off_be;
1921 [ # # ]: 0 : if (mask)
1922 [ # # ]: 0 : mask[midx] = flow_modify_info_mask_32
1923 : : (length, off_be);
1924 : : else
1925 : 0 : info[idx].offset = off_be;
1926 : 0 : width -= length;
1927 : : off_be = 0;
1928 : 0 : idx++;
1929 : : } else {
1930 : 0 : off_be -= 32;
1931 : : }
1932 : 0 : midx--;
1933 : : }
1934 [ # # ]: 0 : if (!width)
1935 : : break;
1936 : 0 : info[idx] = fields[midx];
1937 [ # # ]: 0 : if (mask)
1938 [ # # ]: 0 : mask[midx] = flow_modify_info_mask_32(width, off_be);
1939 : : else
1940 : 0 : info[idx].offset = off_be;
1941 : : break;
1942 : : }
1943 : 0 : case RTE_FLOW_FIELD_TCP_PORT_SRC:
1944 : : MLX5_ASSERT(data->offset + width <= 16);
1945 : 0 : off_be = 16 - (data->offset + width);
1946 [ # # ]: 0 : modi_id = CALC_MODI_ID(TCP_SPORT, data->level);
1947 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
1948 [ # # ]: 0 : if (mask)
1949 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1950 : : else
1951 : 0 : info[idx].offset = off_be;
1952 : : break;
1953 : 0 : case RTE_FLOW_FIELD_TCP_PORT_DST:
1954 : : MLX5_ASSERT(data->offset + width <= 16);
1955 : 0 : off_be = 16 - (data->offset + width);
1956 [ # # ]: 0 : modi_id = CALC_MODI_ID(TCP_DPORT, data->level);
1957 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
1958 [ # # ]: 0 : if (mask)
1959 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1960 : : else
1961 : 0 : info[idx].offset = off_be;
1962 : : break;
1963 : 0 : case RTE_FLOW_FIELD_TCP_SEQ_NUM:
1964 : : MLX5_ASSERT(data->offset + width <= 32);
1965 : 0 : off_be = 32 - (data->offset + width);
1966 [ # # ]: 0 : modi_id = CALC_MODI_ID(TCP_SEQ_NUM, data->level);
1967 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1968 [ # # ]: 0 : if (mask)
1969 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1970 : : else
1971 : 0 : info[idx].offset = off_be;
1972 : : break;
1973 : 0 : case RTE_FLOW_FIELD_TCP_ACK_NUM:
1974 : : MLX5_ASSERT(data->offset + width <= 32);
1975 : 0 : off_be = 32 - (data->offset + width);
1976 [ # # ]: 0 : modi_id = CALC_MODI_ID(TCP_ACK_NUM, data->level);
1977 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1978 [ # # ]: 0 : if (mask)
1979 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1980 : : else
1981 : 0 : info[idx].offset = off_be;
1982 : : break;
1983 : 0 : case RTE_FLOW_FIELD_TCP_FLAGS:
1984 : : MLX5_ASSERT(data->offset + width <= 9);
1985 : 0 : off_be = 9 - (data->offset + width);
1986 [ # # ]: 0 : modi_id = CALC_MODI_ID(TCP_FLAGS, data->level);
1987 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
1988 [ # # ]: 0 : if (mask)
1989 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1990 : : else
1991 : 0 : info[idx].offset = off_be;
1992 : : break;
1993 : 0 : case RTE_FLOW_FIELD_TCP_DATA_OFFSET:
1994 : : MLX5_ASSERT(data->offset + width <= 4);
1995 : 0 : off_be = 4 - (data->offset + width);
1996 [ # # ]: 0 : modi_id = CALC_MODI_ID(TCP_DATA_OFFSET, data->level);
1997 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
1998 [ # # ]: 0 : if (mask)
1999 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
2000 : : else
2001 : 0 : info[idx].offset = off_be;
2002 : : break;
2003 : 0 : case RTE_FLOW_FIELD_UDP_PORT_SRC:
2004 : : MLX5_ASSERT(data->offset + width <= 16);
2005 : 0 : off_be = 16 - (data->offset + width);
2006 [ # # ]: 0 : modi_id = CALC_MODI_ID(UDP_SPORT, data->level);
2007 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
2008 [ # # ]: 0 : if (mask)
2009 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
2010 : : else
2011 : 0 : info[idx].offset = off_be;
2012 : : break;
2013 : 0 : case RTE_FLOW_FIELD_UDP_PORT_DST:
2014 : : MLX5_ASSERT(data->offset + width <= 16);
2015 : 0 : off_be = 16 - (data->offset + width);
2016 [ # # ]: 0 : modi_id = CALC_MODI_ID(UDP_DPORT, data->level);
2017 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
2018 [ # # ]: 0 : if (mask)
2019 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
2020 : : else
2021 : 0 : info[idx].offset = off_be;
2022 : : break;
2023 : 0 : case RTE_FLOW_FIELD_VXLAN_VNI:
2024 : : case RTE_FLOW_FIELD_GENEVE_VNI:
2025 : : MLX5_ASSERT(data->offset + width <= 24);
2026 : : /* VNI is on bits 31-8 of TUNNEL_HDR_DW_1. */
2027 : 0 : off_be = 24 - (data->offset + width) + 8;
2028 : 0 : info[idx] = (struct field_modify_info){4, 0,
2029 : : MLX5_MODI_TUNNEL_HDR_DW_1};
2030 [ # # ]: 0 : if (mask)
2031 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2032 : : else
2033 : 0 : info[idx].offset = off_be;
2034 : : break;
2035 : 0 : case RTE_FLOW_FIELD_VXLAN_LAST_RSVD:
2036 : : MLX5_ASSERT(data->offset + width <= 8);
2037 : : /* Last_rsvd is on bits 7-0 of TUNNEL_HDR_DW_1. */
2038 : 0 : off_be = 8 - (data->offset + width);
2039 : 0 : info[idx] = (struct field_modify_info){1, 0, MLX5_MODI_TUNNEL_HDR_DW_1};
2040 [ # # ]: 0 : if (mask)
2041 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
2042 : : else
2043 : 0 : info[idx].offset = off_be;
2044 : : break;
2045 : : case RTE_FLOW_FIELD_GENEVE_OPT_TYPE:
2046 : : MLX5_ASSERT(data->offset + width <= 8);
2047 : : modi_id = flow_geneve_opt_modi_field_get(priv, data);
2048 [ # # ]: 0 : if (modi_id < 0)
2049 : : return;
2050 : : /* Type is on bits 16-8 of GENEVE option header (DW0). */
2051 : 0 : off_be = 32 - (16 + data->offset + width);
2052 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
2053 [ # # ]: 0 : if (mask)
2054 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2055 : : else
2056 : 0 : info[idx].offset = off_be;
2057 : : break;
2058 : : case RTE_FLOW_FIELD_GENEVE_OPT_CLASS:
2059 : : MLX5_ASSERT(data->offset + width <= 16);
2060 : : modi_id = flow_geneve_opt_modi_field_get(priv, data);
2061 [ # # ]: 0 : if (modi_id < 0)
2062 : : return;
2063 : : /* Class is on bits 31-16 of GENEVE option header (DW0). */
2064 : 0 : off_be = 32 - (data->offset + width);
2065 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
2066 [ # # ]: 0 : if (mask)
2067 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2068 : : else
2069 : 0 : info[idx].offset = off_be;
2070 : : break;
2071 : 0 : case RTE_FLOW_FIELD_GENEVE_OPT_DATA:
2072 [ # # ]: 0 : if ((data->offset % 32) + width > 32) {
2073 : 0 : DRV_LOG(ERR, "Geneve TLV option data is per DW.");
2074 : 0 : return;
2075 : : }
2076 : : modi_id = flow_geneve_opt_modi_field_get(priv, data);
2077 [ # # ]: 0 : if (modi_id < 0)
2078 : : return;
2079 : : /* Use offset inside DW. */
2080 : 0 : off_be = 32 - ((data->offset % 32) + width);
2081 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
2082 [ # # ]: 0 : if (mask)
2083 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2084 : : else
2085 : 0 : info[idx].offset = off_be;
2086 : : break;
2087 : 0 : case RTE_FLOW_FIELD_GTP_TEID:
2088 : : MLX5_ASSERT(data->offset + width <= 32);
2089 : 0 : off_be = 32 - (data->offset + width);
2090 : 0 : info[idx] = (struct field_modify_info){4, 0,
2091 : : MLX5_MODI_GTP_TEID};
2092 [ # # ]: 0 : if (mask)
2093 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2094 : : else
2095 : 0 : info[idx].offset = off_be;
2096 : : break;
2097 : 0 : case RTE_FLOW_FIELD_MPLS:
2098 : : MLX5_ASSERT(data->offset + width <= 32);
2099 : 0 : off_be = 32 - (data->offset + width);
2100 : : modi_id = mlx5_mpls_modi_field_get(data);
2101 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
2102 [ # # ]: 0 : if (mask)
2103 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2104 : : else
2105 : 0 : info[idx].offset = off_be;
2106 : : break;
2107 : : case RTE_FLOW_FIELD_TAG:
2108 : : {
2109 : : MLX5_ASSERT(data->offset + width <= 32);
2110 : : uint8_t tag_index = flow_tag_index_get(data);
2111 : : int reg;
2112 : :
2113 : : off_be = (tag_index == RTE_PMD_MLX5_LINEAR_HASH_TAG_INDEX) ?
2114 [ # # ]: 0 : 16 - (data->offset + width) + 16 : data->offset;
2115 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
2116 [ # # ]: 0 : reg = flow_hw_get_reg_id(dev,
2117 : : RTE_FLOW_ITEM_TYPE_TAG,
2118 : : tag_index);
2119 : : else
2120 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG,
2121 : : tag_index, error);
2122 [ # # ]: 0 : if (reg < 0)
2123 : : return;
2124 : : MLX5_ASSERT(reg != REG_NON);
2125 : : MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
2126 : 0 : info[idx] = (struct field_modify_info){4, 0,
2127 : 0 : reg_to_field[reg]};
2128 [ # # ]: 0 : if (mask)
2129 : 0 : mask[idx] = flow_modify_info_mask_32
2130 : : (width, off_be);
2131 : : else
2132 : 0 : info[idx].offset = off_be;
2133 : : }
2134 : : break;
2135 : 0 : case RTE_FLOW_FIELD_MARK:
2136 : : {
2137 : 0 : uint32_t mark_mask = priv->sh->dv_mark_mask;
2138 : : uint32_t mark_count = rte_popcount32(mark_mask);
2139 : : RTE_SET_USED(mark_count);
2140 : : MLX5_ASSERT(data->offset + width <= mark_count);
2141 : 0 : int reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK,
2142 : : 0, error);
2143 [ # # ]: 0 : if (reg < 0)
2144 : : return;
2145 : : MLX5_ASSERT(reg != REG_NON);
2146 : : MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
2147 : 0 : info[idx] = (struct field_modify_info){4, 0,
2148 : 0 : reg_to_field[reg]};
2149 [ # # ]: 0 : if (mask)
2150 : 0 : mask[idx] = flow_modify_info_mask_32_masked
2151 [ # # ]: 0 : (width, data->offset, mark_mask);
2152 : : else
2153 : 0 : info[idx].offset = data->offset;
2154 : : }
2155 : : break;
2156 : 0 : case RTE_FLOW_FIELD_META:
2157 : : {
2158 : 0 : uint32_t meta_mask = priv->sh->dv_meta_mask;
2159 : : uint32_t meta_count = rte_popcount32(meta_mask);
2160 : : RTE_SET_USED(meta_count);
2161 : : MLX5_ASSERT(data->offset + width <= meta_count);
2162 : 0 : int reg = flow_dv_get_metadata_reg(dev, attr, error);
2163 [ # # ]: 0 : if (reg < 0)
2164 : : return;
2165 : : MLX5_ASSERT(reg != REG_NON);
2166 : : MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
2167 : 0 : info[idx] = (struct field_modify_info){4, 0,
2168 : 0 : reg_to_field[reg]};
2169 [ # # ]: 0 : if (mask)
2170 : 0 : mask[idx] = flow_modify_info_mask_32_masked
2171 [ # # ]: 0 : (width, data->offset, meta_mask);
2172 : : else
2173 : 0 : info[idx].offset = data->offset;
2174 : : }
2175 : : break;
2176 : 0 : case RTE_FLOW_FIELD_IPV4_ECN:
2177 : : MLX5_ASSERT(data->offset + width <= 2);
2178 : 0 : off_be = 2 - (data->offset + width);
2179 [ # # ]: 0 : modi_id = CALC_MODI_ID(IP_ECN, data->level);
2180 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
2181 [ # # ]: 0 : if (mask)
2182 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
2183 : : else
2184 : 0 : info[idx].offset = off_be;
2185 : : break;
2186 : 0 : case RTE_FLOW_FIELD_IPV6_ECN:
2187 : : MLX5_ASSERT(data->offset + width <= 2);
2188 [ # # ]: 0 : off_be = 2 - (data->offset + width);
2189 [ # # ]: 0 : if (mlx5_dv_modify_ipv6_traffic_class_supported(priv))
2190 : 0 : info[idx] = (struct field_modify_info){1, 0,
2191 : : MLX5_MODI_OUT_IPV6_TRAFFIC_CLASS};
2192 : : else
2193 : 0 : info[idx] = (struct field_modify_info){1, 0,
2194 : : MLX5_MODI_OUT_IP_ECN};
2195 [ # # ]: 0 : if (mask)
2196 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
2197 : : else
2198 : 0 : info[idx].offset = off_be;
2199 : : break;
2200 : 0 : case RTE_FLOW_FIELD_GTP_PSC_QFI:
2201 : : MLX5_ASSERT(data->offset + width <= 8);
2202 : 0 : off_be = data->offset + 8;
2203 : 0 : info[idx] = (struct field_modify_info){4, 0,
2204 : : MLX5_MODI_GTPU_FIRST_EXT_DW_0};
2205 [ # # ]: 0 : if (mask)
2206 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2207 : : else
2208 : 0 : info[idx].offset = off_be;
2209 : : break;
2210 : 0 : case MLX5_RTE_FLOW_FIELD_META_REG:
2211 : : {
2212 [ # # ]: 0 : uint32_t meta_mask = priv->sh->dv_meta_mask;
2213 : : uint32_t meta_count = rte_popcount32(meta_mask);
2214 : : uint8_t reg = flow_tag_index_get(data);
2215 : :
2216 : : RTE_SET_USED(meta_count);
2217 : : MLX5_ASSERT(data->offset + width <= meta_count);
2218 : : MLX5_ASSERT(reg != REG_NON);
2219 : : MLX5_ASSERT(reg < RTE_DIM(reg_to_field));
2220 : 0 : info[idx] = (struct field_modify_info){4, 0, reg_to_field[reg]};
2221 [ # # ]: 0 : if (mask)
2222 : 0 : mask[idx] = flow_modify_info_mask_32_masked
2223 [ # # ]: 0 : (width, data->offset, meta_mask);
2224 : : else
2225 : 0 : info[idx].offset = data->offset;
2226 : : }
2227 : : break;
2228 : 0 : case RTE_FLOW_FIELD_METER_COLOR:
2229 : : {
2230 : : const uint32_t color_mask =
2231 : : (UINT32_C(1) << MLX5_MTR_COLOR_BITS) - 1;
2232 : : int reg;
2233 : :
2234 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
2235 : : reg = flow_hw_get_reg_id
2236 : : (dev,
2237 : : RTE_FLOW_ITEM_TYPE_METER_COLOR, 0);
2238 : : else
2239 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR,
2240 : : 0, error);
2241 [ # # ]: 0 : if (reg < 0)
2242 : : return;
2243 : : MLX5_ASSERT(reg != REG_NON);
2244 : : MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
2245 : 0 : info[idx] = (struct field_modify_info){4, 0,
2246 : 0 : reg_to_field[reg]};
2247 [ # # ]: 0 : if (mask)
2248 : 0 : mask[idx] = flow_modify_info_mask_32_masked
2249 [ # # ]: 0 : (width, data->offset, color_mask);
2250 : : else
2251 : 0 : info[idx].offset = data->offset;
2252 : : }
2253 : : break;
2254 : 0 : case RTE_FLOW_FIELD_IPV4_PROTO: /* Fall-through. */
2255 : : case RTE_FLOW_FIELD_IPV6_PROTO:
2256 : : MLX5_ASSERT(data->offset + width <= 8);
2257 : 0 : off_be = 8 - (data->offset + width);
2258 : 0 : info[idx] = (struct field_modify_info){1, 0, MLX5_MODI_OUT_IP_PROTOCOL};
2259 [ # # ]: 0 : if (mask)
2260 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
2261 : : else
2262 : 0 : info[idx].offset = off_be;
2263 : : break;
2264 : 0 : case RTE_FLOW_FIELD_ESP_PROTO:
2265 : : MLX5_ASSERT(data->offset + width <= 8);
2266 : 0 : off_be = 8 - (data->offset + width);
2267 : 0 : info[idx] = (struct field_modify_info){1, 0, MLX5_MODI_OUT_IPSEC_NEXT_HDR};
2268 [ # # ]: 0 : if (mask)
2269 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
2270 : : else
2271 : 0 : info[idx].offset = off_be;
2272 : : break;
2273 : 0 : case RTE_FLOW_FIELD_ESP_SPI:
2274 : : MLX5_ASSERT(data->offset + width <= 32);
2275 : 0 : off_be = 32 - (data->offset + width);
2276 [ # # ]: 0 : modi_id = CALC_MODI_ID(ESP_SPI, data->level);
2277 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
2278 [ # # ]: 0 : if (mask)
2279 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2280 : : else
2281 : 0 : info[idx].offset = off_be;
2282 : : break;
2283 : 0 : case RTE_FLOW_FIELD_ESP_SEQ_NUM:
2284 : : MLX5_ASSERT(data->offset + width <= 32);
2285 : 0 : off_be = 32 - (data->offset + width);
2286 [ # # ]: 0 : modi_id = CALC_MODI_ID(ESP_SEQ_NUM, data->level);
2287 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
2288 [ # # ]: 0 : if (mask)
2289 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2290 : : else
2291 : 0 : info[idx].offset = off_be;
2292 : : break;
2293 : 0 : case RTE_FLOW_FIELD_FLEX_ITEM:
2294 : : MLX5_ASSERT(data->flex_handle != NULL && !(data->offset & 0x7));
2295 : 0 : mlx5_modify_flex_item(dev, (const struct mlx5_flex_item *)data->flex_handle,
2296 : : data, info, mask, width);
2297 : 0 : break;
2298 : 0 : case RTE_FLOW_FIELD_HASH_RESULT:
2299 : : MLX5_ASSERT(data->offset + width <= 32);
2300 : 0 : off_be = 32 - (data->offset + width);
2301 : 0 : info[idx] = (struct field_modify_info){4, 0,
2302 : : MLX5_MODI_HASH_RESULT};
2303 [ # # ]: 0 : if (mask)
2304 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2305 : : else
2306 : 0 : info[idx].offset = off_be;
2307 : : break;
2308 : : case RTE_FLOW_FIELD_POINTER:
2309 : : case RTE_FLOW_FIELD_VALUE:
2310 : : default:
2311 : : MLX5_ASSERT(false);
2312 : : break;
2313 : : }
2314 : : }
2315 : :
2316 : : /**
2317 : : * Convert modify_field action to DV specification.
2318 : : *
2319 : : * @param[in] dev
2320 : : * Pointer to the rte_eth_dev structure.
2321 : : * @param[in,out] resource
2322 : : * Pointer to the modify-header resource.
2323 : : * @param[in] action
2324 : : * Pointer to action specification.
2325 : : * @param[in] attr
2326 : : * Attributes of flow that includes this item.
2327 : : * @param[out] error
2328 : : * Pointer to the error structure.
2329 : : *
2330 : : * @return
2331 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2332 : : */
2333 : : static int
2334 : 0 : flow_dv_convert_action_modify_field
2335 : : (struct rte_eth_dev *dev,
2336 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
2337 : : const struct rte_flow_action *action,
2338 : : const struct rte_flow_attr *attr,
2339 : : struct rte_flow_error *error)
2340 : : {
2341 : 0 : const struct rte_flow_action_modify_field *conf =
2342 : : (const struct rte_flow_action_modify_field *)(action->conf);
2343 : 0 : struct rte_flow_item item = {
2344 : : .spec = NULL,
2345 : : .mask = NULL
2346 : : };
2347 : 0 : struct field_modify_info field[MLX5_ACT_MAX_MOD_FIELDS] = {
2348 : : {0, 0, 0} };
2349 : 0 : struct field_modify_info dcopy[MLX5_ACT_MAX_MOD_FIELDS] = {
2350 : : {0, 0, 0} };
2351 : 0 : uint32_t mask[MLX5_ACT_MAX_MOD_FIELDS] = {0, 0, 0, 0, 0};
2352 : 0 : uint32_t type, meta = 0, dscp = 0;
2353 : :
2354 [ # # ]: 0 : if (conf->src.field == RTE_FLOW_FIELD_POINTER ||
2355 : : conf->src.field == RTE_FLOW_FIELD_VALUE) {
2356 : 0 : type = conf->operation == RTE_FLOW_MODIFY_SET ?
2357 [ # # ]: 0 : MLX5_MODIFICATION_TYPE_SET : MLX5_MODIFICATION_TYPE_ADD;
2358 : : /** For SET fill the destination field (field) first. */
2359 : 0 : mlx5_flow_field_id_to_modify_info(&conf->dst, field, mask,
2360 : 0 : conf->width, dev,
2361 : : attr, error);
2362 : 0 : item.spec = conf->src.field == RTE_FLOW_FIELD_POINTER ?
2363 [ # # ]: 0 : (void *)(uintptr_t)conf->src.pvalue :
2364 : : (void *)(uintptr_t)&conf->src.value;
2365 [ # # ]: 0 : if (conf->dst.field == RTE_FLOW_FIELD_META ||
2366 [ # # ]: 0 : conf->dst.field == RTE_FLOW_FIELD_TAG ||
2367 : : conf->dst.field == RTE_FLOW_FIELD_METER_COLOR) {
2368 : 0 : meta = *(const unaligned_uint32_t *)item.spec;
2369 [ # # ]: 0 : meta = rte_cpu_to_be_32(meta);
2370 : 0 : item.spec = &meta;
2371 : : }
2372 [ # # # # ]: 0 : if (mlx5_dv_modify_ipv6_traffic_class_supported(dev->data->dev_private) &&
2373 : 0 : conf->dst.field == RTE_FLOW_FIELD_IPV6_DSCP &&
2374 [ # # ]: 0 : !(mask[0] & MLX5_IPV6_HDR_ECN_MASK)) {
2375 : 0 : dscp = *(const unaligned_uint32_t *)item.spec;
2376 : : /*
2377 : : * IPv6 DSCP uses OUT_IPV6_TRAFFIC_CLASS as ID but it starts from 2
2378 : : * bits left. Shift the data left for IPv6 DSCP
2379 : : */
2380 : 0 : dscp <<= MLX5_IPV6_HDR_DSCP_SHIFT;
2381 : 0 : item.spec = &dscp;
2382 : : }
2383 : : } else {
2384 : : type = MLX5_MODIFICATION_TYPE_COPY;
2385 : : /** For COPY fill the destination field (dcopy) without mask. */
2386 : 0 : mlx5_flow_field_id_to_modify_info(&conf->dst, dcopy, NULL,
2387 : 0 : conf->width, dev,
2388 : : attr, error);
2389 : : /** Then construct the source field (field) with mask. */
2390 : 0 : mlx5_flow_field_id_to_modify_info(&conf->src, field, mask,
2391 : 0 : conf->width, dev,
2392 : : attr, error);
2393 : : }
2394 : 0 : item.mask = &mask;
2395 : 0 : return flow_dv_convert_modify_action(&item,
2396 : : field, dcopy, resource, type, error);
2397 : : }
2398 : :
2399 : : /**
2400 : : * Validate MARK item.
2401 : : *
2402 : : * @param[in] dev
2403 : : * Pointer to the rte_eth_dev structure.
2404 : : * @param[in] item
2405 : : * Item specification.
2406 : : * @param[in] attr
2407 : : * Attributes of flow that includes this item.
2408 : : * @param[out] error
2409 : : * Pointer to error structure.
2410 : : *
2411 : : * @return
2412 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2413 : : */
2414 : : static int
2415 : 0 : flow_dv_validate_item_mark(struct rte_eth_dev *dev,
2416 : : const struct rte_flow_item *item,
2417 : : const struct rte_flow_attr *attr __rte_unused,
2418 : : struct rte_flow_error *error)
2419 : : {
2420 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2421 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
2422 : 0 : const struct rte_flow_item_mark *spec = item->spec;
2423 : 0 : const struct rte_flow_item_mark *mask = item->mask;
2424 : 0 : const struct rte_flow_item_mark nic_mask = {
2425 : 0 : .id = priv->sh->dv_mark_mask,
2426 : : };
2427 : : int ret;
2428 : :
2429 [ # # ]: 0 : if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
2430 : 0 : return rte_flow_error_set(error, ENOTSUP,
2431 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2432 : : "extended metadata feature"
2433 : : " isn't enabled");
2434 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
2435 : 0 : return rte_flow_error_set(error, ENOTSUP,
2436 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2437 : : "extended metadata register"
2438 : : " isn't supported");
2439 [ # # ]: 0 : if (!nic_mask.id)
2440 : 0 : return rte_flow_error_set(error, ENOTSUP,
2441 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2442 : : "extended metadata register"
2443 : : " isn't available");
2444 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
2445 [ # # ]: 0 : if (ret < 0)
2446 : : return ret;
2447 [ # # ]: 0 : if (!spec)
2448 : 0 : return rte_flow_error_set(error, EINVAL,
2449 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2450 : 0 : item->spec,
2451 : : "data cannot be empty");
2452 [ # # ]: 0 : if (spec->id >= (MLX5_FLOW_MARK_MAX & nic_mask.id))
2453 : 0 : return rte_flow_error_set(error, EINVAL,
2454 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2455 : 0 : &spec->id,
2456 : : "mark id exceeds the limit");
2457 [ # # ]: 0 : if (!mask)
2458 : : mask = &nic_mask;
2459 [ # # ]: 0 : if (!mask->id)
2460 : 0 : return rte_flow_error_set(error, EINVAL,
2461 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2462 : : "mask cannot be zero");
2463 : :
2464 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2465 : : (const uint8_t *)&nic_mask,
2466 : : sizeof(struct rte_flow_item_mark),
2467 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2468 : : if (ret < 0)
2469 : : return ret;
2470 : : return 0;
2471 : : }
2472 : :
2473 : : /**
2474 : : * Validate META item.
2475 : : *
2476 : : * @param[in] dev
2477 : : * Pointer to the rte_eth_dev structure.
2478 : : * @param[in] item
2479 : : * Item specification.
2480 : : * @param[in] attr
2481 : : * Attributes of flow that includes this item.
2482 : : * @param[out] error
2483 : : * Pointer to error structure.
2484 : : *
2485 : : * @return
2486 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2487 : : */
2488 : : static int
2489 : 0 : flow_dv_validate_item_meta(struct rte_eth_dev *dev __rte_unused,
2490 : : const struct rte_flow_item *item,
2491 : : const struct rte_flow_attr *attr,
2492 : : struct rte_flow_error *error)
2493 : : {
2494 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2495 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
2496 : 0 : const struct rte_flow_item_meta *spec = item->spec;
2497 : 0 : const struct rte_flow_item_meta *mask = item->mask;
2498 : 0 : struct rte_flow_item_meta nic_mask = {
2499 : : .data = UINT32_MAX
2500 : : };
2501 : : int reg;
2502 : : int ret;
2503 : :
2504 [ # # ]: 0 : if (!spec)
2505 : 0 : return rte_flow_error_set(error, EINVAL,
2506 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2507 : : item->spec,
2508 : : "data cannot be empty");
2509 [ # # ]: 0 : if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
2510 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
2511 : 0 : return rte_flow_error_set(error, ENOTSUP,
2512 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2513 : : "extended metadata register"
2514 : : " isn't supported");
2515 : 0 : reg = flow_dv_get_metadata_reg(dev, attr, error);
2516 [ # # ]: 0 : if (reg < 0)
2517 : : return reg;
2518 [ # # ]: 0 : if (reg == REG_NON)
2519 : 0 : return rte_flow_error_set(error, ENOTSUP,
2520 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2521 : : "unavailable extended metadata register");
2522 [ # # ]: 0 : if (reg == REG_B)
2523 : 0 : return rte_flow_error_set(error, ENOTSUP,
2524 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2525 : : "match on reg_b "
2526 : : "isn't supported");
2527 [ # # ]: 0 : if (reg != REG_A)
2528 : 0 : nic_mask.data = priv->sh->dv_meta_mask;
2529 : : } else {
2530 [ # # ]: 0 : if (attr->transfer)
2531 : 0 : return rte_flow_error_set(error, ENOTSUP,
2532 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2533 : : "extended metadata feature "
2534 : : "should be enabled when "
2535 : : "meta item is requested "
2536 : : "with e-switch mode ");
2537 [ # # ]: 0 : if (attr->ingress)
2538 : 0 : return rte_flow_error_set(error, ENOTSUP,
2539 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2540 : : "match on metadata for ingress "
2541 : : "is not supported in legacy "
2542 : : "metadata mode");
2543 : : }
2544 [ # # ]: 0 : if (!mask)
2545 : : mask = &rte_flow_item_meta_mask;
2546 [ # # ]: 0 : if (!mask->data)
2547 : 0 : return rte_flow_error_set(error, EINVAL,
2548 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2549 : : "mask cannot be zero");
2550 : :
2551 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2552 : : (const uint8_t *)&nic_mask,
2553 : : sizeof(struct rte_flow_item_meta),
2554 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2555 : 0 : return ret;
2556 : : }
2557 : :
2558 : : /**
2559 : : * Validate TAG item.
2560 : : *
2561 : : * @param[in] dev
2562 : : * Pointer to the rte_eth_dev structure.
2563 : : * @param[in] item
2564 : : * Item specification.
2565 : : * @param[in] tag_bitmap
2566 : : * Tag index bitmap.
2567 : : * @param[in] attr
2568 : : * Attributes of flow that includes this item.
2569 : : * @param[out] error
2570 : : * Pointer to error structure.
2571 : : *
2572 : : * @return
2573 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2574 : : */
2575 : : static int
2576 : 0 : flow_dv_validate_item_tag(struct rte_eth_dev *dev,
2577 : : const struct rte_flow_item *item,
2578 : : uint32_t *tag_bitmap,
2579 : : const struct rte_flow_attr *attr __rte_unused,
2580 : : struct rte_flow_error *error)
2581 : : {
2582 : 0 : const struct rte_flow_item_tag *spec = item->spec;
2583 : 0 : const struct rte_flow_item_tag *mask = item->mask;
2584 : 0 : const struct rte_flow_item_tag nic_mask = {
2585 : : .data = RTE_BE32(UINT32_MAX),
2586 : : .index = 0xff,
2587 : : };
2588 : : int ret;
2589 : :
2590 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
2591 : 0 : return rte_flow_error_set(error, ENOTSUP,
2592 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2593 : : "extensive metadata register"
2594 : : " isn't supported");
2595 [ # # ]: 0 : if (!spec)
2596 : 0 : return rte_flow_error_set(error, EINVAL,
2597 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2598 : 0 : item->spec,
2599 : : "data cannot be empty");
2600 [ # # ]: 0 : if (!mask)
2601 : : mask = &rte_flow_item_tag_mask;
2602 [ # # ]: 0 : if (!mask->data)
2603 : 0 : return rte_flow_error_set(error, EINVAL,
2604 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2605 : : "mask cannot be zero");
2606 : :
2607 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2608 : : (const uint8_t *)&nic_mask,
2609 : : sizeof(struct rte_flow_item_tag),
2610 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2611 [ # # ]: 0 : if (ret < 0)
2612 : : return ret;
2613 [ # # ]: 0 : if (mask->index != 0xff)
2614 : 0 : return rte_flow_error_set(error, EINVAL,
2615 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2616 : : "partial mask for tag index"
2617 : : " is not supported");
2618 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, spec->index, error);
2619 [ # # ]: 0 : if (ret < 0)
2620 : : return ret;
2621 : : MLX5_ASSERT(ret != REG_NON);
2622 [ # # ]: 0 : if (*tag_bitmap & (1 << ret))
2623 : 0 : return rte_flow_error_set(error, EINVAL,
2624 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2625 : 0 : item->spec,
2626 : : "Duplicated tag index");
2627 : 0 : *tag_bitmap |= 1 << ret;
2628 : 0 : return 0;
2629 : : }
2630 : :
2631 : : /**
2632 : : * Validate vport item.
2633 : : *
2634 : : * @param[in] dev
2635 : : * Pointer to the rte_eth_dev structure.
2636 : : * @param[in] item
2637 : : * Item specification.
2638 : : * @param[in] attr
2639 : : * Attributes of flow that includes this item.
2640 : : * @param[in] item_flags
2641 : : * Bit-fields that holds the items detected until now.
2642 : : * @param[out] error
2643 : : * Pointer to error structure.
2644 : : *
2645 : : * @return
2646 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2647 : : */
2648 : : static int
2649 : 0 : flow_dv_validate_item_port_id(struct rte_eth_dev *dev,
2650 : : const struct rte_flow_item *item,
2651 : : const struct rte_flow_attr *attr,
2652 : : uint64_t item_flags,
2653 : : struct mlx5_priv **act_priv,
2654 : : struct rte_flow_error *error)
2655 : : {
2656 : 0 : const struct rte_flow_item_port_id *spec = item->spec;
2657 : 0 : const struct rte_flow_item_port_id *mask = item->mask;
2658 : 0 : const struct rte_flow_item_port_id switch_mask = {
2659 : : .id = 0xffffffff,
2660 : : };
2661 : : struct mlx5_priv *esw_priv;
2662 : : struct mlx5_priv *dev_priv;
2663 : : int ret;
2664 : :
2665 [ # # ]: 0 : if (!attr->transfer)
2666 : 0 : return rte_flow_error_set(error, EINVAL,
2667 : : RTE_FLOW_ERROR_TYPE_ITEM,
2668 : : NULL,
2669 : : "match on port id is valid only"
2670 : : " when transfer flag is enabled");
2671 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_PORT_ID)
2672 : 0 : return rte_flow_error_set(error, ENOTSUP,
2673 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2674 : : "multiple source ports are not"
2675 : : " supported");
2676 [ # # ]: 0 : if (!mask)
2677 : : mask = &switch_mask;
2678 [ # # ]: 0 : if (mask->id != 0xffffffff)
2679 : 0 : return rte_flow_error_set(error, ENOTSUP,
2680 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK,
2681 : : mask,
2682 : : "no support for partial mask on"
2683 : : " \"id\" field");
2684 : 0 : ret = mlx5_flow_item_acceptable
2685 : : (dev, item, (const uint8_t *)mask,
2686 : : (const uint8_t *)&rte_flow_item_port_id_mask,
2687 : : sizeof(struct rte_flow_item_port_id),
2688 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2689 [ # # ]: 0 : if (ret)
2690 : : return ret;
2691 [ # # ]: 0 : if (!spec)
2692 : : return 0;
2693 [ # # ]: 0 : if (spec->id == MLX5_PORT_ESW_MGR)
2694 : : return 0;
2695 : 0 : esw_priv = mlx5_port_to_eswitch_info(spec->id, false);
2696 [ # # ]: 0 : if (!esw_priv)
2697 : 0 : return rte_flow_error_set(error, rte_errno,
2698 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2699 : : "failed to obtain E-Switch info for"
2700 : : " port");
2701 : 0 : dev_priv = mlx5_dev_to_eswitch_info(dev);
2702 [ # # ]: 0 : if (!dev_priv)
2703 : 0 : return rte_flow_error_set(error, rte_errno,
2704 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2705 : : NULL,
2706 : : "failed to obtain E-Switch info");
2707 [ # # ]: 0 : if (esw_priv->domain_id != dev_priv->domain_id)
2708 : 0 : return rte_flow_error_set(error, EINVAL,
2709 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2710 : : "cannot match on a port from a"
2711 : : " different E-Switch");
2712 : 0 : *act_priv = esw_priv;
2713 : 0 : return 0;
2714 : : }
2715 : :
2716 : : /**
2717 : : * Validate represented port item.
2718 : : *
2719 : : * @param[in] dev
2720 : : * Pointer to the rte_eth_dev structure.
2721 : : * @param[in] item
2722 : : * Item specification.
2723 : : * @param[in] attr
2724 : : * Attributes of flow that includes this item.
2725 : : * @param[in] item_flags
2726 : : * Bit-fields that holds the items detected until now.
2727 : : * @param[out] error
2728 : : * Pointer to error structure.
2729 : : *
2730 : : * @return
2731 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2732 : : */
2733 : : static int
2734 : 0 : flow_dv_validate_item_represented_port(struct rte_eth_dev *dev,
2735 : : const struct rte_flow_item *item,
2736 : : const struct rte_flow_attr *attr,
2737 : : uint64_t item_flags,
2738 : : struct mlx5_priv **act_priv,
2739 : : struct rte_flow_error *error)
2740 : : {
2741 : 0 : const struct rte_flow_item_ethdev *spec = item->spec;
2742 : 0 : const struct rte_flow_item_ethdev *mask = item->mask;
2743 : 0 : const struct rte_flow_item_ethdev switch_mask = {
2744 : : .port_id = UINT16_MAX,
2745 : : };
2746 : : struct mlx5_priv *esw_priv;
2747 : : struct mlx5_priv *dev_priv;
2748 : : int ret;
2749 : :
2750 [ # # ]: 0 : if (!attr->transfer)
2751 : 0 : return rte_flow_error_set(error, EINVAL,
2752 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2753 : : "match on port id is valid only when transfer flag is enabled");
2754 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_REPRESENTED_PORT)
2755 : 0 : return rte_flow_error_set(error, ENOTSUP,
2756 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2757 : : "multiple source ports are not supported");
2758 [ # # ]: 0 : if (!mask)
2759 : : mask = &switch_mask;
2760 [ # # ]: 0 : if (mask->port_id != UINT16_MAX)
2761 : 0 : return rte_flow_error_set(error, ENOTSUP,
2762 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2763 : : "no support for partial mask on \"id\" field");
2764 : 0 : ret = mlx5_flow_item_acceptable
2765 : : (dev, item, (const uint8_t *)mask,
2766 : : (const uint8_t *)&rte_flow_item_ethdev_mask,
2767 : : sizeof(struct rte_flow_item_ethdev),
2768 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2769 [ # # ]: 0 : if (ret)
2770 : : return ret;
2771 [ # # # # ]: 0 : if (!spec || spec->port_id == UINT16_MAX)
2772 : : return 0;
2773 : 0 : esw_priv = mlx5_port_to_eswitch_info(spec->port_id, false);
2774 [ # # ]: 0 : if (!esw_priv)
2775 : 0 : return rte_flow_error_set(error, rte_errno,
2776 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2777 : : "failed to obtain E-Switch info for port");
2778 : 0 : dev_priv = mlx5_dev_to_eswitch_info(dev);
2779 [ # # ]: 0 : if (!dev_priv)
2780 : 0 : return rte_flow_error_set(error, rte_errno,
2781 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2782 : : NULL,
2783 : : "failed to obtain E-Switch info");
2784 [ # # ]: 0 : if (esw_priv->domain_id != dev_priv->domain_id)
2785 : 0 : return rte_flow_error_set(error, EINVAL,
2786 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2787 : : "cannot match on a port from a different E-Switch");
2788 : 0 : *act_priv = esw_priv;
2789 : 0 : return 0;
2790 : : }
2791 : :
2792 : : /**
2793 : : * Validate VLAN item.
2794 : : *
2795 : : * @param[in] item
2796 : : * Item specification.
2797 : : * @param[in] item_flags
2798 : : * Bit-fields that holds the items detected until now.
2799 : : * @param[in] dev
2800 : : * Ethernet device flow is being created on.
2801 : : * @param[out] error
2802 : : * Pointer to error structure.
2803 : : *
2804 : : * @return
2805 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2806 : : */
2807 : : int
2808 : 0 : mlx5_flow_dv_validate_item_vlan(const struct rte_flow_item *item,
2809 : : uint64_t item_flags,
2810 : : struct rte_eth_dev *dev,
2811 : : struct rte_flow_error *error)
2812 : : {
2813 : 0 : const struct rte_flow_item_vlan *mask = item->mask;
2814 : 0 : const struct rte_flow_item_vlan nic_mask = {
2815 : : .hdr.vlan_tci = RTE_BE16(UINT16_MAX),
2816 : : .hdr.eth_proto = RTE_BE16(UINT16_MAX),
2817 : : .has_more_vlan = 1,
2818 : : };
2819 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2820 : : int ret;
2821 : : const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
2822 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L4) :
2823 : : (MLX5_FLOW_LAYER_OUTER_L3 |
2824 : : MLX5_FLOW_LAYER_OUTER_L4);
2825 [ # # ]: 0 : const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
2826 : : MLX5_FLOW_LAYER_OUTER_VLAN;
2827 : :
2828 [ # # ]: 0 : if (item_flags & vlanm)
2829 : 0 : return rte_flow_error_set(error, EINVAL,
2830 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2831 : : "multiple VLAN layers not supported");
2832 [ # # ]: 0 : else if ((item_flags & l34m) != 0)
2833 : 0 : return rte_flow_error_set(error, EINVAL,
2834 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2835 : : "VLAN cannot follow L3/L4 layer");
2836 [ # # ]: 0 : if (!mask)
2837 : : mask = &rte_flow_item_vlan_mask;
2838 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2839 : : (const uint8_t *)&nic_mask,
2840 : : sizeof(struct rte_flow_item_vlan),
2841 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2842 [ # # ]: 0 : if (ret)
2843 : : return ret;
2844 [ # # # # ]: 0 : if (!tunnel && mask->hdr.vlan_tci != RTE_BE16(0x0fff)) {
2845 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2846 : :
2847 [ # # ]: 0 : if (priv->vmwa_context) {
2848 : : /*
2849 : : * Non-NULL context means we have a virtual machine
2850 : : * and SR-IOV enabled, we have to create VLAN interface
2851 : : * to make hypervisor to setup E-Switch vport
2852 : : * context correctly. We avoid creating the multiple
2853 : : * VLAN interfaces, so we cannot support VLAN tag mask.
2854 : : */
2855 : 0 : return rte_flow_error_set(error, EINVAL,
2856 : : RTE_FLOW_ERROR_TYPE_ITEM,
2857 : : item,
2858 : : "VLAN tag mask is not"
2859 : : " supported in virtual"
2860 : : " environment");
2861 : : }
2862 : : }
2863 : : return 0;
2864 : : }
2865 : :
2866 : : /*
2867 : : * GTP flags are contained in 1 byte of the format:
2868 : : * -------------------------------------------
2869 : : * | bit | 0 - 2 | 3 | 4 | 5 | 6 | 7 |
2870 : : * |-----------------------------------------|
2871 : : * | value | Version | PT | Res | E | S | PN |
2872 : : * -------------------------------------------
2873 : : *
2874 : : * Matching is supported only for GTP flags E, S, PN.
2875 : : */
2876 : : #define MLX5_GTP_FLAGS_MASK 0x07
2877 : :
2878 : : /**
2879 : : * Validate GTP item.
2880 : : *
2881 : : * @param[in] dev
2882 : : * Pointer to the rte_eth_dev structure.
2883 : : * @param[in] item
2884 : : * Item specification.
2885 : : * @param[in] item_flags
2886 : : * Bit-fields that holds the items detected until now.
2887 : : * @param[out] error
2888 : : * Pointer to error structure.
2889 : : *
2890 : : * @return
2891 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2892 : : */
2893 : : int
2894 : 0 : mlx5_flow_dv_validate_item_gtp(struct rte_eth_dev *dev,
2895 : : const struct rte_flow_item *item,
2896 : : uint64_t item_flags,
2897 : : struct rte_flow_error *error)
2898 : : {
2899 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2900 : 0 : const struct rte_flow_item_gtp *spec = item->spec;
2901 : 0 : const struct rte_flow_item_gtp *mask = item->mask;
2902 : 0 : const struct rte_flow_item_gtp nic_mask = {
2903 : : .hdr.gtp_hdr_info = MLX5_GTP_FLAGS_MASK,
2904 : : .hdr.msg_type = 0xff,
2905 : : .hdr.teid = RTE_BE32(0xffffffff),
2906 : : };
2907 : :
2908 [ # # ]: 0 : if (!priv->sh->cdev->config.hca_attr.tunnel_stateless_gtp)
2909 : 0 : return rte_flow_error_set(error, ENOTSUP,
2910 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2911 : : "GTP support is not enabled");
2912 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2913 : 0 : return rte_flow_error_set(error, ENOTSUP,
2914 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2915 : : "multiple tunnel layers not"
2916 : : " supported");
2917 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
2918 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2919 : 0 : return rte_flow_error_set(error, EINVAL,
2920 : : RTE_FLOW_ERROR_TYPE_ITEM,
2921 : : item, "no outer UDP layer found");
2922 : : }
2923 [ # # ]: 0 : if (!mask)
2924 : : mask = &rte_flow_item_gtp_mask;
2925 [ # # # # ]: 0 : if (spec && spec->hdr.gtp_hdr_info & ~MLX5_GTP_FLAGS_MASK)
2926 : 0 : return rte_flow_error_set(error, ENOTSUP,
2927 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2928 : : "Match is supported for GTP"
2929 : : " flags only");
2930 : 0 : return mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2931 : : (const uint8_t *)&nic_mask,
2932 : : sizeof(struct rte_flow_item_gtp),
2933 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2934 : : }
2935 : :
2936 : : /**
2937 : : * Validate GTP PSC item.
2938 : : *
2939 : : * @param[in] item
2940 : : * Item specification.
2941 : : * @param[in] last_item
2942 : : * Previous validated item in the pattern items.
2943 : : * @param[in] gtp_item
2944 : : * Previous GTP item specification.
2945 : : * @param root
2946 : : * Whether action is on root table.
2947 : : * @param[out] error
2948 : : * Pointer to error structure.
2949 : : *
2950 : : * @return
2951 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2952 : : */
2953 : : int
2954 : 0 : mlx5_flow_dv_validate_item_gtp_psc(const struct rte_eth_dev *dev,
2955 : : const struct rte_flow_item *item,
2956 : : uint64_t last_item,
2957 : : const struct rte_flow_item *gtp_item,
2958 : : bool root,
2959 : : struct rte_flow_error *error)
2960 : : {
2961 : : const struct rte_flow_item_gtp *gtp_spec;
2962 : : const struct rte_flow_item_gtp *gtp_mask;
2963 : : const struct rte_flow_item_gtp_psc *mask;
2964 : 0 : const struct rte_flow_item_gtp_psc nic_mask = {
2965 : : .hdr.type = 0xF,
2966 : : .hdr.qfi = 0x3F,
2967 : : };
2968 : :
2969 [ # # # # ]: 0 : if (!gtp_item || !(last_item & MLX5_FLOW_LAYER_GTP))
2970 : 0 : return rte_flow_error_set
2971 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2972 : : "GTP PSC item must be preceded with GTP item");
2973 : 0 : gtp_spec = gtp_item->spec;
2974 [ # # ]: 0 : gtp_mask = gtp_item->mask ? gtp_item->mask : &rte_flow_item_gtp_mask;
2975 : : /* GTP spec and E flag is requested to match zero. */
2976 [ # # ]: 0 : if (gtp_spec &&
2977 : 0 : (gtp_mask->hdr.gtp_hdr_info &
2978 [ # # ]: 0 : ~gtp_spec->hdr.gtp_hdr_info & MLX5_GTP_EXT_HEADER_FLAG))
2979 : 0 : return rte_flow_error_set
2980 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2981 : : "GTP E flag must be 1 to match GTP PSC");
2982 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
2983 : : /* Check the flow is not created in group zero. */
2984 [ # # ]: 0 : if (root)
2985 : 0 : return rte_flow_error_set
2986 : : (error, ENOTSUP,
2987 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2988 : : "GTP PSC is not supported for group 0");
2989 : : /* GTP spec is here and E flag is requested to match zero. */
2990 [ # # ]: 0 : if (!item->spec)
2991 : : return 0;
2992 : : }
2993 [ # # ]: 0 : mask = item->mask ? item->mask : &rte_flow_item_gtp_psc_mask;
2994 : 0 : return mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2995 : : (const uint8_t *)&nic_mask,
2996 : : sizeof(struct rte_flow_item_gtp_psc),
2997 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2998 : : }
2999 : :
3000 : : /*
3001 : : * Validate IPV4 item.
3002 : : * Use existing validation function mlx5_flow_validate_item_ipv4(), and
3003 : : * add specific validation of fragment_offset field,
3004 : : *
3005 : : * @param[in] dev
3006 : : * Pointer to the rte_eth_dev structure.
3007 : : * @param[in] item
3008 : : * Item specification.
3009 : : * @param[in] item_flags
3010 : : * Bit-fields that holds the items detected until now.
3011 : : * @param[in] last_item
3012 : : * Previous validated item in the pattern items.
3013 : : * @param[in] ether_type
3014 : : * Type in the ethernet layer header (including dot1q).
3015 : : * @param[in] acc_mask
3016 : : * Default acceptable mask (will be adjusted).
3017 : : * @param[out] error
3018 : : * Pointer to error structure.
3019 : : *
3020 : : * @return
3021 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3022 : : */
3023 : : int
3024 : 0 : mlx5_flow_dv_validate_item_ipv4(struct rte_eth_dev *dev,
3025 : : const struct rte_flow_item *item,
3026 : : uint64_t item_flags,
3027 : : uint64_t last_item,
3028 : : uint16_t ether_type,
3029 : : const struct rte_flow_item_ipv4 *acc_mask,
3030 : : struct rte_flow_error *error)
3031 : : {
3032 : : int ret;
3033 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3034 : 0 : struct mlx5_hca_attr *attr = &priv->sh->cdev->config.hca_attr;
3035 : 0 : const struct rte_flow_item_ipv4 *spec = item->spec;
3036 : 0 : const struct rte_flow_item_ipv4 *last = item->last;
3037 : 0 : const struct rte_flow_item_ipv4 *mask = item->mask;
3038 : : rte_be16_t fragment_offset_spec = 0;
3039 : : rte_be16_t fragment_offset_last = 0;
3040 : 0 : struct rte_flow_item_ipv4 actual_ipv4_mask = *acc_mask;
3041 : :
3042 [ # # # # ]: 0 : if (mask && (mask->hdr.version_ihl & RTE_IPV4_HDR_IHL_MASK)) {
3043 : 0 : int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
3044 : : bool ihl_cap = !tunnel ?
3045 [ # # ]: 0 : attr->outer_ipv4_ihl : attr->inner_ipv4_ihl;
3046 [ # # ]: 0 : if (!ihl_cap)
3047 : 0 : return rte_flow_error_set(error, ENOTSUP,
3048 : : RTE_FLOW_ERROR_TYPE_ITEM,
3049 : : item,
3050 : : "IPV4 ihl offload not supported");
3051 : 0 : actual_ipv4_mask.hdr.version_ihl = mask->hdr.version_ihl;
3052 : : }
3053 : 0 : ret = mlx5_flow_validate_item_ipv4(dev, item, item_flags, last_item,
3054 : : ether_type, &actual_ipv4_mask,
3055 : : MLX5_ITEM_RANGE_ACCEPTED, error);
3056 [ # # ]: 0 : if (ret < 0)
3057 : : return ret;
3058 [ # # ]: 0 : if (spec && mask)
3059 : 0 : fragment_offset_spec = spec->hdr.fragment_offset &
3060 : 0 : mask->hdr.fragment_offset;
3061 [ # # ]: 0 : if (!fragment_offset_spec)
3062 : : return 0;
3063 : : /*
3064 : : * spec and mask are valid, enforce using full mask to make sure the
3065 : : * complete value is used correctly.
3066 : : */
3067 [ # # ]: 0 : if ((mask->hdr.fragment_offset & RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
3068 : : != RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
3069 : 0 : return rte_flow_error_set(error, EINVAL,
3070 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK,
3071 : : item, "must use full mask for"
3072 : : " fragment_offset");
3073 : : /*
3074 : : * Match on fragment_offset 0x2000 means MF is 1 and frag-offset is 0,
3075 : : * indicating this is 1st fragment of fragmented packet.
3076 : : * This is not yet supported in MLX5, return appropriate error message.
3077 : : */
3078 [ # # ]: 0 : if (fragment_offset_spec == RTE_BE16(RTE_IPV4_HDR_MF_FLAG))
3079 : 0 : return rte_flow_error_set(error, ENOTSUP,
3080 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3081 : : "match on first fragment not "
3082 : : "supported");
3083 [ # # ]: 0 : if (fragment_offset_spec && !last)
3084 : 0 : return rte_flow_error_set(error, ENOTSUP,
3085 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3086 : : "specified value not supported");
3087 : : /* spec and last are valid, validate the specified range. */
3088 : 0 : fragment_offset_last = last->hdr.fragment_offset &
3089 : : mask->hdr.fragment_offset;
3090 : : /*
3091 : : * Match on fragment_offset spec 0x2001 and last 0x3fff
3092 : : * means MF is 1 and frag-offset is > 0.
3093 : : * This packet is fragment 2nd and onward, excluding last.
3094 : : * This is not yet supported in MLX5, return appropriate
3095 : : * error message.
3096 : : */
3097 : 0 : if (fragment_offset_spec == RTE_BE16(RTE_IPV4_HDR_MF_FLAG + 1) &&
3098 [ # # ]: 0 : fragment_offset_last == RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
3099 : 0 : return rte_flow_error_set(error, ENOTSUP,
3100 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST,
3101 : : last, "match on following "
3102 : : "fragments not supported");
3103 : : /*
3104 : : * Match on fragment_offset spec 0x0001 and last 0x1fff
3105 : : * means MF is 0 and frag-offset is > 0.
3106 : : * This packet is last fragment of fragmented packet.
3107 : : * This is not yet supported in MLX5, return appropriate
3108 : : * error message.
3109 : : */
3110 : 0 : if (fragment_offset_spec == RTE_BE16(1) &&
3111 [ # # ]: 0 : fragment_offset_last == RTE_BE16(RTE_IPV4_HDR_OFFSET_MASK))
3112 : 0 : return rte_flow_error_set(error, ENOTSUP,
3113 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST,
3114 : : last, "match on last "
3115 : : "fragment not supported");
3116 : : /*
3117 : : * Match on fragment_offset spec 0x0001 and last 0x3fff
3118 : : * means MF and/or frag-offset is not 0.
3119 : : * This is a fragmented packet.
3120 : : * Other range values are invalid and rejected.
3121 : : */
3122 : 0 : if (!(fragment_offset_spec == RTE_BE16(1) &&
3123 [ # # ]: 0 : fragment_offset_last == RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK)))
3124 : 0 : return rte_flow_error_set(error, ENOTSUP,
3125 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST, last,
3126 : : "specified range not supported");
3127 : : return 0;
3128 : : }
3129 : :
3130 : : /**
3131 : : * Validate IPV6 fragment extension item.
3132 : : *
3133 : : * @param[in] item
3134 : : * Item specification.
3135 : : * @param[in] item_flags
3136 : : * Bit-fields that holds the items detected until now.
3137 : : * @param[out] error
3138 : : * Pointer to error structure.
3139 : : *
3140 : : * @return
3141 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3142 : : */
3143 : : static int
3144 : 0 : flow_dv_validate_item_ipv6_frag_ext(const struct rte_eth_dev *dev,
3145 : : const struct rte_flow_item *item,
3146 : : uint64_t item_flags,
3147 : : struct rte_flow_error *error)
3148 : : {
3149 : 0 : const struct rte_flow_item_ipv6_frag_ext *spec = item->spec;
3150 : 0 : const struct rte_flow_item_ipv6_frag_ext *last = item->last;
3151 : 0 : const struct rte_flow_item_ipv6_frag_ext *mask = item->mask;
3152 : : rte_be16_t frag_data_spec = 0;
3153 : : rte_be16_t frag_data_last = 0;
3154 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
3155 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
3156 : : MLX5_FLOW_LAYER_OUTER_L4;
3157 : : int ret = 0;
3158 : 0 : struct rte_flow_item_ipv6_frag_ext nic_mask = {
3159 : : .hdr = {
3160 : : .next_header = 0xff,
3161 : : .frag_data = RTE_BE16(0xffff),
3162 : : },
3163 : : };
3164 : :
3165 [ # # ]: 0 : if (item_flags & l4m)
3166 : 0 : return rte_flow_error_set(error, EINVAL,
3167 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3168 : : "ipv6 fragment extension item cannot "
3169 : : "follow L4 item.");
3170 [ # # # # : 0 : if ((tunnel && !(item_flags & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
# # ]
3171 [ # # ]: 0 : (!tunnel && !(item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV6)))
3172 : 0 : return rte_flow_error_set(error, EINVAL,
3173 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3174 : : "ipv6 fragment extension item must "
3175 : : "follow ipv6 item");
3176 [ # # ]: 0 : if (spec && mask)
3177 : 0 : frag_data_spec = spec->hdr.frag_data & mask->hdr.frag_data;
3178 [ # # ]: 0 : if (!frag_data_spec)
3179 : : return 0;
3180 : : /*
3181 : : * spec and mask are valid, enforce using full mask to make sure the
3182 : : * complete value is used correctly.
3183 : : */
3184 [ # # ]: 0 : if ((mask->hdr.frag_data & RTE_BE16(RTE_IPV6_FRAG_USED_MASK)) !=
3185 : : RTE_BE16(RTE_IPV6_FRAG_USED_MASK))
3186 : 0 : return rte_flow_error_set(error, EINVAL,
3187 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK,
3188 : : item, "must use full mask for"
3189 : : " frag_data");
3190 : : /*
3191 : : * Match on frag_data 0x00001 means M is 1 and frag-offset is 0.
3192 : : * This is 1st fragment of fragmented packet.
3193 : : */
3194 [ # # ]: 0 : if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_MF_MASK))
3195 : 0 : return rte_flow_error_set(error, ENOTSUP,
3196 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3197 : : "match on first fragment not "
3198 : : "supported");
3199 [ # # ]: 0 : if (frag_data_spec && !last)
3200 : 0 : return rte_flow_error_set(error, EINVAL,
3201 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3202 : : "specified value not supported");
3203 : 0 : ret = mlx5_flow_item_acceptable
3204 : : (dev, item, (const uint8_t *)mask,
3205 : : (const uint8_t *)&nic_mask,
3206 : : sizeof(struct rte_flow_item_ipv6_frag_ext),
3207 : : MLX5_ITEM_RANGE_ACCEPTED, error);
3208 [ # # ]: 0 : if (ret)
3209 : : return ret;
3210 : : /* spec and last are valid, validate the specified range. */
3211 : 0 : frag_data_last = last->hdr.frag_data & mask->hdr.frag_data;
3212 : : /*
3213 : : * Match on frag_data spec 0x0009 and last 0xfff9
3214 : : * means M is 1 and frag-offset is > 0.
3215 : : * This packet is fragment 2nd and onward, excluding last.
3216 : : * This is not yet supported in MLX5, return appropriate
3217 : : * error message.
3218 : : */
3219 : 0 : if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_FO_ALIGN |
3220 : 0 : RTE_IPV6_EHDR_MF_MASK) &&
3221 [ # # ]: 0 : frag_data_last == RTE_BE16(RTE_IPV6_FRAG_USED_MASK))
3222 : 0 : return rte_flow_error_set(error, ENOTSUP,
3223 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST,
3224 : : last, "match on following "
3225 : : "fragments not supported");
3226 : : /*
3227 : : * Match on frag_data spec 0x0008 and last 0xfff8
3228 : : * means M is 0 and frag-offset is > 0.
3229 : : * This packet is last fragment of fragmented packet.
3230 : : * This is not yet supported in MLX5, return appropriate
3231 : : * error message.
3232 : : */
3233 : 0 : if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_FO_ALIGN) &&
3234 [ # # ]: 0 : frag_data_last == RTE_BE16(RTE_IPV6_EHDR_FO_MASK))
3235 : 0 : return rte_flow_error_set(error, ENOTSUP,
3236 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST,
3237 : : last, "match on last "
3238 : : "fragment not supported");
3239 : : /* Other range values are invalid and rejected. */
3240 : 0 : return rte_flow_error_set(error, EINVAL,
3241 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST, last,
3242 : : "specified range not supported");
3243 : : }
3244 : :
3245 : : /*
3246 : : * Validate ASO CT item.
3247 : : *
3248 : : * @param[in] dev
3249 : : * Pointer to the rte_eth_dev structure.
3250 : : * @param[in] item
3251 : : * Item specification.
3252 : : * @param[in] item_flags
3253 : : * Pointer to bit-fields that holds the items detected until now.
3254 : : * @param[out] error
3255 : : * Pointer to error structure.
3256 : : *
3257 : : * @return
3258 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3259 : : */
3260 : : int
3261 : 0 : mlx5_flow_dv_validate_item_aso_ct(struct rte_eth_dev *dev,
3262 : : const struct rte_flow_item *item,
3263 : : uint64_t *item_flags,
3264 : : struct rte_flow_error *error)
3265 : : {
3266 : 0 : const struct rte_flow_item_conntrack *spec = item->spec;
3267 : 0 : const struct rte_flow_item_conntrack *mask = item->mask;
3268 : : uint32_t flags;
3269 : :
3270 [ # # ]: 0 : if (*item_flags & MLX5_FLOW_LAYER_ASO_CT)
3271 : 0 : return rte_flow_error_set(error, EINVAL,
3272 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
3273 : : "Only one CT is supported");
3274 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
3275 [ # # ]: 0 : if (!mask)
3276 : : mask = &rte_flow_item_conntrack_mask;
3277 : 0 : flags = spec->flags & mask->flags;
3278 [ # # ]: 0 : if ((flags & RTE_FLOW_CONNTRACK_PKT_STATE_VALID) &&
3279 : : ((flags & RTE_FLOW_CONNTRACK_PKT_STATE_INVALID) ||
3280 [ # # ]: 0 : (flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD) ||
3281 : : (flags & RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED)))
3282 : 0 : return rte_flow_error_set(error, EINVAL,
3283 : : RTE_FLOW_ERROR_TYPE_ITEM,
3284 : : NULL,
3285 : : "Conflict status bits");
3286 [ # # ]: 0 : if (spec->flags & ~MLX5_FLOW_CONNTRACK_PKT_STATE_ALL)
3287 : 0 : return rte_flow_error_set(error, EINVAL,
3288 : : RTE_FLOW_ERROR_TYPE_ITEM,
3289 : : NULL,
3290 : : "Invalid CT item flags");
3291 : : }
3292 : : /* State change also needs to be considered. */
3293 : 0 : *item_flags |= MLX5_FLOW_LAYER_ASO_CT;
3294 : 0 : return 0;
3295 : : }
3296 : :
3297 : : /**
3298 : : * Validate the pop VLAN action.
3299 : : *
3300 : : * @param[in] dev
3301 : : * Pointer to the rte_eth_dev structure.
3302 : : * @param[in] action_flags
3303 : : * Holds the actions detected until now.
3304 : : * @param[in] action
3305 : : * Pointer to the pop vlan action.
3306 : : * @param[in] item_flags
3307 : : * The items found in this flow rule.
3308 : : * @param[in] attr
3309 : : * Pointer to flow attributes.
3310 : : * @param[out] error
3311 : : * Pointer to error structure.
3312 : : *
3313 : : * @return
3314 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3315 : : */
3316 : : static int
3317 : 0 : flow_dv_validate_action_pop_vlan(struct rte_eth_dev *dev,
3318 : : uint64_t action_flags,
3319 : : const struct rte_flow_action *action,
3320 : : uint64_t item_flags,
3321 : : const struct rte_flow_attr *attr,
3322 : : struct rte_flow_error *error)
3323 : : {
3324 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
3325 : :
3326 [ # # ]: 0 : if (!priv->sh->pop_vlan_action)
3327 : 0 : return rte_flow_error_set(error, ENOTSUP,
3328 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3329 : : NULL,
3330 : : "pop vlan action is not supported");
3331 [ # # ]: 0 : if (action_flags & MLX5_FLOW_VLAN_ACTIONS)
3332 : 0 : return rte_flow_error_set(error, ENOTSUP,
3333 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3334 : : "no support for multiple VLAN "
3335 : : "actions");
3336 : : /* Pop VLAN with preceding Decap requires inner header with VLAN. */
3337 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_DECAP) &&
3338 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_INNER_VLAN))
3339 : 0 : return rte_flow_error_set(error, ENOTSUP,
3340 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3341 : : NULL,
3342 : : "cannot pop vlan after decap without "
3343 : : "match on inner vlan in the flow");
3344 : : /* Pop VLAN without preceding Decap requires outer header with VLAN. */
3345 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_ACTION_DECAP) &&
3346 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
3347 : 0 : return rte_flow_error_set(error, ENOTSUP,
3348 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3349 : : NULL,
3350 : : "cannot pop vlan without a "
3351 : : "match on (outer) vlan in the flow");
3352 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3353 : 0 : return rte_flow_error_set(error, EINVAL,
3354 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3355 : : "wrong action order, port_id should "
3356 : : "be after pop VLAN action");
3357 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
3358 : 0 : return rte_flow_error_set(error, ENOTSUP,
3359 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3360 : : "pop vlan action for VF representor "
3361 : : "not supported on NIC table");
3362 : : return 0;
3363 : : }
3364 : :
3365 : : /**
3366 : : * Get VLAN default info from vlan match info.
3367 : : *
3368 : : * @param[in] items
3369 : : * the list of item specifications.
3370 : : * @param[out] vlan
3371 : : * pointer VLAN info to fill to.
3372 : : *
3373 : : * @return
3374 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3375 : : */
3376 : : static void
3377 : 0 : flow_dev_get_vlan_info_from_items(const struct rte_flow_item *items,
3378 : : struct rte_vlan_hdr *vlan)
3379 : : {
3380 : 0 : const struct rte_flow_item_vlan nic_mask = {
3381 : : .hdr.vlan_tci = RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK |
3382 : : MLX5DV_FLOW_VLAN_VID_MASK),
3383 : : .hdr.eth_proto = RTE_BE16(0xffff),
3384 : : };
3385 : :
3386 [ # # ]: 0 : if (items == NULL)
3387 : 0 : return;
3388 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
3389 : 0 : int type = items->type;
3390 : :
3391 : 0 : if (type == RTE_FLOW_ITEM_TYPE_VLAN ||
3392 [ # # ]: 0 : type == MLX5_RTE_FLOW_ITEM_TYPE_VLAN)
3393 : : break;
3394 : : }
3395 [ # # ]: 0 : if (items->type != RTE_FLOW_ITEM_TYPE_END) {
3396 : 0 : const struct rte_flow_item_vlan *vlan_m = items->mask;
3397 : 0 : const struct rte_flow_item_vlan *vlan_v = items->spec;
3398 : :
3399 : : /* If VLAN item in pattern doesn't contain data, return here. */
3400 [ # # ]: 0 : if (!vlan_v)
3401 : : return;
3402 [ # # ]: 0 : if (!vlan_m)
3403 : : vlan_m = &nic_mask;
3404 : : /* Only full match values are accepted */
3405 [ # # ]: 0 : if ((vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) ==
3406 : : MLX5DV_FLOW_VLAN_PCP_MASK_BE) {
3407 : 0 : vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
3408 : 0 : vlan->vlan_tci |=
3409 [ # # ]: 0 : rte_be_to_cpu_16(vlan_v->hdr.vlan_tci &
3410 : : MLX5DV_FLOW_VLAN_PCP_MASK_BE);
3411 : : }
3412 [ # # ]: 0 : if ((vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) ==
3413 : : MLX5DV_FLOW_VLAN_VID_MASK_BE) {
3414 : 0 : vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
3415 : 0 : vlan->vlan_tci |=
3416 [ # # ]: 0 : rte_be_to_cpu_16(vlan_v->hdr.vlan_tci &
3417 : : MLX5DV_FLOW_VLAN_VID_MASK_BE);
3418 : : }
3419 [ # # ]: 0 : if (vlan_m->hdr.eth_proto == nic_mask.hdr.eth_proto)
3420 [ # # ]: 0 : vlan->eth_proto = rte_be_to_cpu_16(vlan_v->hdr.eth_proto &
3421 : : vlan_m->hdr.eth_proto);
3422 : : }
3423 : : }
3424 : :
3425 : : /**
3426 : : * Validate the push VLAN action.
3427 : : *
3428 : : * @param[in] dev
3429 : : * Pointer to the rte_eth_dev structure.
3430 : : * @param[in] action_flags
3431 : : * Holds the actions detected until now.
3432 : : * @param[in] item_flags
3433 : : * The items found in this flow rule.
3434 : : * @param[in] action
3435 : : * Pointer to the action structure.
3436 : : * @param[in] attr
3437 : : * Pointer to flow attributes
3438 : : * @param[out] error
3439 : : * Pointer to error structure.
3440 : : *
3441 : : * @return
3442 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3443 : : */
3444 : : static int
3445 : 0 : flow_dv_validate_action_push_vlan(struct rte_eth_dev *dev,
3446 : : uint64_t action_flags,
3447 : : const struct rte_flow_item_vlan *vlan_m,
3448 : : const struct rte_flow_action *action,
3449 : : const struct rte_flow_attr *attr,
3450 : : struct rte_flow_error *error)
3451 : : {
3452 : 0 : const struct rte_flow_action_of_push_vlan *push_vlan = action->conf;
3453 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
3454 : :
3455 [ # # ]: 0 : if (push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_VLAN) &&
3456 : : push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_QINQ))
3457 : 0 : return rte_flow_error_set(error, EINVAL,
3458 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3459 : : "invalid vlan ethertype");
3460 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3461 : 0 : return rte_flow_error_set(error, EINVAL,
3462 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3463 : : "wrong action order, port_id should "
3464 : : "be after push VLAN");
3465 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
3466 : 0 : return rte_flow_error_set(error, ENOTSUP,
3467 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3468 : : "push vlan action for VF representor "
3469 : : "not supported on NIC table");
3470 [ # # ]: 0 : if (vlan_m &&
3471 [ # # # # ]: 0 : (vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) &&
3472 : : (vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) !=
3473 : 0 : MLX5DV_FLOW_VLAN_PCP_MASK_BE &&
3474 [ # # # # ]: 0 : !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP) &&
3475 : 0 : !(mlx5_flow_find_action
3476 : : (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP)))
3477 : 0 : return rte_flow_error_set(error, EINVAL,
3478 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3479 : : "not full match mask on VLAN PCP and "
3480 : : "there is no of_set_vlan_pcp action, "
3481 : : "push VLAN action cannot figure out "
3482 : : "PCP value");
3483 [ # # ]: 0 : if (vlan_m &&
3484 [ # # # # ]: 0 : (vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) &&
3485 : : (vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) !=
3486 : 0 : MLX5DV_FLOW_VLAN_VID_MASK_BE &&
3487 [ # # # # ]: 0 : !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID) &&
3488 : 0 : !(mlx5_flow_find_action
3489 : : (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID)))
3490 : 0 : return rte_flow_error_set(error, EINVAL,
3491 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3492 : : "not full match mask on VLAN VID and "
3493 : : "there is no of_set_vlan_vid action, "
3494 : : "push VLAN action cannot figure out "
3495 : : "VID value");
3496 : : (void)attr;
3497 : : return 0;
3498 : : }
3499 : :
3500 : : /**
3501 : : * Validate the set VLAN PCP.
3502 : : *
3503 : : * @param[in] action_flags
3504 : : * Holds the actions detected until now.
3505 : : * @param[in] actions
3506 : : * Pointer to the list of actions remaining in the flow rule.
3507 : : * @param[out] error
3508 : : * Pointer to error structure.
3509 : : *
3510 : : * @return
3511 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3512 : : */
3513 : : static int
3514 : 0 : flow_dv_validate_action_set_vlan_pcp(uint64_t action_flags,
3515 : : const struct rte_flow_action actions[],
3516 : : struct rte_flow_error *error)
3517 : : {
3518 : : const struct rte_flow_action *action = actions;
3519 : 0 : const struct rte_flow_action_of_set_vlan_pcp *conf = action->conf;
3520 : :
3521 [ # # ]: 0 : if (conf->vlan_pcp > 7)
3522 : 0 : return rte_flow_error_set(error, EINVAL,
3523 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3524 : : "VLAN PCP value is too big");
3525 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN))
3526 : 0 : return rte_flow_error_set(error, ENOTSUP,
3527 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3528 : : "set VLAN PCP action must follow "
3529 : : "the push VLAN action");
3530 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP)
3531 : 0 : return rte_flow_error_set(error, ENOTSUP,
3532 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3533 : : "Multiple VLAN PCP modification are "
3534 : : "not supported");
3535 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3536 : 0 : return rte_flow_error_set(error, EINVAL,
3537 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3538 : : "wrong action order, port_id should "
3539 : : "be after set VLAN PCP");
3540 : : return 0;
3541 : : }
3542 : :
3543 : : /**
3544 : : * Validate the set VLAN VID.
3545 : : *
3546 : : * @param[in] item_flags
3547 : : * Holds the items detected in this rule.
3548 : : * @param[in] action_flags
3549 : : * Holds the actions detected until now.
3550 : : * @param[in] actions
3551 : : * Pointer to the list of actions remaining in the flow rule.
3552 : : * @param[out] error
3553 : : * Pointer to error structure.
3554 : : *
3555 : : * @return
3556 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3557 : : */
3558 : : static int
3559 : 0 : flow_dv_validate_action_set_vlan_vid(uint64_t item_flags,
3560 : : uint64_t action_flags,
3561 : : const struct rte_flow_action actions[],
3562 : : struct rte_flow_error *error)
3563 : : {
3564 : : const struct rte_flow_action *action = actions;
3565 : 0 : const struct rte_flow_action_of_set_vlan_vid *conf = action->conf;
3566 : :
3567 [ # # # # ]: 0 : if (rte_be_to_cpu_16(conf->vlan_vid) > 0xFFE)
3568 : 0 : return rte_flow_error_set(error, EINVAL,
3569 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3570 : : "VLAN VID value is too big");
3571 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) &&
3572 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
3573 : 0 : return rte_flow_error_set(error, ENOTSUP,
3574 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3575 : : "set VLAN VID action must follow push"
3576 : : " VLAN action or match on VLAN item");
3577 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID)
3578 : 0 : return rte_flow_error_set(error, ENOTSUP,
3579 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3580 : : "Multiple VLAN VID modifications are "
3581 : : "not supported");
3582 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3583 : 0 : return rte_flow_error_set(error, EINVAL,
3584 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3585 : : "wrong action order, port_id should "
3586 : : "be after set VLAN VID");
3587 : : return 0;
3588 : : }
3589 : :
3590 : : /*
3591 : : * Validate the FLAG action.
3592 : : *
3593 : : * @param[in] dev
3594 : : * Pointer to the rte_eth_dev structure.
3595 : : * @param[in] action_flags
3596 : : * Holds the actions detected until now.
3597 : : * @param[in] attr
3598 : : * Pointer to flow attributes
3599 : : * @param[out] error
3600 : : * Pointer to error structure.
3601 : : *
3602 : : * @return
3603 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3604 : : */
3605 : : static int
3606 : 0 : flow_dv_validate_action_flag(struct rte_eth_dev *dev,
3607 : : uint64_t action_flags,
3608 : : const struct rte_flow_attr *attr,
3609 : : struct rte_flow_error *error)
3610 : : {
3611 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3612 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
3613 : : int ret;
3614 : :
3615 : : /* Fall back if no extended metadata register support. */
3616 [ # # ]: 0 : if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
3617 : 0 : return mlx5_flow_validate_action_flag(action_flags, attr,
3618 : : error);
3619 : : /* Extensive metadata mode requires registers. */
3620 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
3621 : 0 : return rte_flow_error_set(error, ENOTSUP,
3622 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3623 : : "no metadata registers "
3624 : : "to support flag action");
3625 [ # # ]: 0 : if (!(priv->sh->dv_mark_mask & MLX5_FLOW_MARK_DEFAULT))
3626 : 0 : return rte_flow_error_set(error, ENOTSUP,
3627 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3628 : : "extended metadata register"
3629 : : " isn't available");
3630 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3631 [ # # ]: 0 : if (ret < 0)
3632 : : return ret;
3633 : : MLX5_ASSERT(ret > 0);
3634 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
3635 : 0 : return rte_flow_error_set(error, EINVAL,
3636 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3637 : : "can't mark and flag in same flow");
3638 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_FLAG)
3639 : 0 : return rte_flow_error_set(error, EINVAL,
3640 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3641 : : "can't have 2 flag"
3642 : : " actions in same flow");
3643 : : return 0;
3644 : : }
3645 : :
3646 : : /**
3647 : : * Validate MARK action.
3648 : : *
3649 : : * @param[in] dev
3650 : : * Pointer to the rte_eth_dev structure.
3651 : : * @param[in] action
3652 : : * Pointer to action.
3653 : : * @param[in] action_flags
3654 : : * Holds the actions detected until now.
3655 : : * @param[in] attr
3656 : : * Pointer to flow attributes
3657 : : * @param[out] error
3658 : : * Pointer to error structure.
3659 : : *
3660 : : * @return
3661 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3662 : : */
3663 : : static int
3664 : 0 : flow_dv_validate_action_mark(struct rte_eth_dev *dev,
3665 : : const struct rte_flow_action *action,
3666 : : uint64_t action_flags,
3667 : : const struct rte_flow_attr *attr,
3668 : : struct rte_flow_error *error)
3669 : : {
3670 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3671 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
3672 [ # # ]: 0 : const struct rte_flow_action_mark *mark = action->conf;
3673 : : int ret;
3674 : :
3675 [ # # ]: 0 : if (is_tunnel_offload_active(dev))
3676 : 0 : return rte_flow_error_set(error, ENOTSUP,
3677 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3678 : : "no mark action "
3679 : : "if tunnel offload active");
3680 : : /* Fall back if no extended metadata register support. */
3681 [ # # ]: 0 : if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
3682 : 0 : return mlx5_flow_validate_action_mark(dev, action, action_flags,
3683 : : attr, error);
3684 : : /* Extensive metadata mode requires registers. */
3685 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
3686 : 0 : return rte_flow_error_set(error, ENOTSUP,
3687 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3688 : : "no metadata registers "
3689 : : "to support mark action");
3690 [ # # ]: 0 : if (!priv->sh->dv_mark_mask)
3691 : 0 : return rte_flow_error_set(error, ENOTSUP,
3692 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3693 : : "extended metadata register"
3694 : : " isn't available");
3695 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3696 [ # # ]: 0 : if (ret < 0)
3697 : : return ret;
3698 : : MLX5_ASSERT(ret > 0);
3699 [ # # ]: 0 : if (!mark)
3700 : 0 : return rte_flow_error_set(error, EINVAL,
3701 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3702 : : "configuration cannot be null");
3703 [ # # ]: 0 : if (mark->id >= (MLX5_FLOW_MARK_MAX & priv->sh->dv_mark_mask))
3704 : 0 : return rte_flow_error_set(error, EINVAL,
3705 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3706 : 0 : &mark->id,
3707 : : "mark id exceeds the limit");
3708 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_FLAG)
3709 : 0 : return rte_flow_error_set(error, EINVAL,
3710 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3711 : : "can't flag and mark in same flow");
3712 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
3713 : 0 : return rte_flow_error_set(error, EINVAL,
3714 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3715 : : "can't have 2 mark actions in same"
3716 : : " flow");
3717 : : return 0;
3718 : : }
3719 : :
3720 : : /**
3721 : : * Validate SET_META action.
3722 : : *
3723 : : * @param[in] dev
3724 : : * Pointer to the rte_eth_dev structure.
3725 : : * @param[in] action
3726 : : * Pointer to the action structure.
3727 : : * @param[in] action_flags
3728 : : * Holds the actions detected until now.
3729 : : * @param[in] attr
3730 : : * Pointer to flow attributes
3731 : : * @param[out] error
3732 : : * Pointer to error structure.
3733 : : *
3734 : : * @return
3735 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3736 : : */
3737 : : static int
3738 : 0 : flow_dv_validate_action_set_meta(struct rte_eth_dev *dev,
3739 : : const struct rte_flow_action *action,
3740 : : uint64_t action_flags __rte_unused,
3741 : : const struct rte_flow_attr *attr,
3742 : : struct rte_flow_error *error)
3743 : : {
3744 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3745 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
3746 : : const struct rte_flow_action_set_meta *conf;
3747 : : uint32_t nic_mask = UINT32_MAX;
3748 : : int reg;
3749 : :
3750 [ # # # # ]: 0 : if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
3751 : 0 : !mlx5_flow_ext_mreg_supported(dev))
3752 : 0 : return rte_flow_error_set(error, ENOTSUP,
3753 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3754 : : "extended metadata register"
3755 : : " isn't supported");
3756 : 0 : reg = flow_dv_get_metadata_reg(dev, attr, error);
3757 [ # # ]: 0 : if (reg < 0)
3758 : : return reg;
3759 [ # # ]: 0 : if (reg == REG_NON)
3760 : 0 : return rte_flow_error_set(error, ENOTSUP,
3761 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3762 : : "unavailable extended metadata register");
3763 [ # # ]: 0 : if (reg != REG_A && reg != REG_B) {
3764 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3765 : :
3766 : 0 : nic_mask = priv->sh->dv_meta_mask;
3767 : : }
3768 [ # # ]: 0 : if (!(action->conf))
3769 : 0 : return rte_flow_error_set(error, EINVAL,
3770 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3771 : : "configuration cannot be null");
3772 : : conf = (const struct rte_flow_action_set_meta *)action->conf;
3773 [ # # ]: 0 : if (!conf->mask)
3774 : 0 : return rte_flow_error_set(error, EINVAL,
3775 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3776 : : "zero mask doesn't have any effect");
3777 [ # # ]: 0 : if (conf->mask & ~nic_mask)
3778 : 0 : return rte_flow_error_set(error, EINVAL,
3779 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3780 : : "meta data must be within reg C0");
3781 : : return 0;
3782 : : }
3783 : :
3784 : : /**
3785 : : * Validate SET_TAG action.
3786 : : *
3787 : : * @param[in] dev
3788 : : * Pointer to the rte_eth_dev structure.
3789 : : * @param[in] action
3790 : : * Pointer to the action structure.
3791 : : * @param[in] action_flags
3792 : : * Holds the actions detected until now.
3793 : : * @param[in] attr
3794 : : * Pointer to flow attributes
3795 : : * @param[out] error
3796 : : * Pointer to error structure.
3797 : : *
3798 : : * @return
3799 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3800 : : */
3801 : : static int
3802 : 0 : flow_dv_validate_action_set_tag(struct rte_eth_dev *dev,
3803 : : const struct rte_flow_action *action,
3804 : : uint64_t action_flags,
3805 : : const struct rte_flow_attr *attr,
3806 : : struct rte_flow_error *error)
3807 : : {
3808 : : const struct rte_flow_action_set_tag *conf;
3809 : : const uint64_t terminal_action_flags =
3810 : : MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE |
3811 : : MLX5_FLOW_ACTION_RSS;
3812 : : int ret;
3813 : :
3814 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
3815 : 0 : return rte_flow_error_set(error, ENOTSUP,
3816 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3817 : : "extensive metadata register"
3818 : : " isn't supported");
3819 [ # # ]: 0 : if (!(action->conf))
3820 : 0 : return rte_flow_error_set(error, EINVAL,
3821 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3822 : : "configuration cannot be null");
3823 : : conf = (const struct rte_flow_action_set_tag *)action->conf;
3824 [ # # ]: 0 : if (!conf->mask)
3825 : 0 : return rte_flow_error_set(error, EINVAL,
3826 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3827 : : "zero mask doesn't have any effect");
3828 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
3829 [ # # ]: 0 : if (ret < 0)
3830 : : return ret;
3831 [ # # # # ]: 0 : if (attr->ingress && (action_flags & terminal_action_flags))
3832 : 0 : return rte_flow_error_set(error, EINVAL,
3833 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3834 : : "set_tag has no effect"
3835 : : " with terminal actions");
3836 : : return 0;
3837 : : }
3838 : :
3839 : : /**
3840 : : * Indicates whether ASO aging is supported.
3841 : : *
3842 : : * @param[in] priv
3843 : : * Pointer to device private context structure.
3844 : : * @param[in] root
3845 : : * Whether action is on root table.
3846 : : *
3847 : : * @return
3848 : : * True when ASO aging is supported, false otherwise.
3849 : : */
3850 : : static inline bool
3851 : : flow_hit_aso_supported(const struct mlx5_priv *priv, bool root)
3852 : : {
3853 : : MLX5_ASSERT(priv);
3854 [ # # # # : 0 : return (priv->sh->flow_hit_aso_en && !root);
# # # # #
# ]
3855 : : }
3856 : :
3857 : : /**
3858 : : * Validate count action.
3859 : : *
3860 : : * @param[in] dev
3861 : : * Pointer to rte_eth_dev structure.
3862 : : * @param[in] shared
3863 : : * Indicator if action is shared.
3864 : : * @param[in] action_flags
3865 : : * Holds the actions detected until now.
3866 : : * @param[in] root
3867 : : * Whether action is on root table.
3868 : : * @param[out] error
3869 : : * Pointer to error structure.
3870 : : *
3871 : : * @return
3872 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3873 : : */
3874 : : static int
3875 : 0 : flow_dv_validate_action_count(struct rte_eth_dev *dev, bool shared,
3876 : : uint64_t action_flags,
3877 : : bool root,
3878 : : struct rte_flow_error *error)
3879 : : {
3880 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3881 : :
3882 [ # # ]: 0 : if (!priv->sh->cdev->config.devx)
3883 : 0 : goto notsup_err;
3884 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_COUNT)
3885 : 0 : return rte_flow_error_set(error, EINVAL,
3886 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3887 : : "duplicate count actions set");
3888 [ # # # # : 0 : if (shared && (action_flags & MLX5_FLOW_ACTION_AGE) &&
# # ]
3889 : : !flow_hit_aso_supported(priv, root))
3890 : 0 : return rte_flow_error_set(error, EINVAL,
3891 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3892 : : "old age and indirect count combination is not supported");
3893 : : #ifdef HAVE_IBV_FLOW_DEVX_COUNTERS
3894 : : return 0;
3895 : : #endif
3896 : : notsup_err:
3897 : 0 : return rte_flow_error_set
3898 : : (error, ENOTSUP,
3899 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3900 : : NULL,
3901 : : "count action not supported");
3902 : : }
3903 : :
3904 : : /**
3905 : : * Validate the L2 encap action.
3906 : : *
3907 : : * @param[in] dev
3908 : : * Pointer to the rte_eth_dev structure.
3909 : : * @param[in] action_flags
3910 : : * Holds the actions detected until now.
3911 : : * @param[in] action
3912 : : * Pointer to the action structure.
3913 : : * @param[in] attr
3914 : : * Pointer to flow attributes.
3915 : : * @param[out] error
3916 : : * Pointer to error structure.
3917 : : *
3918 : : * @return
3919 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3920 : : */
3921 : : int
3922 : 0 : mlx5_flow_dv_validate_action_l2_encap(struct rte_eth_dev *dev,
3923 : : uint64_t action_flags,
3924 : : const struct rte_flow_action *action,
3925 : : const struct rte_flow_attr *attr,
3926 : : struct rte_flow_error *error)
3927 : : {
3928 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
3929 : :
3930 [ # # ]: 0 : if (!(action->conf))
3931 : 0 : return rte_flow_error_set(error, EINVAL,
3932 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3933 : : "configuration cannot be null");
3934 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
3935 : 0 : return rte_flow_error_set(error, EINVAL,
3936 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3937 : : "can only have a single encap action "
3938 : : "in a flow");
3939 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
3940 : 0 : return rte_flow_error_set(error, ENOTSUP,
3941 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3942 : : "encap action for VF representor "
3943 : : "not supported on NIC table");
3944 : : return 0;
3945 : : }
3946 : :
3947 : : /**
3948 : : * Validate a decap action.
3949 : : *
3950 : : * @param[in] dev
3951 : : * Pointer to the rte_eth_dev structure.
3952 : : * @param[in] action_flags
3953 : : * Holds the actions detected until now.
3954 : : * @param[in] action
3955 : : * Pointer to the action structure.
3956 : : * @param[in] item_flags
3957 : : * Holds the items detected.
3958 : : * @param[in] attr
3959 : : * Pointer to flow attributes
3960 : : * @param[out] error
3961 : : * Pointer to error structure.
3962 : : *
3963 : : * @return
3964 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3965 : : */
3966 : : int
3967 : 0 : mlx5_flow_dv_validate_action_decap(struct rte_eth_dev *dev,
3968 : : uint64_t action_flags,
3969 : : const struct rte_flow_action *action,
3970 : : const uint64_t item_flags,
3971 : : const struct rte_flow_attr *attr,
3972 : : struct rte_flow_error *error)
3973 : : {
3974 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
3975 : :
3976 [ # # ]: 0 : if (priv->sh->cdev->config.hca_attr.scatter_fcs_w_decap_disable &&
3977 [ # # ]: 0 : !priv->sh->config.decap_en)
3978 : 0 : return rte_flow_error_set(error, ENOTSUP,
3979 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3980 : : "decap is not enabled");
3981 [ # # ]: 0 : if (action_flags & MLX5_FLOW_XCAP_ACTIONS)
3982 : 0 : return rte_flow_error_set(error, ENOTSUP,
3983 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3984 [ # # ]: 0 : action_flags &
3985 : : MLX5_FLOW_ACTION_DECAP ? "can only "
3986 : : "have a single decap action" : "decap "
3987 : : "after encap is not supported");
3988 [ # # ]: 0 : if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
3989 : 0 : return rte_flow_error_set(error, EINVAL,
3990 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3991 : : "can't have decap action after"
3992 : : " modify action");
3993 [ # # ]: 0 : if (attr->egress)
3994 : 0 : return rte_flow_error_set(error, ENOTSUP,
3995 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
3996 : : NULL,
3997 : : "decap action not supported for "
3998 : : "egress");
3999 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
4000 : 0 : return rte_flow_error_set(error, ENOTSUP,
4001 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4002 : : "decap action for VF representor "
4003 : : "not supported on NIC table");
4004 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_DECAP &&
4005 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_VXLAN))
4006 : 0 : return rte_flow_error_set(error, ENOTSUP,
4007 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4008 : : "VXLAN item should be present for VXLAN decap");
4009 : : return 0;
4010 : : }
4011 : :
4012 : : const struct rte_flow_action_raw_decap empty_decap = {.data = NULL, .size = 0,};
4013 : :
4014 : : /**
4015 : : * Validate the raw encap and decap actions.
4016 : : *
4017 : : * @param[in] dev
4018 : : * Pointer to the rte_eth_dev structure.
4019 : : * @param[in] decap
4020 : : * Pointer to the decap action.
4021 : : * @param[in] encap
4022 : : * Pointer to the encap action.
4023 : : * @param[in] attr
4024 : : * Pointer to flow attributes
4025 : : * @param[in/out] action_flags
4026 : : * Holds the actions detected until now.
4027 : : * @param[out] actions_n
4028 : : * pointer to the number of actions counter.
4029 : : * @param[in] action
4030 : : * Pointer to the action structure.
4031 : : * @param[in] item_flags
4032 : : * Holds the items detected.
4033 : : * @param[out] error
4034 : : * Pointer to error structure.
4035 : : *
4036 : : * @return
4037 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4038 : : */
4039 : : int
4040 : 0 : mlx5_flow_dv_validate_action_raw_encap_decap
4041 : : (struct rte_eth_dev *dev,
4042 : : const struct rte_flow_action_raw_decap *decap,
4043 : : const struct rte_flow_action_raw_encap *encap,
4044 : : const struct rte_flow_attr *attr, uint64_t *action_flags,
4045 : : int *actions_n, const struct rte_flow_action *action,
4046 : : uint64_t item_flags, struct rte_flow_error *error)
4047 : : {
4048 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
4049 : : int ret;
4050 : :
4051 [ # # ]: 0 : if (encap) {
4052 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
4053 [ # # # # ]: 0 : if (!encap->size || !encap->data)
4054 : 0 : return rte_flow_error_set
4055 : : (error, EINVAL,
4056 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL, "raw encap data cannot be empty");
4057 : : } else {
4058 [ # # ]: 0 : if (!encap->size)
4059 : 0 : return rte_flow_error_set
4060 : : (error, EINVAL,
4061 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL, "raw encap size cannot be 0");
4062 : : }
4063 : : }
4064 [ # # ]: 0 : if (decap && encap) {
4065 [ # # ]: 0 : if (decap->size <= MLX5_ENCAPSULATION_DECISION_SIZE &&
4066 [ # # ]: 0 : encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4067 : : /* L3 encap. */
4068 : : decap = NULL;
4069 [ # # ]: 0 : else if (encap->size <=
4070 [ # # ]: 0 : MLX5_ENCAPSULATION_DECISION_SIZE &&
4071 : : decap->size >
4072 : : MLX5_ENCAPSULATION_DECISION_SIZE)
4073 : : /* L3 decap. */
4074 : : encap = NULL;
4075 [ # # ]: 0 : else if (encap->size >
4076 [ # # ]: 0 : MLX5_ENCAPSULATION_DECISION_SIZE &&
4077 : : decap->size >
4078 : : MLX5_ENCAPSULATION_DECISION_SIZE)
4079 : : /* 2 L2 actions: encap and decap. */
4080 : : ;
4081 : : else
4082 : 0 : return rte_flow_error_set(error,
4083 : : ENOTSUP,
4084 : : RTE_FLOW_ERROR_TYPE_ACTION,
4085 : : NULL, "unsupported too small "
4086 : : "raw decap and too small raw "
4087 : : "encap combination");
4088 : : }
4089 [ # # ]: 0 : if (decap) {
4090 : 0 : ret = mlx5_flow_dv_validate_action_decap(dev, *action_flags,
4091 : : action,
4092 : : item_flags, attr,
4093 : : error);
4094 [ # # ]: 0 : if (ret < 0)
4095 : : return ret;
4096 : 0 : *action_flags |= MLX5_FLOW_ACTION_DECAP;
4097 : 0 : ++(*actions_n);
4098 : : }
4099 [ # # ]: 0 : if (encap) {
4100 [ # # ]: 0 : if (encap->size <= MLX5_ENCAPSULATION_DECISION_SIZE)
4101 : 0 : return rte_flow_error_set(error, ENOTSUP,
4102 : : RTE_FLOW_ERROR_TYPE_ACTION,
4103 : : NULL,
4104 : : "small raw encap size");
4105 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_ENCAP)
4106 : 0 : return rte_flow_error_set(error, EINVAL,
4107 : : RTE_FLOW_ERROR_TYPE_ACTION,
4108 : : NULL,
4109 : : "more than one encap action");
4110 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
4111 : 0 : return rte_flow_error_set
4112 : : (error, ENOTSUP,
4113 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4114 : : "encap action for VF representor "
4115 : : "not supported on NIC table");
4116 : 0 : *action_flags |= MLX5_FLOW_ACTION_ENCAP;
4117 : 0 : ++(*actions_n);
4118 : : }
4119 : : return 0;
4120 : : }
4121 : :
4122 : : /*
4123 : : * Validate the ASO CT action.
4124 : : *
4125 : : * @param[in] dev
4126 : : * Pointer to the rte_eth_dev structure.
4127 : : * @param[in] action_flags
4128 : : * Holds the actions detected until now.
4129 : : * @param[in] item_flags
4130 : : * The items found in this flow rule.
4131 : : * @param root
4132 : : * Whether action is on root table.
4133 : : * @param[out] error
4134 : : * Pointer to error structure.
4135 : : *
4136 : : * @return
4137 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4138 : : */
4139 : : int
4140 : 0 : mlx5_flow_dv_validate_action_aso_ct(struct rte_eth_dev *dev,
4141 : : uint64_t action_flags,
4142 : : uint64_t item_flags,
4143 : : bool root,
4144 : : struct rte_flow_error *error)
4145 : : {
4146 : : RTE_SET_USED(dev);
4147 : :
4148 [ # # ]: 0 : if (root)
4149 : 0 : return rte_flow_error_set(error, ENOTSUP,
4150 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4151 : : NULL,
4152 : : "Only support non-root table");
4153 [ # # ]: 0 : if (action_flags & MLX5_FLOW_FATE_ACTIONS)
4154 : 0 : return rte_flow_error_set(error, ENOTSUP,
4155 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4156 : : "CT cannot follow a fate action");
4157 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_METER) ||
4158 : : (action_flags & MLX5_FLOW_ACTION_AGE)) {
4159 [ # # ]: 0 : if (!mlx5_hws_active(dev))
4160 : 0 : return rte_flow_error_set(error, EINVAL,
4161 : : RTE_FLOW_ERROR_TYPE_ACTION,
4162 : : NULL, "Only one ASO action is supported");
4163 : : }
4164 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
4165 : 0 : return rte_flow_error_set(error, EINVAL,
4166 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4167 : : "Encap cannot exist before CT");
4168 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP))
4169 : 0 : return rte_flow_error_set(error, EINVAL,
4170 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4171 : : "Not a outer TCP packet");
4172 : : return 0;
4173 : : }
4174 : :
4175 : : /**
4176 : : * Validate METER_COLOR item.
4177 : : *
4178 : : * @param[in] dev
4179 : : * Pointer to the rte_eth_dev structure.
4180 : : * @param[in] item
4181 : : * Item specification.
4182 : : * @param[in] attr
4183 : : * Attributes of flow that includes this item.
4184 : : * @param[out] error
4185 : : * Pointer to error structure.
4186 : : *
4187 : : * @return
4188 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4189 : : */
4190 : : static int
4191 : 0 : flow_dv_validate_item_meter_color(struct rte_eth_dev *dev,
4192 : : const struct rte_flow_item *item,
4193 : : const struct rte_flow_attr *attr __rte_unused,
4194 : : struct rte_flow_error *error)
4195 : : {
4196 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4197 : 0 : const struct rte_flow_item_meter_color *spec = item->spec;
4198 : 0 : const struct rte_flow_item_meter_color *mask = item->mask;
4199 : 0 : struct rte_flow_item_meter_color nic_mask = {
4200 : : .color = RTE_COLORS
4201 : : };
4202 : : int ret;
4203 : :
4204 [ # # ]: 0 : if (priv->sh->registers.aso_reg == REG_NON)
4205 : 0 : return rte_flow_error_set(error, ENOTSUP,
4206 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
4207 : : "meter color register"
4208 : : " isn't available");
4209 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, error);
4210 [ # # ]: 0 : if (ret < 0)
4211 : : return ret;
4212 [ # # ]: 0 : if (!spec)
4213 : 0 : return rte_flow_error_set(error, EINVAL,
4214 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4215 : 0 : item->spec,
4216 : : "data cannot be empty");
4217 [ # # ]: 0 : if (spec->color > RTE_COLORS)
4218 : 0 : return rte_flow_error_set(error, EINVAL,
4219 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4220 : 0 : &spec->color,
4221 : : "meter color is invalid");
4222 [ # # ]: 0 : if (!mask)
4223 : : mask = &rte_flow_item_meter_color_mask;
4224 [ # # ]: 0 : if (!mask->color)
4225 : 0 : return rte_flow_error_set(error, EINVAL,
4226 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
4227 : : "mask cannot be zero");
4228 : :
4229 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
4230 : : (const uint8_t *)&nic_mask,
4231 : : sizeof(struct rte_flow_item_meter_color),
4232 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
4233 : : if (ret < 0)
4234 : : return ret;
4235 : : return 0;
4236 : : }
4237 : :
4238 : : /**
4239 : : * Validate aggregated affinity item.
4240 : : *
4241 : : * @param[in] dev
4242 : : * Pointer to the rte_eth_dev structure.
4243 : : * @param[in] item
4244 : : * Item specification.
4245 : : * @param[in] attr
4246 : : * Attributes of flow that includes this item.
4247 : : * @param[out] error
4248 : : * Pointer to error structure.
4249 : : *
4250 : : * @return
4251 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4252 : : */
4253 : : static int
4254 : 0 : flow_dv_validate_item_aggr_affinity(struct rte_eth_dev *dev,
4255 : : const struct rte_flow_item *item,
4256 : : const struct rte_flow_attr *attr,
4257 : : struct rte_flow_error *error)
4258 : : {
4259 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4260 : 0 : const struct rte_flow_item_aggr_affinity *spec = item->spec;
4261 : 0 : const struct rte_flow_item_aggr_affinity *mask = item->mask;
4262 : 0 : struct rte_flow_item_aggr_affinity nic_mask = {
4263 : : .affinity = UINT8_MAX
4264 : : };
4265 : : int ret;
4266 : :
4267 [ # # ]: 0 : if (!priv->sh->lag_rx_port_affinity_en)
4268 : 0 : return rte_flow_error_set(error, EINVAL,
4269 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
4270 : : "Unsupported aggregated affinity with Older FW");
4271 [ # # # # : 0 : if ((attr->transfer && priv->fdb_def_rule) ||
# # ]
4272 [ # # ]: 0 : attr->egress || attr->group)
4273 : 0 : return rte_flow_error_set(error, ENOTSUP,
4274 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4275 : : item->spec,
4276 : : "aggregated affinity is not supported with egress or FDB on non root table");
4277 [ # # ]: 0 : if (!spec)
4278 : 0 : return rte_flow_error_set(error, EINVAL,
4279 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4280 : : item->spec,
4281 : : "data cannot be empty");
4282 [ # # ]: 0 : if (spec->affinity == 0)
4283 : 0 : return rte_flow_error_set(error, ENOTSUP,
4284 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4285 : : item->spec,
4286 : : "zero affinity number not supported");
4287 [ # # ]: 0 : if (spec->affinity > priv->num_lag_ports)
4288 : 0 : return rte_flow_error_set(error, ENOTSUP,
4289 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4290 : : item->spec,
4291 : : "exceed max affinity number in lag ports");
4292 [ # # ]: 0 : if (!mask)
4293 : : mask = &rte_flow_item_aggr_affinity_mask;
4294 [ # # ]: 0 : if (!mask->affinity)
4295 : 0 : return rte_flow_error_set(error, EINVAL,
4296 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
4297 : : "mask cannot be zero");
4298 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
4299 : : (const uint8_t *)&nic_mask,
4300 : : sizeof(struct rte_flow_item_aggr_affinity),
4301 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
4302 : : if (ret < 0)
4303 : : return ret;
4304 : : return 0;
4305 : : }
4306 : :
4307 : : int
4308 : 0 : flow_encap_decap_match_cb(void *tool_ctx __rte_unused,
4309 : : struct mlx5_list_entry *entry, void *cb_ctx)
4310 : : {
4311 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4312 : 0 : struct mlx5_flow_dv_encap_decap_resource *ctx_resource = ctx->data;
4313 : : struct mlx5_flow_dv_encap_decap_resource *resource;
4314 : :
4315 : : resource = container_of(entry, struct mlx5_flow_dv_encap_decap_resource,
4316 : : entry);
4317 [ # # ]: 0 : if (resource->reformat_type == ctx_resource->reformat_type &&
4318 : 0 : resource->ft_type == ctx_resource->ft_type &&
4319 [ # # ]: 0 : resource->flags == ctx_resource->flags &&
4320 [ # # ]: 0 : resource->size == ctx_resource->size &&
4321 : 0 : !memcmp((const void *)resource->buf,
4322 [ # # ]: 0 : (const void *)ctx_resource->buf,
4323 : : resource->size))
4324 : 0 : return 0;
4325 : : return -1;
4326 : : }
4327 : :
4328 : : struct mlx5_list_entry *
4329 : 0 : flow_encap_decap_create_cb(void *tool_ctx, void *cb_ctx)
4330 : : {
4331 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4332 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4333 : : struct mlx5dv_dr_domain *domain;
4334 : 0 : struct mlx5_flow_dv_encap_decap_resource *ctx_resource = ctx->data;
4335 : : struct mlx5_flow_dv_encap_decap_resource *resource;
4336 : : uint32_t idx;
4337 : : int ret = 0;
4338 : : #ifdef HAVE_MLX5_HWS_SUPPORT
4339 : : struct mlx5dr_action_reformat_header hdr;
4340 : : #endif
4341 : :
4342 : : /* Register new encap/decap resource. */
4343 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], &idx);
4344 [ # # ]: 0 : if (!resource) {
4345 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4346 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4347 : : "cannot allocate resource memory");
4348 : 0 : return NULL;
4349 : : }
4350 : 0 : *resource = *ctx_resource;
4351 [ # # ]: 0 : if (sh->config.dv_flow_en == 2) {
4352 : : #ifdef HAVE_MLX5_HWS_SUPPORT
4353 : 0 : hdr.sz = ctx_resource->size;
4354 : 0 : hdr.data = ctx_resource->buf;
4355 : 0 : resource->action = mlx5dr_action_create_reformat
4356 : 0 : (ctx->data2, (enum mlx5dr_action_type)ctx_resource->reformat_type, 1,
4357 : 0 : &hdr, 0, ctx_resource->flags);
4358 [ # # ]: 0 : if (!resource->action)
4359 : : ret = -1;
4360 : : #else
4361 : : ret = -1;
4362 : : #endif
4363 : : } else {
4364 [ # # ]: 0 : if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
4365 : 0 : domain = sh->fdb_domain;
4366 [ # # ]: 0 : else if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
4367 : 0 : domain = sh->rx_domain;
4368 : : else
4369 : 0 : domain = sh->tx_domain;
4370 [ # # ]: 0 : ret = mlx5_flow_os_create_flow_action_packet_reformat(sh->cdev->ctx,
4371 : : domain, resource,
4372 : : &resource->action);
4373 : : }
4374 : : if (ret) {
4375 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], idx);
4376 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4377 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4378 : : NULL, "cannot create action");
4379 : 0 : return NULL;
4380 : : }
4381 : 0 : resource->idx = idx;
4382 : 0 : return &resource->entry;
4383 : : }
4384 : :
4385 : : struct mlx5_list_entry *
4386 : 0 : flow_encap_decap_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
4387 : : void *cb_ctx)
4388 : : {
4389 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4390 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4391 : : struct mlx5_flow_dv_encap_decap_resource *cache_resource;
4392 : : uint32_t idx;
4393 : :
4394 : 0 : cache_resource = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
4395 : : &idx);
4396 [ # # ]: 0 : if (!cache_resource) {
4397 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4398 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4399 : : "cannot allocate resource memory");
4400 : 0 : return NULL;
4401 : : }
4402 : : memcpy(cache_resource, oentry, sizeof(*cache_resource));
4403 : 0 : cache_resource->idx = idx;
4404 : 0 : return &cache_resource->entry;
4405 : : }
4406 : :
4407 : : void
4408 : 0 : flow_encap_decap_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4409 : : {
4410 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4411 : : struct mlx5_flow_dv_encap_decap_resource *res =
4412 : : container_of(entry, typeof(*res), entry);
4413 : :
4414 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], res->idx);
4415 : 0 : }
4416 : :
4417 : : int
4418 : 0 : __flow_encap_decap_resource_register(struct rte_eth_dev *dev,
4419 : : struct mlx5_flow_dv_encap_decap_resource *resource,
4420 : : bool is_root,
4421 : : struct mlx5_flow_dv_encap_decap_resource **encap_decap,
4422 : : struct rte_flow_error *error)
4423 : : {
4424 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4425 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
4426 : : struct mlx5_list_entry *entry;
4427 : : union {
4428 : : struct {
4429 : : uint32_t ft_type:8;
4430 : : uint32_t refmt_type:8;
4431 : : /*
4432 : : * Header reformat actions can be shared between
4433 : : * non-root tables. One bit to indicate non-root
4434 : : * table or not.
4435 : : */
4436 : : uint32_t is_root:1;
4437 : : uint32_t reserve:15;
4438 : : };
4439 : : uint32_t v32;
4440 : 0 : } encap_decap_key = {
4441 : : {
4442 : 0 : .ft_type = resource->ft_type,
4443 : 0 : .refmt_type = resource->reformat_type,
4444 : : .is_root = is_root,
4445 : : .reserve = 0,
4446 : : }
4447 : : };
4448 : 0 : struct mlx5_flow_cb_ctx ctx = {
4449 : : .error = error,
4450 : : .data = resource,
4451 : 0 : .data2 = priv->dr_ctx,
4452 : : };
4453 : : struct mlx5_hlist *encaps_decaps;
4454 : : uint64_t key64;
4455 : :
4456 : 0 : encaps_decaps = flow_dv_hlist_prepare(sh, &sh->encaps_decaps,
4457 : : "encaps_decaps",
4458 : : MLX5_FLOW_ENCAP_DECAP_HTABLE_SZ,
4459 : : true, true, sh,
4460 : : flow_encap_decap_create_cb,
4461 : : flow_encap_decap_match_cb,
4462 : : flow_encap_decap_remove_cb,
4463 : : flow_encap_decap_clone_cb,
4464 : : flow_encap_decap_clone_free_cb,
4465 : : error);
4466 [ # # ]: 0 : if (unlikely(!encaps_decaps))
4467 : 0 : return -rte_errno;
4468 : 0 : key64 = __rte_raw_cksum(&encap_decap_key.v32,
4469 : : sizeof(encap_decap_key.v32), 0);
4470 [ # # ]: 0 : if (resource->reformat_type !=
4471 : 0 : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2 &&
4472 [ # # ]: 0 : resource->size)
4473 : 0 : key64 = __rte_raw_cksum(resource->buf, resource->size, key64);
4474 : 0 : entry = mlx5_hlist_register(encaps_decaps, key64, &ctx);
4475 [ # # ]: 0 : if (!entry)
4476 : 0 : return -rte_errno;
4477 : 0 : *encap_decap = container_of(entry, typeof(*resource), entry);
4478 : 0 : return 0;
4479 : : }
4480 : :
4481 : : /**
4482 : : * Find existing encap/decap resource or create and register a new one.
4483 : : *
4484 : : * @param[in, out] dev
4485 : : * Pointer to rte_eth_dev structure.
4486 : : * @param[in, out] resource
4487 : : * Pointer to encap/decap resource.
4488 : : * @param[in, out] dev_flow
4489 : : * Pointer to the dev_flow.
4490 : : * @param[out] error
4491 : : * pointer to error structure.
4492 : : *
4493 : : * @return
4494 : : * 0 on success otherwise -errno and errno is set.
4495 : : */
4496 : : static int
4497 : 0 : flow_dv_encap_decap_resource_register
4498 : : (struct rte_eth_dev *dev,
4499 : : struct mlx5_flow_dv_encap_decap_resource *resource,
4500 : : struct mlx5_flow *dev_flow,
4501 : : struct rte_flow_error *error)
4502 : : {
4503 : : int ret;
4504 : :
4505 : 0 : resource->flags = dev_flow->dv.group ? 0 : 1;
4506 : 0 : ret = __flow_encap_decap_resource_register(dev, resource, !!dev_flow->dv.group,
4507 : : &dev_flow->dv.encap_decap, error);
4508 [ # # ]: 0 : if (ret)
4509 : : return ret;
4510 : 0 : dev_flow->handle->dvh.rix_encap_decap = dev_flow->dv.encap_decap->idx;
4511 : 0 : return 0;
4512 : : }
4513 : :
4514 : : /**
4515 : : * Find existing table jump resource or create and register a new one.
4516 : : *
4517 : : * @param[in, out] dev
4518 : : * Pointer to rte_eth_dev structure.
4519 : : * @param[in, out] tbl
4520 : : * Pointer to flow table resource.
4521 : : * @parm[in, out] dev_flow
4522 : : * Pointer to the dev_flow.
4523 : : * @param[out] error
4524 : : * pointer to error structure.
4525 : : *
4526 : : * @return
4527 : : * 0 on success otherwise -errno and errno is set.
4528 : : */
4529 : : static int
4530 : : flow_dv_jump_tbl_resource_register
4531 : : (struct rte_eth_dev *dev __rte_unused,
4532 : : struct mlx5_flow_tbl_resource *tbl,
4533 : : struct mlx5_flow *dev_flow,
4534 : : struct rte_flow_error *error __rte_unused)
4535 : : {
4536 : : struct mlx5_flow_tbl_data_entry *tbl_data =
4537 : 0 : container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
4538 : :
4539 : : MLX5_ASSERT(tbl);
4540 : : MLX5_ASSERT(tbl_data->jump.action);
4541 : 0 : dev_flow->handle->rix_jump = tbl_data->idx;
4542 : 0 : dev_flow->dv.jump = &tbl_data->jump;
4543 : : return 0;
4544 : : }
4545 : :
4546 : : int
4547 : 0 : flow_dv_port_id_match_cb(void *tool_ctx __rte_unused,
4548 : : struct mlx5_list_entry *entry, void *cb_ctx)
4549 : : {
4550 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4551 : 0 : struct mlx5_flow_dv_port_id_action_resource *ref = ctx->data;
4552 : : struct mlx5_flow_dv_port_id_action_resource *res =
4553 : : container_of(entry, typeof(*res), entry);
4554 : :
4555 : 0 : return ref->port_id != res->port_id;
4556 : : }
4557 : :
4558 : : struct mlx5_list_entry *
4559 : 0 : flow_dv_port_id_create_cb(void *tool_ctx, void *cb_ctx)
4560 : : {
4561 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4562 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4563 : 0 : struct mlx5_flow_dv_port_id_action_resource *ref = ctx->data;
4564 : : struct mlx5_flow_dv_port_id_action_resource *resource;
4565 : : uint32_t idx;
4566 : : int ret;
4567 : :
4568 : : /* Register new port id action resource. */
4569 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID], &idx);
4570 [ # # ]: 0 : if (!resource) {
4571 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4572 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4573 : : "cannot allocate port_id action memory");
4574 : 0 : return NULL;
4575 : : }
4576 : 0 : *resource = *ref;
4577 : 0 : ret = mlx5_flow_os_create_flow_action_dest_port(sh->fdb_domain,
4578 : : ref->port_id,
4579 : : &resource->action);
4580 : : if (ret) {
4581 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], idx);
4582 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4583 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4584 : : "cannot create action");
4585 : 0 : return NULL;
4586 : : }
4587 : 0 : resource->idx = idx;
4588 : 0 : return &resource->entry;
4589 : : }
4590 : :
4591 : : struct mlx5_list_entry *
4592 : 0 : flow_dv_port_id_clone_cb(void *tool_ctx,
4593 : : struct mlx5_list_entry *entry __rte_unused,
4594 : : void *cb_ctx)
4595 : : {
4596 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4597 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4598 : : struct mlx5_flow_dv_port_id_action_resource *resource;
4599 : : uint32_t idx;
4600 : :
4601 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID], &idx);
4602 [ # # ]: 0 : if (!resource) {
4603 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4604 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4605 : : "cannot allocate port_id action memory");
4606 : 0 : return NULL;
4607 : : }
4608 : : memcpy(resource, entry, sizeof(*resource));
4609 : 0 : resource->idx = idx;
4610 : 0 : return &resource->entry;
4611 : : }
4612 : :
4613 : : void
4614 : 0 : flow_dv_port_id_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4615 : : {
4616 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4617 : : struct mlx5_flow_dv_port_id_action_resource *resource =
4618 : : container_of(entry, typeof(*resource), entry);
4619 : :
4620 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], resource->idx);
4621 : 0 : }
4622 : :
4623 : : /**
4624 : : * Find existing table port ID resource or create and register a new one.
4625 : : *
4626 : : * @param[in, out] dev
4627 : : * Pointer to rte_eth_dev structure.
4628 : : * @param[in, out] ref
4629 : : * Pointer to port ID action resource reference.
4630 : : * @parm[in, out] dev_flow
4631 : : * Pointer to the dev_flow.
4632 : : * @param[out] error
4633 : : * pointer to error structure.
4634 : : *
4635 : : * @return
4636 : : * 0 on success otherwise -errno and errno is set.
4637 : : */
4638 : : static int
4639 : 0 : flow_dv_port_id_action_resource_register
4640 : : (struct rte_eth_dev *dev,
4641 : : struct mlx5_flow_dv_port_id_action_resource *ref,
4642 : : struct mlx5_flow *dev_flow,
4643 : : struct rte_flow_error *error)
4644 : : {
4645 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4646 : : struct mlx5_list_entry *entry;
4647 : : struct mlx5_flow_dv_port_id_action_resource *resource;
4648 : 0 : struct mlx5_flow_cb_ctx ctx = {
4649 : : .error = error,
4650 : : .data = ref,
4651 : : };
4652 : :
4653 : 0 : entry = mlx5_list_register(priv->sh->port_id_action_list, &ctx);
4654 [ # # ]: 0 : if (!entry)
4655 : 0 : return -rte_errno;
4656 : : resource = container_of(entry, typeof(*resource), entry);
4657 : 0 : dev_flow->dv.port_id_action = resource;
4658 : 0 : dev_flow->handle->rix_port_id_action = resource->idx;
4659 : 0 : return 0;
4660 : : }
4661 : :
4662 : : int
4663 : 0 : flow_dv_push_vlan_match_cb(void *tool_ctx __rte_unused,
4664 : : struct mlx5_list_entry *entry, void *cb_ctx)
4665 : : {
4666 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4667 : 0 : struct mlx5_flow_dv_push_vlan_action_resource *ref = ctx->data;
4668 : : struct mlx5_flow_dv_push_vlan_action_resource *res =
4669 : : container_of(entry, typeof(*res), entry);
4670 : :
4671 : 0 : return ref->vlan_tag != res->vlan_tag || ref->ft_type != res->ft_type;
4672 : : }
4673 : :
4674 : : struct mlx5_list_entry *
4675 : 0 : flow_dv_push_vlan_create_cb(void *tool_ctx, void *cb_ctx)
4676 : : {
4677 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4678 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4679 : 0 : struct mlx5_flow_dv_push_vlan_action_resource *ref = ctx->data;
4680 : : struct mlx5_flow_dv_push_vlan_action_resource *resource;
4681 : : struct mlx5dv_dr_domain *domain;
4682 : : uint32_t idx;
4683 : : int ret;
4684 : :
4685 : : /* Register new port id action resource. */
4686 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PUSH_VLAN], &idx);
4687 [ # # ]: 0 : if (!resource) {
4688 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4689 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4690 : : "cannot allocate push_vlan action memory");
4691 : 0 : return NULL;
4692 : : }
4693 : 0 : *resource = *ref;
4694 [ # # ]: 0 : if (ref->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
4695 : 0 : domain = sh->fdb_domain;
4696 [ # # ]: 0 : else if (ref->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
4697 : 0 : domain = sh->rx_domain;
4698 : : else
4699 : 0 : domain = sh->tx_domain;
4700 : 0 : ret = mlx5_flow_os_create_flow_action_push_vlan(domain, ref->vlan_tag,
4701 : : &resource->action);
4702 : : if (ret) {
4703 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
4704 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4705 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4706 : : "cannot create push vlan action");
4707 : 0 : return NULL;
4708 : : }
4709 : 0 : resource->idx = idx;
4710 : 0 : return &resource->entry;
4711 : : }
4712 : :
4713 : : struct mlx5_list_entry *
4714 : 0 : flow_dv_push_vlan_clone_cb(void *tool_ctx,
4715 : : struct mlx5_list_entry *entry __rte_unused,
4716 : : void *cb_ctx)
4717 : : {
4718 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4719 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4720 : : struct mlx5_flow_dv_push_vlan_action_resource *resource;
4721 : : uint32_t idx;
4722 : :
4723 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PUSH_VLAN], &idx);
4724 [ # # ]: 0 : if (!resource) {
4725 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4726 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4727 : : "cannot allocate push_vlan action memory");
4728 : 0 : return NULL;
4729 : : }
4730 : : memcpy(resource, entry, sizeof(*resource));
4731 : 0 : resource->idx = idx;
4732 : 0 : return &resource->entry;
4733 : : }
4734 : :
4735 : : void
4736 : 0 : flow_dv_push_vlan_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4737 : : {
4738 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4739 : : struct mlx5_flow_dv_push_vlan_action_resource *resource =
4740 : : container_of(entry, typeof(*resource), entry);
4741 : :
4742 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], resource->idx);
4743 : 0 : }
4744 : :
4745 : : /**
4746 : : * Find existing push vlan resource or create and register a new one.
4747 : : *
4748 : : * @param [in, out] dev
4749 : : * Pointer to rte_eth_dev structure.
4750 : : * @param[in, out] ref
4751 : : * Pointer to port ID action resource reference.
4752 : : * @parm[in, out] dev_flow
4753 : : * Pointer to the dev_flow.
4754 : : * @param[out] error
4755 : : * pointer to error structure.
4756 : : *
4757 : : * @return
4758 : : * 0 on success otherwise -errno and errno is set.
4759 : : */
4760 : : static int
4761 : 0 : flow_dv_push_vlan_action_resource_register
4762 : : (struct rte_eth_dev *dev,
4763 : : struct mlx5_flow_dv_push_vlan_action_resource *ref,
4764 : : struct mlx5_flow *dev_flow,
4765 : : struct rte_flow_error *error)
4766 : : {
4767 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4768 : : struct mlx5_flow_dv_push_vlan_action_resource *resource;
4769 : : struct mlx5_list_entry *entry;
4770 : 0 : struct mlx5_flow_cb_ctx ctx = {
4771 : : .error = error,
4772 : : .data = ref,
4773 : : };
4774 : :
4775 : 0 : entry = mlx5_list_register(priv->sh->push_vlan_action_list, &ctx);
4776 [ # # ]: 0 : if (!entry)
4777 : 0 : return -rte_errno;
4778 : : resource = container_of(entry, typeof(*resource), entry);
4779 : :
4780 : 0 : dev_flow->handle->dvh.rix_push_vlan = resource->idx;
4781 : 0 : dev_flow->dv.push_vlan_res = resource;
4782 : 0 : return 0;
4783 : : }
4784 : :
4785 : : /**
4786 : : * Get the size of specific rte_flow_item_type hdr size
4787 : : *
4788 : : * @param[in] item_type
4789 : : * Tested rte_flow_item_type.
4790 : : *
4791 : : * @return
4792 : : * sizeof struct item_type, 0 if void or irrelevant.
4793 : : */
4794 : : size_t
4795 [ # # ]: 0 : flow_dv_get_item_hdr_len(const enum rte_flow_item_type item_type)
4796 : : {
4797 : : size_t retval;
4798 : :
4799 : : switch (item_type) {
4800 : : case RTE_FLOW_ITEM_TYPE_ETH:
4801 : : retval = sizeof(struct rte_ether_hdr);
4802 : : break;
4803 : : case RTE_FLOW_ITEM_TYPE_VLAN:
4804 : : retval = sizeof(struct rte_vlan_hdr);
4805 : : break;
4806 : : case RTE_FLOW_ITEM_TYPE_IPV4:
4807 : : retval = sizeof(struct rte_ipv4_hdr);
4808 : : break;
4809 : : case RTE_FLOW_ITEM_TYPE_IPV6:
4810 : : retval = sizeof(struct rte_ipv6_hdr);
4811 : : break;
4812 : : case RTE_FLOW_ITEM_TYPE_UDP:
4813 : : retval = sizeof(struct rte_udp_hdr);
4814 : : break;
4815 : : case RTE_FLOW_ITEM_TYPE_TCP:
4816 : : retval = sizeof(struct rte_tcp_hdr);
4817 : : break;
4818 : : case RTE_FLOW_ITEM_TYPE_VXLAN:
4819 : : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
4820 : : retval = sizeof(struct rte_vxlan_hdr);
4821 : : break;
4822 : : case RTE_FLOW_ITEM_TYPE_GRE:
4823 : : case RTE_FLOW_ITEM_TYPE_NVGRE:
4824 : : retval = sizeof(struct rte_gre_hdr);
4825 : : break;
4826 : : case RTE_FLOW_ITEM_TYPE_MPLS:
4827 : : retval = sizeof(struct rte_mpls_hdr);
4828 : : break;
4829 : : case RTE_FLOW_ITEM_TYPE_VOID: /* Fall through. */
4830 : : default:
4831 : : retval = 0;
4832 : : break;
4833 : : }
4834 : 0 : return retval;
4835 : : }
4836 : :
4837 : : #define MLX5_ENCAP_IPV4_VERSION 0x40
4838 : : #define MLX5_ENCAP_IPV4_IHL_MIN 0x05
4839 : : #define MLX5_ENCAP_IPV4_TTL_DEF 0x40
4840 : : #define MLX5_ENCAP_IPV6_VTC_FLOW 0x60000000
4841 : : #define MLX5_ENCAP_IPV6_HOP_LIMIT 0xff
4842 : : #define MLX5_ENCAP_VXLAN_FLAGS 0x08000000
4843 : : #define MLX5_ENCAP_VXLAN_GPE_FLAGS 0x04
4844 : :
4845 : : /**
4846 : : * Convert the encap action data from list of rte_flow_item to raw buffer
4847 : : *
4848 : : * @param[in] items
4849 : : * Pointer to rte_flow_item objects list.
4850 : : * @param[out] buf
4851 : : * Pointer to the output buffer.
4852 : : * @param[out] size
4853 : : * Pointer to the output buffer size.
4854 : : * @param[out] error
4855 : : * Pointer to the error structure.
4856 : : *
4857 : : * @return
4858 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4859 : : */
4860 : : int
4861 : 0 : flow_dv_convert_encap_data(const struct rte_flow_item *items, uint8_t *buf,
4862 : : size_t *size, struct rte_flow_error *error)
4863 : : {
4864 : : struct rte_ether_hdr *eth = NULL;
4865 : : struct rte_vlan_hdr *vlan = NULL;
4866 : : struct rte_ipv4_hdr *ipv4 = NULL;
4867 : : struct rte_ipv6_hdr *ipv6 = NULL;
4868 : : struct rte_udp_hdr *udp = NULL;
4869 : : struct rte_vxlan_hdr *vxlan = NULL;
4870 : : struct rte_vxlan_gpe_hdr *vxlan_gpe = NULL;
4871 : : struct rte_gre_hdr *gre = NULL;
4872 : : size_t len;
4873 : : size_t temp_size = 0;
4874 : :
4875 [ # # ]: 0 : if (!items)
4876 : 0 : return rte_flow_error_set(error, EINVAL,
4877 : : RTE_FLOW_ERROR_TYPE_ACTION,
4878 : : NULL, "invalid empty data");
4879 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4880 : 0 : len = flow_dv_get_item_hdr_len(items->type);
4881 [ # # ]: 0 : if (len + temp_size > MLX5_ENCAP_MAX_LEN)
4882 : 0 : return rte_flow_error_set(error, EINVAL,
4883 : : RTE_FLOW_ERROR_TYPE_ACTION,
4884 : 0 : (void *)items->type,
4885 : : "items total size is too big"
4886 : : " for encap action");
4887 [ # # ]: 0 : if (items->spec)
4888 [ # # ]: 0 : rte_memcpy(&buf[temp_size], items->spec, len);
4889 [ # # # # : 0 : switch (items->type) {
# # # # #
# ]
4890 : 0 : case RTE_FLOW_ITEM_TYPE_ETH:
4891 : 0 : eth = (struct rte_ether_hdr *)&buf[temp_size];
4892 : 0 : break;
4893 : 0 : case RTE_FLOW_ITEM_TYPE_VLAN:
4894 : 0 : vlan = (struct rte_vlan_hdr *)&buf[temp_size];
4895 [ # # ]: 0 : if (!eth)
4896 : 0 : return rte_flow_error_set(error, EINVAL,
4897 : : RTE_FLOW_ERROR_TYPE_ACTION,
4898 : : (void *)items->type,
4899 : : "eth header not found");
4900 [ # # ]: 0 : if (!eth->ether_type)
4901 : 0 : eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_VLAN);
4902 : : break;
4903 : 0 : case RTE_FLOW_ITEM_TYPE_IPV4:
4904 : 0 : ipv4 = (struct rte_ipv4_hdr *)&buf[temp_size];
4905 [ # # ]: 0 : if (!vlan && !eth)
4906 : 0 : return rte_flow_error_set(error, EINVAL,
4907 : : RTE_FLOW_ERROR_TYPE_ACTION,
4908 : : (void *)items->type,
4909 : : "neither eth nor vlan"
4910 : : " header found");
4911 [ # # # # ]: 0 : if (vlan && !vlan->eth_proto)
4912 : 0 : vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV4);
4913 [ # # # # ]: 0 : else if (eth && !eth->ether_type)
4914 : 0 : eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV4);
4915 [ # # ]: 0 : if (!ipv4->version_ihl)
4916 : 0 : ipv4->version_ihl = MLX5_ENCAP_IPV4_VERSION |
4917 : : MLX5_ENCAP_IPV4_IHL_MIN;
4918 [ # # ]: 0 : if (!ipv4->time_to_live)
4919 : 0 : ipv4->time_to_live = MLX5_ENCAP_IPV4_TTL_DEF;
4920 : : break;
4921 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6:
4922 : 0 : ipv6 = (struct rte_ipv6_hdr *)&buf[temp_size];
4923 [ # # ]: 0 : if (!vlan && !eth)
4924 : 0 : return rte_flow_error_set(error, EINVAL,
4925 : : RTE_FLOW_ERROR_TYPE_ACTION,
4926 : : (void *)items->type,
4927 : : "neither eth nor vlan"
4928 : : " header found");
4929 [ # # # # ]: 0 : if (vlan && !vlan->eth_proto)
4930 : 0 : vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV6);
4931 [ # # # # ]: 0 : else if (eth && !eth->ether_type)
4932 : 0 : eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV6);
4933 [ # # ]: 0 : if (!ipv6->vtc_flow)
4934 : 0 : ipv6->vtc_flow =
4935 : : RTE_BE32(MLX5_ENCAP_IPV6_VTC_FLOW);
4936 [ # # ]: 0 : if (!ipv6->hop_limits)
4937 : 0 : ipv6->hop_limits = MLX5_ENCAP_IPV6_HOP_LIMIT;
4938 : : break;
4939 : 0 : case RTE_FLOW_ITEM_TYPE_UDP:
4940 : 0 : udp = (struct rte_udp_hdr *)&buf[temp_size];
4941 [ # # ]: 0 : if (!ipv4 && !ipv6)
4942 : 0 : return rte_flow_error_set(error, EINVAL,
4943 : : RTE_FLOW_ERROR_TYPE_ACTION,
4944 : : (void *)items->type,
4945 : : "ip header not found");
4946 [ # # # # ]: 0 : if (ipv4 && !ipv4->next_proto_id)
4947 : 0 : ipv4->next_proto_id = IPPROTO_UDP;
4948 [ # # # # ]: 0 : else if (ipv6 && !ipv6->proto)
4949 : 0 : ipv6->proto = IPPROTO_UDP;
4950 : : break;
4951 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN:
4952 : 0 : vxlan = (struct rte_vxlan_hdr *)&buf[temp_size];
4953 [ # # ]: 0 : if (!udp)
4954 : 0 : return rte_flow_error_set(error, EINVAL,
4955 : : RTE_FLOW_ERROR_TYPE_ACTION,
4956 : : (void *)items->type,
4957 : : "udp header not found");
4958 [ # # ]: 0 : if (!udp->dst_port)
4959 : 0 : udp->dst_port = RTE_BE16(MLX5_UDP_PORT_VXLAN);
4960 [ # # ]: 0 : if (!vxlan->vx_flags)
4961 : 0 : vxlan->vx_flags =
4962 : : RTE_BE32(MLX5_ENCAP_VXLAN_FLAGS);
4963 : : break;
4964 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
4965 : 0 : vxlan_gpe = (struct rte_vxlan_gpe_hdr *)&buf[temp_size];
4966 [ # # ]: 0 : if (!udp)
4967 : 0 : return rte_flow_error_set(error, EINVAL,
4968 : : RTE_FLOW_ERROR_TYPE_ACTION,
4969 : : (void *)items->type,
4970 : : "udp header not found");
4971 [ # # ]: 0 : if (!vxlan_gpe->proto)
4972 : 0 : return rte_flow_error_set(error, EINVAL,
4973 : : RTE_FLOW_ERROR_TYPE_ACTION,
4974 : : (void *)items->type,
4975 : : "next protocol not found");
4976 [ # # ]: 0 : if (!udp->dst_port)
4977 : 0 : udp->dst_port =
4978 : : RTE_BE16(MLX5_UDP_PORT_VXLAN_GPE);
4979 [ # # ]: 0 : if (!vxlan_gpe->vx_flags)
4980 : 0 : vxlan_gpe->vx_flags =
4981 : : MLX5_ENCAP_VXLAN_GPE_FLAGS;
4982 : : break;
4983 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
4984 : : case RTE_FLOW_ITEM_TYPE_NVGRE:
4985 : 0 : gre = (struct rte_gre_hdr *)&buf[temp_size];
4986 [ # # ]: 0 : if (!gre->proto)
4987 : 0 : return rte_flow_error_set(error, EINVAL,
4988 : : RTE_FLOW_ERROR_TYPE_ACTION,
4989 : 0 : (void *)items->type,
4990 : : "next protocol not found");
4991 [ # # ]: 0 : if (!ipv4 && !ipv6)
4992 : 0 : return rte_flow_error_set(error, EINVAL,
4993 : : RTE_FLOW_ERROR_TYPE_ACTION,
4994 : 0 : (void *)items->type,
4995 : : "ip header not found");
4996 [ # # # # ]: 0 : if (ipv4 && !ipv4->next_proto_id)
4997 : 0 : ipv4->next_proto_id = IPPROTO_GRE;
4998 [ # # # # ]: 0 : else if (ipv6 && !ipv6->proto)
4999 : 0 : ipv6->proto = IPPROTO_GRE;
5000 : : break;
5001 : : case RTE_FLOW_ITEM_TYPE_VOID:
5002 : : break;
5003 : 0 : default:
5004 : 0 : return rte_flow_error_set(error, EINVAL,
5005 : : RTE_FLOW_ERROR_TYPE_ACTION,
5006 : 0 : (void *)items->type,
5007 : : "unsupported item type");
5008 : : break;
5009 : : }
5010 : : temp_size += len;
5011 : : }
5012 : 0 : *size = temp_size;
5013 : 0 : return 0;
5014 : : }
5015 : :
5016 : : static int
5017 : 0 : flow_dv_zero_encap_udp_csum(void *data, struct rte_flow_error *error)
5018 : : {
5019 : : struct rte_ether_hdr *eth = NULL;
5020 : : struct rte_vlan_hdr *vlan = NULL;
5021 : : struct rte_ipv4_hdr *ipv4 = NULL;
5022 : : struct rte_ipv6_hdr *ipv6 = NULL;
5023 : : struct rte_udp_hdr *udp = NULL;
5024 : : char *next_hdr;
5025 : : uint16_t proto;
5026 : :
5027 : : eth = (struct rte_ether_hdr *)data;
5028 : 0 : next_hdr = (char *)(eth + 1);
5029 : 0 : proto = RTE_BE16(eth->ether_type);
5030 : :
5031 : : /* VLAN skipping */
5032 [ # # ]: 0 : while (proto == RTE_ETHER_TYPE_VLAN || proto == RTE_ETHER_TYPE_QINQ) {
5033 : : vlan = (struct rte_vlan_hdr *)next_hdr;
5034 : 0 : proto = RTE_BE16(vlan->eth_proto);
5035 : 0 : next_hdr += sizeof(struct rte_vlan_hdr);
5036 : : }
5037 : :
5038 : : /* non IPv4/IPv6 header. not supported */
5039 [ # # ]: 0 : if (proto != RTE_ETHER_TYPE_IPV4 && proto != RTE_ETHER_TYPE_IPV6) {
5040 : 0 : return rte_flow_error_set(error, ENOTSUP,
5041 : : RTE_FLOW_ERROR_TYPE_ACTION,
5042 : : NULL, "Cannot offload non IPv4/IPv6");
5043 : : }
5044 : :
5045 [ # # ]: 0 : if (proto == RTE_ETHER_TYPE_IPV4) {
5046 : : ipv4 = (struct rte_ipv4_hdr *)next_hdr;
5047 : : /* ignore non UDP */
5048 [ # # ]: 0 : if (ipv4->next_proto_id != IPPROTO_UDP)
5049 : : return 0;
5050 : 0 : udp = (struct rte_udp_hdr *)(ipv4 + 1);
5051 : : } else {
5052 : : ipv6 = (struct rte_ipv6_hdr *)next_hdr;
5053 : : /* ignore non UDP */
5054 [ # # ]: 0 : if (ipv6->proto != IPPROTO_UDP)
5055 : : return 0;
5056 : 0 : udp = (struct rte_udp_hdr *)(ipv6 + 1);
5057 : : }
5058 : :
5059 : 0 : udp->dgram_cksum = 0;
5060 : :
5061 : 0 : return 0;
5062 : : }
5063 : :
5064 : : /**
5065 : : * Convert L2 encap action to DV specification.
5066 : : *
5067 : : * @param[in] dev
5068 : : * Pointer to rte_eth_dev structure.
5069 : : * @param[in] action
5070 : : * Pointer to action structure.
5071 : : * @param[in, out] dev_flow
5072 : : * Pointer to the mlx5_flow.
5073 : : * @param[in] transfer
5074 : : * Mark if the flow is E-Switch flow.
5075 : : * @param[out] error
5076 : : * Pointer to the error structure.
5077 : : *
5078 : : * @return
5079 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5080 : : */
5081 : : static int
5082 : 0 : flow_dv_create_action_l2_encap(struct rte_eth_dev *dev,
5083 : : const struct rte_flow_action *action,
5084 : : struct mlx5_flow *dev_flow,
5085 : : uint8_t transfer,
5086 : : struct rte_flow_error *error)
5087 : : {
5088 : : const struct rte_flow_item *encap_data;
5089 : : const struct rte_flow_action_raw_encap *raw_encap_data;
5090 [ # # ]: 0 : struct mlx5_flow_dv_encap_decap_resource res = {
5091 : : .reformat_type =
5092 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L2_TUNNEL,
5093 : : .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
5094 : : MLX5DV_FLOW_TABLE_TYPE_NIC_TX,
5095 : : };
5096 : :
5097 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
5098 : 0 : raw_encap_data =
5099 : : (const struct rte_flow_action_raw_encap *)action->conf;
5100 : 0 : res.size = raw_encap_data->size;
5101 : 0 : memcpy(res.buf, raw_encap_data->data, res.size);
5102 : : } else {
5103 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP)
5104 : 0 : encap_data =
5105 : : ((const struct rte_flow_action_vxlan_encap *)
5106 : 0 : action->conf)->definition;
5107 : : else
5108 : 0 : encap_data =
5109 : : ((const struct rte_flow_action_nvgre_encap *)
5110 : 0 : action->conf)->definition;
5111 [ # # ]: 0 : if (flow_dv_convert_encap_data(encap_data, res.buf,
5112 : : &res.size, error))
5113 : 0 : return -rte_errno;
5114 : : }
5115 [ # # ]: 0 : if (flow_dv_zero_encap_udp_csum(res.buf, error))
5116 : 0 : return -rte_errno;
5117 [ # # ]: 0 : if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
5118 : 0 : return rte_flow_error_set(error, EINVAL,
5119 : : RTE_FLOW_ERROR_TYPE_ACTION,
5120 : : NULL, "can't create L2 encap action");
5121 : : return 0;
5122 : : }
5123 : :
5124 : : /**
5125 : : * Convert L2 decap action to DV specification.
5126 : : *
5127 : : * @param[in] dev
5128 : : * Pointer to rte_eth_dev structure.
5129 : : * @param[in, out] dev_flow
5130 : : * Pointer to the mlx5_flow.
5131 : : * @param[in] transfer
5132 : : * Mark if the flow is E-Switch flow.
5133 : : * @param[out] error
5134 : : * Pointer to the error structure.
5135 : : *
5136 : : * @return
5137 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5138 : : */
5139 : : static int
5140 : 0 : flow_dv_create_action_l2_decap(struct rte_eth_dev *dev,
5141 : : struct mlx5_flow *dev_flow,
5142 : : uint8_t transfer,
5143 : : struct rte_flow_error *error)
5144 : : {
5145 [ # # ]: 0 : struct mlx5_flow_dv_encap_decap_resource res = {
5146 : : .size = 0,
5147 : : .reformat_type =
5148 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2,
5149 : : .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
5150 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX,
5151 : : };
5152 : :
5153 [ # # ]: 0 : if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
5154 : 0 : return rte_flow_error_set(error, EINVAL,
5155 : : RTE_FLOW_ERROR_TYPE_ACTION,
5156 : : NULL, "can't create L2 decap action");
5157 : : return 0;
5158 : : }
5159 : :
5160 : : /**
5161 : : * Convert raw decap/encap (L3 tunnel) action to DV specification.
5162 : : *
5163 : : * @param[in] dev
5164 : : * Pointer to rte_eth_dev structure.
5165 : : * @param[in] action
5166 : : * Pointer to action structure.
5167 : : * @param[in, out] dev_flow
5168 : : * Pointer to the mlx5_flow.
5169 : : * @param[in] attr
5170 : : * Pointer to the flow attributes.
5171 : : * @param[out] error
5172 : : * Pointer to the error structure.
5173 : : *
5174 : : * @return
5175 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5176 : : */
5177 : : static int
5178 [ # # ]: 0 : flow_dv_create_action_raw_encap(struct rte_eth_dev *dev,
5179 : : const struct rte_flow_action *action,
5180 : : struct mlx5_flow *dev_flow,
5181 : : const struct rte_flow_attr *attr,
5182 : : struct rte_flow_error *error)
5183 : : {
5184 : : const struct rte_flow_action_raw_encap *encap_data;
5185 : : struct mlx5_flow_dv_encap_decap_resource res;
5186 : :
5187 : : memset(&res, 0, sizeof(res));
5188 : 0 : encap_data = (const struct rte_flow_action_raw_encap *)action->conf;
5189 : 0 : res.size = encap_data->size;
5190 [ # # ]: 0 : memcpy(res.buf, encap_data->data, res.size);
5191 [ # # ]: 0 : res.reformat_type = res.size < MLX5_ENCAPSULATION_DECISION_SIZE ?
5192 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L3_TUNNEL_TO_L2 :
5193 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L3_TUNNEL;
5194 [ # # ]: 0 : if (attr->transfer)
5195 : 0 : res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
5196 : : else
5197 : 0 : res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
5198 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
5199 [ # # ]: 0 : if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
5200 : 0 : return rte_flow_error_set(error, EINVAL,
5201 : : RTE_FLOW_ERROR_TYPE_ACTION,
5202 : : NULL, "can't create encap action");
5203 : : return 0;
5204 : : }
5205 : :
5206 : : /**
5207 : : * Create action push VLAN.
5208 : : *
5209 : : * @param[in] dev
5210 : : * Pointer to rte_eth_dev structure.
5211 : : * @param[in] attr
5212 : : * Pointer to the flow attributes.
5213 : : * @param[in] vlan
5214 : : * Pointer to the vlan to push to the Ethernet header.
5215 : : * @param[in, out] dev_flow
5216 : : * Pointer to the mlx5_flow.
5217 : : * @param[out] error
5218 : : * Pointer to the error structure.
5219 : : *
5220 : : * @return
5221 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5222 : : */
5223 : : static int
5224 [ # # ]: 0 : flow_dv_create_action_push_vlan(struct rte_eth_dev *dev,
5225 : : const struct rte_flow_attr *attr,
5226 : : const struct rte_vlan_hdr *vlan,
5227 : : struct mlx5_flow *dev_flow,
5228 : : struct rte_flow_error *error)
5229 : : {
5230 : : struct mlx5_flow_dv_push_vlan_action_resource res;
5231 : :
5232 : : memset(&res, 0, sizeof(res));
5233 : 0 : res.vlan_tag =
5234 [ # # ]: 0 : rte_cpu_to_be_32(((uint32_t)vlan->eth_proto) << 16 |
5235 : : vlan->vlan_tci);
5236 [ # # ]: 0 : if (attr->transfer)
5237 : 0 : res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
5238 : : else
5239 : 0 : res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
5240 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
5241 : 0 : return flow_dv_push_vlan_action_resource_register
5242 : : (dev, &res, dev_flow, error);
5243 : : }
5244 : :
5245 : : /**
5246 : : * Validate the modify-header actions.
5247 : : *
5248 : : * @param[in] action_flags
5249 : : * Holds the actions detected until now.
5250 : : * @param[in] action
5251 : : * Pointer to the modify action.
5252 : : * @param[out] error
5253 : : * Pointer to error structure.
5254 : : *
5255 : : * @return
5256 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5257 : : */
5258 : : static int
5259 : 0 : flow_dv_validate_action_modify_hdr(const uint64_t action_flags,
5260 : : const struct rte_flow_action *action,
5261 : : struct rte_flow_error *error)
5262 : : {
5263 [ # # # # ]: 0 : if (action->type != RTE_FLOW_ACTION_TYPE_DEC_TTL && !action->conf)
5264 : 0 : return rte_flow_error_set(error, EINVAL,
5265 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5266 : : NULL, "action configuration not set");
5267 : :
5268 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
5269 : 0 : return rte_flow_error_set(error, EINVAL,
5270 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5271 : : "can't have encap action before"
5272 : : " modify action");
5273 : : return 0;
5274 : : }
5275 : :
5276 : : /**
5277 : : * Validate the modify-header MAC address actions.
5278 : : *
5279 : : * @param[in] action_flags
5280 : : * Holds the actions detected until now.
5281 : : * @param[in] action
5282 : : * Pointer to the modify action.
5283 : : * @param[in] item_flags
5284 : : * Holds the items detected.
5285 : : * @param[out] error
5286 : : * Pointer to error structure.
5287 : : *
5288 : : * @return
5289 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5290 : : */
5291 : : static int
5292 : 0 : flow_dv_validate_action_modify_mac(const uint64_t action_flags,
5293 : : const struct rte_flow_action *action,
5294 : : const uint64_t item_flags,
5295 : : struct rte_flow_error *error)
5296 : : {
5297 : : int ret = 0;
5298 : :
5299 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5300 [ # # ]: 0 : if (!ret) {
5301 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_L2))
5302 : 0 : return rte_flow_error_set(error, EINVAL,
5303 : : RTE_FLOW_ERROR_TYPE_ACTION,
5304 : : NULL,
5305 : : "no L2 item in pattern");
5306 : : }
5307 : : return ret;
5308 : : }
5309 : :
5310 : : /**
5311 : : * Validate the modify-header IPv4 address actions.
5312 : : *
5313 : : * @param[in] action_flags
5314 : : * Holds the actions detected until now.
5315 : : * @param[in] action
5316 : : * Pointer to the modify action.
5317 : : * @param[in] item_flags
5318 : : * Holds the items detected.
5319 : : * @param[out] error
5320 : : * Pointer to error structure.
5321 : : *
5322 : : * @return
5323 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5324 : : */
5325 : : static int
5326 : 0 : flow_dv_validate_action_modify_ipv4(const uint64_t action_flags,
5327 : : const struct rte_flow_action *action,
5328 : : const uint64_t item_flags,
5329 : : struct rte_flow_error *error)
5330 : : {
5331 : : int ret = 0;
5332 : : uint64_t layer;
5333 : :
5334 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5335 [ # # ]: 0 : if (!ret) {
5336 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5337 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L3_IPV4 :
5338 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4;
5339 [ # # ]: 0 : if (!(item_flags & layer))
5340 : 0 : return rte_flow_error_set(error, EINVAL,
5341 : : RTE_FLOW_ERROR_TYPE_ACTION,
5342 : : NULL,
5343 : : "no ipv4 item in pattern");
5344 : : }
5345 : : return ret;
5346 : : }
5347 : :
5348 : : /**
5349 : : * Validate the modify-header IPv6 address actions.
5350 : : *
5351 : : * @param[in] action_flags
5352 : : * Holds the actions detected until now.
5353 : : * @param[in] action
5354 : : * Pointer to the modify action.
5355 : : * @param[in] item_flags
5356 : : * Holds the items detected.
5357 : : * @param[out] error
5358 : : * Pointer to error structure.
5359 : : *
5360 : : * @return
5361 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5362 : : */
5363 : : static int
5364 : 0 : flow_dv_validate_action_modify_ipv6(const uint64_t action_flags,
5365 : : const struct rte_flow_action *action,
5366 : : const uint64_t item_flags,
5367 : : struct rte_flow_error *error)
5368 : : {
5369 : : int ret = 0;
5370 : : uint64_t layer;
5371 : :
5372 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5373 [ # # ]: 0 : if (!ret) {
5374 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5375 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L3_IPV6 :
5376 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6;
5377 [ # # ]: 0 : if (!(item_flags & layer))
5378 : 0 : return rte_flow_error_set(error, EINVAL,
5379 : : RTE_FLOW_ERROR_TYPE_ACTION,
5380 : : NULL,
5381 : : "no ipv6 item in pattern");
5382 : : }
5383 : : return ret;
5384 : : }
5385 : :
5386 : : /**
5387 : : * Validate the modify-header TP actions.
5388 : : *
5389 : : * @param[in] action_flags
5390 : : * Holds the actions detected until now.
5391 : : * @param[in] action
5392 : : * Pointer to the modify action.
5393 : : * @param[in] item_flags
5394 : : * Holds the items detected.
5395 : : * @param[out] error
5396 : : * Pointer to error structure.
5397 : : *
5398 : : * @return
5399 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5400 : : */
5401 : : static int
5402 : 0 : flow_dv_validate_action_modify_tp(const uint64_t action_flags,
5403 : : const struct rte_flow_action *action,
5404 : : const uint64_t item_flags,
5405 : : struct rte_flow_error *error)
5406 : : {
5407 : : int ret = 0;
5408 : : uint64_t layer;
5409 : :
5410 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5411 [ # # ]: 0 : if (!ret) {
5412 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5413 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L4 :
5414 : : MLX5_FLOW_LAYER_OUTER_L4;
5415 [ # # ]: 0 : if (!(item_flags & layer))
5416 : 0 : return rte_flow_error_set(error, EINVAL,
5417 : : RTE_FLOW_ERROR_TYPE_ACTION,
5418 : : NULL, "no transport layer "
5419 : : "in pattern");
5420 : : }
5421 : : return ret;
5422 : : }
5423 : :
5424 : : /**
5425 : : * Validate the modify-header actions of increment/decrement
5426 : : * TCP Sequence-number.
5427 : : *
5428 : : * @param[in] action_flags
5429 : : * Holds the actions detected until now.
5430 : : * @param[in] action
5431 : : * Pointer to the modify action.
5432 : : * @param[in] item_flags
5433 : : * Holds the items detected.
5434 : : * @param[out] error
5435 : : * Pointer to error structure.
5436 : : *
5437 : : * @return
5438 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5439 : : */
5440 : : static int
5441 : 0 : flow_dv_validate_action_modify_tcp_seq(const uint64_t action_flags,
5442 : : const struct rte_flow_action *action,
5443 : : const uint64_t item_flags,
5444 : : struct rte_flow_error *error)
5445 : : {
5446 : : int ret = 0;
5447 : : uint64_t layer;
5448 : :
5449 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5450 [ # # ]: 0 : if (!ret) {
5451 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5452 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L4_TCP :
5453 : : MLX5_FLOW_LAYER_OUTER_L4_TCP;
5454 [ # # ]: 0 : if (!(item_flags & layer))
5455 : 0 : return rte_flow_error_set(error, EINVAL,
5456 : : RTE_FLOW_ERROR_TYPE_ACTION,
5457 : : NULL, "no TCP item in"
5458 : : " pattern");
5459 [ # # ]: 0 : if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ &&
5460 [ # # # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_DEC_TCP_SEQ)) ||
5461 : 0 : (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ &&
5462 [ # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_INC_TCP_SEQ)))
5463 : 0 : return rte_flow_error_set(error, EINVAL,
5464 : : RTE_FLOW_ERROR_TYPE_ACTION,
5465 : : NULL,
5466 : : "cannot decrease and increase"
5467 : : " TCP sequence number"
5468 : : " at the same time");
5469 : : }
5470 : : return ret;
5471 : : }
5472 : :
5473 : : /**
5474 : : * Validate the modify-header actions of increment/decrement
5475 : : * TCP Acknowledgment number.
5476 : : *
5477 : : * @param[in] action_flags
5478 : : * Holds the actions detected until now.
5479 : : * @param[in] action
5480 : : * Pointer to the modify action.
5481 : : * @param[in] item_flags
5482 : : * Holds the items detected.
5483 : : * @param[out] error
5484 : : * Pointer to error structure.
5485 : : *
5486 : : * @return
5487 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5488 : : */
5489 : : static int
5490 : 0 : flow_dv_validate_action_modify_tcp_ack(const uint64_t action_flags,
5491 : : const struct rte_flow_action *action,
5492 : : const uint64_t item_flags,
5493 : : struct rte_flow_error *error)
5494 : : {
5495 : : int ret = 0;
5496 : : uint64_t layer;
5497 : :
5498 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5499 [ # # ]: 0 : if (!ret) {
5500 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5501 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L4_TCP :
5502 : : MLX5_FLOW_LAYER_OUTER_L4_TCP;
5503 [ # # ]: 0 : if (!(item_flags & layer))
5504 : 0 : return rte_flow_error_set(error, EINVAL,
5505 : : RTE_FLOW_ERROR_TYPE_ACTION,
5506 : : NULL, "no TCP item in"
5507 : : " pattern");
5508 [ # # ]: 0 : if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_ACK &&
5509 [ # # # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_DEC_TCP_ACK)) ||
5510 : 0 : (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK &&
5511 [ # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_INC_TCP_ACK)))
5512 : 0 : return rte_flow_error_set(error, EINVAL,
5513 : : RTE_FLOW_ERROR_TYPE_ACTION,
5514 : : NULL,
5515 : : "cannot decrease and increase"
5516 : : " TCP acknowledgment number"
5517 : : " at the same time");
5518 : : }
5519 : : return ret;
5520 : : }
5521 : :
5522 : : /**
5523 : : * Validate the modify-header TTL actions.
5524 : : *
5525 : : * @param[in] action_flags
5526 : : * Holds the actions detected until now.
5527 : : * @param[in] action
5528 : : * Pointer to the modify action.
5529 : : * @param[in] item_flags
5530 : : * Holds the items detected.
5531 : : * @param[out] error
5532 : : * Pointer to error structure.
5533 : : *
5534 : : * @return
5535 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5536 : : */
5537 : : static int
5538 : 0 : flow_dv_validate_action_modify_ttl(const uint64_t action_flags,
5539 : : const struct rte_flow_action *action,
5540 : : const uint64_t item_flags,
5541 : : struct rte_flow_error *error)
5542 : : {
5543 : : int ret = 0;
5544 : : uint64_t layer;
5545 : :
5546 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5547 [ # # ]: 0 : if (!ret) {
5548 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5549 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L3 :
5550 : : MLX5_FLOW_LAYER_OUTER_L3;
5551 [ # # ]: 0 : if (!(item_flags & layer))
5552 : 0 : return rte_flow_error_set(error, EINVAL,
5553 : : RTE_FLOW_ERROR_TYPE_ACTION,
5554 : : NULL,
5555 : : "no IP protocol in pattern");
5556 : : }
5557 : : return ret;
5558 : : }
5559 : :
5560 : : /**
5561 : : * Validate the generic modify field actions.
5562 : : * @param[in] dev
5563 : : * Pointer to the rte_eth_dev structure.
5564 : : * @param[in] action_flags
5565 : : * Holds the actions detected until now.
5566 : : * @param[in] action
5567 : : * Pointer to the modify action.
5568 : : * @param[in] attr
5569 : : * Pointer to the flow attributes.
5570 : : * @param root
5571 : : * Whether action is on root table.
5572 : : * @param[out] error
5573 : : * Pointer to error structure.
5574 : : *
5575 : : * @return
5576 : : * Number of header fields to modify (0 or more) on success,
5577 : : * a negative errno value otherwise and rte_errno is set.
5578 : : */
5579 : : static int
5580 : 0 : flow_dv_validate_action_modify_field(struct rte_eth_dev *dev,
5581 : : const uint64_t action_flags,
5582 : : const struct rte_flow_action *action,
5583 : : const struct rte_flow_attr *attr,
5584 : : bool root,
5585 : : struct rte_flow_error *error)
5586 : : {
5587 : : int ret = 0;
5588 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5589 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
5590 : 0 : struct mlx5_hca_attr *hca_attr = &priv->sh->cdev->config.hca_attr;
5591 : 0 : const struct rte_flow_action_modify_field *conf = action->conf;
5592 : 0 : const struct rte_flow_field_data *src_data = &conf->src;
5593 : 0 : const struct rte_flow_field_data *dst_data = &conf->dst;
5594 : 0 : uint32_t dst_width, src_width, width = conf->width;
5595 : :
5596 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5597 [ # # ]: 0 : if (ret)
5598 : : return ret;
5599 [ # # ]: 0 : if (src_data->field == RTE_FLOW_FIELD_FLEX_ITEM ||
5600 [ # # ]: 0 : dst_data->field == RTE_FLOW_FIELD_FLEX_ITEM)
5601 : 0 : return rte_flow_error_set(error, ENOTSUP,
5602 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5603 : : "flex item fields modification"
5604 : : " is not supported");
5605 : 0 : dst_width = mlx5_flow_item_field_width(dev, dst_data->field,
5606 : : -1, attr, error);
5607 : 0 : src_width = mlx5_flow_item_field_width(dev, src_data->field,
5608 : : dst_width, attr, error);
5609 [ # # ]: 0 : if (width == 0)
5610 : 0 : return rte_flow_error_set(error, EINVAL,
5611 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5612 : : "no bits are requested to be modified");
5613 [ # # ]: 0 : else if (width > dst_width || width > src_width)
5614 : 0 : return rte_flow_error_set(error, EINVAL,
5615 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5616 : : "cannot modify more bits than"
5617 : : " the width of a field");
5618 [ # # ]: 0 : if (dst_data->field != RTE_FLOW_FIELD_VALUE &&
5619 : : dst_data->field != RTE_FLOW_FIELD_POINTER) {
5620 [ # # ]: 0 : if (dst_data->offset + width > dst_width)
5621 : 0 : return rte_flow_error_set(error, EINVAL,
5622 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5623 : : "destination offset is too big");
5624 : 0 : ret = flow_validate_modify_field_level(dst_data, error);
5625 [ # # ]: 0 : if (ret)
5626 : : return ret;
5627 [ # # ]: 0 : if (dst_data->tag_index &&
5628 [ # # ]: 0 : !flow_modify_field_support_tag_array(dst_data->field))
5629 : 0 : return rte_flow_error_set(error, EINVAL,
5630 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5631 : : "destination tag index is not supported");
5632 [ # # ]: 0 : if (dst_data->class_id)
5633 : 0 : return rte_flow_error_set(error, EINVAL,
5634 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5635 : : "destination class ID is not supported");
5636 : : }
5637 [ # # ]: 0 : if (src_data->field != RTE_FLOW_FIELD_VALUE &&
5638 : : src_data->field != RTE_FLOW_FIELD_POINTER) {
5639 [ # # ]: 0 : if (conf->operation != RTE_FLOW_MODIFY_SET)
5640 : 0 : return rte_flow_error_set(error, ENOTSUP,
5641 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5642 : 0 : &conf->operation,
5643 : : "modify field action type add is not"
5644 : : " supported when src field type is"
5645 : : " not value/pointer");
5646 [ # # ]: 0 : if (root)
5647 : 0 : return rte_flow_error_set(error, ENOTSUP,
5648 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5649 : : "modify field action is not"
5650 : : " supported for group 0");
5651 [ # # ]: 0 : if (src_data->offset + width > src_width)
5652 : 0 : return rte_flow_error_set(error, EINVAL,
5653 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5654 : : "source offset is too big");
5655 : 0 : ret = flow_validate_modify_field_level(src_data, error);
5656 [ # # ]: 0 : if (ret)
5657 : : return ret;
5658 [ # # ]: 0 : if (src_data->tag_index &&
5659 [ # # ]: 0 : !flow_modify_field_support_tag_array(src_data->field))
5660 : 0 : return rte_flow_error_set(error, EINVAL,
5661 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5662 : : "source tag index is not supported");
5663 [ # # ]: 0 : if (src_data->class_id)
5664 : 0 : return rte_flow_error_set(error, EINVAL,
5665 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5666 : : "source class ID is not supported");
5667 : : }
5668 [ # # ]: 0 : if ((dst_data->field == src_data->field) &&
5669 [ # # ]: 0 : (dst_data->level == src_data->level))
5670 : 0 : return rte_flow_error_set(error, EINVAL,
5671 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5672 : : "source and destination fields"
5673 : : " cannot be the same");
5674 : 0 : if (dst_data->field == RTE_FLOW_FIELD_VALUE ||
5675 [ # # ]: 0 : dst_data->field == RTE_FLOW_FIELD_POINTER ||
5676 : : dst_data->field == RTE_FLOW_FIELD_MARK)
5677 : 0 : return rte_flow_error_set(error, EINVAL,
5678 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5679 : : "mark, immediate value or a pointer to it"
5680 : : " cannot be used as a destination");
5681 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_START ||
5682 : : src_data->field == RTE_FLOW_FIELD_START)
5683 : 0 : return rte_flow_error_set(error, ENOTSUP,
5684 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5685 : : "modifications of an arbitrary"
5686 : : " place in a packet is not supported");
5687 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_VLAN_TYPE ||
5688 : : src_data->field == RTE_FLOW_FIELD_VLAN_TYPE)
5689 : 0 : return rte_flow_error_set(error, ENOTSUP,
5690 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5691 : : "modifications of the 802.1Q Tag"
5692 : : " Identifier is not supported");
5693 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_VXLAN_VNI ||
5694 : : src_data->field == RTE_FLOW_FIELD_VXLAN_VNI)
5695 : 0 : return rte_flow_error_set(error, ENOTSUP,
5696 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5697 : : "modifications of the VXLAN Network"
5698 : : " Identifier is not supported");
5699 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_GENEVE_VNI ||
5700 : : src_data->field == RTE_FLOW_FIELD_GENEVE_VNI)
5701 : 0 : return rte_flow_error_set(error, ENOTSUP,
5702 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5703 : : "modifications of the GENEVE Network"
5704 : : " Identifier is not supported");
5705 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_GENEVE_OPT_TYPE ||
5706 : : src_data->field == RTE_FLOW_FIELD_GENEVE_OPT_TYPE)
5707 : 0 : return rte_flow_error_set(error, ENOTSUP,
5708 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5709 : : "modifications of the GENEVE option type is not supported");
5710 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_GENEVE_OPT_CLASS ||
5711 : : src_data->field == RTE_FLOW_FIELD_GENEVE_OPT_CLASS)
5712 : 0 : return rte_flow_error_set(error, ENOTSUP,
5713 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5714 : : "modifications of the GENEVE option class is not supported");
5715 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_GENEVE_OPT_DATA ||
5716 : : src_data->field == RTE_FLOW_FIELD_GENEVE_OPT_DATA)
5717 : 0 : return rte_flow_error_set(error, ENOTSUP,
5718 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5719 : : "modifications of the GENEVE option data is not supported");
5720 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_MPLS ||
5721 : : src_data->field == RTE_FLOW_FIELD_MPLS)
5722 : 0 : return rte_flow_error_set(error, ENOTSUP,
5723 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5724 : : "modifications of the MPLS header "
5725 : : "is not supported");
5726 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_RANDOM ||
5727 : : src_data->field == RTE_FLOW_FIELD_RANDOM)
5728 : 0 : return rte_flow_error_set(error, ENOTSUP,
5729 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5730 : : "modifications of random value is not supported");
5731 [ # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_MARK ||
5732 : : src_data->field == RTE_FLOW_FIELD_MARK)
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 mark in legacy mode"
5738 : : " or without extensive registers");
5739 [ # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_META ||
5740 [ # # ]: 0 : src_data->field == RTE_FLOW_FIELD_META) {
5741 [ # # # # ]: 0 : if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
5742 : 0 : !mlx5_flow_ext_mreg_supported(dev))
5743 : 0 : return rte_flow_error_set(error, ENOTSUP,
5744 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5745 : : "cannot modify meta without"
5746 : : " extensive registers support");
5747 : 0 : ret = flow_dv_get_metadata_reg(dev, attr, error);
5748 [ # # ]: 0 : if (ret < 0 || ret == REG_NON)
5749 : 0 : return rte_flow_error_set(error, ENOTSUP,
5750 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5751 : : "cannot modify meta without"
5752 : : " extensive registers available");
5753 : : }
5754 [ # # ]: 0 : if (conf->operation == RTE_FLOW_MODIFY_SUB)
5755 : 0 : return rte_flow_error_set(error, ENOTSUP,
5756 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5757 : : "sub operations are not supported");
5758 [ # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_IPV4_ECN ||
5759 [ # # # # ]: 0 : src_data->field == RTE_FLOW_FIELD_IPV4_ECN ||
5760 [ # # ]: 0 : dst_data->field == RTE_FLOW_FIELD_IPV6_ECN ||
5761 : : src_data->field == RTE_FLOW_FIELD_IPV6_ECN)
5762 [ # # # # ]: 0 : if (!hca_attr->modify_outer_ip_ecn && root)
5763 : 0 : return rte_flow_error_set(error, ENOTSUP,
5764 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5765 : : "modifications of the ECN for current firmware is not supported");
5766 : 0 : return (width / 32) + !!(width % 32);
5767 : : }
5768 : :
5769 : : /**
5770 : : * Validate jump action.
5771 : : *
5772 : : * @param[in] action
5773 : : * Pointer to the jump action.
5774 : : * @param[in] action_flags
5775 : : * Holds the actions detected until now.
5776 : : * @param[in] attributes
5777 : : * Pointer to flow attributes
5778 : : * @param[in] external
5779 : : * Action belongs to flow rule created by request external to PMD.
5780 : : * @param[out] error
5781 : : * Pointer to error structure.
5782 : : *
5783 : : * @return
5784 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5785 : : */
5786 : : static int
5787 : 0 : flow_dv_validate_action_jump(struct rte_eth_dev *dev,
5788 : : const struct mlx5_flow_tunnel *tunnel,
5789 : : const struct rte_flow_action *action,
5790 : : uint64_t action_flags,
5791 : : const struct rte_flow_attr *attributes,
5792 : : bool external, struct rte_flow_error *error)
5793 : : {
5794 : 0 : uint32_t target_group, table = 0;
5795 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5796 : : int ret = 0;
5797 : 0 : struct flow_grp_info grp_info = {
5798 : : .external = !!external,
5799 : 0 : .transfer = !!attributes->transfer,
5800 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
5801 : : .std_tbl_fix = 0
5802 : : };
5803 [ # # ]: 0 : if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
5804 : : MLX5_FLOW_FATE_ESWITCH_ACTIONS))
5805 : 0 : return rte_flow_error_set(error, EINVAL,
5806 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5807 : : "can't have 2 fate actions in"
5808 : : " same flow");
5809 [ # # ]: 0 : if (!action->conf)
5810 : 0 : return rte_flow_error_set(error, EINVAL,
5811 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5812 : : NULL, "action configuration not set");
5813 : 0 : target_group =
5814 : : ((const struct rte_flow_action_jump *)action->conf)->group;
5815 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel, target_group, &table,
5816 : : &grp_info, error);
5817 [ # # ]: 0 : if (ret)
5818 : : return ret;
5819 [ # # ]: 0 : if (table == 0)
5820 : 0 : return rte_flow_error_set(error, EINVAL,
5821 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5822 : : NULL, "root table shouldn't be destination");
5823 : : return 0;
5824 : : }
5825 : :
5826 : : /*
5827 : : * Validate action PORT_ID / REPRESENTED_PORT.
5828 : : *
5829 : : * @param[in] dev
5830 : : * Pointer to rte_eth_dev structure.
5831 : : * @param[in] action_flags
5832 : : * Bit-fields that holds the actions detected until now.
5833 : : * @param[in] action
5834 : : * PORT_ID / REPRESENTED_PORT action structure.
5835 : : * @param[in] attr
5836 : : * Attributes of flow that includes this action.
5837 : : * @param[out] error
5838 : : * Pointer to error structure.
5839 : : *
5840 : : * @return
5841 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5842 : : */
5843 : : static int
5844 : 0 : flow_dv_validate_action_port_id(struct rte_eth_dev *dev,
5845 : : uint64_t action_flags,
5846 : : const struct rte_flow_action *action,
5847 : : const struct rte_flow_attr *attr,
5848 : : struct rte_flow_error *error)
5849 : : {
5850 : : const struct rte_flow_action_port_id *port_id;
5851 : : const struct rte_flow_action_ethdev *ethdev;
5852 : : struct mlx5_priv *act_priv;
5853 : : struct mlx5_priv *dev_priv;
5854 : : uint16_t port;
5855 : :
5856 [ # # ]: 0 : if (!attr->transfer)
5857 : 0 : return rte_flow_error_set(error, ENOTSUP,
5858 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5859 : : NULL,
5860 : : "port action is valid in transfer"
5861 : : " mode only");
5862 [ # # # # ]: 0 : if (!action || !action->conf)
5863 : 0 : return rte_flow_error_set(error, ENOTSUP,
5864 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5865 : : NULL,
5866 : : "port action parameters must be"
5867 : : " specified");
5868 [ # # ]: 0 : if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
5869 : : MLX5_FLOW_FATE_ESWITCH_ACTIONS))
5870 : 0 : return rte_flow_error_set(error, EINVAL,
5871 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5872 : : "can have only one fate actions in"
5873 : : " a flow");
5874 : 0 : dev_priv = mlx5_dev_to_eswitch_info(dev);
5875 [ # # ]: 0 : if (!dev_priv)
5876 : 0 : return rte_flow_error_set(error, rte_errno,
5877 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5878 : : NULL,
5879 : : "failed to obtain E-Switch info");
5880 [ # # # ]: 0 : switch (action->type) {
5881 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
5882 : 0 : port_id = action->conf;
5883 [ # # ]: 0 : port = port_id->original ? dev->data->port_id : port_id->id;
5884 : : break;
5885 : 0 : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
5886 : 0 : ethdev = action->conf;
5887 : 0 : port = ethdev->port_id;
5888 : 0 : break;
5889 : 0 : default:
5890 : : MLX5_ASSERT(false);
5891 : 0 : return rte_flow_error_set
5892 : : (error, EINVAL,
5893 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5894 : : "unknown E-Switch action");
5895 : : }
5896 : 0 : act_priv = mlx5_port_to_eswitch_info(port, false);
5897 [ # # ]: 0 : if (!act_priv)
5898 : 0 : return rte_flow_error_set
5899 : : (error, rte_errno,
5900 : 0 : RTE_FLOW_ERROR_TYPE_ACTION_CONF, action->conf,
5901 : : "failed to obtain E-Switch port id for port");
5902 [ # # ]: 0 : if (act_priv->domain_id != dev_priv->domain_id)
5903 : 0 : return rte_flow_error_set
5904 : : (error, EINVAL,
5905 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5906 : : "port does not belong to"
5907 : : " E-Switch being configured");
5908 : : return 0;
5909 : : }
5910 : :
5911 : : /**
5912 : : * Get the maximum number of modify header actions.
5913 : : *
5914 : : * @param dev
5915 : : * Pointer to rte_eth_dev structure.
5916 : : * @param root
5917 : : * Whether action is on root table.
5918 : : *
5919 : : * @return
5920 : : * Max number of modify header actions device can support.
5921 : : */
5922 : : static inline unsigned int
5923 : : flow_dv_modify_hdr_action_max(struct rte_eth_dev *dev __rte_unused,
5924 : : bool root)
5925 : : {
5926 : : /*
5927 : : * There's no way to directly query the max capacity from FW.
5928 : : * The maximal value on root table should be assumed to be supported.
5929 : : */
5930 [ # # ]: 0 : if (!root)
5931 : : return MLX5_MAX_MODIFY_NUM;
5932 : : else
5933 : 0 : return MLX5_ROOT_TBL_MODIFY_NUM;
5934 : : }
5935 : :
5936 : : /**
5937 : : * Validate the meter action.
5938 : : *
5939 : : * @param[in] dev
5940 : : * Pointer to rte_eth_dev structure.
5941 : : * @param[in] action_flags
5942 : : * Bit-fields that holds the actions detected until now.
5943 : : * @param[in] item_flags
5944 : : * Holds the items detected.
5945 : : * @param[in] action
5946 : : * Pointer to the meter action.
5947 : : * @param[in] attr
5948 : : * Attributes of flow that includes this action.
5949 : : * @param[in] port_id_item
5950 : : * Pointer to item indicating port id.
5951 : : * @param[out] error
5952 : : * Pointer to error structure.
5953 : : *
5954 : : * @return
5955 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5956 : : */
5957 : : static int
5958 : 0 : mlx5_flow_validate_action_meter(struct rte_eth_dev *dev,
5959 : : uint64_t action_flags, uint64_t item_flags,
5960 : : const struct rte_flow_action *action,
5961 : : const struct rte_flow_attr *attr,
5962 : : const struct rte_flow_item *port_id_item,
5963 : : bool *def_policy,
5964 : : struct rte_flow_error *error)
5965 : : {
5966 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5967 : 0 : const struct rte_flow_action_meter *am = action->conf;
5968 : : struct mlx5_flow_meter_info *fm;
5969 : : struct mlx5_flow_meter_policy *mtr_policy;
5970 : 0 : struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
5971 : 0 : uint16_t flow_src_port = priv->representor_id;
5972 : 0 : bool all_ports = false;
5973 : :
5974 [ # # ]: 0 : if (!am)
5975 : 0 : return rte_flow_error_set(error, EINVAL,
5976 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5977 : : "meter action conf is NULL");
5978 : :
5979 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_METER)
5980 : 0 : return rte_flow_error_set(error, ENOTSUP,
5981 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5982 : : "meter chaining not support");
5983 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_JUMP)
5984 : 0 : return rte_flow_error_set(error, ENOTSUP,
5985 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5986 : : "meter with jump not support");
5987 [ # # ]: 0 : if (!priv->mtr_en)
5988 : 0 : return rte_flow_error_set(error, ENOTSUP,
5989 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5990 : : NULL,
5991 : : "meter action not supported");
5992 : 0 : fm = mlx5_flow_meter_find(priv, am->mtr_id, NULL);
5993 [ # # ]: 0 : if (!fm)
5994 : 0 : return rte_flow_error_set(error, EINVAL,
5995 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5996 : : "Meter not found");
5997 : : /* aso meter can always be shared by different domains */
5998 [ # # # # ]: 0 : if (fm->ref_cnt && !priv->sh->meter_aso_en &&
5999 [ # # ]: 0 : !(fm->transfer == attr->transfer ||
6000 [ # # # # ]: 0 : (!fm->ingress && !attr->ingress && attr->egress) ||
6001 [ # # # # ]: 0 : (!fm->egress && !attr->egress && attr->ingress)))
6002 : 0 : return rte_flow_error_set(error, EINVAL,
6003 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6004 : : "Flow attributes domain are either invalid "
6005 : : "or have a domain conflict with current "
6006 : : "meter attributes");
6007 [ # # ]: 0 : if (fm->def_policy) {
6008 [ # # ]: 0 : if (!((attr->transfer &&
6009 [ # # ]: 0 : mtrmng->def_policy[MLX5_MTR_DOMAIN_TRANSFER]) ||
6010 [ # # ]: 0 : (attr->egress &&
6011 [ # # ]: 0 : mtrmng->def_policy[MLX5_MTR_DOMAIN_EGRESS]) ||
6012 [ # # ]: 0 : (attr->ingress &&
6013 [ # # ]: 0 : mtrmng->def_policy[MLX5_MTR_DOMAIN_INGRESS])))
6014 : 0 : return rte_flow_error_set(error, EINVAL,
6015 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6016 : : "Flow attributes domain "
6017 : : "have a conflict with current "
6018 : : "meter domain attributes");
6019 : 0 : *def_policy = true;
6020 : : } else {
6021 : 0 : mtr_policy = mlx5_flow_meter_policy_find(dev,
6022 : : fm->policy_id, NULL);
6023 [ # # ]: 0 : if (!mtr_policy)
6024 : 0 : return rte_flow_error_set(error, EINVAL,
6025 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6026 : : "Invalid policy id for meter ");
6027 [ # # # # ]: 0 : if (!((attr->transfer && mtr_policy->transfer) ||
6028 [ # # # # ]: 0 : (attr->egress && mtr_policy->egress) ||
6029 [ # # # # ]: 0 : (attr->ingress && mtr_policy->ingress)))
6030 : 0 : return rte_flow_error_set(error, EINVAL,
6031 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6032 : : "Flow attributes domain "
6033 : : "have a conflict with current "
6034 : : "meter domain attributes");
6035 [ # # ]: 0 : if (port_id_item) {
6036 [ # # ]: 0 : if (mlx5_flow_get_item_vport_id(dev, port_id_item, &flow_src_port,
6037 : : &all_ports, error))
6038 : 0 : return -rte_errno;
6039 : : }
6040 [ # # ]: 0 : if (attr->transfer) {
6041 : : /* When flow matching all src ports, meter should not have drop count. */
6042 [ # # # # : 0 : if (all_ports && (fm->drop_cnt || mtr_policy->hierarchy_match_port))
# # ]
6043 : 0 : return rte_flow_error_set(error, EINVAL,
6044 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
6045 : : "Meter drop count or "
6046 : : "modify_field/set_tag in meter hierarchy "
6047 : : "not supported when matching all ports.");
6048 [ # # ]: 0 : } else if (mtr_policy->is_rss) {
6049 : : struct mlx5_flow_meter_policy *fp;
6050 : : struct mlx5_meter_policy_action_container *acg;
6051 : : struct mlx5_meter_policy_action_container *acy;
6052 : : const struct rte_flow_action *rss_act;
6053 : : int ret;
6054 : :
6055 : 0 : fp = mlx5_flow_meter_hierarchy_get_final_policy(dev,
6056 : : mtr_policy);
6057 [ # # ]: 0 : if (fp == NULL)
6058 : 0 : return rte_flow_error_set(error, EINVAL,
6059 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6060 : : "Unable to get the final "
6061 : : "policy in the hierarchy");
6062 : : acg = &fp->act_cnt[RTE_COLOR_GREEN];
6063 : : acy = &fp->act_cnt[RTE_COLOR_YELLOW];
6064 : : MLX5_ASSERT(acg->fate_action ==
6065 : : MLX5_FLOW_FATE_SHARED_RSS ||
6066 : : acy->fate_action ==
6067 : : MLX5_FLOW_FATE_SHARED_RSS);
6068 [ # # ]: 0 : if (acg->fate_action == MLX5_FLOW_FATE_SHARED_RSS)
6069 : 0 : rss_act = acg->rss;
6070 : : else
6071 : 0 : rss_act = acy->rss;
6072 : 0 : ret = mlx5_flow_validate_action_rss(rss_act,
6073 : : action_flags, dev, attr,
6074 : : item_flags, error);
6075 [ # # ]: 0 : if (ret)
6076 : : return ret;
6077 : : }
6078 : 0 : *def_policy = false;
6079 : : }
6080 : : return 0;
6081 : : }
6082 : :
6083 : : /**
6084 : : * Validate the age action.
6085 : : *
6086 : : * @param[in] action_flags
6087 : : * Holds the actions detected until now.
6088 : : * @param[in] action
6089 : : * Pointer to the age action.
6090 : : * @param[in] dev
6091 : : * Pointer to the Ethernet device structure.
6092 : : * @param[out] error
6093 : : * Pointer to error structure.
6094 : : *
6095 : : * @return
6096 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
6097 : : */
6098 : : static int
6099 : 0 : flow_dv_validate_action_age(uint64_t action_flags,
6100 : : const struct rte_flow_action *action,
6101 : : struct rte_eth_dev *dev,
6102 : : struct rte_flow_error *error)
6103 : : {
6104 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6105 : 0 : const struct rte_flow_action_age *age = action->conf;
6106 : :
6107 [ # # ]: 0 : if (!priv->sh->cdev->config.devx ||
6108 [ # # # # ]: 0 : (priv->sh->sws_cmng.counter_fallback && !priv->sh->aso_age_mng))
6109 : 0 : return rte_flow_error_set(error, ENOTSUP,
6110 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6111 : : NULL,
6112 : : "age action not supported");
6113 [ # # ]: 0 : if (!(action->conf))
6114 : 0 : return rte_flow_error_set(error, EINVAL,
6115 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6116 : : "configuration cannot be null");
6117 [ # # ]: 0 : if (!(age->timeout))
6118 : 0 : return rte_flow_error_set(error, EINVAL,
6119 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6120 : : "invalid timeout value 0");
6121 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_AGE)
6122 : 0 : return rte_flow_error_set(error, EINVAL,
6123 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6124 : : "duplicate age actions set");
6125 : : return 0;
6126 : : }
6127 : :
6128 : : /**
6129 : : * Validate the modify-header IPv4 DSCP actions.
6130 : : *
6131 : : * @param[in] action_flags
6132 : : * Holds the actions detected until now.
6133 : : * @param[in] action
6134 : : * Pointer to the modify action.
6135 : : * @param[in] item_flags
6136 : : * Holds the items detected.
6137 : : * @param[out] error
6138 : : * Pointer to error structure.
6139 : : *
6140 : : * @return
6141 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
6142 : : */
6143 : : static int
6144 : 0 : flow_dv_validate_action_modify_ipv4_dscp(const uint64_t action_flags,
6145 : : const struct rte_flow_action *action,
6146 : : const uint64_t item_flags,
6147 : : struct rte_flow_error *error)
6148 : : {
6149 : : int ret = 0;
6150 : :
6151 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
6152 [ # # ]: 0 : if (!ret) {
6153 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV4))
6154 : 0 : return rte_flow_error_set(error, EINVAL,
6155 : : RTE_FLOW_ERROR_TYPE_ACTION,
6156 : : NULL,
6157 : : "no ipv4 item in pattern");
6158 : : }
6159 : : return ret;
6160 : : }
6161 : :
6162 : : /**
6163 : : * Validate the modify-header IPv6 DSCP actions.
6164 : : *
6165 : : * @param[in] action_flags
6166 : : * Holds the actions detected until now.
6167 : : * @param[in] action
6168 : : * Pointer to the modify action.
6169 : : * @param[in] item_flags
6170 : : * Holds the items detected.
6171 : : * @param[out] error
6172 : : * Pointer to error structure.
6173 : : *
6174 : : * @return
6175 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
6176 : : */
6177 : : static int
6178 : 0 : flow_dv_validate_action_modify_ipv6_dscp(const uint64_t action_flags,
6179 : : const struct rte_flow_action *action,
6180 : : const uint64_t item_flags,
6181 : : struct rte_flow_error *error)
6182 : : {
6183 : : int ret = 0;
6184 : :
6185 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
6186 [ # # ]: 0 : if (!ret) {
6187 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV6))
6188 : 0 : return rte_flow_error_set(error, EINVAL,
6189 : : RTE_FLOW_ERROR_TYPE_ACTION,
6190 : : NULL,
6191 : : "no ipv6 item in pattern");
6192 : : }
6193 : : return ret;
6194 : : }
6195 : :
6196 : : int
6197 : 0 : flow_modify_match_cb(void *tool_ctx __rte_unused,
6198 : : struct mlx5_list_entry *entry, void *cb_ctx)
6199 : : {
6200 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
6201 : 0 : struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
6202 : : struct mlx5_flow_dv_modify_hdr_resource *resource =
6203 : : container_of(entry, typeof(*resource), entry);
6204 : : uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type);
6205 : :
6206 : 0 : key_len += ref->actions_num * sizeof(ref->actions[0]);
6207 [ # # ]: 0 : return ref->actions_num != resource->actions_num ||
6208 [ # # ]: 0 : memcmp(&ref->ft_type, &resource->ft_type, key_len);
6209 : : }
6210 : :
6211 : : static struct mlx5_indexed_pool *
6212 : 0 : flow_dv_modify_ipool_get(struct mlx5_dev_ctx_shared *sh, uint8_t index)
6213 : : {
6214 : 0 : struct mlx5_indexed_pool *ipool = rte_atomic_load_explicit
6215 : : (&sh->mdh_ipools[index], rte_memory_order_seq_cst);
6216 : :
6217 [ # # ]: 0 : if (!ipool) {
6218 : : struct mlx5_indexed_pool *expected = NULL;
6219 : 0 : struct mlx5_indexed_pool_config cfg =
6220 : : (struct mlx5_indexed_pool_config) {
6221 : 0 : .size = sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
6222 : 0 : (index + 1) *
6223 : : sizeof(struct mlx5_modification_cmd),
6224 : : .trunk_size = 64,
6225 : : .grow_trunk = 3,
6226 : : .grow_shift = 2,
6227 : : .need_lock = 1,
6228 : 0 : .release_mem_en = !!sh->config.reclaim_mode,
6229 : : .per_core_cache =
6230 [ # # ]: 0 : sh->config.reclaim_mode ? 0 : (1 << 16),
6231 : : .malloc = mlx5_malloc,
6232 : : .free = mlx5_free,
6233 : : .type = "mlx5_modify_action_resource",
6234 : : };
6235 : :
6236 : 0 : cfg.size = RTE_ALIGN(cfg.size, sizeof(ipool));
6237 : 0 : ipool = mlx5_ipool_create(&cfg);
6238 [ # # ]: 0 : if (!ipool)
6239 : 0 : return NULL;
6240 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(&sh->mdh_ipools[index],
6241 : : &expected, ipool,
6242 : : rte_memory_order_seq_cst,
6243 : : rte_memory_order_seq_cst)) {
6244 : 0 : mlx5_ipool_destroy(ipool);
6245 : 0 : ipool = rte_atomic_load_explicit(&sh->mdh_ipools[index],
6246 : : rte_memory_order_seq_cst);
6247 : : }
6248 : : }
6249 : : return ipool;
6250 : : }
6251 : :
6252 : : struct mlx5_list_entry *
6253 : 0 : flow_modify_create_cb(void *tool_ctx, void *cb_ctx)
6254 : : {
6255 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
6256 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
6257 : : struct mlx5dv_dr_domain *ns;
6258 : : struct mlx5_flow_dv_modify_hdr_resource *entry;
6259 : 0 : struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
6260 : 0 : struct mlx5_indexed_pool *ipool = flow_dv_modify_ipool_get(sh,
6261 : 0 : ref->actions_num - 1);
6262 : : int ret = 0;
6263 : 0 : uint32_t data_len = ref->actions_num * sizeof(ref->actions[0]);
6264 : : uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type);
6265 : : uint32_t idx;
6266 : :
6267 [ # # ]: 0 : if (unlikely(!ipool)) {
6268 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
6269 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6270 : : NULL, "cannot allocate modify ipool");
6271 : 0 : return NULL;
6272 : : }
6273 : 0 : entry = mlx5_ipool_zmalloc(ipool, &idx);
6274 [ # # ]: 0 : if (!entry) {
6275 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
6276 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6277 : : "cannot allocate resource memory");
6278 : 0 : return NULL;
6279 : : }
6280 : 0 : rte_memcpy(&entry->ft_type,
6281 : 0 : RTE_PTR_ADD(ref, offsetof(typeof(*ref), ft_type)),
6282 [ # # ]: 0 : key_len + data_len);
6283 [ # # ]: 0 : if (sh->config.dv_flow_en == 2) {
6284 : : #ifdef HAVE_MLX5_HWS_SUPPORT
6285 : 0 : struct mlx5dr_action_mh_pattern pattern = {
6286 : : .sz = data_len,
6287 : 0 : .data = (__be64 *)ref->actions
6288 : : };
6289 : 0 : entry->action = mlx5dr_action_create_modify_header(ctx->data2,
6290 : : 1,
6291 : 0 : &pattern, 0, ref->flags);
6292 [ # # ]: 0 : if (!entry->action)
6293 : : ret = -1;
6294 : : #else
6295 : : ret = -1;
6296 : : #endif
6297 : : } else {
6298 [ # # ]: 0 : if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
6299 : 0 : ns = sh->fdb_domain;
6300 [ # # ]: 0 : else if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
6301 : 0 : ns = sh->tx_domain;
6302 : : else
6303 : 0 : ns = sh->rx_domain;
6304 : 0 : ret = mlx5_flow_os_create_flow_action_modify_header
6305 : 0 : (sh->cdev->ctx, ns, entry,
6306 : : data_len, &entry->action);
6307 : : }
6308 : : if (ret) {
6309 : 0 : mlx5_ipool_free(sh->mdh_ipools[ref->actions_num - 1], idx);
6310 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
6311 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6312 : : NULL, "cannot create modification action");
6313 : 0 : return NULL;
6314 : : }
6315 : 0 : entry->idx = idx;
6316 : 0 : return &entry->entry;
6317 : : }
6318 : :
6319 : : struct mlx5_list_entry *
6320 : 0 : flow_modify_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
6321 : : void *cb_ctx)
6322 : : {
6323 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
6324 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
6325 : : struct mlx5_flow_dv_modify_hdr_resource *entry;
6326 : 0 : struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
6327 : 0 : uint32_t data_len = ref->actions_num * sizeof(ref->actions[0]);
6328 : : uint32_t idx;
6329 : :
6330 : 0 : entry = mlx5_ipool_malloc(sh->mdh_ipools[ref->actions_num - 1],
6331 : : &idx);
6332 [ # # ]: 0 : if (!entry) {
6333 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
6334 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6335 : : "cannot allocate resource memory");
6336 : 0 : return NULL;
6337 : : }
6338 : 0 : memcpy(entry, oentry, sizeof(*entry) + data_len);
6339 : 0 : entry->idx = idx;
6340 : 0 : return &entry->entry;
6341 : : }
6342 : :
6343 : : void
6344 : 0 : flow_modify_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
6345 : : {
6346 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
6347 : : struct mlx5_flow_dv_modify_hdr_resource *res =
6348 : : container_of(entry, typeof(*res), entry);
6349 : :
6350 : 0 : mlx5_ipool_free(sh->mdh_ipools[res->actions_num - 1], res->idx);
6351 : 0 : }
6352 : :
6353 : : /**
6354 : : * Validate the sample action.
6355 : : *
6356 : : * @param[in, out] action_flags
6357 : : * Holds the actions detected until now.
6358 : : * @param[in] action
6359 : : * Pointer to the sample action.
6360 : : * @param[in] dev
6361 : : * Pointer to the Ethernet device structure.
6362 : : * @param[in] attr
6363 : : * Attributes of flow that includes this action.
6364 : : * @param[in] item_flags
6365 : : * Holds the items detected.
6366 : : * @param[in] rss
6367 : : * Pointer to the RSS action.
6368 : : * @param[out] sample_rss
6369 : : * Pointer to the RSS action in sample action list.
6370 : : * @param[out] count
6371 : : * Pointer to the COUNT action in sample action list.
6372 : : * @param[out] fdb_mirror
6373 : : * Pointer to the FDB mirror flag.
6374 : : * @param root
6375 : : * Whether action is on root table.
6376 : : * @param[out] error
6377 : : * Pointer to error structure.
6378 : : *
6379 : : * @return
6380 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
6381 : : */
6382 : : static int
6383 : 0 : flow_dv_validate_action_sample(uint64_t *action_flags,
6384 : : uint64_t *sub_action_flags,
6385 : : const struct rte_flow_action *action,
6386 : : struct rte_eth_dev *dev,
6387 : : const struct rte_flow_attr *attr,
6388 : : uint64_t item_flags,
6389 : : const struct rte_flow_action_rss *rss,
6390 : : const struct rte_flow_action_rss **sample_rss,
6391 : : const struct rte_flow_action_count **count,
6392 : : int *fdb_mirror,
6393 : : uint16_t *sample_port_id,
6394 : : bool root,
6395 : : struct rte_flow_error *error)
6396 : : {
6397 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6398 : 0 : struct mlx5_sh_config *dev_conf = &priv->sh->config;
6399 : 0 : const struct rte_flow_action_sample *sample = action->conf;
6400 : : const struct rte_flow_action_port_id *port = NULL;
6401 : : const struct rte_flow_action *act;
6402 : : uint16_t queue_index = 0xFFFF;
6403 : 0 : int actions_n = 0;
6404 : : int ret;
6405 : :
6406 [ # # ]: 0 : if (!sample)
6407 : 0 : return rte_flow_error_set(error, EINVAL,
6408 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6409 : : "configuration cannot be NULL");
6410 [ # # ]: 0 : if (sample->ratio == 0)
6411 : 0 : return rte_flow_error_set(error, EINVAL,
6412 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6413 : : "ratio value starts from 1");
6414 [ # # ]: 0 : if (!priv->sh->cdev->config.devx ||
6415 [ # # ]: 0 : (sample->ratio > 0 && !priv->sampler_en))
6416 : 0 : return rte_flow_error_set(error, ENOTSUP,
6417 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6418 : : NULL,
6419 : : "sample action not supported");
6420 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_SAMPLE)
6421 : 0 : return rte_flow_error_set(error, EINVAL,
6422 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6423 : : "Multiple sample actions not "
6424 : : "supported");
6425 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_METER)
6426 : 0 : return rte_flow_error_set(error, EINVAL,
6427 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6428 : : "wrong action order, meter should "
6429 : : "be after sample action");
6430 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_JUMP)
6431 : 0 : return rte_flow_error_set(error, EINVAL,
6432 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6433 : : "wrong action order, jump should "
6434 : : "be after sample action");
6435 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_CT)
6436 : 0 : return rte_flow_error_set(error, EINVAL,
6437 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6438 : : "Sample after CT not supported");
6439 : 0 : act = sample->actions;
6440 [ # # ]: 0 : for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++) {
6441 [ # # ]: 0 : if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
6442 : 0 : return rte_flow_error_set(error, ENOTSUP,
6443 : : RTE_FLOW_ERROR_TYPE_ACTION,
6444 : : act, "too many actions");
6445 [ # # # # : 0 : switch (act->type) {
# # # # ]
6446 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
6447 : 0 : ret = mlx5_flow_validate_action_queue(act,
6448 : : *sub_action_flags,
6449 : : dev,
6450 : : attr, error);
6451 [ # # ]: 0 : if (ret < 0)
6452 : 0 : return ret;
6453 : 0 : queue_index = ((const struct rte_flow_action_queue *)
6454 : 0 : (act->conf))->index;
6455 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_QUEUE;
6456 : 0 : ++actions_n;
6457 : 0 : break;
6458 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
6459 : 0 : *sample_rss = act->conf;
6460 : 0 : ret = mlx5_flow_validate_action_rss(act,
6461 : : *sub_action_flags,
6462 : : dev, attr,
6463 : : item_flags,
6464 : : error);
6465 [ # # ]: 0 : if (ret < 0)
6466 : 0 : return ret;
6467 [ # # # # ]: 0 : if (rss && *sample_rss &&
6468 [ # # ]: 0 : ((*sample_rss)->level != rss->level ||
6469 [ # # ]: 0 : (*sample_rss)->types != rss->types))
6470 : 0 : return rte_flow_error_set(error, ENOTSUP,
6471 : : RTE_FLOW_ERROR_TYPE_ACTION,
6472 : : NULL,
6473 : : "Can't use the different RSS types "
6474 : : "or level in the same flow");
6475 [ # # # # ]: 0 : if (*sample_rss != NULL && (*sample_rss)->queue_num)
6476 : 0 : queue_index = (*sample_rss)->queue[0];
6477 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_RSS;
6478 : 0 : ++actions_n;
6479 : 0 : break;
6480 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
6481 : 0 : ret = flow_dv_validate_action_mark(dev, act,
6482 : : *sub_action_flags,
6483 : : attr, error);
6484 [ # # ]: 0 : if (ret < 0)
6485 : 0 : return ret;
6486 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY)
6487 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_MARK |
6488 : : MLX5_FLOW_ACTION_MARK_EXT;
6489 : : else
6490 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_MARK;
6491 : 0 : ++actions_n;
6492 : 0 : break;
6493 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
6494 : 0 : ret = flow_dv_validate_action_count
6495 : 0 : (dev, false, *action_flags | *sub_action_flags,
6496 : : root, error);
6497 [ # # ]: 0 : if (ret < 0)
6498 : 0 : return ret;
6499 : 0 : *count = act->conf;
6500 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_COUNT;
6501 : 0 : *action_flags |= MLX5_FLOW_ACTION_COUNT;
6502 : 0 : ++actions_n;
6503 : 0 : break;
6504 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
6505 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
6506 : 0 : ret = flow_dv_validate_action_port_id(dev,
6507 : : *sub_action_flags,
6508 : : act,
6509 : : attr,
6510 : : error);
6511 [ # # ]: 0 : if (ret)
6512 : 0 : return ret;
6513 [ # # ]: 0 : if (act->type == RTE_FLOW_ACTION_TYPE_PORT_ID) {
6514 : 0 : port = (const struct rte_flow_action_port_id *)
6515 : : act->conf;
6516 [ # # ]: 0 : *sample_port_id = port->original ?
6517 : 0 : dev->data->port_id : port->id;
6518 : : } else {
6519 : 0 : *sample_port_id = ((const struct rte_flow_action_ethdev *)
6520 : 0 : act->conf)->port_id;
6521 : : }
6522 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_PORT_ID;
6523 : 0 : ++actions_n;
6524 : 0 : break;
6525 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
6526 : 0 : ret = mlx5_flow_dv_validate_action_raw_encap_decap
6527 : 0 : (dev, NULL, act->conf, attr, sub_action_flags,
6528 : : &actions_n, action, item_flags, error);
6529 [ # # ]: 0 : if (ret < 0)
6530 : 0 : return ret;
6531 : 0 : ++actions_n;
6532 : 0 : break;
6533 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
6534 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
6535 : 0 : ret = mlx5_flow_dv_validate_action_l2_encap(dev,
6536 : : *sub_action_flags,
6537 : : act, attr,
6538 : : error);
6539 [ # # ]: 0 : if (ret < 0)
6540 : 0 : return ret;
6541 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_ENCAP;
6542 : 0 : ++actions_n;
6543 : 0 : break;
6544 : 0 : default:
6545 : 0 : return rte_flow_error_set(error, ENOTSUP,
6546 : : RTE_FLOW_ERROR_TYPE_ACTION,
6547 : : NULL,
6548 : : "Doesn't support optional "
6549 : : "action");
6550 : : }
6551 : : }
6552 [ # # ]: 0 : if (attr->ingress) {
6553 [ # # ]: 0 : if (!(*sub_action_flags & (MLX5_FLOW_ACTION_QUEUE |
6554 : : MLX5_FLOW_ACTION_RSS)))
6555 : 0 : return rte_flow_error_set(error, EINVAL,
6556 : : RTE_FLOW_ERROR_TYPE_ACTION,
6557 : : NULL,
6558 : : "Ingress must has a dest "
6559 : : "QUEUE for Sample");
6560 [ # # ]: 0 : } else if (attr->egress) {
6561 : 0 : return rte_flow_error_set(error, ENOTSUP,
6562 : : RTE_FLOW_ERROR_TYPE_ACTION,
6563 : : NULL,
6564 : : "Sample Only support Ingress "
6565 : : "or E-Switch");
6566 [ # # ]: 0 : } else if (sample->actions->type != RTE_FLOW_ACTION_TYPE_END) {
6567 : : MLX5_ASSERT(attr->transfer);
6568 [ # # ]: 0 : if (sample->ratio > 1)
6569 : 0 : return rte_flow_error_set(error, ENOTSUP,
6570 : : RTE_FLOW_ERROR_TYPE_ACTION,
6571 : : NULL,
6572 : : "E-Switch doesn't support "
6573 : : "any optional action "
6574 : : "for sampling");
6575 [ # # ]: 0 : if (*sub_action_flags & MLX5_FLOW_ACTION_QUEUE)
6576 : 0 : return rte_flow_error_set(error, ENOTSUP,
6577 : : RTE_FLOW_ERROR_TYPE_ACTION,
6578 : : NULL,
6579 : : "unsupported action QUEUE");
6580 [ # # ]: 0 : if (*sub_action_flags & MLX5_FLOW_ACTION_RSS)
6581 : 0 : return rte_flow_error_set(error, ENOTSUP,
6582 : : RTE_FLOW_ERROR_TYPE_ACTION,
6583 : : NULL,
6584 : : "unsupported action QUEUE");
6585 [ # # ]: 0 : if (!(*sub_action_flags & MLX5_FLOW_ACTION_PORT_ID))
6586 : 0 : return rte_flow_error_set(error, EINVAL,
6587 : : RTE_FLOW_ERROR_TYPE_ACTION,
6588 : : NULL,
6589 : : "E-Switch must has a dest "
6590 : : "port for mirroring");
6591 : 0 : *fdb_mirror = 1;
6592 : : }
6593 : : /* Continue validation for Xcap actions.*/
6594 [ # # # # ]: 0 : if ((*sub_action_flags & MLX5_FLOW_XCAP_ACTIONS) &&
6595 [ # # ]: 0 : (queue_index == 0xFFFF || !mlx5_rxq_is_hairpin(dev, queue_index))) {
6596 [ # # ]: 0 : if ((*sub_action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
6597 : : MLX5_FLOW_XCAP_ACTIONS)
6598 : 0 : return rte_flow_error_set(error, ENOTSUP,
6599 : : RTE_FLOW_ERROR_TYPE_ACTION,
6600 : : NULL, "encap and decap "
6601 : : "combination aren't "
6602 : : "supported");
6603 [ # # # # ]: 0 : if (attr->ingress && (*sub_action_flags & MLX5_FLOW_ACTION_ENCAP))
6604 : 0 : return rte_flow_error_set(error, ENOTSUP,
6605 : : RTE_FLOW_ERROR_TYPE_ACTION,
6606 : : NULL, "encap is not supported"
6607 : : " for ingress traffic");
6608 : : }
6609 : : return 0;
6610 : : }
6611 : :
6612 : : int
6613 : 0 : __flow_modify_hdr_resource_register(struct rte_eth_dev *dev,
6614 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
6615 : : struct mlx5_flow_dv_modify_hdr_resource **modify,
6616 : : struct rte_flow_error *error)
6617 : : {
6618 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6619 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
6620 : 0 : uint32_t key_len = sizeof(*resource) -
6621 : : offsetof(typeof(*resource), ft_type) +
6622 : 0 : resource->actions_num * sizeof(resource->actions[0]);
6623 : : struct mlx5_list_entry *entry;
6624 : 0 : struct mlx5_flow_cb_ctx ctx = {
6625 : : .error = error,
6626 : : .data = resource,
6627 : 0 : .data2 = priv->dr_ctx,
6628 : : };
6629 : : struct mlx5_hlist *modify_cmds;
6630 : : uint64_t key64;
6631 : :
6632 : 0 : modify_cmds = flow_dv_hlist_prepare(sh, &sh->modify_cmds,
6633 : : "hdr_modify",
6634 : : MLX5_FLOW_HDR_MODIFY_HTABLE_SZ,
6635 : : true, false, sh,
6636 : : flow_modify_create_cb,
6637 : : flow_modify_match_cb,
6638 : : flow_modify_remove_cb,
6639 : : flow_modify_clone_cb,
6640 : : flow_modify_clone_free_cb,
6641 : : error);
6642 [ # # ]: 0 : if (unlikely(!modify_cmds))
6643 : 0 : return -rte_errno;
6644 [ # # ]: 0 : if (resource->actions_num > flow_dv_modify_hdr_action_max(dev,
6645 [ # # ]: 0 : resource->root))
6646 : 0 : return rte_flow_error_set(error, EOVERFLOW,
6647 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6648 : : "too many modify header items");
6649 : 0 : key64 = __rte_raw_cksum(&resource->ft_type, key_len, 0);
6650 : 0 : entry = mlx5_hlist_register(modify_cmds, key64, &ctx);
6651 [ # # ]: 0 : if (!entry)
6652 : 0 : return -rte_errno;
6653 : 0 : *modify = container_of(entry, typeof(*resource), entry);
6654 : 0 : return 0;
6655 : : }
6656 : :
6657 : : /**
6658 : : * Find existing modify-header resource or create and register a new one.
6659 : : *
6660 : : * @param dev[in, out]
6661 : : * Pointer to rte_eth_dev structure.
6662 : : * @param[in, out] resource
6663 : : * Pointer to modify-header resource.
6664 : : * @param[in, out] dev_flow
6665 : : * Pointer to the dev_flow.
6666 : : * @param[out] error
6667 : : * pointer to error structure.
6668 : : *
6669 : : * @return
6670 : : * 0 on success otherwise -errno and errno is set.
6671 : : */
6672 : : static int
6673 : : flow_dv_modify_hdr_resource_register
6674 : : (struct rte_eth_dev *dev,
6675 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
6676 : : struct mlx5_flow *dev_flow,
6677 : : struct rte_flow_error *error)
6678 : : {
6679 : 0 : resource->root = !dev_flow->dv.group;
6680 : 0 : return __flow_modify_hdr_resource_register(dev, resource,
6681 : 0 : &dev_flow->handle->dvh.modify_hdr, error);
6682 : : }
6683 : :
6684 : : /**
6685 : : * Get DV flow counter by index.
6686 : : *
6687 : : * @param[in] dev
6688 : : * Pointer to the Ethernet device structure.
6689 : : * @param[in] idx
6690 : : * mlx5 flow counter index in the container.
6691 : : * @param[out] ppool
6692 : : * mlx5 flow counter pool in the container.
6693 : : *
6694 : : * @return
6695 : : * Pointer to the counter, NULL otherwise.
6696 : : */
6697 : : static struct mlx5_flow_counter *
6698 : : flow_dv_counter_get_by_idx(struct rte_eth_dev *dev,
6699 : : uint32_t idx,
6700 : : struct mlx5_flow_counter_pool **ppool)
6701 : : {
6702 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6703 : 0 : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
6704 : : struct mlx5_flow_counter_pool *pool;
6705 : :
6706 : : /* Decrease to original index and clear shared bit. */
6707 : 0 : idx = (idx - 1) & (MLX5_CNT_SHARED_OFFSET - 1);
6708 : : MLX5_ASSERT(idx / MLX5_COUNTERS_PER_POOL < MLX5_COUNTER_POOLS_MAX_NUM);
6709 : 0 : pool = cmng->pools[idx / MLX5_COUNTERS_PER_POOL];
6710 : : MLX5_ASSERT(pool);
6711 : : if (ppool)
6712 : : *ppool = pool;
6713 [ # # # # : 0 : return MLX5_POOL_GET_CNT(pool, idx % MLX5_COUNTERS_PER_POOL);
# # # # #
# # # ]
6714 : : }
6715 : :
6716 : : /**
6717 : : * Check the devx counter belongs to the pool.
6718 : : *
6719 : : * @param[in] pool
6720 : : * Pointer to the counter pool.
6721 : : * @param[in] id
6722 : : * The counter devx ID.
6723 : : *
6724 : : * @return
6725 : : * True if counter belongs to the pool, false otherwise.
6726 : : */
6727 : : static bool
6728 : : flow_dv_is_counter_in_pool(struct mlx5_flow_counter_pool *pool, int id)
6729 : : {
6730 : 0 : int base = (pool->min_dcs->id / MLX5_COUNTERS_PER_POOL) *
6731 : : MLX5_COUNTERS_PER_POOL;
6732 : :
6733 [ # # # # ]: 0 : if (id >= base && id < base + MLX5_COUNTERS_PER_POOL)
6734 : : return true;
6735 : : return false;
6736 : : }
6737 : :
6738 : : /**
6739 : : * Get a pool by devx counter ID.
6740 : : *
6741 : : * @param[in] cmng
6742 : : * Pointer to the counter management.
6743 : : * @param[in] id
6744 : : * The counter devx ID.
6745 : : *
6746 : : * @return
6747 : : * The counter pool pointer if exists, NULL otherwise,
6748 : : */
6749 : : static struct mlx5_flow_counter_pool *
6750 : 0 : flow_dv_find_pool_by_id(struct mlx5_flow_counter_mng *cmng, int id)
6751 : : {
6752 : : uint32_t i;
6753 : : struct mlx5_flow_counter_pool *pool = NULL;
6754 : :
6755 : 0 : rte_spinlock_lock(&cmng->pool_update_sl);
6756 : : /* Check last used pool. */
6757 [ # # ]: 0 : if (cmng->last_pool_idx != POOL_IDX_INVALID &&
6758 [ # # ]: 0 : flow_dv_is_counter_in_pool(cmng->pools[cmng->last_pool_idx], id)) {
6759 : : pool = cmng->pools[cmng->last_pool_idx];
6760 : 0 : goto out;
6761 : : }
6762 : : /* ID out of range means no suitable pool in the container. */
6763 [ # # # # ]: 0 : if (id > cmng->max_id || id < cmng->min_id)
6764 : 0 : goto out;
6765 : : /*
6766 : : * Find the pool from the end of the container, since mostly counter
6767 : : * ID is sequence increasing, and the last pool should be the needed
6768 : : * one.
6769 : : */
6770 : 0 : i = cmng->n_valid;
6771 [ # # ]: 0 : while (i--) {
6772 [ # # ]: 0 : struct mlx5_flow_counter_pool *pool_tmp = cmng->pools[i];
6773 : :
6774 : : if (flow_dv_is_counter_in_pool(pool_tmp, id)) {
6775 : : pool = pool_tmp;
6776 : : break;
6777 : : }
6778 : : }
6779 : 0 : out:
6780 : : rte_spinlock_unlock(&cmng->pool_update_sl);
6781 : 0 : return pool;
6782 : : }
6783 : :
6784 : : /**
6785 : : * Query a devx flow counter.
6786 : : *
6787 : : * @param[in] dev
6788 : : * Pointer to the Ethernet device structure.
6789 : : * @param[in] counter
6790 : : * Index to the flow counter.
6791 : : * @param[out] pkts
6792 : : * The statistics value of packets.
6793 : : * @param[out] bytes
6794 : : * The statistics value of bytes.
6795 : : *
6796 : : * @return
6797 : : * 0 on success, otherwise a negative errno value and rte_errno is set.
6798 : : */
6799 : : static inline int
6800 : 0 : _flow_dv_query_count(struct rte_eth_dev *dev, uint32_t counter, uint64_t *pkts,
6801 : : uint64_t *bytes)
6802 : : {
6803 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
6804 : : struct mlx5_flow_counter_pool *pool = NULL;
6805 : : struct mlx5_flow_counter *cnt;
6806 : : int offset;
6807 : :
6808 : : cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
6809 : : MLX5_ASSERT(pool);
6810 [ # # ]: 0 : if (priv->sh->sws_cmng.counter_fallback)
6811 : 0 : return mlx5_devx_cmd_flow_counter_query(cnt->dcs_when_active, 0,
6812 : : 0, pkts, bytes, 0, NULL, NULL, 0);
6813 : 0 : rte_spinlock_lock(&pool->sl);
6814 [ # # ]: 0 : if (!pool->raw) {
6815 : 0 : *pkts = 0;
6816 : 0 : *bytes = 0;
6817 : : } else {
6818 [ # # ]: 0 : offset = MLX5_CNT_ARRAY_IDX(pool, cnt);
6819 : 0 : *pkts = rte_be_to_cpu_64(pool->raw->data[offset].hits);
6820 : 0 : *bytes = rte_be_to_cpu_64(pool->raw->data[offset].bytes);
6821 : : }
6822 : : rte_spinlock_unlock(&pool->sl);
6823 : 0 : return 0;
6824 : : }
6825 : :
6826 : : /**
6827 : : * Create and initialize a new counter pool.
6828 : : *
6829 : : * @param[in] dev
6830 : : * Pointer to the Ethernet device structure.
6831 : : * @param[out] dcs
6832 : : * The devX counter handle.
6833 : : * @param[in] age
6834 : : * Whether the pool is for counter that was allocated for aging.
6835 : : *
6836 : : * @return
6837 : : * The pool container pointer on success, NULL otherwise and rte_errno is set.
6838 : : */
6839 : : static struct mlx5_flow_counter_pool *
6840 : 0 : flow_dv_pool_create(struct rte_eth_dev *dev, struct mlx5_devx_obj *dcs,
6841 : : uint32_t age)
6842 : : {
6843 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6844 : : struct mlx5_flow_counter_pool *pool;
6845 : 0 : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
6846 : 0 : bool fallback = cmng->counter_fallback;
6847 : : uint32_t size = sizeof(*pool);
6848 : :
6849 [ # # ]: 0 : if (cmng->n_valid == MLX5_COUNTER_POOLS_MAX_NUM) {
6850 : 0 : DRV_LOG(ERR, "All counter is in used, try again later.");
6851 : 0 : rte_errno = EAGAIN;
6852 : 0 : return NULL;
6853 : : }
6854 : : size += MLX5_COUNTERS_PER_POOL * MLX5_CNT_SIZE;
6855 [ # # ]: 0 : size += (!age ? 0 : MLX5_COUNTERS_PER_POOL * MLX5_AGE_SIZE);
6856 : 0 : pool = mlx5_malloc(MLX5_MEM_ZERO, size, 0, SOCKET_ID_ANY);
6857 [ # # ]: 0 : if (!pool) {
6858 : 0 : rte_errno = ENOMEM;
6859 : 0 : return NULL;
6860 : : }
6861 : 0 : pool->raw = NULL;
6862 : 0 : pool->is_aged = !!age;
6863 : 0 : pool->query_gen = 0;
6864 : 0 : pool->min_dcs = dcs;
6865 : : rte_spinlock_init(&pool->sl);
6866 : : rte_spinlock_init(&pool->csl);
6867 : 0 : TAILQ_INIT(&pool->counters[0]);
6868 : 0 : TAILQ_INIT(&pool->counters[1]);
6869 : 0 : pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
6870 : 0 : rte_spinlock_lock(&cmng->pool_update_sl);
6871 : 0 : pool->index = cmng->n_valid;
6872 : 0 : cmng->pools[pool->index] = pool;
6873 : 0 : cmng->n_valid++;
6874 [ # # ]: 0 : if (unlikely(fallback)) {
6875 : 0 : int base = RTE_ALIGN_FLOOR(dcs->id, MLX5_COUNTERS_PER_POOL);
6876 : :
6877 [ # # ]: 0 : if (base < cmng->min_id)
6878 : 0 : cmng->min_id = base;
6879 [ # # ]: 0 : if (base > cmng->max_id)
6880 : 0 : cmng->max_id = base + MLX5_COUNTERS_PER_POOL - 1;
6881 : 0 : cmng->last_pool_idx = pool->index;
6882 : : }
6883 : : rte_spinlock_unlock(&cmng->pool_update_sl);
6884 : 0 : return pool;
6885 : : }
6886 : :
6887 : : /**
6888 : : * Prepare a new counter and/or a new counter pool.
6889 : : *
6890 : : * @param[in] dev
6891 : : * Pointer to the Ethernet device structure.
6892 : : * @param[out] cnt_free
6893 : : * Where to put the pointer of a new counter.
6894 : : * @param[in] age
6895 : : * Whether the pool is for counter that was allocated for aging.
6896 : : *
6897 : : * @return
6898 : : * The counter pool pointer and @p cnt_free is set on success,
6899 : : * NULL otherwise and rte_errno is set.
6900 : : */
6901 : : static struct mlx5_flow_counter_pool *
6902 : 0 : flow_dv_counter_pool_prepare(struct rte_eth_dev *dev,
6903 : : struct mlx5_flow_counter **cnt_free,
6904 : : uint32_t age)
6905 : : {
6906 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6907 : 0 : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
6908 : : struct mlx5_flow_counter_pool *pool;
6909 : : struct mlx5_counters tmp_tq;
6910 : : struct mlx5_devx_obj *dcs = NULL;
6911 : : struct mlx5_flow_counter *cnt;
6912 : 0 : enum mlx5_counter_type cnt_type =
6913 : 0 : age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
6914 : 0 : bool fallback = priv->sh->sws_cmng.counter_fallback;
6915 : : uint32_t i;
6916 : :
6917 [ # # ]: 0 : if (fallback) {
6918 : : /* bulk_bitmap must be 0 for single counter allocation. */
6919 : 0 : dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0);
6920 [ # # ]: 0 : if (!dcs)
6921 : : return NULL;
6922 : 0 : pool = flow_dv_find_pool_by_id(cmng, dcs->id);
6923 [ # # ]: 0 : if (!pool) {
6924 : 0 : pool = flow_dv_pool_create(dev, dcs, age);
6925 [ # # ]: 0 : if (!pool) {
6926 : 0 : mlx5_devx_cmd_destroy(dcs);
6927 : 0 : return NULL;
6928 : : }
6929 : : }
6930 : 0 : i = dcs->id % MLX5_COUNTERS_PER_POOL;
6931 [ # # ]: 0 : cnt = MLX5_POOL_GET_CNT(pool, i);
6932 : 0 : cnt->pool = pool;
6933 : 0 : cnt->dcs_when_free = dcs;
6934 : 0 : *cnt_free = cnt;
6935 : 0 : return pool;
6936 : : }
6937 : 0 : dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0x4);
6938 [ # # ]: 0 : if (!dcs) {
6939 : 0 : rte_errno = ENODATA;
6940 : 0 : return NULL;
6941 : : }
6942 : 0 : pool = flow_dv_pool_create(dev, dcs, age);
6943 [ # # ]: 0 : if (!pool) {
6944 : 0 : mlx5_devx_cmd_destroy(dcs);
6945 : 0 : return NULL;
6946 : : }
6947 : 0 : TAILQ_INIT(&tmp_tq);
6948 [ # # ]: 0 : for (i = 1; i < MLX5_COUNTERS_PER_POOL; ++i) {
6949 [ # # ]: 0 : cnt = MLX5_POOL_GET_CNT(pool, i);
6950 : 0 : cnt->pool = pool;
6951 [ # # ]: 0 : TAILQ_INSERT_HEAD(&tmp_tq, cnt, next);
6952 : : }
6953 : 0 : rte_spinlock_lock(&cmng->csl[cnt_type]);
6954 [ # # ]: 0 : TAILQ_CONCAT(&cmng->counters[cnt_type], &tmp_tq, next);
6955 : : rte_spinlock_unlock(&cmng->csl[cnt_type]);
6956 : 0 : *cnt_free = MLX5_POOL_GET_CNT(pool, 0);
6957 : 0 : (*cnt_free)->pool = pool;
6958 : 0 : return pool;
6959 : : }
6960 : :
6961 : : /**
6962 : : * Allocate a flow counter.
6963 : : *
6964 : : * @param[in] dev
6965 : : * Pointer to the Ethernet device structure.
6966 : : * @param[in] age
6967 : : * Whether the counter was allocated for aging.
6968 : : *
6969 : : * @return
6970 : : * Index to flow counter on success, 0 otherwise and rte_errno is set.
6971 : : */
6972 : : static uint32_t
6973 : 0 : flow_dv_counter_alloc(struct rte_eth_dev *dev, uint32_t age)
6974 : : {
6975 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6976 : : struct mlx5_flow_counter_pool *pool = NULL;
6977 : 0 : struct mlx5_flow_counter *cnt_free = NULL;
6978 : 0 : bool fallback = priv->sh->sws_cmng.counter_fallback;
6979 : : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
6980 : 0 : enum mlx5_counter_type cnt_type =
6981 : 0 : age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
6982 : : uint32_t cnt_idx;
6983 : :
6984 [ # # ]: 0 : if (!priv->sh->cdev->config.devx) {
6985 : 0 : rte_errno = ENOTSUP;
6986 : 0 : return 0;
6987 : : }
6988 : : /* Get free counters from container. */
6989 : 0 : rte_spinlock_lock(&cmng->csl[cnt_type]);
6990 : 0 : cnt_free = TAILQ_FIRST(&cmng->counters[cnt_type]);
6991 [ # # ]: 0 : if (cnt_free)
6992 [ # # ]: 0 : TAILQ_REMOVE(&cmng->counters[cnt_type], cnt_free, next);
6993 : : rte_spinlock_unlock(&cmng->csl[cnt_type]);
6994 [ # # # # ]: 0 : if (!cnt_free && !flow_dv_counter_pool_prepare(dev, &cnt_free, age))
6995 : 0 : goto err;
6996 : 0 : pool = cnt_free->pool;
6997 [ # # ]: 0 : if (fallback)
6998 : 0 : cnt_free->dcs_when_active = cnt_free->dcs_when_free;
6999 : : /* Create a DV counter action only in the first time usage. */
7000 [ # # ]: 0 : if (!cnt_free->action) {
7001 : : uint16_t offset;
7002 : : struct mlx5_devx_obj *dcs;
7003 : : int ret;
7004 : :
7005 [ # # ]: 0 : if (!fallback) {
7006 [ # # ]: 0 : offset = MLX5_CNT_ARRAY_IDX(pool, cnt_free);
7007 : 0 : dcs = pool->min_dcs;
7008 : : } else {
7009 : : offset = 0;
7010 : 0 : dcs = cnt_free->dcs_when_free;
7011 : : }
7012 : 0 : ret = mlx5_flow_os_create_flow_action_count(dcs->obj, offset,
7013 : : &cnt_free->action);
7014 : : if (ret) {
7015 : 0 : rte_errno = errno;
7016 : 0 : goto err;
7017 : : }
7018 : : }
7019 [ # # ]: 0 : cnt_idx = MLX5_MAKE_CNT_IDX(pool->index,
7020 : : MLX5_CNT_ARRAY_IDX(pool, cnt_free));
7021 : : /* Update the counter reset values. */
7022 [ # # ]: 0 : if (_flow_dv_query_count(dev, cnt_idx, &cnt_free->hits,
7023 : : &cnt_free->bytes))
7024 : 0 : goto err;
7025 [ # # # # ]: 0 : if (!fallback && !priv->sh->sws_cmng.query_thread_on)
7026 : : /* Start the asynchronous batch query by the host thread. */
7027 : 0 : mlx5_set_query_alarm(priv->sh);
7028 : : /*
7029 : : * When the count action isn't shared (by ID), shared_info field is
7030 : : * used for indirect action API's refcnt.
7031 : : * When the counter action is not shared neither by ID nor by indirect
7032 : : * action API, shared info must be 1.
7033 : : */
7034 : 0 : cnt_free->shared_info.refcnt = 1;
7035 : 0 : return cnt_idx;
7036 : 0 : err:
7037 [ # # ]: 0 : if (cnt_free) {
7038 : 0 : cnt_free->pool = pool;
7039 [ # # ]: 0 : if (fallback)
7040 : 0 : cnt_free->dcs_when_free = cnt_free->dcs_when_active;
7041 : : rte_spinlock_lock(&cmng->csl[cnt_type]);
7042 : 0 : TAILQ_INSERT_TAIL(&cmng->counters[cnt_type], cnt_free, next);
7043 : : rte_spinlock_unlock(&cmng->csl[cnt_type]);
7044 : : }
7045 : : return 0;
7046 : : }
7047 : :
7048 : : /**
7049 : : * Get age param from counter index.
7050 : : *
7051 : : * @param[in] dev
7052 : : * Pointer to the Ethernet device structure.
7053 : : * @param[in] counter
7054 : : * Index to the counter handler.
7055 : : *
7056 : : * @return
7057 : : * The aging parameter specified for the counter index.
7058 : : */
7059 : : static struct mlx5_age_param*
7060 : : flow_dv_counter_idx_get_age(struct rte_eth_dev *dev,
7061 : : uint32_t counter)
7062 : : {
7063 : : struct mlx5_flow_counter *cnt;
7064 : : struct mlx5_flow_counter_pool *pool = NULL;
7065 : :
7066 : : flow_dv_counter_get_by_idx(dev, counter, &pool);
7067 : : counter = (counter - 1) % MLX5_COUNTERS_PER_POOL;
7068 : : cnt = MLX5_POOL_GET_CNT(pool, counter);
7069 : 0 : return MLX5_CNT_TO_AGE(cnt);
7070 : : }
7071 : :
7072 : : /**
7073 : : * Remove a flow counter from aged counter list.
7074 : : *
7075 : : * @param[in] dev
7076 : : * Pointer to the Ethernet device structure.
7077 : : * @param[in] counter
7078 : : * Index to the counter handler.
7079 : : * @param[in] cnt
7080 : : * Pointer to the counter handler.
7081 : : */
7082 : : static void
7083 : 0 : flow_dv_counter_remove_from_age(struct rte_eth_dev *dev,
7084 : : uint32_t counter, struct mlx5_flow_counter *cnt)
7085 : : {
7086 : : struct mlx5_age_info *age_info;
7087 : : struct mlx5_age_param *age_param;
7088 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7089 : : uint16_t expected = AGE_CANDIDATE;
7090 : :
7091 [ # # ]: 0 : age_info = GET_PORT_AGE_INFO(priv);
7092 : : age_param = flow_dv_counter_idx_get_age(dev, counter);
7093 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(&age_param->state, &expected,
7094 : : AGE_FREE, rte_memory_order_relaxed,
7095 : : rte_memory_order_relaxed)) {
7096 : : /**
7097 : : * We need the lock even it is age timeout,
7098 : : * since counter may still in process.
7099 : : */
7100 : 0 : rte_spinlock_lock(&age_info->aged_sl);
7101 [ # # ]: 0 : TAILQ_REMOVE(&age_info->aged_counters, cnt, next);
7102 : : rte_spinlock_unlock(&age_info->aged_sl);
7103 : 0 : rte_atomic_store_explicit(&age_param->state, AGE_FREE, rte_memory_order_relaxed);
7104 : : }
7105 : 0 : }
7106 : :
7107 : : /**
7108 : : * Release a flow counter.
7109 : : *
7110 : : * @param[in] dev
7111 : : * Pointer to the Ethernet device structure.
7112 : : * @param[in] counter
7113 : : * Index to the counter handler.
7114 : : */
7115 : : static void
7116 : 0 : flow_dv_counter_free(struct rte_eth_dev *dev, uint32_t counter)
7117 : : {
7118 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7119 : : struct mlx5_flow_counter_pool *pool = NULL;
7120 : : struct mlx5_flow_counter *cnt;
7121 : : enum mlx5_counter_type cnt_type;
7122 : :
7123 [ # # ]: 0 : if (!counter)
7124 : : return;
7125 : : cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
7126 : : MLX5_ASSERT(pool);
7127 [ # # ]: 0 : if (pool->is_aged) {
7128 : 0 : flow_dv_counter_remove_from_age(dev, counter, cnt);
7129 : : } else {
7130 : : /*
7131 : : * If the counter action is shared by indirect action API,
7132 : : * the atomic function reduces its references counter.
7133 : : * If after the reduction the action is still referenced, the
7134 : : * function returns here and does not release it.
7135 : : * When the counter action is not shared by
7136 : : * indirect action API, shared info is 1 before the reduction,
7137 : : * so this condition is failed and function doesn't return here.
7138 : : */
7139 [ # # ]: 0 : if (rte_atomic_fetch_sub_explicit(&cnt->shared_info.refcnt, 1,
7140 : : rte_memory_order_relaxed) - 1)
7141 : : return;
7142 : : }
7143 : 0 : cnt->pool = pool;
7144 : : /*
7145 : : * Put the counter back to list to be updated in none fallback mode.
7146 : : * Currently, we are using two list alternately, while one is in query,
7147 : : * add the freed counter to the other list based on the pool query_gen
7148 : : * value. After query finishes, add counter the list to the global
7149 : : * container counter list. The list changes while query starts. In
7150 : : * this case, lock will not be needed as query callback and release
7151 : : * function both operate with the different list.
7152 : : */
7153 [ # # ]: 0 : if (!priv->sh->sws_cmng.counter_fallback) {
7154 : 0 : rte_spinlock_lock(&pool->csl);
7155 : 0 : TAILQ_INSERT_TAIL(&pool->counters[pool->query_gen], cnt, next);
7156 : : rte_spinlock_unlock(&pool->csl);
7157 : : } else {
7158 : 0 : cnt->dcs_when_free = cnt->dcs_when_active;
7159 : 0 : cnt_type = pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
7160 : : MLX5_COUNTER_TYPE_ORIGIN;
7161 : 0 : rte_spinlock_lock(&priv->sh->sws_cmng.csl[cnt_type]);
7162 : 0 : TAILQ_INSERT_TAIL(&priv->sh->sws_cmng.counters[cnt_type],
7163 : : cnt, next);
7164 : 0 : rte_spinlock_unlock(&priv->sh->sws_cmng.csl[cnt_type]);
7165 : : }
7166 : : }
7167 : :
7168 : : /**
7169 : : * Resize a meter id container.
7170 : : *
7171 : : * @param[in] dev
7172 : : * Pointer to the Ethernet device structure.
7173 : : *
7174 : : * @return
7175 : : * 0 on success, otherwise negative errno value and rte_errno is set.
7176 : : */
7177 : : static int
7178 : 0 : flow_dv_mtr_container_resize(struct rte_eth_dev *dev)
7179 : : {
7180 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7181 : : struct mlx5_aso_mtr_pools_mng *pools_mng =
7182 : 0 : &priv->sh->mtrmng->pools_mng;
7183 : 0 : void *old_pools = pools_mng->pools;
7184 : 0 : uint32_t resize = pools_mng->n + MLX5_MTRS_CONTAINER_RESIZE;
7185 : 0 : uint32_t mem_size = sizeof(struct mlx5_aso_mtr_pool *) * resize;
7186 : 0 : void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
7187 : :
7188 [ # # ]: 0 : if (!pools) {
7189 : 0 : rte_errno = ENOMEM;
7190 : 0 : return -ENOMEM;
7191 : : }
7192 [ # # ]: 0 : if (!pools_mng->n)
7193 [ # # ]: 0 : if (mlx5_aso_queue_init(priv->sh, ASO_OPC_MOD_POLICER, 1)) {
7194 : 0 : mlx5_free(pools);
7195 : 0 : return -ENOMEM;
7196 : : }
7197 [ # # ]: 0 : if (old_pools)
7198 : 0 : memcpy(pools, old_pools, pools_mng->n *
7199 : : sizeof(struct mlx5_aso_mtr_pool *));
7200 : 0 : pools_mng->n = resize;
7201 : 0 : pools_mng->pools = pools;
7202 [ # # ]: 0 : if (old_pools)
7203 : 0 : mlx5_free(old_pools);
7204 : : return 0;
7205 : : }
7206 : :
7207 : : /**
7208 : : * Prepare a new meter and/or a new meter pool.
7209 : : *
7210 : : * @param[in] dev
7211 : : * Pointer to the Ethernet device structure.
7212 : : * @param[out] mtr_free
7213 : : * Where to put the pointer of a new meter.g.
7214 : : *
7215 : : * @return
7216 : : * The meter pool pointer and @mtr_free is set on success,
7217 : : * NULL otherwise and rte_errno is set.
7218 : : */
7219 : : static struct mlx5_aso_mtr_pool *
7220 : 0 : flow_dv_mtr_pool_create(struct rte_eth_dev *dev, struct mlx5_aso_mtr **mtr_free)
7221 : : {
7222 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7223 : 0 : struct mlx5_aso_mtr_pools_mng *pools_mng = &priv->sh->mtrmng->pools_mng;
7224 : : struct mlx5_aso_mtr_pool *pool = NULL;
7225 : : struct mlx5_devx_obj *dcs = NULL;
7226 : : uint32_t i;
7227 : : uint32_t log_obj_size;
7228 : :
7229 : : log_obj_size = rte_log2_u32(MLX5_ASO_MTRS_PER_POOL >> 1);
7230 : 0 : dcs = mlx5_devx_cmd_create_flow_meter_aso_obj(priv->sh->cdev->ctx,
7231 : 0 : priv->sh->cdev->pdn,
7232 : : log_obj_size);
7233 [ # # ]: 0 : if (!dcs) {
7234 : 0 : rte_errno = ENODATA;
7235 : 0 : return NULL;
7236 : : }
7237 : 0 : pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
7238 [ # # ]: 0 : if (!pool) {
7239 : 0 : rte_errno = ENOMEM;
7240 : 0 : claim_zero(mlx5_devx_cmd_destroy(dcs));
7241 : 0 : return NULL;
7242 : : }
7243 : 0 : pool->devx_obj = dcs;
7244 : 0 : rte_rwlock_write_lock(&pools_mng->resize_mtrwl);
7245 : 0 : pool->index = pools_mng->n_valid;
7246 [ # # # # ]: 0 : if (pool->index == pools_mng->n && flow_dv_mtr_container_resize(dev)) {
7247 : 0 : mlx5_free(pool);
7248 : 0 : claim_zero(mlx5_devx_cmd_destroy(dcs));
7249 : : rte_rwlock_write_unlock(&pools_mng->resize_mtrwl);
7250 : 0 : return NULL;
7251 : : }
7252 : 0 : pools_mng->pools[pool->index] = pool;
7253 : 0 : pools_mng->n_valid++;
7254 : : rte_rwlock_write_unlock(&pools_mng->resize_mtrwl);
7255 [ # # ]: 0 : for (i = 1; i < MLX5_ASO_MTRS_PER_POOL; ++i) {
7256 : 0 : pool->mtrs[i].offset = i;
7257 [ # # ]: 0 : LIST_INSERT_HEAD(&pools_mng->meters, &pool->mtrs[i], next);
7258 : : }
7259 : 0 : pool->mtrs[0].offset = 0;
7260 : 0 : *mtr_free = &pool->mtrs[0];
7261 : 0 : return pool;
7262 : : }
7263 : :
7264 : : /**
7265 : : * Release a flow meter into pool.
7266 : : *
7267 : : * @param[in] dev
7268 : : * Pointer to the Ethernet device structure.
7269 : : * @param[in] mtr_idx
7270 : : * Index to aso flow meter.
7271 : : */
7272 : : static void
7273 : 0 : flow_dv_aso_mtr_release_to_pool(struct rte_eth_dev *dev, uint32_t mtr_idx)
7274 : : {
7275 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7276 : : struct mlx5_aso_mtr_pools_mng *pools_mng =
7277 : 0 : &priv->sh->mtrmng->pools_mng;
7278 : 0 : struct mlx5_aso_mtr *aso_mtr = mlx5_aso_meter_by_idx(priv, mtr_idx);
7279 : :
7280 : : MLX5_ASSERT(aso_mtr);
7281 : 0 : rte_spinlock_lock(&pools_mng->mtrsl);
7282 [ # # ]: 0 : memset(&aso_mtr->fm, 0, sizeof(struct mlx5_flow_meter_info));
7283 : 0 : aso_mtr->state = ASO_METER_FREE;
7284 [ # # ]: 0 : LIST_INSERT_HEAD(&pools_mng->meters, aso_mtr, next);
7285 : : rte_spinlock_unlock(&pools_mng->mtrsl);
7286 : 0 : }
7287 : :
7288 : : /**
7289 : : * Allocate a aso flow meter.
7290 : : *
7291 : : * @param[in] dev
7292 : : * Pointer to the Ethernet device structure.
7293 : : *
7294 : : * @return
7295 : : * Index to aso flow meter on success, 0 otherwise and rte_errno is set.
7296 : : */
7297 : : static uint32_t
7298 : 0 : flow_dv_mtr_alloc(struct rte_eth_dev *dev)
7299 : : {
7300 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7301 : 0 : struct mlx5_aso_mtr *mtr_free = NULL;
7302 : : struct mlx5_aso_mtr_pools_mng *pools_mng =
7303 : 0 : &priv->sh->mtrmng->pools_mng;
7304 : : struct mlx5_aso_mtr_pool *pool;
7305 : : uint32_t mtr_idx = 0;
7306 : :
7307 [ # # ]: 0 : if (!priv->sh->cdev->config.devx) {
7308 : 0 : rte_errno = ENOTSUP;
7309 : 0 : return 0;
7310 : : }
7311 : : /* Allocate the flow meter memory. */
7312 : : /* Get free meters from management. */
7313 : 0 : rte_spinlock_lock(&pools_mng->mtrsl);
7314 : 0 : mtr_free = LIST_FIRST(&pools_mng->meters);
7315 [ # # ]: 0 : if (mtr_free)
7316 [ # # ]: 0 : LIST_REMOVE(mtr_free, next);
7317 [ # # # # ]: 0 : if (!mtr_free && !flow_dv_mtr_pool_create(dev, &mtr_free)) {
7318 : : rte_spinlock_unlock(&pools_mng->mtrsl);
7319 : 0 : return 0;
7320 : : }
7321 : 0 : mtr_free->state = ASO_METER_WAIT;
7322 : : rte_spinlock_unlock(&pools_mng->mtrsl);
7323 : 0 : pool = container_of(mtr_free,
7324 : : struct mlx5_aso_mtr_pool,
7325 : : mtrs[mtr_free->offset]);
7326 : 0 : mtr_idx = MLX5_MAKE_MTR_IDX(pool->index, mtr_free->offset);
7327 [ # # ]: 0 : if (!mtr_free->fm.meter_action_g) {
7328 : : #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
7329 : : struct rte_flow_error error;
7330 : : uint8_t reg_id;
7331 : :
7332 : 0 : reg_id = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &error);
7333 : 0 : mtr_free->fm.meter_action_g =
7334 : 0 : mlx5_glue->dv_create_flow_action_aso
7335 : 0 : (priv->sh->rx_domain,
7336 : 0 : pool->devx_obj->obj,
7337 : : mtr_free->offset,
7338 : : (1 << MLX5_FLOW_COLOR_GREEN),
7339 : 0 : reg_id - REG_C_0);
7340 : : #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
7341 [ # # ]: 0 : if (!mtr_free->fm.meter_action_g) {
7342 : 0 : flow_dv_aso_mtr_release_to_pool(dev, mtr_idx);
7343 : 0 : return 0;
7344 : : }
7345 : : }
7346 : : return mtr_idx;
7347 : : }
7348 : :
7349 : : /**
7350 : : * Verify the @p attributes will be correctly understood by the NIC and store
7351 : : * them in the @p flow if everything is correct.
7352 : : *
7353 : : * @param[in] dev
7354 : : * Pointer to dev struct.
7355 : : * @param[in] attributes
7356 : : * Pointer to flow attributes
7357 : : * @param[in] external
7358 : : * This flow rule is created by request external to PMD.
7359 : : * @param[out] error
7360 : : * Pointer to error structure.
7361 : : *
7362 : : * @return
7363 : : * - 0 on success and non root table.
7364 : : * - 1 on success and root table.
7365 : : * - a negative errno value otherwise and rte_errno is set.
7366 : : */
7367 : : static int
7368 : 0 : flow_dv_validate_attributes(struct rte_eth_dev *dev,
7369 : : const struct mlx5_flow_tunnel *tunnel,
7370 : : const struct rte_flow_attr *attributes,
7371 : : const struct flow_grp_info *grp_info,
7372 : : struct rte_flow_error *error)
7373 : : {
7374 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7375 : 0 : uint32_t lowest_priority = mlx5_get_lowest_priority(dev, attributes);
7376 : : int ret = 0;
7377 : :
7378 : : #ifndef HAVE_MLX5DV_DR
7379 : : RTE_SET_USED(tunnel);
7380 : : RTE_SET_USED(grp_info);
7381 : : if (attributes->group)
7382 : : return rte_flow_error_set(error, ENOTSUP,
7383 : : RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
7384 : : NULL,
7385 : : "groups are not supported");
7386 : : #else
7387 : 0 : uint32_t table = 0;
7388 : :
7389 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel, attributes->group, &table,
7390 : : grp_info, error);
7391 [ # # ]: 0 : if (ret)
7392 : : return ret;
7393 [ # # ]: 0 : if (!table)
7394 : : ret = MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL;
7395 : : #endif
7396 [ # # # # ]: 0 : if (attributes->priority != MLX5_FLOW_LOWEST_PRIO_INDICATOR &&
7397 : : attributes->priority > lowest_priority)
7398 : 0 : return rte_flow_error_set(error, ENOTSUP,
7399 : : RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
7400 : : NULL,
7401 : : "priority out of range");
7402 [ # # # # ]: 0 : if (attributes->transfer && !priv->sh->config.dv_esw_en)
7403 : 0 : return rte_flow_error_set(error, ENOTSUP,
7404 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7405 : : "E-Switch dr is not supported");
7406 [ # # ]: 0 : if (attributes->ingress + attributes->egress + attributes->transfer != 1) {
7407 : 0 : return rte_flow_error_set(error, EINVAL,
7408 : : RTE_FLOW_ERROR_TYPE_ATTR, NULL,
7409 : : "must specify exactly one of "
7410 : : "ingress, egress or transfer");
7411 : : }
7412 : : return ret;
7413 : : }
7414 : :
7415 : : static int
7416 : 0 : validate_integrity_bits(const void *arg,
7417 : : int64_t pattern_flags, uint64_t l3_flags,
7418 : : uint64_t l4_flags, uint64_t ip4_flag,
7419 : : struct rte_flow_error *error)
7420 : : {
7421 : : const struct rte_flow_item_integrity *mask = arg;
7422 : :
7423 [ # # # # ]: 0 : if (mask->l3_ok && !(pattern_flags & l3_flags))
7424 : 0 : return rte_flow_error_set(error, EINVAL,
7425 : : RTE_FLOW_ERROR_TYPE_ITEM,
7426 : : NULL, "missing L3 protocol");
7427 : :
7428 [ # # # # ]: 0 : if (mask->ipv4_csum_ok && !(pattern_flags & ip4_flag))
7429 : 0 : return rte_flow_error_set(error, EINVAL,
7430 : : RTE_FLOW_ERROR_TYPE_ITEM,
7431 : : NULL, "missing IPv4 protocol");
7432 : :
7433 [ # # # # ]: 0 : if ((mask->l4_ok || mask->l4_csum_ok) && !(pattern_flags & l4_flags))
7434 : 0 : return rte_flow_error_set(error, EINVAL,
7435 : : RTE_FLOW_ERROR_TYPE_ITEM,
7436 : : NULL, "missing L4 protocol");
7437 : :
7438 : : return 0;
7439 : : }
7440 : :
7441 : : static int
7442 : 0 : flow_dv_validate_item_integrity_post(const struct
7443 : : rte_flow_item *integrity_items[2],
7444 : : int64_t pattern_flags,
7445 : : struct rte_flow_error *error)
7446 : : {
7447 : : const struct rte_flow_item_integrity *mask;
7448 : : int ret;
7449 : :
7450 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_OUTER_INTEGRITY) {
7451 : 0 : mask = (typeof(mask))integrity_items[0]->mask;
7452 : 0 : ret = validate_integrity_bits(mask, pattern_flags,
7453 : : MLX5_FLOW_LAYER_OUTER_L3,
7454 : : MLX5_FLOW_LAYER_OUTER_L4,
7455 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4,
7456 : : error);
7457 [ # # ]: 0 : if (ret)
7458 : : return ret;
7459 : : }
7460 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_INNER_INTEGRITY) {
7461 : 0 : mask = (typeof(mask))integrity_items[1]->mask;
7462 : 0 : ret = validate_integrity_bits(mask, pattern_flags,
7463 : : MLX5_FLOW_LAYER_INNER_L3,
7464 : : MLX5_FLOW_LAYER_INNER_L4,
7465 : : MLX5_FLOW_LAYER_INNER_L3_IPV4,
7466 : : error);
7467 [ # # ]: 0 : if (ret)
7468 : 0 : return ret;
7469 : : }
7470 : : return 0;
7471 : : }
7472 : :
7473 : : static int
7474 : 0 : flow_dv_validate_item_integrity(struct rte_eth_dev *dev,
7475 : : const struct rte_flow_item *integrity_item,
7476 : : uint64_t pattern_flags, uint64_t *last_item,
7477 : : const struct rte_flow_item *integrity_items[2],
7478 : : struct rte_flow_error *error)
7479 : : {
7480 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7481 : 0 : const struct rte_flow_item_integrity *mask = (typeof(mask))
7482 : : integrity_item->mask;
7483 : 0 : const struct rte_flow_item_integrity *spec = (typeof(spec))
7484 : : integrity_item->spec;
7485 : :
7486 [ # # ]: 0 : if (!priv->sh->cdev->config.hca_attr.pkt_integrity_match)
7487 : 0 : return rte_flow_error_set(error, ENOTSUP,
7488 : : RTE_FLOW_ERROR_TYPE_ITEM,
7489 : : integrity_item,
7490 : : "packet integrity integrity_item not supported");
7491 [ # # ]: 0 : if (!spec)
7492 : 0 : return rte_flow_error_set(error, ENOTSUP,
7493 : : RTE_FLOW_ERROR_TYPE_ITEM,
7494 : : integrity_item,
7495 : : "no spec for integrity item");
7496 [ # # ]: 0 : if (!mask)
7497 : : mask = &rte_flow_item_integrity_mask;
7498 [ # # ]: 0 : if (!mlx5_validate_integrity_item(mask))
7499 : 0 : return rte_flow_error_set(error, ENOTSUP,
7500 : : RTE_FLOW_ERROR_TYPE_ITEM,
7501 : : integrity_item,
7502 : : "unsupported integrity filter");
7503 [ # # # # ]: 0 : if ((mask->l3_ok & !spec->l3_ok) || (mask->l4_ok & !spec->l4_ok) ||
7504 [ # # ]: 0 : (mask->ipv4_csum_ok & !spec->ipv4_csum_ok) ||
7505 [ # # ]: 0 : (mask->l4_csum_ok & !spec->l4_csum_ok))
7506 : 0 : return rte_flow_error_set(error, EINVAL,
7507 : : RTE_FLOW_ERROR_TYPE_ITEM,
7508 : : NULL, "negative integrity flow is not supported");
7509 [ # # ]: 0 : if (spec->level > 1) {
7510 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_INNER_INTEGRITY)
7511 : 0 : return rte_flow_error_set
7512 : : (error, ENOTSUP,
7513 : : RTE_FLOW_ERROR_TYPE_ITEM,
7514 : : NULL, "multiple inner integrity items not supported");
7515 : 0 : integrity_items[1] = integrity_item;
7516 : 0 : *last_item |= MLX5_FLOW_ITEM_INNER_INTEGRITY;
7517 : : } else {
7518 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_OUTER_INTEGRITY)
7519 : 0 : return rte_flow_error_set
7520 : : (error, ENOTSUP,
7521 : : RTE_FLOW_ERROR_TYPE_ITEM,
7522 : : NULL, "multiple outer integrity items not supported");
7523 : 0 : integrity_items[0] = integrity_item;
7524 : 0 : *last_item |= MLX5_FLOW_ITEM_OUTER_INTEGRITY;
7525 : : }
7526 : : return 0;
7527 : : }
7528 : :
7529 : : static int
7530 : 0 : flow_dv_validate_item_flex(struct rte_eth_dev *dev,
7531 : : const struct rte_flow_item *item,
7532 : : uint64_t item_flags,
7533 : : uint64_t *last_item,
7534 : : bool is_inner,
7535 : : struct rte_flow_error *error)
7536 : : {
7537 : 0 : const struct rte_flow_item_flex *flow_spec = item->spec;
7538 : 0 : const struct rte_flow_item_flex *flow_mask = item->mask;
7539 : : struct mlx5_flex_item *flex;
7540 : :
7541 [ # # ]: 0 : if (!flow_spec)
7542 : 0 : return rte_flow_error_set(error, EINVAL,
7543 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
7544 : : "flex flow item spec cannot be NULL");
7545 [ # # ]: 0 : if (!flow_mask)
7546 : 0 : return rte_flow_error_set(error, EINVAL,
7547 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
7548 : : "flex flow item mask cannot be NULL");
7549 [ # # ]: 0 : if (item->last)
7550 : 0 : return rte_flow_error_set(error, ENOTSUP,
7551 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
7552 : : "flex flow item last not supported");
7553 [ # # ]: 0 : if (mlx5_flex_acquire_index(dev, flow_spec->handle, false) < 0)
7554 : 0 : return rte_flow_error_set(error, EINVAL,
7555 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
7556 : : "invalid flex flow item handle");
7557 : 0 : flex = (struct mlx5_flex_item *)flow_spec->handle;
7558 [ # # # # : 0 : switch (flex->tunnel_mode) {
# # ]
7559 : 0 : case FLEX_TUNNEL_MODE_SINGLE:
7560 [ # # ]: 0 : if (item_flags &
7561 : : (MLX5_FLOW_ITEM_OUTER_FLEX | MLX5_FLOW_ITEM_INNER_FLEX))
7562 : 0 : rte_flow_error_set(error, EINVAL,
7563 : : RTE_FLOW_ERROR_TYPE_ITEM,
7564 : : NULL, "multiple flex items not supported");
7565 : : break;
7566 : 0 : case FLEX_TUNNEL_MODE_OUTER:
7567 [ # # ]: 0 : if (is_inner)
7568 : 0 : rte_flow_error_set(error, EINVAL,
7569 : : RTE_FLOW_ERROR_TYPE_ITEM,
7570 : : NULL, "inner flex item was not configured");
7571 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_OUTER_FLEX)
7572 : 0 : rte_flow_error_set(error, ENOTSUP,
7573 : : RTE_FLOW_ERROR_TYPE_ITEM,
7574 : : NULL, "multiple flex items not supported");
7575 : : break;
7576 : 0 : case FLEX_TUNNEL_MODE_INNER:
7577 [ # # ]: 0 : if (!is_inner)
7578 : 0 : rte_flow_error_set(error, EINVAL,
7579 : : RTE_FLOW_ERROR_TYPE_ITEM,
7580 : : NULL, "outer flex item was not configured");
7581 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_INNER_FLEX)
7582 : 0 : rte_flow_error_set(error, EINVAL,
7583 : : RTE_FLOW_ERROR_TYPE_ITEM,
7584 : : NULL, "multiple flex items not supported");
7585 : : break;
7586 : 0 : case FLEX_TUNNEL_MODE_MULTI:
7587 [ # # # # : 0 : if ((is_inner && (item_flags & MLX5_FLOW_ITEM_INNER_FLEX)) ||
# # ]
7588 [ # # ]: 0 : (!is_inner && (item_flags & MLX5_FLOW_ITEM_OUTER_FLEX))) {
7589 : 0 : rte_flow_error_set(error, EINVAL,
7590 : : RTE_FLOW_ERROR_TYPE_ITEM,
7591 : : NULL, "multiple flex items not supported");
7592 : : }
7593 : : break;
7594 : 0 : case FLEX_TUNNEL_MODE_TUNNEL:
7595 [ # # # # ]: 0 : if (is_inner || (item_flags & MLX5_FLOW_ITEM_FLEX_TUNNEL))
7596 : 0 : rte_flow_error_set(error, EINVAL,
7597 : : RTE_FLOW_ERROR_TYPE_ITEM,
7598 : : NULL, "multiple flex tunnel items not supported");
7599 : : break;
7600 : 0 : default:
7601 : 0 : rte_flow_error_set(error, EINVAL,
7602 : : RTE_FLOW_ERROR_TYPE_ITEM,
7603 : : NULL, "invalid flex item configuration");
7604 : : }
7605 : 0 : *last_item = flex->tunnel_mode == FLEX_TUNNEL_MODE_TUNNEL ?
7606 [ # # ]: 0 : MLX5_FLOW_ITEM_FLEX_TUNNEL : is_inner ?
7607 [ # # ]: 0 : MLX5_FLOW_ITEM_INNER_FLEX : MLX5_FLOW_ITEM_OUTER_FLEX;
7608 : 0 : return 0;
7609 : : }
7610 : :
7611 : : static __rte_always_inline uint8_t
7612 : : mlx5_flow_l3_next_protocol(const struct rte_flow_item *l3_item,
7613 : : enum MLX5_SET_MATCHER key_type)
7614 : : {
7615 : : #define MLX5_L3_NEXT_PROTOCOL(i, ms) \
7616 : : ((i)->type == RTE_FLOW_ITEM_TYPE_IPV4 ? \
7617 : : ((const struct rte_flow_item_ipv4 *)(i)->ms)->hdr.next_proto_id : \
7618 : : (i)->type == RTE_FLOW_ITEM_TYPE_IPV6 ? \
7619 : : ((const struct rte_flow_item_ipv6 *)(i)->ms)->hdr.proto : \
7620 : : (i)->type == RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT ? \
7621 : : ((const struct rte_flow_item_ipv6_frag_ext *)(i)->ms)->hdr.next_header :\
7622 : : 0xff)
7623 : :
7624 : : uint8_t next_protocol;
7625 : :
7626 [ # # # # : 0 : if (l3_item->mask != NULL && l3_item->spec != NULL) {
# # # # #
# # # # #
# # # # #
# # # ]
7627 [ # # # # : 0 : next_protocol = MLX5_L3_NEXT_PROTOCOL(l3_item, mask);
# # # # #
# # # ]
7628 [ # # # # : 0 : if (next_protocol)
# # # # #
# # # ]
7629 [ # # # # : 0 : next_protocol &= MLX5_L3_NEXT_PROTOCOL(l3_item, spec);
# # # # #
# # # ]
7630 : : else
7631 : : next_protocol = 0xff;
7632 [ # # # # : 0 : } else if (key_type == MLX5_SET_MATCHER_HS_M && l3_item->mask != NULL) {
# # # # #
# # # ]
7633 [ # # # # : 0 : next_protocol = MLX5_L3_NEXT_PROTOCOL(l3_item, mask);
# # ]
7634 [ # # # # : 0 : } else if (key_type == MLX5_SET_MATCHER_HS_V && l3_item->spec != NULL) {
# # # # #
# # # ]
7635 [ # # # # : 0 : next_protocol = MLX5_L3_NEXT_PROTOCOL(l3_item, spec);
# # ]
7636 : : } else {
7637 : : /* Reset for inner layer. */
7638 : : next_protocol = 0xff;
7639 : : }
7640 : : return next_protocol;
7641 : :
7642 : : #undef MLX5_L3_NEXT_PROTOCOL
7643 : : }
7644 : :
7645 : : /**
7646 : : * Validate IB BTH item.
7647 : : *
7648 : : * @param[in] dev
7649 : : * Pointer to the rte_eth_dev structure.
7650 : : * @param[in] udp_dport
7651 : : * UDP destination port
7652 : : * @param[in] item
7653 : : * Item specification.
7654 : : * @param root
7655 : : * Whether action is on root table.
7656 : : * @param[out] error
7657 : : * Pointer to the error structure.
7658 : : *
7659 : : * @return
7660 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
7661 : : */
7662 : : static int
7663 : 0 : mlx5_flow_validate_item_ib_bth(struct rte_eth_dev *dev,
7664 : : uint16_t udp_dport,
7665 : : const struct rte_flow_item *item,
7666 : : bool root,
7667 : : struct rte_flow_error *error)
7668 : : {
7669 : 0 : const struct rte_flow_item_ib_bth *mask = item->mask;
7670 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7671 : : const struct rte_flow_item_ib_bth *valid_mask;
7672 : : int ret;
7673 : :
7674 : : valid_mask = &rte_flow_item_ib_bth_mask;
7675 [ # # ]: 0 : if (udp_dport && udp_dport != MLX5_UDP_PORT_ROCEv2)
7676 : 0 : return rte_flow_error_set(error, EINVAL,
7677 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
7678 : : "protocol filtering not compatible"
7679 : : " with UDP layer");
7680 [ # # # # ]: 0 : if (mask && (mask->hdr.se || mask->hdr.m || mask->hdr.padcnt ||
7681 [ # # # # ]: 0 : mask->hdr.tver || mask->hdr.pkey || mask->hdr.f || mask->hdr.b ||
7682 [ # # ]: 0 : mask->hdr.rsvd0 || mask->hdr.a || mask->hdr.rsvd1 ||
7683 [ # # # # : 0 : mask->hdr.psn[0] || mask->hdr.psn[1] || mask->hdr.psn[2]))
# # ]
7684 : 0 : return rte_flow_error_set(error, EINVAL,
7685 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
7686 : : "only opcode and dst_qp are supported");
7687 [ # # # # ]: 0 : if (root || priv->sh->steering_format_version ==
7688 : : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5)
7689 : 0 : return rte_flow_error_set(error, EINVAL,
7690 : : RTE_FLOW_ERROR_TYPE_ITEM,
7691 : : item,
7692 : : "IB BTH item is not supported");
7693 [ # # ]: 0 : if (!mask)
7694 : : mask = &rte_flow_item_ib_bth_mask;
7695 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
7696 : : (const uint8_t *)valid_mask,
7697 : : sizeof(struct rte_flow_item_ib_bth),
7698 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
7699 : : if (ret < 0)
7700 : : return ret;
7701 : : return 0;
7702 : : }
7703 : :
7704 : : const struct rte_flow_item_ipv4 nic_ipv4_mask = {
7705 : : .hdr = {
7706 : : .src_addr = RTE_BE32(0xffffffff),
7707 : : .dst_addr = RTE_BE32(0xffffffff),
7708 : : .type_of_service = 0xff,
7709 : : .fragment_offset = RTE_BE16(0xffff),
7710 : : .next_proto_id = 0xff,
7711 : : .time_to_live = 0xff,
7712 : : },
7713 : : };
7714 : :
7715 : : const struct rte_flow_item_ipv6 nic_ipv6_mask = {
7716 : : .hdr = {
7717 : : .src_addr = RTE_IPV6_MASK_FULL,
7718 : : .dst_addr = RTE_IPV6_MASK_FULL,
7719 : : .vtc_flow = RTE_BE32(0xffffffff),
7720 : : .proto = 0xff,
7721 : : .hop_limits = 0xff,
7722 : : },
7723 : : .has_frag_ext = 1,
7724 : : };
7725 : :
7726 : : const struct rte_flow_item_tcp nic_tcp_mask = {
7727 : : .hdr = {
7728 : : .tcp_flags = 0xFF,
7729 : : .src_port = RTE_BE16(UINT16_MAX),
7730 : : .dst_port = RTE_BE16(UINT16_MAX),
7731 : : }
7732 : : };
7733 : :
7734 : : /**
7735 : : * Internal validation function. For validating both actions and items.
7736 : : *
7737 : : * @param[in] dev
7738 : : * Pointer to the rte_eth_dev structure.
7739 : : * @param[in] attr
7740 : : * Pointer to the flow attributes.
7741 : : * @param[in] items
7742 : : * Pointer to the list of items.
7743 : : * @param[in] actions
7744 : : * Pointer to the list of actions.
7745 : : * @param[in] external
7746 : : * This flow rule is created by request external to PMD.
7747 : : * @param[in] hairpin
7748 : : * Number of hairpin TX actions, 0 means classic flow.
7749 : : * @param[out] error
7750 : : * Pointer to the error structure.
7751 : : *
7752 : : * @return
7753 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
7754 : : */
7755 : : int
7756 : 0 : flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
7757 : : const struct rte_flow_item items[],
7758 : : const struct rte_flow_action actions[],
7759 : : bool external, int hairpin, struct rte_flow_error *error)
7760 : : {
7761 : : int ret;
7762 : 0 : uint64_t aso_mask, action_flags = 0;
7763 : 0 : uint64_t item_flags = 0;
7764 : 0 : uint64_t last_item = 0;
7765 : : uint8_t next_protocol = 0xff;
7766 : : uint16_t ether_type = 0;
7767 : 0 : int actions_n = 0;
7768 : : uint8_t item_ipv6_proto = 0;
7769 : 0 : int fdb_mirror = 0;
7770 : : int modify_after_mirror = 0;
7771 : : const struct rte_flow_item *geneve_item = NULL;
7772 : : const struct rte_flow_item *gre_item = NULL;
7773 : : const struct rte_flow_item *gtp_item = NULL;
7774 : : const struct rte_flow_action_raw_decap *decap;
7775 : : const struct rte_flow_action_raw_encap *encap;
7776 : : const struct rte_flow_action_rss *rss = NULL;
7777 : 0 : const struct rte_flow_action_rss *sample_rss = NULL;
7778 : 0 : const struct rte_flow_action_count *sample_count = NULL;
7779 : 0 : const struct rte_flow_item_ecpri nic_ecpri_mask = {
7780 : : .hdr = {
7781 : : .common = {
7782 : : .u32 =
7783 : : RTE_BE32(((const struct rte_ecpri_common_hdr) {
7784 : : .type = 0xFF,
7785 : : }).u32),
7786 : : },
7787 : : .dummy[0] = 0xffffffff,
7788 : : },
7789 : : };
7790 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7791 : 0 : struct mlx5_sh_config *dev_conf = &priv->sh->config;
7792 : : uint16_t queue_index = 0xFFFF;
7793 : : const struct rte_flow_item_vlan *vlan_m = NULL;
7794 : : uint32_t rw_act_num = 0;
7795 : : uint64_t is_root;
7796 : : const struct mlx5_flow_tunnel *tunnel;
7797 : : enum mlx5_tof_rule_type tof_rule_type;
7798 : 0 : struct flow_grp_info grp_info = {
7799 : : .external = !!external,
7800 : 0 : .transfer = !!attr->transfer,
7801 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
7802 : : .std_tbl_fix = true,
7803 : : };
7804 : : const struct rte_eth_hairpin_conf *conf;
7805 : 0 : const struct rte_flow_item *integrity_items[2] = {NULL, NULL};
7806 : : const struct rte_flow_item *port_id_item = NULL;
7807 : 0 : bool def_policy = false;
7808 : : bool shared_count = false;
7809 : : uint16_t udp_dport = 0;
7810 : 0 : uint32_t tag_id = 0, tag_bitmap = 0;
7811 : : const struct rte_flow_action_age *non_shared_age = NULL;
7812 : : const struct rte_flow_action_count *count = NULL;
7813 : : const struct rte_flow_action_port_id *port = NULL;
7814 : : const struct mlx5_rte_flow_item_tag *mlx5_tag;
7815 : 0 : struct mlx5_priv *act_priv = NULL;
7816 : : int aso_after_sample = 0;
7817 : : struct mlx5_priv *port_priv = NULL;
7818 : 0 : uint64_t sub_action_flags = 0;
7819 : 0 : uint16_t sample_port_id = 0;
7820 : : uint16_t port_id = 0;
7821 : :
7822 [ # # ]: 0 : if (items == NULL)
7823 : : return -1;
7824 : : tunnel = is_tunnel_offload_active(dev) ?
7825 [ # # ]: 0 : mlx5_get_tof(items, actions, &tof_rule_type) : NULL;
7826 [ # # ]: 0 : if (tunnel) {
7827 [ # # ]: 0 : if (!dev_conf->dv_flow_en)
7828 : 0 : return rte_flow_error_set
7829 : : (error, ENOTSUP,
7830 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7831 : : NULL, "tunnel offload requires DV flow interface");
7832 [ # # ]: 0 : if (priv->representor)
7833 : 0 : return rte_flow_error_set
7834 : : (error, ENOTSUP,
7835 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7836 : : NULL, "decap not supported for VF representor");
7837 [ # # ]: 0 : if (tof_rule_type == MLX5_TUNNEL_OFFLOAD_SET_RULE)
7838 : 0 : action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
7839 [ # # ]: 0 : else if (tof_rule_type == MLX5_TUNNEL_OFFLOAD_MATCH_RULE)
7840 : 0 : action_flags |= MLX5_FLOW_ACTION_TUNNEL_MATCH |
7841 : : MLX5_FLOW_ACTION_DECAP;
7842 : 0 : grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
7843 : : (dev, attr, tunnel, tof_rule_type);
7844 : : }
7845 : 0 : ret = flow_dv_validate_attributes(dev, tunnel, attr, &grp_info, error);
7846 [ # # ]: 0 : if (ret < 0)
7847 : : return ret;
7848 : 0 : is_root = (uint64_t)ret;
7849 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
7850 : : enum mlx5_l3_tunnel_detection l3_tunnel_detection;
7851 : : uint64_t l3_tunnel_flag;
7852 : 0 : int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
7853 : 0 : int type = items->type;
7854 : :
7855 : : if (!mlx5_flow_os_item_supported(type))
7856 : : return rte_flow_error_set(error, ENOTSUP,
7857 : : RTE_FLOW_ERROR_TYPE_ITEM,
7858 : : NULL, "item not supported");
7859 [ # # # # : 0 : switch (type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # #
# ]
7860 : : case RTE_FLOW_ITEM_TYPE_VOID:
7861 : : break;
7862 : 0 : case RTE_FLOW_ITEM_TYPE_ESP:
7863 : 0 : ret = mlx5_flow_os_validate_item_esp(dev, items, item_flags,
7864 : : next_protocol, false, error);
7865 [ # # ]: 0 : if (ret < 0)
7866 : 0 : return ret;
7867 : 0 : last_item = MLX5_FLOW_ITEM_ESP;
7868 : 0 : break;
7869 : 0 : case RTE_FLOW_ITEM_TYPE_PORT_ID:
7870 : 0 : ret = flow_dv_validate_item_port_id
7871 : : (dev, items, attr, item_flags, &act_priv, error);
7872 [ # # ]: 0 : if (ret < 0)
7873 : 0 : return ret;
7874 : 0 : last_item = MLX5_FLOW_ITEM_PORT_ID;
7875 : : port_id_item = items;
7876 : 0 : break;
7877 : 0 : case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
7878 : : case RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR:
7879 : 0 : ret = flow_dv_validate_item_represented_port
7880 : : (dev, items, attr, item_flags, &act_priv, error);
7881 [ # # ]: 0 : if (ret < 0)
7882 : 0 : return ret;
7883 : 0 : last_item = MLX5_FLOW_ITEM_REPRESENTED_PORT;
7884 : : port_id_item = items;
7885 : 0 : break;
7886 : 0 : case RTE_FLOW_ITEM_TYPE_ETH:
7887 : 0 : ret = mlx5_flow_validate_item_eth(dev, items, item_flags,
7888 : : true, error);
7889 [ # # ]: 0 : if (ret < 0)
7890 : 0 : return ret;
7891 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
7892 : : MLX5_FLOW_LAYER_OUTER_L2;
7893 [ # # # # ]: 0 : if (items->mask != NULL && items->spec != NULL) {
7894 : 0 : ether_type =
7895 : : ((const struct rte_flow_item_eth *)
7896 : : items->spec)->hdr.ether_type;
7897 : 0 : ether_type &=
7898 : : ((const struct rte_flow_item_eth *)
7899 : 0 : items->mask)->hdr.ether_type;
7900 [ # # ]: 0 : ether_type = rte_be_to_cpu_16(ether_type);
7901 : : } else {
7902 : : ether_type = 0;
7903 : : }
7904 : : break;
7905 : 0 : case RTE_FLOW_ITEM_TYPE_VLAN:
7906 : 0 : ret = mlx5_flow_dv_validate_item_vlan(items, item_flags,
7907 : : dev, error);
7908 [ # # ]: 0 : if (ret < 0)
7909 : 0 : return ret;
7910 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
7911 : : MLX5_FLOW_LAYER_OUTER_VLAN;
7912 [ # # # # ]: 0 : if (items->mask != NULL && items->spec != NULL) {
7913 : 0 : ether_type =
7914 : : ((const struct rte_flow_item_vlan *)
7915 : : items->spec)->hdr.eth_proto;
7916 : 0 : ether_type &=
7917 : : ((const struct rte_flow_item_vlan *)
7918 : 0 : items->mask)->hdr.eth_proto;
7919 [ # # ]: 0 : ether_type = rte_be_to_cpu_16(ether_type);
7920 : : } else {
7921 : : ether_type = 0;
7922 : : }
7923 : : /* Store outer VLAN mask for of_push_vlan action. */
7924 [ # # ]: 0 : if (!tunnel)
7925 : : vlan_m = items->mask;
7926 : : break;
7927 : : case RTE_FLOW_ITEM_TYPE_IPV4:
7928 : : next_protocol = mlx5_flow_l3_next_protocol
7929 : : (items, (enum MLX5_SET_MATCHER)-1);
7930 : : l3_tunnel_detection =
7931 : : mlx5_flow_tunnel_ip_check(items, next_protocol,
7932 : : item_flags,
7933 : : &l3_tunnel_flag);
7934 : : /*
7935 : : * explicitly allow inner IPIP match
7936 : : */
7937 : : if (l3_tunnel_detection == l3_tunnel_outer) {
7938 : 0 : item_flags |= l3_tunnel_flag;
7939 : : tunnel = 1;
7940 : : }
7941 : 0 : ret = mlx5_flow_dv_validate_item_ipv4(dev, items,
7942 : : item_flags,
7943 : : last_item,
7944 : : ether_type,
7945 : : &nic_ipv4_mask,
7946 : : error);
7947 [ # # ]: 0 : if (ret < 0)
7948 : 0 : return ret;
7949 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
7950 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4;
7951 [ # # ]: 0 : if (l3_tunnel_detection == l3_tunnel_outer)
7952 : 0 : item_flags |= l3_tunnel_flag;
7953 : : break;
7954 : : case RTE_FLOW_ITEM_TYPE_IPV6:
7955 : : next_protocol = mlx5_flow_l3_next_protocol
7956 : : (items, (enum MLX5_SET_MATCHER)-1);
7957 : : l3_tunnel_detection =
7958 : : mlx5_flow_tunnel_ip_check(items, next_protocol,
7959 : : item_flags,
7960 : : &l3_tunnel_flag);
7961 : : /*
7962 : : * explicitly allow inner IPIP match
7963 : : */
7964 : : if (l3_tunnel_detection == l3_tunnel_outer) {
7965 : 0 : item_flags |= l3_tunnel_flag;
7966 : : tunnel = 1;
7967 : : }
7968 : 0 : ret = mlx5_flow_validate_item_ipv6(dev, items,
7969 : : item_flags,
7970 : : last_item,
7971 : : ether_type,
7972 : : &nic_ipv6_mask,
7973 : : error);
7974 [ # # ]: 0 : if (ret < 0)
7975 : 0 : return ret;
7976 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
7977 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6;
7978 [ # # ]: 0 : if (l3_tunnel_detection == l3_tunnel_outer)
7979 : 0 : item_flags |= l3_tunnel_flag;
7980 : : break;
7981 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
7982 : 0 : ret = flow_dv_validate_item_ipv6_frag_ext(dev, items,
7983 : : item_flags,
7984 : : error);
7985 [ # # ]: 0 : if (ret < 0)
7986 : 0 : return ret;
7987 [ # # ]: 0 : last_item = tunnel ?
7988 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
7989 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
7990 : : next_protocol = mlx5_flow_l3_next_protocol
7991 : : (items, (enum MLX5_SET_MATCHER)-1);
7992 : : break;
7993 : 0 : case RTE_FLOW_ITEM_TYPE_TCP:
7994 : 0 : ret = mlx5_flow_validate_item_tcp
7995 : : (dev, items, item_flags,
7996 : : next_protocol,
7997 : : &nic_tcp_mask,
7998 : : error);
7999 [ # # ]: 0 : if (ret < 0)
8000 : 0 : return ret;
8001 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
8002 : : MLX5_FLOW_LAYER_OUTER_L4_TCP;
8003 : 0 : break;
8004 : 0 : case RTE_FLOW_ITEM_TYPE_UDP:
8005 : 0 : ret = mlx5_flow_validate_item_udp(dev, items, item_flags,
8006 : : next_protocol,
8007 : : error);
8008 : 0 : const struct rte_flow_item_udp *spec = items->spec;
8009 : 0 : const struct rte_flow_item_udp *mask = items->mask;
8010 [ # # ]: 0 : if (!mask)
8011 : : mask = &rte_flow_item_udp_mask;
8012 [ # # ]: 0 : if (spec != NULL)
8013 [ # # ]: 0 : udp_dport = rte_be_to_cpu_16
8014 : : (spec->hdr.dst_port &
8015 : : mask->hdr.dst_port);
8016 [ # # ]: 0 : if (ret < 0)
8017 : 0 : return ret;
8018 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
8019 : : MLX5_FLOW_LAYER_OUTER_L4_UDP;
8020 : 0 : break;
8021 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
8022 : 0 : ret = mlx5_flow_validate_item_gre(dev, items, item_flags,
8023 : : next_protocol, error);
8024 [ # # ]: 0 : if (ret < 0)
8025 : 0 : return ret;
8026 : : gre_item = items;
8027 : 0 : last_item = MLX5_FLOW_LAYER_GRE;
8028 : 0 : break;
8029 : 0 : case RTE_FLOW_ITEM_TYPE_GRE_OPTION:
8030 : 0 : ret = mlx5_flow_validate_item_gre_option(dev, items, item_flags,
8031 : : attr, gre_item, error);
8032 [ # # ]: 0 : if (ret < 0)
8033 : 0 : return ret;
8034 : 0 : last_item = MLX5_FLOW_LAYER_GRE;
8035 : 0 : break;
8036 : 0 : case RTE_FLOW_ITEM_TYPE_NVGRE:
8037 : 0 : ret = mlx5_flow_validate_item_nvgre(dev, items,
8038 : : item_flags,
8039 : : next_protocol,
8040 : : error);
8041 [ # # ]: 0 : if (ret < 0)
8042 : 0 : return ret;
8043 : 0 : last_item = MLX5_FLOW_LAYER_NVGRE;
8044 : 0 : break;
8045 : 0 : case RTE_FLOW_ITEM_TYPE_GRE_KEY:
8046 : 0 : ret = mlx5_flow_validate_item_gre_key
8047 : : (dev, items, item_flags, gre_item, error);
8048 [ # # ]: 0 : if (ret < 0)
8049 : 0 : return ret;
8050 : 0 : last_item = MLX5_FLOW_LAYER_GRE_KEY;
8051 : 0 : break;
8052 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN:
8053 : 0 : ret = mlx5_flow_validate_item_vxlan(dev, udp_dport,
8054 : : items, item_flags,
8055 : : is_root, error);
8056 [ # # ]: 0 : if (ret < 0)
8057 : 0 : return ret;
8058 : 0 : last_item = MLX5_FLOW_LAYER_VXLAN;
8059 : 0 : break;
8060 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
8061 : 0 : ret = mlx5_flow_validate_item_vxlan_gpe(items,
8062 : : item_flags, dev,
8063 : : error);
8064 [ # # ]: 0 : if (ret < 0)
8065 : 0 : return ret;
8066 : 0 : last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
8067 : 0 : break;
8068 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE:
8069 : 0 : ret = mlx5_flow_validate_item_geneve(items,
8070 : : item_flags, dev,
8071 : : error);
8072 [ # # ]: 0 : if (ret < 0)
8073 : 0 : return ret;
8074 : : geneve_item = items;
8075 : 0 : last_item = MLX5_FLOW_LAYER_GENEVE;
8076 : 0 : break;
8077 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
8078 : 0 : ret = mlx5_flow_validate_item_geneve_opt(items,
8079 : : last_item,
8080 : : geneve_item,
8081 : : dev,
8082 : : error);
8083 [ # # ]: 0 : if (ret < 0)
8084 : 0 : return ret;
8085 : 0 : last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
8086 : 0 : break;
8087 : 0 : case RTE_FLOW_ITEM_TYPE_MPLS:
8088 : 0 : ret = mlx5_flow_validate_item_mpls(dev, items,
8089 : : item_flags,
8090 : : last_item, error);
8091 [ # # ]: 0 : if (ret < 0)
8092 : 0 : return ret;
8093 : 0 : last_item = MLX5_FLOW_LAYER_MPLS;
8094 : 0 : break;
8095 : :
8096 : 0 : case RTE_FLOW_ITEM_TYPE_MARK:
8097 : 0 : ret = flow_dv_validate_item_mark(dev, items, attr,
8098 : : error);
8099 [ # # ]: 0 : if (ret < 0)
8100 : 0 : return ret;
8101 : 0 : last_item = MLX5_FLOW_ITEM_MARK;
8102 : 0 : break;
8103 : 0 : case RTE_FLOW_ITEM_TYPE_META:
8104 : 0 : ret = flow_dv_validate_item_meta(dev, items, attr,
8105 : : error);
8106 [ # # ]: 0 : if (ret < 0)
8107 : 0 : return ret;
8108 : 0 : last_item = MLX5_FLOW_ITEM_METADATA;
8109 : 0 : break;
8110 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP:
8111 : 0 : ret = mlx5_flow_validate_item_icmp(dev, items, item_flags,
8112 : : next_protocol,
8113 : : error);
8114 [ # # ]: 0 : if (ret < 0)
8115 : 0 : return ret;
8116 : 0 : last_item = MLX5_FLOW_LAYER_ICMP;
8117 : 0 : break;
8118 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6:
8119 : 0 : ret = mlx5_flow_validate_item_icmp6(dev, items, item_flags,
8120 : : next_protocol,
8121 : : error);
8122 [ # # ]: 0 : if (ret < 0)
8123 : 0 : return ret;
8124 : : item_ipv6_proto = IPPROTO_ICMPV6;
8125 : 0 : last_item = MLX5_FLOW_LAYER_ICMP6;
8126 : 0 : break;
8127 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REQUEST:
8128 : : case RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REPLY:
8129 : 0 : ret = mlx5_flow_validate_item_icmp6_echo(dev, items,
8130 : : item_flags,
8131 : : next_protocol,
8132 : : error);
8133 [ # # ]: 0 : if (ret < 0)
8134 : 0 : return ret;
8135 : : item_ipv6_proto = IPPROTO_ICMPV6;
8136 : 0 : last_item = MLX5_FLOW_LAYER_ICMP6;
8137 : 0 : break;
8138 : 0 : case RTE_FLOW_ITEM_TYPE_TAG:
8139 : 0 : ret = flow_dv_validate_item_tag(dev, items, &tag_bitmap,
8140 : : attr, error);
8141 [ # # ]: 0 : if (ret < 0)
8142 : 0 : return ret;
8143 : 0 : last_item = MLX5_FLOW_ITEM_TAG;
8144 : 0 : break;
8145 : 0 : case RTE_FLOW_ITEM_TYPE_TX_QUEUE:
8146 : : case MLX5_RTE_FLOW_ITEM_TYPE_SQ:
8147 : 0 : last_item = MLX5_FLOW_ITEM_SQ;
8148 : 0 : break;
8149 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
8150 : 0 : mlx5_tag = (const struct mlx5_rte_flow_item_tag *)items->spec;
8151 [ # # ]: 0 : if (tag_bitmap & (1 << mlx5_tag->id))
8152 : 0 : return rte_flow_error_set(error, EINVAL,
8153 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
8154 : : items->spec,
8155 : : "Duplicated tag index");
8156 : 0 : tag_bitmap |= 1 << mlx5_tag->id;
8157 : 0 : break;
8158 : 0 : case RTE_FLOW_ITEM_TYPE_GTP:
8159 : 0 : ret = mlx5_flow_dv_validate_item_gtp(dev, items,
8160 : : item_flags,
8161 : : error);
8162 [ # # ]: 0 : if (ret < 0)
8163 : 0 : return ret;
8164 : : gtp_item = items;
8165 : 0 : last_item = MLX5_FLOW_LAYER_GTP;
8166 : 0 : break;
8167 : 0 : case RTE_FLOW_ITEM_TYPE_GTP_PSC:
8168 : 0 : ret = mlx5_flow_dv_validate_item_gtp_psc(dev, items,
8169 : : last_item,
8170 : : gtp_item,
8171 : : is_root, error);
8172 [ # # ]: 0 : if (ret < 0)
8173 : 0 : return ret;
8174 : 0 : last_item = MLX5_FLOW_LAYER_GTP_PSC;
8175 : 0 : break;
8176 : 0 : case RTE_FLOW_ITEM_TYPE_ECPRI:
8177 : : /* Capacity will be checked in the translate stage. */
8178 : 0 : ret = mlx5_flow_validate_item_ecpri(dev, items,
8179 : : item_flags,
8180 : : last_item,
8181 : : ether_type,
8182 : : &nic_ecpri_mask,
8183 : : error);
8184 [ # # ]: 0 : if (ret < 0)
8185 : 0 : return ret;
8186 : 0 : last_item = MLX5_FLOW_LAYER_ECPRI;
8187 : 0 : break;
8188 : 0 : case RTE_FLOW_ITEM_TYPE_INTEGRITY:
8189 : 0 : ret = flow_dv_validate_item_integrity(dev, items,
8190 : : item_flags,
8191 : : &last_item,
8192 : : integrity_items,
8193 : : error);
8194 [ # # ]: 0 : if (ret < 0)
8195 : 0 : return ret;
8196 : : break;
8197 : 0 : case RTE_FLOW_ITEM_TYPE_CONNTRACK:
8198 : 0 : ret = mlx5_flow_dv_validate_item_aso_ct(dev, items,
8199 : : &item_flags,
8200 : : error);
8201 [ # # ]: 0 : if (ret < 0)
8202 : 0 : return ret;
8203 : 0 : last_item = MLX5_FLOW_LAYER_ASO_CT;
8204 : 0 : break;
8205 : : case MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL:
8206 : : /* tunnel offload item was processed before
8207 : : * list it here as a supported type
8208 : : */
8209 : : break;
8210 : 0 : case RTE_FLOW_ITEM_TYPE_FLEX:
8211 : 0 : ret = flow_dv_validate_item_flex(dev, items, item_flags,
8212 : : &last_item,
8213 : : tunnel != 0, error);
8214 [ # # ]: 0 : if (ret < 0)
8215 : 0 : return ret;
8216 : : /* Reset for next proto, it is unknown. */
8217 : : next_protocol = 0xff;
8218 : : break;
8219 : 0 : case RTE_FLOW_ITEM_TYPE_METER_COLOR:
8220 : 0 : ret = flow_dv_validate_item_meter_color(dev, items,
8221 : : attr, error);
8222 [ # # ]: 0 : if (ret < 0)
8223 : 0 : return ret;
8224 : 0 : last_item = MLX5_FLOW_ITEM_METER_COLOR;
8225 : 0 : break;
8226 : 0 : case RTE_FLOW_ITEM_TYPE_AGGR_AFFINITY:
8227 : 0 : ret = flow_dv_validate_item_aggr_affinity(dev, items,
8228 : : attr, error);
8229 [ # # ]: 0 : if (ret < 0)
8230 : 0 : return ret;
8231 : 0 : last_item = MLX5_FLOW_ITEM_AGGR_AFFINITY;
8232 : 0 : break;
8233 : 0 : case RTE_FLOW_ITEM_TYPE_IB_BTH:
8234 : 0 : ret = mlx5_flow_validate_item_ib_bth(dev, udp_dport,
8235 : : items, is_root, error);
8236 [ # # ]: 0 : if (ret < 0)
8237 : 0 : return ret;
8238 : :
8239 : 0 : last_item = MLX5_FLOW_ITEM_IB_BTH;
8240 : 0 : break;
8241 : 0 : case RTE_FLOW_ITEM_TYPE_NSH:
8242 : 0 : ret = mlx5_flow_validate_item_nsh(dev, items, error);
8243 [ # # ]: 0 : if (ret < 0)
8244 : 0 : return ret;
8245 : 0 : last_item = MLX5_FLOW_ITEM_NSH;
8246 : 0 : break;
8247 : 0 : default:
8248 : 0 : return rte_flow_error_set(error, ENOTSUP,
8249 : : RTE_FLOW_ERROR_TYPE_ITEM,
8250 : : NULL, "item not supported");
8251 : : }
8252 : 0 : item_flags |= last_item;
8253 : : }
8254 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_INTEGRITY) {
8255 : 0 : ret = flow_dv_validate_item_integrity_post(integrity_items,
8256 : : item_flags, error);
8257 [ # # ]: 0 : if (ret)
8258 : : return ret;
8259 : : }
8260 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
8261 : 0 : int type = actions->type;
8262 : :
8263 : : if (!mlx5_flow_os_action_supported(type))
8264 : : return rte_flow_error_set(error, ENOTSUP,
8265 : : RTE_FLOW_ERROR_TYPE_ACTION,
8266 : : actions,
8267 : : "action not supported");
8268 [ # # ]: 0 : if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
8269 : 0 : return rte_flow_error_set(error, ENOTSUP,
8270 : : RTE_FLOW_ERROR_TYPE_ACTION,
8271 : : actions, "too many actions");
8272 [ # # ]: 0 : if (action_flags &
8273 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
8274 : 0 : return rte_flow_error_set(error, ENOTSUP,
8275 : : RTE_FLOW_ERROR_TYPE_ACTION,
8276 : : NULL, "meter action with policy "
8277 : : "must be the last action");
8278 [ # # # # : 0 : switch (type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
8279 : : case RTE_FLOW_ACTION_TYPE_VOID:
8280 : : break;
8281 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
8282 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
8283 : 0 : ret = flow_dv_validate_action_port_id(dev,
8284 : : action_flags,
8285 : : actions,
8286 : : attr,
8287 : : error);
8288 [ # # ]: 0 : if (ret)
8289 : 0 : return ret;
8290 [ # # ]: 0 : if (type == RTE_FLOW_ACTION_TYPE_PORT_ID) {
8291 : 0 : port = (const struct rte_flow_action_port_id *)
8292 : : actions->conf;
8293 [ # # ]: 0 : port_id = port->original ? dev->data->port_id : port->id;
8294 : : } else {
8295 : 0 : port_id = ((const struct rte_flow_action_ethdev *)
8296 : 0 : actions->conf)->port_id;
8297 : : }
8298 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_ID;
8299 : 0 : ++actions_n;
8300 : 0 : break;
8301 : 0 : case RTE_FLOW_ACTION_TYPE_FLAG:
8302 : 0 : ret = flow_dv_validate_action_flag(dev, action_flags,
8303 : : attr, error);
8304 [ # # ]: 0 : if (ret < 0)
8305 : 0 : return ret;
8306 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
8307 : : /* Count all modify-header actions as one. */
8308 [ # # ]: 0 : if (!(action_flags &
8309 : : MLX5_FLOW_MODIFY_HDR_ACTIONS))
8310 : 0 : ++actions_n;
8311 : 0 : action_flags |= MLX5_FLOW_ACTION_FLAG |
8312 : : MLX5_FLOW_ACTION_MARK_EXT;
8313 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8314 : : modify_after_mirror = 1;
8315 : :
8316 : : } else {
8317 : 0 : action_flags |= MLX5_FLOW_ACTION_FLAG;
8318 : 0 : ++actions_n;
8319 : : }
8320 : 0 : rw_act_num += MLX5_ACT_NUM_SET_MARK;
8321 : 0 : break;
8322 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
8323 : 0 : ret = flow_dv_validate_action_mark(dev, actions,
8324 : : action_flags,
8325 : : attr, error);
8326 [ # # ]: 0 : if (ret < 0)
8327 : 0 : return ret;
8328 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
8329 : : /* Count all modify-header actions as one. */
8330 [ # # ]: 0 : if (!(action_flags &
8331 : : MLX5_FLOW_MODIFY_HDR_ACTIONS))
8332 : 0 : ++actions_n;
8333 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK |
8334 : : MLX5_FLOW_ACTION_MARK_EXT;
8335 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8336 : : modify_after_mirror = 1;
8337 : : } else {
8338 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK;
8339 : 0 : ++actions_n;
8340 : : }
8341 : 0 : rw_act_num += MLX5_ACT_NUM_SET_MARK;
8342 : 0 : break;
8343 : 0 : case RTE_FLOW_ACTION_TYPE_SET_META:
8344 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
8345 : 0 : return rte_flow_error_set(error, ENOTSUP,
8346 : : RTE_FLOW_ERROR_TYPE_ACTION,
8347 : : actions,
8348 : : "action not supported");
8349 : 0 : ret = flow_dv_validate_action_set_meta(dev, actions,
8350 : : action_flags,
8351 : : attr, error);
8352 [ # # ]: 0 : if (ret < 0)
8353 : 0 : return ret;
8354 : : /* Count all modify-header actions as one action. */
8355 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8356 : 0 : ++actions_n;
8357 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8358 : : modify_after_mirror = 1;
8359 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_META;
8360 : 0 : rw_act_num += MLX5_ACT_NUM_SET_META;
8361 : 0 : break;
8362 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TAG:
8363 : 0 : ret = flow_dv_validate_action_set_tag(dev, actions,
8364 : : action_flags,
8365 : : attr, error);
8366 [ # # ]: 0 : if (ret < 0)
8367 : 0 : return ret;
8368 : : /* Count all modify-header actions as one action. */
8369 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8370 : 0 : ++actions_n;
8371 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8372 : : modify_after_mirror = 1;
8373 : 0 : tag_id = ((const struct rte_flow_action_set_tag *)
8374 : 0 : actions->conf)->index;
8375 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
8376 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
8377 : 0 : break;
8378 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
8379 : 0 : ret = mlx5_flow_validate_action_drop(dev, is_root,
8380 : : attr, error);
8381 [ # # ]: 0 : if (ret < 0)
8382 : 0 : return ret;
8383 : 0 : action_flags |= MLX5_FLOW_ACTION_DROP;
8384 : 0 : ++actions_n;
8385 : 0 : break;
8386 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
8387 : 0 : ret = mlx5_flow_validate_action_queue(actions,
8388 : : action_flags, dev,
8389 : : attr, error);
8390 [ # # ]: 0 : if (ret < 0)
8391 : 0 : return ret;
8392 : 0 : queue_index = ((const struct rte_flow_action_queue *)
8393 : 0 : (actions->conf))->index;
8394 : 0 : action_flags |= MLX5_FLOW_ACTION_QUEUE;
8395 : 0 : ++actions_n;
8396 : 0 : break;
8397 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
8398 : 0 : rss = actions->conf;
8399 : 0 : ret = mlx5_flow_validate_action_rss(actions,
8400 : : action_flags, dev,
8401 : : attr, item_flags,
8402 : : error);
8403 [ # # ]: 0 : if (ret < 0)
8404 : 0 : return ret;
8405 [ # # ]: 0 : if (rss && sample_rss &&
8406 [ # # ]: 0 : (sample_rss->level != rss->level ||
8407 [ # # ]: 0 : sample_rss->types != rss->types))
8408 : 0 : return rte_flow_error_set(error, ENOTSUP,
8409 : : RTE_FLOW_ERROR_TYPE_ACTION,
8410 : : NULL,
8411 : : "Can't use the different RSS types "
8412 : : "or level in the same flow");
8413 [ # # # # ]: 0 : if (rss != NULL && rss->queue_num)
8414 : 0 : queue_index = rss->queue[0];
8415 : 0 : action_flags |= MLX5_FLOW_ACTION_RSS;
8416 : 0 : ++actions_n;
8417 : 0 : break;
8418 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
8419 : : ret =
8420 : 0 : mlx5_flow_validate_action_default_miss(action_flags,
8421 : : attr, error);
8422 [ # # ]: 0 : if (ret < 0)
8423 : 0 : return ret;
8424 : 0 : action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
8425 : 0 : ++actions_n;
8426 : 0 : break;
8427 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
8428 : : shared_count = true;
8429 : : /* fall-through. */
8430 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
8431 : 0 : ret = flow_dv_validate_action_count(dev, shared_count,
8432 : : action_flags,
8433 : : is_root, error);
8434 [ # # ]: 0 : if (ret < 0)
8435 : 0 : return ret;
8436 : 0 : count = actions->conf;
8437 : 0 : action_flags |= MLX5_FLOW_ACTION_COUNT;
8438 : 0 : ++actions_n;
8439 : 0 : break;
8440 : 0 : case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
8441 [ # # ]: 0 : if (flow_dv_validate_action_pop_vlan(dev,
8442 : : action_flags,
8443 : : actions,
8444 : : item_flags, attr,
8445 : : error))
8446 : 0 : return -rte_errno;
8447 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8448 : : modify_after_mirror = 1;
8449 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
8450 : 0 : ++actions_n;
8451 : 0 : break;
8452 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
8453 : 0 : ret = flow_dv_validate_action_push_vlan(dev,
8454 : : action_flags,
8455 : : vlan_m,
8456 : : actions, attr,
8457 : : error);
8458 [ # # ]: 0 : if (ret < 0)
8459 : 0 : return ret;
8460 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8461 : : modify_after_mirror = 1;
8462 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
8463 : 0 : ++actions_n;
8464 : 0 : break;
8465 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
8466 : 0 : ret = flow_dv_validate_action_set_vlan_pcp
8467 : : (action_flags, actions, error);
8468 [ # # ]: 0 : if (ret < 0)
8469 : 0 : return ret;
8470 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8471 : : modify_after_mirror = 1;
8472 : : /* Count PCP with push_vlan command. */
8473 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_PCP;
8474 : 0 : break;
8475 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
8476 : 0 : ret = flow_dv_validate_action_set_vlan_vid
8477 : : (item_flags, action_flags,
8478 : : actions, error);
8479 [ # # ]: 0 : if (ret < 0)
8480 : 0 : return ret;
8481 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8482 : : modify_after_mirror = 1;
8483 : : /* Count VID with push_vlan command. */
8484 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
8485 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_VID;
8486 : 0 : break;
8487 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
8488 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
8489 : 0 : ret = mlx5_flow_dv_validate_action_l2_encap(dev,
8490 : : action_flags,
8491 : : actions,
8492 : : attr,
8493 : : error);
8494 [ # # ]: 0 : if (ret < 0)
8495 : 0 : return ret;
8496 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
8497 : 0 : ++actions_n;
8498 : 0 : break;
8499 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
8500 : : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
8501 : 0 : ret = mlx5_flow_dv_validate_action_decap(dev,
8502 : : action_flags,
8503 : : actions,
8504 : : item_flags,
8505 : : attr, error);
8506 [ # # ]: 0 : if (ret < 0)
8507 : 0 : return ret;
8508 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8509 : : modify_after_mirror = 1;
8510 : 0 : action_flags |= MLX5_FLOW_ACTION_DECAP;
8511 : 0 : ++actions_n;
8512 : 0 : break;
8513 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
8514 : 0 : ret = mlx5_flow_dv_validate_action_raw_encap_decap
8515 : 0 : (dev, NULL, actions->conf, attr, &action_flags,
8516 : : &actions_n, actions, item_flags, error);
8517 [ # # ]: 0 : if (ret < 0)
8518 : 0 : return ret;
8519 : : break;
8520 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
8521 : 0 : decap = actions->conf;
8522 [ # # ]: 0 : while ((++actions)->type == RTE_FLOW_ACTION_TYPE_VOID)
8523 : : ;
8524 [ # # ]: 0 : if (actions->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
8525 : : encap = NULL;
8526 : : actions--;
8527 : : } else {
8528 : 0 : encap = actions->conf;
8529 : : }
8530 [ # # ]: 0 : ret = mlx5_flow_dv_validate_action_raw_encap_decap
8531 : : (dev,
8532 : : decap ? decap : &empty_decap, encap,
8533 : : attr, &action_flags, &actions_n,
8534 : : actions, item_flags, error);
8535 [ # # ]: 0 : if (ret < 0)
8536 : 0 : return ret;
8537 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_SAMPLE) &&
8538 : : (action_flags & MLX5_FLOW_ACTION_DECAP))
8539 : : modify_after_mirror = 1;
8540 : : break;
8541 : 0 : case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
8542 : : case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
8543 : 0 : ret = flow_dv_validate_action_modify_mac(action_flags,
8544 : : actions,
8545 : : item_flags,
8546 : : error);
8547 [ # # ]: 0 : if (ret < 0)
8548 : 0 : return ret;
8549 : : /* Count all modify-header actions as one action. */
8550 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8551 : 0 : ++actions_n;
8552 : 0 : action_flags |= actions->type ==
8553 : : RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
8554 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_MAC_SRC :
8555 : : MLX5_FLOW_ACTION_SET_MAC_DST;
8556 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8557 : : modify_after_mirror = 1;
8558 : : /*
8559 : : * Even if the source and destination MAC addresses have
8560 : : * overlap in the header with 4B alignment, the convert
8561 : : * function will handle them separately and 4 SW actions
8562 : : * will be created. And 2 actions will be added each
8563 : : * time no matter how many bytes of address will be set.
8564 : : */
8565 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_MAC;
8566 : 0 : break;
8567 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
8568 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
8569 : 0 : ret = flow_dv_validate_action_modify_ipv4(action_flags,
8570 : : actions,
8571 : : item_flags,
8572 : : error);
8573 [ # # ]: 0 : if (ret < 0)
8574 : 0 : return ret;
8575 : : /* Count all modify-header actions as one action. */
8576 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8577 : 0 : ++actions_n;
8578 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8579 : : modify_after_mirror = 1;
8580 : 0 : action_flags |= actions->type ==
8581 : : RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
8582 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_IPV4_SRC :
8583 : : MLX5_FLOW_ACTION_SET_IPV4_DST;
8584 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_IPV4;
8585 : 0 : break;
8586 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
8587 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
8588 : 0 : ret = flow_dv_validate_action_modify_ipv6(action_flags,
8589 : : actions,
8590 : : item_flags,
8591 : : error);
8592 [ # # ]: 0 : if (ret < 0)
8593 : 0 : return ret;
8594 [ # # ]: 0 : if (item_ipv6_proto == IPPROTO_ICMPV6)
8595 : 0 : return rte_flow_error_set(error, ENOTSUP,
8596 : : RTE_FLOW_ERROR_TYPE_ACTION,
8597 : : actions,
8598 : : "Can't change header "
8599 : : "with ICMPv6 proto");
8600 : : /* Count all modify-header actions as one action. */
8601 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8602 : 0 : ++actions_n;
8603 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8604 : : modify_after_mirror = 1;
8605 : 0 : action_flags |= actions->type ==
8606 : : RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
8607 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_IPV6_SRC :
8608 : : MLX5_FLOW_ACTION_SET_IPV6_DST;
8609 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_IPV6;
8610 : 0 : break;
8611 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
8612 : : case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
8613 : 0 : ret = flow_dv_validate_action_modify_tp(action_flags,
8614 : : actions,
8615 : : item_flags,
8616 : : error);
8617 [ # # ]: 0 : if (ret < 0)
8618 : 0 : return ret;
8619 : : /* Count all modify-header actions as one action. */
8620 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8621 : 0 : ++actions_n;
8622 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8623 : : modify_after_mirror = 1;
8624 : 0 : action_flags |= actions->type ==
8625 : : RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
8626 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_TP_SRC :
8627 : : MLX5_FLOW_ACTION_SET_TP_DST;
8628 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_PORT;
8629 : 0 : break;
8630 : 0 : case RTE_FLOW_ACTION_TYPE_DEC_TTL:
8631 : : case RTE_FLOW_ACTION_TYPE_SET_TTL:
8632 : 0 : ret = flow_dv_validate_action_modify_ttl(action_flags,
8633 : : actions,
8634 : : item_flags,
8635 : : error);
8636 [ # # ]: 0 : if (ret < 0)
8637 : 0 : return ret;
8638 : : /* Count all modify-header actions as one action. */
8639 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8640 : 0 : ++actions_n;
8641 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8642 : : modify_after_mirror = 1;
8643 : 0 : action_flags |= actions->type ==
8644 : : RTE_FLOW_ACTION_TYPE_SET_TTL ?
8645 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_TTL :
8646 : : MLX5_FLOW_ACTION_DEC_TTL;
8647 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_TTL;
8648 : 0 : break;
8649 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
8650 : 0 : ret = flow_dv_validate_action_jump(dev, tunnel, actions,
8651 : : action_flags,
8652 : : attr, external,
8653 : : error);
8654 [ # # ]: 0 : if (ret)
8655 : 0 : return ret;
8656 : 0 : ++actions_n;
8657 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP;
8658 : 0 : break;
8659 : 0 : case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
8660 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
8661 : 0 : ret = flow_dv_validate_action_modify_tcp_seq
8662 : : (action_flags,
8663 : : actions,
8664 : : item_flags,
8665 : : error);
8666 [ # # ]: 0 : if (ret < 0)
8667 : 0 : return ret;
8668 : : /* Count all modify-header actions as one action. */
8669 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8670 : 0 : ++actions_n;
8671 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8672 : : modify_after_mirror = 1;
8673 : 0 : action_flags |= actions->type ==
8674 : : RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
8675 [ # # ]: 0 : MLX5_FLOW_ACTION_INC_TCP_SEQ :
8676 : : MLX5_FLOW_ACTION_DEC_TCP_SEQ;
8677 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_TCPSEQ;
8678 : 0 : break;
8679 : 0 : case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
8680 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
8681 : 0 : ret = flow_dv_validate_action_modify_tcp_ack
8682 : : (action_flags,
8683 : : actions,
8684 : : item_flags,
8685 : : error);
8686 [ # # ]: 0 : if (ret < 0)
8687 : 0 : return ret;
8688 : : /* Count all modify-header actions as one action. */
8689 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8690 : 0 : ++actions_n;
8691 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8692 : : modify_after_mirror = 1;
8693 : 0 : action_flags |= actions->type ==
8694 : : RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
8695 [ # # ]: 0 : MLX5_FLOW_ACTION_INC_TCP_ACK :
8696 : : MLX5_FLOW_ACTION_DEC_TCP_ACK;
8697 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_TCPACK;
8698 : 0 : break;
8699 : : case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
8700 : : break;
8701 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
8702 : : case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
8703 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
8704 : 0 : break;
8705 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
8706 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
8707 : 0 : return rte_flow_error_set(error, ENOTSUP,
8708 : : RTE_FLOW_ERROR_TYPE_ACTION,
8709 : : actions,
8710 : : "action not supported");
8711 : 0 : ret = mlx5_flow_validate_action_meter(dev,
8712 : : action_flags,
8713 : : item_flags,
8714 : : actions, attr,
8715 : : port_id_item,
8716 : : &def_policy,
8717 : : error);
8718 [ # # ]: 0 : if (ret < 0)
8719 : 0 : return ret;
8720 : 0 : action_flags |= MLX5_FLOW_ACTION_METER;
8721 [ # # ]: 0 : if (!def_policy)
8722 : 0 : action_flags |=
8723 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
8724 : 0 : ++actions_n;
8725 : : /* Meter action will add one more TAG action. */
8726 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
8727 : 0 : break;
8728 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
8729 [ # # ]: 0 : if (is_root)
8730 : 0 : return rte_flow_error_set(error, ENOTSUP,
8731 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8732 : : NULL,
8733 : : "Shared ASO age action is not supported for group 0");
8734 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_AGE)
8735 : 0 : return rte_flow_error_set
8736 : : (error, EINVAL,
8737 : : RTE_FLOW_ERROR_TYPE_ACTION,
8738 : : NULL,
8739 : : "duplicate age actions set");
8740 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8741 : : aso_after_sample = 1;
8742 : 0 : action_flags |= MLX5_FLOW_ACTION_AGE;
8743 : 0 : ++actions_n;
8744 : 0 : break;
8745 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
8746 : 0 : non_shared_age = actions->conf;
8747 : 0 : ret = flow_dv_validate_action_age(action_flags,
8748 : : actions, dev,
8749 : : error);
8750 [ # # ]: 0 : if (ret < 0)
8751 : 0 : return ret;
8752 : : /*
8753 : : * Validate the regular AGE action (using counter)
8754 : : * mutual exclusion with indirect counter actions.
8755 : : */
8756 [ # # ]: 0 : if (!flow_hit_aso_supported(priv, is_root)) {
8757 [ # # ]: 0 : if (shared_count)
8758 : 0 : return rte_flow_error_set
8759 : : (error, EINVAL,
8760 : : RTE_FLOW_ERROR_TYPE_ACTION,
8761 : : NULL,
8762 : : "old age and indirect count combination is not supported");
8763 [ # # ]: 0 : if (sample_count)
8764 : 0 : return rte_flow_error_set
8765 : : (error, EINVAL,
8766 : : RTE_FLOW_ERROR_TYPE_ACTION,
8767 : : NULL,
8768 : : "old age action and count must be in the same sub flow");
8769 : : } else {
8770 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8771 : : aso_after_sample = 1;
8772 : : }
8773 : 0 : action_flags |= MLX5_FLOW_ACTION_AGE;
8774 : 0 : ++actions_n;
8775 : 0 : break;
8776 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
8777 : 0 : ret = flow_dv_validate_action_modify_ipv4_dscp
8778 : : (action_flags,
8779 : : actions,
8780 : : item_flags,
8781 : : error);
8782 [ # # ]: 0 : if (ret < 0)
8783 : 0 : return ret;
8784 : : /* Count all modify-header actions as one action. */
8785 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8786 : 0 : ++actions_n;
8787 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8788 : : modify_after_mirror = 1;
8789 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
8790 : 0 : rw_act_num += MLX5_ACT_NUM_SET_DSCP;
8791 : 0 : break;
8792 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
8793 : 0 : ret = flow_dv_validate_action_modify_ipv6_dscp
8794 : : (action_flags,
8795 : : actions,
8796 : : item_flags,
8797 : : error);
8798 [ # # ]: 0 : if (ret < 0)
8799 : 0 : return ret;
8800 : : /* Count all modify-header actions as one action. */
8801 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8802 : 0 : ++actions_n;
8803 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8804 : : modify_after_mirror = 1;
8805 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
8806 : 0 : rw_act_num += MLX5_ACT_NUM_SET_DSCP;
8807 : 0 : break;
8808 : 0 : case RTE_FLOW_ACTION_TYPE_SAMPLE:
8809 : 0 : ret = flow_dv_validate_action_sample(&action_flags,
8810 : : &sub_action_flags,
8811 : : actions, dev,
8812 : : attr, item_flags,
8813 : : rss, &sample_rss,
8814 : : &sample_count,
8815 : : &fdb_mirror,
8816 : : &sample_port_id,
8817 : : is_root,
8818 : : error);
8819 [ # # ]: 0 : if (ret < 0)
8820 : 0 : return ret;
8821 [ # # # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_SET_TAG) &&
8822 : 0 : tag_id == 0 &&
8823 [ # # ]: 0 : priv->sh->registers.aso_reg == REG_NON)
8824 : 0 : return rte_flow_error_set(error, EINVAL,
8825 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8826 : : "sample after tag action causes metadata tag index 0 corruption");
8827 : 0 : action_flags |= MLX5_FLOW_ACTION_SAMPLE;
8828 : 0 : ++actions_n;
8829 : 0 : break;
8830 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
8831 : 0 : ret = flow_dv_validate_action_modify_field(dev,
8832 : : action_flags,
8833 : : actions,
8834 : : attr,
8835 : : is_root,
8836 : : error);
8837 [ # # ]: 0 : if (ret < 0)
8838 : 0 : return ret;
8839 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8840 : : modify_after_mirror = 1;
8841 : : /* Count all modify-header actions as one action. */
8842 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8843 : 0 : ++actions_n;
8844 : 0 : action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
8845 : 0 : rw_act_num += ret;
8846 : 0 : break;
8847 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
8848 : 0 : ret = mlx5_flow_dv_validate_action_aso_ct(dev,
8849 : : action_flags,
8850 : : item_flags,
8851 : : is_root,
8852 : : error);
8853 [ # # ]: 0 : if (ret < 0)
8854 : 0 : return ret;
8855 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8856 : : aso_after_sample = 1;
8857 : 0 : action_flags |= MLX5_FLOW_ACTION_CT;
8858 : 0 : break;
8859 : : case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
8860 : : /* tunnel offload action was processed before
8861 : : * list it here as a supported type
8862 : : */
8863 : : break;
8864 : : #ifdef HAVE_MLX5DV_DR_ACTION_CREATE_DEST_ROOT_TABLE
8865 : : case RTE_FLOW_ACTION_TYPE_SEND_TO_KERNEL:
8866 : : action_flags |= MLX5_FLOW_ACTION_SEND_TO_KERNEL;
8867 : : ++actions_n;
8868 : : break;
8869 : : #endif
8870 : 0 : default:
8871 : 0 : return rte_flow_error_set(error, ENOTSUP,
8872 : : RTE_FLOW_ERROR_TYPE_ACTION,
8873 : : actions,
8874 : : "action not supported");
8875 : : }
8876 : : }
8877 : : /*
8878 : : * Validate actions in flow rules
8879 : : * - Explicit decap action is prohibited by the tunnel offload API.
8880 : : * - Drop action in tunnel steer rule is prohibited by the API.
8881 : : * - Application cannot use MARK action because it's value can mask
8882 : : * tunnel default miss notification.
8883 : : * - JUMP in tunnel match rule has no support in current PMD
8884 : : * implementation.
8885 : : * - TAG & META are reserved for future uses.
8886 : : */
8887 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_TUNNEL_SET) {
8888 : : uint64_t bad_actions_mask = MLX5_FLOW_ACTION_DECAP |
8889 : : MLX5_FLOW_ACTION_MARK |
8890 : : MLX5_FLOW_ACTION_SET_TAG |
8891 : : MLX5_FLOW_ACTION_SET_META |
8892 : : MLX5_FLOW_ACTION_DROP;
8893 : :
8894 [ # # ]: 0 : if (action_flags & bad_actions_mask)
8895 : 0 : return rte_flow_error_set
8896 : : (error, EINVAL,
8897 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8898 : : "Invalid RTE action in tunnel "
8899 : : "set decap rule");
8900 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_ACTION_JUMP))
8901 : 0 : return rte_flow_error_set
8902 : : (error, EINVAL,
8903 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8904 : : "tunnel set decap rule must terminate "
8905 : : "with JUMP");
8906 [ # # ]: 0 : if (attr->egress)
8907 : 0 : return rte_flow_error_set
8908 : : (error, EINVAL,
8909 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8910 : : "tunnel flows for ingress and transfer traffic only");
8911 : : }
8912 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_TUNNEL_MATCH) {
8913 : : uint64_t bad_actions_mask = MLX5_FLOW_ACTION_JUMP |
8914 : : MLX5_FLOW_ACTION_MARK |
8915 : : MLX5_FLOW_ACTION_SET_TAG |
8916 : : MLX5_FLOW_ACTION_SET_META;
8917 : :
8918 [ # # ]: 0 : if (action_flags & bad_actions_mask)
8919 : 0 : return rte_flow_error_set
8920 : : (error, EINVAL,
8921 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8922 : : "Invalid RTE action in tunnel "
8923 : : "set match rule");
8924 : : }
8925 : : /*
8926 : : * Validate the drop action mutual exclusion with other actions.
8927 : : * Drop action is mutually-exclusive with any other action, except for
8928 : : * Count/Sample/Age actions.
8929 : : * Drop action compatibility with tunnel offload was already validated.
8930 : : */
8931 [ # # ]: 0 : if (action_flags & (MLX5_FLOW_ACTION_TUNNEL_MATCH |
8932 : : MLX5_FLOW_ACTION_TUNNEL_MATCH));
8933 [ # # ]: 0 : else if ((action_flags & MLX5_FLOW_ACTION_DROP) &&
8934 [ # # ]: 0 : (action_flags & ~(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_DROP_INCLUSIVE_ACTIONS)))
8935 : 0 : return rte_flow_error_set(error, EINVAL,
8936 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8937 : : "Drop action is mutually-exclusive "
8938 : : "with any other action, except for "
8939 : : "Count/Sample/Age action");
8940 : : /* Eswitch has few restrictions on using items and actions */
8941 [ # # ]: 0 : if (attr->transfer) {
8942 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev) &&
8943 [ # # ]: 0 : action_flags & MLX5_FLOW_ACTION_FLAG)
8944 : 0 : return rte_flow_error_set(error, ENOTSUP,
8945 : : RTE_FLOW_ERROR_TYPE_ACTION,
8946 : : NULL,
8947 : : "unsupported action FLAG");
8948 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev) &&
8949 [ # # ]: 0 : action_flags & MLX5_FLOW_ACTION_MARK)
8950 : 0 : return rte_flow_error_set(error, ENOTSUP,
8951 : : RTE_FLOW_ERROR_TYPE_ACTION,
8952 : : NULL,
8953 : : "unsupported action MARK");
8954 [ # # ]: 0 : if (!priv->jump_fdb_rx_en) {
8955 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_QUEUE)
8956 : 0 : return rte_flow_error_set(error, ENOTSUP,
8957 : : RTE_FLOW_ERROR_TYPE_ACTION,
8958 : : NULL,
8959 : : "unsupported action QUEUE");
8960 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_RSS)
8961 : 0 : return rte_flow_error_set(error, ENOTSUP,
8962 : : RTE_FLOW_ERROR_TYPE_ACTION,
8963 : : NULL,
8964 : : "unsupported action RSS");
8965 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
8966 : 0 : return rte_flow_error_set(error, EINVAL,
8967 : : RTE_FLOW_ERROR_TYPE_ACTION,
8968 : : actions,
8969 : : "no fate action is found");
8970 : : }
8971 : : } else {
8972 [ # # # # ]: 0 : if (!(action_flags & MLX5_FLOW_FATE_ACTIONS) && attr->ingress)
8973 : 0 : return rte_flow_error_set(error, EINVAL,
8974 : : RTE_FLOW_ERROR_TYPE_ACTION,
8975 : : actions,
8976 : : "no fate action is found");
8977 : : }
8978 : : /*
8979 : : * Continue validation for Xcap and VLAN actions.
8980 : : * If hairpin is working in explicit TX rule mode, there is no actions
8981 : : * splitting and the validation of hairpin ingress flow should be the
8982 : : * same as other standard flows.
8983 : : */
8984 [ # # ]: 0 : if ((action_flags & (MLX5_FLOW_XCAP_ACTIONS |
8985 [ # # ]: 0 : MLX5_FLOW_VLAN_ACTIONS)) &&
8986 [ # # # # ]: 0 : (queue_index == 0xFFFF || !mlx5_rxq_is_hairpin(dev, queue_index) ||
8987 : 0 : ((conf = mlx5_rxq_get_hairpin_conf(dev, queue_index)) != NULL &&
8988 [ # # ]: 0 : conf->tx_explicit != 0))) {
8989 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
8990 : : MLX5_FLOW_XCAP_ACTIONS)
8991 : 0 : return rte_flow_error_set(error, ENOTSUP,
8992 : : RTE_FLOW_ERROR_TYPE_ACTION,
8993 : : NULL, "encap and decap "
8994 : : "combination aren't supported");
8995 : : /* Push VLAN is not supported in ingress except for NICs newer than CX5. */
8996 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) {
8997 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
8998 : : bool direction_error = false;
8999 : :
9000 [ # # ]: 0 : if (attr->transfer) {
9001 [ # # ]: 0 : bool fdb_tx = flow_source_vport_representor(priv, act_priv);
9002 : 0 : bool is_cx5 = sh->steering_format_version ==
9003 : : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5;
9004 : :
9005 [ # # ]: 0 : if (!fdb_tx && is_cx5)
9006 : : direction_error = true;
9007 [ # # ]: 0 : } else if (attr->ingress) {
9008 : : direction_error = true;
9009 : : }
9010 : : if (direction_error)
9011 : 0 : return rte_flow_error_set(error, ENOTSUP,
9012 : : RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
9013 : : NULL,
9014 : : "push VLAN action not supported "
9015 : : "for ingress");
9016 : : }
9017 [ # # ]: 0 : if (attr->ingress) {
9018 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
9019 : 0 : return rte_flow_error_set
9020 : : (error, ENOTSUP,
9021 : : RTE_FLOW_ERROR_TYPE_ACTION,
9022 : : NULL, "encap is not supported"
9023 : : " for ingress traffic");
9024 [ # # ]: 0 : else if ((action_flags & MLX5_FLOW_VLAN_ACTIONS) ==
9025 : : MLX5_FLOW_VLAN_ACTIONS)
9026 : 0 : return rte_flow_error_set
9027 : : (error, ENOTSUP,
9028 : : RTE_FLOW_ERROR_TYPE_ACTION,
9029 : : NULL, "no support for "
9030 : : "multiple VLAN actions");
9031 : : }
9032 : : }
9033 : : /* Pop VLAN is not supported in egress except for NICs newer than CX5. */
9034 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_POP_VLAN) {
9035 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
9036 : : bool direction_error = false;
9037 : :
9038 [ # # ]: 0 : if (attr->transfer) {
9039 [ # # ]: 0 : bool fdb_tx = flow_source_vport_representor(priv, act_priv);
9040 : 0 : bool is_cx5 = sh->steering_format_version ==
9041 : : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5;
9042 : :
9043 [ # # ]: 0 : if (fdb_tx && is_cx5)
9044 : : direction_error = true;
9045 [ # # ]: 0 : } else if (attr->egress) {
9046 : : direction_error = true;
9047 : : }
9048 : : if (direction_error)
9049 : 0 : return rte_flow_error_set(error, ENOTSUP,
9050 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
9051 : : NULL,
9052 : : "pop vlan action not supported for egress");
9053 : : }
9054 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY) {
9055 [ # # ]: 0 : if ((action_flags & (MLX5_FLOW_FATE_ACTIONS &
9056 [ # # ]: 0 : ~MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)) &&
9057 : : attr->ingress)
9058 : 0 : return rte_flow_error_set
9059 : : (error, ENOTSUP,
9060 : : RTE_FLOW_ERROR_TYPE_ACTION,
9061 : : NULL, "fate action not supported for "
9062 : : "meter with policy");
9063 [ # # ]: 0 : if (attr->egress) {
9064 [ # # ]: 0 : if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
9065 : 0 : return rte_flow_error_set
9066 : : (error, ENOTSUP,
9067 : : RTE_FLOW_ERROR_TYPE_ACTION,
9068 : : NULL, "modify header action in egress "
9069 : : "cannot be done before meter action");
9070 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
9071 : 0 : return rte_flow_error_set
9072 : : (error, ENOTSUP,
9073 : : RTE_FLOW_ERROR_TYPE_ACTION,
9074 : : NULL, "encap action in egress "
9075 : : "cannot be done before meter action");
9076 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
9077 : 0 : return rte_flow_error_set
9078 : : (error, ENOTSUP,
9079 : : RTE_FLOW_ERROR_TYPE_ACTION,
9080 : : NULL, "push vlan action in egress "
9081 : : "cannot be done before meter action");
9082 : : }
9083 : : }
9084 : : /*
9085 : : * Only support one ASO action in a single flow rule.
9086 : : * non-shared AGE + counter will fallback to use HW counter, no ASO hit object.
9087 : : * Group 0 uses HW counter for AGE too even if no counter action.
9088 : : */
9089 [ # # # # ]: 0 : aso_mask = (action_flags & MLX5_FLOW_ACTION_METER && priv->sh->meter_aso_en) << 2 |
9090 [ # # # # : 0 : (action_flags & MLX5_FLOW_ACTION_CT && priv->sh->ct_aso_en) << 1 |
# # ]
9091 : 0 : (action_flags & MLX5_FLOW_ACTION_AGE &&
9092 [ # # ]: 0 : !(non_shared_age && count) &&
9093 [ # # # # : 0 : (attr->group || (attr->transfer && priv->fdb_def_rule)) &&
# # # # ]
9094 [ # # ]: 0 : priv->sh->flow_hit_aso_en);
9095 [ # # ]: 0 : if (rte_popcount64(aso_mask) > 1)
9096 : 0 : return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
9097 : : NULL, "unsupported combining AGE, METER, CT ASO actions in a single rule");
9098 : : /*
9099 : : * Hairpin flow will add one more TAG action in TX implicit mode.
9100 : : * In TX explicit mode, there will be no hairpin flow ID.
9101 : : */
9102 [ # # ]: 0 : if (hairpin > 0)
9103 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
9104 : : /* extra metadata enabled: one more TAG action will be add. */
9105 [ # # ]: 0 : if (dev_conf->dv_flow_en &&
9106 [ # # # # ]: 0 : dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
9107 : 0 : mlx5_flow_ext_mreg_supported(dev))
9108 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
9109 [ # # ]: 0 : if (rw_act_num >
9110 : : flow_dv_modify_hdr_action_max(dev, is_root)) {
9111 : 0 : return rte_flow_error_set(error, ENOTSUP,
9112 : : RTE_FLOW_ERROR_TYPE_ACTION,
9113 : : NULL, "too many header modify"
9114 : : " actions to support");
9115 : : }
9116 [ # # ]: 0 : if (fdb_mirror) {
9117 [ # # # # ]: 0 : if (!priv->sh->cdev->config.hca_attr.reg_c_preserve &&
9118 [ # # ]: 0 : flow_source_vport_representor(priv, act_priv)) {
9119 : : /* Eswitch egress mirror and modify flow has limitation on CX5 */
9120 [ # # ]: 0 : if (modify_after_mirror)
9121 : 0 : return rte_flow_error_set(error, EINVAL,
9122 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9123 : : "sample before modify action is not supported");
9124 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_JUMP)
9125 : 0 : return rte_flow_error_set(error, EINVAL,
9126 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9127 : : "sample and jump action combination is not supported");
9128 : : }
9129 [ # # ]: 0 : if (aso_mask > 0 && aso_after_sample && fdb_mirror)
9130 : 0 : return rte_flow_error_set(error, ENOTSUP,
9131 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9132 : : "sample before ASO action is not supported");
9133 [ # # ]: 0 : if (sub_action_flags & MLX5_FLOW_ACTION_PORT_ID) {
9134 : 0 : port_priv = mlx5_port_to_eswitch_info(sample_port_id, false);
9135 [ # # ]: 0 : if (flow_source_vport_representor(priv, port_priv)) {
9136 [ # # ]: 0 : if (sub_action_flags & MLX5_FLOW_ACTION_ENCAP)
9137 : 0 : return rte_flow_error_set(error, ENOTSUP,
9138 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9139 : : "mirror to rep port with encap is not supported");
9140 : : } else {
9141 [ # # ]: 0 : if (!(sub_action_flags & MLX5_FLOW_ACTION_ENCAP) &&
9142 [ # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_JUMP))
9143 : 0 : return rte_flow_error_set(error, ENOTSUP,
9144 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9145 : : "mirror to wire port without encap is not supported");
9146 : : }
9147 : : }
9148 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_PORT_ID) &&
9149 : : (action_flags & MLX5_FLOW_ACTION_ENCAP)) {
9150 : 0 : port_priv = mlx5_port_to_eswitch_info(port_id, false);
9151 [ # # ]: 0 : if (flow_source_vport_representor(priv, port_priv))
9152 : 0 : return rte_flow_error_set(error, ENOTSUP,
9153 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9154 : : "mirror to rep port with encap is not supported");
9155 : : }
9156 : : }
9157 : : /*
9158 : : * Validation the NIC Egress flow on representor, except implicit
9159 : : * hairpin default egress flow with TX_QUEUE item, other flows not
9160 : : * work due to metadata regC0 mismatch.
9161 : : */
9162 [ # # # # : 0 : if (attr->egress && priv->representor && !(item_flags & MLX5_FLOW_ITEM_SQ))
# # ]
9163 : 0 : return rte_flow_error_set(error, EINVAL,
9164 : : RTE_FLOW_ERROR_TYPE_ITEM,
9165 : : NULL,
9166 : : "NIC egress rules on representors"
9167 : : " is not supported");
9168 : : return 0;
9169 : : }
9170 : :
9171 : : /**
9172 : : * Internal preparation function. Allocates the DV flow size,
9173 : : * this size is constant.
9174 : : *
9175 : : * @param[in] dev
9176 : : * Pointer to the rte_eth_dev structure.
9177 : : * @param[in] attr
9178 : : * Pointer to the flow attributes.
9179 : : * @param[in] items
9180 : : * Pointer to the list of items.
9181 : : * @param[in] actions
9182 : : * Pointer to the list of actions.
9183 : : * @param[out] error
9184 : : * Pointer to the error structure.
9185 : : *
9186 : : * @return
9187 : : * Pointer to mlx5_flow object on success,
9188 : : * otherwise NULL and rte_errno is set.
9189 : : */
9190 : : static struct mlx5_flow *
9191 : 0 : flow_dv_prepare(struct rte_eth_dev *dev,
9192 : : const struct rte_flow_attr *attr __rte_unused,
9193 : : const struct rte_flow_item items[] __rte_unused,
9194 : : const struct rte_flow_action actions[] __rte_unused,
9195 : : struct rte_flow_error *error)
9196 : : {
9197 : 0 : uint32_t handle_idx = 0;
9198 : : struct mlx5_flow *dev_flow;
9199 : : struct mlx5_flow_handle *dev_handle;
9200 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
9201 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
9202 : :
9203 : : MLX5_ASSERT(wks);
9204 : 0 : wks->skip_matcher_reg = 0;
9205 : 0 : wks->policy = NULL;
9206 : 0 : wks->final_policy = NULL;
9207 : 0 : wks->vport_meta_tag = 0;
9208 : : /* In case of corrupting the memory. */
9209 [ # # ]: 0 : if (wks->flow_idx >= MLX5_NUM_MAX_DEV_FLOWS) {
9210 : 0 : rte_flow_error_set(error, ENOSPC,
9211 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9212 : : "not free temporary device flow");
9213 : 0 : return NULL;
9214 : : }
9215 : 0 : dev_handle = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
9216 : : &handle_idx);
9217 [ # # ]: 0 : if (!dev_handle) {
9218 : 0 : rte_flow_error_set(error, ENOMEM,
9219 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9220 : : "not enough memory to create flow handle");
9221 : 0 : return NULL;
9222 : : }
9223 : : MLX5_ASSERT(wks->flow_idx < RTE_DIM(wks->flows));
9224 : 0 : dev_flow = &wks->flows[wks->flow_idx++];
9225 : : memset(dev_flow, 0, sizeof(*dev_flow));
9226 : 0 : dev_flow->handle = dev_handle;
9227 : 0 : dev_flow->handle_idx = handle_idx;
9228 : 0 : dev_flow->dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param);
9229 : 0 : dev_flow->ingress = attr->ingress;
9230 : 0 : dev_flow->dv.transfer = attr->transfer;
9231 : 0 : return dev_flow;
9232 : : }
9233 : :
9234 : : #ifdef RTE_LIBRTE_MLX5_DEBUG
9235 : : /**
9236 : : * Sanity check for match mask and value. Similar to check_valid_spec() in
9237 : : * kernel driver. If unmasked bit is present in value, it returns failure.
9238 : : *
9239 : : * @param match_mask
9240 : : * pointer to match mask buffer.
9241 : : * @param match_value
9242 : : * pointer to match value buffer.
9243 : : *
9244 : : * @return
9245 : : * 0 if valid, -EINVAL otherwise.
9246 : : */
9247 : : static int
9248 : : flow_dv_check_valid_spec(void *match_mask, void *match_value)
9249 : : {
9250 : : uint8_t *m = match_mask;
9251 : : uint8_t *v = match_value;
9252 : : unsigned int i;
9253 : :
9254 : : for (i = 0; i < MLX5_ST_SZ_BYTES(fte_match_param); ++i) {
9255 : : if (v[i] & ~m[i]) {
9256 : : DRV_LOG(ERR,
9257 : : "match_value differs from match_criteria"
9258 : : " %p[%u] != %p[%u]",
9259 : : match_value, i, match_mask, i);
9260 : : return -EINVAL;
9261 : : }
9262 : : }
9263 : : return 0;
9264 : : }
9265 : : #endif
9266 : :
9267 : : /**
9268 : : * Add match of ip_version.
9269 : : *
9270 : : * @param[in] group
9271 : : * Flow group.
9272 : : * @param[in] headers_v
9273 : : * Values header pointer.
9274 : : * @param[in] headers_m
9275 : : * Masks header pointer.
9276 : : * @param[in] ip_version
9277 : : * The IP version to set.
9278 : : */
9279 : : static inline void
9280 : 0 : flow_dv_set_match_ip_version(uint32_t group,
9281 : : void *headers_v,
9282 : : uint32_t key_type,
9283 : : uint8_t ip_version)
9284 : : {
9285 [ # # # # ]: 0 : if (group == 0 && (key_type & MLX5_SET_MATCHER_M))
9286 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version, 0xf);
9287 : : else
9288 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version,
9289 : : ip_version);
9290 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype, 0);
9291 : 0 : }
9292 : :
9293 : : /**
9294 : : * Add Ethernet item to the value.
9295 : : *
9296 : : * @param[in, out] key
9297 : : * Flow matcher value.
9298 : : * @param[in] item
9299 : : * Flow pattern to translate.
9300 : : * @param[in] inner
9301 : : * Item is inner pattern.
9302 : : * @param[in] grpup
9303 : : * Flow matcher group.
9304 : : * @param[in] key_type
9305 : : * Set flow matcher mask or value.
9306 : : */
9307 : : static void
9308 : 0 : flow_dv_translate_item_eth(void *key, const struct rte_flow_item *item,
9309 : : int inner, uint32_t group, uint32_t key_type)
9310 : : {
9311 : 0 : const struct rte_flow_item_eth *eth_vv = item->spec;
9312 : : const struct rte_flow_item_eth *eth_m;
9313 : : const struct rte_flow_item_eth *eth_v;
9314 : 0 : const struct rte_flow_item_eth nic_mask = {
9315 : : .hdr.dst_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
9316 : : .hdr.src_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
9317 : : .hdr.ether_type = RTE_BE16(0xffff),
9318 : : .has_vlan = 0,
9319 : : };
9320 : : void *hdrs_v;
9321 : : char *l24_v;
9322 : : unsigned int i;
9323 : :
9324 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9325 : 0 : return;
9326 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, eth_v, eth_m, &nic_mask);
# # # # ]
9327 [ # # ]: 0 : if (!eth_vv)
9328 : : eth_vv = eth_v;
9329 [ # # ]: 0 : if (inner)
9330 : 0 : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9331 : : else
9332 : : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9333 : : /* The value must be in the range of the mask. */
9334 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, dmac_47_16);
9335 [ # # ]: 0 : for (i = 0; i < sizeof(eth_m->hdr.dst_addr); ++i)
9336 : 0 : l24_v[i] = eth_m->hdr.dst_addr.addr_bytes[i] & eth_v->hdr.dst_addr.addr_bytes[i];
9337 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, smac_47_16);
9338 : : /* The value must be in the range of the mask. */
9339 [ # # ]: 0 : for (i = 0; i < sizeof(eth_m->hdr.dst_addr); ++i)
9340 : 0 : l24_v[i] = eth_m->hdr.src_addr.addr_bytes[i] & eth_v->hdr.src_addr.addr_bytes[i];
9341 : : /*
9342 : : * HW supports match on one Ethertype, the Ethertype following the last
9343 : : * VLAN tag of the packet (see PRM).
9344 : : * Set match on ethertype only if ETH header is not followed by VLAN.
9345 : : * HW is optimized for IPv4/IPv6. In such cases, avoid setting
9346 : : * ethertype, and use ip_version field instead.
9347 : : * eCPRI over Ether layer will use type value 0xAEFE.
9348 : : */
9349 [ # # ]: 0 : if (eth_m->hdr.ether_type == 0xFFFF) {
9350 : 0 : rte_be16_t type = eth_v->hdr.ether_type;
9351 : :
9352 : : /*
9353 : : * When set the matcher mask, refer to the original spec
9354 : : * value.
9355 : : */
9356 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M) {
9357 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
9358 : 0 : type = eth_vv->hdr.ether_type;
9359 : : }
9360 : : /* Set cvlan_tag mask for any single\multi\un-tagged case. */
9361 [ # # # # : 0 : switch (type) {
# ]
9362 : 0 : case RTE_BE16(RTE_ETHER_TYPE_VLAN):
9363 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
9364 : 0 : return;
9365 : 0 : case RTE_BE16(RTE_ETHER_TYPE_QINQ):
9366 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
9367 : 0 : return;
9368 : 0 : case RTE_BE16(RTE_ETHER_TYPE_IPV4):
9369 : 0 : flow_dv_set_match_ip_version(group, hdrs_v, key_type,
9370 : : 4);
9371 : 0 : return;
9372 : 0 : case RTE_BE16(RTE_ETHER_TYPE_IPV6):
9373 : 0 : flow_dv_set_match_ip_version(group, hdrs_v, key_type,
9374 : : 6);
9375 : 0 : return;
9376 : : default:
9377 : : break;
9378 : : }
9379 : : }
9380 : : /*
9381 : : * Only SW steering value should refer to the mask value.
9382 : : * Other cases are using the fake masks, just ignore the mask.
9383 : : */
9384 [ # # # # ]: 0 : if (eth_v->has_vlan && eth_m->has_vlan) {
9385 : : /*
9386 : : * Here, when also has_more_vlan field in VLAN item is
9387 : : * not set, only single-tagged packets will be matched.
9388 : : */
9389 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
9390 [ # # # # ]: 0 : if (key_type != MLX5_SET_MATCHER_HS_M && eth_vv->has_vlan)
9391 : : return;
9392 : : }
9393 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, ethertype);
9394 : 0 : *(uint16_t *)(l24_v) = eth_m->hdr.ether_type & eth_v->hdr.ether_type;
9395 : : }
9396 : :
9397 : : /**
9398 : : * Add VLAN item to the value.
9399 : : *
9400 : : * @param[in, out] key
9401 : : * Flow matcher value.
9402 : : * @param[in] item
9403 : : * Flow pattern to translate.
9404 : : * @param[in] inner
9405 : : * Item is inner pattern.
9406 : : * @param[in] wks
9407 : : * Item workspace.
9408 : : * @param[in] key_type
9409 : : * Set flow matcher mask or value.
9410 : : */
9411 : : static void
9412 : 0 : flow_dv_translate_item_vlan(void *key, const struct rte_flow_item *item,
9413 : : int inner, struct mlx5_dv_matcher_workspace *wks,
9414 : : uint32_t key_type)
9415 : : {
9416 : : const struct rte_flow_item_vlan *vlan_m;
9417 : : const struct rte_flow_item_vlan *vlan_v;
9418 : 0 : const struct rte_flow_item_vlan *vlan_vv = item->spec;
9419 : : void *hdrs_v;
9420 : : uint16_t tci_v;
9421 : :
9422 [ # # ]: 0 : if (inner) {
9423 : 0 : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9424 : : } else {
9425 : : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9426 : : /*
9427 : : * This is workaround, masks are not supported,
9428 : : * and pre-validated.
9429 : : */
9430 [ # # ]: 0 : if (vlan_vv)
9431 [ # # ]: 0 : wks->vlan_tag = rte_be_to_cpu_16(vlan_vv->hdr.vlan_tci) & 0x0fff;
9432 : : }
9433 : : /*
9434 : : * When VLAN item exists in flow, mark packet as tagged,
9435 : : * even if TCI is not specified.
9436 : : */
9437 [ # # # # ]: 0 : if (!MLX5_GET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag))
9438 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
9439 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9440 : : return;
9441 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, vlan_v, vlan_m,
# # # # ]
9442 : : &rte_flow_item_vlan_mask);
9443 [ # # ]: 0 : tci_v = rte_be_to_cpu_16(vlan_m->hdr.vlan_tci & vlan_v->hdr.vlan_tci);
9444 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_vid, tci_v);
9445 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_cfi, tci_v >> 12);
9446 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_prio, tci_v >> 13);
9447 : : /*
9448 : : * HW is optimized for IPv4/IPv6. In such cases, avoid setting
9449 : : * ethertype, and use ip_version field instead.
9450 : : */
9451 [ # # ]: 0 : if (vlan_m->hdr.eth_proto == 0xFFFF) {
9452 : 0 : rte_be16_t inner_type = vlan_v->hdr.eth_proto;
9453 : :
9454 : : /*
9455 : : * When set the matcher mask, refer to the original spec
9456 : : * value.
9457 : : */
9458 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M)
9459 : 0 : inner_type = vlan_vv->hdr.eth_proto;
9460 [ # # # # ]: 0 : switch (inner_type) {
9461 : 0 : case RTE_BE16(RTE_ETHER_TYPE_VLAN):
9462 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
9463 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_V)
9464 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v,
9465 : : cvlan_tag, 0);
9466 : 0 : return;
9467 : 0 : case RTE_BE16(RTE_ETHER_TYPE_IPV4):
9468 : 0 : flow_dv_set_match_ip_version
9469 : : (wks->group, hdrs_v, key_type, 4);
9470 : 0 : return;
9471 : 0 : case RTE_BE16(RTE_ETHER_TYPE_IPV6):
9472 : 0 : flow_dv_set_match_ip_version
9473 : : (wks->group, hdrs_v, key_type, 6);
9474 : 0 : return;
9475 : : default:
9476 : : break;
9477 : : }
9478 : : }
9479 [ # # # # ]: 0 : if (vlan_m->has_more_vlan && vlan_v->has_more_vlan) {
9480 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
9481 : : /* Only one vlan_tag bit can be set. */
9482 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_V)
9483 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 0);
9484 : 0 : return;
9485 : : }
9486 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, ethertype,
9487 : : rte_be_to_cpu_16(vlan_m->hdr.eth_proto & vlan_v->hdr.eth_proto));
9488 : : }
9489 : :
9490 : : /**
9491 : : * Add IPV4 item to the value.
9492 : : *
9493 : : * @param[in, out] key
9494 : : * Flow matcher value.
9495 : : * @param[in] item
9496 : : * Flow pattern to translate.
9497 : : * @param[in] inner
9498 : : * Item is inner pattern.
9499 : : * @param[in] group
9500 : : * The group to insert the rule.
9501 : : * @param[in] key_type
9502 : : * Set flow matcher mask or value.
9503 : : */
9504 : : static void
9505 : 0 : flow_dv_translate_item_ipv4(void *key, const struct rte_flow_item *item,
9506 : : int inner, uint32_t group, uint32_t key_type)
9507 : : {
9508 : : const struct rte_flow_item_ipv4 *ipv4_m;
9509 : : const struct rte_flow_item_ipv4 *ipv4_v;
9510 : 0 : const struct rte_flow_item_ipv4 nic_mask = {
9511 : : .hdr = {
9512 : : .src_addr = RTE_BE32(0xffffffff),
9513 : : .dst_addr = RTE_BE32(0xffffffff),
9514 : : .type_of_service = 0xff,
9515 : : .next_proto_id = 0xff,
9516 : : .time_to_live = 0xff,
9517 : : },
9518 : : };
9519 : : void *headers_v;
9520 : : char *l24_v;
9521 : : uint8_t tos;
9522 : :
9523 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9524 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9525 : 0 : flow_dv_set_match_ip_version(group, headers_v, key_type, 4);
9526 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9527 : 0 : return;
9528 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, ipv4_v, ipv4_m, &nic_mask);
# # # # ]
9529 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
9530 : : dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
9531 : 0 : *(uint32_t *)l24_v = ipv4_m->hdr.dst_addr & ipv4_v->hdr.dst_addr;
9532 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
9533 : : src_ipv4_src_ipv6.ipv4_layout.ipv4);
9534 : 0 : *(uint32_t *)l24_v = ipv4_m->hdr.src_addr & ipv4_v->hdr.src_addr;
9535 : 0 : tos = ipv4_m->hdr.type_of_service & ipv4_v->hdr.type_of_service;
9536 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ipv4_ihl,
9537 : : ipv4_v->hdr.ihl & ipv4_m->hdr.ihl);
9538 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M)
9539 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn,
9540 : : ipv4_v->hdr.type_of_service);
9541 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, tos);
9542 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, tos >> 2);
9543 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
9544 : : ipv4_v->hdr.next_proto_id & ipv4_m->hdr.next_proto_id);
9545 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
9546 : : ipv4_v->hdr.time_to_live & ipv4_m->hdr.time_to_live);
9547 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
9548 : : !!(ipv4_v->hdr.fragment_offset & ipv4_m->hdr.fragment_offset));
9549 : : }
9550 : :
9551 : : /**
9552 : : * Add IPV6 item to the value.
9553 : : *
9554 : : * @param[in, out] key
9555 : : * Flow matcher value.
9556 : : * @param[in] item
9557 : : * Flow pattern to translate.
9558 : : * @param[in] inner
9559 : : * Item is inner pattern.
9560 : : * @param[in] group
9561 : : * The group to insert the rule.
9562 : : * @param[in] key_type
9563 : : * Set flow matcher mask or value.
9564 : : */
9565 : : static void
9566 : 0 : flow_dv_translate_item_ipv6(void *key, const struct rte_flow_item *item,
9567 : : int inner, uint32_t group, uint32_t key_type)
9568 : : {
9569 : : const struct rte_flow_item_ipv6 *ipv6_m;
9570 : : const struct rte_flow_item_ipv6 *ipv6_v;
9571 : 0 : const struct rte_flow_item_ipv6 nic_mask = {
9572 : : .hdr = {
9573 : : .src_addr = RTE_IPV6_MASK_FULL,
9574 : : .dst_addr = RTE_IPV6_MASK_FULL,
9575 : : .vtc_flow = RTE_BE32(0xffffffff),
9576 : : .proto = 0xff,
9577 : : .hop_limits = 0xff,
9578 : : },
9579 : : };
9580 : : void *headers_v;
9581 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9582 : : char *l24_v;
9583 : : uint32_t vtc_v;
9584 : : int i;
9585 : : int size;
9586 : :
9587 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9588 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9589 : 0 : flow_dv_set_match_ip_version(group, headers_v, key_type, 6);
9590 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9591 : 0 : return;
9592 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, ipv6_v, ipv6_m, &nic_mask);
# # # # ]
9593 : : size = sizeof(ipv6_m->hdr.dst_addr);
9594 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
9595 : : dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
9596 [ # # ]: 0 : for (i = 0; i < size; ++i)
9597 : 0 : l24_v[i] = ipv6_m->hdr.dst_addr.a[i] & ipv6_v->hdr.dst_addr.a[i];
9598 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
9599 : : src_ipv4_src_ipv6.ipv6_layout.ipv6);
9600 [ # # ]: 0 : for (i = 0; i < size; ++i)
9601 : 0 : l24_v[i] = ipv6_m->hdr.src_addr.a[i] & ipv6_v->hdr.src_addr.a[i];
9602 : : /* TOS. */
9603 [ # # ]: 0 : vtc_v = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow & ipv6_v->hdr.vtc_flow);
9604 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, vtc_v >> 20);
9605 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, vtc_v >> 22);
9606 : : /* Label. */
9607 [ # # ]: 0 : if (inner)
9608 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, inner_ipv6_flow_label,
9609 : : vtc_v);
9610 : : else
9611 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, outer_ipv6_flow_label,
9612 : : vtc_v);
9613 : : /* Protocol. */
9614 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
9615 : : ipv6_v->hdr.proto & ipv6_m->hdr.proto);
9616 : : /* Hop limit. */
9617 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
9618 : : ipv6_v->hdr.hop_limits & ipv6_m->hdr.hop_limits);
9619 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
9620 : : !!(ipv6_v->has_frag_ext & ipv6_m->has_frag_ext));
9621 : : }
9622 : :
9623 : : /**
9624 : : * Add IPV6 fragment extension item to the value.
9625 : : *
9626 : : * @param[in, out] key
9627 : : * Flow matcher value.
9628 : : * @param[in] item
9629 : : * Flow pattern to translate.
9630 : : * @param[in] inner
9631 : : * Item is inner pattern.
9632 : : * @param[in] key_type
9633 : : * Set flow matcher mask or value.
9634 : : */
9635 : : static void
9636 : 0 : flow_dv_translate_item_ipv6_frag_ext(void *key,
9637 : : const struct rte_flow_item *item,
9638 : : int inner, uint32_t key_type)
9639 : : {
9640 : : const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_m;
9641 : : const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_v;
9642 : 0 : const struct rte_flow_item_ipv6_frag_ext nic_mask = {
9643 : : .hdr = {
9644 : : .next_header = 0xff,
9645 : : .frag_data = RTE_BE16(0xffff),
9646 : : },
9647 : : };
9648 : : void *headers_v;
9649 : :
9650 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9651 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9652 : : /* IPv6 fragment extension item exists, so packet is IP fragment. */
9653 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag, 1);
9654 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9655 : 0 : return;
9656 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, ipv6_frag_ext_v,
# # # # ]
9657 : : ipv6_frag_ext_m, &nic_mask);
9658 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
9659 : : ipv6_frag_ext_v->hdr.next_header &
9660 : : ipv6_frag_ext_m->hdr.next_header);
9661 : : }
9662 : :
9663 : : /**
9664 : : * Add TCP item to the value.
9665 : : *
9666 : : * @param[in, out] key
9667 : : * Flow matcher value.
9668 : : * @param[in] item
9669 : : * Flow pattern to translate.
9670 : : * @param[in] inner
9671 : : * Item is inner pattern.
9672 : : * @param[in] key_type
9673 : : * Set flow matcher mask or value.
9674 : : */
9675 : : static void
9676 : 0 : flow_dv_translate_item_tcp(void *key, const struct rte_flow_item *item,
9677 : : int inner, uint32_t key_type)
9678 : : {
9679 : : const struct rte_flow_item_tcp *tcp_m;
9680 : : const struct rte_flow_item_tcp *tcp_v;
9681 : : void *headers_v;
9682 : :
9683 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9684 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9685 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9686 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9687 : : ip_protocol, 0xff);
9688 : : else
9689 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9690 : : ip_protocol, IPPROTO_TCP);
9691 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9692 : : return;
9693 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, tcp_v, tcp_m,
# # # # ]
9694 : : &rte_flow_item_tcp_mask);
9695 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_sport,
9696 : : rte_be_to_cpu_16(tcp_v->hdr.src_port & tcp_m->hdr.src_port));
9697 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_dport,
9698 : : rte_be_to_cpu_16(tcp_v->hdr.dst_port & tcp_m->hdr.dst_port));
9699 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_flags,
9700 : : tcp_v->hdr.tcp_flags & tcp_m->hdr.tcp_flags);
9701 : : }
9702 : :
9703 : : /**
9704 : : * Add ESP item to the value.
9705 : : *
9706 : : * @param[in, out] key
9707 : : * Flow matcher value.
9708 : : * @param[in] item
9709 : : * Flow pattern to translate.
9710 : : * @param[in] inner
9711 : : * Item is inner pattern.
9712 : : * @param[in] key_type
9713 : : * Set flow matcher mask or value.
9714 : : */
9715 : : static void
9716 : 0 : flow_dv_translate_item_esp(void *key, const struct rte_flow_item *item,
9717 : : int inner, uint32_t key_type, uint64_t item_flags)
9718 : : {
9719 : : const struct rte_flow_item_esp *esp_m;
9720 : : const struct rte_flow_item_esp *esp_v;
9721 : : void *headers_v;
9722 : : char *spi_v;
9723 [ # # ]: 0 : bool over_udp = item_flags & (inner ? MLX5_FLOW_LAYER_INNER_L4_UDP :
9724 : : MLX5_FLOW_LAYER_OUTER_L4_UDP);
9725 : :
9726 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9727 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9728 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
9729 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, 0xff);
9730 [ # # # # : 0 : if (over_udp && !MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport))
# # ]
9731 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, 0xFFFF);
9732 : : } else {
9733 [ # # ]: 0 : if (!over_udp)
9734 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ESP);
9735 : : else
9736 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport))
9737 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
9738 : : MLX5_UDP_PORT_ESP);
9739 : : }
9740 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9741 : : return;
9742 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, esp_v, esp_m, &rte_flow_item_esp_mask);
# # # # ]
9743 : : headers_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9744 [ # # ]: 0 : spi_v = inner ? MLX5_ADDR_OF(fte_match_set_misc, headers_v, inner_esp_spi) :
9745 : : MLX5_ADDR_OF(fte_match_set_misc, headers_v, outer_esp_spi);
9746 : 0 : *(uint32_t *)spi_v = esp_m->hdr.spi & esp_v->hdr.spi;
9747 : : }
9748 : :
9749 : : /**
9750 : : * Add UDP item to the value.
9751 : : *
9752 : : * @param[in, out] key
9753 : : * Flow matcher value.
9754 : : * @param[in] item
9755 : : * Flow pattern to translate.
9756 : : * @param[in] inner
9757 : : * Item is inner pattern.
9758 : : * @param[in] key_type
9759 : : * Set flow matcher mask or value.
9760 : : */
9761 : : static void
9762 : 0 : flow_dv_translate_item_udp(void *key, const struct rte_flow_item *item,
9763 : : int inner, struct mlx5_dv_matcher_workspace *wks,
9764 : : uint32_t key_type)
9765 : : {
9766 : : const struct rte_flow_item_udp *udp_m;
9767 : : const struct rte_flow_item_udp *udp_v;
9768 : : void *headers_v;
9769 : :
9770 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9771 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9772 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9773 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9774 : : ip_protocol, 0xff);
9775 : : else
9776 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9777 : : ip_protocol, IPPROTO_UDP);
9778 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9779 : : return;
9780 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, udp_v, udp_m,
# # # # ]
9781 : : &rte_flow_item_udp_mask);
9782 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_sport,
9783 : : rte_be_to_cpu_16(udp_v->hdr.src_port & udp_m->hdr.src_port));
9784 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
9785 : : rte_be_to_cpu_16(udp_v->hdr.dst_port & udp_m->hdr.dst_port));
9786 : : /* Force get UDP dport in case to be used in VXLAN translate. */
9787 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_SW) {
9788 : 0 : udp_v = item->spec;
9789 [ # # ]: 0 : wks->udp_dport = rte_be_to_cpu_16(udp_v->hdr.dst_port &
9790 : : udp_m->hdr.dst_port);
9791 : : }
9792 : : }
9793 : :
9794 : : /**
9795 : : * Add GRE optional Key item to the value.
9796 : : *
9797 : : * @param[in, out] key
9798 : : * Flow matcher value.
9799 : : * @param[in] item
9800 : : * Flow pattern to translate.
9801 : : * @param[in] inner
9802 : : * Item is inner pattern.
9803 : : */
9804 : : static void
9805 : 0 : flow_dv_translate_item_gre_key(void *key, const struct rte_flow_item *item,
9806 : : uint32_t key_type)
9807 : : {
9808 : : const rte_be32_t *key_m;
9809 : : const rte_be32_t *key_v;
9810 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9811 : 0 : rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
9812 : :
9813 : : /* GRE K bit must be on and should already be validated */
9814 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_k_present, 1);
9815 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9816 : 0 : return;
9817 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, key_v, key_m,
# # # # ]
9818 : : &gre_key_default_mask);
9819 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_key_h,
9820 : : rte_be_to_cpu_32((*key_v) & (*key_m)) >> 8);
9821 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_key_l,
9822 : : rte_be_to_cpu_32((*key_v) & (*key_m)) & 0xFF);
9823 : : }
9824 : :
9825 : : /**
9826 : : * Add GRE item to the value.
9827 : : *
9828 : : * @param[in, out] key
9829 : : * Flow matcher value.
9830 : : * @param[in] item
9831 : : * Flow pattern to translate.
9832 : : * @param[in] pattern_flags
9833 : : * Accumulated pattern flags.
9834 : : * @param[in] key_type
9835 : : * Set flow matcher mask or value.
9836 : : */
9837 : : static void
9838 : 0 : flow_dv_translate_item_gre(void *key, const struct rte_flow_item *item,
9839 : : uint64_t pattern_flags, uint32_t key_type)
9840 : : {
9841 : : static const struct rte_flow_item_gre empty_gre = {0,};
9842 : 0 : const struct rte_flow_item_gre *gre_m = item->mask;
9843 : 0 : const struct rte_flow_item_gre *gre_v = item->spec;
9844 : : void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9845 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9846 : : struct {
9847 : : union {
9848 : : __extension__
9849 : : struct {
9850 : : uint16_t version:3;
9851 : : uint16_t rsvd0:9;
9852 : : uint16_t s_present:1;
9853 : : uint16_t k_present:1;
9854 : : uint16_t rsvd_bit1:1;
9855 : : uint16_t c_present:1;
9856 : : };
9857 : : uint16_t value;
9858 : : };
9859 : : } gre_crks_rsvd0_ver_m, gre_crks_rsvd0_ver_v;
9860 : : uint16_t protocol_m, protocol_v;
9861 : :
9862 : : /* Common logic to SWS/HWS */
9863 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9864 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, 0xff);
9865 : : else
9866 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
9867 : : IPPROTO_GRE);
9868 : : /* HWS mask logic only */
9869 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_HS_M) {
9870 [ # # ]: 0 : if (!gre_m)
9871 : : gre_m = &empty_gre;
9872 : : gre_v = gre_m;
9873 [ # # ]: 0 : } else if (!gre_v) {
9874 : : gre_v = &empty_gre;
9875 : : gre_m = &empty_gre;
9876 [ # # ]: 0 : } else if (!gre_m) {
9877 : : gre_m = &rte_flow_item_gre_mask;
9878 : : }
9879 : : /* SWS logic only */
9880 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_SW_M)
9881 : : gre_v = gre_m;
9882 [ # # ]: 0 : gre_crks_rsvd0_ver_m.value = rte_be_to_cpu_16(gre_m->c_rsvd0_ver);
9883 [ # # ]: 0 : gre_crks_rsvd0_ver_v.value = rte_be_to_cpu_16(gre_v->c_rsvd0_ver);
9884 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_c_present,
9885 : : gre_crks_rsvd0_ver_v.c_present &
9886 : : gre_crks_rsvd0_ver_m.c_present);
9887 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_k_present,
9888 : : gre_crks_rsvd0_ver_v.k_present &
9889 : : gre_crks_rsvd0_ver_m.k_present);
9890 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_s_present,
9891 : : gre_crks_rsvd0_ver_v.s_present &
9892 : : gre_crks_rsvd0_ver_m.s_present);
9893 [ # # ]: 0 : protocol_m = rte_be_to_cpu_16(gre_m->protocol);
9894 [ # # ]: 0 : protocol_v = rte_be_to_cpu_16(gre_v->protocol);
9895 [ # # ]: 0 : if (!protocol_m) {
9896 : : /* Force next protocol to prevent matchers duplication */
9897 : : protocol_v = mlx5_translate_tunnel_etypes(pattern_flags);
9898 : : if (protocol_v)
9899 : : protocol_m = 0xFFFF;
9900 : : /* Restore the value to mask in mask case. */
9901 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9902 : : protocol_v = protocol_m;
9903 : : }
9904 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
9905 : : protocol_m & protocol_v);
9906 : 0 : }
9907 : :
9908 : : /**
9909 : : * Add GRE optional items to the value.
9910 : : *
9911 : : * @param[in, out] key
9912 : : * Flow matcher value.
9913 : : * @param[in] item
9914 : : * Flow pattern to translate.
9915 : : * @param[in] gre_item
9916 : : * Pointer to gre_item.
9917 : : * @param[in] pattern_flags
9918 : : * Accumulated pattern flags.
9919 : : * @param[in] key_type
9920 : : * Set flow matcher mask or value.
9921 : : */
9922 : : static void
9923 : 0 : flow_dv_translate_item_gre_option(void *key,
9924 : : const struct rte_flow_item *item,
9925 : : const struct rte_flow_item *gre_item,
9926 : : uint64_t pattern_flags, uint32_t key_type)
9927 : : {
9928 : : void *misc5_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_5);
9929 : 0 : const struct rte_flow_item_gre_opt *option_m = item->mask;
9930 : 0 : const struct rte_flow_item_gre_opt *option_v = item->spec;
9931 : 0 : const struct rte_flow_item_gre *gre_m = gre_item->mask;
9932 : 0 : const struct rte_flow_item_gre *gre_v = gre_item->spec;
9933 : : static const struct rte_flow_item_gre empty_gre = {0};
9934 : : struct rte_flow_item gre_key_item;
9935 : : uint16_t c_rsvd0_ver_m, c_rsvd0_ver_v;
9936 : : uint16_t protocol_m, protocol_v;
9937 : :
9938 : : /*
9939 : : * If only match key field, keep using misc for matching.
9940 : : * If need to match checksum or sequence, using misc5 and do
9941 : : * not need using misc.
9942 : : */
9943 [ # # ]: 0 : if (!(option_m->sequence.sequence ||
9944 [ # # ]: 0 : option_m->checksum_rsvd.checksum)) {
9945 : 0 : flow_dv_translate_item_gre(key, gre_item, pattern_flags, key_type);
9946 : 0 : gre_key_item.spec = &option_v->key.key;
9947 : 0 : gre_key_item.mask = &option_m->key.key;
9948 : 0 : flow_dv_translate_item_gre_key(key, &gre_key_item, key_type);
9949 : 0 : return;
9950 : : }
9951 [ # # ]: 0 : if (!gre_v) {
9952 : : gre_v = &empty_gre;
9953 : : gre_m = &empty_gre;
9954 : : } else {
9955 [ # # ]: 0 : if (!gre_m)
9956 : : gre_m = &rte_flow_item_gre_mask;
9957 : : }
9958 : 0 : protocol_v = gre_v->protocol;
9959 : 0 : protocol_m = gre_m->protocol;
9960 [ # # ]: 0 : if (!protocol_m) {
9961 : : /* Force next protocol to prevent matchers duplication */
9962 : : uint16_t ether_type =
9963 : : mlx5_translate_tunnel_etypes(pattern_flags);
9964 : : if (ether_type) {
9965 [ # # ]: 0 : protocol_v = rte_be_to_cpu_16(ether_type);
9966 : : protocol_m = UINT16_MAX;
9967 : : }
9968 : : }
9969 : 0 : c_rsvd0_ver_v = gre_v->c_rsvd0_ver;
9970 : 0 : c_rsvd0_ver_m = gre_m->c_rsvd0_ver;
9971 [ # # ]: 0 : if (option_m->sequence.sequence) {
9972 : 0 : c_rsvd0_ver_v |= RTE_BE16(0x1000);
9973 : 0 : c_rsvd0_ver_m |= RTE_BE16(0x1000);
9974 : : }
9975 [ # # ]: 0 : if (option_m->key.key) {
9976 : 0 : c_rsvd0_ver_v |= RTE_BE16(0x2000);
9977 : 0 : c_rsvd0_ver_m |= RTE_BE16(0x2000);
9978 : : }
9979 [ # # ]: 0 : if (option_m->checksum_rsvd.checksum) {
9980 : 0 : c_rsvd0_ver_v |= RTE_BE16(0x8000);
9981 : 0 : c_rsvd0_ver_m |= RTE_BE16(0x8000);
9982 : : }
9983 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
9984 : : c_rsvd0_ver_v = c_rsvd0_ver_m;
9985 : : protocol_v = protocol_m;
9986 : : option_v = option_m;
9987 : : }
9988 : : /*
9989 : : * Hardware parses GRE optional field into the fixed location,
9990 : : * do not need to adjust the tunnel dword indices.
9991 : : */
9992 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_0,
9993 : : rte_be_to_cpu_32((c_rsvd0_ver_v | protocol_v << 16) &
9994 : : (c_rsvd0_ver_m | protocol_m << 16)));
9995 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_1,
9996 : : rte_be_to_cpu_32(option_v->checksum_rsvd.checksum &
9997 : : option_m->checksum_rsvd.checksum));
9998 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_2,
9999 : : rte_be_to_cpu_32(option_v->key.key & option_m->key.key));
10000 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_3,
10001 : : rte_be_to_cpu_32(option_v->sequence.sequence &
10002 : : option_m->sequence.sequence));
10003 : : }
10004 : :
10005 : : /**
10006 : : * Add NVGRE item to matcher and to the value.
10007 : : *
10008 : : * @param[in, out] key
10009 : : * Flow matcher value.
10010 : : * @param[in] item
10011 : : * Flow pattern to translate.
10012 : : * @param[in] pattern_flags
10013 : : * Accumulated pattern flags.
10014 : : * @param[in] key_type
10015 : : * Set flow matcher mask or value.
10016 : : */
10017 : : static void
10018 : 0 : flow_dv_translate_item_nvgre(void *key, const struct rte_flow_item *item,
10019 : : unsigned long pattern_flags, uint32_t key_type)
10020 : : {
10021 : : const struct rte_flow_item_nvgre *nvgre_m;
10022 : : const struct rte_flow_item_nvgre *nvgre_v;
10023 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10024 : : const char *tni_flow_id_m;
10025 : : const char *tni_flow_id_v;
10026 : : char *gre_key_v;
10027 : : int size;
10028 : : int i;
10029 : :
10030 : : /* For NVGRE, GRE header fields must be set with defined values. */
10031 : 0 : const struct rte_flow_item_gre gre_spec = {
10032 : : .c_rsvd0_ver = RTE_BE16(0x2000),
10033 : : .protocol = RTE_BE16(RTE_ETHER_TYPE_TEB)
10034 : : };
10035 : 0 : const struct rte_flow_item_gre gre_mask = {
10036 : : .c_rsvd0_ver = RTE_BE16(0xB000),
10037 : : .protocol = RTE_BE16(UINT16_MAX),
10038 : : };
10039 : 0 : const struct rte_flow_item gre_item = {
10040 : : .spec = &gre_spec,
10041 : : .mask = &gre_mask,
10042 : : .last = NULL,
10043 : : };
10044 : 0 : flow_dv_translate_item_gre(key, &gre_item, pattern_flags, key_type);
10045 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10046 : 0 : return;
10047 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, nvgre_v, nvgre_m,
# # # # ]
10048 : : &rte_flow_item_nvgre_mask);
10049 : 0 : tni_flow_id_m = (const char *)nvgre_m->tni;
10050 : 0 : tni_flow_id_v = (const char *)nvgre_v->tni;
10051 : : size = sizeof(nvgre_m->tni) + sizeof(nvgre_m->flow_id);
10052 : 0 : gre_key_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, gre_key_h);
10053 [ # # ]: 0 : for (i = 0; i < size; ++i)
10054 : 0 : gre_key_v[i] = tni_flow_id_m[i] & tni_flow_id_v[i];
10055 : : }
10056 : :
10057 : : /**
10058 : : * Add VXLAN item to the value.
10059 : : *
10060 : : * @param[in] dev
10061 : : * Pointer to the Ethernet device structure.
10062 : : * @param[in] attr
10063 : : * Flow rule attributes.
10064 : : * @param[in, out] key
10065 : : * Flow matcher value.
10066 : : * @param[in] item
10067 : : * Flow pattern to translate.
10068 : : * @param[in] inner
10069 : : * Item is inner pattern.
10070 : : * @param[in] wks
10071 : : * Matcher workspace.
10072 : : * @param[in] key_type
10073 : : * Set flow matcher mask or value.
10074 : : */
10075 : : static void
10076 : 0 : flow_dv_translate_item_vxlan(struct rte_eth_dev *dev,
10077 : : const struct rte_flow_attr *attr,
10078 : : void *key, const struct rte_flow_item *item,
10079 : : int inner, struct mlx5_dv_matcher_workspace *wks,
10080 : : uint32_t key_type)
10081 : : {
10082 : : const struct rte_flow_item_vxlan *vxlan_m;
10083 : : const struct rte_flow_item_vxlan *vxlan_v;
10084 : : void *headers_v;
10085 : : void *misc_v;
10086 : : void *misc5_v;
10087 : : uint32_t tunnel_v;
10088 : : char *vni_v;
10089 : : uint16_t dport;
10090 : : int size;
10091 : : int i;
10092 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10093 : 0 : const struct rte_flow_item_vxlan nic_mask = {
10094 : : .hdr.vni = { 0xff, 0xff, 0xff },
10095 : : .hdr.rsvd1 = 0xff,
10096 : : };
10097 : :
10098 : : misc5_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_5);
10099 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
10100 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10101 [ # # ]: 0 : dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
10102 : : MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
10103 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
10104 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10105 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
10106 : : udp_dport, 0xFFFF);
10107 : : else
10108 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
10109 : : udp_dport, dport);
10110 : : }
10111 : : /*
10112 : : * Read the UDP dport to check if the value satisfies the VXLAN
10113 : : * matching with MISC5 for CX5.
10114 : : */
10115 [ # # ]: 0 : if (wks->udp_dport)
10116 : : dport = wks->udp_dport;
10117 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10118 : 0 : return;
10119 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, vxlan_v, vxlan_m, &nic_mask);
# # # # ]
10120 : : if ((item->mask == &nic_mask) &&
10121 : : ((!attr->group && !(attr->transfer && priv->fdb_def_rule) &&
10122 : : !priv->sh->tunnel_header_0_1) ||
10123 : : ((attr->group || (attr->transfer && priv->fdb_def_rule)) &&
10124 : : !priv->sh->misc5_cap)))
10125 : : vxlan_m = &rte_flow_item_vxlan_mask;
10126 [ # # ]: 0 : if ((priv->sh->steering_format_version ==
10127 [ # # ]: 0 : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5 &&
10128 : 0 : dport != MLX5_UDP_PORT_VXLAN) ||
10129 [ # # # # : 0 : (!attr->group && !(attr->transfer && priv->fdb_def_rule)) ||
# # # # ]
10130 [ # # # # ]: 0 : ((attr->group || (attr->transfer && priv->fdb_def_rule)) &&
10131 [ # # ]: 0 : !priv->sh->misc5_cap)) {
10132 : : misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10133 : : size = sizeof(vxlan_m->hdr.vni);
10134 : 0 : vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, vxlan_vni);
10135 [ # # ]: 0 : for (i = 0; i < size; ++i)
10136 : 0 : vni_v[i] = vxlan_m->hdr.vni[i] & vxlan_v->hdr.vni[i];
10137 : : return;
10138 : : }
10139 : 0 : tunnel_v = (vxlan_v->hdr.vni[0] & vxlan_m->hdr.vni[0]) |
10140 : 0 : (vxlan_v->hdr.vni[1] & vxlan_m->hdr.vni[1]) << 8 |
10141 : 0 : (vxlan_v->hdr.vni[2] & vxlan_m->hdr.vni[2]) << 16;
10142 : 0 : tunnel_v |= (vxlan_v->hdr.rsvd1 & vxlan_m->hdr.rsvd1) << 24;
10143 [ # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_1, RTE_BE32(tunnel_v));
10144 : : }
10145 : :
10146 : : /**
10147 : : * Add VXLAN-GPE item to the value.
10148 : : *
10149 : : * @param[in, out] key
10150 : : * Flow matcher value.
10151 : : * @param[in] item
10152 : : * Flow pattern to translate.
10153 : : * @param[in] pattern_flags
10154 : : * Item pattern flags.
10155 : : * @param[in] key_type
10156 : : * Set flow matcher mask or value.
10157 : : */
10158 : :
10159 : : static void
10160 : 0 : flow_dv_translate_item_vxlan_gpe(void *key, const struct rte_flow_item *item,
10161 : : const uint64_t pattern_flags,
10162 : : uint32_t key_type)
10163 : : {
10164 : : static const struct rte_flow_item_vxlan_gpe dummy_vxlan_gpe_hdr = {{{0}}};
10165 : 0 : const struct rte_flow_item_vxlan_gpe *vxlan_m = item->mask;
10166 : 0 : const struct rte_flow_item_vxlan_gpe *vxlan_v = item->spec;
10167 : : /* The item was validated to be on the outer side */
10168 : : void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10169 : : void *misc_v =
10170 : : MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
10171 : 0 : char *vni_v =
10172 : : MLX5_ADDR_OF(fte_match_set_misc3, misc_v, outer_vxlan_gpe_vni);
10173 : : int i, size = sizeof(vxlan_m->hdr.vni);
10174 : : uint8_t flags_m = 0xff;
10175 : : uint8_t flags_v = 0xc;
10176 : : uint8_t m_protocol, v_protocol;
10177 : :
10178 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
10179 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10180 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
10181 : : 0xFFFF);
10182 : : else
10183 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
10184 : : MLX5_UDP_PORT_VXLAN_GPE);
10185 : : }
10186 [ # # ]: 0 : if (!vxlan_v) {
10187 : : vxlan_v = &dummy_vxlan_gpe_hdr;
10188 : : vxlan_m = &dummy_vxlan_gpe_hdr;
10189 : : } else {
10190 [ # # ]: 0 : if (!vxlan_m)
10191 : : vxlan_m = &rte_flow_item_vxlan_gpe_mask;
10192 : : }
10193 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10194 : : vxlan_v = vxlan_m;
10195 [ # # ]: 0 : else if (key_type == MLX5_SET_MATCHER_HS_V)
10196 : : vxlan_m = vxlan_v;
10197 [ # # ]: 0 : if (vxlan_m->hdr.flags) {
10198 : : flags_m = vxlan_m->hdr.flags;
10199 : 0 : flags_v = vxlan_v->hdr.flags;
10200 : : }
10201 : 0 : m_protocol = vxlan_m->hdr.protocol;
10202 : 0 : v_protocol = vxlan_v->hdr.protocol;
10203 [ # # ]: 0 : if (!m_protocol) {
10204 : : /* Force next protocol to ensure next headers parsing. */
10205 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_NSH)
10206 : : v_protocol = RTE_VXLAN_GPE_TYPE_NSH;
10207 [ # # ]: 0 : else if (pattern_flags & MLX5_FLOW_LAYER_INNER_L2)
10208 : : v_protocol = RTE_VXLAN_GPE_TYPE_ETH;
10209 [ # # ]: 0 : else if (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV4)
10210 : : v_protocol = RTE_VXLAN_GPE_TYPE_IPV4;
10211 [ # # ]: 0 : else if (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV6)
10212 : : v_protocol = RTE_VXLAN_GPE_TYPE_IPV6;
10213 [ # # ]: 0 : if (v_protocol)
10214 : : m_protocol = 0xFF;
10215 : : /* Restore the value to mask in mask case. */
10216 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10217 : : v_protocol = m_protocol;
10218 : : }
10219 : : /*
10220 : : * If only match flags/protocol/vni field, keep using misc3 for matching.
10221 : : * If need to match rsvd0 or rsvd1, using misc5 and do not need using misc3.
10222 : : */
10223 [ # # # # : 0 : if (!(vxlan_m->hdr.rsvd0[0] || vxlan_m->hdr.rsvd0[1] || vxlan_m->hdr.rsvd1)) {
# # ]
10224 [ # # ]: 0 : for (i = 0; i < size; ++i)
10225 : 0 : vni_v[i] = vxlan_m->hdr.vni[i] & vxlan_v->hdr.vni[i];
10226 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc_v, outer_vxlan_gpe_flags,
10227 : : flags_m & flags_v);
10228 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc_v,
10229 : : outer_vxlan_gpe_next_protocol, m_protocol & v_protocol);
10230 : : } else {
10231 : : uint32_t tunnel_v;
10232 : : void *misc5_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_5);
10233 : :
10234 : 0 : tunnel_v = (flags_m & flags_v) << 24 |
10235 : 0 : (vxlan_v->hdr.rsvd0[0] & vxlan_m->hdr.rsvd0[0]) << 16 |
10236 : 0 : (vxlan_v->hdr.rsvd0[1] & vxlan_m->hdr.rsvd0[1]) << 8 |
10237 : 0 : (m_protocol & v_protocol);
10238 [ # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_0, tunnel_v);
10239 : 0 : tunnel_v = (vxlan_v->hdr.vni[0] & vxlan_m->hdr.vni[0]) << 24 |
10240 : 0 : (vxlan_v->hdr.vni[1] & vxlan_m->hdr.vni[1]) << 16 |
10241 : 0 : (vxlan_v->hdr.vni[2] & vxlan_m->hdr.vni[2]) << 8 |
10242 : 0 : (vxlan_v->hdr.rsvd1 & vxlan_m->hdr.rsvd1);
10243 [ # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_1, tunnel_v);
10244 : : }
10245 : 0 : }
10246 : :
10247 : : /**
10248 : : * Add Geneve item to the value.
10249 : : *
10250 : : * @param[in, out] key
10251 : : * Flow matcher value.
10252 : : * @param[in] item
10253 : : * Flow pattern to translate.
10254 : : * @param[in] pattern_flags
10255 : : * Item pattern flags.
10256 : : * @param[in] key_type
10257 : : * Set flow matcher mask or value.
10258 : : */
10259 : :
10260 : : static void
10261 : 0 : flow_dv_translate_item_geneve(void *key, const struct rte_flow_item *item,
10262 : : uint64_t pattern_flags, uint32_t key_type)
10263 : : {
10264 : : static const struct rte_flow_item_geneve empty_geneve = {0,};
10265 : 0 : const struct rte_flow_item_geneve *geneve_m = item->mask;
10266 : 0 : const struct rte_flow_item_geneve *geneve_v = item->spec;
10267 : : /* GENEVE flow item validation allows single tunnel item */
10268 : : void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10269 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10270 : : uint16_t gbhdr_m;
10271 : : uint16_t gbhdr_v;
10272 : 0 : char *vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, geneve_vni);
10273 : : size_t size = sizeof(geneve_m->vni), i;
10274 : : uint16_t protocol_m, protocol_v;
10275 : :
10276 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
10277 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10278 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
10279 : : 0xFFFF);
10280 : : else
10281 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
10282 : : MLX5_UDP_PORT_GENEVE);
10283 : : }
10284 [ # # ]: 0 : if (!geneve_v) {
10285 : : geneve_v = &empty_geneve;
10286 : : geneve_m = &empty_geneve;
10287 : : } else {
10288 [ # # ]: 0 : if (!geneve_m)
10289 : : geneve_m = &rte_flow_item_geneve_mask;
10290 : : }
10291 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10292 : : geneve_v = geneve_m;
10293 [ # # ]: 0 : else if (key_type == MLX5_SET_MATCHER_HS_V)
10294 : : geneve_m = geneve_v;
10295 [ # # ]: 0 : for (i = 0; i < size; ++i)
10296 : 0 : vni_v[i] = geneve_m->vni[i] & geneve_v->vni[i];
10297 [ # # ]: 0 : gbhdr_m = rte_be_to_cpu_16(geneve_m->ver_opt_len_o_c_rsvd0);
10298 [ # # ]: 0 : gbhdr_v = rte_be_to_cpu_16(geneve_v->ver_opt_len_o_c_rsvd0);
10299 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, geneve_oam,
10300 : : MLX5_GENEVE_OAMF_VAL(gbhdr_v) & MLX5_GENEVE_OAMF_VAL(gbhdr_m));
10301 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
10302 : : MLX5_GENEVE_OPTLEN_VAL(gbhdr_v) &
10303 : : MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
10304 [ # # ]: 0 : protocol_m = rte_be_to_cpu_16(geneve_m->protocol);
10305 [ # # ]: 0 : protocol_v = rte_be_to_cpu_16(geneve_v->protocol);
10306 [ # # ]: 0 : if (!protocol_m) {
10307 : : /* Force next protocol to prevent matchers duplication */
10308 : : protocol_v = mlx5_translate_tunnel_etypes(pattern_flags);
10309 : : if (protocol_v)
10310 : : protocol_m = 0xFFFF;
10311 : : /* Restore the value to mask in mask case. */
10312 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10313 : : protocol_v = protocol_m;
10314 : : }
10315 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, geneve_protocol_type,
10316 : : protocol_m & protocol_v);
10317 : 0 : }
10318 : :
10319 : : /**
10320 : : * Create Geneve TLV option resource.
10321 : : *
10322 : : * @param[in, out] dev
10323 : : * Pointer to rte_eth_dev structure.
10324 : : * @param[in] item
10325 : : * Flow pattern to translate.
10326 : : * @param[out] error
10327 : : * pointer to error structure.
10328 : : *
10329 : : * @return
10330 : : * 0 on success otherwise -errno and errno is set.
10331 : : */
10332 : : static int
10333 : 0 : flow_dev_geneve_tlv_option_resource_register(struct rte_eth_dev *dev,
10334 : : const struct rte_flow_item *item,
10335 : : struct rte_flow_error *error)
10336 : : {
10337 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10338 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
10339 : 0 : struct mlx5_geneve_tlv_option_resource *geneve_opt_resource =
10340 : : sh->geneve_tlv_option_resource;
10341 : : struct mlx5_devx_obj *obj;
10342 : 0 : const struct rte_flow_item_geneve_opt *geneve_opt_v = item->spec;
10343 : : int ret = 0;
10344 : :
10345 : : MLX5_ASSERT(sh->config.dv_flow_en == 1);
10346 [ # # ]: 0 : if (!geneve_opt_v)
10347 : : return -1;
10348 : 0 : rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
10349 [ # # ]: 0 : if (geneve_opt_resource != NULL) {
10350 : 0 : if (geneve_opt_resource->option_class ==
10351 : : geneve_opt_v->option_class &&
10352 : : geneve_opt_resource->option_type ==
10353 [ # # ]: 0 : geneve_opt_v->option_type &&
10354 : : geneve_opt_resource->length ==
10355 : : geneve_opt_v->option_len) {
10356 : 0 : rte_atomic_fetch_add_explicit(&geneve_opt_resource->refcnt, 1,
10357 : : rte_memory_order_relaxed);
10358 : : } else {
10359 : 0 : ret = rte_flow_error_set(error, ENOMEM,
10360 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10361 : : "Only one GENEVE TLV option supported");
10362 : 0 : goto exit;
10363 : : }
10364 : : } else {
10365 : 0 : struct mlx5_devx_geneve_tlv_option_attr attr = {
10366 : 0 : .option_class = geneve_opt_v->option_class,
10367 : 0 : .option_type = geneve_opt_v->option_type,
10368 : 0 : .option_data_len = geneve_opt_v->option_len,
10369 : : };
10370 : :
10371 : : /* Create a GENEVE TLV object and resource. */
10372 : 0 : obj = mlx5_devx_cmd_create_geneve_tlv_option(sh->cdev->ctx,
10373 : : &attr);
10374 [ # # ]: 0 : if (!obj) {
10375 : 0 : ret = rte_flow_error_set(error, ENODATA,
10376 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10377 : : "Failed to create GENEVE TLV Devx object");
10378 : 0 : goto exit;
10379 : : }
10380 : 0 : sh->geneve_tlv_option_resource =
10381 : 0 : mlx5_malloc(MLX5_MEM_ZERO,
10382 : : sizeof(*geneve_opt_resource),
10383 : : 0, SOCKET_ID_ANY);
10384 [ # # ]: 0 : if (!sh->geneve_tlv_option_resource) {
10385 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
10386 : 0 : ret = rte_flow_error_set(error, ENOMEM,
10387 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10388 : : "GENEVE TLV object memory allocation failed");
10389 : 0 : goto exit;
10390 : : }
10391 : : geneve_opt_resource = sh->geneve_tlv_option_resource;
10392 : 0 : geneve_opt_resource->obj = obj;
10393 : 0 : geneve_opt_resource->option_class = geneve_opt_v->option_class;
10394 : 0 : geneve_opt_resource->option_type = geneve_opt_v->option_type;
10395 : 0 : geneve_opt_resource->length = geneve_opt_v->option_len;
10396 : 0 : rte_atomic_store_explicit(&geneve_opt_resource->refcnt, 1,
10397 : : rte_memory_order_relaxed);
10398 : : }
10399 : 0 : exit:
10400 : : rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
10401 : 0 : return ret;
10402 : : }
10403 : :
10404 : : /**
10405 : : * Add Geneve TLV option item to value.
10406 : : *
10407 : : * @param[in, out] dev
10408 : : * Pointer to rte_eth_dev structure.
10409 : : * @param[in, out] key
10410 : : * Flow matcher value.
10411 : : * @param[in] item
10412 : : * Flow pattern to translate.
10413 : : * @param[in] key_type
10414 : : * Set flow matcher mask or value.
10415 : : * @param[out] error
10416 : : * Pointer to error structure.
10417 : : */
10418 : : static int
10419 : 0 : flow_dv_translate_item_geneve_opt(struct rte_eth_dev *dev, void *key,
10420 : : const struct rte_flow_item *item,
10421 : : uint32_t key_type,
10422 : : struct rte_flow_error *error)
10423 : : {
10424 : : const struct rte_flow_item_geneve_opt *geneve_opt_m;
10425 : : const struct rte_flow_item_geneve_opt *geneve_opt_v;
10426 : 0 : const struct rte_flow_item_geneve_opt *orig_spec = item->spec;
10427 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
10428 : 0 : rte_be32_t opt_data_key = 0, opt_data_mask = 0;
10429 : : size_t option_byte_len;
10430 : : int ret = 0;
10431 : :
10432 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type) || !orig_spec)
# # # # #
# # # ]
10433 : : return -1;
10434 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, geneve_opt_v, geneve_opt_m,
# # # # ]
10435 : : &rte_flow_item_geneve_opt_mask);
10436 : : /*
10437 : : * Register resource requires item spec for SW steering,
10438 : : * for HW steering resources is registered explicitly by user.
10439 : : */
10440 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_SW_V) {
10441 : 0 : ret = flow_dev_geneve_tlv_option_resource_register(dev, item,
10442 : : error);
10443 [ # # ]: 0 : if (ret) {
10444 : 0 : DRV_LOG(ERR, "Failed to create geneve_tlv_obj");
10445 : 0 : return ret;
10446 : : }
10447 : : }
10448 : : /* Convert the option length from DW to bytes for using memcpy. */
10449 : 0 : option_byte_len = RTE_MIN((size_t)(orig_spec->option_len * 4),
10450 : : sizeof(rte_be32_t));
10451 [ # # ]: 0 : if (geneve_opt_v->data) {
10452 : : memcpy(&opt_data_key, geneve_opt_v->data, option_byte_len);
10453 : 0 : memcpy(&opt_data_mask, geneve_opt_m->data, option_byte_len);
10454 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v,
10455 : : geneve_tlv_option_0_data,
10456 : : rte_be_to_cpu_32(opt_data_key & opt_data_mask));
10457 : : }
10458 : : return ret;
10459 : : }
10460 : :
10461 : : /**
10462 : : * Add MPLS item to the value.
10463 : : *
10464 : : * @param[in, out] key
10465 : : * Flow matcher value.
10466 : : * @param[in] item
10467 : : * Flow pattern to translate.
10468 : : * @param[in] prev_layer
10469 : : * The protocol layer indicated in previous item.
10470 : : * @param[in] inner
10471 : : * Item is inner pattern.
10472 : : * @param[in] key_type
10473 : : * Set flow matcher mask or value.
10474 : : */
10475 : : static void
10476 : 0 : flow_dv_translate_item_mpls(void *key, const struct rte_flow_item *item,
10477 : : uint64_t prev_layer, int inner,
10478 : : uint32_t key_type)
10479 : : {
10480 : : const uint32_t *in_mpls_m;
10481 : : const uint32_t *in_mpls_v;
10482 : : uint32_t *out_mpls_v = 0;
10483 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10484 : 0 : void *misc2_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
10485 : : void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10486 : :
10487 [ # # # ]: 0 : switch (prev_layer) {
10488 : 0 : case MLX5_FLOW_LAYER_OUTER_L4_UDP:
10489 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
10490 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10491 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
10492 : : udp_dport, 0xffff);
10493 : : else
10494 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
10495 : : udp_dport, MLX5_UDP_PORT_MPLS);
10496 : : }
10497 : : break;
10498 : 0 : case MLX5_FLOW_LAYER_GRE:
10499 : : /* Fall-through. */
10500 : : case MLX5_FLOW_LAYER_GRE_KEY:
10501 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_misc, misc_v, gre_protocol)) {
10502 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10503 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v,
10504 : : gre_protocol, 0xffff);
10505 : : else
10506 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v,
10507 : : gre_protocol, RTE_ETHER_TYPE_MPLS);
10508 : : }
10509 : : break;
10510 : : default:
10511 : : break;
10512 : : }
10513 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10514 : : return;
10515 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, in_mpls_v, in_mpls_m,
# # # # ]
10516 : : &rte_flow_item_mpls_mask);
10517 [ # # # ]: 0 : switch (prev_layer) {
10518 : 0 : case MLX5_FLOW_LAYER_OUTER_L4_UDP:
10519 : 0 : out_mpls_v =
10520 : : (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
10521 : : outer_first_mpls_over_udp);
10522 : 0 : break;
10523 : 0 : case MLX5_FLOW_LAYER_GRE:
10524 : 0 : out_mpls_v =
10525 : : (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
10526 : : outer_first_mpls_over_gre);
10527 : 0 : break;
10528 : 0 : default:
10529 : : /* Inner MPLS not over GRE is not supported. */
10530 [ # # ]: 0 : if (!inner)
10531 : : out_mpls_v =
10532 : : (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
10533 : : misc2_v,
10534 : : outer_first_mpls);
10535 : : break;
10536 : : }
10537 : : if (out_mpls_v)
10538 : 0 : *out_mpls_v = *in_mpls_v & *in_mpls_m;
10539 : : }
10540 : :
10541 : : /**
10542 : : * Add metadata register item to matcher
10543 : : *
10544 : : * @param[in, out] key
10545 : : * Flow matcher value.
10546 : : * @param[in] reg_type
10547 : : * Type of device metadata register
10548 : : * @param[in] data
10549 : : * Register data
10550 : : * @param[in] mask
10551 : : * Register mask
10552 : : */
10553 : : static void
10554 : 0 : flow_dv_match_meta_reg(void *key, enum modify_reg reg_type,
10555 : : uint32_t data, uint32_t mask)
10556 : : {
10557 : : void *misc2_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
10558 : : void *misc5_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_5);
10559 : : uint32_t temp;
10560 : :
10561 [ # # ]: 0 : if (!key)
10562 : : return;
10563 : 0 : data &= mask;
10564 [ # # # # : 0 : switch (reg_type) {
# # # # #
# # # # #
# ]
10565 : 0 : case REG_A:
10566 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_a, data);
10567 : 0 : break;
10568 : 0 : case REG_B:
10569 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_b, data);
10570 : 0 : break;
10571 : 0 : case REG_C_0:
10572 : : /*
10573 : : * The metadata register C0 field might be divided into
10574 : : * source vport index and META item value, we should set
10575 : : * this field according to specified mask, not as whole one.
10576 : : */
10577 [ # # ]: 0 : temp = MLX5_GET(fte_match_set_misc2, misc2_v, metadata_reg_c_0);
10578 [ # # ]: 0 : if (mask)
10579 : 0 : temp &= ~mask;
10580 : 0 : temp |= data;
10581 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_0, temp);
10582 : 0 : break;
10583 : 0 : case REG_C_1:
10584 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_1, data);
10585 : 0 : break;
10586 : 0 : case REG_C_2:
10587 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_2, data);
10588 : 0 : break;
10589 : 0 : case REG_C_3:
10590 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_3, data);
10591 : 0 : break;
10592 : 0 : case REG_C_4:
10593 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_4, data);
10594 : 0 : break;
10595 : 0 : case REG_C_5:
10596 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_5, data);
10597 : 0 : break;
10598 : 0 : case REG_C_6:
10599 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_6, data);
10600 : 0 : break;
10601 : 0 : case REG_C_7:
10602 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_7, data);
10603 : 0 : break;
10604 : 0 : case REG_C_8:
10605 [ # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, metadata_reg_c_8, data);
10606 : 0 : break;
10607 : 0 : case REG_C_9:
10608 [ # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, metadata_reg_c_9, data);
10609 : 0 : break;
10610 : 0 : case REG_C_10:
10611 [ # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, metadata_reg_c_10, data);
10612 : 0 : break;
10613 : 0 : case REG_C_11:
10614 [ # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, metadata_reg_c_11, data);
10615 : 0 : break;
10616 : : default:
10617 : : MLX5_ASSERT(false);
10618 : : break;
10619 : : }
10620 : : }
10621 : :
10622 : : /**
10623 : : * Add metadata register item to matcher
10624 : : *
10625 : : * @param[in, out] matcher
10626 : : * Flow matcher.
10627 : : * @param[in, out] key
10628 : : * Flow matcher value.
10629 : : * @param[in] reg_type
10630 : : * Type of device metadata register
10631 : : * @param[in] value
10632 : : * Register value
10633 : : * @param[in] mask
10634 : : * Register mask
10635 : : */
10636 : : static void
10637 : : flow_dv_match_meta_reg_all(void *matcher, void *key, enum modify_reg reg_type,
10638 : : uint32_t data, uint32_t mask)
10639 : : {
10640 : 0 : flow_dv_match_meta_reg(key, reg_type, data, mask);
10641 : 0 : flow_dv_match_meta_reg(matcher, reg_type, mask, mask);
10642 : : }
10643 : :
10644 : : /**
10645 : : * Add MARK item to matcher
10646 : : *
10647 : : * @param[in] dev
10648 : : * The device to configure through.
10649 : : * @param[in, out] key
10650 : : * Flow matcher value.
10651 : : * @param[in] item
10652 : : * Flow pattern to translate.
10653 : : * @param[in] key_type
10654 : : * Set flow matcher mask or value.
10655 : : */
10656 : : static void
10657 : 0 : flow_dv_translate_item_mark(struct rte_eth_dev *dev, void *key,
10658 : : const struct rte_flow_item *item,
10659 : : uint32_t key_type)
10660 : : {
10661 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10662 : : const struct rte_flow_item_mark *mark;
10663 : : uint32_t value;
10664 : : uint32_t mask = 0;
10665 : :
10666 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_SW) {
10667 [ # # ]: 0 : mark = item->mask ? (const void *)item->mask :
10668 : : &rte_flow_item_mark_mask;
10669 : 0 : mask = mark->id;
10670 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M) {
10671 : : value = mask;
10672 : : } else {
10673 : 0 : mark = (const void *)item->spec;
10674 : : MLX5_ASSERT(mark);
10675 : 0 : value = mark->id;
10676 : : }
10677 : : } else {
10678 [ # # ]: 0 : mark = (key_type == MLX5_SET_MATCHER_HS_V) ?
10679 : : (const void *)item->spec : (const void *)item->mask;
10680 : : MLX5_ASSERT(mark);
10681 : 0 : value = mark->id;
10682 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_HS_M)
10683 : : mask = value;
10684 : : }
10685 : 0 : mask &= priv->sh->dv_mark_mask;
10686 : 0 : value &= mask;
10687 [ # # ]: 0 : if (mask) {
10688 : : enum modify_reg reg;
10689 : :
10690 : : /* Get the metadata register index for the mark. */
10691 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, NULL);
10692 : : MLX5_ASSERT(reg > 0);
10693 [ # # ]: 0 : if (reg == REG_C_0) {
10694 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10695 : 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
10696 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
10697 : :
10698 : 0 : mask &= msk_c0;
10699 : 0 : mask <<= shl_c0;
10700 : 0 : value <<= shl_c0;
10701 : : }
10702 : 0 : flow_dv_match_meta_reg(key, reg, value, mask);
10703 : : }
10704 : 0 : }
10705 : :
10706 : : /**
10707 : : * Add META item to matcher
10708 : : *
10709 : : * @param[in] dev
10710 : : * The devich to configure through.
10711 : : * @param[in, out] key
10712 : : * Flow matcher value.
10713 : : * @param[in] attr
10714 : : * Attributes of flow that includes this item.
10715 : : * @param[in] item
10716 : : * Flow pattern to translate.
10717 : : * @param[in] key_type
10718 : : * Set flow matcher mask or value.
10719 : : */
10720 : : static void
10721 : 0 : flow_dv_translate_item_meta(struct rte_eth_dev *dev,
10722 : : void *key,
10723 : : const struct rte_flow_attr *attr,
10724 : : const struct rte_flow_item *item,
10725 : : uint32_t key_type)
10726 : : {
10727 : : const struct rte_flow_item_meta *meta_m;
10728 : : const struct rte_flow_item_meta *meta_v;
10729 : : uint32_t value;
10730 : : uint32_t mask = 0;
10731 : : int reg;
10732 : :
10733 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10734 : : return;
10735 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, meta_v, meta_m,
# # # # ]
10736 : : &rte_flow_item_meta_mask);
10737 : 0 : value = meta_v->data;
10738 : 0 : mask = meta_m->data;
10739 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_HS_M)
10740 : : mask = value;
10741 : : /*
10742 : : * In the current implementation, REG_B cannot be used to match.
10743 : : * Force to use REG_C_1 in HWS root table as other tables.
10744 : : * This map may change.
10745 : : * NIC: modify - REG_B to be present in SW
10746 : : * match - REG_C_1 when copied from FDB, different from SWS
10747 : : * FDB: modify - REG_C_1 in Xmeta mode, REG_NON in legacy mode
10748 : : * match - REG_C_1 in FDB
10749 : : */
10750 [ # # ]: 0 : if (!!(key_type & MLX5_SET_MATCHER_SW))
10751 : 0 : reg = flow_dv_get_metadata_reg(dev, attr, NULL);
10752 : : else
10753 : : reg = flow_hw_get_reg_id(dev, RTE_FLOW_ITEM_TYPE_META, 0);
10754 [ # # ]: 0 : if (reg < 0)
10755 : : return;
10756 : : MLX5_ASSERT(reg != REG_NON);
10757 [ # # ]: 0 : if (reg == REG_C_0) {
10758 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10759 : 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
10760 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
10761 : :
10762 : 0 : mask &= msk_c0;
10763 : 0 : mask <<= shl_c0;
10764 : 0 : value <<= shl_c0;
10765 : : }
10766 : 0 : flow_dv_match_meta_reg(key, reg, value, mask);
10767 : : }
10768 : :
10769 : : /**
10770 : : * Add vport metadata Reg C0 item to matcher
10771 : : *
10772 : : * @param[in, out] key
10773 : : * Flow matcher value.
10774 : : * @param[in] value
10775 : : * Register value
10776 : : * @param[in] mask
10777 : : * Register mask
10778 : : */
10779 : : static void
10780 : : flow_dv_translate_item_meta_vport(void *key, uint32_t value, uint32_t mask)
10781 : : {
10782 : 0 : flow_dv_match_meta_reg(key, REG_C_0, value, mask);
10783 : 0 : }
10784 : :
10785 : : /**
10786 : : * Add tag item to matcher
10787 : : *
10788 : : * @param[in] dev
10789 : : * The devich to configure through.
10790 : : * @param[in, out] key
10791 : : * Flow matcher value.
10792 : : * @param[in] item
10793 : : * Flow pattern to translate.
10794 : : * @param[in] key_type
10795 : : * Set flow matcher mask or value.
10796 : : */
10797 : : static void
10798 : 0 : flow_dv_translate_mlx5_item_tag(struct rte_eth_dev *dev, void *key,
10799 : : const struct rte_flow_item *item,
10800 : : uint32_t key_type)
10801 : : {
10802 : 0 : const struct mlx5_rte_flow_item_tag *tag_v = item->spec;
10803 : 0 : const struct mlx5_rte_flow_item_tag *tag_m = item->mask;
10804 : : uint32_t mask, value;
10805 : :
10806 : : MLX5_ASSERT(tag_v);
10807 : 0 : value = tag_v->data;
10808 [ # # ]: 0 : mask = tag_m ? tag_m->data : UINT32_MAX;
10809 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10810 : : value = mask;
10811 [ # # ]: 0 : if (tag_v->id == REG_C_0) {
10812 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10813 : 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
10814 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
10815 : :
10816 : 0 : mask &= msk_c0;
10817 : 0 : mask <<= shl_c0;
10818 : 0 : value <<= shl_c0;
10819 : : }
10820 : 0 : flow_dv_match_meta_reg(key, tag_v->id, value, mask);
10821 : 0 : }
10822 : :
10823 : : /**
10824 : : * Add TAG item to matcher
10825 : : *
10826 : : * @param[in] dev
10827 : : * The devich to configure through.
10828 : : * @param[in, out] key
10829 : : * Flow matcher value.
10830 : : * @param[in] item
10831 : : * Flow pattern to translate.
10832 : : * @param[in] key_type
10833 : : * Set flow matcher mask or value.
10834 : : *
10835 : : * @return
10836 : : * 0 on success. Negative errno value otherwise.
10837 : : */
10838 : : static int
10839 : 0 : flow_dv_translate_item_tag(struct rte_eth_dev *dev, void *key,
10840 : : const struct rte_flow_item *item,
10841 : : uint32_t key_type)
10842 : : {
10843 : 0 : const struct rte_flow_item_tag *tag_vv = item->spec;
10844 : : const struct rte_flow_item_tag *tag_v;
10845 : : const struct rte_flow_item_tag *tag_m;
10846 : : int reg;
10847 : : uint32_t index;
10848 : :
10849 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10850 : : return 0;
10851 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, tag_v, tag_m,
# # # # ]
10852 : : &rte_flow_item_tag_mask);
10853 : : /* When set mask, the index should be from spec. */
10854 [ # # ]: 0 : index = tag_vv ? tag_vv->index : tag_v->index;
10855 : : /* Get the metadata register index for the tag. */
10856 [ # # ]: 0 : if (!!(key_type & MLX5_SET_MATCHER_SW))
10857 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, index, NULL);
10858 : : else
10859 : : reg = flow_hw_get_reg_id(dev, RTE_FLOW_ITEM_TYPE_TAG, index);
10860 [ # # ]: 0 : if (reg < 0) {
10861 : 0 : DRV_LOG(ERR, "port %u tag index %u does not map to correct register",
10862 : : dev->data->port_id, index);
10863 : 0 : return -EINVAL;
10864 : : }
10865 [ # # ]: 0 : if (reg == REG_NON) {
10866 : 0 : DRV_LOG(ERR, "port %u tag index %u maps to unsupported register",
10867 : : dev->data->port_id, index);
10868 : 0 : return -ENOTSUP;
10869 : : }
10870 : 0 : flow_dv_match_meta_reg(key, (enum modify_reg)reg, tag_v->data, tag_m->data);
10871 : 0 : return 0;
10872 : : }
10873 : :
10874 : : /**
10875 : : * Add source vport match to the specified matcher.
10876 : : *
10877 : : * @param[in, out] key
10878 : : * Flow matcher value.
10879 : : * @param[in] port
10880 : : * Source vport value to match
10881 : : */
10882 : : static void
10883 : : flow_dv_translate_item_source_vport(void *key,
10884 : : int16_t port)
10885 : : {
10886 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10887 : :
10888 [ # # # # : 0 : MLX5_SET(fte_match_set_misc, misc_v, source_port, port);
# # ]
10889 : 0 : }
10890 : :
10891 : : /**
10892 : : * Translate port-id item to eswitch match on port-id.
10893 : : *
10894 : : * @param[in] dev
10895 : : * The devich to configure through.
10896 : : * @param[in, out] key
10897 : : * Flow matcher value.
10898 : : * @param[in] item
10899 : : * Flow pattern to translate.
10900 : : * @param[in] attr
10901 : : * Flow attributes.
10902 : : * @param[in] key_type
10903 : : * Set flow matcher mask or value.
10904 : : *
10905 : : * @return
10906 : : * 0 on success, a negative errno value otherwise.
10907 : : */
10908 : : static int
10909 : 0 : flow_dv_translate_item_port_id(struct rte_eth_dev *dev, void *key,
10910 : : const struct rte_flow_item *item,
10911 : : const struct rte_flow_attr *attr,
10912 : : uint32_t key_type)
10913 : : {
10914 [ # # ]: 0 : const struct rte_flow_item_port_id *pid_m = item ? item->mask : NULL;
10915 [ # # ]: 0 : const struct rte_flow_item_port_id *pid_v = item ? item->spec : NULL;
10916 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
10917 : : struct mlx5_priv *priv;
10918 : : uint16_t mask, id;
10919 : : uint32_t vport_meta;
10920 : :
10921 : : MLX5_ASSERT(wks);
10922 [ # # # # ]: 0 : if (pid_v && pid_v->id == MLX5_PORT_ESW_MGR) {
10923 : 0 : priv = dev->data->dev_private;
10924 [ # # ]: 0 : if (priv->sh->dev_cap.esw_info.regc_mask) {
10925 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
10926 : : vport_meta = priv->sh->dev_cap.esw_info.regc_mask;
10927 : : } else {
10928 : 0 : vport_meta = priv->sh->dev_cap.esw_info.regc_value;
10929 : 0 : wks->vport_meta_tag = vport_meta;
10930 : : }
10931 : : flow_dv_translate_item_meta_vport(key, vport_meta,
10932 : : priv->sh->dev_cap.esw_info.regc_mask);
10933 : : } else {
10934 : 0 : flow_dv_translate_item_source_vport(key,
10935 [ # # ]: 0 : key_type & MLX5_SET_MATCHER_V ?
10936 : 0 : mlx5_flow_get_esw_manager_vport_id(dev) : 0xffff);
10937 : : }
10938 : 0 : return 0;
10939 : : }
10940 [ # # ]: 0 : mask = pid_m ? pid_m->id : 0xffff;
10941 [ # # ]: 0 : id = pid_v ? pid_v->id : dev->data->port_id;
10942 : 0 : priv = mlx5_port_to_eswitch_info(id, item == NULL);
10943 [ # # ]: 0 : if (!priv)
10944 : 0 : return -rte_errno;
10945 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
10946 : : id = mask;
10947 : 0 : vport_meta = priv->vport_meta_mask;
10948 : : } else {
10949 : 0 : id = priv->vport_id;
10950 : 0 : vport_meta = priv->vport_meta_tag;
10951 : 0 : wks->vport_meta_tag = vport_meta;
10952 : : }
10953 : : /*
10954 : : * Translate to vport field or to metadata, depending on mode.
10955 : : * Kernel can use either misc.source_port or half of C0 metadata
10956 : : * register.
10957 : : */
10958 [ # # ]: 0 : if (priv->vport_meta_mask) {
10959 : : /*
10960 : : * Provide the hint for SW steering library
10961 : : * to insert the flow into ingress domain and
10962 : : * save the extra vport match.
10963 : : */
10964 [ # # # # ]: 0 : if (mask == 0xffff && priv->vport_id == 0xffff &&
10965 [ # # # # ]: 0 : priv->pf_bond < 0 && attr->transfer)
10966 [ # # ]: 0 : flow_dv_translate_item_source_vport(key, id);
10967 : : /*
10968 : : * We should always set the vport metadata register,
10969 : : * otherwise the SW steering library can drop
10970 : : * the rule if wire vport metadata value is not zero,
10971 : : * it depends on kernel configuration.
10972 : : */
10973 : 0 : flow_dv_translate_item_meta_vport
10974 : : (key, vport_meta, priv->vport_meta_mask);
10975 : : } else {
10976 [ # # ]: 0 : flow_dv_translate_item_source_vport(key, id);
10977 : : }
10978 : : return 0;
10979 : : }
10980 : :
10981 : : /**
10982 : : * Translate port representor item to eswitch match on port id.
10983 : : *
10984 : : * @param[in] dev
10985 : : * The devich to configure through.
10986 : : * @param[in, out] key
10987 : : * Flow matcher value.
10988 : : * @param[in] key_type
10989 : : * Set flow matcher mask or value.
10990 : : *
10991 : : * @return
10992 : : * 0 on success, a negative errno value otherwise.
10993 : : */
10994 : : static int
10995 : 0 : flow_dv_translate_item_port_representor(struct rte_eth_dev *dev, void *key,
10996 : : uint32_t key_type)
10997 : : {
10998 : 0 : flow_dv_translate_item_source_vport(key,
10999 [ # # ]: 0 : key_type & MLX5_SET_MATCHER_V ?
11000 : 0 : mlx5_flow_get_esw_manager_vport_id(dev) : 0xffff);
11001 : 0 : return 0;
11002 : : }
11003 : :
11004 : : /**
11005 : : * Translate represented port item to eswitch match on port id.
11006 : : *
11007 : : * @param[in] dev
11008 : : * The devich to configure through.
11009 : : * @param[in, out] key
11010 : : * Flow matcher value.
11011 : : * @param[in] item
11012 : : * Flow pattern to translate.
11013 : : * @param[in]
11014 : : * Flow attributes.
11015 : : *
11016 : : * @return
11017 : : * 0 on success, a negative errno value otherwise.
11018 : : */
11019 : : static int
11020 : 0 : flow_dv_translate_item_represented_port(struct rte_eth_dev *dev, void *key,
11021 : : const struct rte_flow_item *item,
11022 : : const struct rte_flow_attr *attr,
11023 : : uint32_t key_type)
11024 : : {
11025 [ # # ]: 0 : const struct rte_flow_item_ethdev *pid_m = item ? item->mask : NULL;
11026 [ # # ]: 0 : const struct rte_flow_item_ethdev *pid_v = item ? item->spec : NULL;
11027 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
11028 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11029 : : uint16_t mask, id;
11030 : : uint32_t vport_meta;
11031 : : bool vport_match = false;
11032 : :
11033 : : MLX5_ASSERT(wks);
11034 : : #ifndef HAVE_IBV_DEVICE_ATTR_ESW_MGR_REG_C0
11035 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
11036 : : vport_match = true;
11037 : : #endif
11038 [ # # ]: 0 : if (!pid_m && !pid_v)
11039 : : return 0;
11040 [ # # # # ]: 0 : if (pid_v && pid_v->port_id == UINT16_MAX) {
11041 [ # # # # ]: 0 : if (priv->sh->config.dv_flow_en != 2 || vport_match) {
11042 : 0 : flow_dv_translate_item_source_vport
11043 [ # # ]: 0 : (key, key_type & MLX5_SET_MATCHER_V ?
11044 : 0 : mlx5_flow_get_esw_manager_vport_id(dev) : 0xffff);
11045 : : } else {
11046 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11047 : 0 : vport_meta = priv->sh->dev_cap.esw_info.regc_mask;
11048 : : else
11049 : 0 : vport_meta = priv->sh->dev_cap.esw_info.regc_value;
11050 : 0 : flow_dv_translate_item_meta_vport(key, vport_meta,
11051 : : priv->sh->dev_cap.esw_info.regc_mask);
11052 : : }
11053 : 0 : return 0;
11054 : : }
11055 [ # # ]: 0 : mask = pid_m ? pid_m->port_id : UINT16_MAX;
11056 [ # # ]: 0 : id = pid_v ? pid_v->port_id : dev->data->port_id;
11057 : 0 : priv = mlx5_port_to_eswitch_info(id, item == NULL);
11058 [ # # ]: 0 : if (!priv)
11059 : 0 : return -rte_errno;
11060 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
11061 : : id = mask;
11062 : 0 : vport_meta = priv->vport_meta_mask;
11063 : : } else {
11064 : 0 : id = priv->vport_id;
11065 : 0 : vport_meta = priv->vport_meta_tag;
11066 : 0 : wks->vport_meta_tag = vport_meta;
11067 : : }
11068 : : /*
11069 : : * Translate to vport field or to metadata, depending on mode.
11070 : : * Kernel can use either misc.source_port or half of C0 metadata
11071 : : * register.
11072 : : */
11073 [ # # # # ]: 0 : if (priv->vport_meta_mask && !vport_match) {
11074 : : /*
11075 : : * Provide the hint for SW steering library
11076 : : * to insert the flow into ingress domain and
11077 : : * save the extra vport match.
11078 : : */
11079 [ # # # # ]: 0 : if (mask == UINT16_MAX && priv->vport_id == UINT16_MAX &&
11080 [ # # # # ]: 0 : priv->pf_bond < 0 && attr->transfer &&
11081 [ # # ]: 0 : priv->sh->config.dv_flow_en != 2)
11082 [ # # ]: 0 : flow_dv_translate_item_source_vport(key, id);
11083 : : /*
11084 : : * We should always set the vport metadata register,
11085 : : * otherwise the SW steering library can drop
11086 : : * the rule if wire vport metadata value is not zero,
11087 : : * it depends on kernel configuration.
11088 : : */
11089 : 0 : flow_dv_translate_item_meta_vport(key, vport_meta,
11090 : : priv->vport_meta_mask);
11091 : : } else {
11092 [ # # ]: 0 : flow_dv_translate_item_source_vport(key, id);
11093 : : }
11094 : : return 0;
11095 : : }
11096 : :
11097 : : /**
11098 : : * Translate port-id item to eswitch match on port-id.
11099 : : *
11100 : : * @param[in] dev
11101 : : * The devich to configure through.
11102 : : * @param[in, out] matcher
11103 : : * Flow matcher.
11104 : : * @param[in, out] key
11105 : : * Flow matcher value.
11106 : : * @param[in] item
11107 : : * Flow pattern to translate.
11108 : : * @param[in] attr
11109 : : * Flow attributes.
11110 : : *
11111 : : * @return
11112 : : * 0 on success, a negative errno value otherwise.
11113 : : */
11114 : : static int
11115 : 0 : flow_dv_translate_item_port_id_all(struct rte_eth_dev *dev,
11116 : : void *matcher, void *key,
11117 : : const struct rte_flow_item *item,
11118 : : const struct rte_flow_attr *attr)
11119 : : {
11120 : : int ret;
11121 : :
11122 : 0 : ret = flow_dv_translate_item_port_id
11123 : : (dev, matcher, item, attr, MLX5_SET_MATCHER_SW_M);
11124 [ # # ]: 0 : if (ret)
11125 : : return ret;
11126 : 0 : ret = flow_dv_translate_item_port_id
11127 : : (dev, key, item, attr, MLX5_SET_MATCHER_SW_V);
11128 : 0 : return ret;
11129 : : }
11130 : :
11131 : :
11132 : : /**
11133 : : * Add ICMP6 item to the value.
11134 : : *
11135 : : * @param[in, out] key
11136 : : * Flow matcher value.
11137 : : * @param[in] item
11138 : : * Flow pattern to translate.
11139 : : * @param[in] inner
11140 : : * Item is inner pattern.
11141 : : * @param[in] key_type
11142 : : * Set flow matcher mask or value.
11143 : : */
11144 : : static void
11145 : 0 : flow_dv_translate_item_icmp6(void *key, const struct rte_flow_item *item,
11146 : : int inner, uint32_t key_type)
11147 : : {
11148 : : const struct rte_flow_item_icmp6 *icmp6_m;
11149 : : const struct rte_flow_item_icmp6 *icmp6_v;
11150 : : void *headers_v;
11151 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
11152 : :
11153 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
11154 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11155 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11156 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, 0xFF);
11157 : : else
11158 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
11159 : : IPPROTO_ICMPV6);
11160 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11161 : : return;
11162 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, icmp6_v, icmp6_m,
# # # # ]
11163 : : &rte_flow_item_icmp6_mask);
11164 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type,
11165 : : icmp6_v->type & icmp6_m->type);
11166 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code,
11167 : : icmp6_v->code & icmp6_m->code);
11168 : : }
11169 : :
11170 : : /**
11171 : : * Add ICMP6 echo request/reply item to the value.
11172 : : *
11173 : : * @param[in, out] key
11174 : : * Flow matcher value.
11175 : : * @param[in] item
11176 : : * Flow pattern to translate.
11177 : : * @param[in] inner
11178 : : * Item is inner pattern.
11179 : : * @param[in] key_type
11180 : : * Set flow matcher mask or value.
11181 : : */
11182 : : static void
11183 [ # # ]: 0 : flow_dv_translate_item_icmp6_echo(void *key, const struct rte_flow_item *item,
11184 : : int inner, uint32_t key_type)
11185 : : {
11186 : : const struct rte_flow_item_icmp6_echo *icmp6_m;
11187 : : const struct rte_flow_item_icmp6_echo *icmp6_v;
11188 : : uint32_t icmp6_header_data_m = 0;
11189 : : uint32_t icmp6_header_data_v = 0;
11190 : : void *headers_v;
11191 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
11192 : : uint8_t icmp6_type = 0;
11193 : : struct rte_flow_item_icmp6_echo zero_mask;
11194 : :
11195 : : memset(&zero_mask, 0, sizeof(zero_mask));
11196 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
11197 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11198 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11199 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, 0xFF);
11200 : : else
11201 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
11202 : : IPPROTO_ICMPV6);
11203 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, icmp6_v, icmp6_m, &zero_mask);
# # # # ]
11204 : : /* Set fixed type and code for icmpv6 echo request or reply */
11205 [ # # ]: 0 : icmp6_type = (item->type == RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REQUEST ?
11206 : : RTE_ICMP6_ECHO_REQUEST : RTE_ICMP6_ECHO_REPLY);
11207 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
11208 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type, 0xFF);
11209 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code, 0xFF);
11210 : : } else {
11211 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type, icmp6_type);
11212 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code, 0);
11213 : : }
11214 [ # # ]: 0 : if (icmp6_v == NULL)
11215 : 0 : return;
11216 : : /* Set icmp6 header data (identifier & sequence) accordingly */
11217 : 0 : icmp6_header_data_m =
11218 [ # # ]: 0 : (rte_be_to_cpu_16(icmp6_m->hdr.identifier) << 16) |
11219 [ # # ]: 0 : rte_be_to_cpu_16(icmp6_m->hdr.sequence);
11220 [ # # ]: 0 : if (icmp6_header_data_m) {
11221 : 0 : icmp6_header_data_v =
11222 [ # # ]: 0 : (rte_be_to_cpu_16(icmp6_v->hdr.identifier) << 16) |
11223 [ # # ]: 0 : rte_be_to_cpu_16(icmp6_v->hdr.sequence);
11224 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_header_data,
11225 : : icmp6_header_data_v & icmp6_header_data_m);
11226 : : }
11227 : : }
11228 : :
11229 : : /**
11230 : : * Add ICMP item to the value.
11231 : : *
11232 : : * @param[in, out] key
11233 : : * Flow matcher value.
11234 : : * @param[in] item
11235 : : * Flow pattern to translate.
11236 : : * @param[in] inner
11237 : : * Item is inner pattern.
11238 : : * @param[in] key_type
11239 : : * Set flow matcher mask or value.
11240 : : */
11241 : : static void
11242 : 0 : flow_dv_translate_item_icmp(void *key, const struct rte_flow_item *item,
11243 : : int inner, uint32_t key_type)
11244 : : {
11245 : : const struct rte_flow_item_icmp *icmp_m;
11246 : : const struct rte_flow_item_icmp *icmp_v;
11247 : : uint32_t icmp_header_data_m = 0;
11248 : : uint32_t icmp_header_data_v = 0;
11249 : : void *headers_v;
11250 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
11251 : :
11252 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
11253 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11254 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11255 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11256 : : ip_protocol, 0xFF);
11257 : : else
11258 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11259 : : ip_protocol, IPPROTO_ICMP);
11260 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11261 : : return;
11262 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, icmp_v, icmp_m,
# # # # ]
11263 : : &rte_flow_item_icmp_mask);
11264 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmp_type,
11265 : : icmp_v->hdr.icmp_type & icmp_m->hdr.icmp_type);
11266 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmp_code,
11267 : : icmp_v->hdr.icmp_code & icmp_m->hdr.icmp_code);
11268 [ # # ]: 0 : icmp_header_data_m = rte_be_to_cpu_16(icmp_m->hdr.icmp_seq_nb);
11269 [ # # ]: 0 : icmp_header_data_m |= rte_be_to_cpu_16(icmp_m->hdr.icmp_ident) << 16;
11270 [ # # ]: 0 : if (icmp_header_data_m) {
11271 [ # # ]: 0 : icmp_header_data_v = rte_be_to_cpu_16(icmp_v->hdr.icmp_seq_nb);
11272 : 0 : icmp_header_data_v |=
11273 [ # # ]: 0 : rte_be_to_cpu_16(icmp_v->hdr.icmp_ident) << 16;
11274 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmp_header_data,
11275 : : icmp_header_data_v & icmp_header_data_m);
11276 : : }
11277 : : }
11278 : :
11279 : : /**
11280 : : * Add GTP item to the value.
11281 : : *
11282 : : * @param[in, out] key
11283 : : * Flow matcher value.
11284 : : * @param[in] item
11285 : : * Flow pattern to translate.
11286 : : * @param[in] inner
11287 : : * Item is inner pattern.
11288 : : * @param[in] key_type
11289 : : * Set flow matcher mask or value.
11290 : : */
11291 : : static void
11292 : 0 : flow_dv_translate_item_gtp(void *key, const struct rte_flow_item *item,
11293 : : int inner, uint32_t key_type)
11294 : : {
11295 : : const struct rte_flow_item_gtp *gtp_m;
11296 : : const struct rte_flow_item_gtp *gtp_v;
11297 : : void *headers_v;
11298 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
11299 : : uint16_t dport = RTE_GTPU_UDP_PORT;
11300 : :
11301 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
11302 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11303 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
11304 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11305 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11306 : : udp_dport, 0xFFFF);
11307 : : else
11308 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11309 : : udp_dport, dport);
11310 : : }
11311 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11312 : : return;
11313 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, gtp_v, gtp_m,
# # # # ]
11314 : : &rte_flow_item_gtp_mask);
11315 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags,
11316 : : gtp_v->hdr.gtp_hdr_info & gtp_m->hdr.gtp_hdr_info);
11317 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_type,
11318 : : gtp_v->hdr.msg_type & gtp_m->hdr.msg_type);
11319 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_teid,
11320 : : rte_be_to_cpu_32(gtp_v->hdr.teid & gtp_m->hdr.teid));
11321 : : }
11322 : :
11323 : : /**
11324 : : * Add GTP PSC item to matcher.
11325 : : *
11326 : : * @param[in, out] key
11327 : : * Flow matcher value.
11328 : : * @param[in] item
11329 : : * Flow pattern to translate.
11330 : : * @param[in] key_type
11331 : : * Set flow matcher mask or value.
11332 : : */
11333 : : static int
11334 : 0 : flow_dv_translate_item_gtp_psc(void *key, const struct rte_flow_item *item,
11335 : : uint32_t key_type)
11336 : : {
11337 : : const struct rte_flow_item_gtp_psc *gtp_psc_m;
11338 : : const struct rte_flow_item_gtp_psc *gtp_psc_v;
11339 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
11340 : : union {
11341 : : uint32_t w32;
11342 : : struct {
11343 : : uint16_t seq_num;
11344 : : uint8_t npdu_num;
11345 : : uint8_t next_ext_header_type;
11346 : : };
11347 : : } dw_2;
11348 : : union {
11349 : : uint32_t w32;
11350 : : struct {
11351 : : uint8_t len;
11352 : : uint8_t type_flags;
11353 : : uint8_t qfi;
11354 : : uint8_t reserved;
11355 : : };
11356 : : } dw_0;
11357 : : uint8_t gtp_flags;
11358 : :
11359 : : /* Always set E-flag match on one, regardless of GTP item settings. */
11360 [ # # ]: 0 : gtp_flags = MLX5_GET(fte_match_set_misc3, misc3_v, gtpu_msg_flags);
11361 : 0 : gtp_flags |= MLX5_GTP_EXT_HEADER_FLAG;
11362 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags, gtp_flags);
11363 : : /*Set next extension header type. */
11364 : 0 : dw_2.seq_num = 0;
11365 : 0 : dw_2.npdu_num = 0;
11366 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11367 : 0 : dw_2.next_ext_header_type = 0xff;
11368 : : else
11369 : 0 : dw_2.next_ext_header_type = 0x85;
11370 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_dw_2,
11371 : : rte_cpu_to_be_32(dw_2.w32));
11372 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11373 : : return 0;
11374 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, gtp_psc_v,
# # # # ]
11375 : : gtp_psc_m, &rte_flow_item_gtp_psc_mask);
11376 : 0 : dw_0.w32 = 0;
11377 : 0 : dw_0.type_flags = MLX5_GTP_PDU_TYPE_SHIFT(gtp_psc_v->hdr.type &
11378 : : gtp_psc_m->hdr.type);
11379 : 0 : dw_0.qfi = gtp_psc_v->hdr.qfi & gtp_psc_m->hdr.qfi;
11380 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_first_ext_dw_0,
11381 : : rte_cpu_to_be_32(dw_0.w32));
11382 : 0 : return 0;
11383 : : }
11384 : :
11385 : : /**
11386 : : * Add eCPRI item to matcher and to the value.
11387 : : *
11388 : : * @param[in] dev
11389 : : * The devich to configure through.
11390 : : * @param[in, out] key
11391 : : * Flow matcher value.
11392 : : * @param[in] item
11393 : : * Flow pattern to translate.
11394 : : * @param[in] last_item
11395 : : * Last item flags.
11396 : : * @param[in] key_type
11397 : : * Set flow matcher mask or value.
11398 : : */
11399 : : static void
11400 : 0 : flow_dv_translate_item_ecpri(struct rte_eth_dev *dev, void *key,
11401 : : const struct rte_flow_item *item,
11402 : : uint64_t last_item, uint32_t key_type)
11403 : : {
11404 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11405 : : const struct rte_flow_item_ecpri *ecpri_m;
11406 : : const struct rte_flow_item_ecpri *ecpri_v;
11407 : 0 : const struct rte_flow_item_ecpri *ecpri_vv = item->spec;
11408 : : struct rte_ecpri_common_hdr common;
11409 : : void *misc4_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_4);
11410 : : uint32_t *samples;
11411 : : void *dw_v;
11412 : :
11413 : : /*
11414 : : * In case of eCPRI over Ethernet, if EtherType is not specified,
11415 : : * match on eCPRI EtherType implicitly.
11416 : : */
11417 [ # # ]: 0 : if (last_item & MLX5_FLOW_LAYER_OUTER_L2) {
11418 : : void *hdrs_v, *l2v;
11419 : :
11420 : : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11421 : : l2v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, ethertype);
11422 [ # # ]: 0 : if (*(uint16_t *)l2v == 0) {
11423 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11424 : 0 : *(uint16_t *)l2v = UINT16_MAX;
11425 : : else
11426 : 0 : *(uint16_t *)l2v =
11427 : : RTE_BE16(RTE_ETHER_TYPE_ECPRI);
11428 : : }
11429 : : }
11430 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11431 : 0 : return;
11432 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, ecpri_v, ecpri_m,
# # # # ]
11433 : : &rte_flow_item_ecpri_mask);
11434 : : /*
11435 : : * Maximal four DW samples are supported in a single matching now.
11436 : : * Two are used now for a eCPRI matching:
11437 : : * 1. Type: one byte, mask should be 0x00ff0000 in network order
11438 : : * 2. ID of a message: one or two bytes, mask 0xffff0000 or 0xff000000
11439 : : * if any.
11440 : : */
11441 [ # # ]: 0 : if (!ecpri_m->hdr.common.u32)
11442 : : return;
11443 : 0 : samples = priv->sh->ecpri_parser.ids;
11444 : : /* Need to take the whole DW as the mask to fill the entry. */
11445 : : dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
11446 : : prog_sample_field_value_0);
11447 : : /* Already big endian (network order) in the header. */
11448 : 0 : *(uint32_t *)dw_v = ecpri_v->hdr.common.u32 & ecpri_m->hdr.common.u32;
11449 : : /* Sample#0, used for matching type, offset 0. */
11450 : : /* It makes no sense to set the sample ID in the mask field. */
11451 [ # # ]: 0 : MLX5_SET(fte_match_set_misc4, misc4_v,
11452 : : prog_sample_field_id_0, samples[0]);
11453 : : /*
11454 : : * Checking if message body part needs to be matched.
11455 : : * Some wildcard rules only matching type field should be supported.
11456 : : */
11457 [ # # ]: 0 : if (ecpri_m->hdr.dummy[0]) {
11458 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M)
11459 [ # # ]: 0 : common.u32 = rte_be_to_cpu_32(ecpri_vv->hdr.common.u32);
11460 : : else
11461 [ # # ]: 0 : common.u32 = rte_be_to_cpu_32(ecpri_v->hdr.common.u32);
11462 [ # # ]: 0 : switch (common.type) {
11463 : 0 : case RTE_ECPRI_MSG_TYPE_IQ_DATA:
11464 : : case RTE_ECPRI_MSG_TYPE_RTC_CTRL:
11465 : : case RTE_ECPRI_MSG_TYPE_DLY_MSR:
11466 : : dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
11467 : : prog_sample_field_value_1);
11468 : 0 : *(uint32_t *)dw_v = ecpri_v->hdr.dummy[0] &
11469 : : ecpri_m->hdr.dummy[0];
11470 : : /* Sample#1, to match message body, offset 4. */
11471 [ # # ]: 0 : MLX5_SET(fte_match_set_misc4, misc4_v,
11472 : : prog_sample_field_id_1, samples[1]);
11473 : 0 : break;
11474 : : default:
11475 : : /* Others, do not match any sample ID. */
11476 : : break;
11477 : : }
11478 : : }
11479 : : }
11480 : :
11481 : : /*
11482 : : * Add connection tracking status item to matcher
11483 : : *
11484 : : * @param[in] dev
11485 : : * The devich to configure through.
11486 : : * @param[in, out] matcher
11487 : : * Flow matcher.
11488 : : * @param[in, out] key
11489 : : * Flow matcher value.
11490 : : * @param[in] item
11491 : : * Flow pattern to translate.
11492 : : */
11493 : : static void
11494 : 0 : flow_dv_translate_item_aso_ct(struct rte_eth_dev *dev,
11495 : : void *matcher, void *key,
11496 : : const struct rte_flow_item *item)
11497 : : {
11498 : : uint32_t reg_value = 0;
11499 : : int reg_id;
11500 : : /* 8LSB 0b 11/0000/11, middle 4 bits are reserved. */
11501 : : uint32_t reg_mask = 0;
11502 : 0 : const struct rte_flow_item_conntrack *spec = item->spec;
11503 : 0 : const struct rte_flow_item_conntrack *mask = item->mask;
11504 : : uint32_t flags;
11505 : : struct rte_flow_error error;
11506 : :
11507 [ # # ]: 0 : if (!mask)
11508 : : mask = &rte_flow_item_conntrack_mask;
11509 [ # # # # ]: 0 : if (!spec || !mask->flags)
11510 : 0 : return;
11511 : 0 : flags = spec->flags & mask->flags;
11512 : : /* The conflict should be checked in the validation. */
11513 : : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_VALID)
11514 : : reg_value |= MLX5_CT_SYNDROME_VALID;
11515 [ # # ]: 0 : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_CHANGED)
11516 : : reg_value |= MLX5_CT_SYNDROME_STATE_CHANGE;
11517 [ # # ]: 0 : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_INVALID)
11518 : 0 : reg_value |= MLX5_CT_SYNDROME_INVALID;
11519 [ # # ]: 0 : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED)
11520 : 0 : reg_value |= MLX5_CT_SYNDROME_TRAP;
11521 [ # # ]: 0 : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD)
11522 : 0 : reg_value |= MLX5_CT_SYNDROME_BAD_PACKET;
11523 [ # # ]: 0 : if (mask->flags & (RTE_FLOW_CONNTRACK_PKT_STATE_VALID |
11524 : : RTE_FLOW_CONNTRACK_PKT_STATE_INVALID |
11525 : : RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED))
11526 : : reg_mask |= 0xc0;
11527 [ # # ]: 0 : if (mask->flags & RTE_FLOW_CONNTRACK_PKT_STATE_CHANGED)
11528 : 0 : reg_mask |= MLX5_CT_SYNDROME_STATE_CHANGE;
11529 [ # # ]: 0 : if (mask->flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD)
11530 : 0 : reg_mask |= MLX5_CT_SYNDROME_BAD_PACKET;
11531 : : /* The REG_C_x value could be saved during startup. */
11532 : 0 : reg_id = mlx5_flow_get_reg_id(dev, MLX5_ASO_CONNTRACK, 0, &error);
11533 [ # # ]: 0 : if (reg_id == REG_NON)
11534 : : return;
11535 : 0 : flow_dv_match_meta_reg_all(matcher, key, (enum modify_reg)reg_id,
11536 : : reg_value, reg_mask);
11537 : : }
11538 : :
11539 : : static void
11540 : 0 : flow_dv_translate_item_flex(struct rte_eth_dev *dev, void *matcher, void *key,
11541 : : const struct rte_flow_item *item,
11542 : : struct mlx5_flow *dev_flow, bool is_inner)
11543 : : {
11544 : 0 : const struct rte_flow_item_flex *spec =
11545 : : (const struct rte_flow_item_flex *)item->spec;
11546 : 0 : int index = mlx5_flex_acquire_index(dev, spec->handle, false);
11547 : :
11548 : : MLX5_ASSERT(index >= 0 && index < (int)(sizeof(uint32_t) * CHAR_BIT));
11549 [ # # ]: 0 : if (index < 0)
11550 : : return;
11551 [ # # ]: 0 : if (!(dev_flow->handle->flex_item & RTE_BIT32(index))) {
11552 : : /* Don't count both inner and outer flex items in one rule. */
11553 : 0 : if (mlx5_flex_acquire_index(dev, spec->handle, true) != index)
11554 : : MLX5_ASSERT(false);
11555 : 0 : dev_flow->handle->flex_item |= (uint8_t)RTE_BIT32(index);
11556 : : }
11557 : 0 : mlx5_flex_flow_translate_item(dev, matcher, key, item, is_inner);
11558 : : }
11559 : :
11560 : : /**
11561 : : * Add METER_COLOR item to matcher
11562 : : *
11563 : : * @param[in] dev
11564 : : * The device to configure through.
11565 : : * @param[in, out] key
11566 : : * Flow matcher value.
11567 : : * @param[in] item
11568 : : * Flow pattern to translate.
11569 : : * @param[in] key_type
11570 : : * Set flow matcher mask or value.
11571 : : */
11572 : : static void
11573 : 0 : flow_dv_translate_item_meter_color(struct rte_eth_dev *dev, void *key,
11574 : : const struct rte_flow_item *item,
11575 : : uint32_t key_type)
11576 : : {
11577 : 0 : const struct rte_flow_item_meter_color *color_m = item->mask;
11578 : 0 : const struct rte_flow_item_meter_color *color_v = item->spec;
11579 : : uint32_t value, mask;
11580 : : int reg = REG_NON;
11581 : :
11582 : : MLX5_ASSERT(color_v);
11583 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11584 : : return;
11585 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, color_v, color_m,
# # # # ]
11586 : : &rte_flow_item_meter_color_mask);
11587 [ # # ]: 0 : value = rte_col_2_mlx5_col(color_v->color);
11588 : : mask = color_m ?
11589 [ # # ]: 0 : color_m->color : (UINT32_C(1) << MLX5_MTR_COLOR_BITS) - 1;
11590 [ # # ]: 0 : if (!!(key_type & MLX5_SET_MATCHER_SW))
11591 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, NULL);
11592 : : else
11593 : : reg = flow_hw_get_reg_id(dev,
11594 : : RTE_FLOW_ITEM_TYPE_METER_COLOR, 0);
11595 [ # # ]: 0 : if (reg == REG_NON)
11596 : : return;
11597 : 0 : flow_dv_match_meta_reg(key, (enum modify_reg)reg, value, mask);
11598 : : }
11599 : :
11600 : : static void
11601 : 0 : flow_dv_translate_item_aggr_affinity(void *key,
11602 : : const struct rte_flow_item *item,
11603 : : uint32_t key_type)
11604 : : {
11605 : : const struct rte_flow_item_aggr_affinity *affinity_v;
11606 : : const struct rte_flow_item_aggr_affinity *affinity_m;
11607 : : void *misc_v;
11608 : :
11609 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, affinity_v, affinity_m,
# # # # ]
11610 : : &rte_flow_item_aggr_affinity_mask);
11611 : : misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
11612 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, lag_rx_port_affinity,
11613 : : affinity_v->affinity & affinity_m->affinity);
11614 : 0 : }
11615 : :
11616 : : static void
11617 : 0 : flow_dv_translate_item_ib_bth(void *key,
11618 : : const struct rte_flow_item *item,
11619 : : int inner, uint32_t key_type)
11620 : : {
11621 : : const struct rte_flow_item_ib_bth *bth_m;
11622 : : const struct rte_flow_item_ib_bth *bth_v;
11623 : : void *headers_v, *misc_v;
11624 : : uint16_t udp_dport;
11625 : : char *qpn_v;
11626 : : int i, size;
11627 : :
11628 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
11629 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11630 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
11631 [ # # ]: 0 : udp_dport = key_type & MLX5_SET_MATCHER_M ?
11632 : : 0xFFFF : MLX5_UDP_PORT_ROCEv2;
11633 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, udp_dport);
11634 : : }
11635 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11636 : : return;
11637 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, bth_v, bth_m, &rte_flow_item_ib_bth_mask);
# # # # ]
11638 : : misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
11639 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, bth_opcode,
11640 : : bth_v->hdr.opcode & bth_m->hdr.opcode);
11641 : 0 : qpn_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, bth_dst_qp);
11642 : : size = sizeof(bth_m->hdr.dst_qp);
11643 [ # # ]: 0 : for (i = 0; i < size; ++i)
11644 : 0 : qpn_v[i] = bth_m->hdr.dst_qp[i] & bth_v->hdr.dst_qp[i];
11645 : : }
11646 : :
11647 : : static uint32_t matcher_zero[MLX5_ST_SZ_DW(fte_match_param)] = { 0 };
11648 : :
11649 : : #define HEADER_IS_ZERO(match_criteria, headers) \
11650 : : !(memcmp(MLX5_ADDR_OF(fte_match_param, match_criteria, headers), \
11651 : : matcher_zero, MLX5_FLD_SZ_BYTES(fte_match_param, headers))) \
11652 : :
11653 : : /**
11654 : : * Calculate flow matcher enable bitmap.
11655 : : *
11656 : : * @param match_criteria
11657 : : * Pointer to flow matcher criteria.
11658 : : *
11659 : : * @return
11660 : : * Bitmap of enabled fields.
11661 : : */
11662 : : static uint8_t
11663 : 0 : flow_dv_matcher_enable(uint32_t *match_criteria)
11664 : : {
11665 : : uint8_t match_criteria_enable;
11666 : :
11667 : : match_criteria_enable =
11668 : 0 : (!HEADER_IS_ZERO(match_criteria, outer_headers)) <<
11669 : : MLX5_MATCH_CRITERIA_ENABLE_OUTER_BIT;
11670 : 0 : match_criteria_enable |=
11671 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters)) <<
11672 : : MLX5_MATCH_CRITERIA_ENABLE_MISC_BIT;
11673 : 0 : match_criteria_enable |=
11674 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, inner_headers)) <<
11675 : : MLX5_MATCH_CRITERIA_ENABLE_INNER_BIT;
11676 : 0 : match_criteria_enable |=
11677 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) <<
11678 : : MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
11679 : 0 : match_criteria_enable |=
11680 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters_3)) <<
11681 : : MLX5_MATCH_CRITERIA_ENABLE_MISC3_BIT;
11682 : 0 : match_criteria_enable |=
11683 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters_4)) <<
11684 : : MLX5_MATCH_CRITERIA_ENABLE_MISC4_BIT;
11685 : 0 : match_criteria_enable |=
11686 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters_5)) <<
11687 : : MLX5_MATCH_CRITERIA_ENABLE_MISC5_BIT;
11688 : 0 : return match_criteria_enable;
11689 : : }
11690 : :
11691 : : static void
11692 : : __flow_dv_adjust_buf_size(size_t *size, uint8_t match_criteria)
11693 : : {
11694 : : /*
11695 : : * Check flow matching criteria first, subtract misc5/4 length if flow
11696 : : * doesn't own misc5/4 parameters. In some old rdma-core releases,
11697 : : * misc5/4 are not supported, and matcher creation failure is expected
11698 : : * w/o subtraction. If misc5 is provided, misc4 must be counted in since
11699 : : * misc5 is right after misc4.
11700 : : */
11701 : 0 : if (!(match_criteria & (1 << MLX5_MATCH_CRITERIA_ENABLE_MISC5_BIT))) {
11702 : 0 : *size = MLX5_ST_SZ_BYTES(fte_match_param) -
11703 : : MLX5_ST_SZ_BYTES(fte_match_set_misc5);
11704 [ # # # # : 0 : if (!(match_criteria & (1 <<
# # # # #
# # # # #
# # # # #
# ]
11705 : : MLX5_MATCH_CRITERIA_ENABLE_MISC4_BIT))) {
11706 : 0 : *size -= MLX5_ST_SZ_BYTES(fte_match_set_misc4);
11707 : : }
11708 : : }
11709 : : }
11710 : :
11711 : : struct mlx5_list_entry *
11712 : 0 : flow_matcher_clone_cb(void *tool_ctx __rte_unused,
11713 : : struct mlx5_list_entry *entry, void *cb_ctx)
11714 : : {
11715 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11716 : 0 : struct mlx5_flow_dv_matcher *ref = ctx->data;
11717 : 0 : struct mlx5_flow_tbl_data_entry *tbl = container_of(ref->tbl,
11718 : : typeof(*tbl), tbl);
11719 : 0 : struct mlx5_flow_dv_matcher *resource = mlx5_malloc(MLX5_MEM_ANY,
11720 : : sizeof(*resource),
11721 : : 0, SOCKET_ID_ANY);
11722 : :
11723 [ # # ]: 0 : if (!resource) {
11724 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
11725 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11726 : : "cannot create matcher");
11727 : 0 : return NULL;
11728 : : }
11729 : : memcpy(resource, entry, sizeof(*resource));
11730 : 0 : resource->tbl = &tbl->tbl;
11731 : 0 : return &resource->entry;
11732 : : }
11733 : :
11734 : : void
11735 : 0 : flow_matcher_clone_free_cb(void *tool_ctx __rte_unused,
11736 : : struct mlx5_list_entry *entry)
11737 : : {
11738 : 0 : mlx5_free(entry);
11739 : 0 : }
11740 : :
11741 : : struct mlx5_list_entry *
11742 : 0 : flow_dv_tbl_create_cb(void *tool_ctx, void *cb_ctx)
11743 : : {
11744 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11745 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11746 : 0 : struct rte_eth_dev *dev = ctx->dev;
11747 : : struct mlx5_flow_tbl_data_entry *tbl_data;
11748 : 0 : struct mlx5_flow_tbl_tunnel_prm *tt_prm = ctx->data2;
11749 : 0 : struct rte_flow_error *error = ctx->error;
11750 : 0 : union mlx5_flow_tbl_key key = { .v64 = *(uint64_t *)(ctx->data) };
11751 : : struct mlx5_flow_tbl_resource *tbl;
11752 : : void *domain;
11753 : 0 : uint32_t idx = 0;
11754 : : int ret;
11755 : :
11756 : 0 : tbl_data = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_JUMP], &idx);
11757 [ # # ]: 0 : if (!tbl_data) {
11758 : 0 : rte_flow_error_set(error, ENOMEM,
11759 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11760 : : NULL,
11761 : : "cannot allocate flow table data entry");
11762 : 0 : return NULL;
11763 : : }
11764 : 0 : tbl_data->idx = idx;
11765 : 0 : tbl_data->tunnel = tt_prm->tunnel;
11766 : 0 : tbl_data->group_id = tt_prm->group_id;
11767 [ # # ]: 0 : tbl_data->external = !!tt_prm->external;
11768 : 0 : tbl_data->tunnel_offload = is_tunnel_offload_active(dev);
11769 : 0 : tbl_data->is_egress = !!key.is_egress;
11770 : 0 : tbl_data->is_transfer = !!key.is_fdb;
11771 : 0 : tbl_data->dummy = !!key.dummy;
11772 : 0 : tbl_data->level = key.level;
11773 : 0 : tbl_data->id = key.id;
11774 : : tbl = &tbl_data->tbl;
11775 [ # # ]: 0 : if (key.dummy)
11776 : 0 : return &tbl_data->entry;
11777 [ # # ]: 0 : if (key.is_fdb)
11778 : 0 : domain = sh->fdb_domain;
11779 [ # # ]: 0 : else if (key.is_egress)
11780 : 0 : domain = sh->tx_domain;
11781 : : else
11782 : 0 : domain = sh->rx_domain;
11783 : : ret = mlx5_flow_os_create_flow_tbl(domain, key.level, &tbl->obj);
11784 : : if (ret) {
11785 : 0 : rte_flow_error_set(error, ENOMEM,
11786 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11787 : : NULL, "cannot create flow table object");
11788 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
11789 : 0 : return NULL;
11790 : : }
11791 [ # # ]: 0 : if (key.level != 0) {
11792 : : ret = mlx5_flow_os_create_flow_action_dest_flow_tbl
11793 : : (tbl->obj, &tbl_data->jump.action);
11794 : : if (ret) {
11795 : 0 : rte_flow_error_set(error, ENOMEM,
11796 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11797 : : NULL,
11798 : : "cannot create flow jump action");
11799 : 0 : mlx5_flow_os_destroy_flow_tbl(tbl->obj);
11800 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
11801 : 0 : return NULL;
11802 : : }
11803 : : }
11804 [ # # # # ]: 0 : MKSTR(matcher_name, "%s_%s_%u_%u_matcher_list",
11805 : : key.is_fdb ? "FDB" : "NIC", key.is_egress ? "egress" : "ingress",
11806 : : key.level, key.id);
11807 : 0 : tbl_data->matchers = mlx5_list_create(matcher_name, sh, true,
11808 : : flow_matcher_create_cb,
11809 : : flow_matcher_match_cb,
11810 : : flow_matcher_remove_cb,
11811 : : flow_matcher_clone_cb,
11812 : : flow_matcher_clone_free_cb);
11813 [ # # ]: 0 : if (!tbl_data->matchers) {
11814 : 0 : rte_flow_error_set(error, ENOMEM,
11815 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11816 : : NULL,
11817 : : "cannot create tbl matcher list");
11818 : 0 : mlx5_flow_os_destroy_flow_action(tbl_data->jump.action);
11819 : 0 : mlx5_flow_os_destroy_flow_tbl(tbl->obj);
11820 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
11821 : 0 : return NULL;
11822 : : }
11823 : 0 : return &tbl_data->entry;
11824 : : }
11825 : :
11826 : : int
11827 : 0 : flow_dv_tbl_match_cb(void *tool_ctx __rte_unused, struct mlx5_list_entry *entry,
11828 : : void *cb_ctx)
11829 : : {
11830 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11831 : : struct mlx5_flow_tbl_data_entry *tbl_data =
11832 : : container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
11833 : 0 : union mlx5_flow_tbl_key key = { .v64 = *(uint64_t *)(ctx->data) };
11834 : :
11835 : 0 : return tbl_data->level != key.level ||
11836 [ # # ]: 0 : tbl_data->id != key.id ||
11837 [ # # ]: 0 : tbl_data->dummy != key.dummy ||
11838 [ # # # # ]: 0 : tbl_data->is_transfer != !!key.is_fdb ||
11839 [ # # ]: 0 : tbl_data->is_egress != !!key.is_egress;
11840 : : }
11841 : :
11842 : : struct mlx5_list_entry *
11843 : 0 : flow_dv_tbl_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
11844 : : void *cb_ctx)
11845 : : {
11846 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11847 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11848 : : struct mlx5_flow_tbl_data_entry *tbl_data;
11849 : 0 : struct rte_flow_error *error = ctx->error;
11850 : 0 : uint32_t idx = 0;
11851 : :
11852 : 0 : tbl_data = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_JUMP], &idx);
11853 [ # # ]: 0 : if (!tbl_data) {
11854 : 0 : rte_flow_error_set(error, ENOMEM,
11855 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11856 : : NULL,
11857 : : "cannot allocate flow table data entry");
11858 : 0 : return NULL;
11859 : : }
11860 : : memcpy(tbl_data, oentry, sizeof(*tbl_data));
11861 : 0 : tbl_data->idx = idx;
11862 : 0 : return &tbl_data->entry;
11863 : : }
11864 : :
11865 : : void
11866 : 0 : flow_dv_tbl_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
11867 : : {
11868 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11869 : : struct mlx5_flow_tbl_data_entry *tbl_data =
11870 : : container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
11871 : :
11872 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], tbl_data->idx);
11873 : 0 : }
11874 : :
11875 : : /**
11876 : : * Get a flow table.
11877 : : *
11878 : : * @param[in, out] dev
11879 : : * Pointer to rte_eth_dev structure.
11880 : : * @param[in] table_level
11881 : : * Table level to use.
11882 : : * @param[in] egress
11883 : : * Direction of the table.
11884 : : * @param[in] transfer
11885 : : * E-Switch or NIC flow.
11886 : : * @param[in] dummy
11887 : : * Dummy entry for dv API.
11888 : : * @param[in] table_id
11889 : : * Table id to use.
11890 : : * @param[out] error
11891 : : * pointer to error structure.
11892 : : *
11893 : : * @return
11894 : : * Returns tables resource based on the index, NULL in case of failed.
11895 : : */
11896 : : struct mlx5_flow_tbl_resource *
11897 : 0 : flow_dv_tbl_resource_get(struct rte_eth_dev *dev,
11898 : : uint32_t table_level, uint8_t egress,
11899 : : uint8_t transfer,
11900 : : bool external,
11901 : : const struct mlx5_flow_tunnel *tunnel,
11902 : : uint32_t group_id, uint8_t dummy,
11903 : : uint32_t table_id,
11904 : : struct rte_flow_error *error)
11905 : : {
11906 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11907 : 0 : union mlx5_flow_tbl_key table_key = {
11908 : : {
11909 : : .level = table_level,
11910 : : .id = table_id,
11911 : : .reserved = 0,
11912 : 0 : .dummy = !!dummy,
11913 : 0 : .is_fdb = !!transfer,
11914 : 0 : .is_egress = !!egress,
11915 : : }
11916 : : };
11917 : 0 : struct mlx5_flow_tbl_tunnel_prm tt_prm = {
11918 : : .tunnel = tunnel,
11919 : : .group_id = group_id,
11920 : : .external = external,
11921 : : };
11922 : 0 : struct mlx5_flow_cb_ctx ctx = {
11923 : : .dev = dev,
11924 : : .error = error,
11925 : : .data = &table_key.v64,
11926 : : .data2 = &tt_prm,
11927 : : };
11928 : : struct mlx5_list_entry *entry;
11929 : : struct mlx5_flow_tbl_data_entry *tbl_data;
11930 : :
11931 : 0 : entry = mlx5_hlist_register(priv->sh->flow_tbls, table_key.v64, &ctx);
11932 [ # # ]: 0 : if (!entry) {
11933 : 0 : rte_flow_error_set(error, ENOMEM,
11934 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11935 : : "cannot get table");
11936 : 0 : return NULL;
11937 : : }
11938 [ # # ]: 0 : DRV_LOG(DEBUG, "table_level %u table_id %u "
11939 : : "tunnel %u group %u registered.",
11940 : : table_level, table_id,
11941 : : tunnel ? tunnel->tunnel_id : 0, group_id);
11942 : : tbl_data = container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
11943 : 0 : return &tbl_data->tbl;
11944 : : }
11945 : :
11946 : : void
11947 : 0 : flow_dv_tbl_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
11948 : : {
11949 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11950 : : struct mlx5_flow_tbl_data_entry *tbl_data =
11951 : : container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
11952 : :
11953 : : MLX5_ASSERT(entry && sh);
11954 [ # # ]: 0 : if (tbl_data->jump.action)
11955 : : mlx5_flow_os_destroy_flow_action(tbl_data->jump.action);
11956 [ # # ]: 0 : if (tbl_data->tbl.obj)
11957 : : mlx5_flow_os_destroy_flow_tbl(tbl_data->tbl.obj);
11958 [ # # ]: 0 : if (tbl_data->tunnel_offload && tbl_data->external) {
11959 : : struct mlx5_list_entry *he;
11960 : : struct mlx5_hlist *tunnel_grp_hash;
11961 : 0 : struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
11962 : 0 : union tunnel_tbl_key tunnel_key = {
11963 : 0 : .tunnel_id = tbl_data->tunnel ?
11964 [ # # ]: 0 : tbl_data->tunnel->tunnel_id : 0,
11965 : 0 : .group = tbl_data->group_id
11966 : : };
11967 : 0 : uint32_t table_level = tbl_data->level;
11968 : 0 : struct mlx5_flow_cb_ctx ctx = {
11969 : : .data = (void *)&tunnel_key.val,
11970 : : };
11971 : :
11972 : : tunnel_grp_hash = tbl_data->tunnel ?
11973 [ # # ]: 0 : tbl_data->tunnel->groups :
11974 : : thub->groups;
11975 : 0 : he = mlx5_hlist_lookup(tunnel_grp_hash, tunnel_key.val, &ctx);
11976 [ # # ]: 0 : if (he)
11977 : 0 : mlx5_hlist_unregister(tunnel_grp_hash, he);
11978 [ # # ]: 0 : DRV_LOG(DEBUG,
11979 : : "table_level %u id %u tunnel %u group %u released.",
11980 : : table_level,
11981 : : tbl_data->id,
11982 : : tbl_data->tunnel ?
11983 : : tbl_data->tunnel->tunnel_id : 0,
11984 : : tbl_data->group_id);
11985 : : }
11986 [ # # ]: 0 : if (tbl_data->matchers)
11987 : 0 : mlx5_list_destroy(tbl_data->matchers);
11988 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], tbl_data->idx);
11989 : 0 : }
11990 : :
11991 : : /**
11992 : : * Release a flow table.
11993 : : *
11994 : : * @param[in] sh
11995 : : * Pointer to device shared structure.
11996 : : * @param[in] tbl
11997 : : * Table resource to be released.
11998 : : *
11999 : : * @return
12000 : : * Returns 0 if table was released, else return 1;
12001 : : */
12002 : : int
12003 : 0 : flow_dv_tbl_resource_release(struct mlx5_dev_ctx_shared *sh,
12004 : : struct mlx5_flow_tbl_resource *tbl)
12005 : : {
12006 : : struct mlx5_flow_tbl_data_entry *tbl_data =
12007 : 0 : container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
12008 : :
12009 [ # # ]: 0 : if (!tbl)
12010 : : return 0;
12011 : 0 : return mlx5_hlist_unregister(sh->flow_tbls, &tbl_data->entry);
12012 : : }
12013 : :
12014 : : int
12015 : 0 : flow_matcher_match_cb(void *tool_ctx __rte_unused,
12016 : : struct mlx5_list_entry *entry, void *cb_ctx)
12017 : : {
12018 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12019 : 0 : struct mlx5_flow_dv_matcher *ref = ctx->data;
12020 : : struct mlx5_flow_dv_matcher *cur = container_of(entry, typeof(*cur),
12021 : : entry);
12022 : :
12023 : 0 : return cur->crc != ref->crc ||
12024 [ # # ]: 0 : cur->priority != ref->priority ||
12025 : 0 : memcmp((const void *)cur->mask.buf,
12026 [ # # ]: 0 : (const void *)ref->mask.buf, ref->mask.size);
12027 : : }
12028 : :
12029 : : struct mlx5_list_entry *
12030 : 0 : flow_matcher_create_cb(void *tool_ctx, void *cb_ctx)
12031 : : {
12032 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
12033 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12034 : 0 : struct mlx5_flow_dv_matcher *ref = ctx->data;
12035 : : struct mlx5_flow_dv_matcher *resource;
12036 : : #ifdef HAVE_MLX5_HWS_SUPPORT
12037 : : const struct rte_flow_item *items;
12038 : : #endif
12039 : 0 : struct mlx5dv_flow_matcher_attr dv_attr = {
12040 : : .type = IBV_FLOW_ATTR_NORMAL,
12041 : 0 : .match_mask = (void *)&ref->mask,
12042 : : };
12043 : : struct mlx5_flow_tbl_data_entry *tbl;
12044 : : int ret;
12045 : :
12046 : 0 : resource = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*resource), 0,
12047 : : SOCKET_ID_ANY);
12048 [ # # ]: 0 : if (!resource) {
12049 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12050 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12051 : : "cannot create matcher");
12052 : 0 : return NULL;
12053 : : }
12054 : 0 : *resource = *ref;
12055 [ # # ]: 0 : if (sh->config.dv_flow_en != 2) {
12056 : 0 : tbl = container_of(ref->tbl, typeof(*tbl), tbl);
12057 : 0 : dv_attr.match_criteria_enable =
12058 [ # # ]: 0 : flow_dv_matcher_enable(resource->mask.buf);
12059 : : __flow_dv_adjust_buf_size(&ref->mask.size,
12060 : : dv_attr.match_criteria_enable);
12061 : 0 : dv_attr.priority = ref->priority;
12062 [ # # ]: 0 : if (tbl->is_egress)
12063 : 0 : dv_attr.flags |= IBV_FLOW_ATTR_FLAGS_EGRESS;
12064 : 0 : ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
12065 : : tbl->tbl.obj,
12066 : : &resource->matcher_object);
12067 : : if (ret) {
12068 : 0 : mlx5_free(resource);
12069 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12070 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12071 : : "cannot create matcher");
12072 : 0 : return NULL;
12073 : : }
12074 : : } else {
12075 : : #ifdef HAVE_MLX5_HWS_SUPPORT
12076 : 0 : items = *((const struct rte_flow_item **)(ctx->data2));
12077 : 0 : resource->matcher_object = mlx5dr_bwc_matcher_create
12078 : 0 : (resource->group->tbl, resource->priority, items);
12079 [ # # ]: 0 : if (!resource->matcher_object) {
12080 : 0 : mlx5_free(resource);
12081 : 0 : return NULL;
12082 : : }
12083 : : #else
12084 : : mlx5_free(resource);
12085 : : return NULL;
12086 : : #endif
12087 : : }
12088 : 0 : return &resource->entry;
12089 : : }
12090 : :
12091 : : /**
12092 : : * Register the flow matcher.
12093 : : *
12094 : : * @param[in, out] dev
12095 : : * Pointer to rte_eth_dev structure.
12096 : : * @param[in, out] matcher
12097 : : * Pointer to flow matcher.
12098 : : * @param[in, out] key
12099 : : * Pointer to flow table key.
12100 : : * @parm[in, out] dev_flow
12101 : : * Pointer to the dev_flow.
12102 : : * @param[out] error
12103 : : * pointer to error structure.
12104 : : *
12105 : : * @return
12106 : : * 0 on success otherwise -errno and errno is set.
12107 : : */
12108 : : static int
12109 : 0 : flow_dv_matcher_register(struct rte_eth_dev *dev,
12110 : : struct mlx5_flow_dv_matcher *ref,
12111 : : union mlx5_flow_tbl_key *key,
12112 : : struct mlx5_flow *dev_flow,
12113 : : const struct mlx5_flow_tunnel *tunnel,
12114 : : uint32_t group_id,
12115 : : struct rte_flow_error *error)
12116 : : {
12117 : : struct mlx5_list_entry *entry;
12118 : : struct mlx5_flow_dv_matcher *resource;
12119 : : struct mlx5_flow_tbl_resource *tbl;
12120 : : struct mlx5_flow_tbl_data_entry *tbl_data;
12121 : 0 : struct mlx5_flow_cb_ctx ctx = {
12122 : : .error = error,
12123 : : .data = ref,
12124 : : };
12125 : : /**
12126 : : * tunnel offload API requires this registration for cases when
12127 : : * tunnel match rule was inserted before tunnel set rule.
12128 : : */
12129 : 0 : tbl = flow_dv_tbl_resource_get(dev, key->level,
12130 : 0 : key->is_egress, key->is_fdb,
12131 : 0 : dev_flow->external, tunnel,
12132 : 0 : group_id, 0, key->id, error);
12133 [ # # ]: 0 : if (!tbl)
12134 : 0 : return -rte_errno; /* No need to refill the error info */
12135 : 0 : tbl_data = container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
12136 : 0 : ref->tbl = tbl;
12137 : 0 : entry = mlx5_list_register(tbl_data->matchers, &ctx);
12138 [ # # ]: 0 : if (!entry) {
12139 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
12140 : 0 : return rte_flow_error_set(error, ENOMEM,
12141 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12142 : : "cannot allocate ref memory");
12143 : : }
12144 : : resource = container_of(entry, typeof(*resource), entry);
12145 : 0 : dev_flow->handle->dvh.matcher = resource;
12146 : 0 : return 0;
12147 : : }
12148 : :
12149 : : struct mlx5_list_entry *
12150 : 0 : flow_dv_tag_create_cb(void *tool_ctx, void *cb_ctx)
12151 : : {
12152 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
12153 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12154 : : struct mlx5_flow_dv_tag_resource *entry;
12155 : 0 : uint32_t idx = 0;
12156 : : int ret;
12157 : :
12158 : 0 : entry = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_TAG], &idx);
12159 [ # # ]: 0 : if (!entry) {
12160 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12161 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12162 : : "cannot allocate resource memory");
12163 : 0 : return NULL;
12164 : : }
12165 : 0 : entry->idx = idx;
12166 : 0 : entry->tag_id = *(uint32_t *)(ctx->data);
12167 : : ret = mlx5_flow_os_create_flow_action_tag(entry->tag_id,
12168 : : &entry->action);
12169 : : if (ret) {
12170 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], idx);
12171 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12172 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12173 : : NULL, "cannot create action");
12174 : 0 : return NULL;
12175 : : }
12176 : 0 : return &entry->entry;
12177 : : }
12178 : :
12179 : : int
12180 : 0 : flow_dv_tag_match_cb(void *tool_ctx __rte_unused, struct mlx5_list_entry *entry,
12181 : : void *cb_ctx)
12182 : : {
12183 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12184 : : struct mlx5_flow_dv_tag_resource *tag =
12185 : : container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
12186 : :
12187 : 0 : return *(uint32_t *)(ctx->data) != tag->tag_id;
12188 : : }
12189 : :
12190 : : struct mlx5_list_entry *
12191 : 0 : flow_dv_tag_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
12192 : : void *cb_ctx)
12193 : : {
12194 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
12195 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12196 : : struct mlx5_flow_dv_tag_resource *entry;
12197 : 0 : uint32_t idx = 0;
12198 : :
12199 : 0 : entry = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_TAG], &idx);
12200 [ # # ]: 0 : if (!entry) {
12201 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12202 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12203 : : "cannot allocate tag resource memory");
12204 : 0 : return NULL;
12205 : : }
12206 : : memcpy(entry, oentry, sizeof(*entry));
12207 : 0 : entry->idx = idx;
12208 : 0 : return &entry->entry;
12209 : : }
12210 : :
12211 : : void
12212 : 0 : flow_dv_tag_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
12213 : : {
12214 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
12215 : : struct mlx5_flow_dv_tag_resource *tag =
12216 : : container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
12217 : :
12218 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], tag->idx);
12219 : 0 : }
12220 : :
12221 : : /**
12222 : : * Find existing tag resource or create and register a new one.
12223 : : *
12224 : : * @param dev[in, out]
12225 : : * Pointer to rte_eth_dev structure.
12226 : : * @param[in, out] tag_be24
12227 : : * Tag value in big endian then R-shift 8.
12228 : : * @parm[in, out] dev_flow
12229 : : * Pointer to the dev_flow.
12230 : : * @param[out] error
12231 : : * pointer to error structure.
12232 : : *
12233 : : * @return
12234 : : * 0 on success otherwise -errno and errno is set.
12235 : : */
12236 : : static int
12237 : 0 : flow_dv_tag_resource_register
12238 : : (struct rte_eth_dev *dev,
12239 : : uint32_t tag_be24,
12240 : : struct mlx5_flow *dev_flow,
12241 : : struct rte_flow_error *error)
12242 : : {
12243 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12244 : : struct mlx5_flow_dv_tag_resource *resource;
12245 : : struct mlx5_list_entry *entry;
12246 : 0 : struct mlx5_flow_cb_ctx ctx = {
12247 : : .error = error,
12248 : : .data = &tag_be24,
12249 : : };
12250 : : struct mlx5_hlist *tag_table;
12251 : :
12252 : 0 : tag_table = flow_dv_hlist_prepare(priv->sh, &priv->sh->tag_table,
12253 : : "tags",
12254 : : MLX5_TAGS_HLIST_ARRAY_SIZE,
12255 : 0 : false, false, priv->sh,
12256 : : flow_dv_tag_create_cb,
12257 : : flow_dv_tag_match_cb,
12258 : : flow_dv_tag_remove_cb,
12259 : : flow_dv_tag_clone_cb,
12260 : : flow_dv_tag_clone_free_cb,
12261 : : error);
12262 [ # # ]: 0 : if (unlikely(!tag_table))
12263 : 0 : return -rte_errno;
12264 : 0 : entry = mlx5_hlist_register(tag_table, tag_be24, &ctx);
12265 [ # # ]: 0 : if (entry) {
12266 : : resource = container_of(entry, struct mlx5_flow_dv_tag_resource,
12267 : : entry);
12268 : 0 : dev_flow->handle->dvh.rix_tag = resource->idx;
12269 : 0 : dev_flow->dv.tag_resource = resource;
12270 : 0 : return 0;
12271 : : }
12272 : 0 : return -rte_errno;
12273 : : }
12274 : :
12275 : : void
12276 : 0 : flow_dv_tag_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
12277 : : {
12278 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
12279 : : struct mlx5_flow_dv_tag_resource *tag =
12280 : : container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
12281 : :
12282 : : MLX5_ASSERT(tag && sh && tag->action);
12283 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(tag->action));
12284 : 0 : DRV_LOG(DEBUG, "Tag %p: removed.", (void *)tag);
12285 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], tag->idx);
12286 : 0 : }
12287 : :
12288 : : /**
12289 : : * Release the tag.
12290 : : *
12291 : : * @param dev
12292 : : * Pointer to Ethernet device.
12293 : : * @param tag_idx
12294 : : * Tag index.
12295 : : *
12296 : : * @return
12297 : : * 1 while a reference on it exists, 0 when freed.
12298 : : */
12299 : : static int
12300 : 0 : flow_dv_tag_release(struct rte_eth_dev *dev,
12301 : : uint32_t tag_idx)
12302 : : {
12303 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12304 : : struct mlx5_flow_dv_tag_resource *tag;
12305 : :
12306 : 0 : tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG], tag_idx);
12307 [ # # ]: 0 : if (!tag)
12308 : : return 0;
12309 : 0 : DRV_LOG(DEBUG, "port %u tag %p: refcnt %d--",
12310 : : dev->data->port_id, (void *)tag, tag->entry.ref_cnt);
12311 : 0 : return mlx5_hlist_unregister(priv->sh->tag_table, &tag->entry);
12312 : : }
12313 : :
12314 : : /**
12315 : : * Translate action PORT_ID / REPRESENTED_PORT to vport.
12316 : : *
12317 : : * @param[in] dev
12318 : : * Pointer to rte_eth_dev structure.
12319 : : * @param[in] action
12320 : : * Pointer to action PORT_ID / REPRESENTED_PORT.
12321 : : * @param[out] dst_port_id
12322 : : * The target port ID.
12323 : : * @param[out] error
12324 : : * Pointer to the error structure.
12325 : : *
12326 : : * @return
12327 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
12328 : : */
12329 : : static int
12330 : 0 : flow_dv_translate_action_port_id(struct rte_eth_dev *dev,
12331 : : const struct rte_flow_action *action,
12332 : : uint32_t *dst_port_id,
12333 : : struct rte_flow_error *error)
12334 : : {
12335 : : uint32_t port;
12336 : : struct mlx5_priv *priv;
12337 : :
12338 [ # # # ]: 0 : switch (action->type) {
12339 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID: {
12340 : : const struct rte_flow_action_port_id *conf;
12341 : :
12342 : 0 : conf = (const struct rte_flow_action_port_id *)action->conf;
12343 [ # # ]: 0 : port = conf->original ? dev->data->port_id : conf->id;
12344 : : break;
12345 : : }
12346 : 0 : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT: {
12347 : : const struct rte_flow_action_ethdev *ethdev;
12348 : :
12349 : 0 : ethdev = (const struct rte_flow_action_ethdev *)action->conf;
12350 : 0 : port = ethdev->port_id;
12351 : 0 : break;
12352 : : }
12353 : 0 : default:
12354 : : MLX5_ASSERT(false);
12355 : 0 : return rte_flow_error_set(error, EINVAL,
12356 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
12357 : : "unknown E-Switch action");
12358 : : }
12359 : :
12360 : 0 : priv = mlx5_port_to_eswitch_info(port, false);
12361 [ # # ]: 0 : if (!priv)
12362 : 0 : return rte_flow_error_set(error, -rte_errno,
12363 : : RTE_FLOW_ERROR_TYPE_ACTION,
12364 : : NULL,
12365 : : "No eswitch info was found for port");
12366 : : #ifdef HAVE_MLX5DV_DR_CREATE_DEST_IB_PORT
12367 : : /*
12368 : : * This parameter is transferred to
12369 : : * mlx5dv_dr_action_create_dest_ib_port().
12370 : : */
12371 : 0 : *dst_port_id = priv->dev_port;
12372 : : #else
12373 : : /*
12374 : : * Legacy mode, no LAG configurations is supported.
12375 : : * This parameter is transferred to
12376 : : * mlx5dv_dr_action_create_dest_vport().
12377 : : */
12378 : : *dst_port_id = priv->vport_id;
12379 : : #endif
12380 : 0 : return 0;
12381 : : }
12382 : :
12383 : : /**
12384 : : * Create a counter with aging configuration.
12385 : : *
12386 : : * @param[in] dev
12387 : : * Pointer to rte_eth_dev structure.
12388 : : * @param[in] dev_flow
12389 : : * Pointer to the mlx5_flow.
12390 : : * @param[out] count
12391 : : * Pointer to the counter action configuration.
12392 : : * @param[in] age
12393 : : * Pointer to the aging action configuration.
12394 : : *
12395 : : * @return
12396 : : * Index to flow counter on success, 0 otherwise.
12397 : : */
12398 : : static uint32_t
12399 : 0 : flow_dv_translate_create_counter(struct rte_eth_dev *dev,
12400 : : struct mlx5_flow *dev_flow,
12401 : : const struct rte_flow_action_count *count
12402 : : __rte_unused,
12403 : : const struct rte_flow_action_age *age)
12404 : : {
12405 : : uint32_t counter;
12406 : : struct mlx5_age_param *age_param;
12407 : :
12408 : 0 : counter = flow_dv_counter_alloc(dev, !!age);
12409 [ # # ]: 0 : if (!counter || age == NULL)
12410 : : return counter;
12411 : : age_param = flow_dv_counter_idx_get_age(dev, counter);
12412 [ # # ]: 0 : age_param->context = age->context ? age->context :
12413 : 0 : (void *)(uintptr_t)(dev_flow->flow_idx);
12414 : 0 : age_param->timeout = age->timeout;
12415 : 0 : age_param->port_id = dev->data->port_id;
12416 : 0 : rte_atomic_store_explicit(&age_param->sec_since_last_hit, 0, rte_memory_order_relaxed);
12417 : 0 : rte_atomic_store_explicit(&age_param->state, AGE_CANDIDATE, rte_memory_order_relaxed);
12418 : 0 : return counter;
12419 : : }
12420 : :
12421 : : /**
12422 : : * Add Tx queue matcher
12423 : : *
12424 : : * @param[in] dev
12425 : : * Pointer to rte_eth_dev structure.
12426 : : * @param[in, out] key
12427 : : * Flow matcher value.
12428 : : * @param[in] item
12429 : : * Flow pattern to translate.
12430 : : * @param[in] key_type
12431 : : * Set flow matcher mask or value.
12432 : : *
12433 : : * @return
12434 : : * 0 on success otherwise -errno and errno is set.
12435 : : */
12436 : : static int
12437 : 0 : flow_dv_translate_item_tx_queue(struct rte_eth_dev *dev, void *key,
12438 : : const struct rte_flow_item *item, uint32_t key_type)
12439 : : {
12440 : : const struct rte_flow_item_tx_queue *queue_m;
12441 : : const struct rte_flow_item_tx_queue *queue_v;
12442 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
12443 : : uint32_t tx_queue;
12444 : : uint32_t sqn = 0;
12445 : : int ret;
12446 : :
12447 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, queue_v, queue_m, &rte_flow_item_tx_queue_mask);
# # # # ]
12448 [ # # ]: 0 : if (!queue_m || !queue_v)
12449 : : return -EINVAL;
12450 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_V) {
12451 : 0 : tx_queue = queue_v->tx_queue;
12452 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_V)
12453 : 0 : tx_queue &= queue_m->tx_queue;
12454 [ # # ]: 0 : ret = flow_hw_get_sqn(dev, tx_queue, &sqn);
12455 [ # # ]: 0 : if (unlikely(ret))
12456 : 0 : return -ret;
12457 : : } else {
12458 : : /* Due to tx_queue to sqn converting, only fully masked value support. */
12459 [ # # ]: 0 : if (queue_m->tx_queue != rte_flow_item_tx_queue_mask.tx_queue)
12460 : : return -EINVAL;
12461 : : sqn = UINT32_MAX;
12462 : : }
12463 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, source_sqn, sqn);
12464 : 0 : return 0;
12465 : : }
12466 : :
12467 : : /**
12468 : : * Add SQ matcher
12469 : : *
12470 : : * @param[in, out] matcher
12471 : : * Flow matcher.
12472 : : * @param[in, out] key
12473 : : * Flow matcher value.
12474 : : * @param[in] item
12475 : : * Flow pattern to translate.
12476 : : * @param[in] key_type
12477 : : * Set flow matcher mask or value.
12478 : : */
12479 : : static void
12480 : 0 : flow_dv_translate_item_sq(void *key,
12481 : : const struct rte_flow_item *item,
12482 : : uint32_t key_type)
12483 : : {
12484 : : const struct mlx5_rte_flow_item_sq *queue_m;
12485 : : const struct mlx5_rte_flow_item_sq *queue_v;
12486 : 0 : const struct mlx5_rte_flow_item_sq queue_mask = {
12487 : : .queue = UINT32_MAX,
12488 : : };
12489 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
12490 : : uint32_t queue;
12491 : :
12492 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, queue_v, queue_m, &queue_mask);
# # # # ]
12493 [ # # ]: 0 : if (!queue_m || !queue_v)
12494 : 0 : return;
12495 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_V) {
12496 : 0 : queue = queue_v->queue;
12497 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_V)
12498 : 0 : queue &= queue_m->queue;
12499 : : } else {
12500 : 0 : queue = queue_m->queue;
12501 : : }
12502 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, source_sqn, queue);
12503 : : }
12504 : :
12505 : : /**
12506 : : * Set the hash fields according to the @p flow information.
12507 : : *
12508 : : * @param[in] item_flags
12509 : : * The match pattern item flags.
12510 : : * @param[in] rss_desc
12511 : : * Pointer to the mlx5_flow_rss_desc.
12512 : : * @param[out] hash_fields
12513 : : * Pointer to the RSS hash fields.
12514 : : */
12515 : : void
12516 : 0 : flow_dv_hashfields_set(uint64_t item_flags,
12517 : : struct mlx5_flow_rss_desc *rss_desc,
12518 : : uint64_t *hash_fields)
12519 : : {
12520 : : uint64_t items = item_flags;
12521 : : uint64_t fields = 0;
12522 : : int rss_inner = 0;
12523 [ # # ]: 0 : uint64_t rss_types = rte_eth_rss_hf_refine(rss_desc->types);
12524 : :
12525 : : *hash_fields = 0;
12526 : : #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
12527 [ # # ]: 0 : if (rss_desc->level >= 2)
12528 : : rss_inner = 1;
12529 : : #endif
12530 [ # # # # ]: 0 : if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV4)) ||
12531 [ # # ]: 0 : (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV4))) {
12532 [ # # ]: 0 : if (rss_types & MLX5_IPV4_LAYER_TYPES) {
12533 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
12534 : : fields |= IBV_RX_HASH_SRC_IPV4;
12535 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
12536 : : fields |= IBV_RX_HASH_DST_IPV4;
12537 : : else
12538 : : fields |= MLX5_IPV4_IBV_RX_HASH;
12539 : : }
12540 [ # # # # : 0 : } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
# # ]
12541 [ # # ]: 0 : (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV6))) {
12542 [ # # ]: 0 : if (rss_types & MLX5_IPV6_LAYER_TYPES) {
12543 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
12544 : : fields |= IBV_RX_HASH_SRC_IPV6;
12545 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
12546 : : fields |= IBV_RX_HASH_DST_IPV6;
12547 : : else
12548 : : fields |= MLX5_IPV6_IBV_RX_HASH;
12549 : : }
12550 : : }
12551 [ # # ]: 0 : if (items & MLX5_FLOW_ITEM_ESP) {
12552 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_ESP)
12553 : 0 : fields |= IBV_RX_HASH_IPSEC_SPI;
12554 : : }
12555 [ # # ]: 0 : if ((fields & ~IBV_RX_HASH_IPSEC_SPI) == 0) {
12556 : 0 : *hash_fields = fields;
12557 : : /*
12558 : : * There is no match between the RSS types and the
12559 : : * L3 protocol (IPv4/IPv6) defined in the flow rule.
12560 : : */
12561 : 0 : return;
12562 : : }
12563 [ # # # # : 0 : if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_UDP)) ||
# # ]
12564 [ # # ]: 0 : (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_UDP))) {
12565 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_UDP) {
12566 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
12567 : 0 : fields |= IBV_RX_HASH_SRC_PORT_UDP;
12568 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
12569 : 0 : fields |= IBV_RX_HASH_DST_PORT_UDP;
12570 : : else
12571 : 0 : fields |= MLX5_UDP_IBV_RX_HASH;
12572 : : }
12573 [ # # # # : 0 : } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_TCP)) ||
# # ]
12574 [ # # ]: 0 : (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_TCP))) {
12575 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_TCP) {
12576 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
12577 : 0 : fields |= IBV_RX_HASH_SRC_PORT_TCP;
12578 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
12579 : 0 : fields |= IBV_RX_HASH_DST_PORT_TCP;
12580 : : else
12581 : 0 : fields |= MLX5_TCP_IBV_RX_HASH;
12582 : : }
12583 : : }
12584 [ # # ]: 0 : if (rss_inner)
12585 : 0 : fields |= IBV_RX_HASH_INNER;
12586 : 0 : *hash_fields = fields;
12587 : : }
12588 : :
12589 : : /**
12590 : : * Prepare an Rx Hash queue.
12591 : : *
12592 : : * @param dev
12593 : : * Pointer to Ethernet device.
12594 : : * @param[in] dev_flow
12595 : : * Pointer to the mlx5_flow.
12596 : : * @param[in] rss_desc
12597 : : * Pointer to the mlx5_flow_rss_desc.
12598 : : * @param[out] hrxq_idx
12599 : : * Hash Rx queue index.
12600 : : *
12601 : : * @return
12602 : : * The Verbs/DevX object initialised, NULL otherwise and rte_errno is set.
12603 : : */
12604 : : static struct mlx5_hrxq *
12605 : 0 : flow_dv_hrxq_prepare(struct rte_eth_dev *dev,
12606 : : struct mlx5_flow *dev_flow,
12607 : : struct mlx5_flow_rss_desc *rss_desc,
12608 : : uint32_t *hrxq_idx)
12609 : : {
12610 : 0 : struct mlx5_flow_handle *dh = dev_flow->handle;
12611 : 0 : uint32_t shared_rss = rss_desc->shared_rss;
12612 : : struct mlx5_hrxq *hrxq;
12613 : :
12614 : : MLX5_ASSERT(rss_desc->queue_num);
12615 : 0 : rss_desc->symmetric_hash_function = dev_flow->symmetric_hash_function;
12616 : 0 : rss_desc->key_len = MLX5_RSS_HASH_KEY_LEN;
12617 : 0 : rss_desc->hash_fields = dev_flow->hash_fields;
12618 : 0 : rss_desc->tunnel = !!(dh->layers & MLX5_FLOW_LAYER_TUNNEL);
12619 : 0 : rss_desc->shared_rss = 0;
12620 [ # # ]: 0 : if (rss_desc->hash_fields == 0)
12621 : 0 : rss_desc->queue_num = 1;
12622 : 0 : hrxq = mlx5_hrxq_get(dev, rss_desc);
12623 [ # # ]: 0 : *hrxq_idx = hrxq ? hrxq->idx : 0;
12624 : 0 : rss_desc->shared_rss = shared_rss;
12625 : 0 : return hrxq;
12626 : : }
12627 : :
12628 : : /**
12629 : : * Release sample sub action resource.
12630 : : *
12631 : : * @param[in, out] dev
12632 : : * Pointer to rte_eth_dev structure.
12633 : : * @param[in] act_res
12634 : : * Pointer to sample sub action resource.
12635 : : */
12636 : : static void
12637 : 0 : flow_dv_sample_sub_actions_release(struct rte_eth_dev *dev,
12638 : : struct mlx5_flow_sub_actions_idx *act_res)
12639 : : {
12640 [ # # ]: 0 : if (act_res->rix_hrxq) {
12641 : 0 : mlx5_hrxq_release(dev, act_res->rix_hrxq);
12642 : 0 : act_res->rix_hrxq = 0;
12643 : : }
12644 [ # # ]: 0 : if (act_res->rix_encap_decap) {
12645 : 0 : flow_encap_decap_resource_release(dev,
12646 : : act_res->rix_encap_decap);
12647 : 0 : act_res->rix_encap_decap = 0;
12648 : : }
12649 [ # # ]: 0 : if (act_res->rix_port_id_action) {
12650 : 0 : flow_dv_port_id_action_resource_release(dev,
12651 : : act_res->rix_port_id_action);
12652 : 0 : act_res->rix_port_id_action = 0;
12653 : : }
12654 [ # # ]: 0 : if (act_res->rix_tag) {
12655 : 0 : flow_dv_tag_release(dev, act_res->rix_tag);
12656 : 0 : act_res->rix_tag = 0;
12657 : : }
12658 [ # # ]: 0 : if (act_res->rix_jump) {
12659 : 0 : flow_dv_jump_tbl_resource_release(dev, act_res->rix_jump);
12660 : 0 : act_res->rix_jump = 0;
12661 : : }
12662 : 0 : }
12663 : :
12664 : : int
12665 : 0 : flow_dv_sample_match_cb(void *tool_ctx __rte_unused,
12666 : : struct mlx5_list_entry *entry, void *cb_ctx)
12667 : : {
12668 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12669 : 0 : struct rte_eth_dev *dev = ctx->dev;
12670 : 0 : struct mlx5_flow_dv_sample_resource *ctx_resource = ctx->data;
12671 : : struct mlx5_flow_dv_sample_resource *resource = container_of(entry,
12672 : : typeof(*resource),
12673 : : entry);
12674 : :
12675 [ # # ]: 0 : if (ctx_resource->ratio == resource->ratio &&
12676 [ # # ]: 0 : ctx_resource->ft_type == resource->ft_type &&
12677 [ # # ]: 0 : ctx_resource->ft_id == resource->ft_id &&
12678 [ # # ]: 0 : ctx_resource->set_action == resource->set_action &&
12679 : 0 : !memcmp((void *)&ctx_resource->sample_act,
12680 [ # # ]: 0 : (void *)&resource->sample_act,
12681 : : sizeof(struct mlx5_flow_sub_actions_list))) {
12682 : : /*
12683 : : * Existing sample action should release the prepared
12684 : : * sub-actions reference counter.
12685 : : */
12686 : 0 : flow_dv_sample_sub_actions_release(dev,
12687 : : &ctx_resource->sample_idx);
12688 : 0 : return 0;
12689 : : }
12690 : : return 1;
12691 : : }
12692 : :
12693 : : struct mlx5_list_entry *
12694 : 0 : flow_dv_sample_create_cb(void *tool_ctx __rte_unused, void *cb_ctx)
12695 : : {
12696 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12697 : 0 : struct rte_eth_dev *dev = ctx->dev;
12698 : 0 : struct mlx5_flow_dv_sample_resource *ctx_resource = ctx->data;
12699 : 0 : void **sample_dv_actions = ctx_resource->sub_actions;
12700 : : struct mlx5_flow_dv_sample_resource *resource;
12701 : : struct mlx5dv_dr_flow_sampler_attr sampler_attr;
12702 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12703 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
12704 : : struct mlx5_flow_tbl_resource *tbl;
12705 : 0 : uint32_t idx = 0;
12706 : : const uint32_t next_ft_step = 1;
12707 : 0 : uint32_t next_ft_id = ctx_resource->ft_id + next_ft_step;
12708 : : uint8_t is_egress = 0;
12709 : : uint8_t is_transfer = 0;
12710 : 0 : struct rte_flow_error *error = ctx->error;
12711 : :
12712 : : /* Register new sample resource. */
12713 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_SAMPLE], &idx);
12714 [ # # ]: 0 : if (!resource) {
12715 : 0 : rte_flow_error_set(error, ENOMEM,
12716 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12717 : : NULL,
12718 : : "cannot allocate resource memory");
12719 : 0 : return NULL;
12720 : : }
12721 : 0 : *resource = *ctx_resource;
12722 : : /* Create normal path table level */
12723 [ # # ]: 0 : if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
12724 : : is_transfer = 1;
12725 [ # # ]: 0 : else if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
12726 : : is_egress = 1;
12727 : 0 : tbl = flow_dv_tbl_resource_get(dev, next_ft_id,
12728 : : is_egress, is_transfer,
12729 : : true, NULL, 0, 0, 0, error);
12730 [ # # ]: 0 : if (!tbl) {
12731 : 0 : rte_flow_error_set(error, ENOMEM,
12732 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12733 : : NULL,
12734 : : "fail to create normal path table "
12735 : : "for sample");
12736 : 0 : goto error;
12737 : : }
12738 : 0 : resource->normal_path_tbl = tbl;
12739 [ # # ]: 0 : if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB) {
12740 [ # # ]: 0 : if (!sh->default_miss_action) {
12741 : 0 : rte_flow_error_set(error, ENOMEM,
12742 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12743 : : NULL,
12744 : : "default miss action was not "
12745 : : "created");
12746 : 0 : goto error;
12747 : : }
12748 : 0 : sample_dv_actions[ctx_resource->sample_act.actions_num++] =
12749 : : sh->default_miss_action;
12750 : : }
12751 : : /* Create a DR sample action */
12752 : 0 : sampler_attr.sample_ratio = resource->ratio;
12753 : 0 : sampler_attr.default_next_table = tbl->obj;
12754 : 0 : sampler_attr.num_sample_actions = ctx_resource->sample_act.actions_num;
12755 : 0 : sampler_attr.sample_actions = (struct mlx5dv_dr_action **)
12756 : : &sample_dv_actions[0];
12757 : 0 : sampler_attr.action = resource->set_action;
12758 : : if (mlx5_os_flow_dr_create_flow_action_sampler
12759 : : (&sampler_attr, &resource->verbs_action)) {
12760 : 0 : rte_flow_error_set(error, ENOMEM,
12761 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12762 : : NULL, "cannot create sample action");
12763 : 0 : goto error;
12764 : : }
12765 : 0 : resource->idx = idx;
12766 : 0 : resource->dev = dev;
12767 : 0 : return &resource->entry;
12768 : 0 : error:
12769 [ # # ]: 0 : if (resource->ft_type != MLX5DV_FLOW_TABLE_TYPE_FDB)
12770 : 0 : flow_dv_sample_sub_actions_release(dev,
12771 : : &resource->sample_idx);
12772 [ # # ]: 0 : if (resource->normal_path_tbl)
12773 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev),
12774 : : resource->normal_path_tbl);
12775 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_SAMPLE], idx);
12776 : 0 : return NULL;
12777 : :
12778 : : }
12779 : :
12780 : : struct mlx5_list_entry *
12781 : 0 : flow_dv_sample_clone_cb(void *tool_ctx __rte_unused,
12782 : : struct mlx5_list_entry *entry __rte_unused,
12783 : : void *cb_ctx)
12784 : : {
12785 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12786 : 0 : struct rte_eth_dev *dev = ctx->dev;
12787 : : struct mlx5_flow_dv_sample_resource *resource;
12788 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12789 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
12790 : 0 : uint32_t idx = 0;
12791 : :
12792 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_SAMPLE], &idx);
12793 [ # # ]: 0 : if (!resource) {
12794 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12795 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12796 : : NULL,
12797 : : "cannot allocate resource memory");
12798 : 0 : return NULL;
12799 : : }
12800 : : memcpy(resource, entry, sizeof(*resource));
12801 : 0 : resource->idx = idx;
12802 : 0 : resource->dev = dev;
12803 : 0 : return &resource->entry;
12804 : : }
12805 : :
12806 : : void
12807 : 0 : flow_dv_sample_clone_free_cb(void *tool_ctx __rte_unused,
12808 : : struct mlx5_list_entry *entry)
12809 : : {
12810 : : struct mlx5_flow_dv_sample_resource *resource =
12811 : : container_of(entry, typeof(*resource), entry);
12812 : 0 : struct rte_eth_dev *dev = resource->dev;
12813 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12814 : :
12815 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_SAMPLE], resource->idx);
12816 : 0 : }
12817 : :
12818 : : /**
12819 : : * Find existing sample resource or create and register a new one.
12820 : : *
12821 : : * @param[in, out] dev
12822 : : * Pointer to rte_eth_dev structure.
12823 : : * @param[in] ref
12824 : : * Pointer to sample resource reference.
12825 : : * @parm[in, out] dev_flow
12826 : : * Pointer to the dev_flow.
12827 : : * @param[out] error
12828 : : * pointer to error structure.
12829 : : *
12830 : : * @return
12831 : : * 0 on success otherwise -errno and errno is set.
12832 : : */
12833 : : static int
12834 : 0 : flow_dv_sample_resource_register(struct rte_eth_dev *dev,
12835 : : struct mlx5_flow_dv_sample_resource *ref,
12836 : : struct mlx5_flow *dev_flow,
12837 : : struct rte_flow_error *error)
12838 : : {
12839 : : struct mlx5_flow_dv_sample_resource *resource;
12840 : : struct mlx5_list_entry *entry;
12841 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12842 : 0 : struct mlx5_flow_cb_ctx ctx = {
12843 : : .dev = dev,
12844 : : .error = error,
12845 : : .data = ref,
12846 : : };
12847 : :
12848 : 0 : entry = mlx5_list_register(priv->sh->sample_action_list, &ctx);
12849 [ # # ]: 0 : if (!entry)
12850 : 0 : return -rte_errno;
12851 : : resource = container_of(entry, typeof(*resource), entry);
12852 : 0 : dev_flow->handle->dvh.rix_sample = resource->idx;
12853 : 0 : dev_flow->dv.sample_res = resource;
12854 : 0 : return 0;
12855 : : }
12856 : :
12857 : : int
12858 : 0 : flow_dv_dest_array_match_cb(void *tool_ctx __rte_unused,
12859 : : struct mlx5_list_entry *entry, void *cb_ctx)
12860 : : {
12861 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12862 : 0 : struct mlx5_flow_dv_dest_array_resource *ctx_resource = ctx->data;
12863 : 0 : struct rte_eth_dev *dev = ctx->dev;
12864 : : struct mlx5_flow_dv_dest_array_resource *resource =
12865 : : container_of(entry, typeof(*resource), entry);
12866 : : uint32_t idx = 0;
12867 : :
12868 [ # # ]: 0 : if (ctx_resource->num_of_dest == resource->num_of_dest &&
12869 : 0 : ctx_resource->ft_type == resource->ft_type &&
12870 : 0 : !memcmp((void *)resource->sample_act,
12871 : 0 : (void *)ctx_resource->sample_act,
12872 [ # # ]: 0 : (ctx_resource->num_of_dest *
12873 : : sizeof(struct mlx5_flow_sub_actions_list)))) {
12874 : : /*
12875 : : * Existing sample action should release the prepared
12876 : : * sub-actions reference counter.
12877 : : */
12878 [ # # ]: 0 : for (idx = 0; idx < ctx_resource->num_of_dest; idx++)
12879 : 0 : flow_dv_sample_sub_actions_release(dev,
12880 : : &ctx_resource->sample_idx[idx]);
12881 : : return 0;
12882 : : }
12883 : : return 1;
12884 : : }
12885 : :
12886 : : struct mlx5_list_entry *
12887 : 0 : flow_dv_dest_array_create_cb(void *tool_ctx __rte_unused, void *cb_ctx)
12888 : : {
12889 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12890 : 0 : struct rte_eth_dev *dev = ctx->dev;
12891 : : struct mlx5_flow_dv_dest_array_resource *resource;
12892 : 0 : struct mlx5_flow_dv_dest_array_resource *ctx_resource = ctx->data;
12893 : 0 : struct mlx5dv_dr_action_dest_attr *dest_attr[MLX5_MAX_DEST_NUM] = { 0 };
12894 : : struct mlx5dv_dr_action_dest_reformat dest_reformat[MLX5_MAX_DEST_NUM];
12895 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12896 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
12897 : : struct mlx5_flow_sub_actions_list *sample_act;
12898 : : struct mlx5dv_dr_domain *domain;
12899 : 0 : uint32_t idx = 0, res_idx = 0;
12900 : 0 : struct rte_flow_error *error = ctx->error;
12901 : : uint64_t action_flags;
12902 : : int ret;
12903 : :
12904 : : /* Register new destination array resource. */
12905 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DEST_ARRAY],
12906 : : &res_idx);
12907 [ # # ]: 0 : if (!resource) {
12908 : 0 : rte_flow_error_set(error, ENOMEM,
12909 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12910 : : NULL,
12911 : : "cannot allocate resource memory");
12912 : 0 : return NULL;
12913 : : }
12914 : 0 : *resource = *ctx_resource;
12915 [ # # ]: 0 : if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
12916 : 0 : domain = sh->fdb_domain;
12917 [ # # ]: 0 : else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
12918 : 0 : domain = sh->rx_domain;
12919 : : else
12920 : 0 : domain = sh->tx_domain;
12921 [ # # ]: 0 : for (idx = 0; idx < ctx_resource->num_of_dest; idx++) {
12922 : 0 : dest_attr[idx] = (struct mlx5dv_dr_action_dest_attr *)
12923 : 0 : mlx5_malloc(MLX5_MEM_ZERO,
12924 : : sizeof(struct mlx5dv_dr_action_dest_attr),
12925 : : 0, SOCKET_ID_ANY);
12926 [ # # ]: 0 : if (!dest_attr[idx]) {
12927 : 0 : rte_flow_error_set(error, ENOMEM,
12928 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12929 : : NULL,
12930 : : "cannot allocate resource memory");
12931 : 0 : goto error;
12932 : : }
12933 : 0 : dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST;
12934 : : sample_act = &ctx_resource->sample_act[idx];
12935 : 0 : action_flags = sample_act->action_flags;
12936 [ # # # # : 0 : switch (action_flags) {
# ]
12937 : 0 : case MLX5_FLOW_ACTION_QUEUE:
12938 : 0 : dest_attr[idx]->dest = sample_act->dr_queue_action;
12939 : 0 : break;
12940 : 0 : case (MLX5_FLOW_ACTION_PORT_ID | MLX5_FLOW_ACTION_ENCAP):
12941 : 0 : dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST_REFORMAT;
12942 : 0 : dest_attr[idx]->dest_reformat = &dest_reformat[idx];
12943 : 0 : dest_attr[idx]->dest_reformat->reformat =
12944 : 0 : sample_act->dr_encap_action;
12945 : 0 : dest_attr[idx]->dest_reformat->dest =
12946 : 0 : sample_act->dr_port_id_action;
12947 : 0 : break;
12948 : 0 : case MLX5_FLOW_ACTION_PORT_ID:
12949 : 0 : dest_attr[idx]->dest = sample_act->dr_port_id_action;
12950 : 0 : break;
12951 : 0 : case MLX5_FLOW_ACTION_JUMP:
12952 : 0 : dest_attr[idx]->dest = sample_act->dr_jump_action;
12953 : 0 : break;
12954 : 0 : default:
12955 : 0 : rte_flow_error_set(error, EINVAL,
12956 : : RTE_FLOW_ERROR_TYPE_ACTION,
12957 : : NULL,
12958 : : "unsupported actions type");
12959 : 0 : goto error;
12960 : : }
12961 : : }
12962 : : /* create a dest array action */
12963 : 0 : ret = mlx5_os_flow_dr_create_flow_action_dest_array
12964 : : (domain,
12965 : 0 : resource->num_of_dest,
12966 : : dest_attr,
12967 : : &resource->action);
12968 : : if (ret) {
12969 : 0 : rte_flow_error_set(error, ENOMEM,
12970 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12971 : : NULL,
12972 : : "cannot create destination array action");
12973 : 0 : goto error;
12974 : : }
12975 : 0 : resource->idx = res_idx;
12976 : 0 : resource->dev = dev;
12977 [ # # ]: 0 : for (idx = 0; idx < ctx_resource->num_of_dest; idx++)
12978 : 0 : mlx5_free(dest_attr[idx]);
12979 : 0 : return &resource->entry;
12980 : : error:
12981 [ # # ]: 0 : for (idx = 0; idx < ctx_resource->num_of_dest; idx++) {
12982 : 0 : flow_dv_sample_sub_actions_release(dev,
12983 : : &resource->sample_idx[idx]);
12984 [ # # ]: 0 : if (dest_attr[idx])
12985 : 0 : mlx5_free(dest_attr[idx]);
12986 : : }
12987 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DEST_ARRAY], res_idx);
12988 : 0 : return NULL;
12989 : : }
12990 : :
12991 : : struct mlx5_list_entry *
12992 : 0 : flow_dv_dest_array_clone_cb(void *tool_ctx __rte_unused,
12993 : : struct mlx5_list_entry *entry __rte_unused,
12994 : : void *cb_ctx)
12995 : : {
12996 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12997 : 0 : struct rte_eth_dev *dev = ctx->dev;
12998 : : struct mlx5_flow_dv_dest_array_resource *resource;
12999 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13000 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
13001 : 0 : uint32_t res_idx = 0;
13002 : 0 : struct rte_flow_error *error = ctx->error;
13003 : :
13004 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DEST_ARRAY],
13005 : : &res_idx);
13006 [ # # ]: 0 : if (!resource) {
13007 : 0 : rte_flow_error_set(error, ENOMEM,
13008 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13009 : : NULL,
13010 : : "cannot allocate dest-array memory");
13011 : 0 : return NULL;
13012 : : }
13013 : : memcpy(resource, entry, sizeof(*resource));
13014 : 0 : resource->idx = res_idx;
13015 : 0 : resource->dev = dev;
13016 : 0 : return &resource->entry;
13017 : : }
13018 : :
13019 : : void
13020 : 0 : flow_dv_dest_array_clone_free_cb(void *tool_ctx __rte_unused,
13021 : : struct mlx5_list_entry *entry)
13022 : : {
13023 : : struct mlx5_flow_dv_dest_array_resource *resource =
13024 : : container_of(entry, typeof(*resource), entry);
13025 : 0 : struct rte_eth_dev *dev = resource->dev;
13026 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13027 : :
13028 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY], resource->idx);
13029 : 0 : }
13030 : :
13031 : : /**
13032 : : * Find existing destination array resource or create and register a new one.
13033 : : *
13034 : : * @param[in, out] dev
13035 : : * Pointer to rte_eth_dev structure.
13036 : : * @param[in] ref
13037 : : * Pointer to destination array resource reference.
13038 : : * @parm[in, out] dev_flow
13039 : : * Pointer to the dev_flow.
13040 : : * @param[out] error
13041 : : * pointer to error structure.
13042 : : *
13043 : : * @return
13044 : : * 0 on success otherwise -errno and errno is set.
13045 : : */
13046 : : static int
13047 : 0 : flow_dv_dest_array_resource_register(struct rte_eth_dev *dev,
13048 : : struct mlx5_flow_dv_dest_array_resource *ref,
13049 : : struct mlx5_flow *dev_flow,
13050 : : struct rte_flow_error *error)
13051 : : {
13052 : : struct mlx5_flow_dv_dest_array_resource *resource;
13053 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13054 : : struct mlx5_list_entry *entry;
13055 : 0 : struct mlx5_flow_cb_ctx ctx = {
13056 : : .dev = dev,
13057 : : .error = error,
13058 : : .data = ref,
13059 : : };
13060 : :
13061 : 0 : entry = mlx5_list_register(priv->sh->dest_array_list, &ctx);
13062 [ # # ]: 0 : if (!entry)
13063 : 0 : return -rte_errno;
13064 : : resource = container_of(entry, typeof(*resource), entry);
13065 : 0 : dev_flow->handle->dvh.rix_dest_array = resource->idx;
13066 : 0 : dev_flow->dv.dest_array_res = resource;
13067 : 0 : return 0;
13068 : : }
13069 : :
13070 : : /**
13071 : : * Convert Sample action to DV specification.
13072 : : *
13073 : : * @param[in] dev
13074 : : * Pointer to rte_eth_dev structure.
13075 : : * @param[in] action
13076 : : * Pointer to sample action structure.
13077 : : * @param[in, out] dev_flow
13078 : : * Pointer to the mlx5_flow.
13079 : : * @param[in] attr
13080 : : * Pointer to the flow attributes.
13081 : : * @param[in, out] num_of_dest
13082 : : * Pointer to the num of destination.
13083 : : * @param[in, out] sample_actions
13084 : : * Pointer to sample actions list.
13085 : : * @param[in, out] res
13086 : : * Pointer to sample resource.
13087 : : * @param[out] error
13088 : : * Pointer to the error structure.
13089 : : *
13090 : : * @return
13091 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
13092 : : */
13093 : : static int
13094 : 0 : flow_dv_translate_action_sample(struct rte_eth_dev *dev,
13095 : : const struct rte_flow_action_sample *action,
13096 : : struct mlx5_flow *dev_flow,
13097 : : const struct rte_flow_attr *attr,
13098 : : uint32_t *num_of_dest,
13099 : : void **sample_actions,
13100 : : struct mlx5_flow_dv_sample_resource *res,
13101 : : struct rte_flow_error *error)
13102 : : {
13103 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13104 : : const struct rte_flow_action *sub_actions;
13105 : : struct mlx5_flow_sub_actions_list *sample_act;
13106 : : struct mlx5_flow_sub_actions_idx *sample_idx;
13107 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
13108 : 0 : struct rte_flow *flow = dev_flow->flow;
13109 : : struct mlx5_flow_rss_desc *rss_desc;
13110 : : uint64_t action_flags = 0;
13111 : :
13112 : : MLX5_ASSERT(wks);
13113 : 0 : rss_desc = &wks->rss_desc;
13114 : : sample_act = &res->sample_act;
13115 : : sample_idx = &res->sample_idx;
13116 : 0 : res->ratio = action->ratio;
13117 : 0 : sub_actions = action->actions;
13118 [ # # ]: 0 : for (; sub_actions->type != RTE_FLOW_ACTION_TYPE_END; sub_actions++) {
13119 : : int type = sub_actions->type;
13120 : : uint32_t pre_rix = 0;
13121 : : void *pre_r;
13122 [ # # # # : 0 : switch (type) {
# # # ]
13123 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
13124 : : {
13125 : : const struct rte_flow_action_queue *queue;
13126 : : struct mlx5_hrxq *hrxq;
13127 : : uint32_t hrxq_idx;
13128 : :
13129 : 0 : queue = sub_actions->conf;
13130 : 0 : rss_desc->queue_num = 1;
13131 : 0 : rss_desc->queue[0] = queue->index;
13132 : 0 : hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
13133 : : rss_desc, &hrxq_idx);
13134 [ # # ]: 0 : if (!hrxq)
13135 : 0 : return rte_flow_error_set
13136 : : (error, rte_errno,
13137 : : RTE_FLOW_ERROR_TYPE_ACTION,
13138 : : NULL,
13139 : : "cannot create fate queue");
13140 : 0 : sample_act->dr_queue_action = hrxq->action;
13141 : 0 : sample_idx->rix_hrxq = hrxq_idx;
13142 : 0 : sample_actions[sample_act->actions_num++] =
13143 : : hrxq->action;
13144 : 0 : (*num_of_dest)++;
13145 : 0 : action_flags |= MLX5_FLOW_ACTION_QUEUE;
13146 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
13147 : 0 : dev_flow->handle->rix_hrxq = hrxq_idx;
13148 : 0 : dev_flow->handle->fate_action =
13149 : : MLX5_FLOW_FATE_QUEUE;
13150 : 0 : break;
13151 : : }
13152 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
13153 : : {
13154 : : struct mlx5_hrxq *hrxq;
13155 : : uint32_t hrxq_idx;
13156 : : const struct rte_flow_action_rss *rss;
13157 : : const uint8_t *rss_key;
13158 : :
13159 : 0 : rss = sub_actions->conf;
13160 : 0 : rss_desc->symmetric_hash_function =
13161 : 0 : MLX5_RSS_IS_SYMM(rss->func);
13162 : 0 : memcpy(rss_desc->queue, rss->queue,
13163 [ # # ]: 0 : rss->queue_num * sizeof(uint16_t));
13164 : 0 : rss_desc->queue_num = rss->queue_num;
13165 : : /* NULL RSS key indicates default RSS key. */
13166 [ # # ]: 0 : rss_key = !rss->key ? rss_hash_default_key : rss->key;
13167 : 0 : memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
13168 : : /*
13169 : : * rss->level and rss.types should be set in advance
13170 : : * when expanding items for RSS.
13171 : : */
13172 : 0 : flow_dv_hashfields_set(dev_flow->handle->layers,
13173 : : rss_desc,
13174 : : &dev_flow->hash_fields);
13175 : 0 : hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
13176 : : rss_desc, &hrxq_idx);
13177 [ # # ]: 0 : if (!hrxq)
13178 : 0 : return rte_flow_error_set
13179 : : (error, rte_errno,
13180 : : RTE_FLOW_ERROR_TYPE_ACTION,
13181 : : NULL,
13182 : : "cannot create fate queue");
13183 : 0 : sample_act->dr_queue_action = hrxq->action;
13184 : 0 : sample_idx->rix_hrxq = hrxq_idx;
13185 : 0 : sample_actions[sample_act->actions_num++] =
13186 : : hrxq->action;
13187 : 0 : (*num_of_dest)++;
13188 : 0 : action_flags |= MLX5_FLOW_ACTION_RSS;
13189 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
13190 : 0 : dev_flow->handle->rix_hrxq = hrxq_idx;
13191 : 0 : dev_flow->handle->fate_action =
13192 : : MLX5_FLOW_FATE_QUEUE;
13193 : 0 : break;
13194 : : }
13195 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
13196 : : {
13197 : : uint32_t tag_be = mlx5_flow_mark_set
13198 : : (((const struct rte_flow_action_mark *)
13199 [ # # ]: 0 : (sub_actions->conf))->id);
13200 : :
13201 : 0 : wks->mark = 1;
13202 : 0 : pre_rix = dev_flow->handle->dvh.rix_tag;
13203 : : /* Save the mark resource before sample */
13204 : 0 : pre_r = dev_flow->dv.tag_resource;
13205 [ # # ]: 0 : if (flow_dv_tag_resource_register(dev, tag_be,
13206 : : dev_flow, error))
13207 : 0 : return -rte_errno;
13208 : : MLX5_ASSERT(dev_flow->dv.tag_resource);
13209 : 0 : sample_act->dr_tag_action =
13210 : 0 : dev_flow->dv.tag_resource->action;
13211 : 0 : sample_idx->rix_tag =
13212 : 0 : dev_flow->handle->dvh.rix_tag;
13213 : 0 : sample_actions[sample_act->actions_num++] =
13214 : : sample_act->dr_tag_action;
13215 : : /* Recover the mark resource after sample */
13216 : 0 : dev_flow->dv.tag_resource = pre_r;
13217 : 0 : dev_flow->handle->dvh.rix_tag = pre_rix;
13218 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK;
13219 : 0 : break;
13220 : : }
13221 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
13222 : : {
13223 [ # # ]: 0 : if (!flow->counter) {
13224 : 0 : flow->counter =
13225 : 0 : flow_dv_translate_create_counter(dev,
13226 : 0 : dev_flow, sub_actions->conf,
13227 : : 0);
13228 [ # # ]: 0 : if (!flow->counter)
13229 : 0 : return rte_flow_error_set
13230 : : (error, rte_errno,
13231 : : RTE_FLOW_ERROR_TYPE_ACTION,
13232 : : NULL,
13233 : : "cannot create counter"
13234 : : " object.");
13235 : : }
13236 : 0 : sample_act->dr_cnt_action =
13237 [ # # ]: 0 : (flow_dv_counter_get_by_idx(dev,
13238 : 0 : flow->counter, NULL))->action;
13239 : 0 : sample_actions[sample_act->actions_num++] =
13240 : : sample_act->dr_cnt_action;
13241 : 0 : action_flags |= MLX5_FLOW_ACTION_COUNT;
13242 : 0 : break;
13243 : : }
13244 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
13245 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
13246 : : {
13247 : : struct mlx5_flow_dv_port_id_action_resource
13248 : : port_id_resource;
13249 : 0 : uint32_t port_id = 0;
13250 : :
13251 : : memset(&port_id_resource, 0, sizeof(port_id_resource));
13252 : : /* Save the port id resource before sample */
13253 : 0 : pre_rix = dev_flow->handle->rix_port_id_action;
13254 : 0 : pre_r = dev_flow->dv.port_id_action;
13255 [ # # ]: 0 : if (flow_dv_translate_action_port_id(dev, sub_actions,
13256 : : &port_id, error))
13257 : 0 : return -rte_errno;
13258 : 0 : port_id_resource.port_id = port_id;
13259 [ # # ]: 0 : if (flow_dv_port_id_action_resource_register
13260 : : (dev, &port_id_resource, dev_flow, error))
13261 : 0 : return -rte_errno;
13262 : 0 : sample_act->dr_port_id_action =
13263 : 0 : dev_flow->dv.port_id_action->action;
13264 : 0 : sample_idx->rix_port_id_action =
13265 : 0 : dev_flow->handle->rix_port_id_action;
13266 : 0 : sample_actions[sample_act->actions_num++] =
13267 : : sample_act->dr_port_id_action;
13268 : : /* Recover the port id resource after sample */
13269 : 0 : dev_flow->dv.port_id_action = pre_r;
13270 : 0 : dev_flow->handle->rix_port_id_action = pre_rix;
13271 : 0 : (*num_of_dest)++;
13272 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_ID;
13273 : 0 : break;
13274 : : }
13275 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
13276 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
13277 : : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
13278 : : /* Save the encap resource before sample */
13279 : 0 : pre_rix = dev_flow->handle->dvh.rix_encap_decap;
13280 : 0 : pre_r = dev_flow->dv.encap_decap;
13281 [ # # ]: 0 : if (flow_dv_create_action_l2_encap(dev, sub_actions,
13282 : : dev_flow,
13283 : 0 : attr->transfer,
13284 : : error))
13285 : 0 : return -rte_errno;
13286 : 0 : sample_act->dr_encap_action =
13287 : 0 : dev_flow->dv.encap_decap->action;
13288 : 0 : sample_idx->rix_encap_decap =
13289 : 0 : dev_flow->handle->dvh.rix_encap_decap;
13290 : 0 : sample_actions[sample_act->actions_num++] =
13291 : : sample_act->dr_encap_action;
13292 : : /* Recover the encap resource after sample */
13293 : 0 : dev_flow->dv.encap_decap = pre_r;
13294 : 0 : dev_flow->handle->dvh.rix_encap_decap = pre_rix;
13295 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
13296 : 0 : break;
13297 : 0 : default:
13298 : 0 : return rte_flow_error_set(error, EINVAL,
13299 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13300 : : NULL,
13301 : : "Not support for sampler action");
13302 : : }
13303 : : }
13304 : 0 : sample_act->action_flags = action_flags;
13305 : 0 : res->ft_id = dev_flow->dv.group;
13306 [ # # ]: 0 : if (attr->transfer) {
13307 : : union {
13308 : : uint32_t action_in[MLX5_ST_SZ_DW(set_action_in)];
13309 : : uint64_t set_action;
13310 : : } action_ctx = { .set_action = 0 };
13311 : 0 : uint32_t vport_meta_tag = wks->vport_meta_tag ?
13312 [ # # ]: 0 : wks->vport_meta_tag :
13313 : : priv->vport_meta_tag;
13314 : :
13315 : 0 : res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
13316 : : MLX5_SET(set_action_in, action_ctx.action_in, action_type,
13317 : : MLX5_MODIFICATION_TYPE_SET);
13318 [ # # ]: 0 : MLX5_SET(set_action_in, action_ctx.action_in, field,
13319 : : MLX5_MODI_META_REG_C_0);
13320 : 0 : MLX5_SET(set_action_in, action_ctx.action_in, data,
13321 : : vport_meta_tag);
13322 : 0 : res->set_action = action_ctx.set_action;
13323 [ # # ]: 0 : } else if (attr->ingress) {
13324 : 0 : res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
13325 : : } else {
13326 : 0 : res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_TX;
13327 : : }
13328 : : return 0;
13329 : : }
13330 : :
13331 : : static void *
13332 : 0 : flow_dv_translate_action_send_to_kernel(struct rte_eth_dev *dev,
13333 : : const struct rte_flow_attr *attr,
13334 : : struct rte_flow_error *error)
13335 : : {
13336 : : struct mlx5_flow_tbl_resource *tbl;
13337 : : struct mlx5_dev_ctx_shared *sh;
13338 : : uint32_t priority;
13339 : : void *action;
13340 : : int ft_type;
13341 : : int ret;
13342 : :
13343 : 0 : sh = MLX5_SH(dev);
13344 [ # # ]: 0 : ft_type = (attr->ingress) ? MLX5DR_TABLE_TYPE_NIC_RX :
13345 [ # # ]: 0 : ((attr->transfer) ? MLX5DR_TABLE_TYPE_FDB :
13346 : : MLX5DR_TABLE_TYPE_NIC_TX);
13347 [ # # ]: 0 : if (sh->send_to_kernel_action[ft_type].action)
13348 : : return sh->send_to_kernel_action[ft_type].action;
13349 : 0 : priority = mlx5_get_send_to_kernel_priority(dev);
13350 [ # # ]: 0 : if (priority == (uint32_t)-1) {
13351 : 0 : rte_flow_error_set(error, ENOTSUP,
13352 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13353 : : "required priority is not available");
13354 : 0 : return NULL;
13355 : : }
13356 : 0 : tbl = flow_dv_tbl_resource_get(dev, 0, attr->egress, attr->transfer, false, NULL, 0, 0, 0,
13357 : : error);
13358 [ # # ]: 0 : if (!tbl) {
13359 : 0 : rte_flow_error_set(error, ENODATA,
13360 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13361 : : "cannot find destination root table");
13362 : 0 : return NULL;
13363 : : }
13364 : 0 : ret = mlx5_flow_os_create_flow_action_send_to_kernel(tbl->obj,
13365 : : priority, &action);
13366 : : if (ret) {
13367 : 0 : rte_flow_error_set(error, ENOMEM,
13368 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13369 : : "cannot create action");
13370 : 0 : goto err;
13371 : : }
13372 : : MLX5_ASSERT(action);
13373 : 0 : sh->send_to_kernel_action[ft_type].action = action;
13374 : 0 : sh->send_to_kernel_action[ft_type].tbl = tbl;
13375 : 0 : return action;
13376 : : err:
13377 : 0 : flow_dv_tbl_resource_release(sh, tbl);
13378 : 0 : return NULL;
13379 : : }
13380 : :
13381 : : /**
13382 : : * Convert Sample action to DV specification.
13383 : : *
13384 : : * @param[in] dev
13385 : : * Pointer to rte_eth_dev structure.
13386 : : * @param[in, out] dev_flow
13387 : : * Pointer to the mlx5_flow.
13388 : : * @param[in] num_of_dest
13389 : : * The num of destination.
13390 : : * @param[in, out] res
13391 : : * Pointer to sample resource.
13392 : : * @param[in, out] mdest_res
13393 : : * Pointer to destination array resource.
13394 : : * @param[in] sample_actions
13395 : : * Pointer to sample path actions list.
13396 : : * @param[in] action_flags
13397 : : * Holds the actions detected until now.
13398 : : * @param[out] error
13399 : : * Pointer to the error structure.
13400 : : *
13401 : : * @return
13402 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
13403 : : */
13404 : : static int
13405 : 0 : flow_dv_create_action_sample(struct rte_eth_dev *dev,
13406 : : struct mlx5_flow *dev_flow,
13407 : : uint32_t num_of_dest,
13408 : : struct mlx5_flow_dv_sample_resource *res,
13409 : : struct mlx5_flow_dv_dest_array_resource *mdest_res,
13410 : : void **sample_actions,
13411 : : uint64_t action_flags,
13412 : : struct rte_flow_error *error)
13413 : : {
13414 : : /* update normal path action resource into last index of array */
13415 : : uint32_t dest_index = MLX5_MAX_DEST_NUM - 1;
13416 : : struct mlx5_flow_sub_actions_list *sample_act =
13417 : : &mdest_res->sample_act[dest_index];
13418 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
13419 : : struct mlx5_flow_rss_desc *rss_desc;
13420 : : uint32_t normal_idx = 0;
13421 : : struct mlx5_hrxq *hrxq;
13422 : : uint32_t hrxq_idx;
13423 : :
13424 : : MLX5_ASSERT(wks);
13425 : 0 : rss_desc = &wks->rss_desc;
13426 [ # # ]: 0 : if (num_of_dest > 1) {
13427 [ # # ]: 0 : if (sample_act->action_flags & MLX5_FLOW_ACTION_QUEUE) {
13428 : : /* Handle QP action for mirroring */
13429 : 0 : hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
13430 : : rss_desc, &hrxq_idx);
13431 [ # # ]: 0 : if (!hrxq)
13432 : 0 : return rte_flow_error_set
13433 : : (error, rte_errno,
13434 : : RTE_FLOW_ERROR_TYPE_ACTION,
13435 : : NULL,
13436 : : "cannot create rx queue");
13437 : : normal_idx++;
13438 : 0 : mdest_res->sample_idx[dest_index].rix_hrxq = hrxq_idx;
13439 : 0 : sample_act->dr_queue_action = hrxq->action;
13440 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
13441 : 0 : dev_flow->handle->rix_hrxq = hrxq_idx;
13442 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
13443 : : }
13444 [ # # ]: 0 : if (sample_act->action_flags & MLX5_FLOW_ACTION_ENCAP) {
13445 : 0 : normal_idx++;
13446 : 0 : mdest_res->sample_idx[dest_index].rix_encap_decap =
13447 : 0 : dev_flow->handle->dvh.rix_encap_decap;
13448 : 0 : sample_act->dr_encap_action =
13449 : 0 : dev_flow->dv.encap_decap->action;
13450 : 0 : dev_flow->handle->dvh.rix_encap_decap = 0;
13451 : : }
13452 [ # # ]: 0 : if (sample_act->action_flags & MLX5_FLOW_ACTION_PORT_ID) {
13453 : 0 : normal_idx++;
13454 : 0 : mdest_res->sample_idx[dest_index].rix_port_id_action =
13455 : 0 : dev_flow->handle->rix_port_id_action;
13456 : 0 : sample_act->dr_port_id_action =
13457 : 0 : dev_flow->dv.port_id_action->action;
13458 : 0 : dev_flow->handle->rix_port_id_action = 0;
13459 : : }
13460 [ # # ]: 0 : if (sample_act->action_flags & MLX5_FLOW_ACTION_JUMP) {
13461 : 0 : normal_idx++;
13462 : 0 : mdest_res->sample_idx[dest_index].rix_jump =
13463 : 0 : dev_flow->handle->rix_jump;
13464 : 0 : sample_act->dr_jump_action =
13465 : 0 : dev_flow->dv.jump->action;
13466 : 0 : dev_flow->handle->rix_jump = 0;
13467 : : }
13468 : 0 : sample_act->actions_num = normal_idx;
13469 : : /* update sample action resource into first index of array */
13470 : 0 : mdest_res->ft_type = res->ft_type;
13471 : 0 : memcpy(&mdest_res->sample_idx[0], &res->sample_idx,
13472 : : sizeof(struct mlx5_flow_sub_actions_idx));
13473 : 0 : memcpy(&mdest_res->sample_act[0], &res->sample_act,
13474 : : sizeof(struct mlx5_flow_sub_actions_list));
13475 : 0 : mdest_res->num_of_dest = num_of_dest;
13476 [ # # ]: 0 : if (flow_dv_dest_array_resource_register(dev, mdest_res,
13477 : : dev_flow, error))
13478 : 0 : return rte_flow_error_set(error, EINVAL,
13479 : : RTE_FLOW_ERROR_TYPE_ACTION,
13480 : : NULL, "can't create sample "
13481 : : "action");
13482 : : } else {
13483 : 0 : res->sub_actions = sample_actions;
13484 [ # # ]: 0 : if (flow_dv_sample_resource_register(dev, res, dev_flow, error))
13485 : 0 : return rte_flow_error_set(error, EINVAL,
13486 : : RTE_FLOW_ERROR_TYPE_ACTION,
13487 : : NULL,
13488 : : "can't create sample action");
13489 : : }
13490 : : return 0;
13491 : : }
13492 : :
13493 : : /**
13494 : : * Remove an ASO age action from age actions list.
13495 : : *
13496 : : * @param[in] dev
13497 : : * Pointer to the Ethernet device structure.
13498 : : * @param[in] age
13499 : : * Pointer to the aso age action handler.
13500 : : */
13501 : : static void
13502 : 0 : flow_dv_aso_age_remove_from_age(struct rte_eth_dev *dev,
13503 : : struct mlx5_aso_age_action *age)
13504 : : {
13505 : : struct mlx5_age_info *age_info;
13506 : : struct mlx5_age_param *age_param = &age->age_params;
13507 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13508 : : uint16_t expected = AGE_CANDIDATE;
13509 : :
13510 : 0 : age_info = GET_PORT_AGE_INFO(priv);
13511 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(&age_param->state, &expected,
13512 : : AGE_FREE, rte_memory_order_relaxed,
13513 : : rte_memory_order_relaxed)) {
13514 : : /**
13515 : : * We need the lock even it is age timeout,
13516 : : * since age action may still in process.
13517 : : */
13518 : 0 : rte_spinlock_lock(&age_info->aged_sl);
13519 [ # # ]: 0 : LIST_REMOVE(age, next);
13520 : : rte_spinlock_unlock(&age_info->aged_sl);
13521 : 0 : rte_atomic_store_explicit(&age_param->state, AGE_FREE, rte_memory_order_relaxed);
13522 : : }
13523 : 0 : }
13524 : :
13525 : : /**
13526 : : * Release an ASO age action.
13527 : : *
13528 : : * @param[in] dev
13529 : : * Pointer to the Ethernet device structure.
13530 : : * @param[in] age_idx
13531 : : * Index of ASO age action to release.
13532 : : * @param[in] flow
13533 : : * True if the release operation is during flow destroy operation.
13534 : : * False if the release operation is during action destroy operation.
13535 : : *
13536 : : * @return
13537 : : * 0 when age action was removed, otherwise the number of references.
13538 : : */
13539 : : static int
13540 : 0 : flow_dv_aso_age_release(struct rte_eth_dev *dev, uint32_t age_idx)
13541 : : {
13542 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13543 : 0 : struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
13544 : 0 : struct mlx5_aso_age_action *age = flow_aso_age_get_by_idx(dev, age_idx);
13545 : 0 : uint32_t ret = rte_atomic_fetch_sub_explicit(&age->refcnt, 1, rte_memory_order_relaxed) - 1;
13546 : :
13547 [ # # ]: 0 : if (!ret) {
13548 : 0 : flow_dv_aso_age_remove_from_age(dev, age);
13549 : 0 : rte_spinlock_lock(&mng->free_sl);
13550 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free, age, next);
13551 : : rte_spinlock_unlock(&mng->free_sl);
13552 : : }
13553 : 0 : return ret;
13554 : : }
13555 : :
13556 : : /**
13557 : : * Resize the ASO age pools array by MLX5_ASO_AGE_CONTAINER_RESIZE pools.
13558 : : *
13559 : : * @param[in] dev
13560 : : * Pointer to the Ethernet device structure.
13561 : : *
13562 : : * @return
13563 : : * 0 on success, otherwise negative errno value and rte_errno is set.
13564 : : */
13565 : : static int
13566 : 0 : flow_dv_aso_age_pools_resize(struct rte_eth_dev *dev)
13567 : : {
13568 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13569 : 0 : struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
13570 : 0 : void *old_pools = mng->pools;
13571 : 0 : uint32_t resize = mng->n + MLX5_ASO_AGE_CONTAINER_RESIZE;
13572 : 0 : uint32_t mem_size = sizeof(struct mlx5_aso_age_pool *) * resize;
13573 : 0 : void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
13574 : :
13575 [ # # ]: 0 : if (!pools) {
13576 : 0 : rte_errno = ENOMEM;
13577 : 0 : return -ENOMEM;
13578 : : }
13579 [ # # ]: 0 : if (old_pools) {
13580 : 0 : memcpy(pools, old_pools,
13581 : 0 : mng->n * sizeof(struct mlx5_flow_counter_pool *));
13582 : 0 : mlx5_free(old_pools);
13583 : : } else {
13584 : : /* First ASO flow hit allocation - starting ASO data-path. */
13585 : 0 : int ret = mlx5_aso_flow_hit_queue_poll_start(priv->sh);
13586 : :
13587 [ # # ]: 0 : if (ret) {
13588 : 0 : mlx5_free(pools);
13589 : 0 : return ret;
13590 : : }
13591 : : }
13592 : 0 : mng->n = resize;
13593 : 0 : mng->pools = pools;
13594 : 0 : return 0;
13595 : : }
13596 : :
13597 : : /**
13598 : : * Create and initialize a new ASO aging pool.
13599 : : *
13600 : : * @param[in] dev
13601 : : * Pointer to the Ethernet device structure.
13602 : : * @param[out] age_free
13603 : : * Where to put the pointer of a new age action.
13604 : : *
13605 : : * @return
13606 : : * The age actions pool pointer and @p age_free is set on success,
13607 : : * NULL otherwise and rte_errno is set.
13608 : : */
13609 : : static struct mlx5_aso_age_pool *
13610 : 0 : flow_dv_age_pool_create(struct rte_eth_dev *dev,
13611 : : struct mlx5_aso_age_action **age_free)
13612 : : {
13613 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13614 : 0 : struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
13615 : : struct mlx5_aso_age_pool *pool = NULL;
13616 : : struct mlx5_devx_obj *obj = NULL;
13617 : : uint32_t i;
13618 : :
13619 : 0 : obj = mlx5_devx_cmd_create_flow_hit_aso_obj(priv->sh->cdev->ctx,
13620 : 0 : priv->sh->cdev->pdn);
13621 [ # # ]: 0 : if (!obj) {
13622 : 0 : rte_errno = ENODATA;
13623 : 0 : DRV_LOG(ERR, "Failed to create flow_hit_aso_obj using DevX.");
13624 : 0 : return NULL;
13625 : : }
13626 : 0 : pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
13627 [ # # ]: 0 : if (!pool) {
13628 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
13629 : 0 : rte_errno = ENOMEM;
13630 : 0 : return NULL;
13631 : : }
13632 : 0 : pool->flow_hit_aso_obj = obj;
13633 : 0 : pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
13634 : 0 : rte_rwlock_write_lock(&mng->resize_rwl);
13635 : 0 : pool->index = mng->next;
13636 : : /* Resize pools array if there is no room for the new pool in it. */
13637 [ # # # # ]: 0 : if (pool->index == mng->n && flow_dv_aso_age_pools_resize(dev)) {
13638 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
13639 : 0 : mlx5_free(pool);
13640 : : rte_rwlock_write_unlock(&mng->resize_rwl);
13641 : 0 : return NULL;
13642 : : }
13643 : 0 : mng->pools[pool->index] = pool;
13644 : 0 : mng->next++;
13645 : : rte_rwlock_write_unlock(&mng->resize_rwl);
13646 : : /* Assign the first action in the new pool, the rest go to free list. */
13647 : 0 : *age_free = &pool->actions[0];
13648 [ # # ]: 0 : for (i = 1; i < MLX5_ASO_AGE_ACTIONS_PER_POOL; i++) {
13649 : 0 : pool->actions[i].offset = i;
13650 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free, &pool->actions[i], next);
13651 : : }
13652 : : return pool;
13653 : : }
13654 : :
13655 : : /**
13656 : : * Allocate a ASO aging bit.
13657 : : *
13658 : : * @param[in] dev
13659 : : * Pointer to the Ethernet device structure.
13660 : : * @param[out] error
13661 : : * Pointer to the error structure.
13662 : : *
13663 : : * @return
13664 : : * Index to ASO age action on success, 0 otherwise and rte_errno is set.
13665 : : */
13666 : : static uint32_t
13667 : 0 : flow_dv_aso_age_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
13668 : : {
13669 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13670 : : const struct mlx5_aso_age_pool *pool;
13671 : 0 : struct mlx5_aso_age_action *age_free = NULL;
13672 : 0 : struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
13673 : :
13674 : : MLX5_ASSERT(mng);
13675 : : /* Try to get the next free age action bit. */
13676 : 0 : rte_spinlock_lock(&mng->free_sl);
13677 : 0 : age_free = LIST_FIRST(&mng->free);
13678 [ # # ]: 0 : if (age_free) {
13679 [ # # ]: 0 : LIST_REMOVE(age_free, next);
13680 [ # # ]: 0 : } else if (!flow_dv_age_pool_create(dev, &age_free)) {
13681 : : rte_spinlock_unlock(&mng->free_sl);
13682 : 0 : rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
13683 : : NULL, "failed to create ASO age pool");
13684 : 0 : return 0; /* 0 is an error. */
13685 : : }
13686 : : rte_spinlock_unlock(&mng->free_sl);
13687 : 0 : pool = container_of
13688 : : ((const struct mlx5_aso_age_action (*)[MLX5_ASO_AGE_ACTIONS_PER_POOL])
13689 : : (age_free - age_free->offset), const struct mlx5_aso_age_pool,
13690 : : actions);
13691 [ # # ]: 0 : if (!age_free->dr_action) {
13692 : 0 : int reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_FLOW_HIT, 0,
13693 : : error);
13694 : :
13695 [ # # ]: 0 : if (reg_c < 0) {
13696 : 0 : rte_flow_error_set(error, rte_errno,
13697 : : RTE_FLOW_ERROR_TYPE_ACTION,
13698 : : NULL, "failed to get reg_c "
13699 : : "for ASO flow hit");
13700 : 0 : return 0; /* 0 is an error. */
13701 : : }
13702 : : #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
13703 : 0 : age_free->dr_action = mlx5_glue->dv_create_flow_action_aso
13704 : 0 : (priv->sh->rx_domain,
13705 : 0 : pool->flow_hit_aso_obj->obj, age_free->offset,
13706 : : MLX5DV_DR_ACTION_FLAGS_ASO_FIRST_HIT_SET,
13707 : 0 : (reg_c - REG_C_0));
13708 : : #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
13709 [ # # ]: 0 : if (!age_free->dr_action) {
13710 : 0 : rte_errno = errno;
13711 : : rte_spinlock_lock(&mng->free_sl);
13712 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free, age_free, next);
13713 : : rte_spinlock_unlock(&mng->free_sl);
13714 : 0 : rte_flow_error_set(error, rte_errno,
13715 : : RTE_FLOW_ERROR_TYPE_ACTION,
13716 : : NULL, "failed to create ASO "
13717 : : "flow hit action");
13718 : 0 : return 0; /* 0 is an error. */
13719 : : }
13720 : : }
13721 : 0 : rte_atomic_store_explicit(&age_free->refcnt, 1, rte_memory_order_relaxed);
13722 : 0 : return pool->index | ((age_free->offset + 1) << 16);
13723 : : }
13724 : :
13725 : : /**
13726 : : * Initialize flow ASO age parameters.
13727 : : *
13728 : : * @param[in] dev
13729 : : * Pointer to rte_eth_dev structure.
13730 : : * @param[in] age_idx
13731 : : * Index of ASO age action.
13732 : : * @param[in] context
13733 : : * Pointer to flow counter age context.
13734 : : * @param[in] timeout
13735 : : * Aging timeout in seconds.
13736 : : *
13737 : : */
13738 : : static void
13739 : 0 : flow_dv_aso_age_params_init(struct rte_eth_dev *dev,
13740 : : uint32_t age_idx,
13741 : : void *context,
13742 : : uint32_t timeout)
13743 : : {
13744 : : struct mlx5_aso_age_action *aso_age;
13745 : :
13746 : 0 : aso_age = flow_aso_age_get_by_idx(dev, age_idx);
13747 : : MLX5_ASSERT(aso_age);
13748 : 0 : aso_age->age_params.context = context;
13749 : 0 : aso_age->age_params.timeout = timeout;
13750 : 0 : aso_age->age_params.port_id = dev->data->port_id;
13751 : 0 : rte_atomic_store_explicit(&aso_age->age_params.sec_since_last_hit, 0,
13752 : : rte_memory_order_relaxed);
13753 : 0 : rte_atomic_store_explicit(&aso_age->age_params.state, AGE_CANDIDATE,
13754 : : rte_memory_order_relaxed);
13755 : 0 : }
13756 : :
13757 : : static void
13758 : 0 : flow_dv_translate_integrity_l4(const struct rte_flow_item_integrity *mask,
13759 : : void *headers)
13760 : : {
13761 : : /*
13762 : : * In HWS mode MLX5_ITEM_UPDATE() macro assigns the same pointer to
13763 : : * both mask and value, therefore ether can be used.
13764 : : * In SWS SW_V mode mask points to item mask and value points to item
13765 : : * spec. Integrity item value is used only if matching mask is set.
13766 : : * Use mask reference here to keep SWS functionality.
13767 : : */
13768 [ # # ]: 0 : if (mask->l4_ok) {
13769 : : /* RTE l4_ok filter aggregates hardware l4_ok and
13770 : : * l4_checksum_ok filters.
13771 : : * Positive RTE l4_ok match requires hardware match on both L4
13772 : : * hardware integrity bits.
13773 : : * PMD supports positive integrity item semantics only.
13774 : : */
13775 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, l4_ok, 1);
13776 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, l4_checksum_ok, 1);
13777 [ # # ]: 0 : } else if (mask->l4_csum_ok) {
13778 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, l4_checksum_ok, 1);
13779 : : }
13780 : 0 : }
13781 : :
13782 : : static void
13783 : 0 : flow_dv_translate_integrity_l3(const struct rte_flow_item_integrity *mask,
13784 : : void *headers, bool is_ipv4)
13785 : : {
13786 : : /*
13787 : : * In HWS mode MLX5_ITEM_UPDATE() macro assigns the same pointer to
13788 : : * both mask and value, therefore ether can be used.
13789 : : * In SWS SW_V mode mask points to item mask and value points to item
13790 : : * spec. Integrity item value used only if matching mask is set.
13791 : : * Use mask reference here to keep SWS functionality.
13792 : : */
13793 [ # # ]: 0 : if (mask->l3_ok) {
13794 : : /* RTE l3_ok filter aggregates for IPv4 hardware l3_ok and
13795 : : * ipv4_csum_ok filters.
13796 : : * Positive RTE l3_ok match requires hardware match on both L3
13797 : : * hardware integrity bits.
13798 : : * PMD supports positive integrity item semantics only.
13799 : : */
13800 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, l3_ok, 1);
13801 [ # # ]: 0 : if (is_ipv4) {
13802 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers,
13803 : : ipv4_checksum_ok, 1);
13804 : : }
13805 [ # # # # ]: 0 : } else if (is_ipv4 && mask->ipv4_csum_ok) {
13806 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, ipv4_checksum_ok, 1);
13807 : : }
13808 : 0 : }
13809 : :
13810 : : static void
13811 : 0 : set_integrity_bits(void *headers, const struct rte_flow_item *integrity_item,
13812 : : bool is_l3_ip4, uint32_t key_type)
13813 : : {
13814 : : const struct rte_flow_item_integrity *spec;
13815 : : const struct rte_flow_item_integrity *mask;
13816 : :
13817 : : /* Integrity bits validation cleared spec pointer */
13818 [ # # # # : 0 : if (MLX5_ITEM_VALID(integrity_item, key_type))
# # # # #
# ]
13819 : : return;
13820 [ # # # # : 0 : MLX5_ITEM_UPDATE(integrity_item, key_type, spec, mask,
# # # # ]
13821 : : &rte_flow_item_integrity_mask);
13822 : 0 : flow_dv_translate_integrity_l3(mask, headers, is_l3_ip4);
13823 : 0 : flow_dv_translate_integrity_l4(mask, headers);
13824 : : }
13825 : :
13826 : : static void
13827 : 0 : flow_dv_translate_item_integrity_post(void *key,
13828 : : const
13829 : : struct rte_flow_item *integrity_items[2],
13830 : : uint64_t pattern_flags, uint32_t key_type)
13831 : : {
13832 : : void *headers;
13833 : : bool is_l3_ip4;
13834 : :
13835 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_INNER_INTEGRITY) {
13836 : 0 : headers = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
13837 : 0 : is_l3_ip4 = (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV4) !=
13838 : : 0;
13839 : 0 : set_integrity_bits(headers, integrity_items[1], is_l3_ip4,
13840 : : key_type);
13841 : : }
13842 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_OUTER_INTEGRITY) {
13843 : : headers = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
13844 : 0 : is_l3_ip4 = (pattern_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV4) !=
13845 : : 0;
13846 : 0 : set_integrity_bits(headers, integrity_items[0], is_l3_ip4,
13847 : : key_type);
13848 : : }
13849 : 0 : }
13850 : :
13851 : : static uint64_t
13852 : : flow_dv_translate_item_integrity(const struct rte_flow_item *item,
13853 : : struct mlx5_dv_matcher_workspace *wks,
13854 : : uint64_t key_type)
13855 : : {
13856 : 0 : if ((key_type & MLX5_SET_MATCHER_SW) != 0) {
13857 : : const struct rte_flow_item_integrity
13858 : 0 : *spec = (typeof(spec))item->spec;
13859 : :
13860 : : /* SWS integrity bits validation cleared spec pointer */
13861 [ # # ]: 0 : if (spec->level > 1) {
13862 : 0 : wks->integrity_items[1] = item;
13863 : 0 : wks->last_item |= MLX5_FLOW_ITEM_INNER_INTEGRITY;
13864 : : } else {
13865 : 0 : wks->integrity_items[0] = item;
13866 : 0 : wks->last_item |= MLX5_FLOW_ITEM_OUTER_INTEGRITY;
13867 : : }
13868 : : } else {
13869 : : /* HWS supports outer integrity only */
13870 : 0 : wks->integrity_items[0] = item;
13871 : 0 : wks->last_item |= MLX5_FLOW_ITEM_OUTER_INTEGRITY;
13872 : : }
13873 : 0 : return wks->last_item;
13874 : : }
13875 : :
13876 : : /**
13877 : : * Prepares DV flow counter with aging configuration.
13878 : : * Gets it by index when exists, creates a new one when doesn't.
13879 : : *
13880 : : * @param[in] dev
13881 : : * Pointer to rte_eth_dev structure.
13882 : : * @param[in] dev_flow
13883 : : * Pointer to the mlx5_flow.
13884 : : * @param[in, out] flow
13885 : : * Pointer to the sub flow.
13886 : : * @param[in] count
13887 : : * Pointer to the counter action configuration.
13888 : : * @param[in] age
13889 : : * Pointer to the aging action configuration.
13890 : : * @param[out] error
13891 : : * Pointer to the error structure.
13892 : : *
13893 : : * @return
13894 : : * Pointer to the counter, NULL otherwise.
13895 : : */
13896 : : static struct mlx5_flow_counter *
13897 : 0 : flow_dv_prepare_counter(struct rte_eth_dev *dev,
13898 : : struct mlx5_flow *dev_flow,
13899 : : struct rte_flow *flow,
13900 : : const struct rte_flow_action_count *count,
13901 : : const struct rte_flow_action_age *age,
13902 : : struct rte_flow_error *error)
13903 : : {
13904 [ # # ]: 0 : if (!flow->counter) {
13905 : 0 : flow->counter = flow_dv_translate_create_counter(dev, dev_flow,
13906 : : count, age);
13907 [ # # ]: 0 : if (!flow->counter) {
13908 : 0 : rte_flow_error_set(error, rte_errno,
13909 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
13910 : : "cannot create counter object.");
13911 : 0 : return NULL;
13912 : : }
13913 : : }
13914 [ # # ]: 0 : return flow_dv_counter_get_by_idx(dev, flow->counter, NULL);
13915 : : }
13916 : :
13917 : : /*
13918 : : * Release an ASO CT action by its own device.
13919 : : *
13920 : : * @param[in] dev
13921 : : * Pointer to the Ethernet device structure.
13922 : : * @param[in] idx
13923 : : * Index of ASO CT action to release.
13924 : : *
13925 : : * @return
13926 : : * 0 when CT action was removed, otherwise the number of references.
13927 : : */
13928 : : static inline int
13929 : 0 : flow_dv_aso_ct_dev_release(struct rte_eth_dev *dev, uint32_t idx)
13930 : : {
13931 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13932 : 0 : struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
13933 : : uint32_t ret;
13934 : 0 : struct mlx5_aso_ct_action *ct = flow_aso_ct_get_by_dev_idx(dev, idx);
13935 : : enum mlx5_aso_ct_state state =
13936 : 0 : rte_atomic_load_explicit(&ct->state, rte_memory_order_relaxed);
13937 : :
13938 : : /* Cannot release when CT is in the ASO SQ. */
13939 [ # # ]: 0 : if (state == ASO_CONNTRACK_WAIT || state == ASO_CONNTRACK_QUERY)
13940 : : return -1;
13941 : 0 : ret = rte_atomic_fetch_sub_explicit(&ct->refcnt, 1, rte_memory_order_relaxed) - 1;
13942 [ # # ]: 0 : if (!ret) {
13943 [ # # ]: 0 : if (ct->dr_action_orig) {
13944 : : #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
13945 : 0 : claim_zero(mlx5_glue->destroy_flow_action
13946 : : (ct->dr_action_orig));
13947 : : #endif
13948 : 0 : ct->dr_action_orig = NULL;
13949 : : }
13950 [ # # ]: 0 : if (ct->dr_action_rply) {
13951 : : #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
13952 : 0 : claim_zero(mlx5_glue->destroy_flow_action
13953 : : (ct->dr_action_rply));
13954 : : #endif
13955 : 0 : ct->dr_action_rply = NULL;
13956 : : }
13957 : : /* Clear the state to free, no need in 1st allocation. */
13958 : 0 : MLX5_ASO_CT_UPDATE_STATE(ct, ASO_CONNTRACK_FREE);
13959 : 0 : rte_spinlock_lock(&mng->ct_sl);
13960 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free_cts, ct, next);
13961 : : rte_spinlock_unlock(&mng->ct_sl);
13962 : : }
13963 : 0 : return (int)ret;
13964 : : }
13965 : :
13966 : : static inline int
13967 : 0 : flow_dv_aso_ct_release(struct rte_eth_dev *dev, uint32_t own_idx,
13968 : : struct rte_flow_error *error)
13969 : : {
13970 : 0 : uint16_t owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(own_idx);
13971 : 0 : uint32_t idx = MLX5_INDIRECT_ACT_CT_GET_IDX(own_idx);
13972 : 0 : struct rte_eth_dev *owndev = &rte_eth_devices[owner];
13973 : : int ret;
13974 : :
13975 : : MLX5_ASSERT(owner < RTE_MAX_ETHPORTS);
13976 [ # # ]: 0 : if (dev->data->dev_started != 1)
13977 : 0 : return rte_flow_error_set(error, EAGAIN,
13978 : : RTE_FLOW_ERROR_TYPE_ACTION,
13979 : : NULL,
13980 : : "Indirect CT action cannot be destroyed when the port is stopped");
13981 : 0 : ret = flow_dv_aso_ct_dev_release(owndev, idx);
13982 [ # # ]: 0 : if (ret < 0)
13983 : 0 : return rte_flow_error_set(error, EAGAIN,
13984 : : RTE_FLOW_ERROR_TYPE_ACTION,
13985 : : NULL,
13986 : : "Current state prevents indirect CT action from being destroyed");
13987 : : return ret;
13988 : : }
13989 : :
13990 : : /*
13991 : : * Resize the ASO CT pools array by 64 pools.
13992 : : *
13993 : : * @param[in] dev
13994 : : * Pointer to the Ethernet device structure.
13995 : : *
13996 : : * @return
13997 : : * 0 on success, otherwise negative errno value and rte_errno is set.
13998 : : */
13999 : : static int
14000 : 0 : flow_dv_aso_ct_pools_resize(struct rte_eth_dev *dev)
14001 : : {
14002 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14003 : 0 : struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
14004 : 0 : void *old_pools = mng->pools;
14005 : : /* Magic number now, need a macro. */
14006 : 0 : uint32_t resize = mng->n + 64;
14007 : 0 : uint32_t mem_size = sizeof(struct mlx5_aso_ct_pool *) * resize;
14008 : 0 : void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
14009 : :
14010 [ # # ]: 0 : if (!pools) {
14011 : 0 : rte_errno = ENOMEM;
14012 : 0 : return -rte_errno;
14013 : : }
14014 : 0 : rte_rwlock_write_lock(&mng->resize_rwl);
14015 : : /* ASO SQ/QP was already initialized in the startup. */
14016 [ # # ]: 0 : if (old_pools) {
14017 : : /* Realloc could be an alternative choice. */
14018 : 0 : rte_memcpy(pools, old_pools,
14019 [ # # ]: 0 : mng->n * sizeof(struct mlx5_aso_ct_pool *));
14020 : 0 : mlx5_free(old_pools);
14021 : : }
14022 : 0 : mng->n = resize;
14023 : 0 : mng->pools = pools;
14024 : : rte_rwlock_write_unlock(&mng->resize_rwl);
14025 : 0 : return 0;
14026 : : }
14027 : :
14028 : : /*
14029 : : * Create and initialize a new ASO CT pool.
14030 : : *
14031 : : * @param[in] dev
14032 : : * Pointer to the Ethernet device structure.
14033 : : * @param[out] ct_free
14034 : : * Where to put the pointer of a new CT action.
14035 : : *
14036 : : * @return
14037 : : * The CT actions pool pointer and @p ct_free is set on success,
14038 : : * NULL otherwise and rte_errno is set.
14039 : : */
14040 : : static struct mlx5_aso_ct_pool *
14041 : 0 : flow_dv_ct_pool_create(struct rte_eth_dev *dev,
14042 : : struct mlx5_aso_ct_action **ct_free)
14043 : : {
14044 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14045 : 0 : struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
14046 : : struct mlx5_aso_ct_pool *pool = NULL;
14047 : : struct mlx5_devx_obj *obj = NULL;
14048 : : uint32_t i;
14049 : : uint32_t log_obj_size = rte_log2_u32(MLX5_ASO_CT_ACTIONS_PER_POOL);
14050 : : size_t mem_size;
14051 : :
14052 : 0 : obj = mlx5_devx_cmd_create_conn_track_offload_obj(priv->sh->cdev->ctx,
14053 : 0 : priv->sh->cdev->pdn,
14054 : : log_obj_size);
14055 [ # # ]: 0 : if (!obj) {
14056 : 0 : rte_errno = ENODATA;
14057 : 0 : DRV_LOG(ERR, "Failed to create conn_track_offload_obj using DevX.");
14058 : 0 : return NULL;
14059 : : }
14060 : : mem_size = sizeof(struct mlx5_aso_ct_action) *
14061 : : MLX5_ASO_CT_ACTIONS_PER_POOL +
14062 : : sizeof(*pool);
14063 : 0 : pool = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
14064 [ # # ]: 0 : if (!pool) {
14065 : 0 : rte_errno = ENOMEM;
14066 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
14067 : 0 : return NULL;
14068 : : }
14069 : 0 : pool->devx_obj = obj;
14070 : 0 : pool->index = mng->next;
14071 : : /* Resize pools array if there is no room for the new pool in it. */
14072 [ # # # # ]: 0 : if (pool->index == mng->n && flow_dv_aso_ct_pools_resize(dev)) {
14073 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
14074 : 0 : mlx5_free(pool);
14075 : 0 : return NULL;
14076 : : }
14077 : 0 : mng->pools[pool->index] = pool;
14078 : 0 : mng->next++;
14079 : : /* Assign the first action in the new pool, the rest go to free list. */
14080 : 0 : *ct_free = &pool->actions[0];
14081 : : /* Lock outside, the list operation is safe here. */
14082 [ # # ]: 0 : for (i = 1; i < MLX5_ASO_CT_ACTIONS_PER_POOL; i++) {
14083 : : /* refcnt is 0 when allocating the memory. */
14084 : 0 : pool->actions[i].offset = i;
14085 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free_cts, &pool->actions[i], next);
14086 : : }
14087 : : return pool;
14088 : : }
14089 : :
14090 : : /*
14091 : : * Allocate a ASO CT action from free list.
14092 : : *
14093 : : * @param[in] dev
14094 : : * Pointer to the Ethernet device structure.
14095 : : * @param[out] error
14096 : : * Pointer to the error structure.
14097 : : *
14098 : : * @return
14099 : : * Index to ASO CT action on success, 0 otherwise and rte_errno is set.
14100 : : */
14101 : : static uint32_t
14102 : 0 : flow_dv_aso_ct_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
14103 : : {
14104 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14105 : 0 : struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
14106 : 0 : struct mlx5_aso_ct_action *ct = NULL;
14107 : : struct mlx5_aso_ct_pool *pool;
14108 : : uint8_t reg_c;
14109 : : uint32_t ct_idx;
14110 : :
14111 : : MLX5_ASSERT(mng);
14112 [ # # ]: 0 : if (!priv->sh->cdev->config.devx) {
14113 : 0 : rte_errno = ENOTSUP;
14114 : 0 : return 0;
14115 : : }
14116 : : /* Get a free CT action, if no, a new pool will be created. */
14117 : 0 : rte_spinlock_lock(&mng->ct_sl);
14118 : 0 : ct = LIST_FIRST(&mng->free_cts);
14119 [ # # ]: 0 : if (ct) {
14120 [ # # ]: 0 : LIST_REMOVE(ct, next);
14121 [ # # ]: 0 : } else if (!flow_dv_ct_pool_create(dev, &ct)) {
14122 : : rte_spinlock_unlock(&mng->ct_sl);
14123 : 0 : rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
14124 : : NULL, "failed to create ASO CT pool");
14125 : 0 : return 0;
14126 : : }
14127 : : rte_spinlock_unlock(&mng->ct_sl);
14128 : 0 : pool = container_of(ct, struct mlx5_aso_ct_pool, actions[ct->offset]);
14129 : 0 : ct_idx = MLX5_MAKE_CT_IDX(pool->index, ct->offset);
14130 : : /* 0: inactive, 1: created, 2+: used by flows. */
14131 : 0 : rte_atomic_store_explicit(&ct->refcnt, 1, rte_memory_order_relaxed);
14132 : 0 : reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_CONNTRACK, 0, error);
14133 [ # # ]: 0 : if (!ct->dr_action_orig) {
14134 : : #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
14135 : 0 : ct->dr_action_orig = mlx5_glue->dv_create_flow_action_aso
14136 : 0 : (priv->sh->rx_domain, pool->devx_obj->obj,
14137 : : ct->offset,
14138 : : MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_INITIATOR,
14139 : 0 : reg_c - REG_C_0);
14140 : : #else
14141 : : RTE_SET_USED(reg_c);
14142 : : #endif
14143 [ # # ]: 0 : if (!ct->dr_action_orig) {
14144 : 0 : flow_dv_aso_ct_dev_release(dev, ct_idx);
14145 : 0 : rte_flow_error_set(error, rte_errno,
14146 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14147 : : "failed to create ASO CT action");
14148 : 0 : return 0;
14149 : : }
14150 : : }
14151 [ # # ]: 0 : if (!ct->dr_action_rply) {
14152 : : #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
14153 : 0 : ct->dr_action_rply = mlx5_glue->dv_create_flow_action_aso
14154 : 0 : (priv->sh->rx_domain, pool->devx_obj->obj,
14155 : : ct->offset,
14156 : : MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_RESPONDER,
14157 : 0 : reg_c - REG_C_0);
14158 : : #endif
14159 [ # # ]: 0 : if (!ct->dr_action_rply) {
14160 : 0 : flow_dv_aso_ct_dev_release(dev, ct_idx);
14161 : 0 : rte_flow_error_set(error, rte_errno,
14162 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14163 : : "failed to create ASO CT action");
14164 : 0 : return 0;
14165 : : }
14166 : : }
14167 : : return ct_idx;
14168 : : }
14169 : :
14170 : : /*
14171 : : * Create a conntrack object with context and actions by using ASO mechanism.
14172 : : *
14173 : : * @param[in] dev
14174 : : * Pointer to rte_eth_dev structure.
14175 : : * @param[in] pro
14176 : : * Pointer to conntrack information profile.
14177 : : * @param[out] error
14178 : : * Pointer to the error structure.
14179 : : *
14180 : : * @return
14181 : : * Index to conntrack object on success, 0 otherwise.
14182 : : */
14183 : : static uint32_t
14184 : 0 : flow_dv_translate_create_conntrack(struct rte_eth_dev *dev,
14185 : : const struct rte_flow_action_conntrack *pro,
14186 : : struct rte_flow_error *error)
14187 : : {
14188 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14189 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
14190 : : struct mlx5_aso_ct_action *ct;
14191 : : uint32_t idx;
14192 : :
14193 [ # # ]: 0 : if (!sh->ct_aso_en)
14194 : 0 : return rte_flow_error_set(error, ENOTSUP,
14195 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14196 : : "Connection is not supported");
14197 [ # # ]: 0 : if (dev->data->port_id >= MLX5_INDIRECT_ACT_CT_MAX_PORT) {
14198 : 0 : rte_flow_error_set(error, EINVAL,
14199 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14200 : : "CT supports port indexes up to "
14201 : : RTE_STR(MLX5_ACTION_CTX_CT_MAX_PORT));
14202 : 0 : return 0;
14203 : : }
14204 : 0 : idx = flow_dv_aso_ct_alloc(dev, error);
14205 [ # # ]: 0 : if (!idx)
14206 : 0 : return rte_flow_error_set(error, rte_errno,
14207 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14208 : : "Failed to allocate CT object");
14209 : 0 : ct = flow_aso_ct_get_by_dev_idx(dev, idx);
14210 [ # # ]: 0 : if (mlx5_aso_ct_update_by_wqe(sh, MLX5_HW_INV_QUEUE, ct, pro, NULL, true)) {
14211 : 0 : flow_dv_aso_ct_dev_release(dev, idx);
14212 : 0 : rte_flow_error_set(error, EBUSY,
14213 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14214 : : "Failed to update CT");
14215 : 0 : return 0;
14216 : : }
14217 : 0 : ct->is_original = !!pro->is_original_dir;
14218 : 0 : ct->peer = pro->peer_port;
14219 : 0 : return idx;
14220 : : }
14221 : :
14222 : : /**
14223 : : * Fill the flow matcher with DV spec.
14224 : : *
14225 : : * @param[in] dev
14226 : : * Pointer to rte_eth_dev structure.
14227 : : * @param[in] items
14228 : : * Pointer to the list of items.
14229 : : * @param[in] wks
14230 : : * Pointer to the matcher workspace.
14231 : : * @param[in] key
14232 : : * Pointer to the flow matcher key.
14233 : : * @param[in] key_type
14234 : : * Key type.
14235 : : * @param[out] error
14236 : : * Pointer to the error structure.
14237 : : *
14238 : : * @return
14239 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14240 : : */
14241 : : static int
14242 : 0 : flow_dv_translate_items(struct rte_eth_dev *dev,
14243 : : const struct rte_flow_item *items,
14244 : : struct mlx5_dv_matcher_workspace *wks,
14245 : : void *key, uint32_t key_type,
14246 : : struct rte_flow_error *error)
14247 : : {
14248 : 0 : struct mlx5_flow_rss_desc *rss_desc = wks->rss_desc;
14249 : 0 : uint8_t next_protocol = wks->next_protocol;
14250 : 0 : int tunnel = !!(wks->item_flags & MLX5_FLOW_LAYER_TUNNEL);
14251 : 0 : int item_type = items->type;
14252 : 0 : uint64_t last_item = wks->last_item;
14253 : : enum mlx5_l3_tunnel_detection l3_tunnel_detection;
14254 : : uint64_t l3_tunnel_flag;
14255 : : int ret;
14256 : :
14257 [ # # # # : 0 : switch (item_type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
14258 : 0 : case RTE_FLOW_ITEM_TYPE_ESP:
14259 : 0 : flow_dv_translate_item_esp(key, items, tunnel, key_type, wks->item_flags);
14260 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14261 : : last_item = MLX5_FLOW_ITEM_ESP;
14262 : 0 : break;
14263 : 0 : case RTE_FLOW_ITEM_TYPE_PORT_ID:
14264 : 0 : flow_dv_translate_item_port_id
14265 : : (dev, key, items, wks->attr, key_type);
14266 : : last_item = MLX5_FLOW_ITEM_PORT_ID;
14267 : 0 : break;
14268 : 0 : case RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR:
14269 : 0 : flow_dv_translate_item_port_representor
14270 : : (dev, key, key_type);
14271 : : last_item = MLX5_FLOW_ITEM_PORT_REPRESENTOR;
14272 : 0 : break;
14273 : 0 : case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
14274 : 0 : flow_dv_translate_item_represented_port
14275 : : (dev, key, items, wks->attr, key_type);
14276 : : last_item = MLX5_FLOW_ITEM_REPRESENTED_PORT;
14277 : 0 : break;
14278 : 0 : case RTE_FLOW_ITEM_TYPE_ETH:
14279 : 0 : flow_dv_translate_item_eth(key, items, tunnel,
14280 : : wks->group, key_type);
14281 [ # # ]: 0 : wks->priority = wks->action_flags &
14282 : 0 : MLX5_FLOW_ACTION_DEFAULT_MISS &&
14283 [ # # ]: 0 : !wks->external ?
14284 : : MLX5_PRIORITY_MAP_L3 :
14285 : : MLX5_PRIORITY_MAP_L2;
14286 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
14287 : : MLX5_FLOW_LAYER_OUTER_L2;
14288 : : break;
14289 : 0 : case RTE_FLOW_ITEM_TYPE_VLAN:
14290 : 0 : flow_dv_translate_item_vlan(key, items, tunnel, wks, key_type);
14291 : 0 : wks->priority = MLX5_PRIORITY_MAP_L2;
14292 : : last_item = tunnel ? (MLX5_FLOW_LAYER_INNER_L2 |
14293 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_VLAN) :
14294 : : (MLX5_FLOW_LAYER_OUTER_L2 |
14295 : : MLX5_FLOW_LAYER_OUTER_VLAN);
14296 : : break;
14297 : : case RTE_FLOW_ITEM_TYPE_IPV4:
14298 : : next_protocol = mlx5_flow_l3_next_protocol(items, key_type);
14299 : : l3_tunnel_detection =
14300 : : mlx5_flow_tunnel_ip_check(items, next_protocol,
14301 : : wks->item_flags,
14302 : : &l3_tunnel_flag);
14303 : : if (l3_tunnel_detection == l3_tunnel_inner) {
14304 : 0 : wks->item_flags |= l3_tunnel_flag;
14305 : : tunnel = 1;
14306 : : }
14307 : 0 : flow_dv_translate_item_ipv4(key, items, tunnel,
14308 : : wks->group, key_type);
14309 : 0 : wks->priority = MLX5_PRIORITY_MAP_L3;
14310 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
14311 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4;
14312 [ # # ]: 0 : if (l3_tunnel_detection == l3_tunnel_outer)
14313 : 0 : wks->item_flags |= l3_tunnel_flag;
14314 : : break;
14315 : : case RTE_FLOW_ITEM_TYPE_IPV6:
14316 : : next_protocol = mlx5_flow_l3_next_protocol(items, key_type);
14317 : : l3_tunnel_detection =
14318 : : mlx5_flow_tunnel_ip_check(items, next_protocol,
14319 : : wks->item_flags,
14320 : : &l3_tunnel_flag);
14321 : : if (l3_tunnel_detection == l3_tunnel_inner) {
14322 : 0 : wks->item_flags |= l3_tunnel_flag;
14323 : : tunnel = 1;
14324 : : }
14325 : 0 : flow_dv_translate_item_ipv6(key, items, tunnel,
14326 : : wks->group, key_type);
14327 : 0 : wks->priority = MLX5_PRIORITY_MAP_L3;
14328 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
14329 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6;
14330 [ # # ]: 0 : if (l3_tunnel_detection == l3_tunnel_outer)
14331 : 0 : wks->item_flags |= l3_tunnel_flag;
14332 : : break;
14333 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
14334 : 0 : flow_dv_translate_item_ipv6_frag_ext
14335 : : (key, items, tunnel, key_type);
14336 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
14337 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
14338 : : next_protocol = mlx5_flow_l3_next_protocol(items, key_type);
14339 : : break;
14340 : 0 : case RTE_FLOW_ITEM_TYPE_TCP:
14341 : 0 : flow_dv_translate_item_tcp(key, items, tunnel, key_type);
14342 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14343 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
14344 : : MLX5_FLOW_LAYER_OUTER_L4_TCP;
14345 : : break;
14346 : 0 : case RTE_FLOW_ITEM_TYPE_UDP:
14347 : 0 : flow_dv_translate_item_udp(key, items, tunnel, wks, key_type);
14348 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14349 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
14350 : : MLX5_FLOW_LAYER_OUTER_L4_UDP;
14351 : : break;
14352 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
14353 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14354 : 0 : wks->tunnel_item = items;
14355 : 0 : wks->gre_item = items;
14356 : : last_item = MLX5_FLOW_LAYER_GRE;
14357 : 0 : break;
14358 : 0 : case RTE_FLOW_ITEM_TYPE_GRE_KEY:
14359 : 0 : flow_dv_translate_item_gre_key(key, items, key_type);
14360 : : last_item = MLX5_FLOW_LAYER_GRE_KEY;
14361 : 0 : break;
14362 : 0 : case RTE_FLOW_ITEM_TYPE_GRE_OPTION:
14363 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14364 : 0 : wks->tunnel_item = items;
14365 : : last_item = MLX5_FLOW_LAYER_GRE;
14366 : 0 : break;
14367 : 0 : case RTE_FLOW_ITEM_TYPE_NVGRE:
14368 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14369 : 0 : wks->tunnel_item = items;
14370 : : last_item = MLX5_FLOW_LAYER_GRE;
14371 : 0 : break;
14372 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN:
14373 : 0 : flow_dv_translate_item_vxlan(dev, wks->attr, key,
14374 : : items, tunnel, wks, key_type);
14375 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14376 : : last_item = MLX5_FLOW_LAYER_VXLAN;
14377 : 0 : break;
14378 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
14379 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14380 : 0 : wks->tunnel_item = items;
14381 : : last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
14382 : 0 : break;
14383 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE:
14384 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14385 : 0 : wks->tunnel_item = items;
14386 : : last_item = MLX5_FLOW_LAYER_GENEVE;
14387 : 0 : break;
14388 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
14389 : 0 : ret = flow_dv_translate_item_geneve_opt
14390 : : (dev, key, items, key_type, error);
14391 [ # # ]: 0 : if (ret)
14392 : 0 : return rte_flow_error_set(error, -ret,
14393 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14394 : : "cannot create GENEVE TLV option");
14395 : 0 : wks->geneve_tlv_option = 1;
14396 : : last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
14397 : 0 : break;
14398 : 0 : case RTE_FLOW_ITEM_TYPE_MPLS:
14399 : 0 : flow_dv_translate_item_mpls(key, items, last_item,
14400 : : tunnel, key_type);
14401 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14402 : : last_item = MLX5_FLOW_LAYER_MPLS;
14403 : 0 : break;
14404 : 0 : case RTE_FLOW_ITEM_TYPE_MARK:
14405 : 0 : flow_dv_translate_item_mark(dev, key, items, key_type);
14406 : : last_item = MLX5_FLOW_ITEM_MARK;
14407 : 0 : break;
14408 : 0 : case RTE_FLOW_ITEM_TYPE_META:
14409 : 0 : flow_dv_translate_item_meta
14410 : : (dev, key, wks->attr, items, key_type);
14411 : : last_item = MLX5_FLOW_ITEM_METADATA;
14412 : 0 : break;
14413 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP:
14414 : 0 : flow_dv_translate_item_icmp(key, items, tunnel, key_type);
14415 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14416 : : last_item = MLX5_FLOW_LAYER_ICMP;
14417 : 0 : break;
14418 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6:
14419 : 0 : flow_dv_translate_item_icmp6(key, items, tunnel, key_type);
14420 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14421 : : last_item = MLX5_FLOW_LAYER_ICMP6;
14422 : 0 : break;
14423 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REQUEST:
14424 : : case RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REPLY:
14425 : 0 : flow_dv_translate_item_icmp6_echo(key, items, tunnel, key_type);
14426 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14427 : : last_item = MLX5_FLOW_LAYER_ICMP6;
14428 : 0 : break;
14429 : 0 : case RTE_FLOW_ITEM_TYPE_TAG:
14430 : 0 : ret = flow_dv_translate_item_tag(dev, key, items, key_type);
14431 [ # # ]: 0 : if (ret < 0)
14432 : 0 : return rte_flow_error_set(error, -ret, RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14433 : : "invalid flow tag item");
14434 : : last_item = MLX5_FLOW_ITEM_TAG;
14435 : : break;
14436 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
14437 : 0 : flow_dv_translate_mlx5_item_tag(dev, key, items, key_type);
14438 : : last_item = MLX5_FLOW_ITEM_TAG;
14439 : 0 : break;
14440 : 0 : case RTE_FLOW_ITEM_TYPE_TX_QUEUE:
14441 : 0 : ret = flow_dv_translate_item_tx_queue(dev, key, items, key_type);
14442 [ # # ]: 0 : if (ret)
14443 : 0 : return rte_flow_error_set(error, -ret,
14444 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14445 : : "invalid tx_queue item");
14446 : : last_item = MLX5_FLOW_ITEM_SQ;
14447 : : break;
14448 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_SQ:
14449 : 0 : flow_dv_translate_item_sq(key, items, key_type);
14450 : : last_item = MLX5_FLOW_ITEM_SQ;
14451 : 0 : break;
14452 : 0 : case RTE_FLOW_ITEM_TYPE_GTP:
14453 : 0 : flow_dv_translate_item_gtp(key, items, tunnel, key_type);
14454 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14455 : : last_item = MLX5_FLOW_LAYER_GTP;
14456 : 0 : break;
14457 : 0 : case RTE_FLOW_ITEM_TYPE_GTP_PSC:
14458 : 0 : ret = flow_dv_translate_item_gtp_psc(key, items, key_type);
14459 [ # # ]: 0 : if (ret)
14460 : 0 : return rte_flow_error_set(error, -ret,
14461 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14462 : : "cannot create GTP PSC item");
14463 : : last_item = MLX5_FLOW_LAYER_GTP_PSC;
14464 : : break;
14465 : 0 : case RTE_FLOW_ITEM_TYPE_ECPRI:
14466 [ # # ]: 0 : if (!mlx5_flex_parser_ecpri_exist(dev)) {
14467 : : /* Create it only the first time to be used. */
14468 : 0 : ret = mlx5_flex_parser_ecpri_alloc(dev);
14469 [ # # ]: 0 : if (ret)
14470 : 0 : return rte_flow_error_set
14471 : : (error, -ret,
14472 : : RTE_FLOW_ERROR_TYPE_ITEM,
14473 : : NULL,
14474 : : "cannot create eCPRI parser");
14475 : : }
14476 : 0 : flow_dv_translate_item_ecpri
14477 : : (dev, key, items, last_item, key_type);
14478 : : /* No other protocol should follow eCPRI layer. */
14479 : : last_item = MLX5_FLOW_LAYER_ECPRI;
14480 : 0 : break;
14481 : 0 : case RTE_FLOW_ITEM_TYPE_METER_COLOR:
14482 : 0 : flow_dv_translate_item_meter_color(dev, key, items, key_type);
14483 : : last_item = MLX5_FLOW_ITEM_METER_COLOR;
14484 : 0 : break;
14485 [ # # ]: 0 : case RTE_FLOW_ITEM_TYPE_INTEGRITY:
14486 : : last_item = flow_dv_translate_item_integrity(items,
14487 : : wks, key_type);
14488 : 0 : break;
14489 : 0 : case RTE_FLOW_ITEM_TYPE_AGGR_AFFINITY:
14490 : 0 : flow_dv_translate_item_aggr_affinity(key, items, key_type);
14491 : : last_item = MLX5_FLOW_ITEM_AGGR_AFFINITY;
14492 : 0 : break;
14493 : 0 : case RTE_FLOW_ITEM_TYPE_IB_BTH:
14494 : 0 : flow_dv_translate_item_ib_bth(key, items, tunnel, key_type);
14495 : : last_item = MLX5_FLOW_ITEM_IB_BTH;
14496 : 0 : break;
14497 : 0 : case RTE_FLOW_ITEM_TYPE_NSH:
14498 : : last_item = MLX5_FLOW_ITEM_NSH;
14499 : 0 : break;
14500 : : default:
14501 : : break;
14502 : : }
14503 : 0 : wks->item_flags |= last_item;
14504 : 0 : wks->last_item = last_item;
14505 : 0 : wks->next_protocol = next_protocol;
14506 : 0 : return 0;
14507 : : }
14508 : :
14509 : : static int
14510 : 0 : flow_dv_translate_items_geneve_opt_nta(struct rte_eth_dev *dev,
14511 : : const struct rte_flow_item *items,
14512 : : struct mlx5_flow_attr *attr,
14513 : : struct rte_flow_error *error)
14514 : : {
14515 : 0 : rte_be32_t geneve_mask = 0xffffffff;
14516 : 0 : struct rte_pmd_mlx5_geneve_tlv geneve_tlv = {
14517 : : /* Take from item spec, if changed, destroy and add new parser. */
14518 : : .option_class = 0,
14519 : : /* Take from item spec, if changed, destroy and add new parser. */
14520 : : .option_type = 0,
14521 : : /* 1DW is supported. */
14522 : : .option_len = 1,
14523 : : .match_on_class_mode = 1,
14524 : : .offset = 0,
14525 : : .sample_len = 1,
14526 : : .match_data_mask = &geneve_mask
14527 : : };
14528 : 0 : const struct rte_flow_item_geneve_opt *geneve_opt_v = items->spec;
14529 : 0 : const struct rte_flow_item_geneve_opt *geneve_opt_m = items->mask;
14530 : : void *geneve_parser;
14531 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14532 : : #ifdef RTE_LIBRTE_MLX5_DEBUG
14533 : : struct mlx5_geneve_tlv_option *option;
14534 : : #endif
14535 : :
14536 : : /* option length is not as supported. */
14537 [ # # ]: 0 : if ((geneve_opt_v->option_len & geneve_opt_m->option_len) > geneve_tlv.option_len)
14538 : 0 : return rte_flow_error_set(error, ENOTSUP,
14539 : : RTE_FLOW_ERROR_TYPE_ITEM, items,
14540 : : " GENEVE OPT length is not supported ");
14541 : 0 : geneve_tlv.option_class = geneve_opt_v->option_class & geneve_opt_m->option_class;
14542 : 0 : geneve_tlv.option_type = geneve_opt_v->option_type & geneve_opt_m->option_type;
14543 : : /* if parser doesn't exist */
14544 [ # # ]: 0 : if (!priv->tlv_options) {
14545 : : /* Create a GENEVE option parser. */
14546 : 0 : geneve_parser = mlx5_geneve_tlv_parser_create(attr->port_id,
14547 : : &geneve_tlv, 1);
14548 [ # # ]: 0 : if (!geneve_parser)
14549 : 0 : return rte_flow_error_set(error, EINVAL,
14550 : : RTE_FLOW_ERROR_TYPE_ITEM, items,
14551 : : " GENEVE OPT parser creation failed ");
14552 : : #ifdef RTE_LIBRTE_MLX5_DEBUG
14553 : : } else {
14554 : : /* Check if option exist in current parser. */
14555 : : option = mlx5_geneve_tlv_option_get(priv,
14556 : : geneve_tlv.option_type,
14557 : : geneve_tlv.option_class);
14558 : : if (!option)
14559 : : return rte_flow_error_set(error, EINVAL,
14560 : : RTE_FLOW_ERROR_TYPE_ITEM, items,
14561 : : " GENEVE OPT configured does not match this rule class/type");
14562 : : #endif
14563 : : }
14564 : : return 0;
14565 : : }
14566 : :
14567 : : /**
14568 : : * Fill the flow matcher with DV spec for items supported in non template mode.
14569 : : *
14570 : : * @param[in] dev
14571 : : * Pointer to rte_eth_dev structure.
14572 : : * @param[in] items
14573 : : * Pointer to the list of items.
14574 : : * @param[in] wks
14575 : : * Pointer to the matcher workspace.
14576 : : * @param[in] key
14577 : : * Pointer to the flow matcher key.
14578 : : * @param[in] key_type
14579 : : * Key type.
14580 : : * @param[out] error
14581 : : * Pointer to the error structure.
14582 : : *
14583 : : * @return
14584 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14585 : : */
14586 : : static int
14587 : 0 : flow_dv_translate_items_nta(struct rte_eth_dev *dev,
14588 : : const struct rte_flow_item *items,
14589 : : struct mlx5_dv_matcher_workspace *wks,
14590 : : void *key, uint32_t key_type,
14591 : : struct mlx5_flow_attr *attr,
14592 : : struct rte_flow_error *error)
14593 : : {
14594 : : int item_type;
14595 : : int ret = 0;
14596 : : int tunnel;
14597 : : /* Dummy structure to enable the key calculation for flex item. */
14598 : : struct mlx5_flow_dv_match_params flex_item_key;
14599 : :
14600 : 0 : tunnel = !!(wks->item_flags & MLX5_FLOW_LAYER_TUNNEL);
14601 : 0 : item_type = items->type;
14602 [ # # # # ]: 0 : switch (item_type) {
14603 : 0 : case RTE_FLOW_ITEM_TYPE_CONNTRACK:
14604 : 0 : flow_dv_translate_item_aso_ct(dev, key, NULL, items);
14605 : 0 : wks->last_item = MLX5_FLOW_LAYER_ASO_CT;
14606 : 0 : break;
14607 : : /* TODO: remove once flex item translation is added to flow_dv_translate_items. */
14608 : 0 : case RTE_FLOW_ITEM_TYPE_FLEX:
14609 : 0 : mlx5_flex_flow_translate_item(dev, key, flex_item_key.buf, items, tunnel != 0);
14610 [ # # ]: 0 : wks->last_item = tunnel ? MLX5_FLOW_ITEM_INNER_FLEX : MLX5_FLOW_ITEM_OUTER_FLEX;
14611 : 0 : break;
14612 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
14613 : 0 : ret = flow_dv_translate_items_geneve_opt_nta(dev, items, attr, error);
14614 [ # # ]: 0 : if (ret)
14615 : : return ret;
14616 : 0 : wks->last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
14617 : 0 : break;
14618 : 0 : default:
14619 : 0 : ret = flow_dv_translate_items(dev, items, wks, key, key_type, error);
14620 [ # # ]: 0 : if (ret)
14621 : : return ret;
14622 : : break;
14623 : : }
14624 : 0 : wks->item_flags |= wks->last_item;
14625 : 0 : return 0;
14626 : : }
14627 : :
14628 : : /**
14629 : : * Fill the HW steering flow with DV spec.
14630 : : *
14631 : : * @param[in] items
14632 : : * Pointer to the list of items.
14633 : : * @param[in] attr
14634 : : * Pointer to the flow attributes.
14635 : : * @param[in] key
14636 : : * Pointer to the flow matcher key.
14637 : : * @param[in] key_type
14638 : : * Key type.
14639 : : * @param[in, out] item_flags
14640 : : * Pointer to the flow item flags.
14641 : : * @param[in, out] nt_flow
14642 : : * Non template flow.
14643 : : * @param[out] error
14644 : : * Pointer to the error structure.
14645 : : *
14646 : : * @return
14647 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14648 : : */
14649 : : int
14650 : 0 : __flow_dv_translate_items_hws(const struct rte_flow_item *items,
14651 : : struct mlx5_flow_attr *attr, void *key,
14652 : : uint32_t key_type, uint64_t *item_flags,
14653 : : uint8_t *match_criteria,
14654 : : bool nt_flow,
14655 : : struct rte_flow_error *error)
14656 : : {
14657 : 0 : struct mlx5_flow_workspace *flow_wks = mlx5_flow_push_thread_workspace();
14658 : 0 : struct mlx5_flow_rss_desc rss_desc = { .level = attr->rss_level };
14659 : 0 : struct rte_flow_attr rattr = {
14660 : 0 : .group = attr->group,
14661 : 0 : .priority = attr->priority,
14662 : 0 : .ingress = !!(attr->tbl_type == MLX5DR_TABLE_TYPE_NIC_RX),
14663 : 0 : .egress = !!(attr->tbl_type == MLX5DR_TABLE_TYPE_NIC_TX),
14664 : 0 : .transfer = !!(attr->tbl_type == MLX5DR_TABLE_TYPE_FDB),
14665 : : };
14666 : 0 : struct mlx5_dv_matcher_workspace wks = {
14667 : 0 : .action_flags = attr->act_flags,
14668 [ # # ]: 0 : .item_flags = item_flags ? *item_flags : 0,
14669 : : .external = 0,
14670 : : .next_protocol = 0xff,
14671 : : .attr = &rattr,
14672 : : .rss_desc = &rss_desc,
14673 : : .group = attr->group,
14674 : : };
14675 : : int ret = 0;
14676 : :
14677 : : RTE_SET_USED(flow_wks);
14678 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
14679 : : if (!mlx5_flow_os_item_supported(items->type)) {
14680 : : ret = rte_flow_error_set(error, ENOTSUP,
14681 : : RTE_FLOW_ERROR_TYPE_ITEM,
14682 : : NULL, "item not supported");
14683 : : goto exit;
14684 : : }
14685 : : /* Non template flow. */
14686 [ # # ]: 0 : if (nt_flow) {
14687 : 0 : ret = flow_dv_translate_items_nta(&rte_eth_devices[attr->port_id],
14688 : : items, &wks, key, key_type, attr, error);
14689 [ # # ]: 0 : if (ret)
14690 : 0 : goto exit;
14691 : : } else {
14692 : 0 : ret = flow_dv_translate_items(&rte_eth_devices[attr->port_id],
14693 : : items, &wks, key, key_type, error);
14694 [ # # ]: 0 : if (ret)
14695 : 0 : goto exit;
14696 : : }
14697 : : }
14698 [ # # ]: 0 : if (wks.item_flags & MLX5_FLOW_ITEM_INTEGRITY) {
14699 : 0 : flow_dv_translate_item_integrity_post(key,
14700 : : wks.integrity_items,
14701 : : wks.item_flags,
14702 : : key_type);
14703 : : }
14704 [ # # ]: 0 : if (wks.item_flags & MLX5_FLOW_LAYER_VXLAN_GPE) {
14705 : 0 : flow_dv_translate_item_vxlan_gpe(key,
14706 : : wks.tunnel_item,
14707 : : wks.item_flags,
14708 : : key_type);
14709 [ # # ]: 0 : } else if (wks.item_flags & MLX5_FLOW_LAYER_GENEVE) {
14710 : 0 : flow_dv_translate_item_geneve(key,
14711 : : wks.tunnel_item,
14712 : : wks.item_flags,
14713 : : key_type);
14714 [ # # ]: 0 : } else if (wks.item_flags & MLX5_FLOW_LAYER_GRE) {
14715 [ # # ]: 0 : if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE) {
14716 : 0 : flow_dv_translate_item_gre(key,
14717 : : wks.tunnel_item,
14718 : : wks.item_flags,
14719 : : key_type);
14720 [ # # ]: 0 : } else if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE_OPTION) {
14721 : 0 : flow_dv_translate_item_gre_option(key,
14722 : : wks.tunnel_item,
14723 : : wks.gre_item,
14724 : : wks.item_flags,
14725 : : key_type);
14726 [ # # ]: 0 : } else if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_NVGRE) {
14727 : 0 : flow_dv_translate_item_nvgre(key,
14728 : : wks.tunnel_item,
14729 : : wks.item_flags,
14730 : : key_type);
14731 : : } else {
14732 : : MLX5_ASSERT(false);
14733 : : }
14734 : : }
14735 : :
14736 [ # # ]: 0 : if (match_criteria)
14737 : 0 : *match_criteria = flow_dv_matcher_enable(key);
14738 [ # # ]: 0 : if (item_flags)
14739 : 0 : *item_flags = wks.item_flags;
14740 : 0 : exit:
14741 : 0 : mlx5_flow_pop_thread_workspace();
14742 : 0 : return ret;
14743 : : }
14744 : :
14745 : : /**
14746 : : * Fill the HW steering flow with DV spec.
14747 : : * This function assumes given flow is created from template API.
14748 : : *
14749 : : * @param[in] items
14750 : : * Pointer to the list of items.
14751 : : * @param[in] attr
14752 : : * Pointer to the flow attributes.
14753 : : * @param[in] key
14754 : : * Pointer to the flow matcher key.
14755 : : * @param[in] key_type
14756 : : * Key type.
14757 : : * @param[in, out] item_flags
14758 : : * Pointer to the flow item flags.
14759 : : * @param[out] error
14760 : : * Pointer to the error structure.
14761 : : *
14762 : : * @return
14763 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14764 : : */
14765 : : int
14766 : 0 : flow_dv_translate_items_hws(const struct rte_flow_item *items,
14767 : : struct mlx5_flow_attr *attr, void *key,
14768 : : uint32_t key_type, uint64_t *item_flags,
14769 : : uint8_t *match_criteria,
14770 : : struct rte_flow_error *error)
14771 : : {
14772 : 0 : return __flow_dv_translate_items_hws(items, attr, key, key_type, item_flags, match_criteria,
14773 : : false, error);
14774 : : }
14775 : :
14776 : : /**
14777 : : * Fill the SW steering flow with DV spec.
14778 : : *
14779 : : * @param[in] dev
14780 : : * Pointer to rte_eth_dev structure.
14781 : : * @param[in, out] dev_flow
14782 : : * Pointer to the sub flow.
14783 : : * @param[in] attr
14784 : : * Pointer to the flow attributes.
14785 : : * @param[in] items
14786 : : * Pointer to the list of items.
14787 : : * @param[in, out] matcher
14788 : : * Pointer to the flow matcher.
14789 : : * @param[out] error
14790 : : * Pointer to the error structure.
14791 : : *
14792 : : * @return
14793 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14794 : : */
14795 : : static int
14796 : 0 : flow_dv_translate_items_sws(struct rte_eth_dev *dev,
14797 : : struct mlx5_flow *dev_flow,
14798 : : const struct rte_flow_attr *attr,
14799 : : const struct rte_flow_item *items,
14800 : : struct mlx5_flow_dv_matcher *matcher,
14801 : : struct rte_flow_error *error)
14802 : : {
14803 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14804 : 0 : void *match_mask = matcher->mask.buf;
14805 : 0 : void *match_value = dev_flow->dv.value.buf;
14806 : 0 : struct mlx5_dv_matcher_workspace wks = {
14807 : 0 : .action_flags = dev_flow->act_flags,
14808 : : .item_flags = 0,
14809 : 0 : .external = dev_flow->external,
14810 : : .next_protocol = 0xff,
14811 : 0 : .group = dev_flow->dv.group,
14812 : : .attr = attr,
14813 : 0 : .rss_desc = &((struct mlx5_flow_workspace *)
14814 : : mlx5_flow_get_thread_workspace())->rss_desc,
14815 : : };
14816 : 0 : struct mlx5_dv_matcher_workspace wks_m = wks;
14817 : : int item_type;
14818 : : int ret = 0;
14819 : : int tunnel;
14820 : :
14821 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
14822 : 0 : if (!mlx5_flow_os_item_supported(items->type))
14823 : : return rte_flow_error_set(error, ENOTSUP,
14824 : : RTE_FLOW_ERROR_TYPE_ITEM,
14825 : : NULL, "item not supported");
14826 : 0 : tunnel = !!(wks.item_flags & MLX5_FLOW_LAYER_TUNNEL);
14827 : : item_type = items->type;
14828 [ # # # # : 0 : switch (item_type) {
# ]
14829 : 0 : case RTE_FLOW_ITEM_TYPE_CONNTRACK:
14830 : 0 : flow_dv_translate_item_aso_ct(dev, match_mask,
14831 : : match_value, items);
14832 : 0 : wks.last_item = MLX5_FLOW_LAYER_ASO_CT;
14833 : 0 : break;
14834 : 0 : case RTE_FLOW_ITEM_TYPE_FLEX:
14835 : 0 : flow_dv_translate_item_flex(dev, match_mask,
14836 : : match_value, items,
14837 : : dev_flow, tunnel != 0);
14838 [ # # ]: 0 : wks.last_item = tunnel ? MLX5_FLOW_ITEM_INNER_FLEX :
14839 : : MLX5_FLOW_ITEM_OUTER_FLEX;
14840 : 0 : break;
14841 : 0 : case RTE_FLOW_ITEM_TYPE_TX_QUEUE:
14842 : 0 : ret = flow_dv_translate_item_tx_queue(dev, match_value, items,
14843 : : MLX5_SET_MATCHER_SW_V);
14844 [ # # ]: 0 : if (ret)
14845 : 0 : return rte_flow_error_set(error, -ret,
14846 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14847 : : "invalid tx_queue item spec");
14848 : 0 : ret = flow_dv_translate_item_tx_queue(dev, match_mask, items,
14849 : : MLX5_SET_MATCHER_SW_M);
14850 [ # # ]: 0 : if (ret)
14851 : 0 : return rte_flow_error_set(error, -ret,
14852 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14853 : : "invalid tx_queue item mask");
14854 : : break;
14855 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_SQ:
14856 : 0 : flow_dv_translate_item_sq(match_value, items,
14857 : : MLX5_SET_MATCHER_SW_V);
14858 : 0 : flow_dv_translate_item_sq(match_mask, items,
14859 : : MLX5_SET_MATCHER_SW_M);
14860 : 0 : break;
14861 : 0 : default:
14862 : 0 : ret = flow_dv_translate_items(dev, items, &wks_m,
14863 : : match_mask, MLX5_SET_MATCHER_SW_M, error);
14864 [ # # ]: 0 : if (ret)
14865 : 0 : return ret;
14866 : 0 : ret = flow_dv_translate_items(dev, items, &wks,
14867 : : match_value, MLX5_SET_MATCHER_SW_V, error);
14868 [ # # ]: 0 : if (ret)
14869 : 0 : return ret;
14870 : : break;
14871 : : }
14872 : 0 : wks.item_flags |= wks.last_item;
14873 : : }
14874 : : /*
14875 : : * When E-Switch mode is enabled, we have two cases where we need to
14876 : : * set the source port manually.
14877 : : * The first one, is in case of NIC ingress steering rule, and the
14878 : : * second is E-Switch rule where no port_id item was found.
14879 : : * In both cases the source port is set according the current port
14880 : : * in use.
14881 : : */
14882 : 0 : if (!(wks.item_flags & MLX5_FLOW_ITEM_PORT_ID) &&
14883 [ # # ]: 0 : !(wks.item_flags & MLX5_FLOW_ITEM_REPRESENTED_PORT) &&
14884 : 0 : !(wks.item_flags & MLX5_FLOW_ITEM_PORT_REPRESENTOR) &&
14885 [ # # ]: 0 : priv->sh->esw_mode &&
14886 [ # # ]: 0 : !attr->egress &&
14887 [ # # ]: 0 : attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP) {
14888 [ # # ]: 0 : if (flow_dv_translate_item_port_id_all(dev, match_mask,
14889 : : match_value, NULL, attr))
14890 : 0 : return -rte_errno;
14891 : : }
14892 [ # # ]: 0 : if (wks.item_flags & MLX5_FLOW_ITEM_INTEGRITY) {
14893 : 0 : flow_dv_translate_item_integrity_post(match_mask,
14894 : : wks_m.integrity_items,
14895 : : wks_m.item_flags,
14896 : : MLX5_SET_MATCHER_SW_M);
14897 : 0 : flow_dv_translate_item_integrity_post(match_value,
14898 : : wks.integrity_items,
14899 : : wks.item_flags,
14900 : : MLX5_SET_MATCHER_SW_V);
14901 : : }
14902 [ # # ]: 0 : if (wks.item_flags & MLX5_FLOW_LAYER_VXLAN_GPE) {
14903 : 0 : flow_dv_translate_item_vxlan_gpe(match_mask,
14904 : : wks.tunnel_item,
14905 : : wks.item_flags,
14906 : : MLX5_SET_MATCHER_SW_M);
14907 : 0 : flow_dv_translate_item_vxlan_gpe(match_value,
14908 : : wks.tunnel_item,
14909 : : wks.item_flags,
14910 : : MLX5_SET_MATCHER_SW_V);
14911 [ # # ]: 0 : } else if (wks.item_flags & MLX5_FLOW_LAYER_GENEVE) {
14912 : 0 : flow_dv_translate_item_geneve(match_mask,
14913 : : wks.tunnel_item,
14914 : : wks.item_flags,
14915 : : MLX5_SET_MATCHER_SW_M);
14916 : 0 : flow_dv_translate_item_geneve(match_value,
14917 : : wks.tunnel_item,
14918 : : wks.item_flags,
14919 : : MLX5_SET_MATCHER_SW_V);
14920 [ # # ]: 0 : } else if (wks.item_flags & MLX5_FLOW_LAYER_GRE) {
14921 [ # # ]: 0 : if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE) {
14922 : 0 : flow_dv_translate_item_gre(match_mask,
14923 : : wks.tunnel_item,
14924 : : wks.item_flags,
14925 : : MLX5_SET_MATCHER_SW_M);
14926 : 0 : flow_dv_translate_item_gre(match_value,
14927 : : wks.tunnel_item,
14928 : : wks.item_flags,
14929 : : MLX5_SET_MATCHER_SW_V);
14930 [ # # ]: 0 : } else if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_NVGRE) {
14931 : 0 : flow_dv_translate_item_nvgre(match_mask,
14932 : : wks.tunnel_item,
14933 : : wks.item_flags,
14934 : : MLX5_SET_MATCHER_SW_M);
14935 : 0 : flow_dv_translate_item_nvgre(match_value,
14936 : : wks.tunnel_item,
14937 : : wks.item_flags,
14938 : : MLX5_SET_MATCHER_SW_V);
14939 [ # # ]: 0 : } else if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE_OPTION) {
14940 : 0 : flow_dv_translate_item_gre_option(match_mask,
14941 : : wks.tunnel_item,
14942 : : wks.gre_item,
14943 : : wks.item_flags,
14944 : : MLX5_SET_MATCHER_SW_M);
14945 : 0 : flow_dv_translate_item_gre_option(match_value,
14946 : : wks.tunnel_item,
14947 : : wks.gre_item,
14948 : : wks.item_flags,
14949 : : MLX5_SET_MATCHER_SW_V);
14950 : : } else {
14951 : : MLX5_ASSERT(false);
14952 : : }
14953 : : }
14954 : 0 : dev_flow->handle->vf_vlan.tag = wks.vlan_tag;
14955 : 0 : matcher->priority = wks.priority;
14956 : : #ifdef RTE_LIBRTE_MLX5_DEBUG
14957 : : MLX5_ASSERT(!flow_dv_check_valid_spec(match_mask, match_value));
14958 : : #endif
14959 : : /*
14960 : : * Layers may be already initialized from prefix flow if this dev_flow
14961 : : * is the suffix flow.
14962 : : */
14963 : 0 : dev_flow->handle->layers |= wks.item_flags;
14964 : : /*
14965 : : * Update geneve_tlv_option flag only it is set in workspace.
14966 : : * Avoid be overwritten by other sub mlx5_flows.
14967 : : */
14968 [ # # ]: 0 : if (wks.geneve_tlv_option)
14969 : 0 : dev_flow->flow->geneve_tlv_option += wks.geneve_tlv_option;
14970 : : return 0;
14971 : : }
14972 : :
14973 : : /**
14974 : : * Fill the flow with DV spec, lock free
14975 : : * (mutex should be acquired by caller).
14976 : : *
14977 : : * @param[in] dev
14978 : : * Pointer to rte_eth_dev structure.
14979 : : * @param[in, out] dev_flow
14980 : : * Pointer to the sub flow.
14981 : : * @param[in] attr
14982 : : * Pointer to the flow attributes.
14983 : : * @param[in] items
14984 : : * Pointer to the list of items.
14985 : : * @param[in] actions
14986 : : * Pointer to the list of actions.
14987 : : * @param[out] error
14988 : : * Pointer to the error structure.
14989 : : *
14990 : : * @return
14991 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14992 : : */
14993 : : static int
14994 : 0 : flow_dv_translate(struct rte_eth_dev *dev,
14995 : : struct mlx5_flow *dev_flow,
14996 : : const struct rte_flow_attr *attr,
14997 : : const struct rte_flow_item items[],
14998 : : const struct rte_flow_action actions[],
14999 : : struct rte_flow_error *error)
15000 : : {
15001 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15002 : 0 : struct mlx5_sh_config *dev_conf = &priv->sh->config;
15003 : 0 : struct rte_flow *flow = dev_flow->flow;
15004 : 0 : struct mlx5_flow_handle *handle = dev_flow->handle;
15005 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
15006 : : struct mlx5_flow_rss_desc *rss_desc;
15007 : : uint64_t action_flags = 0;
15008 : 0 : struct mlx5_flow_dv_matcher matcher = {
15009 : : .mask = {
15010 : : .size = sizeof(matcher.mask.buf),
15011 : : },
15012 : : };
15013 : : int actions_n = 0;
15014 : : bool actions_end = false;
15015 : : union {
15016 : : struct mlx5_flow_dv_modify_hdr_resource res;
15017 : : uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
15018 : : sizeof(struct mlx5_modification_cmd) *
15019 : : (MLX5_MAX_MODIFY_NUM + 1)];
15020 : : } mhdr_dummy;
15021 : : struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
15022 : : const struct rte_flow_action_count *count = NULL;
15023 : : const struct rte_flow_action_age *non_shared_age = NULL;
15024 : 0 : union flow_dv_attr flow_attr = { .attr = 0 };
15025 : : uint32_t tag_be;
15026 : : union mlx5_flow_tbl_key tbl_key;
15027 : : uint32_t modify_action_position = UINT32_MAX;
15028 : 0 : struct rte_vlan_hdr vlan = { 0 };
15029 : : struct mlx5_flow_dv_dest_array_resource mdest_res;
15030 : : struct mlx5_flow_dv_sample_resource sample_res;
15031 : 0 : void *sample_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
15032 : : const struct rte_flow_action_sample *sample = NULL;
15033 : : struct mlx5_flow_sub_actions_list *sample_act;
15034 : : uint32_t sample_act_pos = UINT32_MAX;
15035 : : uint32_t age_act_pos = UINT32_MAX;
15036 : : uint32_t ipv6_tc_off = 0;
15037 : 0 : uint32_t num_of_dest = 0;
15038 : : int tmp_actions_n = 0;
15039 : : uint32_t table;
15040 : : int ret = 0;
15041 : : const struct mlx5_flow_tunnel *tunnel = NULL;
15042 : 0 : struct flow_grp_info grp_info = {
15043 : 0 : .external = !!dev_flow->external,
15044 : 0 : .transfer = !!attr->transfer,
15045 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
15046 : 0 : .skip_scale = dev_flow->skip_scale &
15047 : : (1 << MLX5_SCALE_FLOW_GROUP_BIT),
15048 : : .std_tbl_fix = true,
15049 : : };
15050 : :
15051 [ # # ]: 0 : if (!wks)
15052 : 0 : return rte_flow_error_set(error, ENOMEM,
15053 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15054 : : NULL,
15055 : : "failed to push flow workspace");
15056 [ # # ]: 0 : rss_desc = &wks->rss_desc;
15057 : : memset(&mdest_res, 0, sizeof(struct mlx5_flow_dv_dest_array_resource));
15058 : : memset(&sample_res, 0, sizeof(struct mlx5_flow_dv_sample_resource));
15059 [ # # ]: 0 : mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
15060 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
15061 : : /* update normal path action resource into last index of array */
15062 : : sample_act = &mdest_res.sample_act[MLX5_MAX_DEST_NUM - 1];
15063 [ # # ]: 0 : if (is_tunnel_offload_active(dev)) {
15064 [ # # ]: 0 : if (dev_flow->tunnel) {
15065 [ # # ]: 0 : RTE_VERIFY(dev_flow->tof_type ==
15066 : : MLX5_TUNNEL_OFFLOAD_MISS_RULE);
15067 : : tunnel = dev_flow->tunnel;
15068 : : } else {
15069 : 0 : tunnel = mlx5_get_tof(items, actions,
15070 : : &dev_flow->tof_type);
15071 : 0 : dev_flow->tunnel = tunnel;
15072 : : }
15073 [ # # ]: 0 : grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
15074 : : (dev, attr, tunnel, dev_flow->tof_type);
15075 : : }
15076 : 0 : mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
15077 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
15078 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel, attr->group, &table,
15079 : : &grp_info, error);
15080 [ # # ]: 0 : if (ret)
15081 : : return ret;
15082 : 0 : dev_flow->dv.group = table;
15083 [ # # ]: 0 : if (attr->transfer)
15084 : 0 : mhdr_res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
15085 : : /* number of actions must be set to 0 in case of dirty stack. */
15086 : 0 : mhdr_res->actions_num = 0;
15087 [ # # ]: 0 : if (is_flow_tunnel_match_rule(dev_flow->tof_type)) {
15088 : : /*
15089 : : * do not add decap action if match rule drops packet
15090 : : * HW rejects rules with decap & drop
15091 : : *
15092 : : * if tunnel match rule was inserted before matching tunnel set
15093 : : * rule flow table used in the match rule must be registered.
15094 : : * current implementation handles that in the
15095 : : * flow_dv_match_register() at the function end.
15096 : : */
15097 : : bool add_decap = true;
15098 : : const struct rte_flow_action *ptr = actions;
15099 : :
15100 [ # # ]: 0 : for (; ptr->type != RTE_FLOW_ACTION_TYPE_END; ptr++) {
15101 [ # # ]: 0 : if (ptr->type == RTE_FLOW_ACTION_TYPE_DROP) {
15102 : : add_decap = false;
15103 : : break;
15104 : : }
15105 : : }
15106 [ # # ]: 0 : if (add_decap) {
15107 [ # # ]: 0 : if (flow_dv_create_action_l2_decap(dev, dev_flow,
15108 : 0 : attr->transfer,
15109 : : error))
15110 : 0 : return -rte_errno;
15111 : 0 : dev_flow->dv.actions[actions_n++] =
15112 : 0 : dev_flow->dv.encap_decap->action;
15113 : : action_flags |= MLX5_FLOW_ACTION_DECAP;
15114 : : }
15115 : : }
15116 [ # # ]: 0 : for (; !actions_end ; actions++) {
15117 : : const struct rte_flow_action_queue *queue;
15118 : : const struct rte_flow_action_rss *rss;
15119 : : const struct rte_flow_action *action = actions;
15120 : : const uint8_t *rss_key;
15121 : : struct mlx5_flow_tbl_resource *tbl;
15122 : : struct mlx5_aso_age_action *age_act;
15123 : : struct mlx5_flow_counter *cnt_act;
15124 : 0 : uint32_t port_id = 0;
15125 : : struct mlx5_flow_dv_port_id_action_resource port_id_resource;
15126 : 0 : int action_type = actions->type;
15127 : : const struct rte_flow_action *found_action = NULL;
15128 : : uint32_t jump_group = 0;
15129 : : uint32_t owner_idx;
15130 : : struct mlx5_aso_ct_action *ct;
15131 : :
15132 : : if (!mlx5_flow_os_action_supported(action_type))
15133 : 0 : return rte_flow_error_set(error, ENOTSUP,
15134 : : RTE_FLOW_ERROR_TYPE_ACTION,
15135 : : actions,
15136 : : "action not supported");
15137 [ # # # # : 0 : switch (action_type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
15138 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
15139 : 0 : action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
15140 : 0 : break;
15141 : : case RTE_FLOW_ACTION_TYPE_VOID:
15142 : : break;
15143 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
15144 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
15145 [ # # ]: 0 : if (flow_dv_translate_action_port_id(dev, action,
15146 : : &port_id, error))
15147 : 0 : return -rte_errno;
15148 : 0 : port_id_resource.port_id = port_id;
15149 : : MLX5_ASSERT(!handle->rix_port_id_action);
15150 [ # # ]: 0 : if (flow_dv_port_id_action_resource_register
15151 : : (dev, &port_id_resource, dev_flow, error))
15152 : 0 : return -rte_errno;
15153 : 0 : dev_flow->dv.actions[actions_n++] =
15154 : 0 : dev_flow->dv.port_id_action->action;
15155 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_ID;
15156 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_PORT_ID;
15157 : 0 : sample_act->action_flags |= MLX5_FLOW_ACTION_PORT_ID;
15158 : 0 : num_of_dest++;
15159 : 0 : break;
15160 : 0 : case RTE_FLOW_ACTION_TYPE_FLAG:
15161 : 0 : action_flags |= MLX5_FLOW_ACTION_FLAG;
15162 : 0 : wks->mark = 1;
15163 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
15164 : 0 : struct rte_flow_action_mark mark = {
15165 : : .id = MLX5_FLOW_MARK_DEFAULT,
15166 : : };
15167 : :
15168 [ # # ]: 0 : if (flow_dv_convert_action_mark(dev, &mark,
15169 : : mhdr_res,
15170 : : error))
15171 : 0 : return -rte_errno;
15172 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
15173 : 0 : break;
15174 : : }
15175 : : tag_be = mlx5_flow_mark_set(MLX5_FLOW_MARK_DEFAULT);
15176 : : /*
15177 : : * Only one FLAG or MARK is supported per device flow
15178 : : * right now. So the pointer to the tag resource must be
15179 : : * zero before the register process.
15180 : : */
15181 : : MLX5_ASSERT(!handle->dvh.rix_tag);
15182 [ # # ]: 0 : if (flow_dv_tag_resource_register(dev, tag_be,
15183 : : dev_flow, error))
15184 : 0 : return -rte_errno;
15185 : : MLX5_ASSERT(dev_flow->dv.tag_resource);
15186 : 0 : dev_flow->dv.actions[actions_n++] =
15187 : 0 : dev_flow->dv.tag_resource->action;
15188 : 0 : break;
15189 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
15190 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK;
15191 : 0 : wks->mark = 1;
15192 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
15193 : 0 : const struct rte_flow_action_mark *mark =
15194 : : (const struct rte_flow_action_mark *)
15195 : : actions->conf;
15196 : :
15197 [ # # ]: 0 : if (flow_dv_convert_action_mark(dev, mark,
15198 : : mhdr_res,
15199 : : error))
15200 : 0 : return -rte_errno;
15201 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
15202 : 0 : break;
15203 : : }
15204 : : /* Fall-through */
15205 : : case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
15206 : : /* Legacy (non-extensive) MARK action. */
15207 : : tag_be = mlx5_flow_mark_set
15208 : : (((const struct rte_flow_action_mark *)
15209 [ # # ]: 0 : (actions->conf))->id);
15210 : : MLX5_ASSERT(!handle->dvh.rix_tag);
15211 [ # # ]: 0 : if (flow_dv_tag_resource_register(dev, tag_be,
15212 : : dev_flow, error))
15213 : 0 : return -rte_errno;
15214 : : MLX5_ASSERT(dev_flow->dv.tag_resource);
15215 : 0 : dev_flow->dv.actions[actions_n++] =
15216 : 0 : dev_flow->dv.tag_resource->action;
15217 : 0 : break;
15218 : 0 : case RTE_FLOW_ACTION_TYPE_SET_META:
15219 [ # # ]: 0 : if (flow_dv_convert_action_set_meta
15220 : : (dev, mhdr_res, attr,
15221 : : (const struct rte_flow_action_set_meta *)
15222 : 0 : actions->conf, error))
15223 : 0 : return -rte_errno;
15224 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_META;
15225 : 0 : break;
15226 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TAG:
15227 [ # # ]: 0 : if (flow_dv_convert_action_set_tag
15228 : : (dev, mhdr_res,
15229 : : (const struct rte_flow_action_set_tag *)
15230 : 0 : actions->conf, error))
15231 : 0 : return -rte_errno;
15232 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
15233 : 0 : break;
15234 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
15235 : 0 : action_flags |= MLX5_FLOW_ACTION_DROP;
15236 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_DROP;
15237 : 0 : break;
15238 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
15239 : 0 : queue = actions->conf;
15240 : 0 : rss_desc->queue_num = 1;
15241 : 0 : rss_desc->queue[0] = queue->index;
15242 : 0 : action_flags |= MLX5_FLOW_ACTION_QUEUE;
15243 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
15244 : 0 : sample_act->action_flags |= MLX5_FLOW_ACTION_QUEUE;
15245 : 0 : num_of_dest++;
15246 : 0 : break;
15247 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
15248 : 0 : rss = actions->conf;
15249 : 0 : rss_desc->symmetric_hash_function =
15250 : 0 : MLX5_RSS_IS_SYMM(rss->func);
15251 : 0 : memcpy(rss_desc->queue, rss->queue,
15252 [ # # ]: 0 : rss->queue_num * sizeof(uint16_t));
15253 : 0 : rss_desc->queue_num = rss->queue_num;
15254 : : /* NULL RSS key indicates default RSS key. */
15255 [ # # ]: 0 : rss_key = !rss->key ? rss_hash_default_key : rss->key;
15256 [ # # ]: 0 : memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
15257 : : /*
15258 : : * rss->level and rss.types should be set in advance
15259 : : * when expanding items for RSS.
15260 : : */
15261 : 0 : action_flags |= MLX5_FLOW_ACTION_RSS;
15262 : 0 : dev_flow->handle->fate_action = rss_desc->shared_rss ?
15263 [ # # ]: 0 : MLX5_FLOW_FATE_SHARED_RSS :
15264 : : MLX5_FLOW_FATE_QUEUE;
15265 : 0 : break;
15266 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
15267 : 0 : owner_idx = (uint32_t)(uintptr_t)action->conf;
15268 : 0 : age_act = flow_aso_age_get_by_idx(dev, owner_idx);
15269 [ # # ]: 0 : if (flow->age == 0) {
15270 : 0 : flow->age = owner_idx;
15271 : 0 : rte_atomic_fetch_add_explicit(&age_act->refcnt, 1,
15272 : : rte_memory_order_relaxed);
15273 : : }
15274 : 0 : age_act_pos = actions_n++;
15275 : 0 : action_flags |= MLX5_FLOW_ACTION_AGE;
15276 : 0 : break;
15277 : 0 : case RTE_FLOW_ACTION_TYPE_SEND_TO_KERNEL:
15278 : 0 : dev_flow->dv.actions[actions_n] =
15279 : 0 : flow_dv_translate_action_send_to_kernel(dev, attr,
15280 : : error);
15281 [ # # ]: 0 : if (!dev_flow->dv.actions[actions_n])
15282 : 0 : return -rte_errno;
15283 : 0 : actions_n++;
15284 : 0 : action_flags |= MLX5_FLOW_ACTION_SEND_TO_KERNEL;
15285 : 0 : dev_flow->handle->fate_action =
15286 : : MLX5_FLOW_FATE_SEND_TO_KERNEL;
15287 : 0 : break;
15288 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
15289 : 0 : non_shared_age = action->conf;
15290 : 0 : age_act_pos = actions_n++;
15291 : 0 : action_flags |= MLX5_FLOW_ACTION_AGE;
15292 : 0 : break;
15293 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
15294 [ # # ]: 0 : owner_idx = (uint32_t)(uintptr_t)action->conf;
15295 : : cnt_act = flow_dv_counter_get_by_idx(dev, owner_idx,
15296 : : NULL);
15297 : : MLX5_ASSERT(cnt_act != NULL);
15298 : : /**
15299 : : * When creating meter drop flow in drop table, the
15300 : : * counter should not overwrite the rte flow counter.
15301 : : */
15302 [ # # ]: 0 : if (attr->group == MLX5_FLOW_TABLE_LEVEL_METER &&
15303 [ # # ]: 0 : dev_flow->dv.table_id == MLX5_MTR_TABLE_ID_DROP) {
15304 : 0 : dev_flow->dv.actions[actions_n++] =
15305 : 0 : cnt_act->action;
15306 : : } else {
15307 [ # # ]: 0 : if (flow->counter == 0) {
15308 : 0 : flow->counter = owner_idx;
15309 : 0 : rte_atomic_fetch_add_explicit
15310 : : (&cnt_act->shared_info.refcnt,
15311 : : 1, rte_memory_order_relaxed);
15312 : : }
15313 : : /* Save information first, will apply later. */
15314 : 0 : action_flags |= MLX5_FLOW_ACTION_COUNT;
15315 : : }
15316 : : break;
15317 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
15318 [ # # ]: 0 : if (!priv->sh->cdev->config.devx) {
15319 : 0 : return rte_flow_error_set
15320 : : (error, ENOTSUP,
15321 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15322 : : NULL,
15323 : : "count action not supported");
15324 : : }
15325 : : /* Save information first, will apply later. */
15326 : 0 : count = action->conf;
15327 : 0 : action_flags |= MLX5_FLOW_ACTION_COUNT;
15328 : 0 : break;
15329 : 0 : case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
15330 : 0 : dev_flow->dv.actions[actions_n++] =
15331 : 0 : priv->sh->pop_vlan_action;
15332 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
15333 : 0 : break;
15334 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
15335 [ # # ]: 0 : if (!(action_flags &
15336 : : MLX5_FLOW_ACTION_OF_SET_VLAN_VID))
15337 : 0 : flow_dev_get_vlan_info_from_items(items, &vlan);
15338 [ # # ]: 0 : vlan.eth_proto = rte_be_to_cpu_16
15339 : : ((((const struct rte_flow_action_of_push_vlan *)
15340 : : actions->conf)->ethertype));
15341 : 0 : found_action = mlx5_flow_find_action
15342 : : (actions + 1,
15343 : : RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID);
15344 [ # # ]: 0 : if (found_action)
15345 : 0 : mlx5_update_vlan_vid_pcp(found_action, &vlan);
15346 : 0 : found_action = mlx5_flow_find_action
15347 : : (actions + 1,
15348 : : RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP);
15349 [ # # ]: 0 : if (found_action)
15350 : 0 : mlx5_update_vlan_vid_pcp(found_action, &vlan);
15351 [ # # ]: 0 : if (flow_dv_create_action_push_vlan
15352 : : (dev, attr, &vlan, dev_flow, error))
15353 : 0 : return -rte_errno;
15354 : 0 : dev_flow->dv.actions[actions_n++] =
15355 : 0 : dev_flow->dv.push_vlan_res->action;
15356 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
15357 : 0 : break;
15358 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
15359 : : /* of_vlan_push action handled this action */
15360 : : MLX5_ASSERT(action_flags &
15361 : : MLX5_FLOW_ACTION_OF_PUSH_VLAN);
15362 : : break;
15363 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
15364 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
15365 : : break;
15366 : 0 : flow_dev_get_vlan_info_from_items(items, &vlan);
15367 : 0 : mlx5_update_vlan_vid_pcp(actions, &vlan);
15368 : : /* If no VLAN push - this is a modify header action */
15369 [ # # ]: 0 : if (flow_dv_convert_action_modify_vlan_vid
15370 : : (mhdr_res, actions, error))
15371 : 0 : return -rte_errno;
15372 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
15373 : 0 : break;
15374 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
15375 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
15376 [ # # ]: 0 : if (flow_dv_create_action_l2_encap(dev, actions,
15377 : : dev_flow,
15378 : 0 : attr->transfer,
15379 : : error))
15380 : 0 : return -rte_errno;
15381 : 0 : dev_flow->dv.actions[actions_n++] =
15382 : 0 : dev_flow->dv.encap_decap->action;
15383 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
15384 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
15385 : 0 : sample_act->action_flags |=
15386 : : MLX5_FLOW_ACTION_ENCAP;
15387 : : break;
15388 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
15389 : : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
15390 [ # # ]: 0 : if (flow_dv_create_action_l2_decap(dev, dev_flow,
15391 : 0 : attr->transfer,
15392 : : error))
15393 : 0 : return -rte_errno;
15394 : 0 : dev_flow->dv.actions[actions_n++] =
15395 : 0 : dev_flow->dv.encap_decap->action;
15396 : 0 : action_flags |= MLX5_FLOW_ACTION_DECAP;
15397 : 0 : break;
15398 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
15399 : : /* Handle encap with preceding decap. */
15400 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_DECAP) {
15401 [ # # ]: 0 : if (flow_dv_create_action_raw_encap
15402 : : (dev, actions, dev_flow, attr, error))
15403 : 0 : return -rte_errno;
15404 : 0 : dev_flow->dv.actions[actions_n++] =
15405 : 0 : dev_flow->dv.encap_decap->action;
15406 : : } else {
15407 : : /* Handle encap without preceding decap. */
15408 [ # # ]: 0 : if (flow_dv_create_action_l2_encap
15409 : 0 : (dev, actions, dev_flow, attr->transfer,
15410 : : error))
15411 : 0 : return -rte_errno;
15412 : 0 : dev_flow->dv.actions[actions_n++] =
15413 : 0 : dev_flow->dv.encap_decap->action;
15414 : : }
15415 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
15416 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
15417 : 0 : sample_act->action_flags |=
15418 : : MLX5_FLOW_ACTION_ENCAP;
15419 : : break;
15420 : : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
15421 [ # # ]: 0 : while ((++action)->type == RTE_FLOW_ACTION_TYPE_VOID)
15422 : : ;
15423 [ # # ]: 0 : if (action->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
15424 [ # # ]: 0 : if (flow_dv_create_action_l2_decap
15425 : 0 : (dev, dev_flow, attr->transfer, error))
15426 : 0 : return -rte_errno;
15427 : 0 : dev_flow->dv.actions[actions_n++] =
15428 : 0 : dev_flow->dv.encap_decap->action;
15429 : : }
15430 : : /* If decap is followed by encap, handle it at encap. */
15431 : 0 : action_flags |= MLX5_FLOW_ACTION_DECAP;
15432 : 0 : break;
15433 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_JUMP:
15434 : 0 : dev_flow->dv.actions[actions_n++] =
15435 : 0 : (void *)(uintptr_t)action->conf;
15436 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP;
15437 : 0 : break;
15438 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
15439 : 0 : jump_group = ((const struct rte_flow_action_jump *)
15440 : 0 : action->conf)->group;
15441 : 0 : grp_info.std_tbl_fix = 0;
15442 [ # # ]: 0 : if (dev_flow->skip_scale &
15443 : : (1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT))
15444 : 0 : grp_info.skip_scale = 1;
15445 : : else
15446 : 0 : grp_info.skip_scale = 0;
15447 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel,
15448 : : jump_group,
15449 : : &table,
15450 : : &grp_info, error);
15451 [ # # ]: 0 : if (ret)
15452 : 0 : return ret;
15453 : 0 : tbl = flow_dv_tbl_resource_get(dev, table, attr->egress,
15454 : 0 : attr->transfer,
15455 : 0 : !!dev_flow->external,
15456 : : tunnel, jump_group, 0,
15457 : : 0, error);
15458 [ # # ]: 0 : if (!tbl)
15459 : 0 : return rte_flow_error_set
15460 : 0 : (error, errno,
15461 : : RTE_FLOW_ERROR_TYPE_ACTION,
15462 : : NULL,
15463 : : "cannot create jump action.");
15464 : : if (flow_dv_jump_tbl_resource_register
15465 : : (dev, tbl, dev_flow, error)) {
15466 : : flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
15467 : : return rte_flow_error_set
15468 : : (error, errno,
15469 : : RTE_FLOW_ERROR_TYPE_ACTION,
15470 : : NULL,
15471 : : "cannot create jump action.");
15472 : : }
15473 : 0 : dev_flow->dv.actions[actions_n++] =
15474 : 0 : dev_flow->dv.jump->action;
15475 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP;
15476 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_JUMP;
15477 : 0 : sample_act->action_flags |= MLX5_FLOW_ACTION_JUMP;
15478 : 0 : num_of_dest++;
15479 : 0 : break;
15480 : 0 : case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
15481 : : case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
15482 [ # # ]: 0 : if (flow_dv_convert_action_modify_mac
15483 : : (mhdr_res, actions, error))
15484 : 0 : return -rte_errno;
15485 : 0 : action_flags |= actions->type ==
15486 : : RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
15487 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_MAC_SRC :
15488 : : MLX5_FLOW_ACTION_SET_MAC_DST;
15489 : 0 : break;
15490 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
15491 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
15492 [ # # ]: 0 : if (flow_dv_convert_action_modify_ipv4
15493 : : (mhdr_res, actions, error))
15494 : 0 : return -rte_errno;
15495 : 0 : action_flags |= actions->type ==
15496 : : RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
15497 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_IPV4_SRC :
15498 : : MLX5_FLOW_ACTION_SET_IPV4_DST;
15499 : 0 : break;
15500 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
15501 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
15502 [ # # ]: 0 : if (flow_dv_convert_action_modify_ipv6
15503 : : (mhdr_res, actions, error))
15504 : 0 : return -rte_errno;
15505 : 0 : action_flags |= actions->type ==
15506 : : RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
15507 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_IPV6_SRC :
15508 : : MLX5_FLOW_ACTION_SET_IPV6_DST;
15509 : 0 : break;
15510 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
15511 : : case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
15512 [ # # ]: 0 : if (flow_dv_convert_action_modify_tp
15513 : : (mhdr_res, actions, items,
15514 : 0 : &flow_attr, dev_flow, !!(action_flags &
15515 : : MLX5_FLOW_ACTION_DECAP), error))
15516 : 0 : return -rte_errno;
15517 : 0 : action_flags |= actions->type ==
15518 : : RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
15519 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_TP_SRC :
15520 : : MLX5_FLOW_ACTION_SET_TP_DST;
15521 : 0 : break;
15522 : 0 : case RTE_FLOW_ACTION_TYPE_DEC_TTL:
15523 [ # # ]: 0 : if (flow_dv_convert_action_modify_dec_ttl
15524 : : (mhdr_res, items, &flow_attr, dev_flow,
15525 : 0 : !!(action_flags &
15526 : : MLX5_FLOW_ACTION_DECAP), error))
15527 : 0 : return -rte_errno;
15528 : 0 : action_flags |= MLX5_FLOW_ACTION_DEC_TTL;
15529 : 0 : break;
15530 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TTL:
15531 [ # # ]: 0 : if (flow_dv_convert_action_modify_ttl
15532 : : (mhdr_res, actions, items, &flow_attr,
15533 : 0 : dev_flow, !!(action_flags &
15534 : : MLX5_FLOW_ACTION_DECAP), error))
15535 : 0 : return -rte_errno;
15536 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TTL;
15537 : 0 : break;
15538 : 0 : case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
15539 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
15540 [ # # ]: 0 : if (flow_dv_convert_action_modify_tcp_seq
15541 : : (mhdr_res, actions, error))
15542 : 0 : return -rte_errno;
15543 : 0 : action_flags |= actions->type ==
15544 : : RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
15545 [ # # ]: 0 : MLX5_FLOW_ACTION_INC_TCP_SEQ :
15546 : : MLX5_FLOW_ACTION_DEC_TCP_SEQ;
15547 : 0 : break;
15548 : :
15549 : 0 : case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
15550 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
15551 [ # # ]: 0 : if (flow_dv_convert_action_modify_tcp_ack
15552 : : (mhdr_res, actions, error))
15553 : 0 : return -rte_errno;
15554 : 0 : action_flags |= actions->type ==
15555 : : RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
15556 [ # # ]: 0 : MLX5_FLOW_ACTION_INC_TCP_ACK :
15557 : : MLX5_FLOW_ACTION_DEC_TCP_ACK;
15558 : 0 : break;
15559 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
15560 [ # # ]: 0 : if (flow_dv_convert_action_set_reg
15561 : : (mhdr_res, actions, error))
15562 : 0 : return -rte_errno;
15563 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
15564 : 0 : break;
15565 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
15566 [ # # ]: 0 : if (flow_dv_convert_action_copy_mreg
15567 : : (dev, mhdr_res, actions, error))
15568 : 0 : return -rte_errno;
15569 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
15570 : 0 : break;
15571 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
15572 : 0 : action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
15573 : 0 : dev_flow->handle->fate_action =
15574 : : MLX5_FLOW_FATE_DEFAULT_MISS;
15575 : 0 : break;
15576 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
15577 [ # # ]: 0 : if (!wks->fm)
15578 : 0 : return rte_flow_error_set(error, rte_errno,
15579 : : RTE_FLOW_ERROR_TYPE_ACTION,
15580 : : NULL, "Failed to get meter in flow.");
15581 : : /* Set the meter action. */
15582 : 0 : dev_flow->dv.actions[actions_n++] =
15583 : 0 : wks->fm->meter_action_g;
15584 : 0 : action_flags |= MLX5_FLOW_ACTION_METER;
15585 : 0 : break;
15586 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
15587 [ # # ]: 0 : if (flow_dv_convert_action_modify_ipv4_dscp(mhdr_res,
15588 : : actions, error))
15589 : 0 : return -rte_errno;
15590 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
15591 : 0 : break;
15592 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
15593 [ # # ]: 0 : if (mlx5_dv_modify_ipv6_traffic_class_supported(priv))
15594 : : ipv6_tc_off = MLX5_IPV6_HDR_DSCP_SHIFT;
15595 : : else
15596 : : ipv6_tc_off = 0;
15597 [ # # ]: 0 : if (flow_dv_convert_action_modify_ipv6_dscp(mhdr_res,
15598 : : actions, ipv6_tc_off, error))
15599 : 0 : return -rte_errno;
15600 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
15601 : 0 : break;
15602 : 0 : case RTE_FLOW_ACTION_TYPE_SAMPLE:
15603 : 0 : sample_act_pos = actions_n;
15604 : 0 : sample = (const struct rte_flow_action_sample *)
15605 : : action->conf;
15606 : 0 : actions_n++;
15607 : 0 : action_flags |= MLX5_FLOW_ACTION_SAMPLE;
15608 : : /* put encap action into group if work with port id */
15609 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_ENCAP) &&
15610 : : (action_flags & MLX5_FLOW_ACTION_PORT_ID))
15611 : 0 : sample_act->action_flags |=
15612 : : MLX5_FLOW_ACTION_ENCAP;
15613 : : break;
15614 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
15615 [ # # ]: 0 : if (flow_dv_convert_action_modify_field
15616 : : (dev, mhdr_res, actions, attr, error))
15617 : 0 : return -rte_errno;
15618 : 0 : action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
15619 : 0 : break;
15620 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
15621 : 0 : owner_idx = (uint32_t)(uintptr_t)action->conf;
15622 : 0 : ct = flow_aso_ct_get_by_idx(dev, owner_idx);
15623 [ # # ]: 0 : if (!ct)
15624 : 0 : return rte_flow_error_set(error, EINVAL,
15625 : : RTE_FLOW_ERROR_TYPE_ACTION,
15626 : : NULL,
15627 : : "Failed to get CT object.");
15628 [ # # ]: 0 : if (mlx5_aso_ct_available(priv->sh, MLX5_HW_INV_QUEUE, ct))
15629 : 0 : return rte_flow_error_set(error, rte_errno,
15630 : : RTE_FLOW_ERROR_TYPE_ACTION,
15631 : : NULL,
15632 : : "CT is unavailable.");
15633 [ # # ]: 0 : if (ct->is_original)
15634 : 0 : dev_flow->dv.actions[actions_n] =
15635 : 0 : ct->dr_action_orig;
15636 : : else
15637 : 0 : dev_flow->dv.actions[actions_n] =
15638 : 0 : ct->dr_action_rply;
15639 [ # # ]: 0 : if (flow->ct == 0) {
15640 : 0 : flow->indirect_type =
15641 : : MLX5_INDIRECT_ACTION_TYPE_CT;
15642 : 0 : flow->ct = owner_idx;
15643 : 0 : rte_atomic_fetch_add_explicit(&ct->refcnt, 1,
15644 : : rte_memory_order_relaxed);
15645 : : }
15646 : 0 : actions_n++;
15647 : 0 : action_flags |= MLX5_FLOW_ACTION_CT;
15648 : 0 : break;
15649 : 0 : case RTE_FLOW_ACTION_TYPE_END:
15650 : : actions_end = true;
15651 [ # # ]: 0 : if (mhdr_res->actions_num) {
15652 : : /* create modify action if needed. */
15653 [ # # ]: 0 : if (flow_dv_modify_hdr_resource_register
15654 : : (dev, mhdr_res, dev_flow, error))
15655 : 0 : return -rte_errno;
15656 : 0 : dev_flow->dv.actions[modify_action_position] =
15657 : 0 : handle->dvh.modify_hdr->action;
15658 : : }
15659 : : /*
15660 : : * Handle AGE and COUNT action by single HW counter
15661 : : * when they are not shared.
15662 : : */
15663 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_AGE) {
15664 [ # # # # ]: 0 : if ((non_shared_age && count) ||
15665 [ # # ]: 0 : !flow_hit_aso_supported(priv, !dev_flow->dv.group)) {
15666 : : /* Creates age by counters. */
15667 : 0 : cnt_act = flow_dv_prepare_counter
15668 : : (dev, dev_flow,
15669 : : flow, count,
15670 : : non_shared_age,
15671 : : error);
15672 [ # # ]: 0 : if (!cnt_act)
15673 : 0 : return -rte_errno;
15674 : 0 : dev_flow->dv.actions[age_act_pos] =
15675 : 0 : cnt_act->action;
15676 : 0 : break;
15677 : : }
15678 [ # # # # ]: 0 : if (!flow->age && non_shared_age) {
15679 : 0 : flow->age = flow_dv_aso_age_alloc
15680 : : (dev, error);
15681 [ # # ]: 0 : if (!flow->age)
15682 : 0 : return -rte_errno;
15683 : 0 : flow_dv_aso_age_params_init
15684 : : (dev, flow->age,
15685 : 0 : non_shared_age->context ?
15686 : : non_shared_age->context :
15687 : 0 : (void *)(uintptr_t)
15688 : 0 : (dev_flow->flow_idx),
15689 [ # # ]: 0 : non_shared_age->timeout);
15690 : : }
15691 : 0 : age_act = flow_aso_age_get_by_idx(dev,
15692 : : flow->age);
15693 : 0 : dev_flow->dv.actions[age_act_pos] =
15694 : 0 : age_act->dr_action;
15695 : : }
15696 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_COUNT) {
15697 : : /*
15698 : : * Create one count action, to be used
15699 : : * by all sub-flows.
15700 : : */
15701 : 0 : cnt_act = flow_dv_prepare_counter(dev, dev_flow,
15702 : : flow, count,
15703 : : NULL, error);
15704 [ # # ]: 0 : if (!cnt_act)
15705 : 0 : return -rte_errno;
15706 : 0 : dev_flow->dv.actions[actions_n++] =
15707 : 0 : cnt_act->action;
15708 : : }
15709 : : default:
15710 : : break;
15711 : : }
15712 [ # # # # ]: 0 : if (mhdr_res->actions_num &&
15713 : : modify_action_position == UINT32_MAX)
15714 : 0 : modify_action_position = actions_n++;
15715 : : }
15716 : 0 : dev_flow->act_flags = action_flags;
15717 : 0 : ret = flow_dv_translate_items_sws(dev, dev_flow, attr, items, &matcher,
15718 : : error);
15719 [ # # ]: 0 : if (ret)
15720 : 0 : return -rte_errno;
15721 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_RSS) {
15722 : 0 : dev_flow->symmetric_hash_function = rss_desc->symmetric_hash_function;
15723 : 0 : flow_dv_hashfields_set(dev_flow->handle->layers,
15724 : : rss_desc,
15725 : : &dev_flow->hash_fields);
15726 : : }
15727 : : /* If has RSS action in the sample action, the Sample/Mirror resource
15728 : : * should be registered after the hash filed be update.
15729 : : */
15730 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE) {
15731 : 0 : ret = flow_dv_translate_action_sample(dev,
15732 : : sample,
15733 : : dev_flow, attr,
15734 : : &num_of_dest,
15735 : : sample_actions,
15736 : : &sample_res,
15737 : : error);
15738 [ # # ]: 0 : if (ret < 0)
15739 : : return ret;
15740 : 0 : ret = flow_dv_create_action_sample(dev,
15741 : : dev_flow,
15742 : : num_of_dest,
15743 : : &sample_res,
15744 : : &mdest_res,
15745 : : sample_actions,
15746 : : action_flags,
15747 : : error);
15748 [ # # ]: 0 : if (ret < 0)
15749 : 0 : return rte_flow_error_set
15750 : : (error, rte_errno,
15751 : : RTE_FLOW_ERROR_TYPE_ACTION,
15752 : : NULL,
15753 : : "cannot create sample action");
15754 [ # # ]: 0 : if (num_of_dest > 1) {
15755 : 0 : dev_flow->dv.actions[sample_act_pos] =
15756 : 0 : dev_flow->dv.dest_array_res->action;
15757 : : } else {
15758 : 0 : dev_flow->dv.actions[sample_act_pos] =
15759 : 0 : dev_flow->dv.sample_res->verbs_action;
15760 : : }
15761 : : }
15762 : : /*
15763 : : * For multiple destination (sample action with ratio=1), the encap
15764 : : * action and port id action will be combined into group action.
15765 : : * So need remove the original these actions in the flow and only
15766 : : * use the sample action instead of.
15767 : : */
15768 [ # # ]: 0 : if (num_of_dest > 1 &&
15769 [ # # # # ]: 0 : (sample_act->dr_port_id_action || sample_act->dr_jump_action)) {
15770 : : int i;
15771 : 0 : void *temp_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
15772 : :
15773 [ # # ]: 0 : for (i = 0; i < actions_n; i++) {
15774 [ # # ]: 0 : if ((sample_act->dr_encap_action &&
15775 : : sample_act->dr_encap_action ==
15776 [ # # # # ]: 0 : dev_flow->dv.actions[i]) ||
15777 : 0 : (sample_act->dr_port_id_action &&
15778 : : sample_act->dr_port_id_action ==
15779 [ # # ]: 0 : dev_flow->dv.actions[i]) ||
15780 [ # # ]: 0 : (sample_act->dr_jump_action &&
15781 : : sample_act->dr_jump_action ==
15782 [ # # ]: 0 : dev_flow->dv.actions[i]))
15783 : 0 : continue;
15784 : 0 : temp_actions[tmp_actions_n++] = dev_flow->dv.actions[i];
15785 : : }
15786 : 0 : memcpy((void *)dev_flow->dv.actions,
15787 : : (void *)temp_actions,
15788 : : tmp_actions_n * sizeof(void *));
15789 : : actions_n = tmp_actions_n;
15790 : : }
15791 : 0 : dev_flow->dv.actions_n = actions_n;
15792 [ # # ]: 0 : if (wks->skip_matcher_reg)
15793 : : return 0;
15794 : : /* Register matcher. */
15795 : 0 : matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
15796 : : matcher.mask.size);
15797 : 0 : matcher.priority = mlx5_get_matcher_priority(dev, attr,
15798 : 0 : matcher.priority,
15799 : 0 : dev_flow->external);
15800 : : /**
15801 : : * When creating meter drop flow in drop table, using original
15802 : : * 5-tuple match, the matcher priority should be lower than
15803 : : * mtr_id matcher.
15804 : : */
15805 [ # # ]: 0 : if (attr->group == MLX5_FLOW_TABLE_LEVEL_METER &&
15806 [ # # # # ]: 0 : dev_flow->dv.table_id == MLX5_MTR_TABLE_ID_DROP &&
15807 : : matcher.priority <= MLX5_REG_BITS)
15808 : 0 : matcher.priority += MLX5_REG_BITS;
15809 : : /* reserved field no needs to be set to 0 here. */
15810 : 0 : tbl_key.is_fdb = attr->transfer;
15811 : 0 : tbl_key.is_egress = attr->egress;
15812 : 0 : tbl_key.level = dev_flow->dv.group;
15813 : 0 : tbl_key.id = dev_flow->dv.table_id;
15814 [ # # ]: 0 : if (flow_dv_matcher_register(dev, &matcher, &tbl_key, dev_flow,
15815 : : tunnel, attr->group, error))
15816 : 0 : return -rte_errno;
15817 : : return 0;
15818 : : }
15819 : :
15820 : : /*
15821 : : * Protocol selector bitmap
15822 : : * Each flag is used as an indicator that given protocol is specified in given RSS hash fields.
15823 : : */
15824 : : #define RX_HASH_SELECTOR_IPV4 RTE_BIT32(0)
15825 : : #define RX_HASH_SELECTOR_IPV6 RTE_BIT32(1)
15826 : : #define RX_HASH_SELECTOR_UDP RTE_BIT32(2)
15827 : : #define RX_HASH_SELECTOR_TCP RTE_BIT32(3)
15828 : : #define RX_HASH_SELECTOR_ESP_SPI RTE_BIT32(4)
15829 : : #define RX_HASH_SELECTOR_NONE (0)
15830 : :
15831 : : #define RX_HASH_SELECTOR_IPV4_TCP (RX_HASH_SELECTOR_IPV4 | RX_HASH_SELECTOR_TCP)
15832 : : #define RX_HASH_SELECTOR_IPV4_UDP (RX_HASH_SELECTOR_IPV4 | RX_HASH_SELECTOR_UDP)
15833 : : #define RX_HASH_SELECTOR_IPV4_ESP (RX_HASH_SELECTOR_IPV4 | RX_HASH_SELECTOR_ESP_SPI)
15834 : :
15835 : : #define RX_HASH_SELECTOR_IPV6_TCP (RX_HASH_SELECTOR_IPV6 | RX_HASH_SELECTOR_TCP)
15836 : : #define RX_HASH_SELECTOR_IPV6_UDP (RX_HASH_SELECTOR_IPV6 | RX_HASH_SELECTOR_UDP)
15837 : : #define RX_HASH_SELECTOR_IPV6_ESP (RX_HASH_SELECTOR_IPV6 | RX_HASH_SELECTOR_ESP_SPI)
15838 : :
15839 : : static bool
15840 : : rx_hash_selector_has_valid_l3(const uint32_t selectors)
15841 : : {
15842 : : /* In TIR configuration, RSS hashing on both IPv4 and IPv6 is mutually exclusive. */
15843 : : return !((selectors & RX_HASH_SELECTOR_IPV4) && (selectors & RX_HASH_SELECTOR_IPV6));
15844 : : }
15845 : :
15846 : : static bool
15847 : : rx_hash_selector_has_valid_l4(const uint32_t selectors)
15848 : : {
15849 : : /* In TIR configuration, RSS hashing on both UDP and TCP is mutually exclusive. */
15850 : 0 : return !((selectors & RX_HASH_SELECTOR_UDP) && (selectors & RX_HASH_SELECTOR_TCP));
15851 : : }
15852 : :
15853 : : static bool
15854 : : rx_hash_selector_has_valid_esp(const uint32_t selectors)
15855 : : {
15856 : : /* In TIR configuration, RSS hashing on ESP and other L4 protocol is mutually exclusive. */
15857 [ # # ]: 0 : if (selectors & RX_HASH_SELECTOR_ESP_SPI)
15858 : 0 : return !((selectors & RX_HASH_SELECTOR_UDP) || (selectors & RX_HASH_SELECTOR_TCP));
15859 : :
15860 : : return true;
15861 : : }
15862 : :
15863 : : /**
15864 : : * Calculate protocol combination based on provided RSS hashing fields.
15865 : : *
15866 : : * @param[in] hash_fields
15867 : : * Requested RSS hashing fields specified as a flags bitmap, based on ibv_rx_hash_fields.
15868 : : * @param[out] selectors_out
15869 : : * Calculated protocol combination will be written here.
15870 : : * Result will be a bitmap of RX_HASH_SELECTOR_* flags.
15871 : : *
15872 : : * @return
15873 : : * 0 if conversion is successful and protocol combination written to @p selectors_out.
15874 : : * (-EINVAL) otherwise.
15875 : : */
15876 : : static int
15877 : 0 : rx_hash_calc_selector(const uint64_t hash_fields, uint32_t *selectors_out)
15878 : : {
15879 : : const uint64_t filtered_hf = hash_fields & ~IBV_RX_HASH_INNER;
15880 : : uint32_t selectors = 0;
15881 : :
15882 [ # # ]: 0 : if (filtered_hf & MLX5_RSS_HASH_IPV4)
15883 : : selectors |= RX_HASH_SELECTOR_IPV4;
15884 [ # # ]: 0 : if (filtered_hf & MLX5_RSS_HASH_IPV6)
15885 : 0 : selectors |= RX_HASH_SELECTOR_IPV6;
15886 [ # # ]: 0 : if (!rx_hash_selector_has_valid_l3(selectors)) {
15887 : 0 : DRV_LOG(NOTICE, "hrxq hashing on both IPv4 and IPv6 is invalid: "
15888 : : "selectors=0x%" PRIx32, selectors);
15889 : 0 : return -EINVAL;
15890 : : }
15891 : :
15892 [ # # ]: 0 : if (filtered_hf & MLX5_UDP_IBV_RX_HASH)
15893 : 0 : selectors |= RX_HASH_SELECTOR_UDP;
15894 [ # # ]: 0 : if (filtered_hf & MLX5_TCP_IBV_RX_HASH)
15895 : 0 : selectors |= RX_HASH_SELECTOR_TCP;
15896 [ # # ]: 0 : if (!rx_hash_selector_has_valid_l4(selectors)) {
15897 : 0 : DRV_LOG(NOTICE, "hrxq hashing on both UDP and TCP is invalid: "
15898 : : "selectors=0x%" PRIx32, selectors);
15899 : 0 : return -EINVAL;
15900 : : }
15901 : :
15902 [ # # ]: 0 : if (filtered_hf & MLX5_RSS_HASH_ESP_SPI)
15903 : 0 : selectors |= RX_HASH_SELECTOR_ESP_SPI;
15904 [ # # ]: 0 : if (!rx_hash_selector_has_valid_esp(selectors)) {
15905 : 0 : DRV_LOG(NOTICE, "hrxq hashing on ESP SPI and UDP or TCP is mutually exclusive: "
15906 : : "selectors=0x%" PRIx32, selectors);
15907 : 0 : return -EINVAL;
15908 : : }
15909 : :
15910 : 0 : *selectors_out = selectors;
15911 : 0 : return 0;
15912 : : }
15913 : :
15914 : : /**
15915 : : * Calculate the hrxq object index based on protocol combination.
15916 : : *
15917 : : * @param[in] selectors
15918 : : * Protocol combination specified as bitmap of RX_HASH_SELECTOR_* flags.
15919 : : *
15920 : : * @return
15921 : : * Index into hrxq array in #mlx5_shared_action_rss based on ginve protocol combination.
15922 : : * (-EINVAL) if given protocol combination is not supported or is invalid.
15923 : : */
15924 : : static int
15925 : 0 : get_rss_hash_idx(const uint32_t selectors)
15926 : : {
15927 [ # # # # : 0 : switch (selectors) {
# # # # #
# # # # ]
15928 : : case RX_HASH_SELECTOR_IPV4:
15929 : : return MLX5_RSS_HASH_IDX_IPV4;
15930 : 0 : case RX_HASH_SELECTOR_IPV4_TCP:
15931 : 0 : return MLX5_RSS_HASH_IDX_IPV4_TCP;
15932 : 0 : case RX_HASH_SELECTOR_IPV4_UDP:
15933 : 0 : return MLX5_RSS_HASH_IDX_IPV4_UDP;
15934 : 0 : case RX_HASH_SELECTOR_IPV4_ESP:
15935 : 0 : return MLX5_RSS_HASH_IDX_IPV4_ESP;
15936 : 0 : case RX_HASH_SELECTOR_IPV6:
15937 : 0 : return MLX5_RSS_HASH_IDX_IPV6;
15938 : 0 : case RX_HASH_SELECTOR_IPV6_TCP:
15939 : 0 : return MLX5_RSS_HASH_IDX_IPV6_TCP;
15940 : 0 : case RX_HASH_SELECTOR_IPV6_UDP:
15941 : 0 : return MLX5_RSS_HASH_IDX_IPV6_UDP;
15942 : 0 : case RX_HASH_SELECTOR_IPV6_ESP:
15943 : 0 : return MLX5_RSS_HASH_IDX_IPV6_ESP;
15944 : 0 : case RX_HASH_SELECTOR_TCP:
15945 : 0 : return MLX5_RSS_HASH_IDX_TCP;
15946 : 0 : case RX_HASH_SELECTOR_UDP:
15947 : 0 : return MLX5_RSS_HASH_IDX_UDP;
15948 : 0 : case RX_HASH_SELECTOR_ESP_SPI:
15949 : 0 : return MLX5_RSS_HASH_IDX_ESP_SPI;
15950 : 0 : case RX_HASH_SELECTOR_NONE:
15951 : 0 : return MLX5_RSS_HASH_IDX_NONE;
15952 : 0 : default:
15953 : 0 : DRV_LOG(ERR, "invalid hrxq hash fields combination: "
15954 : : "selectors=0x%" PRIx32, selectors);
15955 : 0 : return -EINVAL;
15956 : : }
15957 : : }
15958 : :
15959 : : /**
15960 : : * Set hash RX queue by hash fields (see enum ibv_rx_hash_fields)
15961 : : * and tunnel.
15962 : : *
15963 : : * @param[in, out] action
15964 : : * Shred RSS action holding hash RX queue objects.
15965 : : * @param[in] hash_fields
15966 : : * Defines combination of packet fields to participate in RX hash,
15967 : : * specified as a bitmap of #ibv_rx_hash_fields flags.
15968 : : * @param[in] tunnel
15969 : : * Tunnel type
15970 : : * @param[in] hrxq_idx
15971 : : * Hash RX queue index to set.
15972 : : *
15973 : : * @return
15974 : : * 0 on success, otherwise negative errno value.
15975 : : */
15976 : : static int
15977 : 0 : __flow_dv_action_rss_hrxq_set(struct mlx5_shared_action_rss *action,
15978 : : const uint64_t hash_fields,
15979 : : uint32_t hrxq_idx)
15980 : : {
15981 : 0 : uint32_t *hrxqs = action->hrxq;
15982 : 0 : uint32_t selectors = 0;
15983 : : int ret;
15984 : :
15985 : 0 : ret = rx_hash_calc_selector(hash_fields, &selectors);
15986 : : /*
15987 : : * Hash fields passed to this function are constructed internally.
15988 : : * If this fails, then this is a PMD bug.
15989 : : */
15990 : : MLX5_ASSERT(ret == 0);
15991 : :
15992 : 0 : ret = get_rss_hash_idx(selectors);
15993 : : /*
15994 : : * Based on above assert, selectors should always yield correct index
15995 : : * in mlx5_rss_hash_fields array.
15996 : : * If this fails, then this is a PMD bug.
15997 : : */
15998 : : MLX5_ASSERT(ret >= 0 && ret < MLX5_RSS_HASH_IDX_MAX);
15999 : 0 : hrxqs[ret] = hrxq_idx;
16000 : :
16001 : 0 : return 0;
16002 : : }
16003 : :
16004 : : /**
16005 : : * Look up for hash RX queue by hash fields (see enum ibv_rx_hash_fields)
16006 : : * and tunnel.
16007 : : *
16008 : : * @param[in] dev
16009 : : * Pointer to the Ethernet device structure.
16010 : : * @param[in] idx
16011 : : * Shared RSS action ID holding hash RX queue objects.
16012 : : * @param[in] hash_fields
16013 : : * Defines combination of packet fields to participate in RX hash,
16014 : : * specified as a bitmap of #ibv_rx_hash_fields flags.
16015 : : * @param[in] tunnel
16016 : : * Tunnel type
16017 : : *
16018 : : * @return
16019 : : * Valid hash RX queue index, otherwise 0.
16020 : : */
16021 : : uint32_t
16022 : 0 : flow_dv_action_rss_hrxq_lookup(struct rte_eth_dev *dev, uint32_t idx,
16023 : : const uint64_t hash_fields)
16024 : : {
16025 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16026 : : struct mlx5_shared_action_rss *shared_rss =
16027 : 0 : mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
16028 : 0 : const uint32_t *hrxqs = shared_rss->hrxq;
16029 : 0 : uint32_t selectors = 0;
16030 : : int ret;
16031 : :
16032 : 0 : ret = rx_hash_calc_selector(hash_fields, &selectors);
16033 [ # # ]: 0 : if (ret < 0) {
16034 : 0 : DRV_LOG(ERR, "port %u Rx hash selector calculation failed: "
16035 : : "rss_act_idx=%u hash_fields=0x%" PRIx64 " selectors=0x%" PRIx32,
16036 : : dev->data->port_id, idx, hash_fields, selectors);
16037 : 0 : return 0;
16038 : : }
16039 : :
16040 : 0 : ret = get_rss_hash_idx(selectors);
16041 [ # # ]: 0 : if (ret < 0) {
16042 : 0 : DRV_LOG(ERR, "port %u failed hrxq index lookup: "
16043 : : "rss_act_idx=%u hash_fields=0x%" PRIx64 " selectors=0x%" PRIx32,
16044 : : dev->data->port_id, idx, hash_fields, selectors);
16045 : 0 : return 0;
16046 : : }
16047 : :
16048 : 0 : return hrxqs[ret];
16049 : : }
16050 : :
16051 : : /**
16052 : : * Apply the flow to the NIC, lock free,
16053 : : * (mutex should be acquired by caller).
16054 : : *
16055 : : * @param[in] dev
16056 : : * Pointer to the Ethernet device structure.
16057 : : * @param[in, out] flow
16058 : : * Pointer to flow structure.
16059 : : * @param[out] error
16060 : : * Pointer to error structure.
16061 : : *
16062 : : * @return
16063 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
16064 : : */
16065 : : static int
16066 : 0 : flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
16067 : : struct rte_flow_error *error)
16068 : : {
16069 : : struct mlx5_flow_dv_workspace *dv;
16070 : : struct mlx5_flow_handle *dh;
16071 : : struct mlx5_flow_handle_dv *dv_h;
16072 : : struct mlx5_flow *dev_flow;
16073 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16074 : : uint32_t handle_idx;
16075 : : int n;
16076 : : int err;
16077 : : int idx;
16078 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
16079 : 0 : struct mlx5_flow_rss_desc *rss_desc = &wks->rss_desc;
16080 : : uint8_t misc_mask;
16081 : :
16082 : : MLX5_ASSERT(wks);
16083 [ # # ]: 0 : for (idx = wks->flow_idx - 1; idx >= 0; idx--) {
16084 : 0 : dev_flow = &wks->flows[idx];
16085 : : dv = &dev_flow->dv;
16086 : 0 : dh = dev_flow->handle;
16087 : : dv_h = &dh->dvh;
16088 : 0 : n = dv->actions_n;
16089 [ # # ]: 0 : if (dh->fate_action == MLX5_FLOW_FATE_DROP) {
16090 [ # # ]: 0 : if (dv->transfer) {
16091 : : MLX5_ASSERT(priv->sh->dr_drop_action);
16092 : 0 : dv->actions[n++] = priv->sh->dr_drop_action;
16093 : : } else {
16094 : : #ifdef HAVE_MLX5DV_DR
16095 : : /* DR supports drop action placeholder. */
16096 : : MLX5_ASSERT(priv->sh->dr_drop_action);
16097 : 0 : dv->actions[n++] = dv->group ?
16098 [ # # ]: 0 : priv->sh->dr_drop_action :
16099 : : priv->root_drop_action;
16100 : : #else
16101 : : /* For DV we use the explicit drop queue. */
16102 : : MLX5_ASSERT(priv->drop_queue.hrxq);
16103 : : dv->actions[n++] =
16104 : : priv->drop_queue.hrxq->action;
16105 : : #endif
16106 : : }
16107 [ # # ]: 0 : } else if ((dh->fate_action == MLX5_FLOW_FATE_QUEUE &&
16108 [ # # # # ]: 0 : !dv_h->rix_sample && !dv_h->rix_dest_array)) {
16109 : : struct mlx5_hrxq *hrxq;
16110 : : uint32_t hrxq_idx;
16111 : :
16112 : 0 : hrxq = flow_dv_hrxq_prepare(dev, dev_flow, rss_desc,
16113 : : &hrxq_idx);
16114 [ # # ]: 0 : if (!hrxq) {
16115 : 0 : rte_flow_error_set
16116 : : (error, rte_errno,
16117 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16118 : : "cannot get hash queue");
16119 : 0 : goto error;
16120 : : }
16121 : 0 : dh->rix_hrxq = hrxq_idx;
16122 : 0 : dv->actions[n++] = hrxq->action;
16123 [ # # ]: 0 : } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
16124 : : struct mlx5_hrxq *hrxq = NULL;
16125 : : uint32_t hrxq_idx;
16126 : :
16127 : 0 : hrxq_idx = flow_dv_action_rss_hrxq_lookup(dev,
16128 : : rss_desc->shared_rss,
16129 : : dev_flow->hash_fields);
16130 [ # # ]: 0 : if (hrxq_idx)
16131 : 0 : hrxq = mlx5_ipool_get
16132 : 0 : (priv->sh->ipool[MLX5_IPOOL_HRXQ],
16133 : : hrxq_idx);
16134 [ # # ]: 0 : if (!hrxq) {
16135 : 0 : rte_flow_error_set
16136 : : (error, rte_errno,
16137 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16138 : : "cannot get hash queue");
16139 : 0 : goto error;
16140 : : }
16141 : 0 : dh->rix_srss = rss_desc->shared_rss;
16142 : 0 : dv->actions[n++] = hrxq->action;
16143 [ # # ]: 0 : } else if (dh->fate_action == MLX5_FLOW_FATE_DEFAULT_MISS) {
16144 [ # # ]: 0 : if (!priv->sh->default_miss_action) {
16145 : 0 : rte_flow_error_set
16146 : : (error, rte_errno,
16147 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16148 : : "default miss action not be created.");
16149 : 0 : goto error;
16150 : : }
16151 : 0 : dv->actions[n++] = priv->sh->default_miss_action;
16152 : : }
16153 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(dv_h->matcher->mask.buf);
16154 : : __flow_dv_adjust_buf_size(&dv->value.size, misc_mask);
16155 : 0 : err = mlx5_flow_os_create_flow(dv_h->matcher->matcher_object,
16156 : 0 : (void *)&dv->value, n,
16157 : 0 : dv->actions, &dh->drv_flow);
16158 : : if (err) {
16159 : 0 : rte_flow_error_set
16160 : 0 : (error, errno,
16161 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
16162 : : NULL,
16163 [ # # ]: 0 : (!priv->sh->config.allow_duplicate_pattern &&
16164 [ # # ]: 0 : errno == EEXIST) ?
16165 : : "duplicating pattern is not allowed" :
16166 : : "hardware refuses to create flow");
16167 : 0 : goto error;
16168 : : }
16169 [ # # ]: 0 : if (priv->vmwa_context &&
16170 [ # # # # ]: 0 : dh->vf_vlan.tag && !dh->vf_vlan.created) {
16171 : : /*
16172 : : * The rule contains the VLAN pattern.
16173 : : * For VF we are going to create VLAN
16174 : : * interface to make hypervisor set correct
16175 : : * e-Switch vport context.
16176 : : */
16177 : 0 : mlx5_vlan_vmwa_acquire(dev, &dh->vf_vlan);
16178 : : }
16179 : : }
16180 : : return 0;
16181 : 0 : error:
16182 : 0 : err = rte_errno; /* Save rte_errno before cleanup. */
16183 [ # # # # : 0 : SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
# # ]
16184 : : handle_idx, dh, next) {
16185 : : /* hrxq is union, don't clear it if the flag is not set. */
16186 [ # # # # ]: 0 : if (dh->fate_action == MLX5_FLOW_FATE_QUEUE && dh->rix_hrxq &&
16187 [ # # # # ]: 0 : !dh->dvh.rix_sample && !dh->dvh.rix_dest_array) {
16188 : 0 : mlx5_hrxq_release(dev, dh->rix_hrxq);
16189 : 0 : dh->rix_hrxq = 0;
16190 [ # # ]: 0 : } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
16191 : 0 : dh->rix_srss = 0;
16192 : : }
16193 [ # # # # ]: 0 : if (dh->vf_vlan.tag && dh->vf_vlan.created)
16194 : 0 : mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
16195 : : }
16196 : 0 : rte_errno = err; /* Restore rte_errno. */
16197 : 0 : return -rte_errno;
16198 : : }
16199 : :
16200 : : void
16201 : 0 : flow_matcher_remove_cb(void *tool_ctx __rte_unused,
16202 : : struct mlx5_list_entry *entry)
16203 : : {
16204 : : struct mlx5_flow_dv_matcher *resource = container_of(entry,
16205 : : typeof(*resource),
16206 : : entry);
16207 : : #ifdef HAVE_MLX5_HWS_SUPPORT
16208 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
16209 : :
16210 [ # # ]: 0 : if (sh->config.dv_flow_en == 2)
16211 : 0 : claim_zero(mlx5dr_bwc_matcher_destroy((struct mlx5dr_bwc_matcher *)
16212 : : resource->matcher_object));
16213 : : else
16214 : : #endif
16215 : 0 : claim_zero(mlx5_flow_os_destroy_flow_matcher(resource->matcher_object));
16216 : 0 : mlx5_free(resource);
16217 : 0 : }
16218 : :
16219 : : /**
16220 : : * Release the flow matcher.
16221 : : *
16222 : : * @param dev
16223 : : * Pointer to Ethernet device.
16224 : : * @param port_id
16225 : : * Index to port ID action resource.
16226 : : *
16227 : : * @return
16228 : : * 1 while a reference on it exists, 0 when freed.
16229 : : */
16230 : : static int
16231 : 0 : flow_dv_matcher_release(struct rte_eth_dev *dev,
16232 : : struct mlx5_flow_handle *handle)
16233 : : {
16234 : 0 : struct mlx5_flow_dv_matcher *matcher = handle->dvh.matcher;
16235 : 0 : struct mlx5_flow_tbl_data_entry *tbl = container_of(matcher->tbl,
16236 : : typeof(*tbl), tbl);
16237 : : int ret;
16238 : :
16239 : : MLX5_ASSERT(matcher->matcher_object);
16240 : 0 : ret = mlx5_list_unregister(tbl->matchers, &matcher->entry);
16241 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl->tbl);
16242 : 0 : return ret;
16243 : : }
16244 : :
16245 : : void
16246 : 0 : flow_encap_decap_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
16247 : : {
16248 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
16249 : : struct mlx5_flow_dv_encap_decap_resource *res =
16250 : : container_of(entry, typeof(*res), entry);
16251 : :
16252 : : #ifdef HAVE_MLX5_HWS_SUPPORT
16253 [ # # ]: 0 : if (sh->config.dv_flow_en == 2)
16254 : 0 : claim_zero(mlx5dr_action_destroy(res->action));
16255 : : else
16256 : : #endif
16257 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
16258 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], res->idx);
16259 : 0 : }
16260 : :
16261 : : /**
16262 : : * Release an encap/decap resource.
16263 : : *
16264 : : * @param dev
16265 : : * Pointer to Ethernet device.
16266 : : * @param encap_decap_idx
16267 : : * Index of encap decap resource.
16268 : : *
16269 : : * @return
16270 : : * 1 while a reference on it exists, 0 when freed.
16271 : : */
16272 : : int
16273 : 0 : flow_encap_decap_resource_release(struct rte_eth_dev *dev,
16274 : : uint32_t encap_decap_idx)
16275 : : {
16276 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16277 : : struct mlx5_flow_dv_encap_decap_resource *resource;
16278 : :
16279 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
16280 : : encap_decap_idx);
16281 [ # # ]: 0 : if (!resource)
16282 : : return 0;
16283 : : MLX5_ASSERT(resource->action);
16284 : 0 : return mlx5_hlist_unregister(priv->sh->encaps_decaps, &resource->entry);
16285 : : }
16286 : :
16287 : : /**
16288 : : * Release an jump to table action resource.
16289 : : *
16290 : : * @param dev
16291 : : * Pointer to Ethernet device.
16292 : : * @param rix_jump
16293 : : * Index to the jump action resource.
16294 : : *
16295 : : * @return
16296 : : * 1 while a reference on it exists, 0 when freed.
16297 : : */
16298 : : static int
16299 : 0 : flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev,
16300 : : uint32_t rix_jump)
16301 : : {
16302 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16303 : : struct mlx5_flow_tbl_data_entry *tbl_data;
16304 : :
16305 : 0 : tbl_data = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_JUMP],
16306 : : rix_jump);
16307 [ # # ]: 0 : if (!tbl_data)
16308 : : return 0;
16309 : 0 : return flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl_data->tbl);
16310 : : }
16311 : :
16312 : : void
16313 : 0 : flow_modify_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
16314 : : {
16315 : : struct mlx5_flow_dv_modify_hdr_resource *res =
16316 : : container_of(entry, typeof(*res), entry);
16317 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
16318 : :
16319 : : #ifdef HAVE_MLX5_HWS_SUPPORT
16320 [ # # ]: 0 : if (sh->config.dv_flow_en == 2)
16321 : 0 : claim_zero(mlx5dr_action_destroy(res->action));
16322 : : else
16323 : : #endif
16324 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
16325 : 0 : mlx5_ipool_free(sh->mdh_ipools[res->actions_num - 1], res->idx);
16326 : 0 : }
16327 : :
16328 : : /**
16329 : : * Release a modify-header resource.
16330 : : *
16331 : : * @param dev
16332 : : * Pointer to Ethernet device.
16333 : : * @param handle
16334 : : * Pointer to mlx5_flow_handle.
16335 : : *
16336 : : * @return
16337 : : * 1 while a reference on it exists, 0 when freed.
16338 : : */
16339 : : static int
16340 : : flow_dv_modify_hdr_resource_release(struct rte_eth_dev *dev,
16341 : : struct mlx5_flow_handle *handle)
16342 : : {
16343 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16344 : : struct mlx5_flow_dv_modify_hdr_resource *entry = handle->dvh.modify_hdr;
16345 : :
16346 : : MLX5_ASSERT(entry->action);
16347 : 0 : return mlx5_hlist_unregister(priv->sh->modify_cmds, &entry->entry);
16348 : : }
16349 : :
16350 : : void
16351 : 0 : flow_dv_port_id_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
16352 : : {
16353 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
16354 : : struct mlx5_flow_dv_port_id_action_resource *resource =
16355 : : container_of(entry, typeof(*resource), entry);
16356 : :
16357 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
16358 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], resource->idx);
16359 : 0 : }
16360 : :
16361 : : /**
16362 : : * Release port ID action resource.
16363 : : *
16364 : : * @param dev
16365 : : * Pointer to Ethernet device.
16366 : : * @param handle
16367 : : * Pointer to mlx5_flow_handle.
16368 : : *
16369 : : * @return
16370 : : * 1 while a reference on it exists, 0 when freed.
16371 : : */
16372 : : static int
16373 : 0 : flow_dv_port_id_action_resource_release(struct rte_eth_dev *dev,
16374 : : uint32_t port_id)
16375 : : {
16376 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16377 : : struct mlx5_flow_dv_port_id_action_resource *resource;
16378 : :
16379 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PORT_ID], port_id);
16380 [ # # ]: 0 : if (!resource)
16381 : : return 0;
16382 : : MLX5_ASSERT(resource->action);
16383 : 0 : return mlx5_list_unregister(priv->sh->port_id_action_list,
16384 : : &resource->entry);
16385 : : }
16386 : :
16387 : : /**
16388 : : * Release shared RSS action resource.
16389 : : *
16390 : : * @param dev
16391 : : * Pointer to Ethernet device.
16392 : : * @param srss
16393 : : * Shared RSS action index.
16394 : : */
16395 : : static void
16396 : 0 : flow_dv_shared_rss_action_release(struct rte_eth_dev *dev, uint32_t srss)
16397 : : {
16398 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16399 : : struct mlx5_shared_action_rss *shared_rss;
16400 : :
16401 : 0 : shared_rss = mlx5_ipool_get
16402 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], srss);
16403 : 0 : rte_atomic_fetch_sub_explicit(&shared_rss->refcnt, 1, rte_memory_order_relaxed);
16404 : 0 : }
16405 : :
16406 : : void
16407 : 0 : flow_dv_push_vlan_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
16408 : : {
16409 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
16410 : : struct mlx5_flow_dv_push_vlan_action_resource *resource =
16411 : : container_of(entry, typeof(*resource), entry);
16412 : :
16413 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
16414 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], resource->idx);
16415 : 0 : }
16416 : :
16417 : : /**
16418 : : * Release push vlan action resource.
16419 : : *
16420 : : * @param dev
16421 : : * Pointer to Ethernet device.
16422 : : * @param handle
16423 : : * Pointer to mlx5_flow_handle.
16424 : : *
16425 : : * @return
16426 : : * 1 while a reference on it exists, 0 when freed.
16427 : : */
16428 : : static int
16429 : 0 : flow_dv_push_vlan_action_resource_release(struct rte_eth_dev *dev,
16430 : : struct mlx5_flow_handle *handle)
16431 : : {
16432 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16433 : : struct mlx5_flow_dv_push_vlan_action_resource *resource;
16434 : 0 : uint32_t idx = handle->dvh.rix_push_vlan;
16435 : :
16436 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
16437 [ # # ]: 0 : if (!resource)
16438 : : return 0;
16439 : : MLX5_ASSERT(resource->action);
16440 : 0 : return mlx5_list_unregister(priv->sh->push_vlan_action_list,
16441 : : &resource->entry);
16442 : : }
16443 : :
16444 : : /**
16445 : : * Release the fate resource.
16446 : : *
16447 : : * @param dev
16448 : : * Pointer to Ethernet device.
16449 : : * @param handle
16450 : : * Pointer to mlx5_flow_handle.
16451 : : */
16452 : : static void
16453 : 0 : flow_dv_fate_resource_release(struct rte_eth_dev *dev,
16454 : : struct mlx5_flow_handle *handle)
16455 : : {
16456 [ # # ]: 0 : if (!handle->rix_fate)
16457 : : return;
16458 [ # # # # : 0 : switch (handle->fate_action) {
# ]
16459 : 0 : case MLX5_FLOW_FATE_QUEUE:
16460 [ # # # # ]: 0 : if (!handle->dvh.rix_sample && !handle->dvh.rix_dest_array)
16461 : 0 : mlx5_hrxq_release(dev, handle->rix_hrxq);
16462 : : break;
16463 : 0 : case MLX5_FLOW_FATE_JUMP:
16464 : 0 : flow_dv_jump_tbl_resource_release(dev, handle->rix_jump);
16465 : 0 : break;
16466 : 0 : case MLX5_FLOW_FATE_PORT_ID:
16467 : 0 : flow_dv_port_id_action_resource_release(dev,
16468 : : handle->rix_port_id_action);
16469 : 0 : break;
16470 : : case MLX5_FLOW_FATE_SEND_TO_KERNEL:
16471 : : /* In case of send_to_kernel action the actual release of
16472 : : * resource is done when all shared DR resources are released
16473 : : * since this resource is created once and always reused.
16474 : : */
16475 : : break;
16476 : 0 : default:
16477 : 0 : DRV_LOG(DEBUG, "Incorrect fate action:%d", handle->fate_action);
16478 : 0 : break;
16479 : : }
16480 : 0 : handle->rix_fate = 0;
16481 : : }
16482 : :
16483 : : void
16484 : 0 : flow_dv_sample_remove_cb(void *tool_ctx __rte_unused,
16485 : : struct mlx5_list_entry *entry)
16486 : : {
16487 : : struct mlx5_flow_dv_sample_resource *resource = container_of(entry,
16488 : : typeof(*resource),
16489 : : entry);
16490 : 0 : struct rte_eth_dev *dev = resource->dev;
16491 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16492 : :
16493 [ # # ]: 0 : if (resource->verbs_action)
16494 : : claim_zero(mlx5_flow_os_destroy_flow_action
16495 : : (resource->verbs_action));
16496 [ # # ]: 0 : if (resource->normal_path_tbl)
16497 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev),
16498 : : resource->normal_path_tbl);
16499 : 0 : flow_dv_sample_sub_actions_release(dev, &resource->sample_idx);
16500 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_SAMPLE], resource->idx);
16501 : 0 : DRV_LOG(DEBUG, "sample resource %p: removed", (void *)resource);
16502 : 0 : }
16503 : :
16504 : : /**
16505 : : * Release an sample resource.
16506 : : *
16507 : : * @param dev
16508 : : * Pointer to Ethernet device.
16509 : : * @param handle
16510 : : * Pointer to mlx5_flow_handle.
16511 : : *
16512 : : * @return
16513 : : * 1 while a reference on it exists, 0 when freed.
16514 : : */
16515 : : static int
16516 : 0 : flow_dv_sample_resource_release(struct rte_eth_dev *dev,
16517 : : struct mlx5_flow_handle *handle)
16518 : : {
16519 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16520 : : struct mlx5_flow_dv_sample_resource *resource;
16521 : :
16522 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_SAMPLE],
16523 : : handle->dvh.rix_sample);
16524 [ # # ]: 0 : if (!resource)
16525 : : return 0;
16526 : : MLX5_ASSERT(resource->verbs_action);
16527 : 0 : return mlx5_list_unregister(priv->sh->sample_action_list,
16528 : : &resource->entry);
16529 : : }
16530 : :
16531 : : void
16532 : 0 : flow_dv_dest_array_remove_cb(void *tool_ctx __rte_unused,
16533 : : struct mlx5_list_entry *entry)
16534 : : {
16535 : : struct mlx5_flow_dv_dest_array_resource *resource =
16536 : : container_of(entry, typeof(*resource), entry);
16537 : 0 : struct rte_eth_dev *dev = resource->dev;
16538 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16539 : : uint32_t i = 0;
16540 : :
16541 : : MLX5_ASSERT(resource->action);
16542 [ # # ]: 0 : if (resource->action)
16543 : : claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
16544 [ # # ]: 0 : for (; i < resource->num_of_dest; i++)
16545 : 0 : flow_dv_sample_sub_actions_release(dev,
16546 : : &resource->sample_idx[i]);
16547 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY], resource->idx);
16548 : 0 : DRV_LOG(DEBUG, "destination array resource %p: removed",
16549 : : (void *)resource);
16550 : 0 : }
16551 : :
16552 : : /**
16553 : : * Release an destination array resource.
16554 : : *
16555 : : * @param dev
16556 : : * Pointer to Ethernet device.
16557 : : * @param handle
16558 : : * Pointer to mlx5_flow_handle.
16559 : : *
16560 : : * @return
16561 : : * 1 while a reference on it exists, 0 when freed.
16562 : : */
16563 : : static int
16564 : 0 : flow_dv_dest_array_resource_release(struct rte_eth_dev *dev,
16565 : : struct mlx5_flow_handle *handle)
16566 : : {
16567 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16568 : : struct mlx5_flow_dv_dest_array_resource *resource;
16569 : :
16570 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY],
16571 : : handle->dvh.rix_dest_array);
16572 [ # # ]: 0 : if (!resource)
16573 : : return 0;
16574 : : MLX5_ASSERT(resource->action);
16575 : 0 : return mlx5_list_unregister(priv->sh->dest_array_list,
16576 : : &resource->entry);
16577 : : }
16578 : :
16579 : : static void
16580 : 0 : flow_dev_geneve_tlv_option_resource_release(struct mlx5_dev_ctx_shared *sh)
16581 : : {
16582 : 0 : struct mlx5_geneve_tlv_option_resource *geneve_opt_resource =
16583 : : sh->geneve_tlv_option_resource;
16584 : 0 : rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
16585 [ # # ]: 0 : if (geneve_opt_resource) {
16586 [ # # ]: 0 : if (!(rte_atomic_fetch_sub_explicit(&geneve_opt_resource->refcnt, 1,
16587 : : rte_memory_order_relaxed) - 1)) {
16588 : 0 : claim_zero(mlx5_devx_cmd_destroy
16589 : : (geneve_opt_resource->obj));
16590 : 0 : mlx5_free(sh->geneve_tlv_option_resource);
16591 : 0 : sh->geneve_tlv_option_resource = NULL;
16592 : : }
16593 : : }
16594 : : rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
16595 : 0 : }
16596 : :
16597 : : /**
16598 : : * Remove the flow from the NIC but keeps it in memory.
16599 : : * Lock free, (mutex should be acquired by caller).
16600 : : *
16601 : : * @param[in] dev
16602 : : * Pointer to Ethernet device.
16603 : : * @param[in, out] flow
16604 : : * Pointer to flow structure.
16605 : : */
16606 : : static void
16607 : 0 : flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
16608 : : {
16609 : : struct mlx5_flow_handle *dh;
16610 : : uint32_t handle_idx;
16611 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16612 : :
16613 [ # # ]: 0 : if (!flow)
16614 : : return;
16615 : 0 : handle_idx = flow->dev_handles;
16616 [ # # ]: 0 : while (handle_idx) {
16617 : 0 : dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
16618 : : handle_idx);
16619 [ # # ]: 0 : if (!dh)
16620 : : return;
16621 [ # # ]: 0 : if (dh->drv_flow) {
16622 : : claim_zero(mlx5_flow_os_destroy_flow(dh->drv_flow));
16623 : 0 : dh->drv_flow = NULL;
16624 : : }
16625 [ # # ]: 0 : if (dh->fate_action == MLX5_FLOW_FATE_QUEUE)
16626 : 0 : flow_dv_fate_resource_release(dev, dh);
16627 [ # # # # ]: 0 : if (dh->vf_vlan.tag && dh->vf_vlan.created)
16628 : 0 : mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
16629 : 0 : handle_idx = dh->next.next;
16630 : : }
16631 : : }
16632 : :
16633 : : /**
16634 : : * Remove the flow from the NIC and the memory.
16635 : : * Lock free, (mutex should be acquired by caller).
16636 : : *
16637 : : * @param[in] dev
16638 : : * Pointer to the Ethernet device structure.
16639 : : * @param[in, out] flow
16640 : : * Pointer to flow structure.
16641 : : */
16642 : : static void
16643 : 0 : flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
16644 : : {
16645 : : struct mlx5_flow_handle *dev_handle;
16646 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16647 : : struct mlx5_flow_meter_info *fm = NULL;
16648 : : uint32_t srss = 0;
16649 : :
16650 [ # # ]: 0 : if (!flow)
16651 : : return;
16652 : 0 : flow_dv_remove(dev, flow);
16653 [ # # ]: 0 : if (flow->counter) {
16654 : 0 : flow_dv_counter_free(dev, flow->counter);
16655 : 0 : flow->counter = 0;
16656 : : }
16657 [ # # ]: 0 : if (flow->meter) {
16658 : 0 : fm = flow_dv_meter_find_by_idx(priv, flow->meter);
16659 [ # # ]: 0 : if (fm)
16660 : 0 : mlx5_flow_meter_detach(priv, fm);
16661 : 0 : flow->meter = 0;
16662 : : }
16663 : : /* Keep the current age handling by default. */
16664 [ # # # # ]: 0 : if (flow->indirect_type == MLX5_INDIRECT_ACTION_TYPE_CT && flow->ct)
16665 : 0 : flow_dv_aso_ct_release(dev, flow->ct, NULL);
16666 [ # # ]: 0 : else if (flow->age)
16667 : 0 : flow_dv_aso_age_release(dev, flow->age);
16668 [ # # ]: 0 : while (flow->geneve_tlv_option) {
16669 : 0 : flow_dev_geneve_tlv_option_resource_release(priv->sh);
16670 : 0 : flow->geneve_tlv_option--;
16671 : : }
16672 [ # # ]: 0 : while (flow->dev_handles) {
16673 : : uint32_t tmp_idx = flow->dev_handles;
16674 : :
16675 : 0 : dev_handle = mlx5_ipool_get(priv->sh->ipool
16676 : : [MLX5_IPOOL_MLX5_FLOW], tmp_idx);
16677 [ # # ]: 0 : if (!dev_handle)
16678 : : return;
16679 : 0 : flow->dev_handles = dev_handle->next.next;
16680 [ # # ]: 0 : while (dev_handle->flex_item) {
16681 : 0 : int index = rte_bsf32(dev_handle->flex_item);
16682 : :
16683 : 0 : mlx5_flex_release_index(dev, index);
16684 : 0 : dev_handle->flex_item &= ~(uint8_t)RTE_BIT32(index);
16685 : : }
16686 [ # # ]: 0 : if (dev_handle->dvh.matcher)
16687 : 0 : flow_dv_matcher_release(dev, dev_handle);
16688 [ # # ]: 0 : if (dev_handle->dvh.rix_sample)
16689 : 0 : flow_dv_sample_resource_release(dev, dev_handle);
16690 [ # # ]: 0 : if (dev_handle->dvh.rix_dest_array)
16691 : 0 : flow_dv_dest_array_resource_release(dev, dev_handle);
16692 [ # # ]: 0 : if (dev_handle->dvh.rix_encap_decap)
16693 : 0 : flow_encap_decap_resource_release(dev,
16694 : : dev_handle->dvh.rix_encap_decap);
16695 [ # # ]: 0 : if (dev_handle->dvh.modify_hdr)
16696 : : flow_dv_modify_hdr_resource_release(dev, dev_handle);
16697 [ # # ]: 0 : if (dev_handle->dvh.rix_push_vlan)
16698 : 0 : flow_dv_push_vlan_action_resource_release(dev,
16699 : : dev_handle);
16700 [ # # ]: 0 : if (dev_handle->dvh.rix_tag)
16701 : 0 : flow_dv_tag_release(dev,
16702 : : dev_handle->dvh.rix_tag);
16703 [ # # ]: 0 : if (dev_handle->fate_action != MLX5_FLOW_FATE_SHARED_RSS)
16704 : 0 : flow_dv_fate_resource_release(dev, dev_handle);
16705 [ # # ]: 0 : else if (!srss)
16706 : 0 : srss = dev_handle->rix_srss;
16707 [ # # # # ]: 0 : if (fm && dev_handle->is_meter_flow_id &&
16708 [ # # ]: 0 : dev_handle->split_flow_id)
16709 : 0 : mlx5_ipool_free(fm->flow_ipool,
16710 : : dev_handle->split_flow_id);
16711 [ # # ]: 0 : else if (dev_handle->split_flow_id &&
16712 [ # # ]: 0 : !dev_handle->is_meter_flow_id)
16713 : 0 : mlx5_ipool_free(priv->sh->ipool
16714 : : [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
16715 : : dev_handle->split_flow_id);
16716 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
16717 : : tmp_idx);
16718 : : }
16719 [ # # ]: 0 : if (srss)
16720 : 0 : flow_dv_shared_rss_action_release(dev, srss);
16721 : : }
16722 : :
16723 : : /**
16724 : : * Release array of hash RX queue objects.
16725 : : * Helper function.
16726 : : *
16727 : : * @param[in] dev
16728 : : * Pointer to the Ethernet device structure.
16729 : : * @param[in, out] hrxqs
16730 : : * Array of hash RX queue objects.
16731 : : *
16732 : : * @return
16733 : : * Total number of references to hash RX queue objects in *hrxqs* array
16734 : : * after this operation.
16735 : : */
16736 : : static int
16737 : 0 : __flow_dv_hrxqs_release(struct rte_eth_dev *dev,
16738 : : uint32_t (*hrxqs)[MLX5_RSS_HASH_IDX_MAX])
16739 : : {
16740 : : size_t i;
16741 : : int remaining = 0;
16742 : :
16743 [ # # ]: 0 : for (i = 0; i < RTE_DIM(*hrxqs); i++) {
16744 : 0 : int ret = mlx5_hrxq_release(dev, (*hrxqs)[i]);
16745 : :
16746 [ # # ]: 0 : if (!ret)
16747 : 0 : (*hrxqs)[i] = 0;
16748 : 0 : remaining += ret;
16749 : : }
16750 : 0 : return remaining;
16751 : : }
16752 : :
16753 : : /**
16754 : : * Release all hash RX queue objects representing shared RSS action.
16755 : : *
16756 : : * @param[in] dev
16757 : : * Pointer to the Ethernet device structure.
16758 : : * @param[in, out] action
16759 : : * Shared RSS action to remove hash RX queue objects from.
16760 : : *
16761 : : * @return
16762 : : * Total number of references to hash RX queue objects stored in *action*
16763 : : * after this operation.
16764 : : * Expected to be 0 if no external references held.
16765 : : */
16766 : : static int
16767 : : __flow_dv_action_rss_hrxqs_release(struct rte_eth_dev *dev,
16768 : : struct mlx5_shared_action_rss *shared_rss)
16769 : : {
16770 : 0 : return __flow_dv_hrxqs_release(dev, &shared_rss->hrxq);
16771 : : }
16772 : :
16773 : : static inline void
16774 : : filter_ipv4_types(uint64_t rss_types, uint64_t *hash_fields)
16775 : : {
16776 [ # # ]: 0 : if (rss_types & MLX5_IPV4_LAYER_TYPES) {
16777 : 0 : *hash_fields &= ~MLX5_RSS_HASH_IPV4;
16778 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
16779 : 0 : *hash_fields |= IBV_RX_HASH_DST_IPV4;
16780 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
16781 : 0 : *hash_fields |= IBV_RX_HASH_SRC_IPV4;
16782 : : else
16783 : 0 : *hash_fields |= MLX5_RSS_HASH_IPV4;
16784 : : }
16785 : : }
16786 : :
16787 : : static inline void
16788 : : filter_ipv6_types(uint64_t rss_types, uint64_t *hash_fields)
16789 : : {
16790 [ # # ]: 0 : if (rss_types & MLX5_IPV6_LAYER_TYPES) {
16791 : 0 : *hash_fields &= ~MLX5_RSS_HASH_IPV6;
16792 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
16793 : 0 : *hash_fields |= IBV_RX_HASH_DST_IPV6;
16794 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
16795 : 0 : *hash_fields |= IBV_RX_HASH_SRC_IPV6;
16796 : : else
16797 : 0 : *hash_fields |= MLX5_RSS_HASH_IPV6;
16798 : : }
16799 : : }
16800 : :
16801 : : static inline void
16802 : : filter_udp_types(uint64_t rss_types, uint64_t *hash_fields)
16803 : : {
16804 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_UDP) {
16805 : 0 : *hash_fields &= ~MLX5_UDP_IBV_RX_HASH;
16806 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
16807 : 0 : *hash_fields |= IBV_RX_HASH_DST_PORT_UDP;
16808 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
16809 : 0 : *hash_fields |= IBV_RX_HASH_SRC_PORT_UDP;
16810 : : else
16811 : 0 : *hash_fields |= MLX5_UDP_IBV_RX_HASH;
16812 : : }
16813 : : }
16814 : :
16815 : : static inline void
16816 : : filter_tcp_types(uint64_t rss_types, uint64_t *hash_fields)
16817 : : {
16818 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_TCP) {
16819 : 0 : *hash_fields &= ~MLX5_TCP_IBV_RX_HASH;
16820 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
16821 : 0 : *hash_fields |= IBV_RX_HASH_DST_PORT_TCP;
16822 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
16823 : 0 : *hash_fields |= IBV_RX_HASH_SRC_PORT_TCP;
16824 : : else
16825 : 0 : *hash_fields |= MLX5_TCP_IBV_RX_HASH;
16826 : : }
16827 : : }
16828 : :
16829 : : /**
16830 : : * Adjust L3/L4 hash value of pre-created shared RSS hrxq according to
16831 : : * user input.
16832 : : *
16833 : : * Only one hash value is available for one L3+L4 combination:
16834 : : * for example:
16835 : : * MLX5_RSS_HASH_IPV4, MLX5_RSS_HASH_IPV4_SRC_ONLY, and
16836 : : * MLX5_RSS_HASH_IPV4_DST_ONLY are mutually exclusive so they can share
16837 : : * same slot in mlx5_rss_hash_fields.
16838 : : *
16839 : : * @param[in] orig_rss_types
16840 : : * RSS type as provided in shared RSS action, specified as a bitmap of RTE_ETH_RSS_* flags.
16841 : : * @param[in, out] hash_field
16842 : : * hash_field variable needed to be adjusted, specified as a bitmap of #ibv_rx_hash_fields flags.
16843 : : *
16844 : : * @return
16845 : : * void
16846 : : */
16847 : : void
16848 : 0 : flow_dv_action_rss_l34_hash_adjust(uint64_t orig_rss_types,
16849 : : uint64_t *hash_field)
16850 : : {
16851 [ # # ]: 0 : uint64_t hash_field_protos = *hash_field & ~IBV_RX_HASH_INNER;
16852 : : uint64_t rss_types = rte_eth_rss_hf_refine(orig_rss_types);
16853 : :
16854 [ # # ]: 0 : if (hash_field_protos & MLX5_RSS_HASH_IPV4)
16855 : : filter_ipv4_types(rss_types, hash_field);
16856 [ # # ]: 0 : else if (hash_field_protos & MLX5_RSS_HASH_IPV6)
16857 : : filter_ipv6_types(rss_types, hash_field);
16858 : :
16859 [ # # ]: 0 : if (hash_field_protos & MLX5_UDP_IBV_RX_HASH)
16860 : : filter_udp_types(rss_types, hash_field);
16861 [ # # ]: 0 : else if (hash_field_protos & MLX5_TCP_IBV_RX_HASH)
16862 : : filter_tcp_types(rss_types, hash_field);
16863 : 0 : }
16864 : :
16865 : : /**
16866 : : * Setup shared RSS action.
16867 : : * Prepare set of hash RX queue objects sufficient to handle all valid
16868 : : * hash_fields combinations (see enum ibv_rx_hash_fields).
16869 : : *
16870 : : * @param[in] dev
16871 : : * Pointer to the Ethernet device structure.
16872 : : * @param[in] action_idx
16873 : : * Shared RSS action ipool index.
16874 : : * @param[in, out] action
16875 : : * Partially initialized shared RSS action.
16876 : : * @param[out] error
16877 : : * Perform verbose error reporting if not NULL. Initialized in case of
16878 : : * error only.
16879 : : *
16880 : : * @return
16881 : : * 0 on success, otherwise negative errno value.
16882 : : */
16883 : : static int
16884 : 0 : __flow_dv_action_rss_setup(struct rte_eth_dev *dev,
16885 : : uint32_t action_idx,
16886 : : struct mlx5_shared_action_rss *shared_rss,
16887 : : struct rte_flow_error *error)
16888 : : {
16889 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16890 : 0 : struct mlx5_flow_rss_desc rss_desc = { 0 };
16891 : : size_t i;
16892 : : int err;
16893 : :
16894 : 0 : shared_rss->ind_tbl = mlx5_ind_table_obj_new
16895 : : (dev, shared_rss->origin.queue,
16896 : : shared_rss->origin.queue_num,
16897 : : true,
16898 : 0 : !!dev->data->dev_started);
16899 [ # # ]: 0 : if (!shared_rss->ind_tbl)
16900 : 0 : return rte_flow_error_set(error, rte_errno,
16901 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16902 : : "cannot setup indirection table");
16903 : 0 : memcpy(rss_desc.key, shared_rss->origin.key, MLX5_RSS_HASH_KEY_LEN);
16904 : 0 : rss_desc.key_len = MLX5_RSS_HASH_KEY_LEN;
16905 : 0 : rss_desc.symmetric_hash_function =
16906 : 0 : MLX5_RSS_IS_SYMM(shared_rss->origin.func);
16907 : 0 : rss_desc.const_q = shared_rss->origin.queue;
16908 : 0 : rss_desc.queue_num = shared_rss->origin.queue_num;
16909 : : /* Set non-zero value to indicate a shared RSS. */
16910 : 0 : rss_desc.shared_rss = action_idx;
16911 : 0 : rss_desc.ind_tbl = shared_rss->ind_tbl;
16912 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
16913 : 0 : rss_desc.hws_flags = MLX5DR_ACTION_FLAG_HWS_RX;
16914 [ # # ]: 0 : for (i = 0; i < MLX5_RSS_HASH_IDX_MAX; i++) {
16915 : : struct mlx5_hrxq *hrxq;
16916 : 0 : uint64_t hash_fields = mlx5_rss_hash_fields[i];
16917 : : int tunnel = 0;
16918 : :
16919 : 0 : flow_dv_action_rss_l34_hash_adjust(shared_rss->origin.types,
16920 : : &hash_fields);
16921 [ # # ]: 0 : if (shared_rss->origin.level > 1) {
16922 : 0 : hash_fields |= IBV_RX_HASH_INNER;
16923 : : tunnel = 1;
16924 : : }
16925 : 0 : rss_desc.tunnel = tunnel;
16926 : 0 : rss_desc.hash_fields = hash_fields;
16927 : 0 : hrxq = mlx5_hrxq_get(dev, &rss_desc);
16928 [ # # ]: 0 : if (!hrxq) {
16929 : 0 : rte_flow_error_set
16930 : : (error, rte_errno,
16931 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16932 : : "cannot get hash queue");
16933 : 0 : goto error_hrxq_new;
16934 : : }
16935 : 0 : err = __flow_dv_action_rss_hrxq_set
16936 : : (shared_rss, hash_fields, hrxq->idx);
16937 : : MLX5_ASSERT(!err);
16938 : : }
16939 : : return 0;
16940 : : error_hrxq_new:
16941 : 0 : err = rte_errno;
16942 : : __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
16943 [ # # ]: 0 : if (!mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl, true))
16944 : 0 : shared_rss->ind_tbl = NULL;
16945 : 0 : rte_errno = err;
16946 : 0 : return -rte_errno;
16947 : : }
16948 : :
16949 : : /**
16950 : : * Create shared RSS action.
16951 : : *
16952 : : * @param[in] dev
16953 : : * Pointer to the Ethernet device structure.
16954 : : * @param[in] conf
16955 : : * Shared action configuration.
16956 : : * @param[in] rss
16957 : : * RSS action specification used to create shared action.
16958 : : * @param[out] error
16959 : : * Perform verbose error reporting if not NULL. Initialized in case of
16960 : : * error only.
16961 : : *
16962 : : * @return
16963 : : * A valid shared action ID in case of success, 0 otherwise and
16964 : : * rte_errno is set.
16965 : : */
16966 : : static uint32_t
16967 : 0 : __flow_dv_action_rss_create(struct rte_eth_dev *dev,
16968 : : const struct rte_flow_indir_action_conf *conf,
16969 : : const struct rte_flow_action_rss *rss,
16970 : : struct rte_flow_error *error)
16971 : : {
16972 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16973 : : struct mlx5_shared_action_rss *shared_rss = NULL;
16974 : : struct rte_flow_action_rss *origin;
16975 : : const uint8_t *rss_key;
16976 : : uint32_t idx;
16977 : :
16978 : : RTE_SET_USED(conf);
16979 : 0 : shared_rss = mlx5_ipool_zmalloc
16980 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], &idx);
16981 [ # # ]: 0 : if (!shared_rss) {
16982 : 0 : rte_flow_error_set(error, ENOMEM,
16983 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16984 : : "cannot allocate resource memory");
16985 : 0 : goto error_rss_init;
16986 : : }
16987 [ # # ]: 0 : if (idx > (1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET)) {
16988 : 0 : rte_flow_error_set(error, E2BIG,
16989 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16990 : : "rss action number out of range");
16991 : 0 : goto error_rss_init;
16992 : : }
16993 : : origin = &shared_rss->origin;
16994 : 0 : origin->func = rss->func;
16995 : 0 : origin->level = rss->level;
16996 : : /* RSS type 0 indicates default RSS type (RTE_ETH_RSS_IP). */
16997 [ # # ]: 0 : origin->types = !rss->types ? RTE_ETH_RSS_IP : rss->types;
16998 : : /* NULL RSS key indicates default RSS key. */
16999 [ # # ]: 0 : rss_key = !rss->key ? rss_hash_default_key : rss->key;
17000 : 0 : memcpy(shared_rss->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
17001 : 0 : origin->key = &shared_rss->key[0];
17002 : 0 : origin->key_len = MLX5_RSS_HASH_KEY_LEN;
17003 : 0 : origin->queue = rss->queue;
17004 : 0 : origin->queue_num = rss->queue_num;
17005 [ # # ]: 0 : if (__flow_dv_action_rss_setup(dev, idx, shared_rss, error))
17006 : 0 : goto error_rss_init;
17007 : : /* Update queue with indirect table queue memoyr. */
17008 : 0 : origin->queue = shared_rss->ind_tbl->queues;
17009 : : rte_spinlock_init(&shared_rss->action_rss_sl);
17010 : 0 : rte_atomic_fetch_add_explicit(&shared_rss->refcnt, 1, rte_memory_order_relaxed);
17011 : 0 : rte_spinlock_lock(&priv->shared_act_sl);
17012 [ # # # # ]: 0 : ILIST_INSERT(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
17013 : : &priv->rss_shared_actions, idx, shared_rss, next);
17014 : : rte_spinlock_unlock(&priv->shared_act_sl);
17015 : 0 : return idx;
17016 : 0 : error_rss_init:
17017 [ # # ]: 0 : if (shared_rss) {
17018 [ # # ]: 0 : if (shared_rss->ind_tbl)
17019 : 0 : mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl,
17020 : 0 : !!dev->data->dev_started);
17021 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
17022 : : idx);
17023 : : }
17024 : : return 0;
17025 : : }
17026 : :
17027 : : /**
17028 : : * Destroy the shared RSS action.
17029 : : * Release related hash RX queue objects.
17030 : : *
17031 : : * @param[in] dev
17032 : : * Pointer to the Ethernet device structure.
17033 : : * @param[in] idx
17034 : : * The shared RSS action object ID to be removed.
17035 : : * @param[out] error
17036 : : * Perform verbose error reporting if not NULL. Initialized in case of
17037 : : * error only.
17038 : : *
17039 : : * @return
17040 : : * 0 on success, otherwise negative errno value.
17041 : : */
17042 : : static int
17043 : 0 : __flow_dv_action_rss_release(struct rte_eth_dev *dev, uint32_t idx,
17044 : : struct rte_flow_error *error)
17045 : : {
17046 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17047 : : struct mlx5_shared_action_rss *shared_rss =
17048 : 0 : mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
17049 : : uint32_t old_refcnt = 1;
17050 : : int remaining;
17051 : :
17052 [ # # ]: 0 : if (!shared_rss)
17053 : 0 : return rte_flow_error_set(error, EINVAL,
17054 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
17055 : : "invalid shared action");
17056 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(&shared_rss->refcnt, &old_refcnt,
17057 : : 0, rte_memory_order_acquire,
17058 : : rte_memory_order_relaxed))
17059 : 0 : return rte_flow_error_set(error, EBUSY,
17060 : : RTE_FLOW_ERROR_TYPE_ACTION,
17061 : : NULL,
17062 : : "shared rss has references");
17063 : : remaining = __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
17064 [ # # ]: 0 : if (remaining)
17065 : 0 : return rte_flow_error_set(error, EBUSY,
17066 : : RTE_FLOW_ERROR_TYPE_ACTION,
17067 : : NULL,
17068 : : "shared rss hrxq has references");
17069 : 0 : remaining = mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl,
17070 : 0 : !!dev->data->dev_started);
17071 [ # # ]: 0 : if (remaining)
17072 : 0 : return rte_flow_error_set(error, EBUSY,
17073 : : RTE_FLOW_ERROR_TYPE_ACTION,
17074 : : NULL,
17075 : : "shared rss indirection table has"
17076 : : " references");
17077 : 0 : rte_spinlock_lock(&priv->shared_act_sl);
17078 [ # # # # : 0 : ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
# # # # #
# ]
17079 : : &priv->rss_shared_actions, idx, shared_rss, next);
17080 : : rte_spinlock_unlock(&priv->shared_act_sl);
17081 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
17082 : : idx);
17083 : 0 : return 0;
17084 : : }
17085 : :
17086 : : /**
17087 : : * Create indirect action, lock free,
17088 : : * (mutex should be acquired by caller).
17089 : : * Dispatcher for action type specific call.
17090 : : *
17091 : : * @param[in] dev
17092 : : * Pointer to the Ethernet device structure.
17093 : : * @param[in] conf
17094 : : * Shared action configuration.
17095 : : * @param[in] action
17096 : : * Action specification used to create indirect action.
17097 : : * @param[out] error
17098 : : * Perform verbose error reporting if not NULL. Initialized in case of
17099 : : * error only.
17100 : : *
17101 : : * @return
17102 : : * A valid shared action handle in case of success, NULL otherwise and
17103 : : * rte_errno is set.
17104 : : */
17105 : : struct rte_flow_action_handle *
17106 : 0 : flow_dv_action_create(struct rte_eth_dev *dev,
17107 : : const struct rte_flow_indir_action_conf *conf,
17108 : : const struct rte_flow_action *action,
17109 : : struct rte_flow_error *err)
17110 : : {
17111 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17112 : : uint32_t age_idx = 0;
17113 : : uint32_t idx = 0;
17114 : : uint32_t ret = 0;
17115 : :
17116 [ # # # # : 0 : switch (action->type) {
# ]
17117 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
17118 : 0 : ret = __flow_dv_action_rss_create(dev, conf, action->conf, err);
17119 : : idx = (MLX5_INDIRECT_ACTION_TYPE_RSS <<
17120 : : MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
17121 : 0 : break;
17122 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
17123 : 0 : age_idx = flow_dv_aso_age_alloc(dev, err);
17124 [ # # ]: 0 : if (!age_idx) {
17125 : 0 : ret = -rte_errno;
17126 : 0 : break;
17127 : : }
17128 : 0 : idx = (MLX5_INDIRECT_ACTION_TYPE_AGE <<
17129 : : MLX5_INDIRECT_ACTION_TYPE_OFFSET) | age_idx;
17130 : 0 : flow_dv_aso_age_params_init(dev, age_idx,
17131 : : ((const struct rte_flow_action_age *)
17132 : 0 : action->conf)->context ?
17133 : : ((const struct rte_flow_action_age *)
17134 : : action->conf)->context :
17135 : 0 : (void *)(uintptr_t)idx,
17136 : : ((const struct rte_flow_action_age *)
17137 [ # # ]: 0 : action->conf)->timeout);
17138 : : ret = age_idx;
17139 : 0 : break;
17140 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
17141 : 0 : ret = flow_dv_translate_create_counter(dev, NULL, NULL, NULL);
17142 : 0 : idx = (MLX5_INDIRECT_ACTION_TYPE_COUNT <<
17143 : : MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
17144 : 0 : break;
17145 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
17146 : 0 : ret = flow_dv_translate_create_conntrack(dev, action->conf,
17147 : : err);
17148 [ # # ]: 0 : if (!ret)
17149 : : break;
17150 : 0 : idx = MLX5_INDIRECT_ACT_CT_GEN_IDX(PORT_ID(priv), ret);
17151 : 0 : break;
17152 : 0 : default:
17153 : 0 : rte_flow_error_set(err, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
17154 : : NULL, "action type not supported");
17155 : : break;
17156 : : }
17157 [ # # ]: 0 : return ret ? (struct rte_flow_action_handle *)(uintptr_t)idx : NULL;
17158 : : }
17159 : :
17160 : : /**
17161 : : * Destroy the indirect action.
17162 : : * Release action related resources on the NIC and the memory.
17163 : : * Lock free, (mutex should be acquired by caller).
17164 : : * Dispatcher for action type specific call.
17165 : : *
17166 : : * @param[in] dev
17167 : : * Pointer to the Ethernet device structure.
17168 : : * @param[in] handle
17169 : : * The indirect action object handle to be removed.
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_destroy(struct rte_eth_dev *dev,
17179 : : struct rte_flow_action_handle *handle,
17180 : : struct rte_flow_error *error)
17181 : : {
17182 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
17183 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
17184 : 0 : uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
17185 : : struct mlx5_flow_counter *cnt;
17186 : : uint32_t no_flow_refcnt = 1;
17187 : : int ret;
17188 : :
17189 [ # # # # : 0 : switch (type) {
# ]
17190 : 0 : case MLX5_INDIRECT_ACTION_TYPE_RSS:
17191 : 0 : return __flow_dv_action_rss_release(dev, idx, error);
17192 : : case MLX5_INDIRECT_ACTION_TYPE_COUNT:
17193 : : cnt = flow_dv_counter_get_by_idx(dev, idx, NULL);
17194 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(&cnt->shared_info.refcnt,
17195 : : &no_flow_refcnt, 1,
17196 : : rte_memory_order_acquire,
17197 : : rte_memory_order_relaxed))
17198 : 0 : return rte_flow_error_set(error, EBUSY,
17199 : : RTE_FLOW_ERROR_TYPE_ACTION,
17200 : : NULL,
17201 : : "Indirect count action has references");
17202 : 0 : flow_dv_counter_free(dev, idx);
17203 : 0 : return 0;
17204 : 0 : case MLX5_INDIRECT_ACTION_TYPE_AGE:
17205 : 0 : ret = flow_dv_aso_age_release(dev, idx);
17206 [ # # ]: 0 : if (ret)
17207 : : /*
17208 : : * In this case, the last flow has a reference will
17209 : : * actually release the age action.
17210 : : */
17211 : 0 : DRV_LOG(DEBUG, "Indirect age action %" PRIu32 " was"
17212 : : " released with references %d.", idx, ret);
17213 : : return 0;
17214 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
17215 : 0 : ret = flow_dv_aso_ct_release(dev, idx, error);
17216 [ # # ]: 0 : if (ret < 0)
17217 : : return ret;
17218 [ # # ]: 0 : if (ret > 0)
17219 : 0 : DRV_LOG(DEBUG, "Connection tracking object %u still "
17220 : : "has references %d.", idx, ret);
17221 : : return 0;
17222 : 0 : default:
17223 : 0 : return rte_flow_error_set(error, ENOTSUP,
17224 : : RTE_FLOW_ERROR_TYPE_ACTION,
17225 : : NULL,
17226 : : "action type not supported");
17227 : : }
17228 : : }
17229 : :
17230 : : /**
17231 : : * Updates in place shared RSS action configuration.
17232 : : *
17233 : : * @param[in] dev
17234 : : * Pointer to the Ethernet device structure.
17235 : : * @param[in] idx
17236 : : * The shared RSS action object ID to be updated.
17237 : : * @param[in] action_conf
17238 : : * RSS action specification used to modify *shared_rss*.
17239 : : * @param[out] error
17240 : : * Perform verbose error reporting if not NULL. Initialized in case of
17241 : : * error only.
17242 : : *
17243 : : * @return
17244 : : * 0 on success, otherwise negative errno value.
17245 : : * @note: currently only support update of RSS queues.
17246 : : */
17247 : : static int
17248 : 0 : __flow_dv_action_rss_update(struct rte_eth_dev *dev, uint32_t idx,
17249 : : const struct rte_flow_action_rss *action_conf,
17250 : : struct rte_flow_error *error)
17251 : : {
17252 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17253 : : struct mlx5_shared_action_rss *shared_rss =
17254 : 0 : mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
17255 : : int ret = 0;
17256 : : void *queue = NULL;
17257 : : void *queue_i = NULL;
17258 : 0 : uint32_t queue_size = action_conf->queue_num * sizeof(uint16_t);
17259 : 0 : bool dev_started = !!dev->data->dev_started;
17260 : :
17261 [ # # ]: 0 : if (!shared_rss)
17262 : 0 : return rte_flow_error_set(error, EINVAL,
17263 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
17264 : : "invalid shared action to update");
17265 [ # # ]: 0 : if (priv->obj_ops.ind_table_modify == NULL)
17266 : 0 : return rte_flow_error_set(error, ENOTSUP,
17267 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
17268 : : "cannot modify indirection table");
17269 : 0 : queue = mlx5_malloc(MLX5_MEM_ZERO,
17270 : 0 : RTE_ALIGN_CEIL(queue_size, sizeof(void *)),
17271 : : 0, SOCKET_ID_ANY);
17272 [ # # ]: 0 : if (!queue)
17273 : 0 : return rte_flow_error_set(error, ENOMEM,
17274 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17275 : : NULL,
17276 : : "cannot allocate resource memory");
17277 : 0 : memcpy(queue, action_conf->queue, queue_size);
17278 : : MLX5_ASSERT(shared_rss->ind_tbl);
17279 : 0 : rte_spinlock_lock(&shared_rss->action_rss_sl);
17280 : 0 : queue_i = shared_rss->ind_tbl->queues;
17281 : 0 : ret = mlx5_ind_table_obj_modify(dev, shared_rss->ind_tbl,
17282 : 0 : queue, action_conf->queue_num,
17283 : : true /* standalone */,
17284 : : dev_started /* ref_new_qs */,
17285 : : dev_started /* deref_old_qs */);
17286 [ # # ]: 0 : if (ret) {
17287 : 0 : ret = rte_flow_error_set(error, rte_errno,
17288 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
17289 : : "cannot update indirection table");
17290 : : } else {
17291 : : /* Restore the queue to indirect table internal queue. */
17292 : : memcpy(queue_i, queue, queue_size);
17293 : 0 : shared_rss->ind_tbl->queues = queue_i;
17294 : 0 : shared_rss->origin.queue_num = action_conf->queue_num;
17295 : : }
17296 : 0 : mlx5_free(queue);
17297 : : rte_spinlock_unlock(&shared_rss->action_rss_sl);
17298 : 0 : return ret;
17299 : : }
17300 : :
17301 : : /*
17302 : : * Updates in place conntrack context or direction.
17303 : : * Context update should be synchronized.
17304 : : *
17305 : : * @param[in] dev
17306 : : * Pointer to the Ethernet device structure.
17307 : : * @param[in] idx
17308 : : * The conntrack object ID to be updated.
17309 : : * @param[in] update
17310 : : * Pointer to the structure of information to update.
17311 : : * @param[out] error
17312 : : * Perform verbose error reporting if not NULL. Initialized in case of
17313 : : * error only.
17314 : : *
17315 : : * @return
17316 : : * 0 on success, otherwise negative errno value.
17317 : : */
17318 : : static int
17319 : 0 : __flow_dv_action_ct_update(struct rte_eth_dev *dev, uint32_t idx,
17320 : : const struct rte_flow_modify_conntrack *update,
17321 : : struct rte_flow_error *error)
17322 : : {
17323 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17324 : : struct mlx5_aso_ct_action *ct;
17325 : : const struct rte_flow_action_conntrack *new_prf;
17326 : : int ret = 0;
17327 : 0 : uint16_t owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(idx);
17328 : : uint32_t dev_idx;
17329 : :
17330 [ # # ]: 0 : if (PORT_ID(priv) != owner)
17331 : 0 : return rte_flow_error_set(error, EACCES,
17332 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17333 : : NULL,
17334 : : "CT object owned by another port");
17335 : 0 : dev_idx = MLX5_INDIRECT_ACT_CT_GET_IDX(idx);
17336 : 0 : ct = flow_aso_ct_get_by_dev_idx(dev, dev_idx);
17337 [ # # ]: 0 : if (!ct->refcnt)
17338 : 0 : return rte_flow_error_set(error, ENOMEM,
17339 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17340 : : NULL,
17341 : : "CT object is inactive");
17342 : 0 : new_prf = &update->new_ct;
17343 [ # # ]: 0 : if (update->direction)
17344 : 0 : ct->is_original = !!new_prf->is_original_dir;
17345 [ # # ]: 0 : if (update->state) {
17346 : : /* Only validate the profile when it needs to be updated. */
17347 : 0 : ret = mlx5_validate_action_ct(dev, new_prf, error);
17348 [ # # ]: 0 : if (ret)
17349 : : return ret;
17350 : 0 : ret = mlx5_aso_ct_update_by_wqe(priv->sh, MLX5_HW_INV_QUEUE,
17351 : : ct, new_prf, NULL, true);
17352 [ # # ]: 0 : if (ret)
17353 : 0 : return rte_flow_error_set(error, EIO,
17354 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17355 : : NULL,
17356 : : "Failed to send CT context update WQE");
17357 : : /* Block until ready or a failure, default is asynchronous. */
17358 : 0 : ret = mlx5_aso_ct_available(priv->sh, MLX5_HW_INV_QUEUE, ct);
17359 [ # # ]: 0 : if (ret)
17360 : 0 : rte_flow_error_set(error, rte_errno,
17361 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17362 : : NULL,
17363 : : "Timeout to get the CT update");
17364 : : }
17365 : : return ret;
17366 : : }
17367 : :
17368 : : /**
17369 : : * Updates in place shared action configuration, lock free,
17370 : : * (mutex should be acquired by caller).
17371 : : *
17372 : : * @param[in] dev
17373 : : * Pointer to the Ethernet device structure.
17374 : : * @param[in] handle
17375 : : * The indirect action object handle to be updated.
17376 : : * @param[in] update
17377 : : * Action specification used to modify the action pointed by *handle*.
17378 : : * *update* could be of same type with the action pointed by the *handle*
17379 : : * handle argument, or some other structures like a wrapper, depending on
17380 : : * the indirect action type.
17381 : : * @param[out] error
17382 : : * Perform verbose error reporting if not NULL. Initialized in case of
17383 : : * error only.
17384 : : *
17385 : : * @return
17386 : : * 0 on success, otherwise negative errno value.
17387 : : */
17388 : : int
17389 : 0 : flow_dv_action_update(struct rte_eth_dev *dev,
17390 : : struct rte_flow_action_handle *handle,
17391 : : const void *update,
17392 : : struct rte_flow_error *err)
17393 : : {
17394 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
17395 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
17396 : 0 : uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
17397 : : const void *action_conf;
17398 : :
17399 [ # # # ]: 0 : switch (type) {
17400 : 0 : case MLX5_INDIRECT_ACTION_TYPE_RSS:
17401 : 0 : action_conf = ((const struct rte_flow_action *)update)->conf;
17402 : 0 : return __flow_dv_action_rss_update(dev, idx, action_conf, err);
17403 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
17404 : 0 : return __flow_dv_action_ct_update(dev, idx, update, err);
17405 : 0 : default:
17406 : 0 : return rte_flow_error_set(err, ENOTSUP,
17407 : : RTE_FLOW_ERROR_TYPE_ACTION,
17408 : : NULL,
17409 : : "action type update not supported");
17410 : : }
17411 : : }
17412 : :
17413 : : /**
17414 : : * Destroy the meter sub policy table rules.
17415 : : * Lock free, (mutex should be acquired by caller).
17416 : : *
17417 : : * @param[in] dev
17418 : : * Pointer to Ethernet device.
17419 : : * @param[in] sub_policy
17420 : : * Pointer to meter sub policy table.
17421 : : */
17422 : : static void
17423 : 0 : __flow_dv_destroy_sub_policy_rules(struct rte_eth_dev *dev,
17424 : : struct mlx5_flow_meter_sub_policy *sub_policy)
17425 : : {
17426 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17427 : : struct mlx5_flow_tbl_data_entry *tbl;
17428 : 0 : struct mlx5_flow_meter_policy *policy = sub_policy->main_policy;
17429 : : struct mlx5_flow_meter_info *next_fm;
17430 : : struct mlx5_sub_policy_color_rule *color_rule;
17431 : : void *tmp;
17432 : : uint32_t i;
17433 : :
17434 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
17435 : : next_fm = NULL;
17436 [ # # ]: 0 : if (i <= RTE_COLOR_YELLOW && policy &&
17437 [ # # ]: 0 : policy->act_cnt[i].fate_action == MLX5_FLOW_FATE_MTR)
17438 : 0 : next_fm = mlx5_flow_meter_find(priv,
17439 : : policy->act_cnt[i].next_mtr_id, NULL);
17440 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(color_rule, &sub_policy->color_rules[i],
17441 : : next_port, tmp) {
17442 : 0 : claim_zero(mlx5_flow_os_destroy_flow(color_rule->rule));
17443 : 0 : tbl = container_of(color_rule->matcher->tbl,
17444 : : typeof(*tbl), tbl);
17445 : 0 : mlx5_list_unregister(tbl->matchers,
17446 : : &color_rule->matcher->entry);
17447 [ # # ]: 0 : TAILQ_REMOVE(&sub_policy->color_rules[i],
17448 : : color_rule, next_port);
17449 : 0 : mlx5_free(color_rule);
17450 [ # # ]: 0 : if (next_fm)
17451 : 0 : mlx5_flow_meter_detach(priv, next_fm);
17452 : : }
17453 : : }
17454 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
17455 [ # # ]: 0 : if (sub_policy->rix_hrxq[i]) {
17456 [ # # # # ]: 0 : if (policy && !policy->is_hierarchy)
17457 : 0 : mlx5_hrxq_release(dev, sub_policy->rix_hrxq[i]);
17458 : 0 : sub_policy->rix_hrxq[i] = 0;
17459 : : }
17460 [ # # ]: 0 : if (sub_policy->jump_tbl[i]) {
17461 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev),
17462 : : sub_policy->jump_tbl[i]);
17463 : 0 : sub_policy->jump_tbl[i] = NULL;
17464 : : }
17465 : : }
17466 [ # # ]: 0 : if (sub_policy->tbl_rsc) {
17467 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev),
17468 : : sub_policy->tbl_rsc);
17469 : 0 : sub_policy->tbl_rsc = NULL;
17470 : : }
17471 : 0 : }
17472 : :
17473 : : /**
17474 : : * Destroy policy rules, lock free,
17475 : : * (mutex should be acquired by caller).
17476 : : * Dispatcher for action type specific call.
17477 : : *
17478 : : * @param[in] dev
17479 : : * Pointer to the Ethernet device structure.
17480 : : * @param[in] mtr_policy
17481 : : * Meter policy struct.
17482 : : */
17483 : : static void
17484 : 0 : flow_dv_destroy_policy_rules(struct rte_eth_dev *dev,
17485 : : struct mlx5_flow_meter_policy *mtr_policy)
17486 : : {
17487 : : uint32_t i, j;
17488 : : struct mlx5_flow_meter_sub_policy *sub_policy;
17489 : : uint16_t sub_policy_num;
17490 : :
17491 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
17492 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
17493 : 0 : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
17494 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
17495 [ # # ]: 0 : for (j = 0; j < sub_policy_num; j++) {
17496 : 0 : sub_policy = mtr_policy->sub_policys[i][j];
17497 [ # # ]: 0 : if (sub_policy)
17498 : 0 : __flow_dv_destroy_sub_policy_rules(dev,
17499 : : sub_policy);
17500 : : }
17501 : : }
17502 : 0 : }
17503 : :
17504 : : /**
17505 : : * Destroy policy action, lock free,
17506 : : * (mutex should be acquired by caller).
17507 : : * Dispatcher for action type specific call.
17508 : : *
17509 : : * @param[in] dev
17510 : : * Pointer to the Ethernet device structure.
17511 : : * @param[in] mtr_policy
17512 : : * Meter policy struct.
17513 : : */
17514 : : static void
17515 : 0 : flow_dv_destroy_mtr_policy_acts(struct rte_eth_dev *dev,
17516 : : struct mlx5_flow_meter_policy *mtr_policy)
17517 : : {
17518 : : struct rte_flow_action *rss_action;
17519 : : struct mlx5_flow_handle dev_handle;
17520 : : uint32_t i, j;
17521 : :
17522 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
17523 [ # # ]: 0 : if (mtr_policy->act_cnt[i].rix_mark) {
17524 : 0 : flow_dv_tag_release(dev,
17525 : : mtr_policy->act_cnt[i].rix_mark);
17526 : 0 : mtr_policy->act_cnt[i].rix_mark = 0;
17527 : : }
17528 [ # # ]: 0 : if (mtr_policy->act_cnt[i].modify_hdr) {
17529 : : dev_handle.dvh.modify_hdr =
17530 : : mtr_policy->act_cnt[i].modify_hdr;
17531 : : flow_dv_modify_hdr_resource_release(dev, &dev_handle);
17532 : : }
17533 [ # # # # ]: 0 : switch (mtr_policy->act_cnt[i].fate_action) {
17534 : 0 : case MLX5_FLOW_FATE_SHARED_RSS:
17535 : 0 : rss_action = mtr_policy->act_cnt[i].rss;
17536 : 0 : mlx5_free(rss_action);
17537 : 0 : break;
17538 : 0 : case MLX5_FLOW_FATE_PORT_ID:
17539 [ # # ]: 0 : if (mtr_policy->act_cnt[i].rix_port_id_action) {
17540 : 0 : flow_dv_port_id_action_resource_release(dev,
17541 : : mtr_policy->act_cnt[i].rix_port_id_action);
17542 : 0 : mtr_policy->act_cnt[i].rix_port_id_action = 0;
17543 : : }
17544 : : break;
17545 : : case MLX5_FLOW_FATE_DROP:
17546 : : case MLX5_FLOW_FATE_JUMP:
17547 [ # # ]: 0 : for (j = 0; j < MLX5_MTR_DOMAIN_MAX; j++)
17548 : 0 : mtr_policy->act_cnt[i].dr_jump_action[j] =
17549 : : NULL;
17550 : : break;
17551 : : default:
17552 : : /*Queue action do nothing*/
17553 : : break;
17554 : : }
17555 : : }
17556 [ # # ]: 0 : for (j = 0; j < MLX5_MTR_DOMAIN_MAX; j++)
17557 : 0 : mtr_policy->dr_drop_action[j] = NULL;
17558 : 0 : }
17559 : :
17560 : : /**
17561 : : * Create yellow action for color aware meter.
17562 : : *
17563 : : * @param[in] dev
17564 : : * Pointer to the Ethernet device structure.
17565 : : * @param[in] fm
17566 : : * Meter information table.
17567 : : * @param[out] error
17568 : : * Perform verbose error reporting if not NULL. Initialized in case of
17569 : : * error only.
17570 : : *
17571 : : * @return
17572 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
17573 : : */
17574 : : static int
17575 : 0 : __flow_dv_create_mtr_yellow_action(struct rte_eth_dev *dev,
17576 : : struct mlx5_flow_meter_info *fm,
17577 : : struct rte_mtr_error *error)
17578 : : {
17579 : : #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
17580 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17581 : : struct rte_flow_error flow_err;
17582 : : struct mlx5_aso_mtr *aso_mtr;
17583 : : struct mlx5_aso_mtr_pool *pool;
17584 : : uint8_t reg_id;
17585 : :
17586 : 0 : aso_mtr = container_of(fm, struct mlx5_aso_mtr, fm);
17587 : 0 : pool = container_of(aso_mtr, struct mlx5_aso_mtr_pool, mtrs[aso_mtr->offset]);
17588 : 0 : reg_id = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &flow_err);
17589 : 0 : fm->meter_action_y =
17590 : 0 : mlx5_glue->dv_create_flow_action_aso(priv->sh->rx_domain,
17591 : 0 : pool->devx_obj->obj,
17592 : : aso_mtr->offset,
17593 : : (1 << MLX5_FLOW_COLOR_YELLOW),
17594 : 0 : reg_id - REG_C_0);
17595 : : #else
17596 : : RTE_SET_USED(dev);
17597 : : #endif
17598 [ # # ]: 0 : if (!fm->meter_action_y) {
17599 : 0 : return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
17600 : : "Fail to create yellow meter action.");
17601 : : }
17602 : : return 0;
17603 : : }
17604 : :
17605 : : /**
17606 : : * Create policy action per domain, lock free,
17607 : : * (mutex should be acquired by caller).
17608 : : * Dispatcher for action type specific call.
17609 : : *
17610 : : * @param[in] dev
17611 : : * Pointer to the Ethernet device structure.
17612 : : * @param[in] mtr_policy
17613 : : * Meter policy struct.
17614 : : * @param[in] action
17615 : : * Action specification used to create meter actions.
17616 : : * @param[in] attr
17617 : : * Pointer to the flow attributes.
17618 : : * @param[out] error
17619 : : * Perform verbose error reporting if not NULL. Initialized in case of
17620 : : * error only.
17621 : : *
17622 : : * @return
17623 : : * 0 on success, otherwise negative errno value.
17624 : : */
17625 : : static int
17626 : 0 : __flow_dv_create_domain_policy_acts(struct rte_eth_dev *dev,
17627 : : struct mlx5_flow_meter_policy *mtr_policy,
17628 : : const struct rte_flow_action *actions[RTE_COLORS],
17629 : : struct rte_flow_attr *attr,
17630 : : enum mlx5_meter_domain domain,
17631 : : struct rte_mtr_error *error)
17632 : : {
17633 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17634 : : struct rte_flow_error flow_err;
17635 : : const struct rte_flow_action *act;
17636 : : uint64_t action_flags;
17637 : : struct mlx5_flow_handle dh;
17638 : : struct mlx5_flow dev_flow;
17639 : : struct mlx5_flow_dv_port_id_action_resource port_id_action;
17640 : : int i, ret;
17641 : : uint8_t egress, transfer;
17642 : : struct mlx5_meter_policy_action_container *act_cnt = NULL;
17643 : : union {
17644 : : struct mlx5_flow_dv_modify_hdr_resource res;
17645 : : uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
17646 : : sizeof(struct mlx5_modification_cmd) *
17647 : : (MLX5_MAX_MODIFY_NUM + 1)];
17648 : : } mhdr_dummy;
17649 : : struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
17650 : :
17651 : 0 : egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
17652 [ # # ]: 0 : transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
17653 : : memset(&dh, 0, sizeof(struct mlx5_flow_handle));
17654 : : memset(&dev_flow, 0, sizeof(struct mlx5_flow));
17655 : : memset(&port_id_action, 0,
17656 : : sizeof(struct mlx5_flow_dv_port_id_action_resource));
17657 : : memset(mhdr_res, 0, sizeof(*mhdr_res));
17658 [ # # ]: 0 : mhdr_res->ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
17659 : : (egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
17660 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX);
17661 : 0 : dev_flow.handle = &dh;
17662 : 0 : dev_flow.dv.port_id_action = &port_id_action;
17663 : 0 : dev_flow.external = true;
17664 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
17665 [ # # ]: 0 : if (i < MLX5_MTR_RTE_COLORS)
17666 : 0 : act_cnt = &mtr_policy->act_cnt[i];
17667 : : /* Skip the color policy actions creation. */
17668 [ # # # # : 0 : if ((i == RTE_COLOR_YELLOW && mtr_policy->skip_y) ||
# # ]
17669 [ # # ]: 0 : (i == RTE_COLOR_GREEN && mtr_policy->skip_g))
17670 : 0 : continue;
17671 : : action_flags = 0;
17672 : 0 : for (act = actions[i];
17673 [ # # # # ]: 0 : act && act->type != RTE_FLOW_ACTION_TYPE_END; act++) {
17674 [ # # # # : 0 : switch (act->type) {
# # # # #
# ]
17675 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
17676 : : {
17677 : : uint32_t tag_be = mlx5_flow_mark_set
17678 : : (((const struct rte_flow_action_mark *)
17679 [ # # ]: 0 : (act->conf))->id);
17680 : :
17681 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17682 : 0 : return -rte_mtr_error_set(error,
17683 : : ENOTSUP,
17684 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17685 : : NULL,
17686 : : "cannot create policy "
17687 : : "mark action for this color");
17688 [ # # ]: 0 : if (flow_dv_tag_resource_register(dev, tag_be,
17689 : : &dev_flow, &flow_err))
17690 : 0 : return -rte_mtr_error_set(error,
17691 : : ENOTSUP,
17692 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17693 : : NULL,
17694 : : "cannot setup policy mark action");
17695 : : MLX5_ASSERT(dev_flow.dv.tag_resource);
17696 : 0 : act_cnt->rix_mark =
17697 : 0 : dev_flow.handle->dvh.rix_tag;
17698 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK;
17699 : 0 : mtr_policy->mark = 1;
17700 : 0 : break;
17701 : : }
17702 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TAG:
17703 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17704 : 0 : return -rte_mtr_error_set(error,
17705 : : ENOTSUP,
17706 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17707 : : NULL,
17708 : : "cannot create policy "
17709 : : "set tag action for this color");
17710 [ # # ]: 0 : if (flow_dv_convert_action_set_tag
17711 : : (dev, mhdr_res,
17712 : : (const struct rte_flow_action_set_tag *)
17713 : 0 : act->conf, &flow_err))
17714 : 0 : return -rte_mtr_error_set(error,
17715 : : ENOTSUP,
17716 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17717 : : NULL, "cannot convert policy "
17718 : : "set tag action");
17719 [ # # ]: 0 : if (!mhdr_res->actions_num)
17720 : 0 : return -rte_mtr_error_set(error,
17721 : : ENOTSUP,
17722 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17723 : : NULL, "cannot find policy "
17724 : : "set tag action");
17725 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
17726 : 0 : break;
17727 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
17728 : : {
17729 : 0 : struct mlx5_flow_mtr_mng *mtrmng =
17730 : 0 : priv->sh->mtrmng;
17731 : : struct mlx5_flow_tbl_data_entry *tbl_data;
17732 : :
17733 : : /*
17734 : : * Create the drop table with
17735 : : * METER DROP level.
17736 : : */
17737 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
17738 : 0 : mtrmng->drop_tbl[domain] =
17739 : 0 : flow_dv_tbl_resource_get(dev,
17740 : : MLX5_FLOW_TABLE_LEVEL_METER,
17741 : : egress, transfer, false, NULL, 0,
17742 : : 0, MLX5_MTR_TABLE_ID_DROP, &flow_err);
17743 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain])
17744 : 0 : return -rte_mtr_error_set
17745 : : (error, ENOTSUP,
17746 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17747 : : NULL,
17748 : : "Failed to create meter drop table");
17749 : : }
17750 : 0 : tbl_data = container_of
17751 : : (mtrmng->drop_tbl[domain],
17752 : : struct mlx5_flow_tbl_data_entry, tbl);
17753 [ # # ]: 0 : if (i < MLX5_MTR_RTE_COLORS) {
17754 : 0 : act_cnt->dr_jump_action[domain] =
17755 : 0 : tbl_data->jump.action;
17756 : 0 : act_cnt->fate_action =
17757 : : MLX5_FLOW_FATE_DROP;
17758 : : }
17759 [ # # ]: 0 : if (i == RTE_COLOR_RED)
17760 : 0 : mtr_policy->dr_drop_action[domain] =
17761 : 0 : tbl_data->jump.action;
17762 : 0 : action_flags |= MLX5_FLOW_ACTION_DROP;
17763 : 0 : break;
17764 : : }
17765 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
17766 : : {
17767 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17768 : 0 : return -rte_mtr_error_set(error,
17769 : : ENOTSUP,
17770 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17771 : : NULL, "cannot create policy "
17772 : : "fate queue for this color");
17773 : 0 : act_cnt->queue =
17774 : : ((const struct rte_flow_action_queue *)
17775 : 0 : (act->conf))->index;
17776 : 0 : act_cnt->fate_action =
17777 : : MLX5_FLOW_FATE_QUEUE;
17778 : 0 : dev_flow.handle->fate_action =
17779 : : MLX5_FLOW_FATE_QUEUE;
17780 : 0 : mtr_policy->is_queue = 1;
17781 : 0 : action_flags |= MLX5_FLOW_ACTION_QUEUE;
17782 : 0 : break;
17783 : : }
17784 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
17785 : : {
17786 : : int rss_size;
17787 : :
17788 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17789 : 0 : return -rte_mtr_error_set(error,
17790 : : ENOTSUP,
17791 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17792 : : NULL,
17793 : : "cannot create policy "
17794 : : "rss action for this color");
17795 : : /*
17796 : : * Save RSS conf into policy struct
17797 : : * for translate stage.
17798 : : */
17799 : 0 : rss_size = (int)rte_flow_conv
17800 : : (RTE_FLOW_CONV_OP_ACTION,
17801 : : NULL, 0, act, &flow_err);
17802 [ # # ]: 0 : if (rss_size <= 0)
17803 : 0 : return -rte_mtr_error_set(error,
17804 : : ENOTSUP,
17805 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17806 : : NULL, "Get the wrong "
17807 : : "rss action struct size");
17808 : 0 : act_cnt->rss = mlx5_malloc(MLX5_MEM_ZERO,
17809 : : rss_size, 0, SOCKET_ID_ANY);
17810 [ # # ]: 0 : if (!act_cnt->rss)
17811 : 0 : return -rte_mtr_error_set(error,
17812 : : ENOTSUP,
17813 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17814 : : NULL,
17815 : : "Fail to malloc rss action memory");
17816 : 0 : ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTION,
17817 : : act_cnt->rss, rss_size,
17818 : : act, &flow_err);
17819 [ # # ]: 0 : if (ret < 0)
17820 : 0 : return -rte_mtr_error_set(error,
17821 : : ENOTSUP,
17822 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17823 : : NULL, "Fail to save "
17824 : : "rss action into policy struct");
17825 : 0 : act_cnt->fate_action =
17826 : : MLX5_FLOW_FATE_SHARED_RSS;
17827 : 0 : action_flags |= MLX5_FLOW_ACTION_RSS;
17828 : 0 : break;
17829 : : }
17830 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
17831 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
17832 : : {
17833 : : struct mlx5_flow_dv_port_id_action_resource
17834 : : port_id_resource;
17835 : 0 : uint32_t port_id = 0;
17836 : :
17837 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17838 : 0 : return -rte_mtr_error_set(error,
17839 : : ENOTSUP,
17840 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17841 : : NULL, "cannot create policy "
17842 : : "port action for this color");
17843 : : memset(&port_id_resource, 0,
17844 : : sizeof(port_id_resource));
17845 [ # # ]: 0 : if (flow_dv_translate_action_port_id(dev, act,
17846 : : &port_id, &flow_err))
17847 : 0 : return -rte_mtr_error_set(error,
17848 : : ENOTSUP,
17849 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17850 : : NULL, "cannot translate "
17851 : : "policy port action");
17852 : 0 : port_id_resource.port_id = port_id;
17853 [ # # ]: 0 : if (flow_dv_port_id_action_resource_register
17854 : : (dev, &port_id_resource,
17855 : : &dev_flow, &flow_err))
17856 : 0 : return -rte_mtr_error_set(error,
17857 : : ENOTSUP,
17858 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17859 : : NULL, "cannot setup "
17860 : : "policy port action");
17861 : 0 : act_cnt->rix_port_id_action =
17862 : 0 : dev_flow.handle->rix_port_id_action;
17863 : 0 : act_cnt->fate_action =
17864 : : MLX5_FLOW_FATE_PORT_ID;
17865 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_ID;
17866 : 0 : break;
17867 : : }
17868 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
17869 : : {
17870 : : uint32_t jump_group = 0;
17871 : 0 : uint32_t table = 0;
17872 : : struct mlx5_flow_tbl_data_entry *tbl_data;
17873 : 0 : struct flow_grp_info grp_info = {
17874 : 0 : .external = !!dev_flow.external,
17875 : : .transfer = !!transfer,
17876 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
17877 : : .std_tbl_fix = 0,
17878 : 0 : .skip_scale = dev_flow.skip_scale &
17879 : : (1 << MLX5_SCALE_FLOW_GROUP_BIT),
17880 : : };
17881 : 0 : struct mlx5_flow_meter_sub_policy *sub_policy =
17882 : 0 : mtr_policy->sub_policys[domain][0];
17883 : :
17884 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17885 : 0 : return -rte_mtr_error_set(error,
17886 : : ENOTSUP,
17887 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17888 : : NULL,
17889 : : "cannot create policy "
17890 : : "jump action for this color");
17891 : 0 : jump_group =
17892 : : ((const struct rte_flow_action_jump *)
17893 : 0 : act->conf)->group;
17894 [ # # ]: 0 : if (mlx5_flow_group_to_table(dev, NULL,
17895 : : jump_group,
17896 : : &table,
17897 : : &grp_info, &flow_err))
17898 : 0 : return -rte_mtr_error_set(error,
17899 : : ENOTSUP,
17900 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17901 : : NULL, "cannot setup "
17902 : : "policy jump action");
17903 : 0 : sub_policy->jump_tbl[i] =
17904 : 0 : flow_dv_tbl_resource_get(dev,
17905 : : table, egress,
17906 : : transfer,
17907 : : !!dev_flow.external,
17908 : : NULL, jump_group, 0,
17909 : : 0, &flow_err);
17910 : : if
17911 [ # # ]: 0 : (!sub_policy->jump_tbl[i])
17912 : 0 : return -rte_mtr_error_set(error,
17913 : : ENOTSUP,
17914 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17915 : : NULL, "cannot create jump action.");
17916 : 0 : tbl_data = container_of
17917 : : (sub_policy->jump_tbl[i],
17918 : : struct mlx5_flow_tbl_data_entry, tbl);
17919 : 0 : act_cnt->dr_jump_action[domain] =
17920 : 0 : tbl_data->jump.action;
17921 : 0 : act_cnt->fate_action =
17922 : : MLX5_FLOW_FATE_JUMP;
17923 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP;
17924 : 0 : break;
17925 : : }
17926 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
17927 : : {
17928 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17929 : 0 : return -rte_mtr_error_set(error,
17930 : : ENOTSUP,
17931 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17932 : : NULL,
17933 : : "cannot create policy modify field for this color");
17934 [ # # ]: 0 : if (flow_dv_convert_action_modify_field
17935 : : (dev, mhdr_res, act, attr, &flow_err))
17936 : 0 : return -rte_mtr_error_set(error,
17937 : : ENOTSUP,
17938 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17939 : : NULL, "cannot setup policy modify field action");
17940 [ # # ]: 0 : if (!mhdr_res->actions_num)
17941 : 0 : return -rte_mtr_error_set(error,
17942 : : ENOTSUP,
17943 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17944 : : NULL, "cannot find policy modify field action");
17945 : 0 : action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
17946 : 0 : break;
17947 : : }
17948 : : /*
17949 : : * No need to check meter hierarchy for R colors
17950 : : * here since it is done in the validation stage.
17951 : : */
17952 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
17953 : : {
17954 : : const struct rte_flow_action_meter *mtr;
17955 : : struct mlx5_flow_meter_info *next_fm;
17956 : : struct mlx5_flow_meter_policy *next_policy;
17957 : : struct rte_flow_action tag_action;
17958 : : struct mlx5_rte_flow_action_set_tag set_tag;
17959 : 0 : uint32_t next_mtr_idx = 0;
17960 : :
17961 : 0 : mtr = act->conf;
17962 : 0 : next_fm = mlx5_flow_meter_find(priv,
17963 : 0 : mtr->mtr_id,
17964 : : &next_mtr_idx);
17965 [ # # ]: 0 : if (!next_fm)
17966 : 0 : return -rte_mtr_error_set(error, EINVAL,
17967 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
17968 : : "Fail to find next meter.");
17969 [ # # ]: 0 : if (next_fm->def_policy)
17970 : 0 : return -rte_mtr_error_set(error, EINVAL,
17971 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
17972 : : "Hierarchy only supports termination meter.");
17973 : 0 : next_policy = mlx5_flow_meter_policy_find(dev,
17974 : : next_fm->policy_id, NULL);
17975 : : MLX5_ASSERT(next_policy);
17976 [ # # ]: 0 : if (next_fm->drop_cnt) {
17977 : 0 : set_tag.id =
17978 : 0 : (enum modify_reg)
17979 : 0 : mlx5_flow_get_reg_id(dev,
17980 : : MLX5_MTR_ID,
17981 : : 0,
17982 : : (struct rte_flow_error *)error);
17983 : 0 : set_tag.offset = (priv->mtr_reg_share ?
17984 : 0 : MLX5_MTR_COLOR_BITS : 0);
17985 [ # # ]: 0 : set_tag.length = (priv->mtr_reg_share ?
17986 : : MLX5_MTR_IDLE_BITS_IN_COLOR_REG :
17987 : : MLX5_REG_BITS);
17988 : 0 : set_tag.data = next_mtr_idx;
17989 : 0 : tag_action.type =
17990 : : (enum rte_flow_action_type)
17991 : : MLX5_RTE_FLOW_ACTION_TYPE_TAG;
17992 : 0 : tag_action.conf = &set_tag;
17993 [ # # ]: 0 : if (flow_dv_convert_action_set_reg
17994 : : (mhdr_res, &tag_action,
17995 : : (struct rte_flow_error *)error))
17996 : 0 : return -rte_errno;
17997 : 0 : action_flags |=
17998 : : MLX5_FLOW_ACTION_SET_TAG;
17999 : : }
18000 [ # # # # ]: 0 : if (i == RTE_COLOR_YELLOW && next_fm->color_aware &&
18001 [ # # ]: 0 : !next_fm->meter_action_y)
18002 [ # # ]: 0 : if (__flow_dv_create_mtr_yellow_action(dev, next_fm, error))
18003 : 0 : return -rte_errno;
18004 : 0 : act_cnt->fate_action = MLX5_FLOW_FATE_MTR;
18005 : 0 : act_cnt->next_mtr_id = next_fm->meter_id;
18006 : 0 : act_cnt->next_sub_policy = NULL;
18007 : 0 : mtr_policy->is_hierarchy = 1;
18008 [ # # ]: 0 : if (next_policy->mark)
18009 : 0 : mtr_policy->mark = 1;
18010 : 0 : mtr_policy->hierarchy_match_port =
18011 : 0 : next_policy->hierarchy_match_port;
18012 : 0 : action_flags |=
18013 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
18014 : 0 : break;
18015 : : }
18016 : : default:
18017 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
18018 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
18019 : : NULL, "action type not supported");
18020 : : }
18021 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_SET_TAG) ||
18022 : : (action_flags & MLX5_FLOW_ACTION_MODIFY_FIELD)) {
18023 : : /* create modify action if needed. */
18024 : 0 : dev_flow.dv.group = 1;
18025 [ # # ]: 0 : if (flow_dv_modify_hdr_resource_register
18026 : : (dev, mhdr_res, &dev_flow, &flow_err))
18027 : 0 : return -rte_mtr_error_set(error,
18028 : : ENOTSUP,
18029 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
18030 : : NULL, "cannot register policy set tag/modify field action");
18031 : 0 : act_cnt->modify_hdr =
18032 : 0 : dev_flow.handle->dvh.modify_hdr;
18033 : : }
18034 : : }
18035 : : }
18036 : : return 0;
18037 : : }
18038 : :
18039 : : /**
18040 : : * Create policy action per domain, lock free,
18041 : : * (mutex should be acquired by caller).
18042 : : * Dispatcher for action type specific call.
18043 : : *
18044 : : * @param[in] dev
18045 : : * Pointer to the Ethernet device structure.
18046 : : * @param[in] mtr_policy
18047 : : * Meter policy struct.
18048 : : * @param[in] action
18049 : : * Action specification used to create meter actions.
18050 : : * @param[in] attr
18051 : : * Pointer to the flow attributes.
18052 : : * @param[out] error
18053 : : * Perform verbose error reporting if not NULL. Initialized in case of
18054 : : * error only.
18055 : : *
18056 : : * @return
18057 : : * 0 on success, otherwise negative errno value.
18058 : : */
18059 : : static int
18060 : 0 : flow_dv_create_mtr_policy_acts(struct rte_eth_dev *dev,
18061 : : struct mlx5_flow_meter_policy *mtr_policy,
18062 : : const struct rte_flow_action *actions[RTE_COLORS],
18063 : : struct rte_flow_attr *attr,
18064 : : struct rte_mtr_error *error)
18065 : : {
18066 : : int ret, i;
18067 : : uint16_t sub_policy_num;
18068 : :
18069 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
18070 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
18071 : 0 : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
18072 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
18073 [ # # ]: 0 : if (sub_policy_num) {
18074 : 0 : ret = __flow_dv_create_domain_policy_acts(dev,
18075 : : mtr_policy, actions, attr,
18076 : : (enum mlx5_meter_domain)i, error);
18077 : : /* Cleaning resource is done in the caller level. */
18078 [ # # ]: 0 : if (ret)
18079 : 0 : return ret;
18080 : : }
18081 : : }
18082 : : return 0;
18083 : : }
18084 : :
18085 : : /**
18086 : : * Query a DV flow rule for its statistics via DevX.
18087 : : *
18088 : : * @param[in] dev
18089 : : * Pointer to Ethernet device.
18090 : : * @param[in] cnt_idx
18091 : : * Index to the flow counter.
18092 : : * @param[out] data
18093 : : * Data retrieved by the query.
18094 : : * @param[out] error
18095 : : * Perform verbose error reporting if not NULL.
18096 : : *
18097 : : * @return
18098 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
18099 : : */
18100 : : static int
18101 : 0 : flow_dv_query_count(struct rte_eth_dev *dev, uint32_t cnt_idx, void *data,
18102 : : struct rte_flow_error *error)
18103 : : {
18104 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18105 : : struct rte_flow_query_count *qc = data;
18106 : :
18107 [ # # ]: 0 : if (!priv->sh->cdev->config.devx)
18108 : 0 : return rte_flow_error_set(error, ENOTSUP,
18109 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18110 : : NULL,
18111 : : "counters are not supported");
18112 [ # # ]: 0 : if (cnt_idx) {
18113 : : uint64_t pkts, bytes;
18114 : : struct mlx5_flow_counter *cnt;
18115 : 0 : int err = _flow_dv_query_count(dev, cnt_idx, &pkts, &bytes);
18116 : :
18117 [ # # ]: 0 : if (err)
18118 : 0 : return rte_flow_error_set(error, -err,
18119 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18120 : : NULL, "cannot read counters");
18121 : : cnt = flow_dv_counter_get_by_idx(dev, cnt_idx, NULL);
18122 : 0 : qc->hits_set = 1;
18123 : 0 : qc->bytes_set = 1;
18124 : 0 : qc->hits = pkts - cnt->hits;
18125 : 0 : qc->bytes = bytes - cnt->bytes;
18126 [ # # ]: 0 : if (qc->reset) {
18127 : 0 : cnt->hits = pkts;
18128 : 0 : cnt->bytes = bytes;
18129 : : }
18130 : 0 : return 0;
18131 : : }
18132 : 0 : return rte_flow_error_set(error, EINVAL,
18133 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18134 : : NULL,
18135 : : "counters are not available");
18136 : : }
18137 : :
18138 : : int
18139 : 0 : flow_dv_action_query(struct rte_eth_dev *dev,
18140 : : const struct rte_flow_action_handle *handle, void *data,
18141 : : struct rte_flow_error *error)
18142 : : {
18143 : : struct mlx5_age_param *age_param;
18144 : : struct rte_flow_query_age *resp;
18145 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
18146 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
18147 : 0 : uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
18148 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18149 : : struct mlx5_aso_ct_action *ct;
18150 : : uint16_t owner;
18151 : : uint32_t dev_idx;
18152 : :
18153 [ # # # # ]: 0 : switch (type) {
18154 : 0 : case MLX5_INDIRECT_ACTION_TYPE_AGE:
18155 : 0 : age_param = &flow_aso_age_get_by_idx(dev, idx)->age_params;
18156 : : resp = data;
18157 : 0 : resp->aged = rte_atomic_load_explicit(&age_param->state,
18158 : : rte_memory_order_relaxed) == AGE_TMOUT ?
18159 : 0 : 1 : 0;
18160 : 0 : resp->sec_since_last_hit_valid = !resp->aged;
18161 [ # # ]: 0 : if (resp->sec_since_last_hit_valid)
18162 : 0 : resp->sec_since_last_hit = rte_atomic_load_explicit
18163 : : (&age_param->sec_since_last_hit, rte_memory_order_relaxed);
18164 : : return 0;
18165 : 0 : case MLX5_INDIRECT_ACTION_TYPE_COUNT:
18166 : 0 : return flow_dv_query_count(dev, idx, data, error);
18167 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
18168 : 0 : owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(idx);
18169 [ # # ]: 0 : if (owner != PORT_ID(priv))
18170 : 0 : return rte_flow_error_set(error, EACCES,
18171 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18172 : : NULL,
18173 : : "CT object owned by another port");
18174 : 0 : dev_idx = MLX5_INDIRECT_ACT_CT_GET_IDX(idx);
18175 : 0 : ct = flow_aso_ct_get_by_dev_idx(dev, dev_idx);
18176 : : MLX5_ASSERT(ct);
18177 [ # # ]: 0 : if (!ct->refcnt)
18178 : 0 : return rte_flow_error_set(error, EFAULT,
18179 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18180 : : NULL,
18181 : : "CT object is inactive");
18182 : 0 : ((struct rte_flow_action_conntrack *)data)->peer_port =
18183 : 0 : ct->peer;
18184 : 0 : ((struct rte_flow_action_conntrack *)data)->is_original_dir =
18185 : 0 : ct->is_original;
18186 [ # # ]: 0 : if (mlx5_aso_ct_query_by_wqe(priv->sh, MLX5_HW_INV_QUEUE, ct,
18187 : : data, NULL, true))
18188 : 0 : return rte_flow_error_set(error, EIO,
18189 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18190 : : NULL,
18191 : : "Failed to query CT context");
18192 : : return 0;
18193 : 0 : default:
18194 : 0 : return rte_flow_error_set(error, ENOTSUP,
18195 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
18196 : : "action type query not supported");
18197 : : }
18198 : : }
18199 : :
18200 : : /**
18201 : : * Query a flow rule AGE action for aging information.
18202 : : *
18203 : : * @param[in] dev
18204 : : * Pointer to Ethernet device.
18205 : : * @param[in] flow
18206 : : * Pointer to the sub flow.
18207 : : * @param[out] data
18208 : : * data retrieved by the query.
18209 : : * @param[out] error
18210 : : * Perform verbose error reporting if not NULL.
18211 : : *
18212 : : * @return
18213 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
18214 : : */
18215 : : static int
18216 : 0 : flow_dv_query_age(struct rte_eth_dev *dev, struct rte_flow *flow,
18217 : : void *data, struct rte_flow_error *error)
18218 : : {
18219 : : struct rte_flow_query_age *resp = data;
18220 : : struct mlx5_age_param *age_param;
18221 : :
18222 [ # # ]: 0 : if (flow->age) {
18223 : : struct mlx5_aso_age_action *act =
18224 : 0 : flow_aso_age_get_by_idx(dev, flow->age);
18225 : :
18226 : 0 : age_param = &act->age_params;
18227 [ # # ]: 0 : } else if (flow->counter) {
18228 : : age_param = flow_dv_counter_idx_get_age(dev, flow->counter);
18229 : :
18230 [ # # ]: 0 : if (!age_param || !age_param->timeout)
18231 : 0 : return rte_flow_error_set
18232 : : (error, EINVAL,
18233 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18234 : : NULL, "cannot read age data");
18235 : : } else {
18236 : 0 : return rte_flow_error_set(error, EINVAL,
18237 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18238 : : NULL, "age data not available");
18239 : : }
18240 : 0 : resp->aged = rte_atomic_load_explicit(&age_param->state, rte_memory_order_relaxed) ==
18241 : 0 : AGE_TMOUT ? 1 : 0;
18242 : 0 : resp->sec_since_last_hit_valid = !resp->aged;
18243 [ # # ]: 0 : if (resp->sec_since_last_hit_valid)
18244 : 0 : resp->sec_since_last_hit = rte_atomic_load_explicit
18245 : : (&age_param->sec_since_last_hit, rte_memory_order_relaxed);
18246 : : return 0;
18247 : : }
18248 : :
18249 : : /**
18250 : : * Query a flow.
18251 : : *
18252 : : * @see rte_flow_query()
18253 : : * @see rte_flow_ops
18254 : : */
18255 : : static int
18256 : 0 : flow_dv_query(struct rte_eth_dev *dev,
18257 : : struct rte_flow *flow __rte_unused,
18258 : : const struct rte_flow_action *actions __rte_unused,
18259 : : void *data __rte_unused,
18260 : : struct rte_flow_error *error __rte_unused)
18261 : : {
18262 : : int ret = -EINVAL;
18263 : :
18264 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
18265 [ # # # # ]: 0 : switch (actions->type) {
18266 : : case RTE_FLOW_ACTION_TYPE_VOID:
18267 : : break;
18268 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
18269 : 0 : ret = flow_dv_query_count(dev, flow->counter, data,
18270 : : error);
18271 : 0 : break;
18272 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
18273 [ # # ]: 0 : if (flow->indirect_type == MLX5_INDIRECT_ACTION_TYPE_CT)
18274 : 0 : return rte_flow_error_set(error, ENOTSUP,
18275 : : RTE_FLOW_ERROR_TYPE_ACTION,
18276 : : actions,
18277 : : "age not available");
18278 : 0 : ret = flow_dv_query_age(dev, flow, data, error);
18279 : 0 : break;
18280 : 0 : default:
18281 : 0 : return rte_flow_error_set(error, ENOTSUP,
18282 : : RTE_FLOW_ERROR_TYPE_ACTION,
18283 : : actions,
18284 : : "action not supported");
18285 : : }
18286 : : }
18287 : : return ret;
18288 : : }
18289 : :
18290 : : /**
18291 : : * Destroy the meter table set.
18292 : : * Lock free, (mutex should be acquired by caller).
18293 : : *
18294 : : * @param[in] dev
18295 : : * Pointer to Ethernet device.
18296 : : * @param[in] fm
18297 : : * Meter information table.
18298 : : */
18299 : : static void
18300 : 0 : flow_dv_destroy_mtr_tbls(struct rte_eth_dev *dev,
18301 : : struct mlx5_flow_meter_info *fm)
18302 : : {
18303 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18304 : : int i;
18305 : :
18306 [ # # # # ]: 0 : if (!fm || !priv->sh->config.dv_flow_en)
18307 : : return;
18308 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
18309 [ # # ]: 0 : if (fm->drop_rule[i]) {
18310 : : claim_zero(mlx5_flow_os_destroy_flow(fm->drop_rule[i]));
18311 : 0 : fm->drop_rule[i] = NULL;
18312 : : }
18313 : : }
18314 : : }
18315 : :
18316 : : static void
18317 : 0 : flow_dv_destroy_mtr_drop_tbls(struct rte_eth_dev *dev)
18318 : : {
18319 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18320 : 0 : struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
18321 : : struct mlx5_flow_tbl_data_entry *tbl;
18322 : : int i, j;
18323 : :
18324 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
18325 [ # # ]: 0 : if (mtrmng->def_rule[i]) {
18326 : : claim_zero(mlx5_flow_os_destroy_flow
18327 : : (mtrmng->def_rule[i]));
18328 : 0 : mtrmng->def_rule[i] = NULL;
18329 : : }
18330 [ # # ]: 0 : if (mtrmng->def_matcher[i]) {
18331 : 0 : tbl = container_of(mtrmng->def_matcher[i]->tbl,
18332 : : struct mlx5_flow_tbl_data_entry, tbl);
18333 : 0 : mlx5_list_unregister(tbl->matchers,
18334 : : &mtrmng->def_matcher[i]->entry);
18335 : 0 : mtrmng->def_matcher[i] = NULL;
18336 : : }
18337 [ # # ]: 0 : for (j = 0; j < MLX5_REG_BITS; j++) {
18338 [ # # ]: 0 : if (mtrmng->drop_matcher[i][j]) {
18339 : : tbl =
18340 : 0 : container_of(mtrmng->drop_matcher[i][j]->tbl,
18341 : : struct mlx5_flow_tbl_data_entry,
18342 : : tbl);
18343 : 0 : mlx5_list_unregister(tbl->matchers,
18344 : : &mtrmng->drop_matcher[i][j]->entry);
18345 : 0 : mtrmng->drop_matcher[i][j] = NULL;
18346 : : }
18347 : : }
18348 [ # # ]: 0 : if (mtrmng->drop_tbl[i]) {
18349 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev),
18350 : : mtrmng->drop_tbl[i]);
18351 : 0 : mtrmng->drop_tbl[i] = NULL;
18352 : : }
18353 : : }
18354 : 0 : }
18355 : :
18356 : : /* Number of meter flow actions, count and jump or count and drop. */
18357 : : #define METER_ACTIONS 2
18358 : :
18359 : : static void
18360 : 0 : __flow_dv_destroy_domain_def_policy(struct rte_eth_dev *dev,
18361 : : enum mlx5_meter_domain domain)
18362 : : {
18363 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18364 : 0 : struct mlx5_flow_meter_def_policy *def_policy =
18365 : 0 : priv->sh->mtrmng->def_policy[domain];
18366 : :
18367 : 0 : __flow_dv_destroy_sub_policy_rules(dev, &def_policy->sub_policy);
18368 : 0 : mlx5_free(def_policy);
18369 : 0 : priv->sh->mtrmng->def_policy[domain] = NULL;
18370 : 0 : }
18371 : :
18372 : : /**
18373 : : * Destroy the default policy table set.
18374 : : *
18375 : : * @param[in] dev
18376 : : * Pointer to Ethernet device.
18377 : : */
18378 : : static void
18379 : 0 : flow_dv_destroy_def_policy(struct rte_eth_dev *dev)
18380 : : {
18381 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18382 : : int i;
18383 : :
18384 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++)
18385 [ # # ]: 0 : if (priv->sh->mtrmng->def_policy[i])
18386 : 0 : __flow_dv_destroy_domain_def_policy(dev,
18387 : : (enum mlx5_meter_domain)i);
18388 : 0 : priv->sh->mtrmng->def_policy_id = MLX5_INVALID_POLICY_ID;
18389 : 0 : }
18390 : :
18391 : : static int
18392 : 0 : __flow_dv_create_policy_flow(struct rte_eth_dev *dev,
18393 : : uint32_t color_reg_c_idx,
18394 : : enum rte_color color, struct mlx5_flow_dv_matcher *matcher,
18395 : : int actions_n, void *actions,
18396 : : bool match_src_port, const struct rte_flow_item *item,
18397 : : void **rule, const struct rte_flow_attr *attr)
18398 : : {
18399 : : int ret;
18400 : 0 : struct mlx5_flow_dv_match_params value = {
18401 : : .size = sizeof(value.buf),
18402 : : };
18403 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18404 : : uint8_t misc_mask;
18405 : :
18406 [ # # # # ]: 0 : if (match_src_port && priv->sh->esw_mode) {
18407 [ # # # # ]: 0 : if (item && item->type == RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT)
18408 : 0 : ret = flow_dv_translate_item_represented_port(dev, value.buf,
18409 : : item, attr, MLX5_SET_MATCHER_SW_V);
18410 [ # # # # ]: 0 : else if (item && item->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR)
18411 : 0 : ret = flow_dv_translate_item_port_representor(dev, value.buf,
18412 : : MLX5_SET_MATCHER_SW_V);
18413 : : else
18414 : 0 : ret = flow_dv_translate_item_port_id(dev, value.buf,
18415 : : item, attr, MLX5_SET_MATCHER_SW_V);
18416 [ # # ]: 0 : if (ret) {
18417 : 0 : DRV_LOG(ERR, "Failed to create meter policy%d flow's"
18418 : : " value with port.", color);
18419 : 0 : return -1;
18420 : : }
18421 : : }
18422 : 0 : flow_dv_match_meta_reg(value.buf, (enum modify_reg)color_reg_c_idx,
18423 : : rte_col_2_mlx5_col(color), UINT32_MAX);
18424 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(matcher->mask.buf);
18425 : : __flow_dv_adjust_buf_size(&value.size, misc_mask);
18426 : 0 : ret = mlx5_flow_os_create_flow(matcher->matcher_object, (void *)&value,
18427 : : actions_n, actions, rule);
18428 : : if (ret) {
18429 : 0 : DRV_LOG(ERR, "Failed to create meter policy%d flow.", color);
18430 : 0 : return -1;
18431 : : }
18432 : : return 0;
18433 : : }
18434 : :
18435 : : static int
18436 : 0 : __flow_dv_create_policy_matcher(struct rte_eth_dev *dev,
18437 : : uint32_t color_reg_c_idx,
18438 : : uint16_t priority,
18439 : : struct mlx5_flow_meter_sub_policy *sub_policy,
18440 : : const struct rte_flow_attr *attr,
18441 : : bool match_src_port,
18442 : : const struct rte_flow_item *item,
18443 : : struct mlx5_flow_dv_matcher **policy_matcher,
18444 : : struct rte_flow_error *error)
18445 : : {
18446 : : struct mlx5_list_entry *entry;
18447 : 0 : struct mlx5_flow_tbl_resource *tbl_rsc = sub_policy->tbl_rsc;
18448 : 0 : struct mlx5_flow_dv_matcher matcher = {
18449 : : .mask = {
18450 : : .size = sizeof(matcher.mask.buf),
18451 : : },
18452 : : .tbl = tbl_rsc,
18453 : : };
18454 : 0 : struct mlx5_flow_cb_ctx ctx = {
18455 : : .error = error,
18456 : : .data = &matcher,
18457 : : };
18458 : : struct mlx5_flow_tbl_data_entry *tbl_data;
18459 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18460 : : const uint32_t color_mask = (UINT32_C(1) << MLX5_MTR_COLOR_BITS) - 1;
18461 : : int ret;
18462 : :
18463 [ # # # # ]: 0 : if (match_src_port && priv->sh->esw_mode) {
18464 [ # # # # ]: 0 : if (item && item->type == RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT)
18465 : 0 : ret = flow_dv_translate_item_represented_port(dev, matcher.mask.buf,
18466 : : item, attr, MLX5_SET_MATCHER_SW_M);
18467 [ # # # # ]: 0 : else if (item && item->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR)
18468 : 0 : ret = flow_dv_translate_item_port_representor(dev, matcher.mask.buf,
18469 : : MLX5_SET_MATCHER_SW_M);
18470 : : else
18471 : 0 : ret = flow_dv_translate_item_port_id(dev, matcher.mask.buf,
18472 : : item, attr, MLX5_SET_MATCHER_SW_M);
18473 [ # # ]: 0 : if (ret) {
18474 : 0 : DRV_LOG(ERR, "Failed to register meter policy%d matcher"
18475 : : " with port.", priority);
18476 : 0 : return -1;
18477 : : }
18478 : : }
18479 : 0 : tbl_data = container_of(tbl_rsc, struct mlx5_flow_tbl_data_entry, tbl);
18480 : 0 : flow_dv_match_meta_reg(matcher.mask.buf,
18481 : : (enum modify_reg)color_reg_c_idx, color_mask, color_mask);
18482 : 0 : matcher.priority = priority;
18483 : 0 : matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
18484 : : matcher.mask.size);
18485 : 0 : entry = mlx5_list_register(tbl_data->matchers, &ctx);
18486 [ # # ]: 0 : if (!entry) {
18487 : 0 : DRV_LOG(ERR, "Failed to register meter drop matcher.");
18488 : 0 : return -1;
18489 : : }
18490 : 0 : *policy_matcher =
18491 : : container_of(entry, struct mlx5_flow_dv_matcher, entry);
18492 : 0 : return 0;
18493 : : }
18494 : :
18495 : : /**
18496 : : * Create the policy rules per domain.
18497 : : *
18498 : : * @param[in] dev
18499 : : * Pointer to Ethernet device.
18500 : : * @param[in] sub_policy
18501 : : * Pointer to sub policy table..
18502 : : * @param[in] egress
18503 : : * Direction of the table.
18504 : : * @param[in] transfer
18505 : : * E-Switch or NIC flow.
18506 : : * @param[in] acts
18507 : : * Pointer to policy action list per color.
18508 : : *
18509 : : * @return
18510 : : * 0 on success, -1 otherwise.
18511 : : */
18512 : : static int
18513 : 0 : __flow_dv_create_domain_policy_rules(struct rte_eth_dev *dev,
18514 : : struct mlx5_flow_meter_sub_policy *sub_policy,
18515 : : uint8_t egress, uint8_t transfer, bool *match_src_port,
18516 : : struct mlx5_meter_policy_acts acts[RTE_COLORS])
18517 : : {
18518 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18519 : : struct rte_flow_error flow_err;
18520 : : uint32_t color_reg_c_idx;
18521 : 0 : struct rte_flow_attr attr = {
18522 : : .group = MLX5_FLOW_TABLE_LEVEL_POLICY,
18523 : : .priority = 0,
18524 : : .ingress = 0,
18525 : 0 : .egress = !!egress,
18526 : 0 : .transfer = !!transfer,
18527 : : .reserved = 0,
18528 : : };
18529 : : int i;
18530 : : uint16_t priority;
18531 : 0 : int ret = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &flow_err);
18532 : : struct mlx5_sub_policy_color_rule *color_rule;
18533 : 0 : struct mlx5_sub_policy_color_rule *tmp_rules[RTE_COLORS] = {NULL};
18534 : :
18535 [ # # ]: 0 : if (ret < 0)
18536 : : return -1;
18537 : : /* Create policy table with POLICY level. */
18538 [ # # ]: 0 : if (!sub_policy->tbl_rsc)
18539 : 0 : sub_policy->tbl_rsc = flow_dv_tbl_resource_get(dev,
18540 : : MLX5_FLOW_TABLE_LEVEL_POLICY,
18541 : : egress, transfer, false, NULL, 0, 0,
18542 : 0 : sub_policy->idx, &flow_err);
18543 [ # # ]: 0 : if (!sub_policy->tbl_rsc) {
18544 : 0 : DRV_LOG(ERR,
18545 : : "Failed to create meter sub policy table.");
18546 : 0 : return -1;
18547 : : }
18548 : : /* Prepare matchers. */
18549 : 0 : color_reg_c_idx = ret;
18550 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
18551 : 0 : TAILQ_INIT(&sub_policy->color_rules[i]);
18552 [ # # ]: 0 : if (!acts[i].actions_n)
18553 : 0 : continue;
18554 : 0 : color_rule = mlx5_malloc(MLX5_MEM_ZERO,
18555 : : sizeof(struct mlx5_sub_policy_color_rule),
18556 : : 0, SOCKET_ID_ANY);
18557 [ # # ]: 0 : if (!color_rule) {
18558 : 0 : DRV_LOG(ERR, "No memory to create color rule.");
18559 : 0 : goto err_exit;
18560 : : }
18561 : 0 : tmp_rules[i] = color_rule;
18562 : 0 : TAILQ_INSERT_TAIL(&sub_policy->color_rules[i],
18563 : : color_rule, next_port);
18564 : 0 : color_rule->src_port = priv->representor_id;
18565 : 0 : priority = (match_src_port[i] == match_src_port[RTE_COLOR_GREEN]) ?
18566 : 0 : MLX5_MTR_POLICY_MATCHER_PRIO : (MLX5_MTR_POLICY_MATCHER_PRIO + 1);
18567 : : /* Create matchers for colors. */
18568 [ # # ]: 0 : if (__flow_dv_create_policy_matcher(dev, color_reg_c_idx,
18569 : : priority, sub_policy,
18570 : : &attr, match_src_port[i], NULL,
18571 : : &color_rule->matcher, &flow_err)) {
18572 : 0 : DRV_LOG(ERR, "Failed to create color%u matcher.", i);
18573 : 0 : goto err_exit;
18574 : : }
18575 : : /* Create flow, matching color. */
18576 [ # # ]: 0 : if (__flow_dv_create_policy_flow(dev,
18577 : : color_reg_c_idx, (enum rte_color)i,
18578 : : color_rule->matcher,
18579 : 0 : acts[i].actions_n, acts[i].dv_actions,
18580 : 0 : match_src_port[i], NULL, &color_rule->rule,
18581 : : &attr)) {
18582 : 0 : DRV_LOG(ERR, "Failed to create color%u rule.", i);
18583 : 0 : goto err_exit;
18584 : : }
18585 : : }
18586 : : return 0;
18587 : : err_exit:
18588 : : /* All the policy rules will be cleared. */
18589 : : do {
18590 : 0 : color_rule = tmp_rules[i];
18591 [ # # ]: 0 : if (color_rule) {
18592 [ # # ]: 0 : if (color_rule->rule)
18593 : : mlx5_flow_os_destroy_flow(color_rule->rule);
18594 [ # # ]: 0 : if (color_rule->matcher) {
18595 : : struct mlx5_flow_tbl_data_entry *tbl =
18596 : 0 : container_of(color_rule->matcher->tbl,
18597 : : typeof(*tbl), tbl);
18598 : 0 : mlx5_list_unregister(tbl->matchers,
18599 : : &color_rule->matcher->entry);
18600 : : }
18601 [ # # ]: 0 : TAILQ_REMOVE(&sub_policy->color_rules[i],
18602 : : color_rule, next_port);
18603 : 0 : mlx5_free(color_rule);
18604 : : }
18605 [ # # ]: 0 : } while (i--);
18606 : : return -1;
18607 : : }
18608 : :
18609 : : static int
18610 : 0 : __flow_dv_create_policy_acts_rules(struct rte_eth_dev *dev,
18611 : : struct mlx5_flow_meter_policy *mtr_policy,
18612 : : struct mlx5_flow_meter_sub_policy *sub_policy,
18613 : : uint32_t domain)
18614 : : {
18615 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18616 : : struct mlx5_meter_policy_acts acts[RTE_COLORS];
18617 : : struct mlx5_flow_dv_tag_resource *tag;
18618 : : struct mlx5_flow_dv_port_id_action_resource *port_action;
18619 : : struct mlx5_hrxq *hrxq;
18620 : 0 : struct mlx5_flow_meter_info *next_fm[RTE_COLORS] = {NULL};
18621 : : struct mlx5_flow_meter_policy *next_policy;
18622 : : struct mlx5_flow_meter_sub_policy *next_sub_policy;
18623 : : struct mlx5_flow_tbl_data_entry *tbl_data;
18624 : : struct rte_flow_error error;
18625 : 0 : uint8_t egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
18626 : 0 : uint8_t transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
18627 [ # # # # : 0 : bool mtr_first = egress || (transfer && priv->representor_id != UINT16_MAX);
# # ]
18628 : 0 : bool match_src_port[RTE_COLORS] = {false};
18629 : : int i;
18630 : :
18631 : : /* If RSS or Queue, no previous actions / rules is created. */
18632 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
18633 : 0 : acts[i].actions_n = 0;
18634 [ # # ]: 0 : if (i == RTE_COLOR_RED) {
18635 : : /* Only support drop on red. */
18636 : 0 : acts[i].dv_actions[0] =
18637 : 0 : mtr_policy->dr_drop_action[domain];
18638 : 0 : acts[i].actions_n = 1;
18639 : 0 : continue;
18640 : : }
18641 [ # # ]: 0 : if (mtr_policy->act_cnt[i].fate_action == MLX5_FLOW_FATE_MTR) {
18642 : 0 : struct rte_flow_attr attr = {
18643 : : .transfer = transfer
18644 : : };
18645 : :
18646 : 0 : next_fm[i] = mlx5_flow_meter_find(priv,
18647 : : mtr_policy->act_cnt[i].next_mtr_id,
18648 : : NULL);
18649 [ # # ]: 0 : if (!next_fm[i]) {
18650 : 0 : DRV_LOG(ERR,
18651 : : "Failed to get next hierarchy meter.");
18652 : 0 : goto err_exit;
18653 : : }
18654 [ # # ]: 0 : if (mlx5_flow_meter_attach(priv, next_fm[i],
18655 : : &attr, &error)) {
18656 : 0 : DRV_LOG(ERR, "%s", error.message);
18657 : 0 : next_fm[i] = NULL;
18658 : 0 : goto err_exit;
18659 : : }
18660 : : /* Meter action must be the first for TX. */
18661 [ # # ]: 0 : if (mtr_first) {
18662 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18663 [ # # ]: 0 : (next_fm[i]->color_aware && i == RTE_COLOR_YELLOW) ?
18664 [ # # ]: 0 : next_fm[i]->meter_action_y :
18665 : : next_fm[i]->meter_action_g;
18666 : 0 : acts[i].actions_n++;
18667 : : }
18668 : : }
18669 [ # # ]: 0 : if (mtr_policy->act_cnt[i].rix_mark) {
18670 : 0 : tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG],
18671 : : mtr_policy->act_cnt[i].rix_mark);
18672 [ # # ]: 0 : if (!tag) {
18673 : 0 : DRV_LOG(ERR, "Failed to find "
18674 : : "mark action for policy.");
18675 : 0 : goto err_exit;
18676 : : }
18677 : 0 : acts[i].dv_actions[acts[i].actions_n] = tag->action;
18678 : 0 : acts[i].actions_n++;
18679 : : }
18680 [ # # ]: 0 : if (mtr_policy->act_cnt[i].modify_hdr) {
18681 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18682 : 0 : mtr_policy->act_cnt[i].modify_hdr->action;
18683 : 0 : acts[i].actions_n++;
18684 : : }
18685 [ # # ]: 0 : if (mtr_policy->act_cnt[i].fate_action) {
18686 [ # # # # : 0 : switch (mtr_policy->act_cnt[i].fate_action) {
# ]
18687 : 0 : case MLX5_FLOW_FATE_PORT_ID:
18688 : 0 : port_action = mlx5_ipool_get
18689 : 0 : (priv->sh->ipool[MLX5_IPOOL_PORT_ID],
18690 : : mtr_policy->act_cnt[i].rix_port_id_action);
18691 [ # # ]: 0 : if (!port_action) {
18692 : 0 : DRV_LOG(ERR, "Failed to find "
18693 : : "port action for policy.");
18694 : 0 : goto err_exit;
18695 : : }
18696 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18697 : 0 : port_action->action;
18698 : 0 : acts[i].actions_n++;
18699 : 0 : match_src_port[i] = true;
18700 : 0 : break;
18701 : 0 : case MLX5_FLOW_FATE_DROP:
18702 : : case MLX5_FLOW_FATE_JUMP:
18703 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18704 : 0 : mtr_policy->act_cnt[i].dr_jump_action[domain];
18705 : 0 : acts[i].actions_n++;
18706 : 0 : break;
18707 : 0 : case MLX5_FLOW_FATE_SHARED_RSS:
18708 : : case MLX5_FLOW_FATE_QUEUE:
18709 : 0 : hrxq = mlx5_ipool_get
18710 : 0 : (priv->sh->ipool[MLX5_IPOOL_HRXQ],
18711 : : sub_policy->rix_hrxq[i]);
18712 [ # # ]: 0 : if (!hrxq) {
18713 : 0 : DRV_LOG(ERR, "Failed to find "
18714 : : "queue action for policy.");
18715 : 0 : goto err_exit;
18716 : : }
18717 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18718 : 0 : hrxq->action;
18719 : 0 : acts[i].actions_n++;
18720 : 0 : break;
18721 : 0 : case MLX5_FLOW_FATE_MTR:
18722 [ # # ]: 0 : if (!next_fm[i]) {
18723 : 0 : DRV_LOG(ERR,
18724 : : "No next hierarchy meter.");
18725 : 0 : goto err_exit;
18726 : : }
18727 [ # # ]: 0 : if (!mtr_first) {
18728 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18729 [ # # ]: 0 : (next_fm[i]->color_aware && i == RTE_COLOR_YELLOW) ?
18730 [ # # ]: 0 : next_fm[i]->meter_action_y :
18731 : : next_fm[i]->meter_action_g;
18732 : 0 : acts[i].actions_n++;
18733 : : }
18734 [ # # ]: 0 : if (mtr_policy->act_cnt[i].next_sub_policy) {
18735 : : next_sub_policy =
18736 : : mtr_policy->act_cnt[i].next_sub_policy;
18737 : : } else {
18738 : : next_policy =
18739 : 0 : mlx5_flow_meter_policy_find(dev,
18740 : : next_fm[i]->policy_id, NULL);
18741 : : MLX5_ASSERT(next_policy);
18742 : 0 : next_sub_policy =
18743 : 0 : next_policy->sub_policys[domain][0];
18744 : : }
18745 : : tbl_data =
18746 : 0 : container_of(next_sub_policy->tbl_rsc,
18747 : : struct mlx5_flow_tbl_data_entry, tbl);
18748 : 0 : acts[i].dv_actions[acts[i].actions_n++] =
18749 : 0 : tbl_data->jump.action;
18750 [ # # ]: 0 : if (mtr_policy->act_cnt[i].modify_hdr)
18751 : 0 : match_src_port[i] = !!transfer;
18752 : : break;
18753 : : default:
18754 : : /*Queue action do nothing*/
18755 : : break;
18756 : : }
18757 : : }
18758 : : }
18759 [ # # ]: 0 : if (__flow_dv_create_domain_policy_rules(dev, sub_policy,
18760 : : egress, transfer, match_src_port, acts)) {
18761 : 0 : DRV_LOG(ERR,
18762 : : "Failed to create policy rules per domain.");
18763 : 0 : goto err_exit;
18764 : : }
18765 [ # # # # ]: 0 : if (match_src_port[RTE_COLOR_GREEN] || match_src_port[RTE_COLOR_YELLOW]) {
18766 : 0 : mtr_policy->match_port = 1;
18767 : 0 : mtr_policy->hierarchy_match_port = 1;
18768 : : }
18769 : : return 0;
18770 : : err_exit:
18771 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++)
18772 [ # # ]: 0 : if (next_fm[i])
18773 : 0 : mlx5_flow_meter_detach(priv, next_fm[i]);
18774 : : return -1;
18775 : : }
18776 : :
18777 : : /**
18778 : : * Create the policy rules.
18779 : : *
18780 : : * @param[in] dev
18781 : : * Pointer to Ethernet device.
18782 : : * @param[in,out] mtr_policy
18783 : : * Pointer to meter policy table.
18784 : : *
18785 : : * @return
18786 : : * 0 on success, -1 otherwise.
18787 : : */
18788 : : static int
18789 : 0 : flow_dv_create_policy_rules(struct rte_eth_dev *dev,
18790 : : struct mlx5_flow_meter_policy *mtr_policy)
18791 : : {
18792 : : int i;
18793 : : int ret = 0;
18794 : : uint16_t sub_policy_num;
18795 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_push_thread_workspace();
18796 : :
18797 : : RTE_SET_USED(wks);
18798 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
18799 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
18800 : 0 : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
18801 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
18802 [ # # ]: 0 : if (!sub_policy_num)
18803 : 0 : continue;
18804 : : /* Prepare actions list and create policy rules. */
18805 [ # # ]: 0 : if (__flow_dv_create_policy_acts_rules(dev, mtr_policy,
18806 : 0 : mtr_policy->sub_policys[i][0], i)) {
18807 : 0 : DRV_LOG(ERR, "Failed to create policy action "
18808 : : "list per domain.");
18809 : : ret = -1;
18810 : 0 : goto exit;
18811 : : }
18812 : : }
18813 : 0 : exit:
18814 : 0 : mlx5_flow_pop_thread_workspace();
18815 : 0 : return ret;
18816 : : }
18817 : :
18818 : : static int
18819 : 0 : __flow_dv_create_domain_def_policy(struct rte_eth_dev *dev, uint32_t domain)
18820 : : {
18821 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18822 : 0 : struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
18823 : : struct mlx5_flow_meter_def_policy *def_policy;
18824 : : struct mlx5_flow_tbl_resource *jump_tbl;
18825 : : struct mlx5_flow_tbl_data_entry *tbl_data;
18826 : : uint8_t egress, transfer;
18827 : : struct rte_flow_error error;
18828 : : struct mlx5_meter_policy_acts acts[RTE_COLORS];
18829 : 0 : bool match_src_port[RTE_COLORS] = {false};
18830 : : int ret;
18831 : :
18832 : 0 : egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
18833 : 0 : transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
18834 : 0 : def_policy = mtrmng->def_policy[domain];
18835 [ # # ]: 0 : if (!def_policy) {
18836 : 0 : def_policy = mlx5_malloc(MLX5_MEM_ZERO,
18837 : : sizeof(struct mlx5_flow_meter_def_policy),
18838 : : RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
18839 [ # # ]: 0 : if (!def_policy) {
18840 : 0 : DRV_LOG(ERR, "Failed to alloc default policy table.");
18841 : 0 : goto def_policy_error;
18842 : : }
18843 : 0 : mtrmng->def_policy[domain] = def_policy;
18844 : : /* Create the meter suffix table with SUFFIX level. */
18845 : 0 : jump_tbl = flow_dv_tbl_resource_get(dev,
18846 : : MLX5_FLOW_TABLE_LEVEL_METER,
18847 : : egress, transfer, false, NULL, 0,
18848 : : 0, MLX5_MTR_TABLE_ID_SUFFIX, &error);
18849 [ # # ]: 0 : if (!jump_tbl) {
18850 : 0 : DRV_LOG(ERR,
18851 : : "Failed to create meter suffix table.");
18852 : 0 : goto def_policy_error;
18853 : : }
18854 : 0 : def_policy->sub_policy.jump_tbl[RTE_COLOR_GREEN] = jump_tbl;
18855 : 0 : tbl_data = container_of(jump_tbl,
18856 : : struct mlx5_flow_tbl_data_entry, tbl);
18857 : 0 : def_policy->dr_jump_action[RTE_COLOR_GREEN] =
18858 : 0 : tbl_data->jump.action;
18859 : 0 : acts[RTE_COLOR_GREEN].dv_actions[0] = tbl_data->jump.action;
18860 : 0 : acts[RTE_COLOR_GREEN].actions_n = 1;
18861 : : /*
18862 : : * YELLOW has the same default policy as GREEN does.
18863 : : * G & Y share the same table and action. The 2nd time of table
18864 : : * resource getting is just to update the reference count for
18865 : : * the releasing stage.
18866 : : */
18867 : 0 : jump_tbl = flow_dv_tbl_resource_get(dev,
18868 : : MLX5_FLOW_TABLE_LEVEL_METER,
18869 : : egress, transfer, false, NULL, 0,
18870 : : 0, MLX5_MTR_TABLE_ID_SUFFIX, &error);
18871 [ # # ]: 0 : if (!jump_tbl) {
18872 : 0 : DRV_LOG(ERR,
18873 : : "Failed to get meter suffix table.");
18874 : 0 : goto def_policy_error;
18875 : : }
18876 : 0 : def_policy->sub_policy.jump_tbl[RTE_COLOR_YELLOW] = jump_tbl;
18877 : 0 : tbl_data = container_of(jump_tbl,
18878 : : struct mlx5_flow_tbl_data_entry, tbl);
18879 : 0 : def_policy->dr_jump_action[RTE_COLOR_YELLOW] =
18880 : 0 : tbl_data->jump.action;
18881 : 0 : acts[RTE_COLOR_YELLOW].dv_actions[0] = tbl_data->jump.action;
18882 : 0 : acts[RTE_COLOR_YELLOW].actions_n = 1;
18883 : : /* Create jump action to the drop table. */
18884 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
18885 : 0 : mtrmng->drop_tbl[domain] = flow_dv_tbl_resource_get
18886 : : (dev, MLX5_FLOW_TABLE_LEVEL_METER,
18887 : : egress, transfer, false, NULL, 0,
18888 : : 0, MLX5_MTR_TABLE_ID_DROP, &error);
18889 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
18890 : 0 : DRV_LOG(ERR, "Failed to create meter "
18891 : : "drop table for default policy.");
18892 : 0 : goto def_policy_error;
18893 : : }
18894 : : }
18895 : : /* all RED: unique Drop table for jump action. */
18896 : 0 : tbl_data = container_of(mtrmng->drop_tbl[domain],
18897 : : struct mlx5_flow_tbl_data_entry, tbl);
18898 : 0 : def_policy->dr_jump_action[RTE_COLOR_RED] =
18899 : 0 : tbl_data->jump.action;
18900 : 0 : acts[RTE_COLOR_RED].dv_actions[0] = tbl_data->jump.action;
18901 : 0 : acts[RTE_COLOR_RED].actions_n = 1;
18902 : : /* Create default policy rules. */
18903 : 0 : ret = __flow_dv_create_domain_policy_rules(dev,
18904 : : &def_policy->sub_policy,
18905 : : egress, transfer, match_src_port, acts);
18906 [ # # ]: 0 : if (ret) {
18907 : 0 : DRV_LOG(ERR, "Failed to create default policy rules.");
18908 : 0 : goto def_policy_error;
18909 : : }
18910 : : }
18911 : : return 0;
18912 : 0 : def_policy_error:
18913 : 0 : __flow_dv_destroy_domain_def_policy(dev,
18914 : : (enum mlx5_meter_domain)domain);
18915 : 0 : return -1;
18916 : : }
18917 : :
18918 : : /**
18919 : : * Create the default policy table set.
18920 : : *
18921 : : * @param[in] dev
18922 : : * Pointer to Ethernet device.
18923 : : * @return
18924 : : * 0 on success, -1 otherwise.
18925 : : */
18926 : : static int
18927 : 0 : flow_dv_create_def_policy(struct rte_eth_dev *dev)
18928 : : {
18929 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18930 : : int i;
18931 : :
18932 : : /* Non-termination policy table. */
18933 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
18934 [ # # # # ]: 0 : if (!priv->sh->config.dv_esw_en &&
18935 : : i == MLX5_MTR_DOMAIN_TRANSFER)
18936 : 0 : continue;
18937 [ # # ]: 0 : if (__flow_dv_create_domain_def_policy(dev, i)) {
18938 : 0 : DRV_LOG(ERR, "Failed to create default policy");
18939 : : /* Rollback the created default policies for others. */
18940 : 0 : flow_dv_destroy_def_policy(dev);
18941 : 0 : return -1;
18942 : : }
18943 : : }
18944 : : return 0;
18945 : : }
18946 : :
18947 : : /**
18948 : : * Create the needed meter tables.
18949 : : * Lock free, (mutex should be acquired by caller).
18950 : : *
18951 : : * @param[in] dev
18952 : : * Pointer to Ethernet device.
18953 : : * @param[in] fm
18954 : : * Meter information table.
18955 : : * @param[in] mtr_idx
18956 : : * Meter index.
18957 : : * @param[in] domain_bitmap
18958 : : * Domain bitmap.
18959 : : * @return
18960 : : * 0 on success, -1 otherwise.
18961 : : */
18962 : : static int
18963 : 0 : flow_dv_create_mtr_tbls(struct rte_eth_dev *dev,
18964 : : struct mlx5_flow_meter_info *fm,
18965 : : uint32_t mtr_idx,
18966 : : uint8_t domain_bitmap)
18967 : : {
18968 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18969 : 0 : struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
18970 : : struct rte_flow_error error;
18971 : : struct mlx5_flow_tbl_data_entry *tbl_data;
18972 : : uint8_t egress, transfer;
18973 : : void *actions[METER_ACTIONS];
18974 : : int domain, ret, i;
18975 : : struct mlx5_flow_counter *cnt;
18976 : 0 : struct mlx5_flow_dv_match_params value = {
18977 : : .size = sizeof(value.buf),
18978 : : };
18979 : 0 : struct mlx5_flow_dv_match_params matcher_para = {
18980 : : .size = sizeof(matcher_para.buf),
18981 : : };
18982 : 0 : int mtr_id_reg_c = mlx5_flow_get_reg_id(dev, MLX5_MTR_ID,
18983 : : 0, &error);
18984 : 0 : uint32_t mtr_id_mask = (UINT32_C(1) << mtrmng->max_mtr_bits) - 1;
18985 : 0 : uint8_t mtr_id_offset = priv->mtr_reg_share ? MLX5_MTR_COLOR_BITS : 0;
18986 : : struct mlx5_list_entry *entry;
18987 : 0 : struct mlx5_flow_dv_matcher matcher = {
18988 : : .mask = {
18989 : : .size = sizeof(matcher.mask.buf),
18990 : : },
18991 : : };
18992 : : struct mlx5_flow_dv_matcher *drop_matcher;
18993 : 0 : struct mlx5_flow_cb_ctx ctx = {
18994 : : .error = &error,
18995 : : .data = &matcher,
18996 : : };
18997 : : uint8_t misc_mask;
18998 : :
18999 [ # # # # ]: 0 : if (!priv->mtr_en || mtr_id_reg_c < 0) {
19000 : 0 : rte_errno = ENOTSUP;
19001 : 0 : return -1;
19002 : : }
19003 [ # # ]: 0 : for (domain = 0; domain < MLX5_MTR_DOMAIN_MAX; domain++) {
19004 [ # # ]: 0 : if (!(domain_bitmap & (1 << domain)) ||
19005 [ # # # # ]: 0 : (mtrmng->def_rule[domain] && !fm->drop_cnt))
19006 : 0 : continue;
19007 : 0 : egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
19008 : 0 : transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
19009 : : /* Create the drop table with METER DROP level. */
19010 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
19011 : 0 : mtrmng->drop_tbl[domain] = flow_dv_tbl_resource_get(dev,
19012 : : MLX5_FLOW_TABLE_LEVEL_METER,
19013 : : egress, transfer, false, NULL, 0,
19014 : : 0, MLX5_MTR_TABLE_ID_DROP, &error);
19015 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
19016 : 0 : DRV_LOG(ERR, "Failed to create meter drop table.");
19017 : 0 : goto policy_error;
19018 : : }
19019 : : }
19020 : : /* Create default matcher in drop table. */
19021 : 0 : matcher.tbl = mtrmng->drop_tbl[domain];
19022 : 0 : tbl_data = container_of(mtrmng->drop_tbl[domain],
19023 : : struct mlx5_flow_tbl_data_entry, tbl);
19024 [ # # ]: 0 : if (!mtrmng->def_matcher[domain]) {
19025 : 0 : flow_dv_match_meta_reg_all(matcher.mask.buf, value.buf,
19026 : : (enum modify_reg)mtr_id_reg_c,
19027 : : 0, 0);
19028 : 0 : matcher.priority = MLX5_MTRS_DEFAULT_RULE_PRIORITY;
19029 : 0 : matcher.crc = rte_raw_cksum
19030 : : ((const void *)matcher.mask.buf,
19031 : : matcher.mask.size);
19032 : 0 : entry = mlx5_list_register(tbl_data->matchers, &ctx);
19033 [ # # ]: 0 : if (!entry) {
19034 : 0 : DRV_LOG(ERR, "Failed to register meter "
19035 : : "drop default matcher.");
19036 : 0 : goto policy_error;
19037 : : }
19038 : 0 : mtrmng->def_matcher[domain] = container_of(entry,
19039 : : struct mlx5_flow_dv_matcher, entry);
19040 : : }
19041 : : /* Create default rule in drop table. */
19042 [ # # ]: 0 : if (!mtrmng->def_rule[domain]) {
19043 : : i = 0;
19044 : 0 : actions[i++] = priv->sh->dr_drop_action;
19045 : 0 : flow_dv_match_meta_reg_all(matcher_para.buf, value.buf,
19046 : : (enum modify_reg)mtr_id_reg_c, 0, 0);
19047 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(mtrmng->def_matcher[domain]->mask.buf);
19048 : : __flow_dv_adjust_buf_size(&value.size, misc_mask);
19049 : 0 : ret = mlx5_flow_os_create_flow
19050 : : (mtrmng->def_matcher[domain]->matcher_object,
19051 : : (void *)&value, i, actions,
19052 : : &mtrmng->def_rule[domain]);
19053 : : if (ret) {
19054 : 0 : DRV_LOG(ERR, "Failed to create meter "
19055 : : "default drop rule for drop table.");
19056 : 0 : goto policy_error;
19057 : : }
19058 : : }
19059 [ # # ]: 0 : if (!fm->drop_cnt)
19060 : 0 : continue;
19061 : : MLX5_ASSERT(mtrmng->max_mtr_bits);
19062 [ # # ]: 0 : if (!mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1]) {
19063 : : /* Create matchers for Drop. */
19064 : 0 : flow_dv_match_meta_reg_all(matcher.mask.buf, value.buf,
19065 : : (enum modify_reg)mtr_id_reg_c, 0,
19066 : : (mtr_id_mask << mtr_id_offset));
19067 : 0 : matcher.priority = MLX5_REG_BITS - mtrmng->max_mtr_bits;
19068 : 0 : matcher.crc = rte_raw_cksum
19069 : : ((const void *)matcher.mask.buf,
19070 : : matcher.mask.size);
19071 : 0 : entry = mlx5_list_register(tbl_data->matchers, &ctx);
19072 [ # # ]: 0 : if (!entry) {
19073 : 0 : DRV_LOG(ERR,
19074 : : "Failed to register meter drop matcher.");
19075 : 0 : goto policy_error;
19076 : : }
19077 : 0 : mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1] =
19078 : : container_of(entry, struct mlx5_flow_dv_matcher,
19079 : : entry);
19080 : : }
19081 : 0 : drop_matcher =
19082 : 0 : mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1];
19083 : : /* Create drop rule, matching meter_id only. */
19084 : 0 : flow_dv_match_meta_reg_all(matcher_para.buf, value.buf,
19085 : : (enum modify_reg)mtr_id_reg_c,
19086 : : (mtr_idx << mtr_id_offset), UINT32_MAX);
19087 : : i = 0;
19088 [ # # ]: 0 : cnt = flow_dv_counter_get_by_idx(dev,
19089 : : fm->drop_cnt, NULL);
19090 : 0 : actions[i++] = cnt->action;
19091 : 0 : actions[i++] = priv->sh->dr_drop_action;
19092 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(drop_matcher->mask.buf);
19093 : : __flow_dv_adjust_buf_size(&value.size, misc_mask);
19094 : 0 : ret = mlx5_flow_os_create_flow(drop_matcher->matcher_object,
19095 : : (void *)&value, i, actions,
19096 : : &fm->drop_rule[domain]);
19097 : : if (ret) {
19098 : 0 : DRV_LOG(ERR, "Failed to create meter "
19099 : : "drop rule for drop table.");
19100 : 0 : goto policy_error;
19101 : : }
19102 : : }
19103 : : return 0;
19104 : : policy_error:
19105 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
19106 [ # # ]: 0 : if (fm->drop_rule[i]) {
19107 : : claim_zero(mlx5_flow_os_destroy_flow
19108 : : (fm->drop_rule[i]));
19109 : 0 : fm->drop_rule[i] = NULL;
19110 : : }
19111 : : }
19112 : : return -1;
19113 : : }
19114 : :
19115 : : static struct mlx5_flow_meter_sub_policy *
19116 : 0 : __flow_dv_meter_get_rss_sub_policy(struct rte_eth_dev *dev,
19117 : : struct mlx5_flow_meter_policy *mtr_policy,
19118 : : struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS],
19119 : : struct mlx5_flow_meter_sub_policy *next_sub_policy,
19120 : : bool *is_reuse)
19121 : : {
19122 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19123 : : struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
19124 : 0 : uint32_t sub_policy_idx = 0;
19125 : 0 : uint32_t hrxq_idx[MLX5_MTR_RTE_COLORS] = {0};
19126 : : uint32_t i, j;
19127 : : struct mlx5_hrxq *hrxq;
19128 : : struct mlx5_flow_handle dh;
19129 : : struct mlx5_meter_policy_action_container *act_cnt;
19130 : : uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
19131 : : uint16_t sub_policy_num;
19132 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
19133 : :
19134 : : MLX5_ASSERT(wks);
19135 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19136 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
19137 [ # # ]: 0 : if (!rss_desc[i])
19138 : 0 : continue;
19139 : 0 : hrxq = mlx5_hrxq_get(dev, rss_desc[i]);
19140 [ # # ]: 0 : if (!hrxq) {
19141 : : rte_spinlock_unlock(&mtr_policy->sl);
19142 : 0 : return NULL;
19143 : : }
19144 : 0 : hrxq_idx[i] = hrxq->idx;
19145 : : }
19146 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
19147 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
19148 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
19149 [ # # ]: 0 : for (j = 0; j < sub_policy_num; j++) {
19150 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
19151 [ # # ]: 0 : if (rss_desc[i] &&
19152 : 0 : hrxq_idx[i] !=
19153 [ # # ]: 0 : mtr_policy->sub_policys[domain][j]->rix_hrxq[i])
19154 : : break;
19155 : : }
19156 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS) {
19157 : : /*
19158 : : * Found the sub policy table with
19159 : : * the same queue per color.
19160 : : */
19161 : : rte_spinlock_unlock(&mtr_policy->sl);
19162 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++)
19163 : 0 : mlx5_hrxq_release(dev, hrxq_idx[i]);
19164 : 0 : *is_reuse = true;
19165 : 0 : return mtr_policy->sub_policys[domain][j];
19166 : : }
19167 : : }
19168 : : /* Create sub policy. */
19169 [ # # ]: 0 : if (!mtr_policy->sub_policys[domain][0]->rix_hrxq[RTE_COLOR_GREEN] &&
19170 : : !mtr_policy->sub_policys[domain][0]->rix_hrxq[RTE_COLOR_YELLOW]) {
19171 : : /* Reuse the first pre-allocated sub_policy. */
19172 : : sub_policy = mtr_policy->sub_policys[domain][0];
19173 : 0 : sub_policy_idx = sub_policy->idx;
19174 : : } else {
19175 : 0 : sub_policy = mlx5_ipool_zmalloc
19176 : 0 : (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
19177 : : &sub_policy_idx);
19178 [ # # ]: 0 : if (!sub_policy ||
19179 [ # # ]: 0 : sub_policy_idx > MLX5_MAX_SUB_POLICY_TBL_NUM) {
19180 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++)
19181 : 0 : mlx5_hrxq_release(dev, hrxq_idx[i]);
19182 : 0 : goto rss_sub_policy_error;
19183 : : }
19184 : 0 : sub_policy->idx = sub_policy_idx;
19185 : 0 : sub_policy->main_policy = mtr_policy;
19186 : : }
19187 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
19188 [ # # ]: 0 : if (!rss_desc[i])
19189 : 0 : continue;
19190 : 0 : sub_policy->rix_hrxq[i] = hrxq_idx[i];
19191 [ # # ]: 0 : if (mtr_policy->is_hierarchy) {
19192 : : act_cnt = &mtr_policy->act_cnt[i];
19193 : 0 : act_cnt->next_sub_policy = next_sub_policy;
19194 : 0 : mlx5_hrxq_release(dev, hrxq_idx[i]);
19195 : : } else {
19196 : : /*
19197 : : * Overwrite the last action from
19198 : : * RSS action to Queue action.
19199 : : */
19200 : 0 : hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
19201 : : hrxq_idx[i]);
19202 [ # # ]: 0 : if (!hrxq) {
19203 : 0 : DRV_LOG(ERR, "Failed to get policy hrxq");
19204 : 0 : goto rss_sub_policy_error;
19205 : : }
19206 : : act_cnt = &mtr_policy->act_cnt[i];
19207 [ # # # # ]: 0 : if (act_cnt->rix_mark || act_cnt->modify_hdr) {
19208 : : memset(&dh, 0, sizeof(struct mlx5_flow_handle));
19209 [ # # ]: 0 : if (act_cnt->rix_mark)
19210 : 0 : wks->mark = 1;
19211 : 0 : dh.fate_action = MLX5_FLOW_FATE_QUEUE;
19212 : 0 : dh.rix_hrxq = hrxq_idx[i];
19213 : 0 : flow_drv_rxq_flags_set(dev, &dh);
19214 : : }
19215 : : }
19216 : : }
19217 [ # # ]: 0 : if (__flow_dv_create_policy_acts_rules(dev, mtr_policy,
19218 : : sub_policy, domain)) {
19219 : 0 : DRV_LOG(ERR, "Failed to create policy "
19220 : : "rules for ingress domain.");
19221 : 0 : goto rss_sub_policy_error;
19222 : : }
19223 [ # # ]: 0 : if (sub_policy != mtr_policy->sub_policys[domain][0]) {
19224 : 0 : i = (mtr_policy->sub_policy_num >>
19225 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
19226 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
19227 [ # # ]: 0 : if (i >= MLX5_MTR_RSS_MAX_SUB_POLICY) {
19228 : 0 : DRV_LOG(ERR, "No free sub-policy slot.");
19229 : 0 : goto rss_sub_policy_error;
19230 : : }
19231 : 0 : mtr_policy->sub_policys[domain][i] = sub_policy;
19232 : 0 : i++;
19233 : 0 : mtr_policy->sub_policy_num &= ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
19234 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain));
19235 : 0 : mtr_policy->sub_policy_num |=
19236 : 0 : (i & MLX5_MTR_SUB_POLICY_NUM_MASK) <<
19237 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain);
19238 : : }
19239 : : rte_spinlock_unlock(&mtr_policy->sl);
19240 : 0 : *is_reuse = false;
19241 : 0 : return sub_policy;
19242 : 0 : rss_sub_policy_error:
19243 [ # # ]: 0 : if (sub_policy) {
19244 : 0 : __flow_dv_destroy_sub_policy_rules(dev, sub_policy);
19245 [ # # ]: 0 : if (sub_policy != mtr_policy->sub_policys[domain][0]) {
19246 : 0 : i = (mtr_policy->sub_policy_num >>
19247 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
19248 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
19249 : 0 : mtr_policy->sub_policys[domain][i] = NULL;
19250 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
19251 : 0 : sub_policy->idx);
19252 : : }
19253 : : }
19254 : : rte_spinlock_unlock(&mtr_policy->sl);
19255 : 0 : return NULL;
19256 : : }
19257 : :
19258 : : /**
19259 : : * Find the policy table for prefix table with RSS.
19260 : : *
19261 : : * @param[in] dev
19262 : : * Pointer to Ethernet device.
19263 : : * @param[in] mtr_policy
19264 : : * Pointer to meter policy table.
19265 : : * @param[in] rss_desc
19266 : : * Pointer to rss_desc
19267 : : * @return
19268 : : * Pointer to table set on success, NULL otherwise and rte_errno is set.
19269 : : */
19270 : : static struct mlx5_flow_meter_sub_policy *
19271 : 0 : flow_dv_meter_sub_policy_rss_prepare(struct rte_eth_dev *dev,
19272 : : struct mlx5_flow_meter_policy *mtr_policy,
19273 : : struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS])
19274 : : {
19275 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19276 : : struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
19277 : : struct mlx5_flow_meter_info *next_fm;
19278 : : struct mlx5_flow_meter_policy *next_policy;
19279 : : struct mlx5_flow_meter_sub_policy *next_sub_policy = NULL;
19280 : : struct mlx5_flow_meter_policy *policies[MLX5_MTR_CHAIN_MAX_NUM];
19281 : : struct mlx5_flow_meter_sub_policy *sub_policies[MLX5_MTR_CHAIN_MAX_NUM];
19282 : : uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
19283 : : bool reuse_sub_policy;
19284 : : uint32_t i = 0;
19285 : : uint32_t j = 0;
19286 : :
19287 : : while (true) {
19288 : : /* Iterate hierarchy to get all policies in this hierarchy. */
19289 : 0 : policies[i++] = mtr_policy;
19290 [ # # ]: 0 : if (!mtr_policy->is_hierarchy)
19291 : : break;
19292 [ # # ]: 0 : if (i >= MLX5_MTR_CHAIN_MAX_NUM) {
19293 : 0 : DRV_LOG(ERR, "Exceed max meter number in hierarchy.");
19294 : 0 : return NULL;
19295 : : }
19296 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19297 : 0 : next_fm = mlx5_flow_meter_hierarchy_next_meter(priv, mtr_policy, NULL);
19298 : : rte_spinlock_unlock(&mtr_policy->sl);
19299 [ # # ]: 0 : if (!next_fm) {
19300 : 0 : DRV_LOG(ERR, "Failed to get next meter in hierarchy.");
19301 : 0 : return NULL;
19302 : : }
19303 : : next_policy =
19304 : 0 : mlx5_flow_meter_policy_find(dev, next_fm->policy_id,
19305 : : NULL);
19306 : : MLX5_ASSERT(next_policy);
19307 : : mtr_policy = next_policy;
19308 : : }
19309 [ # # ]: 0 : while (i) {
19310 : : /**
19311 : : * From last policy to the first one in hierarchy,
19312 : : * create / get the sub policy for each of them.
19313 : : */
19314 : 0 : sub_policy = __flow_dv_meter_get_rss_sub_policy(dev,
19315 : : policies[--i],
19316 : : rss_desc,
19317 : : next_sub_policy,
19318 : : &reuse_sub_policy);
19319 [ # # ]: 0 : if (!sub_policy) {
19320 : 0 : DRV_LOG(ERR, "Failed to get the sub policy.");
19321 : 0 : goto err_exit;
19322 : : }
19323 [ # # ]: 0 : if (!reuse_sub_policy)
19324 : 0 : sub_policies[j++] = sub_policy;
19325 : : next_sub_policy = sub_policy;
19326 : : }
19327 : : return sub_policy;
19328 : : err_exit:
19329 [ # # ]: 0 : while (j) {
19330 : : uint16_t sub_policy_num;
19331 : :
19332 : 0 : sub_policy = sub_policies[--j];
19333 : 0 : mtr_policy = sub_policy->main_policy;
19334 : 0 : __flow_dv_destroy_sub_policy_rules(dev, sub_policy);
19335 [ # # ]: 0 : if (sub_policy != mtr_policy->sub_policys[domain][0]) {
19336 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
19337 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
19338 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
19339 : 0 : mtr_policy->sub_policys[domain][sub_policy_num - 1] =
19340 : : NULL;
19341 : 0 : sub_policy_num--;
19342 : 0 : mtr_policy->sub_policy_num &=
19343 : 0 : ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
19344 : 0 : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i));
19345 : 0 : mtr_policy->sub_policy_num |=
19346 : 0 : (sub_policy_num & MLX5_MTR_SUB_POLICY_NUM_MASK) <<
19347 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i);
19348 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
19349 : 0 : sub_policy->idx);
19350 : : }
19351 : : }
19352 : : return NULL;
19353 : : }
19354 : :
19355 : : /**
19356 : : * Check if need to create hierarchy tag rule.
19357 : : *
19358 : : * @param[in] priv
19359 : : * Pointer to mlx5_priv.
19360 : : * @param[in] mtr_policy
19361 : : * Pointer to current meter policy.
19362 : : * @param[in] src_port
19363 : : * The src port this extra rule should use.
19364 : : * @param[out] next_fm
19365 : : * Pointer to next meter in hierarchy.
19366 : : * @param[out] skip
19367 : : * Indicate if skip the tag rule creation.
19368 : : * @param[out] error
19369 : : * Perform verbose error reporting if not NULL.
19370 : : * @return
19371 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
19372 : : */
19373 : : static int
19374 : 0 : mlx5_meter_hierarchy_skip_tag_rule(struct mlx5_priv *priv,
19375 : : struct mlx5_flow_meter_policy *mtr_policy,
19376 : : int32_t src_port,
19377 : : struct mlx5_flow_meter_info **next_fm,
19378 : : bool *skip,
19379 : : struct rte_flow_error *error)
19380 : : {
19381 : : struct mlx5_flow_meter_sub_policy *sub_policy;
19382 : : struct mlx5_sub_policy_color_rule *color_rule;
19383 : : uint32_t domain = MLX5_MTR_DOMAIN_TRANSFER;
19384 : : int ret = 0;
19385 : : int i;
19386 : :
19387 : 0 : *next_fm = NULL;
19388 : 0 : *skip = false;
19389 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19390 [ # # ]: 0 : if (mtr_policy->is_hierarchy) {
19391 : 0 : *next_fm = mlx5_flow_meter_hierarchy_next_meter(priv, mtr_policy, NULL);
19392 [ # # ]: 0 : if (!*next_fm) {
19393 : 0 : ret = rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
19394 : : NULL, "Failed to find next meter in hierarchy.");
19395 : 0 : goto exit;
19396 : : }
19397 : : }
19398 [ # # ]: 0 : if (!mtr_policy->match_port) {
19399 : 0 : *skip = true;
19400 : 0 : goto exit;
19401 : : }
19402 : 0 : sub_policy = mtr_policy->sub_policys[domain][0];
19403 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
19404 [ # # ]: 0 : if (mtr_policy->act_cnt[i].fate_action != MLX5_FLOW_FATE_MTR &&
19405 : : mtr_policy->act_cnt[i].fate_action != MLX5_FLOW_FATE_PORT_ID)
19406 : 0 : continue;
19407 [ # # ]: 0 : TAILQ_FOREACH(color_rule, &sub_policy->color_rules[i], next_port)
19408 [ # # ]: 0 : if (color_rule->src_port == src_port) {
19409 : 0 : *skip = true;
19410 : 0 : goto exit;
19411 : : }
19412 : : }
19413 : 0 : exit:
19414 : : rte_spinlock_unlock(&mtr_policy->sl);
19415 : 0 : return ret;
19416 : : }
19417 : :
19418 : : /**
19419 : : * Create the sub policy tag rule for all meters in hierarchy.
19420 : : *
19421 : : * @param[in] dev
19422 : : * Pointer to Ethernet device.
19423 : : * @param[in] fm
19424 : : * Meter information table.
19425 : : * @param[in] src_port
19426 : : * The src port this extra rule should use.
19427 : : * @param[in] item
19428 : : * The src port match item.
19429 : : * @param[out] error
19430 : : * Perform verbose error reporting if not NULL.
19431 : : * @return
19432 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
19433 : : */
19434 : : static int
19435 : 0 : flow_dv_meter_hierarchy_rule_create(struct rte_eth_dev *dev,
19436 : : struct mlx5_flow_meter_info *fm,
19437 : : int32_t src_port,
19438 : : const struct rte_flow_item *item,
19439 : : struct rte_flow_error *error)
19440 : : {
19441 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19442 : : struct mlx5_flow_meter_policy *mtr_policy;
19443 : : struct mlx5_flow_meter_sub_policy *sub_policy;
19444 : 0 : struct mlx5_flow_meter_info *next_fm = NULL;
19445 : : struct mlx5_flow_meter_policy *next_policy;
19446 : : struct mlx5_flow_meter_sub_policy *next_sub_policy;
19447 : : struct mlx5_flow_tbl_data_entry *tbl_data;
19448 : : struct mlx5_sub_policy_color_rule *color_rule;
19449 : : struct mlx5_meter_policy_acts acts;
19450 : : uint32_t color_reg_c_idx;
19451 : : bool mtr_first = (src_port != UINT16_MAX) ? true : false;
19452 : 0 : struct rte_flow_attr attr = {
19453 : : .group = MLX5_FLOW_TABLE_LEVEL_POLICY,
19454 : : .priority = 0,
19455 : : .ingress = 0,
19456 : : .egress = 0,
19457 : : .transfer = 1,
19458 : : .reserved = 0,
19459 : : };
19460 : : uint32_t domain = MLX5_MTR_DOMAIN_TRANSFER;
19461 : : struct {
19462 : : struct mlx5_flow_meter_policy *fm_policy;
19463 : : struct mlx5_flow_meter_info *next_fm;
19464 : : struct mlx5_sub_policy_color_rule *tag_rule[RTE_COLORS];
19465 : 0 : } fm_info[MLX5_MTR_CHAIN_MAX_NUM] = { {0} };
19466 : : uint32_t fm_cnt = 0;
19467 : : uint32_t i, j;
19468 : :
19469 : 0 : color_reg_c_idx = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, error);
19470 : : /* Get all fms who need to create the tag color rule. */
19471 : : do {
19472 : 0 : bool skip = false;
19473 : :
19474 : 0 : mtr_policy = mlx5_flow_meter_policy_find(dev, fm->policy_id, NULL);
19475 : : MLX5_ASSERT(mtr_policy);
19476 [ # # ]: 0 : if (mlx5_meter_hierarchy_skip_tag_rule(priv, mtr_policy, src_port,
19477 : : &next_fm, &skip, error))
19478 : 0 : goto err_exit;
19479 [ # # ]: 0 : if (!skip) {
19480 : 0 : fm_info[fm_cnt].fm_policy = mtr_policy;
19481 : 0 : fm_info[fm_cnt].next_fm = next_fm;
19482 [ # # ]: 0 : if (++fm_cnt >= MLX5_MTR_CHAIN_MAX_NUM) {
19483 : 0 : rte_flow_error_set(error, errno,
19484 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
19485 : : "Exceed max meter number in hierarchy.");
19486 : 0 : goto err_exit;
19487 : : }
19488 : : }
19489 : 0 : fm = next_fm;
19490 [ # # ]: 0 : } while (fm);
19491 : : /* Create tag color rules for all needed fms. */
19492 [ # # ]: 0 : for (i = 0; i < fm_cnt; i++) {
19493 : : void *mtr_action;
19494 : :
19495 : 0 : mtr_policy = fm_info[i].fm_policy;
19496 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19497 : 0 : sub_policy = mtr_policy->sub_policys[domain][0];
19498 [ # # ]: 0 : for (j = 0; j < RTE_COLORS; j++) {
19499 : : uint8_t act_n = 0;
19500 : : struct mlx5_flow_dv_modify_hdr_resource *modify_hdr = NULL;
19501 : : struct mlx5_flow_dv_port_id_action_resource *port_action;
19502 : : uint8_t fate_action;
19503 : :
19504 [ # # ]: 0 : if (j == RTE_COLOR_RED) {
19505 : : fate_action = MLX5_FLOW_FATE_DROP;
19506 : : } else {
19507 : 0 : fate_action = mtr_policy->act_cnt[j].fate_action;
19508 : 0 : modify_hdr = mtr_policy->act_cnt[j].modify_hdr;
19509 : 0 : if (fate_action != MLX5_FLOW_FATE_MTR &&
19510 [ # # # # ]: 0 : fate_action != MLX5_FLOW_FATE_PORT_ID &&
19511 : : fate_action != MLX5_FLOW_FATE_DROP)
19512 : 0 : continue;
19513 : : }
19514 : 0 : color_rule = mlx5_malloc(MLX5_MEM_ZERO,
19515 : : sizeof(struct mlx5_sub_policy_color_rule),
19516 : : 0, SOCKET_ID_ANY);
19517 [ # # ]: 0 : if (!color_rule) {
19518 : : rte_spinlock_unlock(&mtr_policy->sl);
19519 : 0 : rte_flow_error_set(error, ENOMEM,
19520 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
19521 : : "No memory to create tag color rule.");
19522 : 0 : goto err_exit;
19523 : : }
19524 : 0 : color_rule->src_port = src_port;
19525 : : /* Prepare to create color rule. */
19526 [ # # ]: 0 : if (fate_action == MLX5_FLOW_FATE_MTR) {
19527 : 0 : next_fm = fm_info[i].next_fm;
19528 [ # # ]: 0 : if (mlx5_flow_meter_attach(priv, next_fm, &attr, error)) {
19529 : 0 : mlx5_free(color_rule);
19530 : : rte_spinlock_unlock(&mtr_policy->sl);
19531 : 0 : goto err_exit;
19532 : : }
19533 [ # # ]: 0 : mtr_action = (next_fm->color_aware && j == RTE_COLOR_YELLOW) ?
19534 [ # # ]: 0 : next_fm->meter_action_y :
19535 : : next_fm->meter_action_g;
19536 : 0 : next_policy = mlx5_flow_meter_policy_find(dev, next_fm->policy_id,
19537 : : NULL);
19538 : : MLX5_ASSERT(next_policy);
19539 : 0 : next_sub_policy = next_policy->sub_policys[domain][0];
19540 : 0 : tbl_data = container_of(next_sub_policy->tbl_rsc,
19541 : : struct mlx5_flow_tbl_data_entry, tbl);
19542 [ # # ]: 0 : if (mtr_first) {
19543 : 0 : acts.dv_actions[act_n++] = mtr_action;
19544 [ # # ]: 0 : if (modify_hdr)
19545 : 0 : acts.dv_actions[act_n++] = modify_hdr->action;
19546 : : } else {
19547 [ # # ]: 0 : if (modify_hdr)
19548 : 0 : acts.dv_actions[act_n++] = modify_hdr->action;
19549 : 0 : acts.dv_actions[act_n++] = mtr_action;
19550 : : }
19551 : 0 : acts.dv_actions[act_n++] = tbl_data->jump.action;
19552 : 0 : acts.actions_n = act_n;
19553 [ # # ]: 0 : } else if (fate_action == MLX5_FLOW_FATE_PORT_ID) {
19554 : : port_action =
19555 : 0 : mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PORT_ID],
19556 : : mtr_policy->act_cnt[j].rix_port_id_action);
19557 [ # # ]: 0 : if (!port_action) {
19558 : 0 : mlx5_free(color_rule);
19559 : : rte_spinlock_unlock(&mtr_policy->sl);
19560 : 0 : goto err_exit;
19561 : : }
19562 [ # # ]: 0 : if (modify_hdr)
19563 : 0 : acts.dv_actions[act_n++] = modify_hdr->action;
19564 : 0 : acts.dv_actions[act_n++] = port_action->action;
19565 : 0 : acts.actions_n = act_n;
19566 : : } else {
19567 : 0 : acts.dv_actions[act_n++] = mtr_policy->dr_drop_action[domain];
19568 : 0 : acts.actions_n = act_n;
19569 : : }
19570 : 0 : fm_info[i].tag_rule[j] = color_rule;
19571 : 0 : TAILQ_INSERT_TAIL(&sub_policy->color_rules[j], color_rule, next_port);
19572 [ # # ]: 0 : if (__flow_dv_create_policy_matcher(dev, color_reg_c_idx,
19573 : : MLX5_MTR_POLICY_MATCHER_PRIO, sub_policy,
19574 : : &attr, true, item, &color_rule->matcher, error)) {
19575 : : rte_spinlock_unlock(&mtr_policy->sl);
19576 : 0 : rte_flow_error_set(error, errno,
19577 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
19578 : : "Failed to create hierarchy meter matcher.");
19579 : 0 : goto err_exit;
19580 : : }
19581 [ # # ]: 0 : if (__flow_dv_create_policy_flow(dev, color_reg_c_idx, (enum rte_color)j,
19582 : : color_rule->matcher,
19583 : 0 : acts.actions_n, acts.dv_actions,
19584 : : true, item, &color_rule->rule, &attr)) {
19585 : : rte_spinlock_unlock(&mtr_policy->sl);
19586 : 0 : rte_flow_error_set(error, errno,
19587 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
19588 : : "Failed to create hierarchy meter rule.");
19589 : 0 : goto err_exit;
19590 : : }
19591 : : }
19592 : : rte_spinlock_unlock(&mtr_policy->sl);
19593 : : }
19594 : : return 0;
19595 : 0 : err_exit:
19596 [ # # ]: 0 : for (i = 0; i < fm_cnt; i++) {
19597 : 0 : mtr_policy = fm_info[i].fm_policy;
19598 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19599 : 0 : sub_policy = mtr_policy->sub_policys[domain][0];
19600 [ # # ]: 0 : for (j = 0; j < RTE_COLORS; j++) {
19601 : 0 : color_rule = fm_info[i].tag_rule[j];
19602 [ # # ]: 0 : if (!color_rule)
19603 : 0 : continue;
19604 [ # # ]: 0 : if (color_rule->rule)
19605 : : mlx5_flow_os_destroy_flow(color_rule->rule);
19606 [ # # ]: 0 : if (color_rule->matcher) {
19607 : : struct mlx5_flow_tbl_data_entry *tbl =
19608 : 0 : container_of(color_rule->matcher->tbl, typeof(*tbl), tbl);
19609 : 0 : mlx5_list_unregister(tbl->matchers, &color_rule->matcher->entry);
19610 : : }
19611 [ # # ]: 0 : if (fm_info[i].next_fm)
19612 : 0 : mlx5_flow_meter_detach(priv, fm_info[i].next_fm);
19613 [ # # ]: 0 : TAILQ_REMOVE(&sub_policy->color_rules[j], color_rule, next_port);
19614 : 0 : mlx5_free(color_rule);
19615 : : }
19616 : : rte_spinlock_unlock(&mtr_policy->sl);
19617 : : }
19618 : 0 : return -rte_errno;
19619 : : }
19620 : :
19621 : : /**
19622 : : * Destroy the sub policy table with RX queue.
19623 : : *
19624 : : * @param[in] dev
19625 : : * Pointer to Ethernet device.
19626 : : * @param[in] mtr_policy
19627 : : * Pointer to meter policy table.
19628 : : */
19629 : : static void
19630 : 0 : flow_dv_destroy_sub_policy_with_rxq(struct rte_eth_dev *dev,
19631 : : struct mlx5_flow_meter_policy *mtr_policy)
19632 : : {
19633 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19634 : : struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
19635 : : uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
19636 : : uint32_t i, j;
19637 : : uint16_t sub_policy_num, new_policy_num;
19638 : :
19639 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19640 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
19641 [ # # # ]: 0 : switch (mtr_policy->act_cnt[i].fate_action) {
19642 : 0 : case MLX5_FLOW_FATE_SHARED_RSS:
19643 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
19644 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
19645 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
19646 : : new_policy_num = sub_policy_num;
19647 [ # # ]: 0 : for (j = 0; j < sub_policy_num; j++) {
19648 : 0 : sub_policy =
19649 : 0 : mtr_policy->sub_policys[domain][j];
19650 [ # # ]: 0 : if (sub_policy) {
19651 : 0 : __flow_dv_destroy_sub_policy_rules(dev,
19652 : : sub_policy);
19653 : 0 : if (sub_policy !=
19654 [ # # ]: 0 : mtr_policy->sub_policys[domain][0]) {
19655 : 0 : mtr_policy->sub_policys[domain][j] =
19656 : : NULL;
19657 : 0 : mlx5_ipool_free
19658 : 0 : (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
19659 : 0 : sub_policy->idx);
19660 : 0 : new_policy_num--;
19661 : : }
19662 : : }
19663 : : }
19664 [ # # ]: 0 : if (new_policy_num != sub_policy_num) {
19665 : 0 : mtr_policy->sub_policy_num &=
19666 : : ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
19667 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain));
19668 : 0 : mtr_policy->sub_policy_num |=
19669 : : (new_policy_num &
19670 : : MLX5_MTR_SUB_POLICY_NUM_MASK) <<
19671 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain);
19672 : : }
19673 : : break;
19674 : 0 : case MLX5_FLOW_FATE_QUEUE:
19675 : 0 : sub_policy = mtr_policy->sub_policys[domain][0];
19676 : 0 : __flow_dv_destroy_sub_policy_rules(dev,
19677 : : sub_policy);
19678 : 0 : break;
19679 : : default:
19680 : : /*Other actions without queue and do nothing*/
19681 : : break;
19682 : : }
19683 : : }
19684 : : rte_spinlock_unlock(&mtr_policy->sl);
19685 : 0 : }
19686 : : /**
19687 : : * Check whether the DR drop action is supported on the root table or not.
19688 : : *
19689 : : * Create a simple flow with DR drop action on root table to validate
19690 : : * if DR drop action on root table is supported or not.
19691 : : *
19692 : : * @param[in] dev
19693 : : * Pointer to rte_eth_dev structure.
19694 : : *
19695 : : * @return
19696 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
19697 : : */
19698 : : int
19699 : 0 : mlx5_flow_discover_dr_action_support(struct rte_eth_dev *dev)
19700 : : {
19701 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19702 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
19703 : 0 : struct mlx5_flow_dv_match_params mask = {
19704 : : .size = sizeof(mask.buf),
19705 : : };
19706 : 0 : struct mlx5_flow_dv_match_params value = {
19707 : : .size = sizeof(value.buf),
19708 : : };
19709 : 0 : struct mlx5dv_flow_matcher_attr dv_attr = {
19710 : : .type = IBV_FLOW_ATTR_NORMAL,
19711 : : .priority = 0,
19712 : : .match_criteria_enable = 0,
19713 : : .match_mask = (void *)&mask,
19714 : : };
19715 : : struct mlx5_flow_tbl_resource *tbl = NULL;
19716 : : void *matcher = NULL;
19717 : : void *flow = NULL;
19718 : : int ret = -1;
19719 : :
19720 : 0 : tbl = flow_dv_tbl_resource_get(dev, 0, 0, 0, false, NULL,
19721 : : 0, 0, 0, NULL);
19722 [ # # ]: 0 : if (!tbl)
19723 : 0 : goto err;
19724 [ # # ]: 0 : dv_attr.match_criteria_enable = flow_dv_matcher_enable(mask.buf);
19725 : : __flow_dv_adjust_buf_size(&mask.size, dv_attr.match_criteria_enable);
19726 : 0 : ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
19727 : : tbl->obj, &matcher);
19728 : : if (ret)
19729 : 0 : goto err;
19730 [ # # ]: 0 : __flow_dv_adjust_buf_size(&value.size, dv_attr.match_criteria_enable);
19731 : 0 : ret = mlx5_flow_os_create_flow(matcher, (void *)&value, 1,
19732 : : &sh->dr_drop_action, &flow);
19733 : 0 : err:
19734 : : /*
19735 : : * If DR drop action is not supported on root table, flow create will
19736 : : * be failed with EOPNOTSUPP or EPROTONOSUPPORT.
19737 : : */
19738 [ # # ]: 0 : if (!flow) {
19739 [ # # ]: 0 : if (matcher &&
19740 [ # # ]: 0 : (errno == EPROTONOSUPPORT || errno == EOPNOTSUPP))
19741 : 0 : DRV_LOG(INFO, "DR drop action is not supported in root table.");
19742 : : else
19743 : 0 : DRV_LOG(ERR, "Unexpected error in DR drop action support detection");
19744 : : ret = -1;
19745 : : } else {
19746 : : claim_zero(mlx5_flow_os_destroy_flow(flow));
19747 : : }
19748 [ # # ]: 0 : if (matcher)
19749 : : claim_zero(mlx5_flow_os_destroy_flow_matcher(matcher));
19750 [ # # ]: 0 : if (tbl)
19751 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
19752 : 0 : return ret;
19753 : : }
19754 : :
19755 : : /**
19756 : : * Validate the batch counter support in root table.
19757 : : *
19758 : : * Create a simple flow with invalid counter and drop action on root table to
19759 : : * validate if batch counter with offset on root table is supported or not.
19760 : : *
19761 : : * @param[in] dev
19762 : : * Pointer to rte_eth_dev structure.
19763 : : *
19764 : : * @return
19765 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
19766 : : */
19767 : : int
19768 : 0 : mlx5_flow_dv_discover_counter_offset_support(struct rte_eth_dev *dev)
19769 : : {
19770 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19771 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
19772 : 0 : struct mlx5_flow_dv_match_params mask = {
19773 : : .size = sizeof(mask.buf),
19774 : : };
19775 : 0 : struct mlx5_flow_dv_match_params value = {
19776 : : .size = sizeof(value.buf),
19777 : : };
19778 : 0 : struct mlx5dv_flow_matcher_attr dv_attr = {
19779 : : .type = IBV_FLOW_ATTR_NORMAL,
19780 : : .flags = IBV_FLOW_ATTR_FLAGS_EGRESS,
19781 : : .priority = 0,
19782 : : .match_criteria_enable = 0,
19783 : : .match_mask = (void *)&mask,
19784 : : };
19785 : 0 : void *actions[2] = { 0 };
19786 : : struct mlx5_flow_tbl_resource *tbl = NULL;
19787 : : struct mlx5_devx_obj *dcs = NULL;
19788 : : void *matcher = NULL;
19789 : : void *flow = NULL;
19790 : : int ret = -1;
19791 : :
19792 : 0 : tbl = flow_dv_tbl_resource_get(dev, 0, 1, 0, false, NULL,
19793 : : 0, 0, 0, NULL);
19794 [ # # ]: 0 : if (!tbl)
19795 : 0 : goto err;
19796 : 0 : dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0x4);
19797 [ # # ]: 0 : if (!dcs)
19798 : 0 : goto err;
19799 : 0 : ret = mlx5_flow_os_create_flow_action_count(dcs->obj, UINT16_MAX,
19800 : : &actions[0]);
19801 : : if (ret)
19802 : 0 : goto err;
19803 [ # # ]: 0 : dv_attr.match_criteria_enable = flow_dv_matcher_enable(mask.buf);
19804 : : __flow_dv_adjust_buf_size(&mask.size, dv_attr.match_criteria_enable);
19805 : 0 : ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
19806 : : tbl->obj, &matcher);
19807 : : if (ret)
19808 : 0 : goto err;
19809 [ # # ]: 0 : __flow_dv_adjust_buf_size(&value.size, dv_attr.match_criteria_enable);
19810 : : ret = mlx5_flow_os_create_flow(matcher, (void *)&value, 1,
19811 : : actions, &flow);
19812 : 0 : err:
19813 : : /*
19814 : : * If batch counter with offset is not supported, the driver will not
19815 : : * validate the invalid offset value, flow create should success.
19816 : : * In this case, it means batch counter is not supported in root table.
19817 : : *
19818 : : * Otherwise, if flow create is failed, counter offset is supported.
19819 : : */
19820 [ # # ]: 0 : if (flow) {
19821 : 0 : DRV_LOG(INFO, "Batch counter is not supported in root "
19822 : : "table. Switch to fallback mode.");
19823 : 0 : rte_errno = ENOTSUP;
19824 : : ret = -rte_errno;
19825 : : claim_zero(mlx5_flow_os_destroy_flow(flow));
19826 : : } else {
19827 : : /* Check matcher to make sure validate fail at flow create. */
19828 [ # # # # ]: 0 : if (!matcher || (matcher && errno != EINVAL))
19829 : 0 : DRV_LOG(ERR, "Unexpected error in counter offset "
19830 : : "support detection");
19831 : : ret = 0;
19832 : : }
19833 [ # # ]: 0 : if (actions[0])
19834 : : claim_zero(mlx5_flow_os_destroy_flow_action(actions[0]));
19835 [ # # ]: 0 : if (matcher)
19836 : : claim_zero(mlx5_flow_os_destroy_flow_matcher(matcher));
19837 [ # # ]: 0 : if (tbl)
19838 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
19839 [ # # ]: 0 : if (dcs)
19840 : 0 : claim_zero(mlx5_devx_cmd_destroy(dcs));
19841 : 0 : return ret;
19842 : : }
19843 : :
19844 : : /**
19845 : : * Query a devx counter.
19846 : : *
19847 : : * @param[in] dev
19848 : : * Pointer to the Ethernet device structure.
19849 : : * @param[in] cnt
19850 : : * Index to the flow counter.
19851 : : * @param[in] clear
19852 : : * Set to clear the counter statistics.
19853 : : * @param[out] pkts
19854 : : * The statistics value of packets.
19855 : : * @param[out] bytes
19856 : : * The statistics value of bytes.
19857 : : *
19858 : : * @return
19859 : : * 0 on success, otherwise return -1.
19860 : : */
19861 : : static int
19862 : 0 : flow_dv_counter_query(struct rte_eth_dev *dev, uint32_t counter, bool clear,
19863 : : uint64_t *pkts, uint64_t *bytes, void **action)
19864 : : {
19865 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19866 : : struct mlx5_flow_counter *cnt;
19867 : : uint64_t inn_pkts, inn_bytes;
19868 : : int ret;
19869 : :
19870 [ # # ]: 0 : if (!priv->sh->cdev->config.devx)
19871 : : return -1;
19872 : :
19873 : 0 : ret = _flow_dv_query_count(dev, counter, &inn_pkts, &inn_bytes);
19874 [ # # ]: 0 : if (ret)
19875 : : return -1;
19876 : : cnt = flow_dv_counter_get_by_idx(dev, counter, NULL);
19877 [ # # ]: 0 : if (cnt && action)
19878 : 0 : *action = cnt->action;
19879 : :
19880 : 0 : *pkts = inn_pkts - cnt->hits;
19881 : 0 : *bytes = inn_bytes - cnt->bytes;
19882 [ # # ]: 0 : if (clear) {
19883 : 0 : cnt->hits = inn_pkts;
19884 : 0 : cnt->bytes = inn_bytes;
19885 : : }
19886 : : return 0;
19887 : : }
19888 : :
19889 : : /**
19890 : : * Get aged-out flows.
19891 : : *
19892 : : * @param[in] dev
19893 : : * Pointer to the Ethernet device structure.
19894 : : * @param[in] context
19895 : : * The address of an array of pointers to the aged-out flows contexts.
19896 : : * @param[in] nb_contexts
19897 : : * The length of context array pointers.
19898 : : * @param[out] error
19899 : : * Perform verbose error reporting if not NULL. Initialized in case of
19900 : : * error only.
19901 : : *
19902 : : * @return
19903 : : * how many contexts get in success, otherwise negative errno value.
19904 : : * if nb_contexts is 0, return the amount of all aged contexts.
19905 : : * if nb_contexts is not 0 , return the amount of aged flows reported
19906 : : * in the context array.
19907 : : * @note: only stub for now
19908 : : */
19909 : : static int
19910 : 0 : flow_dv_get_aged_flows(struct rte_eth_dev *dev,
19911 : : void **context,
19912 : : uint32_t nb_contexts,
19913 : : struct rte_flow_error *error)
19914 : : {
19915 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19916 : : struct mlx5_age_info *age_info;
19917 : : struct mlx5_age_param *age_param;
19918 : : struct mlx5_flow_counter *counter;
19919 : : struct mlx5_aso_age_action *act;
19920 : : int nb_flows = 0;
19921 : :
19922 [ # # ]: 0 : if (nb_contexts && !context)
19923 : 0 : return rte_flow_error_set(error, EINVAL,
19924 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
19925 : : NULL, "empty context");
19926 : 0 : age_info = GET_PORT_AGE_INFO(priv);
19927 : 0 : rte_spinlock_lock(&age_info->aged_sl);
19928 [ # # ]: 0 : LIST_FOREACH(act, &age_info->aged_aso, next) {
19929 : 0 : nb_flows++;
19930 [ # # ]: 0 : if (nb_contexts) {
19931 : 0 : context[nb_flows - 1] = act->age_params.context;
19932 [ # # ]: 0 : if (!(--nb_contexts))
19933 : : break;
19934 : : }
19935 : : }
19936 [ # # ]: 0 : TAILQ_FOREACH(counter, &age_info->aged_counters, next) {
19937 : 0 : nb_flows++;
19938 [ # # ]: 0 : if (nb_contexts) {
19939 : : age_param = MLX5_CNT_TO_AGE(counter);
19940 : 0 : context[nb_flows - 1] = age_param->context;
19941 [ # # ]: 0 : if (!(--nb_contexts))
19942 : : break;
19943 : : }
19944 : : }
19945 : : rte_spinlock_unlock(&age_info->aged_sl);
19946 : 0 : MLX5_AGE_SET(age_info, MLX5_AGE_TRIGGER);
19947 : 0 : return nb_flows;
19948 : : }
19949 : :
19950 : : /*
19951 : : * Mutex-protected thunk to lock-free flow_dv_counter_alloc().
19952 : : */
19953 : : static uint32_t
19954 : 0 : flow_dv_counter_allocate(struct rte_eth_dev *dev)
19955 : : {
19956 : 0 : return flow_dv_counter_alloc(dev, 0);
19957 : : }
19958 : :
19959 : : /**
19960 : : * Validate indirect action.
19961 : : * Dispatcher for action type specific validation.
19962 : : *
19963 : : * @param[in] dev
19964 : : * Pointer to the Ethernet device structure.
19965 : : * @param[in] conf
19966 : : * Indirect action configuration.
19967 : : * @param[in] action
19968 : : * The indirect action object to validate.
19969 : : * @param[out] error
19970 : : * Perform verbose error reporting if not NULL. Initialized in case of
19971 : : * error only.
19972 : : *
19973 : : * @return
19974 : : * 0 on success, otherwise negative errno value.
19975 : : */
19976 : : int
19977 : 0 : flow_dv_action_validate(struct rte_eth_dev *dev,
19978 : : const struct rte_flow_indir_action_conf *conf,
19979 : : const struct rte_flow_action *action,
19980 : : struct rte_flow_error *err)
19981 : : {
19982 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19983 : : /* called from RTE API */
19984 : :
19985 : : RTE_SET_USED(conf);
19986 [ # # # # : 0 : switch (action->type) {
# ]
19987 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
19988 : : /*
19989 : : * priv->obj_ops is set according to driver capabilities.
19990 : : * When DevX capabilities are
19991 : : * sufficient, it is set to devx_obj_ops.
19992 : : * Otherwise, it is set to ibv_obj_ops.
19993 : : * ibv_obj_ops doesn't support ind_table_modify operation.
19994 : : * In this case the indirect RSS action can't be used.
19995 : : */
19996 [ # # ]: 0 : if (priv->obj_ops.ind_table_modify == NULL)
19997 : 0 : return rte_flow_error_set
19998 : : (err, ENOTSUP,
19999 : : RTE_FLOW_ERROR_TYPE_ACTION,
20000 : : NULL,
20001 : : "Indirect RSS action not supported");
20002 : 0 : return mlx5_validate_action_rss(dev, action, err);
20003 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
20004 [ # # ]: 0 : if (!priv->sh->aso_age_mng)
20005 : 0 : return rte_flow_error_set(err, ENOTSUP,
20006 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
20007 : : NULL,
20008 : : "Indirect age action not supported");
20009 : 0 : return flow_dv_validate_action_age(0, action, dev, err);
20010 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
20011 : 0 : return flow_dv_validate_action_count(dev, true, 0, false, err);
20012 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
20013 [ # # ]: 0 : if (!priv->sh->ct_aso_en)
20014 : 0 : return rte_flow_error_set(err, ENOTSUP,
20015 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
20016 : : "ASO CT is not supported");
20017 : 0 : return mlx5_validate_action_ct(dev, action->conf, err);
20018 : 0 : default:
20019 : 0 : return rte_flow_error_set(err, ENOTSUP,
20020 : : RTE_FLOW_ERROR_TYPE_ACTION,
20021 : : NULL,
20022 : : "action type not supported");
20023 : : }
20024 : : }
20025 : :
20026 : : /*
20027 : : * Check if the RSS configurations for colors of a meter policy match
20028 : : * each other, except the queues.
20029 : : *
20030 : : * @param[in] r1
20031 : : * Pointer to the first RSS flow action.
20032 : : * @param[in] r2
20033 : : * Pointer to the second RSS flow action.
20034 : : *
20035 : : * @return
20036 : : * 0 on match, 1 on conflict.
20037 : : */
20038 : : static inline int
20039 : 0 : flow_dv_mtr_policy_rss_compare(const struct rte_flow_action_rss *r1,
20040 : : const struct rte_flow_action_rss *r2)
20041 : : {
20042 [ # # ]: 0 : if (r1 == NULL || r2 == NULL)
20043 : : return 0;
20044 [ # # # # : 0 : if (!(r1->level <= 1 && r2->level <= 1) &&
# # ]
20045 [ # # ]: 0 : !(r1->level > 1 && r2->level > 1))
20046 : : return 1;
20047 [ # # ]: 0 : if (r1->func != r2->func)
20048 : : return 1;
20049 [ # # ]: 0 : if (r1->types != r2->types &&
20050 [ # # ]: 0 : !((r1->types == 0 || r1->types == RTE_ETH_RSS_IP) &&
20051 [ # # ]: 0 : (r2->types == 0 || r2->types == RTE_ETH_RSS_IP)))
20052 : : return 1;
20053 [ # # # # ]: 0 : if (r1->key || r2->key) {
20054 [ # # ]: 0 : const void *key1 = r1->key ? r1->key : rss_hash_default_key;
20055 [ # # ]: 0 : const void *key2 = r2->key ? r2->key : rss_hash_default_key;
20056 : :
20057 [ # # ]: 0 : if (memcmp(key1, key2, MLX5_RSS_HASH_KEY_LEN))
20058 : 0 : return 1;
20059 : : }
20060 : : return 0;
20061 : : }
20062 : :
20063 : : /**
20064 : : * Validate the meter hierarchy chain for meter policy.
20065 : : *
20066 : : * @param[in] dev
20067 : : * Pointer to the Ethernet device structure.
20068 : : * @param[in] meter_id
20069 : : * Meter id.
20070 : : * @param[in] action_flags
20071 : : * Holds the actions detected until now.
20072 : : * @param[out] is_rss
20073 : : * Is RSS or not.
20074 : : * @param[out] hierarchy_domain
20075 : : * The domain bitmap for hierarchy policy.
20076 : : * @param[out] error
20077 : : * Perform verbose error reporting if not NULL. Initialized in case of
20078 : : * error only.
20079 : : *
20080 : : * @return
20081 : : * 0 on success, otherwise negative errno value with error set.
20082 : : */
20083 : : static int
20084 : 0 : flow_dv_validate_policy_mtr_hierarchy(struct rte_eth_dev *dev,
20085 : : uint32_t meter_id,
20086 : : uint64_t action_flags,
20087 : : bool *is_rss,
20088 : : uint8_t *hierarchy_domain,
20089 : : struct rte_mtr_error *error)
20090 : : {
20091 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
20092 : : struct mlx5_flow_meter_info *fm;
20093 : : struct mlx5_flow_meter_policy *policy;
20094 : : uint8_t cnt = 1;
20095 : :
20096 [ # # ]: 0 : if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
20097 : : MLX5_FLOW_FATE_ESWITCH_ACTIONS))
20098 : 0 : return -rte_mtr_error_set(error, EINVAL,
20099 : : RTE_MTR_ERROR_TYPE_POLICER_ACTION_GREEN,
20100 : : NULL,
20101 : : "Multiple fate actions not supported.");
20102 : 0 : *hierarchy_domain = 0;
20103 : 0 : fm = mlx5_flow_meter_find(priv, meter_id, NULL);
20104 : : while (true) {
20105 [ # # ]: 0 : if (!fm)
20106 : 0 : return -rte_mtr_error_set(error, EINVAL,
20107 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
20108 : : "Meter not found in meter hierarchy.");
20109 [ # # ]: 0 : if (fm->def_policy)
20110 : 0 : return -rte_mtr_error_set(error, EINVAL,
20111 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
20112 : : "Non termination meter not supported in hierarchy.");
20113 [ # # ]: 0 : if (!fm->shared)
20114 : 0 : return -rte_mtr_error_set(error, EINVAL,
20115 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
20116 : : "Only shared meter supported in hierarchy.");
20117 : 0 : policy = mlx5_flow_meter_policy_find(dev, fm->policy_id, NULL);
20118 : : MLX5_ASSERT(policy);
20119 : : /**
20120 : : * Only inherit the supported domains of the first meter in
20121 : : * hierarchy.
20122 : : * One meter supports at least one domain.
20123 : : */
20124 [ # # ]: 0 : if (!*hierarchy_domain) {
20125 [ # # ]: 0 : if (policy->transfer)
20126 : 0 : *hierarchy_domain |=
20127 : : MLX5_MTR_DOMAIN_TRANSFER_BIT;
20128 [ # # ]: 0 : if (policy->ingress)
20129 : 0 : *hierarchy_domain |=
20130 : : MLX5_MTR_DOMAIN_INGRESS_BIT;
20131 [ # # ]: 0 : if (policy->egress)
20132 : 0 : *hierarchy_domain |= MLX5_MTR_DOMAIN_EGRESS_BIT;
20133 : : }
20134 [ # # ]: 0 : if (!policy->is_hierarchy) {
20135 : 0 : *is_rss = policy->is_rss;
20136 : : break;
20137 : : }
20138 : 0 : rte_spinlock_lock(&policy->sl);
20139 : 0 : fm = mlx5_flow_meter_hierarchy_next_meter(priv, policy, NULL);
20140 : : rte_spinlock_unlock(&policy->sl);
20141 [ # # ]: 0 : if (++cnt >= MLX5_MTR_CHAIN_MAX_NUM)
20142 : 0 : return -rte_mtr_error_set(error, EINVAL,
20143 : : RTE_MTR_ERROR_TYPE_METER_POLICY, NULL,
20144 : : "Exceed max hierarchy meter number.");
20145 : : }
20146 : 0 : return 0;
20147 : : }
20148 : :
20149 : : /**
20150 : : * Validate meter policy actions.
20151 : : * Dispatcher for action type specific validation.
20152 : : *
20153 : : * @param[in] dev
20154 : : * Pointer to the Ethernet device structure.
20155 : : * @param[in] action
20156 : : * The meter policy action object to validate.
20157 : : * @param[in] attr
20158 : : * Attributes of flow to determine steering domain.
20159 : : * @param[out] error
20160 : : * Perform verbose error reporting if not NULL. Initialized in case of
20161 : : * error only.
20162 : : *
20163 : : * @return
20164 : : * 0 on success, otherwise negative errno value.
20165 : : */
20166 : : static int
20167 : 0 : flow_dv_validate_mtr_policy_acts(struct rte_eth_dev *dev,
20168 : : const struct rte_flow_action *actions[RTE_COLORS],
20169 : : struct rte_flow_attr *attr,
20170 : : bool *is_rss,
20171 : : uint8_t *domain_bitmap,
20172 : : uint8_t *policy_mode,
20173 : : struct rte_mtr_error *error)
20174 : : {
20175 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
20176 : 0 : struct mlx5_sh_config *dev_conf = &priv->sh->config;
20177 : : const struct rte_flow_action *act;
20178 : 0 : uint64_t action_flags[RTE_COLORS] = {0};
20179 : : int actions_n;
20180 : : int i, ret;
20181 : : struct rte_flow_error flow_err;
20182 : 0 : uint8_t domain_color[RTE_COLORS] = {0};
20183 : : uint8_t def_domain = MLX5_MTR_ALL_DOMAIN_BIT;
20184 : 0 : uint8_t hierarchy_domain = 0;
20185 : : const struct rte_flow_action_meter *mtr;
20186 : : const struct rte_flow_action_meter *next_mtr = NULL;
20187 : : bool def_green = false;
20188 : : bool def_yellow = false;
20189 : 0 : const struct rte_flow_action_rss *rss_color[RTE_COLORS] = {NULL};
20190 : : /* Called from RTE API */
20191 [ # # # # : 0 : bool is_root = !(attr->group || (attr->transfer && priv->fdb_def_rule));
# # ]
20192 : :
20193 [ # # ]: 0 : if (!dev_conf->dv_esw_en)
20194 : : def_domain &= ~MLX5_MTR_DOMAIN_TRANSFER_BIT;
20195 : 0 : *domain_bitmap = def_domain;
20196 : : /* Red color could only support DROP action. */
20197 [ # # ]: 0 : if (!actions[RTE_COLOR_RED] ||
20198 [ # # ]: 0 : actions[RTE_COLOR_RED]->type != RTE_FLOW_ACTION_TYPE_DROP)
20199 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20200 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20201 : : NULL, "Red color only supports drop action.");
20202 : : /*
20203 : : * Check default policy actions:
20204 : : * Green / Yellow: no action, Red: drop action
20205 : : * Either G or Y will trigger default policy actions to be created.
20206 : : */
20207 [ # # ]: 0 : if (!actions[RTE_COLOR_GREEN] ||
20208 [ # # ]: 0 : actions[RTE_COLOR_GREEN]->type == RTE_FLOW_ACTION_TYPE_END)
20209 : : def_green = true;
20210 [ # # ]: 0 : if (!actions[RTE_COLOR_YELLOW] ||
20211 [ # # ]: 0 : actions[RTE_COLOR_YELLOW]->type == RTE_FLOW_ACTION_TYPE_END)
20212 : : def_yellow = true;
20213 [ # # ]: 0 : if (def_green && def_yellow) {
20214 : 0 : *policy_mode = MLX5_MTR_POLICY_MODE_DEF;
20215 : 0 : return 0;
20216 [ # # ]: 0 : } else if (!def_green && def_yellow) {
20217 : 0 : *policy_mode = MLX5_MTR_POLICY_MODE_OG;
20218 [ # # ]: 0 : } else if (def_green && !def_yellow) {
20219 : 0 : *policy_mode = MLX5_MTR_POLICY_MODE_OY;
20220 : : } else {
20221 : 0 : *policy_mode = MLX5_MTR_POLICY_MODE_ALL;
20222 : : }
20223 : : /* Set to empty string in case of NULL pointer access by user. */
20224 : 0 : flow_err.message = "";
20225 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
20226 : 0 : act = actions[i];
20227 : 0 : for (action_flags[i] = 0, actions_n = 0;
20228 [ # # # # ]: 0 : act && act->type != RTE_FLOW_ACTION_TYPE_END;
20229 : 0 : act++) {
20230 [ # # ]: 0 : if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
20231 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20232 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20233 : : NULL, "too many actions");
20234 [ # # # # : 0 : switch (act->type) {
# # # # #
# ]
20235 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
20236 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
20237 [ # # ]: 0 : if (!dev_conf->dv_esw_en)
20238 : 0 : return -rte_mtr_error_set(error,
20239 : : ENOTSUP,
20240 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20241 : : NULL, "PORT action validate check"
20242 : : " fail for ESW disable");
20243 : 0 : ret = flow_dv_validate_action_port_id(dev,
20244 : : action_flags[i],
20245 : : act, attr, &flow_err);
20246 [ # # ]: 0 : if (ret)
20247 : 0 : return -rte_mtr_error_set(error,
20248 : : ENOTSUP,
20249 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20250 [ # # ]: 0 : NULL, flow_err.message ?
20251 : : flow_err.message :
20252 : : "PORT action validate check fail");
20253 : 0 : ++actions_n;
20254 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_PORT_ID;
20255 : 0 : break;
20256 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
20257 : 0 : ret = flow_dv_validate_action_mark(dev, act,
20258 : : action_flags[i],
20259 : : attr, &flow_err);
20260 [ # # ]: 0 : if (ret < 0)
20261 : 0 : return -rte_mtr_error_set(error,
20262 : : ENOTSUP,
20263 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20264 [ # # ]: 0 : NULL, flow_err.message ?
20265 : : flow_err.message :
20266 : : "Mark action validate check fail");
20267 [ # # ]: 0 : if (dev_conf->dv_xmeta_en !=
20268 : : MLX5_XMETA_MODE_LEGACY)
20269 : 0 : return -rte_mtr_error_set(error,
20270 : : ENOTSUP,
20271 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20272 : : NULL, "Extend MARK action is "
20273 : : "not supported. Please try use "
20274 : : "default policy for meter.");
20275 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_MARK;
20276 : 0 : ++actions_n;
20277 : 0 : break;
20278 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TAG:
20279 : 0 : ret = flow_dv_validate_action_set_tag(dev,
20280 : : act, action_flags[i],
20281 : : attr, &flow_err);
20282 [ # # ]: 0 : if (ret)
20283 : 0 : return -rte_mtr_error_set(error,
20284 : : ENOTSUP,
20285 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20286 [ # # ]: 0 : NULL, flow_err.message ?
20287 : : flow_err.message :
20288 : : "Set tag action validate check fail");
20289 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_SET_TAG;
20290 : 0 : ++actions_n;
20291 : 0 : break;
20292 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
20293 : 0 : ret = mlx5_flow_validate_action_drop
20294 : : (dev, false, attr, &flow_err);
20295 [ # # ]: 0 : if (ret < 0)
20296 : 0 : return -rte_mtr_error_set(error,
20297 : : ENOTSUP,
20298 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20299 [ # # ]: 0 : NULL, flow_err.message ?
20300 : : flow_err.message :
20301 : : "Drop action validate check fail");
20302 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_DROP;
20303 : 0 : ++actions_n;
20304 : 0 : break;
20305 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
20306 : : /*
20307 : : * Check whether extensive
20308 : : * metadata feature is engaged.
20309 : : */
20310 [ # # ]: 0 : if (dev_conf->dv_flow_en &&
20311 [ # # ]: 0 : (dev_conf->dv_xmeta_en !=
20312 [ # # ]: 0 : MLX5_XMETA_MODE_LEGACY) &&
20313 : 0 : mlx5_flow_ext_mreg_supported(dev))
20314 : 0 : return -rte_mtr_error_set(error,
20315 : : ENOTSUP,
20316 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20317 : : NULL, "Queue action with meta "
20318 : : "is not supported. Please try use "
20319 : : "default policy for meter.");
20320 : 0 : ret = mlx5_flow_validate_action_queue(act,
20321 : : action_flags[i], dev,
20322 : : attr, &flow_err);
20323 [ # # ]: 0 : if (ret < 0)
20324 : 0 : return -rte_mtr_error_set(error,
20325 : : ENOTSUP,
20326 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20327 [ # # ]: 0 : NULL, flow_err.message ?
20328 : : flow_err.message :
20329 : : "Queue action validate check fail");
20330 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_QUEUE;
20331 : 0 : ++actions_n;
20332 : 0 : break;
20333 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
20334 [ # # ]: 0 : if (dev_conf->dv_flow_en &&
20335 [ # # ]: 0 : (dev_conf->dv_xmeta_en !=
20336 [ # # ]: 0 : MLX5_XMETA_MODE_LEGACY) &&
20337 : 0 : mlx5_flow_ext_mreg_supported(dev))
20338 : 0 : return -rte_mtr_error_set(error,
20339 : : ENOTSUP,
20340 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20341 : : NULL, "RSS action with meta "
20342 : : "is not supported. Please try use "
20343 : : "default policy for meter.");
20344 : 0 : ret = mlx5_validate_action_rss(dev, act,
20345 : : &flow_err);
20346 [ # # ]: 0 : if (ret < 0)
20347 : 0 : return -rte_mtr_error_set(error,
20348 : : ENOTSUP,
20349 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20350 [ # # ]: 0 : NULL, flow_err.message ?
20351 : : flow_err.message :
20352 : : "RSS action validate check fail");
20353 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_RSS;
20354 : 0 : ++actions_n;
20355 : : /* Either G or Y will set the RSS. */
20356 : 0 : rss_color[i] = act->conf;
20357 : 0 : break;
20358 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
20359 : 0 : ret = flow_dv_validate_action_jump(dev,
20360 : : NULL, act, action_flags[i],
20361 : : attr, true, &flow_err);
20362 [ # # ]: 0 : if (ret)
20363 : 0 : return -rte_mtr_error_set(error,
20364 : : ENOTSUP,
20365 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20366 [ # # ]: 0 : NULL, flow_err.message ?
20367 : : flow_err.message :
20368 : : "Jump action validate check fail");
20369 : 0 : ++actions_n;
20370 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_JUMP;
20371 : 0 : break;
20372 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
20373 : 0 : mtr = act->conf;
20374 [ # # # # ]: 0 : if (next_mtr && next_mtr->mtr_id != mtr->mtr_id)
20375 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20376 : : RTE_MTR_ERROR_TYPE_METER_POLICY, NULL,
20377 : : "Green and Yellow must use the same meter.");
20378 : 0 : ret = flow_dv_validate_policy_mtr_hierarchy(dev,
20379 : 0 : mtr->mtr_id,
20380 : : action_flags[i],
20381 : : is_rss,
20382 : : &hierarchy_domain,
20383 : : error);
20384 [ # # ]: 0 : if (ret)
20385 : 0 : return ret;
20386 : 0 : ++actions_n;
20387 : 0 : action_flags[i] |=
20388 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
20389 : : next_mtr = mtr;
20390 : 0 : break;
20391 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
20392 : 0 : ret = flow_dv_validate_action_modify_field(dev,
20393 : : action_flags[i], act, attr, is_root, &flow_err);
20394 [ # # ]: 0 : if (ret < 0)
20395 : 0 : return -rte_mtr_error_set(error,
20396 : : ENOTSUP,
20397 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20398 [ # # ]: 0 : NULL, flow_err.message ?
20399 : : flow_err.message :
20400 : : "Modify field action validate check fail");
20401 : 0 : ++actions_n;
20402 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_MODIFY_FIELD;
20403 : 0 : break;
20404 : : default:
20405 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20406 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20407 : : NULL,
20408 : : "Doesn't support optional action");
20409 : : }
20410 : : }
20411 [ # # ]: 0 : if (action_flags[i] & MLX5_FLOW_ACTION_PORT_ID) {
20412 : 0 : domain_color[i] = MLX5_MTR_DOMAIN_TRANSFER_BIT;
20413 [ # # ]: 0 : } else if ((action_flags[i] &
20414 : 0 : (MLX5_FLOW_ACTION_RSS | MLX5_FLOW_ACTION_QUEUE)) ||
20415 [ # # ]: 0 : (action_flags[i] & MLX5_FLOW_ACTION_MARK)) {
20416 : : /*
20417 : : * Only support MLX5_XMETA_MODE_LEGACY
20418 : : * so MARK action is only in ingress domain.
20419 : : */
20420 : 0 : domain_color[i] = MLX5_MTR_DOMAIN_INGRESS_BIT;
20421 : : } else {
20422 : 0 : domain_color[i] = def_domain;
20423 [ # # ]: 0 : if (action_flags[i] &&
20424 [ # # ]: 0 : !(action_flags[i] & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
20425 : 0 : domain_color[i] &=
20426 : : ~MLX5_MTR_DOMAIN_TRANSFER_BIT;
20427 : : }
20428 [ # # ]: 0 : if (action_flags[i] &
20429 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
20430 : 0 : domain_color[i] &= hierarchy_domain;
20431 : : /*
20432 : : * Non-termination actions only support NIC Tx domain.
20433 : : * The adjustion should be skipped when there is no
20434 : : * action or only END is provided. The default domains
20435 : : * bit-mask is set to find the MIN intersection.
20436 : : * The action flags checking should also be skipped.
20437 : : */
20438 [ # # ]: 0 : if ((def_green && i == RTE_COLOR_GREEN) ||
20439 [ # # ]: 0 : (def_yellow && i == RTE_COLOR_YELLOW))
20440 : 0 : continue;
20441 : : /*
20442 : : * Validate the drop action mutual exclusion
20443 : : * with other actions. Drop action is mutually-exclusive
20444 : : * with any other action, except for Count action.
20445 : : */
20446 [ # # ]: 0 : if ((action_flags[i] & MLX5_FLOW_ACTION_DROP) &&
20447 [ # # ]: 0 : (action_flags[i] & ~MLX5_FLOW_ACTION_DROP)) {
20448 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20449 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20450 : : NULL, "Drop action is mutually-exclusive "
20451 : : "with any other action");
20452 : : }
20453 : : /* Eswitch has few restrictions on using items and actions */
20454 [ # # ]: 0 : if (domain_color[i] & MLX5_MTR_DOMAIN_TRANSFER_BIT) {
20455 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev) &&
20456 [ # # ]: 0 : action_flags[i] & MLX5_FLOW_ACTION_MARK)
20457 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20458 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20459 : : NULL, "unsupported action MARK");
20460 [ # # ]: 0 : if (action_flags[i] & MLX5_FLOW_ACTION_QUEUE)
20461 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20462 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20463 : : NULL, "unsupported action QUEUE");
20464 [ # # ]: 0 : if (action_flags[i] & MLX5_FLOW_ACTION_RSS)
20465 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20466 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20467 : : NULL, "unsupported action RSS");
20468 [ # # ]: 0 : if (!(action_flags[i] & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
20469 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20470 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20471 : : NULL, "no fate action is found");
20472 : : } else {
20473 [ # # # # ]: 0 : if (!(action_flags[i] & MLX5_FLOW_FATE_ACTIONS) &&
20474 : : (domain_color[i] & MLX5_MTR_DOMAIN_INGRESS_BIT)) {
20475 [ # # ]: 0 : if ((domain_color[i] &
20476 : : MLX5_MTR_DOMAIN_EGRESS_BIT))
20477 : 0 : domain_color[i] =
20478 : : MLX5_MTR_DOMAIN_EGRESS_BIT;
20479 : : else
20480 : 0 : return -rte_mtr_error_set(error,
20481 : : ENOTSUP,
20482 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20483 : : NULL,
20484 : : "no fate action is found");
20485 : : }
20486 : : }
20487 : : }
20488 [ # # # # ]: 0 : if (next_mtr && *policy_mode == MLX5_MTR_POLICY_MODE_ALL) {
20489 : : uint64_t hierarchy_type_flag =
20490 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY | MLX5_FLOW_ACTION_JUMP;
20491 [ # # ]: 0 : if (!(action_flags[RTE_COLOR_GREEN] & hierarchy_type_flag) ||
20492 [ # # ]: 0 : !(action_flags[RTE_COLOR_YELLOW] & hierarchy_type_flag))
20493 : 0 : return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_METER_POLICY,
20494 : : NULL,
20495 : : "Unsupported action in meter hierarchy.");
20496 : : }
20497 : : /* If both colors have RSS, the attributes should be the same. */
20498 [ # # ]: 0 : if (flow_dv_mtr_policy_rss_compare(rss_color[RTE_COLOR_GREEN],
20499 : : rss_color[RTE_COLOR_YELLOW]))
20500 : 0 : return -rte_mtr_error_set(error, EINVAL,
20501 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20502 : : NULL, "policy RSS attr conflict");
20503 [ # # # # ]: 0 : if (rss_color[RTE_COLOR_GREEN] || rss_color[RTE_COLOR_YELLOW])
20504 : 0 : *is_rss = true;
20505 : : /* "domain_color[C]" is non-zero for each color, default is ALL. */
20506 [ # # ]: 0 : if (!def_green && !def_yellow &&
20507 [ # # ]: 0 : domain_color[RTE_COLOR_GREEN] != domain_color[RTE_COLOR_YELLOW] &&
20508 [ # # ]: 0 : !(action_flags[RTE_COLOR_GREEN] & MLX5_FLOW_ACTION_DROP) &&
20509 [ # # ]: 0 : !(action_flags[RTE_COLOR_YELLOW] & MLX5_FLOW_ACTION_DROP))
20510 : 0 : return -rte_mtr_error_set(error, EINVAL,
20511 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20512 : : NULL, "policy domains conflict");
20513 : : /*
20514 : : * At least one color policy is listed in the actions, the domains
20515 : : * to be supported should be the intersection.
20516 : : */
20517 : 0 : *domain_bitmap = domain_color[RTE_COLOR_GREEN] &
20518 : 0 : domain_color[RTE_COLOR_YELLOW];
20519 : 0 : return 0;
20520 : : }
20521 : :
20522 : : static int
20523 : 0 : flow_dv_sync_domain(struct rte_eth_dev *dev, uint32_t domains, uint32_t flags)
20524 : : {
20525 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
20526 : : int ret = 0;
20527 : :
20528 [ # # # # ]: 0 : if ((domains & RTE_PMD_MLX5_DOMAIN_BIT_NIC_RX) && priv->sh->rx_domain != NULL) {
20529 : : ret = mlx5_os_flow_dr_sync_domain(priv->sh->rx_domain,
20530 : : flags);
20531 [ # # ]: 0 : if (ret != 0)
20532 : : return ret;
20533 : : }
20534 [ # # # # ]: 0 : if ((domains & RTE_PMD_MLX5_DOMAIN_BIT_NIC_TX) && priv->sh->tx_domain != NULL) {
20535 : : ret = mlx5_os_flow_dr_sync_domain(priv->sh->tx_domain, flags);
20536 [ # # ]: 0 : if (ret != 0)
20537 : : return ret;
20538 : : }
20539 [ # # # # ]: 0 : if ((domains & RTE_PMD_MLX5_DOMAIN_BIT_FDB) && priv->sh->fdb_domain != NULL) {
20540 : : ret = mlx5_os_flow_dr_sync_domain(priv->sh->fdb_domain, flags);
20541 [ # # ]: 0 : if (ret != 0)
20542 : 0 : return ret;
20543 : : }
20544 : : return 0;
20545 : : }
20546 : :
20547 : : /**
20548 : : * Discover the number of available flow priorities
20549 : : * by trying to create a flow with the highest priority value
20550 : : * for each possible number.
20551 : : *
20552 : : * @param[in] dev
20553 : : * Ethernet device.
20554 : : * @param[in] vprio
20555 : : * List of possible number of available priorities.
20556 : : * @param[in] vprio_n
20557 : : * Size of @p vprio array.
20558 : : * @return
20559 : : * On success, number of available flow priorities.
20560 : : * On failure, a negative errno-style code and rte_errno is set.
20561 : : */
20562 : : static int
20563 : 0 : flow_dv_discover_priorities(struct rte_eth_dev *dev,
20564 : : const uint16_t *vprio, int vprio_n)
20565 : : {
20566 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
20567 : 0 : struct mlx5_indexed_pool *pool = priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW];
20568 : : struct rte_flow_item_eth eth;
20569 : 0 : struct rte_flow_item item = {
20570 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
20571 : : .spec = ð,
20572 : : .mask = ð,
20573 : : };
20574 : 0 : struct mlx5_flow_dv_matcher matcher = {
20575 : : .mask = {
20576 : : .size = sizeof(matcher.mask.buf),
20577 : : },
20578 : : };
20579 : : union mlx5_flow_tbl_key tbl_key;
20580 : : struct mlx5_flow flow;
20581 : : void *action;
20582 : : struct rte_flow_error error;
20583 : : uint8_t misc_mask;
20584 : : int i, err, ret = -ENOTSUP;
20585 : :
20586 : : /*
20587 : : * Prepare a flow with a catch-all pattern and a drop action.
20588 : : * Use drop queue, because shared drop action may be unavailable.
20589 : : */
20590 : 0 : action = priv->drop_queue.hrxq->action;
20591 [ # # ]: 0 : if (action == NULL) {
20592 : 0 : DRV_LOG(ERR, "Priority discovery requires a drop action");
20593 : 0 : rte_errno = ENOTSUP;
20594 : 0 : return -rte_errno;
20595 : : }
20596 : : memset(&flow, 0, sizeof(flow));
20597 : 0 : flow.handle = mlx5_ipool_zmalloc(pool, &flow.handle_idx);
20598 [ # # ]: 0 : if (flow.handle == NULL) {
20599 : 0 : DRV_LOG(ERR, "Cannot create flow handle");
20600 : 0 : rte_errno = ENOMEM;
20601 : 0 : return -rte_errno;
20602 : : }
20603 : 0 : flow.ingress = true;
20604 : 0 : flow.dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param);
20605 : 0 : flow.dv.actions[0] = action;
20606 : 0 : flow.dv.actions_n = 1;
20607 : : memset(ð, 0, sizeof(eth));
20608 : 0 : flow_dv_translate_item_eth(matcher.mask.buf, &item,
20609 : : /* inner */ false, /* group */ 0,
20610 : : MLX5_SET_MATCHER_SW_M);
20611 : 0 : flow_dv_translate_item_eth(flow.dv.value.buf, &item,
20612 : : /* inner */ false, /* group */ 0,
20613 : : MLX5_SET_MATCHER_SW_V);
20614 : 0 : matcher.crc = rte_raw_cksum(matcher.mask.buf, matcher.mask.size);
20615 [ # # ]: 0 : for (i = 0; i < vprio_n; i++) {
20616 : : /* Configure the next proposed maximum priority. */
20617 : 0 : matcher.priority = vprio[i] - 1;
20618 : : memset(&tbl_key, 0, sizeof(tbl_key));
20619 : 0 : err = flow_dv_matcher_register(dev, &matcher, &tbl_key, &flow,
20620 : : /* tunnel */ NULL,
20621 : : /* group */ 0,
20622 : : &error);
20623 [ # # ]: 0 : if (err != 0) {
20624 : : /* This action is pure SW and must always succeed. */
20625 : 0 : DRV_LOG(ERR, "Cannot register matcher");
20626 : 0 : ret = -rte_errno;
20627 : 0 : break;
20628 : : }
20629 : : /* Try to apply the flow to HW. */
20630 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(flow.handle->dvh.matcher->mask.buf);
20631 : : __flow_dv_adjust_buf_size(&flow.dv.value.size, misc_mask);
20632 : 0 : err = mlx5_flow_os_create_flow
20633 : : (flow.handle->dvh.matcher->matcher_object,
20634 : 0 : (void *)&flow.dv.value, flow.dv.actions_n,
20635 : : flow.dv.actions, &flow.handle->drv_flow);
20636 : : if (err == 0) {
20637 : 0 : claim_zero(mlx5_flow_os_destroy_flow
20638 : : (flow.handle->drv_flow));
20639 : 0 : flow.handle->drv_flow = NULL;
20640 : : }
20641 : 0 : claim_zero(flow_dv_matcher_release(dev, flow.handle));
20642 [ # # ]: 0 : if (err != 0)
20643 : : break;
20644 : 0 : ret = vprio[i];
20645 : : }
20646 : 0 : mlx5_ipool_free(pool, flow.handle_idx);
20647 : : /* Set rte_errno if no expected priority value matched. */
20648 [ # # ]: 0 : if (ret < 0)
20649 : 0 : rte_errno = -ret;
20650 : : return ret;
20651 : : }
20652 : :
20653 : : const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops = {
20654 : : .list_create = flow_legacy_list_create,
20655 : : .list_destroy = flow_legacy_list_destroy,
20656 : : .validate = flow_dv_validate,
20657 : : .prepare = flow_dv_prepare,
20658 : : .translate = flow_dv_translate,
20659 : : .apply = flow_dv_apply,
20660 : : .remove = flow_dv_remove,
20661 : : .destroy = flow_dv_destroy,
20662 : : .query = flow_dv_query,
20663 : : .create_mtr_tbls = flow_dv_create_mtr_tbls,
20664 : : .destroy_mtr_tbls = flow_dv_destroy_mtr_tbls,
20665 : : .destroy_mtr_drop_tbls = flow_dv_destroy_mtr_drop_tbls,
20666 : : .create_meter = flow_dv_mtr_alloc,
20667 : : .free_meter = flow_dv_aso_mtr_release_to_pool,
20668 : : .validate_mtr_acts = flow_dv_validate_mtr_policy_acts,
20669 : : .create_mtr_acts = flow_dv_create_mtr_policy_acts,
20670 : : .destroy_mtr_acts = flow_dv_destroy_mtr_policy_acts,
20671 : : .create_policy_rules = flow_dv_create_policy_rules,
20672 : : .destroy_policy_rules = flow_dv_destroy_policy_rules,
20673 : : .create_def_policy = flow_dv_create_def_policy,
20674 : : .destroy_def_policy = flow_dv_destroy_def_policy,
20675 : : .meter_sub_policy_rss_prepare = flow_dv_meter_sub_policy_rss_prepare,
20676 : : .meter_hierarchy_rule_create = flow_dv_meter_hierarchy_rule_create,
20677 : : .destroy_sub_policy_with_rxq = flow_dv_destroy_sub_policy_with_rxq,
20678 : : .counter_alloc = flow_dv_counter_allocate,
20679 : : .counter_free = flow_dv_counter_free,
20680 : : .counter_query = flow_dv_counter_query,
20681 : : .get_aged_flows = flow_dv_get_aged_flows,
20682 : : .action_validate = flow_dv_action_validate,
20683 : : .action_create = flow_dv_action_create,
20684 : : .action_destroy = flow_dv_action_destroy,
20685 : : .action_update = flow_dv_action_update,
20686 : : .action_query = flow_dv_action_query,
20687 : : .sync_domain = flow_dv_sync_domain,
20688 : : .discover_priorities = flow_dv_discover_priorities,
20689 : : .item_create = flow_dv_item_create,
20690 : : .item_release = flow_dv_item_release,
20691 : : };
20692 : :
20693 : : #endif /* HAVE_IBV_FLOW_DV_SUPPORT */
|