Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright 2018 Mellanox Technologies, Ltd
3 : : */
4 : :
5 : : #include <sys/queue.h>
6 : : #include <stdalign.h>
7 : : #include <stdint.h>
8 : : #include <string.h>
9 : : #include <unistd.h>
10 : :
11 : : #include <rte_bitops.h>
12 : : #include <rte_common.h>
13 : : #include <rte_ether.h>
14 : : #include <ethdev_driver.h>
15 : : #include <rte_flow.h>
16 : : #include <rte_flow_driver.h>
17 : : #include <rte_malloc.h>
18 : : #include <rte_cycles.h>
19 : : #include <bus_pci_driver.h>
20 : : #include <rte_ip.h>
21 : : #include <rte_gre.h>
22 : : #include <rte_vxlan.h>
23 : : #include <rte_gtp.h>
24 : : #include <rte_eal_paging.h>
25 : : #include <rte_mpls.h>
26 : : #include <rte_mtr.h>
27 : : #include <rte_mtr_driver.h>
28 : : #include <rte_tailq.h>
29 : :
30 : : #include <mlx5_glue.h>
31 : : #include <mlx5_devx_cmds.h>
32 : : #include <mlx5_prm.h>
33 : : #include <mlx5_malloc.h>
34 : :
35 : : #include "mlx5_defs.h"
36 : : #include "mlx5.h"
37 : : #include "mlx5_common_os.h"
38 : : #include "mlx5_flow.h"
39 : : #include "mlx5_flow_os.h"
40 : : #include "mlx5_rx.h"
41 : : #include "mlx5_tx.h"
42 : : #include "rte_pmd_mlx5.h"
43 : :
44 : : #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
45 : :
46 : : #ifndef HAVE_IBV_FLOW_DEVX_COUNTERS
47 : : #define MLX5DV_FLOW_ACTION_COUNTERS_DEVX 0
48 : : #endif
49 : :
50 : : #ifndef HAVE_MLX5DV_DR_ESWITCH
51 : : #ifndef MLX5DV_FLOW_TABLE_TYPE_FDB
52 : : #define MLX5DV_FLOW_TABLE_TYPE_FDB 0
53 : : #endif
54 : : #endif
55 : :
56 : : #ifndef HAVE_MLX5DV_DR
57 : : #define MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL 1
58 : : #endif
59 : :
60 : : /* VLAN header definitions */
61 : : #define MLX5DV_FLOW_VLAN_PCP_SHIFT 13
62 : : #define MLX5DV_FLOW_VLAN_PCP_MASK (0x7 << MLX5DV_FLOW_VLAN_PCP_SHIFT)
63 : : #define MLX5DV_FLOW_VLAN_VID_MASK 0x0fff
64 : : #define MLX5DV_FLOW_VLAN_PCP_MASK_BE RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK)
65 : : #define MLX5DV_FLOW_VLAN_VID_MASK_BE RTE_BE16(MLX5DV_FLOW_VLAN_VID_MASK)
66 : :
67 : : #define MLX5_ITEM_VALID(item, key_type) \
68 : : (((MLX5_SET_MATCHER_SW & (key_type)) && !((item)->spec)) || \
69 : : ((MLX5_SET_MATCHER_HS_V == (key_type)) && !((item)->spec)) || \
70 : : ((MLX5_SET_MATCHER_HS_M == (key_type)) && !((item)->mask)))
71 : :
72 : : #define MLX5_ITEM_UPDATE(item, key_type, v, m, gm) \
73 : : do { \
74 : : if ((key_type) == MLX5_SET_MATCHER_SW_V) { \
75 : : v = (item)->spec; \
76 : : m = (item)->mask ? (item)->mask : (gm); \
77 : : } else if ((key_type) == MLX5_SET_MATCHER_HS_V) { \
78 : : v = (item)->spec; \
79 : : m = (v); \
80 : : } else { \
81 : : v = (item)->mask ? (item)->mask : (gm); \
82 : : m = (v); \
83 : : } \
84 : : } while (0)
85 : :
86 : : #define CALC_MODI_ID(field, level) \
87 : : (((level) > 1) ? MLX5_MODI_IN_##field : MLX5_MODI_OUT_##field)
88 : :
89 : : union flow_dv_attr {
90 : : struct {
91 : : uint32_t valid:1;
92 : : uint32_t ipv4:1;
93 : : uint32_t ipv6:1;
94 : : uint32_t tcp:1;
95 : : uint32_t udp:1;
96 : : uint32_t reserved:27;
97 : : };
98 : : uint32_t attr;
99 : : };
100 : :
101 : : static int
102 : : flow_dv_port_id_action_resource_release(struct rte_eth_dev *dev,
103 : : uint32_t port_id);
104 : : static void
105 : : flow_dv_shared_rss_action_release(struct rte_eth_dev *dev, uint32_t srss);
106 : :
107 : : static int
108 : : flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev,
109 : : uint32_t rix_jump);
110 : :
111 : : /**
112 : : * Initialize flow attributes structure according to flow items' types.
113 : : *
114 : : * mlx5_flow_dv_validate() avoids multiple L3/L4 layers cases other than tunnel
115 : : * mode. For tunnel mode, the items to be modified are the outermost ones.
116 : : *
117 : : * @param[in] item
118 : : * Pointer to item specification.
119 : : * @param[out] attr
120 : : * Pointer to flow attributes structure.
121 : : * @param[in] dev_flow
122 : : * Pointer to the sub flow.
123 : : * @param[in] tunnel_decap
124 : : * Whether action is after tunnel decapsulation.
125 : : */
126 : : static void
127 : 0 : flow_dv_attr_init(const struct rte_flow_item *item, union flow_dv_attr *attr,
128 : : struct mlx5_flow *dev_flow, bool tunnel_decap)
129 : : {
130 : 0 : uint64_t layers = dev_flow->handle->layers;
131 : : bool tunnel_match = false;
132 : :
133 : : /*
134 : : * If layers is already initialized, it means this dev_flow is the
135 : : * suffix flow, the layers flags is set by the prefix flow. Need to
136 : : * use the layer flags from prefix flow as the suffix flow may not
137 : : * have the user defined items as the flow is split.
138 : : */
139 [ # # ]: 0 : if (layers) {
140 [ # # ]: 0 : if (tunnel_decap) {
141 : : /*
142 : : * If decap action before modify, it means the driver
143 : : * should take the inner as outer for the modify actions.
144 : : */
145 : 0 : layers = ((layers >> 6) & MLX5_FLOW_LAYER_OUTER);
146 : : }
147 [ # # ]: 0 : if (layers & MLX5_FLOW_LAYER_OUTER_L3_IPV4)
148 : 0 : attr->ipv4 = 1;
149 [ # # ]: 0 : else if (layers & MLX5_FLOW_LAYER_OUTER_L3_IPV6)
150 : 0 : attr->ipv6 = 1;
151 [ # # ]: 0 : if (layers & MLX5_FLOW_LAYER_OUTER_L4_TCP)
152 : 0 : attr->tcp = 1;
153 [ # # ]: 0 : else if (layers & MLX5_FLOW_LAYER_OUTER_L4_UDP)
154 : 0 : attr->udp = 1;
155 : 0 : attr->valid = 1;
156 : 0 : return;
157 : : }
158 [ # # ]: 0 : for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
159 : : uint8_t next_protocol = 0xff;
160 [ # # # # : 0 : switch (item->type) {
# # ]
161 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
162 : : case RTE_FLOW_ITEM_TYPE_NVGRE:
163 : : case RTE_FLOW_ITEM_TYPE_VXLAN:
164 : : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
165 : : case RTE_FLOW_ITEM_TYPE_GENEVE:
166 : : case RTE_FLOW_ITEM_TYPE_MPLS:
167 : : case RTE_FLOW_ITEM_TYPE_GTP:
168 [ # # ]: 0 : if (tunnel_decap) {
169 : 0 : attr->attr = 0;
170 : : tunnel_match = true;
171 : : }
172 : : break;
173 : 0 : case RTE_FLOW_ITEM_TYPE_IPV4:
174 [ # # ]: 0 : if (!attr->ipv6)
175 : 0 : attr->ipv4 = 1;
176 [ # # ]: 0 : if (item->mask != NULL &&
177 : : ((const struct rte_flow_item_ipv4 *)
178 [ # # ]: 0 : item->mask)->hdr.next_proto_id)
179 : 0 : next_protocol =
180 : : ((const struct rte_flow_item_ipv4 *)
181 : 0 : (item->spec))->hdr.next_proto_id &
182 : : ((const struct rte_flow_item_ipv4 *)
183 : : (item->mask))->hdr.next_proto_id;
184 : 0 : if ((next_protocol == IPPROTO_IPIP ||
185 [ # # ]: 0 : next_protocol == IPPROTO_IPV6) && tunnel_decap &&
186 [ # # ]: 0 : !tunnel_match)
187 : 0 : attr->attr = 0;
188 : : break;
189 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6:
190 [ # # ]: 0 : if (!attr->ipv4)
191 : 0 : attr->ipv6 = 1;
192 [ # # ]: 0 : if (item->mask != NULL &&
193 : : ((const struct rte_flow_item_ipv6 *)
194 [ # # ]: 0 : item->mask)->hdr.proto)
195 : 0 : next_protocol =
196 : : ((const struct rte_flow_item_ipv6 *)
197 : 0 : (item->spec))->hdr.proto &
198 : : ((const struct rte_flow_item_ipv6 *)
199 : : (item->mask))->hdr.proto;
200 : 0 : if ((next_protocol == IPPROTO_IPIP ||
201 [ # # ]: 0 : next_protocol == IPPROTO_IPV6) && tunnel_decap &&
202 [ # # ]: 0 : !tunnel_match)
203 : 0 : attr->attr = 0;
204 : : break;
205 : 0 : case RTE_FLOW_ITEM_TYPE_UDP:
206 [ # # ]: 0 : if (!attr->tcp)
207 : 0 : attr->udp = 1;
208 : : break;
209 : 0 : case RTE_FLOW_ITEM_TYPE_TCP:
210 [ # # ]: 0 : if (!attr->udp)
211 : 0 : attr->tcp = 1;
212 : : break;
213 : : default:
214 : : break;
215 : : }
216 : : }
217 : 0 : attr->valid = 1;
218 : : }
219 : :
220 : : static struct field_modify_info modify_eth[] = {
221 : : {4, 0, MLX5_MODI_OUT_DMAC_47_16},
222 : : {2, 4, MLX5_MODI_OUT_DMAC_15_0},
223 : : {4, 6, MLX5_MODI_OUT_SMAC_47_16},
224 : : {2, 10, MLX5_MODI_OUT_SMAC_15_0},
225 : : {0, 0, 0},
226 : : };
227 : :
228 : : static struct field_modify_info modify_vlan_out_first_vid[] = {
229 : : /* Size in bits !!! */
230 : : {12, 0, MLX5_MODI_OUT_FIRST_VID},
231 : : {0, 0, 0},
232 : : };
233 : :
234 : : static struct field_modify_info modify_ipv4[] = {
235 : : {1, 1, MLX5_MODI_OUT_IP_DSCP},
236 : : {1, 8, MLX5_MODI_OUT_IPV4_TTL},
237 : : {4, 12, MLX5_MODI_OUT_SIPV4},
238 : : {4, 16, MLX5_MODI_OUT_DIPV4},
239 : : {0, 0, 0},
240 : : };
241 : :
242 : : static struct field_modify_info modify_ipv6[] = {
243 : : {1, 0, MLX5_MODI_OUT_IP_DSCP},
244 : : {1, 7, MLX5_MODI_OUT_IPV6_HOPLIMIT},
245 : : {4, 8, MLX5_MODI_OUT_SIPV6_127_96},
246 : : {4, 12, MLX5_MODI_OUT_SIPV6_95_64},
247 : : {4, 16, MLX5_MODI_OUT_SIPV6_63_32},
248 : : {4, 20, MLX5_MODI_OUT_SIPV6_31_0},
249 : : {4, 24, MLX5_MODI_OUT_DIPV6_127_96},
250 : : {4, 28, MLX5_MODI_OUT_DIPV6_95_64},
251 : : {4, 32, MLX5_MODI_OUT_DIPV6_63_32},
252 : : {4, 36, MLX5_MODI_OUT_DIPV6_31_0},
253 : : {0, 0, 0},
254 : : };
255 : :
256 : : static struct field_modify_info modify_ipv6_traffic_class[] = {
257 : : {1, 0, MLX5_MODI_OUT_IPV6_TRAFFIC_CLASS},
258 : : {0, 0, 0},
259 : : };
260 : :
261 : : static struct field_modify_info modify_udp[] = {
262 : : {2, 0, MLX5_MODI_OUT_UDP_SPORT},
263 : : {2, 2, MLX5_MODI_OUT_UDP_DPORT},
264 : : {0, 0, 0},
265 : : };
266 : :
267 : : static struct field_modify_info modify_tcp[] = {
268 : : {2, 0, MLX5_MODI_OUT_TCP_SPORT},
269 : : {2, 2, MLX5_MODI_OUT_TCP_DPORT},
270 : : {4, 4, MLX5_MODI_OUT_TCP_SEQ_NUM},
271 : : {4, 8, MLX5_MODI_OUT_TCP_ACK_NUM},
272 : : {0, 0, 0},
273 : : };
274 : :
275 : : enum mlx5_l3_tunnel_detection {
276 : : l3_tunnel_none,
277 : : l3_tunnel_outer,
278 : : l3_tunnel_inner
279 : : };
280 : :
281 : : static enum mlx5_l3_tunnel_detection
282 : : mlx5_flow_tunnel_ip_check(const struct rte_flow_item *item __rte_unused,
283 : : uint8_t next_protocol, uint64_t item_flags,
284 : : uint64_t *l3_tunnel_flag)
285 : : {
286 : : enum mlx5_l3_tunnel_detection td = l3_tunnel_none;
287 : :
288 : : MLX5_ASSERT(item->type == RTE_FLOW_ITEM_TYPE_IPV4 ||
289 : : item->type == RTE_FLOW_ITEM_TYPE_IPV6);
290 [ # # # # : 0 : if ((item_flags & MLX5_FLOW_LAYER_OUTER_L3) == 0) {
# # # # ]
291 [ # # # # : 0 : switch (next_protocol) {
# # # # #
# # # ]
292 : : case IPPROTO_IPIP:
293 : : td = l3_tunnel_outer;
294 : : *l3_tunnel_flag = MLX5_FLOW_LAYER_IPIP;
295 : : break;
296 : : case IPPROTO_IPV6:
297 : : td = l3_tunnel_outer;
298 : : *l3_tunnel_flag = MLX5_FLOW_LAYER_IPV6_ENCAP;
299 : : break;
300 : : default:
301 : : break;
302 : : }
303 : : } else {
304 : : td = l3_tunnel_inner;
305 : : *l3_tunnel_flag = item->type == RTE_FLOW_ITEM_TYPE_IPV4 ?
306 : : MLX5_FLOW_LAYER_IPIP :
307 : : MLX5_FLOW_LAYER_IPV6_ENCAP;
308 : : }
309 : : return td;
310 : : }
311 : :
312 : : static inline struct mlx5_hlist *
313 : 0 : flow_dv_hlist_prepare(struct mlx5_dev_ctx_shared *sh, RTE_ATOMIC(struct mlx5_hlist *) *phl,
314 : : const char *name, uint32_t size, bool direct_key,
315 : : bool lcores_share, void *ctx,
316 : : mlx5_list_create_cb cb_create,
317 : : mlx5_list_match_cb cb_match,
318 : : mlx5_list_remove_cb cb_remove,
319 : : mlx5_list_clone_cb cb_clone,
320 : : mlx5_list_clone_free_cb cb_clone_free,
321 : : struct rte_flow_error *error)
322 : : {
323 : : struct mlx5_hlist *hl;
324 : : struct mlx5_hlist *expected = NULL;
325 : : char s[MLX5_NAME_SIZE];
326 : :
327 : 0 : hl = rte_atomic_load_explicit(phl, rte_memory_order_seq_cst);
328 [ # # ]: 0 : if (likely(hl))
329 : : return hl;
330 : 0 : snprintf(s, sizeof(s), "%s_%s", sh->ibdev_name, name);
331 : 0 : hl = mlx5_hlist_create(s, size, direct_key, lcores_share,
332 : : ctx, cb_create, cb_match, cb_remove, cb_clone,
333 : : cb_clone_free);
334 [ # # ]: 0 : if (!hl) {
335 : 0 : DRV_LOG(ERR, "%s hash creation failed", name);
336 : 0 : rte_flow_error_set(error, ENOMEM,
337 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
338 : : "cannot allocate resource memory");
339 : 0 : return NULL;
340 : : }
341 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(phl, &expected, hl,
342 : : rte_memory_order_seq_cst,
343 : : rte_memory_order_seq_cst)) {
344 : 0 : mlx5_hlist_destroy(hl);
345 : 0 : hl = rte_atomic_load_explicit(phl, rte_memory_order_seq_cst);
346 : : }
347 : : return hl;
348 : : }
349 : :
350 : : /* Update VLAN's VID/PCP based on input rte_flow_action.
351 : : *
352 : : * @param[in] action
353 : : * Pointer to struct rte_flow_action.
354 : : * @param[out] vlan
355 : : * Pointer to struct rte_vlan_hdr.
356 : : */
357 : : static void
358 : 0 : mlx5_update_vlan_vid_pcp(const struct rte_flow_action *action,
359 : : struct rte_vlan_hdr *vlan)
360 : : {
361 : : uint16_t vlan_tci;
362 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP) {
363 : 0 : vlan_tci =
364 : : ((const struct rte_flow_action_of_set_vlan_pcp *)
365 : 0 : action->conf)->vlan_pcp;
366 : 0 : vlan_tci = vlan_tci << MLX5DV_FLOW_VLAN_PCP_SHIFT;
367 : 0 : vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
368 : 0 : vlan->vlan_tci |= vlan_tci;
369 [ # # ]: 0 : } else if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID) {
370 : 0 : vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
371 [ # # ]: 0 : vlan->vlan_tci |= rte_be_to_cpu_16
372 : : (((const struct rte_flow_action_of_set_vlan_vid *)
373 : : action->conf)->vlan_vid);
374 : : }
375 : 0 : }
376 : :
377 : : /**
378 : : * Convert modify-header action to DV specification.
379 : : *
380 : : * Data length of each action is determined by provided field description
381 : : * and the item mask. Data bit offset and width of each action is determined
382 : : * by provided item mask.
383 : : *
384 : : * @param[in] item
385 : : * Pointer to item specification.
386 : : * @param[in] field
387 : : * Pointer to field modification information.
388 : : * For MLX5_MODIFICATION_TYPE_SET specifies destination field.
389 : : * For MLX5_MODIFICATION_TYPE_ADD specifies destination field.
390 : : * For MLX5_MODIFICATION_TYPE_COPY specifies source field.
391 : : * For MLX5_MODIFICATION_TYPE_ADD_FIELD specifies source field.
392 : : * @param[in] dest
393 : : * Destination field info for MLX5_MODIFICATION_TYPE_COPY and
394 : : * MLX5_MODIFICATION_TYPE_ADD_FIELD in @type.
395 : : * Negative offset value sets the same offset as source offset.
396 : : * size field is ignored, value is taken from source field.
397 : : * @param[in,out] resource
398 : : * Pointer to the modify-header resource.
399 : : * @param[in] type
400 : : * Type of modification.
401 : : * @param[out] error
402 : : * Pointer to the error structure.
403 : : *
404 : : * @return
405 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
406 : : */
407 : : int
408 : 0 : mlx5_flow_dv_convert_modify_action(struct rte_flow_item *item,
409 : : struct field_modify_info *field,
410 : : struct field_modify_info *dest,
411 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
412 : : uint32_t type, struct rte_flow_error *error)
413 : : {
414 : 0 : uint32_t i = resource->actions_num;
415 : 0 : struct mlx5_modification_cmd *actions = resource->actions;
416 : : uint32_t carry_b = 0;
417 : : bool to_dest;
418 : :
419 : : /*
420 : : * The item and mask are provided in big-endian format.
421 : : * The fields should be presented as in big-endian format either.
422 : : * Mask must be always present, it defines the actual field width.
423 : : */
424 : : MLX5_ASSERT(item->mask);
425 : : MLX5_ASSERT(field->size);
426 : 0 : to_dest = type == MLX5_MODIFICATION_TYPE_COPY ||
427 : 0 : type == MLX5_MODIFICATION_TYPE_ADD_FIELD;
428 : : do {
429 : : uint32_t size_b;
430 : : uint32_t off_b;
431 : : uint32_t mask;
432 : : uint32_t data;
433 : : bool next_field = true;
434 : : bool next_dest = true;
435 : :
436 [ # # ]: 0 : if (i >= MLX5_MAX_MODIFY_NUM)
437 : 0 : return rte_flow_error_set(error, EINVAL,
438 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
439 : : "too many items to modify");
440 : : /* Fetch variable byte size mask from the array. */
441 : 0 : mask = flow_dv_fetch_field((const uint8_t *)item->mask +
442 : 0 : field->offset, field->size);
443 [ # # ]: 0 : if (!mask) {
444 : 0 : ++field;
445 : : continue;
446 : : }
447 [ # # # # ]: 0 : if (to_dest && field->is_flex) {
448 : 0 : off_b = 32 - field->shift + carry_b - field->size * CHAR_BIT;
449 : 0 : size_b = field->size * CHAR_BIT - carry_b;
450 : : } else {
451 : : /* Deduce actual data width in bits from mask value. */
452 : 0 : off_b = rte_bsf32(mask) + carry_b;
453 : 0 : size_b = sizeof(uint32_t) * CHAR_BIT -
454 : 0 : off_b - rte_clz32(mask);
455 : : }
456 : : MLX5_ASSERT(size_b);
457 : 0 : actions[i] = (struct mlx5_modification_cmd) {
458 : : .action_type = type,
459 : 0 : .field = field->id,
460 : : .offset = off_b,
461 : : .length = (size_b == sizeof(uint32_t) * CHAR_BIT) ?
462 [ # # ]: 0 : 0 : size_b,
463 : : };
464 [ # # ]: 0 : if (to_dest) {
465 : : MLX5_ASSERT(dest);
466 : 0 : actions[i].dst_field = dest->id;
467 : 0 : actions[i].dst_offset =
468 [ # # ]: 0 : (int)dest->offset < 0 ? off_b : dest->offset;
469 : : /* Convert entire record to big-endian format. */
470 [ # # ]: 0 : actions[i].data1 = rte_cpu_to_be_32(actions[i].data1);
471 : : /*
472 : : * Destination field overflow. Copy leftovers of
473 : : * a source field to the next destination field.
474 : : */
475 [ # # # # ]: 0 : if ((size_b > dest->size * CHAR_BIT - dest->offset) &&
476 : : dest->size != 0) {
477 : 0 : actions[i].length =
478 : 0 : dest->size * CHAR_BIT - dest->offset;
479 : 0 : carry_b += actions[i].length;
480 : 0 : next_field = false;
481 : : } else {
482 : : carry_b = 0;
483 : : }
484 : : /*
485 : : * Not enough bits in a source filed to fill a
486 : : * destination field. Switch to the next source.
487 : : */
488 [ # # ]: 0 : if ((size_b < dest->size * CHAR_BIT - dest->offset) &&
489 [ # # ]: 0 : ((size_b == field->size * CHAR_BIT - off_b) ||
490 [ # # ]: 0 : field->is_flex)) {
491 : 0 : actions[i].length = size_b;
492 : 0 : dest->offset += actions[i].length;
493 : : next_dest = false;
494 : : }
495 : : } else {
496 : : MLX5_ASSERT(item->spec);
497 : 0 : data = flow_dv_fetch_field((const uint8_t *)item->spec +
498 : : field->offset, field->size);
499 : : /* Shift out the trailing masked bits from data. */
500 : 0 : data = (data & mask) >> off_b;
501 [ # # ]: 0 : if (field->is_flex)
502 : 0 : actions[i].offset = 32 - field->shift - field->size * CHAR_BIT;
503 [ # # ]: 0 : actions[i].data1 = rte_cpu_to_be_32(data);
504 : : }
505 : : /* Convert entire record to expected big-endian format. */
506 [ # # ]: 0 : actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
507 [ # # ]: 0 : if ((!to_dest ||
508 [ # # # # ]: 0 : dest->id != (enum mlx5_modification_field)UINT32_MAX) &&
509 : : field->id != (enum mlx5_modification_field)UINT32_MAX)
510 : 0 : ++i;
511 [ # # ]: 0 : if (next_dest && to_dest)
512 : 0 : ++dest;
513 [ # # ]: 0 : if (next_field)
514 : 0 : ++field;
515 [ # # ]: 0 : } while (field->size);
516 [ # # ]: 0 : if (resource->actions_num == i)
517 : 0 : return rte_flow_error_set(error, EINVAL,
518 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
519 : : "invalid modification flow item");
520 : 0 : resource->actions_num = i;
521 : 0 : return 0;
522 : : }
523 : :
524 : : /**
525 : : * Convert modify-header set IPv4 address action to DV specification.
526 : : *
527 : : * @param[in,out] resource
528 : : * Pointer to the modify-header resource.
529 : : * @param[in] action
530 : : * Pointer to action specification.
531 : : * @param[out] error
532 : : * Pointer to the error structure.
533 : : *
534 : : * @return
535 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
536 : : */
537 : : static int
538 : 0 : flow_dv_convert_action_modify_ipv4
539 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
540 : : const struct rte_flow_action *action,
541 : : struct rte_flow_error *error)
542 : : {
543 : 0 : const struct rte_flow_action_set_ipv4 *conf =
544 : : (const struct rte_flow_action_set_ipv4 *)(action->conf);
545 [ # # ]: 0 : struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
546 : : struct rte_flow_item_ipv4 ipv4;
547 : : struct rte_flow_item_ipv4 ipv4_mask;
548 : :
549 : : memset(&ipv4, 0, sizeof(ipv4));
550 : : memset(&ipv4_mask, 0, sizeof(ipv4_mask));
551 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC) {
552 : 0 : ipv4.hdr.src_addr = conf->ipv4_addr;
553 : 0 : ipv4_mask.hdr.src_addr = rte_flow_item_ipv4_mask.hdr.src_addr;
554 : : } else {
555 : 0 : ipv4.hdr.dst_addr = conf->ipv4_addr;
556 : 0 : ipv4_mask.hdr.dst_addr = rte_flow_item_ipv4_mask.hdr.dst_addr;
557 : : }
558 : 0 : item.spec = &ipv4;
559 : 0 : item.mask = &ipv4_mask;
560 : 0 : return mlx5_flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
561 : : MLX5_MODIFICATION_TYPE_SET, error);
562 : : }
563 : :
564 : : /**
565 : : * Convert modify-header set IPv6 address action to DV specification.
566 : : *
567 : : * @param[in,out] resource
568 : : * Pointer to the modify-header resource.
569 : : * @param[in] action
570 : : * Pointer to action specification.
571 : : * @param[out] error
572 : : * Pointer to the error structure.
573 : : *
574 : : * @return
575 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
576 : : */
577 : : static int
578 : 0 : flow_dv_convert_action_modify_ipv6
579 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
580 : : const struct rte_flow_action *action,
581 : : struct rte_flow_error *error)
582 : : {
583 : 0 : const struct rte_flow_action_set_ipv6 *conf =
584 : : (const struct rte_flow_action_set_ipv6 *)(action->conf);
585 [ # # ]: 0 : struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
586 : : struct rte_flow_item_ipv6 ipv6;
587 : : struct rte_flow_item_ipv6 ipv6_mask;
588 : :
589 : : memset(&ipv6, 0, sizeof(ipv6));
590 : : memset(&ipv6_mask, 0, sizeof(ipv6_mask));
591 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC) {
592 : : memcpy(&ipv6.hdr.src_addr, &conf->ipv6_addr,
593 : : sizeof(ipv6.hdr.src_addr));
594 : : memcpy(&ipv6_mask.hdr.src_addr,
595 : : &rte_flow_item_ipv6_mask.hdr.src_addr,
596 : : sizeof(ipv6.hdr.src_addr));
597 : : } else {
598 : : memcpy(&ipv6.hdr.dst_addr, &conf->ipv6_addr,
599 : : sizeof(ipv6.hdr.dst_addr));
600 : : memcpy(&ipv6_mask.hdr.dst_addr,
601 : : &rte_flow_item_ipv6_mask.hdr.dst_addr,
602 : : sizeof(ipv6.hdr.dst_addr));
603 : : }
604 : 0 : item.spec = &ipv6;
605 : 0 : item.mask = &ipv6_mask;
606 : 0 : return mlx5_flow_dv_convert_modify_action(&item, modify_ipv6, NULL, resource,
607 : : MLX5_MODIFICATION_TYPE_SET, error);
608 : : }
609 : :
610 : : /**
611 : : * Convert modify-header set MAC address action to DV specification.
612 : : *
613 : : * @param[in,out] resource
614 : : * Pointer to the modify-header resource.
615 : : * @param[in] action
616 : : * Pointer to action specification.
617 : : * @param[out] error
618 : : * Pointer to the error structure.
619 : : *
620 : : * @return
621 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
622 : : */
623 : : static int
624 : 0 : flow_dv_convert_action_modify_mac
625 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
626 : : const struct rte_flow_action *action,
627 : : struct rte_flow_error *error)
628 : : {
629 : 0 : const struct rte_flow_action_set_mac *conf =
630 : : (const struct rte_flow_action_set_mac *)(action->conf);
631 [ # # ]: 0 : struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_ETH };
632 : : struct rte_flow_item_eth eth;
633 : : struct rte_flow_item_eth eth_mask;
634 : :
635 : : memset(ð, 0, sizeof(eth));
636 : : memset(ð_mask, 0, sizeof(eth_mask));
637 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_SET_MAC_SRC) {
638 : : memcpy(ð.hdr.src_addr.addr_bytes, &conf->mac_addr,
639 : : sizeof(eth.hdr.src_addr.addr_bytes));
640 : : memcpy(ð_mask.hdr.src_addr.addr_bytes,
641 : : &rte_flow_item_eth_mask.hdr.src_addr.addr_bytes,
642 : : sizeof(eth_mask.hdr.src_addr.addr_bytes));
643 : : } else {
644 : : memcpy(ð.hdr.dst_addr.addr_bytes, &conf->mac_addr,
645 : : sizeof(eth.hdr.dst_addr.addr_bytes));
646 : : memcpy(ð_mask.hdr.dst_addr.addr_bytes,
647 : : &rte_flow_item_eth_mask.hdr.dst_addr.addr_bytes,
648 : : sizeof(eth_mask.hdr.dst_addr.addr_bytes));
649 : : }
650 : 0 : item.spec = ð
651 : 0 : item.mask = ð_mask;
652 : 0 : return mlx5_flow_dv_convert_modify_action(&item, modify_eth, NULL, resource,
653 : : MLX5_MODIFICATION_TYPE_SET, error);
654 : : }
655 : :
656 : : /**
657 : : * Convert modify-header set VLAN VID action to DV specification.
658 : : *
659 : : * @param[in,out] resource
660 : : * Pointer to the modify-header resource.
661 : : * @param[in] action
662 : : * Pointer to action specification.
663 : : * @param[out] error
664 : : * Pointer to the error structure.
665 : : *
666 : : * @return
667 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
668 : : */
669 : : static int
670 : 0 : flow_dv_convert_action_modify_vlan_vid
671 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
672 : : const struct rte_flow_action *action,
673 : : struct rte_flow_error *error)
674 : : {
675 : 0 : const struct rte_flow_action_of_set_vlan_vid *conf =
676 : : (const struct rte_flow_action_of_set_vlan_vid *)(action->conf);
677 : 0 : int i = resource->actions_num;
678 : 0 : struct mlx5_modification_cmd *actions = resource->actions;
679 : : struct field_modify_info *field = modify_vlan_out_first_vid;
680 : :
681 [ # # ]: 0 : if (i >= MLX5_MAX_MODIFY_NUM)
682 : 0 : return rte_flow_error_set(error, EINVAL,
683 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
684 : : "too many items to modify");
685 : 0 : actions[i] = (struct mlx5_modification_cmd) {
686 : : .action_type = MLX5_MODIFICATION_TYPE_SET,
687 : 0 : .field = field->id,
688 : 0 : .length = field->size,
689 : 0 : .offset = field->offset,
690 : : };
691 [ # # ]: 0 : actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
692 : 0 : actions[i].data1 = conf->vlan_vid;
693 : 0 : actions[i].data1 = actions[i].data1 << 16;
694 : 0 : resource->actions_num = ++i;
695 : 0 : return 0;
696 : : }
697 : :
698 : : /**
699 : : * Convert modify-header set TP action to DV specification.
700 : : *
701 : : * @param[in,out] resource
702 : : * Pointer to the modify-header resource.
703 : : * @param[in] action
704 : : * Pointer to action specification.
705 : : * @param[in] items
706 : : * Pointer to rte_flow_item objects list.
707 : : * @param[in] attr
708 : : * Pointer to flow attributes structure.
709 : : * @param[in] dev_flow
710 : : * Pointer to the sub flow.
711 : : * @param[in] tunnel_decap
712 : : * Whether action is after tunnel decapsulation.
713 : : * @param[out] error
714 : : * Pointer to the error structure.
715 : : *
716 : : * @return
717 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
718 : : */
719 : : static int
720 : 0 : flow_dv_convert_action_modify_tp
721 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
722 : : const struct rte_flow_action *action,
723 : : const struct rte_flow_item *items,
724 : : union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
725 : : bool tunnel_decap, struct rte_flow_error *error)
726 : : {
727 : 0 : const struct rte_flow_action_set_tp *conf =
728 : : (const struct rte_flow_action_set_tp *)(action->conf);
729 : : struct rte_flow_item item;
730 : : struct rte_flow_item_udp udp;
731 : : struct rte_flow_item_udp udp_mask;
732 : : struct rte_flow_item_tcp tcp;
733 : : struct rte_flow_item_tcp tcp_mask;
734 : : struct field_modify_info *field;
735 : :
736 [ # # ]: 0 : if (!attr->valid)
737 : 0 : flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
738 [ # # ]: 0 : if (attr->udp) {
739 : : memset(&udp, 0, sizeof(udp));
740 : : memset(&udp_mask, 0, sizeof(udp_mask));
741 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
742 : 0 : udp.hdr.src_port = conf->port;
743 : 0 : udp_mask.hdr.src_port =
744 : : rte_flow_item_udp_mask.hdr.src_port;
745 : : } else {
746 : 0 : udp.hdr.dst_port = conf->port;
747 : 0 : udp_mask.hdr.dst_port =
748 : : rte_flow_item_udp_mask.hdr.dst_port;
749 : : }
750 : 0 : item.type = RTE_FLOW_ITEM_TYPE_UDP;
751 : 0 : item.spec = &udp;
752 : 0 : item.mask = &udp_mask;
753 : : field = modify_udp;
754 : : } else {
755 : : MLX5_ASSERT(attr->tcp);
756 : : memset(&tcp, 0, sizeof(tcp));
757 : : memset(&tcp_mask, 0, sizeof(tcp_mask));
758 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
759 : 0 : tcp.hdr.src_port = conf->port;
760 : 0 : tcp_mask.hdr.src_port =
761 : : rte_flow_item_tcp_mask.hdr.src_port;
762 : : } else {
763 : 0 : tcp.hdr.dst_port = conf->port;
764 : 0 : tcp_mask.hdr.dst_port =
765 : : rte_flow_item_tcp_mask.hdr.dst_port;
766 : : }
767 : 0 : item.type = RTE_FLOW_ITEM_TYPE_TCP;
768 : 0 : item.spec = &tcp;
769 : 0 : item.mask = &tcp_mask;
770 : : field = modify_tcp;
771 : : }
772 : 0 : return mlx5_flow_dv_convert_modify_action(&item, field, NULL, resource,
773 : : MLX5_MODIFICATION_TYPE_SET, error);
774 : : }
775 : :
776 : : /**
777 : : * Convert modify-header set TTL action to DV specification.
778 : : *
779 : : * @param[in,out] resource
780 : : * Pointer to the modify-header resource.
781 : : * @param[in] action
782 : : * Pointer to action specification.
783 : : * @param[in] items
784 : : * Pointer to rte_flow_item objects list.
785 : : * @param[in] attr
786 : : * Pointer to flow attributes structure.
787 : : * @param[in] dev_flow
788 : : * Pointer to the sub flow.
789 : : * @param[in] tunnel_decap
790 : : * Whether action is after tunnel decapsulation.
791 : : * @param[out] error
792 : : * Pointer to the error structure.
793 : : *
794 : : * @return
795 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
796 : : */
797 : : static int
798 : 0 : flow_dv_convert_action_modify_ttl
799 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
800 : : const struct rte_flow_action *action,
801 : : const struct rte_flow_item *items,
802 : : union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
803 : : bool tunnel_decap, struct rte_flow_error *error)
804 : : {
805 : 0 : const struct rte_flow_action_set_ttl *conf =
806 : : (const struct rte_flow_action_set_ttl *)(action->conf);
807 : : struct rte_flow_item item;
808 : : struct rte_flow_item_ipv4 ipv4;
809 : : struct rte_flow_item_ipv4 ipv4_mask;
810 : : struct rte_flow_item_ipv6 ipv6;
811 : : struct rte_flow_item_ipv6 ipv6_mask;
812 : : struct field_modify_info *field;
813 : :
814 [ # # ]: 0 : if (!attr->valid)
815 : 0 : flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
816 [ # # ]: 0 : if (attr->ipv4) {
817 : : memset(&ipv4, 0, sizeof(ipv4));
818 : : memset(&ipv4_mask, 0, sizeof(ipv4_mask));
819 : 0 : ipv4.hdr.time_to_live = conf->ttl_value;
820 : 0 : ipv4_mask.hdr.time_to_live = 0xFF;
821 : 0 : item.type = RTE_FLOW_ITEM_TYPE_IPV4;
822 : 0 : item.spec = &ipv4;
823 : 0 : item.mask = &ipv4_mask;
824 : : field = modify_ipv4;
825 : : } else {
826 : : MLX5_ASSERT(attr->ipv6);
827 : : memset(&ipv6, 0, sizeof(ipv6));
828 : : memset(&ipv6_mask, 0, sizeof(ipv6_mask));
829 : 0 : ipv6.hdr.hop_limits = conf->ttl_value;
830 : 0 : ipv6_mask.hdr.hop_limits = 0xFF;
831 : 0 : item.type = RTE_FLOW_ITEM_TYPE_IPV6;
832 : 0 : item.spec = &ipv6;
833 : 0 : item.mask = &ipv6_mask;
834 : : field = modify_ipv6;
835 : : }
836 : 0 : return mlx5_flow_dv_convert_modify_action(&item, field, NULL, resource,
837 : : MLX5_MODIFICATION_TYPE_SET, error);
838 : : }
839 : :
840 : : /**
841 : : * Convert modify-header decrement TTL action to DV specification.
842 : : *
843 : : * @param[in,out] resource
844 : : * Pointer to the modify-header resource.
845 : : * @param[in] action
846 : : * Pointer to action specification.
847 : : * @param[in] items
848 : : * Pointer to rte_flow_item objects list.
849 : : * @param[in] attr
850 : : * Pointer to flow attributes structure.
851 : : * @param[in] dev_flow
852 : : * Pointer to the sub flow.
853 : : * @param[in] tunnel_decap
854 : : * Whether action is after tunnel decapsulation.
855 : : * @param[out] error
856 : : * Pointer to the error structure.
857 : : *
858 : : * @return
859 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
860 : : */
861 : : static int
862 : 0 : flow_dv_convert_action_modify_dec_ttl
863 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
864 : : const struct rte_flow_item *items,
865 : : union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
866 : : bool tunnel_decap, struct rte_flow_error *error)
867 : : {
868 : : struct rte_flow_item item;
869 : : struct rte_flow_item_ipv4 ipv4;
870 : : struct rte_flow_item_ipv4 ipv4_mask;
871 : : struct rte_flow_item_ipv6 ipv6;
872 : : struct rte_flow_item_ipv6 ipv6_mask;
873 : : struct field_modify_info *field;
874 : :
875 [ # # ]: 0 : if (!attr->valid)
876 : 0 : flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
877 [ # # ]: 0 : if (attr->ipv4) {
878 : : memset(&ipv4, 0, sizeof(ipv4));
879 : : memset(&ipv4_mask, 0, sizeof(ipv4_mask));
880 : 0 : ipv4.hdr.time_to_live = 0xFF;
881 : 0 : ipv4_mask.hdr.time_to_live = 0xFF;
882 : 0 : item.type = RTE_FLOW_ITEM_TYPE_IPV4;
883 : 0 : item.spec = &ipv4;
884 : 0 : item.mask = &ipv4_mask;
885 : : field = modify_ipv4;
886 : : } else {
887 : : MLX5_ASSERT(attr->ipv6);
888 : : memset(&ipv6, 0, sizeof(ipv6));
889 : : memset(&ipv6_mask, 0, sizeof(ipv6_mask));
890 : 0 : ipv6.hdr.hop_limits = 0xFF;
891 : 0 : ipv6_mask.hdr.hop_limits = 0xFF;
892 : 0 : item.type = RTE_FLOW_ITEM_TYPE_IPV6;
893 : 0 : item.spec = &ipv6;
894 : 0 : item.mask = &ipv6_mask;
895 : : field = modify_ipv6;
896 : : }
897 : 0 : return mlx5_flow_dv_convert_modify_action(&item, field, NULL, resource,
898 : : MLX5_MODIFICATION_TYPE_ADD, error);
899 : : }
900 : :
901 : : /**
902 : : * Convert modify-header increment/decrement TCP Sequence number
903 : : * to DV specification.
904 : : *
905 : : * @param[in,out] resource
906 : : * Pointer to the modify-header resource.
907 : : * @param[in] action
908 : : * Pointer to action specification.
909 : : * @param[out] error
910 : : * Pointer to the error structure.
911 : : *
912 : : * @return
913 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
914 : : */
915 : : static int
916 : 0 : flow_dv_convert_action_modify_tcp_seq
917 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
918 : : const struct rte_flow_action *action,
919 : : struct rte_flow_error *error)
920 : : {
921 : 0 : const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
922 [ # # ]: 0 : uint64_t value = rte_be_to_cpu_32(*conf);
923 : : struct rte_flow_item item;
924 : : struct rte_flow_item_tcp tcp;
925 : : struct rte_flow_item_tcp tcp_mask;
926 : :
927 : : memset(&tcp, 0, sizeof(tcp));
928 : : memset(&tcp_mask, 0, sizeof(tcp_mask));
929 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ)
930 : : /*
931 : : * The HW has no decrement operation, only increment operation.
932 : : * To simulate decrement X from Y using increment operation
933 : : * we need to add UINT32_MAX X times to Y.
934 : : * Each adding of UINT32_MAX decrements Y by 1.
935 : : */
936 : 0 : value *= UINT32_MAX;
937 [ # # ]: 0 : tcp.hdr.sent_seq = rte_cpu_to_be_32((uint32_t)value);
938 : 0 : tcp_mask.hdr.sent_seq = RTE_BE32(UINT32_MAX);
939 : 0 : item.type = RTE_FLOW_ITEM_TYPE_TCP;
940 : 0 : item.spec = &tcp;
941 : 0 : item.mask = &tcp_mask;
942 : 0 : return mlx5_flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
943 : : MLX5_MODIFICATION_TYPE_ADD, error);
944 : : }
945 : :
946 : : /**
947 : : * Convert modify-header increment/decrement TCP Acknowledgment number
948 : : * to DV specification.
949 : : *
950 : : * @param[in,out] resource
951 : : * Pointer to the modify-header resource.
952 : : * @param[in] action
953 : : * Pointer to action specification.
954 : : * @param[out] error
955 : : * Pointer to the error structure.
956 : : *
957 : : * @return
958 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
959 : : */
960 : : static int
961 : 0 : flow_dv_convert_action_modify_tcp_ack
962 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
963 : : const struct rte_flow_action *action,
964 : : struct rte_flow_error *error)
965 : : {
966 : 0 : const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
967 [ # # ]: 0 : uint64_t value = rte_be_to_cpu_32(*conf);
968 : : struct rte_flow_item item;
969 : : struct rte_flow_item_tcp tcp;
970 : : struct rte_flow_item_tcp tcp_mask;
971 : :
972 : : memset(&tcp, 0, sizeof(tcp));
973 : : memset(&tcp_mask, 0, sizeof(tcp_mask));
974 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK)
975 : : /*
976 : : * The HW has no decrement operation, only increment operation.
977 : : * To simulate decrement X from Y using increment operation
978 : : * we need to add UINT32_MAX X times to Y.
979 : : * Each adding of UINT32_MAX decrements Y by 1.
980 : : */
981 : 0 : value *= UINT32_MAX;
982 [ # # ]: 0 : tcp.hdr.recv_ack = rte_cpu_to_be_32((uint32_t)value);
983 : 0 : tcp_mask.hdr.recv_ack = RTE_BE32(UINT32_MAX);
984 : 0 : item.type = RTE_FLOW_ITEM_TYPE_TCP;
985 : 0 : item.spec = &tcp;
986 : 0 : item.mask = &tcp_mask;
987 : 0 : return mlx5_flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
988 : : MLX5_MODIFICATION_TYPE_ADD, error);
989 : : }
990 : :
991 : : enum mlx5_modification_field mlx5_reg_to_field[] = {
992 : : [REG_NON] = MLX5_MODI_OUT_NONE,
993 : : [REG_A] = MLX5_MODI_META_DATA_REG_A,
994 : : [REG_B] = MLX5_MODI_META_DATA_REG_B,
995 : : [REG_C_0] = MLX5_MODI_META_REG_C_0,
996 : : [REG_C_1] = MLX5_MODI_META_REG_C_1,
997 : : [REG_C_2] = MLX5_MODI_META_REG_C_2,
998 : : [REG_C_3] = MLX5_MODI_META_REG_C_3,
999 : : [REG_C_4] = MLX5_MODI_META_REG_C_4,
1000 : : [REG_C_5] = MLX5_MODI_META_REG_C_5,
1001 : : [REG_C_6] = MLX5_MODI_META_REG_C_6,
1002 : : [REG_C_7] = MLX5_MODI_META_REG_C_7,
1003 : : [REG_C_8] = MLX5_MODI_META_REG_C_8,
1004 : : [REG_C_9] = MLX5_MODI_META_REG_C_9,
1005 : : [REG_C_10] = MLX5_MODI_META_REG_C_10,
1006 : : [REG_C_11] = MLX5_MODI_META_REG_C_11,
1007 : : };
1008 : :
1009 : : const size_t mlx5_mod_reg_size = RTE_DIM(mlx5_reg_to_field);
1010 : :
1011 : : /**
1012 : : * Convert register set to DV specification.
1013 : : *
1014 : : * @param[in,out] resource
1015 : : * Pointer to the modify-header resource.
1016 : : * @param[in] action
1017 : : * Pointer to action specification.
1018 : : * @param[out] error
1019 : : * Pointer to the error structure.
1020 : : *
1021 : : * @return
1022 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1023 : : */
1024 : : static int
1025 : 0 : flow_dv_convert_action_set_reg
1026 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
1027 : : const struct rte_flow_action *action,
1028 : : struct rte_flow_error *error)
1029 : : {
1030 : 0 : const struct mlx5_rte_flow_action_set_tag *conf = action->conf;
1031 : 0 : struct mlx5_modification_cmd *actions = resource->actions;
1032 : 0 : uint32_t i = resource->actions_num;
1033 : :
1034 [ # # ]: 0 : if (i >= MLX5_MAX_MODIFY_NUM)
1035 : 0 : return rte_flow_error_set(error, EINVAL,
1036 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1037 : : "too many items to modify");
1038 : : MLX5_ASSERT(conf->id != REG_NON);
1039 : : MLX5_ASSERT(conf->id < (enum modify_reg)RTE_DIM(mlx5_reg_to_field));
1040 : 0 : actions[i] = (struct mlx5_modification_cmd) {
1041 : : .action_type = MLX5_MODIFICATION_TYPE_SET,
1042 : 0 : .field = mlx5_reg_to_field[conf->id],
1043 : 0 : .offset = conf->offset,
1044 : 0 : .length = conf->length,
1045 : : };
1046 [ # # ]: 0 : actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
1047 [ # # ]: 0 : actions[i].data1 = rte_cpu_to_be_32(conf->data);
1048 : : ++i;
1049 : 0 : resource->actions_num = i;
1050 : 0 : return 0;
1051 : : }
1052 : :
1053 : : /**
1054 : : * Convert SET_TAG action to DV specification.
1055 : : *
1056 : : * @param[in] dev
1057 : : * Pointer to the rte_eth_dev structure.
1058 : : * @param[in,out] resource
1059 : : * Pointer to the modify-header resource.
1060 : : * @param[in] conf
1061 : : * Pointer to action specification.
1062 : : * @param[out] error
1063 : : * Pointer to the error structure.
1064 : : *
1065 : : * @return
1066 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1067 : : */
1068 : : static int
1069 : 0 : flow_dv_convert_action_set_tag
1070 : : (struct rte_eth_dev *dev,
1071 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
1072 : : const struct rte_flow_action_set_tag *conf,
1073 : : struct rte_flow_error *error)
1074 : : {
1075 [ # # ]: 0 : rte_be32_t data = rte_cpu_to_be_32(conf->data);
1076 [ # # ]: 0 : rte_be32_t mask = rte_cpu_to_be_32(conf->mask);
1077 : 0 : struct rte_flow_item item = {
1078 : : .spec = &data,
1079 : : .mask = &mask,
1080 : : };
1081 : 0 : struct field_modify_info reg_c_x[] = {
1082 : : [1] = {0, 0, 0},
1083 : : };
1084 : : enum mlx5_modification_field reg_type;
1085 : : int ret;
1086 : :
1087 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
1088 [ # # ]: 0 : if (ret < 0)
1089 : : return ret;
1090 : : MLX5_ASSERT(ret != REG_NON);
1091 [ # # ]: 0 : if ((unsigned int)ret >= RTE_DIM(mlx5_reg_to_field))
1092 : 0 : return rte_flow_error_set(error, EINVAL,
1093 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1094 : : NULL, "invalid register index");
1095 : 0 : reg_type = mlx5_reg_to_field[ret];
1096 : : MLX5_ASSERT(reg_type > 0);
1097 : 0 : reg_c_x[0] = (struct field_modify_info){4, 0, reg_type};
1098 : 0 : return mlx5_flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1099 : : MLX5_MODIFICATION_TYPE_SET, error);
1100 : : }
1101 : :
1102 : : /**
1103 : : * Convert internal COPY_REG action to DV specification.
1104 : : *
1105 : : * @param[in] dev
1106 : : * Pointer to the rte_eth_dev structure.
1107 : : * @param[in,out] res
1108 : : * Pointer to the modify-header resource.
1109 : : * @param[in] action
1110 : : * Pointer to action specification.
1111 : : * @param[out] error
1112 : : * Pointer to the error structure.
1113 : : *
1114 : : * @return
1115 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1116 : : */
1117 : : static int
1118 : 0 : flow_dv_convert_action_copy_mreg(struct rte_eth_dev *dev,
1119 : : struct mlx5_flow_dv_modify_hdr_resource *res,
1120 : : const struct rte_flow_action *action,
1121 : : struct rte_flow_error *error)
1122 : : {
1123 : 0 : const struct mlx5_flow_action_copy_mreg *conf = action->conf;
1124 : 0 : rte_be32_t mask = RTE_BE32(UINT32_MAX);
1125 : 0 : struct rte_flow_item item = {
1126 : : .spec = NULL,
1127 : : .mask = &mask,
1128 : : };
1129 : 0 : struct field_modify_info reg_src[] = {
1130 : 0 : {4, 0, mlx5_reg_to_field[conf->src]},
1131 : : {0, 0, 0},
1132 : : };
1133 : 0 : struct field_modify_info reg_dst = {
1134 : : .offset = 0,
1135 : 0 : .id = mlx5_reg_to_field[conf->dst],
1136 : : };
1137 : : /* Adjust reg_c[0] usage according to reported mask. */
1138 [ # # # # ]: 0 : if (conf->dst == REG_C_0 || conf->src == REG_C_0) {
1139 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1140 : 0 : uint32_t reg_c0 = priv->sh->dv_regc0_mask;
1141 : :
1142 : : MLX5_ASSERT(reg_c0);
1143 : : MLX5_ASSERT(priv->sh->config.dv_xmeta_en !=
1144 : : MLX5_XMETA_MODE_LEGACY);
1145 [ # # ]: 0 : if (conf->dst == REG_C_0) {
1146 : : /* Copy to reg_c[0], within mask only. */
1147 : 0 : reg_dst.offset = rte_bsf32(reg_c0);
1148 [ # # ]: 0 : mask = rte_cpu_to_be_32(reg_c0 >> reg_dst.offset);
1149 : : } else {
1150 : : reg_dst.offset = 0;
1151 [ # # ]: 0 : mask = rte_cpu_to_be_32(reg_c0);
1152 : : }
1153 : : }
1154 : 0 : return mlx5_flow_dv_convert_modify_action(&item,
1155 : : reg_src, ®_dst, res,
1156 : : MLX5_MODIFICATION_TYPE_COPY,
1157 : : error);
1158 : : }
1159 : :
1160 : : /**
1161 : : * Convert MARK action to DV specification. This routine is used
1162 : : * in extensive metadata only and requires metadata register to be
1163 : : * handled. In legacy mode hardware tag resource is engaged.
1164 : : *
1165 : : * @param[in] dev
1166 : : * Pointer to the rte_eth_dev structure.
1167 : : * @param[in] conf
1168 : : * Pointer to MARK action specification.
1169 : : * @param[in,out] resource
1170 : : * Pointer to the modify-header resource.
1171 : : * @param[out] error
1172 : : * Pointer to the error structure.
1173 : : *
1174 : : * @return
1175 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1176 : : */
1177 : : static int
1178 : 0 : flow_dv_convert_action_mark(struct rte_eth_dev *dev,
1179 : : const struct rte_flow_action_mark *conf,
1180 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
1181 : : struct rte_flow_error *error)
1182 : : {
1183 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1184 [ # # ]: 0 : rte_be32_t mask = rte_cpu_to_be_32(MLX5_FLOW_MARK_MASK &
1185 : : priv->sh->dv_mark_mask);
1186 [ # # ]: 0 : rte_be32_t data = rte_cpu_to_be_32(conf->id) & mask;
1187 : 0 : struct rte_flow_item item = {
1188 : : .spec = &data,
1189 : : .mask = &mask,
1190 : : };
1191 : 0 : struct field_modify_info reg_c_x[] = {
1192 : : [1] = {0, 0, 0},
1193 : : };
1194 : : int reg;
1195 : :
1196 [ # # ]: 0 : if (!mask)
1197 : 0 : return rte_flow_error_set(error, EINVAL,
1198 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1199 : : NULL, "zero mark action mask");
1200 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1201 [ # # ]: 0 : if (reg < 0)
1202 : : return reg;
1203 : : MLX5_ASSERT(reg > 0);
1204 [ # # ]: 0 : if (reg == REG_C_0) {
1205 [ # # ]: 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1206 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
1207 : :
1208 [ # # ]: 0 : data = rte_cpu_to_be_32(rte_cpu_to_be_32(data) << shl_c0);
1209 [ # # ]: 0 : mask = rte_cpu_to_be_32(mask) & msk_c0;
1210 [ # # ]: 0 : mask = rte_cpu_to_be_32(mask << shl_c0);
1211 : : }
1212 : 0 : reg_c_x[0] = (struct field_modify_info){4, 0, mlx5_reg_to_field[reg]};
1213 : 0 : return mlx5_flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1214 : : MLX5_MODIFICATION_TYPE_SET, error);
1215 : : }
1216 : :
1217 : : /**
1218 : : * Get metadata register index for specified steering domain.
1219 : : *
1220 : : * @param[in] dev
1221 : : * Pointer to the rte_eth_dev structure.
1222 : : * @param[in] attr
1223 : : * Attributes of flow to determine steering domain.
1224 : : * @param[out] error
1225 : : * Pointer to the error structure.
1226 : : *
1227 : : * @return
1228 : : * positive index on success, a negative errno value otherwise
1229 : : * and rte_errno is set.
1230 : : */
1231 : : static enum modify_reg
1232 : 0 : flow_dv_get_metadata_reg(struct rte_eth_dev *dev,
1233 : : const struct rte_flow_attr *attr,
1234 : : struct rte_flow_error *error)
1235 : : {
1236 : : int reg =
1237 [ # # ]: 0 : mlx5_flow_get_reg_id(dev, attr->transfer ?
1238 : 0 : MLX5_METADATA_FDB :
1239 [ # # ]: 0 : attr->egress ?
1240 : : MLX5_METADATA_TX :
1241 : : MLX5_METADATA_RX, 0, error);
1242 [ # # ]: 0 : if (reg < 0)
1243 : 0 : return rte_flow_error_set(error,
1244 : : ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM,
1245 : : NULL, "unavailable "
1246 : : "metadata register");
1247 : 0 : return reg;
1248 : : }
1249 : :
1250 : : /**
1251 : : * Convert SET_META action to DV specification.
1252 : : *
1253 : : * @param[in] dev
1254 : : * Pointer to the rte_eth_dev structure.
1255 : : * @param[in,out] resource
1256 : : * Pointer to the modify-header resource.
1257 : : * @param[in] attr
1258 : : * Attributes of flow that includes this item.
1259 : : * @param[in] conf
1260 : : * Pointer to action specification.
1261 : : * @param[out] error
1262 : : * Pointer to the error structure.
1263 : : *
1264 : : * @return
1265 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1266 : : */
1267 : : static int
1268 : 0 : flow_dv_convert_action_set_meta
1269 : : (struct rte_eth_dev *dev,
1270 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
1271 : : const struct rte_flow_attr *attr,
1272 : : const struct rte_flow_action_set_meta *conf,
1273 : : struct rte_flow_error *error)
1274 : : {
1275 [ # # ]: 0 : uint32_t mask = rte_cpu_to_be_32(conf->mask);
1276 [ # # ]: 0 : uint32_t data = rte_cpu_to_be_32(conf->data) & mask;
1277 : 0 : struct rte_flow_item item = {
1278 : : .spec = &data,
1279 : : .mask = &mask,
1280 : : };
1281 : 0 : struct field_modify_info reg_c_x[] = {
1282 : : [1] = {0, 0, 0},
1283 : : };
1284 : 0 : int reg = flow_dv_get_metadata_reg(dev, attr, error);
1285 : :
1286 [ # # ]: 0 : if (reg < 0)
1287 : : return reg;
1288 : : MLX5_ASSERT(reg != REG_NON);
1289 [ # # ]: 0 : if (reg == REG_C_0) {
1290 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1291 [ # # ]: 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1292 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
1293 : :
1294 [ # # ]: 0 : data = rte_cpu_to_be_32(rte_cpu_to_be_32(data) << shl_c0);
1295 [ # # ]: 0 : mask = rte_cpu_to_be_32(mask) & msk_c0;
1296 [ # # ]: 0 : mask = rte_cpu_to_be_32(mask << shl_c0);
1297 : : }
1298 : 0 : reg_c_x[0] = (struct field_modify_info){4, 0, mlx5_reg_to_field[reg]};
1299 : : /* The routine expects parameters in memory as big-endian ones. */
1300 : 0 : return mlx5_flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1301 : : MLX5_MODIFICATION_TYPE_SET, error);
1302 : : }
1303 : :
1304 : : /**
1305 : : * Convert modify-header set IPv4 DSCP action to DV specification.
1306 : : *
1307 : : * @param[in,out] resource
1308 : : * Pointer to the modify-header resource.
1309 : : * @param[in] action
1310 : : * Pointer to action specification.
1311 : : * @param[out] error
1312 : : * Pointer to the error structure.
1313 : : *
1314 : : * @return
1315 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1316 : : */
1317 : : static int
1318 : 0 : flow_dv_convert_action_modify_ipv4_dscp
1319 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
1320 : : const struct rte_flow_action *action,
1321 : : struct rte_flow_error *error)
1322 : : {
1323 : 0 : const struct rte_flow_action_set_dscp *conf =
1324 : : (const struct rte_flow_action_set_dscp *)(action->conf);
1325 : 0 : struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
1326 : : struct rte_flow_item_ipv4 ipv4;
1327 : : struct rte_flow_item_ipv4 ipv4_mask;
1328 : :
1329 : : memset(&ipv4, 0, sizeof(ipv4));
1330 : : memset(&ipv4_mask, 0, sizeof(ipv4_mask));
1331 : 0 : ipv4.hdr.type_of_service = conf->dscp;
1332 : 0 : ipv4_mask.hdr.type_of_service = RTE_IPV4_HDR_DSCP_MASK >> 2;
1333 : 0 : item.spec = &ipv4;
1334 : 0 : item.mask = &ipv4_mask;
1335 : 0 : return mlx5_flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
1336 : : MLX5_MODIFICATION_TYPE_SET, error);
1337 : : }
1338 : :
1339 : : /**
1340 : : * Convert modify-header set IPv6 DSCP action to DV specification.
1341 : : *
1342 : : * @param[in,out] resource
1343 : : * Pointer to the modify-header resource.
1344 : : * @param[in] action
1345 : : * Pointer to action specification.
1346 : : * @param[out] error
1347 : : * Pointer to the error structure.
1348 : : *
1349 : : * @return
1350 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1351 : : */
1352 : : static int
1353 : 0 : flow_dv_convert_action_modify_ipv6_dscp
1354 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
1355 : : const struct rte_flow_action *action,
1356 : : uint32_t ipv6_tc_off,
1357 : : struct rte_flow_error *error)
1358 : : {
1359 : 0 : const struct rte_flow_action_set_dscp *conf =
1360 : : (const struct rte_flow_action_set_dscp *)(action->conf);
1361 [ # # ]: 0 : struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
1362 : : struct rte_flow_item_ipv6 ipv6;
1363 : : struct rte_flow_item_ipv6 ipv6_mask;
1364 : : struct field_modify_info *modify_info;
1365 : :
1366 : : memset(&ipv6, 0, sizeof(ipv6));
1367 : : memset(&ipv6_mask, 0, sizeof(ipv6_mask));
1368 : : /*
1369 : : * Even though the DSCP bits offset of IPv6 is not byte aligned,
1370 : : * rdma-core only accept the DSCP bits byte aligned start from
1371 : : * bit 0 to 5 as to be compatible with IPv4. No need to shift the
1372 : : * bits in IPv6 case as rdma-core requires byte aligned value.
1373 : : * IPv6 DSCP uses OUT_IPV6_TRAFFIC_CLASS as ID but it starts from 2
1374 : : * bits left. Shift the mask left for IPv6 DSCP. Do it here because
1375 : : * it's needed to distinguish DSCP from ECN in data field construct
1376 : : */
1377 : 0 : ipv6.hdr.vtc_flow = conf->dscp << ipv6_tc_off;
1378 : 0 : ipv6_mask.hdr.vtc_flow = RTE_IPV6_HDR_DSCP_MASK >> (22 - ipv6_tc_off);
1379 : 0 : item.spec = &ipv6;
1380 : 0 : item.mask = &ipv6_mask;
1381 [ # # ]: 0 : if (ipv6_tc_off)
1382 : : modify_info = modify_ipv6_traffic_class;
1383 : : else
1384 : : modify_info = modify_ipv6;
1385 : 0 : return mlx5_flow_dv_convert_modify_action(&item, modify_info, NULL, resource,
1386 : : MLX5_MODIFICATION_TYPE_SET, error);
1387 : : }
1388 : :
1389 : : int
1390 : 0 : mlx5_flow_item_field_width(struct rte_eth_dev *dev,
1391 : : enum rte_flow_field_id field, int inherit,
1392 : : const struct rte_flow_attr *attr,
1393 : : struct rte_flow_error *error)
1394 : : {
1395 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1396 : :
1397 [ # # # # : 0 : switch (field) {
# # # # #
# # # # #
# # # # #
# # # # ]
1398 : : case RTE_FLOW_FIELD_START:
1399 : : return 32;
1400 : 0 : case RTE_FLOW_FIELD_MAC_DST:
1401 : : case RTE_FLOW_FIELD_MAC_SRC:
1402 : 0 : return 48;
1403 : 0 : case RTE_FLOW_FIELD_VLAN_TYPE:
1404 : 0 : return 16;
1405 : 0 : case RTE_FLOW_FIELD_VLAN_ID:
1406 : 0 : return 12;
1407 : 0 : case RTE_FLOW_FIELD_MAC_TYPE:
1408 : 0 : return 16;
1409 : 0 : case RTE_FLOW_FIELD_IPV4_DSCP:
1410 : 0 : return 6;
1411 : 0 : case RTE_FLOW_FIELD_IPV4_TTL:
1412 : : case RTE_FLOW_FIELD_IPV4_PROTO:
1413 : 0 : return 8;
1414 : : case RTE_FLOW_FIELD_IPV4_SRC:
1415 : : case RTE_FLOW_FIELD_IPV4_DST:
1416 : : return 32;
1417 : 0 : case RTE_FLOW_FIELD_IPV6_DSCP:
1418 : 0 : return 6;
1419 : 0 : case RTE_FLOW_FIELD_IPV6_FLOW_LABEL:
1420 : 0 : return 20;
1421 : 0 : case RTE_FLOW_FIELD_IPV6_TRAFFIC_CLASS:
1422 : : case RTE_FLOW_FIELD_IPV6_HOPLIMIT:
1423 : : case RTE_FLOW_FIELD_IPV6_PROTO:
1424 : 0 : return 8;
1425 : 0 : case RTE_FLOW_FIELD_IPV6_SRC:
1426 : : case RTE_FLOW_FIELD_IPV6_DST:
1427 : 0 : return 128;
1428 : 0 : case RTE_FLOW_FIELD_TCP_PORT_SRC:
1429 : : case RTE_FLOW_FIELD_TCP_PORT_DST:
1430 : 0 : return 16;
1431 : : case RTE_FLOW_FIELD_TCP_SEQ_NUM:
1432 : : case RTE_FLOW_FIELD_TCP_ACK_NUM:
1433 : : return 32;
1434 : 0 : case RTE_FLOW_FIELD_TCP_FLAGS:
1435 : 0 : return 9;
1436 : 0 : case RTE_FLOW_FIELD_UDP_PORT_SRC:
1437 : : case RTE_FLOW_FIELD_UDP_PORT_DST:
1438 : 0 : return 16;
1439 : 0 : case RTE_FLOW_FIELD_VXLAN_VNI:
1440 : : case RTE_FLOW_FIELD_GENEVE_VNI:
1441 : 0 : return 24;
1442 : 0 : case RTE_FLOW_FIELD_VXLAN_LAST_RSVD:
1443 : 0 : return 8;
1444 : : case RTE_FLOW_FIELD_GTP_TEID:
1445 : : case RTE_FLOW_FIELD_MPLS:
1446 : : case RTE_FLOW_FIELD_TAG:
1447 : : case RTE_FLOW_FIELD_ESP_SPI:
1448 : : case RTE_FLOW_FIELD_ESP_SEQ_NUM:
1449 : : return 32;
1450 : 0 : case RTE_FLOW_FIELD_ESP_PROTO:
1451 : 0 : return 8;
1452 : 0 : case RTE_FLOW_FIELD_MARK:
1453 : 0 : return rte_popcount32(priv->sh->dv_mark_mask);
1454 : 0 : case RTE_FLOW_FIELD_META:
1455 : 0 : return (flow_dv_get_metadata_reg(dev, attr, error) == REG_C_0) ?
1456 [ # # ]: 0 : rte_popcount32(priv->sh->dv_meta_mask) : 32;
1457 : 0 : case RTE_FLOW_FIELD_GTP_PSC_QFI:
1458 : 0 : return 6;
1459 : 0 : case RTE_FLOW_FIELD_POINTER:
1460 : : case RTE_FLOW_FIELD_VALUE:
1461 : 0 : return inherit < 0 ? 0 : inherit;
1462 : 0 : case RTE_FLOW_FIELD_IPV4_ECN:
1463 : : case RTE_FLOW_FIELD_IPV6_ECN:
1464 : : case RTE_FLOW_FIELD_METER_COLOR:
1465 : 0 : return 2;
1466 : : case RTE_FLOW_FIELD_HASH_RESULT:
1467 : : return 32;
1468 : 0 : default:
1469 : : MLX5_ASSERT(false);
1470 : : }
1471 : 0 : return 0;
1472 : : }
1473 : :
1474 : : static __rte_always_inline uint8_t
1475 : : flow_modify_info_mask_8(uint32_t length, uint32_t off)
1476 : : {
1477 : 0 : return (0xffu >> (8 - length)) << off;
1478 : : }
1479 : :
1480 : : static __rte_always_inline uint16_t
1481 : : flow_modify_info_mask_16(uint32_t length, uint32_t off)
1482 : : {
1483 [ # # # # : 0 : return rte_cpu_to_be_16((0xffffu >> (16 - length)) << off);
# # # # #
# # # # #
# # # # #
# # # ]
1484 : : }
1485 : :
1486 : : static __rte_always_inline uint32_t
1487 : : flow_modify_info_mask_32(uint32_t length, uint32_t off)
1488 : : {
1489 [ # # # # : 0 : return rte_cpu_to_be_32((0xffffffffu >> (32 - length)) << off);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1490 : : }
1491 : :
1492 : : static __rte_always_inline uint32_t
1493 : : flow_modify_info_mask_32_masked(uint32_t length, uint32_t off, uint32_t post_mask)
1494 : : {
1495 : 0 : uint32_t mask = (0xffffffffu >> (32 - length)) << off;
1496 : 0 : return rte_cpu_to_be_32(mask & post_mask);
1497 : : }
1498 : :
1499 : : static __rte_always_inline enum mlx5_modification_field
1500 : : mlx5_mpls_modi_field_get(const struct rte_flow_field_data *data)
1501 : : {
1502 : 0 : return MLX5_MODI_IN_MPLS_LABEL_0 + data->tag_index;
1503 : : }
1504 : :
1505 : : static __rte_always_inline int
1506 : : flow_geneve_opt_modi_field_get(struct mlx5_priv *priv,
1507 : : const struct rte_flow_field_data *data)
1508 : : {
1509 : : #ifdef HAVE_MLX5_HWS_SUPPORT
1510 : 0 : return mlx5_geneve_opt_modi_field_get(priv, data);
1511 : : #else
1512 : : (void)priv;
1513 : : (void)data;
1514 : : DRV_LOG(ERR, "GENEVE option modification is not supported.");
1515 : : rte_errno = ENOTSUP;
1516 : : return -rte_errno;
1517 : : #endif
1518 : : }
1519 : :
1520 : : static void
1521 : 0 : mlx5_modify_flex_item(const struct rte_eth_dev *dev,
1522 : : const struct mlx5_flex_item *flex,
1523 : : const struct rte_flow_field_data *data,
1524 : : struct field_modify_info *info,
1525 : : uint32_t *mask, uint32_t width)
1526 : : {
1527 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1528 : 0 : struct mlx5_hca_flex_attr *attr = &priv->sh->cdev->config.hca_attr.flex;
1529 : : uint32_t i, j;
1530 : : int id = 0;
1531 : 0 : uint32_t pos = 0;
1532 : : const struct mlx5_flex_pattern_field *map;
1533 : 0 : uint32_t offset = data->offset;
1534 : : uint32_t width_left = width;
1535 : : uint32_t cur_width = 0;
1536 : : uint32_t tmp_ofs;
1537 : : uint32_t idx = 0;
1538 : : struct field_modify_info tmp;
1539 : : int tmp_id;
1540 : :
1541 [ # # ]: 0 : if (!attr->query_match_sample_info) {
1542 : 0 : DRV_LOG(ERR, "FW doesn't support modify field with flex item.");
1543 : 0 : return;
1544 : : }
1545 : : /*
1546 : : * search for the mapping instance until Accumulated width is no
1547 : : * less than data->offset.
1548 : : */
1549 [ # # ]: 0 : for (i = 0; i < flex->mapnum; i++) {
1550 [ # # ]: 0 : if (flex->map[i].width + pos > data->offset)
1551 : : break;
1552 : 0 : pos += flex->map[i].width;
1553 : : }
1554 [ # # ]: 0 : if (i >= flex->mapnum)
1555 : : return;
1556 [ # # ]: 0 : tmp_ofs = pos < data->offset ? data->offset - pos : 0;
1557 [ # # # # ]: 0 : for (j = i; i < flex->mapnum && width_left > 0; ) {
1558 : 0 : map = flex->map + i;
1559 : 0 : id = mlx5_flex_get_sample_id(flex, i, &pos, false);
1560 [ # # ]: 0 : if (id == -1) {
1561 : 0 : i++;
1562 : : /* All left length is dummy */
1563 [ # # ]: 0 : if (pos >= data->offset + width)
1564 : : return;
1565 : 0 : cur_width = map->width;
1566 : : /* One mapping instance covers the whole width. */
1567 [ # # ]: 0 : } else if (pos + map->width >= (data->offset + width)) {
1568 : : cur_width = width_left;
1569 : : } else {
1570 : 0 : cur_width = cur_width + map->width - tmp_ofs;
1571 : 0 : pos += map->width;
1572 : : /*
1573 : : * Continue to search next until:
1574 : : * 1. Another flex parser ID.
1575 : : * 2. Width has been covered.
1576 : : */
1577 [ # # ]: 0 : for (j = i + 1; j < flex->mapnum; j++) {
1578 : 0 : tmp_id = mlx5_flex_get_sample_id(flex, j, &pos, false);
1579 [ # # ]: 0 : if (tmp_id == -1) {
1580 : : i = j;
1581 : 0 : pos -= flex->map[j].width;
1582 : 0 : break;
1583 : : }
1584 [ # # # # ]: 0 : if (id >= (int)flex->devx_fp->num_samples ||
1585 [ # # ]: 0 : id >= MLX5_GRAPH_NODE_SAMPLE_NUM ||
1586 [ # # ]: 0 : tmp_id >= (int)flex->devx_fp->num_samples ||
1587 : : tmp_id >= MLX5_GRAPH_NODE_SAMPLE_NUM)
1588 : : return;
1589 : 0 : if (flex->devx_fp->sample_info[id].modify_field_id !=
1590 [ # # ]: 0 : flex->devx_fp->sample_info[tmp_id].modify_field_id ||
1591 : 0 : flex->map[j].shift != flex->map[j - 1].width +
1592 [ # # ]: 0 : flex->map[j - 1].shift) {
1593 : : i = j;
1594 : : break;
1595 : : }
1596 [ # # ]: 0 : if ((pos + flex->map[j].width) >= (data->offset + width)) {
1597 : : cur_width = width_left;
1598 : : break;
1599 : : }
1600 : 0 : pos += flex->map[j].width;
1601 : 0 : cur_width += flex->map[j].width;
1602 : : }
1603 : : }
1604 [ # # ]: 0 : if (cur_width > width_left)
1605 : : cur_width = width_left;
1606 [ # # # # : 0 : else if (cur_width < width_left && (j == flex->mapnum || i == flex->mapnum))
# # ]
1607 : : return;
1608 : :
1609 : : MLX5_ASSERT(id < (int)flex->devx_fp->num_samples);
1610 [ # # # # ]: 0 : if (id >= (int)flex->devx_fp->num_samples || id >= MLX5_GRAPH_NODE_SAMPLE_NUM)
1611 : : return;
1612 : : /* Use invalid entry as placeholder for DUMMY mapping. */
1613 : 0 : info[idx] = (struct field_modify_info){cur_width / CHAR_BIT, offset / CHAR_BIT,
1614 [ # # ]: 0 : id == -1 ? MLX5_MODI_INVALID :
1615 : : (enum mlx5_modification_field)
1616 : 0 : flex->devx_fp->sample_info[id].modify_field_id,
1617 : 0 : map->shift + tmp_ofs, 1};
1618 : 0 : offset += cur_width;
1619 : 0 : width_left -= cur_width;
1620 [ # # ]: 0 : if (!mask) {
1621 : 0 : info[idx].offset = (32 - cur_width - map->shift - tmp_ofs);
1622 : 0 : info[idx].size = cur_width / CHAR_BIT + info[idx].offset / CHAR_BIT;
1623 : : }
1624 : : cur_width = 0;
1625 : : tmp_ofs = 0;
1626 : 0 : idx++;
1627 : : }
1628 [ # # ]: 0 : if (unlikely(width_left > 0)) {
1629 : : MLX5_ASSERT(false);
1630 : : return;
1631 : : }
1632 [ # # ]: 0 : if (mask)
1633 : 0 : memset(mask, 0xff, data->offset / CHAR_BIT + width / CHAR_BIT);
1634 : : /* Re-order the info to follow IPv6 address. */
1635 [ # # ]: 0 : for (i = 0; i < idx / 2; i++) {
1636 : 0 : tmp = info[i];
1637 : : MLX5_ASSERT(info[i].id);
1638 : : MLX5_ASSERT(info[idx - 1 - i].id);
1639 : 0 : info[i] = info[idx - 1 - i];
1640 : 0 : info[idx - 1 - i] = tmp;
1641 : : }
1642 : : }
1643 : :
1644 : : void
1645 : 0 : mlx5_flow_field_id_to_modify_info
1646 : : (const struct rte_flow_field_data *data,
1647 : : struct field_modify_info *info, uint32_t *mask,
1648 : : uint32_t width, struct rte_eth_dev *dev,
1649 : : const struct rte_flow_attr *attr, struct rte_flow_error *error)
1650 : : {
1651 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1652 : : enum mlx5_modification_field modi_id;
1653 : : uint32_t idx = 0;
1654 : : uint32_t off_be = 0;
1655 : : uint32_t length = 0;
1656 : :
1657 [ # # # # : 0 : switch ((int)data->field) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
1658 : : case RTE_FLOW_FIELD_START:
1659 : : /* not supported yet */
1660 : : MLX5_ASSERT(false);
1661 : : break;
1662 : 0 : case RTE_FLOW_FIELD_MAC_DST:
1663 : : MLX5_ASSERT(data->offset + width <= 48);
1664 : 0 : off_be = 48 - (data->offset + width);
1665 [ # # ]: 0 : if (off_be < 16) {
1666 [ # # ]: 0 : modi_id = CALC_MODI_ID(DMAC_15_0, data->level);
1667 : 0 : info[idx] = (struct field_modify_info){2, 4, modi_id};
1668 [ # # ]: 0 : length = off_be + width <= 16 ? width : 16 - off_be;
1669 [ # # ]: 0 : if (mask)
1670 : 0 : mask[1] = flow_modify_info_mask_16(length,
1671 : : off_be);
1672 : : else
1673 : 0 : info[idx].offset = off_be;
1674 : 0 : width -= length;
1675 [ # # ]: 0 : if (!width)
1676 : : break;
1677 : : off_be = 0;
1678 : : idx++;
1679 : : } else {
1680 : 0 : off_be -= 16;
1681 : : }
1682 [ # # ]: 0 : modi_id = CALC_MODI_ID(DMAC_47_16, data->level);
1683 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1684 [ # # ]: 0 : if (mask)
1685 : 0 : mask[0] = flow_modify_info_mask_32(width, off_be);
1686 : : else
1687 : 0 : info[idx].offset = off_be;
1688 : : break;
1689 : 0 : case RTE_FLOW_FIELD_MAC_SRC:
1690 : : MLX5_ASSERT(data->offset + width <= 48);
1691 : 0 : off_be = 48 - (data->offset + width);
1692 [ # # ]: 0 : if (off_be < 16) {
1693 [ # # ]: 0 : modi_id = CALC_MODI_ID(SMAC_15_0, data->level);
1694 : 0 : info[idx] = (struct field_modify_info){2, 4, modi_id};
1695 [ # # ]: 0 : length = off_be + width <= 16 ? width : 16 - off_be;
1696 [ # # ]: 0 : if (mask)
1697 : 0 : mask[1] = flow_modify_info_mask_16(length,
1698 : : off_be);
1699 : : else
1700 : 0 : info[idx].offset = off_be;
1701 : 0 : width -= length;
1702 [ # # ]: 0 : if (!width)
1703 : : break;
1704 : : off_be = 0;
1705 : : idx++;
1706 : : } else {
1707 : 0 : off_be -= 16;
1708 : : }
1709 [ # # ]: 0 : modi_id = CALC_MODI_ID(SMAC_47_16, data->level);
1710 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1711 [ # # ]: 0 : if (mask)
1712 : 0 : mask[0] = flow_modify_info_mask_32(width, off_be);
1713 : : else
1714 : 0 : info[idx].offset = off_be;
1715 : : break;
1716 : : case RTE_FLOW_FIELD_VLAN_TYPE:
1717 : : /* not supported yet */
1718 : : break;
1719 : 0 : case RTE_FLOW_FIELD_VLAN_ID:
1720 : : MLX5_ASSERT(data->offset + width <= 12);
1721 : 0 : off_be = 12 - (data->offset + width);
1722 : 0 : info[idx] = (struct field_modify_info){2, 0,
1723 : : MLX5_MODI_OUT_FIRST_VID};
1724 [ # # ]: 0 : if (mask)
1725 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1726 : : else
1727 : 0 : info[idx].offset = off_be;
1728 : : break;
1729 : 0 : case RTE_FLOW_FIELD_MAC_TYPE:
1730 : : MLX5_ASSERT(data->offset + width <= 16);
1731 : 0 : off_be = 16 - (data->offset + width);
1732 [ # # ]: 0 : modi_id = CALC_MODI_ID(ETHERTYPE, data->level);
1733 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
1734 [ # # ]: 0 : if (mask)
1735 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1736 : : else
1737 : 0 : info[idx].offset = off_be;
1738 : : break;
1739 : 0 : case RTE_FLOW_FIELD_IPV4_IHL:
1740 : : MLX5_ASSERT(data->offset + width <= 4);
1741 : 0 : off_be = 4 - (data->offset + width);
1742 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV4_IHL, data->level);
1743 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
1744 [ # # ]: 0 : if (mask)
1745 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1746 : : else
1747 : 0 : info[idx].offset = off_be;
1748 : : break;
1749 : 0 : case RTE_FLOW_FIELD_IPV4_DSCP:
1750 : : MLX5_ASSERT(data->offset + width <= 6);
1751 : 0 : off_be = 6 - (data->offset + width);
1752 [ # # ]: 0 : modi_id = CALC_MODI_ID(IP_DSCP, data->level);
1753 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
1754 [ # # ]: 0 : if (mask)
1755 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1756 : : else
1757 : 0 : info[idx].offset = off_be;
1758 : : break;
1759 : 0 : case RTE_FLOW_FIELD_IPV4_TOTAL_LEN:
1760 : : MLX5_ASSERT(data->offset + width <= 16);
1761 : 0 : off_be = 16 - (data->offset + width);
1762 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV4_TOTAL_LEN, data->level);
1763 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
1764 [ # # ]: 0 : if (mask)
1765 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1766 : : else
1767 : 0 : info[idx].offset = off_be;
1768 : : break;
1769 : 0 : case RTE_FLOW_FIELD_IPV4_TTL:
1770 : : MLX5_ASSERT(data->offset + width <= 8);
1771 : 0 : off_be = 8 - (data->offset + width);
1772 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV4_TTL, data->level);
1773 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
1774 [ # # ]: 0 : if (mask)
1775 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1776 : : else
1777 : 0 : info[idx].offset = off_be;
1778 : : break;
1779 : 0 : case RTE_FLOW_FIELD_IPV4_SRC:
1780 : : MLX5_ASSERT(data->offset + width <= 32);
1781 : 0 : off_be = 32 - (data->offset + width);
1782 [ # # ]: 0 : modi_id = CALC_MODI_ID(SIPV4, data->level);
1783 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1784 [ # # ]: 0 : if (mask)
1785 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1786 : : else
1787 : 0 : info[idx].offset = off_be;
1788 : : break;
1789 : 0 : case RTE_FLOW_FIELD_IPV4_DST:
1790 : : MLX5_ASSERT(data->offset + width <= 32);
1791 : 0 : off_be = 32 - (data->offset + width);
1792 [ # # ]: 0 : modi_id = CALC_MODI_ID(DIPV4, data->level);
1793 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1794 [ # # ]: 0 : if (mask)
1795 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1796 : : else
1797 : 0 : info[idx].offset = off_be;
1798 : : break;
1799 : : case RTE_FLOW_FIELD_IPV6_DSCP:
1800 : : MLX5_ASSERT(data->offset + width <= 6);
1801 : : /*
1802 : : * IPv6 DSCP uses OUT_IPV6_TRAFFIC_CLASS as ID but it starts from 2
1803 : : * bits left. Shift the mask left for IPv6 DSCP. Do it here because
1804 : : * it's needed to distinguish DSCP from ECN in data field construct
1805 : : */
1806 [ # # ]: 0 : if (mlx5_dv_modify_ipv6_traffic_class_supported(priv)) {
1807 : 0 : off_be = 6 - (data->offset + width) + MLX5_IPV6_HDR_DSCP_SHIFT;
1808 : 0 : info[idx] = (struct field_modify_info){1, 0,
1809 : : MLX5_MODI_OUT_IPV6_TRAFFIC_CLASS};
1810 : : } else {
1811 : 0 : off_be = 6 - (data->offset + width);
1812 : 0 : info[idx] = (struct field_modify_info){1, 0,
1813 : : MLX5_MODI_OUT_IP_DSCP};
1814 : : }
1815 [ # # ]: 0 : if (mask)
1816 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1817 : : else
1818 : 0 : info[idx].offset = off_be;
1819 : : break;
1820 : 0 : case RTE_FLOW_FIELD_IPV6_TRAFFIC_CLASS:
1821 : : MLX5_ASSERT(data->offset + width <= 8);
1822 : 0 : off_be = 8 - (data->offset + width);
1823 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV6_TRAFFIC_CLASS, data->level);
1824 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
1825 [ # # ]: 0 : if (mask)
1826 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1827 : : else
1828 : 0 : info[idx].offset = off_be;
1829 : : break;
1830 : 0 : case RTE_FLOW_FIELD_IPV6_FLOW_LABEL:
1831 : : MLX5_ASSERT(data->offset + width <= 20);
1832 : 0 : off_be = 20 - (data->offset + width);
1833 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV6_FLOW_LABEL, data->level);
1834 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1835 [ # # ]: 0 : if (mask)
1836 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1837 : : else
1838 : 0 : info[idx].offset = off_be;
1839 : : break;
1840 : 0 : case RTE_FLOW_FIELD_IPV6_PAYLOAD_LEN:
1841 : : MLX5_ASSERT(data->offset + width <= 16);
1842 : 0 : off_be = 16 - (data->offset + width);
1843 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV6_PAYLOAD_LEN, data->level);
1844 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
1845 [ # # ]: 0 : if (mask)
1846 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1847 : : else
1848 : 0 : info[idx].offset = off_be;
1849 : : break;
1850 : 0 : case RTE_FLOW_FIELD_IPV6_HOPLIMIT:
1851 : : MLX5_ASSERT(data->offset + width <= 8);
1852 : 0 : off_be = 8 - (data->offset + width);
1853 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV6_HOPLIMIT, data->level);
1854 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
1855 [ # # ]: 0 : if (mask)
1856 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1857 : : else
1858 : 0 : info[idx].offset = off_be;
1859 : : break;
1860 : 0 : case RTE_FLOW_FIELD_IPV6_SRC: {
1861 : : /*
1862 : : * Fields corresponding to IPv6 source address bytes
1863 : : * arranged according to network byte ordering.
1864 : : */
1865 : 0 : struct field_modify_info fields[] = {
1866 [ # # ]: 0 : { 4, 0, CALC_MODI_ID(SIPV6_127_96, data->level)},
1867 [ # # ]: 0 : { 4, 4, CALC_MODI_ID(SIPV6_95_64, data->level)},
1868 [ # # ]: 0 : { 4, 8, CALC_MODI_ID(SIPV6_63_32, data->level)},
1869 [ # # ]: 0 : { 4, 12, CALC_MODI_ID(SIPV6_31_0, data->level)},
1870 : : };
1871 : : /* First mask to be modified is the mask of 4th address byte. */
1872 : : uint32_t midx = 3;
1873 : :
1874 : : MLX5_ASSERT(data->offset + width <= 128);
1875 : 0 : off_be = 128 - (data->offset + width);
1876 [ # # ]: 0 : while (width > 0 && midx > 0) {
1877 [ # # ]: 0 : if (off_be < 32) {
1878 : 0 : info[idx] = fields[midx];
1879 : 0 : length = off_be + width <= 32 ?
1880 [ # # ]: 0 : width : 32 - off_be;
1881 [ # # ]: 0 : if (mask)
1882 [ # # ]: 0 : mask[midx] = flow_modify_info_mask_32
1883 : : (length, off_be);
1884 : : else
1885 : 0 : info[idx].offset = off_be;
1886 : 0 : width -= length;
1887 : : off_be = 0;
1888 : 0 : idx++;
1889 : : } else {
1890 : 0 : off_be -= 32;
1891 : : }
1892 : 0 : midx--;
1893 : : }
1894 [ # # ]: 0 : if (!width)
1895 : : break;
1896 : 0 : info[idx] = fields[midx];
1897 [ # # ]: 0 : if (mask)
1898 [ # # ]: 0 : mask[midx] = flow_modify_info_mask_32(width, off_be);
1899 : : else
1900 : 0 : info[idx].offset = off_be;
1901 : : break;
1902 : : }
1903 : 0 : case RTE_FLOW_FIELD_IPV6_DST: {
1904 : : /*
1905 : : * Fields corresponding to IPv6 destination address bytes
1906 : : * arranged according to network byte ordering.
1907 : : */
1908 : 0 : struct field_modify_info fields[] = {
1909 [ # # ]: 0 : { 4, 0, CALC_MODI_ID(DIPV6_127_96, data->level)},
1910 [ # # ]: 0 : { 4, 4, CALC_MODI_ID(DIPV6_95_64, data->level)},
1911 [ # # ]: 0 : { 4, 8, CALC_MODI_ID(DIPV6_63_32, data->level)},
1912 [ # # ]: 0 : { 4, 12, CALC_MODI_ID(DIPV6_31_0, data->level)},
1913 : : };
1914 : : /* First mask to be modified is the mask of 4th address byte. */
1915 : : uint32_t midx = 3;
1916 : :
1917 : : MLX5_ASSERT(data->offset + width <= 128);
1918 : 0 : off_be = 128 - (data->offset + width);
1919 [ # # ]: 0 : while (width > 0 && midx > 0) {
1920 [ # # ]: 0 : if (off_be < 32) {
1921 : 0 : info[idx] = fields[midx];
1922 : 0 : length = off_be + width <= 32 ?
1923 [ # # ]: 0 : width : 32 - off_be;
1924 [ # # ]: 0 : if (mask)
1925 [ # # ]: 0 : mask[midx] = flow_modify_info_mask_32
1926 : : (length, off_be);
1927 : : else
1928 : 0 : info[idx].offset = off_be;
1929 : 0 : width -= length;
1930 : : off_be = 0;
1931 : 0 : idx++;
1932 : : } else {
1933 : 0 : off_be -= 32;
1934 : : }
1935 : 0 : midx--;
1936 : : }
1937 [ # # ]: 0 : if (!width)
1938 : : break;
1939 : 0 : info[idx] = fields[midx];
1940 [ # # ]: 0 : if (mask)
1941 [ # # ]: 0 : mask[midx] = flow_modify_info_mask_32(width, off_be);
1942 : : else
1943 : 0 : info[idx].offset = off_be;
1944 : : break;
1945 : : }
1946 : 0 : case RTE_FLOW_FIELD_TCP_PORT_SRC:
1947 : : MLX5_ASSERT(data->offset + width <= 16);
1948 : 0 : off_be = 16 - (data->offset + width);
1949 [ # # ]: 0 : modi_id = CALC_MODI_ID(TCP_SPORT, data->level);
1950 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
1951 [ # # ]: 0 : if (mask)
1952 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1953 : : else
1954 : 0 : info[idx].offset = off_be;
1955 : : break;
1956 : 0 : case RTE_FLOW_FIELD_TCP_PORT_DST:
1957 : : MLX5_ASSERT(data->offset + width <= 16);
1958 : 0 : off_be = 16 - (data->offset + width);
1959 [ # # ]: 0 : modi_id = CALC_MODI_ID(TCP_DPORT, data->level);
1960 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
1961 [ # # ]: 0 : if (mask)
1962 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1963 : : else
1964 : 0 : info[idx].offset = off_be;
1965 : : break;
1966 : 0 : case RTE_FLOW_FIELD_TCP_SEQ_NUM:
1967 : : MLX5_ASSERT(data->offset + width <= 32);
1968 : 0 : off_be = 32 - (data->offset + width);
1969 [ # # ]: 0 : modi_id = CALC_MODI_ID(TCP_SEQ_NUM, data->level);
1970 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1971 [ # # ]: 0 : if (mask)
1972 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1973 : : else
1974 : 0 : info[idx].offset = off_be;
1975 : : break;
1976 : 0 : case RTE_FLOW_FIELD_TCP_ACK_NUM:
1977 : : MLX5_ASSERT(data->offset + width <= 32);
1978 : 0 : off_be = 32 - (data->offset + width);
1979 [ # # ]: 0 : modi_id = CALC_MODI_ID(TCP_ACK_NUM, data->level);
1980 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1981 [ # # ]: 0 : if (mask)
1982 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1983 : : else
1984 : 0 : info[idx].offset = off_be;
1985 : : break;
1986 : 0 : case RTE_FLOW_FIELD_TCP_FLAGS:
1987 : : MLX5_ASSERT(data->offset + width <= 9);
1988 : 0 : off_be = 9 - (data->offset + width);
1989 [ # # ]: 0 : modi_id = CALC_MODI_ID(TCP_FLAGS, data->level);
1990 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
1991 [ # # ]: 0 : if (mask)
1992 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1993 : : else
1994 : 0 : info[idx].offset = off_be;
1995 : : break;
1996 : 0 : case RTE_FLOW_FIELD_TCP_DATA_OFFSET:
1997 : : MLX5_ASSERT(data->offset + width <= 4);
1998 : 0 : off_be = 4 - (data->offset + width);
1999 [ # # ]: 0 : modi_id = CALC_MODI_ID(TCP_DATA_OFFSET, data->level);
2000 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
2001 [ # # ]: 0 : if (mask)
2002 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
2003 : : else
2004 : 0 : info[idx].offset = off_be;
2005 : : break;
2006 : 0 : case RTE_FLOW_FIELD_UDP_PORT_SRC:
2007 : : MLX5_ASSERT(data->offset + width <= 16);
2008 : 0 : off_be = 16 - (data->offset + width);
2009 [ # # ]: 0 : modi_id = CALC_MODI_ID(UDP_SPORT, data->level);
2010 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
2011 [ # # ]: 0 : if (mask)
2012 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
2013 : : else
2014 : 0 : info[idx].offset = off_be;
2015 : : break;
2016 : 0 : case RTE_FLOW_FIELD_UDP_PORT_DST:
2017 : : MLX5_ASSERT(data->offset + width <= 16);
2018 : 0 : off_be = 16 - (data->offset + width);
2019 [ # # ]: 0 : modi_id = CALC_MODI_ID(UDP_DPORT, data->level);
2020 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
2021 [ # # ]: 0 : if (mask)
2022 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
2023 : : else
2024 : 0 : info[idx].offset = off_be;
2025 : : break;
2026 : 0 : case RTE_FLOW_FIELD_VXLAN_VNI:
2027 : : case RTE_FLOW_FIELD_GENEVE_VNI:
2028 : : MLX5_ASSERT(data->offset + width <= 24);
2029 : : /* VNI is on bits 31-8 of TUNNEL_HDR_DW_1. */
2030 : 0 : off_be = 24 - (data->offset + width) + 8;
2031 : 0 : info[idx] = (struct field_modify_info){4, 0,
2032 : : MLX5_MODI_TUNNEL_HDR_DW_1};
2033 [ # # ]: 0 : if (mask)
2034 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2035 : : else
2036 : 0 : info[idx].offset = off_be;
2037 : : break;
2038 : 0 : case RTE_FLOW_FIELD_VXLAN_LAST_RSVD:
2039 : : MLX5_ASSERT(data->offset + width <= 8);
2040 : : /* Last_rsvd is on bits 7-0 of TUNNEL_HDR_DW_1. */
2041 : 0 : off_be = 8 - (data->offset + width);
2042 : 0 : info[idx] = (struct field_modify_info){1, 0, MLX5_MODI_TUNNEL_HDR_DW_1};
2043 [ # # ]: 0 : if (mask)
2044 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
2045 : : else
2046 : 0 : info[idx].offset = off_be;
2047 : : break;
2048 : : case RTE_FLOW_FIELD_GENEVE_OPT_TYPE:
2049 : : MLX5_ASSERT(data->offset + width <= 8);
2050 : : modi_id = flow_geneve_opt_modi_field_get(priv, data);
2051 [ # # ]: 0 : if (modi_id < 0)
2052 : : return;
2053 : : /* Type is on bits 16-8 of GENEVE option header (DW0). */
2054 : 0 : off_be = 32 - (16 + data->offset + width);
2055 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
2056 [ # # ]: 0 : if (mask)
2057 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2058 : : else
2059 : 0 : info[idx].offset = off_be;
2060 : : break;
2061 : : case RTE_FLOW_FIELD_GENEVE_OPT_CLASS:
2062 : : MLX5_ASSERT(data->offset + width <= 16);
2063 : : modi_id = flow_geneve_opt_modi_field_get(priv, data);
2064 [ # # ]: 0 : if (modi_id < 0)
2065 : : return;
2066 : : /* Class is on bits 31-16 of GENEVE option header (DW0). */
2067 : 0 : off_be = 32 - (data->offset + width);
2068 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
2069 [ # # ]: 0 : if (mask)
2070 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2071 : : else
2072 : 0 : info[idx].offset = off_be;
2073 : : break;
2074 : 0 : case RTE_FLOW_FIELD_GENEVE_OPT_DATA:
2075 [ # # ]: 0 : if ((data->offset % 32) + width > 32) {
2076 : 0 : DRV_LOG(ERR, "Geneve TLV option data is per DW.");
2077 : 0 : return;
2078 : : }
2079 : : modi_id = flow_geneve_opt_modi_field_get(priv, data);
2080 [ # # ]: 0 : if (modi_id < 0)
2081 : : return;
2082 : : /* Use offset inside DW. */
2083 : 0 : off_be = 32 - ((data->offset % 32) + width);
2084 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
2085 [ # # ]: 0 : if (mask)
2086 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2087 : : else
2088 : 0 : info[idx].offset = off_be;
2089 : : break;
2090 : 0 : case RTE_FLOW_FIELD_GTP_TEID:
2091 : : MLX5_ASSERT(data->offset + width <= 32);
2092 : 0 : off_be = 32 - (data->offset + width);
2093 : 0 : info[idx] = (struct field_modify_info){4, 0,
2094 : : MLX5_MODI_GTP_TEID};
2095 [ # # ]: 0 : if (mask)
2096 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2097 : : else
2098 : 0 : info[idx].offset = off_be;
2099 : : break;
2100 : 0 : case RTE_FLOW_FIELD_MPLS:
2101 : : MLX5_ASSERT(data->offset + width <= 32);
2102 : 0 : off_be = 32 - (data->offset + width);
2103 : : modi_id = mlx5_mpls_modi_field_get(data);
2104 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
2105 [ # # ]: 0 : if (mask)
2106 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2107 : : else
2108 : 0 : info[idx].offset = off_be;
2109 : : break;
2110 : : case RTE_FLOW_FIELD_TAG:
2111 : : {
2112 : : MLX5_ASSERT(data->offset + width <= 32);
2113 : : uint8_t tag_index = flow_tag_index_get(data);
2114 : : int reg;
2115 : :
2116 : : off_be = (tag_index == RTE_PMD_MLX5_LINEAR_HASH_TAG_INDEX) ?
2117 [ # # ]: 0 : 16 - (data->offset + width) + 16 : data->offset;
2118 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
2119 [ # # ]: 0 : reg = flow_hw_get_reg_id(dev,
2120 : : RTE_FLOW_ITEM_TYPE_TAG,
2121 : : tag_index);
2122 : : else
2123 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG,
2124 : : tag_index, error);
2125 [ # # ]: 0 : if (reg < 0)
2126 : : return;
2127 : : MLX5_ASSERT(reg != REG_NON);
2128 [ # # ]: 0 : if ((unsigned int)reg >= RTE_DIM(mlx5_reg_to_field))
2129 : : return;
2130 : 0 : info[idx] = (struct field_modify_info){4, 0,
2131 : 0 : mlx5_reg_to_field[reg]};
2132 [ # # ]: 0 : if (mask)
2133 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2134 : : else
2135 : 0 : info[idx].offset = off_be;
2136 : : }
2137 : : break;
2138 : 0 : case RTE_FLOW_FIELD_MARK:
2139 : : {
2140 : 0 : uint32_t mark_mask = priv->sh->dv_mark_mask;
2141 : : uint32_t mark_count = rte_popcount32(mark_mask);
2142 : : RTE_SET_USED(mark_count);
2143 : : MLX5_ASSERT(data->offset + width <= mark_count);
2144 : 0 : int reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK,
2145 : : 0, error);
2146 [ # # ]: 0 : if (reg < 0)
2147 : : return;
2148 : : MLX5_ASSERT(reg != REG_NON);
2149 : : MLX5_ASSERT((unsigned int)reg < RTE_DIM(mlx5_reg_to_field));
2150 : 0 : info[idx] = (struct field_modify_info){4, 0,
2151 : 0 : mlx5_reg_to_field[reg]};
2152 [ # # ]: 0 : if (mask)
2153 : 0 : mask[idx] = flow_modify_info_mask_32_masked
2154 [ # # ]: 0 : (width, data->offset, mark_mask);
2155 : : else
2156 : 0 : info[idx].offset = data->offset;
2157 : : }
2158 : : break;
2159 : 0 : case RTE_FLOW_FIELD_META:
2160 : : {
2161 : 0 : uint32_t meta_mask = priv->sh->dv_meta_mask;
2162 : : uint32_t meta_count = rte_popcount32(meta_mask);
2163 : : RTE_SET_USED(meta_count);
2164 : : MLX5_ASSERT(data->offset + width <= meta_count);
2165 : 0 : int reg = flow_dv_get_metadata_reg(dev, attr, error);
2166 [ # # ]: 0 : if (reg < 0)
2167 : : return;
2168 : : MLX5_ASSERT(reg != REG_NON);
2169 : : MLX5_ASSERT((unsigned int)reg < RTE_DIM(mlx5_reg_to_field));
2170 : 0 : info[idx] = (struct field_modify_info){4, 0,
2171 : 0 : mlx5_reg_to_field[reg]};
2172 [ # # ]: 0 : if (mask)
2173 : 0 : mask[idx] = flow_modify_info_mask_32_masked
2174 [ # # ]: 0 : (width, data->offset, meta_mask);
2175 : : else
2176 : 0 : info[idx].offset = data->offset;
2177 : : }
2178 : : break;
2179 : 0 : case RTE_FLOW_FIELD_IPV4_ECN:
2180 : : MLX5_ASSERT(data->offset + width <= 2);
2181 : 0 : off_be = 2 - (data->offset + width);
2182 [ # # ]: 0 : modi_id = CALC_MODI_ID(IP_ECN, data->level);
2183 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
2184 [ # # ]: 0 : if (mask)
2185 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
2186 : : else
2187 : 0 : info[idx].offset = off_be;
2188 : : break;
2189 : 0 : case RTE_FLOW_FIELD_IPV6_ECN:
2190 : : MLX5_ASSERT(data->offset + width <= 2);
2191 [ # # ]: 0 : off_be = 2 - (data->offset + width);
2192 [ # # ]: 0 : if (mlx5_dv_modify_ipv6_traffic_class_supported(priv))
2193 : 0 : info[idx] = (struct field_modify_info){1, 0,
2194 : : MLX5_MODI_OUT_IPV6_TRAFFIC_CLASS};
2195 : : else
2196 : 0 : info[idx] = (struct field_modify_info){1, 0,
2197 : : MLX5_MODI_OUT_IP_ECN};
2198 [ # # ]: 0 : if (mask)
2199 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
2200 : : else
2201 : 0 : info[idx].offset = off_be;
2202 : : break;
2203 : 0 : case RTE_FLOW_FIELD_GTP_PSC_QFI:
2204 : : MLX5_ASSERT(data->offset + width <= 8);
2205 : 0 : off_be = data->offset + 8;
2206 : 0 : info[idx] = (struct field_modify_info){4, 0,
2207 : : MLX5_MODI_GTPU_FIRST_EXT_DW_0};
2208 [ # # ]: 0 : if (mask)
2209 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2210 : : else
2211 : 0 : info[idx].offset = off_be;
2212 : : break;
2213 : 0 : case MLX5_RTE_FLOW_FIELD_META_REG:
2214 : : {
2215 [ # # ]: 0 : uint32_t meta_mask = priv->sh->dv_meta_mask;
2216 : : uint32_t meta_count = rte_popcount32(meta_mask);
2217 : : uint8_t reg = flow_tag_index_get(data);
2218 : :
2219 : : RTE_SET_USED(meta_count);
2220 : : MLX5_ASSERT(data->offset + width <= meta_count);
2221 : : MLX5_ASSERT(reg != REG_NON);
2222 : : MLX5_ASSERT(reg < RTE_DIM(mlx5_reg_to_field));
2223 : 0 : info[idx] = (struct field_modify_info){4, 0, mlx5_reg_to_field[reg]};
2224 [ # # ]: 0 : if (mask)
2225 : 0 : mask[idx] = flow_modify_info_mask_32_masked
2226 [ # # ]: 0 : (width, data->offset, meta_mask);
2227 : : else
2228 : 0 : info[idx].offset = data->offset;
2229 : : }
2230 : : break;
2231 : 0 : case RTE_FLOW_FIELD_METER_COLOR:
2232 : : {
2233 : : const uint32_t color_mask =
2234 : : (UINT32_C(1) << MLX5_MTR_COLOR_BITS) - 1;
2235 : : int reg;
2236 : :
2237 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
2238 : : reg = flow_hw_get_reg_id
2239 : : (dev,
2240 : : RTE_FLOW_ITEM_TYPE_METER_COLOR, 0);
2241 : : else
2242 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR,
2243 : : 0, error);
2244 [ # # ]: 0 : if (reg < 0)
2245 : : return;
2246 : : MLX5_ASSERT(reg != REG_NON);
2247 [ # # ]: 0 : if ((unsigned int)reg >= RTE_DIM(mlx5_reg_to_field))
2248 : : return;
2249 : 0 : info[idx] = (struct field_modify_info){4, 0,
2250 : 0 : mlx5_reg_to_field[reg]};
2251 [ # # ]: 0 : if (mask)
2252 : 0 : mask[idx] = flow_modify_info_mask_32_masked
2253 [ # # ]: 0 : (width, data->offset, color_mask);
2254 : : else
2255 : 0 : info[idx].offset = data->offset;
2256 : : }
2257 : : break;
2258 : 0 : case RTE_FLOW_FIELD_IPV4_PROTO: /* Fall-through. */
2259 : : case RTE_FLOW_FIELD_IPV6_PROTO:
2260 : : MLX5_ASSERT(data->offset + width <= 8);
2261 : 0 : off_be = 8 - (data->offset + width);
2262 : 0 : info[idx] = (struct field_modify_info){1, 0, MLX5_MODI_OUT_IP_PROTOCOL};
2263 [ # # ]: 0 : if (mask)
2264 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
2265 : : else
2266 : 0 : info[idx].offset = off_be;
2267 : : break;
2268 : 0 : case RTE_FLOW_FIELD_ESP_PROTO:
2269 : : MLX5_ASSERT(data->offset + width <= 8);
2270 : 0 : off_be = 8 - (data->offset + width);
2271 : 0 : info[idx] = (struct field_modify_info){1, 0, MLX5_MODI_OUT_IPSEC_NEXT_HDR};
2272 [ # # ]: 0 : if (mask)
2273 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
2274 : : else
2275 : 0 : info[idx].offset = off_be;
2276 : : break;
2277 : 0 : case RTE_FLOW_FIELD_ESP_SPI:
2278 : : MLX5_ASSERT(data->offset + width <= 32);
2279 : 0 : off_be = 32 - (data->offset + width);
2280 [ # # ]: 0 : modi_id = CALC_MODI_ID(ESP_SPI, data->level);
2281 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
2282 [ # # ]: 0 : if (mask)
2283 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2284 : : else
2285 : 0 : info[idx].offset = off_be;
2286 : : break;
2287 : 0 : case RTE_FLOW_FIELD_ESP_SEQ_NUM:
2288 : : MLX5_ASSERT(data->offset + width <= 32);
2289 : 0 : off_be = 32 - (data->offset + width);
2290 [ # # ]: 0 : modi_id = CALC_MODI_ID(ESP_SEQ_NUM, data->level);
2291 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
2292 [ # # ]: 0 : if (mask)
2293 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2294 : : else
2295 : 0 : info[idx].offset = off_be;
2296 : : break;
2297 : 0 : case RTE_FLOW_FIELD_FLEX_ITEM:
2298 : : MLX5_ASSERT(data->flex_handle != NULL && !(data->offset & 0x7));
2299 : 0 : mlx5_modify_flex_item(dev, (const struct mlx5_flex_item *)data->flex_handle,
2300 : : data, info, mask, width);
2301 : 0 : break;
2302 : 0 : case RTE_FLOW_FIELD_HASH_RESULT:
2303 : : MLX5_ASSERT(data->offset + width <= 32);
2304 : 0 : off_be = 32 - (data->offset + width);
2305 : 0 : info[idx] = (struct field_modify_info){4, 0,
2306 : : MLX5_MODI_HASH_RESULT};
2307 [ # # ]: 0 : if (mask)
2308 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2309 : : else
2310 : 0 : info[idx].offset = off_be;
2311 : : break;
2312 : : case RTE_FLOW_FIELD_POINTER:
2313 : : case RTE_FLOW_FIELD_VALUE:
2314 : : default:
2315 : : MLX5_ASSERT(false);
2316 : : break;
2317 : : }
2318 : : }
2319 : :
2320 : : /**
2321 : : * Convert modify_field action to DV specification.
2322 : : *
2323 : : * @param[in] dev
2324 : : * Pointer to the rte_eth_dev structure.
2325 : : * @param[in,out] resource
2326 : : * Pointer to the modify-header resource.
2327 : : * @param[in] action
2328 : : * Pointer to action specification.
2329 : : * @param[in] attr
2330 : : * Attributes of flow that includes this item.
2331 : : * @param[out] error
2332 : : * Pointer to the error structure.
2333 : : *
2334 : : * @return
2335 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2336 : : */
2337 : : static int
2338 : 0 : flow_dv_convert_action_modify_field
2339 : : (struct rte_eth_dev *dev,
2340 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
2341 : : const struct rte_flow_action *action,
2342 : : const struct rte_flow_attr *attr,
2343 : : struct rte_flow_error *error)
2344 : : {
2345 : 0 : const struct rte_flow_action_modify_field *conf =
2346 : : (const struct rte_flow_action_modify_field *)(action->conf);
2347 : 0 : struct rte_flow_item item = {
2348 : : .spec = NULL,
2349 : : .mask = NULL
2350 : : };
2351 : 0 : struct field_modify_info field[MLX5_ACT_MAX_MOD_FIELDS] = {
2352 : : {0, 0, 0} };
2353 : 0 : struct field_modify_info dcopy[MLX5_ACT_MAX_MOD_FIELDS] = {
2354 : : {0, 0, 0} };
2355 : 0 : uint32_t mask[MLX5_ACT_MAX_MOD_FIELDS] = {0, 0, 0, 0, 0};
2356 : 0 : uint32_t type, meta = 0, dscp = 0;
2357 : :
2358 [ # # ]: 0 : if (conf->src.field == RTE_FLOW_FIELD_POINTER ||
2359 : : conf->src.field == RTE_FLOW_FIELD_VALUE) {
2360 : 0 : type = conf->operation == RTE_FLOW_MODIFY_SET ?
2361 [ # # ]: 0 : MLX5_MODIFICATION_TYPE_SET : MLX5_MODIFICATION_TYPE_ADD;
2362 : : /** For SET fill the destination field (field) first. */
2363 : 0 : mlx5_flow_field_id_to_modify_info(&conf->dst, field, mask,
2364 : 0 : conf->width, dev,
2365 : : attr, error);
2366 : 0 : item.spec = conf->src.field == RTE_FLOW_FIELD_POINTER ?
2367 [ # # ]: 0 : (void *)(uintptr_t)conf->src.pvalue :
2368 : : (void *)(uintptr_t)&conf->src.value;
2369 [ # # ]: 0 : if (conf->dst.field == RTE_FLOW_FIELD_META ||
2370 [ # # ]: 0 : conf->dst.field == RTE_FLOW_FIELD_TAG ||
2371 : : conf->dst.field == RTE_FLOW_FIELD_METER_COLOR) {
2372 : 0 : meta = *(const unaligned_uint32_t *)item.spec;
2373 [ # # ]: 0 : meta = rte_cpu_to_be_32(meta);
2374 : 0 : item.spec = &meta;
2375 : : }
2376 [ # # # # ]: 0 : if (mlx5_dv_modify_ipv6_traffic_class_supported(dev->data->dev_private) &&
2377 : 0 : conf->dst.field == RTE_FLOW_FIELD_IPV6_DSCP &&
2378 [ # # ]: 0 : !(mask[0] & MLX5_IPV6_HDR_ECN_MASK)) {
2379 : 0 : dscp = *(const unaligned_uint32_t *)item.spec;
2380 : : /*
2381 : : * IPv6 DSCP uses OUT_IPV6_TRAFFIC_CLASS as ID but it starts from 2
2382 : : * bits left. Shift the data left for IPv6 DSCP
2383 : : */
2384 : 0 : dscp <<= MLX5_IPV6_HDR_DSCP_SHIFT;
2385 : 0 : item.spec = &dscp;
2386 : : }
2387 : : } else {
2388 : : type = MLX5_MODIFICATION_TYPE_COPY;
2389 : : /** For COPY fill the destination field (dcopy) without mask. */
2390 : 0 : mlx5_flow_field_id_to_modify_info(&conf->dst, dcopy, NULL,
2391 : 0 : conf->width, dev,
2392 : : attr, error);
2393 : : /** Then construct the source field (field) with mask. */
2394 : 0 : mlx5_flow_field_id_to_modify_info(&conf->src, field, mask,
2395 : 0 : conf->width, dev,
2396 : : attr, error);
2397 : : }
2398 : 0 : item.mask = &mask;
2399 : 0 : return mlx5_flow_dv_convert_modify_action(&item,
2400 : : field, dcopy, resource, type, error);
2401 : : }
2402 : :
2403 : : /**
2404 : : * Validate MARK item.
2405 : : *
2406 : : * @param[in] dev
2407 : : * Pointer to the rte_eth_dev structure.
2408 : : * @param[in] item
2409 : : * Item specification.
2410 : : * @param[in] attr
2411 : : * Attributes of flow that includes this item.
2412 : : * @param[out] error
2413 : : * Pointer to error structure.
2414 : : *
2415 : : * @return
2416 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2417 : : */
2418 : : static int
2419 : 0 : flow_dv_validate_item_mark(struct rte_eth_dev *dev,
2420 : : const struct rte_flow_item *item,
2421 : : const struct rte_flow_attr *attr __rte_unused,
2422 : : struct rte_flow_error *error)
2423 : : {
2424 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2425 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
2426 : 0 : const struct rte_flow_item_mark *spec = item->spec;
2427 : 0 : const struct rte_flow_item_mark *mask = item->mask;
2428 : 0 : const struct rte_flow_item_mark nic_mask = {
2429 : 0 : .id = priv->sh->dv_mark_mask,
2430 : : };
2431 : : int ret;
2432 : :
2433 [ # # ]: 0 : if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
2434 : 0 : return rte_flow_error_set(error, ENOTSUP,
2435 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2436 : : "extended metadata feature"
2437 : : " isn't enabled");
2438 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
2439 : 0 : return rte_flow_error_set(error, ENOTSUP,
2440 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2441 : : "extended metadata register"
2442 : : " isn't supported");
2443 [ # # ]: 0 : if (!nic_mask.id)
2444 : 0 : return rte_flow_error_set(error, ENOTSUP,
2445 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2446 : : "extended metadata register"
2447 : : " isn't available");
2448 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
2449 [ # # ]: 0 : if (ret < 0)
2450 : : return ret;
2451 [ # # ]: 0 : if (!spec)
2452 : 0 : return rte_flow_error_set(error, EINVAL,
2453 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2454 : 0 : item->spec,
2455 : : "data cannot be empty");
2456 [ # # ]: 0 : if (spec->id >= (MLX5_FLOW_MARK_MAX & nic_mask.id))
2457 : 0 : return rte_flow_error_set(error, EINVAL,
2458 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2459 : 0 : &spec->id,
2460 : : "mark id exceeds the limit");
2461 [ # # ]: 0 : if (!mask)
2462 : : mask = &nic_mask;
2463 [ # # ]: 0 : if (!mask->id)
2464 : 0 : return rte_flow_error_set(error, EINVAL,
2465 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2466 : : "mask cannot be zero");
2467 : :
2468 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2469 : : (const uint8_t *)&nic_mask,
2470 : : sizeof(struct rte_flow_item_mark),
2471 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2472 : : if (ret < 0)
2473 : : return ret;
2474 : : return 0;
2475 : : }
2476 : :
2477 : : /**
2478 : : * Validate META item.
2479 : : *
2480 : : * @param[in] dev
2481 : : * Pointer to the rte_eth_dev structure.
2482 : : * @param[in] item
2483 : : * Item specification.
2484 : : * @param[in] attr
2485 : : * Attributes of flow that includes this item.
2486 : : * @param[out] error
2487 : : * Pointer to error structure.
2488 : : *
2489 : : * @return
2490 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2491 : : */
2492 : : static int
2493 : 0 : flow_dv_validate_item_meta(struct rte_eth_dev *dev __rte_unused,
2494 : : const struct rte_flow_item *item,
2495 : : const struct rte_flow_attr *attr,
2496 : : struct rte_flow_error *error)
2497 : : {
2498 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2499 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
2500 : 0 : const struct rte_flow_item_meta *spec = item->spec;
2501 : 0 : const struct rte_flow_item_meta *mask = item->mask;
2502 : 0 : struct rte_flow_item_meta nic_mask = {
2503 : : .data = UINT32_MAX
2504 : : };
2505 : : int reg;
2506 : : int ret;
2507 : :
2508 [ # # ]: 0 : if (!spec)
2509 : 0 : return rte_flow_error_set(error, EINVAL,
2510 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2511 : : item->spec,
2512 : : "data cannot be empty");
2513 [ # # ]: 0 : if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
2514 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
2515 : 0 : return rte_flow_error_set(error, ENOTSUP,
2516 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2517 : : "extended metadata register"
2518 : : " isn't supported");
2519 : 0 : reg = flow_dv_get_metadata_reg(dev, attr, error);
2520 [ # # ]: 0 : if (reg < 0)
2521 : : return reg;
2522 [ # # ]: 0 : if (reg == REG_NON)
2523 : 0 : return rte_flow_error_set(error, ENOTSUP,
2524 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2525 : : "unavailable extended metadata register");
2526 [ # # ]: 0 : if (reg == REG_B)
2527 : 0 : return rte_flow_error_set(error, ENOTSUP,
2528 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2529 : : "match on reg_b "
2530 : : "isn't supported");
2531 [ # # ]: 0 : if (reg != REG_A)
2532 : 0 : nic_mask.data = priv->sh->dv_meta_mask;
2533 : : } else {
2534 [ # # ]: 0 : if (attr->transfer)
2535 : 0 : return rte_flow_error_set(error, ENOTSUP,
2536 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2537 : : "extended metadata feature "
2538 : : "should be enabled when "
2539 : : "meta item is requested "
2540 : : "with e-switch mode ");
2541 [ # # ]: 0 : if (attr->ingress)
2542 : 0 : return rte_flow_error_set(error, ENOTSUP,
2543 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2544 : : "match on metadata for ingress "
2545 : : "is not supported in legacy "
2546 : : "metadata mode");
2547 : : }
2548 [ # # ]: 0 : if (!mask)
2549 : : mask = &rte_flow_item_meta_mask;
2550 [ # # ]: 0 : if (!mask->data)
2551 : 0 : return rte_flow_error_set(error, EINVAL,
2552 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2553 : : "mask cannot be zero");
2554 : :
2555 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2556 : : (const uint8_t *)&nic_mask,
2557 : : sizeof(struct rte_flow_item_meta),
2558 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2559 : 0 : return ret;
2560 : : }
2561 : :
2562 : : /**
2563 : : * Validate TAG item.
2564 : : *
2565 : : * @param[in] dev
2566 : : * Pointer to the rte_eth_dev structure.
2567 : : * @param[in] item
2568 : : * Item specification.
2569 : : * @param[in] tag_bitmap
2570 : : * Tag index bitmap.
2571 : : * @param[in] attr
2572 : : * Attributes of flow that includes this item.
2573 : : * @param[out] error
2574 : : * Pointer to error structure.
2575 : : *
2576 : : * @return
2577 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2578 : : */
2579 : : static int
2580 : 0 : flow_dv_validate_item_tag(struct rte_eth_dev *dev,
2581 : : const struct rte_flow_item *item,
2582 : : uint32_t *tag_bitmap,
2583 : : const struct rte_flow_attr *attr __rte_unused,
2584 : : struct rte_flow_error *error)
2585 : : {
2586 : 0 : const struct rte_flow_item_tag *spec = item->spec;
2587 : 0 : const struct rte_flow_item_tag *mask = item->mask;
2588 : 0 : const struct rte_flow_item_tag nic_mask = {
2589 : : .data = RTE_BE32(UINT32_MAX),
2590 : : .index = 0xff,
2591 : : };
2592 : : int ret;
2593 : :
2594 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
2595 : 0 : return rte_flow_error_set(error, ENOTSUP,
2596 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2597 : : "extensive metadata register"
2598 : : " isn't supported");
2599 [ # # ]: 0 : if (!spec)
2600 : 0 : return rte_flow_error_set(error, EINVAL,
2601 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2602 : 0 : item->spec,
2603 : : "data cannot be empty");
2604 [ # # ]: 0 : if (!mask)
2605 : : mask = &rte_flow_item_tag_mask;
2606 [ # # ]: 0 : if (!mask->data)
2607 : 0 : return rte_flow_error_set(error, EINVAL,
2608 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2609 : : "mask cannot be zero");
2610 : :
2611 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2612 : : (const uint8_t *)&nic_mask,
2613 : : sizeof(struct rte_flow_item_tag),
2614 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2615 [ # # ]: 0 : if (ret < 0)
2616 : : return ret;
2617 [ # # ]: 0 : if (mask->index != 0xff)
2618 : 0 : return rte_flow_error_set(error, EINVAL,
2619 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2620 : : "partial mask for tag index"
2621 : : " is not supported");
2622 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, spec->index, error);
2623 [ # # ]: 0 : if (ret < 0)
2624 : : return ret;
2625 : : MLX5_ASSERT(ret != REG_NON);
2626 [ # # ]: 0 : if (*tag_bitmap & (1 << ret))
2627 : 0 : return rte_flow_error_set(error, EINVAL,
2628 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2629 : 0 : item->spec,
2630 : : "Duplicated tag index");
2631 : 0 : *tag_bitmap |= 1 << ret;
2632 : 0 : return 0;
2633 : : }
2634 : :
2635 : : /**
2636 : : * Validate vport item.
2637 : : *
2638 : : * @param[in] dev
2639 : : * Pointer to the rte_eth_dev structure.
2640 : : * @param[in] item
2641 : : * Item specification.
2642 : : * @param[in] attr
2643 : : * Attributes of flow that includes this item.
2644 : : * @param[in] item_flags
2645 : : * Bit-fields that holds the items detected until now.
2646 : : * @param[out] error
2647 : : * Pointer to error structure.
2648 : : *
2649 : : * @return
2650 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2651 : : */
2652 : : static int
2653 : 0 : flow_dv_validate_item_port_id(struct rte_eth_dev *dev,
2654 : : const struct rte_flow_item *item,
2655 : : const struct rte_flow_attr *attr,
2656 : : uint64_t item_flags,
2657 : : struct mlx5_priv **act_priv,
2658 : : struct rte_flow_error *error)
2659 : : {
2660 : 0 : const struct rte_flow_item_port_id *spec = item->spec;
2661 : 0 : const struct rte_flow_item_port_id *mask = item->mask;
2662 : 0 : const struct rte_flow_item_port_id switch_mask = {
2663 : : .id = 0xffffffff,
2664 : : };
2665 : : struct mlx5_priv *esw_priv;
2666 : : struct mlx5_priv *dev_priv;
2667 : : int ret;
2668 : :
2669 [ # # ]: 0 : if (!attr->transfer)
2670 : 0 : return rte_flow_error_set(error, EINVAL,
2671 : : RTE_FLOW_ERROR_TYPE_ITEM,
2672 : : NULL,
2673 : : "match on port id is valid only"
2674 : : " when transfer flag is enabled");
2675 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_PORT_ID)
2676 : 0 : return rte_flow_error_set(error, ENOTSUP,
2677 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2678 : : "multiple source ports are not"
2679 : : " supported");
2680 [ # # ]: 0 : if (!mask)
2681 : : mask = &switch_mask;
2682 [ # # ]: 0 : if (mask->id != 0xffffffff)
2683 : 0 : return rte_flow_error_set(error, ENOTSUP,
2684 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK,
2685 : : mask,
2686 : : "no support for partial mask on"
2687 : : " \"id\" field");
2688 : 0 : ret = mlx5_flow_item_acceptable
2689 : : (dev, item, (const uint8_t *)mask,
2690 : : (const uint8_t *)&rte_flow_item_port_id_mask,
2691 : : sizeof(struct rte_flow_item_port_id),
2692 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2693 [ # # ]: 0 : if (ret)
2694 : : return ret;
2695 [ # # ]: 0 : if (!spec)
2696 : : return 0;
2697 [ # # ]: 0 : if (spec->id == MLX5_PORT_ESW_MGR)
2698 : : return 0;
2699 : 0 : esw_priv = mlx5_port_to_eswitch_info(spec->id, false);
2700 [ # # ]: 0 : if (!esw_priv)
2701 : 0 : return rte_flow_error_set(error, rte_errno,
2702 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2703 : : "failed to obtain E-Switch info for"
2704 : : " port");
2705 : 0 : dev_priv = mlx5_dev_to_eswitch_info(dev);
2706 [ # # ]: 0 : if (!dev_priv)
2707 : 0 : return rte_flow_error_set(error, rte_errno,
2708 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2709 : : NULL,
2710 : : "failed to obtain E-Switch info");
2711 [ # # ]: 0 : if (esw_priv->domain_id != dev_priv->domain_id)
2712 : 0 : return rte_flow_error_set(error, EINVAL,
2713 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2714 : : "cannot match on a port from a"
2715 : : " different E-Switch");
2716 : 0 : *act_priv = esw_priv;
2717 : 0 : return 0;
2718 : : }
2719 : :
2720 : : /**
2721 : : * Validate represented port item.
2722 : : *
2723 : : * @param[in] dev
2724 : : * Pointer to the rte_eth_dev structure.
2725 : : * @param[in] item
2726 : : * Item specification.
2727 : : * @param[in] attr
2728 : : * Attributes of flow that includes this item.
2729 : : * @param[in] item_flags
2730 : : * Bit-fields that holds the items detected until now.
2731 : : * @param[out] error
2732 : : * Pointer to error structure.
2733 : : *
2734 : : * @return
2735 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2736 : : */
2737 : : static int
2738 : 0 : flow_dv_validate_item_represented_port(struct rte_eth_dev *dev,
2739 : : const struct rte_flow_item *item,
2740 : : const struct rte_flow_attr *attr,
2741 : : uint64_t item_flags,
2742 : : struct mlx5_priv **act_priv,
2743 : : struct rte_flow_error *error)
2744 : : {
2745 : 0 : const struct rte_flow_item_ethdev *spec = item->spec;
2746 : 0 : const struct rte_flow_item_ethdev *mask = item->mask;
2747 : 0 : const struct rte_flow_item_ethdev switch_mask = {
2748 : : .port_id = UINT16_MAX,
2749 : : };
2750 : : struct mlx5_priv *esw_priv;
2751 : : struct mlx5_priv *dev_priv;
2752 : : int ret;
2753 : :
2754 [ # # ]: 0 : if (!attr->transfer)
2755 : 0 : return rte_flow_error_set(error, EINVAL,
2756 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2757 : : "match on port id is valid only when transfer flag is enabled");
2758 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_REPRESENTED_PORT)
2759 : 0 : return rte_flow_error_set(error, ENOTSUP,
2760 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2761 : : "multiple source ports are not supported");
2762 [ # # ]: 0 : if (!mask)
2763 : : mask = &switch_mask;
2764 [ # # ]: 0 : if (mask->port_id != UINT16_MAX)
2765 : 0 : return rte_flow_error_set(error, ENOTSUP,
2766 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2767 : : "no support for partial mask on \"id\" field");
2768 : 0 : ret = mlx5_flow_item_acceptable
2769 : : (dev, item, (const uint8_t *)mask,
2770 : : (const uint8_t *)&rte_flow_item_ethdev_mask,
2771 : : sizeof(struct rte_flow_item_ethdev),
2772 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2773 [ # # ]: 0 : if (ret)
2774 : : return ret;
2775 [ # # # # ]: 0 : if (!spec || spec->port_id == UINT16_MAX)
2776 : : return 0;
2777 : 0 : esw_priv = mlx5_port_to_eswitch_info(spec->port_id, false);
2778 [ # # ]: 0 : if (!esw_priv)
2779 : 0 : return rte_flow_error_set(error, rte_errno,
2780 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2781 : : "failed to obtain E-Switch info for port");
2782 : 0 : dev_priv = mlx5_dev_to_eswitch_info(dev);
2783 [ # # ]: 0 : if (!dev_priv)
2784 : 0 : return rte_flow_error_set(error, rte_errno,
2785 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2786 : : NULL,
2787 : : "failed to obtain E-Switch info");
2788 [ # # ]: 0 : if (esw_priv->domain_id != dev_priv->domain_id)
2789 : 0 : return rte_flow_error_set(error, EINVAL,
2790 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2791 : : "cannot match on a port from a different E-Switch");
2792 : 0 : *act_priv = esw_priv;
2793 : 0 : return 0;
2794 : : }
2795 : :
2796 : : /**
2797 : : * Validate VLAN item.
2798 : : *
2799 : : * @param[in] item
2800 : : * Item specification.
2801 : : * @param[in] item_flags
2802 : : * Bit-fields that holds the items detected until now.
2803 : : * @param[in] dev
2804 : : * Ethernet device flow is being created on.
2805 : : * @param[out] error
2806 : : * Pointer to error structure.
2807 : : *
2808 : : * @return
2809 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2810 : : */
2811 : : int
2812 : 0 : mlx5_flow_dv_validate_item_vlan(const struct rte_flow_item *item,
2813 : : uint64_t item_flags,
2814 : : struct rte_eth_dev *dev,
2815 : : struct rte_flow_error *error)
2816 : : {
2817 : 0 : const struct rte_flow_item_vlan *mask = item->mask;
2818 : 0 : const struct rte_flow_item_vlan nic_mask = {
2819 : : .hdr.vlan_tci = RTE_BE16(UINT16_MAX),
2820 : : .hdr.eth_proto = RTE_BE16(UINT16_MAX),
2821 : : .has_more_vlan = 1,
2822 : : };
2823 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2824 : : int ret;
2825 : : const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
2826 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L4) :
2827 : : (MLX5_FLOW_LAYER_OUTER_L3 |
2828 : : MLX5_FLOW_LAYER_OUTER_L4);
2829 [ # # ]: 0 : const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
2830 : : MLX5_FLOW_LAYER_OUTER_VLAN;
2831 : :
2832 [ # # ]: 0 : if (item_flags & vlanm)
2833 : 0 : return rte_flow_error_set(error, EINVAL,
2834 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2835 : : "multiple VLAN layers not supported");
2836 [ # # ]: 0 : else if ((item_flags & l34m) != 0)
2837 : 0 : return rte_flow_error_set(error, EINVAL,
2838 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2839 : : "VLAN cannot follow L3/L4 layer");
2840 [ # # ]: 0 : if (!mask)
2841 : : mask = &rte_flow_item_vlan_mask;
2842 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2843 : : (const uint8_t *)&nic_mask,
2844 : : sizeof(struct rte_flow_item_vlan),
2845 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2846 [ # # ]: 0 : if (ret)
2847 : : return ret;
2848 [ # # # # ]: 0 : if (!tunnel && mask->hdr.vlan_tci != RTE_BE16(0x0fff)) {
2849 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2850 : :
2851 [ # # ]: 0 : if (priv->vmwa_context) {
2852 : : /*
2853 : : * Non-NULL context means we have a virtual machine
2854 : : * and SR-IOV enabled, we have to create VLAN interface
2855 : : * to make hypervisor to setup E-Switch vport
2856 : : * context correctly. We avoid creating the multiple
2857 : : * VLAN interfaces, so we cannot support VLAN tag mask.
2858 : : */
2859 : 0 : return rte_flow_error_set(error, EINVAL,
2860 : : RTE_FLOW_ERROR_TYPE_ITEM,
2861 : : item,
2862 : : "VLAN tag mask is not"
2863 : : " supported in virtual"
2864 : : " environment");
2865 : : }
2866 : : }
2867 : : return 0;
2868 : : }
2869 : :
2870 : : /*
2871 : : * GTP flags are contained in 1 byte of the format:
2872 : : * -------------------------------------------
2873 : : * | bit | 0 - 2 | 3 | 4 | 5 | 6 | 7 |
2874 : : * |-----------------------------------------|
2875 : : * | value | Version | PT | Res | E | S | PN |
2876 : : * -------------------------------------------
2877 : : *
2878 : : * Matching is supported only for GTP flags E, S, PN.
2879 : : */
2880 : : #define MLX5_GTP_FLAGS_MASK 0x07
2881 : :
2882 : : /**
2883 : : * Validate GTP item.
2884 : : *
2885 : : * @param[in] dev
2886 : : * Pointer to the rte_eth_dev structure.
2887 : : * @param[in] item
2888 : : * Item specification.
2889 : : * @param[in] item_flags
2890 : : * Bit-fields that holds the items detected until now.
2891 : : * @param[out] error
2892 : : * Pointer to error structure.
2893 : : *
2894 : : * @return
2895 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2896 : : */
2897 : : int
2898 : 0 : mlx5_flow_dv_validate_item_gtp(struct rte_eth_dev *dev,
2899 : : const struct rte_flow_item *item,
2900 : : uint64_t item_flags,
2901 : : struct rte_flow_error *error)
2902 : : {
2903 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2904 : 0 : const struct rte_flow_item_gtp *spec = item->spec;
2905 : 0 : const struct rte_flow_item_gtp *mask = item->mask;
2906 : 0 : const struct rte_flow_item_gtp nic_mask = {
2907 : : .hdr.gtp_hdr_info = MLX5_GTP_FLAGS_MASK,
2908 : : .hdr.msg_type = 0xff,
2909 : : .hdr.teid = RTE_BE32(0xffffffff),
2910 : : };
2911 : :
2912 [ # # ]: 0 : if (!priv->sh->cdev->config.hca_attr.tunnel_stateless_gtp)
2913 : 0 : return rte_flow_error_set(error, ENOTSUP,
2914 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2915 : : "GTP support is not enabled");
2916 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2917 : 0 : return rte_flow_error_set(error, ENOTSUP,
2918 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2919 : : "multiple tunnel layers not"
2920 : : " supported");
2921 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
2922 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2923 : 0 : return rte_flow_error_set(error, EINVAL,
2924 : : RTE_FLOW_ERROR_TYPE_ITEM,
2925 : : item, "no outer UDP layer found");
2926 : : }
2927 [ # # ]: 0 : if (!mask)
2928 : : mask = &rte_flow_item_gtp_mask;
2929 [ # # # # ]: 0 : if (spec && spec->hdr.gtp_hdr_info & ~MLX5_GTP_FLAGS_MASK)
2930 : 0 : return rte_flow_error_set(error, ENOTSUP,
2931 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2932 : : "Match is supported for GTP"
2933 : : " flags only");
2934 : 0 : return mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2935 : : (const uint8_t *)&nic_mask,
2936 : : sizeof(struct rte_flow_item_gtp),
2937 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2938 : : }
2939 : :
2940 : : /**
2941 : : * Validate GTP PSC item.
2942 : : *
2943 : : * @param[in] item
2944 : : * Item specification.
2945 : : * @param[in] last_item
2946 : : * Previous validated item in the pattern items.
2947 : : * @param[in] gtp_item
2948 : : * Previous GTP item specification.
2949 : : * @param root
2950 : : * Whether action is on root table.
2951 : : * @param[out] error
2952 : : * Pointer to error structure.
2953 : : *
2954 : : * @return
2955 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2956 : : */
2957 : : int
2958 : 0 : mlx5_flow_dv_validate_item_gtp_psc(const struct rte_eth_dev *dev,
2959 : : const struct rte_flow_item *item,
2960 : : uint64_t last_item,
2961 : : const struct rte_flow_item *gtp_item,
2962 : : bool root,
2963 : : struct rte_flow_error *error)
2964 : : {
2965 : : const struct rte_flow_item_gtp *gtp_spec;
2966 : : const struct rte_flow_item_gtp *gtp_mask;
2967 : : const struct rte_flow_item_gtp_psc *mask;
2968 : 0 : const struct rte_flow_item_gtp_psc nic_mask = {
2969 : : .hdr.type = 0xF,
2970 : : .hdr.qfi = 0x3F,
2971 : : };
2972 : :
2973 [ # # # # ]: 0 : if (!gtp_item || !(last_item & MLX5_FLOW_LAYER_GTP))
2974 : 0 : return rte_flow_error_set
2975 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2976 : : "GTP PSC item must be preceded with GTP item");
2977 : 0 : gtp_spec = gtp_item->spec;
2978 [ # # ]: 0 : gtp_mask = gtp_item->mask ? gtp_item->mask : &rte_flow_item_gtp_mask;
2979 : : /* GTP spec and E flag is requested to match zero. */
2980 [ # # ]: 0 : if (gtp_spec &&
2981 : 0 : (gtp_mask->hdr.gtp_hdr_info &
2982 [ # # ]: 0 : ~gtp_spec->hdr.gtp_hdr_info & MLX5_GTP_EXT_HEADER_FLAG))
2983 : 0 : return rte_flow_error_set
2984 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2985 : : "GTP E flag must be 1 to match GTP PSC");
2986 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
2987 : : /* Check the flow is not created in group zero. */
2988 [ # # ]: 0 : if (root)
2989 : 0 : return rte_flow_error_set
2990 : : (error, ENOTSUP,
2991 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2992 : : "GTP PSC is not supported for group 0");
2993 : : /* GTP spec is here and E flag is requested to match zero. */
2994 [ # # ]: 0 : if (!item->spec)
2995 : : return 0;
2996 : : }
2997 [ # # ]: 0 : mask = item->mask ? item->mask : &rte_flow_item_gtp_psc_mask;
2998 : 0 : return mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2999 : : (const uint8_t *)&nic_mask,
3000 : : sizeof(struct rte_flow_item_gtp_psc),
3001 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3002 : : }
3003 : :
3004 : : /*
3005 : : * Validate IPV4 item.
3006 : : * Use existing validation function mlx5_flow_validate_item_ipv4(), and
3007 : : * add specific validation of fragment_offset field,
3008 : : *
3009 : : * @param[in] dev
3010 : : * Pointer to the rte_eth_dev structure.
3011 : : * @param[in] item
3012 : : * Item specification.
3013 : : * @param[in] item_flags
3014 : : * Bit-fields that holds the items detected until now.
3015 : : * @param[in] last_item
3016 : : * Previous validated item in the pattern items.
3017 : : * @param[in] ether_type
3018 : : * Type in the ethernet layer header (including dot1q).
3019 : : * @param[in] acc_mask
3020 : : * Default acceptable mask (will be adjusted).
3021 : : * @param[out] error
3022 : : * Pointer to error structure.
3023 : : *
3024 : : * @return
3025 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3026 : : */
3027 : : int
3028 : 0 : mlx5_flow_dv_validate_item_ipv4(struct rte_eth_dev *dev,
3029 : : const struct rte_flow_item *item,
3030 : : uint64_t item_flags,
3031 : : uint64_t last_item,
3032 : : uint16_t ether_type,
3033 : : const struct rte_flow_item_ipv4 *acc_mask,
3034 : : struct rte_flow_error *error)
3035 : : {
3036 : : int ret;
3037 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3038 : 0 : struct mlx5_hca_attr *attr = &priv->sh->cdev->config.hca_attr;
3039 : 0 : const struct rte_flow_item_ipv4 *spec = item->spec;
3040 : 0 : const struct rte_flow_item_ipv4 *last = item->last;
3041 : 0 : const struct rte_flow_item_ipv4 *mask = item->mask;
3042 : : rte_be16_t fragment_offset_spec = 0;
3043 : : rte_be16_t fragment_offset_last = 0;
3044 : 0 : struct rte_flow_item_ipv4 actual_ipv4_mask = *acc_mask;
3045 : :
3046 [ # # # # ]: 0 : if (mask && (mask->hdr.version_ihl & RTE_IPV4_HDR_IHL_MASK)) {
3047 : 0 : int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
3048 : : bool ihl_cap = !tunnel ?
3049 [ # # ]: 0 : attr->outer_ipv4_ihl : attr->inner_ipv4_ihl;
3050 [ # # ]: 0 : if (!ihl_cap)
3051 : 0 : return rte_flow_error_set(error, ENOTSUP,
3052 : : RTE_FLOW_ERROR_TYPE_ITEM,
3053 : : item,
3054 : : "IPV4 ihl offload not supported");
3055 : 0 : actual_ipv4_mask.hdr.version_ihl = mask->hdr.version_ihl;
3056 : : }
3057 : 0 : ret = mlx5_flow_validate_item_ipv4(dev, item, item_flags, last_item,
3058 : : ether_type, &actual_ipv4_mask,
3059 : : MLX5_ITEM_RANGE_ACCEPTED, error);
3060 [ # # ]: 0 : if (ret < 0)
3061 : : return ret;
3062 [ # # ]: 0 : if (spec && mask)
3063 : 0 : fragment_offset_spec = spec->hdr.fragment_offset &
3064 : 0 : mask->hdr.fragment_offset;
3065 [ # # ]: 0 : if (!fragment_offset_spec)
3066 : : return 0;
3067 : : /*
3068 : : * spec and mask are valid, enforce using full mask to make sure the
3069 : : * complete value is used correctly.
3070 : : */
3071 [ # # ]: 0 : if ((mask->hdr.fragment_offset & RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
3072 : : != RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
3073 : 0 : return rte_flow_error_set(error, EINVAL,
3074 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK,
3075 : : item, "must use full mask for"
3076 : : " fragment_offset");
3077 : : /*
3078 : : * Match on fragment_offset 0x2000 means MF is 1 and frag-offset is 0,
3079 : : * indicating this is 1st fragment of fragmented packet.
3080 : : * This is not yet supported in MLX5, return appropriate error message.
3081 : : */
3082 [ # # ]: 0 : if (fragment_offset_spec == RTE_BE16(RTE_IPV4_HDR_MF_FLAG))
3083 : 0 : return rte_flow_error_set(error, ENOTSUP,
3084 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3085 : : "match on first fragment not "
3086 : : "supported");
3087 [ # # ]: 0 : if (fragment_offset_spec && !last)
3088 : 0 : return rte_flow_error_set(error, ENOTSUP,
3089 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3090 : : "specified value not supported");
3091 : : /* spec and last are valid, validate the specified range. */
3092 : 0 : fragment_offset_last = last->hdr.fragment_offset &
3093 : : mask->hdr.fragment_offset;
3094 : : /*
3095 : : * Match on fragment_offset spec 0x2001 and last 0x3fff
3096 : : * means MF is 1 and frag-offset is > 0.
3097 : : * This packet is fragment 2nd and onward, excluding last.
3098 : : * This is not yet supported in MLX5, return appropriate
3099 : : * error message.
3100 : : */
3101 : 0 : if (fragment_offset_spec == RTE_BE16(RTE_IPV4_HDR_MF_FLAG + 1) &&
3102 [ # # ]: 0 : fragment_offset_last == RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
3103 : 0 : return rte_flow_error_set(error, ENOTSUP,
3104 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST,
3105 : : last, "match on following "
3106 : : "fragments not supported");
3107 : : /*
3108 : : * Match on fragment_offset spec 0x0001 and last 0x1fff
3109 : : * means MF is 0 and frag-offset is > 0.
3110 : : * This packet is last fragment of fragmented packet.
3111 : : * This is not yet supported in MLX5, return appropriate
3112 : : * error message.
3113 : : */
3114 : 0 : if (fragment_offset_spec == RTE_BE16(1) &&
3115 [ # # ]: 0 : fragment_offset_last == RTE_BE16(RTE_IPV4_HDR_OFFSET_MASK))
3116 : 0 : return rte_flow_error_set(error, ENOTSUP,
3117 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST,
3118 : : last, "match on last "
3119 : : "fragment not supported");
3120 : : /*
3121 : : * Match on fragment_offset spec 0x0001 and last 0x3fff
3122 : : * means MF and/or frag-offset is not 0.
3123 : : * This is a fragmented packet.
3124 : : * Other range values are invalid and rejected.
3125 : : */
3126 : 0 : if (!(fragment_offset_spec == RTE_BE16(1) &&
3127 [ # # ]: 0 : fragment_offset_last == RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK)))
3128 : 0 : return rte_flow_error_set(error, ENOTSUP,
3129 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST, last,
3130 : : "specified range not supported");
3131 : : return 0;
3132 : : }
3133 : :
3134 : : /**
3135 : : * Validate IPV6 fragment extension item.
3136 : : *
3137 : : * @param[in] item
3138 : : * Item specification.
3139 : : * @param[in] item_flags
3140 : : * Bit-fields that holds the items detected until now.
3141 : : * @param[out] error
3142 : : * Pointer to error structure.
3143 : : *
3144 : : * @return
3145 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3146 : : */
3147 : : static int
3148 : 0 : flow_dv_validate_item_ipv6_frag_ext(const struct rte_eth_dev *dev,
3149 : : const struct rte_flow_item *item,
3150 : : uint64_t item_flags,
3151 : : struct rte_flow_error *error)
3152 : : {
3153 : 0 : const struct rte_flow_item_ipv6_frag_ext *spec = item->spec;
3154 : 0 : const struct rte_flow_item_ipv6_frag_ext *last = item->last;
3155 : 0 : const struct rte_flow_item_ipv6_frag_ext *mask = item->mask;
3156 : : rte_be16_t frag_data_spec = 0;
3157 : : rte_be16_t frag_data_last = 0;
3158 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
3159 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
3160 : : MLX5_FLOW_LAYER_OUTER_L4;
3161 : : int ret = 0;
3162 : 0 : struct rte_flow_item_ipv6_frag_ext nic_mask = {
3163 : : .hdr = {
3164 : : .next_header = 0xff,
3165 : : .frag_data = RTE_BE16(0xffff),
3166 : : },
3167 : : };
3168 : :
3169 [ # # ]: 0 : if (item_flags & l4m)
3170 : 0 : return rte_flow_error_set(error, EINVAL,
3171 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3172 : : "ipv6 fragment extension item cannot "
3173 : : "follow L4 item.");
3174 [ # # # # : 0 : if ((tunnel && !(item_flags & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
# # ]
3175 [ # # ]: 0 : (!tunnel && !(item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV6)))
3176 : 0 : return rte_flow_error_set(error, EINVAL,
3177 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3178 : : "ipv6 fragment extension item must "
3179 : : "follow ipv6 item");
3180 [ # # ]: 0 : if (spec && mask)
3181 : 0 : frag_data_spec = spec->hdr.frag_data & mask->hdr.frag_data;
3182 [ # # ]: 0 : if (!frag_data_spec)
3183 : : return 0;
3184 : : /*
3185 : : * spec and mask are valid, enforce using full mask to make sure the
3186 : : * complete value is used correctly.
3187 : : */
3188 [ # # ]: 0 : if ((mask->hdr.frag_data & RTE_BE16(RTE_IPV6_FRAG_USED_MASK)) !=
3189 : : RTE_BE16(RTE_IPV6_FRAG_USED_MASK))
3190 : 0 : return rte_flow_error_set(error, EINVAL,
3191 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK,
3192 : : item, "must use full mask for"
3193 : : " frag_data");
3194 : : /*
3195 : : * Match on frag_data 0x00001 means M is 1 and frag-offset is 0.
3196 : : * This is 1st fragment of fragmented packet.
3197 : : */
3198 [ # # ]: 0 : if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_MF_MASK))
3199 : 0 : return rte_flow_error_set(error, ENOTSUP,
3200 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3201 : : "match on first fragment not "
3202 : : "supported");
3203 [ # # ]: 0 : if (frag_data_spec && !last)
3204 : 0 : return rte_flow_error_set(error, EINVAL,
3205 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3206 : : "specified value not supported");
3207 : 0 : ret = mlx5_flow_item_acceptable
3208 : : (dev, item, (const uint8_t *)mask,
3209 : : (const uint8_t *)&nic_mask,
3210 : : sizeof(struct rte_flow_item_ipv6_frag_ext),
3211 : : MLX5_ITEM_RANGE_ACCEPTED, error);
3212 [ # # ]: 0 : if (ret)
3213 : : return ret;
3214 : : /* spec and last are valid, validate the specified range. */
3215 : 0 : frag_data_last = last->hdr.frag_data & mask->hdr.frag_data;
3216 : : /*
3217 : : * Match on frag_data spec 0x0009 and last 0xfff9
3218 : : * means M is 1 and frag-offset is > 0.
3219 : : * This packet is fragment 2nd and onward, excluding last.
3220 : : * This is not yet supported in MLX5, return appropriate
3221 : : * error message.
3222 : : */
3223 : 0 : if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_FO_ALIGN |
3224 : 0 : RTE_IPV6_EHDR_MF_MASK) &&
3225 [ # # ]: 0 : frag_data_last == RTE_BE16(RTE_IPV6_FRAG_USED_MASK))
3226 : 0 : return rte_flow_error_set(error, ENOTSUP,
3227 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST,
3228 : : last, "match on following "
3229 : : "fragments not supported");
3230 : : /*
3231 : : * Match on frag_data spec 0x0008 and last 0xfff8
3232 : : * means M is 0 and frag-offset is > 0.
3233 : : * This packet is last fragment of fragmented packet.
3234 : : * This is not yet supported in MLX5, return appropriate
3235 : : * error message.
3236 : : */
3237 : 0 : if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_FO_ALIGN) &&
3238 [ # # ]: 0 : frag_data_last == RTE_BE16(RTE_IPV6_EHDR_FO_MASK))
3239 : 0 : return rte_flow_error_set(error, ENOTSUP,
3240 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST,
3241 : : last, "match on last "
3242 : : "fragment not supported");
3243 : : /* Other range values are invalid and rejected. */
3244 : 0 : return rte_flow_error_set(error, EINVAL,
3245 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST, last,
3246 : : "specified range not supported");
3247 : : }
3248 : :
3249 : : /*
3250 : : * Validate ASO CT item.
3251 : : *
3252 : : * @param[in] dev
3253 : : * Pointer to the rte_eth_dev structure.
3254 : : * @param[in] item
3255 : : * Item specification.
3256 : : * @param[in] item_flags
3257 : : * Pointer to bit-fields that holds the items detected until now.
3258 : : * @param[out] error
3259 : : * Pointer to error structure.
3260 : : *
3261 : : * @return
3262 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3263 : : */
3264 : : int
3265 : 0 : mlx5_flow_dv_validate_item_aso_ct(struct rte_eth_dev *dev,
3266 : : const struct rte_flow_item *item,
3267 : : uint64_t *item_flags,
3268 : : struct rte_flow_error *error)
3269 : : {
3270 : 0 : const struct rte_flow_item_conntrack *spec = item->spec;
3271 : 0 : const struct rte_flow_item_conntrack *mask = item->mask;
3272 : : uint32_t flags;
3273 : :
3274 [ # # ]: 0 : if (*item_flags & MLX5_FLOW_LAYER_ASO_CT)
3275 : 0 : return rte_flow_error_set(error, EINVAL,
3276 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
3277 : : "Only one CT is supported");
3278 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
3279 [ # # ]: 0 : if (!mask)
3280 : : mask = &rte_flow_item_conntrack_mask;
3281 : 0 : flags = spec->flags & mask->flags;
3282 [ # # ]: 0 : if ((flags & RTE_FLOW_CONNTRACK_PKT_STATE_VALID) &&
3283 : : ((flags & RTE_FLOW_CONNTRACK_PKT_STATE_INVALID) ||
3284 [ # # ]: 0 : (flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD) ||
3285 : : (flags & RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED)))
3286 : 0 : return rte_flow_error_set(error, EINVAL,
3287 : : RTE_FLOW_ERROR_TYPE_ITEM,
3288 : : NULL,
3289 : : "Conflict status bits");
3290 [ # # ]: 0 : if (spec->flags & ~MLX5_FLOW_CONNTRACK_PKT_STATE_ALL)
3291 : 0 : return rte_flow_error_set(error, EINVAL,
3292 : : RTE_FLOW_ERROR_TYPE_ITEM,
3293 : : NULL,
3294 : : "Invalid CT item flags");
3295 : : }
3296 : : /* State change also needs to be considered. */
3297 : 0 : *item_flags |= MLX5_FLOW_LAYER_ASO_CT;
3298 : 0 : return 0;
3299 : : }
3300 : :
3301 : : /**
3302 : : * Validate the pop VLAN action.
3303 : : *
3304 : : * @param[in] dev
3305 : : * Pointer to the rte_eth_dev structure.
3306 : : * @param[in] action_flags
3307 : : * Holds the actions detected until now.
3308 : : * @param[in] action
3309 : : * Pointer to the pop vlan action.
3310 : : * @param[in] item_flags
3311 : : * The items found in this flow rule.
3312 : : * @param[in] attr
3313 : : * Pointer to flow attributes.
3314 : : * @param[out] error
3315 : : * Pointer to error structure.
3316 : : *
3317 : : * @return
3318 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3319 : : */
3320 : : static int
3321 : 0 : flow_dv_validate_action_pop_vlan(struct rte_eth_dev *dev,
3322 : : uint64_t action_flags,
3323 : : const struct rte_flow_action *action,
3324 : : uint64_t item_flags,
3325 : : const struct rte_flow_attr *attr,
3326 : : struct rte_flow_error *error)
3327 : : {
3328 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
3329 : :
3330 [ # # ]: 0 : if (!priv->sh->pop_vlan_action)
3331 : 0 : return rte_flow_error_set(error, ENOTSUP,
3332 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3333 : : NULL,
3334 : : "pop vlan action is not supported");
3335 [ # # ]: 0 : if (action_flags & MLX5_FLOW_VLAN_ACTIONS)
3336 : 0 : return rte_flow_error_set(error, ENOTSUP,
3337 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3338 : : "no support for multiple VLAN "
3339 : : "actions");
3340 : : /* Pop VLAN with preceding Decap requires inner header with VLAN. */
3341 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_DECAP) &&
3342 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_INNER_VLAN))
3343 : 0 : return rte_flow_error_set(error, ENOTSUP,
3344 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3345 : : NULL,
3346 : : "cannot pop vlan after decap without "
3347 : : "match on inner vlan in the flow");
3348 : : /* Pop VLAN without preceding Decap requires outer header with VLAN. */
3349 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_ACTION_DECAP) &&
3350 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
3351 : 0 : return rte_flow_error_set(error, ENOTSUP,
3352 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3353 : : NULL,
3354 : : "cannot pop vlan without a "
3355 : : "match on (outer) vlan in the flow");
3356 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3357 : 0 : return rte_flow_error_set(error, EINVAL,
3358 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3359 : : "wrong action order, port_id should "
3360 : : "be after pop VLAN action");
3361 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
3362 : 0 : return rte_flow_error_set(error, ENOTSUP,
3363 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3364 : : "pop vlan action for VF representor "
3365 : : "not supported on NIC table");
3366 : : return 0;
3367 : : }
3368 : :
3369 : : /**
3370 : : * Get VLAN default info from vlan match info.
3371 : : *
3372 : : * @param[in] items
3373 : : * the list of item specifications.
3374 : : * @param[out] vlan
3375 : : * pointer VLAN info to fill to.
3376 : : *
3377 : : * @return
3378 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3379 : : */
3380 : : static void
3381 : 0 : flow_dev_get_vlan_info_from_items(const struct rte_flow_item *items,
3382 : : struct rte_vlan_hdr *vlan)
3383 : : {
3384 : 0 : const struct rte_flow_item_vlan nic_mask = {
3385 : : .hdr.vlan_tci = RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK |
3386 : : MLX5DV_FLOW_VLAN_VID_MASK),
3387 : : .hdr.eth_proto = RTE_BE16(0xffff),
3388 : : };
3389 : :
3390 [ # # ]: 0 : if (items == NULL)
3391 : 0 : return;
3392 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
3393 : 0 : int type = items->type;
3394 : :
3395 : 0 : if (type == RTE_FLOW_ITEM_TYPE_VLAN ||
3396 [ # # ]: 0 : type == MLX5_RTE_FLOW_ITEM_TYPE_VLAN)
3397 : : break;
3398 : : }
3399 [ # # ]: 0 : if (items->type != RTE_FLOW_ITEM_TYPE_END) {
3400 : 0 : const struct rte_flow_item_vlan *vlan_m = items->mask;
3401 : 0 : const struct rte_flow_item_vlan *vlan_v = items->spec;
3402 : :
3403 : : /* If VLAN item in pattern doesn't contain data, return here. */
3404 [ # # ]: 0 : if (!vlan_v)
3405 : : return;
3406 [ # # ]: 0 : if (!vlan_m)
3407 : : vlan_m = &nic_mask;
3408 : : /* Only full match values are accepted */
3409 [ # # ]: 0 : if ((vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) ==
3410 : : MLX5DV_FLOW_VLAN_PCP_MASK_BE) {
3411 : 0 : vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
3412 : 0 : vlan->vlan_tci |=
3413 [ # # ]: 0 : rte_be_to_cpu_16(vlan_v->hdr.vlan_tci &
3414 : : MLX5DV_FLOW_VLAN_PCP_MASK_BE);
3415 : : }
3416 [ # # ]: 0 : if ((vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) ==
3417 : : MLX5DV_FLOW_VLAN_VID_MASK_BE) {
3418 : 0 : vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
3419 : 0 : vlan->vlan_tci |=
3420 [ # # ]: 0 : rte_be_to_cpu_16(vlan_v->hdr.vlan_tci &
3421 : : MLX5DV_FLOW_VLAN_VID_MASK_BE);
3422 : : }
3423 [ # # ]: 0 : if (vlan_m->hdr.eth_proto == nic_mask.hdr.eth_proto)
3424 [ # # ]: 0 : vlan->eth_proto = rte_be_to_cpu_16(vlan_v->hdr.eth_proto &
3425 : : vlan_m->hdr.eth_proto);
3426 : : }
3427 : : }
3428 : :
3429 : : /**
3430 : : * Validate the push VLAN action.
3431 : : *
3432 : : * @param[in] dev
3433 : : * Pointer to the rte_eth_dev structure.
3434 : : * @param[in] action_flags
3435 : : * Holds the actions detected until now.
3436 : : * @param[in] item_flags
3437 : : * The items found in this flow rule.
3438 : : * @param[in] action
3439 : : * Pointer to the action structure.
3440 : : * @param[in] attr
3441 : : * Pointer to flow attributes
3442 : : * @param[out] error
3443 : : * Pointer to error structure.
3444 : : *
3445 : : * @return
3446 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3447 : : */
3448 : : static int
3449 : 0 : flow_dv_validate_action_push_vlan(struct rte_eth_dev *dev,
3450 : : uint64_t action_flags,
3451 : : const struct rte_flow_item_vlan *vlan_m,
3452 : : const struct rte_flow_action *action,
3453 : : const struct rte_flow_attr *attr,
3454 : : struct rte_flow_error *error)
3455 : : {
3456 : 0 : const struct rte_flow_action_of_push_vlan *push_vlan = action->conf;
3457 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
3458 : :
3459 [ # # ]: 0 : if (push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_VLAN) &&
3460 : : push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_QINQ))
3461 : 0 : return rte_flow_error_set(error, EINVAL,
3462 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3463 : : "invalid vlan ethertype");
3464 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3465 : 0 : return rte_flow_error_set(error, EINVAL,
3466 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3467 : : "wrong action order, port_id should "
3468 : : "be after push VLAN");
3469 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
3470 : 0 : return rte_flow_error_set(error, ENOTSUP,
3471 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3472 : : "push vlan action for VF representor "
3473 : : "not supported on NIC table");
3474 [ # # ]: 0 : if (vlan_m &&
3475 [ # # # # ]: 0 : (vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) &&
3476 : : (vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) !=
3477 : 0 : MLX5DV_FLOW_VLAN_PCP_MASK_BE &&
3478 [ # # # # ]: 0 : !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP) &&
3479 : 0 : !(mlx5_flow_find_action
3480 : : (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP)))
3481 : 0 : return rte_flow_error_set(error, EINVAL,
3482 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3483 : : "not full match mask on VLAN PCP and "
3484 : : "there is no of_set_vlan_pcp action, "
3485 : : "push VLAN action cannot figure out "
3486 : : "PCP value");
3487 [ # # ]: 0 : if (vlan_m &&
3488 [ # # # # ]: 0 : (vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) &&
3489 : : (vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) !=
3490 : 0 : MLX5DV_FLOW_VLAN_VID_MASK_BE &&
3491 [ # # # # ]: 0 : !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID) &&
3492 : 0 : !(mlx5_flow_find_action
3493 : : (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID)))
3494 : 0 : return rte_flow_error_set(error, EINVAL,
3495 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3496 : : "not full match mask on VLAN VID and "
3497 : : "there is no of_set_vlan_vid action, "
3498 : : "push VLAN action cannot figure out "
3499 : : "VID value");
3500 : : (void)attr;
3501 : : return 0;
3502 : : }
3503 : :
3504 : : /**
3505 : : * Validate the set VLAN PCP.
3506 : : *
3507 : : * @param[in] action_flags
3508 : : * Holds the actions detected until now.
3509 : : * @param[in] actions
3510 : : * Pointer to the list of actions remaining in the flow rule.
3511 : : * @param[out] error
3512 : : * Pointer to error structure.
3513 : : *
3514 : : * @return
3515 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3516 : : */
3517 : : static int
3518 : 0 : flow_dv_validate_action_set_vlan_pcp(uint64_t action_flags,
3519 : : const struct rte_flow_action actions[],
3520 : : struct rte_flow_error *error)
3521 : : {
3522 : : const struct rte_flow_action *action = actions;
3523 : 0 : const struct rte_flow_action_of_set_vlan_pcp *conf = action->conf;
3524 : :
3525 [ # # ]: 0 : if (conf->vlan_pcp > 7)
3526 : 0 : return rte_flow_error_set(error, EINVAL,
3527 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3528 : : "VLAN PCP value is too big");
3529 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN))
3530 : 0 : return rte_flow_error_set(error, ENOTSUP,
3531 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3532 : : "set VLAN PCP action must follow "
3533 : : "the push VLAN action");
3534 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP)
3535 : 0 : return rte_flow_error_set(error, ENOTSUP,
3536 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3537 : : "Multiple VLAN PCP modification are "
3538 : : "not supported");
3539 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3540 : 0 : return rte_flow_error_set(error, EINVAL,
3541 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3542 : : "wrong action order, port_id should "
3543 : : "be after set VLAN PCP");
3544 : : return 0;
3545 : : }
3546 : :
3547 : : /**
3548 : : * Validate the set VLAN VID.
3549 : : *
3550 : : * @param[in] item_flags
3551 : : * Holds the items detected in this rule.
3552 : : * @param[in] action_flags
3553 : : * Holds the actions detected until now.
3554 : : * @param[in] actions
3555 : : * Pointer to the list of actions remaining in the flow rule.
3556 : : * @param[out] error
3557 : : * Pointer to error structure.
3558 : : *
3559 : : * @return
3560 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3561 : : */
3562 : : static int
3563 : 0 : flow_dv_validate_action_set_vlan_vid(uint64_t item_flags,
3564 : : uint64_t action_flags,
3565 : : const struct rte_flow_action actions[],
3566 : : struct rte_flow_error *error)
3567 : : {
3568 : : const struct rte_flow_action *action = actions;
3569 : 0 : const struct rte_flow_action_of_set_vlan_vid *conf = action->conf;
3570 : :
3571 [ # # # # ]: 0 : if (rte_be_to_cpu_16(conf->vlan_vid) > 0xFFE)
3572 : 0 : return rte_flow_error_set(error, EINVAL,
3573 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3574 : : "VLAN VID value is too big");
3575 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) &&
3576 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
3577 : 0 : return rte_flow_error_set(error, ENOTSUP,
3578 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3579 : : "set VLAN VID action must follow push"
3580 : : " VLAN action or match on VLAN item");
3581 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID)
3582 : 0 : return rte_flow_error_set(error, ENOTSUP,
3583 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3584 : : "Multiple VLAN VID modifications are "
3585 : : "not supported");
3586 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3587 : 0 : return rte_flow_error_set(error, EINVAL,
3588 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3589 : : "wrong action order, port_id should "
3590 : : "be after set VLAN VID");
3591 : : return 0;
3592 : : }
3593 : :
3594 : : /*
3595 : : * Validate the FLAG action.
3596 : : *
3597 : : * @param[in] dev
3598 : : * Pointer to the rte_eth_dev structure.
3599 : : * @param[in] action_flags
3600 : : * Holds the actions detected until now.
3601 : : * @param[in] attr
3602 : : * Pointer to flow attributes
3603 : : * @param[out] error
3604 : : * Pointer to error structure.
3605 : : *
3606 : : * @return
3607 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3608 : : */
3609 : : static int
3610 : 0 : flow_dv_validate_action_flag(struct rte_eth_dev *dev,
3611 : : uint64_t action_flags,
3612 : : const struct rte_flow_attr *attr,
3613 : : struct rte_flow_error *error)
3614 : : {
3615 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3616 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
3617 : : int ret;
3618 : :
3619 : : /* Fall back if no extended metadata register support. */
3620 [ # # ]: 0 : if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
3621 : 0 : return mlx5_flow_validate_action_flag(action_flags, attr,
3622 : : error);
3623 : : /* Extensive metadata mode requires registers. */
3624 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
3625 : 0 : return rte_flow_error_set(error, ENOTSUP,
3626 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3627 : : "no metadata registers "
3628 : : "to support flag action");
3629 [ # # ]: 0 : if (!(priv->sh->dv_mark_mask & MLX5_FLOW_MARK_DEFAULT))
3630 : 0 : return rte_flow_error_set(error, ENOTSUP,
3631 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3632 : : "extended metadata register"
3633 : : " isn't available");
3634 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3635 [ # # ]: 0 : if (ret < 0)
3636 : : return ret;
3637 : : MLX5_ASSERT(ret > 0);
3638 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
3639 : 0 : return rte_flow_error_set(error, EINVAL,
3640 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3641 : : "can't mark and flag in same flow");
3642 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_FLAG)
3643 : 0 : return rte_flow_error_set(error, EINVAL,
3644 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3645 : : "can't have 2 flag"
3646 : : " actions in same flow");
3647 : : return 0;
3648 : : }
3649 : :
3650 : : /**
3651 : : * Validate MARK action.
3652 : : *
3653 : : * @param[in] dev
3654 : : * Pointer to the rte_eth_dev structure.
3655 : : * @param[in] action
3656 : : * Pointer to action.
3657 : : * @param[in] action_flags
3658 : : * Holds the actions detected until now.
3659 : : * @param[in] attr
3660 : : * Pointer to flow attributes
3661 : : * @param[out] error
3662 : : * Pointer to error structure.
3663 : : *
3664 : : * @return
3665 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3666 : : */
3667 : : static int
3668 : 0 : flow_dv_validate_action_mark(struct rte_eth_dev *dev,
3669 : : const struct rte_flow_action *action,
3670 : : uint64_t action_flags,
3671 : : const struct rte_flow_attr *attr,
3672 : : struct rte_flow_error *error)
3673 : : {
3674 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3675 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
3676 [ # # ]: 0 : const struct rte_flow_action_mark *mark = action->conf;
3677 : : int ret;
3678 : :
3679 [ # # ]: 0 : if (is_tunnel_offload_active(dev))
3680 : 0 : return rte_flow_error_set(error, ENOTSUP,
3681 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3682 : : "no mark action "
3683 : : "if tunnel offload active");
3684 : : /* Fall back if no extended metadata register support. */
3685 [ # # ]: 0 : if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
3686 : 0 : return mlx5_flow_validate_action_mark(dev, action, action_flags,
3687 : : attr, error);
3688 : : /* Extensive metadata mode requires registers. */
3689 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
3690 : 0 : return rte_flow_error_set(error, ENOTSUP,
3691 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3692 : : "no metadata registers "
3693 : : "to support mark action");
3694 [ # # ]: 0 : if (!priv->sh->dv_mark_mask)
3695 : 0 : return rte_flow_error_set(error, ENOTSUP,
3696 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3697 : : "extended metadata register"
3698 : : " isn't available");
3699 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3700 [ # # ]: 0 : if (ret < 0)
3701 : : return ret;
3702 : : MLX5_ASSERT(ret > 0);
3703 [ # # ]: 0 : if (!mark)
3704 : 0 : return rte_flow_error_set(error, EINVAL,
3705 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3706 : : "configuration cannot be null");
3707 [ # # ]: 0 : if (mark->id >= (MLX5_FLOW_MARK_MAX & priv->sh->dv_mark_mask))
3708 : 0 : return rte_flow_error_set(error, EINVAL,
3709 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3710 : 0 : &mark->id,
3711 : : "mark id exceeds the limit");
3712 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_FLAG)
3713 : 0 : return rte_flow_error_set(error, EINVAL,
3714 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3715 : : "can't flag and mark in same flow");
3716 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
3717 : 0 : return rte_flow_error_set(error, EINVAL,
3718 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3719 : : "can't have 2 mark actions in same"
3720 : : " flow");
3721 : : return 0;
3722 : : }
3723 : :
3724 : : /**
3725 : : * Validate SET_META action.
3726 : : *
3727 : : * @param[in] dev
3728 : : * Pointer to the rte_eth_dev structure.
3729 : : * @param[in] action
3730 : : * Pointer to the action structure.
3731 : : * @param[in] action_flags
3732 : : * Holds the actions detected until now.
3733 : : * @param[in] attr
3734 : : * Pointer to flow attributes
3735 : : * @param[out] error
3736 : : * Pointer to error structure.
3737 : : *
3738 : : * @return
3739 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3740 : : */
3741 : : static int
3742 : 0 : flow_dv_validate_action_set_meta(struct rte_eth_dev *dev,
3743 : : const struct rte_flow_action *action,
3744 : : uint64_t action_flags __rte_unused,
3745 : : const struct rte_flow_attr *attr,
3746 : : struct rte_flow_error *error)
3747 : : {
3748 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3749 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
3750 : : const struct rte_flow_action_set_meta *conf;
3751 : : uint32_t nic_mask = UINT32_MAX;
3752 : : int reg;
3753 : :
3754 [ # # # # ]: 0 : if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
3755 : 0 : !mlx5_flow_ext_mreg_supported(dev))
3756 : 0 : return rte_flow_error_set(error, ENOTSUP,
3757 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3758 : : "extended metadata register"
3759 : : " isn't supported");
3760 : 0 : reg = flow_dv_get_metadata_reg(dev, attr, error);
3761 [ # # ]: 0 : if (reg < 0)
3762 : : return reg;
3763 [ # # ]: 0 : if (reg == REG_NON)
3764 : 0 : return rte_flow_error_set(error, ENOTSUP,
3765 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3766 : : "unavailable extended metadata register");
3767 [ # # ]: 0 : if (reg != REG_A && reg != REG_B) {
3768 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3769 : :
3770 : 0 : nic_mask = priv->sh->dv_meta_mask;
3771 : : }
3772 [ # # ]: 0 : if (!(action->conf))
3773 : 0 : return rte_flow_error_set(error, EINVAL,
3774 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3775 : : "configuration cannot be null");
3776 : : conf = (const struct rte_flow_action_set_meta *)action->conf;
3777 [ # # ]: 0 : if (!conf->mask)
3778 : 0 : return rte_flow_error_set(error, EINVAL,
3779 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3780 : : "zero mask doesn't have any effect");
3781 [ # # ]: 0 : if (conf->mask & ~nic_mask)
3782 : 0 : return rte_flow_error_set(error, EINVAL,
3783 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3784 : : "meta data must be within reg C0");
3785 : : return 0;
3786 : : }
3787 : :
3788 : : /**
3789 : : * Validate SET_TAG action.
3790 : : *
3791 : : * @param[in] dev
3792 : : * Pointer to the rte_eth_dev structure.
3793 : : * @param[in] action
3794 : : * Pointer to the action structure.
3795 : : * @param[in] action_flags
3796 : : * Holds the actions detected until now.
3797 : : * @param[in] attr
3798 : : * Pointer to flow attributes
3799 : : * @param[out] error
3800 : : * Pointer to error structure.
3801 : : *
3802 : : * @return
3803 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3804 : : */
3805 : : static int
3806 : 0 : flow_dv_validate_action_set_tag(struct rte_eth_dev *dev,
3807 : : const struct rte_flow_action *action,
3808 : : uint64_t action_flags,
3809 : : const struct rte_flow_attr *attr,
3810 : : struct rte_flow_error *error)
3811 : : {
3812 : : const struct rte_flow_action_set_tag *conf;
3813 : : const uint64_t terminal_action_flags =
3814 : : MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE |
3815 : : MLX5_FLOW_ACTION_RSS;
3816 : : int ret;
3817 : :
3818 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
3819 : 0 : return rte_flow_error_set(error, ENOTSUP,
3820 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3821 : : "extensive metadata register"
3822 : : " isn't supported");
3823 [ # # ]: 0 : if (!(action->conf))
3824 : 0 : return rte_flow_error_set(error, EINVAL,
3825 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3826 : : "configuration cannot be null");
3827 : : conf = (const struct rte_flow_action_set_tag *)action->conf;
3828 [ # # ]: 0 : if (!conf->mask)
3829 : 0 : return rte_flow_error_set(error, EINVAL,
3830 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3831 : : "zero mask doesn't have any effect");
3832 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
3833 [ # # ]: 0 : if (ret < 0)
3834 : : return ret;
3835 [ # # # # ]: 0 : if (attr->ingress && (action_flags & terminal_action_flags))
3836 : 0 : return rte_flow_error_set(error, EINVAL,
3837 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3838 : : "set_tag has no effect"
3839 : : " with terminal actions");
3840 : : return 0;
3841 : : }
3842 : :
3843 : : /**
3844 : : * Indicates whether ASO aging is supported.
3845 : : *
3846 : : * @param[in] priv
3847 : : * Pointer to device private context structure.
3848 : : * @param[in] root
3849 : : * Whether action is on root table.
3850 : : *
3851 : : * @return
3852 : : * True when ASO aging is supported, false otherwise.
3853 : : */
3854 : : static inline bool
3855 : : flow_hit_aso_supported(const struct mlx5_priv *priv, bool root)
3856 : : {
3857 : : MLX5_ASSERT(priv);
3858 [ # # # # : 0 : return (priv->sh->flow_hit_aso_en && !root);
# # # # #
# ]
3859 : : }
3860 : :
3861 : : /**
3862 : : * Validate count action.
3863 : : *
3864 : : * @param[in] dev
3865 : : * Pointer to rte_eth_dev structure.
3866 : : * @param[in] shared
3867 : : * Indicator if action is shared.
3868 : : * @param[in] action_flags
3869 : : * Holds the actions detected until now.
3870 : : * @param[in] root
3871 : : * Whether action is on root table.
3872 : : * @param[out] error
3873 : : * Pointer to error structure.
3874 : : *
3875 : : * @return
3876 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3877 : : */
3878 : : static int
3879 : 0 : flow_dv_validate_action_count(struct rte_eth_dev *dev, bool shared,
3880 : : uint64_t action_flags,
3881 : : bool root,
3882 : : struct rte_flow_error *error)
3883 : : {
3884 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3885 : :
3886 [ # # ]: 0 : if (!priv->sh->cdev->config.devx)
3887 : 0 : goto notsup_err;
3888 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_COUNT)
3889 : 0 : return rte_flow_error_set(error, EINVAL,
3890 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3891 : : "duplicate count actions set");
3892 [ # # # # : 0 : if (shared && (action_flags & MLX5_FLOW_ACTION_AGE) &&
# # ]
3893 : : !flow_hit_aso_supported(priv, root))
3894 : 0 : return rte_flow_error_set(error, EINVAL,
3895 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3896 : : "old age and indirect count combination is not supported");
3897 : : #ifdef HAVE_IBV_FLOW_DEVX_COUNTERS
3898 : : return 0;
3899 : : #endif
3900 : : notsup_err:
3901 : 0 : return rte_flow_error_set
3902 : : (error, ENOTSUP,
3903 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3904 : : NULL,
3905 : : "count action not supported");
3906 : : }
3907 : :
3908 : : /**
3909 : : * Validate the L2 encap action.
3910 : : *
3911 : : * @param[in] dev
3912 : : * Pointer to the rte_eth_dev structure.
3913 : : * @param[in] action_flags
3914 : : * Holds the actions detected until now.
3915 : : * @param[in] action
3916 : : * Pointer to the action structure.
3917 : : * @param[in] attr
3918 : : * Pointer to flow attributes.
3919 : : * @param[out] error
3920 : : * Pointer to error structure.
3921 : : *
3922 : : * @return
3923 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3924 : : */
3925 : : int
3926 : 0 : mlx5_flow_dv_validate_action_l2_encap(struct rte_eth_dev *dev,
3927 : : uint64_t action_flags,
3928 : : const struct rte_flow_action *action,
3929 : : const struct rte_flow_attr *attr,
3930 : : struct rte_flow_error *error)
3931 : : {
3932 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
3933 : :
3934 [ # # ]: 0 : if (!(action->conf))
3935 : 0 : return rte_flow_error_set(error, EINVAL,
3936 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3937 : : "configuration cannot be null");
3938 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
3939 : 0 : return rte_flow_error_set(error, EINVAL,
3940 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3941 : : "can only have a single encap action "
3942 : : "in a flow");
3943 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
3944 : 0 : return rte_flow_error_set(error, ENOTSUP,
3945 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3946 : : "encap action for VF representor "
3947 : : "not supported on NIC table");
3948 : : return 0;
3949 : : }
3950 : :
3951 : : /**
3952 : : * Validate a decap action.
3953 : : *
3954 : : * @param[in] dev
3955 : : * Pointer to the rte_eth_dev structure.
3956 : : * @param[in] action_flags
3957 : : * Holds the actions detected until now.
3958 : : * @param[in] action
3959 : : * Pointer to the action structure.
3960 : : * @param[in] item_flags
3961 : : * Holds the items detected.
3962 : : * @param[in] attr
3963 : : * Pointer to flow attributes
3964 : : * @param[out] error
3965 : : * Pointer to error structure.
3966 : : *
3967 : : * @return
3968 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3969 : : */
3970 : : int
3971 : 0 : mlx5_flow_dv_validate_action_decap(struct rte_eth_dev *dev,
3972 : : uint64_t action_flags,
3973 : : const struct rte_flow_action *action,
3974 : : const uint64_t item_flags,
3975 : : const struct rte_flow_attr *attr,
3976 : : struct rte_flow_error *error)
3977 : : {
3978 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
3979 : :
3980 [ # # ]: 0 : if (priv->sh->cdev->config.hca_attr.scatter_fcs_w_decap_disable &&
3981 [ # # ]: 0 : !priv->sh->config.decap_en)
3982 : 0 : return rte_flow_error_set(error, ENOTSUP,
3983 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3984 : : "decap is not enabled");
3985 [ # # ]: 0 : if (action_flags & MLX5_FLOW_XCAP_ACTIONS)
3986 : 0 : return rte_flow_error_set(error, ENOTSUP,
3987 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3988 [ # # ]: 0 : action_flags &
3989 : : MLX5_FLOW_ACTION_DECAP ? "can only "
3990 : : "have a single decap action" : "decap "
3991 : : "after encap is not supported");
3992 [ # # ]: 0 : if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
3993 : 0 : return rte_flow_error_set(error, EINVAL,
3994 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3995 : : "can't have decap action after"
3996 : : " modify action");
3997 [ # # ]: 0 : if (attr->egress)
3998 : 0 : return rte_flow_error_set(error, ENOTSUP,
3999 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
4000 : : NULL,
4001 : : "decap action not supported for "
4002 : : "egress");
4003 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
4004 : 0 : return rte_flow_error_set(error, ENOTSUP,
4005 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4006 : : "decap action for VF representor "
4007 : : "not supported on NIC table");
4008 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_DECAP &&
4009 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_VXLAN))
4010 : 0 : return rte_flow_error_set(error, ENOTSUP,
4011 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4012 : : "VXLAN item should be present for VXLAN decap");
4013 : : return 0;
4014 : : }
4015 : :
4016 : : const struct rte_flow_action_raw_decap empty_decap = {.data = NULL, .size = 0,};
4017 : :
4018 : : /**
4019 : : * Validate the raw encap and decap actions.
4020 : : *
4021 : : * @param[in] dev
4022 : : * Pointer to the rte_eth_dev structure.
4023 : : * @param[in] decap
4024 : : * Pointer to the decap action.
4025 : : * @param[in] encap
4026 : : * Pointer to the encap action.
4027 : : * @param[in] attr
4028 : : * Pointer to flow attributes
4029 : : * @param[in/out] action_flags
4030 : : * Holds the actions detected until now.
4031 : : * @param[out] actions_n
4032 : : * pointer to the number of actions counter.
4033 : : * @param[in] action
4034 : : * Pointer to the action structure.
4035 : : * @param[in] item_flags
4036 : : * Holds the items detected.
4037 : : * @param[out] error
4038 : : * Pointer to error structure.
4039 : : *
4040 : : * @return
4041 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4042 : : */
4043 : : int
4044 : 0 : mlx5_flow_dv_validate_action_raw_encap_decap
4045 : : (struct rte_eth_dev *dev,
4046 : : const struct rte_flow_action_raw_decap *decap,
4047 : : const struct rte_flow_action_raw_encap *encap,
4048 : : const struct rte_flow_attr *attr, uint64_t *action_flags,
4049 : : int *actions_n, const struct rte_flow_action *action,
4050 : : uint64_t item_flags, struct rte_flow_error *error)
4051 : : {
4052 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
4053 : : int ret;
4054 : :
4055 [ # # ]: 0 : if (encap) {
4056 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
4057 [ # # # # ]: 0 : if (!encap->size || !encap->data)
4058 : 0 : return rte_flow_error_set
4059 : : (error, EINVAL,
4060 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL, "raw encap data cannot be empty");
4061 : : } else {
4062 [ # # ]: 0 : if (!encap->size)
4063 : 0 : return rte_flow_error_set
4064 : : (error, EINVAL,
4065 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL, "raw encap size cannot be 0");
4066 : : }
4067 : : }
4068 [ # # ]: 0 : if (decap && encap) {
4069 [ # # ]: 0 : if (decap->size <= MLX5_ENCAPSULATION_DECISION_SIZE &&
4070 [ # # ]: 0 : encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4071 : : /* L3 encap. */
4072 : : decap = NULL;
4073 [ # # ]: 0 : else if (encap->size <=
4074 [ # # ]: 0 : MLX5_ENCAPSULATION_DECISION_SIZE &&
4075 : : decap->size >
4076 : : MLX5_ENCAPSULATION_DECISION_SIZE)
4077 : : /* L3 decap. */
4078 : : encap = NULL;
4079 [ # # ]: 0 : else if (encap->size >
4080 [ # # ]: 0 : MLX5_ENCAPSULATION_DECISION_SIZE &&
4081 : : decap->size >
4082 : : MLX5_ENCAPSULATION_DECISION_SIZE)
4083 : : /* 2 L2 actions: encap and decap. */
4084 : : ;
4085 : : else
4086 : 0 : return rte_flow_error_set(error,
4087 : : ENOTSUP,
4088 : : RTE_FLOW_ERROR_TYPE_ACTION,
4089 : : NULL, "unsupported too small "
4090 : : "raw decap and too small raw "
4091 : : "encap combination");
4092 : : }
4093 [ # # ]: 0 : if (decap) {
4094 : 0 : ret = mlx5_flow_dv_validate_action_decap(dev, *action_flags,
4095 : : action,
4096 : : item_flags, attr,
4097 : : error);
4098 [ # # ]: 0 : if (ret < 0)
4099 : : return ret;
4100 : 0 : *action_flags |= MLX5_FLOW_ACTION_DECAP;
4101 : 0 : ++(*actions_n);
4102 : : }
4103 [ # # ]: 0 : if (encap) {
4104 [ # # ]: 0 : if (encap->size <= MLX5_ENCAPSULATION_DECISION_SIZE)
4105 : 0 : return rte_flow_error_set(error, ENOTSUP,
4106 : : RTE_FLOW_ERROR_TYPE_ACTION,
4107 : : NULL,
4108 : : "small raw encap size");
4109 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_ENCAP)
4110 : 0 : return rte_flow_error_set(error, EINVAL,
4111 : : RTE_FLOW_ERROR_TYPE_ACTION,
4112 : : NULL,
4113 : : "more than one encap action");
4114 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
4115 : 0 : return rte_flow_error_set
4116 : : (error, ENOTSUP,
4117 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4118 : : "encap action for VF representor "
4119 : : "not supported on NIC table");
4120 : 0 : *action_flags |= MLX5_FLOW_ACTION_ENCAP;
4121 : 0 : ++(*actions_n);
4122 : : }
4123 : : return 0;
4124 : : }
4125 : :
4126 : : /*
4127 : : * Validate the ASO CT action.
4128 : : *
4129 : : * @param[in] dev
4130 : : * Pointer to the rte_eth_dev structure.
4131 : : * @param[in] action_flags
4132 : : * Holds the actions detected until now.
4133 : : * @param[in] item_flags
4134 : : * The items found in this flow rule.
4135 : : * @param root
4136 : : * Whether action is on root table.
4137 : : * @param[out] error
4138 : : * Pointer to error structure.
4139 : : *
4140 : : * @return
4141 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4142 : : */
4143 : : int
4144 : 0 : mlx5_flow_dv_validate_action_aso_ct(struct rte_eth_dev *dev,
4145 : : uint64_t action_flags,
4146 : : uint64_t item_flags,
4147 : : bool root,
4148 : : struct rte_flow_error *error)
4149 : : {
4150 : : RTE_SET_USED(dev);
4151 : :
4152 [ # # ]: 0 : if (root)
4153 : 0 : return rte_flow_error_set(error, ENOTSUP,
4154 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4155 : : NULL,
4156 : : "Only support non-root table");
4157 [ # # ]: 0 : if (action_flags & MLX5_FLOW_FATE_ACTIONS)
4158 : 0 : return rte_flow_error_set(error, ENOTSUP,
4159 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4160 : : "CT cannot follow a fate action");
4161 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_METER) ||
4162 : : (action_flags & MLX5_FLOW_ACTION_AGE)) {
4163 [ # # ]: 0 : if (!mlx5_hws_active(dev))
4164 : 0 : return rte_flow_error_set(error, EINVAL,
4165 : : RTE_FLOW_ERROR_TYPE_ACTION,
4166 : : NULL, "Only one ASO action is supported");
4167 : : }
4168 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
4169 : 0 : return rte_flow_error_set(error, EINVAL,
4170 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4171 : : "Encap cannot exist before CT");
4172 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP))
4173 : 0 : return rte_flow_error_set(error, EINVAL,
4174 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4175 : : "Not a outer TCP packet");
4176 : : return 0;
4177 : : }
4178 : :
4179 : : /**
4180 : : * Validate METER_COLOR item.
4181 : : *
4182 : : * @param[in] dev
4183 : : * Pointer to the rte_eth_dev structure.
4184 : : * @param[in] item
4185 : : * Item specification.
4186 : : * @param[in] attr
4187 : : * Attributes of flow that includes this item.
4188 : : * @param[out] error
4189 : : * Pointer to error structure.
4190 : : *
4191 : : * @return
4192 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4193 : : */
4194 : : static int
4195 : 0 : flow_dv_validate_item_meter_color(struct rte_eth_dev *dev,
4196 : : const struct rte_flow_item *item,
4197 : : const struct rte_flow_attr *attr __rte_unused,
4198 : : struct rte_flow_error *error)
4199 : : {
4200 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4201 : 0 : const struct rte_flow_item_meter_color *spec = item->spec;
4202 : 0 : const struct rte_flow_item_meter_color *mask = item->mask;
4203 : 0 : struct rte_flow_item_meter_color nic_mask = {
4204 : : .color = RTE_COLORS
4205 : : };
4206 : : int ret;
4207 : :
4208 [ # # ]: 0 : if (priv->sh->registers.aso_reg == REG_NON)
4209 : 0 : return rte_flow_error_set(error, ENOTSUP,
4210 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
4211 : : "meter color register"
4212 : : " isn't available");
4213 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, error);
4214 [ # # ]: 0 : if (ret < 0)
4215 : : return ret;
4216 [ # # ]: 0 : if (!spec)
4217 : 0 : return rte_flow_error_set(error, EINVAL,
4218 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4219 : 0 : item->spec,
4220 : : "data cannot be empty");
4221 [ # # ]: 0 : if (spec->color > RTE_COLORS)
4222 : 0 : return rte_flow_error_set(error, EINVAL,
4223 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4224 : 0 : &spec->color,
4225 : : "meter color is invalid");
4226 [ # # ]: 0 : if (!mask)
4227 : : mask = &rte_flow_item_meter_color_mask;
4228 [ # # ]: 0 : if (!mask->color)
4229 : 0 : return rte_flow_error_set(error, EINVAL,
4230 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
4231 : : "mask cannot be zero");
4232 : :
4233 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
4234 : : (const uint8_t *)&nic_mask,
4235 : : sizeof(struct rte_flow_item_meter_color),
4236 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
4237 : : if (ret < 0)
4238 : : return ret;
4239 : : return 0;
4240 : : }
4241 : :
4242 : : /**
4243 : : * Validate aggregated affinity item.
4244 : : *
4245 : : * @param[in] dev
4246 : : * Pointer to the rte_eth_dev structure.
4247 : : * @param[in] item
4248 : : * Item specification.
4249 : : * @param[in] attr
4250 : : * Attributes of flow that includes this item.
4251 : : * @param[out] error
4252 : : * Pointer to error structure.
4253 : : *
4254 : : * @return
4255 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4256 : : */
4257 : : static int
4258 : 0 : flow_dv_validate_item_aggr_affinity(struct rte_eth_dev *dev,
4259 : : const struct rte_flow_item *item,
4260 : : const struct rte_flow_attr *attr,
4261 : : struct rte_flow_error *error)
4262 : : {
4263 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4264 : 0 : const struct rte_flow_item_aggr_affinity *spec = item->spec;
4265 : 0 : const struct rte_flow_item_aggr_affinity *mask = item->mask;
4266 : 0 : struct rte_flow_item_aggr_affinity nic_mask = {
4267 : : .affinity = UINT8_MAX
4268 : : };
4269 : : int ret;
4270 : :
4271 [ # # ]: 0 : if (!priv->sh->lag_rx_port_affinity_en)
4272 : 0 : return rte_flow_error_set(error, EINVAL,
4273 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
4274 : : "Unsupported aggregated affinity with Older FW");
4275 [ # # # # : 0 : if ((attr->transfer && priv->fdb_def_rule) ||
# # ]
4276 [ # # ]: 0 : attr->egress || attr->group)
4277 : 0 : return rte_flow_error_set(error, ENOTSUP,
4278 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4279 : : item->spec,
4280 : : "aggregated affinity is not supported with egress or FDB on non root table");
4281 [ # # ]: 0 : if (!spec)
4282 : 0 : return rte_flow_error_set(error, EINVAL,
4283 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4284 : : item->spec,
4285 : : "data cannot be empty");
4286 [ # # ]: 0 : if (spec->affinity == 0)
4287 : 0 : return rte_flow_error_set(error, ENOTSUP,
4288 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4289 : : item->spec,
4290 : : "zero affinity number not supported");
4291 [ # # ]: 0 : if (spec->affinity > priv->num_lag_ports)
4292 : 0 : return rte_flow_error_set(error, ENOTSUP,
4293 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4294 : : item->spec,
4295 : : "exceed max affinity number in lag ports");
4296 [ # # ]: 0 : if (!mask)
4297 : : mask = &rte_flow_item_aggr_affinity_mask;
4298 [ # # ]: 0 : if (!mask->affinity)
4299 : 0 : return rte_flow_error_set(error, EINVAL,
4300 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
4301 : : "mask cannot be zero");
4302 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
4303 : : (const uint8_t *)&nic_mask,
4304 : : sizeof(struct rte_flow_item_aggr_affinity),
4305 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
4306 : : if (ret < 0)
4307 : : return ret;
4308 : : return 0;
4309 : : }
4310 : :
4311 : : int
4312 : 0 : mlx5_flow_encap_decap_match_cb(void *tool_ctx __rte_unused,
4313 : : struct mlx5_list_entry *entry, void *cb_ctx)
4314 : : {
4315 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4316 : 0 : struct mlx5_flow_dv_encap_decap_resource *ctx_resource = ctx->data;
4317 : : struct mlx5_flow_dv_encap_decap_resource *resource;
4318 : :
4319 : : resource = container_of(entry, struct mlx5_flow_dv_encap_decap_resource,
4320 : : entry);
4321 [ # # ]: 0 : if (resource->reformat_type == ctx_resource->reformat_type &&
4322 : 0 : resource->ft_type == ctx_resource->ft_type &&
4323 [ # # ]: 0 : resource->flags == ctx_resource->flags &&
4324 [ # # ]: 0 : resource->size == ctx_resource->size &&
4325 : 0 : !memcmp((const void *)resource->buf,
4326 [ # # ]: 0 : (const void *)ctx_resource->buf,
4327 : : resource->size))
4328 : 0 : return 0;
4329 : : return -1;
4330 : : }
4331 : :
4332 : : struct mlx5_list_entry *
4333 : 0 : mlx5_flow_encap_decap_create_cb(void *tool_ctx, void *cb_ctx)
4334 : : {
4335 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4336 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4337 : : struct mlx5dv_dr_domain *domain;
4338 : 0 : struct mlx5_flow_dv_encap_decap_resource *ctx_resource = ctx->data;
4339 : : struct mlx5_flow_dv_encap_decap_resource *resource;
4340 : : uint32_t idx;
4341 : : int ret = 0;
4342 : : #ifdef HAVE_MLX5_HWS_SUPPORT
4343 : : struct mlx5dr_action_reformat_header hdr;
4344 : : #endif
4345 : :
4346 : : /* Register new encap/decap resource. */
4347 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], &idx);
4348 [ # # ]: 0 : if (!resource) {
4349 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4350 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4351 : : "cannot allocate resource memory");
4352 : 0 : return NULL;
4353 : : }
4354 : 0 : *resource = *ctx_resource;
4355 [ # # ]: 0 : if (sh->config.dv_flow_en == 2) {
4356 : : #ifdef HAVE_MLX5_HWS_SUPPORT
4357 : 0 : hdr.sz = ctx_resource->size;
4358 : 0 : hdr.data = ctx_resource->buf;
4359 : 0 : resource->action = mlx5dr_action_create_reformat
4360 : 0 : (ctx->data2, (enum mlx5dr_action_type)ctx_resource->reformat_type, 1,
4361 : 0 : &hdr, 0, ctx_resource->flags);
4362 [ # # ]: 0 : if (!resource->action)
4363 : : ret = -1;
4364 : : #else
4365 : : ret = -1;
4366 : : #endif
4367 : : } else {
4368 [ # # ]: 0 : if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
4369 : 0 : domain = sh->fdb_domain;
4370 [ # # ]: 0 : else if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
4371 : 0 : domain = sh->rx_domain;
4372 : : else
4373 : 0 : domain = sh->tx_domain;
4374 [ # # ]: 0 : ret = mlx5_flow_os_create_flow_action_packet_reformat(sh->cdev->ctx,
4375 : : domain, resource,
4376 : : &resource->action);
4377 : : }
4378 : : if (ret) {
4379 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], idx);
4380 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4381 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4382 : : NULL, "cannot create action");
4383 : 0 : return NULL;
4384 : : }
4385 : 0 : resource->idx = idx;
4386 : 0 : return &resource->entry;
4387 : : }
4388 : :
4389 : : struct mlx5_list_entry *
4390 : 0 : mlx5_flow_encap_decap_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
4391 : : void *cb_ctx)
4392 : : {
4393 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4394 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4395 : : struct mlx5_flow_dv_encap_decap_resource *cache_resource;
4396 : : struct mlx5_flow_dv_encap_decap_resource *old_resource;
4397 : : uint32_t idx;
4398 : :
4399 : 0 : cache_resource = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
4400 : : &idx);
4401 [ # # ]: 0 : if (!cache_resource) {
4402 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4403 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4404 : : "cannot allocate resource memory");
4405 : 0 : return NULL;
4406 : : }
4407 : : old_resource = container_of(oentry, typeof(*old_resource), entry);
4408 : : memcpy(cache_resource, old_resource, sizeof(*cache_resource));
4409 : 0 : cache_resource->idx = idx;
4410 : 0 : return &cache_resource->entry;
4411 : : }
4412 : :
4413 : : void
4414 : 0 : mlx5_flow_encap_decap_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4415 : : {
4416 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4417 : : struct mlx5_flow_dv_encap_decap_resource *res =
4418 : : container_of(entry, typeof(*res), entry);
4419 : :
4420 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], res->idx);
4421 : 0 : }
4422 : :
4423 : : int
4424 : 0 : mlx5_flow_encap_decap_resource_register(struct rte_eth_dev *dev,
4425 : : struct mlx5_flow_dv_encap_decap_resource *resource,
4426 : : bool is_root,
4427 : : struct mlx5_flow_dv_encap_decap_resource **encap_decap,
4428 : : struct rte_flow_error *error)
4429 : : {
4430 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4431 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
4432 : : struct mlx5_list_entry *entry;
4433 : : union {
4434 : : struct {
4435 : : uint32_t ft_type:8;
4436 : : uint32_t refmt_type:8;
4437 : : /*
4438 : : * Header reformat actions can be shared between
4439 : : * non-root tables. One bit to indicate non-root
4440 : : * table or not.
4441 : : */
4442 : : uint32_t is_root:1;
4443 : : uint32_t reserve:15;
4444 : : };
4445 : : uint32_t v32;
4446 : 0 : } encap_decap_key = {
4447 : : {
4448 : 0 : .ft_type = resource->ft_type,
4449 : 0 : .refmt_type = resource->reformat_type,
4450 : : .is_root = is_root,
4451 : : .reserve = 0,
4452 : : }
4453 : : };
4454 : 0 : struct mlx5_flow_cb_ctx ctx = {
4455 : : .error = error,
4456 : : .data = resource,
4457 : 0 : .data2 = priv->dr_ctx,
4458 : : };
4459 : : struct mlx5_hlist *encaps_decaps;
4460 : : uint64_t key64;
4461 : :
4462 : 0 : encaps_decaps = flow_dv_hlist_prepare(sh, &sh->encaps_decaps,
4463 : : "encaps_decaps",
4464 : : MLX5_FLOW_ENCAP_DECAP_HTABLE_SZ,
4465 : : true, true, sh,
4466 : : mlx5_flow_encap_decap_create_cb,
4467 : : mlx5_flow_encap_decap_match_cb,
4468 : : mlx5_flow_encap_decap_remove_cb,
4469 : : mlx5_flow_encap_decap_clone_cb,
4470 : : mlx5_flow_encap_decap_clone_free_cb,
4471 : : error);
4472 [ # # ]: 0 : if (unlikely(!encaps_decaps))
4473 : 0 : return -rte_errno;
4474 : 0 : key64 = __rte_raw_cksum(&encap_decap_key.v32,
4475 : : sizeof(encap_decap_key.v32), 0);
4476 [ # # ]: 0 : if (resource->reformat_type !=
4477 : 0 : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2 &&
4478 [ # # ]: 0 : resource->size)
4479 : 0 : key64 = __rte_raw_cksum(resource->buf, resource->size, key64);
4480 : 0 : entry = mlx5_hlist_register(encaps_decaps, key64, &ctx);
4481 [ # # ]: 0 : if (!entry)
4482 : 0 : return -rte_errno;
4483 : 0 : *encap_decap = container_of(entry, typeof(*resource), entry);
4484 : 0 : return 0;
4485 : : }
4486 : :
4487 : : /**
4488 : : * Find existing encap/decap resource or create and register a new one.
4489 : : *
4490 : : * @param[in, out] dev
4491 : : * Pointer to rte_eth_dev structure.
4492 : : * @param[in, out] resource
4493 : : * Pointer to encap/decap resource.
4494 : : * @param[in, out] dev_flow
4495 : : * Pointer to the dev_flow.
4496 : : * @param[out] error
4497 : : * pointer to error structure.
4498 : : *
4499 : : * @return
4500 : : * 0 on success otherwise -errno and errno is set.
4501 : : */
4502 : : static int
4503 : 0 : flow_dv_encap_decap_resource_register
4504 : : (struct rte_eth_dev *dev,
4505 : : struct mlx5_flow_dv_encap_decap_resource *resource,
4506 : : struct mlx5_flow *dev_flow,
4507 : : struct rte_flow_error *error)
4508 : : {
4509 : : int ret;
4510 : :
4511 : 0 : resource->flags = dev_flow->dv.group ? 0 : 1;
4512 : 0 : ret = mlx5_flow_encap_decap_resource_register(dev, resource, !!dev_flow->dv.group,
4513 : : &dev_flow->dv.encap_decap, error);
4514 [ # # ]: 0 : if (ret)
4515 : : return ret;
4516 : 0 : dev_flow->handle->dvh.rix_encap_decap = dev_flow->dv.encap_decap->idx;
4517 : 0 : return 0;
4518 : : }
4519 : :
4520 : : /**
4521 : : * Find existing table jump resource or create and register a new one.
4522 : : *
4523 : : * @param[in, out] dev
4524 : : * Pointer to rte_eth_dev structure.
4525 : : * @param[in, out] tbl
4526 : : * Pointer to flow table resource.
4527 : : * @parm[in, out] dev_flow
4528 : : * Pointer to the dev_flow.
4529 : : * @param[out] error
4530 : : * pointer to error structure.
4531 : : *
4532 : : * @return
4533 : : * 0 on success otherwise -errno and errno is set.
4534 : : */
4535 : : static int
4536 : : flow_dv_jump_tbl_resource_register
4537 : : (struct rte_eth_dev *dev __rte_unused,
4538 : : struct mlx5_flow_tbl_resource *tbl,
4539 : : struct mlx5_flow *dev_flow,
4540 : : struct rte_flow_error *error __rte_unused)
4541 : : {
4542 : : struct mlx5_flow_tbl_data_entry *tbl_data =
4543 : 0 : container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
4544 : :
4545 : : MLX5_ASSERT(tbl);
4546 : : MLX5_ASSERT(tbl_data->jump.action);
4547 : 0 : dev_flow->handle->rix_jump = tbl_data->idx;
4548 : 0 : dev_flow->dv.jump = &tbl_data->jump;
4549 : : return 0;
4550 : : }
4551 : :
4552 : : int
4553 : 0 : mlx5_flow_dv_port_id_match_cb(void *tool_ctx __rte_unused,
4554 : : struct mlx5_list_entry *entry, void *cb_ctx)
4555 : : {
4556 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4557 : 0 : struct mlx5_flow_dv_port_id_action_resource *ref = ctx->data;
4558 : : struct mlx5_flow_dv_port_id_action_resource *res =
4559 : : container_of(entry, typeof(*res), entry);
4560 : :
4561 : 0 : return ref->port_id != res->port_id;
4562 : : }
4563 : :
4564 : : struct mlx5_list_entry *
4565 : 0 : mlx5_flow_dv_port_id_create_cb(void *tool_ctx, void *cb_ctx)
4566 : : {
4567 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4568 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4569 : 0 : struct mlx5_flow_dv_port_id_action_resource *ref = ctx->data;
4570 : : struct mlx5_flow_dv_port_id_action_resource *resource;
4571 : : uint32_t idx;
4572 : : int ret;
4573 : :
4574 : : /* Register new port id action resource. */
4575 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID], &idx);
4576 [ # # ]: 0 : if (!resource) {
4577 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4578 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4579 : : "cannot allocate port_id action memory");
4580 : 0 : return NULL;
4581 : : }
4582 : 0 : *resource = *ref;
4583 : 0 : ret = mlx5_flow_os_create_flow_action_dest_port(sh->fdb_domain,
4584 : : ref->port_id,
4585 : : &resource->action);
4586 : : if (ret) {
4587 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], idx);
4588 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4589 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4590 : : "cannot create action");
4591 : 0 : return NULL;
4592 : : }
4593 : 0 : resource->idx = idx;
4594 : 0 : return &resource->entry;
4595 : : }
4596 : :
4597 : : struct mlx5_list_entry *
4598 : 0 : mlx5_flow_dv_port_id_clone_cb(void *tool_ctx,
4599 : : struct mlx5_list_entry *entry __rte_unused,
4600 : : void *cb_ctx)
4601 : : {
4602 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4603 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4604 : : struct mlx5_flow_dv_port_id_action_resource *resource;
4605 : : struct mlx5_flow_dv_port_id_action_resource *old_resource;
4606 : : uint32_t idx;
4607 : :
4608 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID], &idx);
4609 [ # # ]: 0 : if (!resource) {
4610 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4611 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4612 : : "cannot allocate port_id action memory");
4613 : 0 : return NULL;
4614 : : }
4615 : : old_resource = container_of(entry, typeof(*old_resource), entry);
4616 : : memcpy(resource, old_resource, sizeof(*old_resource));
4617 : 0 : resource->idx = idx;
4618 : 0 : return &resource->entry;
4619 : : }
4620 : :
4621 : : void
4622 : 0 : mlx5_flow_dv_port_id_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4623 : : {
4624 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4625 : : struct mlx5_flow_dv_port_id_action_resource *resource =
4626 : : container_of(entry, typeof(*resource), entry);
4627 : :
4628 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], resource->idx);
4629 : 0 : }
4630 : :
4631 : : /**
4632 : : * Find existing table port ID resource or create and register a new one.
4633 : : *
4634 : : * @param[in, out] dev
4635 : : * Pointer to rte_eth_dev structure.
4636 : : * @param[in, out] ref
4637 : : * Pointer to port ID action resource reference.
4638 : : * @parm[in, out] dev_flow
4639 : : * Pointer to the dev_flow.
4640 : : * @param[out] error
4641 : : * pointer to error structure.
4642 : : *
4643 : : * @return
4644 : : * 0 on success otherwise -errno and errno is set.
4645 : : */
4646 : : static int
4647 : 0 : flow_dv_port_id_action_resource_register
4648 : : (struct rte_eth_dev *dev,
4649 : : struct mlx5_flow_dv_port_id_action_resource *ref,
4650 : : struct mlx5_flow *dev_flow,
4651 : : struct rte_flow_error *error)
4652 : : {
4653 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4654 : : struct mlx5_list_entry *entry;
4655 : : struct mlx5_flow_dv_port_id_action_resource *resource;
4656 : 0 : struct mlx5_flow_cb_ctx ctx = {
4657 : : .error = error,
4658 : : .data = ref,
4659 : : };
4660 : :
4661 : 0 : entry = mlx5_list_register(priv->sh->port_id_action_list, &ctx);
4662 [ # # ]: 0 : if (!entry)
4663 : 0 : return -rte_errno;
4664 : : resource = container_of(entry, typeof(*resource), entry);
4665 : 0 : dev_flow->dv.port_id_action = resource;
4666 : 0 : dev_flow->handle->rix_port_id_action = resource->idx;
4667 : 0 : return 0;
4668 : : }
4669 : :
4670 : : int
4671 : 0 : mlx5_flow_dv_push_vlan_match_cb(void *tool_ctx __rte_unused,
4672 : : struct mlx5_list_entry *entry, void *cb_ctx)
4673 : : {
4674 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4675 : 0 : struct mlx5_flow_dv_push_vlan_action_resource *ref = ctx->data;
4676 : : struct mlx5_flow_dv_push_vlan_action_resource *res =
4677 : : container_of(entry, typeof(*res), entry);
4678 : :
4679 : 0 : return ref->vlan_tag != res->vlan_tag || ref->ft_type != res->ft_type;
4680 : : }
4681 : :
4682 : : struct mlx5_list_entry *
4683 : 0 : mlx5_flow_dv_push_vlan_create_cb(void *tool_ctx, void *cb_ctx)
4684 : : {
4685 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4686 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4687 : 0 : struct mlx5_flow_dv_push_vlan_action_resource *ref = ctx->data;
4688 : : struct mlx5_flow_dv_push_vlan_action_resource *resource;
4689 : : struct mlx5dv_dr_domain *domain;
4690 : : uint32_t idx;
4691 : : int ret;
4692 : :
4693 : : /* Register new port id action resource. */
4694 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PUSH_VLAN], &idx);
4695 [ # # ]: 0 : if (!resource) {
4696 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4697 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4698 : : "cannot allocate push_vlan action memory");
4699 : 0 : return NULL;
4700 : : }
4701 : 0 : *resource = *ref;
4702 [ # # ]: 0 : if (ref->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
4703 : 0 : domain = sh->fdb_domain;
4704 [ # # ]: 0 : else if (ref->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
4705 : 0 : domain = sh->rx_domain;
4706 : : else
4707 : 0 : domain = sh->tx_domain;
4708 : 0 : ret = mlx5_flow_os_create_flow_action_push_vlan(domain, ref->vlan_tag,
4709 : : &resource->action);
4710 : : if (ret) {
4711 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
4712 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4713 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4714 : : "cannot create push vlan action");
4715 : 0 : return NULL;
4716 : : }
4717 : 0 : resource->idx = idx;
4718 : 0 : return &resource->entry;
4719 : : }
4720 : :
4721 : : struct mlx5_list_entry *
4722 : 0 : mlx5_flow_dv_push_vlan_clone_cb(void *tool_ctx,
4723 : : struct mlx5_list_entry *entry __rte_unused,
4724 : : void *cb_ctx)
4725 : : {
4726 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4727 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4728 : : struct mlx5_flow_dv_push_vlan_action_resource *resource;
4729 : : struct mlx5_flow_dv_push_vlan_action_resource *old_resource;
4730 : : uint32_t idx;
4731 : :
4732 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PUSH_VLAN], &idx);
4733 [ # # ]: 0 : if (!resource) {
4734 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4735 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4736 : : "cannot allocate push_vlan action memory");
4737 : 0 : return NULL;
4738 : : }
4739 : : old_resource = container_of(entry, typeof(*old_resource), entry);
4740 : : memcpy(resource, old_resource, sizeof(*old_resource));
4741 : 0 : resource->idx = idx;
4742 : 0 : return &resource->entry;
4743 : : }
4744 : :
4745 : : void
4746 : 0 : mlx5_flow_dv_push_vlan_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4747 : : {
4748 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4749 : : struct mlx5_flow_dv_push_vlan_action_resource *resource =
4750 : : container_of(entry, typeof(*resource), entry);
4751 : :
4752 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], resource->idx);
4753 : 0 : }
4754 : :
4755 : : /**
4756 : : * Find existing push vlan resource or create and register a new one.
4757 : : *
4758 : : * @param [in, out] dev
4759 : : * Pointer to rte_eth_dev structure.
4760 : : * @param[in, out] ref
4761 : : * Pointer to port ID action resource reference.
4762 : : * @parm[in, out] dev_flow
4763 : : * Pointer to the dev_flow.
4764 : : * @param[out] error
4765 : : * pointer to error structure.
4766 : : *
4767 : : * @return
4768 : : * 0 on success otherwise -errno and errno is set.
4769 : : */
4770 : : static int
4771 : 0 : flow_dv_push_vlan_action_resource_register
4772 : : (struct rte_eth_dev *dev,
4773 : : struct mlx5_flow_dv_push_vlan_action_resource *ref,
4774 : : struct mlx5_flow *dev_flow,
4775 : : struct rte_flow_error *error)
4776 : : {
4777 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4778 : : struct mlx5_flow_dv_push_vlan_action_resource *resource;
4779 : : struct mlx5_list_entry *entry;
4780 : 0 : struct mlx5_flow_cb_ctx ctx = {
4781 : : .error = error,
4782 : : .data = ref,
4783 : : };
4784 : :
4785 : 0 : entry = mlx5_list_register(priv->sh->push_vlan_action_list, &ctx);
4786 [ # # ]: 0 : if (!entry)
4787 : 0 : return -rte_errno;
4788 : : resource = container_of(entry, typeof(*resource), entry);
4789 : :
4790 : 0 : dev_flow->handle->dvh.rix_push_vlan = resource->idx;
4791 : 0 : dev_flow->dv.push_vlan_res = resource;
4792 : 0 : return 0;
4793 : : }
4794 : :
4795 : : /**
4796 : : * Get the size of specific rte_flow_item_type hdr size
4797 : : *
4798 : : * @param[in] item_type
4799 : : * Tested rte_flow_item_type.
4800 : : *
4801 : : * @return
4802 : : * sizeof struct item_type, 0 if void or irrelevant.
4803 : : */
4804 : : size_t
4805 [ # # ]: 0 : mlx5_flow_dv_get_item_hdr_len(const enum rte_flow_item_type item_type)
4806 : : {
4807 : : size_t retval;
4808 : :
4809 : : switch (item_type) {
4810 : : case RTE_FLOW_ITEM_TYPE_ETH:
4811 : : retval = sizeof(struct rte_ether_hdr);
4812 : : break;
4813 : : case RTE_FLOW_ITEM_TYPE_VLAN:
4814 : : retval = sizeof(struct rte_vlan_hdr);
4815 : : break;
4816 : : case RTE_FLOW_ITEM_TYPE_IPV4:
4817 : : retval = sizeof(struct rte_ipv4_hdr);
4818 : : break;
4819 : : case RTE_FLOW_ITEM_TYPE_IPV6:
4820 : : retval = sizeof(struct rte_ipv6_hdr);
4821 : : break;
4822 : : case RTE_FLOW_ITEM_TYPE_UDP:
4823 : : retval = sizeof(struct rte_udp_hdr);
4824 : : break;
4825 : : case RTE_FLOW_ITEM_TYPE_TCP:
4826 : : retval = sizeof(struct rte_tcp_hdr);
4827 : : break;
4828 : : case RTE_FLOW_ITEM_TYPE_VXLAN:
4829 : : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
4830 : : retval = sizeof(struct rte_vxlan_hdr);
4831 : : break;
4832 : : case RTE_FLOW_ITEM_TYPE_GRE:
4833 : : case RTE_FLOW_ITEM_TYPE_NVGRE:
4834 : : retval = sizeof(struct rte_gre_hdr);
4835 : : break;
4836 : : case RTE_FLOW_ITEM_TYPE_MPLS:
4837 : : retval = sizeof(struct rte_mpls_hdr);
4838 : : break;
4839 : : case RTE_FLOW_ITEM_TYPE_VOID: /* Fall through. */
4840 : : default:
4841 : : retval = 0;
4842 : : break;
4843 : : }
4844 : 0 : return retval;
4845 : : }
4846 : :
4847 : : #define MLX5_ENCAP_IPV4_VERSION 0x40
4848 : : #define MLX5_ENCAP_IPV4_IHL_MIN 0x05
4849 : : #define MLX5_ENCAP_IPV4_TTL_DEF 0x40
4850 : : #define MLX5_ENCAP_IPV6_VTC_FLOW 0x60000000
4851 : : #define MLX5_ENCAP_IPV6_HOP_LIMIT 0xff
4852 : : #define MLX5_ENCAP_VXLAN_FLAGS 0x08000000
4853 : : #define MLX5_ENCAP_VXLAN_GPE_FLAGS 0x04
4854 : :
4855 : : /**
4856 : : * Convert the encap action data from list of rte_flow_item to raw buffer
4857 : : *
4858 : : * @param[in] items
4859 : : * Pointer to rte_flow_item objects list.
4860 : : * @param[out] buf
4861 : : * Pointer to the output buffer.
4862 : : * @param[out] size
4863 : : * Pointer to the output buffer size.
4864 : : * @param[out] error
4865 : : * Pointer to the error structure.
4866 : : *
4867 : : * @return
4868 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4869 : : */
4870 : : int
4871 : 0 : mlx5_flow_dv_convert_encap_data(const struct rte_flow_item *items, uint8_t *buf,
4872 : : size_t *size, struct rte_flow_error *error)
4873 : : {
4874 : : struct rte_ether_hdr *eth = NULL;
4875 : : struct rte_vlan_hdr *vlan = NULL;
4876 : : struct rte_ipv4_hdr *ipv4 = NULL;
4877 : : struct rte_ipv6_hdr *ipv6 = NULL;
4878 : : struct rte_udp_hdr *udp = NULL;
4879 : : struct rte_vxlan_hdr *vxlan = NULL;
4880 : : struct rte_vxlan_gpe_hdr *vxlan_gpe = NULL;
4881 : : struct rte_gre_hdr *gre = NULL;
4882 : : size_t len;
4883 : : size_t temp_size = 0;
4884 : :
4885 [ # # ]: 0 : if (!items)
4886 : 0 : return rte_flow_error_set(error, EINVAL,
4887 : : RTE_FLOW_ERROR_TYPE_ACTION,
4888 : : NULL, "invalid empty data");
4889 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4890 : 0 : len = mlx5_flow_dv_get_item_hdr_len(items->type);
4891 [ # # ]: 0 : if (len + temp_size > MLX5_ENCAP_MAX_LEN)
4892 : 0 : return rte_flow_error_set(error, EINVAL,
4893 : : RTE_FLOW_ERROR_TYPE_ACTION,
4894 : 0 : (void *)items->type,
4895 : : "items total size is too big"
4896 : : " for encap action");
4897 [ # # ]: 0 : if (items->spec)
4898 [ # # ]: 0 : rte_memcpy(&buf[temp_size], items->spec, len);
4899 [ # # # # : 0 : switch (items->type) {
# # # # #
# ]
4900 : 0 : case RTE_FLOW_ITEM_TYPE_ETH:
4901 : 0 : eth = (struct rte_ether_hdr *)&buf[temp_size];
4902 : 0 : break;
4903 : 0 : case RTE_FLOW_ITEM_TYPE_VLAN:
4904 : 0 : vlan = (struct rte_vlan_hdr *)&buf[temp_size];
4905 [ # # ]: 0 : if (!eth)
4906 : 0 : return rte_flow_error_set(error, EINVAL,
4907 : : RTE_FLOW_ERROR_TYPE_ACTION,
4908 : : (void *)items->type,
4909 : : "eth header not found");
4910 [ # # ]: 0 : if (!eth->ether_type)
4911 : 0 : eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_VLAN);
4912 : : break;
4913 : 0 : case RTE_FLOW_ITEM_TYPE_IPV4:
4914 : 0 : ipv4 = (struct rte_ipv4_hdr *)&buf[temp_size];
4915 [ # # ]: 0 : if (!vlan && !eth)
4916 : 0 : return rte_flow_error_set(error, EINVAL,
4917 : : RTE_FLOW_ERROR_TYPE_ACTION,
4918 : : (void *)items->type,
4919 : : "neither eth nor vlan"
4920 : : " header found");
4921 [ # # # # ]: 0 : if (vlan && !vlan->eth_proto)
4922 : 0 : vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV4);
4923 [ # # # # ]: 0 : else if (eth && !eth->ether_type)
4924 : 0 : eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV4);
4925 [ # # ]: 0 : if (!ipv4->version_ihl)
4926 : 0 : ipv4->version_ihl = MLX5_ENCAP_IPV4_VERSION |
4927 : : MLX5_ENCAP_IPV4_IHL_MIN;
4928 [ # # ]: 0 : if (!ipv4->time_to_live)
4929 : 0 : ipv4->time_to_live = MLX5_ENCAP_IPV4_TTL_DEF;
4930 : : break;
4931 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6:
4932 : 0 : ipv6 = (struct rte_ipv6_hdr *)&buf[temp_size];
4933 [ # # ]: 0 : if (!vlan && !eth)
4934 : 0 : return rte_flow_error_set(error, EINVAL,
4935 : : RTE_FLOW_ERROR_TYPE_ACTION,
4936 : : (void *)items->type,
4937 : : "neither eth nor vlan"
4938 : : " header found");
4939 [ # # # # ]: 0 : if (vlan && !vlan->eth_proto)
4940 : 0 : vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV6);
4941 [ # # # # ]: 0 : else if (eth && !eth->ether_type)
4942 : 0 : eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV6);
4943 [ # # ]: 0 : if (!ipv6->vtc_flow)
4944 : 0 : ipv6->vtc_flow =
4945 : : RTE_BE32(MLX5_ENCAP_IPV6_VTC_FLOW);
4946 [ # # ]: 0 : if (!ipv6->hop_limits)
4947 : 0 : ipv6->hop_limits = MLX5_ENCAP_IPV6_HOP_LIMIT;
4948 : : break;
4949 : 0 : case RTE_FLOW_ITEM_TYPE_UDP:
4950 : 0 : udp = (struct rte_udp_hdr *)&buf[temp_size];
4951 [ # # ]: 0 : if (!ipv4 && !ipv6)
4952 : 0 : return rte_flow_error_set(error, EINVAL,
4953 : : RTE_FLOW_ERROR_TYPE_ACTION,
4954 : : (void *)items->type,
4955 : : "ip header not found");
4956 [ # # # # ]: 0 : if (ipv4 && !ipv4->next_proto_id)
4957 : 0 : ipv4->next_proto_id = IPPROTO_UDP;
4958 [ # # # # ]: 0 : else if (ipv6 && !ipv6->proto)
4959 : 0 : ipv6->proto = IPPROTO_UDP;
4960 : : break;
4961 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN:
4962 : 0 : vxlan = (struct rte_vxlan_hdr *)&buf[temp_size];
4963 [ # # ]: 0 : if (!udp)
4964 : 0 : return rte_flow_error_set(error, EINVAL,
4965 : : RTE_FLOW_ERROR_TYPE_ACTION,
4966 : : (void *)items->type,
4967 : : "udp header not found");
4968 [ # # ]: 0 : if (!udp->dst_port)
4969 : 0 : udp->dst_port = RTE_BE16(MLX5_UDP_PORT_VXLAN);
4970 [ # # ]: 0 : if (!vxlan->vx_flags)
4971 : 0 : vxlan->vx_flags =
4972 : : RTE_BE32(MLX5_ENCAP_VXLAN_FLAGS);
4973 : : break;
4974 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
4975 : 0 : vxlan_gpe = (struct rte_vxlan_gpe_hdr *)&buf[temp_size];
4976 [ # # ]: 0 : if (!udp)
4977 : 0 : return rte_flow_error_set(error, EINVAL,
4978 : : RTE_FLOW_ERROR_TYPE_ACTION,
4979 : : (void *)items->type,
4980 : : "udp header not found");
4981 [ # # ]: 0 : if (!vxlan_gpe->proto)
4982 : 0 : return rte_flow_error_set(error, EINVAL,
4983 : : RTE_FLOW_ERROR_TYPE_ACTION,
4984 : : (void *)items->type,
4985 : : "next protocol not found");
4986 [ # # ]: 0 : if (!udp->dst_port)
4987 : 0 : udp->dst_port =
4988 : : RTE_BE16(MLX5_UDP_PORT_VXLAN_GPE);
4989 [ # # ]: 0 : if (!vxlan_gpe->vx_flags)
4990 : 0 : vxlan_gpe->vx_flags =
4991 : : MLX5_ENCAP_VXLAN_GPE_FLAGS;
4992 : : break;
4993 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
4994 : : case RTE_FLOW_ITEM_TYPE_NVGRE:
4995 : 0 : gre = (struct rte_gre_hdr *)&buf[temp_size];
4996 [ # # ]: 0 : if (!gre->proto)
4997 : 0 : return rte_flow_error_set(error, EINVAL,
4998 : : RTE_FLOW_ERROR_TYPE_ACTION,
4999 : 0 : (void *)items->type,
5000 : : "next protocol not found");
5001 [ # # ]: 0 : if (!ipv4 && !ipv6)
5002 : 0 : return rte_flow_error_set(error, EINVAL,
5003 : : RTE_FLOW_ERROR_TYPE_ACTION,
5004 : 0 : (void *)items->type,
5005 : : "ip header not found");
5006 [ # # # # ]: 0 : if (ipv4 && !ipv4->next_proto_id)
5007 : 0 : ipv4->next_proto_id = IPPROTO_GRE;
5008 [ # # # # ]: 0 : else if (ipv6 && !ipv6->proto)
5009 : 0 : ipv6->proto = IPPROTO_GRE;
5010 : : break;
5011 : : case RTE_FLOW_ITEM_TYPE_VOID:
5012 : : break;
5013 : 0 : default:
5014 : 0 : return rte_flow_error_set(error, EINVAL,
5015 : : RTE_FLOW_ERROR_TYPE_ACTION,
5016 : 0 : (void *)items->type,
5017 : : "unsupported item type");
5018 : : break;
5019 : : }
5020 : : temp_size += len;
5021 : : }
5022 : 0 : *size = temp_size;
5023 : 0 : return 0;
5024 : : }
5025 : :
5026 : : static int
5027 : 0 : flow_dv_zero_encap_udp_csum(void *data, struct rte_flow_error *error)
5028 : : {
5029 : : struct rte_ether_hdr *eth = NULL;
5030 : : struct rte_vlan_hdr *vlan = NULL;
5031 : : struct rte_ipv4_hdr *ipv4 = NULL;
5032 : : struct rte_ipv6_hdr *ipv6 = NULL;
5033 : : struct rte_udp_hdr *udp = NULL;
5034 : : char *next_hdr;
5035 : : uint16_t proto;
5036 : :
5037 : : eth = (struct rte_ether_hdr *)data;
5038 : 0 : next_hdr = (char *)(eth + 1);
5039 : 0 : proto = RTE_BE16(eth->ether_type);
5040 : :
5041 : : /* VLAN skipping */
5042 [ # # ]: 0 : while (proto == RTE_ETHER_TYPE_VLAN || proto == RTE_ETHER_TYPE_QINQ) {
5043 : : vlan = (struct rte_vlan_hdr *)next_hdr;
5044 : 0 : proto = RTE_BE16(vlan->eth_proto);
5045 : 0 : next_hdr += sizeof(struct rte_vlan_hdr);
5046 : : }
5047 : :
5048 : : /* non IPv4/IPv6 header. not supported */
5049 [ # # ]: 0 : if (proto != RTE_ETHER_TYPE_IPV4 && proto != RTE_ETHER_TYPE_IPV6) {
5050 : 0 : return rte_flow_error_set(error, ENOTSUP,
5051 : : RTE_FLOW_ERROR_TYPE_ACTION,
5052 : : NULL, "Cannot offload non IPv4/IPv6");
5053 : : }
5054 : :
5055 [ # # ]: 0 : if (proto == RTE_ETHER_TYPE_IPV4) {
5056 : : ipv4 = (struct rte_ipv4_hdr *)next_hdr;
5057 : : /* ignore non UDP */
5058 [ # # ]: 0 : if (ipv4->next_proto_id != IPPROTO_UDP)
5059 : : return 0;
5060 : 0 : udp = (struct rte_udp_hdr *)(ipv4 + 1);
5061 : : } else {
5062 : : ipv6 = (struct rte_ipv6_hdr *)next_hdr;
5063 : : /* ignore non UDP */
5064 [ # # ]: 0 : if (ipv6->proto != IPPROTO_UDP)
5065 : : return 0;
5066 : 0 : udp = (struct rte_udp_hdr *)(ipv6 + 1);
5067 : : }
5068 : :
5069 : 0 : udp->dgram_cksum = 0;
5070 : :
5071 : 0 : return 0;
5072 : : }
5073 : :
5074 : : /**
5075 : : * Convert L2 encap action to DV specification.
5076 : : *
5077 : : * @param[in] dev
5078 : : * Pointer to rte_eth_dev structure.
5079 : : * @param[in] action
5080 : : * Pointer to action structure.
5081 : : * @param[in, out] dev_flow
5082 : : * Pointer to the mlx5_flow.
5083 : : * @param[in] transfer
5084 : : * Mark if the flow is E-Switch flow.
5085 : : * @param[out] error
5086 : : * Pointer to the error structure.
5087 : : *
5088 : : * @return
5089 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5090 : : */
5091 : : static int
5092 : 0 : flow_dv_create_action_l2_encap(struct rte_eth_dev *dev,
5093 : : const struct rte_flow_action *action,
5094 : : struct mlx5_flow *dev_flow,
5095 : : uint8_t transfer,
5096 : : struct rte_flow_error *error)
5097 : : {
5098 : : const struct rte_flow_item *encap_data;
5099 : : const struct rte_flow_action_raw_encap *raw_encap_data;
5100 [ # # ]: 0 : struct mlx5_flow_dv_encap_decap_resource res = {
5101 : : .reformat_type =
5102 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L2_TUNNEL,
5103 : : .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
5104 : : MLX5DV_FLOW_TABLE_TYPE_NIC_TX,
5105 : : };
5106 : :
5107 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
5108 : 0 : raw_encap_data =
5109 : : (const struct rte_flow_action_raw_encap *)action->conf;
5110 : 0 : res.size = raw_encap_data->size;
5111 : 0 : memcpy(res.buf, raw_encap_data->data, res.size);
5112 : : } else {
5113 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP)
5114 : 0 : encap_data =
5115 : : ((const struct rte_flow_action_vxlan_encap *)
5116 : 0 : action->conf)->definition;
5117 : : else
5118 : 0 : encap_data =
5119 : : ((const struct rte_flow_action_nvgre_encap *)
5120 : 0 : action->conf)->definition;
5121 [ # # ]: 0 : if (mlx5_flow_dv_convert_encap_data(encap_data, res.buf,
5122 : : &res.size, error))
5123 : 0 : return -rte_errno;
5124 : : }
5125 [ # # ]: 0 : if (flow_dv_zero_encap_udp_csum(res.buf, error))
5126 : 0 : return -rte_errno;
5127 [ # # ]: 0 : if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
5128 : 0 : return rte_flow_error_set(error, EINVAL,
5129 : : RTE_FLOW_ERROR_TYPE_ACTION,
5130 : : NULL, "can't create L2 encap action");
5131 : : return 0;
5132 : : }
5133 : :
5134 : : /**
5135 : : * Convert L2 decap action to DV specification.
5136 : : *
5137 : : * @param[in] dev
5138 : : * Pointer to rte_eth_dev structure.
5139 : : * @param[in, out] dev_flow
5140 : : * Pointer to the mlx5_flow.
5141 : : * @param[in] transfer
5142 : : * Mark if the flow is E-Switch flow.
5143 : : * @param[out] error
5144 : : * Pointer to the error structure.
5145 : : *
5146 : : * @return
5147 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5148 : : */
5149 : : static int
5150 : 0 : flow_dv_create_action_l2_decap(struct rte_eth_dev *dev,
5151 : : struct mlx5_flow *dev_flow,
5152 : : uint8_t transfer,
5153 : : struct rte_flow_error *error)
5154 : : {
5155 [ # # ]: 0 : struct mlx5_flow_dv_encap_decap_resource res = {
5156 : : .size = 0,
5157 : : .reformat_type =
5158 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2,
5159 : : .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
5160 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX,
5161 : : };
5162 : :
5163 [ # # ]: 0 : if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
5164 : 0 : return rte_flow_error_set(error, EINVAL,
5165 : : RTE_FLOW_ERROR_TYPE_ACTION,
5166 : : NULL, "can't create L2 decap action");
5167 : : return 0;
5168 : : }
5169 : :
5170 : : /**
5171 : : * Convert raw decap/encap (L3 tunnel) action to DV specification.
5172 : : *
5173 : : * @param[in] dev
5174 : : * Pointer to rte_eth_dev structure.
5175 : : * @param[in] action
5176 : : * Pointer to action structure.
5177 : : * @param[in, out] dev_flow
5178 : : * Pointer to the mlx5_flow.
5179 : : * @param[in] attr
5180 : : * Pointer to the flow attributes.
5181 : : * @param[out] error
5182 : : * Pointer to the error structure.
5183 : : *
5184 : : * @return
5185 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5186 : : */
5187 : : static int
5188 [ # # ]: 0 : flow_dv_create_action_raw_encap(struct rte_eth_dev *dev,
5189 : : const struct rte_flow_action *action,
5190 : : struct mlx5_flow *dev_flow,
5191 : : const struct rte_flow_attr *attr,
5192 : : struct rte_flow_error *error)
5193 : : {
5194 : : const struct rte_flow_action_raw_encap *encap_data;
5195 : : struct mlx5_flow_dv_encap_decap_resource res;
5196 : :
5197 : : memset(&res, 0, sizeof(res));
5198 : 0 : encap_data = (const struct rte_flow_action_raw_encap *)action->conf;
5199 : 0 : res.size = encap_data->size;
5200 [ # # ]: 0 : memcpy(res.buf, encap_data->data, res.size);
5201 [ # # ]: 0 : res.reformat_type = res.size < MLX5_ENCAPSULATION_DECISION_SIZE ?
5202 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L3_TUNNEL_TO_L2 :
5203 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L3_TUNNEL;
5204 [ # # ]: 0 : if (attr->transfer)
5205 : 0 : res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
5206 : : else
5207 : 0 : res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
5208 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
5209 [ # # ]: 0 : if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
5210 : 0 : return rte_flow_error_set(error, EINVAL,
5211 : : RTE_FLOW_ERROR_TYPE_ACTION,
5212 : : NULL, "can't create encap action");
5213 : : return 0;
5214 : : }
5215 : :
5216 : : /**
5217 : : * Create action push VLAN.
5218 : : *
5219 : : * @param[in] dev
5220 : : * Pointer to rte_eth_dev structure.
5221 : : * @param[in] attr
5222 : : * Pointer to the flow attributes.
5223 : : * @param[in] vlan
5224 : : * Pointer to the vlan to push to the Ethernet header.
5225 : : * @param[in, out] dev_flow
5226 : : * Pointer to the mlx5_flow.
5227 : : * @param[out] error
5228 : : * Pointer to the error structure.
5229 : : *
5230 : : * @return
5231 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5232 : : */
5233 : : static int
5234 [ # # ]: 0 : flow_dv_create_action_push_vlan(struct rte_eth_dev *dev,
5235 : : const struct rte_flow_attr *attr,
5236 : : const struct rte_vlan_hdr *vlan,
5237 : : struct mlx5_flow *dev_flow,
5238 : : struct rte_flow_error *error)
5239 : : {
5240 : : struct mlx5_flow_dv_push_vlan_action_resource res;
5241 : :
5242 : : memset(&res, 0, sizeof(res));
5243 : 0 : res.vlan_tag =
5244 [ # # ]: 0 : rte_cpu_to_be_32(((uint32_t)vlan->eth_proto) << 16 |
5245 : : vlan->vlan_tci);
5246 [ # # ]: 0 : if (attr->transfer)
5247 : 0 : res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
5248 : : else
5249 : 0 : res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
5250 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
5251 : 0 : return flow_dv_push_vlan_action_resource_register
5252 : : (dev, &res, dev_flow, error);
5253 : : }
5254 : :
5255 : : /**
5256 : : * Validate the modify-header actions.
5257 : : *
5258 : : * @param[in] action_flags
5259 : : * Holds the actions detected until now.
5260 : : * @param[in] action
5261 : : * Pointer to the modify action.
5262 : : * @param[out] error
5263 : : * Pointer to error structure.
5264 : : *
5265 : : * @return
5266 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5267 : : */
5268 : : static int
5269 : 0 : flow_dv_validate_action_modify_hdr(const uint64_t action_flags,
5270 : : const struct rte_flow_action *action,
5271 : : struct rte_flow_error *error)
5272 : : {
5273 [ # # # # ]: 0 : if (action->type != RTE_FLOW_ACTION_TYPE_DEC_TTL && !action->conf)
5274 : 0 : return rte_flow_error_set(error, EINVAL,
5275 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5276 : : NULL, "action configuration not set");
5277 : :
5278 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
5279 : 0 : return rte_flow_error_set(error, EINVAL,
5280 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5281 : : "can't have encap action before"
5282 : : " modify action");
5283 : : return 0;
5284 : : }
5285 : :
5286 : : /**
5287 : : * Validate the modify-header MAC address actions.
5288 : : *
5289 : : * @param[in] action_flags
5290 : : * Holds the actions detected until now.
5291 : : * @param[in] action
5292 : : * Pointer to the modify action.
5293 : : * @param[in] item_flags
5294 : : * Holds the items detected.
5295 : : * @param[out] error
5296 : : * Pointer to error structure.
5297 : : *
5298 : : * @return
5299 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5300 : : */
5301 : : static int
5302 : 0 : flow_dv_validate_action_modify_mac(const uint64_t action_flags,
5303 : : const struct rte_flow_action *action,
5304 : : const uint64_t item_flags,
5305 : : struct rte_flow_error *error)
5306 : : {
5307 : : int ret = 0;
5308 : :
5309 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5310 [ # # ]: 0 : if (!ret) {
5311 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_L2))
5312 : 0 : return rte_flow_error_set(error, EINVAL,
5313 : : RTE_FLOW_ERROR_TYPE_ACTION,
5314 : : NULL,
5315 : : "no L2 item in pattern");
5316 : : }
5317 : : return ret;
5318 : : }
5319 : :
5320 : : /**
5321 : : * Validate the modify-header IPv4 address actions.
5322 : : *
5323 : : * @param[in] action_flags
5324 : : * Holds the actions detected until now.
5325 : : * @param[in] action
5326 : : * Pointer to the modify action.
5327 : : * @param[in] item_flags
5328 : : * Holds the items detected.
5329 : : * @param[out] error
5330 : : * Pointer to error structure.
5331 : : *
5332 : : * @return
5333 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5334 : : */
5335 : : static int
5336 : 0 : flow_dv_validate_action_modify_ipv4(const uint64_t action_flags,
5337 : : const struct rte_flow_action *action,
5338 : : const uint64_t item_flags,
5339 : : struct rte_flow_error *error)
5340 : : {
5341 : : int ret = 0;
5342 : : uint64_t layer;
5343 : :
5344 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5345 [ # # ]: 0 : if (!ret) {
5346 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5347 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L3_IPV4 :
5348 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4;
5349 [ # # ]: 0 : if (!(item_flags & layer))
5350 : 0 : return rte_flow_error_set(error, EINVAL,
5351 : : RTE_FLOW_ERROR_TYPE_ACTION,
5352 : : NULL,
5353 : : "no ipv4 item in pattern");
5354 : : }
5355 : : return ret;
5356 : : }
5357 : :
5358 : : /**
5359 : : * Validate the modify-header IPv6 address actions.
5360 : : *
5361 : : * @param[in] action_flags
5362 : : * Holds the actions detected until now.
5363 : : * @param[in] action
5364 : : * Pointer to the modify action.
5365 : : * @param[in] item_flags
5366 : : * Holds the items detected.
5367 : : * @param[out] error
5368 : : * Pointer to error structure.
5369 : : *
5370 : : * @return
5371 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5372 : : */
5373 : : static int
5374 : 0 : flow_dv_validate_action_modify_ipv6(const uint64_t action_flags,
5375 : : const struct rte_flow_action *action,
5376 : : const uint64_t item_flags,
5377 : : struct rte_flow_error *error)
5378 : : {
5379 : : int ret = 0;
5380 : : uint64_t layer;
5381 : :
5382 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5383 [ # # ]: 0 : if (!ret) {
5384 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5385 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L3_IPV6 :
5386 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6;
5387 [ # # ]: 0 : if (!(item_flags & layer))
5388 : 0 : return rte_flow_error_set(error, EINVAL,
5389 : : RTE_FLOW_ERROR_TYPE_ACTION,
5390 : : NULL,
5391 : : "no ipv6 item in pattern");
5392 : : }
5393 : : return ret;
5394 : : }
5395 : :
5396 : : /**
5397 : : * Validate the modify-header TP actions.
5398 : : *
5399 : : * @param[in] action_flags
5400 : : * Holds the actions detected until now.
5401 : : * @param[in] action
5402 : : * Pointer to the modify action.
5403 : : * @param[in] item_flags
5404 : : * Holds the items detected.
5405 : : * @param[out] error
5406 : : * Pointer to error structure.
5407 : : *
5408 : : * @return
5409 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5410 : : */
5411 : : static int
5412 : 0 : flow_dv_validate_action_modify_tp(const uint64_t action_flags,
5413 : : const struct rte_flow_action *action,
5414 : : const uint64_t item_flags,
5415 : : struct rte_flow_error *error)
5416 : : {
5417 : : int ret = 0;
5418 : : uint64_t layer;
5419 : :
5420 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5421 [ # # ]: 0 : if (!ret) {
5422 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5423 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L4 :
5424 : : MLX5_FLOW_LAYER_OUTER_L4;
5425 [ # # ]: 0 : if (!(item_flags & layer))
5426 : 0 : return rte_flow_error_set(error, EINVAL,
5427 : : RTE_FLOW_ERROR_TYPE_ACTION,
5428 : : NULL, "no transport layer "
5429 : : "in pattern");
5430 : : }
5431 : : return ret;
5432 : : }
5433 : :
5434 : : /**
5435 : : * Validate the modify-header actions of increment/decrement
5436 : : * TCP Sequence-number.
5437 : : *
5438 : : * @param[in] action_flags
5439 : : * Holds the actions detected until now.
5440 : : * @param[in] action
5441 : : * Pointer to the modify action.
5442 : : * @param[in] item_flags
5443 : : * Holds the items detected.
5444 : : * @param[out] error
5445 : : * Pointer to error structure.
5446 : : *
5447 : : * @return
5448 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5449 : : */
5450 : : static int
5451 : 0 : flow_dv_validate_action_modify_tcp_seq(const uint64_t action_flags,
5452 : : const struct rte_flow_action *action,
5453 : : const uint64_t item_flags,
5454 : : struct rte_flow_error *error)
5455 : : {
5456 : : int ret = 0;
5457 : : uint64_t layer;
5458 : :
5459 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5460 [ # # ]: 0 : if (!ret) {
5461 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5462 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L4_TCP :
5463 : : MLX5_FLOW_LAYER_OUTER_L4_TCP;
5464 [ # # ]: 0 : if (!(item_flags & layer))
5465 : 0 : return rte_flow_error_set(error, EINVAL,
5466 : : RTE_FLOW_ERROR_TYPE_ACTION,
5467 : : NULL, "no TCP item in"
5468 : : " pattern");
5469 [ # # ]: 0 : if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ &&
5470 [ # # # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_DEC_TCP_SEQ)) ||
5471 : 0 : (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ &&
5472 [ # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_INC_TCP_SEQ)))
5473 : 0 : return rte_flow_error_set(error, EINVAL,
5474 : : RTE_FLOW_ERROR_TYPE_ACTION,
5475 : : NULL,
5476 : : "cannot decrease and increase"
5477 : : " TCP sequence number"
5478 : : " at the same time");
5479 : : }
5480 : : return ret;
5481 : : }
5482 : :
5483 : : /**
5484 : : * Validate the modify-header actions of increment/decrement
5485 : : * TCP Acknowledgment number.
5486 : : *
5487 : : * @param[in] action_flags
5488 : : * Holds the actions detected until now.
5489 : : * @param[in] action
5490 : : * Pointer to the modify action.
5491 : : * @param[in] item_flags
5492 : : * Holds the items detected.
5493 : : * @param[out] error
5494 : : * Pointer to error structure.
5495 : : *
5496 : : * @return
5497 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5498 : : */
5499 : : static int
5500 : 0 : flow_dv_validate_action_modify_tcp_ack(const uint64_t action_flags,
5501 : : const struct rte_flow_action *action,
5502 : : const uint64_t item_flags,
5503 : : struct rte_flow_error *error)
5504 : : {
5505 : : int ret = 0;
5506 : : uint64_t layer;
5507 : :
5508 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5509 [ # # ]: 0 : if (!ret) {
5510 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5511 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L4_TCP :
5512 : : MLX5_FLOW_LAYER_OUTER_L4_TCP;
5513 [ # # ]: 0 : if (!(item_flags & layer))
5514 : 0 : return rte_flow_error_set(error, EINVAL,
5515 : : RTE_FLOW_ERROR_TYPE_ACTION,
5516 : : NULL, "no TCP item in"
5517 : : " pattern");
5518 [ # # ]: 0 : if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_ACK &&
5519 [ # # # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_DEC_TCP_ACK)) ||
5520 : 0 : (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK &&
5521 [ # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_INC_TCP_ACK)))
5522 : 0 : return rte_flow_error_set(error, EINVAL,
5523 : : RTE_FLOW_ERROR_TYPE_ACTION,
5524 : : NULL,
5525 : : "cannot decrease and increase"
5526 : : " TCP acknowledgment number"
5527 : : " at the same time");
5528 : : }
5529 : : return ret;
5530 : : }
5531 : :
5532 : : /**
5533 : : * Validate the modify-header TTL actions.
5534 : : *
5535 : : * @param[in] action_flags
5536 : : * Holds the actions detected until now.
5537 : : * @param[in] action
5538 : : * Pointer to the modify action.
5539 : : * @param[in] item_flags
5540 : : * Holds the items detected.
5541 : : * @param[out] error
5542 : : * Pointer to error structure.
5543 : : *
5544 : : * @return
5545 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5546 : : */
5547 : : static int
5548 : 0 : flow_dv_validate_action_modify_ttl(const uint64_t action_flags,
5549 : : const struct rte_flow_action *action,
5550 : : const uint64_t item_flags,
5551 : : struct rte_flow_error *error)
5552 : : {
5553 : : int ret = 0;
5554 : : uint64_t layer;
5555 : :
5556 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5557 [ # # ]: 0 : if (!ret) {
5558 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5559 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L3 :
5560 : : MLX5_FLOW_LAYER_OUTER_L3;
5561 [ # # ]: 0 : if (!(item_flags & layer))
5562 : 0 : return rte_flow_error_set(error, EINVAL,
5563 : : RTE_FLOW_ERROR_TYPE_ACTION,
5564 : : NULL,
5565 : : "no IP protocol in pattern");
5566 : : }
5567 : : return ret;
5568 : : }
5569 : :
5570 : : /**
5571 : : * Validate the generic modify field actions.
5572 : : * @param[in] dev
5573 : : * Pointer to the rte_eth_dev structure.
5574 : : * @param[in] action_flags
5575 : : * Holds the actions detected until now.
5576 : : * @param[in] action
5577 : : * Pointer to the modify action.
5578 : : * @param[in] attr
5579 : : * Pointer to the flow attributes.
5580 : : * @param root
5581 : : * Whether action is on root table.
5582 : : * @param[out] error
5583 : : * Pointer to error structure.
5584 : : *
5585 : : * @return
5586 : : * Number of header fields to modify (0 or more) on success,
5587 : : * a negative errno value otherwise and rte_errno is set.
5588 : : */
5589 : : static int
5590 : 0 : flow_dv_validate_action_modify_field(struct rte_eth_dev *dev,
5591 : : const uint64_t action_flags,
5592 : : const struct rte_flow_action *action,
5593 : : const struct rte_flow_attr *attr,
5594 : : bool root,
5595 : : struct rte_flow_error *error)
5596 : : {
5597 : : int ret = 0;
5598 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5599 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
5600 : 0 : struct mlx5_hca_attr *hca_attr = &priv->sh->cdev->config.hca_attr;
5601 : 0 : const struct rte_flow_action_modify_field *conf = action->conf;
5602 : 0 : const struct rte_flow_field_data *src_data = &conf->src;
5603 : 0 : const struct rte_flow_field_data *dst_data = &conf->dst;
5604 : 0 : uint32_t dst_width, src_width, width = conf->width;
5605 : :
5606 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5607 [ # # ]: 0 : if (ret)
5608 : : return ret;
5609 [ # # ]: 0 : if (src_data->field == RTE_FLOW_FIELD_FLEX_ITEM ||
5610 [ # # ]: 0 : dst_data->field == RTE_FLOW_FIELD_FLEX_ITEM)
5611 : 0 : return rte_flow_error_set(error, ENOTSUP,
5612 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5613 : : "flex item fields modification"
5614 : : " is not supported");
5615 : 0 : dst_width = mlx5_flow_item_field_width(dev, dst_data->field,
5616 : : -1, attr, error);
5617 : 0 : src_width = mlx5_flow_item_field_width(dev, src_data->field,
5618 : : dst_width, attr, error);
5619 [ # # ]: 0 : if (width == 0)
5620 : 0 : return rte_flow_error_set(error, EINVAL,
5621 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5622 : : "no bits are requested to be modified");
5623 [ # # ]: 0 : else if (width > dst_width || width > src_width)
5624 : 0 : return rte_flow_error_set(error, EINVAL,
5625 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5626 : : "cannot modify more bits than"
5627 : : " the width of a field");
5628 [ # # ]: 0 : if (dst_data->field != RTE_FLOW_FIELD_VALUE &&
5629 : : dst_data->field != RTE_FLOW_FIELD_POINTER) {
5630 [ # # ]: 0 : if (dst_data->offset + width > dst_width)
5631 : 0 : return rte_flow_error_set(error, EINVAL,
5632 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5633 : : "destination offset is too big");
5634 : 0 : ret = mlx5_flow_validate_modify_field_level(dst_data, error);
5635 [ # # ]: 0 : if (ret)
5636 : : return ret;
5637 [ # # ]: 0 : if (dst_data->tag_index &&
5638 [ # # ]: 0 : !flow_modify_field_support_tag_array(dst_data->field))
5639 : 0 : return rte_flow_error_set(error, EINVAL,
5640 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5641 : : "destination tag index is not supported");
5642 [ # # ]: 0 : if (dst_data->class_id)
5643 : 0 : return rte_flow_error_set(error, EINVAL,
5644 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5645 : : "destination class ID is not supported");
5646 : : }
5647 [ # # ]: 0 : if (src_data->field != RTE_FLOW_FIELD_VALUE &&
5648 : : src_data->field != RTE_FLOW_FIELD_POINTER) {
5649 [ # # ]: 0 : if (conf->operation != RTE_FLOW_MODIFY_SET)
5650 : 0 : return rte_flow_error_set(error, ENOTSUP,
5651 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5652 : 0 : &conf->operation,
5653 : : "modify field action type add is not"
5654 : : " supported when src field type is"
5655 : : " not value/pointer");
5656 [ # # ]: 0 : if (root)
5657 : 0 : return rte_flow_error_set(error, ENOTSUP,
5658 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5659 : : "modify field action is not"
5660 : : " supported for group 0");
5661 [ # # ]: 0 : if (src_data->offset + width > src_width)
5662 : 0 : return rte_flow_error_set(error, EINVAL,
5663 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5664 : : "source offset is too big");
5665 : 0 : ret = mlx5_flow_validate_modify_field_level(src_data, error);
5666 [ # # ]: 0 : if (ret)
5667 : : return ret;
5668 [ # # ]: 0 : if (src_data->tag_index &&
5669 [ # # ]: 0 : !flow_modify_field_support_tag_array(src_data->field))
5670 : 0 : return rte_flow_error_set(error, EINVAL,
5671 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5672 : : "source tag index is not supported");
5673 [ # # ]: 0 : if (src_data->class_id)
5674 : 0 : return rte_flow_error_set(error, EINVAL,
5675 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5676 : : "source class ID is not supported");
5677 : : }
5678 [ # # ]: 0 : if ((dst_data->field == src_data->field) &&
5679 [ # # ]: 0 : (dst_data->level == src_data->level))
5680 : 0 : return rte_flow_error_set(error, EINVAL,
5681 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5682 : : "source and destination fields"
5683 : : " cannot be the same");
5684 : 0 : if (dst_data->field == RTE_FLOW_FIELD_VALUE ||
5685 [ # # ]: 0 : dst_data->field == RTE_FLOW_FIELD_POINTER ||
5686 : : dst_data->field == RTE_FLOW_FIELD_MARK)
5687 : 0 : return rte_flow_error_set(error, EINVAL,
5688 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5689 : : "mark, immediate value or a pointer to it"
5690 : : " cannot be used as a destination");
5691 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_START ||
5692 : : src_data->field == RTE_FLOW_FIELD_START)
5693 : 0 : return rte_flow_error_set(error, ENOTSUP,
5694 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5695 : : "modifications of an arbitrary"
5696 : : " place in a packet is not supported");
5697 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_VLAN_TYPE ||
5698 : : src_data->field == RTE_FLOW_FIELD_VLAN_TYPE)
5699 : 0 : return rte_flow_error_set(error, ENOTSUP,
5700 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5701 : : "modifications of the 802.1Q Tag"
5702 : : " Identifier is not supported");
5703 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_VXLAN_VNI ||
5704 : : src_data->field == RTE_FLOW_FIELD_VXLAN_VNI)
5705 : 0 : return rte_flow_error_set(error, ENOTSUP,
5706 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5707 : : "modifications of the VXLAN Network"
5708 : : " Identifier is not supported");
5709 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_GENEVE_VNI ||
5710 : : src_data->field == RTE_FLOW_FIELD_GENEVE_VNI)
5711 : 0 : return rte_flow_error_set(error, ENOTSUP,
5712 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5713 : : "modifications of the GENEVE Network"
5714 : : " Identifier is not supported");
5715 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_GENEVE_OPT_TYPE ||
5716 : : src_data->field == RTE_FLOW_FIELD_GENEVE_OPT_TYPE)
5717 : 0 : return rte_flow_error_set(error, ENOTSUP,
5718 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5719 : : "modifications of the GENEVE option type is not supported");
5720 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_GENEVE_OPT_CLASS ||
5721 : : src_data->field == RTE_FLOW_FIELD_GENEVE_OPT_CLASS)
5722 : 0 : return rte_flow_error_set(error, ENOTSUP,
5723 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5724 : : "modifications of the GENEVE option class is not supported");
5725 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_GENEVE_OPT_DATA ||
5726 : : src_data->field == RTE_FLOW_FIELD_GENEVE_OPT_DATA)
5727 : 0 : return rte_flow_error_set(error, ENOTSUP,
5728 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5729 : : "modifications of the GENEVE option data is not supported");
5730 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_MPLS ||
5731 : : src_data->field == RTE_FLOW_FIELD_MPLS)
5732 : 0 : return rte_flow_error_set(error, ENOTSUP,
5733 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5734 : : "modifications of the MPLS header "
5735 : : "is not supported");
5736 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_RANDOM ||
5737 : : src_data->field == RTE_FLOW_FIELD_RANDOM)
5738 : 0 : return rte_flow_error_set(error, ENOTSUP,
5739 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5740 : : "modifications of random value is not supported");
5741 [ # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_MARK ||
5742 : : src_data->field == RTE_FLOW_FIELD_MARK)
5743 [ # # # # ]: 0 : if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
5744 : 0 : !mlx5_flow_ext_mreg_supported(dev))
5745 : 0 : return rte_flow_error_set(error, ENOTSUP,
5746 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5747 : : "cannot modify mark in legacy mode"
5748 : : " or without extensive registers");
5749 [ # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_META ||
5750 [ # # ]: 0 : src_data->field == RTE_FLOW_FIELD_META) {
5751 [ # # # # ]: 0 : if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
5752 : 0 : !mlx5_flow_ext_mreg_supported(dev))
5753 : 0 : return rte_flow_error_set(error, ENOTSUP,
5754 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5755 : : "cannot modify meta without"
5756 : : " extensive registers support");
5757 : 0 : ret = flow_dv_get_metadata_reg(dev, attr, error);
5758 [ # # ]: 0 : if (ret < 0 || ret == REG_NON)
5759 : 0 : return rte_flow_error_set(error, ENOTSUP,
5760 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5761 : : "cannot modify meta without"
5762 : : " extensive registers available");
5763 : : }
5764 [ # # ]: 0 : if (conf->operation == RTE_FLOW_MODIFY_SUB)
5765 : 0 : return rte_flow_error_set(error, ENOTSUP,
5766 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5767 : : "sub operations are not supported");
5768 [ # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_IPV4_ECN ||
5769 [ # # # # ]: 0 : src_data->field == RTE_FLOW_FIELD_IPV4_ECN ||
5770 [ # # ]: 0 : dst_data->field == RTE_FLOW_FIELD_IPV6_ECN ||
5771 : : src_data->field == RTE_FLOW_FIELD_IPV6_ECN)
5772 [ # # # # ]: 0 : if (!hca_attr->modify_outer_ip_ecn && root)
5773 : 0 : return rte_flow_error_set(error, ENOTSUP,
5774 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5775 : : "modifications of the ECN for current firmware is not supported");
5776 : 0 : return (width / 32) + !!(width % 32);
5777 : : }
5778 : :
5779 : : /**
5780 : : * Validate jump action.
5781 : : *
5782 : : * @param[in] action
5783 : : * Pointer to the jump action.
5784 : : * @param[in] action_flags
5785 : : * Holds the actions detected until now.
5786 : : * @param[in] attributes
5787 : : * Pointer to flow attributes
5788 : : * @param[in] external
5789 : : * Action belongs to flow rule created by request external to PMD.
5790 : : * @param[out] error
5791 : : * Pointer to error structure.
5792 : : *
5793 : : * @return
5794 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5795 : : */
5796 : : static int
5797 : 0 : flow_dv_validate_action_jump(struct rte_eth_dev *dev,
5798 : : const struct mlx5_flow_tunnel *tunnel,
5799 : : const struct rte_flow_action *action,
5800 : : uint64_t action_flags,
5801 : : const struct rte_flow_attr *attributes,
5802 : : bool external, struct rte_flow_error *error)
5803 : : {
5804 : 0 : uint32_t target_group, table = 0;
5805 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5806 : : int ret = 0;
5807 : 0 : struct flow_grp_info grp_info = {
5808 : : .external = !!external,
5809 : 0 : .transfer = !!attributes->transfer,
5810 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
5811 : : .std_tbl_fix = 0
5812 : : };
5813 [ # # ]: 0 : if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
5814 : : MLX5_FLOW_FATE_ESWITCH_ACTIONS))
5815 : 0 : return rte_flow_error_set(error, EINVAL,
5816 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5817 : : "can't have 2 fate actions in"
5818 : : " same flow");
5819 [ # # ]: 0 : if (!action->conf)
5820 : 0 : return rte_flow_error_set(error, EINVAL,
5821 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5822 : : NULL, "action configuration not set");
5823 : 0 : target_group =
5824 : : ((const struct rte_flow_action_jump *)action->conf)->group;
5825 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel, target_group, &table,
5826 : : &grp_info, error);
5827 [ # # ]: 0 : if (ret)
5828 : : return ret;
5829 [ # # ]: 0 : if (table == 0)
5830 : 0 : return rte_flow_error_set(error, EINVAL,
5831 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5832 : : NULL, "root table shouldn't be destination");
5833 : : return 0;
5834 : : }
5835 : :
5836 : : /*
5837 : : * Validate action PORT_ID / REPRESENTED_PORT.
5838 : : *
5839 : : * @param[in] dev
5840 : : * Pointer to rte_eth_dev structure.
5841 : : * @param[in] action_flags
5842 : : * Bit-fields that holds the actions detected until now.
5843 : : * @param[in] action
5844 : : * PORT_ID / REPRESENTED_PORT action structure.
5845 : : * @param[in] attr
5846 : : * Attributes of flow that includes this action.
5847 : : * @param[out] error
5848 : : * Pointer to error structure.
5849 : : *
5850 : : * @return
5851 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5852 : : */
5853 : : static int
5854 : 0 : flow_dv_validate_action_port_id(struct rte_eth_dev *dev,
5855 : : uint64_t action_flags,
5856 : : const struct rte_flow_action *action,
5857 : : const struct rte_flow_attr *attr,
5858 : : struct rte_flow_error *error)
5859 : : {
5860 : : const struct rte_flow_action_port_id *port_id;
5861 : : const struct rte_flow_action_ethdev *ethdev;
5862 : : struct mlx5_priv *act_priv;
5863 : : struct mlx5_priv *dev_priv;
5864 : : uint16_t port;
5865 : :
5866 [ # # ]: 0 : if (!attr->transfer)
5867 : 0 : return rte_flow_error_set(error, ENOTSUP,
5868 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5869 : : NULL,
5870 : : "port action is valid in transfer"
5871 : : " mode only");
5872 [ # # # # ]: 0 : if (!action || !action->conf)
5873 : 0 : return rte_flow_error_set(error, ENOTSUP,
5874 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5875 : : NULL,
5876 : : "port action parameters must be"
5877 : : " specified");
5878 [ # # ]: 0 : if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
5879 : : MLX5_FLOW_FATE_ESWITCH_ACTIONS))
5880 : 0 : return rte_flow_error_set(error, EINVAL,
5881 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5882 : : "can have only one fate actions in"
5883 : : " a flow");
5884 : 0 : dev_priv = mlx5_dev_to_eswitch_info(dev);
5885 [ # # ]: 0 : if (!dev_priv)
5886 : 0 : return rte_flow_error_set(error, rte_errno,
5887 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5888 : : NULL,
5889 : : "failed to obtain E-Switch info");
5890 [ # # # ]: 0 : switch (action->type) {
5891 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
5892 : 0 : port_id = action->conf;
5893 [ # # ]: 0 : port = port_id->original ? dev->data->port_id : port_id->id;
5894 : : break;
5895 : 0 : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
5896 : 0 : ethdev = action->conf;
5897 : 0 : port = ethdev->port_id;
5898 : 0 : break;
5899 : 0 : default:
5900 : : MLX5_ASSERT(false);
5901 : 0 : return rte_flow_error_set
5902 : : (error, EINVAL,
5903 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5904 : : "unknown E-Switch action");
5905 : : }
5906 : 0 : act_priv = mlx5_port_to_eswitch_info(port, false);
5907 [ # # ]: 0 : if (!act_priv)
5908 : 0 : return rte_flow_error_set
5909 : : (error, rte_errno,
5910 : 0 : RTE_FLOW_ERROR_TYPE_ACTION_CONF, action->conf,
5911 : : "failed to obtain E-Switch port id for port");
5912 [ # # ]: 0 : if (act_priv->domain_id != dev_priv->domain_id)
5913 : 0 : return rte_flow_error_set
5914 : : (error, EINVAL,
5915 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5916 : : "port does not belong to"
5917 : : " E-Switch being configured");
5918 : : return 0;
5919 : : }
5920 : :
5921 : : /**
5922 : : * Get the maximum number of modify header actions.
5923 : : *
5924 : : * @param dev
5925 : : * Pointer to rte_eth_dev structure.
5926 : : * @param root
5927 : : * Whether action is on root table.
5928 : : *
5929 : : * @return
5930 : : * Max number of modify header actions device can support.
5931 : : */
5932 : : static inline unsigned int
5933 : : flow_dv_modify_hdr_action_max(struct rte_eth_dev *dev __rte_unused,
5934 : : bool root)
5935 : : {
5936 : : /*
5937 : : * There's no way to directly query the max capacity from FW.
5938 : : * The maximal value on root table should be assumed to be supported.
5939 : : */
5940 [ # # ]: 0 : if (!root)
5941 : : return MLX5_MAX_MODIFY_NUM;
5942 : : else
5943 : 0 : return MLX5_ROOT_TBL_MODIFY_NUM;
5944 : : }
5945 : :
5946 : : /**
5947 : : * Validate the meter action.
5948 : : *
5949 : : * @param[in] dev
5950 : : * Pointer to rte_eth_dev structure.
5951 : : * @param[in] action_flags
5952 : : * Bit-fields that holds the actions detected until now.
5953 : : * @param[in] item_flags
5954 : : * Holds the items detected.
5955 : : * @param[in] action
5956 : : * Pointer to the meter action.
5957 : : * @param[in] attr
5958 : : * Attributes of flow that includes this action.
5959 : : * @param[in] port_id_item
5960 : : * Pointer to item indicating port id.
5961 : : * @param[out] error
5962 : : * Pointer to error structure.
5963 : : *
5964 : : * @return
5965 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5966 : : */
5967 : : static int
5968 : 0 : mlx5_flow_validate_action_meter(struct rte_eth_dev *dev,
5969 : : uint64_t action_flags, uint64_t item_flags,
5970 : : const struct rte_flow_action *action,
5971 : : const struct rte_flow_attr *attr,
5972 : : const struct rte_flow_item *port_id_item,
5973 : : bool *def_policy,
5974 : : struct rte_flow_error *error)
5975 : : {
5976 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5977 : 0 : const struct rte_flow_action_meter *am = action->conf;
5978 : : struct mlx5_flow_meter_info *fm;
5979 : : struct mlx5_flow_meter_policy *mtr_policy;
5980 : 0 : struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
5981 : 0 : uint16_t flow_src_port = priv->representor_id;
5982 : 0 : bool all_ports = false;
5983 : :
5984 [ # # ]: 0 : if (!am)
5985 : 0 : return rte_flow_error_set(error, EINVAL,
5986 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5987 : : "meter action conf is NULL");
5988 : :
5989 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_METER)
5990 : 0 : return rte_flow_error_set(error, ENOTSUP,
5991 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5992 : : "meter chaining not support");
5993 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_JUMP)
5994 : 0 : return rte_flow_error_set(error, ENOTSUP,
5995 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5996 : : "meter with jump not support");
5997 [ # # ]: 0 : if (!priv->mtr_en)
5998 : 0 : return rte_flow_error_set(error, ENOTSUP,
5999 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6000 : : NULL,
6001 : : "meter action not supported");
6002 : 0 : fm = mlx5_flow_meter_find(priv, am->mtr_id, NULL);
6003 [ # # ]: 0 : if (!fm)
6004 : 0 : return rte_flow_error_set(error, EINVAL,
6005 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6006 : : "Meter not found");
6007 : : /* aso meter can always be shared by different domains */
6008 [ # # # # ]: 0 : if (fm->ref_cnt && !priv->sh->meter_aso_en &&
6009 [ # # ]: 0 : !(fm->transfer == attr->transfer ||
6010 [ # # # # ]: 0 : (!fm->ingress && !attr->ingress && attr->egress) ||
6011 [ # # # # ]: 0 : (!fm->egress && !attr->egress && attr->ingress)))
6012 : 0 : return rte_flow_error_set(error, EINVAL,
6013 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6014 : : "Flow attributes domain are either invalid "
6015 : : "or have a domain conflict with current "
6016 : : "meter attributes");
6017 [ # # ]: 0 : if (fm->def_policy) {
6018 [ # # ]: 0 : if (!((attr->transfer &&
6019 [ # # ]: 0 : mtrmng->def_policy[MLX5_MTR_DOMAIN_TRANSFER]) ||
6020 [ # # ]: 0 : (attr->egress &&
6021 [ # # ]: 0 : mtrmng->def_policy[MLX5_MTR_DOMAIN_EGRESS]) ||
6022 [ # # ]: 0 : (attr->ingress &&
6023 [ # # ]: 0 : mtrmng->def_policy[MLX5_MTR_DOMAIN_INGRESS])))
6024 : 0 : return rte_flow_error_set(error, EINVAL,
6025 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6026 : : "Flow attributes domain "
6027 : : "have a conflict with current "
6028 : : "meter domain attributes");
6029 : 0 : *def_policy = true;
6030 : : } else {
6031 : 0 : mtr_policy = mlx5_flow_meter_policy_find(dev,
6032 : : fm->policy_id, NULL);
6033 [ # # ]: 0 : if (!mtr_policy)
6034 : 0 : return rte_flow_error_set(error, EINVAL,
6035 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6036 : : "Invalid policy id for meter ");
6037 [ # # # # ]: 0 : if (!((attr->transfer && mtr_policy->transfer) ||
6038 [ # # # # ]: 0 : (attr->egress && mtr_policy->egress) ||
6039 [ # # # # ]: 0 : (attr->ingress && mtr_policy->ingress)))
6040 : 0 : return rte_flow_error_set(error, EINVAL,
6041 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6042 : : "Flow attributes domain "
6043 : : "have a conflict with current "
6044 : : "meter domain attributes");
6045 [ # # ]: 0 : if (port_id_item) {
6046 [ # # ]: 0 : if (mlx5_flow_get_item_vport_id(dev, port_id_item, &flow_src_port,
6047 : : &all_ports, error))
6048 : 0 : return -rte_errno;
6049 : : }
6050 [ # # ]: 0 : if (attr->transfer) {
6051 : : /* When flow matching all src ports, meter should not have drop count. */
6052 [ # # # # : 0 : if (all_ports && (fm->drop_cnt || mtr_policy->hierarchy_match_port))
# # ]
6053 : 0 : return rte_flow_error_set(error, EINVAL,
6054 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
6055 : : "Meter drop count or "
6056 : : "modify_field/set_tag in meter hierarchy "
6057 : : "not supported when matching all ports.");
6058 [ # # ]: 0 : } else if (mtr_policy->is_rss) {
6059 : : struct mlx5_flow_meter_policy *fp;
6060 : : struct mlx5_meter_policy_action_container *acg;
6061 : : struct mlx5_meter_policy_action_container *acy;
6062 : : const struct rte_flow_action *rss_act;
6063 : : int ret;
6064 : :
6065 : 0 : fp = mlx5_flow_meter_hierarchy_get_final_policy(dev,
6066 : : mtr_policy);
6067 [ # # ]: 0 : if (fp == NULL)
6068 : 0 : return rte_flow_error_set(error, EINVAL,
6069 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6070 : : "Unable to get the final "
6071 : : "policy in the hierarchy");
6072 : : acg = &fp->act_cnt[RTE_COLOR_GREEN];
6073 : : acy = &fp->act_cnt[RTE_COLOR_YELLOW];
6074 : : MLX5_ASSERT(acg->fate_action ==
6075 : : MLX5_FLOW_FATE_SHARED_RSS ||
6076 : : acy->fate_action ==
6077 : : MLX5_FLOW_FATE_SHARED_RSS);
6078 [ # # ]: 0 : if (acg->fate_action == MLX5_FLOW_FATE_SHARED_RSS)
6079 : 0 : rss_act = acg->rss;
6080 : : else
6081 : 0 : rss_act = acy->rss;
6082 : 0 : ret = mlx5_flow_validate_action_rss(rss_act,
6083 : : action_flags, dev, attr,
6084 : : item_flags, error);
6085 [ # # ]: 0 : if (ret)
6086 : : return ret;
6087 : : }
6088 : 0 : *def_policy = false;
6089 : : }
6090 : : return 0;
6091 : : }
6092 : :
6093 : : /**
6094 : : * Validate the age action.
6095 : : *
6096 : : * @param[in] action_flags
6097 : : * Holds the actions detected until now.
6098 : : * @param[in] action
6099 : : * Pointer to the age action.
6100 : : * @param[in] dev
6101 : : * Pointer to the Ethernet device structure.
6102 : : * @param[out] error
6103 : : * Pointer to error structure.
6104 : : *
6105 : : * @return
6106 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
6107 : : */
6108 : : static int
6109 : 0 : flow_dv_validate_action_age(uint64_t action_flags,
6110 : : const struct rte_flow_action *action,
6111 : : struct rte_eth_dev *dev,
6112 : : struct rte_flow_error *error)
6113 : : {
6114 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6115 : 0 : const struct rte_flow_action_age *age = action->conf;
6116 : :
6117 [ # # ]: 0 : if (!priv->sh->cdev->config.devx ||
6118 [ # # # # ]: 0 : (priv->sh->sws_cmng.counter_fallback && !priv->sh->aso_age_mng))
6119 : 0 : return rte_flow_error_set(error, ENOTSUP,
6120 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6121 : : NULL,
6122 : : "age action not supported");
6123 [ # # ]: 0 : if (!(action->conf))
6124 : 0 : return rte_flow_error_set(error, EINVAL,
6125 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6126 : : "configuration cannot be null");
6127 [ # # ]: 0 : if (!(age->timeout))
6128 : 0 : return rte_flow_error_set(error, EINVAL,
6129 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6130 : : "invalid timeout value 0");
6131 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_AGE)
6132 : 0 : return rte_flow_error_set(error, EINVAL,
6133 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6134 : : "duplicate age actions set");
6135 : : return 0;
6136 : : }
6137 : :
6138 : : /**
6139 : : * Validate the modify-header IPv4 DSCP actions.
6140 : : *
6141 : : * @param[in] action_flags
6142 : : * Holds the actions detected until now.
6143 : : * @param[in] action
6144 : : * Pointer to the modify action.
6145 : : * @param[in] item_flags
6146 : : * Holds the items detected.
6147 : : * @param[out] error
6148 : : * Pointer to error structure.
6149 : : *
6150 : : * @return
6151 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
6152 : : */
6153 : : static int
6154 : 0 : flow_dv_validate_action_modify_ipv4_dscp(const uint64_t action_flags,
6155 : : const struct rte_flow_action *action,
6156 : : const uint64_t item_flags,
6157 : : struct rte_flow_error *error)
6158 : : {
6159 : : int ret = 0;
6160 : :
6161 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
6162 [ # # ]: 0 : if (!ret) {
6163 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV4))
6164 : 0 : return rte_flow_error_set(error, EINVAL,
6165 : : RTE_FLOW_ERROR_TYPE_ACTION,
6166 : : NULL,
6167 : : "no ipv4 item in pattern");
6168 : : }
6169 : : return ret;
6170 : : }
6171 : :
6172 : : /**
6173 : : * Validate the modify-header IPv6 DSCP actions.
6174 : : *
6175 : : * @param[in] action_flags
6176 : : * Holds the actions detected until now.
6177 : : * @param[in] action
6178 : : * Pointer to the modify action.
6179 : : * @param[in] item_flags
6180 : : * Holds the items detected.
6181 : : * @param[out] error
6182 : : * Pointer to error structure.
6183 : : *
6184 : : * @return
6185 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
6186 : : */
6187 : : static int
6188 : 0 : flow_dv_validate_action_modify_ipv6_dscp(const uint64_t action_flags,
6189 : : const struct rte_flow_action *action,
6190 : : const uint64_t item_flags,
6191 : : struct rte_flow_error *error)
6192 : : {
6193 : : int ret = 0;
6194 : :
6195 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
6196 [ # # ]: 0 : if (!ret) {
6197 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV6))
6198 : 0 : return rte_flow_error_set(error, EINVAL,
6199 : : RTE_FLOW_ERROR_TYPE_ACTION,
6200 : : NULL,
6201 : : "no ipv6 item in pattern");
6202 : : }
6203 : : return ret;
6204 : : }
6205 : :
6206 : : int
6207 : 0 : mlx5_flow_modify_match_cb(void *tool_ctx __rte_unused,
6208 : : struct mlx5_list_entry *entry, void *cb_ctx)
6209 : : {
6210 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
6211 : 0 : struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
6212 : : struct mlx5_flow_dv_modify_hdr_resource *resource =
6213 : : container_of(entry, typeof(*resource), entry);
6214 : : uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type);
6215 : :
6216 : 0 : key_len += ref->actions_num * sizeof(ref->actions[0]);
6217 [ # # ]: 0 : return ref->actions_num != resource->actions_num ||
6218 [ # # ]: 0 : memcmp(&ref->ft_type, &resource->ft_type, key_len);
6219 : : }
6220 : :
6221 : : static struct mlx5_indexed_pool *
6222 : 0 : flow_dv_modify_ipool_get(struct mlx5_dev_ctx_shared *sh, uint8_t index)
6223 : : {
6224 : 0 : struct mlx5_indexed_pool *ipool = rte_atomic_load_explicit
6225 : : (&sh->mdh_ipools[index], rte_memory_order_seq_cst);
6226 : :
6227 [ # # ]: 0 : if (!ipool) {
6228 : : struct mlx5_indexed_pool *expected = NULL;
6229 : 0 : struct mlx5_indexed_pool_config cfg =
6230 : : (struct mlx5_indexed_pool_config) {
6231 : 0 : .size = sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
6232 : 0 : (index + 1) *
6233 : : sizeof(struct mlx5_modification_cmd),
6234 : : .trunk_size = 64,
6235 : : .grow_trunk = 3,
6236 : : .grow_shift = 2,
6237 : : .need_lock = 1,
6238 : 0 : .release_mem_en = !!sh->config.reclaim_mode,
6239 : : .per_core_cache =
6240 [ # # ]: 0 : sh->config.reclaim_mode ? 0 : (1 << 16),
6241 : : .malloc = mlx5_malloc,
6242 : : .free = mlx5_free,
6243 : : .type = "mlx5_modify_action_resource",
6244 : : };
6245 : :
6246 : 0 : cfg.size = RTE_ALIGN(cfg.size, sizeof(ipool));
6247 : 0 : ipool = mlx5_ipool_create(&cfg);
6248 [ # # ]: 0 : if (!ipool)
6249 : 0 : return NULL;
6250 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(&sh->mdh_ipools[index],
6251 : : &expected, ipool,
6252 : : rte_memory_order_seq_cst,
6253 : : rte_memory_order_seq_cst)) {
6254 : 0 : mlx5_ipool_destroy(ipool);
6255 : 0 : ipool = rte_atomic_load_explicit(&sh->mdh_ipools[index],
6256 : : rte_memory_order_seq_cst);
6257 : : }
6258 : : }
6259 : : return ipool;
6260 : : }
6261 : :
6262 : : struct mlx5_list_entry *
6263 : 0 : mlx5_flow_modify_create_cb(void *tool_ctx, void *cb_ctx)
6264 : : {
6265 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
6266 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
6267 : : struct mlx5dv_dr_domain *ns;
6268 : : struct mlx5_flow_dv_modify_hdr_resource *entry;
6269 : 0 : struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
6270 : 0 : struct mlx5_indexed_pool *ipool = flow_dv_modify_ipool_get(sh,
6271 : 0 : ref->actions_num - 1);
6272 : : int ret = 0;
6273 : 0 : uint32_t data_len = ref->actions_num * sizeof(ref->actions[0]);
6274 : : uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type);
6275 : : uint32_t idx;
6276 : :
6277 [ # # ]: 0 : if (unlikely(!ipool)) {
6278 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
6279 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6280 : : NULL, "cannot allocate modify ipool");
6281 : 0 : return NULL;
6282 : : }
6283 : 0 : entry = mlx5_ipool_zmalloc(ipool, &idx);
6284 [ # # ]: 0 : if (!entry) {
6285 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
6286 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6287 : : "cannot allocate resource memory");
6288 : 0 : return NULL;
6289 : : }
6290 : 0 : rte_memcpy(&entry->ft_type,
6291 : 0 : RTE_PTR_ADD(ref, offsetof(typeof(*ref), ft_type)),
6292 [ # # ]: 0 : key_len + data_len);
6293 [ # # ]: 0 : if (sh->config.dv_flow_en == 2) {
6294 : : #ifdef HAVE_MLX5_HWS_SUPPORT
6295 : 0 : struct mlx5dr_action_mh_pattern pattern = {
6296 : : .sz = data_len,
6297 : 0 : .data = (rte_be64_t *)ref->actions
6298 : : };
6299 : 0 : entry->action = mlx5dr_action_create_modify_header(ctx->data2,
6300 : : 1,
6301 : 0 : &pattern, 0, ref->flags);
6302 [ # # ]: 0 : if (!entry->action)
6303 : : ret = -1;
6304 : : #else
6305 : : ret = -1;
6306 : : #endif
6307 : : } else {
6308 [ # # ]: 0 : if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
6309 : 0 : ns = sh->fdb_domain;
6310 [ # # ]: 0 : else if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
6311 : 0 : ns = sh->tx_domain;
6312 : : else
6313 : 0 : ns = sh->rx_domain;
6314 : 0 : ret = mlx5_flow_os_create_flow_action_modify_header
6315 : 0 : (sh->cdev->ctx, ns, entry,
6316 : : data_len, &entry->action);
6317 : : }
6318 : : if (ret) {
6319 : 0 : mlx5_ipool_free(sh->mdh_ipools[ref->actions_num - 1], idx);
6320 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
6321 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6322 : : NULL, "cannot create modification action");
6323 : 0 : return NULL;
6324 : : }
6325 : 0 : entry->idx = idx;
6326 : 0 : return &entry->entry;
6327 : : }
6328 : :
6329 : : struct mlx5_list_entry *
6330 : 0 : mlx5_flow_modify_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
6331 : : void *cb_ctx)
6332 : : {
6333 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
6334 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
6335 : : struct mlx5_flow_dv_modify_hdr_resource *entry;
6336 : 0 : struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
6337 : 0 : uint32_t data_len = ref->actions_num * sizeof(ref->actions[0]);
6338 : : uint32_t idx;
6339 : :
6340 : 0 : entry = mlx5_ipool_malloc(sh->mdh_ipools[ref->actions_num - 1],
6341 : : &idx);
6342 [ # # ]: 0 : if (!entry) {
6343 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
6344 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6345 : : "cannot allocate resource memory");
6346 : 0 : return NULL;
6347 : : }
6348 : 0 : memcpy(entry, oentry, sizeof(*entry) + data_len);
6349 : 0 : entry->idx = idx;
6350 : 0 : return &entry->entry;
6351 : : }
6352 : :
6353 : : void
6354 : 0 : mlx5_flow_modify_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
6355 : : {
6356 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
6357 : : struct mlx5_flow_dv_modify_hdr_resource *res =
6358 : : container_of(entry, typeof(*res), entry);
6359 : :
6360 : 0 : mlx5_ipool_free(sh->mdh_ipools[res->actions_num - 1], res->idx);
6361 : 0 : }
6362 : :
6363 : : /**
6364 : : * Validate the sample action.
6365 : : *
6366 : : * @param[in, out] action_flags
6367 : : * Holds the actions detected until now.
6368 : : * @param[in] action
6369 : : * Pointer to the sample action.
6370 : : * @param[in] dev
6371 : : * Pointer to the Ethernet device structure.
6372 : : * @param[in] attr
6373 : : * Attributes of flow that includes this action.
6374 : : * @param[in] item_flags
6375 : : * Holds the items detected.
6376 : : * @param[in] rss
6377 : : * Pointer to the RSS action.
6378 : : * @param[out] sample_rss
6379 : : * Pointer to the RSS action in sample action list.
6380 : : * @param[out] count
6381 : : * Pointer to the COUNT action in sample action list.
6382 : : * @param[out] fdb_mirror
6383 : : * Pointer to the FDB mirror flag.
6384 : : * @param root
6385 : : * Whether action is on root table.
6386 : : * @param[out] error
6387 : : * Pointer to error structure.
6388 : : *
6389 : : * @return
6390 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
6391 : : */
6392 : : static int
6393 : 0 : flow_dv_validate_action_sample(uint64_t *action_flags,
6394 : : uint64_t *sub_action_flags,
6395 : : const struct rte_flow_action *action,
6396 : : struct rte_eth_dev *dev,
6397 : : const struct rte_flow_attr *attr,
6398 : : uint64_t item_flags,
6399 : : const struct rte_flow_action_rss *rss,
6400 : : const struct rte_flow_action_rss **sample_rss,
6401 : : const struct rte_flow_action_count **count,
6402 : : int *fdb_mirror,
6403 : : uint16_t *sample_port_id,
6404 : : bool root,
6405 : : struct rte_flow_error *error)
6406 : : {
6407 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6408 : 0 : struct mlx5_sh_config *dev_conf = &priv->sh->config;
6409 : 0 : const struct rte_flow_action_sample *sample = action->conf;
6410 : : const struct rte_flow_action_port_id *port = NULL;
6411 : : const struct rte_flow_action *act;
6412 : : uint16_t queue_index = 0xFFFF;
6413 : 0 : int actions_n = 0;
6414 : : int ret;
6415 : :
6416 [ # # ]: 0 : if (!sample)
6417 : 0 : return rte_flow_error_set(error, EINVAL,
6418 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6419 : : "configuration cannot be NULL");
6420 [ # # ]: 0 : if (sample->ratio == 0)
6421 : 0 : return rte_flow_error_set(error, EINVAL,
6422 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6423 : : "ratio value starts from 1");
6424 [ # # ]: 0 : if (!priv->sh->cdev->config.devx ||
6425 [ # # ]: 0 : (sample->ratio > 0 && !priv->sampler_en))
6426 : 0 : return rte_flow_error_set(error, ENOTSUP,
6427 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6428 : : NULL,
6429 : : "sample action not supported");
6430 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_SAMPLE)
6431 : 0 : return rte_flow_error_set(error, EINVAL,
6432 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6433 : : "Multiple sample actions not "
6434 : : "supported");
6435 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_METER)
6436 : 0 : return rte_flow_error_set(error, EINVAL,
6437 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6438 : : "wrong action order, meter should "
6439 : : "be after sample action");
6440 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_JUMP)
6441 : 0 : return rte_flow_error_set(error, EINVAL,
6442 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6443 : : "wrong action order, jump should "
6444 : : "be after sample action");
6445 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_CT)
6446 : 0 : return rte_flow_error_set(error, EINVAL,
6447 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6448 : : "Sample after CT not supported");
6449 : 0 : act = sample->actions;
6450 [ # # ]: 0 : for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++) {
6451 [ # # ]: 0 : if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
6452 : 0 : return rte_flow_error_set(error, ENOTSUP,
6453 : : RTE_FLOW_ERROR_TYPE_ACTION,
6454 : : act, "too many actions");
6455 [ # # # # : 0 : switch (act->type) {
# # # # ]
6456 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
6457 : 0 : ret = mlx5_flow_validate_action_queue(act,
6458 : : *sub_action_flags,
6459 : : dev,
6460 : : attr, error);
6461 [ # # ]: 0 : if (ret < 0)
6462 : 0 : return ret;
6463 : 0 : queue_index = ((const struct rte_flow_action_queue *)
6464 : 0 : (act->conf))->index;
6465 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_QUEUE;
6466 : 0 : ++actions_n;
6467 : 0 : break;
6468 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
6469 : 0 : *sample_rss = act->conf;
6470 : 0 : ret = mlx5_flow_validate_action_rss(act,
6471 : : *sub_action_flags,
6472 : : dev, attr,
6473 : : item_flags,
6474 : : error);
6475 [ # # ]: 0 : if (ret < 0)
6476 : 0 : return ret;
6477 [ # # # # ]: 0 : if (rss && *sample_rss &&
6478 [ # # ]: 0 : ((*sample_rss)->level != rss->level ||
6479 [ # # ]: 0 : (*sample_rss)->types != rss->types))
6480 : 0 : return rte_flow_error_set(error, ENOTSUP,
6481 : : RTE_FLOW_ERROR_TYPE_ACTION,
6482 : : NULL,
6483 : : "Can't use the different RSS types "
6484 : : "or level in the same flow");
6485 [ # # # # ]: 0 : if (*sample_rss != NULL && (*sample_rss)->queue_num)
6486 : 0 : queue_index = (*sample_rss)->queue[0];
6487 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_RSS;
6488 : 0 : ++actions_n;
6489 : 0 : break;
6490 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
6491 : 0 : ret = flow_dv_validate_action_mark(dev, act,
6492 : : *sub_action_flags,
6493 : : attr, error);
6494 [ # # ]: 0 : if (ret < 0)
6495 : 0 : return ret;
6496 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY)
6497 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_MARK |
6498 : : MLX5_FLOW_ACTION_MARK_EXT;
6499 : : else
6500 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_MARK;
6501 : 0 : ++actions_n;
6502 : 0 : break;
6503 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
6504 : 0 : ret = flow_dv_validate_action_count
6505 : 0 : (dev, false, *action_flags | *sub_action_flags,
6506 : : root, error);
6507 [ # # ]: 0 : if (ret < 0)
6508 : 0 : return ret;
6509 : 0 : *count = act->conf;
6510 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_COUNT;
6511 : 0 : *action_flags |= MLX5_FLOW_ACTION_COUNT;
6512 : 0 : ++actions_n;
6513 : 0 : break;
6514 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
6515 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
6516 : 0 : ret = flow_dv_validate_action_port_id(dev,
6517 : : *sub_action_flags,
6518 : : act,
6519 : : attr,
6520 : : error);
6521 [ # # ]: 0 : if (ret)
6522 : 0 : return ret;
6523 [ # # ]: 0 : if (act->type == RTE_FLOW_ACTION_TYPE_PORT_ID) {
6524 : 0 : port = (const struct rte_flow_action_port_id *)
6525 : : act->conf;
6526 [ # # ]: 0 : *sample_port_id = port->original ?
6527 : 0 : dev->data->port_id : port->id;
6528 : : } else {
6529 : 0 : *sample_port_id = ((const struct rte_flow_action_ethdev *)
6530 : 0 : act->conf)->port_id;
6531 : : }
6532 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_PORT_ID;
6533 : 0 : ++actions_n;
6534 : 0 : break;
6535 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
6536 : 0 : ret = mlx5_flow_dv_validate_action_raw_encap_decap
6537 : 0 : (dev, NULL, act->conf, attr, sub_action_flags,
6538 : : &actions_n, action, item_flags, error);
6539 [ # # ]: 0 : if (ret < 0)
6540 : 0 : return ret;
6541 : 0 : ++actions_n;
6542 : 0 : break;
6543 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
6544 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
6545 : 0 : ret = mlx5_flow_dv_validate_action_l2_encap(dev,
6546 : : *sub_action_flags,
6547 : : act, attr,
6548 : : error);
6549 [ # # ]: 0 : if (ret < 0)
6550 : 0 : return ret;
6551 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_ENCAP;
6552 : 0 : ++actions_n;
6553 : 0 : break;
6554 : 0 : default:
6555 : 0 : return rte_flow_error_set(error, ENOTSUP,
6556 : : RTE_FLOW_ERROR_TYPE_ACTION,
6557 : : NULL,
6558 : : "Doesn't support optional "
6559 : : "action");
6560 : : }
6561 : : }
6562 [ # # ]: 0 : if (attr->ingress) {
6563 [ # # ]: 0 : if (!(*sub_action_flags & (MLX5_FLOW_ACTION_QUEUE |
6564 : : MLX5_FLOW_ACTION_RSS)))
6565 : 0 : return rte_flow_error_set(error, EINVAL,
6566 : : RTE_FLOW_ERROR_TYPE_ACTION,
6567 : : NULL,
6568 : : "Ingress must has a dest "
6569 : : "QUEUE for Sample");
6570 [ # # ]: 0 : } else if (attr->egress) {
6571 : 0 : return rte_flow_error_set(error, ENOTSUP,
6572 : : RTE_FLOW_ERROR_TYPE_ACTION,
6573 : : NULL,
6574 : : "Sample Only support Ingress "
6575 : : "or E-Switch");
6576 [ # # ]: 0 : } else if (sample->actions->type != RTE_FLOW_ACTION_TYPE_END) {
6577 : : MLX5_ASSERT(attr->transfer);
6578 [ # # ]: 0 : if (sample->ratio > 1)
6579 : 0 : return rte_flow_error_set(error, ENOTSUP,
6580 : : RTE_FLOW_ERROR_TYPE_ACTION,
6581 : : NULL,
6582 : : "E-Switch doesn't support "
6583 : : "any optional action "
6584 : : "for sampling");
6585 [ # # ]: 0 : if (*sub_action_flags & MLX5_FLOW_ACTION_QUEUE)
6586 : 0 : return rte_flow_error_set(error, ENOTSUP,
6587 : : RTE_FLOW_ERROR_TYPE_ACTION,
6588 : : NULL,
6589 : : "unsupported action QUEUE");
6590 [ # # ]: 0 : if (*sub_action_flags & MLX5_FLOW_ACTION_RSS)
6591 : 0 : return rte_flow_error_set(error, ENOTSUP,
6592 : : RTE_FLOW_ERROR_TYPE_ACTION,
6593 : : NULL,
6594 : : "unsupported action QUEUE");
6595 [ # # ]: 0 : if (!(*sub_action_flags & MLX5_FLOW_ACTION_PORT_ID))
6596 : 0 : return rte_flow_error_set(error, EINVAL,
6597 : : RTE_FLOW_ERROR_TYPE_ACTION,
6598 : : NULL,
6599 : : "E-Switch must has a dest "
6600 : : "port for mirroring");
6601 : 0 : *fdb_mirror = 1;
6602 : : }
6603 : : /* Continue validation for Xcap actions.*/
6604 [ # # # # ]: 0 : if ((*sub_action_flags & MLX5_FLOW_XCAP_ACTIONS) &&
6605 [ # # ]: 0 : (queue_index == 0xFFFF || !mlx5_rxq_is_hairpin(dev, queue_index))) {
6606 [ # # ]: 0 : if ((*sub_action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
6607 : : MLX5_FLOW_XCAP_ACTIONS)
6608 : 0 : return rte_flow_error_set(error, ENOTSUP,
6609 : : RTE_FLOW_ERROR_TYPE_ACTION,
6610 : : NULL, "encap and decap "
6611 : : "combination aren't "
6612 : : "supported");
6613 [ # # # # ]: 0 : if (attr->ingress && (*sub_action_flags & MLX5_FLOW_ACTION_ENCAP))
6614 : 0 : return rte_flow_error_set(error, ENOTSUP,
6615 : : RTE_FLOW_ERROR_TYPE_ACTION,
6616 : : NULL, "encap is not supported"
6617 : : " for ingress traffic");
6618 : : }
6619 : : return 0;
6620 : : }
6621 : :
6622 : : int
6623 : 0 : mlx5_flow_modify_hdr_resource_register(struct rte_eth_dev *dev,
6624 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
6625 : : struct mlx5_flow_dv_modify_hdr_resource **modify,
6626 : : struct rte_flow_error *error)
6627 : : {
6628 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6629 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
6630 : 0 : uint32_t key_len = sizeof(*resource) -
6631 : : offsetof(typeof(*resource), ft_type) +
6632 : 0 : resource->actions_num * sizeof(resource->actions[0]);
6633 : : struct mlx5_list_entry *entry;
6634 : 0 : struct mlx5_flow_cb_ctx ctx = {
6635 : : .error = error,
6636 : : .data = resource,
6637 : 0 : .data2 = priv->dr_ctx,
6638 : : };
6639 : : struct mlx5_hlist *modify_cmds;
6640 : : uint64_t key64;
6641 : :
6642 : 0 : modify_cmds = flow_dv_hlist_prepare(sh, &sh->modify_cmds,
6643 : : "hdr_modify",
6644 : : MLX5_FLOW_HDR_MODIFY_HTABLE_SZ,
6645 : : true, false, sh,
6646 : : mlx5_flow_modify_create_cb,
6647 : : mlx5_flow_modify_match_cb,
6648 : : mlx5_flow_modify_remove_cb,
6649 : : mlx5_flow_modify_clone_cb,
6650 : : mlx5_flow_modify_clone_free_cb,
6651 : : error);
6652 [ # # ]: 0 : if (unlikely(!modify_cmds))
6653 : 0 : return -rte_errno;
6654 [ # # ]: 0 : if (resource->actions_num > flow_dv_modify_hdr_action_max(dev,
6655 [ # # ]: 0 : resource->root))
6656 : 0 : return rte_flow_error_set(error, EOVERFLOW,
6657 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6658 : : "too many modify header items");
6659 : 0 : key64 = __rte_raw_cksum(&resource->ft_type, key_len, 0);
6660 : 0 : entry = mlx5_hlist_register(modify_cmds, key64, &ctx);
6661 [ # # ]: 0 : if (!entry)
6662 : 0 : return -rte_errno;
6663 : 0 : *modify = container_of(entry, typeof(*resource), entry);
6664 : 0 : return 0;
6665 : : }
6666 : :
6667 : : /**
6668 : : * Find existing modify-header resource or create and register a new one.
6669 : : *
6670 : : * @param dev[in, out]
6671 : : * Pointer to rte_eth_dev structure.
6672 : : * @param[in, out] resource
6673 : : * Pointer to modify-header resource.
6674 : : * @param[in, out] dev_flow
6675 : : * Pointer to the dev_flow.
6676 : : * @param[out] error
6677 : : * pointer to error structure.
6678 : : *
6679 : : * @return
6680 : : * 0 on success otherwise -errno and errno is set.
6681 : : */
6682 : : static int
6683 : : flow_dv_modify_hdr_resource_register
6684 : : (struct rte_eth_dev *dev,
6685 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
6686 : : struct mlx5_flow *dev_flow,
6687 : : struct rte_flow_error *error)
6688 : : {
6689 : 0 : resource->root = !dev_flow->dv.group;
6690 : 0 : return mlx5_flow_modify_hdr_resource_register(dev, resource,
6691 : 0 : &dev_flow->handle->dvh.modify_hdr, error);
6692 : : }
6693 : :
6694 : : /**
6695 : : * Get DV flow counter by index.
6696 : : *
6697 : : * @param[in] dev
6698 : : * Pointer to the Ethernet device structure.
6699 : : * @param[in] idx
6700 : : * mlx5 flow counter index in the container.
6701 : : * @param[out] ppool
6702 : : * mlx5 flow counter pool in the container.
6703 : : *
6704 : : * @return
6705 : : * Pointer to the counter, NULL otherwise.
6706 : : */
6707 : : static struct mlx5_flow_counter *
6708 : : flow_dv_counter_get_by_idx(struct rte_eth_dev *dev,
6709 : : uint32_t idx,
6710 : : struct mlx5_flow_counter_pool **ppool)
6711 : : {
6712 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6713 : 0 : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
6714 : : struct mlx5_flow_counter_pool *pool;
6715 : :
6716 : : /* Decrease to original index and clear shared bit. */
6717 : 0 : idx = (idx - 1) & (MLX5_CNT_SHARED_OFFSET - 1);
6718 : : MLX5_ASSERT(idx / MLX5_COUNTERS_PER_POOL < MLX5_COUNTER_POOLS_MAX_NUM);
6719 : 0 : pool = cmng->pools[idx / MLX5_COUNTERS_PER_POOL];
6720 : : MLX5_ASSERT(pool);
6721 : : if (ppool)
6722 : : *ppool = pool;
6723 [ # # # # : 0 : return MLX5_POOL_GET_CNT(pool, idx % MLX5_COUNTERS_PER_POOL);
# # # # #
# # # ]
6724 : : }
6725 : :
6726 : : /**
6727 : : * Check the devx counter belongs to the pool.
6728 : : *
6729 : : * @param[in] pool
6730 : : * Pointer to the counter pool.
6731 : : * @param[in] id
6732 : : * The counter devx ID.
6733 : : *
6734 : : * @return
6735 : : * True if counter belongs to the pool, false otherwise.
6736 : : */
6737 : : static bool
6738 : : flow_dv_is_counter_in_pool(struct mlx5_flow_counter_pool *pool, int id)
6739 : : {
6740 : 0 : int base = (pool->min_dcs->id / MLX5_COUNTERS_PER_POOL) *
6741 : : MLX5_COUNTERS_PER_POOL;
6742 : :
6743 [ # # # # ]: 0 : if (id >= base && id < base + MLX5_COUNTERS_PER_POOL)
6744 : : return true;
6745 : : return false;
6746 : : }
6747 : :
6748 : : /**
6749 : : * Get a pool by devx counter ID.
6750 : : *
6751 : : * @param[in] cmng
6752 : : * Pointer to the counter management.
6753 : : * @param[in] id
6754 : : * The counter devx ID.
6755 : : *
6756 : : * @return
6757 : : * The counter pool pointer if exists, NULL otherwise,
6758 : : */
6759 : : static struct mlx5_flow_counter_pool *
6760 : 0 : flow_dv_find_pool_by_id(struct mlx5_flow_counter_mng *cmng, int id)
6761 : : {
6762 : : uint32_t i;
6763 : : struct mlx5_flow_counter_pool *pool = NULL;
6764 : :
6765 : 0 : rte_spinlock_lock(&cmng->pool_update_sl);
6766 : : /* Check last used pool. */
6767 [ # # ]: 0 : if (cmng->last_pool_idx != POOL_IDX_INVALID &&
6768 [ # # ]: 0 : flow_dv_is_counter_in_pool(cmng->pools[cmng->last_pool_idx], id)) {
6769 : : pool = cmng->pools[cmng->last_pool_idx];
6770 : 0 : goto out;
6771 : : }
6772 : : /* ID out of range means no suitable pool in the container. */
6773 [ # # # # ]: 0 : if (id > cmng->max_id || id < cmng->min_id)
6774 : 0 : goto out;
6775 : : /*
6776 : : * Find the pool from the end of the container, since mostly counter
6777 : : * ID is sequence increasing, and the last pool should be the needed
6778 : : * one.
6779 : : */
6780 : 0 : i = cmng->n_valid;
6781 [ # # ]: 0 : while (i--) {
6782 [ # # ]: 0 : struct mlx5_flow_counter_pool *pool_tmp = cmng->pools[i];
6783 : :
6784 : : if (flow_dv_is_counter_in_pool(pool_tmp, id)) {
6785 : : pool = pool_tmp;
6786 : : break;
6787 : : }
6788 : : }
6789 : 0 : out:
6790 : : rte_spinlock_unlock(&cmng->pool_update_sl);
6791 : 0 : return pool;
6792 : : }
6793 : :
6794 : : /**
6795 : : * Query a devx flow counter.
6796 : : *
6797 : : * @param[in] dev
6798 : : * Pointer to the Ethernet device structure.
6799 : : * @param[in] counter
6800 : : * Index to the flow counter.
6801 : : * @param[out] pkts
6802 : : * The statistics value of packets.
6803 : : * @param[out] bytes
6804 : : * The statistics value of bytes.
6805 : : *
6806 : : * @return
6807 : : * 0 on success, otherwise a negative errno value and rte_errno is set.
6808 : : */
6809 : : static inline int
6810 : 0 : _flow_dv_query_count(struct rte_eth_dev *dev, uint32_t counter, uint64_t *pkts,
6811 : : uint64_t *bytes)
6812 : : {
6813 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
6814 : : struct mlx5_flow_counter_pool *pool = NULL;
6815 : : struct mlx5_flow_counter *cnt;
6816 : : int offset;
6817 : :
6818 : : cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
6819 : : MLX5_ASSERT(pool);
6820 [ # # ]: 0 : if (priv->sh->sws_cmng.counter_fallback)
6821 : 0 : return mlx5_devx_cmd_flow_counter_query(cnt->dcs_when_active, 0,
6822 : : 0, pkts, bytes, 0, NULL, NULL, 0);
6823 : 0 : rte_spinlock_lock(&pool->sl);
6824 [ # # ]: 0 : if (!pool->raw) {
6825 : 0 : *pkts = 0;
6826 : 0 : *bytes = 0;
6827 : : } else {
6828 [ # # ]: 0 : offset = MLX5_CNT_ARRAY_IDX(pool, cnt);
6829 : 0 : *pkts = rte_be_to_cpu_64(pool->raw->data[offset].hits);
6830 : 0 : *bytes = rte_be_to_cpu_64(pool->raw->data[offset].bytes);
6831 : : }
6832 : : rte_spinlock_unlock(&pool->sl);
6833 : 0 : return 0;
6834 : : }
6835 : :
6836 : : /**
6837 : : * Create and initialize a new counter pool.
6838 : : *
6839 : : * @param[in] dev
6840 : : * Pointer to the Ethernet device structure.
6841 : : * @param[out] dcs
6842 : : * The devX counter handle.
6843 : : * @param[in] age
6844 : : * Whether the pool is for counter that was allocated for aging.
6845 : : *
6846 : : * @return
6847 : : * The pool container pointer on success, NULL otherwise and rte_errno is set.
6848 : : */
6849 : : static struct mlx5_flow_counter_pool *
6850 : 0 : flow_dv_pool_create(struct rte_eth_dev *dev, struct mlx5_devx_obj *dcs,
6851 : : uint32_t age)
6852 : : {
6853 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6854 : : struct mlx5_flow_counter_pool *pool;
6855 : 0 : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
6856 : 0 : bool fallback = cmng->counter_fallback;
6857 : : uint32_t size = sizeof(*pool);
6858 : :
6859 [ # # ]: 0 : if (cmng->n_valid == MLX5_COUNTER_POOLS_MAX_NUM) {
6860 : 0 : DRV_LOG(ERR, "All counter is in used, try again later.");
6861 : 0 : rte_errno = EAGAIN;
6862 : 0 : return NULL;
6863 : : }
6864 : : size += MLX5_COUNTERS_PER_POOL * MLX5_CNT_SIZE;
6865 [ # # ]: 0 : size += (!age ? 0 : MLX5_COUNTERS_PER_POOL * MLX5_AGE_SIZE);
6866 : 0 : pool = mlx5_malloc(MLX5_MEM_ZERO, size, 0, SOCKET_ID_ANY);
6867 [ # # ]: 0 : if (!pool) {
6868 : 0 : rte_errno = ENOMEM;
6869 : 0 : return NULL;
6870 : : }
6871 : 0 : pool->raw = NULL;
6872 : 0 : pool->is_aged = !!age;
6873 : 0 : pool->query_gen = 0;
6874 : 0 : pool->min_dcs = dcs;
6875 : : rte_spinlock_init(&pool->sl);
6876 : : rte_spinlock_init(&pool->csl);
6877 : 0 : TAILQ_INIT(&pool->counters[0]);
6878 : 0 : TAILQ_INIT(&pool->counters[1]);
6879 : 0 : pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
6880 : 0 : rte_spinlock_lock(&cmng->pool_update_sl);
6881 : 0 : pool->index = cmng->n_valid;
6882 : 0 : cmng->pools[pool->index] = pool;
6883 : 0 : cmng->n_valid++;
6884 [ # # ]: 0 : if (unlikely(fallback)) {
6885 : 0 : int base = RTE_ALIGN_FLOOR(dcs->id, MLX5_COUNTERS_PER_POOL);
6886 : :
6887 [ # # ]: 0 : if (base < cmng->min_id)
6888 : 0 : cmng->min_id = base;
6889 [ # # ]: 0 : if (base > cmng->max_id)
6890 : 0 : cmng->max_id = base + MLX5_COUNTERS_PER_POOL - 1;
6891 : 0 : cmng->last_pool_idx = pool->index;
6892 : : }
6893 : : rte_spinlock_unlock(&cmng->pool_update_sl);
6894 : 0 : return pool;
6895 : : }
6896 : :
6897 : : /**
6898 : : * Prepare a new counter and/or a new counter pool.
6899 : : *
6900 : : * @param[in] dev
6901 : : * Pointer to the Ethernet device structure.
6902 : : * @param[out] cnt_free
6903 : : * Where to put the pointer of a new counter.
6904 : : * @param[in] age
6905 : : * Whether the pool is for counter that was allocated for aging.
6906 : : *
6907 : : * @return
6908 : : * The counter pool pointer and @p cnt_free is set on success,
6909 : : * NULL otherwise and rte_errno is set.
6910 : : */
6911 : : static struct mlx5_flow_counter_pool *
6912 : 0 : flow_dv_counter_pool_prepare(struct rte_eth_dev *dev,
6913 : : struct mlx5_flow_counter **cnt_free,
6914 : : uint32_t age)
6915 : : {
6916 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6917 : 0 : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
6918 : : struct mlx5_flow_counter_pool *pool;
6919 : : struct mlx5_counters tmp_tq;
6920 : : struct mlx5_devx_obj *dcs = NULL;
6921 : : struct mlx5_flow_counter *cnt;
6922 : 0 : enum mlx5_counter_type cnt_type =
6923 : 0 : age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
6924 : 0 : bool fallback = priv->sh->sws_cmng.counter_fallback;
6925 : : uint32_t i;
6926 : :
6927 [ # # ]: 0 : if (fallback) {
6928 : : /* bulk_bitmap must be 0 for single counter allocation. */
6929 : 0 : dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0);
6930 [ # # ]: 0 : if (!dcs)
6931 : : return NULL;
6932 : 0 : pool = flow_dv_find_pool_by_id(cmng, dcs->id);
6933 [ # # ]: 0 : if (!pool) {
6934 : 0 : pool = flow_dv_pool_create(dev, dcs, age);
6935 [ # # ]: 0 : if (!pool) {
6936 : 0 : mlx5_devx_cmd_destroy(dcs);
6937 : 0 : return NULL;
6938 : : }
6939 : : }
6940 : 0 : i = dcs->id % MLX5_COUNTERS_PER_POOL;
6941 [ # # ]: 0 : cnt = MLX5_POOL_GET_CNT(pool, i);
6942 : 0 : cnt->pool = pool;
6943 : 0 : cnt->dcs_when_free = dcs;
6944 : 0 : *cnt_free = cnt;
6945 : 0 : return pool;
6946 : : }
6947 : 0 : dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0x4);
6948 [ # # ]: 0 : if (!dcs) {
6949 : 0 : rte_errno = ENODATA;
6950 : 0 : return NULL;
6951 : : }
6952 : 0 : pool = flow_dv_pool_create(dev, dcs, age);
6953 [ # # ]: 0 : if (!pool) {
6954 : 0 : mlx5_devx_cmd_destroy(dcs);
6955 : 0 : return NULL;
6956 : : }
6957 : 0 : TAILQ_INIT(&tmp_tq);
6958 [ # # ]: 0 : for (i = 1; i < MLX5_COUNTERS_PER_POOL; ++i) {
6959 [ # # ]: 0 : cnt = MLX5_POOL_GET_CNT(pool, i);
6960 : 0 : cnt->pool = pool;
6961 [ # # ]: 0 : TAILQ_INSERT_HEAD(&tmp_tq, cnt, next);
6962 : : }
6963 : 0 : rte_spinlock_lock(&cmng->csl[cnt_type]);
6964 [ # # ]: 0 : TAILQ_CONCAT(&cmng->counters[cnt_type], &tmp_tq, next);
6965 : : rte_spinlock_unlock(&cmng->csl[cnt_type]);
6966 : 0 : *cnt_free = MLX5_POOL_GET_CNT(pool, 0);
6967 : 0 : (*cnt_free)->pool = pool;
6968 : 0 : return pool;
6969 : : }
6970 : :
6971 : : /**
6972 : : * Allocate a flow counter.
6973 : : *
6974 : : * @param[in] dev
6975 : : * Pointer to the Ethernet device structure.
6976 : : * @param[in] age
6977 : : * Whether the counter was allocated for aging.
6978 : : *
6979 : : * @return
6980 : : * Index to flow counter on success, 0 otherwise and rte_errno is set.
6981 : : */
6982 : : static uint32_t
6983 : 0 : flow_dv_counter_alloc(struct rte_eth_dev *dev, uint32_t age)
6984 : : {
6985 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6986 : : struct mlx5_flow_counter_pool *pool = NULL;
6987 : 0 : struct mlx5_flow_counter *cnt_free = NULL;
6988 : 0 : bool fallback = priv->sh->sws_cmng.counter_fallback;
6989 : : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
6990 : 0 : enum mlx5_counter_type cnt_type =
6991 : 0 : age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
6992 : : uint32_t cnt_idx;
6993 : :
6994 [ # # ]: 0 : if (!priv->sh->cdev->config.devx) {
6995 : 0 : rte_errno = ENOTSUP;
6996 : 0 : return 0;
6997 : : }
6998 : : /* Get free counters from container. */
6999 : 0 : rte_spinlock_lock(&cmng->csl[cnt_type]);
7000 : 0 : cnt_free = TAILQ_FIRST(&cmng->counters[cnt_type]);
7001 [ # # ]: 0 : if (cnt_free)
7002 [ # # ]: 0 : TAILQ_REMOVE(&cmng->counters[cnt_type], cnt_free, next);
7003 : : rte_spinlock_unlock(&cmng->csl[cnt_type]);
7004 [ # # # # ]: 0 : if (!cnt_free && !flow_dv_counter_pool_prepare(dev, &cnt_free, age))
7005 : 0 : goto err;
7006 : 0 : pool = cnt_free->pool;
7007 [ # # ]: 0 : if (fallback)
7008 : 0 : cnt_free->dcs_when_active = cnt_free->dcs_when_free;
7009 : : /* Create a DV counter action only in the first time usage. */
7010 [ # # ]: 0 : if (!cnt_free->action) {
7011 : : uint16_t offset;
7012 : : struct mlx5_devx_obj *dcs;
7013 : : int ret;
7014 : :
7015 [ # # ]: 0 : if (!fallback) {
7016 [ # # ]: 0 : offset = MLX5_CNT_ARRAY_IDX(pool, cnt_free);
7017 : 0 : dcs = pool->min_dcs;
7018 : : } else {
7019 : : offset = 0;
7020 : 0 : dcs = cnt_free->dcs_when_free;
7021 : : }
7022 : 0 : ret = mlx5_flow_os_create_flow_action_count(dcs->obj, offset,
7023 : : &cnt_free->action);
7024 : : if (ret) {
7025 : 0 : rte_errno = errno;
7026 : 0 : goto err;
7027 : : }
7028 : : }
7029 [ # # ]: 0 : cnt_idx = MLX5_MAKE_CNT_IDX(pool->index,
7030 : : MLX5_CNT_ARRAY_IDX(pool, cnt_free));
7031 : : /* Update the counter reset values. */
7032 [ # # ]: 0 : if (_flow_dv_query_count(dev, cnt_idx, &cnt_free->hits,
7033 : : &cnt_free->bytes))
7034 : 0 : goto err;
7035 [ # # # # ]: 0 : if (!fallback && !priv->sh->sws_cmng.query_thread_on)
7036 : : /* Start the asynchronous batch query by the host thread. */
7037 : 0 : mlx5_set_query_alarm(priv->sh);
7038 : : /*
7039 : : * When the count action isn't shared (by ID), shared_info field is
7040 : : * used for indirect action API's refcnt.
7041 : : * When the counter action is not shared neither by ID nor by indirect
7042 : : * action API, shared info must be 1.
7043 : : */
7044 : 0 : cnt_free->shared_info.refcnt = 1;
7045 : 0 : return cnt_idx;
7046 : 0 : err:
7047 [ # # ]: 0 : if (cnt_free) {
7048 : 0 : cnt_free->pool = pool;
7049 [ # # ]: 0 : if (fallback)
7050 : 0 : cnt_free->dcs_when_free = cnt_free->dcs_when_active;
7051 : : rte_spinlock_lock(&cmng->csl[cnt_type]);
7052 : 0 : TAILQ_INSERT_TAIL(&cmng->counters[cnt_type], cnt_free, next);
7053 : : rte_spinlock_unlock(&cmng->csl[cnt_type]);
7054 : : }
7055 : : return 0;
7056 : : }
7057 : :
7058 : : /**
7059 : : * Get age param from counter index.
7060 : : *
7061 : : * @param[in] dev
7062 : : * Pointer to the Ethernet device structure.
7063 : : * @param[in] counter
7064 : : * Index to the counter handler.
7065 : : *
7066 : : * @return
7067 : : * The aging parameter specified for the counter index.
7068 : : */
7069 : : static struct mlx5_age_param*
7070 : : flow_dv_counter_idx_get_age(struct rte_eth_dev *dev,
7071 : : uint32_t counter)
7072 : : {
7073 : : struct mlx5_flow_counter *cnt;
7074 : : struct mlx5_flow_counter_pool *pool = NULL;
7075 : :
7076 : : flow_dv_counter_get_by_idx(dev, counter, &pool);
7077 : : counter = (counter - 1) % MLX5_COUNTERS_PER_POOL;
7078 : : cnt = MLX5_POOL_GET_CNT(pool, counter);
7079 : 0 : return MLX5_CNT_TO_AGE(cnt);
7080 : : }
7081 : :
7082 : : /**
7083 : : * Remove a flow counter from aged counter list.
7084 : : *
7085 : : * @param[in] dev
7086 : : * Pointer to the Ethernet device structure.
7087 : : * @param[in] counter
7088 : : * Index to the counter handler.
7089 : : * @param[in] cnt
7090 : : * Pointer to the counter handler.
7091 : : */
7092 : : static void
7093 : 0 : flow_dv_counter_remove_from_age(struct rte_eth_dev *dev,
7094 : : uint32_t counter, struct mlx5_flow_counter *cnt)
7095 : : {
7096 : : struct mlx5_age_info *age_info;
7097 : : struct mlx5_age_param *age_param;
7098 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7099 : : uint16_t expected = AGE_CANDIDATE;
7100 : :
7101 [ # # ]: 0 : age_info = GET_PORT_AGE_INFO(priv);
7102 : : age_param = flow_dv_counter_idx_get_age(dev, counter);
7103 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(&age_param->state, &expected,
7104 : : AGE_FREE, rte_memory_order_relaxed,
7105 : : rte_memory_order_relaxed)) {
7106 : : /**
7107 : : * We need the lock even it is age timeout,
7108 : : * since counter may still in process.
7109 : : */
7110 : 0 : rte_spinlock_lock(&age_info->aged_sl);
7111 [ # # ]: 0 : TAILQ_REMOVE(&age_info->aged_counters, cnt, next);
7112 : : rte_spinlock_unlock(&age_info->aged_sl);
7113 : 0 : rte_atomic_store_explicit(&age_param->state, AGE_FREE, rte_memory_order_relaxed);
7114 : : }
7115 : 0 : }
7116 : :
7117 : : /**
7118 : : * Release a flow counter.
7119 : : *
7120 : : * @param[in] dev
7121 : : * Pointer to the Ethernet device structure.
7122 : : * @param[in] counter
7123 : : * Index to the counter handler.
7124 : : */
7125 : : static void
7126 : 0 : flow_dv_counter_free(struct rte_eth_dev *dev, uint32_t counter)
7127 : : {
7128 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7129 : : struct mlx5_flow_counter_pool *pool = NULL;
7130 : : struct mlx5_flow_counter *cnt;
7131 : : enum mlx5_counter_type cnt_type;
7132 : : uint32_t query_gen;
7133 : :
7134 [ # # ]: 0 : if (!counter)
7135 : : return;
7136 : : cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
7137 : : MLX5_ASSERT(pool);
7138 [ # # ]: 0 : if (pool->is_aged) {
7139 : 0 : flow_dv_counter_remove_from_age(dev, counter, cnt);
7140 : : } else {
7141 : : /*
7142 : : * If the counter action is shared by indirect action API,
7143 : : * the atomic function reduces its references counter.
7144 : : * If after the reduction the action is still referenced, the
7145 : : * function returns here and does not release it.
7146 : : * When the counter action is not shared by
7147 : : * indirect action API, shared info is 1 before the reduction,
7148 : : * so this condition is failed and function doesn't return here.
7149 : : */
7150 [ # # ]: 0 : if (rte_atomic_fetch_sub_explicit(&cnt->shared_info.refcnt, 1,
7151 : : rte_memory_order_relaxed) - 1)
7152 : : return;
7153 : : }
7154 : 0 : cnt->pool = pool;
7155 : : /*
7156 : : * Put the counter back to list to be updated in none fallback mode.
7157 : : * Currently, we are using two lists alternately, while one is in query,
7158 : : * add the freed counter to the other list based on the pool query_gen
7159 : : * value. After query finishes, add counter the list to the global
7160 : : * container counter list. Cache query_gen into a local variable before
7161 : : * TAILQ_INSERT_TAIL, since the macro evaluates its head argument
7162 : : * multiple times and pool->query_gen is a volatile bit-field.
7163 : : */
7164 [ # # ]: 0 : if (!priv->sh->sws_cmng.counter_fallback) {
7165 : 0 : rte_spinlock_lock(&pool->csl);
7166 : 0 : query_gen = pool->query_gen;
7167 : 0 : TAILQ_INSERT_TAIL(&pool->counters[query_gen], cnt, next);
7168 : : rte_spinlock_unlock(&pool->csl);
7169 : : } else {
7170 : 0 : cnt->dcs_when_free = cnt->dcs_when_active;
7171 : 0 : cnt_type = pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
7172 : : MLX5_COUNTER_TYPE_ORIGIN;
7173 : 0 : rte_spinlock_lock(&priv->sh->sws_cmng.csl[cnt_type]);
7174 : 0 : TAILQ_INSERT_TAIL(&priv->sh->sws_cmng.counters[cnt_type],
7175 : : cnt, next);
7176 : 0 : rte_spinlock_unlock(&priv->sh->sws_cmng.csl[cnt_type]);
7177 : : }
7178 : : }
7179 : :
7180 : : /**
7181 : : * Resize a meter id container.
7182 : : *
7183 : : * @param[in] dev
7184 : : * Pointer to the Ethernet device structure.
7185 : : *
7186 : : * @return
7187 : : * 0 on success, otherwise negative errno value and rte_errno is set.
7188 : : */
7189 : : static int
7190 : 0 : flow_dv_mtr_container_resize(struct rte_eth_dev *dev)
7191 : : {
7192 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7193 : : struct mlx5_aso_mtr_pools_mng *pools_mng =
7194 : 0 : &priv->sh->mtrmng->pools_mng;
7195 : 0 : void *old_pools = pools_mng->pools;
7196 : 0 : uint32_t resize = pools_mng->n + MLX5_MTRS_CONTAINER_RESIZE;
7197 : 0 : uint32_t mem_size = sizeof(struct mlx5_aso_mtr_pool *) * resize;
7198 : 0 : void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
7199 : :
7200 [ # # ]: 0 : if (!pools) {
7201 : 0 : rte_errno = ENOMEM;
7202 : 0 : return -ENOMEM;
7203 : : }
7204 [ # # ]: 0 : if (!pools_mng->n)
7205 [ # # ]: 0 : if (mlx5_aso_queue_init(priv->sh, ASO_OPC_MOD_POLICER, 1)) {
7206 : 0 : mlx5_free(pools);
7207 : 0 : return -ENOMEM;
7208 : : }
7209 [ # # ]: 0 : if (old_pools)
7210 : 0 : memcpy(pools, old_pools, pools_mng->n *
7211 : : sizeof(struct mlx5_aso_mtr_pool *));
7212 : 0 : pools_mng->n = resize;
7213 : 0 : pools_mng->pools = pools;
7214 [ # # ]: 0 : if (old_pools)
7215 : 0 : mlx5_free(old_pools);
7216 : : return 0;
7217 : : }
7218 : :
7219 : : /**
7220 : : * Prepare a new meter and/or a new meter pool.
7221 : : *
7222 : : * @param[in] dev
7223 : : * Pointer to the Ethernet device structure.
7224 : : * @param[out] mtr_free
7225 : : * Where to put the pointer of a new meter.g.
7226 : : *
7227 : : * @return
7228 : : * The meter pool pointer and @mtr_free is set on success,
7229 : : * NULL otherwise and rte_errno is set.
7230 : : */
7231 : : static struct mlx5_aso_mtr_pool *
7232 : 0 : flow_dv_mtr_pool_create(struct rte_eth_dev *dev, struct mlx5_aso_mtr **mtr_free)
7233 : : {
7234 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7235 : 0 : struct mlx5_aso_mtr_pools_mng *pools_mng = &priv->sh->mtrmng->pools_mng;
7236 : : struct mlx5_aso_mtr_pool *pool = NULL;
7237 : : struct mlx5_devx_obj *dcs = NULL;
7238 : : uint32_t i;
7239 : : uint32_t log_obj_size;
7240 : :
7241 : : log_obj_size = rte_log2_u32(MLX5_ASO_MTRS_PER_POOL >> 1);
7242 : 0 : dcs = mlx5_devx_cmd_create_flow_meter_aso_obj(priv->sh->cdev->ctx,
7243 : 0 : priv->sh->cdev->pdn,
7244 : : log_obj_size);
7245 [ # # ]: 0 : if (!dcs) {
7246 : 0 : rte_errno = ENODATA;
7247 : 0 : return NULL;
7248 : : }
7249 : 0 : pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
7250 [ # # ]: 0 : if (!pool) {
7251 : 0 : rte_errno = ENOMEM;
7252 : 0 : claim_zero(mlx5_devx_cmd_destroy(dcs));
7253 : 0 : return NULL;
7254 : : }
7255 : 0 : pool->devx_obj = dcs;
7256 : 0 : rte_rwlock_write_lock(&pools_mng->resize_mtrwl);
7257 : 0 : pool->index = pools_mng->n_valid;
7258 [ # # # # ]: 0 : if (pool->index == pools_mng->n && flow_dv_mtr_container_resize(dev)) {
7259 : 0 : mlx5_free(pool);
7260 : 0 : claim_zero(mlx5_devx_cmd_destroy(dcs));
7261 : : rte_rwlock_write_unlock(&pools_mng->resize_mtrwl);
7262 : 0 : return NULL;
7263 : : }
7264 : 0 : pools_mng->pools[pool->index] = pool;
7265 : 0 : pools_mng->n_valid++;
7266 : : rte_rwlock_write_unlock(&pools_mng->resize_mtrwl);
7267 [ # # ]: 0 : for (i = 1; i < MLX5_ASO_MTRS_PER_POOL; ++i) {
7268 : 0 : pool->mtrs[i].offset = i;
7269 [ # # ]: 0 : LIST_INSERT_HEAD(&pools_mng->meters, &pool->mtrs[i], next);
7270 : : }
7271 : 0 : pool->mtrs[0].offset = 0;
7272 : 0 : *mtr_free = &pool->mtrs[0];
7273 : 0 : return pool;
7274 : : }
7275 : :
7276 : : /**
7277 : : * Release a flow meter into pool.
7278 : : *
7279 : : * @param[in] dev
7280 : : * Pointer to the Ethernet device structure.
7281 : : * @param[in] mtr_idx
7282 : : * Index to aso flow meter.
7283 : : */
7284 : : static void
7285 : 0 : flow_dv_aso_mtr_release_to_pool(struct rte_eth_dev *dev, uint32_t mtr_idx)
7286 : : {
7287 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7288 : : struct mlx5_aso_mtr_pools_mng *pools_mng =
7289 : 0 : &priv->sh->mtrmng->pools_mng;
7290 : 0 : struct mlx5_aso_mtr *aso_mtr = mlx5_aso_meter_by_idx(priv, mtr_idx);
7291 : : void *meter_action_g;
7292 : : void *meter_action_y;
7293 : :
7294 : : MLX5_ASSERT(aso_mtr);
7295 : 0 : rte_spinlock_lock(&pools_mng->mtrsl);
7296 : 0 : meter_action_g = aso_mtr->fm.meter_action_g;
7297 : 0 : meter_action_y = aso_mtr->fm.meter_action_y;
7298 [ # # ]: 0 : memset(&aso_mtr->fm, 0, sizeof(struct mlx5_flow_meter_info));
7299 : 0 : aso_mtr->fm.meter_action_g = meter_action_g;
7300 : 0 : aso_mtr->fm.meter_action_y = meter_action_y;
7301 : 0 : aso_mtr->state = ASO_METER_FREE;
7302 [ # # ]: 0 : LIST_INSERT_HEAD(&pools_mng->meters, aso_mtr, next);
7303 : : rte_spinlock_unlock(&pools_mng->mtrsl);
7304 : 0 : }
7305 : :
7306 : : /**
7307 : : * Allocate a aso flow meter.
7308 : : *
7309 : : * @param[in] dev
7310 : : * Pointer to the Ethernet device structure.
7311 : : *
7312 : : * @return
7313 : : * Index to aso flow meter on success, 0 otherwise and rte_errno is set.
7314 : : */
7315 : : static uint32_t
7316 : 0 : flow_dv_mtr_alloc(struct rte_eth_dev *dev)
7317 : : {
7318 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7319 : 0 : struct mlx5_aso_mtr *mtr_free = NULL;
7320 : : struct mlx5_aso_mtr_pools_mng *pools_mng =
7321 : 0 : &priv->sh->mtrmng->pools_mng;
7322 : : struct mlx5_aso_mtr_pool *pool;
7323 : : uint32_t mtr_idx = 0;
7324 : :
7325 [ # # ]: 0 : if (!priv->sh->cdev->config.devx) {
7326 : 0 : rte_errno = ENOTSUP;
7327 : 0 : return 0;
7328 : : }
7329 : : /* Allocate the flow meter memory. */
7330 : : /* Get free meters from management. */
7331 : 0 : rte_spinlock_lock(&pools_mng->mtrsl);
7332 : 0 : mtr_free = LIST_FIRST(&pools_mng->meters);
7333 [ # # ]: 0 : if (mtr_free)
7334 [ # # ]: 0 : LIST_REMOVE(mtr_free, next);
7335 [ # # # # ]: 0 : if (!mtr_free && !flow_dv_mtr_pool_create(dev, &mtr_free)) {
7336 : : rte_spinlock_unlock(&pools_mng->mtrsl);
7337 : 0 : return 0;
7338 : : }
7339 : 0 : mtr_free->state = ASO_METER_WAIT;
7340 : : rte_spinlock_unlock(&pools_mng->mtrsl);
7341 : 0 : pool = container_of(mtr_free,
7342 : : struct mlx5_aso_mtr_pool,
7343 : : mtrs[mtr_free->offset]);
7344 : 0 : mtr_idx = MLX5_MAKE_MTR_IDX(pool->index, mtr_free->offset);
7345 [ # # ]: 0 : if (!mtr_free->fm.meter_action_g) {
7346 : : #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
7347 : : struct rte_flow_error error;
7348 : : uint8_t reg_id;
7349 : :
7350 : 0 : reg_id = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &error);
7351 : 0 : mtr_free->fm.meter_action_g =
7352 : 0 : mlx5_glue->dv_create_flow_action_aso
7353 : 0 : (priv->sh->rx_domain,
7354 : 0 : pool->devx_obj->obj,
7355 : : mtr_free->offset,
7356 : : (1 << MLX5_FLOW_COLOR_GREEN),
7357 : 0 : reg_id - REG_C_0);
7358 : : #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
7359 [ # # ]: 0 : if (!mtr_free->fm.meter_action_g) {
7360 : 0 : flow_dv_aso_mtr_release_to_pool(dev, mtr_idx);
7361 : 0 : return 0;
7362 : : }
7363 : : }
7364 : : return mtr_idx;
7365 : : }
7366 : :
7367 : : /**
7368 : : * Verify the @p attributes will be correctly understood by the NIC and store
7369 : : * them in the @p flow if everything is correct.
7370 : : *
7371 : : * @param[in] dev
7372 : : * Pointer to dev struct.
7373 : : * @param[in] attributes
7374 : : * Pointer to flow attributes
7375 : : * @param[in] external
7376 : : * This flow rule is created by request external to PMD.
7377 : : * @param[out] error
7378 : : * Pointer to error structure.
7379 : : *
7380 : : * @return
7381 : : * - 0 on success and non root table.
7382 : : * - 1 on success and root table.
7383 : : * - a negative errno value otherwise and rte_errno is set.
7384 : : */
7385 : : static int
7386 : 0 : flow_dv_validate_attributes(struct rte_eth_dev *dev,
7387 : : const struct mlx5_flow_tunnel *tunnel,
7388 : : const struct rte_flow_attr *attributes,
7389 : : const struct flow_grp_info *grp_info,
7390 : : struct rte_flow_error *error)
7391 : : {
7392 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7393 : 0 : uint32_t lowest_priority = mlx5_get_lowest_priority(dev, attributes);
7394 : : int ret = 0;
7395 : :
7396 : : #ifndef HAVE_MLX5DV_DR
7397 : : RTE_SET_USED(tunnel);
7398 : : RTE_SET_USED(grp_info);
7399 : : if (attributes->group)
7400 : : return rte_flow_error_set(error, ENOTSUP,
7401 : : RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
7402 : : NULL,
7403 : : "groups are not supported");
7404 : : #else
7405 : 0 : uint32_t table = 0;
7406 : :
7407 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel, attributes->group, &table,
7408 : : grp_info, error);
7409 [ # # ]: 0 : if (ret)
7410 : : return ret;
7411 [ # # ]: 0 : if (!table)
7412 : : ret = MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL;
7413 : : #endif
7414 [ # # # # ]: 0 : if (attributes->priority != MLX5_FLOW_LOWEST_PRIO_INDICATOR &&
7415 : : attributes->priority > lowest_priority)
7416 : 0 : return rte_flow_error_set(error, ENOTSUP,
7417 : : RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
7418 : : NULL,
7419 : : "priority out of range");
7420 [ # # # # ]: 0 : if (attributes->transfer && !priv->sh->config.dv_esw_en)
7421 : 0 : return rte_flow_error_set(error, ENOTSUP,
7422 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7423 : : "E-Switch dr is not supported");
7424 [ # # ]: 0 : if (attributes->ingress + attributes->egress + attributes->transfer != 1) {
7425 : 0 : return rte_flow_error_set(error, EINVAL,
7426 : : RTE_FLOW_ERROR_TYPE_ATTR, NULL,
7427 : : "must specify exactly one of "
7428 : : "ingress, egress or transfer");
7429 : : }
7430 : : return ret;
7431 : : }
7432 : :
7433 : : static int
7434 : 0 : validate_integrity_bits(const void *arg,
7435 : : int64_t pattern_flags, uint64_t l3_flags,
7436 : : uint64_t l4_flags, uint64_t ip4_flag,
7437 : : struct rte_flow_error *error)
7438 : : {
7439 : : const struct rte_flow_item_integrity *mask = arg;
7440 : :
7441 [ # # # # ]: 0 : if (mask->l3_ok && !(pattern_flags & l3_flags))
7442 : 0 : return rte_flow_error_set(error, EINVAL,
7443 : : RTE_FLOW_ERROR_TYPE_ITEM,
7444 : : NULL, "missing L3 protocol");
7445 : :
7446 [ # # # # ]: 0 : if (mask->ipv4_csum_ok && !(pattern_flags & ip4_flag))
7447 : 0 : return rte_flow_error_set(error, EINVAL,
7448 : : RTE_FLOW_ERROR_TYPE_ITEM,
7449 : : NULL, "missing IPv4 protocol");
7450 : :
7451 [ # # # # ]: 0 : if ((mask->l4_ok || mask->l4_csum_ok) && !(pattern_flags & l4_flags))
7452 : 0 : return rte_flow_error_set(error, EINVAL,
7453 : : RTE_FLOW_ERROR_TYPE_ITEM,
7454 : : NULL, "missing L4 protocol");
7455 : :
7456 : : return 0;
7457 : : }
7458 : :
7459 : : static int
7460 : 0 : flow_dv_validate_item_integrity_post(const struct
7461 : : rte_flow_item *integrity_items[2],
7462 : : int64_t pattern_flags,
7463 : : struct rte_flow_error *error)
7464 : : {
7465 : : const struct rte_flow_item_integrity *mask;
7466 : : int ret;
7467 : :
7468 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_OUTER_INTEGRITY) {
7469 : 0 : mask = (typeof(mask))integrity_items[0]->mask;
7470 : 0 : ret = validate_integrity_bits(mask, pattern_flags,
7471 : : MLX5_FLOW_LAYER_OUTER_L3,
7472 : : MLX5_FLOW_LAYER_OUTER_L4,
7473 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4,
7474 : : error);
7475 [ # # ]: 0 : if (ret)
7476 : : return ret;
7477 : : }
7478 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_INNER_INTEGRITY) {
7479 : 0 : mask = (typeof(mask))integrity_items[1]->mask;
7480 : 0 : ret = validate_integrity_bits(mask, pattern_flags,
7481 : : MLX5_FLOW_LAYER_INNER_L3,
7482 : : MLX5_FLOW_LAYER_INNER_L4,
7483 : : MLX5_FLOW_LAYER_INNER_L3_IPV4,
7484 : : error);
7485 [ # # ]: 0 : if (ret)
7486 : 0 : return ret;
7487 : : }
7488 : : return 0;
7489 : : }
7490 : :
7491 : : static int
7492 : 0 : flow_dv_validate_item_integrity(struct rte_eth_dev *dev,
7493 : : const struct rte_flow_item *integrity_item,
7494 : : uint64_t pattern_flags, uint64_t *last_item,
7495 : : const struct rte_flow_item *integrity_items[2],
7496 : : struct rte_flow_error *error)
7497 : : {
7498 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7499 : 0 : const struct rte_flow_item_integrity *mask = (typeof(mask))
7500 : : integrity_item->mask;
7501 : 0 : const struct rte_flow_item_integrity *spec = (typeof(spec))
7502 : : integrity_item->spec;
7503 : :
7504 [ # # ]: 0 : if (!priv->sh->cdev->config.hca_attr.pkt_integrity_match)
7505 : 0 : return rte_flow_error_set(error, ENOTSUP,
7506 : : RTE_FLOW_ERROR_TYPE_ITEM,
7507 : : integrity_item,
7508 : : "packet integrity integrity_item not supported");
7509 [ # # ]: 0 : if (!spec)
7510 : 0 : return rte_flow_error_set(error, ENOTSUP,
7511 : : RTE_FLOW_ERROR_TYPE_ITEM,
7512 : : integrity_item,
7513 : : "no spec for integrity item");
7514 [ # # ]: 0 : if (!mask)
7515 : : mask = &rte_flow_item_integrity_mask;
7516 [ # # ]: 0 : if (!mlx5_validate_integrity_item(mask))
7517 : 0 : return rte_flow_error_set(error, ENOTSUP,
7518 : : RTE_FLOW_ERROR_TYPE_ITEM,
7519 : : integrity_item,
7520 : : "unsupported integrity filter");
7521 [ # # # # ]: 0 : if ((mask->l3_ok & !spec->l3_ok) || (mask->l4_ok & !spec->l4_ok) ||
7522 [ # # ]: 0 : (mask->ipv4_csum_ok & !spec->ipv4_csum_ok) ||
7523 [ # # ]: 0 : (mask->l4_csum_ok & !spec->l4_csum_ok))
7524 : 0 : return rte_flow_error_set(error, EINVAL,
7525 : : RTE_FLOW_ERROR_TYPE_ITEM,
7526 : : NULL, "negative integrity flow is not supported");
7527 [ # # ]: 0 : if (spec->level > 1) {
7528 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_INNER_INTEGRITY)
7529 : 0 : return rte_flow_error_set
7530 : : (error, ENOTSUP,
7531 : : RTE_FLOW_ERROR_TYPE_ITEM,
7532 : : NULL, "multiple inner integrity items not supported");
7533 : 0 : integrity_items[1] = integrity_item;
7534 : 0 : *last_item |= MLX5_FLOW_ITEM_INNER_INTEGRITY;
7535 : : } else {
7536 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_OUTER_INTEGRITY)
7537 : 0 : return rte_flow_error_set
7538 : : (error, ENOTSUP,
7539 : : RTE_FLOW_ERROR_TYPE_ITEM,
7540 : : NULL, "multiple outer integrity items not supported");
7541 : 0 : integrity_items[0] = integrity_item;
7542 : 0 : *last_item |= MLX5_FLOW_ITEM_OUTER_INTEGRITY;
7543 : : }
7544 : : return 0;
7545 : : }
7546 : :
7547 : : static int
7548 : 0 : flow_dv_validate_item_flex(struct rte_eth_dev *dev,
7549 : : const struct rte_flow_item *item,
7550 : : uint64_t item_flags,
7551 : : uint64_t *last_item,
7552 : : bool is_inner,
7553 : : struct rte_flow_error *error)
7554 : : {
7555 : 0 : const struct rte_flow_item_flex *flow_spec = item->spec;
7556 : 0 : const struct rte_flow_item_flex *flow_mask = item->mask;
7557 : : struct mlx5_flex_item *flex;
7558 : :
7559 [ # # ]: 0 : if (!flow_spec)
7560 : 0 : return rte_flow_error_set(error, EINVAL,
7561 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
7562 : : "flex flow item spec cannot be NULL");
7563 [ # # ]: 0 : if (!flow_mask)
7564 : 0 : return rte_flow_error_set(error, EINVAL,
7565 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
7566 : : "flex flow item mask cannot be NULL");
7567 [ # # ]: 0 : if (item->last)
7568 : 0 : return rte_flow_error_set(error, ENOTSUP,
7569 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
7570 : : "flex flow item last not supported");
7571 [ # # ]: 0 : if (mlx5_flex_acquire_index(dev, flow_spec->handle, false) < 0)
7572 : 0 : return rte_flow_error_set(error, EINVAL,
7573 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
7574 : : "invalid flex flow item handle");
7575 : 0 : flex = (struct mlx5_flex_item *)flow_spec->handle;
7576 [ # # # # : 0 : switch (flex->tunnel_mode) {
# # ]
7577 : 0 : case FLEX_TUNNEL_MODE_SINGLE:
7578 [ # # ]: 0 : if (item_flags &
7579 : : (MLX5_FLOW_ITEM_OUTER_FLEX | MLX5_FLOW_ITEM_INNER_FLEX))
7580 : 0 : rte_flow_error_set(error, EINVAL,
7581 : : RTE_FLOW_ERROR_TYPE_ITEM,
7582 : : NULL, "multiple flex items not supported");
7583 : : break;
7584 : 0 : case FLEX_TUNNEL_MODE_OUTER:
7585 [ # # ]: 0 : if (is_inner)
7586 : 0 : rte_flow_error_set(error, EINVAL,
7587 : : RTE_FLOW_ERROR_TYPE_ITEM,
7588 : : NULL, "inner flex item was not configured");
7589 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_OUTER_FLEX)
7590 : 0 : rte_flow_error_set(error, ENOTSUP,
7591 : : RTE_FLOW_ERROR_TYPE_ITEM,
7592 : : NULL, "multiple flex items not supported");
7593 : : break;
7594 : 0 : case FLEX_TUNNEL_MODE_INNER:
7595 [ # # ]: 0 : if (!is_inner)
7596 : 0 : rte_flow_error_set(error, EINVAL,
7597 : : RTE_FLOW_ERROR_TYPE_ITEM,
7598 : : NULL, "outer flex item was not configured");
7599 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_INNER_FLEX)
7600 : 0 : rte_flow_error_set(error, EINVAL,
7601 : : RTE_FLOW_ERROR_TYPE_ITEM,
7602 : : NULL, "multiple flex items not supported");
7603 : : break;
7604 : 0 : case FLEX_TUNNEL_MODE_MULTI:
7605 [ # # # # : 0 : if ((is_inner && (item_flags & MLX5_FLOW_ITEM_INNER_FLEX)) ||
# # ]
7606 [ # # ]: 0 : (!is_inner && (item_flags & MLX5_FLOW_ITEM_OUTER_FLEX))) {
7607 : 0 : rte_flow_error_set(error, EINVAL,
7608 : : RTE_FLOW_ERROR_TYPE_ITEM,
7609 : : NULL, "multiple flex items not supported");
7610 : : }
7611 : : break;
7612 : 0 : case FLEX_TUNNEL_MODE_TUNNEL:
7613 [ # # # # ]: 0 : if (is_inner || (item_flags & MLX5_FLOW_ITEM_FLEX_TUNNEL))
7614 : 0 : rte_flow_error_set(error, EINVAL,
7615 : : RTE_FLOW_ERROR_TYPE_ITEM,
7616 : : NULL, "multiple flex tunnel items not supported");
7617 : : break;
7618 : 0 : default:
7619 : 0 : rte_flow_error_set(error, EINVAL,
7620 : : RTE_FLOW_ERROR_TYPE_ITEM,
7621 : : NULL, "invalid flex item configuration");
7622 : : }
7623 : 0 : *last_item = flex->tunnel_mode == FLEX_TUNNEL_MODE_TUNNEL ?
7624 [ # # ]: 0 : MLX5_FLOW_ITEM_FLEX_TUNNEL : is_inner ?
7625 [ # # ]: 0 : MLX5_FLOW_ITEM_INNER_FLEX : MLX5_FLOW_ITEM_OUTER_FLEX;
7626 : 0 : return 0;
7627 : : }
7628 : :
7629 : : static __rte_always_inline uint8_t
7630 : : mlx5_flow_l3_next_protocol(const struct rte_flow_item *l3_item,
7631 : : enum MLX5_SET_MATCHER key_type)
7632 : : {
7633 : : #define MLX5_L3_NEXT_PROTOCOL(i, ms) \
7634 : : ((i)->type == RTE_FLOW_ITEM_TYPE_IPV4 ? \
7635 : : ((const struct rte_flow_item_ipv4 *)(i)->ms)->hdr.next_proto_id : \
7636 : : (i)->type == RTE_FLOW_ITEM_TYPE_IPV6 ? \
7637 : : ((const struct rte_flow_item_ipv6 *)(i)->ms)->hdr.proto : \
7638 : : (i)->type == RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT ? \
7639 : : ((const struct rte_flow_item_ipv6_frag_ext *)(i)->ms)->hdr.next_header :\
7640 : : 0xff)
7641 : :
7642 : : uint8_t next_protocol;
7643 : :
7644 [ # # # # : 0 : if (l3_item->mask != NULL && l3_item->spec != NULL) {
# # # # #
# # # # #
# # # # #
# # # ]
7645 [ # # # # : 0 : next_protocol = MLX5_L3_NEXT_PROTOCOL(l3_item, mask);
# # # # #
# # # ]
7646 [ # # # # : 0 : if (next_protocol)
# # # # #
# # # ]
7647 [ # # # # : 0 : next_protocol &= MLX5_L3_NEXT_PROTOCOL(l3_item, spec);
# # # # #
# # # ]
7648 : : else
7649 : : next_protocol = 0xff;
7650 [ # # # # : 0 : } else if (key_type == MLX5_SET_MATCHER_HS_M && l3_item->mask != NULL) {
# # # # #
# # # ]
7651 [ # # # # : 0 : next_protocol = MLX5_L3_NEXT_PROTOCOL(l3_item, mask);
# # ]
7652 [ # # # # : 0 : } else if (key_type == MLX5_SET_MATCHER_HS_V && l3_item->spec != NULL) {
# # # # #
# # # ]
7653 [ # # # # : 0 : next_protocol = MLX5_L3_NEXT_PROTOCOL(l3_item, spec);
# # ]
7654 : : } else {
7655 : : /* Reset for inner layer. */
7656 : : next_protocol = 0xff;
7657 : : }
7658 : : return next_protocol;
7659 : :
7660 : : #undef MLX5_L3_NEXT_PROTOCOL
7661 : : }
7662 : :
7663 : : /**
7664 : : * Validate IB BTH item.
7665 : : *
7666 : : * @param[in] dev
7667 : : * Pointer to the rte_eth_dev structure.
7668 : : * @param[in] udp_dport
7669 : : * UDP destination port
7670 : : * @param[in] item
7671 : : * Item specification.
7672 : : * @param root
7673 : : * Whether action is on root table.
7674 : : * @param[out] error
7675 : : * Pointer to the error structure.
7676 : : *
7677 : : * @return
7678 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
7679 : : */
7680 : : static int
7681 : 0 : mlx5_flow_validate_item_ib_bth(struct rte_eth_dev *dev,
7682 : : uint16_t udp_dport,
7683 : : const struct rte_flow_item *item,
7684 : : bool root,
7685 : : struct rte_flow_error *error)
7686 : : {
7687 : 0 : const struct rte_flow_item_ib_bth *mask = item->mask;
7688 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7689 : : const struct rte_flow_item_ib_bth *valid_mask;
7690 : : int ret;
7691 : :
7692 : : valid_mask = &rte_flow_item_ib_bth_mask;
7693 [ # # ]: 0 : if (udp_dport && udp_dport != MLX5_UDP_PORT_ROCEv2)
7694 : 0 : return rte_flow_error_set(error, EINVAL,
7695 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
7696 : : "protocol filtering not compatible"
7697 : : " with UDP layer");
7698 [ # # # # ]: 0 : if (mask && (mask->hdr.se || mask->hdr.m || mask->hdr.padcnt ||
7699 [ # # # # ]: 0 : mask->hdr.tver || mask->hdr.pkey || mask->hdr.f || mask->hdr.b ||
7700 [ # # ]: 0 : mask->hdr.rsvd0 || mask->hdr.a || mask->hdr.rsvd1 ||
7701 [ # # # # : 0 : mask->hdr.psn[0] || mask->hdr.psn[1] || mask->hdr.psn[2]))
# # ]
7702 : 0 : return rte_flow_error_set(error, EINVAL,
7703 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
7704 : : "only opcode and dst_qp are supported");
7705 [ # # # # ]: 0 : if (root || priv->sh->steering_format_version ==
7706 : : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5)
7707 : 0 : return rte_flow_error_set(error, EINVAL,
7708 : : RTE_FLOW_ERROR_TYPE_ITEM,
7709 : : item,
7710 : : "IB BTH item is not supported");
7711 [ # # ]: 0 : if (!mask)
7712 : : mask = &rte_flow_item_ib_bth_mask;
7713 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
7714 : : (const uint8_t *)valid_mask,
7715 : : sizeof(struct rte_flow_item_ib_bth),
7716 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
7717 : : if (ret < 0)
7718 : : return ret;
7719 : : return 0;
7720 : : }
7721 : :
7722 : : const struct rte_flow_item_ipv4 nic_ipv4_mask = {
7723 : : .hdr = {
7724 : : .src_addr = RTE_BE32(0xffffffff),
7725 : : .dst_addr = RTE_BE32(0xffffffff),
7726 : : .type_of_service = 0xff,
7727 : : .fragment_offset = RTE_BE16(0xffff),
7728 : : .next_proto_id = 0xff,
7729 : : .time_to_live = 0xff,
7730 : : },
7731 : : };
7732 : :
7733 : : const struct rte_flow_item_ipv6 nic_ipv6_mask = {
7734 : : .hdr = {
7735 : : .src_addr = RTE_IPV6_MASK_FULL,
7736 : : .dst_addr = RTE_IPV6_MASK_FULL,
7737 : : .vtc_flow = RTE_BE32(0xffffffff),
7738 : : .proto = 0xff,
7739 : : .hop_limits = 0xff,
7740 : : },
7741 : : .has_frag_ext = 1,
7742 : : };
7743 : :
7744 : : const struct rte_flow_item_tcp nic_tcp_mask = {
7745 : : .hdr = {
7746 : : .tcp_flags = 0xFF,
7747 : : .src_port = RTE_BE16(UINT16_MAX),
7748 : : .dst_port = RTE_BE16(UINT16_MAX),
7749 : : }
7750 : : };
7751 : :
7752 : : /**
7753 : : * Internal validation function. For validating both actions and items.
7754 : : *
7755 : : * @param[in] dev
7756 : : * Pointer to the rte_eth_dev structure.
7757 : : * @param[in] attr
7758 : : * Pointer to the flow attributes.
7759 : : * @param[in] items
7760 : : * Pointer to the list of items.
7761 : : * @param[in] actions
7762 : : * Pointer to the list of actions.
7763 : : * @param[in] external
7764 : : * This flow rule is created by request external to PMD.
7765 : : * @param[in] hairpin
7766 : : * Number of hairpin TX actions, 0 means classic flow.
7767 : : * @param[out] error
7768 : : * Pointer to the error structure.
7769 : : *
7770 : : * @return
7771 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
7772 : : */
7773 : : int
7774 : 0 : mlx5_flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
7775 : : const struct rte_flow_item items[],
7776 : : const struct rte_flow_action actions[],
7777 : : bool external, int hairpin, struct rte_flow_error *error)
7778 : : {
7779 : : int ret;
7780 : 0 : uint64_t aso_mask, action_flags = 0;
7781 : 0 : uint64_t item_flags = 0;
7782 : 0 : uint64_t last_item = 0;
7783 : : uint8_t next_protocol = 0xff;
7784 : : uint16_t ether_type = 0;
7785 : 0 : int actions_n = 0;
7786 : : uint8_t item_ipv6_proto = 0;
7787 : 0 : int fdb_mirror = 0;
7788 : : int modify_after_mirror = 0;
7789 : : const struct rte_flow_item *geneve_item = NULL;
7790 : : const struct rte_flow_item *gre_item = NULL;
7791 : : const struct rte_flow_item *gtp_item = NULL;
7792 : : const struct rte_flow_action_raw_decap *decap;
7793 : : const struct rte_flow_action_raw_encap *encap;
7794 : : const struct rte_flow_action_rss *rss = NULL;
7795 : 0 : const struct rte_flow_action_rss *sample_rss = NULL;
7796 : 0 : const struct rte_flow_action_count *sample_count = NULL;
7797 : 0 : const struct rte_flow_item_ecpri nic_ecpri_mask = {
7798 : : .hdr = {
7799 : : .common = {
7800 : : .u32 =
7801 : : RTE_BE32(((const struct rte_ecpri_common_hdr) {
7802 : : .type = 0xFF,
7803 : : }).u32),
7804 : : },
7805 : : .dummy[0] = 0xffffffff,
7806 : : },
7807 : : };
7808 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7809 : 0 : struct mlx5_sh_config *dev_conf = &priv->sh->config;
7810 : : uint16_t queue_index = 0xFFFF;
7811 : : const struct rte_flow_item_vlan *vlan_m = NULL;
7812 : : uint32_t rw_act_num = 0;
7813 : : uint64_t is_root;
7814 : : const struct mlx5_flow_tunnel *tunnel;
7815 : : enum mlx5_tof_rule_type tof_rule_type;
7816 : 0 : struct flow_grp_info grp_info = {
7817 : : .external = !!external,
7818 : 0 : .transfer = !!attr->transfer,
7819 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
7820 : : .std_tbl_fix = true,
7821 : : };
7822 : : const struct rte_eth_hairpin_conf *conf;
7823 : 0 : const struct rte_flow_item *integrity_items[2] = {NULL, NULL};
7824 : : const struct rte_flow_item *port_id_item = NULL;
7825 : 0 : bool def_policy = false;
7826 : : bool shared_count = false;
7827 : : uint16_t udp_dport = 0;
7828 : 0 : uint32_t tag_id = 0, tag_bitmap = 0;
7829 : : const struct rte_flow_action_age *non_shared_age = NULL;
7830 : : const struct rte_flow_action_count *count = NULL;
7831 : : const struct rte_flow_action_port_id *port = NULL;
7832 : : const struct mlx5_rte_flow_item_tag *mlx5_tag;
7833 : 0 : struct mlx5_priv *act_priv = NULL;
7834 : : int aso_after_sample = 0;
7835 : : struct mlx5_priv *port_priv = NULL;
7836 : 0 : uint64_t sub_action_flags = 0;
7837 : 0 : uint16_t sample_port_id = 0;
7838 : : uint16_t port_id = 0;
7839 : :
7840 [ # # ]: 0 : if (items == NULL)
7841 : : return -1;
7842 : : tunnel = is_tunnel_offload_active(dev) ?
7843 [ # # ]: 0 : mlx5_get_tof(items, actions, &tof_rule_type) : NULL;
7844 [ # # ]: 0 : if (tunnel) {
7845 [ # # ]: 0 : if (!dev_conf->dv_flow_en)
7846 : 0 : return rte_flow_error_set
7847 : : (error, ENOTSUP,
7848 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7849 : : NULL, "tunnel offload requires DV flow interface");
7850 [ # # ]: 0 : if (priv->representor)
7851 : 0 : return rte_flow_error_set
7852 : : (error, ENOTSUP,
7853 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7854 : : NULL, "decap not supported for VF representor");
7855 [ # # ]: 0 : if (tof_rule_type == MLX5_TUNNEL_OFFLOAD_SET_RULE)
7856 : 0 : action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
7857 [ # # ]: 0 : else if (tof_rule_type == MLX5_TUNNEL_OFFLOAD_MATCH_RULE)
7858 : 0 : action_flags |= MLX5_FLOW_ACTION_TUNNEL_MATCH |
7859 : : MLX5_FLOW_ACTION_DECAP;
7860 : 0 : grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
7861 : : (dev, attr, tunnel, tof_rule_type);
7862 : : }
7863 : 0 : ret = flow_dv_validate_attributes(dev, tunnel, attr, &grp_info, error);
7864 [ # # ]: 0 : if (ret < 0)
7865 : : return ret;
7866 : 0 : is_root = (uint64_t)ret;
7867 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
7868 : : enum mlx5_l3_tunnel_detection l3_tunnel_detection;
7869 : : uint64_t l3_tunnel_flag;
7870 : 0 : int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
7871 : 0 : int type = items->type;
7872 : :
7873 : : if (!mlx5_flow_os_item_supported(type))
7874 : : return rte_flow_error_set(error, ENOTSUP,
7875 : : RTE_FLOW_ERROR_TYPE_ITEM,
7876 : : NULL, "item not supported");
7877 [ # # # # : 0 : switch (type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # #
# ]
7878 : : case RTE_FLOW_ITEM_TYPE_VOID:
7879 : : break;
7880 : 0 : case RTE_FLOW_ITEM_TYPE_ESP:
7881 : 0 : ret = mlx5_flow_os_validate_item_esp(dev, items, item_flags,
7882 : : next_protocol, false, error);
7883 [ # # ]: 0 : if (ret < 0)
7884 : 0 : return ret;
7885 : 0 : last_item = MLX5_FLOW_ITEM_ESP;
7886 : 0 : break;
7887 : 0 : case RTE_FLOW_ITEM_TYPE_PORT_ID:
7888 : 0 : ret = flow_dv_validate_item_port_id
7889 : : (dev, items, attr, item_flags, &act_priv, error);
7890 [ # # ]: 0 : if (ret < 0)
7891 : 0 : return ret;
7892 : 0 : last_item = MLX5_FLOW_ITEM_PORT_ID;
7893 : : port_id_item = items;
7894 : 0 : break;
7895 : 0 : case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
7896 : : case RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR:
7897 : 0 : ret = flow_dv_validate_item_represented_port
7898 : : (dev, items, attr, item_flags, &act_priv, error);
7899 [ # # ]: 0 : if (ret < 0)
7900 : 0 : return ret;
7901 : 0 : last_item = MLX5_FLOW_ITEM_REPRESENTED_PORT;
7902 : : port_id_item = items;
7903 : 0 : break;
7904 : 0 : case RTE_FLOW_ITEM_TYPE_ETH:
7905 : 0 : ret = mlx5_flow_validate_item_eth(dev, items, item_flags,
7906 : : true, error);
7907 [ # # ]: 0 : if (ret < 0)
7908 : 0 : return ret;
7909 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
7910 : : MLX5_FLOW_LAYER_OUTER_L2;
7911 [ # # # # ]: 0 : if (items->mask != NULL && items->spec != NULL) {
7912 : 0 : ether_type =
7913 : : ((const struct rte_flow_item_eth *)
7914 : : items->spec)->hdr.ether_type;
7915 : 0 : ether_type &=
7916 : : ((const struct rte_flow_item_eth *)
7917 : 0 : items->mask)->hdr.ether_type;
7918 [ # # ]: 0 : ether_type = rte_be_to_cpu_16(ether_type);
7919 : : } else {
7920 : : ether_type = 0;
7921 : : }
7922 : : break;
7923 : 0 : case RTE_FLOW_ITEM_TYPE_VLAN:
7924 : 0 : ret = mlx5_flow_dv_validate_item_vlan(items, item_flags,
7925 : : dev, error);
7926 [ # # ]: 0 : if (ret < 0)
7927 : 0 : return ret;
7928 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
7929 : : MLX5_FLOW_LAYER_OUTER_VLAN;
7930 [ # # # # ]: 0 : if (items->mask != NULL && items->spec != NULL) {
7931 : 0 : ether_type =
7932 : : ((const struct rte_flow_item_vlan *)
7933 : : items->spec)->hdr.eth_proto;
7934 : 0 : ether_type &=
7935 : : ((const struct rte_flow_item_vlan *)
7936 : 0 : items->mask)->hdr.eth_proto;
7937 [ # # ]: 0 : ether_type = rte_be_to_cpu_16(ether_type);
7938 : : } else {
7939 : : ether_type = 0;
7940 : : }
7941 : : /* Store outer VLAN mask for of_push_vlan action. */
7942 [ # # ]: 0 : if (!tunnel)
7943 : : vlan_m = items->mask;
7944 : : break;
7945 : : case RTE_FLOW_ITEM_TYPE_IPV4:
7946 : : next_protocol = mlx5_flow_l3_next_protocol
7947 : : (items, (enum MLX5_SET_MATCHER)-1);
7948 : : l3_tunnel_detection =
7949 : : mlx5_flow_tunnel_ip_check(items, next_protocol,
7950 : : item_flags,
7951 : : &l3_tunnel_flag);
7952 : : /*
7953 : : * explicitly allow inner IPIP match
7954 : : */
7955 : : if (l3_tunnel_detection == l3_tunnel_outer) {
7956 : 0 : item_flags |= l3_tunnel_flag;
7957 : : tunnel = 1;
7958 : : }
7959 : 0 : ret = mlx5_flow_dv_validate_item_ipv4(dev, items,
7960 : : item_flags,
7961 : : last_item,
7962 : : ether_type,
7963 : : &nic_ipv4_mask,
7964 : : error);
7965 [ # # ]: 0 : if (ret < 0)
7966 : 0 : return ret;
7967 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
7968 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4;
7969 [ # # ]: 0 : if (l3_tunnel_detection == l3_tunnel_outer)
7970 : 0 : item_flags |= l3_tunnel_flag;
7971 : : break;
7972 : : case RTE_FLOW_ITEM_TYPE_IPV6:
7973 : : next_protocol = mlx5_flow_l3_next_protocol
7974 : : (items, (enum MLX5_SET_MATCHER)-1);
7975 : : l3_tunnel_detection =
7976 : : mlx5_flow_tunnel_ip_check(items, next_protocol,
7977 : : item_flags,
7978 : : &l3_tunnel_flag);
7979 : : /*
7980 : : * explicitly allow inner IPIP match
7981 : : */
7982 : : if (l3_tunnel_detection == l3_tunnel_outer) {
7983 : 0 : item_flags |= l3_tunnel_flag;
7984 : : tunnel = 1;
7985 : : }
7986 : 0 : ret = mlx5_flow_validate_item_ipv6(dev, items,
7987 : : item_flags,
7988 : : last_item,
7989 : : ether_type,
7990 : : &nic_ipv6_mask,
7991 : : error);
7992 [ # # ]: 0 : if (ret < 0)
7993 : 0 : return ret;
7994 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
7995 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6;
7996 [ # # ]: 0 : if (l3_tunnel_detection == l3_tunnel_outer)
7997 : 0 : item_flags |= l3_tunnel_flag;
7998 : : break;
7999 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
8000 : 0 : ret = flow_dv_validate_item_ipv6_frag_ext(dev, items,
8001 : : item_flags,
8002 : : error);
8003 [ # # ]: 0 : if (ret < 0)
8004 : 0 : return ret;
8005 [ # # ]: 0 : last_item = tunnel ?
8006 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
8007 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
8008 : : next_protocol = mlx5_flow_l3_next_protocol
8009 : : (items, (enum MLX5_SET_MATCHER)-1);
8010 : : break;
8011 : 0 : case RTE_FLOW_ITEM_TYPE_TCP:
8012 : 0 : ret = mlx5_flow_validate_item_tcp
8013 : : (dev, items, item_flags,
8014 : : next_protocol,
8015 : : &nic_tcp_mask,
8016 : : error);
8017 [ # # ]: 0 : if (ret < 0)
8018 : 0 : return ret;
8019 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
8020 : : MLX5_FLOW_LAYER_OUTER_L4_TCP;
8021 : 0 : break;
8022 : 0 : case RTE_FLOW_ITEM_TYPE_UDP:
8023 : 0 : ret = mlx5_flow_validate_item_udp(dev, items, item_flags,
8024 : : next_protocol,
8025 : : error);
8026 : 0 : const struct rte_flow_item_udp *spec = items->spec;
8027 : 0 : const struct rte_flow_item_udp *mask = items->mask;
8028 [ # # ]: 0 : if (!mask)
8029 : : mask = &rte_flow_item_udp_mask;
8030 [ # # ]: 0 : if (spec != NULL)
8031 [ # # ]: 0 : udp_dport = rte_be_to_cpu_16
8032 : : (spec->hdr.dst_port &
8033 : : mask->hdr.dst_port);
8034 [ # # ]: 0 : if (ret < 0)
8035 : 0 : return ret;
8036 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
8037 : : MLX5_FLOW_LAYER_OUTER_L4_UDP;
8038 : 0 : break;
8039 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
8040 : 0 : ret = mlx5_flow_validate_item_gre(dev, items, item_flags,
8041 : : next_protocol, error);
8042 [ # # ]: 0 : if (ret < 0)
8043 : 0 : return ret;
8044 : : gre_item = items;
8045 : 0 : last_item = MLX5_FLOW_LAYER_GRE;
8046 : 0 : break;
8047 : 0 : case RTE_FLOW_ITEM_TYPE_GRE_OPTION:
8048 : 0 : ret = mlx5_flow_validate_item_gre_option(dev, items, item_flags,
8049 : : attr, gre_item, error);
8050 [ # # ]: 0 : if (ret < 0)
8051 : 0 : return ret;
8052 : 0 : last_item = MLX5_FLOW_LAYER_GRE;
8053 : 0 : break;
8054 : 0 : case RTE_FLOW_ITEM_TYPE_NVGRE:
8055 : 0 : ret = mlx5_flow_validate_item_nvgre(dev, items,
8056 : : item_flags,
8057 : : next_protocol,
8058 : : error);
8059 [ # # ]: 0 : if (ret < 0)
8060 : 0 : return ret;
8061 : 0 : last_item = MLX5_FLOW_LAYER_NVGRE;
8062 : 0 : break;
8063 : 0 : case RTE_FLOW_ITEM_TYPE_GRE_KEY:
8064 : 0 : ret = mlx5_flow_validate_item_gre_key
8065 : : (dev, items, item_flags, gre_item, error);
8066 [ # # ]: 0 : if (ret < 0)
8067 : 0 : return ret;
8068 : 0 : last_item = MLX5_FLOW_LAYER_GRE_KEY;
8069 : 0 : break;
8070 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN:
8071 : 0 : ret = mlx5_flow_validate_item_vxlan(dev, udp_dport,
8072 : : items, item_flags,
8073 : : is_root, error);
8074 [ # # ]: 0 : if (ret < 0)
8075 : 0 : return ret;
8076 : 0 : last_item = MLX5_FLOW_LAYER_VXLAN;
8077 : 0 : break;
8078 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
8079 : 0 : ret = mlx5_flow_validate_item_vxlan_gpe(items,
8080 : : item_flags, dev,
8081 : : error);
8082 [ # # ]: 0 : if (ret < 0)
8083 : 0 : return ret;
8084 : 0 : last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
8085 : 0 : break;
8086 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE:
8087 : 0 : ret = mlx5_flow_validate_item_geneve(items,
8088 : : item_flags, dev,
8089 : : error);
8090 [ # # ]: 0 : if (ret < 0)
8091 : 0 : return ret;
8092 : : geneve_item = items;
8093 : 0 : last_item = MLX5_FLOW_LAYER_GENEVE;
8094 : 0 : break;
8095 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
8096 : 0 : ret = mlx5_flow_validate_item_geneve_opt(items,
8097 : : last_item,
8098 : : geneve_item,
8099 : : dev,
8100 : : error);
8101 [ # # ]: 0 : if (ret < 0)
8102 : 0 : return ret;
8103 : 0 : last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
8104 : 0 : break;
8105 : 0 : case RTE_FLOW_ITEM_TYPE_MPLS:
8106 : 0 : ret = mlx5_flow_validate_item_mpls(dev, items,
8107 : : item_flags,
8108 : : last_item, error);
8109 [ # # ]: 0 : if (ret < 0)
8110 : 0 : return ret;
8111 : 0 : last_item = MLX5_FLOW_LAYER_MPLS;
8112 : 0 : break;
8113 : :
8114 : 0 : case RTE_FLOW_ITEM_TYPE_MARK:
8115 : 0 : ret = flow_dv_validate_item_mark(dev, items, attr,
8116 : : error);
8117 [ # # ]: 0 : if (ret < 0)
8118 : 0 : return ret;
8119 : 0 : last_item = MLX5_FLOW_ITEM_MARK;
8120 : 0 : break;
8121 : 0 : case RTE_FLOW_ITEM_TYPE_META:
8122 : 0 : ret = flow_dv_validate_item_meta(dev, items, attr,
8123 : : error);
8124 [ # # ]: 0 : if (ret < 0)
8125 : 0 : return ret;
8126 : 0 : last_item = MLX5_FLOW_ITEM_METADATA;
8127 : 0 : break;
8128 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP:
8129 : 0 : ret = mlx5_flow_validate_item_icmp(dev, items, item_flags,
8130 : : next_protocol,
8131 : : error);
8132 [ # # ]: 0 : if (ret < 0)
8133 : 0 : return ret;
8134 : 0 : last_item = MLX5_FLOW_LAYER_ICMP;
8135 : 0 : break;
8136 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6:
8137 : 0 : ret = mlx5_flow_validate_item_icmp6(dev, items, item_flags,
8138 : : next_protocol,
8139 : : error);
8140 [ # # ]: 0 : if (ret < 0)
8141 : 0 : return ret;
8142 : : item_ipv6_proto = IPPROTO_ICMPV6;
8143 : 0 : last_item = MLX5_FLOW_LAYER_ICMP6;
8144 : 0 : break;
8145 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REQUEST:
8146 : : case RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REPLY:
8147 : 0 : ret = mlx5_flow_validate_item_icmp6_echo(dev, items,
8148 : : item_flags,
8149 : : next_protocol,
8150 : : error);
8151 [ # # ]: 0 : if (ret < 0)
8152 : 0 : return ret;
8153 : : item_ipv6_proto = IPPROTO_ICMPV6;
8154 : 0 : last_item = MLX5_FLOW_LAYER_ICMP6;
8155 : 0 : break;
8156 : 0 : case RTE_FLOW_ITEM_TYPE_TAG:
8157 : 0 : ret = flow_dv_validate_item_tag(dev, items, &tag_bitmap,
8158 : : attr, error);
8159 [ # # ]: 0 : if (ret < 0)
8160 : 0 : return ret;
8161 : 0 : last_item = MLX5_FLOW_ITEM_TAG;
8162 : 0 : break;
8163 : 0 : case RTE_FLOW_ITEM_TYPE_TX_QUEUE:
8164 : : case MLX5_RTE_FLOW_ITEM_TYPE_SQ:
8165 : 0 : last_item = MLX5_FLOW_ITEM_SQ;
8166 : 0 : break;
8167 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
8168 : 0 : mlx5_tag = (const struct mlx5_rte_flow_item_tag *)items->spec;
8169 [ # # ]: 0 : if (tag_bitmap & (1 << mlx5_tag->id))
8170 : 0 : return rte_flow_error_set(error, EINVAL,
8171 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
8172 : : items->spec,
8173 : : "Duplicated tag index");
8174 : 0 : tag_bitmap |= 1 << mlx5_tag->id;
8175 : 0 : break;
8176 : 0 : case RTE_FLOW_ITEM_TYPE_GTP:
8177 : 0 : ret = mlx5_flow_dv_validate_item_gtp(dev, items,
8178 : : item_flags,
8179 : : error);
8180 [ # # ]: 0 : if (ret < 0)
8181 : 0 : return ret;
8182 : : gtp_item = items;
8183 : 0 : last_item = MLX5_FLOW_LAYER_GTP;
8184 : 0 : break;
8185 : 0 : case RTE_FLOW_ITEM_TYPE_GTP_PSC:
8186 : 0 : ret = mlx5_flow_dv_validate_item_gtp_psc(dev, items,
8187 : : last_item,
8188 : : gtp_item,
8189 : : is_root, error);
8190 [ # # ]: 0 : if (ret < 0)
8191 : 0 : return ret;
8192 : 0 : last_item = MLX5_FLOW_LAYER_GTP_PSC;
8193 : 0 : break;
8194 : 0 : case RTE_FLOW_ITEM_TYPE_ECPRI:
8195 : : /* Capacity will be checked in the translate stage. */
8196 : 0 : ret = mlx5_flow_validate_item_ecpri(dev, items,
8197 : : item_flags,
8198 : : last_item,
8199 : : ether_type,
8200 : : &nic_ecpri_mask,
8201 : : error);
8202 [ # # ]: 0 : if (ret < 0)
8203 : 0 : return ret;
8204 : 0 : last_item = MLX5_FLOW_LAYER_ECPRI;
8205 : 0 : break;
8206 : 0 : case RTE_FLOW_ITEM_TYPE_INTEGRITY:
8207 : 0 : ret = flow_dv_validate_item_integrity(dev, items,
8208 : : item_flags,
8209 : : &last_item,
8210 : : integrity_items,
8211 : : error);
8212 [ # # ]: 0 : if (ret < 0)
8213 : 0 : return ret;
8214 : : break;
8215 : 0 : case RTE_FLOW_ITEM_TYPE_CONNTRACK:
8216 : 0 : ret = mlx5_flow_dv_validate_item_aso_ct(dev, items,
8217 : : &item_flags,
8218 : : error);
8219 [ # # ]: 0 : if (ret < 0)
8220 : 0 : return ret;
8221 : 0 : last_item = MLX5_FLOW_LAYER_ASO_CT;
8222 : 0 : break;
8223 : : case MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL:
8224 : : /* tunnel offload item was processed before
8225 : : * list it here as a supported type
8226 : : */
8227 : : break;
8228 : 0 : case RTE_FLOW_ITEM_TYPE_FLEX:
8229 : 0 : ret = flow_dv_validate_item_flex(dev, items, item_flags,
8230 : : &last_item,
8231 : : tunnel != 0, error);
8232 [ # # ]: 0 : if (ret < 0)
8233 : 0 : return ret;
8234 : : /* Reset for next proto, it is unknown. */
8235 : : next_protocol = 0xff;
8236 : : break;
8237 : 0 : case RTE_FLOW_ITEM_TYPE_METER_COLOR:
8238 : 0 : ret = flow_dv_validate_item_meter_color(dev, items,
8239 : : attr, error);
8240 [ # # ]: 0 : if (ret < 0)
8241 : 0 : return ret;
8242 : 0 : last_item = MLX5_FLOW_ITEM_METER_COLOR;
8243 : 0 : break;
8244 : 0 : case RTE_FLOW_ITEM_TYPE_AGGR_AFFINITY:
8245 : 0 : ret = flow_dv_validate_item_aggr_affinity(dev, items,
8246 : : attr, error);
8247 [ # # ]: 0 : if (ret < 0)
8248 : 0 : return ret;
8249 : 0 : last_item = MLX5_FLOW_ITEM_AGGR_AFFINITY;
8250 : 0 : break;
8251 : 0 : case RTE_FLOW_ITEM_TYPE_IB_BTH:
8252 : 0 : ret = mlx5_flow_validate_item_ib_bth(dev, udp_dport,
8253 : : items, is_root, error);
8254 [ # # ]: 0 : if (ret < 0)
8255 : 0 : return ret;
8256 : :
8257 : 0 : last_item = MLX5_FLOW_ITEM_IB_BTH;
8258 : 0 : break;
8259 : 0 : case RTE_FLOW_ITEM_TYPE_NSH:
8260 : 0 : ret = mlx5_flow_validate_item_nsh(dev, items, error);
8261 [ # # ]: 0 : if (ret < 0)
8262 : 0 : return ret;
8263 : 0 : last_item = MLX5_FLOW_ITEM_NSH;
8264 : 0 : break;
8265 : 0 : default:
8266 : 0 : return rte_flow_error_set(error, ENOTSUP,
8267 : : RTE_FLOW_ERROR_TYPE_ITEM,
8268 : : NULL, "item not supported");
8269 : : }
8270 : 0 : item_flags |= last_item;
8271 : : }
8272 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_INTEGRITY) {
8273 : 0 : ret = flow_dv_validate_item_integrity_post(integrity_items,
8274 : : item_flags, error);
8275 [ # # ]: 0 : if (ret)
8276 : : return ret;
8277 : : }
8278 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
8279 : 0 : int type = actions->type;
8280 : :
8281 : : if (!mlx5_flow_os_action_supported(type))
8282 : : return rte_flow_error_set(error, ENOTSUP,
8283 : : RTE_FLOW_ERROR_TYPE_ACTION,
8284 : : actions,
8285 : : "action not supported");
8286 [ # # ]: 0 : if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
8287 : 0 : return rte_flow_error_set(error, ENOTSUP,
8288 : : RTE_FLOW_ERROR_TYPE_ACTION,
8289 : : actions, "too many actions");
8290 [ # # ]: 0 : if (action_flags &
8291 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
8292 : 0 : return rte_flow_error_set(error, ENOTSUP,
8293 : : RTE_FLOW_ERROR_TYPE_ACTION,
8294 : : NULL, "meter action with policy "
8295 : : "must be the last action");
8296 [ # # # # : 0 : switch (type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
8297 : : case RTE_FLOW_ACTION_TYPE_VOID:
8298 : : break;
8299 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
8300 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
8301 : 0 : ret = flow_dv_validate_action_port_id(dev,
8302 : : action_flags,
8303 : : actions,
8304 : : attr,
8305 : : error);
8306 [ # # ]: 0 : if (ret)
8307 : 0 : return ret;
8308 [ # # ]: 0 : if (type == RTE_FLOW_ACTION_TYPE_PORT_ID) {
8309 : 0 : port = (const struct rte_flow_action_port_id *)
8310 : : actions->conf;
8311 [ # # ]: 0 : port_id = port->original ? dev->data->port_id : port->id;
8312 : : } else {
8313 : 0 : port_id = ((const struct rte_flow_action_ethdev *)
8314 : 0 : actions->conf)->port_id;
8315 : : }
8316 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_ID;
8317 : 0 : ++actions_n;
8318 : 0 : break;
8319 : 0 : case RTE_FLOW_ACTION_TYPE_FLAG:
8320 : 0 : ret = flow_dv_validate_action_flag(dev, action_flags,
8321 : : attr, error);
8322 [ # # ]: 0 : if (ret < 0)
8323 : 0 : return ret;
8324 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
8325 : : /* Count all modify-header actions as one. */
8326 [ # # ]: 0 : if (!(action_flags &
8327 : : MLX5_FLOW_MODIFY_HDR_ACTIONS))
8328 : 0 : ++actions_n;
8329 : 0 : action_flags |= MLX5_FLOW_ACTION_FLAG |
8330 : : MLX5_FLOW_ACTION_MARK_EXT;
8331 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8332 : : modify_after_mirror = 1;
8333 : :
8334 : : } else {
8335 : 0 : action_flags |= MLX5_FLOW_ACTION_FLAG;
8336 : 0 : ++actions_n;
8337 : : }
8338 : 0 : rw_act_num += MLX5_ACT_NUM_SET_MARK;
8339 : 0 : break;
8340 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
8341 : 0 : ret = flow_dv_validate_action_mark(dev, actions,
8342 : : action_flags,
8343 : : attr, error);
8344 [ # # ]: 0 : if (ret < 0)
8345 : 0 : return ret;
8346 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
8347 : : /* Count all modify-header actions as one. */
8348 [ # # ]: 0 : if (!(action_flags &
8349 : : MLX5_FLOW_MODIFY_HDR_ACTIONS))
8350 : 0 : ++actions_n;
8351 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK |
8352 : : MLX5_FLOW_ACTION_MARK_EXT;
8353 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8354 : : modify_after_mirror = 1;
8355 : : } else {
8356 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK;
8357 : 0 : ++actions_n;
8358 : : }
8359 : 0 : rw_act_num += MLX5_ACT_NUM_SET_MARK;
8360 : 0 : break;
8361 : 0 : case RTE_FLOW_ACTION_TYPE_SET_META:
8362 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
8363 : 0 : return rte_flow_error_set(error, ENOTSUP,
8364 : : RTE_FLOW_ERROR_TYPE_ACTION,
8365 : : actions,
8366 : : "action not supported");
8367 : 0 : ret = flow_dv_validate_action_set_meta(dev, actions,
8368 : : action_flags,
8369 : : attr, error);
8370 [ # # ]: 0 : if (ret < 0)
8371 : 0 : return ret;
8372 : : /* Count all modify-header actions as one action. */
8373 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8374 : 0 : ++actions_n;
8375 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8376 : : modify_after_mirror = 1;
8377 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_META;
8378 : 0 : rw_act_num += MLX5_ACT_NUM_SET_META;
8379 : 0 : break;
8380 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TAG:
8381 : 0 : ret = flow_dv_validate_action_set_tag(dev, actions,
8382 : : action_flags,
8383 : : attr, error);
8384 [ # # ]: 0 : if (ret < 0)
8385 : 0 : return ret;
8386 : : /* Count all modify-header actions as one action. */
8387 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8388 : 0 : ++actions_n;
8389 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8390 : : modify_after_mirror = 1;
8391 : 0 : tag_id = ((const struct rte_flow_action_set_tag *)
8392 : 0 : actions->conf)->index;
8393 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
8394 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
8395 : 0 : break;
8396 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
8397 : 0 : ret = mlx5_flow_validate_action_drop(dev, is_root,
8398 : : attr, error);
8399 [ # # ]: 0 : if (ret < 0)
8400 : 0 : return ret;
8401 : 0 : action_flags |= MLX5_FLOW_ACTION_DROP;
8402 : 0 : ++actions_n;
8403 : 0 : break;
8404 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
8405 : 0 : ret = mlx5_flow_validate_action_queue(actions,
8406 : : action_flags, dev,
8407 : : attr, error);
8408 [ # # ]: 0 : if (ret < 0)
8409 : 0 : return ret;
8410 : 0 : queue_index = ((const struct rte_flow_action_queue *)
8411 : 0 : (actions->conf))->index;
8412 : 0 : action_flags |= MLX5_FLOW_ACTION_QUEUE;
8413 : 0 : ++actions_n;
8414 : 0 : break;
8415 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
8416 : 0 : rss = actions->conf;
8417 : 0 : ret = mlx5_flow_validate_action_rss(actions,
8418 : : action_flags, dev,
8419 : : attr, item_flags,
8420 : : error);
8421 [ # # ]: 0 : if (ret < 0)
8422 : 0 : return ret;
8423 [ # # ]: 0 : if (rss && sample_rss &&
8424 [ # # ]: 0 : (sample_rss->level != rss->level ||
8425 [ # # ]: 0 : sample_rss->types != rss->types))
8426 : 0 : return rte_flow_error_set(error, ENOTSUP,
8427 : : RTE_FLOW_ERROR_TYPE_ACTION,
8428 : : NULL,
8429 : : "Can't use the different RSS types "
8430 : : "or level in the same flow");
8431 [ # # # # ]: 0 : if (rss != NULL && rss->queue_num)
8432 : 0 : queue_index = rss->queue[0];
8433 : 0 : action_flags |= MLX5_FLOW_ACTION_RSS;
8434 : 0 : ++actions_n;
8435 : 0 : break;
8436 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
8437 : : ret =
8438 : 0 : mlx5_flow_validate_action_default_miss(action_flags,
8439 : : attr, error);
8440 [ # # ]: 0 : if (ret < 0)
8441 : 0 : return ret;
8442 : 0 : action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
8443 : 0 : ++actions_n;
8444 : 0 : break;
8445 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
8446 : : shared_count = true;
8447 : : /* fall-through. */
8448 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
8449 : 0 : ret = flow_dv_validate_action_count(dev, shared_count,
8450 : : action_flags,
8451 : : is_root, error);
8452 [ # # ]: 0 : if (ret < 0)
8453 : 0 : return ret;
8454 : 0 : count = actions->conf;
8455 : 0 : action_flags |= MLX5_FLOW_ACTION_COUNT;
8456 : 0 : ++actions_n;
8457 : 0 : break;
8458 : 0 : case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
8459 [ # # ]: 0 : if (flow_dv_validate_action_pop_vlan(dev,
8460 : : action_flags,
8461 : : actions,
8462 : : item_flags, attr,
8463 : : error))
8464 : 0 : return -rte_errno;
8465 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8466 : : modify_after_mirror = 1;
8467 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
8468 : 0 : ++actions_n;
8469 : 0 : break;
8470 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
8471 : 0 : ret = flow_dv_validate_action_push_vlan(dev,
8472 : : action_flags,
8473 : : vlan_m,
8474 : : actions, attr,
8475 : : error);
8476 [ # # ]: 0 : if (ret < 0)
8477 : 0 : return ret;
8478 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8479 : : modify_after_mirror = 1;
8480 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
8481 : 0 : ++actions_n;
8482 : 0 : break;
8483 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
8484 : 0 : ret = flow_dv_validate_action_set_vlan_pcp
8485 : : (action_flags, actions, error);
8486 [ # # ]: 0 : if (ret < 0)
8487 : 0 : return ret;
8488 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8489 : : modify_after_mirror = 1;
8490 : : /* Count PCP with push_vlan command. */
8491 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_PCP;
8492 : 0 : break;
8493 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
8494 : 0 : ret = flow_dv_validate_action_set_vlan_vid
8495 : : (item_flags, action_flags,
8496 : : actions, error);
8497 [ # # ]: 0 : if (ret < 0)
8498 : 0 : return ret;
8499 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8500 : : modify_after_mirror = 1;
8501 : : /* Count VID with push_vlan command. */
8502 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
8503 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_VID;
8504 : 0 : break;
8505 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
8506 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
8507 : 0 : ret = mlx5_flow_dv_validate_action_l2_encap(dev,
8508 : : action_flags,
8509 : : actions,
8510 : : attr,
8511 : : error);
8512 [ # # ]: 0 : if (ret < 0)
8513 : 0 : return ret;
8514 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
8515 : 0 : ++actions_n;
8516 : 0 : break;
8517 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
8518 : : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
8519 : 0 : ret = mlx5_flow_dv_validate_action_decap(dev,
8520 : : action_flags,
8521 : : actions,
8522 : : item_flags,
8523 : : attr, error);
8524 [ # # ]: 0 : if (ret < 0)
8525 : 0 : return ret;
8526 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8527 : : modify_after_mirror = 1;
8528 : 0 : action_flags |= MLX5_FLOW_ACTION_DECAP;
8529 : 0 : ++actions_n;
8530 : 0 : break;
8531 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
8532 : 0 : ret = mlx5_flow_dv_validate_action_raw_encap_decap
8533 : 0 : (dev, NULL, actions->conf, attr, &action_flags,
8534 : : &actions_n, actions, item_flags, error);
8535 [ # # ]: 0 : if (ret < 0)
8536 : 0 : return ret;
8537 : : break;
8538 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
8539 : 0 : decap = actions->conf;
8540 [ # # ]: 0 : while ((++actions)->type == RTE_FLOW_ACTION_TYPE_VOID)
8541 : : ;
8542 [ # # ]: 0 : if (actions->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
8543 : : encap = NULL;
8544 : : actions--;
8545 : : } else {
8546 : 0 : encap = actions->conf;
8547 : : }
8548 [ # # ]: 0 : ret = mlx5_flow_dv_validate_action_raw_encap_decap
8549 : : (dev,
8550 : : decap ? decap : &empty_decap, encap,
8551 : : attr, &action_flags, &actions_n,
8552 : : actions, item_flags, error);
8553 [ # # ]: 0 : if (ret < 0)
8554 : 0 : return ret;
8555 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_SAMPLE) &&
8556 : : (action_flags & MLX5_FLOW_ACTION_DECAP))
8557 : : modify_after_mirror = 1;
8558 : : break;
8559 : 0 : case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
8560 : : case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
8561 : 0 : ret = flow_dv_validate_action_modify_mac(action_flags,
8562 : : actions,
8563 : : item_flags,
8564 : : error);
8565 [ # # ]: 0 : if (ret < 0)
8566 : 0 : return ret;
8567 : : /* Count all modify-header actions as one action. */
8568 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8569 : 0 : ++actions_n;
8570 : 0 : action_flags |= actions->type ==
8571 : : RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
8572 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_MAC_SRC :
8573 : : MLX5_FLOW_ACTION_SET_MAC_DST;
8574 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8575 : : modify_after_mirror = 1;
8576 : : /*
8577 : : * Even if the source and destination MAC addresses have
8578 : : * overlap in the header with 4B alignment, the convert
8579 : : * function will handle them separately and 4 SW actions
8580 : : * will be created. And 2 actions will be added each
8581 : : * time no matter how many bytes of address will be set.
8582 : : */
8583 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_MAC;
8584 : 0 : break;
8585 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
8586 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
8587 : 0 : ret = flow_dv_validate_action_modify_ipv4(action_flags,
8588 : : actions,
8589 : : item_flags,
8590 : : error);
8591 [ # # ]: 0 : if (ret < 0)
8592 : 0 : return ret;
8593 : : /* Count all modify-header actions as one action. */
8594 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8595 : 0 : ++actions_n;
8596 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8597 : : modify_after_mirror = 1;
8598 : 0 : action_flags |= actions->type ==
8599 : : RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
8600 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_IPV4_SRC :
8601 : : MLX5_FLOW_ACTION_SET_IPV4_DST;
8602 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_IPV4;
8603 : 0 : break;
8604 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
8605 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
8606 : 0 : ret = flow_dv_validate_action_modify_ipv6(action_flags,
8607 : : actions,
8608 : : item_flags,
8609 : : error);
8610 [ # # ]: 0 : if (ret < 0)
8611 : 0 : return ret;
8612 [ # # ]: 0 : if (item_ipv6_proto == IPPROTO_ICMPV6)
8613 : 0 : return rte_flow_error_set(error, ENOTSUP,
8614 : : RTE_FLOW_ERROR_TYPE_ACTION,
8615 : : actions,
8616 : : "Can't change header "
8617 : : "with ICMPv6 proto");
8618 : : /* Count all modify-header actions as one action. */
8619 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8620 : 0 : ++actions_n;
8621 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8622 : : modify_after_mirror = 1;
8623 : 0 : action_flags |= actions->type ==
8624 : : RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
8625 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_IPV6_SRC :
8626 : : MLX5_FLOW_ACTION_SET_IPV6_DST;
8627 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_IPV6;
8628 : 0 : break;
8629 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
8630 : : case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
8631 : 0 : ret = flow_dv_validate_action_modify_tp(action_flags,
8632 : : actions,
8633 : : item_flags,
8634 : : error);
8635 [ # # ]: 0 : if (ret < 0)
8636 : 0 : return ret;
8637 : : /* Count all modify-header actions as one action. */
8638 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8639 : 0 : ++actions_n;
8640 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8641 : : modify_after_mirror = 1;
8642 : 0 : action_flags |= actions->type ==
8643 : : RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
8644 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_TP_SRC :
8645 : : MLX5_FLOW_ACTION_SET_TP_DST;
8646 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_PORT;
8647 : 0 : break;
8648 : 0 : case RTE_FLOW_ACTION_TYPE_DEC_TTL:
8649 : : case RTE_FLOW_ACTION_TYPE_SET_TTL:
8650 : 0 : ret = flow_dv_validate_action_modify_ttl(action_flags,
8651 : : actions,
8652 : : item_flags,
8653 : : error);
8654 [ # # ]: 0 : if (ret < 0)
8655 : 0 : return ret;
8656 : : /* Count all modify-header actions as one action. */
8657 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8658 : 0 : ++actions_n;
8659 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8660 : : modify_after_mirror = 1;
8661 : 0 : action_flags |= actions->type ==
8662 : : RTE_FLOW_ACTION_TYPE_SET_TTL ?
8663 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_TTL :
8664 : : MLX5_FLOW_ACTION_DEC_TTL;
8665 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_TTL;
8666 : 0 : break;
8667 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
8668 : 0 : ret = flow_dv_validate_action_jump(dev, tunnel, actions,
8669 : : action_flags,
8670 : : attr, external,
8671 : : error);
8672 [ # # ]: 0 : if (ret)
8673 : 0 : return ret;
8674 : 0 : ++actions_n;
8675 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP;
8676 : 0 : break;
8677 : 0 : case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
8678 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
8679 : 0 : ret = flow_dv_validate_action_modify_tcp_seq
8680 : : (action_flags,
8681 : : actions,
8682 : : item_flags,
8683 : : error);
8684 [ # # ]: 0 : if (ret < 0)
8685 : 0 : return ret;
8686 : : /* Count all modify-header actions as one action. */
8687 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8688 : 0 : ++actions_n;
8689 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8690 : : modify_after_mirror = 1;
8691 : 0 : action_flags |= actions->type ==
8692 : : RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
8693 [ # # ]: 0 : MLX5_FLOW_ACTION_INC_TCP_SEQ :
8694 : : MLX5_FLOW_ACTION_DEC_TCP_SEQ;
8695 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_TCPSEQ;
8696 : 0 : break;
8697 : 0 : case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
8698 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
8699 : 0 : ret = flow_dv_validate_action_modify_tcp_ack
8700 : : (action_flags,
8701 : : actions,
8702 : : item_flags,
8703 : : error);
8704 [ # # ]: 0 : if (ret < 0)
8705 : 0 : return ret;
8706 : : /* Count all modify-header actions as one action. */
8707 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8708 : 0 : ++actions_n;
8709 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8710 : : modify_after_mirror = 1;
8711 : 0 : action_flags |= actions->type ==
8712 : : RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
8713 [ # # ]: 0 : MLX5_FLOW_ACTION_INC_TCP_ACK :
8714 : : MLX5_FLOW_ACTION_DEC_TCP_ACK;
8715 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_TCPACK;
8716 : 0 : break;
8717 : : case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
8718 : : break;
8719 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
8720 : : case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
8721 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
8722 : 0 : break;
8723 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
8724 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
8725 : 0 : return rte_flow_error_set(error, ENOTSUP,
8726 : : RTE_FLOW_ERROR_TYPE_ACTION,
8727 : : actions,
8728 : : "action not supported");
8729 : 0 : ret = mlx5_flow_validate_action_meter(dev,
8730 : : action_flags,
8731 : : item_flags,
8732 : : actions, attr,
8733 : : port_id_item,
8734 : : &def_policy,
8735 : : error);
8736 [ # # ]: 0 : if (ret < 0)
8737 : 0 : return ret;
8738 : 0 : action_flags |= MLX5_FLOW_ACTION_METER;
8739 [ # # ]: 0 : if (!def_policy)
8740 : 0 : action_flags |=
8741 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
8742 : 0 : ++actions_n;
8743 : : /* Meter action will add one more TAG action. */
8744 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
8745 : 0 : break;
8746 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
8747 [ # # ]: 0 : if (is_root)
8748 : 0 : return rte_flow_error_set(error, ENOTSUP,
8749 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8750 : : NULL,
8751 : : "Shared ASO age action is not supported for group 0");
8752 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_AGE)
8753 : 0 : return rte_flow_error_set
8754 : : (error, EINVAL,
8755 : : RTE_FLOW_ERROR_TYPE_ACTION,
8756 : : NULL,
8757 : : "duplicate age actions set");
8758 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8759 : : aso_after_sample = 1;
8760 : 0 : action_flags |= MLX5_FLOW_ACTION_AGE;
8761 : 0 : ++actions_n;
8762 : 0 : break;
8763 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
8764 : 0 : non_shared_age = actions->conf;
8765 : 0 : ret = flow_dv_validate_action_age(action_flags,
8766 : : actions, dev,
8767 : : error);
8768 [ # # ]: 0 : if (ret < 0)
8769 : 0 : return ret;
8770 : : /*
8771 : : * Validate the regular AGE action (using counter)
8772 : : * mutual exclusion with indirect counter actions.
8773 : : */
8774 [ # # ]: 0 : if (!flow_hit_aso_supported(priv, is_root)) {
8775 [ # # ]: 0 : if (shared_count)
8776 : 0 : return rte_flow_error_set
8777 : : (error, EINVAL,
8778 : : RTE_FLOW_ERROR_TYPE_ACTION,
8779 : : NULL,
8780 : : "old age and indirect count combination is not supported");
8781 [ # # ]: 0 : if (sample_count)
8782 : 0 : return rte_flow_error_set
8783 : : (error, EINVAL,
8784 : : RTE_FLOW_ERROR_TYPE_ACTION,
8785 : : NULL,
8786 : : "old age action and count must be in the same sub flow");
8787 : : } else {
8788 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8789 : : aso_after_sample = 1;
8790 : : }
8791 : 0 : action_flags |= MLX5_FLOW_ACTION_AGE;
8792 : 0 : ++actions_n;
8793 : 0 : break;
8794 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
8795 : 0 : ret = flow_dv_validate_action_modify_ipv4_dscp
8796 : : (action_flags,
8797 : : actions,
8798 : : item_flags,
8799 : : error);
8800 [ # # ]: 0 : if (ret < 0)
8801 : 0 : return ret;
8802 : : /* Count all modify-header actions as one action. */
8803 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8804 : 0 : ++actions_n;
8805 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8806 : : modify_after_mirror = 1;
8807 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
8808 : 0 : rw_act_num += MLX5_ACT_NUM_SET_DSCP;
8809 : 0 : break;
8810 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
8811 : 0 : ret = flow_dv_validate_action_modify_ipv6_dscp
8812 : : (action_flags,
8813 : : actions,
8814 : : item_flags,
8815 : : error);
8816 [ # # ]: 0 : if (ret < 0)
8817 : 0 : return ret;
8818 : : /* Count all modify-header actions as one action. */
8819 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8820 : 0 : ++actions_n;
8821 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8822 : : modify_after_mirror = 1;
8823 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
8824 : 0 : rw_act_num += MLX5_ACT_NUM_SET_DSCP;
8825 : 0 : break;
8826 : 0 : case RTE_FLOW_ACTION_TYPE_SAMPLE:
8827 : 0 : ret = flow_dv_validate_action_sample(&action_flags,
8828 : : &sub_action_flags,
8829 : : actions, dev,
8830 : : attr, item_flags,
8831 : : rss, &sample_rss,
8832 : : &sample_count,
8833 : : &fdb_mirror,
8834 : : &sample_port_id,
8835 : : is_root,
8836 : : error);
8837 [ # # ]: 0 : if (ret < 0)
8838 : 0 : return ret;
8839 [ # # # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_SET_TAG) &&
8840 : 0 : tag_id == 0 &&
8841 [ # # ]: 0 : priv->sh->registers.aso_reg == REG_NON)
8842 : 0 : return rte_flow_error_set(error, EINVAL,
8843 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8844 : : "sample after tag action causes metadata tag index 0 corruption");
8845 : 0 : action_flags |= MLX5_FLOW_ACTION_SAMPLE;
8846 : 0 : ++actions_n;
8847 : 0 : break;
8848 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
8849 : 0 : ret = flow_dv_validate_action_modify_field(dev,
8850 : : action_flags,
8851 : : actions,
8852 : : attr,
8853 : : is_root,
8854 : : error);
8855 [ # # ]: 0 : if (ret < 0)
8856 : 0 : return ret;
8857 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8858 : : modify_after_mirror = 1;
8859 : : /* Count all modify-header actions as one action. */
8860 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8861 : 0 : ++actions_n;
8862 : 0 : action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
8863 : 0 : rw_act_num += ret;
8864 : 0 : break;
8865 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
8866 : 0 : ret = mlx5_flow_dv_validate_action_aso_ct(dev,
8867 : : action_flags,
8868 : : item_flags,
8869 : : is_root,
8870 : : error);
8871 [ # # ]: 0 : if (ret < 0)
8872 : 0 : return ret;
8873 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8874 : : aso_after_sample = 1;
8875 : 0 : action_flags |= MLX5_FLOW_ACTION_CT;
8876 : 0 : break;
8877 : : case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
8878 : : /* tunnel offload action was processed before
8879 : : * list it here as a supported type
8880 : : */
8881 : : break;
8882 : : #ifdef HAVE_MLX5DV_DR_ACTION_CREATE_DEST_ROOT_TABLE
8883 : : case RTE_FLOW_ACTION_TYPE_SEND_TO_KERNEL:
8884 : : action_flags |= MLX5_FLOW_ACTION_SEND_TO_KERNEL;
8885 : : ++actions_n;
8886 : : break;
8887 : : #endif
8888 : 0 : default:
8889 : 0 : return rte_flow_error_set(error, ENOTSUP,
8890 : : RTE_FLOW_ERROR_TYPE_ACTION,
8891 : : actions,
8892 : : "action not supported");
8893 : : }
8894 : : }
8895 : : /*
8896 : : * Validate actions in flow rules
8897 : : * - Explicit decap action is prohibited by the tunnel offload API.
8898 : : * - Drop action in tunnel steer rule is prohibited by the API.
8899 : : * - Application cannot use MARK action because it's value can mask
8900 : : * tunnel default miss notification.
8901 : : * - JUMP in tunnel match rule has no support in current PMD
8902 : : * implementation.
8903 : : * - TAG & META are reserved for future uses.
8904 : : */
8905 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_TUNNEL_SET) {
8906 : : uint64_t bad_actions_mask = MLX5_FLOW_ACTION_DECAP |
8907 : : MLX5_FLOW_ACTION_MARK |
8908 : : MLX5_FLOW_ACTION_SET_TAG |
8909 : : MLX5_FLOW_ACTION_SET_META |
8910 : : MLX5_FLOW_ACTION_DROP;
8911 : :
8912 [ # # ]: 0 : if (action_flags & bad_actions_mask)
8913 : 0 : return rte_flow_error_set
8914 : : (error, EINVAL,
8915 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8916 : : "Invalid RTE action in tunnel "
8917 : : "set decap rule");
8918 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_ACTION_JUMP))
8919 : 0 : return rte_flow_error_set
8920 : : (error, EINVAL,
8921 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8922 : : "tunnel set decap rule must terminate "
8923 : : "with JUMP");
8924 [ # # ]: 0 : if (attr->egress)
8925 : 0 : return rte_flow_error_set
8926 : : (error, EINVAL,
8927 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8928 : : "tunnel flows for ingress and transfer traffic only");
8929 : : }
8930 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_TUNNEL_MATCH) {
8931 : : uint64_t bad_actions_mask = MLX5_FLOW_ACTION_JUMP |
8932 : : MLX5_FLOW_ACTION_MARK |
8933 : : MLX5_FLOW_ACTION_SET_TAG |
8934 : : MLX5_FLOW_ACTION_SET_META;
8935 : :
8936 [ # # ]: 0 : if (action_flags & bad_actions_mask)
8937 : 0 : return rte_flow_error_set
8938 : : (error, EINVAL,
8939 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8940 : : "Invalid RTE action in tunnel "
8941 : : "set match rule");
8942 : : }
8943 : : /*
8944 : : * Validate the drop action mutual exclusion with other actions.
8945 : : * Drop action is mutually-exclusive with any other action, except for
8946 : : * Count/Sample/Age actions.
8947 : : * Drop action compatibility with tunnel offload was already validated.
8948 : : */
8949 [ # # ]: 0 : if (action_flags & (MLX5_FLOW_ACTION_TUNNEL_MATCH |
8950 : : MLX5_FLOW_ACTION_TUNNEL_MATCH));
8951 [ # # ]: 0 : else if ((action_flags & MLX5_FLOW_ACTION_DROP) &&
8952 [ # # ]: 0 : (action_flags & ~(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_DROP_INCLUSIVE_ACTIONS)))
8953 : 0 : return rte_flow_error_set(error, EINVAL,
8954 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8955 : : "Drop action is mutually-exclusive "
8956 : : "with any other action, except for "
8957 : : "Count/Sample/Age action");
8958 : : /* Eswitch has few restrictions on using items and actions */
8959 [ # # ]: 0 : if (attr->transfer) {
8960 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev) &&
8961 [ # # ]: 0 : action_flags & MLX5_FLOW_ACTION_FLAG)
8962 : 0 : return rte_flow_error_set(error, ENOTSUP,
8963 : : RTE_FLOW_ERROR_TYPE_ACTION,
8964 : : NULL,
8965 : : "unsupported action FLAG");
8966 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev) &&
8967 [ # # ]: 0 : action_flags & MLX5_FLOW_ACTION_MARK)
8968 : 0 : return rte_flow_error_set(error, ENOTSUP,
8969 : : RTE_FLOW_ERROR_TYPE_ACTION,
8970 : : NULL,
8971 : : "unsupported action MARK");
8972 [ # # ]: 0 : if (!priv->jump_fdb_rx_en) {
8973 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_QUEUE)
8974 : 0 : return rte_flow_error_set(error, ENOTSUP,
8975 : : RTE_FLOW_ERROR_TYPE_ACTION,
8976 : : NULL,
8977 : : "unsupported action QUEUE");
8978 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_RSS)
8979 : 0 : return rte_flow_error_set(error, ENOTSUP,
8980 : : RTE_FLOW_ERROR_TYPE_ACTION,
8981 : : NULL,
8982 : : "unsupported action RSS");
8983 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
8984 : 0 : return rte_flow_error_set(error, EINVAL,
8985 : : RTE_FLOW_ERROR_TYPE_ACTION,
8986 : : actions,
8987 : : "no fate action is found");
8988 : : }
8989 : : } else {
8990 [ # # # # ]: 0 : if (!(action_flags & MLX5_FLOW_FATE_ACTIONS) && attr->ingress)
8991 : 0 : return rte_flow_error_set(error, EINVAL,
8992 : : RTE_FLOW_ERROR_TYPE_ACTION,
8993 : : actions,
8994 : : "no fate action is found");
8995 : : }
8996 : : /*
8997 : : * Continue validation for Xcap and VLAN actions.
8998 : : * If hairpin is working in explicit TX rule mode, there is no actions
8999 : : * splitting and the validation of hairpin ingress flow should be the
9000 : : * same as other standard flows.
9001 : : */
9002 [ # # ]: 0 : if ((action_flags & (MLX5_FLOW_XCAP_ACTIONS |
9003 [ # # ]: 0 : MLX5_FLOW_VLAN_ACTIONS)) &&
9004 [ # # # # ]: 0 : (queue_index == 0xFFFF || !mlx5_rxq_is_hairpin(dev, queue_index) ||
9005 : 0 : ((conf = mlx5_rxq_get_hairpin_conf(dev, queue_index)) != NULL &&
9006 [ # # ]: 0 : conf->tx_explicit != 0))) {
9007 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
9008 : : MLX5_FLOW_XCAP_ACTIONS)
9009 : 0 : return rte_flow_error_set(error, ENOTSUP,
9010 : : RTE_FLOW_ERROR_TYPE_ACTION,
9011 : : NULL, "encap and decap "
9012 : : "combination aren't supported");
9013 : : /* Push VLAN is not supported in ingress except for NICs newer than CX5. */
9014 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) {
9015 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
9016 : : bool direction_error = false;
9017 : :
9018 [ # # ]: 0 : if (attr->transfer) {
9019 [ # # ]: 0 : bool fdb_tx = flow_source_vport_representor(priv, act_priv);
9020 : 0 : bool is_cx5 = sh->steering_format_version ==
9021 : : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5;
9022 : :
9023 [ # # ]: 0 : if (!fdb_tx && is_cx5)
9024 : : direction_error = true;
9025 [ # # ]: 0 : } else if (attr->ingress) {
9026 : : direction_error = true;
9027 : : }
9028 : : if (direction_error)
9029 : 0 : return rte_flow_error_set(error, ENOTSUP,
9030 : : RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
9031 : : NULL,
9032 : : "push VLAN action not supported "
9033 : : "for ingress");
9034 : : }
9035 [ # # ]: 0 : if (attr->ingress) {
9036 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
9037 : 0 : return rte_flow_error_set
9038 : : (error, ENOTSUP,
9039 : : RTE_FLOW_ERROR_TYPE_ACTION,
9040 : : NULL, "encap is not supported"
9041 : : " for ingress traffic");
9042 [ # # ]: 0 : else if ((action_flags & MLX5_FLOW_VLAN_ACTIONS) ==
9043 : : MLX5_FLOW_VLAN_ACTIONS)
9044 : 0 : return rte_flow_error_set
9045 : : (error, ENOTSUP,
9046 : : RTE_FLOW_ERROR_TYPE_ACTION,
9047 : : NULL, "no support for "
9048 : : "multiple VLAN actions");
9049 : : }
9050 : : }
9051 : : /* Pop VLAN is not supported in egress except for NICs newer than CX5. */
9052 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_POP_VLAN) {
9053 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
9054 : : bool direction_error = false;
9055 : :
9056 [ # # ]: 0 : if (attr->transfer) {
9057 [ # # ]: 0 : bool fdb_tx = flow_source_vport_representor(priv, act_priv);
9058 : 0 : bool is_cx5 = sh->steering_format_version ==
9059 : : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5;
9060 : :
9061 [ # # ]: 0 : if (fdb_tx && is_cx5)
9062 : : direction_error = true;
9063 [ # # ]: 0 : } else if (attr->egress) {
9064 : : direction_error = true;
9065 : : }
9066 : : if (direction_error)
9067 : 0 : return rte_flow_error_set(error, ENOTSUP,
9068 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
9069 : : NULL,
9070 : : "pop vlan action not supported for egress");
9071 : : }
9072 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY) {
9073 [ # # ]: 0 : if ((action_flags & (MLX5_FLOW_FATE_ACTIONS &
9074 [ # # ]: 0 : ~MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)) &&
9075 : : attr->ingress)
9076 : 0 : return rte_flow_error_set
9077 : : (error, ENOTSUP,
9078 : : RTE_FLOW_ERROR_TYPE_ACTION,
9079 : : NULL, "fate action not supported for "
9080 : : "meter with policy");
9081 [ # # ]: 0 : if (attr->egress) {
9082 [ # # ]: 0 : if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
9083 : 0 : return rte_flow_error_set
9084 : : (error, ENOTSUP,
9085 : : RTE_FLOW_ERROR_TYPE_ACTION,
9086 : : NULL, "modify header action in egress "
9087 : : "cannot be done before meter action");
9088 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
9089 : 0 : return rte_flow_error_set
9090 : : (error, ENOTSUP,
9091 : : RTE_FLOW_ERROR_TYPE_ACTION,
9092 : : NULL, "encap action in egress "
9093 : : "cannot be done before meter action");
9094 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
9095 : 0 : return rte_flow_error_set
9096 : : (error, ENOTSUP,
9097 : : RTE_FLOW_ERROR_TYPE_ACTION,
9098 : : NULL, "push vlan action in egress "
9099 : : "cannot be done before meter action");
9100 : : }
9101 : : }
9102 : : /*
9103 : : * Only support one ASO action in a single flow rule.
9104 : : * non-shared AGE + counter will fallback to use HW counter, no ASO hit object.
9105 : : * Group 0 uses HW counter for AGE too even if no counter action.
9106 : : */
9107 [ # # # # ]: 0 : aso_mask = (action_flags & MLX5_FLOW_ACTION_METER && priv->sh->meter_aso_en) << 2 |
9108 [ # # # # : 0 : (action_flags & MLX5_FLOW_ACTION_CT && priv->sh->ct_aso_en) << 1 |
# # ]
9109 : 0 : (action_flags & MLX5_FLOW_ACTION_AGE &&
9110 [ # # ]: 0 : !(non_shared_age && count) &&
9111 [ # # # # : 0 : (attr->group || (attr->transfer && priv->fdb_def_rule)) &&
# # # # ]
9112 [ # # ]: 0 : priv->sh->flow_hit_aso_en);
9113 [ # # ]: 0 : if (rte_popcount64(aso_mask) > 1)
9114 : 0 : return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
9115 : : NULL, "unsupported combining AGE, METER, CT ASO actions in a single rule");
9116 : : /*
9117 : : * Hairpin flow will add one more TAG action in TX implicit mode.
9118 : : * In TX explicit mode, there will be no hairpin flow ID.
9119 : : */
9120 [ # # ]: 0 : if (hairpin > 0)
9121 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
9122 : : /* extra metadata enabled: one more TAG action will be add. */
9123 [ # # ]: 0 : if (dev_conf->dv_flow_en &&
9124 [ # # # # ]: 0 : dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
9125 : 0 : mlx5_flow_ext_mreg_supported(dev))
9126 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
9127 [ # # ]: 0 : if (rw_act_num >
9128 : : flow_dv_modify_hdr_action_max(dev, is_root)) {
9129 : 0 : return rte_flow_error_set(error, ENOTSUP,
9130 : : RTE_FLOW_ERROR_TYPE_ACTION,
9131 : : NULL, "too many header modify"
9132 : : " actions to support");
9133 : : }
9134 [ # # ]: 0 : if (fdb_mirror) {
9135 [ # # # # ]: 0 : if (!priv->sh->cdev->config.hca_attr.reg_c_preserve &&
9136 [ # # ]: 0 : flow_source_vport_representor(priv, act_priv)) {
9137 : : /* Eswitch egress mirror and modify flow has limitation on CX5 */
9138 [ # # ]: 0 : if (modify_after_mirror)
9139 : 0 : return rte_flow_error_set(error, EINVAL,
9140 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9141 : : "sample before modify action is not supported");
9142 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_JUMP)
9143 : 0 : return rte_flow_error_set(error, EINVAL,
9144 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9145 : : "sample and jump action combination is not supported");
9146 : : }
9147 [ # # ]: 0 : if (aso_mask > 0 && aso_after_sample && fdb_mirror)
9148 : 0 : return rte_flow_error_set(error, ENOTSUP,
9149 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9150 : : "sample before ASO action is not supported");
9151 [ # # ]: 0 : if (sub_action_flags & MLX5_FLOW_ACTION_PORT_ID) {
9152 : 0 : port_priv = mlx5_port_to_eswitch_info(sample_port_id, false);
9153 [ # # ]: 0 : if (flow_source_vport_representor(priv, port_priv)) {
9154 [ # # ]: 0 : if (sub_action_flags & MLX5_FLOW_ACTION_ENCAP)
9155 : 0 : return rte_flow_error_set(error, ENOTSUP,
9156 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9157 : : "mirror to rep port with encap is not supported");
9158 : : } else {
9159 [ # # ]: 0 : if (!(sub_action_flags & MLX5_FLOW_ACTION_ENCAP) &&
9160 [ # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_JUMP))
9161 : 0 : return rte_flow_error_set(error, ENOTSUP,
9162 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9163 : : "mirror to wire port without encap is not supported");
9164 : : }
9165 : : }
9166 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_PORT_ID) &&
9167 : : (action_flags & MLX5_FLOW_ACTION_ENCAP)) {
9168 : 0 : port_priv = mlx5_port_to_eswitch_info(port_id, false);
9169 [ # # ]: 0 : if (flow_source_vport_representor(priv, port_priv))
9170 : 0 : return rte_flow_error_set(error, ENOTSUP,
9171 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9172 : : "mirror to rep port with encap is not supported");
9173 : : }
9174 : : }
9175 : : /*
9176 : : * Validation the NIC Egress flow on representor, except implicit
9177 : : * hairpin default egress flow with TX_QUEUE item, other flows not
9178 : : * work due to metadata regC0 mismatch.
9179 : : */
9180 [ # # # # : 0 : if (attr->egress && priv->representor && !(item_flags & MLX5_FLOW_ITEM_SQ))
# # ]
9181 : 0 : return rte_flow_error_set(error, EINVAL,
9182 : : RTE_FLOW_ERROR_TYPE_ITEM,
9183 : : NULL,
9184 : : "NIC egress rules on representors"
9185 : : " is not supported");
9186 : : return 0;
9187 : : }
9188 : :
9189 : : /**
9190 : : * Internal preparation function. Allocates the DV flow size,
9191 : : * this size is constant.
9192 : : *
9193 : : * @param[in] dev
9194 : : * Pointer to the rte_eth_dev structure.
9195 : : * @param[in] attr
9196 : : * Pointer to the flow attributes.
9197 : : * @param[in] items
9198 : : * Pointer to the list of items.
9199 : : * @param[in] actions
9200 : : * Pointer to the list of actions.
9201 : : * @param[out] error
9202 : : * Pointer to the error structure.
9203 : : *
9204 : : * @return
9205 : : * Pointer to mlx5_flow object on success,
9206 : : * otherwise NULL and rte_errno is set.
9207 : : */
9208 : : static struct mlx5_flow *
9209 : 0 : flow_dv_prepare(struct rte_eth_dev *dev,
9210 : : const struct rte_flow_attr *attr __rte_unused,
9211 : : const struct rte_flow_item items[] __rte_unused,
9212 : : const struct rte_flow_action actions[] __rte_unused,
9213 : : struct rte_flow_error *error)
9214 : : {
9215 : 0 : uint32_t handle_idx = 0;
9216 : : struct mlx5_flow *dev_flow;
9217 : : struct mlx5_flow_handle *dev_handle;
9218 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
9219 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
9220 : :
9221 : : MLX5_ASSERT(wks);
9222 : 0 : wks->skip_matcher_reg = 0;
9223 : 0 : wks->policy = NULL;
9224 : 0 : wks->final_policy = NULL;
9225 : 0 : wks->vport_meta_tag = 0;
9226 : : /* In case of corrupting the memory. */
9227 [ # # ]: 0 : if (wks->flow_idx >= MLX5_NUM_MAX_DEV_FLOWS) {
9228 : 0 : rte_flow_error_set(error, ENOSPC,
9229 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9230 : : "not free temporary device flow");
9231 : 0 : return NULL;
9232 : : }
9233 : 0 : dev_handle = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
9234 : : &handle_idx);
9235 [ # # ]: 0 : if (!dev_handle) {
9236 : 0 : rte_flow_error_set(error, ENOMEM,
9237 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9238 : : "not enough memory to create flow handle");
9239 : 0 : return NULL;
9240 : : }
9241 : : MLX5_ASSERT(wks->flow_idx < RTE_DIM(wks->flows));
9242 : 0 : dev_flow = &wks->flows[wks->flow_idx++];
9243 : : memset(dev_flow, 0, sizeof(*dev_flow));
9244 : 0 : dev_flow->handle = dev_handle;
9245 : 0 : dev_flow->handle_idx = handle_idx;
9246 : 0 : dev_flow->dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param);
9247 : 0 : dev_flow->ingress = attr->ingress;
9248 : 0 : dev_flow->dv.transfer = attr->transfer;
9249 : 0 : return dev_flow;
9250 : : }
9251 : :
9252 : : #ifdef RTE_PMD_MLX5_DEBUG
9253 : : /**
9254 : : * Sanity check for match mask and value. Similar to check_valid_spec() in
9255 : : * kernel driver. If unmasked bit is present in value, it returns failure.
9256 : : *
9257 : : * @param match_mask
9258 : : * pointer to match mask buffer.
9259 : : * @param match_value
9260 : : * pointer to match value buffer.
9261 : : *
9262 : : * @return
9263 : : * 0 if valid, -EINVAL otherwise.
9264 : : */
9265 : : static int
9266 : : flow_dv_check_valid_spec(void *match_mask, void *match_value)
9267 : : {
9268 : : uint8_t *m = match_mask;
9269 : : uint8_t *v = match_value;
9270 : : unsigned int i;
9271 : :
9272 : : for (i = 0; i < MLX5_ST_SZ_BYTES(fte_match_param); ++i) {
9273 : : if (v[i] & ~m[i]) {
9274 : : DRV_LOG(ERR,
9275 : : "match_value differs from match_criteria"
9276 : : " %p[%u] != %p[%u]",
9277 : : match_value, i, match_mask, i);
9278 : : return -EINVAL;
9279 : : }
9280 : : }
9281 : : return 0;
9282 : : }
9283 : : #endif
9284 : :
9285 : : /**
9286 : : * Add match of ip_version.
9287 : : *
9288 : : * @param[in] group
9289 : : * Flow group.
9290 : : * @param[in] headers_v
9291 : : * Values header pointer.
9292 : : * @param[in] headers_m
9293 : : * Masks header pointer.
9294 : : * @param[in] ip_version
9295 : : * The IP version to set.
9296 : : */
9297 : : static inline void
9298 : 0 : flow_dv_set_match_ip_version(uint32_t group,
9299 : : void *headers_v,
9300 : : uint32_t key_type,
9301 : : uint8_t ip_version)
9302 : : {
9303 [ # # # # ]: 0 : if (group == 0 && (key_type & MLX5_SET_MATCHER_M))
9304 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version, 0xf);
9305 : : else
9306 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version,
9307 : : ip_version);
9308 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype, 0);
9309 : 0 : }
9310 : :
9311 : : /**
9312 : : * Add Ethernet item to the value.
9313 : : *
9314 : : * @param[in, out] key
9315 : : * Flow matcher value.
9316 : : * @param[in] item
9317 : : * Flow pattern to translate.
9318 : : * @param[in] inner
9319 : : * Item is inner pattern.
9320 : : * @param[in] grpup
9321 : : * Flow matcher group.
9322 : : * @param[in] key_type
9323 : : * Set flow matcher mask or value.
9324 : : */
9325 : : static void
9326 : 0 : flow_dv_translate_item_eth(void *key, const struct rte_flow_item *item,
9327 : : int inner, uint32_t group, uint32_t key_type)
9328 : : {
9329 : 0 : const struct rte_flow_item_eth *eth_vv = item->spec;
9330 : : const struct rte_flow_item_eth *eth_m;
9331 : : const struct rte_flow_item_eth *eth_v;
9332 : 0 : const struct rte_flow_item_eth nic_mask = {
9333 : : .hdr.dst_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
9334 : : .hdr.src_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
9335 : : .hdr.ether_type = RTE_BE16(0xffff),
9336 : : .has_vlan = 0,
9337 : : };
9338 : : void *hdrs_v;
9339 : : char *l24_v;
9340 : : unsigned int i;
9341 : :
9342 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9343 : 0 : return;
9344 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, eth_v, eth_m, &nic_mask);
# # # # ]
9345 [ # # ]: 0 : if (!eth_vv)
9346 : : eth_vv = eth_v;
9347 [ # # ]: 0 : if (inner)
9348 : 0 : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9349 : : else
9350 : : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9351 : : /* The value must be in the range of the mask. */
9352 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, dmac_47_16);
9353 [ # # ]: 0 : for (i = 0; i < sizeof(eth_m->hdr.dst_addr); ++i)
9354 : 0 : l24_v[i] = eth_m->hdr.dst_addr.addr_bytes[i] & eth_v->hdr.dst_addr.addr_bytes[i];
9355 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, smac_47_16);
9356 : : /* The value must be in the range of the mask. */
9357 [ # # ]: 0 : for (i = 0; i < sizeof(eth_m->hdr.dst_addr); ++i)
9358 : 0 : l24_v[i] = eth_m->hdr.src_addr.addr_bytes[i] & eth_v->hdr.src_addr.addr_bytes[i];
9359 : : /*
9360 : : * HW supports match on one Ethertype, the Ethertype following the last
9361 : : * VLAN tag of the packet (see PRM).
9362 : : * Set match on ethertype only if ETH header is not followed by VLAN.
9363 : : * HW is optimized for IPv4/IPv6. In such cases, avoid setting
9364 : : * ethertype, and use ip_version field instead.
9365 : : * eCPRI over Ether layer will use type value 0xAEFE.
9366 : : */
9367 [ # # ]: 0 : if (eth_m->hdr.ether_type == 0xFFFF) {
9368 : 0 : rte_be16_t type = eth_v->hdr.ether_type;
9369 : :
9370 : : /*
9371 : : * When set the matcher mask, refer to the original spec
9372 : : * value.
9373 : : */
9374 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M) {
9375 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
9376 : 0 : type = eth_vv->hdr.ether_type;
9377 : : }
9378 : : /* Set cvlan_tag mask for any single\multi\un-tagged case. */
9379 [ # # # # : 0 : switch (type) {
# ]
9380 : 0 : case RTE_BE16(RTE_ETHER_TYPE_VLAN):
9381 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
9382 : 0 : return;
9383 : 0 : case RTE_BE16(RTE_ETHER_TYPE_QINQ):
9384 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
9385 : 0 : return;
9386 : 0 : case RTE_BE16(RTE_ETHER_TYPE_IPV4):
9387 : 0 : flow_dv_set_match_ip_version(group, hdrs_v, key_type,
9388 : : 4);
9389 : 0 : return;
9390 : 0 : case RTE_BE16(RTE_ETHER_TYPE_IPV6):
9391 : 0 : flow_dv_set_match_ip_version(group, hdrs_v, key_type,
9392 : : 6);
9393 : 0 : return;
9394 : : default:
9395 : : break;
9396 : : }
9397 : : }
9398 : : /*
9399 : : * Only SW steering value should refer to the mask value.
9400 : : * Other cases are using the fake masks, just ignore the mask.
9401 : : */
9402 [ # # # # ]: 0 : if (eth_v->has_vlan && eth_m->has_vlan) {
9403 : : /*
9404 : : * Here, when also has_more_vlan field in VLAN item is
9405 : : * not set, only single-tagged packets will be matched.
9406 : : */
9407 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
9408 [ # # # # ]: 0 : if (key_type != MLX5_SET_MATCHER_HS_M && eth_vv->has_vlan)
9409 : : return;
9410 : : }
9411 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, ethertype);
9412 : 0 : *(uint16_t *)(l24_v) = eth_m->hdr.ether_type & eth_v->hdr.ether_type;
9413 : : }
9414 : :
9415 : : /**
9416 : : * Add VLAN item to the value.
9417 : : *
9418 : : * @param[in, out] key
9419 : : * Flow matcher value.
9420 : : * @param[in] item
9421 : : * Flow pattern to translate.
9422 : : * @param[in] inner
9423 : : * Item is inner pattern.
9424 : : * @param[in] wks
9425 : : * Item workspace.
9426 : : * @param[in] key_type
9427 : : * Set flow matcher mask or value.
9428 : : */
9429 : : static void
9430 : 0 : flow_dv_translate_item_vlan(void *key, const struct rte_flow_item *item,
9431 : : int inner, struct mlx5_dv_matcher_workspace *wks,
9432 : : uint32_t key_type)
9433 : : {
9434 : : const struct rte_flow_item_vlan *vlan_m;
9435 : : const struct rte_flow_item_vlan *vlan_v;
9436 : 0 : const struct rte_flow_item_vlan *vlan_vv = item->spec;
9437 : : void *hdrs_v;
9438 : : uint16_t tci_v;
9439 : :
9440 [ # # ]: 0 : if (inner) {
9441 : 0 : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9442 : : } else {
9443 : : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9444 : : /*
9445 : : * This is workaround, masks are not supported,
9446 : : * and pre-validated.
9447 : : */
9448 [ # # ]: 0 : if (vlan_vv)
9449 [ # # ]: 0 : wks->vlan_tag = rte_be_to_cpu_16(vlan_vv->hdr.vlan_tci) & 0x0fff;
9450 : : }
9451 : : /*
9452 : : * When VLAN item exists in flow, mark packet as tagged,
9453 : : * even if TCI is not specified.
9454 : : */
9455 [ # # # # ]: 0 : if (!MLX5_GET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag))
9456 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
9457 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9458 : : return;
9459 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, vlan_v, vlan_m,
# # # # ]
9460 : : &rte_flow_item_vlan_mask);
9461 [ # # ]: 0 : tci_v = rte_be_to_cpu_16(vlan_m->hdr.vlan_tci & vlan_v->hdr.vlan_tci);
9462 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_vid, tci_v);
9463 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_cfi, tci_v >> 12);
9464 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_prio, tci_v >> 13);
9465 : : /*
9466 : : * HW is optimized for IPv4/IPv6. In such cases, avoid setting
9467 : : * ethertype, and use ip_version field instead.
9468 : : */
9469 [ # # ]: 0 : if (vlan_m->hdr.eth_proto == 0xFFFF) {
9470 : 0 : rte_be16_t inner_type = vlan_v->hdr.eth_proto;
9471 : :
9472 : : /*
9473 : : * When set the matcher mask, refer to the original spec
9474 : : * value.
9475 : : */
9476 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M)
9477 : 0 : inner_type = vlan_vv->hdr.eth_proto;
9478 [ # # # # ]: 0 : switch (inner_type) {
9479 : 0 : case RTE_BE16(RTE_ETHER_TYPE_VLAN):
9480 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
9481 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_V)
9482 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v,
9483 : : cvlan_tag, 0);
9484 : 0 : return;
9485 : 0 : case RTE_BE16(RTE_ETHER_TYPE_IPV4):
9486 : 0 : flow_dv_set_match_ip_version
9487 : : (wks->group, hdrs_v, key_type, 4);
9488 : 0 : return;
9489 : 0 : case RTE_BE16(RTE_ETHER_TYPE_IPV6):
9490 : 0 : flow_dv_set_match_ip_version
9491 : : (wks->group, hdrs_v, key_type, 6);
9492 : 0 : return;
9493 : : default:
9494 : : break;
9495 : : }
9496 : : }
9497 [ # # # # ]: 0 : if (vlan_m->has_more_vlan && vlan_v->has_more_vlan) {
9498 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
9499 : : /* Only one vlan_tag bit can be set. */
9500 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_V)
9501 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 0);
9502 : 0 : return;
9503 : : }
9504 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, ethertype,
9505 : : rte_be_to_cpu_16(vlan_m->hdr.eth_proto & vlan_v->hdr.eth_proto));
9506 : : }
9507 : :
9508 : : /**
9509 : : * Add IPV4 item to the value.
9510 : : *
9511 : : * @param[in, out] key
9512 : : * Flow matcher value.
9513 : : * @param[in] item
9514 : : * Flow pattern to translate.
9515 : : * @param[in] inner
9516 : : * Item is inner pattern.
9517 : : * @param[in] group
9518 : : * The group to insert the rule.
9519 : : * @param[in] key_type
9520 : : * Set flow matcher mask or value.
9521 : : */
9522 : : static void
9523 : 0 : flow_dv_translate_item_ipv4(void *key, const struct rte_flow_item *item,
9524 : : int inner, uint32_t group, uint32_t key_type)
9525 : : {
9526 : : const struct rte_flow_item_ipv4 *ipv4_m;
9527 : : const struct rte_flow_item_ipv4 *ipv4_v;
9528 : 0 : const struct rte_flow_item_ipv4 nic_mask = {
9529 : : .hdr = {
9530 : : .src_addr = RTE_BE32(0xffffffff),
9531 : : .dst_addr = RTE_BE32(0xffffffff),
9532 : : .type_of_service = 0xff,
9533 : : .next_proto_id = 0xff,
9534 : : .time_to_live = 0xff,
9535 : : },
9536 : : };
9537 : : void *headers_v;
9538 : : char *l24_v;
9539 : : uint8_t tos;
9540 : :
9541 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9542 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9543 : 0 : flow_dv_set_match_ip_version(group, headers_v, key_type, 4);
9544 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9545 : 0 : return;
9546 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, ipv4_v, ipv4_m, &nic_mask);
# # # # ]
9547 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
9548 : : dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
9549 : 0 : *(uint32_t *)l24_v = ipv4_m->hdr.dst_addr & ipv4_v->hdr.dst_addr;
9550 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
9551 : : src_ipv4_src_ipv6.ipv4_layout.ipv4);
9552 : 0 : *(uint32_t *)l24_v = ipv4_m->hdr.src_addr & ipv4_v->hdr.src_addr;
9553 : 0 : tos = ipv4_m->hdr.type_of_service & ipv4_v->hdr.type_of_service;
9554 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ipv4_ihl,
9555 : : ipv4_v->hdr.ihl & ipv4_m->hdr.ihl);
9556 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M)
9557 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn,
9558 : : ipv4_v->hdr.type_of_service);
9559 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, tos);
9560 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, tos >> 2);
9561 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
9562 : : ipv4_v->hdr.next_proto_id & ipv4_m->hdr.next_proto_id);
9563 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
9564 : : ipv4_v->hdr.time_to_live & ipv4_m->hdr.time_to_live);
9565 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
9566 : : !!(ipv4_v->hdr.fragment_offset & ipv4_m->hdr.fragment_offset));
9567 : : }
9568 : :
9569 : : /**
9570 : : * Add IPV6 item to the value.
9571 : : *
9572 : : * @param[in, out] key
9573 : : * Flow matcher value.
9574 : : * @param[in] item
9575 : : * Flow pattern to translate.
9576 : : * @param[in] inner
9577 : : * Item is inner pattern.
9578 : : * @param[in] group
9579 : : * The group to insert the rule.
9580 : : * @param[in] key_type
9581 : : * Set flow matcher mask or value.
9582 : : */
9583 : : static void
9584 : 0 : flow_dv_translate_item_ipv6(void *key, const struct rte_flow_item *item,
9585 : : int inner, uint32_t group, uint32_t key_type)
9586 : : {
9587 : : const struct rte_flow_item_ipv6 *ipv6_m;
9588 : : const struct rte_flow_item_ipv6 *ipv6_v;
9589 : 0 : const struct rte_flow_item_ipv6 nic_mask = {
9590 : : .hdr = {
9591 : : .src_addr = RTE_IPV6_MASK_FULL,
9592 : : .dst_addr = RTE_IPV6_MASK_FULL,
9593 : : .vtc_flow = RTE_BE32(0xffffffff),
9594 : : .proto = 0xff,
9595 : : .hop_limits = 0xff,
9596 : : },
9597 : : };
9598 : : void *headers_v;
9599 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9600 : : char *l24_v;
9601 : : uint32_t vtc_v;
9602 : : int i;
9603 : : int size;
9604 : :
9605 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9606 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9607 : 0 : flow_dv_set_match_ip_version(group, headers_v, key_type, 6);
9608 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9609 : 0 : return;
9610 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, ipv6_v, ipv6_m, &nic_mask);
# # # # ]
9611 : : size = sizeof(ipv6_m->hdr.dst_addr);
9612 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
9613 : : dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
9614 [ # # ]: 0 : for (i = 0; i < size; ++i)
9615 : 0 : l24_v[i] = ipv6_m->hdr.dst_addr.a[i] & ipv6_v->hdr.dst_addr.a[i];
9616 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
9617 : : src_ipv4_src_ipv6.ipv6_layout.ipv6);
9618 [ # # ]: 0 : for (i = 0; i < size; ++i)
9619 : 0 : l24_v[i] = ipv6_m->hdr.src_addr.a[i] & ipv6_v->hdr.src_addr.a[i];
9620 : : /* TOS. */
9621 [ # # ]: 0 : vtc_v = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow & ipv6_v->hdr.vtc_flow);
9622 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, vtc_v >> 20);
9623 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, vtc_v >> 22);
9624 : : /* Label. */
9625 [ # # ]: 0 : if (inner)
9626 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, inner_ipv6_flow_label,
9627 : : vtc_v);
9628 : : else
9629 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, outer_ipv6_flow_label,
9630 : : vtc_v);
9631 : : /* Protocol. */
9632 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
9633 : : ipv6_v->hdr.proto & ipv6_m->hdr.proto);
9634 : : /* Hop limit. */
9635 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
9636 : : ipv6_v->hdr.hop_limits & ipv6_m->hdr.hop_limits);
9637 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
9638 : : !!(ipv6_v->has_frag_ext & ipv6_m->has_frag_ext));
9639 : : }
9640 : :
9641 : : /**
9642 : : * Add IPV6 fragment extension item to the value.
9643 : : *
9644 : : * @param[in, out] key
9645 : : * Flow matcher value.
9646 : : * @param[in] item
9647 : : * Flow pattern to translate.
9648 : : * @param[in] inner
9649 : : * Item is inner pattern.
9650 : : * @param[in] key_type
9651 : : * Set flow matcher mask or value.
9652 : : */
9653 : : static void
9654 : 0 : flow_dv_translate_item_ipv6_frag_ext(void *key,
9655 : : const struct rte_flow_item *item,
9656 : : int inner, uint32_t key_type)
9657 : : {
9658 : : const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_m;
9659 : : const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_v;
9660 : 0 : const struct rte_flow_item_ipv6_frag_ext nic_mask = {
9661 : : .hdr = {
9662 : : .next_header = 0xff,
9663 : : .frag_data = RTE_BE16(0xffff),
9664 : : },
9665 : : };
9666 : : void *headers_v;
9667 : :
9668 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9669 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9670 : : /* IPv6 fragment extension item exists, so packet is IP fragment. */
9671 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag, 1);
9672 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9673 : 0 : return;
9674 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, ipv6_frag_ext_v,
# # # # ]
9675 : : ipv6_frag_ext_m, &nic_mask);
9676 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
9677 : : ipv6_frag_ext_v->hdr.next_header &
9678 : : ipv6_frag_ext_m->hdr.next_header);
9679 : : }
9680 : :
9681 : : /**
9682 : : * Add TCP item to the value.
9683 : : *
9684 : : * @param[in, out] key
9685 : : * Flow matcher value.
9686 : : * @param[in] item
9687 : : * Flow pattern to translate.
9688 : : * @param[in] inner
9689 : : * Item is inner pattern.
9690 : : * @param[in] key_type
9691 : : * Set flow matcher mask or value.
9692 : : */
9693 : : static void
9694 : 0 : flow_dv_translate_item_tcp(void *key, const struct rte_flow_item *item,
9695 : : int inner, uint32_t key_type)
9696 : : {
9697 : : const struct rte_flow_item_tcp *tcp_m;
9698 : : const struct rte_flow_item_tcp *tcp_v;
9699 : : void *headers_v;
9700 : :
9701 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9702 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9703 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9704 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9705 : : ip_protocol, 0xff);
9706 : : else
9707 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9708 : : ip_protocol, IPPROTO_TCP);
9709 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9710 : : return;
9711 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, tcp_v, tcp_m,
# # # # ]
9712 : : &rte_flow_item_tcp_mask);
9713 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_sport,
9714 : : rte_be_to_cpu_16(tcp_v->hdr.src_port & tcp_m->hdr.src_port));
9715 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_dport,
9716 : : rte_be_to_cpu_16(tcp_v->hdr.dst_port & tcp_m->hdr.dst_port));
9717 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_flags,
9718 : : tcp_v->hdr.tcp_flags & tcp_m->hdr.tcp_flags);
9719 : : }
9720 : :
9721 : : /**
9722 : : * Add ESP item to the value.
9723 : : *
9724 : : * @param[in, out] key
9725 : : * Flow matcher value.
9726 : : * @param[in] item
9727 : : * Flow pattern to translate.
9728 : : * @param[in] inner
9729 : : * Item is inner pattern.
9730 : : * @param[in] key_type
9731 : : * Set flow matcher mask or value.
9732 : : */
9733 : : static void
9734 : 0 : flow_dv_translate_item_esp(void *key, const struct rte_flow_item *item,
9735 : : int inner, uint32_t key_type, uint64_t item_flags)
9736 : : {
9737 : : const struct rte_flow_item_esp *esp_m;
9738 : : const struct rte_flow_item_esp *esp_v;
9739 : : void *headers_v;
9740 : : char *spi_v;
9741 [ # # ]: 0 : bool over_udp = item_flags & (inner ? MLX5_FLOW_LAYER_INNER_L4_UDP :
9742 : : MLX5_FLOW_LAYER_OUTER_L4_UDP);
9743 : :
9744 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9745 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9746 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
9747 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, 0xff);
9748 [ # # # # : 0 : if (over_udp && !MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport))
# # ]
9749 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, 0xFFFF);
9750 : : } else {
9751 [ # # ]: 0 : if (!over_udp)
9752 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, IPPROTO_ESP);
9753 : : else
9754 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport))
9755 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
9756 : : MLX5_UDP_PORT_ESP);
9757 : : }
9758 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9759 : : return;
9760 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, esp_v, esp_m, &rte_flow_item_esp_mask);
# # # # ]
9761 : : headers_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9762 [ # # ]: 0 : spi_v = inner ? MLX5_ADDR_OF(fte_match_set_misc, headers_v, inner_esp_spi) :
9763 : : MLX5_ADDR_OF(fte_match_set_misc, headers_v, outer_esp_spi);
9764 : 0 : *(uint32_t *)spi_v = esp_m->hdr.spi & esp_v->hdr.spi;
9765 : : }
9766 : :
9767 : : /**
9768 : : * Add UDP item to the value.
9769 : : *
9770 : : * @param[in, out] key
9771 : : * Flow matcher value.
9772 : : * @param[in] item
9773 : : * Flow pattern to translate.
9774 : : * @param[in] inner
9775 : : * Item is inner pattern.
9776 : : * @param[in] key_type
9777 : : * Set flow matcher mask or value.
9778 : : */
9779 : : static void
9780 : 0 : flow_dv_translate_item_udp(void *key, const struct rte_flow_item *item,
9781 : : int inner, struct mlx5_dv_matcher_workspace *wks,
9782 : : uint32_t key_type)
9783 : : {
9784 : : const struct rte_flow_item_udp *udp_m;
9785 : : const struct rte_flow_item_udp *udp_v;
9786 : : void *headers_v;
9787 : :
9788 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9789 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9790 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9791 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9792 : : ip_protocol, 0xff);
9793 : : else
9794 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9795 : : ip_protocol, IPPROTO_UDP);
9796 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9797 : : return;
9798 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, udp_v, udp_m,
# # # # ]
9799 : : &rte_flow_item_udp_mask);
9800 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_sport,
9801 : : rte_be_to_cpu_16(udp_v->hdr.src_port & udp_m->hdr.src_port));
9802 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
9803 : : rte_be_to_cpu_16(udp_v->hdr.dst_port & udp_m->hdr.dst_port));
9804 : : /* Force get UDP dport in case to be used in VXLAN translate. */
9805 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_SW) {
9806 : 0 : udp_v = item->spec;
9807 [ # # ]: 0 : wks->udp_dport = rte_be_to_cpu_16(udp_v->hdr.dst_port &
9808 : : udp_m->hdr.dst_port);
9809 : : }
9810 : : }
9811 : :
9812 : : /**
9813 : : * Add GRE optional Key item to the value.
9814 : : *
9815 : : * @param[in, out] key
9816 : : * Flow matcher value.
9817 : : * @param[in] item
9818 : : * Flow pattern to translate.
9819 : : * @param[in] inner
9820 : : * Item is inner pattern.
9821 : : */
9822 : : static void
9823 : 0 : flow_dv_translate_item_gre_key(void *key, const struct rte_flow_item *item,
9824 : : uint32_t key_type)
9825 : : {
9826 : : const rte_be32_t *key_m;
9827 : : const rte_be32_t *key_v;
9828 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9829 : 0 : rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
9830 : :
9831 : : /* GRE K bit must be on and should already be validated */
9832 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_k_present, 1);
9833 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9834 : 0 : return;
9835 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, key_v, key_m,
# # # # ]
9836 : : &gre_key_default_mask);
9837 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_key_h,
9838 : : rte_be_to_cpu_32((*key_v) & (*key_m)) >> 8);
9839 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_key_l,
9840 : : rte_be_to_cpu_32((*key_v) & (*key_m)) & 0xFF);
9841 : : }
9842 : :
9843 : : /**
9844 : : * Add GRE item to the value.
9845 : : *
9846 : : * @param[in, out] key
9847 : : * Flow matcher value.
9848 : : * @param[in] item
9849 : : * Flow pattern to translate.
9850 : : * @param[in] pattern_flags
9851 : : * Accumulated pattern flags.
9852 : : * @param[in] key_type
9853 : : * Set flow matcher mask or value.
9854 : : */
9855 : : static void
9856 : 0 : flow_dv_translate_item_gre(void *key, const struct rte_flow_item *item,
9857 : : uint64_t pattern_flags, uint32_t key_type)
9858 : : {
9859 : : static const struct rte_flow_item_gre empty_gre = {0,};
9860 : 0 : const struct rte_flow_item_gre *gre_m = item->mask;
9861 : 0 : const struct rte_flow_item_gre *gre_v = item->spec;
9862 : : void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9863 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9864 : : struct {
9865 : : union {
9866 : : __extension__
9867 : : struct {
9868 : : uint16_t version:3;
9869 : : uint16_t rsvd0:9;
9870 : : uint16_t s_present:1;
9871 : : uint16_t k_present:1;
9872 : : uint16_t rsvd_bit1:1;
9873 : : uint16_t c_present:1;
9874 : : };
9875 : : uint16_t value;
9876 : : };
9877 : : } gre_crks_rsvd0_ver_m, gre_crks_rsvd0_ver_v;
9878 : : uint16_t protocol_m, protocol_v;
9879 : :
9880 : : /* Common logic to SWS/HWS */
9881 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9882 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, 0xff);
9883 : : else
9884 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
9885 : : IPPROTO_GRE);
9886 : : /* HWS mask logic only */
9887 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_HS_M) {
9888 [ # # ]: 0 : if (!gre_m)
9889 : : gre_m = &empty_gre;
9890 : : gre_v = gre_m;
9891 [ # # ]: 0 : } else if (!gre_v) {
9892 : : gre_v = &empty_gre;
9893 : : gre_m = &empty_gre;
9894 [ # # ]: 0 : } else if (!gre_m) {
9895 : : gre_m = &rte_flow_item_gre_mask;
9896 : : }
9897 : : /* SWS logic only */
9898 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_SW_M)
9899 : : gre_v = gre_m;
9900 [ # # ]: 0 : gre_crks_rsvd0_ver_m.value = rte_be_to_cpu_16(gre_m->c_rsvd0_ver);
9901 [ # # ]: 0 : gre_crks_rsvd0_ver_v.value = rte_be_to_cpu_16(gre_v->c_rsvd0_ver);
9902 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_c_present,
9903 : : gre_crks_rsvd0_ver_v.c_present &
9904 : : gre_crks_rsvd0_ver_m.c_present);
9905 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_k_present,
9906 : : gre_crks_rsvd0_ver_v.k_present &
9907 : : gre_crks_rsvd0_ver_m.k_present);
9908 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_s_present,
9909 : : gre_crks_rsvd0_ver_v.s_present &
9910 : : gre_crks_rsvd0_ver_m.s_present);
9911 [ # # ]: 0 : protocol_m = rte_be_to_cpu_16(gre_m->protocol);
9912 [ # # ]: 0 : protocol_v = rte_be_to_cpu_16(gre_v->protocol);
9913 [ # # ]: 0 : if (!protocol_m) {
9914 : : /* Force next protocol to prevent matchers duplication */
9915 : : protocol_v = mlx5_translate_tunnel_etypes(pattern_flags);
9916 : : if (protocol_v)
9917 : : protocol_m = 0xFFFF;
9918 : : /* Restore the value to mask in mask case. */
9919 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9920 : : protocol_v = protocol_m;
9921 : : }
9922 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
9923 : : protocol_m & protocol_v);
9924 : 0 : }
9925 : :
9926 : : /**
9927 : : * Add GRE optional items to the value.
9928 : : *
9929 : : * @param[in, out] key
9930 : : * Flow matcher value.
9931 : : * @param[in] item
9932 : : * Flow pattern to translate.
9933 : : * @param[in] gre_item
9934 : : * Pointer to gre_item.
9935 : : * @param[in] pattern_flags
9936 : : * Accumulated pattern flags.
9937 : : * @param[in] key_type
9938 : : * Set flow matcher mask or value.
9939 : : */
9940 : : static void
9941 : 0 : flow_dv_translate_item_gre_option(void *key,
9942 : : const struct rte_flow_item *item,
9943 : : const struct rte_flow_item *gre_item,
9944 : : uint64_t pattern_flags, uint32_t key_type)
9945 : : {
9946 : : void *misc5_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_5);
9947 : 0 : const struct rte_flow_item_gre_opt *option_m = item->mask;
9948 : 0 : const struct rte_flow_item_gre_opt *option_v = item->spec;
9949 : 0 : const struct rte_flow_item_gre *gre_m = gre_item->mask;
9950 : 0 : const struct rte_flow_item_gre *gre_v = gre_item->spec;
9951 : : static const struct rte_flow_item_gre empty_gre = {0};
9952 : : struct rte_flow_item gre_key_item;
9953 : : uint16_t c_rsvd0_ver_m, c_rsvd0_ver_v;
9954 : : uint16_t protocol_m, protocol_v;
9955 : :
9956 : : /*
9957 : : * If only match key field, keep using misc for matching.
9958 : : * If need to match checksum or sequence, using misc5 and do
9959 : : * not need using misc.
9960 : : */
9961 [ # # ]: 0 : if (!(option_m->sequence.sequence ||
9962 [ # # ]: 0 : option_m->checksum_rsvd.checksum)) {
9963 : 0 : flow_dv_translate_item_gre(key, gre_item, pattern_flags, key_type);
9964 : 0 : gre_key_item.spec = &option_v->key.key;
9965 : 0 : gre_key_item.mask = &option_m->key.key;
9966 : 0 : flow_dv_translate_item_gre_key(key, &gre_key_item, key_type);
9967 : 0 : return;
9968 : : }
9969 [ # # ]: 0 : if (!gre_v) {
9970 : : gre_v = &empty_gre;
9971 : : gre_m = &empty_gre;
9972 : : } else {
9973 [ # # ]: 0 : if (!gre_m)
9974 : : gre_m = &rte_flow_item_gre_mask;
9975 : : }
9976 : 0 : protocol_v = gre_v->protocol;
9977 : 0 : protocol_m = gre_m->protocol;
9978 [ # # ]: 0 : if (!protocol_m) {
9979 : : /* Force next protocol to prevent matchers duplication */
9980 : : uint16_t ether_type =
9981 : : mlx5_translate_tunnel_etypes(pattern_flags);
9982 : : if (ether_type) {
9983 [ # # ]: 0 : protocol_v = rte_be_to_cpu_16(ether_type);
9984 : : protocol_m = UINT16_MAX;
9985 : : }
9986 : : }
9987 : 0 : c_rsvd0_ver_v = gre_v->c_rsvd0_ver;
9988 : 0 : c_rsvd0_ver_m = gre_m->c_rsvd0_ver;
9989 [ # # ]: 0 : if (option_m->sequence.sequence) {
9990 : 0 : c_rsvd0_ver_v |= RTE_BE16(0x1000);
9991 : 0 : c_rsvd0_ver_m |= RTE_BE16(0x1000);
9992 : : }
9993 [ # # ]: 0 : if (option_m->key.key) {
9994 : 0 : c_rsvd0_ver_v |= RTE_BE16(0x2000);
9995 : 0 : c_rsvd0_ver_m |= RTE_BE16(0x2000);
9996 : : }
9997 [ # # ]: 0 : if (option_m->checksum_rsvd.checksum) {
9998 : 0 : c_rsvd0_ver_v |= RTE_BE16(0x8000);
9999 : 0 : c_rsvd0_ver_m |= RTE_BE16(0x8000);
10000 : : }
10001 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
10002 : : c_rsvd0_ver_v = c_rsvd0_ver_m;
10003 : : protocol_v = protocol_m;
10004 : : option_v = option_m;
10005 : : }
10006 : : /*
10007 : : * Hardware parses GRE optional field into the fixed location,
10008 : : * do not need to adjust the tunnel dword indices.
10009 : : */
10010 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_0,
10011 : : rte_be_to_cpu_32((c_rsvd0_ver_v | protocol_v << 16) &
10012 : : (c_rsvd0_ver_m | protocol_m << 16)));
10013 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_1,
10014 : : rte_be_to_cpu_32(option_v->checksum_rsvd.checksum &
10015 : : option_m->checksum_rsvd.checksum));
10016 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_2,
10017 : : rte_be_to_cpu_32(option_v->key.key & option_m->key.key));
10018 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_3,
10019 : : rte_be_to_cpu_32(option_v->sequence.sequence &
10020 : : option_m->sequence.sequence));
10021 : : }
10022 : :
10023 : : /**
10024 : : * Add NVGRE item to matcher and to the value.
10025 : : *
10026 : : * @param[in, out] key
10027 : : * Flow matcher value.
10028 : : * @param[in] item
10029 : : * Flow pattern to translate.
10030 : : * @param[in] pattern_flags
10031 : : * Accumulated pattern flags.
10032 : : * @param[in] key_type
10033 : : * Set flow matcher mask or value.
10034 : : */
10035 : : static void
10036 : 0 : flow_dv_translate_item_nvgre(void *key, const struct rte_flow_item *item,
10037 : : unsigned long pattern_flags, uint32_t key_type)
10038 : : {
10039 : : const struct rte_flow_item_nvgre *nvgre_m;
10040 : : const struct rte_flow_item_nvgre *nvgre_v;
10041 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10042 : : const char *tni_flow_id_m;
10043 : : const char *tni_flow_id_v;
10044 : : char *gre_key_v;
10045 : : int size;
10046 : : int i;
10047 : :
10048 : : /* For NVGRE, GRE header fields must be set with defined values. */
10049 : 0 : const struct rte_flow_item_gre gre_spec = {
10050 : : .c_rsvd0_ver = RTE_BE16(0x2000),
10051 : : .protocol = RTE_BE16(RTE_ETHER_TYPE_TEB)
10052 : : };
10053 : 0 : const struct rte_flow_item_gre gre_mask = {
10054 : : .c_rsvd0_ver = RTE_BE16(0xB000),
10055 : : .protocol = RTE_BE16(UINT16_MAX),
10056 : : };
10057 : 0 : const struct rte_flow_item gre_item = {
10058 : : .spec = &gre_spec,
10059 : : .mask = &gre_mask,
10060 : : .last = NULL,
10061 : : };
10062 : 0 : flow_dv_translate_item_gre(key, &gre_item, pattern_flags, key_type);
10063 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10064 : 0 : return;
10065 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, nvgre_v, nvgre_m,
# # # # ]
10066 : : &rte_flow_item_nvgre_mask);
10067 : 0 : tni_flow_id_m = (const char *)nvgre_m->tni;
10068 : 0 : tni_flow_id_v = (const char *)nvgre_v->tni;
10069 : : size = sizeof(nvgre_m->tni) + sizeof(nvgre_m->flow_id);
10070 : 0 : gre_key_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, gre_key_h);
10071 [ # # ]: 0 : for (i = 0; i < size; ++i)
10072 : 0 : gre_key_v[i] = tni_flow_id_m[i] & tni_flow_id_v[i];
10073 : : }
10074 : :
10075 : : /**
10076 : : * Add VXLAN item to the value.
10077 : : *
10078 : : * @param[in] dev
10079 : : * Pointer to the Ethernet device structure.
10080 : : * @param[in] attr
10081 : : * Flow rule attributes.
10082 : : * @param[in, out] key
10083 : : * Flow matcher value.
10084 : : * @param[in] item
10085 : : * Flow pattern to translate.
10086 : : * @param[in] inner
10087 : : * Item is inner pattern.
10088 : : * @param[in] wks
10089 : : * Matcher workspace.
10090 : : * @param[in] key_type
10091 : : * Set flow matcher mask or value.
10092 : : */
10093 : : static void
10094 : 0 : flow_dv_translate_item_vxlan(struct rte_eth_dev *dev,
10095 : : const struct rte_flow_attr *attr,
10096 : : void *key, const struct rte_flow_item *item,
10097 : : int inner, struct mlx5_dv_matcher_workspace *wks,
10098 : : uint32_t key_type)
10099 : : {
10100 : : const struct rte_flow_item_vxlan *vxlan_m;
10101 : : const struct rte_flow_item_vxlan *vxlan_v;
10102 : : void *headers_v;
10103 : : void *misc_v;
10104 : : void *misc5_v;
10105 : : uint32_t tunnel_v;
10106 : : char *vni_v;
10107 : : uint16_t dport;
10108 : : int size;
10109 : : int i;
10110 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10111 : 0 : const struct rte_flow_item_vxlan nic_mask = {
10112 : : .hdr.vni = { 0xff, 0xff, 0xff },
10113 : : .hdr.rsvd1 = 0xff,
10114 : : };
10115 : :
10116 : : misc5_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_5);
10117 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
10118 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10119 [ # # ]: 0 : dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
10120 : : MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
10121 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
10122 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10123 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
10124 : : udp_dport, 0xFFFF);
10125 : : else
10126 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
10127 : : udp_dport, dport);
10128 : : }
10129 : : /*
10130 : : * Read the UDP dport to check if the value satisfies the VXLAN
10131 : : * matching with MISC5 for CX5.
10132 : : */
10133 [ # # ]: 0 : if (wks->udp_dport)
10134 : : dport = wks->udp_dport;
10135 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10136 : 0 : return;
10137 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, vxlan_v, vxlan_m, &nic_mask);
# # # # ]
10138 : : if ((item->mask == &nic_mask) &&
10139 : : ((!attr->group && !(attr->transfer && priv->fdb_def_rule) &&
10140 : : !priv->sh->tunnel_header_0_1) ||
10141 : : ((attr->group || (attr->transfer && priv->fdb_def_rule)) &&
10142 : : !priv->sh->misc5_cap)))
10143 : : vxlan_m = &rte_flow_item_vxlan_mask;
10144 [ # # ]: 0 : if ((priv->sh->steering_format_version ==
10145 [ # # ]: 0 : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5 &&
10146 : 0 : dport != MLX5_UDP_PORT_VXLAN) ||
10147 [ # # # # : 0 : (!attr->group && !(attr->transfer && priv->fdb_def_rule)) ||
# # # # ]
10148 [ # # # # ]: 0 : ((attr->group || (attr->transfer && priv->fdb_def_rule)) &&
10149 [ # # ]: 0 : !priv->sh->misc5_cap)) {
10150 : : misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10151 : : size = sizeof(vxlan_m->hdr.vni);
10152 : 0 : vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, vxlan_vni);
10153 [ # # ]: 0 : for (i = 0; i < size; ++i)
10154 : 0 : vni_v[i] = vxlan_m->hdr.vni[i] & vxlan_v->hdr.vni[i];
10155 : : return;
10156 : : }
10157 : 0 : tunnel_v = (vxlan_v->hdr.vni[0] & vxlan_m->hdr.vni[0]) |
10158 : 0 : (vxlan_v->hdr.vni[1] & vxlan_m->hdr.vni[1]) << 8 |
10159 : 0 : (vxlan_v->hdr.vni[2] & vxlan_m->hdr.vni[2]) << 16;
10160 : 0 : tunnel_v |= (vxlan_v->hdr.rsvd1 & vxlan_m->hdr.rsvd1) << 24;
10161 [ # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_1, RTE_BE32(tunnel_v));
10162 : : }
10163 : :
10164 : : /**
10165 : : * Add VXLAN-GPE item to the value.
10166 : : *
10167 : : * @param[in, out] key
10168 : : * Flow matcher value.
10169 : : * @param[in] item
10170 : : * Flow pattern to translate.
10171 : : * @param[in] pattern_flags
10172 : : * Item pattern flags.
10173 : : * @param[in] key_type
10174 : : * Set flow matcher mask or value.
10175 : : */
10176 : :
10177 : : static void
10178 : 0 : flow_dv_translate_item_vxlan_gpe(void *key, const struct rte_flow_item *item,
10179 : : const uint64_t pattern_flags,
10180 : : uint32_t key_type)
10181 : : {
10182 : : static const struct rte_flow_item_vxlan_gpe dummy_vxlan_gpe_hdr = {{{0}}};
10183 : 0 : const struct rte_flow_item_vxlan_gpe *vxlan_m = item->mask;
10184 : 0 : const struct rte_flow_item_vxlan_gpe *vxlan_v = item->spec;
10185 : : /* The item was validated to be on the outer side */
10186 : : void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10187 : : void *misc_v =
10188 : : MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
10189 : 0 : char *vni_v =
10190 : : MLX5_ADDR_OF(fte_match_set_misc3, misc_v, outer_vxlan_gpe_vni);
10191 : : int i, size = sizeof(vxlan_m->hdr.vni);
10192 : : uint8_t flags_m = 0xff;
10193 : : uint8_t flags_v = 0xc;
10194 : : uint8_t m_protocol, v_protocol;
10195 : :
10196 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
10197 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10198 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
10199 : : 0xFFFF);
10200 : : else
10201 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
10202 : : MLX5_UDP_PORT_VXLAN_GPE);
10203 : : }
10204 [ # # ]: 0 : if (!vxlan_v) {
10205 : : vxlan_v = &dummy_vxlan_gpe_hdr;
10206 : : vxlan_m = &dummy_vxlan_gpe_hdr;
10207 : : } else {
10208 [ # # ]: 0 : if (!vxlan_m)
10209 : : vxlan_m = &rte_flow_item_vxlan_gpe_mask;
10210 : : }
10211 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10212 : : vxlan_v = vxlan_m;
10213 [ # # ]: 0 : else if (key_type == MLX5_SET_MATCHER_HS_V)
10214 : : vxlan_m = vxlan_v;
10215 [ # # ]: 0 : if (vxlan_m->hdr.flags) {
10216 : : flags_m = vxlan_m->hdr.flags;
10217 : 0 : flags_v = vxlan_v->hdr.flags;
10218 : : }
10219 : 0 : m_protocol = vxlan_m->hdr.protocol;
10220 : 0 : v_protocol = vxlan_v->hdr.protocol;
10221 [ # # ]: 0 : if (!m_protocol) {
10222 : : /* Force next protocol to ensure next headers parsing. */
10223 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_NSH)
10224 : : v_protocol = RTE_VXLAN_GPE_TYPE_NSH;
10225 [ # # ]: 0 : else if (pattern_flags & MLX5_FLOW_LAYER_INNER_L2)
10226 : : v_protocol = RTE_VXLAN_GPE_TYPE_ETH;
10227 [ # # ]: 0 : else if (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV4)
10228 : : v_protocol = RTE_VXLAN_GPE_TYPE_IPV4;
10229 [ # # ]: 0 : else if (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV6)
10230 : : v_protocol = RTE_VXLAN_GPE_TYPE_IPV6;
10231 [ # # ]: 0 : if (v_protocol)
10232 : : m_protocol = 0xFF;
10233 : : /* Restore the value to mask in mask case. */
10234 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10235 : : v_protocol = m_protocol;
10236 : : }
10237 : : /*
10238 : : * If only match flags/protocol/vni field, keep using misc3 for matching.
10239 : : * If need to match rsvd0 or rsvd1, using misc5 and do not need using misc3.
10240 : : */
10241 [ # # # # : 0 : if (!(vxlan_m->hdr.rsvd0[0] || vxlan_m->hdr.rsvd0[1] || vxlan_m->hdr.rsvd1)) {
# # ]
10242 [ # # ]: 0 : for (i = 0; i < size; ++i)
10243 : 0 : vni_v[i] = vxlan_m->hdr.vni[i] & vxlan_v->hdr.vni[i];
10244 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc_v, outer_vxlan_gpe_flags,
10245 : : flags_m & flags_v);
10246 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc_v,
10247 : : outer_vxlan_gpe_next_protocol, m_protocol & v_protocol);
10248 : : } else {
10249 : : uint32_t tunnel_v;
10250 : : void *misc5_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_5);
10251 : :
10252 : 0 : tunnel_v = (flags_m & flags_v) << 24 |
10253 : 0 : (vxlan_v->hdr.rsvd0[0] & vxlan_m->hdr.rsvd0[0]) << 16 |
10254 : 0 : (vxlan_v->hdr.rsvd0[1] & vxlan_m->hdr.rsvd0[1]) << 8 |
10255 : 0 : (m_protocol & v_protocol);
10256 [ # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_0, tunnel_v);
10257 : 0 : tunnel_v = (vxlan_v->hdr.vni[0] & vxlan_m->hdr.vni[0]) << 24 |
10258 : 0 : (vxlan_v->hdr.vni[1] & vxlan_m->hdr.vni[1]) << 16 |
10259 : 0 : (vxlan_v->hdr.vni[2] & vxlan_m->hdr.vni[2]) << 8 |
10260 : 0 : (vxlan_v->hdr.rsvd1 & vxlan_m->hdr.rsvd1);
10261 [ # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_1, tunnel_v);
10262 : : }
10263 : 0 : }
10264 : :
10265 : : /**
10266 : : * Add Geneve item to the value.
10267 : : *
10268 : : * @param[in, out] key
10269 : : * Flow matcher value.
10270 : : * @param[in] item
10271 : : * Flow pattern to translate.
10272 : : * @param[in] pattern_flags
10273 : : * Item pattern flags.
10274 : : * @param[in] key_type
10275 : : * Set flow matcher mask or value.
10276 : : */
10277 : :
10278 : : static void
10279 : 0 : flow_dv_translate_item_geneve(void *key, const struct rte_flow_item *item,
10280 : : uint64_t pattern_flags, uint32_t key_type)
10281 : : {
10282 : : static const struct rte_flow_item_geneve empty_geneve = {0,};
10283 : 0 : const struct rte_flow_item_geneve *geneve_m = item->mask;
10284 : 0 : const struct rte_flow_item_geneve *geneve_v = item->spec;
10285 : : /* GENEVE flow item validation allows single tunnel item */
10286 : : void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10287 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10288 : : uint16_t gbhdr_m;
10289 : : uint16_t gbhdr_v;
10290 : 0 : char *vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, geneve_vni);
10291 : : size_t size = sizeof(geneve_m->vni), i;
10292 : : uint16_t protocol_m, protocol_v;
10293 : :
10294 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
10295 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10296 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
10297 : : 0xFFFF);
10298 : : else
10299 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
10300 : : MLX5_UDP_PORT_GENEVE);
10301 : : }
10302 [ # # ]: 0 : if (!geneve_v) {
10303 : : geneve_v = &empty_geneve;
10304 : : geneve_m = &empty_geneve;
10305 : : } else {
10306 [ # # ]: 0 : if (!geneve_m)
10307 : : geneve_m = &rte_flow_item_geneve_mask;
10308 : : }
10309 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10310 : : geneve_v = geneve_m;
10311 [ # # ]: 0 : else if (key_type == MLX5_SET_MATCHER_HS_V)
10312 : : geneve_m = geneve_v;
10313 [ # # ]: 0 : for (i = 0; i < size; ++i)
10314 : 0 : vni_v[i] = geneve_m->vni[i] & geneve_v->vni[i];
10315 [ # # ]: 0 : gbhdr_m = rte_be_to_cpu_16(geneve_m->ver_opt_len_o_c_rsvd0);
10316 [ # # ]: 0 : gbhdr_v = rte_be_to_cpu_16(geneve_v->ver_opt_len_o_c_rsvd0);
10317 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, geneve_oam,
10318 : : MLX5_GENEVE_OAMF_VAL(gbhdr_v) & MLX5_GENEVE_OAMF_VAL(gbhdr_m));
10319 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
10320 : : MLX5_GENEVE_OPTLEN_VAL(gbhdr_v) &
10321 : : MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
10322 [ # # ]: 0 : protocol_m = rte_be_to_cpu_16(geneve_m->protocol);
10323 [ # # ]: 0 : protocol_v = rte_be_to_cpu_16(geneve_v->protocol);
10324 [ # # ]: 0 : if (!protocol_m) {
10325 : : /* Force next protocol to prevent matchers duplication */
10326 : : protocol_v = mlx5_translate_tunnel_etypes(pattern_flags);
10327 : : if (protocol_v)
10328 : : protocol_m = 0xFFFF;
10329 : : /* Restore the value to mask in mask case. */
10330 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10331 : : protocol_v = protocol_m;
10332 : : }
10333 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, geneve_protocol_type,
10334 : : protocol_m & protocol_v);
10335 : 0 : }
10336 : :
10337 : : /**
10338 : : * Create Geneve TLV option resource.
10339 : : *
10340 : : * @param[in, out] dev
10341 : : * Pointer to rte_eth_dev structure.
10342 : : * @param[in] item
10343 : : * Flow pattern to translate.
10344 : : * @param[out] error
10345 : : * pointer to error structure.
10346 : : *
10347 : : * @return
10348 : : * 0 on success otherwise -errno and errno is set.
10349 : : */
10350 : : static int
10351 : 0 : flow_dev_geneve_tlv_option_resource_register(struct rte_eth_dev *dev,
10352 : : const struct rte_flow_item *item,
10353 : : struct rte_flow_error *error)
10354 : : {
10355 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10356 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
10357 : 0 : struct mlx5_geneve_tlv_option_resource *geneve_opt_resource =
10358 : : sh->geneve_tlv_option_resource;
10359 : : struct mlx5_devx_obj *obj;
10360 : 0 : const struct rte_flow_item_geneve_opt *geneve_opt_v = item->spec;
10361 : : int ret = 0;
10362 : :
10363 : : MLX5_ASSERT(sh->config.dv_flow_en == 1);
10364 [ # # ]: 0 : if (!geneve_opt_v)
10365 : : return -1;
10366 : 0 : rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
10367 [ # # ]: 0 : if (geneve_opt_resource != NULL) {
10368 : 0 : if (geneve_opt_resource->option_class ==
10369 : : geneve_opt_v->option_class &&
10370 : : geneve_opt_resource->option_type ==
10371 [ # # ]: 0 : geneve_opt_v->option_type &&
10372 : : geneve_opt_resource->length ==
10373 : : geneve_opt_v->option_len) {
10374 : 0 : rte_atomic_fetch_add_explicit(&geneve_opt_resource->refcnt, 1,
10375 : : rte_memory_order_relaxed);
10376 : : } else {
10377 : 0 : ret = rte_flow_error_set(error, ENOMEM,
10378 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10379 : : "Only one GENEVE TLV option supported");
10380 : 0 : goto exit;
10381 : : }
10382 : : } else {
10383 : 0 : struct mlx5_devx_geneve_tlv_option_attr attr = {
10384 : 0 : .option_class = geneve_opt_v->option_class,
10385 : 0 : .option_type = geneve_opt_v->option_type,
10386 : 0 : .option_data_len = geneve_opt_v->option_len,
10387 : : };
10388 : :
10389 : : /* Create a GENEVE TLV object and resource. */
10390 : 0 : obj = mlx5_devx_cmd_create_geneve_tlv_option(sh->cdev->ctx,
10391 : : &attr);
10392 [ # # ]: 0 : if (!obj) {
10393 : 0 : ret = rte_flow_error_set(error, ENODATA,
10394 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10395 : : "Failed to create GENEVE TLV Devx object");
10396 : 0 : goto exit;
10397 : : }
10398 : 0 : sh->geneve_tlv_option_resource =
10399 : 0 : mlx5_malloc(MLX5_MEM_ZERO,
10400 : : sizeof(*geneve_opt_resource),
10401 : : 0, SOCKET_ID_ANY);
10402 [ # # ]: 0 : if (!sh->geneve_tlv_option_resource) {
10403 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
10404 : 0 : ret = rte_flow_error_set(error, ENOMEM,
10405 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10406 : : "GENEVE TLV object memory allocation failed");
10407 : 0 : goto exit;
10408 : : }
10409 : : geneve_opt_resource = sh->geneve_tlv_option_resource;
10410 : 0 : geneve_opt_resource->obj = obj;
10411 : 0 : geneve_opt_resource->option_class = geneve_opt_v->option_class;
10412 : 0 : geneve_opt_resource->option_type = geneve_opt_v->option_type;
10413 : 0 : geneve_opt_resource->length = geneve_opt_v->option_len;
10414 : 0 : rte_atomic_store_explicit(&geneve_opt_resource->refcnt, 1,
10415 : : rte_memory_order_relaxed);
10416 : : }
10417 : 0 : exit:
10418 : : rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
10419 : 0 : return ret;
10420 : : }
10421 : :
10422 : : /**
10423 : : * Add Geneve TLV option item to value.
10424 : : *
10425 : : * @param[in, out] dev
10426 : : * Pointer to rte_eth_dev structure.
10427 : : * @param[in, out] key
10428 : : * Flow matcher value.
10429 : : * @param[in] item
10430 : : * Flow pattern to translate.
10431 : : * @param[in] key_type
10432 : : * Set flow matcher mask or value.
10433 : : * @param[out] error
10434 : : * Pointer to error structure.
10435 : : */
10436 : : static int
10437 : 0 : flow_dv_translate_item_geneve_opt(struct rte_eth_dev *dev, void *key,
10438 : : const struct rte_flow_item *item,
10439 : : uint32_t key_type,
10440 : : struct rte_flow_error *error)
10441 : : {
10442 : : const struct rte_flow_item_geneve_opt *geneve_opt_m;
10443 : : const struct rte_flow_item_geneve_opt *geneve_opt_v;
10444 : 0 : const struct rte_flow_item_geneve_opt *orig_spec = item->spec;
10445 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
10446 : 0 : rte_be32_t opt_data_key = 0, opt_data_mask = 0;
10447 : : size_t option_byte_len;
10448 : : int ret = 0;
10449 : :
10450 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type) || !orig_spec)
# # # # #
# # # ]
10451 : : return -1;
10452 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, geneve_opt_v, geneve_opt_m,
# # # # ]
10453 : : &rte_flow_item_geneve_opt_mask);
10454 : : /*
10455 : : * Register resource requires item spec for SW steering,
10456 : : * for HW steering resources is registered explicitly by user.
10457 : : */
10458 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_SW_V) {
10459 : 0 : ret = flow_dev_geneve_tlv_option_resource_register(dev, item,
10460 : : error);
10461 [ # # ]: 0 : if (ret) {
10462 : 0 : DRV_LOG(ERR, "Failed to create geneve_tlv_obj");
10463 : 0 : return ret;
10464 : : }
10465 : : }
10466 : : /* Convert the option length from DW to bytes for using memcpy. */
10467 : 0 : option_byte_len = RTE_MIN((size_t)(orig_spec->option_len * 4),
10468 : : sizeof(rte_be32_t));
10469 [ # # ]: 0 : if (geneve_opt_v->data) {
10470 : : memcpy(&opt_data_key, geneve_opt_v->data, option_byte_len);
10471 : 0 : memcpy(&opt_data_mask, geneve_opt_m->data, option_byte_len);
10472 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v,
10473 : : geneve_tlv_option_0_data,
10474 : : rte_be_to_cpu_32(opt_data_key & opt_data_mask));
10475 : : }
10476 : : return ret;
10477 : : }
10478 : :
10479 : : /**
10480 : : * Add MPLS item to the value.
10481 : : *
10482 : : * @param[in, out] key
10483 : : * Flow matcher value.
10484 : : * @param[in] item
10485 : : * Flow pattern to translate.
10486 : : * @param[in] prev_layer
10487 : : * The protocol layer indicated in previous item.
10488 : : * @param[in] inner
10489 : : * Item is inner pattern.
10490 : : * @param[in] key_type
10491 : : * Set flow matcher mask or value.
10492 : : */
10493 : : static void
10494 : 0 : flow_dv_translate_item_mpls(void *key, const struct rte_flow_item *item,
10495 : : uint64_t prev_layer, int inner,
10496 : : uint32_t key_type)
10497 : : {
10498 : : const uint32_t *in_mpls_m;
10499 : : const uint32_t *in_mpls_v;
10500 : : uint32_t *out_mpls_v = 0;
10501 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10502 : 0 : void *misc2_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
10503 : : void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10504 : :
10505 [ # # # ]: 0 : switch (prev_layer) {
10506 : 0 : case MLX5_FLOW_LAYER_OUTER_L4_UDP:
10507 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
10508 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10509 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
10510 : : udp_dport, 0xffff);
10511 : : else
10512 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
10513 : : udp_dport, MLX5_UDP_PORT_MPLS);
10514 : : }
10515 : : break;
10516 : 0 : case MLX5_FLOW_LAYER_GRE:
10517 : : /* Fall-through. */
10518 : : case MLX5_FLOW_LAYER_GRE_KEY:
10519 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_misc, misc_v, gre_protocol)) {
10520 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10521 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v,
10522 : : gre_protocol, 0xffff);
10523 : : else
10524 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v,
10525 : : gre_protocol, RTE_ETHER_TYPE_MPLS);
10526 : : }
10527 : : break;
10528 : : default:
10529 : : break;
10530 : : }
10531 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10532 : : return;
10533 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, in_mpls_v, in_mpls_m,
# # # # ]
10534 : : &rte_flow_item_mpls_mask);
10535 [ # # # ]: 0 : switch (prev_layer) {
10536 : 0 : case MLX5_FLOW_LAYER_OUTER_L4_UDP:
10537 : 0 : out_mpls_v =
10538 : : (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
10539 : : outer_first_mpls_over_udp);
10540 : 0 : break;
10541 : 0 : case MLX5_FLOW_LAYER_GRE:
10542 : 0 : out_mpls_v =
10543 : : (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
10544 : : outer_first_mpls_over_gre);
10545 : 0 : break;
10546 : 0 : default:
10547 : : /* Inner MPLS not over GRE is not supported. */
10548 [ # # ]: 0 : if (!inner)
10549 : : out_mpls_v =
10550 : : (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
10551 : : misc2_v,
10552 : : outer_first_mpls);
10553 : : break;
10554 : : }
10555 : : if (out_mpls_v)
10556 : 0 : *out_mpls_v = *in_mpls_v & *in_mpls_m;
10557 : : }
10558 : :
10559 : : /**
10560 : : * Add metadata register item to matcher
10561 : : *
10562 : : * @param[in, out] key
10563 : : * Flow matcher value.
10564 : : * @param[in] reg_type
10565 : : * Type of device metadata register
10566 : : * @param[in] data
10567 : : * Register data
10568 : : * @param[in] mask
10569 : : * Register mask
10570 : : */
10571 : : static void
10572 : 0 : flow_dv_match_meta_reg(void *key, enum modify_reg reg_type,
10573 : : uint32_t data, uint32_t mask)
10574 : : {
10575 : : void *misc2_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
10576 : : void *misc5_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_5);
10577 : : uint32_t temp;
10578 : :
10579 [ # # ]: 0 : if (!key)
10580 : : return;
10581 : 0 : data &= mask;
10582 [ # # # # : 0 : switch (reg_type) {
# # # # #
# # # # #
# ]
10583 : 0 : case REG_A:
10584 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_a, data);
10585 : 0 : break;
10586 : 0 : case REG_B:
10587 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_b, data);
10588 : 0 : break;
10589 : 0 : case REG_C_0:
10590 : : /*
10591 : : * The metadata register C0 field might be divided into
10592 : : * source vport index and META item value, we should set
10593 : : * this field according to specified mask, not as whole one.
10594 : : */
10595 [ # # ]: 0 : temp = MLX5_GET(fte_match_set_misc2, misc2_v, metadata_reg_c_0);
10596 [ # # ]: 0 : if (mask)
10597 : 0 : temp &= ~mask;
10598 : 0 : temp |= data;
10599 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_0, temp);
10600 : 0 : break;
10601 : 0 : case REG_C_1:
10602 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_1, data);
10603 : 0 : break;
10604 : 0 : case REG_C_2:
10605 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_2, data);
10606 : 0 : break;
10607 : 0 : case REG_C_3:
10608 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_3, data);
10609 : 0 : break;
10610 : 0 : case REG_C_4:
10611 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_4, data);
10612 : 0 : break;
10613 : 0 : case REG_C_5:
10614 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_5, data);
10615 : 0 : break;
10616 : 0 : case REG_C_6:
10617 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_6, data);
10618 : 0 : break;
10619 : 0 : case REG_C_7:
10620 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_7, data);
10621 : 0 : break;
10622 : 0 : case REG_C_8:
10623 [ # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, metadata_reg_c_8, data);
10624 : 0 : break;
10625 : 0 : case REG_C_9:
10626 [ # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, metadata_reg_c_9, data);
10627 : 0 : break;
10628 : 0 : case REG_C_10:
10629 [ # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, metadata_reg_c_10, data);
10630 : 0 : break;
10631 : 0 : case REG_C_11:
10632 [ # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, metadata_reg_c_11, data);
10633 : 0 : break;
10634 : : default:
10635 : : MLX5_ASSERT(false);
10636 : : break;
10637 : : }
10638 : : }
10639 : :
10640 : : /**
10641 : : * Add metadata register item to matcher
10642 : : *
10643 : : * @param[in, out] matcher
10644 : : * Flow matcher.
10645 : : * @param[in, out] key
10646 : : * Flow matcher value.
10647 : : * @param[in] reg_type
10648 : : * Type of device metadata register
10649 : : * @param[in] value
10650 : : * Register value
10651 : : * @param[in] mask
10652 : : * Register mask
10653 : : */
10654 : : static void
10655 : : flow_dv_match_meta_reg_all(void *matcher, void *key, enum modify_reg reg_type,
10656 : : uint32_t data, uint32_t mask)
10657 : : {
10658 : 0 : flow_dv_match_meta_reg(key, reg_type, data, mask);
10659 : 0 : flow_dv_match_meta_reg(matcher, reg_type, mask, mask);
10660 : : }
10661 : :
10662 : : /**
10663 : : * Add MARK item to matcher
10664 : : *
10665 : : * @param[in] dev
10666 : : * The device to configure through.
10667 : : * @param[in, out] key
10668 : : * Flow matcher value.
10669 : : * @param[in] item
10670 : : * Flow pattern to translate.
10671 : : * @param[in] key_type
10672 : : * Set flow matcher mask or value.
10673 : : */
10674 : : static void
10675 : 0 : flow_dv_translate_item_mark(struct rte_eth_dev *dev, void *key,
10676 : : const struct rte_flow_item *item,
10677 : : uint32_t key_type)
10678 : : {
10679 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10680 : : const struct rte_flow_item_mark *mark;
10681 : : uint32_t value;
10682 : : uint32_t mask = 0;
10683 : :
10684 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_SW) {
10685 [ # # ]: 0 : mark = item->mask ? (const void *)item->mask :
10686 : : &rte_flow_item_mark_mask;
10687 : 0 : mask = mark->id;
10688 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M) {
10689 : : value = mask;
10690 : : } else {
10691 : 0 : mark = (const void *)item->spec;
10692 : : MLX5_ASSERT(mark);
10693 : 0 : value = mark->id;
10694 : : }
10695 : : } else {
10696 [ # # ]: 0 : mark = (key_type == MLX5_SET_MATCHER_HS_V) ?
10697 : : (const void *)item->spec : (const void *)item->mask;
10698 : : MLX5_ASSERT(mark);
10699 : 0 : value = mark->id;
10700 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_HS_M)
10701 : : mask = value;
10702 : : }
10703 : 0 : mask &= priv->sh->dv_mark_mask;
10704 : 0 : value &= mask;
10705 [ # # ]: 0 : if (mask) {
10706 : : enum modify_reg reg;
10707 : :
10708 : : /* Get the metadata register index for the mark. */
10709 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, NULL);
10710 : : MLX5_ASSERT(reg > 0);
10711 [ # # ]: 0 : if (reg == REG_C_0) {
10712 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10713 : 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
10714 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
10715 : :
10716 : 0 : mask &= msk_c0;
10717 : 0 : mask <<= shl_c0;
10718 : 0 : value <<= shl_c0;
10719 : : }
10720 : 0 : flow_dv_match_meta_reg(key, reg, value, mask);
10721 : : }
10722 : 0 : }
10723 : :
10724 : : /**
10725 : : * Add META item to matcher
10726 : : *
10727 : : * @param[in] dev
10728 : : * The devich to configure through.
10729 : : * @param[in, out] key
10730 : : * Flow matcher value.
10731 : : * @param[in] attr
10732 : : * Attributes of flow that includes this item.
10733 : : * @param[in] item
10734 : : * Flow pattern to translate.
10735 : : * @param[in] key_type
10736 : : * Set flow matcher mask or value.
10737 : : */
10738 : : static void
10739 : 0 : flow_dv_translate_item_meta(struct rte_eth_dev *dev,
10740 : : void *key,
10741 : : const struct rte_flow_attr *attr,
10742 : : const struct rte_flow_item *item,
10743 : : uint32_t key_type)
10744 : : {
10745 : : const struct rte_flow_item_meta *meta_m;
10746 : : const struct rte_flow_item_meta *meta_v;
10747 : : uint32_t value;
10748 : : uint32_t mask = 0;
10749 : : int reg;
10750 : :
10751 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10752 : : return;
10753 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, meta_v, meta_m,
# # # # ]
10754 : : &rte_flow_item_meta_mask);
10755 : 0 : value = meta_v->data;
10756 : 0 : mask = meta_m->data;
10757 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_HS_M)
10758 : : mask = value;
10759 : : /*
10760 : : * In the current implementation, REG_B cannot be used to match.
10761 : : * Force to use REG_C_1 in HWS root table as other tables.
10762 : : * This map may change.
10763 : : * NIC: modify - REG_B to be present in SW
10764 : : * match - REG_C_1 when copied from FDB, different from SWS
10765 : : * FDB: modify - REG_C_1 in Xmeta mode, REG_NON in legacy mode
10766 : : * match - REG_C_1 in FDB
10767 : : */
10768 [ # # ]: 0 : if (!!(key_type & MLX5_SET_MATCHER_SW))
10769 : 0 : reg = flow_dv_get_metadata_reg(dev, attr, NULL);
10770 : : else
10771 : : reg = flow_hw_get_reg_id(dev, RTE_FLOW_ITEM_TYPE_META, 0);
10772 [ # # ]: 0 : if (reg < 0)
10773 : : return;
10774 : : MLX5_ASSERT(reg != REG_NON);
10775 [ # # ]: 0 : if (reg == REG_C_0) {
10776 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10777 : 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
10778 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
10779 : :
10780 : 0 : mask &= msk_c0;
10781 : 0 : mask <<= shl_c0;
10782 : 0 : value <<= shl_c0;
10783 : : }
10784 : 0 : flow_dv_match_meta_reg(key, reg, value, mask);
10785 : : }
10786 : :
10787 : : /**
10788 : : * Add vport metadata Reg C0 item to matcher
10789 : : *
10790 : : * @param[in, out] key
10791 : : * Flow matcher value.
10792 : : * @param[in] value
10793 : : * Register value
10794 : : * @param[in] mask
10795 : : * Register mask
10796 : : */
10797 : : static void
10798 : : flow_dv_translate_item_meta_vport(void *key, uint32_t value, uint32_t mask)
10799 : : {
10800 : 0 : flow_dv_match_meta_reg(key, REG_C_0, value, mask);
10801 : 0 : }
10802 : :
10803 : : /**
10804 : : * Add tag item to matcher
10805 : : *
10806 : : * @param[in] dev
10807 : : * The devich to configure through.
10808 : : * @param[in, out] key
10809 : : * Flow matcher value.
10810 : : * @param[in] item
10811 : : * Flow pattern to translate.
10812 : : * @param[in] key_type
10813 : : * Set flow matcher mask or value.
10814 : : */
10815 : : static void
10816 : 0 : flow_dv_translate_mlx5_item_tag(struct rte_eth_dev *dev, void *key,
10817 : : const struct rte_flow_item *item,
10818 : : uint32_t key_type)
10819 : : {
10820 : 0 : const struct mlx5_rte_flow_item_tag *tag_v = item->spec;
10821 : 0 : const struct mlx5_rte_flow_item_tag *tag_m = item->mask;
10822 : : uint32_t mask, value;
10823 : :
10824 : : MLX5_ASSERT(tag_v);
10825 : 0 : value = tag_v->data;
10826 [ # # ]: 0 : mask = tag_m ? tag_m->data : UINT32_MAX;
10827 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10828 : : value = mask;
10829 [ # # ]: 0 : if (tag_v->id == REG_C_0) {
10830 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10831 : 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
10832 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
10833 : :
10834 : 0 : mask &= msk_c0;
10835 : 0 : mask <<= shl_c0;
10836 : 0 : value <<= shl_c0;
10837 : : }
10838 : 0 : flow_dv_match_meta_reg(key, tag_v->id, value, mask);
10839 : 0 : }
10840 : :
10841 : : /**
10842 : : * Add TAG item to matcher
10843 : : *
10844 : : * @param[in] dev
10845 : : * The devich to configure through.
10846 : : * @param[in, out] key
10847 : : * Flow matcher value.
10848 : : * @param[in] item
10849 : : * Flow pattern to translate.
10850 : : * @param[in] key_type
10851 : : * Set flow matcher mask or value.
10852 : : *
10853 : : * @return
10854 : : * 0 on success. Negative errno value otherwise.
10855 : : */
10856 : : static int
10857 : 0 : flow_dv_translate_item_tag(struct rte_eth_dev *dev, void *key,
10858 : : const struct rte_flow_item *item,
10859 : : uint32_t key_type)
10860 : : {
10861 : 0 : const struct rte_flow_item_tag *tag_vv = item->spec;
10862 : : const struct rte_flow_item_tag *tag_v;
10863 : : const struct rte_flow_item_tag *tag_m;
10864 : : int reg;
10865 : : uint32_t index;
10866 : :
10867 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10868 : : return 0;
10869 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, tag_v, tag_m,
# # # # ]
10870 : : &rte_flow_item_tag_mask);
10871 : : /* When set mask, the index should be from spec. */
10872 [ # # ]: 0 : index = tag_vv ? tag_vv->index : tag_v->index;
10873 : : /* Get the metadata register index for the tag. */
10874 [ # # ]: 0 : if (!!(key_type & MLX5_SET_MATCHER_SW))
10875 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, index, NULL);
10876 : : else
10877 : : reg = flow_hw_get_reg_id(dev, RTE_FLOW_ITEM_TYPE_TAG, index);
10878 [ # # ]: 0 : if (reg < 0) {
10879 : 0 : DRV_LOG(ERR, "port %u tag index %u does not map to correct register",
10880 : : dev->data->port_id, index);
10881 : 0 : return -EINVAL;
10882 : : }
10883 [ # # ]: 0 : if (reg == REG_NON) {
10884 : 0 : DRV_LOG(ERR, "port %u tag index %u maps to unsupported register",
10885 : : dev->data->port_id, index);
10886 : 0 : return -ENOTSUP;
10887 : : }
10888 : 0 : flow_dv_match_meta_reg(key, (enum modify_reg)reg, tag_v->data, tag_m->data);
10889 : 0 : return 0;
10890 : : }
10891 : :
10892 : : /**
10893 : : * Add source vport match to the specified matcher.
10894 : : *
10895 : : * @param[in, out] key
10896 : : * Flow matcher value.
10897 : : * @param[in] port
10898 : : * Source vport value to match
10899 : : */
10900 : : static void
10901 : : flow_dv_translate_item_source_vport(void *key,
10902 : : int16_t port)
10903 : : {
10904 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10905 : :
10906 [ # # # # : 0 : MLX5_SET(fte_match_set_misc, misc_v, source_port, port);
# # ]
10907 : 0 : }
10908 : :
10909 : : /**
10910 : : * Translate port-id item to eswitch match on port-id.
10911 : : *
10912 : : * @param[in] dev
10913 : : * The devich to configure through.
10914 : : * @param[in, out] key
10915 : : * Flow matcher value.
10916 : : * @param[in] item
10917 : : * Flow pattern to translate.
10918 : : * @param[in] attr
10919 : : * Flow attributes.
10920 : : * @param[in] key_type
10921 : : * Set flow matcher mask or value.
10922 : : *
10923 : : * @return
10924 : : * 0 on success, a negative errno value otherwise.
10925 : : */
10926 : : static int
10927 : 0 : flow_dv_translate_item_port_id(struct rte_eth_dev *dev, void *key,
10928 : : const struct rte_flow_item *item,
10929 : : const struct rte_flow_attr *attr,
10930 : : uint32_t key_type)
10931 : : {
10932 [ # # ]: 0 : const struct rte_flow_item_port_id *pid_m = item ? item->mask : NULL;
10933 [ # # ]: 0 : const struct rte_flow_item_port_id *pid_v = item ? item->spec : NULL;
10934 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
10935 : : struct mlx5_priv *priv;
10936 : : uint16_t mask, id;
10937 : : uint32_t vport_meta;
10938 : :
10939 : : MLX5_ASSERT(wks);
10940 [ # # # # ]: 0 : if (pid_v && pid_v->id == MLX5_PORT_ESW_MGR) {
10941 : 0 : priv = dev->data->dev_private;
10942 [ # # ]: 0 : if (priv->sh->dev_cap.esw_info.regc_mask) {
10943 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
10944 : : vport_meta = priv->sh->dev_cap.esw_info.regc_mask;
10945 : : } else {
10946 : 0 : vport_meta = priv->sh->dev_cap.esw_info.regc_value;
10947 : 0 : wks->vport_meta_tag = vport_meta;
10948 : : }
10949 : : flow_dv_translate_item_meta_vport(key, vport_meta,
10950 : : priv->sh->dev_cap.esw_info.regc_mask);
10951 : : } else {
10952 : 0 : flow_dv_translate_item_source_vport(key,
10953 [ # # ]: 0 : key_type & MLX5_SET_MATCHER_V ?
10954 : 0 : mlx5_flow_get_esw_manager_vport_id(dev) : 0xffff);
10955 : : }
10956 : 0 : return 0;
10957 : : }
10958 [ # # ]: 0 : mask = pid_m ? pid_m->id : 0xffff;
10959 [ # # ]: 0 : id = pid_v ? pid_v->id : dev->data->port_id;
10960 : 0 : priv = mlx5_port_to_eswitch_info(id, item == NULL);
10961 [ # # ]: 0 : if (!priv)
10962 : 0 : return -rte_errno;
10963 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
10964 : : id = mask;
10965 : 0 : vport_meta = priv->vport_meta_mask;
10966 : : } else {
10967 : 0 : id = priv->vport_id;
10968 : 0 : vport_meta = priv->vport_meta_tag;
10969 : 0 : wks->vport_meta_tag = vport_meta;
10970 : : }
10971 : : /*
10972 : : * Translate to vport field or to metadata, depending on mode.
10973 : : * Kernel can use either misc.source_port or half of C0 metadata
10974 : : * register.
10975 : : */
10976 [ # # ]: 0 : if (priv->vport_meta_mask) {
10977 : : /*
10978 : : * Provide the hint for SW steering library
10979 : : * to insert the flow into ingress domain and
10980 : : * save the extra vport match.
10981 : : */
10982 [ # # # # ]: 0 : if (mask == 0xffff && priv->vport_id == 0xffff &&
10983 [ # # # # ]: 0 : priv->pf_bond < 0 && attr->transfer)
10984 [ # # ]: 0 : flow_dv_translate_item_source_vport(key, id);
10985 : : /*
10986 : : * We should always set the vport metadata register,
10987 : : * otherwise the SW steering library can drop
10988 : : * the rule if wire vport metadata value is not zero,
10989 : : * it depends on kernel configuration.
10990 : : */
10991 : 0 : flow_dv_translate_item_meta_vport
10992 : : (key, vport_meta, priv->vport_meta_mask);
10993 : : } else {
10994 [ # # ]: 0 : flow_dv_translate_item_source_vport(key, id);
10995 : : }
10996 : : return 0;
10997 : : }
10998 : :
10999 : : /**
11000 : : * Translate port representor item to eswitch match on port id.
11001 : : *
11002 : : * @param[in] dev
11003 : : * The devich to configure through.
11004 : : * @param[in, out] key
11005 : : * Flow matcher value.
11006 : : * @param[in] key_type
11007 : : * Set flow matcher mask or value.
11008 : : *
11009 : : * @return
11010 : : * 0 on success, a negative errno value otherwise.
11011 : : */
11012 : : static int
11013 : 0 : flow_dv_translate_item_port_representor(struct rte_eth_dev *dev, void *key,
11014 : : uint32_t key_type)
11015 : : {
11016 : 0 : flow_dv_translate_item_source_vport(key,
11017 [ # # ]: 0 : key_type & MLX5_SET_MATCHER_V ?
11018 : 0 : mlx5_flow_get_esw_manager_vport_id(dev) : 0xffff);
11019 : 0 : return 0;
11020 : : }
11021 : :
11022 : : /**
11023 : : * Translate represented port item to eswitch match on port id.
11024 : : *
11025 : : * @param[in] dev
11026 : : * The devich to configure through.
11027 : : * @param[in, out] key
11028 : : * Flow matcher value.
11029 : : * @param[in] item
11030 : : * Flow pattern to translate.
11031 : : * @param[in]
11032 : : * Flow attributes.
11033 : : *
11034 : : * @return
11035 : : * 0 on success, a negative errno value otherwise.
11036 : : */
11037 : : static int
11038 : 0 : flow_dv_translate_item_represented_port(struct rte_eth_dev *dev, void *key,
11039 : : const struct rte_flow_item *item,
11040 : : const struct rte_flow_attr *attr,
11041 : : uint32_t key_type)
11042 : : {
11043 [ # # ]: 0 : const struct rte_flow_item_ethdev *pid_m = item ? item->mask : NULL;
11044 [ # # ]: 0 : const struct rte_flow_item_ethdev *pid_v = item ? item->spec : NULL;
11045 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
11046 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11047 : : uint16_t mask, id;
11048 : : uint32_t vport_meta;
11049 : : bool vport_match = false;
11050 : :
11051 : : MLX5_ASSERT(wks);
11052 : : #ifndef HAVE_IBV_DEVICE_ATTR_ESW_MGR_REG_C0
11053 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
11054 : : vport_match = true;
11055 : : #else
11056 : : if (priv->sh->config.dv_flow_en == 2)
11057 : : vport_match = !!priv->vport_match;
11058 : : #endif
11059 [ # # ]: 0 : if (!pid_m && !pid_v)
11060 : : return 0;
11061 [ # # # # ]: 0 : if (pid_v && pid_v->port_id == UINT16_MAX) {
11062 [ # # # # ]: 0 : if (priv->sh->config.dv_flow_en != 2 || vport_match) {
11063 : 0 : flow_dv_translate_item_source_vport
11064 [ # # ]: 0 : (key, key_type & MLX5_SET_MATCHER_V ?
11065 : 0 : mlx5_flow_get_esw_manager_vport_id(dev) : 0xffff);
11066 : : } else {
11067 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11068 : 0 : vport_meta = priv->sh->dev_cap.esw_info.regc_mask;
11069 : : else
11070 : 0 : vport_meta = priv->sh->dev_cap.esw_info.regc_value;
11071 : 0 : flow_dv_translate_item_meta_vport(key, vport_meta,
11072 : : priv->sh->dev_cap.esw_info.regc_mask);
11073 : : }
11074 : 0 : return 0;
11075 : : }
11076 [ # # ]: 0 : mask = pid_m ? pid_m->port_id : UINT16_MAX;
11077 [ # # ]: 0 : id = pid_v ? pid_v->port_id : dev->data->port_id;
11078 : 0 : priv = mlx5_port_to_eswitch_info(id, item == NULL);
11079 [ # # ]: 0 : if (!priv)
11080 : 0 : return -rte_errno;
11081 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
11082 : : id = mask;
11083 : 0 : vport_meta = priv->vport_meta_mask;
11084 : : } else {
11085 : 0 : id = priv->vport_id;
11086 : 0 : vport_meta = priv->vport_meta_tag;
11087 : 0 : wks->vport_meta_tag = vport_meta;
11088 : : }
11089 : : /*
11090 : : * Translate to vport field or to metadata, depending on mode.
11091 : : * Kernel can use either misc.source_port or half of C0 metadata
11092 : : * register.
11093 : : */
11094 [ # # # # ]: 0 : if (priv->vport_meta_mask && !vport_match) {
11095 : : /*
11096 : : * Provide the hint for SW steering library
11097 : : * to insert the flow into ingress domain and
11098 : : * save the extra vport match.
11099 : : */
11100 [ # # # # ]: 0 : if (mask == UINT16_MAX && priv->vport_id == UINT16_MAX &&
11101 [ # # # # ]: 0 : priv->pf_bond < 0 && attr->transfer &&
11102 [ # # ]: 0 : priv->sh->config.dv_flow_en != 2)
11103 [ # # ]: 0 : flow_dv_translate_item_source_vport(key, id);
11104 : : /*
11105 : : * We should always set the vport metadata register,
11106 : : * otherwise the SW steering library can drop
11107 : : * the rule if wire vport metadata value is not zero,
11108 : : * it depends on kernel configuration.
11109 : : */
11110 : 0 : flow_dv_translate_item_meta_vport(key, vport_meta,
11111 : : priv->vport_meta_mask);
11112 : : } else {
11113 [ # # ]: 0 : flow_dv_translate_item_source_vport(key, id);
11114 : : }
11115 : : return 0;
11116 : : }
11117 : :
11118 : : /**
11119 : : * Translate port-id item to eswitch match on port-id.
11120 : : *
11121 : : * @param[in] dev
11122 : : * The devich to configure through.
11123 : : * @param[in, out] matcher
11124 : : * Flow matcher.
11125 : : * @param[in, out] key
11126 : : * Flow matcher value.
11127 : : * @param[in] item
11128 : : * Flow pattern to translate.
11129 : : * @param[in] attr
11130 : : * Flow attributes.
11131 : : *
11132 : : * @return
11133 : : * 0 on success, a negative errno value otherwise.
11134 : : */
11135 : : static int
11136 : 0 : flow_dv_translate_item_port_id_all(struct rte_eth_dev *dev,
11137 : : void *matcher, void *key,
11138 : : const struct rte_flow_item *item,
11139 : : const struct rte_flow_attr *attr)
11140 : : {
11141 : : int ret;
11142 : :
11143 : 0 : ret = flow_dv_translate_item_port_id
11144 : : (dev, matcher, item, attr, MLX5_SET_MATCHER_SW_M);
11145 [ # # ]: 0 : if (ret)
11146 : : return ret;
11147 : 0 : ret = flow_dv_translate_item_port_id
11148 : : (dev, key, item, attr, MLX5_SET_MATCHER_SW_V);
11149 : 0 : return ret;
11150 : : }
11151 : :
11152 : :
11153 : : /**
11154 : : * Add ICMP6 item to the value.
11155 : : *
11156 : : * @param[in, out] key
11157 : : * Flow matcher value.
11158 : : * @param[in] item
11159 : : * Flow pattern to translate.
11160 : : * @param[in] inner
11161 : : * Item is inner pattern.
11162 : : * @param[in] key_type
11163 : : * Set flow matcher mask or value.
11164 : : */
11165 : : static void
11166 : 0 : flow_dv_translate_item_icmp6(void *key, const struct rte_flow_item *item,
11167 : : int inner, uint32_t key_type)
11168 : : {
11169 : : const struct rte_flow_item_icmp6 *icmp6_m;
11170 : : const struct rte_flow_item_icmp6 *icmp6_v;
11171 : : void *headers_v;
11172 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
11173 : :
11174 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
11175 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11176 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11177 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, 0xFF);
11178 : : else
11179 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
11180 : : IPPROTO_ICMPV6);
11181 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11182 : : return;
11183 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, icmp6_v, icmp6_m,
# # # # ]
11184 : : &rte_flow_item_icmp6_mask);
11185 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type,
11186 : : icmp6_v->type & icmp6_m->type);
11187 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code,
11188 : : icmp6_v->code & icmp6_m->code);
11189 : : }
11190 : :
11191 : : /**
11192 : : * Add ICMP6 echo request/reply item to the value.
11193 : : *
11194 : : * @param[in, out] key
11195 : : * Flow matcher value.
11196 : : * @param[in] item
11197 : : * Flow pattern to translate.
11198 : : * @param[in] inner
11199 : : * Item is inner pattern.
11200 : : * @param[in] key_type
11201 : : * Set flow matcher mask or value.
11202 : : */
11203 : : static void
11204 [ # # ]: 0 : flow_dv_translate_item_icmp6_echo(void *key, const struct rte_flow_item *item,
11205 : : int inner, uint32_t key_type)
11206 : : {
11207 : : const struct rte_flow_item_icmp6_echo *icmp6_m;
11208 : : const struct rte_flow_item_icmp6_echo *icmp6_v;
11209 : : uint32_t icmp6_header_data_m = 0;
11210 : : uint32_t icmp6_header_data_v = 0;
11211 : : void *headers_v;
11212 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
11213 : : uint8_t icmp6_type = 0;
11214 : : struct rte_flow_item_icmp6_echo zero_mask;
11215 : :
11216 : : memset(&zero_mask, 0, sizeof(zero_mask));
11217 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
11218 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11219 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11220 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, 0xFF);
11221 : : else
11222 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
11223 : : IPPROTO_ICMPV6);
11224 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, icmp6_v, icmp6_m, &zero_mask);
# # # # ]
11225 : : /* Set fixed type and code for icmpv6 echo request or reply */
11226 [ # # ]: 0 : icmp6_type = (item->type == RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REQUEST ?
11227 : : RTE_ICMP6_ECHO_REQUEST : RTE_ICMP6_ECHO_REPLY);
11228 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
11229 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type, 0xFF);
11230 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code, 0xFF);
11231 : : } else {
11232 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type, icmp6_type);
11233 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code, 0);
11234 : : }
11235 [ # # ]: 0 : if (icmp6_v == NULL)
11236 : 0 : return;
11237 : : /* Set icmp6 header data (identifier & sequence) accordingly */
11238 : 0 : icmp6_header_data_m =
11239 [ # # ]: 0 : (rte_be_to_cpu_16(icmp6_m->hdr.identifier) << 16) |
11240 [ # # ]: 0 : rte_be_to_cpu_16(icmp6_m->hdr.sequence);
11241 [ # # ]: 0 : if (icmp6_header_data_m) {
11242 : 0 : icmp6_header_data_v =
11243 [ # # ]: 0 : (rte_be_to_cpu_16(icmp6_v->hdr.identifier) << 16) |
11244 [ # # ]: 0 : rte_be_to_cpu_16(icmp6_v->hdr.sequence);
11245 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_header_data,
11246 : : icmp6_header_data_v & icmp6_header_data_m);
11247 : : }
11248 : : }
11249 : :
11250 : : /**
11251 : : * Add ICMP item to the value.
11252 : : *
11253 : : * @param[in, out] key
11254 : : * Flow matcher value.
11255 : : * @param[in] item
11256 : : * Flow pattern to translate.
11257 : : * @param[in] inner
11258 : : * Item is inner pattern.
11259 : : * @param[in] key_type
11260 : : * Set flow matcher mask or value.
11261 : : */
11262 : : static void
11263 : 0 : flow_dv_translate_item_icmp(void *key, const struct rte_flow_item *item,
11264 : : int inner, uint32_t key_type)
11265 : : {
11266 : : const struct rte_flow_item_icmp *icmp_m;
11267 : : const struct rte_flow_item_icmp *icmp_v;
11268 : : uint32_t icmp_header_data_m = 0;
11269 : : uint32_t icmp_header_data_v = 0;
11270 : : void *headers_v;
11271 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
11272 : :
11273 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
11274 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11275 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11276 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11277 : : ip_protocol, 0xFF);
11278 : : else
11279 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11280 : : ip_protocol, IPPROTO_ICMP);
11281 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11282 : : return;
11283 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, icmp_v, icmp_m,
# # # # ]
11284 : : &rte_flow_item_icmp_mask);
11285 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmp_type,
11286 : : icmp_v->hdr.icmp_type & icmp_m->hdr.icmp_type);
11287 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmp_code,
11288 : : icmp_v->hdr.icmp_code & icmp_m->hdr.icmp_code);
11289 [ # # ]: 0 : icmp_header_data_m = rte_be_to_cpu_16(icmp_m->hdr.icmp_seq_nb);
11290 [ # # ]: 0 : icmp_header_data_m |= rte_be_to_cpu_16(icmp_m->hdr.icmp_ident) << 16;
11291 [ # # ]: 0 : if (icmp_header_data_m) {
11292 [ # # ]: 0 : icmp_header_data_v = rte_be_to_cpu_16(icmp_v->hdr.icmp_seq_nb);
11293 : 0 : icmp_header_data_v |=
11294 [ # # ]: 0 : rte_be_to_cpu_16(icmp_v->hdr.icmp_ident) << 16;
11295 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmp_header_data,
11296 : : icmp_header_data_v & icmp_header_data_m);
11297 : : }
11298 : : }
11299 : :
11300 : : /**
11301 : : * Add GTP item to the value.
11302 : : *
11303 : : * @param[in, out] key
11304 : : * Flow matcher value.
11305 : : * @param[in] item
11306 : : * Flow pattern to translate.
11307 : : * @param[in] inner
11308 : : * Item is inner pattern.
11309 : : * @param[in] key_type
11310 : : * Set flow matcher mask or value.
11311 : : */
11312 : : static void
11313 : 0 : flow_dv_translate_item_gtp(void *key, const struct rte_flow_item *item,
11314 : : int inner, uint32_t key_type)
11315 : : {
11316 : : const struct rte_flow_item_gtp *gtp_m;
11317 : : const struct rte_flow_item_gtp *gtp_v;
11318 : : void *headers_v;
11319 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
11320 : : uint16_t dport = RTE_GTPU_UDP_PORT;
11321 : :
11322 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
11323 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11324 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
11325 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11326 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11327 : : udp_dport, 0xFFFF);
11328 : : else
11329 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11330 : : udp_dport, dport);
11331 : : }
11332 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11333 : : return;
11334 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, gtp_v, gtp_m,
# # # # ]
11335 : : &rte_flow_item_gtp_mask);
11336 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags,
11337 : : gtp_v->hdr.gtp_hdr_info & gtp_m->hdr.gtp_hdr_info);
11338 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_type,
11339 : : gtp_v->hdr.msg_type & gtp_m->hdr.msg_type);
11340 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_teid,
11341 : : rte_be_to_cpu_32(gtp_v->hdr.teid & gtp_m->hdr.teid));
11342 : : }
11343 : :
11344 : : /**
11345 : : * Add GTP PSC item to matcher.
11346 : : *
11347 : : * @param[in, out] key
11348 : : * Flow matcher value.
11349 : : * @param[in] item
11350 : : * Flow pattern to translate.
11351 : : * @param[in] key_type
11352 : : * Set flow matcher mask or value.
11353 : : */
11354 : : static int
11355 : 0 : flow_dv_translate_item_gtp_psc(void *key, const struct rte_flow_item *item,
11356 : : uint32_t key_type)
11357 : : {
11358 : : const struct rte_flow_item_gtp_psc *gtp_psc_m;
11359 : : const struct rte_flow_item_gtp_psc *gtp_psc_v;
11360 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
11361 : : union {
11362 : : uint32_t w32;
11363 : : struct {
11364 : : uint16_t seq_num;
11365 : : uint8_t npdu_num;
11366 : : uint8_t next_ext_header_type;
11367 : : };
11368 : : } dw_2;
11369 : : union {
11370 : : uint32_t w32;
11371 : : struct {
11372 : : uint8_t len;
11373 : : uint8_t type_flags;
11374 : : uint8_t qfi;
11375 : : uint8_t reserved;
11376 : : };
11377 : : } dw_0;
11378 : : uint8_t gtp_flags;
11379 : :
11380 : : /* Always set E-flag match on one, regardless of GTP item settings. */
11381 [ # # ]: 0 : gtp_flags = MLX5_GET(fte_match_set_misc3, misc3_v, gtpu_msg_flags);
11382 : 0 : gtp_flags |= MLX5_GTP_EXT_HEADER_FLAG;
11383 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags, gtp_flags);
11384 : : /*Set next extension header type. */
11385 : 0 : dw_2.seq_num = 0;
11386 : 0 : dw_2.npdu_num = 0;
11387 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11388 : 0 : dw_2.next_ext_header_type = 0xff;
11389 : : else
11390 : 0 : dw_2.next_ext_header_type = 0x85;
11391 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_dw_2,
11392 : : rte_cpu_to_be_32(dw_2.w32));
11393 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11394 : : return 0;
11395 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, gtp_psc_v,
# # # # ]
11396 : : gtp_psc_m, &rte_flow_item_gtp_psc_mask);
11397 : 0 : dw_0.w32 = 0;
11398 : 0 : dw_0.type_flags = MLX5_GTP_PDU_TYPE_SHIFT(gtp_psc_v->hdr.type &
11399 : : gtp_psc_m->hdr.type);
11400 : 0 : dw_0.qfi = gtp_psc_v->hdr.qfi & gtp_psc_m->hdr.qfi;
11401 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_first_ext_dw_0,
11402 : : rte_cpu_to_be_32(dw_0.w32));
11403 : 0 : return 0;
11404 : : }
11405 : :
11406 : :
11407 : : static inline void
11408 : : flow_dv_set_ecpri_sample1(void *misc4_v,
11409 : : const struct rte_flow_item_ecpri *ecpri_m,
11410 : : const struct rte_flow_item_ecpri *ecpri_v,
11411 : : uint32_t sample1)
11412 : : {
11413 : : void *dw_v;
11414 : : dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v, prog_sample_field_value_1);
11415 : 0 : *(uint32_t *)dw_v = ecpri_v->hdr.dummy[0] & ecpri_m->hdr.dummy[0];
11416 : : /* Sample#1, to match message body, offset 4. */
11417 : 0 : MLX5_SET(fte_match_set_misc4, misc4_v, prog_sample_field_id_1, sample1);
11418 : 0 : }
11419 : :
11420 : : /**
11421 : : * Add eCPRI item to matcher and to the value.
11422 : : *
11423 : : * @param[in] dev
11424 : : * The devich to configure through.
11425 : : * @param[in, out] key
11426 : : * Flow matcher value.
11427 : : * @param[in] item
11428 : : * Flow pattern to translate.
11429 : : * @param[in] last_item
11430 : : * Last item flags.
11431 : : * @param[in] key_type
11432 : : * Set flow matcher mask or value.
11433 : : */
11434 : : static void
11435 : 0 : flow_dv_translate_item_ecpri(struct rte_eth_dev *dev, void *key,
11436 : : const struct rte_flow_item *item,
11437 : : struct mlx5_dv_matcher_workspace *wks,
11438 : : uint64_t last_item, uint32_t key_type)
11439 : : {
11440 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11441 : : const struct rte_flow_item_ecpri *ecpri_m;
11442 : : const struct rte_flow_item_ecpri *ecpri_v;
11443 : 0 : const struct rte_flow_item_ecpri *ecpri_vv = item->spec;
11444 : : struct rte_ecpri_common_hdr common;
11445 : : void *misc4_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_4);
11446 : : uint32_t *samples;
11447 : : void *dw_v;
11448 : :
11449 : : /*
11450 : : * In case of eCPRI over Ethernet, if EtherType is not specified,
11451 : : * match on eCPRI EtherType implicitly.
11452 : : */
11453 [ # # ]: 0 : if (last_item & MLX5_FLOW_LAYER_OUTER_L2) {
11454 : : void *hdrs_v, *l2v;
11455 : :
11456 : : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11457 : : l2v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, ethertype);
11458 [ # # ]: 0 : if (*(uint16_t *)l2v == 0) {
11459 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11460 : 0 : *(uint16_t *)l2v = UINT16_MAX;
11461 : : else
11462 : 0 : *(uint16_t *)l2v =
11463 : : RTE_BE16(RTE_ETHER_TYPE_ECPRI);
11464 : : }
11465 : : }
11466 : : /* HWS matcher does need a non-empty mask. */
11467 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11468 : 0 : return;
11469 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, ecpri_v, ecpri_m, &rte_flow_item_ecpri_mask);
# # # # ]
11470 : : /*
11471 : : * Maximal four DW samples are supported in a single matching now.
11472 : : * Two are used now for a eCPRI matching:
11473 : : * 1. Type: one byte, mask should be 0x00ff0000 in network order
11474 : : * 2. ID of a message: one or two bytes, mask 0xffff0000 or 0xff000000
11475 : : * if any.
11476 : : * Translation also handles the following cases.
11477 : : * 1. HWS mode may face a case with NULL mask and value all zeros.
11478 : : * 2. Matching all eCPRI packets will be done in ETH / VLAN item.
11479 : : * 3. If type is not masked, then message body will not be masked either, forcefully.
11480 : : */
11481 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_HS_M) {
11482 [ # # ]: 0 : if (!ecpri_m->hdr.common.u32) {
11483 : 0 : *wks->p_root_flags |= MLX5_EMPTY_ECPRI_TYPE_MASK;
11484 : 0 : return;
11485 : : }
11486 : : /* Initialized with 0, this should not hit. */
11487 : 0 : *wks->p_root_flags &= ~MLX5_EMPTY_ECPRI_TYPE_MASK;
11488 : : }
11489 [ # # # # ]: 0 : if (key_type == MLX5_SET_MATCHER_HS_V && (*wks->p_root_flags & MLX5_EMPTY_ECPRI_TYPE_MASK))
11490 : : return;
11491 [ # # # # ]: 0 : if ((key_type & MLX5_SET_MATCHER_SW) && !ecpri_m->hdr.common.u32)
11492 : : return;
11493 : 0 : samples = priv->sh->ecpri_parser.ids;
11494 : : /* Need to take the whole DW as the mask to fill the entry. */
11495 : : dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
11496 : : prog_sample_field_value_0);
11497 : : /* Already big endian (network order) in the header. */
11498 : 0 : *(uint32_t *)dw_v = ecpri_v->hdr.common.u32 & ecpri_m->hdr.common.u32;
11499 : : /* Sample#0, used for matching type, offset 0. */
11500 : : /* It makes no sense to set the sample ID in the mask field. */
11501 [ # # ]: 0 : MLX5_SET(fte_match_set_misc4, misc4_v,
11502 : : prog_sample_field_id_0, samples[0]);
11503 : : /*
11504 : : * Checking if message body part needs to be matched.
11505 : : * Some wildcard rules only matching type field should be supported.
11506 : : */
11507 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_HS_M) {
11508 [ # # ]: 0 : if (!ecpri_m->hdr.dummy[0]) {
11509 : 0 : *wks->p_root_flags |= MLX5_EMPTY_ECPRI_BODY_MASK;
11510 : 0 : return;
11511 : : }
11512 : 0 : *wks->p_root_flags &= ~MLX5_EMPTY_ECPRI_BODY_MASK;
11513 : : }
11514 [ # # # # ]: 0 : if (key_type == MLX5_SET_MATCHER_HS_V && (*wks->p_root_flags & MLX5_EMPTY_ECPRI_BODY_MASK))
11515 : : return;
11516 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_SW) {
11517 [ # # ]: 0 : if (!ecpri_m->hdr.dummy[0])
11518 : : return;
11519 [ # # ]: 0 : common.u32 = rte_be_to_cpu_32(ecpri_vv->hdr.common.u32);
11520 [ # # ]: 0 : } else if (key_type == MLX5_SET_MATCHER_HS_V) {
11521 [ # # ]: 0 : common.u32 = rte_be_to_cpu_32(ecpri_v->hdr.common.u32);
11522 : : }
11523 [ # # ]: 0 : if (key_type != MLX5_SET_MATCHER_HS_M) {
11524 [ # # ]: 0 : switch (common.type) {
11525 : 0 : case RTE_ECPRI_MSG_TYPE_IQ_DATA:
11526 : : case RTE_ECPRI_MSG_TYPE_RTC_CTRL:
11527 : : case RTE_ECPRI_MSG_TYPE_DLY_MSR:
11528 [ # # ]: 0 : flow_dv_set_ecpri_sample1(misc4_v, ecpri_v, ecpri_m, samples[1]);
11529 : : break;
11530 : : default:
11531 : : /* Others, do not match any sample ID. */
11532 : : break;
11533 : : }
11534 : : } else {
11535 : : /* When MLX5_SET_MATCHER_HS_M on root table (default value),
11536 : : * the sample ID and mask should be set, or else prog_sample_field_id_1 will
11537 : : * be zero and a mismatch with the HWS rule.
11538 : : * Empty body mask for a matcher returns directly in the previous lines.
11539 : : */
11540 [ # # ]: 0 : flow_dv_set_ecpri_sample1(misc4_v, ecpri_v, ecpri_m, samples[1]);
11541 : : }
11542 : : }
11543 : :
11544 : : /*
11545 : : * Add connection tracking status item to matcher
11546 : : *
11547 : : * @param[in] dev
11548 : : * The devich to configure through.
11549 : : * @param[in, out] matcher
11550 : : * Flow matcher.
11551 : : * @param[in, out] key
11552 : : * Flow matcher value.
11553 : : * @param[in] item
11554 : : * Flow pattern to translate.
11555 : : */
11556 : : static void
11557 : 0 : flow_dv_translate_item_aso_ct(struct rte_eth_dev *dev,
11558 : : void *matcher, void *key,
11559 : : const struct rte_flow_item *item)
11560 : : {
11561 : : uint32_t reg_value = 0;
11562 : : int reg_id;
11563 : : /* 8LSB 0b 11/0000/11, middle 4 bits are reserved. */
11564 : : uint32_t reg_mask = 0;
11565 : 0 : const struct rte_flow_item_conntrack *spec = item->spec;
11566 : 0 : const struct rte_flow_item_conntrack *mask = item->mask;
11567 : : uint32_t flags;
11568 : : struct rte_flow_error error;
11569 : :
11570 [ # # ]: 0 : if (!mask)
11571 : : mask = &rte_flow_item_conntrack_mask;
11572 [ # # # # ]: 0 : if (!spec || !mask->flags)
11573 : 0 : return;
11574 : 0 : flags = spec->flags & mask->flags;
11575 : : /* The conflict should be checked in the validation. */
11576 : : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_VALID)
11577 : : reg_value |= MLX5_CT_SYNDROME_VALID;
11578 [ # # ]: 0 : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_CHANGED)
11579 : : reg_value |= MLX5_CT_SYNDROME_STATE_CHANGE;
11580 [ # # ]: 0 : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_INVALID)
11581 : 0 : reg_value |= MLX5_CT_SYNDROME_INVALID;
11582 [ # # ]: 0 : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED)
11583 : 0 : reg_value |= MLX5_CT_SYNDROME_TRAP;
11584 [ # # ]: 0 : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD)
11585 : 0 : reg_value |= MLX5_CT_SYNDROME_BAD_PACKET;
11586 [ # # ]: 0 : if (mask->flags & (RTE_FLOW_CONNTRACK_PKT_STATE_VALID |
11587 : : RTE_FLOW_CONNTRACK_PKT_STATE_INVALID |
11588 : : RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED))
11589 : : reg_mask |= 0xc0;
11590 [ # # ]: 0 : if (mask->flags & RTE_FLOW_CONNTRACK_PKT_STATE_CHANGED)
11591 : 0 : reg_mask |= MLX5_CT_SYNDROME_STATE_CHANGE;
11592 [ # # ]: 0 : if (mask->flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD)
11593 : 0 : reg_mask |= MLX5_CT_SYNDROME_BAD_PACKET;
11594 : : /* The REG_C_x value could be saved during startup. */
11595 : 0 : reg_id = mlx5_flow_get_reg_id(dev, MLX5_ASO_CONNTRACK, 0, &error);
11596 [ # # ]: 0 : if (reg_id == REG_NON)
11597 : : return;
11598 : 0 : flow_dv_match_meta_reg_all(matcher, key, (enum modify_reg)reg_id,
11599 : : reg_value, reg_mask);
11600 : : }
11601 : :
11602 : : static void
11603 : 0 : flow_dv_translate_item_flex(struct rte_eth_dev *dev, void *matcher, void *key,
11604 : : const struct rte_flow_item *item,
11605 : : struct mlx5_flow *dev_flow, bool is_inner)
11606 : : {
11607 : 0 : const struct rte_flow_item_flex *spec =
11608 : : (const struct rte_flow_item_flex *)item->spec;
11609 : 0 : int index = mlx5_flex_acquire_index(dev, spec->handle, false);
11610 : :
11611 : : MLX5_ASSERT(index >= 0 && index < (int)(sizeof(uint32_t) * CHAR_BIT));
11612 [ # # ]: 0 : if (index < 0)
11613 : : return;
11614 [ # # ]: 0 : if (!(dev_flow->handle->flex_item & RTE_BIT32(index))) {
11615 : : /* Don't count both inner and outer flex items in one rule. */
11616 : 0 : if (mlx5_flex_acquire_index(dev, spec->handle, true) != index)
11617 : : MLX5_ASSERT(false);
11618 : 0 : dev_flow->handle->flex_item |= (uint8_t)RTE_BIT32(index);
11619 : : }
11620 : 0 : mlx5_flex_flow_translate_item(dev, matcher, key, item, is_inner);
11621 : : }
11622 : :
11623 : : /**
11624 : : * Add METER_COLOR item to matcher
11625 : : *
11626 : : * @param[in] dev
11627 : : * The device to configure through.
11628 : : * @param[in, out] key
11629 : : * Flow matcher value.
11630 : : * @param[in] item
11631 : : * Flow pattern to translate.
11632 : : * @param[in] key_type
11633 : : * Set flow matcher mask or value.
11634 : : */
11635 : : static void
11636 : 0 : flow_dv_translate_item_meter_color(struct rte_eth_dev *dev, void *key,
11637 : : const struct rte_flow_item *item,
11638 : : uint32_t key_type)
11639 : : {
11640 : 0 : const struct rte_flow_item_meter_color *color_m = item->mask;
11641 : 0 : const struct rte_flow_item_meter_color *color_v = item->spec;
11642 : : uint32_t value, mask;
11643 : : int reg = REG_NON;
11644 : :
11645 : : MLX5_ASSERT(color_v);
11646 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11647 : : return;
11648 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, color_v, color_m,
# # # # ]
11649 : : &rte_flow_item_meter_color_mask);
11650 [ # # ]: 0 : value = rte_col_2_mlx5_col(color_v->color);
11651 : : mask = color_m ?
11652 [ # # ]: 0 : color_m->color : (UINT32_C(1) << MLX5_MTR_COLOR_BITS) - 1;
11653 [ # # ]: 0 : if (!!(key_type & MLX5_SET_MATCHER_SW))
11654 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, NULL);
11655 : : else
11656 : : reg = flow_hw_get_reg_id(dev,
11657 : : RTE_FLOW_ITEM_TYPE_METER_COLOR, 0);
11658 [ # # ]: 0 : if (reg == REG_NON)
11659 : : return;
11660 : 0 : flow_dv_match_meta_reg(key, (enum modify_reg)reg, value, mask);
11661 : : }
11662 : :
11663 : : static void
11664 : 0 : flow_dv_translate_item_aggr_affinity(void *key,
11665 : : const struct rte_flow_item *item,
11666 : : uint32_t key_type)
11667 : : {
11668 : : const struct rte_flow_item_aggr_affinity *affinity_v;
11669 : : const struct rte_flow_item_aggr_affinity *affinity_m;
11670 : : void *misc_v;
11671 : :
11672 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, affinity_v, affinity_m,
# # # # ]
11673 : : &rte_flow_item_aggr_affinity_mask);
11674 : : misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
11675 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, lag_rx_port_affinity,
11676 : : affinity_v->affinity & affinity_m->affinity);
11677 : 0 : }
11678 : :
11679 : : static void
11680 : 0 : flow_dv_translate_item_ib_bth(void *key,
11681 : : const struct rte_flow_item *item,
11682 : : int inner, uint32_t key_type)
11683 : : {
11684 : : const struct rte_flow_item_ib_bth *bth_m;
11685 : : const struct rte_flow_item_ib_bth *bth_v;
11686 : : void *headers_v, *misc_v;
11687 : : uint16_t udp_dport;
11688 : : char *qpn_v;
11689 : : int i, size;
11690 : :
11691 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
11692 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11693 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
11694 [ # # ]: 0 : udp_dport = key_type & MLX5_SET_MATCHER_M ?
11695 : : 0xFFFF : MLX5_UDP_PORT_ROCEv2;
11696 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, udp_dport);
11697 : : }
11698 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11699 : : return;
11700 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, bth_v, bth_m, &rte_flow_item_ib_bth_mask);
# # # # ]
11701 : : misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
11702 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, bth_opcode,
11703 : : bth_v->hdr.opcode & bth_m->hdr.opcode);
11704 : 0 : qpn_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, bth_dst_qp);
11705 : : size = sizeof(bth_m->hdr.dst_qp);
11706 [ # # ]: 0 : for (i = 0; i < size; ++i)
11707 : 0 : qpn_v[i] = bth_m->hdr.dst_qp[i] & bth_v->hdr.dst_qp[i];
11708 : : }
11709 : :
11710 : : static uint32_t matcher_zero[MLX5_ST_SZ_DW(fte_match_param)] = { 0 };
11711 : :
11712 : : #define HEADER_IS_ZERO(match_criteria, headers) \
11713 : : !(memcmp(MLX5_ADDR_OF(fte_match_param, match_criteria, headers), \
11714 : : matcher_zero, MLX5_FLD_SZ_BYTES(fte_match_param, headers))) \
11715 : :
11716 : : /**
11717 : : * Calculate flow matcher enable bitmap.
11718 : : *
11719 : : * @param match_criteria
11720 : : * Pointer to flow matcher criteria.
11721 : : *
11722 : : * @return
11723 : : * Bitmap of enabled fields.
11724 : : */
11725 : : static uint8_t
11726 : 0 : flow_dv_matcher_enable(uint32_t *match_criteria)
11727 : : {
11728 : : uint8_t match_criteria_enable;
11729 : :
11730 : : match_criteria_enable =
11731 : 0 : (!HEADER_IS_ZERO(match_criteria, outer_headers)) <<
11732 : : MLX5_MATCH_CRITERIA_ENABLE_OUTER_BIT;
11733 : 0 : match_criteria_enable |=
11734 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters)) <<
11735 : : MLX5_MATCH_CRITERIA_ENABLE_MISC_BIT;
11736 : 0 : match_criteria_enable |=
11737 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, inner_headers)) <<
11738 : : MLX5_MATCH_CRITERIA_ENABLE_INNER_BIT;
11739 : 0 : match_criteria_enable |=
11740 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) <<
11741 : : MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
11742 : 0 : match_criteria_enable |=
11743 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters_3)) <<
11744 : : MLX5_MATCH_CRITERIA_ENABLE_MISC3_BIT;
11745 : 0 : match_criteria_enable |=
11746 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters_4)) <<
11747 : : MLX5_MATCH_CRITERIA_ENABLE_MISC4_BIT;
11748 : 0 : match_criteria_enable |=
11749 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters_5)) <<
11750 : : MLX5_MATCH_CRITERIA_ENABLE_MISC5_BIT;
11751 : 0 : return match_criteria_enable;
11752 : : }
11753 : :
11754 : : static void
11755 : : __flow_dv_adjust_buf_size(size_t *size, uint8_t match_criteria)
11756 : : {
11757 : : /*
11758 : : * Check flow matching criteria first, subtract misc5/4 length if flow
11759 : : * doesn't own misc5/4 parameters. In some old rdma-core releases,
11760 : : * misc5/4 are not supported, and matcher creation failure is expected
11761 : : * w/o subtraction. If misc5 is provided, misc4 must be counted in since
11762 : : * misc5 is right after misc4.
11763 : : */
11764 : 0 : if (!(match_criteria & (1 << MLX5_MATCH_CRITERIA_ENABLE_MISC5_BIT))) {
11765 : 0 : *size = MLX5_ST_SZ_BYTES(fte_match_param) -
11766 : : MLX5_ST_SZ_BYTES(fte_match_set_misc5);
11767 [ # # # # : 0 : if (!(match_criteria & (1 <<
# # # # #
# # # # #
# # # # #
# ]
11768 : : MLX5_MATCH_CRITERIA_ENABLE_MISC4_BIT))) {
11769 : 0 : *size -= MLX5_ST_SZ_BYTES(fte_match_set_misc4);
11770 : : }
11771 : : }
11772 : : }
11773 : :
11774 : : struct mlx5_list_entry *
11775 : 0 : mlx5_flow_matcher_clone_cb(void *tool_ctx __rte_unused,
11776 : : struct mlx5_list_entry *entry, void *cb_ctx)
11777 : : {
11778 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11779 : 0 : struct mlx5_flow_dv_matcher *ref = ctx->data;
11780 : : struct mlx5_flow_dv_matcher *old_resource;
11781 : 0 : struct mlx5_flow_tbl_data_entry *tbl = container_of(ref->tbl,
11782 : : typeof(*tbl), tbl);
11783 : 0 : struct mlx5_flow_dv_matcher *resource = mlx5_malloc(MLX5_MEM_ANY,
11784 : : sizeof(*resource),
11785 : : 0, SOCKET_ID_ANY);
11786 : :
11787 [ # # ]: 0 : if (!resource) {
11788 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
11789 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11790 : : "cannot create matcher");
11791 : 0 : return NULL;
11792 : : }
11793 : : old_resource = container_of(entry, typeof(*old_resource), entry);
11794 : : memcpy(resource, old_resource, sizeof(*resource));
11795 : 0 : resource->tbl = &tbl->tbl;
11796 : 0 : return &resource->entry;
11797 : : }
11798 : :
11799 : : void
11800 : 0 : mlx5_flow_matcher_clone_free_cb(void *tool_ctx __rte_unused,
11801 : : struct mlx5_list_entry *entry)
11802 : : {
11803 : 0 : mlx5_free(entry);
11804 : 0 : }
11805 : :
11806 : : struct mlx5_list_entry *
11807 : 0 : mlx5_flow_dv_tbl_create_cb(void *tool_ctx, void *cb_ctx)
11808 : : {
11809 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11810 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11811 : 0 : struct rte_eth_dev *dev = ctx->dev;
11812 : : struct mlx5_flow_tbl_data_entry *tbl_data;
11813 : 0 : struct mlx5_flow_tbl_tunnel_prm *tt_prm = ctx->data2;
11814 : 0 : struct rte_flow_error *error = ctx->error;
11815 : 0 : union mlx5_flow_tbl_key key = { .v64 = *(uint64_t *)(ctx->data) };
11816 : : struct mlx5_flow_tbl_resource *tbl;
11817 : : void *domain;
11818 : 0 : uint32_t idx = 0;
11819 : : int ret;
11820 : :
11821 : 0 : tbl_data = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_JUMP], &idx);
11822 [ # # ]: 0 : if (!tbl_data) {
11823 : 0 : rte_flow_error_set(error, ENOMEM,
11824 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11825 : : NULL,
11826 : : "cannot allocate flow table data entry");
11827 : 0 : return NULL;
11828 : : }
11829 : 0 : tbl_data->idx = idx;
11830 : 0 : tbl_data->tunnel = tt_prm->tunnel;
11831 : 0 : tbl_data->group_id = tt_prm->group_id;
11832 [ # # ]: 0 : tbl_data->external = !!tt_prm->external;
11833 : 0 : tbl_data->tunnel_offload = is_tunnel_offload_active(dev);
11834 : 0 : tbl_data->is_egress = !!key.is_egress;
11835 : 0 : tbl_data->is_transfer = !!key.is_fdb;
11836 : 0 : tbl_data->dummy = !!key.dummy;
11837 : 0 : tbl_data->level = key.level;
11838 : 0 : tbl_data->id = key.id;
11839 : : tbl = &tbl_data->tbl;
11840 [ # # ]: 0 : if (key.dummy)
11841 : 0 : return &tbl_data->entry;
11842 [ # # ]: 0 : if (key.is_fdb)
11843 : 0 : domain = sh->fdb_domain;
11844 [ # # ]: 0 : else if (key.is_egress)
11845 : 0 : domain = sh->tx_domain;
11846 : : else
11847 : 0 : domain = sh->rx_domain;
11848 : : ret = mlx5_flow_os_create_flow_tbl(domain, key.level, &tbl->obj);
11849 : : if (ret) {
11850 : 0 : rte_flow_error_set(error, ENOMEM,
11851 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11852 : : NULL, "cannot create flow table object");
11853 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
11854 : 0 : return NULL;
11855 : : }
11856 [ # # ]: 0 : if (key.level != 0) {
11857 : : ret = mlx5_flow_os_create_flow_action_dest_flow_tbl
11858 : : (tbl->obj, &tbl_data->jump.action);
11859 : : if (ret) {
11860 : 0 : rte_flow_error_set(error, ENOMEM,
11861 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11862 : : NULL,
11863 : : "cannot create flow jump action");
11864 : 0 : mlx5_flow_os_destroy_flow_tbl(tbl->obj);
11865 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
11866 : 0 : return NULL;
11867 : : }
11868 : : }
11869 [ # # # # ]: 0 : MKSTR(matcher_name, "%s_%s_%u_%u_matcher_list",
11870 : : key.is_fdb ? "FDB" : "NIC", key.is_egress ? "egress" : "ingress",
11871 : : key.level, key.id);
11872 : 0 : tbl_data->matchers = mlx5_list_create(matcher_name, sh, true,
11873 : : mlx5_flow_matcher_create_cb,
11874 : : mlx5_flow_matcher_match_cb,
11875 : : mlx5_flow_matcher_remove_cb,
11876 : : mlx5_flow_matcher_clone_cb,
11877 : : mlx5_flow_matcher_clone_free_cb);
11878 [ # # ]: 0 : if (!tbl_data->matchers) {
11879 : 0 : rte_flow_error_set(error, ENOMEM,
11880 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11881 : : NULL,
11882 : : "cannot create tbl matcher list");
11883 : 0 : mlx5_flow_os_destroy_flow_action(tbl_data->jump.action);
11884 : 0 : mlx5_flow_os_destroy_flow_tbl(tbl->obj);
11885 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
11886 : 0 : return NULL;
11887 : : }
11888 : 0 : return &tbl_data->entry;
11889 : : }
11890 : :
11891 : : int
11892 : 0 : mlx5_flow_dv_tbl_match_cb(void *tool_ctx __rte_unused, struct mlx5_list_entry *entry,
11893 : : void *cb_ctx)
11894 : : {
11895 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11896 : : struct mlx5_flow_tbl_data_entry *tbl_data =
11897 : : container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
11898 : 0 : union mlx5_flow_tbl_key key = { .v64 = *(uint64_t *)(ctx->data) };
11899 : :
11900 : 0 : return tbl_data->level != key.level ||
11901 [ # # ]: 0 : tbl_data->id != key.id ||
11902 [ # # ]: 0 : tbl_data->dummy != key.dummy ||
11903 [ # # # # ]: 0 : tbl_data->is_transfer != !!key.is_fdb ||
11904 [ # # ]: 0 : tbl_data->is_egress != !!key.is_egress;
11905 : : }
11906 : :
11907 : : struct mlx5_list_entry *
11908 : 0 : mlx5_flow_dv_tbl_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
11909 : : void *cb_ctx)
11910 : : {
11911 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11912 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11913 : : struct mlx5_flow_tbl_data_entry *tbl_data;
11914 : 0 : struct rte_flow_error *error = ctx->error;
11915 : 0 : uint32_t idx = 0;
11916 : : struct mlx5_flow_tbl_data_entry *old_resource;
11917 : :
11918 : 0 : tbl_data = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_JUMP], &idx);
11919 [ # # ]: 0 : if (!tbl_data) {
11920 : 0 : rte_flow_error_set(error, ENOMEM,
11921 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11922 : : NULL,
11923 : : "cannot allocate flow table data entry");
11924 : 0 : return NULL;
11925 : : }
11926 : : old_resource = container_of(oentry, typeof(*old_resource), entry);
11927 : : memcpy(tbl_data, old_resource, sizeof(*tbl_data));
11928 : 0 : tbl_data->idx = idx;
11929 : 0 : return &tbl_data->entry;
11930 : : }
11931 : :
11932 : : void
11933 : 0 : mlx5_flow_dv_tbl_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
11934 : : {
11935 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11936 : : struct mlx5_flow_tbl_data_entry *tbl_data =
11937 : : container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
11938 : :
11939 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], tbl_data->idx);
11940 : 0 : }
11941 : :
11942 : : /**
11943 : : * Get a flow table.
11944 : : *
11945 : : * @param[in, out] dev
11946 : : * Pointer to rte_eth_dev structure.
11947 : : * @param[in] table_level
11948 : : * Table level to use.
11949 : : * @param[in] egress
11950 : : * Direction of the table.
11951 : : * @param[in] transfer
11952 : : * E-Switch or NIC flow.
11953 : : * @param[in] dummy
11954 : : * Dummy entry for dv API.
11955 : : * @param[in] table_id
11956 : : * Table id to use.
11957 : : * @param[out] error
11958 : : * pointer to error structure.
11959 : : *
11960 : : * @return
11961 : : * Returns tables resource based on the index, NULL in case of failed.
11962 : : */
11963 : : struct mlx5_flow_tbl_resource *
11964 : 0 : mlx5_flow_dv_tbl_resource_get(struct rte_eth_dev *dev,
11965 : : uint32_t table_level, uint8_t egress,
11966 : : uint8_t transfer,
11967 : : bool external,
11968 : : const struct mlx5_flow_tunnel *tunnel,
11969 : : uint32_t group_id, uint8_t dummy,
11970 : : uint32_t table_id,
11971 : : struct rte_flow_error *error)
11972 : : {
11973 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11974 : 0 : union mlx5_flow_tbl_key table_key = {
11975 : : {
11976 : : .level = table_level,
11977 : : .id = table_id,
11978 : : .reserved = 0,
11979 : 0 : .dummy = !!dummy,
11980 : 0 : .is_fdb = !!transfer,
11981 : 0 : .is_egress = !!egress,
11982 : : }
11983 : : };
11984 : 0 : struct mlx5_flow_tbl_tunnel_prm tt_prm = {
11985 : : .tunnel = tunnel,
11986 : : .group_id = group_id,
11987 : : .external = external,
11988 : : };
11989 : 0 : struct mlx5_flow_cb_ctx ctx = {
11990 : : .dev = dev,
11991 : : .error = error,
11992 : : .data = &table_key.v64,
11993 : : .data2 = &tt_prm,
11994 : : };
11995 : : struct mlx5_list_entry *entry;
11996 : : struct mlx5_flow_tbl_data_entry *tbl_data;
11997 : :
11998 : 0 : entry = mlx5_hlist_register(priv->sh->flow_tbls, table_key.v64, &ctx);
11999 [ # # ]: 0 : if (!entry) {
12000 : 0 : rte_flow_error_set(error, ENOMEM,
12001 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12002 : : "cannot get table");
12003 : 0 : return NULL;
12004 : : }
12005 [ # # ]: 0 : DRV_LOG(DEBUG, "table_level %u table_id %u "
12006 : : "tunnel %u group %u registered.",
12007 : : table_level, table_id,
12008 : : tunnel ? tunnel->tunnel_id : 0, group_id);
12009 : : tbl_data = container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
12010 : 0 : return &tbl_data->tbl;
12011 : : }
12012 : :
12013 : : void
12014 : 0 : mlx5_flow_dv_tbl_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
12015 : : {
12016 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
12017 : : struct mlx5_flow_tbl_data_entry *tbl_data =
12018 : : container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
12019 : :
12020 : : MLX5_ASSERT(entry && sh);
12021 [ # # ]: 0 : if (tbl_data->jump.action)
12022 : : mlx5_flow_os_destroy_flow_action(tbl_data->jump.action);
12023 [ # # ]: 0 : if (tbl_data->tbl.obj)
12024 : : mlx5_flow_os_destroy_flow_tbl(tbl_data->tbl.obj);
12025 [ # # ]: 0 : if (tbl_data->tunnel_offload && tbl_data->external) {
12026 : : struct mlx5_list_entry *he;
12027 : : struct mlx5_hlist *tunnel_grp_hash;
12028 : 0 : struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
12029 : 0 : union tunnel_tbl_key tunnel_key = {
12030 : 0 : .tunnel_id = tbl_data->tunnel ?
12031 [ # # ]: 0 : tbl_data->tunnel->tunnel_id : 0,
12032 : 0 : .group = tbl_data->group_id
12033 : : };
12034 : 0 : uint32_t table_level = tbl_data->level;
12035 : 0 : struct mlx5_flow_cb_ctx ctx = {
12036 : : .data = (void *)&tunnel_key.val,
12037 : : };
12038 : :
12039 : : tunnel_grp_hash = tbl_data->tunnel ?
12040 [ # # ]: 0 : tbl_data->tunnel->groups :
12041 : : thub->groups;
12042 : 0 : he = mlx5_hlist_lookup(tunnel_grp_hash, tunnel_key.val, &ctx);
12043 [ # # ]: 0 : if (he)
12044 : 0 : mlx5_hlist_unregister(tunnel_grp_hash, he);
12045 [ # # ]: 0 : DRV_LOG(DEBUG,
12046 : : "table_level %u id %u tunnel %u group %u released.",
12047 : : table_level,
12048 : : tbl_data->id,
12049 : : tbl_data->tunnel ?
12050 : : tbl_data->tunnel->tunnel_id : 0,
12051 : : tbl_data->group_id);
12052 : : }
12053 [ # # ]: 0 : if (tbl_data->matchers)
12054 : 0 : mlx5_list_destroy(tbl_data->matchers);
12055 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], tbl_data->idx);
12056 : 0 : }
12057 : :
12058 : : /**
12059 : : * Release a flow table.
12060 : : *
12061 : : * @param[in] sh
12062 : : * Pointer to device shared structure.
12063 : : * @param[in] tbl
12064 : : * Table resource to be released.
12065 : : *
12066 : : * @return
12067 : : * Returns 0 if table was released, else return 1;
12068 : : */
12069 : : int
12070 : 0 : mlx5_flow_dv_tbl_resource_release(struct mlx5_dev_ctx_shared *sh,
12071 : : struct mlx5_flow_tbl_resource *tbl)
12072 : : {
12073 : : struct mlx5_flow_tbl_data_entry *tbl_data =
12074 : 0 : container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
12075 : :
12076 [ # # ]: 0 : if (!tbl)
12077 : : return 0;
12078 : 0 : return mlx5_hlist_unregister(sh->flow_tbls, &tbl_data->entry);
12079 : : }
12080 : :
12081 : : int
12082 : 0 : mlx5_flow_matcher_match_cb(void *tool_ctx __rte_unused,
12083 : : struct mlx5_list_entry *entry, void *cb_ctx)
12084 : : {
12085 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12086 : 0 : struct mlx5_flow_dv_matcher *ref = ctx->data;
12087 : : struct mlx5_flow_dv_matcher *cur = container_of(entry, typeof(*cur),
12088 : : entry);
12089 : :
12090 : 0 : return cur->crc != ref->crc ||
12091 [ # # ]: 0 : cur->priority != ref->priority ||
12092 : 0 : memcmp((const void *)cur->mask.buf,
12093 [ # # ]: 0 : (const void *)ref->mask.buf, ref->mask.size);
12094 : : }
12095 : :
12096 : : struct mlx5_list_entry *
12097 : 0 : mlx5_flow_matcher_create_cb(void *tool_ctx, void *cb_ctx)
12098 : : {
12099 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
12100 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12101 : 0 : struct mlx5_flow_dv_matcher *ref = ctx->data;
12102 : : struct mlx5_flow_dv_matcher *resource;
12103 : : #ifdef HAVE_MLX5_HWS_SUPPORT
12104 : : const struct rte_flow_item *items;
12105 : : #endif
12106 : 0 : struct mlx5dv_flow_matcher_attr dv_attr = {
12107 : : .type = IBV_FLOW_ATTR_NORMAL,
12108 : 0 : .match_mask = (void *)&ref->mask,
12109 : : };
12110 : : struct mlx5_flow_tbl_data_entry *tbl;
12111 : : int ret;
12112 : :
12113 : 0 : resource = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*resource), 0,
12114 : : SOCKET_ID_ANY);
12115 [ # # ]: 0 : if (!resource) {
12116 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12117 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12118 : : "cannot create matcher");
12119 : 0 : return NULL;
12120 : : }
12121 : 0 : *resource = *ref;
12122 [ # # ]: 0 : if (sh->config.dv_flow_en != 2) {
12123 : 0 : tbl = container_of(ref->tbl, typeof(*tbl), tbl);
12124 : 0 : dv_attr.match_criteria_enable =
12125 [ # # ]: 0 : flow_dv_matcher_enable(resource->mask.buf);
12126 : : __flow_dv_adjust_buf_size(&ref->mask.size,
12127 : : dv_attr.match_criteria_enable);
12128 : 0 : dv_attr.priority = ref->priority;
12129 [ # # ]: 0 : if (tbl->is_egress)
12130 : 0 : dv_attr.flags |= IBV_FLOW_ATTR_FLAGS_EGRESS;
12131 : 0 : ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
12132 : : tbl->tbl.obj,
12133 : : &resource->matcher_object);
12134 : : if (ret) {
12135 : 0 : mlx5_free(resource);
12136 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12137 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12138 : : "cannot create matcher");
12139 : 0 : return NULL;
12140 : : }
12141 : : } else {
12142 : : #ifdef HAVE_MLX5_HWS_SUPPORT
12143 : 0 : items = *((const struct rte_flow_item **)(ctx->data2));
12144 [ # # ]: 0 : if (!items)
12145 : 0 : goto error;
12146 : 0 : resource->matcher_object = mlx5dr_bwc_matcher_create
12147 : 0 : (resource->group->tbl, resource->priority, items);
12148 [ # # ]: 0 : if (!resource->matcher_object)
12149 : 0 : goto error;
12150 : : #else
12151 : : goto error;
12152 : : #endif
12153 : : }
12154 : 0 : return &resource->entry;
12155 : 0 : error:
12156 : 0 : mlx5_free(resource);
12157 : 0 : return NULL;
12158 : : }
12159 : :
12160 : : /**
12161 : : * Register the flow matcher.
12162 : : *
12163 : : * @param[in, out] dev
12164 : : * Pointer to rte_eth_dev structure.
12165 : : * @param[in, out] matcher
12166 : : * Pointer to flow matcher.
12167 : : * @param[in, out] key
12168 : : * Pointer to flow table key.
12169 : : * @parm[in, out] dev_flow
12170 : : * Pointer to the dev_flow.
12171 : : * @param[out] error
12172 : : * pointer to error structure.
12173 : : *
12174 : : * @return
12175 : : * 0 on success otherwise -errno and errno is set.
12176 : : */
12177 : : static int
12178 : 0 : flow_dv_matcher_register(struct rte_eth_dev *dev,
12179 : : struct mlx5_flow_dv_matcher *ref,
12180 : : union mlx5_flow_tbl_key *key,
12181 : : struct mlx5_flow *dev_flow,
12182 : : const struct mlx5_flow_tunnel *tunnel,
12183 : : uint32_t group_id,
12184 : : struct rte_flow_error *error)
12185 : : {
12186 : : struct mlx5_list_entry *entry;
12187 : : struct mlx5_flow_dv_matcher *resource;
12188 : : struct mlx5_flow_tbl_resource *tbl;
12189 : : struct mlx5_flow_tbl_data_entry *tbl_data;
12190 : 0 : struct mlx5_flow_cb_ctx ctx = {
12191 : : .error = error,
12192 : : .data = ref,
12193 : : };
12194 : : /**
12195 : : * tunnel offload API requires this registration for cases when
12196 : : * tunnel match rule was inserted before tunnel set rule.
12197 : : */
12198 : 0 : tbl = mlx5_flow_dv_tbl_resource_get(dev, key->level,
12199 : 0 : key->is_egress, key->is_fdb,
12200 : 0 : dev_flow->external, tunnel,
12201 : 0 : group_id, 0, key->id, error);
12202 [ # # ]: 0 : if (!tbl)
12203 : 0 : return -rte_errno; /* No need to refill the error info */
12204 : 0 : tbl_data = container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
12205 : 0 : ref->tbl = tbl;
12206 : 0 : entry = mlx5_list_register(tbl_data->matchers, &ctx);
12207 [ # # ]: 0 : if (!entry) {
12208 : 0 : mlx5_flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
12209 : 0 : return rte_flow_error_set(error, ENOMEM,
12210 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12211 : : "cannot allocate ref memory");
12212 : : }
12213 : : resource = container_of(entry, typeof(*resource), entry);
12214 : 0 : dev_flow->handle->dvh.matcher = resource;
12215 : 0 : return 0;
12216 : : }
12217 : :
12218 : : struct mlx5_list_entry *
12219 : 0 : mlx5_flow_dv_tag_create_cb(void *tool_ctx, void *cb_ctx)
12220 : : {
12221 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
12222 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12223 : : struct mlx5_flow_dv_tag_resource *entry;
12224 : 0 : uint32_t idx = 0;
12225 : : int ret;
12226 : :
12227 : 0 : entry = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_TAG], &idx);
12228 [ # # ]: 0 : if (!entry) {
12229 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12230 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12231 : : "cannot allocate resource memory");
12232 : 0 : return NULL;
12233 : : }
12234 : 0 : entry->idx = idx;
12235 : 0 : entry->tag_id = *(uint32_t *)(ctx->data);
12236 : : ret = mlx5_flow_os_create_flow_action_tag(entry->tag_id,
12237 : : &entry->action);
12238 : : if (ret) {
12239 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], idx);
12240 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12241 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12242 : : NULL, "cannot create action");
12243 : 0 : return NULL;
12244 : : }
12245 : 0 : return &entry->entry;
12246 : : }
12247 : :
12248 : : int
12249 : 0 : mlx5_flow_dv_tag_match_cb(void *tool_ctx __rte_unused, struct mlx5_list_entry *entry,
12250 : : void *cb_ctx)
12251 : : {
12252 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12253 : : struct mlx5_flow_dv_tag_resource *tag =
12254 : : container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
12255 : :
12256 : 0 : return *(uint32_t *)(ctx->data) != tag->tag_id;
12257 : : }
12258 : :
12259 : : struct mlx5_list_entry *
12260 : 0 : mlx5_flow_dv_tag_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
12261 : : void *cb_ctx)
12262 : : {
12263 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
12264 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12265 : : struct mlx5_flow_dv_tag_resource *entry;
12266 : : struct mlx5_flow_dv_tag_resource *old_entry;
12267 : 0 : uint32_t idx = 0;
12268 : :
12269 : 0 : entry = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_TAG], &idx);
12270 [ # # ]: 0 : if (!entry) {
12271 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12272 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12273 : : "cannot allocate tag resource memory");
12274 : 0 : return NULL;
12275 : : }
12276 : : old_entry = container_of(oentry, typeof(*old_entry), entry);
12277 : : memcpy(entry, old_entry, sizeof(*entry));
12278 : 0 : entry->idx = idx;
12279 : 0 : return &entry->entry;
12280 : : }
12281 : :
12282 : : void
12283 : 0 : mlx5_flow_dv_tag_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
12284 : : {
12285 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
12286 : : struct mlx5_flow_dv_tag_resource *tag =
12287 : : container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
12288 : :
12289 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], tag->idx);
12290 : 0 : }
12291 : :
12292 : : /**
12293 : : * Find existing tag resource or create and register a new one.
12294 : : *
12295 : : * @param dev[in, out]
12296 : : * Pointer to rte_eth_dev structure.
12297 : : * @param[in, out] tag_be24
12298 : : * Tag value in big endian then R-shift 8.
12299 : : * @parm[in, out] dev_flow
12300 : : * Pointer to the dev_flow.
12301 : : * @param[out] error
12302 : : * pointer to error structure.
12303 : : *
12304 : : * @return
12305 : : * 0 on success otherwise -errno and errno is set.
12306 : : */
12307 : : static int
12308 : 0 : flow_dv_tag_resource_register
12309 : : (struct rte_eth_dev *dev,
12310 : : uint32_t tag_be24,
12311 : : struct mlx5_flow *dev_flow,
12312 : : struct rte_flow_error *error)
12313 : : {
12314 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12315 : : struct mlx5_flow_dv_tag_resource *resource;
12316 : : struct mlx5_list_entry *entry;
12317 : 0 : struct mlx5_flow_cb_ctx ctx = {
12318 : : .error = error,
12319 : : .data = &tag_be24,
12320 : : };
12321 : : struct mlx5_hlist *tag_table;
12322 : :
12323 : 0 : tag_table = flow_dv_hlist_prepare(priv->sh, &priv->sh->tag_table,
12324 : : "tags",
12325 : : MLX5_TAGS_HLIST_ARRAY_SIZE,
12326 : 0 : false, false, priv->sh,
12327 : : mlx5_flow_dv_tag_create_cb,
12328 : : mlx5_flow_dv_tag_match_cb,
12329 : : mlx5_flow_dv_tag_remove_cb,
12330 : : mlx5_flow_dv_tag_clone_cb,
12331 : : mlx5_flow_dv_tag_clone_free_cb,
12332 : : error);
12333 [ # # ]: 0 : if (unlikely(!tag_table))
12334 : 0 : return -rte_errno;
12335 : 0 : entry = mlx5_hlist_register(tag_table, tag_be24, &ctx);
12336 [ # # ]: 0 : if (entry) {
12337 : : resource = container_of(entry, struct mlx5_flow_dv_tag_resource,
12338 : : entry);
12339 : 0 : dev_flow->handle->dvh.rix_tag = resource->idx;
12340 : 0 : dev_flow->dv.tag_resource = resource;
12341 : 0 : return 0;
12342 : : }
12343 : 0 : return -rte_errno;
12344 : : }
12345 : :
12346 : : void
12347 : 0 : mlx5_flow_dv_tag_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
12348 : : {
12349 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
12350 : : struct mlx5_flow_dv_tag_resource *tag =
12351 : : container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
12352 : :
12353 : : MLX5_ASSERT(tag && sh && tag->action);
12354 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(tag->action));
12355 : 0 : DRV_LOG(DEBUG, "Tag %p: removed.", (void *)tag);
12356 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], tag->idx);
12357 : 0 : }
12358 : :
12359 : : /**
12360 : : * Release the tag.
12361 : : *
12362 : : * @param dev
12363 : : * Pointer to Ethernet device.
12364 : : * @param tag_idx
12365 : : * Tag index.
12366 : : *
12367 : : * @return
12368 : : * 1 while a reference on it exists, 0 when freed.
12369 : : */
12370 : : static int
12371 : 0 : flow_dv_tag_release(struct rte_eth_dev *dev,
12372 : : uint32_t tag_idx)
12373 : : {
12374 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12375 : : struct mlx5_flow_dv_tag_resource *tag;
12376 : :
12377 : 0 : tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG], tag_idx);
12378 [ # # ]: 0 : if (!tag)
12379 : : return 0;
12380 : 0 : DRV_LOG(DEBUG, "port %u tag %p: refcnt %d--",
12381 : : dev->data->port_id, (void *)tag, tag->entry.ref_cnt);
12382 : 0 : return mlx5_hlist_unregister(priv->sh->tag_table, &tag->entry);
12383 : : }
12384 : :
12385 : : /**
12386 : : * Translate action PORT_ID / REPRESENTED_PORT to vport.
12387 : : *
12388 : : * @param[in] dev
12389 : : * Pointer to rte_eth_dev structure.
12390 : : * @param[in] action
12391 : : * Pointer to action PORT_ID / REPRESENTED_PORT.
12392 : : * @param[out] dst_port_id
12393 : : * The target port ID.
12394 : : * @param[out] error
12395 : : * Pointer to the error structure.
12396 : : *
12397 : : * @return
12398 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
12399 : : */
12400 : : static int
12401 : 0 : flow_dv_translate_action_port_id(struct rte_eth_dev *dev,
12402 : : const struct rte_flow_action *action,
12403 : : uint32_t *dst_port_id,
12404 : : struct rte_flow_error *error)
12405 : : {
12406 : : uint32_t port;
12407 : : struct mlx5_priv *priv;
12408 : :
12409 [ # # # ]: 0 : switch (action->type) {
12410 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID: {
12411 : : const struct rte_flow_action_port_id *conf;
12412 : :
12413 : 0 : conf = (const struct rte_flow_action_port_id *)action->conf;
12414 [ # # ]: 0 : port = conf->original ? dev->data->port_id : conf->id;
12415 : : break;
12416 : : }
12417 : 0 : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT: {
12418 : : const struct rte_flow_action_ethdev *ethdev;
12419 : :
12420 : 0 : ethdev = (const struct rte_flow_action_ethdev *)action->conf;
12421 : 0 : port = ethdev->port_id;
12422 : 0 : break;
12423 : : }
12424 : 0 : default:
12425 : : MLX5_ASSERT(false);
12426 : 0 : return rte_flow_error_set(error, EINVAL,
12427 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
12428 : : "unknown E-Switch action");
12429 : : }
12430 : :
12431 : 0 : priv = mlx5_port_to_eswitch_info(port, false);
12432 [ # # ]: 0 : if (!priv)
12433 : 0 : return rte_flow_error_set(error, -rte_errno,
12434 : : RTE_FLOW_ERROR_TYPE_ACTION,
12435 : : NULL,
12436 : : "No eswitch info was found for port");
12437 : : #ifdef HAVE_MLX5DV_DR_CREATE_DEST_IB_PORT
12438 : : /*
12439 : : * This parameter is transferred to
12440 : : * mlx5dv_dr_action_create_dest_ib_port().
12441 : : */
12442 : 0 : *dst_port_id = priv->dev_port;
12443 : : #else
12444 : : /*
12445 : : * Legacy mode, no LAG configurations is supported.
12446 : : * This parameter is transferred to
12447 : : * mlx5dv_dr_action_create_dest_vport().
12448 : : */
12449 : : *dst_port_id = priv->vport_id;
12450 : : #endif
12451 : 0 : return 0;
12452 : : }
12453 : :
12454 : : /**
12455 : : * Create a counter with aging configuration.
12456 : : *
12457 : : * @param[in] dev
12458 : : * Pointer to rte_eth_dev structure.
12459 : : * @param[in] dev_flow
12460 : : * Pointer to the mlx5_flow.
12461 : : * @param[out] count
12462 : : * Pointer to the counter action configuration.
12463 : : * @param[in] age
12464 : : * Pointer to the aging action configuration.
12465 : : *
12466 : : * @return
12467 : : * Index to flow counter on success, 0 otherwise.
12468 : : */
12469 : : static uint32_t
12470 : 0 : flow_dv_translate_create_counter(struct rte_eth_dev *dev,
12471 : : struct mlx5_flow *dev_flow,
12472 : : const struct rte_flow_action_count *count
12473 : : __rte_unused,
12474 : : const struct rte_flow_action_age *age)
12475 : : {
12476 : : uint32_t counter;
12477 : : struct mlx5_age_param *age_param;
12478 : :
12479 : 0 : counter = flow_dv_counter_alloc(dev, !!age);
12480 [ # # ]: 0 : if (!counter || age == NULL)
12481 : : return counter;
12482 : : age_param = flow_dv_counter_idx_get_age(dev, counter);
12483 [ # # ]: 0 : age_param->context = age->context ? age->context :
12484 : 0 : (void *)(uintptr_t)(dev_flow->flow_idx);
12485 : 0 : age_param->timeout = age->timeout;
12486 : 0 : age_param->port_id = dev->data->port_id;
12487 : 0 : rte_atomic_store_explicit(&age_param->sec_since_last_hit, 0, rte_memory_order_relaxed);
12488 : 0 : rte_atomic_store_explicit(&age_param->state, AGE_CANDIDATE, rte_memory_order_relaxed);
12489 : 0 : return counter;
12490 : : }
12491 : :
12492 : : /**
12493 : : * Add Tx queue matcher
12494 : : *
12495 : : * @param[in] dev
12496 : : * Pointer to rte_eth_dev structure.
12497 : : * @param[in, out] key
12498 : : * Flow matcher value.
12499 : : * @param[in] item
12500 : : * Flow pattern to translate.
12501 : : * @param[in] key_type
12502 : : * Set flow matcher mask or value.
12503 : : *
12504 : : * @return
12505 : : * 0 on success otherwise -errno and errno is set.
12506 : : */
12507 : : static int
12508 : 0 : flow_dv_translate_item_tx_queue(struct rte_eth_dev *dev, void *key,
12509 : : const struct rte_flow_item *item, uint32_t key_type)
12510 : : {
12511 : : const struct rte_flow_item_tx_queue *queue_m;
12512 : : const struct rte_flow_item_tx_queue *queue_v;
12513 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
12514 : : uint32_t tx_queue;
12515 : : uint32_t sqn = 0;
12516 : : int ret;
12517 : :
12518 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, queue_v, queue_m, &rte_flow_item_tx_queue_mask);
# # # # ]
12519 [ # # ]: 0 : if (!queue_m || !queue_v)
12520 : : return -EINVAL;
12521 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_V) {
12522 : 0 : tx_queue = queue_v->tx_queue;
12523 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_V)
12524 : 0 : tx_queue &= queue_m->tx_queue;
12525 [ # # ]: 0 : ret = flow_hw_get_sqn(dev, tx_queue, &sqn);
12526 [ # # ]: 0 : if (unlikely(ret))
12527 : 0 : return -ret;
12528 : : } else {
12529 : : /* Due to tx_queue to sqn converting, only fully masked value support. */
12530 [ # # ]: 0 : if (queue_m->tx_queue != rte_flow_item_tx_queue_mask.tx_queue)
12531 : : return -EINVAL;
12532 : : sqn = UINT32_MAX;
12533 : : }
12534 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, source_sqn, sqn);
12535 : 0 : return 0;
12536 : : }
12537 : :
12538 : : /**
12539 : : * Add SQ matcher
12540 : : *
12541 : : * @param[in, out] matcher
12542 : : * Flow matcher.
12543 : : * @param[in, out] key
12544 : : * Flow matcher value.
12545 : : * @param[in] item
12546 : : * Flow pattern to translate.
12547 : : * @param[in] key_type
12548 : : * Set flow matcher mask or value.
12549 : : */
12550 : : static void
12551 : 0 : flow_dv_translate_item_sq(void *key,
12552 : : const struct rte_flow_item *item,
12553 : : uint32_t key_type)
12554 : : {
12555 : : const struct mlx5_rte_flow_item_sq *queue_m;
12556 : : const struct mlx5_rte_flow_item_sq *queue_v;
12557 : 0 : const struct mlx5_rte_flow_item_sq queue_mask = {
12558 : : .queue = UINT32_MAX,
12559 : : };
12560 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
12561 : : uint32_t queue;
12562 : :
12563 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, queue_v, queue_m, &queue_mask);
# # # # ]
12564 [ # # ]: 0 : if (!queue_m || !queue_v)
12565 : 0 : return;
12566 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_V) {
12567 : 0 : queue = queue_v->queue;
12568 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_V)
12569 : 0 : queue &= queue_m->queue;
12570 : : } else {
12571 : 0 : queue = queue_m->queue;
12572 : : }
12573 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, source_sqn, queue);
12574 : : }
12575 : :
12576 : : /**
12577 : : * Set the hash fields according to the @p flow information.
12578 : : *
12579 : : * @param[in] item_flags
12580 : : * The match pattern item flags.
12581 : : * @param[in] rss_desc
12582 : : * Pointer to the mlx5_flow_rss_desc.
12583 : : * @param[out] hash_fields
12584 : : * Pointer to the RSS hash fields.
12585 : : */
12586 : : void
12587 : 0 : mlx5_flow_dv_hashfields_set(uint64_t item_flags,
12588 : : struct mlx5_flow_rss_desc *rss_desc,
12589 : : uint64_t *hash_fields)
12590 : : {
12591 : : uint64_t items = item_flags;
12592 : : uint64_t fields = 0;
12593 : : int rss_inner = 0;
12594 [ # # ]: 0 : uint64_t rss_types = rte_eth_rss_hf_refine(rss_desc->types);
12595 : :
12596 : : *hash_fields = 0;
12597 : : #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
12598 [ # # ]: 0 : if (rss_desc->level >= 2)
12599 : : rss_inner = 1;
12600 : : #endif
12601 [ # # # # ]: 0 : if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV4)) ||
12602 [ # # ]: 0 : (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV4))) {
12603 [ # # ]: 0 : if (rss_types & MLX5_IPV4_LAYER_TYPES) {
12604 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
12605 : : fields |= IBV_RX_HASH_SRC_IPV4;
12606 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
12607 : : fields |= IBV_RX_HASH_DST_IPV4;
12608 : : else
12609 : : fields |= MLX5_IPV4_IBV_RX_HASH;
12610 : : }
12611 [ # # # # : 0 : } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
# # ]
12612 [ # # ]: 0 : (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV6))) {
12613 [ # # ]: 0 : if (rss_types & MLX5_IPV6_LAYER_TYPES) {
12614 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
12615 : : fields |= IBV_RX_HASH_SRC_IPV6;
12616 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
12617 : : fields |= IBV_RX_HASH_DST_IPV6;
12618 : : else
12619 : : fields |= MLX5_IPV6_IBV_RX_HASH;
12620 : : }
12621 : : }
12622 [ # # ]: 0 : if (items & MLX5_FLOW_ITEM_ESP) {
12623 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_ESP)
12624 : 0 : fields |= IBV_RX_HASH_IPSEC_SPI;
12625 : : }
12626 [ # # ]: 0 : if ((fields & ~IBV_RX_HASH_IPSEC_SPI) == 0) {
12627 : 0 : *hash_fields = fields;
12628 : : /*
12629 : : * There is no match between the RSS types and the
12630 : : * L3 protocol (IPv4/IPv6) defined in the flow rule.
12631 : : */
12632 : 0 : return;
12633 : : }
12634 [ # # # # : 0 : if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_UDP)) ||
# # ]
12635 [ # # ]: 0 : (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_UDP))) {
12636 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_UDP) {
12637 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
12638 : 0 : fields |= IBV_RX_HASH_SRC_PORT_UDP;
12639 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
12640 : 0 : fields |= IBV_RX_HASH_DST_PORT_UDP;
12641 : : else
12642 : 0 : fields |= MLX5_UDP_IBV_RX_HASH;
12643 : : }
12644 [ # # # # : 0 : } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_TCP)) ||
# # ]
12645 [ # # ]: 0 : (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_TCP))) {
12646 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_TCP) {
12647 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
12648 : 0 : fields |= IBV_RX_HASH_SRC_PORT_TCP;
12649 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
12650 : 0 : fields |= IBV_RX_HASH_DST_PORT_TCP;
12651 : : else
12652 : 0 : fields |= MLX5_TCP_IBV_RX_HASH;
12653 : : }
12654 : : }
12655 [ # # ]: 0 : if (rss_inner)
12656 : 0 : fields |= IBV_RX_HASH_INNER;
12657 : 0 : *hash_fields = fields;
12658 : : }
12659 : :
12660 : : /**
12661 : : * Prepare an Rx Hash queue.
12662 : : *
12663 : : * @param dev
12664 : : * Pointer to Ethernet device.
12665 : : * @param[in] dev_flow
12666 : : * Pointer to the mlx5_flow.
12667 : : * @param[in] rss_desc
12668 : : * Pointer to the mlx5_flow_rss_desc.
12669 : : * @param[out] hrxq_idx
12670 : : * Hash Rx queue index.
12671 : : *
12672 : : * @return
12673 : : * The Verbs/DevX object initialised, NULL otherwise and rte_errno is set.
12674 : : */
12675 : : static struct mlx5_hrxq *
12676 : 0 : flow_dv_hrxq_prepare(struct rte_eth_dev *dev,
12677 : : struct mlx5_flow *dev_flow,
12678 : : struct mlx5_flow_rss_desc *rss_desc,
12679 : : uint32_t *hrxq_idx)
12680 : : {
12681 : 0 : struct mlx5_flow_handle *dh = dev_flow->handle;
12682 : 0 : uint32_t shared_rss = rss_desc->shared_rss;
12683 : : struct mlx5_hrxq *hrxq;
12684 : :
12685 : : MLX5_ASSERT(rss_desc->queue_num);
12686 : 0 : rss_desc->symmetric_hash_function = dev_flow->symmetric_hash_function;
12687 : 0 : rss_desc->key_len = MLX5_RSS_HASH_KEY_LEN;
12688 : 0 : rss_desc->hash_fields = dev_flow->hash_fields;
12689 : 0 : rss_desc->tunnel = !!(dh->layers & MLX5_FLOW_LAYER_TUNNEL);
12690 : 0 : rss_desc->shared_rss = 0;
12691 [ # # ]: 0 : if (rss_desc->hash_fields == 0)
12692 : 0 : rss_desc->queue_num = 1;
12693 : 0 : hrxq = mlx5_hrxq_get(dev, rss_desc);
12694 [ # # ]: 0 : *hrxq_idx = hrxq ? hrxq->idx : 0;
12695 : 0 : rss_desc->shared_rss = shared_rss;
12696 : 0 : return hrxq;
12697 : : }
12698 : :
12699 : : /**
12700 : : * Release sample sub action resource.
12701 : : *
12702 : : * @param[in, out] dev
12703 : : * Pointer to rte_eth_dev structure.
12704 : : * @param[in] act_res
12705 : : * Pointer to sample sub action resource.
12706 : : */
12707 : : static void
12708 : 0 : flow_dv_sample_sub_actions_release(struct rte_eth_dev *dev,
12709 : : struct mlx5_flow_sub_actions_idx *act_res)
12710 : : {
12711 [ # # ]: 0 : if (act_res->rix_hrxq) {
12712 : 0 : mlx5_hrxq_release(dev, act_res->rix_hrxq);
12713 : 0 : act_res->rix_hrxq = 0;
12714 : : }
12715 [ # # ]: 0 : if (act_res->rix_encap_decap) {
12716 : 0 : mlx5_flow_encap_decap_resource_release(dev, act_res->rix_encap_decap);
12717 : 0 : act_res->rix_encap_decap = 0;
12718 : : }
12719 [ # # ]: 0 : if (act_res->rix_port_id_action) {
12720 : 0 : flow_dv_port_id_action_resource_release(dev,
12721 : : act_res->rix_port_id_action);
12722 : 0 : act_res->rix_port_id_action = 0;
12723 : : }
12724 [ # # ]: 0 : if (act_res->rix_tag) {
12725 : 0 : flow_dv_tag_release(dev, act_res->rix_tag);
12726 : 0 : act_res->rix_tag = 0;
12727 : : }
12728 [ # # ]: 0 : if (act_res->rix_jump) {
12729 : 0 : flow_dv_jump_tbl_resource_release(dev, act_res->rix_jump);
12730 : 0 : act_res->rix_jump = 0;
12731 : : }
12732 : 0 : }
12733 : :
12734 : : int
12735 : 0 : mlx5_flow_dv_sample_match_cb(void *tool_ctx __rte_unused,
12736 : : struct mlx5_list_entry *entry, void *cb_ctx)
12737 : : {
12738 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12739 : 0 : struct rte_eth_dev *dev = ctx->dev;
12740 : 0 : struct mlx5_flow_dv_sample_resource *ctx_resource = ctx->data;
12741 : : struct mlx5_flow_dv_sample_resource *resource = container_of(entry,
12742 : : typeof(*resource),
12743 : : entry);
12744 : :
12745 [ # # ]: 0 : if (ctx_resource->ratio == resource->ratio &&
12746 [ # # ]: 0 : ctx_resource->ft_type == resource->ft_type &&
12747 [ # # ]: 0 : ctx_resource->ft_id == resource->ft_id &&
12748 [ # # ]: 0 : ctx_resource->set_action == resource->set_action &&
12749 : 0 : !memcmp((void *)&ctx_resource->sample_act,
12750 [ # # ]: 0 : (void *)&resource->sample_act,
12751 : : sizeof(struct mlx5_flow_sub_actions_list))) {
12752 : : /*
12753 : : * Existing sample action should release the prepared
12754 : : * sub-actions reference counter.
12755 : : */
12756 : 0 : flow_dv_sample_sub_actions_release(dev,
12757 : : &ctx_resource->sample_idx);
12758 : 0 : return 0;
12759 : : }
12760 : : return 1;
12761 : : }
12762 : :
12763 : : struct mlx5_list_entry *
12764 : 0 : mlx5_flow_dv_sample_create_cb(void *tool_ctx __rte_unused, void *cb_ctx)
12765 : : {
12766 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12767 : 0 : struct rte_eth_dev *dev = ctx->dev;
12768 : 0 : struct mlx5_flow_dv_sample_resource *ctx_resource = ctx->data;
12769 : 0 : void **sample_dv_actions = ctx_resource->sub_actions;
12770 : : struct mlx5_flow_dv_sample_resource *resource;
12771 : : struct mlx5dv_dr_flow_sampler_attr sampler_attr;
12772 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12773 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
12774 : : struct mlx5_flow_tbl_resource *tbl;
12775 : 0 : uint32_t idx = 0;
12776 : : const uint32_t next_ft_step = 1;
12777 : 0 : uint32_t next_ft_id = ctx_resource->ft_id + next_ft_step;
12778 : : uint8_t is_egress = 0;
12779 : : uint8_t is_transfer = 0;
12780 : 0 : struct rte_flow_error *error = ctx->error;
12781 : :
12782 : : /* Register new sample resource. */
12783 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_SAMPLE], &idx);
12784 [ # # ]: 0 : if (!resource) {
12785 : 0 : rte_flow_error_set(error, ENOMEM,
12786 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12787 : : NULL,
12788 : : "cannot allocate resource memory");
12789 : 0 : return NULL;
12790 : : }
12791 : 0 : *resource = *ctx_resource;
12792 : : /* Create normal path table level */
12793 [ # # ]: 0 : if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
12794 : : is_transfer = 1;
12795 [ # # ]: 0 : else if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
12796 : : is_egress = 1;
12797 : 0 : tbl = mlx5_flow_dv_tbl_resource_get(dev, next_ft_id,
12798 : : is_egress, is_transfer,
12799 : : true, NULL, 0, 0, 0, error);
12800 [ # # ]: 0 : if (!tbl) {
12801 : 0 : rte_flow_error_set(error, ENOMEM,
12802 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12803 : : NULL,
12804 : : "fail to create normal path table "
12805 : : "for sample");
12806 : 0 : goto error;
12807 : : }
12808 : 0 : resource->normal_path_tbl = tbl;
12809 [ # # ]: 0 : if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB) {
12810 [ # # ]: 0 : if (!sh->default_miss_action) {
12811 : 0 : rte_flow_error_set(error, ENOMEM,
12812 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12813 : : NULL,
12814 : : "default miss action was not "
12815 : : "created");
12816 : 0 : goto error;
12817 : : }
12818 : 0 : sample_dv_actions[ctx_resource->sample_act.actions_num++] =
12819 : : sh->default_miss_action;
12820 : : }
12821 : : /* Create a DR sample action */
12822 : 0 : sampler_attr.sample_ratio = resource->ratio;
12823 : 0 : sampler_attr.default_next_table = tbl->obj;
12824 : 0 : sampler_attr.num_sample_actions = ctx_resource->sample_act.actions_num;
12825 : 0 : sampler_attr.sample_actions = (struct mlx5dv_dr_action **)
12826 : : &sample_dv_actions[0];
12827 : 0 : sampler_attr.action = resource->set_action;
12828 : : if (mlx5_os_flow_dr_create_flow_action_sampler
12829 : : (&sampler_attr, &resource->verbs_action)) {
12830 : 0 : rte_flow_error_set(error, ENOMEM,
12831 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12832 : : NULL, "cannot create sample action");
12833 : 0 : goto error;
12834 : : }
12835 : 0 : resource->idx = idx;
12836 : 0 : resource->dev = dev;
12837 : 0 : return &resource->entry;
12838 : 0 : error:
12839 [ # # ]: 0 : if (resource->ft_type != MLX5DV_FLOW_TABLE_TYPE_FDB)
12840 : 0 : flow_dv_sample_sub_actions_release(dev,
12841 : : &resource->sample_idx);
12842 [ # # ]: 0 : if (resource->normal_path_tbl)
12843 : 0 : mlx5_flow_dv_tbl_resource_release(MLX5_SH(dev), resource->normal_path_tbl);
12844 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_SAMPLE], idx);
12845 : 0 : return NULL;
12846 : :
12847 : : }
12848 : :
12849 : : struct mlx5_list_entry *
12850 : 0 : mlx5_flow_dv_sample_clone_cb(void *tool_ctx __rte_unused,
12851 : : struct mlx5_list_entry *entry __rte_unused,
12852 : : void *cb_ctx)
12853 : : {
12854 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12855 : 0 : struct rte_eth_dev *dev = ctx->dev;
12856 : : struct mlx5_flow_dv_sample_resource *resource;
12857 : : struct mlx5_flow_dv_sample_resource *old_resource;
12858 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12859 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
12860 : 0 : uint32_t idx = 0;
12861 : :
12862 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_SAMPLE], &idx);
12863 [ # # ]: 0 : if (!resource) {
12864 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12865 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12866 : : NULL,
12867 : : "cannot allocate resource memory");
12868 : 0 : return NULL;
12869 : : }
12870 : : old_resource = container_of(entry, typeof(*old_resource), entry);
12871 : : memcpy(resource, old_resource, sizeof(*resource));
12872 : 0 : resource->idx = idx;
12873 : 0 : resource->dev = dev;
12874 : 0 : return &resource->entry;
12875 : : }
12876 : :
12877 : : void
12878 : 0 : mlx5_flow_dv_sample_clone_free_cb(void *tool_ctx __rte_unused,
12879 : : struct mlx5_list_entry *entry)
12880 : : {
12881 : : struct mlx5_flow_dv_sample_resource *resource =
12882 : : container_of(entry, typeof(*resource), entry);
12883 : 0 : struct rte_eth_dev *dev = resource->dev;
12884 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12885 : :
12886 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_SAMPLE], resource->idx);
12887 : 0 : }
12888 : :
12889 : : /**
12890 : : * Find existing sample resource or create and register a new one.
12891 : : *
12892 : : * @param[in, out] dev
12893 : : * Pointer to rte_eth_dev structure.
12894 : : * @param[in] ref
12895 : : * Pointer to sample resource reference.
12896 : : * @parm[in, out] dev_flow
12897 : : * Pointer to the dev_flow.
12898 : : * @param[out] error
12899 : : * pointer to error structure.
12900 : : *
12901 : : * @return
12902 : : * 0 on success otherwise -errno and errno is set.
12903 : : */
12904 : : static int
12905 : 0 : flow_dv_sample_resource_register(struct rte_eth_dev *dev,
12906 : : struct mlx5_flow_dv_sample_resource *ref,
12907 : : struct mlx5_flow *dev_flow,
12908 : : struct rte_flow_error *error)
12909 : : {
12910 : : struct mlx5_flow_dv_sample_resource *resource;
12911 : : struct mlx5_list_entry *entry;
12912 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12913 : 0 : struct mlx5_flow_cb_ctx ctx = {
12914 : : .dev = dev,
12915 : : .error = error,
12916 : : .data = ref,
12917 : : };
12918 : :
12919 : 0 : entry = mlx5_list_register(priv->sh->sample_action_list, &ctx);
12920 [ # # ]: 0 : if (!entry)
12921 : 0 : return -rte_errno;
12922 : : resource = container_of(entry, typeof(*resource), entry);
12923 : 0 : dev_flow->handle->dvh.rix_sample = resource->idx;
12924 : 0 : dev_flow->dv.sample_res = resource;
12925 : 0 : return 0;
12926 : : }
12927 : :
12928 : : int
12929 : 0 : mlx5_flow_dv_dest_array_match_cb(void *tool_ctx __rte_unused,
12930 : : struct mlx5_list_entry *entry, void *cb_ctx)
12931 : : {
12932 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12933 : 0 : struct mlx5_flow_dv_dest_array_resource *ctx_resource = ctx->data;
12934 : 0 : struct rte_eth_dev *dev = ctx->dev;
12935 : : struct mlx5_flow_dv_dest_array_resource *resource =
12936 : : container_of(entry, typeof(*resource), entry);
12937 : : uint32_t idx = 0;
12938 : :
12939 [ # # ]: 0 : if (ctx_resource->num_of_dest == resource->num_of_dest &&
12940 : 0 : ctx_resource->ft_type == resource->ft_type &&
12941 : 0 : !memcmp((void *)resource->sample_act,
12942 : 0 : (void *)ctx_resource->sample_act,
12943 [ # # ]: 0 : (ctx_resource->num_of_dest *
12944 : : sizeof(struct mlx5_flow_sub_actions_list)))) {
12945 : : /*
12946 : : * Existing sample action should release the prepared
12947 : : * sub-actions reference counter.
12948 : : */
12949 [ # # ]: 0 : for (idx = 0; idx < ctx_resource->num_of_dest; idx++)
12950 : 0 : flow_dv_sample_sub_actions_release(dev,
12951 : : &ctx_resource->sample_idx[idx]);
12952 : : return 0;
12953 : : }
12954 : : return 1;
12955 : : }
12956 : :
12957 : : struct mlx5_list_entry *
12958 : 0 : mlx5_flow_dv_dest_array_create_cb(void *tool_ctx __rte_unused, void *cb_ctx)
12959 : : {
12960 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12961 : 0 : struct rte_eth_dev *dev = ctx->dev;
12962 : : struct mlx5_flow_dv_dest_array_resource *resource;
12963 : 0 : struct mlx5_flow_dv_dest_array_resource *ctx_resource = ctx->data;
12964 : 0 : struct mlx5dv_dr_action_dest_attr *dest_attr[MLX5_MAX_DEST_NUM] = { 0 };
12965 : : struct mlx5dv_dr_action_dest_reformat dest_reformat[MLX5_MAX_DEST_NUM];
12966 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12967 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
12968 : : struct mlx5_flow_sub_actions_list *sample_act;
12969 : : struct mlx5dv_dr_domain *domain;
12970 : 0 : uint32_t idx = 0, res_idx = 0;
12971 : 0 : struct rte_flow_error *error = ctx->error;
12972 : : uint64_t action_flags;
12973 : : int ret;
12974 : :
12975 : : /* Register new destination array resource. */
12976 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DEST_ARRAY],
12977 : : &res_idx);
12978 [ # # ]: 0 : if (!resource) {
12979 : 0 : rte_flow_error_set(error, ENOMEM,
12980 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12981 : : NULL,
12982 : : "cannot allocate resource memory");
12983 : 0 : return NULL;
12984 : : }
12985 : 0 : *resource = *ctx_resource;
12986 [ # # ]: 0 : if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
12987 : 0 : domain = sh->fdb_domain;
12988 [ # # ]: 0 : else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
12989 : 0 : domain = sh->rx_domain;
12990 : : else
12991 : 0 : domain = sh->tx_domain;
12992 [ # # ]: 0 : for (idx = 0; idx < ctx_resource->num_of_dest; idx++) {
12993 : 0 : dest_attr[idx] = (struct mlx5dv_dr_action_dest_attr *)
12994 : 0 : mlx5_malloc(MLX5_MEM_ZERO,
12995 : : sizeof(struct mlx5dv_dr_action_dest_attr),
12996 : : 0, SOCKET_ID_ANY);
12997 [ # # ]: 0 : if (!dest_attr[idx]) {
12998 : 0 : rte_flow_error_set(error, ENOMEM,
12999 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13000 : : NULL,
13001 : : "cannot allocate resource memory");
13002 : 0 : goto error;
13003 : : }
13004 : 0 : dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST;
13005 : : sample_act = &ctx_resource->sample_act[idx];
13006 : 0 : action_flags = sample_act->action_flags;
13007 [ # # # # : 0 : switch (action_flags) {
# ]
13008 : 0 : case MLX5_FLOW_ACTION_QUEUE:
13009 : 0 : dest_attr[idx]->dest = sample_act->dr_queue_action;
13010 : 0 : break;
13011 : 0 : case (MLX5_FLOW_ACTION_PORT_ID | MLX5_FLOW_ACTION_ENCAP):
13012 : 0 : dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST_REFORMAT;
13013 : 0 : dest_attr[idx]->dest_reformat = &dest_reformat[idx];
13014 : 0 : dest_attr[idx]->dest_reformat->reformat =
13015 : 0 : sample_act->dr_encap_action;
13016 : 0 : dest_attr[idx]->dest_reformat->dest =
13017 : 0 : sample_act->dr_port_id_action;
13018 : 0 : break;
13019 : 0 : case MLX5_FLOW_ACTION_PORT_ID:
13020 : 0 : dest_attr[idx]->dest = sample_act->dr_port_id_action;
13021 : 0 : break;
13022 : 0 : case MLX5_FLOW_ACTION_JUMP:
13023 : 0 : dest_attr[idx]->dest = sample_act->dr_jump_action;
13024 : 0 : break;
13025 : 0 : default:
13026 : 0 : rte_flow_error_set(error, EINVAL,
13027 : : RTE_FLOW_ERROR_TYPE_ACTION,
13028 : : NULL,
13029 : : "unsupported actions type");
13030 : 0 : goto error;
13031 : : }
13032 : : }
13033 : : /* create a dest array action */
13034 : 0 : ret = mlx5_os_flow_dr_create_flow_action_dest_array
13035 : : (domain,
13036 : 0 : resource->num_of_dest,
13037 : : dest_attr,
13038 : : &resource->action);
13039 : : if (ret) {
13040 : 0 : rte_flow_error_set(error, ENOMEM,
13041 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13042 : : NULL,
13043 : : "cannot create destination array action");
13044 : 0 : goto error;
13045 : : }
13046 : 0 : resource->idx = res_idx;
13047 : 0 : resource->dev = dev;
13048 [ # # ]: 0 : for (idx = 0; idx < ctx_resource->num_of_dest; idx++)
13049 : 0 : mlx5_free(dest_attr[idx]);
13050 : 0 : return &resource->entry;
13051 : : error:
13052 [ # # ]: 0 : for (idx = 0; idx < ctx_resource->num_of_dest; idx++) {
13053 : 0 : flow_dv_sample_sub_actions_release(dev,
13054 : : &resource->sample_idx[idx]);
13055 [ # # ]: 0 : if (dest_attr[idx])
13056 : 0 : mlx5_free(dest_attr[idx]);
13057 : : }
13058 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DEST_ARRAY], res_idx);
13059 : 0 : return NULL;
13060 : : }
13061 : :
13062 : : struct mlx5_list_entry *
13063 : 0 : mlx5_flow_dv_dest_array_clone_cb(void *tool_ctx __rte_unused,
13064 : : struct mlx5_list_entry *entry __rte_unused,
13065 : : void *cb_ctx)
13066 : : {
13067 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
13068 : 0 : struct rte_eth_dev *dev = ctx->dev;
13069 : : struct mlx5_flow_dv_dest_array_resource *resource;
13070 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13071 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
13072 : 0 : uint32_t res_idx = 0;
13073 : 0 : struct rte_flow_error *error = ctx->error;
13074 : :
13075 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DEST_ARRAY],
13076 : : &res_idx);
13077 [ # # ]: 0 : if (!resource) {
13078 : 0 : rte_flow_error_set(error, ENOMEM,
13079 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13080 : : NULL,
13081 : : "cannot allocate dest-array memory");
13082 : 0 : return NULL;
13083 : : }
13084 : : memcpy(resource, entry, sizeof(*resource));
13085 : 0 : resource->idx = res_idx;
13086 : 0 : resource->dev = dev;
13087 : 0 : return &resource->entry;
13088 : : }
13089 : :
13090 : : void
13091 : 0 : mlx5_flow_dv_dest_array_clone_free_cb(void *tool_ctx __rte_unused,
13092 : : struct mlx5_list_entry *entry)
13093 : : {
13094 : : struct mlx5_flow_dv_dest_array_resource *resource =
13095 : : container_of(entry, typeof(*resource), entry);
13096 : 0 : struct rte_eth_dev *dev = resource->dev;
13097 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13098 : :
13099 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY], resource->idx);
13100 : 0 : }
13101 : :
13102 : : /**
13103 : : * Find existing destination array resource or create and register a new one.
13104 : : *
13105 : : * @param[in, out] dev
13106 : : * Pointer to rte_eth_dev structure.
13107 : : * @param[in] ref
13108 : : * Pointer to destination array resource reference.
13109 : : * @parm[in, out] dev_flow
13110 : : * Pointer to the dev_flow.
13111 : : * @param[out] error
13112 : : * pointer to error structure.
13113 : : *
13114 : : * @return
13115 : : * 0 on success otherwise -errno and errno is set.
13116 : : */
13117 : : static int
13118 : 0 : flow_dv_dest_array_resource_register(struct rte_eth_dev *dev,
13119 : : struct mlx5_flow_dv_dest_array_resource *ref,
13120 : : struct mlx5_flow *dev_flow,
13121 : : struct rte_flow_error *error)
13122 : : {
13123 : : struct mlx5_flow_dv_dest_array_resource *resource;
13124 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13125 : : struct mlx5_list_entry *entry;
13126 : 0 : struct mlx5_flow_cb_ctx ctx = {
13127 : : .dev = dev,
13128 : : .error = error,
13129 : : .data = ref,
13130 : : };
13131 : :
13132 : 0 : entry = mlx5_list_register(priv->sh->dest_array_list, &ctx);
13133 [ # # ]: 0 : if (!entry)
13134 : 0 : return -rte_errno;
13135 : : resource = container_of(entry, typeof(*resource), entry);
13136 : 0 : dev_flow->handle->dvh.rix_dest_array = resource->idx;
13137 : 0 : dev_flow->dv.dest_array_res = resource;
13138 : 0 : return 0;
13139 : : }
13140 : :
13141 : : /**
13142 : : * Convert Sample action to DV specification.
13143 : : *
13144 : : * @param[in] dev
13145 : : * Pointer to rte_eth_dev structure.
13146 : : * @param[in] action
13147 : : * Pointer to sample action structure.
13148 : : * @param[in, out] dev_flow
13149 : : * Pointer to the mlx5_flow.
13150 : : * @param[in] attr
13151 : : * Pointer to the flow attributes.
13152 : : * @param[in, out] num_of_dest
13153 : : * Pointer to the num of destination.
13154 : : * @param[in, out] sample_actions
13155 : : * Pointer to sample actions list.
13156 : : * @param[in, out] res
13157 : : * Pointer to sample resource.
13158 : : * @param[out] error
13159 : : * Pointer to the error structure.
13160 : : *
13161 : : * @return
13162 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
13163 : : */
13164 : : static int
13165 : 0 : flow_dv_translate_action_sample(struct rte_eth_dev *dev,
13166 : : const struct rte_flow_action_sample *action,
13167 : : struct mlx5_flow *dev_flow,
13168 : : const struct rte_flow_attr *attr,
13169 : : uint32_t *num_of_dest,
13170 : : void **sample_actions,
13171 : : struct mlx5_flow_dv_sample_resource *res,
13172 : : struct rte_flow_error *error)
13173 : : {
13174 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13175 : : const struct rte_flow_action *sub_actions;
13176 : : struct mlx5_flow_sub_actions_list *sample_act;
13177 : : struct mlx5_flow_sub_actions_idx *sample_idx;
13178 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
13179 : 0 : struct rte_flow *flow = dev_flow->flow;
13180 : : struct mlx5_flow_rss_desc *rss_desc;
13181 : : uint64_t action_flags = 0;
13182 : :
13183 : : MLX5_ASSERT(wks);
13184 : 0 : rss_desc = &wks->rss_desc;
13185 : : sample_act = &res->sample_act;
13186 : : sample_idx = &res->sample_idx;
13187 : 0 : res->ratio = action->ratio;
13188 : 0 : sub_actions = action->actions;
13189 [ # # ]: 0 : for (; sub_actions->type != RTE_FLOW_ACTION_TYPE_END; sub_actions++) {
13190 : : int type = sub_actions->type;
13191 : : uint32_t pre_rix = 0;
13192 : : void *pre_r;
13193 [ # # # # : 0 : switch (type) {
# # # ]
13194 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
13195 : : {
13196 : : const struct rte_flow_action_queue *queue;
13197 : : struct mlx5_hrxq *hrxq;
13198 : : uint32_t hrxq_idx;
13199 : :
13200 : 0 : queue = sub_actions->conf;
13201 : 0 : rss_desc->queue_num = 1;
13202 : 0 : rss_desc->queue[0] = queue->index;
13203 : 0 : hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
13204 : : rss_desc, &hrxq_idx);
13205 [ # # ]: 0 : if (!hrxq)
13206 : 0 : return rte_flow_error_set
13207 : : (error, rte_errno,
13208 : : RTE_FLOW_ERROR_TYPE_ACTION,
13209 : : NULL,
13210 : : "cannot create fate queue");
13211 : 0 : sample_act->dr_queue_action = hrxq->action;
13212 : 0 : sample_idx->rix_hrxq = hrxq_idx;
13213 : 0 : sample_actions[sample_act->actions_num++] =
13214 : : hrxq->action;
13215 : 0 : (*num_of_dest)++;
13216 : 0 : action_flags |= MLX5_FLOW_ACTION_QUEUE;
13217 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
13218 : 0 : dev_flow->handle->rix_hrxq = hrxq_idx;
13219 : 0 : dev_flow->handle->fate_action =
13220 : : MLX5_FLOW_FATE_QUEUE;
13221 : 0 : break;
13222 : : }
13223 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
13224 : : {
13225 : : struct mlx5_hrxq *hrxq;
13226 : : uint32_t hrxq_idx;
13227 : : const struct rte_flow_action_rss *rss;
13228 : : const uint8_t *rss_key;
13229 : :
13230 : 0 : rss = sub_actions->conf;
13231 : 0 : rss_desc->symmetric_hash_function =
13232 : 0 : MLX5_RSS_IS_SYMM(rss->func);
13233 : 0 : memcpy(rss_desc->queue, rss->queue,
13234 [ # # ]: 0 : rss->queue_num * sizeof(uint16_t));
13235 : 0 : rss_desc->queue_num = rss->queue_num;
13236 : : /* NULL RSS key indicates default RSS key. */
13237 [ # # ]: 0 : rss_key = !rss->key ? mlx5_rss_hash_default_key : rss->key;
13238 : 0 : memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
13239 : : /*
13240 : : * rss->level and rss.types should be set in advance
13241 : : * when expanding items for RSS.
13242 : : */
13243 : 0 : mlx5_flow_dv_hashfields_set(dev_flow->handle->layers,
13244 : : rss_desc,
13245 : : &dev_flow->hash_fields);
13246 : 0 : hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
13247 : : rss_desc, &hrxq_idx);
13248 [ # # ]: 0 : if (!hrxq)
13249 : 0 : return rte_flow_error_set
13250 : : (error, rte_errno,
13251 : : RTE_FLOW_ERROR_TYPE_ACTION,
13252 : : NULL,
13253 : : "cannot create fate queue");
13254 : 0 : sample_act->dr_queue_action = hrxq->action;
13255 : 0 : sample_idx->rix_hrxq = hrxq_idx;
13256 : 0 : sample_actions[sample_act->actions_num++] =
13257 : : hrxq->action;
13258 : 0 : (*num_of_dest)++;
13259 : 0 : action_flags |= MLX5_FLOW_ACTION_RSS;
13260 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
13261 : 0 : dev_flow->handle->rix_hrxq = hrxq_idx;
13262 : 0 : dev_flow->handle->fate_action =
13263 : : MLX5_FLOW_FATE_QUEUE;
13264 : 0 : break;
13265 : : }
13266 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
13267 : : {
13268 : : uint32_t tag_be = mlx5_flow_mark_set
13269 : : (((const struct rte_flow_action_mark *)
13270 [ # # ]: 0 : (sub_actions->conf))->id);
13271 : :
13272 : 0 : wks->mark = 1;
13273 : 0 : pre_rix = dev_flow->handle->dvh.rix_tag;
13274 : : /* Save the mark resource before sample */
13275 : 0 : pre_r = dev_flow->dv.tag_resource;
13276 [ # # ]: 0 : if (flow_dv_tag_resource_register(dev, tag_be,
13277 : : dev_flow, error))
13278 : 0 : return -rte_errno;
13279 : : MLX5_ASSERT(dev_flow->dv.tag_resource);
13280 : 0 : sample_act->dr_tag_action =
13281 : 0 : dev_flow->dv.tag_resource->action;
13282 : 0 : sample_idx->rix_tag =
13283 : 0 : dev_flow->handle->dvh.rix_tag;
13284 : 0 : sample_actions[sample_act->actions_num++] =
13285 : : sample_act->dr_tag_action;
13286 : : /* Recover the mark resource after sample */
13287 : 0 : dev_flow->dv.tag_resource = pre_r;
13288 : 0 : dev_flow->handle->dvh.rix_tag = pre_rix;
13289 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK;
13290 : 0 : break;
13291 : : }
13292 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
13293 : : {
13294 [ # # ]: 0 : if (!flow->counter) {
13295 : 0 : flow->counter =
13296 : 0 : flow_dv_translate_create_counter(dev,
13297 : 0 : dev_flow, sub_actions->conf,
13298 : : 0);
13299 [ # # ]: 0 : if (!flow->counter)
13300 : 0 : return rte_flow_error_set
13301 : : (error, rte_errno,
13302 : : RTE_FLOW_ERROR_TYPE_ACTION,
13303 : : NULL,
13304 : : "cannot create counter"
13305 : : " object.");
13306 : : }
13307 : 0 : sample_act->dr_cnt_action =
13308 [ # # ]: 0 : (flow_dv_counter_get_by_idx(dev,
13309 : 0 : flow->counter, NULL))->action;
13310 : 0 : sample_actions[sample_act->actions_num++] =
13311 : : sample_act->dr_cnt_action;
13312 : 0 : action_flags |= MLX5_FLOW_ACTION_COUNT;
13313 : 0 : break;
13314 : : }
13315 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
13316 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
13317 : : {
13318 : : struct mlx5_flow_dv_port_id_action_resource
13319 : : port_id_resource;
13320 : 0 : uint32_t port_id = 0;
13321 : :
13322 : : memset(&port_id_resource, 0, sizeof(port_id_resource));
13323 : : /* Save the port id resource before sample */
13324 : 0 : pre_rix = dev_flow->handle->rix_port_id_action;
13325 : 0 : pre_r = dev_flow->dv.port_id_action;
13326 [ # # ]: 0 : if (flow_dv_translate_action_port_id(dev, sub_actions,
13327 : : &port_id, error))
13328 : 0 : return -rte_errno;
13329 : 0 : port_id_resource.port_id = port_id;
13330 [ # # ]: 0 : if (flow_dv_port_id_action_resource_register
13331 : : (dev, &port_id_resource, dev_flow, error))
13332 : 0 : return -rte_errno;
13333 : 0 : sample_act->dr_port_id_action =
13334 : 0 : dev_flow->dv.port_id_action->action;
13335 : 0 : sample_idx->rix_port_id_action =
13336 : 0 : dev_flow->handle->rix_port_id_action;
13337 : 0 : sample_actions[sample_act->actions_num++] =
13338 : : sample_act->dr_port_id_action;
13339 : : /* Recover the port id resource after sample */
13340 : 0 : dev_flow->dv.port_id_action = pre_r;
13341 : 0 : dev_flow->handle->rix_port_id_action = pre_rix;
13342 : 0 : (*num_of_dest)++;
13343 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_ID;
13344 : 0 : break;
13345 : : }
13346 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
13347 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
13348 : : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
13349 : : /* Save the encap resource before sample */
13350 : 0 : pre_rix = dev_flow->handle->dvh.rix_encap_decap;
13351 : 0 : pre_r = dev_flow->dv.encap_decap;
13352 [ # # ]: 0 : if (flow_dv_create_action_l2_encap(dev, sub_actions,
13353 : : dev_flow,
13354 : 0 : attr->transfer,
13355 : : error))
13356 : 0 : return -rte_errno;
13357 : 0 : sample_act->dr_encap_action =
13358 : 0 : dev_flow->dv.encap_decap->action;
13359 : 0 : sample_idx->rix_encap_decap =
13360 : 0 : dev_flow->handle->dvh.rix_encap_decap;
13361 : 0 : sample_actions[sample_act->actions_num++] =
13362 : : sample_act->dr_encap_action;
13363 : : /* Recover the encap resource after sample */
13364 : 0 : dev_flow->dv.encap_decap = pre_r;
13365 : 0 : dev_flow->handle->dvh.rix_encap_decap = pre_rix;
13366 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
13367 : 0 : break;
13368 : 0 : default:
13369 : 0 : return rte_flow_error_set(error, EINVAL,
13370 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13371 : : NULL,
13372 : : "Not support for sampler action");
13373 : : }
13374 : : }
13375 : 0 : sample_act->action_flags = action_flags;
13376 : 0 : res->ft_id = dev_flow->dv.group;
13377 [ # # ]: 0 : if (attr->transfer) {
13378 : : union {
13379 : : uint32_t action_in[MLX5_ST_SZ_DW(set_action_in)];
13380 : : uint64_t set_action;
13381 : : } action_ctx = { .set_action = 0 };
13382 : 0 : uint32_t vport_meta_tag = wks->vport_meta_tag ?
13383 [ # # ]: 0 : wks->vport_meta_tag :
13384 : : priv->vport_meta_tag;
13385 : :
13386 : 0 : res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
13387 : : MLX5_SET(set_action_in, action_ctx.action_in, action_type,
13388 : : MLX5_MODIFICATION_TYPE_SET);
13389 [ # # ]: 0 : MLX5_SET(set_action_in, action_ctx.action_in, field,
13390 : : MLX5_MODI_META_REG_C_0);
13391 : 0 : MLX5_SET(set_action_in, action_ctx.action_in, data,
13392 : : vport_meta_tag);
13393 : 0 : res->set_action = action_ctx.set_action;
13394 [ # # ]: 0 : } else if (attr->ingress) {
13395 : 0 : res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
13396 : : } else {
13397 : 0 : res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_TX;
13398 : : }
13399 : : return 0;
13400 : : }
13401 : :
13402 : : static void *
13403 : 0 : flow_dv_translate_action_send_to_kernel(struct rte_eth_dev *dev,
13404 : : const struct rte_flow_attr *attr,
13405 : : struct rte_flow_error *error)
13406 : : {
13407 : : struct mlx5_flow_tbl_resource *tbl;
13408 : : struct mlx5_dev_ctx_shared *sh;
13409 : : uint32_t priority;
13410 : : void *action;
13411 : : int ft_type;
13412 : : int ret;
13413 : :
13414 : 0 : sh = MLX5_SH(dev);
13415 [ # # ]: 0 : ft_type = (attr->ingress) ? MLX5DR_TABLE_TYPE_NIC_RX :
13416 [ # # ]: 0 : ((attr->transfer) ? MLX5DR_TABLE_TYPE_FDB :
13417 : : MLX5DR_TABLE_TYPE_NIC_TX);
13418 [ # # ]: 0 : if (sh->send_to_kernel_action[ft_type].action)
13419 : : return sh->send_to_kernel_action[ft_type].action;
13420 : 0 : priority = mlx5_get_send_to_kernel_priority(dev);
13421 [ # # ]: 0 : if (priority == (uint32_t)-1) {
13422 : 0 : rte_flow_error_set(error, ENOTSUP,
13423 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13424 : : "required priority is not available");
13425 : 0 : return NULL;
13426 : : }
13427 : 0 : tbl = mlx5_flow_dv_tbl_resource_get(dev, 0, attr->egress, attr->transfer,
13428 : : false, NULL, 0, 0, 0, error);
13429 [ # # ]: 0 : if (!tbl) {
13430 : 0 : rte_flow_error_set(error, ENODATA,
13431 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13432 : : "cannot find destination root table");
13433 : 0 : return NULL;
13434 : : }
13435 : 0 : ret = mlx5_flow_os_create_flow_action_send_to_kernel(tbl->obj,
13436 : : priority, &action);
13437 : : if (ret) {
13438 : 0 : rte_flow_error_set(error, ENOMEM,
13439 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13440 : : "cannot create action");
13441 : 0 : goto err;
13442 : : }
13443 : : MLX5_ASSERT(action);
13444 : 0 : sh->send_to_kernel_action[ft_type].action = action;
13445 : 0 : sh->send_to_kernel_action[ft_type].tbl = tbl;
13446 : 0 : return action;
13447 : : err:
13448 : 0 : mlx5_flow_dv_tbl_resource_release(sh, tbl);
13449 : 0 : return NULL;
13450 : : }
13451 : :
13452 : : /**
13453 : : * Convert Sample action to DV specification.
13454 : : *
13455 : : * @param[in] dev
13456 : : * Pointer to rte_eth_dev structure.
13457 : : * @param[in, out] dev_flow
13458 : : * Pointer to the mlx5_flow.
13459 : : * @param[in] num_of_dest
13460 : : * The num of destination.
13461 : : * @param[in, out] res
13462 : : * Pointer to sample resource.
13463 : : * @param[in, out] mdest_res
13464 : : * Pointer to destination array resource.
13465 : : * @param[in] sample_actions
13466 : : * Pointer to sample path actions list.
13467 : : * @param[in] action_flags
13468 : : * Holds the actions detected until now.
13469 : : * @param[out] error
13470 : : * Pointer to the error structure.
13471 : : *
13472 : : * @return
13473 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
13474 : : */
13475 : : static int
13476 : 0 : flow_dv_create_action_sample(struct rte_eth_dev *dev,
13477 : : struct mlx5_flow *dev_flow,
13478 : : uint32_t num_of_dest,
13479 : : struct mlx5_flow_dv_sample_resource *res,
13480 : : struct mlx5_flow_dv_dest_array_resource *mdest_res,
13481 : : void **sample_actions,
13482 : : uint64_t action_flags,
13483 : : struct rte_flow_error *error)
13484 : : {
13485 : : /* update normal path action resource into last index of array */
13486 : : uint32_t dest_index = MLX5_MAX_DEST_NUM - 1;
13487 : : struct mlx5_flow_sub_actions_list *sample_act =
13488 : : &mdest_res->sample_act[dest_index];
13489 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
13490 : : struct mlx5_flow_rss_desc *rss_desc;
13491 : : uint32_t normal_idx = 0;
13492 : : struct mlx5_hrxq *hrxq;
13493 : : uint32_t hrxq_idx;
13494 : :
13495 : : MLX5_ASSERT(wks);
13496 : 0 : rss_desc = &wks->rss_desc;
13497 [ # # ]: 0 : if (num_of_dest > 1) {
13498 [ # # ]: 0 : if (sample_act->action_flags & MLX5_FLOW_ACTION_QUEUE) {
13499 : : /* Handle QP action for mirroring */
13500 : 0 : hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
13501 : : rss_desc, &hrxq_idx);
13502 [ # # ]: 0 : if (!hrxq)
13503 : 0 : return rte_flow_error_set
13504 : : (error, rte_errno,
13505 : : RTE_FLOW_ERROR_TYPE_ACTION,
13506 : : NULL,
13507 : : "cannot create rx queue");
13508 : : normal_idx++;
13509 : 0 : mdest_res->sample_idx[dest_index].rix_hrxq = hrxq_idx;
13510 : 0 : sample_act->dr_queue_action = hrxq->action;
13511 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
13512 : 0 : dev_flow->handle->rix_hrxq = hrxq_idx;
13513 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
13514 : : }
13515 [ # # ]: 0 : if (sample_act->action_flags & MLX5_FLOW_ACTION_ENCAP) {
13516 : 0 : normal_idx++;
13517 : 0 : mdest_res->sample_idx[dest_index].rix_encap_decap =
13518 : 0 : dev_flow->handle->dvh.rix_encap_decap;
13519 : 0 : sample_act->dr_encap_action =
13520 : 0 : dev_flow->dv.encap_decap->action;
13521 : 0 : dev_flow->handle->dvh.rix_encap_decap = 0;
13522 : : }
13523 [ # # ]: 0 : if (sample_act->action_flags & MLX5_FLOW_ACTION_PORT_ID) {
13524 : 0 : normal_idx++;
13525 : 0 : mdest_res->sample_idx[dest_index].rix_port_id_action =
13526 : 0 : dev_flow->handle->rix_port_id_action;
13527 : 0 : sample_act->dr_port_id_action =
13528 : 0 : dev_flow->dv.port_id_action->action;
13529 : 0 : dev_flow->handle->rix_port_id_action = 0;
13530 : : }
13531 [ # # ]: 0 : if (sample_act->action_flags & MLX5_FLOW_ACTION_JUMP) {
13532 : 0 : normal_idx++;
13533 : 0 : mdest_res->sample_idx[dest_index].rix_jump =
13534 : 0 : dev_flow->handle->rix_jump;
13535 : 0 : sample_act->dr_jump_action =
13536 : 0 : dev_flow->dv.jump->action;
13537 : 0 : dev_flow->handle->rix_jump = 0;
13538 : : }
13539 : 0 : sample_act->actions_num = normal_idx;
13540 : : /* update sample action resource into first index of array */
13541 : 0 : mdest_res->ft_type = res->ft_type;
13542 : 0 : memcpy(&mdest_res->sample_idx[0], &res->sample_idx,
13543 : : sizeof(struct mlx5_flow_sub_actions_idx));
13544 : 0 : memcpy(&mdest_res->sample_act[0], &res->sample_act,
13545 : : sizeof(struct mlx5_flow_sub_actions_list));
13546 : 0 : mdest_res->num_of_dest = num_of_dest;
13547 [ # # ]: 0 : if (flow_dv_dest_array_resource_register(dev, mdest_res,
13548 : : dev_flow, error))
13549 : 0 : return rte_flow_error_set(error, EINVAL,
13550 : : RTE_FLOW_ERROR_TYPE_ACTION,
13551 : : NULL, "can't create sample "
13552 : : "action");
13553 : : } else {
13554 : 0 : res->sub_actions = sample_actions;
13555 [ # # ]: 0 : if (flow_dv_sample_resource_register(dev, res, dev_flow, error))
13556 : 0 : return rte_flow_error_set(error, EINVAL,
13557 : : RTE_FLOW_ERROR_TYPE_ACTION,
13558 : : NULL,
13559 : : "can't create sample action");
13560 : : }
13561 : : return 0;
13562 : : }
13563 : :
13564 : : /**
13565 : : * Remove an ASO age action from age actions list.
13566 : : *
13567 : : * @param[in] dev
13568 : : * Pointer to the Ethernet device structure.
13569 : : * @param[in] age
13570 : : * Pointer to the aso age action handler.
13571 : : */
13572 : : static void
13573 : 0 : flow_dv_aso_age_remove_from_age(struct rte_eth_dev *dev,
13574 : : struct mlx5_aso_age_action *age)
13575 : : {
13576 : : struct mlx5_age_info *age_info;
13577 : : struct mlx5_age_param *age_param = &age->age_params;
13578 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13579 : : uint16_t expected = AGE_CANDIDATE;
13580 : :
13581 : 0 : age_info = GET_PORT_AGE_INFO(priv);
13582 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(&age_param->state, &expected,
13583 : : AGE_FREE, rte_memory_order_relaxed,
13584 : : rte_memory_order_relaxed)) {
13585 : : /**
13586 : : * We need the lock even it is age timeout,
13587 : : * since age action may still in process.
13588 : : */
13589 : 0 : rte_spinlock_lock(&age_info->aged_sl);
13590 [ # # ]: 0 : LIST_REMOVE(age, next);
13591 : : rte_spinlock_unlock(&age_info->aged_sl);
13592 : 0 : rte_atomic_store_explicit(&age_param->state, AGE_FREE, rte_memory_order_relaxed);
13593 : : }
13594 : 0 : }
13595 : :
13596 : : /**
13597 : : * Release an ASO age action.
13598 : : *
13599 : : * @param[in] dev
13600 : : * Pointer to the Ethernet device structure.
13601 : : * @param[in] age_idx
13602 : : * Index of ASO age action to release.
13603 : : * @param[in] flow
13604 : : * True if the release operation is during flow destroy operation.
13605 : : * False if the release operation is during action destroy operation.
13606 : : *
13607 : : * @return
13608 : : * 0 when age action was removed, otherwise the number of references.
13609 : : */
13610 : : static int
13611 : 0 : flow_dv_aso_age_release(struct rte_eth_dev *dev, uint32_t age_idx)
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 : 0 : struct mlx5_aso_age_action *age = mlx5_flow_aso_age_get_by_idx(dev, age_idx);
13616 : 0 : uint32_t ret = rte_atomic_fetch_sub_explicit(&age->refcnt, 1, rte_memory_order_relaxed) - 1;
13617 : :
13618 [ # # ]: 0 : if (!ret) {
13619 : 0 : flow_dv_aso_age_remove_from_age(dev, age);
13620 : 0 : rte_spinlock_lock(&mng->free_sl);
13621 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free, age, next);
13622 : : rte_spinlock_unlock(&mng->free_sl);
13623 : : }
13624 : 0 : return ret;
13625 : : }
13626 : :
13627 : : /**
13628 : : * Resize the ASO age pools array by MLX5_ASO_AGE_CONTAINER_RESIZE pools.
13629 : : *
13630 : : * @param[in] dev
13631 : : * Pointer to the Ethernet device structure.
13632 : : *
13633 : : * @return
13634 : : * 0 on success, otherwise negative errno value and rte_errno is set.
13635 : : */
13636 : : static int
13637 : 0 : flow_dv_aso_age_pools_resize(struct rte_eth_dev *dev)
13638 : : {
13639 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13640 : 0 : struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
13641 : 0 : void *old_pools = mng->pools;
13642 : 0 : uint32_t resize = mng->n + MLX5_ASO_AGE_CONTAINER_RESIZE;
13643 : 0 : uint32_t mem_size = sizeof(struct mlx5_aso_age_pool *) * resize;
13644 : 0 : void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
13645 : :
13646 [ # # ]: 0 : if (!pools) {
13647 : 0 : rte_errno = ENOMEM;
13648 : 0 : return -ENOMEM;
13649 : : }
13650 [ # # ]: 0 : if (old_pools) {
13651 : 0 : memcpy(pools, old_pools,
13652 : 0 : mng->n * sizeof(struct mlx5_flow_counter_pool *));
13653 : 0 : mlx5_free(old_pools);
13654 : : } else {
13655 : : /* First ASO flow hit allocation - starting ASO data-path. */
13656 : 0 : int ret = mlx5_aso_flow_hit_queue_poll_start(priv->sh);
13657 : :
13658 [ # # ]: 0 : if (ret) {
13659 : 0 : mlx5_free(pools);
13660 : 0 : return ret;
13661 : : }
13662 : : }
13663 : 0 : mng->n = resize;
13664 : 0 : mng->pools = pools;
13665 : 0 : return 0;
13666 : : }
13667 : :
13668 : : /**
13669 : : * Create and initialize a new ASO aging pool.
13670 : : *
13671 : : * @param[in] dev
13672 : : * Pointer to the Ethernet device structure.
13673 : : * @param[out] age_free
13674 : : * Where to put the pointer of a new age action.
13675 : : *
13676 : : * @return
13677 : : * The age actions pool pointer and @p age_free is set on success,
13678 : : * NULL otherwise and rte_errno is set.
13679 : : */
13680 : : static struct mlx5_aso_age_pool *
13681 : 0 : flow_dv_age_pool_create(struct rte_eth_dev *dev,
13682 : : struct mlx5_aso_age_action **age_free)
13683 : : {
13684 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13685 : 0 : struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
13686 : : struct mlx5_aso_age_pool *pool = NULL;
13687 : : struct mlx5_devx_obj *obj = NULL;
13688 : : uint32_t i;
13689 : :
13690 : 0 : obj = mlx5_devx_cmd_create_flow_hit_aso_obj(priv->sh->cdev->ctx,
13691 : 0 : priv->sh->cdev->pdn);
13692 [ # # ]: 0 : if (!obj) {
13693 : 0 : rte_errno = ENODATA;
13694 : 0 : DRV_LOG(ERR, "Failed to create flow_hit_aso_obj using DevX.");
13695 : 0 : return NULL;
13696 : : }
13697 : 0 : pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
13698 [ # # ]: 0 : if (!pool) {
13699 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
13700 : 0 : rte_errno = ENOMEM;
13701 : 0 : return NULL;
13702 : : }
13703 : 0 : pool->flow_hit_aso_obj = obj;
13704 : 0 : pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
13705 : 0 : rte_rwlock_write_lock(&mng->resize_rwl);
13706 : 0 : pool->index = mng->next;
13707 : : /* Resize pools array if there is no room for the new pool in it. */
13708 [ # # # # ]: 0 : if (pool->index == mng->n && flow_dv_aso_age_pools_resize(dev)) {
13709 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
13710 : 0 : mlx5_free(pool);
13711 : : rte_rwlock_write_unlock(&mng->resize_rwl);
13712 : 0 : return NULL;
13713 : : }
13714 : 0 : mng->pools[pool->index] = pool;
13715 : 0 : mng->next++;
13716 : : rte_rwlock_write_unlock(&mng->resize_rwl);
13717 : : /* Assign the first action in the new pool, the rest go to free list. */
13718 : 0 : *age_free = &pool->actions[0];
13719 [ # # ]: 0 : for (i = 1; i < MLX5_ASO_AGE_ACTIONS_PER_POOL; i++) {
13720 : 0 : pool->actions[i].offset = i;
13721 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free, &pool->actions[i], next);
13722 : : }
13723 : : return pool;
13724 : : }
13725 : :
13726 : : /**
13727 : : * Allocate a ASO aging bit.
13728 : : *
13729 : : * @param[in] dev
13730 : : * Pointer to the Ethernet device structure.
13731 : : * @param[out] error
13732 : : * Pointer to the error structure.
13733 : : *
13734 : : * @return
13735 : : * Index to ASO age action on success, 0 otherwise and rte_errno is set.
13736 : : */
13737 : : static uint32_t
13738 : 0 : flow_dv_aso_age_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
13739 : : {
13740 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13741 : : const struct mlx5_aso_age_pool *pool;
13742 : 0 : struct mlx5_aso_age_action *age_free = NULL;
13743 : 0 : struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
13744 : :
13745 : : MLX5_ASSERT(mng);
13746 : : /* Try to get the next free age action bit. */
13747 : 0 : rte_spinlock_lock(&mng->free_sl);
13748 : 0 : age_free = LIST_FIRST(&mng->free);
13749 [ # # ]: 0 : if (age_free) {
13750 [ # # ]: 0 : LIST_REMOVE(age_free, next);
13751 [ # # ]: 0 : } else if (!flow_dv_age_pool_create(dev, &age_free)) {
13752 : : rte_spinlock_unlock(&mng->free_sl);
13753 : 0 : rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
13754 : : NULL, "failed to create ASO age pool");
13755 : 0 : return 0; /* 0 is an error. */
13756 : : }
13757 : : rte_spinlock_unlock(&mng->free_sl);
13758 : 0 : pool = container_of
13759 : : ((const struct mlx5_aso_age_action (*)[MLX5_ASO_AGE_ACTIONS_PER_POOL])
13760 : : (age_free - age_free->offset), const struct mlx5_aso_age_pool,
13761 : : actions);
13762 [ # # ]: 0 : if (!age_free->dr_action) {
13763 : 0 : int reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_FLOW_HIT, 0,
13764 : : error);
13765 : :
13766 [ # # ]: 0 : if (reg_c < 0) {
13767 : 0 : rte_flow_error_set(error, rte_errno,
13768 : : RTE_FLOW_ERROR_TYPE_ACTION,
13769 : : NULL, "failed to get reg_c "
13770 : : "for ASO flow hit");
13771 : 0 : return 0; /* 0 is an error. */
13772 : : }
13773 : : #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
13774 : 0 : age_free->dr_action = mlx5_glue->dv_create_flow_action_aso
13775 : 0 : (priv->sh->rx_domain,
13776 : 0 : pool->flow_hit_aso_obj->obj, age_free->offset,
13777 : : MLX5DV_DR_ACTION_FLAGS_ASO_FIRST_HIT_SET,
13778 : 0 : (reg_c - REG_C_0));
13779 : : #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
13780 [ # # ]: 0 : if (!age_free->dr_action) {
13781 : 0 : rte_errno = errno;
13782 : : rte_spinlock_lock(&mng->free_sl);
13783 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free, age_free, next);
13784 : : rte_spinlock_unlock(&mng->free_sl);
13785 : 0 : rte_flow_error_set(error, rte_errno,
13786 : : RTE_FLOW_ERROR_TYPE_ACTION,
13787 : : NULL, "failed to create ASO "
13788 : : "flow hit action");
13789 : 0 : return 0; /* 0 is an error. */
13790 : : }
13791 : : }
13792 : 0 : rte_atomic_store_explicit(&age_free->refcnt, 1, rte_memory_order_relaxed);
13793 : 0 : return pool->index | ((age_free->offset + 1) << 16);
13794 : : }
13795 : :
13796 : : /**
13797 : : * Initialize flow ASO age parameters.
13798 : : *
13799 : : * @param[in] dev
13800 : : * Pointer to rte_eth_dev structure.
13801 : : * @param[in] age_idx
13802 : : * Index of ASO age action.
13803 : : * @param[in] context
13804 : : * Pointer to flow counter age context.
13805 : : * @param[in] timeout
13806 : : * Aging timeout in seconds.
13807 : : *
13808 : : */
13809 : : static void
13810 : 0 : flow_dv_aso_age_params_init(struct rte_eth_dev *dev,
13811 : : uint32_t age_idx,
13812 : : void *context,
13813 : : uint32_t timeout)
13814 : : {
13815 : : struct mlx5_aso_age_action *aso_age;
13816 : :
13817 : 0 : aso_age = mlx5_flow_aso_age_get_by_idx(dev, age_idx);
13818 : : MLX5_ASSERT(aso_age);
13819 : 0 : aso_age->age_params.context = context;
13820 : 0 : aso_age->age_params.timeout = timeout;
13821 : 0 : aso_age->age_params.port_id = dev->data->port_id;
13822 : 0 : rte_atomic_store_explicit(&aso_age->age_params.sec_since_last_hit, 0,
13823 : : rte_memory_order_relaxed);
13824 : 0 : rte_atomic_store_explicit(&aso_age->age_params.state, AGE_CANDIDATE,
13825 : : rte_memory_order_relaxed);
13826 : 0 : }
13827 : :
13828 : : static void
13829 : 0 : flow_dv_translate_integrity_l4(const struct rte_flow_item_integrity *mask,
13830 : : void *headers)
13831 : : {
13832 : : /*
13833 : : * In HWS mode MLX5_ITEM_UPDATE() macro assigns the same pointer to
13834 : : * both mask and value, therefore ether can be used.
13835 : : * In SWS SW_V mode mask points to item mask and value points to item
13836 : : * spec. Integrity item value is used only if matching mask is set.
13837 : : * Use mask reference here to keep SWS functionality.
13838 : : */
13839 [ # # ]: 0 : if (mask->l4_ok) {
13840 : : /* RTE l4_ok filter aggregates hardware l4_ok and
13841 : : * l4_checksum_ok filters.
13842 : : * Positive RTE l4_ok match requires hardware match on both L4
13843 : : * hardware integrity bits.
13844 : : * PMD supports positive integrity item semantics only.
13845 : : */
13846 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, l4_ok, 1);
13847 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, l4_checksum_ok, 1);
13848 [ # # ]: 0 : } else if (mask->l4_csum_ok) {
13849 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, l4_checksum_ok, 1);
13850 : : }
13851 : 0 : }
13852 : :
13853 : : static void
13854 : 0 : flow_dv_translate_integrity_l3(const struct rte_flow_item_integrity *mask,
13855 : : void *headers, bool is_ipv4)
13856 : : {
13857 : : /*
13858 : : * In HWS mode MLX5_ITEM_UPDATE() macro assigns the same pointer to
13859 : : * both mask and value, therefore ether can be used.
13860 : : * In SWS SW_V mode mask points to item mask and value points to item
13861 : : * spec. Integrity item value used only if matching mask is set.
13862 : : * Use mask reference here to keep SWS functionality.
13863 : : */
13864 [ # # ]: 0 : if (mask->l3_ok) {
13865 : : /* RTE l3_ok filter aggregates for IPv4 hardware l3_ok and
13866 : : * ipv4_csum_ok filters.
13867 : : * Positive RTE l3_ok match requires hardware match on both L3
13868 : : * hardware integrity bits.
13869 : : * PMD supports positive integrity item semantics only.
13870 : : */
13871 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, l3_ok, 1);
13872 [ # # ]: 0 : if (is_ipv4) {
13873 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers,
13874 : : ipv4_checksum_ok, 1);
13875 : : }
13876 [ # # # # ]: 0 : } else if (is_ipv4 && mask->ipv4_csum_ok) {
13877 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, ipv4_checksum_ok, 1);
13878 : : }
13879 : 0 : }
13880 : :
13881 : : static void
13882 : 0 : set_integrity_bits(void *headers, const struct rte_flow_item *integrity_item,
13883 : : bool is_l3_ip4, uint32_t key_type)
13884 : : {
13885 : : const struct rte_flow_item_integrity *spec;
13886 : : const struct rte_flow_item_integrity *mask;
13887 : :
13888 : : /* Integrity bits validation cleared spec pointer */
13889 [ # # # # : 0 : if (MLX5_ITEM_VALID(integrity_item, key_type))
# # # # #
# ]
13890 : : return;
13891 [ # # # # : 0 : MLX5_ITEM_UPDATE(integrity_item, key_type, spec, mask,
# # # # ]
13892 : : &rte_flow_item_integrity_mask);
13893 : 0 : flow_dv_translate_integrity_l3(mask, headers, is_l3_ip4);
13894 : 0 : flow_dv_translate_integrity_l4(mask, headers);
13895 : : }
13896 : :
13897 : : static void
13898 : 0 : flow_dv_translate_item_integrity_post(void *key,
13899 : : const
13900 : : struct rte_flow_item *integrity_items[2],
13901 : : uint64_t pattern_flags, uint32_t key_type)
13902 : : {
13903 : : void *headers;
13904 : : bool is_l3_ip4;
13905 : :
13906 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_INNER_INTEGRITY) {
13907 : 0 : headers = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
13908 : 0 : is_l3_ip4 = (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV4) !=
13909 : : 0;
13910 : 0 : set_integrity_bits(headers, integrity_items[1], is_l3_ip4,
13911 : : key_type);
13912 : : }
13913 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_OUTER_INTEGRITY) {
13914 : : headers = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
13915 : 0 : is_l3_ip4 = (pattern_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV4) !=
13916 : : 0;
13917 : 0 : set_integrity_bits(headers, integrity_items[0], is_l3_ip4,
13918 : : key_type);
13919 : : }
13920 : 0 : }
13921 : :
13922 : : static uint64_t
13923 : : flow_dv_translate_item_integrity(const struct rte_flow_item *item,
13924 : : struct mlx5_dv_matcher_workspace *wks,
13925 : : uint64_t key_type)
13926 : : {
13927 : 0 : if ((key_type & MLX5_SET_MATCHER_SW) != 0) {
13928 : : const struct rte_flow_item_integrity
13929 : 0 : *spec = (typeof(spec))item->spec;
13930 : :
13931 : : /* SWS integrity bits validation cleared spec pointer */
13932 [ # # ]: 0 : if (spec->level > 1) {
13933 : 0 : wks->integrity_items[1] = item;
13934 : 0 : wks->last_item |= MLX5_FLOW_ITEM_INNER_INTEGRITY;
13935 : : } else {
13936 : 0 : wks->integrity_items[0] = item;
13937 : 0 : wks->last_item |= MLX5_FLOW_ITEM_OUTER_INTEGRITY;
13938 : : }
13939 : : } else {
13940 : : /* HWS supports outer integrity only */
13941 : 0 : wks->integrity_items[0] = item;
13942 : 0 : wks->last_item |= MLX5_FLOW_ITEM_OUTER_INTEGRITY;
13943 : : }
13944 : 0 : return wks->last_item;
13945 : : }
13946 : :
13947 : : /**
13948 : : * Prepares DV flow counter with aging configuration.
13949 : : * Gets it by index when exists, creates a new one when doesn't.
13950 : : *
13951 : : * @param[in] dev
13952 : : * Pointer to rte_eth_dev structure.
13953 : : * @param[in] dev_flow
13954 : : * Pointer to the mlx5_flow.
13955 : : * @param[in, out] flow
13956 : : * Pointer to the sub flow.
13957 : : * @param[in] count
13958 : : * Pointer to the counter action configuration.
13959 : : * @param[in] age
13960 : : * Pointer to the aging action configuration.
13961 : : * @param[out] error
13962 : : * Pointer to the error structure.
13963 : : *
13964 : : * @return
13965 : : * Pointer to the counter, NULL otherwise.
13966 : : */
13967 : : static struct mlx5_flow_counter *
13968 : 0 : flow_dv_prepare_counter(struct rte_eth_dev *dev,
13969 : : struct mlx5_flow *dev_flow,
13970 : : struct rte_flow *flow,
13971 : : const struct rte_flow_action_count *count,
13972 : : const struct rte_flow_action_age *age,
13973 : : struct rte_flow_error *error)
13974 : : {
13975 [ # # ]: 0 : if (!flow->counter) {
13976 : 0 : flow->counter = flow_dv_translate_create_counter(dev, dev_flow,
13977 : : count, age);
13978 [ # # ]: 0 : if (!flow->counter) {
13979 : 0 : rte_flow_error_set(error, rte_errno,
13980 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
13981 : : "cannot create counter object.");
13982 : 0 : return NULL;
13983 : : }
13984 : : }
13985 [ # # ]: 0 : return flow_dv_counter_get_by_idx(dev, flow->counter, NULL);
13986 : : }
13987 : :
13988 : : /*
13989 : : * Release an ASO CT action by its own device.
13990 : : *
13991 : : * @param[in] dev
13992 : : * Pointer to the Ethernet device structure.
13993 : : * @param[in] idx
13994 : : * Index of ASO CT action to release.
13995 : : *
13996 : : * @return
13997 : : * 0 when CT action was removed, otherwise the number of references.
13998 : : */
13999 : : static inline int
14000 : 0 : flow_dv_aso_ct_dev_release(struct rte_eth_dev *dev, uint32_t idx)
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 : : uint32_t ret;
14005 : 0 : struct mlx5_aso_ct_action *ct = flow_aso_ct_get_by_dev_idx(dev, idx);
14006 : : enum mlx5_aso_ct_state state =
14007 : 0 : rte_atomic_load_explicit(&ct->state, rte_memory_order_relaxed);
14008 : :
14009 : : /* Cannot release when CT is in the ASO SQ. */
14010 [ # # ]: 0 : if (state == ASO_CONNTRACK_WAIT || state == ASO_CONNTRACK_QUERY)
14011 : : return -1;
14012 : 0 : ret = rte_atomic_fetch_sub_explicit(&ct->refcnt, 1, rte_memory_order_relaxed) - 1;
14013 [ # # ]: 0 : if (!ret) {
14014 [ # # ]: 0 : if (ct->dr_action_orig) {
14015 : : #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
14016 : 0 : claim_zero(mlx5_glue->destroy_flow_action
14017 : : (ct->dr_action_orig));
14018 : : #endif
14019 : 0 : ct->dr_action_orig = NULL;
14020 : : }
14021 [ # # ]: 0 : if (ct->dr_action_rply) {
14022 : : #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
14023 : 0 : claim_zero(mlx5_glue->destroy_flow_action
14024 : : (ct->dr_action_rply));
14025 : : #endif
14026 : 0 : ct->dr_action_rply = NULL;
14027 : : }
14028 : : /* Clear the state to free, no need in 1st allocation. */
14029 : 0 : MLX5_ASO_CT_UPDATE_STATE(ct, ASO_CONNTRACK_FREE);
14030 : 0 : rte_spinlock_lock(&mng->ct_sl);
14031 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free_cts, ct, next);
14032 : : rte_spinlock_unlock(&mng->ct_sl);
14033 : : }
14034 : 0 : return (int)ret;
14035 : : }
14036 : :
14037 : : static inline int
14038 : 0 : flow_dv_aso_ct_release(struct rte_eth_dev *dev, uint32_t own_idx,
14039 : : struct rte_flow_error *error)
14040 : : {
14041 : 0 : uint16_t owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(own_idx);
14042 : 0 : uint32_t idx = MLX5_INDIRECT_ACT_CT_GET_IDX(own_idx);
14043 : 0 : struct rte_eth_dev *owndev = &rte_eth_devices[owner];
14044 : : int ret;
14045 : :
14046 : : MLX5_ASSERT(owner < RTE_MAX_ETHPORTS);
14047 [ # # ]: 0 : if (dev->data->dev_started != 1)
14048 : 0 : return rte_flow_error_set(error, EAGAIN,
14049 : : RTE_FLOW_ERROR_TYPE_ACTION,
14050 : : NULL,
14051 : : "Indirect CT action cannot be destroyed when the port is stopped");
14052 : 0 : ret = flow_dv_aso_ct_dev_release(owndev, idx);
14053 [ # # ]: 0 : if (ret < 0)
14054 : 0 : return rte_flow_error_set(error, EAGAIN,
14055 : : RTE_FLOW_ERROR_TYPE_ACTION,
14056 : : NULL,
14057 : : "Current state prevents indirect CT action from being destroyed");
14058 : : return ret;
14059 : : }
14060 : :
14061 : : /*
14062 : : * Resize the ASO CT pools array by 64 pools.
14063 : : *
14064 : : * @param[in] dev
14065 : : * Pointer to the Ethernet device structure.
14066 : : *
14067 : : * @return
14068 : : * 0 on success, otherwise negative errno value and rte_errno is set.
14069 : : */
14070 : : static int
14071 : 0 : flow_dv_aso_ct_pools_resize(struct rte_eth_dev *dev)
14072 : : {
14073 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14074 : 0 : struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
14075 : 0 : void *old_pools = mng->pools;
14076 : : /* Magic number now, need a macro. */
14077 : 0 : uint32_t resize = mng->n + 64;
14078 : 0 : uint32_t mem_size = sizeof(struct mlx5_aso_ct_pool *) * resize;
14079 : 0 : void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
14080 : :
14081 [ # # ]: 0 : if (!pools) {
14082 : 0 : rte_errno = ENOMEM;
14083 : 0 : return -rte_errno;
14084 : : }
14085 : 0 : rte_rwlock_write_lock(&mng->resize_rwl);
14086 : : /* ASO SQ/QP was already initialized in the startup. */
14087 [ # # ]: 0 : if (old_pools) {
14088 : : /* Realloc could be an alternative choice. */
14089 : 0 : rte_memcpy(pools, old_pools,
14090 [ # # ]: 0 : mng->n * sizeof(struct mlx5_aso_ct_pool *));
14091 : 0 : mlx5_free(old_pools);
14092 : : }
14093 : 0 : mng->n = resize;
14094 : 0 : mng->pools = pools;
14095 : : rte_rwlock_write_unlock(&mng->resize_rwl);
14096 : 0 : return 0;
14097 : : }
14098 : :
14099 : : /*
14100 : : * Create and initialize a new ASO CT pool.
14101 : : *
14102 : : * @param[in] dev
14103 : : * Pointer to the Ethernet device structure.
14104 : : * @param[out] ct_free
14105 : : * Where to put the pointer of a new CT action.
14106 : : *
14107 : : * @return
14108 : : * The CT actions pool pointer and @p ct_free is set on success,
14109 : : * NULL otherwise and rte_errno is set.
14110 : : */
14111 : : static struct mlx5_aso_ct_pool *
14112 : 0 : flow_dv_ct_pool_create(struct rte_eth_dev *dev,
14113 : : struct mlx5_aso_ct_action **ct_free)
14114 : : {
14115 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14116 : 0 : struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
14117 : : struct mlx5_aso_ct_pool *pool = NULL;
14118 : : struct mlx5_devx_obj *obj = NULL;
14119 : : uint32_t i;
14120 : : uint32_t log_obj_size = rte_log2_u32(MLX5_ASO_CT_ACTIONS_PER_POOL);
14121 : : size_t mem_size;
14122 : :
14123 : 0 : obj = mlx5_devx_cmd_create_conn_track_offload_obj(priv->sh->cdev->ctx,
14124 : 0 : priv->sh->cdev->pdn,
14125 : : log_obj_size);
14126 [ # # ]: 0 : if (!obj) {
14127 : 0 : rte_errno = ENODATA;
14128 : 0 : DRV_LOG(ERR, "Failed to create conn_track_offload_obj using DevX.");
14129 : 0 : return NULL;
14130 : : }
14131 : : mem_size = sizeof(struct mlx5_aso_ct_action) *
14132 : : MLX5_ASO_CT_ACTIONS_PER_POOL +
14133 : : sizeof(*pool);
14134 : 0 : pool = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
14135 [ # # ]: 0 : if (!pool) {
14136 : 0 : rte_errno = ENOMEM;
14137 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
14138 : 0 : return NULL;
14139 : : }
14140 : 0 : pool->devx_obj = obj;
14141 : 0 : pool->index = mng->next;
14142 : : /* Resize pools array if there is no room for the new pool in it. */
14143 [ # # # # ]: 0 : if (pool->index == mng->n && flow_dv_aso_ct_pools_resize(dev)) {
14144 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
14145 : 0 : mlx5_free(pool);
14146 : 0 : return NULL;
14147 : : }
14148 : 0 : mng->pools[pool->index] = pool;
14149 : 0 : mng->next++;
14150 : : /* Assign the first action in the new pool, the rest go to free list. */
14151 : 0 : *ct_free = &pool->actions[0];
14152 : : /* Lock outside, the list operation is safe here. */
14153 [ # # ]: 0 : for (i = 1; i < MLX5_ASO_CT_ACTIONS_PER_POOL; i++) {
14154 : : /* refcnt is 0 when allocating the memory. */
14155 : 0 : pool->actions[i].offset = i;
14156 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free_cts, &pool->actions[i], next);
14157 : : }
14158 : : return pool;
14159 : : }
14160 : :
14161 : : /*
14162 : : * Allocate a ASO CT action from free list.
14163 : : *
14164 : : * @param[in] dev
14165 : : * Pointer to the Ethernet device structure.
14166 : : * @param[out] error
14167 : : * Pointer to the error structure.
14168 : : *
14169 : : * @return
14170 : : * Index to ASO CT action on success, 0 otherwise and rte_errno is set.
14171 : : */
14172 : : static uint32_t
14173 : 0 : flow_dv_aso_ct_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
14174 : : {
14175 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14176 : 0 : struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
14177 : 0 : struct mlx5_aso_ct_action *ct = NULL;
14178 : : struct mlx5_aso_ct_pool *pool;
14179 : : uint8_t reg_c;
14180 : : uint32_t ct_idx;
14181 : :
14182 : : MLX5_ASSERT(mng);
14183 [ # # ]: 0 : if (!priv->sh->cdev->config.devx) {
14184 : 0 : rte_errno = ENOTSUP;
14185 : 0 : return 0;
14186 : : }
14187 : : /* Get a free CT action, if no, a new pool will be created. */
14188 : 0 : rte_spinlock_lock(&mng->ct_sl);
14189 : 0 : ct = LIST_FIRST(&mng->free_cts);
14190 [ # # ]: 0 : if (ct) {
14191 [ # # ]: 0 : LIST_REMOVE(ct, next);
14192 [ # # ]: 0 : } else if (!flow_dv_ct_pool_create(dev, &ct)) {
14193 : : rte_spinlock_unlock(&mng->ct_sl);
14194 : 0 : rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
14195 : : NULL, "failed to create ASO CT pool");
14196 : 0 : return 0;
14197 : : }
14198 : : rte_spinlock_unlock(&mng->ct_sl);
14199 : 0 : pool = container_of(ct, struct mlx5_aso_ct_pool, actions[ct->offset]);
14200 : 0 : ct_idx = MLX5_MAKE_CT_IDX(pool->index, ct->offset);
14201 : : /* 0: inactive, 1: created, 2+: used by flows. */
14202 : 0 : rte_atomic_store_explicit(&ct->refcnt, 1, rte_memory_order_relaxed);
14203 : 0 : reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_CONNTRACK, 0, error);
14204 [ # # ]: 0 : if (!ct->dr_action_orig) {
14205 : : #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
14206 : 0 : ct->dr_action_orig = mlx5_glue->dv_create_flow_action_aso
14207 : 0 : (priv->sh->rx_domain, pool->devx_obj->obj,
14208 : : ct->offset,
14209 : : MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_INITIATOR,
14210 : 0 : reg_c - REG_C_0);
14211 : : #else
14212 : : RTE_SET_USED(reg_c);
14213 : : #endif
14214 [ # # ]: 0 : if (!ct->dr_action_orig) {
14215 : 0 : flow_dv_aso_ct_dev_release(dev, ct_idx);
14216 : 0 : rte_flow_error_set(error, rte_errno,
14217 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14218 : : "failed to create ASO CT action");
14219 : 0 : return 0;
14220 : : }
14221 : : }
14222 [ # # ]: 0 : if (!ct->dr_action_rply) {
14223 : : #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
14224 : 0 : ct->dr_action_rply = mlx5_glue->dv_create_flow_action_aso
14225 : 0 : (priv->sh->rx_domain, pool->devx_obj->obj,
14226 : : ct->offset,
14227 : : MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_RESPONDER,
14228 : 0 : reg_c - REG_C_0);
14229 : : #endif
14230 [ # # ]: 0 : if (!ct->dr_action_rply) {
14231 : 0 : flow_dv_aso_ct_dev_release(dev, ct_idx);
14232 : 0 : rte_flow_error_set(error, rte_errno,
14233 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14234 : : "failed to create ASO CT action");
14235 : 0 : return 0;
14236 : : }
14237 : : }
14238 : : return ct_idx;
14239 : : }
14240 : :
14241 : : /*
14242 : : * Create a conntrack object with context and actions by using ASO mechanism.
14243 : : *
14244 : : * @param[in] dev
14245 : : * Pointer to rte_eth_dev structure.
14246 : : * @param[in] pro
14247 : : * Pointer to conntrack information profile.
14248 : : * @param[out] error
14249 : : * Pointer to the error structure.
14250 : : *
14251 : : * @return
14252 : : * Index to conntrack object on success, 0 otherwise.
14253 : : */
14254 : : static uint32_t
14255 : 0 : flow_dv_translate_create_conntrack(struct rte_eth_dev *dev,
14256 : : const struct rte_flow_action_conntrack *pro,
14257 : : struct rte_flow_error *error)
14258 : : {
14259 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14260 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
14261 : : struct mlx5_aso_ct_action *ct;
14262 : : uint32_t idx;
14263 : :
14264 [ # # ]: 0 : if (!sh->ct_aso_en)
14265 : 0 : return rte_flow_error_set(error, ENOTSUP,
14266 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14267 : : "Connection is not supported");
14268 [ # # ]: 0 : if (dev->data->port_id >= MLX5_INDIRECT_ACT_CT_MAX_PORT) {
14269 : 0 : rte_flow_error_set(error, EINVAL,
14270 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14271 : : "CT supports port indexes up to "
14272 : : RTE_STR(MLX5_ACTION_CTX_CT_MAX_PORT));
14273 : 0 : return 0;
14274 : : }
14275 : 0 : idx = flow_dv_aso_ct_alloc(dev, error);
14276 [ # # ]: 0 : if (!idx)
14277 : 0 : return rte_flow_error_set(error, rte_errno,
14278 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14279 : : "Failed to allocate CT object");
14280 : 0 : ct = flow_aso_ct_get_by_dev_idx(dev, idx);
14281 [ # # ]: 0 : if (mlx5_aso_ct_update_by_wqe(sh, MLX5_HW_INV_QUEUE, ct, pro, NULL, true)) {
14282 : 0 : flow_dv_aso_ct_dev_release(dev, idx);
14283 : 0 : rte_flow_error_set(error, EBUSY,
14284 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14285 : : "Failed to update CT");
14286 : 0 : return 0;
14287 : : }
14288 : 0 : ct->is_original = !!pro->is_original_dir;
14289 : 0 : ct->peer = pro->peer_port;
14290 : 0 : return idx;
14291 : : }
14292 : :
14293 : : /**
14294 : : * Fill the flow matcher with DV spec.
14295 : : *
14296 : : * @param[in] dev
14297 : : * Pointer to rte_eth_dev structure.
14298 : : * @param[in] items
14299 : : * Pointer to the list of items.
14300 : : * @param[in] wks
14301 : : * Pointer to the matcher workspace.
14302 : : * @param[in] key
14303 : : * Pointer to the flow matcher key.
14304 : : * @param[in] key_type
14305 : : * Key type.
14306 : : * @param[out] error
14307 : : * Pointer to the error structure.
14308 : : *
14309 : : * @return
14310 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14311 : : */
14312 : : static int
14313 : 0 : flow_dv_translate_items(struct rte_eth_dev *dev,
14314 : : const struct rte_flow_item *items,
14315 : : struct mlx5_dv_matcher_workspace *wks,
14316 : : void *key, uint32_t key_type,
14317 : : struct rte_flow_error *error)
14318 : : {
14319 : 0 : struct mlx5_flow_rss_desc *rss_desc = wks->rss_desc;
14320 : 0 : uint8_t next_protocol = wks->next_protocol;
14321 : 0 : int tunnel = !!(wks->item_flags & MLX5_FLOW_LAYER_TUNNEL);
14322 : 0 : int item_type = items->type;
14323 : 0 : uint64_t last_item = wks->last_item;
14324 : : enum mlx5_l3_tunnel_detection l3_tunnel_detection;
14325 : : uint64_t l3_tunnel_flag;
14326 : : int ret;
14327 : :
14328 [ # # # # : 0 : switch (item_type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
14329 : 0 : case RTE_FLOW_ITEM_TYPE_ESP:
14330 : 0 : flow_dv_translate_item_esp(key, items, tunnel, key_type, wks->item_flags);
14331 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14332 : : last_item = MLX5_FLOW_ITEM_ESP;
14333 : 0 : break;
14334 : 0 : case RTE_FLOW_ITEM_TYPE_PORT_ID:
14335 : 0 : flow_dv_translate_item_port_id
14336 : : (dev, key, items, wks->attr, key_type);
14337 : : last_item = MLX5_FLOW_ITEM_PORT_ID;
14338 : 0 : break;
14339 : 0 : case RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR:
14340 : 0 : flow_dv_translate_item_port_representor
14341 : : (dev, key, key_type);
14342 : : last_item = MLX5_FLOW_ITEM_PORT_REPRESENTOR;
14343 : 0 : break;
14344 : 0 : case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
14345 : 0 : flow_dv_translate_item_represented_port
14346 : : (dev, key, items, wks->attr, key_type);
14347 : : last_item = MLX5_FLOW_ITEM_REPRESENTED_PORT;
14348 : 0 : break;
14349 : 0 : case RTE_FLOW_ITEM_TYPE_ETH:
14350 : 0 : flow_dv_translate_item_eth(key, items, tunnel,
14351 : : wks->group, key_type);
14352 [ # # ]: 0 : wks->priority = wks->action_flags &
14353 : 0 : MLX5_FLOW_ACTION_DEFAULT_MISS &&
14354 [ # # ]: 0 : !wks->external ?
14355 : : MLX5_PRIORITY_MAP_L3 :
14356 : : MLX5_PRIORITY_MAP_L2;
14357 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
14358 : : MLX5_FLOW_LAYER_OUTER_L2;
14359 : : break;
14360 : 0 : case RTE_FLOW_ITEM_TYPE_VLAN:
14361 : 0 : flow_dv_translate_item_vlan(key, items, tunnel, wks, key_type);
14362 : 0 : wks->priority = MLX5_PRIORITY_MAP_L2;
14363 : : last_item = tunnel ? (MLX5_FLOW_LAYER_INNER_L2 |
14364 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_VLAN) :
14365 : : (MLX5_FLOW_LAYER_OUTER_L2 |
14366 : : MLX5_FLOW_LAYER_OUTER_VLAN);
14367 : : break;
14368 : : case RTE_FLOW_ITEM_TYPE_IPV4:
14369 : : next_protocol = mlx5_flow_l3_next_protocol(items, key_type);
14370 : : l3_tunnel_detection =
14371 : : mlx5_flow_tunnel_ip_check(items, next_protocol,
14372 : : wks->item_flags,
14373 : : &l3_tunnel_flag);
14374 : : if (l3_tunnel_detection == l3_tunnel_inner) {
14375 : 0 : wks->item_flags |= l3_tunnel_flag;
14376 : : tunnel = 1;
14377 : : }
14378 : 0 : flow_dv_translate_item_ipv4(key, items, tunnel,
14379 : : wks->group, key_type);
14380 : 0 : wks->priority = MLX5_PRIORITY_MAP_L3;
14381 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
14382 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4;
14383 [ # # ]: 0 : if (l3_tunnel_detection == l3_tunnel_outer)
14384 : 0 : wks->item_flags |= l3_tunnel_flag;
14385 : : break;
14386 : : case RTE_FLOW_ITEM_TYPE_IPV6:
14387 : : next_protocol = mlx5_flow_l3_next_protocol(items, key_type);
14388 : : l3_tunnel_detection =
14389 : : mlx5_flow_tunnel_ip_check(items, next_protocol,
14390 : : wks->item_flags,
14391 : : &l3_tunnel_flag);
14392 : : if (l3_tunnel_detection == l3_tunnel_inner) {
14393 : 0 : wks->item_flags |= l3_tunnel_flag;
14394 : : tunnel = 1;
14395 : : }
14396 : 0 : flow_dv_translate_item_ipv6(key, items, tunnel,
14397 : : wks->group, key_type);
14398 : 0 : wks->priority = MLX5_PRIORITY_MAP_L3;
14399 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
14400 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6;
14401 [ # # ]: 0 : if (l3_tunnel_detection == l3_tunnel_outer)
14402 : 0 : wks->item_flags |= l3_tunnel_flag;
14403 : : break;
14404 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
14405 : 0 : flow_dv_translate_item_ipv6_frag_ext
14406 : : (key, items, tunnel, key_type);
14407 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
14408 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
14409 : : next_protocol = mlx5_flow_l3_next_protocol(items, key_type);
14410 : : break;
14411 : 0 : case RTE_FLOW_ITEM_TYPE_TCP:
14412 : 0 : flow_dv_translate_item_tcp(key, items, tunnel, key_type);
14413 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14414 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
14415 : : MLX5_FLOW_LAYER_OUTER_L4_TCP;
14416 : : break;
14417 : 0 : case RTE_FLOW_ITEM_TYPE_UDP:
14418 : 0 : flow_dv_translate_item_udp(key, items, tunnel, wks, key_type);
14419 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14420 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
14421 : : MLX5_FLOW_LAYER_OUTER_L4_UDP;
14422 : : break;
14423 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
14424 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14425 : 0 : wks->tunnel_item = items;
14426 : 0 : wks->gre_item = items;
14427 : : last_item = MLX5_FLOW_LAYER_GRE;
14428 : 0 : break;
14429 : 0 : case RTE_FLOW_ITEM_TYPE_GRE_KEY:
14430 : 0 : flow_dv_translate_item_gre_key(key, items, key_type);
14431 : : last_item = MLX5_FLOW_LAYER_GRE_KEY;
14432 : 0 : break;
14433 : 0 : case RTE_FLOW_ITEM_TYPE_GRE_OPTION:
14434 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14435 : 0 : wks->tunnel_item = items;
14436 : : last_item = MLX5_FLOW_LAYER_GRE;
14437 : 0 : break;
14438 : 0 : case RTE_FLOW_ITEM_TYPE_NVGRE:
14439 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14440 : 0 : wks->tunnel_item = items;
14441 : : last_item = MLX5_FLOW_LAYER_GRE;
14442 : 0 : break;
14443 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN:
14444 : 0 : flow_dv_translate_item_vxlan(dev, wks->attr, key,
14445 : : items, tunnel, wks, key_type);
14446 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14447 : : last_item = MLX5_FLOW_LAYER_VXLAN;
14448 : 0 : break;
14449 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
14450 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14451 : 0 : wks->tunnel_item = items;
14452 : : last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
14453 : 0 : break;
14454 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE:
14455 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14456 : 0 : wks->tunnel_item = items;
14457 : : last_item = MLX5_FLOW_LAYER_GENEVE;
14458 : 0 : break;
14459 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
14460 : 0 : ret = flow_dv_translate_item_geneve_opt
14461 : : (dev, key, items, key_type, error);
14462 [ # # ]: 0 : if (ret)
14463 : 0 : return rte_flow_error_set(error, -ret,
14464 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14465 : : "cannot create GENEVE TLV option");
14466 : 0 : wks->geneve_tlv_option = 1;
14467 : : last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
14468 : 0 : break;
14469 : 0 : case RTE_FLOW_ITEM_TYPE_MPLS:
14470 : 0 : flow_dv_translate_item_mpls(key, items, last_item,
14471 : : tunnel, key_type);
14472 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14473 : : last_item = MLX5_FLOW_LAYER_MPLS;
14474 : 0 : break;
14475 : 0 : case RTE_FLOW_ITEM_TYPE_MARK:
14476 : 0 : flow_dv_translate_item_mark(dev, key, items, key_type);
14477 : : last_item = MLX5_FLOW_ITEM_MARK;
14478 : 0 : break;
14479 : 0 : case RTE_FLOW_ITEM_TYPE_META:
14480 : 0 : flow_dv_translate_item_meta
14481 : : (dev, key, wks->attr, items, key_type);
14482 : : last_item = MLX5_FLOW_ITEM_METADATA;
14483 : 0 : break;
14484 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP:
14485 : 0 : flow_dv_translate_item_icmp(key, items, tunnel, key_type);
14486 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14487 : : last_item = MLX5_FLOW_LAYER_ICMP;
14488 : 0 : break;
14489 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6:
14490 : 0 : flow_dv_translate_item_icmp6(key, items, tunnel, key_type);
14491 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14492 : : last_item = MLX5_FLOW_LAYER_ICMP6;
14493 : 0 : break;
14494 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REQUEST:
14495 : : case RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REPLY:
14496 : 0 : flow_dv_translate_item_icmp6_echo(key, items, tunnel, key_type);
14497 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14498 : : last_item = MLX5_FLOW_LAYER_ICMP6;
14499 : 0 : break;
14500 : 0 : case RTE_FLOW_ITEM_TYPE_TAG:
14501 : 0 : ret = flow_dv_translate_item_tag(dev, key, items, key_type);
14502 [ # # ]: 0 : if (ret < 0)
14503 : 0 : return rte_flow_error_set(error, -ret, RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14504 : : "invalid flow tag item");
14505 : : last_item = MLX5_FLOW_ITEM_TAG;
14506 : : break;
14507 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
14508 : 0 : flow_dv_translate_mlx5_item_tag(dev, key, items, key_type);
14509 : : last_item = MLX5_FLOW_ITEM_TAG;
14510 : 0 : break;
14511 : 0 : case RTE_FLOW_ITEM_TYPE_TX_QUEUE:
14512 : 0 : ret = flow_dv_translate_item_tx_queue(dev, key, items, key_type);
14513 [ # # ]: 0 : if (ret)
14514 : 0 : return rte_flow_error_set(error, -ret,
14515 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14516 : : "invalid tx_queue item");
14517 : : last_item = MLX5_FLOW_ITEM_SQ;
14518 : : break;
14519 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_SQ:
14520 : 0 : flow_dv_translate_item_sq(key, items, key_type);
14521 : : last_item = MLX5_FLOW_ITEM_SQ;
14522 : 0 : break;
14523 : 0 : case RTE_FLOW_ITEM_TYPE_GTP:
14524 : 0 : flow_dv_translate_item_gtp(key, items, tunnel, key_type);
14525 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14526 : : last_item = MLX5_FLOW_LAYER_GTP;
14527 : 0 : break;
14528 : 0 : case RTE_FLOW_ITEM_TYPE_GTP_PSC:
14529 : 0 : ret = flow_dv_translate_item_gtp_psc(key, items, key_type);
14530 [ # # ]: 0 : if (ret)
14531 : 0 : return rte_flow_error_set(error, -ret,
14532 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14533 : : "cannot create GTP PSC item");
14534 : : last_item = MLX5_FLOW_LAYER_GTP_PSC;
14535 : : break;
14536 : 0 : case RTE_FLOW_ITEM_TYPE_ECPRI:
14537 [ # # ]: 0 : if (!mlx5_flex_parser_ecpri_exist(dev)) {
14538 : : /* Create it only the first time to be used. */
14539 : 0 : ret = mlx5_flex_parser_ecpri_alloc(dev);
14540 [ # # ]: 0 : if (ret)
14541 : 0 : return rte_flow_error_set
14542 : : (error, -ret,
14543 : : RTE_FLOW_ERROR_TYPE_ITEM,
14544 : : NULL,
14545 : : "cannot create eCPRI parser");
14546 : : }
14547 : 0 : flow_dv_translate_item_ecpri
14548 : : (dev, key, items, wks, last_item, key_type);
14549 : : /* No other protocol should follow eCPRI layer. */
14550 : : last_item = MLX5_FLOW_LAYER_ECPRI;
14551 : 0 : break;
14552 : 0 : case RTE_FLOW_ITEM_TYPE_METER_COLOR:
14553 : 0 : flow_dv_translate_item_meter_color(dev, key, items, key_type);
14554 : : last_item = MLX5_FLOW_ITEM_METER_COLOR;
14555 : 0 : break;
14556 [ # # ]: 0 : case RTE_FLOW_ITEM_TYPE_INTEGRITY:
14557 : : last_item = flow_dv_translate_item_integrity(items,
14558 : : wks, key_type);
14559 : 0 : break;
14560 : 0 : case RTE_FLOW_ITEM_TYPE_AGGR_AFFINITY:
14561 : 0 : flow_dv_translate_item_aggr_affinity(key, items, key_type);
14562 : : last_item = MLX5_FLOW_ITEM_AGGR_AFFINITY;
14563 : 0 : break;
14564 : 0 : case RTE_FLOW_ITEM_TYPE_IB_BTH:
14565 : 0 : flow_dv_translate_item_ib_bth(key, items, tunnel, key_type);
14566 : : last_item = MLX5_FLOW_ITEM_IB_BTH;
14567 : 0 : break;
14568 : 0 : case RTE_FLOW_ITEM_TYPE_NSH:
14569 : : last_item = MLX5_FLOW_ITEM_NSH;
14570 : 0 : break;
14571 : : default:
14572 : : break;
14573 : : }
14574 : 0 : wks->item_flags |= last_item;
14575 : 0 : wks->last_item = last_item;
14576 : 0 : wks->next_protocol = next_protocol;
14577 : 0 : return 0;
14578 : : }
14579 : :
14580 : : static int
14581 : 0 : flow_dv_translate_items_geneve_opt_nta(struct rte_eth_dev *dev,
14582 : : const struct rte_flow_item *items,
14583 : : struct mlx5_flow_attr *attr,
14584 : : struct rte_flow_error *error)
14585 : : {
14586 : 0 : rte_be32_t geneve_mask = 0xffffffff;
14587 : 0 : struct rte_pmd_mlx5_geneve_tlv geneve_tlv = {
14588 : : /* Take from item spec, if changed, destroy and add new parser. */
14589 : : .option_class = 0,
14590 : : /* Take from item spec, if changed, destroy and add new parser. */
14591 : : .option_type = 0,
14592 : : /* 1DW is supported. */
14593 : : .option_len = 1,
14594 : : .match_on_class_mode = 1,
14595 : : .offset = 0,
14596 : : .sample_len = 1,
14597 : : .match_data_mask = &geneve_mask
14598 : : };
14599 : 0 : const struct rte_flow_item_geneve_opt *geneve_opt_v = items->spec;
14600 : 0 : const struct rte_flow_item_geneve_opt *geneve_opt_m = items->mask;
14601 : : void *geneve_parser;
14602 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14603 : : #ifdef RTE_PMD_MLX5_DEBUG
14604 : : struct mlx5_geneve_tlv_option *option;
14605 : : #endif
14606 : :
14607 : : /* option length is not as supported. */
14608 [ # # ]: 0 : if ((geneve_opt_v->option_len & geneve_opt_m->option_len) > geneve_tlv.option_len)
14609 : 0 : return rte_flow_error_set(error, ENOTSUP,
14610 : : RTE_FLOW_ERROR_TYPE_ITEM, items,
14611 : : " GENEVE OPT length is not supported ");
14612 : 0 : geneve_tlv.option_class = geneve_opt_v->option_class & geneve_opt_m->option_class;
14613 : 0 : geneve_tlv.option_type = geneve_opt_v->option_type & geneve_opt_m->option_type;
14614 : : /* if parser doesn't exist */
14615 [ # # ]: 0 : if (!priv->tlv_options) {
14616 : : /* Create a GENEVE option parser. */
14617 : 0 : geneve_parser = mlx5_geneve_tlv_parser_create(attr->port_id,
14618 : : &geneve_tlv, 1);
14619 [ # # ]: 0 : if (!geneve_parser)
14620 : 0 : return rte_flow_error_set(error, EINVAL,
14621 : : RTE_FLOW_ERROR_TYPE_ITEM, items,
14622 : : " GENEVE OPT parser creation failed ");
14623 : : #ifdef RTE_PMD_MLX5_DEBUG
14624 : : } else {
14625 : : /* Check if option exist in current parser. */
14626 : : option = mlx5_geneve_tlv_option_get(priv,
14627 : : geneve_tlv.option_type,
14628 : : geneve_tlv.option_class);
14629 : : if (!option)
14630 : : return rte_flow_error_set(error, EINVAL,
14631 : : RTE_FLOW_ERROR_TYPE_ITEM, items,
14632 : : " GENEVE OPT configured does not match this rule class/type");
14633 : : #endif
14634 : : }
14635 : : return 0;
14636 : : }
14637 : :
14638 : : /**
14639 : : * Fill the flow matcher with DV spec for items supported in non template mode.
14640 : : *
14641 : : * @param[in] dev
14642 : : * Pointer to rte_eth_dev structure.
14643 : : * @param[in] items
14644 : : * Pointer to the list of items.
14645 : : * @param[in] wks
14646 : : * Pointer to the matcher workspace.
14647 : : * @param[in] key
14648 : : * Pointer to the flow matcher key.
14649 : : * @param[in] key_type
14650 : : * Key type.
14651 : : * @param[out] error
14652 : : * Pointer to the error structure.
14653 : : *
14654 : : * @return
14655 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14656 : : */
14657 : : static int
14658 : 0 : flow_dv_translate_items_nta(struct rte_eth_dev *dev,
14659 : : const struct rte_flow_item *items,
14660 : : struct mlx5_dv_matcher_workspace *wks,
14661 : : void *key, uint32_t key_type,
14662 : : struct mlx5_flow_attr *attr,
14663 : : struct rte_flow_error *error)
14664 : : {
14665 : : int item_type;
14666 : : int ret = 0;
14667 : : int tunnel;
14668 : : /* Dummy structure to enable the key calculation for flex item. */
14669 : : struct mlx5_flow_dv_match_params flex_item_key;
14670 : :
14671 : 0 : tunnel = !!(wks->item_flags & MLX5_FLOW_LAYER_TUNNEL);
14672 : 0 : item_type = items->type;
14673 [ # # # # ]: 0 : switch (item_type) {
14674 : 0 : case RTE_FLOW_ITEM_TYPE_CONNTRACK:
14675 : 0 : flow_dv_translate_item_aso_ct(dev, key, NULL, items);
14676 : 0 : wks->last_item = MLX5_FLOW_LAYER_ASO_CT;
14677 : 0 : break;
14678 : : /* TODO: remove once flex item translation is added to flow_dv_translate_items. */
14679 : 0 : case RTE_FLOW_ITEM_TYPE_FLEX:
14680 : 0 : mlx5_flex_flow_translate_item(dev, key, flex_item_key.buf, items, tunnel != 0);
14681 [ # # ]: 0 : wks->last_item = tunnel ? MLX5_FLOW_ITEM_INNER_FLEX : MLX5_FLOW_ITEM_OUTER_FLEX;
14682 : 0 : break;
14683 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
14684 : 0 : ret = flow_dv_translate_items_geneve_opt_nta(dev, items, attr, error);
14685 [ # # ]: 0 : if (ret)
14686 : : return ret;
14687 : 0 : wks->last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
14688 : 0 : break;
14689 : 0 : default:
14690 : 0 : ret = flow_dv_translate_items(dev, items, wks, key, key_type, error);
14691 [ # # ]: 0 : if (ret)
14692 : : return ret;
14693 : : break;
14694 : : }
14695 : 0 : wks->item_flags |= wks->last_item;
14696 : 0 : return 0;
14697 : : }
14698 : :
14699 : : /**
14700 : : * Fill the HW steering flow with DV spec.
14701 : : *
14702 : : * @param[in] items
14703 : : * Pointer to the list of items.
14704 : : * @param[in] attr
14705 : : * Pointer to the flow attributes.
14706 : : * @param[in] key
14707 : : * Pointer to the flow matcher key.
14708 : : * @param[in] key_type
14709 : : * Key type.
14710 : : * @param[in, out] item_flags
14711 : : * Pointer to the flow item flags.
14712 : : * @param[in, out] nt_flow
14713 : : * Non template flow.
14714 : : * @param[out] error
14715 : : * Pointer to the error structure.
14716 : : *
14717 : : * @return
14718 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14719 : : */
14720 : : int
14721 : 0 : mlx5_flow_dv_translate_items_hws_impl(const struct rte_flow_item *items,
14722 : : struct mlx5_flow_attr *attr, void *key,
14723 : : uint32_t key_type, uint64_t *item_flags,
14724 : : uint8_t *match_criteria,
14725 : : bool nt_flow,
14726 : : struct rte_flow_error *error)
14727 : : {
14728 : 0 : struct mlx5_flow_workspace *flow_wks = mlx5_flow_push_thread_workspace();
14729 : 0 : struct mlx5_flow_rss_desc rss_desc = { .level = attr->rss_level };
14730 : 0 : struct rte_flow_attr rattr = {
14731 : 0 : .group = attr->group,
14732 : 0 : .priority = attr->priority,
14733 : 0 : .ingress = !!(attr->tbl_type == MLX5DR_TABLE_TYPE_NIC_RX),
14734 : 0 : .egress = !!(attr->tbl_type == MLX5DR_TABLE_TYPE_NIC_TX),
14735 : 0 : .transfer = !!(attr->tbl_type == MLX5DR_TABLE_TYPE_FDB),
14736 : : };
14737 : 0 : struct mlx5_dv_matcher_workspace wks = {
14738 : 0 : .action_flags = attr->act_flags,
14739 [ # # ]: 0 : .item_flags = item_flags ? *item_flags : 0,
14740 : : .external = 0,
14741 : : .next_protocol = 0xff,
14742 : : .attr = &rattr,
14743 : : .rss_desc = &rss_desc,
14744 : : .group = attr->group,
14745 : 0 : .p_root_flags = &attr->hws_root_match_flags,
14746 : : };
14747 : : int ret = 0;
14748 : :
14749 : : RTE_SET_USED(flow_wks);
14750 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
14751 : : if (!mlx5_flow_os_item_supported(items->type)) {
14752 : : ret = rte_flow_error_set(error, ENOTSUP,
14753 : : RTE_FLOW_ERROR_TYPE_ITEM,
14754 : : NULL, "item not supported");
14755 : : goto exit;
14756 : : }
14757 : : /* Non template flow. */
14758 [ # # ]: 0 : if (nt_flow) {
14759 : 0 : ret = flow_dv_translate_items_nta(&rte_eth_devices[attr->port_id],
14760 : : items, &wks, key, key_type, attr, error);
14761 [ # # ]: 0 : if (ret)
14762 : 0 : goto exit;
14763 : : } else {
14764 : 0 : ret = flow_dv_translate_items(&rte_eth_devices[attr->port_id],
14765 : : items, &wks, key, key_type, error);
14766 [ # # ]: 0 : if (ret)
14767 : 0 : goto exit;
14768 : : }
14769 : : }
14770 [ # # ]: 0 : if (wks.item_flags & MLX5_FLOW_ITEM_INTEGRITY) {
14771 : 0 : flow_dv_translate_item_integrity_post(key,
14772 : : wks.integrity_items,
14773 : : wks.item_flags,
14774 : : key_type);
14775 : : }
14776 [ # # ]: 0 : if (wks.item_flags & MLX5_FLOW_LAYER_VXLAN_GPE) {
14777 [ # # ]: 0 : if (wks.tunnel_item)
14778 : 0 : flow_dv_translate_item_vxlan_gpe(key,
14779 : : wks.tunnel_item,
14780 : : wks.item_flags,
14781 : : key_type);
14782 [ # # ]: 0 : } else if (wks.item_flags & MLX5_FLOW_LAYER_GENEVE) {
14783 [ # # ]: 0 : if (wks.tunnel_item)
14784 : 0 : flow_dv_translate_item_geneve(key,
14785 : : wks.tunnel_item,
14786 : : wks.item_flags,
14787 : : key_type);
14788 [ # # ]: 0 : } else if (wks.item_flags & MLX5_FLOW_LAYER_GRE) {
14789 [ # # # # ]: 0 : if (wks.tunnel_item && wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE) {
14790 : 0 : flow_dv_translate_item_gre(key,
14791 : : wks.tunnel_item,
14792 : : wks.item_flags,
14793 : : key_type);
14794 [ # # ]: 0 : } else if (wks.tunnel_item &&
14795 [ # # ]: 0 : wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE_OPTION) {
14796 : 0 : flow_dv_translate_item_gre_option(key,
14797 : : wks.tunnel_item,
14798 : : wks.gre_item,
14799 : : wks.item_flags,
14800 : : key_type);
14801 [ # # # # ]: 0 : } else if (wks.tunnel_item && wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_NVGRE) {
14802 : 0 : flow_dv_translate_item_nvgre(key,
14803 : : wks.tunnel_item,
14804 : : wks.item_flags,
14805 : : key_type);
14806 : : } else {
14807 : : MLX5_ASSERT(false);
14808 : : }
14809 : : }
14810 : :
14811 [ # # ]: 0 : if (match_criteria)
14812 : 0 : *match_criteria = flow_dv_matcher_enable(key);
14813 [ # # ]: 0 : if (item_flags)
14814 : 0 : *item_flags = wks.item_flags;
14815 : 0 : exit:
14816 : 0 : mlx5_flow_pop_thread_workspace();
14817 : 0 : return ret;
14818 : : }
14819 : :
14820 : : /**
14821 : : * Fill the HW steering flow with DV spec.
14822 : : * This function assumes given flow is created from template API.
14823 : : *
14824 : : * @param[in] items
14825 : : * Pointer to the list of items.
14826 : : * @param[in] attr
14827 : : * Pointer to the flow attributes.
14828 : : * @param[in] key
14829 : : * Pointer to the flow matcher key.
14830 : : * @param[in] key_type
14831 : : * Key type.
14832 : : * @param[in, out] item_flags
14833 : : * Pointer to the flow item flags.
14834 : : * @param[out] error
14835 : : * Pointer to the error structure.
14836 : : *
14837 : : * @return
14838 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14839 : : */
14840 : : int
14841 : 0 : mlx5_flow_dv_translate_items_hws(const struct rte_flow_item *items,
14842 : : struct mlx5_flow_attr *attr, void *key,
14843 : : uint32_t key_type, uint64_t *item_flags,
14844 : : uint8_t *match_criteria,
14845 : : struct rte_flow_error *error)
14846 : : {
14847 : 0 : return mlx5_flow_dv_translate_items_hws_impl(items, attr, key, key_type, item_flags,
14848 : : match_criteria, false, error);
14849 : : }
14850 : :
14851 : : /**
14852 : : * Fill the SW steering flow with DV spec.
14853 : : *
14854 : : * @param[in] dev
14855 : : * Pointer to rte_eth_dev structure.
14856 : : * @param[in, out] dev_flow
14857 : : * Pointer to the sub flow.
14858 : : * @param[in] attr
14859 : : * Pointer to the flow attributes.
14860 : : * @param[in] items
14861 : : * Pointer to the list of items.
14862 : : * @param[in, out] matcher
14863 : : * Pointer to the flow matcher.
14864 : : * @param[out] error
14865 : : * Pointer to the error structure.
14866 : : *
14867 : : * @return
14868 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14869 : : */
14870 : : static int
14871 : 0 : flow_dv_translate_items_sws(struct rte_eth_dev *dev,
14872 : : struct mlx5_flow *dev_flow,
14873 : : const struct rte_flow_attr *attr,
14874 : : const struct rte_flow_item *items,
14875 : : struct mlx5_flow_dv_matcher *matcher,
14876 : : struct rte_flow_error *error)
14877 : : {
14878 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14879 : 0 : void *match_mask = matcher->mask.buf;
14880 : 0 : void *match_value = dev_flow->dv.value.buf;
14881 : 0 : struct mlx5_dv_matcher_workspace wks = {
14882 : 0 : .action_flags = dev_flow->act_flags,
14883 : : .item_flags = 0,
14884 : 0 : .external = dev_flow->external,
14885 : : .next_protocol = 0xff,
14886 : 0 : .group = dev_flow->dv.group,
14887 : : .attr = attr,
14888 : 0 : .rss_desc = &((struct mlx5_flow_workspace *)
14889 : : mlx5_flow_get_thread_workspace())->rss_desc,
14890 : : };
14891 : 0 : struct mlx5_dv_matcher_workspace wks_m = wks;
14892 : : int item_type;
14893 : : int ret = 0;
14894 : : int tunnel;
14895 : :
14896 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
14897 : 0 : if (!mlx5_flow_os_item_supported(items->type))
14898 : : return rte_flow_error_set(error, ENOTSUP,
14899 : : RTE_FLOW_ERROR_TYPE_ITEM,
14900 : : NULL, "item not supported");
14901 : 0 : tunnel = !!(wks.item_flags & MLX5_FLOW_LAYER_TUNNEL);
14902 : : item_type = items->type;
14903 [ # # # # : 0 : switch (item_type) {
# ]
14904 : 0 : case RTE_FLOW_ITEM_TYPE_CONNTRACK:
14905 : 0 : flow_dv_translate_item_aso_ct(dev, match_mask,
14906 : : match_value, items);
14907 : 0 : wks.last_item = MLX5_FLOW_LAYER_ASO_CT;
14908 : 0 : break;
14909 : 0 : case RTE_FLOW_ITEM_TYPE_FLEX:
14910 : 0 : flow_dv_translate_item_flex(dev, match_mask,
14911 : : match_value, items,
14912 : : dev_flow, tunnel != 0);
14913 [ # # ]: 0 : wks.last_item = tunnel ? MLX5_FLOW_ITEM_INNER_FLEX :
14914 : : MLX5_FLOW_ITEM_OUTER_FLEX;
14915 : 0 : break;
14916 : 0 : case RTE_FLOW_ITEM_TYPE_TX_QUEUE:
14917 : 0 : ret = flow_dv_translate_item_tx_queue(dev, match_value, items,
14918 : : MLX5_SET_MATCHER_SW_V);
14919 [ # # ]: 0 : if (ret)
14920 : 0 : return rte_flow_error_set(error, -ret,
14921 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14922 : : "invalid tx_queue item spec");
14923 : 0 : ret = flow_dv_translate_item_tx_queue(dev, match_mask, items,
14924 : : MLX5_SET_MATCHER_SW_M);
14925 [ # # ]: 0 : if (ret)
14926 : 0 : return rte_flow_error_set(error, -ret,
14927 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14928 : : "invalid tx_queue item mask");
14929 : : break;
14930 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_SQ:
14931 : 0 : flow_dv_translate_item_sq(match_value, items,
14932 : : MLX5_SET_MATCHER_SW_V);
14933 : 0 : flow_dv_translate_item_sq(match_mask, items,
14934 : : MLX5_SET_MATCHER_SW_M);
14935 : 0 : break;
14936 : 0 : default:
14937 : 0 : ret = flow_dv_translate_items(dev, items, &wks_m,
14938 : : match_mask, MLX5_SET_MATCHER_SW_M, error);
14939 [ # # ]: 0 : if (ret)
14940 : 0 : return ret;
14941 : 0 : ret = flow_dv_translate_items(dev, items, &wks,
14942 : : match_value, MLX5_SET_MATCHER_SW_V, error);
14943 [ # # ]: 0 : if (ret)
14944 : 0 : return ret;
14945 : : break;
14946 : : }
14947 : 0 : wks.item_flags |= wks.last_item;
14948 : : }
14949 : : /*
14950 : : * When E-Switch mode is enabled, we have two cases where we need to
14951 : : * set the source port manually.
14952 : : * The first one, is in case of NIC ingress steering rule, and the
14953 : : * second is E-Switch rule where no port_id item was found.
14954 : : * In both cases the source port is set according the current port
14955 : : * in use.
14956 : : */
14957 : 0 : if (!(wks.item_flags & MLX5_FLOW_ITEM_PORT_ID) &&
14958 [ # # ]: 0 : !(wks.item_flags & MLX5_FLOW_ITEM_REPRESENTED_PORT) &&
14959 : 0 : !(wks.item_flags & MLX5_FLOW_ITEM_PORT_REPRESENTOR) &&
14960 [ # # ]: 0 : priv->sh->esw_mode &&
14961 [ # # ]: 0 : !attr->egress &&
14962 [ # # ]: 0 : attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP) {
14963 [ # # ]: 0 : if (flow_dv_translate_item_port_id_all(dev, match_mask,
14964 : : match_value, NULL, attr))
14965 : 0 : return -rte_errno;
14966 : : }
14967 [ # # ]: 0 : if (wks.item_flags & MLX5_FLOW_ITEM_INTEGRITY) {
14968 : 0 : flow_dv_translate_item_integrity_post(match_mask,
14969 : : wks_m.integrity_items,
14970 : : wks_m.item_flags,
14971 : : MLX5_SET_MATCHER_SW_M);
14972 : 0 : flow_dv_translate_item_integrity_post(match_value,
14973 : : wks.integrity_items,
14974 : : wks.item_flags,
14975 : : MLX5_SET_MATCHER_SW_V);
14976 : : }
14977 [ # # ]: 0 : if (wks.item_flags & MLX5_FLOW_LAYER_VXLAN_GPE) {
14978 : 0 : flow_dv_translate_item_vxlan_gpe(match_mask,
14979 : : wks.tunnel_item,
14980 : : wks.item_flags,
14981 : : MLX5_SET_MATCHER_SW_M);
14982 : 0 : flow_dv_translate_item_vxlan_gpe(match_value,
14983 : : wks.tunnel_item,
14984 : : wks.item_flags,
14985 : : MLX5_SET_MATCHER_SW_V);
14986 [ # # ]: 0 : } else if (wks.item_flags & MLX5_FLOW_LAYER_GENEVE) {
14987 : 0 : flow_dv_translate_item_geneve(match_mask,
14988 : : wks.tunnel_item,
14989 : : wks.item_flags,
14990 : : MLX5_SET_MATCHER_SW_M);
14991 : 0 : flow_dv_translate_item_geneve(match_value,
14992 : : wks.tunnel_item,
14993 : : wks.item_flags,
14994 : : MLX5_SET_MATCHER_SW_V);
14995 [ # # ]: 0 : } else if (wks.item_flags & MLX5_FLOW_LAYER_GRE) {
14996 [ # # ]: 0 : if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE) {
14997 : 0 : flow_dv_translate_item_gre(match_mask,
14998 : : wks.tunnel_item,
14999 : : wks.item_flags,
15000 : : MLX5_SET_MATCHER_SW_M);
15001 : 0 : flow_dv_translate_item_gre(match_value,
15002 : : wks.tunnel_item,
15003 : : wks.item_flags,
15004 : : MLX5_SET_MATCHER_SW_V);
15005 [ # # ]: 0 : } else if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_NVGRE) {
15006 : 0 : flow_dv_translate_item_nvgre(match_mask,
15007 : : wks.tunnel_item,
15008 : : wks.item_flags,
15009 : : MLX5_SET_MATCHER_SW_M);
15010 : 0 : flow_dv_translate_item_nvgre(match_value,
15011 : : wks.tunnel_item,
15012 : : wks.item_flags,
15013 : : MLX5_SET_MATCHER_SW_V);
15014 [ # # ]: 0 : } else if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE_OPTION) {
15015 : 0 : flow_dv_translate_item_gre_option(match_mask,
15016 : : wks.tunnel_item,
15017 : : wks.gre_item,
15018 : : wks.item_flags,
15019 : : MLX5_SET_MATCHER_SW_M);
15020 : 0 : flow_dv_translate_item_gre_option(match_value,
15021 : : wks.tunnel_item,
15022 : : wks.gre_item,
15023 : : wks.item_flags,
15024 : : MLX5_SET_MATCHER_SW_V);
15025 : : } else {
15026 : : MLX5_ASSERT(false);
15027 : : }
15028 : : }
15029 : 0 : dev_flow->handle->vf_vlan.tag = wks.vlan_tag;
15030 : 0 : matcher->priority = wks.priority;
15031 : : #ifdef RTE_PMD_MLX5_DEBUG
15032 : : MLX5_ASSERT(!flow_dv_check_valid_spec(match_mask, match_value));
15033 : : #endif
15034 : : /*
15035 : : * Layers may be already initialized from prefix flow if this dev_flow
15036 : : * is the suffix flow.
15037 : : */
15038 : 0 : dev_flow->handle->layers |= wks.item_flags;
15039 : : /*
15040 : : * Update geneve_tlv_option flag only it is set in workspace.
15041 : : * Avoid be overwritten by other sub mlx5_flows.
15042 : : */
15043 [ # # ]: 0 : if (wks.geneve_tlv_option)
15044 : 0 : dev_flow->flow->geneve_tlv_option += wks.geneve_tlv_option;
15045 : : return 0;
15046 : : }
15047 : :
15048 : : /**
15049 : : * Fill the flow with DV spec, lock free
15050 : : * (mutex should be acquired by caller).
15051 : : *
15052 : : * @param[in] dev
15053 : : * Pointer to rte_eth_dev structure.
15054 : : * @param[in, out] dev_flow
15055 : : * Pointer to the sub flow.
15056 : : * @param[in] attr
15057 : : * Pointer to the flow attributes.
15058 : : * @param[in] items
15059 : : * Pointer to the list of items.
15060 : : * @param[in] actions
15061 : : * Pointer to the list of actions.
15062 : : * @param[out] error
15063 : : * Pointer to the error structure.
15064 : : *
15065 : : * @return
15066 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
15067 : : */
15068 : : static int
15069 : 0 : flow_dv_translate(struct rte_eth_dev *dev,
15070 : : struct mlx5_flow *dev_flow,
15071 : : const struct rte_flow_attr *attr,
15072 : : const struct rte_flow_item items[],
15073 : : const struct rte_flow_action actions[],
15074 : : struct rte_flow_error *error)
15075 : : {
15076 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15077 : 0 : struct mlx5_sh_config *dev_conf = &priv->sh->config;
15078 : 0 : struct rte_flow *flow = dev_flow->flow;
15079 : 0 : struct mlx5_flow_handle *handle = dev_flow->handle;
15080 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
15081 : : struct mlx5_flow_rss_desc *rss_desc;
15082 : : uint64_t action_flags = 0;
15083 : 0 : struct mlx5_flow_dv_matcher matcher = {
15084 : : .mask = {
15085 : : .size = sizeof(matcher.mask.buf),
15086 : : },
15087 : : };
15088 : : int actions_n = 0;
15089 : : bool actions_end = false;
15090 : : union {
15091 : : struct mlx5_flow_dv_modify_hdr_resource res;
15092 : : uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
15093 : : sizeof(struct mlx5_modification_cmd) *
15094 : : (MLX5_MAX_MODIFY_NUM + 1)];
15095 : : } mhdr_dummy;
15096 : : struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
15097 : : const struct rte_flow_action_count *count = NULL;
15098 : : const struct rte_flow_action_age *non_shared_age = NULL;
15099 : 0 : union flow_dv_attr flow_attr = { .attr = 0 };
15100 : : uint32_t tag_be;
15101 : : union mlx5_flow_tbl_key tbl_key;
15102 : : uint32_t modify_action_position = UINT32_MAX;
15103 : 0 : struct rte_vlan_hdr vlan = { 0 };
15104 : : struct mlx5_flow_dv_dest_array_resource mdest_res;
15105 : : struct mlx5_flow_dv_sample_resource sample_res;
15106 : 0 : void *sample_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
15107 : : const struct rte_flow_action_sample *sample = NULL;
15108 : : struct mlx5_flow_sub_actions_list *sample_act;
15109 : : uint32_t sample_act_pos = UINT32_MAX;
15110 : : uint32_t age_act_pos = UINT32_MAX;
15111 : : uint32_t ipv6_tc_off = 0;
15112 : 0 : uint32_t num_of_dest = 0;
15113 : : int tmp_actions_n = 0;
15114 : : uint32_t table;
15115 : : int ret = 0;
15116 : : const struct mlx5_flow_tunnel *tunnel = NULL;
15117 : 0 : struct flow_grp_info grp_info = {
15118 : 0 : .external = !!dev_flow->external,
15119 : 0 : .transfer = !!attr->transfer,
15120 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
15121 : 0 : .skip_scale = dev_flow->skip_scale &
15122 : : (1 << MLX5_SCALE_FLOW_GROUP_BIT),
15123 : : .std_tbl_fix = true,
15124 : : };
15125 : :
15126 [ # # ]: 0 : if (!wks)
15127 : 0 : return rte_flow_error_set(error, ENOMEM,
15128 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15129 : : NULL,
15130 : : "failed to push flow workspace");
15131 [ # # ]: 0 : rss_desc = &wks->rss_desc;
15132 : : memset(&mdest_res, 0, sizeof(struct mlx5_flow_dv_dest_array_resource));
15133 : : memset(&sample_res, 0, sizeof(struct mlx5_flow_dv_sample_resource));
15134 [ # # ]: 0 : mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
15135 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
15136 : : /* update normal path action resource into last index of array */
15137 : : sample_act = &mdest_res.sample_act[MLX5_MAX_DEST_NUM - 1];
15138 [ # # ]: 0 : if (is_tunnel_offload_active(dev)) {
15139 [ # # ]: 0 : if (dev_flow->tunnel) {
15140 [ # # ]: 0 : RTE_VERIFY(dev_flow->tof_type ==
15141 : : MLX5_TUNNEL_OFFLOAD_MISS_RULE);
15142 : : tunnel = dev_flow->tunnel;
15143 : : } else {
15144 : 0 : tunnel = mlx5_get_tof(items, actions,
15145 : : &dev_flow->tof_type);
15146 : 0 : dev_flow->tunnel = tunnel;
15147 : : }
15148 [ # # ]: 0 : grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
15149 : : (dev, attr, tunnel, dev_flow->tof_type);
15150 : : }
15151 : 0 : mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
15152 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
15153 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel, attr->group, &table,
15154 : : &grp_info, error);
15155 [ # # ]: 0 : if (ret)
15156 : : return ret;
15157 : 0 : dev_flow->dv.group = table;
15158 [ # # ]: 0 : if (attr->transfer)
15159 : 0 : mhdr_res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
15160 : : /* number of actions must be set to 0 in case of dirty stack. */
15161 : 0 : mhdr_res->actions_num = 0;
15162 [ # # ]: 0 : if (is_flow_tunnel_match_rule(dev_flow->tof_type)) {
15163 : : /*
15164 : : * do not add decap action if match rule drops packet
15165 : : * HW rejects rules with decap & drop
15166 : : *
15167 : : * if tunnel match rule was inserted before matching tunnel set
15168 : : * rule flow table used in the match rule must be registered.
15169 : : * current implementation handles that in the
15170 : : * flow_dv_match_register() at the function end.
15171 : : */
15172 : : bool add_decap = true;
15173 : : const struct rte_flow_action *ptr = actions;
15174 : :
15175 [ # # ]: 0 : for (; ptr->type != RTE_FLOW_ACTION_TYPE_END; ptr++) {
15176 [ # # ]: 0 : if (ptr->type == RTE_FLOW_ACTION_TYPE_DROP) {
15177 : : add_decap = false;
15178 : : break;
15179 : : }
15180 : : }
15181 [ # # ]: 0 : if (add_decap) {
15182 [ # # ]: 0 : if (flow_dv_create_action_l2_decap(dev, dev_flow,
15183 : 0 : attr->transfer,
15184 : : error))
15185 : 0 : return -rte_errno;
15186 : 0 : dev_flow->dv.actions[actions_n++] =
15187 : 0 : dev_flow->dv.encap_decap->action;
15188 : : action_flags |= MLX5_FLOW_ACTION_DECAP;
15189 : : }
15190 : : }
15191 [ # # ]: 0 : for (; !actions_end ; actions++) {
15192 : : const struct rte_flow_action_queue *queue;
15193 : : const struct rte_flow_action_rss *rss;
15194 : : const struct rte_flow_action *action = actions;
15195 : : const uint8_t *rss_key;
15196 : : struct mlx5_flow_tbl_resource *tbl;
15197 : : struct mlx5_aso_age_action *age_act;
15198 : : struct mlx5_flow_counter *cnt_act;
15199 : 0 : uint32_t port_id = 0;
15200 : : struct mlx5_flow_dv_port_id_action_resource port_id_resource;
15201 : 0 : int action_type = actions->type;
15202 : : const struct rte_flow_action *found_action = NULL;
15203 : : uint32_t jump_group = 0;
15204 : : uint32_t owner_idx;
15205 : : struct mlx5_aso_ct_action *ct;
15206 : :
15207 : : if (!mlx5_flow_os_action_supported(action_type))
15208 : 0 : return rte_flow_error_set(error, ENOTSUP,
15209 : : RTE_FLOW_ERROR_TYPE_ACTION,
15210 : : actions,
15211 : : "action not supported");
15212 [ # # # # : 0 : switch (action_type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
15213 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
15214 : 0 : action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
15215 : 0 : break;
15216 : : case RTE_FLOW_ACTION_TYPE_VOID:
15217 : : break;
15218 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
15219 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
15220 [ # # ]: 0 : if (flow_dv_translate_action_port_id(dev, action,
15221 : : &port_id, error))
15222 : 0 : return -rte_errno;
15223 : 0 : port_id_resource.port_id = port_id;
15224 : : MLX5_ASSERT(!handle->rix_port_id_action);
15225 [ # # ]: 0 : if (flow_dv_port_id_action_resource_register
15226 : : (dev, &port_id_resource, dev_flow, error))
15227 : 0 : return -rte_errno;
15228 : 0 : dev_flow->dv.actions[actions_n++] =
15229 : 0 : dev_flow->dv.port_id_action->action;
15230 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_ID;
15231 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_PORT_ID;
15232 : 0 : sample_act->action_flags |= MLX5_FLOW_ACTION_PORT_ID;
15233 : 0 : num_of_dest++;
15234 : 0 : break;
15235 : 0 : case RTE_FLOW_ACTION_TYPE_FLAG:
15236 : 0 : action_flags |= MLX5_FLOW_ACTION_FLAG;
15237 : 0 : wks->mark = 1;
15238 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
15239 : 0 : struct rte_flow_action_mark mark = {
15240 : : .id = MLX5_FLOW_MARK_DEFAULT,
15241 : : };
15242 : :
15243 [ # # ]: 0 : if (flow_dv_convert_action_mark(dev, &mark,
15244 : : mhdr_res,
15245 : : error))
15246 : 0 : return -rte_errno;
15247 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
15248 : 0 : break;
15249 : : }
15250 : : tag_be = mlx5_flow_mark_set(MLX5_FLOW_MARK_DEFAULT);
15251 : : /*
15252 : : * Only one FLAG or MARK is supported per device flow
15253 : : * right now. So the pointer to the tag resource must be
15254 : : * zero before the register process.
15255 : : */
15256 : : MLX5_ASSERT(!handle->dvh.rix_tag);
15257 [ # # ]: 0 : if (flow_dv_tag_resource_register(dev, tag_be,
15258 : : dev_flow, error))
15259 : 0 : return -rte_errno;
15260 : : MLX5_ASSERT(dev_flow->dv.tag_resource);
15261 : 0 : dev_flow->dv.actions[actions_n++] =
15262 : 0 : dev_flow->dv.tag_resource->action;
15263 : 0 : break;
15264 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
15265 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK;
15266 : 0 : wks->mark = 1;
15267 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
15268 : 0 : const struct rte_flow_action_mark *mark =
15269 : : (const struct rte_flow_action_mark *)
15270 : : actions->conf;
15271 : :
15272 [ # # ]: 0 : if (flow_dv_convert_action_mark(dev, mark,
15273 : : mhdr_res,
15274 : : error))
15275 : 0 : return -rte_errno;
15276 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
15277 : 0 : break;
15278 : : }
15279 : : /* Fall-through */
15280 : : case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
15281 : : /* Legacy (non-extensive) MARK action. */
15282 : : tag_be = mlx5_flow_mark_set
15283 : : (((const struct rte_flow_action_mark *)
15284 [ # # ]: 0 : (actions->conf))->id);
15285 : : MLX5_ASSERT(!handle->dvh.rix_tag);
15286 [ # # ]: 0 : if (flow_dv_tag_resource_register(dev, tag_be,
15287 : : dev_flow, error))
15288 : 0 : return -rte_errno;
15289 : : MLX5_ASSERT(dev_flow->dv.tag_resource);
15290 : 0 : dev_flow->dv.actions[actions_n++] =
15291 : 0 : dev_flow->dv.tag_resource->action;
15292 : 0 : break;
15293 : 0 : case RTE_FLOW_ACTION_TYPE_SET_META:
15294 [ # # ]: 0 : if (flow_dv_convert_action_set_meta
15295 : : (dev, mhdr_res, attr,
15296 : : (const struct rte_flow_action_set_meta *)
15297 : 0 : actions->conf, error))
15298 : 0 : return -rte_errno;
15299 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_META;
15300 : 0 : break;
15301 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TAG:
15302 [ # # ]: 0 : if (flow_dv_convert_action_set_tag
15303 : : (dev, mhdr_res,
15304 : : (const struct rte_flow_action_set_tag *)
15305 : 0 : actions->conf, error))
15306 : 0 : return -rte_errno;
15307 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
15308 : 0 : break;
15309 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
15310 : 0 : action_flags |= MLX5_FLOW_ACTION_DROP;
15311 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_DROP;
15312 : 0 : break;
15313 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
15314 : 0 : queue = actions->conf;
15315 : 0 : rss_desc->queue_num = 1;
15316 : 0 : rss_desc->queue[0] = queue->index;
15317 : 0 : action_flags |= MLX5_FLOW_ACTION_QUEUE;
15318 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
15319 : 0 : sample_act->action_flags |= MLX5_FLOW_ACTION_QUEUE;
15320 : 0 : num_of_dest++;
15321 : 0 : break;
15322 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
15323 : 0 : rss = actions->conf;
15324 : 0 : rss_desc->symmetric_hash_function =
15325 : 0 : MLX5_RSS_IS_SYMM(rss->func);
15326 : 0 : memcpy(rss_desc->queue, rss->queue,
15327 [ # # ]: 0 : rss->queue_num * sizeof(uint16_t));
15328 : 0 : rss_desc->queue_num = rss->queue_num;
15329 : : /* NULL RSS key indicates default RSS key. */
15330 [ # # ]: 0 : rss_key = !rss->key ? mlx5_rss_hash_default_key : rss->key;
15331 [ # # ]: 0 : memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
15332 : : /*
15333 : : * rss->level and rss.types should be set in advance
15334 : : * when expanding items for RSS.
15335 : : */
15336 : 0 : action_flags |= MLX5_FLOW_ACTION_RSS;
15337 : 0 : dev_flow->handle->fate_action = rss_desc->shared_rss ?
15338 [ # # ]: 0 : MLX5_FLOW_FATE_SHARED_RSS :
15339 : : MLX5_FLOW_FATE_QUEUE;
15340 : 0 : break;
15341 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
15342 : 0 : owner_idx = (uint32_t)(uintptr_t)action->conf;
15343 : 0 : age_act = mlx5_flow_aso_age_get_by_idx(dev, owner_idx);
15344 [ # # ]: 0 : if (flow->age == 0) {
15345 : 0 : flow->age = owner_idx;
15346 : 0 : rte_atomic_fetch_add_explicit(&age_act->refcnt, 1,
15347 : : rte_memory_order_relaxed);
15348 : : }
15349 : 0 : age_act_pos = actions_n++;
15350 : 0 : action_flags |= MLX5_FLOW_ACTION_AGE;
15351 : 0 : break;
15352 : 0 : case RTE_FLOW_ACTION_TYPE_SEND_TO_KERNEL:
15353 : 0 : dev_flow->dv.actions[actions_n] =
15354 : 0 : flow_dv_translate_action_send_to_kernel(dev, attr,
15355 : : error);
15356 [ # # ]: 0 : if (!dev_flow->dv.actions[actions_n])
15357 : 0 : return -rte_errno;
15358 : 0 : actions_n++;
15359 : 0 : action_flags |= MLX5_FLOW_ACTION_SEND_TO_KERNEL;
15360 : 0 : dev_flow->handle->fate_action =
15361 : : MLX5_FLOW_FATE_SEND_TO_KERNEL;
15362 : 0 : break;
15363 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
15364 : 0 : non_shared_age = action->conf;
15365 : 0 : age_act_pos = actions_n++;
15366 : 0 : action_flags |= MLX5_FLOW_ACTION_AGE;
15367 : 0 : break;
15368 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
15369 [ # # ]: 0 : owner_idx = (uint32_t)(uintptr_t)action->conf;
15370 : : cnt_act = flow_dv_counter_get_by_idx(dev, owner_idx,
15371 : : NULL);
15372 : : MLX5_ASSERT(cnt_act != NULL);
15373 : : /**
15374 : : * When creating meter drop flow in drop table, the
15375 : : * counter should not overwrite the rte flow counter.
15376 : : */
15377 [ # # ]: 0 : if (attr->group == MLX5_FLOW_TABLE_LEVEL_METER &&
15378 [ # # ]: 0 : dev_flow->dv.table_id == MLX5_MTR_TABLE_ID_DROP) {
15379 : 0 : dev_flow->dv.actions[actions_n++] =
15380 : 0 : cnt_act->action;
15381 : : } else {
15382 [ # # ]: 0 : if (flow->counter == 0) {
15383 : 0 : flow->counter = owner_idx;
15384 : 0 : rte_atomic_fetch_add_explicit
15385 : : (&cnt_act->shared_info.refcnt,
15386 : : 1, rte_memory_order_relaxed);
15387 : : }
15388 : : /* Save information first, will apply later. */
15389 : 0 : action_flags |= MLX5_FLOW_ACTION_COUNT;
15390 : : }
15391 : : break;
15392 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
15393 [ # # ]: 0 : if (!priv->sh->cdev->config.devx) {
15394 : 0 : return rte_flow_error_set
15395 : : (error, ENOTSUP,
15396 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15397 : : NULL,
15398 : : "count action not supported");
15399 : : }
15400 : : /* Save information first, will apply later. */
15401 : 0 : count = action->conf;
15402 : 0 : action_flags |= MLX5_FLOW_ACTION_COUNT;
15403 : 0 : break;
15404 : 0 : case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
15405 : 0 : dev_flow->dv.actions[actions_n++] =
15406 : 0 : priv->sh->pop_vlan_action;
15407 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
15408 : 0 : break;
15409 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
15410 [ # # ]: 0 : if (!(action_flags &
15411 : : MLX5_FLOW_ACTION_OF_SET_VLAN_VID))
15412 : 0 : flow_dev_get_vlan_info_from_items(items, &vlan);
15413 [ # # ]: 0 : vlan.eth_proto = rte_be_to_cpu_16
15414 : : ((((const struct rte_flow_action_of_push_vlan *)
15415 : : actions->conf)->ethertype));
15416 : 0 : found_action = mlx5_flow_find_action
15417 : : (actions + 1,
15418 : : RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID);
15419 [ # # ]: 0 : if (found_action)
15420 : 0 : mlx5_update_vlan_vid_pcp(found_action, &vlan);
15421 : 0 : found_action = mlx5_flow_find_action
15422 : : (actions + 1,
15423 : : RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP);
15424 [ # # ]: 0 : if (found_action)
15425 : 0 : mlx5_update_vlan_vid_pcp(found_action, &vlan);
15426 [ # # ]: 0 : if (flow_dv_create_action_push_vlan
15427 : : (dev, attr, &vlan, dev_flow, error))
15428 : 0 : return -rte_errno;
15429 : 0 : dev_flow->dv.actions[actions_n++] =
15430 : 0 : dev_flow->dv.push_vlan_res->action;
15431 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
15432 : 0 : break;
15433 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
15434 : : /* of_vlan_push action handled this action */
15435 : : MLX5_ASSERT(action_flags &
15436 : : MLX5_FLOW_ACTION_OF_PUSH_VLAN);
15437 : : break;
15438 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
15439 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
15440 : : break;
15441 : 0 : flow_dev_get_vlan_info_from_items(items, &vlan);
15442 : 0 : mlx5_update_vlan_vid_pcp(actions, &vlan);
15443 : : /* If no VLAN push - this is a modify header action */
15444 [ # # ]: 0 : if (flow_dv_convert_action_modify_vlan_vid
15445 : : (mhdr_res, actions, error))
15446 : 0 : return -rte_errno;
15447 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
15448 : 0 : break;
15449 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
15450 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
15451 [ # # ]: 0 : if (flow_dv_create_action_l2_encap(dev, actions,
15452 : : dev_flow,
15453 : 0 : attr->transfer,
15454 : : error))
15455 : 0 : return -rte_errno;
15456 : 0 : dev_flow->dv.actions[actions_n++] =
15457 : 0 : dev_flow->dv.encap_decap->action;
15458 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
15459 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
15460 : 0 : sample_act->action_flags |=
15461 : : MLX5_FLOW_ACTION_ENCAP;
15462 : : break;
15463 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
15464 : : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
15465 [ # # ]: 0 : if (flow_dv_create_action_l2_decap(dev, dev_flow,
15466 : 0 : attr->transfer,
15467 : : error))
15468 : 0 : return -rte_errno;
15469 : 0 : dev_flow->dv.actions[actions_n++] =
15470 : 0 : dev_flow->dv.encap_decap->action;
15471 : 0 : action_flags |= MLX5_FLOW_ACTION_DECAP;
15472 : 0 : break;
15473 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
15474 : : /* Handle encap with preceding decap. */
15475 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_DECAP) {
15476 [ # # ]: 0 : if (flow_dv_create_action_raw_encap
15477 : : (dev, actions, dev_flow, attr, error))
15478 : 0 : return -rte_errno;
15479 : 0 : dev_flow->dv.actions[actions_n++] =
15480 : 0 : dev_flow->dv.encap_decap->action;
15481 : : } else {
15482 : : /* Handle encap without preceding decap. */
15483 [ # # ]: 0 : if (flow_dv_create_action_l2_encap
15484 : 0 : (dev, actions, dev_flow, attr->transfer,
15485 : : error))
15486 : 0 : return -rte_errno;
15487 : 0 : dev_flow->dv.actions[actions_n++] =
15488 : 0 : dev_flow->dv.encap_decap->action;
15489 : : }
15490 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
15491 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
15492 : 0 : sample_act->action_flags |=
15493 : : MLX5_FLOW_ACTION_ENCAP;
15494 : : break;
15495 : : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
15496 [ # # ]: 0 : while ((++action)->type == RTE_FLOW_ACTION_TYPE_VOID)
15497 : : ;
15498 [ # # ]: 0 : if (action->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
15499 [ # # ]: 0 : if (flow_dv_create_action_l2_decap
15500 : 0 : (dev, dev_flow, attr->transfer, error))
15501 : 0 : return -rte_errno;
15502 : 0 : dev_flow->dv.actions[actions_n++] =
15503 : 0 : dev_flow->dv.encap_decap->action;
15504 : : }
15505 : : /* If decap is followed by encap, handle it at encap. */
15506 : 0 : action_flags |= MLX5_FLOW_ACTION_DECAP;
15507 : 0 : break;
15508 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_JUMP:
15509 : 0 : dev_flow->dv.actions[actions_n++] =
15510 : 0 : (void *)(uintptr_t)action->conf;
15511 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP;
15512 : 0 : break;
15513 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
15514 : 0 : jump_group = ((const struct rte_flow_action_jump *)
15515 : 0 : action->conf)->group;
15516 : 0 : grp_info.std_tbl_fix = 0;
15517 [ # # ]: 0 : if (dev_flow->skip_scale &
15518 : : (1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT))
15519 : 0 : grp_info.skip_scale = 1;
15520 : : else
15521 : 0 : grp_info.skip_scale = 0;
15522 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel,
15523 : : jump_group,
15524 : : &table,
15525 : : &grp_info, error);
15526 [ # # ]: 0 : if (ret)
15527 : 0 : return ret;
15528 : 0 : tbl = mlx5_flow_dv_tbl_resource_get(dev, table, attr->egress,
15529 : 0 : attr->transfer,
15530 : 0 : dev_flow->external,
15531 : : tunnel, jump_group, 0,
15532 : : 0, error);
15533 [ # # ]: 0 : if (!tbl)
15534 : 0 : return rte_flow_error_set
15535 : 0 : (error, errno,
15536 : : RTE_FLOW_ERROR_TYPE_ACTION,
15537 : : NULL,
15538 : : "cannot create jump action.");
15539 : : if (flow_dv_jump_tbl_resource_register
15540 : : (dev, tbl, dev_flow, error)) {
15541 : : mlx5_flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
15542 : : return rte_flow_error_set
15543 : : (error, errno,
15544 : : RTE_FLOW_ERROR_TYPE_ACTION,
15545 : : NULL,
15546 : : "cannot create jump action.");
15547 : : }
15548 : 0 : dev_flow->dv.actions[actions_n++] =
15549 : 0 : dev_flow->dv.jump->action;
15550 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP;
15551 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_JUMP;
15552 : 0 : sample_act->action_flags |= MLX5_FLOW_ACTION_JUMP;
15553 : 0 : num_of_dest++;
15554 : 0 : break;
15555 : 0 : case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
15556 : : case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
15557 [ # # ]: 0 : if (flow_dv_convert_action_modify_mac
15558 : : (mhdr_res, actions, error))
15559 : 0 : return -rte_errno;
15560 : 0 : action_flags |= actions->type ==
15561 : : RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
15562 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_MAC_SRC :
15563 : : MLX5_FLOW_ACTION_SET_MAC_DST;
15564 : 0 : break;
15565 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
15566 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
15567 [ # # ]: 0 : if (flow_dv_convert_action_modify_ipv4
15568 : : (mhdr_res, actions, error))
15569 : 0 : return -rte_errno;
15570 : 0 : action_flags |= actions->type ==
15571 : : RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
15572 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_IPV4_SRC :
15573 : : MLX5_FLOW_ACTION_SET_IPV4_DST;
15574 : 0 : break;
15575 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
15576 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
15577 [ # # ]: 0 : if (flow_dv_convert_action_modify_ipv6
15578 : : (mhdr_res, actions, error))
15579 : 0 : return -rte_errno;
15580 : 0 : action_flags |= actions->type ==
15581 : : RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
15582 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_IPV6_SRC :
15583 : : MLX5_FLOW_ACTION_SET_IPV6_DST;
15584 : 0 : break;
15585 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
15586 : : case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
15587 [ # # ]: 0 : if (flow_dv_convert_action_modify_tp
15588 : : (mhdr_res, actions, items,
15589 : 0 : &flow_attr, dev_flow, !!(action_flags &
15590 : : MLX5_FLOW_ACTION_DECAP), error))
15591 : 0 : return -rte_errno;
15592 : 0 : action_flags |= actions->type ==
15593 : : RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
15594 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_TP_SRC :
15595 : : MLX5_FLOW_ACTION_SET_TP_DST;
15596 : 0 : break;
15597 : 0 : case RTE_FLOW_ACTION_TYPE_DEC_TTL:
15598 [ # # ]: 0 : if (flow_dv_convert_action_modify_dec_ttl
15599 : : (mhdr_res, items, &flow_attr, dev_flow,
15600 : 0 : !!(action_flags &
15601 : : MLX5_FLOW_ACTION_DECAP), error))
15602 : 0 : return -rte_errno;
15603 : 0 : action_flags |= MLX5_FLOW_ACTION_DEC_TTL;
15604 : 0 : break;
15605 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TTL:
15606 [ # # ]: 0 : if (flow_dv_convert_action_modify_ttl
15607 : : (mhdr_res, actions, items, &flow_attr,
15608 : 0 : dev_flow, !!(action_flags &
15609 : : MLX5_FLOW_ACTION_DECAP), error))
15610 : 0 : return -rte_errno;
15611 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TTL;
15612 : 0 : break;
15613 : 0 : case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
15614 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
15615 [ # # ]: 0 : if (flow_dv_convert_action_modify_tcp_seq
15616 : : (mhdr_res, actions, error))
15617 : 0 : return -rte_errno;
15618 : 0 : action_flags |= actions->type ==
15619 : : RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
15620 [ # # ]: 0 : MLX5_FLOW_ACTION_INC_TCP_SEQ :
15621 : : MLX5_FLOW_ACTION_DEC_TCP_SEQ;
15622 : 0 : break;
15623 : :
15624 : 0 : case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
15625 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
15626 [ # # ]: 0 : if (flow_dv_convert_action_modify_tcp_ack
15627 : : (mhdr_res, actions, error))
15628 : 0 : return -rte_errno;
15629 : 0 : action_flags |= actions->type ==
15630 : : RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
15631 [ # # ]: 0 : MLX5_FLOW_ACTION_INC_TCP_ACK :
15632 : : MLX5_FLOW_ACTION_DEC_TCP_ACK;
15633 : 0 : break;
15634 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
15635 [ # # ]: 0 : if (flow_dv_convert_action_set_reg
15636 : : (mhdr_res, actions, error))
15637 : 0 : return -rte_errno;
15638 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
15639 : 0 : break;
15640 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
15641 [ # # ]: 0 : if (flow_dv_convert_action_copy_mreg
15642 : : (dev, mhdr_res, actions, error))
15643 : 0 : return -rte_errno;
15644 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
15645 : 0 : break;
15646 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
15647 : 0 : action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
15648 : 0 : dev_flow->handle->fate_action =
15649 : : MLX5_FLOW_FATE_DEFAULT_MISS;
15650 : 0 : break;
15651 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
15652 [ # # ]: 0 : if (!wks->fm)
15653 : 0 : return rte_flow_error_set(error, rte_errno,
15654 : : RTE_FLOW_ERROR_TYPE_ACTION,
15655 : : NULL, "Failed to get meter in flow.");
15656 : : /* Set the meter action. */
15657 : 0 : dev_flow->dv.actions[actions_n++] =
15658 : 0 : wks->fm->meter_action_g;
15659 : 0 : action_flags |= MLX5_FLOW_ACTION_METER;
15660 : 0 : break;
15661 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
15662 [ # # ]: 0 : if (flow_dv_convert_action_modify_ipv4_dscp(mhdr_res,
15663 : : actions, error))
15664 : 0 : return -rte_errno;
15665 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
15666 : 0 : break;
15667 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
15668 [ # # ]: 0 : if (mlx5_dv_modify_ipv6_traffic_class_supported(priv))
15669 : : ipv6_tc_off = MLX5_IPV6_HDR_DSCP_SHIFT;
15670 : : else
15671 : : ipv6_tc_off = 0;
15672 [ # # ]: 0 : if (flow_dv_convert_action_modify_ipv6_dscp(mhdr_res,
15673 : : actions, ipv6_tc_off, error))
15674 : 0 : return -rte_errno;
15675 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
15676 : 0 : break;
15677 : 0 : case RTE_FLOW_ACTION_TYPE_SAMPLE:
15678 : 0 : sample_act_pos = actions_n;
15679 : 0 : sample = (const struct rte_flow_action_sample *)
15680 : : action->conf;
15681 : 0 : actions_n++;
15682 : 0 : action_flags |= MLX5_FLOW_ACTION_SAMPLE;
15683 : : /* put encap action into group if work with port id */
15684 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_ENCAP) &&
15685 : : (action_flags & MLX5_FLOW_ACTION_PORT_ID))
15686 : 0 : sample_act->action_flags |=
15687 : : MLX5_FLOW_ACTION_ENCAP;
15688 : : break;
15689 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
15690 [ # # ]: 0 : if (flow_dv_convert_action_modify_field
15691 : : (dev, mhdr_res, actions, attr, error))
15692 : 0 : return -rte_errno;
15693 : 0 : action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
15694 : 0 : break;
15695 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
15696 : 0 : owner_idx = (uint32_t)(uintptr_t)action->conf;
15697 : 0 : ct = flow_aso_ct_get_by_idx(dev, owner_idx);
15698 [ # # ]: 0 : if (!ct)
15699 : 0 : return rte_flow_error_set(error, EINVAL,
15700 : : RTE_FLOW_ERROR_TYPE_ACTION,
15701 : : NULL,
15702 : : "Failed to get CT object.");
15703 [ # # ]: 0 : if (mlx5_aso_ct_available(priv->sh, MLX5_HW_INV_QUEUE, ct))
15704 : 0 : return rte_flow_error_set(error, rte_errno,
15705 : : RTE_FLOW_ERROR_TYPE_ACTION,
15706 : : NULL,
15707 : : "CT is unavailable.");
15708 [ # # ]: 0 : if (ct->is_original)
15709 : 0 : dev_flow->dv.actions[actions_n] =
15710 : 0 : ct->dr_action_orig;
15711 : : else
15712 : 0 : dev_flow->dv.actions[actions_n] =
15713 : 0 : ct->dr_action_rply;
15714 [ # # ]: 0 : if (flow->ct == 0) {
15715 : 0 : flow->indirect_type =
15716 : : MLX5_INDIRECT_ACTION_TYPE_CT;
15717 : 0 : flow->ct = owner_idx;
15718 : 0 : rte_atomic_fetch_add_explicit(&ct->refcnt, 1,
15719 : : rte_memory_order_relaxed);
15720 : : }
15721 : 0 : actions_n++;
15722 : 0 : action_flags |= MLX5_FLOW_ACTION_CT;
15723 : 0 : break;
15724 : 0 : case RTE_FLOW_ACTION_TYPE_END:
15725 : : actions_end = true;
15726 [ # # ]: 0 : if (mhdr_res->actions_num) {
15727 : : /* create modify action if needed. */
15728 [ # # ]: 0 : if (flow_dv_modify_hdr_resource_register
15729 : : (dev, mhdr_res, dev_flow, error))
15730 : 0 : return -rte_errno;
15731 : 0 : dev_flow->dv.actions[modify_action_position] =
15732 : 0 : handle->dvh.modify_hdr->action;
15733 : : }
15734 : : /*
15735 : : * Handle AGE and COUNT action by single HW counter
15736 : : * when they are not shared.
15737 : : */
15738 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_AGE) {
15739 [ # # # # ]: 0 : if ((non_shared_age && count) ||
15740 [ # # ]: 0 : !flow_hit_aso_supported(priv, !dev_flow->dv.group)) {
15741 : : /* Creates age by counters. */
15742 : 0 : cnt_act = flow_dv_prepare_counter
15743 : : (dev, dev_flow,
15744 : : flow, count,
15745 : : non_shared_age,
15746 : : error);
15747 [ # # ]: 0 : if (!cnt_act)
15748 : 0 : return -rte_errno;
15749 : 0 : dev_flow->dv.actions[age_act_pos] =
15750 : 0 : cnt_act->action;
15751 : 0 : break;
15752 : : }
15753 [ # # # # ]: 0 : if (!flow->age && non_shared_age) {
15754 : 0 : flow->age = flow_dv_aso_age_alloc
15755 : : (dev, error);
15756 [ # # ]: 0 : if (!flow->age)
15757 : 0 : return -rte_errno;
15758 : 0 : flow_dv_aso_age_params_init
15759 : : (dev, flow->age,
15760 : 0 : non_shared_age->context ?
15761 : : non_shared_age->context :
15762 : 0 : (void *)(uintptr_t)
15763 : 0 : (dev_flow->flow_idx),
15764 [ # # ]: 0 : non_shared_age->timeout);
15765 : : }
15766 : 0 : age_act = mlx5_flow_aso_age_get_by_idx(dev, flow->age);
15767 : 0 : dev_flow->dv.actions[age_act_pos] =
15768 : 0 : age_act->dr_action;
15769 : : }
15770 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_COUNT) {
15771 : : /*
15772 : : * Create one count action, to be used
15773 : : * by all sub-flows.
15774 : : */
15775 : 0 : cnt_act = flow_dv_prepare_counter(dev, dev_flow,
15776 : : flow, count,
15777 : : NULL, error);
15778 [ # # ]: 0 : if (!cnt_act)
15779 : 0 : return -rte_errno;
15780 : 0 : dev_flow->dv.actions[actions_n++] =
15781 : 0 : cnt_act->action;
15782 : : }
15783 : : default:
15784 : : break;
15785 : : }
15786 [ # # # # ]: 0 : if (mhdr_res->actions_num &&
15787 : : modify_action_position == UINT32_MAX)
15788 : 0 : modify_action_position = actions_n++;
15789 : : }
15790 : 0 : dev_flow->act_flags = action_flags;
15791 : 0 : ret = flow_dv_translate_items_sws(dev, dev_flow, attr, items, &matcher,
15792 : : error);
15793 [ # # ]: 0 : if (ret)
15794 : 0 : return -rte_errno;
15795 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_RSS) {
15796 : 0 : dev_flow->symmetric_hash_function = rss_desc->symmetric_hash_function;
15797 : 0 : mlx5_flow_dv_hashfields_set(dev_flow->handle->layers,
15798 : : rss_desc,
15799 : : &dev_flow->hash_fields);
15800 : : }
15801 : : /* If has RSS action in the sample action, the Sample/Mirror resource
15802 : : * should be registered after the hash filed be update.
15803 : : */
15804 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE) {
15805 : 0 : ret = flow_dv_translate_action_sample(dev,
15806 : : sample,
15807 : : dev_flow, attr,
15808 : : &num_of_dest,
15809 : : sample_actions,
15810 : : &sample_res,
15811 : : error);
15812 [ # # ]: 0 : if (ret < 0)
15813 : : return ret;
15814 : 0 : ret = flow_dv_create_action_sample(dev,
15815 : : dev_flow,
15816 : : num_of_dest,
15817 : : &sample_res,
15818 : : &mdest_res,
15819 : : sample_actions,
15820 : : action_flags,
15821 : : error);
15822 [ # # ]: 0 : if (ret < 0)
15823 : 0 : return rte_flow_error_set
15824 : : (error, rte_errno,
15825 : : RTE_FLOW_ERROR_TYPE_ACTION,
15826 : : NULL,
15827 : : "cannot create sample action");
15828 [ # # ]: 0 : if (num_of_dest > 1) {
15829 : 0 : dev_flow->dv.actions[sample_act_pos] =
15830 : 0 : dev_flow->dv.dest_array_res->action;
15831 : : } else {
15832 : 0 : dev_flow->dv.actions[sample_act_pos] =
15833 : 0 : dev_flow->dv.sample_res->verbs_action;
15834 : : }
15835 : : }
15836 : : /*
15837 : : * For multiple destination (sample action with ratio=1), the encap
15838 : : * action and port id action will be combined into group action.
15839 : : * So need remove the original these actions in the flow and only
15840 : : * use the sample action instead of.
15841 : : */
15842 [ # # ]: 0 : if (num_of_dest > 1 &&
15843 [ # # # # ]: 0 : (sample_act->dr_port_id_action || sample_act->dr_jump_action)) {
15844 : : int i;
15845 : 0 : void *temp_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
15846 : :
15847 [ # # ]: 0 : for (i = 0; i < actions_n; i++) {
15848 [ # # ]: 0 : if ((sample_act->dr_encap_action &&
15849 : : sample_act->dr_encap_action ==
15850 [ # # # # ]: 0 : dev_flow->dv.actions[i]) ||
15851 : 0 : (sample_act->dr_port_id_action &&
15852 : : sample_act->dr_port_id_action ==
15853 [ # # ]: 0 : dev_flow->dv.actions[i]) ||
15854 [ # # ]: 0 : (sample_act->dr_jump_action &&
15855 : : sample_act->dr_jump_action ==
15856 [ # # ]: 0 : dev_flow->dv.actions[i]))
15857 : 0 : continue;
15858 : 0 : temp_actions[tmp_actions_n++] = dev_flow->dv.actions[i];
15859 : : }
15860 : 0 : memcpy((void *)dev_flow->dv.actions,
15861 : : (void *)temp_actions,
15862 : : tmp_actions_n * sizeof(void *));
15863 : : actions_n = tmp_actions_n;
15864 : : }
15865 : 0 : dev_flow->dv.actions_n = actions_n;
15866 [ # # ]: 0 : if (wks->skip_matcher_reg)
15867 : : return 0;
15868 : : /* Register matcher. */
15869 : 0 : matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
15870 : : matcher.mask.size);
15871 : 0 : matcher.priority = mlx5_get_matcher_priority(dev, attr,
15872 : 0 : matcher.priority,
15873 : 0 : dev_flow->external);
15874 : : /**
15875 : : * When creating meter drop flow in drop table, using original
15876 : : * 5-tuple match, the matcher priority should be lower than
15877 : : * mtr_id matcher.
15878 : : */
15879 [ # # ]: 0 : if (attr->group == MLX5_FLOW_TABLE_LEVEL_METER &&
15880 [ # # # # ]: 0 : dev_flow->dv.table_id == MLX5_MTR_TABLE_ID_DROP &&
15881 : : matcher.priority <= MLX5_REG_BITS)
15882 : 0 : matcher.priority += MLX5_REG_BITS;
15883 : : /* reserved field no needs to be set to 0 here. */
15884 : 0 : tbl_key.is_fdb = attr->transfer;
15885 : 0 : tbl_key.is_egress = attr->egress;
15886 : 0 : tbl_key.level = dev_flow->dv.group;
15887 : 0 : tbl_key.id = dev_flow->dv.table_id;
15888 [ # # ]: 0 : if (flow_dv_matcher_register(dev, &matcher, &tbl_key, dev_flow,
15889 : : tunnel, attr->group, error))
15890 : 0 : return -rte_errno;
15891 : : return 0;
15892 : : }
15893 : :
15894 : : /*
15895 : : * Protocol selector bitmap
15896 : : * Each flag is used as an indicator that given protocol is specified in given RSS hash fields.
15897 : : */
15898 : : #define RX_HASH_SELECTOR_IPV4 RTE_BIT32(0)
15899 : : #define RX_HASH_SELECTOR_IPV6 RTE_BIT32(1)
15900 : : #define RX_HASH_SELECTOR_UDP RTE_BIT32(2)
15901 : : #define RX_HASH_SELECTOR_TCP RTE_BIT32(3)
15902 : : #define RX_HASH_SELECTOR_ESP_SPI RTE_BIT32(4)
15903 : : #define RX_HASH_SELECTOR_NONE (0)
15904 : :
15905 : : #define RX_HASH_SELECTOR_IPV4_TCP (RX_HASH_SELECTOR_IPV4 | RX_HASH_SELECTOR_TCP)
15906 : : #define RX_HASH_SELECTOR_IPV4_UDP (RX_HASH_SELECTOR_IPV4 | RX_HASH_SELECTOR_UDP)
15907 : : #define RX_HASH_SELECTOR_IPV4_ESP (RX_HASH_SELECTOR_IPV4 | RX_HASH_SELECTOR_ESP_SPI)
15908 : :
15909 : : #define RX_HASH_SELECTOR_IPV6_TCP (RX_HASH_SELECTOR_IPV6 | RX_HASH_SELECTOR_TCP)
15910 : : #define RX_HASH_SELECTOR_IPV6_UDP (RX_HASH_SELECTOR_IPV6 | RX_HASH_SELECTOR_UDP)
15911 : : #define RX_HASH_SELECTOR_IPV6_ESP (RX_HASH_SELECTOR_IPV6 | RX_HASH_SELECTOR_ESP_SPI)
15912 : :
15913 : : static bool
15914 : : rx_hash_selector_has_valid_l3(const uint32_t selectors)
15915 : : {
15916 : : /* In TIR configuration, RSS hashing on both IPv4 and IPv6 is mutually exclusive. */
15917 : : return !((selectors & RX_HASH_SELECTOR_IPV4) && (selectors & RX_HASH_SELECTOR_IPV6));
15918 : : }
15919 : :
15920 : : static bool
15921 : : rx_hash_selector_has_valid_l4(const uint32_t selectors)
15922 : : {
15923 : : /* In TIR configuration, RSS hashing on both UDP and TCP is mutually exclusive. */
15924 : 0 : return !((selectors & RX_HASH_SELECTOR_UDP) && (selectors & RX_HASH_SELECTOR_TCP));
15925 : : }
15926 : :
15927 : : static bool
15928 : : rx_hash_selector_has_valid_esp(const uint32_t selectors)
15929 : : {
15930 : : /* In TIR configuration, RSS hashing on ESP and other L4 protocol is mutually exclusive. */
15931 [ # # ]: 0 : if (selectors & RX_HASH_SELECTOR_ESP_SPI)
15932 : 0 : return !((selectors & RX_HASH_SELECTOR_UDP) || (selectors & RX_HASH_SELECTOR_TCP));
15933 : :
15934 : : return true;
15935 : : }
15936 : :
15937 : : /**
15938 : : * Calculate protocol combination based on provided RSS hashing fields.
15939 : : *
15940 : : * @param[in] hash_fields
15941 : : * Requested RSS hashing fields specified as a flags bitmap, based on ibv_rx_hash_fields.
15942 : : * @param[out] selectors_out
15943 : : * Calculated protocol combination will be written here.
15944 : : * Result will be a bitmap of RX_HASH_SELECTOR_* flags.
15945 : : *
15946 : : * @return
15947 : : * 0 if conversion is successful and protocol combination written to @p selectors_out.
15948 : : * (-EINVAL) otherwise.
15949 : : */
15950 : : static int
15951 : 0 : rx_hash_calc_selector(const uint64_t hash_fields, uint32_t *selectors_out)
15952 : : {
15953 : : const uint64_t filtered_hf = hash_fields & ~IBV_RX_HASH_INNER;
15954 : : uint32_t selectors = 0;
15955 : :
15956 [ # # ]: 0 : if (filtered_hf & MLX5_RSS_HASH_IPV4)
15957 : : selectors |= RX_HASH_SELECTOR_IPV4;
15958 [ # # ]: 0 : if (filtered_hf & MLX5_RSS_HASH_IPV6)
15959 : 0 : selectors |= RX_HASH_SELECTOR_IPV6;
15960 [ # # ]: 0 : if (!rx_hash_selector_has_valid_l3(selectors)) {
15961 : 0 : DRV_LOG(NOTICE, "hrxq hashing on both IPv4 and IPv6 is invalid: "
15962 : : "selectors=0x%" PRIx32, selectors);
15963 : 0 : return -EINVAL;
15964 : : }
15965 : :
15966 [ # # ]: 0 : if (filtered_hf & MLX5_UDP_IBV_RX_HASH)
15967 : 0 : selectors |= RX_HASH_SELECTOR_UDP;
15968 [ # # ]: 0 : if (filtered_hf & MLX5_TCP_IBV_RX_HASH)
15969 : 0 : selectors |= RX_HASH_SELECTOR_TCP;
15970 [ # # ]: 0 : if (!rx_hash_selector_has_valid_l4(selectors)) {
15971 : 0 : DRV_LOG(NOTICE, "hrxq hashing on both UDP and TCP is invalid: "
15972 : : "selectors=0x%" PRIx32, selectors);
15973 : 0 : return -EINVAL;
15974 : : }
15975 : :
15976 [ # # ]: 0 : if (filtered_hf & MLX5_RSS_HASH_ESP_SPI)
15977 : 0 : selectors |= RX_HASH_SELECTOR_ESP_SPI;
15978 [ # # ]: 0 : if (!rx_hash_selector_has_valid_esp(selectors)) {
15979 : 0 : DRV_LOG(NOTICE, "hrxq hashing on ESP SPI and UDP or TCP is mutually exclusive: "
15980 : : "selectors=0x%" PRIx32, selectors);
15981 : 0 : return -EINVAL;
15982 : : }
15983 : :
15984 : 0 : *selectors_out = selectors;
15985 : 0 : return 0;
15986 : : }
15987 : :
15988 : : /**
15989 : : * Calculate the hrxq object index based on protocol combination.
15990 : : *
15991 : : * @param[in] selectors
15992 : : * Protocol combination specified as bitmap of RX_HASH_SELECTOR_* flags.
15993 : : *
15994 : : * @return
15995 : : * Index into hrxq array in #mlx5_shared_action_rss based on ginve protocol combination.
15996 : : * (-EINVAL) if given protocol combination is not supported or is invalid.
15997 : : */
15998 : : static int
15999 : 0 : get_rss_hash_idx(const uint32_t selectors)
16000 : : {
16001 [ # # # # : 0 : switch (selectors) {
# # # # #
# # # # ]
16002 : : case RX_HASH_SELECTOR_IPV4:
16003 : : return MLX5_RSS_HASH_IDX_IPV4;
16004 : 0 : case RX_HASH_SELECTOR_IPV4_TCP:
16005 : 0 : return MLX5_RSS_HASH_IDX_IPV4_TCP;
16006 : 0 : case RX_HASH_SELECTOR_IPV4_UDP:
16007 : 0 : return MLX5_RSS_HASH_IDX_IPV4_UDP;
16008 : 0 : case RX_HASH_SELECTOR_IPV4_ESP:
16009 : 0 : return MLX5_RSS_HASH_IDX_IPV4_ESP;
16010 : 0 : case RX_HASH_SELECTOR_IPV6:
16011 : 0 : return MLX5_RSS_HASH_IDX_IPV6;
16012 : 0 : case RX_HASH_SELECTOR_IPV6_TCP:
16013 : 0 : return MLX5_RSS_HASH_IDX_IPV6_TCP;
16014 : 0 : case RX_HASH_SELECTOR_IPV6_UDP:
16015 : 0 : return MLX5_RSS_HASH_IDX_IPV6_UDP;
16016 : 0 : case RX_HASH_SELECTOR_IPV6_ESP:
16017 : 0 : return MLX5_RSS_HASH_IDX_IPV6_ESP;
16018 : 0 : case RX_HASH_SELECTOR_TCP:
16019 : 0 : return MLX5_RSS_HASH_IDX_TCP;
16020 : 0 : case RX_HASH_SELECTOR_UDP:
16021 : 0 : return MLX5_RSS_HASH_IDX_UDP;
16022 : 0 : case RX_HASH_SELECTOR_ESP_SPI:
16023 : 0 : return MLX5_RSS_HASH_IDX_ESP_SPI;
16024 : 0 : case RX_HASH_SELECTOR_NONE:
16025 : 0 : return MLX5_RSS_HASH_IDX_NONE;
16026 : 0 : default:
16027 : 0 : DRV_LOG(ERR, "invalid hrxq hash fields combination: "
16028 : : "selectors=0x%" PRIx32, selectors);
16029 : 0 : return -EINVAL;
16030 : : }
16031 : : }
16032 : :
16033 : : /**
16034 : : * Set hash RX queue by hash fields (see enum ibv_rx_hash_fields)
16035 : : * and tunnel.
16036 : : *
16037 : : * @param[in, out] action
16038 : : * Shred RSS action holding hash RX queue objects.
16039 : : * @param[in] hash_fields
16040 : : * Defines combination of packet fields to participate in RX hash,
16041 : : * specified as a bitmap of #ibv_rx_hash_fields flags.
16042 : : * @param[in] tunnel
16043 : : * Tunnel type
16044 : : * @param[in] hrxq_idx
16045 : : * Hash RX queue index to set.
16046 : : *
16047 : : * @return
16048 : : * 0 on success, otherwise negative errno value.
16049 : : */
16050 : : static int
16051 : 0 : __flow_dv_action_rss_hrxq_set(struct mlx5_shared_action_rss *action,
16052 : : const uint64_t hash_fields,
16053 : : uint32_t hrxq_idx)
16054 : : {
16055 : 0 : uint32_t *hrxqs = action->hrxq;
16056 : 0 : uint32_t selectors = 0;
16057 : : int ret;
16058 : :
16059 : 0 : ret = rx_hash_calc_selector(hash_fields, &selectors);
16060 : : /*
16061 : : * Hash fields passed to this function are constructed internally.
16062 : : * If this fails, then this is a PMD bug.
16063 : : */
16064 : : MLX5_ASSERT(ret == 0);
16065 : :
16066 : 0 : ret = get_rss_hash_idx(selectors);
16067 : : /*
16068 : : * Based on above assert, selectors should always yield correct index
16069 : : * in mlx5_rss_hash_fields array.
16070 : : * If this fails, then this is a PMD bug.
16071 : : */
16072 : : MLX5_ASSERT(ret >= 0 && ret < MLX5_RSS_HASH_IDX_MAX);
16073 : 0 : hrxqs[ret] = hrxq_idx;
16074 : :
16075 : 0 : return 0;
16076 : : }
16077 : :
16078 : : /**
16079 : : * Look up for hash RX queue by hash fields (see enum ibv_rx_hash_fields)
16080 : : * and tunnel.
16081 : : *
16082 : : * @param[in] dev
16083 : : * Pointer to the Ethernet device structure.
16084 : : * @param[in] idx
16085 : : * Shared RSS action ID holding hash RX queue objects.
16086 : : * @param[in] hash_fields
16087 : : * Defines combination of packet fields to participate in RX hash,
16088 : : * specified as a bitmap of #ibv_rx_hash_fields flags.
16089 : : * @param[in] tunnel
16090 : : * Tunnel type
16091 : : *
16092 : : * @return
16093 : : * Valid hash RX queue index, otherwise 0.
16094 : : */
16095 : : uint32_t
16096 : 0 : mlx5_flow_dv_action_rss_hrxq_lookup(struct rte_eth_dev *dev, uint32_t idx,
16097 : : const uint64_t hash_fields)
16098 : : {
16099 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16100 : : struct mlx5_shared_action_rss *shared_rss =
16101 : 0 : mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
16102 : : const uint32_t *hrxqs;
16103 : 0 : uint32_t selectors = 0;
16104 : : int ret;
16105 : :
16106 [ # # ]: 0 : if (!shared_rss) {
16107 : 0 : DRV_LOG(ERR, "port %u cannot get RSS action: rss_act_idx=%u",
16108 : : dev->data->port_id, idx);
16109 : 0 : return 0;
16110 : : }
16111 : 0 : hrxqs = shared_rss->hrxq;
16112 : :
16113 : 0 : ret = rx_hash_calc_selector(hash_fields, &selectors);
16114 [ # # ]: 0 : if (ret < 0) {
16115 : 0 : DRV_LOG(ERR, "port %u Rx hash selector calculation failed: "
16116 : : "rss_act_idx=%u hash_fields=0x%" PRIx64 " selectors=0x%" PRIx32,
16117 : : dev->data->port_id, idx, hash_fields, selectors);
16118 : 0 : return 0;
16119 : : }
16120 : :
16121 : 0 : ret = get_rss_hash_idx(selectors);
16122 [ # # ]: 0 : if (ret < 0) {
16123 : 0 : DRV_LOG(ERR, "port %u failed hrxq index lookup: "
16124 : : "rss_act_idx=%u hash_fields=0x%" PRIx64 " selectors=0x%" PRIx32,
16125 : : dev->data->port_id, idx, hash_fields, selectors);
16126 : 0 : return 0;
16127 : : }
16128 : :
16129 : 0 : return hrxqs[ret];
16130 : : }
16131 : :
16132 : : /**
16133 : : * Apply the flow to the NIC, lock free,
16134 : : * (mutex should be acquired by caller).
16135 : : *
16136 : : * @param[in] dev
16137 : : * Pointer to the Ethernet device structure.
16138 : : * @param[in, out] flow
16139 : : * Pointer to flow structure.
16140 : : * @param[out] error
16141 : : * Pointer to error structure.
16142 : : *
16143 : : * @return
16144 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
16145 : : */
16146 : : static int
16147 : 0 : flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
16148 : : struct rte_flow_error *error)
16149 : : {
16150 : : struct mlx5_flow_dv_workspace *dv;
16151 : : struct mlx5_flow_handle *dh;
16152 : : struct mlx5_flow_handle_dv *dv_h;
16153 : : struct mlx5_flow *dev_flow;
16154 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16155 : : uint32_t handle_idx;
16156 : : int n;
16157 : : int err;
16158 : : int idx;
16159 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
16160 : 0 : struct mlx5_flow_rss_desc *rss_desc = &wks->rss_desc;
16161 : : uint8_t misc_mask;
16162 : :
16163 : : MLX5_ASSERT(wks);
16164 [ # # ]: 0 : for (idx = wks->flow_idx - 1; idx >= 0; idx--) {
16165 : 0 : dev_flow = &wks->flows[idx];
16166 : : dv = &dev_flow->dv;
16167 : 0 : dh = dev_flow->handle;
16168 : : dv_h = &dh->dvh;
16169 : 0 : n = dv->actions_n;
16170 [ # # ]: 0 : if (dh->fate_action == MLX5_FLOW_FATE_DROP) {
16171 [ # # ]: 0 : if (dv->transfer) {
16172 : : MLX5_ASSERT(priv->sh->dr_drop_action);
16173 : 0 : dv->actions[n++] = priv->sh->dr_drop_action;
16174 : : } else {
16175 : : #ifdef HAVE_MLX5DV_DR
16176 : : /* DR supports drop action placeholder. */
16177 : : MLX5_ASSERT(priv->sh->dr_drop_action);
16178 : 0 : dv->actions[n++] = dv->group ?
16179 [ # # ]: 0 : priv->sh->dr_drop_action :
16180 : : priv->root_drop_action;
16181 : : #else
16182 : : /* For DV we use the explicit drop queue. */
16183 : : MLX5_ASSERT(priv->drop_queue.hrxq);
16184 : : dv->actions[n++] =
16185 : : priv->drop_queue.hrxq->action;
16186 : : #endif
16187 : : }
16188 [ # # ]: 0 : } else if ((dh->fate_action == MLX5_FLOW_FATE_QUEUE &&
16189 [ # # # # ]: 0 : !dv_h->rix_sample && !dv_h->rix_dest_array)) {
16190 : : struct mlx5_hrxq *hrxq;
16191 : : uint32_t hrxq_idx;
16192 : :
16193 : 0 : hrxq = flow_dv_hrxq_prepare(dev, dev_flow, rss_desc,
16194 : : &hrxq_idx);
16195 [ # # ]: 0 : if (!hrxq) {
16196 : 0 : rte_flow_error_set
16197 : : (error, rte_errno,
16198 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16199 : : "cannot get hash queue");
16200 : 0 : goto error;
16201 : : }
16202 : 0 : dh->rix_hrxq = hrxq_idx;
16203 : 0 : dv->actions[n++] = hrxq->action;
16204 [ # # ]: 0 : } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
16205 : : struct mlx5_hrxq *hrxq = NULL;
16206 : : uint32_t hrxq_idx;
16207 : :
16208 : 0 : hrxq_idx = mlx5_flow_dv_action_rss_hrxq_lookup(dev,
16209 : : rss_desc->shared_rss,
16210 : : dev_flow->hash_fields);
16211 [ # # ]: 0 : if (hrxq_idx)
16212 : 0 : hrxq = mlx5_ipool_get
16213 : 0 : (priv->sh->ipool[MLX5_IPOOL_HRXQ],
16214 : : hrxq_idx);
16215 [ # # ]: 0 : if (!hrxq) {
16216 : 0 : rte_flow_error_set
16217 : : (error, rte_errno,
16218 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16219 : : "cannot get hash queue");
16220 : 0 : goto error;
16221 : : }
16222 : 0 : dh->rix_srss = rss_desc->shared_rss;
16223 : 0 : dv->actions[n++] = hrxq->action;
16224 [ # # ]: 0 : } else if (dh->fate_action == MLX5_FLOW_FATE_DEFAULT_MISS) {
16225 [ # # ]: 0 : if (!priv->sh->default_miss_action) {
16226 : 0 : rte_flow_error_set
16227 : : (error, rte_errno,
16228 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16229 : : "default miss action not be created.");
16230 : 0 : goto error;
16231 : : }
16232 : 0 : dv->actions[n++] = priv->sh->default_miss_action;
16233 : : }
16234 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(dv_h->matcher->mask.buf);
16235 : : __flow_dv_adjust_buf_size(&dv->value.size, misc_mask);
16236 : 0 : err = mlx5_flow_os_create_flow(dv_h->matcher->matcher_object,
16237 : 0 : (void *)&dv->value, n,
16238 : 0 : dv->actions, &dh->drv_flow);
16239 : : if (err) {
16240 : 0 : rte_flow_error_set
16241 : 0 : (error, errno,
16242 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
16243 : : NULL,
16244 [ # # ]: 0 : (!priv->sh->config.allow_duplicate_pattern &&
16245 [ # # ]: 0 : errno == EEXIST) ?
16246 : : "duplicating pattern is not allowed" :
16247 : : "hardware refuses to create flow");
16248 : 0 : goto error;
16249 : : }
16250 [ # # ]: 0 : if (priv->vmwa_context &&
16251 [ # # # # ]: 0 : dh->vf_vlan.tag && !dh->vf_vlan.created) {
16252 : : /*
16253 : : * The rule contains the VLAN pattern.
16254 : : * For VF we are going to create VLAN
16255 : : * interface to make hypervisor set correct
16256 : : * e-Switch vport context.
16257 : : */
16258 : 0 : mlx5_vlan_vmwa_acquire(dev, &dh->vf_vlan);
16259 : : }
16260 : : }
16261 : : return 0;
16262 : 0 : error:
16263 : 0 : err = rte_errno; /* Save rte_errno before cleanup. */
16264 [ # # # # : 0 : SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
# # ]
16265 : : handle_idx, dh, next) {
16266 : : /* hrxq is union, don't clear it if the flag is not set. */
16267 [ # # # # ]: 0 : if (dh->fate_action == MLX5_FLOW_FATE_QUEUE && dh->rix_hrxq &&
16268 [ # # # # ]: 0 : !dh->dvh.rix_sample && !dh->dvh.rix_dest_array) {
16269 : 0 : mlx5_hrxq_release(dev, dh->rix_hrxq);
16270 : 0 : dh->rix_hrxq = 0;
16271 [ # # ]: 0 : } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
16272 : 0 : dh->rix_srss = 0;
16273 : : }
16274 [ # # # # ]: 0 : if (dh->vf_vlan.tag && dh->vf_vlan.created)
16275 : 0 : mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
16276 : : }
16277 : 0 : rte_errno = err; /* Restore rte_errno. */
16278 : 0 : return -rte_errno;
16279 : : }
16280 : :
16281 : : void
16282 : 0 : mlx5_flow_matcher_remove_cb(void *tool_ctx __rte_unused,
16283 : : struct mlx5_list_entry *entry)
16284 : : {
16285 : : struct mlx5_flow_dv_matcher *resource = container_of(entry,
16286 : : typeof(*resource),
16287 : : entry);
16288 : : #ifdef HAVE_MLX5_HWS_SUPPORT
16289 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
16290 : :
16291 [ # # ]: 0 : if (sh->config.dv_flow_en == 2)
16292 : 0 : claim_zero(mlx5dr_bwc_matcher_destroy((struct mlx5dr_bwc_matcher *)
16293 : : resource->matcher_object));
16294 : : else
16295 : : #endif
16296 : 0 : claim_zero(mlx5_flow_os_destroy_flow_matcher(resource->matcher_object));
16297 : 0 : mlx5_free(resource);
16298 : 0 : }
16299 : :
16300 : : /**
16301 : : * Release the flow matcher.
16302 : : *
16303 : : * @param dev
16304 : : * Pointer to Ethernet device.
16305 : : * @param port_id
16306 : : * Index to port ID action resource.
16307 : : *
16308 : : * @return
16309 : : * 1 while a reference on it exists, 0 when freed.
16310 : : */
16311 : : static int
16312 : 0 : flow_dv_matcher_release(struct rte_eth_dev *dev,
16313 : : struct mlx5_flow_handle *handle)
16314 : : {
16315 : 0 : struct mlx5_flow_dv_matcher *matcher = handle->dvh.matcher;
16316 : 0 : struct mlx5_flow_tbl_data_entry *tbl = container_of(matcher->tbl,
16317 : : typeof(*tbl), tbl);
16318 : : int ret;
16319 : :
16320 : : MLX5_ASSERT(matcher->matcher_object);
16321 : 0 : ret = mlx5_list_unregister(tbl->matchers, &matcher->entry);
16322 : 0 : mlx5_flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl->tbl);
16323 : 0 : return ret;
16324 : : }
16325 : :
16326 : : void
16327 : 0 : mlx5_flow_encap_decap_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
16328 : : {
16329 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
16330 : : struct mlx5_flow_dv_encap_decap_resource *res =
16331 : : container_of(entry, typeof(*res), entry);
16332 : :
16333 : : #ifdef HAVE_MLX5_HWS_SUPPORT
16334 [ # # ]: 0 : if (sh->config.dv_flow_en == 2)
16335 : 0 : claim_zero(mlx5dr_action_destroy(res->action));
16336 : : else
16337 : : #endif
16338 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
16339 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], res->idx);
16340 : 0 : }
16341 : :
16342 : : /**
16343 : : * Release an encap/decap resource.
16344 : : *
16345 : : * @param dev
16346 : : * Pointer to Ethernet device.
16347 : : * @param encap_decap_idx
16348 : : * Index of encap decap resource.
16349 : : *
16350 : : * @return
16351 : : * 1 while a reference on it exists, 0 when freed.
16352 : : */
16353 : : int
16354 : 0 : mlx5_flow_encap_decap_resource_release(struct rte_eth_dev *dev,
16355 : : uint32_t encap_decap_idx)
16356 : : {
16357 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16358 : : struct mlx5_flow_dv_encap_decap_resource *resource;
16359 : :
16360 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
16361 : : encap_decap_idx);
16362 [ # # ]: 0 : if (!resource)
16363 : : return 0;
16364 : : MLX5_ASSERT(resource->action);
16365 : 0 : return mlx5_hlist_unregister(priv->sh->encaps_decaps, &resource->entry);
16366 : : }
16367 : :
16368 : : /**
16369 : : * Release an jump to table action resource.
16370 : : *
16371 : : * @param dev
16372 : : * Pointer to Ethernet device.
16373 : : * @param rix_jump
16374 : : * Index to the jump action resource.
16375 : : *
16376 : : * @return
16377 : : * 1 while a reference on it exists, 0 when freed.
16378 : : */
16379 : : static int
16380 : 0 : flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev,
16381 : : uint32_t rix_jump)
16382 : : {
16383 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16384 : : struct mlx5_flow_tbl_data_entry *tbl_data;
16385 : :
16386 : 0 : tbl_data = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_JUMP],
16387 : : rix_jump);
16388 [ # # ]: 0 : if (!tbl_data)
16389 : : return 0;
16390 : 0 : return mlx5_flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl_data->tbl);
16391 : : }
16392 : :
16393 : : void
16394 : 0 : mlx5_flow_modify_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
16395 : : {
16396 : : struct mlx5_flow_dv_modify_hdr_resource *res =
16397 : : container_of(entry, typeof(*res), entry);
16398 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
16399 : :
16400 : : #ifdef HAVE_MLX5_HWS_SUPPORT
16401 [ # # ]: 0 : if (sh->config.dv_flow_en == 2)
16402 : 0 : claim_zero(mlx5dr_action_destroy(res->action));
16403 : : else
16404 : : #endif
16405 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
16406 : 0 : mlx5_ipool_free(sh->mdh_ipools[res->actions_num - 1], res->idx);
16407 : 0 : }
16408 : :
16409 : : /**
16410 : : * Release a modify-header resource.
16411 : : *
16412 : : * @param dev
16413 : : * Pointer to Ethernet device.
16414 : : * @param handle
16415 : : * Pointer to mlx5_flow_handle.
16416 : : *
16417 : : * @return
16418 : : * 1 while a reference on it exists, 0 when freed.
16419 : : */
16420 : : static int
16421 : : flow_dv_modify_hdr_resource_release(struct rte_eth_dev *dev,
16422 : : struct mlx5_flow_handle *handle)
16423 : : {
16424 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16425 : : struct mlx5_flow_dv_modify_hdr_resource *entry = handle->dvh.modify_hdr;
16426 : :
16427 : : MLX5_ASSERT(entry->action);
16428 : 0 : return mlx5_hlist_unregister(priv->sh->modify_cmds, &entry->entry);
16429 : : }
16430 : :
16431 : : void
16432 : 0 : mlx5_flow_dv_port_id_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
16433 : : {
16434 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
16435 : : struct mlx5_flow_dv_port_id_action_resource *resource =
16436 : : container_of(entry, typeof(*resource), entry);
16437 : :
16438 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
16439 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], resource->idx);
16440 : 0 : }
16441 : :
16442 : : /**
16443 : : * Release port ID action resource.
16444 : : *
16445 : : * @param dev
16446 : : * Pointer to Ethernet device.
16447 : : * @param handle
16448 : : * Pointer to mlx5_flow_handle.
16449 : : *
16450 : : * @return
16451 : : * 1 while a reference on it exists, 0 when freed.
16452 : : */
16453 : : static int
16454 : 0 : flow_dv_port_id_action_resource_release(struct rte_eth_dev *dev,
16455 : : uint32_t port_id)
16456 : : {
16457 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16458 : : struct mlx5_flow_dv_port_id_action_resource *resource;
16459 : :
16460 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PORT_ID], port_id);
16461 [ # # ]: 0 : if (!resource)
16462 : : return 0;
16463 : : MLX5_ASSERT(resource->action);
16464 : 0 : return mlx5_list_unregister(priv->sh->port_id_action_list,
16465 : : &resource->entry);
16466 : : }
16467 : :
16468 : : /**
16469 : : * Release shared RSS action resource.
16470 : : *
16471 : : * @param dev
16472 : : * Pointer to Ethernet device.
16473 : : * @param srss
16474 : : * Shared RSS action index.
16475 : : */
16476 : : static void
16477 : 0 : flow_dv_shared_rss_action_release(struct rte_eth_dev *dev, uint32_t srss)
16478 : : {
16479 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16480 : : struct mlx5_shared_action_rss *shared_rss;
16481 : :
16482 : 0 : shared_rss = mlx5_ipool_get
16483 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], srss);
16484 : 0 : rte_atomic_fetch_sub_explicit(&shared_rss->refcnt, 1, rte_memory_order_relaxed);
16485 : 0 : }
16486 : :
16487 : : void
16488 : 0 : mlx5_flow_dv_push_vlan_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
16489 : : {
16490 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
16491 : : struct mlx5_flow_dv_push_vlan_action_resource *resource =
16492 : : container_of(entry, typeof(*resource), entry);
16493 : :
16494 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
16495 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], resource->idx);
16496 : 0 : }
16497 : :
16498 : : /**
16499 : : * Release push vlan action resource.
16500 : : *
16501 : : * @param dev
16502 : : * Pointer to Ethernet device.
16503 : : * @param handle
16504 : : * Pointer to mlx5_flow_handle.
16505 : : *
16506 : : * @return
16507 : : * 1 while a reference on it exists, 0 when freed.
16508 : : */
16509 : : static int
16510 : 0 : flow_dv_push_vlan_action_resource_release(struct rte_eth_dev *dev,
16511 : : struct mlx5_flow_handle *handle)
16512 : : {
16513 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16514 : : struct mlx5_flow_dv_push_vlan_action_resource *resource;
16515 : 0 : uint32_t idx = handle->dvh.rix_push_vlan;
16516 : :
16517 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
16518 [ # # ]: 0 : if (!resource)
16519 : : return 0;
16520 : : MLX5_ASSERT(resource->action);
16521 : 0 : return mlx5_list_unregister(priv->sh->push_vlan_action_list,
16522 : : &resource->entry);
16523 : : }
16524 : :
16525 : : /**
16526 : : * Release the fate resource.
16527 : : *
16528 : : * @param dev
16529 : : * Pointer to Ethernet device.
16530 : : * @param handle
16531 : : * Pointer to mlx5_flow_handle.
16532 : : */
16533 : : static void
16534 : 0 : flow_dv_fate_resource_release(struct rte_eth_dev *dev,
16535 : : struct mlx5_flow_handle *handle)
16536 : : {
16537 [ # # ]: 0 : if (!handle->rix_fate)
16538 : : return;
16539 [ # # # # : 0 : switch (handle->fate_action) {
# ]
16540 : 0 : case MLX5_FLOW_FATE_QUEUE:
16541 [ # # # # ]: 0 : if (!handle->dvh.rix_sample && !handle->dvh.rix_dest_array)
16542 : 0 : mlx5_hrxq_release(dev, handle->rix_hrxq);
16543 : : break;
16544 : 0 : case MLX5_FLOW_FATE_JUMP:
16545 : 0 : flow_dv_jump_tbl_resource_release(dev, handle->rix_jump);
16546 : 0 : break;
16547 : 0 : case MLX5_FLOW_FATE_PORT_ID:
16548 : 0 : flow_dv_port_id_action_resource_release(dev, handle->rix_port_id_action);
16549 : 0 : break;
16550 : : case MLX5_FLOW_FATE_SEND_TO_KERNEL:
16551 : : /* In case of send_to_kernel action the actual release of
16552 : : * resource is done when all shared DR resources are released
16553 : : * since this resource is created once and always reused.
16554 : : */
16555 : : break;
16556 : 0 : default:
16557 : 0 : DRV_LOG(DEBUG, "Incorrect fate action:%d", handle->fate_action);
16558 : 0 : break;
16559 : : }
16560 : 0 : handle->rix_fate = 0;
16561 : : }
16562 : :
16563 : : void
16564 : 0 : mlx5_flow_dv_sample_remove_cb(void *tool_ctx __rte_unused,
16565 : : struct mlx5_list_entry *entry)
16566 : : {
16567 : : struct mlx5_flow_dv_sample_resource *resource = container_of(entry,
16568 : : typeof(*resource),
16569 : : entry);
16570 : 0 : struct rte_eth_dev *dev = resource->dev;
16571 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16572 : :
16573 [ # # ]: 0 : if (resource->verbs_action)
16574 : : claim_zero(mlx5_flow_os_destroy_flow_action
16575 : : (resource->verbs_action));
16576 [ # # ]: 0 : if (resource->normal_path_tbl)
16577 : 0 : mlx5_flow_dv_tbl_resource_release(MLX5_SH(dev), resource->normal_path_tbl);
16578 : 0 : flow_dv_sample_sub_actions_release(dev, &resource->sample_idx);
16579 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_SAMPLE], resource->idx);
16580 : 0 : DRV_LOG(DEBUG, "sample resource %p: removed", (void *)resource);
16581 : 0 : }
16582 : :
16583 : : /**
16584 : : * Release an sample resource.
16585 : : *
16586 : : * @param dev
16587 : : * Pointer to Ethernet device.
16588 : : * @param handle
16589 : : * Pointer to mlx5_flow_handle.
16590 : : *
16591 : : * @return
16592 : : * 1 while a reference on it exists, 0 when freed.
16593 : : */
16594 : : static int
16595 : 0 : flow_dv_sample_resource_release(struct rte_eth_dev *dev,
16596 : : struct mlx5_flow_handle *handle)
16597 : : {
16598 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16599 : : struct mlx5_flow_dv_sample_resource *resource;
16600 : :
16601 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_SAMPLE],
16602 : : handle->dvh.rix_sample);
16603 [ # # ]: 0 : if (!resource)
16604 : : return 0;
16605 : : MLX5_ASSERT(resource->verbs_action);
16606 : 0 : return mlx5_list_unregister(priv->sh->sample_action_list,
16607 : : &resource->entry);
16608 : : }
16609 : :
16610 : : void
16611 : 0 : mlx5_flow_dv_dest_array_remove_cb(void *tool_ctx __rte_unused,
16612 : : struct mlx5_list_entry *entry)
16613 : : {
16614 : : struct mlx5_flow_dv_dest_array_resource *resource =
16615 : : container_of(entry, typeof(*resource), entry);
16616 : 0 : struct rte_eth_dev *dev = resource->dev;
16617 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16618 : : uint32_t i = 0;
16619 : :
16620 : : MLX5_ASSERT(resource->action);
16621 [ # # ]: 0 : if (resource->action)
16622 : : claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
16623 [ # # ]: 0 : for (; i < resource->num_of_dest; i++)
16624 : 0 : flow_dv_sample_sub_actions_release(dev,
16625 : : &resource->sample_idx[i]);
16626 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY], resource->idx);
16627 : 0 : DRV_LOG(DEBUG, "destination array resource %p: removed",
16628 : : (void *)resource);
16629 : 0 : }
16630 : :
16631 : : /**
16632 : : * Release an destination array resource.
16633 : : *
16634 : : * @param dev
16635 : : * Pointer to Ethernet device.
16636 : : * @param handle
16637 : : * Pointer to mlx5_flow_handle.
16638 : : *
16639 : : * @return
16640 : : * 1 while a reference on it exists, 0 when freed.
16641 : : */
16642 : : static int
16643 : 0 : flow_dv_dest_array_resource_release(struct rte_eth_dev *dev,
16644 : : struct mlx5_flow_handle *handle)
16645 : : {
16646 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16647 : : struct mlx5_flow_dv_dest_array_resource *resource;
16648 : :
16649 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY],
16650 : : handle->dvh.rix_dest_array);
16651 [ # # ]: 0 : if (!resource)
16652 : : return 0;
16653 : : MLX5_ASSERT(resource->action);
16654 : 0 : return mlx5_list_unregister(priv->sh->dest_array_list,
16655 : : &resource->entry);
16656 : : }
16657 : :
16658 : : static void
16659 : 0 : flow_dev_geneve_tlv_option_resource_release(struct mlx5_dev_ctx_shared *sh)
16660 : : {
16661 : 0 : struct mlx5_geneve_tlv_option_resource *geneve_opt_resource =
16662 : : sh->geneve_tlv_option_resource;
16663 : 0 : rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
16664 [ # # ]: 0 : if (geneve_opt_resource) {
16665 [ # # ]: 0 : if (!(rte_atomic_fetch_sub_explicit(&geneve_opt_resource->refcnt, 1,
16666 : : rte_memory_order_relaxed) - 1)) {
16667 : 0 : claim_zero(mlx5_devx_cmd_destroy
16668 : : (geneve_opt_resource->obj));
16669 : 0 : mlx5_free(sh->geneve_tlv_option_resource);
16670 : 0 : sh->geneve_tlv_option_resource = NULL;
16671 : : }
16672 : : }
16673 : : rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
16674 : 0 : }
16675 : :
16676 : : /**
16677 : : * Remove the flow from the NIC but keeps it in memory.
16678 : : * Lock free, (mutex should be acquired by caller).
16679 : : *
16680 : : * @param[in] dev
16681 : : * Pointer to Ethernet device.
16682 : : * @param[in, out] flow
16683 : : * Pointer to flow structure.
16684 : : */
16685 : : static void
16686 : 0 : flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
16687 : : {
16688 : : struct mlx5_flow_handle *dh;
16689 : : uint32_t handle_idx;
16690 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16691 : :
16692 [ # # ]: 0 : if (!flow)
16693 : : return;
16694 : 0 : handle_idx = flow->dev_handles;
16695 [ # # ]: 0 : while (handle_idx) {
16696 : 0 : dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
16697 : : handle_idx);
16698 [ # # ]: 0 : if (!dh)
16699 : : return;
16700 [ # # ]: 0 : if (dh->drv_flow) {
16701 : : claim_zero(mlx5_flow_os_destroy_flow(dh->drv_flow));
16702 : 0 : dh->drv_flow = NULL;
16703 : : }
16704 [ # # ]: 0 : if (dh->fate_action == MLX5_FLOW_FATE_QUEUE)
16705 : 0 : flow_dv_fate_resource_release(dev, dh);
16706 [ # # # # ]: 0 : if (dh->vf_vlan.tag && dh->vf_vlan.created)
16707 : 0 : mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
16708 : 0 : handle_idx = dh->next.next;
16709 : : }
16710 : : }
16711 : :
16712 : : /**
16713 : : * Remove the flow from the NIC and the memory.
16714 : : * Lock free, (mutex should be acquired by caller).
16715 : : *
16716 : : * @param[in] dev
16717 : : * Pointer to the Ethernet device structure.
16718 : : * @param[in, out] flow
16719 : : * Pointer to flow structure.
16720 : : */
16721 : : static void
16722 : 0 : flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
16723 : : {
16724 : : struct mlx5_flow_handle *dev_handle;
16725 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16726 : : struct mlx5_flow_meter_info *fm = NULL;
16727 : : uint32_t srss = 0;
16728 : :
16729 [ # # ]: 0 : if (!flow)
16730 : : return;
16731 : 0 : flow_dv_remove(dev, flow);
16732 [ # # ]: 0 : if (flow->counter) {
16733 : 0 : flow_dv_counter_free(dev, flow->counter);
16734 : 0 : flow->counter = 0;
16735 : : }
16736 [ # # ]: 0 : if (flow->meter) {
16737 : 0 : fm = mlx5_flow_dv_meter_find_by_idx(priv, flow->meter);
16738 [ # # ]: 0 : if (fm)
16739 : 0 : mlx5_flow_meter_detach(priv, fm);
16740 : 0 : flow->meter = 0;
16741 : : }
16742 : : /* Keep the current age handling by default. */
16743 [ # # # # ]: 0 : if (flow->indirect_type == MLX5_INDIRECT_ACTION_TYPE_CT && flow->ct)
16744 : 0 : flow_dv_aso_ct_release(dev, flow->ct, NULL);
16745 [ # # ]: 0 : else if (flow->age)
16746 : 0 : flow_dv_aso_age_release(dev, flow->age);
16747 [ # # ]: 0 : while (flow->geneve_tlv_option) {
16748 : 0 : flow_dev_geneve_tlv_option_resource_release(priv->sh);
16749 : 0 : flow->geneve_tlv_option--;
16750 : : }
16751 [ # # ]: 0 : while (flow->dev_handles) {
16752 : : uint32_t tmp_idx = flow->dev_handles;
16753 : :
16754 : 0 : dev_handle = mlx5_ipool_get(priv->sh->ipool
16755 : : [MLX5_IPOOL_MLX5_FLOW], tmp_idx);
16756 [ # # ]: 0 : if (!dev_handle)
16757 : : return;
16758 : 0 : flow->dev_handles = dev_handle->next.next;
16759 [ # # ]: 0 : while (dev_handle->flex_item) {
16760 : 0 : int index = rte_bsf32(dev_handle->flex_item);
16761 : :
16762 : 0 : mlx5_flex_release_index(dev, index);
16763 : 0 : dev_handle->flex_item &= ~(uint8_t)RTE_BIT32(index);
16764 : : }
16765 [ # # ]: 0 : if (dev_handle->dvh.matcher)
16766 : 0 : flow_dv_matcher_release(dev, dev_handle);
16767 [ # # ]: 0 : if (dev_handle->dvh.rix_sample)
16768 : 0 : flow_dv_sample_resource_release(dev, dev_handle);
16769 [ # # ]: 0 : if (dev_handle->dvh.rix_dest_array)
16770 : 0 : flow_dv_dest_array_resource_release(dev, dev_handle);
16771 [ # # ]: 0 : if (dev_handle->dvh.rix_encap_decap)
16772 : 0 : mlx5_flow_encap_decap_resource_release(dev,
16773 : : dev_handle->dvh.rix_encap_decap);
16774 [ # # ]: 0 : if (dev_handle->dvh.modify_hdr)
16775 : : flow_dv_modify_hdr_resource_release(dev, dev_handle);
16776 [ # # ]: 0 : if (dev_handle->dvh.rix_push_vlan)
16777 : 0 : flow_dv_push_vlan_action_resource_release(dev,
16778 : : dev_handle);
16779 [ # # ]: 0 : if (dev_handle->dvh.rix_tag)
16780 : 0 : flow_dv_tag_release(dev,
16781 : : dev_handle->dvh.rix_tag);
16782 [ # # ]: 0 : if (dev_handle->fate_action != MLX5_FLOW_FATE_SHARED_RSS)
16783 : 0 : flow_dv_fate_resource_release(dev, dev_handle);
16784 [ # # ]: 0 : else if (!srss)
16785 : 0 : srss = dev_handle->rix_srss;
16786 [ # # # # ]: 0 : if (fm && dev_handle->is_meter_flow_id &&
16787 [ # # ]: 0 : dev_handle->split_flow_id)
16788 : 0 : mlx5_ipool_free(fm->flow_ipool,
16789 : : dev_handle->split_flow_id);
16790 [ # # ]: 0 : else if (dev_handle->split_flow_id &&
16791 [ # # ]: 0 : !dev_handle->is_meter_flow_id)
16792 : 0 : mlx5_ipool_free(priv->sh->ipool
16793 : : [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
16794 : : dev_handle->split_flow_id);
16795 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
16796 : : tmp_idx);
16797 : : }
16798 [ # # ]: 0 : if (srss)
16799 : 0 : flow_dv_shared_rss_action_release(dev, srss);
16800 : : }
16801 : :
16802 : : /**
16803 : : * Release array of hash RX queue objects.
16804 : : * Helper function.
16805 : : *
16806 : : * @param[in] dev
16807 : : * Pointer to the Ethernet device structure.
16808 : : * @param[in, out] hrxqs
16809 : : * Array of hash RX queue objects.
16810 : : *
16811 : : * @return
16812 : : * Total number of references to hash RX queue objects in *hrxqs* array
16813 : : * after this operation.
16814 : : */
16815 : : static int
16816 : 0 : __flow_dv_hrxqs_release(struct rte_eth_dev *dev,
16817 : : uint32_t (*hrxqs)[MLX5_RSS_HASH_IDX_MAX])
16818 : : {
16819 : : size_t i;
16820 : : int remaining = 0;
16821 : :
16822 [ # # ]: 0 : for (i = 0; i < RTE_DIM(*hrxqs); i++) {
16823 : 0 : int ret = mlx5_hrxq_release(dev, (*hrxqs)[i]);
16824 : :
16825 [ # # ]: 0 : if (!ret)
16826 : 0 : (*hrxqs)[i] = 0;
16827 : 0 : remaining += ret;
16828 : : }
16829 : 0 : return remaining;
16830 : : }
16831 : :
16832 : : /**
16833 : : * Release all hash RX queue objects representing shared RSS action.
16834 : : *
16835 : : * @param[in] dev
16836 : : * Pointer to the Ethernet device structure.
16837 : : * @param[in, out] action
16838 : : * Shared RSS action to remove hash RX queue objects from.
16839 : : *
16840 : : * @return
16841 : : * Total number of references to hash RX queue objects stored in *action*
16842 : : * after this operation.
16843 : : * Expected to be 0 if no external references held.
16844 : : */
16845 : : static int
16846 : : __flow_dv_action_rss_hrxqs_release(struct rte_eth_dev *dev,
16847 : : struct mlx5_shared_action_rss *shared_rss)
16848 : : {
16849 : 0 : return __flow_dv_hrxqs_release(dev, &shared_rss->hrxq);
16850 : : }
16851 : :
16852 : : static inline void
16853 : : filter_ipv4_types(uint64_t rss_types, uint64_t *hash_fields)
16854 : : {
16855 [ # # ]: 0 : if (rss_types & MLX5_IPV4_LAYER_TYPES) {
16856 : 0 : *hash_fields &= ~MLX5_RSS_HASH_IPV4;
16857 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
16858 : 0 : *hash_fields |= IBV_RX_HASH_DST_IPV4;
16859 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
16860 : 0 : *hash_fields |= IBV_RX_HASH_SRC_IPV4;
16861 : : else
16862 : 0 : *hash_fields |= MLX5_RSS_HASH_IPV4;
16863 : : }
16864 : : }
16865 : :
16866 : : static inline void
16867 : : filter_ipv6_types(uint64_t rss_types, uint64_t *hash_fields)
16868 : : {
16869 [ # # ]: 0 : if (rss_types & MLX5_IPV6_LAYER_TYPES) {
16870 : 0 : *hash_fields &= ~MLX5_RSS_HASH_IPV6;
16871 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
16872 : 0 : *hash_fields |= IBV_RX_HASH_DST_IPV6;
16873 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
16874 : 0 : *hash_fields |= IBV_RX_HASH_SRC_IPV6;
16875 : : else
16876 : 0 : *hash_fields |= MLX5_RSS_HASH_IPV6;
16877 : : }
16878 : : }
16879 : :
16880 : : static inline void
16881 : : filter_udp_types(uint64_t rss_types, uint64_t *hash_fields)
16882 : : {
16883 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_UDP) {
16884 : 0 : *hash_fields &= ~MLX5_UDP_IBV_RX_HASH;
16885 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
16886 : 0 : *hash_fields |= IBV_RX_HASH_DST_PORT_UDP;
16887 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
16888 : 0 : *hash_fields |= IBV_RX_HASH_SRC_PORT_UDP;
16889 : : else
16890 : 0 : *hash_fields |= MLX5_UDP_IBV_RX_HASH;
16891 : : }
16892 : : }
16893 : :
16894 : : static inline void
16895 : : filter_tcp_types(uint64_t rss_types, uint64_t *hash_fields)
16896 : : {
16897 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_TCP) {
16898 : 0 : *hash_fields &= ~MLX5_TCP_IBV_RX_HASH;
16899 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
16900 : 0 : *hash_fields |= IBV_RX_HASH_DST_PORT_TCP;
16901 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
16902 : 0 : *hash_fields |= IBV_RX_HASH_SRC_PORT_TCP;
16903 : : else
16904 : 0 : *hash_fields |= MLX5_TCP_IBV_RX_HASH;
16905 : : }
16906 : : }
16907 : :
16908 : : /**
16909 : : * Adjust L3/L4 hash value of pre-created shared RSS hrxq according to
16910 : : * user input.
16911 : : *
16912 : : * Only one hash value is available for one L3+L4 combination:
16913 : : * for example:
16914 : : * MLX5_RSS_HASH_IPV4, MLX5_RSS_HASH_IPV4_SRC_ONLY, and
16915 : : * MLX5_RSS_HASH_IPV4_DST_ONLY are mutually exclusive so they can share
16916 : : * same slot in mlx5_rss_hash_fields.
16917 : : *
16918 : : * @param[in] orig_rss_types
16919 : : * RSS type as provided in shared RSS action, specified as a bitmap of RTE_ETH_RSS_* flags.
16920 : : * @param[in, out] hash_field
16921 : : * hash_field variable needed to be adjusted, specified as a bitmap of #ibv_rx_hash_fields flags.
16922 : : *
16923 : : * @return
16924 : : * void
16925 : : */
16926 : : void
16927 : 0 : mlx5_flow_dv_action_rss_l34_hash_adjust(uint64_t orig_rss_types,
16928 : : uint64_t *hash_field)
16929 : : {
16930 [ # # ]: 0 : uint64_t hash_field_protos = *hash_field & ~IBV_RX_HASH_INNER;
16931 : : uint64_t rss_types = rte_eth_rss_hf_refine(orig_rss_types);
16932 : :
16933 [ # # ]: 0 : if (hash_field_protos & MLX5_RSS_HASH_IPV4)
16934 : : filter_ipv4_types(rss_types, hash_field);
16935 [ # # ]: 0 : else if (hash_field_protos & MLX5_RSS_HASH_IPV6)
16936 : : filter_ipv6_types(rss_types, hash_field);
16937 : :
16938 [ # # ]: 0 : if (hash_field_protos & MLX5_UDP_IBV_RX_HASH)
16939 : : filter_udp_types(rss_types, hash_field);
16940 [ # # ]: 0 : else if (hash_field_protos & MLX5_TCP_IBV_RX_HASH)
16941 : : filter_tcp_types(rss_types, hash_field);
16942 : 0 : }
16943 : :
16944 : : /**
16945 : : * Setup shared RSS action.
16946 : : * Prepare set of hash RX queue objects sufficient to handle all valid
16947 : : * hash_fields combinations (see enum ibv_rx_hash_fields).
16948 : : *
16949 : : * @param[in] dev
16950 : : * Pointer to the Ethernet device structure.
16951 : : * @param[in] action_idx
16952 : : * Shared RSS action ipool index.
16953 : : * @param[in, out] action
16954 : : * Partially initialized shared RSS action.
16955 : : * @param[out] error
16956 : : * Perform verbose error reporting if not NULL. Initialized in case of
16957 : : * error only.
16958 : : *
16959 : : * @return
16960 : : * 0 on success, otherwise negative errno value.
16961 : : */
16962 : : static int
16963 : 0 : __flow_dv_action_rss_setup(struct rte_eth_dev *dev,
16964 : : uint32_t action_idx,
16965 : : struct mlx5_shared_action_rss *shared_rss,
16966 : : struct rte_flow_error *error)
16967 : : {
16968 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16969 : 0 : struct mlx5_flow_rss_desc rss_desc = { 0 };
16970 : : size_t i;
16971 : : int err;
16972 : :
16973 : 0 : shared_rss->ind_tbl = mlx5_ind_table_obj_new
16974 : : (dev, shared_rss->origin.queue,
16975 : : shared_rss->origin.queue_num,
16976 : : true,
16977 : 0 : !!dev->data->dev_started);
16978 [ # # ]: 0 : if (!shared_rss->ind_tbl)
16979 : 0 : return rte_flow_error_set(error, rte_errno,
16980 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16981 : : "cannot setup indirection table");
16982 : 0 : memcpy(rss_desc.key, shared_rss->origin.key, MLX5_RSS_HASH_KEY_LEN);
16983 : 0 : rss_desc.key_len = MLX5_RSS_HASH_KEY_LEN;
16984 : 0 : rss_desc.symmetric_hash_function =
16985 : 0 : MLX5_RSS_IS_SYMM(shared_rss->origin.func);
16986 : 0 : rss_desc.const_q = shared_rss->origin.queue;
16987 : 0 : rss_desc.queue_num = shared_rss->origin.queue_num;
16988 : : /* Set non-zero value to indicate a shared RSS. */
16989 : 0 : rss_desc.shared_rss = action_idx;
16990 : 0 : rss_desc.ind_tbl = shared_rss->ind_tbl;
16991 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
16992 : 0 : rss_desc.hws_flags = MLX5DR_ACTION_FLAG_HWS_RX;
16993 [ # # ]: 0 : for (i = 0; i < MLX5_RSS_HASH_IDX_MAX; i++) {
16994 : : struct mlx5_hrxq *hrxq;
16995 : 0 : uint64_t hash_fields = mlx5_rss_hash_fields[i];
16996 : : int tunnel = 0;
16997 : :
16998 : 0 : mlx5_flow_dv_action_rss_l34_hash_adjust(shared_rss->origin.types,
16999 : : &hash_fields);
17000 [ # # ]: 0 : if (shared_rss->origin.level > 1) {
17001 : 0 : hash_fields |= IBV_RX_HASH_INNER;
17002 : : tunnel = 1;
17003 : : }
17004 : 0 : rss_desc.tunnel = tunnel;
17005 : 0 : rss_desc.hash_fields = hash_fields;
17006 : 0 : hrxq = mlx5_hrxq_get(dev, &rss_desc);
17007 [ # # ]: 0 : if (!hrxq) {
17008 : 0 : rte_flow_error_set
17009 : : (error, rte_errno,
17010 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
17011 : : "cannot get hash queue");
17012 : 0 : goto error_hrxq_new;
17013 : : }
17014 : 0 : err = __flow_dv_action_rss_hrxq_set
17015 : : (shared_rss, hash_fields, hrxq->idx);
17016 : : MLX5_ASSERT(!err);
17017 : : }
17018 : : return 0;
17019 : : error_hrxq_new:
17020 : 0 : err = rte_errno;
17021 : : __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
17022 [ # # ]: 0 : if (!mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl, true))
17023 : 0 : shared_rss->ind_tbl = NULL;
17024 : 0 : rte_errno = err;
17025 : 0 : return -rte_errno;
17026 : : }
17027 : :
17028 : : /**
17029 : : * Create shared RSS action.
17030 : : *
17031 : : * @param[in] dev
17032 : : * Pointer to the Ethernet device structure.
17033 : : * @param[in] conf
17034 : : * Shared action configuration.
17035 : : * @param[in] rss
17036 : : * RSS action specification used to create shared action.
17037 : : * @param[out] error
17038 : : * Perform verbose error reporting if not NULL. Initialized in case of
17039 : : * error only.
17040 : : *
17041 : : * @return
17042 : : * A valid shared action ID in case of success, 0 otherwise and
17043 : : * rte_errno is set.
17044 : : */
17045 : : static uint32_t
17046 : 0 : __flow_dv_action_rss_create(struct rte_eth_dev *dev,
17047 : : const struct rte_flow_indir_action_conf *conf,
17048 : : const struct rte_flow_action_rss *rss,
17049 : : struct rte_flow_error *error)
17050 : : {
17051 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17052 : : struct mlx5_shared_action_rss *shared_rss = NULL;
17053 : : struct rte_flow_action_rss *origin;
17054 : : const uint8_t *rss_key;
17055 : : uint32_t idx;
17056 : :
17057 : : RTE_SET_USED(conf);
17058 : 0 : shared_rss = mlx5_ipool_zmalloc
17059 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], &idx);
17060 [ # # ]: 0 : if (!shared_rss) {
17061 : 0 : rte_flow_error_set(error, ENOMEM,
17062 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
17063 : : "cannot allocate resource memory");
17064 : 0 : goto error_rss_init;
17065 : : }
17066 [ # # ]: 0 : if (idx > (1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET)) {
17067 : 0 : rte_flow_error_set(error, E2BIG,
17068 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
17069 : : "rss action number out of range");
17070 : 0 : goto error_rss_init;
17071 : : }
17072 : : origin = &shared_rss->origin;
17073 : 0 : origin->func = rss->func;
17074 : 0 : origin->level = rss->level;
17075 : : /* RSS type 0 indicates default RSS type (RTE_ETH_RSS_IP). */
17076 [ # # ]: 0 : origin->types = !rss->types ? RTE_ETH_RSS_IP : rss->types;
17077 : : /* NULL RSS key indicates default RSS key. */
17078 [ # # ]: 0 : rss_key = !rss->key ? mlx5_rss_hash_default_key : rss->key;
17079 : 0 : memcpy(shared_rss->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
17080 : 0 : origin->key = &shared_rss->key[0];
17081 : 0 : origin->key_len = MLX5_RSS_HASH_KEY_LEN;
17082 : 0 : origin->queue = rss->queue;
17083 : 0 : origin->queue_num = rss->queue_num;
17084 [ # # ]: 0 : if (__flow_dv_action_rss_setup(dev, idx, shared_rss, error))
17085 : 0 : goto error_rss_init;
17086 : : /* Update queue with indirect table queue memoyr. */
17087 : 0 : origin->queue = shared_rss->ind_tbl->queues;
17088 : : rte_spinlock_init(&shared_rss->action_rss_sl);
17089 : 0 : rte_atomic_fetch_add_explicit(&shared_rss->refcnt, 1, rte_memory_order_relaxed);
17090 : 0 : rte_spinlock_lock(&priv->shared_act_sl);
17091 [ # # # # ]: 0 : ILIST_INSERT(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
17092 : : &priv->rss_shared_actions, idx, shared_rss, next);
17093 : : rte_spinlock_unlock(&priv->shared_act_sl);
17094 : 0 : return idx;
17095 : 0 : error_rss_init:
17096 [ # # ]: 0 : if (shared_rss) {
17097 [ # # ]: 0 : if (shared_rss->ind_tbl)
17098 : 0 : mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl,
17099 : 0 : !!dev->data->dev_started);
17100 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
17101 : : idx);
17102 : : }
17103 : : return 0;
17104 : : }
17105 : :
17106 : : /**
17107 : : * Destroy the shared RSS action.
17108 : : * Release related hash RX queue objects.
17109 : : *
17110 : : * @param[in] dev
17111 : : * Pointer to the Ethernet device structure.
17112 : : * @param[in] idx
17113 : : * The shared RSS action object ID to be removed.
17114 : : * @param[out] error
17115 : : * Perform verbose error reporting if not NULL. Initialized in case of
17116 : : * error only.
17117 : : *
17118 : : * @return
17119 : : * 0 on success, otherwise negative errno value.
17120 : : */
17121 : : static int
17122 : 0 : __flow_dv_action_rss_release(struct rte_eth_dev *dev, uint32_t idx,
17123 : : struct rte_flow_error *error)
17124 : : {
17125 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17126 : : struct mlx5_shared_action_rss *shared_rss =
17127 : 0 : mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
17128 : : uint32_t old_refcnt = 1;
17129 : : int remaining;
17130 : :
17131 [ # # ]: 0 : if (!shared_rss)
17132 : 0 : return rte_flow_error_set(error, EINVAL,
17133 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
17134 : : "invalid shared action");
17135 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(&shared_rss->refcnt, &old_refcnt,
17136 : : 0, rte_memory_order_acquire,
17137 : : rte_memory_order_relaxed))
17138 : 0 : return rte_flow_error_set(error, EBUSY,
17139 : : RTE_FLOW_ERROR_TYPE_ACTION,
17140 : : NULL,
17141 : : "shared rss has references");
17142 : : remaining = __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
17143 [ # # ]: 0 : if (remaining)
17144 : 0 : return rte_flow_error_set(error, EBUSY,
17145 : : RTE_FLOW_ERROR_TYPE_ACTION,
17146 : : NULL,
17147 : : "shared rss hrxq has references");
17148 : 0 : remaining = mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl,
17149 : 0 : !!dev->data->dev_started);
17150 [ # # ]: 0 : if (remaining)
17151 : 0 : return rte_flow_error_set(error, EBUSY,
17152 : : RTE_FLOW_ERROR_TYPE_ACTION,
17153 : : NULL,
17154 : : "shared rss indirection table has"
17155 : : " references");
17156 : 0 : rte_spinlock_lock(&priv->shared_act_sl);
17157 [ # # # # : 0 : ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
# # # # #
# ]
17158 : : &priv->rss_shared_actions, idx, shared_rss, next);
17159 : : rte_spinlock_unlock(&priv->shared_act_sl);
17160 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
17161 : : idx);
17162 : 0 : return 0;
17163 : : }
17164 : :
17165 : : /**
17166 : : * Create indirect action, lock free,
17167 : : * (mutex should be acquired by caller).
17168 : : * Dispatcher for action type specific call.
17169 : : *
17170 : : * @param[in] dev
17171 : : * Pointer to the Ethernet device structure.
17172 : : * @param[in] conf
17173 : : * Shared action configuration.
17174 : : * @param[in] action
17175 : : * Action specification used to create indirect action.
17176 : : * @param[out] error
17177 : : * Perform verbose error reporting if not NULL. Initialized in case of
17178 : : * error only.
17179 : : *
17180 : : * @return
17181 : : * A valid shared action handle in case of success, NULL otherwise and
17182 : : * rte_errno is set.
17183 : : */
17184 : : struct rte_flow_action_handle *
17185 : 0 : mlx5_flow_dv_action_create(struct rte_eth_dev *dev,
17186 : : const struct rte_flow_indir_action_conf *conf,
17187 : : const struct rte_flow_action *action,
17188 : : struct rte_flow_error *err)
17189 : : {
17190 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17191 : : uint32_t age_idx = 0;
17192 : : uint32_t idx = 0;
17193 : : uint32_t ret = 0;
17194 : :
17195 [ # # # # : 0 : switch (action->type) {
# ]
17196 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
17197 : 0 : ret = __flow_dv_action_rss_create(dev, conf, action->conf, err);
17198 : : idx = (MLX5_INDIRECT_ACTION_TYPE_RSS <<
17199 : : MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
17200 : 0 : break;
17201 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
17202 : 0 : age_idx = flow_dv_aso_age_alloc(dev, err);
17203 [ # # ]: 0 : if (!age_idx) {
17204 : 0 : ret = -rte_errno;
17205 : 0 : break;
17206 : : }
17207 : 0 : idx = (MLX5_INDIRECT_ACTION_TYPE_AGE <<
17208 : : MLX5_INDIRECT_ACTION_TYPE_OFFSET) | age_idx;
17209 : 0 : flow_dv_aso_age_params_init(dev, age_idx,
17210 : : ((const struct rte_flow_action_age *)
17211 : 0 : action->conf)->context ?
17212 : : ((const struct rte_flow_action_age *)
17213 : : action->conf)->context :
17214 : 0 : (void *)(uintptr_t)idx,
17215 : : ((const struct rte_flow_action_age *)
17216 [ # # ]: 0 : action->conf)->timeout);
17217 : : ret = age_idx;
17218 : 0 : break;
17219 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
17220 : 0 : ret = flow_dv_translate_create_counter(dev, NULL, NULL, NULL);
17221 : 0 : idx = (MLX5_INDIRECT_ACTION_TYPE_COUNT <<
17222 : : MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
17223 : 0 : break;
17224 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
17225 : 0 : ret = flow_dv_translate_create_conntrack(dev, action->conf,
17226 : : err);
17227 [ # # ]: 0 : if (!ret)
17228 : : break;
17229 : 0 : idx = MLX5_INDIRECT_ACT_CT_GEN_IDX(PORT_ID(priv), ret);
17230 : 0 : break;
17231 : 0 : default:
17232 : 0 : rte_flow_error_set(err, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
17233 : : NULL, "action type not supported");
17234 : : break;
17235 : : }
17236 [ # # ]: 0 : return ret ? (struct rte_flow_action_handle *)(uintptr_t)idx : NULL;
17237 : : }
17238 : :
17239 : : /**
17240 : : * Destroy the indirect action.
17241 : : * Release action related resources on the NIC and the memory.
17242 : : * Lock free, (mutex should be acquired by caller).
17243 : : * Dispatcher for action type specific call.
17244 : : *
17245 : : * @param[in] dev
17246 : : * Pointer to the Ethernet device structure.
17247 : : * @param[in] handle
17248 : : * The indirect action object handle to be removed.
17249 : : * @param[out] error
17250 : : * Perform verbose error reporting if not NULL. Initialized in case of
17251 : : * error only.
17252 : : *
17253 : : * @return
17254 : : * 0 on success, otherwise negative errno value.
17255 : : */
17256 : : int
17257 : 0 : mlx5_flow_dv_action_destroy(struct rte_eth_dev *dev,
17258 : : struct rte_flow_action_handle *handle,
17259 : : struct rte_flow_error *error)
17260 : : {
17261 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
17262 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
17263 : 0 : uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
17264 : : struct mlx5_flow_counter *cnt;
17265 : : uint32_t no_flow_refcnt = 1;
17266 : : int ret;
17267 : :
17268 [ # # # # : 0 : switch (type) {
# ]
17269 : 0 : case MLX5_INDIRECT_ACTION_TYPE_RSS:
17270 : 0 : return __flow_dv_action_rss_release(dev, idx, error);
17271 : : case MLX5_INDIRECT_ACTION_TYPE_COUNT:
17272 : : cnt = flow_dv_counter_get_by_idx(dev, idx, NULL);
17273 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(&cnt->shared_info.refcnt,
17274 : : &no_flow_refcnt, 1,
17275 : : rte_memory_order_acquire,
17276 : : rte_memory_order_relaxed))
17277 : 0 : return rte_flow_error_set(error, EBUSY,
17278 : : RTE_FLOW_ERROR_TYPE_ACTION,
17279 : : NULL,
17280 : : "Indirect count action has references");
17281 : 0 : flow_dv_counter_free(dev, idx);
17282 : 0 : return 0;
17283 : 0 : case MLX5_INDIRECT_ACTION_TYPE_AGE:
17284 : 0 : ret = flow_dv_aso_age_release(dev, idx);
17285 [ # # ]: 0 : if (ret)
17286 : : /*
17287 : : * In this case, the last flow has a reference will
17288 : : * actually release the age action.
17289 : : */
17290 : 0 : DRV_LOG(DEBUG, "Indirect age action %" PRIu32 " was"
17291 : : " released with references %d.", idx, ret);
17292 : : return 0;
17293 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
17294 : 0 : ret = flow_dv_aso_ct_release(dev, idx, error);
17295 [ # # ]: 0 : if (ret < 0)
17296 : : return ret;
17297 [ # # ]: 0 : if (ret > 0)
17298 : 0 : DRV_LOG(DEBUG, "Connection tracking object %u still "
17299 : : "has references %d.", idx, ret);
17300 : : return 0;
17301 : 0 : default:
17302 : 0 : return rte_flow_error_set(error, ENOTSUP,
17303 : : RTE_FLOW_ERROR_TYPE_ACTION,
17304 : : NULL,
17305 : : "action type not supported");
17306 : : }
17307 : : }
17308 : :
17309 : : /**
17310 : : * Updates in place shared RSS action configuration.
17311 : : *
17312 : : * @param[in] dev
17313 : : * Pointer to the Ethernet device structure.
17314 : : * @param[in] idx
17315 : : * The shared RSS action object ID to be updated.
17316 : : * @param[in] action_conf
17317 : : * RSS action specification used to modify *shared_rss*.
17318 : : * @param[out] error
17319 : : * Perform verbose error reporting if not NULL. Initialized in case of
17320 : : * error only.
17321 : : *
17322 : : * @return
17323 : : * 0 on success, otherwise negative errno value.
17324 : : * @note: currently only support update of RSS queues.
17325 : : */
17326 : : static int
17327 : 0 : __flow_dv_action_rss_update(struct rte_eth_dev *dev, uint32_t idx,
17328 : : const struct rte_flow_action_rss *action_conf,
17329 : : struct rte_flow_error *error)
17330 : : {
17331 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17332 : : struct mlx5_shared_action_rss *shared_rss =
17333 : 0 : mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
17334 : : int ret = 0;
17335 : : void *queue = NULL;
17336 : : void *queue_i = NULL;
17337 : 0 : uint32_t queue_size = action_conf->queue_num * sizeof(uint16_t);
17338 : 0 : bool dev_started = !!dev->data->dev_started;
17339 : :
17340 [ # # ]: 0 : if (!shared_rss)
17341 : 0 : return rte_flow_error_set(error, EINVAL,
17342 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
17343 : : "invalid shared action to update");
17344 [ # # ]: 0 : if (priv->obj_ops.ind_table_modify == NULL)
17345 : 0 : return rte_flow_error_set(error, ENOTSUP,
17346 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
17347 : : "cannot modify indirection table");
17348 : 0 : queue = mlx5_malloc(MLX5_MEM_ZERO,
17349 : 0 : RTE_ALIGN_CEIL(queue_size, sizeof(void *)),
17350 : : 0, SOCKET_ID_ANY);
17351 [ # # ]: 0 : if (!queue)
17352 : 0 : return rte_flow_error_set(error, ENOMEM,
17353 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17354 : : NULL,
17355 : : "cannot allocate resource memory");
17356 : 0 : memcpy(queue, action_conf->queue, queue_size);
17357 : : MLX5_ASSERT(shared_rss->ind_tbl);
17358 : 0 : rte_spinlock_lock(&shared_rss->action_rss_sl);
17359 : 0 : queue_i = shared_rss->ind_tbl->queues;
17360 : 0 : ret = mlx5_ind_table_obj_modify(dev, shared_rss->ind_tbl,
17361 : 0 : queue, action_conf->queue_num,
17362 : : true /* standalone */,
17363 : : dev_started /* ref_new_qs */,
17364 : : dev_started /* deref_old_qs */);
17365 [ # # ]: 0 : if (ret) {
17366 : 0 : ret = rte_flow_error_set(error, rte_errno,
17367 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
17368 : : "cannot update indirection table");
17369 : : } else {
17370 : : /* Restore the queue to indirect table internal queue. */
17371 : : memcpy(queue_i, queue, queue_size);
17372 : 0 : shared_rss->ind_tbl->queues = queue_i;
17373 : 0 : shared_rss->origin.queue_num = action_conf->queue_num;
17374 : : }
17375 : 0 : mlx5_free(queue);
17376 : : rte_spinlock_unlock(&shared_rss->action_rss_sl);
17377 : 0 : return ret;
17378 : : }
17379 : :
17380 : : /*
17381 : : * Updates in place conntrack context or direction.
17382 : : * Context update should be synchronized.
17383 : : *
17384 : : * @param[in] dev
17385 : : * Pointer to the Ethernet device structure.
17386 : : * @param[in] idx
17387 : : * The conntrack object ID to be updated.
17388 : : * @param[in] update
17389 : : * Pointer to the structure of information to update.
17390 : : * @param[out] error
17391 : : * Perform verbose error reporting if not NULL. Initialized in case of
17392 : : * error only.
17393 : : *
17394 : : * @return
17395 : : * 0 on success, otherwise negative errno value.
17396 : : */
17397 : : static int
17398 : 0 : __flow_dv_action_ct_update(struct rte_eth_dev *dev, uint32_t idx,
17399 : : const struct rte_flow_modify_conntrack *update,
17400 : : struct rte_flow_error *error)
17401 : : {
17402 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17403 : : struct mlx5_aso_ct_action *ct;
17404 : : const struct rte_flow_action_conntrack *new_prf;
17405 : : int ret = 0;
17406 : 0 : uint16_t owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(idx);
17407 : : uint32_t dev_idx;
17408 : :
17409 [ # # ]: 0 : if (PORT_ID(priv) != owner)
17410 : 0 : return rte_flow_error_set(error, EACCES,
17411 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17412 : : NULL,
17413 : : "CT object owned by another port");
17414 : 0 : dev_idx = MLX5_INDIRECT_ACT_CT_GET_IDX(idx);
17415 : 0 : ct = flow_aso_ct_get_by_dev_idx(dev, dev_idx);
17416 [ # # ]: 0 : if (!ct->refcnt)
17417 : 0 : return rte_flow_error_set(error, ENOMEM,
17418 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17419 : : NULL,
17420 : : "CT object is inactive");
17421 : 0 : new_prf = &update->new_ct;
17422 [ # # ]: 0 : if (update->direction)
17423 : 0 : ct->is_original = !!new_prf->is_original_dir;
17424 [ # # ]: 0 : if (update->state) {
17425 : : /* Only validate the profile when it needs to be updated. */
17426 : 0 : ret = mlx5_validate_action_ct(dev, new_prf, error);
17427 [ # # ]: 0 : if (ret)
17428 : : return ret;
17429 : 0 : ret = mlx5_aso_ct_update_by_wqe(priv->sh, MLX5_HW_INV_QUEUE,
17430 : : ct, new_prf, NULL, true);
17431 [ # # ]: 0 : if (ret)
17432 : 0 : return rte_flow_error_set(error, EIO,
17433 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17434 : : NULL,
17435 : : "Failed to send CT context update WQE");
17436 : : /* Block until ready or a failure, default is asynchronous. */
17437 : 0 : ret = mlx5_aso_ct_available(priv->sh, MLX5_HW_INV_QUEUE, ct);
17438 [ # # ]: 0 : if (ret)
17439 : 0 : rte_flow_error_set(error, rte_errno,
17440 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17441 : : NULL,
17442 : : "Timeout to get the CT update");
17443 : : }
17444 : : return ret;
17445 : : }
17446 : :
17447 : : /**
17448 : : * Updates in place shared action configuration, lock free,
17449 : : * (mutex should be acquired by caller).
17450 : : *
17451 : : * @param[in] dev
17452 : : * Pointer to the Ethernet device structure.
17453 : : * @param[in] handle
17454 : : * The indirect action object handle to be updated.
17455 : : * @param[in] update
17456 : : * Action specification used to modify the action pointed by *handle*.
17457 : : * *update* could be of same type with the action pointed by the *handle*
17458 : : * handle argument, or some other structures like a wrapper, depending on
17459 : : * the indirect action type.
17460 : : * @param[out] error
17461 : : * Perform verbose error reporting if not NULL. Initialized in case of
17462 : : * error only.
17463 : : *
17464 : : * @return
17465 : : * 0 on success, otherwise negative errno value.
17466 : : */
17467 : : int
17468 : 0 : mlx5_flow_dv_action_update(struct rte_eth_dev *dev,
17469 : : struct rte_flow_action_handle *handle,
17470 : : const void *update,
17471 : : struct rte_flow_error *err)
17472 : : {
17473 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
17474 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
17475 : 0 : uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
17476 : : const void *action_conf;
17477 : :
17478 [ # # # ]: 0 : switch (type) {
17479 : 0 : case MLX5_INDIRECT_ACTION_TYPE_RSS:
17480 : 0 : action_conf = ((const struct rte_flow_action *)update)->conf;
17481 : 0 : return __flow_dv_action_rss_update(dev, idx, action_conf, err);
17482 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
17483 : 0 : return __flow_dv_action_ct_update(dev, idx, update, err);
17484 : 0 : default:
17485 : 0 : return rte_flow_error_set(err, ENOTSUP,
17486 : : RTE_FLOW_ERROR_TYPE_ACTION,
17487 : : NULL,
17488 : : "action type update not supported");
17489 : : }
17490 : : }
17491 : :
17492 : : /**
17493 : : * Destroy the meter sub policy table rules.
17494 : : * Lock free, (mutex should be acquired by caller).
17495 : : *
17496 : : * @param[in] dev
17497 : : * Pointer to Ethernet device.
17498 : : * @param[in] sub_policy
17499 : : * Pointer to meter sub policy table.
17500 : : */
17501 : : static void
17502 : 0 : __flow_dv_destroy_sub_policy_rules(struct rte_eth_dev *dev,
17503 : : struct mlx5_flow_meter_sub_policy *sub_policy)
17504 : : {
17505 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17506 : : struct mlx5_flow_tbl_data_entry *tbl;
17507 : 0 : struct mlx5_flow_meter_policy *policy = sub_policy->main_policy;
17508 : : struct mlx5_flow_meter_info *next_fm;
17509 : : struct mlx5_sub_policy_color_rule *color_rule;
17510 : : void *tmp;
17511 : : uint32_t i;
17512 : :
17513 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
17514 : : next_fm = NULL;
17515 [ # # ]: 0 : if (i <= RTE_COLOR_YELLOW && policy &&
17516 [ # # ]: 0 : policy->act_cnt[i].fate_action == MLX5_FLOW_FATE_MTR)
17517 : 0 : next_fm = mlx5_flow_meter_find(priv,
17518 : : policy->act_cnt[i].next_mtr_id, NULL);
17519 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(color_rule, &sub_policy->color_rules[i],
17520 : : next_port, tmp) {
17521 : 0 : claim_zero(mlx5_flow_os_destroy_flow(color_rule->rule));
17522 : 0 : tbl = container_of(color_rule->matcher->tbl,
17523 : : typeof(*tbl), tbl);
17524 : 0 : mlx5_list_unregister(tbl->matchers,
17525 : : &color_rule->matcher->entry);
17526 [ # # ]: 0 : TAILQ_REMOVE(&sub_policy->color_rules[i],
17527 : : color_rule, next_port);
17528 : 0 : mlx5_free(color_rule);
17529 [ # # ]: 0 : if (next_fm)
17530 : 0 : mlx5_flow_meter_detach(priv, next_fm);
17531 : : }
17532 : : }
17533 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
17534 [ # # ]: 0 : if (sub_policy->rix_hrxq[i]) {
17535 [ # # # # ]: 0 : if (policy && !policy->is_hierarchy)
17536 : 0 : mlx5_hrxq_release(dev, sub_policy->rix_hrxq[i]);
17537 : 0 : sub_policy->rix_hrxq[i] = 0;
17538 : : }
17539 [ # # ]: 0 : if (sub_policy->jump_tbl[i]) {
17540 : 0 : mlx5_flow_dv_tbl_resource_release(MLX5_SH(dev), sub_policy->jump_tbl[i]);
17541 : 0 : sub_policy->jump_tbl[i] = NULL;
17542 : : }
17543 : : }
17544 [ # # ]: 0 : if (sub_policy->tbl_rsc) {
17545 : 0 : mlx5_flow_dv_tbl_resource_release(MLX5_SH(dev), sub_policy->tbl_rsc);
17546 : 0 : sub_policy->tbl_rsc = NULL;
17547 : : }
17548 : 0 : }
17549 : :
17550 : : /**
17551 : : * Destroy policy rules, lock free,
17552 : : * (mutex should be acquired by caller).
17553 : : * Dispatcher for action type specific call.
17554 : : *
17555 : : * @param[in] dev
17556 : : * Pointer to the Ethernet device structure.
17557 : : * @param[in] mtr_policy
17558 : : * Meter policy struct.
17559 : : */
17560 : : static void
17561 : 0 : flow_dv_destroy_policy_rules(struct rte_eth_dev *dev,
17562 : : struct mlx5_flow_meter_policy *mtr_policy)
17563 : : {
17564 : : uint32_t i, j;
17565 : : struct mlx5_flow_meter_sub_policy *sub_policy;
17566 : : uint16_t sub_policy_num;
17567 : :
17568 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
17569 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
17570 : 0 : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
17571 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
17572 [ # # ]: 0 : for (j = 0; j < sub_policy_num; j++) {
17573 : 0 : sub_policy = mtr_policy->sub_policys[i][j];
17574 [ # # ]: 0 : if (sub_policy)
17575 : 0 : __flow_dv_destroy_sub_policy_rules(dev,
17576 : : sub_policy);
17577 : : }
17578 : : }
17579 : 0 : }
17580 : :
17581 : : /**
17582 : : * Destroy policy action, lock free,
17583 : : * (mutex should be acquired by caller).
17584 : : * Dispatcher for action type specific call.
17585 : : *
17586 : : * @param[in] dev
17587 : : * Pointer to the Ethernet device structure.
17588 : : * @param[in] mtr_policy
17589 : : * Meter policy struct.
17590 : : */
17591 : : static void
17592 : 0 : flow_dv_destroy_mtr_policy_acts(struct rte_eth_dev *dev,
17593 : : struct mlx5_flow_meter_policy *mtr_policy)
17594 : : {
17595 : : struct rte_flow_action *rss_action;
17596 : : struct mlx5_flow_handle dev_handle;
17597 : : uint32_t i, j;
17598 : :
17599 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
17600 [ # # ]: 0 : if (mtr_policy->act_cnt[i].rix_mark) {
17601 : 0 : flow_dv_tag_release(dev,
17602 : : mtr_policy->act_cnt[i].rix_mark);
17603 : 0 : mtr_policy->act_cnt[i].rix_mark = 0;
17604 : : }
17605 [ # # ]: 0 : if (mtr_policy->act_cnt[i].modify_hdr) {
17606 : : dev_handle.dvh.modify_hdr =
17607 : : mtr_policy->act_cnt[i].modify_hdr;
17608 : : flow_dv_modify_hdr_resource_release(dev, &dev_handle);
17609 : : }
17610 [ # # # # ]: 0 : switch (mtr_policy->act_cnt[i].fate_action) {
17611 : 0 : case MLX5_FLOW_FATE_SHARED_RSS:
17612 : 0 : rss_action = mtr_policy->act_cnt[i].rss;
17613 : 0 : mlx5_free(rss_action);
17614 : 0 : break;
17615 : 0 : case MLX5_FLOW_FATE_PORT_ID:
17616 [ # # ]: 0 : if (mtr_policy->act_cnt[i].rix_port_id_action) {
17617 : 0 : flow_dv_port_id_action_resource_release(dev,
17618 : : mtr_policy->act_cnt[i].rix_port_id_action);
17619 : 0 : mtr_policy->act_cnt[i].rix_port_id_action = 0;
17620 : : }
17621 : : break;
17622 : : case MLX5_FLOW_FATE_DROP:
17623 : : case MLX5_FLOW_FATE_JUMP:
17624 [ # # ]: 0 : for (j = 0; j < MLX5_MTR_DOMAIN_MAX; j++)
17625 : 0 : mtr_policy->act_cnt[i].dr_jump_action[j] =
17626 : : NULL;
17627 : : break;
17628 : : default:
17629 : : /*Queue action do nothing*/
17630 : : break;
17631 : : }
17632 : : }
17633 [ # # ]: 0 : for (j = 0; j < MLX5_MTR_DOMAIN_MAX; j++)
17634 : 0 : mtr_policy->dr_drop_action[j] = NULL;
17635 : 0 : }
17636 : :
17637 : : /**
17638 : : * Create yellow action for color aware meter.
17639 : : *
17640 : : * @param[in] dev
17641 : : * Pointer to the Ethernet device structure.
17642 : : * @param[in] fm
17643 : : * Meter information table.
17644 : : * @param[out] error
17645 : : * Perform verbose error reporting if not NULL. Initialized in case of
17646 : : * error only.
17647 : : *
17648 : : * @return
17649 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
17650 : : */
17651 : : static int
17652 : 0 : __flow_dv_create_mtr_yellow_action(struct rte_eth_dev *dev,
17653 : : struct mlx5_flow_meter_info *fm,
17654 : : struct rte_mtr_error *error)
17655 : : {
17656 : : #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
17657 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17658 : : struct rte_flow_error flow_err;
17659 : : struct mlx5_aso_mtr *aso_mtr;
17660 : : struct mlx5_aso_mtr_pool *pool;
17661 : : uint8_t reg_id;
17662 : :
17663 : 0 : aso_mtr = container_of(fm, struct mlx5_aso_mtr, fm);
17664 : 0 : pool = container_of(aso_mtr, struct mlx5_aso_mtr_pool, mtrs[aso_mtr->offset]);
17665 : 0 : reg_id = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &flow_err);
17666 : 0 : fm->meter_action_y =
17667 : 0 : mlx5_glue->dv_create_flow_action_aso(priv->sh->rx_domain,
17668 : 0 : pool->devx_obj->obj,
17669 : : aso_mtr->offset,
17670 : : (1 << MLX5_FLOW_COLOR_YELLOW),
17671 : 0 : reg_id - REG_C_0);
17672 : : #else
17673 : : RTE_SET_USED(dev);
17674 : : #endif
17675 [ # # ]: 0 : if (!fm->meter_action_y) {
17676 : 0 : return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
17677 : : "Fail to create yellow meter action.");
17678 : : }
17679 : : return 0;
17680 : : }
17681 : :
17682 : : /**
17683 : : * Create policy action per domain, lock free,
17684 : : * (mutex should be acquired by caller).
17685 : : * Dispatcher for action type specific call.
17686 : : *
17687 : : * @param[in] dev
17688 : : * Pointer to the Ethernet device structure.
17689 : : * @param[in] mtr_policy
17690 : : * Meter policy struct.
17691 : : * @param[in] action
17692 : : * Action specification used to create meter actions.
17693 : : * @param[in] attr
17694 : : * Pointer to the flow attributes.
17695 : : * @param[out] error
17696 : : * Perform verbose error reporting if not NULL. Initialized in case of
17697 : : * error only.
17698 : : *
17699 : : * @return
17700 : : * 0 on success, otherwise negative errno value.
17701 : : */
17702 : : static int
17703 : 0 : __flow_dv_create_domain_policy_acts(struct rte_eth_dev *dev,
17704 : : struct mlx5_flow_meter_policy *mtr_policy,
17705 : : const struct rte_flow_action *actions[RTE_COLORS],
17706 : : struct rte_flow_attr *attr,
17707 : : enum mlx5_meter_domain domain,
17708 : : struct rte_mtr_error *error)
17709 : : {
17710 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17711 : : struct rte_flow_error flow_err;
17712 : : const struct rte_flow_action *act;
17713 : : uint64_t action_flags;
17714 : : struct mlx5_flow_handle dh;
17715 : : struct mlx5_flow dev_flow;
17716 : : struct mlx5_flow_dv_port_id_action_resource port_id_action;
17717 : : int i, ret;
17718 : : uint8_t egress, transfer;
17719 : : struct mlx5_meter_policy_action_container *act_cnt = NULL;
17720 : : union {
17721 : : struct mlx5_flow_dv_modify_hdr_resource res;
17722 : : uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
17723 : : sizeof(struct mlx5_modification_cmd) *
17724 : : (MLX5_MAX_MODIFY_NUM + 1)];
17725 : : } mhdr_dummy;
17726 : : struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
17727 : :
17728 : 0 : egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
17729 [ # # ]: 0 : transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
17730 : : memset(&dh, 0, sizeof(struct mlx5_flow_handle));
17731 : : memset(&dev_flow, 0, sizeof(struct mlx5_flow));
17732 : : memset(&port_id_action, 0,
17733 : : sizeof(struct mlx5_flow_dv_port_id_action_resource));
17734 : : memset(mhdr_res, 0, sizeof(*mhdr_res));
17735 [ # # ]: 0 : mhdr_res->ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
17736 : : (egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
17737 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX);
17738 : 0 : dev_flow.handle = &dh;
17739 : 0 : dev_flow.dv.port_id_action = &port_id_action;
17740 : 0 : dev_flow.external = true;
17741 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
17742 [ # # ]: 0 : if (i < MLX5_MTR_RTE_COLORS)
17743 : 0 : act_cnt = &mtr_policy->act_cnt[i];
17744 : : /* Skip the color policy actions creation. */
17745 [ # # # # : 0 : if ((i == RTE_COLOR_YELLOW && mtr_policy->skip_y) ||
# # ]
17746 [ # # ]: 0 : (i == RTE_COLOR_GREEN && mtr_policy->skip_g))
17747 : 0 : continue;
17748 : : action_flags = 0;
17749 : 0 : for (act = actions[i];
17750 [ # # # # ]: 0 : act && act->type != RTE_FLOW_ACTION_TYPE_END; act++) {
17751 [ # # # # : 0 : switch (act->type) {
# # # # #
# ]
17752 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
17753 : : {
17754 : : uint32_t tag_be = mlx5_flow_mark_set
17755 : : (((const struct rte_flow_action_mark *)
17756 [ # # ]: 0 : (act->conf))->id);
17757 : :
17758 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17759 : 0 : return -rte_mtr_error_set(error,
17760 : : ENOTSUP,
17761 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17762 : : NULL,
17763 : : "cannot create policy "
17764 : : "mark action for this color");
17765 [ # # ]: 0 : if (flow_dv_tag_resource_register(dev, tag_be,
17766 : : &dev_flow, &flow_err))
17767 : 0 : return -rte_mtr_error_set(error,
17768 : : ENOTSUP,
17769 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17770 : : NULL,
17771 : : "cannot setup policy mark action");
17772 : : MLX5_ASSERT(dev_flow.dv.tag_resource);
17773 : 0 : act_cnt->rix_mark =
17774 : 0 : dev_flow.handle->dvh.rix_tag;
17775 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK;
17776 : 0 : mtr_policy->mark = 1;
17777 : 0 : break;
17778 : : }
17779 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TAG:
17780 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17781 : 0 : return -rte_mtr_error_set(error,
17782 : : ENOTSUP,
17783 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17784 : : NULL,
17785 : : "cannot create policy "
17786 : : "set tag action for this color");
17787 [ # # ]: 0 : if (flow_dv_convert_action_set_tag
17788 : : (dev, mhdr_res,
17789 : : (const struct rte_flow_action_set_tag *)
17790 : 0 : act->conf, &flow_err))
17791 : 0 : return -rte_mtr_error_set(error,
17792 : : ENOTSUP,
17793 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17794 : : NULL, "cannot convert policy "
17795 : : "set tag action");
17796 [ # # ]: 0 : if (!mhdr_res->actions_num)
17797 : 0 : return -rte_mtr_error_set(error,
17798 : : ENOTSUP,
17799 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17800 : : NULL, "cannot find policy "
17801 : : "set tag action");
17802 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
17803 : 0 : break;
17804 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
17805 : : {
17806 : 0 : struct mlx5_flow_mtr_mng *mtrmng =
17807 : 0 : priv->sh->mtrmng;
17808 : : struct mlx5_flow_tbl_data_entry *tbl_data;
17809 : :
17810 : : /*
17811 : : * Create the drop table with
17812 : : * METER DROP level.
17813 : : */
17814 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
17815 : 0 : mtrmng->drop_tbl[domain] =
17816 : 0 : mlx5_flow_dv_tbl_resource_get(dev,
17817 : : MLX5_FLOW_TABLE_LEVEL_METER,
17818 : : egress, transfer, false,
17819 : : NULL, 0,
17820 : : 0, MLX5_MTR_TABLE_ID_DROP,
17821 : : &flow_err);
17822 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain])
17823 : 0 : return -rte_mtr_error_set
17824 : : (error, ENOTSUP,
17825 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17826 : : NULL,
17827 : : "Failed to create meter drop table");
17828 : : }
17829 : 0 : tbl_data = container_of
17830 : : (mtrmng->drop_tbl[domain],
17831 : : struct mlx5_flow_tbl_data_entry, tbl);
17832 [ # # ]: 0 : if (i < MLX5_MTR_RTE_COLORS) {
17833 : 0 : act_cnt->dr_jump_action[domain] =
17834 : 0 : tbl_data->jump.action;
17835 : 0 : act_cnt->fate_action =
17836 : : MLX5_FLOW_FATE_DROP;
17837 : : }
17838 [ # # ]: 0 : if (i == RTE_COLOR_RED)
17839 : 0 : mtr_policy->dr_drop_action[domain] =
17840 : 0 : tbl_data->jump.action;
17841 : 0 : action_flags |= MLX5_FLOW_ACTION_DROP;
17842 : 0 : break;
17843 : : }
17844 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
17845 : : {
17846 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17847 : 0 : return -rte_mtr_error_set(error,
17848 : : ENOTSUP,
17849 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17850 : : NULL, "cannot create policy "
17851 : : "fate queue for this color");
17852 : 0 : act_cnt->queue =
17853 : : ((const struct rte_flow_action_queue *)
17854 : 0 : (act->conf))->index;
17855 : 0 : act_cnt->fate_action =
17856 : : MLX5_FLOW_FATE_QUEUE;
17857 : 0 : dev_flow.handle->fate_action =
17858 : : MLX5_FLOW_FATE_QUEUE;
17859 : 0 : mtr_policy->is_queue = 1;
17860 : 0 : action_flags |= MLX5_FLOW_ACTION_QUEUE;
17861 : 0 : break;
17862 : : }
17863 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
17864 : : {
17865 : : int rss_size;
17866 : :
17867 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17868 : 0 : return -rte_mtr_error_set(error,
17869 : : ENOTSUP,
17870 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17871 : : NULL,
17872 : : "cannot create policy "
17873 : : "rss action for this color");
17874 : : /*
17875 : : * Save RSS conf into policy struct
17876 : : * for translate stage.
17877 : : */
17878 : 0 : rss_size = (int)rte_flow_conv
17879 : : (RTE_FLOW_CONV_OP_ACTION,
17880 : : NULL, 0, act, &flow_err);
17881 [ # # ]: 0 : if (rss_size <= 0)
17882 : 0 : return -rte_mtr_error_set(error,
17883 : : ENOTSUP,
17884 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17885 : : NULL, "Get the wrong "
17886 : : "rss action struct size");
17887 : 0 : act_cnt->rss = mlx5_malloc(MLX5_MEM_ZERO,
17888 : : rss_size, 0, SOCKET_ID_ANY);
17889 [ # # ]: 0 : if (!act_cnt->rss)
17890 : 0 : return -rte_mtr_error_set(error,
17891 : : ENOTSUP,
17892 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17893 : : NULL,
17894 : : "Fail to malloc rss action memory");
17895 : 0 : ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTION,
17896 : : act_cnt->rss, rss_size,
17897 : : act, &flow_err);
17898 [ # # ]: 0 : if (ret < 0)
17899 : 0 : return -rte_mtr_error_set(error,
17900 : : ENOTSUP,
17901 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17902 : : NULL, "Fail to save "
17903 : : "rss action into policy struct");
17904 : 0 : act_cnt->fate_action =
17905 : : MLX5_FLOW_FATE_SHARED_RSS;
17906 : 0 : action_flags |= MLX5_FLOW_ACTION_RSS;
17907 : 0 : break;
17908 : : }
17909 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
17910 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
17911 : : {
17912 : : struct mlx5_flow_dv_port_id_action_resource
17913 : : port_id_resource;
17914 : 0 : uint32_t port_id = 0;
17915 : :
17916 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17917 : 0 : return -rte_mtr_error_set(error,
17918 : : ENOTSUP,
17919 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17920 : : NULL, "cannot create policy "
17921 : : "port action for this color");
17922 : : memset(&port_id_resource, 0,
17923 : : sizeof(port_id_resource));
17924 [ # # ]: 0 : if (flow_dv_translate_action_port_id(dev, act,
17925 : : &port_id, &flow_err))
17926 : 0 : return -rte_mtr_error_set(error,
17927 : : ENOTSUP,
17928 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17929 : : NULL, "cannot translate "
17930 : : "policy port action");
17931 : 0 : port_id_resource.port_id = port_id;
17932 [ # # ]: 0 : if (flow_dv_port_id_action_resource_register
17933 : : (dev, &port_id_resource,
17934 : : &dev_flow, &flow_err))
17935 : 0 : return -rte_mtr_error_set(error,
17936 : : ENOTSUP,
17937 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17938 : : NULL, "cannot setup "
17939 : : "policy port action");
17940 : 0 : act_cnt->rix_port_id_action =
17941 : 0 : dev_flow.handle->rix_port_id_action;
17942 : 0 : act_cnt->fate_action =
17943 : : MLX5_FLOW_FATE_PORT_ID;
17944 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_ID;
17945 : 0 : break;
17946 : : }
17947 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
17948 : : {
17949 : : uint32_t jump_group = 0;
17950 : 0 : uint32_t table = 0;
17951 : : struct mlx5_flow_tbl_data_entry *tbl_data;
17952 : 0 : struct flow_grp_info grp_info = {
17953 : 0 : .external = !!dev_flow.external,
17954 : : .transfer = !!transfer,
17955 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
17956 : : .std_tbl_fix = 0,
17957 : 0 : .skip_scale = dev_flow.skip_scale &
17958 : : (1 << MLX5_SCALE_FLOW_GROUP_BIT),
17959 : : };
17960 : 0 : struct mlx5_flow_meter_sub_policy *sub_policy =
17961 : 0 : mtr_policy->sub_policys[domain][0];
17962 : :
17963 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17964 : 0 : return -rte_mtr_error_set(error,
17965 : : ENOTSUP,
17966 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17967 : : NULL,
17968 : : "cannot create policy "
17969 : : "jump action for this color");
17970 : 0 : jump_group =
17971 : : ((const struct rte_flow_action_jump *)
17972 : 0 : act->conf)->group;
17973 [ # # ]: 0 : if (mlx5_flow_group_to_table(dev, NULL,
17974 : : jump_group,
17975 : : &table,
17976 : : &grp_info, &flow_err))
17977 : 0 : return -rte_mtr_error_set(error,
17978 : : ENOTSUP,
17979 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17980 : : NULL, "cannot setup "
17981 : : "policy jump action");
17982 : 0 : sub_policy->jump_tbl[i] =
17983 : 0 : mlx5_flow_dv_tbl_resource_get(dev,
17984 : : table, egress,
17985 : : transfer, !!dev_flow.external,
17986 : : NULL, jump_group, 0,
17987 : : 0, &flow_err);
17988 : : if
17989 [ # # ]: 0 : (!sub_policy->jump_tbl[i])
17990 : 0 : return -rte_mtr_error_set(error,
17991 : : ENOTSUP,
17992 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17993 : : NULL, "cannot create jump action.");
17994 : 0 : tbl_data = container_of
17995 : : (sub_policy->jump_tbl[i],
17996 : : struct mlx5_flow_tbl_data_entry, tbl);
17997 : 0 : act_cnt->dr_jump_action[domain] =
17998 : 0 : tbl_data->jump.action;
17999 : 0 : act_cnt->fate_action =
18000 : : MLX5_FLOW_FATE_JUMP;
18001 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP;
18002 : 0 : break;
18003 : : }
18004 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
18005 : : {
18006 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
18007 : 0 : return -rte_mtr_error_set(error,
18008 : : ENOTSUP,
18009 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
18010 : : NULL,
18011 : : "cannot create policy modify field for this color");
18012 [ # # ]: 0 : if (flow_dv_convert_action_modify_field
18013 : : (dev, mhdr_res, act, attr, &flow_err))
18014 : 0 : return -rte_mtr_error_set(error,
18015 : : ENOTSUP,
18016 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
18017 : : NULL, "cannot setup policy modify field action");
18018 [ # # ]: 0 : if (!mhdr_res->actions_num)
18019 : 0 : return -rte_mtr_error_set(error,
18020 : : ENOTSUP,
18021 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
18022 : : NULL, "cannot find policy modify field action");
18023 : 0 : action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
18024 : 0 : break;
18025 : : }
18026 : : /*
18027 : : * No need to check meter hierarchy for R colors
18028 : : * here since it is done in the validation stage.
18029 : : */
18030 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
18031 : : {
18032 : : const struct rte_flow_action_meter *mtr;
18033 : : struct mlx5_flow_meter_info *next_fm;
18034 : : struct mlx5_flow_meter_policy *next_policy;
18035 : : struct rte_flow_action tag_action;
18036 : : struct mlx5_rte_flow_action_set_tag set_tag;
18037 : 0 : uint32_t next_mtr_idx = 0;
18038 : :
18039 : 0 : mtr = act->conf;
18040 : 0 : next_fm = mlx5_flow_meter_find(priv,
18041 : 0 : mtr->mtr_id,
18042 : : &next_mtr_idx);
18043 [ # # ]: 0 : if (!next_fm)
18044 : 0 : return -rte_mtr_error_set(error, EINVAL,
18045 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
18046 : : "Fail to find next meter.");
18047 [ # # ]: 0 : if (next_fm->def_policy)
18048 : 0 : return -rte_mtr_error_set(error, EINVAL,
18049 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
18050 : : "Hierarchy only supports termination meter.");
18051 : 0 : next_policy = mlx5_flow_meter_policy_find(dev,
18052 : : next_fm->policy_id, NULL);
18053 : : MLX5_ASSERT(next_policy);
18054 [ # # ]: 0 : if (next_fm->drop_cnt) {
18055 : 0 : set_tag.id =
18056 : 0 : (enum modify_reg)
18057 : 0 : mlx5_flow_get_reg_id(dev,
18058 : : MLX5_MTR_ID,
18059 : : 0,
18060 : : (struct rte_flow_error *)error);
18061 : 0 : set_tag.offset = (priv->mtr_reg_share ?
18062 : 0 : MLX5_MTR_COLOR_BITS : 0);
18063 [ # # ]: 0 : set_tag.length = (priv->mtr_reg_share ?
18064 : : MLX5_MTR_IDLE_BITS_IN_COLOR_REG :
18065 : : MLX5_REG_BITS);
18066 : 0 : set_tag.data = next_mtr_idx;
18067 : 0 : tag_action.type =
18068 : : (enum rte_flow_action_type)
18069 : : MLX5_RTE_FLOW_ACTION_TYPE_TAG;
18070 : 0 : tag_action.conf = &set_tag;
18071 [ # # ]: 0 : if (flow_dv_convert_action_set_reg
18072 : : (mhdr_res, &tag_action,
18073 : : (struct rte_flow_error *)error))
18074 : 0 : return -rte_errno;
18075 : 0 : action_flags |=
18076 : : MLX5_FLOW_ACTION_SET_TAG;
18077 : : }
18078 [ # # # # ]: 0 : if (i == RTE_COLOR_YELLOW && next_fm->color_aware &&
18079 [ # # ]: 0 : !next_fm->meter_action_y)
18080 [ # # ]: 0 : if (__flow_dv_create_mtr_yellow_action(dev, next_fm, error))
18081 : 0 : return -rte_errno;
18082 : 0 : act_cnt->fate_action = MLX5_FLOW_FATE_MTR;
18083 : 0 : act_cnt->next_mtr_id = next_fm->meter_id;
18084 : 0 : act_cnt->next_sub_policy = NULL;
18085 : 0 : mtr_policy->is_hierarchy = 1;
18086 [ # # ]: 0 : if (next_policy->mark)
18087 : 0 : mtr_policy->mark = 1;
18088 : 0 : mtr_policy->hierarchy_match_port =
18089 : 0 : next_policy->hierarchy_match_port;
18090 : 0 : action_flags |=
18091 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
18092 : 0 : break;
18093 : : }
18094 : : default:
18095 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
18096 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
18097 : : NULL, "action type not supported");
18098 : : }
18099 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_SET_TAG) ||
18100 : : (action_flags & MLX5_FLOW_ACTION_MODIFY_FIELD)) {
18101 : : /* create modify action if needed. */
18102 : 0 : dev_flow.dv.group = 1;
18103 [ # # ]: 0 : if (flow_dv_modify_hdr_resource_register
18104 : : (dev, mhdr_res, &dev_flow, &flow_err))
18105 : 0 : return -rte_mtr_error_set(error,
18106 : : ENOTSUP,
18107 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
18108 : : NULL, "cannot register policy set tag/modify field action");
18109 : 0 : act_cnt->modify_hdr =
18110 : 0 : dev_flow.handle->dvh.modify_hdr;
18111 : : }
18112 : : }
18113 : : }
18114 : : return 0;
18115 : : }
18116 : :
18117 : : /**
18118 : : * Create policy action per domain, lock free,
18119 : : * (mutex should be acquired by caller).
18120 : : * Dispatcher for action type specific call.
18121 : : *
18122 : : * @param[in] dev
18123 : : * Pointer to the Ethernet device structure.
18124 : : * @param[in] mtr_policy
18125 : : * Meter policy struct.
18126 : : * @param[in] action
18127 : : * Action specification used to create meter actions.
18128 : : * @param[in] attr
18129 : : * Pointer to the flow attributes.
18130 : : * @param[out] error
18131 : : * Perform verbose error reporting if not NULL. Initialized in case of
18132 : : * error only.
18133 : : *
18134 : : * @return
18135 : : * 0 on success, otherwise negative errno value.
18136 : : */
18137 : : static int
18138 : 0 : flow_dv_create_mtr_policy_acts(struct rte_eth_dev *dev,
18139 : : struct mlx5_flow_meter_policy *mtr_policy,
18140 : : const struct rte_flow_action *actions[RTE_COLORS],
18141 : : struct rte_flow_attr *attr,
18142 : : struct rte_mtr_error *error)
18143 : : {
18144 : : int ret, i;
18145 : : uint16_t sub_policy_num;
18146 : :
18147 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
18148 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
18149 : 0 : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
18150 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
18151 [ # # ]: 0 : if (sub_policy_num) {
18152 : 0 : ret = __flow_dv_create_domain_policy_acts(dev,
18153 : : mtr_policy, actions, attr,
18154 : : (enum mlx5_meter_domain)i, error);
18155 : : /* Cleaning resource is done in the caller level. */
18156 [ # # ]: 0 : if (ret)
18157 : 0 : return ret;
18158 : : }
18159 : : }
18160 : : return 0;
18161 : : }
18162 : :
18163 : : /**
18164 : : * Query a DV flow rule for its statistics via DevX.
18165 : : *
18166 : : * @param[in] dev
18167 : : * Pointer to Ethernet device.
18168 : : * @param[in] cnt_idx
18169 : : * Index to the flow counter.
18170 : : * @param[out] data
18171 : : * Data retrieved by the query.
18172 : : * @param[out] error
18173 : : * Perform verbose error reporting if not NULL.
18174 : : *
18175 : : * @return
18176 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
18177 : : */
18178 : : static int
18179 : 0 : flow_dv_query_count(struct rte_eth_dev *dev, uint32_t cnt_idx, void *data,
18180 : : struct rte_flow_error *error)
18181 : : {
18182 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18183 : : struct rte_flow_query_count *qc = data;
18184 : :
18185 [ # # ]: 0 : if (!priv->sh->cdev->config.devx)
18186 : 0 : return rte_flow_error_set(error, ENOTSUP,
18187 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18188 : : NULL,
18189 : : "counters are not supported");
18190 [ # # ]: 0 : if (cnt_idx) {
18191 : : uint64_t pkts, bytes;
18192 : : struct mlx5_flow_counter *cnt;
18193 : 0 : int err = _flow_dv_query_count(dev, cnt_idx, &pkts, &bytes);
18194 : :
18195 [ # # ]: 0 : if (err)
18196 : 0 : return rte_flow_error_set(error, -err,
18197 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18198 : : NULL, "cannot read counters");
18199 : : cnt = flow_dv_counter_get_by_idx(dev, cnt_idx, NULL);
18200 : 0 : qc->hits_set = 1;
18201 : 0 : qc->bytes_set = 1;
18202 : 0 : qc->hits = pkts - cnt->hits;
18203 : 0 : qc->bytes = bytes - cnt->bytes;
18204 [ # # ]: 0 : if (qc->reset) {
18205 : 0 : cnt->hits = pkts;
18206 : 0 : cnt->bytes = bytes;
18207 : : }
18208 : 0 : return 0;
18209 : : }
18210 : 0 : return rte_flow_error_set(error, EINVAL,
18211 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18212 : : NULL,
18213 : : "counters are not available");
18214 : : }
18215 : :
18216 : : int
18217 : 0 : mlx5_flow_dv_action_query(struct rte_eth_dev *dev,
18218 : : const struct rte_flow_action_handle *handle, void *data,
18219 : : struct rte_flow_error *error)
18220 : : {
18221 : : struct mlx5_age_param *age_param;
18222 : : struct rte_flow_query_age *resp;
18223 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
18224 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
18225 : 0 : uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
18226 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18227 : : struct mlx5_aso_ct_action *ct;
18228 : : uint16_t owner;
18229 : : uint32_t dev_idx;
18230 : :
18231 [ # # # # ]: 0 : switch (type) {
18232 : 0 : case MLX5_INDIRECT_ACTION_TYPE_AGE:
18233 : 0 : age_param = &mlx5_flow_aso_age_get_by_idx(dev, idx)->age_params;
18234 : : resp = data;
18235 : 0 : resp->aged = rte_atomic_load_explicit(&age_param->state,
18236 : : rte_memory_order_relaxed) == AGE_TMOUT ?
18237 : 0 : 1 : 0;
18238 : 0 : resp->sec_since_last_hit_valid = !resp->aged;
18239 [ # # ]: 0 : if (resp->sec_since_last_hit_valid)
18240 : 0 : resp->sec_since_last_hit = rte_atomic_load_explicit
18241 : : (&age_param->sec_since_last_hit, rte_memory_order_relaxed);
18242 : : return 0;
18243 : 0 : case MLX5_INDIRECT_ACTION_TYPE_COUNT:
18244 : 0 : return flow_dv_query_count(dev, idx, data, error);
18245 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
18246 : 0 : owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(idx);
18247 [ # # ]: 0 : if (owner != PORT_ID(priv))
18248 : 0 : return rte_flow_error_set(error, EACCES,
18249 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18250 : : NULL,
18251 : : "CT object owned by another port");
18252 : 0 : dev_idx = MLX5_INDIRECT_ACT_CT_GET_IDX(idx);
18253 : 0 : ct = flow_aso_ct_get_by_dev_idx(dev, dev_idx);
18254 : : MLX5_ASSERT(ct);
18255 [ # # ]: 0 : if (!ct->refcnt)
18256 : 0 : return rte_flow_error_set(error, EFAULT,
18257 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18258 : : NULL,
18259 : : "CT object is inactive");
18260 : 0 : ((struct rte_flow_action_conntrack *)data)->peer_port =
18261 : 0 : ct->peer;
18262 : 0 : ((struct rte_flow_action_conntrack *)data)->is_original_dir =
18263 : 0 : ct->is_original;
18264 [ # # ]: 0 : if (mlx5_aso_ct_query_by_wqe(priv->sh, MLX5_HW_INV_QUEUE, ct,
18265 : : data, NULL, true))
18266 : 0 : return rte_flow_error_set(error, EIO,
18267 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18268 : : NULL,
18269 : : "Failed to query CT context");
18270 : : return 0;
18271 : 0 : default:
18272 : 0 : return rte_flow_error_set(error, ENOTSUP,
18273 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
18274 : : "action type query not supported");
18275 : : }
18276 : : }
18277 : :
18278 : : /**
18279 : : * Query a flow rule AGE action for aging information.
18280 : : *
18281 : : * @param[in] dev
18282 : : * Pointer to Ethernet device.
18283 : : * @param[in] flow
18284 : : * Pointer to the sub flow.
18285 : : * @param[out] data
18286 : : * data retrieved by the query.
18287 : : * @param[out] error
18288 : : * Perform verbose error reporting if not NULL.
18289 : : *
18290 : : * @return
18291 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
18292 : : */
18293 : : static int
18294 : 0 : flow_dv_query_age(struct rte_eth_dev *dev, struct rte_flow *flow,
18295 : : void *data, struct rte_flow_error *error)
18296 : : {
18297 : : struct rte_flow_query_age *resp = data;
18298 : : struct mlx5_age_param *age_param;
18299 : :
18300 [ # # ]: 0 : if (flow->age) {
18301 : : struct mlx5_aso_age_action *act =
18302 : 0 : mlx5_flow_aso_age_get_by_idx(dev, flow->age);
18303 : :
18304 : 0 : age_param = &act->age_params;
18305 [ # # ]: 0 : } else if (flow->counter) {
18306 : : age_param = flow_dv_counter_idx_get_age(dev, flow->counter);
18307 : :
18308 [ # # ]: 0 : if (!age_param || !age_param->timeout)
18309 : 0 : return rte_flow_error_set
18310 : : (error, EINVAL,
18311 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18312 : : NULL, "cannot read age data");
18313 : : } else {
18314 : 0 : return rte_flow_error_set(error, EINVAL,
18315 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18316 : : NULL, "age data not available");
18317 : : }
18318 : 0 : resp->aged = rte_atomic_load_explicit(&age_param->state, rte_memory_order_relaxed) ==
18319 : 0 : AGE_TMOUT ? 1 : 0;
18320 : 0 : resp->sec_since_last_hit_valid = !resp->aged;
18321 [ # # ]: 0 : if (resp->sec_since_last_hit_valid)
18322 : 0 : resp->sec_since_last_hit = rte_atomic_load_explicit
18323 : : (&age_param->sec_since_last_hit, rte_memory_order_relaxed);
18324 : : return 0;
18325 : : }
18326 : :
18327 : : /**
18328 : : * Query a flow.
18329 : : *
18330 : : * @see rte_flow_query()
18331 : : * @see rte_flow_ops
18332 : : */
18333 : : static int
18334 : 0 : flow_dv_query(struct rte_eth_dev *dev,
18335 : : struct rte_flow *flow __rte_unused,
18336 : : const struct rte_flow_action *actions __rte_unused,
18337 : : void *data __rte_unused,
18338 : : struct rte_flow_error *error __rte_unused)
18339 : : {
18340 : : int ret = -EINVAL;
18341 : :
18342 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
18343 [ # # # # ]: 0 : switch (actions->type) {
18344 : : case RTE_FLOW_ACTION_TYPE_VOID:
18345 : : break;
18346 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
18347 : 0 : ret = flow_dv_query_count(dev, flow->counter, data,
18348 : : error);
18349 : 0 : break;
18350 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
18351 [ # # ]: 0 : if (flow->indirect_type == MLX5_INDIRECT_ACTION_TYPE_CT)
18352 : 0 : return rte_flow_error_set(error, ENOTSUP,
18353 : : RTE_FLOW_ERROR_TYPE_ACTION,
18354 : : actions,
18355 : : "age not available");
18356 : 0 : ret = flow_dv_query_age(dev, flow, data, error);
18357 : 0 : break;
18358 : 0 : default:
18359 : 0 : return rte_flow_error_set(error, ENOTSUP,
18360 : : RTE_FLOW_ERROR_TYPE_ACTION,
18361 : : actions,
18362 : : "action not supported");
18363 : : }
18364 : : }
18365 : : return ret;
18366 : : }
18367 : :
18368 : : /**
18369 : : * Destroy the meter table set.
18370 : : * Lock free, (mutex should be acquired by caller).
18371 : : *
18372 : : * @param[in] dev
18373 : : * Pointer to Ethernet device.
18374 : : * @param[in] fm
18375 : : * Meter information table.
18376 : : */
18377 : : static void
18378 : 0 : flow_dv_destroy_mtr_tbls(struct rte_eth_dev *dev,
18379 : : struct mlx5_flow_meter_info *fm)
18380 : : {
18381 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18382 : : int i;
18383 : :
18384 [ # # # # ]: 0 : if (!fm || !priv->sh->config.dv_flow_en)
18385 : : return;
18386 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
18387 [ # # ]: 0 : if (fm->drop_rule[i]) {
18388 : : claim_zero(mlx5_flow_os_destroy_flow(fm->drop_rule[i]));
18389 : 0 : fm->drop_rule[i] = NULL;
18390 : : }
18391 : : }
18392 : : }
18393 : :
18394 : : static void
18395 : 0 : flow_dv_destroy_mtr_drop_tbls(struct rte_eth_dev *dev)
18396 : : {
18397 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18398 : 0 : struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
18399 : : struct mlx5_flow_tbl_data_entry *tbl;
18400 : : int i, j;
18401 : :
18402 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
18403 [ # # ]: 0 : if (mtrmng->def_rule[i]) {
18404 : : claim_zero(mlx5_flow_os_destroy_flow
18405 : : (mtrmng->def_rule[i]));
18406 : 0 : mtrmng->def_rule[i] = NULL;
18407 : : }
18408 [ # # ]: 0 : if (mtrmng->def_matcher[i]) {
18409 : 0 : tbl = container_of(mtrmng->def_matcher[i]->tbl,
18410 : : struct mlx5_flow_tbl_data_entry, tbl);
18411 : 0 : mlx5_list_unregister(tbl->matchers,
18412 : : &mtrmng->def_matcher[i]->entry);
18413 : 0 : mtrmng->def_matcher[i] = NULL;
18414 : : }
18415 [ # # ]: 0 : for (j = 0; j < MLX5_REG_BITS; j++) {
18416 [ # # ]: 0 : if (mtrmng->drop_matcher[i][j]) {
18417 : : tbl =
18418 : 0 : container_of(mtrmng->drop_matcher[i][j]->tbl,
18419 : : struct mlx5_flow_tbl_data_entry,
18420 : : tbl);
18421 : 0 : mlx5_list_unregister(tbl->matchers,
18422 : : &mtrmng->drop_matcher[i][j]->entry);
18423 : 0 : mtrmng->drop_matcher[i][j] = NULL;
18424 : : }
18425 : : }
18426 [ # # ]: 0 : if (mtrmng->drop_tbl[i]) {
18427 : 0 : mlx5_flow_dv_tbl_resource_release(MLX5_SH(dev), mtrmng->drop_tbl[i]);
18428 : 0 : mtrmng->drop_tbl[i] = NULL;
18429 : : }
18430 : : }
18431 : 0 : }
18432 : :
18433 : : /* Number of meter flow actions, count and jump or count and drop. */
18434 : : #define METER_ACTIONS 2
18435 : :
18436 : : static void
18437 : 0 : __flow_dv_destroy_domain_def_policy(struct rte_eth_dev *dev,
18438 : : enum mlx5_meter_domain domain)
18439 : : {
18440 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18441 : 0 : struct mlx5_flow_meter_def_policy *def_policy =
18442 : 0 : priv->sh->mtrmng->def_policy[domain];
18443 : :
18444 : 0 : __flow_dv_destroy_sub_policy_rules(dev, &def_policy->sub_policy);
18445 : 0 : mlx5_free(def_policy);
18446 : 0 : priv->sh->mtrmng->def_policy[domain] = NULL;
18447 : 0 : }
18448 : :
18449 : : /**
18450 : : * Destroy the default policy table set.
18451 : : *
18452 : : * @param[in] dev
18453 : : * Pointer to Ethernet device.
18454 : : */
18455 : : static void
18456 : 0 : flow_dv_destroy_def_policy(struct rte_eth_dev *dev)
18457 : : {
18458 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18459 : : int i;
18460 : :
18461 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++)
18462 [ # # ]: 0 : if (priv->sh->mtrmng->def_policy[i])
18463 : 0 : __flow_dv_destroy_domain_def_policy(dev,
18464 : : (enum mlx5_meter_domain)i);
18465 : 0 : priv->sh->mtrmng->def_policy_id = MLX5_INVALID_POLICY_ID;
18466 : 0 : }
18467 : :
18468 : : static int
18469 : 0 : __flow_dv_create_policy_flow(struct rte_eth_dev *dev,
18470 : : uint32_t color_reg_c_idx,
18471 : : enum rte_color color, struct mlx5_flow_dv_matcher *matcher,
18472 : : int actions_n, void *actions,
18473 : : bool match_src_port, const struct rte_flow_item *item,
18474 : : void **rule, const struct rte_flow_attr *attr)
18475 : : {
18476 : : int ret;
18477 : 0 : struct mlx5_flow_dv_match_params value = {
18478 : : .size = sizeof(value.buf),
18479 : : };
18480 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18481 : : uint8_t misc_mask;
18482 : :
18483 [ # # # # ]: 0 : if (match_src_port && priv->sh->esw_mode) {
18484 [ # # # # ]: 0 : if (item && item->type == RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT)
18485 : 0 : ret = flow_dv_translate_item_represented_port(dev, value.buf,
18486 : : item, attr, MLX5_SET_MATCHER_SW_V);
18487 [ # # # # ]: 0 : else if (item && item->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR)
18488 : 0 : ret = flow_dv_translate_item_port_representor(dev, value.buf,
18489 : : MLX5_SET_MATCHER_SW_V);
18490 : : else
18491 : 0 : ret = flow_dv_translate_item_port_id(dev, value.buf,
18492 : : item, attr, MLX5_SET_MATCHER_SW_V);
18493 [ # # ]: 0 : if (ret) {
18494 : 0 : DRV_LOG(ERR, "Failed to create meter policy%d flow's"
18495 : : " value with port.", color);
18496 : 0 : return -1;
18497 : : }
18498 : : }
18499 : 0 : flow_dv_match_meta_reg(value.buf, (enum modify_reg)color_reg_c_idx,
18500 : : rte_col_2_mlx5_col(color), UINT32_MAX);
18501 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(matcher->mask.buf);
18502 : : __flow_dv_adjust_buf_size(&value.size, misc_mask);
18503 : 0 : ret = mlx5_flow_os_create_flow(matcher->matcher_object, (void *)&value,
18504 : : actions_n, actions, rule);
18505 : : if (ret) {
18506 : 0 : DRV_LOG(ERR, "Failed to create meter policy%d flow.", color);
18507 : 0 : return -1;
18508 : : }
18509 : : return 0;
18510 : : }
18511 : :
18512 : : static int
18513 : 0 : __flow_dv_create_policy_matcher(struct rte_eth_dev *dev,
18514 : : uint32_t color_reg_c_idx,
18515 : : uint16_t priority,
18516 : : struct mlx5_flow_meter_sub_policy *sub_policy,
18517 : : const struct rte_flow_attr *attr,
18518 : : bool match_src_port,
18519 : : const struct rte_flow_item *item,
18520 : : struct mlx5_flow_dv_matcher **policy_matcher,
18521 : : struct rte_flow_error *error)
18522 : : {
18523 : : struct mlx5_list_entry *entry;
18524 : 0 : struct mlx5_flow_tbl_resource *tbl_rsc = sub_policy->tbl_rsc;
18525 : 0 : struct mlx5_flow_dv_matcher matcher = {
18526 : : .mask = {
18527 : : .size = sizeof(matcher.mask.buf),
18528 : : },
18529 : : .tbl = tbl_rsc,
18530 : : };
18531 : 0 : struct mlx5_flow_cb_ctx ctx = {
18532 : : .error = error,
18533 : : .data = &matcher,
18534 : : };
18535 : : struct mlx5_flow_tbl_data_entry *tbl_data;
18536 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18537 : : const uint32_t color_mask = (UINT32_C(1) << MLX5_MTR_COLOR_BITS) - 1;
18538 : : int ret;
18539 : :
18540 [ # # # # ]: 0 : if (match_src_port && priv->sh->esw_mode) {
18541 [ # # # # ]: 0 : if (item && item->type == RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT)
18542 : 0 : ret = flow_dv_translate_item_represented_port(dev, matcher.mask.buf,
18543 : : item, attr, MLX5_SET_MATCHER_SW_M);
18544 [ # # # # ]: 0 : else if (item && item->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR)
18545 : 0 : ret = flow_dv_translate_item_port_representor(dev, matcher.mask.buf,
18546 : : MLX5_SET_MATCHER_SW_M);
18547 : : else
18548 : 0 : ret = flow_dv_translate_item_port_id(dev, matcher.mask.buf,
18549 : : item, attr, MLX5_SET_MATCHER_SW_M);
18550 [ # # ]: 0 : if (ret) {
18551 : 0 : DRV_LOG(ERR, "Failed to register meter policy%d matcher"
18552 : : " with port.", priority);
18553 : 0 : return -1;
18554 : : }
18555 : : }
18556 : 0 : tbl_data = container_of(tbl_rsc, struct mlx5_flow_tbl_data_entry, tbl);
18557 : 0 : flow_dv_match_meta_reg(matcher.mask.buf,
18558 : : (enum modify_reg)color_reg_c_idx, color_mask, color_mask);
18559 : 0 : matcher.priority = priority;
18560 : 0 : matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
18561 : : matcher.mask.size);
18562 : 0 : entry = mlx5_list_register(tbl_data->matchers, &ctx);
18563 [ # # ]: 0 : if (!entry) {
18564 : 0 : DRV_LOG(ERR, "Failed to register meter drop matcher.");
18565 : 0 : return -1;
18566 : : }
18567 : 0 : *policy_matcher =
18568 : : container_of(entry, struct mlx5_flow_dv_matcher, entry);
18569 : 0 : return 0;
18570 : : }
18571 : :
18572 : : /**
18573 : : * Create the policy rules per domain.
18574 : : *
18575 : : * @param[in] dev
18576 : : * Pointer to Ethernet device.
18577 : : * @param[in] sub_policy
18578 : : * Pointer to sub policy table..
18579 : : * @param[in] egress
18580 : : * Direction of the table.
18581 : : * @param[in] transfer
18582 : : * E-Switch or NIC flow.
18583 : : * @param[in] acts
18584 : : * Pointer to policy action list per color.
18585 : : *
18586 : : * @return
18587 : : * 0 on success, -1 otherwise.
18588 : : */
18589 : : static int
18590 : 0 : __flow_dv_create_domain_policy_rules(struct rte_eth_dev *dev,
18591 : : struct mlx5_flow_meter_sub_policy *sub_policy,
18592 : : uint8_t egress, uint8_t transfer, bool *match_src_port,
18593 : : struct mlx5_meter_policy_acts acts[RTE_COLORS])
18594 : : {
18595 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18596 : : struct rte_flow_error flow_err;
18597 : : uint32_t color_reg_c_idx;
18598 : 0 : struct rte_flow_attr attr = {
18599 : : .group = MLX5_FLOW_TABLE_LEVEL_POLICY,
18600 : : .priority = 0,
18601 : : .ingress = 0,
18602 : 0 : .egress = !!egress,
18603 : 0 : .transfer = !!transfer,
18604 : : .reserved = 0,
18605 : : };
18606 : : int i;
18607 : : uint16_t priority;
18608 : 0 : int ret = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &flow_err);
18609 : : struct mlx5_sub_policy_color_rule *color_rule;
18610 : 0 : struct mlx5_sub_policy_color_rule *tmp_rules[RTE_COLORS] = {NULL};
18611 : :
18612 [ # # ]: 0 : if (ret < 0)
18613 : : return -1;
18614 : : /* Create policy table with POLICY level. */
18615 [ # # ]: 0 : if (!sub_policy->tbl_rsc)
18616 : 0 : sub_policy->tbl_rsc = mlx5_flow_dv_tbl_resource_get(dev,
18617 : : MLX5_FLOW_TABLE_LEVEL_POLICY,
18618 : : egress, transfer, false,
18619 : : NULL, 0, 0,
18620 : 0 : sub_policy->idx, &flow_err);
18621 [ # # ]: 0 : if (!sub_policy->tbl_rsc) {
18622 : 0 : DRV_LOG(ERR,
18623 : : "Failed to create meter sub policy table.");
18624 : 0 : return -1;
18625 : : }
18626 : : /* Prepare matchers. */
18627 : 0 : color_reg_c_idx = ret;
18628 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
18629 : 0 : TAILQ_INIT(&sub_policy->color_rules[i]);
18630 [ # # ]: 0 : if (!acts[i].actions_n)
18631 : 0 : continue;
18632 : 0 : color_rule = mlx5_malloc(MLX5_MEM_ZERO,
18633 : : sizeof(struct mlx5_sub_policy_color_rule),
18634 : : 0, SOCKET_ID_ANY);
18635 [ # # ]: 0 : if (!color_rule) {
18636 : 0 : DRV_LOG(ERR, "No memory to create color rule.");
18637 : 0 : goto err_exit;
18638 : : }
18639 : 0 : tmp_rules[i] = color_rule;
18640 : 0 : TAILQ_INSERT_TAIL(&sub_policy->color_rules[i],
18641 : : color_rule, next_port);
18642 : 0 : color_rule->src_port = priv->representor_id;
18643 : 0 : priority = (match_src_port[i] == match_src_port[RTE_COLOR_GREEN]) ?
18644 : 0 : MLX5_MTR_POLICY_MATCHER_PRIO : (MLX5_MTR_POLICY_MATCHER_PRIO + 1);
18645 : : /* Create matchers for colors. */
18646 [ # # ]: 0 : if (__flow_dv_create_policy_matcher(dev, color_reg_c_idx,
18647 : : priority, sub_policy,
18648 : : &attr, match_src_port[i], NULL,
18649 : : &color_rule->matcher, &flow_err)) {
18650 : 0 : DRV_LOG(ERR, "Failed to create color%u matcher.", i);
18651 : 0 : goto err_exit;
18652 : : }
18653 : : /* Create flow, matching color. */
18654 [ # # ]: 0 : if (__flow_dv_create_policy_flow(dev,
18655 : : color_reg_c_idx, (enum rte_color)i,
18656 : : color_rule->matcher,
18657 : 0 : acts[i].actions_n, acts[i].dv_actions,
18658 : 0 : match_src_port[i], NULL, &color_rule->rule,
18659 : : &attr)) {
18660 : 0 : DRV_LOG(ERR, "Failed to create color%u rule.", i);
18661 : 0 : goto err_exit;
18662 : : }
18663 : : }
18664 : : return 0;
18665 : : err_exit:
18666 : : /* All the policy rules will be cleared. */
18667 : : do {
18668 : 0 : color_rule = tmp_rules[i];
18669 [ # # ]: 0 : if (color_rule) {
18670 [ # # ]: 0 : if (color_rule->rule)
18671 : : mlx5_flow_os_destroy_flow(color_rule->rule);
18672 [ # # ]: 0 : if (color_rule->matcher) {
18673 : : struct mlx5_flow_tbl_data_entry *tbl =
18674 : 0 : container_of(color_rule->matcher->tbl,
18675 : : typeof(*tbl), tbl);
18676 : 0 : mlx5_list_unregister(tbl->matchers,
18677 : : &color_rule->matcher->entry);
18678 : : }
18679 [ # # ]: 0 : TAILQ_REMOVE(&sub_policy->color_rules[i],
18680 : : color_rule, next_port);
18681 : 0 : mlx5_free(color_rule);
18682 : : }
18683 [ # # ]: 0 : } while (i--);
18684 : : return -1;
18685 : : }
18686 : :
18687 : : static int
18688 : 0 : __flow_dv_create_policy_acts_rules(struct rte_eth_dev *dev,
18689 : : struct mlx5_flow_meter_policy *mtr_policy,
18690 : : struct mlx5_flow_meter_sub_policy *sub_policy,
18691 : : uint32_t domain)
18692 : : {
18693 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18694 : : struct mlx5_meter_policy_acts acts[RTE_COLORS];
18695 : : struct mlx5_flow_dv_tag_resource *tag;
18696 : : struct mlx5_flow_dv_port_id_action_resource *port_action;
18697 : : struct mlx5_hrxq *hrxq;
18698 : 0 : struct mlx5_flow_meter_info *next_fm[RTE_COLORS] = {NULL};
18699 : : struct mlx5_flow_meter_policy *next_policy;
18700 : : struct mlx5_flow_meter_sub_policy *next_sub_policy;
18701 : : struct mlx5_flow_tbl_data_entry *tbl_data;
18702 : : struct rte_flow_error error;
18703 : 0 : uint8_t egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
18704 : 0 : uint8_t transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
18705 [ # # # # : 0 : bool mtr_first = egress || (transfer && priv->representor_id != UINT16_MAX);
# # ]
18706 : 0 : bool match_src_port[RTE_COLORS] = {false};
18707 : : int i;
18708 : :
18709 : : /* If RSS or Queue, no previous actions / rules is created. */
18710 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
18711 : 0 : acts[i].actions_n = 0;
18712 [ # # ]: 0 : if (i == RTE_COLOR_RED) {
18713 : : /* Only support drop on red. */
18714 : 0 : acts[i].dv_actions[0] =
18715 : 0 : mtr_policy->dr_drop_action[domain];
18716 : 0 : acts[i].actions_n = 1;
18717 : 0 : continue;
18718 : : }
18719 [ # # ]: 0 : if (mtr_policy->act_cnt[i].fate_action == MLX5_FLOW_FATE_MTR) {
18720 : 0 : struct rte_flow_attr attr = {
18721 : : .transfer = transfer
18722 : : };
18723 : :
18724 : 0 : next_fm[i] = mlx5_flow_meter_find(priv,
18725 : : mtr_policy->act_cnt[i].next_mtr_id,
18726 : : NULL);
18727 [ # # ]: 0 : if (!next_fm[i]) {
18728 : 0 : DRV_LOG(ERR,
18729 : : "Failed to get next hierarchy meter.");
18730 : 0 : goto err_exit;
18731 : : }
18732 [ # # ]: 0 : if (mlx5_flow_meter_attach(priv, next_fm[i],
18733 : : &attr, &error)) {
18734 : 0 : DRV_LOG(ERR, "%s", error.message);
18735 : 0 : next_fm[i] = NULL;
18736 : 0 : goto err_exit;
18737 : : }
18738 : : /* Meter action must be the first for TX. */
18739 [ # # ]: 0 : if (mtr_first) {
18740 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18741 [ # # ]: 0 : (next_fm[i]->color_aware && i == RTE_COLOR_YELLOW) ?
18742 [ # # ]: 0 : next_fm[i]->meter_action_y :
18743 : : next_fm[i]->meter_action_g;
18744 : 0 : acts[i].actions_n++;
18745 : : }
18746 : : }
18747 [ # # ]: 0 : if (mtr_policy->act_cnt[i].rix_mark) {
18748 : 0 : tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG],
18749 : : mtr_policy->act_cnt[i].rix_mark);
18750 [ # # ]: 0 : if (!tag) {
18751 : 0 : DRV_LOG(ERR, "Failed to find "
18752 : : "mark action for policy.");
18753 : 0 : goto err_exit;
18754 : : }
18755 : 0 : acts[i].dv_actions[acts[i].actions_n] = tag->action;
18756 : 0 : acts[i].actions_n++;
18757 : : }
18758 [ # # ]: 0 : if (mtr_policy->act_cnt[i].modify_hdr) {
18759 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18760 : 0 : mtr_policy->act_cnt[i].modify_hdr->action;
18761 : 0 : acts[i].actions_n++;
18762 : : }
18763 [ # # ]: 0 : if (mtr_policy->act_cnt[i].fate_action) {
18764 [ # # # # : 0 : switch (mtr_policy->act_cnt[i].fate_action) {
# ]
18765 : 0 : case MLX5_FLOW_FATE_PORT_ID:
18766 : 0 : port_action = mlx5_ipool_get
18767 : 0 : (priv->sh->ipool[MLX5_IPOOL_PORT_ID],
18768 : : mtr_policy->act_cnt[i].rix_port_id_action);
18769 [ # # ]: 0 : if (!port_action) {
18770 : 0 : DRV_LOG(ERR, "Failed to find "
18771 : : "port action for policy.");
18772 : 0 : goto err_exit;
18773 : : }
18774 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18775 : 0 : port_action->action;
18776 : 0 : acts[i].actions_n++;
18777 : 0 : match_src_port[i] = true;
18778 : 0 : break;
18779 : 0 : case MLX5_FLOW_FATE_DROP:
18780 : : case MLX5_FLOW_FATE_JUMP:
18781 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18782 : 0 : mtr_policy->act_cnt[i].dr_jump_action[domain];
18783 : 0 : acts[i].actions_n++;
18784 : 0 : break;
18785 : 0 : case MLX5_FLOW_FATE_SHARED_RSS:
18786 : : case MLX5_FLOW_FATE_QUEUE:
18787 : 0 : hrxq = mlx5_ipool_get
18788 : 0 : (priv->sh->ipool[MLX5_IPOOL_HRXQ],
18789 : : sub_policy->rix_hrxq[i]);
18790 [ # # ]: 0 : if (!hrxq) {
18791 : 0 : DRV_LOG(ERR, "Failed to find "
18792 : : "queue action for policy.");
18793 : 0 : goto err_exit;
18794 : : }
18795 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18796 : 0 : hrxq->action;
18797 : 0 : acts[i].actions_n++;
18798 : 0 : break;
18799 : 0 : case MLX5_FLOW_FATE_MTR:
18800 [ # # ]: 0 : if (!next_fm[i]) {
18801 : 0 : DRV_LOG(ERR,
18802 : : "No next hierarchy meter.");
18803 : 0 : goto err_exit;
18804 : : }
18805 [ # # ]: 0 : if (!mtr_first) {
18806 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18807 [ # # ]: 0 : (next_fm[i]->color_aware && i == RTE_COLOR_YELLOW) ?
18808 [ # # ]: 0 : next_fm[i]->meter_action_y :
18809 : : next_fm[i]->meter_action_g;
18810 : 0 : acts[i].actions_n++;
18811 : : }
18812 [ # # ]: 0 : if (mtr_policy->act_cnt[i].next_sub_policy) {
18813 : : next_sub_policy =
18814 : : mtr_policy->act_cnt[i].next_sub_policy;
18815 : : } else {
18816 : : next_policy =
18817 : 0 : mlx5_flow_meter_policy_find(dev,
18818 : : next_fm[i]->policy_id, NULL);
18819 : : MLX5_ASSERT(next_policy);
18820 : 0 : next_sub_policy =
18821 : 0 : next_policy->sub_policys[domain][0];
18822 : : }
18823 : : tbl_data =
18824 : 0 : container_of(next_sub_policy->tbl_rsc,
18825 : : struct mlx5_flow_tbl_data_entry, tbl);
18826 : 0 : acts[i].dv_actions[acts[i].actions_n++] =
18827 : 0 : tbl_data->jump.action;
18828 [ # # ]: 0 : if (mtr_policy->act_cnt[i].modify_hdr)
18829 : 0 : match_src_port[i] = !!transfer;
18830 : : break;
18831 : : default:
18832 : : /*Queue action do nothing*/
18833 : : break;
18834 : : }
18835 : : }
18836 : : }
18837 [ # # ]: 0 : if (__flow_dv_create_domain_policy_rules(dev, sub_policy,
18838 : : egress, transfer, match_src_port, acts)) {
18839 : 0 : DRV_LOG(ERR,
18840 : : "Failed to create policy rules per domain.");
18841 : 0 : goto err_exit;
18842 : : }
18843 [ # # # # ]: 0 : if (match_src_port[RTE_COLOR_GREEN] || match_src_port[RTE_COLOR_YELLOW]) {
18844 : 0 : mtr_policy->match_port = 1;
18845 : 0 : mtr_policy->hierarchy_match_port = 1;
18846 : : }
18847 : : return 0;
18848 : : err_exit:
18849 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++)
18850 [ # # ]: 0 : if (next_fm[i])
18851 : 0 : mlx5_flow_meter_detach(priv, next_fm[i]);
18852 : : return -1;
18853 : : }
18854 : :
18855 : : /**
18856 : : * Create the policy rules.
18857 : : *
18858 : : * @param[in] dev
18859 : : * Pointer to Ethernet device.
18860 : : * @param[in,out] mtr_policy
18861 : : * Pointer to meter policy table.
18862 : : *
18863 : : * @return
18864 : : * 0 on success, -1 otherwise.
18865 : : */
18866 : : static int
18867 : 0 : flow_dv_create_policy_rules(struct rte_eth_dev *dev,
18868 : : struct mlx5_flow_meter_policy *mtr_policy)
18869 : : {
18870 : : int i;
18871 : : int ret = 0;
18872 : : uint16_t sub_policy_num;
18873 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_push_thread_workspace();
18874 : :
18875 : : RTE_SET_USED(wks);
18876 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
18877 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
18878 : 0 : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
18879 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
18880 [ # # ]: 0 : if (!sub_policy_num)
18881 : 0 : continue;
18882 : : /* Prepare actions list and create policy rules. */
18883 [ # # ]: 0 : if (__flow_dv_create_policy_acts_rules(dev, mtr_policy,
18884 : 0 : mtr_policy->sub_policys[i][0], i)) {
18885 : 0 : DRV_LOG(ERR, "Failed to create policy action "
18886 : : "list per domain.");
18887 : : ret = -1;
18888 : 0 : goto exit;
18889 : : }
18890 : : }
18891 : 0 : exit:
18892 : 0 : mlx5_flow_pop_thread_workspace();
18893 : 0 : return ret;
18894 : : }
18895 : :
18896 : : static int
18897 : 0 : __flow_dv_create_domain_def_policy(struct rte_eth_dev *dev, uint32_t domain)
18898 : : {
18899 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18900 : 0 : struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
18901 : : struct mlx5_flow_meter_def_policy *def_policy;
18902 : : struct mlx5_flow_tbl_resource *jump_tbl;
18903 : : struct mlx5_flow_tbl_data_entry *tbl_data;
18904 : : uint8_t egress, transfer;
18905 : : struct rte_flow_error error;
18906 : : struct mlx5_meter_policy_acts acts[RTE_COLORS];
18907 : 0 : bool match_src_port[RTE_COLORS] = {false};
18908 : : int ret;
18909 : :
18910 : 0 : egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
18911 : 0 : transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
18912 : 0 : def_policy = mtrmng->def_policy[domain];
18913 [ # # ]: 0 : if (!def_policy) {
18914 : 0 : def_policy = mlx5_malloc(MLX5_MEM_ZERO,
18915 : : sizeof(struct mlx5_flow_meter_def_policy),
18916 : : RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
18917 [ # # ]: 0 : if (!def_policy) {
18918 : 0 : DRV_LOG(ERR, "Failed to alloc default policy table.");
18919 : 0 : goto def_policy_error;
18920 : : }
18921 : 0 : mtrmng->def_policy[domain] = def_policy;
18922 : : /* Create the meter suffix table with SUFFIX level. */
18923 : 0 : jump_tbl = mlx5_flow_dv_tbl_resource_get(dev,
18924 : : MLX5_FLOW_TABLE_LEVEL_METER,
18925 : : egress, transfer, false, NULL, 0,
18926 : : 0, MLX5_MTR_TABLE_ID_SUFFIX, &error);
18927 [ # # ]: 0 : if (!jump_tbl) {
18928 : 0 : DRV_LOG(ERR,
18929 : : "Failed to create meter suffix table.");
18930 : 0 : goto def_policy_error;
18931 : : }
18932 : 0 : def_policy->sub_policy.jump_tbl[RTE_COLOR_GREEN] = jump_tbl;
18933 : 0 : tbl_data = container_of(jump_tbl,
18934 : : struct mlx5_flow_tbl_data_entry, tbl);
18935 : 0 : def_policy->dr_jump_action[RTE_COLOR_GREEN] =
18936 : 0 : tbl_data->jump.action;
18937 : 0 : acts[RTE_COLOR_GREEN].dv_actions[0] = tbl_data->jump.action;
18938 : 0 : acts[RTE_COLOR_GREEN].actions_n = 1;
18939 : : /*
18940 : : * YELLOW has the same default policy as GREEN does.
18941 : : * G & Y share the same table and action. The 2nd time of table
18942 : : * resource getting is just to update the reference count for
18943 : : * the releasing stage.
18944 : : */
18945 : 0 : jump_tbl = mlx5_flow_dv_tbl_resource_get(dev,
18946 : : MLX5_FLOW_TABLE_LEVEL_METER,
18947 : : egress, transfer, false, NULL, 0,
18948 : : 0, MLX5_MTR_TABLE_ID_SUFFIX, &error);
18949 [ # # ]: 0 : if (!jump_tbl) {
18950 : 0 : DRV_LOG(ERR,
18951 : : "Failed to get meter suffix table.");
18952 : 0 : goto def_policy_error;
18953 : : }
18954 : 0 : def_policy->sub_policy.jump_tbl[RTE_COLOR_YELLOW] = jump_tbl;
18955 : 0 : tbl_data = container_of(jump_tbl,
18956 : : struct mlx5_flow_tbl_data_entry, tbl);
18957 : 0 : def_policy->dr_jump_action[RTE_COLOR_YELLOW] =
18958 : 0 : tbl_data->jump.action;
18959 : 0 : acts[RTE_COLOR_YELLOW].dv_actions[0] = tbl_data->jump.action;
18960 : 0 : acts[RTE_COLOR_YELLOW].actions_n = 1;
18961 : : /* Create jump action to the drop table. */
18962 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
18963 : 0 : mtrmng->drop_tbl[domain] = mlx5_flow_dv_tbl_resource_get
18964 : : (dev, MLX5_FLOW_TABLE_LEVEL_METER,
18965 : : egress, transfer, false, NULL, 0,
18966 : : 0, MLX5_MTR_TABLE_ID_DROP, &error);
18967 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
18968 : 0 : DRV_LOG(ERR, "Failed to create meter "
18969 : : "drop table for default policy.");
18970 : 0 : goto def_policy_error;
18971 : : }
18972 : : }
18973 : : /* all RED: unique Drop table for jump action. */
18974 : 0 : tbl_data = container_of(mtrmng->drop_tbl[domain],
18975 : : struct mlx5_flow_tbl_data_entry, tbl);
18976 : 0 : def_policy->dr_jump_action[RTE_COLOR_RED] =
18977 : 0 : tbl_data->jump.action;
18978 : 0 : acts[RTE_COLOR_RED].dv_actions[0] = tbl_data->jump.action;
18979 : 0 : acts[RTE_COLOR_RED].actions_n = 1;
18980 : : /* Create default policy rules. */
18981 : 0 : ret = __flow_dv_create_domain_policy_rules(dev,
18982 : : &def_policy->sub_policy,
18983 : : egress, transfer, match_src_port, acts);
18984 [ # # ]: 0 : if (ret) {
18985 : 0 : DRV_LOG(ERR, "Failed to create default policy rules.");
18986 : 0 : goto def_policy_error;
18987 : : }
18988 : : }
18989 : : return 0;
18990 : 0 : def_policy_error:
18991 : 0 : __flow_dv_destroy_domain_def_policy(dev,
18992 : : (enum mlx5_meter_domain)domain);
18993 : 0 : return -1;
18994 : : }
18995 : :
18996 : : /**
18997 : : * Create the default policy table set.
18998 : : *
18999 : : * @param[in] dev
19000 : : * Pointer to Ethernet device.
19001 : : * @return
19002 : : * 0 on success, -1 otherwise.
19003 : : */
19004 : : static int
19005 : 0 : flow_dv_create_def_policy(struct rte_eth_dev *dev)
19006 : : {
19007 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19008 : : int i;
19009 : :
19010 : : /* Non-termination policy table. */
19011 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
19012 [ # # # # ]: 0 : if (!priv->sh->config.dv_esw_en &&
19013 : : i == MLX5_MTR_DOMAIN_TRANSFER)
19014 : 0 : continue;
19015 [ # # ]: 0 : if (__flow_dv_create_domain_def_policy(dev, i)) {
19016 : 0 : DRV_LOG(ERR, "Failed to create default policy");
19017 : : /* Rollback the created default policies for others. */
19018 : 0 : flow_dv_destroy_def_policy(dev);
19019 : 0 : return -1;
19020 : : }
19021 : : }
19022 : : return 0;
19023 : : }
19024 : :
19025 : : /**
19026 : : * Create the needed meter tables.
19027 : : * Lock free, (mutex should be acquired by caller).
19028 : : *
19029 : : * @param[in] dev
19030 : : * Pointer to Ethernet device.
19031 : : * @param[in] fm
19032 : : * Meter information table.
19033 : : * @param[in] mtr_idx
19034 : : * Meter index.
19035 : : * @param[in] domain_bitmap
19036 : : * Domain bitmap.
19037 : : * @return
19038 : : * 0 on success, -1 otherwise.
19039 : : */
19040 : : static int
19041 : 0 : flow_dv_create_mtr_tbls(struct rte_eth_dev *dev,
19042 : : struct mlx5_flow_meter_info *fm,
19043 : : uint32_t mtr_idx,
19044 : : uint8_t domain_bitmap)
19045 : : {
19046 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19047 : 0 : struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
19048 : : struct rte_flow_error error;
19049 : : struct mlx5_flow_tbl_data_entry *tbl_data;
19050 : : uint8_t egress, transfer;
19051 : : void *actions[METER_ACTIONS];
19052 : : int domain, ret, i;
19053 : : struct mlx5_flow_counter *cnt;
19054 : 0 : struct mlx5_flow_dv_match_params value = {
19055 : : .size = sizeof(value.buf),
19056 : : };
19057 : 0 : struct mlx5_flow_dv_match_params matcher_para = {
19058 : : .size = sizeof(matcher_para.buf),
19059 : : };
19060 : 0 : int mtr_id_reg_c = mlx5_flow_get_reg_id(dev, MLX5_MTR_ID,
19061 : : 0, &error);
19062 : 0 : uint32_t mtr_id_mask = (UINT32_C(1) << mtrmng->max_mtr_bits) - 1;
19063 : 0 : uint8_t mtr_id_offset = priv->mtr_reg_share ? MLX5_MTR_COLOR_BITS : 0;
19064 : : struct mlx5_list_entry *entry;
19065 : 0 : struct mlx5_flow_dv_matcher matcher = {
19066 : : .mask = {
19067 : : .size = sizeof(matcher.mask.buf),
19068 : : },
19069 : : };
19070 : : struct mlx5_flow_dv_matcher *drop_matcher;
19071 : 0 : struct mlx5_flow_cb_ctx ctx = {
19072 : : .error = &error,
19073 : : .data = &matcher,
19074 : : };
19075 : : uint8_t misc_mask;
19076 : :
19077 [ # # # # ]: 0 : if (!priv->mtr_en || mtr_id_reg_c < 0) {
19078 : 0 : rte_errno = ENOTSUP;
19079 : 0 : return -1;
19080 : : }
19081 [ # # ]: 0 : for (domain = 0; domain < MLX5_MTR_DOMAIN_MAX; domain++) {
19082 [ # # ]: 0 : if (!(domain_bitmap & (1 << domain)) ||
19083 [ # # # # ]: 0 : (mtrmng->def_rule[domain] && !fm->drop_cnt))
19084 : 0 : continue;
19085 : 0 : egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
19086 : 0 : transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
19087 : : /* Create the drop table with METER DROP level. */
19088 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
19089 : 0 : mtrmng->drop_tbl[domain] = mlx5_flow_dv_tbl_resource_get(dev,
19090 : : MLX5_FLOW_TABLE_LEVEL_METER,
19091 : : egress, transfer, false, NULL, 0,
19092 : : 0, MLX5_MTR_TABLE_ID_DROP, &error);
19093 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
19094 : 0 : DRV_LOG(ERR, "Failed to create meter drop table.");
19095 : 0 : goto policy_error;
19096 : : }
19097 : : }
19098 : : /* Create default matcher in drop table. */
19099 : 0 : matcher.tbl = mtrmng->drop_tbl[domain];
19100 : 0 : tbl_data = container_of(mtrmng->drop_tbl[domain],
19101 : : struct mlx5_flow_tbl_data_entry, tbl);
19102 [ # # ]: 0 : if (!mtrmng->def_matcher[domain]) {
19103 : 0 : flow_dv_match_meta_reg_all(matcher.mask.buf, value.buf,
19104 : : (enum modify_reg)mtr_id_reg_c,
19105 : : 0, 0);
19106 : 0 : matcher.priority = MLX5_MTRS_DEFAULT_RULE_PRIORITY;
19107 : 0 : matcher.crc = rte_raw_cksum
19108 : : ((const void *)matcher.mask.buf,
19109 : : matcher.mask.size);
19110 : 0 : entry = mlx5_list_register(tbl_data->matchers, &ctx);
19111 [ # # ]: 0 : if (!entry) {
19112 : 0 : DRV_LOG(ERR, "Failed to register meter "
19113 : : "drop default matcher.");
19114 : 0 : goto policy_error;
19115 : : }
19116 : 0 : mtrmng->def_matcher[domain] = container_of(entry,
19117 : : struct mlx5_flow_dv_matcher, entry);
19118 : : }
19119 : : /* Create default rule in drop table. */
19120 [ # # ]: 0 : if (!mtrmng->def_rule[domain]) {
19121 : : i = 0;
19122 : 0 : actions[i++] = priv->sh->dr_drop_action;
19123 : 0 : flow_dv_match_meta_reg_all(matcher_para.buf, value.buf,
19124 : : (enum modify_reg)mtr_id_reg_c, 0, 0);
19125 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(mtrmng->def_matcher[domain]->mask.buf);
19126 : : __flow_dv_adjust_buf_size(&value.size, misc_mask);
19127 : 0 : ret = mlx5_flow_os_create_flow
19128 : : (mtrmng->def_matcher[domain]->matcher_object,
19129 : : (void *)&value, i, actions,
19130 : : &mtrmng->def_rule[domain]);
19131 : : if (ret) {
19132 : 0 : DRV_LOG(ERR, "Failed to create meter "
19133 : : "default drop rule for drop table.");
19134 : 0 : goto policy_error;
19135 : : }
19136 : : }
19137 [ # # ]: 0 : if (!fm->drop_cnt)
19138 : 0 : continue;
19139 : : MLX5_ASSERT(mtrmng->max_mtr_bits);
19140 [ # # ]: 0 : if (!mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1]) {
19141 : : /* Create matchers for Drop. */
19142 : 0 : flow_dv_match_meta_reg_all(matcher.mask.buf, value.buf,
19143 : : (enum modify_reg)mtr_id_reg_c, 0,
19144 : : (mtr_id_mask << mtr_id_offset));
19145 : 0 : matcher.priority = MLX5_REG_BITS - mtrmng->max_mtr_bits;
19146 : 0 : matcher.crc = rte_raw_cksum
19147 : : ((const void *)matcher.mask.buf,
19148 : : matcher.mask.size);
19149 : 0 : entry = mlx5_list_register(tbl_data->matchers, &ctx);
19150 [ # # ]: 0 : if (!entry) {
19151 : 0 : DRV_LOG(ERR,
19152 : : "Failed to register meter drop matcher.");
19153 : 0 : goto policy_error;
19154 : : }
19155 : 0 : mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1] =
19156 : : container_of(entry, struct mlx5_flow_dv_matcher,
19157 : : entry);
19158 : : }
19159 : 0 : drop_matcher =
19160 : 0 : mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1];
19161 : : /* Create drop rule, matching meter_id only. */
19162 : 0 : flow_dv_match_meta_reg_all(matcher_para.buf, value.buf,
19163 : : (enum modify_reg)mtr_id_reg_c,
19164 : : (mtr_idx << mtr_id_offset), UINT32_MAX);
19165 : : i = 0;
19166 [ # # ]: 0 : cnt = flow_dv_counter_get_by_idx(dev,
19167 : : fm->drop_cnt, NULL);
19168 : 0 : actions[i++] = cnt->action;
19169 : 0 : actions[i++] = priv->sh->dr_drop_action;
19170 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(drop_matcher->mask.buf);
19171 : : __flow_dv_adjust_buf_size(&value.size, misc_mask);
19172 : 0 : ret = mlx5_flow_os_create_flow(drop_matcher->matcher_object,
19173 : : (void *)&value, i, actions,
19174 : : &fm->drop_rule[domain]);
19175 : : if (ret) {
19176 : 0 : DRV_LOG(ERR, "Failed to create meter "
19177 : : "drop rule for drop table.");
19178 : 0 : goto policy_error;
19179 : : }
19180 : : }
19181 : : return 0;
19182 : : policy_error:
19183 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
19184 [ # # ]: 0 : if (fm->drop_rule[i]) {
19185 : : claim_zero(mlx5_flow_os_destroy_flow
19186 : : (fm->drop_rule[i]));
19187 : 0 : fm->drop_rule[i] = NULL;
19188 : : }
19189 : : }
19190 : : return -1;
19191 : : }
19192 : :
19193 : : static struct mlx5_flow_meter_sub_policy *
19194 : 0 : __flow_dv_meter_get_rss_sub_policy(struct rte_eth_dev *dev,
19195 : : struct mlx5_flow_meter_policy *mtr_policy,
19196 : : struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS],
19197 : : struct mlx5_flow_meter_sub_policy *next_sub_policy,
19198 : : bool *is_reuse)
19199 : : {
19200 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19201 : : struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
19202 : 0 : uint32_t sub_policy_idx = 0;
19203 : 0 : uint32_t hrxq_idx[MLX5_MTR_RTE_COLORS] = {0};
19204 : : uint32_t i, j;
19205 : : struct mlx5_hrxq *hrxq;
19206 : : struct mlx5_flow_handle dh;
19207 : : struct mlx5_meter_policy_action_container *act_cnt;
19208 : : uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
19209 : : uint16_t sub_policy_num;
19210 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
19211 : :
19212 : : MLX5_ASSERT(wks);
19213 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19214 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
19215 [ # # ]: 0 : if (!rss_desc[i])
19216 : 0 : continue;
19217 : 0 : hrxq = mlx5_hrxq_get(dev, rss_desc[i]);
19218 [ # # ]: 0 : if (!hrxq) {
19219 : : rte_spinlock_unlock(&mtr_policy->sl);
19220 : 0 : return NULL;
19221 : : }
19222 : 0 : hrxq_idx[i] = hrxq->idx;
19223 : : }
19224 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
19225 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
19226 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
19227 [ # # ]: 0 : for (j = 0; j < sub_policy_num; j++) {
19228 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
19229 [ # # ]: 0 : if (rss_desc[i] &&
19230 : 0 : hrxq_idx[i] !=
19231 [ # # ]: 0 : mtr_policy->sub_policys[domain][j]->rix_hrxq[i])
19232 : : break;
19233 : : }
19234 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS) {
19235 : : /*
19236 : : * Found the sub policy table with
19237 : : * the same queue per color.
19238 : : */
19239 : : rte_spinlock_unlock(&mtr_policy->sl);
19240 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++)
19241 : 0 : mlx5_hrxq_release(dev, hrxq_idx[i]);
19242 : 0 : *is_reuse = true;
19243 : 0 : return mtr_policy->sub_policys[domain][j];
19244 : : }
19245 : : }
19246 : : /* Create sub policy. */
19247 [ # # ]: 0 : if (!mtr_policy->sub_policys[domain][0]->rix_hrxq[RTE_COLOR_GREEN] &&
19248 : : !mtr_policy->sub_policys[domain][0]->rix_hrxq[RTE_COLOR_YELLOW]) {
19249 : : /* Reuse the first pre-allocated sub_policy. */
19250 : : sub_policy = mtr_policy->sub_policys[domain][0];
19251 : 0 : sub_policy_idx = sub_policy->idx;
19252 : : } else {
19253 : 0 : sub_policy = mlx5_ipool_zmalloc
19254 : 0 : (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
19255 : : &sub_policy_idx);
19256 [ # # ]: 0 : if (!sub_policy ||
19257 [ # # ]: 0 : sub_policy_idx > MLX5_MAX_SUB_POLICY_TBL_NUM) {
19258 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++)
19259 : 0 : mlx5_hrxq_release(dev, hrxq_idx[i]);
19260 : 0 : goto rss_sub_policy_error;
19261 : : }
19262 : 0 : sub_policy->idx = sub_policy_idx;
19263 : 0 : sub_policy->main_policy = mtr_policy;
19264 : : }
19265 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
19266 [ # # ]: 0 : if (!rss_desc[i])
19267 : 0 : continue;
19268 : 0 : sub_policy->rix_hrxq[i] = hrxq_idx[i];
19269 [ # # ]: 0 : if (mtr_policy->is_hierarchy) {
19270 : : act_cnt = &mtr_policy->act_cnt[i];
19271 : 0 : act_cnt->next_sub_policy = next_sub_policy;
19272 : 0 : mlx5_hrxq_release(dev, hrxq_idx[i]);
19273 : : } else {
19274 : : /*
19275 : : * Overwrite the last action from
19276 : : * RSS action to Queue action.
19277 : : */
19278 : 0 : hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
19279 : : hrxq_idx[i]);
19280 [ # # ]: 0 : if (!hrxq) {
19281 : 0 : DRV_LOG(ERR, "Failed to get policy hrxq");
19282 : 0 : goto rss_sub_policy_error;
19283 : : }
19284 : : act_cnt = &mtr_policy->act_cnt[i];
19285 [ # # # # ]: 0 : if (act_cnt->rix_mark || act_cnt->modify_hdr) {
19286 : : memset(&dh, 0, sizeof(struct mlx5_flow_handle));
19287 [ # # ]: 0 : if (act_cnt->rix_mark)
19288 : 0 : wks->mark = 1;
19289 : 0 : dh.fate_action = MLX5_FLOW_FATE_QUEUE;
19290 : 0 : dh.rix_hrxq = hrxq_idx[i];
19291 : 0 : mlx5_flow_drv_rxq_flags_set(dev, &dh);
19292 : : }
19293 : : }
19294 : : }
19295 [ # # ]: 0 : if (__flow_dv_create_policy_acts_rules(dev, mtr_policy,
19296 : : sub_policy, domain)) {
19297 : 0 : DRV_LOG(ERR, "Failed to create policy "
19298 : : "rules for ingress domain.");
19299 : 0 : goto rss_sub_policy_error;
19300 : : }
19301 [ # # ]: 0 : if (sub_policy != mtr_policy->sub_policys[domain][0]) {
19302 : 0 : i = (mtr_policy->sub_policy_num >>
19303 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
19304 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
19305 [ # # ]: 0 : if (i >= MLX5_MTR_RSS_MAX_SUB_POLICY) {
19306 : 0 : DRV_LOG(ERR, "No free sub-policy slot.");
19307 : 0 : goto rss_sub_policy_error;
19308 : : }
19309 : 0 : mtr_policy->sub_policys[domain][i] = sub_policy;
19310 : 0 : i++;
19311 : 0 : mtr_policy->sub_policy_num &= ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
19312 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain));
19313 : 0 : mtr_policy->sub_policy_num |=
19314 : 0 : (i & MLX5_MTR_SUB_POLICY_NUM_MASK) <<
19315 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain);
19316 : : }
19317 : : rte_spinlock_unlock(&mtr_policy->sl);
19318 : 0 : *is_reuse = false;
19319 : 0 : return sub_policy;
19320 : 0 : rss_sub_policy_error:
19321 [ # # ]: 0 : if (sub_policy) {
19322 : 0 : __flow_dv_destroy_sub_policy_rules(dev, sub_policy);
19323 [ # # ]: 0 : if (sub_policy != mtr_policy->sub_policys[domain][0]) {
19324 : 0 : i = (mtr_policy->sub_policy_num >>
19325 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
19326 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
19327 : 0 : mtr_policy->sub_policys[domain][i] = NULL;
19328 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
19329 : 0 : sub_policy->idx);
19330 : : }
19331 : : }
19332 : : rte_spinlock_unlock(&mtr_policy->sl);
19333 : 0 : return NULL;
19334 : : }
19335 : :
19336 : : /**
19337 : : * Find the policy table for prefix table with RSS.
19338 : : *
19339 : : * @param[in] dev
19340 : : * Pointer to Ethernet device.
19341 : : * @param[in] mtr_policy
19342 : : * Pointer to meter policy table.
19343 : : * @param[in] rss_desc
19344 : : * Pointer to rss_desc
19345 : : * @return
19346 : : * Pointer to table set on success, NULL otherwise and rte_errno is set.
19347 : : */
19348 : : static struct mlx5_flow_meter_sub_policy *
19349 : 0 : flow_dv_meter_sub_policy_rss_prepare(struct rte_eth_dev *dev,
19350 : : struct mlx5_flow_meter_policy *mtr_policy,
19351 : : struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS])
19352 : : {
19353 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19354 : : struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
19355 : : struct mlx5_flow_meter_info *next_fm;
19356 : : struct mlx5_flow_meter_policy *next_policy;
19357 : : struct mlx5_flow_meter_sub_policy *next_sub_policy = NULL;
19358 : : struct mlx5_flow_meter_policy *policies[MLX5_MTR_CHAIN_MAX_NUM];
19359 : : struct mlx5_flow_meter_sub_policy *sub_policies[MLX5_MTR_CHAIN_MAX_NUM];
19360 : : uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
19361 : : bool reuse_sub_policy;
19362 : : uint32_t i = 0;
19363 : : uint32_t j = 0;
19364 : :
19365 : : while (true) {
19366 : : /* Iterate hierarchy to get all policies in this hierarchy. */
19367 : 0 : policies[i++] = mtr_policy;
19368 [ # # ]: 0 : if (!mtr_policy->is_hierarchy)
19369 : : break;
19370 [ # # ]: 0 : if (i >= MLX5_MTR_CHAIN_MAX_NUM) {
19371 : 0 : DRV_LOG(ERR, "Exceed max meter number in hierarchy.");
19372 : 0 : return NULL;
19373 : : }
19374 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19375 : 0 : next_fm = mlx5_flow_meter_hierarchy_next_meter(priv, mtr_policy, NULL);
19376 : : rte_spinlock_unlock(&mtr_policy->sl);
19377 [ # # ]: 0 : if (!next_fm) {
19378 : 0 : DRV_LOG(ERR, "Failed to get next meter in hierarchy.");
19379 : 0 : return NULL;
19380 : : }
19381 : : next_policy =
19382 : 0 : mlx5_flow_meter_policy_find(dev, next_fm->policy_id,
19383 : : NULL);
19384 : : MLX5_ASSERT(next_policy);
19385 : : mtr_policy = next_policy;
19386 : : }
19387 [ # # ]: 0 : while (i) {
19388 : : /**
19389 : : * From last policy to the first one in hierarchy,
19390 : : * create / get the sub policy for each of them.
19391 : : */
19392 : 0 : sub_policy = __flow_dv_meter_get_rss_sub_policy(dev,
19393 : : policies[--i],
19394 : : rss_desc,
19395 : : next_sub_policy,
19396 : : &reuse_sub_policy);
19397 [ # # ]: 0 : if (!sub_policy) {
19398 : 0 : DRV_LOG(ERR, "Failed to get the sub policy.");
19399 : 0 : goto err_exit;
19400 : : }
19401 [ # # ]: 0 : if (!reuse_sub_policy)
19402 : 0 : sub_policies[j++] = sub_policy;
19403 : : next_sub_policy = sub_policy;
19404 : : }
19405 : : return sub_policy;
19406 : : err_exit:
19407 [ # # ]: 0 : while (j) {
19408 : : uint16_t sub_policy_num;
19409 : :
19410 : 0 : sub_policy = sub_policies[--j];
19411 : 0 : mtr_policy = sub_policy->main_policy;
19412 : 0 : __flow_dv_destroy_sub_policy_rules(dev, sub_policy);
19413 [ # # ]: 0 : if (sub_policy != mtr_policy->sub_policys[domain][0]) {
19414 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
19415 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
19416 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
19417 : 0 : mtr_policy->sub_policys[domain][sub_policy_num - 1] =
19418 : : NULL;
19419 : 0 : sub_policy_num--;
19420 : 0 : mtr_policy->sub_policy_num &=
19421 : 0 : ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
19422 : 0 : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i));
19423 : 0 : mtr_policy->sub_policy_num |=
19424 : 0 : (sub_policy_num & MLX5_MTR_SUB_POLICY_NUM_MASK) <<
19425 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i);
19426 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
19427 : 0 : sub_policy->idx);
19428 : : }
19429 : : }
19430 : : return NULL;
19431 : : }
19432 : :
19433 : : /**
19434 : : * Check if need to create hierarchy tag rule.
19435 : : *
19436 : : * @param[in] priv
19437 : : * Pointer to mlx5_priv.
19438 : : * @param[in] mtr_policy
19439 : : * Pointer to current meter policy.
19440 : : * @param[in] src_port
19441 : : * The src port this extra rule should use.
19442 : : * @param[out] next_fm
19443 : : * Pointer to next meter in hierarchy.
19444 : : * @param[out] skip
19445 : : * Indicate if skip the tag rule creation.
19446 : : * @param[out] error
19447 : : * Perform verbose error reporting if not NULL.
19448 : : * @return
19449 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
19450 : : */
19451 : : static int
19452 : 0 : mlx5_meter_hierarchy_skip_tag_rule(struct mlx5_priv *priv,
19453 : : struct mlx5_flow_meter_policy *mtr_policy,
19454 : : int32_t src_port,
19455 : : struct mlx5_flow_meter_info **next_fm,
19456 : : bool *skip,
19457 : : struct rte_flow_error *error)
19458 : : {
19459 : : struct mlx5_flow_meter_sub_policy *sub_policy;
19460 : : struct mlx5_sub_policy_color_rule *color_rule;
19461 : : uint32_t domain = MLX5_MTR_DOMAIN_TRANSFER;
19462 : : int ret = 0;
19463 : : int i;
19464 : :
19465 : 0 : *next_fm = NULL;
19466 : 0 : *skip = false;
19467 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19468 [ # # ]: 0 : if (mtr_policy->is_hierarchy) {
19469 : 0 : *next_fm = mlx5_flow_meter_hierarchy_next_meter(priv, mtr_policy, NULL);
19470 [ # # ]: 0 : if (!*next_fm) {
19471 : 0 : ret = rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
19472 : : NULL, "Failed to find next meter in hierarchy.");
19473 : 0 : goto exit;
19474 : : }
19475 : : }
19476 [ # # ]: 0 : if (!mtr_policy->match_port) {
19477 : 0 : *skip = true;
19478 : 0 : goto exit;
19479 : : }
19480 : 0 : sub_policy = mtr_policy->sub_policys[domain][0];
19481 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
19482 [ # # ]: 0 : if (mtr_policy->act_cnt[i].fate_action != MLX5_FLOW_FATE_MTR &&
19483 : : mtr_policy->act_cnt[i].fate_action != MLX5_FLOW_FATE_PORT_ID)
19484 : 0 : continue;
19485 [ # # ]: 0 : TAILQ_FOREACH(color_rule, &sub_policy->color_rules[i], next_port)
19486 [ # # ]: 0 : if (color_rule->src_port == src_port) {
19487 : 0 : *skip = true;
19488 : 0 : goto exit;
19489 : : }
19490 : : }
19491 : 0 : exit:
19492 : : rte_spinlock_unlock(&mtr_policy->sl);
19493 : 0 : return ret;
19494 : : }
19495 : :
19496 : : /**
19497 : : * Create the sub policy tag rule for all meters in hierarchy.
19498 : : *
19499 : : * @param[in] dev
19500 : : * Pointer to Ethernet device.
19501 : : * @param[in] fm
19502 : : * Meter information table.
19503 : : * @param[in] src_port
19504 : : * The src port this extra rule should use.
19505 : : * @param[in] item
19506 : : * The src port match item.
19507 : : * @param[out] error
19508 : : * Perform verbose error reporting if not NULL.
19509 : : * @return
19510 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
19511 : : */
19512 : : static int
19513 : 0 : flow_dv_meter_hierarchy_rule_create(struct rte_eth_dev *dev,
19514 : : struct mlx5_flow_meter_info *fm,
19515 : : int32_t src_port,
19516 : : const struct rte_flow_item *item,
19517 : : struct rte_flow_error *error)
19518 : : {
19519 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19520 : : struct mlx5_flow_meter_policy *mtr_policy;
19521 : : struct mlx5_flow_meter_sub_policy *sub_policy;
19522 : 0 : struct mlx5_flow_meter_info *next_fm = NULL;
19523 : : struct mlx5_flow_meter_policy *next_policy;
19524 : : struct mlx5_flow_meter_sub_policy *next_sub_policy;
19525 : : struct mlx5_flow_tbl_data_entry *tbl_data;
19526 : : struct mlx5_sub_policy_color_rule *color_rule;
19527 : : struct mlx5_meter_policy_acts acts;
19528 : : uint32_t color_reg_c_idx;
19529 : : bool mtr_first = (src_port != UINT16_MAX) ? true : false;
19530 : 0 : struct rte_flow_attr attr = {
19531 : : .group = MLX5_FLOW_TABLE_LEVEL_POLICY,
19532 : : .priority = 0,
19533 : : .ingress = 0,
19534 : : .egress = 0,
19535 : : .transfer = 1,
19536 : : .reserved = 0,
19537 : : };
19538 : : uint32_t domain = MLX5_MTR_DOMAIN_TRANSFER;
19539 : : struct {
19540 : : struct mlx5_flow_meter_policy *fm_policy;
19541 : : struct mlx5_flow_meter_info *next_fm;
19542 : : struct mlx5_sub_policy_color_rule *tag_rule[RTE_COLORS];
19543 : 0 : } fm_info[MLX5_MTR_CHAIN_MAX_NUM] = { {0} };
19544 : : uint32_t fm_cnt = 0;
19545 : : uint32_t i, j;
19546 : :
19547 : 0 : color_reg_c_idx = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, error);
19548 : : /* Get all fms who need to create the tag color rule. */
19549 : : do {
19550 : 0 : bool skip = false;
19551 : :
19552 : 0 : mtr_policy = mlx5_flow_meter_policy_find(dev, fm->policy_id, NULL);
19553 : : MLX5_ASSERT(mtr_policy);
19554 [ # # ]: 0 : if (mlx5_meter_hierarchy_skip_tag_rule(priv, mtr_policy, src_port,
19555 : : &next_fm, &skip, error))
19556 : 0 : goto err_exit;
19557 [ # # ]: 0 : if (!skip) {
19558 : 0 : fm_info[fm_cnt].fm_policy = mtr_policy;
19559 : 0 : fm_info[fm_cnt].next_fm = next_fm;
19560 [ # # ]: 0 : if (++fm_cnt >= MLX5_MTR_CHAIN_MAX_NUM) {
19561 : 0 : rte_flow_error_set(error, errno,
19562 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
19563 : : "Exceed max meter number in hierarchy.");
19564 : 0 : goto err_exit;
19565 : : }
19566 : : }
19567 : 0 : fm = next_fm;
19568 [ # # ]: 0 : } while (fm);
19569 : : /* Create tag color rules for all needed fms. */
19570 [ # # ]: 0 : for (i = 0; i < fm_cnt; i++) {
19571 : : void *mtr_action;
19572 : :
19573 : 0 : mtr_policy = fm_info[i].fm_policy;
19574 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19575 : 0 : sub_policy = mtr_policy->sub_policys[domain][0];
19576 [ # # ]: 0 : for (j = 0; j < RTE_COLORS; j++) {
19577 : : uint8_t act_n = 0;
19578 : : struct mlx5_flow_dv_modify_hdr_resource *modify_hdr = NULL;
19579 : : struct mlx5_flow_dv_port_id_action_resource *port_action;
19580 : : uint8_t fate_action;
19581 : :
19582 [ # # ]: 0 : if (j == RTE_COLOR_RED) {
19583 : : fate_action = MLX5_FLOW_FATE_DROP;
19584 : : } else {
19585 : 0 : fate_action = mtr_policy->act_cnt[j].fate_action;
19586 : 0 : modify_hdr = mtr_policy->act_cnt[j].modify_hdr;
19587 : 0 : if (fate_action != MLX5_FLOW_FATE_MTR &&
19588 [ # # # # ]: 0 : fate_action != MLX5_FLOW_FATE_PORT_ID &&
19589 : : fate_action != MLX5_FLOW_FATE_DROP)
19590 : 0 : continue;
19591 : : }
19592 : 0 : color_rule = mlx5_malloc(MLX5_MEM_ZERO,
19593 : : sizeof(struct mlx5_sub_policy_color_rule),
19594 : : 0, SOCKET_ID_ANY);
19595 [ # # ]: 0 : if (!color_rule) {
19596 : : rte_spinlock_unlock(&mtr_policy->sl);
19597 : 0 : rte_flow_error_set(error, ENOMEM,
19598 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
19599 : : "No memory to create tag color rule.");
19600 : 0 : goto err_exit;
19601 : : }
19602 : 0 : color_rule->src_port = src_port;
19603 : : /* Prepare to create color rule. */
19604 [ # # ]: 0 : if (fate_action == MLX5_FLOW_FATE_MTR) {
19605 : 0 : next_fm = fm_info[i].next_fm;
19606 [ # # ]: 0 : if (mlx5_flow_meter_attach(priv, next_fm, &attr, error)) {
19607 : 0 : mlx5_free(color_rule);
19608 : : rte_spinlock_unlock(&mtr_policy->sl);
19609 : 0 : goto err_exit;
19610 : : }
19611 [ # # ]: 0 : mtr_action = (next_fm->color_aware && j == RTE_COLOR_YELLOW) ?
19612 [ # # ]: 0 : next_fm->meter_action_y :
19613 : : next_fm->meter_action_g;
19614 : 0 : next_policy = mlx5_flow_meter_policy_find(dev, next_fm->policy_id,
19615 : : NULL);
19616 : : MLX5_ASSERT(next_policy);
19617 : 0 : next_sub_policy = next_policy->sub_policys[domain][0];
19618 : 0 : tbl_data = container_of(next_sub_policy->tbl_rsc,
19619 : : struct mlx5_flow_tbl_data_entry, tbl);
19620 [ # # ]: 0 : if (mtr_first) {
19621 : 0 : acts.dv_actions[act_n++] = mtr_action;
19622 [ # # ]: 0 : if (modify_hdr)
19623 : 0 : acts.dv_actions[act_n++] = modify_hdr->action;
19624 : : } else {
19625 [ # # ]: 0 : if (modify_hdr)
19626 : 0 : acts.dv_actions[act_n++] = modify_hdr->action;
19627 : 0 : acts.dv_actions[act_n++] = mtr_action;
19628 : : }
19629 : 0 : acts.dv_actions[act_n++] = tbl_data->jump.action;
19630 : 0 : acts.actions_n = act_n;
19631 [ # # ]: 0 : } else if (fate_action == MLX5_FLOW_FATE_PORT_ID) {
19632 : : port_action =
19633 : 0 : mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PORT_ID],
19634 : : mtr_policy->act_cnt[j].rix_port_id_action);
19635 [ # # ]: 0 : if (!port_action) {
19636 : 0 : mlx5_free(color_rule);
19637 : : rte_spinlock_unlock(&mtr_policy->sl);
19638 : 0 : goto err_exit;
19639 : : }
19640 [ # # ]: 0 : if (modify_hdr)
19641 : 0 : acts.dv_actions[act_n++] = modify_hdr->action;
19642 : 0 : acts.dv_actions[act_n++] = port_action->action;
19643 : 0 : acts.actions_n = act_n;
19644 : : } else {
19645 : 0 : acts.dv_actions[act_n++] = mtr_policy->dr_drop_action[domain];
19646 : 0 : acts.actions_n = act_n;
19647 : : }
19648 : 0 : fm_info[i].tag_rule[j] = color_rule;
19649 : 0 : TAILQ_INSERT_TAIL(&sub_policy->color_rules[j], color_rule, next_port);
19650 [ # # ]: 0 : if (__flow_dv_create_policy_matcher(dev, color_reg_c_idx,
19651 : : MLX5_MTR_POLICY_MATCHER_PRIO, sub_policy,
19652 : : &attr, true, item, &color_rule->matcher, error)) {
19653 : : rte_spinlock_unlock(&mtr_policy->sl);
19654 : 0 : rte_flow_error_set(error, errno,
19655 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
19656 : : "Failed to create hierarchy meter matcher.");
19657 : 0 : goto err_exit;
19658 : : }
19659 [ # # ]: 0 : if (__flow_dv_create_policy_flow(dev, color_reg_c_idx, (enum rte_color)j,
19660 : : color_rule->matcher,
19661 : 0 : acts.actions_n, acts.dv_actions,
19662 : : true, item, &color_rule->rule, &attr)) {
19663 : : rte_spinlock_unlock(&mtr_policy->sl);
19664 : 0 : rte_flow_error_set(error, errno,
19665 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
19666 : : "Failed to create hierarchy meter rule.");
19667 : 0 : goto err_exit;
19668 : : }
19669 : : }
19670 : : rte_spinlock_unlock(&mtr_policy->sl);
19671 : : }
19672 : : return 0;
19673 : 0 : err_exit:
19674 [ # # ]: 0 : for (i = 0; i < fm_cnt; i++) {
19675 : 0 : mtr_policy = fm_info[i].fm_policy;
19676 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19677 : 0 : sub_policy = mtr_policy->sub_policys[domain][0];
19678 [ # # ]: 0 : for (j = 0; j < RTE_COLORS; j++) {
19679 : 0 : color_rule = fm_info[i].tag_rule[j];
19680 [ # # ]: 0 : if (!color_rule)
19681 : 0 : continue;
19682 [ # # ]: 0 : if (color_rule->rule)
19683 : : mlx5_flow_os_destroy_flow(color_rule->rule);
19684 [ # # ]: 0 : if (color_rule->matcher) {
19685 : : struct mlx5_flow_tbl_data_entry *tbl =
19686 : 0 : container_of(color_rule->matcher->tbl, typeof(*tbl), tbl);
19687 : 0 : mlx5_list_unregister(tbl->matchers, &color_rule->matcher->entry);
19688 : : }
19689 [ # # ]: 0 : if (fm_info[i].next_fm)
19690 : 0 : mlx5_flow_meter_detach(priv, fm_info[i].next_fm);
19691 [ # # ]: 0 : TAILQ_REMOVE(&sub_policy->color_rules[j], color_rule, next_port);
19692 : 0 : mlx5_free(color_rule);
19693 : : }
19694 : : rte_spinlock_unlock(&mtr_policy->sl);
19695 : : }
19696 : 0 : return -rte_errno;
19697 : : }
19698 : :
19699 : : /**
19700 : : * Destroy the sub policy table with RX queue.
19701 : : *
19702 : : * @param[in] dev
19703 : : * Pointer to Ethernet device.
19704 : : * @param[in] mtr_policy
19705 : : * Pointer to meter policy table.
19706 : : */
19707 : : static void
19708 : 0 : flow_dv_destroy_sub_policy_with_rxq(struct rte_eth_dev *dev,
19709 : : struct mlx5_flow_meter_policy *mtr_policy)
19710 : : {
19711 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19712 : : struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
19713 : : uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
19714 : : uint32_t i, j;
19715 : : uint16_t sub_policy_num, new_policy_num;
19716 : :
19717 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19718 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
19719 [ # # # ]: 0 : switch (mtr_policy->act_cnt[i].fate_action) {
19720 : 0 : case MLX5_FLOW_FATE_SHARED_RSS:
19721 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
19722 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
19723 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
19724 : : new_policy_num = sub_policy_num;
19725 [ # # ]: 0 : for (j = 0; j < sub_policy_num; j++) {
19726 : 0 : sub_policy =
19727 : 0 : mtr_policy->sub_policys[domain][j];
19728 [ # # ]: 0 : if (sub_policy) {
19729 : 0 : __flow_dv_destroy_sub_policy_rules(dev,
19730 : : sub_policy);
19731 : 0 : if (sub_policy !=
19732 [ # # ]: 0 : mtr_policy->sub_policys[domain][0]) {
19733 : 0 : mtr_policy->sub_policys[domain][j] =
19734 : : NULL;
19735 : 0 : mlx5_ipool_free
19736 : 0 : (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
19737 : 0 : sub_policy->idx);
19738 : 0 : new_policy_num--;
19739 : : }
19740 : : }
19741 : : }
19742 [ # # ]: 0 : if (new_policy_num != sub_policy_num) {
19743 : 0 : mtr_policy->sub_policy_num &=
19744 : : ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
19745 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain));
19746 : 0 : mtr_policy->sub_policy_num |=
19747 : : (new_policy_num &
19748 : : MLX5_MTR_SUB_POLICY_NUM_MASK) <<
19749 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain);
19750 : : }
19751 : : break;
19752 : 0 : case MLX5_FLOW_FATE_QUEUE:
19753 : 0 : sub_policy = mtr_policy->sub_policys[domain][0];
19754 : 0 : __flow_dv_destroy_sub_policy_rules(dev,
19755 : : sub_policy);
19756 : 0 : break;
19757 : : default:
19758 : : /*Other actions without queue and do nothing*/
19759 : : break;
19760 : : }
19761 : : }
19762 : : rte_spinlock_unlock(&mtr_policy->sl);
19763 : 0 : }
19764 : : /**
19765 : : * Check whether the DR drop action is supported on the root table or not.
19766 : : *
19767 : : * Create a simple flow with DR drop action on root table to validate
19768 : : * if DR drop action on root table is supported or not.
19769 : : *
19770 : : * @param[in] dev
19771 : : * Pointer to rte_eth_dev structure.
19772 : : *
19773 : : * @return
19774 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
19775 : : */
19776 : : int
19777 : 0 : mlx5_flow_discover_dr_action_support(struct rte_eth_dev *dev)
19778 : : {
19779 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19780 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
19781 : 0 : struct mlx5_flow_dv_match_params mask = {
19782 : : .size = sizeof(mask.buf),
19783 : : };
19784 : 0 : struct mlx5_flow_dv_match_params value = {
19785 : : .size = sizeof(value.buf),
19786 : : };
19787 : 0 : struct mlx5dv_flow_matcher_attr dv_attr = {
19788 : : .type = IBV_FLOW_ATTR_NORMAL,
19789 : : .priority = 0,
19790 : : .match_criteria_enable = 0,
19791 : : .match_mask = (void *)&mask,
19792 : : };
19793 : : struct mlx5_flow_tbl_resource *tbl = NULL;
19794 : : void *matcher = NULL;
19795 : : void *flow = NULL;
19796 : : int ret = -1;
19797 : : struct rte_flow_item_eth eth;
19798 : 0 : struct rte_flow_item item = {
19799 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
19800 : : .spec = ð,
19801 : : .mask = ð,
19802 : : };
19803 : :
19804 : : memset(ð, 0, sizeof(eth));
19805 : : memset(ð.hdr.dst_addr, 0xff, sizeof(eth.hdr.dst_addr));
19806 : : memset(ð.hdr.src_addr, 0xff, sizeof(eth.hdr.src_addr));
19807 : 0 : flow_dv_translate_item_eth(mask.buf, &item,
19808 : : /* inner */ false, /* group */ 0,
19809 : : MLX5_SET_MATCHER_SW_M);
19810 : 0 : flow_dv_translate_item_eth(value.buf, &item,
19811 : : /* inner */ false, /* group */ 0,
19812 : : MLX5_SET_MATCHER_SW_V);
19813 : :
19814 : 0 : tbl = mlx5_flow_dv_tbl_resource_get(dev, 0, 0, 0, false, NULL,
19815 : : 0, 0, 0, NULL);
19816 [ # # ]: 0 : if (!tbl)
19817 : 0 : goto err;
19818 [ # # ]: 0 : dv_attr.match_criteria_enable = flow_dv_matcher_enable(mask.buf);
19819 : : __flow_dv_adjust_buf_size(&mask.size, dv_attr.match_criteria_enable);
19820 : 0 : ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
19821 : : tbl->obj, &matcher);
19822 : : if (ret)
19823 : 0 : goto err;
19824 [ # # ]: 0 : __flow_dv_adjust_buf_size(&value.size, dv_attr.match_criteria_enable);
19825 : 0 : ret = mlx5_flow_os_create_flow(matcher, (void *)&value, 1,
19826 : : &sh->dr_drop_action, &flow);
19827 : 0 : err:
19828 : : /*
19829 : : * If DR drop action is not supported on root table, flow create will
19830 : : * be failed with EOPNOTSUPP or EPROTONOSUPPORT.
19831 : : */
19832 [ # # ]: 0 : if (!flow) {
19833 [ # # ]: 0 : if (matcher &&
19834 [ # # ]: 0 : (errno == EPROTONOSUPPORT || errno == EOPNOTSUPP))
19835 : 0 : DRV_LOG(INFO, "DR drop action is not supported in root table.");
19836 : : else
19837 : 0 : DRV_LOG(ERR, "Unexpected error in DR drop action support detection");
19838 : : ret = -1;
19839 : : } else {
19840 : : claim_zero(mlx5_flow_os_destroy_flow(flow));
19841 : : }
19842 [ # # ]: 0 : if (matcher)
19843 : : claim_zero(mlx5_flow_os_destroy_flow_matcher(matcher));
19844 [ # # ]: 0 : if (tbl)
19845 : 0 : mlx5_flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
19846 : 0 : return ret;
19847 : : }
19848 : :
19849 : : /**
19850 : : * Validate the batch counter support in root table.
19851 : : *
19852 : : * Create a simple flow with invalid counter and drop action on root table to
19853 : : * validate if batch counter with offset on root table is supported or not.
19854 : : *
19855 : : * @param[in] dev
19856 : : * Pointer to rte_eth_dev structure.
19857 : : *
19858 : : * @return
19859 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
19860 : : */
19861 : : int
19862 : 0 : mlx5_flow_dv_discover_counter_offset_support(struct rte_eth_dev *dev)
19863 : : {
19864 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19865 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
19866 : 0 : struct mlx5_flow_dv_match_params mask = {
19867 : : .size = sizeof(mask.buf),
19868 : : };
19869 : 0 : struct mlx5_flow_dv_match_params value = {
19870 : : .size = sizeof(value.buf),
19871 : : };
19872 : 0 : struct mlx5dv_flow_matcher_attr dv_attr = {
19873 : : .type = IBV_FLOW_ATTR_NORMAL,
19874 : : .flags = IBV_FLOW_ATTR_FLAGS_EGRESS,
19875 : : .priority = 0,
19876 : : .match_criteria_enable = 0,
19877 : : .match_mask = (void *)&mask,
19878 : : };
19879 : 0 : void *actions[2] = { 0 };
19880 : : struct mlx5_flow_tbl_resource *tbl = NULL;
19881 : : struct mlx5_devx_obj *dcs = NULL;
19882 : : void *matcher = NULL;
19883 : : void *flow = NULL;
19884 : : int ret = -1;
19885 : :
19886 : 0 : tbl = mlx5_flow_dv_tbl_resource_get(dev, 0, 1, 0, false, NULL,
19887 : : 0, 0, 0, NULL);
19888 [ # # ]: 0 : if (!tbl)
19889 : 0 : goto err;
19890 : 0 : dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0x4);
19891 [ # # ]: 0 : if (!dcs)
19892 : 0 : goto err;
19893 : 0 : ret = mlx5_flow_os_create_flow_action_count(dcs->obj, UINT16_MAX,
19894 : : &actions[0]);
19895 : : if (ret)
19896 : 0 : goto err;
19897 [ # # ]: 0 : dv_attr.match_criteria_enable = flow_dv_matcher_enable(mask.buf);
19898 : : __flow_dv_adjust_buf_size(&mask.size, dv_attr.match_criteria_enable);
19899 : 0 : ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
19900 : : tbl->obj, &matcher);
19901 : : if (ret)
19902 : 0 : goto err;
19903 [ # # ]: 0 : __flow_dv_adjust_buf_size(&value.size, dv_attr.match_criteria_enable);
19904 : : ret = mlx5_flow_os_create_flow(matcher, (void *)&value, 1,
19905 : : actions, &flow);
19906 : 0 : err:
19907 : : /*
19908 : : * If batch counter with offset is not supported, the driver will not
19909 : : * validate the invalid offset value, flow create should success.
19910 : : * In this case, it means batch counter is not supported in root table.
19911 : : *
19912 : : * Otherwise, if flow create is failed, counter offset is supported.
19913 : : */
19914 [ # # ]: 0 : if (flow) {
19915 : 0 : DRV_LOG(INFO, "Batch counter is not supported in root "
19916 : : "table. Switch to fallback mode.");
19917 : 0 : rte_errno = ENOTSUP;
19918 : : ret = -rte_errno;
19919 : : claim_zero(mlx5_flow_os_destroy_flow(flow));
19920 : : } else {
19921 : : /* Check matcher to make sure validate fail at flow create. */
19922 [ # # # # ]: 0 : if (!matcher || (matcher && errno != EINVAL))
19923 : 0 : DRV_LOG(ERR, "Unexpected error in counter offset "
19924 : : "support detection");
19925 : : ret = 0;
19926 : : }
19927 [ # # ]: 0 : if (actions[0])
19928 : : claim_zero(mlx5_flow_os_destroy_flow_action(actions[0]));
19929 [ # # ]: 0 : if (matcher)
19930 : : claim_zero(mlx5_flow_os_destroy_flow_matcher(matcher));
19931 [ # # ]: 0 : if (tbl)
19932 : 0 : mlx5_flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
19933 [ # # ]: 0 : if (dcs)
19934 : 0 : claim_zero(mlx5_devx_cmd_destroy(dcs));
19935 : 0 : return ret;
19936 : : }
19937 : :
19938 : : /**
19939 : : * Query a devx counter.
19940 : : *
19941 : : * @param[in] dev
19942 : : * Pointer to the Ethernet device structure.
19943 : : * @param[in] cnt
19944 : : * Index to the flow counter.
19945 : : * @param[in] clear
19946 : : * Set to clear the counter statistics.
19947 : : * @param[out] pkts
19948 : : * The statistics value of packets.
19949 : : * @param[out] bytes
19950 : : * The statistics value of bytes.
19951 : : *
19952 : : * @return
19953 : : * 0 on success, otherwise return -1.
19954 : : */
19955 : : static int
19956 : 0 : flow_dv_counter_query(struct rte_eth_dev *dev, uint32_t counter, bool clear,
19957 : : uint64_t *pkts, uint64_t *bytes, void **action)
19958 : : {
19959 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19960 : : struct mlx5_flow_counter *cnt;
19961 : : uint64_t inn_pkts, inn_bytes;
19962 : : int ret;
19963 : :
19964 [ # # ]: 0 : if (!priv->sh->cdev->config.devx)
19965 : : return -1;
19966 : :
19967 : 0 : ret = _flow_dv_query_count(dev, counter, &inn_pkts, &inn_bytes);
19968 [ # # ]: 0 : if (ret)
19969 : : return -1;
19970 : : cnt = flow_dv_counter_get_by_idx(dev, counter, NULL);
19971 [ # # ]: 0 : if (cnt && action)
19972 : 0 : *action = cnt->action;
19973 : :
19974 : 0 : *pkts = inn_pkts - cnt->hits;
19975 : 0 : *bytes = inn_bytes - cnt->bytes;
19976 [ # # ]: 0 : if (clear) {
19977 : 0 : cnt->hits = inn_pkts;
19978 : 0 : cnt->bytes = inn_bytes;
19979 : : }
19980 : : return 0;
19981 : : }
19982 : :
19983 : : /**
19984 : : * Get aged-out flows.
19985 : : *
19986 : : * @param[in] dev
19987 : : * Pointer to the Ethernet device structure.
19988 : : * @param[in] context
19989 : : * The address of an array of pointers to the aged-out flows contexts.
19990 : : * @param[in] nb_contexts
19991 : : * The length of context array pointers.
19992 : : * @param[out] error
19993 : : * Perform verbose error reporting if not NULL. Initialized in case of
19994 : : * error only.
19995 : : *
19996 : : * @return
19997 : : * how many contexts get in success, otherwise negative errno value.
19998 : : * if nb_contexts is 0, return the amount of all aged contexts.
19999 : : * if nb_contexts is not 0 , return the amount of aged flows reported
20000 : : * in the context array.
20001 : : * @note: only stub for now
20002 : : */
20003 : : static int
20004 : 0 : flow_dv_get_aged_flows(struct rte_eth_dev *dev,
20005 : : void **context,
20006 : : uint32_t nb_contexts,
20007 : : struct rte_flow_error *error)
20008 : : {
20009 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
20010 : : struct mlx5_age_info *age_info;
20011 : : struct mlx5_age_param *age_param;
20012 : : struct mlx5_flow_counter *counter;
20013 : : struct mlx5_aso_age_action *act;
20014 : : int nb_flows = 0;
20015 : :
20016 [ # # ]: 0 : if (nb_contexts && !context)
20017 : 0 : return rte_flow_error_set(error, EINVAL,
20018 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
20019 : : NULL, "empty context");
20020 : 0 : age_info = GET_PORT_AGE_INFO(priv);
20021 : 0 : rte_spinlock_lock(&age_info->aged_sl);
20022 [ # # ]: 0 : LIST_FOREACH(act, &age_info->aged_aso, next) {
20023 : 0 : nb_flows++;
20024 [ # # ]: 0 : if (nb_contexts) {
20025 : 0 : context[nb_flows - 1] = act->age_params.context;
20026 [ # # ]: 0 : if (!(--nb_contexts))
20027 : : break;
20028 : : }
20029 : : }
20030 [ # # ]: 0 : TAILQ_FOREACH(counter, &age_info->aged_counters, next) {
20031 : 0 : nb_flows++;
20032 [ # # ]: 0 : if (nb_contexts) {
20033 : : age_param = MLX5_CNT_TO_AGE(counter);
20034 : 0 : context[nb_flows - 1] = age_param->context;
20035 [ # # ]: 0 : if (!(--nb_contexts))
20036 : : break;
20037 : : }
20038 : : }
20039 : : rte_spinlock_unlock(&age_info->aged_sl);
20040 : 0 : MLX5_AGE_SET(age_info, MLX5_AGE_TRIGGER);
20041 : 0 : return nb_flows;
20042 : : }
20043 : :
20044 : : /*
20045 : : * Mutex-protected thunk to lock-free flow_dv_counter_alloc().
20046 : : */
20047 : : static uint32_t
20048 : 0 : flow_dv_counter_allocate(struct rte_eth_dev *dev)
20049 : : {
20050 : 0 : return flow_dv_counter_alloc(dev, 0);
20051 : : }
20052 : :
20053 : : /**
20054 : : * Validate indirect action.
20055 : : * Dispatcher for action type specific validation.
20056 : : *
20057 : : * @param[in] dev
20058 : : * Pointer to the Ethernet device structure.
20059 : : * @param[in] conf
20060 : : * Indirect action configuration.
20061 : : * @param[in] action
20062 : : * The indirect action object to validate.
20063 : : * @param[out] error
20064 : : * Perform verbose error reporting if not NULL. Initialized in case of
20065 : : * error only.
20066 : : *
20067 : : * @return
20068 : : * 0 on success, otherwise negative errno value.
20069 : : */
20070 : : int
20071 : 0 : mlx5_flow_dv_action_validate(struct rte_eth_dev *dev,
20072 : : const struct rte_flow_indir_action_conf *conf,
20073 : : const struct rte_flow_action *action,
20074 : : struct rte_flow_error *err)
20075 : : {
20076 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
20077 : : /* called from RTE API */
20078 : :
20079 : : RTE_SET_USED(conf);
20080 [ # # # # : 0 : switch (action->type) {
# ]
20081 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
20082 : : /*
20083 : : * priv->obj_ops is set according to driver capabilities.
20084 : : * When DevX capabilities are
20085 : : * sufficient, it is set to mlx5_devx_obj_ops.
20086 : : * Otherwise, it is set to mlx5_ibv_obj_ops.
20087 : : * mlx5_ibv_obj_ops doesn't support ind_table_modify operation.
20088 : : * In this case the indirect RSS action can't be used.
20089 : : */
20090 [ # # ]: 0 : if (priv->obj_ops.ind_table_modify == NULL)
20091 : 0 : return rte_flow_error_set
20092 : : (err, ENOTSUP,
20093 : : RTE_FLOW_ERROR_TYPE_ACTION,
20094 : : NULL,
20095 : : "Indirect RSS action not supported");
20096 : 0 : return mlx5_validate_action_rss(dev, action, err);
20097 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
20098 [ # # ]: 0 : if (!priv->sh->aso_age_mng)
20099 : 0 : return rte_flow_error_set(err, ENOTSUP,
20100 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
20101 : : NULL,
20102 : : "Indirect age action not supported");
20103 : 0 : return flow_dv_validate_action_age(0, action, dev, err);
20104 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
20105 : 0 : return flow_dv_validate_action_count(dev, true, 0, false, err);
20106 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
20107 [ # # ]: 0 : if (!priv->sh->ct_aso_en)
20108 : 0 : return rte_flow_error_set(err, ENOTSUP,
20109 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
20110 : : "ASO CT is not supported");
20111 : 0 : return mlx5_validate_action_ct(dev, action->conf, err);
20112 : 0 : default:
20113 : 0 : return rte_flow_error_set(err, ENOTSUP,
20114 : : RTE_FLOW_ERROR_TYPE_ACTION,
20115 : : NULL,
20116 : : "action type not supported");
20117 : : }
20118 : : }
20119 : :
20120 : : /*
20121 : : * Check if the RSS configurations for colors of a meter policy match
20122 : : * each other, except the queues.
20123 : : *
20124 : : * @param[in] r1
20125 : : * Pointer to the first RSS flow action.
20126 : : * @param[in] r2
20127 : : * Pointer to the second RSS flow action.
20128 : : *
20129 : : * @return
20130 : : * 0 on match, 1 on conflict.
20131 : : */
20132 : : static inline int
20133 : 0 : flow_dv_mtr_policy_rss_compare(const struct rte_flow_action_rss *r1,
20134 : : const struct rte_flow_action_rss *r2)
20135 : : {
20136 [ # # ]: 0 : if (r1 == NULL || r2 == NULL)
20137 : : return 0;
20138 [ # # # # : 0 : if (!(r1->level <= 1 && r2->level <= 1) &&
# # ]
20139 [ # # ]: 0 : !(r1->level > 1 && r2->level > 1))
20140 : : return 1;
20141 [ # # ]: 0 : if (r1->func != r2->func)
20142 : : return 1;
20143 [ # # ]: 0 : if (r1->types != r2->types &&
20144 [ # # ]: 0 : !((r1->types == 0 || r1->types == RTE_ETH_RSS_IP) &&
20145 [ # # ]: 0 : (r2->types == 0 || r2->types == RTE_ETH_RSS_IP)))
20146 : : return 1;
20147 [ # # # # ]: 0 : if (r1->key || r2->key) {
20148 [ # # ]: 0 : const void *key1 = r1->key ? r1->key : mlx5_rss_hash_default_key;
20149 [ # # ]: 0 : const void *key2 = r2->key ? r2->key : mlx5_rss_hash_default_key;
20150 : :
20151 [ # # ]: 0 : if (memcmp(key1, key2, MLX5_RSS_HASH_KEY_LEN))
20152 : 0 : return 1;
20153 : : }
20154 : : return 0;
20155 : : }
20156 : :
20157 : : /**
20158 : : * Validate the meter hierarchy chain for meter policy.
20159 : : *
20160 : : * @param[in] dev
20161 : : * Pointer to the Ethernet device structure.
20162 : : * @param[in] meter_id
20163 : : * Meter id.
20164 : : * @param[in] action_flags
20165 : : * Holds the actions detected until now.
20166 : : * @param[out] is_rss
20167 : : * Is RSS or not.
20168 : : * @param[out] hierarchy_domain
20169 : : * The domain bitmap for hierarchy policy.
20170 : : * @param[out] error
20171 : : * Perform verbose error reporting if not NULL. Initialized in case of
20172 : : * error only.
20173 : : *
20174 : : * @return
20175 : : * 0 on success, otherwise negative errno value with error set.
20176 : : */
20177 : : static int
20178 : 0 : flow_dv_validate_policy_mtr_hierarchy(struct rte_eth_dev *dev,
20179 : : uint32_t meter_id,
20180 : : uint64_t action_flags,
20181 : : bool *is_rss,
20182 : : uint8_t *hierarchy_domain,
20183 : : struct rte_mtr_error *error)
20184 : : {
20185 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
20186 : : struct mlx5_flow_meter_info *fm;
20187 : : struct mlx5_flow_meter_policy *policy;
20188 : : uint8_t cnt = 1;
20189 : :
20190 [ # # ]: 0 : if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
20191 : : MLX5_FLOW_FATE_ESWITCH_ACTIONS))
20192 : 0 : return -rte_mtr_error_set(error, EINVAL,
20193 : : RTE_MTR_ERROR_TYPE_POLICER_ACTION_GREEN,
20194 : : NULL,
20195 : : "Multiple fate actions not supported.");
20196 : 0 : *hierarchy_domain = 0;
20197 : 0 : fm = mlx5_flow_meter_find(priv, meter_id, NULL);
20198 : : while (true) {
20199 [ # # ]: 0 : if (!fm)
20200 : 0 : return -rte_mtr_error_set(error, EINVAL,
20201 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
20202 : : "Meter not found in meter hierarchy.");
20203 [ # # ]: 0 : if (fm->def_policy)
20204 : 0 : return -rte_mtr_error_set(error, EINVAL,
20205 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
20206 : : "Non termination meter not supported in hierarchy.");
20207 [ # # ]: 0 : if (!fm->shared)
20208 : 0 : return -rte_mtr_error_set(error, EINVAL,
20209 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
20210 : : "Only shared meter supported in hierarchy.");
20211 : 0 : policy = mlx5_flow_meter_policy_find(dev, fm->policy_id, NULL);
20212 : : MLX5_ASSERT(policy);
20213 : : /**
20214 : : * Only inherit the supported domains of the first meter in
20215 : : * hierarchy.
20216 : : * One meter supports at least one domain.
20217 : : */
20218 [ # # ]: 0 : if (!*hierarchy_domain) {
20219 [ # # ]: 0 : if (policy->transfer)
20220 : 0 : *hierarchy_domain |=
20221 : : MLX5_MTR_DOMAIN_TRANSFER_BIT;
20222 [ # # ]: 0 : if (policy->ingress)
20223 : 0 : *hierarchy_domain |=
20224 : : MLX5_MTR_DOMAIN_INGRESS_BIT;
20225 [ # # ]: 0 : if (policy->egress)
20226 : 0 : *hierarchy_domain |= MLX5_MTR_DOMAIN_EGRESS_BIT;
20227 : : }
20228 [ # # ]: 0 : if (!policy->is_hierarchy) {
20229 : 0 : *is_rss = policy->is_rss;
20230 : : break;
20231 : : }
20232 : 0 : rte_spinlock_lock(&policy->sl);
20233 : 0 : fm = mlx5_flow_meter_hierarchy_next_meter(priv, policy, NULL);
20234 : : rte_spinlock_unlock(&policy->sl);
20235 [ # # ]: 0 : if (++cnt >= MLX5_MTR_CHAIN_MAX_NUM)
20236 : 0 : return -rte_mtr_error_set(error, EINVAL,
20237 : : RTE_MTR_ERROR_TYPE_METER_POLICY, NULL,
20238 : : "Exceed max hierarchy meter number.");
20239 : : }
20240 : 0 : return 0;
20241 : : }
20242 : :
20243 : : /**
20244 : : * Validate meter policy actions.
20245 : : * Dispatcher for action type specific validation.
20246 : : *
20247 : : * @param[in] dev
20248 : : * Pointer to the Ethernet device structure.
20249 : : * @param[in] action
20250 : : * The meter policy action object to validate.
20251 : : * @param[in] attr
20252 : : * Attributes of flow to determine steering domain.
20253 : : * @param[out] error
20254 : : * Perform verbose error reporting if not NULL. Initialized in case of
20255 : : * error only.
20256 : : *
20257 : : * @return
20258 : : * 0 on success, otherwise negative errno value.
20259 : : */
20260 : : static int
20261 : 0 : flow_dv_validate_mtr_policy_acts(struct rte_eth_dev *dev,
20262 : : const struct rte_flow_action *actions[RTE_COLORS],
20263 : : struct rte_flow_attr *attr,
20264 : : bool *is_rss,
20265 : : uint8_t *domain_bitmap,
20266 : : uint8_t *policy_mode,
20267 : : struct rte_mtr_error *error)
20268 : : {
20269 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
20270 : 0 : struct mlx5_sh_config *dev_conf = &priv->sh->config;
20271 : : const struct rte_flow_action *act;
20272 : 0 : uint64_t action_flags[RTE_COLORS] = {0};
20273 : : int actions_n;
20274 : : int i, ret;
20275 : : struct rte_flow_error flow_err;
20276 : 0 : uint8_t domain_color[RTE_COLORS] = {0};
20277 : : uint8_t def_domain = MLX5_MTR_ALL_DOMAIN_BIT;
20278 : 0 : uint8_t hierarchy_domain = 0;
20279 : : const struct rte_flow_action_meter *mtr;
20280 : : const struct rte_flow_action_meter *next_mtr = NULL;
20281 : : bool def_green = false;
20282 : : bool def_yellow = false;
20283 : 0 : const struct rte_flow_action_rss *rss_color[RTE_COLORS] = {NULL};
20284 : : /* Called from RTE API */
20285 [ # # # # : 0 : bool is_root = !(attr->group || (attr->transfer && priv->fdb_def_rule));
# # ]
20286 : :
20287 [ # # ]: 0 : if (!dev_conf->dv_esw_en)
20288 : : def_domain &= ~MLX5_MTR_DOMAIN_TRANSFER_BIT;
20289 : 0 : *domain_bitmap = def_domain;
20290 : : /* Red color could only support DROP action. */
20291 [ # # ]: 0 : if (!actions[RTE_COLOR_RED] ||
20292 [ # # ]: 0 : actions[RTE_COLOR_RED]->type != RTE_FLOW_ACTION_TYPE_DROP)
20293 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20294 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20295 : : NULL, "Red color only supports drop action.");
20296 : : /*
20297 : : * Check default policy actions:
20298 : : * Green / Yellow: no action, Red: drop action
20299 : : * Either G or Y will trigger default policy actions to be created.
20300 : : */
20301 [ # # ]: 0 : if (!actions[RTE_COLOR_GREEN] ||
20302 [ # # ]: 0 : actions[RTE_COLOR_GREEN]->type == RTE_FLOW_ACTION_TYPE_END)
20303 : : def_green = true;
20304 [ # # ]: 0 : if (!actions[RTE_COLOR_YELLOW] ||
20305 [ # # ]: 0 : actions[RTE_COLOR_YELLOW]->type == RTE_FLOW_ACTION_TYPE_END)
20306 : : def_yellow = true;
20307 [ # # ]: 0 : if (def_green && def_yellow) {
20308 : 0 : *policy_mode = MLX5_MTR_POLICY_MODE_DEF;
20309 : 0 : return 0;
20310 [ # # ]: 0 : } else if (!def_green && def_yellow) {
20311 : 0 : *policy_mode = MLX5_MTR_POLICY_MODE_OG;
20312 [ # # ]: 0 : } else if (def_green && !def_yellow) {
20313 : 0 : *policy_mode = MLX5_MTR_POLICY_MODE_OY;
20314 : : } else {
20315 : 0 : *policy_mode = MLX5_MTR_POLICY_MODE_ALL;
20316 : : }
20317 : : /* Set to empty string in case of NULL pointer access by user. */
20318 : 0 : flow_err.message = "";
20319 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
20320 : 0 : act = actions[i];
20321 : 0 : for (action_flags[i] = 0, actions_n = 0;
20322 [ # # # # ]: 0 : act && act->type != RTE_FLOW_ACTION_TYPE_END;
20323 : 0 : act++) {
20324 [ # # ]: 0 : if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
20325 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20326 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20327 : : NULL, "too many actions");
20328 [ # # # # : 0 : switch (act->type) {
# # # # #
# ]
20329 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
20330 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
20331 [ # # ]: 0 : if (!dev_conf->dv_esw_en)
20332 : 0 : return -rte_mtr_error_set(error,
20333 : : ENOTSUP,
20334 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20335 : : NULL, "PORT action validate check"
20336 : : " fail for ESW disable");
20337 : 0 : ret = flow_dv_validate_action_port_id(dev,
20338 : : action_flags[i],
20339 : : act, attr, &flow_err);
20340 [ # # ]: 0 : if (ret)
20341 : 0 : return -rte_mtr_error_set(error,
20342 : : ENOTSUP,
20343 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20344 [ # # ]: 0 : NULL, flow_err.message ?
20345 : : flow_err.message :
20346 : : "PORT action validate check fail");
20347 : 0 : ++actions_n;
20348 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_PORT_ID;
20349 : 0 : break;
20350 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
20351 : 0 : ret = flow_dv_validate_action_mark(dev, act,
20352 : : action_flags[i],
20353 : : attr, &flow_err);
20354 [ # # ]: 0 : if (ret < 0)
20355 : 0 : return -rte_mtr_error_set(error,
20356 : : ENOTSUP,
20357 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20358 [ # # ]: 0 : NULL, flow_err.message ?
20359 : : flow_err.message :
20360 : : "Mark action validate check fail");
20361 [ # # ]: 0 : if (dev_conf->dv_xmeta_en !=
20362 : : MLX5_XMETA_MODE_LEGACY)
20363 : 0 : return -rte_mtr_error_set(error,
20364 : : ENOTSUP,
20365 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20366 : : NULL, "Extend MARK action is "
20367 : : "not supported. Please try use "
20368 : : "default policy for meter.");
20369 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_MARK;
20370 : 0 : ++actions_n;
20371 : 0 : break;
20372 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TAG:
20373 : 0 : ret = flow_dv_validate_action_set_tag(dev,
20374 : : act, action_flags[i],
20375 : : attr, &flow_err);
20376 [ # # ]: 0 : if (ret)
20377 : 0 : return -rte_mtr_error_set(error,
20378 : : ENOTSUP,
20379 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20380 [ # # ]: 0 : NULL, flow_err.message ?
20381 : : flow_err.message :
20382 : : "Set tag action validate check fail");
20383 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_SET_TAG;
20384 : 0 : ++actions_n;
20385 : 0 : break;
20386 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
20387 : 0 : ret = mlx5_flow_validate_action_drop
20388 : : (dev, false, attr, &flow_err);
20389 [ # # ]: 0 : if (ret < 0)
20390 : 0 : return -rte_mtr_error_set(error,
20391 : : ENOTSUP,
20392 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20393 [ # # ]: 0 : NULL, flow_err.message ?
20394 : : flow_err.message :
20395 : : "Drop action validate check fail");
20396 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_DROP;
20397 : 0 : ++actions_n;
20398 : 0 : break;
20399 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
20400 : : /*
20401 : : * Check whether extensive
20402 : : * metadata feature is engaged.
20403 : : */
20404 [ # # ]: 0 : if (dev_conf->dv_flow_en &&
20405 [ # # ]: 0 : (dev_conf->dv_xmeta_en !=
20406 [ # # ]: 0 : MLX5_XMETA_MODE_LEGACY) &&
20407 : 0 : mlx5_flow_ext_mreg_supported(dev))
20408 : 0 : return -rte_mtr_error_set(error,
20409 : : ENOTSUP,
20410 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20411 : : NULL, "Queue action with meta "
20412 : : "is not supported. Please try use "
20413 : : "default policy for meter.");
20414 : 0 : ret = mlx5_flow_validate_action_queue(act,
20415 : : action_flags[i], dev,
20416 : : attr, &flow_err);
20417 [ # # ]: 0 : if (ret < 0)
20418 : 0 : return -rte_mtr_error_set(error,
20419 : : ENOTSUP,
20420 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20421 [ # # ]: 0 : NULL, flow_err.message ?
20422 : : flow_err.message :
20423 : : "Queue action validate check fail");
20424 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_QUEUE;
20425 : 0 : ++actions_n;
20426 : 0 : break;
20427 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
20428 [ # # ]: 0 : if (dev_conf->dv_flow_en &&
20429 [ # # ]: 0 : (dev_conf->dv_xmeta_en !=
20430 [ # # ]: 0 : MLX5_XMETA_MODE_LEGACY) &&
20431 : 0 : mlx5_flow_ext_mreg_supported(dev))
20432 : 0 : return -rte_mtr_error_set(error,
20433 : : ENOTSUP,
20434 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20435 : : NULL, "RSS action with meta "
20436 : : "is not supported. Please try use "
20437 : : "default policy for meter.");
20438 : 0 : ret = mlx5_validate_action_rss(dev, act,
20439 : : &flow_err);
20440 [ # # ]: 0 : if (ret < 0)
20441 : 0 : return -rte_mtr_error_set(error,
20442 : : ENOTSUP,
20443 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20444 [ # # ]: 0 : NULL, flow_err.message ?
20445 : : flow_err.message :
20446 : : "RSS action validate check fail");
20447 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_RSS;
20448 : 0 : ++actions_n;
20449 : : /* Either G or Y will set the RSS. */
20450 : 0 : rss_color[i] = act->conf;
20451 : 0 : break;
20452 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
20453 : 0 : ret = flow_dv_validate_action_jump(dev,
20454 : : NULL, act, action_flags[i],
20455 : : attr, true, &flow_err);
20456 [ # # ]: 0 : if (ret)
20457 : 0 : return -rte_mtr_error_set(error,
20458 : : ENOTSUP,
20459 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20460 [ # # ]: 0 : NULL, flow_err.message ?
20461 : : flow_err.message :
20462 : : "Jump action validate check fail");
20463 : 0 : ++actions_n;
20464 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_JUMP;
20465 : 0 : break;
20466 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
20467 : 0 : mtr = act->conf;
20468 [ # # # # ]: 0 : if (next_mtr && next_mtr->mtr_id != mtr->mtr_id)
20469 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20470 : : RTE_MTR_ERROR_TYPE_METER_POLICY, NULL,
20471 : : "Green and Yellow must use the same meter.");
20472 : 0 : ret = flow_dv_validate_policy_mtr_hierarchy(dev,
20473 : 0 : mtr->mtr_id,
20474 : : action_flags[i],
20475 : : is_rss,
20476 : : &hierarchy_domain,
20477 : : error);
20478 [ # # ]: 0 : if (ret)
20479 : 0 : return ret;
20480 : 0 : ++actions_n;
20481 : 0 : action_flags[i] |=
20482 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
20483 : : next_mtr = mtr;
20484 : 0 : break;
20485 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
20486 : 0 : ret = flow_dv_validate_action_modify_field(dev,
20487 : : action_flags[i], act, attr, is_root, &flow_err);
20488 [ # # ]: 0 : if (ret < 0)
20489 : 0 : return -rte_mtr_error_set(error,
20490 : : ENOTSUP,
20491 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20492 [ # # ]: 0 : NULL, flow_err.message ?
20493 : : flow_err.message :
20494 : : "Modify field action validate check fail");
20495 : 0 : ++actions_n;
20496 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_MODIFY_FIELD;
20497 : 0 : break;
20498 : : default:
20499 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20500 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20501 : : NULL,
20502 : : "Doesn't support optional action");
20503 : : }
20504 : : }
20505 [ # # ]: 0 : if (action_flags[i] & MLX5_FLOW_ACTION_PORT_ID) {
20506 : 0 : domain_color[i] = MLX5_MTR_DOMAIN_TRANSFER_BIT;
20507 [ # # ]: 0 : } else if ((action_flags[i] &
20508 : 0 : (MLX5_FLOW_ACTION_RSS | MLX5_FLOW_ACTION_QUEUE)) ||
20509 [ # # ]: 0 : (action_flags[i] & MLX5_FLOW_ACTION_MARK)) {
20510 : : /*
20511 : : * Only support MLX5_XMETA_MODE_LEGACY
20512 : : * so MARK action is only in ingress domain.
20513 : : */
20514 : 0 : domain_color[i] = MLX5_MTR_DOMAIN_INGRESS_BIT;
20515 : : } else {
20516 : 0 : domain_color[i] = def_domain;
20517 [ # # ]: 0 : if (action_flags[i] &&
20518 [ # # ]: 0 : !(action_flags[i] & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
20519 : 0 : domain_color[i] &=
20520 : : ~MLX5_MTR_DOMAIN_TRANSFER_BIT;
20521 : : }
20522 [ # # ]: 0 : if (action_flags[i] &
20523 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
20524 : 0 : domain_color[i] &= hierarchy_domain;
20525 : : /*
20526 : : * Non-termination actions only support NIC Tx domain.
20527 : : * The adjustion should be skipped when there is no
20528 : : * action or only END is provided. The default domains
20529 : : * bit-mask is set to find the MIN intersection.
20530 : : * The action flags checking should also be skipped.
20531 : : */
20532 [ # # ]: 0 : if ((def_green && i == RTE_COLOR_GREEN) ||
20533 [ # # ]: 0 : (def_yellow && i == RTE_COLOR_YELLOW))
20534 : 0 : continue;
20535 : : /*
20536 : : * Validate the drop action mutual exclusion
20537 : : * with other actions. Drop action is mutually-exclusive
20538 : : * with any other action, except for Count action.
20539 : : */
20540 [ # # ]: 0 : if ((action_flags[i] & MLX5_FLOW_ACTION_DROP) &&
20541 [ # # ]: 0 : (action_flags[i] & ~MLX5_FLOW_ACTION_DROP)) {
20542 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20543 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20544 : : NULL, "Drop action is mutually-exclusive "
20545 : : "with any other action");
20546 : : }
20547 : : /* Eswitch has few restrictions on using items and actions */
20548 [ # # ]: 0 : if (domain_color[i] & MLX5_MTR_DOMAIN_TRANSFER_BIT) {
20549 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev) &&
20550 [ # # ]: 0 : action_flags[i] & MLX5_FLOW_ACTION_MARK)
20551 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20552 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20553 : : NULL, "unsupported action MARK");
20554 [ # # ]: 0 : if (action_flags[i] & MLX5_FLOW_ACTION_QUEUE)
20555 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20556 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20557 : : NULL, "unsupported action QUEUE");
20558 [ # # ]: 0 : if (action_flags[i] & MLX5_FLOW_ACTION_RSS)
20559 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20560 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20561 : : NULL, "unsupported action RSS");
20562 [ # # ]: 0 : if (!(action_flags[i] & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
20563 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20564 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20565 : : NULL, "no fate action is found");
20566 : : } else {
20567 [ # # # # ]: 0 : if (!(action_flags[i] & MLX5_FLOW_FATE_ACTIONS) &&
20568 : : (domain_color[i] & MLX5_MTR_DOMAIN_INGRESS_BIT)) {
20569 [ # # ]: 0 : if ((domain_color[i] &
20570 : : MLX5_MTR_DOMAIN_EGRESS_BIT))
20571 : 0 : domain_color[i] =
20572 : : MLX5_MTR_DOMAIN_EGRESS_BIT;
20573 : : else
20574 : 0 : return -rte_mtr_error_set(error,
20575 : : ENOTSUP,
20576 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20577 : : NULL,
20578 : : "no fate action is found");
20579 : : }
20580 : : }
20581 : : }
20582 [ # # # # ]: 0 : if (next_mtr && *policy_mode == MLX5_MTR_POLICY_MODE_ALL) {
20583 : : uint64_t hierarchy_type_flag =
20584 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY | MLX5_FLOW_ACTION_JUMP;
20585 [ # # ]: 0 : if (!(action_flags[RTE_COLOR_GREEN] & hierarchy_type_flag) ||
20586 [ # # ]: 0 : !(action_flags[RTE_COLOR_YELLOW] & hierarchy_type_flag))
20587 : 0 : return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_METER_POLICY,
20588 : : NULL,
20589 : : "Unsupported action in meter hierarchy.");
20590 : : }
20591 : : /* If both colors have RSS, the attributes should be the same. */
20592 [ # # ]: 0 : if (flow_dv_mtr_policy_rss_compare(rss_color[RTE_COLOR_GREEN],
20593 : : rss_color[RTE_COLOR_YELLOW]))
20594 : 0 : return -rte_mtr_error_set(error, EINVAL,
20595 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20596 : : NULL, "policy RSS attr conflict");
20597 [ # # # # ]: 0 : if (rss_color[RTE_COLOR_GREEN] || rss_color[RTE_COLOR_YELLOW])
20598 : 0 : *is_rss = true;
20599 : : /* "domain_color[C]" is non-zero for each color, default is ALL. */
20600 [ # # ]: 0 : if (!def_green && !def_yellow &&
20601 [ # # ]: 0 : domain_color[RTE_COLOR_GREEN] != domain_color[RTE_COLOR_YELLOW] &&
20602 [ # # ]: 0 : !(action_flags[RTE_COLOR_GREEN] & MLX5_FLOW_ACTION_DROP) &&
20603 [ # # ]: 0 : !(action_flags[RTE_COLOR_YELLOW] & MLX5_FLOW_ACTION_DROP))
20604 : 0 : return -rte_mtr_error_set(error, EINVAL,
20605 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20606 : : NULL, "policy domains conflict");
20607 : : /*
20608 : : * At least one color policy is listed in the actions, the domains
20609 : : * to be supported should be the intersection.
20610 : : */
20611 : 0 : *domain_bitmap = domain_color[RTE_COLOR_GREEN] &
20612 : 0 : domain_color[RTE_COLOR_YELLOW];
20613 : 0 : return 0;
20614 : : }
20615 : :
20616 : : static int
20617 : 0 : flow_dv_sync_domain(struct rte_eth_dev *dev, uint32_t domains, uint32_t flags)
20618 : : {
20619 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
20620 : : int ret = 0;
20621 : :
20622 [ # # # # ]: 0 : if ((domains & RTE_PMD_MLX5_DOMAIN_BIT_NIC_RX) && priv->sh->rx_domain != NULL) {
20623 : : ret = mlx5_os_flow_dr_sync_domain(priv->sh->rx_domain,
20624 : : flags);
20625 [ # # ]: 0 : if (ret != 0)
20626 : : return ret;
20627 : : }
20628 [ # # # # ]: 0 : if ((domains & RTE_PMD_MLX5_DOMAIN_BIT_NIC_TX) && priv->sh->tx_domain != NULL) {
20629 : : ret = mlx5_os_flow_dr_sync_domain(priv->sh->tx_domain, flags);
20630 [ # # ]: 0 : if (ret != 0)
20631 : : return ret;
20632 : : }
20633 [ # # # # ]: 0 : if ((domains & RTE_PMD_MLX5_DOMAIN_BIT_FDB) && priv->sh->fdb_domain != NULL) {
20634 : : ret = mlx5_os_flow_dr_sync_domain(priv->sh->fdb_domain, flags);
20635 [ # # ]: 0 : if (ret != 0)
20636 : 0 : return ret;
20637 : : }
20638 : : return 0;
20639 : : }
20640 : :
20641 : : /**
20642 : : * Discover the number of available flow priorities
20643 : : * by trying to create a flow with the highest priority value
20644 : : * for each possible number.
20645 : : *
20646 : : * @param[in] dev
20647 : : * Ethernet device.
20648 : : * @param[in] vprio
20649 : : * List of possible number of available priorities.
20650 : : * @param[in] vprio_n
20651 : : * Size of @p vprio array.
20652 : : * @return
20653 : : * On success, number of available flow priorities.
20654 : : * On failure, a negative errno-style code and rte_errno is set.
20655 : : */
20656 : : static int
20657 : 0 : flow_dv_discover_priorities(struct rte_eth_dev *dev,
20658 : : const uint16_t *vprio, int vprio_n)
20659 : : {
20660 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
20661 : 0 : struct mlx5_indexed_pool *pool = priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW];
20662 : : struct rte_flow_item_eth eth;
20663 : 0 : struct rte_flow_item item = {
20664 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
20665 : : .spec = ð,
20666 : : .mask = ð,
20667 : : };
20668 : 0 : struct mlx5_flow_dv_matcher matcher = {
20669 : : .mask = {
20670 : : .size = sizeof(matcher.mask.buf),
20671 : : },
20672 : : };
20673 : : union mlx5_flow_tbl_key tbl_key;
20674 : : struct mlx5_flow flow;
20675 : : void *action;
20676 : : struct rte_flow_error error;
20677 : : uint8_t misc_mask;
20678 : : int i, err, ret = -ENOTSUP;
20679 : :
20680 : : /*
20681 : : * Prepare a flow with a catch-all pattern and a drop action.
20682 : : * Use drop queue, because shared drop action may be unavailable.
20683 : : */
20684 : 0 : action = priv->drop_queue.hrxq->action;
20685 [ # # ]: 0 : if (action == NULL) {
20686 : 0 : DRV_LOG(ERR, "Priority discovery requires a drop action");
20687 : 0 : rte_errno = ENOTSUP;
20688 : 0 : return -rte_errno;
20689 : : }
20690 : : memset(&flow, 0, sizeof(flow));
20691 : 0 : flow.handle = mlx5_ipool_zmalloc(pool, &flow.handle_idx);
20692 [ # # ]: 0 : if (flow.handle == NULL) {
20693 : 0 : DRV_LOG(ERR, "Cannot create flow handle");
20694 : 0 : rte_errno = ENOMEM;
20695 : 0 : return -rte_errno;
20696 : : }
20697 : 0 : flow.ingress = true;
20698 : 0 : flow.dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param);
20699 : 0 : flow.dv.actions[0] = action;
20700 : 0 : flow.dv.actions_n = 1;
20701 : : memset(ð, 0, sizeof(eth));
20702 : : memset(ð.hdr.dst_addr, 0xff, sizeof(eth.hdr.dst_addr));
20703 : : memset(ð.hdr.src_addr, 0xff, sizeof(eth.hdr.src_addr));
20704 : 0 : flow_dv_translate_item_eth(matcher.mask.buf, &item,
20705 : : /* inner */ false, /* group */ 0,
20706 : : MLX5_SET_MATCHER_SW_M);
20707 : 0 : flow_dv_translate_item_eth(flow.dv.value.buf, &item,
20708 : : /* inner */ false, /* group */ 0,
20709 : : MLX5_SET_MATCHER_SW_V);
20710 : 0 : matcher.crc = rte_raw_cksum(matcher.mask.buf, matcher.mask.size);
20711 [ # # ]: 0 : for (i = 0; i < vprio_n; i++) {
20712 : : /* Configure the next proposed maximum priority. */
20713 : 0 : matcher.priority = vprio[i] - 1;
20714 : : memset(&tbl_key, 0, sizeof(tbl_key));
20715 : 0 : err = flow_dv_matcher_register(dev, &matcher, &tbl_key, &flow,
20716 : : /* tunnel */ NULL,
20717 : : /* group */ 0,
20718 : : &error);
20719 [ # # ]: 0 : if (err != 0) {
20720 : : /* This action is pure SW and must always succeed. */
20721 : 0 : DRV_LOG(ERR, "Cannot register matcher");
20722 : 0 : ret = -rte_errno;
20723 : 0 : break;
20724 : : }
20725 : : /* Try to apply the flow to HW. */
20726 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(flow.handle->dvh.matcher->mask.buf);
20727 : : __flow_dv_adjust_buf_size(&flow.dv.value.size, misc_mask);
20728 : 0 : err = mlx5_flow_os_create_flow
20729 : : (flow.handle->dvh.matcher->matcher_object,
20730 : 0 : (void *)&flow.dv.value, flow.dv.actions_n,
20731 : : flow.dv.actions, &flow.handle->drv_flow);
20732 : : if (err == 0) {
20733 : 0 : claim_zero(mlx5_flow_os_destroy_flow
20734 : : (flow.handle->drv_flow));
20735 : 0 : flow.handle->drv_flow = NULL;
20736 : : }
20737 : 0 : claim_zero(flow_dv_matcher_release(dev, flow.handle));
20738 [ # # ]: 0 : if (err != 0)
20739 : : break;
20740 : 0 : ret = vprio[i];
20741 : : }
20742 : 0 : mlx5_ipool_free(pool, flow.handle_idx);
20743 : : /* Set rte_errno if no expected priority value matched. */
20744 [ # # ]: 0 : if (ret < 0)
20745 : 0 : rte_errno = -ret;
20746 : : return ret;
20747 : : }
20748 : :
20749 : : const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops = {
20750 : : .list_create = mlx5_flow_legacy_list_create,
20751 : : .list_destroy = mlx5_flow_legacy_list_destroy,
20752 : : .validate = mlx5_flow_dv_validate,
20753 : : .prepare = flow_dv_prepare,
20754 : : .translate = flow_dv_translate,
20755 : : .apply = flow_dv_apply,
20756 : : .remove = flow_dv_remove,
20757 : : .destroy = flow_dv_destroy,
20758 : : .query = flow_dv_query,
20759 : : .create_mtr_tbls = flow_dv_create_mtr_tbls,
20760 : : .destroy_mtr_tbls = flow_dv_destroy_mtr_tbls,
20761 : : .destroy_mtr_drop_tbls = flow_dv_destroy_mtr_drop_tbls,
20762 : : .create_meter = flow_dv_mtr_alloc,
20763 : : .free_meter = flow_dv_aso_mtr_release_to_pool,
20764 : : .validate_mtr_acts = flow_dv_validate_mtr_policy_acts,
20765 : : .create_mtr_acts = flow_dv_create_mtr_policy_acts,
20766 : : .destroy_mtr_acts = flow_dv_destroy_mtr_policy_acts,
20767 : : .create_policy_rules = flow_dv_create_policy_rules,
20768 : : .destroy_policy_rules = flow_dv_destroy_policy_rules,
20769 : : .create_def_policy = flow_dv_create_def_policy,
20770 : : .destroy_def_policy = flow_dv_destroy_def_policy,
20771 : : .meter_sub_policy_rss_prepare = flow_dv_meter_sub_policy_rss_prepare,
20772 : : .meter_hierarchy_rule_create = flow_dv_meter_hierarchy_rule_create,
20773 : : .destroy_sub_policy_with_rxq = flow_dv_destroy_sub_policy_with_rxq,
20774 : : .counter_alloc = flow_dv_counter_allocate,
20775 : : .counter_free = flow_dv_counter_free,
20776 : : .counter_query = flow_dv_counter_query,
20777 : : .get_aged_flows = flow_dv_get_aged_flows,
20778 : : .action_validate = mlx5_flow_dv_action_validate,
20779 : : .action_create = mlx5_flow_dv_action_create,
20780 : : .action_destroy = mlx5_flow_dv_action_destroy,
20781 : : .action_update = mlx5_flow_dv_action_update,
20782 : : .action_query = mlx5_flow_dv_action_query,
20783 : : .sync_domain = flow_dv_sync_domain,
20784 : : .discover_priorities = flow_dv_discover_priorities,
20785 : : .item_create = mlx5_flow_dv_item_create,
20786 : : .item_release = mlx5_flow_dv_item_release,
20787 : : };
20788 : :
20789 : : #endif /* HAVE_IBV_FLOW_DV_SUPPORT */
|