Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright 2018 Mellanox Technologies, Ltd
3 : : */
4 : :
5 : : #include <sys/queue.h>
6 : : #include <stdalign.h>
7 : : #include <stdint.h>
8 : : #include <string.h>
9 : : #include <unistd.h>
10 : :
11 : : #include <rte_bitops.h>
12 : : #include <rte_common.h>
13 : : #include <rte_ether.h>
14 : : #include <ethdev_driver.h>
15 : : #include <rte_flow.h>
16 : : #include <rte_flow_driver.h>
17 : : #include <rte_malloc.h>
18 : : #include <rte_cycles.h>
19 : : #include <bus_pci_driver.h>
20 : : #include <rte_ip.h>
21 : : #include <rte_gre.h>
22 : : #include <rte_vxlan.h>
23 : : #include <rte_gtp.h>
24 : : #include <rte_eal_paging.h>
25 : : #include <rte_mpls.h>
26 : : #include <rte_mtr.h>
27 : : #include <rte_mtr_driver.h>
28 : : #include <rte_tailq.h>
29 : :
30 : : #include <mlx5_glue.h>
31 : : #include <mlx5_devx_cmds.h>
32 : : #include <mlx5_prm.h>
33 : : #include <mlx5_malloc.h>
34 : :
35 : : #include "mlx5_defs.h"
36 : : #include "mlx5.h"
37 : : #include "mlx5_common_os.h"
38 : : #include "mlx5_flow.h"
39 : : #include "mlx5_flow_os.h"
40 : : #include "mlx5_rx.h"
41 : : #include "mlx5_tx.h"
42 : : #include "rte_pmd_mlx5.h"
43 : :
44 : : #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
45 : :
46 : : #ifndef HAVE_IBV_FLOW_DEVX_COUNTERS
47 : : #define MLX5DV_FLOW_ACTION_COUNTERS_DEVX 0
48 : : #endif
49 : :
50 : : #ifndef HAVE_MLX5DV_DR_ESWITCH
51 : : #ifndef MLX5DV_FLOW_TABLE_TYPE_FDB
52 : : #define MLX5DV_FLOW_TABLE_TYPE_FDB 0
53 : : #endif
54 : : #endif
55 : :
56 : : #ifndef HAVE_MLX5DV_DR
57 : : #define MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL 1
58 : : #endif
59 : :
60 : : /* VLAN header definitions */
61 : : #define MLX5DV_FLOW_VLAN_PCP_SHIFT 13
62 : : #define MLX5DV_FLOW_VLAN_PCP_MASK (0x7 << MLX5DV_FLOW_VLAN_PCP_SHIFT)
63 : : #define MLX5DV_FLOW_VLAN_VID_MASK 0x0fff
64 : : #define MLX5DV_FLOW_VLAN_PCP_MASK_BE RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK)
65 : : #define MLX5DV_FLOW_VLAN_VID_MASK_BE RTE_BE16(MLX5DV_FLOW_VLAN_VID_MASK)
66 : :
67 : : #define MLX5_ITEM_VALID(item, key_type) \
68 : : (((MLX5_SET_MATCHER_SW & (key_type)) && !((item)->spec)) || \
69 : : ((MLX5_SET_MATCHER_HS_V == (key_type)) && !((item)->spec)) || \
70 : : ((MLX5_SET_MATCHER_HS_M == (key_type)) && !((item)->mask)))
71 : :
72 : : #define MLX5_ITEM_UPDATE(item, key_type, v, m, gm) \
73 : : do { \
74 : : if ((key_type) == MLX5_SET_MATCHER_SW_V) { \
75 : : v = (item)->spec; \
76 : : m = (item)->mask ? (item)->mask : (gm); \
77 : : } else if ((key_type) == MLX5_SET_MATCHER_HS_V) { \
78 : : v = (item)->spec; \
79 : : m = (v); \
80 : : } else { \
81 : : v = (item)->mask ? (item)->mask : (gm); \
82 : : m = (v); \
83 : : } \
84 : : } while (0)
85 : :
86 : : #define CALC_MODI_ID(field, level) \
87 : : (((level) > 1) ? MLX5_MODI_IN_##field : MLX5_MODI_OUT_##field)
88 : :
89 : : union flow_dv_attr {
90 : : struct {
91 : : uint32_t valid:1;
92 : : uint32_t ipv4:1;
93 : : uint32_t ipv6:1;
94 : : uint32_t tcp:1;
95 : : uint32_t udp:1;
96 : : uint32_t reserved:27;
97 : : };
98 : : uint32_t attr;
99 : : };
100 : :
101 : : static int
102 : : flow_dv_port_id_action_resource_release(struct rte_eth_dev *dev,
103 : : uint32_t port_id);
104 : : static void
105 : : flow_dv_shared_rss_action_release(struct rte_eth_dev *dev, uint32_t srss);
106 : :
107 : : static int
108 : : flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev,
109 : : uint32_t rix_jump);
110 : :
111 : : /**
112 : : * Initialize flow attributes structure according to flow items' types.
113 : : *
114 : : * flow_dv_validate() avoids multiple L3/L4 layers cases other than tunnel
115 : : * mode. For tunnel mode, the items to be modified are the outermost ones.
116 : : *
117 : : * @param[in] item
118 : : * Pointer to item specification.
119 : : * @param[out] attr
120 : : * Pointer to flow attributes structure.
121 : : * @param[in] dev_flow
122 : : * Pointer to the sub flow.
123 : : * @param[in] tunnel_decap
124 : : * Whether action is after tunnel decapsulation.
125 : : */
126 : : static void
127 : 0 : flow_dv_attr_init(const struct rte_flow_item *item, union flow_dv_attr *attr,
128 : : struct mlx5_flow *dev_flow, bool tunnel_decap)
129 : : {
130 : 0 : uint64_t layers = dev_flow->handle->layers;
131 : : bool tunnel_match = false;
132 : :
133 : : /*
134 : : * If layers is already initialized, it means this dev_flow is the
135 : : * suffix flow, the layers flags is set by the prefix flow. Need to
136 : : * use the layer flags from prefix flow as the suffix flow may not
137 : : * have the user defined items as the flow is split.
138 : : */
139 [ # # ]: 0 : if (layers) {
140 [ # # ]: 0 : if (tunnel_decap) {
141 : : /*
142 : : * If decap action before modify, it means the driver
143 : : * should take the inner as outer for the modify actions.
144 : : */
145 : 0 : layers = ((layers >> 6) & MLX5_FLOW_LAYER_OUTER);
146 : : }
147 [ # # ]: 0 : if (layers & MLX5_FLOW_LAYER_OUTER_L3_IPV4)
148 : 0 : attr->ipv4 = 1;
149 [ # # ]: 0 : else if (layers & MLX5_FLOW_LAYER_OUTER_L3_IPV6)
150 : 0 : attr->ipv6 = 1;
151 [ # # ]: 0 : if (layers & MLX5_FLOW_LAYER_OUTER_L4_TCP)
152 : 0 : attr->tcp = 1;
153 [ # # ]: 0 : else if (layers & MLX5_FLOW_LAYER_OUTER_L4_UDP)
154 : 0 : attr->udp = 1;
155 : 0 : attr->valid = 1;
156 : 0 : return;
157 : : }
158 [ # # ]: 0 : for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
159 : : uint8_t next_protocol = 0xff;
160 [ # # # # : 0 : switch (item->type) {
# # ]
161 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
162 : : case RTE_FLOW_ITEM_TYPE_NVGRE:
163 : : case RTE_FLOW_ITEM_TYPE_VXLAN:
164 : : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
165 : : case RTE_FLOW_ITEM_TYPE_GENEVE:
166 : : case RTE_FLOW_ITEM_TYPE_MPLS:
167 : : case RTE_FLOW_ITEM_TYPE_GTP:
168 [ # # ]: 0 : if (tunnel_decap) {
169 : 0 : attr->attr = 0;
170 : : tunnel_match = true;
171 : : }
172 : : break;
173 : 0 : case RTE_FLOW_ITEM_TYPE_IPV4:
174 [ # # ]: 0 : if (!attr->ipv6)
175 : 0 : attr->ipv4 = 1;
176 [ # # ]: 0 : if (item->mask != NULL &&
177 : : ((const struct rte_flow_item_ipv4 *)
178 [ # # ]: 0 : item->mask)->hdr.next_proto_id)
179 : 0 : next_protocol =
180 : : ((const struct rte_flow_item_ipv4 *)
181 : 0 : (item->spec))->hdr.next_proto_id &
182 : : ((const struct rte_flow_item_ipv4 *)
183 : : (item->mask))->hdr.next_proto_id;
184 : 0 : if ((next_protocol == IPPROTO_IPIP ||
185 [ # # ]: 0 : next_protocol == IPPROTO_IPV6) && tunnel_decap &&
186 [ # # ]: 0 : !tunnel_match)
187 : 0 : attr->attr = 0;
188 : : break;
189 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6:
190 [ # # ]: 0 : if (!attr->ipv4)
191 : 0 : attr->ipv6 = 1;
192 [ # # ]: 0 : if (item->mask != NULL &&
193 : : ((const struct rte_flow_item_ipv6 *)
194 [ # # ]: 0 : item->mask)->hdr.proto)
195 : 0 : next_protocol =
196 : : ((const struct rte_flow_item_ipv6 *)
197 : 0 : (item->spec))->hdr.proto &
198 : : ((const struct rte_flow_item_ipv6 *)
199 : : (item->mask))->hdr.proto;
200 : 0 : if ((next_protocol == IPPROTO_IPIP ||
201 [ # # ]: 0 : next_protocol == IPPROTO_IPV6) && tunnel_decap &&
202 [ # # ]: 0 : !tunnel_match)
203 : 0 : attr->attr = 0;
204 : : break;
205 : 0 : case RTE_FLOW_ITEM_TYPE_UDP:
206 [ # # ]: 0 : if (!attr->tcp)
207 : 0 : attr->udp = 1;
208 : : break;
209 : 0 : case RTE_FLOW_ITEM_TYPE_TCP:
210 [ # # ]: 0 : if (!attr->udp)
211 : 0 : attr->tcp = 1;
212 : : break;
213 : : default:
214 : : break;
215 : : }
216 : : }
217 : 0 : attr->valid = 1;
218 : : }
219 : :
220 : : struct field_modify_info modify_eth[] = {
221 : : {4, 0, MLX5_MODI_OUT_DMAC_47_16},
222 : : {2, 4, MLX5_MODI_OUT_DMAC_15_0},
223 : : {4, 6, MLX5_MODI_OUT_SMAC_47_16},
224 : : {2, 10, MLX5_MODI_OUT_SMAC_15_0},
225 : : {0, 0, 0},
226 : : };
227 : :
228 : : struct field_modify_info modify_vlan_out_first_vid[] = {
229 : : /* Size in bits !!! */
230 : : {12, 0, MLX5_MODI_OUT_FIRST_VID},
231 : : {0, 0, 0},
232 : : };
233 : :
234 : : struct field_modify_info modify_ipv4[] = {
235 : : {1, 1, MLX5_MODI_OUT_IP_DSCP},
236 : : {1, 8, MLX5_MODI_OUT_IPV4_TTL},
237 : : {4, 12, MLX5_MODI_OUT_SIPV4},
238 : : {4, 16, MLX5_MODI_OUT_DIPV4},
239 : : {0, 0, 0},
240 : : };
241 : :
242 : : struct field_modify_info modify_ipv6[] = {
243 : : {1, 0, MLX5_MODI_OUT_IP_DSCP},
244 : : {1, 7, MLX5_MODI_OUT_IPV6_HOPLIMIT},
245 : : {4, 8, MLX5_MODI_OUT_SIPV6_127_96},
246 : : {4, 12, MLX5_MODI_OUT_SIPV6_95_64},
247 : : {4, 16, MLX5_MODI_OUT_SIPV6_63_32},
248 : : {4, 20, MLX5_MODI_OUT_SIPV6_31_0},
249 : : {4, 24, MLX5_MODI_OUT_DIPV6_127_96},
250 : : {4, 28, MLX5_MODI_OUT_DIPV6_95_64},
251 : : {4, 32, MLX5_MODI_OUT_DIPV6_63_32},
252 : : {4, 36, MLX5_MODI_OUT_DIPV6_31_0},
253 : : {0, 0, 0},
254 : : };
255 : :
256 : : struct field_modify_info modify_ipv6_traffic_class[] = {
257 : : {1, 0, MLX5_MODI_OUT_IPV6_TRAFFIC_CLASS},
258 : : {0, 0, 0},
259 : : };
260 : :
261 : : struct field_modify_info modify_udp[] = {
262 : : {2, 0, MLX5_MODI_OUT_UDP_SPORT},
263 : : {2, 2, MLX5_MODI_OUT_UDP_DPORT},
264 : : {0, 0, 0},
265 : : };
266 : :
267 : : struct field_modify_info modify_tcp[] = {
268 : : {2, 0, MLX5_MODI_OUT_TCP_SPORT},
269 : : {2, 2, MLX5_MODI_OUT_TCP_DPORT},
270 : : {4, 4, MLX5_MODI_OUT_TCP_SEQ_NUM},
271 : : {4, 8, MLX5_MODI_OUT_TCP_ACK_NUM},
272 : : {0, 0, 0},
273 : : };
274 : :
275 : : enum mlx5_l3_tunnel_detection {
276 : : l3_tunnel_none,
277 : : l3_tunnel_outer,
278 : : l3_tunnel_inner
279 : : };
280 : :
281 : : static enum mlx5_l3_tunnel_detection
282 : : mlx5_flow_tunnel_ip_check(const struct rte_flow_item *item __rte_unused,
283 : : uint8_t next_protocol, uint64_t item_flags,
284 : : uint64_t *l3_tunnel_flag)
285 : : {
286 : : enum mlx5_l3_tunnel_detection td = l3_tunnel_none;
287 : :
288 : : MLX5_ASSERT(item->type == RTE_FLOW_ITEM_TYPE_IPV4 ||
289 : : item->type == RTE_FLOW_ITEM_TYPE_IPV6);
290 [ # # # # : 0 : if ((item_flags & MLX5_FLOW_LAYER_OUTER_L3) == 0) {
# # # # ]
291 [ # # # # : 0 : switch (next_protocol) {
# # # # #
# # # ]
292 : : case IPPROTO_IPIP:
293 : : td = l3_tunnel_outer;
294 : : *l3_tunnel_flag = MLX5_FLOW_LAYER_IPIP;
295 : : break;
296 : : case IPPROTO_IPV6:
297 : : td = l3_tunnel_outer;
298 : : *l3_tunnel_flag = MLX5_FLOW_LAYER_IPV6_ENCAP;
299 : : break;
300 : : default:
301 : : break;
302 : : }
303 : : } else {
304 : : td = l3_tunnel_inner;
305 : : *l3_tunnel_flag = item->type == RTE_FLOW_ITEM_TYPE_IPV4 ?
306 : : MLX5_FLOW_LAYER_IPIP :
307 : : MLX5_FLOW_LAYER_IPV6_ENCAP;
308 : : }
309 : : return td;
310 : : }
311 : :
312 : : static inline struct mlx5_hlist *
313 : 0 : flow_dv_hlist_prepare(struct mlx5_dev_ctx_shared *sh, RTE_ATOMIC(struct mlx5_hlist *) *phl,
314 : : const char *name, uint32_t size, bool direct_key,
315 : : bool lcores_share, void *ctx,
316 : : mlx5_list_create_cb cb_create,
317 : : mlx5_list_match_cb cb_match,
318 : : mlx5_list_remove_cb cb_remove,
319 : : mlx5_list_clone_cb cb_clone,
320 : : mlx5_list_clone_free_cb cb_clone_free,
321 : : struct rte_flow_error *error)
322 : : {
323 : : struct mlx5_hlist *hl;
324 : : struct mlx5_hlist *expected = NULL;
325 : : char s[MLX5_NAME_SIZE];
326 : :
327 : 0 : hl = rte_atomic_load_explicit(phl, rte_memory_order_seq_cst);
328 [ # # ]: 0 : if (likely(hl))
329 : : return hl;
330 : 0 : snprintf(s, sizeof(s), "%s_%s", sh->ibdev_name, name);
331 : 0 : hl = mlx5_hlist_create(s, size, direct_key, lcores_share,
332 : : ctx, cb_create, cb_match, cb_remove, cb_clone,
333 : : cb_clone_free);
334 [ # # ]: 0 : if (!hl) {
335 : 0 : DRV_LOG(ERR, "%s hash creation failed", name);
336 : 0 : rte_flow_error_set(error, ENOMEM,
337 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
338 : : "cannot allocate resource memory");
339 : 0 : return NULL;
340 : : }
341 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(phl, &expected, hl,
342 : : rte_memory_order_seq_cst,
343 : : rte_memory_order_seq_cst)) {
344 : 0 : mlx5_hlist_destroy(hl);
345 : 0 : hl = rte_atomic_load_explicit(phl, rte_memory_order_seq_cst);
346 : : }
347 : : return hl;
348 : : }
349 : :
350 : : /* Update VLAN's VID/PCP based on input rte_flow_action.
351 : : *
352 : : * @param[in] action
353 : : * Pointer to struct rte_flow_action.
354 : : * @param[out] vlan
355 : : * Pointer to struct rte_vlan_hdr.
356 : : */
357 : : static void
358 : 0 : mlx5_update_vlan_vid_pcp(const struct rte_flow_action *action,
359 : : struct rte_vlan_hdr *vlan)
360 : : {
361 : : uint16_t vlan_tci;
362 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP) {
363 : 0 : vlan_tci =
364 : : ((const struct rte_flow_action_of_set_vlan_pcp *)
365 : 0 : action->conf)->vlan_pcp;
366 : 0 : vlan_tci = vlan_tci << MLX5DV_FLOW_VLAN_PCP_SHIFT;
367 : 0 : vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
368 : 0 : vlan->vlan_tci |= vlan_tci;
369 [ # # ]: 0 : } else if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID) {
370 : 0 : vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
371 [ # # ]: 0 : vlan->vlan_tci |= rte_be_to_cpu_16
372 : : (((const struct rte_flow_action_of_set_vlan_vid *)
373 : : action->conf)->vlan_vid);
374 : : }
375 : 0 : }
376 : :
377 : : /**
378 : : * Convert modify-header action to DV specification.
379 : : *
380 : : * Data length of each action is determined by provided field description
381 : : * and the item mask. Data bit offset and width of each action is determined
382 : : * by provided item mask.
383 : : *
384 : : * @param[in] item
385 : : * Pointer to item specification.
386 : : * @param[in] field
387 : : * Pointer to field modification information.
388 : : * For MLX5_MODIFICATION_TYPE_SET specifies destination field.
389 : : * For MLX5_MODIFICATION_TYPE_ADD specifies destination field.
390 : : * For MLX5_MODIFICATION_TYPE_COPY specifies source field.
391 : : * For MLX5_MODIFICATION_TYPE_ADD_FIELD specifies source field.
392 : : * @param[in] dest
393 : : * Destination field info for MLX5_MODIFICATION_TYPE_COPY and
394 : : * MLX5_MODIFICATION_TYPE_ADD_FIELD in @type.
395 : : * Negative offset value sets the same offset as source offset.
396 : : * size field is ignored, value is taken from source field.
397 : : * @param[in,out] resource
398 : : * Pointer to the modify-header resource.
399 : : * @param[in] type
400 : : * Type of modification.
401 : : * @param[out] error
402 : : * Pointer to the error structure.
403 : : *
404 : : * @return
405 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
406 : : */
407 : : int
408 : 0 : flow_dv_convert_modify_action(struct rte_flow_item *item,
409 : : struct field_modify_info *field,
410 : : struct field_modify_info *dest,
411 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
412 : : uint32_t type, struct rte_flow_error *error)
413 : : {
414 : 0 : uint32_t i = resource->actions_num;
415 : 0 : struct mlx5_modification_cmd *actions = resource->actions;
416 : : uint32_t carry_b = 0;
417 : : bool to_dest;
418 : :
419 : : /*
420 : : * The item and mask are provided in big-endian format.
421 : : * The fields should be presented as in big-endian format either.
422 : : * Mask must be always present, it defines the actual field width.
423 : : */
424 : : MLX5_ASSERT(item->mask);
425 : : MLX5_ASSERT(field->size);
426 : 0 : to_dest = type == MLX5_MODIFICATION_TYPE_COPY ||
427 : 0 : type == MLX5_MODIFICATION_TYPE_ADD_FIELD;
428 : : do {
429 : : uint32_t size_b;
430 : : uint32_t off_b;
431 : : uint32_t mask;
432 : : uint32_t data;
433 : : bool next_field = true;
434 : : bool next_dest = true;
435 : :
436 [ # # ]: 0 : if (i >= MLX5_MAX_MODIFY_NUM)
437 : 0 : return rte_flow_error_set(error, EINVAL,
438 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
439 : : "too many items to modify");
440 : : /* Fetch variable byte size mask from the array. */
441 : 0 : mask = flow_dv_fetch_field((const uint8_t *)item->mask +
442 : 0 : field->offset, field->size);
443 [ # # ]: 0 : if (!mask) {
444 : 0 : ++field;
445 : : continue;
446 : : }
447 [ # # # # ]: 0 : if (to_dest && field->is_flex) {
448 : 0 : off_b = 32 - field->shift + carry_b - field->size * CHAR_BIT;
449 : 0 : size_b = field->size * CHAR_BIT - carry_b;
450 : : } else {
451 : : /* Deduce actual data width in bits from mask value. */
452 : 0 : off_b = rte_bsf32(mask) + carry_b;
453 : 0 : size_b = sizeof(uint32_t) * CHAR_BIT -
454 : 0 : off_b - rte_clz32(mask);
455 : : }
456 : : MLX5_ASSERT(size_b);
457 : 0 : actions[i] = (struct mlx5_modification_cmd) {
458 : : .action_type = type,
459 : 0 : .field = field->id,
460 : : .offset = off_b,
461 : : .length = (size_b == sizeof(uint32_t) * CHAR_BIT) ?
462 [ # # ]: 0 : 0 : size_b,
463 : : };
464 [ # # ]: 0 : if (to_dest) {
465 : : MLX5_ASSERT(dest);
466 : 0 : actions[i].dst_field = dest->id;
467 : 0 : actions[i].dst_offset =
468 [ # # ]: 0 : (int)dest->offset < 0 ? off_b : dest->offset;
469 : : /* Convert entire record to big-endian format. */
470 [ # # ]: 0 : actions[i].data1 = rte_cpu_to_be_32(actions[i].data1);
471 : : /*
472 : : * Destination field overflow. Copy leftovers of
473 : : * a source field to the next destination field.
474 : : */
475 [ # # # # ]: 0 : if ((size_b > dest->size * CHAR_BIT - dest->offset) &&
476 : : dest->size != 0) {
477 : 0 : actions[i].length =
478 : 0 : dest->size * CHAR_BIT - dest->offset;
479 : 0 : carry_b += actions[i].length;
480 : 0 : next_field = false;
481 : : } else {
482 : : carry_b = 0;
483 : : }
484 : : /*
485 : : * Not enough bits in a source filed to fill a
486 : : * destination field. Switch to the next source.
487 : : */
488 [ # # ]: 0 : if ((size_b < dest->size * CHAR_BIT - dest->offset) &&
489 [ # # ]: 0 : ((size_b == field->size * CHAR_BIT - off_b) ||
490 [ # # ]: 0 : field->is_flex)) {
491 : 0 : actions[i].length = size_b;
492 : 0 : dest->offset += actions[i].length;
493 : : next_dest = false;
494 : : }
495 : : } else {
496 : : MLX5_ASSERT(item->spec);
497 : 0 : data = flow_dv_fetch_field((const uint8_t *)item->spec +
498 : : field->offset, field->size);
499 : : /* Shift out the trailing masked bits from data. */
500 : 0 : data = (data & mask) >> off_b;
501 [ # # ]: 0 : if (field->is_flex)
502 : 0 : actions[i].offset = 32 - field->shift - field->size * CHAR_BIT;
503 [ # # ]: 0 : actions[i].data1 = rte_cpu_to_be_32(data);
504 : : }
505 : : /* Convert entire record to expected big-endian format. */
506 [ # # ]: 0 : actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
507 [ # # ]: 0 : if ((!to_dest ||
508 [ # # # # ]: 0 : dest->id != (enum mlx5_modification_field)UINT32_MAX) &&
509 : : field->id != (enum mlx5_modification_field)UINT32_MAX)
510 : 0 : ++i;
511 [ # # ]: 0 : if (next_dest && to_dest)
512 : 0 : ++dest;
513 [ # # ]: 0 : if (next_field)
514 : 0 : ++field;
515 [ # # ]: 0 : } while (field->size);
516 [ # # ]: 0 : if (resource->actions_num == i)
517 : 0 : return rte_flow_error_set(error, EINVAL,
518 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
519 : : "invalid modification flow item");
520 : 0 : resource->actions_num = i;
521 : 0 : return 0;
522 : : }
523 : :
524 : : /**
525 : : * Convert modify-header set IPv4 address action to DV specification.
526 : : *
527 : : * @param[in,out] resource
528 : : * Pointer to the modify-header resource.
529 : : * @param[in] action
530 : : * Pointer to action specification.
531 : : * @param[out] error
532 : : * Pointer to the error structure.
533 : : *
534 : : * @return
535 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
536 : : */
537 : : static int
538 : 0 : flow_dv_convert_action_modify_ipv4
539 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
540 : : const struct rte_flow_action *action,
541 : : struct rte_flow_error *error)
542 : : {
543 : 0 : const struct rte_flow_action_set_ipv4 *conf =
544 : : (const struct rte_flow_action_set_ipv4 *)(action->conf);
545 [ # # ]: 0 : struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
546 : : struct rte_flow_item_ipv4 ipv4;
547 : : struct rte_flow_item_ipv4 ipv4_mask;
548 : :
549 : : memset(&ipv4, 0, sizeof(ipv4));
550 : : memset(&ipv4_mask, 0, sizeof(ipv4_mask));
551 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC) {
552 : 0 : ipv4.hdr.src_addr = conf->ipv4_addr;
553 : 0 : ipv4_mask.hdr.src_addr = rte_flow_item_ipv4_mask.hdr.src_addr;
554 : : } else {
555 : 0 : ipv4.hdr.dst_addr = conf->ipv4_addr;
556 : 0 : ipv4_mask.hdr.dst_addr = rte_flow_item_ipv4_mask.hdr.dst_addr;
557 : : }
558 : 0 : item.spec = &ipv4;
559 : 0 : item.mask = &ipv4_mask;
560 : 0 : return flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
561 : : MLX5_MODIFICATION_TYPE_SET, error);
562 : : }
563 : :
564 : : /**
565 : : * Convert modify-header set IPv6 address action to DV specification.
566 : : *
567 : : * @param[in,out] resource
568 : : * Pointer to the modify-header resource.
569 : : * @param[in] action
570 : : * Pointer to action specification.
571 : : * @param[out] error
572 : : * Pointer to the error structure.
573 : : *
574 : : * @return
575 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
576 : : */
577 : : static int
578 : 0 : flow_dv_convert_action_modify_ipv6
579 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
580 : : const struct rte_flow_action *action,
581 : : struct rte_flow_error *error)
582 : : {
583 : 0 : const struct rte_flow_action_set_ipv6 *conf =
584 : : (const struct rte_flow_action_set_ipv6 *)(action->conf);
585 [ # # ]: 0 : struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
586 : : struct rte_flow_item_ipv6 ipv6;
587 : : struct rte_flow_item_ipv6 ipv6_mask;
588 : :
589 : : memset(&ipv6, 0, sizeof(ipv6));
590 : : memset(&ipv6_mask, 0, sizeof(ipv6_mask));
591 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC) {
592 : : memcpy(&ipv6.hdr.src_addr, &conf->ipv6_addr,
593 : : sizeof(ipv6.hdr.src_addr));
594 : : memcpy(&ipv6_mask.hdr.src_addr,
595 : : &rte_flow_item_ipv6_mask.hdr.src_addr,
596 : : sizeof(ipv6.hdr.src_addr));
597 : : } else {
598 : : memcpy(&ipv6.hdr.dst_addr, &conf->ipv6_addr,
599 : : sizeof(ipv6.hdr.dst_addr));
600 : : memcpy(&ipv6_mask.hdr.dst_addr,
601 : : &rte_flow_item_ipv6_mask.hdr.dst_addr,
602 : : sizeof(ipv6.hdr.dst_addr));
603 : : }
604 : 0 : item.spec = &ipv6;
605 : 0 : item.mask = &ipv6_mask;
606 : 0 : return flow_dv_convert_modify_action(&item, modify_ipv6, NULL, resource,
607 : : MLX5_MODIFICATION_TYPE_SET, error);
608 : : }
609 : :
610 : : /**
611 : : * Convert modify-header set MAC address action to DV specification.
612 : : *
613 : : * @param[in,out] resource
614 : : * Pointer to the modify-header resource.
615 : : * @param[in] action
616 : : * Pointer to action specification.
617 : : * @param[out] error
618 : : * Pointer to the error structure.
619 : : *
620 : : * @return
621 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
622 : : */
623 : : static int
624 : 0 : flow_dv_convert_action_modify_mac
625 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
626 : : const struct rte_flow_action *action,
627 : : struct rte_flow_error *error)
628 : : {
629 : 0 : const struct rte_flow_action_set_mac *conf =
630 : : (const struct rte_flow_action_set_mac *)(action->conf);
631 [ # # ]: 0 : struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_ETH };
632 : : struct rte_flow_item_eth eth;
633 : : struct rte_flow_item_eth eth_mask;
634 : :
635 : : memset(ð, 0, sizeof(eth));
636 : : memset(ð_mask, 0, sizeof(eth_mask));
637 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_SET_MAC_SRC) {
638 : : memcpy(ð.hdr.src_addr.addr_bytes, &conf->mac_addr,
639 : : sizeof(eth.hdr.src_addr.addr_bytes));
640 : : memcpy(ð_mask.hdr.src_addr.addr_bytes,
641 : : &rte_flow_item_eth_mask.hdr.src_addr.addr_bytes,
642 : : sizeof(eth_mask.hdr.src_addr.addr_bytes));
643 : : } else {
644 : : memcpy(ð.hdr.dst_addr.addr_bytes, &conf->mac_addr,
645 : : sizeof(eth.hdr.dst_addr.addr_bytes));
646 : : memcpy(ð_mask.hdr.dst_addr.addr_bytes,
647 : : &rte_flow_item_eth_mask.hdr.dst_addr.addr_bytes,
648 : : sizeof(eth_mask.hdr.dst_addr.addr_bytes));
649 : : }
650 : 0 : item.spec = ð
651 : 0 : item.mask = ð_mask;
652 : 0 : return flow_dv_convert_modify_action(&item, modify_eth, NULL, resource,
653 : : MLX5_MODIFICATION_TYPE_SET, error);
654 : : }
655 : :
656 : : /**
657 : : * Convert modify-header set VLAN VID action to DV specification.
658 : : *
659 : : * @param[in,out] resource
660 : : * Pointer to the modify-header resource.
661 : : * @param[in] action
662 : : * Pointer to action specification.
663 : : * @param[out] error
664 : : * Pointer to the error structure.
665 : : *
666 : : * @return
667 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
668 : : */
669 : : static int
670 : 0 : flow_dv_convert_action_modify_vlan_vid
671 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
672 : : const struct rte_flow_action *action,
673 : : struct rte_flow_error *error)
674 : : {
675 : 0 : const struct rte_flow_action_of_set_vlan_vid *conf =
676 : : (const struct rte_flow_action_of_set_vlan_vid *)(action->conf);
677 : 0 : int i = resource->actions_num;
678 : 0 : struct mlx5_modification_cmd *actions = resource->actions;
679 : : struct field_modify_info *field = modify_vlan_out_first_vid;
680 : :
681 [ # # ]: 0 : if (i >= MLX5_MAX_MODIFY_NUM)
682 : 0 : return rte_flow_error_set(error, EINVAL,
683 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
684 : : "too many items to modify");
685 : 0 : actions[i] = (struct mlx5_modification_cmd) {
686 : : .action_type = MLX5_MODIFICATION_TYPE_SET,
687 : 0 : .field = field->id,
688 : 0 : .length = field->size,
689 : 0 : .offset = field->offset,
690 : : };
691 [ # # ]: 0 : actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
692 : 0 : actions[i].data1 = conf->vlan_vid;
693 : 0 : actions[i].data1 = actions[i].data1 << 16;
694 : 0 : resource->actions_num = ++i;
695 : 0 : return 0;
696 : : }
697 : :
698 : : /**
699 : : * Convert modify-header set TP action to DV specification.
700 : : *
701 : : * @param[in,out] resource
702 : : * Pointer to the modify-header resource.
703 : : * @param[in] action
704 : : * Pointer to action specification.
705 : : * @param[in] items
706 : : * Pointer to rte_flow_item objects list.
707 : : * @param[in] attr
708 : : * Pointer to flow attributes structure.
709 : : * @param[in] dev_flow
710 : : * Pointer to the sub flow.
711 : : * @param[in] tunnel_decap
712 : : * Whether action is after tunnel decapsulation.
713 : : * @param[out] error
714 : : * Pointer to the error structure.
715 : : *
716 : : * @return
717 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
718 : : */
719 : : static int
720 : 0 : flow_dv_convert_action_modify_tp
721 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
722 : : const struct rte_flow_action *action,
723 : : const struct rte_flow_item *items,
724 : : union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
725 : : bool tunnel_decap, struct rte_flow_error *error)
726 : : {
727 : 0 : const struct rte_flow_action_set_tp *conf =
728 : : (const struct rte_flow_action_set_tp *)(action->conf);
729 : : struct rte_flow_item item;
730 : : struct rte_flow_item_udp udp;
731 : : struct rte_flow_item_udp udp_mask;
732 : : struct rte_flow_item_tcp tcp;
733 : : struct rte_flow_item_tcp tcp_mask;
734 : : struct field_modify_info *field;
735 : :
736 [ # # ]: 0 : if (!attr->valid)
737 : 0 : flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
738 [ # # ]: 0 : if (attr->udp) {
739 : : memset(&udp, 0, sizeof(udp));
740 : : memset(&udp_mask, 0, sizeof(udp_mask));
741 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
742 : 0 : udp.hdr.src_port = conf->port;
743 : 0 : udp_mask.hdr.src_port =
744 : : rte_flow_item_udp_mask.hdr.src_port;
745 : : } else {
746 : 0 : udp.hdr.dst_port = conf->port;
747 : 0 : udp_mask.hdr.dst_port =
748 : : rte_flow_item_udp_mask.hdr.dst_port;
749 : : }
750 : 0 : item.type = RTE_FLOW_ITEM_TYPE_UDP;
751 : 0 : item.spec = &udp;
752 : 0 : item.mask = &udp_mask;
753 : : field = modify_udp;
754 : : } else {
755 : : MLX5_ASSERT(attr->tcp);
756 : : memset(&tcp, 0, sizeof(tcp));
757 : : memset(&tcp_mask, 0, sizeof(tcp_mask));
758 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
759 : 0 : tcp.hdr.src_port = conf->port;
760 : 0 : tcp_mask.hdr.src_port =
761 : : rte_flow_item_tcp_mask.hdr.src_port;
762 : : } else {
763 : 0 : tcp.hdr.dst_port = conf->port;
764 : 0 : tcp_mask.hdr.dst_port =
765 : : rte_flow_item_tcp_mask.hdr.dst_port;
766 : : }
767 : 0 : item.type = RTE_FLOW_ITEM_TYPE_TCP;
768 : 0 : item.spec = &tcp;
769 : 0 : item.mask = &tcp_mask;
770 : : field = modify_tcp;
771 : : }
772 : 0 : return flow_dv_convert_modify_action(&item, field, NULL, resource,
773 : : MLX5_MODIFICATION_TYPE_SET, error);
774 : : }
775 : :
776 : : /**
777 : : * Convert modify-header set TTL action to DV specification.
778 : : *
779 : : * @param[in,out] resource
780 : : * Pointer to the modify-header resource.
781 : : * @param[in] action
782 : : * Pointer to action specification.
783 : : * @param[in] items
784 : : * Pointer to rte_flow_item objects list.
785 : : * @param[in] attr
786 : : * Pointer to flow attributes structure.
787 : : * @param[in] dev_flow
788 : : * Pointer to the sub flow.
789 : : * @param[in] tunnel_decap
790 : : * Whether action is after tunnel decapsulation.
791 : : * @param[out] error
792 : : * Pointer to the error structure.
793 : : *
794 : : * @return
795 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
796 : : */
797 : : static int
798 : 0 : flow_dv_convert_action_modify_ttl
799 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
800 : : const struct rte_flow_action *action,
801 : : const struct rte_flow_item *items,
802 : : union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
803 : : bool tunnel_decap, struct rte_flow_error *error)
804 : : {
805 : 0 : const struct rte_flow_action_set_ttl *conf =
806 : : (const struct rte_flow_action_set_ttl *)(action->conf);
807 : : struct rte_flow_item item;
808 : : struct rte_flow_item_ipv4 ipv4;
809 : : struct rte_flow_item_ipv4 ipv4_mask;
810 : : struct rte_flow_item_ipv6 ipv6;
811 : : struct rte_flow_item_ipv6 ipv6_mask;
812 : : struct field_modify_info *field;
813 : :
814 [ # # ]: 0 : if (!attr->valid)
815 : 0 : flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
816 [ # # ]: 0 : if (attr->ipv4) {
817 : : memset(&ipv4, 0, sizeof(ipv4));
818 : : memset(&ipv4_mask, 0, sizeof(ipv4_mask));
819 : 0 : ipv4.hdr.time_to_live = conf->ttl_value;
820 : 0 : ipv4_mask.hdr.time_to_live = 0xFF;
821 : 0 : item.type = RTE_FLOW_ITEM_TYPE_IPV4;
822 : 0 : item.spec = &ipv4;
823 : 0 : item.mask = &ipv4_mask;
824 : : field = modify_ipv4;
825 : : } else {
826 : : MLX5_ASSERT(attr->ipv6);
827 : : memset(&ipv6, 0, sizeof(ipv6));
828 : : memset(&ipv6_mask, 0, sizeof(ipv6_mask));
829 : 0 : ipv6.hdr.hop_limits = conf->ttl_value;
830 : 0 : ipv6_mask.hdr.hop_limits = 0xFF;
831 : 0 : item.type = RTE_FLOW_ITEM_TYPE_IPV6;
832 : 0 : item.spec = &ipv6;
833 : 0 : item.mask = &ipv6_mask;
834 : : field = modify_ipv6;
835 : : }
836 : 0 : return flow_dv_convert_modify_action(&item, field, NULL, resource,
837 : : MLX5_MODIFICATION_TYPE_SET, error);
838 : : }
839 : :
840 : : /**
841 : : * Convert modify-header decrement TTL action to DV specification.
842 : : *
843 : : * @param[in,out] resource
844 : : * Pointer to the modify-header resource.
845 : : * @param[in] action
846 : : * Pointer to action specification.
847 : : * @param[in] items
848 : : * Pointer to rte_flow_item objects list.
849 : : * @param[in] attr
850 : : * Pointer to flow attributes structure.
851 : : * @param[in] dev_flow
852 : : * Pointer to the sub flow.
853 : : * @param[in] tunnel_decap
854 : : * Whether action is after tunnel decapsulation.
855 : : * @param[out] error
856 : : * Pointer to the error structure.
857 : : *
858 : : * @return
859 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
860 : : */
861 : : static int
862 : 0 : flow_dv_convert_action_modify_dec_ttl
863 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
864 : : const struct rte_flow_item *items,
865 : : union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
866 : : bool tunnel_decap, struct rte_flow_error *error)
867 : : {
868 : : struct rte_flow_item item;
869 : : struct rte_flow_item_ipv4 ipv4;
870 : : struct rte_flow_item_ipv4 ipv4_mask;
871 : : struct rte_flow_item_ipv6 ipv6;
872 : : struct rte_flow_item_ipv6 ipv6_mask;
873 : : struct field_modify_info *field;
874 : :
875 [ # # ]: 0 : if (!attr->valid)
876 : 0 : flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
877 [ # # ]: 0 : if (attr->ipv4) {
878 : : memset(&ipv4, 0, sizeof(ipv4));
879 : : memset(&ipv4_mask, 0, sizeof(ipv4_mask));
880 : 0 : ipv4.hdr.time_to_live = 0xFF;
881 : 0 : ipv4_mask.hdr.time_to_live = 0xFF;
882 : 0 : item.type = RTE_FLOW_ITEM_TYPE_IPV4;
883 : 0 : item.spec = &ipv4;
884 : 0 : item.mask = &ipv4_mask;
885 : : field = modify_ipv4;
886 : : } else {
887 : : MLX5_ASSERT(attr->ipv6);
888 : : memset(&ipv6, 0, sizeof(ipv6));
889 : : memset(&ipv6_mask, 0, sizeof(ipv6_mask));
890 : 0 : ipv6.hdr.hop_limits = 0xFF;
891 : 0 : ipv6_mask.hdr.hop_limits = 0xFF;
892 : 0 : item.type = RTE_FLOW_ITEM_TYPE_IPV6;
893 : 0 : item.spec = &ipv6;
894 : 0 : item.mask = &ipv6_mask;
895 : : field = modify_ipv6;
896 : : }
897 : 0 : return flow_dv_convert_modify_action(&item, field, NULL, resource,
898 : : MLX5_MODIFICATION_TYPE_ADD, error);
899 : : }
900 : :
901 : : /**
902 : : * Convert modify-header increment/decrement TCP Sequence number
903 : : * to DV specification.
904 : : *
905 : : * @param[in,out] resource
906 : : * Pointer to the modify-header resource.
907 : : * @param[in] action
908 : : * Pointer to action specification.
909 : : * @param[out] error
910 : : * Pointer to the error structure.
911 : : *
912 : : * @return
913 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
914 : : */
915 : : static int
916 : 0 : flow_dv_convert_action_modify_tcp_seq
917 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
918 : : const struct rte_flow_action *action,
919 : : struct rte_flow_error *error)
920 : : {
921 : 0 : const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
922 [ # # ]: 0 : uint64_t value = rte_be_to_cpu_32(*conf);
923 : : struct rte_flow_item item;
924 : : struct rte_flow_item_tcp tcp;
925 : : struct rte_flow_item_tcp tcp_mask;
926 : :
927 : : memset(&tcp, 0, sizeof(tcp));
928 : : memset(&tcp_mask, 0, sizeof(tcp_mask));
929 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ)
930 : : /*
931 : : * The HW has no decrement operation, only increment operation.
932 : : * To simulate decrement X from Y using increment operation
933 : : * we need to add UINT32_MAX X times to Y.
934 : : * Each adding of UINT32_MAX decrements Y by 1.
935 : : */
936 : 0 : value *= UINT32_MAX;
937 [ # # ]: 0 : tcp.hdr.sent_seq = rte_cpu_to_be_32((uint32_t)value);
938 : 0 : tcp_mask.hdr.sent_seq = RTE_BE32(UINT32_MAX);
939 : 0 : item.type = RTE_FLOW_ITEM_TYPE_TCP;
940 : 0 : item.spec = &tcp;
941 : 0 : item.mask = &tcp_mask;
942 : 0 : return flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
943 : : MLX5_MODIFICATION_TYPE_ADD, error);
944 : : }
945 : :
946 : : /**
947 : : * Convert modify-header increment/decrement TCP Acknowledgment number
948 : : * to DV specification.
949 : : *
950 : : * @param[in,out] resource
951 : : * Pointer to the modify-header resource.
952 : : * @param[in] action
953 : : * Pointer to action specification.
954 : : * @param[out] error
955 : : * Pointer to the error structure.
956 : : *
957 : : * @return
958 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
959 : : */
960 : : static int
961 : 0 : flow_dv_convert_action_modify_tcp_ack
962 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
963 : : const struct rte_flow_action *action,
964 : : struct rte_flow_error *error)
965 : : {
966 : 0 : const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
967 [ # # ]: 0 : uint64_t value = rte_be_to_cpu_32(*conf);
968 : : struct rte_flow_item item;
969 : : struct rte_flow_item_tcp tcp;
970 : : struct rte_flow_item_tcp tcp_mask;
971 : :
972 : : memset(&tcp, 0, sizeof(tcp));
973 : : memset(&tcp_mask, 0, sizeof(tcp_mask));
974 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK)
975 : : /*
976 : : * The HW has no decrement operation, only increment operation.
977 : : * To simulate decrement X from Y using increment operation
978 : : * we need to add UINT32_MAX X times to Y.
979 : : * Each adding of UINT32_MAX decrements Y by 1.
980 : : */
981 : 0 : value *= UINT32_MAX;
982 [ # # ]: 0 : tcp.hdr.recv_ack = rte_cpu_to_be_32((uint32_t)value);
983 : 0 : tcp_mask.hdr.recv_ack = RTE_BE32(UINT32_MAX);
984 : 0 : item.type = RTE_FLOW_ITEM_TYPE_TCP;
985 : 0 : item.spec = &tcp;
986 : 0 : item.mask = &tcp_mask;
987 : 0 : return flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
988 : : MLX5_MODIFICATION_TYPE_ADD, error);
989 : : }
990 : :
991 : : enum mlx5_modification_field reg_to_field[] = {
992 : : [REG_NON] = MLX5_MODI_OUT_NONE,
993 : : [REG_A] = MLX5_MODI_META_DATA_REG_A,
994 : : [REG_B] = MLX5_MODI_META_DATA_REG_B,
995 : : [REG_C_0] = MLX5_MODI_META_REG_C_0,
996 : : [REG_C_1] = MLX5_MODI_META_REG_C_1,
997 : : [REG_C_2] = MLX5_MODI_META_REG_C_2,
998 : : [REG_C_3] = MLX5_MODI_META_REG_C_3,
999 : : [REG_C_4] = MLX5_MODI_META_REG_C_4,
1000 : : [REG_C_5] = MLX5_MODI_META_REG_C_5,
1001 : : [REG_C_6] = MLX5_MODI_META_REG_C_6,
1002 : : [REG_C_7] = MLX5_MODI_META_REG_C_7,
1003 : : [REG_C_8] = MLX5_MODI_META_REG_C_8,
1004 : : [REG_C_9] = MLX5_MODI_META_REG_C_9,
1005 : : [REG_C_10] = MLX5_MODI_META_REG_C_10,
1006 : : [REG_C_11] = MLX5_MODI_META_REG_C_11,
1007 : : };
1008 : :
1009 : : const size_t mlx5_mod_reg_size = RTE_DIM(reg_to_field);
1010 : :
1011 : : /**
1012 : : * Convert register set to DV specification.
1013 : : *
1014 : : * @param[in,out] resource
1015 : : * Pointer to the modify-header resource.
1016 : : * @param[in] action
1017 : : * Pointer to action specification.
1018 : : * @param[out] error
1019 : : * Pointer to the error structure.
1020 : : *
1021 : : * @return
1022 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1023 : : */
1024 : : static int
1025 : 0 : flow_dv_convert_action_set_reg
1026 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
1027 : : const struct rte_flow_action *action,
1028 : : struct rte_flow_error *error)
1029 : : {
1030 : 0 : const struct mlx5_rte_flow_action_set_tag *conf = action->conf;
1031 : 0 : struct mlx5_modification_cmd *actions = resource->actions;
1032 : 0 : uint32_t i = resource->actions_num;
1033 : :
1034 [ # # ]: 0 : if (i >= MLX5_MAX_MODIFY_NUM)
1035 : 0 : return rte_flow_error_set(error, EINVAL,
1036 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1037 : : "too many items to modify");
1038 : : MLX5_ASSERT(conf->id != REG_NON);
1039 : : MLX5_ASSERT(conf->id < (enum modify_reg)RTE_DIM(reg_to_field));
1040 : 0 : actions[i] = (struct mlx5_modification_cmd) {
1041 : : .action_type = MLX5_MODIFICATION_TYPE_SET,
1042 : 0 : .field = reg_to_field[conf->id],
1043 : 0 : .offset = conf->offset,
1044 : 0 : .length = conf->length,
1045 : : };
1046 [ # # ]: 0 : actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
1047 [ # # ]: 0 : actions[i].data1 = rte_cpu_to_be_32(conf->data);
1048 : : ++i;
1049 : 0 : resource->actions_num = i;
1050 : 0 : return 0;
1051 : : }
1052 : :
1053 : : /**
1054 : : * Convert SET_TAG action to DV specification.
1055 : : *
1056 : : * @param[in] dev
1057 : : * Pointer to the rte_eth_dev structure.
1058 : : * @param[in,out] resource
1059 : : * Pointer to the modify-header resource.
1060 : : * @param[in] conf
1061 : : * Pointer to action specification.
1062 : : * @param[out] error
1063 : : * Pointer to the error structure.
1064 : : *
1065 : : * @return
1066 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1067 : : */
1068 : : static int
1069 : 0 : flow_dv_convert_action_set_tag
1070 : : (struct rte_eth_dev *dev,
1071 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
1072 : : const struct rte_flow_action_set_tag *conf,
1073 : : struct rte_flow_error *error)
1074 : : {
1075 [ # # ]: 0 : rte_be32_t data = rte_cpu_to_be_32(conf->data);
1076 [ # # ]: 0 : rte_be32_t mask = rte_cpu_to_be_32(conf->mask);
1077 : 0 : struct rte_flow_item item = {
1078 : : .spec = &data,
1079 : : .mask = &mask,
1080 : : };
1081 : 0 : struct field_modify_info reg_c_x[] = {
1082 : : [1] = {0, 0, 0},
1083 : : };
1084 : : enum mlx5_modification_field reg_type;
1085 : : int ret;
1086 : :
1087 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
1088 [ # # ]: 0 : if (ret < 0)
1089 : : return ret;
1090 : : MLX5_ASSERT(ret != REG_NON);
1091 : : MLX5_ASSERT((unsigned int)ret < RTE_DIM(reg_to_field));
1092 : 0 : reg_type = reg_to_field[ret];
1093 : : MLX5_ASSERT(reg_type > 0);
1094 : 0 : reg_c_x[0] = (struct field_modify_info){4, 0, reg_type};
1095 : 0 : return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1096 : : MLX5_MODIFICATION_TYPE_SET, error);
1097 : : }
1098 : :
1099 : : /**
1100 : : * Convert internal COPY_REG action to DV specification.
1101 : : *
1102 : : * @param[in] dev
1103 : : * Pointer to the rte_eth_dev structure.
1104 : : * @param[in,out] res
1105 : : * Pointer to the modify-header resource.
1106 : : * @param[in] action
1107 : : * Pointer to action specification.
1108 : : * @param[out] error
1109 : : * Pointer to the error structure.
1110 : : *
1111 : : * @return
1112 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1113 : : */
1114 : : static int
1115 : 0 : flow_dv_convert_action_copy_mreg(struct rte_eth_dev *dev,
1116 : : struct mlx5_flow_dv_modify_hdr_resource *res,
1117 : : const struct rte_flow_action *action,
1118 : : struct rte_flow_error *error)
1119 : : {
1120 : 0 : const struct mlx5_flow_action_copy_mreg *conf = action->conf;
1121 : 0 : rte_be32_t mask = RTE_BE32(UINT32_MAX);
1122 : 0 : struct rte_flow_item item = {
1123 : : .spec = NULL,
1124 : : .mask = &mask,
1125 : : };
1126 : 0 : struct field_modify_info reg_src[] = {
1127 : 0 : {4, 0, reg_to_field[conf->src]},
1128 : : {0, 0, 0},
1129 : : };
1130 : 0 : struct field_modify_info reg_dst = {
1131 : : .offset = 0,
1132 : 0 : .id = reg_to_field[conf->dst],
1133 : : };
1134 : : /* Adjust reg_c[0] usage according to reported mask. */
1135 [ # # # # ]: 0 : if (conf->dst == REG_C_0 || conf->src == REG_C_0) {
1136 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1137 : 0 : uint32_t reg_c0 = priv->sh->dv_regc0_mask;
1138 : :
1139 : : MLX5_ASSERT(reg_c0);
1140 : : MLX5_ASSERT(priv->sh->config.dv_xmeta_en !=
1141 : : MLX5_XMETA_MODE_LEGACY);
1142 [ # # ]: 0 : if (conf->dst == REG_C_0) {
1143 : : /* Copy to reg_c[0], within mask only. */
1144 : 0 : reg_dst.offset = rte_bsf32(reg_c0);
1145 [ # # ]: 0 : mask = rte_cpu_to_be_32(reg_c0 >> reg_dst.offset);
1146 : : } else {
1147 : : reg_dst.offset = 0;
1148 [ # # ]: 0 : mask = rte_cpu_to_be_32(reg_c0);
1149 : : }
1150 : : }
1151 : 0 : return flow_dv_convert_modify_action(&item,
1152 : : reg_src, ®_dst, res,
1153 : : MLX5_MODIFICATION_TYPE_COPY,
1154 : : error);
1155 : : }
1156 : :
1157 : : /**
1158 : : * Convert MARK action to DV specification. This routine is used
1159 : : * in extensive metadata only and requires metadata register to be
1160 : : * handled. In legacy mode hardware tag resource is engaged.
1161 : : *
1162 : : * @param[in] dev
1163 : : * Pointer to the rte_eth_dev structure.
1164 : : * @param[in] conf
1165 : : * Pointer to MARK action specification.
1166 : : * @param[in,out] resource
1167 : : * Pointer to the modify-header resource.
1168 : : * @param[out] error
1169 : : * Pointer to the error structure.
1170 : : *
1171 : : * @return
1172 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1173 : : */
1174 : : static int
1175 : 0 : flow_dv_convert_action_mark(struct rte_eth_dev *dev,
1176 : : const struct rte_flow_action_mark *conf,
1177 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
1178 : : struct rte_flow_error *error)
1179 : : {
1180 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1181 [ # # ]: 0 : rte_be32_t mask = rte_cpu_to_be_32(MLX5_FLOW_MARK_MASK &
1182 : : priv->sh->dv_mark_mask);
1183 [ # # ]: 0 : rte_be32_t data = rte_cpu_to_be_32(conf->id) & mask;
1184 : 0 : struct rte_flow_item item = {
1185 : : .spec = &data,
1186 : : .mask = &mask,
1187 : : };
1188 : 0 : struct field_modify_info reg_c_x[] = {
1189 : : [1] = {0, 0, 0},
1190 : : };
1191 : : int reg;
1192 : :
1193 [ # # ]: 0 : if (!mask)
1194 : 0 : return rte_flow_error_set(error, EINVAL,
1195 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1196 : : NULL, "zero mark action mask");
1197 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1198 [ # # ]: 0 : if (reg < 0)
1199 : : return reg;
1200 : : MLX5_ASSERT(reg > 0);
1201 [ # # ]: 0 : if (reg == REG_C_0) {
1202 [ # # ]: 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1203 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
1204 : :
1205 [ # # ]: 0 : data = rte_cpu_to_be_32(rte_cpu_to_be_32(data) << shl_c0);
1206 [ # # ]: 0 : mask = rte_cpu_to_be_32(mask) & msk_c0;
1207 [ # # ]: 0 : mask = rte_cpu_to_be_32(mask << shl_c0);
1208 : : }
1209 : 0 : reg_c_x[0] = (struct field_modify_info){4, 0, reg_to_field[reg]};
1210 : 0 : return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1211 : : MLX5_MODIFICATION_TYPE_SET, error);
1212 : : }
1213 : :
1214 : : /**
1215 : : * Get metadata register index for specified steering domain.
1216 : : *
1217 : : * @param[in] dev
1218 : : * Pointer to the rte_eth_dev structure.
1219 : : * @param[in] attr
1220 : : * Attributes of flow to determine steering domain.
1221 : : * @param[out] error
1222 : : * Pointer to the error structure.
1223 : : *
1224 : : * @return
1225 : : * positive index on success, a negative errno value otherwise
1226 : : * and rte_errno is set.
1227 : : */
1228 : : static enum modify_reg
1229 : 0 : flow_dv_get_metadata_reg(struct rte_eth_dev *dev,
1230 : : const struct rte_flow_attr *attr,
1231 : : struct rte_flow_error *error)
1232 : : {
1233 : : int reg =
1234 [ # # ]: 0 : mlx5_flow_get_reg_id(dev, attr->transfer ?
1235 : 0 : MLX5_METADATA_FDB :
1236 [ # # ]: 0 : attr->egress ?
1237 : : MLX5_METADATA_TX :
1238 : : MLX5_METADATA_RX, 0, error);
1239 [ # # ]: 0 : if (reg < 0)
1240 : 0 : return rte_flow_error_set(error,
1241 : : ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM,
1242 : : NULL, "unavailable "
1243 : : "metadata register");
1244 : 0 : return reg;
1245 : : }
1246 : :
1247 : : /**
1248 : : * Convert SET_META action to DV specification.
1249 : : *
1250 : : * @param[in] dev
1251 : : * Pointer to the rte_eth_dev structure.
1252 : : * @param[in,out] resource
1253 : : * Pointer to the modify-header resource.
1254 : : * @param[in] attr
1255 : : * Attributes of flow that includes this item.
1256 : : * @param[in] conf
1257 : : * Pointer to action specification.
1258 : : * @param[out] error
1259 : : * Pointer to the error structure.
1260 : : *
1261 : : * @return
1262 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1263 : : */
1264 : : static int
1265 : 0 : flow_dv_convert_action_set_meta
1266 : : (struct rte_eth_dev *dev,
1267 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
1268 : : const struct rte_flow_attr *attr,
1269 : : const struct rte_flow_action_set_meta *conf,
1270 : : struct rte_flow_error *error)
1271 : : {
1272 [ # # ]: 0 : uint32_t mask = rte_cpu_to_be_32(conf->mask);
1273 [ # # ]: 0 : uint32_t data = rte_cpu_to_be_32(conf->data) & mask;
1274 : 0 : struct rte_flow_item item = {
1275 : : .spec = &data,
1276 : : .mask = &mask,
1277 : : };
1278 : 0 : struct field_modify_info reg_c_x[] = {
1279 : : [1] = {0, 0, 0},
1280 : : };
1281 : 0 : int reg = flow_dv_get_metadata_reg(dev, attr, error);
1282 : :
1283 [ # # ]: 0 : if (reg < 0)
1284 : : return reg;
1285 : : MLX5_ASSERT(reg != REG_NON);
1286 [ # # ]: 0 : if (reg == REG_C_0) {
1287 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1288 [ # # ]: 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1289 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
1290 : :
1291 [ # # ]: 0 : data = rte_cpu_to_be_32(rte_cpu_to_be_32(data) << shl_c0);
1292 [ # # ]: 0 : mask = rte_cpu_to_be_32(mask) & msk_c0;
1293 [ # # ]: 0 : mask = rte_cpu_to_be_32(mask << shl_c0);
1294 : : }
1295 : 0 : reg_c_x[0] = (struct field_modify_info){4, 0, reg_to_field[reg]};
1296 : : /* The routine expects parameters in memory as big-endian ones. */
1297 : 0 : return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1298 : : MLX5_MODIFICATION_TYPE_SET, error);
1299 : : }
1300 : :
1301 : : /**
1302 : : * Convert modify-header set IPv4 DSCP action to DV specification.
1303 : : *
1304 : : * @param[in,out] resource
1305 : : * Pointer to the modify-header resource.
1306 : : * @param[in] action
1307 : : * Pointer to action specification.
1308 : : * @param[out] error
1309 : : * Pointer to the error structure.
1310 : : *
1311 : : * @return
1312 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1313 : : */
1314 : : static int
1315 : 0 : flow_dv_convert_action_modify_ipv4_dscp
1316 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
1317 : : const struct rte_flow_action *action,
1318 : : struct rte_flow_error *error)
1319 : : {
1320 : 0 : const struct rte_flow_action_set_dscp *conf =
1321 : : (const struct rte_flow_action_set_dscp *)(action->conf);
1322 : 0 : struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
1323 : : struct rte_flow_item_ipv4 ipv4;
1324 : : struct rte_flow_item_ipv4 ipv4_mask;
1325 : :
1326 : : memset(&ipv4, 0, sizeof(ipv4));
1327 : : memset(&ipv4_mask, 0, sizeof(ipv4_mask));
1328 : 0 : ipv4.hdr.type_of_service = conf->dscp;
1329 : 0 : ipv4_mask.hdr.type_of_service = RTE_IPV4_HDR_DSCP_MASK >> 2;
1330 : 0 : item.spec = &ipv4;
1331 : 0 : item.mask = &ipv4_mask;
1332 : 0 : return flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
1333 : : MLX5_MODIFICATION_TYPE_SET, error);
1334 : : }
1335 : :
1336 : : /**
1337 : : * Convert modify-header set IPv6 DSCP action to DV specification.
1338 : : *
1339 : : * @param[in,out] resource
1340 : : * Pointer to the modify-header resource.
1341 : : * @param[in] action
1342 : : * Pointer to action specification.
1343 : : * @param[out] error
1344 : : * Pointer to the error structure.
1345 : : *
1346 : : * @return
1347 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1348 : : */
1349 : : static int
1350 : 0 : flow_dv_convert_action_modify_ipv6_dscp
1351 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
1352 : : const struct rte_flow_action *action,
1353 : : uint32_t ipv6_tc_off,
1354 : : struct rte_flow_error *error)
1355 : : {
1356 : 0 : const struct rte_flow_action_set_dscp *conf =
1357 : : (const struct rte_flow_action_set_dscp *)(action->conf);
1358 [ # # ]: 0 : struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
1359 : : struct rte_flow_item_ipv6 ipv6;
1360 : : struct rte_flow_item_ipv6 ipv6_mask;
1361 : : struct field_modify_info *modify_info;
1362 : :
1363 : : memset(&ipv6, 0, sizeof(ipv6));
1364 : : memset(&ipv6_mask, 0, sizeof(ipv6_mask));
1365 : : /*
1366 : : * Even though the DSCP bits offset of IPv6 is not byte aligned,
1367 : : * rdma-core only accept the DSCP bits byte aligned start from
1368 : : * bit 0 to 5 as to be compatible with IPv4. No need to shift the
1369 : : * bits in IPv6 case as rdma-core requires byte aligned value.
1370 : : * IPv6 DSCP uses OUT_IPV6_TRAFFIC_CLASS as ID but it starts from 2
1371 : : * bits left. Shift the mask left for IPv6 DSCP. Do it here because
1372 : : * it's needed to distinguish DSCP from ECN in data field construct
1373 : : */
1374 : 0 : ipv6.hdr.vtc_flow = conf->dscp << ipv6_tc_off;
1375 : 0 : ipv6_mask.hdr.vtc_flow = RTE_IPV6_HDR_DSCP_MASK >> (22 - ipv6_tc_off);
1376 : 0 : item.spec = &ipv6;
1377 : 0 : item.mask = &ipv6_mask;
1378 [ # # ]: 0 : if (ipv6_tc_off)
1379 : : modify_info = modify_ipv6_traffic_class;
1380 : : else
1381 : : modify_info = modify_ipv6;
1382 : 0 : return flow_dv_convert_modify_action(&item, modify_info, NULL, resource,
1383 : : MLX5_MODIFICATION_TYPE_SET, error);
1384 : : }
1385 : :
1386 : : int
1387 : 0 : mlx5_flow_item_field_width(struct rte_eth_dev *dev,
1388 : : enum rte_flow_field_id field, int inherit,
1389 : : const struct rte_flow_attr *attr,
1390 : : struct rte_flow_error *error)
1391 : : {
1392 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1393 : :
1394 [ # # # # : 0 : switch (field) {
# # # # #
# # # # #
# # # # #
# # # # ]
1395 : : case RTE_FLOW_FIELD_START:
1396 : : return 32;
1397 : 0 : case RTE_FLOW_FIELD_MAC_DST:
1398 : : case RTE_FLOW_FIELD_MAC_SRC:
1399 : 0 : return 48;
1400 : 0 : case RTE_FLOW_FIELD_VLAN_TYPE:
1401 : 0 : return 16;
1402 : 0 : case RTE_FLOW_FIELD_VLAN_ID:
1403 : 0 : return 12;
1404 : 0 : case RTE_FLOW_FIELD_MAC_TYPE:
1405 : 0 : return 16;
1406 : 0 : case RTE_FLOW_FIELD_IPV4_DSCP:
1407 : 0 : return 6;
1408 : 0 : case RTE_FLOW_FIELD_IPV4_TTL:
1409 : : case RTE_FLOW_FIELD_IPV4_PROTO:
1410 : 0 : return 8;
1411 : : case RTE_FLOW_FIELD_IPV4_SRC:
1412 : : case RTE_FLOW_FIELD_IPV4_DST:
1413 : : return 32;
1414 : 0 : case RTE_FLOW_FIELD_IPV6_DSCP:
1415 : 0 : return 6;
1416 : 0 : case RTE_FLOW_FIELD_IPV6_FLOW_LABEL:
1417 : 0 : return 20;
1418 : 0 : case RTE_FLOW_FIELD_IPV6_TRAFFIC_CLASS:
1419 : : case RTE_FLOW_FIELD_IPV6_HOPLIMIT:
1420 : : case RTE_FLOW_FIELD_IPV6_PROTO:
1421 : 0 : return 8;
1422 : 0 : case RTE_FLOW_FIELD_IPV6_SRC:
1423 : : case RTE_FLOW_FIELD_IPV6_DST:
1424 : 0 : return 128;
1425 : 0 : case RTE_FLOW_FIELD_TCP_PORT_SRC:
1426 : : case RTE_FLOW_FIELD_TCP_PORT_DST:
1427 : 0 : return 16;
1428 : : case RTE_FLOW_FIELD_TCP_SEQ_NUM:
1429 : : case RTE_FLOW_FIELD_TCP_ACK_NUM:
1430 : : return 32;
1431 : 0 : case RTE_FLOW_FIELD_TCP_FLAGS:
1432 : 0 : return 9;
1433 : 0 : case RTE_FLOW_FIELD_UDP_PORT_SRC:
1434 : : case RTE_FLOW_FIELD_UDP_PORT_DST:
1435 : 0 : return 16;
1436 : 0 : case RTE_FLOW_FIELD_VXLAN_VNI:
1437 : : case RTE_FLOW_FIELD_GENEVE_VNI:
1438 : 0 : return 24;
1439 : 0 : case RTE_FLOW_FIELD_VXLAN_LAST_RSVD:
1440 : 0 : return 8;
1441 : : case RTE_FLOW_FIELD_GTP_TEID:
1442 : : case RTE_FLOW_FIELD_MPLS:
1443 : : case RTE_FLOW_FIELD_TAG:
1444 : : case RTE_FLOW_FIELD_ESP_SPI:
1445 : : case RTE_FLOW_FIELD_ESP_SEQ_NUM:
1446 : : return 32;
1447 : 0 : case RTE_FLOW_FIELD_ESP_PROTO:
1448 : 0 : return 8;
1449 : 0 : case RTE_FLOW_FIELD_MARK:
1450 : 0 : return rte_popcount32(priv->sh->dv_mark_mask);
1451 : 0 : case RTE_FLOW_FIELD_META:
1452 : 0 : return (flow_dv_get_metadata_reg(dev, attr, error) == REG_C_0) ?
1453 [ # # ]: 0 : rte_popcount32(priv->sh->dv_meta_mask) : 32;
1454 : 0 : case RTE_FLOW_FIELD_GTP_PSC_QFI:
1455 : 0 : return 6;
1456 : 0 : case RTE_FLOW_FIELD_POINTER:
1457 : : case RTE_FLOW_FIELD_VALUE:
1458 : 0 : return inherit < 0 ? 0 : inherit;
1459 : 0 : case RTE_FLOW_FIELD_IPV4_ECN:
1460 : : case RTE_FLOW_FIELD_IPV6_ECN:
1461 : : case RTE_FLOW_FIELD_METER_COLOR:
1462 : 0 : return 2;
1463 : : case RTE_FLOW_FIELD_HASH_RESULT:
1464 : : return 32;
1465 : 0 : default:
1466 : : MLX5_ASSERT(false);
1467 : : }
1468 : 0 : return 0;
1469 : : }
1470 : :
1471 : : static __rte_always_inline uint8_t
1472 : : flow_modify_info_mask_8(uint32_t length, uint32_t off)
1473 : : {
1474 : 0 : return (0xffu >> (8 - length)) << off;
1475 : : }
1476 : :
1477 : : static __rte_always_inline uint16_t
1478 : : flow_modify_info_mask_16(uint32_t length, uint32_t off)
1479 : : {
1480 [ # # # # : 0 : return rte_cpu_to_be_16((0xffffu >> (16 - length)) << off);
# # # # #
# # # # #
# # # # #
# # # ]
1481 : : }
1482 : :
1483 : : static __rte_always_inline uint32_t
1484 : : flow_modify_info_mask_32(uint32_t length, uint32_t off)
1485 : : {
1486 [ # # # # : 0 : return rte_cpu_to_be_32((0xffffffffu >> (32 - length)) << off);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1487 : : }
1488 : :
1489 : : static __rte_always_inline uint32_t
1490 : : flow_modify_info_mask_32_masked(uint32_t length, uint32_t off, uint32_t post_mask)
1491 : : {
1492 : 0 : uint32_t mask = (0xffffffffu >> (32 - length)) << off;
1493 : 0 : return rte_cpu_to_be_32(mask & post_mask);
1494 : : }
1495 : :
1496 : : static __rte_always_inline enum mlx5_modification_field
1497 : : mlx5_mpls_modi_field_get(const struct rte_flow_field_data *data)
1498 : : {
1499 : 0 : return MLX5_MODI_IN_MPLS_LABEL_0 + data->tag_index;
1500 : : }
1501 : :
1502 : : static __rte_always_inline int
1503 : : flow_geneve_opt_modi_field_get(struct mlx5_priv *priv,
1504 : : const struct rte_flow_field_data *data)
1505 : : {
1506 : : #ifdef HAVE_MLX5_HWS_SUPPORT
1507 : 0 : return mlx5_geneve_opt_modi_field_get(priv, data);
1508 : : #else
1509 : : (void)priv;
1510 : : (void)data;
1511 : : DRV_LOG(ERR, "GENEVE option modification is not supported.");
1512 : : rte_errno = ENOTSUP;
1513 : : return -rte_errno;
1514 : : #endif
1515 : : }
1516 : :
1517 : : static void
1518 : 0 : mlx5_modify_flex_item(const struct rte_eth_dev *dev,
1519 : : const struct mlx5_flex_item *flex,
1520 : : const struct rte_flow_field_data *data,
1521 : : struct field_modify_info *info,
1522 : : uint32_t *mask, uint32_t width)
1523 : : {
1524 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1525 : 0 : struct mlx5_hca_flex_attr *attr = &priv->sh->cdev->config.hca_attr.flex;
1526 : : uint32_t i, j;
1527 : : int id = 0;
1528 : 0 : uint32_t pos = 0;
1529 : : const struct mlx5_flex_pattern_field *map;
1530 : 0 : uint32_t offset = data->offset;
1531 : : uint32_t width_left = width;
1532 : : uint32_t cur_width = 0;
1533 : : uint32_t tmp_ofs;
1534 : : uint32_t idx = 0;
1535 : : struct field_modify_info tmp;
1536 : : int tmp_id;
1537 : :
1538 [ # # ]: 0 : if (!attr->query_match_sample_info) {
1539 : 0 : DRV_LOG(ERR, "FW doesn't support modify field with flex item.");
1540 : 0 : return;
1541 : : }
1542 : : /*
1543 : : * search for the mapping instance until Accumulated width is no
1544 : : * less than data->offset.
1545 : : */
1546 [ # # ]: 0 : for (i = 0; i < flex->mapnum; i++) {
1547 [ # # ]: 0 : if (flex->map[i].width + pos > data->offset)
1548 : : break;
1549 : 0 : pos += flex->map[i].width;
1550 : : }
1551 [ # # ]: 0 : if (i >= flex->mapnum)
1552 : : return;
1553 [ # # ]: 0 : tmp_ofs = pos < data->offset ? data->offset - pos : 0;
1554 [ # # # # ]: 0 : for (j = i; i < flex->mapnum && width_left > 0; ) {
1555 : 0 : map = flex->map + i;
1556 : 0 : id = mlx5_flex_get_sample_id(flex, i, &pos, false);
1557 [ # # ]: 0 : if (id == -1) {
1558 : 0 : i++;
1559 : : /* All left length is dummy */
1560 [ # # ]: 0 : if (pos >= data->offset + width)
1561 : : return;
1562 : 0 : cur_width = map->width;
1563 : : /* One mapping instance covers the whole width. */
1564 [ # # ]: 0 : } else if (pos + map->width >= (data->offset + width)) {
1565 : : cur_width = width_left;
1566 : : } else {
1567 : 0 : cur_width = cur_width + map->width - tmp_ofs;
1568 : 0 : pos += map->width;
1569 : : /*
1570 : : * Continue to search next until:
1571 : : * 1. Another flex parser ID.
1572 : : * 2. Width has been covered.
1573 : : */
1574 [ # # ]: 0 : for (j = i + 1; j < flex->mapnum; j++) {
1575 : 0 : tmp_id = mlx5_flex_get_sample_id(flex, j, &pos, false);
1576 [ # # ]: 0 : if (tmp_id == -1) {
1577 : : i = j;
1578 : 0 : pos -= flex->map[j].width;
1579 : 0 : break;
1580 : : }
1581 [ # # # # ]: 0 : if (id >= (int)flex->devx_fp->num_samples ||
1582 [ # # ]: 0 : id >= MLX5_GRAPH_NODE_SAMPLE_NUM ||
1583 [ # # ]: 0 : tmp_id >= (int)flex->devx_fp->num_samples ||
1584 : : tmp_id >= MLX5_GRAPH_NODE_SAMPLE_NUM)
1585 : : return;
1586 : 0 : if (flex->devx_fp->sample_info[id].modify_field_id !=
1587 [ # # ]: 0 : flex->devx_fp->sample_info[tmp_id].modify_field_id ||
1588 : 0 : flex->map[j].shift != flex->map[j - 1].width +
1589 [ # # ]: 0 : flex->map[j - 1].shift) {
1590 : : i = j;
1591 : : break;
1592 : : }
1593 [ # # ]: 0 : if ((pos + flex->map[j].width) >= (data->offset + width)) {
1594 : : cur_width = width_left;
1595 : : break;
1596 : : }
1597 : 0 : pos += flex->map[j].width;
1598 : 0 : cur_width += flex->map[j].width;
1599 : : }
1600 : : }
1601 [ # # ]: 0 : if (cur_width > width_left)
1602 : : cur_width = width_left;
1603 [ # # # # : 0 : else if (cur_width < width_left && (j == flex->mapnum || i == flex->mapnum))
# # ]
1604 : : return;
1605 : :
1606 : : MLX5_ASSERT(id < (int)flex->devx_fp->num_samples);
1607 [ # # # # ]: 0 : if (id >= (int)flex->devx_fp->num_samples || id >= MLX5_GRAPH_NODE_SAMPLE_NUM)
1608 : : return;
1609 : : /* Use invalid entry as placeholder for DUMMY mapping. */
1610 : 0 : info[idx] = (struct field_modify_info){cur_width / CHAR_BIT, offset / CHAR_BIT,
1611 [ # # ]: 0 : id == -1 ? MLX5_MODI_INVALID :
1612 : : (enum mlx5_modification_field)
1613 : 0 : flex->devx_fp->sample_info[id].modify_field_id,
1614 : 0 : map->shift + tmp_ofs, 1};
1615 : 0 : offset += cur_width;
1616 : 0 : width_left -= cur_width;
1617 [ # # ]: 0 : if (!mask) {
1618 : 0 : info[idx].offset = (32 - cur_width - map->shift - tmp_ofs);
1619 : 0 : info[idx].size = cur_width / CHAR_BIT + info[idx].offset / CHAR_BIT;
1620 : : }
1621 : : cur_width = 0;
1622 : : tmp_ofs = 0;
1623 : 0 : idx++;
1624 : : }
1625 [ # # ]: 0 : if (unlikely(width_left > 0)) {
1626 : : MLX5_ASSERT(false);
1627 : : return;
1628 : : }
1629 [ # # ]: 0 : if (mask)
1630 : 0 : memset(mask, 0xff, data->offset / CHAR_BIT + width / CHAR_BIT);
1631 : : /* Re-order the info to follow IPv6 address. */
1632 [ # # ]: 0 : for (i = 0; i < idx / 2; i++) {
1633 : 0 : tmp = info[i];
1634 : : MLX5_ASSERT(info[i].id);
1635 : : MLX5_ASSERT(info[idx - 1 - i].id);
1636 : 0 : info[i] = info[idx - 1 - i];
1637 : 0 : info[idx - 1 - i] = tmp;
1638 : : }
1639 : : }
1640 : :
1641 : : static inline bool
1642 : : mlx5_dv_modify_ipv6_traffic_class_supported(struct mlx5_priv *priv)
1643 : : {
1644 : 0 : return priv->sh->phdev->config.ipv6_tc_fallback == MLX5_IPV6_TC_OK;
1645 : : }
1646 : :
1647 : : void
1648 : 0 : mlx5_flow_field_id_to_modify_info
1649 : : (const struct rte_flow_field_data *data,
1650 : : struct field_modify_info *info, uint32_t *mask,
1651 : : uint32_t width, struct rte_eth_dev *dev,
1652 : : const struct rte_flow_attr *attr, struct rte_flow_error *error)
1653 : : {
1654 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1655 : : enum mlx5_modification_field modi_id;
1656 : : uint32_t idx = 0;
1657 : : uint32_t off_be = 0;
1658 : : uint32_t length = 0;
1659 : :
1660 [ # # # # : 0 : switch ((int)data->field) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
1661 : : case RTE_FLOW_FIELD_START:
1662 : : /* not supported yet */
1663 : : MLX5_ASSERT(false);
1664 : : break;
1665 : 0 : case RTE_FLOW_FIELD_MAC_DST:
1666 : : MLX5_ASSERT(data->offset + width <= 48);
1667 : 0 : off_be = 48 - (data->offset + width);
1668 [ # # ]: 0 : if (off_be < 16) {
1669 [ # # ]: 0 : modi_id = CALC_MODI_ID(DMAC_15_0, data->level);
1670 : 0 : info[idx] = (struct field_modify_info){2, 4, modi_id};
1671 [ # # ]: 0 : length = off_be + width <= 16 ? width : 16 - off_be;
1672 [ # # ]: 0 : if (mask)
1673 : 0 : mask[1] = flow_modify_info_mask_16(length,
1674 : : off_be);
1675 : : else
1676 : 0 : info[idx].offset = off_be;
1677 : 0 : width -= length;
1678 [ # # ]: 0 : if (!width)
1679 : : break;
1680 : : off_be = 0;
1681 : : idx++;
1682 : : } else {
1683 : 0 : off_be -= 16;
1684 : : }
1685 [ # # ]: 0 : modi_id = CALC_MODI_ID(DMAC_47_16, data->level);
1686 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1687 [ # # ]: 0 : if (mask)
1688 : 0 : mask[0] = flow_modify_info_mask_32(width, off_be);
1689 : : else
1690 : 0 : info[idx].offset = off_be;
1691 : : break;
1692 : 0 : case RTE_FLOW_FIELD_MAC_SRC:
1693 : : MLX5_ASSERT(data->offset + width <= 48);
1694 : 0 : off_be = 48 - (data->offset + width);
1695 [ # # ]: 0 : if (off_be < 16) {
1696 [ # # ]: 0 : modi_id = CALC_MODI_ID(SMAC_15_0, data->level);
1697 : 0 : info[idx] = (struct field_modify_info){2, 4, modi_id};
1698 [ # # ]: 0 : length = off_be + width <= 16 ? width : 16 - off_be;
1699 [ # # ]: 0 : if (mask)
1700 : 0 : mask[1] = flow_modify_info_mask_16(length,
1701 : : off_be);
1702 : : else
1703 : 0 : info[idx].offset = off_be;
1704 : 0 : width -= length;
1705 [ # # ]: 0 : if (!width)
1706 : : break;
1707 : : off_be = 0;
1708 : : idx++;
1709 : : } else {
1710 : 0 : off_be -= 16;
1711 : : }
1712 [ # # ]: 0 : modi_id = CALC_MODI_ID(SMAC_47_16, data->level);
1713 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1714 [ # # ]: 0 : if (mask)
1715 : 0 : mask[0] = flow_modify_info_mask_32(width, off_be);
1716 : : else
1717 : 0 : info[idx].offset = off_be;
1718 : : break;
1719 : : case RTE_FLOW_FIELD_VLAN_TYPE:
1720 : : /* not supported yet */
1721 : : break;
1722 : 0 : case RTE_FLOW_FIELD_VLAN_ID:
1723 : : MLX5_ASSERT(data->offset + width <= 12);
1724 : 0 : off_be = 12 - (data->offset + width);
1725 : 0 : info[idx] = (struct field_modify_info){2, 0,
1726 : : MLX5_MODI_OUT_FIRST_VID};
1727 [ # # ]: 0 : if (mask)
1728 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1729 : : else
1730 : 0 : info[idx].offset = off_be;
1731 : : break;
1732 : 0 : case RTE_FLOW_FIELD_MAC_TYPE:
1733 : : MLX5_ASSERT(data->offset + width <= 16);
1734 : 0 : off_be = 16 - (data->offset + width);
1735 [ # # ]: 0 : modi_id = CALC_MODI_ID(ETHERTYPE, data->level);
1736 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
1737 [ # # ]: 0 : if (mask)
1738 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1739 : : else
1740 : 0 : info[idx].offset = off_be;
1741 : : break;
1742 : 0 : case RTE_FLOW_FIELD_IPV4_IHL:
1743 : : MLX5_ASSERT(data->offset + width <= 4);
1744 : 0 : off_be = 4 - (data->offset + width);
1745 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV4_IHL, data->level);
1746 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
1747 [ # # ]: 0 : if (mask)
1748 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1749 : : else
1750 : 0 : info[idx].offset = off_be;
1751 : : break;
1752 : 0 : case RTE_FLOW_FIELD_IPV4_DSCP:
1753 : : MLX5_ASSERT(data->offset + width <= 6);
1754 : 0 : off_be = 6 - (data->offset + width);
1755 [ # # ]: 0 : modi_id = CALC_MODI_ID(IP_DSCP, data->level);
1756 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
1757 [ # # ]: 0 : if (mask)
1758 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1759 : : else
1760 : 0 : info[idx].offset = off_be;
1761 : : break;
1762 : 0 : case RTE_FLOW_FIELD_IPV4_TOTAL_LEN:
1763 : : MLX5_ASSERT(data->offset + width <= 16);
1764 : 0 : off_be = 16 - (data->offset + width);
1765 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV4_TOTAL_LEN, data->level);
1766 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
1767 [ # # ]: 0 : if (mask)
1768 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1769 : : else
1770 : 0 : info[idx].offset = off_be;
1771 : : break;
1772 : 0 : case RTE_FLOW_FIELD_IPV4_TTL:
1773 : : MLX5_ASSERT(data->offset + width <= 8);
1774 : 0 : off_be = 8 - (data->offset + width);
1775 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV4_TTL, data->level);
1776 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
1777 [ # # ]: 0 : if (mask)
1778 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1779 : : else
1780 : 0 : info[idx].offset = off_be;
1781 : : break;
1782 : 0 : case RTE_FLOW_FIELD_IPV4_SRC:
1783 : : MLX5_ASSERT(data->offset + width <= 32);
1784 : 0 : off_be = 32 - (data->offset + width);
1785 [ # # ]: 0 : modi_id = CALC_MODI_ID(SIPV4, data->level);
1786 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1787 [ # # ]: 0 : if (mask)
1788 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1789 : : else
1790 : 0 : info[idx].offset = off_be;
1791 : : break;
1792 : 0 : case RTE_FLOW_FIELD_IPV4_DST:
1793 : : MLX5_ASSERT(data->offset + width <= 32);
1794 : 0 : off_be = 32 - (data->offset + width);
1795 [ # # ]: 0 : modi_id = CALC_MODI_ID(DIPV4, data->level);
1796 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1797 [ # # ]: 0 : if (mask)
1798 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1799 : : else
1800 : 0 : info[idx].offset = off_be;
1801 : : break;
1802 : : case RTE_FLOW_FIELD_IPV6_DSCP:
1803 : : MLX5_ASSERT(data->offset + width <= 6);
1804 : : /*
1805 : : * IPv6 DSCP uses OUT_IPV6_TRAFFIC_CLASS as ID but it starts from 2
1806 : : * bits left. Shift the mask left for IPv6 DSCP. Do it here because
1807 : : * it's needed to distinguish DSCP from ECN in data field construct
1808 : : */
1809 [ # # ]: 0 : if (mlx5_dv_modify_ipv6_traffic_class_supported(priv)) {
1810 : 0 : off_be = 6 - (data->offset + width) + MLX5_IPV6_HDR_DSCP_SHIFT;
1811 : 0 : info[idx] = (struct field_modify_info){1, 0,
1812 : : MLX5_MODI_OUT_IPV6_TRAFFIC_CLASS};
1813 : : } else {
1814 : 0 : off_be = 6 - (data->offset + width);
1815 : 0 : info[idx] = (struct field_modify_info){1, 0,
1816 : : MLX5_MODI_OUT_IP_DSCP};
1817 : : }
1818 [ # # ]: 0 : if (mask)
1819 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1820 : : else
1821 : 0 : info[idx].offset = off_be;
1822 : : break;
1823 : 0 : case RTE_FLOW_FIELD_IPV6_TRAFFIC_CLASS:
1824 : : MLX5_ASSERT(data->offset + width <= 8);
1825 : 0 : off_be = 8 - (data->offset + width);
1826 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV6_TRAFFIC_CLASS, data->level);
1827 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
1828 [ # # ]: 0 : if (mask)
1829 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1830 : : else
1831 : 0 : info[idx].offset = off_be;
1832 : : break;
1833 : 0 : case RTE_FLOW_FIELD_IPV6_FLOW_LABEL:
1834 : : MLX5_ASSERT(data->offset + width <= 20);
1835 : 0 : off_be = 20 - (data->offset + width);
1836 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV6_FLOW_LABEL, data->level);
1837 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1838 [ # # ]: 0 : if (mask)
1839 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1840 : : else
1841 : 0 : info[idx].offset = off_be;
1842 : : break;
1843 : 0 : case RTE_FLOW_FIELD_IPV6_PAYLOAD_LEN:
1844 : : MLX5_ASSERT(data->offset + width <= 16);
1845 : 0 : off_be = 16 - (data->offset + width);
1846 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV6_PAYLOAD_LEN, data->level);
1847 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
1848 [ # # ]: 0 : if (mask)
1849 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1850 : : else
1851 : 0 : info[idx].offset = off_be;
1852 : : break;
1853 : 0 : case RTE_FLOW_FIELD_IPV6_HOPLIMIT:
1854 : : MLX5_ASSERT(data->offset + width <= 8);
1855 : 0 : off_be = 8 - (data->offset + width);
1856 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV6_HOPLIMIT, data->level);
1857 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
1858 [ # # ]: 0 : if (mask)
1859 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1860 : : else
1861 : 0 : info[idx].offset = off_be;
1862 : : break;
1863 : 0 : case RTE_FLOW_FIELD_IPV6_SRC: {
1864 : : /*
1865 : : * Fields corresponding to IPv6 source address bytes
1866 : : * arranged according to network byte ordering.
1867 : : */
1868 : 0 : struct field_modify_info fields[] = {
1869 [ # # ]: 0 : { 4, 0, CALC_MODI_ID(SIPV6_127_96, data->level)},
1870 [ # # ]: 0 : { 4, 4, CALC_MODI_ID(SIPV6_95_64, data->level)},
1871 [ # # ]: 0 : { 4, 8, CALC_MODI_ID(SIPV6_63_32, data->level)},
1872 [ # # ]: 0 : { 4, 12, CALC_MODI_ID(SIPV6_31_0, data->level)},
1873 : : };
1874 : : /* First mask to be modified is the mask of 4th address byte. */
1875 : : uint32_t midx = 3;
1876 : :
1877 : : MLX5_ASSERT(data->offset + width <= 128);
1878 : 0 : off_be = 128 - (data->offset + width);
1879 [ # # ]: 0 : while (width > 0 && midx > 0) {
1880 [ # # ]: 0 : if (off_be < 32) {
1881 : 0 : info[idx] = fields[midx];
1882 : 0 : length = off_be + width <= 32 ?
1883 [ # # ]: 0 : width : 32 - off_be;
1884 [ # # ]: 0 : if (mask)
1885 [ # # ]: 0 : mask[midx] = flow_modify_info_mask_32
1886 : : (length, off_be);
1887 : : else
1888 : 0 : info[idx].offset = off_be;
1889 : 0 : width -= length;
1890 : : off_be = 0;
1891 : 0 : idx++;
1892 : : } else {
1893 : 0 : off_be -= 32;
1894 : : }
1895 : 0 : midx--;
1896 : : }
1897 [ # # ]: 0 : if (!width)
1898 : : break;
1899 : 0 : info[idx] = fields[midx];
1900 [ # # ]: 0 : if (mask)
1901 [ # # ]: 0 : mask[midx] = flow_modify_info_mask_32(width, off_be);
1902 : : else
1903 : 0 : info[idx].offset = off_be;
1904 : : break;
1905 : : }
1906 : 0 : case RTE_FLOW_FIELD_IPV6_DST: {
1907 : : /*
1908 : : * Fields corresponding to IPv6 destination address bytes
1909 : : * arranged according to network byte ordering.
1910 : : */
1911 : 0 : struct field_modify_info fields[] = {
1912 [ # # ]: 0 : { 4, 0, CALC_MODI_ID(DIPV6_127_96, data->level)},
1913 [ # # ]: 0 : { 4, 4, CALC_MODI_ID(DIPV6_95_64, data->level)},
1914 [ # # ]: 0 : { 4, 8, CALC_MODI_ID(DIPV6_63_32, data->level)},
1915 [ # # ]: 0 : { 4, 12, CALC_MODI_ID(DIPV6_31_0, data->level)},
1916 : : };
1917 : : /* First mask to be modified is the mask of 4th address byte. */
1918 : : uint32_t midx = 3;
1919 : :
1920 : : MLX5_ASSERT(data->offset + width <= 128);
1921 : 0 : off_be = 128 - (data->offset + width);
1922 [ # # ]: 0 : while (width > 0 && midx > 0) {
1923 [ # # ]: 0 : if (off_be < 32) {
1924 : 0 : info[idx] = fields[midx];
1925 : 0 : length = off_be + width <= 32 ?
1926 [ # # ]: 0 : width : 32 - off_be;
1927 [ # # ]: 0 : if (mask)
1928 [ # # ]: 0 : mask[midx] = flow_modify_info_mask_32
1929 : : (length, off_be);
1930 : : else
1931 : 0 : info[idx].offset = off_be;
1932 : 0 : width -= length;
1933 : : off_be = 0;
1934 : 0 : idx++;
1935 : : } else {
1936 : 0 : off_be -= 32;
1937 : : }
1938 : 0 : midx--;
1939 : : }
1940 [ # # ]: 0 : if (!width)
1941 : : break;
1942 : 0 : info[idx] = fields[midx];
1943 [ # # ]: 0 : if (mask)
1944 [ # # ]: 0 : mask[midx] = flow_modify_info_mask_32(width, off_be);
1945 : : else
1946 : 0 : info[idx].offset = off_be;
1947 : : break;
1948 : : }
1949 : 0 : case RTE_FLOW_FIELD_TCP_PORT_SRC:
1950 : : MLX5_ASSERT(data->offset + width <= 16);
1951 : 0 : off_be = 16 - (data->offset + width);
1952 [ # # ]: 0 : modi_id = CALC_MODI_ID(TCP_SPORT, data->level);
1953 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
1954 [ # # ]: 0 : if (mask)
1955 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1956 : : else
1957 : 0 : info[idx].offset = off_be;
1958 : : break;
1959 : 0 : case RTE_FLOW_FIELD_TCP_PORT_DST:
1960 : : MLX5_ASSERT(data->offset + width <= 16);
1961 : 0 : off_be = 16 - (data->offset + width);
1962 [ # # ]: 0 : modi_id = CALC_MODI_ID(TCP_DPORT, data->level);
1963 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
1964 [ # # ]: 0 : if (mask)
1965 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1966 : : else
1967 : 0 : info[idx].offset = off_be;
1968 : : break;
1969 : 0 : case RTE_FLOW_FIELD_TCP_SEQ_NUM:
1970 : : MLX5_ASSERT(data->offset + width <= 32);
1971 : 0 : off_be = 32 - (data->offset + width);
1972 [ # # ]: 0 : modi_id = CALC_MODI_ID(TCP_SEQ_NUM, data->level);
1973 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1974 [ # # ]: 0 : if (mask)
1975 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1976 : : else
1977 : 0 : info[idx].offset = off_be;
1978 : : break;
1979 : 0 : case RTE_FLOW_FIELD_TCP_ACK_NUM:
1980 : : MLX5_ASSERT(data->offset + width <= 32);
1981 : 0 : off_be = 32 - (data->offset + width);
1982 [ # # ]: 0 : modi_id = CALC_MODI_ID(TCP_ACK_NUM, data->level);
1983 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1984 [ # # ]: 0 : if (mask)
1985 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1986 : : else
1987 : 0 : info[idx].offset = off_be;
1988 : : break;
1989 : 0 : case RTE_FLOW_FIELD_TCP_FLAGS:
1990 : : MLX5_ASSERT(data->offset + width <= 9);
1991 : 0 : off_be = 9 - (data->offset + width);
1992 [ # # ]: 0 : modi_id = CALC_MODI_ID(TCP_FLAGS, data->level);
1993 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
1994 [ # # ]: 0 : if (mask)
1995 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1996 : : else
1997 : 0 : info[idx].offset = off_be;
1998 : : break;
1999 : 0 : case RTE_FLOW_FIELD_TCP_DATA_OFFSET:
2000 : : MLX5_ASSERT(data->offset + width <= 4);
2001 : 0 : off_be = 4 - (data->offset + width);
2002 [ # # ]: 0 : modi_id = CALC_MODI_ID(TCP_DATA_OFFSET, data->level);
2003 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
2004 [ # # ]: 0 : if (mask)
2005 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
2006 : : else
2007 : 0 : info[idx].offset = off_be;
2008 : : break;
2009 : 0 : case RTE_FLOW_FIELD_UDP_PORT_SRC:
2010 : : MLX5_ASSERT(data->offset + width <= 16);
2011 : 0 : off_be = 16 - (data->offset + width);
2012 [ # # ]: 0 : modi_id = CALC_MODI_ID(UDP_SPORT, data->level);
2013 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
2014 [ # # ]: 0 : if (mask)
2015 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
2016 : : else
2017 : 0 : info[idx].offset = off_be;
2018 : : break;
2019 : 0 : case RTE_FLOW_FIELD_UDP_PORT_DST:
2020 : : MLX5_ASSERT(data->offset + width <= 16);
2021 : 0 : off_be = 16 - (data->offset + width);
2022 [ # # ]: 0 : modi_id = CALC_MODI_ID(UDP_DPORT, data->level);
2023 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
2024 [ # # ]: 0 : if (mask)
2025 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
2026 : : else
2027 : 0 : info[idx].offset = off_be;
2028 : : break;
2029 : 0 : case RTE_FLOW_FIELD_VXLAN_VNI:
2030 : : case RTE_FLOW_FIELD_GENEVE_VNI:
2031 : : MLX5_ASSERT(data->offset + width <= 24);
2032 : : /* VNI is on bits 31-8 of TUNNEL_HDR_DW_1. */
2033 : 0 : off_be = 24 - (data->offset + width) + 8;
2034 : 0 : info[idx] = (struct field_modify_info){4, 0,
2035 : : MLX5_MODI_TUNNEL_HDR_DW_1};
2036 [ # # ]: 0 : if (mask)
2037 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2038 : : else
2039 : 0 : info[idx].offset = off_be;
2040 : : break;
2041 : 0 : case RTE_FLOW_FIELD_VXLAN_LAST_RSVD:
2042 : : MLX5_ASSERT(data->offset + width <= 8);
2043 : : /* Last_rsvd is on bits 7-0 of TUNNEL_HDR_DW_1. */
2044 : 0 : off_be = 8 - (data->offset + width);
2045 : 0 : info[idx] = (struct field_modify_info){1, 0, MLX5_MODI_TUNNEL_HDR_DW_1};
2046 [ # # ]: 0 : if (mask)
2047 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
2048 : : else
2049 : 0 : info[idx].offset = off_be;
2050 : : break;
2051 : : case RTE_FLOW_FIELD_GENEVE_OPT_TYPE:
2052 : : MLX5_ASSERT(data->offset + width <= 8);
2053 : : modi_id = flow_geneve_opt_modi_field_get(priv, data);
2054 [ # # ]: 0 : if (modi_id < 0)
2055 : : return;
2056 : : /* Type is on bits 16-8 of GENEVE option header (DW0). */
2057 : 0 : off_be = 32 - (16 + data->offset + width);
2058 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
2059 [ # # ]: 0 : if (mask)
2060 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2061 : : else
2062 : 0 : info[idx].offset = off_be;
2063 : : break;
2064 : : case RTE_FLOW_FIELD_GENEVE_OPT_CLASS:
2065 : : MLX5_ASSERT(data->offset + width <= 16);
2066 : : modi_id = flow_geneve_opt_modi_field_get(priv, data);
2067 [ # # ]: 0 : if (modi_id < 0)
2068 : : return;
2069 : : /* Class is on bits 31-16 of GENEVE option header (DW0). */
2070 : 0 : off_be = 32 - (data->offset + width);
2071 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
2072 [ # # ]: 0 : if (mask)
2073 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2074 : : else
2075 : 0 : info[idx].offset = off_be;
2076 : : break;
2077 : 0 : case RTE_FLOW_FIELD_GENEVE_OPT_DATA:
2078 [ # # ]: 0 : if ((data->offset % 32) + width > 32) {
2079 : 0 : DRV_LOG(ERR, "Geneve TLV option data is per DW.");
2080 : 0 : return;
2081 : : }
2082 : : modi_id = flow_geneve_opt_modi_field_get(priv, data);
2083 [ # # ]: 0 : if (modi_id < 0)
2084 : : return;
2085 : : /* Use offset inside DW. */
2086 : 0 : off_be = 32 - ((data->offset % 32) + width);
2087 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
2088 [ # # ]: 0 : if (mask)
2089 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2090 : : else
2091 : 0 : info[idx].offset = off_be;
2092 : : break;
2093 : 0 : case RTE_FLOW_FIELD_GTP_TEID:
2094 : : MLX5_ASSERT(data->offset + width <= 32);
2095 : 0 : off_be = 32 - (data->offset + width);
2096 : 0 : info[idx] = (struct field_modify_info){4, 0,
2097 : : MLX5_MODI_GTP_TEID};
2098 [ # # ]: 0 : if (mask)
2099 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2100 : : else
2101 : 0 : info[idx].offset = off_be;
2102 : : break;
2103 : 0 : case RTE_FLOW_FIELD_MPLS:
2104 : : MLX5_ASSERT(data->offset + width <= 32);
2105 : 0 : off_be = 32 - (data->offset + width);
2106 : : modi_id = mlx5_mpls_modi_field_get(data);
2107 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
2108 [ # # ]: 0 : if (mask)
2109 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2110 : : else
2111 : 0 : info[idx].offset = off_be;
2112 : : break;
2113 : : case RTE_FLOW_FIELD_TAG:
2114 : : {
2115 : : MLX5_ASSERT(data->offset + width <= 32);
2116 : : uint8_t tag_index = flow_tag_index_get(data);
2117 : : int reg;
2118 : :
2119 : : off_be = (tag_index == RTE_PMD_MLX5_LINEAR_HASH_TAG_INDEX) ?
2120 [ # # ]: 0 : 16 - (data->offset + width) + 16 : data->offset;
2121 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
2122 [ # # ]: 0 : reg = flow_hw_get_reg_id(dev,
2123 : : RTE_FLOW_ITEM_TYPE_TAG,
2124 : : tag_index);
2125 : : else
2126 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG,
2127 : : tag_index, error);
2128 [ # # ]: 0 : if (reg < 0)
2129 : : return;
2130 : : MLX5_ASSERT(reg != REG_NON);
2131 : : MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
2132 : 0 : info[idx] = (struct field_modify_info){4, 0,
2133 : 0 : reg_to_field[reg]};
2134 [ # # ]: 0 : if (mask)
2135 : 0 : mask[idx] = flow_modify_info_mask_32
2136 : : (width, off_be);
2137 : : else
2138 : 0 : info[idx].offset = off_be;
2139 : : }
2140 : : break;
2141 : 0 : case RTE_FLOW_FIELD_MARK:
2142 : : {
2143 : 0 : uint32_t mark_mask = priv->sh->dv_mark_mask;
2144 : : uint32_t mark_count = rte_popcount32(mark_mask);
2145 : : RTE_SET_USED(mark_count);
2146 : : MLX5_ASSERT(data->offset + width <= mark_count);
2147 : 0 : int reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK,
2148 : : 0, error);
2149 [ # # ]: 0 : if (reg < 0)
2150 : : return;
2151 : : MLX5_ASSERT(reg != REG_NON);
2152 : : MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
2153 : 0 : info[idx] = (struct field_modify_info){4, 0,
2154 : 0 : reg_to_field[reg]};
2155 [ # # ]: 0 : if (mask)
2156 : 0 : mask[idx] = flow_modify_info_mask_32_masked
2157 [ # # ]: 0 : (width, data->offset, mark_mask);
2158 : : else
2159 : 0 : info[idx].offset = data->offset;
2160 : : }
2161 : : break;
2162 : 0 : case RTE_FLOW_FIELD_META:
2163 : : {
2164 : 0 : uint32_t meta_mask = priv->sh->dv_meta_mask;
2165 : : uint32_t meta_count = rte_popcount32(meta_mask);
2166 : : RTE_SET_USED(meta_count);
2167 : : MLX5_ASSERT(data->offset + width <= meta_count);
2168 : 0 : int reg = flow_dv_get_metadata_reg(dev, attr, error);
2169 [ # # ]: 0 : if (reg < 0)
2170 : : return;
2171 : : MLX5_ASSERT(reg != REG_NON);
2172 : : MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
2173 : 0 : info[idx] = (struct field_modify_info){4, 0,
2174 : 0 : reg_to_field[reg]};
2175 [ # # ]: 0 : if (mask)
2176 : 0 : mask[idx] = flow_modify_info_mask_32_masked
2177 [ # # ]: 0 : (width, data->offset, meta_mask);
2178 : : else
2179 : 0 : info[idx].offset = data->offset;
2180 : : }
2181 : : break;
2182 : 0 : case RTE_FLOW_FIELD_IPV4_ECN:
2183 : : MLX5_ASSERT(data->offset + width <= 2);
2184 : 0 : off_be = 2 - (data->offset + width);
2185 [ # # ]: 0 : modi_id = CALC_MODI_ID(IP_ECN, data->level);
2186 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
2187 [ # # ]: 0 : if (mask)
2188 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
2189 : : else
2190 : 0 : info[idx].offset = off_be;
2191 : : break;
2192 : 0 : case RTE_FLOW_FIELD_IPV6_ECN:
2193 : : MLX5_ASSERT(data->offset + width <= 2);
2194 : 0 : off_be = 2 - (data->offset + width);
2195 [ # # ]: 0 : if (mlx5_dv_modify_ipv6_traffic_class_supported(priv))
2196 : 0 : info[idx] = (struct field_modify_info){1, 0,
2197 : : MLX5_MODI_OUT_IPV6_TRAFFIC_CLASS};
2198 : : else
2199 : 0 : info[idx] = (struct field_modify_info){1, 0,
2200 : : MLX5_MODI_OUT_IP_ECN};
2201 [ # # ]: 0 : if (mask)
2202 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
2203 : : else
2204 : 0 : info[idx].offset = off_be;
2205 : : break;
2206 : 0 : case RTE_FLOW_FIELD_GTP_PSC_QFI:
2207 : : MLX5_ASSERT(data->offset + width <= 8);
2208 : 0 : off_be = data->offset + 8;
2209 : 0 : info[idx] = (struct field_modify_info){4, 0,
2210 : : MLX5_MODI_GTPU_FIRST_EXT_DW_0};
2211 [ # # ]: 0 : if (mask)
2212 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2213 : : else
2214 : 0 : info[idx].offset = off_be;
2215 : : break;
2216 : 0 : case MLX5_RTE_FLOW_FIELD_META_REG:
2217 : : {
2218 [ # # ]: 0 : uint32_t meta_mask = priv->sh->dv_meta_mask;
2219 : : uint32_t meta_count = rte_popcount32(meta_mask);
2220 : : uint8_t reg = flow_tag_index_get(data);
2221 : :
2222 : : RTE_SET_USED(meta_count);
2223 : : MLX5_ASSERT(data->offset + width <= meta_count);
2224 : : MLX5_ASSERT(reg != REG_NON);
2225 : : MLX5_ASSERT(reg < RTE_DIM(reg_to_field));
2226 : 0 : info[idx] = (struct field_modify_info){4, 0, reg_to_field[reg]};
2227 [ # # ]: 0 : if (mask)
2228 : 0 : mask[idx] = flow_modify_info_mask_32_masked
2229 [ # # ]: 0 : (width, data->offset, meta_mask);
2230 : : else
2231 : 0 : info[idx].offset = data->offset;
2232 : : }
2233 : : break;
2234 : 0 : case RTE_FLOW_FIELD_METER_COLOR:
2235 : : {
2236 : : const uint32_t color_mask =
2237 : : (UINT32_C(1) << MLX5_MTR_COLOR_BITS) - 1;
2238 : : int reg;
2239 : :
2240 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
2241 : : reg = flow_hw_get_reg_id
2242 : : (dev,
2243 : : RTE_FLOW_ITEM_TYPE_METER_COLOR, 0);
2244 : : else
2245 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR,
2246 : : 0, error);
2247 [ # # ]: 0 : if (reg < 0)
2248 : : return;
2249 : : MLX5_ASSERT(reg != REG_NON);
2250 : : MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
2251 : 0 : info[idx] = (struct field_modify_info){4, 0,
2252 : 0 : reg_to_field[reg]};
2253 [ # # ]: 0 : if (mask)
2254 : 0 : mask[idx] = flow_modify_info_mask_32_masked
2255 [ # # ]: 0 : (width, data->offset, color_mask);
2256 : : else
2257 : 0 : info[idx].offset = data->offset;
2258 : : }
2259 : : break;
2260 : 0 : case RTE_FLOW_FIELD_IPV4_PROTO: /* Fall-through. */
2261 : : case RTE_FLOW_FIELD_IPV6_PROTO:
2262 : : MLX5_ASSERT(data->offset + width <= 8);
2263 : 0 : off_be = 8 - (data->offset + width);
2264 : 0 : info[idx] = (struct field_modify_info){1, 0, MLX5_MODI_OUT_IP_PROTOCOL};
2265 [ # # ]: 0 : if (mask)
2266 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
2267 : : else
2268 : 0 : info[idx].offset = off_be;
2269 : : break;
2270 : 0 : case RTE_FLOW_FIELD_ESP_PROTO:
2271 : : MLX5_ASSERT(data->offset + width <= 8);
2272 : 0 : off_be = 8 - (data->offset + width);
2273 : 0 : info[idx] = (struct field_modify_info){1, 0, MLX5_MODI_OUT_IPSEC_NEXT_HDR};
2274 [ # # ]: 0 : if (mask)
2275 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
2276 : : else
2277 : 0 : info[idx].offset = off_be;
2278 : : break;
2279 : 0 : case RTE_FLOW_FIELD_ESP_SPI:
2280 : : MLX5_ASSERT(data->offset + width <= 32);
2281 : 0 : off_be = 32 - (data->offset + width);
2282 [ # # ]: 0 : modi_id = CALC_MODI_ID(ESP_SPI, data->level);
2283 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
2284 [ # # ]: 0 : if (mask)
2285 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2286 : : else
2287 : 0 : info[idx].offset = off_be;
2288 : : break;
2289 : 0 : case RTE_FLOW_FIELD_ESP_SEQ_NUM:
2290 : : MLX5_ASSERT(data->offset + width <= 32);
2291 : 0 : off_be = 32 - (data->offset + width);
2292 [ # # ]: 0 : modi_id = CALC_MODI_ID(ESP_SEQ_NUM, data->level);
2293 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
2294 [ # # ]: 0 : if (mask)
2295 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2296 : : else
2297 : 0 : info[idx].offset = off_be;
2298 : : break;
2299 : 0 : case RTE_FLOW_FIELD_FLEX_ITEM:
2300 : : MLX5_ASSERT(data->flex_handle != NULL && !(data->offset & 0x7));
2301 : 0 : mlx5_modify_flex_item(dev, (const struct mlx5_flex_item *)data->flex_handle,
2302 : : data, info, mask, width);
2303 : 0 : break;
2304 : 0 : case RTE_FLOW_FIELD_HASH_RESULT:
2305 : : MLX5_ASSERT(data->offset + width <= 32);
2306 : 0 : off_be = 32 - (data->offset + width);
2307 : 0 : info[idx] = (struct field_modify_info){4, 0,
2308 : : MLX5_MODI_HASH_RESULT};
2309 [ # # ]: 0 : if (mask)
2310 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2311 : : else
2312 : 0 : info[idx].offset = off_be;
2313 : : break;
2314 : : case RTE_FLOW_FIELD_POINTER:
2315 : : case RTE_FLOW_FIELD_VALUE:
2316 : : default:
2317 : : MLX5_ASSERT(false);
2318 : : break;
2319 : : }
2320 : : }
2321 : :
2322 : : /**
2323 : : * Convert modify_field action to DV specification.
2324 : : *
2325 : : * @param[in] dev
2326 : : * Pointer to the rte_eth_dev structure.
2327 : : * @param[in,out] resource
2328 : : * Pointer to the modify-header resource.
2329 : : * @param[in] action
2330 : : * Pointer to action specification.
2331 : : * @param[in] attr
2332 : : * Attributes of flow that includes this item.
2333 : : * @param[out] error
2334 : : * Pointer to the error structure.
2335 : : *
2336 : : * @return
2337 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2338 : : */
2339 : : static int
2340 : 0 : flow_dv_convert_action_modify_field
2341 : : (struct rte_eth_dev *dev,
2342 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
2343 : : const struct rte_flow_action *action,
2344 : : const struct rte_flow_attr *attr,
2345 : : struct rte_flow_error *error)
2346 : : {
2347 : 0 : const struct rte_flow_action_modify_field *conf =
2348 : : (const struct rte_flow_action_modify_field *)(action->conf);
2349 : 0 : struct rte_flow_item item = {
2350 : : .spec = NULL,
2351 : : .mask = NULL
2352 : : };
2353 : 0 : struct field_modify_info field[MLX5_ACT_MAX_MOD_FIELDS] = {
2354 : : {0, 0, 0} };
2355 : 0 : struct field_modify_info dcopy[MLX5_ACT_MAX_MOD_FIELDS] = {
2356 : : {0, 0, 0} };
2357 : 0 : uint32_t mask[MLX5_ACT_MAX_MOD_FIELDS] = {0, 0, 0, 0, 0};
2358 : 0 : uint32_t type, meta = 0, dscp = 0;
2359 : :
2360 [ # # ]: 0 : if (conf->src.field == RTE_FLOW_FIELD_POINTER ||
2361 : : conf->src.field == RTE_FLOW_FIELD_VALUE) {
2362 : 0 : type = conf->operation == RTE_FLOW_MODIFY_SET ?
2363 [ # # ]: 0 : MLX5_MODIFICATION_TYPE_SET : MLX5_MODIFICATION_TYPE_ADD;
2364 : : /** For SET fill the destination field (field) first. */
2365 : 0 : mlx5_flow_field_id_to_modify_info(&conf->dst, field, mask,
2366 : 0 : conf->width, dev,
2367 : : attr, error);
2368 : 0 : item.spec = conf->src.field == RTE_FLOW_FIELD_POINTER ?
2369 [ # # ]: 0 : (void *)(uintptr_t)conf->src.pvalue :
2370 : : (void *)(uintptr_t)&conf->src.value;
2371 [ # # ]: 0 : if (conf->dst.field == RTE_FLOW_FIELD_META ||
2372 [ # # ]: 0 : conf->dst.field == RTE_FLOW_FIELD_TAG ||
2373 : : conf->dst.field == RTE_FLOW_FIELD_METER_COLOR) {
2374 : 0 : meta = *(const unaligned_uint32_t *)item.spec;
2375 [ # # ]: 0 : meta = rte_cpu_to_be_32(meta);
2376 : 0 : item.spec = &meta;
2377 : : }
2378 [ # # # # ]: 0 : if (mlx5_dv_modify_ipv6_traffic_class_supported(dev->data->dev_private) &&
2379 : 0 : conf->dst.field == RTE_FLOW_FIELD_IPV6_DSCP &&
2380 [ # # ]: 0 : !(mask[0] & MLX5_IPV6_HDR_ECN_MASK)) {
2381 : 0 : dscp = *(const unaligned_uint32_t *)item.spec;
2382 : : /*
2383 : : * IPv6 DSCP uses OUT_IPV6_TRAFFIC_CLASS as ID but it starts from 2
2384 : : * bits left. Shift the data left for IPv6 DSCP
2385 : : */
2386 : 0 : dscp <<= MLX5_IPV6_HDR_DSCP_SHIFT;
2387 : 0 : item.spec = &dscp;
2388 : : }
2389 : : } else {
2390 : : type = MLX5_MODIFICATION_TYPE_COPY;
2391 : : /** For COPY fill the destination field (dcopy) without mask. */
2392 : 0 : mlx5_flow_field_id_to_modify_info(&conf->dst, dcopy, NULL,
2393 : 0 : conf->width, dev,
2394 : : attr, error);
2395 : : /** Then construct the source field (field) with mask. */
2396 : 0 : mlx5_flow_field_id_to_modify_info(&conf->src, field, mask,
2397 : 0 : conf->width, dev,
2398 : : attr, error);
2399 : : }
2400 : 0 : item.mask = &mask;
2401 : 0 : return flow_dv_convert_modify_action(&item,
2402 : : field, dcopy, resource, type, error);
2403 : : }
2404 : :
2405 : : /**
2406 : : * Validate MARK item.
2407 : : *
2408 : : * @param[in] dev
2409 : : * Pointer to the rte_eth_dev structure.
2410 : : * @param[in] item
2411 : : * Item specification.
2412 : : * @param[in] attr
2413 : : * Attributes of flow that includes this item.
2414 : : * @param[out] error
2415 : : * Pointer to error structure.
2416 : : *
2417 : : * @return
2418 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2419 : : */
2420 : : static int
2421 : 0 : flow_dv_validate_item_mark(struct rte_eth_dev *dev,
2422 : : const struct rte_flow_item *item,
2423 : : const struct rte_flow_attr *attr __rte_unused,
2424 : : struct rte_flow_error *error)
2425 : : {
2426 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2427 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
2428 : 0 : const struct rte_flow_item_mark *spec = item->spec;
2429 : 0 : const struct rte_flow_item_mark *mask = item->mask;
2430 : 0 : const struct rte_flow_item_mark nic_mask = {
2431 : 0 : .id = priv->sh->dv_mark_mask,
2432 : : };
2433 : : int ret;
2434 : :
2435 [ # # ]: 0 : if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
2436 : 0 : return rte_flow_error_set(error, ENOTSUP,
2437 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2438 : : "extended metadata feature"
2439 : : " isn't enabled");
2440 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
2441 : 0 : return rte_flow_error_set(error, ENOTSUP,
2442 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2443 : : "extended metadata register"
2444 : : " isn't supported");
2445 [ # # ]: 0 : if (!nic_mask.id)
2446 : 0 : return rte_flow_error_set(error, ENOTSUP,
2447 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2448 : : "extended metadata register"
2449 : : " isn't available");
2450 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
2451 [ # # ]: 0 : if (ret < 0)
2452 : : return ret;
2453 [ # # ]: 0 : if (!spec)
2454 : 0 : return rte_flow_error_set(error, EINVAL,
2455 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2456 : 0 : item->spec,
2457 : : "data cannot be empty");
2458 [ # # ]: 0 : if (spec->id >= (MLX5_FLOW_MARK_MAX & nic_mask.id))
2459 : 0 : return rte_flow_error_set(error, EINVAL,
2460 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2461 : 0 : &spec->id,
2462 : : "mark id exceeds the limit");
2463 [ # # ]: 0 : if (!mask)
2464 : : mask = &nic_mask;
2465 [ # # ]: 0 : if (!mask->id)
2466 : 0 : return rte_flow_error_set(error, EINVAL,
2467 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2468 : : "mask cannot be zero");
2469 : :
2470 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2471 : : (const uint8_t *)&nic_mask,
2472 : : sizeof(struct rte_flow_item_mark),
2473 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2474 : : if (ret < 0)
2475 : : return ret;
2476 : : return 0;
2477 : : }
2478 : :
2479 : : /**
2480 : : * Validate META item.
2481 : : *
2482 : : * @param[in] dev
2483 : : * Pointer to the rte_eth_dev structure.
2484 : : * @param[in] item
2485 : : * Item specification.
2486 : : * @param[in] attr
2487 : : * Attributes of flow that includes this item.
2488 : : * @param[out] error
2489 : : * Pointer to error structure.
2490 : : *
2491 : : * @return
2492 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2493 : : */
2494 : : static int
2495 : 0 : flow_dv_validate_item_meta(struct rte_eth_dev *dev __rte_unused,
2496 : : const struct rte_flow_item *item,
2497 : : const struct rte_flow_attr *attr,
2498 : : struct rte_flow_error *error)
2499 : : {
2500 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2501 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
2502 : 0 : const struct rte_flow_item_meta *spec = item->spec;
2503 : 0 : const struct rte_flow_item_meta *mask = item->mask;
2504 : 0 : struct rte_flow_item_meta nic_mask = {
2505 : : .data = UINT32_MAX
2506 : : };
2507 : : int reg;
2508 : : int ret;
2509 : :
2510 [ # # ]: 0 : if (!spec)
2511 : 0 : return rte_flow_error_set(error, EINVAL,
2512 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2513 : : item->spec,
2514 : : "data cannot be empty");
2515 [ # # ]: 0 : if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
2516 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
2517 : 0 : return rte_flow_error_set(error, ENOTSUP,
2518 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2519 : : "extended metadata register"
2520 : : " isn't supported");
2521 : 0 : reg = flow_dv_get_metadata_reg(dev, attr, error);
2522 [ # # ]: 0 : if (reg < 0)
2523 : : return reg;
2524 [ # # ]: 0 : if (reg == REG_NON)
2525 : 0 : return rte_flow_error_set(error, ENOTSUP,
2526 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2527 : : "unavailable extended metadata register");
2528 [ # # ]: 0 : if (reg == REG_B)
2529 : 0 : return rte_flow_error_set(error, ENOTSUP,
2530 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2531 : : "match on reg_b "
2532 : : "isn't supported");
2533 [ # # ]: 0 : if (reg != REG_A)
2534 : 0 : nic_mask.data = priv->sh->dv_meta_mask;
2535 : : } else {
2536 [ # # ]: 0 : if (attr->transfer)
2537 : 0 : return rte_flow_error_set(error, ENOTSUP,
2538 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2539 : : "extended metadata feature "
2540 : : "should be enabled when "
2541 : : "meta item is requested "
2542 : : "with e-switch mode ");
2543 [ # # ]: 0 : if (attr->ingress)
2544 : 0 : return rte_flow_error_set(error, ENOTSUP,
2545 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2546 : : "match on metadata for ingress "
2547 : : "is not supported in legacy "
2548 : : "metadata mode");
2549 : : }
2550 [ # # ]: 0 : if (!mask)
2551 : : mask = &rte_flow_item_meta_mask;
2552 [ # # ]: 0 : if (!mask->data)
2553 : 0 : return rte_flow_error_set(error, EINVAL,
2554 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2555 : : "mask cannot be zero");
2556 : :
2557 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2558 : : (const uint8_t *)&nic_mask,
2559 : : sizeof(struct rte_flow_item_meta),
2560 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2561 : 0 : return ret;
2562 : : }
2563 : :
2564 : : /**
2565 : : * Validate TAG item.
2566 : : *
2567 : : * @param[in] dev
2568 : : * Pointer to the rte_eth_dev structure.
2569 : : * @param[in] item
2570 : : * Item specification.
2571 : : * @param[in] tag_bitmap
2572 : : * Tag index bitmap.
2573 : : * @param[in] attr
2574 : : * Attributes of flow that includes this item.
2575 : : * @param[out] error
2576 : : * Pointer to error structure.
2577 : : *
2578 : : * @return
2579 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2580 : : */
2581 : : static int
2582 : 0 : flow_dv_validate_item_tag(struct rte_eth_dev *dev,
2583 : : const struct rte_flow_item *item,
2584 : : uint32_t *tag_bitmap,
2585 : : const struct rte_flow_attr *attr __rte_unused,
2586 : : struct rte_flow_error *error)
2587 : : {
2588 : 0 : const struct rte_flow_item_tag *spec = item->spec;
2589 : 0 : const struct rte_flow_item_tag *mask = item->mask;
2590 : 0 : const struct rte_flow_item_tag nic_mask = {
2591 : : .data = RTE_BE32(UINT32_MAX),
2592 : : .index = 0xff,
2593 : : };
2594 : : int ret;
2595 : :
2596 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
2597 : 0 : return rte_flow_error_set(error, ENOTSUP,
2598 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2599 : : "extensive metadata register"
2600 : : " isn't supported");
2601 [ # # ]: 0 : if (!spec)
2602 : 0 : return rte_flow_error_set(error, EINVAL,
2603 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2604 : 0 : item->spec,
2605 : : "data cannot be empty");
2606 [ # # ]: 0 : if (!mask)
2607 : : mask = &rte_flow_item_tag_mask;
2608 [ # # ]: 0 : if (!mask->data)
2609 : 0 : return rte_flow_error_set(error, EINVAL,
2610 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2611 : : "mask cannot be zero");
2612 : :
2613 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2614 : : (const uint8_t *)&nic_mask,
2615 : : sizeof(struct rte_flow_item_tag),
2616 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2617 [ # # ]: 0 : if (ret < 0)
2618 : : return ret;
2619 [ # # ]: 0 : if (mask->index != 0xff)
2620 : 0 : return rte_flow_error_set(error, EINVAL,
2621 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2622 : : "partial mask for tag index"
2623 : : " is not supported");
2624 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, spec->index, error);
2625 [ # # ]: 0 : if (ret < 0)
2626 : : return ret;
2627 : : MLX5_ASSERT(ret != REG_NON);
2628 [ # # ]: 0 : if (*tag_bitmap & (1 << ret))
2629 : 0 : return rte_flow_error_set(error, EINVAL,
2630 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2631 : 0 : item->spec,
2632 : : "Duplicated tag index");
2633 : 0 : *tag_bitmap |= 1 << ret;
2634 : 0 : return 0;
2635 : : }
2636 : :
2637 : : /**
2638 : : * Validate vport item.
2639 : : *
2640 : : * @param[in] dev
2641 : : * Pointer to the rte_eth_dev structure.
2642 : : * @param[in] item
2643 : : * Item specification.
2644 : : * @param[in] attr
2645 : : * Attributes of flow that includes this item.
2646 : : * @param[in] item_flags
2647 : : * Bit-fields that holds the items detected until now.
2648 : : * @param[out] error
2649 : : * Pointer to error structure.
2650 : : *
2651 : : * @return
2652 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2653 : : */
2654 : : static int
2655 : 0 : flow_dv_validate_item_port_id(struct rte_eth_dev *dev,
2656 : : const struct rte_flow_item *item,
2657 : : const struct rte_flow_attr *attr,
2658 : : uint64_t item_flags,
2659 : : struct mlx5_priv **act_priv,
2660 : : struct rte_flow_error *error)
2661 : : {
2662 : 0 : const struct rte_flow_item_port_id *spec = item->spec;
2663 : 0 : const struct rte_flow_item_port_id *mask = item->mask;
2664 : 0 : const struct rte_flow_item_port_id switch_mask = {
2665 : : .id = 0xffffffff,
2666 : : };
2667 : : struct mlx5_priv *esw_priv;
2668 : : struct mlx5_priv *dev_priv;
2669 : : int ret;
2670 : :
2671 [ # # ]: 0 : if (!attr->transfer)
2672 : 0 : return rte_flow_error_set(error, EINVAL,
2673 : : RTE_FLOW_ERROR_TYPE_ITEM,
2674 : : NULL,
2675 : : "match on port id is valid only"
2676 : : " when transfer flag is enabled");
2677 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_PORT_ID)
2678 : 0 : return rte_flow_error_set(error, ENOTSUP,
2679 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2680 : : "multiple source ports are not"
2681 : : " supported");
2682 [ # # ]: 0 : if (!mask)
2683 : : mask = &switch_mask;
2684 [ # # ]: 0 : if (mask->id != 0xffffffff)
2685 : 0 : return rte_flow_error_set(error, ENOTSUP,
2686 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK,
2687 : : mask,
2688 : : "no support for partial mask on"
2689 : : " \"id\" field");
2690 : 0 : ret = mlx5_flow_item_acceptable
2691 : : (dev, item, (const uint8_t *)mask,
2692 : : (const uint8_t *)&rte_flow_item_port_id_mask,
2693 : : sizeof(struct rte_flow_item_port_id),
2694 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2695 [ # # ]: 0 : if (ret)
2696 : : return ret;
2697 [ # # ]: 0 : if (!spec)
2698 : : return 0;
2699 [ # # ]: 0 : if (spec->id == MLX5_PORT_ESW_MGR)
2700 : : return 0;
2701 : 0 : esw_priv = mlx5_port_to_eswitch_info(spec->id, false);
2702 [ # # ]: 0 : if (!esw_priv)
2703 : 0 : return rte_flow_error_set(error, rte_errno,
2704 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2705 : : "failed to obtain E-Switch info for"
2706 : : " port");
2707 : 0 : dev_priv = mlx5_dev_to_eswitch_info(dev);
2708 [ # # ]: 0 : if (!dev_priv)
2709 : 0 : return rte_flow_error_set(error, rte_errno,
2710 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2711 : : NULL,
2712 : : "failed to obtain E-Switch info");
2713 [ # # ]: 0 : if (esw_priv->domain_id != dev_priv->domain_id)
2714 : 0 : return rte_flow_error_set(error, EINVAL,
2715 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2716 : : "cannot match on a port from a"
2717 : : " different E-Switch");
2718 : 0 : *act_priv = esw_priv;
2719 : 0 : return 0;
2720 : : }
2721 : :
2722 : : /**
2723 : : * Validate represented port item.
2724 : : *
2725 : : * @param[in] dev
2726 : : * Pointer to the rte_eth_dev structure.
2727 : : * @param[in] item
2728 : : * Item specification.
2729 : : * @param[in] attr
2730 : : * Attributes of flow that includes this item.
2731 : : * @param[in] item_flags
2732 : : * Bit-fields that holds the items detected until now.
2733 : : * @param[out] error
2734 : : * Pointer to error structure.
2735 : : *
2736 : : * @return
2737 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2738 : : */
2739 : : static int
2740 : 0 : flow_dv_validate_item_represented_port(struct rte_eth_dev *dev,
2741 : : const struct rte_flow_item *item,
2742 : : const struct rte_flow_attr *attr,
2743 : : uint64_t item_flags,
2744 : : struct mlx5_priv **act_priv,
2745 : : struct rte_flow_error *error)
2746 : : {
2747 : 0 : const struct rte_flow_item_ethdev *spec = item->spec;
2748 : 0 : const struct rte_flow_item_ethdev *mask = item->mask;
2749 : 0 : const struct rte_flow_item_ethdev switch_mask = {
2750 : : .port_id = UINT16_MAX,
2751 : : };
2752 : : struct mlx5_priv *esw_priv;
2753 : : struct mlx5_priv *dev_priv;
2754 : : int ret;
2755 : :
2756 [ # # ]: 0 : if (!attr->transfer)
2757 : 0 : return rte_flow_error_set(error, EINVAL,
2758 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2759 : : "match on port id is valid only when transfer flag is enabled");
2760 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_REPRESENTED_PORT)
2761 : 0 : return rte_flow_error_set(error, ENOTSUP,
2762 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2763 : : "multiple source ports are not supported");
2764 [ # # ]: 0 : if (!mask)
2765 : : mask = &switch_mask;
2766 [ # # ]: 0 : if (mask->port_id != UINT16_MAX)
2767 : 0 : return rte_flow_error_set(error, ENOTSUP,
2768 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2769 : : "no support for partial mask on \"id\" field");
2770 : 0 : ret = mlx5_flow_item_acceptable
2771 : : (dev, item, (const uint8_t *)mask,
2772 : : (const uint8_t *)&rte_flow_item_ethdev_mask,
2773 : : sizeof(struct rte_flow_item_ethdev),
2774 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2775 [ # # ]: 0 : if (ret)
2776 : : return ret;
2777 [ # # # # ]: 0 : if (!spec || spec->port_id == UINT16_MAX)
2778 : : return 0;
2779 : 0 : esw_priv = mlx5_port_to_eswitch_info(spec->port_id, false);
2780 [ # # ]: 0 : if (!esw_priv)
2781 : 0 : return rte_flow_error_set(error, rte_errno,
2782 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2783 : : "failed to obtain E-Switch info for port");
2784 : 0 : dev_priv = mlx5_dev_to_eswitch_info(dev);
2785 [ # # ]: 0 : if (!dev_priv)
2786 : 0 : return rte_flow_error_set(error, rte_errno,
2787 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2788 : : NULL,
2789 : : "failed to obtain E-Switch info");
2790 [ # # ]: 0 : if (esw_priv->domain_id != dev_priv->domain_id)
2791 : 0 : return rte_flow_error_set(error, EINVAL,
2792 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2793 : : "cannot match on a port from a different E-Switch");
2794 : 0 : *act_priv = esw_priv;
2795 : 0 : return 0;
2796 : : }
2797 : :
2798 : : /**
2799 : : * Validate VLAN item.
2800 : : *
2801 : : * @param[in] item
2802 : : * Item specification.
2803 : : * @param[in] item_flags
2804 : : * Bit-fields that holds the items detected until now.
2805 : : * @param[in] dev
2806 : : * Ethernet device flow is being created on.
2807 : : * @param[out] error
2808 : : * Pointer to error structure.
2809 : : *
2810 : : * @return
2811 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2812 : : */
2813 : : int
2814 : 0 : mlx5_flow_dv_validate_item_vlan(const struct rte_flow_item *item,
2815 : : uint64_t item_flags,
2816 : : struct rte_eth_dev *dev,
2817 : : struct rte_flow_error *error)
2818 : : {
2819 : 0 : const struct rte_flow_item_vlan *mask = item->mask;
2820 : 0 : const struct rte_flow_item_vlan nic_mask = {
2821 : : .hdr.vlan_tci = RTE_BE16(UINT16_MAX),
2822 : : .hdr.eth_proto = RTE_BE16(UINT16_MAX),
2823 : : .has_more_vlan = 1,
2824 : : };
2825 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2826 : : int ret;
2827 : : const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
2828 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L4) :
2829 : : (MLX5_FLOW_LAYER_OUTER_L3 |
2830 : : MLX5_FLOW_LAYER_OUTER_L4);
2831 [ # # ]: 0 : const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
2832 : : MLX5_FLOW_LAYER_OUTER_VLAN;
2833 : :
2834 [ # # ]: 0 : if (item_flags & vlanm)
2835 : 0 : return rte_flow_error_set(error, EINVAL,
2836 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2837 : : "multiple VLAN layers not supported");
2838 [ # # ]: 0 : else if ((item_flags & l34m) != 0)
2839 : 0 : return rte_flow_error_set(error, EINVAL,
2840 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2841 : : "VLAN cannot follow L3/L4 layer");
2842 [ # # ]: 0 : if (!mask)
2843 : : mask = &rte_flow_item_vlan_mask;
2844 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2845 : : (const uint8_t *)&nic_mask,
2846 : : sizeof(struct rte_flow_item_vlan),
2847 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2848 [ # # ]: 0 : if (ret)
2849 : : return ret;
2850 [ # # # # ]: 0 : if (!tunnel && mask->hdr.vlan_tci != RTE_BE16(0x0fff)) {
2851 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2852 : :
2853 [ # # ]: 0 : if (priv->vmwa_context) {
2854 : : /*
2855 : : * Non-NULL context means we have a virtual machine
2856 : : * and SR-IOV enabled, we have to create VLAN interface
2857 : : * to make hypervisor to setup E-Switch vport
2858 : : * context correctly. We avoid creating the multiple
2859 : : * VLAN interfaces, so we cannot support VLAN tag mask.
2860 : : */
2861 : 0 : return rte_flow_error_set(error, EINVAL,
2862 : : RTE_FLOW_ERROR_TYPE_ITEM,
2863 : : item,
2864 : : "VLAN tag mask is not"
2865 : : " supported in virtual"
2866 : : " environment");
2867 : : }
2868 : : }
2869 : : return 0;
2870 : : }
2871 : :
2872 : : /*
2873 : : * GTP flags are contained in 1 byte of the format:
2874 : : * -------------------------------------------
2875 : : * | bit | 0 - 2 | 3 | 4 | 5 | 6 | 7 |
2876 : : * |-----------------------------------------|
2877 : : * | value | Version | PT | Res | E | S | PN |
2878 : : * -------------------------------------------
2879 : : *
2880 : : * Matching is supported only for GTP flags E, S, PN.
2881 : : */
2882 : : #define MLX5_GTP_FLAGS_MASK 0x07
2883 : :
2884 : : /**
2885 : : * Validate GTP item.
2886 : : *
2887 : : * @param[in] dev
2888 : : * Pointer to the rte_eth_dev structure.
2889 : : * @param[in] item
2890 : : * Item specification.
2891 : : * @param[in] item_flags
2892 : : * Bit-fields that holds the items detected until now.
2893 : : * @param[out] error
2894 : : * Pointer to error structure.
2895 : : *
2896 : : * @return
2897 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2898 : : */
2899 : : int
2900 : 0 : mlx5_flow_dv_validate_item_gtp(struct rte_eth_dev *dev,
2901 : : const struct rte_flow_item *item,
2902 : : uint64_t item_flags,
2903 : : struct rte_flow_error *error)
2904 : : {
2905 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2906 : 0 : const struct rte_flow_item_gtp *spec = item->spec;
2907 : 0 : const struct rte_flow_item_gtp *mask = item->mask;
2908 : 0 : const struct rte_flow_item_gtp nic_mask = {
2909 : : .hdr.gtp_hdr_info = MLX5_GTP_FLAGS_MASK,
2910 : : .hdr.msg_type = 0xff,
2911 : : .hdr.teid = RTE_BE32(0xffffffff),
2912 : : };
2913 : :
2914 [ # # ]: 0 : if (!priv->sh->cdev->config.hca_attr.tunnel_stateless_gtp)
2915 : 0 : return rte_flow_error_set(error, ENOTSUP,
2916 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2917 : : "GTP support is not enabled");
2918 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2919 : 0 : return rte_flow_error_set(error, ENOTSUP,
2920 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2921 : : "multiple tunnel layers not"
2922 : : " supported");
2923 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
2924 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2925 : 0 : return rte_flow_error_set(error, EINVAL,
2926 : : RTE_FLOW_ERROR_TYPE_ITEM,
2927 : : item, "no outer UDP layer found");
2928 : : }
2929 [ # # ]: 0 : if (!mask)
2930 : : mask = &rte_flow_item_gtp_mask;
2931 [ # # # # ]: 0 : if (spec && spec->hdr.gtp_hdr_info & ~MLX5_GTP_FLAGS_MASK)
2932 : 0 : return rte_flow_error_set(error, ENOTSUP,
2933 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2934 : : "Match is supported for GTP"
2935 : : " flags only");
2936 : 0 : return mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2937 : : (const uint8_t *)&nic_mask,
2938 : : sizeof(struct rte_flow_item_gtp),
2939 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2940 : : }
2941 : :
2942 : : /**
2943 : : * Validate GTP PSC item.
2944 : : *
2945 : : * @param[in] item
2946 : : * Item specification.
2947 : : * @param[in] last_item
2948 : : * Previous validated item in the pattern items.
2949 : : * @param[in] gtp_item
2950 : : * Previous GTP item specification.
2951 : : * @param root
2952 : : * Whether action is on root table.
2953 : : * @param[out] error
2954 : : * Pointer to error structure.
2955 : : *
2956 : : * @return
2957 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2958 : : */
2959 : : int
2960 : 0 : mlx5_flow_dv_validate_item_gtp_psc(const struct rte_eth_dev *dev,
2961 : : const struct rte_flow_item *item,
2962 : : uint64_t last_item,
2963 : : const struct rte_flow_item *gtp_item,
2964 : : bool root,
2965 : : struct rte_flow_error *error)
2966 : : {
2967 : : const struct rte_flow_item_gtp *gtp_spec;
2968 : : const struct rte_flow_item_gtp *gtp_mask;
2969 : : const struct rte_flow_item_gtp_psc *mask;
2970 : 0 : const struct rte_flow_item_gtp_psc nic_mask = {
2971 : : .hdr.type = 0xF,
2972 : : .hdr.qfi = 0x3F,
2973 : : };
2974 : :
2975 [ # # # # ]: 0 : if (!gtp_item || !(last_item & MLX5_FLOW_LAYER_GTP))
2976 : 0 : return rte_flow_error_set
2977 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2978 : : "GTP PSC item must be preceded with GTP item");
2979 : 0 : gtp_spec = gtp_item->spec;
2980 [ # # ]: 0 : gtp_mask = gtp_item->mask ? gtp_item->mask : &rte_flow_item_gtp_mask;
2981 : : /* GTP spec and E flag is requested to match zero. */
2982 [ # # ]: 0 : if (gtp_spec &&
2983 : 0 : (gtp_mask->hdr.gtp_hdr_info &
2984 [ # # ]: 0 : ~gtp_spec->hdr.gtp_hdr_info & MLX5_GTP_EXT_HEADER_FLAG))
2985 : 0 : return rte_flow_error_set
2986 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2987 : : "GTP E flag must be 1 to match GTP PSC");
2988 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
2989 : : /* Check the flow is not created in group zero. */
2990 [ # # ]: 0 : if (root)
2991 : 0 : return rte_flow_error_set
2992 : : (error, ENOTSUP,
2993 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2994 : : "GTP PSC is not supported for group 0");
2995 : : /* GTP spec is here and E flag is requested to match zero. */
2996 [ # # ]: 0 : if (!item->spec)
2997 : : return 0;
2998 : : }
2999 [ # # ]: 0 : mask = item->mask ? item->mask : &rte_flow_item_gtp_psc_mask;
3000 : 0 : return mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
3001 : : (const uint8_t *)&nic_mask,
3002 : : sizeof(struct rte_flow_item_gtp_psc),
3003 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3004 : : }
3005 : :
3006 : : /*
3007 : : * Validate IPV4 item.
3008 : : * Use existing validation function mlx5_flow_validate_item_ipv4(), and
3009 : : * add specific validation of fragment_offset field,
3010 : : *
3011 : : * @param[in] dev
3012 : : * Pointer to the rte_eth_dev structure.
3013 : : * @param[in] item
3014 : : * Item specification.
3015 : : * @param[in] item_flags
3016 : : * Bit-fields that holds the items detected until now.
3017 : : * @param[in] last_item
3018 : : * Previous validated item in the pattern items.
3019 : : * @param[in] ether_type
3020 : : * Type in the ethernet layer header (including dot1q).
3021 : : * @param[in] acc_mask
3022 : : * Default acceptable mask (will be adjusted).
3023 : : * @param[out] error
3024 : : * Pointer to error structure.
3025 : : *
3026 : : * @return
3027 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3028 : : */
3029 : : int
3030 : 0 : mlx5_flow_dv_validate_item_ipv4(struct rte_eth_dev *dev,
3031 : : const struct rte_flow_item *item,
3032 : : uint64_t item_flags,
3033 : : uint64_t last_item,
3034 : : uint16_t ether_type,
3035 : : const struct rte_flow_item_ipv4 *acc_mask,
3036 : : struct rte_flow_error *error)
3037 : : {
3038 : : int ret;
3039 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3040 : 0 : struct mlx5_hca_attr *attr = &priv->sh->cdev->config.hca_attr;
3041 : 0 : const struct rte_flow_item_ipv4 *spec = item->spec;
3042 : 0 : const struct rte_flow_item_ipv4 *last = item->last;
3043 : 0 : const struct rte_flow_item_ipv4 *mask = item->mask;
3044 : : rte_be16_t fragment_offset_spec = 0;
3045 : : rte_be16_t fragment_offset_last = 0;
3046 : 0 : struct rte_flow_item_ipv4 actual_ipv4_mask = *acc_mask;
3047 : :
3048 [ # # # # ]: 0 : if (mask && (mask->hdr.version_ihl & RTE_IPV4_HDR_IHL_MASK)) {
3049 : 0 : int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
3050 : : bool ihl_cap = !tunnel ?
3051 [ # # ]: 0 : attr->outer_ipv4_ihl : attr->inner_ipv4_ihl;
3052 [ # # ]: 0 : if (!ihl_cap)
3053 : 0 : return rte_flow_error_set(error, ENOTSUP,
3054 : : RTE_FLOW_ERROR_TYPE_ITEM,
3055 : : item,
3056 : : "IPV4 ihl offload not supported");
3057 : 0 : actual_ipv4_mask.hdr.version_ihl = mask->hdr.version_ihl;
3058 : : }
3059 : 0 : ret = mlx5_flow_validate_item_ipv4(dev, item, item_flags, last_item,
3060 : : ether_type, &actual_ipv4_mask,
3061 : : MLX5_ITEM_RANGE_ACCEPTED, error);
3062 [ # # ]: 0 : if (ret < 0)
3063 : : return ret;
3064 [ # # ]: 0 : if (spec && mask)
3065 : 0 : fragment_offset_spec = spec->hdr.fragment_offset &
3066 : 0 : mask->hdr.fragment_offset;
3067 [ # # ]: 0 : if (!fragment_offset_spec)
3068 : : return 0;
3069 : : /*
3070 : : * spec and mask are valid, enforce using full mask to make sure the
3071 : : * complete value is used correctly.
3072 : : */
3073 [ # # ]: 0 : if ((mask->hdr.fragment_offset & RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
3074 : : != RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
3075 : 0 : return rte_flow_error_set(error, EINVAL,
3076 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK,
3077 : : item, "must use full mask for"
3078 : : " fragment_offset");
3079 : : /*
3080 : : * Match on fragment_offset 0x2000 means MF is 1 and frag-offset is 0,
3081 : : * indicating this is 1st fragment of fragmented packet.
3082 : : * This is not yet supported in MLX5, return appropriate error message.
3083 : : */
3084 [ # # ]: 0 : if (fragment_offset_spec == RTE_BE16(RTE_IPV4_HDR_MF_FLAG))
3085 : 0 : return rte_flow_error_set(error, ENOTSUP,
3086 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3087 : : "match on first fragment not "
3088 : : "supported");
3089 [ # # ]: 0 : if (fragment_offset_spec && !last)
3090 : 0 : return rte_flow_error_set(error, ENOTSUP,
3091 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3092 : : "specified value not supported");
3093 : : /* spec and last are valid, validate the specified range. */
3094 : 0 : fragment_offset_last = last->hdr.fragment_offset &
3095 : : mask->hdr.fragment_offset;
3096 : : /*
3097 : : * Match on fragment_offset spec 0x2001 and last 0x3fff
3098 : : * means MF is 1 and frag-offset is > 0.
3099 : : * This packet is fragment 2nd and onward, excluding last.
3100 : : * This is not yet supported in MLX5, return appropriate
3101 : : * error message.
3102 : : */
3103 : 0 : if (fragment_offset_spec == RTE_BE16(RTE_IPV4_HDR_MF_FLAG + 1) &&
3104 [ # # ]: 0 : fragment_offset_last == RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
3105 : 0 : return rte_flow_error_set(error, ENOTSUP,
3106 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST,
3107 : : last, "match on following "
3108 : : "fragments not supported");
3109 : : /*
3110 : : * Match on fragment_offset spec 0x0001 and last 0x1fff
3111 : : * means MF is 0 and frag-offset is > 0.
3112 : : * This packet is last fragment of fragmented packet.
3113 : : * This is not yet supported in MLX5, return appropriate
3114 : : * error message.
3115 : : */
3116 : 0 : if (fragment_offset_spec == RTE_BE16(1) &&
3117 [ # # ]: 0 : fragment_offset_last == RTE_BE16(RTE_IPV4_HDR_OFFSET_MASK))
3118 : 0 : return rte_flow_error_set(error, ENOTSUP,
3119 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST,
3120 : : last, "match on last "
3121 : : "fragment not supported");
3122 : : /*
3123 : : * Match on fragment_offset spec 0x0001 and last 0x3fff
3124 : : * means MF and/or frag-offset is not 0.
3125 : : * This is a fragmented packet.
3126 : : * Other range values are invalid and rejected.
3127 : : */
3128 : 0 : if (!(fragment_offset_spec == RTE_BE16(1) &&
3129 [ # # ]: 0 : fragment_offset_last == RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK)))
3130 : 0 : return rte_flow_error_set(error, ENOTSUP,
3131 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST, last,
3132 : : "specified range not supported");
3133 : : return 0;
3134 : : }
3135 : :
3136 : : /**
3137 : : * Validate IPV6 fragment extension item.
3138 : : *
3139 : : * @param[in] item
3140 : : * Item specification.
3141 : : * @param[in] item_flags
3142 : : * Bit-fields that holds the items detected until now.
3143 : : * @param[out] error
3144 : : * Pointer to error structure.
3145 : : *
3146 : : * @return
3147 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3148 : : */
3149 : : static int
3150 : 0 : flow_dv_validate_item_ipv6_frag_ext(const struct rte_eth_dev *dev,
3151 : : const struct rte_flow_item *item,
3152 : : uint64_t item_flags,
3153 : : struct rte_flow_error *error)
3154 : : {
3155 : 0 : const struct rte_flow_item_ipv6_frag_ext *spec = item->spec;
3156 : 0 : const struct rte_flow_item_ipv6_frag_ext *last = item->last;
3157 : 0 : const struct rte_flow_item_ipv6_frag_ext *mask = item->mask;
3158 : : rte_be16_t frag_data_spec = 0;
3159 : : rte_be16_t frag_data_last = 0;
3160 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
3161 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
3162 : : MLX5_FLOW_LAYER_OUTER_L4;
3163 : : int ret = 0;
3164 : 0 : struct rte_flow_item_ipv6_frag_ext nic_mask = {
3165 : : .hdr = {
3166 : : .next_header = 0xff,
3167 : : .frag_data = RTE_BE16(0xffff),
3168 : : },
3169 : : };
3170 : :
3171 [ # # ]: 0 : if (item_flags & l4m)
3172 : 0 : return rte_flow_error_set(error, EINVAL,
3173 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3174 : : "ipv6 fragment extension item cannot "
3175 : : "follow L4 item.");
3176 [ # # # # : 0 : if ((tunnel && !(item_flags & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
# # ]
3177 [ # # ]: 0 : (!tunnel && !(item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV6)))
3178 : 0 : return rte_flow_error_set(error, EINVAL,
3179 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3180 : : "ipv6 fragment extension item must "
3181 : : "follow ipv6 item");
3182 [ # # ]: 0 : if (spec && mask)
3183 : 0 : frag_data_spec = spec->hdr.frag_data & mask->hdr.frag_data;
3184 [ # # ]: 0 : if (!frag_data_spec)
3185 : : return 0;
3186 : : /*
3187 : : * spec and mask are valid, enforce using full mask to make sure the
3188 : : * complete value is used correctly.
3189 : : */
3190 [ # # ]: 0 : if ((mask->hdr.frag_data & RTE_BE16(RTE_IPV6_FRAG_USED_MASK)) !=
3191 : : RTE_BE16(RTE_IPV6_FRAG_USED_MASK))
3192 : 0 : return rte_flow_error_set(error, EINVAL,
3193 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK,
3194 : : item, "must use full mask for"
3195 : : " frag_data");
3196 : : /*
3197 : : * Match on frag_data 0x00001 means M is 1 and frag-offset is 0.
3198 : : * This is 1st fragment of fragmented packet.
3199 : : */
3200 [ # # ]: 0 : if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_MF_MASK))
3201 : 0 : return rte_flow_error_set(error, ENOTSUP,
3202 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3203 : : "match on first fragment not "
3204 : : "supported");
3205 [ # # ]: 0 : if (frag_data_spec && !last)
3206 : 0 : return rte_flow_error_set(error, EINVAL,
3207 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3208 : : "specified value not supported");
3209 : 0 : ret = mlx5_flow_item_acceptable
3210 : : (dev, item, (const uint8_t *)mask,
3211 : : (const uint8_t *)&nic_mask,
3212 : : sizeof(struct rte_flow_item_ipv6_frag_ext),
3213 : : MLX5_ITEM_RANGE_ACCEPTED, error);
3214 [ # # ]: 0 : if (ret)
3215 : : return ret;
3216 : : /* spec and last are valid, validate the specified range. */
3217 : 0 : frag_data_last = last->hdr.frag_data & mask->hdr.frag_data;
3218 : : /*
3219 : : * Match on frag_data spec 0x0009 and last 0xfff9
3220 : : * means M is 1 and frag-offset is > 0.
3221 : : * This packet is fragment 2nd and onward, excluding last.
3222 : : * This is not yet supported in MLX5, return appropriate
3223 : : * error message.
3224 : : */
3225 : 0 : if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_FO_ALIGN |
3226 : 0 : RTE_IPV6_EHDR_MF_MASK) &&
3227 [ # # ]: 0 : frag_data_last == RTE_BE16(RTE_IPV6_FRAG_USED_MASK))
3228 : 0 : return rte_flow_error_set(error, ENOTSUP,
3229 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST,
3230 : : last, "match on following "
3231 : : "fragments not supported");
3232 : : /*
3233 : : * Match on frag_data spec 0x0008 and last 0xfff8
3234 : : * means M is 0 and frag-offset is > 0.
3235 : : * This packet is last fragment of fragmented packet.
3236 : : * This is not yet supported in MLX5, return appropriate
3237 : : * error message.
3238 : : */
3239 : 0 : if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_FO_ALIGN) &&
3240 [ # # ]: 0 : frag_data_last == RTE_BE16(RTE_IPV6_EHDR_FO_MASK))
3241 : 0 : return rte_flow_error_set(error, ENOTSUP,
3242 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST,
3243 : : last, "match on last "
3244 : : "fragment not supported");
3245 : : /* Other range values are invalid and rejected. */
3246 : 0 : return rte_flow_error_set(error, EINVAL,
3247 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST, last,
3248 : : "specified range not supported");
3249 : : }
3250 : :
3251 : : /*
3252 : : * Validate ASO CT item.
3253 : : *
3254 : : * @param[in] dev
3255 : : * Pointer to the rte_eth_dev structure.
3256 : : * @param[in] item
3257 : : * Item specification.
3258 : : * @param[in] item_flags
3259 : : * Pointer to bit-fields that holds the items detected until now.
3260 : : * @param[out] error
3261 : : * Pointer to error structure.
3262 : : *
3263 : : * @return
3264 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3265 : : */
3266 : : int
3267 : 0 : mlx5_flow_dv_validate_item_aso_ct(struct rte_eth_dev *dev,
3268 : : const struct rte_flow_item *item,
3269 : : uint64_t *item_flags,
3270 : : struct rte_flow_error *error)
3271 : : {
3272 : 0 : const struct rte_flow_item_conntrack *spec = item->spec;
3273 : 0 : const struct rte_flow_item_conntrack *mask = item->mask;
3274 : : uint32_t flags;
3275 : :
3276 [ # # ]: 0 : if (*item_flags & MLX5_FLOW_LAYER_ASO_CT)
3277 : 0 : return rte_flow_error_set(error, EINVAL,
3278 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
3279 : : "Only one CT is supported");
3280 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
3281 [ # # ]: 0 : if (!mask)
3282 : : mask = &rte_flow_item_conntrack_mask;
3283 : 0 : flags = spec->flags & mask->flags;
3284 [ # # ]: 0 : if ((flags & RTE_FLOW_CONNTRACK_PKT_STATE_VALID) &&
3285 : : ((flags & RTE_FLOW_CONNTRACK_PKT_STATE_INVALID) ||
3286 [ # # ]: 0 : (flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD) ||
3287 : : (flags & RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED)))
3288 : 0 : return rte_flow_error_set(error, EINVAL,
3289 : : RTE_FLOW_ERROR_TYPE_ITEM,
3290 : : NULL,
3291 : : "Conflict status bits");
3292 : : }
3293 : : /* State change also needs to be considered. */
3294 : 0 : *item_flags |= MLX5_FLOW_LAYER_ASO_CT;
3295 : 0 : return 0;
3296 : : }
3297 : :
3298 : : /**
3299 : : * Validate the pop VLAN action.
3300 : : *
3301 : : * @param[in] dev
3302 : : * Pointer to the rte_eth_dev structure.
3303 : : * @param[in] action_flags
3304 : : * Holds the actions detected until now.
3305 : : * @param[in] action
3306 : : * Pointer to the pop vlan action.
3307 : : * @param[in] item_flags
3308 : : * The items found in this flow rule.
3309 : : * @param[in] attr
3310 : : * Pointer to flow attributes.
3311 : : * @param[out] error
3312 : : * Pointer to error structure.
3313 : : *
3314 : : * @return
3315 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3316 : : */
3317 : : static int
3318 : 0 : flow_dv_validate_action_pop_vlan(struct rte_eth_dev *dev,
3319 : : uint64_t action_flags,
3320 : : const struct rte_flow_action *action,
3321 : : uint64_t item_flags,
3322 : : const struct rte_flow_attr *attr,
3323 : : struct rte_flow_error *error)
3324 : : {
3325 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
3326 : :
3327 [ # # ]: 0 : if (!priv->sh->pop_vlan_action)
3328 : 0 : return rte_flow_error_set(error, ENOTSUP,
3329 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3330 : : NULL,
3331 : : "pop vlan action is not supported");
3332 [ # # ]: 0 : if (action_flags & MLX5_FLOW_VLAN_ACTIONS)
3333 : 0 : return rte_flow_error_set(error, ENOTSUP,
3334 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3335 : : "no support for multiple VLAN "
3336 : : "actions");
3337 : : /* Pop VLAN with preceding Decap requires inner header with VLAN. */
3338 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_DECAP) &&
3339 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_INNER_VLAN))
3340 : 0 : return rte_flow_error_set(error, ENOTSUP,
3341 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3342 : : NULL,
3343 : : "cannot pop vlan after decap without "
3344 : : "match on inner vlan in the flow");
3345 : : /* Pop VLAN without preceding Decap requires outer header with VLAN. */
3346 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_ACTION_DECAP) &&
3347 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
3348 : 0 : return rte_flow_error_set(error, ENOTSUP,
3349 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3350 : : NULL,
3351 : : "cannot pop vlan without a "
3352 : : "match on (outer) vlan in the flow");
3353 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3354 : 0 : return rte_flow_error_set(error, EINVAL,
3355 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3356 : : "wrong action order, port_id should "
3357 : : "be after pop VLAN action");
3358 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
3359 : 0 : return rte_flow_error_set(error, ENOTSUP,
3360 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3361 : : "pop vlan action for VF representor "
3362 : : "not supported on NIC table");
3363 : : return 0;
3364 : : }
3365 : :
3366 : : /**
3367 : : * Get VLAN default info from vlan match info.
3368 : : *
3369 : : * @param[in] items
3370 : : * the list of item specifications.
3371 : : * @param[out] vlan
3372 : : * pointer VLAN info to fill to.
3373 : : *
3374 : : * @return
3375 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3376 : : */
3377 : : static void
3378 : 0 : flow_dev_get_vlan_info_from_items(const struct rte_flow_item *items,
3379 : : struct rte_vlan_hdr *vlan)
3380 : : {
3381 : 0 : const struct rte_flow_item_vlan nic_mask = {
3382 : : .hdr.vlan_tci = RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK |
3383 : : MLX5DV_FLOW_VLAN_VID_MASK),
3384 : : .hdr.eth_proto = RTE_BE16(0xffff),
3385 : : };
3386 : :
3387 [ # # ]: 0 : if (items == NULL)
3388 : 0 : return;
3389 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
3390 : 0 : int type = items->type;
3391 : :
3392 : 0 : if (type == RTE_FLOW_ITEM_TYPE_VLAN ||
3393 [ # # ]: 0 : type == MLX5_RTE_FLOW_ITEM_TYPE_VLAN)
3394 : : break;
3395 : : }
3396 [ # # ]: 0 : if (items->type != RTE_FLOW_ITEM_TYPE_END) {
3397 : 0 : const struct rte_flow_item_vlan *vlan_m = items->mask;
3398 : 0 : const struct rte_flow_item_vlan *vlan_v = items->spec;
3399 : :
3400 : : /* If VLAN item in pattern doesn't contain data, return here. */
3401 [ # # ]: 0 : if (!vlan_v)
3402 : : return;
3403 [ # # ]: 0 : if (!vlan_m)
3404 : : vlan_m = &nic_mask;
3405 : : /* Only full match values are accepted */
3406 [ # # ]: 0 : if ((vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) ==
3407 : : MLX5DV_FLOW_VLAN_PCP_MASK_BE) {
3408 : 0 : vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
3409 : 0 : vlan->vlan_tci |=
3410 [ # # ]: 0 : rte_be_to_cpu_16(vlan_v->hdr.vlan_tci &
3411 : : MLX5DV_FLOW_VLAN_PCP_MASK_BE);
3412 : : }
3413 [ # # ]: 0 : if ((vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) ==
3414 : : MLX5DV_FLOW_VLAN_VID_MASK_BE) {
3415 : 0 : vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
3416 : 0 : vlan->vlan_tci |=
3417 [ # # ]: 0 : rte_be_to_cpu_16(vlan_v->hdr.vlan_tci &
3418 : : MLX5DV_FLOW_VLAN_VID_MASK_BE);
3419 : : }
3420 [ # # ]: 0 : if (vlan_m->hdr.eth_proto == nic_mask.hdr.eth_proto)
3421 [ # # ]: 0 : vlan->eth_proto = rte_be_to_cpu_16(vlan_v->hdr.eth_proto &
3422 : : vlan_m->hdr.eth_proto);
3423 : : }
3424 : : }
3425 : :
3426 : : /**
3427 : : * Validate the push VLAN action.
3428 : : *
3429 : : * @param[in] dev
3430 : : * Pointer to the rte_eth_dev structure.
3431 : : * @param[in] action_flags
3432 : : * Holds the actions detected until now.
3433 : : * @param[in] item_flags
3434 : : * The items found in this flow rule.
3435 : : * @param[in] action
3436 : : * Pointer to the action structure.
3437 : : * @param[in] attr
3438 : : * Pointer to flow attributes
3439 : : * @param[out] error
3440 : : * Pointer to error structure.
3441 : : *
3442 : : * @return
3443 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3444 : : */
3445 : : static int
3446 : 0 : flow_dv_validate_action_push_vlan(struct rte_eth_dev *dev,
3447 : : uint64_t action_flags,
3448 : : const struct rte_flow_item_vlan *vlan_m,
3449 : : const struct rte_flow_action *action,
3450 : : const struct rte_flow_attr *attr,
3451 : : struct rte_flow_error *error)
3452 : : {
3453 : 0 : const struct rte_flow_action_of_push_vlan *push_vlan = action->conf;
3454 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
3455 : :
3456 [ # # ]: 0 : if (push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_VLAN) &&
3457 : : push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_QINQ))
3458 : 0 : return rte_flow_error_set(error, EINVAL,
3459 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3460 : : "invalid vlan ethertype");
3461 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3462 : 0 : return rte_flow_error_set(error, EINVAL,
3463 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3464 : : "wrong action order, port_id should "
3465 : : "be after push VLAN");
3466 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
3467 : 0 : return rte_flow_error_set(error, ENOTSUP,
3468 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3469 : : "push vlan action for VF representor "
3470 : : "not supported on NIC table");
3471 [ # # ]: 0 : if (vlan_m &&
3472 [ # # # # ]: 0 : (vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) &&
3473 : : (vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) !=
3474 : 0 : MLX5DV_FLOW_VLAN_PCP_MASK_BE &&
3475 [ # # # # ]: 0 : !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP) &&
3476 : 0 : !(mlx5_flow_find_action
3477 : : (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP)))
3478 : 0 : return rte_flow_error_set(error, EINVAL,
3479 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3480 : : "not full match mask on VLAN PCP and "
3481 : : "there is no of_set_vlan_pcp action, "
3482 : : "push VLAN action cannot figure out "
3483 : : "PCP value");
3484 [ # # ]: 0 : if (vlan_m &&
3485 [ # # # # ]: 0 : (vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) &&
3486 : : (vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) !=
3487 : 0 : MLX5DV_FLOW_VLAN_VID_MASK_BE &&
3488 [ # # # # ]: 0 : !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID) &&
3489 : 0 : !(mlx5_flow_find_action
3490 : : (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID)))
3491 : 0 : return rte_flow_error_set(error, EINVAL,
3492 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3493 : : "not full match mask on VLAN VID and "
3494 : : "there is no of_set_vlan_vid action, "
3495 : : "push VLAN action cannot figure out "
3496 : : "VID value");
3497 : : (void)attr;
3498 : : return 0;
3499 : : }
3500 : :
3501 : : /**
3502 : : * Validate the set VLAN PCP.
3503 : : *
3504 : : * @param[in] action_flags
3505 : : * Holds the actions detected until now.
3506 : : * @param[in] actions
3507 : : * Pointer to the list of actions remaining in the flow rule.
3508 : : * @param[out] error
3509 : : * Pointer to error structure.
3510 : : *
3511 : : * @return
3512 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3513 : : */
3514 : : static int
3515 : 0 : flow_dv_validate_action_set_vlan_pcp(uint64_t action_flags,
3516 : : const struct rte_flow_action actions[],
3517 : : struct rte_flow_error *error)
3518 : : {
3519 : : const struct rte_flow_action *action = actions;
3520 : 0 : const struct rte_flow_action_of_set_vlan_pcp *conf = action->conf;
3521 : :
3522 [ # # ]: 0 : if (conf->vlan_pcp > 7)
3523 : 0 : return rte_flow_error_set(error, EINVAL,
3524 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3525 : : "VLAN PCP value is too big");
3526 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN))
3527 : 0 : return rte_flow_error_set(error, ENOTSUP,
3528 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3529 : : "set VLAN PCP action must follow "
3530 : : "the push VLAN action");
3531 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP)
3532 : 0 : return rte_flow_error_set(error, ENOTSUP,
3533 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3534 : : "Multiple VLAN PCP modification are "
3535 : : "not supported");
3536 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3537 : 0 : return rte_flow_error_set(error, EINVAL,
3538 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3539 : : "wrong action order, port_id should "
3540 : : "be after set VLAN PCP");
3541 : : return 0;
3542 : : }
3543 : :
3544 : : /**
3545 : : * Validate the set VLAN VID.
3546 : : *
3547 : : * @param[in] item_flags
3548 : : * Holds the items detected in this rule.
3549 : : * @param[in] action_flags
3550 : : * Holds the actions detected until now.
3551 : : * @param[in] actions
3552 : : * Pointer to the list of actions remaining in the flow rule.
3553 : : * @param[out] error
3554 : : * Pointer to error structure.
3555 : : *
3556 : : * @return
3557 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3558 : : */
3559 : : static int
3560 : 0 : flow_dv_validate_action_set_vlan_vid(uint64_t item_flags,
3561 : : uint64_t action_flags,
3562 : : const struct rte_flow_action actions[],
3563 : : struct rte_flow_error *error)
3564 : : {
3565 : : const struct rte_flow_action *action = actions;
3566 : 0 : const struct rte_flow_action_of_set_vlan_vid *conf = action->conf;
3567 : :
3568 [ # # # # ]: 0 : if (rte_be_to_cpu_16(conf->vlan_vid) > 0xFFE)
3569 : 0 : return rte_flow_error_set(error, EINVAL,
3570 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3571 : : "VLAN VID value is too big");
3572 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) &&
3573 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
3574 : 0 : return rte_flow_error_set(error, ENOTSUP,
3575 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3576 : : "set VLAN VID action must follow push"
3577 : : " VLAN action or match on VLAN item");
3578 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID)
3579 : 0 : return rte_flow_error_set(error, ENOTSUP,
3580 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3581 : : "Multiple VLAN VID modifications are "
3582 : : "not supported");
3583 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3584 : 0 : return rte_flow_error_set(error, EINVAL,
3585 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3586 : : "wrong action order, port_id should "
3587 : : "be after set VLAN VID");
3588 : : return 0;
3589 : : }
3590 : :
3591 : : /*
3592 : : * Validate the FLAG action.
3593 : : *
3594 : : * @param[in] dev
3595 : : * Pointer to the rte_eth_dev structure.
3596 : : * @param[in] action_flags
3597 : : * Holds the actions detected until now.
3598 : : * @param[in] attr
3599 : : * Pointer to flow attributes
3600 : : * @param[out] error
3601 : : * Pointer to error structure.
3602 : : *
3603 : : * @return
3604 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3605 : : */
3606 : : static int
3607 : 0 : flow_dv_validate_action_flag(struct rte_eth_dev *dev,
3608 : : uint64_t action_flags,
3609 : : const struct rte_flow_attr *attr,
3610 : : struct rte_flow_error *error)
3611 : : {
3612 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3613 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
3614 : : int ret;
3615 : :
3616 : : /* Fall back if no extended metadata register support. */
3617 [ # # ]: 0 : if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
3618 : 0 : return mlx5_flow_validate_action_flag(action_flags, attr,
3619 : : error);
3620 : : /* Extensive metadata mode requires registers. */
3621 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
3622 : 0 : return rte_flow_error_set(error, ENOTSUP,
3623 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3624 : : "no metadata registers "
3625 : : "to support flag action");
3626 [ # # ]: 0 : if (!(priv->sh->dv_mark_mask & MLX5_FLOW_MARK_DEFAULT))
3627 : 0 : return rte_flow_error_set(error, ENOTSUP,
3628 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3629 : : "extended metadata register"
3630 : : " isn't available");
3631 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3632 [ # # ]: 0 : if (ret < 0)
3633 : : return ret;
3634 : : MLX5_ASSERT(ret > 0);
3635 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
3636 : 0 : return rte_flow_error_set(error, EINVAL,
3637 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3638 : : "can't mark and flag in same flow");
3639 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_FLAG)
3640 : 0 : return rte_flow_error_set(error, EINVAL,
3641 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3642 : : "can't have 2 flag"
3643 : : " actions in same flow");
3644 : : return 0;
3645 : : }
3646 : :
3647 : : /**
3648 : : * Validate MARK action.
3649 : : *
3650 : : * @param[in] dev
3651 : : * Pointer to the rte_eth_dev structure.
3652 : : * @param[in] action
3653 : : * Pointer to action.
3654 : : * @param[in] action_flags
3655 : : * Holds the actions detected until now.
3656 : : * @param[in] attr
3657 : : * Pointer to flow attributes
3658 : : * @param[out] error
3659 : : * Pointer to error structure.
3660 : : *
3661 : : * @return
3662 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3663 : : */
3664 : : static int
3665 : 0 : flow_dv_validate_action_mark(struct rte_eth_dev *dev,
3666 : : const struct rte_flow_action *action,
3667 : : uint64_t action_flags,
3668 : : const struct rte_flow_attr *attr,
3669 : : struct rte_flow_error *error)
3670 : : {
3671 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3672 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
3673 [ # # ]: 0 : const struct rte_flow_action_mark *mark = action->conf;
3674 : : int ret;
3675 : :
3676 [ # # ]: 0 : if (is_tunnel_offload_active(dev))
3677 : 0 : return rte_flow_error_set(error, ENOTSUP,
3678 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3679 : : "no mark action "
3680 : : "if tunnel offload active");
3681 : : /* Fall back if no extended metadata register support. */
3682 [ # # ]: 0 : if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
3683 : 0 : return mlx5_flow_validate_action_mark(dev, action, action_flags,
3684 : : attr, error);
3685 : : /* Extensive metadata mode requires registers. */
3686 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
3687 : 0 : return rte_flow_error_set(error, ENOTSUP,
3688 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3689 : : "no metadata registers "
3690 : : "to support mark action");
3691 [ # # ]: 0 : if (!priv->sh->dv_mark_mask)
3692 : 0 : return rte_flow_error_set(error, ENOTSUP,
3693 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3694 : : "extended metadata register"
3695 : : " isn't available");
3696 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3697 [ # # ]: 0 : if (ret < 0)
3698 : : return ret;
3699 : : MLX5_ASSERT(ret > 0);
3700 [ # # ]: 0 : if (!mark)
3701 : 0 : return rte_flow_error_set(error, EINVAL,
3702 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3703 : : "configuration cannot be null");
3704 [ # # ]: 0 : if (mark->id >= (MLX5_FLOW_MARK_MAX & priv->sh->dv_mark_mask))
3705 : 0 : return rte_flow_error_set(error, EINVAL,
3706 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3707 : 0 : &mark->id,
3708 : : "mark id exceeds the limit");
3709 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_FLAG)
3710 : 0 : return rte_flow_error_set(error, EINVAL,
3711 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3712 : : "can't flag and mark in same flow");
3713 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
3714 : 0 : return rte_flow_error_set(error, EINVAL,
3715 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3716 : : "can't have 2 mark actions in same"
3717 : : " flow");
3718 : : return 0;
3719 : : }
3720 : :
3721 : : /**
3722 : : * Validate SET_META action.
3723 : : *
3724 : : * @param[in] dev
3725 : : * Pointer to the rte_eth_dev structure.
3726 : : * @param[in] action
3727 : : * Pointer to the action structure.
3728 : : * @param[in] action_flags
3729 : : * Holds the actions detected until now.
3730 : : * @param[in] attr
3731 : : * Pointer to flow attributes
3732 : : * @param[out] error
3733 : : * Pointer to error structure.
3734 : : *
3735 : : * @return
3736 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3737 : : */
3738 : : static int
3739 : 0 : flow_dv_validate_action_set_meta(struct rte_eth_dev *dev,
3740 : : const struct rte_flow_action *action,
3741 : : uint64_t action_flags __rte_unused,
3742 : : const struct rte_flow_attr *attr,
3743 : : struct rte_flow_error *error)
3744 : : {
3745 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3746 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
3747 : : const struct rte_flow_action_set_meta *conf;
3748 : : uint32_t nic_mask = UINT32_MAX;
3749 : : int reg;
3750 : :
3751 [ # # # # ]: 0 : if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
3752 : 0 : !mlx5_flow_ext_mreg_supported(dev))
3753 : 0 : return rte_flow_error_set(error, ENOTSUP,
3754 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3755 : : "extended metadata register"
3756 : : " isn't supported");
3757 : 0 : reg = flow_dv_get_metadata_reg(dev, attr, error);
3758 [ # # ]: 0 : if (reg < 0)
3759 : : return reg;
3760 [ # # ]: 0 : if (reg == REG_NON)
3761 : 0 : return rte_flow_error_set(error, ENOTSUP,
3762 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3763 : : "unavailable extended metadata register");
3764 [ # # ]: 0 : if (reg != REG_A && reg != REG_B) {
3765 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3766 : :
3767 : 0 : nic_mask = priv->sh->dv_meta_mask;
3768 : : }
3769 [ # # ]: 0 : if (!(action->conf))
3770 : 0 : return rte_flow_error_set(error, EINVAL,
3771 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3772 : : "configuration cannot be null");
3773 : : conf = (const struct rte_flow_action_set_meta *)action->conf;
3774 [ # # ]: 0 : if (!conf->mask)
3775 : 0 : return rte_flow_error_set(error, EINVAL,
3776 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3777 : : "zero mask doesn't have any effect");
3778 [ # # ]: 0 : if (conf->mask & ~nic_mask)
3779 : 0 : return rte_flow_error_set(error, EINVAL,
3780 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3781 : : "meta data must be within reg C0");
3782 : : return 0;
3783 : : }
3784 : :
3785 : : /**
3786 : : * Validate SET_TAG action.
3787 : : *
3788 : : * @param[in] dev
3789 : : * Pointer to the rte_eth_dev structure.
3790 : : * @param[in] action
3791 : : * Pointer to the action structure.
3792 : : * @param[in] action_flags
3793 : : * Holds the actions detected until now.
3794 : : * @param[in] attr
3795 : : * Pointer to flow attributes
3796 : : * @param[out] error
3797 : : * Pointer to error structure.
3798 : : *
3799 : : * @return
3800 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3801 : : */
3802 : : static int
3803 : 0 : flow_dv_validate_action_set_tag(struct rte_eth_dev *dev,
3804 : : const struct rte_flow_action *action,
3805 : : uint64_t action_flags,
3806 : : const struct rte_flow_attr *attr,
3807 : : struct rte_flow_error *error)
3808 : : {
3809 : : const struct rte_flow_action_set_tag *conf;
3810 : : const uint64_t terminal_action_flags =
3811 : : MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE |
3812 : : MLX5_FLOW_ACTION_RSS;
3813 : : int ret;
3814 : :
3815 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
3816 : 0 : return rte_flow_error_set(error, ENOTSUP,
3817 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3818 : : "extensive metadata register"
3819 : : " isn't supported");
3820 [ # # ]: 0 : if (!(action->conf))
3821 : 0 : return rte_flow_error_set(error, EINVAL,
3822 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3823 : : "configuration cannot be null");
3824 : : conf = (const struct rte_flow_action_set_tag *)action->conf;
3825 [ # # ]: 0 : if (!conf->mask)
3826 : 0 : return rte_flow_error_set(error, EINVAL,
3827 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3828 : : "zero mask doesn't have any effect");
3829 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
3830 [ # # ]: 0 : if (ret < 0)
3831 : : return ret;
3832 [ # # # # ]: 0 : if (attr->ingress && (action_flags & terminal_action_flags))
3833 : 0 : return rte_flow_error_set(error, EINVAL,
3834 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3835 : : "set_tag has no effect"
3836 : : " with terminal actions");
3837 : : return 0;
3838 : : }
3839 : :
3840 : : /**
3841 : : * Indicates whether ASO aging is supported.
3842 : : *
3843 : : * @param[in] priv
3844 : : * Pointer to device private context structure.
3845 : : * @param[in] root
3846 : : * Whether action is on root table.
3847 : : *
3848 : : * @return
3849 : : * True when ASO aging is supported, false otherwise.
3850 : : */
3851 : : static inline bool
3852 : : flow_hit_aso_supported(const struct mlx5_priv *priv, bool root)
3853 : : {
3854 : : MLX5_ASSERT(priv);
3855 [ # # # # : 0 : return (priv->sh->flow_hit_aso_en && !root);
# # # # #
# ]
3856 : : }
3857 : :
3858 : : /**
3859 : : * Validate count action.
3860 : : *
3861 : : * @param[in] dev
3862 : : * Pointer to rte_eth_dev structure.
3863 : : * @param[in] shared
3864 : : * Indicator if action is shared.
3865 : : * @param[in] action_flags
3866 : : * Holds the actions detected until now.
3867 : : * @param[in] root
3868 : : * Whether action is on root table.
3869 : : * @param[out] error
3870 : : * Pointer to error structure.
3871 : : *
3872 : : * @return
3873 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3874 : : */
3875 : : static int
3876 : 0 : flow_dv_validate_action_count(struct rte_eth_dev *dev, bool shared,
3877 : : uint64_t action_flags,
3878 : : bool root,
3879 : : struct rte_flow_error *error)
3880 : : {
3881 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3882 : :
3883 [ # # ]: 0 : if (!priv->sh->cdev->config.devx)
3884 : 0 : goto notsup_err;
3885 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_COUNT)
3886 : 0 : return rte_flow_error_set(error, EINVAL,
3887 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3888 : : "duplicate count actions set");
3889 [ # # # # : 0 : if (shared && (action_flags & MLX5_FLOW_ACTION_AGE) &&
# # ]
3890 : : !flow_hit_aso_supported(priv, root))
3891 : 0 : return rte_flow_error_set(error, EINVAL,
3892 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3893 : : "old age and indirect count combination is not supported");
3894 : : #ifdef HAVE_IBV_FLOW_DEVX_COUNTERS
3895 : : return 0;
3896 : : #endif
3897 : : notsup_err:
3898 : 0 : return rte_flow_error_set
3899 : : (error, ENOTSUP,
3900 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3901 : : NULL,
3902 : : "count action not supported");
3903 : : }
3904 : :
3905 : : /**
3906 : : * Validate the L2 encap action.
3907 : : *
3908 : : * @param[in] dev
3909 : : * Pointer to the rte_eth_dev structure.
3910 : : * @param[in] action_flags
3911 : : * Holds the actions detected until now.
3912 : : * @param[in] action
3913 : : * Pointer to the action structure.
3914 : : * @param[in] attr
3915 : : * Pointer to flow attributes.
3916 : : * @param[out] error
3917 : : * Pointer to error structure.
3918 : : *
3919 : : * @return
3920 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3921 : : */
3922 : : int
3923 : 0 : mlx5_flow_dv_validate_action_l2_encap(struct rte_eth_dev *dev,
3924 : : uint64_t action_flags,
3925 : : const struct rte_flow_action *action,
3926 : : const struct rte_flow_attr *attr,
3927 : : struct rte_flow_error *error)
3928 : : {
3929 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
3930 : :
3931 [ # # ]: 0 : if (!(action->conf))
3932 : 0 : return rte_flow_error_set(error, EINVAL,
3933 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3934 : : "configuration cannot be null");
3935 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
3936 : 0 : return rte_flow_error_set(error, EINVAL,
3937 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3938 : : "can only have a single encap action "
3939 : : "in a flow");
3940 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
3941 : 0 : return rte_flow_error_set(error, ENOTSUP,
3942 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3943 : : "encap action for VF representor "
3944 : : "not supported on NIC table");
3945 : : return 0;
3946 : : }
3947 : :
3948 : : /**
3949 : : * Validate a decap action.
3950 : : *
3951 : : * @param[in] dev
3952 : : * Pointer to the rte_eth_dev structure.
3953 : : * @param[in] action_flags
3954 : : * Holds the actions detected until now.
3955 : : * @param[in] action
3956 : : * Pointer to the action structure.
3957 : : * @param[in] item_flags
3958 : : * Holds the items detected.
3959 : : * @param[in] attr
3960 : : * Pointer to flow attributes
3961 : : * @param[out] error
3962 : : * Pointer to error structure.
3963 : : *
3964 : : * @return
3965 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3966 : : */
3967 : : int
3968 : 0 : mlx5_flow_dv_validate_action_decap(struct rte_eth_dev *dev,
3969 : : uint64_t action_flags,
3970 : : const struct rte_flow_action *action,
3971 : : const uint64_t item_flags,
3972 : : const struct rte_flow_attr *attr,
3973 : : struct rte_flow_error *error)
3974 : : {
3975 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
3976 : :
3977 [ # # ]: 0 : if (priv->sh->cdev->config.hca_attr.scatter_fcs_w_decap_disable &&
3978 [ # # ]: 0 : !priv->sh->config.decap_en)
3979 : 0 : return rte_flow_error_set(error, ENOTSUP,
3980 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3981 : : "decap is not enabled");
3982 [ # # ]: 0 : if (action_flags & MLX5_FLOW_XCAP_ACTIONS)
3983 : 0 : return rte_flow_error_set(error, ENOTSUP,
3984 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3985 [ # # ]: 0 : action_flags &
3986 : : MLX5_FLOW_ACTION_DECAP ? "can only "
3987 : : "have a single decap action" : "decap "
3988 : : "after encap is not supported");
3989 [ # # ]: 0 : if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
3990 : 0 : return rte_flow_error_set(error, EINVAL,
3991 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3992 : : "can't have decap action after"
3993 : : " modify action");
3994 [ # # ]: 0 : if (attr->egress)
3995 : 0 : return rte_flow_error_set(error, ENOTSUP,
3996 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
3997 : : NULL,
3998 : : "decap action not supported for "
3999 : : "egress");
4000 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
4001 : 0 : return rte_flow_error_set(error, ENOTSUP,
4002 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4003 : : "decap action for VF representor "
4004 : : "not supported on NIC table");
4005 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_DECAP &&
4006 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_VXLAN))
4007 : 0 : return rte_flow_error_set(error, ENOTSUP,
4008 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4009 : : "VXLAN item should be present for VXLAN decap");
4010 : : return 0;
4011 : : }
4012 : :
4013 : : const struct rte_flow_action_raw_decap empty_decap = {.data = NULL, .size = 0,};
4014 : :
4015 : : /**
4016 : : * Validate the raw encap and decap actions.
4017 : : *
4018 : : * @param[in] dev
4019 : : * Pointer to the rte_eth_dev structure.
4020 : : * @param[in] decap
4021 : : * Pointer to the decap action.
4022 : : * @param[in] encap
4023 : : * Pointer to the encap action.
4024 : : * @param[in] attr
4025 : : * Pointer to flow attributes
4026 : : * @param[in/out] action_flags
4027 : : * Holds the actions detected until now.
4028 : : * @param[out] actions_n
4029 : : * pointer to the number of actions counter.
4030 : : * @param[in] action
4031 : : * Pointer to the action structure.
4032 : : * @param[in] item_flags
4033 : : * Holds the items detected.
4034 : : * @param[out] error
4035 : : * Pointer to error structure.
4036 : : *
4037 : : * @return
4038 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4039 : : */
4040 : : int
4041 : 0 : mlx5_flow_dv_validate_action_raw_encap_decap
4042 : : (struct rte_eth_dev *dev,
4043 : : const struct rte_flow_action_raw_decap *decap,
4044 : : const struct rte_flow_action_raw_encap *encap,
4045 : : const struct rte_flow_attr *attr, uint64_t *action_flags,
4046 : : int *actions_n, const struct rte_flow_action *action,
4047 : : uint64_t item_flags, struct rte_flow_error *error)
4048 : : {
4049 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
4050 : : int ret;
4051 : :
4052 [ # # ]: 0 : if (encap) {
4053 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
4054 [ # # # # ]: 0 : if (!encap->size || !encap->data)
4055 : 0 : return rte_flow_error_set
4056 : : (error, EINVAL,
4057 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL, "raw encap data cannot be empty");
4058 : : } else {
4059 [ # # ]: 0 : if (!encap->size)
4060 : 0 : return rte_flow_error_set
4061 : : (error, EINVAL,
4062 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL, "raw encap size cannot be 0");
4063 : : }
4064 : : }
4065 [ # # ]: 0 : if (decap && encap) {
4066 [ # # ]: 0 : if (decap->size <= MLX5_ENCAPSULATION_DECISION_SIZE &&
4067 [ # # ]: 0 : encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4068 : : /* L3 encap. */
4069 : : decap = NULL;
4070 [ # # ]: 0 : else if (encap->size <=
4071 [ # # ]: 0 : MLX5_ENCAPSULATION_DECISION_SIZE &&
4072 : : decap->size >
4073 : : MLX5_ENCAPSULATION_DECISION_SIZE)
4074 : : /* L3 decap. */
4075 : : encap = NULL;
4076 [ # # ]: 0 : else if (encap->size >
4077 [ # # ]: 0 : MLX5_ENCAPSULATION_DECISION_SIZE &&
4078 : : decap->size >
4079 : : MLX5_ENCAPSULATION_DECISION_SIZE)
4080 : : /* 2 L2 actions: encap and decap. */
4081 : : ;
4082 : : else
4083 : 0 : return rte_flow_error_set(error,
4084 : : ENOTSUP,
4085 : : RTE_FLOW_ERROR_TYPE_ACTION,
4086 : : NULL, "unsupported too small "
4087 : : "raw decap and too small raw "
4088 : : "encap combination");
4089 : : }
4090 [ # # ]: 0 : if (decap) {
4091 : 0 : ret = mlx5_flow_dv_validate_action_decap(dev, *action_flags,
4092 : : action,
4093 : : item_flags, attr,
4094 : : error);
4095 [ # # ]: 0 : if (ret < 0)
4096 : : return ret;
4097 : 0 : *action_flags |= MLX5_FLOW_ACTION_DECAP;
4098 : 0 : ++(*actions_n);
4099 : : }
4100 [ # # ]: 0 : if (encap) {
4101 [ # # ]: 0 : if (encap->size <= MLX5_ENCAPSULATION_DECISION_SIZE)
4102 : 0 : return rte_flow_error_set(error, ENOTSUP,
4103 : : RTE_FLOW_ERROR_TYPE_ACTION,
4104 : : NULL,
4105 : : "small raw encap size");
4106 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_ENCAP)
4107 : 0 : return rte_flow_error_set(error, EINVAL,
4108 : : RTE_FLOW_ERROR_TYPE_ACTION,
4109 : : NULL,
4110 : : "more than one encap action");
4111 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
4112 : 0 : return rte_flow_error_set
4113 : : (error, ENOTSUP,
4114 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4115 : : "encap action for VF representor "
4116 : : "not supported on NIC table");
4117 : 0 : *action_flags |= MLX5_FLOW_ACTION_ENCAP;
4118 : 0 : ++(*actions_n);
4119 : : }
4120 : : return 0;
4121 : : }
4122 : :
4123 : : /*
4124 : : * Validate the ASO CT action.
4125 : : *
4126 : : * @param[in] dev
4127 : : * Pointer to the rte_eth_dev structure.
4128 : : * @param[in] action_flags
4129 : : * Holds the actions detected until now.
4130 : : * @param[in] item_flags
4131 : : * The items found in this flow rule.
4132 : : * @param root
4133 : : * Whether action is on root table.
4134 : : * @param[out] error
4135 : : * Pointer to error structure.
4136 : : *
4137 : : * @return
4138 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4139 : : */
4140 : : int
4141 : 0 : mlx5_flow_dv_validate_action_aso_ct(struct rte_eth_dev *dev,
4142 : : uint64_t action_flags,
4143 : : uint64_t item_flags,
4144 : : bool root,
4145 : : struct rte_flow_error *error)
4146 : : {
4147 : : RTE_SET_USED(dev);
4148 : :
4149 [ # # ]: 0 : if (root)
4150 : 0 : return rte_flow_error_set(error, ENOTSUP,
4151 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4152 : : NULL,
4153 : : "Only support non-root table");
4154 [ # # ]: 0 : if (action_flags & MLX5_FLOW_FATE_ACTIONS)
4155 : 0 : return rte_flow_error_set(error, ENOTSUP,
4156 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4157 : : "CT cannot follow a fate action");
4158 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_METER) ||
4159 : : (action_flags & MLX5_FLOW_ACTION_AGE)) {
4160 [ # # ]: 0 : if (!mlx5_hws_active(dev))
4161 : 0 : return rte_flow_error_set(error, EINVAL,
4162 : : RTE_FLOW_ERROR_TYPE_ACTION,
4163 : : NULL, "Only one ASO action is supported");
4164 : : }
4165 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
4166 : 0 : return rte_flow_error_set(error, EINVAL,
4167 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4168 : : "Encap cannot exist before CT");
4169 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP))
4170 : 0 : return rte_flow_error_set(error, EINVAL,
4171 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4172 : : "Not a outer TCP packet");
4173 : : return 0;
4174 : : }
4175 : :
4176 : : /**
4177 : : * Validate METER_COLOR item.
4178 : : *
4179 : : * @param[in] dev
4180 : : * Pointer to the rte_eth_dev structure.
4181 : : * @param[in] item
4182 : : * Item specification.
4183 : : * @param[in] attr
4184 : : * Attributes of flow that includes this item.
4185 : : * @param[out] error
4186 : : * Pointer to error structure.
4187 : : *
4188 : : * @return
4189 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4190 : : */
4191 : : static int
4192 : 0 : flow_dv_validate_item_meter_color(struct rte_eth_dev *dev,
4193 : : const struct rte_flow_item *item,
4194 : : const struct rte_flow_attr *attr __rte_unused,
4195 : : struct rte_flow_error *error)
4196 : : {
4197 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4198 : 0 : const struct rte_flow_item_meter_color *spec = item->spec;
4199 : 0 : const struct rte_flow_item_meter_color *mask = item->mask;
4200 : 0 : struct rte_flow_item_meter_color nic_mask = {
4201 : : .color = RTE_COLORS
4202 : : };
4203 : : int ret;
4204 : :
4205 [ # # ]: 0 : if (priv->sh->registers.aso_reg == REG_NON)
4206 : 0 : return rte_flow_error_set(error, ENOTSUP,
4207 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
4208 : : "meter color register"
4209 : : " isn't available");
4210 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, error);
4211 [ # # ]: 0 : if (ret < 0)
4212 : : return ret;
4213 [ # # ]: 0 : if (!spec)
4214 : 0 : return rte_flow_error_set(error, EINVAL,
4215 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4216 : 0 : item->spec,
4217 : : "data cannot be empty");
4218 [ # # ]: 0 : if (spec->color > RTE_COLORS)
4219 : 0 : return rte_flow_error_set(error, EINVAL,
4220 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4221 : 0 : &spec->color,
4222 : : "meter color is invalid");
4223 [ # # ]: 0 : if (!mask)
4224 : : mask = &rte_flow_item_meter_color_mask;
4225 [ # # ]: 0 : if (!mask->color)
4226 : 0 : return rte_flow_error_set(error, EINVAL,
4227 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
4228 : : "mask cannot be zero");
4229 : :
4230 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
4231 : : (const uint8_t *)&nic_mask,
4232 : : sizeof(struct rte_flow_item_meter_color),
4233 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
4234 : : if (ret < 0)
4235 : : return ret;
4236 : : return 0;
4237 : : }
4238 : :
4239 : : /**
4240 : : * Validate aggregated affinity item.
4241 : : *
4242 : : * @param[in] dev
4243 : : * Pointer to the rte_eth_dev structure.
4244 : : * @param[in] item
4245 : : * Item specification.
4246 : : * @param[in] attr
4247 : : * Attributes of flow that includes this item.
4248 : : * @param[out] error
4249 : : * Pointer to error structure.
4250 : : *
4251 : : * @return
4252 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4253 : : */
4254 : : static int
4255 : 0 : flow_dv_validate_item_aggr_affinity(struct rte_eth_dev *dev,
4256 : : const struct rte_flow_item *item,
4257 : : const struct rte_flow_attr *attr,
4258 : : struct rte_flow_error *error)
4259 : : {
4260 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4261 : 0 : const struct rte_flow_item_aggr_affinity *spec = item->spec;
4262 : 0 : const struct rte_flow_item_aggr_affinity *mask = item->mask;
4263 : 0 : struct rte_flow_item_aggr_affinity nic_mask = {
4264 : : .affinity = UINT8_MAX
4265 : : };
4266 : : int ret;
4267 : :
4268 [ # # ]: 0 : if (!priv->sh->lag_rx_port_affinity_en)
4269 : 0 : return rte_flow_error_set(error, EINVAL,
4270 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
4271 : : "Unsupported aggregated affinity with Older FW");
4272 [ # # # # : 0 : if ((attr->transfer && priv->fdb_def_rule) ||
# # ]
4273 [ # # ]: 0 : attr->egress || attr->group)
4274 : 0 : return rte_flow_error_set(error, ENOTSUP,
4275 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4276 : : item->spec,
4277 : : "aggregated affinity is not supported with egress or FDB on non root table");
4278 [ # # ]: 0 : if (!spec)
4279 : 0 : return rte_flow_error_set(error, EINVAL,
4280 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4281 : : item->spec,
4282 : : "data cannot be empty");
4283 [ # # ]: 0 : if (spec->affinity == 0)
4284 : 0 : return rte_flow_error_set(error, ENOTSUP,
4285 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4286 : : item->spec,
4287 : : "zero affinity number not supported");
4288 [ # # ]: 0 : if (spec->affinity > priv->num_lag_ports)
4289 : 0 : return rte_flow_error_set(error, ENOTSUP,
4290 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4291 : : item->spec,
4292 : : "exceed max affinity number in lag ports");
4293 [ # # ]: 0 : if (!mask)
4294 : : mask = &rte_flow_item_aggr_affinity_mask;
4295 [ # # ]: 0 : if (!mask->affinity)
4296 : 0 : return rte_flow_error_set(error, EINVAL,
4297 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
4298 : : "mask cannot be zero");
4299 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
4300 : : (const uint8_t *)&nic_mask,
4301 : : sizeof(struct rte_flow_item_aggr_affinity),
4302 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
4303 : : if (ret < 0)
4304 : : return ret;
4305 : : return 0;
4306 : : }
4307 : :
4308 : : int
4309 : 0 : flow_encap_decap_match_cb(void *tool_ctx __rte_unused,
4310 : : struct mlx5_list_entry *entry, void *cb_ctx)
4311 : : {
4312 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4313 : 0 : struct mlx5_flow_dv_encap_decap_resource *ctx_resource = ctx->data;
4314 : : struct mlx5_flow_dv_encap_decap_resource *resource;
4315 : :
4316 : : resource = container_of(entry, struct mlx5_flow_dv_encap_decap_resource,
4317 : : entry);
4318 [ # # ]: 0 : if (resource->reformat_type == ctx_resource->reformat_type &&
4319 : 0 : resource->ft_type == ctx_resource->ft_type &&
4320 [ # # ]: 0 : resource->flags == ctx_resource->flags &&
4321 [ # # ]: 0 : resource->size == ctx_resource->size &&
4322 : 0 : !memcmp((const void *)resource->buf,
4323 [ # # ]: 0 : (const void *)ctx_resource->buf,
4324 : : resource->size))
4325 : 0 : return 0;
4326 : : return -1;
4327 : : }
4328 : :
4329 : : struct mlx5_list_entry *
4330 : 0 : flow_encap_decap_create_cb(void *tool_ctx, void *cb_ctx)
4331 : : {
4332 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4333 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4334 : : struct mlx5dv_dr_domain *domain;
4335 : 0 : struct mlx5_flow_dv_encap_decap_resource *ctx_resource = ctx->data;
4336 : : struct mlx5_flow_dv_encap_decap_resource *resource;
4337 : : uint32_t idx;
4338 : : int ret = 0;
4339 : : #ifdef HAVE_MLX5_HWS_SUPPORT
4340 : : struct mlx5dr_action_reformat_header hdr;
4341 : : #endif
4342 : :
4343 : : /* Register new encap/decap resource. */
4344 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], &idx);
4345 [ # # ]: 0 : if (!resource) {
4346 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4347 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4348 : : "cannot allocate resource memory");
4349 : 0 : return NULL;
4350 : : }
4351 : 0 : *resource = *ctx_resource;
4352 [ # # ]: 0 : if (sh->config.dv_flow_en == 2) {
4353 : : #ifdef HAVE_MLX5_HWS_SUPPORT
4354 : 0 : hdr.sz = ctx_resource->size;
4355 : 0 : hdr.data = ctx_resource->buf;
4356 : 0 : resource->action = mlx5dr_action_create_reformat
4357 : 0 : (ctx->data2, (enum mlx5dr_action_type)ctx_resource->reformat_type, 1,
4358 : 0 : &hdr, 0, ctx_resource->flags);
4359 [ # # ]: 0 : if (!resource->action)
4360 : : ret = -1;
4361 : : #else
4362 : : ret = -1;
4363 : : #endif
4364 : : } else {
4365 [ # # ]: 0 : if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
4366 : 0 : domain = sh->fdb_domain;
4367 [ # # ]: 0 : else if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
4368 : 0 : domain = sh->rx_domain;
4369 : : else
4370 : 0 : domain = sh->tx_domain;
4371 [ # # ]: 0 : ret = mlx5_flow_os_create_flow_action_packet_reformat(sh->cdev->ctx,
4372 : : domain, resource,
4373 : : &resource->action);
4374 : : }
4375 : : if (ret) {
4376 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], idx);
4377 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4378 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4379 : : NULL, "cannot create action");
4380 : 0 : return NULL;
4381 : : }
4382 : 0 : resource->idx = idx;
4383 : 0 : return &resource->entry;
4384 : : }
4385 : :
4386 : : struct mlx5_list_entry *
4387 : 0 : flow_encap_decap_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
4388 : : void *cb_ctx)
4389 : : {
4390 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4391 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4392 : : struct mlx5_flow_dv_encap_decap_resource *cache_resource;
4393 : : uint32_t idx;
4394 : :
4395 : 0 : cache_resource = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
4396 : : &idx);
4397 [ # # ]: 0 : if (!cache_resource) {
4398 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4399 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4400 : : "cannot allocate resource memory");
4401 : 0 : return NULL;
4402 : : }
4403 : : memcpy(cache_resource, oentry, sizeof(*cache_resource));
4404 : 0 : cache_resource->idx = idx;
4405 : 0 : return &cache_resource->entry;
4406 : : }
4407 : :
4408 : : void
4409 : 0 : flow_encap_decap_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4410 : : {
4411 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4412 : : struct mlx5_flow_dv_encap_decap_resource *res =
4413 : : container_of(entry, typeof(*res), entry);
4414 : :
4415 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], res->idx);
4416 : 0 : }
4417 : :
4418 : : int
4419 : 0 : __flow_encap_decap_resource_register(struct rte_eth_dev *dev,
4420 : : struct mlx5_flow_dv_encap_decap_resource *resource,
4421 : : bool is_root,
4422 : : struct mlx5_flow_dv_encap_decap_resource **encap_decap,
4423 : : struct rte_flow_error *error)
4424 : : {
4425 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4426 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
4427 : : struct mlx5_list_entry *entry;
4428 : : union {
4429 : : struct {
4430 : : uint32_t ft_type:8;
4431 : : uint32_t refmt_type:8;
4432 : : /*
4433 : : * Header reformat actions can be shared between
4434 : : * non-root tables. One bit to indicate non-root
4435 : : * table or not.
4436 : : */
4437 : : uint32_t is_root:1;
4438 : : uint32_t reserve:15;
4439 : : };
4440 : : uint32_t v32;
4441 : 0 : } encap_decap_key = {
4442 : : {
4443 : 0 : .ft_type = resource->ft_type,
4444 : 0 : .refmt_type = resource->reformat_type,
4445 : : .is_root = is_root,
4446 : : .reserve = 0,
4447 : : }
4448 : : };
4449 : 0 : struct mlx5_flow_cb_ctx ctx = {
4450 : : .error = error,
4451 : : .data = resource,
4452 : 0 : .data2 = priv->dr_ctx,
4453 : : };
4454 : : struct mlx5_hlist *encaps_decaps;
4455 : : uint64_t key64;
4456 : :
4457 : 0 : encaps_decaps = flow_dv_hlist_prepare(sh, &sh->encaps_decaps,
4458 : : "encaps_decaps",
4459 : : MLX5_FLOW_ENCAP_DECAP_HTABLE_SZ,
4460 : : true, true, sh,
4461 : : flow_encap_decap_create_cb,
4462 : : flow_encap_decap_match_cb,
4463 : : flow_encap_decap_remove_cb,
4464 : : flow_encap_decap_clone_cb,
4465 : : flow_encap_decap_clone_free_cb,
4466 : : error);
4467 [ # # ]: 0 : if (unlikely(!encaps_decaps))
4468 : 0 : return -rte_errno;
4469 : 0 : key64 = __rte_raw_cksum(&encap_decap_key.v32,
4470 : : sizeof(encap_decap_key.v32), 0);
4471 [ # # ]: 0 : if (resource->reformat_type !=
4472 : 0 : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2 &&
4473 [ # # ]: 0 : resource->size)
4474 : 0 : key64 = __rte_raw_cksum(resource->buf, resource->size, key64);
4475 : 0 : entry = mlx5_hlist_register(encaps_decaps, key64, &ctx);
4476 [ # # ]: 0 : if (!entry)
4477 : 0 : return -rte_errno;
4478 : 0 : *encap_decap = container_of(entry, typeof(*resource), entry);
4479 : 0 : return 0;
4480 : : }
4481 : :
4482 : : /**
4483 : : * Find existing encap/decap resource or create and register a new one.
4484 : : *
4485 : : * @param[in, out] dev
4486 : : * Pointer to rte_eth_dev structure.
4487 : : * @param[in, out] resource
4488 : : * Pointer to encap/decap resource.
4489 : : * @param[in, out] dev_flow
4490 : : * Pointer to the dev_flow.
4491 : : * @param[out] error
4492 : : * pointer to error structure.
4493 : : *
4494 : : * @return
4495 : : * 0 on success otherwise -errno and errno is set.
4496 : : */
4497 : : static int
4498 : 0 : flow_dv_encap_decap_resource_register
4499 : : (struct rte_eth_dev *dev,
4500 : : struct mlx5_flow_dv_encap_decap_resource *resource,
4501 : : struct mlx5_flow *dev_flow,
4502 : : struct rte_flow_error *error)
4503 : : {
4504 : : int ret;
4505 : :
4506 : 0 : resource->flags = dev_flow->dv.group ? 0 : 1;
4507 : 0 : ret = __flow_encap_decap_resource_register(dev, resource, !!dev_flow->dv.group,
4508 : : &dev_flow->dv.encap_decap, error);
4509 [ # # ]: 0 : if (ret)
4510 : : return ret;
4511 : 0 : dev_flow->handle->dvh.rix_encap_decap = dev_flow->dv.encap_decap->idx;
4512 : 0 : return 0;
4513 : : }
4514 : :
4515 : : /**
4516 : : * Find existing table jump resource or create and register a new one.
4517 : : *
4518 : : * @param[in, out] dev
4519 : : * Pointer to rte_eth_dev structure.
4520 : : * @param[in, out] tbl
4521 : : * Pointer to flow table resource.
4522 : : * @parm[in, out] dev_flow
4523 : : * Pointer to the dev_flow.
4524 : : * @param[out] error
4525 : : * pointer to error structure.
4526 : : *
4527 : : * @return
4528 : : * 0 on success otherwise -errno and errno is set.
4529 : : */
4530 : : static int
4531 : : flow_dv_jump_tbl_resource_register
4532 : : (struct rte_eth_dev *dev __rte_unused,
4533 : : struct mlx5_flow_tbl_resource *tbl,
4534 : : struct mlx5_flow *dev_flow,
4535 : : struct rte_flow_error *error __rte_unused)
4536 : : {
4537 : : struct mlx5_flow_tbl_data_entry *tbl_data =
4538 : 0 : container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
4539 : :
4540 : : MLX5_ASSERT(tbl);
4541 : : MLX5_ASSERT(tbl_data->jump.action);
4542 : 0 : dev_flow->handle->rix_jump = tbl_data->idx;
4543 : 0 : dev_flow->dv.jump = &tbl_data->jump;
4544 : : return 0;
4545 : : }
4546 : :
4547 : : int
4548 : 0 : flow_dv_port_id_match_cb(void *tool_ctx __rte_unused,
4549 : : struct mlx5_list_entry *entry, void *cb_ctx)
4550 : : {
4551 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4552 : 0 : struct mlx5_flow_dv_port_id_action_resource *ref = ctx->data;
4553 : : struct mlx5_flow_dv_port_id_action_resource *res =
4554 : : container_of(entry, typeof(*res), entry);
4555 : :
4556 : 0 : return ref->port_id != res->port_id;
4557 : : }
4558 : :
4559 : : struct mlx5_list_entry *
4560 : 0 : flow_dv_port_id_create_cb(void *tool_ctx, void *cb_ctx)
4561 : : {
4562 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4563 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4564 : 0 : struct mlx5_flow_dv_port_id_action_resource *ref = ctx->data;
4565 : : struct mlx5_flow_dv_port_id_action_resource *resource;
4566 : : uint32_t idx;
4567 : : int ret;
4568 : :
4569 : : /* Register new port id action resource. */
4570 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID], &idx);
4571 [ # # ]: 0 : if (!resource) {
4572 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4573 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4574 : : "cannot allocate port_id action memory");
4575 : 0 : return NULL;
4576 : : }
4577 : 0 : *resource = *ref;
4578 : 0 : ret = mlx5_flow_os_create_flow_action_dest_port(sh->fdb_domain,
4579 : : ref->port_id,
4580 : : &resource->action);
4581 : : if (ret) {
4582 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], idx);
4583 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4584 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4585 : : "cannot create action");
4586 : 0 : return NULL;
4587 : : }
4588 : 0 : resource->idx = idx;
4589 : 0 : return &resource->entry;
4590 : : }
4591 : :
4592 : : struct mlx5_list_entry *
4593 : 0 : flow_dv_port_id_clone_cb(void *tool_ctx,
4594 : : struct mlx5_list_entry *entry __rte_unused,
4595 : : void *cb_ctx)
4596 : : {
4597 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4598 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4599 : : struct mlx5_flow_dv_port_id_action_resource *resource;
4600 : : uint32_t idx;
4601 : :
4602 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID], &idx);
4603 [ # # ]: 0 : if (!resource) {
4604 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4605 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4606 : : "cannot allocate port_id action memory");
4607 : 0 : return NULL;
4608 : : }
4609 : : memcpy(resource, entry, sizeof(*resource));
4610 : 0 : resource->idx = idx;
4611 : 0 : return &resource->entry;
4612 : : }
4613 : :
4614 : : void
4615 : 0 : flow_dv_port_id_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4616 : : {
4617 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4618 : : struct mlx5_flow_dv_port_id_action_resource *resource =
4619 : : container_of(entry, typeof(*resource), entry);
4620 : :
4621 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], resource->idx);
4622 : 0 : }
4623 : :
4624 : : /**
4625 : : * Find existing table port ID resource or create and register a new one.
4626 : : *
4627 : : * @param[in, out] dev
4628 : : * Pointer to rte_eth_dev structure.
4629 : : * @param[in, out] ref
4630 : : * Pointer to port ID action resource reference.
4631 : : * @parm[in, out] dev_flow
4632 : : * Pointer to the dev_flow.
4633 : : * @param[out] error
4634 : : * pointer to error structure.
4635 : : *
4636 : : * @return
4637 : : * 0 on success otherwise -errno and errno is set.
4638 : : */
4639 : : static int
4640 : 0 : flow_dv_port_id_action_resource_register
4641 : : (struct rte_eth_dev *dev,
4642 : : struct mlx5_flow_dv_port_id_action_resource *ref,
4643 : : struct mlx5_flow *dev_flow,
4644 : : struct rte_flow_error *error)
4645 : : {
4646 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4647 : : struct mlx5_list_entry *entry;
4648 : : struct mlx5_flow_dv_port_id_action_resource *resource;
4649 : 0 : struct mlx5_flow_cb_ctx ctx = {
4650 : : .error = error,
4651 : : .data = ref,
4652 : : };
4653 : :
4654 : 0 : entry = mlx5_list_register(priv->sh->port_id_action_list, &ctx);
4655 [ # # ]: 0 : if (!entry)
4656 : 0 : return -rte_errno;
4657 : : resource = container_of(entry, typeof(*resource), entry);
4658 : 0 : dev_flow->dv.port_id_action = resource;
4659 : 0 : dev_flow->handle->rix_port_id_action = resource->idx;
4660 : 0 : return 0;
4661 : : }
4662 : :
4663 : : int
4664 : 0 : flow_dv_push_vlan_match_cb(void *tool_ctx __rte_unused,
4665 : : struct mlx5_list_entry *entry, void *cb_ctx)
4666 : : {
4667 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4668 : 0 : struct mlx5_flow_dv_push_vlan_action_resource *ref = ctx->data;
4669 : : struct mlx5_flow_dv_push_vlan_action_resource *res =
4670 : : container_of(entry, typeof(*res), entry);
4671 : :
4672 : 0 : return ref->vlan_tag != res->vlan_tag || ref->ft_type != res->ft_type;
4673 : : }
4674 : :
4675 : : struct mlx5_list_entry *
4676 : 0 : flow_dv_push_vlan_create_cb(void *tool_ctx, void *cb_ctx)
4677 : : {
4678 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4679 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4680 : 0 : struct mlx5_flow_dv_push_vlan_action_resource *ref = ctx->data;
4681 : : struct mlx5_flow_dv_push_vlan_action_resource *resource;
4682 : : struct mlx5dv_dr_domain *domain;
4683 : : uint32_t idx;
4684 : : int ret;
4685 : :
4686 : : /* Register new port id action resource. */
4687 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PUSH_VLAN], &idx);
4688 [ # # ]: 0 : if (!resource) {
4689 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4690 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4691 : : "cannot allocate push_vlan action memory");
4692 : 0 : return NULL;
4693 : : }
4694 : 0 : *resource = *ref;
4695 [ # # ]: 0 : if (ref->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
4696 : 0 : domain = sh->fdb_domain;
4697 [ # # ]: 0 : else if (ref->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
4698 : 0 : domain = sh->rx_domain;
4699 : : else
4700 : 0 : domain = sh->tx_domain;
4701 : 0 : ret = mlx5_flow_os_create_flow_action_push_vlan(domain, ref->vlan_tag,
4702 : : &resource->action);
4703 : : if (ret) {
4704 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
4705 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4706 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4707 : : "cannot create push vlan action");
4708 : 0 : return NULL;
4709 : : }
4710 : 0 : resource->idx = idx;
4711 : 0 : return &resource->entry;
4712 : : }
4713 : :
4714 : : struct mlx5_list_entry *
4715 : 0 : flow_dv_push_vlan_clone_cb(void *tool_ctx,
4716 : : struct mlx5_list_entry *entry __rte_unused,
4717 : : void *cb_ctx)
4718 : : {
4719 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4720 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4721 : : struct mlx5_flow_dv_push_vlan_action_resource *resource;
4722 : : uint32_t idx;
4723 : :
4724 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PUSH_VLAN], &idx);
4725 [ # # ]: 0 : if (!resource) {
4726 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4727 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4728 : : "cannot allocate push_vlan action memory");
4729 : 0 : return NULL;
4730 : : }
4731 : : memcpy(resource, entry, sizeof(*resource));
4732 : 0 : resource->idx = idx;
4733 : 0 : return &resource->entry;
4734 : : }
4735 : :
4736 : : void
4737 : 0 : flow_dv_push_vlan_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4738 : : {
4739 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4740 : : struct mlx5_flow_dv_push_vlan_action_resource *resource =
4741 : : container_of(entry, typeof(*resource), entry);
4742 : :
4743 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], resource->idx);
4744 : 0 : }
4745 : :
4746 : : /**
4747 : : * Find existing push vlan resource or create and register a new one.
4748 : : *
4749 : : * @param [in, out] dev
4750 : : * Pointer to rte_eth_dev structure.
4751 : : * @param[in, out] ref
4752 : : * Pointer to port ID action resource reference.
4753 : : * @parm[in, out] dev_flow
4754 : : * Pointer to the dev_flow.
4755 : : * @param[out] error
4756 : : * pointer to error structure.
4757 : : *
4758 : : * @return
4759 : : * 0 on success otherwise -errno and errno is set.
4760 : : */
4761 : : static int
4762 : 0 : flow_dv_push_vlan_action_resource_register
4763 : : (struct rte_eth_dev *dev,
4764 : : struct mlx5_flow_dv_push_vlan_action_resource *ref,
4765 : : struct mlx5_flow *dev_flow,
4766 : : struct rte_flow_error *error)
4767 : : {
4768 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4769 : : struct mlx5_flow_dv_push_vlan_action_resource *resource;
4770 : : struct mlx5_list_entry *entry;
4771 : 0 : struct mlx5_flow_cb_ctx ctx = {
4772 : : .error = error,
4773 : : .data = ref,
4774 : : };
4775 : :
4776 : 0 : entry = mlx5_list_register(priv->sh->push_vlan_action_list, &ctx);
4777 [ # # ]: 0 : if (!entry)
4778 : 0 : return -rte_errno;
4779 : : resource = container_of(entry, typeof(*resource), entry);
4780 : :
4781 : 0 : dev_flow->handle->dvh.rix_push_vlan = resource->idx;
4782 : 0 : dev_flow->dv.push_vlan_res = resource;
4783 : 0 : return 0;
4784 : : }
4785 : :
4786 : : /**
4787 : : * Get the size of specific rte_flow_item_type hdr size
4788 : : *
4789 : : * @param[in] item_type
4790 : : * Tested rte_flow_item_type.
4791 : : *
4792 : : * @return
4793 : : * sizeof struct item_type, 0 if void or irrelevant.
4794 : : */
4795 : : size_t
4796 [ # # ]: 0 : flow_dv_get_item_hdr_len(const enum rte_flow_item_type item_type)
4797 : : {
4798 : : size_t retval;
4799 : :
4800 : : switch (item_type) {
4801 : : case RTE_FLOW_ITEM_TYPE_ETH:
4802 : : retval = sizeof(struct rte_ether_hdr);
4803 : : break;
4804 : : case RTE_FLOW_ITEM_TYPE_VLAN:
4805 : : retval = sizeof(struct rte_vlan_hdr);
4806 : : break;
4807 : : case RTE_FLOW_ITEM_TYPE_IPV4:
4808 : : retval = sizeof(struct rte_ipv4_hdr);
4809 : : break;
4810 : : case RTE_FLOW_ITEM_TYPE_IPV6:
4811 : : retval = sizeof(struct rte_ipv6_hdr);
4812 : : break;
4813 : : case RTE_FLOW_ITEM_TYPE_UDP:
4814 : : retval = sizeof(struct rte_udp_hdr);
4815 : : break;
4816 : : case RTE_FLOW_ITEM_TYPE_TCP:
4817 : : retval = sizeof(struct rte_tcp_hdr);
4818 : : break;
4819 : : case RTE_FLOW_ITEM_TYPE_VXLAN:
4820 : : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
4821 : : retval = sizeof(struct rte_vxlan_hdr);
4822 : : break;
4823 : : case RTE_FLOW_ITEM_TYPE_GRE:
4824 : : case RTE_FLOW_ITEM_TYPE_NVGRE:
4825 : : retval = sizeof(struct rte_gre_hdr);
4826 : : break;
4827 : : case RTE_FLOW_ITEM_TYPE_MPLS:
4828 : : retval = sizeof(struct rte_mpls_hdr);
4829 : : break;
4830 : : case RTE_FLOW_ITEM_TYPE_VOID: /* Fall through. */
4831 : : default:
4832 : : retval = 0;
4833 : : break;
4834 : : }
4835 : 0 : return retval;
4836 : : }
4837 : :
4838 : : #define MLX5_ENCAP_IPV4_VERSION 0x40
4839 : : #define MLX5_ENCAP_IPV4_IHL_MIN 0x05
4840 : : #define MLX5_ENCAP_IPV4_TTL_DEF 0x40
4841 : : #define MLX5_ENCAP_IPV6_VTC_FLOW 0x60000000
4842 : : #define MLX5_ENCAP_IPV6_HOP_LIMIT 0xff
4843 : : #define MLX5_ENCAP_VXLAN_FLAGS 0x08000000
4844 : : #define MLX5_ENCAP_VXLAN_GPE_FLAGS 0x04
4845 : :
4846 : : /**
4847 : : * Convert the encap action data from list of rte_flow_item to raw buffer
4848 : : *
4849 : : * @param[in] items
4850 : : * Pointer to rte_flow_item objects list.
4851 : : * @param[out] buf
4852 : : * Pointer to the output buffer.
4853 : : * @param[out] size
4854 : : * Pointer to the output buffer size.
4855 : : * @param[out] error
4856 : : * Pointer to the error structure.
4857 : : *
4858 : : * @return
4859 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4860 : : */
4861 : : int
4862 : 0 : flow_dv_convert_encap_data(const struct rte_flow_item *items, uint8_t *buf,
4863 : : size_t *size, struct rte_flow_error *error)
4864 : : {
4865 : : struct rte_ether_hdr *eth = NULL;
4866 : : struct rte_vlan_hdr *vlan = NULL;
4867 : : struct rte_ipv4_hdr *ipv4 = NULL;
4868 : : struct rte_ipv6_hdr *ipv6 = NULL;
4869 : : struct rte_udp_hdr *udp = NULL;
4870 : : struct rte_vxlan_hdr *vxlan = NULL;
4871 : : struct rte_vxlan_gpe_hdr *vxlan_gpe = NULL;
4872 : : struct rte_gre_hdr *gre = NULL;
4873 : : size_t len;
4874 : : size_t temp_size = 0;
4875 : :
4876 [ # # ]: 0 : if (!items)
4877 : 0 : return rte_flow_error_set(error, EINVAL,
4878 : : RTE_FLOW_ERROR_TYPE_ACTION,
4879 : : NULL, "invalid empty data");
4880 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4881 : 0 : len = flow_dv_get_item_hdr_len(items->type);
4882 [ # # ]: 0 : if (len + temp_size > MLX5_ENCAP_MAX_LEN)
4883 : 0 : return rte_flow_error_set(error, EINVAL,
4884 : : RTE_FLOW_ERROR_TYPE_ACTION,
4885 : 0 : (void *)items->type,
4886 : : "items total size is too big"
4887 : : " for encap action");
4888 [ # # ]: 0 : if (items->spec)
4889 [ # # ]: 0 : rte_memcpy(&buf[temp_size], items->spec, len);
4890 [ # # # # : 0 : switch (items->type) {
# # # # #
# ]
4891 : 0 : case RTE_FLOW_ITEM_TYPE_ETH:
4892 : 0 : eth = (struct rte_ether_hdr *)&buf[temp_size];
4893 : 0 : break;
4894 : 0 : case RTE_FLOW_ITEM_TYPE_VLAN:
4895 : 0 : vlan = (struct rte_vlan_hdr *)&buf[temp_size];
4896 [ # # ]: 0 : if (!eth)
4897 : 0 : return rte_flow_error_set(error, EINVAL,
4898 : : RTE_FLOW_ERROR_TYPE_ACTION,
4899 : : (void *)items->type,
4900 : : "eth header not found");
4901 [ # # ]: 0 : if (!eth->ether_type)
4902 : 0 : eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_VLAN);
4903 : : break;
4904 : 0 : case RTE_FLOW_ITEM_TYPE_IPV4:
4905 : 0 : ipv4 = (struct rte_ipv4_hdr *)&buf[temp_size];
4906 [ # # ]: 0 : if (!vlan && !eth)
4907 : 0 : return rte_flow_error_set(error, EINVAL,
4908 : : RTE_FLOW_ERROR_TYPE_ACTION,
4909 : : (void *)items->type,
4910 : : "neither eth nor vlan"
4911 : : " header found");
4912 [ # # # # ]: 0 : if (vlan && !vlan->eth_proto)
4913 : 0 : vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV4);
4914 [ # # # # ]: 0 : else if (eth && !eth->ether_type)
4915 : 0 : eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV4);
4916 [ # # ]: 0 : if (!ipv4->version_ihl)
4917 : 0 : ipv4->version_ihl = MLX5_ENCAP_IPV4_VERSION |
4918 : : MLX5_ENCAP_IPV4_IHL_MIN;
4919 [ # # ]: 0 : if (!ipv4->time_to_live)
4920 : 0 : ipv4->time_to_live = MLX5_ENCAP_IPV4_TTL_DEF;
4921 : : break;
4922 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6:
4923 : 0 : ipv6 = (struct rte_ipv6_hdr *)&buf[temp_size];
4924 [ # # ]: 0 : if (!vlan && !eth)
4925 : 0 : return rte_flow_error_set(error, EINVAL,
4926 : : RTE_FLOW_ERROR_TYPE_ACTION,
4927 : : (void *)items->type,
4928 : : "neither eth nor vlan"
4929 : : " header found");
4930 [ # # # # ]: 0 : if (vlan && !vlan->eth_proto)
4931 : 0 : vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV6);
4932 [ # # # # ]: 0 : else if (eth && !eth->ether_type)
4933 : 0 : eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV6);
4934 [ # # ]: 0 : if (!ipv6->vtc_flow)
4935 : 0 : ipv6->vtc_flow =
4936 : : RTE_BE32(MLX5_ENCAP_IPV6_VTC_FLOW);
4937 [ # # ]: 0 : if (!ipv6->hop_limits)
4938 : 0 : ipv6->hop_limits = MLX5_ENCAP_IPV6_HOP_LIMIT;
4939 : : break;
4940 : 0 : case RTE_FLOW_ITEM_TYPE_UDP:
4941 : 0 : udp = (struct rte_udp_hdr *)&buf[temp_size];
4942 [ # # ]: 0 : if (!ipv4 && !ipv6)
4943 : 0 : return rte_flow_error_set(error, EINVAL,
4944 : : RTE_FLOW_ERROR_TYPE_ACTION,
4945 : : (void *)items->type,
4946 : : "ip header not found");
4947 [ # # # # ]: 0 : if (ipv4 && !ipv4->next_proto_id)
4948 : 0 : ipv4->next_proto_id = IPPROTO_UDP;
4949 [ # # # # ]: 0 : else if (ipv6 && !ipv6->proto)
4950 : 0 : ipv6->proto = IPPROTO_UDP;
4951 : : break;
4952 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN:
4953 : 0 : vxlan = (struct rte_vxlan_hdr *)&buf[temp_size];
4954 [ # # ]: 0 : if (!udp)
4955 : 0 : return rte_flow_error_set(error, EINVAL,
4956 : : RTE_FLOW_ERROR_TYPE_ACTION,
4957 : : (void *)items->type,
4958 : : "udp header not found");
4959 [ # # ]: 0 : if (!udp->dst_port)
4960 : 0 : udp->dst_port = RTE_BE16(MLX5_UDP_PORT_VXLAN);
4961 [ # # ]: 0 : if (!vxlan->vx_flags)
4962 : 0 : vxlan->vx_flags =
4963 : : RTE_BE32(MLX5_ENCAP_VXLAN_FLAGS);
4964 : : break;
4965 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
4966 : 0 : vxlan_gpe = (struct rte_vxlan_gpe_hdr *)&buf[temp_size];
4967 [ # # ]: 0 : if (!udp)
4968 : 0 : return rte_flow_error_set(error, EINVAL,
4969 : : RTE_FLOW_ERROR_TYPE_ACTION,
4970 : : (void *)items->type,
4971 : : "udp header not found");
4972 [ # # ]: 0 : if (!vxlan_gpe->proto)
4973 : 0 : return rte_flow_error_set(error, EINVAL,
4974 : : RTE_FLOW_ERROR_TYPE_ACTION,
4975 : : (void *)items->type,
4976 : : "next protocol not found");
4977 [ # # ]: 0 : if (!udp->dst_port)
4978 : 0 : udp->dst_port =
4979 : : RTE_BE16(MLX5_UDP_PORT_VXLAN_GPE);
4980 [ # # ]: 0 : if (!vxlan_gpe->vx_flags)
4981 : 0 : vxlan_gpe->vx_flags =
4982 : : MLX5_ENCAP_VXLAN_GPE_FLAGS;
4983 : : break;
4984 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
4985 : : case RTE_FLOW_ITEM_TYPE_NVGRE:
4986 : 0 : gre = (struct rte_gre_hdr *)&buf[temp_size];
4987 [ # # ]: 0 : if (!gre->proto)
4988 : 0 : return rte_flow_error_set(error, EINVAL,
4989 : : RTE_FLOW_ERROR_TYPE_ACTION,
4990 : 0 : (void *)items->type,
4991 : : "next protocol not found");
4992 [ # # ]: 0 : if (!ipv4 && !ipv6)
4993 : 0 : return rte_flow_error_set(error, EINVAL,
4994 : : RTE_FLOW_ERROR_TYPE_ACTION,
4995 : 0 : (void *)items->type,
4996 : : "ip header not found");
4997 [ # # # # ]: 0 : if (ipv4 && !ipv4->next_proto_id)
4998 : 0 : ipv4->next_proto_id = IPPROTO_GRE;
4999 [ # # # # ]: 0 : else if (ipv6 && !ipv6->proto)
5000 : 0 : ipv6->proto = IPPROTO_GRE;
5001 : : break;
5002 : : case RTE_FLOW_ITEM_TYPE_VOID:
5003 : : break;
5004 : 0 : default:
5005 : 0 : return rte_flow_error_set(error, EINVAL,
5006 : : RTE_FLOW_ERROR_TYPE_ACTION,
5007 : 0 : (void *)items->type,
5008 : : "unsupported item type");
5009 : : break;
5010 : : }
5011 : : temp_size += len;
5012 : : }
5013 : 0 : *size = temp_size;
5014 : 0 : return 0;
5015 : : }
5016 : :
5017 : : static int
5018 : 0 : flow_dv_zero_encap_udp_csum(void *data, struct rte_flow_error *error)
5019 : : {
5020 : : struct rte_ether_hdr *eth = NULL;
5021 : : struct rte_vlan_hdr *vlan = NULL;
5022 : : struct rte_ipv4_hdr *ipv4 = NULL;
5023 : : struct rte_ipv6_hdr *ipv6 = NULL;
5024 : : struct rte_udp_hdr *udp = NULL;
5025 : : char *next_hdr;
5026 : : uint16_t proto;
5027 : :
5028 : : eth = (struct rte_ether_hdr *)data;
5029 : 0 : next_hdr = (char *)(eth + 1);
5030 : 0 : proto = RTE_BE16(eth->ether_type);
5031 : :
5032 : : /* VLAN skipping */
5033 [ # # ]: 0 : while (proto == RTE_ETHER_TYPE_VLAN || proto == RTE_ETHER_TYPE_QINQ) {
5034 : : vlan = (struct rte_vlan_hdr *)next_hdr;
5035 : 0 : proto = RTE_BE16(vlan->eth_proto);
5036 : 0 : next_hdr += sizeof(struct rte_vlan_hdr);
5037 : : }
5038 : :
5039 : : /* non IPv4/IPv6 header. not supported */
5040 [ # # ]: 0 : if (proto != RTE_ETHER_TYPE_IPV4 && proto != RTE_ETHER_TYPE_IPV6) {
5041 : 0 : return rte_flow_error_set(error, ENOTSUP,
5042 : : RTE_FLOW_ERROR_TYPE_ACTION,
5043 : : NULL, "Cannot offload non IPv4/IPv6");
5044 : : }
5045 : :
5046 [ # # ]: 0 : if (proto == RTE_ETHER_TYPE_IPV4) {
5047 : : ipv4 = (struct rte_ipv4_hdr *)next_hdr;
5048 : : /* ignore non UDP */
5049 [ # # ]: 0 : if (ipv4->next_proto_id != IPPROTO_UDP)
5050 : : return 0;
5051 : 0 : udp = (struct rte_udp_hdr *)(ipv4 + 1);
5052 : : } else {
5053 : : ipv6 = (struct rte_ipv6_hdr *)next_hdr;
5054 : : /* ignore non UDP */
5055 [ # # ]: 0 : if (ipv6->proto != IPPROTO_UDP)
5056 : : return 0;
5057 : 0 : udp = (struct rte_udp_hdr *)(ipv6 + 1);
5058 : : }
5059 : :
5060 : 0 : udp->dgram_cksum = 0;
5061 : :
5062 : 0 : return 0;
5063 : : }
5064 : :
5065 : : /**
5066 : : * Convert L2 encap action to DV specification.
5067 : : *
5068 : : * @param[in] dev
5069 : : * Pointer to rte_eth_dev structure.
5070 : : * @param[in] action
5071 : : * Pointer to action structure.
5072 : : * @param[in, out] dev_flow
5073 : : * Pointer to the mlx5_flow.
5074 : : * @param[in] transfer
5075 : : * Mark if the flow is E-Switch flow.
5076 : : * @param[out] error
5077 : : * Pointer to the error structure.
5078 : : *
5079 : : * @return
5080 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5081 : : */
5082 : : static int
5083 : 0 : flow_dv_create_action_l2_encap(struct rte_eth_dev *dev,
5084 : : const struct rte_flow_action *action,
5085 : : struct mlx5_flow *dev_flow,
5086 : : uint8_t transfer,
5087 : : struct rte_flow_error *error)
5088 : : {
5089 : : const struct rte_flow_item *encap_data;
5090 : : const struct rte_flow_action_raw_encap *raw_encap_data;
5091 [ # # ]: 0 : struct mlx5_flow_dv_encap_decap_resource res = {
5092 : : .reformat_type =
5093 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L2_TUNNEL,
5094 : : .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
5095 : : MLX5DV_FLOW_TABLE_TYPE_NIC_TX,
5096 : : };
5097 : :
5098 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
5099 : 0 : raw_encap_data =
5100 : : (const struct rte_flow_action_raw_encap *)action->conf;
5101 : 0 : res.size = raw_encap_data->size;
5102 : 0 : memcpy(res.buf, raw_encap_data->data, res.size);
5103 : : } else {
5104 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP)
5105 : 0 : encap_data =
5106 : : ((const struct rte_flow_action_vxlan_encap *)
5107 : 0 : action->conf)->definition;
5108 : : else
5109 : 0 : encap_data =
5110 : : ((const struct rte_flow_action_nvgre_encap *)
5111 : 0 : action->conf)->definition;
5112 [ # # ]: 0 : if (flow_dv_convert_encap_data(encap_data, res.buf,
5113 : : &res.size, error))
5114 : 0 : return -rte_errno;
5115 : : }
5116 [ # # ]: 0 : if (flow_dv_zero_encap_udp_csum(res.buf, error))
5117 : 0 : return -rte_errno;
5118 [ # # ]: 0 : if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
5119 : 0 : return rte_flow_error_set(error, EINVAL,
5120 : : RTE_FLOW_ERROR_TYPE_ACTION,
5121 : : NULL, "can't create L2 encap action");
5122 : : return 0;
5123 : : }
5124 : :
5125 : : /**
5126 : : * Convert L2 decap action to DV specification.
5127 : : *
5128 : : * @param[in] dev
5129 : : * Pointer to rte_eth_dev structure.
5130 : : * @param[in, out] dev_flow
5131 : : * Pointer to the mlx5_flow.
5132 : : * @param[in] transfer
5133 : : * Mark if the flow is E-Switch flow.
5134 : : * @param[out] error
5135 : : * Pointer to the error structure.
5136 : : *
5137 : : * @return
5138 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5139 : : */
5140 : : static int
5141 : 0 : flow_dv_create_action_l2_decap(struct rte_eth_dev *dev,
5142 : : struct mlx5_flow *dev_flow,
5143 : : uint8_t transfer,
5144 : : struct rte_flow_error *error)
5145 : : {
5146 [ # # ]: 0 : struct mlx5_flow_dv_encap_decap_resource res = {
5147 : : .size = 0,
5148 : : .reformat_type =
5149 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2,
5150 : : .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
5151 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX,
5152 : : };
5153 : :
5154 [ # # ]: 0 : if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
5155 : 0 : return rte_flow_error_set(error, EINVAL,
5156 : : RTE_FLOW_ERROR_TYPE_ACTION,
5157 : : NULL, "can't create L2 decap action");
5158 : : return 0;
5159 : : }
5160 : :
5161 : : /**
5162 : : * Convert raw decap/encap (L3 tunnel) action to DV specification.
5163 : : *
5164 : : * @param[in] dev
5165 : : * Pointer to rte_eth_dev structure.
5166 : : * @param[in] action
5167 : : * Pointer to action structure.
5168 : : * @param[in, out] dev_flow
5169 : : * Pointer to the mlx5_flow.
5170 : : * @param[in] attr
5171 : : * Pointer to the flow attributes.
5172 : : * @param[out] error
5173 : : * Pointer to the error structure.
5174 : : *
5175 : : * @return
5176 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5177 : : */
5178 : : static int
5179 [ # # ]: 0 : flow_dv_create_action_raw_encap(struct rte_eth_dev *dev,
5180 : : const struct rte_flow_action *action,
5181 : : struct mlx5_flow *dev_flow,
5182 : : const struct rte_flow_attr *attr,
5183 : : struct rte_flow_error *error)
5184 : : {
5185 : : const struct rte_flow_action_raw_encap *encap_data;
5186 : : struct mlx5_flow_dv_encap_decap_resource res;
5187 : :
5188 : : memset(&res, 0, sizeof(res));
5189 : 0 : encap_data = (const struct rte_flow_action_raw_encap *)action->conf;
5190 : 0 : res.size = encap_data->size;
5191 [ # # ]: 0 : memcpy(res.buf, encap_data->data, res.size);
5192 [ # # ]: 0 : res.reformat_type = res.size < MLX5_ENCAPSULATION_DECISION_SIZE ?
5193 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L3_TUNNEL_TO_L2 :
5194 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L3_TUNNEL;
5195 [ # # ]: 0 : if (attr->transfer)
5196 : 0 : res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
5197 : : else
5198 : 0 : res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
5199 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
5200 [ # # ]: 0 : if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
5201 : 0 : return rte_flow_error_set(error, EINVAL,
5202 : : RTE_FLOW_ERROR_TYPE_ACTION,
5203 : : NULL, "can't create encap action");
5204 : : return 0;
5205 : : }
5206 : :
5207 : : /**
5208 : : * Create action push VLAN.
5209 : : *
5210 : : * @param[in] dev
5211 : : * Pointer to rte_eth_dev structure.
5212 : : * @param[in] attr
5213 : : * Pointer to the flow attributes.
5214 : : * @param[in] vlan
5215 : : * Pointer to the vlan to push to the Ethernet header.
5216 : : * @param[in, out] dev_flow
5217 : : * Pointer to the mlx5_flow.
5218 : : * @param[out] error
5219 : : * Pointer to the error structure.
5220 : : *
5221 : : * @return
5222 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5223 : : */
5224 : : static int
5225 [ # # ]: 0 : flow_dv_create_action_push_vlan(struct rte_eth_dev *dev,
5226 : : const struct rte_flow_attr *attr,
5227 : : const struct rte_vlan_hdr *vlan,
5228 : : struct mlx5_flow *dev_flow,
5229 : : struct rte_flow_error *error)
5230 : : {
5231 : : struct mlx5_flow_dv_push_vlan_action_resource res;
5232 : :
5233 : : memset(&res, 0, sizeof(res));
5234 : 0 : res.vlan_tag =
5235 [ # # ]: 0 : rte_cpu_to_be_32(((uint32_t)vlan->eth_proto) << 16 |
5236 : : vlan->vlan_tci);
5237 [ # # ]: 0 : if (attr->transfer)
5238 : 0 : res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
5239 : : else
5240 : 0 : res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
5241 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
5242 : 0 : return flow_dv_push_vlan_action_resource_register
5243 : : (dev, &res, dev_flow, error);
5244 : : }
5245 : :
5246 : : /**
5247 : : * Validate the modify-header actions.
5248 : : *
5249 : : * @param[in] action_flags
5250 : : * Holds the actions detected until now.
5251 : : * @param[in] action
5252 : : * Pointer to the modify action.
5253 : : * @param[out] error
5254 : : * Pointer to error structure.
5255 : : *
5256 : : * @return
5257 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5258 : : */
5259 : : static int
5260 : 0 : flow_dv_validate_action_modify_hdr(const uint64_t action_flags,
5261 : : const struct rte_flow_action *action,
5262 : : struct rte_flow_error *error)
5263 : : {
5264 [ # # # # ]: 0 : if (action->type != RTE_FLOW_ACTION_TYPE_DEC_TTL && !action->conf)
5265 : 0 : return rte_flow_error_set(error, EINVAL,
5266 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5267 : : NULL, "action configuration not set");
5268 : :
5269 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
5270 : 0 : return rte_flow_error_set(error, EINVAL,
5271 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5272 : : "can't have encap action before"
5273 : : " modify action");
5274 : : return 0;
5275 : : }
5276 : :
5277 : : /**
5278 : : * Validate the modify-header MAC address actions.
5279 : : *
5280 : : * @param[in] action_flags
5281 : : * Holds the actions detected until now.
5282 : : * @param[in] action
5283 : : * Pointer to the modify action.
5284 : : * @param[in] item_flags
5285 : : * Holds the items detected.
5286 : : * @param[out] error
5287 : : * Pointer to error structure.
5288 : : *
5289 : : * @return
5290 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5291 : : */
5292 : : static int
5293 : 0 : flow_dv_validate_action_modify_mac(const uint64_t action_flags,
5294 : : const struct rte_flow_action *action,
5295 : : const uint64_t item_flags,
5296 : : struct rte_flow_error *error)
5297 : : {
5298 : : int ret = 0;
5299 : :
5300 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5301 [ # # ]: 0 : if (!ret) {
5302 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_L2))
5303 : 0 : return rte_flow_error_set(error, EINVAL,
5304 : : RTE_FLOW_ERROR_TYPE_ACTION,
5305 : : NULL,
5306 : : "no L2 item in pattern");
5307 : : }
5308 : : return ret;
5309 : : }
5310 : :
5311 : : /**
5312 : : * Validate the modify-header IPv4 address actions.
5313 : : *
5314 : : * @param[in] action_flags
5315 : : * Holds the actions detected until now.
5316 : : * @param[in] action
5317 : : * Pointer to the modify action.
5318 : : * @param[in] item_flags
5319 : : * Holds the items detected.
5320 : : * @param[out] error
5321 : : * Pointer to error structure.
5322 : : *
5323 : : * @return
5324 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5325 : : */
5326 : : static int
5327 : 0 : flow_dv_validate_action_modify_ipv4(const uint64_t action_flags,
5328 : : const struct rte_flow_action *action,
5329 : : const uint64_t item_flags,
5330 : : struct rte_flow_error *error)
5331 : : {
5332 : : int ret = 0;
5333 : : uint64_t layer;
5334 : :
5335 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5336 [ # # ]: 0 : if (!ret) {
5337 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5338 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L3_IPV4 :
5339 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4;
5340 [ # # ]: 0 : if (!(item_flags & layer))
5341 : 0 : return rte_flow_error_set(error, EINVAL,
5342 : : RTE_FLOW_ERROR_TYPE_ACTION,
5343 : : NULL,
5344 : : "no ipv4 item in pattern");
5345 : : }
5346 : : return ret;
5347 : : }
5348 : :
5349 : : /**
5350 : : * Validate the modify-header IPv6 address actions.
5351 : : *
5352 : : * @param[in] action_flags
5353 : : * Holds the actions detected until now.
5354 : : * @param[in] action
5355 : : * Pointer to the modify action.
5356 : : * @param[in] item_flags
5357 : : * Holds the items detected.
5358 : : * @param[out] error
5359 : : * Pointer to error structure.
5360 : : *
5361 : : * @return
5362 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5363 : : */
5364 : : static int
5365 : 0 : flow_dv_validate_action_modify_ipv6(const uint64_t action_flags,
5366 : : const struct rte_flow_action *action,
5367 : : const uint64_t item_flags,
5368 : : struct rte_flow_error *error)
5369 : : {
5370 : : int ret = 0;
5371 : : uint64_t layer;
5372 : :
5373 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5374 [ # # ]: 0 : if (!ret) {
5375 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5376 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L3_IPV6 :
5377 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6;
5378 [ # # ]: 0 : if (!(item_flags & layer))
5379 : 0 : return rte_flow_error_set(error, EINVAL,
5380 : : RTE_FLOW_ERROR_TYPE_ACTION,
5381 : : NULL,
5382 : : "no ipv6 item in pattern");
5383 : : }
5384 : : return ret;
5385 : : }
5386 : :
5387 : : /**
5388 : : * Validate the modify-header TP actions.
5389 : : *
5390 : : * @param[in] action_flags
5391 : : * Holds the actions detected until now.
5392 : : * @param[in] action
5393 : : * Pointer to the modify action.
5394 : : * @param[in] item_flags
5395 : : * Holds the items detected.
5396 : : * @param[out] error
5397 : : * Pointer to error structure.
5398 : : *
5399 : : * @return
5400 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5401 : : */
5402 : : static int
5403 : 0 : flow_dv_validate_action_modify_tp(const uint64_t action_flags,
5404 : : const struct rte_flow_action *action,
5405 : : const uint64_t item_flags,
5406 : : struct rte_flow_error *error)
5407 : : {
5408 : : int ret = 0;
5409 : : uint64_t layer;
5410 : :
5411 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5412 [ # # ]: 0 : if (!ret) {
5413 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5414 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L4 :
5415 : : MLX5_FLOW_LAYER_OUTER_L4;
5416 [ # # ]: 0 : if (!(item_flags & layer))
5417 : 0 : return rte_flow_error_set(error, EINVAL,
5418 : : RTE_FLOW_ERROR_TYPE_ACTION,
5419 : : NULL, "no transport layer "
5420 : : "in pattern");
5421 : : }
5422 : : return ret;
5423 : : }
5424 : :
5425 : : /**
5426 : : * Validate the modify-header actions of increment/decrement
5427 : : * TCP Sequence-number.
5428 : : *
5429 : : * @param[in] action_flags
5430 : : * Holds the actions detected until now.
5431 : : * @param[in] action
5432 : : * Pointer to the modify action.
5433 : : * @param[in] item_flags
5434 : : * Holds the items detected.
5435 : : * @param[out] error
5436 : : * Pointer to error structure.
5437 : : *
5438 : : * @return
5439 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5440 : : */
5441 : : static int
5442 : 0 : flow_dv_validate_action_modify_tcp_seq(const uint64_t action_flags,
5443 : : const struct rte_flow_action *action,
5444 : : const uint64_t item_flags,
5445 : : struct rte_flow_error *error)
5446 : : {
5447 : : int ret = 0;
5448 : : uint64_t layer;
5449 : :
5450 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5451 [ # # ]: 0 : if (!ret) {
5452 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5453 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L4_TCP :
5454 : : MLX5_FLOW_LAYER_OUTER_L4_TCP;
5455 [ # # ]: 0 : if (!(item_flags & layer))
5456 : 0 : return rte_flow_error_set(error, EINVAL,
5457 : : RTE_FLOW_ERROR_TYPE_ACTION,
5458 : : NULL, "no TCP item in"
5459 : : " pattern");
5460 [ # # ]: 0 : if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ &&
5461 [ # # # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_DEC_TCP_SEQ)) ||
5462 : 0 : (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ &&
5463 [ # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_INC_TCP_SEQ)))
5464 : 0 : return rte_flow_error_set(error, EINVAL,
5465 : : RTE_FLOW_ERROR_TYPE_ACTION,
5466 : : NULL,
5467 : : "cannot decrease and increase"
5468 : : " TCP sequence number"
5469 : : " at the same time");
5470 : : }
5471 : : return ret;
5472 : : }
5473 : :
5474 : : /**
5475 : : * Validate the modify-header actions of increment/decrement
5476 : : * TCP Acknowledgment number.
5477 : : *
5478 : : * @param[in] action_flags
5479 : : * Holds the actions detected until now.
5480 : : * @param[in] action
5481 : : * Pointer to the modify action.
5482 : : * @param[in] item_flags
5483 : : * Holds the items detected.
5484 : : * @param[out] error
5485 : : * Pointer to error structure.
5486 : : *
5487 : : * @return
5488 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5489 : : */
5490 : : static int
5491 : 0 : flow_dv_validate_action_modify_tcp_ack(const uint64_t action_flags,
5492 : : const struct rte_flow_action *action,
5493 : : const uint64_t item_flags,
5494 : : struct rte_flow_error *error)
5495 : : {
5496 : : int ret = 0;
5497 : : uint64_t layer;
5498 : :
5499 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5500 [ # # ]: 0 : if (!ret) {
5501 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5502 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L4_TCP :
5503 : : MLX5_FLOW_LAYER_OUTER_L4_TCP;
5504 [ # # ]: 0 : if (!(item_flags & layer))
5505 : 0 : return rte_flow_error_set(error, EINVAL,
5506 : : RTE_FLOW_ERROR_TYPE_ACTION,
5507 : : NULL, "no TCP item in"
5508 : : " pattern");
5509 [ # # ]: 0 : if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_ACK &&
5510 [ # # # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_DEC_TCP_ACK)) ||
5511 : 0 : (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK &&
5512 [ # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_INC_TCP_ACK)))
5513 : 0 : return rte_flow_error_set(error, EINVAL,
5514 : : RTE_FLOW_ERROR_TYPE_ACTION,
5515 : : NULL,
5516 : : "cannot decrease and increase"
5517 : : " TCP acknowledgment number"
5518 : : " at the same time");
5519 : : }
5520 : : return ret;
5521 : : }
5522 : :
5523 : : /**
5524 : : * Validate the modify-header TTL actions.
5525 : : *
5526 : : * @param[in] action_flags
5527 : : * Holds the actions detected until now.
5528 : : * @param[in] action
5529 : : * Pointer to the modify action.
5530 : : * @param[in] item_flags
5531 : : * Holds the items detected.
5532 : : * @param[out] error
5533 : : * Pointer to error structure.
5534 : : *
5535 : : * @return
5536 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5537 : : */
5538 : : static int
5539 : 0 : flow_dv_validate_action_modify_ttl(const uint64_t action_flags,
5540 : : const struct rte_flow_action *action,
5541 : : const uint64_t item_flags,
5542 : : struct rte_flow_error *error)
5543 : : {
5544 : : int ret = 0;
5545 : : uint64_t layer;
5546 : :
5547 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5548 [ # # ]: 0 : if (!ret) {
5549 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5550 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L3 :
5551 : : MLX5_FLOW_LAYER_OUTER_L3;
5552 [ # # ]: 0 : if (!(item_flags & layer))
5553 : 0 : return rte_flow_error_set(error, EINVAL,
5554 : : RTE_FLOW_ERROR_TYPE_ACTION,
5555 : : NULL,
5556 : : "no IP protocol in pattern");
5557 : : }
5558 : : return ret;
5559 : : }
5560 : :
5561 : : /**
5562 : : * Validate the generic modify field actions.
5563 : : * @param[in] dev
5564 : : * Pointer to the rte_eth_dev structure.
5565 : : * @param[in] action_flags
5566 : : * Holds the actions detected until now.
5567 : : * @param[in] action
5568 : : * Pointer to the modify action.
5569 : : * @param[in] attr
5570 : : * Pointer to the flow attributes.
5571 : : * @param root
5572 : : * Whether action is on root table.
5573 : : * @param[out] error
5574 : : * Pointer to error structure.
5575 : : *
5576 : : * @return
5577 : : * Number of header fields to modify (0 or more) on success,
5578 : : * a negative errno value otherwise and rte_errno is set.
5579 : : */
5580 : : static int
5581 : 0 : flow_dv_validate_action_modify_field(struct rte_eth_dev *dev,
5582 : : const uint64_t action_flags,
5583 : : const struct rte_flow_action *action,
5584 : : const struct rte_flow_attr *attr,
5585 : : bool root,
5586 : : struct rte_flow_error *error)
5587 : : {
5588 : : int ret = 0;
5589 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5590 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
5591 : 0 : struct mlx5_hca_attr *hca_attr = &priv->sh->cdev->config.hca_attr;
5592 : 0 : const struct rte_flow_action_modify_field *conf = action->conf;
5593 : 0 : const struct rte_flow_field_data *src_data = &conf->src;
5594 : 0 : const struct rte_flow_field_data *dst_data = &conf->dst;
5595 : 0 : uint32_t dst_width, src_width, width = conf->width;
5596 : :
5597 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5598 [ # # ]: 0 : if (ret)
5599 : : return ret;
5600 [ # # ]: 0 : if (src_data->field == RTE_FLOW_FIELD_FLEX_ITEM ||
5601 [ # # ]: 0 : dst_data->field == RTE_FLOW_FIELD_FLEX_ITEM)
5602 : 0 : return rte_flow_error_set(error, ENOTSUP,
5603 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5604 : : "flex item fields modification"
5605 : : " is not supported");
5606 : 0 : dst_width = mlx5_flow_item_field_width(dev, dst_data->field,
5607 : : -1, attr, error);
5608 : 0 : src_width = mlx5_flow_item_field_width(dev, src_data->field,
5609 : : dst_width, attr, error);
5610 [ # # ]: 0 : if (width == 0)
5611 : 0 : return rte_flow_error_set(error, EINVAL,
5612 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5613 : : "no bits are requested to be modified");
5614 [ # # ]: 0 : else if (width > dst_width || width > src_width)
5615 : 0 : return rte_flow_error_set(error, EINVAL,
5616 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5617 : : "cannot modify more bits than"
5618 : : " the width of a field");
5619 [ # # ]: 0 : if (dst_data->field != RTE_FLOW_FIELD_VALUE &&
5620 : : dst_data->field != RTE_FLOW_FIELD_POINTER) {
5621 [ # # ]: 0 : if (dst_data->offset + width > dst_width)
5622 : 0 : return rte_flow_error_set(error, EINVAL,
5623 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5624 : : "destination offset is too big");
5625 : 0 : ret = flow_validate_modify_field_level(dst_data, error);
5626 [ # # ]: 0 : if (ret)
5627 : : return ret;
5628 [ # # ]: 0 : if (dst_data->tag_index &&
5629 [ # # ]: 0 : !flow_modify_field_support_tag_array(dst_data->field))
5630 : 0 : return rte_flow_error_set(error, EINVAL,
5631 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5632 : : "destination tag index is not supported");
5633 [ # # ]: 0 : if (dst_data->class_id)
5634 : 0 : return rte_flow_error_set(error, EINVAL,
5635 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5636 : : "destination class ID is not supported");
5637 : : }
5638 [ # # ]: 0 : if (src_data->field != RTE_FLOW_FIELD_VALUE &&
5639 : : src_data->field != RTE_FLOW_FIELD_POINTER) {
5640 [ # # ]: 0 : if (root)
5641 : 0 : return rte_flow_error_set(error, ENOTSUP,
5642 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5643 : : "modify field action is not"
5644 : : " supported for group 0");
5645 [ # # ]: 0 : if (src_data->offset + width > src_width)
5646 : 0 : return rte_flow_error_set(error, EINVAL,
5647 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5648 : : "source offset is too big");
5649 : 0 : ret = flow_validate_modify_field_level(src_data, error);
5650 [ # # ]: 0 : if (ret)
5651 : : return ret;
5652 [ # # ]: 0 : if (src_data->tag_index &&
5653 [ # # ]: 0 : !flow_modify_field_support_tag_array(src_data->field))
5654 : 0 : return rte_flow_error_set(error, EINVAL,
5655 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5656 : : "source tag index is not supported");
5657 [ # # ]: 0 : if (src_data->class_id)
5658 : 0 : return rte_flow_error_set(error, EINVAL,
5659 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5660 : : "source class ID is not supported");
5661 : : }
5662 [ # # ]: 0 : if ((dst_data->field == src_data->field) &&
5663 [ # # ]: 0 : (dst_data->level == src_data->level))
5664 : 0 : return rte_flow_error_set(error, EINVAL,
5665 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5666 : : "source and destination fields"
5667 : : " cannot be the same");
5668 : 0 : if (dst_data->field == RTE_FLOW_FIELD_VALUE ||
5669 [ # # ]: 0 : dst_data->field == RTE_FLOW_FIELD_POINTER ||
5670 : : dst_data->field == RTE_FLOW_FIELD_MARK)
5671 : 0 : return rte_flow_error_set(error, EINVAL,
5672 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5673 : : "mark, immediate value or a pointer to it"
5674 : : " cannot be used as a destination");
5675 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_START ||
5676 : : src_data->field == RTE_FLOW_FIELD_START)
5677 : 0 : return rte_flow_error_set(error, ENOTSUP,
5678 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5679 : : "modifications of an arbitrary"
5680 : : " place in a packet is not supported");
5681 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_VLAN_TYPE ||
5682 : : src_data->field == RTE_FLOW_FIELD_VLAN_TYPE)
5683 : 0 : return rte_flow_error_set(error, ENOTSUP,
5684 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5685 : : "modifications of the 802.1Q Tag"
5686 : : " Identifier is not supported");
5687 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_VXLAN_VNI ||
5688 : : src_data->field == RTE_FLOW_FIELD_VXLAN_VNI)
5689 : 0 : return rte_flow_error_set(error, ENOTSUP,
5690 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5691 : : "modifications of the VXLAN Network"
5692 : : " Identifier is not supported");
5693 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_GENEVE_VNI ||
5694 : : src_data->field == RTE_FLOW_FIELD_GENEVE_VNI)
5695 : 0 : return rte_flow_error_set(error, ENOTSUP,
5696 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5697 : : "modifications of the GENEVE Network"
5698 : : " Identifier is not supported");
5699 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_GENEVE_OPT_TYPE ||
5700 : : src_data->field == RTE_FLOW_FIELD_GENEVE_OPT_TYPE)
5701 : 0 : return rte_flow_error_set(error, ENOTSUP,
5702 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5703 : : "modifications of the GENEVE option type is not supported");
5704 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_GENEVE_OPT_CLASS ||
5705 : : src_data->field == RTE_FLOW_FIELD_GENEVE_OPT_CLASS)
5706 : 0 : return rte_flow_error_set(error, ENOTSUP,
5707 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5708 : : "modifications of the GENEVE option class is not supported");
5709 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_GENEVE_OPT_DATA ||
5710 : : src_data->field == RTE_FLOW_FIELD_GENEVE_OPT_DATA)
5711 : 0 : return rte_flow_error_set(error, ENOTSUP,
5712 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5713 : : "modifications of the GENEVE option data is not supported");
5714 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_MPLS ||
5715 : : src_data->field == RTE_FLOW_FIELD_MPLS)
5716 : 0 : return rte_flow_error_set(error, ENOTSUP,
5717 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5718 : : "modifications of the MPLS header "
5719 : : "is not supported");
5720 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_RANDOM ||
5721 : : src_data->field == RTE_FLOW_FIELD_RANDOM)
5722 : 0 : return rte_flow_error_set(error, ENOTSUP,
5723 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5724 : : "modifications of random value is not supported");
5725 [ # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_MARK ||
5726 : : src_data->field == RTE_FLOW_FIELD_MARK)
5727 [ # # # # ]: 0 : if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
5728 : 0 : !mlx5_flow_ext_mreg_supported(dev))
5729 : 0 : return rte_flow_error_set(error, ENOTSUP,
5730 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5731 : : "cannot modify mark in legacy mode"
5732 : : " or without extensive registers");
5733 [ # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_META ||
5734 [ # # ]: 0 : src_data->field == RTE_FLOW_FIELD_META) {
5735 [ # # # # ]: 0 : if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
5736 : 0 : !mlx5_flow_ext_mreg_supported(dev))
5737 : 0 : return rte_flow_error_set(error, ENOTSUP,
5738 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5739 : : "cannot modify meta without"
5740 : : " extensive registers support");
5741 : 0 : ret = flow_dv_get_metadata_reg(dev, attr, error);
5742 [ # # ]: 0 : if (ret < 0 || ret == REG_NON)
5743 : 0 : return rte_flow_error_set(error, ENOTSUP,
5744 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5745 : : "cannot modify meta without"
5746 : : " extensive registers available");
5747 : : }
5748 [ # # ]: 0 : if (conf->operation == RTE_FLOW_MODIFY_SUB)
5749 : 0 : return rte_flow_error_set(error, ENOTSUP,
5750 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5751 : : "sub operations are not supported");
5752 [ # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_IPV4_ECN ||
5753 [ # # # # ]: 0 : src_data->field == RTE_FLOW_FIELD_IPV4_ECN ||
5754 [ # # ]: 0 : dst_data->field == RTE_FLOW_FIELD_IPV6_ECN ||
5755 : : src_data->field == RTE_FLOW_FIELD_IPV6_ECN)
5756 [ # # # # ]: 0 : if (!hca_attr->modify_outer_ip_ecn && root)
5757 : 0 : return rte_flow_error_set(error, ENOTSUP,
5758 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5759 : : "modifications of the ECN for current firmware is not supported");
5760 : 0 : return (width / 32) + !!(width % 32);
5761 : : }
5762 : :
5763 : : /**
5764 : : * Validate jump action.
5765 : : *
5766 : : * @param[in] action
5767 : : * Pointer to the jump action.
5768 : : * @param[in] action_flags
5769 : : * Holds the actions detected until now.
5770 : : * @param[in] attributes
5771 : : * Pointer to flow attributes
5772 : : * @param[in] external
5773 : : * Action belongs to flow rule created by request external to PMD.
5774 : : * @param[out] error
5775 : : * Pointer to error structure.
5776 : : *
5777 : : * @return
5778 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5779 : : */
5780 : : static int
5781 : 0 : flow_dv_validate_action_jump(struct rte_eth_dev *dev,
5782 : : const struct mlx5_flow_tunnel *tunnel,
5783 : : const struct rte_flow_action *action,
5784 : : uint64_t action_flags,
5785 : : const struct rte_flow_attr *attributes,
5786 : : bool external, struct rte_flow_error *error)
5787 : : {
5788 : 0 : uint32_t target_group, table = 0;
5789 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5790 : : int ret = 0;
5791 : 0 : struct flow_grp_info grp_info = {
5792 : : .external = !!external,
5793 : 0 : .transfer = !!attributes->transfer,
5794 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
5795 : : .std_tbl_fix = 0
5796 : : };
5797 [ # # ]: 0 : if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
5798 : : MLX5_FLOW_FATE_ESWITCH_ACTIONS))
5799 : 0 : return rte_flow_error_set(error, EINVAL,
5800 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5801 : : "can't have 2 fate actions in"
5802 : : " same flow");
5803 [ # # ]: 0 : if (!action->conf)
5804 : 0 : return rte_flow_error_set(error, EINVAL,
5805 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5806 : : NULL, "action configuration not set");
5807 : 0 : target_group =
5808 : : ((const struct rte_flow_action_jump *)action->conf)->group;
5809 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel, target_group, &table,
5810 : : &grp_info, error);
5811 [ # # ]: 0 : if (ret)
5812 : : return ret;
5813 [ # # ]: 0 : if (table == 0)
5814 : 0 : return rte_flow_error_set(error, EINVAL,
5815 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5816 : : NULL, "root table shouldn't be destination");
5817 : : return 0;
5818 : : }
5819 : :
5820 : : /*
5821 : : * Validate action PORT_ID / REPRESENTED_PORT.
5822 : : *
5823 : : * @param[in] dev
5824 : : * Pointer to rte_eth_dev structure.
5825 : : * @param[in] action_flags
5826 : : * Bit-fields that holds the actions detected until now.
5827 : : * @param[in] action
5828 : : * PORT_ID / REPRESENTED_PORT action structure.
5829 : : * @param[in] attr
5830 : : * Attributes of flow that includes this action.
5831 : : * @param[out] error
5832 : : * Pointer to error structure.
5833 : : *
5834 : : * @return
5835 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5836 : : */
5837 : : static int
5838 : 0 : flow_dv_validate_action_port_id(struct rte_eth_dev *dev,
5839 : : uint64_t action_flags,
5840 : : const struct rte_flow_action *action,
5841 : : const struct rte_flow_attr *attr,
5842 : : struct rte_flow_error *error)
5843 : : {
5844 : : const struct rte_flow_action_port_id *port_id;
5845 : : const struct rte_flow_action_ethdev *ethdev;
5846 : : struct mlx5_priv *act_priv;
5847 : : struct mlx5_priv *dev_priv;
5848 : : uint16_t port;
5849 : :
5850 [ # # ]: 0 : if (!attr->transfer)
5851 : 0 : return rte_flow_error_set(error, ENOTSUP,
5852 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5853 : : NULL,
5854 : : "port action is valid in transfer"
5855 : : " mode only");
5856 [ # # # # ]: 0 : if (!action || !action->conf)
5857 : 0 : return rte_flow_error_set(error, ENOTSUP,
5858 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5859 : : NULL,
5860 : : "port action parameters must be"
5861 : : " specified");
5862 [ # # ]: 0 : if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
5863 : : MLX5_FLOW_FATE_ESWITCH_ACTIONS))
5864 : 0 : return rte_flow_error_set(error, EINVAL,
5865 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5866 : : "can have only one fate actions in"
5867 : : " a flow");
5868 : 0 : dev_priv = mlx5_dev_to_eswitch_info(dev);
5869 [ # # ]: 0 : if (!dev_priv)
5870 : 0 : return rte_flow_error_set(error, rte_errno,
5871 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5872 : : NULL,
5873 : : "failed to obtain E-Switch info");
5874 [ # # # ]: 0 : switch (action->type) {
5875 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
5876 : 0 : port_id = action->conf;
5877 [ # # ]: 0 : port = port_id->original ? dev->data->port_id : port_id->id;
5878 : : break;
5879 : 0 : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
5880 : 0 : ethdev = action->conf;
5881 : 0 : port = ethdev->port_id;
5882 : 0 : break;
5883 : 0 : default:
5884 : : MLX5_ASSERT(false);
5885 : 0 : return rte_flow_error_set
5886 : : (error, EINVAL,
5887 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5888 : : "unknown E-Switch action");
5889 : : }
5890 : 0 : act_priv = mlx5_port_to_eswitch_info(port, false);
5891 [ # # ]: 0 : if (!act_priv)
5892 : 0 : return rte_flow_error_set
5893 : : (error, rte_errno,
5894 : 0 : RTE_FLOW_ERROR_TYPE_ACTION_CONF, action->conf,
5895 : : "failed to obtain E-Switch port id for port");
5896 [ # # ]: 0 : if (act_priv->domain_id != dev_priv->domain_id)
5897 : 0 : return rte_flow_error_set
5898 : : (error, EINVAL,
5899 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5900 : : "port does not belong to"
5901 : : " E-Switch being configured");
5902 : : return 0;
5903 : : }
5904 : :
5905 : : /**
5906 : : * Get the maximum number of modify header actions.
5907 : : *
5908 : : * @param dev
5909 : : * Pointer to rte_eth_dev structure.
5910 : : * @param root
5911 : : * Whether action is on root table.
5912 : : *
5913 : : * @return
5914 : : * Max number of modify header actions device can support.
5915 : : */
5916 : : static inline unsigned int
5917 : : flow_dv_modify_hdr_action_max(struct rte_eth_dev *dev __rte_unused,
5918 : : bool root)
5919 : : {
5920 : : /*
5921 : : * There's no way to directly query the max capacity from FW.
5922 : : * The maximal value on root table should be assumed to be supported.
5923 : : */
5924 [ # # ]: 0 : if (!root)
5925 : : return MLX5_MAX_MODIFY_NUM;
5926 : : else
5927 : 0 : return MLX5_ROOT_TBL_MODIFY_NUM;
5928 : : }
5929 : :
5930 : : /**
5931 : : * Validate the meter action.
5932 : : *
5933 : : * @param[in] dev
5934 : : * Pointer to rte_eth_dev structure.
5935 : : * @param[in] action_flags
5936 : : * Bit-fields that holds the actions detected until now.
5937 : : * @param[in] item_flags
5938 : : * Holds the items detected.
5939 : : * @param[in] action
5940 : : * Pointer to the meter action.
5941 : : * @param[in] attr
5942 : : * Attributes of flow that includes this action.
5943 : : * @param[in] port_id_item
5944 : : * Pointer to item indicating port id.
5945 : : * @param[out] error
5946 : : * Pointer to error structure.
5947 : : *
5948 : : * @return
5949 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5950 : : */
5951 : : static int
5952 : 0 : mlx5_flow_validate_action_meter(struct rte_eth_dev *dev,
5953 : : uint64_t action_flags, uint64_t item_flags,
5954 : : const struct rte_flow_action *action,
5955 : : const struct rte_flow_attr *attr,
5956 : : const struct rte_flow_item *port_id_item,
5957 : : bool *def_policy,
5958 : : struct rte_flow_error *error)
5959 : : {
5960 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5961 : 0 : const struct rte_flow_action_meter *am = action->conf;
5962 : : struct mlx5_flow_meter_info *fm;
5963 : : struct mlx5_flow_meter_policy *mtr_policy;
5964 : 0 : struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
5965 : 0 : uint16_t flow_src_port = priv->representor_id;
5966 : 0 : bool all_ports = false;
5967 : :
5968 [ # # ]: 0 : if (!am)
5969 : 0 : return rte_flow_error_set(error, EINVAL,
5970 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5971 : : "meter action conf is NULL");
5972 : :
5973 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_METER)
5974 : 0 : return rte_flow_error_set(error, ENOTSUP,
5975 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5976 : : "meter chaining not support");
5977 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_JUMP)
5978 : 0 : return rte_flow_error_set(error, ENOTSUP,
5979 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5980 : : "meter with jump not support");
5981 [ # # ]: 0 : if (!priv->mtr_en)
5982 : 0 : return rte_flow_error_set(error, ENOTSUP,
5983 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5984 : : NULL,
5985 : : "meter action not supported");
5986 : 0 : fm = mlx5_flow_meter_find(priv, am->mtr_id, NULL);
5987 [ # # ]: 0 : if (!fm)
5988 : 0 : return rte_flow_error_set(error, EINVAL,
5989 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5990 : : "Meter not found");
5991 : : /* aso meter can always be shared by different domains */
5992 [ # # # # ]: 0 : if (fm->ref_cnt && !priv->sh->meter_aso_en &&
5993 [ # # ]: 0 : !(fm->transfer == attr->transfer ||
5994 [ # # # # ]: 0 : (!fm->ingress && !attr->ingress && attr->egress) ||
5995 [ # # # # ]: 0 : (!fm->egress && !attr->egress && attr->ingress)))
5996 : 0 : return rte_flow_error_set(error, EINVAL,
5997 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5998 : : "Flow attributes domain are either invalid "
5999 : : "or have a domain conflict with current "
6000 : : "meter attributes");
6001 [ # # ]: 0 : if (fm->def_policy) {
6002 [ # # ]: 0 : if (!((attr->transfer &&
6003 [ # # ]: 0 : mtrmng->def_policy[MLX5_MTR_DOMAIN_TRANSFER]) ||
6004 [ # # ]: 0 : (attr->egress &&
6005 [ # # ]: 0 : mtrmng->def_policy[MLX5_MTR_DOMAIN_EGRESS]) ||
6006 [ # # ]: 0 : (attr->ingress &&
6007 [ # # ]: 0 : mtrmng->def_policy[MLX5_MTR_DOMAIN_INGRESS])))
6008 : 0 : return rte_flow_error_set(error, EINVAL,
6009 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6010 : : "Flow attributes domain "
6011 : : "have a conflict with current "
6012 : : "meter domain attributes");
6013 : 0 : *def_policy = true;
6014 : : } else {
6015 : 0 : mtr_policy = mlx5_flow_meter_policy_find(dev,
6016 : : fm->policy_id, NULL);
6017 [ # # ]: 0 : if (!mtr_policy)
6018 : 0 : return rte_flow_error_set(error, EINVAL,
6019 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6020 : : "Invalid policy id for meter ");
6021 [ # # # # ]: 0 : if (!((attr->transfer && mtr_policy->transfer) ||
6022 [ # # # # ]: 0 : (attr->egress && mtr_policy->egress) ||
6023 [ # # # # ]: 0 : (attr->ingress && mtr_policy->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 : if (port_id_item) {
6030 [ # # ]: 0 : if (mlx5_flow_get_item_vport_id(dev, port_id_item, &flow_src_port,
6031 : : &all_ports, error))
6032 : 0 : return -rte_errno;
6033 : : }
6034 [ # # ]: 0 : if (attr->transfer) {
6035 : : /* When flow matching all src ports, meter should not have drop count. */
6036 [ # # # # : 0 : if (all_ports && (fm->drop_cnt || mtr_policy->hierarchy_match_port))
# # ]
6037 : 0 : return rte_flow_error_set(error, EINVAL,
6038 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
6039 : : "Meter drop count or "
6040 : : "modify_field/set_tag in meter hierarchy "
6041 : : "not supported when matching all ports.");
6042 [ # # ]: 0 : } else if (mtr_policy->is_rss) {
6043 : : struct mlx5_flow_meter_policy *fp;
6044 : : struct mlx5_meter_policy_action_container *acg;
6045 : : struct mlx5_meter_policy_action_container *acy;
6046 : : const struct rte_flow_action *rss_act;
6047 : : int ret;
6048 : :
6049 : 0 : fp = mlx5_flow_meter_hierarchy_get_final_policy(dev,
6050 : : mtr_policy);
6051 [ # # ]: 0 : if (fp == NULL)
6052 : 0 : return rte_flow_error_set(error, EINVAL,
6053 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6054 : : "Unable to get the final "
6055 : : "policy in the hierarchy");
6056 : : acg = &fp->act_cnt[RTE_COLOR_GREEN];
6057 : : acy = &fp->act_cnt[RTE_COLOR_YELLOW];
6058 : : MLX5_ASSERT(acg->fate_action ==
6059 : : MLX5_FLOW_FATE_SHARED_RSS ||
6060 : : acy->fate_action ==
6061 : : MLX5_FLOW_FATE_SHARED_RSS);
6062 [ # # ]: 0 : if (acg->fate_action == MLX5_FLOW_FATE_SHARED_RSS)
6063 : 0 : rss_act = acg->rss;
6064 : : else
6065 : 0 : rss_act = acy->rss;
6066 : 0 : ret = mlx5_flow_validate_action_rss(rss_act,
6067 : : action_flags, dev, attr,
6068 : : item_flags, error);
6069 [ # # ]: 0 : if (ret)
6070 : : return ret;
6071 : : }
6072 : 0 : *def_policy = false;
6073 : : }
6074 : : return 0;
6075 : : }
6076 : :
6077 : : /**
6078 : : * Validate the age action.
6079 : : *
6080 : : * @param[in] action_flags
6081 : : * Holds the actions detected until now.
6082 : : * @param[in] action
6083 : : * Pointer to the age action.
6084 : : * @param[in] dev
6085 : : * Pointer to the Ethernet device structure.
6086 : : * @param[out] error
6087 : : * Pointer to error structure.
6088 : : *
6089 : : * @return
6090 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
6091 : : */
6092 : : static int
6093 : 0 : flow_dv_validate_action_age(uint64_t action_flags,
6094 : : const struct rte_flow_action *action,
6095 : : struct rte_eth_dev *dev,
6096 : : struct rte_flow_error *error)
6097 : : {
6098 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6099 : 0 : const struct rte_flow_action_age *age = action->conf;
6100 : :
6101 [ # # ]: 0 : if (!priv->sh->cdev->config.devx ||
6102 [ # # # # ]: 0 : (priv->sh->sws_cmng.counter_fallback && !priv->sh->aso_age_mng))
6103 : 0 : return rte_flow_error_set(error, ENOTSUP,
6104 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6105 : : NULL,
6106 : : "age action not supported");
6107 [ # # ]: 0 : if (!(action->conf))
6108 : 0 : return rte_flow_error_set(error, EINVAL,
6109 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6110 : : "configuration cannot be null");
6111 [ # # ]: 0 : if (!(age->timeout))
6112 : 0 : return rte_flow_error_set(error, EINVAL,
6113 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6114 : : "invalid timeout value 0");
6115 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_AGE)
6116 : 0 : return rte_flow_error_set(error, EINVAL,
6117 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6118 : : "duplicate age actions set");
6119 : : return 0;
6120 : : }
6121 : :
6122 : : /**
6123 : : * Validate the modify-header IPv4 DSCP actions.
6124 : : *
6125 : : * @param[in] action_flags
6126 : : * Holds the actions detected until now.
6127 : : * @param[in] action
6128 : : * Pointer to the modify action.
6129 : : * @param[in] item_flags
6130 : : * Holds the items detected.
6131 : : * @param[out] error
6132 : : * Pointer to error structure.
6133 : : *
6134 : : * @return
6135 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
6136 : : */
6137 : : static int
6138 : 0 : flow_dv_validate_action_modify_ipv4_dscp(const uint64_t action_flags,
6139 : : const struct rte_flow_action *action,
6140 : : const uint64_t item_flags,
6141 : : struct rte_flow_error *error)
6142 : : {
6143 : : int ret = 0;
6144 : :
6145 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
6146 [ # # ]: 0 : if (!ret) {
6147 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV4))
6148 : 0 : return rte_flow_error_set(error, EINVAL,
6149 : : RTE_FLOW_ERROR_TYPE_ACTION,
6150 : : NULL,
6151 : : "no ipv4 item in pattern");
6152 : : }
6153 : : return ret;
6154 : : }
6155 : :
6156 : : /**
6157 : : * Validate the modify-header IPv6 DSCP actions.
6158 : : *
6159 : : * @param[in] action_flags
6160 : : * Holds the actions detected until now.
6161 : : * @param[in] action
6162 : : * Pointer to the modify action.
6163 : : * @param[in] item_flags
6164 : : * Holds the items detected.
6165 : : * @param[out] error
6166 : : * Pointer to error structure.
6167 : : *
6168 : : * @return
6169 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
6170 : : */
6171 : : static int
6172 : 0 : flow_dv_validate_action_modify_ipv6_dscp(const uint64_t action_flags,
6173 : : const struct rte_flow_action *action,
6174 : : const uint64_t item_flags,
6175 : : struct rte_flow_error *error)
6176 : : {
6177 : : int ret = 0;
6178 : :
6179 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
6180 [ # # ]: 0 : if (!ret) {
6181 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV6))
6182 : 0 : return rte_flow_error_set(error, EINVAL,
6183 : : RTE_FLOW_ERROR_TYPE_ACTION,
6184 : : NULL,
6185 : : "no ipv6 item in pattern");
6186 : : }
6187 : : return ret;
6188 : : }
6189 : :
6190 : : int
6191 : 0 : flow_modify_match_cb(void *tool_ctx __rte_unused,
6192 : : struct mlx5_list_entry *entry, void *cb_ctx)
6193 : : {
6194 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
6195 : 0 : struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
6196 : : struct mlx5_flow_dv_modify_hdr_resource *resource =
6197 : : container_of(entry, typeof(*resource), entry);
6198 : : uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type);
6199 : :
6200 : 0 : key_len += ref->actions_num * sizeof(ref->actions[0]);
6201 [ # # ]: 0 : return ref->actions_num != resource->actions_num ||
6202 [ # # ]: 0 : memcmp(&ref->ft_type, &resource->ft_type, key_len);
6203 : : }
6204 : :
6205 : : static struct mlx5_indexed_pool *
6206 : 0 : flow_dv_modify_ipool_get(struct mlx5_dev_ctx_shared *sh, uint8_t index)
6207 : : {
6208 : 0 : struct mlx5_indexed_pool *ipool = rte_atomic_load_explicit
6209 : : (&sh->mdh_ipools[index], rte_memory_order_seq_cst);
6210 : :
6211 [ # # ]: 0 : if (!ipool) {
6212 : : struct mlx5_indexed_pool *expected = NULL;
6213 : 0 : struct mlx5_indexed_pool_config cfg =
6214 : : (struct mlx5_indexed_pool_config) {
6215 : 0 : .size = sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
6216 : 0 : (index + 1) *
6217 : : sizeof(struct mlx5_modification_cmd),
6218 : : .trunk_size = 64,
6219 : : .grow_trunk = 3,
6220 : : .grow_shift = 2,
6221 : : .need_lock = 1,
6222 : 0 : .release_mem_en = !!sh->config.reclaim_mode,
6223 : : .per_core_cache =
6224 [ # # ]: 0 : sh->config.reclaim_mode ? 0 : (1 << 16),
6225 : : .malloc = mlx5_malloc,
6226 : : .free = mlx5_free,
6227 : : .type = "mlx5_modify_action_resource",
6228 : : };
6229 : :
6230 : 0 : cfg.size = RTE_ALIGN(cfg.size, sizeof(ipool));
6231 : 0 : ipool = mlx5_ipool_create(&cfg);
6232 [ # # ]: 0 : if (!ipool)
6233 : 0 : return NULL;
6234 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(&sh->mdh_ipools[index],
6235 : : &expected, ipool,
6236 : : rte_memory_order_seq_cst,
6237 : : rte_memory_order_seq_cst)) {
6238 : 0 : mlx5_ipool_destroy(ipool);
6239 : 0 : ipool = rte_atomic_load_explicit(&sh->mdh_ipools[index],
6240 : : rte_memory_order_seq_cst);
6241 : : }
6242 : : }
6243 : : return ipool;
6244 : : }
6245 : :
6246 : : struct mlx5_list_entry *
6247 : 0 : flow_modify_create_cb(void *tool_ctx, void *cb_ctx)
6248 : : {
6249 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
6250 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
6251 : : struct mlx5dv_dr_domain *ns;
6252 : : struct mlx5_flow_dv_modify_hdr_resource *entry;
6253 : 0 : struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
6254 : 0 : struct mlx5_indexed_pool *ipool = flow_dv_modify_ipool_get(sh,
6255 : 0 : ref->actions_num - 1);
6256 : : int ret = 0;
6257 : 0 : uint32_t data_len = ref->actions_num * sizeof(ref->actions[0]);
6258 : : uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type);
6259 : : uint32_t idx;
6260 : :
6261 [ # # ]: 0 : if (unlikely(!ipool)) {
6262 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
6263 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6264 : : NULL, "cannot allocate modify ipool");
6265 : 0 : return NULL;
6266 : : }
6267 : 0 : entry = mlx5_ipool_zmalloc(ipool, &idx);
6268 [ # # ]: 0 : if (!entry) {
6269 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
6270 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6271 : : "cannot allocate resource memory");
6272 : 0 : return NULL;
6273 : : }
6274 : 0 : rte_memcpy(&entry->ft_type,
6275 : 0 : RTE_PTR_ADD(ref, offsetof(typeof(*ref), ft_type)),
6276 [ # # ]: 0 : key_len + data_len);
6277 [ # # ]: 0 : if (sh->config.dv_flow_en == 2) {
6278 : : #ifdef HAVE_MLX5_HWS_SUPPORT
6279 : 0 : struct mlx5dr_action_mh_pattern pattern = {
6280 : : .sz = data_len,
6281 : 0 : .data = (__be64 *)ref->actions
6282 : : };
6283 : 0 : entry->action = mlx5dr_action_create_modify_header(ctx->data2,
6284 : : 1,
6285 : 0 : &pattern, 0, ref->flags);
6286 [ # # ]: 0 : if (!entry->action)
6287 : : ret = -1;
6288 : : #else
6289 : : ret = -1;
6290 : : #endif
6291 : : } else {
6292 [ # # ]: 0 : if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
6293 : 0 : ns = sh->fdb_domain;
6294 [ # # ]: 0 : else if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
6295 : 0 : ns = sh->tx_domain;
6296 : : else
6297 : 0 : ns = sh->rx_domain;
6298 : 0 : ret = mlx5_flow_os_create_flow_action_modify_header
6299 : 0 : (sh->cdev->ctx, ns, entry,
6300 : : data_len, &entry->action);
6301 : : }
6302 : : if (ret) {
6303 : 0 : mlx5_ipool_free(sh->mdh_ipools[ref->actions_num - 1], idx);
6304 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
6305 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6306 : : NULL, "cannot create modification action");
6307 : 0 : return NULL;
6308 : : }
6309 : 0 : entry->idx = idx;
6310 : 0 : return &entry->entry;
6311 : : }
6312 : :
6313 : : struct mlx5_list_entry *
6314 : 0 : flow_modify_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
6315 : : void *cb_ctx)
6316 : : {
6317 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
6318 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
6319 : : struct mlx5_flow_dv_modify_hdr_resource *entry;
6320 : 0 : struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
6321 : 0 : uint32_t data_len = ref->actions_num * sizeof(ref->actions[0]);
6322 : : uint32_t idx;
6323 : :
6324 : 0 : entry = mlx5_ipool_malloc(sh->mdh_ipools[ref->actions_num - 1],
6325 : : &idx);
6326 [ # # ]: 0 : if (!entry) {
6327 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
6328 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6329 : : "cannot allocate resource memory");
6330 : 0 : return NULL;
6331 : : }
6332 : 0 : memcpy(entry, oentry, sizeof(*entry) + data_len);
6333 : 0 : entry->idx = idx;
6334 : 0 : return &entry->entry;
6335 : : }
6336 : :
6337 : : void
6338 : 0 : flow_modify_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
6339 : : {
6340 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
6341 : : struct mlx5_flow_dv_modify_hdr_resource *res =
6342 : : container_of(entry, typeof(*res), entry);
6343 : :
6344 : 0 : mlx5_ipool_free(sh->mdh_ipools[res->actions_num - 1], res->idx);
6345 : 0 : }
6346 : :
6347 : : /**
6348 : : * Validate the sample action.
6349 : : *
6350 : : * @param[in, out] action_flags
6351 : : * Holds the actions detected until now.
6352 : : * @param[in] action
6353 : : * Pointer to the sample action.
6354 : : * @param[in] dev
6355 : : * Pointer to the Ethernet device structure.
6356 : : * @param[in] attr
6357 : : * Attributes of flow that includes this action.
6358 : : * @param[in] item_flags
6359 : : * Holds the items detected.
6360 : : * @param[in] rss
6361 : : * Pointer to the RSS action.
6362 : : * @param[out] sample_rss
6363 : : * Pointer to the RSS action in sample action list.
6364 : : * @param[out] count
6365 : : * Pointer to the COUNT action in sample action list.
6366 : : * @param[out] fdb_mirror
6367 : : * Pointer to the FDB mirror flag.
6368 : : * @param root
6369 : : * Whether action is on root table.
6370 : : * @param[out] error
6371 : : * Pointer to error structure.
6372 : : *
6373 : : * @return
6374 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
6375 : : */
6376 : : static int
6377 : 0 : flow_dv_validate_action_sample(uint64_t *action_flags,
6378 : : uint64_t *sub_action_flags,
6379 : : const struct rte_flow_action *action,
6380 : : struct rte_eth_dev *dev,
6381 : : const struct rte_flow_attr *attr,
6382 : : uint64_t item_flags,
6383 : : const struct rte_flow_action_rss *rss,
6384 : : const struct rte_flow_action_rss **sample_rss,
6385 : : const struct rte_flow_action_count **count,
6386 : : int *fdb_mirror,
6387 : : uint16_t *sample_port_id,
6388 : : bool root,
6389 : : struct rte_flow_error *error)
6390 : : {
6391 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6392 : 0 : struct mlx5_sh_config *dev_conf = &priv->sh->config;
6393 : 0 : const struct rte_flow_action_sample *sample = action->conf;
6394 : : const struct rte_flow_action_port_id *port = NULL;
6395 : : const struct rte_flow_action *act;
6396 : : uint16_t queue_index = 0xFFFF;
6397 : 0 : int actions_n = 0;
6398 : : int ret;
6399 : :
6400 [ # # ]: 0 : if (!sample)
6401 : 0 : return rte_flow_error_set(error, EINVAL,
6402 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6403 : : "configuration cannot be NULL");
6404 [ # # ]: 0 : if (sample->ratio == 0)
6405 : 0 : return rte_flow_error_set(error, EINVAL,
6406 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6407 : : "ratio value starts from 1");
6408 [ # # ]: 0 : if (!priv->sh->cdev->config.devx ||
6409 [ # # ]: 0 : (sample->ratio > 0 && !priv->sampler_en))
6410 : 0 : return rte_flow_error_set(error, ENOTSUP,
6411 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6412 : : NULL,
6413 : : "sample action not supported");
6414 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_SAMPLE)
6415 : 0 : return rte_flow_error_set(error, EINVAL,
6416 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6417 : : "Multiple sample actions not "
6418 : : "supported");
6419 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_METER)
6420 : 0 : return rte_flow_error_set(error, EINVAL,
6421 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6422 : : "wrong action order, meter should "
6423 : : "be after sample action");
6424 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_JUMP)
6425 : 0 : return rte_flow_error_set(error, EINVAL,
6426 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6427 : : "wrong action order, jump should "
6428 : : "be after sample action");
6429 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_CT)
6430 : 0 : return rte_flow_error_set(error, EINVAL,
6431 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6432 : : "Sample after CT not supported");
6433 : 0 : act = sample->actions;
6434 [ # # ]: 0 : for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++) {
6435 [ # # ]: 0 : if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
6436 : 0 : return rte_flow_error_set(error, ENOTSUP,
6437 : : RTE_FLOW_ERROR_TYPE_ACTION,
6438 : : act, "too many actions");
6439 [ # # # # : 0 : switch (act->type) {
# # # # ]
6440 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
6441 : 0 : ret = mlx5_flow_validate_action_queue(act,
6442 : : *sub_action_flags,
6443 : : dev,
6444 : : attr, error);
6445 [ # # ]: 0 : if (ret < 0)
6446 : 0 : return ret;
6447 : 0 : queue_index = ((const struct rte_flow_action_queue *)
6448 : 0 : (act->conf))->index;
6449 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_QUEUE;
6450 : 0 : ++actions_n;
6451 : 0 : break;
6452 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
6453 : 0 : *sample_rss = act->conf;
6454 : 0 : ret = mlx5_flow_validate_action_rss(act,
6455 : : *sub_action_flags,
6456 : : dev, attr,
6457 : : item_flags,
6458 : : error);
6459 [ # # ]: 0 : if (ret < 0)
6460 : 0 : return ret;
6461 [ # # # # ]: 0 : if (rss && *sample_rss &&
6462 [ # # ]: 0 : ((*sample_rss)->level != rss->level ||
6463 [ # # ]: 0 : (*sample_rss)->types != rss->types))
6464 : 0 : return rte_flow_error_set(error, ENOTSUP,
6465 : : RTE_FLOW_ERROR_TYPE_ACTION,
6466 : : NULL,
6467 : : "Can't use the different RSS types "
6468 : : "or level in the same flow");
6469 [ # # # # ]: 0 : if (*sample_rss != NULL && (*sample_rss)->queue_num)
6470 : 0 : queue_index = (*sample_rss)->queue[0];
6471 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_RSS;
6472 : 0 : ++actions_n;
6473 : 0 : break;
6474 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
6475 : 0 : ret = flow_dv_validate_action_mark(dev, act,
6476 : : *sub_action_flags,
6477 : : attr, error);
6478 [ # # ]: 0 : if (ret < 0)
6479 : 0 : return ret;
6480 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY)
6481 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_MARK |
6482 : : MLX5_FLOW_ACTION_MARK_EXT;
6483 : : else
6484 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_MARK;
6485 : 0 : ++actions_n;
6486 : 0 : break;
6487 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
6488 : 0 : ret = flow_dv_validate_action_count
6489 : 0 : (dev, false, *action_flags | *sub_action_flags,
6490 : : root, error);
6491 [ # # ]: 0 : if (ret < 0)
6492 : 0 : return ret;
6493 : 0 : *count = act->conf;
6494 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_COUNT;
6495 : 0 : *action_flags |= MLX5_FLOW_ACTION_COUNT;
6496 : 0 : ++actions_n;
6497 : 0 : break;
6498 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
6499 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
6500 : 0 : ret = flow_dv_validate_action_port_id(dev,
6501 : : *sub_action_flags,
6502 : : act,
6503 : : attr,
6504 : : error);
6505 [ # # ]: 0 : if (ret)
6506 : 0 : return ret;
6507 [ # # ]: 0 : if (act->type == RTE_FLOW_ACTION_TYPE_PORT_ID) {
6508 : 0 : port = (const struct rte_flow_action_port_id *)
6509 : : act->conf;
6510 [ # # ]: 0 : *sample_port_id = port->original ?
6511 : 0 : dev->data->port_id : port->id;
6512 : : } else {
6513 : 0 : *sample_port_id = ((const struct rte_flow_action_ethdev *)
6514 : 0 : act->conf)->port_id;
6515 : : }
6516 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_PORT_ID;
6517 : 0 : ++actions_n;
6518 : 0 : break;
6519 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
6520 : 0 : ret = mlx5_flow_dv_validate_action_raw_encap_decap
6521 : 0 : (dev, NULL, act->conf, attr, sub_action_flags,
6522 : : &actions_n, action, item_flags, error);
6523 [ # # ]: 0 : if (ret < 0)
6524 : 0 : return ret;
6525 : 0 : ++actions_n;
6526 : 0 : break;
6527 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
6528 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
6529 : 0 : ret = mlx5_flow_dv_validate_action_l2_encap(dev,
6530 : : *sub_action_flags,
6531 : : act, attr,
6532 : : error);
6533 [ # # ]: 0 : if (ret < 0)
6534 : 0 : return ret;
6535 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_ENCAP;
6536 : 0 : ++actions_n;
6537 : 0 : break;
6538 : 0 : default:
6539 : 0 : return rte_flow_error_set(error, ENOTSUP,
6540 : : RTE_FLOW_ERROR_TYPE_ACTION,
6541 : : NULL,
6542 : : "Doesn't support optional "
6543 : : "action");
6544 : : }
6545 : : }
6546 [ # # ]: 0 : if (attr->ingress) {
6547 [ # # ]: 0 : if (!(*sub_action_flags & (MLX5_FLOW_ACTION_QUEUE |
6548 : : MLX5_FLOW_ACTION_RSS)))
6549 : 0 : return rte_flow_error_set(error, EINVAL,
6550 : : RTE_FLOW_ERROR_TYPE_ACTION,
6551 : : NULL,
6552 : : "Ingress must has a dest "
6553 : : "QUEUE for Sample");
6554 [ # # ]: 0 : } else if (attr->egress) {
6555 : 0 : return rte_flow_error_set(error, ENOTSUP,
6556 : : RTE_FLOW_ERROR_TYPE_ACTION,
6557 : : NULL,
6558 : : "Sample Only support Ingress "
6559 : : "or E-Switch");
6560 [ # # ]: 0 : } else if (sample->actions->type != RTE_FLOW_ACTION_TYPE_END) {
6561 : : MLX5_ASSERT(attr->transfer);
6562 [ # # ]: 0 : if (sample->ratio > 1)
6563 : 0 : return rte_flow_error_set(error, ENOTSUP,
6564 : : RTE_FLOW_ERROR_TYPE_ACTION,
6565 : : NULL,
6566 : : "E-Switch doesn't support "
6567 : : "any optional action "
6568 : : "for sampling");
6569 [ # # ]: 0 : if (*sub_action_flags & MLX5_FLOW_ACTION_QUEUE)
6570 : 0 : return rte_flow_error_set(error, ENOTSUP,
6571 : : RTE_FLOW_ERROR_TYPE_ACTION,
6572 : : NULL,
6573 : : "unsupported action QUEUE");
6574 [ # # ]: 0 : if (*sub_action_flags & MLX5_FLOW_ACTION_RSS)
6575 : 0 : return rte_flow_error_set(error, ENOTSUP,
6576 : : RTE_FLOW_ERROR_TYPE_ACTION,
6577 : : NULL,
6578 : : "unsupported action QUEUE");
6579 [ # # ]: 0 : if (!(*sub_action_flags & MLX5_FLOW_ACTION_PORT_ID))
6580 : 0 : return rte_flow_error_set(error, EINVAL,
6581 : : RTE_FLOW_ERROR_TYPE_ACTION,
6582 : : NULL,
6583 : : "E-Switch must has a dest "
6584 : : "port for mirroring");
6585 : 0 : *fdb_mirror = 1;
6586 : : }
6587 : : /* Continue validation for Xcap actions.*/
6588 [ # # # # ]: 0 : if ((*sub_action_flags & MLX5_FLOW_XCAP_ACTIONS) &&
6589 [ # # ]: 0 : (queue_index == 0xFFFF || !mlx5_rxq_is_hairpin(dev, queue_index))) {
6590 [ # # ]: 0 : if ((*sub_action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
6591 : : MLX5_FLOW_XCAP_ACTIONS)
6592 : 0 : return rte_flow_error_set(error, ENOTSUP,
6593 : : RTE_FLOW_ERROR_TYPE_ACTION,
6594 : : NULL, "encap and decap "
6595 : : "combination aren't "
6596 : : "supported");
6597 [ # # # # ]: 0 : if (attr->ingress && (*sub_action_flags & MLX5_FLOW_ACTION_ENCAP))
6598 : 0 : return rte_flow_error_set(error, ENOTSUP,
6599 : : RTE_FLOW_ERROR_TYPE_ACTION,
6600 : : NULL, "encap is not supported"
6601 : : " for ingress traffic");
6602 : : }
6603 : : return 0;
6604 : : }
6605 : :
6606 : : int
6607 : 0 : __flow_modify_hdr_resource_register(struct rte_eth_dev *dev,
6608 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
6609 : : struct mlx5_flow_dv_modify_hdr_resource **modify,
6610 : : struct rte_flow_error *error)
6611 : : {
6612 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6613 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
6614 : 0 : uint32_t key_len = sizeof(*resource) -
6615 : : offsetof(typeof(*resource), ft_type) +
6616 : 0 : resource->actions_num * sizeof(resource->actions[0]);
6617 : : struct mlx5_list_entry *entry;
6618 : 0 : struct mlx5_flow_cb_ctx ctx = {
6619 : : .error = error,
6620 : : .data = resource,
6621 : 0 : .data2 = priv->dr_ctx,
6622 : : };
6623 : : struct mlx5_hlist *modify_cmds;
6624 : : uint64_t key64;
6625 : :
6626 : 0 : modify_cmds = flow_dv_hlist_prepare(sh, &sh->modify_cmds,
6627 : : "hdr_modify",
6628 : : MLX5_FLOW_HDR_MODIFY_HTABLE_SZ,
6629 : : true, false, sh,
6630 : : flow_modify_create_cb,
6631 : : flow_modify_match_cb,
6632 : : flow_modify_remove_cb,
6633 : : flow_modify_clone_cb,
6634 : : flow_modify_clone_free_cb,
6635 : : error);
6636 [ # # ]: 0 : if (unlikely(!modify_cmds))
6637 : 0 : return -rte_errno;
6638 [ # # ]: 0 : if (resource->actions_num > flow_dv_modify_hdr_action_max(dev,
6639 [ # # ]: 0 : resource->root))
6640 : 0 : return rte_flow_error_set(error, EOVERFLOW,
6641 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6642 : : "too many modify header items");
6643 : 0 : key64 = __rte_raw_cksum(&resource->ft_type, key_len, 0);
6644 : 0 : entry = mlx5_hlist_register(modify_cmds, key64, &ctx);
6645 [ # # ]: 0 : if (!entry)
6646 : 0 : return -rte_errno;
6647 : 0 : *modify = container_of(entry, typeof(*resource), entry);
6648 : 0 : return 0;
6649 : : }
6650 : :
6651 : : /**
6652 : : * Find existing modify-header resource or create and register a new one.
6653 : : *
6654 : : * @param dev[in, out]
6655 : : * Pointer to rte_eth_dev structure.
6656 : : * @param[in, out] resource
6657 : : * Pointer to modify-header resource.
6658 : : * @param[in, out] dev_flow
6659 : : * Pointer to the dev_flow.
6660 : : * @param[out] error
6661 : : * pointer to error structure.
6662 : : *
6663 : : * @return
6664 : : * 0 on success otherwise -errno and errno is set.
6665 : : */
6666 : : static int
6667 : : flow_dv_modify_hdr_resource_register
6668 : : (struct rte_eth_dev *dev,
6669 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
6670 : : struct mlx5_flow *dev_flow,
6671 : : struct rte_flow_error *error)
6672 : : {
6673 : 0 : resource->root = !dev_flow->dv.group;
6674 : 0 : return __flow_modify_hdr_resource_register(dev, resource,
6675 : 0 : &dev_flow->handle->dvh.modify_hdr, error);
6676 : : }
6677 : :
6678 : : /**
6679 : : * Get DV flow counter by index.
6680 : : *
6681 : : * @param[in] dev
6682 : : * Pointer to the Ethernet device structure.
6683 : : * @param[in] idx
6684 : : * mlx5 flow counter index in the container.
6685 : : * @param[out] ppool
6686 : : * mlx5 flow counter pool in the container.
6687 : : *
6688 : : * @return
6689 : : * Pointer to the counter, NULL otherwise.
6690 : : */
6691 : : static struct mlx5_flow_counter *
6692 : : flow_dv_counter_get_by_idx(struct rte_eth_dev *dev,
6693 : : uint32_t idx,
6694 : : struct mlx5_flow_counter_pool **ppool)
6695 : : {
6696 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6697 : 0 : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
6698 : : struct mlx5_flow_counter_pool *pool;
6699 : :
6700 : : /* Decrease to original index and clear shared bit. */
6701 : 0 : idx = (idx - 1) & (MLX5_CNT_SHARED_OFFSET - 1);
6702 : : MLX5_ASSERT(idx / MLX5_COUNTERS_PER_POOL < MLX5_COUNTER_POOLS_MAX_NUM);
6703 : 0 : pool = cmng->pools[idx / MLX5_COUNTERS_PER_POOL];
6704 : : MLX5_ASSERT(pool);
6705 : : if (ppool)
6706 : : *ppool = pool;
6707 [ # # # # : 0 : return MLX5_POOL_GET_CNT(pool, idx % MLX5_COUNTERS_PER_POOL);
# # # # #
# # # ]
6708 : : }
6709 : :
6710 : : /**
6711 : : * Check the devx counter belongs to the pool.
6712 : : *
6713 : : * @param[in] pool
6714 : : * Pointer to the counter pool.
6715 : : * @param[in] id
6716 : : * The counter devx ID.
6717 : : *
6718 : : * @return
6719 : : * True if counter belongs to the pool, false otherwise.
6720 : : */
6721 : : static bool
6722 : : flow_dv_is_counter_in_pool(struct mlx5_flow_counter_pool *pool, int id)
6723 : : {
6724 : 0 : int base = (pool->min_dcs->id / MLX5_COUNTERS_PER_POOL) *
6725 : : MLX5_COUNTERS_PER_POOL;
6726 : :
6727 [ # # # # ]: 0 : if (id >= base && id < base + MLX5_COUNTERS_PER_POOL)
6728 : : return true;
6729 : : return false;
6730 : : }
6731 : :
6732 : : /**
6733 : : * Get a pool by devx counter ID.
6734 : : *
6735 : : * @param[in] cmng
6736 : : * Pointer to the counter management.
6737 : : * @param[in] id
6738 : : * The counter devx ID.
6739 : : *
6740 : : * @return
6741 : : * The counter pool pointer if exists, NULL otherwise,
6742 : : */
6743 : : static struct mlx5_flow_counter_pool *
6744 : 0 : flow_dv_find_pool_by_id(struct mlx5_flow_counter_mng *cmng, int id)
6745 : : {
6746 : : uint32_t i;
6747 : : struct mlx5_flow_counter_pool *pool = NULL;
6748 : :
6749 : 0 : rte_spinlock_lock(&cmng->pool_update_sl);
6750 : : /* Check last used pool. */
6751 [ # # ]: 0 : if (cmng->last_pool_idx != POOL_IDX_INVALID &&
6752 [ # # ]: 0 : flow_dv_is_counter_in_pool(cmng->pools[cmng->last_pool_idx], id)) {
6753 : : pool = cmng->pools[cmng->last_pool_idx];
6754 : 0 : goto out;
6755 : : }
6756 : : /* ID out of range means no suitable pool in the container. */
6757 [ # # # # ]: 0 : if (id > cmng->max_id || id < cmng->min_id)
6758 : 0 : goto out;
6759 : : /*
6760 : : * Find the pool from the end of the container, since mostly counter
6761 : : * ID is sequence increasing, and the last pool should be the needed
6762 : : * one.
6763 : : */
6764 : 0 : i = cmng->n_valid;
6765 [ # # ]: 0 : while (i--) {
6766 [ # # ]: 0 : struct mlx5_flow_counter_pool *pool_tmp = cmng->pools[i];
6767 : :
6768 : : if (flow_dv_is_counter_in_pool(pool_tmp, id)) {
6769 : : pool = pool_tmp;
6770 : : break;
6771 : : }
6772 : : }
6773 : 0 : out:
6774 : : rte_spinlock_unlock(&cmng->pool_update_sl);
6775 : 0 : return pool;
6776 : : }
6777 : :
6778 : : /**
6779 : : * Query a devx flow counter.
6780 : : *
6781 : : * @param[in] dev
6782 : : * Pointer to the Ethernet device structure.
6783 : : * @param[in] counter
6784 : : * Index to the flow counter.
6785 : : * @param[out] pkts
6786 : : * The statistics value of packets.
6787 : : * @param[out] bytes
6788 : : * The statistics value of bytes.
6789 : : *
6790 : : * @return
6791 : : * 0 on success, otherwise a negative errno value and rte_errno is set.
6792 : : */
6793 : : static inline int
6794 : 0 : _flow_dv_query_count(struct rte_eth_dev *dev, uint32_t counter, uint64_t *pkts,
6795 : : uint64_t *bytes)
6796 : : {
6797 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
6798 : : struct mlx5_flow_counter_pool *pool = NULL;
6799 : : struct mlx5_flow_counter *cnt;
6800 : : int offset;
6801 : :
6802 : : cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
6803 : : MLX5_ASSERT(pool);
6804 [ # # ]: 0 : if (priv->sh->sws_cmng.counter_fallback)
6805 : 0 : return mlx5_devx_cmd_flow_counter_query(cnt->dcs_when_active, 0,
6806 : : 0, pkts, bytes, 0, NULL, NULL, 0);
6807 : 0 : rte_spinlock_lock(&pool->sl);
6808 [ # # ]: 0 : if (!pool->raw) {
6809 : 0 : *pkts = 0;
6810 : 0 : *bytes = 0;
6811 : : } else {
6812 [ # # ]: 0 : offset = MLX5_CNT_ARRAY_IDX(pool, cnt);
6813 : 0 : *pkts = rte_be_to_cpu_64(pool->raw->data[offset].hits);
6814 : 0 : *bytes = rte_be_to_cpu_64(pool->raw->data[offset].bytes);
6815 : : }
6816 : : rte_spinlock_unlock(&pool->sl);
6817 : 0 : return 0;
6818 : : }
6819 : :
6820 : : /**
6821 : : * Create and initialize a new counter pool.
6822 : : *
6823 : : * @param[in] dev
6824 : : * Pointer to the Ethernet device structure.
6825 : : * @param[out] dcs
6826 : : * The devX counter handle.
6827 : : * @param[in] age
6828 : : * Whether the pool is for counter that was allocated for aging.
6829 : : *
6830 : : * @return
6831 : : * The pool container pointer on success, NULL otherwise and rte_errno is set.
6832 : : */
6833 : : static struct mlx5_flow_counter_pool *
6834 : 0 : flow_dv_pool_create(struct rte_eth_dev *dev, struct mlx5_devx_obj *dcs,
6835 : : uint32_t age)
6836 : : {
6837 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6838 : : struct mlx5_flow_counter_pool *pool;
6839 : 0 : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
6840 : 0 : bool fallback = cmng->counter_fallback;
6841 : : uint32_t size = sizeof(*pool);
6842 : :
6843 [ # # ]: 0 : if (cmng->n_valid == MLX5_COUNTER_POOLS_MAX_NUM) {
6844 : 0 : DRV_LOG(ERR, "All counter is in used, try again later.");
6845 : 0 : rte_errno = EAGAIN;
6846 : 0 : return NULL;
6847 : : }
6848 : : size += MLX5_COUNTERS_PER_POOL * MLX5_CNT_SIZE;
6849 [ # # ]: 0 : size += (!age ? 0 : MLX5_COUNTERS_PER_POOL * MLX5_AGE_SIZE);
6850 : 0 : pool = mlx5_malloc(MLX5_MEM_ZERO, size, 0, SOCKET_ID_ANY);
6851 [ # # ]: 0 : if (!pool) {
6852 : 0 : rte_errno = ENOMEM;
6853 : 0 : return NULL;
6854 : : }
6855 : 0 : pool->raw = NULL;
6856 : 0 : pool->is_aged = !!age;
6857 : 0 : pool->query_gen = 0;
6858 : 0 : pool->min_dcs = dcs;
6859 : : rte_spinlock_init(&pool->sl);
6860 : : rte_spinlock_init(&pool->csl);
6861 : 0 : TAILQ_INIT(&pool->counters[0]);
6862 : 0 : TAILQ_INIT(&pool->counters[1]);
6863 : 0 : pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
6864 : 0 : rte_spinlock_lock(&cmng->pool_update_sl);
6865 : 0 : pool->index = cmng->n_valid;
6866 : 0 : cmng->pools[pool->index] = pool;
6867 : 0 : cmng->n_valid++;
6868 [ # # ]: 0 : if (unlikely(fallback)) {
6869 : 0 : int base = RTE_ALIGN_FLOOR(dcs->id, MLX5_COUNTERS_PER_POOL);
6870 : :
6871 [ # # ]: 0 : if (base < cmng->min_id)
6872 : 0 : cmng->min_id = base;
6873 [ # # ]: 0 : if (base > cmng->max_id)
6874 : 0 : cmng->max_id = base + MLX5_COUNTERS_PER_POOL - 1;
6875 : 0 : cmng->last_pool_idx = pool->index;
6876 : : }
6877 : : rte_spinlock_unlock(&cmng->pool_update_sl);
6878 : 0 : return pool;
6879 : : }
6880 : :
6881 : : /**
6882 : : * Prepare a new counter and/or a new counter pool.
6883 : : *
6884 : : * @param[in] dev
6885 : : * Pointer to the Ethernet device structure.
6886 : : * @param[out] cnt_free
6887 : : * Where to put the pointer of a new counter.
6888 : : * @param[in] age
6889 : : * Whether the pool is for counter that was allocated for aging.
6890 : : *
6891 : : * @return
6892 : : * The counter pool pointer and @p cnt_free is set on success,
6893 : : * NULL otherwise and rte_errno is set.
6894 : : */
6895 : : static struct mlx5_flow_counter_pool *
6896 : 0 : flow_dv_counter_pool_prepare(struct rte_eth_dev *dev,
6897 : : struct mlx5_flow_counter **cnt_free,
6898 : : uint32_t age)
6899 : : {
6900 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6901 : 0 : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
6902 : : struct mlx5_flow_counter_pool *pool;
6903 : : struct mlx5_counters tmp_tq;
6904 : : struct mlx5_devx_obj *dcs = NULL;
6905 : : struct mlx5_flow_counter *cnt;
6906 : 0 : enum mlx5_counter_type cnt_type =
6907 : 0 : age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
6908 : 0 : bool fallback = priv->sh->sws_cmng.counter_fallback;
6909 : : uint32_t i;
6910 : :
6911 [ # # ]: 0 : if (fallback) {
6912 : : /* bulk_bitmap must be 0 for single counter allocation. */
6913 : 0 : dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0);
6914 [ # # ]: 0 : if (!dcs)
6915 : : return NULL;
6916 : 0 : pool = flow_dv_find_pool_by_id(cmng, dcs->id);
6917 [ # # ]: 0 : if (!pool) {
6918 : 0 : pool = flow_dv_pool_create(dev, dcs, age);
6919 [ # # ]: 0 : if (!pool) {
6920 : 0 : mlx5_devx_cmd_destroy(dcs);
6921 : 0 : return NULL;
6922 : : }
6923 : : }
6924 : 0 : i = dcs->id % MLX5_COUNTERS_PER_POOL;
6925 [ # # ]: 0 : cnt = MLX5_POOL_GET_CNT(pool, i);
6926 : 0 : cnt->pool = pool;
6927 : 0 : cnt->dcs_when_free = dcs;
6928 : 0 : *cnt_free = cnt;
6929 : 0 : return pool;
6930 : : }
6931 : 0 : dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0x4);
6932 [ # # ]: 0 : if (!dcs) {
6933 : 0 : rte_errno = ENODATA;
6934 : 0 : return NULL;
6935 : : }
6936 : 0 : pool = flow_dv_pool_create(dev, dcs, age);
6937 [ # # ]: 0 : if (!pool) {
6938 : 0 : mlx5_devx_cmd_destroy(dcs);
6939 : 0 : return NULL;
6940 : : }
6941 : 0 : TAILQ_INIT(&tmp_tq);
6942 [ # # ]: 0 : for (i = 1; i < MLX5_COUNTERS_PER_POOL; ++i) {
6943 [ # # ]: 0 : cnt = MLX5_POOL_GET_CNT(pool, i);
6944 : 0 : cnt->pool = pool;
6945 [ # # ]: 0 : TAILQ_INSERT_HEAD(&tmp_tq, cnt, next);
6946 : : }
6947 : 0 : rte_spinlock_lock(&cmng->csl[cnt_type]);
6948 [ # # ]: 0 : TAILQ_CONCAT(&cmng->counters[cnt_type], &tmp_tq, next);
6949 : : rte_spinlock_unlock(&cmng->csl[cnt_type]);
6950 : 0 : *cnt_free = MLX5_POOL_GET_CNT(pool, 0);
6951 : 0 : (*cnt_free)->pool = pool;
6952 : 0 : return pool;
6953 : : }
6954 : :
6955 : : /**
6956 : : * Allocate a flow counter.
6957 : : *
6958 : : * @param[in] dev
6959 : : * Pointer to the Ethernet device structure.
6960 : : * @param[in] age
6961 : : * Whether the counter was allocated for aging.
6962 : : *
6963 : : * @return
6964 : : * Index to flow counter on success, 0 otherwise and rte_errno is set.
6965 : : */
6966 : : static uint32_t
6967 : 0 : flow_dv_counter_alloc(struct rte_eth_dev *dev, uint32_t age)
6968 : : {
6969 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6970 : : struct mlx5_flow_counter_pool *pool = NULL;
6971 : 0 : struct mlx5_flow_counter *cnt_free = NULL;
6972 : 0 : bool fallback = priv->sh->sws_cmng.counter_fallback;
6973 : : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
6974 : 0 : enum mlx5_counter_type cnt_type =
6975 : 0 : age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
6976 : : uint32_t cnt_idx;
6977 : :
6978 [ # # ]: 0 : if (!priv->sh->cdev->config.devx) {
6979 : 0 : rte_errno = ENOTSUP;
6980 : 0 : return 0;
6981 : : }
6982 : : /* Get free counters from container. */
6983 : 0 : rte_spinlock_lock(&cmng->csl[cnt_type]);
6984 : 0 : cnt_free = TAILQ_FIRST(&cmng->counters[cnt_type]);
6985 [ # # ]: 0 : if (cnt_free)
6986 [ # # ]: 0 : TAILQ_REMOVE(&cmng->counters[cnt_type], cnt_free, next);
6987 : : rte_spinlock_unlock(&cmng->csl[cnt_type]);
6988 [ # # # # ]: 0 : if (!cnt_free && !flow_dv_counter_pool_prepare(dev, &cnt_free, age))
6989 : 0 : goto err;
6990 : 0 : pool = cnt_free->pool;
6991 [ # # ]: 0 : if (fallback)
6992 : 0 : cnt_free->dcs_when_active = cnt_free->dcs_when_free;
6993 : : /* Create a DV counter action only in the first time usage. */
6994 [ # # ]: 0 : if (!cnt_free->action) {
6995 : : uint16_t offset;
6996 : : struct mlx5_devx_obj *dcs;
6997 : : int ret;
6998 : :
6999 [ # # ]: 0 : if (!fallback) {
7000 [ # # ]: 0 : offset = MLX5_CNT_ARRAY_IDX(pool, cnt_free);
7001 : 0 : dcs = pool->min_dcs;
7002 : : } else {
7003 : : offset = 0;
7004 : 0 : dcs = cnt_free->dcs_when_free;
7005 : : }
7006 : 0 : ret = mlx5_flow_os_create_flow_action_count(dcs->obj, offset,
7007 : : &cnt_free->action);
7008 : : if (ret) {
7009 : 0 : rte_errno = errno;
7010 : 0 : goto err;
7011 : : }
7012 : : }
7013 [ # # ]: 0 : cnt_idx = MLX5_MAKE_CNT_IDX(pool->index,
7014 : : MLX5_CNT_ARRAY_IDX(pool, cnt_free));
7015 : : /* Update the counter reset values. */
7016 [ # # ]: 0 : if (_flow_dv_query_count(dev, cnt_idx, &cnt_free->hits,
7017 : : &cnt_free->bytes))
7018 : 0 : goto err;
7019 [ # # # # ]: 0 : if (!fallback && !priv->sh->sws_cmng.query_thread_on)
7020 : : /* Start the asynchronous batch query by the host thread. */
7021 : 0 : mlx5_set_query_alarm(priv->sh);
7022 : : /*
7023 : : * When the count action isn't shared (by ID), shared_info field is
7024 : : * used for indirect action API's refcnt.
7025 : : * When the counter action is not shared neither by ID nor by indirect
7026 : : * action API, shared info must be 1.
7027 : : */
7028 : 0 : cnt_free->shared_info.refcnt = 1;
7029 : 0 : return cnt_idx;
7030 : 0 : err:
7031 [ # # ]: 0 : if (cnt_free) {
7032 : 0 : cnt_free->pool = pool;
7033 [ # # ]: 0 : if (fallback)
7034 : 0 : cnt_free->dcs_when_free = cnt_free->dcs_when_active;
7035 : : rte_spinlock_lock(&cmng->csl[cnt_type]);
7036 : 0 : TAILQ_INSERT_TAIL(&cmng->counters[cnt_type], cnt_free, next);
7037 : : rte_spinlock_unlock(&cmng->csl[cnt_type]);
7038 : : }
7039 : : return 0;
7040 : : }
7041 : :
7042 : : /**
7043 : : * Get age param from counter index.
7044 : : *
7045 : : * @param[in] dev
7046 : : * Pointer to the Ethernet device structure.
7047 : : * @param[in] counter
7048 : : * Index to the counter handler.
7049 : : *
7050 : : * @return
7051 : : * The aging parameter specified for the counter index.
7052 : : */
7053 : : static struct mlx5_age_param*
7054 : : flow_dv_counter_idx_get_age(struct rte_eth_dev *dev,
7055 : : uint32_t counter)
7056 : : {
7057 : : struct mlx5_flow_counter *cnt;
7058 : : struct mlx5_flow_counter_pool *pool = NULL;
7059 : :
7060 : : flow_dv_counter_get_by_idx(dev, counter, &pool);
7061 : : counter = (counter - 1) % MLX5_COUNTERS_PER_POOL;
7062 : : cnt = MLX5_POOL_GET_CNT(pool, counter);
7063 : 0 : return MLX5_CNT_TO_AGE(cnt);
7064 : : }
7065 : :
7066 : : /**
7067 : : * Remove a flow counter from aged counter list.
7068 : : *
7069 : : * @param[in] dev
7070 : : * Pointer to the Ethernet device structure.
7071 : : * @param[in] counter
7072 : : * Index to the counter handler.
7073 : : * @param[in] cnt
7074 : : * Pointer to the counter handler.
7075 : : */
7076 : : static void
7077 : 0 : flow_dv_counter_remove_from_age(struct rte_eth_dev *dev,
7078 : : uint32_t counter, struct mlx5_flow_counter *cnt)
7079 : : {
7080 : : struct mlx5_age_info *age_info;
7081 : : struct mlx5_age_param *age_param;
7082 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7083 : : uint16_t expected = AGE_CANDIDATE;
7084 : :
7085 [ # # ]: 0 : age_info = GET_PORT_AGE_INFO(priv);
7086 : : age_param = flow_dv_counter_idx_get_age(dev, counter);
7087 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(&age_param->state, &expected,
7088 : : AGE_FREE, rte_memory_order_relaxed,
7089 : : rte_memory_order_relaxed)) {
7090 : : /**
7091 : : * We need the lock even it is age timeout,
7092 : : * since counter may still in process.
7093 : : */
7094 : 0 : rte_spinlock_lock(&age_info->aged_sl);
7095 [ # # ]: 0 : TAILQ_REMOVE(&age_info->aged_counters, cnt, next);
7096 : : rte_spinlock_unlock(&age_info->aged_sl);
7097 : 0 : rte_atomic_store_explicit(&age_param->state, AGE_FREE, rte_memory_order_relaxed);
7098 : : }
7099 : 0 : }
7100 : :
7101 : : /**
7102 : : * Release a flow counter.
7103 : : *
7104 : : * @param[in] dev
7105 : : * Pointer to the Ethernet device structure.
7106 : : * @param[in] counter
7107 : : * Index to the counter handler.
7108 : : */
7109 : : static void
7110 : 0 : flow_dv_counter_free(struct rte_eth_dev *dev, uint32_t counter)
7111 : : {
7112 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7113 : : struct mlx5_flow_counter_pool *pool = NULL;
7114 : : struct mlx5_flow_counter *cnt;
7115 : : enum mlx5_counter_type cnt_type;
7116 : :
7117 [ # # ]: 0 : if (!counter)
7118 : : return;
7119 : : cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
7120 : : MLX5_ASSERT(pool);
7121 [ # # ]: 0 : if (pool->is_aged) {
7122 : 0 : flow_dv_counter_remove_from_age(dev, counter, cnt);
7123 : : } else {
7124 : : /*
7125 : : * If the counter action is shared by indirect action API,
7126 : : * the atomic function reduces its references counter.
7127 : : * If after the reduction the action is still referenced, the
7128 : : * function returns here and does not release it.
7129 : : * When the counter action is not shared by
7130 : : * indirect action API, shared info is 1 before the reduction,
7131 : : * so this condition is failed and function doesn't return here.
7132 : : */
7133 [ # # ]: 0 : if (rte_atomic_fetch_sub_explicit(&cnt->shared_info.refcnt, 1,
7134 : : rte_memory_order_relaxed) - 1)
7135 : : return;
7136 : : }
7137 : 0 : cnt->pool = pool;
7138 : : /*
7139 : : * Put the counter back to list to be updated in none fallback mode.
7140 : : * Currently, we are using two list alternately, while one is in query,
7141 : : * add the freed counter to the other list based on the pool query_gen
7142 : : * value. After query finishes, add counter the list to the global
7143 : : * container counter list. The list changes while query starts. In
7144 : : * this case, lock will not be needed as query callback and release
7145 : : * function both operate with the different list.
7146 : : */
7147 [ # # ]: 0 : if (!priv->sh->sws_cmng.counter_fallback) {
7148 : 0 : rte_spinlock_lock(&pool->csl);
7149 : 0 : TAILQ_INSERT_TAIL(&pool->counters[pool->query_gen], cnt, next);
7150 : : rte_spinlock_unlock(&pool->csl);
7151 : : } else {
7152 : 0 : cnt->dcs_when_free = cnt->dcs_when_active;
7153 : 0 : cnt_type = pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
7154 : : MLX5_COUNTER_TYPE_ORIGIN;
7155 : 0 : rte_spinlock_lock(&priv->sh->sws_cmng.csl[cnt_type]);
7156 : 0 : TAILQ_INSERT_TAIL(&priv->sh->sws_cmng.counters[cnt_type],
7157 : : cnt, next);
7158 : 0 : rte_spinlock_unlock(&priv->sh->sws_cmng.csl[cnt_type]);
7159 : : }
7160 : : }
7161 : :
7162 : : /**
7163 : : * Resize a meter id container.
7164 : : *
7165 : : * @param[in] dev
7166 : : * Pointer to the Ethernet device structure.
7167 : : *
7168 : : * @return
7169 : : * 0 on success, otherwise negative errno value and rte_errno is set.
7170 : : */
7171 : : static int
7172 : 0 : flow_dv_mtr_container_resize(struct rte_eth_dev *dev)
7173 : : {
7174 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7175 : : struct mlx5_aso_mtr_pools_mng *pools_mng =
7176 : 0 : &priv->sh->mtrmng->pools_mng;
7177 : 0 : void *old_pools = pools_mng->pools;
7178 : 0 : uint32_t resize = pools_mng->n + MLX5_MTRS_CONTAINER_RESIZE;
7179 : 0 : uint32_t mem_size = sizeof(struct mlx5_aso_mtr_pool *) * resize;
7180 : 0 : void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
7181 : :
7182 [ # # ]: 0 : if (!pools) {
7183 : 0 : rte_errno = ENOMEM;
7184 : 0 : return -ENOMEM;
7185 : : }
7186 [ # # ]: 0 : if (!pools_mng->n)
7187 [ # # ]: 0 : if (mlx5_aso_queue_init(priv->sh, ASO_OPC_MOD_POLICER, 1)) {
7188 : 0 : mlx5_free(pools);
7189 : 0 : return -ENOMEM;
7190 : : }
7191 [ # # ]: 0 : if (old_pools)
7192 : 0 : memcpy(pools, old_pools, pools_mng->n *
7193 : : sizeof(struct mlx5_aso_mtr_pool *));
7194 : 0 : pools_mng->n = resize;
7195 : 0 : pools_mng->pools = pools;
7196 [ # # ]: 0 : if (old_pools)
7197 : 0 : mlx5_free(old_pools);
7198 : : return 0;
7199 : : }
7200 : :
7201 : : /**
7202 : : * Prepare a new meter and/or a new meter pool.
7203 : : *
7204 : : * @param[in] dev
7205 : : * Pointer to the Ethernet device structure.
7206 : : * @param[out] mtr_free
7207 : : * Where to put the pointer of a new meter.g.
7208 : : *
7209 : : * @return
7210 : : * The meter pool pointer and @mtr_free is set on success,
7211 : : * NULL otherwise and rte_errno is set.
7212 : : */
7213 : : static struct mlx5_aso_mtr_pool *
7214 : 0 : flow_dv_mtr_pool_create(struct rte_eth_dev *dev, struct mlx5_aso_mtr **mtr_free)
7215 : : {
7216 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7217 : 0 : struct mlx5_aso_mtr_pools_mng *pools_mng = &priv->sh->mtrmng->pools_mng;
7218 : : struct mlx5_aso_mtr_pool *pool = NULL;
7219 : : struct mlx5_devx_obj *dcs = NULL;
7220 : : uint32_t i;
7221 : : uint32_t log_obj_size;
7222 : :
7223 : : log_obj_size = rte_log2_u32(MLX5_ASO_MTRS_PER_POOL >> 1);
7224 : 0 : dcs = mlx5_devx_cmd_create_flow_meter_aso_obj(priv->sh->cdev->ctx,
7225 : 0 : priv->sh->cdev->pdn,
7226 : : log_obj_size);
7227 [ # # ]: 0 : if (!dcs) {
7228 : 0 : rte_errno = ENODATA;
7229 : 0 : return NULL;
7230 : : }
7231 : 0 : pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
7232 [ # # ]: 0 : if (!pool) {
7233 : 0 : rte_errno = ENOMEM;
7234 : 0 : claim_zero(mlx5_devx_cmd_destroy(dcs));
7235 : 0 : return NULL;
7236 : : }
7237 : 0 : pool->devx_obj = dcs;
7238 : 0 : rte_rwlock_write_lock(&pools_mng->resize_mtrwl);
7239 : 0 : pool->index = pools_mng->n_valid;
7240 [ # # # # ]: 0 : if (pool->index == pools_mng->n && flow_dv_mtr_container_resize(dev)) {
7241 : 0 : mlx5_free(pool);
7242 : 0 : claim_zero(mlx5_devx_cmd_destroy(dcs));
7243 : : rte_rwlock_write_unlock(&pools_mng->resize_mtrwl);
7244 : 0 : return NULL;
7245 : : }
7246 : 0 : pools_mng->pools[pool->index] = pool;
7247 : 0 : pools_mng->n_valid++;
7248 : : rte_rwlock_write_unlock(&pools_mng->resize_mtrwl);
7249 [ # # ]: 0 : for (i = 1; i < MLX5_ASO_MTRS_PER_POOL; ++i) {
7250 : 0 : pool->mtrs[i].offset = i;
7251 [ # # ]: 0 : LIST_INSERT_HEAD(&pools_mng->meters, &pool->mtrs[i], next);
7252 : : }
7253 : 0 : pool->mtrs[0].offset = 0;
7254 : 0 : *mtr_free = &pool->mtrs[0];
7255 : 0 : return pool;
7256 : : }
7257 : :
7258 : : /**
7259 : : * Release a flow meter into pool.
7260 : : *
7261 : : * @param[in] dev
7262 : : * Pointer to the Ethernet device structure.
7263 : : * @param[in] mtr_idx
7264 : : * Index to aso flow meter.
7265 : : */
7266 : : static void
7267 : 0 : flow_dv_aso_mtr_release_to_pool(struct rte_eth_dev *dev, uint32_t mtr_idx)
7268 : : {
7269 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7270 : : struct mlx5_aso_mtr_pools_mng *pools_mng =
7271 : 0 : &priv->sh->mtrmng->pools_mng;
7272 : 0 : struct mlx5_aso_mtr *aso_mtr = mlx5_aso_meter_by_idx(priv, mtr_idx);
7273 : :
7274 : : MLX5_ASSERT(aso_mtr);
7275 : 0 : rte_spinlock_lock(&pools_mng->mtrsl);
7276 [ # # ]: 0 : memset(&aso_mtr->fm, 0, sizeof(struct mlx5_flow_meter_info));
7277 : 0 : aso_mtr->state = ASO_METER_FREE;
7278 [ # # ]: 0 : LIST_INSERT_HEAD(&pools_mng->meters, aso_mtr, next);
7279 : : rte_spinlock_unlock(&pools_mng->mtrsl);
7280 : 0 : }
7281 : :
7282 : : /**
7283 : : * Allocate a aso flow meter.
7284 : : *
7285 : : * @param[in] dev
7286 : : * Pointer to the Ethernet device structure.
7287 : : *
7288 : : * @return
7289 : : * Index to aso flow meter on success, 0 otherwise and rte_errno is set.
7290 : : */
7291 : : static uint32_t
7292 : 0 : flow_dv_mtr_alloc(struct rte_eth_dev *dev)
7293 : : {
7294 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7295 : 0 : struct mlx5_aso_mtr *mtr_free = NULL;
7296 : : struct mlx5_aso_mtr_pools_mng *pools_mng =
7297 : 0 : &priv->sh->mtrmng->pools_mng;
7298 : : struct mlx5_aso_mtr_pool *pool;
7299 : : uint32_t mtr_idx = 0;
7300 : :
7301 [ # # ]: 0 : if (!priv->sh->cdev->config.devx) {
7302 : 0 : rte_errno = ENOTSUP;
7303 : 0 : return 0;
7304 : : }
7305 : : /* Allocate the flow meter memory. */
7306 : : /* Get free meters from management. */
7307 : 0 : rte_spinlock_lock(&pools_mng->mtrsl);
7308 : 0 : mtr_free = LIST_FIRST(&pools_mng->meters);
7309 [ # # ]: 0 : if (mtr_free)
7310 [ # # ]: 0 : LIST_REMOVE(mtr_free, next);
7311 [ # # # # ]: 0 : if (!mtr_free && !flow_dv_mtr_pool_create(dev, &mtr_free)) {
7312 : : rte_spinlock_unlock(&pools_mng->mtrsl);
7313 : 0 : return 0;
7314 : : }
7315 : 0 : mtr_free->state = ASO_METER_WAIT;
7316 : : rte_spinlock_unlock(&pools_mng->mtrsl);
7317 : 0 : pool = container_of(mtr_free,
7318 : : struct mlx5_aso_mtr_pool,
7319 : : mtrs[mtr_free->offset]);
7320 : 0 : mtr_idx = MLX5_MAKE_MTR_IDX(pool->index, mtr_free->offset);
7321 [ # # ]: 0 : if (!mtr_free->fm.meter_action_g) {
7322 : : #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
7323 : : struct rte_flow_error error;
7324 : : uint8_t reg_id;
7325 : :
7326 : 0 : reg_id = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &error);
7327 : 0 : mtr_free->fm.meter_action_g =
7328 : 0 : mlx5_glue->dv_create_flow_action_aso
7329 : 0 : (priv->sh->rx_domain,
7330 : 0 : pool->devx_obj->obj,
7331 : : mtr_free->offset,
7332 : : (1 << MLX5_FLOW_COLOR_GREEN),
7333 : 0 : reg_id - REG_C_0);
7334 : : #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
7335 [ # # ]: 0 : if (!mtr_free->fm.meter_action_g) {
7336 : 0 : flow_dv_aso_mtr_release_to_pool(dev, mtr_idx);
7337 : 0 : return 0;
7338 : : }
7339 : : }
7340 : : return mtr_idx;
7341 : : }
7342 : :
7343 : : /**
7344 : : * Verify the @p attributes will be correctly understood by the NIC and store
7345 : : * them in the @p flow if everything is correct.
7346 : : *
7347 : : * @param[in] dev
7348 : : * Pointer to dev struct.
7349 : : * @param[in] attributes
7350 : : * Pointer to flow attributes
7351 : : * @param[in] external
7352 : : * This flow rule is created by request external to PMD.
7353 : : * @param[out] error
7354 : : * Pointer to error structure.
7355 : : *
7356 : : * @return
7357 : : * - 0 on success and non root table.
7358 : : * - 1 on success and root table.
7359 : : * - a negative errno value otherwise and rte_errno is set.
7360 : : */
7361 : : static int
7362 : 0 : flow_dv_validate_attributes(struct rte_eth_dev *dev,
7363 : : const struct mlx5_flow_tunnel *tunnel,
7364 : : const struct rte_flow_attr *attributes,
7365 : : const struct flow_grp_info *grp_info,
7366 : : struct rte_flow_error *error)
7367 : : {
7368 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7369 : 0 : uint32_t lowest_priority = mlx5_get_lowest_priority(dev, attributes);
7370 : : int ret = 0;
7371 : :
7372 : : #ifndef HAVE_MLX5DV_DR
7373 : : RTE_SET_USED(tunnel);
7374 : : RTE_SET_USED(grp_info);
7375 : : if (attributes->group)
7376 : : return rte_flow_error_set(error, ENOTSUP,
7377 : : RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
7378 : : NULL,
7379 : : "groups are not supported");
7380 : : #else
7381 : 0 : uint32_t table = 0;
7382 : :
7383 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel, attributes->group, &table,
7384 : : grp_info, error);
7385 [ # # ]: 0 : if (ret)
7386 : : return ret;
7387 [ # # ]: 0 : if (!table)
7388 : : ret = MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL;
7389 : : #endif
7390 [ # # # # ]: 0 : if (attributes->priority != MLX5_FLOW_LOWEST_PRIO_INDICATOR &&
7391 : : attributes->priority > lowest_priority)
7392 : 0 : return rte_flow_error_set(error, ENOTSUP,
7393 : : RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
7394 : : NULL,
7395 : : "priority out of range");
7396 [ # # # # ]: 0 : if (attributes->transfer && !priv->sh->config.dv_esw_en)
7397 : 0 : return rte_flow_error_set(error, ENOTSUP,
7398 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7399 : : "E-Switch dr is not supported");
7400 [ # # ]: 0 : if (attributes->ingress + attributes->egress + attributes->transfer != 1) {
7401 : 0 : return rte_flow_error_set(error, EINVAL,
7402 : : RTE_FLOW_ERROR_TYPE_ATTR, NULL,
7403 : : "must specify exactly one of "
7404 : : "ingress, egress or transfer");
7405 : : }
7406 : : return ret;
7407 : : }
7408 : :
7409 : : static int
7410 : 0 : validate_integrity_bits(const void *arg,
7411 : : int64_t pattern_flags, uint64_t l3_flags,
7412 : : uint64_t l4_flags, uint64_t ip4_flag,
7413 : : struct rte_flow_error *error)
7414 : : {
7415 : : const struct rte_flow_item_integrity *mask = arg;
7416 : :
7417 [ # # # # ]: 0 : if (mask->l3_ok && !(pattern_flags & l3_flags))
7418 : 0 : return rte_flow_error_set(error, EINVAL,
7419 : : RTE_FLOW_ERROR_TYPE_ITEM,
7420 : : NULL, "missing L3 protocol");
7421 : :
7422 [ # # # # ]: 0 : if (mask->ipv4_csum_ok && !(pattern_flags & ip4_flag))
7423 : 0 : return rte_flow_error_set(error, EINVAL,
7424 : : RTE_FLOW_ERROR_TYPE_ITEM,
7425 : : NULL, "missing IPv4 protocol");
7426 : :
7427 [ # # # # ]: 0 : if ((mask->l4_ok || mask->l4_csum_ok) && !(pattern_flags & l4_flags))
7428 : 0 : return rte_flow_error_set(error, EINVAL,
7429 : : RTE_FLOW_ERROR_TYPE_ITEM,
7430 : : NULL, "missing L4 protocol");
7431 : :
7432 : : return 0;
7433 : : }
7434 : :
7435 : : static int
7436 : 0 : flow_dv_validate_item_integrity_post(const struct
7437 : : rte_flow_item *integrity_items[2],
7438 : : int64_t pattern_flags,
7439 : : struct rte_flow_error *error)
7440 : : {
7441 : : const struct rte_flow_item_integrity *mask;
7442 : : int ret;
7443 : :
7444 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_OUTER_INTEGRITY) {
7445 : 0 : mask = (typeof(mask))integrity_items[0]->mask;
7446 : 0 : ret = validate_integrity_bits(mask, pattern_flags,
7447 : : MLX5_FLOW_LAYER_OUTER_L3,
7448 : : MLX5_FLOW_LAYER_OUTER_L4,
7449 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4,
7450 : : error);
7451 [ # # ]: 0 : if (ret)
7452 : : return ret;
7453 : : }
7454 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_INNER_INTEGRITY) {
7455 : 0 : mask = (typeof(mask))integrity_items[1]->mask;
7456 : 0 : ret = validate_integrity_bits(mask, pattern_flags,
7457 : : MLX5_FLOW_LAYER_INNER_L3,
7458 : : MLX5_FLOW_LAYER_INNER_L4,
7459 : : MLX5_FLOW_LAYER_INNER_L3_IPV4,
7460 : : error);
7461 [ # # ]: 0 : if (ret)
7462 : 0 : return ret;
7463 : : }
7464 : : return 0;
7465 : : }
7466 : :
7467 : : static int
7468 : 0 : flow_dv_validate_item_integrity(struct rte_eth_dev *dev,
7469 : : const struct rte_flow_item *integrity_item,
7470 : : uint64_t pattern_flags, uint64_t *last_item,
7471 : : const struct rte_flow_item *integrity_items[2],
7472 : : struct rte_flow_error *error)
7473 : : {
7474 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7475 : 0 : const struct rte_flow_item_integrity *mask = (typeof(mask))
7476 : : integrity_item->mask;
7477 : 0 : const struct rte_flow_item_integrity *spec = (typeof(spec))
7478 : : integrity_item->spec;
7479 : :
7480 [ # # ]: 0 : if (!priv->sh->cdev->config.hca_attr.pkt_integrity_match)
7481 : 0 : return rte_flow_error_set(error, ENOTSUP,
7482 : : RTE_FLOW_ERROR_TYPE_ITEM,
7483 : : integrity_item,
7484 : : "packet integrity integrity_item not supported");
7485 [ # # ]: 0 : if (!spec)
7486 : 0 : return rte_flow_error_set(error, ENOTSUP,
7487 : : RTE_FLOW_ERROR_TYPE_ITEM,
7488 : : integrity_item,
7489 : : "no spec for integrity item");
7490 [ # # ]: 0 : if (!mask)
7491 : : mask = &rte_flow_item_integrity_mask;
7492 [ # # ]: 0 : if (!mlx5_validate_integrity_item(mask))
7493 : 0 : return rte_flow_error_set(error, ENOTSUP,
7494 : : RTE_FLOW_ERROR_TYPE_ITEM,
7495 : : integrity_item,
7496 : : "unsupported integrity filter");
7497 [ # # # # ]: 0 : if ((mask->l3_ok & !spec->l3_ok) || (mask->l4_ok & !spec->l4_ok) ||
7498 [ # # ]: 0 : (mask->ipv4_csum_ok & !spec->ipv4_csum_ok) ||
7499 [ # # ]: 0 : (mask->l4_csum_ok & !spec->l4_csum_ok))
7500 : 0 : return rte_flow_error_set(error, EINVAL,
7501 : : RTE_FLOW_ERROR_TYPE_ITEM,
7502 : : NULL, "negative integrity flow is not supported");
7503 [ # # ]: 0 : if (spec->level > 1) {
7504 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_INNER_INTEGRITY)
7505 : 0 : return rte_flow_error_set
7506 : : (error, ENOTSUP,
7507 : : RTE_FLOW_ERROR_TYPE_ITEM,
7508 : : NULL, "multiple inner integrity items not supported");
7509 : 0 : integrity_items[1] = integrity_item;
7510 : 0 : *last_item |= MLX5_FLOW_ITEM_INNER_INTEGRITY;
7511 : : } else {
7512 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_OUTER_INTEGRITY)
7513 : 0 : return rte_flow_error_set
7514 : : (error, ENOTSUP,
7515 : : RTE_FLOW_ERROR_TYPE_ITEM,
7516 : : NULL, "multiple outer integrity items not supported");
7517 : 0 : integrity_items[0] = integrity_item;
7518 : 0 : *last_item |= MLX5_FLOW_ITEM_OUTER_INTEGRITY;
7519 : : }
7520 : : return 0;
7521 : : }
7522 : :
7523 : : static int
7524 : 0 : flow_dv_validate_item_flex(struct rte_eth_dev *dev,
7525 : : const struct rte_flow_item *item,
7526 : : uint64_t item_flags,
7527 : : uint64_t *last_item,
7528 : : bool is_inner,
7529 : : struct rte_flow_error *error)
7530 : : {
7531 : 0 : const struct rte_flow_item_flex *flow_spec = item->spec;
7532 : 0 : const struct rte_flow_item_flex *flow_mask = item->mask;
7533 : : struct mlx5_flex_item *flex;
7534 : :
7535 [ # # ]: 0 : if (!flow_spec)
7536 : 0 : return rte_flow_error_set(error, EINVAL,
7537 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
7538 : : "flex flow item spec cannot be NULL");
7539 [ # # ]: 0 : if (!flow_mask)
7540 : 0 : return rte_flow_error_set(error, EINVAL,
7541 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
7542 : : "flex flow item mask cannot be NULL");
7543 [ # # ]: 0 : if (item->last)
7544 : 0 : return rte_flow_error_set(error, ENOTSUP,
7545 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
7546 : : "flex flow item last not supported");
7547 [ # # ]: 0 : if (mlx5_flex_acquire_index(dev, flow_spec->handle, false) < 0)
7548 : 0 : return rte_flow_error_set(error, EINVAL,
7549 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
7550 : : "invalid flex flow item handle");
7551 : 0 : flex = (struct mlx5_flex_item *)flow_spec->handle;
7552 [ # # # # : 0 : switch (flex->tunnel_mode) {
# # ]
7553 : 0 : case FLEX_TUNNEL_MODE_SINGLE:
7554 [ # # ]: 0 : if (item_flags &
7555 : : (MLX5_FLOW_ITEM_OUTER_FLEX | MLX5_FLOW_ITEM_INNER_FLEX))
7556 : 0 : rte_flow_error_set(error, EINVAL,
7557 : : RTE_FLOW_ERROR_TYPE_ITEM,
7558 : : NULL, "multiple flex items not supported");
7559 : : break;
7560 : 0 : case FLEX_TUNNEL_MODE_OUTER:
7561 [ # # ]: 0 : if (is_inner)
7562 : 0 : rte_flow_error_set(error, EINVAL,
7563 : : RTE_FLOW_ERROR_TYPE_ITEM,
7564 : : NULL, "inner flex item was not configured");
7565 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_OUTER_FLEX)
7566 : 0 : rte_flow_error_set(error, ENOTSUP,
7567 : : RTE_FLOW_ERROR_TYPE_ITEM,
7568 : : NULL, "multiple flex items not supported");
7569 : : break;
7570 : 0 : case FLEX_TUNNEL_MODE_INNER:
7571 [ # # ]: 0 : if (!is_inner)
7572 : 0 : rte_flow_error_set(error, EINVAL,
7573 : : RTE_FLOW_ERROR_TYPE_ITEM,
7574 : : NULL, "outer flex item was not configured");
7575 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_INNER_FLEX)
7576 : 0 : rte_flow_error_set(error, EINVAL,
7577 : : RTE_FLOW_ERROR_TYPE_ITEM,
7578 : : NULL, "multiple flex items not supported");
7579 : : break;
7580 : 0 : case FLEX_TUNNEL_MODE_MULTI:
7581 [ # # # # : 0 : if ((is_inner && (item_flags & MLX5_FLOW_ITEM_INNER_FLEX)) ||
# # ]
7582 [ # # ]: 0 : (!is_inner && (item_flags & MLX5_FLOW_ITEM_OUTER_FLEX))) {
7583 : 0 : rte_flow_error_set(error, EINVAL,
7584 : : RTE_FLOW_ERROR_TYPE_ITEM,
7585 : : NULL, "multiple flex items not supported");
7586 : : }
7587 : : break;
7588 : 0 : case FLEX_TUNNEL_MODE_TUNNEL:
7589 [ # # # # ]: 0 : if (is_inner || (item_flags & MLX5_FLOW_ITEM_FLEX_TUNNEL))
7590 : 0 : rte_flow_error_set(error, EINVAL,
7591 : : RTE_FLOW_ERROR_TYPE_ITEM,
7592 : : NULL, "multiple flex tunnel items not supported");
7593 : : break;
7594 : 0 : default:
7595 : 0 : rte_flow_error_set(error, EINVAL,
7596 : : RTE_FLOW_ERROR_TYPE_ITEM,
7597 : : NULL, "invalid flex item configuration");
7598 : : }
7599 : 0 : *last_item = flex->tunnel_mode == FLEX_TUNNEL_MODE_TUNNEL ?
7600 [ # # ]: 0 : MLX5_FLOW_ITEM_FLEX_TUNNEL : is_inner ?
7601 [ # # ]: 0 : MLX5_FLOW_ITEM_INNER_FLEX : MLX5_FLOW_ITEM_OUTER_FLEX;
7602 : 0 : return 0;
7603 : : }
7604 : :
7605 : : static __rte_always_inline uint8_t
7606 : : mlx5_flow_l3_next_protocol(const struct rte_flow_item *l3_item,
7607 : : enum MLX5_SET_MATCHER key_type)
7608 : : {
7609 : : #define MLX5_L3_NEXT_PROTOCOL(i, ms) \
7610 : : ((i)->type == RTE_FLOW_ITEM_TYPE_IPV4 ? \
7611 : : ((const struct rte_flow_item_ipv4 *)(i)->ms)->hdr.next_proto_id : \
7612 : : (i)->type == RTE_FLOW_ITEM_TYPE_IPV6 ? \
7613 : : ((const struct rte_flow_item_ipv6 *)(i)->ms)->hdr.proto : \
7614 : : (i)->type == RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT ? \
7615 : : ((const struct rte_flow_item_ipv6_frag_ext *)(i)->ms)->hdr.next_header :\
7616 : : 0xff)
7617 : :
7618 : : uint8_t next_protocol;
7619 : :
7620 [ # # # # : 0 : if (l3_item->mask != NULL && l3_item->spec != NULL) {
# # # # #
# # # # #
# # # # #
# # # ]
7621 [ # # # # : 0 : next_protocol = MLX5_L3_NEXT_PROTOCOL(l3_item, mask);
# # # # #
# # # ]
7622 [ # # # # : 0 : if (next_protocol)
# # # # #
# # # ]
7623 [ # # # # : 0 : next_protocol &= MLX5_L3_NEXT_PROTOCOL(l3_item, spec);
# # # # #
# # # ]
7624 : : else
7625 : : next_protocol = 0xff;
7626 [ # # # # : 0 : } else if (key_type == MLX5_SET_MATCHER_HS_M && l3_item->mask != NULL) {
# # # # #
# # # ]
7627 [ # # # # : 0 : next_protocol = MLX5_L3_NEXT_PROTOCOL(l3_item, mask);
# # ]
7628 [ # # # # : 0 : } else if (key_type == MLX5_SET_MATCHER_HS_V && l3_item->spec != NULL) {
# # # # #
# # # ]
7629 [ # # # # : 0 : next_protocol = MLX5_L3_NEXT_PROTOCOL(l3_item, spec);
# # ]
7630 : : } else {
7631 : : /* Reset for inner layer. */
7632 : : next_protocol = 0xff;
7633 : : }
7634 : : return next_protocol;
7635 : :
7636 : : #undef MLX5_L3_NEXT_PROTOCOL
7637 : : }
7638 : :
7639 : : /**
7640 : : * Validate IB BTH item.
7641 : : *
7642 : : * @param[in] dev
7643 : : * Pointer to the rte_eth_dev structure.
7644 : : * @param[in] udp_dport
7645 : : * UDP destination port
7646 : : * @param[in] item
7647 : : * Item specification.
7648 : : * @param root
7649 : : * Whether action is on root table.
7650 : : * @param[out] error
7651 : : * Pointer to the error structure.
7652 : : *
7653 : : * @return
7654 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
7655 : : */
7656 : : static int
7657 : 0 : mlx5_flow_validate_item_ib_bth(struct rte_eth_dev *dev,
7658 : : uint16_t udp_dport,
7659 : : const struct rte_flow_item *item,
7660 : : bool root,
7661 : : struct rte_flow_error *error)
7662 : : {
7663 : 0 : const struct rte_flow_item_ib_bth *mask = item->mask;
7664 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7665 : : const struct rte_flow_item_ib_bth *valid_mask;
7666 : : int ret;
7667 : :
7668 : : valid_mask = &rte_flow_item_ib_bth_mask;
7669 [ # # ]: 0 : if (udp_dport && udp_dport != MLX5_UDP_PORT_ROCEv2)
7670 : 0 : return rte_flow_error_set(error, EINVAL,
7671 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
7672 : : "protocol filtering not compatible"
7673 : : " with UDP layer");
7674 [ # # # # ]: 0 : if (mask && (mask->hdr.se || mask->hdr.m || mask->hdr.padcnt ||
7675 [ # # # # ]: 0 : mask->hdr.tver || mask->hdr.pkey || mask->hdr.f || mask->hdr.b ||
7676 [ # # ]: 0 : mask->hdr.rsvd0 || mask->hdr.a || mask->hdr.rsvd1 ||
7677 [ # # # # : 0 : mask->hdr.psn[0] || mask->hdr.psn[1] || mask->hdr.psn[2]))
# # ]
7678 : 0 : return rte_flow_error_set(error, EINVAL,
7679 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
7680 : : "only opcode and dst_qp are supported");
7681 [ # # # # ]: 0 : if (root || priv->sh->steering_format_version ==
7682 : : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5)
7683 : 0 : return rte_flow_error_set(error, EINVAL,
7684 : : RTE_FLOW_ERROR_TYPE_ITEM,
7685 : : item,
7686 : : "IB BTH item is not supported");
7687 [ # # ]: 0 : if (!mask)
7688 : : mask = &rte_flow_item_ib_bth_mask;
7689 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
7690 : : (const uint8_t *)valid_mask,
7691 : : sizeof(struct rte_flow_item_ib_bth),
7692 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
7693 : : if (ret < 0)
7694 : : return ret;
7695 : : return 0;
7696 : : }
7697 : :
7698 : : const struct rte_flow_item_ipv4 nic_ipv4_mask = {
7699 : : .hdr = {
7700 : : .src_addr = RTE_BE32(0xffffffff),
7701 : : .dst_addr = RTE_BE32(0xffffffff),
7702 : : .type_of_service = 0xff,
7703 : : .fragment_offset = RTE_BE16(0xffff),
7704 : : .next_proto_id = 0xff,
7705 : : .time_to_live = 0xff,
7706 : : },
7707 : : };
7708 : :
7709 : : const struct rte_flow_item_ipv6 nic_ipv6_mask = {
7710 : : .hdr = {
7711 : : .src_addr = RTE_IPV6_MASK_FULL,
7712 : : .dst_addr = RTE_IPV6_MASK_FULL,
7713 : : .vtc_flow = RTE_BE32(0xffffffff),
7714 : : .proto = 0xff,
7715 : : .hop_limits = 0xff,
7716 : : },
7717 : : .has_frag_ext = 1,
7718 : : };
7719 : :
7720 : : const struct rte_flow_item_tcp nic_tcp_mask = {
7721 : : .hdr = {
7722 : : .tcp_flags = 0xFF,
7723 : : .src_port = RTE_BE16(UINT16_MAX),
7724 : : .dst_port = RTE_BE16(UINT16_MAX),
7725 : : }
7726 : : };
7727 : :
7728 : : /**
7729 : : * Internal validation function. For validating both actions and items.
7730 : : *
7731 : : * @param[in] dev
7732 : : * Pointer to the rte_eth_dev structure.
7733 : : * @param[in] attr
7734 : : * Pointer to the flow attributes.
7735 : : * @param[in] items
7736 : : * Pointer to the list of items.
7737 : : * @param[in] actions
7738 : : * Pointer to the list of actions.
7739 : : * @param[in] external
7740 : : * This flow rule is created by request external to PMD.
7741 : : * @param[in] hairpin
7742 : : * Number of hairpin TX actions, 0 means classic flow.
7743 : : * @param[out] error
7744 : : * Pointer to the error structure.
7745 : : *
7746 : : * @return
7747 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
7748 : : */
7749 : : int
7750 : 0 : flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
7751 : : const struct rte_flow_item items[],
7752 : : const struct rte_flow_action actions[],
7753 : : bool external, int hairpin, struct rte_flow_error *error)
7754 : : {
7755 : : int ret;
7756 : 0 : uint64_t aso_mask, action_flags = 0;
7757 : 0 : uint64_t item_flags = 0;
7758 : 0 : uint64_t last_item = 0;
7759 : : uint8_t next_protocol = 0xff;
7760 : : uint16_t ether_type = 0;
7761 : 0 : int actions_n = 0;
7762 : : uint8_t item_ipv6_proto = 0;
7763 : 0 : int fdb_mirror = 0;
7764 : : int modify_after_mirror = 0;
7765 : : const struct rte_flow_item *geneve_item = NULL;
7766 : : const struct rte_flow_item *gre_item = NULL;
7767 : : const struct rte_flow_item *gtp_item = NULL;
7768 : : const struct rte_flow_action_raw_decap *decap;
7769 : : const struct rte_flow_action_raw_encap *encap;
7770 : : const struct rte_flow_action_rss *rss = NULL;
7771 : 0 : const struct rte_flow_action_rss *sample_rss = NULL;
7772 : 0 : const struct rte_flow_action_count *sample_count = NULL;
7773 : 0 : const struct rte_flow_item_ecpri nic_ecpri_mask = {
7774 : : .hdr = {
7775 : : .common = {
7776 : : .u32 =
7777 : : RTE_BE32(((const struct rte_ecpri_common_hdr) {
7778 : : .type = 0xFF,
7779 : : }).u32),
7780 : : },
7781 : : .dummy[0] = 0xffffffff,
7782 : : },
7783 : : };
7784 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7785 : 0 : struct mlx5_sh_config *dev_conf = &priv->sh->config;
7786 : : uint16_t queue_index = 0xFFFF;
7787 : : const struct rte_flow_item_vlan *vlan_m = NULL;
7788 : : uint32_t rw_act_num = 0;
7789 : : uint64_t is_root;
7790 : : const struct mlx5_flow_tunnel *tunnel;
7791 : : enum mlx5_tof_rule_type tof_rule_type;
7792 : 0 : struct flow_grp_info grp_info = {
7793 : : .external = !!external,
7794 : 0 : .transfer = !!attr->transfer,
7795 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
7796 : : .std_tbl_fix = true,
7797 : : };
7798 : : const struct rte_eth_hairpin_conf *conf;
7799 : 0 : const struct rte_flow_item *integrity_items[2] = {NULL, NULL};
7800 : : const struct rte_flow_item *port_id_item = NULL;
7801 : 0 : bool def_policy = false;
7802 : : bool shared_count = false;
7803 : : uint16_t udp_dport = 0;
7804 : 0 : uint32_t tag_id = 0, tag_bitmap = 0;
7805 : : const struct rte_flow_action_age *non_shared_age = NULL;
7806 : : const struct rte_flow_action_count *count = NULL;
7807 : : const struct rte_flow_action_port_id *port = NULL;
7808 : : const struct mlx5_rte_flow_item_tag *mlx5_tag;
7809 : 0 : struct mlx5_priv *act_priv = NULL;
7810 : : int aso_after_sample = 0;
7811 : : struct mlx5_priv *port_priv = NULL;
7812 : 0 : uint64_t sub_action_flags = 0;
7813 : 0 : uint16_t sample_port_id = 0;
7814 : : uint16_t port_id = 0;
7815 : :
7816 [ # # ]: 0 : if (items == NULL)
7817 : : return -1;
7818 : : tunnel = is_tunnel_offload_active(dev) ?
7819 [ # # ]: 0 : mlx5_get_tof(items, actions, &tof_rule_type) : NULL;
7820 [ # # ]: 0 : if (tunnel) {
7821 [ # # ]: 0 : if (!dev_conf->dv_flow_en)
7822 : 0 : return rte_flow_error_set
7823 : : (error, ENOTSUP,
7824 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7825 : : NULL, "tunnel offload requires DV flow interface");
7826 [ # # ]: 0 : if (priv->representor)
7827 : 0 : return rte_flow_error_set
7828 : : (error, ENOTSUP,
7829 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7830 : : NULL, "decap not supported for VF representor");
7831 [ # # ]: 0 : if (tof_rule_type == MLX5_TUNNEL_OFFLOAD_SET_RULE)
7832 : 0 : action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
7833 [ # # ]: 0 : else if (tof_rule_type == MLX5_TUNNEL_OFFLOAD_MATCH_RULE)
7834 : 0 : action_flags |= MLX5_FLOW_ACTION_TUNNEL_MATCH |
7835 : : MLX5_FLOW_ACTION_DECAP;
7836 : 0 : grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
7837 : : (dev, attr, tunnel, tof_rule_type);
7838 : : }
7839 : 0 : ret = flow_dv_validate_attributes(dev, tunnel, attr, &grp_info, error);
7840 [ # # ]: 0 : if (ret < 0)
7841 : : return ret;
7842 : 0 : is_root = (uint64_t)ret;
7843 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
7844 : : enum mlx5_l3_tunnel_detection l3_tunnel_detection;
7845 : : uint64_t l3_tunnel_flag;
7846 : 0 : int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
7847 : 0 : int type = items->type;
7848 : :
7849 : : if (!mlx5_flow_os_item_supported(type))
7850 : : return rte_flow_error_set(error, ENOTSUP,
7851 : : RTE_FLOW_ERROR_TYPE_ITEM,
7852 : : NULL, "item not supported");
7853 [ # # # # : 0 : switch (type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # #
# ]
7854 : : case RTE_FLOW_ITEM_TYPE_VOID:
7855 : : break;
7856 : 0 : case RTE_FLOW_ITEM_TYPE_ESP:
7857 : 0 : ret = mlx5_flow_os_validate_item_esp(dev, items,
7858 : : item_flags,
7859 : : next_protocol,
7860 : : error);
7861 [ # # ]: 0 : if (ret < 0)
7862 : 0 : return ret;
7863 : 0 : last_item = MLX5_FLOW_ITEM_ESP;
7864 : 0 : break;
7865 : 0 : case RTE_FLOW_ITEM_TYPE_PORT_ID:
7866 : 0 : ret = flow_dv_validate_item_port_id
7867 : : (dev, items, attr, item_flags, &act_priv, error);
7868 [ # # ]: 0 : if (ret < 0)
7869 : 0 : return ret;
7870 : 0 : last_item = MLX5_FLOW_ITEM_PORT_ID;
7871 : : port_id_item = items;
7872 : 0 : break;
7873 : 0 : case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
7874 : : case RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR:
7875 : 0 : ret = flow_dv_validate_item_represented_port
7876 : : (dev, items, attr, item_flags, &act_priv, error);
7877 [ # # ]: 0 : if (ret < 0)
7878 : 0 : return ret;
7879 : 0 : last_item = MLX5_FLOW_ITEM_REPRESENTED_PORT;
7880 : : port_id_item = items;
7881 : 0 : break;
7882 : 0 : case RTE_FLOW_ITEM_TYPE_ETH:
7883 : 0 : ret = mlx5_flow_validate_item_eth(dev, items, item_flags,
7884 : : true, error);
7885 [ # # ]: 0 : if (ret < 0)
7886 : 0 : return ret;
7887 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
7888 : : MLX5_FLOW_LAYER_OUTER_L2;
7889 [ # # # # ]: 0 : if (items->mask != NULL && items->spec != NULL) {
7890 : 0 : ether_type =
7891 : : ((const struct rte_flow_item_eth *)
7892 : : items->spec)->hdr.ether_type;
7893 : 0 : ether_type &=
7894 : : ((const struct rte_flow_item_eth *)
7895 : 0 : items->mask)->hdr.ether_type;
7896 [ # # ]: 0 : ether_type = rte_be_to_cpu_16(ether_type);
7897 : : } else {
7898 : : ether_type = 0;
7899 : : }
7900 : : break;
7901 : 0 : case RTE_FLOW_ITEM_TYPE_VLAN:
7902 : 0 : ret = mlx5_flow_dv_validate_item_vlan(items, item_flags,
7903 : : dev, error);
7904 [ # # ]: 0 : if (ret < 0)
7905 : 0 : return ret;
7906 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
7907 : : MLX5_FLOW_LAYER_OUTER_VLAN;
7908 [ # # # # ]: 0 : if (items->mask != NULL && items->spec != NULL) {
7909 : 0 : ether_type =
7910 : : ((const struct rte_flow_item_vlan *)
7911 : : items->spec)->hdr.eth_proto;
7912 : 0 : ether_type &=
7913 : : ((const struct rte_flow_item_vlan *)
7914 : 0 : items->mask)->hdr.eth_proto;
7915 [ # # ]: 0 : ether_type = rte_be_to_cpu_16(ether_type);
7916 : : } else {
7917 : : ether_type = 0;
7918 : : }
7919 : : /* Store outer VLAN mask for of_push_vlan action. */
7920 [ # # ]: 0 : if (!tunnel)
7921 : : vlan_m = items->mask;
7922 : : break;
7923 : : case RTE_FLOW_ITEM_TYPE_IPV4:
7924 : : next_protocol = mlx5_flow_l3_next_protocol
7925 : : (items, (enum MLX5_SET_MATCHER)-1);
7926 : : l3_tunnel_detection =
7927 : : mlx5_flow_tunnel_ip_check(items, next_protocol,
7928 : : item_flags,
7929 : : &l3_tunnel_flag);
7930 : : /*
7931 : : * explicitly allow inner IPIP match
7932 : : */
7933 : : if (l3_tunnel_detection == l3_tunnel_outer) {
7934 : 0 : item_flags |= l3_tunnel_flag;
7935 : : tunnel = 1;
7936 : : }
7937 : 0 : ret = mlx5_flow_dv_validate_item_ipv4(dev, items,
7938 : : item_flags,
7939 : : last_item,
7940 : : ether_type,
7941 : : &nic_ipv4_mask,
7942 : : error);
7943 [ # # ]: 0 : if (ret < 0)
7944 : 0 : return ret;
7945 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
7946 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4;
7947 [ # # ]: 0 : if (l3_tunnel_detection == l3_tunnel_outer)
7948 : 0 : item_flags |= l3_tunnel_flag;
7949 : : break;
7950 : : case RTE_FLOW_ITEM_TYPE_IPV6:
7951 : : next_protocol = mlx5_flow_l3_next_protocol
7952 : : (items, (enum MLX5_SET_MATCHER)-1);
7953 : : l3_tunnel_detection =
7954 : : mlx5_flow_tunnel_ip_check(items, next_protocol,
7955 : : item_flags,
7956 : : &l3_tunnel_flag);
7957 : : /*
7958 : : * explicitly allow inner IPIP match
7959 : : */
7960 : : if (l3_tunnel_detection == l3_tunnel_outer) {
7961 : 0 : item_flags |= l3_tunnel_flag;
7962 : : tunnel = 1;
7963 : : }
7964 : 0 : ret = mlx5_flow_validate_item_ipv6(dev, items,
7965 : : item_flags,
7966 : : last_item,
7967 : : ether_type,
7968 : : &nic_ipv6_mask,
7969 : : error);
7970 [ # # ]: 0 : if (ret < 0)
7971 : 0 : return ret;
7972 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
7973 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6;
7974 [ # # ]: 0 : if (l3_tunnel_detection == l3_tunnel_outer)
7975 : 0 : item_flags |= l3_tunnel_flag;
7976 : : break;
7977 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
7978 : 0 : ret = flow_dv_validate_item_ipv6_frag_ext(dev, items,
7979 : : item_flags,
7980 : : error);
7981 [ # # ]: 0 : if (ret < 0)
7982 : 0 : return ret;
7983 [ # # ]: 0 : last_item = tunnel ?
7984 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
7985 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
7986 : : next_protocol = mlx5_flow_l3_next_protocol
7987 : : (items, (enum MLX5_SET_MATCHER)-1);
7988 : : break;
7989 : 0 : case RTE_FLOW_ITEM_TYPE_TCP:
7990 : 0 : ret = mlx5_flow_validate_item_tcp
7991 : : (dev, items, item_flags,
7992 : : next_protocol,
7993 : : &nic_tcp_mask,
7994 : : error);
7995 [ # # ]: 0 : if (ret < 0)
7996 : 0 : return ret;
7997 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
7998 : : MLX5_FLOW_LAYER_OUTER_L4_TCP;
7999 : 0 : break;
8000 : 0 : case RTE_FLOW_ITEM_TYPE_UDP:
8001 : 0 : ret = mlx5_flow_validate_item_udp(dev, items, item_flags,
8002 : : next_protocol,
8003 : : error);
8004 : 0 : const struct rte_flow_item_udp *spec = items->spec;
8005 : 0 : const struct rte_flow_item_udp *mask = items->mask;
8006 [ # # ]: 0 : if (!mask)
8007 : : mask = &rte_flow_item_udp_mask;
8008 [ # # ]: 0 : if (spec != NULL)
8009 [ # # ]: 0 : udp_dport = rte_be_to_cpu_16
8010 : : (spec->hdr.dst_port &
8011 : : mask->hdr.dst_port);
8012 [ # # ]: 0 : if (ret < 0)
8013 : 0 : return ret;
8014 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
8015 : : MLX5_FLOW_LAYER_OUTER_L4_UDP;
8016 : 0 : break;
8017 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
8018 : 0 : ret = mlx5_flow_validate_item_gre(dev, items, item_flags,
8019 : : next_protocol, error);
8020 [ # # ]: 0 : if (ret < 0)
8021 : 0 : return ret;
8022 : : gre_item = items;
8023 : 0 : last_item = MLX5_FLOW_LAYER_GRE;
8024 : 0 : break;
8025 : 0 : case RTE_FLOW_ITEM_TYPE_GRE_OPTION:
8026 : 0 : ret = mlx5_flow_validate_item_gre_option(dev, items, item_flags,
8027 : : attr, gre_item, error);
8028 [ # # ]: 0 : if (ret < 0)
8029 : 0 : return ret;
8030 : 0 : last_item = MLX5_FLOW_LAYER_GRE;
8031 : 0 : break;
8032 : 0 : case RTE_FLOW_ITEM_TYPE_NVGRE:
8033 : 0 : ret = mlx5_flow_validate_item_nvgre(dev, items,
8034 : : item_flags,
8035 : : next_protocol,
8036 : : error);
8037 [ # # ]: 0 : if (ret < 0)
8038 : 0 : return ret;
8039 : 0 : last_item = MLX5_FLOW_LAYER_NVGRE;
8040 : 0 : break;
8041 : 0 : case RTE_FLOW_ITEM_TYPE_GRE_KEY:
8042 : 0 : ret = mlx5_flow_validate_item_gre_key
8043 : : (dev, items, item_flags, gre_item, error);
8044 [ # # ]: 0 : if (ret < 0)
8045 : 0 : return ret;
8046 : 0 : last_item = MLX5_FLOW_LAYER_GRE_KEY;
8047 : 0 : break;
8048 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN:
8049 : 0 : ret = mlx5_flow_validate_item_vxlan(dev, udp_dport,
8050 : : items, item_flags,
8051 : : is_root, error);
8052 [ # # ]: 0 : if (ret < 0)
8053 : 0 : return ret;
8054 : 0 : last_item = MLX5_FLOW_LAYER_VXLAN;
8055 : 0 : break;
8056 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
8057 : 0 : ret = mlx5_flow_validate_item_vxlan_gpe(items,
8058 : : item_flags, dev,
8059 : : error);
8060 [ # # ]: 0 : if (ret < 0)
8061 : 0 : return ret;
8062 : 0 : last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
8063 : 0 : break;
8064 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE:
8065 : 0 : ret = mlx5_flow_validate_item_geneve(items,
8066 : : item_flags, dev,
8067 : : error);
8068 [ # # ]: 0 : if (ret < 0)
8069 : 0 : return ret;
8070 : : geneve_item = items;
8071 : 0 : last_item = MLX5_FLOW_LAYER_GENEVE;
8072 : 0 : break;
8073 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
8074 : 0 : ret = mlx5_flow_validate_item_geneve_opt(items,
8075 : : last_item,
8076 : : geneve_item,
8077 : : dev,
8078 : : error);
8079 [ # # ]: 0 : if (ret < 0)
8080 : 0 : return ret;
8081 : 0 : last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
8082 : 0 : break;
8083 : 0 : case RTE_FLOW_ITEM_TYPE_MPLS:
8084 : 0 : ret = mlx5_flow_validate_item_mpls(dev, items,
8085 : : item_flags,
8086 : : last_item, error);
8087 [ # # ]: 0 : if (ret < 0)
8088 : 0 : return ret;
8089 : 0 : last_item = MLX5_FLOW_LAYER_MPLS;
8090 : 0 : break;
8091 : :
8092 : 0 : case RTE_FLOW_ITEM_TYPE_MARK:
8093 : 0 : ret = flow_dv_validate_item_mark(dev, items, attr,
8094 : : error);
8095 [ # # ]: 0 : if (ret < 0)
8096 : 0 : return ret;
8097 : 0 : last_item = MLX5_FLOW_ITEM_MARK;
8098 : 0 : break;
8099 : 0 : case RTE_FLOW_ITEM_TYPE_META:
8100 : 0 : ret = flow_dv_validate_item_meta(dev, items, attr,
8101 : : error);
8102 [ # # ]: 0 : if (ret < 0)
8103 : 0 : return ret;
8104 : 0 : last_item = MLX5_FLOW_ITEM_METADATA;
8105 : 0 : break;
8106 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP:
8107 : 0 : ret = mlx5_flow_validate_item_icmp(dev, items, item_flags,
8108 : : next_protocol,
8109 : : error);
8110 [ # # ]: 0 : if (ret < 0)
8111 : 0 : return ret;
8112 : 0 : last_item = MLX5_FLOW_LAYER_ICMP;
8113 : 0 : break;
8114 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6:
8115 : 0 : ret = mlx5_flow_validate_item_icmp6(dev, items, item_flags,
8116 : : next_protocol,
8117 : : error);
8118 [ # # ]: 0 : if (ret < 0)
8119 : 0 : return ret;
8120 : : item_ipv6_proto = IPPROTO_ICMPV6;
8121 : 0 : last_item = MLX5_FLOW_LAYER_ICMP6;
8122 : 0 : break;
8123 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REQUEST:
8124 : : case RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REPLY:
8125 : 0 : ret = mlx5_flow_validate_item_icmp6_echo(dev, items,
8126 : : item_flags,
8127 : : next_protocol,
8128 : : error);
8129 [ # # ]: 0 : if (ret < 0)
8130 : 0 : return ret;
8131 : : item_ipv6_proto = IPPROTO_ICMPV6;
8132 : 0 : last_item = MLX5_FLOW_LAYER_ICMP6;
8133 : 0 : break;
8134 : 0 : case RTE_FLOW_ITEM_TYPE_TAG:
8135 : 0 : ret = flow_dv_validate_item_tag(dev, items, &tag_bitmap,
8136 : : attr, error);
8137 [ # # ]: 0 : if (ret < 0)
8138 : 0 : return ret;
8139 : 0 : last_item = MLX5_FLOW_ITEM_TAG;
8140 : 0 : break;
8141 : 0 : case RTE_FLOW_ITEM_TYPE_TX_QUEUE:
8142 : : case MLX5_RTE_FLOW_ITEM_TYPE_SQ:
8143 : 0 : last_item = MLX5_FLOW_ITEM_SQ;
8144 : 0 : break;
8145 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
8146 : 0 : mlx5_tag = (const struct mlx5_rte_flow_item_tag *)items->spec;
8147 [ # # ]: 0 : if (tag_bitmap & (1 << mlx5_tag->id))
8148 : 0 : return rte_flow_error_set(error, EINVAL,
8149 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
8150 : : items->spec,
8151 : : "Duplicated tag index");
8152 : 0 : tag_bitmap |= 1 << mlx5_tag->id;
8153 : 0 : break;
8154 : 0 : case RTE_FLOW_ITEM_TYPE_GTP:
8155 : 0 : ret = mlx5_flow_dv_validate_item_gtp(dev, items,
8156 : : item_flags,
8157 : : error);
8158 [ # # ]: 0 : if (ret < 0)
8159 : 0 : return ret;
8160 : : gtp_item = items;
8161 : 0 : last_item = MLX5_FLOW_LAYER_GTP;
8162 : 0 : break;
8163 : 0 : case RTE_FLOW_ITEM_TYPE_GTP_PSC:
8164 : 0 : ret = mlx5_flow_dv_validate_item_gtp_psc(dev, items,
8165 : : last_item,
8166 : : gtp_item,
8167 : : is_root, error);
8168 [ # # ]: 0 : if (ret < 0)
8169 : 0 : return ret;
8170 : 0 : last_item = MLX5_FLOW_LAYER_GTP_PSC;
8171 : 0 : break;
8172 : 0 : case RTE_FLOW_ITEM_TYPE_ECPRI:
8173 : : /* Capacity will be checked in the translate stage. */
8174 : 0 : ret = mlx5_flow_validate_item_ecpri(dev, items,
8175 : : item_flags,
8176 : : last_item,
8177 : : ether_type,
8178 : : &nic_ecpri_mask,
8179 : : error);
8180 [ # # ]: 0 : if (ret < 0)
8181 : 0 : return ret;
8182 : 0 : last_item = MLX5_FLOW_LAYER_ECPRI;
8183 : 0 : break;
8184 : 0 : case RTE_FLOW_ITEM_TYPE_INTEGRITY:
8185 : 0 : ret = flow_dv_validate_item_integrity(dev, items,
8186 : : item_flags,
8187 : : &last_item,
8188 : : integrity_items,
8189 : : error);
8190 [ # # ]: 0 : if (ret < 0)
8191 : 0 : return ret;
8192 : : break;
8193 : 0 : case RTE_FLOW_ITEM_TYPE_CONNTRACK:
8194 : 0 : ret = mlx5_flow_dv_validate_item_aso_ct(dev, items,
8195 : : &item_flags,
8196 : : error);
8197 [ # # ]: 0 : if (ret < 0)
8198 : 0 : return ret;
8199 : 0 : last_item = MLX5_FLOW_LAYER_ASO_CT;
8200 : 0 : break;
8201 : : case MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL:
8202 : : /* tunnel offload item was processed before
8203 : : * list it here as a supported type
8204 : : */
8205 : : break;
8206 : 0 : case RTE_FLOW_ITEM_TYPE_FLEX:
8207 : 0 : ret = flow_dv_validate_item_flex(dev, items, item_flags,
8208 : : &last_item,
8209 : : tunnel != 0, error);
8210 [ # # ]: 0 : if (ret < 0)
8211 : 0 : return ret;
8212 : : /* Reset for next proto, it is unknown. */
8213 : : next_protocol = 0xff;
8214 : : break;
8215 : 0 : case RTE_FLOW_ITEM_TYPE_METER_COLOR:
8216 : 0 : ret = flow_dv_validate_item_meter_color(dev, items,
8217 : : attr, error);
8218 [ # # ]: 0 : if (ret < 0)
8219 : 0 : return ret;
8220 : 0 : last_item = MLX5_FLOW_ITEM_METER_COLOR;
8221 : 0 : break;
8222 : 0 : case RTE_FLOW_ITEM_TYPE_AGGR_AFFINITY:
8223 : 0 : ret = flow_dv_validate_item_aggr_affinity(dev, items,
8224 : : attr, error);
8225 [ # # ]: 0 : if (ret < 0)
8226 : 0 : return ret;
8227 : 0 : last_item = MLX5_FLOW_ITEM_AGGR_AFFINITY;
8228 : 0 : break;
8229 : 0 : case RTE_FLOW_ITEM_TYPE_IB_BTH:
8230 : 0 : ret = mlx5_flow_validate_item_ib_bth(dev, udp_dport,
8231 : : items, is_root, error);
8232 [ # # ]: 0 : if (ret < 0)
8233 : 0 : return ret;
8234 : :
8235 : 0 : last_item = MLX5_FLOW_ITEM_IB_BTH;
8236 : 0 : break;
8237 : 0 : case RTE_FLOW_ITEM_TYPE_NSH:
8238 : 0 : ret = mlx5_flow_validate_item_nsh(dev, items, error);
8239 [ # # ]: 0 : if (ret < 0)
8240 : 0 : return ret;
8241 : 0 : last_item = MLX5_FLOW_ITEM_NSH;
8242 : 0 : break;
8243 : 0 : default:
8244 : 0 : return rte_flow_error_set(error, ENOTSUP,
8245 : : RTE_FLOW_ERROR_TYPE_ITEM,
8246 : : NULL, "item not supported");
8247 : : }
8248 : 0 : item_flags |= last_item;
8249 : : }
8250 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_INTEGRITY) {
8251 : 0 : ret = flow_dv_validate_item_integrity_post(integrity_items,
8252 : : item_flags, error);
8253 [ # # ]: 0 : if (ret)
8254 : : return ret;
8255 : : }
8256 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
8257 : 0 : int type = actions->type;
8258 : :
8259 : : if (!mlx5_flow_os_action_supported(type))
8260 : : return rte_flow_error_set(error, ENOTSUP,
8261 : : RTE_FLOW_ERROR_TYPE_ACTION,
8262 : : actions,
8263 : : "action not supported");
8264 [ # # ]: 0 : if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
8265 : 0 : return rte_flow_error_set(error, ENOTSUP,
8266 : : RTE_FLOW_ERROR_TYPE_ACTION,
8267 : : actions, "too many actions");
8268 [ # # ]: 0 : if (action_flags &
8269 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
8270 : 0 : return rte_flow_error_set(error, ENOTSUP,
8271 : : RTE_FLOW_ERROR_TYPE_ACTION,
8272 : : NULL, "meter action with policy "
8273 : : "must be the last action");
8274 [ # # # # : 0 : switch (type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
8275 : : case RTE_FLOW_ACTION_TYPE_VOID:
8276 : : break;
8277 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
8278 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
8279 : 0 : ret = flow_dv_validate_action_port_id(dev,
8280 : : action_flags,
8281 : : actions,
8282 : : attr,
8283 : : error);
8284 [ # # ]: 0 : if (ret)
8285 : 0 : return ret;
8286 [ # # ]: 0 : if (type == RTE_FLOW_ACTION_TYPE_PORT_ID) {
8287 : 0 : port = (const struct rte_flow_action_port_id *)
8288 : : actions->conf;
8289 [ # # ]: 0 : port_id = port->original ? dev->data->port_id : port->id;
8290 : : } else {
8291 : 0 : port_id = ((const struct rte_flow_action_ethdev *)
8292 : 0 : actions->conf)->port_id;
8293 : : }
8294 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_ID;
8295 : 0 : ++actions_n;
8296 : 0 : break;
8297 : 0 : case RTE_FLOW_ACTION_TYPE_FLAG:
8298 : 0 : ret = flow_dv_validate_action_flag(dev, action_flags,
8299 : : attr, error);
8300 [ # # ]: 0 : if (ret < 0)
8301 : 0 : return ret;
8302 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
8303 : : /* Count all modify-header actions as one. */
8304 [ # # ]: 0 : if (!(action_flags &
8305 : : MLX5_FLOW_MODIFY_HDR_ACTIONS))
8306 : 0 : ++actions_n;
8307 : 0 : action_flags |= MLX5_FLOW_ACTION_FLAG |
8308 : : MLX5_FLOW_ACTION_MARK_EXT;
8309 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8310 : : modify_after_mirror = 1;
8311 : :
8312 : : } else {
8313 : 0 : action_flags |= MLX5_FLOW_ACTION_FLAG;
8314 : 0 : ++actions_n;
8315 : : }
8316 : 0 : rw_act_num += MLX5_ACT_NUM_SET_MARK;
8317 : 0 : break;
8318 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
8319 : 0 : ret = flow_dv_validate_action_mark(dev, actions,
8320 : : 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_MARK |
8330 : : MLX5_FLOW_ACTION_MARK_EXT;
8331 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8332 : : modify_after_mirror = 1;
8333 : : } else {
8334 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK;
8335 : 0 : ++actions_n;
8336 : : }
8337 : 0 : rw_act_num += MLX5_ACT_NUM_SET_MARK;
8338 : 0 : break;
8339 : 0 : case RTE_FLOW_ACTION_TYPE_SET_META:
8340 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
8341 : 0 : return rte_flow_error_set(error, ENOTSUP,
8342 : : RTE_FLOW_ERROR_TYPE_ACTION,
8343 : : actions,
8344 : : "action not supported");
8345 : 0 : ret = flow_dv_validate_action_set_meta(dev, actions,
8346 : : action_flags,
8347 : : attr, error);
8348 [ # # ]: 0 : if (ret < 0)
8349 : 0 : return ret;
8350 : : /* Count all modify-header actions as one action. */
8351 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8352 : 0 : ++actions_n;
8353 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8354 : : modify_after_mirror = 1;
8355 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_META;
8356 : 0 : rw_act_num += MLX5_ACT_NUM_SET_META;
8357 : 0 : break;
8358 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TAG:
8359 : 0 : ret = flow_dv_validate_action_set_tag(dev, actions,
8360 : : action_flags,
8361 : : attr, error);
8362 [ # # ]: 0 : if (ret < 0)
8363 : 0 : return ret;
8364 : : /* Count all modify-header actions as one action. */
8365 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8366 : 0 : ++actions_n;
8367 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8368 : : modify_after_mirror = 1;
8369 : 0 : tag_id = ((const struct rte_flow_action_set_tag *)
8370 : 0 : actions->conf)->index;
8371 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
8372 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
8373 : 0 : break;
8374 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
8375 : 0 : ret = mlx5_flow_validate_action_drop(dev, is_root,
8376 : : attr, error);
8377 [ # # ]: 0 : if (ret < 0)
8378 : 0 : return ret;
8379 : 0 : action_flags |= MLX5_FLOW_ACTION_DROP;
8380 : 0 : ++actions_n;
8381 : 0 : break;
8382 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
8383 : 0 : ret = mlx5_flow_validate_action_queue(actions,
8384 : : action_flags, dev,
8385 : : attr, error);
8386 [ # # ]: 0 : if (ret < 0)
8387 : 0 : return ret;
8388 : 0 : queue_index = ((const struct rte_flow_action_queue *)
8389 : 0 : (actions->conf))->index;
8390 : 0 : action_flags |= MLX5_FLOW_ACTION_QUEUE;
8391 : 0 : ++actions_n;
8392 : 0 : break;
8393 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
8394 : 0 : rss = actions->conf;
8395 : 0 : ret = mlx5_flow_validate_action_rss(actions,
8396 : : action_flags, dev,
8397 : : attr, item_flags,
8398 : : error);
8399 [ # # ]: 0 : if (ret < 0)
8400 : 0 : return ret;
8401 [ # # ]: 0 : if (rss && sample_rss &&
8402 [ # # ]: 0 : (sample_rss->level != rss->level ||
8403 [ # # ]: 0 : sample_rss->types != rss->types))
8404 : 0 : return rte_flow_error_set(error, ENOTSUP,
8405 : : RTE_FLOW_ERROR_TYPE_ACTION,
8406 : : NULL,
8407 : : "Can't use the different RSS types "
8408 : : "or level in the same flow");
8409 [ # # # # ]: 0 : if (rss != NULL && rss->queue_num)
8410 : 0 : queue_index = rss->queue[0];
8411 : 0 : action_flags |= MLX5_FLOW_ACTION_RSS;
8412 : 0 : ++actions_n;
8413 : 0 : break;
8414 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
8415 : : ret =
8416 : 0 : mlx5_flow_validate_action_default_miss(action_flags,
8417 : : attr, error);
8418 [ # # ]: 0 : if (ret < 0)
8419 : 0 : return ret;
8420 : 0 : action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
8421 : 0 : ++actions_n;
8422 : 0 : break;
8423 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
8424 : : shared_count = true;
8425 : : /* fall-through. */
8426 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
8427 : 0 : ret = flow_dv_validate_action_count(dev, shared_count,
8428 : : action_flags,
8429 : : is_root, error);
8430 [ # # ]: 0 : if (ret < 0)
8431 : 0 : return ret;
8432 : 0 : count = actions->conf;
8433 : 0 : action_flags |= MLX5_FLOW_ACTION_COUNT;
8434 : 0 : ++actions_n;
8435 : 0 : break;
8436 : 0 : case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
8437 [ # # ]: 0 : if (flow_dv_validate_action_pop_vlan(dev,
8438 : : action_flags,
8439 : : actions,
8440 : : item_flags, attr,
8441 : : error))
8442 : 0 : return -rte_errno;
8443 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8444 : : modify_after_mirror = 1;
8445 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
8446 : 0 : ++actions_n;
8447 : 0 : break;
8448 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
8449 : 0 : ret = flow_dv_validate_action_push_vlan(dev,
8450 : : action_flags,
8451 : : vlan_m,
8452 : : actions, attr,
8453 : : error);
8454 [ # # ]: 0 : if (ret < 0)
8455 : 0 : return ret;
8456 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8457 : : modify_after_mirror = 1;
8458 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
8459 : 0 : ++actions_n;
8460 : 0 : break;
8461 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
8462 : 0 : ret = flow_dv_validate_action_set_vlan_pcp
8463 : : (action_flags, actions, error);
8464 [ # # ]: 0 : if (ret < 0)
8465 : 0 : return ret;
8466 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8467 : : modify_after_mirror = 1;
8468 : : /* Count PCP with push_vlan command. */
8469 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_PCP;
8470 : 0 : break;
8471 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
8472 : 0 : ret = flow_dv_validate_action_set_vlan_vid
8473 : : (item_flags, action_flags,
8474 : : actions, error);
8475 [ # # ]: 0 : if (ret < 0)
8476 : 0 : return ret;
8477 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8478 : : modify_after_mirror = 1;
8479 : : /* Count VID with push_vlan command. */
8480 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
8481 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_VID;
8482 : 0 : break;
8483 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
8484 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
8485 : 0 : ret = mlx5_flow_dv_validate_action_l2_encap(dev,
8486 : : action_flags,
8487 : : actions,
8488 : : attr,
8489 : : error);
8490 [ # # ]: 0 : if (ret < 0)
8491 : 0 : return ret;
8492 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
8493 : 0 : ++actions_n;
8494 : 0 : break;
8495 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
8496 : : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
8497 : 0 : ret = mlx5_flow_dv_validate_action_decap(dev,
8498 : : action_flags,
8499 : : actions,
8500 : : item_flags,
8501 : : attr, error);
8502 [ # # ]: 0 : if (ret < 0)
8503 : 0 : return ret;
8504 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8505 : : modify_after_mirror = 1;
8506 : 0 : action_flags |= MLX5_FLOW_ACTION_DECAP;
8507 : 0 : ++actions_n;
8508 : 0 : break;
8509 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
8510 : 0 : ret = mlx5_flow_dv_validate_action_raw_encap_decap
8511 : 0 : (dev, NULL, actions->conf, attr, &action_flags,
8512 : : &actions_n, actions, item_flags, error);
8513 [ # # ]: 0 : if (ret < 0)
8514 : 0 : return ret;
8515 : : break;
8516 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
8517 : 0 : decap = actions->conf;
8518 [ # # ]: 0 : while ((++actions)->type == RTE_FLOW_ACTION_TYPE_VOID)
8519 : : ;
8520 [ # # ]: 0 : if (actions->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
8521 : : encap = NULL;
8522 : : actions--;
8523 : : } else {
8524 : 0 : encap = actions->conf;
8525 : : }
8526 [ # # ]: 0 : ret = mlx5_flow_dv_validate_action_raw_encap_decap
8527 : : (dev,
8528 : : decap ? decap : &empty_decap, encap,
8529 : : attr, &action_flags, &actions_n,
8530 : : actions, item_flags, error);
8531 [ # # ]: 0 : if (ret < 0)
8532 : 0 : return ret;
8533 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_SAMPLE) &&
8534 : : (action_flags & MLX5_FLOW_ACTION_DECAP))
8535 : : modify_after_mirror = 1;
8536 : : break;
8537 : 0 : case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
8538 : : case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
8539 : 0 : ret = flow_dv_validate_action_modify_mac(action_flags,
8540 : : actions,
8541 : : item_flags,
8542 : : error);
8543 [ # # ]: 0 : if (ret < 0)
8544 : 0 : return ret;
8545 : : /* Count all modify-header actions as one action. */
8546 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8547 : 0 : ++actions_n;
8548 : 0 : action_flags |= actions->type ==
8549 : : RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
8550 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_MAC_SRC :
8551 : : MLX5_FLOW_ACTION_SET_MAC_DST;
8552 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8553 : : modify_after_mirror = 1;
8554 : : /*
8555 : : * Even if the source and destination MAC addresses have
8556 : : * overlap in the header with 4B alignment, the convert
8557 : : * function will handle them separately and 4 SW actions
8558 : : * will be created. And 2 actions will be added each
8559 : : * time no matter how many bytes of address will be set.
8560 : : */
8561 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_MAC;
8562 : 0 : break;
8563 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
8564 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
8565 : 0 : ret = flow_dv_validate_action_modify_ipv4(action_flags,
8566 : : actions,
8567 : : item_flags,
8568 : : error);
8569 [ # # ]: 0 : if (ret < 0)
8570 : 0 : return ret;
8571 : : /* Count all modify-header actions as one action. */
8572 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8573 : 0 : ++actions_n;
8574 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8575 : : modify_after_mirror = 1;
8576 : 0 : action_flags |= actions->type ==
8577 : : RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
8578 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_IPV4_SRC :
8579 : : MLX5_FLOW_ACTION_SET_IPV4_DST;
8580 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_IPV4;
8581 : 0 : break;
8582 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
8583 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
8584 : 0 : ret = flow_dv_validate_action_modify_ipv6(action_flags,
8585 : : actions,
8586 : : item_flags,
8587 : : error);
8588 [ # # ]: 0 : if (ret < 0)
8589 : 0 : return ret;
8590 [ # # ]: 0 : if (item_ipv6_proto == IPPROTO_ICMPV6)
8591 : 0 : return rte_flow_error_set(error, ENOTSUP,
8592 : : RTE_FLOW_ERROR_TYPE_ACTION,
8593 : : actions,
8594 : : "Can't change header "
8595 : : "with ICMPv6 proto");
8596 : : /* Count all modify-header actions as one action. */
8597 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8598 : 0 : ++actions_n;
8599 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8600 : : modify_after_mirror = 1;
8601 : 0 : action_flags |= actions->type ==
8602 : : RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
8603 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_IPV6_SRC :
8604 : : MLX5_FLOW_ACTION_SET_IPV6_DST;
8605 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_IPV6;
8606 : 0 : break;
8607 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
8608 : : case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
8609 : 0 : ret = flow_dv_validate_action_modify_tp(action_flags,
8610 : : actions,
8611 : : item_flags,
8612 : : error);
8613 [ # # ]: 0 : if (ret < 0)
8614 : 0 : return ret;
8615 : : /* Count all modify-header actions as one action. */
8616 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8617 : 0 : ++actions_n;
8618 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8619 : : modify_after_mirror = 1;
8620 : 0 : action_flags |= actions->type ==
8621 : : RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
8622 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_TP_SRC :
8623 : : MLX5_FLOW_ACTION_SET_TP_DST;
8624 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_PORT;
8625 : 0 : break;
8626 : 0 : case RTE_FLOW_ACTION_TYPE_DEC_TTL:
8627 : : case RTE_FLOW_ACTION_TYPE_SET_TTL:
8628 : 0 : ret = flow_dv_validate_action_modify_ttl(action_flags,
8629 : : actions,
8630 : : item_flags,
8631 : : error);
8632 [ # # ]: 0 : if (ret < 0)
8633 : 0 : return ret;
8634 : : /* Count all modify-header actions as one action. */
8635 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8636 : 0 : ++actions_n;
8637 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8638 : : modify_after_mirror = 1;
8639 : 0 : action_flags |= actions->type ==
8640 : : RTE_FLOW_ACTION_TYPE_SET_TTL ?
8641 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_TTL :
8642 : : MLX5_FLOW_ACTION_DEC_TTL;
8643 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_TTL;
8644 : 0 : break;
8645 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
8646 : 0 : ret = flow_dv_validate_action_jump(dev, tunnel, actions,
8647 : : action_flags,
8648 : : attr, external,
8649 : : error);
8650 [ # # ]: 0 : if (ret)
8651 : 0 : return ret;
8652 : 0 : ++actions_n;
8653 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP;
8654 : 0 : break;
8655 : 0 : case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
8656 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
8657 : 0 : ret = flow_dv_validate_action_modify_tcp_seq
8658 : : (action_flags,
8659 : : actions,
8660 : : item_flags,
8661 : : error);
8662 [ # # ]: 0 : if (ret < 0)
8663 : 0 : return ret;
8664 : : /* Count all modify-header actions as one action. */
8665 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8666 : 0 : ++actions_n;
8667 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8668 : : modify_after_mirror = 1;
8669 : 0 : action_flags |= actions->type ==
8670 : : RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
8671 [ # # ]: 0 : MLX5_FLOW_ACTION_INC_TCP_SEQ :
8672 : : MLX5_FLOW_ACTION_DEC_TCP_SEQ;
8673 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_TCPSEQ;
8674 : 0 : break;
8675 : 0 : case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
8676 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
8677 : 0 : ret = flow_dv_validate_action_modify_tcp_ack
8678 : : (action_flags,
8679 : : actions,
8680 : : item_flags,
8681 : : error);
8682 [ # # ]: 0 : if (ret < 0)
8683 : 0 : return ret;
8684 : : /* Count all modify-header actions as one action. */
8685 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8686 : 0 : ++actions_n;
8687 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8688 : : modify_after_mirror = 1;
8689 : 0 : action_flags |= actions->type ==
8690 : : RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
8691 [ # # ]: 0 : MLX5_FLOW_ACTION_INC_TCP_ACK :
8692 : : MLX5_FLOW_ACTION_DEC_TCP_ACK;
8693 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_TCPACK;
8694 : 0 : break;
8695 : : case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
8696 : : break;
8697 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
8698 : : case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
8699 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
8700 : 0 : break;
8701 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
8702 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
8703 : 0 : return rte_flow_error_set(error, ENOTSUP,
8704 : : RTE_FLOW_ERROR_TYPE_ACTION,
8705 : : actions,
8706 : : "action not supported");
8707 : 0 : ret = mlx5_flow_validate_action_meter(dev,
8708 : : action_flags,
8709 : : item_flags,
8710 : : actions, attr,
8711 : : port_id_item,
8712 : : &def_policy,
8713 : : error);
8714 [ # # ]: 0 : if (ret < 0)
8715 : 0 : return ret;
8716 : 0 : action_flags |= MLX5_FLOW_ACTION_METER;
8717 [ # # ]: 0 : if (!def_policy)
8718 : 0 : action_flags |=
8719 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
8720 : 0 : ++actions_n;
8721 : : /* Meter action will add one more TAG action. */
8722 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
8723 : 0 : break;
8724 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
8725 [ # # ]: 0 : if (is_root)
8726 : 0 : return rte_flow_error_set(error, ENOTSUP,
8727 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8728 : : NULL,
8729 : : "Shared ASO age action is not supported for group 0");
8730 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_AGE)
8731 : 0 : return rte_flow_error_set
8732 : : (error, EINVAL,
8733 : : RTE_FLOW_ERROR_TYPE_ACTION,
8734 : : NULL,
8735 : : "duplicate age actions set");
8736 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8737 : : aso_after_sample = 1;
8738 : 0 : action_flags |= MLX5_FLOW_ACTION_AGE;
8739 : 0 : ++actions_n;
8740 : 0 : break;
8741 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
8742 : 0 : non_shared_age = actions->conf;
8743 : 0 : ret = flow_dv_validate_action_age(action_flags,
8744 : : actions, dev,
8745 : : error);
8746 [ # # ]: 0 : if (ret < 0)
8747 : 0 : return ret;
8748 : : /*
8749 : : * Validate the regular AGE action (using counter)
8750 : : * mutual exclusion with indirect counter actions.
8751 : : */
8752 [ # # ]: 0 : if (!flow_hit_aso_supported(priv, is_root)) {
8753 [ # # ]: 0 : if (shared_count)
8754 : 0 : return rte_flow_error_set
8755 : : (error, EINVAL,
8756 : : RTE_FLOW_ERROR_TYPE_ACTION,
8757 : : NULL,
8758 : : "old age and indirect count combination is not supported");
8759 [ # # ]: 0 : if (sample_count)
8760 : 0 : return rte_flow_error_set
8761 : : (error, EINVAL,
8762 : : RTE_FLOW_ERROR_TYPE_ACTION,
8763 : : NULL,
8764 : : "old age action and count must be in the same sub flow");
8765 : : } else {
8766 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8767 : : aso_after_sample = 1;
8768 : : }
8769 : 0 : action_flags |= MLX5_FLOW_ACTION_AGE;
8770 : 0 : ++actions_n;
8771 : 0 : break;
8772 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
8773 : 0 : ret = flow_dv_validate_action_modify_ipv4_dscp
8774 : : (action_flags,
8775 : : actions,
8776 : : item_flags,
8777 : : error);
8778 [ # # ]: 0 : if (ret < 0)
8779 : 0 : return ret;
8780 : : /* Count all modify-header actions as one action. */
8781 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8782 : 0 : ++actions_n;
8783 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8784 : : modify_after_mirror = 1;
8785 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
8786 : 0 : rw_act_num += MLX5_ACT_NUM_SET_DSCP;
8787 : 0 : break;
8788 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
8789 : 0 : ret = flow_dv_validate_action_modify_ipv6_dscp
8790 : : (action_flags,
8791 : : actions,
8792 : : item_flags,
8793 : : error);
8794 [ # # ]: 0 : if (ret < 0)
8795 : 0 : return ret;
8796 : : /* Count all modify-header actions as one action. */
8797 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8798 : 0 : ++actions_n;
8799 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8800 : : modify_after_mirror = 1;
8801 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
8802 : 0 : rw_act_num += MLX5_ACT_NUM_SET_DSCP;
8803 : 0 : break;
8804 : 0 : case RTE_FLOW_ACTION_TYPE_SAMPLE:
8805 : 0 : ret = flow_dv_validate_action_sample(&action_flags,
8806 : : &sub_action_flags,
8807 : : actions, dev,
8808 : : attr, item_flags,
8809 : : rss, &sample_rss,
8810 : : &sample_count,
8811 : : &fdb_mirror,
8812 : : &sample_port_id,
8813 : : is_root,
8814 : : error);
8815 [ # # ]: 0 : if (ret < 0)
8816 : 0 : return ret;
8817 [ # # # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_SET_TAG) &&
8818 : 0 : tag_id == 0 &&
8819 [ # # ]: 0 : priv->sh->registers.aso_reg == REG_NON)
8820 : 0 : return rte_flow_error_set(error, EINVAL,
8821 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8822 : : "sample after tag action causes metadata tag index 0 corruption");
8823 : 0 : action_flags |= MLX5_FLOW_ACTION_SAMPLE;
8824 : 0 : ++actions_n;
8825 : 0 : break;
8826 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
8827 : 0 : ret = flow_dv_validate_action_modify_field(dev,
8828 : : action_flags,
8829 : : actions,
8830 : : attr,
8831 : : is_root,
8832 : : error);
8833 [ # # ]: 0 : if (ret < 0)
8834 : 0 : return ret;
8835 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8836 : : modify_after_mirror = 1;
8837 : : /* Count all modify-header actions as one action. */
8838 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8839 : 0 : ++actions_n;
8840 : 0 : action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
8841 : 0 : rw_act_num += ret;
8842 : 0 : break;
8843 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
8844 : 0 : ret = mlx5_flow_dv_validate_action_aso_ct(dev,
8845 : : action_flags,
8846 : : item_flags,
8847 : : is_root,
8848 : : error);
8849 [ # # ]: 0 : if (ret < 0)
8850 : 0 : return ret;
8851 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8852 : : aso_after_sample = 1;
8853 : 0 : action_flags |= MLX5_FLOW_ACTION_CT;
8854 : 0 : break;
8855 : : case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
8856 : : /* tunnel offload action was processed before
8857 : : * list it here as a supported type
8858 : : */
8859 : : break;
8860 : : #ifdef HAVE_MLX5DV_DR_ACTION_CREATE_DEST_ROOT_TABLE
8861 : : case RTE_FLOW_ACTION_TYPE_SEND_TO_KERNEL:
8862 : : action_flags |= MLX5_FLOW_ACTION_SEND_TO_KERNEL;
8863 : : ++actions_n;
8864 : : break;
8865 : : #endif
8866 : 0 : default:
8867 : 0 : return rte_flow_error_set(error, ENOTSUP,
8868 : : RTE_FLOW_ERROR_TYPE_ACTION,
8869 : : actions,
8870 : : "action not supported");
8871 : : }
8872 : : }
8873 : : /*
8874 : : * Validate actions in flow rules
8875 : : * - Explicit decap action is prohibited by the tunnel offload API.
8876 : : * - Drop action in tunnel steer rule is prohibited by the API.
8877 : : * - Application cannot use MARK action because it's value can mask
8878 : : * tunnel default miss notification.
8879 : : * - JUMP in tunnel match rule has no support in current PMD
8880 : : * implementation.
8881 : : * - TAG & META are reserved for future uses.
8882 : : */
8883 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_TUNNEL_SET) {
8884 : : uint64_t bad_actions_mask = MLX5_FLOW_ACTION_DECAP |
8885 : : MLX5_FLOW_ACTION_MARK |
8886 : : MLX5_FLOW_ACTION_SET_TAG |
8887 : : MLX5_FLOW_ACTION_SET_META |
8888 : : MLX5_FLOW_ACTION_DROP;
8889 : :
8890 [ # # ]: 0 : if (action_flags & bad_actions_mask)
8891 : 0 : return rte_flow_error_set
8892 : : (error, EINVAL,
8893 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8894 : : "Invalid RTE action in tunnel "
8895 : : "set decap rule");
8896 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_ACTION_JUMP))
8897 : 0 : return rte_flow_error_set
8898 : : (error, EINVAL,
8899 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8900 : : "tunnel set decap rule must terminate "
8901 : : "with JUMP");
8902 [ # # ]: 0 : if (attr->egress)
8903 : 0 : return rte_flow_error_set
8904 : : (error, EINVAL,
8905 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8906 : : "tunnel flows for ingress and transfer traffic only");
8907 : : }
8908 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_TUNNEL_MATCH) {
8909 : : uint64_t bad_actions_mask = MLX5_FLOW_ACTION_JUMP |
8910 : : MLX5_FLOW_ACTION_MARK |
8911 : : MLX5_FLOW_ACTION_SET_TAG |
8912 : : MLX5_FLOW_ACTION_SET_META;
8913 : :
8914 [ # # ]: 0 : if (action_flags & bad_actions_mask)
8915 : 0 : return rte_flow_error_set
8916 : : (error, EINVAL,
8917 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8918 : : "Invalid RTE action in tunnel "
8919 : : "set match rule");
8920 : : }
8921 : : /*
8922 : : * Validate the drop action mutual exclusion with other actions.
8923 : : * Drop action is mutually-exclusive with any other action, except for
8924 : : * Count/Sample/Age actions.
8925 : : * Drop action compatibility with tunnel offload was already validated.
8926 : : */
8927 [ # # ]: 0 : if (action_flags & (MLX5_FLOW_ACTION_TUNNEL_MATCH |
8928 : : MLX5_FLOW_ACTION_TUNNEL_MATCH));
8929 [ # # ]: 0 : else if ((action_flags & MLX5_FLOW_ACTION_DROP) &&
8930 [ # # ]: 0 : (action_flags & ~(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_DROP_INCLUSIVE_ACTIONS)))
8931 : 0 : return rte_flow_error_set(error, EINVAL,
8932 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8933 : : "Drop action is mutually-exclusive "
8934 : : "with any other action, except for "
8935 : : "Count/Sample/Age action");
8936 : : /* Eswitch has few restrictions on using items and actions */
8937 [ # # ]: 0 : if (attr->transfer) {
8938 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev) &&
8939 [ # # ]: 0 : action_flags & MLX5_FLOW_ACTION_FLAG)
8940 : 0 : return rte_flow_error_set(error, ENOTSUP,
8941 : : RTE_FLOW_ERROR_TYPE_ACTION,
8942 : : NULL,
8943 : : "unsupported action FLAG");
8944 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev) &&
8945 [ # # ]: 0 : action_flags & MLX5_FLOW_ACTION_MARK)
8946 : 0 : return rte_flow_error_set(error, ENOTSUP,
8947 : : RTE_FLOW_ERROR_TYPE_ACTION,
8948 : : NULL,
8949 : : "unsupported action MARK");
8950 [ # # ]: 0 : if (!priv->jump_fdb_rx_en) {
8951 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_QUEUE)
8952 : 0 : return rte_flow_error_set(error, ENOTSUP,
8953 : : RTE_FLOW_ERROR_TYPE_ACTION,
8954 : : NULL,
8955 : : "unsupported action QUEUE");
8956 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_RSS)
8957 : 0 : return rte_flow_error_set(error, ENOTSUP,
8958 : : RTE_FLOW_ERROR_TYPE_ACTION,
8959 : : NULL,
8960 : : "unsupported action RSS");
8961 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
8962 : 0 : return rte_flow_error_set(error, EINVAL,
8963 : : RTE_FLOW_ERROR_TYPE_ACTION,
8964 : : actions,
8965 : : "no fate action is found");
8966 : : }
8967 : : } else {
8968 [ # # # # ]: 0 : if (!(action_flags & MLX5_FLOW_FATE_ACTIONS) && attr->ingress)
8969 : 0 : return rte_flow_error_set(error, EINVAL,
8970 : : RTE_FLOW_ERROR_TYPE_ACTION,
8971 : : actions,
8972 : : "no fate action is found");
8973 : : }
8974 : : /*
8975 : : * Continue validation for Xcap and VLAN actions.
8976 : : * If hairpin is working in explicit TX rule mode, there is no actions
8977 : : * splitting and the validation of hairpin ingress flow should be the
8978 : : * same as other standard flows.
8979 : : */
8980 [ # # ]: 0 : if ((action_flags & (MLX5_FLOW_XCAP_ACTIONS |
8981 [ # # ]: 0 : MLX5_FLOW_VLAN_ACTIONS)) &&
8982 [ # # # # ]: 0 : (queue_index == 0xFFFF || !mlx5_rxq_is_hairpin(dev, queue_index) ||
8983 : 0 : ((conf = mlx5_rxq_get_hairpin_conf(dev, queue_index)) != NULL &&
8984 [ # # ]: 0 : conf->tx_explicit != 0))) {
8985 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
8986 : : MLX5_FLOW_XCAP_ACTIONS)
8987 : 0 : return rte_flow_error_set(error, ENOTSUP,
8988 : : RTE_FLOW_ERROR_TYPE_ACTION,
8989 : : NULL, "encap and decap "
8990 : : "combination aren't supported");
8991 : : /* Push VLAN is not supported in ingress except for NICs newer than CX5. */
8992 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) {
8993 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
8994 : : bool direction_error = false;
8995 : :
8996 [ # # ]: 0 : if (attr->transfer) {
8997 [ # # ]: 0 : bool fdb_tx = flow_source_vport_representor(priv, act_priv);
8998 : 0 : bool is_cx5 = sh->steering_format_version ==
8999 : : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5;
9000 : :
9001 [ # # ]: 0 : if (!fdb_tx && is_cx5)
9002 : : direction_error = true;
9003 [ # # ]: 0 : } else if (attr->ingress) {
9004 : : direction_error = true;
9005 : : }
9006 : : if (direction_error)
9007 : 0 : return rte_flow_error_set(error, ENOTSUP,
9008 : : RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
9009 : : NULL,
9010 : : "push VLAN action not supported "
9011 : : "for ingress");
9012 : : }
9013 [ # # ]: 0 : if (attr->ingress) {
9014 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
9015 : 0 : return rte_flow_error_set
9016 : : (error, ENOTSUP,
9017 : : RTE_FLOW_ERROR_TYPE_ACTION,
9018 : : NULL, "encap is not supported"
9019 : : " for ingress traffic");
9020 [ # # ]: 0 : else if ((action_flags & MLX5_FLOW_VLAN_ACTIONS) ==
9021 : : MLX5_FLOW_VLAN_ACTIONS)
9022 : 0 : return rte_flow_error_set
9023 : : (error, ENOTSUP,
9024 : : RTE_FLOW_ERROR_TYPE_ACTION,
9025 : : NULL, "no support for "
9026 : : "multiple VLAN actions");
9027 : : }
9028 : : }
9029 : : /* Pop VLAN is not supported in egress except for NICs newer than CX5. */
9030 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_POP_VLAN) {
9031 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
9032 : : bool direction_error = false;
9033 : :
9034 [ # # ]: 0 : if (attr->transfer) {
9035 [ # # ]: 0 : bool fdb_tx = flow_source_vport_representor(priv, act_priv);
9036 : 0 : bool is_cx5 = sh->steering_format_version ==
9037 : : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5;
9038 : :
9039 [ # # ]: 0 : if (fdb_tx && is_cx5)
9040 : : direction_error = true;
9041 [ # # ]: 0 : } else if (attr->egress) {
9042 : : direction_error = true;
9043 : : }
9044 : : if (direction_error)
9045 : 0 : return rte_flow_error_set(error, ENOTSUP,
9046 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
9047 : : NULL,
9048 : : "pop vlan action not supported for egress");
9049 : : }
9050 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY) {
9051 [ # # ]: 0 : if ((action_flags & (MLX5_FLOW_FATE_ACTIONS &
9052 [ # # ]: 0 : ~MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)) &&
9053 : : attr->ingress)
9054 : 0 : return rte_flow_error_set
9055 : : (error, ENOTSUP,
9056 : : RTE_FLOW_ERROR_TYPE_ACTION,
9057 : : NULL, "fate action not supported for "
9058 : : "meter with policy");
9059 [ # # ]: 0 : if (attr->egress) {
9060 [ # # ]: 0 : if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
9061 : 0 : return rte_flow_error_set
9062 : : (error, ENOTSUP,
9063 : : RTE_FLOW_ERROR_TYPE_ACTION,
9064 : : NULL, "modify header action in egress "
9065 : : "cannot be done before meter action");
9066 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
9067 : 0 : return rte_flow_error_set
9068 : : (error, ENOTSUP,
9069 : : RTE_FLOW_ERROR_TYPE_ACTION,
9070 : : NULL, "encap action in egress "
9071 : : "cannot be done before meter action");
9072 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
9073 : 0 : return rte_flow_error_set
9074 : : (error, ENOTSUP,
9075 : : RTE_FLOW_ERROR_TYPE_ACTION,
9076 : : NULL, "push vlan action in egress "
9077 : : "cannot be done before meter action");
9078 : : }
9079 : : }
9080 : : /*
9081 : : * Only support one ASO action in a single flow rule.
9082 : : * non-shared AGE + counter will fallback to use HW counter, no ASO hit object.
9083 : : * Group 0 uses HW counter for AGE too even if no counter action.
9084 : : */
9085 [ # # # # ]: 0 : aso_mask = (action_flags & MLX5_FLOW_ACTION_METER && priv->sh->meter_aso_en) << 2 |
9086 [ # # # # : 0 : (action_flags & MLX5_FLOW_ACTION_CT && priv->sh->ct_aso_en) << 1 |
# # ]
9087 : 0 : (action_flags & MLX5_FLOW_ACTION_AGE &&
9088 [ # # ]: 0 : !(non_shared_age && count) &&
9089 [ # # # # : 0 : (attr->group || (attr->transfer && priv->fdb_def_rule)) &&
# # # # ]
9090 [ # # ]: 0 : priv->sh->flow_hit_aso_en);
9091 [ # # ]: 0 : if (rte_popcount64(aso_mask) > 1)
9092 : 0 : return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
9093 : : NULL, "unsupported combining AGE, METER, CT ASO actions in a single rule");
9094 : : /*
9095 : : * Hairpin flow will add one more TAG action in TX implicit mode.
9096 : : * In TX explicit mode, there will be no hairpin flow ID.
9097 : : */
9098 [ # # ]: 0 : if (hairpin > 0)
9099 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
9100 : : /* extra metadata enabled: one more TAG action will be add. */
9101 [ # # ]: 0 : if (dev_conf->dv_flow_en &&
9102 [ # # # # ]: 0 : dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
9103 : 0 : mlx5_flow_ext_mreg_supported(dev))
9104 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
9105 [ # # ]: 0 : if (rw_act_num >
9106 : : flow_dv_modify_hdr_action_max(dev, is_root)) {
9107 : 0 : return rte_flow_error_set(error, ENOTSUP,
9108 : : RTE_FLOW_ERROR_TYPE_ACTION,
9109 : : NULL, "too many header modify"
9110 : : " actions to support");
9111 : : }
9112 [ # # ]: 0 : if (fdb_mirror) {
9113 [ # # # # ]: 0 : if (!priv->sh->cdev->config.hca_attr.reg_c_preserve &&
9114 [ # # ]: 0 : flow_source_vport_representor(priv, act_priv)) {
9115 : : /* Eswitch egress mirror and modify flow has limitation on CX5 */
9116 [ # # ]: 0 : if (modify_after_mirror)
9117 : 0 : return rte_flow_error_set(error, EINVAL,
9118 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9119 : : "sample before modify action is not supported");
9120 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_JUMP)
9121 : 0 : return rte_flow_error_set(error, EINVAL,
9122 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9123 : : "sample and jump action combination is not supported");
9124 : : }
9125 [ # # ]: 0 : if (aso_mask > 0 && aso_after_sample && fdb_mirror)
9126 : 0 : return rte_flow_error_set(error, ENOTSUP,
9127 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9128 : : "sample before ASO action is not supported");
9129 [ # # ]: 0 : if (sub_action_flags & MLX5_FLOW_ACTION_PORT_ID) {
9130 : 0 : port_priv = mlx5_port_to_eswitch_info(sample_port_id, false);
9131 [ # # ]: 0 : if (flow_source_vport_representor(priv, port_priv)) {
9132 [ # # ]: 0 : if (sub_action_flags & MLX5_FLOW_ACTION_ENCAP)
9133 : 0 : return rte_flow_error_set(error, ENOTSUP,
9134 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9135 : : "mirror to rep port with encap is not supported");
9136 : : } else {
9137 [ # # ]: 0 : if (!(sub_action_flags & MLX5_FLOW_ACTION_ENCAP) &&
9138 [ # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_JUMP))
9139 : 0 : return rte_flow_error_set(error, ENOTSUP,
9140 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9141 : : "mirror to wire port without encap is not supported");
9142 : : }
9143 : : }
9144 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_PORT_ID) &&
9145 : : (action_flags & MLX5_FLOW_ACTION_ENCAP)) {
9146 : 0 : port_priv = mlx5_port_to_eswitch_info(port_id, false);
9147 [ # # ]: 0 : if (flow_source_vport_representor(priv, port_priv))
9148 : 0 : return rte_flow_error_set(error, ENOTSUP,
9149 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9150 : : "mirror to rep port with encap is not supported");
9151 : : }
9152 : : }
9153 : : /*
9154 : : * Validation the NIC Egress flow on representor, except implicit
9155 : : * hairpin default egress flow with TX_QUEUE item, other flows not
9156 : : * work due to metadata regC0 mismatch.
9157 : : */
9158 [ # # # # : 0 : if (attr->egress && priv->representor && !(item_flags & MLX5_FLOW_ITEM_SQ))
# # ]
9159 : 0 : return rte_flow_error_set(error, EINVAL,
9160 : : RTE_FLOW_ERROR_TYPE_ITEM,
9161 : : NULL,
9162 : : "NIC egress rules on representors"
9163 : : " is not supported");
9164 : : return 0;
9165 : : }
9166 : :
9167 : : /**
9168 : : * Internal preparation function. Allocates the DV flow size,
9169 : : * this size is constant.
9170 : : *
9171 : : * @param[in] dev
9172 : : * Pointer to the rte_eth_dev structure.
9173 : : * @param[in] attr
9174 : : * Pointer to the flow attributes.
9175 : : * @param[in] items
9176 : : * Pointer to the list of items.
9177 : : * @param[in] actions
9178 : : * Pointer to the list of actions.
9179 : : * @param[out] error
9180 : : * Pointer to the error structure.
9181 : : *
9182 : : * @return
9183 : : * Pointer to mlx5_flow object on success,
9184 : : * otherwise NULL and rte_errno is set.
9185 : : */
9186 : : static struct mlx5_flow *
9187 : 0 : flow_dv_prepare(struct rte_eth_dev *dev,
9188 : : const struct rte_flow_attr *attr __rte_unused,
9189 : : const struct rte_flow_item items[] __rte_unused,
9190 : : const struct rte_flow_action actions[] __rte_unused,
9191 : : struct rte_flow_error *error)
9192 : : {
9193 : 0 : uint32_t handle_idx = 0;
9194 : : struct mlx5_flow *dev_flow;
9195 : : struct mlx5_flow_handle *dev_handle;
9196 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
9197 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
9198 : :
9199 : : MLX5_ASSERT(wks);
9200 : 0 : wks->skip_matcher_reg = 0;
9201 : 0 : wks->policy = NULL;
9202 : 0 : wks->final_policy = NULL;
9203 : 0 : wks->vport_meta_tag = 0;
9204 : : /* In case of corrupting the memory. */
9205 [ # # ]: 0 : if (wks->flow_idx >= MLX5_NUM_MAX_DEV_FLOWS) {
9206 : 0 : rte_flow_error_set(error, ENOSPC,
9207 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9208 : : "not free temporary device flow");
9209 : 0 : return NULL;
9210 : : }
9211 : 0 : dev_handle = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
9212 : : &handle_idx);
9213 [ # # ]: 0 : if (!dev_handle) {
9214 : 0 : rte_flow_error_set(error, ENOMEM,
9215 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9216 : : "not enough memory to create flow handle");
9217 : 0 : return NULL;
9218 : : }
9219 : : MLX5_ASSERT(wks->flow_idx < RTE_DIM(wks->flows));
9220 : 0 : dev_flow = &wks->flows[wks->flow_idx++];
9221 : : memset(dev_flow, 0, sizeof(*dev_flow));
9222 : 0 : dev_flow->handle = dev_handle;
9223 : 0 : dev_flow->handle_idx = handle_idx;
9224 : 0 : dev_flow->dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param);
9225 : 0 : dev_flow->ingress = attr->ingress;
9226 : 0 : dev_flow->dv.transfer = attr->transfer;
9227 : 0 : return dev_flow;
9228 : : }
9229 : :
9230 : : #ifdef RTE_LIBRTE_MLX5_DEBUG
9231 : : /**
9232 : : * Sanity check for match mask and value. Similar to check_valid_spec() in
9233 : : * kernel driver. If unmasked bit is present in value, it returns failure.
9234 : : *
9235 : : * @param match_mask
9236 : : * pointer to match mask buffer.
9237 : : * @param match_value
9238 : : * pointer to match value buffer.
9239 : : *
9240 : : * @return
9241 : : * 0 if valid, -EINVAL otherwise.
9242 : : */
9243 : : static int
9244 : : flow_dv_check_valid_spec(void *match_mask, void *match_value)
9245 : : {
9246 : : uint8_t *m = match_mask;
9247 : : uint8_t *v = match_value;
9248 : : unsigned int i;
9249 : :
9250 : : for (i = 0; i < MLX5_ST_SZ_BYTES(fte_match_param); ++i) {
9251 : : if (v[i] & ~m[i]) {
9252 : : DRV_LOG(ERR,
9253 : : "match_value differs from match_criteria"
9254 : : " %p[%u] != %p[%u]",
9255 : : match_value, i, match_mask, i);
9256 : : return -EINVAL;
9257 : : }
9258 : : }
9259 : : return 0;
9260 : : }
9261 : : #endif
9262 : :
9263 : : /**
9264 : : * Add match of ip_version.
9265 : : *
9266 : : * @param[in] group
9267 : : * Flow group.
9268 : : * @param[in] headers_v
9269 : : * Values header pointer.
9270 : : * @param[in] headers_m
9271 : : * Masks header pointer.
9272 : : * @param[in] ip_version
9273 : : * The IP version to set.
9274 : : */
9275 : : static inline void
9276 : 0 : flow_dv_set_match_ip_version(uint32_t group,
9277 : : void *headers_v,
9278 : : uint32_t key_type,
9279 : : uint8_t ip_version)
9280 : : {
9281 [ # # # # ]: 0 : if (group == 0 && (key_type & MLX5_SET_MATCHER_M))
9282 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version, 0xf);
9283 : : else
9284 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version,
9285 : : ip_version);
9286 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype, 0);
9287 : 0 : }
9288 : :
9289 : : /**
9290 : : * Add Ethernet item to the value.
9291 : : *
9292 : : * @param[in, out] key
9293 : : * Flow matcher value.
9294 : : * @param[in] item
9295 : : * Flow pattern to translate.
9296 : : * @param[in] inner
9297 : : * Item is inner pattern.
9298 : : * @param[in] grpup
9299 : : * Flow matcher group.
9300 : : * @param[in] key_type
9301 : : * Set flow matcher mask or value.
9302 : : */
9303 : : static void
9304 : 0 : flow_dv_translate_item_eth(void *key, const struct rte_flow_item *item,
9305 : : int inner, uint32_t group, uint32_t key_type)
9306 : : {
9307 : 0 : const struct rte_flow_item_eth *eth_vv = item->spec;
9308 : : const struct rte_flow_item_eth *eth_m;
9309 : : const struct rte_flow_item_eth *eth_v;
9310 : 0 : const struct rte_flow_item_eth nic_mask = {
9311 : : .hdr.dst_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
9312 : : .hdr.src_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
9313 : : .hdr.ether_type = RTE_BE16(0xffff),
9314 : : .has_vlan = 0,
9315 : : };
9316 : : void *hdrs_v;
9317 : : char *l24_v;
9318 : : unsigned int i;
9319 : :
9320 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9321 : 0 : return;
9322 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, eth_v, eth_m, &nic_mask);
# # # # ]
9323 [ # # ]: 0 : if (!eth_vv)
9324 : : eth_vv = eth_v;
9325 [ # # ]: 0 : if (inner)
9326 : 0 : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9327 : : else
9328 : : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9329 : : /* The value must be in the range of the mask. */
9330 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, dmac_47_16);
9331 [ # # ]: 0 : for (i = 0; i < sizeof(eth_m->hdr.dst_addr); ++i)
9332 : 0 : l24_v[i] = eth_m->hdr.dst_addr.addr_bytes[i] & eth_v->hdr.dst_addr.addr_bytes[i];
9333 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, smac_47_16);
9334 : : /* The value must be in the range of the mask. */
9335 [ # # ]: 0 : for (i = 0; i < sizeof(eth_m->hdr.dst_addr); ++i)
9336 : 0 : l24_v[i] = eth_m->hdr.src_addr.addr_bytes[i] & eth_v->hdr.src_addr.addr_bytes[i];
9337 : : /*
9338 : : * HW supports match on one Ethertype, the Ethertype following the last
9339 : : * VLAN tag of the packet (see PRM).
9340 : : * Set match on ethertype only if ETH header is not followed by VLAN.
9341 : : * HW is optimized for IPv4/IPv6. In such cases, avoid setting
9342 : : * ethertype, and use ip_version field instead.
9343 : : * eCPRI over Ether layer will use type value 0xAEFE.
9344 : : */
9345 [ # # ]: 0 : if (eth_m->hdr.ether_type == 0xFFFF) {
9346 : 0 : rte_be16_t type = eth_v->hdr.ether_type;
9347 : :
9348 : : /*
9349 : : * When set the matcher mask, refer to the original spec
9350 : : * value.
9351 : : */
9352 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M) {
9353 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
9354 : 0 : type = eth_vv->hdr.ether_type;
9355 : : }
9356 : : /* Set cvlan_tag mask for any single\multi\un-tagged case. */
9357 [ # # # # : 0 : switch (type) {
# ]
9358 : 0 : case RTE_BE16(RTE_ETHER_TYPE_VLAN):
9359 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
9360 : 0 : return;
9361 : 0 : case RTE_BE16(RTE_ETHER_TYPE_QINQ):
9362 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
9363 : 0 : return;
9364 : 0 : case RTE_BE16(RTE_ETHER_TYPE_IPV4):
9365 : 0 : flow_dv_set_match_ip_version(group, hdrs_v, key_type,
9366 : : 4);
9367 : 0 : return;
9368 : 0 : case RTE_BE16(RTE_ETHER_TYPE_IPV6):
9369 : 0 : flow_dv_set_match_ip_version(group, hdrs_v, key_type,
9370 : : 6);
9371 : 0 : return;
9372 : : default:
9373 : : break;
9374 : : }
9375 : : }
9376 : : /*
9377 : : * Only SW steering value should refer to the mask value.
9378 : : * Other cases are using the fake masks, just ignore the mask.
9379 : : */
9380 [ # # # # ]: 0 : if (eth_v->has_vlan && eth_m->has_vlan) {
9381 : : /*
9382 : : * Here, when also has_more_vlan field in VLAN item is
9383 : : * not set, only single-tagged packets will be matched.
9384 : : */
9385 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
9386 [ # # # # ]: 0 : if (key_type != MLX5_SET_MATCHER_HS_M && eth_vv->has_vlan)
9387 : : return;
9388 : : }
9389 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, ethertype);
9390 : 0 : *(uint16_t *)(l24_v) = eth_m->hdr.ether_type & eth_v->hdr.ether_type;
9391 : : }
9392 : :
9393 : : /**
9394 : : * Add VLAN item to the value.
9395 : : *
9396 : : * @param[in, out] key
9397 : : * Flow matcher value.
9398 : : * @param[in] item
9399 : : * Flow pattern to translate.
9400 : : * @param[in] inner
9401 : : * Item is inner pattern.
9402 : : * @param[in] wks
9403 : : * Item workspace.
9404 : : * @param[in] key_type
9405 : : * Set flow matcher mask or value.
9406 : : */
9407 : : static void
9408 : 0 : flow_dv_translate_item_vlan(void *key, const struct rte_flow_item *item,
9409 : : int inner, struct mlx5_dv_matcher_workspace *wks,
9410 : : uint32_t key_type)
9411 : : {
9412 : : const struct rte_flow_item_vlan *vlan_m;
9413 : : const struct rte_flow_item_vlan *vlan_v;
9414 : 0 : const struct rte_flow_item_vlan *vlan_vv = item->spec;
9415 : : void *hdrs_v;
9416 : : uint16_t tci_v;
9417 : :
9418 [ # # ]: 0 : if (inner) {
9419 : 0 : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9420 : : } else {
9421 : : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9422 : : /*
9423 : : * This is workaround, masks are not supported,
9424 : : * and pre-validated.
9425 : : */
9426 [ # # ]: 0 : if (vlan_vv)
9427 [ # # ]: 0 : wks->vlan_tag = rte_be_to_cpu_16(vlan_vv->hdr.vlan_tci) & 0x0fff;
9428 : : }
9429 : : /*
9430 : : * When VLAN item exists in flow, mark packet as tagged,
9431 : : * even if TCI is not specified.
9432 : : */
9433 [ # # # # ]: 0 : if (!MLX5_GET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag))
9434 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
9435 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9436 : : return;
9437 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, vlan_v, vlan_m,
# # # # ]
9438 : : &rte_flow_item_vlan_mask);
9439 [ # # ]: 0 : tci_v = rte_be_to_cpu_16(vlan_m->hdr.vlan_tci & vlan_v->hdr.vlan_tci);
9440 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_vid, tci_v);
9441 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_cfi, tci_v >> 12);
9442 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_prio, tci_v >> 13);
9443 : : /*
9444 : : * HW is optimized for IPv4/IPv6. In such cases, avoid setting
9445 : : * ethertype, and use ip_version field instead.
9446 : : */
9447 [ # # ]: 0 : if (vlan_m->hdr.eth_proto == 0xFFFF) {
9448 : 0 : rte_be16_t inner_type = vlan_v->hdr.eth_proto;
9449 : :
9450 : : /*
9451 : : * When set the matcher mask, refer to the original spec
9452 : : * value.
9453 : : */
9454 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M)
9455 : 0 : inner_type = vlan_vv->hdr.eth_proto;
9456 [ # # # # ]: 0 : switch (inner_type) {
9457 : 0 : case RTE_BE16(RTE_ETHER_TYPE_VLAN):
9458 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
9459 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_V)
9460 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v,
9461 : : cvlan_tag, 0);
9462 : 0 : return;
9463 : 0 : case RTE_BE16(RTE_ETHER_TYPE_IPV4):
9464 : 0 : flow_dv_set_match_ip_version
9465 : : (wks->group, hdrs_v, key_type, 4);
9466 : 0 : return;
9467 : 0 : case RTE_BE16(RTE_ETHER_TYPE_IPV6):
9468 : 0 : flow_dv_set_match_ip_version
9469 : : (wks->group, hdrs_v, key_type, 6);
9470 : 0 : return;
9471 : : default:
9472 : : break;
9473 : : }
9474 : : }
9475 [ # # # # ]: 0 : if (vlan_m->has_more_vlan && vlan_v->has_more_vlan) {
9476 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
9477 : : /* Only one vlan_tag bit can be set. */
9478 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_V)
9479 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 0);
9480 : 0 : return;
9481 : : }
9482 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, ethertype,
9483 : : rte_be_to_cpu_16(vlan_m->hdr.eth_proto & vlan_v->hdr.eth_proto));
9484 : : }
9485 : :
9486 : : /**
9487 : : * Add IPV4 item to the value.
9488 : : *
9489 : : * @param[in, out] key
9490 : : * Flow matcher value.
9491 : : * @param[in] item
9492 : : * Flow pattern to translate.
9493 : : * @param[in] inner
9494 : : * Item is inner pattern.
9495 : : * @param[in] group
9496 : : * The group to insert the rule.
9497 : : * @param[in] key_type
9498 : : * Set flow matcher mask or value.
9499 : : */
9500 : : static void
9501 : 0 : flow_dv_translate_item_ipv4(void *key, const struct rte_flow_item *item,
9502 : : int inner, uint32_t group, uint32_t key_type)
9503 : : {
9504 : : const struct rte_flow_item_ipv4 *ipv4_m;
9505 : : const struct rte_flow_item_ipv4 *ipv4_v;
9506 : 0 : const struct rte_flow_item_ipv4 nic_mask = {
9507 : : .hdr = {
9508 : : .src_addr = RTE_BE32(0xffffffff),
9509 : : .dst_addr = RTE_BE32(0xffffffff),
9510 : : .type_of_service = 0xff,
9511 : : .next_proto_id = 0xff,
9512 : : .time_to_live = 0xff,
9513 : : },
9514 : : };
9515 : : void *headers_v;
9516 : : char *l24_v;
9517 : : uint8_t tos;
9518 : :
9519 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9520 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9521 : 0 : flow_dv_set_match_ip_version(group, headers_v, key_type, 4);
9522 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9523 : 0 : return;
9524 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, ipv4_v, ipv4_m, &nic_mask);
# # # # ]
9525 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
9526 : : dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
9527 : 0 : *(uint32_t *)l24_v = ipv4_m->hdr.dst_addr & ipv4_v->hdr.dst_addr;
9528 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
9529 : : src_ipv4_src_ipv6.ipv4_layout.ipv4);
9530 : 0 : *(uint32_t *)l24_v = ipv4_m->hdr.src_addr & ipv4_v->hdr.src_addr;
9531 : 0 : tos = ipv4_m->hdr.type_of_service & ipv4_v->hdr.type_of_service;
9532 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ipv4_ihl,
9533 : : ipv4_v->hdr.ihl & ipv4_m->hdr.ihl);
9534 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M)
9535 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn,
9536 : : ipv4_v->hdr.type_of_service);
9537 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, tos);
9538 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, tos >> 2);
9539 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
9540 : : ipv4_v->hdr.next_proto_id & ipv4_m->hdr.next_proto_id);
9541 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
9542 : : ipv4_v->hdr.time_to_live & ipv4_m->hdr.time_to_live);
9543 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
9544 : : !!(ipv4_v->hdr.fragment_offset & ipv4_m->hdr.fragment_offset));
9545 : : }
9546 : :
9547 : : /**
9548 : : * Add IPV6 item to the value.
9549 : : *
9550 : : * @param[in, out] key
9551 : : * Flow matcher value.
9552 : : * @param[in] item
9553 : : * Flow pattern to translate.
9554 : : * @param[in] inner
9555 : : * Item is inner pattern.
9556 : : * @param[in] group
9557 : : * The group to insert the rule.
9558 : : * @param[in] key_type
9559 : : * Set flow matcher mask or value.
9560 : : */
9561 : : static void
9562 : 0 : flow_dv_translate_item_ipv6(void *key, const struct rte_flow_item *item,
9563 : : int inner, uint32_t group, uint32_t key_type)
9564 : : {
9565 : : const struct rte_flow_item_ipv6 *ipv6_m;
9566 : : const struct rte_flow_item_ipv6 *ipv6_v;
9567 : 0 : const struct rte_flow_item_ipv6 nic_mask = {
9568 : : .hdr = {
9569 : : .src_addr = RTE_IPV6_MASK_FULL,
9570 : : .dst_addr = RTE_IPV6_MASK_FULL,
9571 : : .vtc_flow = RTE_BE32(0xffffffff),
9572 : : .proto = 0xff,
9573 : : .hop_limits = 0xff,
9574 : : },
9575 : : };
9576 : : void *headers_v;
9577 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9578 : : char *l24_v;
9579 : : uint32_t vtc_v;
9580 : : int i;
9581 : : int size;
9582 : :
9583 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9584 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9585 : 0 : flow_dv_set_match_ip_version(group, headers_v, key_type, 6);
9586 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9587 : 0 : return;
9588 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, ipv6_v, ipv6_m, &nic_mask);
# # # # ]
9589 : : size = sizeof(ipv6_m->hdr.dst_addr);
9590 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
9591 : : dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
9592 [ # # ]: 0 : for (i = 0; i < size; ++i)
9593 : 0 : l24_v[i] = ipv6_m->hdr.dst_addr.a[i] & ipv6_v->hdr.dst_addr.a[i];
9594 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
9595 : : src_ipv4_src_ipv6.ipv6_layout.ipv6);
9596 [ # # ]: 0 : for (i = 0; i < size; ++i)
9597 : 0 : l24_v[i] = ipv6_m->hdr.src_addr.a[i] & ipv6_v->hdr.src_addr.a[i];
9598 : : /* TOS. */
9599 [ # # ]: 0 : vtc_v = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow & ipv6_v->hdr.vtc_flow);
9600 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, vtc_v >> 20);
9601 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, vtc_v >> 22);
9602 : : /* Label. */
9603 [ # # ]: 0 : if (inner)
9604 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, inner_ipv6_flow_label,
9605 : : vtc_v);
9606 : : else
9607 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, outer_ipv6_flow_label,
9608 : : vtc_v);
9609 : : /* Protocol. */
9610 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
9611 : : ipv6_v->hdr.proto & ipv6_m->hdr.proto);
9612 : : /* Hop limit. */
9613 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
9614 : : ipv6_v->hdr.hop_limits & ipv6_m->hdr.hop_limits);
9615 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
9616 : : !!(ipv6_v->has_frag_ext & ipv6_m->has_frag_ext));
9617 : : }
9618 : :
9619 : : /**
9620 : : * Add IPV6 fragment extension item to the value.
9621 : : *
9622 : : * @param[in, out] key
9623 : : * Flow matcher value.
9624 : : * @param[in] item
9625 : : * Flow pattern to translate.
9626 : : * @param[in] inner
9627 : : * Item is inner pattern.
9628 : : * @param[in] key_type
9629 : : * Set flow matcher mask or value.
9630 : : */
9631 : : static void
9632 : 0 : flow_dv_translate_item_ipv6_frag_ext(void *key,
9633 : : const struct rte_flow_item *item,
9634 : : int inner, uint32_t key_type)
9635 : : {
9636 : : const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_m;
9637 : : const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_v;
9638 : 0 : const struct rte_flow_item_ipv6_frag_ext nic_mask = {
9639 : : .hdr = {
9640 : : .next_header = 0xff,
9641 : : .frag_data = RTE_BE16(0xffff),
9642 : : },
9643 : : };
9644 : : void *headers_v;
9645 : :
9646 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9647 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9648 : : /* IPv6 fragment extension item exists, so packet is IP fragment. */
9649 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag, 1);
9650 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9651 : 0 : return;
9652 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, ipv6_frag_ext_v,
# # # # ]
9653 : : ipv6_frag_ext_m, &nic_mask);
9654 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
9655 : : ipv6_frag_ext_v->hdr.next_header &
9656 : : ipv6_frag_ext_m->hdr.next_header);
9657 : : }
9658 : :
9659 : : /**
9660 : : * Add TCP item to the value.
9661 : : *
9662 : : * @param[in, out] key
9663 : : * Flow matcher value.
9664 : : * @param[in] item
9665 : : * Flow pattern to translate.
9666 : : * @param[in] inner
9667 : : * Item is inner pattern.
9668 : : * @param[in] key_type
9669 : : * Set flow matcher mask or value.
9670 : : */
9671 : : static void
9672 : 0 : flow_dv_translate_item_tcp(void *key, const struct rte_flow_item *item,
9673 : : int inner, uint32_t key_type)
9674 : : {
9675 : : const struct rte_flow_item_tcp *tcp_m;
9676 : : const struct rte_flow_item_tcp *tcp_v;
9677 : : void *headers_v;
9678 : :
9679 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9680 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9681 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9682 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9683 : : ip_protocol, 0xff);
9684 : : else
9685 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9686 : : ip_protocol, IPPROTO_TCP);
9687 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9688 : : return;
9689 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, tcp_v, tcp_m,
# # # # ]
9690 : : &rte_flow_item_tcp_mask);
9691 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_sport,
9692 : : rte_be_to_cpu_16(tcp_v->hdr.src_port & tcp_m->hdr.src_port));
9693 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_dport,
9694 : : rte_be_to_cpu_16(tcp_v->hdr.dst_port & tcp_m->hdr.dst_port));
9695 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_flags,
9696 : : tcp_v->hdr.tcp_flags & tcp_m->hdr.tcp_flags);
9697 : : }
9698 : :
9699 : : /**
9700 : : * Add ESP item to the value.
9701 : : *
9702 : : * @param[in, out] key
9703 : : * Flow matcher value.
9704 : : * @param[in] item
9705 : : * Flow pattern to translate.
9706 : : * @param[in] inner
9707 : : * Item is inner pattern.
9708 : : * @param[in] key_type
9709 : : * Set flow matcher mask or value.
9710 : : */
9711 : : static void
9712 : 0 : flow_dv_translate_item_esp(void *key, const struct rte_flow_item *item,
9713 : : int inner, uint32_t key_type)
9714 : : {
9715 : : const struct rte_flow_item_esp *esp_m;
9716 : : const struct rte_flow_item_esp *esp_v;
9717 : : void *headers_v;
9718 : : char *spi_v;
9719 : :
9720 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9721 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9722 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9723 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9724 : : ip_protocol, 0xff);
9725 : : else
9726 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9727 : : ip_protocol, IPPROTO_ESP);
9728 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9729 : : return;
9730 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, esp_v, esp_m,
# # # # ]
9731 : : &rte_flow_item_esp_mask);
9732 : : headers_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9733 : : spi_v = inner ? MLX5_ADDR_OF(fte_match_set_misc, headers_v,
9734 [ # # ]: 0 : inner_esp_spi) : MLX5_ADDR_OF(fte_match_set_misc
9735 : : , headers_v, outer_esp_spi);
9736 : 0 : *(uint32_t *)spi_v = esp_m->hdr.spi & esp_v->hdr.spi;
9737 : : }
9738 : :
9739 : : /**
9740 : : * Add UDP item to the value.
9741 : : *
9742 : : * @param[in, out] key
9743 : : * Flow matcher value.
9744 : : * @param[in] item
9745 : : * Flow pattern to translate.
9746 : : * @param[in] inner
9747 : : * Item is inner pattern.
9748 : : * @param[in] key_type
9749 : : * Set flow matcher mask or value.
9750 : : */
9751 : : static void
9752 : 0 : flow_dv_translate_item_udp(void *key, const struct rte_flow_item *item,
9753 : : int inner, struct mlx5_dv_matcher_workspace *wks,
9754 : : uint32_t key_type)
9755 : : {
9756 : : const struct rte_flow_item_udp *udp_m;
9757 : : const struct rte_flow_item_udp *udp_v;
9758 : : void *headers_v;
9759 : :
9760 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9761 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9762 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9763 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9764 : : ip_protocol, 0xff);
9765 : : else
9766 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9767 : : ip_protocol, IPPROTO_UDP);
9768 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9769 : : return;
9770 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, udp_v, udp_m,
# # # # ]
9771 : : &rte_flow_item_udp_mask);
9772 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_sport,
9773 : : rte_be_to_cpu_16(udp_v->hdr.src_port & udp_m->hdr.src_port));
9774 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
9775 : : rte_be_to_cpu_16(udp_v->hdr.dst_port & udp_m->hdr.dst_port));
9776 : : /* Force get UDP dport in case to be used in VXLAN translate. */
9777 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_SW) {
9778 : 0 : udp_v = item->spec;
9779 [ # # ]: 0 : wks->udp_dport = rte_be_to_cpu_16(udp_v->hdr.dst_port &
9780 : : udp_m->hdr.dst_port);
9781 : : }
9782 : : }
9783 : :
9784 : : /**
9785 : : * Add GRE optional Key item to the value.
9786 : : *
9787 : : * @param[in, out] key
9788 : : * Flow matcher value.
9789 : : * @param[in] item
9790 : : * Flow pattern to translate.
9791 : : * @param[in] inner
9792 : : * Item is inner pattern.
9793 : : */
9794 : : static void
9795 : 0 : flow_dv_translate_item_gre_key(void *key, const struct rte_flow_item *item,
9796 : : uint32_t key_type)
9797 : : {
9798 : : const rte_be32_t *key_m;
9799 : : const rte_be32_t *key_v;
9800 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9801 : 0 : rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
9802 : :
9803 : : /* GRE K bit must be on and should already be validated */
9804 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_k_present, 1);
9805 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9806 : 0 : return;
9807 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, key_v, key_m,
# # # # ]
9808 : : &gre_key_default_mask);
9809 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_key_h,
9810 : : rte_be_to_cpu_32((*key_v) & (*key_m)) >> 8);
9811 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_key_l,
9812 : : rte_be_to_cpu_32((*key_v) & (*key_m)) & 0xFF);
9813 : : }
9814 : :
9815 : : /**
9816 : : * Add GRE item to the value.
9817 : : *
9818 : : * @param[in, out] key
9819 : : * Flow matcher value.
9820 : : * @param[in] item
9821 : : * Flow pattern to translate.
9822 : : * @param[in] pattern_flags
9823 : : * Accumulated pattern flags.
9824 : : * @param[in] key_type
9825 : : * Set flow matcher mask or value.
9826 : : */
9827 : : static void
9828 : 0 : flow_dv_translate_item_gre(void *key, const struct rte_flow_item *item,
9829 : : uint64_t pattern_flags, uint32_t key_type)
9830 : : {
9831 : : static const struct rte_flow_item_gre empty_gre = {0,};
9832 : 0 : const struct rte_flow_item_gre *gre_m = item->mask;
9833 : 0 : const struct rte_flow_item_gre *gre_v = item->spec;
9834 : : void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9835 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9836 : : struct {
9837 : : union {
9838 : : __extension__
9839 : : struct {
9840 : : uint16_t version:3;
9841 : : uint16_t rsvd0:9;
9842 : : uint16_t s_present:1;
9843 : : uint16_t k_present:1;
9844 : : uint16_t rsvd_bit1:1;
9845 : : uint16_t c_present:1;
9846 : : };
9847 : : uint16_t value;
9848 : : };
9849 : : } gre_crks_rsvd0_ver_m, gre_crks_rsvd0_ver_v;
9850 : : uint16_t protocol_m, protocol_v;
9851 : :
9852 : : /* Common logic to SWS/HWS */
9853 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9854 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, 0xff);
9855 : : else
9856 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
9857 : : IPPROTO_GRE);
9858 : : /* HWS mask logic only */
9859 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_HS_M) {
9860 [ # # ]: 0 : if (!gre_m)
9861 : : gre_m = &empty_gre;
9862 : : gre_v = gre_m;
9863 [ # # ]: 0 : } else if (!gre_v) {
9864 : : gre_v = &empty_gre;
9865 : : gre_m = &empty_gre;
9866 [ # # ]: 0 : } else if (!gre_m) {
9867 : : gre_m = &rte_flow_item_gre_mask;
9868 : : }
9869 : : /* SWS logic only */
9870 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_SW_M)
9871 : : gre_v = gre_m;
9872 [ # # ]: 0 : gre_crks_rsvd0_ver_m.value = rte_be_to_cpu_16(gre_m->c_rsvd0_ver);
9873 [ # # ]: 0 : gre_crks_rsvd0_ver_v.value = rte_be_to_cpu_16(gre_v->c_rsvd0_ver);
9874 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_c_present,
9875 : : gre_crks_rsvd0_ver_v.c_present &
9876 : : gre_crks_rsvd0_ver_m.c_present);
9877 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_k_present,
9878 : : gre_crks_rsvd0_ver_v.k_present &
9879 : : gre_crks_rsvd0_ver_m.k_present);
9880 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_s_present,
9881 : : gre_crks_rsvd0_ver_v.s_present &
9882 : : gre_crks_rsvd0_ver_m.s_present);
9883 [ # # ]: 0 : protocol_m = rte_be_to_cpu_16(gre_m->protocol);
9884 [ # # ]: 0 : protocol_v = rte_be_to_cpu_16(gre_v->protocol);
9885 [ # # ]: 0 : if (!protocol_m) {
9886 : : /* Force next protocol to prevent matchers duplication */
9887 : : protocol_v = mlx5_translate_tunnel_etypes(pattern_flags);
9888 : : if (protocol_v)
9889 : : protocol_m = 0xFFFF;
9890 : : /* Restore the value to mask in mask case. */
9891 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9892 : : protocol_v = protocol_m;
9893 : : }
9894 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
9895 : : protocol_m & protocol_v);
9896 : 0 : }
9897 : :
9898 : : /**
9899 : : * Add GRE optional items to the value.
9900 : : *
9901 : : * @param[in, out] key
9902 : : * Flow matcher value.
9903 : : * @param[in] item
9904 : : * Flow pattern to translate.
9905 : : * @param[in] gre_item
9906 : : * Pointer to gre_item.
9907 : : * @param[in] pattern_flags
9908 : : * Accumulated pattern flags.
9909 : : * @param[in] key_type
9910 : : * Set flow matcher mask or value.
9911 : : */
9912 : : static void
9913 : 0 : flow_dv_translate_item_gre_option(void *key,
9914 : : const struct rte_flow_item *item,
9915 : : const struct rte_flow_item *gre_item,
9916 : : uint64_t pattern_flags, uint32_t key_type)
9917 : : {
9918 : : void *misc5_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_5);
9919 : 0 : const struct rte_flow_item_gre_opt *option_m = item->mask;
9920 : 0 : const struct rte_flow_item_gre_opt *option_v = item->spec;
9921 : 0 : const struct rte_flow_item_gre *gre_m = gre_item->mask;
9922 : 0 : const struct rte_flow_item_gre *gre_v = gre_item->spec;
9923 : : static const struct rte_flow_item_gre empty_gre = {0};
9924 : : struct rte_flow_item gre_key_item;
9925 : : uint16_t c_rsvd0_ver_m, c_rsvd0_ver_v;
9926 : : uint16_t protocol_m, protocol_v;
9927 : :
9928 : : /*
9929 : : * If only match key field, keep using misc for matching.
9930 : : * If need to match checksum or sequence, using misc5 and do
9931 : : * not need using misc.
9932 : : */
9933 [ # # ]: 0 : if (!(option_m->sequence.sequence ||
9934 [ # # ]: 0 : option_m->checksum_rsvd.checksum)) {
9935 : 0 : flow_dv_translate_item_gre(key, gre_item, pattern_flags, key_type);
9936 : 0 : gre_key_item.spec = &option_v->key.key;
9937 : 0 : gre_key_item.mask = &option_m->key.key;
9938 : 0 : flow_dv_translate_item_gre_key(key, &gre_key_item, key_type);
9939 : 0 : return;
9940 : : }
9941 [ # # ]: 0 : if (!gre_v) {
9942 : : gre_v = &empty_gre;
9943 : : gre_m = &empty_gre;
9944 : : } else {
9945 [ # # ]: 0 : if (!gre_m)
9946 : : gre_m = &rte_flow_item_gre_mask;
9947 : : }
9948 : 0 : protocol_v = gre_v->protocol;
9949 : 0 : protocol_m = gre_m->protocol;
9950 [ # # ]: 0 : if (!protocol_m) {
9951 : : /* Force next protocol to prevent matchers duplication */
9952 : : uint16_t ether_type =
9953 : : mlx5_translate_tunnel_etypes(pattern_flags);
9954 : : if (ether_type) {
9955 [ # # ]: 0 : protocol_v = rte_be_to_cpu_16(ether_type);
9956 : : protocol_m = UINT16_MAX;
9957 : : }
9958 : : }
9959 : 0 : c_rsvd0_ver_v = gre_v->c_rsvd0_ver;
9960 : 0 : c_rsvd0_ver_m = gre_m->c_rsvd0_ver;
9961 [ # # ]: 0 : if (option_m->sequence.sequence) {
9962 : 0 : c_rsvd0_ver_v |= RTE_BE16(0x1000);
9963 : 0 : c_rsvd0_ver_m |= RTE_BE16(0x1000);
9964 : : }
9965 [ # # ]: 0 : if (option_m->key.key) {
9966 : 0 : c_rsvd0_ver_v |= RTE_BE16(0x2000);
9967 : 0 : c_rsvd0_ver_m |= RTE_BE16(0x2000);
9968 : : }
9969 [ # # ]: 0 : if (option_m->checksum_rsvd.checksum) {
9970 : 0 : c_rsvd0_ver_v |= RTE_BE16(0x8000);
9971 : 0 : c_rsvd0_ver_m |= RTE_BE16(0x8000);
9972 : : }
9973 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
9974 : : c_rsvd0_ver_v = c_rsvd0_ver_m;
9975 : : protocol_v = protocol_m;
9976 : : option_v = option_m;
9977 : : }
9978 : : /*
9979 : : * Hardware parses GRE optional field into the fixed location,
9980 : : * do not need to adjust the tunnel dword indices.
9981 : : */
9982 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_0,
9983 : : rte_be_to_cpu_32((c_rsvd0_ver_v | protocol_v << 16) &
9984 : : (c_rsvd0_ver_m | protocol_m << 16)));
9985 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_1,
9986 : : rte_be_to_cpu_32(option_v->checksum_rsvd.checksum &
9987 : : option_m->checksum_rsvd.checksum));
9988 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_2,
9989 : : rte_be_to_cpu_32(option_v->key.key & option_m->key.key));
9990 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_3,
9991 : : rte_be_to_cpu_32(option_v->sequence.sequence &
9992 : : option_m->sequence.sequence));
9993 : : }
9994 : :
9995 : : /**
9996 : : * Add NVGRE item to matcher and to the value.
9997 : : *
9998 : : * @param[in, out] key
9999 : : * Flow matcher value.
10000 : : * @param[in] item
10001 : : * Flow pattern to translate.
10002 : : * @param[in] pattern_flags
10003 : : * Accumulated pattern flags.
10004 : : * @param[in] key_type
10005 : : * Set flow matcher mask or value.
10006 : : */
10007 : : static void
10008 : 0 : flow_dv_translate_item_nvgre(void *key, const struct rte_flow_item *item,
10009 : : unsigned long pattern_flags, uint32_t key_type)
10010 : : {
10011 : : const struct rte_flow_item_nvgre *nvgre_m;
10012 : : const struct rte_flow_item_nvgre *nvgre_v;
10013 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10014 : : const char *tni_flow_id_m;
10015 : : const char *tni_flow_id_v;
10016 : : char *gre_key_v;
10017 : : int size;
10018 : : int i;
10019 : :
10020 : : /* For NVGRE, GRE header fields must be set with defined values. */
10021 : 0 : const struct rte_flow_item_gre gre_spec = {
10022 : : .c_rsvd0_ver = RTE_BE16(0x2000),
10023 : : .protocol = RTE_BE16(RTE_ETHER_TYPE_TEB)
10024 : : };
10025 : 0 : const struct rte_flow_item_gre gre_mask = {
10026 : : .c_rsvd0_ver = RTE_BE16(0xB000),
10027 : : .protocol = RTE_BE16(UINT16_MAX),
10028 : : };
10029 : 0 : const struct rte_flow_item gre_item = {
10030 : : .spec = &gre_spec,
10031 : : .mask = &gre_mask,
10032 : : .last = NULL,
10033 : : };
10034 : 0 : flow_dv_translate_item_gre(key, &gre_item, pattern_flags, key_type);
10035 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10036 : 0 : return;
10037 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, nvgre_v, nvgre_m,
# # # # ]
10038 : : &rte_flow_item_nvgre_mask);
10039 : 0 : tni_flow_id_m = (const char *)nvgre_m->tni;
10040 : 0 : tni_flow_id_v = (const char *)nvgre_v->tni;
10041 : : size = sizeof(nvgre_m->tni) + sizeof(nvgre_m->flow_id);
10042 : 0 : gre_key_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, gre_key_h);
10043 [ # # ]: 0 : for (i = 0; i < size; ++i)
10044 : 0 : gre_key_v[i] = tni_flow_id_m[i] & tni_flow_id_v[i];
10045 : : }
10046 : :
10047 : : /**
10048 : : * Add VXLAN item to the value.
10049 : : *
10050 : : * @param[in] dev
10051 : : * Pointer to the Ethernet device structure.
10052 : : * @param[in] attr
10053 : : * Flow rule attributes.
10054 : : * @param[in, out] key
10055 : : * Flow matcher value.
10056 : : * @param[in] item
10057 : : * Flow pattern to translate.
10058 : : * @param[in] inner
10059 : : * Item is inner pattern.
10060 : : * @param[in] wks
10061 : : * Matcher workspace.
10062 : : * @param[in] key_type
10063 : : * Set flow matcher mask or value.
10064 : : */
10065 : : static void
10066 : 0 : flow_dv_translate_item_vxlan(struct rte_eth_dev *dev,
10067 : : const struct rte_flow_attr *attr,
10068 : : void *key, const struct rte_flow_item *item,
10069 : : int inner, struct mlx5_dv_matcher_workspace *wks,
10070 : : uint32_t key_type)
10071 : : {
10072 : : const struct rte_flow_item_vxlan *vxlan_m;
10073 : : const struct rte_flow_item_vxlan *vxlan_v;
10074 : : void *headers_v;
10075 : : void *misc_v;
10076 : : void *misc5_v;
10077 : : uint32_t tunnel_v;
10078 : : char *vni_v;
10079 : : uint16_t dport;
10080 : : int size;
10081 : : int i;
10082 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10083 : 0 : const struct rte_flow_item_vxlan nic_mask = {
10084 : : .hdr.vni = { 0xff, 0xff, 0xff },
10085 : : .hdr.rsvd1 = 0xff,
10086 : : };
10087 : :
10088 : : misc5_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_5);
10089 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
10090 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10091 [ # # ]: 0 : dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
10092 : : MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
10093 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
10094 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10095 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
10096 : : udp_dport, 0xFFFF);
10097 : : else
10098 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
10099 : : udp_dport, dport);
10100 : : }
10101 : : /*
10102 : : * Read the UDP dport to check if the value satisfies the VXLAN
10103 : : * matching with MISC5 for CX5.
10104 : : */
10105 [ # # ]: 0 : if (wks->udp_dport)
10106 : : dport = wks->udp_dport;
10107 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10108 : 0 : return;
10109 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, vxlan_v, vxlan_m, &nic_mask);
# # # # ]
10110 : : if ((item->mask == &nic_mask) &&
10111 : : ((!attr->group && !(attr->transfer && priv->fdb_def_rule) &&
10112 : : !priv->sh->tunnel_header_0_1) ||
10113 : : ((attr->group || (attr->transfer && priv->fdb_def_rule)) &&
10114 : : !priv->sh->misc5_cap)))
10115 : : vxlan_m = &rte_flow_item_vxlan_mask;
10116 [ # # ]: 0 : if ((priv->sh->steering_format_version ==
10117 [ # # ]: 0 : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5 &&
10118 : 0 : dport != MLX5_UDP_PORT_VXLAN) ||
10119 [ # # # # : 0 : (!attr->group && !(attr->transfer && priv->fdb_def_rule)) ||
# # # # ]
10120 [ # # # # ]: 0 : ((attr->group || (attr->transfer && priv->fdb_def_rule)) &&
10121 [ # # ]: 0 : !priv->sh->misc5_cap)) {
10122 : : misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10123 : : size = sizeof(vxlan_m->hdr.vni);
10124 : 0 : vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, vxlan_vni);
10125 [ # # ]: 0 : for (i = 0; i < size; ++i)
10126 : 0 : vni_v[i] = vxlan_m->hdr.vni[i] & vxlan_v->hdr.vni[i];
10127 : : return;
10128 : : }
10129 : 0 : tunnel_v = (vxlan_v->hdr.vni[0] & vxlan_m->hdr.vni[0]) |
10130 : 0 : (vxlan_v->hdr.vni[1] & vxlan_m->hdr.vni[1]) << 8 |
10131 : 0 : (vxlan_v->hdr.vni[2] & vxlan_m->hdr.vni[2]) << 16;
10132 : 0 : tunnel_v |= (vxlan_v->hdr.rsvd1 & vxlan_m->hdr.rsvd1) << 24;
10133 [ # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_1, RTE_BE32(tunnel_v));
10134 : : }
10135 : :
10136 : : /**
10137 : : * Add VXLAN-GPE item to the value.
10138 : : *
10139 : : * @param[in, out] key
10140 : : * Flow matcher value.
10141 : : * @param[in] item
10142 : : * Flow pattern to translate.
10143 : : * @param[in] pattern_flags
10144 : : * Item pattern flags.
10145 : : * @param[in] key_type
10146 : : * Set flow matcher mask or value.
10147 : : */
10148 : :
10149 : : static void
10150 : 0 : flow_dv_translate_item_vxlan_gpe(void *key, const struct rte_flow_item *item,
10151 : : const uint64_t pattern_flags,
10152 : : uint32_t key_type)
10153 : : {
10154 : : static const struct rte_flow_item_vxlan_gpe dummy_vxlan_gpe_hdr = {{{0}}};
10155 : 0 : const struct rte_flow_item_vxlan_gpe *vxlan_m = item->mask;
10156 : 0 : const struct rte_flow_item_vxlan_gpe *vxlan_v = item->spec;
10157 : : /* The item was validated to be on the outer side */
10158 : : void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10159 : : void *misc_v =
10160 : : MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
10161 : 0 : char *vni_v =
10162 : : MLX5_ADDR_OF(fte_match_set_misc3, misc_v, outer_vxlan_gpe_vni);
10163 : : int i, size = sizeof(vxlan_m->hdr.vni);
10164 : : uint8_t flags_m = 0xff;
10165 : : uint8_t flags_v = 0xc;
10166 : : uint8_t m_protocol, v_protocol;
10167 : :
10168 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
10169 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10170 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
10171 : : 0xFFFF);
10172 : : else
10173 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
10174 : : MLX5_UDP_PORT_VXLAN_GPE);
10175 : : }
10176 [ # # ]: 0 : if (!vxlan_v) {
10177 : : vxlan_v = &dummy_vxlan_gpe_hdr;
10178 : : vxlan_m = &dummy_vxlan_gpe_hdr;
10179 : : } else {
10180 [ # # ]: 0 : if (!vxlan_m)
10181 : : vxlan_m = &rte_flow_item_vxlan_gpe_mask;
10182 : : }
10183 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10184 : : vxlan_v = vxlan_m;
10185 [ # # ]: 0 : else if (key_type == MLX5_SET_MATCHER_HS_V)
10186 : : vxlan_m = vxlan_v;
10187 [ # # ]: 0 : if (vxlan_m->hdr.flags) {
10188 : : flags_m = vxlan_m->hdr.flags;
10189 : 0 : flags_v = vxlan_v->hdr.flags;
10190 : : }
10191 : 0 : m_protocol = vxlan_m->hdr.protocol;
10192 : 0 : v_protocol = vxlan_v->hdr.protocol;
10193 [ # # ]: 0 : if (!m_protocol) {
10194 : : /* Force next protocol to ensure next headers parsing. */
10195 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_NSH)
10196 : : v_protocol = RTE_VXLAN_GPE_TYPE_NSH;
10197 [ # # ]: 0 : else if (pattern_flags & MLX5_FLOW_LAYER_INNER_L2)
10198 : : v_protocol = RTE_VXLAN_GPE_TYPE_ETH;
10199 [ # # ]: 0 : else if (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV4)
10200 : : v_protocol = RTE_VXLAN_GPE_TYPE_IPV4;
10201 [ # # ]: 0 : else if (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV6)
10202 : : v_protocol = RTE_VXLAN_GPE_TYPE_IPV6;
10203 [ # # ]: 0 : if (v_protocol)
10204 : : m_protocol = 0xFF;
10205 : : /* Restore the value to mask in mask case. */
10206 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10207 : : v_protocol = m_protocol;
10208 : : }
10209 : : /*
10210 : : * If only match flags/protocol/vni field, keep using misc3 for matching.
10211 : : * If need to match rsvd0 or rsvd1, using misc5 and do not need using misc3.
10212 : : */
10213 [ # # # # : 0 : if (!(vxlan_m->hdr.rsvd0[0] || vxlan_m->hdr.rsvd0[1] || vxlan_m->hdr.rsvd1)) {
# # ]
10214 [ # # ]: 0 : for (i = 0; i < size; ++i)
10215 : 0 : vni_v[i] = vxlan_m->hdr.vni[i] & vxlan_v->hdr.vni[i];
10216 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc_v, outer_vxlan_gpe_flags,
10217 : : flags_m & flags_v);
10218 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc_v,
10219 : : outer_vxlan_gpe_next_protocol, m_protocol & v_protocol);
10220 : : } else {
10221 : : uint32_t tunnel_v;
10222 : : void *misc5_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_5);
10223 : :
10224 : 0 : tunnel_v = (flags_m & flags_v) << 24 |
10225 : 0 : (vxlan_v->hdr.rsvd0[0] & vxlan_m->hdr.rsvd0[0]) << 16 |
10226 : 0 : (vxlan_v->hdr.rsvd0[1] & vxlan_m->hdr.rsvd0[1]) << 8 |
10227 : 0 : (m_protocol & v_protocol);
10228 [ # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_0, tunnel_v);
10229 : 0 : tunnel_v = (vxlan_v->hdr.vni[0] & vxlan_m->hdr.vni[0]) << 24 |
10230 : 0 : (vxlan_v->hdr.vni[1] & vxlan_m->hdr.vni[1]) << 16 |
10231 : 0 : (vxlan_v->hdr.vni[2] & vxlan_m->hdr.vni[2]) << 8 |
10232 : 0 : (vxlan_v->hdr.rsvd1 & vxlan_m->hdr.rsvd1);
10233 [ # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_1, tunnel_v);
10234 : : }
10235 : 0 : }
10236 : :
10237 : : /**
10238 : : * Add Geneve item to the value.
10239 : : *
10240 : : * @param[in, out] key
10241 : : * Flow matcher value.
10242 : : * @param[in] item
10243 : : * Flow pattern to translate.
10244 : : * @param[in] pattern_flags
10245 : : * Item pattern flags.
10246 : : * @param[in] key_type
10247 : : * Set flow matcher mask or value.
10248 : : */
10249 : :
10250 : : static void
10251 : 0 : flow_dv_translate_item_geneve(void *key, const struct rte_flow_item *item,
10252 : : uint64_t pattern_flags, uint32_t key_type)
10253 : : {
10254 : : static const struct rte_flow_item_geneve empty_geneve = {0,};
10255 : 0 : const struct rte_flow_item_geneve *geneve_m = item->mask;
10256 : 0 : const struct rte_flow_item_geneve *geneve_v = item->spec;
10257 : : /* GENEVE flow item validation allows single tunnel item */
10258 : : void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10259 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10260 : : uint16_t gbhdr_m;
10261 : : uint16_t gbhdr_v;
10262 : 0 : char *vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, geneve_vni);
10263 : : size_t size = sizeof(geneve_m->vni), i;
10264 : : uint16_t protocol_m, protocol_v;
10265 : :
10266 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
10267 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10268 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
10269 : : 0xFFFF);
10270 : : else
10271 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
10272 : : MLX5_UDP_PORT_GENEVE);
10273 : : }
10274 [ # # ]: 0 : if (!geneve_v) {
10275 : : geneve_v = &empty_geneve;
10276 : : geneve_m = &empty_geneve;
10277 : : } else {
10278 [ # # ]: 0 : if (!geneve_m)
10279 : : geneve_m = &rte_flow_item_geneve_mask;
10280 : : }
10281 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10282 : : geneve_v = geneve_m;
10283 [ # # ]: 0 : else if (key_type == MLX5_SET_MATCHER_HS_V)
10284 : : geneve_m = geneve_v;
10285 [ # # ]: 0 : for (i = 0; i < size; ++i)
10286 : 0 : vni_v[i] = geneve_m->vni[i] & geneve_v->vni[i];
10287 [ # # ]: 0 : gbhdr_m = rte_be_to_cpu_16(geneve_m->ver_opt_len_o_c_rsvd0);
10288 [ # # ]: 0 : gbhdr_v = rte_be_to_cpu_16(geneve_v->ver_opt_len_o_c_rsvd0);
10289 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, geneve_oam,
10290 : : MLX5_GENEVE_OAMF_VAL(gbhdr_v) & MLX5_GENEVE_OAMF_VAL(gbhdr_m));
10291 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
10292 : : MLX5_GENEVE_OPTLEN_VAL(gbhdr_v) &
10293 : : MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
10294 [ # # ]: 0 : protocol_m = rte_be_to_cpu_16(geneve_m->protocol);
10295 [ # # ]: 0 : protocol_v = rte_be_to_cpu_16(geneve_v->protocol);
10296 [ # # ]: 0 : if (!protocol_m) {
10297 : : /* Force next protocol to prevent matchers duplication */
10298 : : protocol_v = mlx5_translate_tunnel_etypes(pattern_flags);
10299 : : if (protocol_v)
10300 : : protocol_m = 0xFFFF;
10301 : : /* Restore the value to mask in mask case. */
10302 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10303 : : protocol_v = protocol_m;
10304 : : }
10305 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, geneve_protocol_type,
10306 : : protocol_m & protocol_v);
10307 : 0 : }
10308 : :
10309 : : /**
10310 : : * Create Geneve TLV option resource.
10311 : : *
10312 : : * @param[in, out] dev
10313 : : * Pointer to rte_eth_dev structure.
10314 : : * @param[in] item
10315 : : * Flow pattern to translate.
10316 : : * @param[out] error
10317 : : * pointer to error structure.
10318 : : *
10319 : : * @return
10320 : : * 0 on success otherwise -errno and errno is set.
10321 : : */
10322 : : static int
10323 : 0 : flow_dev_geneve_tlv_option_resource_register(struct rte_eth_dev *dev,
10324 : : const struct rte_flow_item *item,
10325 : : struct rte_flow_error *error)
10326 : : {
10327 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10328 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
10329 : 0 : struct mlx5_geneve_tlv_option_resource *geneve_opt_resource =
10330 : : sh->geneve_tlv_option_resource;
10331 : : struct mlx5_devx_obj *obj;
10332 : 0 : const struct rte_flow_item_geneve_opt *geneve_opt_v = item->spec;
10333 : : int ret = 0;
10334 : :
10335 : : MLX5_ASSERT(sh->config.dv_flow_en == 1);
10336 [ # # ]: 0 : if (!geneve_opt_v)
10337 : : return -1;
10338 : 0 : rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
10339 [ # # ]: 0 : if (geneve_opt_resource != NULL) {
10340 : 0 : if (geneve_opt_resource->option_class ==
10341 : : geneve_opt_v->option_class &&
10342 : : geneve_opt_resource->option_type ==
10343 [ # # ]: 0 : geneve_opt_v->option_type &&
10344 : : geneve_opt_resource->length ==
10345 : : geneve_opt_v->option_len) {
10346 : 0 : rte_atomic_fetch_add_explicit(&geneve_opt_resource->refcnt, 1,
10347 : : rte_memory_order_relaxed);
10348 : : } else {
10349 : 0 : ret = rte_flow_error_set(error, ENOMEM,
10350 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10351 : : "Only one GENEVE TLV option supported");
10352 : 0 : goto exit;
10353 : : }
10354 : : } else {
10355 : 0 : struct mlx5_devx_geneve_tlv_option_attr attr = {
10356 : 0 : .option_class = geneve_opt_v->option_class,
10357 : 0 : .option_type = geneve_opt_v->option_type,
10358 : 0 : .option_data_len = geneve_opt_v->option_len,
10359 : : };
10360 : :
10361 : : /* Create a GENEVE TLV object and resource. */
10362 : 0 : obj = mlx5_devx_cmd_create_geneve_tlv_option(sh->cdev->ctx,
10363 : : &attr);
10364 [ # # ]: 0 : if (!obj) {
10365 : 0 : ret = rte_flow_error_set(error, ENODATA,
10366 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10367 : : "Failed to create GENEVE TLV Devx object");
10368 : 0 : goto exit;
10369 : : }
10370 : 0 : sh->geneve_tlv_option_resource =
10371 : 0 : mlx5_malloc(MLX5_MEM_ZERO,
10372 : : sizeof(*geneve_opt_resource),
10373 : : 0, SOCKET_ID_ANY);
10374 [ # # ]: 0 : if (!sh->geneve_tlv_option_resource) {
10375 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
10376 : 0 : ret = rte_flow_error_set(error, ENOMEM,
10377 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10378 : : "GENEVE TLV object memory allocation failed");
10379 : 0 : goto exit;
10380 : : }
10381 : : geneve_opt_resource = sh->geneve_tlv_option_resource;
10382 : 0 : geneve_opt_resource->obj = obj;
10383 : 0 : geneve_opt_resource->option_class = geneve_opt_v->option_class;
10384 : 0 : geneve_opt_resource->option_type = geneve_opt_v->option_type;
10385 : 0 : geneve_opt_resource->length = geneve_opt_v->option_len;
10386 : 0 : rte_atomic_store_explicit(&geneve_opt_resource->refcnt, 1,
10387 : : rte_memory_order_relaxed);
10388 : : }
10389 : 0 : exit:
10390 : : rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
10391 : 0 : return ret;
10392 : : }
10393 : :
10394 : : /**
10395 : : * Add Geneve TLV option item to value.
10396 : : *
10397 : : * @param[in, out] dev
10398 : : * Pointer to rte_eth_dev structure.
10399 : : * @param[in, out] key
10400 : : * Flow matcher value.
10401 : : * @param[in] item
10402 : : * Flow pattern to translate.
10403 : : * @param[in] key_type
10404 : : * Set flow matcher mask or value.
10405 : : * @param[out] error
10406 : : * Pointer to error structure.
10407 : : */
10408 : : static int
10409 : 0 : flow_dv_translate_item_geneve_opt(struct rte_eth_dev *dev, void *key,
10410 : : const struct rte_flow_item *item,
10411 : : uint32_t key_type,
10412 : : struct rte_flow_error *error)
10413 : : {
10414 : : const struct rte_flow_item_geneve_opt *geneve_opt_m;
10415 : : const struct rte_flow_item_geneve_opt *geneve_opt_v;
10416 : 0 : const struct rte_flow_item_geneve_opt *orig_spec = item->spec;
10417 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
10418 : 0 : rte_be32_t opt_data_key = 0, opt_data_mask = 0;
10419 : : size_t option_byte_len;
10420 : : int ret = 0;
10421 : :
10422 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type) || !orig_spec)
# # # # #
# # # ]
10423 : : return -1;
10424 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, geneve_opt_v, geneve_opt_m,
# # # # ]
10425 : : &rte_flow_item_geneve_opt_mask);
10426 : : /*
10427 : : * Register resource requires item spec for SW steering,
10428 : : * for HW steering resources is registered explicitly by user.
10429 : : */
10430 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_SW_V) {
10431 : 0 : ret = flow_dev_geneve_tlv_option_resource_register(dev, item,
10432 : : error);
10433 [ # # ]: 0 : if (ret) {
10434 : 0 : DRV_LOG(ERR, "Failed to create geneve_tlv_obj");
10435 : 0 : return ret;
10436 : : }
10437 : : }
10438 : : /* Convert the option length from DW to bytes for using memcpy. */
10439 : 0 : option_byte_len = RTE_MIN((size_t)(orig_spec->option_len * 4),
10440 : : sizeof(rte_be32_t));
10441 [ # # ]: 0 : if (geneve_opt_v->data) {
10442 : : memcpy(&opt_data_key, geneve_opt_v->data, option_byte_len);
10443 : 0 : memcpy(&opt_data_mask, geneve_opt_m->data, option_byte_len);
10444 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v,
10445 : : geneve_tlv_option_0_data,
10446 : : rte_be_to_cpu_32(opt_data_key & opt_data_mask));
10447 : : }
10448 : : return ret;
10449 : : }
10450 : :
10451 : : /**
10452 : : * Add MPLS item to the value.
10453 : : *
10454 : : * @param[in, out] key
10455 : : * Flow matcher value.
10456 : : * @param[in] item
10457 : : * Flow pattern to translate.
10458 : : * @param[in] prev_layer
10459 : : * The protocol layer indicated in previous item.
10460 : : * @param[in] inner
10461 : : * Item is inner pattern.
10462 : : * @param[in] key_type
10463 : : * Set flow matcher mask or value.
10464 : : */
10465 : : static void
10466 : 0 : flow_dv_translate_item_mpls(void *key, const struct rte_flow_item *item,
10467 : : uint64_t prev_layer, int inner,
10468 : : uint32_t key_type)
10469 : : {
10470 : : const uint32_t *in_mpls_m;
10471 : : const uint32_t *in_mpls_v;
10472 : : uint32_t *out_mpls_v = 0;
10473 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10474 : 0 : void *misc2_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
10475 : : void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10476 : :
10477 [ # # # ]: 0 : switch (prev_layer) {
10478 : 0 : case MLX5_FLOW_LAYER_OUTER_L4_UDP:
10479 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
10480 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10481 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
10482 : : udp_dport, 0xffff);
10483 : : else
10484 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
10485 : : udp_dport, MLX5_UDP_PORT_MPLS);
10486 : : }
10487 : : break;
10488 : 0 : case MLX5_FLOW_LAYER_GRE:
10489 : : /* Fall-through. */
10490 : : case MLX5_FLOW_LAYER_GRE_KEY:
10491 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_misc, misc_v, gre_protocol)) {
10492 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10493 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v,
10494 : : gre_protocol, 0xffff);
10495 : : else
10496 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v,
10497 : : gre_protocol, RTE_ETHER_TYPE_MPLS);
10498 : : }
10499 : : break;
10500 : : default:
10501 : : break;
10502 : : }
10503 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10504 : : return;
10505 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, in_mpls_v, in_mpls_m,
# # # # ]
10506 : : &rte_flow_item_mpls_mask);
10507 [ # # # ]: 0 : switch (prev_layer) {
10508 : 0 : case MLX5_FLOW_LAYER_OUTER_L4_UDP:
10509 : 0 : out_mpls_v =
10510 : : (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
10511 : : outer_first_mpls_over_udp);
10512 : 0 : break;
10513 : 0 : case MLX5_FLOW_LAYER_GRE:
10514 : 0 : out_mpls_v =
10515 : : (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
10516 : : outer_first_mpls_over_gre);
10517 : 0 : break;
10518 : 0 : default:
10519 : : /* Inner MPLS not over GRE is not supported. */
10520 [ # # ]: 0 : if (!inner)
10521 : : out_mpls_v =
10522 : : (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
10523 : : misc2_v,
10524 : : outer_first_mpls);
10525 : : break;
10526 : : }
10527 : : if (out_mpls_v)
10528 : 0 : *out_mpls_v = *in_mpls_v & *in_mpls_m;
10529 : : }
10530 : :
10531 : : /**
10532 : : * Add metadata register item to matcher
10533 : : *
10534 : : * @param[in, out] key
10535 : : * Flow matcher value.
10536 : : * @param[in] reg_type
10537 : : * Type of device metadata register
10538 : : * @param[in] data
10539 : : * Register data
10540 : : * @param[in] mask
10541 : : * Register mask
10542 : : */
10543 : : static void
10544 : 0 : flow_dv_match_meta_reg(void *key, enum modify_reg reg_type,
10545 : : uint32_t data, uint32_t mask)
10546 : : {
10547 : : void *misc2_v =
10548 : : MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
10549 : : uint32_t temp;
10550 : :
10551 [ # # ]: 0 : if (!key)
10552 : : return;
10553 : 0 : data &= mask;
10554 [ # # # # : 0 : switch (reg_type) {
# # # # #
# # ]
10555 : 0 : case REG_A:
10556 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_a, data);
10557 : 0 : break;
10558 : 0 : case REG_B:
10559 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_b, data);
10560 : 0 : break;
10561 : 0 : case REG_C_0:
10562 : : /*
10563 : : * The metadata register C0 field might be divided into
10564 : : * source vport index and META item value, we should set
10565 : : * this field according to specified mask, not as whole one.
10566 : : */
10567 [ # # ]: 0 : temp = MLX5_GET(fte_match_set_misc2, misc2_v, metadata_reg_c_0);
10568 [ # # ]: 0 : if (mask)
10569 : 0 : temp &= ~mask;
10570 : 0 : temp |= data;
10571 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_0, temp);
10572 : 0 : break;
10573 : 0 : case REG_C_1:
10574 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_1, data);
10575 : 0 : break;
10576 : 0 : case REG_C_2:
10577 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_2, data);
10578 : 0 : break;
10579 : 0 : case REG_C_3:
10580 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_3, data);
10581 : 0 : break;
10582 : 0 : case REG_C_4:
10583 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_4, data);
10584 : 0 : break;
10585 : 0 : case REG_C_5:
10586 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_5, data);
10587 : 0 : break;
10588 : 0 : case REG_C_6:
10589 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_6, data);
10590 : 0 : break;
10591 : 0 : case REG_C_7:
10592 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_7, data);
10593 : 0 : break;
10594 : : default:
10595 : : MLX5_ASSERT(false);
10596 : : break;
10597 : : }
10598 : : }
10599 : :
10600 : : /**
10601 : : * Add metadata register item to matcher
10602 : : *
10603 : : * @param[in, out] matcher
10604 : : * Flow matcher.
10605 : : * @param[in, out] key
10606 : : * Flow matcher value.
10607 : : * @param[in] reg_type
10608 : : * Type of device metadata register
10609 : : * @param[in] value
10610 : : * Register value
10611 : : * @param[in] mask
10612 : : * Register mask
10613 : : */
10614 : : static void
10615 : : flow_dv_match_meta_reg_all(void *matcher, void *key, enum modify_reg reg_type,
10616 : : uint32_t data, uint32_t mask)
10617 : : {
10618 : 0 : flow_dv_match_meta_reg(key, reg_type, data, mask);
10619 : 0 : flow_dv_match_meta_reg(matcher, reg_type, mask, mask);
10620 : : }
10621 : :
10622 : : /**
10623 : : * Add MARK item to matcher
10624 : : *
10625 : : * @param[in] dev
10626 : : * The device to configure through.
10627 : : * @param[in, out] key
10628 : : * Flow matcher value.
10629 : : * @param[in] item
10630 : : * Flow pattern to translate.
10631 : : * @param[in] key_type
10632 : : * Set flow matcher mask or value.
10633 : : */
10634 : : static void
10635 : 0 : flow_dv_translate_item_mark(struct rte_eth_dev *dev, void *key,
10636 : : const struct rte_flow_item *item,
10637 : : uint32_t key_type)
10638 : : {
10639 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10640 : : const struct rte_flow_item_mark *mark;
10641 : : uint32_t value;
10642 : : uint32_t mask = 0;
10643 : :
10644 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_SW) {
10645 [ # # ]: 0 : mark = item->mask ? (const void *)item->mask :
10646 : : &rte_flow_item_mark_mask;
10647 : 0 : mask = mark->id;
10648 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M) {
10649 : : value = mask;
10650 : : } else {
10651 : 0 : mark = (const void *)item->spec;
10652 : : MLX5_ASSERT(mark);
10653 : 0 : value = mark->id;
10654 : : }
10655 : : } else {
10656 [ # # ]: 0 : mark = (key_type == MLX5_SET_MATCHER_HS_V) ?
10657 : : (const void *)item->spec : (const void *)item->mask;
10658 : : MLX5_ASSERT(mark);
10659 : 0 : value = mark->id;
10660 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_HS_M)
10661 : : mask = value;
10662 : : }
10663 : 0 : mask &= priv->sh->dv_mark_mask;
10664 : 0 : value &= mask;
10665 [ # # ]: 0 : if (mask) {
10666 : : enum modify_reg reg;
10667 : :
10668 : : /* Get the metadata register index for the mark. */
10669 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, NULL);
10670 : : MLX5_ASSERT(reg > 0);
10671 [ # # ]: 0 : if (reg == REG_C_0) {
10672 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10673 : 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
10674 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
10675 : :
10676 : 0 : mask &= msk_c0;
10677 : 0 : mask <<= shl_c0;
10678 : 0 : value <<= shl_c0;
10679 : : }
10680 : 0 : flow_dv_match_meta_reg(key, reg, value, mask);
10681 : : }
10682 : 0 : }
10683 : :
10684 : : /**
10685 : : * Add META item to matcher
10686 : : *
10687 : : * @param[in] dev
10688 : : * The devich to configure through.
10689 : : * @param[in, out] key
10690 : : * Flow matcher value.
10691 : : * @param[in] attr
10692 : : * Attributes of flow that includes this item.
10693 : : * @param[in] item
10694 : : * Flow pattern to translate.
10695 : : * @param[in] key_type
10696 : : * Set flow matcher mask or value.
10697 : : */
10698 : : static void
10699 : 0 : flow_dv_translate_item_meta(struct rte_eth_dev *dev,
10700 : : void *key,
10701 : : const struct rte_flow_attr *attr,
10702 : : const struct rte_flow_item *item,
10703 : : uint32_t key_type)
10704 : : {
10705 : : const struct rte_flow_item_meta *meta_m;
10706 : : const struct rte_flow_item_meta *meta_v;
10707 : : uint32_t value;
10708 : : uint32_t mask = 0;
10709 : : int reg;
10710 : :
10711 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10712 : : return;
10713 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, meta_v, meta_m,
# # # # ]
10714 : : &rte_flow_item_meta_mask);
10715 : 0 : value = meta_v->data;
10716 : 0 : mask = meta_m->data;
10717 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_HS_M)
10718 : : mask = value;
10719 : : /*
10720 : : * In the current implementation, REG_B cannot be used to match.
10721 : : * Force to use REG_C_1 in HWS root table as other tables.
10722 : : * This map may change.
10723 : : * NIC: modify - REG_B to be present in SW
10724 : : * match - REG_C_1 when copied from FDB, different from SWS
10725 : : * FDB: modify - REG_C_1 in Xmeta mode, REG_NON in legacy mode
10726 : : * match - REG_C_1 in FDB
10727 : : */
10728 [ # # ]: 0 : if (!!(key_type & MLX5_SET_MATCHER_SW))
10729 : 0 : reg = flow_dv_get_metadata_reg(dev, attr, NULL);
10730 : : else
10731 : : reg = flow_hw_get_reg_id(dev, RTE_FLOW_ITEM_TYPE_META, 0);
10732 [ # # ]: 0 : if (reg < 0)
10733 : : return;
10734 : : MLX5_ASSERT(reg != REG_NON);
10735 [ # # ]: 0 : if (reg == REG_C_0) {
10736 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10737 : 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
10738 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
10739 : :
10740 : 0 : mask &= msk_c0;
10741 : 0 : mask <<= shl_c0;
10742 : 0 : value <<= shl_c0;
10743 : : }
10744 : 0 : flow_dv_match_meta_reg(key, reg, value, mask);
10745 : : }
10746 : :
10747 : : /**
10748 : : * Add vport metadata Reg C0 item to matcher
10749 : : *
10750 : : * @param[in, out] key
10751 : : * Flow matcher value.
10752 : : * @param[in] value
10753 : : * Register value
10754 : : * @param[in] mask
10755 : : * Register mask
10756 : : */
10757 : : static void
10758 : : flow_dv_translate_item_meta_vport(void *key, uint32_t value, uint32_t mask)
10759 : : {
10760 : 0 : flow_dv_match_meta_reg(key, REG_C_0, value, mask);
10761 : 0 : }
10762 : :
10763 : : /**
10764 : : * Add tag item to matcher
10765 : : *
10766 : : * @param[in] dev
10767 : : * The devich to configure through.
10768 : : * @param[in, out] key
10769 : : * Flow matcher value.
10770 : : * @param[in] item
10771 : : * Flow pattern to translate.
10772 : : * @param[in] key_type
10773 : : * Set flow matcher mask or value.
10774 : : */
10775 : : static void
10776 : 0 : flow_dv_translate_mlx5_item_tag(struct rte_eth_dev *dev, void *key,
10777 : : const struct rte_flow_item *item,
10778 : : uint32_t key_type)
10779 : : {
10780 : 0 : const struct mlx5_rte_flow_item_tag *tag_v = item->spec;
10781 : 0 : const struct mlx5_rte_flow_item_tag *tag_m = item->mask;
10782 : : uint32_t mask, value;
10783 : :
10784 : : MLX5_ASSERT(tag_v);
10785 : 0 : value = tag_v->data;
10786 [ # # ]: 0 : mask = tag_m ? tag_m->data : UINT32_MAX;
10787 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10788 : : value = mask;
10789 [ # # ]: 0 : if (tag_v->id == REG_C_0) {
10790 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10791 : 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
10792 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
10793 : :
10794 : 0 : mask &= msk_c0;
10795 : 0 : mask <<= shl_c0;
10796 : 0 : value <<= shl_c0;
10797 : : }
10798 : 0 : flow_dv_match_meta_reg(key, tag_v->id, value, mask);
10799 : 0 : }
10800 : :
10801 : : /**
10802 : : * Add TAG item to matcher
10803 : : *
10804 : : * @param[in] dev
10805 : : * The devich to configure through.
10806 : : * @param[in, out] key
10807 : : * Flow matcher value.
10808 : : * @param[in] item
10809 : : * Flow pattern to translate.
10810 : : * @param[in] key_type
10811 : : * Set flow matcher mask or value.
10812 : : */
10813 : : static void
10814 : 0 : flow_dv_translate_item_tag(struct rte_eth_dev *dev, void *key,
10815 : : const struct rte_flow_item *item,
10816 : : uint32_t key_type)
10817 : : {
10818 : 0 : const struct rte_flow_item_tag *tag_vv = item->spec;
10819 : : const struct rte_flow_item_tag *tag_v;
10820 : : const struct rte_flow_item_tag *tag_m;
10821 : : int reg;
10822 : : uint32_t index;
10823 : :
10824 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10825 : : return;
10826 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, tag_v, tag_m,
# # # # ]
10827 : : &rte_flow_item_tag_mask);
10828 : : /* When set mask, the index should be from spec. */
10829 [ # # ]: 0 : index = tag_vv ? tag_vv->index : tag_v->index;
10830 : : /* Get the metadata register index for the tag. */
10831 [ # # ]: 0 : if (!!(key_type & MLX5_SET_MATCHER_SW))
10832 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, index, NULL);
10833 : : else
10834 : : reg = flow_hw_get_reg_id(dev, RTE_FLOW_ITEM_TYPE_TAG, index);
10835 : : MLX5_ASSERT(reg > 0);
10836 : 0 : flow_dv_match_meta_reg(key, (enum modify_reg)reg, tag_v->data, tag_m->data);
10837 : : }
10838 : :
10839 : : /**
10840 : : * Add source vport match to the specified matcher.
10841 : : *
10842 : : * @param[in, out] key
10843 : : * Flow matcher value.
10844 : : * @param[in] port
10845 : : * Source vport value to match
10846 : : */
10847 : : static void
10848 : : flow_dv_translate_item_source_vport(void *key,
10849 : : int16_t port)
10850 : : {
10851 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10852 : :
10853 [ # # # # : 0 : MLX5_SET(fte_match_set_misc, misc_v, source_port, port);
# # ]
10854 : 0 : }
10855 : :
10856 : : /**
10857 : : * Translate port-id item to eswitch match on port-id.
10858 : : *
10859 : : * @param[in] dev
10860 : : * The devich to configure through.
10861 : : * @param[in, out] key
10862 : : * Flow matcher value.
10863 : : * @param[in] item
10864 : : * Flow pattern to translate.
10865 : : * @param[in] attr
10866 : : * Flow attributes.
10867 : : * @param[in] key_type
10868 : : * Set flow matcher mask or value.
10869 : : *
10870 : : * @return
10871 : : * 0 on success, a negative errno value otherwise.
10872 : : */
10873 : : static int
10874 : 0 : flow_dv_translate_item_port_id(struct rte_eth_dev *dev, void *key,
10875 : : const struct rte_flow_item *item,
10876 : : const struct rte_flow_attr *attr,
10877 : : uint32_t key_type)
10878 : : {
10879 [ # # ]: 0 : const struct rte_flow_item_port_id *pid_m = item ? item->mask : NULL;
10880 [ # # ]: 0 : const struct rte_flow_item_port_id *pid_v = item ? item->spec : NULL;
10881 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
10882 : : struct mlx5_priv *priv;
10883 : : uint16_t mask, id;
10884 : : uint32_t vport_meta;
10885 : :
10886 : : MLX5_ASSERT(wks);
10887 [ # # # # ]: 0 : if (pid_v && pid_v->id == MLX5_PORT_ESW_MGR) {
10888 : 0 : flow_dv_translate_item_source_vport(key,
10889 [ # # ]: 0 : key_type & MLX5_SET_MATCHER_V ?
10890 : 0 : mlx5_flow_get_esw_manager_vport_id(dev) : 0xffff);
10891 : 0 : return 0;
10892 : : }
10893 [ # # ]: 0 : mask = pid_m ? pid_m->id : 0xffff;
10894 [ # # ]: 0 : id = pid_v ? pid_v->id : dev->data->port_id;
10895 : 0 : priv = mlx5_port_to_eswitch_info(id, item == NULL);
10896 [ # # ]: 0 : if (!priv)
10897 : 0 : return -rte_errno;
10898 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
10899 : : id = mask;
10900 : 0 : vport_meta = priv->vport_meta_mask;
10901 : : } else {
10902 : 0 : id = priv->vport_id;
10903 : 0 : vport_meta = priv->vport_meta_tag;
10904 : 0 : wks->vport_meta_tag = vport_meta;
10905 : : }
10906 : : /*
10907 : : * Translate to vport field or to metadata, depending on mode.
10908 : : * Kernel can use either misc.source_port or half of C0 metadata
10909 : : * register.
10910 : : */
10911 [ # # ]: 0 : if (priv->vport_meta_mask) {
10912 : : /*
10913 : : * Provide the hint for SW steering library
10914 : : * to insert the flow into ingress domain and
10915 : : * save the extra vport match.
10916 : : */
10917 [ # # # # ]: 0 : if (mask == 0xffff && priv->vport_id == 0xffff &&
10918 [ # # # # ]: 0 : priv->pf_bond < 0 && attr->transfer)
10919 [ # # ]: 0 : flow_dv_translate_item_source_vport(key, id);
10920 : : /*
10921 : : * We should always set the vport metadata register,
10922 : : * otherwise the SW steering library can drop
10923 : : * the rule if wire vport metadata value is not zero,
10924 : : * it depends on kernel configuration.
10925 : : */
10926 : 0 : flow_dv_translate_item_meta_vport
10927 : : (key, vport_meta, priv->vport_meta_mask);
10928 : : } else {
10929 [ # # ]: 0 : flow_dv_translate_item_source_vport(key, id);
10930 : : }
10931 : : return 0;
10932 : : }
10933 : :
10934 : : /**
10935 : : * Translate port representor item to eswitch match on port id.
10936 : : *
10937 : : * @param[in] dev
10938 : : * The devich to configure through.
10939 : : * @param[in, out] key
10940 : : * Flow matcher value.
10941 : : * @param[in] key_type
10942 : : * Set flow matcher mask or value.
10943 : : *
10944 : : * @return
10945 : : * 0 on success, a negative errno value otherwise.
10946 : : */
10947 : : static int
10948 : 0 : flow_dv_translate_item_port_representor(struct rte_eth_dev *dev, void *key,
10949 : : uint32_t key_type)
10950 : : {
10951 : 0 : flow_dv_translate_item_source_vport(key,
10952 [ # # ]: 0 : key_type & MLX5_SET_MATCHER_V ?
10953 : 0 : mlx5_flow_get_esw_manager_vport_id(dev) : 0xffff);
10954 : 0 : return 0;
10955 : : }
10956 : :
10957 : : /**
10958 : : * Translate represented port item to eswitch match on port id.
10959 : : *
10960 : : * @param[in] dev
10961 : : * The devich to configure through.
10962 : : * @param[in, out] key
10963 : : * Flow matcher value.
10964 : : * @param[in] item
10965 : : * Flow pattern to translate.
10966 : : * @param[in]
10967 : : * Flow attributes.
10968 : : *
10969 : : * @return
10970 : : * 0 on success, a negative errno value otherwise.
10971 : : */
10972 : : static int
10973 : 0 : flow_dv_translate_item_represented_port(struct rte_eth_dev *dev, void *key,
10974 : : const struct rte_flow_item *item,
10975 : : const struct rte_flow_attr *attr,
10976 : : uint32_t key_type)
10977 : : {
10978 [ # # ]: 0 : const struct rte_flow_item_ethdev *pid_m = item ? item->mask : NULL;
10979 [ # # ]: 0 : const struct rte_flow_item_ethdev *pid_v = item ? item->spec : NULL;
10980 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
10981 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10982 : : uint16_t mask, id;
10983 : : uint32_t vport_meta;
10984 : : bool vport_match = false;
10985 : :
10986 : : MLX5_ASSERT(wks);
10987 : : #ifndef HAVE_IBV_DEVICE_ATTR_ESW_MGR_REG_C0
10988 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
10989 : : vport_match = true;
10990 : : #endif
10991 [ # # ]: 0 : if (!pid_m && !pid_v)
10992 : : return 0;
10993 [ # # # # ]: 0 : if (pid_v && pid_v->port_id == UINT16_MAX) {
10994 [ # # # # ]: 0 : if (priv->sh->config.dv_flow_en != 2 || vport_match) {
10995 : 0 : flow_dv_translate_item_source_vport
10996 [ # # ]: 0 : (key, key_type & MLX5_SET_MATCHER_V ?
10997 : 0 : mlx5_flow_get_esw_manager_vport_id(dev) : 0xffff);
10998 : : } else {
10999 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11000 : 0 : vport_meta = priv->sh->dev_cap.esw_info.regc_mask;
11001 : : else
11002 : 0 : vport_meta = priv->sh->dev_cap.esw_info.regc_value;
11003 : 0 : flow_dv_translate_item_meta_vport(key, vport_meta,
11004 : : priv->sh->dev_cap.esw_info.regc_mask);
11005 : : }
11006 : 0 : return 0;
11007 : : }
11008 [ # # ]: 0 : mask = pid_m ? pid_m->port_id : UINT16_MAX;
11009 [ # # ]: 0 : id = pid_v ? pid_v->port_id : dev->data->port_id;
11010 : 0 : priv = mlx5_port_to_eswitch_info(id, item == NULL);
11011 [ # # ]: 0 : if (!priv)
11012 : 0 : return -rte_errno;
11013 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
11014 : : id = mask;
11015 : 0 : vport_meta = priv->vport_meta_mask;
11016 : : } else {
11017 : 0 : id = priv->vport_id;
11018 : 0 : vport_meta = priv->vport_meta_tag;
11019 : 0 : wks->vport_meta_tag = vport_meta;
11020 : : }
11021 : : /*
11022 : : * Translate to vport field or to metadata, depending on mode.
11023 : : * Kernel can use either misc.source_port or half of C0 metadata
11024 : : * register.
11025 : : */
11026 [ # # # # ]: 0 : if (priv->vport_meta_mask && !vport_match) {
11027 : : /*
11028 : : * Provide the hint for SW steering library
11029 : : * to insert the flow into ingress domain and
11030 : : * save the extra vport match.
11031 : : */
11032 [ # # # # ]: 0 : if (mask == UINT16_MAX && priv->vport_id == UINT16_MAX &&
11033 [ # # # # ]: 0 : priv->pf_bond < 0 && attr->transfer &&
11034 [ # # ]: 0 : priv->sh->config.dv_flow_en != 2)
11035 [ # # ]: 0 : flow_dv_translate_item_source_vport(key, id);
11036 : : /*
11037 : : * We should always set the vport metadata register,
11038 : : * otherwise the SW steering library can drop
11039 : : * the rule if wire vport metadata value is not zero,
11040 : : * it depends on kernel configuration.
11041 : : */
11042 : 0 : flow_dv_translate_item_meta_vport(key, vport_meta,
11043 : : priv->vport_meta_mask);
11044 : : } else {
11045 [ # # ]: 0 : flow_dv_translate_item_source_vport(key, id);
11046 : : }
11047 : : return 0;
11048 : : }
11049 : :
11050 : : /**
11051 : : * Translate port-id item to eswitch match on port-id.
11052 : : *
11053 : : * @param[in] dev
11054 : : * The devich to configure through.
11055 : : * @param[in, out] matcher
11056 : : * Flow matcher.
11057 : : * @param[in, out] key
11058 : : * Flow matcher value.
11059 : : * @param[in] item
11060 : : * Flow pattern to translate.
11061 : : * @param[in] attr
11062 : : * Flow attributes.
11063 : : *
11064 : : * @return
11065 : : * 0 on success, a negative errno value otherwise.
11066 : : */
11067 : : static int
11068 : 0 : flow_dv_translate_item_port_id_all(struct rte_eth_dev *dev,
11069 : : void *matcher, void *key,
11070 : : const struct rte_flow_item *item,
11071 : : const struct rte_flow_attr *attr)
11072 : : {
11073 : : int ret;
11074 : :
11075 : 0 : ret = flow_dv_translate_item_port_id
11076 : : (dev, matcher, item, attr, MLX5_SET_MATCHER_SW_M);
11077 [ # # ]: 0 : if (ret)
11078 : : return ret;
11079 : 0 : ret = flow_dv_translate_item_port_id
11080 : : (dev, key, item, attr, MLX5_SET_MATCHER_SW_V);
11081 : 0 : return ret;
11082 : : }
11083 : :
11084 : :
11085 : : /**
11086 : : * Add ICMP6 item to the value.
11087 : : *
11088 : : * @param[in, out] key
11089 : : * Flow matcher value.
11090 : : * @param[in] item
11091 : : * Flow pattern to translate.
11092 : : * @param[in] inner
11093 : : * Item is inner pattern.
11094 : : * @param[in] key_type
11095 : : * Set flow matcher mask or value.
11096 : : */
11097 : : static void
11098 : 0 : flow_dv_translate_item_icmp6(void *key, const struct rte_flow_item *item,
11099 : : int inner, uint32_t key_type)
11100 : : {
11101 : : const struct rte_flow_item_icmp6 *icmp6_m;
11102 : : const struct rte_flow_item_icmp6 *icmp6_v;
11103 : : void *headers_v;
11104 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
11105 : :
11106 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
11107 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11108 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11109 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, 0xFF);
11110 : : else
11111 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
11112 : : IPPROTO_ICMPV6);
11113 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11114 : : return;
11115 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, icmp6_v, icmp6_m,
# # # # ]
11116 : : &rte_flow_item_icmp6_mask);
11117 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type,
11118 : : icmp6_v->type & icmp6_m->type);
11119 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code,
11120 : : icmp6_v->code & icmp6_m->code);
11121 : : }
11122 : :
11123 : : /**
11124 : : * Add ICMP6 echo request/reply item to the value.
11125 : : *
11126 : : * @param[in, out] key
11127 : : * Flow matcher value.
11128 : : * @param[in] item
11129 : : * Flow pattern to translate.
11130 : : * @param[in] inner
11131 : : * Item is inner pattern.
11132 : : * @param[in] key_type
11133 : : * Set flow matcher mask or value.
11134 : : */
11135 : : static void
11136 [ # # ]: 0 : flow_dv_translate_item_icmp6_echo(void *key, const struct rte_flow_item *item,
11137 : : int inner, uint32_t key_type)
11138 : : {
11139 : : const struct rte_flow_item_icmp6_echo *icmp6_m;
11140 : : const struct rte_flow_item_icmp6_echo *icmp6_v;
11141 : : uint32_t icmp6_header_data_m = 0;
11142 : : uint32_t icmp6_header_data_v = 0;
11143 : : void *headers_v;
11144 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
11145 : : uint8_t icmp6_type = 0;
11146 : : struct rte_flow_item_icmp6_echo zero_mask;
11147 : :
11148 : : memset(&zero_mask, 0, sizeof(zero_mask));
11149 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
11150 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11151 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11152 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, 0xFF);
11153 : : else
11154 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
11155 : : IPPROTO_ICMPV6);
11156 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, icmp6_v, icmp6_m, &zero_mask);
# # # # ]
11157 : : /* Set fixed type and code for icmpv6 echo request or reply */
11158 [ # # ]: 0 : icmp6_type = (item->type == RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REQUEST ?
11159 : : RTE_ICMP6_ECHO_REQUEST : RTE_ICMP6_ECHO_REPLY);
11160 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
11161 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type, 0xFF);
11162 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code, 0xFF);
11163 : : } else {
11164 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type, icmp6_type);
11165 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code, 0);
11166 : : }
11167 [ # # ]: 0 : if (icmp6_v == NULL)
11168 : 0 : return;
11169 : : /* Set icmp6 header data (identifier & sequence) accordingly */
11170 : 0 : icmp6_header_data_m =
11171 [ # # ]: 0 : (rte_be_to_cpu_16(icmp6_m->hdr.identifier) << 16) |
11172 [ # # ]: 0 : rte_be_to_cpu_16(icmp6_m->hdr.sequence);
11173 [ # # ]: 0 : if (icmp6_header_data_m) {
11174 : 0 : icmp6_header_data_v =
11175 [ # # ]: 0 : (rte_be_to_cpu_16(icmp6_v->hdr.identifier) << 16) |
11176 [ # # ]: 0 : rte_be_to_cpu_16(icmp6_v->hdr.sequence);
11177 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_header_data,
11178 : : icmp6_header_data_v & icmp6_header_data_m);
11179 : : }
11180 : : }
11181 : :
11182 : : /**
11183 : : * Add ICMP item to the value.
11184 : : *
11185 : : * @param[in, out] key
11186 : : * Flow matcher value.
11187 : : * @param[in] item
11188 : : * Flow pattern to translate.
11189 : : * @param[in] inner
11190 : : * Item is inner pattern.
11191 : : * @param[in] key_type
11192 : : * Set flow matcher mask or value.
11193 : : */
11194 : : static void
11195 : 0 : flow_dv_translate_item_icmp(void *key, const struct rte_flow_item *item,
11196 : : int inner, uint32_t key_type)
11197 : : {
11198 : : const struct rte_flow_item_icmp *icmp_m;
11199 : : const struct rte_flow_item_icmp *icmp_v;
11200 : : uint32_t icmp_header_data_m = 0;
11201 : : uint32_t icmp_header_data_v = 0;
11202 : : void *headers_v;
11203 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
11204 : :
11205 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
11206 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11207 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11208 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11209 : : ip_protocol, 0xFF);
11210 : : else
11211 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11212 : : ip_protocol, IPPROTO_ICMP);
11213 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11214 : : return;
11215 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, icmp_v, icmp_m,
# # # # ]
11216 : : &rte_flow_item_icmp_mask);
11217 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmp_type,
11218 : : icmp_v->hdr.icmp_type & icmp_m->hdr.icmp_type);
11219 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmp_code,
11220 : : icmp_v->hdr.icmp_code & icmp_m->hdr.icmp_code);
11221 [ # # ]: 0 : icmp_header_data_m = rte_be_to_cpu_16(icmp_m->hdr.icmp_seq_nb);
11222 [ # # ]: 0 : icmp_header_data_m |= rte_be_to_cpu_16(icmp_m->hdr.icmp_ident) << 16;
11223 [ # # ]: 0 : if (icmp_header_data_m) {
11224 [ # # ]: 0 : icmp_header_data_v = rte_be_to_cpu_16(icmp_v->hdr.icmp_seq_nb);
11225 : 0 : icmp_header_data_v |=
11226 [ # # ]: 0 : rte_be_to_cpu_16(icmp_v->hdr.icmp_ident) << 16;
11227 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmp_header_data,
11228 : : icmp_header_data_v & icmp_header_data_m);
11229 : : }
11230 : : }
11231 : :
11232 : : /**
11233 : : * Add GTP item to the value.
11234 : : *
11235 : : * @param[in, out] key
11236 : : * Flow matcher value.
11237 : : * @param[in] item
11238 : : * Flow pattern to translate.
11239 : : * @param[in] inner
11240 : : * Item is inner pattern.
11241 : : * @param[in] key_type
11242 : : * Set flow matcher mask or value.
11243 : : */
11244 : : static void
11245 : 0 : flow_dv_translate_item_gtp(void *key, const struct rte_flow_item *item,
11246 : : int inner, uint32_t key_type)
11247 : : {
11248 : : const struct rte_flow_item_gtp *gtp_m;
11249 : : const struct rte_flow_item_gtp *gtp_v;
11250 : : void *headers_v;
11251 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
11252 : : uint16_t dport = RTE_GTPU_UDP_PORT;
11253 : :
11254 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
11255 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11256 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
11257 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11258 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11259 : : udp_dport, 0xFFFF);
11260 : : else
11261 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11262 : : udp_dport, dport);
11263 : : }
11264 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11265 : : return;
11266 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, gtp_v, gtp_m,
# # # # ]
11267 : : &rte_flow_item_gtp_mask);
11268 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags,
11269 : : gtp_v->hdr.gtp_hdr_info & gtp_m->hdr.gtp_hdr_info);
11270 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_type,
11271 : : gtp_v->hdr.msg_type & gtp_m->hdr.msg_type);
11272 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_teid,
11273 : : rte_be_to_cpu_32(gtp_v->hdr.teid & gtp_m->hdr.teid));
11274 : : }
11275 : :
11276 : : /**
11277 : : * Add GTP PSC item to matcher.
11278 : : *
11279 : : * @param[in, out] key
11280 : : * Flow matcher value.
11281 : : * @param[in] item
11282 : : * Flow pattern to translate.
11283 : : * @param[in] key_type
11284 : : * Set flow matcher mask or value.
11285 : : */
11286 : : static int
11287 : 0 : flow_dv_translate_item_gtp_psc(void *key, const struct rte_flow_item *item,
11288 : : uint32_t key_type)
11289 : : {
11290 : : const struct rte_flow_item_gtp_psc *gtp_psc_m;
11291 : : const struct rte_flow_item_gtp_psc *gtp_psc_v;
11292 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
11293 : : union {
11294 : : uint32_t w32;
11295 : : struct {
11296 : : uint16_t seq_num;
11297 : : uint8_t npdu_num;
11298 : : uint8_t next_ext_header_type;
11299 : : };
11300 : : } dw_2;
11301 : : union {
11302 : : uint32_t w32;
11303 : : struct {
11304 : : uint8_t len;
11305 : : uint8_t type_flags;
11306 : : uint8_t qfi;
11307 : : uint8_t reserved;
11308 : : };
11309 : : } dw_0;
11310 : : uint8_t gtp_flags;
11311 : :
11312 : : /* Always set E-flag match on one, regardless of GTP item settings. */
11313 [ # # ]: 0 : gtp_flags = MLX5_GET(fte_match_set_misc3, misc3_v, gtpu_msg_flags);
11314 : 0 : gtp_flags |= MLX5_GTP_EXT_HEADER_FLAG;
11315 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags, gtp_flags);
11316 : : /*Set next extension header type. */
11317 : 0 : dw_2.seq_num = 0;
11318 : 0 : dw_2.npdu_num = 0;
11319 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11320 : 0 : dw_2.next_ext_header_type = 0xff;
11321 : : else
11322 : 0 : dw_2.next_ext_header_type = 0x85;
11323 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_dw_2,
11324 : : rte_cpu_to_be_32(dw_2.w32));
11325 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11326 : : return 0;
11327 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, gtp_psc_v,
# # # # ]
11328 : : gtp_psc_m, &rte_flow_item_gtp_psc_mask);
11329 : 0 : dw_0.w32 = 0;
11330 : 0 : dw_0.type_flags = MLX5_GTP_PDU_TYPE_SHIFT(gtp_psc_v->hdr.type &
11331 : : gtp_psc_m->hdr.type);
11332 : 0 : dw_0.qfi = gtp_psc_v->hdr.qfi & gtp_psc_m->hdr.qfi;
11333 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_first_ext_dw_0,
11334 : : rte_cpu_to_be_32(dw_0.w32));
11335 : 0 : return 0;
11336 : : }
11337 : :
11338 : : /**
11339 : : * Add eCPRI item to matcher and to the value.
11340 : : *
11341 : : * @param[in] dev
11342 : : * The devich to configure through.
11343 : : * @param[in, out] key
11344 : : * Flow matcher value.
11345 : : * @param[in] item
11346 : : * Flow pattern to translate.
11347 : : * @param[in] last_item
11348 : : * Last item flags.
11349 : : * @param[in] key_type
11350 : : * Set flow matcher mask or value.
11351 : : */
11352 : : static void
11353 : 0 : flow_dv_translate_item_ecpri(struct rte_eth_dev *dev, void *key,
11354 : : const struct rte_flow_item *item,
11355 : : uint64_t last_item, uint32_t key_type)
11356 : : {
11357 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11358 : : const struct rte_flow_item_ecpri *ecpri_m;
11359 : : const struct rte_flow_item_ecpri *ecpri_v;
11360 : 0 : const struct rte_flow_item_ecpri *ecpri_vv = item->spec;
11361 : : struct rte_ecpri_common_hdr common;
11362 : : void *misc4_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_4);
11363 : : uint32_t *samples;
11364 : : void *dw_v;
11365 : :
11366 : : /*
11367 : : * In case of eCPRI over Ethernet, if EtherType is not specified,
11368 : : * match on eCPRI EtherType implicitly.
11369 : : */
11370 [ # # ]: 0 : if (last_item & MLX5_FLOW_LAYER_OUTER_L2) {
11371 : : void *hdrs_v, *l2v;
11372 : :
11373 : : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11374 : : l2v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, ethertype);
11375 [ # # ]: 0 : if (*(uint16_t *)l2v == 0) {
11376 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11377 : 0 : *(uint16_t *)l2v = UINT16_MAX;
11378 : : else
11379 : 0 : *(uint16_t *)l2v =
11380 : : RTE_BE16(RTE_ETHER_TYPE_ECPRI);
11381 : : }
11382 : : }
11383 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11384 : 0 : return;
11385 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, ecpri_v, ecpri_m,
# # # # ]
11386 : : &rte_flow_item_ecpri_mask);
11387 : : /*
11388 : : * Maximal four DW samples are supported in a single matching now.
11389 : : * Two are used now for a eCPRI matching:
11390 : : * 1. Type: one byte, mask should be 0x00ff0000 in network order
11391 : : * 2. ID of a message: one or two bytes, mask 0xffff0000 or 0xff000000
11392 : : * if any.
11393 : : */
11394 [ # # ]: 0 : if (!ecpri_m->hdr.common.u32)
11395 : : return;
11396 : 0 : samples = priv->sh->ecpri_parser.ids;
11397 : : /* Need to take the whole DW as the mask to fill the entry. */
11398 : : dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
11399 : : prog_sample_field_value_0);
11400 : : /* Already big endian (network order) in the header. */
11401 : 0 : *(uint32_t *)dw_v = ecpri_v->hdr.common.u32 & ecpri_m->hdr.common.u32;
11402 : : /* Sample#0, used for matching type, offset 0. */
11403 : : /* It makes no sense to set the sample ID in the mask field. */
11404 [ # # ]: 0 : MLX5_SET(fte_match_set_misc4, misc4_v,
11405 : : prog_sample_field_id_0, samples[0]);
11406 : : /*
11407 : : * Checking if message body part needs to be matched.
11408 : : * Some wildcard rules only matching type field should be supported.
11409 : : */
11410 [ # # ]: 0 : if (ecpri_m->hdr.dummy[0]) {
11411 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M)
11412 [ # # ]: 0 : common.u32 = rte_be_to_cpu_32(ecpri_vv->hdr.common.u32);
11413 : : else
11414 [ # # ]: 0 : common.u32 = rte_be_to_cpu_32(ecpri_v->hdr.common.u32);
11415 [ # # ]: 0 : switch (common.type) {
11416 : 0 : case RTE_ECPRI_MSG_TYPE_IQ_DATA:
11417 : : case RTE_ECPRI_MSG_TYPE_RTC_CTRL:
11418 : : case RTE_ECPRI_MSG_TYPE_DLY_MSR:
11419 : : dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
11420 : : prog_sample_field_value_1);
11421 : 0 : *(uint32_t *)dw_v = ecpri_v->hdr.dummy[0] &
11422 : : ecpri_m->hdr.dummy[0];
11423 : : /* Sample#1, to match message body, offset 4. */
11424 [ # # ]: 0 : MLX5_SET(fte_match_set_misc4, misc4_v,
11425 : : prog_sample_field_id_1, samples[1]);
11426 : 0 : break;
11427 : : default:
11428 : : /* Others, do not match any sample ID. */
11429 : : break;
11430 : : }
11431 : : }
11432 : : }
11433 : :
11434 : : /*
11435 : : * Add connection tracking status item to matcher
11436 : : *
11437 : : * @param[in] dev
11438 : : * The devich to configure through.
11439 : : * @param[in, out] matcher
11440 : : * Flow matcher.
11441 : : * @param[in, out] key
11442 : : * Flow matcher value.
11443 : : * @param[in] item
11444 : : * Flow pattern to translate.
11445 : : */
11446 : : static void
11447 : 0 : flow_dv_translate_item_aso_ct(struct rte_eth_dev *dev,
11448 : : void *matcher, void *key,
11449 : : const struct rte_flow_item *item)
11450 : : {
11451 : : uint32_t reg_value = 0;
11452 : : int reg_id;
11453 : : /* 8LSB 0b 11/0000/11, middle 4 bits are reserved. */
11454 : : uint32_t reg_mask = 0;
11455 : 0 : const struct rte_flow_item_conntrack *spec = item->spec;
11456 : 0 : const struct rte_flow_item_conntrack *mask = item->mask;
11457 : : uint32_t flags;
11458 : : struct rte_flow_error error;
11459 : :
11460 [ # # ]: 0 : if (!mask)
11461 : : mask = &rte_flow_item_conntrack_mask;
11462 [ # # # # ]: 0 : if (!spec || !mask->flags)
11463 : 0 : return;
11464 : 0 : flags = spec->flags & mask->flags;
11465 : : /* The conflict should be checked in the validation. */
11466 : : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_VALID)
11467 : : reg_value |= MLX5_CT_SYNDROME_VALID;
11468 [ # # ]: 0 : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_CHANGED)
11469 : : reg_value |= MLX5_CT_SYNDROME_STATE_CHANGE;
11470 [ # # ]: 0 : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_INVALID)
11471 : 0 : reg_value |= MLX5_CT_SYNDROME_INVALID;
11472 [ # # ]: 0 : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED)
11473 : 0 : reg_value |= MLX5_CT_SYNDROME_TRAP;
11474 [ # # ]: 0 : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD)
11475 : 0 : reg_value |= MLX5_CT_SYNDROME_BAD_PACKET;
11476 [ # # ]: 0 : if (mask->flags & (RTE_FLOW_CONNTRACK_PKT_STATE_VALID |
11477 : : RTE_FLOW_CONNTRACK_PKT_STATE_INVALID |
11478 : : RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED))
11479 : : reg_mask |= 0xc0;
11480 [ # # ]: 0 : if (mask->flags & RTE_FLOW_CONNTRACK_PKT_STATE_CHANGED)
11481 : 0 : reg_mask |= MLX5_CT_SYNDROME_STATE_CHANGE;
11482 [ # # ]: 0 : if (mask->flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD)
11483 : 0 : reg_mask |= MLX5_CT_SYNDROME_BAD_PACKET;
11484 : : /* The REG_C_x value could be saved during startup. */
11485 : 0 : reg_id = mlx5_flow_get_reg_id(dev, MLX5_ASO_CONNTRACK, 0, &error);
11486 [ # # ]: 0 : if (reg_id == REG_NON)
11487 : : return;
11488 : 0 : flow_dv_match_meta_reg_all(matcher, key, (enum modify_reg)reg_id,
11489 : : reg_value, reg_mask);
11490 : : }
11491 : :
11492 : : static void
11493 : 0 : flow_dv_translate_item_flex(struct rte_eth_dev *dev, void *matcher, void *key,
11494 : : const struct rte_flow_item *item,
11495 : : struct mlx5_flow *dev_flow, bool is_inner)
11496 : : {
11497 : 0 : const struct rte_flow_item_flex *spec =
11498 : : (const struct rte_flow_item_flex *)item->spec;
11499 : 0 : int index = mlx5_flex_acquire_index(dev, spec->handle, false);
11500 : :
11501 : : MLX5_ASSERT(index >= 0 && index < (int)(sizeof(uint32_t) * CHAR_BIT));
11502 [ # # ]: 0 : if (index < 0)
11503 : : return;
11504 [ # # ]: 0 : if (!(dev_flow->handle->flex_item & RTE_BIT32(index))) {
11505 : : /* Don't count both inner and outer flex items in one rule. */
11506 : 0 : if (mlx5_flex_acquire_index(dev, spec->handle, true) != index)
11507 : : MLX5_ASSERT(false);
11508 : 0 : dev_flow->handle->flex_item |= (uint8_t)RTE_BIT32(index);
11509 : : }
11510 : 0 : mlx5_flex_flow_translate_item(dev, matcher, key, item, is_inner);
11511 : : }
11512 : :
11513 : : /**
11514 : : * Add METER_COLOR item to matcher
11515 : : *
11516 : : * @param[in] dev
11517 : : * The device to configure through.
11518 : : * @param[in, out] key
11519 : : * Flow matcher value.
11520 : : * @param[in] item
11521 : : * Flow pattern to translate.
11522 : : * @param[in] key_type
11523 : : * Set flow matcher mask or value.
11524 : : */
11525 : : static void
11526 : 0 : flow_dv_translate_item_meter_color(struct rte_eth_dev *dev, void *key,
11527 : : const struct rte_flow_item *item,
11528 : : uint32_t key_type)
11529 : : {
11530 : 0 : const struct rte_flow_item_meter_color *color_m = item->mask;
11531 : 0 : const struct rte_flow_item_meter_color *color_v = item->spec;
11532 : : uint32_t value, mask;
11533 : : int reg = REG_NON;
11534 : :
11535 : : MLX5_ASSERT(color_v);
11536 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11537 : : return;
11538 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, color_v, color_m,
# # # # ]
11539 : : &rte_flow_item_meter_color_mask);
11540 [ # # ]: 0 : value = rte_col_2_mlx5_col(color_v->color);
11541 : : mask = color_m ?
11542 [ # # ]: 0 : color_m->color : (UINT32_C(1) << MLX5_MTR_COLOR_BITS) - 1;
11543 [ # # ]: 0 : if (!!(key_type & MLX5_SET_MATCHER_SW))
11544 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, NULL);
11545 : : else
11546 : : reg = flow_hw_get_reg_id(dev,
11547 : : RTE_FLOW_ITEM_TYPE_METER_COLOR, 0);
11548 [ # # ]: 0 : if (reg == REG_NON)
11549 : : return;
11550 : 0 : flow_dv_match_meta_reg(key, (enum modify_reg)reg, value, mask);
11551 : : }
11552 : :
11553 : : static void
11554 : 0 : flow_dv_translate_item_aggr_affinity(void *key,
11555 : : const struct rte_flow_item *item,
11556 : : uint32_t key_type)
11557 : : {
11558 : : const struct rte_flow_item_aggr_affinity *affinity_v;
11559 : : const struct rte_flow_item_aggr_affinity *affinity_m;
11560 : : void *misc_v;
11561 : :
11562 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, affinity_v, affinity_m,
# # # # ]
11563 : : &rte_flow_item_aggr_affinity_mask);
11564 : : misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
11565 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, lag_rx_port_affinity,
11566 : : affinity_v->affinity & affinity_m->affinity);
11567 : 0 : }
11568 : :
11569 : : static void
11570 : 0 : flow_dv_translate_item_ib_bth(void *key,
11571 : : const struct rte_flow_item *item,
11572 : : int inner, uint32_t key_type)
11573 : : {
11574 : : const struct rte_flow_item_ib_bth *bth_m;
11575 : : const struct rte_flow_item_ib_bth *bth_v;
11576 : : void *headers_v, *misc_v;
11577 : : uint16_t udp_dport;
11578 : : char *qpn_v;
11579 : : int i, size;
11580 : :
11581 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
11582 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11583 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
11584 [ # # ]: 0 : udp_dport = key_type & MLX5_SET_MATCHER_M ?
11585 : : 0xFFFF : MLX5_UDP_PORT_ROCEv2;
11586 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, udp_dport);
11587 : : }
11588 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11589 : : return;
11590 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, bth_v, bth_m, &rte_flow_item_ib_bth_mask);
# # # # ]
11591 : : misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
11592 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, bth_opcode,
11593 : : bth_v->hdr.opcode & bth_m->hdr.opcode);
11594 : 0 : qpn_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, bth_dst_qp);
11595 : : size = sizeof(bth_m->hdr.dst_qp);
11596 [ # # ]: 0 : for (i = 0; i < size; ++i)
11597 : 0 : qpn_v[i] = bth_m->hdr.dst_qp[i] & bth_v->hdr.dst_qp[i];
11598 : : }
11599 : :
11600 : : static uint32_t matcher_zero[MLX5_ST_SZ_DW(fte_match_param)] = { 0 };
11601 : :
11602 : : #define HEADER_IS_ZERO(match_criteria, headers) \
11603 : : !(memcmp(MLX5_ADDR_OF(fte_match_param, match_criteria, headers), \
11604 : : matcher_zero, MLX5_FLD_SZ_BYTES(fte_match_param, headers))) \
11605 : :
11606 : : /**
11607 : : * Calculate flow matcher enable bitmap.
11608 : : *
11609 : : * @param match_criteria
11610 : : * Pointer to flow matcher criteria.
11611 : : *
11612 : : * @return
11613 : : * Bitmap of enabled fields.
11614 : : */
11615 : : static uint8_t
11616 : 0 : flow_dv_matcher_enable(uint32_t *match_criteria)
11617 : : {
11618 : : uint8_t match_criteria_enable;
11619 : :
11620 : : match_criteria_enable =
11621 : 0 : (!HEADER_IS_ZERO(match_criteria, outer_headers)) <<
11622 : : MLX5_MATCH_CRITERIA_ENABLE_OUTER_BIT;
11623 : 0 : match_criteria_enable |=
11624 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters)) <<
11625 : : MLX5_MATCH_CRITERIA_ENABLE_MISC_BIT;
11626 : 0 : match_criteria_enable |=
11627 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, inner_headers)) <<
11628 : : MLX5_MATCH_CRITERIA_ENABLE_INNER_BIT;
11629 : 0 : match_criteria_enable |=
11630 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) <<
11631 : : MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
11632 : 0 : match_criteria_enable |=
11633 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters_3)) <<
11634 : : MLX5_MATCH_CRITERIA_ENABLE_MISC3_BIT;
11635 : 0 : match_criteria_enable |=
11636 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters_4)) <<
11637 : : MLX5_MATCH_CRITERIA_ENABLE_MISC4_BIT;
11638 : 0 : match_criteria_enable |=
11639 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters_5)) <<
11640 : : MLX5_MATCH_CRITERIA_ENABLE_MISC5_BIT;
11641 : 0 : return match_criteria_enable;
11642 : : }
11643 : :
11644 : : static void
11645 : : __flow_dv_adjust_buf_size(size_t *size, uint8_t match_criteria)
11646 : : {
11647 : : /*
11648 : : * Check flow matching criteria first, subtract misc5/4 length if flow
11649 : : * doesn't own misc5/4 parameters. In some old rdma-core releases,
11650 : : * misc5/4 are not supported, and matcher creation failure is expected
11651 : : * w/o subtraction. If misc5 is provided, misc4 must be counted in since
11652 : : * misc5 is right after misc4.
11653 : : */
11654 : 0 : if (!(match_criteria & (1 << MLX5_MATCH_CRITERIA_ENABLE_MISC5_BIT))) {
11655 : 0 : *size = MLX5_ST_SZ_BYTES(fte_match_param) -
11656 : : MLX5_ST_SZ_BYTES(fte_match_set_misc5);
11657 [ # # # # : 0 : if (!(match_criteria & (1 <<
# # # # #
# # # # #
# # # # #
# ]
11658 : : MLX5_MATCH_CRITERIA_ENABLE_MISC4_BIT))) {
11659 : 0 : *size -= MLX5_ST_SZ_BYTES(fte_match_set_misc4);
11660 : : }
11661 : : }
11662 : : }
11663 : :
11664 : : struct mlx5_list_entry *
11665 : 0 : flow_matcher_clone_cb(void *tool_ctx __rte_unused,
11666 : : struct mlx5_list_entry *entry, void *cb_ctx)
11667 : : {
11668 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11669 : 0 : struct mlx5_flow_dv_matcher *ref = ctx->data;
11670 : 0 : struct mlx5_flow_tbl_data_entry *tbl = container_of(ref->tbl,
11671 : : typeof(*tbl), tbl);
11672 : 0 : struct mlx5_flow_dv_matcher *resource = mlx5_malloc(MLX5_MEM_ANY,
11673 : : sizeof(*resource),
11674 : : 0, SOCKET_ID_ANY);
11675 : :
11676 [ # # ]: 0 : if (!resource) {
11677 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
11678 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11679 : : "cannot create matcher");
11680 : 0 : return NULL;
11681 : : }
11682 : : memcpy(resource, entry, sizeof(*resource));
11683 : 0 : resource->tbl = &tbl->tbl;
11684 : 0 : return &resource->entry;
11685 : : }
11686 : :
11687 : : void
11688 : 0 : flow_matcher_clone_free_cb(void *tool_ctx __rte_unused,
11689 : : struct mlx5_list_entry *entry)
11690 : : {
11691 : 0 : mlx5_free(entry);
11692 : 0 : }
11693 : :
11694 : : struct mlx5_list_entry *
11695 : 0 : flow_dv_tbl_create_cb(void *tool_ctx, void *cb_ctx)
11696 : : {
11697 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11698 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11699 : 0 : struct rte_eth_dev *dev = ctx->dev;
11700 : : struct mlx5_flow_tbl_data_entry *tbl_data;
11701 : 0 : struct mlx5_flow_tbl_tunnel_prm *tt_prm = ctx->data2;
11702 : 0 : struct rte_flow_error *error = ctx->error;
11703 : 0 : union mlx5_flow_tbl_key key = { .v64 = *(uint64_t *)(ctx->data) };
11704 : : struct mlx5_flow_tbl_resource *tbl;
11705 : : void *domain;
11706 : 0 : uint32_t idx = 0;
11707 : : int ret;
11708 : :
11709 : 0 : tbl_data = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_JUMP], &idx);
11710 [ # # ]: 0 : if (!tbl_data) {
11711 : 0 : rte_flow_error_set(error, ENOMEM,
11712 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11713 : : NULL,
11714 : : "cannot allocate flow table data entry");
11715 : 0 : return NULL;
11716 : : }
11717 : 0 : tbl_data->idx = idx;
11718 : 0 : tbl_data->tunnel = tt_prm->tunnel;
11719 : 0 : tbl_data->group_id = tt_prm->group_id;
11720 [ # # ]: 0 : tbl_data->external = !!tt_prm->external;
11721 : 0 : tbl_data->tunnel_offload = is_tunnel_offload_active(dev);
11722 : 0 : tbl_data->is_egress = !!key.is_egress;
11723 : 0 : tbl_data->is_transfer = !!key.is_fdb;
11724 : 0 : tbl_data->dummy = !!key.dummy;
11725 : 0 : tbl_data->level = key.level;
11726 : 0 : tbl_data->id = key.id;
11727 : : tbl = &tbl_data->tbl;
11728 [ # # ]: 0 : if (key.dummy)
11729 : 0 : return &tbl_data->entry;
11730 [ # # ]: 0 : if (key.is_fdb)
11731 : 0 : domain = sh->fdb_domain;
11732 [ # # ]: 0 : else if (key.is_egress)
11733 : 0 : domain = sh->tx_domain;
11734 : : else
11735 : 0 : domain = sh->rx_domain;
11736 : : ret = mlx5_flow_os_create_flow_tbl(domain, key.level, &tbl->obj);
11737 : : if (ret) {
11738 : 0 : rte_flow_error_set(error, ENOMEM,
11739 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11740 : : NULL, "cannot create flow table object");
11741 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
11742 : 0 : return NULL;
11743 : : }
11744 [ # # ]: 0 : if (key.level != 0) {
11745 : : ret = mlx5_flow_os_create_flow_action_dest_flow_tbl
11746 : : (tbl->obj, &tbl_data->jump.action);
11747 : : if (ret) {
11748 : 0 : rte_flow_error_set(error, ENOMEM,
11749 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11750 : : NULL,
11751 : : "cannot create flow jump action");
11752 : 0 : mlx5_flow_os_destroy_flow_tbl(tbl->obj);
11753 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
11754 : 0 : return NULL;
11755 : : }
11756 : : }
11757 [ # # # # ]: 0 : MKSTR(matcher_name, "%s_%s_%u_%u_matcher_list",
11758 : : key.is_fdb ? "FDB" : "NIC", key.is_egress ? "egress" : "ingress",
11759 : : key.level, key.id);
11760 : 0 : tbl_data->matchers = mlx5_list_create(matcher_name, sh, true,
11761 : : flow_matcher_create_cb,
11762 : : flow_matcher_match_cb,
11763 : : flow_matcher_remove_cb,
11764 : : flow_matcher_clone_cb,
11765 : : flow_matcher_clone_free_cb);
11766 [ # # ]: 0 : if (!tbl_data->matchers) {
11767 : 0 : rte_flow_error_set(error, ENOMEM,
11768 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11769 : : NULL,
11770 : : "cannot create tbl matcher list");
11771 : 0 : mlx5_flow_os_destroy_flow_action(tbl_data->jump.action);
11772 : 0 : mlx5_flow_os_destroy_flow_tbl(tbl->obj);
11773 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
11774 : 0 : return NULL;
11775 : : }
11776 : 0 : return &tbl_data->entry;
11777 : : }
11778 : :
11779 : : int
11780 : 0 : flow_dv_tbl_match_cb(void *tool_ctx __rte_unused, struct mlx5_list_entry *entry,
11781 : : void *cb_ctx)
11782 : : {
11783 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11784 : : struct mlx5_flow_tbl_data_entry *tbl_data =
11785 : : container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
11786 : 0 : union mlx5_flow_tbl_key key = { .v64 = *(uint64_t *)(ctx->data) };
11787 : :
11788 : 0 : return tbl_data->level != key.level ||
11789 [ # # ]: 0 : tbl_data->id != key.id ||
11790 [ # # ]: 0 : tbl_data->dummy != key.dummy ||
11791 [ # # # # ]: 0 : tbl_data->is_transfer != !!key.is_fdb ||
11792 [ # # ]: 0 : tbl_data->is_egress != !!key.is_egress;
11793 : : }
11794 : :
11795 : : struct mlx5_list_entry *
11796 : 0 : flow_dv_tbl_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
11797 : : void *cb_ctx)
11798 : : {
11799 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11800 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11801 : : struct mlx5_flow_tbl_data_entry *tbl_data;
11802 : 0 : struct rte_flow_error *error = ctx->error;
11803 : 0 : uint32_t idx = 0;
11804 : :
11805 : 0 : tbl_data = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_JUMP], &idx);
11806 [ # # ]: 0 : if (!tbl_data) {
11807 : 0 : rte_flow_error_set(error, ENOMEM,
11808 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11809 : : NULL,
11810 : : "cannot allocate flow table data entry");
11811 : 0 : return NULL;
11812 : : }
11813 : : memcpy(tbl_data, oentry, sizeof(*tbl_data));
11814 : 0 : tbl_data->idx = idx;
11815 : 0 : return &tbl_data->entry;
11816 : : }
11817 : :
11818 : : void
11819 : 0 : flow_dv_tbl_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
11820 : : {
11821 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11822 : : struct mlx5_flow_tbl_data_entry *tbl_data =
11823 : : container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
11824 : :
11825 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], tbl_data->idx);
11826 : 0 : }
11827 : :
11828 : : /**
11829 : : * Get a flow table.
11830 : : *
11831 : : * @param[in, out] dev
11832 : : * Pointer to rte_eth_dev structure.
11833 : : * @param[in] table_level
11834 : : * Table level to use.
11835 : : * @param[in] egress
11836 : : * Direction of the table.
11837 : : * @param[in] transfer
11838 : : * E-Switch or NIC flow.
11839 : : * @param[in] dummy
11840 : : * Dummy entry for dv API.
11841 : : * @param[in] table_id
11842 : : * Table id to use.
11843 : : * @param[out] error
11844 : : * pointer to error structure.
11845 : : *
11846 : : * @return
11847 : : * Returns tables resource based on the index, NULL in case of failed.
11848 : : */
11849 : : struct mlx5_flow_tbl_resource *
11850 : 0 : flow_dv_tbl_resource_get(struct rte_eth_dev *dev,
11851 : : uint32_t table_level, uint8_t egress,
11852 : : uint8_t transfer,
11853 : : bool external,
11854 : : const struct mlx5_flow_tunnel *tunnel,
11855 : : uint32_t group_id, uint8_t dummy,
11856 : : uint32_t table_id,
11857 : : struct rte_flow_error *error)
11858 : : {
11859 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11860 : 0 : union mlx5_flow_tbl_key table_key = {
11861 : : {
11862 : : .level = table_level,
11863 : : .id = table_id,
11864 : : .reserved = 0,
11865 : 0 : .dummy = !!dummy,
11866 : 0 : .is_fdb = !!transfer,
11867 : 0 : .is_egress = !!egress,
11868 : : }
11869 : : };
11870 : 0 : struct mlx5_flow_tbl_tunnel_prm tt_prm = {
11871 : : .tunnel = tunnel,
11872 : : .group_id = group_id,
11873 : : .external = external,
11874 : : };
11875 : 0 : struct mlx5_flow_cb_ctx ctx = {
11876 : : .dev = dev,
11877 : : .error = error,
11878 : : .data = &table_key.v64,
11879 : : .data2 = &tt_prm,
11880 : : };
11881 : : struct mlx5_list_entry *entry;
11882 : : struct mlx5_flow_tbl_data_entry *tbl_data;
11883 : :
11884 : 0 : entry = mlx5_hlist_register(priv->sh->flow_tbls, table_key.v64, &ctx);
11885 [ # # ]: 0 : if (!entry) {
11886 : 0 : rte_flow_error_set(error, ENOMEM,
11887 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11888 : : "cannot get table");
11889 : 0 : return NULL;
11890 : : }
11891 [ # # ]: 0 : DRV_LOG(DEBUG, "table_level %u table_id %u "
11892 : : "tunnel %u group %u registered.",
11893 : : table_level, table_id,
11894 : : tunnel ? tunnel->tunnel_id : 0, group_id);
11895 : : tbl_data = container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
11896 : 0 : return &tbl_data->tbl;
11897 : : }
11898 : :
11899 : : void
11900 : 0 : flow_dv_tbl_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
11901 : : {
11902 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11903 : : struct mlx5_flow_tbl_data_entry *tbl_data =
11904 : : container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
11905 : :
11906 : : MLX5_ASSERT(entry && sh);
11907 [ # # ]: 0 : if (tbl_data->jump.action)
11908 : : mlx5_flow_os_destroy_flow_action(tbl_data->jump.action);
11909 [ # # ]: 0 : if (tbl_data->tbl.obj)
11910 : : mlx5_flow_os_destroy_flow_tbl(tbl_data->tbl.obj);
11911 [ # # ]: 0 : if (tbl_data->tunnel_offload && tbl_data->external) {
11912 : : struct mlx5_list_entry *he;
11913 : : struct mlx5_hlist *tunnel_grp_hash;
11914 : 0 : struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
11915 : 0 : union tunnel_tbl_key tunnel_key = {
11916 : 0 : .tunnel_id = tbl_data->tunnel ?
11917 [ # # ]: 0 : tbl_data->tunnel->tunnel_id : 0,
11918 : 0 : .group = tbl_data->group_id
11919 : : };
11920 : 0 : uint32_t table_level = tbl_data->level;
11921 : 0 : struct mlx5_flow_cb_ctx ctx = {
11922 : : .data = (void *)&tunnel_key.val,
11923 : : };
11924 : :
11925 : : tunnel_grp_hash = tbl_data->tunnel ?
11926 [ # # ]: 0 : tbl_data->tunnel->groups :
11927 : : thub->groups;
11928 : 0 : he = mlx5_hlist_lookup(tunnel_grp_hash, tunnel_key.val, &ctx);
11929 [ # # ]: 0 : if (he)
11930 : 0 : mlx5_hlist_unregister(tunnel_grp_hash, he);
11931 [ # # ]: 0 : DRV_LOG(DEBUG,
11932 : : "table_level %u id %u tunnel %u group %u released.",
11933 : : table_level,
11934 : : tbl_data->id,
11935 : : tbl_data->tunnel ?
11936 : : tbl_data->tunnel->tunnel_id : 0,
11937 : : tbl_data->group_id);
11938 : : }
11939 [ # # ]: 0 : if (tbl_data->matchers)
11940 : 0 : mlx5_list_destroy(tbl_data->matchers);
11941 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], tbl_data->idx);
11942 : 0 : }
11943 : :
11944 : : /**
11945 : : * Release a flow table.
11946 : : *
11947 : : * @param[in] sh
11948 : : * Pointer to device shared structure.
11949 : : * @param[in] tbl
11950 : : * Table resource to be released.
11951 : : *
11952 : : * @return
11953 : : * Returns 0 if table was released, else return 1;
11954 : : */
11955 : : int
11956 : 0 : flow_dv_tbl_resource_release(struct mlx5_dev_ctx_shared *sh,
11957 : : struct mlx5_flow_tbl_resource *tbl)
11958 : : {
11959 : : struct mlx5_flow_tbl_data_entry *tbl_data =
11960 : 0 : container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
11961 : :
11962 [ # # ]: 0 : if (!tbl)
11963 : : return 0;
11964 : 0 : return mlx5_hlist_unregister(sh->flow_tbls, &tbl_data->entry);
11965 : : }
11966 : :
11967 : : int
11968 : 0 : flow_matcher_match_cb(void *tool_ctx __rte_unused,
11969 : : struct mlx5_list_entry *entry, void *cb_ctx)
11970 : : {
11971 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11972 : 0 : struct mlx5_flow_dv_matcher *ref = ctx->data;
11973 : : struct mlx5_flow_dv_matcher *cur = container_of(entry, typeof(*cur),
11974 : : entry);
11975 : :
11976 : 0 : return cur->crc != ref->crc ||
11977 [ # # ]: 0 : cur->priority != ref->priority ||
11978 : 0 : memcmp((const void *)cur->mask.buf,
11979 [ # # ]: 0 : (const void *)ref->mask.buf, ref->mask.size);
11980 : : }
11981 : :
11982 : : struct mlx5_list_entry *
11983 : 0 : flow_matcher_create_cb(void *tool_ctx, void *cb_ctx)
11984 : : {
11985 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11986 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11987 : 0 : struct mlx5_flow_dv_matcher *ref = ctx->data;
11988 : : struct mlx5_flow_dv_matcher *resource;
11989 : : #ifdef HAVE_MLX5_HWS_SUPPORT
11990 : : const struct rte_flow_item *items;
11991 : : #endif
11992 : 0 : struct mlx5dv_flow_matcher_attr dv_attr = {
11993 : : .type = IBV_FLOW_ATTR_NORMAL,
11994 : 0 : .match_mask = (void *)&ref->mask,
11995 : : };
11996 : : struct mlx5_flow_tbl_data_entry *tbl;
11997 : : int ret;
11998 : :
11999 : 0 : resource = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*resource), 0,
12000 : : SOCKET_ID_ANY);
12001 [ # # ]: 0 : if (!resource) {
12002 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12003 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12004 : : "cannot create matcher");
12005 : 0 : return NULL;
12006 : : }
12007 : 0 : *resource = *ref;
12008 [ # # ]: 0 : if (sh->config.dv_flow_en != 2) {
12009 : 0 : tbl = container_of(ref->tbl, typeof(*tbl), tbl);
12010 : 0 : dv_attr.match_criteria_enable =
12011 [ # # ]: 0 : flow_dv_matcher_enable(resource->mask.buf);
12012 : : __flow_dv_adjust_buf_size(&ref->mask.size,
12013 : : dv_attr.match_criteria_enable);
12014 : 0 : dv_attr.priority = ref->priority;
12015 [ # # ]: 0 : if (tbl->is_egress)
12016 : 0 : dv_attr.flags |= IBV_FLOW_ATTR_FLAGS_EGRESS;
12017 : 0 : ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
12018 : : tbl->tbl.obj,
12019 : : &resource->matcher_object);
12020 : : if (ret) {
12021 : 0 : mlx5_free(resource);
12022 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12023 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12024 : : "cannot create matcher");
12025 : 0 : return NULL;
12026 : : }
12027 : : } else {
12028 : : #ifdef HAVE_MLX5_HWS_SUPPORT
12029 : 0 : items = *((const struct rte_flow_item **)(ctx->data2));
12030 : 0 : resource->matcher_object = mlx5dr_bwc_matcher_create
12031 : 0 : (resource->group->tbl, resource->priority, items);
12032 [ # # ]: 0 : if (!resource->matcher_object) {
12033 : 0 : mlx5_free(resource);
12034 : 0 : return NULL;
12035 : : }
12036 : : #else
12037 : : mlx5_free(resource);
12038 : : return NULL;
12039 : : #endif
12040 : : }
12041 : 0 : return &resource->entry;
12042 : : }
12043 : :
12044 : : /**
12045 : : * Register the flow matcher.
12046 : : *
12047 : : * @param[in, out] dev
12048 : : * Pointer to rte_eth_dev structure.
12049 : : * @param[in, out] matcher
12050 : : * Pointer to flow matcher.
12051 : : * @param[in, out] key
12052 : : * Pointer to flow table key.
12053 : : * @parm[in, out] dev_flow
12054 : : * Pointer to the dev_flow.
12055 : : * @param[out] error
12056 : : * pointer to error structure.
12057 : : *
12058 : : * @return
12059 : : * 0 on success otherwise -errno and errno is set.
12060 : : */
12061 : : static int
12062 : 0 : flow_dv_matcher_register(struct rte_eth_dev *dev,
12063 : : struct mlx5_flow_dv_matcher *ref,
12064 : : union mlx5_flow_tbl_key *key,
12065 : : struct mlx5_flow *dev_flow,
12066 : : const struct mlx5_flow_tunnel *tunnel,
12067 : : uint32_t group_id,
12068 : : struct rte_flow_error *error)
12069 : : {
12070 : : struct mlx5_list_entry *entry;
12071 : : struct mlx5_flow_dv_matcher *resource;
12072 : : struct mlx5_flow_tbl_resource *tbl;
12073 : : struct mlx5_flow_tbl_data_entry *tbl_data;
12074 : 0 : struct mlx5_flow_cb_ctx ctx = {
12075 : : .error = error,
12076 : : .data = ref,
12077 : : };
12078 : : /**
12079 : : * tunnel offload API requires this registration for cases when
12080 : : * tunnel match rule was inserted before tunnel set rule.
12081 : : */
12082 : 0 : tbl = flow_dv_tbl_resource_get(dev, key->level,
12083 : 0 : key->is_egress, key->is_fdb,
12084 : 0 : dev_flow->external, tunnel,
12085 : 0 : group_id, 0, key->id, error);
12086 [ # # ]: 0 : if (!tbl)
12087 : 0 : return -rte_errno; /* No need to refill the error info */
12088 : 0 : tbl_data = container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
12089 : 0 : ref->tbl = tbl;
12090 : 0 : entry = mlx5_list_register(tbl_data->matchers, &ctx);
12091 [ # # ]: 0 : if (!entry) {
12092 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
12093 : 0 : return rte_flow_error_set(error, ENOMEM,
12094 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12095 : : "cannot allocate ref memory");
12096 : : }
12097 : : resource = container_of(entry, typeof(*resource), entry);
12098 : 0 : dev_flow->handle->dvh.matcher = resource;
12099 : 0 : return 0;
12100 : : }
12101 : :
12102 : : struct mlx5_list_entry *
12103 : 0 : flow_dv_tag_create_cb(void *tool_ctx, void *cb_ctx)
12104 : : {
12105 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
12106 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12107 : : struct mlx5_flow_dv_tag_resource *entry;
12108 : 0 : uint32_t idx = 0;
12109 : : int ret;
12110 : :
12111 : 0 : entry = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_TAG], &idx);
12112 [ # # ]: 0 : if (!entry) {
12113 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12114 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12115 : : "cannot allocate resource memory");
12116 : 0 : return NULL;
12117 : : }
12118 : 0 : entry->idx = idx;
12119 : 0 : entry->tag_id = *(uint32_t *)(ctx->data);
12120 : : ret = mlx5_flow_os_create_flow_action_tag(entry->tag_id,
12121 : : &entry->action);
12122 : : if (ret) {
12123 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], idx);
12124 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12125 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12126 : : NULL, "cannot create action");
12127 : 0 : return NULL;
12128 : : }
12129 : 0 : return &entry->entry;
12130 : : }
12131 : :
12132 : : int
12133 : 0 : flow_dv_tag_match_cb(void *tool_ctx __rte_unused, struct mlx5_list_entry *entry,
12134 : : void *cb_ctx)
12135 : : {
12136 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12137 : : struct mlx5_flow_dv_tag_resource *tag =
12138 : : container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
12139 : :
12140 : 0 : return *(uint32_t *)(ctx->data) != tag->tag_id;
12141 : : }
12142 : :
12143 : : struct mlx5_list_entry *
12144 : 0 : flow_dv_tag_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
12145 : : void *cb_ctx)
12146 : : {
12147 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
12148 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12149 : : struct mlx5_flow_dv_tag_resource *entry;
12150 : 0 : uint32_t idx = 0;
12151 : :
12152 : 0 : entry = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_TAG], &idx);
12153 [ # # ]: 0 : if (!entry) {
12154 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12155 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12156 : : "cannot allocate tag resource memory");
12157 : 0 : return NULL;
12158 : : }
12159 : : memcpy(entry, oentry, sizeof(*entry));
12160 : 0 : entry->idx = idx;
12161 : 0 : return &entry->entry;
12162 : : }
12163 : :
12164 : : void
12165 : 0 : flow_dv_tag_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
12166 : : {
12167 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
12168 : : struct mlx5_flow_dv_tag_resource *tag =
12169 : : container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
12170 : :
12171 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], tag->idx);
12172 : 0 : }
12173 : :
12174 : : /**
12175 : : * Find existing tag resource or create and register a new one.
12176 : : *
12177 : : * @param dev[in, out]
12178 : : * Pointer to rte_eth_dev structure.
12179 : : * @param[in, out] tag_be24
12180 : : * Tag value in big endian then R-shift 8.
12181 : : * @parm[in, out] dev_flow
12182 : : * Pointer to the dev_flow.
12183 : : * @param[out] error
12184 : : * pointer to error structure.
12185 : : *
12186 : : * @return
12187 : : * 0 on success otherwise -errno and errno is set.
12188 : : */
12189 : : static int
12190 : 0 : flow_dv_tag_resource_register
12191 : : (struct rte_eth_dev *dev,
12192 : : uint32_t tag_be24,
12193 : : struct mlx5_flow *dev_flow,
12194 : : struct rte_flow_error *error)
12195 : : {
12196 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12197 : : struct mlx5_flow_dv_tag_resource *resource;
12198 : : struct mlx5_list_entry *entry;
12199 : 0 : struct mlx5_flow_cb_ctx ctx = {
12200 : : .error = error,
12201 : : .data = &tag_be24,
12202 : : };
12203 : : struct mlx5_hlist *tag_table;
12204 : :
12205 : 0 : tag_table = flow_dv_hlist_prepare(priv->sh, &priv->sh->tag_table,
12206 : : "tags",
12207 : : MLX5_TAGS_HLIST_ARRAY_SIZE,
12208 : 0 : false, false, priv->sh,
12209 : : flow_dv_tag_create_cb,
12210 : : flow_dv_tag_match_cb,
12211 : : flow_dv_tag_remove_cb,
12212 : : flow_dv_tag_clone_cb,
12213 : : flow_dv_tag_clone_free_cb,
12214 : : error);
12215 [ # # ]: 0 : if (unlikely(!tag_table))
12216 : 0 : return -rte_errno;
12217 : 0 : entry = mlx5_hlist_register(tag_table, tag_be24, &ctx);
12218 [ # # ]: 0 : if (entry) {
12219 : : resource = container_of(entry, struct mlx5_flow_dv_tag_resource,
12220 : : entry);
12221 : 0 : dev_flow->handle->dvh.rix_tag = resource->idx;
12222 : 0 : dev_flow->dv.tag_resource = resource;
12223 : 0 : return 0;
12224 : : }
12225 : 0 : return -rte_errno;
12226 : : }
12227 : :
12228 : : void
12229 : 0 : flow_dv_tag_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
12230 : : {
12231 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
12232 : : struct mlx5_flow_dv_tag_resource *tag =
12233 : : container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
12234 : :
12235 : : MLX5_ASSERT(tag && sh && tag->action);
12236 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(tag->action));
12237 : 0 : DRV_LOG(DEBUG, "Tag %p: removed.", (void *)tag);
12238 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], tag->idx);
12239 : 0 : }
12240 : :
12241 : : /**
12242 : : * Release the tag.
12243 : : *
12244 : : * @param dev
12245 : : * Pointer to Ethernet device.
12246 : : * @param tag_idx
12247 : : * Tag index.
12248 : : *
12249 : : * @return
12250 : : * 1 while a reference on it exists, 0 when freed.
12251 : : */
12252 : : static int
12253 : 0 : flow_dv_tag_release(struct rte_eth_dev *dev,
12254 : : uint32_t tag_idx)
12255 : : {
12256 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12257 : : struct mlx5_flow_dv_tag_resource *tag;
12258 : :
12259 : 0 : tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG], tag_idx);
12260 [ # # ]: 0 : if (!tag)
12261 : : return 0;
12262 : 0 : DRV_LOG(DEBUG, "port %u tag %p: refcnt %d--",
12263 : : dev->data->port_id, (void *)tag, tag->entry.ref_cnt);
12264 : 0 : return mlx5_hlist_unregister(priv->sh->tag_table, &tag->entry);
12265 : : }
12266 : :
12267 : : /**
12268 : : * Translate action PORT_ID / REPRESENTED_PORT to vport.
12269 : : *
12270 : : * @param[in] dev
12271 : : * Pointer to rte_eth_dev structure.
12272 : : * @param[in] action
12273 : : * Pointer to action PORT_ID / REPRESENTED_PORT.
12274 : : * @param[out] dst_port_id
12275 : : * The target port ID.
12276 : : * @param[out] error
12277 : : * Pointer to the error structure.
12278 : : *
12279 : : * @return
12280 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
12281 : : */
12282 : : static int
12283 : 0 : flow_dv_translate_action_port_id(struct rte_eth_dev *dev,
12284 : : const struct rte_flow_action *action,
12285 : : uint32_t *dst_port_id,
12286 : : struct rte_flow_error *error)
12287 : : {
12288 : : uint32_t port;
12289 : : struct mlx5_priv *priv;
12290 : :
12291 [ # # # ]: 0 : switch (action->type) {
12292 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID: {
12293 : : const struct rte_flow_action_port_id *conf;
12294 : :
12295 : 0 : conf = (const struct rte_flow_action_port_id *)action->conf;
12296 [ # # ]: 0 : port = conf->original ? dev->data->port_id : conf->id;
12297 : : break;
12298 : : }
12299 : 0 : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT: {
12300 : : const struct rte_flow_action_ethdev *ethdev;
12301 : :
12302 : 0 : ethdev = (const struct rte_flow_action_ethdev *)action->conf;
12303 : 0 : port = ethdev->port_id;
12304 : 0 : break;
12305 : : }
12306 : 0 : default:
12307 : : MLX5_ASSERT(false);
12308 : 0 : return rte_flow_error_set(error, EINVAL,
12309 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
12310 : : "unknown E-Switch action");
12311 : : }
12312 : :
12313 : 0 : priv = mlx5_port_to_eswitch_info(port, false);
12314 [ # # ]: 0 : if (!priv)
12315 : 0 : return rte_flow_error_set(error, -rte_errno,
12316 : : RTE_FLOW_ERROR_TYPE_ACTION,
12317 : : NULL,
12318 : : "No eswitch info was found for port");
12319 : : #ifdef HAVE_MLX5DV_DR_CREATE_DEST_IB_PORT
12320 : : /*
12321 : : * This parameter is transferred to
12322 : : * mlx5dv_dr_action_create_dest_ib_port().
12323 : : */
12324 : 0 : *dst_port_id = priv->dev_port;
12325 : : #else
12326 : : /*
12327 : : * Legacy mode, no LAG configurations is supported.
12328 : : * This parameter is transferred to
12329 : : * mlx5dv_dr_action_create_dest_vport().
12330 : : */
12331 : : *dst_port_id = priv->vport_id;
12332 : : #endif
12333 : 0 : return 0;
12334 : : }
12335 : :
12336 : : /**
12337 : : * Create a counter with aging configuration.
12338 : : *
12339 : : * @param[in] dev
12340 : : * Pointer to rte_eth_dev structure.
12341 : : * @param[in] dev_flow
12342 : : * Pointer to the mlx5_flow.
12343 : : * @param[out] count
12344 : : * Pointer to the counter action configuration.
12345 : : * @param[in] age
12346 : : * Pointer to the aging action configuration.
12347 : : *
12348 : : * @return
12349 : : * Index to flow counter on success, 0 otherwise.
12350 : : */
12351 : : static uint32_t
12352 : 0 : flow_dv_translate_create_counter(struct rte_eth_dev *dev,
12353 : : struct mlx5_flow *dev_flow,
12354 : : const struct rte_flow_action_count *count
12355 : : __rte_unused,
12356 : : const struct rte_flow_action_age *age)
12357 : : {
12358 : : uint32_t counter;
12359 : : struct mlx5_age_param *age_param;
12360 : :
12361 : 0 : counter = flow_dv_counter_alloc(dev, !!age);
12362 [ # # ]: 0 : if (!counter || age == NULL)
12363 : : return counter;
12364 : : age_param = flow_dv_counter_idx_get_age(dev, counter);
12365 [ # # ]: 0 : age_param->context = age->context ? age->context :
12366 : 0 : (void *)(uintptr_t)(dev_flow->flow_idx);
12367 : 0 : age_param->timeout = age->timeout;
12368 : 0 : age_param->port_id = dev->data->port_id;
12369 : 0 : rte_atomic_store_explicit(&age_param->sec_since_last_hit, 0, rte_memory_order_relaxed);
12370 : 0 : rte_atomic_store_explicit(&age_param->state, AGE_CANDIDATE, rte_memory_order_relaxed);
12371 : 0 : return counter;
12372 : : }
12373 : :
12374 : : /**
12375 : : * Add Tx queue matcher
12376 : : *
12377 : : * @param[in] dev
12378 : : * Pointer to rte_eth_dev structure.
12379 : : * @param[in, out] key
12380 : : * Flow matcher value.
12381 : : * @param[in] item
12382 : : * Flow pattern to translate.
12383 : : * @param[in] key_type
12384 : : * Set flow matcher mask or value.
12385 : : *
12386 : : * @return
12387 : : * 0 on success otherwise -errno and errno is set.
12388 : : */
12389 : : static int
12390 : 0 : flow_dv_translate_item_tx_queue(struct rte_eth_dev *dev, void *key,
12391 : : const struct rte_flow_item *item, uint32_t key_type)
12392 : : {
12393 : : const struct rte_flow_item_tx_queue *queue_m;
12394 : : const struct rte_flow_item_tx_queue *queue_v;
12395 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
12396 : : uint32_t tx_queue;
12397 : : uint32_t sqn = 0;
12398 : : int ret;
12399 : :
12400 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, queue_v, queue_m, &rte_flow_item_tx_queue_mask);
# # # # ]
12401 [ # # ]: 0 : if (!queue_m || !queue_v)
12402 : : return -EINVAL;
12403 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_V) {
12404 : 0 : tx_queue = queue_v->tx_queue;
12405 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_V)
12406 : 0 : tx_queue &= queue_m->tx_queue;
12407 [ # # ]: 0 : ret = flow_hw_get_sqn(dev, tx_queue, &sqn);
12408 [ # # ]: 0 : if (unlikely(ret))
12409 : 0 : return -ret;
12410 : : } else {
12411 : : /* Due to tx_queue to sqn converting, only fully masked value support. */
12412 [ # # ]: 0 : if (queue_m->tx_queue != rte_flow_item_tx_queue_mask.tx_queue)
12413 : : return -EINVAL;
12414 : : sqn = UINT32_MAX;
12415 : : }
12416 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, source_sqn, sqn);
12417 : 0 : return 0;
12418 : : }
12419 : :
12420 : : /**
12421 : : * Add SQ matcher
12422 : : *
12423 : : * @param[in, out] matcher
12424 : : * Flow matcher.
12425 : : * @param[in, out] key
12426 : : * Flow matcher value.
12427 : : * @param[in] item
12428 : : * Flow pattern to translate.
12429 : : * @param[in] key_type
12430 : : * Set flow matcher mask or value.
12431 : : */
12432 : : static void
12433 : 0 : flow_dv_translate_item_sq(void *key,
12434 : : const struct rte_flow_item *item,
12435 : : uint32_t key_type)
12436 : : {
12437 : : const struct mlx5_rte_flow_item_sq *queue_m;
12438 : : const struct mlx5_rte_flow_item_sq *queue_v;
12439 : 0 : const struct mlx5_rte_flow_item_sq queue_mask = {
12440 : : .queue = UINT32_MAX,
12441 : : };
12442 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
12443 : : uint32_t queue;
12444 : :
12445 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, queue_v, queue_m, &queue_mask);
# # # # ]
12446 [ # # ]: 0 : if (!queue_m || !queue_v)
12447 : 0 : return;
12448 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_V) {
12449 : 0 : queue = queue_v->queue;
12450 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_V)
12451 : 0 : queue &= queue_m->queue;
12452 : : } else {
12453 : 0 : queue = queue_m->queue;
12454 : : }
12455 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, source_sqn, queue);
12456 : : }
12457 : :
12458 : : /**
12459 : : * Set the hash fields according to the @p flow information.
12460 : : *
12461 : : * @param[in] item_flags
12462 : : * The match pattern item flags.
12463 : : * @param[in] rss_desc
12464 : : * Pointer to the mlx5_flow_rss_desc.
12465 : : * @param[out] hash_fields
12466 : : * Pointer to the RSS hash fields.
12467 : : */
12468 : : void
12469 : 0 : flow_dv_hashfields_set(uint64_t item_flags,
12470 : : struct mlx5_flow_rss_desc *rss_desc,
12471 : : uint64_t *hash_fields)
12472 : : {
12473 : : uint64_t items = item_flags;
12474 : : uint64_t fields = 0;
12475 : : int rss_inner = 0;
12476 [ # # ]: 0 : uint64_t rss_types = rte_eth_rss_hf_refine(rss_desc->types);
12477 : :
12478 : : *hash_fields = 0;
12479 : : #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
12480 [ # # ]: 0 : if (rss_desc->level >= 2)
12481 : : rss_inner = 1;
12482 : : #endif
12483 [ # # # # ]: 0 : if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV4)) ||
12484 [ # # ]: 0 : (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV4))) {
12485 [ # # ]: 0 : if (rss_types & MLX5_IPV4_LAYER_TYPES) {
12486 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
12487 : : fields |= IBV_RX_HASH_SRC_IPV4;
12488 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
12489 : : fields |= IBV_RX_HASH_DST_IPV4;
12490 : : else
12491 : : fields |= MLX5_IPV4_IBV_RX_HASH;
12492 : : }
12493 [ # # # # : 0 : } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
# # ]
12494 [ # # ]: 0 : (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV6))) {
12495 [ # # ]: 0 : if (rss_types & MLX5_IPV6_LAYER_TYPES) {
12496 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
12497 : : fields |= IBV_RX_HASH_SRC_IPV6;
12498 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
12499 : : fields |= IBV_RX_HASH_DST_IPV6;
12500 : : else
12501 : : fields |= MLX5_IPV6_IBV_RX_HASH;
12502 : : }
12503 : : }
12504 [ # # ]: 0 : if (items & MLX5_FLOW_ITEM_ESP) {
12505 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_ESP)
12506 : 0 : fields |= IBV_RX_HASH_IPSEC_SPI;
12507 : : }
12508 [ # # ]: 0 : if ((fields & ~IBV_RX_HASH_IPSEC_SPI) == 0) {
12509 : 0 : *hash_fields = fields;
12510 : : /*
12511 : : * There is no match between the RSS types and the
12512 : : * L3 protocol (IPv4/IPv6) defined in the flow rule.
12513 : : */
12514 : 0 : return;
12515 : : }
12516 [ # # # # : 0 : if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_UDP)) ||
# # ]
12517 [ # # ]: 0 : (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_UDP))) {
12518 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_UDP) {
12519 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
12520 : 0 : fields |= IBV_RX_HASH_SRC_PORT_UDP;
12521 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
12522 : 0 : fields |= IBV_RX_HASH_DST_PORT_UDP;
12523 : : else
12524 : 0 : fields |= MLX5_UDP_IBV_RX_HASH;
12525 : : }
12526 [ # # # # : 0 : } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_TCP)) ||
# # ]
12527 [ # # ]: 0 : (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_TCP))) {
12528 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_TCP) {
12529 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
12530 : 0 : fields |= IBV_RX_HASH_SRC_PORT_TCP;
12531 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
12532 : 0 : fields |= IBV_RX_HASH_DST_PORT_TCP;
12533 : : else
12534 : 0 : fields |= MLX5_TCP_IBV_RX_HASH;
12535 : : }
12536 : : }
12537 [ # # ]: 0 : if (rss_inner)
12538 : 0 : fields |= IBV_RX_HASH_INNER;
12539 : 0 : *hash_fields = fields;
12540 : : }
12541 : :
12542 : : /**
12543 : : * Prepare an Rx Hash queue.
12544 : : *
12545 : : * @param dev
12546 : : * Pointer to Ethernet device.
12547 : : * @param[in] dev_flow
12548 : : * Pointer to the mlx5_flow.
12549 : : * @param[in] rss_desc
12550 : : * Pointer to the mlx5_flow_rss_desc.
12551 : : * @param[out] hrxq_idx
12552 : : * Hash Rx queue index.
12553 : : *
12554 : : * @return
12555 : : * The Verbs/DevX object initialised, NULL otherwise and rte_errno is set.
12556 : : */
12557 : : static struct mlx5_hrxq *
12558 : 0 : flow_dv_hrxq_prepare(struct rte_eth_dev *dev,
12559 : : struct mlx5_flow *dev_flow,
12560 : : struct mlx5_flow_rss_desc *rss_desc,
12561 : : uint32_t *hrxq_idx)
12562 : : {
12563 : 0 : struct mlx5_flow_handle *dh = dev_flow->handle;
12564 : 0 : uint32_t shared_rss = rss_desc->shared_rss;
12565 : : struct mlx5_hrxq *hrxq;
12566 : :
12567 : : MLX5_ASSERT(rss_desc->queue_num);
12568 : 0 : rss_desc->symmetric_hash_function = dev_flow->symmetric_hash_function;
12569 : 0 : rss_desc->key_len = MLX5_RSS_HASH_KEY_LEN;
12570 : 0 : rss_desc->hash_fields = dev_flow->hash_fields;
12571 : 0 : rss_desc->tunnel = !!(dh->layers & MLX5_FLOW_LAYER_TUNNEL);
12572 : 0 : rss_desc->shared_rss = 0;
12573 [ # # ]: 0 : if (rss_desc->hash_fields == 0)
12574 : 0 : rss_desc->queue_num = 1;
12575 : 0 : hrxq = mlx5_hrxq_get(dev, rss_desc);
12576 [ # # ]: 0 : *hrxq_idx = hrxq ? hrxq->idx : 0;
12577 : 0 : rss_desc->shared_rss = shared_rss;
12578 : 0 : return hrxq;
12579 : : }
12580 : :
12581 : : /**
12582 : : * Release sample sub action resource.
12583 : : *
12584 : : * @param[in, out] dev
12585 : : * Pointer to rte_eth_dev structure.
12586 : : * @param[in] act_res
12587 : : * Pointer to sample sub action resource.
12588 : : */
12589 : : static void
12590 : 0 : flow_dv_sample_sub_actions_release(struct rte_eth_dev *dev,
12591 : : struct mlx5_flow_sub_actions_idx *act_res)
12592 : : {
12593 [ # # ]: 0 : if (act_res->rix_hrxq) {
12594 : 0 : mlx5_hrxq_release(dev, act_res->rix_hrxq);
12595 : 0 : act_res->rix_hrxq = 0;
12596 : : }
12597 [ # # ]: 0 : if (act_res->rix_encap_decap) {
12598 : 0 : flow_encap_decap_resource_release(dev,
12599 : : act_res->rix_encap_decap);
12600 : 0 : act_res->rix_encap_decap = 0;
12601 : : }
12602 [ # # ]: 0 : if (act_res->rix_port_id_action) {
12603 : 0 : flow_dv_port_id_action_resource_release(dev,
12604 : : act_res->rix_port_id_action);
12605 : 0 : act_res->rix_port_id_action = 0;
12606 : : }
12607 [ # # ]: 0 : if (act_res->rix_tag) {
12608 : 0 : flow_dv_tag_release(dev, act_res->rix_tag);
12609 : 0 : act_res->rix_tag = 0;
12610 : : }
12611 [ # # ]: 0 : if (act_res->rix_jump) {
12612 : 0 : flow_dv_jump_tbl_resource_release(dev, act_res->rix_jump);
12613 : 0 : act_res->rix_jump = 0;
12614 : : }
12615 : 0 : }
12616 : :
12617 : : int
12618 : 0 : flow_dv_sample_match_cb(void *tool_ctx __rte_unused,
12619 : : struct mlx5_list_entry *entry, void *cb_ctx)
12620 : : {
12621 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12622 : 0 : struct rte_eth_dev *dev = ctx->dev;
12623 : 0 : struct mlx5_flow_dv_sample_resource *ctx_resource = ctx->data;
12624 : : struct mlx5_flow_dv_sample_resource *resource = container_of(entry,
12625 : : typeof(*resource),
12626 : : entry);
12627 : :
12628 [ # # ]: 0 : if (ctx_resource->ratio == resource->ratio &&
12629 [ # # ]: 0 : ctx_resource->ft_type == resource->ft_type &&
12630 [ # # ]: 0 : ctx_resource->ft_id == resource->ft_id &&
12631 [ # # ]: 0 : ctx_resource->set_action == resource->set_action &&
12632 : 0 : !memcmp((void *)&ctx_resource->sample_act,
12633 [ # # ]: 0 : (void *)&resource->sample_act,
12634 : : sizeof(struct mlx5_flow_sub_actions_list))) {
12635 : : /*
12636 : : * Existing sample action should release the prepared
12637 : : * sub-actions reference counter.
12638 : : */
12639 : 0 : flow_dv_sample_sub_actions_release(dev,
12640 : : &ctx_resource->sample_idx);
12641 : 0 : return 0;
12642 : : }
12643 : : return 1;
12644 : : }
12645 : :
12646 : : struct mlx5_list_entry *
12647 : 0 : flow_dv_sample_create_cb(void *tool_ctx __rte_unused, void *cb_ctx)
12648 : : {
12649 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12650 : 0 : struct rte_eth_dev *dev = ctx->dev;
12651 : 0 : struct mlx5_flow_dv_sample_resource *ctx_resource = ctx->data;
12652 : 0 : void **sample_dv_actions = ctx_resource->sub_actions;
12653 : : struct mlx5_flow_dv_sample_resource *resource;
12654 : : struct mlx5dv_dr_flow_sampler_attr sampler_attr;
12655 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12656 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
12657 : : struct mlx5_flow_tbl_resource *tbl;
12658 : 0 : uint32_t idx = 0;
12659 : : const uint32_t next_ft_step = 1;
12660 : 0 : uint32_t next_ft_id = ctx_resource->ft_id + next_ft_step;
12661 : : uint8_t is_egress = 0;
12662 : : uint8_t is_transfer = 0;
12663 : 0 : struct rte_flow_error *error = ctx->error;
12664 : :
12665 : : /* Register new sample resource. */
12666 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_SAMPLE], &idx);
12667 [ # # ]: 0 : if (!resource) {
12668 : 0 : rte_flow_error_set(error, ENOMEM,
12669 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12670 : : NULL,
12671 : : "cannot allocate resource memory");
12672 : 0 : return NULL;
12673 : : }
12674 : 0 : *resource = *ctx_resource;
12675 : : /* Create normal path table level */
12676 [ # # ]: 0 : if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
12677 : : is_transfer = 1;
12678 [ # # ]: 0 : else if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
12679 : : is_egress = 1;
12680 : 0 : tbl = flow_dv_tbl_resource_get(dev, next_ft_id,
12681 : : is_egress, is_transfer,
12682 : : true, NULL, 0, 0, 0, error);
12683 [ # # ]: 0 : if (!tbl) {
12684 : 0 : rte_flow_error_set(error, ENOMEM,
12685 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12686 : : NULL,
12687 : : "fail to create normal path table "
12688 : : "for sample");
12689 : 0 : goto error;
12690 : : }
12691 : 0 : resource->normal_path_tbl = tbl;
12692 [ # # ]: 0 : if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB) {
12693 [ # # ]: 0 : if (!sh->default_miss_action) {
12694 : 0 : rte_flow_error_set(error, ENOMEM,
12695 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12696 : : NULL,
12697 : : "default miss action was not "
12698 : : "created");
12699 : 0 : goto error;
12700 : : }
12701 : 0 : sample_dv_actions[ctx_resource->sample_act.actions_num++] =
12702 : : sh->default_miss_action;
12703 : : }
12704 : : /* Create a DR sample action */
12705 : 0 : sampler_attr.sample_ratio = resource->ratio;
12706 : 0 : sampler_attr.default_next_table = tbl->obj;
12707 : 0 : sampler_attr.num_sample_actions = ctx_resource->sample_act.actions_num;
12708 : 0 : sampler_attr.sample_actions = (struct mlx5dv_dr_action **)
12709 : : &sample_dv_actions[0];
12710 : 0 : sampler_attr.action = resource->set_action;
12711 : : if (mlx5_os_flow_dr_create_flow_action_sampler
12712 : : (&sampler_attr, &resource->verbs_action)) {
12713 : 0 : rte_flow_error_set(error, ENOMEM,
12714 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12715 : : NULL, "cannot create sample action");
12716 : 0 : goto error;
12717 : : }
12718 : 0 : resource->idx = idx;
12719 : 0 : resource->dev = dev;
12720 : 0 : return &resource->entry;
12721 : 0 : error:
12722 [ # # ]: 0 : if (resource->ft_type != MLX5DV_FLOW_TABLE_TYPE_FDB)
12723 : 0 : flow_dv_sample_sub_actions_release(dev,
12724 : : &resource->sample_idx);
12725 [ # # ]: 0 : if (resource->normal_path_tbl)
12726 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev),
12727 : : resource->normal_path_tbl);
12728 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_SAMPLE], idx);
12729 : 0 : return NULL;
12730 : :
12731 : : }
12732 : :
12733 : : struct mlx5_list_entry *
12734 : 0 : flow_dv_sample_clone_cb(void *tool_ctx __rte_unused,
12735 : : struct mlx5_list_entry *entry __rte_unused,
12736 : : void *cb_ctx)
12737 : : {
12738 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12739 : 0 : struct rte_eth_dev *dev = ctx->dev;
12740 : : struct mlx5_flow_dv_sample_resource *resource;
12741 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12742 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
12743 : 0 : uint32_t idx = 0;
12744 : :
12745 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_SAMPLE], &idx);
12746 [ # # ]: 0 : if (!resource) {
12747 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12748 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12749 : : NULL,
12750 : : "cannot allocate resource memory");
12751 : 0 : return NULL;
12752 : : }
12753 : : memcpy(resource, entry, sizeof(*resource));
12754 : 0 : resource->idx = idx;
12755 : 0 : resource->dev = dev;
12756 : 0 : return &resource->entry;
12757 : : }
12758 : :
12759 : : void
12760 : 0 : flow_dv_sample_clone_free_cb(void *tool_ctx __rte_unused,
12761 : : struct mlx5_list_entry *entry)
12762 : : {
12763 : : struct mlx5_flow_dv_sample_resource *resource =
12764 : : container_of(entry, typeof(*resource), entry);
12765 : 0 : struct rte_eth_dev *dev = resource->dev;
12766 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12767 : :
12768 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_SAMPLE], resource->idx);
12769 : 0 : }
12770 : :
12771 : : /**
12772 : : * Find existing sample resource or create and register a new one.
12773 : : *
12774 : : * @param[in, out] dev
12775 : : * Pointer to rte_eth_dev structure.
12776 : : * @param[in] ref
12777 : : * Pointer to sample resource reference.
12778 : : * @parm[in, out] dev_flow
12779 : : * Pointer to the dev_flow.
12780 : : * @param[out] error
12781 : : * pointer to error structure.
12782 : : *
12783 : : * @return
12784 : : * 0 on success otherwise -errno and errno is set.
12785 : : */
12786 : : static int
12787 : 0 : flow_dv_sample_resource_register(struct rte_eth_dev *dev,
12788 : : struct mlx5_flow_dv_sample_resource *ref,
12789 : : struct mlx5_flow *dev_flow,
12790 : : struct rte_flow_error *error)
12791 : : {
12792 : : struct mlx5_flow_dv_sample_resource *resource;
12793 : : struct mlx5_list_entry *entry;
12794 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12795 : 0 : struct mlx5_flow_cb_ctx ctx = {
12796 : : .dev = dev,
12797 : : .error = error,
12798 : : .data = ref,
12799 : : };
12800 : :
12801 : 0 : entry = mlx5_list_register(priv->sh->sample_action_list, &ctx);
12802 [ # # ]: 0 : if (!entry)
12803 : 0 : return -rte_errno;
12804 : : resource = container_of(entry, typeof(*resource), entry);
12805 : 0 : dev_flow->handle->dvh.rix_sample = resource->idx;
12806 : 0 : dev_flow->dv.sample_res = resource;
12807 : 0 : return 0;
12808 : : }
12809 : :
12810 : : int
12811 : 0 : flow_dv_dest_array_match_cb(void *tool_ctx __rte_unused,
12812 : : struct mlx5_list_entry *entry, void *cb_ctx)
12813 : : {
12814 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12815 : 0 : struct mlx5_flow_dv_dest_array_resource *ctx_resource = ctx->data;
12816 : 0 : struct rte_eth_dev *dev = ctx->dev;
12817 : : struct mlx5_flow_dv_dest_array_resource *resource =
12818 : : container_of(entry, typeof(*resource), entry);
12819 : : uint32_t idx = 0;
12820 : :
12821 [ # # ]: 0 : if (ctx_resource->num_of_dest == resource->num_of_dest &&
12822 : 0 : ctx_resource->ft_type == resource->ft_type &&
12823 : 0 : !memcmp((void *)resource->sample_act,
12824 : 0 : (void *)ctx_resource->sample_act,
12825 [ # # ]: 0 : (ctx_resource->num_of_dest *
12826 : : sizeof(struct mlx5_flow_sub_actions_list)))) {
12827 : : /*
12828 : : * Existing sample action should release the prepared
12829 : : * sub-actions reference counter.
12830 : : */
12831 [ # # ]: 0 : for (idx = 0; idx < ctx_resource->num_of_dest; idx++)
12832 : 0 : flow_dv_sample_sub_actions_release(dev,
12833 : : &ctx_resource->sample_idx[idx]);
12834 : : return 0;
12835 : : }
12836 : : return 1;
12837 : : }
12838 : :
12839 : : struct mlx5_list_entry *
12840 : 0 : flow_dv_dest_array_create_cb(void *tool_ctx __rte_unused, void *cb_ctx)
12841 : : {
12842 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12843 : 0 : struct rte_eth_dev *dev = ctx->dev;
12844 : : struct mlx5_flow_dv_dest_array_resource *resource;
12845 : 0 : struct mlx5_flow_dv_dest_array_resource *ctx_resource = ctx->data;
12846 : 0 : struct mlx5dv_dr_action_dest_attr *dest_attr[MLX5_MAX_DEST_NUM] = { 0 };
12847 : : struct mlx5dv_dr_action_dest_reformat dest_reformat[MLX5_MAX_DEST_NUM];
12848 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12849 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
12850 : : struct mlx5_flow_sub_actions_list *sample_act;
12851 : : struct mlx5dv_dr_domain *domain;
12852 : 0 : uint32_t idx = 0, res_idx = 0;
12853 : 0 : struct rte_flow_error *error = ctx->error;
12854 : : uint64_t action_flags;
12855 : : int ret;
12856 : :
12857 : : /* Register new destination array resource. */
12858 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DEST_ARRAY],
12859 : : &res_idx);
12860 [ # # ]: 0 : if (!resource) {
12861 : 0 : rte_flow_error_set(error, ENOMEM,
12862 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12863 : : NULL,
12864 : : "cannot allocate resource memory");
12865 : 0 : return NULL;
12866 : : }
12867 : 0 : *resource = *ctx_resource;
12868 [ # # ]: 0 : if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
12869 : 0 : domain = sh->fdb_domain;
12870 [ # # ]: 0 : else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
12871 : 0 : domain = sh->rx_domain;
12872 : : else
12873 : 0 : domain = sh->tx_domain;
12874 [ # # ]: 0 : for (idx = 0; idx < ctx_resource->num_of_dest; idx++) {
12875 : 0 : dest_attr[idx] = (struct mlx5dv_dr_action_dest_attr *)
12876 : 0 : mlx5_malloc(MLX5_MEM_ZERO,
12877 : : sizeof(struct mlx5dv_dr_action_dest_attr),
12878 : : 0, SOCKET_ID_ANY);
12879 [ # # ]: 0 : if (!dest_attr[idx]) {
12880 : 0 : rte_flow_error_set(error, ENOMEM,
12881 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12882 : : NULL,
12883 : : "cannot allocate resource memory");
12884 : 0 : goto error;
12885 : : }
12886 : 0 : dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST;
12887 : : sample_act = &ctx_resource->sample_act[idx];
12888 : 0 : action_flags = sample_act->action_flags;
12889 [ # # # # : 0 : switch (action_flags) {
# ]
12890 : 0 : case MLX5_FLOW_ACTION_QUEUE:
12891 : 0 : dest_attr[idx]->dest = sample_act->dr_queue_action;
12892 : 0 : break;
12893 : 0 : case (MLX5_FLOW_ACTION_PORT_ID | MLX5_FLOW_ACTION_ENCAP):
12894 : 0 : dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST_REFORMAT;
12895 : 0 : dest_attr[idx]->dest_reformat = &dest_reformat[idx];
12896 : 0 : dest_attr[idx]->dest_reformat->reformat =
12897 : 0 : sample_act->dr_encap_action;
12898 : 0 : dest_attr[idx]->dest_reformat->dest =
12899 : 0 : sample_act->dr_port_id_action;
12900 : 0 : break;
12901 : 0 : case MLX5_FLOW_ACTION_PORT_ID:
12902 : 0 : dest_attr[idx]->dest = sample_act->dr_port_id_action;
12903 : 0 : break;
12904 : 0 : case MLX5_FLOW_ACTION_JUMP:
12905 : 0 : dest_attr[idx]->dest = sample_act->dr_jump_action;
12906 : 0 : break;
12907 : 0 : default:
12908 : 0 : rte_flow_error_set(error, EINVAL,
12909 : : RTE_FLOW_ERROR_TYPE_ACTION,
12910 : : NULL,
12911 : : "unsupported actions type");
12912 : 0 : goto error;
12913 : : }
12914 : : }
12915 : : /* create a dest array action */
12916 : 0 : ret = mlx5_os_flow_dr_create_flow_action_dest_array
12917 : : (domain,
12918 : 0 : resource->num_of_dest,
12919 : : dest_attr,
12920 : : &resource->action);
12921 : : if (ret) {
12922 : 0 : rte_flow_error_set(error, ENOMEM,
12923 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12924 : : NULL,
12925 : : "cannot create destination array action");
12926 : 0 : goto error;
12927 : : }
12928 : 0 : resource->idx = res_idx;
12929 : 0 : resource->dev = dev;
12930 [ # # ]: 0 : for (idx = 0; idx < ctx_resource->num_of_dest; idx++)
12931 : 0 : mlx5_free(dest_attr[idx]);
12932 : 0 : return &resource->entry;
12933 : : error:
12934 [ # # ]: 0 : for (idx = 0; idx < ctx_resource->num_of_dest; idx++) {
12935 : 0 : flow_dv_sample_sub_actions_release(dev,
12936 : : &resource->sample_idx[idx]);
12937 [ # # ]: 0 : if (dest_attr[idx])
12938 : 0 : mlx5_free(dest_attr[idx]);
12939 : : }
12940 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DEST_ARRAY], res_idx);
12941 : 0 : return NULL;
12942 : : }
12943 : :
12944 : : struct mlx5_list_entry *
12945 : 0 : flow_dv_dest_array_clone_cb(void *tool_ctx __rte_unused,
12946 : : struct mlx5_list_entry *entry __rte_unused,
12947 : : void *cb_ctx)
12948 : : {
12949 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12950 : 0 : struct rte_eth_dev *dev = ctx->dev;
12951 : : struct mlx5_flow_dv_dest_array_resource *resource;
12952 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12953 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
12954 : 0 : uint32_t res_idx = 0;
12955 : 0 : struct rte_flow_error *error = ctx->error;
12956 : :
12957 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DEST_ARRAY],
12958 : : &res_idx);
12959 [ # # ]: 0 : if (!resource) {
12960 : 0 : rte_flow_error_set(error, ENOMEM,
12961 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12962 : : NULL,
12963 : : "cannot allocate dest-array memory");
12964 : 0 : return NULL;
12965 : : }
12966 : : memcpy(resource, entry, sizeof(*resource));
12967 : 0 : resource->idx = res_idx;
12968 : 0 : resource->dev = dev;
12969 : 0 : return &resource->entry;
12970 : : }
12971 : :
12972 : : void
12973 : 0 : flow_dv_dest_array_clone_free_cb(void *tool_ctx __rte_unused,
12974 : : struct mlx5_list_entry *entry)
12975 : : {
12976 : : struct mlx5_flow_dv_dest_array_resource *resource =
12977 : : container_of(entry, typeof(*resource), entry);
12978 : 0 : struct rte_eth_dev *dev = resource->dev;
12979 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12980 : :
12981 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY], resource->idx);
12982 : 0 : }
12983 : :
12984 : : /**
12985 : : * Find existing destination array resource or create and register a new one.
12986 : : *
12987 : : * @param[in, out] dev
12988 : : * Pointer to rte_eth_dev structure.
12989 : : * @param[in] ref
12990 : : * Pointer to destination array resource reference.
12991 : : * @parm[in, out] dev_flow
12992 : : * Pointer to the dev_flow.
12993 : : * @param[out] error
12994 : : * pointer to error structure.
12995 : : *
12996 : : * @return
12997 : : * 0 on success otherwise -errno and errno is set.
12998 : : */
12999 : : static int
13000 : 0 : flow_dv_dest_array_resource_register(struct rte_eth_dev *dev,
13001 : : struct mlx5_flow_dv_dest_array_resource *ref,
13002 : : struct mlx5_flow *dev_flow,
13003 : : struct rte_flow_error *error)
13004 : : {
13005 : : struct mlx5_flow_dv_dest_array_resource *resource;
13006 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13007 : : struct mlx5_list_entry *entry;
13008 : 0 : struct mlx5_flow_cb_ctx ctx = {
13009 : : .dev = dev,
13010 : : .error = error,
13011 : : .data = ref,
13012 : : };
13013 : :
13014 : 0 : entry = mlx5_list_register(priv->sh->dest_array_list, &ctx);
13015 [ # # ]: 0 : if (!entry)
13016 : 0 : return -rte_errno;
13017 : : resource = container_of(entry, typeof(*resource), entry);
13018 : 0 : dev_flow->handle->dvh.rix_dest_array = resource->idx;
13019 : 0 : dev_flow->dv.dest_array_res = resource;
13020 : 0 : return 0;
13021 : : }
13022 : :
13023 : : /**
13024 : : * Convert Sample action to DV specification.
13025 : : *
13026 : : * @param[in] dev
13027 : : * Pointer to rte_eth_dev structure.
13028 : : * @param[in] action
13029 : : * Pointer to sample action structure.
13030 : : * @param[in, out] dev_flow
13031 : : * Pointer to the mlx5_flow.
13032 : : * @param[in] attr
13033 : : * Pointer to the flow attributes.
13034 : : * @param[in, out] num_of_dest
13035 : : * Pointer to the num of destination.
13036 : : * @param[in, out] sample_actions
13037 : : * Pointer to sample actions list.
13038 : : * @param[in, out] res
13039 : : * Pointer to sample resource.
13040 : : * @param[out] error
13041 : : * Pointer to the error structure.
13042 : : *
13043 : : * @return
13044 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
13045 : : */
13046 : : static int
13047 : 0 : flow_dv_translate_action_sample(struct rte_eth_dev *dev,
13048 : : const struct rte_flow_action_sample *action,
13049 : : struct mlx5_flow *dev_flow,
13050 : : const struct rte_flow_attr *attr,
13051 : : uint32_t *num_of_dest,
13052 : : void **sample_actions,
13053 : : struct mlx5_flow_dv_sample_resource *res,
13054 : : struct rte_flow_error *error)
13055 : : {
13056 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13057 : : const struct rte_flow_action *sub_actions;
13058 : : struct mlx5_flow_sub_actions_list *sample_act;
13059 : : struct mlx5_flow_sub_actions_idx *sample_idx;
13060 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
13061 : 0 : struct rte_flow *flow = dev_flow->flow;
13062 : : struct mlx5_flow_rss_desc *rss_desc;
13063 : : uint64_t action_flags = 0;
13064 : :
13065 : : MLX5_ASSERT(wks);
13066 : 0 : rss_desc = &wks->rss_desc;
13067 : : sample_act = &res->sample_act;
13068 : : sample_idx = &res->sample_idx;
13069 : 0 : res->ratio = action->ratio;
13070 : 0 : sub_actions = action->actions;
13071 [ # # ]: 0 : for (; sub_actions->type != RTE_FLOW_ACTION_TYPE_END; sub_actions++) {
13072 : : int type = sub_actions->type;
13073 : : uint32_t pre_rix = 0;
13074 : : void *pre_r;
13075 [ # # # # : 0 : switch (type) {
# # # ]
13076 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
13077 : : {
13078 : : const struct rte_flow_action_queue *queue;
13079 : : struct mlx5_hrxq *hrxq;
13080 : : uint32_t hrxq_idx;
13081 : :
13082 : 0 : queue = sub_actions->conf;
13083 : 0 : rss_desc->queue_num = 1;
13084 : 0 : rss_desc->queue[0] = queue->index;
13085 : 0 : hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
13086 : : rss_desc, &hrxq_idx);
13087 [ # # ]: 0 : if (!hrxq)
13088 : 0 : return rte_flow_error_set
13089 : : (error, rte_errno,
13090 : : RTE_FLOW_ERROR_TYPE_ACTION,
13091 : : NULL,
13092 : : "cannot create fate queue");
13093 : 0 : sample_act->dr_queue_action = hrxq->action;
13094 : 0 : sample_idx->rix_hrxq = hrxq_idx;
13095 : 0 : sample_actions[sample_act->actions_num++] =
13096 : : hrxq->action;
13097 : 0 : (*num_of_dest)++;
13098 : 0 : action_flags |= MLX5_FLOW_ACTION_QUEUE;
13099 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
13100 : 0 : dev_flow->handle->rix_hrxq = hrxq_idx;
13101 : 0 : dev_flow->handle->fate_action =
13102 : : MLX5_FLOW_FATE_QUEUE;
13103 : 0 : break;
13104 : : }
13105 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
13106 : : {
13107 : : struct mlx5_hrxq *hrxq;
13108 : : uint32_t hrxq_idx;
13109 : : const struct rte_flow_action_rss *rss;
13110 : : const uint8_t *rss_key;
13111 : :
13112 : 0 : rss = sub_actions->conf;
13113 : 0 : rss_desc->symmetric_hash_function =
13114 : 0 : MLX5_RSS_IS_SYMM(rss->func);
13115 : 0 : memcpy(rss_desc->queue, rss->queue,
13116 [ # # ]: 0 : rss->queue_num * sizeof(uint16_t));
13117 : 0 : rss_desc->queue_num = rss->queue_num;
13118 : : /* NULL RSS key indicates default RSS key. */
13119 [ # # ]: 0 : rss_key = !rss->key ? rss_hash_default_key : rss->key;
13120 : 0 : memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
13121 : : /*
13122 : : * rss->level and rss.types should be set in advance
13123 : : * when expanding items for RSS.
13124 : : */
13125 : 0 : flow_dv_hashfields_set(dev_flow->handle->layers,
13126 : : rss_desc,
13127 : : &dev_flow->hash_fields);
13128 : 0 : hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
13129 : : rss_desc, &hrxq_idx);
13130 [ # # ]: 0 : if (!hrxq)
13131 : 0 : return rte_flow_error_set
13132 : : (error, rte_errno,
13133 : : RTE_FLOW_ERROR_TYPE_ACTION,
13134 : : NULL,
13135 : : "cannot create fate queue");
13136 : 0 : sample_act->dr_queue_action = hrxq->action;
13137 : 0 : sample_idx->rix_hrxq = hrxq_idx;
13138 : 0 : sample_actions[sample_act->actions_num++] =
13139 : : hrxq->action;
13140 : 0 : (*num_of_dest)++;
13141 : 0 : action_flags |= MLX5_FLOW_ACTION_RSS;
13142 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
13143 : 0 : dev_flow->handle->rix_hrxq = hrxq_idx;
13144 : 0 : dev_flow->handle->fate_action =
13145 : : MLX5_FLOW_FATE_QUEUE;
13146 : 0 : break;
13147 : : }
13148 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
13149 : : {
13150 : : uint32_t tag_be = mlx5_flow_mark_set
13151 : : (((const struct rte_flow_action_mark *)
13152 [ # # ]: 0 : (sub_actions->conf))->id);
13153 : :
13154 : 0 : wks->mark = 1;
13155 : 0 : pre_rix = dev_flow->handle->dvh.rix_tag;
13156 : : /* Save the mark resource before sample */
13157 : 0 : pre_r = dev_flow->dv.tag_resource;
13158 [ # # ]: 0 : if (flow_dv_tag_resource_register(dev, tag_be,
13159 : : dev_flow, error))
13160 : 0 : return -rte_errno;
13161 : : MLX5_ASSERT(dev_flow->dv.tag_resource);
13162 : 0 : sample_act->dr_tag_action =
13163 : 0 : dev_flow->dv.tag_resource->action;
13164 : 0 : sample_idx->rix_tag =
13165 : 0 : dev_flow->handle->dvh.rix_tag;
13166 : 0 : sample_actions[sample_act->actions_num++] =
13167 : : sample_act->dr_tag_action;
13168 : : /* Recover the mark resource after sample */
13169 : 0 : dev_flow->dv.tag_resource = pre_r;
13170 : 0 : dev_flow->handle->dvh.rix_tag = pre_rix;
13171 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK;
13172 : 0 : break;
13173 : : }
13174 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
13175 : : {
13176 [ # # ]: 0 : if (!flow->counter) {
13177 : 0 : flow->counter =
13178 : 0 : flow_dv_translate_create_counter(dev,
13179 : 0 : dev_flow, sub_actions->conf,
13180 : : 0);
13181 [ # # ]: 0 : if (!flow->counter)
13182 : 0 : return rte_flow_error_set
13183 : : (error, rte_errno,
13184 : : RTE_FLOW_ERROR_TYPE_ACTION,
13185 : : NULL,
13186 : : "cannot create counter"
13187 : : " object.");
13188 : : }
13189 : 0 : sample_act->dr_cnt_action =
13190 [ # # ]: 0 : (flow_dv_counter_get_by_idx(dev,
13191 : 0 : flow->counter, NULL))->action;
13192 : 0 : sample_actions[sample_act->actions_num++] =
13193 : : sample_act->dr_cnt_action;
13194 : 0 : action_flags |= MLX5_FLOW_ACTION_COUNT;
13195 : 0 : break;
13196 : : }
13197 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
13198 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
13199 : : {
13200 : : struct mlx5_flow_dv_port_id_action_resource
13201 : : port_id_resource;
13202 : 0 : uint32_t port_id = 0;
13203 : :
13204 : : memset(&port_id_resource, 0, sizeof(port_id_resource));
13205 : : /* Save the port id resource before sample */
13206 : 0 : pre_rix = dev_flow->handle->rix_port_id_action;
13207 : 0 : pre_r = dev_flow->dv.port_id_action;
13208 [ # # ]: 0 : if (flow_dv_translate_action_port_id(dev, sub_actions,
13209 : : &port_id, error))
13210 : 0 : return -rte_errno;
13211 : 0 : port_id_resource.port_id = port_id;
13212 [ # # ]: 0 : if (flow_dv_port_id_action_resource_register
13213 : : (dev, &port_id_resource, dev_flow, error))
13214 : 0 : return -rte_errno;
13215 : 0 : sample_act->dr_port_id_action =
13216 : 0 : dev_flow->dv.port_id_action->action;
13217 : 0 : sample_idx->rix_port_id_action =
13218 : 0 : dev_flow->handle->rix_port_id_action;
13219 : 0 : sample_actions[sample_act->actions_num++] =
13220 : : sample_act->dr_port_id_action;
13221 : : /* Recover the port id resource after sample */
13222 : 0 : dev_flow->dv.port_id_action = pre_r;
13223 : 0 : dev_flow->handle->rix_port_id_action = pre_rix;
13224 : 0 : (*num_of_dest)++;
13225 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_ID;
13226 : 0 : break;
13227 : : }
13228 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
13229 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
13230 : : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
13231 : : /* Save the encap resource before sample */
13232 : 0 : pre_rix = dev_flow->handle->dvh.rix_encap_decap;
13233 : 0 : pre_r = dev_flow->dv.encap_decap;
13234 [ # # ]: 0 : if (flow_dv_create_action_l2_encap(dev, sub_actions,
13235 : : dev_flow,
13236 : 0 : attr->transfer,
13237 : : error))
13238 : 0 : return -rte_errno;
13239 : 0 : sample_act->dr_encap_action =
13240 : 0 : dev_flow->dv.encap_decap->action;
13241 : 0 : sample_idx->rix_encap_decap =
13242 : 0 : dev_flow->handle->dvh.rix_encap_decap;
13243 : 0 : sample_actions[sample_act->actions_num++] =
13244 : : sample_act->dr_encap_action;
13245 : : /* Recover the encap resource after sample */
13246 : 0 : dev_flow->dv.encap_decap = pre_r;
13247 : 0 : dev_flow->handle->dvh.rix_encap_decap = pre_rix;
13248 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
13249 : 0 : break;
13250 : 0 : default:
13251 : 0 : return rte_flow_error_set(error, EINVAL,
13252 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13253 : : NULL,
13254 : : "Not support for sampler action");
13255 : : }
13256 : : }
13257 : 0 : sample_act->action_flags = action_flags;
13258 : 0 : res->ft_id = dev_flow->dv.group;
13259 [ # # ]: 0 : if (attr->transfer) {
13260 : : union {
13261 : : uint32_t action_in[MLX5_ST_SZ_DW(set_action_in)];
13262 : : uint64_t set_action;
13263 : : } action_ctx = { .set_action = 0 };
13264 : 0 : uint32_t vport_meta_tag = wks->vport_meta_tag ?
13265 [ # # ]: 0 : wks->vport_meta_tag :
13266 : : priv->vport_meta_tag;
13267 : :
13268 : 0 : res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
13269 : : MLX5_SET(set_action_in, action_ctx.action_in, action_type,
13270 : : MLX5_MODIFICATION_TYPE_SET);
13271 [ # # ]: 0 : MLX5_SET(set_action_in, action_ctx.action_in, field,
13272 : : MLX5_MODI_META_REG_C_0);
13273 : 0 : MLX5_SET(set_action_in, action_ctx.action_in, data,
13274 : : vport_meta_tag);
13275 : 0 : res->set_action = action_ctx.set_action;
13276 [ # # ]: 0 : } else if (attr->ingress) {
13277 : 0 : res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
13278 : : } else {
13279 : 0 : res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_TX;
13280 : : }
13281 : : return 0;
13282 : : }
13283 : :
13284 : : static void *
13285 : 0 : flow_dv_translate_action_send_to_kernel(struct rte_eth_dev *dev,
13286 : : const struct rte_flow_attr *attr,
13287 : : struct rte_flow_error *error)
13288 : : {
13289 : : struct mlx5_flow_tbl_resource *tbl;
13290 : : struct mlx5_dev_ctx_shared *sh;
13291 : : uint32_t priority;
13292 : : void *action;
13293 : : int ft_type;
13294 : : int ret;
13295 : :
13296 : 0 : sh = MLX5_SH(dev);
13297 [ # # ]: 0 : ft_type = (attr->ingress) ? MLX5DR_TABLE_TYPE_NIC_RX :
13298 [ # # ]: 0 : ((attr->transfer) ? MLX5DR_TABLE_TYPE_FDB :
13299 : : MLX5DR_TABLE_TYPE_NIC_TX);
13300 [ # # ]: 0 : if (sh->send_to_kernel_action[ft_type].action)
13301 : : return sh->send_to_kernel_action[ft_type].action;
13302 : 0 : priority = mlx5_get_send_to_kernel_priority(dev);
13303 [ # # ]: 0 : if (priority == (uint32_t)-1) {
13304 : 0 : rte_flow_error_set(error, ENOTSUP,
13305 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13306 : : "required priority is not available");
13307 : 0 : return NULL;
13308 : : }
13309 : 0 : tbl = flow_dv_tbl_resource_get(dev, 0, attr->egress, attr->transfer, false, NULL, 0, 0, 0,
13310 : : error);
13311 [ # # ]: 0 : if (!tbl) {
13312 : 0 : rte_flow_error_set(error, ENODATA,
13313 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13314 : : "cannot find destination root table");
13315 : 0 : return NULL;
13316 : : }
13317 : 0 : ret = mlx5_flow_os_create_flow_action_send_to_kernel(tbl->obj,
13318 : : priority, &action);
13319 : : if (ret) {
13320 : 0 : rte_flow_error_set(error, ENOMEM,
13321 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13322 : : "cannot create action");
13323 : 0 : goto err;
13324 : : }
13325 : : MLX5_ASSERT(action);
13326 : 0 : sh->send_to_kernel_action[ft_type].action = action;
13327 : 0 : sh->send_to_kernel_action[ft_type].tbl = tbl;
13328 : 0 : return action;
13329 : : err:
13330 : 0 : flow_dv_tbl_resource_release(sh, tbl);
13331 : 0 : return NULL;
13332 : : }
13333 : :
13334 : : /**
13335 : : * Convert Sample action to DV specification.
13336 : : *
13337 : : * @param[in] dev
13338 : : * Pointer to rte_eth_dev structure.
13339 : : * @param[in, out] dev_flow
13340 : : * Pointer to the mlx5_flow.
13341 : : * @param[in] num_of_dest
13342 : : * The num of destination.
13343 : : * @param[in, out] res
13344 : : * Pointer to sample resource.
13345 : : * @param[in, out] mdest_res
13346 : : * Pointer to destination array resource.
13347 : : * @param[in] sample_actions
13348 : : * Pointer to sample path actions list.
13349 : : * @param[in] action_flags
13350 : : * Holds the actions detected until now.
13351 : : * @param[out] error
13352 : : * Pointer to the error structure.
13353 : : *
13354 : : * @return
13355 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
13356 : : */
13357 : : static int
13358 : 0 : flow_dv_create_action_sample(struct rte_eth_dev *dev,
13359 : : struct mlx5_flow *dev_flow,
13360 : : uint32_t num_of_dest,
13361 : : struct mlx5_flow_dv_sample_resource *res,
13362 : : struct mlx5_flow_dv_dest_array_resource *mdest_res,
13363 : : void **sample_actions,
13364 : : uint64_t action_flags,
13365 : : struct rte_flow_error *error)
13366 : : {
13367 : : /* update normal path action resource into last index of array */
13368 : : uint32_t dest_index = MLX5_MAX_DEST_NUM - 1;
13369 : : struct mlx5_flow_sub_actions_list *sample_act =
13370 : : &mdest_res->sample_act[dest_index];
13371 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
13372 : : struct mlx5_flow_rss_desc *rss_desc;
13373 : : uint32_t normal_idx = 0;
13374 : : struct mlx5_hrxq *hrxq;
13375 : : uint32_t hrxq_idx;
13376 : :
13377 : : MLX5_ASSERT(wks);
13378 : 0 : rss_desc = &wks->rss_desc;
13379 [ # # ]: 0 : if (num_of_dest > 1) {
13380 [ # # ]: 0 : if (sample_act->action_flags & MLX5_FLOW_ACTION_QUEUE) {
13381 : : /* Handle QP action for mirroring */
13382 : 0 : hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
13383 : : rss_desc, &hrxq_idx);
13384 [ # # ]: 0 : if (!hrxq)
13385 : 0 : return rte_flow_error_set
13386 : : (error, rte_errno,
13387 : : RTE_FLOW_ERROR_TYPE_ACTION,
13388 : : NULL,
13389 : : "cannot create rx queue");
13390 : : normal_idx++;
13391 : 0 : mdest_res->sample_idx[dest_index].rix_hrxq = hrxq_idx;
13392 : 0 : sample_act->dr_queue_action = hrxq->action;
13393 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
13394 : 0 : dev_flow->handle->rix_hrxq = hrxq_idx;
13395 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
13396 : : }
13397 [ # # ]: 0 : if (sample_act->action_flags & MLX5_FLOW_ACTION_ENCAP) {
13398 : 0 : normal_idx++;
13399 : 0 : mdest_res->sample_idx[dest_index].rix_encap_decap =
13400 : 0 : dev_flow->handle->dvh.rix_encap_decap;
13401 : 0 : sample_act->dr_encap_action =
13402 : 0 : dev_flow->dv.encap_decap->action;
13403 : 0 : dev_flow->handle->dvh.rix_encap_decap = 0;
13404 : : }
13405 [ # # ]: 0 : if (sample_act->action_flags & MLX5_FLOW_ACTION_PORT_ID) {
13406 : 0 : normal_idx++;
13407 : 0 : mdest_res->sample_idx[dest_index].rix_port_id_action =
13408 : 0 : dev_flow->handle->rix_port_id_action;
13409 : 0 : sample_act->dr_port_id_action =
13410 : 0 : dev_flow->dv.port_id_action->action;
13411 : 0 : dev_flow->handle->rix_port_id_action = 0;
13412 : : }
13413 [ # # ]: 0 : if (sample_act->action_flags & MLX5_FLOW_ACTION_JUMP) {
13414 : 0 : normal_idx++;
13415 : 0 : mdest_res->sample_idx[dest_index].rix_jump =
13416 : 0 : dev_flow->handle->rix_jump;
13417 : 0 : sample_act->dr_jump_action =
13418 : 0 : dev_flow->dv.jump->action;
13419 : 0 : dev_flow->handle->rix_jump = 0;
13420 : : }
13421 : 0 : sample_act->actions_num = normal_idx;
13422 : : /* update sample action resource into first index of array */
13423 : 0 : mdest_res->ft_type = res->ft_type;
13424 : 0 : memcpy(&mdest_res->sample_idx[0], &res->sample_idx,
13425 : : sizeof(struct mlx5_flow_sub_actions_idx));
13426 : 0 : memcpy(&mdest_res->sample_act[0], &res->sample_act,
13427 : : sizeof(struct mlx5_flow_sub_actions_list));
13428 : 0 : mdest_res->num_of_dest = num_of_dest;
13429 [ # # ]: 0 : if (flow_dv_dest_array_resource_register(dev, mdest_res,
13430 : : dev_flow, error))
13431 : 0 : return rte_flow_error_set(error, EINVAL,
13432 : : RTE_FLOW_ERROR_TYPE_ACTION,
13433 : : NULL, "can't create sample "
13434 : : "action");
13435 : : } else {
13436 : 0 : res->sub_actions = sample_actions;
13437 [ # # ]: 0 : if (flow_dv_sample_resource_register(dev, res, dev_flow, error))
13438 : 0 : return rte_flow_error_set(error, EINVAL,
13439 : : RTE_FLOW_ERROR_TYPE_ACTION,
13440 : : NULL,
13441 : : "can't create sample action");
13442 : : }
13443 : : return 0;
13444 : : }
13445 : :
13446 : : /**
13447 : : * Remove an ASO age action from age actions list.
13448 : : *
13449 : : * @param[in] dev
13450 : : * Pointer to the Ethernet device structure.
13451 : : * @param[in] age
13452 : : * Pointer to the aso age action handler.
13453 : : */
13454 : : static void
13455 : 0 : flow_dv_aso_age_remove_from_age(struct rte_eth_dev *dev,
13456 : : struct mlx5_aso_age_action *age)
13457 : : {
13458 : : struct mlx5_age_info *age_info;
13459 : : struct mlx5_age_param *age_param = &age->age_params;
13460 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13461 : : uint16_t expected = AGE_CANDIDATE;
13462 : :
13463 : 0 : age_info = GET_PORT_AGE_INFO(priv);
13464 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(&age_param->state, &expected,
13465 : : AGE_FREE, rte_memory_order_relaxed,
13466 : : rte_memory_order_relaxed)) {
13467 : : /**
13468 : : * We need the lock even it is age timeout,
13469 : : * since age action may still in process.
13470 : : */
13471 : 0 : rte_spinlock_lock(&age_info->aged_sl);
13472 [ # # ]: 0 : LIST_REMOVE(age, next);
13473 : : rte_spinlock_unlock(&age_info->aged_sl);
13474 : 0 : rte_atomic_store_explicit(&age_param->state, AGE_FREE, rte_memory_order_relaxed);
13475 : : }
13476 : 0 : }
13477 : :
13478 : : /**
13479 : : * Release an ASO age action.
13480 : : *
13481 : : * @param[in] dev
13482 : : * Pointer to the Ethernet device structure.
13483 : : * @param[in] age_idx
13484 : : * Index of ASO age action to release.
13485 : : * @param[in] flow
13486 : : * True if the release operation is during flow destroy operation.
13487 : : * False if the release operation is during action destroy operation.
13488 : : *
13489 : : * @return
13490 : : * 0 when age action was removed, otherwise the number of references.
13491 : : */
13492 : : static int
13493 : 0 : flow_dv_aso_age_release(struct rte_eth_dev *dev, uint32_t age_idx)
13494 : : {
13495 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13496 : 0 : struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
13497 : 0 : struct mlx5_aso_age_action *age = flow_aso_age_get_by_idx(dev, age_idx);
13498 : 0 : uint32_t ret = rte_atomic_fetch_sub_explicit(&age->refcnt, 1, rte_memory_order_relaxed) - 1;
13499 : :
13500 [ # # ]: 0 : if (!ret) {
13501 : 0 : flow_dv_aso_age_remove_from_age(dev, age);
13502 : 0 : rte_spinlock_lock(&mng->free_sl);
13503 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free, age, next);
13504 : : rte_spinlock_unlock(&mng->free_sl);
13505 : : }
13506 : 0 : return ret;
13507 : : }
13508 : :
13509 : : /**
13510 : : * Resize the ASO age pools array by MLX5_ASO_AGE_CONTAINER_RESIZE pools.
13511 : : *
13512 : : * @param[in] dev
13513 : : * Pointer to the Ethernet device structure.
13514 : : *
13515 : : * @return
13516 : : * 0 on success, otherwise negative errno value and rte_errno is set.
13517 : : */
13518 : : static int
13519 : 0 : flow_dv_aso_age_pools_resize(struct rte_eth_dev *dev)
13520 : : {
13521 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13522 : 0 : struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
13523 : 0 : void *old_pools = mng->pools;
13524 : 0 : uint32_t resize = mng->n + MLX5_ASO_AGE_CONTAINER_RESIZE;
13525 : 0 : uint32_t mem_size = sizeof(struct mlx5_aso_age_pool *) * resize;
13526 : 0 : void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
13527 : :
13528 [ # # ]: 0 : if (!pools) {
13529 : 0 : rte_errno = ENOMEM;
13530 : 0 : return -ENOMEM;
13531 : : }
13532 [ # # ]: 0 : if (old_pools) {
13533 : 0 : memcpy(pools, old_pools,
13534 : 0 : mng->n * sizeof(struct mlx5_flow_counter_pool *));
13535 : 0 : mlx5_free(old_pools);
13536 : : } else {
13537 : : /* First ASO flow hit allocation - starting ASO data-path. */
13538 : 0 : int ret = mlx5_aso_flow_hit_queue_poll_start(priv->sh);
13539 : :
13540 [ # # ]: 0 : if (ret) {
13541 : 0 : mlx5_free(pools);
13542 : 0 : return ret;
13543 : : }
13544 : : }
13545 : 0 : mng->n = resize;
13546 : 0 : mng->pools = pools;
13547 : 0 : return 0;
13548 : : }
13549 : :
13550 : : /**
13551 : : * Create and initialize a new ASO aging pool.
13552 : : *
13553 : : * @param[in] dev
13554 : : * Pointer to the Ethernet device structure.
13555 : : * @param[out] age_free
13556 : : * Where to put the pointer of a new age action.
13557 : : *
13558 : : * @return
13559 : : * The age actions pool pointer and @p age_free is set on success,
13560 : : * NULL otherwise and rte_errno is set.
13561 : : */
13562 : : static struct mlx5_aso_age_pool *
13563 : 0 : flow_dv_age_pool_create(struct rte_eth_dev *dev,
13564 : : struct mlx5_aso_age_action **age_free)
13565 : : {
13566 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13567 : 0 : struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
13568 : : struct mlx5_aso_age_pool *pool = NULL;
13569 : : struct mlx5_devx_obj *obj = NULL;
13570 : : uint32_t i;
13571 : :
13572 : 0 : obj = mlx5_devx_cmd_create_flow_hit_aso_obj(priv->sh->cdev->ctx,
13573 : 0 : priv->sh->cdev->pdn);
13574 [ # # ]: 0 : if (!obj) {
13575 : 0 : rte_errno = ENODATA;
13576 : 0 : DRV_LOG(ERR, "Failed to create flow_hit_aso_obj using DevX.");
13577 : 0 : return NULL;
13578 : : }
13579 : 0 : pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
13580 [ # # ]: 0 : if (!pool) {
13581 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
13582 : 0 : rte_errno = ENOMEM;
13583 : 0 : return NULL;
13584 : : }
13585 : 0 : pool->flow_hit_aso_obj = obj;
13586 : 0 : pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
13587 : 0 : rte_rwlock_write_lock(&mng->resize_rwl);
13588 : 0 : pool->index = mng->next;
13589 : : /* Resize pools array if there is no room for the new pool in it. */
13590 [ # # # # ]: 0 : if (pool->index == mng->n && flow_dv_aso_age_pools_resize(dev)) {
13591 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
13592 : 0 : mlx5_free(pool);
13593 : : rte_rwlock_write_unlock(&mng->resize_rwl);
13594 : 0 : return NULL;
13595 : : }
13596 : 0 : mng->pools[pool->index] = pool;
13597 : 0 : mng->next++;
13598 : : rte_rwlock_write_unlock(&mng->resize_rwl);
13599 : : /* Assign the first action in the new pool, the rest go to free list. */
13600 : 0 : *age_free = &pool->actions[0];
13601 [ # # ]: 0 : for (i = 1; i < MLX5_ASO_AGE_ACTIONS_PER_POOL; i++) {
13602 : 0 : pool->actions[i].offset = i;
13603 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free, &pool->actions[i], next);
13604 : : }
13605 : : return pool;
13606 : : }
13607 : :
13608 : : /**
13609 : : * Allocate a ASO aging bit.
13610 : : *
13611 : : * @param[in] dev
13612 : : * Pointer to the Ethernet device structure.
13613 : : * @param[out] error
13614 : : * Pointer to the error structure.
13615 : : *
13616 : : * @return
13617 : : * Index to ASO age action on success, 0 otherwise and rte_errno is set.
13618 : : */
13619 : : static uint32_t
13620 : 0 : flow_dv_aso_age_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
13621 : : {
13622 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13623 : : const struct mlx5_aso_age_pool *pool;
13624 : 0 : struct mlx5_aso_age_action *age_free = NULL;
13625 : 0 : struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
13626 : :
13627 : : MLX5_ASSERT(mng);
13628 : : /* Try to get the next free age action bit. */
13629 : 0 : rte_spinlock_lock(&mng->free_sl);
13630 : 0 : age_free = LIST_FIRST(&mng->free);
13631 [ # # ]: 0 : if (age_free) {
13632 [ # # ]: 0 : LIST_REMOVE(age_free, next);
13633 [ # # ]: 0 : } else if (!flow_dv_age_pool_create(dev, &age_free)) {
13634 : : rte_spinlock_unlock(&mng->free_sl);
13635 : 0 : rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
13636 : : NULL, "failed to create ASO age pool");
13637 : 0 : return 0; /* 0 is an error. */
13638 : : }
13639 : : rte_spinlock_unlock(&mng->free_sl);
13640 : 0 : pool = container_of
13641 : : ((const struct mlx5_aso_age_action (*)[MLX5_ASO_AGE_ACTIONS_PER_POOL])
13642 : : (age_free - age_free->offset), const struct mlx5_aso_age_pool,
13643 : : actions);
13644 [ # # ]: 0 : if (!age_free->dr_action) {
13645 : 0 : int reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_FLOW_HIT, 0,
13646 : : error);
13647 : :
13648 [ # # ]: 0 : if (reg_c < 0) {
13649 : 0 : rte_flow_error_set(error, rte_errno,
13650 : : RTE_FLOW_ERROR_TYPE_ACTION,
13651 : : NULL, "failed to get reg_c "
13652 : : "for ASO flow hit");
13653 : 0 : return 0; /* 0 is an error. */
13654 : : }
13655 : : #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
13656 : 0 : age_free->dr_action = mlx5_glue->dv_create_flow_action_aso
13657 : 0 : (priv->sh->rx_domain,
13658 : 0 : pool->flow_hit_aso_obj->obj, age_free->offset,
13659 : : MLX5DV_DR_ACTION_FLAGS_ASO_FIRST_HIT_SET,
13660 : 0 : (reg_c - REG_C_0));
13661 : : #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
13662 [ # # ]: 0 : if (!age_free->dr_action) {
13663 : 0 : rte_errno = errno;
13664 : : rte_spinlock_lock(&mng->free_sl);
13665 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free, age_free, next);
13666 : : rte_spinlock_unlock(&mng->free_sl);
13667 : 0 : rte_flow_error_set(error, rte_errno,
13668 : : RTE_FLOW_ERROR_TYPE_ACTION,
13669 : : NULL, "failed to create ASO "
13670 : : "flow hit action");
13671 : 0 : return 0; /* 0 is an error. */
13672 : : }
13673 : : }
13674 : 0 : rte_atomic_store_explicit(&age_free->refcnt, 1, rte_memory_order_relaxed);
13675 : 0 : return pool->index | ((age_free->offset + 1) << 16);
13676 : : }
13677 : :
13678 : : /**
13679 : : * Initialize flow ASO age parameters.
13680 : : *
13681 : : * @param[in] dev
13682 : : * Pointer to rte_eth_dev structure.
13683 : : * @param[in] age_idx
13684 : : * Index of ASO age action.
13685 : : * @param[in] context
13686 : : * Pointer to flow counter age context.
13687 : : * @param[in] timeout
13688 : : * Aging timeout in seconds.
13689 : : *
13690 : : */
13691 : : static void
13692 : 0 : flow_dv_aso_age_params_init(struct rte_eth_dev *dev,
13693 : : uint32_t age_idx,
13694 : : void *context,
13695 : : uint32_t timeout)
13696 : : {
13697 : : struct mlx5_aso_age_action *aso_age;
13698 : :
13699 : 0 : aso_age = flow_aso_age_get_by_idx(dev, age_idx);
13700 : : MLX5_ASSERT(aso_age);
13701 : 0 : aso_age->age_params.context = context;
13702 : 0 : aso_age->age_params.timeout = timeout;
13703 : 0 : aso_age->age_params.port_id = dev->data->port_id;
13704 : 0 : rte_atomic_store_explicit(&aso_age->age_params.sec_since_last_hit, 0,
13705 : : rte_memory_order_relaxed);
13706 : 0 : rte_atomic_store_explicit(&aso_age->age_params.state, AGE_CANDIDATE,
13707 : : rte_memory_order_relaxed);
13708 : 0 : }
13709 : :
13710 : : static void
13711 : 0 : flow_dv_translate_integrity_l4(const struct rte_flow_item_integrity *mask,
13712 : : void *headers)
13713 : : {
13714 : : /*
13715 : : * In HWS mode MLX5_ITEM_UPDATE() macro assigns the same pointer to
13716 : : * both mask and value, therefore ether can be used.
13717 : : * In SWS SW_V mode mask points to item mask and value points to item
13718 : : * spec. Integrity item value is used only if matching mask is set.
13719 : : * Use mask reference here to keep SWS functionality.
13720 : : */
13721 [ # # ]: 0 : if (mask->l4_ok) {
13722 : : /* RTE l4_ok filter aggregates hardware l4_ok and
13723 : : * l4_checksum_ok filters.
13724 : : * Positive RTE l4_ok match requires hardware match on both L4
13725 : : * hardware integrity bits.
13726 : : * PMD supports positive integrity item semantics only.
13727 : : */
13728 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, l4_ok, 1);
13729 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, l4_checksum_ok, 1);
13730 [ # # ]: 0 : } else if (mask->l4_csum_ok) {
13731 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, l4_checksum_ok, 1);
13732 : : }
13733 : 0 : }
13734 : :
13735 : : static void
13736 : 0 : flow_dv_translate_integrity_l3(const struct rte_flow_item_integrity *mask,
13737 : : void *headers, bool is_ipv4)
13738 : : {
13739 : : /*
13740 : : * In HWS mode MLX5_ITEM_UPDATE() macro assigns the same pointer to
13741 : : * both mask and value, therefore ether can be used.
13742 : : * In SWS SW_V mode mask points to item mask and value points to item
13743 : : * spec. Integrity item value used only if matching mask is set.
13744 : : * Use mask reference here to keep SWS functionality.
13745 : : */
13746 [ # # ]: 0 : if (mask->l3_ok) {
13747 : : /* RTE l3_ok filter aggregates for IPv4 hardware l3_ok and
13748 : : * ipv4_csum_ok filters.
13749 : : * Positive RTE l3_ok match requires hardware match on both L3
13750 : : * hardware integrity bits.
13751 : : * PMD supports positive integrity item semantics only.
13752 : : */
13753 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, l3_ok, 1);
13754 [ # # ]: 0 : if (is_ipv4) {
13755 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers,
13756 : : ipv4_checksum_ok, 1);
13757 : : }
13758 [ # # # # ]: 0 : } else if (is_ipv4 && mask->ipv4_csum_ok) {
13759 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, ipv4_checksum_ok, 1);
13760 : : }
13761 : 0 : }
13762 : :
13763 : : static void
13764 : 0 : set_integrity_bits(void *headers, const struct rte_flow_item *integrity_item,
13765 : : bool is_l3_ip4, uint32_t key_type)
13766 : : {
13767 : : const struct rte_flow_item_integrity *spec;
13768 : : const struct rte_flow_item_integrity *mask;
13769 : :
13770 : : /* Integrity bits validation cleared spec pointer */
13771 [ # # # # : 0 : if (MLX5_ITEM_VALID(integrity_item, key_type))
# # # # #
# ]
13772 : : return;
13773 [ # # # # : 0 : MLX5_ITEM_UPDATE(integrity_item, key_type, spec, mask,
# # # # ]
13774 : : &rte_flow_item_integrity_mask);
13775 : 0 : flow_dv_translate_integrity_l3(mask, headers, is_l3_ip4);
13776 : 0 : flow_dv_translate_integrity_l4(mask, headers);
13777 : : }
13778 : :
13779 : : static void
13780 : 0 : flow_dv_translate_item_integrity_post(void *key,
13781 : : const
13782 : : struct rte_flow_item *integrity_items[2],
13783 : : uint64_t pattern_flags, uint32_t key_type)
13784 : : {
13785 : : void *headers;
13786 : : bool is_l3_ip4;
13787 : :
13788 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_INNER_INTEGRITY) {
13789 : 0 : headers = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
13790 : 0 : is_l3_ip4 = (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV4) !=
13791 : : 0;
13792 : 0 : set_integrity_bits(headers, integrity_items[1], is_l3_ip4,
13793 : : key_type);
13794 : : }
13795 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_OUTER_INTEGRITY) {
13796 : : headers = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
13797 : 0 : is_l3_ip4 = (pattern_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV4) !=
13798 : : 0;
13799 : 0 : set_integrity_bits(headers, integrity_items[0], is_l3_ip4,
13800 : : key_type);
13801 : : }
13802 : 0 : }
13803 : :
13804 : : static uint64_t
13805 : : flow_dv_translate_item_integrity(const struct rte_flow_item *item,
13806 : : struct mlx5_dv_matcher_workspace *wks,
13807 : : uint64_t key_type)
13808 : : {
13809 : 0 : if ((key_type & MLX5_SET_MATCHER_SW) != 0) {
13810 : : const struct rte_flow_item_integrity
13811 : 0 : *spec = (typeof(spec))item->spec;
13812 : :
13813 : : /* SWS integrity bits validation cleared spec pointer */
13814 [ # # ]: 0 : if (spec->level > 1) {
13815 : 0 : wks->integrity_items[1] = item;
13816 : 0 : wks->last_item |= MLX5_FLOW_ITEM_INNER_INTEGRITY;
13817 : : } else {
13818 : 0 : wks->integrity_items[0] = item;
13819 : 0 : wks->last_item |= MLX5_FLOW_ITEM_OUTER_INTEGRITY;
13820 : : }
13821 : : } else {
13822 : : /* HWS supports outer integrity only */
13823 : 0 : wks->integrity_items[0] = item;
13824 : 0 : wks->last_item |= MLX5_FLOW_ITEM_OUTER_INTEGRITY;
13825 : : }
13826 : 0 : return wks->last_item;
13827 : : }
13828 : :
13829 : : /**
13830 : : * Prepares DV flow counter with aging configuration.
13831 : : * Gets it by index when exists, creates a new one when doesn't.
13832 : : *
13833 : : * @param[in] dev
13834 : : * Pointer to rte_eth_dev structure.
13835 : : * @param[in] dev_flow
13836 : : * Pointer to the mlx5_flow.
13837 : : * @param[in, out] flow
13838 : : * Pointer to the sub flow.
13839 : : * @param[in] count
13840 : : * Pointer to the counter action configuration.
13841 : : * @param[in] age
13842 : : * Pointer to the aging action configuration.
13843 : : * @param[out] error
13844 : : * Pointer to the error structure.
13845 : : *
13846 : : * @return
13847 : : * Pointer to the counter, NULL otherwise.
13848 : : */
13849 : : static struct mlx5_flow_counter *
13850 : 0 : flow_dv_prepare_counter(struct rte_eth_dev *dev,
13851 : : struct mlx5_flow *dev_flow,
13852 : : struct rte_flow *flow,
13853 : : const struct rte_flow_action_count *count,
13854 : : const struct rte_flow_action_age *age,
13855 : : struct rte_flow_error *error)
13856 : : {
13857 [ # # ]: 0 : if (!flow->counter) {
13858 : 0 : flow->counter = flow_dv_translate_create_counter(dev, dev_flow,
13859 : : count, age);
13860 [ # # ]: 0 : if (!flow->counter) {
13861 : 0 : rte_flow_error_set(error, rte_errno,
13862 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
13863 : : "cannot create counter object.");
13864 : 0 : return NULL;
13865 : : }
13866 : : }
13867 [ # # ]: 0 : return flow_dv_counter_get_by_idx(dev, flow->counter, NULL);
13868 : : }
13869 : :
13870 : : /*
13871 : : * Release an ASO CT action by its own device.
13872 : : *
13873 : : * @param[in] dev
13874 : : * Pointer to the Ethernet device structure.
13875 : : * @param[in] idx
13876 : : * Index of ASO CT action to release.
13877 : : *
13878 : : * @return
13879 : : * 0 when CT action was removed, otherwise the number of references.
13880 : : */
13881 : : static inline int
13882 : 0 : flow_dv_aso_ct_dev_release(struct rte_eth_dev *dev, uint32_t idx)
13883 : : {
13884 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13885 : 0 : struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
13886 : : uint32_t ret;
13887 : 0 : struct mlx5_aso_ct_action *ct = flow_aso_ct_get_by_dev_idx(dev, idx);
13888 : : enum mlx5_aso_ct_state state =
13889 : 0 : rte_atomic_load_explicit(&ct->state, rte_memory_order_relaxed);
13890 : :
13891 : : /* Cannot release when CT is in the ASO SQ. */
13892 [ # # ]: 0 : if (state == ASO_CONNTRACK_WAIT || state == ASO_CONNTRACK_QUERY)
13893 : : return -1;
13894 : 0 : ret = rte_atomic_fetch_sub_explicit(&ct->refcnt, 1, rte_memory_order_relaxed) - 1;
13895 [ # # ]: 0 : if (!ret) {
13896 [ # # ]: 0 : if (ct->dr_action_orig) {
13897 : : #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
13898 : 0 : claim_zero(mlx5_glue->destroy_flow_action
13899 : : (ct->dr_action_orig));
13900 : : #endif
13901 : 0 : ct->dr_action_orig = NULL;
13902 : : }
13903 [ # # ]: 0 : if (ct->dr_action_rply) {
13904 : : #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
13905 : 0 : claim_zero(mlx5_glue->destroy_flow_action
13906 : : (ct->dr_action_rply));
13907 : : #endif
13908 : 0 : ct->dr_action_rply = NULL;
13909 : : }
13910 : : /* Clear the state to free, no need in 1st allocation. */
13911 : 0 : MLX5_ASO_CT_UPDATE_STATE(ct, ASO_CONNTRACK_FREE);
13912 : 0 : rte_spinlock_lock(&mng->ct_sl);
13913 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free_cts, ct, next);
13914 : : rte_spinlock_unlock(&mng->ct_sl);
13915 : : }
13916 : 0 : return (int)ret;
13917 : : }
13918 : :
13919 : : static inline int
13920 : 0 : flow_dv_aso_ct_release(struct rte_eth_dev *dev, uint32_t own_idx,
13921 : : struct rte_flow_error *error)
13922 : : {
13923 : 0 : uint16_t owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(own_idx);
13924 : 0 : uint32_t idx = MLX5_INDIRECT_ACT_CT_GET_IDX(own_idx);
13925 : 0 : struct rte_eth_dev *owndev = &rte_eth_devices[owner];
13926 : : int ret;
13927 : :
13928 : : MLX5_ASSERT(owner < RTE_MAX_ETHPORTS);
13929 [ # # ]: 0 : if (dev->data->dev_started != 1)
13930 : 0 : return rte_flow_error_set(error, EAGAIN,
13931 : : RTE_FLOW_ERROR_TYPE_ACTION,
13932 : : NULL,
13933 : : "Indirect CT action cannot be destroyed when the port is stopped");
13934 : 0 : ret = flow_dv_aso_ct_dev_release(owndev, idx);
13935 [ # # ]: 0 : if (ret < 0)
13936 : 0 : return rte_flow_error_set(error, EAGAIN,
13937 : : RTE_FLOW_ERROR_TYPE_ACTION,
13938 : : NULL,
13939 : : "Current state prevents indirect CT action from being destroyed");
13940 : : return ret;
13941 : : }
13942 : :
13943 : : /*
13944 : : * Resize the ASO CT pools array by 64 pools.
13945 : : *
13946 : : * @param[in] dev
13947 : : * Pointer to the Ethernet device structure.
13948 : : *
13949 : : * @return
13950 : : * 0 on success, otherwise negative errno value and rte_errno is set.
13951 : : */
13952 : : static int
13953 : 0 : flow_dv_aso_ct_pools_resize(struct rte_eth_dev *dev)
13954 : : {
13955 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13956 : 0 : struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
13957 : 0 : void *old_pools = mng->pools;
13958 : : /* Magic number now, need a macro. */
13959 : 0 : uint32_t resize = mng->n + 64;
13960 : 0 : uint32_t mem_size = sizeof(struct mlx5_aso_ct_pool *) * resize;
13961 : 0 : void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
13962 : :
13963 [ # # ]: 0 : if (!pools) {
13964 : 0 : rte_errno = ENOMEM;
13965 : 0 : return -rte_errno;
13966 : : }
13967 : 0 : rte_rwlock_write_lock(&mng->resize_rwl);
13968 : : /* ASO SQ/QP was already initialized in the startup. */
13969 [ # # ]: 0 : if (old_pools) {
13970 : : /* Realloc could be an alternative choice. */
13971 : 0 : rte_memcpy(pools, old_pools,
13972 [ # # ]: 0 : mng->n * sizeof(struct mlx5_aso_ct_pool *));
13973 : 0 : mlx5_free(old_pools);
13974 : : }
13975 : 0 : mng->n = resize;
13976 : 0 : mng->pools = pools;
13977 : : rte_rwlock_write_unlock(&mng->resize_rwl);
13978 : 0 : return 0;
13979 : : }
13980 : :
13981 : : /*
13982 : : * Create and initialize a new ASO CT pool.
13983 : : *
13984 : : * @param[in] dev
13985 : : * Pointer to the Ethernet device structure.
13986 : : * @param[out] ct_free
13987 : : * Where to put the pointer of a new CT action.
13988 : : *
13989 : : * @return
13990 : : * The CT actions pool pointer and @p ct_free is set on success,
13991 : : * NULL otherwise and rte_errno is set.
13992 : : */
13993 : : static struct mlx5_aso_ct_pool *
13994 : 0 : flow_dv_ct_pool_create(struct rte_eth_dev *dev,
13995 : : struct mlx5_aso_ct_action **ct_free)
13996 : : {
13997 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13998 : 0 : struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
13999 : : struct mlx5_aso_ct_pool *pool = NULL;
14000 : : struct mlx5_devx_obj *obj = NULL;
14001 : : uint32_t i;
14002 : : uint32_t log_obj_size = rte_log2_u32(MLX5_ASO_CT_ACTIONS_PER_POOL);
14003 : : size_t mem_size;
14004 : :
14005 : 0 : obj = mlx5_devx_cmd_create_conn_track_offload_obj(priv->sh->cdev->ctx,
14006 : 0 : priv->sh->cdev->pdn,
14007 : : log_obj_size);
14008 [ # # ]: 0 : if (!obj) {
14009 : 0 : rte_errno = ENODATA;
14010 : 0 : DRV_LOG(ERR, "Failed to create conn_track_offload_obj using DevX.");
14011 : 0 : return NULL;
14012 : : }
14013 : : mem_size = sizeof(struct mlx5_aso_ct_action) *
14014 : : MLX5_ASO_CT_ACTIONS_PER_POOL +
14015 : : sizeof(*pool);
14016 : 0 : pool = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
14017 [ # # ]: 0 : if (!pool) {
14018 : 0 : rte_errno = ENOMEM;
14019 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
14020 : 0 : return NULL;
14021 : : }
14022 : 0 : pool->devx_obj = obj;
14023 : 0 : pool->index = mng->next;
14024 : : /* Resize pools array if there is no room for the new pool in it. */
14025 [ # # # # ]: 0 : if (pool->index == mng->n && flow_dv_aso_ct_pools_resize(dev)) {
14026 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
14027 : 0 : mlx5_free(pool);
14028 : 0 : return NULL;
14029 : : }
14030 : 0 : mng->pools[pool->index] = pool;
14031 : 0 : mng->next++;
14032 : : /* Assign the first action in the new pool, the rest go to free list. */
14033 : 0 : *ct_free = &pool->actions[0];
14034 : : /* Lock outside, the list operation is safe here. */
14035 [ # # ]: 0 : for (i = 1; i < MLX5_ASO_CT_ACTIONS_PER_POOL; i++) {
14036 : : /* refcnt is 0 when allocating the memory. */
14037 : 0 : pool->actions[i].offset = i;
14038 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free_cts, &pool->actions[i], next);
14039 : : }
14040 : : return pool;
14041 : : }
14042 : :
14043 : : /*
14044 : : * Allocate a ASO CT action from free list.
14045 : : *
14046 : : * @param[in] dev
14047 : : * Pointer to the Ethernet device structure.
14048 : : * @param[out] error
14049 : : * Pointer to the error structure.
14050 : : *
14051 : : * @return
14052 : : * Index to ASO CT action on success, 0 otherwise and rte_errno is set.
14053 : : */
14054 : : static uint32_t
14055 : 0 : flow_dv_aso_ct_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
14056 : : {
14057 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14058 : 0 : struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
14059 : 0 : struct mlx5_aso_ct_action *ct = NULL;
14060 : : struct mlx5_aso_ct_pool *pool;
14061 : : uint8_t reg_c;
14062 : : uint32_t ct_idx;
14063 : :
14064 : : MLX5_ASSERT(mng);
14065 [ # # ]: 0 : if (!priv->sh->cdev->config.devx) {
14066 : 0 : rte_errno = ENOTSUP;
14067 : 0 : return 0;
14068 : : }
14069 : : /* Get a free CT action, if no, a new pool will be created. */
14070 : 0 : rte_spinlock_lock(&mng->ct_sl);
14071 : 0 : ct = LIST_FIRST(&mng->free_cts);
14072 [ # # ]: 0 : if (ct) {
14073 [ # # ]: 0 : LIST_REMOVE(ct, next);
14074 [ # # ]: 0 : } else if (!flow_dv_ct_pool_create(dev, &ct)) {
14075 : : rte_spinlock_unlock(&mng->ct_sl);
14076 : 0 : rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
14077 : : NULL, "failed to create ASO CT pool");
14078 : 0 : return 0;
14079 : : }
14080 : : rte_spinlock_unlock(&mng->ct_sl);
14081 : 0 : pool = container_of(ct, struct mlx5_aso_ct_pool, actions[ct->offset]);
14082 : 0 : ct_idx = MLX5_MAKE_CT_IDX(pool->index, ct->offset);
14083 : : /* 0: inactive, 1: created, 2+: used by flows. */
14084 : 0 : rte_atomic_store_explicit(&ct->refcnt, 1, rte_memory_order_relaxed);
14085 : 0 : reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_CONNTRACK, 0, error);
14086 [ # # ]: 0 : if (!ct->dr_action_orig) {
14087 : : #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
14088 : 0 : ct->dr_action_orig = mlx5_glue->dv_create_flow_action_aso
14089 : 0 : (priv->sh->rx_domain, pool->devx_obj->obj,
14090 : : ct->offset,
14091 : : MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_INITIATOR,
14092 : 0 : reg_c - REG_C_0);
14093 : : #else
14094 : : RTE_SET_USED(reg_c);
14095 : : #endif
14096 [ # # ]: 0 : if (!ct->dr_action_orig) {
14097 : 0 : flow_dv_aso_ct_dev_release(dev, ct_idx);
14098 : 0 : rte_flow_error_set(error, rte_errno,
14099 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14100 : : "failed to create ASO CT action");
14101 : 0 : return 0;
14102 : : }
14103 : : }
14104 [ # # ]: 0 : if (!ct->dr_action_rply) {
14105 : : #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
14106 : 0 : ct->dr_action_rply = mlx5_glue->dv_create_flow_action_aso
14107 : 0 : (priv->sh->rx_domain, pool->devx_obj->obj,
14108 : : ct->offset,
14109 : : MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_RESPONDER,
14110 : 0 : reg_c - REG_C_0);
14111 : : #endif
14112 [ # # ]: 0 : if (!ct->dr_action_rply) {
14113 : 0 : flow_dv_aso_ct_dev_release(dev, ct_idx);
14114 : 0 : rte_flow_error_set(error, rte_errno,
14115 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14116 : : "failed to create ASO CT action");
14117 : 0 : return 0;
14118 : : }
14119 : : }
14120 : : return ct_idx;
14121 : : }
14122 : :
14123 : : /*
14124 : : * Create a conntrack object with context and actions by using ASO mechanism.
14125 : : *
14126 : : * @param[in] dev
14127 : : * Pointer to rte_eth_dev structure.
14128 : : * @param[in] pro
14129 : : * Pointer to conntrack information profile.
14130 : : * @param[out] error
14131 : : * Pointer to the error structure.
14132 : : *
14133 : : * @return
14134 : : * Index to conntrack object on success, 0 otherwise.
14135 : : */
14136 : : static uint32_t
14137 : 0 : flow_dv_translate_create_conntrack(struct rte_eth_dev *dev,
14138 : : const struct rte_flow_action_conntrack *pro,
14139 : : struct rte_flow_error *error)
14140 : : {
14141 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14142 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
14143 : : struct mlx5_aso_ct_action *ct;
14144 : : uint32_t idx;
14145 : :
14146 [ # # ]: 0 : if (!sh->ct_aso_en)
14147 : 0 : return rte_flow_error_set(error, ENOTSUP,
14148 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14149 : : "Connection is not supported");
14150 [ # # ]: 0 : if (dev->data->port_id >= MLX5_INDIRECT_ACT_CT_MAX_PORT) {
14151 : 0 : rte_flow_error_set(error, EINVAL,
14152 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14153 : : "CT supports port indexes up to "
14154 : : RTE_STR(MLX5_ACTION_CTX_CT_MAX_PORT));
14155 : 0 : return 0;
14156 : : }
14157 : 0 : idx = flow_dv_aso_ct_alloc(dev, error);
14158 [ # # ]: 0 : if (!idx)
14159 : 0 : return rte_flow_error_set(error, rte_errno,
14160 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14161 : : "Failed to allocate CT object");
14162 : 0 : ct = flow_aso_ct_get_by_dev_idx(dev, idx);
14163 [ # # ]: 0 : if (mlx5_aso_ct_update_by_wqe(sh, MLX5_HW_INV_QUEUE, ct, pro, NULL, true)) {
14164 : 0 : flow_dv_aso_ct_dev_release(dev, idx);
14165 : 0 : rte_flow_error_set(error, EBUSY,
14166 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14167 : : "Failed to update CT");
14168 : 0 : return 0;
14169 : : }
14170 : 0 : ct->is_original = !!pro->is_original_dir;
14171 : 0 : ct->peer = pro->peer_port;
14172 : 0 : return idx;
14173 : : }
14174 : :
14175 : : /**
14176 : : * Fill the flow matcher with DV spec.
14177 : : *
14178 : : * @param[in] dev
14179 : : * Pointer to rte_eth_dev structure.
14180 : : * @param[in] items
14181 : : * Pointer to the list of items.
14182 : : * @param[in] wks
14183 : : * Pointer to the matcher workspace.
14184 : : * @param[in] key
14185 : : * Pointer to the flow matcher key.
14186 : : * @param[in] key_type
14187 : : * Key type.
14188 : : * @param[out] error
14189 : : * Pointer to the error structure.
14190 : : *
14191 : : * @return
14192 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14193 : : */
14194 : : static int
14195 : 0 : flow_dv_translate_items(struct rte_eth_dev *dev,
14196 : : const struct rte_flow_item *items,
14197 : : struct mlx5_dv_matcher_workspace *wks,
14198 : : void *key, uint32_t key_type,
14199 : : struct rte_flow_error *error)
14200 : : {
14201 : 0 : struct mlx5_flow_rss_desc *rss_desc = wks->rss_desc;
14202 : 0 : uint8_t next_protocol = wks->next_protocol;
14203 : 0 : int tunnel = !!(wks->item_flags & MLX5_FLOW_LAYER_TUNNEL);
14204 : 0 : int item_type = items->type;
14205 : 0 : uint64_t last_item = wks->last_item;
14206 : : enum mlx5_l3_tunnel_detection l3_tunnel_detection;
14207 : : uint64_t l3_tunnel_flag;
14208 : : int ret;
14209 : :
14210 [ # # # # : 0 : switch (item_type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
14211 : 0 : case RTE_FLOW_ITEM_TYPE_ESP:
14212 : 0 : flow_dv_translate_item_esp(key, items, tunnel, key_type);
14213 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14214 : : last_item = MLX5_FLOW_ITEM_ESP;
14215 : 0 : break;
14216 : 0 : case RTE_FLOW_ITEM_TYPE_PORT_ID:
14217 : 0 : flow_dv_translate_item_port_id
14218 : : (dev, key, items, wks->attr, key_type);
14219 : : last_item = MLX5_FLOW_ITEM_PORT_ID;
14220 : 0 : break;
14221 : 0 : case RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR:
14222 : 0 : flow_dv_translate_item_port_representor
14223 : : (dev, key, key_type);
14224 : : last_item = MLX5_FLOW_ITEM_PORT_REPRESENTOR;
14225 : 0 : break;
14226 : 0 : case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
14227 : 0 : flow_dv_translate_item_represented_port
14228 : : (dev, key, items, wks->attr, key_type);
14229 : : last_item = MLX5_FLOW_ITEM_REPRESENTED_PORT;
14230 : 0 : break;
14231 : 0 : case RTE_FLOW_ITEM_TYPE_ETH:
14232 : 0 : flow_dv_translate_item_eth(key, items, tunnel,
14233 : : wks->group, key_type);
14234 [ # # ]: 0 : wks->priority = wks->action_flags &
14235 : 0 : MLX5_FLOW_ACTION_DEFAULT_MISS &&
14236 [ # # ]: 0 : !wks->external ?
14237 : : MLX5_PRIORITY_MAP_L3 :
14238 : : MLX5_PRIORITY_MAP_L2;
14239 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
14240 : : MLX5_FLOW_LAYER_OUTER_L2;
14241 : : break;
14242 : 0 : case RTE_FLOW_ITEM_TYPE_VLAN:
14243 : 0 : flow_dv_translate_item_vlan(key, items, tunnel, wks, key_type);
14244 : 0 : wks->priority = MLX5_PRIORITY_MAP_L2;
14245 : : last_item = tunnel ? (MLX5_FLOW_LAYER_INNER_L2 |
14246 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_VLAN) :
14247 : : (MLX5_FLOW_LAYER_OUTER_L2 |
14248 : : MLX5_FLOW_LAYER_OUTER_VLAN);
14249 : : break;
14250 : : case RTE_FLOW_ITEM_TYPE_IPV4:
14251 : : next_protocol = mlx5_flow_l3_next_protocol(items, key_type);
14252 : : l3_tunnel_detection =
14253 : : mlx5_flow_tunnel_ip_check(items, next_protocol,
14254 : : wks->item_flags,
14255 : : &l3_tunnel_flag);
14256 : : if (l3_tunnel_detection == l3_tunnel_inner) {
14257 : 0 : wks->item_flags |= l3_tunnel_flag;
14258 : : tunnel = 1;
14259 : : }
14260 : 0 : flow_dv_translate_item_ipv4(key, items, tunnel,
14261 : : wks->group, key_type);
14262 : 0 : wks->priority = MLX5_PRIORITY_MAP_L3;
14263 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
14264 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4;
14265 [ # # ]: 0 : if (l3_tunnel_detection == l3_tunnel_outer)
14266 : 0 : wks->item_flags |= l3_tunnel_flag;
14267 : : break;
14268 : : case RTE_FLOW_ITEM_TYPE_IPV6:
14269 : : next_protocol = mlx5_flow_l3_next_protocol(items, key_type);
14270 : : l3_tunnel_detection =
14271 : : mlx5_flow_tunnel_ip_check(items, next_protocol,
14272 : : wks->item_flags,
14273 : : &l3_tunnel_flag);
14274 : : if (l3_tunnel_detection == l3_tunnel_inner) {
14275 : 0 : wks->item_flags |= l3_tunnel_flag;
14276 : : tunnel = 1;
14277 : : }
14278 : 0 : flow_dv_translate_item_ipv6(key, items, tunnel,
14279 : : wks->group, key_type);
14280 : 0 : wks->priority = MLX5_PRIORITY_MAP_L3;
14281 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
14282 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6;
14283 [ # # ]: 0 : if (l3_tunnel_detection == l3_tunnel_outer)
14284 : 0 : wks->item_flags |= l3_tunnel_flag;
14285 : : break;
14286 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
14287 : 0 : flow_dv_translate_item_ipv6_frag_ext
14288 : : (key, items, tunnel, key_type);
14289 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
14290 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
14291 : : next_protocol = mlx5_flow_l3_next_protocol(items, key_type);
14292 : : break;
14293 : 0 : case RTE_FLOW_ITEM_TYPE_TCP:
14294 : 0 : flow_dv_translate_item_tcp(key, items, tunnel, key_type);
14295 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14296 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
14297 : : MLX5_FLOW_LAYER_OUTER_L4_TCP;
14298 : : break;
14299 : 0 : case RTE_FLOW_ITEM_TYPE_UDP:
14300 : 0 : flow_dv_translate_item_udp(key, items, tunnel, wks, key_type);
14301 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14302 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
14303 : : MLX5_FLOW_LAYER_OUTER_L4_UDP;
14304 : : break;
14305 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
14306 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14307 : 0 : wks->tunnel_item = items;
14308 : 0 : wks->gre_item = items;
14309 : : last_item = MLX5_FLOW_LAYER_GRE;
14310 : 0 : break;
14311 : 0 : case RTE_FLOW_ITEM_TYPE_GRE_KEY:
14312 : 0 : flow_dv_translate_item_gre_key(key, items, key_type);
14313 : : last_item = MLX5_FLOW_LAYER_GRE_KEY;
14314 : 0 : break;
14315 : 0 : case RTE_FLOW_ITEM_TYPE_GRE_OPTION:
14316 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14317 : 0 : wks->tunnel_item = items;
14318 : : last_item = MLX5_FLOW_LAYER_GRE;
14319 : 0 : break;
14320 : 0 : case RTE_FLOW_ITEM_TYPE_NVGRE:
14321 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14322 : 0 : wks->tunnel_item = items;
14323 : : last_item = MLX5_FLOW_LAYER_GRE;
14324 : 0 : break;
14325 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN:
14326 : 0 : flow_dv_translate_item_vxlan(dev, wks->attr, key,
14327 : : items, tunnel, wks, key_type);
14328 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14329 : : last_item = MLX5_FLOW_LAYER_VXLAN;
14330 : 0 : break;
14331 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
14332 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14333 : 0 : wks->tunnel_item = items;
14334 : : last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
14335 : 0 : break;
14336 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE:
14337 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14338 : 0 : wks->tunnel_item = items;
14339 : : last_item = MLX5_FLOW_LAYER_GENEVE;
14340 : 0 : break;
14341 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
14342 : 0 : ret = flow_dv_translate_item_geneve_opt
14343 : : (dev, key, items, key_type, error);
14344 [ # # ]: 0 : if (ret)
14345 : 0 : return rte_flow_error_set(error, -ret,
14346 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14347 : : "cannot create GENEVE TLV option");
14348 : 0 : wks->geneve_tlv_option = 1;
14349 : : last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
14350 : 0 : break;
14351 : 0 : case RTE_FLOW_ITEM_TYPE_MPLS:
14352 : 0 : flow_dv_translate_item_mpls(key, items, last_item,
14353 : : tunnel, key_type);
14354 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14355 : : last_item = MLX5_FLOW_LAYER_MPLS;
14356 : 0 : break;
14357 : 0 : case RTE_FLOW_ITEM_TYPE_MARK:
14358 : 0 : flow_dv_translate_item_mark(dev, key, items, key_type);
14359 : : last_item = MLX5_FLOW_ITEM_MARK;
14360 : 0 : break;
14361 : 0 : case RTE_FLOW_ITEM_TYPE_META:
14362 : 0 : flow_dv_translate_item_meta
14363 : : (dev, key, wks->attr, items, key_type);
14364 : : last_item = MLX5_FLOW_ITEM_METADATA;
14365 : 0 : break;
14366 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP:
14367 : 0 : flow_dv_translate_item_icmp(key, items, tunnel, key_type);
14368 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14369 : : last_item = MLX5_FLOW_LAYER_ICMP;
14370 : 0 : break;
14371 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6:
14372 : 0 : flow_dv_translate_item_icmp6(key, items, tunnel, key_type);
14373 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14374 : : last_item = MLX5_FLOW_LAYER_ICMP6;
14375 : 0 : break;
14376 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REQUEST:
14377 : : case RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REPLY:
14378 : 0 : flow_dv_translate_item_icmp6_echo(key, items, tunnel, key_type);
14379 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14380 : : last_item = MLX5_FLOW_LAYER_ICMP6;
14381 : 0 : break;
14382 : 0 : case RTE_FLOW_ITEM_TYPE_TAG:
14383 : 0 : flow_dv_translate_item_tag(dev, key, items, key_type);
14384 : : last_item = MLX5_FLOW_ITEM_TAG;
14385 : 0 : break;
14386 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
14387 : 0 : flow_dv_translate_mlx5_item_tag(dev, key, items, key_type);
14388 : : last_item = MLX5_FLOW_ITEM_TAG;
14389 : 0 : break;
14390 : 0 : case RTE_FLOW_ITEM_TYPE_TX_QUEUE:
14391 : 0 : ret = flow_dv_translate_item_tx_queue(dev, key, items, key_type);
14392 [ # # ]: 0 : if (ret)
14393 : 0 : return rte_flow_error_set(error, -ret,
14394 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14395 : : "invalid tx_queue item");
14396 : : last_item = MLX5_FLOW_ITEM_SQ;
14397 : : break;
14398 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_SQ:
14399 : 0 : flow_dv_translate_item_sq(key, items, key_type);
14400 : : last_item = MLX5_FLOW_ITEM_SQ;
14401 : 0 : break;
14402 : 0 : case RTE_FLOW_ITEM_TYPE_GTP:
14403 : 0 : flow_dv_translate_item_gtp(key, items, tunnel, key_type);
14404 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14405 : : last_item = MLX5_FLOW_LAYER_GTP;
14406 : 0 : break;
14407 : 0 : case RTE_FLOW_ITEM_TYPE_GTP_PSC:
14408 : 0 : ret = flow_dv_translate_item_gtp_psc(key, items, key_type);
14409 [ # # ]: 0 : if (ret)
14410 : 0 : return rte_flow_error_set(error, -ret,
14411 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14412 : : "cannot create GTP PSC item");
14413 : : last_item = MLX5_FLOW_LAYER_GTP_PSC;
14414 : : break;
14415 : 0 : case RTE_FLOW_ITEM_TYPE_ECPRI:
14416 [ # # ]: 0 : if (!mlx5_flex_parser_ecpri_exist(dev)) {
14417 : : /* Create it only the first time to be used. */
14418 : 0 : ret = mlx5_flex_parser_ecpri_alloc(dev);
14419 [ # # ]: 0 : if (ret)
14420 : 0 : return rte_flow_error_set
14421 : : (error, -ret,
14422 : : RTE_FLOW_ERROR_TYPE_ITEM,
14423 : : NULL,
14424 : : "cannot create eCPRI parser");
14425 : : }
14426 : 0 : flow_dv_translate_item_ecpri
14427 : : (dev, key, items, last_item, key_type);
14428 : : /* No other protocol should follow eCPRI layer. */
14429 : : last_item = MLX5_FLOW_LAYER_ECPRI;
14430 : 0 : break;
14431 : 0 : case RTE_FLOW_ITEM_TYPE_METER_COLOR:
14432 : 0 : flow_dv_translate_item_meter_color(dev, key, items, key_type);
14433 : : last_item = MLX5_FLOW_ITEM_METER_COLOR;
14434 : 0 : break;
14435 [ # # ]: 0 : case RTE_FLOW_ITEM_TYPE_INTEGRITY:
14436 : : last_item = flow_dv_translate_item_integrity(items,
14437 : : wks, key_type);
14438 : 0 : break;
14439 : 0 : case RTE_FLOW_ITEM_TYPE_AGGR_AFFINITY:
14440 : 0 : flow_dv_translate_item_aggr_affinity(key, items, key_type);
14441 : : last_item = MLX5_FLOW_ITEM_AGGR_AFFINITY;
14442 : 0 : break;
14443 : 0 : case RTE_FLOW_ITEM_TYPE_IB_BTH:
14444 : 0 : flow_dv_translate_item_ib_bth(key, items, tunnel, key_type);
14445 : : last_item = MLX5_FLOW_ITEM_IB_BTH;
14446 : 0 : break;
14447 : 0 : case RTE_FLOW_ITEM_TYPE_NSH:
14448 : : last_item = MLX5_FLOW_ITEM_NSH;
14449 : 0 : break;
14450 : : default:
14451 : : break;
14452 : : }
14453 : 0 : wks->item_flags |= last_item;
14454 : 0 : wks->last_item = last_item;
14455 : 0 : wks->next_protocol = next_protocol;
14456 : 0 : return 0;
14457 : : }
14458 : :
14459 : : static int
14460 : 0 : flow_dv_translate_items_geneve_opt_nta(struct rte_eth_dev *dev,
14461 : : const struct rte_flow_item *items,
14462 : : struct mlx5_flow_attr *attr,
14463 : : struct rte_flow_error *error)
14464 : : {
14465 : 0 : rte_be32_t geneve_mask = 0xffffffff;
14466 : 0 : struct rte_pmd_mlx5_geneve_tlv geneve_tlv = {
14467 : : /* Take from item spec, if changed, destroy and add new parser. */
14468 : : .option_class = 0,
14469 : : /* Take from item spec, if changed, destroy and add new parser. */
14470 : : .option_type = 0,
14471 : : /* 1DW is supported. */
14472 : : .option_len = 1,
14473 : : .match_on_class_mode = 1,
14474 : : .offset = 0,
14475 : : .sample_len = 1,
14476 : : .match_data_mask = &geneve_mask
14477 : : };
14478 : 0 : const struct rte_flow_item_geneve_opt *geneve_opt_v = items->spec;
14479 : 0 : const struct rte_flow_item_geneve_opt *geneve_opt_m = items->mask;
14480 : : void *geneve_parser;
14481 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14482 : : #ifdef RTE_LIBRTE_MLX5_DEBUG
14483 : : struct mlx5_geneve_tlv_option *option;
14484 : : #endif
14485 : :
14486 : : /* option length is not as supported. */
14487 [ # # ]: 0 : if ((geneve_opt_v->option_len & geneve_opt_m->option_len) > geneve_tlv.option_len)
14488 : 0 : return rte_flow_error_set(error, ENOTSUP,
14489 : : RTE_FLOW_ERROR_TYPE_ITEM, items,
14490 : : " GENEVE OPT length is not supported ");
14491 : 0 : geneve_tlv.option_class = geneve_opt_v->option_class & geneve_opt_m->option_class;
14492 : 0 : geneve_tlv.option_type = geneve_opt_v->option_type & geneve_opt_m->option_type;
14493 : : /* if parser doesn't exist */
14494 [ # # ]: 0 : if (!priv->tlv_options) {
14495 : : /* Create a GENEVE option parser. */
14496 : 0 : geneve_parser = mlx5_geneve_tlv_parser_create(attr->port_id,
14497 : : &geneve_tlv, 1);
14498 [ # # ]: 0 : if (!geneve_parser)
14499 : 0 : return rte_flow_error_set(error, EINVAL,
14500 : : RTE_FLOW_ERROR_TYPE_ITEM, items,
14501 : : " GENEVE OPT parser creation failed ");
14502 : : #ifdef RTE_LIBRTE_MLX5_DEBUG
14503 : : } else {
14504 : : /* Check if option exist in current parser. */
14505 : : option = mlx5_geneve_tlv_option_get(priv,
14506 : : geneve_tlv.option_type,
14507 : : geneve_tlv.option_class);
14508 : : if (!option)
14509 : : return rte_flow_error_set(error, EINVAL,
14510 : : RTE_FLOW_ERROR_TYPE_ITEM, items,
14511 : : " GENEVE OPT configured does not match this rule class/type");
14512 : : #endif
14513 : : }
14514 : : return 0;
14515 : : }
14516 : :
14517 : : /**
14518 : : * Fill the flow matcher with DV spec for items supported in non template mode.
14519 : : *
14520 : : * @param[in] dev
14521 : : * Pointer to rte_eth_dev structure.
14522 : : * @param[in] items
14523 : : * Pointer to the list of items.
14524 : : * @param[in] wks
14525 : : * Pointer to the matcher workspace.
14526 : : * @param[in] key
14527 : : * Pointer to the flow matcher key.
14528 : : * @param[in] key_type
14529 : : * Key type.
14530 : : * @param[out] error
14531 : : * Pointer to the error structure.
14532 : : *
14533 : : * @return
14534 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14535 : : */
14536 : : static int
14537 : 0 : flow_dv_translate_items_nta(struct rte_eth_dev *dev,
14538 : : const struct rte_flow_item *items,
14539 : : struct mlx5_dv_matcher_workspace *wks,
14540 : : void *key, uint32_t key_type,
14541 : : struct mlx5_flow_attr *attr,
14542 : : struct rte_flow_error *error)
14543 : : {
14544 : : int item_type;
14545 : : int ret = 0;
14546 : : int tunnel;
14547 : : /* Dummy structure to enable the key calculation for flex item. */
14548 : : struct mlx5_flow_dv_match_params flex_item_key;
14549 : :
14550 : 0 : tunnel = !!(wks->item_flags & MLX5_FLOW_LAYER_TUNNEL);
14551 : 0 : item_type = items->type;
14552 [ # # # # ]: 0 : switch (item_type) {
14553 : 0 : case RTE_FLOW_ITEM_TYPE_CONNTRACK:
14554 : 0 : flow_dv_translate_item_aso_ct(dev, key, NULL, items);
14555 : 0 : wks->last_item = MLX5_FLOW_LAYER_ASO_CT;
14556 : 0 : break;
14557 : : /* TODO: remove once flex item translation is added to flow_dv_translate_items. */
14558 : 0 : case RTE_FLOW_ITEM_TYPE_FLEX:
14559 : 0 : mlx5_flex_flow_translate_item(dev, key, flex_item_key.buf, items, tunnel != 0);
14560 [ # # ]: 0 : wks->last_item = tunnel ? MLX5_FLOW_ITEM_INNER_FLEX : MLX5_FLOW_ITEM_OUTER_FLEX;
14561 : 0 : break;
14562 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
14563 : 0 : ret = flow_dv_translate_items_geneve_opt_nta(dev, items, attr, error);
14564 [ # # ]: 0 : if (ret)
14565 : : return ret;
14566 : 0 : wks->last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
14567 : 0 : break;
14568 : 0 : default:
14569 : 0 : ret = flow_dv_translate_items(dev, items, wks, key, key_type, error);
14570 [ # # ]: 0 : if (ret)
14571 : : return ret;
14572 : : break;
14573 : : }
14574 : 0 : wks->item_flags |= wks->last_item;
14575 : 0 : return 0;
14576 : : }
14577 : :
14578 : : /**
14579 : : * Fill the HW steering flow with DV spec.
14580 : : *
14581 : : * @param[in] items
14582 : : * Pointer to the list of items.
14583 : : * @param[in] attr
14584 : : * Pointer to the flow attributes.
14585 : : * @param[in] key
14586 : : * Pointer to the flow matcher key.
14587 : : * @param[in] key_type
14588 : : * Key type.
14589 : : * @param[in, out] item_flags
14590 : : * Pointer to the flow item flags.
14591 : : * @param[in, out] nt_flow
14592 : : * Non template flow.
14593 : : * @param[out] error
14594 : : * Pointer to the error structure.
14595 : : *
14596 : : * @return
14597 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14598 : : */
14599 : : int
14600 : 0 : __flow_dv_translate_items_hws(const struct rte_flow_item *items,
14601 : : struct mlx5_flow_attr *attr, void *key,
14602 : : uint32_t key_type, uint64_t *item_flags,
14603 : : uint8_t *match_criteria,
14604 : : bool nt_flow,
14605 : : struct rte_flow_error *error)
14606 : : {
14607 : 0 : struct mlx5_flow_workspace *flow_wks = mlx5_flow_push_thread_workspace();
14608 : 0 : struct mlx5_flow_rss_desc rss_desc = { .level = attr->rss_level };
14609 : 0 : struct rte_flow_attr rattr = {
14610 : 0 : .group = attr->group,
14611 : 0 : .priority = attr->priority,
14612 : 0 : .ingress = !!(attr->tbl_type == MLX5DR_TABLE_TYPE_NIC_RX),
14613 : 0 : .egress = !!(attr->tbl_type == MLX5DR_TABLE_TYPE_NIC_TX),
14614 : 0 : .transfer = !!(attr->tbl_type == MLX5DR_TABLE_TYPE_FDB),
14615 : : };
14616 : 0 : struct mlx5_dv_matcher_workspace wks = {
14617 : 0 : .action_flags = attr->act_flags,
14618 [ # # ]: 0 : .item_flags = item_flags ? *item_flags : 0,
14619 : : .external = 0,
14620 : : .next_protocol = 0xff,
14621 : : .attr = &rattr,
14622 : : .rss_desc = &rss_desc,
14623 : : .group = attr->group,
14624 : : };
14625 : : int ret = 0;
14626 : :
14627 : : RTE_SET_USED(flow_wks);
14628 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
14629 : : if (!mlx5_flow_os_item_supported(items->type)) {
14630 : : ret = rte_flow_error_set(error, ENOTSUP,
14631 : : RTE_FLOW_ERROR_TYPE_ITEM,
14632 : : NULL, "item not supported");
14633 : : goto exit;
14634 : : }
14635 : : /* Non template flow. */
14636 [ # # ]: 0 : if (nt_flow) {
14637 : 0 : ret = flow_dv_translate_items_nta(&rte_eth_devices[attr->port_id],
14638 : : items, &wks, key, key_type, attr, error);
14639 [ # # ]: 0 : if (ret)
14640 : 0 : goto exit;
14641 : : } else {
14642 : 0 : ret = flow_dv_translate_items(&rte_eth_devices[attr->port_id],
14643 : : items, &wks, key, key_type, error);
14644 [ # # ]: 0 : if (ret)
14645 : 0 : goto exit;
14646 : : }
14647 : : }
14648 [ # # ]: 0 : if (wks.item_flags & MLX5_FLOW_ITEM_INTEGRITY) {
14649 : 0 : flow_dv_translate_item_integrity_post(key,
14650 : : wks.integrity_items,
14651 : : wks.item_flags,
14652 : : key_type);
14653 : : }
14654 [ # # ]: 0 : if (wks.item_flags & MLX5_FLOW_LAYER_VXLAN_GPE) {
14655 : 0 : flow_dv_translate_item_vxlan_gpe(key,
14656 : : wks.tunnel_item,
14657 : : wks.item_flags,
14658 : : key_type);
14659 [ # # ]: 0 : } else if (wks.item_flags & MLX5_FLOW_LAYER_GENEVE) {
14660 : 0 : flow_dv_translate_item_geneve(key,
14661 : : wks.tunnel_item,
14662 : : wks.item_flags,
14663 : : key_type);
14664 [ # # ]: 0 : } else if (wks.item_flags & MLX5_FLOW_LAYER_GRE) {
14665 [ # # ]: 0 : if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE) {
14666 : 0 : flow_dv_translate_item_gre(key,
14667 : : wks.tunnel_item,
14668 : : wks.item_flags,
14669 : : key_type);
14670 [ # # ]: 0 : } else if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE_OPTION) {
14671 : 0 : flow_dv_translate_item_gre_option(key,
14672 : : wks.tunnel_item,
14673 : : wks.gre_item,
14674 : : wks.item_flags,
14675 : : key_type);
14676 [ # # ]: 0 : } else if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_NVGRE) {
14677 : 0 : flow_dv_translate_item_nvgre(key,
14678 : : wks.tunnel_item,
14679 : : wks.item_flags,
14680 : : key_type);
14681 : : } else {
14682 : : MLX5_ASSERT(false);
14683 : : }
14684 : : }
14685 : :
14686 [ # # ]: 0 : if (match_criteria)
14687 : 0 : *match_criteria = flow_dv_matcher_enable(key);
14688 [ # # ]: 0 : if (item_flags)
14689 : 0 : *item_flags = wks.item_flags;
14690 : 0 : exit:
14691 : 0 : mlx5_flow_pop_thread_workspace();
14692 : 0 : return ret;
14693 : : }
14694 : :
14695 : : /**
14696 : : * Fill the HW steering flow with DV spec.
14697 : : * This function assumes given flow is created from template API.
14698 : : *
14699 : : * @param[in] items
14700 : : * Pointer to the list of items.
14701 : : * @param[in] attr
14702 : : * Pointer to the flow attributes.
14703 : : * @param[in] key
14704 : : * Pointer to the flow matcher key.
14705 : : * @param[in] key_type
14706 : : * Key type.
14707 : : * @param[in, out] item_flags
14708 : : * Pointer to the flow item flags.
14709 : : * @param[out] error
14710 : : * Pointer to the error structure.
14711 : : *
14712 : : * @return
14713 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14714 : : */
14715 : : int
14716 : 0 : flow_dv_translate_items_hws(const struct rte_flow_item *items,
14717 : : struct mlx5_flow_attr *attr, void *key,
14718 : : uint32_t key_type, uint64_t *item_flags,
14719 : : uint8_t *match_criteria,
14720 : : struct rte_flow_error *error)
14721 : : {
14722 : 0 : return __flow_dv_translate_items_hws(items, attr, key, key_type, item_flags, match_criteria,
14723 : : false, error);
14724 : : }
14725 : :
14726 : : /**
14727 : : * Fill the SW steering flow with DV spec.
14728 : : *
14729 : : * @param[in] dev
14730 : : * Pointer to rte_eth_dev structure.
14731 : : * @param[in, out] dev_flow
14732 : : * Pointer to the sub flow.
14733 : : * @param[in] attr
14734 : : * Pointer to the flow attributes.
14735 : : * @param[in] items
14736 : : * Pointer to the list of items.
14737 : : * @param[in, out] matcher
14738 : : * Pointer to the flow matcher.
14739 : : * @param[out] error
14740 : : * Pointer to the error structure.
14741 : : *
14742 : : * @return
14743 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14744 : : */
14745 : : static int
14746 : 0 : flow_dv_translate_items_sws(struct rte_eth_dev *dev,
14747 : : struct mlx5_flow *dev_flow,
14748 : : const struct rte_flow_attr *attr,
14749 : : const struct rte_flow_item *items,
14750 : : struct mlx5_flow_dv_matcher *matcher,
14751 : : struct rte_flow_error *error)
14752 : : {
14753 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14754 : 0 : void *match_mask = matcher->mask.buf;
14755 : 0 : void *match_value = dev_flow->dv.value.buf;
14756 : 0 : struct mlx5_dv_matcher_workspace wks = {
14757 : 0 : .action_flags = dev_flow->act_flags,
14758 : : .item_flags = 0,
14759 : 0 : .external = dev_flow->external,
14760 : : .next_protocol = 0xff,
14761 : 0 : .group = dev_flow->dv.group,
14762 : : .attr = attr,
14763 : 0 : .rss_desc = &((struct mlx5_flow_workspace *)
14764 : : mlx5_flow_get_thread_workspace())->rss_desc,
14765 : : };
14766 : 0 : struct mlx5_dv_matcher_workspace wks_m = wks;
14767 : : int item_type;
14768 : : int ret = 0;
14769 : : int tunnel;
14770 : :
14771 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
14772 : 0 : if (!mlx5_flow_os_item_supported(items->type))
14773 : : return rte_flow_error_set(error, ENOTSUP,
14774 : : RTE_FLOW_ERROR_TYPE_ITEM,
14775 : : NULL, "item not supported");
14776 : 0 : tunnel = !!(wks.item_flags & MLX5_FLOW_LAYER_TUNNEL);
14777 : : item_type = items->type;
14778 [ # # # # : 0 : switch (item_type) {
# ]
14779 : 0 : case RTE_FLOW_ITEM_TYPE_CONNTRACK:
14780 : 0 : flow_dv_translate_item_aso_ct(dev, match_mask,
14781 : : match_value, items);
14782 : 0 : wks.last_item = MLX5_FLOW_LAYER_ASO_CT;
14783 : 0 : break;
14784 : 0 : case RTE_FLOW_ITEM_TYPE_FLEX:
14785 : 0 : flow_dv_translate_item_flex(dev, match_mask,
14786 : : match_value, items,
14787 : : dev_flow, tunnel != 0);
14788 [ # # ]: 0 : wks.last_item = tunnel ? MLX5_FLOW_ITEM_INNER_FLEX :
14789 : : MLX5_FLOW_ITEM_OUTER_FLEX;
14790 : 0 : break;
14791 : 0 : case RTE_FLOW_ITEM_TYPE_TX_QUEUE:
14792 : 0 : ret = flow_dv_translate_item_tx_queue(dev, match_value, items,
14793 : : MLX5_SET_MATCHER_SW_V);
14794 [ # # ]: 0 : if (ret)
14795 : 0 : return rte_flow_error_set(error, -ret,
14796 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14797 : : "invalid tx_queue item spec");
14798 : 0 : ret = flow_dv_translate_item_tx_queue(dev, match_mask, items,
14799 : : MLX5_SET_MATCHER_SW_M);
14800 [ # # ]: 0 : if (ret)
14801 : 0 : return rte_flow_error_set(error, -ret,
14802 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14803 : : "invalid tx_queue item mask");
14804 : : break;
14805 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_SQ:
14806 : 0 : flow_dv_translate_item_sq(match_value, items,
14807 : : MLX5_SET_MATCHER_SW_V);
14808 : 0 : flow_dv_translate_item_sq(match_mask, items,
14809 : : MLX5_SET_MATCHER_SW_M);
14810 : 0 : break;
14811 : 0 : default:
14812 : 0 : ret = flow_dv_translate_items(dev, items, &wks_m,
14813 : : match_mask, MLX5_SET_MATCHER_SW_M, error);
14814 [ # # ]: 0 : if (ret)
14815 : 0 : return ret;
14816 : 0 : ret = flow_dv_translate_items(dev, items, &wks,
14817 : : match_value, MLX5_SET_MATCHER_SW_V, error);
14818 [ # # ]: 0 : if (ret)
14819 : 0 : return ret;
14820 : : break;
14821 : : }
14822 : 0 : wks.item_flags |= wks.last_item;
14823 : : }
14824 : : /*
14825 : : * When E-Switch mode is enabled, we have two cases where we need to
14826 : : * set the source port manually.
14827 : : * The first one, is in case of NIC ingress steering rule, and the
14828 : : * second is E-Switch rule where no port_id item was found.
14829 : : * In both cases the source port is set according the current port
14830 : : * in use.
14831 : : */
14832 : 0 : if (!(wks.item_flags & MLX5_FLOW_ITEM_PORT_ID) &&
14833 [ # # ]: 0 : !(wks.item_flags & MLX5_FLOW_ITEM_REPRESENTED_PORT) &&
14834 : 0 : !(wks.item_flags & MLX5_FLOW_ITEM_PORT_REPRESENTOR) &&
14835 [ # # ]: 0 : priv->sh->esw_mode &&
14836 [ # # ]: 0 : !attr->egress &&
14837 [ # # ]: 0 : attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP) {
14838 [ # # ]: 0 : if (flow_dv_translate_item_port_id_all(dev, match_mask,
14839 : : match_value, NULL, attr))
14840 : 0 : return -rte_errno;
14841 : : }
14842 [ # # ]: 0 : if (wks.item_flags & MLX5_FLOW_ITEM_INTEGRITY) {
14843 : 0 : flow_dv_translate_item_integrity_post(match_mask,
14844 : : wks_m.integrity_items,
14845 : : wks_m.item_flags,
14846 : : MLX5_SET_MATCHER_SW_M);
14847 : 0 : flow_dv_translate_item_integrity_post(match_value,
14848 : : wks.integrity_items,
14849 : : wks.item_flags,
14850 : : MLX5_SET_MATCHER_SW_V);
14851 : : }
14852 [ # # ]: 0 : if (wks.item_flags & MLX5_FLOW_LAYER_VXLAN_GPE) {
14853 : 0 : flow_dv_translate_item_vxlan_gpe(match_mask,
14854 : : wks.tunnel_item,
14855 : : wks.item_flags,
14856 : : MLX5_SET_MATCHER_SW_M);
14857 : 0 : flow_dv_translate_item_vxlan_gpe(match_value,
14858 : : wks.tunnel_item,
14859 : : wks.item_flags,
14860 : : MLX5_SET_MATCHER_SW_V);
14861 [ # # ]: 0 : } else if (wks.item_flags & MLX5_FLOW_LAYER_GENEVE) {
14862 : 0 : flow_dv_translate_item_geneve(match_mask,
14863 : : wks.tunnel_item,
14864 : : wks.item_flags,
14865 : : MLX5_SET_MATCHER_SW_M);
14866 : 0 : flow_dv_translate_item_geneve(match_value,
14867 : : wks.tunnel_item,
14868 : : wks.item_flags,
14869 : : MLX5_SET_MATCHER_SW_V);
14870 [ # # ]: 0 : } else if (wks.item_flags & MLX5_FLOW_LAYER_GRE) {
14871 [ # # ]: 0 : if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE) {
14872 : 0 : flow_dv_translate_item_gre(match_mask,
14873 : : wks.tunnel_item,
14874 : : wks.item_flags,
14875 : : MLX5_SET_MATCHER_SW_M);
14876 : 0 : flow_dv_translate_item_gre(match_value,
14877 : : wks.tunnel_item,
14878 : : wks.item_flags,
14879 : : MLX5_SET_MATCHER_SW_V);
14880 [ # # ]: 0 : } else if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_NVGRE) {
14881 : 0 : flow_dv_translate_item_nvgre(match_mask,
14882 : : wks.tunnel_item,
14883 : : wks.item_flags,
14884 : : MLX5_SET_MATCHER_SW_M);
14885 : 0 : flow_dv_translate_item_nvgre(match_value,
14886 : : wks.tunnel_item,
14887 : : wks.item_flags,
14888 : : MLX5_SET_MATCHER_SW_V);
14889 [ # # ]: 0 : } else if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE_OPTION) {
14890 : 0 : flow_dv_translate_item_gre_option(match_mask,
14891 : : wks.tunnel_item,
14892 : : wks.gre_item,
14893 : : wks.item_flags,
14894 : : MLX5_SET_MATCHER_SW_M);
14895 : 0 : flow_dv_translate_item_gre_option(match_value,
14896 : : wks.tunnel_item,
14897 : : wks.gre_item,
14898 : : wks.item_flags,
14899 : : MLX5_SET_MATCHER_SW_V);
14900 : : } else {
14901 : : MLX5_ASSERT(false);
14902 : : }
14903 : : }
14904 : 0 : dev_flow->handle->vf_vlan.tag = wks.vlan_tag;
14905 : 0 : matcher->priority = wks.priority;
14906 : : #ifdef RTE_LIBRTE_MLX5_DEBUG
14907 : : MLX5_ASSERT(!flow_dv_check_valid_spec(match_mask, match_value));
14908 : : #endif
14909 : : /*
14910 : : * Layers may be already initialized from prefix flow if this dev_flow
14911 : : * is the suffix flow.
14912 : : */
14913 : 0 : dev_flow->handle->layers |= wks.item_flags;
14914 : : /*
14915 : : * Update geneve_tlv_option flag only it is set in workspace.
14916 : : * Avoid be overwritten by other sub mlx5_flows.
14917 : : */
14918 [ # # ]: 0 : if (wks.geneve_tlv_option)
14919 : 0 : dev_flow->flow->geneve_tlv_option += wks.geneve_tlv_option;
14920 : : return 0;
14921 : : }
14922 : :
14923 : : /**
14924 : : * Fill the flow with DV spec, lock free
14925 : : * (mutex should be acquired by caller).
14926 : : *
14927 : : * @param[in] dev
14928 : : * Pointer to rte_eth_dev structure.
14929 : : * @param[in, out] dev_flow
14930 : : * Pointer to the sub flow.
14931 : : * @param[in] attr
14932 : : * Pointer to the flow attributes.
14933 : : * @param[in] items
14934 : : * Pointer to the list of items.
14935 : : * @param[in] actions
14936 : : * Pointer to the list of actions.
14937 : : * @param[out] error
14938 : : * Pointer to the error structure.
14939 : : *
14940 : : * @return
14941 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14942 : : */
14943 : : static int
14944 : 0 : flow_dv_translate(struct rte_eth_dev *dev,
14945 : : struct mlx5_flow *dev_flow,
14946 : : const struct rte_flow_attr *attr,
14947 : : const struct rte_flow_item items[],
14948 : : const struct rte_flow_action actions[],
14949 : : struct rte_flow_error *error)
14950 : : {
14951 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14952 : 0 : struct mlx5_sh_config *dev_conf = &priv->sh->config;
14953 : 0 : struct rte_flow *flow = dev_flow->flow;
14954 : 0 : struct mlx5_flow_handle *handle = dev_flow->handle;
14955 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
14956 : : struct mlx5_flow_rss_desc *rss_desc;
14957 : : uint64_t action_flags = 0;
14958 : 0 : struct mlx5_flow_dv_matcher matcher = {
14959 : : .mask = {
14960 : : .size = sizeof(matcher.mask.buf),
14961 : : },
14962 : : };
14963 : : int actions_n = 0;
14964 : : bool actions_end = false;
14965 : : union {
14966 : : struct mlx5_flow_dv_modify_hdr_resource res;
14967 : : uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
14968 : : sizeof(struct mlx5_modification_cmd) *
14969 : : (MLX5_MAX_MODIFY_NUM + 1)];
14970 : : } mhdr_dummy;
14971 : : struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
14972 : : const struct rte_flow_action_count *count = NULL;
14973 : : const struct rte_flow_action_age *non_shared_age = NULL;
14974 : 0 : union flow_dv_attr flow_attr = { .attr = 0 };
14975 : : uint32_t tag_be;
14976 : : union mlx5_flow_tbl_key tbl_key;
14977 : : uint32_t modify_action_position = UINT32_MAX;
14978 : 0 : struct rte_vlan_hdr vlan = { 0 };
14979 : : struct mlx5_flow_dv_dest_array_resource mdest_res;
14980 : : struct mlx5_flow_dv_sample_resource sample_res;
14981 : 0 : void *sample_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
14982 : : const struct rte_flow_action_sample *sample = NULL;
14983 : : struct mlx5_flow_sub_actions_list *sample_act;
14984 : : uint32_t sample_act_pos = UINT32_MAX;
14985 : : uint32_t age_act_pos = UINT32_MAX;
14986 : : uint32_t ipv6_tc_off = 0;
14987 : 0 : uint32_t num_of_dest = 0;
14988 : : int tmp_actions_n = 0;
14989 : : uint32_t table;
14990 : : int ret = 0;
14991 : : const struct mlx5_flow_tunnel *tunnel = NULL;
14992 : 0 : struct flow_grp_info grp_info = {
14993 : 0 : .external = !!dev_flow->external,
14994 : 0 : .transfer = !!attr->transfer,
14995 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
14996 : 0 : .skip_scale = dev_flow->skip_scale &
14997 : : (1 << MLX5_SCALE_FLOW_GROUP_BIT),
14998 : : .std_tbl_fix = true,
14999 : : };
15000 : :
15001 [ # # ]: 0 : if (!wks)
15002 : 0 : return rte_flow_error_set(error, ENOMEM,
15003 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15004 : : NULL,
15005 : : "failed to push flow workspace");
15006 [ # # ]: 0 : rss_desc = &wks->rss_desc;
15007 : : memset(&mdest_res, 0, sizeof(struct mlx5_flow_dv_dest_array_resource));
15008 : : memset(&sample_res, 0, sizeof(struct mlx5_flow_dv_sample_resource));
15009 [ # # ]: 0 : mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
15010 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
15011 : : /* update normal path action resource into last index of array */
15012 : : sample_act = &mdest_res.sample_act[MLX5_MAX_DEST_NUM - 1];
15013 [ # # ]: 0 : if (is_tunnel_offload_active(dev)) {
15014 [ # # ]: 0 : if (dev_flow->tunnel) {
15015 [ # # ]: 0 : RTE_VERIFY(dev_flow->tof_type ==
15016 : : MLX5_TUNNEL_OFFLOAD_MISS_RULE);
15017 : : tunnel = dev_flow->tunnel;
15018 : : } else {
15019 : 0 : tunnel = mlx5_get_tof(items, actions,
15020 : : &dev_flow->tof_type);
15021 : 0 : dev_flow->tunnel = tunnel;
15022 : : }
15023 [ # # ]: 0 : grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
15024 : : (dev, attr, tunnel, dev_flow->tof_type);
15025 : : }
15026 : 0 : mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
15027 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
15028 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel, attr->group, &table,
15029 : : &grp_info, error);
15030 [ # # ]: 0 : if (ret)
15031 : : return ret;
15032 : 0 : dev_flow->dv.group = table;
15033 [ # # ]: 0 : if (attr->transfer)
15034 : 0 : mhdr_res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
15035 : : /* number of actions must be set to 0 in case of dirty stack. */
15036 : 0 : mhdr_res->actions_num = 0;
15037 [ # # ]: 0 : if (is_flow_tunnel_match_rule(dev_flow->tof_type)) {
15038 : : /*
15039 : : * do not add decap action if match rule drops packet
15040 : : * HW rejects rules with decap & drop
15041 : : *
15042 : : * if tunnel match rule was inserted before matching tunnel set
15043 : : * rule flow table used in the match rule must be registered.
15044 : : * current implementation handles that in the
15045 : : * flow_dv_match_register() at the function end.
15046 : : */
15047 : : bool add_decap = true;
15048 : : const struct rte_flow_action *ptr = actions;
15049 : :
15050 [ # # ]: 0 : for (; ptr->type != RTE_FLOW_ACTION_TYPE_END; ptr++) {
15051 [ # # ]: 0 : if (ptr->type == RTE_FLOW_ACTION_TYPE_DROP) {
15052 : : add_decap = false;
15053 : : break;
15054 : : }
15055 : : }
15056 [ # # ]: 0 : if (add_decap) {
15057 [ # # ]: 0 : if (flow_dv_create_action_l2_decap(dev, dev_flow,
15058 : 0 : attr->transfer,
15059 : : error))
15060 : 0 : return -rte_errno;
15061 : 0 : dev_flow->dv.actions[actions_n++] =
15062 : 0 : dev_flow->dv.encap_decap->action;
15063 : : action_flags |= MLX5_FLOW_ACTION_DECAP;
15064 : : }
15065 : : }
15066 [ # # ]: 0 : for (; !actions_end ; actions++) {
15067 : : const struct rte_flow_action_queue *queue;
15068 : : const struct rte_flow_action_rss *rss;
15069 : : const struct rte_flow_action *action = actions;
15070 : : const uint8_t *rss_key;
15071 : : struct mlx5_flow_tbl_resource *tbl;
15072 : : struct mlx5_aso_age_action *age_act;
15073 : : struct mlx5_flow_counter *cnt_act;
15074 : 0 : uint32_t port_id = 0;
15075 : : struct mlx5_flow_dv_port_id_action_resource port_id_resource;
15076 : 0 : int action_type = actions->type;
15077 : : const struct rte_flow_action *found_action = NULL;
15078 : : uint32_t jump_group = 0;
15079 : : uint32_t owner_idx;
15080 : : struct mlx5_aso_ct_action *ct;
15081 : :
15082 : : if (!mlx5_flow_os_action_supported(action_type))
15083 : 0 : return rte_flow_error_set(error, ENOTSUP,
15084 : : RTE_FLOW_ERROR_TYPE_ACTION,
15085 : : actions,
15086 : : "action not supported");
15087 [ # # # # : 0 : switch (action_type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
15088 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
15089 : 0 : action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
15090 : 0 : break;
15091 : : case RTE_FLOW_ACTION_TYPE_VOID:
15092 : : break;
15093 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
15094 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
15095 [ # # ]: 0 : if (flow_dv_translate_action_port_id(dev, action,
15096 : : &port_id, error))
15097 : 0 : return -rte_errno;
15098 : 0 : port_id_resource.port_id = port_id;
15099 : : MLX5_ASSERT(!handle->rix_port_id_action);
15100 [ # # ]: 0 : if (flow_dv_port_id_action_resource_register
15101 : : (dev, &port_id_resource, dev_flow, error))
15102 : 0 : return -rte_errno;
15103 : 0 : dev_flow->dv.actions[actions_n++] =
15104 : 0 : dev_flow->dv.port_id_action->action;
15105 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_ID;
15106 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_PORT_ID;
15107 : 0 : sample_act->action_flags |= MLX5_FLOW_ACTION_PORT_ID;
15108 : 0 : num_of_dest++;
15109 : 0 : break;
15110 : 0 : case RTE_FLOW_ACTION_TYPE_FLAG:
15111 : 0 : action_flags |= MLX5_FLOW_ACTION_FLAG;
15112 : 0 : wks->mark = 1;
15113 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
15114 : 0 : struct rte_flow_action_mark mark = {
15115 : : .id = MLX5_FLOW_MARK_DEFAULT,
15116 : : };
15117 : :
15118 [ # # ]: 0 : if (flow_dv_convert_action_mark(dev, &mark,
15119 : : mhdr_res,
15120 : : error))
15121 : 0 : return -rte_errno;
15122 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
15123 : 0 : break;
15124 : : }
15125 : : tag_be = mlx5_flow_mark_set(MLX5_FLOW_MARK_DEFAULT);
15126 : : /*
15127 : : * Only one FLAG or MARK is supported per device flow
15128 : : * right now. So the pointer to the tag resource must be
15129 : : * zero before the register process.
15130 : : */
15131 : : MLX5_ASSERT(!handle->dvh.rix_tag);
15132 [ # # ]: 0 : if (flow_dv_tag_resource_register(dev, tag_be,
15133 : : dev_flow, error))
15134 : 0 : return -rte_errno;
15135 : : MLX5_ASSERT(dev_flow->dv.tag_resource);
15136 : 0 : dev_flow->dv.actions[actions_n++] =
15137 : 0 : dev_flow->dv.tag_resource->action;
15138 : 0 : break;
15139 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
15140 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK;
15141 : 0 : wks->mark = 1;
15142 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
15143 : 0 : const struct rte_flow_action_mark *mark =
15144 : : (const struct rte_flow_action_mark *)
15145 : : actions->conf;
15146 : :
15147 [ # # ]: 0 : if (flow_dv_convert_action_mark(dev, mark,
15148 : : mhdr_res,
15149 : : error))
15150 : 0 : return -rte_errno;
15151 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
15152 : 0 : break;
15153 : : }
15154 : : /* Fall-through */
15155 : : case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
15156 : : /* Legacy (non-extensive) MARK action. */
15157 : : tag_be = mlx5_flow_mark_set
15158 : : (((const struct rte_flow_action_mark *)
15159 [ # # ]: 0 : (actions->conf))->id);
15160 : : MLX5_ASSERT(!handle->dvh.rix_tag);
15161 [ # # ]: 0 : if (flow_dv_tag_resource_register(dev, tag_be,
15162 : : dev_flow, error))
15163 : 0 : return -rte_errno;
15164 : : MLX5_ASSERT(dev_flow->dv.tag_resource);
15165 : 0 : dev_flow->dv.actions[actions_n++] =
15166 : 0 : dev_flow->dv.tag_resource->action;
15167 : 0 : break;
15168 : 0 : case RTE_FLOW_ACTION_TYPE_SET_META:
15169 [ # # ]: 0 : if (flow_dv_convert_action_set_meta
15170 : : (dev, mhdr_res, attr,
15171 : : (const struct rte_flow_action_set_meta *)
15172 : 0 : actions->conf, error))
15173 : 0 : return -rte_errno;
15174 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_META;
15175 : 0 : break;
15176 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TAG:
15177 [ # # ]: 0 : if (flow_dv_convert_action_set_tag
15178 : : (dev, mhdr_res,
15179 : : (const struct rte_flow_action_set_tag *)
15180 : 0 : actions->conf, error))
15181 : 0 : return -rte_errno;
15182 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
15183 : 0 : break;
15184 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
15185 : 0 : action_flags |= MLX5_FLOW_ACTION_DROP;
15186 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_DROP;
15187 : 0 : break;
15188 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
15189 : 0 : queue = actions->conf;
15190 : 0 : rss_desc->queue_num = 1;
15191 : 0 : rss_desc->queue[0] = queue->index;
15192 : 0 : action_flags |= MLX5_FLOW_ACTION_QUEUE;
15193 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
15194 : 0 : sample_act->action_flags |= MLX5_FLOW_ACTION_QUEUE;
15195 : 0 : num_of_dest++;
15196 : 0 : break;
15197 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
15198 : 0 : rss = actions->conf;
15199 : 0 : rss_desc->symmetric_hash_function =
15200 : 0 : MLX5_RSS_IS_SYMM(rss->func);
15201 : 0 : memcpy(rss_desc->queue, rss->queue,
15202 [ # # ]: 0 : rss->queue_num * sizeof(uint16_t));
15203 : 0 : rss_desc->queue_num = rss->queue_num;
15204 : : /* NULL RSS key indicates default RSS key. */
15205 [ # # ]: 0 : rss_key = !rss->key ? rss_hash_default_key : rss->key;
15206 [ # # ]: 0 : memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
15207 : : /*
15208 : : * rss->level and rss.types should be set in advance
15209 : : * when expanding items for RSS.
15210 : : */
15211 : 0 : action_flags |= MLX5_FLOW_ACTION_RSS;
15212 : 0 : dev_flow->handle->fate_action = rss_desc->shared_rss ?
15213 [ # # ]: 0 : MLX5_FLOW_FATE_SHARED_RSS :
15214 : : MLX5_FLOW_FATE_QUEUE;
15215 : 0 : break;
15216 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
15217 : 0 : owner_idx = (uint32_t)(uintptr_t)action->conf;
15218 : 0 : age_act = flow_aso_age_get_by_idx(dev, owner_idx);
15219 [ # # ]: 0 : if (flow->age == 0) {
15220 : 0 : flow->age = owner_idx;
15221 : 0 : rte_atomic_fetch_add_explicit(&age_act->refcnt, 1,
15222 : : rte_memory_order_relaxed);
15223 : : }
15224 : 0 : age_act_pos = actions_n++;
15225 : 0 : action_flags |= MLX5_FLOW_ACTION_AGE;
15226 : 0 : break;
15227 : 0 : case RTE_FLOW_ACTION_TYPE_SEND_TO_KERNEL:
15228 : 0 : dev_flow->dv.actions[actions_n] =
15229 : 0 : flow_dv_translate_action_send_to_kernel(dev, attr,
15230 : : error);
15231 [ # # ]: 0 : if (!dev_flow->dv.actions[actions_n])
15232 : 0 : return -rte_errno;
15233 : 0 : actions_n++;
15234 : 0 : action_flags |= MLX5_FLOW_ACTION_SEND_TO_KERNEL;
15235 : 0 : dev_flow->handle->fate_action =
15236 : : MLX5_FLOW_FATE_SEND_TO_KERNEL;
15237 : 0 : break;
15238 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
15239 : 0 : non_shared_age = action->conf;
15240 : 0 : age_act_pos = actions_n++;
15241 : 0 : action_flags |= MLX5_FLOW_ACTION_AGE;
15242 : 0 : break;
15243 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
15244 [ # # ]: 0 : owner_idx = (uint32_t)(uintptr_t)action->conf;
15245 : : cnt_act = flow_dv_counter_get_by_idx(dev, owner_idx,
15246 : : NULL);
15247 : : MLX5_ASSERT(cnt_act != NULL);
15248 : : /**
15249 : : * When creating meter drop flow in drop table, the
15250 : : * counter should not overwrite the rte flow counter.
15251 : : */
15252 [ # # ]: 0 : if (attr->group == MLX5_FLOW_TABLE_LEVEL_METER &&
15253 [ # # ]: 0 : dev_flow->dv.table_id == MLX5_MTR_TABLE_ID_DROP) {
15254 : 0 : dev_flow->dv.actions[actions_n++] =
15255 : 0 : cnt_act->action;
15256 : : } else {
15257 [ # # ]: 0 : if (flow->counter == 0) {
15258 : 0 : flow->counter = owner_idx;
15259 : 0 : rte_atomic_fetch_add_explicit
15260 : : (&cnt_act->shared_info.refcnt,
15261 : : 1, rte_memory_order_relaxed);
15262 : : }
15263 : : /* Save information first, will apply later. */
15264 : 0 : action_flags |= MLX5_FLOW_ACTION_COUNT;
15265 : : }
15266 : : break;
15267 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
15268 [ # # ]: 0 : if (!priv->sh->cdev->config.devx) {
15269 : 0 : return rte_flow_error_set
15270 : : (error, ENOTSUP,
15271 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15272 : : NULL,
15273 : : "count action not supported");
15274 : : }
15275 : : /* Save information first, will apply later. */
15276 : 0 : count = action->conf;
15277 : 0 : action_flags |= MLX5_FLOW_ACTION_COUNT;
15278 : 0 : break;
15279 : 0 : case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
15280 : 0 : dev_flow->dv.actions[actions_n++] =
15281 : 0 : priv->sh->pop_vlan_action;
15282 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
15283 : 0 : break;
15284 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
15285 [ # # ]: 0 : if (!(action_flags &
15286 : : MLX5_FLOW_ACTION_OF_SET_VLAN_VID))
15287 : 0 : flow_dev_get_vlan_info_from_items(items, &vlan);
15288 [ # # ]: 0 : vlan.eth_proto = rte_be_to_cpu_16
15289 : : ((((const struct rte_flow_action_of_push_vlan *)
15290 : : actions->conf)->ethertype));
15291 : 0 : found_action = mlx5_flow_find_action
15292 : : (actions + 1,
15293 : : RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID);
15294 [ # # ]: 0 : if (found_action)
15295 : 0 : mlx5_update_vlan_vid_pcp(found_action, &vlan);
15296 : 0 : found_action = mlx5_flow_find_action
15297 : : (actions + 1,
15298 : : RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP);
15299 [ # # ]: 0 : if (found_action)
15300 : 0 : mlx5_update_vlan_vid_pcp(found_action, &vlan);
15301 [ # # ]: 0 : if (flow_dv_create_action_push_vlan
15302 : : (dev, attr, &vlan, dev_flow, error))
15303 : 0 : return -rte_errno;
15304 : 0 : dev_flow->dv.actions[actions_n++] =
15305 : 0 : dev_flow->dv.push_vlan_res->action;
15306 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
15307 : 0 : break;
15308 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
15309 : : /* of_vlan_push action handled this action */
15310 : : MLX5_ASSERT(action_flags &
15311 : : MLX5_FLOW_ACTION_OF_PUSH_VLAN);
15312 : : break;
15313 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
15314 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
15315 : : break;
15316 : 0 : flow_dev_get_vlan_info_from_items(items, &vlan);
15317 : 0 : mlx5_update_vlan_vid_pcp(actions, &vlan);
15318 : : /* If no VLAN push - this is a modify header action */
15319 [ # # ]: 0 : if (flow_dv_convert_action_modify_vlan_vid
15320 : : (mhdr_res, actions, error))
15321 : 0 : return -rte_errno;
15322 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
15323 : 0 : break;
15324 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
15325 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
15326 [ # # ]: 0 : if (flow_dv_create_action_l2_encap(dev, actions,
15327 : : dev_flow,
15328 : 0 : attr->transfer,
15329 : : error))
15330 : 0 : return -rte_errno;
15331 : 0 : dev_flow->dv.actions[actions_n++] =
15332 : 0 : dev_flow->dv.encap_decap->action;
15333 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
15334 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
15335 : 0 : sample_act->action_flags |=
15336 : : MLX5_FLOW_ACTION_ENCAP;
15337 : : break;
15338 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
15339 : : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
15340 [ # # ]: 0 : if (flow_dv_create_action_l2_decap(dev, dev_flow,
15341 : 0 : attr->transfer,
15342 : : error))
15343 : 0 : return -rte_errno;
15344 : 0 : dev_flow->dv.actions[actions_n++] =
15345 : 0 : dev_flow->dv.encap_decap->action;
15346 : 0 : action_flags |= MLX5_FLOW_ACTION_DECAP;
15347 : 0 : break;
15348 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
15349 : : /* Handle encap with preceding decap. */
15350 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_DECAP) {
15351 [ # # ]: 0 : if (flow_dv_create_action_raw_encap
15352 : : (dev, actions, dev_flow, attr, error))
15353 : 0 : return -rte_errno;
15354 : 0 : dev_flow->dv.actions[actions_n++] =
15355 : 0 : dev_flow->dv.encap_decap->action;
15356 : : } else {
15357 : : /* Handle encap without preceding decap. */
15358 [ # # ]: 0 : if (flow_dv_create_action_l2_encap
15359 : 0 : (dev, actions, dev_flow, attr->transfer,
15360 : : error))
15361 : 0 : return -rte_errno;
15362 : 0 : dev_flow->dv.actions[actions_n++] =
15363 : 0 : dev_flow->dv.encap_decap->action;
15364 : : }
15365 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
15366 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
15367 : 0 : sample_act->action_flags |=
15368 : : MLX5_FLOW_ACTION_ENCAP;
15369 : : break;
15370 : : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
15371 [ # # ]: 0 : while ((++action)->type == RTE_FLOW_ACTION_TYPE_VOID)
15372 : : ;
15373 [ # # ]: 0 : if (action->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
15374 [ # # ]: 0 : if (flow_dv_create_action_l2_decap
15375 : 0 : (dev, dev_flow, attr->transfer, error))
15376 : 0 : return -rte_errno;
15377 : 0 : dev_flow->dv.actions[actions_n++] =
15378 : 0 : dev_flow->dv.encap_decap->action;
15379 : : }
15380 : : /* If decap is followed by encap, handle it at encap. */
15381 : 0 : action_flags |= MLX5_FLOW_ACTION_DECAP;
15382 : 0 : break;
15383 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_JUMP:
15384 : 0 : dev_flow->dv.actions[actions_n++] =
15385 : 0 : (void *)(uintptr_t)action->conf;
15386 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP;
15387 : 0 : break;
15388 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
15389 : 0 : jump_group = ((const struct rte_flow_action_jump *)
15390 : 0 : action->conf)->group;
15391 : 0 : grp_info.std_tbl_fix = 0;
15392 [ # # ]: 0 : if (dev_flow->skip_scale &
15393 : : (1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT))
15394 : 0 : grp_info.skip_scale = 1;
15395 : : else
15396 : 0 : grp_info.skip_scale = 0;
15397 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel,
15398 : : jump_group,
15399 : : &table,
15400 : : &grp_info, error);
15401 [ # # ]: 0 : if (ret)
15402 : 0 : return ret;
15403 : 0 : tbl = flow_dv_tbl_resource_get(dev, table, attr->egress,
15404 : 0 : attr->transfer,
15405 : 0 : !!dev_flow->external,
15406 : : tunnel, jump_group, 0,
15407 : : 0, error);
15408 [ # # ]: 0 : if (!tbl)
15409 : 0 : return rte_flow_error_set
15410 : 0 : (error, errno,
15411 : : RTE_FLOW_ERROR_TYPE_ACTION,
15412 : : NULL,
15413 : : "cannot create jump action.");
15414 : : if (flow_dv_jump_tbl_resource_register
15415 : : (dev, tbl, dev_flow, error)) {
15416 : : flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
15417 : : return rte_flow_error_set
15418 : : (error, errno,
15419 : : RTE_FLOW_ERROR_TYPE_ACTION,
15420 : : NULL,
15421 : : "cannot create jump action.");
15422 : : }
15423 : 0 : dev_flow->dv.actions[actions_n++] =
15424 : 0 : dev_flow->dv.jump->action;
15425 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP;
15426 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_JUMP;
15427 : 0 : sample_act->action_flags |= MLX5_FLOW_ACTION_JUMP;
15428 : 0 : num_of_dest++;
15429 : 0 : break;
15430 : 0 : case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
15431 : : case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
15432 [ # # ]: 0 : if (flow_dv_convert_action_modify_mac
15433 : : (mhdr_res, actions, error))
15434 : 0 : return -rte_errno;
15435 : 0 : action_flags |= actions->type ==
15436 : : RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
15437 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_MAC_SRC :
15438 : : MLX5_FLOW_ACTION_SET_MAC_DST;
15439 : 0 : break;
15440 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
15441 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
15442 [ # # ]: 0 : if (flow_dv_convert_action_modify_ipv4
15443 : : (mhdr_res, actions, error))
15444 : 0 : return -rte_errno;
15445 : 0 : action_flags |= actions->type ==
15446 : : RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
15447 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_IPV4_SRC :
15448 : : MLX5_FLOW_ACTION_SET_IPV4_DST;
15449 : 0 : break;
15450 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
15451 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
15452 [ # # ]: 0 : if (flow_dv_convert_action_modify_ipv6
15453 : : (mhdr_res, actions, error))
15454 : 0 : return -rte_errno;
15455 : 0 : action_flags |= actions->type ==
15456 : : RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
15457 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_IPV6_SRC :
15458 : : MLX5_FLOW_ACTION_SET_IPV6_DST;
15459 : 0 : break;
15460 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
15461 : : case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
15462 [ # # ]: 0 : if (flow_dv_convert_action_modify_tp
15463 : : (mhdr_res, actions, items,
15464 : 0 : &flow_attr, dev_flow, !!(action_flags &
15465 : : MLX5_FLOW_ACTION_DECAP), error))
15466 : 0 : return -rte_errno;
15467 : 0 : action_flags |= actions->type ==
15468 : : RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
15469 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_TP_SRC :
15470 : : MLX5_FLOW_ACTION_SET_TP_DST;
15471 : 0 : break;
15472 : 0 : case RTE_FLOW_ACTION_TYPE_DEC_TTL:
15473 [ # # ]: 0 : if (flow_dv_convert_action_modify_dec_ttl
15474 : : (mhdr_res, items, &flow_attr, dev_flow,
15475 : 0 : !!(action_flags &
15476 : : MLX5_FLOW_ACTION_DECAP), error))
15477 : 0 : return -rte_errno;
15478 : 0 : action_flags |= MLX5_FLOW_ACTION_DEC_TTL;
15479 : 0 : break;
15480 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TTL:
15481 [ # # ]: 0 : if (flow_dv_convert_action_modify_ttl
15482 : : (mhdr_res, actions, items, &flow_attr,
15483 : 0 : dev_flow, !!(action_flags &
15484 : : MLX5_FLOW_ACTION_DECAP), error))
15485 : 0 : return -rte_errno;
15486 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TTL;
15487 : 0 : break;
15488 : 0 : case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
15489 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
15490 [ # # ]: 0 : if (flow_dv_convert_action_modify_tcp_seq
15491 : : (mhdr_res, actions, error))
15492 : 0 : return -rte_errno;
15493 : 0 : action_flags |= actions->type ==
15494 : : RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
15495 [ # # ]: 0 : MLX5_FLOW_ACTION_INC_TCP_SEQ :
15496 : : MLX5_FLOW_ACTION_DEC_TCP_SEQ;
15497 : 0 : break;
15498 : :
15499 : 0 : case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
15500 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
15501 [ # # ]: 0 : if (flow_dv_convert_action_modify_tcp_ack
15502 : : (mhdr_res, actions, error))
15503 : 0 : return -rte_errno;
15504 : 0 : action_flags |= actions->type ==
15505 : : RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
15506 [ # # ]: 0 : MLX5_FLOW_ACTION_INC_TCP_ACK :
15507 : : MLX5_FLOW_ACTION_DEC_TCP_ACK;
15508 : 0 : break;
15509 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
15510 [ # # ]: 0 : if (flow_dv_convert_action_set_reg
15511 : : (mhdr_res, actions, error))
15512 : 0 : return -rte_errno;
15513 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
15514 : 0 : break;
15515 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
15516 [ # # ]: 0 : if (flow_dv_convert_action_copy_mreg
15517 : : (dev, mhdr_res, actions, error))
15518 : 0 : return -rte_errno;
15519 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
15520 : 0 : break;
15521 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
15522 : 0 : action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
15523 : 0 : dev_flow->handle->fate_action =
15524 : : MLX5_FLOW_FATE_DEFAULT_MISS;
15525 : 0 : break;
15526 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
15527 [ # # ]: 0 : if (!wks->fm)
15528 : 0 : return rte_flow_error_set(error, rte_errno,
15529 : : RTE_FLOW_ERROR_TYPE_ACTION,
15530 : : NULL, "Failed to get meter in flow.");
15531 : : /* Set the meter action. */
15532 : 0 : dev_flow->dv.actions[actions_n++] =
15533 : 0 : wks->fm->meter_action_g;
15534 : 0 : action_flags |= MLX5_FLOW_ACTION_METER;
15535 : 0 : break;
15536 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
15537 [ # # ]: 0 : if (flow_dv_convert_action_modify_ipv4_dscp(mhdr_res,
15538 : : actions, error))
15539 : 0 : return -rte_errno;
15540 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
15541 : 0 : break;
15542 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
15543 [ # # ]: 0 : if (mlx5_dv_modify_ipv6_traffic_class_supported(priv))
15544 : : ipv6_tc_off = MLX5_IPV6_HDR_DSCP_SHIFT;
15545 : : else
15546 : : ipv6_tc_off = 0;
15547 [ # # ]: 0 : if (flow_dv_convert_action_modify_ipv6_dscp(mhdr_res,
15548 : : actions, ipv6_tc_off, error))
15549 : 0 : return -rte_errno;
15550 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
15551 : 0 : break;
15552 : 0 : case RTE_FLOW_ACTION_TYPE_SAMPLE:
15553 : 0 : sample_act_pos = actions_n;
15554 : 0 : sample = (const struct rte_flow_action_sample *)
15555 : : action->conf;
15556 : 0 : actions_n++;
15557 : 0 : action_flags |= MLX5_FLOW_ACTION_SAMPLE;
15558 : : /* put encap action into group if work with port id */
15559 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_ENCAP) &&
15560 : : (action_flags & MLX5_FLOW_ACTION_PORT_ID))
15561 : 0 : sample_act->action_flags |=
15562 : : MLX5_FLOW_ACTION_ENCAP;
15563 : : break;
15564 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
15565 [ # # ]: 0 : if (flow_dv_convert_action_modify_field
15566 : : (dev, mhdr_res, actions, attr, error))
15567 : 0 : return -rte_errno;
15568 : 0 : action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
15569 : 0 : break;
15570 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
15571 : 0 : owner_idx = (uint32_t)(uintptr_t)action->conf;
15572 : 0 : ct = flow_aso_ct_get_by_idx(dev, owner_idx);
15573 [ # # ]: 0 : if (!ct)
15574 : 0 : return rte_flow_error_set(error, EINVAL,
15575 : : RTE_FLOW_ERROR_TYPE_ACTION,
15576 : : NULL,
15577 : : "Failed to get CT object.");
15578 [ # # ]: 0 : if (mlx5_aso_ct_available(priv->sh, MLX5_HW_INV_QUEUE, ct))
15579 : 0 : return rte_flow_error_set(error, rte_errno,
15580 : : RTE_FLOW_ERROR_TYPE_ACTION,
15581 : : NULL,
15582 : : "CT is unavailable.");
15583 [ # # ]: 0 : if (ct->is_original)
15584 : 0 : dev_flow->dv.actions[actions_n] =
15585 : 0 : ct->dr_action_orig;
15586 : : else
15587 : 0 : dev_flow->dv.actions[actions_n] =
15588 : 0 : ct->dr_action_rply;
15589 [ # # ]: 0 : if (flow->ct == 0) {
15590 : 0 : flow->indirect_type =
15591 : : MLX5_INDIRECT_ACTION_TYPE_CT;
15592 : 0 : flow->ct = owner_idx;
15593 : 0 : rte_atomic_fetch_add_explicit(&ct->refcnt, 1,
15594 : : rte_memory_order_relaxed);
15595 : : }
15596 : 0 : actions_n++;
15597 : 0 : action_flags |= MLX5_FLOW_ACTION_CT;
15598 : 0 : break;
15599 : 0 : case RTE_FLOW_ACTION_TYPE_END:
15600 : : actions_end = true;
15601 [ # # ]: 0 : if (mhdr_res->actions_num) {
15602 : : /* create modify action if needed. */
15603 [ # # ]: 0 : if (flow_dv_modify_hdr_resource_register
15604 : : (dev, mhdr_res, dev_flow, error))
15605 : 0 : return -rte_errno;
15606 : 0 : dev_flow->dv.actions[modify_action_position] =
15607 : 0 : handle->dvh.modify_hdr->action;
15608 : : }
15609 : : /*
15610 : : * Handle AGE and COUNT action by single HW counter
15611 : : * when they are not shared.
15612 : : */
15613 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_AGE) {
15614 [ # # # # ]: 0 : if ((non_shared_age && count) ||
15615 [ # # ]: 0 : !flow_hit_aso_supported(priv, !dev_flow->dv.group)) {
15616 : : /* Creates age by counters. */
15617 : 0 : cnt_act = flow_dv_prepare_counter
15618 : : (dev, dev_flow,
15619 : : flow, count,
15620 : : non_shared_age,
15621 : : error);
15622 [ # # ]: 0 : if (!cnt_act)
15623 : 0 : return -rte_errno;
15624 : 0 : dev_flow->dv.actions[age_act_pos] =
15625 : 0 : cnt_act->action;
15626 : 0 : break;
15627 : : }
15628 [ # # # # ]: 0 : if (!flow->age && non_shared_age) {
15629 : 0 : flow->age = flow_dv_aso_age_alloc
15630 : : (dev, error);
15631 [ # # ]: 0 : if (!flow->age)
15632 : 0 : return -rte_errno;
15633 : 0 : flow_dv_aso_age_params_init
15634 : : (dev, flow->age,
15635 : 0 : non_shared_age->context ?
15636 : : non_shared_age->context :
15637 : 0 : (void *)(uintptr_t)
15638 : 0 : (dev_flow->flow_idx),
15639 [ # # ]: 0 : non_shared_age->timeout);
15640 : : }
15641 : 0 : age_act = flow_aso_age_get_by_idx(dev,
15642 : : flow->age);
15643 : 0 : dev_flow->dv.actions[age_act_pos] =
15644 : 0 : age_act->dr_action;
15645 : : }
15646 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_COUNT) {
15647 : : /*
15648 : : * Create one count action, to be used
15649 : : * by all sub-flows.
15650 : : */
15651 : 0 : cnt_act = flow_dv_prepare_counter(dev, dev_flow,
15652 : : flow, count,
15653 : : NULL, error);
15654 [ # # ]: 0 : if (!cnt_act)
15655 : 0 : return -rte_errno;
15656 : 0 : dev_flow->dv.actions[actions_n++] =
15657 : 0 : cnt_act->action;
15658 : : }
15659 : : default:
15660 : : break;
15661 : : }
15662 [ # # # # ]: 0 : if (mhdr_res->actions_num &&
15663 : : modify_action_position == UINT32_MAX)
15664 : 0 : modify_action_position = actions_n++;
15665 : : }
15666 : 0 : dev_flow->act_flags = action_flags;
15667 : 0 : ret = flow_dv_translate_items_sws(dev, dev_flow, attr, items, &matcher,
15668 : : error);
15669 [ # # ]: 0 : if (ret)
15670 : 0 : return -rte_errno;
15671 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_RSS) {
15672 : 0 : dev_flow->symmetric_hash_function = rss_desc->symmetric_hash_function;
15673 : 0 : flow_dv_hashfields_set(dev_flow->handle->layers,
15674 : : rss_desc,
15675 : : &dev_flow->hash_fields);
15676 : : }
15677 : : /* If has RSS action in the sample action, the Sample/Mirror resource
15678 : : * should be registered after the hash filed be update.
15679 : : */
15680 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE) {
15681 : 0 : ret = flow_dv_translate_action_sample(dev,
15682 : : sample,
15683 : : dev_flow, attr,
15684 : : &num_of_dest,
15685 : : sample_actions,
15686 : : &sample_res,
15687 : : error);
15688 [ # # ]: 0 : if (ret < 0)
15689 : : return ret;
15690 : 0 : ret = flow_dv_create_action_sample(dev,
15691 : : dev_flow,
15692 : : num_of_dest,
15693 : : &sample_res,
15694 : : &mdest_res,
15695 : : sample_actions,
15696 : : action_flags,
15697 : : error);
15698 [ # # ]: 0 : if (ret < 0)
15699 : 0 : return rte_flow_error_set
15700 : : (error, rte_errno,
15701 : : RTE_FLOW_ERROR_TYPE_ACTION,
15702 : : NULL,
15703 : : "cannot create sample action");
15704 [ # # ]: 0 : if (num_of_dest > 1) {
15705 : 0 : dev_flow->dv.actions[sample_act_pos] =
15706 : 0 : dev_flow->dv.dest_array_res->action;
15707 : : } else {
15708 : 0 : dev_flow->dv.actions[sample_act_pos] =
15709 : 0 : dev_flow->dv.sample_res->verbs_action;
15710 : : }
15711 : : }
15712 : : /*
15713 : : * For multiple destination (sample action with ratio=1), the encap
15714 : : * action and port id action will be combined into group action.
15715 : : * So need remove the original these actions in the flow and only
15716 : : * use the sample action instead of.
15717 : : */
15718 [ # # ]: 0 : if (num_of_dest > 1 &&
15719 [ # # # # ]: 0 : (sample_act->dr_port_id_action || sample_act->dr_jump_action)) {
15720 : : int i;
15721 : 0 : void *temp_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
15722 : :
15723 [ # # ]: 0 : for (i = 0; i < actions_n; i++) {
15724 [ # # ]: 0 : if ((sample_act->dr_encap_action &&
15725 : : sample_act->dr_encap_action ==
15726 [ # # # # ]: 0 : dev_flow->dv.actions[i]) ||
15727 : 0 : (sample_act->dr_port_id_action &&
15728 : : sample_act->dr_port_id_action ==
15729 [ # # ]: 0 : dev_flow->dv.actions[i]) ||
15730 [ # # ]: 0 : (sample_act->dr_jump_action &&
15731 : : sample_act->dr_jump_action ==
15732 [ # # ]: 0 : dev_flow->dv.actions[i]))
15733 : 0 : continue;
15734 : 0 : temp_actions[tmp_actions_n++] = dev_flow->dv.actions[i];
15735 : : }
15736 : 0 : memcpy((void *)dev_flow->dv.actions,
15737 : : (void *)temp_actions,
15738 : : tmp_actions_n * sizeof(void *));
15739 : : actions_n = tmp_actions_n;
15740 : : }
15741 : 0 : dev_flow->dv.actions_n = actions_n;
15742 [ # # ]: 0 : if (wks->skip_matcher_reg)
15743 : : return 0;
15744 : : /* Register matcher. */
15745 : 0 : matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
15746 : : matcher.mask.size);
15747 : 0 : matcher.priority = mlx5_get_matcher_priority(dev, attr,
15748 : 0 : matcher.priority,
15749 : 0 : dev_flow->external);
15750 : : /**
15751 : : * When creating meter drop flow in drop table, using original
15752 : : * 5-tuple match, the matcher priority should be lower than
15753 : : * mtr_id matcher.
15754 : : */
15755 [ # # ]: 0 : if (attr->group == MLX5_FLOW_TABLE_LEVEL_METER &&
15756 [ # # # # ]: 0 : dev_flow->dv.table_id == MLX5_MTR_TABLE_ID_DROP &&
15757 : : matcher.priority <= MLX5_REG_BITS)
15758 : 0 : matcher.priority += MLX5_REG_BITS;
15759 : : /* reserved field no needs to be set to 0 here. */
15760 : 0 : tbl_key.is_fdb = attr->transfer;
15761 : 0 : tbl_key.is_egress = attr->egress;
15762 : 0 : tbl_key.level = dev_flow->dv.group;
15763 : 0 : tbl_key.id = dev_flow->dv.table_id;
15764 [ # # ]: 0 : if (flow_dv_matcher_register(dev, &matcher, &tbl_key, dev_flow,
15765 : : tunnel, attr->group, error))
15766 : 0 : return -rte_errno;
15767 : : return 0;
15768 : : }
15769 : :
15770 : : /**
15771 : : * Set hash RX queue by hash fields (see enum ibv_rx_hash_fields)
15772 : : * and tunnel.
15773 : : *
15774 : : * @param[in, out] action
15775 : : * Shred RSS action holding hash RX queue objects.
15776 : : * @param[in] hash_fields
15777 : : * Defines combination of packet fields to participate in RX hash.
15778 : : * @param[in] tunnel
15779 : : * Tunnel type
15780 : : * @param[in] hrxq_idx
15781 : : * Hash RX queue index to set.
15782 : : *
15783 : : * @return
15784 : : * 0 on success, otherwise negative errno value.
15785 : : */
15786 : : static int
15787 : 0 : __flow_dv_action_rss_hrxq_set(struct mlx5_shared_action_rss *action,
15788 : : const uint64_t hash_fields,
15789 : : uint32_t hrxq_idx)
15790 : : {
15791 : : uint32_t *hrxqs = action->hrxq;
15792 : :
15793 [ # # # # : 0 : switch (hash_fields & ~IBV_RX_HASH_INNER) {
# # # # #
# # ]
15794 : 0 : case MLX5_RSS_HASH_IPV4:
15795 : : /* fall-through. */
15796 : : case MLX5_RSS_HASH_IPV4_DST_ONLY:
15797 : : /* fall-through. */
15798 : : case MLX5_RSS_HASH_IPV4_SRC_ONLY:
15799 : 0 : hrxqs[0] = hrxq_idx;
15800 : 0 : return 0;
15801 : 0 : case MLX5_RSS_HASH_IPV4_TCP:
15802 : : /* fall-through. */
15803 : : case MLX5_RSS_HASH_IPV4_TCP_DST_ONLY:
15804 : : /* fall-through. */
15805 : : case MLX5_RSS_HASH_IPV4_TCP_SRC_ONLY:
15806 : 0 : hrxqs[1] = hrxq_idx;
15807 : 0 : return 0;
15808 : 0 : case MLX5_RSS_HASH_IPV4_UDP:
15809 : : /* fall-through. */
15810 : : case MLX5_RSS_HASH_IPV4_UDP_DST_ONLY:
15811 : : /* fall-through. */
15812 : : case MLX5_RSS_HASH_IPV4_UDP_SRC_ONLY:
15813 : 0 : hrxqs[2] = hrxq_idx;
15814 : 0 : return 0;
15815 : 0 : case MLX5_RSS_HASH_IPV6:
15816 : : /* fall-through. */
15817 : : case MLX5_RSS_HASH_IPV6_DST_ONLY:
15818 : : /* fall-through. */
15819 : : case MLX5_RSS_HASH_IPV6_SRC_ONLY:
15820 : 0 : hrxqs[3] = hrxq_idx;
15821 : 0 : return 0;
15822 : 0 : case MLX5_RSS_HASH_IPV6_TCP:
15823 : : /* fall-through. */
15824 : : case MLX5_RSS_HASH_IPV6_TCP_DST_ONLY:
15825 : : /* fall-through. */
15826 : : case MLX5_RSS_HASH_IPV6_TCP_SRC_ONLY:
15827 : 0 : hrxqs[4] = hrxq_idx;
15828 : 0 : return 0;
15829 : 0 : case MLX5_RSS_HASH_IPV6_UDP:
15830 : : /* fall-through. */
15831 : : case MLX5_RSS_HASH_IPV6_UDP_DST_ONLY:
15832 : : /* fall-through. */
15833 : : case MLX5_RSS_HASH_IPV6_UDP_SRC_ONLY:
15834 : 0 : hrxqs[5] = hrxq_idx;
15835 : 0 : return 0;
15836 : 0 : case MLX5_RSS_HASH_NONE:
15837 : 0 : hrxqs[6] = hrxq_idx;
15838 : 0 : return 0;
15839 : 0 : case MLX5_RSS_HASH_IPV4_ESP:
15840 : 0 : hrxqs[7] = hrxq_idx;
15841 : 0 : return 0;
15842 : 0 : case MLX5_RSS_HASH_IPV6_ESP:
15843 : 0 : hrxqs[8] = hrxq_idx;
15844 : 0 : return 0;
15845 : 0 : case MLX5_RSS_HASH_ESP_SPI:
15846 : 0 : hrxqs[9] = hrxq_idx;
15847 : 0 : return 0;
15848 : : default:
15849 : : return -1;
15850 : : }
15851 : : }
15852 : :
15853 : : /**
15854 : : * Look up for hash RX queue by hash fields (see enum ibv_rx_hash_fields)
15855 : : * and tunnel.
15856 : : *
15857 : : * @param[in] dev
15858 : : * Pointer to the Ethernet device structure.
15859 : : * @param[in] idx
15860 : : * Shared RSS action ID holding hash RX queue objects.
15861 : : * @param[in] hash_fields
15862 : : * Defines combination of packet fields to participate in RX hash.
15863 : : * @param[in] tunnel
15864 : : * Tunnel type
15865 : : *
15866 : : * @return
15867 : : * Valid hash RX queue index, otherwise 0.
15868 : : */
15869 : : uint32_t
15870 : 0 : flow_dv_action_rss_hrxq_lookup(struct rte_eth_dev *dev, uint32_t idx,
15871 : : const uint64_t hash_fields)
15872 : : {
15873 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15874 : : struct mlx5_shared_action_rss *shared_rss =
15875 : 0 : mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
15876 : : const uint32_t *hrxqs = shared_rss->hrxq;
15877 : :
15878 [ # # # # : 0 : switch (hash_fields & ~IBV_RX_HASH_INNER) {
# # # # #
# # ]
15879 : 0 : case MLX5_RSS_HASH_IPV4:
15880 : : /* fall-through. */
15881 : : case MLX5_RSS_HASH_IPV4_DST_ONLY:
15882 : : /* fall-through. */
15883 : : case MLX5_RSS_HASH_IPV4_SRC_ONLY:
15884 : 0 : return hrxqs[0];
15885 : 0 : case MLX5_RSS_HASH_IPV4_TCP:
15886 : : /* fall-through. */
15887 : : case MLX5_RSS_HASH_IPV4_TCP_DST_ONLY:
15888 : : /* fall-through. */
15889 : : case MLX5_RSS_HASH_IPV4_TCP_SRC_ONLY:
15890 : 0 : return hrxqs[1];
15891 : 0 : case MLX5_RSS_HASH_IPV4_UDP:
15892 : : /* fall-through. */
15893 : : case MLX5_RSS_HASH_IPV4_UDP_DST_ONLY:
15894 : : /* fall-through. */
15895 : : case MLX5_RSS_HASH_IPV4_UDP_SRC_ONLY:
15896 : 0 : return hrxqs[2];
15897 : 0 : case MLX5_RSS_HASH_IPV6:
15898 : : /* fall-through. */
15899 : : case MLX5_RSS_HASH_IPV6_DST_ONLY:
15900 : : /* fall-through. */
15901 : : case MLX5_RSS_HASH_IPV6_SRC_ONLY:
15902 : 0 : return hrxqs[3];
15903 : 0 : case MLX5_RSS_HASH_IPV6_TCP:
15904 : : /* fall-through. */
15905 : : case MLX5_RSS_HASH_IPV6_TCP_DST_ONLY:
15906 : : /* fall-through. */
15907 : : case MLX5_RSS_HASH_IPV6_TCP_SRC_ONLY:
15908 : 0 : return hrxqs[4];
15909 : 0 : case MLX5_RSS_HASH_IPV6_UDP:
15910 : : /* fall-through. */
15911 : : case MLX5_RSS_HASH_IPV6_UDP_DST_ONLY:
15912 : : /* fall-through. */
15913 : : case MLX5_RSS_HASH_IPV6_UDP_SRC_ONLY:
15914 : 0 : return hrxqs[5];
15915 : 0 : case MLX5_RSS_HASH_NONE:
15916 : 0 : return hrxqs[6];
15917 : 0 : case MLX5_RSS_HASH_IPV4_ESP:
15918 : 0 : return hrxqs[7];
15919 : 0 : case MLX5_RSS_HASH_IPV6_ESP:
15920 : 0 : return hrxqs[8];
15921 : 0 : case MLX5_RSS_HASH_ESP_SPI:
15922 : 0 : return hrxqs[9];
15923 : : default:
15924 : : return 0;
15925 : : }
15926 : :
15927 : : }
15928 : :
15929 : : /**
15930 : : * Apply the flow to the NIC, lock free,
15931 : : * (mutex should be acquired by caller).
15932 : : *
15933 : : * @param[in] dev
15934 : : * Pointer to the Ethernet device structure.
15935 : : * @param[in, out] flow
15936 : : * Pointer to flow structure.
15937 : : * @param[out] error
15938 : : * Pointer to error structure.
15939 : : *
15940 : : * @return
15941 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
15942 : : */
15943 : : static int
15944 : 0 : flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
15945 : : struct rte_flow_error *error)
15946 : : {
15947 : : struct mlx5_flow_dv_workspace *dv;
15948 : : struct mlx5_flow_handle *dh;
15949 : : struct mlx5_flow_handle_dv *dv_h;
15950 : : struct mlx5_flow *dev_flow;
15951 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15952 : : uint32_t handle_idx;
15953 : : int n;
15954 : : int err;
15955 : : int idx;
15956 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
15957 : 0 : struct mlx5_flow_rss_desc *rss_desc = &wks->rss_desc;
15958 : : uint8_t misc_mask;
15959 : :
15960 : : MLX5_ASSERT(wks);
15961 [ # # ]: 0 : for (idx = wks->flow_idx - 1; idx >= 0; idx--) {
15962 : 0 : dev_flow = &wks->flows[idx];
15963 : : dv = &dev_flow->dv;
15964 : 0 : dh = dev_flow->handle;
15965 : : dv_h = &dh->dvh;
15966 : 0 : n = dv->actions_n;
15967 [ # # ]: 0 : if (dh->fate_action == MLX5_FLOW_FATE_DROP) {
15968 [ # # ]: 0 : if (dv->transfer) {
15969 : : MLX5_ASSERT(priv->sh->dr_drop_action);
15970 : 0 : dv->actions[n++] = priv->sh->dr_drop_action;
15971 : : } else {
15972 : : #ifdef HAVE_MLX5DV_DR
15973 : : /* DR supports drop action placeholder. */
15974 : : MLX5_ASSERT(priv->sh->dr_drop_action);
15975 : 0 : dv->actions[n++] = dv->group ?
15976 [ # # ]: 0 : priv->sh->dr_drop_action :
15977 : : priv->root_drop_action;
15978 : : #else
15979 : : /* For DV we use the explicit drop queue. */
15980 : : MLX5_ASSERT(priv->drop_queue.hrxq);
15981 : : dv->actions[n++] =
15982 : : priv->drop_queue.hrxq->action;
15983 : : #endif
15984 : : }
15985 [ # # ]: 0 : } else if ((dh->fate_action == MLX5_FLOW_FATE_QUEUE &&
15986 [ # # # # ]: 0 : !dv_h->rix_sample && !dv_h->rix_dest_array)) {
15987 : : struct mlx5_hrxq *hrxq;
15988 : : uint32_t hrxq_idx;
15989 : :
15990 : 0 : hrxq = flow_dv_hrxq_prepare(dev, dev_flow, rss_desc,
15991 : : &hrxq_idx);
15992 [ # # ]: 0 : if (!hrxq) {
15993 : 0 : rte_flow_error_set
15994 : : (error, rte_errno,
15995 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
15996 : : "cannot get hash queue");
15997 : 0 : goto error;
15998 : : }
15999 : 0 : dh->rix_hrxq = hrxq_idx;
16000 : 0 : dv->actions[n++] = hrxq->action;
16001 [ # # ]: 0 : } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
16002 : : struct mlx5_hrxq *hrxq = NULL;
16003 : : uint32_t hrxq_idx;
16004 : :
16005 : 0 : hrxq_idx = flow_dv_action_rss_hrxq_lookup(dev,
16006 : : rss_desc->shared_rss,
16007 : : dev_flow->hash_fields);
16008 [ # # ]: 0 : if (hrxq_idx)
16009 : 0 : hrxq = mlx5_ipool_get
16010 : 0 : (priv->sh->ipool[MLX5_IPOOL_HRXQ],
16011 : : hrxq_idx);
16012 [ # # ]: 0 : if (!hrxq) {
16013 : 0 : rte_flow_error_set
16014 : : (error, rte_errno,
16015 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16016 : : "cannot get hash queue");
16017 : 0 : goto error;
16018 : : }
16019 : 0 : dh->rix_srss = rss_desc->shared_rss;
16020 : 0 : dv->actions[n++] = hrxq->action;
16021 [ # # ]: 0 : } else if (dh->fate_action == MLX5_FLOW_FATE_DEFAULT_MISS) {
16022 [ # # ]: 0 : if (!priv->sh->default_miss_action) {
16023 : 0 : rte_flow_error_set
16024 : : (error, rte_errno,
16025 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16026 : : "default miss action not be created.");
16027 : 0 : goto error;
16028 : : }
16029 : 0 : dv->actions[n++] = priv->sh->default_miss_action;
16030 : : }
16031 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(dv_h->matcher->mask.buf);
16032 : : __flow_dv_adjust_buf_size(&dv->value.size, misc_mask);
16033 : 0 : err = mlx5_flow_os_create_flow(dv_h->matcher->matcher_object,
16034 : 0 : (void *)&dv->value, n,
16035 : 0 : dv->actions, &dh->drv_flow);
16036 : : if (err) {
16037 : 0 : rte_flow_error_set
16038 : 0 : (error, errno,
16039 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
16040 : : NULL,
16041 [ # # ]: 0 : (!priv->sh->config.allow_duplicate_pattern &&
16042 [ # # ]: 0 : errno == EEXIST) ?
16043 : : "duplicating pattern is not allowed" :
16044 : : "hardware refuses to create flow");
16045 : 0 : goto error;
16046 : : }
16047 [ # # ]: 0 : if (priv->vmwa_context &&
16048 [ # # # # ]: 0 : dh->vf_vlan.tag && !dh->vf_vlan.created) {
16049 : : /*
16050 : : * The rule contains the VLAN pattern.
16051 : : * For VF we are going to create VLAN
16052 : : * interface to make hypervisor set correct
16053 : : * e-Switch vport context.
16054 : : */
16055 : 0 : mlx5_vlan_vmwa_acquire(dev, &dh->vf_vlan);
16056 : : }
16057 : : }
16058 : : return 0;
16059 : 0 : error:
16060 : 0 : err = rte_errno; /* Save rte_errno before cleanup. */
16061 [ # # # # : 0 : SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
# # ]
16062 : : handle_idx, dh, next) {
16063 : : /* hrxq is union, don't clear it if the flag is not set. */
16064 [ # # # # ]: 0 : if (dh->fate_action == MLX5_FLOW_FATE_QUEUE && dh->rix_hrxq &&
16065 [ # # # # ]: 0 : !dh->dvh.rix_sample && !dh->dvh.rix_dest_array) {
16066 : 0 : mlx5_hrxq_release(dev, dh->rix_hrxq);
16067 : 0 : dh->rix_hrxq = 0;
16068 [ # # ]: 0 : } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
16069 : 0 : dh->rix_srss = 0;
16070 : : }
16071 [ # # # # ]: 0 : if (dh->vf_vlan.tag && dh->vf_vlan.created)
16072 : 0 : mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
16073 : : }
16074 : 0 : rte_errno = err; /* Restore rte_errno. */
16075 : 0 : return -rte_errno;
16076 : : }
16077 : :
16078 : : void
16079 : 0 : flow_matcher_remove_cb(void *tool_ctx __rte_unused,
16080 : : struct mlx5_list_entry *entry)
16081 : : {
16082 : : struct mlx5_flow_dv_matcher *resource = container_of(entry,
16083 : : typeof(*resource),
16084 : : entry);
16085 : : #ifdef HAVE_MLX5_HWS_SUPPORT
16086 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
16087 : :
16088 [ # # ]: 0 : if (sh->config.dv_flow_en == 2)
16089 : 0 : claim_zero(mlx5dr_bwc_matcher_destroy((struct mlx5dr_bwc_matcher *)
16090 : : resource->matcher_object));
16091 : : else
16092 : : #endif
16093 : 0 : claim_zero(mlx5_flow_os_destroy_flow_matcher(resource->matcher_object));
16094 : 0 : mlx5_free(resource);
16095 : 0 : }
16096 : :
16097 : : /**
16098 : : * Release the flow matcher.
16099 : : *
16100 : : * @param dev
16101 : : * Pointer to Ethernet device.
16102 : : * @param port_id
16103 : : * Index to port ID action resource.
16104 : : *
16105 : : * @return
16106 : : * 1 while a reference on it exists, 0 when freed.
16107 : : */
16108 : : static int
16109 : 0 : flow_dv_matcher_release(struct rte_eth_dev *dev,
16110 : : struct mlx5_flow_handle *handle)
16111 : : {
16112 : 0 : struct mlx5_flow_dv_matcher *matcher = handle->dvh.matcher;
16113 : 0 : struct mlx5_flow_tbl_data_entry *tbl = container_of(matcher->tbl,
16114 : : typeof(*tbl), tbl);
16115 : : int ret;
16116 : :
16117 : : MLX5_ASSERT(matcher->matcher_object);
16118 : 0 : ret = mlx5_list_unregister(tbl->matchers, &matcher->entry);
16119 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl->tbl);
16120 : 0 : return ret;
16121 : : }
16122 : :
16123 : : void
16124 : 0 : flow_encap_decap_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
16125 : : {
16126 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
16127 : : struct mlx5_flow_dv_encap_decap_resource *res =
16128 : : container_of(entry, typeof(*res), entry);
16129 : :
16130 : : #ifdef HAVE_MLX5_HWS_SUPPORT
16131 [ # # ]: 0 : if (sh->config.dv_flow_en == 2)
16132 : 0 : claim_zero(mlx5dr_action_destroy(res->action));
16133 : : else
16134 : : #endif
16135 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
16136 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], res->idx);
16137 : 0 : }
16138 : :
16139 : : /**
16140 : : * Release an encap/decap resource.
16141 : : *
16142 : : * @param dev
16143 : : * Pointer to Ethernet device.
16144 : : * @param encap_decap_idx
16145 : : * Index of encap decap resource.
16146 : : *
16147 : : * @return
16148 : : * 1 while a reference on it exists, 0 when freed.
16149 : : */
16150 : : int
16151 : 0 : flow_encap_decap_resource_release(struct rte_eth_dev *dev,
16152 : : uint32_t encap_decap_idx)
16153 : : {
16154 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16155 : : struct mlx5_flow_dv_encap_decap_resource *resource;
16156 : :
16157 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
16158 : : encap_decap_idx);
16159 [ # # ]: 0 : if (!resource)
16160 : : return 0;
16161 : : MLX5_ASSERT(resource->action);
16162 : 0 : return mlx5_hlist_unregister(priv->sh->encaps_decaps, &resource->entry);
16163 : : }
16164 : :
16165 : : /**
16166 : : * Release an jump to table action resource.
16167 : : *
16168 : : * @param dev
16169 : : * Pointer to Ethernet device.
16170 : : * @param rix_jump
16171 : : * Index to the jump action resource.
16172 : : *
16173 : : * @return
16174 : : * 1 while a reference on it exists, 0 when freed.
16175 : : */
16176 : : static int
16177 : 0 : flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev,
16178 : : uint32_t rix_jump)
16179 : : {
16180 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16181 : : struct mlx5_flow_tbl_data_entry *tbl_data;
16182 : :
16183 : 0 : tbl_data = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_JUMP],
16184 : : rix_jump);
16185 [ # # ]: 0 : if (!tbl_data)
16186 : : return 0;
16187 : 0 : return flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl_data->tbl);
16188 : : }
16189 : :
16190 : : void
16191 : 0 : flow_modify_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
16192 : : {
16193 : : struct mlx5_flow_dv_modify_hdr_resource *res =
16194 : : container_of(entry, typeof(*res), entry);
16195 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
16196 : :
16197 : : #ifdef HAVE_MLX5_HWS_SUPPORT
16198 [ # # ]: 0 : if (sh->config.dv_flow_en == 2)
16199 : 0 : claim_zero(mlx5dr_action_destroy(res->action));
16200 : : else
16201 : : #endif
16202 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
16203 : 0 : mlx5_ipool_free(sh->mdh_ipools[res->actions_num - 1], res->idx);
16204 : 0 : }
16205 : :
16206 : : /**
16207 : : * Release a modify-header resource.
16208 : : *
16209 : : * @param dev
16210 : : * Pointer to Ethernet device.
16211 : : * @param handle
16212 : : * Pointer to mlx5_flow_handle.
16213 : : *
16214 : : * @return
16215 : : * 1 while a reference on it exists, 0 when freed.
16216 : : */
16217 : : static int
16218 : : flow_dv_modify_hdr_resource_release(struct rte_eth_dev *dev,
16219 : : struct mlx5_flow_handle *handle)
16220 : : {
16221 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16222 : : struct mlx5_flow_dv_modify_hdr_resource *entry = handle->dvh.modify_hdr;
16223 : :
16224 : : MLX5_ASSERT(entry->action);
16225 : 0 : return mlx5_hlist_unregister(priv->sh->modify_cmds, &entry->entry);
16226 : : }
16227 : :
16228 : : void
16229 : 0 : flow_dv_port_id_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
16230 : : {
16231 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
16232 : : struct mlx5_flow_dv_port_id_action_resource *resource =
16233 : : container_of(entry, typeof(*resource), entry);
16234 : :
16235 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
16236 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], resource->idx);
16237 : 0 : }
16238 : :
16239 : : /**
16240 : : * Release port ID action resource.
16241 : : *
16242 : : * @param dev
16243 : : * Pointer to Ethernet device.
16244 : : * @param handle
16245 : : * Pointer to mlx5_flow_handle.
16246 : : *
16247 : : * @return
16248 : : * 1 while a reference on it exists, 0 when freed.
16249 : : */
16250 : : static int
16251 : 0 : flow_dv_port_id_action_resource_release(struct rte_eth_dev *dev,
16252 : : uint32_t port_id)
16253 : : {
16254 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16255 : : struct mlx5_flow_dv_port_id_action_resource *resource;
16256 : :
16257 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PORT_ID], port_id);
16258 [ # # ]: 0 : if (!resource)
16259 : : return 0;
16260 : : MLX5_ASSERT(resource->action);
16261 : 0 : return mlx5_list_unregister(priv->sh->port_id_action_list,
16262 : : &resource->entry);
16263 : : }
16264 : :
16265 : : /**
16266 : : * Release shared RSS action resource.
16267 : : *
16268 : : * @param dev
16269 : : * Pointer to Ethernet device.
16270 : : * @param srss
16271 : : * Shared RSS action index.
16272 : : */
16273 : : static void
16274 : 0 : flow_dv_shared_rss_action_release(struct rte_eth_dev *dev, uint32_t srss)
16275 : : {
16276 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16277 : : struct mlx5_shared_action_rss *shared_rss;
16278 : :
16279 : 0 : shared_rss = mlx5_ipool_get
16280 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], srss);
16281 : 0 : rte_atomic_fetch_sub_explicit(&shared_rss->refcnt, 1, rte_memory_order_relaxed);
16282 : 0 : }
16283 : :
16284 : : void
16285 : 0 : flow_dv_push_vlan_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
16286 : : {
16287 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
16288 : : struct mlx5_flow_dv_push_vlan_action_resource *resource =
16289 : : container_of(entry, typeof(*resource), entry);
16290 : :
16291 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
16292 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], resource->idx);
16293 : 0 : }
16294 : :
16295 : : /**
16296 : : * Release push vlan action resource.
16297 : : *
16298 : : * @param dev
16299 : : * Pointer to Ethernet device.
16300 : : * @param handle
16301 : : * Pointer to mlx5_flow_handle.
16302 : : *
16303 : : * @return
16304 : : * 1 while a reference on it exists, 0 when freed.
16305 : : */
16306 : : static int
16307 : 0 : flow_dv_push_vlan_action_resource_release(struct rte_eth_dev *dev,
16308 : : struct mlx5_flow_handle *handle)
16309 : : {
16310 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16311 : : struct mlx5_flow_dv_push_vlan_action_resource *resource;
16312 : 0 : uint32_t idx = handle->dvh.rix_push_vlan;
16313 : :
16314 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
16315 [ # # ]: 0 : if (!resource)
16316 : : return 0;
16317 : : MLX5_ASSERT(resource->action);
16318 : 0 : return mlx5_list_unregister(priv->sh->push_vlan_action_list,
16319 : : &resource->entry);
16320 : : }
16321 : :
16322 : : /**
16323 : : * Release the fate resource.
16324 : : *
16325 : : * @param dev
16326 : : * Pointer to Ethernet device.
16327 : : * @param handle
16328 : : * Pointer to mlx5_flow_handle.
16329 : : */
16330 : : static void
16331 : 0 : flow_dv_fate_resource_release(struct rte_eth_dev *dev,
16332 : : struct mlx5_flow_handle *handle)
16333 : : {
16334 [ # # ]: 0 : if (!handle->rix_fate)
16335 : : return;
16336 [ # # # # : 0 : switch (handle->fate_action) {
# ]
16337 : 0 : case MLX5_FLOW_FATE_QUEUE:
16338 [ # # # # ]: 0 : if (!handle->dvh.rix_sample && !handle->dvh.rix_dest_array)
16339 : 0 : mlx5_hrxq_release(dev, handle->rix_hrxq);
16340 : : break;
16341 : 0 : case MLX5_FLOW_FATE_JUMP:
16342 : 0 : flow_dv_jump_tbl_resource_release(dev, handle->rix_jump);
16343 : 0 : break;
16344 : 0 : case MLX5_FLOW_FATE_PORT_ID:
16345 : 0 : flow_dv_port_id_action_resource_release(dev,
16346 : : handle->rix_port_id_action);
16347 : 0 : break;
16348 : : case MLX5_FLOW_FATE_SEND_TO_KERNEL:
16349 : : /* In case of send_to_kernel action the actual release of
16350 : : * resource is done when all shared DR resources are released
16351 : : * since this resource is created once and always reused.
16352 : : */
16353 : : break;
16354 : 0 : default:
16355 : 0 : DRV_LOG(DEBUG, "Incorrect fate action:%d", handle->fate_action);
16356 : 0 : break;
16357 : : }
16358 : 0 : handle->rix_fate = 0;
16359 : : }
16360 : :
16361 : : void
16362 : 0 : flow_dv_sample_remove_cb(void *tool_ctx __rte_unused,
16363 : : struct mlx5_list_entry *entry)
16364 : : {
16365 : : struct mlx5_flow_dv_sample_resource *resource = container_of(entry,
16366 : : typeof(*resource),
16367 : : entry);
16368 : 0 : struct rte_eth_dev *dev = resource->dev;
16369 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16370 : :
16371 [ # # ]: 0 : if (resource->verbs_action)
16372 : : claim_zero(mlx5_flow_os_destroy_flow_action
16373 : : (resource->verbs_action));
16374 [ # # ]: 0 : if (resource->normal_path_tbl)
16375 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev),
16376 : : resource->normal_path_tbl);
16377 : 0 : flow_dv_sample_sub_actions_release(dev, &resource->sample_idx);
16378 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_SAMPLE], resource->idx);
16379 : 0 : DRV_LOG(DEBUG, "sample resource %p: removed", (void *)resource);
16380 : 0 : }
16381 : :
16382 : : /**
16383 : : * Release an sample resource.
16384 : : *
16385 : : * @param dev
16386 : : * Pointer to Ethernet device.
16387 : : * @param handle
16388 : : * Pointer to mlx5_flow_handle.
16389 : : *
16390 : : * @return
16391 : : * 1 while a reference on it exists, 0 when freed.
16392 : : */
16393 : : static int
16394 : 0 : flow_dv_sample_resource_release(struct rte_eth_dev *dev,
16395 : : struct mlx5_flow_handle *handle)
16396 : : {
16397 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16398 : : struct mlx5_flow_dv_sample_resource *resource;
16399 : :
16400 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_SAMPLE],
16401 : : handle->dvh.rix_sample);
16402 [ # # ]: 0 : if (!resource)
16403 : : return 0;
16404 : : MLX5_ASSERT(resource->verbs_action);
16405 : 0 : return mlx5_list_unregister(priv->sh->sample_action_list,
16406 : : &resource->entry);
16407 : : }
16408 : :
16409 : : void
16410 : 0 : flow_dv_dest_array_remove_cb(void *tool_ctx __rte_unused,
16411 : : struct mlx5_list_entry *entry)
16412 : : {
16413 : : struct mlx5_flow_dv_dest_array_resource *resource =
16414 : : container_of(entry, typeof(*resource), entry);
16415 : 0 : struct rte_eth_dev *dev = resource->dev;
16416 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16417 : : uint32_t i = 0;
16418 : :
16419 : : MLX5_ASSERT(resource->action);
16420 [ # # ]: 0 : if (resource->action)
16421 : : claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
16422 [ # # ]: 0 : for (; i < resource->num_of_dest; i++)
16423 : 0 : flow_dv_sample_sub_actions_release(dev,
16424 : : &resource->sample_idx[i]);
16425 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY], resource->idx);
16426 : 0 : DRV_LOG(DEBUG, "destination array resource %p: removed",
16427 : : (void *)resource);
16428 : 0 : }
16429 : :
16430 : : /**
16431 : : * Release an destination array resource.
16432 : : *
16433 : : * @param dev
16434 : : * Pointer to Ethernet device.
16435 : : * @param handle
16436 : : * Pointer to mlx5_flow_handle.
16437 : : *
16438 : : * @return
16439 : : * 1 while a reference on it exists, 0 when freed.
16440 : : */
16441 : : static int
16442 : 0 : flow_dv_dest_array_resource_release(struct rte_eth_dev *dev,
16443 : : struct mlx5_flow_handle *handle)
16444 : : {
16445 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16446 : : struct mlx5_flow_dv_dest_array_resource *resource;
16447 : :
16448 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY],
16449 : : handle->dvh.rix_dest_array);
16450 [ # # ]: 0 : if (!resource)
16451 : : return 0;
16452 : : MLX5_ASSERT(resource->action);
16453 : 0 : return mlx5_list_unregister(priv->sh->dest_array_list,
16454 : : &resource->entry);
16455 : : }
16456 : :
16457 : : static void
16458 : 0 : flow_dev_geneve_tlv_option_resource_release(struct mlx5_dev_ctx_shared *sh)
16459 : : {
16460 : 0 : struct mlx5_geneve_tlv_option_resource *geneve_opt_resource =
16461 : : sh->geneve_tlv_option_resource;
16462 : 0 : rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
16463 [ # # ]: 0 : if (geneve_opt_resource) {
16464 [ # # ]: 0 : if (!(rte_atomic_fetch_sub_explicit(&geneve_opt_resource->refcnt, 1,
16465 : : rte_memory_order_relaxed) - 1)) {
16466 : 0 : claim_zero(mlx5_devx_cmd_destroy
16467 : : (geneve_opt_resource->obj));
16468 : 0 : mlx5_free(sh->geneve_tlv_option_resource);
16469 : 0 : sh->geneve_tlv_option_resource = NULL;
16470 : : }
16471 : : }
16472 : : rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
16473 : 0 : }
16474 : :
16475 : : /**
16476 : : * Remove the flow from the NIC but keeps it in memory.
16477 : : * Lock free, (mutex should be acquired by caller).
16478 : : *
16479 : : * @param[in] dev
16480 : : * Pointer to Ethernet device.
16481 : : * @param[in, out] flow
16482 : : * Pointer to flow structure.
16483 : : */
16484 : : static void
16485 : 0 : flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
16486 : : {
16487 : : struct mlx5_flow_handle *dh;
16488 : : uint32_t handle_idx;
16489 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16490 : :
16491 [ # # ]: 0 : if (!flow)
16492 : : return;
16493 : 0 : handle_idx = flow->dev_handles;
16494 [ # # ]: 0 : while (handle_idx) {
16495 : 0 : dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
16496 : : handle_idx);
16497 [ # # ]: 0 : if (!dh)
16498 : : return;
16499 [ # # ]: 0 : if (dh->drv_flow) {
16500 : : claim_zero(mlx5_flow_os_destroy_flow(dh->drv_flow));
16501 : 0 : dh->drv_flow = NULL;
16502 : : }
16503 [ # # ]: 0 : if (dh->fate_action == MLX5_FLOW_FATE_QUEUE)
16504 : 0 : flow_dv_fate_resource_release(dev, dh);
16505 [ # # # # ]: 0 : if (dh->vf_vlan.tag && dh->vf_vlan.created)
16506 : 0 : mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
16507 : 0 : handle_idx = dh->next.next;
16508 : : }
16509 : : }
16510 : :
16511 : : /**
16512 : : * Remove the flow from the NIC and the memory.
16513 : : * Lock free, (mutex should be acquired by caller).
16514 : : *
16515 : : * @param[in] dev
16516 : : * Pointer to the Ethernet device structure.
16517 : : * @param[in, out] flow
16518 : : * Pointer to flow structure.
16519 : : */
16520 : : static void
16521 : 0 : flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
16522 : : {
16523 : : struct mlx5_flow_handle *dev_handle;
16524 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16525 : : struct mlx5_flow_meter_info *fm = NULL;
16526 : : uint32_t srss = 0;
16527 : :
16528 [ # # ]: 0 : if (!flow)
16529 : : return;
16530 : 0 : flow_dv_remove(dev, flow);
16531 [ # # ]: 0 : if (flow->counter) {
16532 : 0 : flow_dv_counter_free(dev, flow->counter);
16533 : 0 : flow->counter = 0;
16534 : : }
16535 [ # # ]: 0 : if (flow->meter) {
16536 : 0 : fm = flow_dv_meter_find_by_idx(priv, flow->meter);
16537 [ # # ]: 0 : if (fm)
16538 : 0 : mlx5_flow_meter_detach(priv, fm);
16539 : 0 : flow->meter = 0;
16540 : : }
16541 : : /* Keep the current age handling by default. */
16542 [ # # # # ]: 0 : if (flow->indirect_type == MLX5_INDIRECT_ACTION_TYPE_CT && flow->ct)
16543 : 0 : flow_dv_aso_ct_release(dev, flow->ct, NULL);
16544 [ # # ]: 0 : else if (flow->age)
16545 : 0 : flow_dv_aso_age_release(dev, flow->age);
16546 [ # # ]: 0 : while (flow->geneve_tlv_option) {
16547 : 0 : flow_dev_geneve_tlv_option_resource_release(priv->sh);
16548 : 0 : flow->geneve_tlv_option--;
16549 : : }
16550 [ # # ]: 0 : while (flow->dev_handles) {
16551 : : uint32_t tmp_idx = flow->dev_handles;
16552 : :
16553 : 0 : dev_handle = mlx5_ipool_get(priv->sh->ipool
16554 : : [MLX5_IPOOL_MLX5_FLOW], tmp_idx);
16555 [ # # ]: 0 : if (!dev_handle)
16556 : : return;
16557 : 0 : flow->dev_handles = dev_handle->next.next;
16558 [ # # ]: 0 : while (dev_handle->flex_item) {
16559 : 0 : int index = rte_bsf32(dev_handle->flex_item);
16560 : :
16561 : 0 : mlx5_flex_release_index(dev, index);
16562 : 0 : dev_handle->flex_item &= ~(uint8_t)RTE_BIT32(index);
16563 : : }
16564 [ # # ]: 0 : if (dev_handle->dvh.matcher)
16565 : 0 : flow_dv_matcher_release(dev, dev_handle);
16566 [ # # ]: 0 : if (dev_handle->dvh.rix_sample)
16567 : 0 : flow_dv_sample_resource_release(dev, dev_handle);
16568 [ # # ]: 0 : if (dev_handle->dvh.rix_dest_array)
16569 : 0 : flow_dv_dest_array_resource_release(dev, dev_handle);
16570 [ # # ]: 0 : if (dev_handle->dvh.rix_encap_decap)
16571 : 0 : flow_encap_decap_resource_release(dev,
16572 : : dev_handle->dvh.rix_encap_decap);
16573 [ # # ]: 0 : if (dev_handle->dvh.modify_hdr)
16574 : : flow_dv_modify_hdr_resource_release(dev, dev_handle);
16575 [ # # ]: 0 : if (dev_handle->dvh.rix_push_vlan)
16576 : 0 : flow_dv_push_vlan_action_resource_release(dev,
16577 : : dev_handle);
16578 [ # # ]: 0 : if (dev_handle->dvh.rix_tag)
16579 : 0 : flow_dv_tag_release(dev,
16580 : : dev_handle->dvh.rix_tag);
16581 [ # # ]: 0 : if (dev_handle->fate_action != MLX5_FLOW_FATE_SHARED_RSS)
16582 : 0 : flow_dv_fate_resource_release(dev, dev_handle);
16583 [ # # ]: 0 : else if (!srss)
16584 : 0 : srss = dev_handle->rix_srss;
16585 [ # # # # ]: 0 : if (fm && dev_handle->is_meter_flow_id &&
16586 [ # # ]: 0 : dev_handle->split_flow_id)
16587 : 0 : mlx5_ipool_free(fm->flow_ipool,
16588 : : dev_handle->split_flow_id);
16589 [ # # ]: 0 : else if (dev_handle->split_flow_id &&
16590 [ # # ]: 0 : !dev_handle->is_meter_flow_id)
16591 : 0 : mlx5_ipool_free(priv->sh->ipool
16592 : : [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
16593 : : dev_handle->split_flow_id);
16594 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
16595 : : tmp_idx);
16596 : : }
16597 [ # # ]: 0 : if (srss)
16598 : 0 : flow_dv_shared_rss_action_release(dev, srss);
16599 : : }
16600 : :
16601 : : /**
16602 : : * Release array of hash RX queue objects.
16603 : : * Helper function.
16604 : : *
16605 : : * @param[in] dev
16606 : : * Pointer to the Ethernet device structure.
16607 : : * @param[in, out] hrxqs
16608 : : * Array of hash RX queue objects.
16609 : : *
16610 : : * @return
16611 : : * Total number of references to hash RX queue objects in *hrxqs* array
16612 : : * after this operation.
16613 : : */
16614 : : static int
16615 : 0 : __flow_dv_hrxqs_release(struct rte_eth_dev *dev,
16616 : : uint32_t (*hrxqs)[MLX5_RSS_HASH_FIELDS_LEN])
16617 : : {
16618 : : size_t i;
16619 : : int remaining = 0;
16620 : :
16621 [ # # ]: 0 : for (i = 0; i < RTE_DIM(*hrxqs); i++) {
16622 : 0 : int ret = mlx5_hrxq_release(dev, (*hrxqs)[i]);
16623 : :
16624 [ # # ]: 0 : if (!ret)
16625 : 0 : (*hrxqs)[i] = 0;
16626 : 0 : remaining += ret;
16627 : : }
16628 : 0 : return remaining;
16629 : : }
16630 : :
16631 : : /**
16632 : : * Release all hash RX queue objects representing shared RSS action.
16633 : : *
16634 : : * @param[in] dev
16635 : : * Pointer to the Ethernet device structure.
16636 : : * @param[in, out] action
16637 : : * Shared RSS action to remove hash RX queue objects from.
16638 : : *
16639 : : * @return
16640 : : * Total number of references to hash RX queue objects stored in *action*
16641 : : * after this operation.
16642 : : * Expected to be 0 if no external references held.
16643 : : */
16644 : : static int
16645 : : __flow_dv_action_rss_hrxqs_release(struct rte_eth_dev *dev,
16646 : : struct mlx5_shared_action_rss *shared_rss)
16647 : : {
16648 : 0 : return __flow_dv_hrxqs_release(dev, &shared_rss->hrxq);
16649 : : }
16650 : :
16651 : : /**
16652 : : * Adjust L3/L4 hash value of pre-created shared RSS hrxq according to
16653 : : * user input.
16654 : : *
16655 : : * Only one hash value is available for one L3+L4 combination:
16656 : : * for example:
16657 : : * MLX5_RSS_HASH_IPV4, MLX5_RSS_HASH_IPV4_SRC_ONLY, and
16658 : : * MLX5_RSS_HASH_IPV4_DST_ONLY are mutually exclusive so they can share
16659 : : * same slot in mlx5_rss_hash_fields.
16660 : : *
16661 : : * @param[in] orig_rss_types
16662 : : * RSS type as provided in shared RSS action.
16663 : : * @param[in, out] hash_field
16664 : : * hash_field variable needed to be adjusted.
16665 : : *
16666 : : * @return
16667 : : * void
16668 : : */
16669 : : void
16670 [ # # ]: 0 : flow_dv_action_rss_l34_hash_adjust(uint64_t orig_rss_types,
16671 : : uint64_t *hash_field)
16672 : : {
16673 : : uint64_t rss_types = rte_eth_rss_hf_refine(orig_rss_types);
16674 : :
16675 [ # # # # : 0 : switch (*hash_field & ~IBV_RX_HASH_INNER) {
# ]
16676 : 0 : case MLX5_RSS_HASH_IPV4:
16677 [ # # ]: 0 : if (rss_types & MLX5_IPV4_LAYER_TYPES) {
16678 : 0 : *hash_field &= ~MLX5_RSS_HASH_IPV4;
16679 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
16680 : 0 : *hash_field |= IBV_RX_HASH_DST_IPV4;
16681 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
16682 : 0 : *hash_field |= IBV_RX_HASH_SRC_IPV4;
16683 : : else
16684 : 0 : *hash_field |= MLX5_RSS_HASH_IPV4;
16685 : : }
16686 : : return;
16687 : 0 : case MLX5_RSS_HASH_IPV6:
16688 [ # # ]: 0 : if (rss_types & MLX5_IPV6_LAYER_TYPES) {
16689 : 0 : *hash_field &= ~MLX5_RSS_HASH_IPV6;
16690 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
16691 : 0 : *hash_field |= IBV_RX_HASH_DST_IPV6;
16692 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
16693 : 0 : *hash_field |= IBV_RX_HASH_SRC_IPV6;
16694 : : else
16695 : 0 : *hash_field |= MLX5_RSS_HASH_IPV6;
16696 : : }
16697 : : return;
16698 : 0 : case MLX5_RSS_HASH_IPV4_UDP:
16699 : : /* fall-through. */
16700 : : case MLX5_RSS_HASH_IPV6_UDP:
16701 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_UDP) {
16702 : 0 : *hash_field &= ~MLX5_UDP_IBV_RX_HASH;
16703 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
16704 : 0 : *hash_field |= IBV_RX_HASH_DST_PORT_UDP;
16705 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
16706 : 0 : *hash_field |= IBV_RX_HASH_SRC_PORT_UDP;
16707 : : else
16708 : 0 : *hash_field |= MLX5_UDP_IBV_RX_HASH;
16709 : : }
16710 : : return;
16711 : 0 : case MLX5_RSS_HASH_IPV4_TCP:
16712 : : /* fall-through. */
16713 : : case MLX5_RSS_HASH_IPV6_TCP:
16714 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_TCP) {
16715 : 0 : *hash_field &= ~MLX5_TCP_IBV_RX_HASH;
16716 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
16717 : 0 : *hash_field |= IBV_RX_HASH_DST_PORT_TCP;
16718 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
16719 : 0 : *hash_field |= IBV_RX_HASH_SRC_PORT_TCP;
16720 : : else
16721 : 0 : *hash_field |= MLX5_TCP_IBV_RX_HASH;
16722 : : }
16723 : : return;
16724 : : default:
16725 : : return;
16726 : : }
16727 : : }
16728 : :
16729 : : /**
16730 : : * Setup shared RSS action.
16731 : : * Prepare set of hash RX queue objects sufficient to handle all valid
16732 : : * hash_fields combinations (see enum ibv_rx_hash_fields).
16733 : : *
16734 : : * @param[in] dev
16735 : : * Pointer to the Ethernet device structure.
16736 : : * @param[in] action_idx
16737 : : * Shared RSS action ipool index.
16738 : : * @param[in, out] action
16739 : : * Partially initialized shared RSS action.
16740 : : * @param[out] error
16741 : : * Perform verbose error reporting if not NULL. Initialized in case of
16742 : : * error only.
16743 : : *
16744 : : * @return
16745 : : * 0 on success, otherwise negative errno value.
16746 : : */
16747 : : static int
16748 : 0 : __flow_dv_action_rss_setup(struct rte_eth_dev *dev,
16749 : : uint32_t action_idx,
16750 : : struct mlx5_shared_action_rss *shared_rss,
16751 : : struct rte_flow_error *error)
16752 : : {
16753 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16754 : 0 : struct mlx5_flow_rss_desc rss_desc = { 0 };
16755 : : size_t i;
16756 : : int err;
16757 : :
16758 : 0 : shared_rss->ind_tbl = mlx5_ind_table_obj_new
16759 : : (dev, shared_rss->origin.queue,
16760 : : shared_rss->origin.queue_num,
16761 : : true,
16762 : 0 : !!dev->data->dev_started);
16763 [ # # ]: 0 : if (!shared_rss->ind_tbl)
16764 : 0 : return rte_flow_error_set(error, rte_errno,
16765 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16766 : : "cannot setup indirection table");
16767 : 0 : memcpy(rss_desc.key, shared_rss->origin.key, MLX5_RSS_HASH_KEY_LEN);
16768 : 0 : rss_desc.key_len = MLX5_RSS_HASH_KEY_LEN;
16769 : 0 : rss_desc.symmetric_hash_function =
16770 : 0 : MLX5_RSS_IS_SYMM(shared_rss->origin.func);
16771 : 0 : rss_desc.const_q = shared_rss->origin.queue;
16772 : 0 : rss_desc.queue_num = shared_rss->origin.queue_num;
16773 : : /* Set non-zero value to indicate a shared RSS. */
16774 : 0 : rss_desc.shared_rss = action_idx;
16775 : 0 : rss_desc.ind_tbl = shared_rss->ind_tbl;
16776 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
16777 : 0 : rss_desc.hws_flags = MLX5DR_ACTION_FLAG_HWS_RX;
16778 [ # # ]: 0 : for (i = 0; i < MLX5_RSS_HASH_FIELDS_LEN; i++) {
16779 : : struct mlx5_hrxq *hrxq;
16780 : 0 : uint64_t hash_fields = mlx5_rss_hash_fields[i];
16781 : : int tunnel = 0;
16782 : :
16783 : 0 : flow_dv_action_rss_l34_hash_adjust(shared_rss->origin.types,
16784 : : &hash_fields);
16785 [ # # ]: 0 : if (shared_rss->origin.level > 1) {
16786 : 0 : hash_fields |= IBV_RX_HASH_INNER;
16787 : : tunnel = 1;
16788 : : }
16789 : 0 : rss_desc.tunnel = tunnel;
16790 : 0 : rss_desc.hash_fields = hash_fields;
16791 : 0 : hrxq = mlx5_hrxq_get(dev, &rss_desc);
16792 [ # # ]: 0 : if (!hrxq) {
16793 : 0 : rte_flow_error_set
16794 : : (error, rte_errno,
16795 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16796 : : "cannot get hash queue");
16797 : 0 : goto error_hrxq_new;
16798 : : }
16799 : 0 : err = __flow_dv_action_rss_hrxq_set
16800 : : (shared_rss, hash_fields, hrxq->idx);
16801 : : MLX5_ASSERT(!err);
16802 : : }
16803 : : return 0;
16804 : : error_hrxq_new:
16805 : 0 : err = rte_errno;
16806 : : __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
16807 [ # # ]: 0 : if (!mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl, true))
16808 : 0 : shared_rss->ind_tbl = NULL;
16809 : 0 : rte_errno = err;
16810 : 0 : return -rte_errno;
16811 : : }
16812 : :
16813 : : /**
16814 : : * Create shared RSS action.
16815 : : *
16816 : : * @param[in] dev
16817 : : * Pointer to the Ethernet device structure.
16818 : : * @param[in] conf
16819 : : * Shared action configuration.
16820 : : * @param[in] rss
16821 : : * RSS action specification used to create shared action.
16822 : : * @param[out] error
16823 : : * Perform verbose error reporting if not NULL. Initialized in case of
16824 : : * error only.
16825 : : *
16826 : : * @return
16827 : : * A valid shared action ID in case of success, 0 otherwise and
16828 : : * rte_errno is set.
16829 : : */
16830 : : static uint32_t
16831 : 0 : __flow_dv_action_rss_create(struct rte_eth_dev *dev,
16832 : : const struct rte_flow_indir_action_conf *conf,
16833 : : const struct rte_flow_action_rss *rss,
16834 : : struct rte_flow_error *error)
16835 : : {
16836 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16837 : : struct mlx5_shared_action_rss *shared_rss = NULL;
16838 : : struct rte_flow_action_rss *origin;
16839 : : const uint8_t *rss_key;
16840 : : uint32_t idx;
16841 : :
16842 : : RTE_SET_USED(conf);
16843 : 0 : shared_rss = mlx5_ipool_zmalloc
16844 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], &idx);
16845 [ # # ]: 0 : if (!shared_rss) {
16846 : 0 : rte_flow_error_set(error, ENOMEM,
16847 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16848 : : "cannot allocate resource memory");
16849 : 0 : goto error_rss_init;
16850 : : }
16851 [ # # ]: 0 : if (idx > (1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET)) {
16852 : 0 : rte_flow_error_set(error, E2BIG,
16853 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16854 : : "rss action number out of range");
16855 : 0 : goto error_rss_init;
16856 : : }
16857 : : origin = &shared_rss->origin;
16858 : 0 : origin->func = rss->func;
16859 : 0 : origin->level = rss->level;
16860 : : /* RSS type 0 indicates default RSS type (RTE_ETH_RSS_IP). */
16861 [ # # ]: 0 : origin->types = !rss->types ? RTE_ETH_RSS_IP : rss->types;
16862 : : /* NULL RSS key indicates default RSS key. */
16863 [ # # ]: 0 : rss_key = !rss->key ? rss_hash_default_key : rss->key;
16864 : 0 : memcpy(shared_rss->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
16865 : 0 : origin->key = &shared_rss->key[0];
16866 : 0 : origin->key_len = MLX5_RSS_HASH_KEY_LEN;
16867 : 0 : origin->queue = rss->queue;
16868 : 0 : origin->queue_num = rss->queue_num;
16869 [ # # ]: 0 : if (__flow_dv_action_rss_setup(dev, idx, shared_rss, error))
16870 : 0 : goto error_rss_init;
16871 : : /* Update queue with indirect table queue memoyr. */
16872 : 0 : origin->queue = shared_rss->ind_tbl->queues;
16873 : : rte_spinlock_init(&shared_rss->action_rss_sl);
16874 : 0 : rte_atomic_fetch_add_explicit(&shared_rss->refcnt, 1, rte_memory_order_relaxed);
16875 : 0 : rte_spinlock_lock(&priv->shared_act_sl);
16876 [ # # # # ]: 0 : ILIST_INSERT(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
16877 : : &priv->rss_shared_actions, idx, shared_rss, next);
16878 : : rte_spinlock_unlock(&priv->shared_act_sl);
16879 : 0 : return idx;
16880 : 0 : error_rss_init:
16881 [ # # ]: 0 : if (shared_rss) {
16882 [ # # ]: 0 : if (shared_rss->ind_tbl)
16883 : 0 : mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl,
16884 : 0 : !!dev->data->dev_started);
16885 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
16886 : : idx);
16887 : : }
16888 : : return 0;
16889 : : }
16890 : :
16891 : : /**
16892 : : * Destroy the shared RSS action.
16893 : : * Release related hash RX queue objects.
16894 : : *
16895 : : * @param[in] dev
16896 : : * Pointer to the Ethernet device structure.
16897 : : * @param[in] idx
16898 : : * The shared RSS action object ID to be removed.
16899 : : * @param[out] error
16900 : : * Perform verbose error reporting if not NULL. Initialized in case of
16901 : : * error only.
16902 : : *
16903 : : * @return
16904 : : * 0 on success, otherwise negative errno value.
16905 : : */
16906 : : static int
16907 : 0 : __flow_dv_action_rss_release(struct rte_eth_dev *dev, uint32_t idx,
16908 : : struct rte_flow_error *error)
16909 : : {
16910 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16911 : : struct mlx5_shared_action_rss *shared_rss =
16912 : 0 : mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
16913 : : uint32_t old_refcnt = 1;
16914 : : int remaining;
16915 : :
16916 [ # # ]: 0 : if (!shared_rss)
16917 : 0 : return rte_flow_error_set(error, EINVAL,
16918 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
16919 : : "invalid shared action");
16920 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(&shared_rss->refcnt, &old_refcnt,
16921 : : 0, rte_memory_order_acquire,
16922 : : rte_memory_order_relaxed))
16923 : 0 : return rte_flow_error_set(error, EBUSY,
16924 : : RTE_FLOW_ERROR_TYPE_ACTION,
16925 : : NULL,
16926 : : "shared rss has references");
16927 : : remaining = __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
16928 [ # # ]: 0 : if (remaining)
16929 : 0 : return rte_flow_error_set(error, EBUSY,
16930 : : RTE_FLOW_ERROR_TYPE_ACTION,
16931 : : NULL,
16932 : : "shared rss hrxq has references");
16933 : 0 : remaining = mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl,
16934 : 0 : !!dev->data->dev_started);
16935 [ # # ]: 0 : if (remaining)
16936 : 0 : return rte_flow_error_set(error, EBUSY,
16937 : : RTE_FLOW_ERROR_TYPE_ACTION,
16938 : : NULL,
16939 : : "shared rss indirection table has"
16940 : : " references");
16941 : 0 : rte_spinlock_lock(&priv->shared_act_sl);
16942 [ # # # # : 0 : ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
# # # # #
# ]
16943 : : &priv->rss_shared_actions, idx, shared_rss, next);
16944 : : rte_spinlock_unlock(&priv->shared_act_sl);
16945 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
16946 : : idx);
16947 : 0 : return 0;
16948 : : }
16949 : :
16950 : : /**
16951 : : * Create indirect action, lock free,
16952 : : * (mutex should be acquired by caller).
16953 : : * Dispatcher for action type specific call.
16954 : : *
16955 : : * @param[in] dev
16956 : : * Pointer to the Ethernet device structure.
16957 : : * @param[in] conf
16958 : : * Shared action configuration.
16959 : : * @param[in] action
16960 : : * Action specification used to create indirect action.
16961 : : * @param[out] error
16962 : : * Perform verbose error reporting if not NULL. Initialized in case of
16963 : : * error only.
16964 : : *
16965 : : * @return
16966 : : * A valid shared action handle in case of success, NULL otherwise and
16967 : : * rte_errno is set.
16968 : : */
16969 : : struct rte_flow_action_handle *
16970 : 0 : flow_dv_action_create(struct rte_eth_dev *dev,
16971 : : const struct rte_flow_indir_action_conf *conf,
16972 : : const struct rte_flow_action *action,
16973 : : struct rte_flow_error *err)
16974 : : {
16975 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16976 : : uint32_t age_idx = 0;
16977 : : uint32_t idx = 0;
16978 : : uint32_t ret = 0;
16979 : :
16980 [ # # # # : 0 : switch (action->type) {
# ]
16981 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
16982 : 0 : ret = __flow_dv_action_rss_create(dev, conf, action->conf, err);
16983 : : idx = (MLX5_INDIRECT_ACTION_TYPE_RSS <<
16984 : : MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
16985 : 0 : break;
16986 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
16987 : 0 : age_idx = flow_dv_aso_age_alloc(dev, err);
16988 [ # # ]: 0 : if (!age_idx) {
16989 : 0 : ret = -rte_errno;
16990 : 0 : break;
16991 : : }
16992 : 0 : idx = (MLX5_INDIRECT_ACTION_TYPE_AGE <<
16993 : : MLX5_INDIRECT_ACTION_TYPE_OFFSET) | age_idx;
16994 : 0 : flow_dv_aso_age_params_init(dev, age_idx,
16995 : : ((const struct rte_flow_action_age *)
16996 : 0 : action->conf)->context ?
16997 : : ((const struct rte_flow_action_age *)
16998 : : action->conf)->context :
16999 : 0 : (void *)(uintptr_t)idx,
17000 : : ((const struct rte_flow_action_age *)
17001 [ # # ]: 0 : action->conf)->timeout);
17002 : : ret = age_idx;
17003 : 0 : break;
17004 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
17005 : 0 : ret = flow_dv_translate_create_counter(dev, NULL, NULL, NULL);
17006 : 0 : idx = (MLX5_INDIRECT_ACTION_TYPE_COUNT <<
17007 : : MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
17008 : 0 : break;
17009 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
17010 : 0 : ret = flow_dv_translate_create_conntrack(dev, action->conf,
17011 : : err);
17012 [ # # ]: 0 : if (!ret)
17013 : : break;
17014 : 0 : idx = MLX5_INDIRECT_ACT_CT_GEN_IDX(PORT_ID(priv), ret);
17015 : 0 : break;
17016 : 0 : default:
17017 : 0 : rte_flow_error_set(err, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
17018 : : NULL, "action type not supported");
17019 : : break;
17020 : : }
17021 [ # # ]: 0 : return ret ? (struct rte_flow_action_handle *)(uintptr_t)idx : NULL;
17022 : : }
17023 : :
17024 : : /**
17025 : : * Destroy the indirect action.
17026 : : * Release action related resources on the NIC and the memory.
17027 : : * Lock free, (mutex should be acquired by caller).
17028 : : * Dispatcher for action type specific call.
17029 : : *
17030 : : * @param[in] dev
17031 : : * Pointer to the Ethernet device structure.
17032 : : * @param[in] handle
17033 : : * The indirect action object handle to be removed.
17034 : : * @param[out] error
17035 : : * Perform verbose error reporting if not NULL. Initialized in case of
17036 : : * error only.
17037 : : *
17038 : : * @return
17039 : : * 0 on success, otherwise negative errno value.
17040 : : */
17041 : : int
17042 : 0 : flow_dv_action_destroy(struct rte_eth_dev *dev,
17043 : : struct rte_flow_action_handle *handle,
17044 : : struct rte_flow_error *error)
17045 : : {
17046 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
17047 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
17048 : 0 : uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
17049 : : struct mlx5_flow_counter *cnt;
17050 : : uint32_t no_flow_refcnt = 1;
17051 : : int ret;
17052 : :
17053 [ # # # # : 0 : switch (type) {
# ]
17054 : 0 : case MLX5_INDIRECT_ACTION_TYPE_RSS:
17055 : 0 : return __flow_dv_action_rss_release(dev, idx, error);
17056 : : case MLX5_INDIRECT_ACTION_TYPE_COUNT:
17057 : : cnt = flow_dv_counter_get_by_idx(dev, idx, NULL);
17058 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(&cnt->shared_info.refcnt,
17059 : : &no_flow_refcnt, 1,
17060 : : rte_memory_order_acquire,
17061 : : rte_memory_order_relaxed))
17062 : 0 : return rte_flow_error_set(error, EBUSY,
17063 : : RTE_FLOW_ERROR_TYPE_ACTION,
17064 : : NULL,
17065 : : "Indirect count action has references");
17066 : 0 : flow_dv_counter_free(dev, idx);
17067 : 0 : return 0;
17068 : 0 : case MLX5_INDIRECT_ACTION_TYPE_AGE:
17069 : 0 : ret = flow_dv_aso_age_release(dev, idx);
17070 [ # # ]: 0 : if (ret)
17071 : : /*
17072 : : * In this case, the last flow has a reference will
17073 : : * actually release the age action.
17074 : : */
17075 : 0 : DRV_LOG(DEBUG, "Indirect age action %" PRIu32 " was"
17076 : : " released with references %d.", idx, ret);
17077 : : return 0;
17078 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
17079 : 0 : ret = flow_dv_aso_ct_release(dev, idx, error);
17080 [ # # ]: 0 : if (ret < 0)
17081 : : return ret;
17082 [ # # ]: 0 : if (ret > 0)
17083 : 0 : DRV_LOG(DEBUG, "Connection tracking object %u still "
17084 : : "has references %d.", idx, ret);
17085 : : return 0;
17086 : 0 : default:
17087 : 0 : return rte_flow_error_set(error, ENOTSUP,
17088 : : RTE_FLOW_ERROR_TYPE_ACTION,
17089 : : NULL,
17090 : : "action type not supported");
17091 : : }
17092 : : }
17093 : :
17094 : : /**
17095 : : * Updates in place shared RSS action configuration.
17096 : : *
17097 : : * @param[in] dev
17098 : : * Pointer to the Ethernet device structure.
17099 : : * @param[in] idx
17100 : : * The shared RSS action object ID to be updated.
17101 : : * @param[in] action_conf
17102 : : * RSS action specification used to modify *shared_rss*.
17103 : : * @param[out] error
17104 : : * Perform verbose error reporting if not NULL. Initialized in case of
17105 : : * error only.
17106 : : *
17107 : : * @return
17108 : : * 0 on success, otherwise negative errno value.
17109 : : * @note: currently only support update of RSS queues.
17110 : : */
17111 : : static int
17112 : 0 : __flow_dv_action_rss_update(struct rte_eth_dev *dev, uint32_t idx,
17113 : : const struct rte_flow_action_rss *action_conf,
17114 : : struct rte_flow_error *error)
17115 : : {
17116 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17117 : : struct mlx5_shared_action_rss *shared_rss =
17118 : 0 : mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
17119 : : int ret = 0;
17120 : : void *queue = NULL;
17121 : : void *queue_i = NULL;
17122 : 0 : uint32_t queue_size = action_conf->queue_num * sizeof(uint16_t);
17123 : 0 : bool dev_started = !!dev->data->dev_started;
17124 : :
17125 [ # # ]: 0 : if (!shared_rss)
17126 : 0 : return rte_flow_error_set(error, EINVAL,
17127 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
17128 : : "invalid shared action to update");
17129 [ # # ]: 0 : if (priv->obj_ops.ind_table_modify == NULL)
17130 : 0 : return rte_flow_error_set(error, ENOTSUP,
17131 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
17132 : : "cannot modify indirection table");
17133 : 0 : queue = mlx5_malloc(MLX5_MEM_ZERO,
17134 : 0 : RTE_ALIGN_CEIL(queue_size, sizeof(void *)),
17135 : : 0, SOCKET_ID_ANY);
17136 [ # # ]: 0 : if (!queue)
17137 : 0 : return rte_flow_error_set(error, ENOMEM,
17138 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17139 : : NULL,
17140 : : "cannot allocate resource memory");
17141 : 0 : memcpy(queue, action_conf->queue, queue_size);
17142 : : MLX5_ASSERT(shared_rss->ind_tbl);
17143 : 0 : rte_spinlock_lock(&shared_rss->action_rss_sl);
17144 : 0 : queue_i = shared_rss->ind_tbl->queues;
17145 : 0 : ret = mlx5_ind_table_obj_modify(dev, shared_rss->ind_tbl,
17146 : 0 : queue, action_conf->queue_num,
17147 : : true /* standalone */,
17148 : : dev_started /* ref_new_qs */,
17149 : : dev_started /* deref_old_qs */);
17150 [ # # ]: 0 : if (ret) {
17151 : 0 : ret = rte_flow_error_set(error, rte_errno,
17152 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
17153 : : "cannot update indirection table");
17154 : : } else {
17155 : : /* Restore the queue to indirect table internal queue. */
17156 : : memcpy(queue_i, queue, queue_size);
17157 : 0 : shared_rss->ind_tbl->queues = queue_i;
17158 : 0 : shared_rss->origin.queue_num = action_conf->queue_num;
17159 : : }
17160 : 0 : mlx5_free(queue);
17161 : : rte_spinlock_unlock(&shared_rss->action_rss_sl);
17162 : 0 : return ret;
17163 : : }
17164 : :
17165 : : /*
17166 : : * Updates in place conntrack context or direction.
17167 : : * Context update should be synchronized.
17168 : : *
17169 : : * @param[in] dev
17170 : : * Pointer to the Ethernet device structure.
17171 : : * @param[in] idx
17172 : : * The conntrack object ID to be updated.
17173 : : * @param[in] update
17174 : : * Pointer to the structure of information to update.
17175 : : * @param[out] error
17176 : : * Perform verbose error reporting if not NULL. Initialized in case of
17177 : : * error only.
17178 : : *
17179 : : * @return
17180 : : * 0 on success, otherwise negative errno value.
17181 : : */
17182 : : static int
17183 : 0 : __flow_dv_action_ct_update(struct rte_eth_dev *dev, uint32_t idx,
17184 : : const struct rte_flow_modify_conntrack *update,
17185 : : struct rte_flow_error *error)
17186 : : {
17187 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17188 : : struct mlx5_aso_ct_action *ct;
17189 : : const struct rte_flow_action_conntrack *new_prf;
17190 : : int ret = 0;
17191 : 0 : uint16_t owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(idx);
17192 : : uint32_t dev_idx;
17193 : :
17194 [ # # ]: 0 : if (PORT_ID(priv) != owner)
17195 : 0 : return rte_flow_error_set(error, EACCES,
17196 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17197 : : NULL,
17198 : : "CT object owned by another port");
17199 : 0 : dev_idx = MLX5_INDIRECT_ACT_CT_GET_IDX(idx);
17200 : 0 : ct = flow_aso_ct_get_by_dev_idx(dev, dev_idx);
17201 [ # # ]: 0 : if (!ct->refcnt)
17202 : 0 : return rte_flow_error_set(error, ENOMEM,
17203 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17204 : : NULL,
17205 : : "CT object is inactive");
17206 : 0 : new_prf = &update->new_ct;
17207 [ # # ]: 0 : if (update->direction)
17208 : 0 : ct->is_original = !!new_prf->is_original_dir;
17209 [ # # ]: 0 : if (update->state) {
17210 : : /* Only validate the profile when it needs to be updated. */
17211 : 0 : ret = mlx5_validate_action_ct(dev, new_prf, error);
17212 [ # # ]: 0 : if (ret)
17213 : : return ret;
17214 : 0 : ret = mlx5_aso_ct_update_by_wqe(priv->sh, MLX5_HW_INV_QUEUE,
17215 : : ct, new_prf, NULL, true);
17216 [ # # ]: 0 : if (ret)
17217 : 0 : return rte_flow_error_set(error, EIO,
17218 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17219 : : NULL,
17220 : : "Failed to send CT context update WQE");
17221 : : /* Block until ready or a failure, default is asynchronous. */
17222 : 0 : ret = mlx5_aso_ct_available(priv->sh, MLX5_HW_INV_QUEUE, ct);
17223 [ # # ]: 0 : if (ret)
17224 : 0 : rte_flow_error_set(error, rte_errno,
17225 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17226 : : NULL,
17227 : : "Timeout to get the CT update");
17228 : : }
17229 : : return ret;
17230 : : }
17231 : :
17232 : : /**
17233 : : * Updates in place shared action configuration, lock free,
17234 : : * (mutex should be acquired by caller).
17235 : : *
17236 : : * @param[in] dev
17237 : : * Pointer to the Ethernet device structure.
17238 : : * @param[in] handle
17239 : : * The indirect action object handle to be updated.
17240 : : * @param[in] update
17241 : : * Action specification used to modify the action pointed by *handle*.
17242 : : * *update* could be of same type with the action pointed by the *handle*
17243 : : * handle argument, or some other structures like a wrapper, depending on
17244 : : * the indirect action type.
17245 : : * @param[out] error
17246 : : * Perform verbose error reporting if not NULL. Initialized in case of
17247 : : * error only.
17248 : : *
17249 : : * @return
17250 : : * 0 on success, otherwise negative errno value.
17251 : : */
17252 : : int
17253 : 0 : flow_dv_action_update(struct rte_eth_dev *dev,
17254 : : struct rte_flow_action_handle *handle,
17255 : : const void *update,
17256 : : struct rte_flow_error *err)
17257 : : {
17258 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
17259 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
17260 : 0 : uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
17261 : : const void *action_conf;
17262 : :
17263 [ # # # ]: 0 : switch (type) {
17264 : 0 : case MLX5_INDIRECT_ACTION_TYPE_RSS:
17265 : 0 : action_conf = ((const struct rte_flow_action *)update)->conf;
17266 : 0 : return __flow_dv_action_rss_update(dev, idx, action_conf, err);
17267 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
17268 : 0 : return __flow_dv_action_ct_update(dev, idx, update, err);
17269 : 0 : default:
17270 : 0 : return rte_flow_error_set(err, ENOTSUP,
17271 : : RTE_FLOW_ERROR_TYPE_ACTION,
17272 : : NULL,
17273 : : "action type update not supported");
17274 : : }
17275 : : }
17276 : :
17277 : : /**
17278 : : * Destroy the meter sub policy table rules.
17279 : : * Lock free, (mutex should be acquired by caller).
17280 : : *
17281 : : * @param[in] dev
17282 : : * Pointer to Ethernet device.
17283 : : * @param[in] sub_policy
17284 : : * Pointer to meter sub policy table.
17285 : : */
17286 : : static void
17287 : 0 : __flow_dv_destroy_sub_policy_rules(struct rte_eth_dev *dev,
17288 : : struct mlx5_flow_meter_sub_policy *sub_policy)
17289 : : {
17290 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17291 : : struct mlx5_flow_tbl_data_entry *tbl;
17292 : 0 : struct mlx5_flow_meter_policy *policy = sub_policy->main_policy;
17293 : : struct mlx5_flow_meter_info *next_fm;
17294 : : struct mlx5_sub_policy_color_rule *color_rule;
17295 : : void *tmp;
17296 : : uint32_t i;
17297 : :
17298 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
17299 : : next_fm = NULL;
17300 [ # # ]: 0 : if (i <= RTE_COLOR_YELLOW && policy &&
17301 [ # # ]: 0 : policy->act_cnt[i].fate_action == MLX5_FLOW_FATE_MTR)
17302 : 0 : next_fm = mlx5_flow_meter_find(priv,
17303 : : policy->act_cnt[i].next_mtr_id, NULL);
17304 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(color_rule, &sub_policy->color_rules[i],
17305 : : next_port, tmp) {
17306 : 0 : claim_zero(mlx5_flow_os_destroy_flow(color_rule->rule));
17307 : 0 : tbl = container_of(color_rule->matcher->tbl,
17308 : : typeof(*tbl), tbl);
17309 : 0 : mlx5_list_unregister(tbl->matchers,
17310 : : &color_rule->matcher->entry);
17311 [ # # ]: 0 : TAILQ_REMOVE(&sub_policy->color_rules[i],
17312 : : color_rule, next_port);
17313 : 0 : mlx5_free(color_rule);
17314 [ # # ]: 0 : if (next_fm)
17315 : 0 : mlx5_flow_meter_detach(priv, next_fm);
17316 : : }
17317 : : }
17318 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
17319 [ # # ]: 0 : if (sub_policy->rix_hrxq[i]) {
17320 [ # # # # ]: 0 : if (policy && !policy->is_hierarchy)
17321 : 0 : mlx5_hrxq_release(dev, sub_policy->rix_hrxq[i]);
17322 : 0 : sub_policy->rix_hrxq[i] = 0;
17323 : : }
17324 [ # # ]: 0 : if (sub_policy->jump_tbl[i]) {
17325 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev),
17326 : : sub_policy->jump_tbl[i]);
17327 : 0 : sub_policy->jump_tbl[i] = NULL;
17328 : : }
17329 : : }
17330 [ # # ]: 0 : if (sub_policy->tbl_rsc) {
17331 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev),
17332 : : sub_policy->tbl_rsc);
17333 : 0 : sub_policy->tbl_rsc = NULL;
17334 : : }
17335 : 0 : }
17336 : :
17337 : : /**
17338 : : * Destroy policy rules, lock free,
17339 : : * (mutex should be acquired by caller).
17340 : : * Dispatcher for action type specific call.
17341 : : *
17342 : : * @param[in] dev
17343 : : * Pointer to the Ethernet device structure.
17344 : : * @param[in] mtr_policy
17345 : : * Meter policy struct.
17346 : : */
17347 : : static void
17348 : 0 : flow_dv_destroy_policy_rules(struct rte_eth_dev *dev,
17349 : : struct mlx5_flow_meter_policy *mtr_policy)
17350 : : {
17351 : : uint32_t i, j;
17352 : : struct mlx5_flow_meter_sub_policy *sub_policy;
17353 : : uint16_t sub_policy_num;
17354 : :
17355 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
17356 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
17357 : 0 : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
17358 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
17359 [ # # ]: 0 : for (j = 0; j < sub_policy_num; j++) {
17360 : 0 : sub_policy = mtr_policy->sub_policys[i][j];
17361 [ # # ]: 0 : if (sub_policy)
17362 : 0 : __flow_dv_destroy_sub_policy_rules(dev,
17363 : : sub_policy);
17364 : : }
17365 : : }
17366 : 0 : }
17367 : :
17368 : : /**
17369 : : * Destroy policy action, lock free,
17370 : : * (mutex should be acquired by caller).
17371 : : * Dispatcher for action type specific call.
17372 : : *
17373 : : * @param[in] dev
17374 : : * Pointer to the Ethernet device structure.
17375 : : * @param[in] mtr_policy
17376 : : * Meter policy struct.
17377 : : */
17378 : : static void
17379 : 0 : flow_dv_destroy_mtr_policy_acts(struct rte_eth_dev *dev,
17380 : : struct mlx5_flow_meter_policy *mtr_policy)
17381 : : {
17382 : : struct rte_flow_action *rss_action;
17383 : : struct mlx5_flow_handle dev_handle;
17384 : : uint32_t i, j;
17385 : :
17386 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
17387 [ # # ]: 0 : if (mtr_policy->act_cnt[i].rix_mark) {
17388 : 0 : flow_dv_tag_release(dev,
17389 : : mtr_policy->act_cnt[i].rix_mark);
17390 : 0 : mtr_policy->act_cnt[i].rix_mark = 0;
17391 : : }
17392 [ # # ]: 0 : if (mtr_policy->act_cnt[i].modify_hdr) {
17393 : : dev_handle.dvh.modify_hdr =
17394 : : mtr_policy->act_cnt[i].modify_hdr;
17395 : : flow_dv_modify_hdr_resource_release(dev, &dev_handle);
17396 : : }
17397 [ # # # # ]: 0 : switch (mtr_policy->act_cnt[i].fate_action) {
17398 : 0 : case MLX5_FLOW_FATE_SHARED_RSS:
17399 : 0 : rss_action = mtr_policy->act_cnt[i].rss;
17400 : 0 : mlx5_free(rss_action);
17401 : 0 : break;
17402 : 0 : case MLX5_FLOW_FATE_PORT_ID:
17403 [ # # ]: 0 : if (mtr_policy->act_cnt[i].rix_port_id_action) {
17404 : 0 : flow_dv_port_id_action_resource_release(dev,
17405 : : mtr_policy->act_cnt[i].rix_port_id_action);
17406 : 0 : mtr_policy->act_cnt[i].rix_port_id_action = 0;
17407 : : }
17408 : : break;
17409 : : case MLX5_FLOW_FATE_DROP:
17410 : : case MLX5_FLOW_FATE_JUMP:
17411 [ # # ]: 0 : for (j = 0; j < MLX5_MTR_DOMAIN_MAX; j++)
17412 : 0 : mtr_policy->act_cnt[i].dr_jump_action[j] =
17413 : : NULL;
17414 : : break;
17415 : : default:
17416 : : /*Queue action do nothing*/
17417 : : break;
17418 : : }
17419 : : }
17420 [ # # ]: 0 : for (j = 0; j < MLX5_MTR_DOMAIN_MAX; j++)
17421 : 0 : mtr_policy->dr_drop_action[j] = NULL;
17422 : 0 : }
17423 : :
17424 : : /**
17425 : : * Create yellow action for color aware meter.
17426 : : *
17427 : : * @param[in] dev
17428 : : * Pointer to the Ethernet device structure.
17429 : : * @param[in] fm
17430 : : * Meter information table.
17431 : : * @param[out] error
17432 : : * Perform verbose error reporting if not NULL. Initialized in case of
17433 : : * error only.
17434 : : *
17435 : : * @return
17436 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
17437 : : */
17438 : : static int
17439 : 0 : __flow_dv_create_mtr_yellow_action(struct rte_eth_dev *dev,
17440 : : struct mlx5_flow_meter_info *fm,
17441 : : struct rte_mtr_error *error)
17442 : : {
17443 : : #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
17444 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17445 : : struct rte_flow_error flow_err;
17446 : : struct mlx5_aso_mtr *aso_mtr;
17447 : : struct mlx5_aso_mtr_pool *pool;
17448 : : uint8_t reg_id;
17449 : :
17450 : 0 : aso_mtr = container_of(fm, struct mlx5_aso_mtr, fm);
17451 : 0 : pool = container_of(aso_mtr, struct mlx5_aso_mtr_pool, mtrs[aso_mtr->offset]);
17452 : 0 : reg_id = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &flow_err);
17453 : 0 : fm->meter_action_y =
17454 : 0 : mlx5_glue->dv_create_flow_action_aso(priv->sh->rx_domain,
17455 : 0 : pool->devx_obj->obj,
17456 : : aso_mtr->offset,
17457 : : (1 << MLX5_FLOW_COLOR_YELLOW),
17458 : 0 : reg_id - REG_C_0);
17459 : : #else
17460 : : RTE_SET_USED(dev);
17461 : : #endif
17462 [ # # ]: 0 : if (!fm->meter_action_y) {
17463 : 0 : return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
17464 : : "Fail to create yellow meter action.");
17465 : : }
17466 : : return 0;
17467 : : }
17468 : :
17469 : : /**
17470 : : * Create policy action per domain, lock free,
17471 : : * (mutex should be acquired by caller).
17472 : : * Dispatcher for action type specific call.
17473 : : *
17474 : : * @param[in] dev
17475 : : * Pointer to the Ethernet device structure.
17476 : : * @param[in] mtr_policy
17477 : : * Meter policy struct.
17478 : : * @param[in] action
17479 : : * Action specification used to create meter actions.
17480 : : * @param[in] attr
17481 : : * Pointer to the flow attributes.
17482 : : * @param[out] error
17483 : : * Perform verbose error reporting if not NULL. Initialized in case of
17484 : : * error only.
17485 : : *
17486 : : * @return
17487 : : * 0 on success, otherwise negative errno value.
17488 : : */
17489 : : static int
17490 : 0 : __flow_dv_create_domain_policy_acts(struct rte_eth_dev *dev,
17491 : : struct mlx5_flow_meter_policy *mtr_policy,
17492 : : const struct rte_flow_action *actions[RTE_COLORS],
17493 : : struct rte_flow_attr *attr,
17494 : : enum mlx5_meter_domain domain,
17495 : : struct rte_mtr_error *error)
17496 : : {
17497 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17498 : : struct rte_flow_error flow_err;
17499 : : const struct rte_flow_action *act;
17500 : : uint64_t action_flags;
17501 : : struct mlx5_flow_handle dh;
17502 : : struct mlx5_flow dev_flow;
17503 : : struct mlx5_flow_dv_port_id_action_resource port_id_action;
17504 : : int i, ret;
17505 : : uint8_t egress, transfer;
17506 : : struct mlx5_meter_policy_action_container *act_cnt = NULL;
17507 : : union {
17508 : : struct mlx5_flow_dv_modify_hdr_resource res;
17509 : : uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
17510 : : sizeof(struct mlx5_modification_cmd) *
17511 : : (MLX5_MAX_MODIFY_NUM + 1)];
17512 : : } mhdr_dummy;
17513 : : struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
17514 : :
17515 : 0 : egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
17516 [ # # ]: 0 : transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
17517 : : memset(&dh, 0, sizeof(struct mlx5_flow_handle));
17518 : : memset(&dev_flow, 0, sizeof(struct mlx5_flow));
17519 : : memset(&port_id_action, 0,
17520 : : sizeof(struct mlx5_flow_dv_port_id_action_resource));
17521 : : memset(mhdr_res, 0, sizeof(*mhdr_res));
17522 [ # # ]: 0 : mhdr_res->ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
17523 : : (egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
17524 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX);
17525 : 0 : dev_flow.handle = &dh;
17526 : 0 : dev_flow.dv.port_id_action = &port_id_action;
17527 : 0 : dev_flow.external = true;
17528 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
17529 [ # # ]: 0 : if (i < MLX5_MTR_RTE_COLORS)
17530 : 0 : act_cnt = &mtr_policy->act_cnt[i];
17531 : : /* Skip the color policy actions creation. */
17532 [ # # # # : 0 : if ((i == RTE_COLOR_YELLOW && mtr_policy->skip_y) ||
# # ]
17533 [ # # ]: 0 : (i == RTE_COLOR_GREEN && mtr_policy->skip_g))
17534 : 0 : continue;
17535 : : action_flags = 0;
17536 : 0 : for (act = actions[i];
17537 [ # # # # ]: 0 : act && act->type != RTE_FLOW_ACTION_TYPE_END; act++) {
17538 [ # # # # : 0 : switch (act->type) {
# # # # #
# ]
17539 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
17540 : : {
17541 : : uint32_t tag_be = mlx5_flow_mark_set
17542 : : (((const struct rte_flow_action_mark *)
17543 [ # # ]: 0 : (act->conf))->id);
17544 : :
17545 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17546 : 0 : return -rte_mtr_error_set(error,
17547 : : ENOTSUP,
17548 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17549 : : NULL,
17550 : : "cannot create policy "
17551 : : "mark action for this color");
17552 [ # # ]: 0 : if (flow_dv_tag_resource_register(dev, tag_be,
17553 : : &dev_flow, &flow_err))
17554 : 0 : return -rte_mtr_error_set(error,
17555 : : ENOTSUP,
17556 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17557 : : NULL,
17558 : : "cannot setup policy mark action");
17559 : : MLX5_ASSERT(dev_flow.dv.tag_resource);
17560 : 0 : act_cnt->rix_mark =
17561 : 0 : dev_flow.handle->dvh.rix_tag;
17562 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK;
17563 : 0 : mtr_policy->mark = 1;
17564 : 0 : break;
17565 : : }
17566 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TAG:
17567 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17568 : 0 : return -rte_mtr_error_set(error,
17569 : : ENOTSUP,
17570 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17571 : : NULL,
17572 : : "cannot create policy "
17573 : : "set tag action for this color");
17574 [ # # ]: 0 : if (flow_dv_convert_action_set_tag
17575 : : (dev, mhdr_res,
17576 : : (const struct rte_flow_action_set_tag *)
17577 : 0 : act->conf, &flow_err))
17578 : 0 : return -rte_mtr_error_set(error,
17579 : : ENOTSUP,
17580 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17581 : : NULL, "cannot convert policy "
17582 : : "set tag action");
17583 [ # # ]: 0 : if (!mhdr_res->actions_num)
17584 : 0 : return -rte_mtr_error_set(error,
17585 : : ENOTSUP,
17586 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17587 : : NULL, "cannot find policy "
17588 : : "set tag action");
17589 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
17590 : 0 : break;
17591 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
17592 : : {
17593 : 0 : struct mlx5_flow_mtr_mng *mtrmng =
17594 : 0 : priv->sh->mtrmng;
17595 : : struct mlx5_flow_tbl_data_entry *tbl_data;
17596 : :
17597 : : /*
17598 : : * Create the drop table with
17599 : : * METER DROP level.
17600 : : */
17601 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
17602 : 0 : mtrmng->drop_tbl[domain] =
17603 : 0 : flow_dv_tbl_resource_get(dev,
17604 : : MLX5_FLOW_TABLE_LEVEL_METER,
17605 : : egress, transfer, false, NULL, 0,
17606 : : 0, MLX5_MTR_TABLE_ID_DROP, &flow_err);
17607 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain])
17608 : 0 : return -rte_mtr_error_set
17609 : : (error, ENOTSUP,
17610 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17611 : : NULL,
17612 : : "Failed to create meter drop table");
17613 : : }
17614 : 0 : tbl_data = container_of
17615 : : (mtrmng->drop_tbl[domain],
17616 : : struct mlx5_flow_tbl_data_entry, tbl);
17617 [ # # ]: 0 : if (i < MLX5_MTR_RTE_COLORS) {
17618 : 0 : act_cnt->dr_jump_action[domain] =
17619 : 0 : tbl_data->jump.action;
17620 : 0 : act_cnt->fate_action =
17621 : : MLX5_FLOW_FATE_DROP;
17622 : : }
17623 [ # # ]: 0 : if (i == RTE_COLOR_RED)
17624 : 0 : mtr_policy->dr_drop_action[domain] =
17625 : 0 : tbl_data->jump.action;
17626 : 0 : action_flags |= MLX5_FLOW_ACTION_DROP;
17627 : 0 : break;
17628 : : }
17629 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
17630 : : {
17631 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17632 : 0 : return -rte_mtr_error_set(error,
17633 : : ENOTSUP,
17634 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17635 : : NULL, "cannot create policy "
17636 : : "fate queue for this color");
17637 : 0 : act_cnt->queue =
17638 : : ((const struct rte_flow_action_queue *)
17639 : 0 : (act->conf))->index;
17640 : 0 : act_cnt->fate_action =
17641 : : MLX5_FLOW_FATE_QUEUE;
17642 : 0 : dev_flow.handle->fate_action =
17643 : : MLX5_FLOW_FATE_QUEUE;
17644 : 0 : mtr_policy->is_queue = 1;
17645 : 0 : action_flags |= MLX5_FLOW_ACTION_QUEUE;
17646 : 0 : break;
17647 : : }
17648 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
17649 : : {
17650 : : int rss_size;
17651 : :
17652 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17653 : 0 : return -rte_mtr_error_set(error,
17654 : : ENOTSUP,
17655 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17656 : : NULL,
17657 : : "cannot create policy "
17658 : : "rss action for this color");
17659 : : /*
17660 : : * Save RSS conf into policy struct
17661 : : * for translate stage.
17662 : : */
17663 : 0 : rss_size = (int)rte_flow_conv
17664 : : (RTE_FLOW_CONV_OP_ACTION,
17665 : : NULL, 0, act, &flow_err);
17666 [ # # ]: 0 : if (rss_size <= 0)
17667 : 0 : return -rte_mtr_error_set(error,
17668 : : ENOTSUP,
17669 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17670 : : NULL, "Get the wrong "
17671 : : "rss action struct size");
17672 : 0 : act_cnt->rss = mlx5_malloc(MLX5_MEM_ZERO,
17673 : : rss_size, 0, SOCKET_ID_ANY);
17674 [ # # ]: 0 : if (!act_cnt->rss)
17675 : 0 : return -rte_mtr_error_set(error,
17676 : : ENOTSUP,
17677 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17678 : : NULL,
17679 : : "Fail to malloc rss action memory");
17680 : 0 : ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTION,
17681 : : act_cnt->rss, rss_size,
17682 : : act, &flow_err);
17683 [ # # ]: 0 : if (ret < 0)
17684 : 0 : return -rte_mtr_error_set(error,
17685 : : ENOTSUP,
17686 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17687 : : NULL, "Fail to save "
17688 : : "rss action into policy struct");
17689 : 0 : act_cnt->fate_action =
17690 : : MLX5_FLOW_FATE_SHARED_RSS;
17691 : 0 : action_flags |= MLX5_FLOW_ACTION_RSS;
17692 : 0 : break;
17693 : : }
17694 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
17695 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
17696 : : {
17697 : : struct mlx5_flow_dv_port_id_action_resource
17698 : : port_id_resource;
17699 : 0 : uint32_t port_id = 0;
17700 : :
17701 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17702 : 0 : return -rte_mtr_error_set(error,
17703 : : ENOTSUP,
17704 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17705 : : NULL, "cannot create policy "
17706 : : "port action for this color");
17707 : : memset(&port_id_resource, 0,
17708 : : sizeof(port_id_resource));
17709 [ # # ]: 0 : if (flow_dv_translate_action_port_id(dev, act,
17710 : : &port_id, &flow_err))
17711 : 0 : return -rte_mtr_error_set(error,
17712 : : ENOTSUP,
17713 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17714 : : NULL, "cannot translate "
17715 : : "policy port action");
17716 : 0 : port_id_resource.port_id = port_id;
17717 [ # # ]: 0 : if (flow_dv_port_id_action_resource_register
17718 : : (dev, &port_id_resource,
17719 : : &dev_flow, &flow_err))
17720 : 0 : return -rte_mtr_error_set(error,
17721 : : ENOTSUP,
17722 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17723 : : NULL, "cannot setup "
17724 : : "policy port action");
17725 : 0 : act_cnt->rix_port_id_action =
17726 : 0 : dev_flow.handle->rix_port_id_action;
17727 : 0 : act_cnt->fate_action =
17728 : : MLX5_FLOW_FATE_PORT_ID;
17729 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_ID;
17730 : 0 : break;
17731 : : }
17732 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
17733 : : {
17734 : : uint32_t jump_group = 0;
17735 : 0 : uint32_t table = 0;
17736 : : struct mlx5_flow_tbl_data_entry *tbl_data;
17737 : 0 : struct flow_grp_info grp_info = {
17738 : 0 : .external = !!dev_flow.external,
17739 : : .transfer = !!transfer,
17740 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
17741 : : .std_tbl_fix = 0,
17742 : 0 : .skip_scale = dev_flow.skip_scale &
17743 : : (1 << MLX5_SCALE_FLOW_GROUP_BIT),
17744 : : };
17745 : 0 : struct mlx5_flow_meter_sub_policy *sub_policy =
17746 : 0 : mtr_policy->sub_policys[domain][0];
17747 : :
17748 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17749 : 0 : return -rte_mtr_error_set(error,
17750 : : ENOTSUP,
17751 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17752 : : NULL,
17753 : : "cannot create policy "
17754 : : "jump action for this color");
17755 : 0 : jump_group =
17756 : : ((const struct rte_flow_action_jump *)
17757 : 0 : act->conf)->group;
17758 [ # # ]: 0 : if (mlx5_flow_group_to_table(dev, NULL,
17759 : : jump_group,
17760 : : &table,
17761 : : &grp_info, &flow_err))
17762 : 0 : return -rte_mtr_error_set(error,
17763 : : ENOTSUP,
17764 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17765 : : NULL, "cannot setup "
17766 : : "policy jump action");
17767 : 0 : sub_policy->jump_tbl[i] =
17768 : 0 : flow_dv_tbl_resource_get(dev,
17769 : : table, egress,
17770 : : transfer,
17771 : : !!dev_flow.external,
17772 : : NULL, jump_group, 0,
17773 : : 0, &flow_err);
17774 : : if
17775 [ # # ]: 0 : (!sub_policy->jump_tbl[i])
17776 : 0 : return -rte_mtr_error_set(error,
17777 : : ENOTSUP,
17778 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17779 : : NULL, "cannot create jump action.");
17780 : 0 : tbl_data = container_of
17781 : : (sub_policy->jump_tbl[i],
17782 : : struct mlx5_flow_tbl_data_entry, tbl);
17783 : 0 : act_cnt->dr_jump_action[domain] =
17784 : 0 : tbl_data->jump.action;
17785 : 0 : act_cnt->fate_action =
17786 : : MLX5_FLOW_FATE_JUMP;
17787 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP;
17788 : 0 : break;
17789 : : }
17790 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
17791 : : {
17792 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17793 : 0 : return -rte_mtr_error_set(error,
17794 : : ENOTSUP,
17795 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17796 : : NULL,
17797 : : "cannot create policy modify field for this color");
17798 [ # # ]: 0 : if (flow_dv_convert_action_modify_field
17799 : : (dev, mhdr_res, act, attr, &flow_err))
17800 : 0 : return -rte_mtr_error_set(error,
17801 : : ENOTSUP,
17802 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17803 : : NULL, "cannot setup policy modify field action");
17804 [ # # ]: 0 : if (!mhdr_res->actions_num)
17805 : 0 : return -rte_mtr_error_set(error,
17806 : : ENOTSUP,
17807 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17808 : : NULL, "cannot find policy modify field action");
17809 : 0 : action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
17810 : 0 : break;
17811 : : }
17812 : : /*
17813 : : * No need to check meter hierarchy for R colors
17814 : : * here since it is done in the validation stage.
17815 : : */
17816 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
17817 : : {
17818 : : const struct rte_flow_action_meter *mtr;
17819 : : struct mlx5_flow_meter_info *next_fm;
17820 : : struct mlx5_flow_meter_policy *next_policy;
17821 : : struct rte_flow_action tag_action;
17822 : : struct mlx5_rte_flow_action_set_tag set_tag;
17823 : 0 : uint32_t next_mtr_idx = 0;
17824 : :
17825 : 0 : mtr = act->conf;
17826 : 0 : next_fm = mlx5_flow_meter_find(priv,
17827 : 0 : mtr->mtr_id,
17828 : : &next_mtr_idx);
17829 [ # # ]: 0 : if (!next_fm)
17830 : 0 : return -rte_mtr_error_set(error, EINVAL,
17831 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
17832 : : "Fail to find next meter.");
17833 [ # # ]: 0 : if (next_fm->def_policy)
17834 : 0 : return -rte_mtr_error_set(error, EINVAL,
17835 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
17836 : : "Hierarchy only supports termination meter.");
17837 : 0 : next_policy = mlx5_flow_meter_policy_find(dev,
17838 : : next_fm->policy_id, NULL);
17839 : : MLX5_ASSERT(next_policy);
17840 [ # # ]: 0 : if (next_fm->drop_cnt) {
17841 : 0 : set_tag.id =
17842 : 0 : (enum modify_reg)
17843 : 0 : mlx5_flow_get_reg_id(dev,
17844 : : MLX5_MTR_ID,
17845 : : 0,
17846 : : (struct rte_flow_error *)error);
17847 : 0 : set_tag.offset = (priv->mtr_reg_share ?
17848 : 0 : MLX5_MTR_COLOR_BITS : 0);
17849 [ # # ]: 0 : set_tag.length = (priv->mtr_reg_share ?
17850 : : MLX5_MTR_IDLE_BITS_IN_COLOR_REG :
17851 : : MLX5_REG_BITS);
17852 : 0 : set_tag.data = next_mtr_idx;
17853 : 0 : tag_action.type =
17854 : : (enum rte_flow_action_type)
17855 : : MLX5_RTE_FLOW_ACTION_TYPE_TAG;
17856 : 0 : tag_action.conf = &set_tag;
17857 [ # # ]: 0 : if (flow_dv_convert_action_set_reg
17858 : : (mhdr_res, &tag_action,
17859 : : (struct rte_flow_error *)error))
17860 : 0 : return -rte_errno;
17861 : 0 : action_flags |=
17862 : : MLX5_FLOW_ACTION_SET_TAG;
17863 : : }
17864 [ # # # # ]: 0 : if (i == RTE_COLOR_YELLOW && next_fm->color_aware &&
17865 [ # # ]: 0 : !next_fm->meter_action_y)
17866 [ # # ]: 0 : if (__flow_dv_create_mtr_yellow_action(dev, next_fm, error))
17867 : 0 : return -rte_errno;
17868 : 0 : act_cnt->fate_action = MLX5_FLOW_FATE_MTR;
17869 : 0 : act_cnt->next_mtr_id = next_fm->meter_id;
17870 : 0 : act_cnt->next_sub_policy = NULL;
17871 : 0 : mtr_policy->is_hierarchy = 1;
17872 [ # # ]: 0 : if (next_policy->mark)
17873 : 0 : mtr_policy->mark = 1;
17874 : 0 : mtr_policy->hierarchy_match_port =
17875 : 0 : next_policy->hierarchy_match_port;
17876 : 0 : action_flags |=
17877 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
17878 : 0 : break;
17879 : : }
17880 : : default:
17881 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
17882 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17883 : : NULL, "action type not supported");
17884 : : }
17885 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_SET_TAG) ||
17886 : : (action_flags & MLX5_FLOW_ACTION_MODIFY_FIELD)) {
17887 : : /* create modify action if needed. */
17888 : 0 : dev_flow.dv.group = 1;
17889 [ # # ]: 0 : if (flow_dv_modify_hdr_resource_register
17890 : : (dev, mhdr_res, &dev_flow, &flow_err))
17891 : 0 : return -rte_mtr_error_set(error,
17892 : : ENOTSUP,
17893 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17894 : : NULL, "cannot register policy set tag/modify field action");
17895 : 0 : act_cnt->modify_hdr =
17896 : 0 : dev_flow.handle->dvh.modify_hdr;
17897 : : }
17898 : : }
17899 : : }
17900 : : return 0;
17901 : : }
17902 : :
17903 : : /**
17904 : : * Create policy action per domain, lock free,
17905 : : * (mutex should be acquired by caller).
17906 : : * Dispatcher for action type specific call.
17907 : : *
17908 : : * @param[in] dev
17909 : : * Pointer to the Ethernet device structure.
17910 : : * @param[in] mtr_policy
17911 : : * Meter policy struct.
17912 : : * @param[in] action
17913 : : * Action specification used to create meter actions.
17914 : : * @param[in] attr
17915 : : * Pointer to the flow attributes.
17916 : : * @param[out] error
17917 : : * Perform verbose error reporting if not NULL. Initialized in case of
17918 : : * error only.
17919 : : *
17920 : : * @return
17921 : : * 0 on success, otherwise negative errno value.
17922 : : */
17923 : : static int
17924 : 0 : flow_dv_create_mtr_policy_acts(struct rte_eth_dev *dev,
17925 : : struct mlx5_flow_meter_policy *mtr_policy,
17926 : : const struct rte_flow_action *actions[RTE_COLORS],
17927 : : struct rte_flow_attr *attr,
17928 : : struct rte_mtr_error *error)
17929 : : {
17930 : : int ret, i;
17931 : : uint16_t sub_policy_num;
17932 : :
17933 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
17934 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
17935 : 0 : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
17936 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
17937 [ # # ]: 0 : if (sub_policy_num) {
17938 : 0 : ret = __flow_dv_create_domain_policy_acts(dev,
17939 : : mtr_policy, actions, attr,
17940 : : (enum mlx5_meter_domain)i, error);
17941 : : /* Cleaning resource is done in the caller level. */
17942 [ # # ]: 0 : if (ret)
17943 : 0 : return ret;
17944 : : }
17945 : : }
17946 : : return 0;
17947 : : }
17948 : :
17949 : : /**
17950 : : * Query a DV flow rule for its statistics via DevX.
17951 : : *
17952 : : * @param[in] dev
17953 : : * Pointer to Ethernet device.
17954 : : * @param[in] cnt_idx
17955 : : * Index to the flow counter.
17956 : : * @param[out] data
17957 : : * Data retrieved by the query.
17958 : : * @param[out] error
17959 : : * Perform verbose error reporting if not NULL.
17960 : : *
17961 : : * @return
17962 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
17963 : : */
17964 : : static int
17965 : 0 : flow_dv_query_count(struct rte_eth_dev *dev, uint32_t cnt_idx, void *data,
17966 : : struct rte_flow_error *error)
17967 : : {
17968 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17969 : : struct rte_flow_query_count *qc = data;
17970 : :
17971 [ # # ]: 0 : if (!priv->sh->cdev->config.devx)
17972 : 0 : return rte_flow_error_set(error, ENOTSUP,
17973 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17974 : : NULL,
17975 : : "counters are not supported");
17976 [ # # ]: 0 : if (cnt_idx) {
17977 : : uint64_t pkts, bytes;
17978 : : struct mlx5_flow_counter *cnt;
17979 : 0 : int err = _flow_dv_query_count(dev, cnt_idx, &pkts, &bytes);
17980 : :
17981 [ # # ]: 0 : if (err)
17982 : 0 : return rte_flow_error_set(error, -err,
17983 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17984 : : NULL, "cannot read counters");
17985 : : cnt = flow_dv_counter_get_by_idx(dev, cnt_idx, NULL);
17986 : 0 : qc->hits_set = 1;
17987 : 0 : qc->bytes_set = 1;
17988 : 0 : qc->hits = pkts - cnt->hits;
17989 : 0 : qc->bytes = bytes - cnt->bytes;
17990 [ # # ]: 0 : if (qc->reset) {
17991 : 0 : cnt->hits = pkts;
17992 : 0 : cnt->bytes = bytes;
17993 : : }
17994 : 0 : return 0;
17995 : : }
17996 : 0 : return rte_flow_error_set(error, EINVAL,
17997 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17998 : : NULL,
17999 : : "counters are not available");
18000 : : }
18001 : :
18002 : : int
18003 : 0 : flow_dv_action_query(struct rte_eth_dev *dev,
18004 : : const struct rte_flow_action_handle *handle, void *data,
18005 : : struct rte_flow_error *error)
18006 : : {
18007 : : struct mlx5_age_param *age_param;
18008 : : struct rte_flow_query_age *resp;
18009 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
18010 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
18011 : 0 : uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
18012 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18013 : : struct mlx5_aso_ct_action *ct;
18014 : : uint16_t owner;
18015 : : uint32_t dev_idx;
18016 : :
18017 [ # # # # ]: 0 : switch (type) {
18018 : 0 : case MLX5_INDIRECT_ACTION_TYPE_AGE:
18019 : 0 : age_param = &flow_aso_age_get_by_idx(dev, idx)->age_params;
18020 : : resp = data;
18021 : 0 : resp->aged = rte_atomic_load_explicit(&age_param->state,
18022 : : rte_memory_order_relaxed) == AGE_TMOUT ?
18023 : 0 : 1 : 0;
18024 : 0 : resp->sec_since_last_hit_valid = !resp->aged;
18025 [ # # ]: 0 : if (resp->sec_since_last_hit_valid)
18026 : 0 : resp->sec_since_last_hit = rte_atomic_load_explicit
18027 : : (&age_param->sec_since_last_hit, rte_memory_order_relaxed);
18028 : : return 0;
18029 : 0 : case MLX5_INDIRECT_ACTION_TYPE_COUNT:
18030 : 0 : return flow_dv_query_count(dev, idx, data, error);
18031 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
18032 : 0 : owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(idx);
18033 [ # # ]: 0 : if (owner != PORT_ID(priv))
18034 : 0 : return rte_flow_error_set(error, EACCES,
18035 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18036 : : NULL,
18037 : : "CT object owned by another port");
18038 : 0 : dev_idx = MLX5_INDIRECT_ACT_CT_GET_IDX(idx);
18039 : 0 : ct = flow_aso_ct_get_by_dev_idx(dev, dev_idx);
18040 : : MLX5_ASSERT(ct);
18041 [ # # ]: 0 : if (!ct->refcnt)
18042 : 0 : return rte_flow_error_set(error, EFAULT,
18043 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18044 : : NULL,
18045 : : "CT object is inactive");
18046 : 0 : ((struct rte_flow_action_conntrack *)data)->peer_port =
18047 : 0 : ct->peer;
18048 : 0 : ((struct rte_flow_action_conntrack *)data)->is_original_dir =
18049 : 0 : ct->is_original;
18050 [ # # ]: 0 : if (mlx5_aso_ct_query_by_wqe(priv->sh, MLX5_HW_INV_QUEUE, ct,
18051 : : data, NULL, true))
18052 : 0 : return rte_flow_error_set(error, EIO,
18053 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18054 : : NULL,
18055 : : "Failed to query CT context");
18056 : : return 0;
18057 : 0 : default:
18058 : 0 : return rte_flow_error_set(error, ENOTSUP,
18059 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
18060 : : "action type query not supported");
18061 : : }
18062 : : }
18063 : :
18064 : : /**
18065 : : * Query a flow rule AGE action for aging information.
18066 : : *
18067 : : * @param[in] dev
18068 : : * Pointer to Ethernet device.
18069 : : * @param[in] flow
18070 : : * Pointer to the sub flow.
18071 : : * @param[out] data
18072 : : * data retrieved by the query.
18073 : : * @param[out] error
18074 : : * Perform verbose error reporting if not NULL.
18075 : : *
18076 : : * @return
18077 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
18078 : : */
18079 : : static int
18080 : 0 : flow_dv_query_age(struct rte_eth_dev *dev, struct rte_flow *flow,
18081 : : void *data, struct rte_flow_error *error)
18082 : : {
18083 : : struct rte_flow_query_age *resp = data;
18084 : : struct mlx5_age_param *age_param;
18085 : :
18086 [ # # ]: 0 : if (flow->age) {
18087 : : struct mlx5_aso_age_action *act =
18088 : 0 : flow_aso_age_get_by_idx(dev, flow->age);
18089 : :
18090 : 0 : age_param = &act->age_params;
18091 [ # # ]: 0 : } else if (flow->counter) {
18092 : : age_param = flow_dv_counter_idx_get_age(dev, flow->counter);
18093 : :
18094 [ # # ]: 0 : if (!age_param || !age_param->timeout)
18095 : 0 : return rte_flow_error_set
18096 : : (error, EINVAL,
18097 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18098 : : NULL, "cannot read age data");
18099 : : } else {
18100 : 0 : return rte_flow_error_set(error, EINVAL,
18101 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18102 : : NULL, "age data not available");
18103 : : }
18104 : 0 : resp->aged = rte_atomic_load_explicit(&age_param->state, rte_memory_order_relaxed) ==
18105 : 0 : AGE_TMOUT ? 1 : 0;
18106 : 0 : resp->sec_since_last_hit_valid = !resp->aged;
18107 [ # # ]: 0 : if (resp->sec_since_last_hit_valid)
18108 : 0 : resp->sec_since_last_hit = rte_atomic_load_explicit
18109 : : (&age_param->sec_since_last_hit, rte_memory_order_relaxed);
18110 : : return 0;
18111 : : }
18112 : :
18113 : : /**
18114 : : * Query a flow.
18115 : : *
18116 : : * @see rte_flow_query()
18117 : : * @see rte_flow_ops
18118 : : */
18119 : : static int
18120 : 0 : flow_dv_query(struct rte_eth_dev *dev,
18121 : : struct rte_flow *flow __rte_unused,
18122 : : const struct rte_flow_action *actions __rte_unused,
18123 : : void *data __rte_unused,
18124 : : struct rte_flow_error *error __rte_unused)
18125 : : {
18126 : : int ret = -EINVAL;
18127 : :
18128 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
18129 [ # # # # ]: 0 : switch (actions->type) {
18130 : : case RTE_FLOW_ACTION_TYPE_VOID:
18131 : : break;
18132 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
18133 : 0 : ret = flow_dv_query_count(dev, flow->counter, data,
18134 : : error);
18135 : 0 : break;
18136 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
18137 : 0 : ret = flow_dv_query_age(dev, flow, data, error);
18138 : 0 : break;
18139 : 0 : default:
18140 : 0 : return rte_flow_error_set(error, ENOTSUP,
18141 : : RTE_FLOW_ERROR_TYPE_ACTION,
18142 : : actions,
18143 : : "action not supported");
18144 : : }
18145 : : }
18146 : : return ret;
18147 : : }
18148 : :
18149 : : /**
18150 : : * Destroy the meter table set.
18151 : : * Lock free, (mutex should be acquired by caller).
18152 : : *
18153 : : * @param[in] dev
18154 : : * Pointer to Ethernet device.
18155 : : * @param[in] fm
18156 : : * Meter information table.
18157 : : */
18158 : : static void
18159 : 0 : flow_dv_destroy_mtr_tbls(struct rte_eth_dev *dev,
18160 : : struct mlx5_flow_meter_info *fm)
18161 : : {
18162 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18163 : : int i;
18164 : :
18165 [ # # # # ]: 0 : if (!fm || !priv->sh->config.dv_flow_en)
18166 : : return;
18167 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
18168 [ # # ]: 0 : if (fm->drop_rule[i]) {
18169 : : claim_zero(mlx5_flow_os_destroy_flow(fm->drop_rule[i]));
18170 : 0 : fm->drop_rule[i] = NULL;
18171 : : }
18172 : : }
18173 : : }
18174 : :
18175 : : static void
18176 : 0 : flow_dv_destroy_mtr_drop_tbls(struct rte_eth_dev *dev)
18177 : : {
18178 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18179 : 0 : struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
18180 : : struct mlx5_flow_tbl_data_entry *tbl;
18181 : : int i, j;
18182 : :
18183 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
18184 [ # # ]: 0 : if (mtrmng->def_rule[i]) {
18185 : : claim_zero(mlx5_flow_os_destroy_flow
18186 : : (mtrmng->def_rule[i]));
18187 : 0 : mtrmng->def_rule[i] = NULL;
18188 : : }
18189 [ # # ]: 0 : if (mtrmng->def_matcher[i]) {
18190 : 0 : tbl = container_of(mtrmng->def_matcher[i]->tbl,
18191 : : struct mlx5_flow_tbl_data_entry, tbl);
18192 : 0 : mlx5_list_unregister(tbl->matchers,
18193 : : &mtrmng->def_matcher[i]->entry);
18194 : 0 : mtrmng->def_matcher[i] = NULL;
18195 : : }
18196 [ # # ]: 0 : for (j = 0; j < MLX5_REG_BITS; j++) {
18197 [ # # ]: 0 : if (mtrmng->drop_matcher[i][j]) {
18198 : : tbl =
18199 : 0 : container_of(mtrmng->drop_matcher[i][j]->tbl,
18200 : : struct mlx5_flow_tbl_data_entry,
18201 : : tbl);
18202 : 0 : mlx5_list_unregister(tbl->matchers,
18203 : : &mtrmng->drop_matcher[i][j]->entry);
18204 : 0 : mtrmng->drop_matcher[i][j] = NULL;
18205 : : }
18206 : : }
18207 [ # # ]: 0 : if (mtrmng->drop_tbl[i]) {
18208 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev),
18209 : : mtrmng->drop_tbl[i]);
18210 : 0 : mtrmng->drop_tbl[i] = NULL;
18211 : : }
18212 : : }
18213 : 0 : }
18214 : :
18215 : : /* Number of meter flow actions, count and jump or count and drop. */
18216 : : #define METER_ACTIONS 2
18217 : :
18218 : : static void
18219 : 0 : __flow_dv_destroy_domain_def_policy(struct rte_eth_dev *dev,
18220 : : enum mlx5_meter_domain domain)
18221 : : {
18222 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18223 : 0 : struct mlx5_flow_meter_def_policy *def_policy =
18224 : 0 : priv->sh->mtrmng->def_policy[domain];
18225 : :
18226 : 0 : __flow_dv_destroy_sub_policy_rules(dev, &def_policy->sub_policy);
18227 : 0 : mlx5_free(def_policy);
18228 : 0 : priv->sh->mtrmng->def_policy[domain] = NULL;
18229 : 0 : }
18230 : :
18231 : : /**
18232 : : * Destroy the default policy table set.
18233 : : *
18234 : : * @param[in] dev
18235 : : * Pointer to Ethernet device.
18236 : : */
18237 : : static void
18238 : 0 : flow_dv_destroy_def_policy(struct rte_eth_dev *dev)
18239 : : {
18240 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18241 : : int i;
18242 : :
18243 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++)
18244 [ # # ]: 0 : if (priv->sh->mtrmng->def_policy[i])
18245 : 0 : __flow_dv_destroy_domain_def_policy(dev,
18246 : : (enum mlx5_meter_domain)i);
18247 : 0 : priv->sh->mtrmng->def_policy_id = MLX5_INVALID_POLICY_ID;
18248 : 0 : }
18249 : :
18250 : : static int
18251 : 0 : __flow_dv_create_policy_flow(struct rte_eth_dev *dev,
18252 : : uint32_t color_reg_c_idx,
18253 : : enum rte_color color, struct mlx5_flow_dv_matcher *matcher,
18254 : : int actions_n, void *actions,
18255 : : bool match_src_port, const struct rte_flow_item *item,
18256 : : void **rule, const struct rte_flow_attr *attr)
18257 : : {
18258 : : int ret;
18259 : 0 : struct mlx5_flow_dv_match_params value = {
18260 : : .size = sizeof(value.buf),
18261 : : };
18262 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18263 : : uint8_t misc_mask;
18264 : :
18265 [ # # # # ]: 0 : if (match_src_port && priv->sh->esw_mode) {
18266 [ # # # # ]: 0 : if (item && item->type == RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT)
18267 : 0 : ret = flow_dv_translate_item_represented_port(dev, value.buf,
18268 : : item, attr, MLX5_SET_MATCHER_SW_V);
18269 [ # # # # ]: 0 : else if (item && item->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR)
18270 : 0 : ret = flow_dv_translate_item_port_representor(dev, value.buf,
18271 : : MLX5_SET_MATCHER_SW_V);
18272 : : else
18273 : 0 : ret = flow_dv_translate_item_port_id(dev, value.buf,
18274 : : item, attr, MLX5_SET_MATCHER_SW_V);
18275 [ # # ]: 0 : if (ret) {
18276 : 0 : DRV_LOG(ERR, "Failed to create meter policy%d flow's"
18277 : : " value with port.", color);
18278 : 0 : return -1;
18279 : : }
18280 : : }
18281 : 0 : flow_dv_match_meta_reg(value.buf, (enum modify_reg)color_reg_c_idx,
18282 : : rte_col_2_mlx5_col(color), UINT32_MAX);
18283 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(matcher->mask.buf);
18284 : : __flow_dv_adjust_buf_size(&value.size, misc_mask);
18285 : 0 : ret = mlx5_flow_os_create_flow(matcher->matcher_object, (void *)&value,
18286 : : actions_n, actions, rule);
18287 : : if (ret) {
18288 : 0 : DRV_LOG(ERR, "Failed to create meter policy%d flow.", color);
18289 : 0 : return -1;
18290 : : }
18291 : : return 0;
18292 : : }
18293 : :
18294 : : static int
18295 : 0 : __flow_dv_create_policy_matcher(struct rte_eth_dev *dev,
18296 : : uint32_t color_reg_c_idx,
18297 : : uint16_t priority,
18298 : : struct mlx5_flow_meter_sub_policy *sub_policy,
18299 : : const struct rte_flow_attr *attr,
18300 : : bool match_src_port,
18301 : : const struct rte_flow_item *item,
18302 : : struct mlx5_flow_dv_matcher **policy_matcher,
18303 : : struct rte_flow_error *error)
18304 : : {
18305 : : struct mlx5_list_entry *entry;
18306 : 0 : struct mlx5_flow_tbl_resource *tbl_rsc = sub_policy->tbl_rsc;
18307 : 0 : struct mlx5_flow_dv_matcher matcher = {
18308 : : .mask = {
18309 : : .size = sizeof(matcher.mask.buf),
18310 : : },
18311 : : .tbl = tbl_rsc,
18312 : : };
18313 : 0 : struct mlx5_flow_cb_ctx ctx = {
18314 : : .error = error,
18315 : : .data = &matcher,
18316 : : };
18317 : : struct mlx5_flow_tbl_data_entry *tbl_data;
18318 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18319 : : const uint32_t color_mask = (UINT32_C(1) << MLX5_MTR_COLOR_BITS) - 1;
18320 : : int ret;
18321 : :
18322 [ # # # # ]: 0 : if (match_src_port && priv->sh->esw_mode) {
18323 [ # # # # ]: 0 : if (item && item->type == RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT)
18324 : 0 : ret = flow_dv_translate_item_represented_port(dev, matcher.mask.buf,
18325 : : item, attr, MLX5_SET_MATCHER_SW_M);
18326 [ # # # # ]: 0 : else if (item && item->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR)
18327 : 0 : ret = flow_dv_translate_item_port_representor(dev, matcher.mask.buf,
18328 : : MLX5_SET_MATCHER_SW_M);
18329 : : else
18330 : 0 : ret = flow_dv_translate_item_port_id(dev, matcher.mask.buf,
18331 : : item, attr, MLX5_SET_MATCHER_SW_M);
18332 [ # # ]: 0 : if (ret) {
18333 : 0 : DRV_LOG(ERR, "Failed to register meter policy%d matcher"
18334 : : " with port.", priority);
18335 : 0 : return -1;
18336 : : }
18337 : : }
18338 : 0 : tbl_data = container_of(tbl_rsc, struct mlx5_flow_tbl_data_entry, tbl);
18339 : 0 : flow_dv_match_meta_reg(matcher.mask.buf,
18340 : : (enum modify_reg)color_reg_c_idx, color_mask, color_mask);
18341 : 0 : matcher.priority = priority;
18342 : 0 : matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
18343 : : matcher.mask.size);
18344 : 0 : entry = mlx5_list_register(tbl_data->matchers, &ctx);
18345 [ # # ]: 0 : if (!entry) {
18346 : 0 : DRV_LOG(ERR, "Failed to register meter drop matcher.");
18347 : 0 : return -1;
18348 : : }
18349 : 0 : *policy_matcher =
18350 : : container_of(entry, struct mlx5_flow_dv_matcher, entry);
18351 : 0 : return 0;
18352 : : }
18353 : :
18354 : : /**
18355 : : * Create the policy rules per domain.
18356 : : *
18357 : : * @param[in] dev
18358 : : * Pointer to Ethernet device.
18359 : : * @param[in] sub_policy
18360 : : * Pointer to sub policy table..
18361 : : * @param[in] egress
18362 : : * Direction of the table.
18363 : : * @param[in] transfer
18364 : : * E-Switch or NIC flow.
18365 : : * @param[in] acts
18366 : : * Pointer to policy action list per color.
18367 : : *
18368 : : * @return
18369 : : * 0 on success, -1 otherwise.
18370 : : */
18371 : : static int
18372 : 0 : __flow_dv_create_domain_policy_rules(struct rte_eth_dev *dev,
18373 : : struct mlx5_flow_meter_sub_policy *sub_policy,
18374 : : uint8_t egress, uint8_t transfer, bool *match_src_port,
18375 : : struct mlx5_meter_policy_acts acts[RTE_COLORS])
18376 : : {
18377 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18378 : : struct rte_flow_error flow_err;
18379 : : uint32_t color_reg_c_idx;
18380 : 0 : struct rte_flow_attr attr = {
18381 : : .group = MLX5_FLOW_TABLE_LEVEL_POLICY,
18382 : : .priority = 0,
18383 : : .ingress = 0,
18384 : 0 : .egress = !!egress,
18385 : 0 : .transfer = !!transfer,
18386 : : .reserved = 0,
18387 : : };
18388 : : int i;
18389 : : uint16_t priority;
18390 : 0 : int ret = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &flow_err);
18391 : : struct mlx5_sub_policy_color_rule *color_rule;
18392 : 0 : struct mlx5_sub_policy_color_rule *tmp_rules[RTE_COLORS] = {NULL};
18393 : :
18394 [ # # ]: 0 : if (ret < 0)
18395 : : return -1;
18396 : : /* Create policy table with POLICY level. */
18397 [ # # ]: 0 : if (!sub_policy->tbl_rsc)
18398 : 0 : sub_policy->tbl_rsc = flow_dv_tbl_resource_get(dev,
18399 : : MLX5_FLOW_TABLE_LEVEL_POLICY,
18400 : : egress, transfer, false, NULL, 0, 0,
18401 : 0 : sub_policy->idx, &flow_err);
18402 [ # # ]: 0 : if (!sub_policy->tbl_rsc) {
18403 : 0 : DRV_LOG(ERR,
18404 : : "Failed to create meter sub policy table.");
18405 : 0 : return -1;
18406 : : }
18407 : : /* Prepare matchers. */
18408 : 0 : color_reg_c_idx = ret;
18409 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
18410 : 0 : TAILQ_INIT(&sub_policy->color_rules[i]);
18411 [ # # ]: 0 : if (!acts[i].actions_n)
18412 : 0 : continue;
18413 : 0 : color_rule = mlx5_malloc(MLX5_MEM_ZERO,
18414 : : sizeof(struct mlx5_sub_policy_color_rule),
18415 : : 0, SOCKET_ID_ANY);
18416 [ # # ]: 0 : if (!color_rule) {
18417 : 0 : DRV_LOG(ERR, "No memory to create color rule.");
18418 : 0 : goto err_exit;
18419 : : }
18420 : 0 : tmp_rules[i] = color_rule;
18421 : 0 : TAILQ_INSERT_TAIL(&sub_policy->color_rules[i],
18422 : : color_rule, next_port);
18423 : 0 : color_rule->src_port = priv->representor_id;
18424 : 0 : priority = (match_src_port[i] == match_src_port[RTE_COLOR_GREEN]) ?
18425 : 0 : MLX5_MTR_POLICY_MATCHER_PRIO : (MLX5_MTR_POLICY_MATCHER_PRIO + 1);
18426 : : /* Create matchers for colors. */
18427 [ # # ]: 0 : if (__flow_dv_create_policy_matcher(dev, color_reg_c_idx,
18428 : : priority, sub_policy,
18429 : : &attr, match_src_port[i], NULL,
18430 : : &color_rule->matcher, &flow_err)) {
18431 : 0 : DRV_LOG(ERR, "Failed to create color%u matcher.", i);
18432 : 0 : goto err_exit;
18433 : : }
18434 : : /* Create flow, matching color. */
18435 [ # # ]: 0 : if (__flow_dv_create_policy_flow(dev,
18436 : : color_reg_c_idx, (enum rte_color)i,
18437 : : color_rule->matcher,
18438 : 0 : acts[i].actions_n, acts[i].dv_actions,
18439 : 0 : match_src_port[i], NULL, &color_rule->rule,
18440 : : &attr)) {
18441 : 0 : DRV_LOG(ERR, "Failed to create color%u rule.", i);
18442 : 0 : goto err_exit;
18443 : : }
18444 : : }
18445 : : return 0;
18446 : : err_exit:
18447 : : /* All the policy rules will be cleared. */
18448 : : do {
18449 : 0 : color_rule = tmp_rules[i];
18450 [ # # ]: 0 : if (color_rule) {
18451 [ # # ]: 0 : if (color_rule->rule)
18452 : : mlx5_flow_os_destroy_flow(color_rule->rule);
18453 [ # # ]: 0 : if (color_rule->matcher) {
18454 : : struct mlx5_flow_tbl_data_entry *tbl =
18455 : 0 : container_of(color_rule->matcher->tbl,
18456 : : typeof(*tbl), tbl);
18457 : 0 : mlx5_list_unregister(tbl->matchers,
18458 : : &color_rule->matcher->entry);
18459 : : }
18460 [ # # ]: 0 : TAILQ_REMOVE(&sub_policy->color_rules[i],
18461 : : color_rule, next_port);
18462 : 0 : mlx5_free(color_rule);
18463 : : }
18464 [ # # ]: 0 : } while (i--);
18465 : : return -1;
18466 : : }
18467 : :
18468 : : static int
18469 : 0 : __flow_dv_create_policy_acts_rules(struct rte_eth_dev *dev,
18470 : : struct mlx5_flow_meter_policy *mtr_policy,
18471 : : struct mlx5_flow_meter_sub_policy *sub_policy,
18472 : : uint32_t domain)
18473 : : {
18474 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18475 : : struct mlx5_meter_policy_acts acts[RTE_COLORS];
18476 : : struct mlx5_flow_dv_tag_resource *tag;
18477 : : struct mlx5_flow_dv_port_id_action_resource *port_action;
18478 : : struct mlx5_hrxq *hrxq;
18479 : 0 : struct mlx5_flow_meter_info *next_fm[RTE_COLORS] = {NULL};
18480 : : struct mlx5_flow_meter_policy *next_policy;
18481 : : struct mlx5_flow_meter_sub_policy *next_sub_policy;
18482 : : struct mlx5_flow_tbl_data_entry *tbl_data;
18483 : : struct rte_flow_error error;
18484 : 0 : uint8_t egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
18485 : 0 : uint8_t transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
18486 [ # # # # : 0 : bool mtr_first = egress || (transfer && priv->representor_id != UINT16_MAX);
# # ]
18487 : 0 : bool match_src_port[RTE_COLORS] = {false};
18488 : : int i;
18489 : :
18490 : : /* If RSS or Queue, no previous actions / rules is created. */
18491 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
18492 : 0 : acts[i].actions_n = 0;
18493 [ # # ]: 0 : if (i == RTE_COLOR_RED) {
18494 : : /* Only support drop on red. */
18495 : 0 : acts[i].dv_actions[0] =
18496 : 0 : mtr_policy->dr_drop_action[domain];
18497 : 0 : acts[i].actions_n = 1;
18498 : 0 : continue;
18499 : : }
18500 [ # # ]: 0 : if (mtr_policy->act_cnt[i].fate_action == MLX5_FLOW_FATE_MTR) {
18501 : 0 : struct rte_flow_attr attr = {
18502 : : .transfer = transfer
18503 : : };
18504 : :
18505 : 0 : next_fm[i] = mlx5_flow_meter_find(priv,
18506 : : mtr_policy->act_cnt[i].next_mtr_id,
18507 : : NULL);
18508 [ # # ]: 0 : if (!next_fm[i]) {
18509 : 0 : DRV_LOG(ERR,
18510 : : "Failed to get next hierarchy meter.");
18511 : 0 : goto err_exit;
18512 : : }
18513 [ # # ]: 0 : if (mlx5_flow_meter_attach(priv, next_fm[i],
18514 : : &attr, &error)) {
18515 : 0 : DRV_LOG(ERR, "%s", error.message);
18516 : 0 : next_fm[i] = NULL;
18517 : 0 : goto err_exit;
18518 : : }
18519 : : /* Meter action must be the first for TX. */
18520 [ # # ]: 0 : if (mtr_first) {
18521 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18522 [ # # ]: 0 : (next_fm[i]->color_aware && i == RTE_COLOR_YELLOW) ?
18523 [ # # ]: 0 : next_fm[i]->meter_action_y :
18524 : : next_fm[i]->meter_action_g;
18525 : 0 : acts[i].actions_n++;
18526 : : }
18527 : : }
18528 [ # # ]: 0 : if (mtr_policy->act_cnt[i].rix_mark) {
18529 : 0 : tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG],
18530 : : mtr_policy->act_cnt[i].rix_mark);
18531 [ # # ]: 0 : if (!tag) {
18532 : 0 : DRV_LOG(ERR, "Failed to find "
18533 : : "mark action for policy.");
18534 : 0 : goto err_exit;
18535 : : }
18536 : 0 : acts[i].dv_actions[acts[i].actions_n] = tag->action;
18537 : 0 : acts[i].actions_n++;
18538 : : }
18539 [ # # ]: 0 : if (mtr_policy->act_cnt[i].modify_hdr) {
18540 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18541 : 0 : mtr_policy->act_cnt[i].modify_hdr->action;
18542 : 0 : acts[i].actions_n++;
18543 : : }
18544 [ # # ]: 0 : if (mtr_policy->act_cnt[i].fate_action) {
18545 [ # # # # : 0 : switch (mtr_policy->act_cnt[i].fate_action) {
# ]
18546 : 0 : case MLX5_FLOW_FATE_PORT_ID:
18547 : 0 : port_action = mlx5_ipool_get
18548 : 0 : (priv->sh->ipool[MLX5_IPOOL_PORT_ID],
18549 : : mtr_policy->act_cnt[i].rix_port_id_action);
18550 [ # # ]: 0 : if (!port_action) {
18551 : 0 : DRV_LOG(ERR, "Failed to find "
18552 : : "port action for policy.");
18553 : 0 : goto err_exit;
18554 : : }
18555 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18556 : 0 : port_action->action;
18557 : 0 : acts[i].actions_n++;
18558 : 0 : match_src_port[i] = true;
18559 : 0 : break;
18560 : 0 : case MLX5_FLOW_FATE_DROP:
18561 : : case MLX5_FLOW_FATE_JUMP:
18562 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18563 : 0 : mtr_policy->act_cnt[i].dr_jump_action[domain];
18564 : 0 : acts[i].actions_n++;
18565 : 0 : break;
18566 : 0 : case MLX5_FLOW_FATE_SHARED_RSS:
18567 : : case MLX5_FLOW_FATE_QUEUE:
18568 : 0 : hrxq = mlx5_ipool_get
18569 : 0 : (priv->sh->ipool[MLX5_IPOOL_HRXQ],
18570 : : sub_policy->rix_hrxq[i]);
18571 [ # # ]: 0 : if (!hrxq) {
18572 : 0 : DRV_LOG(ERR, "Failed to find "
18573 : : "queue action for policy.");
18574 : 0 : goto err_exit;
18575 : : }
18576 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18577 : 0 : hrxq->action;
18578 : 0 : acts[i].actions_n++;
18579 : 0 : break;
18580 : 0 : case MLX5_FLOW_FATE_MTR:
18581 [ # # ]: 0 : if (!next_fm[i]) {
18582 : 0 : DRV_LOG(ERR,
18583 : : "No next hierarchy meter.");
18584 : 0 : goto err_exit;
18585 : : }
18586 [ # # ]: 0 : if (!mtr_first) {
18587 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18588 [ # # ]: 0 : (next_fm[i]->color_aware && i == RTE_COLOR_YELLOW) ?
18589 [ # # ]: 0 : next_fm[i]->meter_action_y :
18590 : : next_fm[i]->meter_action_g;
18591 : 0 : acts[i].actions_n++;
18592 : : }
18593 [ # # ]: 0 : if (mtr_policy->act_cnt[i].next_sub_policy) {
18594 : : next_sub_policy =
18595 : : mtr_policy->act_cnt[i].next_sub_policy;
18596 : : } else {
18597 : : next_policy =
18598 : 0 : mlx5_flow_meter_policy_find(dev,
18599 : : next_fm[i]->policy_id, NULL);
18600 : : MLX5_ASSERT(next_policy);
18601 : 0 : next_sub_policy =
18602 : 0 : next_policy->sub_policys[domain][0];
18603 : : }
18604 : : tbl_data =
18605 : 0 : container_of(next_sub_policy->tbl_rsc,
18606 : : struct mlx5_flow_tbl_data_entry, tbl);
18607 : 0 : acts[i].dv_actions[acts[i].actions_n++] =
18608 : 0 : tbl_data->jump.action;
18609 [ # # ]: 0 : if (mtr_policy->act_cnt[i].modify_hdr)
18610 : 0 : match_src_port[i] = !!transfer;
18611 : : break;
18612 : : default:
18613 : : /*Queue action do nothing*/
18614 : : break;
18615 : : }
18616 : : }
18617 : : }
18618 [ # # ]: 0 : if (__flow_dv_create_domain_policy_rules(dev, sub_policy,
18619 : : egress, transfer, match_src_port, acts)) {
18620 : 0 : DRV_LOG(ERR,
18621 : : "Failed to create policy rules per domain.");
18622 : 0 : goto err_exit;
18623 : : }
18624 [ # # # # ]: 0 : if (match_src_port[RTE_COLOR_GREEN] || match_src_port[RTE_COLOR_YELLOW]) {
18625 : 0 : mtr_policy->match_port = 1;
18626 : 0 : mtr_policy->hierarchy_match_port = 1;
18627 : : }
18628 : : return 0;
18629 : : err_exit:
18630 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++)
18631 [ # # ]: 0 : if (next_fm[i])
18632 : 0 : mlx5_flow_meter_detach(priv, next_fm[i]);
18633 : : return -1;
18634 : : }
18635 : :
18636 : : /**
18637 : : * Create the policy rules.
18638 : : *
18639 : : * @param[in] dev
18640 : : * Pointer to Ethernet device.
18641 : : * @param[in,out] mtr_policy
18642 : : * Pointer to meter policy table.
18643 : : *
18644 : : * @return
18645 : : * 0 on success, -1 otherwise.
18646 : : */
18647 : : static int
18648 : 0 : flow_dv_create_policy_rules(struct rte_eth_dev *dev,
18649 : : struct mlx5_flow_meter_policy *mtr_policy)
18650 : : {
18651 : : int i;
18652 : : int ret = 0;
18653 : : uint16_t sub_policy_num;
18654 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_push_thread_workspace();
18655 : :
18656 : : RTE_SET_USED(wks);
18657 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
18658 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
18659 : 0 : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
18660 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
18661 [ # # ]: 0 : if (!sub_policy_num)
18662 : 0 : continue;
18663 : : /* Prepare actions list and create policy rules. */
18664 [ # # ]: 0 : if (__flow_dv_create_policy_acts_rules(dev, mtr_policy,
18665 : 0 : mtr_policy->sub_policys[i][0], i)) {
18666 : 0 : DRV_LOG(ERR, "Failed to create policy action "
18667 : : "list per domain.");
18668 : : ret = -1;
18669 : 0 : goto exit;
18670 : : }
18671 : : }
18672 : 0 : exit:
18673 : 0 : mlx5_flow_pop_thread_workspace();
18674 : 0 : return ret;
18675 : : }
18676 : :
18677 : : static int
18678 : 0 : __flow_dv_create_domain_def_policy(struct rte_eth_dev *dev, uint32_t domain)
18679 : : {
18680 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18681 : 0 : struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
18682 : : struct mlx5_flow_meter_def_policy *def_policy;
18683 : : struct mlx5_flow_tbl_resource *jump_tbl;
18684 : : struct mlx5_flow_tbl_data_entry *tbl_data;
18685 : : uint8_t egress, transfer;
18686 : : struct rte_flow_error error;
18687 : : struct mlx5_meter_policy_acts acts[RTE_COLORS];
18688 : 0 : bool match_src_port[RTE_COLORS] = {false};
18689 : : int ret;
18690 : :
18691 : 0 : egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
18692 : 0 : transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
18693 : 0 : def_policy = mtrmng->def_policy[domain];
18694 [ # # ]: 0 : if (!def_policy) {
18695 : 0 : def_policy = mlx5_malloc(MLX5_MEM_ZERO,
18696 : : sizeof(struct mlx5_flow_meter_def_policy),
18697 : : RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
18698 [ # # ]: 0 : if (!def_policy) {
18699 : 0 : DRV_LOG(ERR, "Failed to alloc default policy table.");
18700 : 0 : goto def_policy_error;
18701 : : }
18702 : 0 : mtrmng->def_policy[domain] = def_policy;
18703 : : /* Create the meter suffix table with SUFFIX level. */
18704 : 0 : jump_tbl = flow_dv_tbl_resource_get(dev,
18705 : : MLX5_FLOW_TABLE_LEVEL_METER,
18706 : : egress, transfer, false, NULL, 0,
18707 : : 0, MLX5_MTR_TABLE_ID_SUFFIX, &error);
18708 [ # # ]: 0 : if (!jump_tbl) {
18709 : 0 : DRV_LOG(ERR,
18710 : : "Failed to create meter suffix table.");
18711 : 0 : goto def_policy_error;
18712 : : }
18713 : 0 : def_policy->sub_policy.jump_tbl[RTE_COLOR_GREEN] = jump_tbl;
18714 : 0 : tbl_data = container_of(jump_tbl,
18715 : : struct mlx5_flow_tbl_data_entry, tbl);
18716 : 0 : def_policy->dr_jump_action[RTE_COLOR_GREEN] =
18717 : 0 : tbl_data->jump.action;
18718 : 0 : acts[RTE_COLOR_GREEN].dv_actions[0] = tbl_data->jump.action;
18719 : 0 : acts[RTE_COLOR_GREEN].actions_n = 1;
18720 : : /*
18721 : : * YELLOW has the same default policy as GREEN does.
18722 : : * G & Y share the same table and action. The 2nd time of table
18723 : : * resource getting is just to update the reference count for
18724 : : * the releasing stage.
18725 : : */
18726 : 0 : jump_tbl = flow_dv_tbl_resource_get(dev,
18727 : : MLX5_FLOW_TABLE_LEVEL_METER,
18728 : : egress, transfer, false, NULL, 0,
18729 : : 0, MLX5_MTR_TABLE_ID_SUFFIX, &error);
18730 [ # # ]: 0 : if (!jump_tbl) {
18731 : 0 : DRV_LOG(ERR,
18732 : : "Failed to get meter suffix table.");
18733 : 0 : goto def_policy_error;
18734 : : }
18735 : 0 : def_policy->sub_policy.jump_tbl[RTE_COLOR_YELLOW] = jump_tbl;
18736 : 0 : tbl_data = container_of(jump_tbl,
18737 : : struct mlx5_flow_tbl_data_entry, tbl);
18738 : 0 : def_policy->dr_jump_action[RTE_COLOR_YELLOW] =
18739 : 0 : tbl_data->jump.action;
18740 : 0 : acts[RTE_COLOR_YELLOW].dv_actions[0] = tbl_data->jump.action;
18741 : 0 : acts[RTE_COLOR_YELLOW].actions_n = 1;
18742 : : /* Create jump action to the drop table. */
18743 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
18744 : 0 : mtrmng->drop_tbl[domain] = flow_dv_tbl_resource_get
18745 : : (dev, MLX5_FLOW_TABLE_LEVEL_METER,
18746 : : egress, transfer, false, NULL, 0,
18747 : : 0, MLX5_MTR_TABLE_ID_DROP, &error);
18748 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
18749 : 0 : DRV_LOG(ERR, "Failed to create meter "
18750 : : "drop table for default policy.");
18751 : 0 : goto def_policy_error;
18752 : : }
18753 : : }
18754 : : /* all RED: unique Drop table for jump action. */
18755 : 0 : tbl_data = container_of(mtrmng->drop_tbl[domain],
18756 : : struct mlx5_flow_tbl_data_entry, tbl);
18757 : 0 : def_policy->dr_jump_action[RTE_COLOR_RED] =
18758 : 0 : tbl_data->jump.action;
18759 : 0 : acts[RTE_COLOR_RED].dv_actions[0] = tbl_data->jump.action;
18760 : 0 : acts[RTE_COLOR_RED].actions_n = 1;
18761 : : /* Create default policy rules. */
18762 : 0 : ret = __flow_dv_create_domain_policy_rules(dev,
18763 : : &def_policy->sub_policy,
18764 : : egress, transfer, match_src_port, acts);
18765 [ # # ]: 0 : if (ret) {
18766 : 0 : DRV_LOG(ERR, "Failed to create default policy rules.");
18767 : 0 : goto def_policy_error;
18768 : : }
18769 : : }
18770 : : return 0;
18771 : 0 : def_policy_error:
18772 : 0 : __flow_dv_destroy_domain_def_policy(dev,
18773 : : (enum mlx5_meter_domain)domain);
18774 : 0 : return -1;
18775 : : }
18776 : :
18777 : : /**
18778 : : * Create the default policy table set.
18779 : : *
18780 : : * @param[in] dev
18781 : : * Pointer to Ethernet device.
18782 : : * @return
18783 : : * 0 on success, -1 otherwise.
18784 : : */
18785 : : static int
18786 : 0 : flow_dv_create_def_policy(struct rte_eth_dev *dev)
18787 : : {
18788 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18789 : : int i;
18790 : :
18791 : : /* Non-termination policy table. */
18792 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
18793 [ # # # # ]: 0 : if (!priv->sh->config.dv_esw_en &&
18794 : : i == MLX5_MTR_DOMAIN_TRANSFER)
18795 : 0 : continue;
18796 [ # # ]: 0 : if (__flow_dv_create_domain_def_policy(dev, i)) {
18797 : 0 : DRV_LOG(ERR, "Failed to create default policy");
18798 : : /* Rollback the created default policies for others. */
18799 : 0 : flow_dv_destroy_def_policy(dev);
18800 : 0 : return -1;
18801 : : }
18802 : : }
18803 : : return 0;
18804 : : }
18805 : :
18806 : : /**
18807 : : * Create the needed meter tables.
18808 : : * Lock free, (mutex should be acquired by caller).
18809 : : *
18810 : : * @param[in] dev
18811 : : * Pointer to Ethernet device.
18812 : : * @param[in] fm
18813 : : * Meter information table.
18814 : : * @param[in] mtr_idx
18815 : : * Meter index.
18816 : : * @param[in] domain_bitmap
18817 : : * Domain bitmap.
18818 : : * @return
18819 : : * 0 on success, -1 otherwise.
18820 : : */
18821 : : static int
18822 : 0 : flow_dv_create_mtr_tbls(struct rte_eth_dev *dev,
18823 : : struct mlx5_flow_meter_info *fm,
18824 : : uint32_t mtr_idx,
18825 : : uint8_t domain_bitmap)
18826 : : {
18827 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18828 : 0 : struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
18829 : : struct rte_flow_error error;
18830 : : struct mlx5_flow_tbl_data_entry *tbl_data;
18831 : : uint8_t egress, transfer;
18832 : : void *actions[METER_ACTIONS];
18833 : : int domain, ret, i;
18834 : : struct mlx5_flow_counter *cnt;
18835 : 0 : struct mlx5_flow_dv_match_params value = {
18836 : : .size = sizeof(value.buf),
18837 : : };
18838 : 0 : struct mlx5_flow_dv_match_params matcher_para = {
18839 : : .size = sizeof(matcher_para.buf),
18840 : : };
18841 : 0 : int mtr_id_reg_c = mlx5_flow_get_reg_id(dev, MLX5_MTR_ID,
18842 : : 0, &error);
18843 : 0 : uint32_t mtr_id_mask = (UINT32_C(1) << mtrmng->max_mtr_bits) - 1;
18844 : 0 : uint8_t mtr_id_offset = priv->mtr_reg_share ? MLX5_MTR_COLOR_BITS : 0;
18845 : : struct mlx5_list_entry *entry;
18846 : 0 : struct mlx5_flow_dv_matcher matcher = {
18847 : : .mask = {
18848 : : .size = sizeof(matcher.mask.buf),
18849 : : },
18850 : : };
18851 : : struct mlx5_flow_dv_matcher *drop_matcher;
18852 : 0 : struct mlx5_flow_cb_ctx ctx = {
18853 : : .error = &error,
18854 : : .data = &matcher,
18855 : : };
18856 : : uint8_t misc_mask;
18857 : :
18858 [ # # # # ]: 0 : if (!priv->mtr_en || mtr_id_reg_c < 0) {
18859 : 0 : rte_errno = ENOTSUP;
18860 : 0 : return -1;
18861 : : }
18862 [ # # ]: 0 : for (domain = 0; domain < MLX5_MTR_DOMAIN_MAX; domain++) {
18863 [ # # ]: 0 : if (!(domain_bitmap & (1 << domain)) ||
18864 [ # # # # ]: 0 : (mtrmng->def_rule[domain] && !fm->drop_cnt))
18865 : 0 : continue;
18866 : 0 : egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
18867 : 0 : transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
18868 : : /* Create the drop table with METER DROP level. */
18869 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
18870 : 0 : mtrmng->drop_tbl[domain] = flow_dv_tbl_resource_get(dev,
18871 : : MLX5_FLOW_TABLE_LEVEL_METER,
18872 : : egress, transfer, false, NULL, 0,
18873 : : 0, MLX5_MTR_TABLE_ID_DROP, &error);
18874 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
18875 : 0 : DRV_LOG(ERR, "Failed to create meter drop table.");
18876 : 0 : goto policy_error;
18877 : : }
18878 : : }
18879 : : /* Create default matcher in drop table. */
18880 : 0 : matcher.tbl = mtrmng->drop_tbl[domain],
18881 : 0 : tbl_data = container_of(mtrmng->drop_tbl[domain],
18882 : : struct mlx5_flow_tbl_data_entry, tbl);
18883 [ # # ]: 0 : if (!mtrmng->def_matcher[domain]) {
18884 : 0 : flow_dv_match_meta_reg_all(matcher.mask.buf, value.buf,
18885 : : (enum modify_reg)mtr_id_reg_c,
18886 : : 0, 0);
18887 : 0 : matcher.priority = MLX5_MTRS_DEFAULT_RULE_PRIORITY;
18888 : 0 : matcher.crc = rte_raw_cksum
18889 : : ((const void *)matcher.mask.buf,
18890 : : matcher.mask.size);
18891 : 0 : entry = mlx5_list_register(tbl_data->matchers, &ctx);
18892 [ # # ]: 0 : if (!entry) {
18893 : 0 : DRV_LOG(ERR, "Failed to register meter "
18894 : : "drop default matcher.");
18895 : 0 : goto policy_error;
18896 : : }
18897 : 0 : mtrmng->def_matcher[domain] = container_of(entry,
18898 : : struct mlx5_flow_dv_matcher, entry);
18899 : : }
18900 : : /* Create default rule in drop table. */
18901 [ # # ]: 0 : if (!mtrmng->def_rule[domain]) {
18902 : : i = 0;
18903 : 0 : actions[i++] = priv->sh->dr_drop_action;
18904 : 0 : flow_dv_match_meta_reg_all(matcher_para.buf, value.buf,
18905 : : (enum modify_reg)mtr_id_reg_c, 0, 0);
18906 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(mtrmng->def_matcher[domain]->mask.buf);
18907 : : __flow_dv_adjust_buf_size(&value.size, misc_mask);
18908 : 0 : ret = mlx5_flow_os_create_flow
18909 : : (mtrmng->def_matcher[domain]->matcher_object,
18910 : : (void *)&value, i, actions,
18911 : : &mtrmng->def_rule[domain]);
18912 : : if (ret) {
18913 : 0 : DRV_LOG(ERR, "Failed to create meter "
18914 : : "default drop rule for drop table.");
18915 : 0 : goto policy_error;
18916 : : }
18917 : : }
18918 [ # # ]: 0 : if (!fm->drop_cnt)
18919 : 0 : continue;
18920 : : MLX5_ASSERT(mtrmng->max_mtr_bits);
18921 [ # # ]: 0 : if (!mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1]) {
18922 : : /* Create matchers for Drop. */
18923 : 0 : flow_dv_match_meta_reg_all(matcher.mask.buf, value.buf,
18924 : : (enum modify_reg)mtr_id_reg_c, 0,
18925 : : (mtr_id_mask << mtr_id_offset));
18926 : 0 : matcher.priority = MLX5_REG_BITS - mtrmng->max_mtr_bits;
18927 : 0 : matcher.crc = rte_raw_cksum
18928 : : ((const void *)matcher.mask.buf,
18929 : : matcher.mask.size);
18930 : 0 : entry = mlx5_list_register(tbl_data->matchers, &ctx);
18931 [ # # ]: 0 : if (!entry) {
18932 : 0 : DRV_LOG(ERR,
18933 : : "Failed to register meter drop matcher.");
18934 : 0 : goto policy_error;
18935 : : }
18936 : 0 : mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1] =
18937 : : container_of(entry, struct mlx5_flow_dv_matcher,
18938 : : entry);
18939 : : }
18940 : 0 : drop_matcher =
18941 : 0 : mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1];
18942 : : /* Create drop rule, matching meter_id only. */
18943 : 0 : flow_dv_match_meta_reg_all(matcher_para.buf, value.buf,
18944 : : (enum modify_reg)mtr_id_reg_c,
18945 : : (mtr_idx << mtr_id_offset), UINT32_MAX);
18946 : : i = 0;
18947 [ # # ]: 0 : cnt = flow_dv_counter_get_by_idx(dev,
18948 : : fm->drop_cnt, NULL);
18949 : 0 : actions[i++] = cnt->action;
18950 : 0 : actions[i++] = priv->sh->dr_drop_action;
18951 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(drop_matcher->mask.buf);
18952 : : __flow_dv_adjust_buf_size(&value.size, misc_mask);
18953 : 0 : ret = mlx5_flow_os_create_flow(drop_matcher->matcher_object,
18954 : : (void *)&value, i, actions,
18955 : : &fm->drop_rule[domain]);
18956 : : if (ret) {
18957 : 0 : DRV_LOG(ERR, "Failed to create meter "
18958 : : "drop rule for drop table.");
18959 : 0 : goto policy_error;
18960 : : }
18961 : : }
18962 : : return 0;
18963 : : policy_error:
18964 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
18965 [ # # ]: 0 : if (fm->drop_rule[i]) {
18966 : : claim_zero(mlx5_flow_os_destroy_flow
18967 : : (fm->drop_rule[i]));
18968 : 0 : fm->drop_rule[i] = NULL;
18969 : : }
18970 : : }
18971 : : return -1;
18972 : : }
18973 : :
18974 : : static struct mlx5_flow_meter_sub_policy *
18975 : 0 : __flow_dv_meter_get_rss_sub_policy(struct rte_eth_dev *dev,
18976 : : struct mlx5_flow_meter_policy *mtr_policy,
18977 : : struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS],
18978 : : struct mlx5_flow_meter_sub_policy *next_sub_policy,
18979 : : bool *is_reuse)
18980 : : {
18981 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18982 : : struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
18983 : 0 : uint32_t sub_policy_idx = 0;
18984 : 0 : uint32_t hrxq_idx[MLX5_MTR_RTE_COLORS] = {0};
18985 : : uint32_t i, j;
18986 : : struct mlx5_hrxq *hrxq;
18987 : : struct mlx5_flow_handle dh;
18988 : : struct mlx5_meter_policy_action_container *act_cnt;
18989 : : uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
18990 : : uint16_t sub_policy_num;
18991 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
18992 : :
18993 : : MLX5_ASSERT(wks);
18994 : 0 : rte_spinlock_lock(&mtr_policy->sl);
18995 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
18996 [ # # ]: 0 : if (!rss_desc[i])
18997 : 0 : continue;
18998 : 0 : hrxq = mlx5_hrxq_get(dev, rss_desc[i]);
18999 [ # # ]: 0 : if (!hrxq) {
19000 : : rte_spinlock_unlock(&mtr_policy->sl);
19001 : 0 : return NULL;
19002 : : }
19003 : 0 : hrxq_idx[i] = hrxq->idx;
19004 : : }
19005 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
19006 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
19007 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
19008 [ # # ]: 0 : for (j = 0; j < sub_policy_num; j++) {
19009 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
19010 [ # # ]: 0 : if (rss_desc[i] &&
19011 : 0 : hrxq_idx[i] !=
19012 [ # # ]: 0 : mtr_policy->sub_policys[domain][j]->rix_hrxq[i])
19013 : : break;
19014 : : }
19015 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS) {
19016 : : /*
19017 : : * Found the sub policy table with
19018 : : * the same queue per color.
19019 : : */
19020 : : rte_spinlock_unlock(&mtr_policy->sl);
19021 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++)
19022 : 0 : mlx5_hrxq_release(dev, hrxq_idx[i]);
19023 : 0 : *is_reuse = true;
19024 : 0 : return mtr_policy->sub_policys[domain][j];
19025 : : }
19026 : : }
19027 : : /* Create sub policy. */
19028 [ # # ]: 0 : if (!mtr_policy->sub_policys[domain][0]->rix_hrxq[RTE_COLOR_GREEN] &&
19029 : : !mtr_policy->sub_policys[domain][0]->rix_hrxq[RTE_COLOR_YELLOW]) {
19030 : : /* Reuse the first pre-allocated sub_policy. */
19031 : : sub_policy = mtr_policy->sub_policys[domain][0];
19032 : 0 : sub_policy_idx = sub_policy->idx;
19033 : : } else {
19034 : 0 : sub_policy = mlx5_ipool_zmalloc
19035 : 0 : (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
19036 : : &sub_policy_idx);
19037 [ # # ]: 0 : if (!sub_policy ||
19038 [ # # ]: 0 : sub_policy_idx > MLX5_MAX_SUB_POLICY_TBL_NUM) {
19039 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++)
19040 : 0 : mlx5_hrxq_release(dev, hrxq_idx[i]);
19041 : 0 : goto rss_sub_policy_error;
19042 : : }
19043 : 0 : sub_policy->idx = sub_policy_idx;
19044 : 0 : sub_policy->main_policy = mtr_policy;
19045 : : }
19046 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
19047 [ # # ]: 0 : if (!rss_desc[i])
19048 : 0 : continue;
19049 : 0 : sub_policy->rix_hrxq[i] = hrxq_idx[i];
19050 [ # # ]: 0 : if (mtr_policy->is_hierarchy) {
19051 : : act_cnt = &mtr_policy->act_cnt[i];
19052 : 0 : act_cnt->next_sub_policy = next_sub_policy;
19053 : 0 : mlx5_hrxq_release(dev, hrxq_idx[i]);
19054 : : } else {
19055 : : /*
19056 : : * Overwrite the last action from
19057 : : * RSS action to Queue action.
19058 : : */
19059 : 0 : hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
19060 : : hrxq_idx[i]);
19061 [ # # ]: 0 : if (!hrxq) {
19062 : 0 : DRV_LOG(ERR, "Failed to get policy hrxq");
19063 : 0 : goto rss_sub_policy_error;
19064 : : }
19065 : : act_cnt = &mtr_policy->act_cnt[i];
19066 [ # # # # ]: 0 : if (act_cnt->rix_mark || act_cnt->modify_hdr) {
19067 : : memset(&dh, 0, sizeof(struct mlx5_flow_handle));
19068 [ # # ]: 0 : if (act_cnt->rix_mark)
19069 : 0 : wks->mark = 1;
19070 : 0 : dh.fate_action = MLX5_FLOW_FATE_QUEUE;
19071 : 0 : dh.rix_hrxq = hrxq_idx[i];
19072 : 0 : flow_drv_rxq_flags_set(dev, &dh);
19073 : : }
19074 : : }
19075 : : }
19076 [ # # ]: 0 : if (__flow_dv_create_policy_acts_rules(dev, mtr_policy,
19077 : : sub_policy, domain)) {
19078 : 0 : DRV_LOG(ERR, "Failed to create policy "
19079 : : "rules for ingress domain.");
19080 : 0 : goto rss_sub_policy_error;
19081 : : }
19082 [ # # ]: 0 : if (sub_policy != mtr_policy->sub_policys[domain][0]) {
19083 : 0 : i = (mtr_policy->sub_policy_num >>
19084 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
19085 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
19086 [ # # ]: 0 : if (i >= MLX5_MTR_RSS_MAX_SUB_POLICY) {
19087 : 0 : DRV_LOG(ERR, "No free sub-policy slot.");
19088 : 0 : goto rss_sub_policy_error;
19089 : : }
19090 : 0 : mtr_policy->sub_policys[domain][i] = sub_policy;
19091 : 0 : i++;
19092 : 0 : mtr_policy->sub_policy_num &= ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
19093 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain));
19094 : 0 : mtr_policy->sub_policy_num |=
19095 : 0 : (i & MLX5_MTR_SUB_POLICY_NUM_MASK) <<
19096 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain);
19097 : : }
19098 : : rte_spinlock_unlock(&mtr_policy->sl);
19099 : 0 : *is_reuse = false;
19100 : 0 : return sub_policy;
19101 : 0 : rss_sub_policy_error:
19102 [ # # ]: 0 : if (sub_policy) {
19103 : 0 : __flow_dv_destroy_sub_policy_rules(dev, sub_policy);
19104 [ # # ]: 0 : if (sub_policy != mtr_policy->sub_policys[domain][0]) {
19105 : 0 : i = (mtr_policy->sub_policy_num >>
19106 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
19107 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
19108 : 0 : mtr_policy->sub_policys[domain][i] = NULL;
19109 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
19110 : 0 : sub_policy->idx);
19111 : : }
19112 : : }
19113 : : rte_spinlock_unlock(&mtr_policy->sl);
19114 : 0 : return NULL;
19115 : : }
19116 : :
19117 : : /**
19118 : : * Find the policy table for prefix table with RSS.
19119 : : *
19120 : : * @param[in] dev
19121 : : * Pointer to Ethernet device.
19122 : : * @param[in] mtr_policy
19123 : : * Pointer to meter policy table.
19124 : : * @param[in] rss_desc
19125 : : * Pointer to rss_desc
19126 : : * @return
19127 : : * Pointer to table set on success, NULL otherwise and rte_errno is set.
19128 : : */
19129 : : static struct mlx5_flow_meter_sub_policy *
19130 : 0 : flow_dv_meter_sub_policy_rss_prepare(struct rte_eth_dev *dev,
19131 : : struct mlx5_flow_meter_policy *mtr_policy,
19132 : : struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS])
19133 : : {
19134 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19135 : : struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
19136 : : struct mlx5_flow_meter_info *next_fm;
19137 : : struct mlx5_flow_meter_policy *next_policy;
19138 : : struct mlx5_flow_meter_sub_policy *next_sub_policy = NULL;
19139 : : struct mlx5_flow_meter_policy *policies[MLX5_MTR_CHAIN_MAX_NUM];
19140 : : struct mlx5_flow_meter_sub_policy *sub_policies[MLX5_MTR_CHAIN_MAX_NUM];
19141 : : uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
19142 : : bool reuse_sub_policy;
19143 : : uint32_t i = 0;
19144 : : uint32_t j = 0;
19145 : :
19146 : : while (true) {
19147 : : /* Iterate hierarchy to get all policies in this hierarchy. */
19148 : 0 : policies[i++] = mtr_policy;
19149 [ # # ]: 0 : if (!mtr_policy->is_hierarchy)
19150 : : break;
19151 [ # # ]: 0 : if (i >= MLX5_MTR_CHAIN_MAX_NUM) {
19152 : 0 : DRV_LOG(ERR, "Exceed max meter number in hierarchy.");
19153 : 0 : return NULL;
19154 : : }
19155 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19156 : 0 : next_fm = mlx5_flow_meter_hierarchy_next_meter(priv, mtr_policy, NULL);
19157 : : rte_spinlock_unlock(&mtr_policy->sl);
19158 [ # # ]: 0 : if (!next_fm) {
19159 : 0 : DRV_LOG(ERR, "Failed to get next meter in hierarchy.");
19160 : 0 : return NULL;
19161 : : }
19162 : : next_policy =
19163 : 0 : mlx5_flow_meter_policy_find(dev, next_fm->policy_id,
19164 : : NULL);
19165 : : MLX5_ASSERT(next_policy);
19166 : : mtr_policy = next_policy;
19167 : : }
19168 [ # # ]: 0 : while (i) {
19169 : : /**
19170 : : * From last policy to the first one in hierarchy,
19171 : : * create / get the sub policy for each of them.
19172 : : */
19173 : 0 : sub_policy = __flow_dv_meter_get_rss_sub_policy(dev,
19174 : : policies[--i],
19175 : : rss_desc,
19176 : : next_sub_policy,
19177 : : &reuse_sub_policy);
19178 [ # # ]: 0 : if (!sub_policy) {
19179 : 0 : DRV_LOG(ERR, "Failed to get the sub policy.");
19180 : 0 : goto err_exit;
19181 : : }
19182 [ # # ]: 0 : if (!reuse_sub_policy)
19183 : 0 : sub_policies[j++] = sub_policy;
19184 : : next_sub_policy = sub_policy;
19185 : : }
19186 : : return sub_policy;
19187 : : err_exit:
19188 [ # # ]: 0 : while (j) {
19189 : : uint16_t sub_policy_num;
19190 : :
19191 : 0 : sub_policy = sub_policies[--j];
19192 : 0 : mtr_policy = sub_policy->main_policy;
19193 : 0 : __flow_dv_destroy_sub_policy_rules(dev, sub_policy);
19194 [ # # ]: 0 : if (sub_policy != mtr_policy->sub_policys[domain][0]) {
19195 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
19196 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
19197 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
19198 : 0 : mtr_policy->sub_policys[domain][sub_policy_num - 1] =
19199 : : NULL;
19200 : 0 : sub_policy_num--;
19201 : 0 : mtr_policy->sub_policy_num &=
19202 : 0 : ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
19203 : 0 : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i));
19204 : 0 : mtr_policy->sub_policy_num |=
19205 : 0 : (sub_policy_num & MLX5_MTR_SUB_POLICY_NUM_MASK) <<
19206 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i);
19207 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
19208 : 0 : sub_policy->idx);
19209 : : }
19210 : : }
19211 : : return NULL;
19212 : : }
19213 : :
19214 : : /**
19215 : : * Check if need to create hierarchy tag rule.
19216 : : *
19217 : : * @param[in] priv
19218 : : * Pointer to mlx5_priv.
19219 : : * @param[in] mtr_policy
19220 : : * Pointer to current meter policy.
19221 : : * @param[in] src_port
19222 : : * The src port this extra rule should use.
19223 : : * @param[out] next_fm
19224 : : * Pointer to next meter in hierarchy.
19225 : : * @param[out] skip
19226 : : * Indicate if skip the tag rule creation.
19227 : : * @param[out] error
19228 : : * Perform verbose error reporting if not NULL.
19229 : : * @return
19230 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
19231 : : */
19232 : : static int
19233 : 0 : mlx5_meter_hierarchy_skip_tag_rule(struct mlx5_priv *priv,
19234 : : struct mlx5_flow_meter_policy *mtr_policy,
19235 : : int32_t src_port,
19236 : : struct mlx5_flow_meter_info **next_fm,
19237 : : bool *skip,
19238 : : struct rte_flow_error *error)
19239 : : {
19240 : : struct mlx5_flow_meter_sub_policy *sub_policy;
19241 : : struct mlx5_sub_policy_color_rule *color_rule;
19242 : : uint32_t domain = MLX5_MTR_DOMAIN_TRANSFER;
19243 : : int ret = 0;
19244 : : int i;
19245 : :
19246 : 0 : *next_fm = NULL;
19247 : 0 : *skip = false;
19248 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19249 [ # # ]: 0 : if (mtr_policy->is_hierarchy) {
19250 : 0 : *next_fm = mlx5_flow_meter_hierarchy_next_meter(priv, mtr_policy, NULL);
19251 [ # # ]: 0 : if (!*next_fm) {
19252 : 0 : ret = rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
19253 : : NULL, "Failed to find next meter in hierarchy.");
19254 : 0 : goto exit;
19255 : : }
19256 : : }
19257 [ # # ]: 0 : if (!mtr_policy->match_port) {
19258 : 0 : *skip = true;
19259 : 0 : goto exit;
19260 : : }
19261 : 0 : sub_policy = mtr_policy->sub_policys[domain][0];
19262 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
19263 [ # # ]: 0 : if (mtr_policy->act_cnt[i].fate_action != MLX5_FLOW_FATE_MTR &&
19264 : : mtr_policy->act_cnt[i].fate_action != MLX5_FLOW_FATE_PORT_ID)
19265 : 0 : continue;
19266 [ # # ]: 0 : TAILQ_FOREACH(color_rule, &sub_policy->color_rules[i], next_port)
19267 [ # # ]: 0 : if (color_rule->src_port == src_port) {
19268 : 0 : *skip = true;
19269 : 0 : goto exit;
19270 : : }
19271 : : }
19272 : 0 : exit:
19273 : : rte_spinlock_unlock(&mtr_policy->sl);
19274 : 0 : return ret;
19275 : : }
19276 : :
19277 : : /**
19278 : : * Create the sub policy tag rule for all meters in hierarchy.
19279 : : *
19280 : : * @param[in] dev
19281 : : * Pointer to Ethernet device.
19282 : : * @param[in] fm
19283 : : * Meter information table.
19284 : : * @param[in] src_port
19285 : : * The src port this extra rule should use.
19286 : : * @param[in] item
19287 : : * The src port match item.
19288 : : * @param[out] error
19289 : : * Perform verbose error reporting if not NULL.
19290 : : * @return
19291 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
19292 : : */
19293 : : static int
19294 : 0 : flow_dv_meter_hierarchy_rule_create(struct rte_eth_dev *dev,
19295 : : struct mlx5_flow_meter_info *fm,
19296 : : int32_t src_port,
19297 : : const struct rte_flow_item *item,
19298 : : struct rte_flow_error *error)
19299 : : {
19300 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19301 : : struct mlx5_flow_meter_policy *mtr_policy;
19302 : : struct mlx5_flow_meter_sub_policy *sub_policy;
19303 : 0 : struct mlx5_flow_meter_info *next_fm = NULL;
19304 : : struct mlx5_flow_meter_policy *next_policy;
19305 : : struct mlx5_flow_meter_sub_policy *next_sub_policy;
19306 : : struct mlx5_flow_tbl_data_entry *tbl_data;
19307 : : struct mlx5_sub_policy_color_rule *color_rule;
19308 : : struct mlx5_meter_policy_acts acts;
19309 : : uint32_t color_reg_c_idx;
19310 : : bool mtr_first = (src_port != UINT16_MAX) ? true : false;
19311 : 0 : struct rte_flow_attr attr = {
19312 : : .group = MLX5_FLOW_TABLE_LEVEL_POLICY,
19313 : : .priority = 0,
19314 : : .ingress = 0,
19315 : : .egress = 0,
19316 : : .transfer = 1,
19317 : : .reserved = 0,
19318 : : };
19319 : : uint32_t domain = MLX5_MTR_DOMAIN_TRANSFER;
19320 : : struct {
19321 : : struct mlx5_flow_meter_policy *fm_policy;
19322 : : struct mlx5_flow_meter_info *next_fm;
19323 : : struct mlx5_sub_policy_color_rule *tag_rule[RTE_COLORS];
19324 : 0 : } fm_info[MLX5_MTR_CHAIN_MAX_NUM] = { {0} };
19325 : : uint32_t fm_cnt = 0;
19326 : : uint32_t i, j;
19327 : :
19328 : 0 : color_reg_c_idx = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, error);
19329 : : /* Get all fms who need to create the tag color rule. */
19330 : : do {
19331 : 0 : bool skip = false;
19332 : :
19333 : 0 : mtr_policy = mlx5_flow_meter_policy_find(dev, fm->policy_id, NULL);
19334 : : MLX5_ASSERT(mtr_policy);
19335 [ # # ]: 0 : if (mlx5_meter_hierarchy_skip_tag_rule(priv, mtr_policy, src_port,
19336 : : &next_fm, &skip, error))
19337 : 0 : goto err_exit;
19338 [ # # ]: 0 : if (!skip) {
19339 : 0 : fm_info[fm_cnt].fm_policy = mtr_policy;
19340 : 0 : fm_info[fm_cnt].next_fm = next_fm;
19341 [ # # ]: 0 : if (++fm_cnt >= MLX5_MTR_CHAIN_MAX_NUM) {
19342 : 0 : rte_flow_error_set(error, errno,
19343 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
19344 : : "Exceed max meter number in hierarchy.");
19345 : 0 : goto err_exit;
19346 : : }
19347 : : }
19348 : 0 : fm = next_fm;
19349 [ # # ]: 0 : } while (fm);
19350 : : /* Create tag color rules for all needed fms. */
19351 [ # # ]: 0 : for (i = 0; i < fm_cnt; i++) {
19352 : : void *mtr_action;
19353 : :
19354 : 0 : mtr_policy = fm_info[i].fm_policy;
19355 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19356 : 0 : sub_policy = mtr_policy->sub_policys[domain][0];
19357 [ # # ]: 0 : for (j = 0; j < RTE_COLORS; j++) {
19358 : : uint8_t act_n = 0;
19359 : : struct mlx5_flow_dv_modify_hdr_resource *modify_hdr = NULL;
19360 : : struct mlx5_flow_dv_port_id_action_resource *port_action;
19361 : : uint8_t fate_action;
19362 : :
19363 [ # # ]: 0 : if (j == RTE_COLOR_RED) {
19364 : : fate_action = MLX5_FLOW_FATE_DROP;
19365 : : } else {
19366 : 0 : fate_action = mtr_policy->act_cnt[j].fate_action;
19367 : 0 : modify_hdr = mtr_policy->act_cnt[j].modify_hdr;
19368 : 0 : if (fate_action != MLX5_FLOW_FATE_MTR &&
19369 [ # # # # ]: 0 : fate_action != MLX5_FLOW_FATE_PORT_ID &&
19370 : : fate_action != MLX5_FLOW_FATE_DROP)
19371 : 0 : continue;
19372 : : }
19373 : 0 : color_rule = mlx5_malloc(MLX5_MEM_ZERO,
19374 : : sizeof(struct mlx5_sub_policy_color_rule),
19375 : : 0, SOCKET_ID_ANY);
19376 [ # # ]: 0 : if (!color_rule) {
19377 : : rte_spinlock_unlock(&mtr_policy->sl);
19378 : 0 : rte_flow_error_set(error, ENOMEM,
19379 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
19380 : : "No memory to create tag color rule.");
19381 : 0 : goto err_exit;
19382 : : }
19383 : 0 : color_rule->src_port = src_port;
19384 : : /* Prepare to create color rule. */
19385 [ # # ]: 0 : if (fate_action == MLX5_FLOW_FATE_MTR) {
19386 : 0 : next_fm = fm_info[i].next_fm;
19387 [ # # ]: 0 : if (mlx5_flow_meter_attach(priv, next_fm, &attr, error)) {
19388 : 0 : mlx5_free(color_rule);
19389 : : rte_spinlock_unlock(&mtr_policy->sl);
19390 : 0 : goto err_exit;
19391 : : }
19392 [ # # ]: 0 : mtr_action = (next_fm->color_aware && j == RTE_COLOR_YELLOW) ?
19393 [ # # ]: 0 : next_fm->meter_action_y :
19394 : : next_fm->meter_action_g;
19395 : 0 : next_policy = mlx5_flow_meter_policy_find(dev, next_fm->policy_id,
19396 : : NULL);
19397 : : MLX5_ASSERT(next_policy);
19398 : 0 : next_sub_policy = next_policy->sub_policys[domain][0];
19399 : 0 : tbl_data = container_of(next_sub_policy->tbl_rsc,
19400 : : struct mlx5_flow_tbl_data_entry, tbl);
19401 [ # # ]: 0 : if (mtr_first) {
19402 : 0 : acts.dv_actions[act_n++] = mtr_action;
19403 [ # # ]: 0 : if (modify_hdr)
19404 : 0 : acts.dv_actions[act_n++] = modify_hdr->action;
19405 : : } else {
19406 [ # # ]: 0 : if (modify_hdr)
19407 : 0 : acts.dv_actions[act_n++] = modify_hdr->action;
19408 : 0 : acts.dv_actions[act_n++] = mtr_action;
19409 : : }
19410 : 0 : acts.dv_actions[act_n++] = tbl_data->jump.action;
19411 : 0 : acts.actions_n = act_n;
19412 [ # # ]: 0 : } else if (fate_action == MLX5_FLOW_FATE_PORT_ID) {
19413 : : port_action =
19414 : 0 : mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PORT_ID],
19415 : : mtr_policy->act_cnt[j].rix_port_id_action);
19416 [ # # ]: 0 : if (!port_action) {
19417 : 0 : mlx5_free(color_rule);
19418 : : rte_spinlock_unlock(&mtr_policy->sl);
19419 : 0 : goto err_exit;
19420 : : }
19421 [ # # ]: 0 : if (modify_hdr)
19422 : 0 : acts.dv_actions[act_n++] = modify_hdr->action;
19423 : 0 : acts.dv_actions[act_n++] = port_action->action;
19424 : 0 : acts.actions_n = act_n;
19425 : : } else {
19426 : 0 : acts.dv_actions[act_n++] = mtr_policy->dr_drop_action[domain];
19427 : 0 : acts.actions_n = act_n;
19428 : : }
19429 : 0 : fm_info[i].tag_rule[j] = color_rule;
19430 : 0 : TAILQ_INSERT_TAIL(&sub_policy->color_rules[j], color_rule, next_port);
19431 [ # # ]: 0 : if (__flow_dv_create_policy_matcher(dev, color_reg_c_idx,
19432 : : MLX5_MTR_POLICY_MATCHER_PRIO, sub_policy,
19433 : : &attr, true, item, &color_rule->matcher, error)) {
19434 : : rte_spinlock_unlock(&mtr_policy->sl);
19435 : 0 : rte_flow_error_set(error, errno,
19436 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
19437 : : "Failed to create hierarchy meter matcher.");
19438 : 0 : goto err_exit;
19439 : : }
19440 [ # # ]: 0 : if (__flow_dv_create_policy_flow(dev, color_reg_c_idx, (enum rte_color)j,
19441 : : color_rule->matcher,
19442 : 0 : acts.actions_n, acts.dv_actions,
19443 : : true, item, &color_rule->rule, &attr)) {
19444 : : rte_spinlock_unlock(&mtr_policy->sl);
19445 : 0 : rte_flow_error_set(error, errno,
19446 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
19447 : : "Failed to create hierarchy meter rule.");
19448 : 0 : goto err_exit;
19449 : : }
19450 : : }
19451 : : rte_spinlock_unlock(&mtr_policy->sl);
19452 : : }
19453 : : return 0;
19454 : 0 : err_exit:
19455 [ # # ]: 0 : for (i = 0; i < fm_cnt; i++) {
19456 : 0 : mtr_policy = fm_info[i].fm_policy;
19457 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19458 : 0 : sub_policy = mtr_policy->sub_policys[domain][0];
19459 [ # # ]: 0 : for (j = 0; j < RTE_COLORS; j++) {
19460 : 0 : color_rule = fm_info[i].tag_rule[j];
19461 [ # # ]: 0 : if (!color_rule)
19462 : 0 : continue;
19463 [ # # ]: 0 : if (color_rule->rule)
19464 : : mlx5_flow_os_destroy_flow(color_rule->rule);
19465 [ # # ]: 0 : if (color_rule->matcher) {
19466 : : struct mlx5_flow_tbl_data_entry *tbl =
19467 : 0 : container_of(color_rule->matcher->tbl, typeof(*tbl), tbl);
19468 : 0 : mlx5_list_unregister(tbl->matchers, &color_rule->matcher->entry);
19469 : : }
19470 [ # # ]: 0 : if (fm_info[i].next_fm)
19471 : 0 : mlx5_flow_meter_detach(priv, fm_info[i].next_fm);
19472 [ # # ]: 0 : TAILQ_REMOVE(&sub_policy->color_rules[j], color_rule, next_port);
19473 : 0 : mlx5_free(color_rule);
19474 : : }
19475 : : rte_spinlock_unlock(&mtr_policy->sl);
19476 : : }
19477 : 0 : return -rte_errno;
19478 : : }
19479 : :
19480 : : /**
19481 : : * Destroy the sub policy table with RX queue.
19482 : : *
19483 : : * @param[in] dev
19484 : : * Pointer to Ethernet device.
19485 : : * @param[in] mtr_policy
19486 : : * Pointer to meter policy table.
19487 : : */
19488 : : static void
19489 : 0 : flow_dv_destroy_sub_policy_with_rxq(struct rte_eth_dev *dev,
19490 : : struct mlx5_flow_meter_policy *mtr_policy)
19491 : : {
19492 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19493 : : struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
19494 : : uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
19495 : : uint32_t i, j;
19496 : : uint16_t sub_policy_num, new_policy_num;
19497 : :
19498 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19499 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
19500 [ # # # ]: 0 : switch (mtr_policy->act_cnt[i].fate_action) {
19501 : 0 : case MLX5_FLOW_FATE_SHARED_RSS:
19502 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
19503 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
19504 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
19505 : : new_policy_num = sub_policy_num;
19506 [ # # ]: 0 : for (j = 0; j < sub_policy_num; j++) {
19507 : 0 : sub_policy =
19508 : 0 : mtr_policy->sub_policys[domain][j];
19509 [ # # ]: 0 : if (sub_policy) {
19510 : 0 : __flow_dv_destroy_sub_policy_rules(dev,
19511 : : sub_policy);
19512 : 0 : if (sub_policy !=
19513 [ # # ]: 0 : mtr_policy->sub_policys[domain][0]) {
19514 : 0 : mtr_policy->sub_policys[domain][j] =
19515 : : NULL;
19516 : 0 : mlx5_ipool_free
19517 : 0 : (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
19518 : 0 : sub_policy->idx);
19519 : 0 : new_policy_num--;
19520 : : }
19521 : : }
19522 : : }
19523 [ # # ]: 0 : if (new_policy_num != sub_policy_num) {
19524 : 0 : mtr_policy->sub_policy_num &=
19525 : : ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
19526 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain));
19527 : 0 : mtr_policy->sub_policy_num |=
19528 : : (new_policy_num &
19529 : : MLX5_MTR_SUB_POLICY_NUM_MASK) <<
19530 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain);
19531 : : }
19532 : : break;
19533 : 0 : case MLX5_FLOW_FATE_QUEUE:
19534 : 0 : sub_policy = mtr_policy->sub_policys[domain][0];
19535 : 0 : __flow_dv_destroy_sub_policy_rules(dev,
19536 : : sub_policy);
19537 : 0 : break;
19538 : : default:
19539 : : /*Other actions without queue and do nothing*/
19540 : : break;
19541 : : }
19542 : : }
19543 : : rte_spinlock_unlock(&mtr_policy->sl);
19544 : 0 : }
19545 : : /**
19546 : : * Check whether the DR drop action is supported on the root table or not.
19547 : : *
19548 : : * Create a simple flow with DR drop action on root table to validate
19549 : : * if DR drop action on root table is supported or not.
19550 : : *
19551 : : * @param[in] dev
19552 : : * Pointer to rte_eth_dev structure.
19553 : : *
19554 : : * @return
19555 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
19556 : : */
19557 : : int
19558 : 0 : mlx5_flow_discover_dr_action_support(struct rte_eth_dev *dev)
19559 : : {
19560 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19561 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
19562 : 0 : struct mlx5_flow_dv_match_params mask = {
19563 : : .size = sizeof(mask.buf),
19564 : : };
19565 : 0 : struct mlx5_flow_dv_match_params value = {
19566 : : .size = sizeof(value.buf),
19567 : : };
19568 : 0 : struct mlx5dv_flow_matcher_attr dv_attr = {
19569 : : .type = IBV_FLOW_ATTR_NORMAL,
19570 : : .priority = 0,
19571 : : .match_criteria_enable = 0,
19572 : : .match_mask = (void *)&mask,
19573 : : };
19574 : : struct mlx5_flow_tbl_resource *tbl = NULL;
19575 : : void *matcher = NULL;
19576 : : void *flow = NULL;
19577 : : int ret = -1;
19578 : :
19579 : 0 : tbl = flow_dv_tbl_resource_get(dev, 0, 0, 0, false, NULL,
19580 : : 0, 0, 0, NULL);
19581 [ # # ]: 0 : if (!tbl)
19582 : 0 : goto err;
19583 [ # # ]: 0 : dv_attr.match_criteria_enable = flow_dv_matcher_enable(mask.buf);
19584 : : __flow_dv_adjust_buf_size(&mask.size, dv_attr.match_criteria_enable);
19585 : 0 : ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
19586 : : tbl->obj, &matcher);
19587 : : if (ret)
19588 : 0 : goto err;
19589 [ # # ]: 0 : __flow_dv_adjust_buf_size(&value.size, dv_attr.match_criteria_enable);
19590 : 0 : ret = mlx5_flow_os_create_flow(matcher, (void *)&value, 1,
19591 : : &sh->dr_drop_action, &flow);
19592 : 0 : err:
19593 : : /*
19594 : : * If DR drop action is not supported on root table, flow create will
19595 : : * be failed with EOPNOTSUPP or EPROTONOSUPPORT.
19596 : : */
19597 [ # # ]: 0 : if (!flow) {
19598 [ # # ]: 0 : if (matcher &&
19599 [ # # ]: 0 : (errno == EPROTONOSUPPORT || errno == EOPNOTSUPP))
19600 : 0 : DRV_LOG(INFO, "DR drop action is not supported in root table.");
19601 : : else
19602 : 0 : DRV_LOG(ERR, "Unexpected error in DR drop action support detection");
19603 : : ret = -1;
19604 : : } else {
19605 : : claim_zero(mlx5_flow_os_destroy_flow(flow));
19606 : : }
19607 [ # # ]: 0 : if (matcher)
19608 : : claim_zero(mlx5_flow_os_destroy_flow_matcher(matcher));
19609 [ # # ]: 0 : if (tbl)
19610 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
19611 : 0 : return ret;
19612 : : }
19613 : :
19614 : : /**
19615 : : * Validate the batch counter support in root table.
19616 : : *
19617 : : * Create a simple flow with invalid counter and drop action on root table to
19618 : : * validate if batch counter with offset on root table is supported or not.
19619 : : *
19620 : : * @param[in] dev
19621 : : * Pointer to rte_eth_dev structure.
19622 : : *
19623 : : * @return
19624 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
19625 : : */
19626 : : int
19627 : 0 : mlx5_flow_dv_discover_counter_offset_support(struct rte_eth_dev *dev)
19628 : : {
19629 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19630 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
19631 : 0 : struct mlx5_flow_dv_match_params mask = {
19632 : : .size = sizeof(mask.buf),
19633 : : };
19634 : 0 : struct mlx5_flow_dv_match_params value = {
19635 : : .size = sizeof(value.buf),
19636 : : };
19637 : 0 : struct mlx5dv_flow_matcher_attr dv_attr = {
19638 : : .type = IBV_FLOW_ATTR_NORMAL | IBV_FLOW_ATTR_FLAGS_EGRESS,
19639 : : .priority = 0,
19640 : : .match_criteria_enable = 0,
19641 : : .match_mask = (void *)&mask,
19642 : : };
19643 : 0 : void *actions[2] = { 0 };
19644 : : struct mlx5_flow_tbl_resource *tbl = NULL;
19645 : : struct mlx5_devx_obj *dcs = NULL;
19646 : : void *matcher = NULL;
19647 : : void *flow = NULL;
19648 : : int ret = -1;
19649 : :
19650 : 0 : tbl = flow_dv_tbl_resource_get(dev, 0, 1, 0, false, NULL,
19651 : : 0, 0, 0, NULL);
19652 [ # # ]: 0 : if (!tbl)
19653 : 0 : goto err;
19654 : 0 : dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0x4);
19655 [ # # ]: 0 : if (!dcs)
19656 : 0 : goto err;
19657 : 0 : ret = mlx5_flow_os_create_flow_action_count(dcs->obj, UINT16_MAX,
19658 : : &actions[0]);
19659 : : if (ret)
19660 : 0 : goto err;
19661 [ # # ]: 0 : dv_attr.match_criteria_enable = flow_dv_matcher_enable(mask.buf);
19662 : : __flow_dv_adjust_buf_size(&mask.size, dv_attr.match_criteria_enable);
19663 : 0 : ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
19664 : : tbl->obj, &matcher);
19665 : : if (ret)
19666 : 0 : goto err;
19667 [ # # ]: 0 : __flow_dv_adjust_buf_size(&value.size, dv_attr.match_criteria_enable);
19668 : : ret = mlx5_flow_os_create_flow(matcher, (void *)&value, 1,
19669 : : actions, &flow);
19670 : 0 : err:
19671 : : /*
19672 : : * If batch counter with offset is not supported, the driver will not
19673 : : * validate the invalid offset value, flow create should success.
19674 : : * In this case, it means batch counter is not supported in root table.
19675 : : *
19676 : : * Otherwise, if flow create is failed, counter offset is supported.
19677 : : */
19678 [ # # ]: 0 : if (flow) {
19679 : 0 : DRV_LOG(INFO, "Batch counter is not supported in root "
19680 : : "table. Switch to fallback mode.");
19681 : 0 : rte_errno = ENOTSUP;
19682 : : ret = -rte_errno;
19683 : : claim_zero(mlx5_flow_os_destroy_flow(flow));
19684 : : } else {
19685 : : /* Check matcher to make sure validate fail at flow create. */
19686 [ # # # # ]: 0 : if (!matcher || (matcher && errno != EINVAL))
19687 : 0 : DRV_LOG(ERR, "Unexpected error in counter offset "
19688 : : "support detection");
19689 : : ret = 0;
19690 : : }
19691 [ # # ]: 0 : if (actions[0])
19692 : : claim_zero(mlx5_flow_os_destroy_flow_action(actions[0]));
19693 [ # # ]: 0 : if (matcher)
19694 : : claim_zero(mlx5_flow_os_destroy_flow_matcher(matcher));
19695 [ # # ]: 0 : if (tbl)
19696 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
19697 [ # # ]: 0 : if (dcs)
19698 : 0 : claim_zero(mlx5_devx_cmd_destroy(dcs));
19699 : 0 : return ret;
19700 : : }
19701 : :
19702 : : /**
19703 : : * Query a devx counter.
19704 : : *
19705 : : * @param[in] dev
19706 : : * Pointer to the Ethernet device structure.
19707 : : * @param[in] cnt
19708 : : * Index to the flow counter.
19709 : : * @param[in] clear
19710 : : * Set to clear the counter statistics.
19711 : : * @param[out] pkts
19712 : : * The statistics value of packets.
19713 : : * @param[out] bytes
19714 : : * The statistics value of bytes.
19715 : : *
19716 : : * @return
19717 : : * 0 on success, otherwise return -1.
19718 : : */
19719 : : static int
19720 : 0 : flow_dv_counter_query(struct rte_eth_dev *dev, uint32_t counter, bool clear,
19721 : : uint64_t *pkts, uint64_t *bytes, void **action)
19722 : : {
19723 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19724 : : struct mlx5_flow_counter *cnt;
19725 : : uint64_t inn_pkts, inn_bytes;
19726 : : int ret;
19727 : :
19728 [ # # ]: 0 : if (!priv->sh->cdev->config.devx)
19729 : : return -1;
19730 : :
19731 : 0 : ret = _flow_dv_query_count(dev, counter, &inn_pkts, &inn_bytes);
19732 [ # # ]: 0 : if (ret)
19733 : : return -1;
19734 : : cnt = flow_dv_counter_get_by_idx(dev, counter, NULL);
19735 [ # # ]: 0 : if (cnt && action)
19736 : 0 : *action = cnt->action;
19737 : :
19738 : 0 : *pkts = inn_pkts - cnt->hits;
19739 : 0 : *bytes = inn_bytes - cnt->bytes;
19740 [ # # ]: 0 : if (clear) {
19741 : 0 : cnt->hits = inn_pkts;
19742 : 0 : cnt->bytes = inn_bytes;
19743 : : }
19744 : : return 0;
19745 : : }
19746 : :
19747 : : /**
19748 : : * Get aged-out flows.
19749 : : *
19750 : : * @param[in] dev
19751 : : * Pointer to the Ethernet device structure.
19752 : : * @param[in] context
19753 : : * The address of an array of pointers to the aged-out flows contexts.
19754 : : * @param[in] nb_contexts
19755 : : * The length of context array pointers.
19756 : : * @param[out] error
19757 : : * Perform verbose error reporting if not NULL. Initialized in case of
19758 : : * error only.
19759 : : *
19760 : : * @return
19761 : : * how many contexts get in success, otherwise negative errno value.
19762 : : * if nb_contexts is 0, return the amount of all aged contexts.
19763 : : * if nb_contexts is not 0 , return the amount of aged flows reported
19764 : : * in the context array.
19765 : : * @note: only stub for now
19766 : : */
19767 : : static int
19768 : 0 : flow_dv_get_aged_flows(struct rte_eth_dev *dev,
19769 : : void **context,
19770 : : uint32_t nb_contexts,
19771 : : struct rte_flow_error *error)
19772 : : {
19773 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19774 : : struct mlx5_age_info *age_info;
19775 : : struct mlx5_age_param *age_param;
19776 : : struct mlx5_flow_counter *counter;
19777 : : struct mlx5_aso_age_action *act;
19778 : : int nb_flows = 0;
19779 : :
19780 [ # # ]: 0 : if (nb_contexts && !context)
19781 : 0 : return rte_flow_error_set(error, EINVAL,
19782 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
19783 : : NULL, "empty context");
19784 : 0 : age_info = GET_PORT_AGE_INFO(priv);
19785 : 0 : rte_spinlock_lock(&age_info->aged_sl);
19786 [ # # ]: 0 : LIST_FOREACH(act, &age_info->aged_aso, next) {
19787 : 0 : nb_flows++;
19788 [ # # ]: 0 : if (nb_contexts) {
19789 : 0 : context[nb_flows - 1] = act->age_params.context;
19790 [ # # ]: 0 : if (!(--nb_contexts))
19791 : : break;
19792 : : }
19793 : : }
19794 [ # # ]: 0 : TAILQ_FOREACH(counter, &age_info->aged_counters, next) {
19795 : 0 : nb_flows++;
19796 [ # # ]: 0 : if (nb_contexts) {
19797 : : age_param = MLX5_CNT_TO_AGE(counter);
19798 : 0 : context[nb_flows - 1] = age_param->context;
19799 [ # # ]: 0 : if (!(--nb_contexts))
19800 : : break;
19801 : : }
19802 : : }
19803 : : rte_spinlock_unlock(&age_info->aged_sl);
19804 : 0 : MLX5_AGE_SET(age_info, MLX5_AGE_TRIGGER);
19805 : 0 : return nb_flows;
19806 : : }
19807 : :
19808 : : /*
19809 : : * Mutex-protected thunk to lock-free flow_dv_counter_alloc().
19810 : : */
19811 : : static uint32_t
19812 : 0 : flow_dv_counter_allocate(struct rte_eth_dev *dev)
19813 : : {
19814 : 0 : return flow_dv_counter_alloc(dev, 0);
19815 : : }
19816 : :
19817 : : /**
19818 : : * Validate indirect action.
19819 : : * Dispatcher for action type specific validation.
19820 : : *
19821 : : * @param[in] dev
19822 : : * Pointer to the Ethernet device structure.
19823 : : * @param[in] conf
19824 : : * Indirect action configuration.
19825 : : * @param[in] action
19826 : : * The indirect action object to validate.
19827 : : * @param[out] error
19828 : : * Perform verbose error reporting if not NULL. Initialized in case of
19829 : : * error only.
19830 : : *
19831 : : * @return
19832 : : * 0 on success, otherwise negative errno value.
19833 : : */
19834 : : int
19835 : 0 : flow_dv_action_validate(struct rte_eth_dev *dev,
19836 : : const struct rte_flow_indir_action_conf *conf,
19837 : : const struct rte_flow_action *action,
19838 : : struct rte_flow_error *err)
19839 : : {
19840 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19841 : : /* called from RTE API */
19842 : :
19843 : : RTE_SET_USED(conf);
19844 [ # # # # : 0 : switch (action->type) {
# ]
19845 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
19846 : : /*
19847 : : * priv->obj_ops is set according to driver capabilities.
19848 : : * When DevX capabilities are
19849 : : * sufficient, it is set to devx_obj_ops.
19850 : : * Otherwise, it is set to ibv_obj_ops.
19851 : : * ibv_obj_ops doesn't support ind_table_modify operation.
19852 : : * In this case the indirect RSS action can't be used.
19853 : : */
19854 [ # # ]: 0 : if (priv->obj_ops.ind_table_modify == NULL)
19855 : 0 : return rte_flow_error_set
19856 : : (err, ENOTSUP,
19857 : : RTE_FLOW_ERROR_TYPE_ACTION,
19858 : : NULL,
19859 : : "Indirect RSS action not supported");
19860 : 0 : return mlx5_validate_action_rss(dev, action, err);
19861 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
19862 [ # # ]: 0 : if (!priv->sh->aso_age_mng)
19863 : 0 : return rte_flow_error_set(err, ENOTSUP,
19864 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
19865 : : NULL,
19866 : : "Indirect age action not supported");
19867 : 0 : return flow_dv_validate_action_age(0, action, dev, err);
19868 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
19869 : 0 : return flow_dv_validate_action_count(dev, true, 0, false, err);
19870 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
19871 [ # # ]: 0 : if (!priv->sh->ct_aso_en)
19872 : 0 : return rte_flow_error_set(err, ENOTSUP,
19873 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
19874 : : "ASO CT is not supported");
19875 : 0 : return mlx5_validate_action_ct(dev, action->conf, err);
19876 : 0 : default:
19877 : 0 : return rte_flow_error_set(err, ENOTSUP,
19878 : : RTE_FLOW_ERROR_TYPE_ACTION,
19879 : : NULL,
19880 : : "action type not supported");
19881 : : }
19882 : : }
19883 : :
19884 : : /*
19885 : : * Check if the RSS configurations for colors of a meter policy match
19886 : : * each other, except the queues.
19887 : : *
19888 : : * @param[in] r1
19889 : : * Pointer to the first RSS flow action.
19890 : : * @param[in] r2
19891 : : * Pointer to the second RSS flow action.
19892 : : *
19893 : : * @return
19894 : : * 0 on match, 1 on conflict.
19895 : : */
19896 : : static inline int
19897 : 0 : flow_dv_mtr_policy_rss_compare(const struct rte_flow_action_rss *r1,
19898 : : const struct rte_flow_action_rss *r2)
19899 : : {
19900 [ # # ]: 0 : if (r1 == NULL || r2 == NULL)
19901 : : return 0;
19902 [ # # # # : 0 : if (!(r1->level <= 1 && r2->level <= 1) &&
# # ]
19903 [ # # ]: 0 : !(r1->level > 1 && r2->level > 1))
19904 : : return 1;
19905 [ # # ]: 0 : if (r1->func != r2->func)
19906 : : return 1;
19907 [ # # ]: 0 : if (r1->types != r2->types &&
19908 [ # # ]: 0 : !((r1->types == 0 || r1->types == RTE_ETH_RSS_IP) &&
19909 [ # # ]: 0 : (r2->types == 0 || r2->types == RTE_ETH_RSS_IP)))
19910 : : return 1;
19911 [ # # # # ]: 0 : if (r1->key || r2->key) {
19912 [ # # ]: 0 : const void *key1 = r1->key ? r1->key : rss_hash_default_key;
19913 [ # # ]: 0 : const void *key2 = r2->key ? r2->key : rss_hash_default_key;
19914 : :
19915 [ # # ]: 0 : if (memcmp(key1, key2, MLX5_RSS_HASH_KEY_LEN))
19916 : 0 : return 1;
19917 : : }
19918 : : return 0;
19919 : : }
19920 : :
19921 : : /**
19922 : : * Validate the meter hierarchy chain for meter policy.
19923 : : *
19924 : : * @param[in] dev
19925 : : * Pointer to the Ethernet device structure.
19926 : : * @param[in] meter_id
19927 : : * Meter id.
19928 : : * @param[in] action_flags
19929 : : * Holds the actions detected until now.
19930 : : * @param[out] is_rss
19931 : : * Is RSS or not.
19932 : : * @param[out] hierarchy_domain
19933 : : * The domain bitmap for hierarchy policy.
19934 : : * @param[out] error
19935 : : * Perform verbose error reporting if not NULL. Initialized in case of
19936 : : * error only.
19937 : : *
19938 : : * @return
19939 : : * 0 on success, otherwise negative errno value with error set.
19940 : : */
19941 : : static int
19942 : 0 : flow_dv_validate_policy_mtr_hierarchy(struct rte_eth_dev *dev,
19943 : : uint32_t meter_id,
19944 : : uint64_t action_flags,
19945 : : bool *is_rss,
19946 : : uint8_t *hierarchy_domain,
19947 : : struct rte_mtr_error *error)
19948 : : {
19949 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19950 : : struct mlx5_flow_meter_info *fm;
19951 : : struct mlx5_flow_meter_policy *policy;
19952 : : uint8_t cnt = 1;
19953 : :
19954 [ # # ]: 0 : if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
19955 : : MLX5_FLOW_FATE_ESWITCH_ACTIONS))
19956 : 0 : return -rte_mtr_error_set(error, EINVAL,
19957 : : RTE_MTR_ERROR_TYPE_POLICER_ACTION_GREEN,
19958 : : NULL,
19959 : : "Multiple fate actions not supported.");
19960 : 0 : *hierarchy_domain = 0;
19961 : 0 : fm = mlx5_flow_meter_find(priv, meter_id, NULL);
19962 : : while (true) {
19963 [ # # ]: 0 : if (!fm)
19964 : 0 : return -rte_mtr_error_set(error, EINVAL,
19965 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
19966 : : "Meter not found in meter hierarchy.");
19967 [ # # ]: 0 : if (fm->def_policy)
19968 : 0 : return -rte_mtr_error_set(error, EINVAL,
19969 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
19970 : : "Non termination meter not supported in hierarchy.");
19971 [ # # ]: 0 : if (!fm->shared)
19972 : 0 : return -rte_mtr_error_set(error, EINVAL,
19973 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
19974 : : "Only shared meter supported in hierarchy.");
19975 : 0 : policy = mlx5_flow_meter_policy_find(dev, fm->policy_id, NULL);
19976 : : MLX5_ASSERT(policy);
19977 : : /**
19978 : : * Only inherit the supported domains of the first meter in
19979 : : * hierarchy.
19980 : : * One meter supports at least one domain.
19981 : : */
19982 [ # # ]: 0 : if (!*hierarchy_domain) {
19983 [ # # ]: 0 : if (policy->transfer)
19984 : 0 : *hierarchy_domain |=
19985 : : MLX5_MTR_DOMAIN_TRANSFER_BIT;
19986 [ # # ]: 0 : if (policy->ingress)
19987 : 0 : *hierarchy_domain |=
19988 : : MLX5_MTR_DOMAIN_INGRESS_BIT;
19989 [ # # ]: 0 : if (policy->egress)
19990 : 0 : *hierarchy_domain |= MLX5_MTR_DOMAIN_EGRESS_BIT;
19991 : : }
19992 [ # # ]: 0 : if (!policy->is_hierarchy) {
19993 : 0 : *is_rss = policy->is_rss;
19994 : : break;
19995 : : }
19996 : 0 : rte_spinlock_lock(&policy->sl);
19997 : 0 : fm = mlx5_flow_meter_hierarchy_next_meter(priv, policy, NULL);
19998 : : rte_spinlock_unlock(&policy->sl);
19999 [ # # ]: 0 : if (++cnt >= MLX5_MTR_CHAIN_MAX_NUM)
20000 : 0 : return -rte_mtr_error_set(error, EINVAL,
20001 : : RTE_MTR_ERROR_TYPE_METER_POLICY, NULL,
20002 : : "Exceed max hierarchy meter number.");
20003 : : }
20004 : 0 : return 0;
20005 : : }
20006 : :
20007 : : /**
20008 : : * Validate meter policy actions.
20009 : : * Dispatcher for action type specific validation.
20010 : : *
20011 : : * @param[in] dev
20012 : : * Pointer to the Ethernet device structure.
20013 : : * @param[in] action
20014 : : * The meter policy action object to validate.
20015 : : * @param[in] attr
20016 : : * Attributes of flow to determine steering domain.
20017 : : * @param[out] error
20018 : : * Perform verbose error reporting if not NULL. Initialized in case of
20019 : : * error only.
20020 : : *
20021 : : * @return
20022 : : * 0 on success, otherwise negative errno value.
20023 : : */
20024 : : static int
20025 : 0 : flow_dv_validate_mtr_policy_acts(struct rte_eth_dev *dev,
20026 : : const struct rte_flow_action *actions[RTE_COLORS],
20027 : : struct rte_flow_attr *attr,
20028 : : bool *is_rss,
20029 : : uint8_t *domain_bitmap,
20030 : : uint8_t *policy_mode,
20031 : : struct rte_mtr_error *error)
20032 : : {
20033 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
20034 : 0 : struct mlx5_sh_config *dev_conf = &priv->sh->config;
20035 : : const struct rte_flow_action *act;
20036 : 0 : uint64_t action_flags[RTE_COLORS] = {0};
20037 : : int actions_n;
20038 : : int i, ret;
20039 : : struct rte_flow_error flow_err;
20040 : 0 : uint8_t domain_color[RTE_COLORS] = {0};
20041 : : uint8_t def_domain = MLX5_MTR_ALL_DOMAIN_BIT;
20042 : 0 : uint8_t hierarchy_domain = 0;
20043 : : const struct rte_flow_action_meter *mtr;
20044 : : const struct rte_flow_action_meter *next_mtr = NULL;
20045 : : bool def_green = false;
20046 : : bool def_yellow = false;
20047 : 0 : const struct rte_flow_action_rss *rss_color[RTE_COLORS] = {NULL};
20048 : : /* Called from RTE API */
20049 [ # # # # : 0 : bool is_root = !(attr->group || (attr->transfer && priv->fdb_def_rule));
# # ]
20050 : :
20051 [ # # ]: 0 : if (!dev_conf->dv_esw_en)
20052 : : def_domain &= ~MLX5_MTR_DOMAIN_TRANSFER_BIT;
20053 : 0 : *domain_bitmap = def_domain;
20054 : : /* Red color could only support DROP action. */
20055 [ # # ]: 0 : if (!actions[RTE_COLOR_RED] ||
20056 [ # # ]: 0 : actions[RTE_COLOR_RED]->type != RTE_FLOW_ACTION_TYPE_DROP)
20057 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20058 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20059 : : NULL, "Red color only supports drop action.");
20060 : : /*
20061 : : * Check default policy actions:
20062 : : * Green / Yellow: no action, Red: drop action
20063 : : * Either G or Y will trigger default policy actions to be created.
20064 : : */
20065 [ # # ]: 0 : if (!actions[RTE_COLOR_GREEN] ||
20066 [ # # ]: 0 : actions[RTE_COLOR_GREEN]->type == RTE_FLOW_ACTION_TYPE_END)
20067 : : def_green = true;
20068 [ # # ]: 0 : if (!actions[RTE_COLOR_YELLOW] ||
20069 [ # # ]: 0 : actions[RTE_COLOR_YELLOW]->type == RTE_FLOW_ACTION_TYPE_END)
20070 : : def_yellow = true;
20071 [ # # ]: 0 : if (def_green && def_yellow) {
20072 : 0 : *policy_mode = MLX5_MTR_POLICY_MODE_DEF;
20073 : 0 : return 0;
20074 [ # # ]: 0 : } else if (!def_green && def_yellow) {
20075 : 0 : *policy_mode = MLX5_MTR_POLICY_MODE_OG;
20076 [ # # ]: 0 : } else if (def_green && !def_yellow) {
20077 : 0 : *policy_mode = MLX5_MTR_POLICY_MODE_OY;
20078 : : } else {
20079 : 0 : *policy_mode = MLX5_MTR_POLICY_MODE_ALL;
20080 : : }
20081 : : /* Set to empty string in case of NULL pointer access by user. */
20082 : 0 : flow_err.message = "";
20083 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
20084 : 0 : act = actions[i];
20085 : 0 : for (action_flags[i] = 0, actions_n = 0;
20086 [ # # # # ]: 0 : act && act->type != RTE_FLOW_ACTION_TYPE_END;
20087 : 0 : act++) {
20088 [ # # ]: 0 : if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
20089 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20090 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20091 : : NULL, "too many actions");
20092 [ # # # # : 0 : switch (act->type) {
# # # # #
# ]
20093 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
20094 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
20095 [ # # ]: 0 : if (!dev_conf->dv_esw_en)
20096 : 0 : return -rte_mtr_error_set(error,
20097 : : ENOTSUP,
20098 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20099 : : NULL, "PORT action validate check"
20100 : : " fail for ESW disable");
20101 : 0 : ret = flow_dv_validate_action_port_id(dev,
20102 : : action_flags[i],
20103 : : act, attr, &flow_err);
20104 [ # # ]: 0 : if (ret)
20105 : 0 : return -rte_mtr_error_set(error,
20106 : : ENOTSUP,
20107 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20108 [ # # ]: 0 : NULL, flow_err.message ?
20109 : : flow_err.message :
20110 : : "PORT action validate check fail");
20111 : 0 : ++actions_n;
20112 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_PORT_ID;
20113 : 0 : break;
20114 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
20115 : 0 : ret = flow_dv_validate_action_mark(dev, act,
20116 : : action_flags[i],
20117 : : attr, &flow_err);
20118 [ # # ]: 0 : if (ret < 0)
20119 : 0 : return -rte_mtr_error_set(error,
20120 : : ENOTSUP,
20121 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20122 [ # # ]: 0 : NULL, flow_err.message ?
20123 : : flow_err.message :
20124 : : "Mark action validate check fail");
20125 [ # # ]: 0 : if (dev_conf->dv_xmeta_en !=
20126 : : MLX5_XMETA_MODE_LEGACY)
20127 : 0 : return -rte_mtr_error_set(error,
20128 : : ENOTSUP,
20129 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20130 : : NULL, "Extend MARK action is "
20131 : : "not supported. Please try use "
20132 : : "default policy for meter.");
20133 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_MARK;
20134 : 0 : ++actions_n;
20135 : 0 : break;
20136 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TAG:
20137 : 0 : ret = flow_dv_validate_action_set_tag(dev,
20138 : : act, action_flags[i],
20139 : : attr, &flow_err);
20140 [ # # ]: 0 : if (ret)
20141 : 0 : return -rte_mtr_error_set(error,
20142 : : ENOTSUP,
20143 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20144 [ # # ]: 0 : NULL, flow_err.message ?
20145 : : flow_err.message :
20146 : : "Set tag action validate check fail");
20147 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_SET_TAG;
20148 : 0 : ++actions_n;
20149 : 0 : break;
20150 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
20151 : 0 : ret = mlx5_flow_validate_action_drop
20152 : : (dev, false, attr, &flow_err);
20153 [ # # ]: 0 : if (ret < 0)
20154 : 0 : return -rte_mtr_error_set(error,
20155 : : ENOTSUP,
20156 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20157 [ # # ]: 0 : NULL, flow_err.message ?
20158 : : flow_err.message :
20159 : : "Drop action validate check fail");
20160 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_DROP;
20161 : 0 : ++actions_n;
20162 : 0 : break;
20163 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
20164 : : /*
20165 : : * Check whether extensive
20166 : : * metadata feature is engaged.
20167 : : */
20168 [ # # ]: 0 : if (dev_conf->dv_flow_en &&
20169 [ # # ]: 0 : (dev_conf->dv_xmeta_en !=
20170 [ # # ]: 0 : MLX5_XMETA_MODE_LEGACY) &&
20171 : 0 : mlx5_flow_ext_mreg_supported(dev))
20172 : 0 : return -rte_mtr_error_set(error,
20173 : : ENOTSUP,
20174 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20175 : : NULL, "Queue action with meta "
20176 : : "is not supported. Please try use "
20177 : : "default policy for meter.");
20178 : 0 : ret = mlx5_flow_validate_action_queue(act,
20179 : : action_flags[i], dev,
20180 : : attr, &flow_err);
20181 [ # # ]: 0 : if (ret < 0)
20182 : 0 : return -rte_mtr_error_set(error,
20183 : : ENOTSUP,
20184 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20185 [ # # ]: 0 : NULL, flow_err.message ?
20186 : : flow_err.message :
20187 : : "Queue action validate check fail");
20188 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_QUEUE;
20189 : 0 : ++actions_n;
20190 : 0 : break;
20191 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
20192 [ # # ]: 0 : if (dev_conf->dv_flow_en &&
20193 [ # # ]: 0 : (dev_conf->dv_xmeta_en !=
20194 [ # # ]: 0 : MLX5_XMETA_MODE_LEGACY) &&
20195 : 0 : mlx5_flow_ext_mreg_supported(dev))
20196 : 0 : return -rte_mtr_error_set(error,
20197 : : ENOTSUP,
20198 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20199 : : NULL, "RSS action with meta "
20200 : : "is not supported. Please try use "
20201 : : "default policy for meter.");
20202 : 0 : ret = mlx5_validate_action_rss(dev, act,
20203 : : &flow_err);
20204 [ # # ]: 0 : if (ret < 0)
20205 : 0 : return -rte_mtr_error_set(error,
20206 : : ENOTSUP,
20207 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20208 [ # # ]: 0 : NULL, flow_err.message ?
20209 : : flow_err.message :
20210 : : "RSS action validate check fail");
20211 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_RSS;
20212 : 0 : ++actions_n;
20213 : : /* Either G or Y will set the RSS. */
20214 : 0 : rss_color[i] = act->conf;
20215 : 0 : break;
20216 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
20217 : 0 : ret = flow_dv_validate_action_jump(dev,
20218 : : NULL, act, action_flags[i],
20219 : : attr, true, &flow_err);
20220 [ # # ]: 0 : if (ret)
20221 : 0 : return -rte_mtr_error_set(error,
20222 : : ENOTSUP,
20223 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20224 [ # # ]: 0 : NULL, flow_err.message ?
20225 : : flow_err.message :
20226 : : "Jump action validate check fail");
20227 : 0 : ++actions_n;
20228 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_JUMP;
20229 : 0 : break;
20230 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
20231 : 0 : mtr = act->conf;
20232 [ # # # # ]: 0 : if (next_mtr && next_mtr->mtr_id != mtr->mtr_id)
20233 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20234 : : RTE_MTR_ERROR_TYPE_METER_POLICY, NULL,
20235 : : "Green and Yellow must use the same meter.");
20236 : 0 : ret = flow_dv_validate_policy_mtr_hierarchy(dev,
20237 : 0 : mtr->mtr_id,
20238 : : action_flags[i],
20239 : : is_rss,
20240 : : &hierarchy_domain,
20241 : : error);
20242 [ # # ]: 0 : if (ret)
20243 : 0 : return ret;
20244 : 0 : ++actions_n;
20245 : 0 : action_flags[i] |=
20246 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
20247 : : next_mtr = mtr;
20248 : 0 : break;
20249 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
20250 : 0 : ret = flow_dv_validate_action_modify_field(dev,
20251 : : action_flags[i], act, attr, is_root, &flow_err);
20252 [ # # ]: 0 : if (ret < 0)
20253 : 0 : return -rte_mtr_error_set(error,
20254 : : ENOTSUP,
20255 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20256 [ # # ]: 0 : NULL, flow_err.message ?
20257 : : flow_err.message :
20258 : : "Modify field action validate check fail");
20259 : 0 : ++actions_n;
20260 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_MODIFY_FIELD;
20261 : 0 : break;
20262 : : default:
20263 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20264 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20265 : : NULL,
20266 : : "Doesn't support optional action");
20267 : : }
20268 : : }
20269 [ # # ]: 0 : if (action_flags[i] & MLX5_FLOW_ACTION_PORT_ID) {
20270 : 0 : domain_color[i] = MLX5_MTR_DOMAIN_TRANSFER_BIT;
20271 [ # # ]: 0 : } else if ((action_flags[i] &
20272 : 0 : (MLX5_FLOW_ACTION_RSS | MLX5_FLOW_ACTION_QUEUE)) ||
20273 [ # # ]: 0 : (action_flags[i] & MLX5_FLOW_ACTION_MARK)) {
20274 : : /*
20275 : : * Only support MLX5_XMETA_MODE_LEGACY
20276 : : * so MARK action is only in ingress domain.
20277 : : */
20278 : 0 : domain_color[i] = MLX5_MTR_DOMAIN_INGRESS_BIT;
20279 : : } else {
20280 : 0 : domain_color[i] = def_domain;
20281 [ # # ]: 0 : if (action_flags[i] &&
20282 [ # # ]: 0 : !(action_flags[i] & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
20283 : 0 : domain_color[i] &=
20284 : : ~MLX5_MTR_DOMAIN_TRANSFER_BIT;
20285 : : }
20286 [ # # ]: 0 : if (action_flags[i] &
20287 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
20288 : 0 : domain_color[i] &= hierarchy_domain;
20289 : : /*
20290 : : * Non-termination actions only support NIC Tx domain.
20291 : : * The adjustion should be skipped when there is no
20292 : : * action or only END is provided. The default domains
20293 : : * bit-mask is set to find the MIN intersection.
20294 : : * The action flags checking should also be skipped.
20295 : : */
20296 [ # # ]: 0 : if ((def_green && i == RTE_COLOR_GREEN) ||
20297 [ # # ]: 0 : (def_yellow && i == RTE_COLOR_YELLOW))
20298 : 0 : continue;
20299 : : /*
20300 : : * Validate the drop action mutual exclusion
20301 : : * with other actions. Drop action is mutually-exclusive
20302 : : * with any other action, except for Count action.
20303 : : */
20304 [ # # ]: 0 : if ((action_flags[i] & MLX5_FLOW_ACTION_DROP) &&
20305 [ # # ]: 0 : (action_flags[i] & ~MLX5_FLOW_ACTION_DROP)) {
20306 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20307 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20308 : : NULL, "Drop action is mutually-exclusive "
20309 : : "with any other action");
20310 : : }
20311 : : /* Eswitch has few restrictions on using items and actions */
20312 [ # # ]: 0 : if (domain_color[i] & MLX5_MTR_DOMAIN_TRANSFER_BIT) {
20313 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev) &&
20314 [ # # ]: 0 : action_flags[i] & MLX5_FLOW_ACTION_MARK)
20315 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20316 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20317 : : NULL, "unsupported action MARK");
20318 [ # # ]: 0 : if (action_flags[i] & MLX5_FLOW_ACTION_QUEUE)
20319 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20320 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20321 : : NULL, "unsupported action QUEUE");
20322 [ # # ]: 0 : if (action_flags[i] & MLX5_FLOW_ACTION_RSS)
20323 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20324 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20325 : : NULL, "unsupported action RSS");
20326 [ # # ]: 0 : if (!(action_flags[i] & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
20327 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20328 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20329 : : NULL, "no fate action is found");
20330 : : } else {
20331 [ # # # # ]: 0 : if (!(action_flags[i] & MLX5_FLOW_FATE_ACTIONS) &&
20332 : : (domain_color[i] & MLX5_MTR_DOMAIN_INGRESS_BIT)) {
20333 [ # # ]: 0 : if ((domain_color[i] &
20334 : : MLX5_MTR_DOMAIN_EGRESS_BIT))
20335 : 0 : domain_color[i] =
20336 : : MLX5_MTR_DOMAIN_EGRESS_BIT;
20337 : : else
20338 : 0 : return -rte_mtr_error_set(error,
20339 : : ENOTSUP,
20340 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20341 : : NULL,
20342 : : "no fate action is found");
20343 : : }
20344 : : }
20345 : : }
20346 [ # # # # ]: 0 : if (next_mtr && *policy_mode == MLX5_MTR_POLICY_MODE_ALL) {
20347 : : uint64_t hierarchy_type_flag =
20348 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY | MLX5_FLOW_ACTION_JUMP;
20349 [ # # ]: 0 : if (!(action_flags[RTE_COLOR_GREEN] & hierarchy_type_flag) ||
20350 [ # # ]: 0 : !(action_flags[RTE_COLOR_YELLOW] & hierarchy_type_flag))
20351 : 0 : return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_METER_POLICY,
20352 : : NULL,
20353 : : "Unsupported action in meter hierarchy.");
20354 : : }
20355 : : /* If both colors have RSS, the attributes should be the same. */
20356 [ # # ]: 0 : if (flow_dv_mtr_policy_rss_compare(rss_color[RTE_COLOR_GREEN],
20357 : : rss_color[RTE_COLOR_YELLOW]))
20358 : 0 : return -rte_mtr_error_set(error, EINVAL,
20359 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20360 : : NULL, "policy RSS attr conflict");
20361 [ # # # # ]: 0 : if (rss_color[RTE_COLOR_GREEN] || rss_color[RTE_COLOR_YELLOW])
20362 : 0 : *is_rss = true;
20363 : : /* "domain_color[C]" is non-zero for each color, default is ALL. */
20364 [ # # ]: 0 : if (!def_green && !def_yellow &&
20365 [ # # ]: 0 : domain_color[RTE_COLOR_GREEN] != domain_color[RTE_COLOR_YELLOW] &&
20366 [ # # ]: 0 : !(action_flags[RTE_COLOR_GREEN] & MLX5_FLOW_ACTION_DROP) &&
20367 [ # # ]: 0 : !(action_flags[RTE_COLOR_YELLOW] & MLX5_FLOW_ACTION_DROP))
20368 : 0 : return -rte_mtr_error_set(error, EINVAL,
20369 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20370 : : NULL, "policy domains conflict");
20371 : : /*
20372 : : * At least one color policy is listed in the actions, the domains
20373 : : * to be supported should be the intersection.
20374 : : */
20375 : 0 : *domain_bitmap = domain_color[RTE_COLOR_GREEN] &
20376 : 0 : domain_color[RTE_COLOR_YELLOW];
20377 : 0 : return 0;
20378 : : }
20379 : :
20380 : : static int
20381 : 0 : flow_dv_sync_domain(struct rte_eth_dev *dev, uint32_t domains, uint32_t flags)
20382 : : {
20383 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
20384 : : int ret = 0;
20385 : :
20386 [ # # # # ]: 0 : if ((domains & RTE_PMD_MLX5_DOMAIN_BIT_NIC_RX) && priv->sh->rx_domain != NULL) {
20387 : : ret = mlx5_os_flow_dr_sync_domain(priv->sh->rx_domain,
20388 : : flags);
20389 [ # # ]: 0 : if (ret != 0)
20390 : : return ret;
20391 : : }
20392 [ # # # # ]: 0 : if ((domains & RTE_PMD_MLX5_DOMAIN_BIT_NIC_TX) && priv->sh->tx_domain != NULL) {
20393 : : ret = mlx5_os_flow_dr_sync_domain(priv->sh->tx_domain, flags);
20394 [ # # ]: 0 : if (ret != 0)
20395 : : return ret;
20396 : : }
20397 [ # # # # ]: 0 : if ((domains & RTE_PMD_MLX5_DOMAIN_BIT_FDB) && priv->sh->fdb_domain != NULL) {
20398 : : ret = mlx5_os_flow_dr_sync_domain(priv->sh->fdb_domain, flags);
20399 [ # # ]: 0 : if (ret != 0)
20400 : 0 : return ret;
20401 : : }
20402 : : return 0;
20403 : : }
20404 : :
20405 : : /**
20406 : : * Discover the number of available flow priorities
20407 : : * by trying to create a flow with the highest priority value
20408 : : * for each possible number.
20409 : : *
20410 : : * @param[in] dev
20411 : : * Ethernet device.
20412 : : * @param[in] vprio
20413 : : * List of possible number of available priorities.
20414 : : * @param[in] vprio_n
20415 : : * Size of @p vprio array.
20416 : : * @return
20417 : : * On success, number of available flow priorities.
20418 : : * On failure, a negative errno-style code and rte_errno is set.
20419 : : */
20420 : : static int
20421 : 0 : flow_dv_discover_priorities(struct rte_eth_dev *dev,
20422 : : const uint16_t *vprio, int vprio_n)
20423 : : {
20424 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
20425 : 0 : struct mlx5_indexed_pool *pool = priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW];
20426 : : struct rte_flow_item_eth eth;
20427 : 0 : struct rte_flow_item item = {
20428 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
20429 : : .spec = ð,
20430 : : .mask = ð,
20431 : : };
20432 : 0 : struct mlx5_flow_dv_matcher matcher = {
20433 : : .mask = {
20434 : : .size = sizeof(matcher.mask.buf),
20435 : : },
20436 : : };
20437 : : union mlx5_flow_tbl_key tbl_key;
20438 : : struct mlx5_flow flow;
20439 : : void *action;
20440 : : struct rte_flow_error error;
20441 : : uint8_t misc_mask;
20442 : : int i, err, ret = -ENOTSUP;
20443 : :
20444 : : /*
20445 : : * Prepare a flow with a catch-all pattern and a drop action.
20446 : : * Use drop queue, because shared drop action may be unavailable.
20447 : : */
20448 : 0 : action = priv->drop_queue.hrxq->action;
20449 [ # # ]: 0 : if (action == NULL) {
20450 : 0 : DRV_LOG(ERR, "Priority discovery requires a drop action");
20451 : 0 : rte_errno = ENOTSUP;
20452 : 0 : return -rte_errno;
20453 : : }
20454 : : memset(&flow, 0, sizeof(flow));
20455 : 0 : flow.handle = mlx5_ipool_zmalloc(pool, &flow.handle_idx);
20456 [ # # ]: 0 : if (flow.handle == NULL) {
20457 : 0 : DRV_LOG(ERR, "Cannot create flow handle");
20458 : 0 : rte_errno = ENOMEM;
20459 : 0 : return -rte_errno;
20460 : : }
20461 : 0 : flow.ingress = true;
20462 : 0 : flow.dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param);
20463 : 0 : flow.dv.actions[0] = action;
20464 : 0 : flow.dv.actions_n = 1;
20465 : : memset(ð, 0, sizeof(eth));
20466 : 0 : flow_dv_translate_item_eth(matcher.mask.buf, &item,
20467 : : /* inner */ false, /* group */ 0,
20468 : : MLX5_SET_MATCHER_SW_M);
20469 : 0 : flow_dv_translate_item_eth(flow.dv.value.buf, &item,
20470 : : /* inner */ false, /* group */ 0,
20471 : : MLX5_SET_MATCHER_SW_V);
20472 : 0 : matcher.crc = rte_raw_cksum(matcher.mask.buf, matcher.mask.size);
20473 [ # # ]: 0 : for (i = 0; i < vprio_n; i++) {
20474 : : /* Configure the next proposed maximum priority. */
20475 : 0 : matcher.priority = vprio[i] - 1;
20476 : : memset(&tbl_key, 0, sizeof(tbl_key));
20477 : 0 : err = flow_dv_matcher_register(dev, &matcher, &tbl_key, &flow,
20478 : : /* tunnel */ NULL,
20479 : : /* group */ 0,
20480 : : &error);
20481 [ # # ]: 0 : if (err != 0) {
20482 : : /* This action is pure SW and must always succeed. */
20483 : 0 : DRV_LOG(ERR, "Cannot register matcher");
20484 : 0 : ret = -rte_errno;
20485 : 0 : break;
20486 : : }
20487 : : /* Try to apply the flow to HW. */
20488 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(flow.handle->dvh.matcher->mask.buf);
20489 : : __flow_dv_adjust_buf_size(&flow.dv.value.size, misc_mask);
20490 : 0 : err = mlx5_flow_os_create_flow
20491 : : (flow.handle->dvh.matcher->matcher_object,
20492 : 0 : (void *)&flow.dv.value, flow.dv.actions_n,
20493 : : flow.dv.actions, &flow.handle->drv_flow);
20494 : : if (err == 0) {
20495 : 0 : claim_zero(mlx5_flow_os_destroy_flow
20496 : : (flow.handle->drv_flow));
20497 : 0 : flow.handle->drv_flow = NULL;
20498 : : }
20499 : 0 : claim_zero(flow_dv_matcher_release(dev, flow.handle));
20500 [ # # ]: 0 : if (err != 0)
20501 : : break;
20502 : 0 : ret = vprio[i];
20503 : : }
20504 : 0 : mlx5_ipool_free(pool, flow.handle_idx);
20505 : : /* Set rte_errno if no expected priority value matched. */
20506 [ # # ]: 0 : if (ret < 0)
20507 : 0 : rte_errno = -ret;
20508 : : return ret;
20509 : : }
20510 : :
20511 : : const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops = {
20512 : : .list_create = flow_legacy_list_create,
20513 : : .list_destroy = flow_legacy_list_destroy,
20514 : : .validate = flow_dv_validate,
20515 : : .prepare = flow_dv_prepare,
20516 : : .translate = flow_dv_translate,
20517 : : .apply = flow_dv_apply,
20518 : : .remove = flow_dv_remove,
20519 : : .destroy = flow_dv_destroy,
20520 : : .query = flow_dv_query,
20521 : : .create_mtr_tbls = flow_dv_create_mtr_tbls,
20522 : : .destroy_mtr_tbls = flow_dv_destroy_mtr_tbls,
20523 : : .destroy_mtr_drop_tbls = flow_dv_destroy_mtr_drop_tbls,
20524 : : .create_meter = flow_dv_mtr_alloc,
20525 : : .free_meter = flow_dv_aso_mtr_release_to_pool,
20526 : : .validate_mtr_acts = flow_dv_validate_mtr_policy_acts,
20527 : : .create_mtr_acts = flow_dv_create_mtr_policy_acts,
20528 : : .destroy_mtr_acts = flow_dv_destroy_mtr_policy_acts,
20529 : : .create_policy_rules = flow_dv_create_policy_rules,
20530 : : .destroy_policy_rules = flow_dv_destroy_policy_rules,
20531 : : .create_def_policy = flow_dv_create_def_policy,
20532 : : .destroy_def_policy = flow_dv_destroy_def_policy,
20533 : : .meter_sub_policy_rss_prepare = flow_dv_meter_sub_policy_rss_prepare,
20534 : : .meter_hierarchy_rule_create = flow_dv_meter_hierarchy_rule_create,
20535 : : .destroy_sub_policy_with_rxq = flow_dv_destroy_sub_policy_with_rxq,
20536 : : .counter_alloc = flow_dv_counter_allocate,
20537 : : .counter_free = flow_dv_counter_free,
20538 : : .counter_query = flow_dv_counter_query,
20539 : : .get_aged_flows = flow_dv_get_aged_flows,
20540 : : .action_validate = flow_dv_action_validate,
20541 : : .action_create = flow_dv_action_create,
20542 : : .action_destroy = flow_dv_action_destroy,
20543 : : .action_update = flow_dv_action_update,
20544 : : .action_query = flow_dv_action_query,
20545 : : .sync_domain = flow_dv_sync_domain,
20546 : : .discover_priorities = flow_dv_discover_priorities,
20547 : : .item_create = flow_dv_item_create,
20548 : : .item_release = flow_dv_item_release,
20549 : : };
20550 : :
20551 : : #endif /* HAVE_IBV_FLOW_DV_SUPPORT */
|