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 [ # # ]: 0 : if (spec->flags & ~MLX5_FLOW_CONNTRACK_PKT_STATE_ALL)
3293 : 0 : return rte_flow_error_set(error, EINVAL,
3294 : : RTE_FLOW_ERROR_TYPE_ITEM,
3295 : : NULL,
3296 : : "Invalid CT item flags");
3297 : : }
3298 : : /* State change also needs to be considered. */
3299 : 0 : *item_flags |= MLX5_FLOW_LAYER_ASO_CT;
3300 : 0 : return 0;
3301 : : }
3302 : :
3303 : : /**
3304 : : * Validate the pop VLAN action.
3305 : : *
3306 : : * @param[in] dev
3307 : : * Pointer to the rte_eth_dev structure.
3308 : : * @param[in] action_flags
3309 : : * Holds the actions detected until now.
3310 : : * @param[in] action
3311 : : * Pointer to the pop vlan action.
3312 : : * @param[in] item_flags
3313 : : * The items found in this flow rule.
3314 : : * @param[in] attr
3315 : : * Pointer to flow attributes.
3316 : : * @param[out] error
3317 : : * Pointer to error structure.
3318 : : *
3319 : : * @return
3320 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3321 : : */
3322 : : static int
3323 : 0 : flow_dv_validate_action_pop_vlan(struct rte_eth_dev *dev,
3324 : : uint64_t action_flags,
3325 : : const struct rte_flow_action *action,
3326 : : uint64_t item_flags,
3327 : : const struct rte_flow_attr *attr,
3328 : : struct rte_flow_error *error)
3329 : : {
3330 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
3331 : :
3332 [ # # ]: 0 : if (!priv->sh->pop_vlan_action)
3333 : 0 : return rte_flow_error_set(error, ENOTSUP,
3334 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3335 : : NULL,
3336 : : "pop vlan action is not supported");
3337 [ # # ]: 0 : if (action_flags & MLX5_FLOW_VLAN_ACTIONS)
3338 : 0 : return rte_flow_error_set(error, ENOTSUP,
3339 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3340 : : "no support for multiple VLAN "
3341 : : "actions");
3342 : : /* Pop VLAN with preceding Decap requires inner header with VLAN. */
3343 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_DECAP) &&
3344 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_INNER_VLAN))
3345 : 0 : return rte_flow_error_set(error, ENOTSUP,
3346 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3347 : : NULL,
3348 : : "cannot pop vlan after decap without "
3349 : : "match on inner vlan in the flow");
3350 : : /* Pop VLAN without preceding Decap requires outer header with VLAN. */
3351 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_ACTION_DECAP) &&
3352 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
3353 : 0 : return rte_flow_error_set(error, ENOTSUP,
3354 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3355 : : NULL,
3356 : : "cannot pop vlan without a "
3357 : : "match on (outer) vlan in the flow");
3358 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3359 : 0 : return rte_flow_error_set(error, EINVAL,
3360 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3361 : : "wrong action order, port_id should "
3362 : : "be after pop VLAN action");
3363 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
3364 : 0 : return rte_flow_error_set(error, ENOTSUP,
3365 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3366 : : "pop vlan action for VF representor "
3367 : : "not supported on NIC table");
3368 : : return 0;
3369 : : }
3370 : :
3371 : : /**
3372 : : * Get VLAN default info from vlan match info.
3373 : : *
3374 : : * @param[in] items
3375 : : * the list of item specifications.
3376 : : * @param[out] vlan
3377 : : * pointer VLAN info to fill to.
3378 : : *
3379 : : * @return
3380 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3381 : : */
3382 : : static void
3383 : 0 : flow_dev_get_vlan_info_from_items(const struct rte_flow_item *items,
3384 : : struct rte_vlan_hdr *vlan)
3385 : : {
3386 : 0 : const struct rte_flow_item_vlan nic_mask = {
3387 : : .hdr.vlan_tci = RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK |
3388 : : MLX5DV_FLOW_VLAN_VID_MASK),
3389 : : .hdr.eth_proto = RTE_BE16(0xffff),
3390 : : };
3391 : :
3392 [ # # ]: 0 : if (items == NULL)
3393 : 0 : return;
3394 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
3395 : 0 : int type = items->type;
3396 : :
3397 : 0 : if (type == RTE_FLOW_ITEM_TYPE_VLAN ||
3398 [ # # ]: 0 : type == MLX5_RTE_FLOW_ITEM_TYPE_VLAN)
3399 : : break;
3400 : : }
3401 [ # # ]: 0 : if (items->type != RTE_FLOW_ITEM_TYPE_END) {
3402 : 0 : const struct rte_flow_item_vlan *vlan_m = items->mask;
3403 : 0 : const struct rte_flow_item_vlan *vlan_v = items->spec;
3404 : :
3405 : : /* If VLAN item in pattern doesn't contain data, return here. */
3406 [ # # ]: 0 : if (!vlan_v)
3407 : : return;
3408 [ # # ]: 0 : if (!vlan_m)
3409 : : vlan_m = &nic_mask;
3410 : : /* Only full match values are accepted */
3411 [ # # ]: 0 : if ((vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) ==
3412 : : MLX5DV_FLOW_VLAN_PCP_MASK_BE) {
3413 : 0 : vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
3414 : 0 : vlan->vlan_tci |=
3415 [ # # ]: 0 : rte_be_to_cpu_16(vlan_v->hdr.vlan_tci &
3416 : : MLX5DV_FLOW_VLAN_PCP_MASK_BE);
3417 : : }
3418 [ # # ]: 0 : if ((vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) ==
3419 : : MLX5DV_FLOW_VLAN_VID_MASK_BE) {
3420 : 0 : vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
3421 : 0 : vlan->vlan_tci |=
3422 [ # # ]: 0 : rte_be_to_cpu_16(vlan_v->hdr.vlan_tci &
3423 : : MLX5DV_FLOW_VLAN_VID_MASK_BE);
3424 : : }
3425 [ # # ]: 0 : if (vlan_m->hdr.eth_proto == nic_mask.hdr.eth_proto)
3426 [ # # ]: 0 : vlan->eth_proto = rte_be_to_cpu_16(vlan_v->hdr.eth_proto &
3427 : : vlan_m->hdr.eth_proto);
3428 : : }
3429 : : }
3430 : :
3431 : : /**
3432 : : * Validate the push VLAN action.
3433 : : *
3434 : : * @param[in] dev
3435 : : * Pointer to the rte_eth_dev structure.
3436 : : * @param[in] action_flags
3437 : : * Holds the actions detected until now.
3438 : : * @param[in] item_flags
3439 : : * The items found in this flow rule.
3440 : : * @param[in] action
3441 : : * Pointer to the action structure.
3442 : : * @param[in] attr
3443 : : * Pointer to flow attributes
3444 : : * @param[out] error
3445 : : * Pointer to error structure.
3446 : : *
3447 : : * @return
3448 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3449 : : */
3450 : : static int
3451 : 0 : flow_dv_validate_action_push_vlan(struct rte_eth_dev *dev,
3452 : : uint64_t action_flags,
3453 : : const struct rte_flow_item_vlan *vlan_m,
3454 : : const struct rte_flow_action *action,
3455 : : const struct rte_flow_attr *attr,
3456 : : struct rte_flow_error *error)
3457 : : {
3458 : 0 : const struct rte_flow_action_of_push_vlan *push_vlan = action->conf;
3459 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
3460 : :
3461 [ # # ]: 0 : if (push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_VLAN) &&
3462 : : push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_QINQ))
3463 : 0 : return rte_flow_error_set(error, EINVAL,
3464 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3465 : : "invalid vlan ethertype");
3466 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3467 : 0 : return rte_flow_error_set(error, EINVAL,
3468 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3469 : : "wrong action order, port_id should "
3470 : : "be after push VLAN");
3471 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
3472 : 0 : return rte_flow_error_set(error, ENOTSUP,
3473 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3474 : : "push vlan action for VF representor "
3475 : : "not supported on NIC table");
3476 [ # # ]: 0 : if (vlan_m &&
3477 [ # # # # ]: 0 : (vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) &&
3478 : : (vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) !=
3479 : 0 : MLX5DV_FLOW_VLAN_PCP_MASK_BE &&
3480 [ # # # # ]: 0 : !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP) &&
3481 : 0 : !(mlx5_flow_find_action
3482 : : (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP)))
3483 : 0 : return rte_flow_error_set(error, EINVAL,
3484 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3485 : : "not full match mask on VLAN PCP and "
3486 : : "there is no of_set_vlan_pcp action, "
3487 : : "push VLAN action cannot figure out "
3488 : : "PCP value");
3489 [ # # ]: 0 : if (vlan_m &&
3490 [ # # # # ]: 0 : (vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) &&
3491 : : (vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) !=
3492 : 0 : MLX5DV_FLOW_VLAN_VID_MASK_BE &&
3493 [ # # # # ]: 0 : !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID) &&
3494 : 0 : !(mlx5_flow_find_action
3495 : : (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID)))
3496 : 0 : return rte_flow_error_set(error, EINVAL,
3497 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3498 : : "not full match mask on VLAN VID and "
3499 : : "there is no of_set_vlan_vid action, "
3500 : : "push VLAN action cannot figure out "
3501 : : "VID value");
3502 : : (void)attr;
3503 : : return 0;
3504 : : }
3505 : :
3506 : : /**
3507 : : * Validate the set VLAN PCP.
3508 : : *
3509 : : * @param[in] action_flags
3510 : : * Holds the actions detected until now.
3511 : : * @param[in] actions
3512 : : * Pointer to the list of actions remaining in the flow rule.
3513 : : * @param[out] error
3514 : : * Pointer to error structure.
3515 : : *
3516 : : * @return
3517 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3518 : : */
3519 : : static int
3520 : 0 : flow_dv_validate_action_set_vlan_pcp(uint64_t action_flags,
3521 : : const struct rte_flow_action actions[],
3522 : : struct rte_flow_error *error)
3523 : : {
3524 : : const struct rte_flow_action *action = actions;
3525 : 0 : const struct rte_flow_action_of_set_vlan_pcp *conf = action->conf;
3526 : :
3527 [ # # ]: 0 : if (conf->vlan_pcp > 7)
3528 : 0 : return rte_flow_error_set(error, EINVAL,
3529 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3530 : : "VLAN PCP value is too big");
3531 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN))
3532 : 0 : return rte_flow_error_set(error, ENOTSUP,
3533 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3534 : : "set VLAN PCP action must follow "
3535 : : "the push VLAN action");
3536 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP)
3537 : 0 : return rte_flow_error_set(error, ENOTSUP,
3538 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3539 : : "Multiple VLAN PCP modification are "
3540 : : "not supported");
3541 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3542 : 0 : return rte_flow_error_set(error, EINVAL,
3543 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3544 : : "wrong action order, port_id should "
3545 : : "be after set VLAN PCP");
3546 : : return 0;
3547 : : }
3548 : :
3549 : : /**
3550 : : * Validate the set VLAN VID.
3551 : : *
3552 : : * @param[in] item_flags
3553 : : * Holds the items detected in this rule.
3554 : : * @param[in] action_flags
3555 : : * Holds the actions detected until now.
3556 : : * @param[in] actions
3557 : : * Pointer to the list of actions remaining in the flow rule.
3558 : : * @param[out] error
3559 : : * Pointer to error structure.
3560 : : *
3561 : : * @return
3562 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3563 : : */
3564 : : static int
3565 : 0 : flow_dv_validate_action_set_vlan_vid(uint64_t item_flags,
3566 : : uint64_t action_flags,
3567 : : const struct rte_flow_action actions[],
3568 : : struct rte_flow_error *error)
3569 : : {
3570 : : const struct rte_flow_action *action = actions;
3571 : 0 : const struct rte_flow_action_of_set_vlan_vid *conf = action->conf;
3572 : :
3573 [ # # # # ]: 0 : if (rte_be_to_cpu_16(conf->vlan_vid) > 0xFFE)
3574 : 0 : return rte_flow_error_set(error, EINVAL,
3575 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3576 : : "VLAN VID value is too big");
3577 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) &&
3578 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
3579 : 0 : return rte_flow_error_set(error, ENOTSUP,
3580 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3581 : : "set VLAN VID action must follow push"
3582 : : " VLAN action or match on VLAN item");
3583 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID)
3584 : 0 : return rte_flow_error_set(error, ENOTSUP,
3585 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3586 : : "Multiple VLAN VID modifications are "
3587 : : "not supported");
3588 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3589 : 0 : return rte_flow_error_set(error, EINVAL,
3590 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3591 : : "wrong action order, port_id should "
3592 : : "be after set VLAN VID");
3593 : : return 0;
3594 : : }
3595 : :
3596 : : /*
3597 : : * Validate the FLAG action.
3598 : : *
3599 : : * @param[in] dev
3600 : : * Pointer to the rte_eth_dev structure.
3601 : : * @param[in] action_flags
3602 : : * Holds the actions detected until now.
3603 : : * @param[in] attr
3604 : : * Pointer to flow attributes
3605 : : * @param[out] error
3606 : : * Pointer to error structure.
3607 : : *
3608 : : * @return
3609 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3610 : : */
3611 : : static int
3612 : 0 : flow_dv_validate_action_flag(struct rte_eth_dev *dev,
3613 : : uint64_t action_flags,
3614 : : const struct rte_flow_attr *attr,
3615 : : struct rte_flow_error *error)
3616 : : {
3617 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3618 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
3619 : : int ret;
3620 : :
3621 : : /* Fall back if no extended metadata register support. */
3622 [ # # ]: 0 : if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
3623 : 0 : return mlx5_flow_validate_action_flag(action_flags, attr,
3624 : : error);
3625 : : /* Extensive metadata mode requires registers. */
3626 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
3627 : 0 : return rte_flow_error_set(error, ENOTSUP,
3628 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3629 : : "no metadata registers "
3630 : : "to support flag action");
3631 [ # # ]: 0 : if (!(priv->sh->dv_mark_mask & MLX5_FLOW_MARK_DEFAULT))
3632 : 0 : return rte_flow_error_set(error, ENOTSUP,
3633 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3634 : : "extended metadata register"
3635 : : " isn't available");
3636 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3637 [ # # ]: 0 : if (ret < 0)
3638 : : return ret;
3639 : : MLX5_ASSERT(ret > 0);
3640 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
3641 : 0 : return rte_flow_error_set(error, EINVAL,
3642 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3643 : : "can't mark and flag in same flow");
3644 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_FLAG)
3645 : 0 : return rte_flow_error_set(error, EINVAL,
3646 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3647 : : "can't have 2 flag"
3648 : : " actions in same flow");
3649 : : return 0;
3650 : : }
3651 : :
3652 : : /**
3653 : : * Validate MARK action.
3654 : : *
3655 : : * @param[in] dev
3656 : : * Pointer to the rte_eth_dev structure.
3657 : : * @param[in] action
3658 : : * Pointer to action.
3659 : : * @param[in] action_flags
3660 : : * Holds the actions detected until now.
3661 : : * @param[in] attr
3662 : : * Pointer to flow attributes
3663 : : * @param[out] error
3664 : : * Pointer to error structure.
3665 : : *
3666 : : * @return
3667 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3668 : : */
3669 : : static int
3670 : 0 : flow_dv_validate_action_mark(struct rte_eth_dev *dev,
3671 : : const struct rte_flow_action *action,
3672 : : uint64_t action_flags,
3673 : : const struct rte_flow_attr *attr,
3674 : : struct rte_flow_error *error)
3675 : : {
3676 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3677 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
3678 [ # # ]: 0 : const struct rte_flow_action_mark *mark = action->conf;
3679 : : int ret;
3680 : :
3681 [ # # ]: 0 : if (is_tunnel_offload_active(dev))
3682 : 0 : return rte_flow_error_set(error, ENOTSUP,
3683 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3684 : : "no mark action "
3685 : : "if tunnel offload active");
3686 : : /* Fall back if no extended metadata register support. */
3687 [ # # ]: 0 : if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
3688 : 0 : return mlx5_flow_validate_action_mark(dev, action, action_flags,
3689 : : attr, error);
3690 : : /* Extensive metadata mode requires registers. */
3691 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
3692 : 0 : return rte_flow_error_set(error, ENOTSUP,
3693 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3694 : : "no metadata registers "
3695 : : "to support mark action");
3696 [ # # ]: 0 : if (!priv->sh->dv_mark_mask)
3697 : 0 : return rte_flow_error_set(error, ENOTSUP,
3698 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3699 : : "extended metadata register"
3700 : : " isn't available");
3701 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3702 [ # # ]: 0 : if (ret < 0)
3703 : : return ret;
3704 : : MLX5_ASSERT(ret > 0);
3705 [ # # ]: 0 : if (!mark)
3706 : 0 : return rte_flow_error_set(error, EINVAL,
3707 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3708 : : "configuration cannot be null");
3709 [ # # ]: 0 : if (mark->id >= (MLX5_FLOW_MARK_MAX & priv->sh->dv_mark_mask))
3710 : 0 : return rte_flow_error_set(error, EINVAL,
3711 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3712 : 0 : &mark->id,
3713 : : "mark id exceeds the limit");
3714 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_FLAG)
3715 : 0 : return rte_flow_error_set(error, EINVAL,
3716 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3717 : : "can't flag and mark in same flow");
3718 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
3719 : 0 : return rte_flow_error_set(error, EINVAL,
3720 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3721 : : "can't have 2 mark actions in same"
3722 : : " flow");
3723 : : return 0;
3724 : : }
3725 : :
3726 : : /**
3727 : : * Validate SET_META action.
3728 : : *
3729 : : * @param[in] dev
3730 : : * Pointer to the rte_eth_dev structure.
3731 : : * @param[in] action
3732 : : * Pointer to the action structure.
3733 : : * @param[in] action_flags
3734 : : * Holds the actions detected until now.
3735 : : * @param[in] attr
3736 : : * Pointer to flow attributes
3737 : : * @param[out] error
3738 : : * Pointer to error structure.
3739 : : *
3740 : : * @return
3741 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3742 : : */
3743 : : static int
3744 : 0 : flow_dv_validate_action_set_meta(struct rte_eth_dev *dev,
3745 : : const struct rte_flow_action *action,
3746 : : uint64_t action_flags __rte_unused,
3747 : : const struct rte_flow_attr *attr,
3748 : : struct rte_flow_error *error)
3749 : : {
3750 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3751 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
3752 : : const struct rte_flow_action_set_meta *conf;
3753 : : uint32_t nic_mask = UINT32_MAX;
3754 : : int reg;
3755 : :
3756 [ # # # # ]: 0 : if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
3757 : 0 : !mlx5_flow_ext_mreg_supported(dev))
3758 : 0 : return rte_flow_error_set(error, ENOTSUP,
3759 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3760 : : "extended metadata register"
3761 : : " isn't supported");
3762 : 0 : reg = flow_dv_get_metadata_reg(dev, attr, error);
3763 [ # # ]: 0 : if (reg < 0)
3764 : : return reg;
3765 [ # # ]: 0 : if (reg == REG_NON)
3766 : 0 : return rte_flow_error_set(error, ENOTSUP,
3767 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3768 : : "unavailable extended metadata register");
3769 [ # # ]: 0 : if (reg != REG_A && reg != REG_B) {
3770 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3771 : :
3772 : 0 : nic_mask = priv->sh->dv_meta_mask;
3773 : : }
3774 [ # # ]: 0 : if (!(action->conf))
3775 : 0 : return rte_flow_error_set(error, EINVAL,
3776 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3777 : : "configuration cannot be null");
3778 : : conf = (const struct rte_flow_action_set_meta *)action->conf;
3779 [ # # ]: 0 : if (!conf->mask)
3780 : 0 : return rte_flow_error_set(error, EINVAL,
3781 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3782 : : "zero mask doesn't have any effect");
3783 [ # # ]: 0 : if (conf->mask & ~nic_mask)
3784 : 0 : return rte_flow_error_set(error, EINVAL,
3785 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3786 : : "meta data must be within reg C0");
3787 : : return 0;
3788 : : }
3789 : :
3790 : : /**
3791 : : * Validate SET_TAG action.
3792 : : *
3793 : : * @param[in] dev
3794 : : * Pointer to the rte_eth_dev structure.
3795 : : * @param[in] action
3796 : : * Pointer to the action structure.
3797 : : * @param[in] action_flags
3798 : : * Holds the actions detected until now.
3799 : : * @param[in] attr
3800 : : * Pointer to flow attributes
3801 : : * @param[out] error
3802 : : * Pointer to error structure.
3803 : : *
3804 : : * @return
3805 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3806 : : */
3807 : : static int
3808 : 0 : flow_dv_validate_action_set_tag(struct rte_eth_dev *dev,
3809 : : const struct rte_flow_action *action,
3810 : : uint64_t action_flags,
3811 : : const struct rte_flow_attr *attr,
3812 : : struct rte_flow_error *error)
3813 : : {
3814 : : const struct rte_flow_action_set_tag *conf;
3815 : : const uint64_t terminal_action_flags =
3816 : : MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE |
3817 : : MLX5_FLOW_ACTION_RSS;
3818 : : int ret;
3819 : :
3820 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
3821 : 0 : return rte_flow_error_set(error, ENOTSUP,
3822 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3823 : : "extensive metadata register"
3824 : : " isn't supported");
3825 [ # # ]: 0 : if (!(action->conf))
3826 : 0 : return rte_flow_error_set(error, EINVAL,
3827 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3828 : : "configuration cannot be null");
3829 : : conf = (const struct rte_flow_action_set_tag *)action->conf;
3830 [ # # ]: 0 : if (!conf->mask)
3831 : 0 : return rte_flow_error_set(error, EINVAL,
3832 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3833 : : "zero mask doesn't have any effect");
3834 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
3835 [ # # ]: 0 : if (ret < 0)
3836 : : return ret;
3837 [ # # # # ]: 0 : if (attr->ingress && (action_flags & terminal_action_flags))
3838 : 0 : return rte_flow_error_set(error, EINVAL,
3839 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3840 : : "set_tag has no effect"
3841 : : " with terminal actions");
3842 : : return 0;
3843 : : }
3844 : :
3845 : : /**
3846 : : * Indicates whether ASO aging is supported.
3847 : : *
3848 : : * @param[in] priv
3849 : : * Pointer to device private context structure.
3850 : : * @param[in] root
3851 : : * Whether action is on root table.
3852 : : *
3853 : : * @return
3854 : : * True when ASO aging is supported, false otherwise.
3855 : : */
3856 : : static inline bool
3857 : : flow_hit_aso_supported(const struct mlx5_priv *priv, bool root)
3858 : : {
3859 : : MLX5_ASSERT(priv);
3860 [ # # # # : 0 : return (priv->sh->flow_hit_aso_en && !root);
# # # # #
# ]
3861 : : }
3862 : :
3863 : : /**
3864 : : * Validate count action.
3865 : : *
3866 : : * @param[in] dev
3867 : : * Pointer to rte_eth_dev structure.
3868 : : * @param[in] shared
3869 : : * Indicator if action is shared.
3870 : : * @param[in] action_flags
3871 : : * Holds the actions detected until now.
3872 : : * @param[in] root
3873 : : * Whether action is on root table.
3874 : : * @param[out] error
3875 : : * Pointer to error structure.
3876 : : *
3877 : : * @return
3878 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3879 : : */
3880 : : static int
3881 : 0 : flow_dv_validate_action_count(struct rte_eth_dev *dev, bool shared,
3882 : : uint64_t action_flags,
3883 : : bool root,
3884 : : struct rte_flow_error *error)
3885 : : {
3886 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3887 : :
3888 [ # # ]: 0 : if (!priv->sh->cdev->config.devx)
3889 : 0 : goto notsup_err;
3890 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_COUNT)
3891 : 0 : return rte_flow_error_set(error, EINVAL,
3892 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3893 : : "duplicate count actions set");
3894 [ # # # # : 0 : if (shared && (action_flags & MLX5_FLOW_ACTION_AGE) &&
# # ]
3895 : : !flow_hit_aso_supported(priv, root))
3896 : 0 : return rte_flow_error_set(error, EINVAL,
3897 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3898 : : "old age and indirect count combination is not supported");
3899 : : #ifdef HAVE_IBV_FLOW_DEVX_COUNTERS
3900 : : return 0;
3901 : : #endif
3902 : : notsup_err:
3903 : 0 : return rte_flow_error_set
3904 : : (error, ENOTSUP,
3905 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3906 : : NULL,
3907 : : "count action not supported");
3908 : : }
3909 : :
3910 : : /**
3911 : : * Validate the L2 encap action.
3912 : : *
3913 : : * @param[in] dev
3914 : : * Pointer to the rte_eth_dev structure.
3915 : : * @param[in] action_flags
3916 : : * Holds the actions detected until now.
3917 : : * @param[in] action
3918 : : * Pointer to the action structure.
3919 : : * @param[in] attr
3920 : : * Pointer to flow attributes.
3921 : : * @param[out] error
3922 : : * Pointer to error structure.
3923 : : *
3924 : : * @return
3925 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3926 : : */
3927 : : int
3928 : 0 : mlx5_flow_dv_validate_action_l2_encap(struct rte_eth_dev *dev,
3929 : : uint64_t action_flags,
3930 : : const struct rte_flow_action *action,
3931 : : const struct rte_flow_attr *attr,
3932 : : struct rte_flow_error *error)
3933 : : {
3934 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
3935 : :
3936 [ # # ]: 0 : if (!(action->conf))
3937 : 0 : return rte_flow_error_set(error, EINVAL,
3938 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3939 : : "configuration cannot be null");
3940 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
3941 : 0 : return rte_flow_error_set(error, EINVAL,
3942 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3943 : : "can only have a single encap action "
3944 : : "in a flow");
3945 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
3946 : 0 : return rte_flow_error_set(error, ENOTSUP,
3947 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3948 : : "encap action for VF representor "
3949 : : "not supported on NIC table");
3950 : : return 0;
3951 : : }
3952 : :
3953 : : /**
3954 : : * Validate a decap action.
3955 : : *
3956 : : * @param[in] dev
3957 : : * Pointer to the rte_eth_dev structure.
3958 : : * @param[in] action_flags
3959 : : * Holds the actions detected until now.
3960 : : * @param[in] action
3961 : : * Pointer to the action structure.
3962 : : * @param[in] item_flags
3963 : : * Holds the items detected.
3964 : : * @param[in] attr
3965 : : * Pointer to flow attributes
3966 : : * @param[out] error
3967 : : * Pointer to error structure.
3968 : : *
3969 : : * @return
3970 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3971 : : */
3972 : : int
3973 : 0 : mlx5_flow_dv_validate_action_decap(struct rte_eth_dev *dev,
3974 : : uint64_t action_flags,
3975 : : const struct rte_flow_action *action,
3976 : : const uint64_t item_flags,
3977 : : const struct rte_flow_attr *attr,
3978 : : struct rte_flow_error *error)
3979 : : {
3980 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
3981 : :
3982 [ # # ]: 0 : if (priv->sh->cdev->config.hca_attr.scatter_fcs_w_decap_disable &&
3983 [ # # ]: 0 : !priv->sh->config.decap_en)
3984 : 0 : return rte_flow_error_set(error, ENOTSUP,
3985 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3986 : : "decap is not enabled");
3987 [ # # ]: 0 : if (action_flags & MLX5_FLOW_XCAP_ACTIONS)
3988 : 0 : return rte_flow_error_set(error, ENOTSUP,
3989 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3990 [ # # ]: 0 : action_flags &
3991 : : MLX5_FLOW_ACTION_DECAP ? "can only "
3992 : : "have a single decap action" : "decap "
3993 : : "after encap is not supported");
3994 [ # # ]: 0 : if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
3995 : 0 : return rte_flow_error_set(error, EINVAL,
3996 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3997 : : "can't have decap action after"
3998 : : " modify action");
3999 [ # # ]: 0 : if (attr->egress)
4000 : 0 : return rte_flow_error_set(error, ENOTSUP,
4001 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
4002 : : NULL,
4003 : : "decap action not supported for "
4004 : : "egress");
4005 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
4006 : 0 : return rte_flow_error_set(error, ENOTSUP,
4007 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4008 : : "decap action for VF representor "
4009 : : "not supported on NIC table");
4010 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_DECAP &&
4011 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_VXLAN))
4012 : 0 : return rte_flow_error_set(error, ENOTSUP,
4013 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4014 : : "VXLAN item should be present for VXLAN decap");
4015 : : return 0;
4016 : : }
4017 : :
4018 : : const struct rte_flow_action_raw_decap empty_decap = {.data = NULL, .size = 0,};
4019 : :
4020 : : /**
4021 : : * Validate the raw encap and decap actions.
4022 : : *
4023 : : * @param[in] dev
4024 : : * Pointer to the rte_eth_dev structure.
4025 : : * @param[in] decap
4026 : : * Pointer to the decap action.
4027 : : * @param[in] encap
4028 : : * Pointer to the encap action.
4029 : : * @param[in] attr
4030 : : * Pointer to flow attributes
4031 : : * @param[in/out] action_flags
4032 : : * Holds the actions detected until now.
4033 : : * @param[out] actions_n
4034 : : * pointer to the number of actions counter.
4035 : : * @param[in] action
4036 : : * Pointer to the action structure.
4037 : : * @param[in] item_flags
4038 : : * Holds the items detected.
4039 : : * @param[out] error
4040 : : * Pointer to error structure.
4041 : : *
4042 : : * @return
4043 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4044 : : */
4045 : : int
4046 : 0 : mlx5_flow_dv_validate_action_raw_encap_decap
4047 : : (struct rte_eth_dev *dev,
4048 : : const struct rte_flow_action_raw_decap *decap,
4049 : : const struct rte_flow_action_raw_encap *encap,
4050 : : const struct rte_flow_attr *attr, uint64_t *action_flags,
4051 : : int *actions_n, const struct rte_flow_action *action,
4052 : : uint64_t item_flags, struct rte_flow_error *error)
4053 : : {
4054 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
4055 : : int ret;
4056 : :
4057 [ # # ]: 0 : if (encap) {
4058 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
4059 [ # # # # ]: 0 : if (!encap->size || !encap->data)
4060 : 0 : return rte_flow_error_set
4061 : : (error, EINVAL,
4062 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL, "raw encap data cannot be empty");
4063 : : } else {
4064 [ # # ]: 0 : if (!encap->size)
4065 : 0 : return rte_flow_error_set
4066 : : (error, EINVAL,
4067 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL, "raw encap size cannot be 0");
4068 : : }
4069 : : }
4070 [ # # ]: 0 : if (decap && encap) {
4071 [ # # ]: 0 : if (decap->size <= MLX5_ENCAPSULATION_DECISION_SIZE &&
4072 [ # # ]: 0 : encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4073 : : /* L3 encap. */
4074 : : decap = NULL;
4075 [ # # ]: 0 : else if (encap->size <=
4076 [ # # ]: 0 : MLX5_ENCAPSULATION_DECISION_SIZE &&
4077 : : decap->size >
4078 : : MLX5_ENCAPSULATION_DECISION_SIZE)
4079 : : /* L3 decap. */
4080 : : encap = NULL;
4081 [ # # ]: 0 : else if (encap->size >
4082 [ # # ]: 0 : MLX5_ENCAPSULATION_DECISION_SIZE &&
4083 : : decap->size >
4084 : : MLX5_ENCAPSULATION_DECISION_SIZE)
4085 : : /* 2 L2 actions: encap and decap. */
4086 : : ;
4087 : : else
4088 : 0 : return rte_flow_error_set(error,
4089 : : ENOTSUP,
4090 : : RTE_FLOW_ERROR_TYPE_ACTION,
4091 : : NULL, "unsupported too small "
4092 : : "raw decap and too small raw "
4093 : : "encap combination");
4094 : : }
4095 [ # # ]: 0 : if (decap) {
4096 : 0 : ret = mlx5_flow_dv_validate_action_decap(dev, *action_flags,
4097 : : action,
4098 : : item_flags, attr,
4099 : : error);
4100 [ # # ]: 0 : if (ret < 0)
4101 : : return ret;
4102 : 0 : *action_flags |= MLX5_FLOW_ACTION_DECAP;
4103 : 0 : ++(*actions_n);
4104 : : }
4105 [ # # ]: 0 : if (encap) {
4106 [ # # ]: 0 : if (encap->size <= MLX5_ENCAPSULATION_DECISION_SIZE)
4107 : 0 : return rte_flow_error_set(error, ENOTSUP,
4108 : : RTE_FLOW_ERROR_TYPE_ACTION,
4109 : : NULL,
4110 : : "small raw encap size");
4111 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_ENCAP)
4112 : 0 : return rte_flow_error_set(error, EINVAL,
4113 : : RTE_FLOW_ERROR_TYPE_ACTION,
4114 : : NULL,
4115 : : "more than one encap action");
4116 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
4117 : 0 : return rte_flow_error_set
4118 : : (error, ENOTSUP,
4119 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4120 : : "encap action for VF representor "
4121 : : "not supported on NIC table");
4122 : 0 : *action_flags |= MLX5_FLOW_ACTION_ENCAP;
4123 : 0 : ++(*actions_n);
4124 : : }
4125 : : return 0;
4126 : : }
4127 : :
4128 : : /*
4129 : : * Validate the ASO CT action.
4130 : : *
4131 : : * @param[in] dev
4132 : : * Pointer to the rte_eth_dev structure.
4133 : : * @param[in] action_flags
4134 : : * Holds the actions detected until now.
4135 : : * @param[in] item_flags
4136 : : * The items found in this flow rule.
4137 : : * @param root
4138 : : * Whether action is on root table.
4139 : : * @param[out] error
4140 : : * Pointer to error structure.
4141 : : *
4142 : : * @return
4143 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4144 : : */
4145 : : int
4146 : 0 : mlx5_flow_dv_validate_action_aso_ct(struct rte_eth_dev *dev,
4147 : : uint64_t action_flags,
4148 : : uint64_t item_flags,
4149 : : bool root,
4150 : : struct rte_flow_error *error)
4151 : : {
4152 : : RTE_SET_USED(dev);
4153 : :
4154 [ # # ]: 0 : if (root)
4155 : 0 : return rte_flow_error_set(error, ENOTSUP,
4156 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4157 : : NULL,
4158 : : "Only support non-root table");
4159 [ # # ]: 0 : if (action_flags & MLX5_FLOW_FATE_ACTIONS)
4160 : 0 : return rte_flow_error_set(error, ENOTSUP,
4161 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4162 : : "CT cannot follow a fate action");
4163 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_METER) ||
4164 : : (action_flags & MLX5_FLOW_ACTION_AGE)) {
4165 [ # # ]: 0 : if (!mlx5_hws_active(dev))
4166 : 0 : return rte_flow_error_set(error, EINVAL,
4167 : : RTE_FLOW_ERROR_TYPE_ACTION,
4168 : : NULL, "Only one ASO action is supported");
4169 : : }
4170 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
4171 : 0 : return rte_flow_error_set(error, EINVAL,
4172 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4173 : : "Encap cannot exist before CT");
4174 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP))
4175 : 0 : return rte_flow_error_set(error, EINVAL,
4176 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4177 : : "Not a outer TCP packet");
4178 : : return 0;
4179 : : }
4180 : :
4181 : : /**
4182 : : * Validate METER_COLOR item.
4183 : : *
4184 : : * @param[in] dev
4185 : : * Pointer to the rte_eth_dev structure.
4186 : : * @param[in] item
4187 : : * Item specification.
4188 : : * @param[in] attr
4189 : : * Attributes of flow that includes this item.
4190 : : * @param[out] error
4191 : : * Pointer to error structure.
4192 : : *
4193 : : * @return
4194 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4195 : : */
4196 : : static int
4197 : 0 : flow_dv_validate_item_meter_color(struct rte_eth_dev *dev,
4198 : : const struct rte_flow_item *item,
4199 : : const struct rte_flow_attr *attr __rte_unused,
4200 : : struct rte_flow_error *error)
4201 : : {
4202 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4203 : 0 : const struct rte_flow_item_meter_color *spec = item->spec;
4204 : 0 : const struct rte_flow_item_meter_color *mask = item->mask;
4205 : 0 : struct rte_flow_item_meter_color nic_mask = {
4206 : : .color = RTE_COLORS
4207 : : };
4208 : : int ret;
4209 : :
4210 [ # # ]: 0 : if (priv->sh->registers.aso_reg == REG_NON)
4211 : 0 : return rte_flow_error_set(error, ENOTSUP,
4212 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
4213 : : "meter color register"
4214 : : " isn't available");
4215 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, error);
4216 [ # # ]: 0 : if (ret < 0)
4217 : : return ret;
4218 [ # # ]: 0 : if (!spec)
4219 : 0 : return rte_flow_error_set(error, EINVAL,
4220 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4221 : 0 : item->spec,
4222 : : "data cannot be empty");
4223 [ # # ]: 0 : if (spec->color > RTE_COLORS)
4224 : 0 : return rte_flow_error_set(error, EINVAL,
4225 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4226 : 0 : &spec->color,
4227 : : "meter color is invalid");
4228 [ # # ]: 0 : if (!mask)
4229 : : mask = &rte_flow_item_meter_color_mask;
4230 [ # # ]: 0 : if (!mask->color)
4231 : 0 : return rte_flow_error_set(error, EINVAL,
4232 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
4233 : : "mask cannot be zero");
4234 : :
4235 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
4236 : : (const uint8_t *)&nic_mask,
4237 : : sizeof(struct rte_flow_item_meter_color),
4238 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
4239 : : if (ret < 0)
4240 : : return ret;
4241 : : return 0;
4242 : : }
4243 : :
4244 : : /**
4245 : : * Validate aggregated affinity item.
4246 : : *
4247 : : * @param[in] dev
4248 : : * Pointer to the rte_eth_dev structure.
4249 : : * @param[in] item
4250 : : * Item specification.
4251 : : * @param[in] attr
4252 : : * Attributes of flow that includes this item.
4253 : : * @param[out] error
4254 : : * Pointer to error structure.
4255 : : *
4256 : : * @return
4257 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4258 : : */
4259 : : static int
4260 : 0 : flow_dv_validate_item_aggr_affinity(struct rte_eth_dev *dev,
4261 : : const struct rte_flow_item *item,
4262 : : const struct rte_flow_attr *attr,
4263 : : struct rte_flow_error *error)
4264 : : {
4265 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4266 : 0 : const struct rte_flow_item_aggr_affinity *spec = item->spec;
4267 : 0 : const struct rte_flow_item_aggr_affinity *mask = item->mask;
4268 : 0 : struct rte_flow_item_aggr_affinity nic_mask = {
4269 : : .affinity = UINT8_MAX
4270 : : };
4271 : : int ret;
4272 : :
4273 [ # # ]: 0 : if (!priv->sh->lag_rx_port_affinity_en)
4274 : 0 : return rte_flow_error_set(error, EINVAL,
4275 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
4276 : : "Unsupported aggregated affinity with Older FW");
4277 [ # # # # : 0 : if ((attr->transfer && priv->fdb_def_rule) ||
# # ]
4278 [ # # ]: 0 : attr->egress || attr->group)
4279 : 0 : return rte_flow_error_set(error, ENOTSUP,
4280 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4281 : : item->spec,
4282 : : "aggregated affinity is not supported with egress or FDB on non root table");
4283 [ # # ]: 0 : if (!spec)
4284 : 0 : return rte_flow_error_set(error, EINVAL,
4285 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4286 : : item->spec,
4287 : : "data cannot be empty");
4288 [ # # ]: 0 : if (spec->affinity == 0)
4289 : 0 : return rte_flow_error_set(error, ENOTSUP,
4290 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4291 : : item->spec,
4292 : : "zero affinity number not supported");
4293 [ # # ]: 0 : if (spec->affinity > priv->num_lag_ports)
4294 : 0 : return rte_flow_error_set(error, ENOTSUP,
4295 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4296 : : item->spec,
4297 : : "exceed max affinity number in lag ports");
4298 [ # # ]: 0 : if (!mask)
4299 : : mask = &rte_flow_item_aggr_affinity_mask;
4300 [ # # ]: 0 : if (!mask->affinity)
4301 : 0 : return rte_flow_error_set(error, EINVAL,
4302 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
4303 : : "mask cannot be zero");
4304 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
4305 : : (const uint8_t *)&nic_mask,
4306 : : sizeof(struct rte_flow_item_aggr_affinity),
4307 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
4308 : : if (ret < 0)
4309 : : return ret;
4310 : : return 0;
4311 : : }
4312 : :
4313 : : int
4314 : 0 : flow_encap_decap_match_cb(void *tool_ctx __rte_unused,
4315 : : struct mlx5_list_entry *entry, void *cb_ctx)
4316 : : {
4317 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4318 : 0 : struct mlx5_flow_dv_encap_decap_resource *ctx_resource = ctx->data;
4319 : : struct mlx5_flow_dv_encap_decap_resource *resource;
4320 : :
4321 : : resource = container_of(entry, struct mlx5_flow_dv_encap_decap_resource,
4322 : : entry);
4323 [ # # ]: 0 : if (resource->reformat_type == ctx_resource->reformat_type &&
4324 : 0 : resource->ft_type == ctx_resource->ft_type &&
4325 [ # # ]: 0 : resource->flags == ctx_resource->flags &&
4326 [ # # ]: 0 : resource->size == ctx_resource->size &&
4327 : 0 : !memcmp((const void *)resource->buf,
4328 [ # # ]: 0 : (const void *)ctx_resource->buf,
4329 : : resource->size))
4330 : 0 : return 0;
4331 : : return -1;
4332 : : }
4333 : :
4334 : : struct mlx5_list_entry *
4335 : 0 : flow_encap_decap_create_cb(void *tool_ctx, void *cb_ctx)
4336 : : {
4337 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4338 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4339 : : struct mlx5dv_dr_domain *domain;
4340 : 0 : struct mlx5_flow_dv_encap_decap_resource *ctx_resource = ctx->data;
4341 : : struct mlx5_flow_dv_encap_decap_resource *resource;
4342 : : uint32_t idx;
4343 : : int ret = 0;
4344 : : #ifdef HAVE_MLX5_HWS_SUPPORT
4345 : : struct mlx5dr_action_reformat_header hdr;
4346 : : #endif
4347 : :
4348 : : /* Register new encap/decap resource. */
4349 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], &idx);
4350 [ # # ]: 0 : if (!resource) {
4351 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4352 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4353 : : "cannot allocate resource memory");
4354 : 0 : return NULL;
4355 : : }
4356 : 0 : *resource = *ctx_resource;
4357 [ # # ]: 0 : if (sh->config.dv_flow_en == 2) {
4358 : : #ifdef HAVE_MLX5_HWS_SUPPORT
4359 : 0 : hdr.sz = ctx_resource->size;
4360 : 0 : hdr.data = ctx_resource->buf;
4361 : 0 : resource->action = mlx5dr_action_create_reformat
4362 : 0 : (ctx->data2, (enum mlx5dr_action_type)ctx_resource->reformat_type, 1,
4363 : 0 : &hdr, 0, ctx_resource->flags);
4364 [ # # ]: 0 : if (!resource->action)
4365 : : ret = -1;
4366 : : #else
4367 : : ret = -1;
4368 : : #endif
4369 : : } else {
4370 [ # # ]: 0 : if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
4371 : 0 : domain = sh->fdb_domain;
4372 [ # # ]: 0 : else if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
4373 : 0 : domain = sh->rx_domain;
4374 : : else
4375 : 0 : domain = sh->tx_domain;
4376 [ # # ]: 0 : ret = mlx5_flow_os_create_flow_action_packet_reformat(sh->cdev->ctx,
4377 : : domain, resource,
4378 : : &resource->action);
4379 : : }
4380 : : if (ret) {
4381 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], idx);
4382 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4383 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4384 : : NULL, "cannot create action");
4385 : 0 : return NULL;
4386 : : }
4387 : 0 : resource->idx = idx;
4388 : 0 : return &resource->entry;
4389 : : }
4390 : :
4391 : : struct mlx5_list_entry *
4392 : 0 : flow_encap_decap_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
4393 : : void *cb_ctx)
4394 : : {
4395 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4396 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4397 : : struct mlx5_flow_dv_encap_decap_resource *cache_resource;
4398 : : uint32_t idx;
4399 : :
4400 : 0 : cache_resource = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
4401 : : &idx);
4402 [ # # ]: 0 : if (!cache_resource) {
4403 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4404 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4405 : : "cannot allocate resource memory");
4406 : 0 : return NULL;
4407 : : }
4408 : : memcpy(cache_resource, oentry, sizeof(*cache_resource));
4409 : 0 : cache_resource->idx = idx;
4410 : 0 : return &cache_resource->entry;
4411 : : }
4412 : :
4413 : : void
4414 : 0 : flow_encap_decap_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4415 : : {
4416 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4417 : : struct mlx5_flow_dv_encap_decap_resource *res =
4418 : : container_of(entry, typeof(*res), entry);
4419 : :
4420 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], res->idx);
4421 : 0 : }
4422 : :
4423 : : int
4424 : 0 : __flow_encap_decap_resource_register(struct rte_eth_dev *dev,
4425 : : struct mlx5_flow_dv_encap_decap_resource *resource,
4426 : : bool is_root,
4427 : : struct mlx5_flow_dv_encap_decap_resource **encap_decap,
4428 : : struct rte_flow_error *error)
4429 : : {
4430 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4431 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
4432 : : struct mlx5_list_entry *entry;
4433 : : union {
4434 : : struct {
4435 : : uint32_t ft_type:8;
4436 : : uint32_t refmt_type:8;
4437 : : /*
4438 : : * Header reformat actions can be shared between
4439 : : * non-root tables. One bit to indicate non-root
4440 : : * table or not.
4441 : : */
4442 : : uint32_t is_root:1;
4443 : : uint32_t reserve:15;
4444 : : };
4445 : : uint32_t v32;
4446 : 0 : } encap_decap_key = {
4447 : : {
4448 : 0 : .ft_type = resource->ft_type,
4449 : 0 : .refmt_type = resource->reformat_type,
4450 : : .is_root = is_root,
4451 : : .reserve = 0,
4452 : : }
4453 : : };
4454 : 0 : struct mlx5_flow_cb_ctx ctx = {
4455 : : .error = error,
4456 : : .data = resource,
4457 : 0 : .data2 = priv->dr_ctx,
4458 : : };
4459 : : struct mlx5_hlist *encaps_decaps;
4460 : : uint64_t key64;
4461 : :
4462 : 0 : encaps_decaps = flow_dv_hlist_prepare(sh, &sh->encaps_decaps,
4463 : : "encaps_decaps",
4464 : : MLX5_FLOW_ENCAP_DECAP_HTABLE_SZ,
4465 : : true, true, sh,
4466 : : flow_encap_decap_create_cb,
4467 : : flow_encap_decap_match_cb,
4468 : : flow_encap_decap_remove_cb,
4469 : : flow_encap_decap_clone_cb,
4470 : : flow_encap_decap_clone_free_cb,
4471 : : error);
4472 [ # # ]: 0 : if (unlikely(!encaps_decaps))
4473 : 0 : return -rte_errno;
4474 : 0 : key64 = __rte_raw_cksum(&encap_decap_key.v32,
4475 : : sizeof(encap_decap_key.v32), 0);
4476 [ # # ]: 0 : if (resource->reformat_type !=
4477 : 0 : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2 &&
4478 [ # # ]: 0 : resource->size)
4479 : 0 : key64 = __rte_raw_cksum(resource->buf, resource->size, key64);
4480 : 0 : entry = mlx5_hlist_register(encaps_decaps, key64, &ctx);
4481 [ # # ]: 0 : if (!entry)
4482 : 0 : return -rte_errno;
4483 : 0 : *encap_decap = container_of(entry, typeof(*resource), entry);
4484 : 0 : return 0;
4485 : : }
4486 : :
4487 : : /**
4488 : : * Find existing encap/decap resource or create and register a new one.
4489 : : *
4490 : : * @param[in, out] dev
4491 : : * Pointer to rte_eth_dev structure.
4492 : : * @param[in, out] resource
4493 : : * Pointer to encap/decap resource.
4494 : : * @param[in, out] dev_flow
4495 : : * Pointer to the dev_flow.
4496 : : * @param[out] error
4497 : : * pointer to error structure.
4498 : : *
4499 : : * @return
4500 : : * 0 on success otherwise -errno and errno is set.
4501 : : */
4502 : : static int
4503 : 0 : flow_dv_encap_decap_resource_register
4504 : : (struct rte_eth_dev *dev,
4505 : : struct mlx5_flow_dv_encap_decap_resource *resource,
4506 : : struct mlx5_flow *dev_flow,
4507 : : struct rte_flow_error *error)
4508 : : {
4509 : : int ret;
4510 : :
4511 : 0 : resource->flags = dev_flow->dv.group ? 0 : 1;
4512 : 0 : ret = __flow_encap_decap_resource_register(dev, resource, !!dev_flow->dv.group,
4513 : : &dev_flow->dv.encap_decap, error);
4514 [ # # ]: 0 : if (ret)
4515 : : return ret;
4516 : 0 : dev_flow->handle->dvh.rix_encap_decap = dev_flow->dv.encap_decap->idx;
4517 : 0 : return 0;
4518 : : }
4519 : :
4520 : : /**
4521 : : * Find existing table jump resource or create and register a new one.
4522 : : *
4523 : : * @param[in, out] dev
4524 : : * Pointer to rte_eth_dev structure.
4525 : : * @param[in, out] tbl
4526 : : * Pointer to flow table resource.
4527 : : * @parm[in, out] dev_flow
4528 : : * Pointer to the dev_flow.
4529 : : * @param[out] error
4530 : : * pointer to error structure.
4531 : : *
4532 : : * @return
4533 : : * 0 on success otherwise -errno and errno is set.
4534 : : */
4535 : : static int
4536 : : flow_dv_jump_tbl_resource_register
4537 : : (struct rte_eth_dev *dev __rte_unused,
4538 : : struct mlx5_flow_tbl_resource *tbl,
4539 : : struct mlx5_flow *dev_flow,
4540 : : struct rte_flow_error *error __rte_unused)
4541 : : {
4542 : : struct mlx5_flow_tbl_data_entry *tbl_data =
4543 : 0 : container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
4544 : :
4545 : : MLX5_ASSERT(tbl);
4546 : : MLX5_ASSERT(tbl_data->jump.action);
4547 : 0 : dev_flow->handle->rix_jump = tbl_data->idx;
4548 : 0 : dev_flow->dv.jump = &tbl_data->jump;
4549 : : return 0;
4550 : : }
4551 : :
4552 : : int
4553 : 0 : flow_dv_port_id_match_cb(void *tool_ctx __rte_unused,
4554 : : struct mlx5_list_entry *entry, void *cb_ctx)
4555 : : {
4556 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4557 : 0 : struct mlx5_flow_dv_port_id_action_resource *ref = ctx->data;
4558 : : struct mlx5_flow_dv_port_id_action_resource *res =
4559 : : container_of(entry, typeof(*res), entry);
4560 : :
4561 : 0 : return ref->port_id != res->port_id;
4562 : : }
4563 : :
4564 : : struct mlx5_list_entry *
4565 : 0 : flow_dv_port_id_create_cb(void *tool_ctx, void *cb_ctx)
4566 : : {
4567 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4568 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4569 : 0 : struct mlx5_flow_dv_port_id_action_resource *ref = ctx->data;
4570 : : struct mlx5_flow_dv_port_id_action_resource *resource;
4571 : : uint32_t idx;
4572 : : int ret;
4573 : :
4574 : : /* Register new port id action resource. */
4575 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID], &idx);
4576 [ # # ]: 0 : if (!resource) {
4577 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4578 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4579 : : "cannot allocate port_id action memory");
4580 : 0 : return NULL;
4581 : : }
4582 : 0 : *resource = *ref;
4583 : 0 : ret = mlx5_flow_os_create_flow_action_dest_port(sh->fdb_domain,
4584 : : ref->port_id,
4585 : : &resource->action);
4586 : : if (ret) {
4587 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], idx);
4588 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4589 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4590 : : "cannot create action");
4591 : 0 : return NULL;
4592 : : }
4593 : 0 : resource->idx = idx;
4594 : 0 : return &resource->entry;
4595 : : }
4596 : :
4597 : : struct mlx5_list_entry *
4598 : 0 : flow_dv_port_id_clone_cb(void *tool_ctx,
4599 : : struct mlx5_list_entry *entry __rte_unused,
4600 : : void *cb_ctx)
4601 : : {
4602 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4603 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4604 : : struct mlx5_flow_dv_port_id_action_resource *resource;
4605 : : uint32_t idx;
4606 : :
4607 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID], &idx);
4608 [ # # ]: 0 : if (!resource) {
4609 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4610 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4611 : : "cannot allocate port_id action memory");
4612 : 0 : return NULL;
4613 : : }
4614 : : memcpy(resource, entry, sizeof(*resource));
4615 : 0 : resource->idx = idx;
4616 : 0 : return &resource->entry;
4617 : : }
4618 : :
4619 : : void
4620 : 0 : flow_dv_port_id_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4621 : : {
4622 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4623 : : struct mlx5_flow_dv_port_id_action_resource *resource =
4624 : : container_of(entry, typeof(*resource), entry);
4625 : :
4626 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], resource->idx);
4627 : 0 : }
4628 : :
4629 : : /**
4630 : : * Find existing table port ID resource or create and register a new one.
4631 : : *
4632 : : * @param[in, out] dev
4633 : : * Pointer to rte_eth_dev structure.
4634 : : * @param[in, out] ref
4635 : : * Pointer to port ID action resource reference.
4636 : : * @parm[in, out] dev_flow
4637 : : * Pointer to the dev_flow.
4638 : : * @param[out] error
4639 : : * pointer to error structure.
4640 : : *
4641 : : * @return
4642 : : * 0 on success otherwise -errno and errno is set.
4643 : : */
4644 : : static int
4645 : 0 : flow_dv_port_id_action_resource_register
4646 : : (struct rte_eth_dev *dev,
4647 : : struct mlx5_flow_dv_port_id_action_resource *ref,
4648 : : struct mlx5_flow *dev_flow,
4649 : : struct rte_flow_error *error)
4650 : : {
4651 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4652 : : struct mlx5_list_entry *entry;
4653 : : struct mlx5_flow_dv_port_id_action_resource *resource;
4654 : 0 : struct mlx5_flow_cb_ctx ctx = {
4655 : : .error = error,
4656 : : .data = ref,
4657 : : };
4658 : :
4659 : 0 : entry = mlx5_list_register(priv->sh->port_id_action_list, &ctx);
4660 [ # # ]: 0 : if (!entry)
4661 : 0 : return -rte_errno;
4662 : : resource = container_of(entry, typeof(*resource), entry);
4663 : 0 : dev_flow->dv.port_id_action = resource;
4664 : 0 : dev_flow->handle->rix_port_id_action = resource->idx;
4665 : 0 : return 0;
4666 : : }
4667 : :
4668 : : int
4669 : 0 : flow_dv_push_vlan_match_cb(void *tool_ctx __rte_unused,
4670 : : struct mlx5_list_entry *entry, void *cb_ctx)
4671 : : {
4672 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4673 : 0 : struct mlx5_flow_dv_push_vlan_action_resource *ref = ctx->data;
4674 : : struct mlx5_flow_dv_push_vlan_action_resource *res =
4675 : : container_of(entry, typeof(*res), entry);
4676 : :
4677 : 0 : return ref->vlan_tag != res->vlan_tag || ref->ft_type != res->ft_type;
4678 : : }
4679 : :
4680 : : struct mlx5_list_entry *
4681 : 0 : flow_dv_push_vlan_create_cb(void *tool_ctx, void *cb_ctx)
4682 : : {
4683 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4684 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4685 : 0 : struct mlx5_flow_dv_push_vlan_action_resource *ref = ctx->data;
4686 : : struct mlx5_flow_dv_push_vlan_action_resource *resource;
4687 : : struct mlx5dv_dr_domain *domain;
4688 : : uint32_t idx;
4689 : : int ret;
4690 : :
4691 : : /* Register new port id action resource. */
4692 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PUSH_VLAN], &idx);
4693 [ # # ]: 0 : if (!resource) {
4694 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4695 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4696 : : "cannot allocate push_vlan action memory");
4697 : 0 : return NULL;
4698 : : }
4699 : 0 : *resource = *ref;
4700 [ # # ]: 0 : if (ref->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
4701 : 0 : domain = sh->fdb_domain;
4702 [ # # ]: 0 : else if (ref->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
4703 : 0 : domain = sh->rx_domain;
4704 : : else
4705 : 0 : domain = sh->tx_domain;
4706 : 0 : ret = mlx5_flow_os_create_flow_action_push_vlan(domain, ref->vlan_tag,
4707 : : &resource->action);
4708 : : if (ret) {
4709 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
4710 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4711 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4712 : : "cannot create push vlan action");
4713 : 0 : return NULL;
4714 : : }
4715 : 0 : resource->idx = idx;
4716 : 0 : return &resource->entry;
4717 : : }
4718 : :
4719 : : struct mlx5_list_entry *
4720 : 0 : flow_dv_push_vlan_clone_cb(void *tool_ctx,
4721 : : struct mlx5_list_entry *entry __rte_unused,
4722 : : void *cb_ctx)
4723 : : {
4724 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4725 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4726 : : struct mlx5_flow_dv_push_vlan_action_resource *resource;
4727 : : uint32_t idx;
4728 : :
4729 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PUSH_VLAN], &idx);
4730 [ # # ]: 0 : if (!resource) {
4731 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4732 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4733 : : "cannot allocate push_vlan action memory");
4734 : 0 : return NULL;
4735 : : }
4736 : : memcpy(resource, entry, sizeof(*resource));
4737 : 0 : resource->idx = idx;
4738 : 0 : return &resource->entry;
4739 : : }
4740 : :
4741 : : void
4742 : 0 : flow_dv_push_vlan_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4743 : : {
4744 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4745 : : struct mlx5_flow_dv_push_vlan_action_resource *resource =
4746 : : container_of(entry, typeof(*resource), entry);
4747 : :
4748 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], resource->idx);
4749 : 0 : }
4750 : :
4751 : : /**
4752 : : * Find existing push vlan resource or create and register a new one.
4753 : : *
4754 : : * @param [in, out] dev
4755 : : * Pointer to rte_eth_dev structure.
4756 : : * @param[in, out] ref
4757 : : * Pointer to port ID action resource reference.
4758 : : * @parm[in, out] dev_flow
4759 : : * Pointer to the dev_flow.
4760 : : * @param[out] error
4761 : : * pointer to error structure.
4762 : : *
4763 : : * @return
4764 : : * 0 on success otherwise -errno and errno is set.
4765 : : */
4766 : : static int
4767 : 0 : flow_dv_push_vlan_action_resource_register
4768 : : (struct rte_eth_dev *dev,
4769 : : struct mlx5_flow_dv_push_vlan_action_resource *ref,
4770 : : struct mlx5_flow *dev_flow,
4771 : : struct rte_flow_error *error)
4772 : : {
4773 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4774 : : struct mlx5_flow_dv_push_vlan_action_resource *resource;
4775 : : struct mlx5_list_entry *entry;
4776 : 0 : struct mlx5_flow_cb_ctx ctx = {
4777 : : .error = error,
4778 : : .data = ref,
4779 : : };
4780 : :
4781 : 0 : entry = mlx5_list_register(priv->sh->push_vlan_action_list, &ctx);
4782 [ # # ]: 0 : if (!entry)
4783 : 0 : return -rte_errno;
4784 : : resource = container_of(entry, typeof(*resource), entry);
4785 : :
4786 : 0 : dev_flow->handle->dvh.rix_push_vlan = resource->idx;
4787 : 0 : dev_flow->dv.push_vlan_res = resource;
4788 : 0 : return 0;
4789 : : }
4790 : :
4791 : : /**
4792 : : * Get the size of specific rte_flow_item_type hdr size
4793 : : *
4794 : : * @param[in] item_type
4795 : : * Tested rte_flow_item_type.
4796 : : *
4797 : : * @return
4798 : : * sizeof struct item_type, 0 if void or irrelevant.
4799 : : */
4800 : : size_t
4801 [ # # ]: 0 : flow_dv_get_item_hdr_len(const enum rte_flow_item_type item_type)
4802 : : {
4803 : : size_t retval;
4804 : :
4805 : : switch (item_type) {
4806 : : case RTE_FLOW_ITEM_TYPE_ETH:
4807 : : retval = sizeof(struct rte_ether_hdr);
4808 : : break;
4809 : : case RTE_FLOW_ITEM_TYPE_VLAN:
4810 : : retval = sizeof(struct rte_vlan_hdr);
4811 : : break;
4812 : : case RTE_FLOW_ITEM_TYPE_IPV4:
4813 : : retval = sizeof(struct rte_ipv4_hdr);
4814 : : break;
4815 : : case RTE_FLOW_ITEM_TYPE_IPV6:
4816 : : retval = sizeof(struct rte_ipv6_hdr);
4817 : : break;
4818 : : case RTE_FLOW_ITEM_TYPE_UDP:
4819 : : retval = sizeof(struct rte_udp_hdr);
4820 : : break;
4821 : : case RTE_FLOW_ITEM_TYPE_TCP:
4822 : : retval = sizeof(struct rte_tcp_hdr);
4823 : : break;
4824 : : case RTE_FLOW_ITEM_TYPE_VXLAN:
4825 : : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
4826 : : retval = sizeof(struct rte_vxlan_hdr);
4827 : : break;
4828 : : case RTE_FLOW_ITEM_TYPE_GRE:
4829 : : case RTE_FLOW_ITEM_TYPE_NVGRE:
4830 : : retval = sizeof(struct rte_gre_hdr);
4831 : : break;
4832 : : case RTE_FLOW_ITEM_TYPE_MPLS:
4833 : : retval = sizeof(struct rte_mpls_hdr);
4834 : : break;
4835 : : case RTE_FLOW_ITEM_TYPE_VOID: /* Fall through. */
4836 : : default:
4837 : : retval = 0;
4838 : : break;
4839 : : }
4840 : 0 : return retval;
4841 : : }
4842 : :
4843 : : #define MLX5_ENCAP_IPV4_VERSION 0x40
4844 : : #define MLX5_ENCAP_IPV4_IHL_MIN 0x05
4845 : : #define MLX5_ENCAP_IPV4_TTL_DEF 0x40
4846 : : #define MLX5_ENCAP_IPV6_VTC_FLOW 0x60000000
4847 : : #define MLX5_ENCAP_IPV6_HOP_LIMIT 0xff
4848 : : #define MLX5_ENCAP_VXLAN_FLAGS 0x08000000
4849 : : #define MLX5_ENCAP_VXLAN_GPE_FLAGS 0x04
4850 : :
4851 : : /**
4852 : : * Convert the encap action data from list of rte_flow_item to raw buffer
4853 : : *
4854 : : * @param[in] items
4855 : : * Pointer to rte_flow_item objects list.
4856 : : * @param[out] buf
4857 : : * Pointer to the output buffer.
4858 : : * @param[out] size
4859 : : * Pointer to the output buffer size.
4860 : : * @param[out] error
4861 : : * Pointer to the error structure.
4862 : : *
4863 : : * @return
4864 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4865 : : */
4866 : : int
4867 : 0 : flow_dv_convert_encap_data(const struct rte_flow_item *items, uint8_t *buf,
4868 : : size_t *size, struct rte_flow_error *error)
4869 : : {
4870 : : struct rte_ether_hdr *eth = NULL;
4871 : : struct rte_vlan_hdr *vlan = NULL;
4872 : : struct rte_ipv4_hdr *ipv4 = NULL;
4873 : : struct rte_ipv6_hdr *ipv6 = NULL;
4874 : : struct rte_udp_hdr *udp = NULL;
4875 : : struct rte_vxlan_hdr *vxlan = NULL;
4876 : : struct rte_vxlan_gpe_hdr *vxlan_gpe = NULL;
4877 : : struct rte_gre_hdr *gre = NULL;
4878 : : size_t len;
4879 : : size_t temp_size = 0;
4880 : :
4881 [ # # ]: 0 : if (!items)
4882 : 0 : return rte_flow_error_set(error, EINVAL,
4883 : : RTE_FLOW_ERROR_TYPE_ACTION,
4884 : : NULL, "invalid empty data");
4885 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4886 : 0 : len = flow_dv_get_item_hdr_len(items->type);
4887 [ # # ]: 0 : if (len + temp_size > MLX5_ENCAP_MAX_LEN)
4888 : 0 : return rte_flow_error_set(error, EINVAL,
4889 : : RTE_FLOW_ERROR_TYPE_ACTION,
4890 : 0 : (void *)items->type,
4891 : : "items total size is too big"
4892 : : " for encap action");
4893 [ # # ]: 0 : if (items->spec)
4894 [ # # ]: 0 : rte_memcpy(&buf[temp_size], items->spec, len);
4895 [ # # # # : 0 : switch (items->type) {
# # # # #
# ]
4896 : 0 : case RTE_FLOW_ITEM_TYPE_ETH:
4897 : 0 : eth = (struct rte_ether_hdr *)&buf[temp_size];
4898 : 0 : break;
4899 : 0 : case RTE_FLOW_ITEM_TYPE_VLAN:
4900 : 0 : vlan = (struct rte_vlan_hdr *)&buf[temp_size];
4901 [ # # ]: 0 : if (!eth)
4902 : 0 : return rte_flow_error_set(error, EINVAL,
4903 : : RTE_FLOW_ERROR_TYPE_ACTION,
4904 : : (void *)items->type,
4905 : : "eth header not found");
4906 [ # # ]: 0 : if (!eth->ether_type)
4907 : 0 : eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_VLAN);
4908 : : break;
4909 : 0 : case RTE_FLOW_ITEM_TYPE_IPV4:
4910 : 0 : ipv4 = (struct rte_ipv4_hdr *)&buf[temp_size];
4911 [ # # ]: 0 : if (!vlan && !eth)
4912 : 0 : return rte_flow_error_set(error, EINVAL,
4913 : : RTE_FLOW_ERROR_TYPE_ACTION,
4914 : : (void *)items->type,
4915 : : "neither eth nor vlan"
4916 : : " header found");
4917 [ # # # # ]: 0 : if (vlan && !vlan->eth_proto)
4918 : 0 : vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV4);
4919 [ # # # # ]: 0 : else if (eth && !eth->ether_type)
4920 : 0 : eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV4);
4921 [ # # ]: 0 : if (!ipv4->version_ihl)
4922 : 0 : ipv4->version_ihl = MLX5_ENCAP_IPV4_VERSION |
4923 : : MLX5_ENCAP_IPV4_IHL_MIN;
4924 [ # # ]: 0 : if (!ipv4->time_to_live)
4925 : 0 : ipv4->time_to_live = MLX5_ENCAP_IPV4_TTL_DEF;
4926 : : break;
4927 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6:
4928 : 0 : ipv6 = (struct rte_ipv6_hdr *)&buf[temp_size];
4929 [ # # ]: 0 : if (!vlan && !eth)
4930 : 0 : return rte_flow_error_set(error, EINVAL,
4931 : : RTE_FLOW_ERROR_TYPE_ACTION,
4932 : : (void *)items->type,
4933 : : "neither eth nor vlan"
4934 : : " header found");
4935 [ # # # # ]: 0 : if (vlan && !vlan->eth_proto)
4936 : 0 : vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV6);
4937 [ # # # # ]: 0 : else if (eth && !eth->ether_type)
4938 : 0 : eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV6);
4939 [ # # ]: 0 : if (!ipv6->vtc_flow)
4940 : 0 : ipv6->vtc_flow =
4941 : : RTE_BE32(MLX5_ENCAP_IPV6_VTC_FLOW);
4942 [ # # ]: 0 : if (!ipv6->hop_limits)
4943 : 0 : ipv6->hop_limits = MLX5_ENCAP_IPV6_HOP_LIMIT;
4944 : : break;
4945 : 0 : case RTE_FLOW_ITEM_TYPE_UDP:
4946 : 0 : udp = (struct rte_udp_hdr *)&buf[temp_size];
4947 [ # # ]: 0 : if (!ipv4 && !ipv6)
4948 : 0 : return rte_flow_error_set(error, EINVAL,
4949 : : RTE_FLOW_ERROR_TYPE_ACTION,
4950 : : (void *)items->type,
4951 : : "ip header not found");
4952 [ # # # # ]: 0 : if (ipv4 && !ipv4->next_proto_id)
4953 : 0 : ipv4->next_proto_id = IPPROTO_UDP;
4954 [ # # # # ]: 0 : else if (ipv6 && !ipv6->proto)
4955 : 0 : ipv6->proto = IPPROTO_UDP;
4956 : : break;
4957 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN:
4958 : 0 : vxlan = (struct rte_vxlan_hdr *)&buf[temp_size];
4959 [ # # ]: 0 : if (!udp)
4960 : 0 : return rte_flow_error_set(error, EINVAL,
4961 : : RTE_FLOW_ERROR_TYPE_ACTION,
4962 : : (void *)items->type,
4963 : : "udp header not found");
4964 [ # # ]: 0 : if (!udp->dst_port)
4965 : 0 : udp->dst_port = RTE_BE16(MLX5_UDP_PORT_VXLAN);
4966 [ # # ]: 0 : if (!vxlan->vx_flags)
4967 : 0 : vxlan->vx_flags =
4968 : : RTE_BE32(MLX5_ENCAP_VXLAN_FLAGS);
4969 : : break;
4970 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
4971 : 0 : vxlan_gpe = (struct rte_vxlan_gpe_hdr *)&buf[temp_size];
4972 [ # # ]: 0 : if (!udp)
4973 : 0 : return rte_flow_error_set(error, EINVAL,
4974 : : RTE_FLOW_ERROR_TYPE_ACTION,
4975 : : (void *)items->type,
4976 : : "udp header not found");
4977 [ # # ]: 0 : if (!vxlan_gpe->proto)
4978 : 0 : return rte_flow_error_set(error, EINVAL,
4979 : : RTE_FLOW_ERROR_TYPE_ACTION,
4980 : : (void *)items->type,
4981 : : "next protocol not found");
4982 [ # # ]: 0 : if (!udp->dst_port)
4983 : 0 : udp->dst_port =
4984 : : RTE_BE16(MLX5_UDP_PORT_VXLAN_GPE);
4985 [ # # ]: 0 : if (!vxlan_gpe->vx_flags)
4986 : 0 : vxlan_gpe->vx_flags =
4987 : : MLX5_ENCAP_VXLAN_GPE_FLAGS;
4988 : : break;
4989 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
4990 : : case RTE_FLOW_ITEM_TYPE_NVGRE:
4991 : 0 : gre = (struct rte_gre_hdr *)&buf[temp_size];
4992 [ # # ]: 0 : if (!gre->proto)
4993 : 0 : return rte_flow_error_set(error, EINVAL,
4994 : : RTE_FLOW_ERROR_TYPE_ACTION,
4995 : 0 : (void *)items->type,
4996 : : "next protocol not found");
4997 [ # # ]: 0 : if (!ipv4 && !ipv6)
4998 : 0 : return rte_flow_error_set(error, EINVAL,
4999 : : RTE_FLOW_ERROR_TYPE_ACTION,
5000 : 0 : (void *)items->type,
5001 : : "ip header not found");
5002 [ # # # # ]: 0 : if (ipv4 && !ipv4->next_proto_id)
5003 : 0 : ipv4->next_proto_id = IPPROTO_GRE;
5004 [ # # # # ]: 0 : else if (ipv6 && !ipv6->proto)
5005 : 0 : ipv6->proto = IPPROTO_GRE;
5006 : : break;
5007 : : case RTE_FLOW_ITEM_TYPE_VOID:
5008 : : break;
5009 : 0 : default:
5010 : 0 : return rte_flow_error_set(error, EINVAL,
5011 : : RTE_FLOW_ERROR_TYPE_ACTION,
5012 : 0 : (void *)items->type,
5013 : : "unsupported item type");
5014 : : break;
5015 : : }
5016 : : temp_size += len;
5017 : : }
5018 : 0 : *size = temp_size;
5019 : 0 : return 0;
5020 : : }
5021 : :
5022 : : static int
5023 : 0 : flow_dv_zero_encap_udp_csum(void *data, struct rte_flow_error *error)
5024 : : {
5025 : : struct rte_ether_hdr *eth = NULL;
5026 : : struct rte_vlan_hdr *vlan = NULL;
5027 : : struct rte_ipv4_hdr *ipv4 = NULL;
5028 : : struct rte_ipv6_hdr *ipv6 = NULL;
5029 : : struct rte_udp_hdr *udp = NULL;
5030 : : char *next_hdr;
5031 : : uint16_t proto;
5032 : :
5033 : : eth = (struct rte_ether_hdr *)data;
5034 : 0 : next_hdr = (char *)(eth + 1);
5035 : 0 : proto = RTE_BE16(eth->ether_type);
5036 : :
5037 : : /* VLAN skipping */
5038 [ # # ]: 0 : while (proto == RTE_ETHER_TYPE_VLAN || proto == RTE_ETHER_TYPE_QINQ) {
5039 : : vlan = (struct rte_vlan_hdr *)next_hdr;
5040 : 0 : proto = RTE_BE16(vlan->eth_proto);
5041 : 0 : next_hdr += sizeof(struct rte_vlan_hdr);
5042 : : }
5043 : :
5044 : : /* non IPv4/IPv6 header. not supported */
5045 [ # # ]: 0 : if (proto != RTE_ETHER_TYPE_IPV4 && proto != RTE_ETHER_TYPE_IPV6) {
5046 : 0 : return rte_flow_error_set(error, ENOTSUP,
5047 : : RTE_FLOW_ERROR_TYPE_ACTION,
5048 : : NULL, "Cannot offload non IPv4/IPv6");
5049 : : }
5050 : :
5051 [ # # ]: 0 : if (proto == RTE_ETHER_TYPE_IPV4) {
5052 : : ipv4 = (struct rte_ipv4_hdr *)next_hdr;
5053 : : /* ignore non UDP */
5054 [ # # ]: 0 : if (ipv4->next_proto_id != IPPROTO_UDP)
5055 : : return 0;
5056 : 0 : udp = (struct rte_udp_hdr *)(ipv4 + 1);
5057 : : } else {
5058 : : ipv6 = (struct rte_ipv6_hdr *)next_hdr;
5059 : : /* ignore non UDP */
5060 [ # # ]: 0 : if (ipv6->proto != IPPROTO_UDP)
5061 : : return 0;
5062 : 0 : udp = (struct rte_udp_hdr *)(ipv6 + 1);
5063 : : }
5064 : :
5065 : 0 : udp->dgram_cksum = 0;
5066 : :
5067 : 0 : return 0;
5068 : : }
5069 : :
5070 : : /**
5071 : : * Convert L2 encap action to DV specification.
5072 : : *
5073 : : * @param[in] dev
5074 : : * Pointer to rte_eth_dev structure.
5075 : : * @param[in] action
5076 : : * Pointer to action structure.
5077 : : * @param[in, out] dev_flow
5078 : : * Pointer to the mlx5_flow.
5079 : : * @param[in] transfer
5080 : : * Mark if the flow is E-Switch flow.
5081 : : * @param[out] error
5082 : : * Pointer to the error structure.
5083 : : *
5084 : : * @return
5085 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5086 : : */
5087 : : static int
5088 : 0 : flow_dv_create_action_l2_encap(struct rte_eth_dev *dev,
5089 : : const struct rte_flow_action *action,
5090 : : struct mlx5_flow *dev_flow,
5091 : : uint8_t transfer,
5092 : : struct rte_flow_error *error)
5093 : : {
5094 : : const struct rte_flow_item *encap_data;
5095 : : const struct rte_flow_action_raw_encap *raw_encap_data;
5096 [ # # ]: 0 : struct mlx5_flow_dv_encap_decap_resource res = {
5097 : : .reformat_type =
5098 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L2_TUNNEL,
5099 : : .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
5100 : : MLX5DV_FLOW_TABLE_TYPE_NIC_TX,
5101 : : };
5102 : :
5103 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
5104 : 0 : raw_encap_data =
5105 : : (const struct rte_flow_action_raw_encap *)action->conf;
5106 : 0 : res.size = raw_encap_data->size;
5107 : 0 : memcpy(res.buf, raw_encap_data->data, res.size);
5108 : : } else {
5109 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP)
5110 : 0 : encap_data =
5111 : : ((const struct rte_flow_action_vxlan_encap *)
5112 : 0 : action->conf)->definition;
5113 : : else
5114 : 0 : encap_data =
5115 : : ((const struct rte_flow_action_nvgre_encap *)
5116 : 0 : action->conf)->definition;
5117 [ # # ]: 0 : if (flow_dv_convert_encap_data(encap_data, res.buf,
5118 : : &res.size, error))
5119 : 0 : return -rte_errno;
5120 : : }
5121 [ # # ]: 0 : if (flow_dv_zero_encap_udp_csum(res.buf, error))
5122 : 0 : return -rte_errno;
5123 [ # # ]: 0 : if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
5124 : 0 : return rte_flow_error_set(error, EINVAL,
5125 : : RTE_FLOW_ERROR_TYPE_ACTION,
5126 : : NULL, "can't create L2 encap action");
5127 : : return 0;
5128 : : }
5129 : :
5130 : : /**
5131 : : * Convert L2 decap action to DV specification.
5132 : : *
5133 : : * @param[in] dev
5134 : : * Pointer to rte_eth_dev structure.
5135 : : * @param[in, out] dev_flow
5136 : : * Pointer to the mlx5_flow.
5137 : : * @param[in] transfer
5138 : : * Mark if the flow is E-Switch flow.
5139 : : * @param[out] error
5140 : : * Pointer to the error structure.
5141 : : *
5142 : : * @return
5143 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5144 : : */
5145 : : static int
5146 : 0 : flow_dv_create_action_l2_decap(struct rte_eth_dev *dev,
5147 : : struct mlx5_flow *dev_flow,
5148 : : uint8_t transfer,
5149 : : struct rte_flow_error *error)
5150 : : {
5151 [ # # ]: 0 : struct mlx5_flow_dv_encap_decap_resource res = {
5152 : : .size = 0,
5153 : : .reformat_type =
5154 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2,
5155 : : .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
5156 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX,
5157 : : };
5158 : :
5159 [ # # ]: 0 : if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
5160 : 0 : return rte_flow_error_set(error, EINVAL,
5161 : : RTE_FLOW_ERROR_TYPE_ACTION,
5162 : : NULL, "can't create L2 decap action");
5163 : : return 0;
5164 : : }
5165 : :
5166 : : /**
5167 : : * Convert raw decap/encap (L3 tunnel) action to DV specification.
5168 : : *
5169 : : * @param[in] dev
5170 : : * Pointer to rte_eth_dev structure.
5171 : : * @param[in] action
5172 : : * Pointer to action structure.
5173 : : * @param[in, out] dev_flow
5174 : : * Pointer to the mlx5_flow.
5175 : : * @param[in] attr
5176 : : * Pointer to the flow attributes.
5177 : : * @param[out] error
5178 : : * Pointer to the error structure.
5179 : : *
5180 : : * @return
5181 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5182 : : */
5183 : : static int
5184 [ # # ]: 0 : flow_dv_create_action_raw_encap(struct rte_eth_dev *dev,
5185 : : const struct rte_flow_action *action,
5186 : : struct mlx5_flow *dev_flow,
5187 : : const struct rte_flow_attr *attr,
5188 : : struct rte_flow_error *error)
5189 : : {
5190 : : const struct rte_flow_action_raw_encap *encap_data;
5191 : : struct mlx5_flow_dv_encap_decap_resource res;
5192 : :
5193 : : memset(&res, 0, sizeof(res));
5194 : 0 : encap_data = (const struct rte_flow_action_raw_encap *)action->conf;
5195 : 0 : res.size = encap_data->size;
5196 [ # # ]: 0 : memcpy(res.buf, encap_data->data, res.size);
5197 [ # # ]: 0 : res.reformat_type = res.size < MLX5_ENCAPSULATION_DECISION_SIZE ?
5198 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L3_TUNNEL_TO_L2 :
5199 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L3_TUNNEL;
5200 [ # # ]: 0 : if (attr->transfer)
5201 : 0 : res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
5202 : : else
5203 : 0 : res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
5204 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
5205 [ # # ]: 0 : if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
5206 : 0 : return rte_flow_error_set(error, EINVAL,
5207 : : RTE_FLOW_ERROR_TYPE_ACTION,
5208 : : NULL, "can't create encap action");
5209 : : return 0;
5210 : : }
5211 : :
5212 : : /**
5213 : : * Create action push VLAN.
5214 : : *
5215 : : * @param[in] dev
5216 : : * Pointer to rte_eth_dev structure.
5217 : : * @param[in] attr
5218 : : * Pointer to the flow attributes.
5219 : : * @param[in] vlan
5220 : : * Pointer to the vlan to push to the Ethernet header.
5221 : : * @param[in, out] dev_flow
5222 : : * Pointer to the mlx5_flow.
5223 : : * @param[out] error
5224 : : * Pointer to the error structure.
5225 : : *
5226 : : * @return
5227 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5228 : : */
5229 : : static int
5230 [ # # ]: 0 : flow_dv_create_action_push_vlan(struct rte_eth_dev *dev,
5231 : : const struct rte_flow_attr *attr,
5232 : : const struct rte_vlan_hdr *vlan,
5233 : : struct mlx5_flow *dev_flow,
5234 : : struct rte_flow_error *error)
5235 : : {
5236 : : struct mlx5_flow_dv_push_vlan_action_resource res;
5237 : :
5238 : : memset(&res, 0, sizeof(res));
5239 : 0 : res.vlan_tag =
5240 [ # # ]: 0 : rte_cpu_to_be_32(((uint32_t)vlan->eth_proto) << 16 |
5241 : : vlan->vlan_tci);
5242 [ # # ]: 0 : if (attr->transfer)
5243 : 0 : res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
5244 : : else
5245 : 0 : res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
5246 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
5247 : 0 : return flow_dv_push_vlan_action_resource_register
5248 : : (dev, &res, dev_flow, error);
5249 : : }
5250 : :
5251 : : /**
5252 : : * Validate the modify-header actions.
5253 : : *
5254 : : * @param[in] action_flags
5255 : : * Holds the actions detected until now.
5256 : : * @param[in] action
5257 : : * Pointer to the modify action.
5258 : : * @param[out] error
5259 : : * Pointer to error structure.
5260 : : *
5261 : : * @return
5262 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5263 : : */
5264 : : static int
5265 : 0 : flow_dv_validate_action_modify_hdr(const uint64_t action_flags,
5266 : : const struct rte_flow_action *action,
5267 : : struct rte_flow_error *error)
5268 : : {
5269 [ # # # # ]: 0 : if (action->type != RTE_FLOW_ACTION_TYPE_DEC_TTL && !action->conf)
5270 : 0 : return rte_flow_error_set(error, EINVAL,
5271 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5272 : : NULL, "action configuration not set");
5273 : :
5274 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
5275 : 0 : return rte_flow_error_set(error, EINVAL,
5276 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5277 : : "can't have encap action before"
5278 : : " modify action");
5279 : : return 0;
5280 : : }
5281 : :
5282 : : /**
5283 : : * Validate the modify-header MAC address actions.
5284 : : *
5285 : : * @param[in] action_flags
5286 : : * Holds the actions detected until now.
5287 : : * @param[in] action
5288 : : * Pointer to the modify action.
5289 : : * @param[in] item_flags
5290 : : * Holds the items detected.
5291 : : * @param[out] error
5292 : : * Pointer to error structure.
5293 : : *
5294 : : * @return
5295 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5296 : : */
5297 : : static int
5298 : 0 : flow_dv_validate_action_modify_mac(const uint64_t action_flags,
5299 : : const struct rte_flow_action *action,
5300 : : const uint64_t item_flags,
5301 : : struct rte_flow_error *error)
5302 : : {
5303 : : int ret = 0;
5304 : :
5305 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5306 [ # # ]: 0 : if (!ret) {
5307 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_L2))
5308 : 0 : return rte_flow_error_set(error, EINVAL,
5309 : : RTE_FLOW_ERROR_TYPE_ACTION,
5310 : : NULL,
5311 : : "no L2 item in pattern");
5312 : : }
5313 : : return ret;
5314 : : }
5315 : :
5316 : : /**
5317 : : * Validate the modify-header IPv4 address actions.
5318 : : *
5319 : : * @param[in] action_flags
5320 : : * Holds the actions detected until now.
5321 : : * @param[in] action
5322 : : * Pointer to the modify action.
5323 : : * @param[in] item_flags
5324 : : * Holds the items detected.
5325 : : * @param[out] error
5326 : : * Pointer to error structure.
5327 : : *
5328 : : * @return
5329 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5330 : : */
5331 : : static int
5332 : 0 : flow_dv_validate_action_modify_ipv4(const uint64_t action_flags,
5333 : : const struct rte_flow_action *action,
5334 : : const uint64_t item_flags,
5335 : : struct rte_flow_error *error)
5336 : : {
5337 : : int ret = 0;
5338 : : uint64_t layer;
5339 : :
5340 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5341 [ # # ]: 0 : if (!ret) {
5342 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5343 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L3_IPV4 :
5344 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4;
5345 [ # # ]: 0 : if (!(item_flags & layer))
5346 : 0 : return rte_flow_error_set(error, EINVAL,
5347 : : RTE_FLOW_ERROR_TYPE_ACTION,
5348 : : NULL,
5349 : : "no ipv4 item in pattern");
5350 : : }
5351 : : return ret;
5352 : : }
5353 : :
5354 : : /**
5355 : : * Validate the modify-header IPv6 address actions.
5356 : : *
5357 : : * @param[in] action_flags
5358 : : * Holds the actions detected until now.
5359 : : * @param[in] action
5360 : : * Pointer to the modify action.
5361 : : * @param[in] item_flags
5362 : : * Holds the items detected.
5363 : : * @param[out] error
5364 : : * Pointer to error structure.
5365 : : *
5366 : : * @return
5367 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5368 : : */
5369 : : static int
5370 : 0 : flow_dv_validate_action_modify_ipv6(const uint64_t action_flags,
5371 : : const struct rte_flow_action *action,
5372 : : const uint64_t item_flags,
5373 : : struct rte_flow_error *error)
5374 : : {
5375 : : int ret = 0;
5376 : : uint64_t layer;
5377 : :
5378 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5379 [ # # ]: 0 : if (!ret) {
5380 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5381 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L3_IPV6 :
5382 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6;
5383 [ # # ]: 0 : if (!(item_flags & layer))
5384 : 0 : return rte_flow_error_set(error, EINVAL,
5385 : : RTE_FLOW_ERROR_TYPE_ACTION,
5386 : : NULL,
5387 : : "no ipv6 item in pattern");
5388 : : }
5389 : : return ret;
5390 : : }
5391 : :
5392 : : /**
5393 : : * Validate the modify-header TP actions.
5394 : : *
5395 : : * @param[in] action_flags
5396 : : * Holds the actions detected until now.
5397 : : * @param[in] action
5398 : : * Pointer to the modify action.
5399 : : * @param[in] item_flags
5400 : : * Holds the items detected.
5401 : : * @param[out] error
5402 : : * Pointer to error structure.
5403 : : *
5404 : : * @return
5405 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5406 : : */
5407 : : static int
5408 : 0 : flow_dv_validate_action_modify_tp(const uint64_t action_flags,
5409 : : const struct rte_flow_action *action,
5410 : : const uint64_t item_flags,
5411 : : struct rte_flow_error *error)
5412 : : {
5413 : : int ret = 0;
5414 : : uint64_t layer;
5415 : :
5416 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5417 [ # # ]: 0 : if (!ret) {
5418 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5419 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L4 :
5420 : : MLX5_FLOW_LAYER_OUTER_L4;
5421 [ # # ]: 0 : if (!(item_flags & layer))
5422 : 0 : return rte_flow_error_set(error, EINVAL,
5423 : : RTE_FLOW_ERROR_TYPE_ACTION,
5424 : : NULL, "no transport layer "
5425 : : "in pattern");
5426 : : }
5427 : : return ret;
5428 : : }
5429 : :
5430 : : /**
5431 : : * Validate the modify-header actions of increment/decrement
5432 : : * TCP Sequence-number.
5433 : : *
5434 : : * @param[in] action_flags
5435 : : * Holds the actions detected until now.
5436 : : * @param[in] action
5437 : : * Pointer to the modify action.
5438 : : * @param[in] item_flags
5439 : : * Holds the items detected.
5440 : : * @param[out] error
5441 : : * Pointer to error structure.
5442 : : *
5443 : : * @return
5444 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5445 : : */
5446 : : static int
5447 : 0 : flow_dv_validate_action_modify_tcp_seq(const uint64_t action_flags,
5448 : : const struct rte_flow_action *action,
5449 : : const uint64_t item_flags,
5450 : : struct rte_flow_error *error)
5451 : : {
5452 : : int ret = 0;
5453 : : uint64_t layer;
5454 : :
5455 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5456 [ # # ]: 0 : if (!ret) {
5457 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5458 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L4_TCP :
5459 : : MLX5_FLOW_LAYER_OUTER_L4_TCP;
5460 [ # # ]: 0 : if (!(item_flags & layer))
5461 : 0 : return rte_flow_error_set(error, EINVAL,
5462 : : RTE_FLOW_ERROR_TYPE_ACTION,
5463 : : NULL, "no TCP item in"
5464 : : " pattern");
5465 [ # # ]: 0 : if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ &&
5466 [ # # # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_DEC_TCP_SEQ)) ||
5467 : 0 : (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ &&
5468 [ # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_INC_TCP_SEQ)))
5469 : 0 : return rte_flow_error_set(error, EINVAL,
5470 : : RTE_FLOW_ERROR_TYPE_ACTION,
5471 : : NULL,
5472 : : "cannot decrease and increase"
5473 : : " TCP sequence number"
5474 : : " at the same time");
5475 : : }
5476 : : return ret;
5477 : : }
5478 : :
5479 : : /**
5480 : : * Validate the modify-header actions of increment/decrement
5481 : : * TCP Acknowledgment number.
5482 : : *
5483 : : * @param[in] action_flags
5484 : : * Holds the actions detected until now.
5485 : : * @param[in] action
5486 : : * Pointer to the modify action.
5487 : : * @param[in] item_flags
5488 : : * Holds the items detected.
5489 : : * @param[out] error
5490 : : * Pointer to error structure.
5491 : : *
5492 : : * @return
5493 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5494 : : */
5495 : : static int
5496 : 0 : flow_dv_validate_action_modify_tcp_ack(const uint64_t action_flags,
5497 : : const struct rte_flow_action *action,
5498 : : const uint64_t item_flags,
5499 : : struct rte_flow_error *error)
5500 : : {
5501 : : int ret = 0;
5502 : : uint64_t layer;
5503 : :
5504 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5505 [ # # ]: 0 : if (!ret) {
5506 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5507 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L4_TCP :
5508 : : MLX5_FLOW_LAYER_OUTER_L4_TCP;
5509 [ # # ]: 0 : if (!(item_flags & layer))
5510 : 0 : return rte_flow_error_set(error, EINVAL,
5511 : : RTE_FLOW_ERROR_TYPE_ACTION,
5512 : : NULL, "no TCP item in"
5513 : : " pattern");
5514 [ # # ]: 0 : if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_ACK &&
5515 [ # # # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_DEC_TCP_ACK)) ||
5516 : 0 : (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK &&
5517 [ # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_INC_TCP_ACK)))
5518 : 0 : return rte_flow_error_set(error, EINVAL,
5519 : : RTE_FLOW_ERROR_TYPE_ACTION,
5520 : : NULL,
5521 : : "cannot decrease and increase"
5522 : : " TCP acknowledgment number"
5523 : : " at the same time");
5524 : : }
5525 : : return ret;
5526 : : }
5527 : :
5528 : : /**
5529 : : * Validate the modify-header TTL actions.
5530 : : *
5531 : : * @param[in] action_flags
5532 : : * Holds the actions detected until now.
5533 : : * @param[in] action
5534 : : * Pointer to the modify action.
5535 : : * @param[in] item_flags
5536 : : * Holds the items detected.
5537 : : * @param[out] error
5538 : : * Pointer to error structure.
5539 : : *
5540 : : * @return
5541 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5542 : : */
5543 : : static int
5544 : 0 : flow_dv_validate_action_modify_ttl(const uint64_t action_flags,
5545 : : const struct rte_flow_action *action,
5546 : : const uint64_t item_flags,
5547 : : struct rte_flow_error *error)
5548 : : {
5549 : : int ret = 0;
5550 : : uint64_t layer;
5551 : :
5552 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5553 [ # # ]: 0 : if (!ret) {
5554 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5555 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L3 :
5556 : : MLX5_FLOW_LAYER_OUTER_L3;
5557 [ # # ]: 0 : if (!(item_flags & layer))
5558 : 0 : return rte_flow_error_set(error, EINVAL,
5559 : : RTE_FLOW_ERROR_TYPE_ACTION,
5560 : : NULL,
5561 : : "no IP protocol in pattern");
5562 : : }
5563 : : return ret;
5564 : : }
5565 : :
5566 : : /**
5567 : : * Validate the generic modify field actions.
5568 : : * @param[in] dev
5569 : : * Pointer to the rte_eth_dev structure.
5570 : : * @param[in] action_flags
5571 : : * Holds the actions detected until now.
5572 : : * @param[in] action
5573 : : * Pointer to the modify action.
5574 : : * @param[in] attr
5575 : : * Pointer to the flow attributes.
5576 : : * @param root
5577 : : * Whether action is on root table.
5578 : : * @param[out] error
5579 : : * Pointer to error structure.
5580 : : *
5581 : : * @return
5582 : : * Number of header fields to modify (0 or more) on success,
5583 : : * a negative errno value otherwise and rte_errno is set.
5584 : : */
5585 : : static int
5586 : 0 : flow_dv_validate_action_modify_field(struct rte_eth_dev *dev,
5587 : : const uint64_t action_flags,
5588 : : const struct rte_flow_action *action,
5589 : : const struct rte_flow_attr *attr,
5590 : : bool root,
5591 : : struct rte_flow_error *error)
5592 : : {
5593 : : int ret = 0;
5594 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5595 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
5596 : 0 : struct mlx5_hca_attr *hca_attr = &priv->sh->cdev->config.hca_attr;
5597 : 0 : const struct rte_flow_action_modify_field *conf = action->conf;
5598 : 0 : const struct rte_flow_field_data *src_data = &conf->src;
5599 : 0 : const struct rte_flow_field_data *dst_data = &conf->dst;
5600 : 0 : uint32_t dst_width, src_width, width = conf->width;
5601 : :
5602 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5603 [ # # ]: 0 : if (ret)
5604 : : return ret;
5605 [ # # ]: 0 : if (src_data->field == RTE_FLOW_FIELD_FLEX_ITEM ||
5606 [ # # ]: 0 : dst_data->field == RTE_FLOW_FIELD_FLEX_ITEM)
5607 : 0 : return rte_flow_error_set(error, ENOTSUP,
5608 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5609 : : "flex item fields modification"
5610 : : " is not supported");
5611 : 0 : dst_width = mlx5_flow_item_field_width(dev, dst_data->field,
5612 : : -1, attr, error);
5613 : 0 : src_width = mlx5_flow_item_field_width(dev, src_data->field,
5614 : : dst_width, attr, error);
5615 [ # # ]: 0 : if (width == 0)
5616 : 0 : return rte_flow_error_set(error, EINVAL,
5617 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5618 : : "no bits are requested to be modified");
5619 [ # # ]: 0 : else if (width > dst_width || width > src_width)
5620 : 0 : return rte_flow_error_set(error, EINVAL,
5621 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5622 : : "cannot modify more bits than"
5623 : : " the width of a field");
5624 [ # # ]: 0 : if (dst_data->field != RTE_FLOW_FIELD_VALUE &&
5625 : : dst_data->field != RTE_FLOW_FIELD_POINTER) {
5626 [ # # ]: 0 : if (dst_data->offset + width > dst_width)
5627 : 0 : return rte_flow_error_set(error, EINVAL,
5628 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5629 : : "destination offset is too big");
5630 : 0 : ret = flow_validate_modify_field_level(dst_data, error);
5631 [ # # ]: 0 : if (ret)
5632 : : return ret;
5633 [ # # ]: 0 : if (dst_data->tag_index &&
5634 [ # # ]: 0 : !flow_modify_field_support_tag_array(dst_data->field))
5635 : 0 : return rte_flow_error_set(error, EINVAL,
5636 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5637 : : "destination tag index is not supported");
5638 [ # # ]: 0 : if (dst_data->class_id)
5639 : 0 : return rte_flow_error_set(error, EINVAL,
5640 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5641 : : "destination class ID is not supported");
5642 : : }
5643 [ # # ]: 0 : if (src_data->field != RTE_FLOW_FIELD_VALUE &&
5644 : : src_data->field != RTE_FLOW_FIELD_POINTER) {
5645 [ # # ]: 0 : if (root)
5646 : 0 : return rte_flow_error_set(error, ENOTSUP,
5647 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5648 : : "modify field action is not"
5649 : : " supported for group 0");
5650 [ # # ]: 0 : if (src_data->offset + width > src_width)
5651 : 0 : return rte_flow_error_set(error, EINVAL,
5652 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5653 : : "source offset is too big");
5654 : 0 : ret = flow_validate_modify_field_level(src_data, error);
5655 [ # # ]: 0 : if (ret)
5656 : : return ret;
5657 [ # # ]: 0 : if (src_data->tag_index &&
5658 [ # # ]: 0 : !flow_modify_field_support_tag_array(src_data->field))
5659 : 0 : return rte_flow_error_set(error, EINVAL,
5660 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5661 : : "source tag index is not supported");
5662 [ # # ]: 0 : if (src_data->class_id)
5663 : 0 : return rte_flow_error_set(error, EINVAL,
5664 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5665 : : "source class ID is not supported");
5666 : : }
5667 [ # # ]: 0 : if ((dst_data->field == src_data->field) &&
5668 [ # # ]: 0 : (dst_data->level == src_data->level))
5669 : 0 : return rte_flow_error_set(error, EINVAL,
5670 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5671 : : "source and destination fields"
5672 : : " cannot be the same");
5673 : 0 : if (dst_data->field == RTE_FLOW_FIELD_VALUE ||
5674 [ # # ]: 0 : dst_data->field == RTE_FLOW_FIELD_POINTER ||
5675 : : dst_data->field == RTE_FLOW_FIELD_MARK)
5676 : 0 : return rte_flow_error_set(error, EINVAL,
5677 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5678 : : "mark, immediate value or a pointer to it"
5679 : : " cannot be used as a destination");
5680 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_START ||
5681 : : src_data->field == RTE_FLOW_FIELD_START)
5682 : 0 : return rte_flow_error_set(error, ENOTSUP,
5683 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5684 : : "modifications of an arbitrary"
5685 : : " place in a packet is not supported");
5686 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_VLAN_TYPE ||
5687 : : src_data->field == RTE_FLOW_FIELD_VLAN_TYPE)
5688 : 0 : return rte_flow_error_set(error, ENOTSUP,
5689 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5690 : : "modifications of the 802.1Q Tag"
5691 : : " Identifier is not supported");
5692 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_VXLAN_VNI ||
5693 : : src_data->field == RTE_FLOW_FIELD_VXLAN_VNI)
5694 : 0 : return rte_flow_error_set(error, ENOTSUP,
5695 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5696 : : "modifications of the VXLAN Network"
5697 : : " Identifier is not supported");
5698 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_GENEVE_VNI ||
5699 : : src_data->field == RTE_FLOW_FIELD_GENEVE_VNI)
5700 : 0 : return rte_flow_error_set(error, ENOTSUP,
5701 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5702 : : "modifications of the GENEVE Network"
5703 : : " Identifier is not supported");
5704 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_GENEVE_OPT_TYPE ||
5705 : : src_data->field == RTE_FLOW_FIELD_GENEVE_OPT_TYPE)
5706 : 0 : return rte_flow_error_set(error, ENOTSUP,
5707 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5708 : : "modifications of the GENEVE option type is not supported");
5709 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_GENEVE_OPT_CLASS ||
5710 : : src_data->field == RTE_FLOW_FIELD_GENEVE_OPT_CLASS)
5711 : 0 : return rte_flow_error_set(error, ENOTSUP,
5712 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5713 : : "modifications of the GENEVE option class is not supported");
5714 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_GENEVE_OPT_DATA ||
5715 : : src_data->field == RTE_FLOW_FIELD_GENEVE_OPT_DATA)
5716 : 0 : return rte_flow_error_set(error, ENOTSUP,
5717 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5718 : : "modifications of the GENEVE option data is not supported");
5719 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_MPLS ||
5720 : : src_data->field == RTE_FLOW_FIELD_MPLS)
5721 : 0 : return rte_flow_error_set(error, ENOTSUP,
5722 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5723 : : "modifications of the MPLS header "
5724 : : "is not supported");
5725 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_RANDOM ||
5726 : : src_data->field == RTE_FLOW_FIELD_RANDOM)
5727 : 0 : return rte_flow_error_set(error, ENOTSUP,
5728 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5729 : : "modifications of random value is not supported");
5730 [ # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_MARK ||
5731 : : src_data->field == RTE_FLOW_FIELD_MARK)
5732 [ # # # # ]: 0 : if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
5733 : 0 : !mlx5_flow_ext_mreg_supported(dev))
5734 : 0 : return rte_flow_error_set(error, ENOTSUP,
5735 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5736 : : "cannot modify mark in legacy mode"
5737 : : " or without extensive registers");
5738 [ # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_META ||
5739 [ # # ]: 0 : src_data->field == RTE_FLOW_FIELD_META) {
5740 [ # # # # ]: 0 : if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
5741 : 0 : !mlx5_flow_ext_mreg_supported(dev))
5742 : 0 : return rte_flow_error_set(error, ENOTSUP,
5743 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5744 : : "cannot modify meta without"
5745 : : " extensive registers support");
5746 : 0 : ret = flow_dv_get_metadata_reg(dev, attr, error);
5747 [ # # ]: 0 : if (ret < 0 || ret == REG_NON)
5748 : 0 : return rte_flow_error_set(error, ENOTSUP,
5749 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5750 : : "cannot modify meta without"
5751 : : " extensive registers available");
5752 : : }
5753 [ # # ]: 0 : if (conf->operation == RTE_FLOW_MODIFY_SUB)
5754 : 0 : return rte_flow_error_set(error, ENOTSUP,
5755 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5756 : : "sub operations are not supported");
5757 [ # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_IPV4_ECN ||
5758 [ # # # # ]: 0 : src_data->field == RTE_FLOW_FIELD_IPV4_ECN ||
5759 [ # # ]: 0 : dst_data->field == RTE_FLOW_FIELD_IPV6_ECN ||
5760 : : src_data->field == RTE_FLOW_FIELD_IPV6_ECN)
5761 [ # # # # ]: 0 : if (!hca_attr->modify_outer_ip_ecn && root)
5762 : 0 : return rte_flow_error_set(error, ENOTSUP,
5763 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5764 : : "modifications of the ECN for current firmware is not supported");
5765 : 0 : return (width / 32) + !!(width % 32);
5766 : : }
5767 : :
5768 : : /**
5769 : : * Validate jump action.
5770 : : *
5771 : : * @param[in] action
5772 : : * Pointer to the jump action.
5773 : : * @param[in] action_flags
5774 : : * Holds the actions detected until now.
5775 : : * @param[in] attributes
5776 : : * Pointer to flow attributes
5777 : : * @param[in] external
5778 : : * Action belongs to flow rule created by request external to PMD.
5779 : : * @param[out] error
5780 : : * Pointer to error structure.
5781 : : *
5782 : : * @return
5783 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5784 : : */
5785 : : static int
5786 : 0 : flow_dv_validate_action_jump(struct rte_eth_dev *dev,
5787 : : const struct mlx5_flow_tunnel *tunnel,
5788 : : const struct rte_flow_action *action,
5789 : : uint64_t action_flags,
5790 : : const struct rte_flow_attr *attributes,
5791 : : bool external, struct rte_flow_error *error)
5792 : : {
5793 : 0 : uint32_t target_group, table = 0;
5794 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5795 : : int ret = 0;
5796 : 0 : struct flow_grp_info grp_info = {
5797 : : .external = !!external,
5798 : 0 : .transfer = !!attributes->transfer,
5799 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
5800 : : .std_tbl_fix = 0
5801 : : };
5802 [ # # ]: 0 : if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
5803 : : MLX5_FLOW_FATE_ESWITCH_ACTIONS))
5804 : 0 : return rte_flow_error_set(error, EINVAL,
5805 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5806 : : "can't have 2 fate actions in"
5807 : : " same flow");
5808 [ # # ]: 0 : if (!action->conf)
5809 : 0 : return rte_flow_error_set(error, EINVAL,
5810 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5811 : : NULL, "action configuration not set");
5812 : 0 : target_group =
5813 : : ((const struct rte_flow_action_jump *)action->conf)->group;
5814 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel, target_group, &table,
5815 : : &grp_info, error);
5816 [ # # ]: 0 : if (ret)
5817 : : return ret;
5818 [ # # ]: 0 : if (table == 0)
5819 : 0 : return rte_flow_error_set(error, EINVAL,
5820 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5821 : : NULL, "root table shouldn't be destination");
5822 : : return 0;
5823 : : }
5824 : :
5825 : : /*
5826 : : * Validate action PORT_ID / REPRESENTED_PORT.
5827 : : *
5828 : : * @param[in] dev
5829 : : * Pointer to rte_eth_dev structure.
5830 : : * @param[in] action_flags
5831 : : * Bit-fields that holds the actions detected until now.
5832 : : * @param[in] action
5833 : : * PORT_ID / REPRESENTED_PORT action structure.
5834 : : * @param[in] attr
5835 : : * Attributes of flow that includes this action.
5836 : : * @param[out] error
5837 : : * Pointer to error structure.
5838 : : *
5839 : : * @return
5840 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5841 : : */
5842 : : static int
5843 : 0 : flow_dv_validate_action_port_id(struct rte_eth_dev *dev,
5844 : : uint64_t action_flags,
5845 : : const struct rte_flow_action *action,
5846 : : const struct rte_flow_attr *attr,
5847 : : struct rte_flow_error *error)
5848 : : {
5849 : : const struct rte_flow_action_port_id *port_id;
5850 : : const struct rte_flow_action_ethdev *ethdev;
5851 : : struct mlx5_priv *act_priv;
5852 : : struct mlx5_priv *dev_priv;
5853 : : uint16_t port;
5854 : :
5855 [ # # ]: 0 : if (!attr->transfer)
5856 : 0 : return rte_flow_error_set(error, ENOTSUP,
5857 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5858 : : NULL,
5859 : : "port action is valid in transfer"
5860 : : " mode only");
5861 [ # # # # ]: 0 : if (!action || !action->conf)
5862 : 0 : return rte_flow_error_set(error, ENOTSUP,
5863 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5864 : : NULL,
5865 : : "port action parameters must be"
5866 : : " specified");
5867 [ # # ]: 0 : if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
5868 : : MLX5_FLOW_FATE_ESWITCH_ACTIONS))
5869 : 0 : return rte_flow_error_set(error, EINVAL,
5870 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5871 : : "can have only one fate actions in"
5872 : : " a flow");
5873 : 0 : dev_priv = mlx5_dev_to_eswitch_info(dev);
5874 [ # # ]: 0 : if (!dev_priv)
5875 : 0 : return rte_flow_error_set(error, rte_errno,
5876 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5877 : : NULL,
5878 : : "failed to obtain E-Switch info");
5879 [ # # # ]: 0 : switch (action->type) {
5880 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
5881 : 0 : port_id = action->conf;
5882 [ # # ]: 0 : port = port_id->original ? dev->data->port_id : port_id->id;
5883 : : break;
5884 : 0 : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
5885 : 0 : ethdev = action->conf;
5886 : 0 : port = ethdev->port_id;
5887 : 0 : break;
5888 : 0 : default:
5889 : : MLX5_ASSERT(false);
5890 : 0 : return rte_flow_error_set
5891 : : (error, EINVAL,
5892 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5893 : : "unknown E-Switch action");
5894 : : }
5895 : 0 : act_priv = mlx5_port_to_eswitch_info(port, false);
5896 [ # # ]: 0 : if (!act_priv)
5897 : 0 : return rte_flow_error_set
5898 : : (error, rte_errno,
5899 : 0 : RTE_FLOW_ERROR_TYPE_ACTION_CONF, action->conf,
5900 : : "failed to obtain E-Switch port id for port");
5901 [ # # ]: 0 : if (act_priv->domain_id != dev_priv->domain_id)
5902 : 0 : return rte_flow_error_set
5903 : : (error, EINVAL,
5904 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5905 : : "port does not belong to"
5906 : : " E-Switch being configured");
5907 : : return 0;
5908 : : }
5909 : :
5910 : : /**
5911 : : * Get the maximum number of modify header actions.
5912 : : *
5913 : : * @param dev
5914 : : * Pointer to rte_eth_dev structure.
5915 : : * @param root
5916 : : * Whether action is on root table.
5917 : : *
5918 : : * @return
5919 : : * Max number of modify header actions device can support.
5920 : : */
5921 : : static inline unsigned int
5922 : : flow_dv_modify_hdr_action_max(struct rte_eth_dev *dev __rte_unused,
5923 : : bool root)
5924 : : {
5925 : : /*
5926 : : * There's no way to directly query the max capacity from FW.
5927 : : * The maximal value on root table should be assumed to be supported.
5928 : : */
5929 [ # # ]: 0 : if (!root)
5930 : : return MLX5_MAX_MODIFY_NUM;
5931 : : else
5932 : 0 : return MLX5_ROOT_TBL_MODIFY_NUM;
5933 : : }
5934 : :
5935 : : /**
5936 : : * Validate the meter action.
5937 : : *
5938 : : * @param[in] dev
5939 : : * Pointer to rte_eth_dev structure.
5940 : : * @param[in] action_flags
5941 : : * Bit-fields that holds the actions detected until now.
5942 : : * @param[in] item_flags
5943 : : * Holds the items detected.
5944 : : * @param[in] action
5945 : : * Pointer to the meter action.
5946 : : * @param[in] attr
5947 : : * Attributes of flow that includes this action.
5948 : : * @param[in] port_id_item
5949 : : * Pointer to item indicating port id.
5950 : : * @param[out] error
5951 : : * Pointer to error structure.
5952 : : *
5953 : : * @return
5954 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5955 : : */
5956 : : static int
5957 : 0 : mlx5_flow_validate_action_meter(struct rte_eth_dev *dev,
5958 : : uint64_t action_flags, uint64_t item_flags,
5959 : : const struct rte_flow_action *action,
5960 : : const struct rte_flow_attr *attr,
5961 : : const struct rte_flow_item *port_id_item,
5962 : : bool *def_policy,
5963 : : struct rte_flow_error *error)
5964 : : {
5965 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5966 : 0 : const struct rte_flow_action_meter *am = action->conf;
5967 : : struct mlx5_flow_meter_info *fm;
5968 : : struct mlx5_flow_meter_policy *mtr_policy;
5969 : 0 : struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
5970 : 0 : uint16_t flow_src_port = priv->representor_id;
5971 : 0 : bool all_ports = false;
5972 : :
5973 [ # # ]: 0 : if (!am)
5974 : 0 : return rte_flow_error_set(error, EINVAL,
5975 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5976 : : "meter action conf is NULL");
5977 : :
5978 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_METER)
5979 : 0 : return rte_flow_error_set(error, ENOTSUP,
5980 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5981 : : "meter chaining not support");
5982 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_JUMP)
5983 : 0 : return rte_flow_error_set(error, ENOTSUP,
5984 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5985 : : "meter with jump not support");
5986 [ # # ]: 0 : if (!priv->mtr_en)
5987 : 0 : return rte_flow_error_set(error, ENOTSUP,
5988 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5989 : : NULL,
5990 : : "meter action not supported");
5991 : 0 : fm = mlx5_flow_meter_find(priv, am->mtr_id, NULL);
5992 [ # # ]: 0 : if (!fm)
5993 : 0 : return rte_flow_error_set(error, EINVAL,
5994 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5995 : : "Meter not found");
5996 : : /* aso meter can always be shared by different domains */
5997 [ # # # # ]: 0 : if (fm->ref_cnt && !priv->sh->meter_aso_en &&
5998 [ # # ]: 0 : !(fm->transfer == attr->transfer ||
5999 [ # # # # ]: 0 : (!fm->ingress && !attr->ingress && attr->egress) ||
6000 [ # # # # ]: 0 : (!fm->egress && !attr->egress && attr->ingress)))
6001 : 0 : return rte_flow_error_set(error, EINVAL,
6002 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6003 : : "Flow attributes domain are either invalid "
6004 : : "or have a domain conflict with current "
6005 : : "meter attributes");
6006 [ # # ]: 0 : if (fm->def_policy) {
6007 [ # # ]: 0 : if (!((attr->transfer &&
6008 [ # # ]: 0 : mtrmng->def_policy[MLX5_MTR_DOMAIN_TRANSFER]) ||
6009 [ # # ]: 0 : (attr->egress &&
6010 [ # # ]: 0 : mtrmng->def_policy[MLX5_MTR_DOMAIN_EGRESS]) ||
6011 [ # # ]: 0 : (attr->ingress &&
6012 [ # # ]: 0 : mtrmng->def_policy[MLX5_MTR_DOMAIN_INGRESS])))
6013 : 0 : return rte_flow_error_set(error, EINVAL,
6014 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6015 : : "Flow attributes domain "
6016 : : "have a conflict with current "
6017 : : "meter domain attributes");
6018 : 0 : *def_policy = true;
6019 : : } else {
6020 : 0 : mtr_policy = mlx5_flow_meter_policy_find(dev,
6021 : : fm->policy_id, NULL);
6022 [ # # ]: 0 : if (!mtr_policy)
6023 : 0 : return rte_flow_error_set(error, EINVAL,
6024 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6025 : : "Invalid policy id for meter ");
6026 [ # # # # ]: 0 : if (!((attr->transfer && mtr_policy->transfer) ||
6027 [ # # # # ]: 0 : (attr->egress && mtr_policy->egress) ||
6028 [ # # # # ]: 0 : (attr->ingress && mtr_policy->ingress)))
6029 : 0 : return rte_flow_error_set(error, EINVAL,
6030 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6031 : : "Flow attributes domain "
6032 : : "have a conflict with current "
6033 : : "meter domain attributes");
6034 [ # # ]: 0 : if (port_id_item) {
6035 [ # # ]: 0 : if (mlx5_flow_get_item_vport_id(dev, port_id_item, &flow_src_port,
6036 : : &all_ports, error))
6037 : 0 : return -rte_errno;
6038 : : }
6039 [ # # ]: 0 : if (attr->transfer) {
6040 : : /* When flow matching all src ports, meter should not have drop count. */
6041 [ # # # # : 0 : if (all_ports && (fm->drop_cnt || mtr_policy->hierarchy_match_port))
# # ]
6042 : 0 : return rte_flow_error_set(error, EINVAL,
6043 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
6044 : : "Meter drop count or "
6045 : : "modify_field/set_tag in meter hierarchy "
6046 : : "not supported when matching all ports.");
6047 [ # # ]: 0 : } else if (mtr_policy->is_rss) {
6048 : : struct mlx5_flow_meter_policy *fp;
6049 : : struct mlx5_meter_policy_action_container *acg;
6050 : : struct mlx5_meter_policy_action_container *acy;
6051 : : const struct rte_flow_action *rss_act;
6052 : : int ret;
6053 : :
6054 : 0 : fp = mlx5_flow_meter_hierarchy_get_final_policy(dev,
6055 : : mtr_policy);
6056 [ # # ]: 0 : if (fp == NULL)
6057 : 0 : return rte_flow_error_set(error, EINVAL,
6058 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6059 : : "Unable to get the final "
6060 : : "policy in the hierarchy");
6061 : : acg = &fp->act_cnt[RTE_COLOR_GREEN];
6062 : : acy = &fp->act_cnt[RTE_COLOR_YELLOW];
6063 : : MLX5_ASSERT(acg->fate_action ==
6064 : : MLX5_FLOW_FATE_SHARED_RSS ||
6065 : : acy->fate_action ==
6066 : : MLX5_FLOW_FATE_SHARED_RSS);
6067 [ # # ]: 0 : if (acg->fate_action == MLX5_FLOW_FATE_SHARED_RSS)
6068 : 0 : rss_act = acg->rss;
6069 : : else
6070 : 0 : rss_act = acy->rss;
6071 : 0 : ret = mlx5_flow_validate_action_rss(rss_act,
6072 : : action_flags, dev, attr,
6073 : : item_flags, error);
6074 [ # # ]: 0 : if (ret)
6075 : : return ret;
6076 : : }
6077 : 0 : *def_policy = false;
6078 : : }
6079 : : return 0;
6080 : : }
6081 : :
6082 : : /**
6083 : : * Validate the age action.
6084 : : *
6085 : : * @param[in] action_flags
6086 : : * Holds the actions detected until now.
6087 : : * @param[in] action
6088 : : * Pointer to the age action.
6089 : : * @param[in] dev
6090 : : * Pointer to the Ethernet device structure.
6091 : : * @param[out] error
6092 : : * Pointer to error structure.
6093 : : *
6094 : : * @return
6095 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
6096 : : */
6097 : : static int
6098 : 0 : flow_dv_validate_action_age(uint64_t action_flags,
6099 : : const struct rte_flow_action *action,
6100 : : struct rte_eth_dev *dev,
6101 : : struct rte_flow_error *error)
6102 : : {
6103 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6104 : 0 : const struct rte_flow_action_age *age = action->conf;
6105 : :
6106 [ # # ]: 0 : if (!priv->sh->cdev->config.devx ||
6107 [ # # # # ]: 0 : (priv->sh->sws_cmng.counter_fallback && !priv->sh->aso_age_mng))
6108 : 0 : return rte_flow_error_set(error, ENOTSUP,
6109 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6110 : : NULL,
6111 : : "age action not supported");
6112 [ # # ]: 0 : if (!(action->conf))
6113 : 0 : return rte_flow_error_set(error, EINVAL,
6114 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6115 : : "configuration cannot be null");
6116 [ # # ]: 0 : if (!(age->timeout))
6117 : 0 : return rte_flow_error_set(error, EINVAL,
6118 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6119 : : "invalid timeout value 0");
6120 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_AGE)
6121 : 0 : return rte_flow_error_set(error, EINVAL,
6122 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6123 : : "duplicate age actions set");
6124 : : return 0;
6125 : : }
6126 : :
6127 : : /**
6128 : : * Validate the modify-header IPv4 DSCP actions.
6129 : : *
6130 : : * @param[in] action_flags
6131 : : * Holds the actions detected until now.
6132 : : * @param[in] action
6133 : : * Pointer to the modify action.
6134 : : * @param[in] item_flags
6135 : : * Holds the items detected.
6136 : : * @param[out] error
6137 : : * Pointer to error structure.
6138 : : *
6139 : : * @return
6140 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
6141 : : */
6142 : : static int
6143 : 0 : flow_dv_validate_action_modify_ipv4_dscp(const uint64_t action_flags,
6144 : : const struct rte_flow_action *action,
6145 : : const uint64_t item_flags,
6146 : : struct rte_flow_error *error)
6147 : : {
6148 : : int ret = 0;
6149 : :
6150 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
6151 [ # # ]: 0 : if (!ret) {
6152 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV4))
6153 : 0 : return rte_flow_error_set(error, EINVAL,
6154 : : RTE_FLOW_ERROR_TYPE_ACTION,
6155 : : NULL,
6156 : : "no ipv4 item in pattern");
6157 : : }
6158 : : return ret;
6159 : : }
6160 : :
6161 : : /**
6162 : : * Validate the modify-header IPv6 DSCP actions.
6163 : : *
6164 : : * @param[in] action_flags
6165 : : * Holds the actions detected until now.
6166 : : * @param[in] action
6167 : : * Pointer to the modify action.
6168 : : * @param[in] item_flags
6169 : : * Holds the items detected.
6170 : : * @param[out] error
6171 : : * Pointer to error structure.
6172 : : *
6173 : : * @return
6174 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
6175 : : */
6176 : : static int
6177 : 0 : flow_dv_validate_action_modify_ipv6_dscp(const uint64_t action_flags,
6178 : : const struct rte_flow_action *action,
6179 : : const uint64_t item_flags,
6180 : : struct rte_flow_error *error)
6181 : : {
6182 : : int ret = 0;
6183 : :
6184 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
6185 [ # # ]: 0 : if (!ret) {
6186 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV6))
6187 : 0 : return rte_flow_error_set(error, EINVAL,
6188 : : RTE_FLOW_ERROR_TYPE_ACTION,
6189 : : NULL,
6190 : : "no ipv6 item in pattern");
6191 : : }
6192 : : return ret;
6193 : : }
6194 : :
6195 : : int
6196 : 0 : flow_modify_match_cb(void *tool_ctx __rte_unused,
6197 : : struct mlx5_list_entry *entry, void *cb_ctx)
6198 : : {
6199 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
6200 : 0 : struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
6201 : : struct mlx5_flow_dv_modify_hdr_resource *resource =
6202 : : container_of(entry, typeof(*resource), entry);
6203 : : uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type);
6204 : :
6205 : 0 : key_len += ref->actions_num * sizeof(ref->actions[0]);
6206 [ # # ]: 0 : return ref->actions_num != resource->actions_num ||
6207 [ # # ]: 0 : memcmp(&ref->ft_type, &resource->ft_type, key_len);
6208 : : }
6209 : :
6210 : : static struct mlx5_indexed_pool *
6211 : 0 : flow_dv_modify_ipool_get(struct mlx5_dev_ctx_shared *sh, uint8_t index)
6212 : : {
6213 : 0 : struct mlx5_indexed_pool *ipool = rte_atomic_load_explicit
6214 : : (&sh->mdh_ipools[index], rte_memory_order_seq_cst);
6215 : :
6216 [ # # ]: 0 : if (!ipool) {
6217 : : struct mlx5_indexed_pool *expected = NULL;
6218 : 0 : struct mlx5_indexed_pool_config cfg =
6219 : : (struct mlx5_indexed_pool_config) {
6220 : 0 : .size = sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
6221 : 0 : (index + 1) *
6222 : : sizeof(struct mlx5_modification_cmd),
6223 : : .trunk_size = 64,
6224 : : .grow_trunk = 3,
6225 : : .grow_shift = 2,
6226 : : .need_lock = 1,
6227 : 0 : .release_mem_en = !!sh->config.reclaim_mode,
6228 : : .per_core_cache =
6229 [ # # ]: 0 : sh->config.reclaim_mode ? 0 : (1 << 16),
6230 : : .malloc = mlx5_malloc,
6231 : : .free = mlx5_free,
6232 : : .type = "mlx5_modify_action_resource",
6233 : : };
6234 : :
6235 : 0 : cfg.size = RTE_ALIGN(cfg.size, sizeof(ipool));
6236 : 0 : ipool = mlx5_ipool_create(&cfg);
6237 [ # # ]: 0 : if (!ipool)
6238 : 0 : return NULL;
6239 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(&sh->mdh_ipools[index],
6240 : : &expected, ipool,
6241 : : rte_memory_order_seq_cst,
6242 : : rte_memory_order_seq_cst)) {
6243 : 0 : mlx5_ipool_destroy(ipool);
6244 : 0 : ipool = rte_atomic_load_explicit(&sh->mdh_ipools[index],
6245 : : rte_memory_order_seq_cst);
6246 : : }
6247 : : }
6248 : : return ipool;
6249 : : }
6250 : :
6251 : : struct mlx5_list_entry *
6252 : 0 : flow_modify_create_cb(void *tool_ctx, void *cb_ctx)
6253 : : {
6254 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
6255 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
6256 : : struct mlx5dv_dr_domain *ns;
6257 : : struct mlx5_flow_dv_modify_hdr_resource *entry;
6258 : 0 : struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
6259 : 0 : struct mlx5_indexed_pool *ipool = flow_dv_modify_ipool_get(sh,
6260 : 0 : ref->actions_num - 1);
6261 : : int ret = 0;
6262 : 0 : uint32_t data_len = ref->actions_num * sizeof(ref->actions[0]);
6263 : : uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type);
6264 : : uint32_t idx;
6265 : :
6266 [ # # ]: 0 : if (unlikely(!ipool)) {
6267 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
6268 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6269 : : NULL, "cannot allocate modify ipool");
6270 : 0 : return NULL;
6271 : : }
6272 : 0 : entry = mlx5_ipool_zmalloc(ipool, &idx);
6273 [ # # ]: 0 : if (!entry) {
6274 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
6275 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6276 : : "cannot allocate resource memory");
6277 : 0 : return NULL;
6278 : : }
6279 : 0 : rte_memcpy(&entry->ft_type,
6280 : 0 : RTE_PTR_ADD(ref, offsetof(typeof(*ref), ft_type)),
6281 [ # # ]: 0 : key_len + data_len);
6282 [ # # ]: 0 : if (sh->config.dv_flow_en == 2) {
6283 : : #ifdef HAVE_MLX5_HWS_SUPPORT
6284 : 0 : struct mlx5dr_action_mh_pattern pattern = {
6285 : : .sz = data_len,
6286 : 0 : .data = (__be64 *)ref->actions
6287 : : };
6288 : 0 : entry->action = mlx5dr_action_create_modify_header(ctx->data2,
6289 : : 1,
6290 : 0 : &pattern, 0, ref->flags);
6291 [ # # ]: 0 : if (!entry->action)
6292 : : ret = -1;
6293 : : #else
6294 : : ret = -1;
6295 : : #endif
6296 : : } else {
6297 [ # # ]: 0 : if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
6298 : 0 : ns = sh->fdb_domain;
6299 [ # # ]: 0 : else if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
6300 : 0 : ns = sh->tx_domain;
6301 : : else
6302 : 0 : ns = sh->rx_domain;
6303 : 0 : ret = mlx5_flow_os_create_flow_action_modify_header
6304 : 0 : (sh->cdev->ctx, ns, entry,
6305 : : data_len, &entry->action);
6306 : : }
6307 : : if (ret) {
6308 : 0 : mlx5_ipool_free(sh->mdh_ipools[ref->actions_num - 1], idx);
6309 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
6310 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6311 : : NULL, "cannot create modification action");
6312 : 0 : return NULL;
6313 : : }
6314 : 0 : entry->idx = idx;
6315 : 0 : return &entry->entry;
6316 : : }
6317 : :
6318 : : struct mlx5_list_entry *
6319 : 0 : flow_modify_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
6320 : : void *cb_ctx)
6321 : : {
6322 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
6323 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
6324 : : struct mlx5_flow_dv_modify_hdr_resource *entry;
6325 : 0 : struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
6326 : 0 : uint32_t data_len = ref->actions_num * sizeof(ref->actions[0]);
6327 : : uint32_t idx;
6328 : :
6329 : 0 : entry = mlx5_ipool_malloc(sh->mdh_ipools[ref->actions_num - 1],
6330 : : &idx);
6331 [ # # ]: 0 : if (!entry) {
6332 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
6333 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6334 : : "cannot allocate resource memory");
6335 : 0 : return NULL;
6336 : : }
6337 : 0 : memcpy(entry, oentry, sizeof(*entry) + data_len);
6338 : 0 : entry->idx = idx;
6339 : 0 : return &entry->entry;
6340 : : }
6341 : :
6342 : : void
6343 : 0 : flow_modify_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
6344 : : {
6345 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
6346 : : struct mlx5_flow_dv_modify_hdr_resource *res =
6347 : : container_of(entry, typeof(*res), entry);
6348 : :
6349 : 0 : mlx5_ipool_free(sh->mdh_ipools[res->actions_num - 1], res->idx);
6350 : 0 : }
6351 : :
6352 : : /**
6353 : : * Validate the sample action.
6354 : : *
6355 : : * @param[in, out] action_flags
6356 : : * Holds the actions detected until now.
6357 : : * @param[in] action
6358 : : * Pointer to the sample action.
6359 : : * @param[in] dev
6360 : : * Pointer to the Ethernet device structure.
6361 : : * @param[in] attr
6362 : : * Attributes of flow that includes this action.
6363 : : * @param[in] item_flags
6364 : : * Holds the items detected.
6365 : : * @param[in] rss
6366 : : * Pointer to the RSS action.
6367 : : * @param[out] sample_rss
6368 : : * Pointer to the RSS action in sample action list.
6369 : : * @param[out] count
6370 : : * Pointer to the COUNT action in sample action list.
6371 : : * @param[out] fdb_mirror
6372 : : * Pointer to the FDB mirror flag.
6373 : : * @param root
6374 : : * Whether action is on root table.
6375 : : * @param[out] error
6376 : : * Pointer to error structure.
6377 : : *
6378 : : * @return
6379 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
6380 : : */
6381 : : static int
6382 : 0 : flow_dv_validate_action_sample(uint64_t *action_flags,
6383 : : uint64_t *sub_action_flags,
6384 : : const struct rte_flow_action *action,
6385 : : struct rte_eth_dev *dev,
6386 : : const struct rte_flow_attr *attr,
6387 : : uint64_t item_flags,
6388 : : const struct rte_flow_action_rss *rss,
6389 : : const struct rte_flow_action_rss **sample_rss,
6390 : : const struct rte_flow_action_count **count,
6391 : : int *fdb_mirror,
6392 : : uint16_t *sample_port_id,
6393 : : bool root,
6394 : : struct rte_flow_error *error)
6395 : : {
6396 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6397 : 0 : struct mlx5_sh_config *dev_conf = &priv->sh->config;
6398 : 0 : const struct rte_flow_action_sample *sample = action->conf;
6399 : : const struct rte_flow_action_port_id *port = NULL;
6400 : : const struct rte_flow_action *act;
6401 : : uint16_t queue_index = 0xFFFF;
6402 : 0 : int actions_n = 0;
6403 : : int ret;
6404 : :
6405 [ # # ]: 0 : if (!sample)
6406 : 0 : return rte_flow_error_set(error, EINVAL,
6407 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6408 : : "configuration cannot be NULL");
6409 [ # # ]: 0 : if (sample->ratio == 0)
6410 : 0 : return rte_flow_error_set(error, EINVAL,
6411 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6412 : : "ratio value starts from 1");
6413 [ # # ]: 0 : if (!priv->sh->cdev->config.devx ||
6414 [ # # ]: 0 : (sample->ratio > 0 && !priv->sampler_en))
6415 : 0 : return rte_flow_error_set(error, ENOTSUP,
6416 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6417 : : NULL,
6418 : : "sample action not supported");
6419 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_SAMPLE)
6420 : 0 : return rte_flow_error_set(error, EINVAL,
6421 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6422 : : "Multiple sample actions not "
6423 : : "supported");
6424 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_METER)
6425 : 0 : return rte_flow_error_set(error, EINVAL,
6426 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6427 : : "wrong action order, meter should "
6428 : : "be after sample action");
6429 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_JUMP)
6430 : 0 : return rte_flow_error_set(error, EINVAL,
6431 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6432 : : "wrong action order, jump should "
6433 : : "be after sample action");
6434 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_CT)
6435 : 0 : return rte_flow_error_set(error, EINVAL,
6436 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6437 : : "Sample after CT not supported");
6438 : 0 : act = sample->actions;
6439 [ # # ]: 0 : for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++) {
6440 [ # # ]: 0 : if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
6441 : 0 : return rte_flow_error_set(error, ENOTSUP,
6442 : : RTE_FLOW_ERROR_TYPE_ACTION,
6443 : : act, "too many actions");
6444 [ # # # # : 0 : switch (act->type) {
# # # # ]
6445 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
6446 : 0 : ret = mlx5_flow_validate_action_queue(act,
6447 : : *sub_action_flags,
6448 : : dev,
6449 : : attr, error);
6450 [ # # ]: 0 : if (ret < 0)
6451 : 0 : return ret;
6452 : 0 : queue_index = ((const struct rte_flow_action_queue *)
6453 : 0 : (act->conf))->index;
6454 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_QUEUE;
6455 : 0 : ++actions_n;
6456 : 0 : break;
6457 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
6458 : 0 : *sample_rss = act->conf;
6459 : 0 : ret = mlx5_flow_validate_action_rss(act,
6460 : : *sub_action_flags,
6461 : : dev, attr,
6462 : : item_flags,
6463 : : error);
6464 [ # # ]: 0 : if (ret < 0)
6465 : 0 : return ret;
6466 [ # # # # ]: 0 : if (rss && *sample_rss &&
6467 [ # # ]: 0 : ((*sample_rss)->level != rss->level ||
6468 [ # # ]: 0 : (*sample_rss)->types != rss->types))
6469 : 0 : return rte_flow_error_set(error, ENOTSUP,
6470 : : RTE_FLOW_ERROR_TYPE_ACTION,
6471 : : NULL,
6472 : : "Can't use the different RSS types "
6473 : : "or level in the same flow");
6474 [ # # # # ]: 0 : if (*sample_rss != NULL && (*sample_rss)->queue_num)
6475 : 0 : queue_index = (*sample_rss)->queue[0];
6476 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_RSS;
6477 : 0 : ++actions_n;
6478 : 0 : break;
6479 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
6480 : 0 : ret = flow_dv_validate_action_mark(dev, act,
6481 : : *sub_action_flags,
6482 : : attr, error);
6483 [ # # ]: 0 : if (ret < 0)
6484 : 0 : return ret;
6485 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY)
6486 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_MARK |
6487 : : MLX5_FLOW_ACTION_MARK_EXT;
6488 : : else
6489 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_MARK;
6490 : 0 : ++actions_n;
6491 : 0 : break;
6492 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
6493 : 0 : ret = flow_dv_validate_action_count
6494 : 0 : (dev, false, *action_flags | *sub_action_flags,
6495 : : root, error);
6496 [ # # ]: 0 : if (ret < 0)
6497 : 0 : return ret;
6498 : 0 : *count = act->conf;
6499 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_COUNT;
6500 : 0 : *action_flags |= MLX5_FLOW_ACTION_COUNT;
6501 : 0 : ++actions_n;
6502 : 0 : break;
6503 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
6504 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
6505 : 0 : ret = flow_dv_validate_action_port_id(dev,
6506 : : *sub_action_flags,
6507 : : act,
6508 : : attr,
6509 : : error);
6510 [ # # ]: 0 : if (ret)
6511 : 0 : return ret;
6512 [ # # ]: 0 : if (act->type == RTE_FLOW_ACTION_TYPE_PORT_ID) {
6513 : 0 : port = (const struct rte_flow_action_port_id *)
6514 : : act->conf;
6515 [ # # ]: 0 : *sample_port_id = port->original ?
6516 : 0 : dev->data->port_id : port->id;
6517 : : } else {
6518 : 0 : *sample_port_id = ((const struct rte_flow_action_ethdev *)
6519 : 0 : act->conf)->port_id;
6520 : : }
6521 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_PORT_ID;
6522 : 0 : ++actions_n;
6523 : 0 : break;
6524 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
6525 : 0 : ret = mlx5_flow_dv_validate_action_raw_encap_decap
6526 : 0 : (dev, NULL, act->conf, attr, sub_action_flags,
6527 : : &actions_n, action, item_flags, error);
6528 [ # # ]: 0 : if (ret < 0)
6529 : 0 : return ret;
6530 : 0 : ++actions_n;
6531 : 0 : break;
6532 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
6533 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
6534 : 0 : ret = mlx5_flow_dv_validate_action_l2_encap(dev,
6535 : : *sub_action_flags,
6536 : : act, attr,
6537 : : error);
6538 [ # # ]: 0 : if (ret < 0)
6539 : 0 : return ret;
6540 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_ENCAP;
6541 : 0 : ++actions_n;
6542 : 0 : break;
6543 : 0 : default:
6544 : 0 : return rte_flow_error_set(error, ENOTSUP,
6545 : : RTE_FLOW_ERROR_TYPE_ACTION,
6546 : : NULL,
6547 : : "Doesn't support optional "
6548 : : "action");
6549 : : }
6550 : : }
6551 [ # # ]: 0 : if (attr->ingress) {
6552 [ # # ]: 0 : if (!(*sub_action_flags & (MLX5_FLOW_ACTION_QUEUE |
6553 : : MLX5_FLOW_ACTION_RSS)))
6554 : 0 : return rte_flow_error_set(error, EINVAL,
6555 : : RTE_FLOW_ERROR_TYPE_ACTION,
6556 : : NULL,
6557 : : "Ingress must has a dest "
6558 : : "QUEUE for Sample");
6559 [ # # ]: 0 : } else if (attr->egress) {
6560 : 0 : return rte_flow_error_set(error, ENOTSUP,
6561 : : RTE_FLOW_ERROR_TYPE_ACTION,
6562 : : NULL,
6563 : : "Sample Only support Ingress "
6564 : : "or E-Switch");
6565 [ # # ]: 0 : } else if (sample->actions->type != RTE_FLOW_ACTION_TYPE_END) {
6566 : : MLX5_ASSERT(attr->transfer);
6567 [ # # ]: 0 : if (sample->ratio > 1)
6568 : 0 : return rte_flow_error_set(error, ENOTSUP,
6569 : : RTE_FLOW_ERROR_TYPE_ACTION,
6570 : : NULL,
6571 : : "E-Switch doesn't support "
6572 : : "any optional action "
6573 : : "for sampling");
6574 [ # # ]: 0 : if (*sub_action_flags & MLX5_FLOW_ACTION_QUEUE)
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_RSS)
6580 : 0 : return rte_flow_error_set(error, ENOTSUP,
6581 : : RTE_FLOW_ERROR_TYPE_ACTION,
6582 : : NULL,
6583 : : "unsupported action QUEUE");
6584 [ # # ]: 0 : if (!(*sub_action_flags & MLX5_FLOW_ACTION_PORT_ID))
6585 : 0 : return rte_flow_error_set(error, EINVAL,
6586 : : RTE_FLOW_ERROR_TYPE_ACTION,
6587 : : NULL,
6588 : : "E-Switch must has a dest "
6589 : : "port for mirroring");
6590 : 0 : *fdb_mirror = 1;
6591 : : }
6592 : : /* Continue validation for Xcap actions.*/
6593 [ # # # # ]: 0 : if ((*sub_action_flags & MLX5_FLOW_XCAP_ACTIONS) &&
6594 [ # # ]: 0 : (queue_index == 0xFFFF || !mlx5_rxq_is_hairpin(dev, queue_index))) {
6595 [ # # ]: 0 : if ((*sub_action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
6596 : : MLX5_FLOW_XCAP_ACTIONS)
6597 : 0 : return rte_flow_error_set(error, ENOTSUP,
6598 : : RTE_FLOW_ERROR_TYPE_ACTION,
6599 : : NULL, "encap and decap "
6600 : : "combination aren't "
6601 : : "supported");
6602 [ # # # # ]: 0 : if (attr->ingress && (*sub_action_flags & MLX5_FLOW_ACTION_ENCAP))
6603 : 0 : return rte_flow_error_set(error, ENOTSUP,
6604 : : RTE_FLOW_ERROR_TYPE_ACTION,
6605 : : NULL, "encap is not supported"
6606 : : " for ingress traffic");
6607 : : }
6608 : : return 0;
6609 : : }
6610 : :
6611 : : int
6612 : 0 : __flow_modify_hdr_resource_register(struct rte_eth_dev *dev,
6613 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
6614 : : struct mlx5_flow_dv_modify_hdr_resource **modify,
6615 : : struct rte_flow_error *error)
6616 : : {
6617 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6618 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
6619 : 0 : uint32_t key_len = sizeof(*resource) -
6620 : : offsetof(typeof(*resource), ft_type) +
6621 : 0 : resource->actions_num * sizeof(resource->actions[0]);
6622 : : struct mlx5_list_entry *entry;
6623 : 0 : struct mlx5_flow_cb_ctx ctx = {
6624 : : .error = error,
6625 : : .data = resource,
6626 : 0 : .data2 = priv->dr_ctx,
6627 : : };
6628 : : struct mlx5_hlist *modify_cmds;
6629 : : uint64_t key64;
6630 : :
6631 : 0 : modify_cmds = flow_dv_hlist_prepare(sh, &sh->modify_cmds,
6632 : : "hdr_modify",
6633 : : MLX5_FLOW_HDR_MODIFY_HTABLE_SZ,
6634 : : true, false, sh,
6635 : : flow_modify_create_cb,
6636 : : flow_modify_match_cb,
6637 : : flow_modify_remove_cb,
6638 : : flow_modify_clone_cb,
6639 : : flow_modify_clone_free_cb,
6640 : : error);
6641 [ # # ]: 0 : if (unlikely(!modify_cmds))
6642 : 0 : return -rte_errno;
6643 [ # # ]: 0 : if (resource->actions_num > flow_dv_modify_hdr_action_max(dev,
6644 [ # # ]: 0 : resource->root))
6645 : 0 : return rte_flow_error_set(error, EOVERFLOW,
6646 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6647 : : "too many modify header items");
6648 : 0 : key64 = __rte_raw_cksum(&resource->ft_type, key_len, 0);
6649 : 0 : entry = mlx5_hlist_register(modify_cmds, key64, &ctx);
6650 [ # # ]: 0 : if (!entry)
6651 : 0 : return -rte_errno;
6652 : 0 : *modify = container_of(entry, typeof(*resource), entry);
6653 : 0 : return 0;
6654 : : }
6655 : :
6656 : : /**
6657 : : * Find existing modify-header resource or create and register a new one.
6658 : : *
6659 : : * @param dev[in, out]
6660 : : * Pointer to rte_eth_dev structure.
6661 : : * @param[in, out] resource
6662 : : * Pointer to modify-header resource.
6663 : : * @param[in, out] dev_flow
6664 : : * Pointer to the dev_flow.
6665 : : * @param[out] error
6666 : : * pointer to error structure.
6667 : : *
6668 : : * @return
6669 : : * 0 on success otherwise -errno and errno is set.
6670 : : */
6671 : : static int
6672 : : flow_dv_modify_hdr_resource_register
6673 : : (struct rte_eth_dev *dev,
6674 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
6675 : : struct mlx5_flow *dev_flow,
6676 : : struct rte_flow_error *error)
6677 : : {
6678 : 0 : resource->root = !dev_flow->dv.group;
6679 : 0 : return __flow_modify_hdr_resource_register(dev, resource,
6680 : 0 : &dev_flow->handle->dvh.modify_hdr, error);
6681 : : }
6682 : :
6683 : : /**
6684 : : * Get DV flow counter by index.
6685 : : *
6686 : : * @param[in] dev
6687 : : * Pointer to the Ethernet device structure.
6688 : : * @param[in] idx
6689 : : * mlx5 flow counter index in the container.
6690 : : * @param[out] ppool
6691 : : * mlx5 flow counter pool in the container.
6692 : : *
6693 : : * @return
6694 : : * Pointer to the counter, NULL otherwise.
6695 : : */
6696 : : static struct mlx5_flow_counter *
6697 : : flow_dv_counter_get_by_idx(struct rte_eth_dev *dev,
6698 : : uint32_t idx,
6699 : : struct mlx5_flow_counter_pool **ppool)
6700 : : {
6701 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6702 : 0 : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
6703 : : struct mlx5_flow_counter_pool *pool;
6704 : :
6705 : : /* Decrease to original index and clear shared bit. */
6706 : 0 : idx = (idx - 1) & (MLX5_CNT_SHARED_OFFSET - 1);
6707 : : MLX5_ASSERT(idx / MLX5_COUNTERS_PER_POOL < MLX5_COUNTER_POOLS_MAX_NUM);
6708 : 0 : pool = cmng->pools[idx / MLX5_COUNTERS_PER_POOL];
6709 : : MLX5_ASSERT(pool);
6710 : : if (ppool)
6711 : : *ppool = pool;
6712 [ # # # # : 0 : return MLX5_POOL_GET_CNT(pool, idx % MLX5_COUNTERS_PER_POOL);
# # # # #
# # # ]
6713 : : }
6714 : :
6715 : : /**
6716 : : * Check the devx counter belongs to the pool.
6717 : : *
6718 : : * @param[in] pool
6719 : : * Pointer to the counter pool.
6720 : : * @param[in] id
6721 : : * The counter devx ID.
6722 : : *
6723 : : * @return
6724 : : * True if counter belongs to the pool, false otherwise.
6725 : : */
6726 : : static bool
6727 : : flow_dv_is_counter_in_pool(struct mlx5_flow_counter_pool *pool, int id)
6728 : : {
6729 : 0 : int base = (pool->min_dcs->id / MLX5_COUNTERS_PER_POOL) *
6730 : : MLX5_COUNTERS_PER_POOL;
6731 : :
6732 [ # # # # ]: 0 : if (id >= base && id < base + MLX5_COUNTERS_PER_POOL)
6733 : : return true;
6734 : : return false;
6735 : : }
6736 : :
6737 : : /**
6738 : : * Get a pool by devx counter ID.
6739 : : *
6740 : : * @param[in] cmng
6741 : : * Pointer to the counter management.
6742 : : * @param[in] id
6743 : : * The counter devx ID.
6744 : : *
6745 : : * @return
6746 : : * The counter pool pointer if exists, NULL otherwise,
6747 : : */
6748 : : static struct mlx5_flow_counter_pool *
6749 : 0 : flow_dv_find_pool_by_id(struct mlx5_flow_counter_mng *cmng, int id)
6750 : : {
6751 : : uint32_t i;
6752 : : struct mlx5_flow_counter_pool *pool = NULL;
6753 : :
6754 : 0 : rte_spinlock_lock(&cmng->pool_update_sl);
6755 : : /* Check last used pool. */
6756 [ # # ]: 0 : if (cmng->last_pool_idx != POOL_IDX_INVALID &&
6757 [ # # ]: 0 : flow_dv_is_counter_in_pool(cmng->pools[cmng->last_pool_idx], id)) {
6758 : : pool = cmng->pools[cmng->last_pool_idx];
6759 : 0 : goto out;
6760 : : }
6761 : : /* ID out of range means no suitable pool in the container. */
6762 [ # # # # ]: 0 : if (id > cmng->max_id || id < cmng->min_id)
6763 : 0 : goto out;
6764 : : /*
6765 : : * Find the pool from the end of the container, since mostly counter
6766 : : * ID is sequence increasing, and the last pool should be the needed
6767 : : * one.
6768 : : */
6769 : 0 : i = cmng->n_valid;
6770 [ # # ]: 0 : while (i--) {
6771 [ # # ]: 0 : struct mlx5_flow_counter_pool *pool_tmp = cmng->pools[i];
6772 : :
6773 : : if (flow_dv_is_counter_in_pool(pool_tmp, id)) {
6774 : : pool = pool_tmp;
6775 : : break;
6776 : : }
6777 : : }
6778 : 0 : out:
6779 : : rte_spinlock_unlock(&cmng->pool_update_sl);
6780 : 0 : return pool;
6781 : : }
6782 : :
6783 : : /**
6784 : : * Query a devx flow counter.
6785 : : *
6786 : : * @param[in] dev
6787 : : * Pointer to the Ethernet device structure.
6788 : : * @param[in] counter
6789 : : * Index to the flow counter.
6790 : : * @param[out] pkts
6791 : : * The statistics value of packets.
6792 : : * @param[out] bytes
6793 : : * The statistics value of bytes.
6794 : : *
6795 : : * @return
6796 : : * 0 on success, otherwise a negative errno value and rte_errno is set.
6797 : : */
6798 : : static inline int
6799 : 0 : _flow_dv_query_count(struct rte_eth_dev *dev, uint32_t counter, uint64_t *pkts,
6800 : : uint64_t *bytes)
6801 : : {
6802 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
6803 : : struct mlx5_flow_counter_pool *pool = NULL;
6804 : : struct mlx5_flow_counter *cnt;
6805 : : int offset;
6806 : :
6807 : : cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
6808 : : MLX5_ASSERT(pool);
6809 [ # # ]: 0 : if (priv->sh->sws_cmng.counter_fallback)
6810 : 0 : return mlx5_devx_cmd_flow_counter_query(cnt->dcs_when_active, 0,
6811 : : 0, pkts, bytes, 0, NULL, NULL, 0);
6812 : 0 : rte_spinlock_lock(&pool->sl);
6813 [ # # ]: 0 : if (!pool->raw) {
6814 : 0 : *pkts = 0;
6815 : 0 : *bytes = 0;
6816 : : } else {
6817 [ # # ]: 0 : offset = MLX5_CNT_ARRAY_IDX(pool, cnt);
6818 : 0 : *pkts = rte_be_to_cpu_64(pool->raw->data[offset].hits);
6819 : 0 : *bytes = rte_be_to_cpu_64(pool->raw->data[offset].bytes);
6820 : : }
6821 : : rte_spinlock_unlock(&pool->sl);
6822 : 0 : return 0;
6823 : : }
6824 : :
6825 : : /**
6826 : : * Create and initialize a new counter pool.
6827 : : *
6828 : : * @param[in] dev
6829 : : * Pointer to the Ethernet device structure.
6830 : : * @param[out] dcs
6831 : : * The devX counter handle.
6832 : : * @param[in] age
6833 : : * Whether the pool is for counter that was allocated for aging.
6834 : : *
6835 : : * @return
6836 : : * The pool container pointer on success, NULL otherwise and rte_errno is set.
6837 : : */
6838 : : static struct mlx5_flow_counter_pool *
6839 : 0 : flow_dv_pool_create(struct rte_eth_dev *dev, struct mlx5_devx_obj *dcs,
6840 : : uint32_t age)
6841 : : {
6842 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6843 : : struct mlx5_flow_counter_pool *pool;
6844 : 0 : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
6845 : 0 : bool fallback = cmng->counter_fallback;
6846 : : uint32_t size = sizeof(*pool);
6847 : :
6848 [ # # ]: 0 : if (cmng->n_valid == MLX5_COUNTER_POOLS_MAX_NUM) {
6849 : 0 : DRV_LOG(ERR, "All counter is in used, try again later.");
6850 : 0 : rte_errno = EAGAIN;
6851 : 0 : return NULL;
6852 : : }
6853 : : size += MLX5_COUNTERS_PER_POOL * MLX5_CNT_SIZE;
6854 [ # # ]: 0 : size += (!age ? 0 : MLX5_COUNTERS_PER_POOL * MLX5_AGE_SIZE);
6855 : 0 : pool = mlx5_malloc(MLX5_MEM_ZERO, size, 0, SOCKET_ID_ANY);
6856 [ # # ]: 0 : if (!pool) {
6857 : 0 : rte_errno = ENOMEM;
6858 : 0 : return NULL;
6859 : : }
6860 : 0 : pool->raw = NULL;
6861 : 0 : pool->is_aged = !!age;
6862 : 0 : pool->query_gen = 0;
6863 : 0 : pool->min_dcs = dcs;
6864 : : rte_spinlock_init(&pool->sl);
6865 : : rte_spinlock_init(&pool->csl);
6866 : 0 : TAILQ_INIT(&pool->counters[0]);
6867 : 0 : TAILQ_INIT(&pool->counters[1]);
6868 : 0 : pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
6869 : 0 : rte_spinlock_lock(&cmng->pool_update_sl);
6870 : 0 : pool->index = cmng->n_valid;
6871 : 0 : cmng->pools[pool->index] = pool;
6872 : 0 : cmng->n_valid++;
6873 [ # # ]: 0 : if (unlikely(fallback)) {
6874 : 0 : int base = RTE_ALIGN_FLOOR(dcs->id, MLX5_COUNTERS_PER_POOL);
6875 : :
6876 [ # # ]: 0 : if (base < cmng->min_id)
6877 : 0 : cmng->min_id = base;
6878 [ # # ]: 0 : if (base > cmng->max_id)
6879 : 0 : cmng->max_id = base + MLX5_COUNTERS_PER_POOL - 1;
6880 : 0 : cmng->last_pool_idx = pool->index;
6881 : : }
6882 : : rte_spinlock_unlock(&cmng->pool_update_sl);
6883 : 0 : return pool;
6884 : : }
6885 : :
6886 : : /**
6887 : : * Prepare a new counter and/or a new counter pool.
6888 : : *
6889 : : * @param[in] dev
6890 : : * Pointer to the Ethernet device structure.
6891 : : * @param[out] cnt_free
6892 : : * Where to put the pointer of a new counter.
6893 : : * @param[in] age
6894 : : * Whether the pool is for counter that was allocated for aging.
6895 : : *
6896 : : * @return
6897 : : * The counter pool pointer and @p cnt_free is set on success,
6898 : : * NULL otherwise and rte_errno is set.
6899 : : */
6900 : : static struct mlx5_flow_counter_pool *
6901 : 0 : flow_dv_counter_pool_prepare(struct rte_eth_dev *dev,
6902 : : struct mlx5_flow_counter **cnt_free,
6903 : : uint32_t age)
6904 : : {
6905 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6906 : 0 : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
6907 : : struct mlx5_flow_counter_pool *pool;
6908 : : struct mlx5_counters tmp_tq;
6909 : : struct mlx5_devx_obj *dcs = NULL;
6910 : : struct mlx5_flow_counter *cnt;
6911 : 0 : enum mlx5_counter_type cnt_type =
6912 : 0 : age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
6913 : 0 : bool fallback = priv->sh->sws_cmng.counter_fallback;
6914 : : uint32_t i;
6915 : :
6916 [ # # ]: 0 : if (fallback) {
6917 : : /* bulk_bitmap must be 0 for single counter allocation. */
6918 : 0 : dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0);
6919 [ # # ]: 0 : if (!dcs)
6920 : : return NULL;
6921 : 0 : pool = flow_dv_find_pool_by_id(cmng, dcs->id);
6922 [ # # ]: 0 : if (!pool) {
6923 : 0 : pool = flow_dv_pool_create(dev, dcs, age);
6924 [ # # ]: 0 : if (!pool) {
6925 : 0 : mlx5_devx_cmd_destroy(dcs);
6926 : 0 : return NULL;
6927 : : }
6928 : : }
6929 : 0 : i = dcs->id % MLX5_COUNTERS_PER_POOL;
6930 [ # # ]: 0 : cnt = MLX5_POOL_GET_CNT(pool, i);
6931 : 0 : cnt->pool = pool;
6932 : 0 : cnt->dcs_when_free = dcs;
6933 : 0 : *cnt_free = cnt;
6934 : 0 : return pool;
6935 : : }
6936 : 0 : dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0x4);
6937 [ # # ]: 0 : if (!dcs) {
6938 : 0 : rte_errno = ENODATA;
6939 : 0 : return NULL;
6940 : : }
6941 : 0 : pool = flow_dv_pool_create(dev, dcs, age);
6942 [ # # ]: 0 : if (!pool) {
6943 : 0 : mlx5_devx_cmd_destroy(dcs);
6944 : 0 : return NULL;
6945 : : }
6946 : 0 : TAILQ_INIT(&tmp_tq);
6947 [ # # ]: 0 : for (i = 1; i < MLX5_COUNTERS_PER_POOL; ++i) {
6948 [ # # ]: 0 : cnt = MLX5_POOL_GET_CNT(pool, i);
6949 : 0 : cnt->pool = pool;
6950 [ # # ]: 0 : TAILQ_INSERT_HEAD(&tmp_tq, cnt, next);
6951 : : }
6952 : 0 : rte_spinlock_lock(&cmng->csl[cnt_type]);
6953 [ # # ]: 0 : TAILQ_CONCAT(&cmng->counters[cnt_type], &tmp_tq, next);
6954 : : rte_spinlock_unlock(&cmng->csl[cnt_type]);
6955 : 0 : *cnt_free = MLX5_POOL_GET_CNT(pool, 0);
6956 : 0 : (*cnt_free)->pool = pool;
6957 : 0 : return pool;
6958 : : }
6959 : :
6960 : : /**
6961 : : * Allocate a flow counter.
6962 : : *
6963 : : * @param[in] dev
6964 : : * Pointer to the Ethernet device structure.
6965 : : * @param[in] age
6966 : : * Whether the counter was allocated for aging.
6967 : : *
6968 : : * @return
6969 : : * Index to flow counter on success, 0 otherwise and rte_errno is set.
6970 : : */
6971 : : static uint32_t
6972 : 0 : flow_dv_counter_alloc(struct rte_eth_dev *dev, uint32_t age)
6973 : : {
6974 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6975 : : struct mlx5_flow_counter_pool *pool = NULL;
6976 : 0 : struct mlx5_flow_counter *cnt_free = NULL;
6977 : 0 : bool fallback = priv->sh->sws_cmng.counter_fallback;
6978 : : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
6979 : 0 : enum mlx5_counter_type cnt_type =
6980 : 0 : age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
6981 : : uint32_t cnt_idx;
6982 : :
6983 [ # # ]: 0 : if (!priv->sh->cdev->config.devx) {
6984 : 0 : rte_errno = ENOTSUP;
6985 : 0 : return 0;
6986 : : }
6987 : : /* Get free counters from container. */
6988 : 0 : rte_spinlock_lock(&cmng->csl[cnt_type]);
6989 : 0 : cnt_free = TAILQ_FIRST(&cmng->counters[cnt_type]);
6990 [ # # ]: 0 : if (cnt_free)
6991 [ # # ]: 0 : TAILQ_REMOVE(&cmng->counters[cnt_type], cnt_free, next);
6992 : : rte_spinlock_unlock(&cmng->csl[cnt_type]);
6993 [ # # # # ]: 0 : if (!cnt_free && !flow_dv_counter_pool_prepare(dev, &cnt_free, age))
6994 : 0 : goto err;
6995 : 0 : pool = cnt_free->pool;
6996 [ # # ]: 0 : if (fallback)
6997 : 0 : cnt_free->dcs_when_active = cnt_free->dcs_when_free;
6998 : : /* Create a DV counter action only in the first time usage. */
6999 [ # # ]: 0 : if (!cnt_free->action) {
7000 : : uint16_t offset;
7001 : : struct mlx5_devx_obj *dcs;
7002 : : int ret;
7003 : :
7004 [ # # ]: 0 : if (!fallback) {
7005 [ # # ]: 0 : offset = MLX5_CNT_ARRAY_IDX(pool, cnt_free);
7006 : 0 : dcs = pool->min_dcs;
7007 : : } else {
7008 : : offset = 0;
7009 : 0 : dcs = cnt_free->dcs_when_free;
7010 : : }
7011 : 0 : ret = mlx5_flow_os_create_flow_action_count(dcs->obj, offset,
7012 : : &cnt_free->action);
7013 : : if (ret) {
7014 : 0 : rte_errno = errno;
7015 : 0 : goto err;
7016 : : }
7017 : : }
7018 [ # # ]: 0 : cnt_idx = MLX5_MAKE_CNT_IDX(pool->index,
7019 : : MLX5_CNT_ARRAY_IDX(pool, cnt_free));
7020 : : /* Update the counter reset values. */
7021 [ # # ]: 0 : if (_flow_dv_query_count(dev, cnt_idx, &cnt_free->hits,
7022 : : &cnt_free->bytes))
7023 : 0 : goto err;
7024 [ # # # # ]: 0 : if (!fallback && !priv->sh->sws_cmng.query_thread_on)
7025 : : /* Start the asynchronous batch query by the host thread. */
7026 : 0 : mlx5_set_query_alarm(priv->sh);
7027 : : /*
7028 : : * When the count action isn't shared (by ID), shared_info field is
7029 : : * used for indirect action API's refcnt.
7030 : : * When the counter action is not shared neither by ID nor by indirect
7031 : : * action API, shared info must be 1.
7032 : : */
7033 : 0 : cnt_free->shared_info.refcnt = 1;
7034 : 0 : return cnt_idx;
7035 : 0 : err:
7036 [ # # ]: 0 : if (cnt_free) {
7037 : 0 : cnt_free->pool = pool;
7038 [ # # ]: 0 : if (fallback)
7039 : 0 : cnt_free->dcs_when_free = cnt_free->dcs_when_active;
7040 : : rte_spinlock_lock(&cmng->csl[cnt_type]);
7041 : 0 : TAILQ_INSERT_TAIL(&cmng->counters[cnt_type], cnt_free, next);
7042 : : rte_spinlock_unlock(&cmng->csl[cnt_type]);
7043 : : }
7044 : : return 0;
7045 : : }
7046 : :
7047 : : /**
7048 : : * Get age param from counter index.
7049 : : *
7050 : : * @param[in] dev
7051 : : * Pointer to the Ethernet device structure.
7052 : : * @param[in] counter
7053 : : * Index to the counter handler.
7054 : : *
7055 : : * @return
7056 : : * The aging parameter specified for the counter index.
7057 : : */
7058 : : static struct mlx5_age_param*
7059 : : flow_dv_counter_idx_get_age(struct rte_eth_dev *dev,
7060 : : uint32_t counter)
7061 : : {
7062 : : struct mlx5_flow_counter *cnt;
7063 : : struct mlx5_flow_counter_pool *pool = NULL;
7064 : :
7065 : : flow_dv_counter_get_by_idx(dev, counter, &pool);
7066 : : counter = (counter - 1) % MLX5_COUNTERS_PER_POOL;
7067 : : cnt = MLX5_POOL_GET_CNT(pool, counter);
7068 : 0 : return MLX5_CNT_TO_AGE(cnt);
7069 : : }
7070 : :
7071 : : /**
7072 : : * Remove a flow counter from aged counter list.
7073 : : *
7074 : : * @param[in] dev
7075 : : * Pointer to the Ethernet device structure.
7076 : : * @param[in] counter
7077 : : * Index to the counter handler.
7078 : : * @param[in] cnt
7079 : : * Pointer to the counter handler.
7080 : : */
7081 : : static void
7082 : 0 : flow_dv_counter_remove_from_age(struct rte_eth_dev *dev,
7083 : : uint32_t counter, struct mlx5_flow_counter *cnt)
7084 : : {
7085 : : struct mlx5_age_info *age_info;
7086 : : struct mlx5_age_param *age_param;
7087 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7088 : : uint16_t expected = AGE_CANDIDATE;
7089 : :
7090 [ # # ]: 0 : age_info = GET_PORT_AGE_INFO(priv);
7091 : : age_param = flow_dv_counter_idx_get_age(dev, counter);
7092 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(&age_param->state, &expected,
7093 : : AGE_FREE, rte_memory_order_relaxed,
7094 : : rte_memory_order_relaxed)) {
7095 : : /**
7096 : : * We need the lock even it is age timeout,
7097 : : * since counter may still in process.
7098 : : */
7099 : 0 : rte_spinlock_lock(&age_info->aged_sl);
7100 [ # # ]: 0 : TAILQ_REMOVE(&age_info->aged_counters, cnt, next);
7101 : : rte_spinlock_unlock(&age_info->aged_sl);
7102 : 0 : rte_atomic_store_explicit(&age_param->state, AGE_FREE, rte_memory_order_relaxed);
7103 : : }
7104 : 0 : }
7105 : :
7106 : : /**
7107 : : * Release a flow counter.
7108 : : *
7109 : : * @param[in] dev
7110 : : * Pointer to the Ethernet device structure.
7111 : : * @param[in] counter
7112 : : * Index to the counter handler.
7113 : : */
7114 : : static void
7115 : 0 : flow_dv_counter_free(struct rte_eth_dev *dev, uint32_t counter)
7116 : : {
7117 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7118 : : struct mlx5_flow_counter_pool *pool = NULL;
7119 : : struct mlx5_flow_counter *cnt;
7120 : : enum mlx5_counter_type cnt_type;
7121 : :
7122 [ # # ]: 0 : if (!counter)
7123 : : return;
7124 : : cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
7125 : : MLX5_ASSERT(pool);
7126 [ # # ]: 0 : if (pool->is_aged) {
7127 : 0 : flow_dv_counter_remove_from_age(dev, counter, cnt);
7128 : : } else {
7129 : : /*
7130 : : * If the counter action is shared by indirect action API,
7131 : : * the atomic function reduces its references counter.
7132 : : * If after the reduction the action is still referenced, the
7133 : : * function returns here and does not release it.
7134 : : * When the counter action is not shared by
7135 : : * indirect action API, shared info is 1 before the reduction,
7136 : : * so this condition is failed and function doesn't return here.
7137 : : */
7138 [ # # ]: 0 : if (rte_atomic_fetch_sub_explicit(&cnt->shared_info.refcnt, 1,
7139 : : rte_memory_order_relaxed) - 1)
7140 : : return;
7141 : : }
7142 : 0 : cnt->pool = pool;
7143 : : /*
7144 : : * Put the counter back to list to be updated in none fallback mode.
7145 : : * Currently, we are using two list alternately, while one is in query,
7146 : : * add the freed counter to the other list based on the pool query_gen
7147 : : * value. After query finishes, add counter the list to the global
7148 : : * container counter list. The list changes while query starts. In
7149 : : * this case, lock will not be needed as query callback and release
7150 : : * function both operate with the different list.
7151 : : */
7152 [ # # ]: 0 : if (!priv->sh->sws_cmng.counter_fallback) {
7153 : 0 : rte_spinlock_lock(&pool->csl);
7154 : 0 : TAILQ_INSERT_TAIL(&pool->counters[pool->query_gen], cnt, next);
7155 : : rte_spinlock_unlock(&pool->csl);
7156 : : } else {
7157 : 0 : cnt->dcs_when_free = cnt->dcs_when_active;
7158 : 0 : cnt_type = pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
7159 : : MLX5_COUNTER_TYPE_ORIGIN;
7160 : 0 : rte_spinlock_lock(&priv->sh->sws_cmng.csl[cnt_type]);
7161 : 0 : TAILQ_INSERT_TAIL(&priv->sh->sws_cmng.counters[cnt_type],
7162 : : cnt, next);
7163 : 0 : rte_spinlock_unlock(&priv->sh->sws_cmng.csl[cnt_type]);
7164 : : }
7165 : : }
7166 : :
7167 : : /**
7168 : : * Resize a meter id container.
7169 : : *
7170 : : * @param[in] dev
7171 : : * Pointer to the Ethernet device structure.
7172 : : *
7173 : : * @return
7174 : : * 0 on success, otherwise negative errno value and rte_errno is set.
7175 : : */
7176 : : static int
7177 : 0 : flow_dv_mtr_container_resize(struct rte_eth_dev *dev)
7178 : : {
7179 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7180 : : struct mlx5_aso_mtr_pools_mng *pools_mng =
7181 : 0 : &priv->sh->mtrmng->pools_mng;
7182 : 0 : void *old_pools = pools_mng->pools;
7183 : 0 : uint32_t resize = pools_mng->n + MLX5_MTRS_CONTAINER_RESIZE;
7184 : 0 : uint32_t mem_size = sizeof(struct mlx5_aso_mtr_pool *) * resize;
7185 : 0 : void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
7186 : :
7187 [ # # ]: 0 : if (!pools) {
7188 : 0 : rte_errno = ENOMEM;
7189 : 0 : return -ENOMEM;
7190 : : }
7191 [ # # ]: 0 : if (!pools_mng->n)
7192 [ # # ]: 0 : if (mlx5_aso_queue_init(priv->sh, ASO_OPC_MOD_POLICER, 1)) {
7193 : 0 : mlx5_free(pools);
7194 : 0 : return -ENOMEM;
7195 : : }
7196 [ # # ]: 0 : if (old_pools)
7197 : 0 : memcpy(pools, old_pools, pools_mng->n *
7198 : : sizeof(struct mlx5_aso_mtr_pool *));
7199 : 0 : pools_mng->n = resize;
7200 : 0 : pools_mng->pools = pools;
7201 [ # # ]: 0 : if (old_pools)
7202 : 0 : mlx5_free(old_pools);
7203 : : return 0;
7204 : : }
7205 : :
7206 : : /**
7207 : : * Prepare a new meter and/or a new meter pool.
7208 : : *
7209 : : * @param[in] dev
7210 : : * Pointer to the Ethernet device structure.
7211 : : * @param[out] mtr_free
7212 : : * Where to put the pointer of a new meter.g.
7213 : : *
7214 : : * @return
7215 : : * The meter pool pointer and @mtr_free is set on success,
7216 : : * NULL otherwise and rte_errno is set.
7217 : : */
7218 : : static struct mlx5_aso_mtr_pool *
7219 : 0 : flow_dv_mtr_pool_create(struct rte_eth_dev *dev, struct mlx5_aso_mtr **mtr_free)
7220 : : {
7221 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7222 : 0 : struct mlx5_aso_mtr_pools_mng *pools_mng = &priv->sh->mtrmng->pools_mng;
7223 : : struct mlx5_aso_mtr_pool *pool = NULL;
7224 : : struct mlx5_devx_obj *dcs = NULL;
7225 : : uint32_t i;
7226 : : uint32_t log_obj_size;
7227 : :
7228 : : log_obj_size = rte_log2_u32(MLX5_ASO_MTRS_PER_POOL >> 1);
7229 : 0 : dcs = mlx5_devx_cmd_create_flow_meter_aso_obj(priv->sh->cdev->ctx,
7230 : 0 : priv->sh->cdev->pdn,
7231 : : log_obj_size);
7232 [ # # ]: 0 : if (!dcs) {
7233 : 0 : rte_errno = ENODATA;
7234 : 0 : return NULL;
7235 : : }
7236 : 0 : pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
7237 [ # # ]: 0 : if (!pool) {
7238 : 0 : rte_errno = ENOMEM;
7239 : 0 : claim_zero(mlx5_devx_cmd_destroy(dcs));
7240 : 0 : return NULL;
7241 : : }
7242 : 0 : pool->devx_obj = dcs;
7243 : 0 : rte_rwlock_write_lock(&pools_mng->resize_mtrwl);
7244 : 0 : pool->index = pools_mng->n_valid;
7245 [ # # # # ]: 0 : if (pool->index == pools_mng->n && flow_dv_mtr_container_resize(dev)) {
7246 : 0 : mlx5_free(pool);
7247 : 0 : claim_zero(mlx5_devx_cmd_destroy(dcs));
7248 : : rte_rwlock_write_unlock(&pools_mng->resize_mtrwl);
7249 : 0 : return NULL;
7250 : : }
7251 : 0 : pools_mng->pools[pool->index] = pool;
7252 : 0 : pools_mng->n_valid++;
7253 : : rte_rwlock_write_unlock(&pools_mng->resize_mtrwl);
7254 [ # # ]: 0 : for (i = 1; i < MLX5_ASO_MTRS_PER_POOL; ++i) {
7255 : 0 : pool->mtrs[i].offset = i;
7256 [ # # ]: 0 : LIST_INSERT_HEAD(&pools_mng->meters, &pool->mtrs[i], next);
7257 : : }
7258 : 0 : pool->mtrs[0].offset = 0;
7259 : 0 : *mtr_free = &pool->mtrs[0];
7260 : 0 : return pool;
7261 : : }
7262 : :
7263 : : /**
7264 : : * Release a flow meter into pool.
7265 : : *
7266 : : * @param[in] dev
7267 : : * Pointer to the Ethernet device structure.
7268 : : * @param[in] mtr_idx
7269 : : * Index to aso flow meter.
7270 : : */
7271 : : static void
7272 : 0 : flow_dv_aso_mtr_release_to_pool(struct rte_eth_dev *dev, uint32_t mtr_idx)
7273 : : {
7274 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7275 : : struct mlx5_aso_mtr_pools_mng *pools_mng =
7276 : 0 : &priv->sh->mtrmng->pools_mng;
7277 : 0 : struct mlx5_aso_mtr *aso_mtr = mlx5_aso_meter_by_idx(priv, mtr_idx);
7278 : :
7279 : : MLX5_ASSERT(aso_mtr);
7280 : 0 : rte_spinlock_lock(&pools_mng->mtrsl);
7281 [ # # ]: 0 : memset(&aso_mtr->fm, 0, sizeof(struct mlx5_flow_meter_info));
7282 : 0 : aso_mtr->state = ASO_METER_FREE;
7283 [ # # ]: 0 : LIST_INSERT_HEAD(&pools_mng->meters, aso_mtr, next);
7284 : : rte_spinlock_unlock(&pools_mng->mtrsl);
7285 : 0 : }
7286 : :
7287 : : /**
7288 : : * Allocate a aso flow meter.
7289 : : *
7290 : : * @param[in] dev
7291 : : * Pointer to the Ethernet device structure.
7292 : : *
7293 : : * @return
7294 : : * Index to aso flow meter on success, 0 otherwise and rte_errno is set.
7295 : : */
7296 : : static uint32_t
7297 : 0 : flow_dv_mtr_alloc(struct rte_eth_dev *dev)
7298 : : {
7299 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7300 : 0 : struct mlx5_aso_mtr *mtr_free = NULL;
7301 : : struct mlx5_aso_mtr_pools_mng *pools_mng =
7302 : 0 : &priv->sh->mtrmng->pools_mng;
7303 : : struct mlx5_aso_mtr_pool *pool;
7304 : : uint32_t mtr_idx = 0;
7305 : :
7306 [ # # ]: 0 : if (!priv->sh->cdev->config.devx) {
7307 : 0 : rte_errno = ENOTSUP;
7308 : 0 : return 0;
7309 : : }
7310 : : /* Allocate the flow meter memory. */
7311 : : /* Get free meters from management. */
7312 : 0 : rte_spinlock_lock(&pools_mng->mtrsl);
7313 : 0 : mtr_free = LIST_FIRST(&pools_mng->meters);
7314 [ # # ]: 0 : if (mtr_free)
7315 [ # # ]: 0 : LIST_REMOVE(mtr_free, next);
7316 [ # # # # ]: 0 : if (!mtr_free && !flow_dv_mtr_pool_create(dev, &mtr_free)) {
7317 : : rte_spinlock_unlock(&pools_mng->mtrsl);
7318 : 0 : return 0;
7319 : : }
7320 : 0 : mtr_free->state = ASO_METER_WAIT;
7321 : : rte_spinlock_unlock(&pools_mng->mtrsl);
7322 : 0 : pool = container_of(mtr_free,
7323 : : struct mlx5_aso_mtr_pool,
7324 : : mtrs[mtr_free->offset]);
7325 : 0 : mtr_idx = MLX5_MAKE_MTR_IDX(pool->index, mtr_free->offset);
7326 [ # # ]: 0 : if (!mtr_free->fm.meter_action_g) {
7327 : : #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
7328 : : struct rte_flow_error error;
7329 : : uint8_t reg_id;
7330 : :
7331 : 0 : reg_id = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &error);
7332 : 0 : mtr_free->fm.meter_action_g =
7333 : 0 : mlx5_glue->dv_create_flow_action_aso
7334 : 0 : (priv->sh->rx_domain,
7335 : 0 : pool->devx_obj->obj,
7336 : : mtr_free->offset,
7337 : : (1 << MLX5_FLOW_COLOR_GREEN),
7338 : 0 : reg_id - REG_C_0);
7339 : : #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
7340 [ # # ]: 0 : if (!mtr_free->fm.meter_action_g) {
7341 : 0 : flow_dv_aso_mtr_release_to_pool(dev, mtr_idx);
7342 : 0 : return 0;
7343 : : }
7344 : : }
7345 : : return mtr_idx;
7346 : : }
7347 : :
7348 : : /**
7349 : : * Verify the @p attributes will be correctly understood by the NIC and store
7350 : : * them in the @p flow if everything is correct.
7351 : : *
7352 : : * @param[in] dev
7353 : : * Pointer to dev struct.
7354 : : * @param[in] attributes
7355 : : * Pointer to flow attributes
7356 : : * @param[in] external
7357 : : * This flow rule is created by request external to PMD.
7358 : : * @param[out] error
7359 : : * Pointer to error structure.
7360 : : *
7361 : : * @return
7362 : : * - 0 on success and non root table.
7363 : : * - 1 on success and root table.
7364 : : * - a negative errno value otherwise and rte_errno is set.
7365 : : */
7366 : : static int
7367 : 0 : flow_dv_validate_attributes(struct rte_eth_dev *dev,
7368 : : const struct mlx5_flow_tunnel *tunnel,
7369 : : const struct rte_flow_attr *attributes,
7370 : : const struct flow_grp_info *grp_info,
7371 : : struct rte_flow_error *error)
7372 : : {
7373 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7374 : 0 : uint32_t lowest_priority = mlx5_get_lowest_priority(dev, attributes);
7375 : : int ret = 0;
7376 : :
7377 : : #ifndef HAVE_MLX5DV_DR
7378 : : RTE_SET_USED(tunnel);
7379 : : RTE_SET_USED(grp_info);
7380 : : if (attributes->group)
7381 : : return rte_flow_error_set(error, ENOTSUP,
7382 : : RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
7383 : : NULL,
7384 : : "groups are not supported");
7385 : : #else
7386 : 0 : uint32_t table = 0;
7387 : :
7388 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel, attributes->group, &table,
7389 : : grp_info, error);
7390 [ # # ]: 0 : if (ret)
7391 : : return ret;
7392 [ # # ]: 0 : if (!table)
7393 : : ret = MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL;
7394 : : #endif
7395 [ # # # # ]: 0 : if (attributes->priority != MLX5_FLOW_LOWEST_PRIO_INDICATOR &&
7396 : : attributes->priority > lowest_priority)
7397 : 0 : return rte_flow_error_set(error, ENOTSUP,
7398 : : RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
7399 : : NULL,
7400 : : "priority out of range");
7401 [ # # # # ]: 0 : if (attributes->transfer && !priv->sh->config.dv_esw_en)
7402 : 0 : return rte_flow_error_set(error, ENOTSUP,
7403 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7404 : : "E-Switch dr is not supported");
7405 [ # # ]: 0 : if (attributes->ingress + attributes->egress + attributes->transfer != 1) {
7406 : 0 : return rte_flow_error_set(error, EINVAL,
7407 : : RTE_FLOW_ERROR_TYPE_ATTR, NULL,
7408 : : "must specify exactly one of "
7409 : : "ingress, egress or transfer");
7410 : : }
7411 : : return ret;
7412 : : }
7413 : :
7414 : : static int
7415 : 0 : validate_integrity_bits(const void *arg,
7416 : : int64_t pattern_flags, uint64_t l3_flags,
7417 : : uint64_t l4_flags, uint64_t ip4_flag,
7418 : : struct rte_flow_error *error)
7419 : : {
7420 : : const struct rte_flow_item_integrity *mask = arg;
7421 : :
7422 [ # # # # ]: 0 : if (mask->l3_ok && !(pattern_flags & l3_flags))
7423 : 0 : return rte_flow_error_set(error, EINVAL,
7424 : : RTE_FLOW_ERROR_TYPE_ITEM,
7425 : : NULL, "missing L3 protocol");
7426 : :
7427 [ # # # # ]: 0 : if (mask->ipv4_csum_ok && !(pattern_flags & ip4_flag))
7428 : 0 : return rte_flow_error_set(error, EINVAL,
7429 : : RTE_FLOW_ERROR_TYPE_ITEM,
7430 : : NULL, "missing IPv4 protocol");
7431 : :
7432 [ # # # # ]: 0 : if ((mask->l4_ok || mask->l4_csum_ok) && !(pattern_flags & l4_flags))
7433 : 0 : return rte_flow_error_set(error, EINVAL,
7434 : : RTE_FLOW_ERROR_TYPE_ITEM,
7435 : : NULL, "missing L4 protocol");
7436 : :
7437 : : return 0;
7438 : : }
7439 : :
7440 : : static int
7441 : 0 : flow_dv_validate_item_integrity_post(const struct
7442 : : rte_flow_item *integrity_items[2],
7443 : : int64_t pattern_flags,
7444 : : struct rte_flow_error *error)
7445 : : {
7446 : : const struct rte_flow_item_integrity *mask;
7447 : : int ret;
7448 : :
7449 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_OUTER_INTEGRITY) {
7450 : 0 : mask = (typeof(mask))integrity_items[0]->mask;
7451 : 0 : ret = validate_integrity_bits(mask, pattern_flags,
7452 : : MLX5_FLOW_LAYER_OUTER_L3,
7453 : : MLX5_FLOW_LAYER_OUTER_L4,
7454 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4,
7455 : : error);
7456 [ # # ]: 0 : if (ret)
7457 : : return ret;
7458 : : }
7459 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_INNER_INTEGRITY) {
7460 : 0 : mask = (typeof(mask))integrity_items[1]->mask;
7461 : 0 : ret = validate_integrity_bits(mask, pattern_flags,
7462 : : MLX5_FLOW_LAYER_INNER_L3,
7463 : : MLX5_FLOW_LAYER_INNER_L4,
7464 : : MLX5_FLOW_LAYER_INNER_L3_IPV4,
7465 : : error);
7466 [ # # ]: 0 : if (ret)
7467 : 0 : return ret;
7468 : : }
7469 : : return 0;
7470 : : }
7471 : :
7472 : : static int
7473 : 0 : flow_dv_validate_item_integrity(struct rte_eth_dev *dev,
7474 : : const struct rte_flow_item *integrity_item,
7475 : : uint64_t pattern_flags, uint64_t *last_item,
7476 : : const struct rte_flow_item *integrity_items[2],
7477 : : struct rte_flow_error *error)
7478 : : {
7479 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7480 : 0 : const struct rte_flow_item_integrity *mask = (typeof(mask))
7481 : : integrity_item->mask;
7482 : 0 : const struct rte_flow_item_integrity *spec = (typeof(spec))
7483 : : integrity_item->spec;
7484 : :
7485 [ # # ]: 0 : if (!priv->sh->cdev->config.hca_attr.pkt_integrity_match)
7486 : 0 : return rte_flow_error_set(error, ENOTSUP,
7487 : : RTE_FLOW_ERROR_TYPE_ITEM,
7488 : : integrity_item,
7489 : : "packet integrity integrity_item not supported");
7490 [ # # ]: 0 : if (!spec)
7491 : 0 : return rte_flow_error_set(error, ENOTSUP,
7492 : : RTE_FLOW_ERROR_TYPE_ITEM,
7493 : : integrity_item,
7494 : : "no spec for integrity item");
7495 [ # # ]: 0 : if (!mask)
7496 : : mask = &rte_flow_item_integrity_mask;
7497 [ # # ]: 0 : if (!mlx5_validate_integrity_item(mask))
7498 : 0 : return rte_flow_error_set(error, ENOTSUP,
7499 : : RTE_FLOW_ERROR_TYPE_ITEM,
7500 : : integrity_item,
7501 : : "unsupported integrity filter");
7502 [ # # # # ]: 0 : if ((mask->l3_ok & !spec->l3_ok) || (mask->l4_ok & !spec->l4_ok) ||
7503 [ # # ]: 0 : (mask->ipv4_csum_ok & !spec->ipv4_csum_ok) ||
7504 [ # # ]: 0 : (mask->l4_csum_ok & !spec->l4_csum_ok))
7505 : 0 : return rte_flow_error_set(error, EINVAL,
7506 : : RTE_FLOW_ERROR_TYPE_ITEM,
7507 : : NULL, "negative integrity flow is not supported");
7508 [ # # ]: 0 : if (spec->level > 1) {
7509 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_INNER_INTEGRITY)
7510 : 0 : return rte_flow_error_set
7511 : : (error, ENOTSUP,
7512 : : RTE_FLOW_ERROR_TYPE_ITEM,
7513 : : NULL, "multiple inner integrity items not supported");
7514 : 0 : integrity_items[1] = integrity_item;
7515 : 0 : *last_item |= MLX5_FLOW_ITEM_INNER_INTEGRITY;
7516 : : } else {
7517 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_OUTER_INTEGRITY)
7518 : 0 : return rte_flow_error_set
7519 : : (error, ENOTSUP,
7520 : : RTE_FLOW_ERROR_TYPE_ITEM,
7521 : : NULL, "multiple outer integrity items not supported");
7522 : 0 : integrity_items[0] = integrity_item;
7523 : 0 : *last_item |= MLX5_FLOW_ITEM_OUTER_INTEGRITY;
7524 : : }
7525 : : return 0;
7526 : : }
7527 : :
7528 : : static int
7529 : 0 : flow_dv_validate_item_flex(struct rte_eth_dev *dev,
7530 : : const struct rte_flow_item *item,
7531 : : uint64_t item_flags,
7532 : : uint64_t *last_item,
7533 : : bool is_inner,
7534 : : struct rte_flow_error *error)
7535 : : {
7536 : 0 : const struct rte_flow_item_flex *flow_spec = item->spec;
7537 : 0 : const struct rte_flow_item_flex *flow_mask = item->mask;
7538 : : struct mlx5_flex_item *flex;
7539 : :
7540 [ # # ]: 0 : if (!flow_spec)
7541 : 0 : return rte_flow_error_set(error, EINVAL,
7542 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
7543 : : "flex flow item spec cannot be NULL");
7544 [ # # ]: 0 : if (!flow_mask)
7545 : 0 : return rte_flow_error_set(error, EINVAL,
7546 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
7547 : : "flex flow item mask cannot be NULL");
7548 [ # # ]: 0 : if (item->last)
7549 : 0 : return rte_flow_error_set(error, ENOTSUP,
7550 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
7551 : : "flex flow item last not supported");
7552 [ # # ]: 0 : if (mlx5_flex_acquire_index(dev, flow_spec->handle, false) < 0)
7553 : 0 : return rte_flow_error_set(error, EINVAL,
7554 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
7555 : : "invalid flex flow item handle");
7556 : 0 : flex = (struct mlx5_flex_item *)flow_spec->handle;
7557 [ # # # # : 0 : switch (flex->tunnel_mode) {
# # ]
7558 : 0 : case FLEX_TUNNEL_MODE_SINGLE:
7559 [ # # ]: 0 : if (item_flags &
7560 : : (MLX5_FLOW_ITEM_OUTER_FLEX | MLX5_FLOW_ITEM_INNER_FLEX))
7561 : 0 : rte_flow_error_set(error, EINVAL,
7562 : : RTE_FLOW_ERROR_TYPE_ITEM,
7563 : : NULL, "multiple flex items not supported");
7564 : : break;
7565 : 0 : case FLEX_TUNNEL_MODE_OUTER:
7566 [ # # ]: 0 : if (is_inner)
7567 : 0 : rte_flow_error_set(error, EINVAL,
7568 : : RTE_FLOW_ERROR_TYPE_ITEM,
7569 : : NULL, "inner flex item was not configured");
7570 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_OUTER_FLEX)
7571 : 0 : rte_flow_error_set(error, ENOTSUP,
7572 : : RTE_FLOW_ERROR_TYPE_ITEM,
7573 : : NULL, "multiple flex items not supported");
7574 : : break;
7575 : 0 : case FLEX_TUNNEL_MODE_INNER:
7576 [ # # ]: 0 : if (!is_inner)
7577 : 0 : rte_flow_error_set(error, EINVAL,
7578 : : RTE_FLOW_ERROR_TYPE_ITEM,
7579 : : NULL, "outer flex item was not configured");
7580 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_INNER_FLEX)
7581 : 0 : rte_flow_error_set(error, EINVAL,
7582 : : RTE_FLOW_ERROR_TYPE_ITEM,
7583 : : NULL, "multiple flex items not supported");
7584 : : break;
7585 : 0 : case FLEX_TUNNEL_MODE_MULTI:
7586 [ # # # # : 0 : if ((is_inner && (item_flags & MLX5_FLOW_ITEM_INNER_FLEX)) ||
# # ]
7587 [ # # ]: 0 : (!is_inner && (item_flags & MLX5_FLOW_ITEM_OUTER_FLEX))) {
7588 : 0 : rte_flow_error_set(error, EINVAL,
7589 : : RTE_FLOW_ERROR_TYPE_ITEM,
7590 : : NULL, "multiple flex items not supported");
7591 : : }
7592 : : break;
7593 : 0 : case FLEX_TUNNEL_MODE_TUNNEL:
7594 [ # # # # ]: 0 : if (is_inner || (item_flags & MLX5_FLOW_ITEM_FLEX_TUNNEL))
7595 : 0 : rte_flow_error_set(error, EINVAL,
7596 : : RTE_FLOW_ERROR_TYPE_ITEM,
7597 : : NULL, "multiple flex tunnel items not supported");
7598 : : break;
7599 : 0 : default:
7600 : 0 : rte_flow_error_set(error, EINVAL,
7601 : : RTE_FLOW_ERROR_TYPE_ITEM,
7602 : : NULL, "invalid flex item configuration");
7603 : : }
7604 : 0 : *last_item = flex->tunnel_mode == FLEX_TUNNEL_MODE_TUNNEL ?
7605 [ # # ]: 0 : MLX5_FLOW_ITEM_FLEX_TUNNEL : is_inner ?
7606 [ # # ]: 0 : MLX5_FLOW_ITEM_INNER_FLEX : MLX5_FLOW_ITEM_OUTER_FLEX;
7607 : 0 : return 0;
7608 : : }
7609 : :
7610 : : static __rte_always_inline uint8_t
7611 : : mlx5_flow_l3_next_protocol(const struct rte_flow_item *l3_item,
7612 : : enum MLX5_SET_MATCHER key_type)
7613 : : {
7614 : : #define MLX5_L3_NEXT_PROTOCOL(i, ms) \
7615 : : ((i)->type == RTE_FLOW_ITEM_TYPE_IPV4 ? \
7616 : : ((const struct rte_flow_item_ipv4 *)(i)->ms)->hdr.next_proto_id : \
7617 : : (i)->type == RTE_FLOW_ITEM_TYPE_IPV6 ? \
7618 : : ((const struct rte_flow_item_ipv6 *)(i)->ms)->hdr.proto : \
7619 : : (i)->type == RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT ? \
7620 : : ((const struct rte_flow_item_ipv6_frag_ext *)(i)->ms)->hdr.next_header :\
7621 : : 0xff)
7622 : :
7623 : : uint8_t next_protocol;
7624 : :
7625 [ # # # # : 0 : if (l3_item->mask != NULL && l3_item->spec != NULL) {
# # # # #
# # # # #
# # # # #
# # # ]
7626 [ # # # # : 0 : next_protocol = MLX5_L3_NEXT_PROTOCOL(l3_item, mask);
# # # # #
# # # ]
7627 [ # # # # : 0 : if (next_protocol)
# # # # #
# # # ]
7628 [ # # # # : 0 : next_protocol &= MLX5_L3_NEXT_PROTOCOL(l3_item, spec);
# # # # #
# # # ]
7629 : : else
7630 : : next_protocol = 0xff;
7631 [ # # # # : 0 : } else if (key_type == MLX5_SET_MATCHER_HS_M && l3_item->mask != NULL) {
# # # # #
# # # ]
7632 [ # # # # : 0 : next_protocol = MLX5_L3_NEXT_PROTOCOL(l3_item, mask);
# # ]
7633 [ # # # # : 0 : } else if (key_type == MLX5_SET_MATCHER_HS_V && l3_item->spec != NULL) {
# # # # #
# # # ]
7634 [ # # # # : 0 : next_protocol = MLX5_L3_NEXT_PROTOCOL(l3_item, spec);
# # ]
7635 : : } else {
7636 : : /* Reset for inner layer. */
7637 : : next_protocol = 0xff;
7638 : : }
7639 : : return next_protocol;
7640 : :
7641 : : #undef MLX5_L3_NEXT_PROTOCOL
7642 : : }
7643 : :
7644 : : /**
7645 : : * Validate IB BTH item.
7646 : : *
7647 : : * @param[in] dev
7648 : : * Pointer to the rte_eth_dev structure.
7649 : : * @param[in] udp_dport
7650 : : * UDP destination port
7651 : : * @param[in] item
7652 : : * Item specification.
7653 : : * @param root
7654 : : * Whether action is on root table.
7655 : : * @param[out] error
7656 : : * Pointer to the error structure.
7657 : : *
7658 : : * @return
7659 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
7660 : : */
7661 : : static int
7662 : 0 : mlx5_flow_validate_item_ib_bth(struct rte_eth_dev *dev,
7663 : : uint16_t udp_dport,
7664 : : const struct rte_flow_item *item,
7665 : : bool root,
7666 : : struct rte_flow_error *error)
7667 : : {
7668 : 0 : const struct rte_flow_item_ib_bth *mask = item->mask;
7669 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7670 : : const struct rte_flow_item_ib_bth *valid_mask;
7671 : : int ret;
7672 : :
7673 : : valid_mask = &rte_flow_item_ib_bth_mask;
7674 [ # # ]: 0 : if (udp_dport && udp_dport != MLX5_UDP_PORT_ROCEv2)
7675 : 0 : return rte_flow_error_set(error, EINVAL,
7676 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
7677 : : "protocol filtering not compatible"
7678 : : " with UDP layer");
7679 [ # # # # ]: 0 : if (mask && (mask->hdr.se || mask->hdr.m || mask->hdr.padcnt ||
7680 [ # # # # ]: 0 : mask->hdr.tver || mask->hdr.pkey || mask->hdr.f || mask->hdr.b ||
7681 [ # # ]: 0 : mask->hdr.rsvd0 || mask->hdr.a || mask->hdr.rsvd1 ||
7682 [ # # # # : 0 : mask->hdr.psn[0] || mask->hdr.psn[1] || mask->hdr.psn[2]))
# # ]
7683 : 0 : return rte_flow_error_set(error, EINVAL,
7684 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
7685 : : "only opcode and dst_qp are supported");
7686 [ # # # # ]: 0 : if (root || priv->sh->steering_format_version ==
7687 : : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5)
7688 : 0 : return rte_flow_error_set(error, EINVAL,
7689 : : RTE_FLOW_ERROR_TYPE_ITEM,
7690 : : item,
7691 : : "IB BTH item is not supported");
7692 [ # # ]: 0 : if (!mask)
7693 : : mask = &rte_flow_item_ib_bth_mask;
7694 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
7695 : : (const uint8_t *)valid_mask,
7696 : : sizeof(struct rte_flow_item_ib_bth),
7697 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
7698 : : if (ret < 0)
7699 : : return ret;
7700 : : return 0;
7701 : : }
7702 : :
7703 : : const struct rte_flow_item_ipv4 nic_ipv4_mask = {
7704 : : .hdr = {
7705 : : .src_addr = RTE_BE32(0xffffffff),
7706 : : .dst_addr = RTE_BE32(0xffffffff),
7707 : : .type_of_service = 0xff,
7708 : : .fragment_offset = RTE_BE16(0xffff),
7709 : : .next_proto_id = 0xff,
7710 : : .time_to_live = 0xff,
7711 : : },
7712 : : };
7713 : :
7714 : : const struct rte_flow_item_ipv6 nic_ipv6_mask = {
7715 : : .hdr = {
7716 : : .src_addr = RTE_IPV6_MASK_FULL,
7717 : : .dst_addr = RTE_IPV6_MASK_FULL,
7718 : : .vtc_flow = RTE_BE32(0xffffffff),
7719 : : .proto = 0xff,
7720 : : .hop_limits = 0xff,
7721 : : },
7722 : : .has_frag_ext = 1,
7723 : : };
7724 : :
7725 : : const struct rte_flow_item_tcp nic_tcp_mask = {
7726 : : .hdr = {
7727 : : .tcp_flags = 0xFF,
7728 : : .src_port = RTE_BE16(UINT16_MAX),
7729 : : .dst_port = RTE_BE16(UINT16_MAX),
7730 : : }
7731 : : };
7732 : :
7733 : : /**
7734 : : * Internal validation function. For validating both actions and items.
7735 : : *
7736 : : * @param[in] dev
7737 : : * Pointer to the rte_eth_dev structure.
7738 : : * @param[in] attr
7739 : : * Pointer to the flow attributes.
7740 : : * @param[in] items
7741 : : * Pointer to the list of items.
7742 : : * @param[in] actions
7743 : : * Pointer to the list of actions.
7744 : : * @param[in] external
7745 : : * This flow rule is created by request external to PMD.
7746 : : * @param[in] hairpin
7747 : : * Number of hairpin TX actions, 0 means classic flow.
7748 : : * @param[out] error
7749 : : * Pointer to the error structure.
7750 : : *
7751 : : * @return
7752 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
7753 : : */
7754 : : int
7755 : 0 : flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
7756 : : const struct rte_flow_item items[],
7757 : : const struct rte_flow_action actions[],
7758 : : bool external, int hairpin, struct rte_flow_error *error)
7759 : : {
7760 : : int ret;
7761 : 0 : uint64_t aso_mask, action_flags = 0;
7762 : 0 : uint64_t item_flags = 0;
7763 : 0 : uint64_t last_item = 0;
7764 : : uint8_t next_protocol = 0xff;
7765 : : uint16_t ether_type = 0;
7766 : 0 : int actions_n = 0;
7767 : : uint8_t item_ipv6_proto = 0;
7768 : 0 : int fdb_mirror = 0;
7769 : : int modify_after_mirror = 0;
7770 : : const struct rte_flow_item *geneve_item = NULL;
7771 : : const struct rte_flow_item *gre_item = NULL;
7772 : : const struct rte_flow_item *gtp_item = NULL;
7773 : : const struct rte_flow_action_raw_decap *decap;
7774 : : const struct rte_flow_action_raw_encap *encap;
7775 : : const struct rte_flow_action_rss *rss = NULL;
7776 : 0 : const struct rte_flow_action_rss *sample_rss = NULL;
7777 : 0 : const struct rte_flow_action_count *sample_count = NULL;
7778 : 0 : const struct rte_flow_item_ecpri nic_ecpri_mask = {
7779 : : .hdr = {
7780 : : .common = {
7781 : : .u32 =
7782 : : RTE_BE32(((const struct rte_ecpri_common_hdr) {
7783 : : .type = 0xFF,
7784 : : }).u32),
7785 : : },
7786 : : .dummy[0] = 0xffffffff,
7787 : : },
7788 : : };
7789 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7790 : 0 : struct mlx5_sh_config *dev_conf = &priv->sh->config;
7791 : : uint16_t queue_index = 0xFFFF;
7792 : : const struct rte_flow_item_vlan *vlan_m = NULL;
7793 : : uint32_t rw_act_num = 0;
7794 : : uint64_t is_root;
7795 : : const struct mlx5_flow_tunnel *tunnel;
7796 : : enum mlx5_tof_rule_type tof_rule_type;
7797 : 0 : struct flow_grp_info grp_info = {
7798 : : .external = !!external,
7799 : 0 : .transfer = !!attr->transfer,
7800 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
7801 : : .std_tbl_fix = true,
7802 : : };
7803 : : const struct rte_eth_hairpin_conf *conf;
7804 : 0 : const struct rte_flow_item *integrity_items[2] = {NULL, NULL};
7805 : : const struct rte_flow_item *port_id_item = NULL;
7806 : 0 : bool def_policy = false;
7807 : : bool shared_count = false;
7808 : : uint16_t udp_dport = 0;
7809 : 0 : uint32_t tag_id = 0, tag_bitmap = 0;
7810 : : const struct rte_flow_action_age *non_shared_age = NULL;
7811 : : const struct rte_flow_action_count *count = NULL;
7812 : : const struct rte_flow_action_port_id *port = NULL;
7813 : : const struct mlx5_rte_flow_item_tag *mlx5_tag;
7814 : 0 : struct mlx5_priv *act_priv = NULL;
7815 : : int aso_after_sample = 0;
7816 : : struct mlx5_priv *port_priv = NULL;
7817 : 0 : uint64_t sub_action_flags = 0;
7818 : 0 : uint16_t sample_port_id = 0;
7819 : : uint16_t port_id = 0;
7820 : :
7821 [ # # ]: 0 : if (items == NULL)
7822 : : return -1;
7823 : : tunnel = is_tunnel_offload_active(dev) ?
7824 [ # # ]: 0 : mlx5_get_tof(items, actions, &tof_rule_type) : NULL;
7825 [ # # ]: 0 : if (tunnel) {
7826 [ # # ]: 0 : if (!dev_conf->dv_flow_en)
7827 : 0 : return rte_flow_error_set
7828 : : (error, ENOTSUP,
7829 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7830 : : NULL, "tunnel offload requires DV flow interface");
7831 [ # # ]: 0 : if (priv->representor)
7832 : 0 : return rte_flow_error_set
7833 : : (error, ENOTSUP,
7834 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7835 : : NULL, "decap not supported for VF representor");
7836 [ # # ]: 0 : if (tof_rule_type == MLX5_TUNNEL_OFFLOAD_SET_RULE)
7837 : 0 : action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
7838 [ # # ]: 0 : else if (tof_rule_type == MLX5_TUNNEL_OFFLOAD_MATCH_RULE)
7839 : 0 : action_flags |= MLX5_FLOW_ACTION_TUNNEL_MATCH |
7840 : : MLX5_FLOW_ACTION_DECAP;
7841 : 0 : grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
7842 : : (dev, attr, tunnel, tof_rule_type);
7843 : : }
7844 : 0 : ret = flow_dv_validate_attributes(dev, tunnel, attr, &grp_info, error);
7845 [ # # ]: 0 : if (ret < 0)
7846 : : return ret;
7847 : 0 : is_root = (uint64_t)ret;
7848 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
7849 : : enum mlx5_l3_tunnel_detection l3_tunnel_detection;
7850 : : uint64_t l3_tunnel_flag;
7851 : 0 : int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
7852 : 0 : int type = items->type;
7853 : :
7854 : : if (!mlx5_flow_os_item_supported(type))
7855 : : return rte_flow_error_set(error, ENOTSUP,
7856 : : RTE_FLOW_ERROR_TYPE_ITEM,
7857 : : NULL, "item not supported");
7858 [ # # # # : 0 : switch (type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # #
# ]
7859 : : case RTE_FLOW_ITEM_TYPE_VOID:
7860 : : break;
7861 : 0 : case RTE_FLOW_ITEM_TYPE_ESP:
7862 : 0 : ret = mlx5_flow_os_validate_item_esp(dev, items,
7863 : : item_flags,
7864 : : next_protocol,
7865 : : error);
7866 [ # # ]: 0 : if (ret < 0)
7867 : 0 : return ret;
7868 : 0 : last_item = MLX5_FLOW_ITEM_ESP;
7869 : 0 : break;
7870 : 0 : case RTE_FLOW_ITEM_TYPE_PORT_ID:
7871 : 0 : ret = flow_dv_validate_item_port_id
7872 : : (dev, items, attr, item_flags, &act_priv, error);
7873 [ # # ]: 0 : if (ret < 0)
7874 : 0 : return ret;
7875 : 0 : last_item = MLX5_FLOW_ITEM_PORT_ID;
7876 : : port_id_item = items;
7877 : 0 : break;
7878 : 0 : case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
7879 : : case RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR:
7880 : 0 : ret = flow_dv_validate_item_represented_port
7881 : : (dev, items, attr, item_flags, &act_priv, error);
7882 [ # # ]: 0 : if (ret < 0)
7883 : 0 : return ret;
7884 : 0 : last_item = MLX5_FLOW_ITEM_REPRESENTED_PORT;
7885 : : port_id_item = items;
7886 : 0 : break;
7887 : 0 : case RTE_FLOW_ITEM_TYPE_ETH:
7888 : 0 : ret = mlx5_flow_validate_item_eth(dev, items, item_flags,
7889 : : true, error);
7890 [ # # ]: 0 : if (ret < 0)
7891 : 0 : return ret;
7892 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
7893 : : MLX5_FLOW_LAYER_OUTER_L2;
7894 [ # # # # ]: 0 : if (items->mask != NULL && items->spec != NULL) {
7895 : 0 : ether_type =
7896 : : ((const struct rte_flow_item_eth *)
7897 : : items->spec)->hdr.ether_type;
7898 : 0 : ether_type &=
7899 : : ((const struct rte_flow_item_eth *)
7900 : 0 : items->mask)->hdr.ether_type;
7901 [ # # ]: 0 : ether_type = rte_be_to_cpu_16(ether_type);
7902 : : } else {
7903 : : ether_type = 0;
7904 : : }
7905 : : break;
7906 : 0 : case RTE_FLOW_ITEM_TYPE_VLAN:
7907 : 0 : ret = mlx5_flow_dv_validate_item_vlan(items, item_flags,
7908 : : dev, error);
7909 [ # # ]: 0 : if (ret < 0)
7910 : 0 : return ret;
7911 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
7912 : : MLX5_FLOW_LAYER_OUTER_VLAN;
7913 [ # # # # ]: 0 : if (items->mask != NULL && items->spec != NULL) {
7914 : 0 : ether_type =
7915 : : ((const struct rte_flow_item_vlan *)
7916 : : items->spec)->hdr.eth_proto;
7917 : 0 : ether_type &=
7918 : : ((const struct rte_flow_item_vlan *)
7919 : 0 : items->mask)->hdr.eth_proto;
7920 [ # # ]: 0 : ether_type = rte_be_to_cpu_16(ether_type);
7921 : : } else {
7922 : : ether_type = 0;
7923 : : }
7924 : : /* Store outer VLAN mask for of_push_vlan action. */
7925 [ # # ]: 0 : if (!tunnel)
7926 : : vlan_m = items->mask;
7927 : : break;
7928 : : case RTE_FLOW_ITEM_TYPE_IPV4:
7929 : : next_protocol = mlx5_flow_l3_next_protocol
7930 : : (items, (enum MLX5_SET_MATCHER)-1);
7931 : : l3_tunnel_detection =
7932 : : mlx5_flow_tunnel_ip_check(items, next_protocol,
7933 : : item_flags,
7934 : : &l3_tunnel_flag);
7935 : : /*
7936 : : * explicitly allow inner IPIP match
7937 : : */
7938 : : if (l3_tunnel_detection == l3_tunnel_outer) {
7939 : 0 : item_flags |= l3_tunnel_flag;
7940 : : tunnel = 1;
7941 : : }
7942 : 0 : ret = mlx5_flow_dv_validate_item_ipv4(dev, items,
7943 : : item_flags,
7944 : : last_item,
7945 : : ether_type,
7946 : : &nic_ipv4_mask,
7947 : : error);
7948 [ # # ]: 0 : if (ret < 0)
7949 : 0 : return ret;
7950 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
7951 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4;
7952 [ # # ]: 0 : if (l3_tunnel_detection == l3_tunnel_outer)
7953 : 0 : item_flags |= l3_tunnel_flag;
7954 : : break;
7955 : : case RTE_FLOW_ITEM_TYPE_IPV6:
7956 : : next_protocol = mlx5_flow_l3_next_protocol
7957 : : (items, (enum MLX5_SET_MATCHER)-1);
7958 : : l3_tunnel_detection =
7959 : : mlx5_flow_tunnel_ip_check(items, next_protocol,
7960 : : item_flags,
7961 : : &l3_tunnel_flag);
7962 : : /*
7963 : : * explicitly allow inner IPIP match
7964 : : */
7965 : : if (l3_tunnel_detection == l3_tunnel_outer) {
7966 : 0 : item_flags |= l3_tunnel_flag;
7967 : : tunnel = 1;
7968 : : }
7969 : 0 : ret = mlx5_flow_validate_item_ipv6(dev, items,
7970 : : item_flags,
7971 : : last_item,
7972 : : ether_type,
7973 : : &nic_ipv6_mask,
7974 : : error);
7975 [ # # ]: 0 : if (ret < 0)
7976 : 0 : return ret;
7977 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
7978 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6;
7979 [ # # ]: 0 : if (l3_tunnel_detection == l3_tunnel_outer)
7980 : 0 : item_flags |= l3_tunnel_flag;
7981 : : break;
7982 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
7983 : 0 : ret = flow_dv_validate_item_ipv6_frag_ext(dev, items,
7984 : : item_flags,
7985 : : error);
7986 [ # # ]: 0 : if (ret < 0)
7987 : 0 : return ret;
7988 [ # # ]: 0 : last_item = tunnel ?
7989 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
7990 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
7991 : : next_protocol = mlx5_flow_l3_next_protocol
7992 : : (items, (enum MLX5_SET_MATCHER)-1);
7993 : : break;
7994 : 0 : case RTE_FLOW_ITEM_TYPE_TCP:
7995 : 0 : ret = mlx5_flow_validate_item_tcp
7996 : : (dev, items, item_flags,
7997 : : next_protocol,
7998 : : &nic_tcp_mask,
7999 : : error);
8000 [ # # ]: 0 : if (ret < 0)
8001 : 0 : return ret;
8002 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
8003 : : MLX5_FLOW_LAYER_OUTER_L4_TCP;
8004 : 0 : break;
8005 : 0 : case RTE_FLOW_ITEM_TYPE_UDP:
8006 : 0 : ret = mlx5_flow_validate_item_udp(dev, items, item_flags,
8007 : : next_protocol,
8008 : : error);
8009 : 0 : const struct rte_flow_item_udp *spec = items->spec;
8010 : 0 : const struct rte_flow_item_udp *mask = items->mask;
8011 [ # # ]: 0 : if (!mask)
8012 : : mask = &rte_flow_item_udp_mask;
8013 [ # # ]: 0 : if (spec != NULL)
8014 [ # # ]: 0 : udp_dport = rte_be_to_cpu_16
8015 : : (spec->hdr.dst_port &
8016 : : mask->hdr.dst_port);
8017 [ # # ]: 0 : if (ret < 0)
8018 : 0 : return ret;
8019 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
8020 : : MLX5_FLOW_LAYER_OUTER_L4_UDP;
8021 : 0 : break;
8022 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
8023 : 0 : ret = mlx5_flow_validate_item_gre(dev, items, item_flags,
8024 : : next_protocol, error);
8025 [ # # ]: 0 : if (ret < 0)
8026 : 0 : return ret;
8027 : : gre_item = items;
8028 : 0 : last_item = MLX5_FLOW_LAYER_GRE;
8029 : 0 : break;
8030 : 0 : case RTE_FLOW_ITEM_TYPE_GRE_OPTION:
8031 : 0 : ret = mlx5_flow_validate_item_gre_option(dev, items, item_flags,
8032 : : attr, gre_item, error);
8033 [ # # ]: 0 : if (ret < 0)
8034 : 0 : return ret;
8035 : 0 : last_item = MLX5_FLOW_LAYER_GRE;
8036 : 0 : break;
8037 : 0 : case RTE_FLOW_ITEM_TYPE_NVGRE:
8038 : 0 : ret = mlx5_flow_validate_item_nvgre(dev, items,
8039 : : item_flags,
8040 : : next_protocol,
8041 : : error);
8042 [ # # ]: 0 : if (ret < 0)
8043 : 0 : return ret;
8044 : 0 : last_item = MLX5_FLOW_LAYER_NVGRE;
8045 : 0 : break;
8046 : 0 : case RTE_FLOW_ITEM_TYPE_GRE_KEY:
8047 : 0 : ret = mlx5_flow_validate_item_gre_key
8048 : : (dev, items, item_flags, gre_item, error);
8049 [ # # ]: 0 : if (ret < 0)
8050 : 0 : return ret;
8051 : 0 : last_item = MLX5_FLOW_LAYER_GRE_KEY;
8052 : 0 : break;
8053 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN:
8054 : 0 : ret = mlx5_flow_validate_item_vxlan(dev, udp_dport,
8055 : : items, item_flags,
8056 : : is_root, error);
8057 [ # # ]: 0 : if (ret < 0)
8058 : 0 : return ret;
8059 : 0 : last_item = MLX5_FLOW_LAYER_VXLAN;
8060 : 0 : break;
8061 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
8062 : 0 : ret = mlx5_flow_validate_item_vxlan_gpe(items,
8063 : : item_flags, dev,
8064 : : error);
8065 [ # # ]: 0 : if (ret < 0)
8066 : 0 : return ret;
8067 : 0 : last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
8068 : 0 : break;
8069 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE:
8070 : 0 : ret = mlx5_flow_validate_item_geneve(items,
8071 : : item_flags, dev,
8072 : : error);
8073 [ # # ]: 0 : if (ret < 0)
8074 : 0 : return ret;
8075 : : geneve_item = items;
8076 : 0 : last_item = MLX5_FLOW_LAYER_GENEVE;
8077 : 0 : break;
8078 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
8079 : 0 : ret = mlx5_flow_validate_item_geneve_opt(items,
8080 : : last_item,
8081 : : geneve_item,
8082 : : dev,
8083 : : error);
8084 [ # # ]: 0 : if (ret < 0)
8085 : 0 : return ret;
8086 : 0 : last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
8087 : 0 : break;
8088 : 0 : case RTE_FLOW_ITEM_TYPE_MPLS:
8089 : 0 : ret = mlx5_flow_validate_item_mpls(dev, items,
8090 : : item_flags,
8091 : : last_item, error);
8092 [ # # ]: 0 : if (ret < 0)
8093 : 0 : return ret;
8094 : 0 : last_item = MLX5_FLOW_LAYER_MPLS;
8095 : 0 : break;
8096 : :
8097 : 0 : case RTE_FLOW_ITEM_TYPE_MARK:
8098 : 0 : ret = flow_dv_validate_item_mark(dev, items, attr,
8099 : : error);
8100 [ # # ]: 0 : if (ret < 0)
8101 : 0 : return ret;
8102 : 0 : last_item = MLX5_FLOW_ITEM_MARK;
8103 : 0 : break;
8104 : 0 : case RTE_FLOW_ITEM_TYPE_META:
8105 : 0 : ret = flow_dv_validate_item_meta(dev, items, attr,
8106 : : error);
8107 [ # # ]: 0 : if (ret < 0)
8108 : 0 : return ret;
8109 : 0 : last_item = MLX5_FLOW_ITEM_METADATA;
8110 : 0 : break;
8111 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP:
8112 : 0 : ret = mlx5_flow_validate_item_icmp(dev, items, item_flags,
8113 : : next_protocol,
8114 : : error);
8115 [ # # ]: 0 : if (ret < 0)
8116 : 0 : return ret;
8117 : 0 : last_item = MLX5_FLOW_LAYER_ICMP;
8118 : 0 : break;
8119 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6:
8120 : 0 : ret = mlx5_flow_validate_item_icmp6(dev, items, item_flags,
8121 : : next_protocol,
8122 : : error);
8123 [ # # ]: 0 : if (ret < 0)
8124 : 0 : return ret;
8125 : : item_ipv6_proto = IPPROTO_ICMPV6;
8126 : 0 : last_item = MLX5_FLOW_LAYER_ICMP6;
8127 : 0 : break;
8128 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REQUEST:
8129 : : case RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REPLY:
8130 : 0 : ret = mlx5_flow_validate_item_icmp6_echo(dev, items,
8131 : : item_flags,
8132 : : next_protocol,
8133 : : error);
8134 [ # # ]: 0 : if (ret < 0)
8135 : 0 : return ret;
8136 : : item_ipv6_proto = IPPROTO_ICMPV6;
8137 : 0 : last_item = MLX5_FLOW_LAYER_ICMP6;
8138 : 0 : break;
8139 : 0 : case RTE_FLOW_ITEM_TYPE_TAG:
8140 : 0 : ret = flow_dv_validate_item_tag(dev, items, &tag_bitmap,
8141 : : attr, error);
8142 [ # # ]: 0 : if (ret < 0)
8143 : 0 : return ret;
8144 : 0 : last_item = MLX5_FLOW_ITEM_TAG;
8145 : 0 : break;
8146 : 0 : case RTE_FLOW_ITEM_TYPE_TX_QUEUE:
8147 : : case MLX5_RTE_FLOW_ITEM_TYPE_SQ:
8148 : 0 : last_item = MLX5_FLOW_ITEM_SQ;
8149 : 0 : break;
8150 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
8151 : 0 : mlx5_tag = (const struct mlx5_rte_flow_item_tag *)items->spec;
8152 [ # # ]: 0 : if (tag_bitmap & (1 << mlx5_tag->id))
8153 : 0 : return rte_flow_error_set(error, EINVAL,
8154 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
8155 : : items->spec,
8156 : : "Duplicated tag index");
8157 : 0 : tag_bitmap |= 1 << mlx5_tag->id;
8158 : 0 : break;
8159 : 0 : case RTE_FLOW_ITEM_TYPE_GTP:
8160 : 0 : ret = mlx5_flow_dv_validate_item_gtp(dev, items,
8161 : : item_flags,
8162 : : error);
8163 [ # # ]: 0 : if (ret < 0)
8164 : 0 : return ret;
8165 : : gtp_item = items;
8166 : 0 : last_item = MLX5_FLOW_LAYER_GTP;
8167 : 0 : break;
8168 : 0 : case RTE_FLOW_ITEM_TYPE_GTP_PSC:
8169 : 0 : ret = mlx5_flow_dv_validate_item_gtp_psc(dev, items,
8170 : : last_item,
8171 : : gtp_item,
8172 : : is_root, error);
8173 [ # # ]: 0 : if (ret < 0)
8174 : 0 : return ret;
8175 : 0 : last_item = MLX5_FLOW_LAYER_GTP_PSC;
8176 : 0 : break;
8177 : 0 : case RTE_FLOW_ITEM_TYPE_ECPRI:
8178 : : /* Capacity will be checked in the translate stage. */
8179 : 0 : ret = mlx5_flow_validate_item_ecpri(dev, items,
8180 : : item_flags,
8181 : : last_item,
8182 : : ether_type,
8183 : : &nic_ecpri_mask,
8184 : : error);
8185 [ # # ]: 0 : if (ret < 0)
8186 : 0 : return ret;
8187 : 0 : last_item = MLX5_FLOW_LAYER_ECPRI;
8188 : 0 : break;
8189 : 0 : case RTE_FLOW_ITEM_TYPE_INTEGRITY:
8190 : 0 : ret = flow_dv_validate_item_integrity(dev, items,
8191 : : item_flags,
8192 : : &last_item,
8193 : : integrity_items,
8194 : : error);
8195 [ # # ]: 0 : if (ret < 0)
8196 : 0 : return ret;
8197 : : break;
8198 : 0 : case RTE_FLOW_ITEM_TYPE_CONNTRACK:
8199 : 0 : ret = mlx5_flow_dv_validate_item_aso_ct(dev, items,
8200 : : &item_flags,
8201 : : error);
8202 [ # # ]: 0 : if (ret < 0)
8203 : 0 : return ret;
8204 : 0 : last_item = MLX5_FLOW_LAYER_ASO_CT;
8205 : 0 : break;
8206 : : case MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL:
8207 : : /* tunnel offload item was processed before
8208 : : * list it here as a supported type
8209 : : */
8210 : : break;
8211 : 0 : case RTE_FLOW_ITEM_TYPE_FLEX:
8212 : 0 : ret = flow_dv_validate_item_flex(dev, items, item_flags,
8213 : : &last_item,
8214 : : tunnel != 0, error);
8215 [ # # ]: 0 : if (ret < 0)
8216 : 0 : return ret;
8217 : : /* Reset for next proto, it is unknown. */
8218 : : next_protocol = 0xff;
8219 : : break;
8220 : 0 : case RTE_FLOW_ITEM_TYPE_METER_COLOR:
8221 : 0 : ret = flow_dv_validate_item_meter_color(dev, items,
8222 : : attr, error);
8223 [ # # ]: 0 : if (ret < 0)
8224 : 0 : return ret;
8225 : 0 : last_item = MLX5_FLOW_ITEM_METER_COLOR;
8226 : 0 : break;
8227 : 0 : case RTE_FLOW_ITEM_TYPE_AGGR_AFFINITY:
8228 : 0 : ret = flow_dv_validate_item_aggr_affinity(dev, items,
8229 : : attr, error);
8230 [ # # ]: 0 : if (ret < 0)
8231 : 0 : return ret;
8232 : 0 : last_item = MLX5_FLOW_ITEM_AGGR_AFFINITY;
8233 : 0 : break;
8234 : 0 : case RTE_FLOW_ITEM_TYPE_IB_BTH:
8235 : 0 : ret = mlx5_flow_validate_item_ib_bth(dev, udp_dport,
8236 : : items, is_root, error);
8237 [ # # ]: 0 : if (ret < 0)
8238 : 0 : return ret;
8239 : :
8240 : 0 : last_item = MLX5_FLOW_ITEM_IB_BTH;
8241 : 0 : break;
8242 : 0 : case RTE_FLOW_ITEM_TYPE_NSH:
8243 : 0 : ret = mlx5_flow_validate_item_nsh(dev, items, error);
8244 [ # # ]: 0 : if (ret < 0)
8245 : 0 : return ret;
8246 : 0 : last_item = MLX5_FLOW_ITEM_NSH;
8247 : 0 : break;
8248 : 0 : default:
8249 : 0 : return rte_flow_error_set(error, ENOTSUP,
8250 : : RTE_FLOW_ERROR_TYPE_ITEM,
8251 : : NULL, "item not supported");
8252 : : }
8253 : 0 : item_flags |= last_item;
8254 : : }
8255 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_INTEGRITY) {
8256 : 0 : ret = flow_dv_validate_item_integrity_post(integrity_items,
8257 : : item_flags, error);
8258 [ # # ]: 0 : if (ret)
8259 : : return ret;
8260 : : }
8261 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
8262 : 0 : int type = actions->type;
8263 : :
8264 : : if (!mlx5_flow_os_action_supported(type))
8265 : : return rte_flow_error_set(error, ENOTSUP,
8266 : : RTE_FLOW_ERROR_TYPE_ACTION,
8267 : : actions,
8268 : : "action not supported");
8269 [ # # ]: 0 : if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
8270 : 0 : return rte_flow_error_set(error, ENOTSUP,
8271 : : RTE_FLOW_ERROR_TYPE_ACTION,
8272 : : actions, "too many actions");
8273 [ # # ]: 0 : if (action_flags &
8274 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
8275 : 0 : return rte_flow_error_set(error, ENOTSUP,
8276 : : RTE_FLOW_ERROR_TYPE_ACTION,
8277 : : NULL, "meter action with policy "
8278 : : "must be the last action");
8279 [ # # # # : 0 : switch (type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
8280 : : case RTE_FLOW_ACTION_TYPE_VOID:
8281 : : break;
8282 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
8283 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
8284 : 0 : ret = flow_dv_validate_action_port_id(dev,
8285 : : action_flags,
8286 : : actions,
8287 : : attr,
8288 : : error);
8289 [ # # ]: 0 : if (ret)
8290 : 0 : return ret;
8291 [ # # ]: 0 : if (type == RTE_FLOW_ACTION_TYPE_PORT_ID) {
8292 : 0 : port = (const struct rte_flow_action_port_id *)
8293 : : actions->conf;
8294 [ # # ]: 0 : port_id = port->original ? dev->data->port_id : port->id;
8295 : : } else {
8296 : 0 : port_id = ((const struct rte_flow_action_ethdev *)
8297 : 0 : actions->conf)->port_id;
8298 : : }
8299 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_ID;
8300 : 0 : ++actions_n;
8301 : 0 : break;
8302 : 0 : case RTE_FLOW_ACTION_TYPE_FLAG:
8303 : 0 : ret = flow_dv_validate_action_flag(dev, action_flags,
8304 : : attr, error);
8305 [ # # ]: 0 : if (ret < 0)
8306 : 0 : return ret;
8307 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
8308 : : /* Count all modify-header actions as one. */
8309 [ # # ]: 0 : if (!(action_flags &
8310 : : MLX5_FLOW_MODIFY_HDR_ACTIONS))
8311 : 0 : ++actions_n;
8312 : 0 : action_flags |= MLX5_FLOW_ACTION_FLAG |
8313 : : MLX5_FLOW_ACTION_MARK_EXT;
8314 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8315 : : modify_after_mirror = 1;
8316 : :
8317 : : } else {
8318 : 0 : action_flags |= MLX5_FLOW_ACTION_FLAG;
8319 : 0 : ++actions_n;
8320 : : }
8321 : 0 : rw_act_num += MLX5_ACT_NUM_SET_MARK;
8322 : 0 : break;
8323 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
8324 : 0 : ret = flow_dv_validate_action_mark(dev, actions,
8325 : : action_flags,
8326 : : attr, error);
8327 [ # # ]: 0 : if (ret < 0)
8328 : 0 : return ret;
8329 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
8330 : : /* Count all modify-header actions as one. */
8331 [ # # ]: 0 : if (!(action_flags &
8332 : : MLX5_FLOW_MODIFY_HDR_ACTIONS))
8333 : 0 : ++actions_n;
8334 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK |
8335 : : MLX5_FLOW_ACTION_MARK_EXT;
8336 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8337 : : modify_after_mirror = 1;
8338 : : } else {
8339 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK;
8340 : 0 : ++actions_n;
8341 : : }
8342 : 0 : rw_act_num += MLX5_ACT_NUM_SET_MARK;
8343 : 0 : break;
8344 : 0 : case RTE_FLOW_ACTION_TYPE_SET_META:
8345 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
8346 : 0 : return rte_flow_error_set(error, ENOTSUP,
8347 : : RTE_FLOW_ERROR_TYPE_ACTION,
8348 : : actions,
8349 : : "action not supported");
8350 : 0 : ret = flow_dv_validate_action_set_meta(dev, actions,
8351 : : action_flags,
8352 : : attr, error);
8353 [ # # ]: 0 : if (ret < 0)
8354 : 0 : return ret;
8355 : : /* Count all modify-header actions as one action. */
8356 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8357 : 0 : ++actions_n;
8358 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8359 : : modify_after_mirror = 1;
8360 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_META;
8361 : 0 : rw_act_num += MLX5_ACT_NUM_SET_META;
8362 : 0 : break;
8363 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TAG:
8364 : 0 : ret = flow_dv_validate_action_set_tag(dev, actions,
8365 : : action_flags,
8366 : : attr, error);
8367 [ # # ]: 0 : if (ret < 0)
8368 : 0 : return ret;
8369 : : /* Count all modify-header actions as one action. */
8370 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8371 : 0 : ++actions_n;
8372 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8373 : : modify_after_mirror = 1;
8374 : 0 : tag_id = ((const struct rte_flow_action_set_tag *)
8375 : 0 : actions->conf)->index;
8376 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
8377 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
8378 : 0 : break;
8379 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
8380 : 0 : ret = mlx5_flow_validate_action_drop(dev, is_root,
8381 : : attr, error);
8382 [ # # ]: 0 : if (ret < 0)
8383 : 0 : return ret;
8384 : 0 : action_flags |= MLX5_FLOW_ACTION_DROP;
8385 : 0 : ++actions_n;
8386 : 0 : break;
8387 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
8388 : 0 : ret = mlx5_flow_validate_action_queue(actions,
8389 : : action_flags, dev,
8390 : : attr, error);
8391 [ # # ]: 0 : if (ret < 0)
8392 : 0 : return ret;
8393 : 0 : queue_index = ((const struct rte_flow_action_queue *)
8394 : 0 : (actions->conf))->index;
8395 : 0 : action_flags |= MLX5_FLOW_ACTION_QUEUE;
8396 : 0 : ++actions_n;
8397 : 0 : break;
8398 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
8399 : 0 : rss = actions->conf;
8400 : 0 : ret = mlx5_flow_validate_action_rss(actions,
8401 : : action_flags, dev,
8402 : : attr, item_flags,
8403 : : error);
8404 [ # # ]: 0 : if (ret < 0)
8405 : 0 : return ret;
8406 [ # # ]: 0 : if (rss && sample_rss &&
8407 [ # # ]: 0 : (sample_rss->level != rss->level ||
8408 [ # # ]: 0 : sample_rss->types != rss->types))
8409 : 0 : return rte_flow_error_set(error, ENOTSUP,
8410 : : RTE_FLOW_ERROR_TYPE_ACTION,
8411 : : NULL,
8412 : : "Can't use the different RSS types "
8413 : : "or level in the same flow");
8414 [ # # # # ]: 0 : if (rss != NULL && rss->queue_num)
8415 : 0 : queue_index = rss->queue[0];
8416 : 0 : action_flags |= MLX5_FLOW_ACTION_RSS;
8417 : 0 : ++actions_n;
8418 : 0 : break;
8419 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
8420 : : ret =
8421 : 0 : mlx5_flow_validate_action_default_miss(action_flags,
8422 : : attr, error);
8423 [ # # ]: 0 : if (ret < 0)
8424 : 0 : return ret;
8425 : 0 : action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
8426 : 0 : ++actions_n;
8427 : 0 : break;
8428 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
8429 : : shared_count = true;
8430 : : /* fall-through. */
8431 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
8432 : 0 : ret = flow_dv_validate_action_count(dev, shared_count,
8433 : : action_flags,
8434 : : is_root, error);
8435 [ # # ]: 0 : if (ret < 0)
8436 : 0 : return ret;
8437 : 0 : count = actions->conf;
8438 : 0 : action_flags |= MLX5_FLOW_ACTION_COUNT;
8439 : 0 : ++actions_n;
8440 : 0 : break;
8441 : 0 : case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
8442 [ # # ]: 0 : if (flow_dv_validate_action_pop_vlan(dev,
8443 : : action_flags,
8444 : : actions,
8445 : : item_flags, attr,
8446 : : error))
8447 : 0 : return -rte_errno;
8448 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8449 : : modify_after_mirror = 1;
8450 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
8451 : 0 : ++actions_n;
8452 : 0 : break;
8453 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
8454 : 0 : ret = flow_dv_validate_action_push_vlan(dev,
8455 : : action_flags,
8456 : : vlan_m,
8457 : : actions, attr,
8458 : : error);
8459 [ # # ]: 0 : if (ret < 0)
8460 : 0 : return ret;
8461 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8462 : : modify_after_mirror = 1;
8463 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
8464 : 0 : ++actions_n;
8465 : 0 : break;
8466 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
8467 : 0 : ret = flow_dv_validate_action_set_vlan_pcp
8468 : : (action_flags, actions, error);
8469 [ # # ]: 0 : if (ret < 0)
8470 : 0 : return ret;
8471 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8472 : : modify_after_mirror = 1;
8473 : : /* Count PCP with push_vlan command. */
8474 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_PCP;
8475 : 0 : break;
8476 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
8477 : 0 : ret = flow_dv_validate_action_set_vlan_vid
8478 : : (item_flags, action_flags,
8479 : : actions, error);
8480 [ # # ]: 0 : if (ret < 0)
8481 : 0 : return ret;
8482 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8483 : : modify_after_mirror = 1;
8484 : : /* Count VID with push_vlan command. */
8485 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
8486 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_VID;
8487 : 0 : break;
8488 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
8489 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
8490 : 0 : ret = mlx5_flow_dv_validate_action_l2_encap(dev,
8491 : : action_flags,
8492 : : actions,
8493 : : attr,
8494 : : error);
8495 [ # # ]: 0 : if (ret < 0)
8496 : 0 : return ret;
8497 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
8498 : 0 : ++actions_n;
8499 : 0 : break;
8500 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
8501 : : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
8502 : 0 : ret = mlx5_flow_dv_validate_action_decap(dev,
8503 : : action_flags,
8504 : : actions,
8505 : : item_flags,
8506 : : attr, error);
8507 [ # # ]: 0 : if (ret < 0)
8508 : 0 : return ret;
8509 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8510 : : modify_after_mirror = 1;
8511 : 0 : action_flags |= MLX5_FLOW_ACTION_DECAP;
8512 : 0 : ++actions_n;
8513 : 0 : break;
8514 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
8515 : 0 : ret = mlx5_flow_dv_validate_action_raw_encap_decap
8516 : 0 : (dev, NULL, actions->conf, attr, &action_flags,
8517 : : &actions_n, actions, item_flags, error);
8518 [ # # ]: 0 : if (ret < 0)
8519 : 0 : return ret;
8520 : : break;
8521 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
8522 : 0 : decap = actions->conf;
8523 [ # # ]: 0 : while ((++actions)->type == RTE_FLOW_ACTION_TYPE_VOID)
8524 : : ;
8525 [ # # ]: 0 : if (actions->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
8526 : : encap = NULL;
8527 : : actions--;
8528 : : } else {
8529 : 0 : encap = actions->conf;
8530 : : }
8531 [ # # ]: 0 : ret = mlx5_flow_dv_validate_action_raw_encap_decap
8532 : : (dev,
8533 : : decap ? decap : &empty_decap, encap,
8534 : : attr, &action_flags, &actions_n,
8535 : : actions, item_flags, error);
8536 [ # # ]: 0 : if (ret < 0)
8537 : 0 : return ret;
8538 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_SAMPLE) &&
8539 : : (action_flags & MLX5_FLOW_ACTION_DECAP))
8540 : : modify_after_mirror = 1;
8541 : : break;
8542 : 0 : case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
8543 : : case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
8544 : 0 : ret = flow_dv_validate_action_modify_mac(action_flags,
8545 : : actions,
8546 : : item_flags,
8547 : : error);
8548 [ # # ]: 0 : if (ret < 0)
8549 : 0 : return ret;
8550 : : /* Count all modify-header actions as one action. */
8551 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8552 : 0 : ++actions_n;
8553 : 0 : action_flags |= actions->type ==
8554 : : RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
8555 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_MAC_SRC :
8556 : : MLX5_FLOW_ACTION_SET_MAC_DST;
8557 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8558 : : modify_after_mirror = 1;
8559 : : /*
8560 : : * Even if the source and destination MAC addresses have
8561 : : * overlap in the header with 4B alignment, the convert
8562 : : * function will handle them separately and 4 SW actions
8563 : : * will be created. And 2 actions will be added each
8564 : : * time no matter how many bytes of address will be set.
8565 : : */
8566 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_MAC;
8567 : 0 : break;
8568 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
8569 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
8570 : 0 : ret = flow_dv_validate_action_modify_ipv4(action_flags,
8571 : : actions,
8572 : : item_flags,
8573 : : error);
8574 [ # # ]: 0 : if (ret < 0)
8575 : 0 : return ret;
8576 : : /* Count all modify-header actions as one action. */
8577 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8578 : 0 : ++actions_n;
8579 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8580 : : modify_after_mirror = 1;
8581 : 0 : action_flags |= actions->type ==
8582 : : RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
8583 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_IPV4_SRC :
8584 : : MLX5_FLOW_ACTION_SET_IPV4_DST;
8585 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_IPV4;
8586 : 0 : break;
8587 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
8588 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
8589 : 0 : ret = flow_dv_validate_action_modify_ipv6(action_flags,
8590 : : actions,
8591 : : item_flags,
8592 : : error);
8593 [ # # ]: 0 : if (ret < 0)
8594 : 0 : return ret;
8595 [ # # ]: 0 : if (item_ipv6_proto == IPPROTO_ICMPV6)
8596 : 0 : return rte_flow_error_set(error, ENOTSUP,
8597 : : RTE_FLOW_ERROR_TYPE_ACTION,
8598 : : actions,
8599 : : "Can't change header "
8600 : : "with ICMPv6 proto");
8601 : : /* Count all modify-header actions as one action. */
8602 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8603 : 0 : ++actions_n;
8604 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8605 : : modify_after_mirror = 1;
8606 : 0 : action_flags |= actions->type ==
8607 : : RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
8608 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_IPV6_SRC :
8609 : : MLX5_FLOW_ACTION_SET_IPV6_DST;
8610 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_IPV6;
8611 : 0 : break;
8612 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
8613 : : case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
8614 : 0 : ret = flow_dv_validate_action_modify_tp(action_flags,
8615 : : actions,
8616 : : item_flags,
8617 : : error);
8618 [ # # ]: 0 : if (ret < 0)
8619 : 0 : return ret;
8620 : : /* Count all modify-header actions as one action. */
8621 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8622 : 0 : ++actions_n;
8623 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8624 : : modify_after_mirror = 1;
8625 : 0 : action_flags |= actions->type ==
8626 : : RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
8627 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_TP_SRC :
8628 : : MLX5_FLOW_ACTION_SET_TP_DST;
8629 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_PORT;
8630 : 0 : break;
8631 : 0 : case RTE_FLOW_ACTION_TYPE_DEC_TTL:
8632 : : case RTE_FLOW_ACTION_TYPE_SET_TTL:
8633 : 0 : ret = flow_dv_validate_action_modify_ttl(action_flags,
8634 : : actions,
8635 : : item_flags,
8636 : : error);
8637 [ # # ]: 0 : if (ret < 0)
8638 : 0 : return ret;
8639 : : /* Count all modify-header actions as one action. */
8640 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8641 : 0 : ++actions_n;
8642 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8643 : : modify_after_mirror = 1;
8644 : 0 : action_flags |= actions->type ==
8645 : : RTE_FLOW_ACTION_TYPE_SET_TTL ?
8646 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_TTL :
8647 : : MLX5_FLOW_ACTION_DEC_TTL;
8648 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_TTL;
8649 : 0 : break;
8650 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
8651 : 0 : ret = flow_dv_validate_action_jump(dev, tunnel, actions,
8652 : : action_flags,
8653 : : attr, external,
8654 : : error);
8655 [ # # ]: 0 : if (ret)
8656 : 0 : return ret;
8657 : 0 : ++actions_n;
8658 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP;
8659 : 0 : break;
8660 : 0 : case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
8661 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
8662 : 0 : ret = flow_dv_validate_action_modify_tcp_seq
8663 : : (action_flags,
8664 : : actions,
8665 : : item_flags,
8666 : : error);
8667 [ # # ]: 0 : if (ret < 0)
8668 : 0 : return ret;
8669 : : /* Count all modify-header actions as one action. */
8670 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8671 : 0 : ++actions_n;
8672 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8673 : : modify_after_mirror = 1;
8674 : 0 : action_flags |= actions->type ==
8675 : : RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
8676 [ # # ]: 0 : MLX5_FLOW_ACTION_INC_TCP_SEQ :
8677 : : MLX5_FLOW_ACTION_DEC_TCP_SEQ;
8678 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_TCPSEQ;
8679 : 0 : break;
8680 : 0 : case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
8681 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
8682 : 0 : ret = flow_dv_validate_action_modify_tcp_ack
8683 : : (action_flags,
8684 : : actions,
8685 : : item_flags,
8686 : : error);
8687 [ # # ]: 0 : if (ret < 0)
8688 : 0 : return ret;
8689 : : /* Count all modify-header actions as one action. */
8690 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8691 : 0 : ++actions_n;
8692 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8693 : : modify_after_mirror = 1;
8694 : 0 : action_flags |= actions->type ==
8695 : : RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
8696 [ # # ]: 0 : MLX5_FLOW_ACTION_INC_TCP_ACK :
8697 : : MLX5_FLOW_ACTION_DEC_TCP_ACK;
8698 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_TCPACK;
8699 : 0 : break;
8700 : : case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
8701 : : break;
8702 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
8703 : : case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
8704 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
8705 : 0 : break;
8706 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
8707 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
8708 : 0 : return rte_flow_error_set(error, ENOTSUP,
8709 : : RTE_FLOW_ERROR_TYPE_ACTION,
8710 : : actions,
8711 : : "action not supported");
8712 : 0 : ret = mlx5_flow_validate_action_meter(dev,
8713 : : action_flags,
8714 : : item_flags,
8715 : : actions, attr,
8716 : : port_id_item,
8717 : : &def_policy,
8718 : : error);
8719 [ # # ]: 0 : if (ret < 0)
8720 : 0 : return ret;
8721 : 0 : action_flags |= MLX5_FLOW_ACTION_METER;
8722 [ # # ]: 0 : if (!def_policy)
8723 : 0 : action_flags |=
8724 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
8725 : 0 : ++actions_n;
8726 : : /* Meter action will add one more TAG action. */
8727 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
8728 : 0 : break;
8729 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
8730 [ # # ]: 0 : if (is_root)
8731 : 0 : return rte_flow_error_set(error, ENOTSUP,
8732 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8733 : : NULL,
8734 : : "Shared ASO age action is not supported for group 0");
8735 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_AGE)
8736 : 0 : return rte_flow_error_set
8737 : : (error, EINVAL,
8738 : : RTE_FLOW_ERROR_TYPE_ACTION,
8739 : : NULL,
8740 : : "duplicate age actions set");
8741 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8742 : : aso_after_sample = 1;
8743 : 0 : action_flags |= MLX5_FLOW_ACTION_AGE;
8744 : 0 : ++actions_n;
8745 : 0 : break;
8746 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
8747 : 0 : non_shared_age = actions->conf;
8748 : 0 : ret = flow_dv_validate_action_age(action_flags,
8749 : : actions, dev,
8750 : : error);
8751 [ # # ]: 0 : if (ret < 0)
8752 : 0 : return ret;
8753 : : /*
8754 : : * Validate the regular AGE action (using counter)
8755 : : * mutual exclusion with indirect counter actions.
8756 : : */
8757 [ # # ]: 0 : if (!flow_hit_aso_supported(priv, is_root)) {
8758 [ # # ]: 0 : if (shared_count)
8759 : 0 : return rte_flow_error_set
8760 : : (error, EINVAL,
8761 : : RTE_FLOW_ERROR_TYPE_ACTION,
8762 : : NULL,
8763 : : "old age and indirect count combination is not supported");
8764 [ # # ]: 0 : if (sample_count)
8765 : 0 : return rte_flow_error_set
8766 : : (error, EINVAL,
8767 : : RTE_FLOW_ERROR_TYPE_ACTION,
8768 : : NULL,
8769 : : "old age action and count must be in the same sub flow");
8770 : : } else {
8771 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8772 : : aso_after_sample = 1;
8773 : : }
8774 : 0 : action_flags |= MLX5_FLOW_ACTION_AGE;
8775 : 0 : ++actions_n;
8776 : 0 : break;
8777 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
8778 : 0 : ret = flow_dv_validate_action_modify_ipv4_dscp
8779 : : (action_flags,
8780 : : actions,
8781 : : item_flags,
8782 : : error);
8783 [ # # ]: 0 : if (ret < 0)
8784 : 0 : return ret;
8785 : : /* Count all modify-header actions as one action. */
8786 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8787 : 0 : ++actions_n;
8788 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8789 : : modify_after_mirror = 1;
8790 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
8791 : 0 : rw_act_num += MLX5_ACT_NUM_SET_DSCP;
8792 : 0 : break;
8793 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
8794 : 0 : ret = flow_dv_validate_action_modify_ipv6_dscp
8795 : : (action_flags,
8796 : : actions,
8797 : : item_flags,
8798 : : error);
8799 [ # # ]: 0 : if (ret < 0)
8800 : 0 : return ret;
8801 : : /* Count all modify-header actions as one action. */
8802 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8803 : 0 : ++actions_n;
8804 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8805 : : modify_after_mirror = 1;
8806 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
8807 : 0 : rw_act_num += MLX5_ACT_NUM_SET_DSCP;
8808 : 0 : break;
8809 : 0 : case RTE_FLOW_ACTION_TYPE_SAMPLE:
8810 : 0 : ret = flow_dv_validate_action_sample(&action_flags,
8811 : : &sub_action_flags,
8812 : : actions, dev,
8813 : : attr, item_flags,
8814 : : rss, &sample_rss,
8815 : : &sample_count,
8816 : : &fdb_mirror,
8817 : : &sample_port_id,
8818 : : is_root,
8819 : : error);
8820 [ # # ]: 0 : if (ret < 0)
8821 : 0 : return ret;
8822 [ # # # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_SET_TAG) &&
8823 : 0 : tag_id == 0 &&
8824 [ # # ]: 0 : priv->sh->registers.aso_reg == REG_NON)
8825 : 0 : return rte_flow_error_set(error, EINVAL,
8826 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8827 : : "sample after tag action causes metadata tag index 0 corruption");
8828 : 0 : action_flags |= MLX5_FLOW_ACTION_SAMPLE;
8829 : 0 : ++actions_n;
8830 : 0 : break;
8831 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
8832 : 0 : ret = flow_dv_validate_action_modify_field(dev,
8833 : : action_flags,
8834 : : actions,
8835 : : attr,
8836 : : is_root,
8837 : : error);
8838 [ # # ]: 0 : if (ret < 0)
8839 : 0 : return ret;
8840 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8841 : : modify_after_mirror = 1;
8842 : : /* Count all modify-header actions as one action. */
8843 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8844 : 0 : ++actions_n;
8845 : 0 : action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
8846 : 0 : rw_act_num += ret;
8847 : 0 : break;
8848 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
8849 : 0 : ret = mlx5_flow_dv_validate_action_aso_ct(dev,
8850 : : action_flags,
8851 : : item_flags,
8852 : : is_root,
8853 : : error);
8854 [ # # ]: 0 : if (ret < 0)
8855 : 0 : return ret;
8856 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8857 : : aso_after_sample = 1;
8858 : 0 : action_flags |= MLX5_FLOW_ACTION_CT;
8859 : 0 : break;
8860 : : case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
8861 : : /* tunnel offload action was processed before
8862 : : * list it here as a supported type
8863 : : */
8864 : : break;
8865 : : #ifdef HAVE_MLX5DV_DR_ACTION_CREATE_DEST_ROOT_TABLE
8866 : : case RTE_FLOW_ACTION_TYPE_SEND_TO_KERNEL:
8867 : : action_flags |= MLX5_FLOW_ACTION_SEND_TO_KERNEL;
8868 : : ++actions_n;
8869 : : break;
8870 : : #endif
8871 : 0 : default:
8872 : 0 : return rte_flow_error_set(error, ENOTSUP,
8873 : : RTE_FLOW_ERROR_TYPE_ACTION,
8874 : : actions,
8875 : : "action not supported");
8876 : : }
8877 : : }
8878 : : /*
8879 : : * Validate actions in flow rules
8880 : : * - Explicit decap action is prohibited by the tunnel offload API.
8881 : : * - Drop action in tunnel steer rule is prohibited by the API.
8882 : : * - Application cannot use MARK action because it's value can mask
8883 : : * tunnel default miss notification.
8884 : : * - JUMP in tunnel match rule has no support in current PMD
8885 : : * implementation.
8886 : : * - TAG & META are reserved for future uses.
8887 : : */
8888 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_TUNNEL_SET) {
8889 : : uint64_t bad_actions_mask = MLX5_FLOW_ACTION_DECAP |
8890 : : MLX5_FLOW_ACTION_MARK |
8891 : : MLX5_FLOW_ACTION_SET_TAG |
8892 : : MLX5_FLOW_ACTION_SET_META |
8893 : : MLX5_FLOW_ACTION_DROP;
8894 : :
8895 [ # # ]: 0 : if (action_flags & bad_actions_mask)
8896 : 0 : return rte_flow_error_set
8897 : : (error, EINVAL,
8898 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8899 : : "Invalid RTE action in tunnel "
8900 : : "set decap rule");
8901 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_ACTION_JUMP))
8902 : 0 : return rte_flow_error_set
8903 : : (error, EINVAL,
8904 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8905 : : "tunnel set decap rule must terminate "
8906 : : "with JUMP");
8907 [ # # ]: 0 : if (attr->egress)
8908 : 0 : return rte_flow_error_set
8909 : : (error, EINVAL,
8910 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8911 : : "tunnel flows for ingress and transfer traffic only");
8912 : : }
8913 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_TUNNEL_MATCH) {
8914 : : uint64_t bad_actions_mask = MLX5_FLOW_ACTION_JUMP |
8915 : : MLX5_FLOW_ACTION_MARK |
8916 : : MLX5_FLOW_ACTION_SET_TAG |
8917 : : MLX5_FLOW_ACTION_SET_META;
8918 : :
8919 [ # # ]: 0 : if (action_flags & bad_actions_mask)
8920 : 0 : return rte_flow_error_set
8921 : : (error, EINVAL,
8922 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8923 : : "Invalid RTE action in tunnel "
8924 : : "set match rule");
8925 : : }
8926 : : /*
8927 : : * Validate the drop action mutual exclusion with other actions.
8928 : : * Drop action is mutually-exclusive with any other action, except for
8929 : : * Count/Sample/Age actions.
8930 : : * Drop action compatibility with tunnel offload was already validated.
8931 : : */
8932 [ # # ]: 0 : if (action_flags & (MLX5_FLOW_ACTION_TUNNEL_MATCH |
8933 : : MLX5_FLOW_ACTION_TUNNEL_MATCH));
8934 [ # # ]: 0 : else if ((action_flags & MLX5_FLOW_ACTION_DROP) &&
8935 [ # # ]: 0 : (action_flags & ~(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_DROP_INCLUSIVE_ACTIONS)))
8936 : 0 : return rte_flow_error_set(error, EINVAL,
8937 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8938 : : "Drop action is mutually-exclusive "
8939 : : "with any other action, except for "
8940 : : "Count/Sample/Age action");
8941 : : /* Eswitch has few restrictions on using items and actions */
8942 [ # # ]: 0 : if (attr->transfer) {
8943 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev) &&
8944 [ # # ]: 0 : action_flags & MLX5_FLOW_ACTION_FLAG)
8945 : 0 : return rte_flow_error_set(error, ENOTSUP,
8946 : : RTE_FLOW_ERROR_TYPE_ACTION,
8947 : : NULL,
8948 : : "unsupported action FLAG");
8949 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev) &&
8950 [ # # ]: 0 : action_flags & MLX5_FLOW_ACTION_MARK)
8951 : 0 : return rte_flow_error_set(error, ENOTSUP,
8952 : : RTE_FLOW_ERROR_TYPE_ACTION,
8953 : : NULL,
8954 : : "unsupported action MARK");
8955 [ # # ]: 0 : if (!priv->jump_fdb_rx_en) {
8956 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_QUEUE)
8957 : 0 : return rte_flow_error_set(error, ENOTSUP,
8958 : : RTE_FLOW_ERROR_TYPE_ACTION,
8959 : : NULL,
8960 : : "unsupported action QUEUE");
8961 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_RSS)
8962 : 0 : return rte_flow_error_set(error, ENOTSUP,
8963 : : RTE_FLOW_ERROR_TYPE_ACTION,
8964 : : NULL,
8965 : : "unsupported action RSS");
8966 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
8967 : 0 : return rte_flow_error_set(error, EINVAL,
8968 : : RTE_FLOW_ERROR_TYPE_ACTION,
8969 : : actions,
8970 : : "no fate action is found");
8971 : : }
8972 : : } else {
8973 [ # # # # ]: 0 : if (!(action_flags & MLX5_FLOW_FATE_ACTIONS) && attr->ingress)
8974 : 0 : return rte_flow_error_set(error, EINVAL,
8975 : : RTE_FLOW_ERROR_TYPE_ACTION,
8976 : : actions,
8977 : : "no fate action is found");
8978 : : }
8979 : : /*
8980 : : * Continue validation for Xcap and VLAN actions.
8981 : : * If hairpin is working in explicit TX rule mode, there is no actions
8982 : : * splitting and the validation of hairpin ingress flow should be the
8983 : : * same as other standard flows.
8984 : : */
8985 [ # # ]: 0 : if ((action_flags & (MLX5_FLOW_XCAP_ACTIONS |
8986 [ # # ]: 0 : MLX5_FLOW_VLAN_ACTIONS)) &&
8987 [ # # # # ]: 0 : (queue_index == 0xFFFF || !mlx5_rxq_is_hairpin(dev, queue_index) ||
8988 : 0 : ((conf = mlx5_rxq_get_hairpin_conf(dev, queue_index)) != NULL &&
8989 [ # # ]: 0 : conf->tx_explicit != 0))) {
8990 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
8991 : : MLX5_FLOW_XCAP_ACTIONS)
8992 : 0 : return rte_flow_error_set(error, ENOTSUP,
8993 : : RTE_FLOW_ERROR_TYPE_ACTION,
8994 : : NULL, "encap and decap "
8995 : : "combination aren't supported");
8996 : : /* Push VLAN is not supported in ingress except for NICs newer than CX5. */
8997 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) {
8998 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
8999 : : bool direction_error = false;
9000 : :
9001 [ # # ]: 0 : if (attr->transfer) {
9002 [ # # ]: 0 : bool fdb_tx = flow_source_vport_representor(priv, act_priv);
9003 : 0 : bool is_cx5 = sh->steering_format_version ==
9004 : : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5;
9005 : :
9006 [ # # ]: 0 : if (!fdb_tx && is_cx5)
9007 : : direction_error = true;
9008 [ # # ]: 0 : } else if (attr->ingress) {
9009 : : direction_error = true;
9010 : : }
9011 : : if (direction_error)
9012 : 0 : return rte_flow_error_set(error, ENOTSUP,
9013 : : RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
9014 : : NULL,
9015 : : "push VLAN action not supported "
9016 : : "for ingress");
9017 : : }
9018 [ # # ]: 0 : if (attr->ingress) {
9019 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
9020 : 0 : return rte_flow_error_set
9021 : : (error, ENOTSUP,
9022 : : RTE_FLOW_ERROR_TYPE_ACTION,
9023 : : NULL, "encap is not supported"
9024 : : " for ingress traffic");
9025 [ # # ]: 0 : else if ((action_flags & MLX5_FLOW_VLAN_ACTIONS) ==
9026 : : MLX5_FLOW_VLAN_ACTIONS)
9027 : 0 : return rte_flow_error_set
9028 : : (error, ENOTSUP,
9029 : : RTE_FLOW_ERROR_TYPE_ACTION,
9030 : : NULL, "no support for "
9031 : : "multiple VLAN actions");
9032 : : }
9033 : : }
9034 : : /* Pop VLAN is not supported in egress except for NICs newer than CX5. */
9035 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_POP_VLAN) {
9036 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
9037 : : bool direction_error = false;
9038 : :
9039 [ # # ]: 0 : if (attr->transfer) {
9040 [ # # ]: 0 : bool fdb_tx = flow_source_vport_representor(priv, act_priv);
9041 : 0 : bool is_cx5 = sh->steering_format_version ==
9042 : : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5;
9043 : :
9044 [ # # ]: 0 : if (fdb_tx && is_cx5)
9045 : : direction_error = true;
9046 [ # # ]: 0 : } else if (attr->egress) {
9047 : : direction_error = true;
9048 : : }
9049 : : if (direction_error)
9050 : 0 : return rte_flow_error_set(error, ENOTSUP,
9051 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
9052 : : NULL,
9053 : : "pop vlan action not supported for egress");
9054 : : }
9055 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY) {
9056 [ # # ]: 0 : if ((action_flags & (MLX5_FLOW_FATE_ACTIONS &
9057 [ # # ]: 0 : ~MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)) &&
9058 : : attr->ingress)
9059 : 0 : return rte_flow_error_set
9060 : : (error, ENOTSUP,
9061 : : RTE_FLOW_ERROR_TYPE_ACTION,
9062 : : NULL, "fate action not supported for "
9063 : : "meter with policy");
9064 [ # # ]: 0 : if (attr->egress) {
9065 [ # # ]: 0 : if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
9066 : 0 : return rte_flow_error_set
9067 : : (error, ENOTSUP,
9068 : : RTE_FLOW_ERROR_TYPE_ACTION,
9069 : : NULL, "modify header action in egress "
9070 : : "cannot be done before meter action");
9071 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
9072 : 0 : return rte_flow_error_set
9073 : : (error, ENOTSUP,
9074 : : RTE_FLOW_ERROR_TYPE_ACTION,
9075 : : NULL, "encap action in egress "
9076 : : "cannot be done before meter action");
9077 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
9078 : 0 : return rte_flow_error_set
9079 : : (error, ENOTSUP,
9080 : : RTE_FLOW_ERROR_TYPE_ACTION,
9081 : : NULL, "push vlan action in egress "
9082 : : "cannot be done before meter action");
9083 : : }
9084 : : }
9085 : : /*
9086 : : * Only support one ASO action in a single flow rule.
9087 : : * non-shared AGE + counter will fallback to use HW counter, no ASO hit object.
9088 : : * Group 0 uses HW counter for AGE too even if no counter action.
9089 : : */
9090 [ # # # # ]: 0 : aso_mask = (action_flags & MLX5_FLOW_ACTION_METER && priv->sh->meter_aso_en) << 2 |
9091 [ # # # # : 0 : (action_flags & MLX5_FLOW_ACTION_CT && priv->sh->ct_aso_en) << 1 |
# # ]
9092 : 0 : (action_flags & MLX5_FLOW_ACTION_AGE &&
9093 [ # # ]: 0 : !(non_shared_age && count) &&
9094 [ # # # # : 0 : (attr->group || (attr->transfer && priv->fdb_def_rule)) &&
# # # # ]
9095 [ # # ]: 0 : priv->sh->flow_hit_aso_en);
9096 [ # # ]: 0 : if (rte_popcount64(aso_mask) > 1)
9097 : 0 : return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
9098 : : NULL, "unsupported combining AGE, METER, CT ASO actions in a single rule");
9099 : : /*
9100 : : * Hairpin flow will add one more TAG action in TX implicit mode.
9101 : : * In TX explicit mode, there will be no hairpin flow ID.
9102 : : */
9103 [ # # ]: 0 : if (hairpin > 0)
9104 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
9105 : : /* extra metadata enabled: one more TAG action will be add. */
9106 [ # # ]: 0 : if (dev_conf->dv_flow_en &&
9107 [ # # # # ]: 0 : dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
9108 : 0 : mlx5_flow_ext_mreg_supported(dev))
9109 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
9110 [ # # ]: 0 : if (rw_act_num >
9111 : : flow_dv_modify_hdr_action_max(dev, is_root)) {
9112 : 0 : return rte_flow_error_set(error, ENOTSUP,
9113 : : RTE_FLOW_ERROR_TYPE_ACTION,
9114 : : NULL, "too many header modify"
9115 : : " actions to support");
9116 : : }
9117 [ # # ]: 0 : if (fdb_mirror) {
9118 [ # # # # ]: 0 : if (!priv->sh->cdev->config.hca_attr.reg_c_preserve &&
9119 [ # # ]: 0 : flow_source_vport_representor(priv, act_priv)) {
9120 : : /* Eswitch egress mirror and modify flow has limitation on CX5 */
9121 [ # # ]: 0 : if (modify_after_mirror)
9122 : 0 : return rte_flow_error_set(error, EINVAL,
9123 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9124 : : "sample before modify action is not supported");
9125 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_JUMP)
9126 : 0 : return rte_flow_error_set(error, EINVAL,
9127 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9128 : : "sample and jump action combination is not supported");
9129 : : }
9130 [ # # ]: 0 : if (aso_mask > 0 && aso_after_sample && fdb_mirror)
9131 : 0 : return rte_flow_error_set(error, ENOTSUP,
9132 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9133 : : "sample before ASO action is not supported");
9134 [ # # ]: 0 : if (sub_action_flags & MLX5_FLOW_ACTION_PORT_ID) {
9135 : 0 : port_priv = mlx5_port_to_eswitch_info(sample_port_id, false);
9136 [ # # ]: 0 : if (flow_source_vport_representor(priv, port_priv)) {
9137 [ # # ]: 0 : if (sub_action_flags & MLX5_FLOW_ACTION_ENCAP)
9138 : 0 : return rte_flow_error_set(error, ENOTSUP,
9139 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9140 : : "mirror to rep port with encap is not supported");
9141 : : } else {
9142 [ # # ]: 0 : if (!(sub_action_flags & MLX5_FLOW_ACTION_ENCAP) &&
9143 [ # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_JUMP))
9144 : 0 : return rte_flow_error_set(error, ENOTSUP,
9145 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9146 : : "mirror to wire port without encap is not supported");
9147 : : }
9148 : : }
9149 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_PORT_ID) &&
9150 : : (action_flags & MLX5_FLOW_ACTION_ENCAP)) {
9151 : 0 : port_priv = mlx5_port_to_eswitch_info(port_id, false);
9152 [ # # ]: 0 : if (flow_source_vport_representor(priv, port_priv))
9153 : 0 : return rte_flow_error_set(error, ENOTSUP,
9154 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9155 : : "mirror to rep port with encap is not supported");
9156 : : }
9157 : : }
9158 : : /*
9159 : : * Validation the NIC Egress flow on representor, except implicit
9160 : : * hairpin default egress flow with TX_QUEUE item, other flows not
9161 : : * work due to metadata regC0 mismatch.
9162 : : */
9163 [ # # # # : 0 : if (attr->egress && priv->representor && !(item_flags & MLX5_FLOW_ITEM_SQ))
# # ]
9164 : 0 : return rte_flow_error_set(error, EINVAL,
9165 : : RTE_FLOW_ERROR_TYPE_ITEM,
9166 : : NULL,
9167 : : "NIC egress rules on representors"
9168 : : " is not supported");
9169 : : return 0;
9170 : : }
9171 : :
9172 : : /**
9173 : : * Internal preparation function. Allocates the DV flow size,
9174 : : * this size is constant.
9175 : : *
9176 : : * @param[in] dev
9177 : : * Pointer to the rte_eth_dev structure.
9178 : : * @param[in] attr
9179 : : * Pointer to the flow attributes.
9180 : : * @param[in] items
9181 : : * Pointer to the list of items.
9182 : : * @param[in] actions
9183 : : * Pointer to the list of actions.
9184 : : * @param[out] error
9185 : : * Pointer to the error structure.
9186 : : *
9187 : : * @return
9188 : : * Pointer to mlx5_flow object on success,
9189 : : * otherwise NULL and rte_errno is set.
9190 : : */
9191 : : static struct mlx5_flow *
9192 : 0 : flow_dv_prepare(struct rte_eth_dev *dev,
9193 : : const struct rte_flow_attr *attr __rte_unused,
9194 : : const struct rte_flow_item items[] __rte_unused,
9195 : : const struct rte_flow_action actions[] __rte_unused,
9196 : : struct rte_flow_error *error)
9197 : : {
9198 : 0 : uint32_t handle_idx = 0;
9199 : : struct mlx5_flow *dev_flow;
9200 : : struct mlx5_flow_handle *dev_handle;
9201 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
9202 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
9203 : :
9204 : : MLX5_ASSERT(wks);
9205 : 0 : wks->skip_matcher_reg = 0;
9206 : 0 : wks->policy = NULL;
9207 : 0 : wks->final_policy = NULL;
9208 : 0 : wks->vport_meta_tag = 0;
9209 : : /* In case of corrupting the memory. */
9210 [ # # ]: 0 : if (wks->flow_idx >= MLX5_NUM_MAX_DEV_FLOWS) {
9211 : 0 : rte_flow_error_set(error, ENOSPC,
9212 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9213 : : "not free temporary device flow");
9214 : 0 : return NULL;
9215 : : }
9216 : 0 : dev_handle = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
9217 : : &handle_idx);
9218 [ # # ]: 0 : if (!dev_handle) {
9219 : 0 : rte_flow_error_set(error, ENOMEM,
9220 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9221 : : "not enough memory to create flow handle");
9222 : 0 : return NULL;
9223 : : }
9224 : : MLX5_ASSERT(wks->flow_idx < RTE_DIM(wks->flows));
9225 : 0 : dev_flow = &wks->flows[wks->flow_idx++];
9226 : : memset(dev_flow, 0, sizeof(*dev_flow));
9227 : 0 : dev_flow->handle = dev_handle;
9228 : 0 : dev_flow->handle_idx = handle_idx;
9229 : 0 : dev_flow->dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param);
9230 : 0 : dev_flow->ingress = attr->ingress;
9231 : 0 : dev_flow->dv.transfer = attr->transfer;
9232 : 0 : return dev_flow;
9233 : : }
9234 : :
9235 : : #ifdef RTE_LIBRTE_MLX5_DEBUG
9236 : : /**
9237 : : * Sanity check for match mask and value. Similar to check_valid_spec() in
9238 : : * kernel driver. If unmasked bit is present in value, it returns failure.
9239 : : *
9240 : : * @param match_mask
9241 : : * pointer to match mask buffer.
9242 : : * @param match_value
9243 : : * pointer to match value buffer.
9244 : : *
9245 : : * @return
9246 : : * 0 if valid, -EINVAL otherwise.
9247 : : */
9248 : : static int
9249 : : flow_dv_check_valid_spec(void *match_mask, void *match_value)
9250 : : {
9251 : : uint8_t *m = match_mask;
9252 : : uint8_t *v = match_value;
9253 : : unsigned int i;
9254 : :
9255 : : for (i = 0; i < MLX5_ST_SZ_BYTES(fte_match_param); ++i) {
9256 : : if (v[i] & ~m[i]) {
9257 : : DRV_LOG(ERR,
9258 : : "match_value differs from match_criteria"
9259 : : " %p[%u] != %p[%u]",
9260 : : match_value, i, match_mask, i);
9261 : : return -EINVAL;
9262 : : }
9263 : : }
9264 : : return 0;
9265 : : }
9266 : : #endif
9267 : :
9268 : : /**
9269 : : * Add match of ip_version.
9270 : : *
9271 : : * @param[in] group
9272 : : * Flow group.
9273 : : * @param[in] headers_v
9274 : : * Values header pointer.
9275 : : * @param[in] headers_m
9276 : : * Masks header pointer.
9277 : : * @param[in] ip_version
9278 : : * The IP version to set.
9279 : : */
9280 : : static inline void
9281 : 0 : flow_dv_set_match_ip_version(uint32_t group,
9282 : : void *headers_v,
9283 : : uint32_t key_type,
9284 : : uint8_t ip_version)
9285 : : {
9286 [ # # # # ]: 0 : if (group == 0 && (key_type & MLX5_SET_MATCHER_M))
9287 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version, 0xf);
9288 : : else
9289 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version,
9290 : : ip_version);
9291 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype, 0);
9292 : 0 : }
9293 : :
9294 : : /**
9295 : : * Add Ethernet item to the value.
9296 : : *
9297 : : * @param[in, out] key
9298 : : * Flow matcher value.
9299 : : * @param[in] item
9300 : : * Flow pattern to translate.
9301 : : * @param[in] inner
9302 : : * Item is inner pattern.
9303 : : * @param[in] grpup
9304 : : * Flow matcher group.
9305 : : * @param[in] key_type
9306 : : * Set flow matcher mask or value.
9307 : : */
9308 : : static void
9309 : 0 : flow_dv_translate_item_eth(void *key, const struct rte_flow_item *item,
9310 : : int inner, uint32_t group, uint32_t key_type)
9311 : : {
9312 : 0 : const struct rte_flow_item_eth *eth_vv = item->spec;
9313 : : const struct rte_flow_item_eth *eth_m;
9314 : : const struct rte_flow_item_eth *eth_v;
9315 : 0 : const struct rte_flow_item_eth nic_mask = {
9316 : : .hdr.dst_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
9317 : : .hdr.src_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
9318 : : .hdr.ether_type = RTE_BE16(0xffff),
9319 : : .has_vlan = 0,
9320 : : };
9321 : : void *hdrs_v;
9322 : : char *l24_v;
9323 : : unsigned int i;
9324 : :
9325 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9326 : 0 : return;
9327 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, eth_v, eth_m, &nic_mask);
# # # # ]
9328 [ # # ]: 0 : if (!eth_vv)
9329 : : eth_vv = eth_v;
9330 [ # # ]: 0 : if (inner)
9331 : 0 : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9332 : : else
9333 : : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9334 : : /* The value must be in the range of the mask. */
9335 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, dmac_47_16);
9336 [ # # ]: 0 : for (i = 0; i < sizeof(eth_m->hdr.dst_addr); ++i)
9337 : 0 : l24_v[i] = eth_m->hdr.dst_addr.addr_bytes[i] & eth_v->hdr.dst_addr.addr_bytes[i];
9338 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, smac_47_16);
9339 : : /* The value must be in the range of the mask. */
9340 [ # # ]: 0 : for (i = 0; i < sizeof(eth_m->hdr.dst_addr); ++i)
9341 : 0 : l24_v[i] = eth_m->hdr.src_addr.addr_bytes[i] & eth_v->hdr.src_addr.addr_bytes[i];
9342 : : /*
9343 : : * HW supports match on one Ethertype, the Ethertype following the last
9344 : : * VLAN tag of the packet (see PRM).
9345 : : * Set match on ethertype only if ETH header is not followed by VLAN.
9346 : : * HW is optimized for IPv4/IPv6. In such cases, avoid setting
9347 : : * ethertype, and use ip_version field instead.
9348 : : * eCPRI over Ether layer will use type value 0xAEFE.
9349 : : */
9350 [ # # ]: 0 : if (eth_m->hdr.ether_type == 0xFFFF) {
9351 : 0 : rte_be16_t type = eth_v->hdr.ether_type;
9352 : :
9353 : : /*
9354 : : * When set the matcher mask, refer to the original spec
9355 : : * value.
9356 : : */
9357 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M) {
9358 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
9359 : 0 : type = eth_vv->hdr.ether_type;
9360 : : }
9361 : : /* Set cvlan_tag mask for any single\multi\un-tagged case. */
9362 [ # # # # : 0 : switch (type) {
# ]
9363 : 0 : case RTE_BE16(RTE_ETHER_TYPE_VLAN):
9364 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
9365 : 0 : return;
9366 : 0 : case RTE_BE16(RTE_ETHER_TYPE_QINQ):
9367 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
9368 : 0 : return;
9369 : 0 : case RTE_BE16(RTE_ETHER_TYPE_IPV4):
9370 : 0 : flow_dv_set_match_ip_version(group, hdrs_v, key_type,
9371 : : 4);
9372 : 0 : return;
9373 : 0 : case RTE_BE16(RTE_ETHER_TYPE_IPV6):
9374 : 0 : flow_dv_set_match_ip_version(group, hdrs_v, key_type,
9375 : : 6);
9376 : 0 : return;
9377 : : default:
9378 : : break;
9379 : : }
9380 : : }
9381 : : /*
9382 : : * Only SW steering value should refer to the mask value.
9383 : : * Other cases are using the fake masks, just ignore the mask.
9384 : : */
9385 [ # # # # ]: 0 : if (eth_v->has_vlan && eth_m->has_vlan) {
9386 : : /*
9387 : : * Here, when also has_more_vlan field in VLAN item is
9388 : : * not set, only single-tagged packets will be matched.
9389 : : */
9390 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
9391 [ # # # # ]: 0 : if (key_type != MLX5_SET_MATCHER_HS_M && eth_vv->has_vlan)
9392 : : return;
9393 : : }
9394 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, ethertype);
9395 : 0 : *(uint16_t *)(l24_v) = eth_m->hdr.ether_type & eth_v->hdr.ether_type;
9396 : : }
9397 : :
9398 : : /**
9399 : : * Add VLAN item to the value.
9400 : : *
9401 : : * @param[in, out] key
9402 : : * Flow matcher value.
9403 : : * @param[in] item
9404 : : * Flow pattern to translate.
9405 : : * @param[in] inner
9406 : : * Item is inner pattern.
9407 : : * @param[in] wks
9408 : : * Item workspace.
9409 : : * @param[in] key_type
9410 : : * Set flow matcher mask or value.
9411 : : */
9412 : : static void
9413 : 0 : flow_dv_translate_item_vlan(void *key, const struct rte_flow_item *item,
9414 : : int inner, struct mlx5_dv_matcher_workspace *wks,
9415 : : uint32_t key_type)
9416 : : {
9417 : : const struct rte_flow_item_vlan *vlan_m;
9418 : : const struct rte_flow_item_vlan *vlan_v;
9419 : 0 : const struct rte_flow_item_vlan *vlan_vv = item->spec;
9420 : : void *hdrs_v;
9421 : : uint16_t tci_v;
9422 : :
9423 [ # # ]: 0 : if (inner) {
9424 : 0 : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9425 : : } else {
9426 : : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9427 : : /*
9428 : : * This is workaround, masks are not supported,
9429 : : * and pre-validated.
9430 : : */
9431 [ # # ]: 0 : if (vlan_vv)
9432 [ # # ]: 0 : wks->vlan_tag = rte_be_to_cpu_16(vlan_vv->hdr.vlan_tci) & 0x0fff;
9433 : : }
9434 : : /*
9435 : : * When VLAN item exists in flow, mark packet as tagged,
9436 : : * even if TCI is not specified.
9437 : : */
9438 [ # # # # ]: 0 : if (!MLX5_GET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag))
9439 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
9440 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9441 : : return;
9442 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, vlan_v, vlan_m,
# # # # ]
9443 : : &rte_flow_item_vlan_mask);
9444 [ # # ]: 0 : tci_v = rte_be_to_cpu_16(vlan_m->hdr.vlan_tci & vlan_v->hdr.vlan_tci);
9445 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_vid, tci_v);
9446 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_cfi, tci_v >> 12);
9447 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_prio, tci_v >> 13);
9448 : : /*
9449 : : * HW is optimized for IPv4/IPv6. In such cases, avoid setting
9450 : : * ethertype, and use ip_version field instead.
9451 : : */
9452 [ # # ]: 0 : if (vlan_m->hdr.eth_proto == 0xFFFF) {
9453 : 0 : rte_be16_t inner_type = vlan_v->hdr.eth_proto;
9454 : :
9455 : : /*
9456 : : * When set the matcher mask, refer to the original spec
9457 : : * value.
9458 : : */
9459 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M)
9460 : 0 : inner_type = vlan_vv->hdr.eth_proto;
9461 [ # # # # ]: 0 : switch (inner_type) {
9462 : 0 : case RTE_BE16(RTE_ETHER_TYPE_VLAN):
9463 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
9464 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_V)
9465 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v,
9466 : : cvlan_tag, 0);
9467 : 0 : return;
9468 : 0 : case RTE_BE16(RTE_ETHER_TYPE_IPV4):
9469 : 0 : flow_dv_set_match_ip_version
9470 : : (wks->group, hdrs_v, key_type, 4);
9471 : 0 : return;
9472 : 0 : case RTE_BE16(RTE_ETHER_TYPE_IPV6):
9473 : 0 : flow_dv_set_match_ip_version
9474 : : (wks->group, hdrs_v, key_type, 6);
9475 : 0 : return;
9476 : : default:
9477 : : break;
9478 : : }
9479 : : }
9480 [ # # # # ]: 0 : if (vlan_m->has_more_vlan && vlan_v->has_more_vlan) {
9481 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
9482 : : /* Only one vlan_tag bit can be set. */
9483 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_V)
9484 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 0);
9485 : 0 : return;
9486 : : }
9487 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, ethertype,
9488 : : rte_be_to_cpu_16(vlan_m->hdr.eth_proto & vlan_v->hdr.eth_proto));
9489 : : }
9490 : :
9491 : : /**
9492 : : * Add IPV4 item to the value.
9493 : : *
9494 : : * @param[in, out] key
9495 : : * Flow matcher value.
9496 : : * @param[in] item
9497 : : * Flow pattern to translate.
9498 : : * @param[in] inner
9499 : : * Item is inner pattern.
9500 : : * @param[in] group
9501 : : * The group to insert the rule.
9502 : : * @param[in] key_type
9503 : : * Set flow matcher mask or value.
9504 : : */
9505 : : static void
9506 : 0 : flow_dv_translate_item_ipv4(void *key, const struct rte_flow_item *item,
9507 : : int inner, uint32_t group, uint32_t key_type)
9508 : : {
9509 : : const struct rte_flow_item_ipv4 *ipv4_m;
9510 : : const struct rte_flow_item_ipv4 *ipv4_v;
9511 : 0 : const struct rte_flow_item_ipv4 nic_mask = {
9512 : : .hdr = {
9513 : : .src_addr = RTE_BE32(0xffffffff),
9514 : : .dst_addr = RTE_BE32(0xffffffff),
9515 : : .type_of_service = 0xff,
9516 : : .next_proto_id = 0xff,
9517 : : .time_to_live = 0xff,
9518 : : },
9519 : : };
9520 : : void *headers_v;
9521 : : char *l24_v;
9522 : : uint8_t tos;
9523 : :
9524 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9525 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9526 : 0 : flow_dv_set_match_ip_version(group, headers_v, key_type, 4);
9527 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9528 : 0 : return;
9529 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, ipv4_v, ipv4_m, &nic_mask);
# # # # ]
9530 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
9531 : : dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
9532 : 0 : *(uint32_t *)l24_v = ipv4_m->hdr.dst_addr & ipv4_v->hdr.dst_addr;
9533 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
9534 : : src_ipv4_src_ipv6.ipv4_layout.ipv4);
9535 : 0 : *(uint32_t *)l24_v = ipv4_m->hdr.src_addr & ipv4_v->hdr.src_addr;
9536 : 0 : tos = ipv4_m->hdr.type_of_service & ipv4_v->hdr.type_of_service;
9537 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ipv4_ihl,
9538 : : ipv4_v->hdr.ihl & ipv4_m->hdr.ihl);
9539 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M)
9540 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn,
9541 : : ipv4_v->hdr.type_of_service);
9542 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, tos);
9543 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, tos >> 2);
9544 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
9545 : : ipv4_v->hdr.next_proto_id & ipv4_m->hdr.next_proto_id);
9546 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
9547 : : ipv4_v->hdr.time_to_live & ipv4_m->hdr.time_to_live);
9548 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
9549 : : !!(ipv4_v->hdr.fragment_offset & ipv4_m->hdr.fragment_offset));
9550 : : }
9551 : :
9552 : : /**
9553 : : * Add IPV6 item to the value.
9554 : : *
9555 : : * @param[in, out] key
9556 : : * Flow matcher value.
9557 : : * @param[in] item
9558 : : * Flow pattern to translate.
9559 : : * @param[in] inner
9560 : : * Item is inner pattern.
9561 : : * @param[in] group
9562 : : * The group to insert the rule.
9563 : : * @param[in] key_type
9564 : : * Set flow matcher mask or value.
9565 : : */
9566 : : static void
9567 : 0 : flow_dv_translate_item_ipv6(void *key, const struct rte_flow_item *item,
9568 : : int inner, uint32_t group, uint32_t key_type)
9569 : : {
9570 : : const struct rte_flow_item_ipv6 *ipv6_m;
9571 : : const struct rte_flow_item_ipv6 *ipv6_v;
9572 : 0 : const struct rte_flow_item_ipv6 nic_mask = {
9573 : : .hdr = {
9574 : : .src_addr = RTE_IPV6_MASK_FULL,
9575 : : .dst_addr = RTE_IPV6_MASK_FULL,
9576 : : .vtc_flow = RTE_BE32(0xffffffff),
9577 : : .proto = 0xff,
9578 : : .hop_limits = 0xff,
9579 : : },
9580 : : };
9581 : : void *headers_v;
9582 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9583 : : char *l24_v;
9584 : : uint32_t vtc_v;
9585 : : int i;
9586 : : int size;
9587 : :
9588 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9589 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9590 : 0 : flow_dv_set_match_ip_version(group, headers_v, key_type, 6);
9591 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9592 : 0 : return;
9593 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, ipv6_v, ipv6_m, &nic_mask);
# # # # ]
9594 : : size = sizeof(ipv6_m->hdr.dst_addr);
9595 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
9596 : : dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
9597 [ # # ]: 0 : for (i = 0; i < size; ++i)
9598 : 0 : l24_v[i] = ipv6_m->hdr.dst_addr.a[i] & ipv6_v->hdr.dst_addr.a[i];
9599 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
9600 : : src_ipv4_src_ipv6.ipv6_layout.ipv6);
9601 [ # # ]: 0 : for (i = 0; i < size; ++i)
9602 : 0 : l24_v[i] = ipv6_m->hdr.src_addr.a[i] & ipv6_v->hdr.src_addr.a[i];
9603 : : /* TOS. */
9604 [ # # ]: 0 : vtc_v = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow & ipv6_v->hdr.vtc_flow);
9605 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, vtc_v >> 20);
9606 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, vtc_v >> 22);
9607 : : /* Label. */
9608 [ # # ]: 0 : if (inner)
9609 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, inner_ipv6_flow_label,
9610 : : vtc_v);
9611 : : else
9612 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, outer_ipv6_flow_label,
9613 : : vtc_v);
9614 : : /* Protocol. */
9615 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
9616 : : ipv6_v->hdr.proto & ipv6_m->hdr.proto);
9617 : : /* Hop limit. */
9618 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
9619 : : ipv6_v->hdr.hop_limits & ipv6_m->hdr.hop_limits);
9620 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
9621 : : !!(ipv6_v->has_frag_ext & ipv6_m->has_frag_ext));
9622 : : }
9623 : :
9624 : : /**
9625 : : * Add IPV6 fragment extension item to the value.
9626 : : *
9627 : : * @param[in, out] key
9628 : : * Flow matcher value.
9629 : : * @param[in] item
9630 : : * Flow pattern to translate.
9631 : : * @param[in] inner
9632 : : * Item is inner pattern.
9633 : : * @param[in] key_type
9634 : : * Set flow matcher mask or value.
9635 : : */
9636 : : static void
9637 : 0 : flow_dv_translate_item_ipv6_frag_ext(void *key,
9638 : : const struct rte_flow_item *item,
9639 : : int inner, uint32_t key_type)
9640 : : {
9641 : : const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_m;
9642 : : const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_v;
9643 : 0 : const struct rte_flow_item_ipv6_frag_ext nic_mask = {
9644 : : .hdr = {
9645 : : .next_header = 0xff,
9646 : : .frag_data = RTE_BE16(0xffff),
9647 : : },
9648 : : };
9649 : : void *headers_v;
9650 : :
9651 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9652 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9653 : : /* IPv6 fragment extension item exists, so packet is IP fragment. */
9654 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag, 1);
9655 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9656 : 0 : return;
9657 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, ipv6_frag_ext_v,
# # # # ]
9658 : : ipv6_frag_ext_m, &nic_mask);
9659 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
9660 : : ipv6_frag_ext_v->hdr.next_header &
9661 : : ipv6_frag_ext_m->hdr.next_header);
9662 : : }
9663 : :
9664 : : /**
9665 : : * Add TCP item to the value.
9666 : : *
9667 : : * @param[in, out] key
9668 : : * Flow matcher value.
9669 : : * @param[in] item
9670 : : * Flow pattern to translate.
9671 : : * @param[in] inner
9672 : : * Item is inner pattern.
9673 : : * @param[in] key_type
9674 : : * Set flow matcher mask or value.
9675 : : */
9676 : : static void
9677 : 0 : flow_dv_translate_item_tcp(void *key, const struct rte_flow_item *item,
9678 : : int inner, uint32_t key_type)
9679 : : {
9680 : : const struct rte_flow_item_tcp *tcp_m;
9681 : : const struct rte_flow_item_tcp *tcp_v;
9682 : : void *headers_v;
9683 : :
9684 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9685 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9686 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9687 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9688 : : ip_protocol, 0xff);
9689 : : else
9690 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9691 : : ip_protocol, IPPROTO_TCP);
9692 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9693 : : return;
9694 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, tcp_v, tcp_m,
# # # # ]
9695 : : &rte_flow_item_tcp_mask);
9696 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_sport,
9697 : : rte_be_to_cpu_16(tcp_v->hdr.src_port & tcp_m->hdr.src_port));
9698 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_dport,
9699 : : rte_be_to_cpu_16(tcp_v->hdr.dst_port & tcp_m->hdr.dst_port));
9700 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_flags,
9701 : : tcp_v->hdr.tcp_flags & tcp_m->hdr.tcp_flags);
9702 : : }
9703 : :
9704 : : /**
9705 : : * Add ESP item to the value.
9706 : : *
9707 : : * @param[in, out] key
9708 : : * Flow matcher value.
9709 : : * @param[in] item
9710 : : * Flow pattern to translate.
9711 : : * @param[in] inner
9712 : : * Item is inner pattern.
9713 : : * @param[in] key_type
9714 : : * Set flow matcher mask or value.
9715 : : */
9716 : : static void
9717 : 0 : flow_dv_translate_item_esp(void *key, const struct rte_flow_item *item,
9718 : : int inner, uint32_t key_type)
9719 : : {
9720 : : const struct rte_flow_item_esp *esp_m;
9721 : : const struct rte_flow_item_esp *esp_v;
9722 : : void *headers_v;
9723 : : char *spi_v;
9724 : :
9725 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9726 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9727 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9728 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9729 : : ip_protocol, 0xff);
9730 : : else
9731 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9732 : : ip_protocol, IPPROTO_ESP);
9733 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9734 : : return;
9735 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, esp_v, esp_m,
# # # # ]
9736 : : &rte_flow_item_esp_mask);
9737 : : headers_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9738 : : spi_v = inner ? MLX5_ADDR_OF(fte_match_set_misc, headers_v,
9739 [ # # ]: 0 : inner_esp_spi) : MLX5_ADDR_OF(fte_match_set_misc
9740 : : , headers_v, outer_esp_spi);
9741 : 0 : *(uint32_t *)spi_v = esp_m->hdr.spi & esp_v->hdr.spi;
9742 : : }
9743 : :
9744 : : /**
9745 : : * Add UDP item to the value.
9746 : : *
9747 : : * @param[in, out] key
9748 : : * Flow matcher value.
9749 : : * @param[in] item
9750 : : * Flow pattern to translate.
9751 : : * @param[in] inner
9752 : : * Item is inner pattern.
9753 : : * @param[in] key_type
9754 : : * Set flow matcher mask or value.
9755 : : */
9756 : : static void
9757 : 0 : flow_dv_translate_item_udp(void *key, const struct rte_flow_item *item,
9758 : : int inner, struct mlx5_dv_matcher_workspace *wks,
9759 : : uint32_t key_type)
9760 : : {
9761 : : const struct rte_flow_item_udp *udp_m;
9762 : : const struct rte_flow_item_udp *udp_v;
9763 : : void *headers_v;
9764 : :
9765 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9766 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9767 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9768 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9769 : : ip_protocol, 0xff);
9770 : : else
9771 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9772 : : ip_protocol, IPPROTO_UDP);
9773 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9774 : : return;
9775 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, udp_v, udp_m,
# # # # ]
9776 : : &rte_flow_item_udp_mask);
9777 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_sport,
9778 : : rte_be_to_cpu_16(udp_v->hdr.src_port & udp_m->hdr.src_port));
9779 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
9780 : : rte_be_to_cpu_16(udp_v->hdr.dst_port & udp_m->hdr.dst_port));
9781 : : /* Force get UDP dport in case to be used in VXLAN translate. */
9782 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_SW) {
9783 : 0 : udp_v = item->spec;
9784 [ # # ]: 0 : wks->udp_dport = rte_be_to_cpu_16(udp_v->hdr.dst_port &
9785 : : udp_m->hdr.dst_port);
9786 : : }
9787 : : }
9788 : :
9789 : : /**
9790 : : * Add GRE optional Key item to the value.
9791 : : *
9792 : : * @param[in, out] key
9793 : : * Flow matcher value.
9794 : : * @param[in] item
9795 : : * Flow pattern to translate.
9796 : : * @param[in] inner
9797 : : * Item is inner pattern.
9798 : : */
9799 : : static void
9800 : 0 : flow_dv_translate_item_gre_key(void *key, const struct rte_flow_item *item,
9801 : : uint32_t key_type)
9802 : : {
9803 : : const rte_be32_t *key_m;
9804 : : const rte_be32_t *key_v;
9805 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9806 : 0 : rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
9807 : :
9808 : : /* GRE K bit must be on and should already be validated */
9809 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_k_present, 1);
9810 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9811 : 0 : return;
9812 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, key_v, key_m,
# # # # ]
9813 : : &gre_key_default_mask);
9814 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_key_h,
9815 : : rte_be_to_cpu_32((*key_v) & (*key_m)) >> 8);
9816 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_key_l,
9817 : : rte_be_to_cpu_32((*key_v) & (*key_m)) & 0xFF);
9818 : : }
9819 : :
9820 : : /**
9821 : : * Add GRE item to the value.
9822 : : *
9823 : : * @param[in, out] key
9824 : : * Flow matcher value.
9825 : : * @param[in] item
9826 : : * Flow pattern to translate.
9827 : : * @param[in] pattern_flags
9828 : : * Accumulated pattern flags.
9829 : : * @param[in] key_type
9830 : : * Set flow matcher mask or value.
9831 : : */
9832 : : static void
9833 : 0 : flow_dv_translate_item_gre(void *key, const struct rte_flow_item *item,
9834 : : uint64_t pattern_flags, uint32_t key_type)
9835 : : {
9836 : : static const struct rte_flow_item_gre empty_gre = {0,};
9837 : 0 : const struct rte_flow_item_gre *gre_m = item->mask;
9838 : 0 : const struct rte_flow_item_gre *gre_v = item->spec;
9839 : : void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9840 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9841 : : struct {
9842 : : union {
9843 : : __extension__
9844 : : struct {
9845 : : uint16_t version:3;
9846 : : uint16_t rsvd0:9;
9847 : : uint16_t s_present:1;
9848 : : uint16_t k_present:1;
9849 : : uint16_t rsvd_bit1:1;
9850 : : uint16_t c_present:1;
9851 : : };
9852 : : uint16_t value;
9853 : : };
9854 : : } gre_crks_rsvd0_ver_m, gre_crks_rsvd0_ver_v;
9855 : : uint16_t protocol_m, protocol_v;
9856 : :
9857 : : /* Common logic to SWS/HWS */
9858 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9859 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, 0xff);
9860 : : else
9861 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
9862 : : IPPROTO_GRE);
9863 : : /* HWS mask logic only */
9864 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_HS_M) {
9865 [ # # ]: 0 : if (!gre_m)
9866 : : gre_m = &empty_gre;
9867 : : gre_v = gre_m;
9868 [ # # ]: 0 : } else if (!gre_v) {
9869 : : gre_v = &empty_gre;
9870 : : gre_m = &empty_gre;
9871 [ # # ]: 0 : } else if (!gre_m) {
9872 : : gre_m = &rte_flow_item_gre_mask;
9873 : : }
9874 : : /* SWS logic only */
9875 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_SW_M)
9876 : : gre_v = gre_m;
9877 [ # # ]: 0 : gre_crks_rsvd0_ver_m.value = rte_be_to_cpu_16(gre_m->c_rsvd0_ver);
9878 [ # # ]: 0 : gre_crks_rsvd0_ver_v.value = rte_be_to_cpu_16(gre_v->c_rsvd0_ver);
9879 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_c_present,
9880 : : gre_crks_rsvd0_ver_v.c_present &
9881 : : gre_crks_rsvd0_ver_m.c_present);
9882 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_k_present,
9883 : : gre_crks_rsvd0_ver_v.k_present &
9884 : : gre_crks_rsvd0_ver_m.k_present);
9885 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_s_present,
9886 : : gre_crks_rsvd0_ver_v.s_present &
9887 : : gre_crks_rsvd0_ver_m.s_present);
9888 [ # # ]: 0 : protocol_m = rte_be_to_cpu_16(gre_m->protocol);
9889 [ # # ]: 0 : protocol_v = rte_be_to_cpu_16(gre_v->protocol);
9890 [ # # ]: 0 : if (!protocol_m) {
9891 : : /* Force next protocol to prevent matchers duplication */
9892 : : protocol_v = mlx5_translate_tunnel_etypes(pattern_flags);
9893 : : if (protocol_v)
9894 : : protocol_m = 0xFFFF;
9895 : : /* Restore the value to mask in mask case. */
9896 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9897 : : protocol_v = protocol_m;
9898 : : }
9899 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
9900 : : protocol_m & protocol_v);
9901 : 0 : }
9902 : :
9903 : : /**
9904 : : * Add GRE optional items to the value.
9905 : : *
9906 : : * @param[in, out] key
9907 : : * Flow matcher value.
9908 : : * @param[in] item
9909 : : * Flow pattern to translate.
9910 : : * @param[in] gre_item
9911 : : * Pointer to gre_item.
9912 : : * @param[in] pattern_flags
9913 : : * Accumulated pattern flags.
9914 : : * @param[in] key_type
9915 : : * Set flow matcher mask or value.
9916 : : */
9917 : : static void
9918 : 0 : flow_dv_translate_item_gre_option(void *key,
9919 : : const struct rte_flow_item *item,
9920 : : const struct rte_flow_item *gre_item,
9921 : : uint64_t pattern_flags, uint32_t key_type)
9922 : : {
9923 : : void *misc5_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_5);
9924 : 0 : const struct rte_flow_item_gre_opt *option_m = item->mask;
9925 : 0 : const struct rte_flow_item_gre_opt *option_v = item->spec;
9926 : 0 : const struct rte_flow_item_gre *gre_m = gre_item->mask;
9927 : 0 : const struct rte_flow_item_gre *gre_v = gre_item->spec;
9928 : : static const struct rte_flow_item_gre empty_gre = {0};
9929 : : struct rte_flow_item gre_key_item;
9930 : : uint16_t c_rsvd0_ver_m, c_rsvd0_ver_v;
9931 : : uint16_t protocol_m, protocol_v;
9932 : :
9933 : : /*
9934 : : * If only match key field, keep using misc for matching.
9935 : : * If need to match checksum or sequence, using misc5 and do
9936 : : * not need using misc.
9937 : : */
9938 [ # # ]: 0 : if (!(option_m->sequence.sequence ||
9939 [ # # ]: 0 : option_m->checksum_rsvd.checksum)) {
9940 : 0 : flow_dv_translate_item_gre(key, gre_item, pattern_flags, key_type);
9941 : 0 : gre_key_item.spec = &option_v->key.key;
9942 : 0 : gre_key_item.mask = &option_m->key.key;
9943 : 0 : flow_dv_translate_item_gre_key(key, &gre_key_item, key_type);
9944 : 0 : return;
9945 : : }
9946 [ # # ]: 0 : if (!gre_v) {
9947 : : gre_v = &empty_gre;
9948 : : gre_m = &empty_gre;
9949 : : } else {
9950 [ # # ]: 0 : if (!gre_m)
9951 : : gre_m = &rte_flow_item_gre_mask;
9952 : : }
9953 : 0 : protocol_v = gre_v->protocol;
9954 : 0 : protocol_m = gre_m->protocol;
9955 [ # # ]: 0 : if (!protocol_m) {
9956 : : /* Force next protocol to prevent matchers duplication */
9957 : : uint16_t ether_type =
9958 : : mlx5_translate_tunnel_etypes(pattern_flags);
9959 : : if (ether_type) {
9960 [ # # ]: 0 : protocol_v = rte_be_to_cpu_16(ether_type);
9961 : : protocol_m = UINT16_MAX;
9962 : : }
9963 : : }
9964 : 0 : c_rsvd0_ver_v = gre_v->c_rsvd0_ver;
9965 : 0 : c_rsvd0_ver_m = gre_m->c_rsvd0_ver;
9966 [ # # ]: 0 : if (option_m->sequence.sequence) {
9967 : 0 : c_rsvd0_ver_v |= RTE_BE16(0x1000);
9968 : 0 : c_rsvd0_ver_m |= RTE_BE16(0x1000);
9969 : : }
9970 [ # # ]: 0 : if (option_m->key.key) {
9971 : 0 : c_rsvd0_ver_v |= RTE_BE16(0x2000);
9972 : 0 : c_rsvd0_ver_m |= RTE_BE16(0x2000);
9973 : : }
9974 [ # # ]: 0 : if (option_m->checksum_rsvd.checksum) {
9975 : 0 : c_rsvd0_ver_v |= RTE_BE16(0x8000);
9976 : 0 : c_rsvd0_ver_m |= RTE_BE16(0x8000);
9977 : : }
9978 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
9979 : : c_rsvd0_ver_v = c_rsvd0_ver_m;
9980 : : protocol_v = protocol_m;
9981 : : option_v = option_m;
9982 : : }
9983 : : /*
9984 : : * Hardware parses GRE optional field into the fixed location,
9985 : : * do not need to adjust the tunnel dword indices.
9986 : : */
9987 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_0,
9988 : : rte_be_to_cpu_32((c_rsvd0_ver_v | protocol_v << 16) &
9989 : : (c_rsvd0_ver_m | protocol_m << 16)));
9990 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_1,
9991 : : rte_be_to_cpu_32(option_v->checksum_rsvd.checksum &
9992 : : option_m->checksum_rsvd.checksum));
9993 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_2,
9994 : : rte_be_to_cpu_32(option_v->key.key & option_m->key.key));
9995 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_3,
9996 : : rte_be_to_cpu_32(option_v->sequence.sequence &
9997 : : option_m->sequence.sequence));
9998 : : }
9999 : :
10000 : : /**
10001 : : * Add NVGRE item to matcher and to the value.
10002 : : *
10003 : : * @param[in, out] key
10004 : : * Flow matcher value.
10005 : : * @param[in] item
10006 : : * Flow pattern to translate.
10007 : : * @param[in] pattern_flags
10008 : : * Accumulated pattern flags.
10009 : : * @param[in] key_type
10010 : : * Set flow matcher mask or value.
10011 : : */
10012 : : static void
10013 : 0 : flow_dv_translate_item_nvgre(void *key, const struct rte_flow_item *item,
10014 : : unsigned long pattern_flags, uint32_t key_type)
10015 : : {
10016 : : const struct rte_flow_item_nvgre *nvgre_m;
10017 : : const struct rte_flow_item_nvgre *nvgre_v;
10018 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10019 : : const char *tni_flow_id_m;
10020 : : const char *tni_flow_id_v;
10021 : : char *gre_key_v;
10022 : : int size;
10023 : : int i;
10024 : :
10025 : : /* For NVGRE, GRE header fields must be set with defined values. */
10026 : 0 : const struct rte_flow_item_gre gre_spec = {
10027 : : .c_rsvd0_ver = RTE_BE16(0x2000),
10028 : : .protocol = RTE_BE16(RTE_ETHER_TYPE_TEB)
10029 : : };
10030 : 0 : const struct rte_flow_item_gre gre_mask = {
10031 : : .c_rsvd0_ver = RTE_BE16(0xB000),
10032 : : .protocol = RTE_BE16(UINT16_MAX),
10033 : : };
10034 : 0 : const struct rte_flow_item gre_item = {
10035 : : .spec = &gre_spec,
10036 : : .mask = &gre_mask,
10037 : : .last = NULL,
10038 : : };
10039 : 0 : flow_dv_translate_item_gre(key, &gre_item, pattern_flags, key_type);
10040 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10041 : 0 : return;
10042 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, nvgre_v, nvgre_m,
# # # # ]
10043 : : &rte_flow_item_nvgre_mask);
10044 : 0 : tni_flow_id_m = (const char *)nvgre_m->tni;
10045 : 0 : tni_flow_id_v = (const char *)nvgre_v->tni;
10046 : : size = sizeof(nvgre_m->tni) + sizeof(nvgre_m->flow_id);
10047 : 0 : gre_key_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, gre_key_h);
10048 [ # # ]: 0 : for (i = 0; i < size; ++i)
10049 : 0 : gre_key_v[i] = tni_flow_id_m[i] & tni_flow_id_v[i];
10050 : : }
10051 : :
10052 : : /**
10053 : : * Add VXLAN item to the value.
10054 : : *
10055 : : * @param[in] dev
10056 : : * Pointer to the Ethernet device structure.
10057 : : * @param[in] attr
10058 : : * Flow rule attributes.
10059 : : * @param[in, out] key
10060 : : * Flow matcher value.
10061 : : * @param[in] item
10062 : : * Flow pattern to translate.
10063 : : * @param[in] inner
10064 : : * Item is inner pattern.
10065 : : * @param[in] wks
10066 : : * Matcher workspace.
10067 : : * @param[in] key_type
10068 : : * Set flow matcher mask or value.
10069 : : */
10070 : : static void
10071 : 0 : flow_dv_translate_item_vxlan(struct rte_eth_dev *dev,
10072 : : const struct rte_flow_attr *attr,
10073 : : void *key, const struct rte_flow_item *item,
10074 : : int inner, struct mlx5_dv_matcher_workspace *wks,
10075 : : uint32_t key_type)
10076 : : {
10077 : : const struct rte_flow_item_vxlan *vxlan_m;
10078 : : const struct rte_flow_item_vxlan *vxlan_v;
10079 : : void *headers_v;
10080 : : void *misc_v;
10081 : : void *misc5_v;
10082 : : uint32_t tunnel_v;
10083 : : char *vni_v;
10084 : : uint16_t dport;
10085 : : int size;
10086 : : int i;
10087 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10088 : 0 : const struct rte_flow_item_vxlan nic_mask = {
10089 : : .hdr.vni = { 0xff, 0xff, 0xff },
10090 : : .hdr.rsvd1 = 0xff,
10091 : : };
10092 : :
10093 : : misc5_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_5);
10094 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
10095 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10096 [ # # ]: 0 : dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
10097 : : MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
10098 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
10099 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10100 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
10101 : : udp_dport, 0xFFFF);
10102 : : else
10103 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
10104 : : udp_dport, dport);
10105 : : }
10106 : : /*
10107 : : * Read the UDP dport to check if the value satisfies the VXLAN
10108 : : * matching with MISC5 for CX5.
10109 : : */
10110 [ # # ]: 0 : if (wks->udp_dport)
10111 : : dport = wks->udp_dport;
10112 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10113 : 0 : return;
10114 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, vxlan_v, vxlan_m, &nic_mask);
# # # # ]
10115 : : if ((item->mask == &nic_mask) &&
10116 : : ((!attr->group && !(attr->transfer && priv->fdb_def_rule) &&
10117 : : !priv->sh->tunnel_header_0_1) ||
10118 : : ((attr->group || (attr->transfer && priv->fdb_def_rule)) &&
10119 : : !priv->sh->misc5_cap)))
10120 : : vxlan_m = &rte_flow_item_vxlan_mask;
10121 [ # # ]: 0 : if ((priv->sh->steering_format_version ==
10122 [ # # ]: 0 : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5 &&
10123 : 0 : dport != MLX5_UDP_PORT_VXLAN) ||
10124 [ # # # # : 0 : (!attr->group && !(attr->transfer && priv->fdb_def_rule)) ||
# # # # ]
10125 [ # # # # ]: 0 : ((attr->group || (attr->transfer && priv->fdb_def_rule)) &&
10126 [ # # ]: 0 : !priv->sh->misc5_cap)) {
10127 : : misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10128 : : size = sizeof(vxlan_m->hdr.vni);
10129 : 0 : vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, vxlan_vni);
10130 [ # # ]: 0 : for (i = 0; i < size; ++i)
10131 : 0 : vni_v[i] = vxlan_m->hdr.vni[i] & vxlan_v->hdr.vni[i];
10132 : : return;
10133 : : }
10134 : 0 : tunnel_v = (vxlan_v->hdr.vni[0] & vxlan_m->hdr.vni[0]) |
10135 : 0 : (vxlan_v->hdr.vni[1] & vxlan_m->hdr.vni[1]) << 8 |
10136 : 0 : (vxlan_v->hdr.vni[2] & vxlan_m->hdr.vni[2]) << 16;
10137 : 0 : tunnel_v |= (vxlan_v->hdr.rsvd1 & vxlan_m->hdr.rsvd1) << 24;
10138 [ # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_1, RTE_BE32(tunnel_v));
10139 : : }
10140 : :
10141 : : /**
10142 : : * Add VXLAN-GPE item to the value.
10143 : : *
10144 : : * @param[in, out] key
10145 : : * Flow matcher value.
10146 : : * @param[in] item
10147 : : * Flow pattern to translate.
10148 : : * @param[in] pattern_flags
10149 : : * Item pattern flags.
10150 : : * @param[in] key_type
10151 : : * Set flow matcher mask or value.
10152 : : */
10153 : :
10154 : : static void
10155 : 0 : flow_dv_translate_item_vxlan_gpe(void *key, const struct rte_flow_item *item,
10156 : : const uint64_t pattern_flags,
10157 : : uint32_t key_type)
10158 : : {
10159 : : static const struct rte_flow_item_vxlan_gpe dummy_vxlan_gpe_hdr = {{{0}}};
10160 : 0 : const struct rte_flow_item_vxlan_gpe *vxlan_m = item->mask;
10161 : 0 : const struct rte_flow_item_vxlan_gpe *vxlan_v = item->spec;
10162 : : /* The item was validated to be on the outer side */
10163 : : void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10164 : : void *misc_v =
10165 : : MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
10166 : 0 : char *vni_v =
10167 : : MLX5_ADDR_OF(fte_match_set_misc3, misc_v, outer_vxlan_gpe_vni);
10168 : : int i, size = sizeof(vxlan_m->hdr.vni);
10169 : : uint8_t flags_m = 0xff;
10170 : : uint8_t flags_v = 0xc;
10171 : : uint8_t m_protocol, v_protocol;
10172 : :
10173 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
10174 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10175 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
10176 : : 0xFFFF);
10177 : : else
10178 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
10179 : : MLX5_UDP_PORT_VXLAN_GPE);
10180 : : }
10181 [ # # ]: 0 : if (!vxlan_v) {
10182 : : vxlan_v = &dummy_vxlan_gpe_hdr;
10183 : : vxlan_m = &dummy_vxlan_gpe_hdr;
10184 : : } else {
10185 [ # # ]: 0 : if (!vxlan_m)
10186 : : vxlan_m = &rte_flow_item_vxlan_gpe_mask;
10187 : : }
10188 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10189 : : vxlan_v = vxlan_m;
10190 [ # # ]: 0 : else if (key_type == MLX5_SET_MATCHER_HS_V)
10191 : : vxlan_m = vxlan_v;
10192 [ # # ]: 0 : if (vxlan_m->hdr.flags) {
10193 : : flags_m = vxlan_m->hdr.flags;
10194 : 0 : flags_v = vxlan_v->hdr.flags;
10195 : : }
10196 : 0 : m_protocol = vxlan_m->hdr.protocol;
10197 : 0 : v_protocol = vxlan_v->hdr.protocol;
10198 [ # # ]: 0 : if (!m_protocol) {
10199 : : /* Force next protocol to ensure next headers parsing. */
10200 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_NSH)
10201 : : v_protocol = RTE_VXLAN_GPE_TYPE_NSH;
10202 [ # # ]: 0 : else if (pattern_flags & MLX5_FLOW_LAYER_INNER_L2)
10203 : : v_protocol = RTE_VXLAN_GPE_TYPE_ETH;
10204 [ # # ]: 0 : else if (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV4)
10205 : : v_protocol = RTE_VXLAN_GPE_TYPE_IPV4;
10206 [ # # ]: 0 : else if (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV6)
10207 : : v_protocol = RTE_VXLAN_GPE_TYPE_IPV6;
10208 [ # # ]: 0 : if (v_protocol)
10209 : : m_protocol = 0xFF;
10210 : : /* Restore the value to mask in mask case. */
10211 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10212 : : v_protocol = m_protocol;
10213 : : }
10214 : : /*
10215 : : * If only match flags/protocol/vni field, keep using misc3 for matching.
10216 : : * If need to match rsvd0 or rsvd1, using misc5 and do not need using misc3.
10217 : : */
10218 [ # # # # : 0 : if (!(vxlan_m->hdr.rsvd0[0] || vxlan_m->hdr.rsvd0[1] || vxlan_m->hdr.rsvd1)) {
# # ]
10219 [ # # ]: 0 : for (i = 0; i < size; ++i)
10220 : 0 : vni_v[i] = vxlan_m->hdr.vni[i] & vxlan_v->hdr.vni[i];
10221 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc_v, outer_vxlan_gpe_flags,
10222 : : flags_m & flags_v);
10223 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc_v,
10224 : : outer_vxlan_gpe_next_protocol, m_protocol & v_protocol);
10225 : : } else {
10226 : : uint32_t tunnel_v;
10227 : : void *misc5_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_5);
10228 : :
10229 : 0 : tunnel_v = (flags_m & flags_v) << 24 |
10230 : 0 : (vxlan_v->hdr.rsvd0[0] & vxlan_m->hdr.rsvd0[0]) << 16 |
10231 : 0 : (vxlan_v->hdr.rsvd0[1] & vxlan_m->hdr.rsvd0[1]) << 8 |
10232 : 0 : (m_protocol & v_protocol);
10233 [ # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_0, tunnel_v);
10234 : 0 : tunnel_v = (vxlan_v->hdr.vni[0] & vxlan_m->hdr.vni[0]) << 24 |
10235 : 0 : (vxlan_v->hdr.vni[1] & vxlan_m->hdr.vni[1]) << 16 |
10236 : 0 : (vxlan_v->hdr.vni[2] & vxlan_m->hdr.vni[2]) << 8 |
10237 : 0 : (vxlan_v->hdr.rsvd1 & vxlan_m->hdr.rsvd1);
10238 [ # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_1, tunnel_v);
10239 : : }
10240 : 0 : }
10241 : :
10242 : : /**
10243 : : * Add Geneve item to the value.
10244 : : *
10245 : : * @param[in, out] key
10246 : : * Flow matcher value.
10247 : : * @param[in] item
10248 : : * Flow pattern to translate.
10249 : : * @param[in] pattern_flags
10250 : : * Item pattern flags.
10251 : : * @param[in] key_type
10252 : : * Set flow matcher mask or value.
10253 : : */
10254 : :
10255 : : static void
10256 : 0 : flow_dv_translate_item_geneve(void *key, const struct rte_flow_item *item,
10257 : : uint64_t pattern_flags, uint32_t key_type)
10258 : : {
10259 : : static const struct rte_flow_item_geneve empty_geneve = {0,};
10260 : 0 : const struct rte_flow_item_geneve *geneve_m = item->mask;
10261 : 0 : const struct rte_flow_item_geneve *geneve_v = item->spec;
10262 : : /* GENEVE flow item validation allows single tunnel item */
10263 : : void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10264 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10265 : : uint16_t gbhdr_m;
10266 : : uint16_t gbhdr_v;
10267 : 0 : char *vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, geneve_vni);
10268 : : size_t size = sizeof(geneve_m->vni), i;
10269 : : uint16_t protocol_m, protocol_v;
10270 : :
10271 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
10272 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10273 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
10274 : : 0xFFFF);
10275 : : else
10276 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
10277 : : MLX5_UDP_PORT_GENEVE);
10278 : : }
10279 [ # # ]: 0 : if (!geneve_v) {
10280 : : geneve_v = &empty_geneve;
10281 : : geneve_m = &empty_geneve;
10282 : : } else {
10283 [ # # ]: 0 : if (!geneve_m)
10284 : : geneve_m = &rte_flow_item_geneve_mask;
10285 : : }
10286 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10287 : : geneve_v = geneve_m;
10288 [ # # ]: 0 : else if (key_type == MLX5_SET_MATCHER_HS_V)
10289 : : geneve_m = geneve_v;
10290 [ # # ]: 0 : for (i = 0; i < size; ++i)
10291 : 0 : vni_v[i] = geneve_m->vni[i] & geneve_v->vni[i];
10292 [ # # ]: 0 : gbhdr_m = rte_be_to_cpu_16(geneve_m->ver_opt_len_o_c_rsvd0);
10293 [ # # ]: 0 : gbhdr_v = rte_be_to_cpu_16(geneve_v->ver_opt_len_o_c_rsvd0);
10294 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, geneve_oam,
10295 : : MLX5_GENEVE_OAMF_VAL(gbhdr_v) & MLX5_GENEVE_OAMF_VAL(gbhdr_m));
10296 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
10297 : : MLX5_GENEVE_OPTLEN_VAL(gbhdr_v) &
10298 : : MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
10299 [ # # ]: 0 : protocol_m = rte_be_to_cpu_16(geneve_m->protocol);
10300 [ # # ]: 0 : protocol_v = rte_be_to_cpu_16(geneve_v->protocol);
10301 [ # # ]: 0 : if (!protocol_m) {
10302 : : /* Force next protocol to prevent matchers duplication */
10303 : : protocol_v = mlx5_translate_tunnel_etypes(pattern_flags);
10304 : : if (protocol_v)
10305 : : protocol_m = 0xFFFF;
10306 : : /* Restore the value to mask in mask case. */
10307 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10308 : : protocol_v = protocol_m;
10309 : : }
10310 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, geneve_protocol_type,
10311 : : protocol_m & protocol_v);
10312 : 0 : }
10313 : :
10314 : : /**
10315 : : * Create Geneve TLV option resource.
10316 : : *
10317 : : * @param[in, out] dev
10318 : : * Pointer to rte_eth_dev structure.
10319 : : * @param[in] item
10320 : : * Flow pattern to translate.
10321 : : * @param[out] error
10322 : : * pointer to error structure.
10323 : : *
10324 : : * @return
10325 : : * 0 on success otherwise -errno and errno is set.
10326 : : */
10327 : : static int
10328 : 0 : flow_dev_geneve_tlv_option_resource_register(struct rte_eth_dev *dev,
10329 : : const struct rte_flow_item *item,
10330 : : struct rte_flow_error *error)
10331 : : {
10332 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10333 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
10334 : 0 : struct mlx5_geneve_tlv_option_resource *geneve_opt_resource =
10335 : : sh->geneve_tlv_option_resource;
10336 : : struct mlx5_devx_obj *obj;
10337 : 0 : const struct rte_flow_item_geneve_opt *geneve_opt_v = item->spec;
10338 : : int ret = 0;
10339 : :
10340 : : MLX5_ASSERT(sh->config.dv_flow_en == 1);
10341 [ # # ]: 0 : if (!geneve_opt_v)
10342 : : return -1;
10343 : 0 : rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
10344 [ # # ]: 0 : if (geneve_opt_resource != NULL) {
10345 : 0 : if (geneve_opt_resource->option_class ==
10346 : : geneve_opt_v->option_class &&
10347 : : geneve_opt_resource->option_type ==
10348 [ # # ]: 0 : geneve_opt_v->option_type &&
10349 : : geneve_opt_resource->length ==
10350 : : geneve_opt_v->option_len) {
10351 : 0 : rte_atomic_fetch_add_explicit(&geneve_opt_resource->refcnt, 1,
10352 : : rte_memory_order_relaxed);
10353 : : } else {
10354 : 0 : ret = rte_flow_error_set(error, ENOMEM,
10355 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10356 : : "Only one GENEVE TLV option supported");
10357 : 0 : goto exit;
10358 : : }
10359 : : } else {
10360 : 0 : struct mlx5_devx_geneve_tlv_option_attr attr = {
10361 : 0 : .option_class = geneve_opt_v->option_class,
10362 : 0 : .option_type = geneve_opt_v->option_type,
10363 : 0 : .option_data_len = geneve_opt_v->option_len,
10364 : : };
10365 : :
10366 : : /* Create a GENEVE TLV object and resource. */
10367 : 0 : obj = mlx5_devx_cmd_create_geneve_tlv_option(sh->cdev->ctx,
10368 : : &attr);
10369 [ # # ]: 0 : if (!obj) {
10370 : 0 : ret = rte_flow_error_set(error, ENODATA,
10371 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10372 : : "Failed to create GENEVE TLV Devx object");
10373 : 0 : goto exit;
10374 : : }
10375 : 0 : sh->geneve_tlv_option_resource =
10376 : 0 : mlx5_malloc(MLX5_MEM_ZERO,
10377 : : sizeof(*geneve_opt_resource),
10378 : : 0, SOCKET_ID_ANY);
10379 [ # # ]: 0 : if (!sh->geneve_tlv_option_resource) {
10380 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
10381 : 0 : ret = rte_flow_error_set(error, ENOMEM,
10382 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10383 : : "GENEVE TLV object memory allocation failed");
10384 : 0 : goto exit;
10385 : : }
10386 : : geneve_opt_resource = sh->geneve_tlv_option_resource;
10387 : 0 : geneve_opt_resource->obj = obj;
10388 : 0 : geneve_opt_resource->option_class = geneve_opt_v->option_class;
10389 : 0 : geneve_opt_resource->option_type = geneve_opt_v->option_type;
10390 : 0 : geneve_opt_resource->length = geneve_opt_v->option_len;
10391 : 0 : rte_atomic_store_explicit(&geneve_opt_resource->refcnt, 1,
10392 : : rte_memory_order_relaxed);
10393 : : }
10394 : 0 : exit:
10395 : : rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
10396 : 0 : return ret;
10397 : : }
10398 : :
10399 : : /**
10400 : : * Add Geneve TLV option item to value.
10401 : : *
10402 : : * @param[in, out] dev
10403 : : * Pointer to rte_eth_dev structure.
10404 : : * @param[in, out] key
10405 : : * Flow matcher value.
10406 : : * @param[in] item
10407 : : * Flow pattern to translate.
10408 : : * @param[in] key_type
10409 : : * Set flow matcher mask or value.
10410 : : * @param[out] error
10411 : : * Pointer to error structure.
10412 : : */
10413 : : static int
10414 : 0 : flow_dv_translate_item_geneve_opt(struct rte_eth_dev *dev, void *key,
10415 : : const struct rte_flow_item *item,
10416 : : uint32_t key_type,
10417 : : struct rte_flow_error *error)
10418 : : {
10419 : : const struct rte_flow_item_geneve_opt *geneve_opt_m;
10420 : : const struct rte_flow_item_geneve_opt *geneve_opt_v;
10421 : 0 : const struct rte_flow_item_geneve_opt *orig_spec = item->spec;
10422 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
10423 : 0 : rte_be32_t opt_data_key = 0, opt_data_mask = 0;
10424 : : size_t option_byte_len;
10425 : : int ret = 0;
10426 : :
10427 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type) || !orig_spec)
# # # # #
# # # ]
10428 : : return -1;
10429 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, geneve_opt_v, geneve_opt_m,
# # # # ]
10430 : : &rte_flow_item_geneve_opt_mask);
10431 : : /*
10432 : : * Register resource requires item spec for SW steering,
10433 : : * for HW steering resources is registered explicitly by user.
10434 : : */
10435 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_SW_V) {
10436 : 0 : ret = flow_dev_geneve_tlv_option_resource_register(dev, item,
10437 : : error);
10438 [ # # ]: 0 : if (ret) {
10439 : 0 : DRV_LOG(ERR, "Failed to create geneve_tlv_obj");
10440 : 0 : return ret;
10441 : : }
10442 : : }
10443 : : /* Convert the option length from DW to bytes for using memcpy. */
10444 : 0 : option_byte_len = RTE_MIN((size_t)(orig_spec->option_len * 4),
10445 : : sizeof(rte_be32_t));
10446 [ # # ]: 0 : if (geneve_opt_v->data) {
10447 : : memcpy(&opt_data_key, geneve_opt_v->data, option_byte_len);
10448 : 0 : memcpy(&opt_data_mask, geneve_opt_m->data, option_byte_len);
10449 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v,
10450 : : geneve_tlv_option_0_data,
10451 : : rte_be_to_cpu_32(opt_data_key & opt_data_mask));
10452 : : }
10453 : : return ret;
10454 : : }
10455 : :
10456 : : /**
10457 : : * Add MPLS item to the value.
10458 : : *
10459 : : * @param[in, out] key
10460 : : * Flow matcher value.
10461 : : * @param[in] item
10462 : : * Flow pattern to translate.
10463 : : * @param[in] prev_layer
10464 : : * The protocol layer indicated in previous item.
10465 : : * @param[in] inner
10466 : : * Item is inner pattern.
10467 : : * @param[in] key_type
10468 : : * Set flow matcher mask or value.
10469 : : */
10470 : : static void
10471 : 0 : flow_dv_translate_item_mpls(void *key, const struct rte_flow_item *item,
10472 : : uint64_t prev_layer, int inner,
10473 : : uint32_t key_type)
10474 : : {
10475 : : const uint32_t *in_mpls_m;
10476 : : const uint32_t *in_mpls_v;
10477 : : uint32_t *out_mpls_v = 0;
10478 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10479 : 0 : void *misc2_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
10480 : : void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10481 : :
10482 [ # # # ]: 0 : switch (prev_layer) {
10483 : 0 : case MLX5_FLOW_LAYER_OUTER_L4_UDP:
10484 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
10485 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10486 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
10487 : : udp_dport, 0xffff);
10488 : : else
10489 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
10490 : : udp_dport, MLX5_UDP_PORT_MPLS);
10491 : : }
10492 : : break;
10493 : 0 : case MLX5_FLOW_LAYER_GRE:
10494 : : /* Fall-through. */
10495 : : case MLX5_FLOW_LAYER_GRE_KEY:
10496 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_misc, misc_v, gre_protocol)) {
10497 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10498 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v,
10499 : : gre_protocol, 0xffff);
10500 : : else
10501 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v,
10502 : : gre_protocol, RTE_ETHER_TYPE_MPLS);
10503 : : }
10504 : : break;
10505 : : default:
10506 : : break;
10507 : : }
10508 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10509 : : return;
10510 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, in_mpls_v, in_mpls_m,
# # # # ]
10511 : : &rte_flow_item_mpls_mask);
10512 [ # # # ]: 0 : switch (prev_layer) {
10513 : 0 : case MLX5_FLOW_LAYER_OUTER_L4_UDP:
10514 : 0 : out_mpls_v =
10515 : : (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
10516 : : outer_first_mpls_over_udp);
10517 : 0 : break;
10518 : 0 : case MLX5_FLOW_LAYER_GRE:
10519 : 0 : out_mpls_v =
10520 : : (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
10521 : : outer_first_mpls_over_gre);
10522 : 0 : break;
10523 : 0 : default:
10524 : : /* Inner MPLS not over GRE is not supported. */
10525 [ # # ]: 0 : if (!inner)
10526 : : out_mpls_v =
10527 : : (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
10528 : : misc2_v,
10529 : : outer_first_mpls);
10530 : : break;
10531 : : }
10532 : : if (out_mpls_v)
10533 : 0 : *out_mpls_v = *in_mpls_v & *in_mpls_m;
10534 : : }
10535 : :
10536 : : /**
10537 : : * Add metadata register item to matcher
10538 : : *
10539 : : * @param[in, out] key
10540 : : * Flow matcher value.
10541 : : * @param[in] reg_type
10542 : : * Type of device metadata register
10543 : : * @param[in] data
10544 : : * Register data
10545 : : * @param[in] mask
10546 : : * Register mask
10547 : : */
10548 : : static void
10549 : 0 : flow_dv_match_meta_reg(void *key, enum modify_reg reg_type,
10550 : : uint32_t data, uint32_t mask)
10551 : : {
10552 : : void *misc2_v =
10553 : : MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
10554 : : uint32_t temp;
10555 : :
10556 [ # # ]: 0 : if (!key)
10557 : : return;
10558 : 0 : data &= mask;
10559 [ # # # # : 0 : switch (reg_type) {
# # # # #
# # ]
10560 : 0 : case REG_A:
10561 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_a, data);
10562 : 0 : break;
10563 : 0 : case REG_B:
10564 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_b, data);
10565 : 0 : break;
10566 : 0 : case REG_C_0:
10567 : : /*
10568 : : * The metadata register C0 field might be divided into
10569 : : * source vport index and META item value, we should set
10570 : : * this field according to specified mask, not as whole one.
10571 : : */
10572 [ # # ]: 0 : temp = MLX5_GET(fte_match_set_misc2, misc2_v, metadata_reg_c_0);
10573 [ # # ]: 0 : if (mask)
10574 : 0 : temp &= ~mask;
10575 : 0 : temp |= data;
10576 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_0, temp);
10577 : 0 : break;
10578 : 0 : case REG_C_1:
10579 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_1, data);
10580 : 0 : break;
10581 : 0 : case REG_C_2:
10582 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_2, data);
10583 : 0 : break;
10584 : 0 : case REG_C_3:
10585 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_3, data);
10586 : 0 : break;
10587 : 0 : case REG_C_4:
10588 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_4, data);
10589 : 0 : break;
10590 : 0 : case REG_C_5:
10591 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_5, data);
10592 : 0 : break;
10593 : 0 : case REG_C_6:
10594 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_6, data);
10595 : 0 : break;
10596 : 0 : case REG_C_7:
10597 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_7, data);
10598 : 0 : break;
10599 : : default:
10600 : : MLX5_ASSERT(false);
10601 : : break;
10602 : : }
10603 : : }
10604 : :
10605 : : /**
10606 : : * Add metadata register item to matcher
10607 : : *
10608 : : * @param[in, out] matcher
10609 : : * Flow matcher.
10610 : : * @param[in, out] key
10611 : : * Flow matcher value.
10612 : : * @param[in] reg_type
10613 : : * Type of device metadata register
10614 : : * @param[in] value
10615 : : * Register value
10616 : : * @param[in] mask
10617 : : * Register mask
10618 : : */
10619 : : static void
10620 : : flow_dv_match_meta_reg_all(void *matcher, void *key, enum modify_reg reg_type,
10621 : : uint32_t data, uint32_t mask)
10622 : : {
10623 : 0 : flow_dv_match_meta_reg(key, reg_type, data, mask);
10624 : 0 : flow_dv_match_meta_reg(matcher, reg_type, mask, mask);
10625 : : }
10626 : :
10627 : : /**
10628 : : * Add MARK item to matcher
10629 : : *
10630 : : * @param[in] dev
10631 : : * The device to configure through.
10632 : : * @param[in, out] key
10633 : : * Flow matcher value.
10634 : : * @param[in] item
10635 : : * Flow pattern to translate.
10636 : : * @param[in] key_type
10637 : : * Set flow matcher mask or value.
10638 : : */
10639 : : static void
10640 : 0 : flow_dv_translate_item_mark(struct rte_eth_dev *dev, void *key,
10641 : : const struct rte_flow_item *item,
10642 : : uint32_t key_type)
10643 : : {
10644 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10645 : : const struct rte_flow_item_mark *mark;
10646 : : uint32_t value;
10647 : : uint32_t mask = 0;
10648 : :
10649 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_SW) {
10650 [ # # ]: 0 : mark = item->mask ? (const void *)item->mask :
10651 : : &rte_flow_item_mark_mask;
10652 : 0 : mask = mark->id;
10653 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M) {
10654 : : value = mask;
10655 : : } else {
10656 : 0 : mark = (const void *)item->spec;
10657 : : MLX5_ASSERT(mark);
10658 : 0 : value = mark->id;
10659 : : }
10660 : : } else {
10661 [ # # ]: 0 : mark = (key_type == MLX5_SET_MATCHER_HS_V) ?
10662 : : (const void *)item->spec : (const void *)item->mask;
10663 : : MLX5_ASSERT(mark);
10664 : 0 : value = mark->id;
10665 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_HS_M)
10666 : : mask = value;
10667 : : }
10668 : 0 : mask &= priv->sh->dv_mark_mask;
10669 : 0 : value &= mask;
10670 [ # # ]: 0 : if (mask) {
10671 : : enum modify_reg reg;
10672 : :
10673 : : /* Get the metadata register index for the mark. */
10674 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, NULL);
10675 : : MLX5_ASSERT(reg > 0);
10676 [ # # ]: 0 : if (reg == REG_C_0) {
10677 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10678 : 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
10679 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
10680 : :
10681 : 0 : mask &= msk_c0;
10682 : 0 : mask <<= shl_c0;
10683 : 0 : value <<= shl_c0;
10684 : : }
10685 : 0 : flow_dv_match_meta_reg(key, reg, value, mask);
10686 : : }
10687 : 0 : }
10688 : :
10689 : : /**
10690 : : * Add META item to matcher
10691 : : *
10692 : : * @param[in] dev
10693 : : * The devich to configure through.
10694 : : * @param[in, out] key
10695 : : * Flow matcher value.
10696 : : * @param[in] attr
10697 : : * Attributes of flow that includes this item.
10698 : : * @param[in] item
10699 : : * Flow pattern to translate.
10700 : : * @param[in] key_type
10701 : : * Set flow matcher mask or value.
10702 : : */
10703 : : static void
10704 : 0 : flow_dv_translate_item_meta(struct rte_eth_dev *dev,
10705 : : void *key,
10706 : : const struct rte_flow_attr *attr,
10707 : : const struct rte_flow_item *item,
10708 : : uint32_t key_type)
10709 : : {
10710 : : const struct rte_flow_item_meta *meta_m;
10711 : : const struct rte_flow_item_meta *meta_v;
10712 : : uint32_t value;
10713 : : uint32_t mask = 0;
10714 : : int reg;
10715 : :
10716 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10717 : : return;
10718 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, meta_v, meta_m,
# # # # ]
10719 : : &rte_flow_item_meta_mask);
10720 : 0 : value = meta_v->data;
10721 : 0 : mask = meta_m->data;
10722 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_HS_M)
10723 : : mask = value;
10724 : : /*
10725 : : * In the current implementation, REG_B cannot be used to match.
10726 : : * Force to use REG_C_1 in HWS root table as other tables.
10727 : : * This map may change.
10728 : : * NIC: modify - REG_B to be present in SW
10729 : : * match - REG_C_1 when copied from FDB, different from SWS
10730 : : * FDB: modify - REG_C_1 in Xmeta mode, REG_NON in legacy mode
10731 : : * match - REG_C_1 in FDB
10732 : : */
10733 [ # # ]: 0 : if (!!(key_type & MLX5_SET_MATCHER_SW))
10734 : 0 : reg = flow_dv_get_metadata_reg(dev, attr, NULL);
10735 : : else
10736 : : reg = flow_hw_get_reg_id(dev, RTE_FLOW_ITEM_TYPE_META, 0);
10737 [ # # ]: 0 : if (reg < 0)
10738 : : return;
10739 : : MLX5_ASSERT(reg != REG_NON);
10740 [ # # ]: 0 : if (reg == REG_C_0) {
10741 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10742 : 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
10743 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
10744 : :
10745 : 0 : mask &= msk_c0;
10746 : 0 : mask <<= shl_c0;
10747 : 0 : value <<= shl_c0;
10748 : : }
10749 : 0 : flow_dv_match_meta_reg(key, reg, value, mask);
10750 : : }
10751 : :
10752 : : /**
10753 : : * Add vport metadata Reg C0 item to matcher
10754 : : *
10755 : : * @param[in, out] key
10756 : : * Flow matcher value.
10757 : : * @param[in] value
10758 : : * Register value
10759 : : * @param[in] mask
10760 : : * Register mask
10761 : : */
10762 : : static void
10763 : : flow_dv_translate_item_meta_vport(void *key, uint32_t value, uint32_t mask)
10764 : : {
10765 : 0 : flow_dv_match_meta_reg(key, REG_C_0, value, mask);
10766 : 0 : }
10767 : :
10768 : : /**
10769 : : * Add tag item to matcher
10770 : : *
10771 : : * @param[in] dev
10772 : : * The devich to configure through.
10773 : : * @param[in, out] key
10774 : : * Flow matcher value.
10775 : : * @param[in] item
10776 : : * Flow pattern to translate.
10777 : : * @param[in] key_type
10778 : : * Set flow matcher mask or value.
10779 : : */
10780 : : static void
10781 : 0 : flow_dv_translate_mlx5_item_tag(struct rte_eth_dev *dev, void *key,
10782 : : const struct rte_flow_item *item,
10783 : : uint32_t key_type)
10784 : : {
10785 : 0 : const struct mlx5_rte_flow_item_tag *tag_v = item->spec;
10786 : 0 : const struct mlx5_rte_flow_item_tag *tag_m = item->mask;
10787 : : uint32_t mask, value;
10788 : :
10789 : : MLX5_ASSERT(tag_v);
10790 : 0 : value = tag_v->data;
10791 [ # # ]: 0 : mask = tag_m ? tag_m->data : UINT32_MAX;
10792 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10793 : : value = mask;
10794 [ # # ]: 0 : if (tag_v->id == REG_C_0) {
10795 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10796 : 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
10797 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
10798 : :
10799 : 0 : mask &= msk_c0;
10800 : 0 : mask <<= shl_c0;
10801 : 0 : value <<= shl_c0;
10802 : : }
10803 : 0 : flow_dv_match_meta_reg(key, tag_v->id, value, mask);
10804 : 0 : }
10805 : :
10806 : : /**
10807 : : * Add TAG item to matcher
10808 : : *
10809 : : * @param[in] dev
10810 : : * The devich to configure through.
10811 : : * @param[in, out] key
10812 : : * Flow matcher value.
10813 : : * @param[in] item
10814 : : * Flow pattern to translate.
10815 : : * @param[in] key_type
10816 : : * Set flow matcher mask or value.
10817 : : */
10818 : : static void
10819 : 0 : flow_dv_translate_item_tag(struct rte_eth_dev *dev, void *key,
10820 : : const struct rte_flow_item *item,
10821 : : uint32_t key_type)
10822 : : {
10823 : 0 : const struct rte_flow_item_tag *tag_vv = item->spec;
10824 : : const struct rte_flow_item_tag *tag_v;
10825 : : const struct rte_flow_item_tag *tag_m;
10826 : : int reg;
10827 : : uint32_t index;
10828 : :
10829 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10830 : : return;
10831 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, tag_v, tag_m,
# # # # ]
10832 : : &rte_flow_item_tag_mask);
10833 : : /* When set mask, the index should be from spec. */
10834 [ # # ]: 0 : index = tag_vv ? tag_vv->index : tag_v->index;
10835 : : /* Get the metadata register index for the tag. */
10836 [ # # ]: 0 : if (!!(key_type & MLX5_SET_MATCHER_SW))
10837 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, index, NULL);
10838 : : else
10839 : : reg = flow_hw_get_reg_id(dev, RTE_FLOW_ITEM_TYPE_TAG, index);
10840 : : MLX5_ASSERT(reg > 0);
10841 : 0 : flow_dv_match_meta_reg(key, (enum modify_reg)reg, tag_v->data, tag_m->data);
10842 : : }
10843 : :
10844 : : /**
10845 : : * Add source vport match to the specified matcher.
10846 : : *
10847 : : * @param[in, out] key
10848 : : * Flow matcher value.
10849 : : * @param[in] port
10850 : : * Source vport value to match
10851 : : */
10852 : : static void
10853 : : flow_dv_translate_item_source_vport(void *key,
10854 : : int16_t port)
10855 : : {
10856 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10857 : :
10858 [ # # # # : 0 : MLX5_SET(fte_match_set_misc, misc_v, source_port, port);
# # ]
10859 : 0 : }
10860 : :
10861 : : /**
10862 : : * Translate port-id item to eswitch match on port-id.
10863 : : *
10864 : : * @param[in] dev
10865 : : * The devich to configure through.
10866 : : * @param[in, out] key
10867 : : * Flow matcher value.
10868 : : * @param[in] item
10869 : : * Flow pattern to translate.
10870 : : * @param[in] attr
10871 : : * Flow attributes.
10872 : : * @param[in] key_type
10873 : : * Set flow matcher mask or value.
10874 : : *
10875 : : * @return
10876 : : * 0 on success, a negative errno value otherwise.
10877 : : */
10878 : : static int
10879 : 0 : flow_dv_translate_item_port_id(struct rte_eth_dev *dev, void *key,
10880 : : const struct rte_flow_item *item,
10881 : : const struct rte_flow_attr *attr,
10882 : : uint32_t key_type)
10883 : : {
10884 [ # # ]: 0 : const struct rte_flow_item_port_id *pid_m = item ? item->mask : NULL;
10885 [ # # ]: 0 : const struct rte_flow_item_port_id *pid_v = item ? item->spec : NULL;
10886 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
10887 : : struct mlx5_priv *priv;
10888 : : uint16_t mask, id;
10889 : : uint32_t vport_meta;
10890 : :
10891 : : MLX5_ASSERT(wks);
10892 [ # # # # ]: 0 : if (pid_v && pid_v->id == MLX5_PORT_ESW_MGR) {
10893 : 0 : priv = dev->data->dev_private;
10894 [ # # ]: 0 : if (priv->sh->dev_cap.esw_info.regc_mask) {
10895 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
10896 : : vport_meta = priv->sh->dev_cap.esw_info.regc_mask;
10897 : : } else {
10898 : 0 : vport_meta = priv->sh->dev_cap.esw_info.regc_value;
10899 : 0 : wks->vport_meta_tag = vport_meta;
10900 : : }
10901 : : flow_dv_translate_item_meta_vport(key, vport_meta,
10902 : : priv->sh->dev_cap.esw_info.regc_mask);
10903 : : } else {
10904 : 0 : flow_dv_translate_item_source_vport(key,
10905 [ # # ]: 0 : key_type & MLX5_SET_MATCHER_V ?
10906 : 0 : mlx5_flow_get_esw_manager_vport_id(dev) : 0xffff);
10907 : : }
10908 : 0 : return 0;
10909 : : }
10910 [ # # ]: 0 : mask = pid_m ? pid_m->id : 0xffff;
10911 [ # # ]: 0 : id = pid_v ? pid_v->id : dev->data->port_id;
10912 : 0 : priv = mlx5_port_to_eswitch_info(id, item == NULL);
10913 [ # # ]: 0 : if (!priv)
10914 : 0 : return -rte_errno;
10915 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
10916 : : id = mask;
10917 : 0 : vport_meta = priv->vport_meta_mask;
10918 : : } else {
10919 : 0 : id = priv->vport_id;
10920 : 0 : vport_meta = priv->vport_meta_tag;
10921 : 0 : wks->vport_meta_tag = vport_meta;
10922 : : }
10923 : : /*
10924 : : * Translate to vport field or to metadata, depending on mode.
10925 : : * Kernel can use either misc.source_port or half of C0 metadata
10926 : : * register.
10927 : : */
10928 [ # # ]: 0 : if (priv->vport_meta_mask) {
10929 : : /*
10930 : : * Provide the hint for SW steering library
10931 : : * to insert the flow into ingress domain and
10932 : : * save the extra vport match.
10933 : : */
10934 [ # # # # ]: 0 : if (mask == 0xffff && priv->vport_id == 0xffff &&
10935 [ # # # # ]: 0 : priv->pf_bond < 0 && attr->transfer)
10936 [ # # ]: 0 : flow_dv_translate_item_source_vport(key, id);
10937 : : /*
10938 : : * We should always set the vport metadata register,
10939 : : * otherwise the SW steering library can drop
10940 : : * the rule if wire vport metadata value is not zero,
10941 : : * it depends on kernel configuration.
10942 : : */
10943 : 0 : flow_dv_translate_item_meta_vport
10944 : : (key, vport_meta, priv->vport_meta_mask);
10945 : : } else {
10946 [ # # ]: 0 : flow_dv_translate_item_source_vport(key, id);
10947 : : }
10948 : : return 0;
10949 : : }
10950 : :
10951 : : /**
10952 : : * Translate port representor item to eswitch match on port id.
10953 : : *
10954 : : * @param[in] dev
10955 : : * The devich to configure through.
10956 : : * @param[in, out] key
10957 : : * Flow matcher value.
10958 : : * @param[in] key_type
10959 : : * Set flow matcher mask or value.
10960 : : *
10961 : : * @return
10962 : : * 0 on success, a negative errno value otherwise.
10963 : : */
10964 : : static int
10965 : 0 : flow_dv_translate_item_port_representor(struct rte_eth_dev *dev, void *key,
10966 : : uint32_t key_type)
10967 : : {
10968 : 0 : flow_dv_translate_item_source_vport(key,
10969 [ # # ]: 0 : key_type & MLX5_SET_MATCHER_V ?
10970 : 0 : mlx5_flow_get_esw_manager_vport_id(dev) : 0xffff);
10971 : 0 : return 0;
10972 : : }
10973 : :
10974 : : /**
10975 : : * Translate represented port item to eswitch match on port id.
10976 : : *
10977 : : * @param[in] dev
10978 : : * The devich to configure through.
10979 : : * @param[in, out] key
10980 : : * Flow matcher value.
10981 : : * @param[in] item
10982 : : * Flow pattern to translate.
10983 : : * @param[in]
10984 : : * Flow attributes.
10985 : : *
10986 : : * @return
10987 : : * 0 on success, a negative errno value otherwise.
10988 : : */
10989 : : static int
10990 : 0 : flow_dv_translate_item_represented_port(struct rte_eth_dev *dev, void *key,
10991 : : const struct rte_flow_item *item,
10992 : : const struct rte_flow_attr *attr,
10993 : : uint32_t key_type)
10994 : : {
10995 [ # # ]: 0 : const struct rte_flow_item_ethdev *pid_m = item ? item->mask : NULL;
10996 [ # # ]: 0 : const struct rte_flow_item_ethdev *pid_v = item ? item->spec : NULL;
10997 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
10998 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10999 : : uint16_t mask, id;
11000 : : uint32_t vport_meta;
11001 : : bool vport_match = false;
11002 : :
11003 : : MLX5_ASSERT(wks);
11004 : : #ifndef HAVE_IBV_DEVICE_ATTR_ESW_MGR_REG_C0
11005 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
11006 : : vport_match = true;
11007 : : #endif
11008 [ # # ]: 0 : if (!pid_m && !pid_v)
11009 : : return 0;
11010 [ # # # # ]: 0 : if (pid_v && pid_v->port_id == UINT16_MAX) {
11011 [ # # # # ]: 0 : if (priv->sh->config.dv_flow_en != 2 || vport_match) {
11012 : 0 : flow_dv_translate_item_source_vport
11013 [ # # ]: 0 : (key, key_type & MLX5_SET_MATCHER_V ?
11014 : 0 : mlx5_flow_get_esw_manager_vport_id(dev) : 0xffff);
11015 : : } else {
11016 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11017 : 0 : vport_meta = priv->sh->dev_cap.esw_info.regc_mask;
11018 : : else
11019 : 0 : vport_meta = priv->sh->dev_cap.esw_info.regc_value;
11020 : 0 : flow_dv_translate_item_meta_vport(key, vport_meta,
11021 : : priv->sh->dev_cap.esw_info.regc_mask);
11022 : : }
11023 : 0 : return 0;
11024 : : }
11025 [ # # ]: 0 : mask = pid_m ? pid_m->port_id : UINT16_MAX;
11026 [ # # ]: 0 : id = pid_v ? pid_v->port_id : dev->data->port_id;
11027 : 0 : priv = mlx5_port_to_eswitch_info(id, item == NULL);
11028 [ # # ]: 0 : if (!priv)
11029 : 0 : return -rte_errno;
11030 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
11031 : : id = mask;
11032 : 0 : vport_meta = priv->vport_meta_mask;
11033 : : } else {
11034 : 0 : id = priv->vport_id;
11035 : 0 : vport_meta = priv->vport_meta_tag;
11036 : 0 : wks->vport_meta_tag = vport_meta;
11037 : : }
11038 : : /*
11039 : : * Translate to vport field or to metadata, depending on mode.
11040 : : * Kernel can use either misc.source_port or half of C0 metadata
11041 : : * register.
11042 : : */
11043 [ # # # # ]: 0 : if (priv->vport_meta_mask && !vport_match) {
11044 : : /*
11045 : : * Provide the hint for SW steering library
11046 : : * to insert the flow into ingress domain and
11047 : : * save the extra vport match.
11048 : : */
11049 [ # # # # ]: 0 : if (mask == UINT16_MAX && priv->vport_id == UINT16_MAX &&
11050 [ # # # # ]: 0 : priv->pf_bond < 0 && attr->transfer &&
11051 [ # # ]: 0 : priv->sh->config.dv_flow_en != 2)
11052 [ # # ]: 0 : flow_dv_translate_item_source_vport(key, id);
11053 : : /*
11054 : : * We should always set the vport metadata register,
11055 : : * otherwise the SW steering library can drop
11056 : : * the rule if wire vport metadata value is not zero,
11057 : : * it depends on kernel configuration.
11058 : : */
11059 : 0 : flow_dv_translate_item_meta_vport(key, vport_meta,
11060 : : priv->vport_meta_mask);
11061 : : } else {
11062 [ # # ]: 0 : flow_dv_translate_item_source_vport(key, id);
11063 : : }
11064 : : return 0;
11065 : : }
11066 : :
11067 : : /**
11068 : : * Translate port-id item to eswitch match on port-id.
11069 : : *
11070 : : * @param[in] dev
11071 : : * The devich to configure through.
11072 : : * @param[in, out] matcher
11073 : : * Flow matcher.
11074 : : * @param[in, out] key
11075 : : * Flow matcher value.
11076 : : * @param[in] item
11077 : : * Flow pattern to translate.
11078 : : * @param[in] attr
11079 : : * Flow attributes.
11080 : : *
11081 : : * @return
11082 : : * 0 on success, a negative errno value otherwise.
11083 : : */
11084 : : static int
11085 : 0 : flow_dv_translate_item_port_id_all(struct rte_eth_dev *dev,
11086 : : void *matcher, void *key,
11087 : : const struct rte_flow_item *item,
11088 : : const struct rte_flow_attr *attr)
11089 : : {
11090 : : int ret;
11091 : :
11092 : 0 : ret = flow_dv_translate_item_port_id
11093 : : (dev, matcher, item, attr, MLX5_SET_MATCHER_SW_M);
11094 [ # # ]: 0 : if (ret)
11095 : : return ret;
11096 : 0 : ret = flow_dv_translate_item_port_id
11097 : : (dev, key, item, attr, MLX5_SET_MATCHER_SW_V);
11098 : 0 : return ret;
11099 : : }
11100 : :
11101 : :
11102 : : /**
11103 : : * Add ICMP6 item to the value.
11104 : : *
11105 : : * @param[in, out] key
11106 : : * Flow matcher value.
11107 : : * @param[in] item
11108 : : * Flow pattern to translate.
11109 : : * @param[in] inner
11110 : : * Item is inner pattern.
11111 : : * @param[in] key_type
11112 : : * Set flow matcher mask or value.
11113 : : */
11114 : : static void
11115 : 0 : flow_dv_translate_item_icmp6(void *key, const struct rte_flow_item *item,
11116 : : int inner, uint32_t key_type)
11117 : : {
11118 : : const struct rte_flow_item_icmp6 *icmp6_m;
11119 : : const struct rte_flow_item_icmp6 *icmp6_v;
11120 : : void *headers_v;
11121 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
11122 : :
11123 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
11124 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11125 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11126 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, 0xFF);
11127 : : else
11128 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
11129 : : IPPROTO_ICMPV6);
11130 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11131 : : return;
11132 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, icmp6_v, icmp6_m,
# # # # ]
11133 : : &rte_flow_item_icmp6_mask);
11134 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type,
11135 : : icmp6_v->type & icmp6_m->type);
11136 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code,
11137 : : icmp6_v->code & icmp6_m->code);
11138 : : }
11139 : :
11140 : : /**
11141 : : * Add ICMP6 echo request/reply item to the value.
11142 : : *
11143 : : * @param[in, out] key
11144 : : * Flow matcher value.
11145 : : * @param[in] item
11146 : : * Flow pattern to translate.
11147 : : * @param[in] inner
11148 : : * Item is inner pattern.
11149 : : * @param[in] key_type
11150 : : * Set flow matcher mask or value.
11151 : : */
11152 : : static void
11153 [ # # ]: 0 : flow_dv_translate_item_icmp6_echo(void *key, const struct rte_flow_item *item,
11154 : : int inner, uint32_t key_type)
11155 : : {
11156 : : const struct rte_flow_item_icmp6_echo *icmp6_m;
11157 : : const struct rte_flow_item_icmp6_echo *icmp6_v;
11158 : : uint32_t icmp6_header_data_m = 0;
11159 : : uint32_t icmp6_header_data_v = 0;
11160 : : void *headers_v;
11161 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
11162 : : uint8_t icmp6_type = 0;
11163 : : struct rte_flow_item_icmp6_echo zero_mask;
11164 : :
11165 : : memset(&zero_mask, 0, sizeof(zero_mask));
11166 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
11167 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11168 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11169 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, 0xFF);
11170 : : else
11171 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
11172 : : IPPROTO_ICMPV6);
11173 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, icmp6_v, icmp6_m, &zero_mask);
# # # # ]
11174 : : /* Set fixed type and code for icmpv6 echo request or reply */
11175 [ # # ]: 0 : icmp6_type = (item->type == RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REQUEST ?
11176 : : RTE_ICMP6_ECHO_REQUEST : RTE_ICMP6_ECHO_REPLY);
11177 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
11178 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type, 0xFF);
11179 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code, 0xFF);
11180 : : } else {
11181 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type, icmp6_type);
11182 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code, 0);
11183 : : }
11184 [ # # ]: 0 : if (icmp6_v == NULL)
11185 : 0 : return;
11186 : : /* Set icmp6 header data (identifier & sequence) accordingly */
11187 : 0 : icmp6_header_data_m =
11188 [ # # ]: 0 : (rte_be_to_cpu_16(icmp6_m->hdr.identifier) << 16) |
11189 [ # # ]: 0 : rte_be_to_cpu_16(icmp6_m->hdr.sequence);
11190 [ # # ]: 0 : if (icmp6_header_data_m) {
11191 : 0 : icmp6_header_data_v =
11192 [ # # ]: 0 : (rte_be_to_cpu_16(icmp6_v->hdr.identifier) << 16) |
11193 [ # # ]: 0 : rte_be_to_cpu_16(icmp6_v->hdr.sequence);
11194 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_header_data,
11195 : : icmp6_header_data_v & icmp6_header_data_m);
11196 : : }
11197 : : }
11198 : :
11199 : : /**
11200 : : * Add ICMP item to the value.
11201 : : *
11202 : : * @param[in, out] key
11203 : : * Flow matcher value.
11204 : : * @param[in] item
11205 : : * Flow pattern to translate.
11206 : : * @param[in] inner
11207 : : * Item is inner pattern.
11208 : : * @param[in] key_type
11209 : : * Set flow matcher mask or value.
11210 : : */
11211 : : static void
11212 : 0 : flow_dv_translate_item_icmp(void *key, const struct rte_flow_item *item,
11213 : : int inner, uint32_t key_type)
11214 : : {
11215 : : const struct rte_flow_item_icmp *icmp_m;
11216 : : const struct rte_flow_item_icmp *icmp_v;
11217 : : uint32_t icmp_header_data_m = 0;
11218 : : uint32_t icmp_header_data_v = 0;
11219 : : void *headers_v;
11220 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
11221 : :
11222 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
11223 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11224 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11225 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11226 : : ip_protocol, 0xFF);
11227 : : else
11228 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11229 : : ip_protocol, IPPROTO_ICMP);
11230 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11231 : : return;
11232 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, icmp_v, icmp_m,
# # # # ]
11233 : : &rte_flow_item_icmp_mask);
11234 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmp_type,
11235 : : icmp_v->hdr.icmp_type & icmp_m->hdr.icmp_type);
11236 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmp_code,
11237 : : icmp_v->hdr.icmp_code & icmp_m->hdr.icmp_code);
11238 [ # # ]: 0 : icmp_header_data_m = rte_be_to_cpu_16(icmp_m->hdr.icmp_seq_nb);
11239 [ # # ]: 0 : icmp_header_data_m |= rte_be_to_cpu_16(icmp_m->hdr.icmp_ident) << 16;
11240 [ # # ]: 0 : if (icmp_header_data_m) {
11241 [ # # ]: 0 : icmp_header_data_v = rte_be_to_cpu_16(icmp_v->hdr.icmp_seq_nb);
11242 : 0 : icmp_header_data_v |=
11243 [ # # ]: 0 : rte_be_to_cpu_16(icmp_v->hdr.icmp_ident) << 16;
11244 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmp_header_data,
11245 : : icmp_header_data_v & icmp_header_data_m);
11246 : : }
11247 : : }
11248 : :
11249 : : /**
11250 : : * Add GTP item to the value.
11251 : : *
11252 : : * @param[in, out] key
11253 : : * Flow matcher value.
11254 : : * @param[in] item
11255 : : * Flow pattern to translate.
11256 : : * @param[in] inner
11257 : : * Item is inner pattern.
11258 : : * @param[in] key_type
11259 : : * Set flow matcher mask or value.
11260 : : */
11261 : : static void
11262 : 0 : flow_dv_translate_item_gtp(void *key, const struct rte_flow_item *item,
11263 : : int inner, uint32_t key_type)
11264 : : {
11265 : : const struct rte_flow_item_gtp *gtp_m;
11266 : : const struct rte_flow_item_gtp *gtp_v;
11267 : : void *headers_v;
11268 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
11269 : : uint16_t dport = RTE_GTPU_UDP_PORT;
11270 : :
11271 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
11272 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11273 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
11274 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11275 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11276 : : udp_dport, 0xFFFF);
11277 : : else
11278 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11279 : : udp_dport, dport);
11280 : : }
11281 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11282 : : return;
11283 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, gtp_v, gtp_m,
# # # # ]
11284 : : &rte_flow_item_gtp_mask);
11285 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags,
11286 : : gtp_v->hdr.gtp_hdr_info & gtp_m->hdr.gtp_hdr_info);
11287 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_type,
11288 : : gtp_v->hdr.msg_type & gtp_m->hdr.msg_type);
11289 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_teid,
11290 : : rte_be_to_cpu_32(gtp_v->hdr.teid & gtp_m->hdr.teid));
11291 : : }
11292 : :
11293 : : /**
11294 : : * Add GTP PSC item to matcher.
11295 : : *
11296 : : * @param[in, out] key
11297 : : * Flow matcher value.
11298 : : * @param[in] item
11299 : : * Flow pattern to translate.
11300 : : * @param[in] key_type
11301 : : * Set flow matcher mask or value.
11302 : : */
11303 : : static int
11304 : 0 : flow_dv_translate_item_gtp_psc(void *key, const struct rte_flow_item *item,
11305 : : uint32_t key_type)
11306 : : {
11307 : : const struct rte_flow_item_gtp_psc *gtp_psc_m;
11308 : : const struct rte_flow_item_gtp_psc *gtp_psc_v;
11309 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
11310 : : union {
11311 : : uint32_t w32;
11312 : : struct {
11313 : : uint16_t seq_num;
11314 : : uint8_t npdu_num;
11315 : : uint8_t next_ext_header_type;
11316 : : };
11317 : : } dw_2;
11318 : : union {
11319 : : uint32_t w32;
11320 : : struct {
11321 : : uint8_t len;
11322 : : uint8_t type_flags;
11323 : : uint8_t qfi;
11324 : : uint8_t reserved;
11325 : : };
11326 : : } dw_0;
11327 : : uint8_t gtp_flags;
11328 : :
11329 : : /* Always set E-flag match on one, regardless of GTP item settings. */
11330 [ # # ]: 0 : gtp_flags = MLX5_GET(fte_match_set_misc3, misc3_v, gtpu_msg_flags);
11331 : 0 : gtp_flags |= MLX5_GTP_EXT_HEADER_FLAG;
11332 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags, gtp_flags);
11333 : : /*Set next extension header type. */
11334 : 0 : dw_2.seq_num = 0;
11335 : 0 : dw_2.npdu_num = 0;
11336 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11337 : 0 : dw_2.next_ext_header_type = 0xff;
11338 : : else
11339 : 0 : dw_2.next_ext_header_type = 0x85;
11340 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_dw_2,
11341 : : rte_cpu_to_be_32(dw_2.w32));
11342 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11343 : : return 0;
11344 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, gtp_psc_v,
# # # # ]
11345 : : gtp_psc_m, &rte_flow_item_gtp_psc_mask);
11346 : 0 : dw_0.w32 = 0;
11347 : 0 : dw_0.type_flags = MLX5_GTP_PDU_TYPE_SHIFT(gtp_psc_v->hdr.type &
11348 : : gtp_psc_m->hdr.type);
11349 : 0 : dw_0.qfi = gtp_psc_v->hdr.qfi & gtp_psc_m->hdr.qfi;
11350 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_first_ext_dw_0,
11351 : : rte_cpu_to_be_32(dw_0.w32));
11352 : 0 : return 0;
11353 : : }
11354 : :
11355 : : /**
11356 : : * Add eCPRI item to matcher and to the value.
11357 : : *
11358 : : * @param[in] dev
11359 : : * The devich to configure through.
11360 : : * @param[in, out] key
11361 : : * Flow matcher value.
11362 : : * @param[in] item
11363 : : * Flow pattern to translate.
11364 : : * @param[in] last_item
11365 : : * Last item flags.
11366 : : * @param[in] key_type
11367 : : * Set flow matcher mask or value.
11368 : : */
11369 : : static void
11370 : 0 : flow_dv_translate_item_ecpri(struct rte_eth_dev *dev, void *key,
11371 : : const struct rte_flow_item *item,
11372 : : uint64_t last_item, uint32_t key_type)
11373 : : {
11374 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11375 : : const struct rte_flow_item_ecpri *ecpri_m;
11376 : : const struct rte_flow_item_ecpri *ecpri_v;
11377 : 0 : const struct rte_flow_item_ecpri *ecpri_vv = item->spec;
11378 : : struct rte_ecpri_common_hdr common;
11379 : : void *misc4_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_4);
11380 : : uint32_t *samples;
11381 : : void *dw_v;
11382 : :
11383 : : /*
11384 : : * In case of eCPRI over Ethernet, if EtherType is not specified,
11385 : : * match on eCPRI EtherType implicitly.
11386 : : */
11387 [ # # ]: 0 : if (last_item & MLX5_FLOW_LAYER_OUTER_L2) {
11388 : : void *hdrs_v, *l2v;
11389 : :
11390 : : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11391 : : l2v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, ethertype);
11392 [ # # ]: 0 : if (*(uint16_t *)l2v == 0) {
11393 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11394 : 0 : *(uint16_t *)l2v = UINT16_MAX;
11395 : : else
11396 : 0 : *(uint16_t *)l2v =
11397 : : RTE_BE16(RTE_ETHER_TYPE_ECPRI);
11398 : : }
11399 : : }
11400 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11401 : 0 : return;
11402 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, ecpri_v, ecpri_m,
# # # # ]
11403 : : &rte_flow_item_ecpri_mask);
11404 : : /*
11405 : : * Maximal four DW samples are supported in a single matching now.
11406 : : * Two are used now for a eCPRI matching:
11407 : : * 1. Type: one byte, mask should be 0x00ff0000 in network order
11408 : : * 2. ID of a message: one or two bytes, mask 0xffff0000 or 0xff000000
11409 : : * if any.
11410 : : */
11411 [ # # ]: 0 : if (!ecpri_m->hdr.common.u32)
11412 : : return;
11413 : 0 : samples = priv->sh->ecpri_parser.ids;
11414 : : /* Need to take the whole DW as the mask to fill the entry. */
11415 : : dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
11416 : : prog_sample_field_value_0);
11417 : : /* Already big endian (network order) in the header. */
11418 : 0 : *(uint32_t *)dw_v = ecpri_v->hdr.common.u32 & ecpri_m->hdr.common.u32;
11419 : : /* Sample#0, used for matching type, offset 0. */
11420 : : /* It makes no sense to set the sample ID in the mask field. */
11421 [ # # ]: 0 : MLX5_SET(fte_match_set_misc4, misc4_v,
11422 : : prog_sample_field_id_0, samples[0]);
11423 : : /*
11424 : : * Checking if message body part needs to be matched.
11425 : : * Some wildcard rules only matching type field should be supported.
11426 : : */
11427 [ # # ]: 0 : if (ecpri_m->hdr.dummy[0]) {
11428 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M)
11429 [ # # ]: 0 : common.u32 = rte_be_to_cpu_32(ecpri_vv->hdr.common.u32);
11430 : : else
11431 [ # # ]: 0 : common.u32 = rte_be_to_cpu_32(ecpri_v->hdr.common.u32);
11432 [ # # ]: 0 : switch (common.type) {
11433 : 0 : case RTE_ECPRI_MSG_TYPE_IQ_DATA:
11434 : : case RTE_ECPRI_MSG_TYPE_RTC_CTRL:
11435 : : case RTE_ECPRI_MSG_TYPE_DLY_MSR:
11436 : : dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
11437 : : prog_sample_field_value_1);
11438 : 0 : *(uint32_t *)dw_v = ecpri_v->hdr.dummy[0] &
11439 : : ecpri_m->hdr.dummy[0];
11440 : : /* Sample#1, to match message body, offset 4. */
11441 [ # # ]: 0 : MLX5_SET(fte_match_set_misc4, misc4_v,
11442 : : prog_sample_field_id_1, samples[1]);
11443 : 0 : break;
11444 : : default:
11445 : : /* Others, do not match any sample ID. */
11446 : : break;
11447 : : }
11448 : : }
11449 : : }
11450 : :
11451 : : /*
11452 : : * Add connection tracking status item to matcher
11453 : : *
11454 : : * @param[in] dev
11455 : : * The devich to configure through.
11456 : : * @param[in, out] matcher
11457 : : * Flow matcher.
11458 : : * @param[in, out] key
11459 : : * Flow matcher value.
11460 : : * @param[in] item
11461 : : * Flow pattern to translate.
11462 : : */
11463 : : static void
11464 : 0 : flow_dv_translate_item_aso_ct(struct rte_eth_dev *dev,
11465 : : void *matcher, void *key,
11466 : : const struct rte_flow_item *item)
11467 : : {
11468 : : uint32_t reg_value = 0;
11469 : : int reg_id;
11470 : : /* 8LSB 0b 11/0000/11, middle 4 bits are reserved. */
11471 : : uint32_t reg_mask = 0;
11472 : 0 : const struct rte_flow_item_conntrack *spec = item->spec;
11473 : 0 : const struct rte_flow_item_conntrack *mask = item->mask;
11474 : : uint32_t flags;
11475 : : struct rte_flow_error error;
11476 : :
11477 [ # # ]: 0 : if (!mask)
11478 : : mask = &rte_flow_item_conntrack_mask;
11479 [ # # # # ]: 0 : if (!spec || !mask->flags)
11480 : 0 : return;
11481 : 0 : flags = spec->flags & mask->flags;
11482 : : /* The conflict should be checked in the validation. */
11483 : : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_VALID)
11484 : : reg_value |= MLX5_CT_SYNDROME_VALID;
11485 [ # # ]: 0 : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_CHANGED)
11486 : : reg_value |= MLX5_CT_SYNDROME_STATE_CHANGE;
11487 [ # # ]: 0 : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_INVALID)
11488 : 0 : reg_value |= MLX5_CT_SYNDROME_INVALID;
11489 [ # # ]: 0 : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED)
11490 : 0 : reg_value |= MLX5_CT_SYNDROME_TRAP;
11491 [ # # ]: 0 : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD)
11492 : 0 : reg_value |= MLX5_CT_SYNDROME_BAD_PACKET;
11493 [ # # ]: 0 : if (mask->flags & (RTE_FLOW_CONNTRACK_PKT_STATE_VALID |
11494 : : RTE_FLOW_CONNTRACK_PKT_STATE_INVALID |
11495 : : RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED))
11496 : : reg_mask |= 0xc0;
11497 [ # # ]: 0 : if (mask->flags & RTE_FLOW_CONNTRACK_PKT_STATE_CHANGED)
11498 : 0 : reg_mask |= MLX5_CT_SYNDROME_STATE_CHANGE;
11499 [ # # ]: 0 : if (mask->flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD)
11500 : 0 : reg_mask |= MLX5_CT_SYNDROME_BAD_PACKET;
11501 : : /* The REG_C_x value could be saved during startup. */
11502 : 0 : reg_id = mlx5_flow_get_reg_id(dev, MLX5_ASO_CONNTRACK, 0, &error);
11503 [ # # ]: 0 : if (reg_id == REG_NON)
11504 : : return;
11505 : 0 : flow_dv_match_meta_reg_all(matcher, key, (enum modify_reg)reg_id,
11506 : : reg_value, reg_mask);
11507 : : }
11508 : :
11509 : : static void
11510 : 0 : flow_dv_translate_item_flex(struct rte_eth_dev *dev, void *matcher, void *key,
11511 : : const struct rte_flow_item *item,
11512 : : struct mlx5_flow *dev_flow, bool is_inner)
11513 : : {
11514 : 0 : const struct rte_flow_item_flex *spec =
11515 : : (const struct rte_flow_item_flex *)item->spec;
11516 : 0 : int index = mlx5_flex_acquire_index(dev, spec->handle, false);
11517 : :
11518 : : MLX5_ASSERT(index >= 0 && index < (int)(sizeof(uint32_t) * CHAR_BIT));
11519 [ # # ]: 0 : if (index < 0)
11520 : : return;
11521 [ # # ]: 0 : if (!(dev_flow->handle->flex_item & RTE_BIT32(index))) {
11522 : : /* Don't count both inner and outer flex items in one rule. */
11523 : 0 : if (mlx5_flex_acquire_index(dev, spec->handle, true) != index)
11524 : : MLX5_ASSERT(false);
11525 : 0 : dev_flow->handle->flex_item |= (uint8_t)RTE_BIT32(index);
11526 : : }
11527 : 0 : mlx5_flex_flow_translate_item(dev, matcher, key, item, is_inner);
11528 : : }
11529 : :
11530 : : /**
11531 : : * Add METER_COLOR item to matcher
11532 : : *
11533 : : * @param[in] dev
11534 : : * The device to configure through.
11535 : : * @param[in, out] key
11536 : : * Flow matcher value.
11537 : : * @param[in] item
11538 : : * Flow pattern to translate.
11539 : : * @param[in] key_type
11540 : : * Set flow matcher mask or value.
11541 : : */
11542 : : static void
11543 : 0 : flow_dv_translate_item_meter_color(struct rte_eth_dev *dev, void *key,
11544 : : const struct rte_flow_item *item,
11545 : : uint32_t key_type)
11546 : : {
11547 : 0 : const struct rte_flow_item_meter_color *color_m = item->mask;
11548 : 0 : const struct rte_flow_item_meter_color *color_v = item->spec;
11549 : : uint32_t value, mask;
11550 : : int reg = REG_NON;
11551 : :
11552 : : MLX5_ASSERT(color_v);
11553 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11554 : : return;
11555 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, color_v, color_m,
# # # # ]
11556 : : &rte_flow_item_meter_color_mask);
11557 [ # # ]: 0 : value = rte_col_2_mlx5_col(color_v->color);
11558 : : mask = color_m ?
11559 [ # # ]: 0 : color_m->color : (UINT32_C(1) << MLX5_MTR_COLOR_BITS) - 1;
11560 [ # # ]: 0 : if (!!(key_type & MLX5_SET_MATCHER_SW))
11561 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, NULL);
11562 : : else
11563 : : reg = flow_hw_get_reg_id(dev,
11564 : : RTE_FLOW_ITEM_TYPE_METER_COLOR, 0);
11565 [ # # ]: 0 : if (reg == REG_NON)
11566 : : return;
11567 : 0 : flow_dv_match_meta_reg(key, (enum modify_reg)reg, value, mask);
11568 : : }
11569 : :
11570 : : static void
11571 : 0 : flow_dv_translate_item_aggr_affinity(void *key,
11572 : : const struct rte_flow_item *item,
11573 : : uint32_t key_type)
11574 : : {
11575 : : const struct rte_flow_item_aggr_affinity *affinity_v;
11576 : : const struct rte_flow_item_aggr_affinity *affinity_m;
11577 : : void *misc_v;
11578 : :
11579 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, affinity_v, affinity_m,
# # # # ]
11580 : : &rte_flow_item_aggr_affinity_mask);
11581 : : misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
11582 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, lag_rx_port_affinity,
11583 : : affinity_v->affinity & affinity_m->affinity);
11584 : 0 : }
11585 : :
11586 : : static void
11587 : 0 : flow_dv_translate_item_ib_bth(void *key,
11588 : : const struct rte_flow_item *item,
11589 : : int inner, uint32_t key_type)
11590 : : {
11591 : : const struct rte_flow_item_ib_bth *bth_m;
11592 : : const struct rte_flow_item_ib_bth *bth_v;
11593 : : void *headers_v, *misc_v;
11594 : : uint16_t udp_dport;
11595 : : char *qpn_v;
11596 : : int i, size;
11597 : :
11598 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
11599 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11600 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
11601 [ # # ]: 0 : udp_dport = key_type & MLX5_SET_MATCHER_M ?
11602 : : 0xFFFF : MLX5_UDP_PORT_ROCEv2;
11603 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, udp_dport);
11604 : : }
11605 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11606 : : return;
11607 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, bth_v, bth_m, &rte_flow_item_ib_bth_mask);
# # # # ]
11608 : : misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
11609 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, bth_opcode,
11610 : : bth_v->hdr.opcode & bth_m->hdr.opcode);
11611 : 0 : qpn_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, bth_dst_qp);
11612 : : size = sizeof(bth_m->hdr.dst_qp);
11613 [ # # ]: 0 : for (i = 0; i < size; ++i)
11614 : 0 : qpn_v[i] = bth_m->hdr.dst_qp[i] & bth_v->hdr.dst_qp[i];
11615 : : }
11616 : :
11617 : : static uint32_t matcher_zero[MLX5_ST_SZ_DW(fte_match_param)] = { 0 };
11618 : :
11619 : : #define HEADER_IS_ZERO(match_criteria, headers) \
11620 : : !(memcmp(MLX5_ADDR_OF(fte_match_param, match_criteria, headers), \
11621 : : matcher_zero, MLX5_FLD_SZ_BYTES(fte_match_param, headers))) \
11622 : :
11623 : : /**
11624 : : * Calculate flow matcher enable bitmap.
11625 : : *
11626 : : * @param match_criteria
11627 : : * Pointer to flow matcher criteria.
11628 : : *
11629 : : * @return
11630 : : * Bitmap of enabled fields.
11631 : : */
11632 : : static uint8_t
11633 : 0 : flow_dv_matcher_enable(uint32_t *match_criteria)
11634 : : {
11635 : : uint8_t match_criteria_enable;
11636 : :
11637 : : match_criteria_enable =
11638 : 0 : (!HEADER_IS_ZERO(match_criteria, outer_headers)) <<
11639 : : MLX5_MATCH_CRITERIA_ENABLE_OUTER_BIT;
11640 : 0 : match_criteria_enable |=
11641 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters)) <<
11642 : : MLX5_MATCH_CRITERIA_ENABLE_MISC_BIT;
11643 : 0 : match_criteria_enable |=
11644 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, inner_headers)) <<
11645 : : MLX5_MATCH_CRITERIA_ENABLE_INNER_BIT;
11646 : 0 : match_criteria_enable |=
11647 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) <<
11648 : : MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
11649 : 0 : match_criteria_enable |=
11650 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters_3)) <<
11651 : : MLX5_MATCH_CRITERIA_ENABLE_MISC3_BIT;
11652 : 0 : match_criteria_enable |=
11653 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters_4)) <<
11654 : : MLX5_MATCH_CRITERIA_ENABLE_MISC4_BIT;
11655 : 0 : match_criteria_enable |=
11656 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters_5)) <<
11657 : : MLX5_MATCH_CRITERIA_ENABLE_MISC5_BIT;
11658 : 0 : return match_criteria_enable;
11659 : : }
11660 : :
11661 : : static void
11662 : : __flow_dv_adjust_buf_size(size_t *size, uint8_t match_criteria)
11663 : : {
11664 : : /*
11665 : : * Check flow matching criteria first, subtract misc5/4 length if flow
11666 : : * doesn't own misc5/4 parameters. In some old rdma-core releases,
11667 : : * misc5/4 are not supported, and matcher creation failure is expected
11668 : : * w/o subtraction. If misc5 is provided, misc4 must be counted in since
11669 : : * misc5 is right after misc4.
11670 : : */
11671 : 0 : if (!(match_criteria & (1 << MLX5_MATCH_CRITERIA_ENABLE_MISC5_BIT))) {
11672 : 0 : *size = MLX5_ST_SZ_BYTES(fte_match_param) -
11673 : : MLX5_ST_SZ_BYTES(fte_match_set_misc5);
11674 [ # # # # : 0 : if (!(match_criteria & (1 <<
# # # # #
# # # # #
# # # # #
# ]
11675 : : MLX5_MATCH_CRITERIA_ENABLE_MISC4_BIT))) {
11676 : 0 : *size -= MLX5_ST_SZ_BYTES(fte_match_set_misc4);
11677 : : }
11678 : : }
11679 : : }
11680 : :
11681 : : struct mlx5_list_entry *
11682 : 0 : flow_matcher_clone_cb(void *tool_ctx __rte_unused,
11683 : : struct mlx5_list_entry *entry, void *cb_ctx)
11684 : : {
11685 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11686 : 0 : struct mlx5_flow_dv_matcher *ref = ctx->data;
11687 : 0 : struct mlx5_flow_tbl_data_entry *tbl = container_of(ref->tbl,
11688 : : typeof(*tbl), tbl);
11689 : 0 : struct mlx5_flow_dv_matcher *resource = mlx5_malloc(MLX5_MEM_ANY,
11690 : : sizeof(*resource),
11691 : : 0, SOCKET_ID_ANY);
11692 : :
11693 [ # # ]: 0 : if (!resource) {
11694 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
11695 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11696 : : "cannot create matcher");
11697 : 0 : return NULL;
11698 : : }
11699 : : memcpy(resource, entry, sizeof(*resource));
11700 : 0 : resource->tbl = &tbl->tbl;
11701 : 0 : return &resource->entry;
11702 : : }
11703 : :
11704 : : void
11705 : 0 : flow_matcher_clone_free_cb(void *tool_ctx __rte_unused,
11706 : : struct mlx5_list_entry *entry)
11707 : : {
11708 : 0 : mlx5_free(entry);
11709 : 0 : }
11710 : :
11711 : : struct mlx5_list_entry *
11712 : 0 : flow_dv_tbl_create_cb(void *tool_ctx, void *cb_ctx)
11713 : : {
11714 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11715 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11716 : 0 : struct rte_eth_dev *dev = ctx->dev;
11717 : : struct mlx5_flow_tbl_data_entry *tbl_data;
11718 : 0 : struct mlx5_flow_tbl_tunnel_prm *tt_prm = ctx->data2;
11719 : 0 : struct rte_flow_error *error = ctx->error;
11720 : 0 : union mlx5_flow_tbl_key key = { .v64 = *(uint64_t *)(ctx->data) };
11721 : : struct mlx5_flow_tbl_resource *tbl;
11722 : : void *domain;
11723 : 0 : uint32_t idx = 0;
11724 : : int ret;
11725 : :
11726 : 0 : tbl_data = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_JUMP], &idx);
11727 [ # # ]: 0 : if (!tbl_data) {
11728 : 0 : rte_flow_error_set(error, ENOMEM,
11729 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11730 : : NULL,
11731 : : "cannot allocate flow table data entry");
11732 : 0 : return NULL;
11733 : : }
11734 : 0 : tbl_data->idx = idx;
11735 : 0 : tbl_data->tunnel = tt_prm->tunnel;
11736 : 0 : tbl_data->group_id = tt_prm->group_id;
11737 [ # # ]: 0 : tbl_data->external = !!tt_prm->external;
11738 : 0 : tbl_data->tunnel_offload = is_tunnel_offload_active(dev);
11739 : 0 : tbl_data->is_egress = !!key.is_egress;
11740 : 0 : tbl_data->is_transfer = !!key.is_fdb;
11741 : 0 : tbl_data->dummy = !!key.dummy;
11742 : 0 : tbl_data->level = key.level;
11743 : 0 : tbl_data->id = key.id;
11744 : : tbl = &tbl_data->tbl;
11745 [ # # ]: 0 : if (key.dummy)
11746 : 0 : return &tbl_data->entry;
11747 [ # # ]: 0 : if (key.is_fdb)
11748 : 0 : domain = sh->fdb_domain;
11749 [ # # ]: 0 : else if (key.is_egress)
11750 : 0 : domain = sh->tx_domain;
11751 : : else
11752 : 0 : domain = sh->rx_domain;
11753 : : ret = mlx5_flow_os_create_flow_tbl(domain, key.level, &tbl->obj);
11754 : : if (ret) {
11755 : 0 : rte_flow_error_set(error, ENOMEM,
11756 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11757 : : NULL, "cannot create flow table object");
11758 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
11759 : 0 : return NULL;
11760 : : }
11761 [ # # ]: 0 : if (key.level != 0) {
11762 : : ret = mlx5_flow_os_create_flow_action_dest_flow_tbl
11763 : : (tbl->obj, &tbl_data->jump.action);
11764 : : if (ret) {
11765 : 0 : rte_flow_error_set(error, ENOMEM,
11766 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11767 : : NULL,
11768 : : "cannot create flow jump action");
11769 : 0 : mlx5_flow_os_destroy_flow_tbl(tbl->obj);
11770 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
11771 : 0 : return NULL;
11772 : : }
11773 : : }
11774 [ # # # # ]: 0 : MKSTR(matcher_name, "%s_%s_%u_%u_matcher_list",
11775 : : key.is_fdb ? "FDB" : "NIC", key.is_egress ? "egress" : "ingress",
11776 : : key.level, key.id);
11777 : 0 : tbl_data->matchers = mlx5_list_create(matcher_name, sh, true,
11778 : : flow_matcher_create_cb,
11779 : : flow_matcher_match_cb,
11780 : : flow_matcher_remove_cb,
11781 : : flow_matcher_clone_cb,
11782 : : flow_matcher_clone_free_cb);
11783 [ # # ]: 0 : if (!tbl_data->matchers) {
11784 : 0 : rte_flow_error_set(error, ENOMEM,
11785 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11786 : : NULL,
11787 : : "cannot create tbl matcher list");
11788 : 0 : mlx5_flow_os_destroy_flow_action(tbl_data->jump.action);
11789 : 0 : mlx5_flow_os_destroy_flow_tbl(tbl->obj);
11790 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
11791 : 0 : return NULL;
11792 : : }
11793 : 0 : return &tbl_data->entry;
11794 : : }
11795 : :
11796 : : int
11797 : 0 : flow_dv_tbl_match_cb(void *tool_ctx __rte_unused, struct mlx5_list_entry *entry,
11798 : : void *cb_ctx)
11799 : : {
11800 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11801 : : struct mlx5_flow_tbl_data_entry *tbl_data =
11802 : : container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
11803 : 0 : union mlx5_flow_tbl_key key = { .v64 = *(uint64_t *)(ctx->data) };
11804 : :
11805 : 0 : return tbl_data->level != key.level ||
11806 [ # # ]: 0 : tbl_data->id != key.id ||
11807 [ # # ]: 0 : tbl_data->dummy != key.dummy ||
11808 [ # # # # ]: 0 : tbl_data->is_transfer != !!key.is_fdb ||
11809 [ # # ]: 0 : tbl_data->is_egress != !!key.is_egress;
11810 : : }
11811 : :
11812 : : struct mlx5_list_entry *
11813 : 0 : flow_dv_tbl_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
11814 : : void *cb_ctx)
11815 : : {
11816 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11817 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11818 : : struct mlx5_flow_tbl_data_entry *tbl_data;
11819 : 0 : struct rte_flow_error *error = ctx->error;
11820 : 0 : uint32_t idx = 0;
11821 : :
11822 : 0 : tbl_data = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_JUMP], &idx);
11823 [ # # ]: 0 : if (!tbl_data) {
11824 : 0 : rte_flow_error_set(error, ENOMEM,
11825 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11826 : : NULL,
11827 : : "cannot allocate flow table data entry");
11828 : 0 : return NULL;
11829 : : }
11830 : : memcpy(tbl_data, oentry, sizeof(*tbl_data));
11831 : 0 : tbl_data->idx = idx;
11832 : 0 : return &tbl_data->entry;
11833 : : }
11834 : :
11835 : : void
11836 : 0 : flow_dv_tbl_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
11837 : : {
11838 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11839 : : struct mlx5_flow_tbl_data_entry *tbl_data =
11840 : : container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
11841 : :
11842 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], tbl_data->idx);
11843 : 0 : }
11844 : :
11845 : : /**
11846 : : * Get a flow table.
11847 : : *
11848 : : * @param[in, out] dev
11849 : : * Pointer to rte_eth_dev structure.
11850 : : * @param[in] table_level
11851 : : * Table level to use.
11852 : : * @param[in] egress
11853 : : * Direction of the table.
11854 : : * @param[in] transfer
11855 : : * E-Switch or NIC flow.
11856 : : * @param[in] dummy
11857 : : * Dummy entry for dv API.
11858 : : * @param[in] table_id
11859 : : * Table id to use.
11860 : : * @param[out] error
11861 : : * pointer to error structure.
11862 : : *
11863 : : * @return
11864 : : * Returns tables resource based on the index, NULL in case of failed.
11865 : : */
11866 : : struct mlx5_flow_tbl_resource *
11867 : 0 : flow_dv_tbl_resource_get(struct rte_eth_dev *dev,
11868 : : uint32_t table_level, uint8_t egress,
11869 : : uint8_t transfer,
11870 : : bool external,
11871 : : const struct mlx5_flow_tunnel *tunnel,
11872 : : uint32_t group_id, uint8_t dummy,
11873 : : uint32_t table_id,
11874 : : struct rte_flow_error *error)
11875 : : {
11876 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11877 : 0 : union mlx5_flow_tbl_key table_key = {
11878 : : {
11879 : : .level = table_level,
11880 : : .id = table_id,
11881 : : .reserved = 0,
11882 : 0 : .dummy = !!dummy,
11883 : 0 : .is_fdb = !!transfer,
11884 : 0 : .is_egress = !!egress,
11885 : : }
11886 : : };
11887 : 0 : struct mlx5_flow_tbl_tunnel_prm tt_prm = {
11888 : : .tunnel = tunnel,
11889 : : .group_id = group_id,
11890 : : .external = external,
11891 : : };
11892 : 0 : struct mlx5_flow_cb_ctx ctx = {
11893 : : .dev = dev,
11894 : : .error = error,
11895 : : .data = &table_key.v64,
11896 : : .data2 = &tt_prm,
11897 : : };
11898 : : struct mlx5_list_entry *entry;
11899 : : struct mlx5_flow_tbl_data_entry *tbl_data;
11900 : :
11901 : 0 : entry = mlx5_hlist_register(priv->sh->flow_tbls, table_key.v64, &ctx);
11902 [ # # ]: 0 : if (!entry) {
11903 : 0 : rte_flow_error_set(error, ENOMEM,
11904 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11905 : : "cannot get table");
11906 : 0 : return NULL;
11907 : : }
11908 [ # # ]: 0 : DRV_LOG(DEBUG, "table_level %u table_id %u "
11909 : : "tunnel %u group %u registered.",
11910 : : table_level, table_id,
11911 : : tunnel ? tunnel->tunnel_id : 0, group_id);
11912 : : tbl_data = container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
11913 : 0 : return &tbl_data->tbl;
11914 : : }
11915 : :
11916 : : void
11917 : 0 : flow_dv_tbl_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
11918 : : {
11919 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11920 : : struct mlx5_flow_tbl_data_entry *tbl_data =
11921 : : container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
11922 : :
11923 : : MLX5_ASSERT(entry && sh);
11924 [ # # ]: 0 : if (tbl_data->jump.action)
11925 : : mlx5_flow_os_destroy_flow_action(tbl_data->jump.action);
11926 [ # # ]: 0 : if (tbl_data->tbl.obj)
11927 : : mlx5_flow_os_destroy_flow_tbl(tbl_data->tbl.obj);
11928 [ # # ]: 0 : if (tbl_data->tunnel_offload && tbl_data->external) {
11929 : : struct mlx5_list_entry *he;
11930 : : struct mlx5_hlist *tunnel_grp_hash;
11931 : 0 : struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
11932 : 0 : union tunnel_tbl_key tunnel_key = {
11933 : 0 : .tunnel_id = tbl_data->tunnel ?
11934 [ # # ]: 0 : tbl_data->tunnel->tunnel_id : 0,
11935 : 0 : .group = tbl_data->group_id
11936 : : };
11937 : 0 : uint32_t table_level = tbl_data->level;
11938 : 0 : struct mlx5_flow_cb_ctx ctx = {
11939 : : .data = (void *)&tunnel_key.val,
11940 : : };
11941 : :
11942 : : tunnel_grp_hash = tbl_data->tunnel ?
11943 [ # # ]: 0 : tbl_data->tunnel->groups :
11944 : : thub->groups;
11945 : 0 : he = mlx5_hlist_lookup(tunnel_grp_hash, tunnel_key.val, &ctx);
11946 [ # # ]: 0 : if (he)
11947 : 0 : mlx5_hlist_unregister(tunnel_grp_hash, he);
11948 [ # # ]: 0 : DRV_LOG(DEBUG,
11949 : : "table_level %u id %u tunnel %u group %u released.",
11950 : : table_level,
11951 : : tbl_data->id,
11952 : : tbl_data->tunnel ?
11953 : : tbl_data->tunnel->tunnel_id : 0,
11954 : : tbl_data->group_id);
11955 : : }
11956 [ # # ]: 0 : if (tbl_data->matchers)
11957 : 0 : mlx5_list_destroy(tbl_data->matchers);
11958 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], tbl_data->idx);
11959 : 0 : }
11960 : :
11961 : : /**
11962 : : * Release a flow table.
11963 : : *
11964 : : * @param[in] sh
11965 : : * Pointer to device shared structure.
11966 : : * @param[in] tbl
11967 : : * Table resource to be released.
11968 : : *
11969 : : * @return
11970 : : * Returns 0 if table was released, else return 1;
11971 : : */
11972 : : int
11973 : 0 : flow_dv_tbl_resource_release(struct mlx5_dev_ctx_shared *sh,
11974 : : struct mlx5_flow_tbl_resource *tbl)
11975 : : {
11976 : : struct mlx5_flow_tbl_data_entry *tbl_data =
11977 : 0 : container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
11978 : :
11979 [ # # ]: 0 : if (!tbl)
11980 : : return 0;
11981 : 0 : return mlx5_hlist_unregister(sh->flow_tbls, &tbl_data->entry);
11982 : : }
11983 : :
11984 : : int
11985 : 0 : flow_matcher_match_cb(void *tool_ctx __rte_unused,
11986 : : struct mlx5_list_entry *entry, void *cb_ctx)
11987 : : {
11988 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11989 : 0 : struct mlx5_flow_dv_matcher *ref = ctx->data;
11990 : : struct mlx5_flow_dv_matcher *cur = container_of(entry, typeof(*cur),
11991 : : entry);
11992 : :
11993 : 0 : return cur->crc != ref->crc ||
11994 [ # # ]: 0 : cur->priority != ref->priority ||
11995 : 0 : memcmp((const void *)cur->mask.buf,
11996 [ # # ]: 0 : (const void *)ref->mask.buf, ref->mask.size);
11997 : : }
11998 : :
11999 : : struct mlx5_list_entry *
12000 : 0 : flow_matcher_create_cb(void *tool_ctx, void *cb_ctx)
12001 : : {
12002 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
12003 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12004 : 0 : struct mlx5_flow_dv_matcher *ref = ctx->data;
12005 : : struct mlx5_flow_dv_matcher *resource;
12006 : : #ifdef HAVE_MLX5_HWS_SUPPORT
12007 : : const struct rte_flow_item *items;
12008 : : #endif
12009 : 0 : struct mlx5dv_flow_matcher_attr dv_attr = {
12010 : : .type = IBV_FLOW_ATTR_NORMAL,
12011 : 0 : .match_mask = (void *)&ref->mask,
12012 : : };
12013 : : struct mlx5_flow_tbl_data_entry *tbl;
12014 : : int ret;
12015 : :
12016 : 0 : resource = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*resource), 0,
12017 : : SOCKET_ID_ANY);
12018 [ # # ]: 0 : if (!resource) {
12019 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12020 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12021 : : "cannot create matcher");
12022 : 0 : return NULL;
12023 : : }
12024 : 0 : *resource = *ref;
12025 [ # # ]: 0 : if (sh->config.dv_flow_en != 2) {
12026 : 0 : tbl = container_of(ref->tbl, typeof(*tbl), tbl);
12027 : 0 : dv_attr.match_criteria_enable =
12028 [ # # ]: 0 : flow_dv_matcher_enable(resource->mask.buf);
12029 : : __flow_dv_adjust_buf_size(&ref->mask.size,
12030 : : dv_attr.match_criteria_enable);
12031 : 0 : dv_attr.priority = ref->priority;
12032 [ # # ]: 0 : if (tbl->is_egress)
12033 : 0 : dv_attr.flags |= IBV_FLOW_ATTR_FLAGS_EGRESS;
12034 : 0 : ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
12035 : : tbl->tbl.obj,
12036 : : &resource->matcher_object);
12037 : : if (ret) {
12038 : 0 : mlx5_free(resource);
12039 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12040 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12041 : : "cannot create matcher");
12042 : 0 : return NULL;
12043 : : }
12044 : : } else {
12045 : : #ifdef HAVE_MLX5_HWS_SUPPORT
12046 : 0 : items = *((const struct rte_flow_item **)(ctx->data2));
12047 : 0 : resource->matcher_object = mlx5dr_bwc_matcher_create
12048 : 0 : (resource->group->tbl, resource->priority, items);
12049 [ # # ]: 0 : if (!resource->matcher_object) {
12050 : 0 : mlx5_free(resource);
12051 : 0 : return NULL;
12052 : : }
12053 : : #else
12054 : : mlx5_free(resource);
12055 : : return NULL;
12056 : : #endif
12057 : : }
12058 : 0 : return &resource->entry;
12059 : : }
12060 : :
12061 : : /**
12062 : : * Register the flow matcher.
12063 : : *
12064 : : * @param[in, out] dev
12065 : : * Pointer to rte_eth_dev structure.
12066 : : * @param[in, out] matcher
12067 : : * Pointer to flow matcher.
12068 : : * @param[in, out] key
12069 : : * Pointer to flow table key.
12070 : : * @parm[in, out] dev_flow
12071 : : * Pointer to the dev_flow.
12072 : : * @param[out] error
12073 : : * pointer to error structure.
12074 : : *
12075 : : * @return
12076 : : * 0 on success otherwise -errno and errno is set.
12077 : : */
12078 : : static int
12079 : 0 : flow_dv_matcher_register(struct rte_eth_dev *dev,
12080 : : struct mlx5_flow_dv_matcher *ref,
12081 : : union mlx5_flow_tbl_key *key,
12082 : : struct mlx5_flow *dev_flow,
12083 : : const struct mlx5_flow_tunnel *tunnel,
12084 : : uint32_t group_id,
12085 : : struct rte_flow_error *error)
12086 : : {
12087 : : struct mlx5_list_entry *entry;
12088 : : struct mlx5_flow_dv_matcher *resource;
12089 : : struct mlx5_flow_tbl_resource *tbl;
12090 : : struct mlx5_flow_tbl_data_entry *tbl_data;
12091 : 0 : struct mlx5_flow_cb_ctx ctx = {
12092 : : .error = error,
12093 : : .data = ref,
12094 : : };
12095 : : /**
12096 : : * tunnel offload API requires this registration for cases when
12097 : : * tunnel match rule was inserted before tunnel set rule.
12098 : : */
12099 : 0 : tbl = flow_dv_tbl_resource_get(dev, key->level,
12100 : 0 : key->is_egress, key->is_fdb,
12101 : 0 : dev_flow->external, tunnel,
12102 : 0 : group_id, 0, key->id, error);
12103 [ # # ]: 0 : if (!tbl)
12104 : 0 : return -rte_errno; /* No need to refill the error info */
12105 : 0 : tbl_data = container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
12106 : 0 : ref->tbl = tbl;
12107 : 0 : entry = mlx5_list_register(tbl_data->matchers, &ctx);
12108 [ # # ]: 0 : if (!entry) {
12109 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
12110 : 0 : return rte_flow_error_set(error, ENOMEM,
12111 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12112 : : "cannot allocate ref memory");
12113 : : }
12114 : : resource = container_of(entry, typeof(*resource), entry);
12115 : 0 : dev_flow->handle->dvh.matcher = resource;
12116 : 0 : return 0;
12117 : : }
12118 : :
12119 : : struct mlx5_list_entry *
12120 : 0 : flow_dv_tag_create_cb(void *tool_ctx, void *cb_ctx)
12121 : : {
12122 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
12123 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12124 : : struct mlx5_flow_dv_tag_resource *entry;
12125 : 0 : uint32_t idx = 0;
12126 : : int ret;
12127 : :
12128 : 0 : entry = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_TAG], &idx);
12129 [ # # ]: 0 : if (!entry) {
12130 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12131 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12132 : : "cannot allocate resource memory");
12133 : 0 : return NULL;
12134 : : }
12135 : 0 : entry->idx = idx;
12136 : 0 : entry->tag_id = *(uint32_t *)(ctx->data);
12137 : : ret = mlx5_flow_os_create_flow_action_tag(entry->tag_id,
12138 : : &entry->action);
12139 : : if (ret) {
12140 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], idx);
12141 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12142 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12143 : : NULL, "cannot create action");
12144 : 0 : return NULL;
12145 : : }
12146 : 0 : return &entry->entry;
12147 : : }
12148 : :
12149 : : int
12150 : 0 : flow_dv_tag_match_cb(void *tool_ctx __rte_unused, struct mlx5_list_entry *entry,
12151 : : void *cb_ctx)
12152 : : {
12153 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12154 : : struct mlx5_flow_dv_tag_resource *tag =
12155 : : container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
12156 : :
12157 : 0 : return *(uint32_t *)(ctx->data) != tag->tag_id;
12158 : : }
12159 : :
12160 : : struct mlx5_list_entry *
12161 : 0 : flow_dv_tag_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
12162 : : void *cb_ctx)
12163 : : {
12164 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
12165 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12166 : : struct mlx5_flow_dv_tag_resource *entry;
12167 : 0 : uint32_t idx = 0;
12168 : :
12169 : 0 : entry = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_TAG], &idx);
12170 [ # # ]: 0 : if (!entry) {
12171 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12172 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12173 : : "cannot allocate tag resource memory");
12174 : 0 : return NULL;
12175 : : }
12176 : : memcpy(entry, oentry, sizeof(*entry));
12177 : 0 : entry->idx = idx;
12178 : 0 : return &entry->entry;
12179 : : }
12180 : :
12181 : : void
12182 : 0 : flow_dv_tag_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
12183 : : {
12184 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
12185 : : struct mlx5_flow_dv_tag_resource *tag =
12186 : : container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
12187 : :
12188 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], tag->idx);
12189 : 0 : }
12190 : :
12191 : : /**
12192 : : * Find existing tag resource or create and register a new one.
12193 : : *
12194 : : * @param dev[in, out]
12195 : : * Pointer to rte_eth_dev structure.
12196 : : * @param[in, out] tag_be24
12197 : : * Tag value in big endian then R-shift 8.
12198 : : * @parm[in, out] dev_flow
12199 : : * Pointer to the dev_flow.
12200 : : * @param[out] error
12201 : : * pointer to error structure.
12202 : : *
12203 : : * @return
12204 : : * 0 on success otherwise -errno and errno is set.
12205 : : */
12206 : : static int
12207 : 0 : flow_dv_tag_resource_register
12208 : : (struct rte_eth_dev *dev,
12209 : : uint32_t tag_be24,
12210 : : struct mlx5_flow *dev_flow,
12211 : : struct rte_flow_error *error)
12212 : : {
12213 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12214 : : struct mlx5_flow_dv_tag_resource *resource;
12215 : : struct mlx5_list_entry *entry;
12216 : 0 : struct mlx5_flow_cb_ctx ctx = {
12217 : : .error = error,
12218 : : .data = &tag_be24,
12219 : : };
12220 : : struct mlx5_hlist *tag_table;
12221 : :
12222 : 0 : tag_table = flow_dv_hlist_prepare(priv->sh, &priv->sh->tag_table,
12223 : : "tags",
12224 : : MLX5_TAGS_HLIST_ARRAY_SIZE,
12225 : 0 : false, false, priv->sh,
12226 : : flow_dv_tag_create_cb,
12227 : : flow_dv_tag_match_cb,
12228 : : flow_dv_tag_remove_cb,
12229 : : flow_dv_tag_clone_cb,
12230 : : flow_dv_tag_clone_free_cb,
12231 : : error);
12232 [ # # ]: 0 : if (unlikely(!tag_table))
12233 : 0 : return -rte_errno;
12234 : 0 : entry = mlx5_hlist_register(tag_table, tag_be24, &ctx);
12235 [ # # ]: 0 : if (entry) {
12236 : : resource = container_of(entry, struct mlx5_flow_dv_tag_resource,
12237 : : entry);
12238 : 0 : dev_flow->handle->dvh.rix_tag = resource->idx;
12239 : 0 : dev_flow->dv.tag_resource = resource;
12240 : 0 : return 0;
12241 : : }
12242 : 0 : return -rte_errno;
12243 : : }
12244 : :
12245 : : void
12246 : 0 : flow_dv_tag_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
12247 : : {
12248 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
12249 : : struct mlx5_flow_dv_tag_resource *tag =
12250 : : container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
12251 : :
12252 : : MLX5_ASSERT(tag && sh && tag->action);
12253 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(tag->action));
12254 : 0 : DRV_LOG(DEBUG, "Tag %p: removed.", (void *)tag);
12255 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], tag->idx);
12256 : 0 : }
12257 : :
12258 : : /**
12259 : : * Release the tag.
12260 : : *
12261 : : * @param dev
12262 : : * Pointer to Ethernet device.
12263 : : * @param tag_idx
12264 : : * Tag index.
12265 : : *
12266 : : * @return
12267 : : * 1 while a reference on it exists, 0 when freed.
12268 : : */
12269 : : static int
12270 : 0 : flow_dv_tag_release(struct rte_eth_dev *dev,
12271 : : uint32_t tag_idx)
12272 : : {
12273 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12274 : : struct mlx5_flow_dv_tag_resource *tag;
12275 : :
12276 : 0 : tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG], tag_idx);
12277 [ # # ]: 0 : if (!tag)
12278 : : return 0;
12279 : 0 : DRV_LOG(DEBUG, "port %u tag %p: refcnt %d--",
12280 : : dev->data->port_id, (void *)tag, tag->entry.ref_cnt);
12281 : 0 : return mlx5_hlist_unregister(priv->sh->tag_table, &tag->entry);
12282 : : }
12283 : :
12284 : : /**
12285 : : * Translate action PORT_ID / REPRESENTED_PORT to vport.
12286 : : *
12287 : : * @param[in] dev
12288 : : * Pointer to rte_eth_dev structure.
12289 : : * @param[in] action
12290 : : * Pointer to action PORT_ID / REPRESENTED_PORT.
12291 : : * @param[out] dst_port_id
12292 : : * The target port ID.
12293 : : * @param[out] error
12294 : : * Pointer to the error structure.
12295 : : *
12296 : : * @return
12297 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
12298 : : */
12299 : : static int
12300 : 0 : flow_dv_translate_action_port_id(struct rte_eth_dev *dev,
12301 : : const struct rte_flow_action *action,
12302 : : uint32_t *dst_port_id,
12303 : : struct rte_flow_error *error)
12304 : : {
12305 : : uint32_t port;
12306 : : struct mlx5_priv *priv;
12307 : :
12308 [ # # # ]: 0 : switch (action->type) {
12309 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID: {
12310 : : const struct rte_flow_action_port_id *conf;
12311 : :
12312 : 0 : conf = (const struct rte_flow_action_port_id *)action->conf;
12313 [ # # ]: 0 : port = conf->original ? dev->data->port_id : conf->id;
12314 : : break;
12315 : : }
12316 : 0 : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT: {
12317 : : const struct rte_flow_action_ethdev *ethdev;
12318 : :
12319 : 0 : ethdev = (const struct rte_flow_action_ethdev *)action->conf;
12320 : 0 : port = ethdev->port_id;
12321 : 0 : break;
12322 : : }
12323 : 0 : default:
12324 : : MLX5_ASSERT(false);
12325 : 0 : return rte_flow_error_set(error, EINVAL,
12326 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
12327 : : "unknown E-Switch action");
12328 : : }
12329 : :
12330 : 0 : priv = mlx5_port_to_eswitch_info(port, false);
12331 [ # # ]: 0 : if (!priv)
12332 : 0 : return rte_flow_error_set(error, -rte_errno,
12333 : : RTE_FLOW_ERROR_TYPE_ACTION,
12334 : : NULL,
12335 : : "No eswitch info was found for port");
12336 : : #ifdef HAVE_MLX5DV_DR_CREATE_DEST_IB_PORT
12337 : : /*
12338 : : * This parameter is transferred to
12339 : : * mlx5dv_dr_action_create_dest_ib_port().
12340 : : */
12341 : 0 : *dst_port_id = priv->dev_port;
12342 : : #else
12343 : : /*
12344 : : * Legacy mode, no LAG configurations is supported.
12345 : : * This parameter is transferred to
12346 : : * mlx5dv_dr_action_create_dest_vport().
12347 : : */
12348 : : *dst_port_id = priv->vport_id;
12349 : : #endif
12350 : 0 : return 0;
12351 : : }
12352 : :
12353 : : /**
12354 : : * Create a counter with aging configuration.
12355 : : *
12356 : : * @param[in] dev
12357 : : * Pointer to rte_eth_dev structure.
12358 : : * @param[in] dev_flow
12359 : : * Pointer to the mlx5_flow.
12360 : : * @param[out] count
12361 : : * Pointer to the counter action configuration.
12362 : : * @param[in] age
12363 : : * Pointer to the aging action configuration.
12364 : : *
12365 : : * @return
12366 : : * Index to flow counter on success, 0 otherwise.
12367 : : */
12368 : : static uint32_t
12369 : 0 : flow_dv_translate_create_counter(struct rte_eth_dev *dev,
12370 : : struct mlx5_flow *dev_flow,
12371 : : const struct rte_flow_action_count *count
12372 : : __rte_unused,
12373 : : const struct rte_flow_action_age *age)
12374 : : {
12375 : : uint32_t counter;
12376 : : struct mlx5_age_param *age_param;
12377 : :
12378 : 0 : counter = flow_dv_counter_alloc(dev, !!age);
12379 [ # # ]: 0 : if (!counter || age == NULL)
12380 : : return counter;
12381 : : age_param = flow_dv_counter_idx_get_age(dev, counter);
12382 [ # # ]: 0 : age_param->context = age->context ? age->context :
12383 : 0 : (void *)(uintptr_t)(dev_flow->flow_idx);
12384 : 0 : age_param->timeout = age->timeout;
12385 : 0 : age_param->port_id = dev->data->port_id;
12386 : 0 : rte_atomic_store_explicit(&age_param->sec_since_last_hit, 0, rte_memory_order_relaxed);
12387 : 0 : rte_atomic_store_explicit(&age_param->state, AGE_CANDIDATE, rte_memory_order_relaxed);
12388 : 0 : return counter;
12389 : : }
12390 : :
12391 : : /**
12392 : : * Add Tx queue matcher
12393 : : *
12394 : : * @param[in] dev
12395 : : * Pointer to rte_eth_dev structure.
12396 : : * @param[in, out] key
12397 : : * Flow matcher value.
12398 : : * @param[in] item
12399 : : * Flow pattern to translate.
12400 : : * @param[in] key_type
12401 : : * Set flow matcher mask or value.
12402 : : *
12403 : : * @return
12404 : : * 0 on success otherwise -errno and errno is set.
12405 : : */
12406 : : static int
12407 : 0 : flow_dv_translate_item_tx_queue(struct rte_eth_dev *dev, void *key,
12408 : : const struct rte_flow_item *item, uint32_t key_type)
12409 : : {
12410 : : const struct rte_flow_item_tx_queue *queue_m;
12411 : : const struct rte_flow_item_tx_queue *queue_v;
12412 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
12413 : : uint32_t tx_queue;
12414 : : uint32_t sqn = 0;
12415 : : int ret;
12416 : :
12417 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, queue_v, queue_m, &rte_flow_item_tx_queue_mask);
# # # # ]
12418 [ # # ]: 0 : if (!queue_m || !queue_v)
12419 : : return -EINVAL;
12420 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_V) {
12421 : 0 : tx_queue = queue_v->tx_queue;
12422 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_V)
12423 : 0 : tx_queue &= queue_m->tx_queue;
12424 [ # # ]: 0 : ret = flow_hw_get_sqn(dev, tx_queue, &sqn);
12425 [ # # ]: 0 : if (unlikely(ret))
12426 : 0 : return -ret;
12427 : : } else {
12428 : : /* Due to tx_queue to sqn converting, only fully masked value support. */
12429 [ # # ]: 0 : if (queue_m->tx_queue != rte_flow_item_tx_queue_mask.tx_queue)
12430 : : return -EINVAL;
12431 : : sqn = UINT32_MAX;
12432 : : }
12433 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, source_sqn, sqn);
12434 : 0 : return 0;
12435 : : }
12436 : :
12437 : : /**
12438 : : * Add SQ matcher
12439 : : *
12440 : : * @param[in, out] matcher
12441 : : * Flow matcher.
12442 : : * @param[in, out] key
12443 : : * Flow matcher value.
12444 : : * @param[in] item
12445 : : * Flow pattern to translate.
12446 : : * @param[in] key_type
12447 : : * Set flow matcher mask or value.
12448 : : */
12449 : : static void
12450 : 0 : flow_dv_translate_item_sq(void *key,
12451 : : const struct rte_flow_item *item,
12452 : : uint32_t key_type)
12453 : : {
12454 : : const struct mlx5_rte_flow_item_sq *queue_m;
12455 : : const struct mlx5_rte_flow_item_sq *queue_v;
12456 : 0 : const struct mlx5_rte_flow_item_sq queue_mask = {
12457 : : .queue = UINT32_MAX,
12458 : : };
12459 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
12460 : : uint32_t queue;
12461 : :
12462 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, queue_v, queue_m, &queue_mask);
# # # # ]
12463 [ # # ]: 0 : if (!queue_m || !queue_v)
12464 : 0 : return;
12465 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_V) {
12466 : 0 : queue = queue_v->queue;
12467 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_V)
12468 : 0 : queue &= queue_m->queue;
12469 : : } else {
12470 : 0 : queue = queue_m->queue;
12471 : : }
12472 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, source_sqn, queue);
12473 : : }
12474 : :
12475 : : /**
12476 : : * Set the hash fields according to the @p flow information.
12477 : : *
12478 : : * @param[in] item_flags
12479 : : * The match pattern item flags.
12480 : : * @param[in] rss_desc
12481 : : * Pointer to the mlx5_flow_rss_desc.
12482 : : * @param[out] hash_fields
12483 : : * Pointer to the RSS hash fields.
12484 : : */
12485 : : void
12486 : 0 : flow_dv_hashfields_set(uint64_t item_flags,
12487 : : struct mlx5_flow_rss_desc *rss_desc,
12488 : : uint64_t *hash_fields)
12489 : : {
12490 : : uint64_t items = item_flags;
12491 : : uint64_t fields = 0;
12492 : : int rss_inner = 0;
12493 [ # # ]: 0 : uint64_t rss_types = rte_eth_rss_hf_refine(rss_desc->types);
12494 : :
12495 : : *hash_fields = 0;
12496 : : #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
12497 [ # # ]: 0 : if (rss_desc->level >= 2)
12498 : : rss_inner = 1;
12499 : : #endif
12500 [ # # # # ]: 0 : if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV4)) ||
12501 [ # # ]: 0 : (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV4))) {
12502 [ # # ]: 0 : if (rss_types & MLX5_IPV4_LAYER_TYPES) {
12503 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
12504 : : fields |= IBV_RX_HASH_SRC_IPV4;
12505 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
12506 : : fields |= IBV_RX_HASH_DST_IPV4;
12507 : : else
12508 : : fields |= MLX5_IPV4_IBV_RX_HASH;
12509 : : }
12510 [ # # # # : 0 : } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
# # ]
12511 [ # # ]: 0 : (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV6))) {
12512 [ # # ]: 0 : if (rss_types & MLX5_IPV6_LAYER_TYPES) {
12513 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
12514 : : fields |= IBV_RX_HASH_SRC_IPV6;
12515 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
12516 : : fields |= IBV_RX_HASH_DST_IPV6;
12517 : : else
12518 : : fields |= MLX5_IPV6_IBV_RX_HASH;
12519 : : }
12520 : : }
12521 [ # # ]: 0 : if (items & MLX5_FLOW_ITEM_ESP) {
12522 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_ESP)
12523 : 0 : fields |= IBV_RX_HASH_IPSEC_SPI;
12524 : : }
12525 [ # # ]: 0 : if ((fields & ~IBV_RX_HASH_IPSEC_SPI) == 0) {
12526 : 0 : *hash_fields = fields;
12527 : : /*
12528 : : * There is no match between the RSS types and the
12529 : : * L3 protocol (IPv4/IPv6) defined in the flow rule.
12530 : : */
12531 : 0 : return;
12532 : : }
12533 [ # # # # : 0 : if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_UDP)) ||
# # ]
12534 [ # # ]: 0 : (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_UDP))) {
12535 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_UDP) {
12536 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
12537 : 0 : fields |= IBV_RX_HASH_SRC_PORT_UDP;
12538 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
12539 : 0 : fields |= IBV_RX_HASH_DST_PORT_UDP;
12540 : : else
12541 : 0 : fields |= MLX5_UDP_IBV_RX_HASH;
12542 : : }
12543 [ # # # # : 0 : } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_TCP)) ||
# # ]
12544 [ # # ]: 0 : (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_TCP))) {
12545 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_TCP) {
12546 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
12547 : 0 : fields |= IBV_RX_HASH_SRC_PORT_TCP;
12548 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
12549 : 0 : fields |= IBV_RX_HASH_DST_PORT_TCP;
12550 : : else
12551 : 0 : fields |= MLX5_TCP_IBV_RX_HASH;
12552 : : }
12553 : : }
12554 [ # # ]: 0 : if (rss_inner)
12555 : 0 : fields |= IBV_RX_HASH_INNER;
12556 : 0 : *hash_fields = fields;
12557 : : }
12558 : :
12559 : : /**
12560 : : * Prepare an Rx Hash queue.
12561 : : *
12562 : : * @param dev
12563 : : * Pointer to Ethernet device.
12564 : : * @param[in] dev_flow
12565 : : * Pointer to the mlx5_flow.
12566 : : * @param[in] rss_desc
12567 : : * Pointer to the mlx5_flow_rss_desc.
12568 : : * @param[out] hrxq_idx
12569 : : * Hash Rx queue index.
12570 : : *
12571 : : * @return
12572 : : * The Verbs/DevX object initialised, NULL otherwise and rte_errno is set.
12573 : : */
12574 : : static struct mlx5_hrxq *
12575 : 0 : flow_dv_hrxq_prepare(struct rte_eth_dev *dev,
12576 : : struct mlx5_flow *dev_flow,
12577 : : struct mlx5_flow_rss_desc *rss_desc,
12578 : : uint32_t *hrxq_idx)
12579 : : {
12580 : 0 : struct mlx5_flow_handle *dh = dev_flow->handle;
12581 : 0 : uint32_t shared_rss = rss_desc->shared_rss;
12582 : : struct mlx5_hrxq *hrxq;
12583 : :
12584 : : MLX5_ASSERT(rss_desc->queue_num);
12585 : 0 : rss_desc->symmetric_hash_function = dev_flow->symmetric_hash_function;
12586 : 0 : rss_desc->key_len = MLX5_RSS_HASH_KEY_LEN;
12587 : 0 : rss_desc->hash_fields = dev_flow->hash_fields;
12588 : 0 : rss_desc->tunnel = !!(dh->layers & MLX5_FLOW_LAYER_TUNNEL);
12589 : 0 : rss_desc->shared_rss = 0;
12590 [ # # ]: 0 : if (rss_desc->hash_fields == 0)
12591 : 0 : rss_desc->queue_num = 1;
12592 : 0 : hrxq = mlx5_hrxq_get(dev, rss_desc);
12593 [ # # ]: 0 : *hrxq_idx = hrxq ? hrxq->idx : 0;
12594 : 0 : rss_desc->shared_rss = shared_rss;
12595 : 0 : return hrxq;
12596 : : }
12597 : :
12598 : : /**
12599 : : * Release sample sub action resource.
12600 : : *
12601 : : * @param[in, out] dev
12602 : : * Pointer to rte_eth_dev structure.
12603 : : * @param[in] act_res
12604 : : * Pointer to sample sub action resource.
12605 : : */
12606 : : static void
12607 : 0 : flow_dv_sample_sub_actions_release(struct rte_eth_dev *dev,
12608 : : struct mlx5_flow_sub_actions_idx *act_res)
12609 : : {
12610 [ # # ]: 0 : if (act_res->rix_hrxq) {
12611 : 0 : mlx5_hrxq_release(dev, act_res->rix_hrxq);
12612 : 0 : act_res->rix_hrxq = 0;
12613 : : }
12614 [ # # ]: 0 : if (act_res->rix_encap_decap) {
12615 : 0 : flow_encap_decap_resource_release(dev,
12616 : : act_res->rix_encap_decap);
12617 : 0 : act_res->rix_encap_decap = 0;
12618 : : }
12619 [ # # ]: 0 : if (act_res->rix_port_id_action) {
12620 : 0 : flow_dv_port_id_action_resource_release(dev,
12621 : : act_res->rix_port_id_action);
12622 : 0 : act_res->rix_port_id_action = 0;
12623 : : }
12624 [ # # ]: 0 : if (act_res->rix_tag) {
12625 : 0 : flow_dv_tag_release(dev, act_res->rix_tag);
12626 : 0 : act_res->rix_tag = 0;
12627 : : }
12628 [ # # ]: 0 : if (act_res->rix_jump) {
12629 : 0 : flow_dv_jump_tbl_resource_release(dev, act_res->rix_jump);
12630 : 0 : act_res->rix_jump = 0;
12631 : : }
12632 : 0 : }
12633 : :
12634 : : int
12635 : 0 : flow_dv_sample_match_cb(void *tool_ctx __rte_unused,
12636 : : struct mlx5_list_entry *entry, void *cb_ctx)
12637 : : {
12638 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12639 : 0 : struct rte_eth_dev *dev = ctx->dev;
12640 : 0 : struct mlx5_flow_dv_sample_resource *ctx_resource = ctx->data;
12641 : : struct mlx5_flow_dv_sample_resource *resource = container_of(entry,
12642 : : typeof(*resource),
12643 : : entry);
12644 : :
12645 [ # # ]: 0 : if (ctx_resource->ratio == resource->ratio &&
12646 [ # # ]: 0 : ctx_resource->ft_type == resource->ft_type &&
12647 [ # # ]: 0 : ctx_resource->ft_id == resource->ft_id &&
12648 [ # # ]: 0 : ctx_resource->set_action == resource->set_action &&
12649 : 0 : !memcmp((void *)&ctx_resource->sample_act,
12650 [ # # ]: 0 : (void *)&resource->sample_act,
12651 : : sizeof(struct mlx5_flow_sub_actions_list))) {
12652 : : /*
12653 : : * Existing sample action should release the prepared
12654 : : * sub-actions reference counter.
12655 : : */
12656 : 0 : flow_dv_sample_sub_actions_release(dev,
12657 : : &ctx_resource->sample_idx);
12658 : 0 : return 0;
12659 : : }
12660 : : return 1;
12661 : : }
12662 : :
12663 : : struct mlx5_list_entry *
12664 : 0 : flow_dv_sample_create_cb(void *tool_ctx __rte_unused, void *cb_ctx)
12665 : : {
12666 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12667 : 0 : struct rte_eth_dev *dev = ctx->dev;
12668 : 0 : struct mlx5_flow_dv_sample_resource *ctx_resource = ctx->data;
12669 : 0 : void **sample_dv_actions = ctx_resource->sub_actions;
12670 : : struct mlx5_flow_dv_sample_resource *resource;
12671 : : struct mlx5dv_dr_flow_sampler_attr sampler_attr;
12672 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12673 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
12674 : : struct mlx5_flow_tbl_resource *tbl;
12675 : 0 : uint32_t idx = 0;
12676 : : const uint32_t next_ft_step = 1;
12677 : 0 : uint32_t next_ft_id = ctx_resource->ft_id + next_ft_step;
12678 : : uint8_t is_egress = 0;
12679 : : uint8_t is_transfer = 0;
12680 : 0 : struct rte_flow_error *error = ctx->error;
12681 : :
12682 : : /* Register new sample resource. */
12683 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_SAMPLE], &idx);
12684 [ # # ]: 0 : if (!resource) {
12685 : 0 : rte_flow_error_set(error, ENOMEM,
12686 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12687 : : NULL,
12688 : : "cannot allocate resource memory");
12689 : 0 : return NULL;
12690 : : }
12691 : 0 : *resource = *ctx_resource;
12692 : : /* Create normal path table level */
12693 [ # # ]: 0 : if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
12694 : : is_transfer = 1;
12695 [ # # ]: 0 : else if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
12696 : : is_egress = 1;
12697 : 0 : tbl = flow_dv_tbl_resource_get(dev, next_ft_id,
12698 : : is_egress, is_transfer,
12699 : : true, NULL, 0, 0, 0, error);
12700 [ # # ]: 0 : if (!tbl) {
12701 : 0 : rte_flow_error_set(error, ENOMEM,
12702 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12703 : : NULL,
12704 : : "fail to create normal path table "
12705 : : "for sample");
12706 : 0 : goto error;
12707 : : }
12708 : 0 : resource->normal_path_tbl = tbl;
12709 [ # # ]: 0 : if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB) {
12710 [ # # ]: 0 : if (!sh->default_miss_action) {
12711 : 0 : rte_flow_error_set(error, ENOMEM,
12712 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12713 : : NULL,
12714 : : "default miss action was not "
12715 : : "created");
12716 : 0 : goto error;
12717 : : }
12718 : 0 : sample_dv_actions[ctx_resource->sample_act.actions_num++] =
12719 : : sh->default_miss_action;
12720 : : }
12721 : : /* Create a DR sample action */
12722 : 0 : sampler_attr.sample_ratio = resource->ratio;
12723 : 0 : sampler_attr.default_next_table = tbl->obj;
12724 : 0 : sampler_attr.num_sample_actions = ctx_resource->sample_act.actions_num;
12725 : 0 : sampler_attr.sample_actions = (struct mlx5dv_dr_action **)
12726 : : &sample_dv_actions[0];
12727 : 0 : sampler_attr.action = resource->set_action;
12728 : : if (mlx5_os_flow_dr_create_flow_action_sampler
12729 : : (&sampler_attr, &resource->verbs_action)) {
12730 : 0 : rte_flow_error_set(error, ENOMEM,
12731 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12732 : : NULL, "cannot create sample action");
12733 : 0 : goto error;
12734 : : }
12735 : 0 : resource->idx = idx;
12736 : 0 : resource->dev = dev;
12737 : 0 : return &resource->entry;
12738 : 0 : error:
12739 [ # # ]: 0 : if (resource->ft_type != MLX5DV_FLOW_TABLE_TYPE_FDB)
12740 : 0 : flow_dv_sample_sub_actions_release(dev,
12741 : : &resource->sample_idx);
12742 [ # # ]: 0 : if (resource->normal_path_tbl)
12743 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev),
12744 : : resource->normal_path_tbl);
12745 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_SAMPLE], idx);
12746 : 0 : return NULL;
12747 : :
12748 : : }
12749 : :
12750 : : struct mlx5_list_entry *
12751 : 0 : flow_dv_sample_clone_cb(void *tool_ctx __rte_unused,
12752 : : struct mlx5_list_entry *entry __rte_unused,
12753 : : void *cb_ctx)
12754 : : {
12755 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12756 : 0 : struct rte_eth_dev *dev = ctx->dev;
12757 : : struct mlx5_flow_dv_sample_resource *resource;
12758 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12759 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
12760 : 0 : uint32_t idx = 0;
12761 : :
12762 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_SAMPLE], &idx);
12763 [ # # ]: 0 : if (!resource) {
12764 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12765 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12766 : : NULL,
12767 : : "cannot allocate resource memory");
12768 : 0 : return NULL;
12769 : : }
12770 : : memcpy(resource, entry, sizeof(*resource));
12771 : 0 : resource->idx = idx;
12772 : 0 : resource->dev = dev;
12773 : 0 : return &resource->entry;
12774 : : }
12775 : :
12776 : : void
12777 : 0 : flow_dv_sample_clone_free_cb(void *tool_ctx __rte_unused,
12778 : : struct mlx5_list_entry *entry)
12779 : : {
12780 : : struct mlx5_flow_dv_sample_resource *resource =
12781 : : container_of(entry, typeof(*resource), entry);
12782 : 0 : struct rte_eth_dev *dev = resource->dev;
12783 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12784 : :
12785 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_SAMPLE], resource->idx);
12786 : 0 : }
12787 : :
12788 : : /**
12789 : : * Find existing sample resource or create and register a new one.
12790 : : *
12791 : : * @param[in, out] dev
12792 : : * Pointer to rte_eth_dev structure.
12793 : : * @param[in] ref
12794 : : * Pointer to sample resource reference.
12795 : : * @parm[in, out] dev_flow
12796 : : * Pointer to the dev_flow.
12797 : : * @param[out] error
12798 : : * pointer to error structure.
12799 : : *
12800 : : * @return
12801 : : * 0 on success otherwise -errno and errno is set.
12802 : : */
12803 : : static int
12804 : 0 : flow_dv_sample_resource_register(struct rte_eth_dev *dev,
12805 : : struct mlx5_flow_dv_sample_resource *ref,
12806 : : struct mlx5_flow *dev_flow,
12807 : : struct rte_flow_error *error)
12808 : : {
12809 : : struct mlx5_flow_dv_sample_resource *resource;
12810 : : struct mlx5_list_entry *entry;
12811 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12812 : 0 : struct mlx5_flow_cb_ctx ctx = {
12813 : : .dev = dev,
12814 : : .error = error,
12815 : : .data = ref,
12816 : : };
12817 : :
12818 : 0 : entry = mlx5_list_register(priv->sh->sample_action_list, &ctx);
12819 [ # # ]: 0 : if (!entry)
12820 : 0 : return -rte_errno;
12821 : : resource = container_of(entry, typeof(*resource), entry);
12822 : 0 : dev_flow->handle->dvh.rix_sample = resource->idx;
12823 : 0 : dev_flow->dv.sample_res = resource;
12824 : 0 : return 0;
12825 : : }
12826 : :
12827 : : int
12828 : 0 : flow_dv_dest_array_match_cb(void *tool_ctx __rte_unused,
12829 : : struct mlx5_list_entry *entry, void *cb_ctx)
12830 : : {
12831 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12832 : 0 : struct mlx5_flow_dv_dest_array_resource *ctx_resource = ctx->data;
12833 : 0 : struct rte_eth_dev *dev = ctx->dev;
12834 : : struct mlx5_flow_dv_dest_array_resource *resource =
12835 : : container_of(entry, typeof(*resource), entry);
12836 : : uint32_t idx = 0;
12837 : :
12838 [ # # ]: 0 : if (ctx_resource->num_of_dest == resource->num_of_dest &&
12839 : 0 : ctx_resource->ft_type == resource->ft_type &&
12840 : 0 : !memcmp((void *)resource->sample_act,
12841 : 0 : (void *)ctx_resource->sample_act,
12842 [ # # ]: 0 : (ctx_resource->num_of_dest *
12843 : : sizeof(struct mlx5_flow_sub_actions_list)))) {
12844 : : /*
12845 : : * Existing sample action should release the prepared
12846 : : * sub-actions reference counter.
12847 : : */
12848 [ # # ]: 0 : for (idx = 0; idx < ctx_resource->num_of_dest; idx++)
12849 : 0 : flow_dv_sample_sub_actions_release(dev,
12850 : : &ctx_resource->sample_idx[idx]);
12851 : : return 0;
12852 : : }
12853 : : return 1;
12854 : : }
12855 : :
12856 : : struct mlx5_list_entry *
12857 : 0 : flow_dv_dest_array_create_cb(void *tool_ctx __rte_unused, void *cb_ctx)
12858 : : {
12859 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12860 : 0 : struct rte_eth_dev *dev = ctx->dev;
12861 : : struct mlx5_flow_dv_dest_array_resource *resource;
12862 : 0 : struct mlx5_flow_dv_dest_array_resource *ctx_resource = ctx->data;
12863 : 0 : struct mlx5dv_dr_action_dest_attr *dest_attr[MLX5_MAX_DEST_NUM] = { 0 };
12864 : : struct mlx5dv_dr_action_dest_reformat dest_reformat[MLX5_MAX_DEST_NUM];
12865 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12866 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
12867 : : struct mlx5_flow_sub_actions_list *sample_act;
12868 : : struct mlx5dv_dr_domain *domain;
12869 : 0 : uint32_t idx = 0, res_idx = 0;
12870 : 0 : struct rte_flow_error *error = ctx->error;
12871 : : uint64_t action_flags;
12872 : : int ret;
12873 : :
12874 : : /* Register new destination array resource. */
12875 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DEST_ARRAY],
12876 : : &res_idx);
12877 [ # # ]: 0 : if (!resource) {
12878 : 0 : rte_flow_error_set(error, ENOMEM,
12879 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12880 : : NULL,
12881 : : "cannot allocate resource memory");
12882 : 0 : return NULL;
12883 : : }
12884 : 0 : *resource = *ctx_resource;
12885 [ # # ]: 0 : if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
12886 : 0 : domain = sh->fdb_domain;
12887 [ # # ]: 0 : else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
12888 : 0 : domain = sh->rx_domain;
12889 : : else
12890 : 0 : domain = sh->tx_domain;
12891 [ # # ]: 0 : for (idx = 0; idx < ctx_resource->num_of_dest; idx++) {
12892 : 0 : dest_attr[idx] = (struct mlx5dv_dr_action_dest_attr *)
12893 : 0 : mlx5_malloc(MLX5_MEM_ZERO,
12894 : : sizeof(struct mlx5dv_dr_action_dest_attr),
12895 : : 0, SOCKET_ID_ANY);
12896 [ # # ]: 0 : if (!dest_attr[idx]) {
12897 : 0 : rte_flow_error_set(error, ENOMEM,
12898 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12899 : : NULL,
12900 : : "cannot allocate resource memory");
12901 : 0 : goto error;
12902 : : }
12903 : 0 : dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST;
12904 : : sample_act = &ctx_resource->sample_act[idx];
12905 : 0 : action_flags = sample_act->action_flags;
12906 [ # # # # : 0 : switch (action_flags) {
# ]
12907 : 0 : case MLX5_FLOW_ACTION_QUEUE:
12908 : 0 : dest_attr[idx]->dest = sample_act->dr_queue_action;
12909 : 0 : break;
12910 : 0 : case (MLX5_FLOW_ACTION_PORT_ID | MLX5_FLOW_ACTION_ENCAP):
12911 : 0 : dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST_REFORMAT;
12912 : 0 : dest_attr[idx]->dest_reformat = &dest_reformat[idx];
12913 : 0 : dest_attr[idx]->dest_reformat->reformat =
12914 : 0 : sample_act->dr_encap_action;
12915 : 0 : dest_attr[idx]->dest_reformat->dest =
12916 : 0 : sample_act->dr_port_id_action;
12917 : 0 : break;
12918 : 0 : case MLX5_FLOW_ACTION_PORT_ID:
12919 : 0 : dest_attr[idx]->dest = sample_act->dr_port_id_action;
12920 : 0 : break;
12921 : 0 : case MLX5_FLOW_ACTION_JUMP:
12922 : 0 : dest_attr[idx]->dest = sample_act->dr_jump_action;
12923 : 0 : break;
12924 : 0 : default:
12925 : 0 : rte_flow_error_set(error, EINVAL,
12926 : : RTE_FLOW_ERROR_TYPE_ACTION,
12927 : : NULL,
12928 : : "unsupported actions type");
12929 : 0 : goto error;
12930 : : }
12931 : : }
12932 : : /* create a dest array action */
12933 : 0 : ret = mlx5_os_flow_dr_create_flow_action_dest_array
12934 : : (domain,
12935 : 0 : resource->num_of_dest,
12936 : : dest_attr,
12937 : : &resource->action);
12938 : : if (ret) {
12939 : 0 : rte_flow_error_set(error, ENOMEM,
12940 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12941 : : NULL,
12942 : : "cannot create destination array action");
12943 : 0 : goto error;
12944 : : }
12945 : 0 : resource->idx = res_idx;
12946 : 0 : resource->dev = dev;
12947 [ # # ]: 0 : for (idx = 0; idx < ctx_resource->num_of_dest; idx++)
12948 : 0 : mlx5_free(dest_attr[idx]);
12949 : 0 : return &resource->entry;
12950 : : error:
12951 [ # # ]: 0 : for (idx = 0; idx < ctx_resource->num_of_dest; idx++) {
12952 : 0 : flow_dv_sample_sub_actions_release(dev,
12953 : : &resource->sample_idx[idx]);
12954 [ # # ]: 0 : if (dest_attr[idx])
12955 : 0 : mlx5_free(dest_attr[idx]);
12956 : : }
12957 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DEST_ARRAY], res_idx);
12958 : 0 : return NULL;
12959 : : }
12960 : :
12961 : : struct mlx5_list_entry *
12962 : 0 : flow_dv_dest_array_clone_cb(void *tool_ctx __rte_unused,
12963 : : struct mlx5_list_entry *entry __rte_unused,
12964 : : void *cb_ctx)
12965 : : {
12966 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12967 : 0 : struct rte_eth_dev *dev = ctx->dev;
12968 : : struct mlx5_flow_dv_dest_array_resource *resource;
12969 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12970 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
12971 : 0 : uint32_t res_idx = 0;
12972 : 0 : struct rte_flow_error *error = ctx->error;
12973 : :
12974 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DEST_ARRAY],
12975 : : &res_idx);
12976 [ # # ]: 0 : if (!resource) {
12977 : 0 : rte_flow_error_set(error, ENOMEM,
12978 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12979 : : NULL,
12980 : : "cannot allocate dest-array memory");
12981 : 0 : return NULL;
12982 : : }
12983 : : memcpy(resource, entry, sizeof(*resource));
12984 : 0 : resource->idx = res_idx;
12985 : 0 : resource->dev = dev;
12986 : 0 : return &resource->entry;
12987 : : }
12988 : :
12989 : : void
12990 : 0 : flow_dv_dest_array_clone_free_cb(void *tool_ctx __rte_unused,
12991 : : struct mlx5_list_entry *entry)
12992 : : {
12993 : : struct mlx5_flow_dv_dest_array_resource *resource =
12994 : : container_of(entry, typeof(*resource), entry);
12995 : 0 : struct rte_eth_dev *dev = resource->dev;
12996 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12997 : :
12998 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY], resource->idx);
12999 : 0 : }
13000 : :
13001 : : /**
13002 : : * Find existing destination array resource or create and register a new one.
13003 : : *
13004 : : * @param[in, out] dev
13005 : : * Pointer to rte_eth_dev structure.
13006 : : * @param[in] ref
13007 : : * Pointer to destination array resource reference.
13008 : : * @parm[in, out] dev_flow
13009 : : * Pointer to the dev_flow.
13010 : : * @param[out] error
13011 : : * pointer to error structure.
13012 : : *
13013 : : * @return
13014 : : * 0 on success otherwise -errno and errno is set.
13015 : : */
13016 : : static int
13017 : 0 : flow_dv_dest_array_resource_register(struct rte_eth_dev *dev,
13018 : : struct mlx5_flow_dv_dest_array_resource *ref,
13019 : : struct mlx5_flow *dev_flow,
13020 : : struct rte_flow_error *error)
13021 : : {
13022 : : struct mlx5_flow_dv_dest_array_resource *resource;
13023 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13024 : : struct mlx5_list_entry *entry;
13025 : 0 : struct mlx5_flow_cb_ctx ctx = {
13026 : : .dev = dev,
13027 : : .error = error,
13028 : : .data = ref,
13029 : : };
13030 : :
13031 : 0 : entry = mlx5_list_register(priv->sh->dest_array_list, &ctx);
13032 [ # # ]: 0 : if (!entry)
13033 : 0 : return -rte_errno;
13034 : : resource = container_of(entry, typeof(*resource), entry);
13035 : 0 : dev_flow->handle->dvh.rix_dest_array = resource->idx;
13036 : 0 : dev_flow->dv.dest_array_res = resource;
13037 : 0 : return 0;
13038 : : }
13039 : :
13040 : : /**
13041 : : * Convert Sample action to DV specification.
13042 : : *
13043 : : * @param[in] dev
13044 : : * Pointer to rte_eth_dev structure.
13045 : : * @param[in] action
13046 : : * Pointer to sample action structure.
13047 : : * @param[in, out] dev_flow
13048 : : * Pointer to the mlx5_flow.
13049 : : * @param[in] attr
13050 : : * Pointer to the flow attributes.
13051 : : * @param[in, out] num_of_dest
13052 : : * Pointer to the num of destination.
13053 : : * @param[in, out] sample_actions
13054 : : * Pointer to sample actions list.
13055 : : * @param[in, out] res
13056 : : * Pointer to sample resource.
13057 : : * @param[out] error
13058 : : * Pointer to the error structure.
13059 : : *
13060 : : * @return
13061 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
13062 : : */
13063 : : static int
13064 : 0 : flow_dv_translate_action_sample(struct rte_eth_dev *dev,
13065 : : const struct rte_flow_action_sample *action,
13066 : : struct mlx5_flow *dev_flow,
13067 : : const struct rte_flow_attr *attr,
13068 : : uint32_t *num_of_dest,
13069 : : void **sample_actions,
13070 : : struct mlx5_flow_dv_sample_resource *res,
13071 : : struct rte_flow_error *error)
13072 : : {
13073 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13074 : : const struct rte_flow_action *sub_actions;
13075 : : struct mlx5_flow_sub_actions_list *sample_act;
13076 : : struct mlx5_flow_sub_actions_idx *sample_idx;
13077 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
13078 : 0 : struct rte_flow *flow = dev_flow->flow;
13079 : : struct mlx5_flow_rss_desc *rss_desc;
13080 : : uint64_t action_flags = 0;
13081 : :
13082 : : MLX5_ASSERT(wks);
13083 : 0 : rss_desc = &wks->rss_desc;
13084 : : sample_act = &res->sample_act;
13085 : : sample_idx = &res->sample_idx;
13086 : 0 : res->ratio = action->ratio;
13087 : 0 : sub_actions = action->actions;
13088 [ # # ]: 0 : for (; sub_actions->type != RTE_FLOW_ACTION_TYPE_END; sub_actions++) {
13089 : : int type = sub_actions->type;
13090 : : uint32_t pre_rix = 0;
13091 : : void *pre_r;
13092 [ # # # # : 0 : switch (type) {
# # # ]
13093 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
13094 : : {
13095 : : const struct rte_flow_action_queue *queue;
13096 : : struct mlx5_hrxq *hrxq;
13097 : : uint32_t hrxq_idx;
13098 : :
13099 : 0 : queue = sub_actions->conf;
13100 : 0 : rss_desc->queue_num = 1;
13101 : 0 : rss_desc->queue[0] = queue->index;
13102 : 0 : hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
13103 : : rss_desc, &hrxq_idx);
13104 [ # # ]: 0 : if (!hrxq)
13105 : 0 : return rte_flow_error_set
13106 : : (error, rte_errno,
13107 : : RTE_FLOW_ERROR_TYPE_ACTION,
13108 : : NULL,
13109 : : "cannot create fate queue");
13110 : 0 : sample_act->dr_queue_action = hrxq->action;
13111 : 0 : sample_idx->rix_hrxq = hrxq_idx;
13112 : 0 : sample_actions[sample_act->actions_num++] =
13113 : : hrxq->action;
13114 : 0 : (*num_of_dest)++;
13115 : 0 : action_flags |= MLX5_FLOW_ACTION_QUEUE;
13116 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
13117 : 0 : dev_flow->handle->rix_hrxq = hrxq_idx;
13118 : 0 : dev_flow->handle->fate_action =
13119 : : MLX5_FLOW_FATE_QUEUE;
13120 : 0 : break;
13121 : : }
13122 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
13123 : : {
13124 : : struct mlx5_hrxq *hrxq;
13125 : : uint32_t hrxq_idx;
13126 : : const struct rte_flow_action_rss *rss;
13127 : : const uint8_t *rss_key;
13128 : :
13129 : 0 : rss = sub_actions->conf;
13130 : 0 : rss_desc->symmetric_hash_function =
13131 : 0 : MLX5_RSS_IS_SYMM(rss->func);
13132 : 0 : memcpy(rss_desc->queue, rss->queue,
13133 [ # # ]: 0 : rss->queue_num * sizeof(uint16_t));
13134 : 0 : rss_desc->queue_num = rss->queue_num;
13135 : : /* NULL RSS key indicates default RSS key. */
13136 [ # # ]: 0 : rss_key = !rss->key ? rss_hash_default_key : rss->key;
13137 : 0 : memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
13138 : : /*
13139 : : * rss->level and rss.types should be set in advance
13140 : : * when expanding items for RSS.
13141 : : */
13142 : 0 : flow_dv_hashfields_set(dev_flow->handle->layers,
13143 : : rss_desc,
13144 : : &dev_flow->hash_fields);
13145 : 0 : hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
13146 : : rss_desc, &hrxq_idx);
13147 [ # # ]: 0 : if (!hrxq)
13148 : 0 : return rte_flow_error_set
13149 : : (error, rte_errno,
13150 : : RTE_FLOW_ERROR_TYPE_ACTION,
13151 : : NULL,
13152 : : "cannot create fate queue");
13153 : 0 : sample_act->dr_queue_action = hrxq->action;
13154 : 0 : sample_idx->rix_hrxq = hrxq_idx;
13155 : 0 : sample_actions[sample_act->actions_num++] =
13156 : : hrxq->action;
13157 : 0 : (*num_of_dest)++;
13158 : 0 : action_flags |= MLX5_FLOW_ACTION_RSS;
13159 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
13160 : 0 : dev_flow->handle->rix_hrxq = hrxq_idx;
13161 : 0 : dev_flow->handle->fate_action =
13162 : : MLX5_FLOW_FATE_QUEUE;
13163 : 0 : break;
13164 : : }
13165 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
13166 : : {
13167 : : uint32_t tag_be = mlx5_flow_mark_set
13168 : : (((const struct rte_flow_action_mark *)
13169 [ # # ]: 0 : (sub_actions->conf))->id);
13170 : :
13171 : 0 : wks->mark = 1;
13172 : 0 : pre_rix = dev_flow->handle->dvh.rix_tag;
13173 : : /* Save the mark resource before sample */
13174 : 0 : pre_r = dev_flow->dv.tag_resource;
13175 [ # # ]: 0 : if (flow_dv_tag_resource_register(dev, tag_be,
13176 : : dev_flow, error))
13177 : 0 : return -rte_errno;
13178 : : MLX5_ASSERT(dev_flow->dv.tag_resource);
13179 : 0 : sample_act->dr_tag_action =
13180 : 0 : dev_flow->dv.tag_resource->action;
13181 : 0 : sample_idx->rix_tag =
13182 : 0 : dev_flow->handle->dvh.rix_tag;
13183 : 0 : sample_actions[sample_act->actions_num++] =
13184 : : sample_act->dr_tag_action;
13185 : : /* Recover the mark resource after sample */
13186 : 0 : dev_flow->dv.tag_resource = pre_r;
13187 : 0 : dev_flow->handle->dvh.rix_tag = pre_rix;
13188 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK;
13189 : 0 : break;
13190 : : }
13191 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
13192 : : {
13193 [ # # ]: 0 : if (!flow->counter) {
13194 : 0 : flow->counter =
13195 : 0 : flow_dv_translate_create_counter(dev,
13196 : 0 : dev_flow, sub_actions->conf,
13197 : : 0);
13198 [ # # ]: 0 : if (!flow->counter)
13199 : 0 : return rte_flow_error_set
13200 : : (error, rte_errno,
13201 : : RTE_FLOW_ERROR_TYPE_ACTION,
13202 : : NULL,
13203 : : "cannot create counter"
13204 : : " object.");
13205 : : }
13206 : 0 : sample_act->dr_cnt_action =
13207 [ # # ]: 0 : (flow_dv_counter_get_by_idx(dev,
13208 : 0 : flow->counter, NULL))->action;
13209 : 0 : sample_actions[sample_act->actions_num++] =
13210 : : sample_act->dr_cnt_action;
13211 : 0 : action_flags |= MLX5_FLOW_ACTION_COUNT;
13212 : 0 : break;
13213 : : }
13214 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
13215 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
13216 : : {
13217 : : struct mlx5_flow_dv_port_id_action_resource
13218 : : port_id_resource;
13219 : 0 : uint32_t port_id = 0;
13220 : :
13221 : : memset(&port_id_resource, 0, sizeof(port_id_resource));
13222 : : /* Save the port id resource before sample */
13223 : 0 : pre_rix = dev_flow->handle->rix_port_id_action;
13224 : 0 : pre_r = dev_flow->dv.port_id_action;
13225 [ # # ]: 0 : if (flow_dv_translate_action_port_id(dev, sub_actions,
13226 : : &port_id, error))
13227 : 0 : return -rte_errno;
13228 : 0 : port_id_resource.port_id = port_id;
13229 [ # # ]: 0 : if (flow_dv_port_id_action_resource_register
13230 : : (dev, &port_id_resource, dev_flow, error))
13231 : 0 : return -rte_errno;
13232 : 0 : sample_act->dr_port_id_action =
13233 : 0 : dev_flow->dv.port_id_action->action;
13234 : 0 : sample_idx->rix_port_id_action =
13235 : 0 : dev_flow->handle->rix_port_id_action;
13236 : 0 : sample_actions[sample_act->actions_num++] =
13237 : : sample_act->dr_port_id_action;
13238 : : /* Recover the port id resource after sample */
13239 : 0 : dev_flow->dv.port_id_action = pre_r;
13240 : 0 : dev_flow->handle->rix_port_id_action = pre_rix;
13241 : 0 : (*num_of_dest)++;
13242 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_ID;
13243 : 0 : break;
13244 : : }
13245 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
13246 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
13247 : : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
13248 : : /* Save the encap resource before sample */
13249 : 0 : pre_rix = dev_flow->handle->dvh.rix_encap_decap;
13250 : 0 : pre_r = dev_flow->dv.encap_decap;
13251 [ # # ]: 0 : if (flow_dv_create_action_l2_encap(dev, sub_actions,
13252 : : dev_flow,
13253 : 0 : attr->transfer,
13254 : : error))
13255 : 0 : return -rte_errno;
13256 : 0 : sample_act->dr_encap_action =
13257 : 0 : dev_flow->dv.encap_decap->action;
13258 : 0 : sample_idx->rix_encap_decap =
13259 : 0 : dev_flow->handle->dvh.rix_encap_decap;
13260 : 0 : sample_actions[sample_act->actions_num++] =
13261 : : sample_act->dr_encap_action;
13262 : : /* Recover the encap resource after sample */
13263 : 0 : dev_flow->dv.encap_decap = pre_r;
13264 : 0 : dev_flow->handle->dvh.rix_encap_decap = pre_rix;
13265 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
13266 : 0 : break;
13267 : 0 : default:
13268 : 0 : return rte_flow_error_set(error, EINVAL,
13269 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13270 : : NULL,
13271 : : "Not support for sampler action");
13272 : : }
13273 : : }
13274 : 0 : sample_act->action_flags = action_flags;
13275 : 0 : res->ft_id = dev_flow->dv.group;
13276 [ # # ]: 0 : if (attr->transfer) {
13277 : : union {
13278 : : uint32_t action_in[MLX5_ST_SZ_DW(set_action_in)];
13279 : : uint64_t set_action;
13280 : : } action_ctx = { .set_action = 0 };
13281 : 0 : uint32_t vport_meta_tag = wks->vport_meta_tag ?
13282 [ # # ]: 0 : wks->vport_meta_tag :
13283 : : priv->vport_meta_tag;
13284 : :
13285 : 0 : res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
13286 : : MLX5_SET(set_action_in, action_ctx.action_in, action_type,
13287 : : MLX5_MODIFICATION_TYPE_SET);
13288 [ # # ]: 0 : MLX5_SET(set_action_in, action_ctx.action_in, field,
13289 : : MLX5_MODI_META_REG_C_0);
13290 : 0 : MLX5_SET(set_action_in, action_ctx.action_in, data,
13291 : : vport_meta_tag);
13292 : 0 : res->set_action = action_ctx.set_action;
13293 [ # # ]: 0 : } else if (attr->ingress) {
13294 : 0 : res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
13295 : : } else {
13296 : 0 : res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_TX;
13297 : : }
13298 : : return 0;
13299 : : }
13300 : :
13301 : : static void *
13302 : 0 : flow_dv_translate_action_send_to_kernel(struct rte_eth_dev *dev,
13303 : : const struct rte_flow_attr *attr,
13304 : : struct rte_flow_error *error)
13305 : : {
13306 : : struct mlx5_flow_tbl_resource *tbl;
13307 : : struct mlx5_dev_ctx_shared *sh;
13308 : : uint32_t priority;
13309 : : void *action;
13310 : : int ft_type;
13311 : : int ret;
13312 : :
13313 : 0 : sh = MLX5_SH(dev);
13314 [ # # ]: 0 : ft_type = (attr->ingress) ? MLX5DR_TABLE_TYPE_NIC_RX :
13315 [ # # ]: 0 : ((attr->transfer) ? MLX5DR_TABLE_TYPE_FDB :
13316 : : MLX5DR_TABLE_TYPE_NIC_TX);
13317 [ # # ]: 0 : if (sh->send_to_kernel_action[ft_type].action)
13318 : : return sh->send_to_kernel_action[ft_type].action;
13319 : 0 : priority = mlx5_get_send_to_kernel_priority(dev);
13320 [ # # ]: 0 : if (priority == (uint32_t)-1) {
13321 : 0 : rte_flow_error_set(error, ENOTSUP,
13322 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13323 : : "required priority is not available");
13324 : 0 : return NULL;
13325 : : }
13326 : 0 : tbl = flow_dv_tbl_resource_get(dev, 0, attr->egress, attr->transfer, false, NULL, 0, 0, 0,
13327 : : error);
13328 [ # # ]: 0 : if (!tbl) {
13329 : 0 : rte_flow_error_set(error, ENODATA,
13330 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13331 : : "cannot find destination root table");
13332 : 0 : return NULL;
13333 : : }
13334 : 0 : ret = mlx5_flow_os_create_flow_action_send_to_kernel(tbl->obj,
13335 : : priority, &action);
13336 : : if (ret) {
13337 : 0 : rte_flow_error_set(error, ENOMEM,
13338 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13339 : : "cannot create action");
13340 : 0 : goto err;
13341 : : }
13342 : : MLX5_ASSERT(action);
13343 : 0 : sh->send_to_kernel_action[ft_type].action = action;
13344 : 0 : sh->send_to_kernel_action[ft_type].tbl = tbl;
13345 : 0 : return action;
13346 : : err:
13347 : 0 : flow_dv_tbl_resource_release(sh, tbl);
13348 : 0 : return NULL;
13349 : : }
13350 : :
13351 : : /**
13352 : : * Convert Sample action to DV specification.
13353 : : *
13354 : : * @param[in] dev
13355 : : * Pointer to rte_eth_dev structure.
13356 : : * @param[in, out] dev_flow
13357 : : * Pointer to the mlx5_flow.
13358 : : * @param[in] num_of_dest
13359 : : * The num of destination.
13360 : : * @param[in, out] res
13361 : : * Pointer to sample resource.
13362 : : * @param[in, out] mdest_res
13363 : : * Pointer to destination array resource.
13364 : : * @param[in] sample_actions
13365 : : * Pointer to sample path actions list.
13366 : : * @param[in] action_flags
13367 : : * Holds the actions detected until now.
13368 : : * @param[out] error
13369 : : * Pointer to the error structure.
13370 : : *
13371 : : * @return
13372 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
13373 : : */
13374 : : static int
13375 : 0 : flow_dv_create_action_sample(struct rte_eth_dev *dev,
13376 : : struct mlx5_flow *dev_flow,
13377 : : uint32_t num_of_dest,
13378 : : struct mlx5_flow_dv_sample_resource *res,
13379 : : struct mlx5_flow_dv_dest_array_resource *mdest_res,
13380 : : void **sample_actions,
13381 : : uint64_t action_flags,
13382 : : struct rte_flow_error *error)
13383 : : {
13384 : : /* update normal path action resource into last index of array */
13385 : : uint32_t dest_index = MLX5_MAX_DEST_NUM - 1;
13386 : : struct mlx5_flow_sub_actions_list *sample_act =
13387 : : &mdest_res->sample_act[dest_index];
13388 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
13389 : : struct mlx5_flow_rss_desc *rss_desc;
13390 : : uint32_t normal_idx = 0;
13391 : : struct mlx5_hrxq *hrxq;
13392 : : uint32_t hrxq_idx;
13393 : :
13394 : : MLX5_ASSERT(wks);
13395 : 0 : rss_desc = &wks->rss_desc;
13396 [ # # ]: 0 : if (num_of_dest > 1) {
13397 [ # # ]: 0 : if (sample_act->action_flags & MLX5_FLOW_ACTION_QUEUE) {
13398 : : /* Handle QP action for mirroring */
13399 : 0 : hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
13400 : : rss_desc, &hrxq_idx);
13401 [ # # ]: 0 : if (!hrxq)
13402 : 0 : return rte_flow_error_set
13403 : : (error, rte_errno,
13404 : : RTE_FLOW_ERROR_TYPE_ACTION,
13405 : : NULL,
13406 : : "cannot create rx queue");
13407 : : normal_idx++;
13408 : 0 : mdest_res->sample_idx[dest_index].rix_hrxq = hrxq_idx;
13409 : 0 : sample_act->dr_queue_action = hrxq->action;
13410 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
13411 : 0 : dev_flow->handle->rix_hrxq = hrxq_idx;
13412 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
13413 : : }
13414 [ # # ]: 0 : if (sample_act->action_flags & MLX5_FLOW_ACTION_ENCAP) {
13415 : 0 : normal_idx++;
13416 : 0 : mdest_res->sample_idx[dest_index].rix_encap_decap =
13417 : 0 : dev_flow->handle->dvh.rix_encap_decap;
13418 : 0 : sample_act->dr_encap_action =
13419 : 0 : dev_flow->dv.encap_decap->action;
13420 : 0 : dev_flow->handle->dvh.rix_encap_decap = 0;
13421 : : }
13422 [ # # ]: 0 : if (sample_act->action_flags & MLX5_FLOW_ACTION_PORT_ID) {
13423 : 0 : normal_idx++;
13424 : 0 : mdest_res->sample_idx[dest_index].rix_port_id_action =
13425 : 0 : dev_flow->handle->rix_port_id_action;
13426 : 0 : sample_act->dr_port_id_action =
13427 : 0 : dev_flow->dv.port_id_action->action;
13428 : 0 : dev_flow->handle->rix_port_id_action = 0;
13429 : : }
13430 [ # # ]: 0 : if (sample_act->action_flags & MLX5_FLOW_ACTION_JUMP) {
13431 : 0 : normal_idx++;
13432 : 0 : mdest_res->sample_idx[dest_index].rix_jump =
13433 : 0 : dev_flow->handle->rix_jump;
13434 : 0 : sample_act->dr_jump_action =
13435 : 0 : dev_flow->dv.jump->action;
13436 : 0 : dev_flow->handle->rix_jump = 0;
13437 : : }
13438 : 0 : sample_act->actions_num = normal_idx;
13439 : : /* update sample action resource into first index of array */
13440 : 0 : mdest_res->ft_type = res->ft_type;
13441 : 0 : memcpy(&mdest_res->sample_idx[0], &res->sample_idx,
13442 : : sizeof(struct mlx5_flow_sub_actions_idx));
13443 : 0 : memcpy(&mdest_res->sample_act[0], &res->sample_act,
13444 : : sizeof(struct mlx5_flow_sub_actions_list));
13445 : 0 : mdest_res->num_of_dest = num_of_dest;
13446 [ # # ]: 0 : if (flow_dv_dest_array_resource_register(dev, mdest_res,
13447 : : dev_flow, error))
13448 : 0 : return rte_flow_error_set(error, EINVAL,
13449 : : RTE_FLOW_ERROR_TYPE_ACTION,
13450 : : NULL, "can't create sample "
13451 : : "action");
13452 : : } else {
13453 : 0 : res->sub_actions = sample_actions;
13454 [ # # ]: 0 : if (flow_dv_sample_resource_register(dev, res, dev_flow, error))
13455 : 0 : return rte_flow_error_set(error, EINVAL,
13456 : : RTE_FLOW_ERROR_TYPE_ACTION,
13457 : : NULL,
13458 : : "can't create sample action");
13459 : : }
13460 : : return 0;
13461 : : }
13462 : :
13463 : : /**
13464 : : * Remove an ASO age action from age actions list.
13465 : : *
13466 : : * @param[in] dev
13467 : : * Pointer to the Ethernet device structure.
13468 : : * @param[in] age
13469 : : * Pointer to the aso age action handler.
13470 : : */
13471 : : static void
13472 : 0 : flow_dv_aso_age_remove_from_age(struct rte_eth_dev *dev,
13473 : : struct mlx5_aso_age_action *age)
13474 : : {
13475 : : struct mlx5_age_info *age_info;
13476 : : struct mlx5_age_param *age_param = &age->age_params;
13477 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13478 : : uint16_t expected = AGE_CANDIDATE;
13479 : :
13480 : 0 : age_info = GET_PORT_AGE_INFO(priv);
13481 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(&age_param->state, &expected,
13482 : : AGE_FREE, rte_memory_order_relaxed,
13483 : : rte_memory_order_relaxed)) {
13484 : : /**
13485 : : * We need the lock even it is age timeout,
13486 : : * since age action may still in process.
13487 : : */
13488 : 0 : rte_spinlock_lock(&age_info->aged_sl);
13489 [ # # ]: 0 : LIST_REMOVE(age, next);
13490 : : rte_spinlock_unlock(&age_info->aged_sl);
13491 : 0 : rte_atomic_store_explicit(&age_param->state, AGE_FREE, rte_memory_order_relaxed);
13492 : : }
13493 : 0 : }
13494 : :
13495 : : /**
13496 : : * Release an ASO age action.
13497 : : *
13498 : : * @param[in] dev
13499 : : * Pointer to the Ethernet device structure.
13500 : : * @param[in] age_idx
13501 : : * Index of ASO age action to release.
13502 : : * @param[in] flow
13503 : : * True if the release operation is during flow destroy operation.
13504 : : * False if the release operation is during action destroy operation.
13505 : : *
13506 : : * @return
13507 : : * 0 when age action was removed, otherwise the number of references.
13508 : : */
13509 : : static int
13510 : 0 : flow_dv_aso_age_release(struct rte_eth_dev *dev, uint32_t age_idx)
13511 : : {
13512 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13513 : 0 : struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
13514 : 0 : struct mlx5_aso_age_action *age = flow_aso_age_get_by_idx(dev, age_idx);
13515 : 0 : uint32_t ret = rte_atomic_fetch_sub_explicit(&age->refcnt, 1, rte_memory_order_relaxed) - 1;
13516 : :
13517 [ # # ]: 0 : if (!ret) {
13518 : 0 : flow_dv_aso_age_remove_from_age(dev, age);
13519 : 0 : rte_spinlock_lock(&mng->free_sl);
13520 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free, age, next);
13521 : : rte_spinlock_unlock(&mng->free_sl);
13522 : : }
13523 : 0 : return ret;
13524 : : }
13525 : :
13526 : : /**
13527 : : * Resize the ASO age pools array by MLX5_ASO_AGE_CONTAINER_RESIZE pools.
13528 : : *
13529 : : * @param[in] dev
13530 : : * Pointer to the Ethernet device structure.
13531 : : *
13532 : : * @return
13533 : : * 0 on success, otherwise negative errno value and rte_errno is set.
13534 : : */
13535 : : static int
13536 : 0 : flow_dv_aso_age_pools_resize(struct rte_eth_dev *dev)
13537 : : {
13538 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13539 : 0 : struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
13540 : 0 : void *old_pools = mng->pools;
13541 : 0 : uint32_t resize = mng->n + MLX5_ASO_AGE_CONTAINER_RESIZE;
13542 : 0 : uint32_t mem_size = sizeof(struct mlx5_aso_age_pool *) * resize;
13543 : 0 : void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
13544 : :
13545 [ # # ]: 0 : if (!pools) {
13546 : 0 : rte_errno = ENOMEM;
13547 : 0 : return -ENOMEM;
13548 : : }
13549 [ # # ]: 0 : if (old_pools) {
13550 : 0 : memcpy(pools, old_pools,
13551 : 0 : mng->n * sizeof(struct mlx5_flow_counter_pool *));
13552 : 0 : mlx5_free(old_pools);
13553 : : } else {
13554 : : /* First ASO flow hit allocation - starting ASO data-path. */
13555 : 0 : int ret = mlx5_aso_flow_hit_queue_poll_start(priv->sh);
13556 : :
13557 [ # # ]: 0 : if (ret) {
13558 : 0 : mlx5_free(pools);
13559 : 0 : return ret;
13560 : : }
13561 : : }
13562 : 0 : mng->n = resize;
13563 : 0 : mng->pools = pools;
13564 : 0 : return 0;
13565 : : }
13566 : :
13567 : : /**
13568 : : * Create and initialize a new ASO aging pool.
13569 : : *
13570 : : * @param[in] dev
13571 : : * Pointer to the Ethernet device structure.
13572 : : * @param[out] age_free
13573 : : * Where to put the pointer of a new age action.
13574 : : *
13575 : : * @return
13576 : : * The age actions pool pointer and @p age_free is set on success,
13577 : : * NULL otherwise and rte_errno is set.
13578 : : */
13579 : : static struct mlx5_aso_age_pool *
13580 : 0 : flow_dv_age_pool_create(struct rte_eth_dev *dev,
13581 : : struct mlx5_aso_age_action **age_free)
13582 : : {
13583 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13584 : 0 : struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
13585 : : struct mlx5_aso_age_pool *pool = NULL;
13586 : : struct mlx5_devx_obj *obj = NULL;
13587 : : uint32_t i;
13588 : :
13589 : 0 : obj = mlx5_devx_cmd_create_flow_hit_aso_obj(priv->sh->cdev->ctx,
13590 : 0 : priv->sh->cdev->pdn);
13591 [ # # ]: 0 : if (!obj) {
13592 : 0 : rte_errno = ENODATA;
13593 : 0 : DRV_LOG(ERR, "Failed to create flow_hit_aso_obj using DevX.");
13594 : 0 : return NULL;
13595 : : }
13596 : 0 : pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
13597 [ # # ]: 0 : if (!pool) {
13598 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
13599 : 0 : rte_errno = ENOMEM;
13600 : 0 : return NULL;
13601 : : }
13602 : 0 : pool->flow_hit_aso_obj = obj;
13603 : 0 : pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
13604 : 0 : rte_rwlock_write_lock(&mng->resize_rwl);
13605 : 0 : pool->index = mng->next;
13606 : : /* Resize pools array if there is no room for the new pool in it. */
13607 [ # # # # ]: 0 : if (pool->index == mng->n && flow_dv_aso_age_pools_resize(dev)) {
13608 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
13609 : 0 : mlx5_free(pool);
13610 : : rte_rwlock_write_unlock(&mng->resize_rwl);
13611 : 0 : return NULL;
13612 : : }
13613 : 0 : mng->pools[pool->index] = pool;
13614 : 0 : mng->next++;
13615 : : rte_rwlock_write_unlock(&mng->resize_rwl);
13616 : : /* Assign the first action in the new pool, the rest go to free list. */
13617 : 0 : *age_free = &pool->actions[0];
13618 [ # # ]: 0 : for (i = 1; i < MLX5_ASO_AGE_ACTIONS_PER_POOL; i++) {
13619 : 0 : pool->actions[i].offset = i;
13620 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free, &pool->actions[i], next);
13621 : : }
13622 : : return pool;
13623 : : }
13624 : :
13625 : : /**
13626 : : * Allocate a ASO aging bit.
13627 : : *
13628 : : * @param[in] dev
13629 : : * Pointer to the Ethernet device structure.
13630 : : * @param[out] error
13631 : : * Pointer to the error structure.
13632 : : *
13633 : : * @return
13634 : : * Index to ASO age action on success, 0 otherwise and rte_errno is set.
13635 : : */
13636 : : static uint32_t
13637 : 0 : flow_dv_aso_age_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
13638 : : {
13639 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13640 : : const struct mlx5_aso_age_pool *pool;
13641 : 0 : struct mlx5_aso_age_action *age_free = NULL;
13642 : 0 : struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
13643 : :
13644 : : MLX5_ASSERT(mng);
13645 : : /* Try to get the next free age action bit. */
13646 : 0 : rte_spinlock_lock(&mng->free_sl);
13647 : 0 : age_free = LIST_FIRST(&mng->free);
13648 [ # # ]: 0 : if (age_free) {
13649 [ # # ]: 0 : LIST_REMOVE(age_free, next);
13650 [ # # ]: 0 : } else if (!flow_dv_age_pool_create(dev, &age_free)) {
13651 : : rte_spinlock_unlock(&mng->free_sl);
13652 : 0 : rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
13653 : : NULL, "failed to create ASO age pool");
13654 : 0 : return 0; /* 0 is an error. */
13655 : : }
13656 : : rte_spinlock_unlock(&mng->free_sl);
13657 : 0 : pool = container_of
13658 : : ((const struct mlx5_aso_age_action (*)[MLX5_ASO_AGE_ACTIONS_PER_POOL])
13659 : : (age_free - age_free->offset), const struct mlx5_aso_age_pool,
13660 : : actions);
13661 [ # # ]: 0 : if (!age_free->dr_action) {
13662 : 0 : int reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_FLOW_HIT, 0,
13663 : : error);
13664 : :
13665 [ # # ]: 0 : if (reg_c < 0) {
13666 : 0 : rte_flow_error_set(error, rte_errno,
13667 : : RTE_FLOW_ERROR_TYPE_ACTION,
13668 : : NULL, "failed to get reg_c "
13669 : : "for ASO flow hit");
13670 : 0 : return 0; /* 0 is an error. */
13671 : : }
13672 : : #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
13673 : 0 : age_free->dr_action = mlx5_glue->dv_create_flow_action_aso
13674 : 0 : (priv->sh->rx_domain,
13675 : 0 : pool->flow_hit_aso_obj->obj, age_free->offset,
13676 : : MLX5DV_DR_ACTION_FLAGS_ASO_FIRST_HIT_SET,
13677 : 0 : (reg_c - REG_C_0));
13678 : : #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
13679 [ # # ]: 0 : if (!age_free->dr_action) {
13680 : 0 : rte_errno = errno;
13681 : : rte_spinlock_lock(&mng->free_sl);
13682 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free, age_free, next);
13683 : : rte_spinlock_unlock(&mng->free_sl);
13684 : 0 : rte_flow_error_set(error, rte_errno,
13685 : : RTE_FLOW_ERROR_TYPE_ACTION,
13686 : : NULL, "failed to create ASO "
13687 : : "flow hit action");
13688 : 0 : return 0; /* 0 is an error. */
13689 : : }
13690 : : }
13691 : 0 : rte_atomic_store_explicit(&age_free->refcnt, 1, rte_memory_order_relaxed);
13692 : 0 : return pool->index | ((age_free->offset + 1) << 16);
13693 : : }
13694 : :
13695 : : /**
13696 : : * Initialize flow ASO age parameters.
13697 : : *
13698 : : * @param[in] dev
13699 : : * Pointer to rte_eth_dev structure.
13700 : : * @param[in] age_idx
13701 : : * Index of ASO age action.
13702 : : * @param[in] context
13703 : : * Pointer to flow counter age context.
13704 : : * @param[in] timeout
13705 : : * Aging timeout in seconds.
13706 : : *
13707 : : */
13708 : : static void
13709 : 0 : flow_dv_aso_age_params_init(struct rte_eth_dev *dev,
13710 : : uint32_t age_idx,
13711 : : void *context,
13712 : : uint32_t timeout)
13713 : : {
13714 : : struct mlx5_aso_age_action *aso_age;
13715 : :
13716 : 0 : aso_age = flow_aso_age_get_by_idx(dev, age_idx);
13717 : : MLX5_ASSERT(aso_age);
13718 : 0 : aso_age->age_params.context = context;
13719 : 0 : aso_age->age_params.timeout = timeout;
13720 : 0 : aso_age->age_params.port_id = dev->data->port_id;
13721 : 0 : rte_atomic_store_explicit(&aso_age->age_params.sec_since_last_hit, 0,
13722 : : rte_memory_order_relaxed);
13723 : 0 : rte_atomic_store_explicit(&aso_age->age_params.state, AGE_CANDIDATE,
13724 : : rte_memory_order_relaxed);
13725 : 0 : }
13726 : :
13727 : : static void
13728 : 0 : flow_dv_translate_integrity_l4(const struct rte_flow_item_integrity *mask,
13729 : : void *headers)
13730 : : {
13731 : : /*
13732 : : * In HWS mode MLX5_ITEM_UPDATE() macro assigns the same pointer to
13733 : : * both mask and value, therefore ether can be used.
13734 : : * In SWS SW_V mode mask points to item mask and value points to item
13735 : : * spec. Integrity item value is used only if matching mask is set.
13736 : : * Use mask reference here to keep SWS functionality.
13737 : : */
13738 [ # # ]: 0 : if (mask->l4_ok) {
13739 : : /* RTE l4_ok filter aggregates hardware l4_ok and
13740 : : * l4_checksum_ok filters.
13741 : : * Positive RTE l4_ok match requires hardware match on both L4
13742 : : * hardware integrity bits.
13743 : : * PMD supports positive integrity item semantics only.
13744 : : */
13745 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, l4_ok, 1);
13746 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, l4_checksum_ok, 1);
13747 [ # # ]: 0 : } else if (mask->l4_csum_ok) {
13748 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, l4_checksum_ok, 1);
13749 : : }
13750 : 0 : }
13751 : :
13752 : : static void
13753 : 0 : flow_dv_translate_integrity_l3(const struct rte_flow_item_integrity *mask,
13754 : : void *headers, bool is_ipv4)
13755 : : {
13756 : : /*
13757 : : * In HWS mode MLX5_ITEM_UPDATE() macro assigns the same pointer to
13758 : : * both mask and value, therefore ether can be used.
13759 : : * In SWS SW_V mode mask points to item mask and value points to item
13760 : : * spec. Integrity item value used only if matching mask is set.
13761 : : * Use mask reference here to keep SWS functionality.
13762 : : */
13763 [ # # ]: 0 : if (mask->l3_ok) {
13764 : : /* RTE l3_ok filter aggregates for IPv4 hardware l3_ok and
13765 : : * ipv4_csum_ok filters.
13766 : : * Positive RTE l3_ok match requires hardware match on both L3
13767 : : * hardware integrity bits.
13768 : : * PMD supports positive integrity item semantics only.
13769 : : */
13770 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, l3_ok, 1);
13771 [ # # ]: 0 : if (is_ipv4) {
13772 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers,
13773 : : ipv4_checksum_ok, 1);
13774 : : }
13775 [ # # # # ]: 0 : } else if (is_ipv4 && mask->ipv4_csum_ok) {
13776 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, ipv4_checksum_ok, 1);
13777 : : }
13778 : 0 : }
13779 : :
13780 : : static void
13781 : 0 : set_integrity_bits(void *headers, const struct rte_flow_item *integrity_item,
13782 : : bool is_l3_ip4, uint32_t key_type)
13783 : : {
13784 : : const struct rte_flow_item_integrity *spec;
13785 : : const struct rte_flow_item_integrity *mask;
13786 : :
13787 : : /* Integrity bits validation cleared spec pointer */
13788 [ # # # # : 0 : if (MLX5_ITEM_VALID(integrity_item, key_type))
# # # # #
# ]
13789 : : return;
13790 [ # # # # : 0 : MLX5_ITEM_UPDATE(integrity_item, key_type, spec, mask,
# # # # ]
13791 : : &rte_flow_item_integrity_mask);
13792 : 0 : flow_dv_translate_integrity_l3(mask, headers, is_l3_ip4);
13793 : 0 : flow_dv_translate_integrity_l4(mask, headers);
13794 : : }
13795 : :
13796 : : static void
13797 : 0 : flow_dv_translate_item_integrity_post(void *key,
13798 : : const
13799 : : struct rte_flow_item *integrity_items[2],
13800 : : uint64_t pattern_flags, uint32_t key_type)
13801 : : {
13802 : : void *headers;
13803 : : bool is_l3_ip4;
13804 : :
13805 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_INNER_INTEGRITY) {
13806 : 0 : headers = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
13807 : 0 : is_l3_ip4 = (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV4) !=
13808 : : 0;
13809 : 0 : set_integrity_bits(headers, integrity_items[1], is_l3_ip4,
13810 : : key_type);
13811 : : }
13812 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_OUTER_INTEGRITY) {
13813 : : headers = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
13814 : 0 : is_l3_ip4 = (pattern_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV4) !=
13815 : : 0;
13816 : 0 : set_integrity_bits(headers, integrity_items[0], is_l3_ip4,
13817 : : key_type);
13818 : : }
13819 : 0 : }
13820 : :
13821 : : static uint64_t
13822 : : flow_dv_translate_item_integrity(const struct rte_flow_item *item,
13823 : : struct mlx5_dv_matcher_workspace *wks,
13824 : : uint64_t key_type)
13825 : : {
13826 : 0 : if ((key_type & MLX5_SET_MATCHER_SW) != 0) {
13827 : : const struct rte_flow_item_integrity
13828 : 0 : *spec = (typeof(spec))item->spec;
13829 : :
13830 : : /* SWS integrity bits validation cleared spec pointer */
13831 [ # # ]: 0 : if (spec->level > 1) {
13832 : 0 : wks->integrity_items[1] = item;
13833 : 0 : wks->last_item |= MLX5_FLOW_ITEM_INNER_INTEGRITY;
13834 : : } else {
13835 : 0 : wks->integrity_items[0] = item;
13836 : 0 : wks->last_item |= MLX5_FLOW_ITEM_OUTER_INTEGRITY;
13837 : : }
13838 : : } else {
13839 : : /* HWS supports outer integrity only */
13840 : 0 : wks->integrity_items[0] = item;
13841 : 0 : wks->last_item |= MLX5_FLOW_ITEM_OUTER_INTEGRITY;
13842 : : }
13843 : 0 : return wks->last_item;
13844 : : }
13845 : :
13846 : : /**
13847 : : * Prepares DV flow counter with aging configuration.
13848 : : * Gets it by index when exists, creates a new one when doesn't.
13849 : : *
13850 : : * @param[in] dev
13851 : : * Pointer to rte_eth_dev structure.
13852 : : * @param[in] dev_flow
13853 : : * Pointer to the mlx5_flow.
13854 : : * @param[in, out] flow
13855 : : * Pointer to the sub flow.
13856 : : * @param[in] count
13857 : : * Pointer to the counter action configuration.
13858 : : * @param[in] age
13859 : : * Pointer to the aging action configuration.
13860 : : * @param[out] error
13861 : : * Pointer to the error structure.
13862 : : *
13863 : : * @return
13864 : : * Pointer to the counter, NULL otherwise.
13865 : : */
13866 : : static struct mlx5_flow_counter *
13867 : 0 : flow_dv_prepare_counter(struct rte_eth_dev *dev,
13868 : : struct mlx5_flow *dev_flow,
13869 : : struct rte_flow *flow,
13870 : : const struct rte_flow_action_count *count,
13871 : : const struct rte_flow_action_age *age,
13872 : : struct rte_flow_error *error)
13873 : : {
13874 [ # # ]: 0 : if (!flow->counter) {
13875 : 0 : flow->counter = flow_dv_translate_create_counter(dev, dev_flow,
13876 : : count, age);
13877 [ # # ]: 0 : if (!flow->counter) {
13878 : 0 : rte_flow_error_set(error, rte_errno,
13879 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
13880 : : "cannot create counter object.");
13881 : 0 : return NULL;
13882 : : }
13883 : : }
13884 [ # # ]: 0 : return flow_dv_counter_get_by_idx(dev, flow->counter, NULL);
13885 : : }
13886 : :
13887 : : /*
13888 : : * Release an ASO CT action by its own device.
13889 : : *
13890 : : * @param[in] dev
13891 : : * Pointer to the Ethernet device structure.
13892 : : * @param[in] idx
13893 : : * Index of ASO CT action to release.
13894 : : *
13895 : : * @return
13896 : : * 0 when CT action was removed, otherwise the number of references.
13897 : : */
13898 : : static inline int
13899 : 0 : flow_dv_aso_ct_dev_release(struct rte_eth_dev *dev, uint32_t idx)
13900 : : {
13901 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13902 : 0 : struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
13903 : : uint32_t ret;
13904 : 0 : struct mlx5_aso_ct_action *ct = flow_aso_ct_get_by_dev_idx(dev, idx);
13905 : : enum mlx5_aso_ct_state state =
13906 : 0 : rte_atomic_load_explicit(&ct->state, rte_memory_order_relaxed);
13907 : :
13908 : : /* Cannot release when CT is in the ASO SQ. */
13909 [ # # ]: 0 : if (state == ASO_CONNTRACK_WAIT || state == ASO_CONNTRACK_QUERY)
13910 : : return -1;
13911 : 0 : ret = rte_atomic_fetch_sub_explicit(&ct->refcnt, 1, rte_memory_order_relaxed) - 1;
13912 [ # # ]: 0 : if (!ret) {
13913 [ # # ]: 0 : if (ct->dr_action_orig) {
13914 : : #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
13915 : 0 : claim_zero(mlx5_glue->destroy_flow_action
13916 : : (ct->dr_action_orig));
13917 : : #endif
13918 : 0 : ct->dr_action_orig = NULL;
13919 : : }
13920 [ # # ]: 0 : if (ct->dr_action_rply) {
13921 : : #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
13922 : 0 : claim_zero(mlx5_glue->destroy_flow_action
13923 : : (ct->dr_action_rply));
13924 : : #endif
13925 : 0 : ct->dr_action_rply = NULL;
13926 : : }
13927 : : /* Clear the state to free, no need in 1st allocation. */
13928 : 0 : MLX5_ASO_CT_UPDATE_STATE(ct, ASO_CONNTRACK_FREE);
13929 : 0 : rte_spinlock_lock(&mng->ct_sl);
13930 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free_cts, ct, next);
13931 : : rte_spinlock_unlock(&mng->ct_sl);
13932 : : }
13933 : 0 : return (int)ret;
13934 : : }
13935 : :
13936 : : static inline int
13937 : 0 : flow_dv_aso_ct_release(struct rte_eth_dev *dev, uint32_t own_idx,
13938 : : struct rte_flow_error *error)
13939 : : {
13940 : 0 : uint16_t owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(own_idx);
13941 : 0 : uint32_t idx = MLX5_INDIRECT_ACT_CT_GET_IDX(own_idx);
13942 : 0 : struct rte_eth_dev *owndev = &rte_eth_devices[owner];
13943 : : int ret;
13944 : :
13945 : : MLX5_ASSERT(owner < RTE_MAX_ETHPORTS);
13946 [ # # ]: 0 : if (dev->data->dev_started != 1)
13947 : 0 : return rte_flow_error_set(error, EAGAIN,
13948 : : RTE_FLOW_ERROR_TYPE_ACTION,
13949 : : NULL,
13950 : : "Indirect CT action cannot be destroyed when the port is stopped");
13951 : 0 : ret = flow_dv_aso_ct_dev_release(owndev, idx);
13952 [ # # ]: 0 : if (ret < 0)
13953 : 0 : return rte_flow_error_set(error, EAGAIN,
13954 : : RTE_FLOW_ERROR_TYPE_ACTION,
13955 : : NULL,
13956 : : "Current state prevents indirect CT action from being destroyed");
13957 : : return ret;
13958 : : }
13959 : :
13960 : : /*
13961 : : * Resize the ASO CT pools array by 64 pools.
13962 : : *
13963 : : * @param[in] dev
13964 : : * Pointer to the Ethernet device structure.
13965 : : *
13966 : : * @return
13967 : : * 0 on success, otherwise negative errno value and rte_errno is set.
13968 : : */
13969 : : static int
13970 : 0 : flow_dv_aso_ct_pools_resize(struct rte_eth_dev *dev)
13971 : : {
13972 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13973 : 0 : struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
13974 : 0 : void *old_pools = mng->pools;
13975 : : /* Magic number now, need a macro. */
13976 : 0 : uint32_t resize = mng->n + 64;
13977 : 0 : uint32_t mem_size = sizeof(struct mlx5_aso_ct_pool *) * resize;
13978 : 0 : void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
13979 : :
13980 [ # # ]: 0 : if (!pools) {
13981 : 0 : rte_errno = ENOMEM;
13982 : 0 : return -rte_errno;
13983 : : }
13984 : 0 : rte_rwlock_write_lock(&mng->resize_rwl);
13985 : : /* ASO SQ/QP was already initialized in the startup. */
13986 [ # # ]: 0 : if (old_pools) {
13987 : : /* Realloc could be an alternative choice. */
13988 : 0 : rte_memcpy(pools, old_pools,
13989 [ # # ]: 0 : mng->n * sizeof(struct mlx5_aso_ct_pool *));
13990 : 0 : mlx5_free(old_pools);
13991 : : }
13992 : 0 : mng->n = resize;
13993 : 0 : mng->pools = pools;
13994 : : rte_rwlock_write_unlock(&mng->resize_rwl);
13995 : 0 : return 0;
13996 : : }
13997 : :
13998 : : /*
13999 : : * Create and initialize a new ASO CT pool.
14000 : : *
14001 : : * @param[in] dev
14002 : : * Pointer to the Ethernet device structure.
14003 : : * @param[out] ct_free
14004 : : * Where to put the pointer of a new CT action.
14005 : : *
14006 : : * @return
14007 : : * The CT actions pool pointer and @p ct_free is set on success,
14008 : : * NULL otherwise and rte_errno is set.
14009 : : */
14010 : : static struct mlx5_aso_ct_pool *
14011 : 0 : flow_dv_ct_pool_create(struct rte_eth_dev *dev,
14012 : : struct mlx5_aso_ct_action **ct_free)
14013 : : {
14014 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14015 : 0 : struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
14016 : : struct mlx5_aso_ct_pool *pool = NULL;
14017 : : struct mlx5_devx_obj *obj = NULL;
14018 : : uint32_t i;
14019 : : uint32_t log_obj_size = rte_log2_u32(MLX5_ASO_CT_ACTIONS_PER_POOL);
14020 : : size_t mem_size;
14021 : :
14022 : 0 : obj = mlx5_devx_cmd_create_conn_track_offload_obj(priv->sh->cdev->ctx,
14023 : 0 : priv->sh->cdev->pdn,
14024 : : log_obj_size);
14025 [ # # ]: 0 : if (!obj) {
14026 : 0 : rte_errno = ENODATA;
14027 : 0 : DRV_LOG(ERR, "Failed to create conn_track_offload_obj using DevX.");
14028 : 0 : return NULL;
14029 : : }
14030 : : mem_size = sizeof(struct mlx5_aso_ct_action) *
14031 : : MLX5_ASO_CT_ACTIONS_PER_POOL +
14032 : : sizeof(*pool);
14033 : 0 : pool = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
14034 [ # # ]: 0 : if (!pool) {
14035 : 0 : rte_errno = ENOMEM;
14036 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
14037 : 0 : return NULL;
14038 : : }
14039 : 0 : pool->devx_obj = obj;
14040 : 0 : pool->index = mng->next;
14041 : : /* Resize pools array if there is no room for the new pool in it. */
14042 [ # # # # ]: 0 : if (pool->index == mng->n && flow_dv_aso_ct_pools_resize(dev)) {
14043 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
14044 : 0 : mlx5_free(pool);
14045 : 0 : return NULL;
14046 : : }
14047 : 0 : mng->pools[pool->index] = pool;
14048 : 0 : mng->next++;
14049 : : /* Assign the first action in the new pool, the rest go to free list. */
14050 : 0 : *ct_free = &pool->actions[0];
14051 : : /* Lock outside, the list operation is safe here. */
14052 [ # # ]: 0 : for (i = 1; i < MLX5_ASO_CT_ACTIONS_PER_POOL; i++) {
14053 : : /* refcnt is 0 when allocating the memory. */
14054 : 0 : pool->actions[i].offset = i;
14055 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free_cts, &pool->actions[i], next);
14056 : : }
14057 : : return pool;
14058 : : }
14059 : :
14060 : : /*
14061 : : * Allocate a ASO CT action from free list.
14062 : : *
14063 : : * @param[in] dev
14064 : : * Pointer to the Ethernet device structure.
14065 : : * @param[out] error
14066 : : * Pointer to the error structure.
14067 : : *
14068 : : * @return
14069 : : * Index to ASO CT action on success, 0 otherwise and rte_errno is set.
14070 : : */
14071 : : static uint32_t
14072 : 0 : flow_dv_aso_ct_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
14073 : : {
14074 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14075 : 0 : struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
14076 : 0 : struct mlx5_aso_ct_action *ct = NULL;
14077 : : struct mlx5_aso_ct_pool *pool;
14078 : : uint8_t reg_c;
14079 : : uint32_t ct_idx;
14080 : :
14081 : : MLX5_ASSERT(mng);
14082 [ # # ]: 0 : if (!priv->sh->cdev->config.devx) {
14083 : 0 : rte_errno = ENOTSUP;
14084 : 0 : return 0;
14085 : : }
14086 : : /* Get a free CT action, if no, a new pool will be created. */
14087 : 0 : rte_spinlock_lock(&mng->ct_sl);
14088 : 0 : ct = LIST_FIRST(&mng->free_cts);
14089 [ # # ]: 0 : if (ct) {
14090 [ # # ]: 0 : LIST_REMOVE(ct, next);
14091 [ # # ]: 0 : } else if (!flow_dv_ct_pool_create(dev, &ct)) {
14092 : : rte_spinlock_unlock(&mng->ct_sl);
14093 : 0 : rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
14094 : : NULL, "failed to create ASO CT pool");
14095 : 0 : return 0;
14096 : : }
14097 : : rte_spinlock_unlock(&mng->ct_sl);
14098 : 0 : pool = container_of(ct, struct mlx5_aso_ct_pool, actions[ct->offset]);
14099 : 0 : ct_idx = MLX5_MAKE_CT_IDX(pool->index, ct->offset);
14100 : : /* 0: inactive, 1: created, 2+: used by flows. */
14101 : 0 : rte_atomic_store_explicit(&ct->refcnt, 1, rte_memory_order_relaxed);
14102 : 0 : reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_CONNTRACK, 0, error);
14103 [ # # ]: 0 : if (!ct->dr_action_orig) {
14104 : : #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
14105 : 0 : ct->dr_action_orig = mlx5_glue->dv_create_flow_action_aso
14106 : 0 : (priv->sh->rx_domain, pool->devx_obj->obj,
14107 : : ct->offset,
14108 : : MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_INITIATOR,
14109 : 0 : reg_c - REG_C_0);
14110 : : #else
14111 : : RTE_SET_USED(reg_c);
14112 : : #endif
14113 [ # # ]: 0 : if (!ct->dr_action_orig) {
14114 : 0 : flow_dv_aso_ct_dev_release(dev, ct_idx);
14115 : 0 : rte_flow_error_set(error, rte_errno,
14116 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14117 : : "failed to create ASO CT action");
14118 : 0 : return 0;
14119 : : }
14120 : : }
14121 [ # # ]: 0 : if (!ct->dr_action_rply) {
14122 : : #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
14123 : 0 : ct->dr_action_rply = mlx5_glue->dv_create_flow_action_aso
14124 : 0 : (priv->sh->rx_domain, pool->devx_obj->obj,
14125 : : ct->offset,
14126 : : MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_RESPONDER,
14127 : 0 : reg_c - REG_C_0);
14128 : : #endif
14129 [ # # ]: 0 : if (!ct->dr_action_rply) {
14130 : 0 : flow_dv_aso_ct_dev_release(dev, ct_idx);
14131 : 0 : rte_flow_error_set(error, rte_errno,
14132 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14133 : : "failed to create ASO CT action");
14134 : 0 : return 0;
14135 : : }
14136 : : }
14137 : : return ct_idx;
14138 : : }
14139 : :
14140 : : /*
14141 : : * Create a conntrack object with context and actions by using ASO mechanism.
14142 : : *
14143 : : * @param[in] dev
14144 : : * Pointer to rte_eth_dev structure.
14145 : : * @param[in] pro
14146 : : * Pointer to conntrack information profile.
14147 : : * @param[out] error
14148 : : * Pointer to the error structure.
14149 : : *
14150 : : * @return
14151 : : * Index to conntrack object on success, 0 otherwise.
14152 : : */
14153 : : static uint32_t
14154 : 0 : flow_dv_translate_create_conntrack(struct rte_eth_dev *dev,
14155 : : const struct rte_flow_action_conntrack *pro,
14156 : : struct rte_flow_error *error)
14157 : : {
14158 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14159 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
14160 : : struct mlx5_aso_ct_action *ct;
14161 : : uint32_t idx;
14162 : :
14163 [ # # ]: 0 : if (!sh->ct_aso_en)
14164 : 0 : return rte_flow_error_set(error, ENOTSUP,
14165 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14166 : : "Connection is not supported");
14167 [ # # ]: 0 : if (dev->data->port_id >= MLX5_INDIRECT_ACT_CT_MAX_PORT) {
14168 : 0 : rte_flow_error_set(error, EINVAL,
14169 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14170 : : "CT supports port indexes up to "
14171 : : RTE_STR(MLX5_ACTION_CTX_CT_MAX_PORT));
14172 : 0 : return 0;
14173 : : }
14174 : 0 : idx = flow_dv_aso_ct_alloc(dev, error);
14175 [ # # ]: 0 : if (!idx)
14176 : 0 : return rte_flow_error_set(error, rte_errno,
14177 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14178 : : "Failed to allocate CT object");
14179 : 0 : ct = flow_aso_ct_get_by_dev_idx(dev, idx);
14180 [ # # ]: 0 : if (mlx5_aso_ct_update_by_wqe(sh, MLX5_HW_INV_QUEUE, ct, pro, NULL, true)) {
14181 : 0 : flow_dv_aso_ct_dev_release(dev, idx);
14182 : 0 : rte_flow_error_set(error, EBUSY,
14183 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14184 : : "Failed to update CT");
14185 : 0 : return 0;
14186 : : }
14187 : 0 : ct->is_original = !!pro->is_original_dir;
14188 : 0 : ct->peer = pro->peer_port;
14189 : 0 : return idx;
14190 : : }
14191 : :
14192 : : /**
14193 : : * Fill the flow matcher with DV spec.
14194 : : *
14195 : : * @param[in] dev
14196 : : * Pointer to rte_eth_dev structure.
14197 : : * @param[in] items
14198 : : * Pointer to the list of items.
14199 : : * @param[in] wks
14200 : : * Pointer to the matcher workspace.
14201 : : * @param[in] key
14202 : : * Pointer to the flow matcher key.
14203 : : * @param[in] key_type
14204 : : * Key type.
14205 : : * @param[out] error
14206 : : * Pointer to the error structure.
14207 : : *
14208 : : * @return
14209 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14210 : : */
14211 : : static int
14212 : 0 : flow_dv_translate_items(struct rte_eth_dev *dev,
14213 : : const struct rte_flow_item *items,
14214 : : struct mlx5_dv_matcher_workspace *wks,
14215 : : void *key, uint32_t key_type,
14216 : : struct rte_flow_error *error)
14217 : : {
14218 : 0 : struct mlx5_flow_rss_desc *rss_desc = wks->rss_desc;
14219 : 0 : uint8_t next_protocol = wks->next_protocol;
14220 : 0 : int tunnel = !!(wks->item_flags & MLX5_FLOW_LAYER_TUNNEL);
14221 : 0 : int item_type = items->type;
14222 : 0 : uint64_t last_item = wks->last_item;
14223 : : enum mlx5_l3_tunnel_detection l3_tunnel_detection;
14224 : : uint64_t l3_tunnel_flag;
14225 : : int ret;
14226 : :
14227 [ # # # # : 0 : switch (item_type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
14228 : 0 : case RTE_FLOW_ITEM_TYPE_ESP:
14229 : 0 : flow_dv_translate_item_esp(key, items, tunnel, key_type);
14230 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14231 : : last_item = MLX5_FLOW_ITEM_ESP;
14232 : 0 : break;
14233 : 0 : case RTE_FLOW_ITEM_TYPE_PORT_ID:
14234 : 0 : flow_dv_translate_item_port_id
14235 : : (dev, key, items, wks->attr, key_type);
14236 : : last_item = MLX5_FLOW_ITEM_PORT_ID;
14237 : 0 : break;
14238 : 0 : case RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR:
14239 : 0 : flow_dv_translate_item_port_representor
14240 : : (dev, key, key_type);
14241 : : last_item = MLX5_FLOW_ITEM_PORT_REPRESENTOR;
14242 : 0 : break;
14243 : 0 : case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
14244 : 0 : flow_dv_translate_item_represented_port
14245 : : (dev, key, items, wks->attr, key_type);
14246 : : last_item = MLX5_FLOW_ITEM_REPRESENTED_PORT;
14247 : 0 : break;
14248 : 0 : case RTE_FLOW_ITEM_TYPE_ETH:
14249 : 0 : flow_dv_translate_item_eth(key, items, tunnel,
14250 : : wks->group, key_type);
14251 [ # # ]: 0 : wks->priority = wks->action_flags &
14252 : 0 : MLX5_FLOW_ACTION_DEFAULT_MISS &&
14253 [ # # ]: 0 : !wks->external ?
14254 : : MLX5_PRIORITY_MAP_L3 :
14255 : : MLX5_PRIORITY_MAP_L2;
14256 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
14257 : : MLX5_FLOW_LAYER_OUTER_L2;
14258 : : break;
14259 : 0 : case RTE_FLOW_ITEM_TYPE_VLAN:
14260 : 0 : flow_dv_translate_item_vlan(key, items, tunnel, wks, key_type);
14261 : 0 : wks->priority = MLX5_PRIORITY_MAP_L2;
14262 : : last_item = tunnel ? (MLX5_FLOW_LAYER_INNER_L2 |
14263 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_VLAN) :
14264 : : (MLX5_FLOW_LAYER_OUTER_L2 |
14265 : : MLX5_FLOW_LAYER_OUTER_VLAN);
14266 : : break;
14267 : : case RTE_FLOW_ITEM_TYPE_IPV4:
14268 : : next_protocol = mlx5_flow_l3_next_protocol(items, key_type);
14269 : : l3_tunnel_detection =
14270 : : mlx5_flow_tunnel_ip_check(items, next_protocol,
14271 : : wks->item_flags,
14272 : : &l3_tunnel_flag);
14273 : : if (l3_tunnel_detection == l3_tunnel_inner) {
14274 : 0 : wks->item_flags |= l3_tunnel_flag;
14275 : : tunnel = 1;
14276 : : }
14277 : 0 : flow_dv_translate_item_ipv4(key, items, tunnel,
14278 : : wks->group, key_type);
14279 : 0 : wks->priority = MLX5_PRIORITY_MAP_L3;
14280 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
14281 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4;
14282 [ # # ]: 0 : if (l3_tunnel_detection == l3_tunnel_outer)
14283 : 0 : wks->item_flags |= l3_tunnel_flag;
14284 : : break;
14285 : : case RTE_FLOW_ITEM_TYPE_IPV6:
14286 : : next_protocol = mlx5_flow_l3_next_protocol(items, key_type);
14287 : : l3_tunnel_detection =
14288 : : mlx5_flow_tunnel_ip_check(items, next_protocol,
14289 : : wks->item_flags,
14290 : : &l3_tunnel_flag);
14291 : : if (l3_tunnel_detection == l3_tunnel_inner) {
14292 : 0 : wks->item_flags |= l3_tunnel_flag;
14293 : : tunnel = 1;
14294 : : }
14295 : 0 : flow_dv_translate_item_ipv6(key, items, tunnel,
14296 : : wks->group, key_type);
14297 : 0 : wks->priority = MLX5_PRIORITY_MAP_L3;
14298 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
14299 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6;
14300 [ # # ]: 0 : if (l3_tunnel_detection == l3_tunnel_outer)
14301 : 0 : wks->item_flags |= l3_tunnel_flag;
14302 : : break;
14303 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
14304 : 0 : flow_dv_translate_item_ipv6_frag_ext
14305 : : (key, items, tunnel, key_type);
14306 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
14307 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
14308 : : next_protocol = mlx5_flow_l3_next_protocol(items, key_type);
14309 : : break;
14310 : 0 : case RTE_FLOW_ITEM_TYPE_TCP:
14311 : 0 : flow_dv_translate_item_tcp(key, items, tunnel, key_type);
14312 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14313 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
14314 : : MLX5_FLOW_LAYER_OUTER_L4_TCP;
14315 : : break;
14316 : 0 : case RTE_FLOW_ITEM_TYPE_UDP:
14317 : 0 : flow_dv_translate_item_udp(key, items, tunnel, wks, key_type);
14318 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14319 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
14320 : : MLX5_FLOW_LAYER_OUTER_L4_UDP;
14321 : : break;
14322 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
14323 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14324 : 0 : wks->tunnel_item = items;
14325 : 0 : wks->gre_item = items;
14326 : : last_item = MLX5_FLOW_LAYER_GRE;
14327 : 0 : break;
14328 : 0 : case RTE_FLOW_ITEM_TYPE_GRE_KEY:
14329 : 0 : flow_dv_translate_item_gre_key(key, items, key_type);
14330 : : last_item = MLX5_FLOW_LAYER_GRE_KEY;
14331 : 0 : break;
14332 : 0 : case RTE_FLOW_ITEM_TYPE_GRE_OPTION:
14333 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14334 : 0 : wks->tunnel_item = items;
14335 : : last_item = MLX5_FLOW_LAYER_GRE;
14336 : 0 : break;
14337 : 0 : case RTE_FLOW_ITEM_TYPE_NVGRE:
14338 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14339 : 0 : wks->tunnel_item = items;
14340 : : last_item = MLX5_FLOW_LAYER_GRE;
14341 : 0 : break;
14342 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN:
14343 : 0 : flow_dv_translate_item_vxlan(dev, wks->attr, key,
14344 : : items, tunnel, wks, key_type);
14345 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14346 : : last_item = MLX5_FLOW_LAYER_VXLAN;
14347 : 0 : break;
14348 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
14349 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14350 : 0 : wks->tunnel_item = items;
14351 : : last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
14352 : 0 : break;
14353 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE:
14354 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14355 : 0 : wks->tunnel_item = items;
14356 : : last_item = MLX5_FLOW_LAYER_GENEVE;
14357 : 0 : break;
14358 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
14359 : 0 : ret = flow_dv_translate_item_geneve_opt
14360 : : (dev, key, items, key_type, error);
14361 [ # # ]: 0 : if (ret)
14362 : 0 : return rte_flow_error_set(error, -ret,
14363 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14364 : : "cannot create GENEVE TLV option");
14365 : 0 : wks->geneve_tlv_option = 1;
14366 : : last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
14367 : 0 : break;
14368 : 0 : case RTE_FLOW_ITEM_TYPE_MPLS:
14369 : 0 : flow_dv_translate_item_mpls(key, items, last_item,
14370 : : tunnel, key_type);
14371 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14372 : : last_item = MLX5_FLOW_LAYER_MPLS;
14373 : 0 : break;
14374 : 0 : case RTE_FLOW_ITEM_TYPE_MARK:
14375 : 0 : flow_dv_translate_item_mark(dev, key, items, key_type);
14376 : : last_item = MLX5_FLOW_ITEM_MARK;
14377 : 0 : break;
14378 : 0 : case RTE_FLOW_ITEM_TYPE_META:
14379 : 0 : flow_dv_translate_item_meta
14380 : : (dev, key, wks->attr, items, key_type);
14381 : : last_item = MLX5_FLOW_ITEM_METADATA;
14382 : 0 : break;
14383 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP:
14384 : 0 : flow_dv_translate_item_icmp(key, items, tunnel, key_type);
14385 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14386 : : last_item = MLX5_FLOW_LAYER_ICMP;
14387 : 0 : break;
14388 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6:
14389 : 0 : flow_dv_translate_item_icmp6(key, items, tunnel, key_type);
14390 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14391 : : last_item = MLX5_FLOW_LAYER_ICMP6;
14392 : 0 : break;
14393 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REQUEST:
14394 : : case RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REPLY:
14395 : 0 : flow_dv_translate_item_icmp6_echo(key, items, tunnel, key_type);
14396 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14397 : : last_item = MLX5_FLOW_LAYER_ICMP6;
14398 : 0 : break;
14399 : 0 : case RTE_FLOW_ITEM_TYPE_TAG:
14400 : 0 : flow_dv_translate_item_tag(dev, key, items, key_type);
14401 : : last_item = MLX5_FLOW_ITEM_TAG;
14402 : 0 : break;
14403 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
14404 : 0 : flow_dv_translate_mlx5_item_tag(dev, key, items, key_type);
14405 : : last_item = MLX5_FLOW_ITEM_TAG;
14406 : 0 : break;
14407 : 0 : case RTE_FLOW_ITEM_TYPE_TX_QUEUE:
14408 : 0 : ret = flow_dv_translate_item_tx_queue(dev, 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 : : "invalid tx_queue item");
14413 : : last_item = MLX5_FLOW_ITEM_SQ;
14414 : : break;
14415 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_SQ:
14416 : 0 : flow_dv_translate_item_sq(key, items, key_type);
14417 : : last_item = MLX5_FLOW_ITEM_SQ;
14418 : 0 : break;
14419 : 0 : case RTE_FLOW_ITEM_TYPE_GTP:
14420 : 0 : flow_dv_translate_item_gtp(key, items, tunnel, key_type);
14421 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14422 : : last_item = MLX5_FLOW_LAYER_GTP;
14423 : 0 : break;
14424 : 0 : case RTE_FLOW_ITEM_TYPE_GTP_PSC:
14425 : 0 : ret = flow_dv_translate_item_gtp_psc(key, items, key_type);
14426 [ # # ]: 0 : if (ret)
14427 : 0 : return rte_flow_error_set(error, -ret,
14428 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14429 : : "cannot create GTP PSC item");
14430 : : last_item = MLX5_FLOW_LAYER_GTP_PSC;
14431 : : break;
14432 : 0 : case RTE_FLOW_ITEM_TYPE_ECPRI:
14433 [ # # ]: 0 : if (!mlx5_flex_parser_ecpri_exist(dev)) {
14434 : : /* Create it only the first time to be used. */
14435 : 0 : ret = mlx5_flex_parser_ecpri_alloc(dev);
14436 [ # # ]: 0 : if (ret)
14437 : 0 : return rte_flow_error_set
14438 : : (error, -ret,
14439 : : RTE_FLOW_ERROR_TYPE_ITEM,
14440 : : NULL,
14441 : : "cannot create eCPRI parser");
14442 : : }
14443 : 0 : flow_dv_translate_item_ecpri
14444 : : (dev, key, items, last_item, key_type);
14445 : : /* No other protocol should follow eCPRI layer. */
14446 : : last_item = MLX5_FLOW_LAYER_ECPRI;
14447 : 0 : break;
14448 : 0 : case RTE_FLOW_ITEM_TYPE_METER_COLOR:
14449 : 0 : flow_dv_translate_item_meter_color(dev, key, items, key_type);
14450 : : last_item = MLX5_FLOW_ITEM_METER_COLOR;
14451 : 0 : break;
14452 [ # # ]: 0 : case RTE_FLOW_ITEM_TYPE_INTEGRITY:
14453 : : last_item = flow_dv_translate_item_integrity(items,
14454 : : wks, key_type);
14455 : 0 : break;
14456 : 0 : case RTE_FLOW_ITEM_TYPE_AGGR_AFFINITY:
14457 : 0 : flow_dv_translate_item_aggr_affinity(key, items, key_type);
14458 : : last_item = MLX5_FLOW_ITEM_AGGR_AFFINITY;
14459 : 0 : break;
14460 : 0 : case RTE_FLOW_ITEM_TYPE_IB_BTH:
14461 : 0 : flow_dv_translate_item_ib_bth(key, items, tunnel, key_type);
14462 : : last_item = MLX5_FLOW_ITEM_IB_BTH;
14463 : 0 : break;
14464 : 0 : case RTE_FLOW_ITEM_TYPE_NSH:
14465 : : last_item = MLX5_FLOW_ITEM_NSH;
14466 : 0 : break;
14467 : : default:
14468 : : break;
14469 : : }
14470 : 0 : wks->item_flags |= last_item;
14471 : 0 : wks->last_item = last_item;
14472 : 0 : wks->next_protocol = next_protocol;
14473 : 0 : return 0;
14474 : : }
14475 : :
14476 : : static int
14477 : 0 : flow_dv_translate_items_geneve_opt_nta(struct rte_eth_dev *dev,
14478 : : const struct rte_flow_item *items,
14479 : : struct mlx5_flow_attr *attr,
14480 : : struct rte_flow_error *error)
14481 : : {
14482 : 0 : rte_be32_t geneve_mask = 0xffffffff;
14483 : 0 : struct rte_pmd_mlx5_geneve_tlv geneve_tlv = {
14484 : : /* Take from item spec, if changed, destroy and add new parser. */
14485 : : .option_class = 0,
14486 : : /* Take from item spec, if changed, destroy and add new parser. */
14487 : : .option_type = 0,
14488 : : /* 1DW is supported. */
14489 : : .option_len = 1,
14490 : : .match_on_class_mode = 1,
14491 : : .offset = 0,
14492 : : .sample_len = 1,
14493 : : .match_data_mask = &geneve_mask
14494 : : };
14495 : 0 : const struct rte_flow_item_geneve_opt *geneve_opt_v = items->spec;
14496 : 0 : const struct rte_flow_item_geneve_opt *geneve_opt_m = items->mask;
14497 : : void *geneve_parser;
14498 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14499 : : #ifdef RTE_LIBRTE_MLX5_DEBUG
14500 : : struct mlx5_geneve_tlv_option *option;
14501 : : #endif
14502 : :
14503 : : /* option length is not as supported. */
14504 [ # # ]: 0 : if ((geneve_opt_v->option_len & geneve_opt_m->option_len) > geneve_tlv.option_len)
14505 : 0 : return rte_flow_error_set(error, ENOTSUP,
14506 : : RTE_FLOW_ERROR_TYPE_ITEM, items,
14507 : : " GENEVE OPT length is not supported ");
14508 : 0 : geneve_tlv.option_class = geneve_opt_v->option_class & geneve_opt_m->option_class;
14509 : 0 : geneve_tlv.option_type = geneve_opt_v->option_type & geneve_opt_m->option_type;
14510 : : /* if parser doesn't exist */
14511 [ # # ]: 0 : if (!priv->tlv_options) {
14512 : : /* Create a GENEVE option parser. */
14513 : 0 : geneve_parser = mlx5_geneve_tlv_parser_create(attr->port_id,
14514 : : &geneve_tlv, 1);
14515 [ # # ]: 0 : if (!geneve_parser)
14516 : 0 : return rte_flow_error_set(error, EINVAL,
14517 : : RTE_FLOW_ERROR_TYPE_ITEM, items,
14518 : : " GENEVE OPT parser creation failed ");
14519 : : #ifdef RTE_LIBRTE_MLX5_DEBUG
14520 : : } else {
14521 : : /* Check if option exist in current parser. */
14522 : : option = mlx5_geneve_tlv_option_get(priv,
14523 : : geneve_tlv.option_type,
14524 : : geneve_tlv.option_class);
14525 : : if (!option)
14526 : : return rte_flow_error_set(error, EINVAL,
14527 : : RTE_FLOW_ERROR_TYPE_ITEM, items,
14528 : : " GENEVE OPT configured does not match this rule class/type");
14529 : : #endif
14530 : : }
14531 : : return 0;
14532 : : }
14533 : :
14534 : : /**
14535 : : * Fill the flow matcher with DV spec for items supported in non template mode.
14536 : : *
14537 : : * @param[in] dev
14538 : : * Pointer to rte_eth_dev structure.
14539 : : * @param[in] items
14540 : : * Pointer to the list of items.
14541 : : * @param[in] wks
14542 : : * Pointer to the matcher workspace.
14543 : : * @param[in] key
14544 : : * Pointer to the flow matcher key.
14545 : : * @param[in] key_type
14546 : : * Key type.
14547 : : * @param[out] error
14548 : : * Pointer to the error structure.
14549 : : *
14550 : : * @return
14551 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14552 : : */
14553 : : static int
14554 : 0 : flow_dv_translate_items_nta(struct rte_eth_dev *dev,
14555 : : const struct rte_flow_item *items,
14556 : : struct mlx5_dv_matcher_workspace *wks,
14557 : : void *key, uint32_t key_type,
14558 : : struct mlx5_flow_attr *attr,
14559 : : struct rte_flow_error *error)
14560 : : {
14561 : : int item_type;
14562 : : int ret = 0;
14563 : : int tunnel;
14564 : : /* Dummy structure to enable the key calculation for flex item. */
14565 : : struct mlx5_flow_dv_match_params flex_item_key;
14566 : :
14567 : 0 : tunnel = !!(wks->item_flags & MLX5_FLOW_LAYER_TUNNEL);
14568 : 0 : item_type = items->type;
14569 [ # # # # ]: 0 : switch (item_type) {
14570 : 0 : case RTE_FLOW_ITEM_TYPE_CONNTRACK:
14571 : 0 : flow_dv_translate_item_aso_ct(dev, key, NULL, items);
14572 : 0 : wks->last_item = MLX5_FLOW_LAYER_ASO_CT;
14573 : 0 : break;
14574 : : /* TODO: remove once flex item translation is added to flow_dv_translate_items. */
14575 : 0 : case RTE_FLOW_ITEM_TYPE_FLEX:
14576 : 0 : mlx5_flex_flow_translate_item(dev, key, flex_item_key.buf, items, tunnel != 0);
14577 [ # # ]: 0 : wks->last_item = tunnel ? MLX5_FLOW_ITEM_INNER_FLEX : MLX5_FLOW_ITEM_OUTER_FLEX;
14578 : 0 : break;
14579 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
14580 : 0 : ret = flow_dv_translate_items_geneve_opt_nta(dev, items, attr, error);
14581 [ # # ]: 0 : if (ret)
14582 : : return ret;
14583 : 0 : wks->last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
14584 : 0 : break;
14585 : 0 : default:
14586 : 0 : ret = flow_dv_translate_items(dev, items, wks, key, key_type, error);
14587 [ # # ]: 0 : if (ret)
14588 : : return ret;
14589 : : break;
14590 : : }
14591 : 0 : wks->item_flags |= wks->last_item;
14592 : 0 : return 0;
14593 : : }
14594 : :
14595 : : /**
14596 : : * Fill the HW steering flow with DV spec.
14597 : : *
14598 : : * @param[in] items
14599 : : * Pointer to the list of items.
14600 : : * @param[in] attr
14601 : : * Pointer to the flow attributes.
14602 : : * @param[in] key
14603 : : * Pointer to the flow matcher key.
14604 : : * @param[in] key_type
14605 : : * Key type.
14606 : : * @param[in, out] item_flags
14607 : : * Pointer to the flow item flags.
14608 : : * @param[in, out] nt_flow
14609 : : * Non template flow.
14610 : : * @param[out] error
14611 : : * Pointer to the error structure.
14612 : : *
14613 : : * @return
14614 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14615 : : */
14616 : : int
14617 : 0 : __flow_dv_translate_items_hws(const struct rte_flow_item *items,
14618 : : struct mlx5_flow_attr *attr, void *key,
14619 : : uint32_t key_type, uint64_t *item_flags,
14620 : : uint8_t *match_criteria,
14621 : : bool nt_flow,
14622 : : struct rte_flow_error *error)
14623 : : {
14624 : 0 : struct mlx5_flow_workspace *flow_wks = mlx5_flow_push_thread_workspace();
14625 : 0 : struct mlx5_flow_rss_desc rss_desc = { .level = attr->rss_level };
14626 : 0 : struct rte_flow_attr rattr = {
14627 : 0 : .group = attr->group,
14628 : 0 : .priority = attr->priority,
14629 : 0 : .ingress = !!(attr->tbl_type == MLX5DR_TABLE_TYPE_NIC_RX),
14630 : 0 : .egress = !!(attr->tbl_type == MLX5DR_TABLE_TYPE_NIC_TX),
14631 : 0 : .transfer = !!(attr->tbl_type == MLX5DR_TABLE_TYPE_FDB),
14632 : : };
14633 : 0 : struct mlx5_dv_matcher_workspace wks = {
14634 : 0 : .action_flags = attr->act_flags,
14635 [ # # ]: 0 : .item_flags = item_flags ? *item_flags : 0,
14636 : : .external = 0,
14637 : : .next_protocol = 0xff,
14638 : : .attr = &rattr,
14639 : : .rss_desc = &rss_desc,
14640 : : .group = attr->group,
14641 : : };
14642 : : int ret = 0;
14643 : :
14644 : : RTE_SET_USED(flow_wks);
14645 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
14646 : : if (!mlx5_flow_os_item_supported(items->type)) {
14647 : : ret = rte_flow_error_set(error, ENOTSUP,
14648 : : RTE_FLOW_ERROR_TYPE_ITEM,
14649 : : NULL, "item not supported");
14650 : : goto exit;
14651 : : }
14652 : : /* Non template flow. */
14653 [ # # ]: 0 : if (nt_flow) {
14654 : 0 : ret = flow_dv_translate_items_nta(&rte_eth_devices[attr->port_id],
14655 : : items, &wks, key, key_type, attr, error);
14656 [ # # ]: 0 : if (ret)
14657 : 0 : goto exit;
14658 : : } else {
14659 : 0 : ret = flow_dv_translate_items(&rte_eth_devices[attr->port_id],
14660 : : items, &wks, key, key_type, error);
14661 [ # # ]: 0 : if (ret)
14662 : 0 : goto exit;
14663 : : }
14664 : : }
14665 [ # # ]: 0 : if (wks.item_flags & MLX5_FLOW_ITEM_INTEGRITY) {
14666 : 0 : flow_dv_translate_item_integrity_post(key,
14667 : : wks.integrity_items,
14668 : : wks.item_flags,
14669 : : key_type);
14670 : : }
14671 [ # # ]: 0 : if (wks.item_flags & MLX5_FLOW_LAYER_VXLAN_GPE) {
14672 : 0 : flow_dv_translate_item_vxlan_gpe(key,
14673 : : wks.tunnel_item,
14674 : : wks.item_flags,
14675 : : key_type);
14676 [ # # ]: 0 : } else if (wks.item_flags & MLX5_FLOW_LAYER_GENEVE) {
14677 : 0 : flow_dv_translate_item_geneve(key,
14678 : : wks.tunnel_item,
14679 : : wks.item_flags,
14680 : : key_type);
14681 [ # # ]: 0 : } else if (wks.item_flags & MLX5_FLOW_LAYER_GRE) {
14682 [ # # ]: 0 : if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE) {
14683 : 0 : flow_dv_translate_item_gre(key,
14684 : : wks.tunnel_item,
14685 : : wks.item_flags,
14686 : : key_type);
14687 [ # # ]: 0 : } else if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE_OPTION) {
14688 : 0 : flow_dv_translate_item_gre_option(key,
14689 : : wks.tunnel_item,
14690 : : wks.gre_item,
14691 : : wks.item_flags,
14692 : : key_type);
14693 [ # # ]: 0 : } else if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_NVGRE) {
14694 : 0 : flow_dv_translate_item_nvgre(key,
14695 : : wks.tunnel_item,
14696 : : wks.item_flags,
14697 : : key_type);
14698 : : } else {
14699 : : MLX5_ASSERT(false);
14700 : : }
14701 : : }
14702 : :
14703 [ # # ]: 0 : if (match_criteria)
14704 : 0 : *match_criteria = flow_dv_matcher_enable(key);
14705 [ # # ]: 0 : if (item_flags)
14706 : 0 : *item_flags = wks.item_flags;
14707 : 0 : exit:
14708 : 0 : mlx5_flow_pop_thread_workspace();
14709 : 0 : return ret;
14710 : : }
14711 : :
14712 : : /**
14713 : : * Fill the HW steering flow with DV spec.
14714 : : * This function assumes given flow is created from template API.
14715 : : *
14716 : : * @param[in] items
14717 : : * Pointer to the list of items.
14718 : : * @param[in] attr
14719 : : * Pointer to the flow attributes.
14720 : : * @param[in] key
14721 : : * Pointer to the flow matcher key.
14722 : : * @param[in] key_type
14723 : : * Key type.
14724 : : * @param[in, out] item_flags
14725 : : * Pointer to the flow item flags.
14726 : : * @param[out] error
14727 : : * Pointer to the error structure.
14728 : : *
14729 : : * @return
14730 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14731 : : */
14732 : : int
14733 : 0 : flow_dv_translate_items_hws(const struct rte_flow_item *items,
14734 : : struct mlx5_flow_attr *attr, void *key,
14735 : : uint32_t key_type, uint64_t *item_flags,
14736 : : uint8_t *match_criteria,
14737 : : struct rte_flow_error *error)
14738 : : {
14739 : 0 : return __flow_dv_translate_items_hws(items, attr, key, key_type, item_flags, match_criteria,
14740 : : false, error);
14741 : : }
14742 : :
14743 : : /**
14744 : : * Fill the SW steering flow with DV spec.
14745 : : *
14746 : : * @param[in] dev
14747 : : * Pointer to rte_eth_dev structure.
14748 : : * @param[in, out] dev_flow
14749 : : * Pointer to the sub flow.
14750 : : * @param[in] attr
14751 : : * Pointer to the flow attributes.
14752 : : * @param[in] items
14753 : : * Pointer to the list of items.
14754 : : * @param[in, out] matcher
14755 : : * Pointer to the flow matcher.
14756 : : * @param[out] error
14757 : : * Pointer to the error structure.
14758 : : *
14759 : : * @return
14760 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14761 : : */
14762 : : static int
14763 : 0 : flow_dv_translate_items_sws(struct rte_eth_dev *dev,
14764 : : struct mlx5_flow *dev_flow,
14765 : : const struct rte_flow_attr *attr,
14766 : : const struct rte_flow_item *items,
14767 : : struct mlx5_flow_dv_matcher *matcher,
14768 : : struct rte_flow_error *error)
14769 : : {
14770 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14771 : 0 : void *match_mask = matcher->mask.buf;
14772 : 0 : void *match_value = dev_flow->dv.value.buf;
14773 : 0 : struct mlx5_dv_matcher_workspace wks = {
14774 : 0 : .action_flags = dev_flow->act_flags,
14775 : : .item_flags = 0,
14776 : 0 : .external = dev_flow->external,
14777 : : .next_protocol = 0xff,
14778 : 0 : .group = dev_flow->dv.group,
14779 : : .attr = attr,
14780 : 0 : .rss_desc = &((struct mlx5_flow_workspace *)
14781 : : mlx5_flow_get_thread_workspace())->rss_desc,
14782 : : };
14783 : 0 : struct mlx5_dv_matcher_workspace wks_m = wks;
14784 : : int item_type;
14785 : : int ret = 0;
14786 : : int tunnel;
14787 : :
14788 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
14789 : 0 : if (!mlx5_flow_os_item_supported(items->type))
14790 : : return rte_flow_error_set(error, ENOTSUP,
14791 : : RTE_FLOW_ERROR_TYPE_ITEM,
14792 : : NULL, "item not supported");
14793 : 0 : tunnel = !!(wks.item_flags & MLX5_FLOW_LAYER_TUNNEL);
14794 : : item_type = items->type;
14795 [ # # # # : 0 : switch (item_type) {
# ]
14796 : 0 : case RTE_FLOW_ITEM_TYPE_CONNTRACK:
14797 : 0 : flow_dv_translate_item_aso_ct(dev, match_mask,
14798 : : match_value, items);
14799 : 0 : wks.last_item = MLX5_FLOW_LAYER_ASO_CT;
14800 : 0 : break;
14801 : 0 : case RTE_FLOW_ITEM_TYPE_FLEX:
14802 : 0 : flow_dv_translate_item_flex(dev, match_mask,
14803 : : match_value, items,
14804 : : dev_flow, tunnel != 0);
14805 [ # # ]: 0 : wks.last_item = tunnel ? MLX5_FLOW_ITEM_INNER_FLEX :
14806 : : MLX5_FLOW_ITEM_OUTER_FLEX;
14807 : 0 : break;
14808 : 0 : case RTE_FLOW_ITEM_TYPE_TX_QUEUE:
14809 : 0 : ret = flow_dv_translate_item_tx_queue(dev, match_value, items,
14810 : : MLX5_SET_MATCHER_SW_V);
14811 [ # # ]: 0 : if (ret)
14812 : 0 : return rte_flow_error_set(error, -ret,
14813 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14814 : : "invalid tx_queue item spec");
14815 : 0 : ret = flow_dv_translate_item_tx_queue(dev, match_mask, items,
14816 : : MLX5_SET_MATCHER_SW_M);
14817 [ # # ]: 0 : if (ret)
14818 : 0 : return rte_flow_error_set(error, -ret,
14819 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14820 : : "invalid tx_queue item mask");
14821 : : break;
14822 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_SQ:
14823 : 0 : flow_dv_translate_item_sq(match_value, items,
14824 : : MLX5_SET_MATCHER_SW_V);
14825 : 0 : flow_dv_translate_item_sq(match_mask, items,
14826 : : MLX5_SET_MATCHER_SW_M);
14827 : 0 : break;
14828 : 0 : default:
14829 : 0 : ret = flow_dv_translate_items(dev, items, &wks_m,
14830 : : match_mask, MLX5_SET_MATCHER_SW_M, error);
14831 [ # # ]: 0 : if (ret)
14832 : 0 : return ret;
14833 : 0 : ret = flow_dv_translate_items(dev, items, &wks,
14834 : : match_value, MLX5_SET_MATCHER_SW_V, error);
14835 [ # # ]: 0 : if (ret)
14836 : 0 : return ret;
14837 : : break;
14838 : : }
14839 : 0 : wks.item_flags |= wks.last_item;
14840 : : }
14841 : : /*
14842 : : * When E-Switch mode is enabled, we have two cases where we need to
14843 : : * set the source port manually.
14844 : : * The first one, is in case of NIC ingress steering rule, and the
14845 : : * second is E-Switch rule where no port_id item was found.
14846 : : * In both cases the source port is set according the current port
14847 : : * in use.
14848 : : */
14849 : 0 : if (!(wks.item_flags & MLX5_FLOW_ITEM_PORT_ID) &&
14850 [ # # ]: 0 : !(wks.item_flags & MLX5_FLOW_ITEM_REPRESENTED_PORT) &&
14851 : 0 : !(wks.item_flags & MLX5_FLOW_ITEM_PORT_REPRESENTOR) &&
14852 [ # # ]: 0 : priv->sh->esw_mode &&
14853 [ # # ]: 0 : !attr->egress &&
14854 [ # # ]: 0 : attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP) {
14855 [ # # ]: 0 : if (flow_dv_translate_item_port_id_all(dev, match_mask,
14856 : : match_value, NULL, attr))
14857 : 0 : return -rte_errno;
14858 : : }
14859 [ # # ]: 0 : if (wks.item_flags & MLX5_FLOW_ITEM_INTEGRITY) {
14860 : 0 : flow_dv_translate_item_integrity_post(match_mask,
14861 : : wks_m.integrity_items,
14862 : : wks_m.item_flags,
14863 : : MLX5_SET_MATCHER_SW_M);
14864 : 0 : flow_dv_translate_item_integrity_post(match_value,
14865 : : wks.integrity_items,
14866 : : wks.item_flags,
14867 : : MLX5_SET_MATCHER_SW_V);
14868 : : }
14869 [ # # ]: 0 : if (wks.item_flags & MLX5_FLOW_LAYER_VXLAN_GPE) {
14870 : 0 : flow_dv_translate_item_vxlan_gpe(match_mask,
14871 : : wks.tunnel_item,
14872 : : wks.item_flags,
14873 : : MLX5_SET_MATCHER_SW_M);
14874 : 0 : flow_dv_translate_item_vxlan_gpe(match_value,
14875 : : wks.tunnel_item,
14876 : : wks.item_flags,
14877 : : MLX5_SET_MATCHER_SW_V);
14878 [ # # ]: 0 : } else if (wks.item_flags & MLX5_FLOW_LAYER_GENEVE) {
14879 : 0 : flow_dv_translate_item_geneve(match_mask,
14880 : : wks.tunnel_item,
14881 : : wks.item_flags,
14882 : : MLX5_SET_MATCHER_SW_M);
14883 : 0 : flow_dv_translate_item_geneve(match_value,
14884 : : wks.tunnel_item,
14885 : : wks.item_flags,
14886 : : MLX5_SET_MATCHER_SW_V);
14887 [ # # ]: 0 : } else if (wks.item_flags & MLX5_FLOW_LAYER_GRE) {
14888 [ # # ]: 0 : if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE) {
14889 : 0 : flow_dv_translate_item_gre(match_mask,
14890 : : wks.tunnel_item,
14891 : : wks.item_flags,
14892 : : MLX5_SET_MATCHER_SW_M);
14893 : 0 : flow_dv_translate_item_gre(match_value,
14894 : : wks.tunnel_item,
14895 : : wks.item_flags,
14896 : : MLX5_SET_MATCHER_SW_V);
14897 [ # # ]: 0 : } else if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_NVGRE) {
14898 : 0 : flow_dv_translate_item_nvgre(match_mask,
14899 : : wks.tunnel_item,
14900 : : wks.item_flags,
14901 : : MLX5_SET_MATCHER_SW_M);
14902 : 0 : flow_dv_translate_item_nvgre(match_value,
14903 : : wks.tunnel_item,
14904 : : wks.item_flags,
14905 : : MLX5_SET_MATCHER_SW_V);
14906 [ # # ]: 0 : } else if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE_OPTION) {
14907 : 0 : flow_dv_translate_item_gre_option(match_mask,
14908 : : wks.tunnel_item,
14909 : : wks.gre_item,
14910 : : wks.item_flags,
14911 : : MLX5_SET_MATCHER_SW_M);
14912 : 0 : flow_dv_translate_item_gre_option(match_value,
14913 : : wks.tunnel_item,
14914 : : wks.gre_item,
14915 : : wks.item_flags,
14916 : : MLX5_SET_MATCHER_SW_V);
14917 : : } else {
14918 : : MLX5_ASSERT(false);
14919 : : }
14920 : : }
14921 : 0 : dev_flow->handle->vf_vlan.tag = wks.vlan_tag;
14922 : 0 : matcher->priority = wks.priority;
14923 : : #ifdef RTE_LIBRTE_MLX5_DEBUG
14924 : : MLX5_ASSERT(!flow_dv_check_valid_spec(match_mask, match_value));
14925 : : #endif
14926 : : /*
14927 : : * Layers may be already initialized from prefix flow if this dev_flow
14928 : : * is the suffix flow.
14929 : : */
14930 : 0 : dev_flow->handle->layers |= wks.item_flags;
14931 : : /*
14932 : : * Update geneve_tlv_option flag only it is set in workspace.
14933 : : * Avoid be overwritten by other sub mlx5_flows.
14934 : : */
14935 [ # # ]: 0 : if (wks.geneve_tlv_option)
14936 : 0 : dev_flow->flow->geneve_tlv_option += wks.geneve_tlv_option;
14937 : : return 0;
14938 : : }
14939 : :
14940 : : /**
14941 : : * Fill the flow with DV spec, lock free
14942 : : * (mutex should be acquired by caller).
14943 : : *
14944 : : * @param[in] dev
14945 : : * Pointer to rte_eth_dev structure.
14946 : : * @param[in, out] dev_flow
14947 : : * Pointer to the sub flow.
14948 : : * @param[in] attr
14949 : : * Pointer to the flow attributes.
14950 : : * @param[in] items
14951 : : * Pointer to the list of items.
14952 : : * @param[in] actions
14953 : : * Pointer to the list of actions.
14954 : : * @param[out] error
14955 : : * Pointer to the error structure.
14956 : : *
14957 : : * @return
14958 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14959 : : */
14960 : : static int
14961 : 0 : flow_dv_translate(struct rte_eth_dev *dev,
14962 : : struct mlx5_flow *dev_flow,
14963 : : const struct rte_flow_attr *attr,
14964 : : const struct rte_flow_item items[],
14965 : : const struct rte_flow_action actions[],
14966 : : struct rte_flow_error *error)
14967 : : {
14968 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14969 : 0 : struct mlx5_sh_config *dev_conf = &priv->sh->config;
14970 : 0 : struct rte_flow *flow = dev_flow->flow;
14971 : 0 : struct mlx5_flow_handle *handle = dev_flow->handle;
14972 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
14973 : : struct mlx5_flow_rss_desc *rss_desc;
14974 : : uint64_t action_flags = 0;
14975 : 0 : struct mlx5_flow_dv_matcher matcher = {
14976 : : .mask = {
14977 : : .size = sizeof(matcher.mask.buf),
14978 : : },
14979 : : };
14980 : : int actions_n = 0;
14981 : : bool actions_end = false;
14982 : : union {
14983 : : struct mlx5_flow_dv_modify_hdr_resource res;
14984 : : uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
14985 : : sizeof(struct mlx5_modification_cmd) *
14986 : : (MLX5_MAX_MODIFY_NUM + 1)];
14987 : : } mhdr_dummy;
14988 : : struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
14989 : : const struct rte_flow_action_count *count = NULL;
14990 : : const struct rte_flow_action_age *non_shared_age = NULL;
14991 : 0 : union flow_dv_attr flow_attr = { .attr = 0 };
14992 : : uint32_t tag_be;
14993 : : union mlx5_flow_tbl_key tbl_key;
14994 : : uint32_t modify_action_position = UINT32_MAX;
14995 : 0 : struct rte_vlan_hdr vlan = { 0 };
14996 : : struct mlx5_flow_dv_dest_array_resource mdest_res;
14997 : : struct mlx5_flow_dv_sample_resource sample_res;
14998 : 0 : void *sample_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
14999 : : const struct rte_flow_action_sample *sample = NULL;
15000 : : struct mlx5_flow_sub_actions_list *sample_act;
15001 : : uint32_t sample_act_pos = UINT32_MAX;
15002 : : uint32_t age_act_pos = UINT32_MAX;
15003 : : uint32_t ipv6_tc_off = 0;
15004 : 0 : uint32_t num_of_dest = 0;
15005 : : int tmp_actions_n = 0;
15006 : : uint32_t table;
15007 : : int ret = 0;
15008 : : const struct mlx5_flow_tunnel *tunnel = NULL;
15009 : 0 : struct flow_grp_info grp_info = {
15010 : 0 : .external = !!dev_flow->external,
15011 : 0 : .transfer = !!attr->transfer,
15012 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
15013 : 0 : .skip_scale = dev_flow->skip_scale &
15014 : : (1 << MLX5_SCALE_FLOW_GROUP_BIT),
15015 : : .std_tbl_fix = true,
15016 : : };
15017 : :
15018 [ # # ]: 0 : if (!wks)
15019 : 0 : return rte_flow_error_set(error, ENOMEM,
15020 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15021 : : NULL,
15022 : : "failed to push flow workspace");
15023 [ # # ]: 0 : rss_desc = &wks->rss_desc;
15024 : : memset(&mdest_res, 0, sizeof(struct mlx5_flow_dv_dest_array_resource));
15025 : : memset(&sample_res, 0, sizeof(struct mlx5_flow_dv_sample_resource));
15026 [ # # ]: 0 : mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
15027 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
15028 : : /* update normal path action resource into last index of array */
15029 : : sample_act = &mdest_res.sample_act[MLX5_MAX_DEST_NUM - 1];
15030 [ # # ]: 0 : if (is_tunnel_offload_active(dev)) {
15031 [ # # ]: 0 : if (dev_flow->tunnel) {
15032 [ # # ]: 0 : RTE_VERIFY(dev_flow->tof_type ==
15033 : : MLX5_TUNNEL_OFFLOAD_MISS_RULE);
15034 : : tunnel = dev_flow->tunnel;
15035 : : } else {
15036 : 0 : tunnel = mlx5_get_tof(items, actions,
15037 : : &dev_flow->tof_type);
15038 : 0 : dev_flow->tunnel = tunnel;
15039 : : }
15040 [ # # ]: 0 : grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
15041 : : (dev, attr, tunnel, dev_flow->tof_type);
15042 : : }
15043 : 0 : mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
15044 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
15045 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel, attr->group, &table,
15046 : : &grp_info, error);
15047 [ # # ]: 0 : if (ret)
15048 : : return ret;
15049 : 0 : dev_flow->dv.group = table;
15050 [ # # ]: 0 : if (attr->transfer)
15051 : 0 : mhdr_res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
15052 : : /* number of actions must be set to 0 in case of dirty stack. */
15053 : 0 : mhdr_res->actions_num = 0;
15054 [ # # ]: 0 : if (is_flow_tunnel_match_rule(dev_flow->tof_type)) {
15055 : : /*
15056 : : * do not add decap action if match rule drops packet
15057 : : * HW rejects rules with decap & drop
15058 : : *
15059 : : * if tunnel match rule was inserted before matching tunnel set
15060 : : * rule flow table used in the match rule must be registered.
15061 : : * current implementation handles that in the
15062 : : * flow_dv_match_register() at the function end.
15063 : : */
15064 : : bool add_decap = true;
15065 : : const struct rte_flow_action *ptr = actions;
15066 : :
15067 [ # # ]: 0 : for (; ptr->type != RTE_FLOW_ACTION_TYPE_END; ptr++) {
15068 [ # # ]: 0 : if (ptr->type == RTE_FLOW_ACTION_TYPE_DROP) {
15069 : : add_decap = false;
15070 : : break;
15071 : : }
15072 : : }
15073 [ # # ]: 0 : if (add_decap) {
15074 [ # # ]: 0 : if (flow_dv_create_action_l2_decap(dev, dev_flow,
15075 : 0 : attr->transfer,
15076 : : error))
15077 : 0 : return -rte_errno;
15078 : 0 : dev_flow->dv.actions[actions_n++] =
15079 : 0 : dev_flow->dv.encap_decap->action;
15080 : : action_flags |= MLX5_FLOW_ACTION_DECAP;
15081 : : }
15082 : : }
15083 [ # # ]: 0 : for (; !actions_end ; actions++) {
15084 : : const struct rte_flow_action_queue *queue;
15085 : : const struct rte_flow_action_rss *rss;
15086 : : const struct rte_flow_action *action = actions;
15087 : : const uint8_t *rss_key;
15088 : : struct mlx5_flow_tbl_resource *tbl;
15089 : : struct mlx5_aso_age_action *age_act;
15090 : : struct mlx5_flow_counter *cnt_act;
15091 : 0 : uint32_t port_id = 0;
15092 : : struct mlx5_flow_dv_port_id_action_resource port_id_resource;
15093 : 0 : int action_type = actions->type;
15094 : : const struct rte_flow_action *found_action = NULL;
15095 : : uint32_t jump_group = 0;
15096 : : uint32_t owner_idx;
15097 : : struct mlx5_aso_ct_action *ct;
15098 : :
15099 : : if (!mlx5_flow_os_action_supported(action_type))
15100 : 0 : return rte_flow_error_set(error, ENOTSUP,
15101 : : RTE_FLOW_ERROR_TYPE_ACTION,
15102 : : actions,
15103 : : "action not supported");
15104 [ # # # # : 0 : switch (action_type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
15105 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
15106 : 0 : action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
15107 : 0 : break;
15108 : : case RTE_FLOW_ACTION_TYPE_VOID:
15109 : : break;
15110 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
15111 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
15112 [ # # ]: 0 : if (flow_dv_translate_action_port_id(dev, action,
15113 : : &port_id, error))
15114 : 0 : return -rte_errno;
15115 : 0 : port_id_resource.port_id = port_id;
15116 : : MLX5_ASSERT(!handle->rix_port_id_action);
15117 [ # # ]: 0 : if (flow_dv_port_id_action_resource_register
15118 : : (dev, &port_id_resource, dev_flow, error))
15119 : 0 : return -rte_errno;
15120 : 0 : dev_flow->dv.actions[actions_n++] =
15121 : 0 : dev_flow->dv.port_id_action->action;
15122 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_ID;
15123 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_PORT_ID;
15124 : 0 : sample_act->action_flags |= MLX5_FLOW_ACTION_PORT_ID;
15125 : 0 : num_of_dest++;
15126 : 0 : break;
15127 : 0 : case RTE_FLOW_ACTION_TYPE_FLAG:
15128 : 0 : action_flags |= MLX5_FLOW_ACTION_FLAG;
15129 : 0 : wks->mark = 1;
15130 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
15131 : 0 : struct rte_flow_action_mark mark = {
15132 : : .id = MLX5_FLOW_MARK_DEFAULT,
15133 : : };
15134 : :
15135 [ # # ]: 0 : if (flow_dv_convert_action_mark(dev, &mark,
15136 : : mhdr_res,
15137 : : error))
15138 : 0 : return -rte_errno;
15139 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
15140 : 0 : break;
15141 : : }
15142 : : tag_be = mlx5_flow_mark_set(MLX5_FLOW_MARK_DEFAULT);
15143 : : /*
15144 : : * Only one FLAG or MARK is supported per device flow
15145 : : * right now. So the pointer to the tag resource must be
15146 : : * zero before the register process.
15147 : : */
15148 : : MLX5_ASSERT(!handle->dvh.rix_tag);
15149 [ # # ]: 0 : if (flow_dv_tag_resource_register(dev, tag_be,
15150 : : dev_flow, error))
15151 : 0 : return -rte_errno;
15152 : : MLX5_ASSERT(dev_flow->dv.tag_resource);
15153 : 0 : dev_flow->dv.actions[actions_n++] =
15154 : 0 : dev_flow->dv.tag_resource->action;
15155 : 0 : break;
15156 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
15157 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK;
15158 : 0 : wks->mark = 1;
15159 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
15160 : 0 : const struct rte_flow_action_mark *mark =
15161 : : (const struct rte_flow_action_mark *)
15162 : : actions->conf;
15163 : :
15164 [ # # ]: 0 : if (flow_dv_convert_action_mark(dev, mark,
15165 : : mhdr_res,
15166 : : error))
15167 : 0 : return -rte_errno;
15168 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
15169 : 0 : break;
15170 : : }
15171 : : /* Fall-through */
15172 : : case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
15173 : : /* Legacy (non-extensive) MARK action. */
15174 : : tag_be = mlx5_flow_mark_set
15175 : : (((const struct rte_flow_action_mark *)
15176 [ # # ]: 0 : (actions->conf))->id);
15177 : : MLX5_ASSERT(!handle->dvh.rix_tag);
15178 [ # # ]: 0 : if (flow_dv_tag_resource_register(dev, tag_be,
15179 : : dev_flow, error))
15180 : 0 : return -rte_errno;
15181 : : MLX5_ASSERT(dev_flow->dv.tag_resource);
15182 : 0 : dev_flow->dv.actions[actions_n++] =
15183 : 0 : dev_flow->dv.tag_resource->action;
15184 : 0 : break;
15185 : 0 : case RTE_FLOW_ACTION_TYPE_SET_META:
15186 [ # # ]: 0 : if (flow_dv_convert_action_set_meta
15187 : : (dev, mhdr_res, attr,
15188 : : (const struct rte_flow_action_set_meta *)
15189 : 0 : actions->conf, error))
15190 : 0 : return -rte_errno;
15191 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_META;
15192 : 0 : break;
15193 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TAG:
15194 [ # # ]: 0 : if (flow_dv_convert_action_set_tag
15195 : : (dev, mhdr_res,
15196 : : (const struct rte_flow_action_set_tag *)
15197 : 0 : actions->conf, error))
15198 : 0 : return -rte_errno;
15199 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
15200 : 0 : break;
15201 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
15202 : 0 : action_flags |= MLX5_FLOW_ACTION_DROP;
15203 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_DROP;
15204 : 0 : break;
15205 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
15206 : 0 : queue = actions->conf;
15207 : 0 : rss_desc->queue_num = 1;
15208 : 0 : rss_desc->queue[0] = queue->index;
15209 : 0 : action_flags |= MLX5_FLOW_ACTION_QUEUE;
15210 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
15211 : 0 : sample_act->action_flags |= MLX5_FLOW_ACTION_QUEUE;
15212 : 0 : num_of_dest++;
15213 : 0 : break;
15214 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
15215 : 0 : rss = actions->conf;
15216 : 0 : rss_desc->symmetric_hash_function =
15217 : 0 : MLX5_RSS_IS_SYMM(rss->func);
15218 : 0 : memcpy(rss_desc->queue, rss->queue,
15219 [ # # ]: 0 : rss->queue_num * sizeof(uint16_t));
15220 : 0 : rss_desc->queue_num = rss->queue_num;
15221 : : /* NULL RSS key indicates default RSS key. */
15222 [ # # ]: 0 : rss_key = !rss->key ? rss_hash_default_key : rss->key;
15223 [ # # ]: 0 : memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
15224 : : /*
15225 : : * rss->level and rss.types should be set in advance
15226 : : * when expanding items for RSS.
15227 : : */
15228 : 0 : action_flags |= MLX5_FLOW_ACTION_RSS;
15229 : 0 : dev_flow->handle->fate_action = rss_desc->shared_rss ?
15230 [ # # ]: 0 : MLX5_FLOW_FATE_SHARED_RSS :
15231 : : MLX5_FLOW_FATE_QUEUE;
15232 : 0 : break;
15233 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
15234 : 0 : owner_idx = (uint32_t)(uintptr_t)action->conf;
15235 : 0 : age_act = flow_aso_age_get_by_idx(dev, owner_idx);
15236 [ # # ]: 0 : if (flow->age == 0) {
15237 : 0 : flow->age = owner_idx;
15238 : 0 : rte_atomic_fetch_add_explicit(&age_act->refcnt, 1,
15239 : : rte_memory_order_relaxed);
15240 : : }
15241 : 0 : age_act_pos = actions_n++;
15242 : 0 : action_flags |= MLX5_FLOW_ACTION_AGE;
15243 : 0 : break;
15244 : 0 : case RTE_FLOW_ACTION_TYPE_SEND_TO_KERNEL:
15245 : 0 : dev_flow->dv.actions[actions_n] =
15246 : 0 : flow_dv_translate_action_send_to_kernel(dev, attr,
15247 : : error);
15248 [ # # ]: 0 : if (!dev_flow->dv.actions[actions_n])
15249 : 0 : return -rte_errno;
15250 : 0 : actions_n++;
15251 : 0 : action_flags |= MLX5_FLOW_ACTION_SEND_TO_KERNEL;
15252 : 0 : dev_flow->handle->fate_action =
15253 : : MLX5_FLOW_FATE_SEND_TO_KERNEL;
15254 : 0 : break;
15255 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
15256 : 0 : non_shared_age = action->conf;
15257 : 0 : age_act_pos = actions_n++;
15258 : 0 : action_flags |= MLX5_FLOW_ACTION_AGE;
15259 : 0 : break;
15260 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
15261 [ # # ]: 0 : owner_idx = (uint32_t)(uintptr_t)action->conf;
15262 : : cnt_act = flow_dv_counter_get_by_idx(dev, owner_idx,
15263 : : NULL);
15264 : : MLX5_ASSERT(cnt_act != NULL);
15265 : : /**
15266 : : * When creating meter drop flow in drop table, the
15267 : : * counter should not overwrite the rte flow counter.
15268 : : */
15269 [ # # ]: 0 : if (attr->group == MLX5_FLOW_TABLE_LEVEL_METER &&
15270 [ # # ]: 0 : dev_flow->dv.table_id == MLX5_MTR_TABLE_ID_DROP) {
15271 : 0 : dev_flow->dv.actions[actions_n++] =
15272 : 0 : cnt_act->action;
15273 : : } else {
15274 [ # # ]: 0 : if (flow->counter == 0) {
15275 : 0 : flow->counter = owner_idx;
15276 : 0 : rte_atomic_fetch_add_explicit
15277 : : (&cnt_act->shared_info.refcnt,
15278 : : 1, rte_memory_order_relaxed);
15279 : : }
15280 : : /* Save information first, will apply later. */
15281 : 0 : action_flags |= MLX5_FLOW_ACTION_COUNT;
15282 : : }
15283 : : break;
15284 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
15285 [ # # ]: 0 : if (!priv->sh->cdev->config.devx) {
15286 : 0 : return rte_flow_error_set
15287 : : (error, ENOTSUP,
15288 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15289 : : NULL,
15290 : : "count action not supported");
15291 : : }
15292 : : /* Save information first, will apply later. */
15293 : 0 : count = action->conf;
15294 : 0 : action_flags |= MLX5_FLOW_ACTION_COUNT;
15295 : 0 : break;
15296 : 0 : case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
15297 : 0 : dev_flow->dv.actions[actions_n++] =
15298 : 0 : priv->sh->pop_vlan_action;
15299 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
15300 : 0 : break;
15301 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
15302 [ # # ]: 0 : if (!(action_flags &
15303 : : MLX5_FLOW_ACTION_OF_SET_VLAN_VID))
15304 : 0 : flow_dev_get_vlan_info_from_items(items, &vlan);
15305 [ # # ]: 0 : vlan.eth_proto = rte_be_to_cpu_16
15306 : : ((((const struct rte_flow_action_of_push_vlan *)
15307 : : actions->conf)->ethertype));
15308 : 0 : found_action = mlx5_flow_find_action
15309 : : (actions + 1,
15310 : : RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID);
15311 [ # # ]: 0 : if (found_action)
15312 : 0 : mlx5_update_vlan_vid_pcp(found_action, &vlan);
15313 : 0 : found_action = mlx5_flow_find_action
15314 : : (actions + 1,
15315 : : RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP);
15316 [ # # ]: 0 : if (found_action)
15317 : 0 : mlx5_update_vlan_vid_pcp(found_action, &vlan);
15318 [ # # ]: 0 : if (flow_dv_create_action_push_vlan
15319 : : (dev, attr, &vlan, dev_flow, error))
15320 : 0 : return -rte_errno;
15321 : 0 : dev_flow->dv.actions[actions_n++] =
15322 : 0 : dev_flow->dv.push_vlan_res->action;
15323 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
15324 : 0 : break;
15325 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
15326 : : /* of_vlan_push action handled this action */
15327 : : MLX5_ASSERT(action_flags &
15328 : : MLX5_FLOW_ACTION_OF_PUSH_VLAN);
15329 : : break;
15330 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
15331 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
15332 : : break;
15333 : 0 : flow_dev_get_vlan_info_from_items(items, &vlan);
15334 : 0 : mlx5_update_vlan_vid_pcp(actions, &vlan);
15335 : : /* If no VLAN push - this is a modify header action */
15336 [ # # ]: 0 : if (flow_dv_convert_action_modify_vlan_vid
15337 : : (mhdr_res, actions, error))
15338 : 0 : return -rte_errno;
15339 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
15340 : 0 : break;
15341 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
15342 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
15343 [ # # ]: 0 : if (flow_dv_create_action_l2_encap(dev, actions,
15344 : : dev_flow,
15345 : 0 : attr->transfer,
15346 : : error))
15347 : 0 : return -rte_errno;
15348 : 0 : dev_flow->dv.actions[actions_n++] =
15349 : 0 : dev_flow->dv.encap_decap->action;
15350 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
15351 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
15352 : 0 : sample_act->action_flags |=
15353 : : MLX5_FLOW_ACTION_ENCAP;
15354 : : break;
15355 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
15356 : : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
15357 [ # # ]: 0 : if (flow_dv_create_action_l2_decap(dev, dev_flow,
15358 : 0 : attr->transfer,
15359 : : error))
15360 : 0 : return -rte_errno;
15361 : 0 : dev_flow->dv.actions[actions_n++] =
15362 : 0 : dev_flow->dv.encap_decap->action;
15363 : 0 : action_flags |= MLX5_FLOW_ACTION_DECAP;
15364 : 0 : break;
15365 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
15366 : : /* Handle encap with preceding decap. */
15367 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_DECAP) {
15368 [ # # ]: 0 : if (flow_dv_create_action_raw_encap
15369 : : (dev, actions, dev_flow, attr, error))
15370 : 0 : return -rte_errno;
15371 : 0 : dev_flow->dv.actions[actions_n++] =
15372 : 0 : dev_flow->dv.encap_decap->action;
15373 : : } else {
15374 : : /* Handle encap without preceding decap. */
15375 [ # # ]: 0 : if (flow_dv_create_action_l2_encap
15376 : 0 : (dev, actions, dev_flow, attr->transfer,
15377 : : error))
15378 : 0 : return -rte_errno;
15379 : 0 : dev_flow->dv.actions[actions_n++] =
15380 : 0 : dev_flow->dv.encap_decap->action;
15381 : : }
15382 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
15383 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
15384 : 0 : sample_act->action_flags |=
15385 : : MLX5_FLOW_ACTION_ENCAP;
15386 : : break;
15387 : : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
15388 [ # # ]: 0 : while ((++action)->type == RTE_FLOW_ACTION_TYPE_VOID)
15389 : : ;
15390 [ # # ]: 0 : if (action->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
15391 [ # # ]: 0 : if (flow_dv_create_action_l2_decap
15392 : 0 : (dev, dev_flow, attr->transfer, error))
15393 : 0 : return -rte_errno;
15394 : 0 : dev_flow->dv.actions[actions_n++] =
15395 : 0 : dev_flow->dv.encap_decap->action;
15396 : : }
15397 : : /* If decap is followed by encap, handle it at encap. */
15398 : 0 : action_flags |= MLX5_FLOW_ACTION_DECAP;
15399 : 0 : break;
15400 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_JUMP:
15401 : 0 : dev_flow->dv.actions[actions_n++] =
15402 : 0 : (void *)(uintptr_t)action->conf;
15403 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP;
15404 : 0 : break;
15405 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
15406 : 0 : jump_group = ((const struct rte_flow_action_jump *)
15407 : 0 : action->conf)->group;
15408 : 0 : grp_info.std_tbl_fix = 0;
15409 [ # # ]: 0 : if (dev_flow->skip_scale &
15410 : : (1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT))
15411 : 0 : grp_info.skip_scale = 1;
15412 : : else
15413 : 0 : grp_info.skip_scale = 0;
15414 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel,
15415 : : jump_group,
15416 : : &table,
15417 : : &grp_info, error);
15418 [ # # ]: 0 : if (ret)
15419 : 0 : return ret;
15420 : 0 : tbl = flow_dv_tbl_resource_get(dev, table, attr->egress,
15421 : 0 : attr->transfer,
15422 : 0 : !!dev_flow->external,
15423 : : tunnel, jump_group, 0,
15424 : : 0, error);
15425 [ # # ]: 0 : if (!tbl)
15426 : 0 : return rte_flow_error_set
15427 : 0 : (error, errno,
15428 : : RTE_FLOW_ERROR_TYPE_ACTION,
15429 : : NULL,
15430 : : "cannot create jump action.");
15431 : : if (flow_dv_jump_tbl_resource_register
15432 : : (dev, tbl, dev_flow, error)) {
15433 : : flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
15434 : : return rte_flow_error_set
15435 : : (error, errno,
15436 : : RTE_FLOW_ERROR_TYPE_ACTION,
15437 : : NULL,
15438 : : "cannot create jump action.");
15439 : : }
15440 : 0 : dev_flow->dv.actions[actions_n++] =
15441 : 0 : dev_flow->dv.jump->action;
15442 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP;
15443 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_JUMP;
15444 : 0 : sample_act->action_flags |= MLX5_FLOW_ACTION_JUMP;
15445 : 0 : num_of_dest++;
15446 : 0 : break;
15447 : 0 : case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
15448 : : case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
15449 [ # # ]: 0 : if (flow_dv_convert_action_modify_mac
15450 : : (mhdr_res, actions, error))
15451 : 0 : return -rte_errno;
15452 : 0 : action_flags |= actions->type ==
15453 : : RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
15454 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_MAC_SRC :
15455 : : MLX5_FLOW_ACTION_SET_MAC_DST;
15456 : 0 : break;
15457 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
15458 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
15459 [ # # ]: 0 : if (flow_dv_convert_action_modify_ipv4
15460 : : (mhdr_res, actions, error))
15461 : 0 : return -rte_errno;
15462 : 0 : action_flags |= actions->type ==
15463 : : RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
15464 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_IPV4_SRC :
15465 : : MLX5_FLOW_ACTION_SET_IPV4_DST;
15466 : 0 : break;
15467 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
15468 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
15469 [ # # ]: 0 : if (flow_dv_convert_action_modify_ipv6
15470 : : (mhdr_res, actions, error))
15471 : 0 : return -rte_errno;
15472 : 0 : action_flags |= actions->type ==
15473 : : RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
15474 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_IPV6_SRC :
15475 : : MLX5_FLOW_ACTION_SET_IPV6_DST;
15476 : 0 : break;
15477 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
15478 : : case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
15479 [ # # ]: 0 : if (flow_dv_convert_action_modify_tp
15480 : : (mhdr_res, actions, items,
15481 : 0 : &flow_attr, dev_flow, !!(action_flags &
15482 : : MLX5_FLOW_ACTION_DECAP), error))
15483 : 0 : return -rte_errno;
15484 : 0 : action_flags |= actions->type ==
15485 : : RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
15486 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_TP_SRC :
15487 : : MLX5_FLOW_ACTION_SET_TP_DST;
15488 : 0 : break;
15489 : 0 : case RTE_FLOW_ACTION_TYPE_DEC_TTL:
15490 [ # # ]: 0 : if (flow_dv_convert_action_modify_dec_ttl
15491 : : (mhdr_res, items, &flow_attr, dev_flow,
15492 : 0 : !!(action_flags &
15493 : : MLX5_FLOW_ACTION_DECAP), error))
15494 : 0 : return -rte_errno;
15495 : 0 : action_flags |= MLX5_FLOW_ACTION_DEC_TTL;
15496 : 0 : break;
15497 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TTL:
15498 [ # # ]: 0 : if (flow_dv_convert_action_modify_ttl
15499 : : (mhdr_res, actions, items, &flow_attr,
15500 : 0 : dev_flow, !!(action_flags &
15501 : : MLX5_FLOW_ACTION_DECAP), error))
15502 : 0 : return -rte_errno;
15503 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TTL;
15504 : 0 : break;
15505 : 0 : case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
15506 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
15507 [ # # ]: 0 : if (flow_dv_convert_action_modify_tcp_seq
15508 : : (mhdr_res, actions, error))
15509 : 0 : return -rte_errno;
15510 : 0 : action_flags |= actions->type ==
15511 : : RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
15512 [ # # ]: 0 : MLX5_FLOW_ACTION_INC_TCP_SEQ :
15513 : : MLX5_FLOW_ACTION_DEC_TCP_SEQ;
15514 : 0 : break;
15515 : :
15516 : 0 : case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
15517 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
15518 [ # # ]: 0 : if (flow_dv_convert_action_modify_tcp_ack
15519 : : (mhdr_res, actions, error))
15520 : 0 : return -rte_errno;
15521 : 0 : action_flags |= actions->type ==
15522 : : RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
15523 [ # # ]: 0 : MLX5_FLOW_ACTION_INC_TCP_ACK :
15524 : : MLX5_FLOW_ACTION_DEC_TCP_ACK;
15525 : 0 : break;
15526 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
15527 [ # # ]: 0 : if (flow_dv_convert_action_set_reg
15528 : : (mhdr_res, actions, error))
15529 : 0 : return -rte_errno;
15530 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
15531 : 0 : break;
15532 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
15533 [ # # ]: 0 : if (flow_dv_convert_action_copy_mreg
15534 : : (dev, mhdr_res, actions, error))
15535 : 0 : return -rte_errno;
15536 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
15537 : 0 : break;
15538 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
15539 : 0 : action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
15540 : 0 : dev_flow->handle->fate_action =
15541 : : MLX5_FLOW_FATE_DEFAULT_MISS;
15542 : 0 : break;
15543 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
15544 [ # # ]: 0 : if (!wks->fm)
15545 : 0 : return rte_flow_error_set(error, rte_errno,
15546 : : RTE_FLOW_ERROR_TYPE_ACTION,
15547 : : NULL, "Failed to get meter in flow.");
15548 : : /* Set the meter action. */
15549 : 0 : dev_flow->dv.actions[actions_n++] =
15550 : 0 : wks->fm->meter_action_g;
15551 : 0 : action_flags |= MLX5_FLOW_ACTION_METER;
15552 : 0 : break;
15553 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
15554 [ # # ]: 0 : if (flow_dv_convert_action_modify_ipv4_dscp(mhdr_res,
15555 : : actions, error))
15556 : 0 : return -rte_errno;
15557 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
15558 : 0 : break;
15559 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
15560 [ # # ]: 0 : if (mlx5_dv_modify_ipv6_traffic_class_supported(priv))
15561 : : ipv6_tc_off = MLX5_IPV6_HDR_DSCP_SHIFT;
15562 : : else
15563 : : ipv6_tc_off = 0;
15564 [ # # ]: 0 : if (flow_dv_convert_action_modify_ipv6_dscp(mhdr_res,
15565 : : actions, ipv6_tc_off, error))
15566 : 0 : return -rte_errno;
15567 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
15568 : 0 : break;
15569 : 0 : case RTE_FLOW_ACTION_TYPE_SAMPLE:
15570 : 0 : sample_act_pos = actions_n;
15571 : 0 : sample = (const struct rte_flow_action_sample *)
15572 : : action->conf;
15573 : 0 : actions_n++;
15574 : 0 : action_flags |= MLX5_FLOW_ACTION_SAMPLE;
15575 : : /* put encap action into group if work with port id */
15576 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_ENCAP) &&
15577 : : (action_flags & MLX5_FLOW_ACTION_PORT_ID))
15578 : 0 : sample_act->action_flags |=
15579 : : MLX5_FLOW_ACTION_ENCAP;
15580 : : break;
15581 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
15582 [ # # ]: 0 : if (flow_dv_convert_action_modify_field
15583 : : (dev, mhdr_res, actions, attr, error))
15584 : 0 : return -rte_errno;
15585 : 0 : action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
15586 : 0 : break;
15587 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
15588 : 0 : owner_idx = (uint32_t)(uintptr_t)action->conf;
15589 : 0 : ct = flow_aso_ct_get_by_idx(dev, owner_idx);
15590 [ # # ]: 0 : if (!ct)
15591 : 0 : return rte_flow_error_set(error, EINVAL,
15592 : : RTE_FLOW_ERROR_TYPE_ACTION,
15593 : : NULL,
15594 : : "Failed to get CT object.");
15595 [ # # ]: 0 : if (mlx5_aso_ct_available(priv->sh, MLX5_HW_INV_QUEUE, ct))
15596 : 0 : return rte_flow_error_set(error, rte_errno,
15597 : : RTE_FLOW_ERROR_TYPE_ACTION,
15598 : : NULL,
15599 : : "CT is unavailable.");
15600 [ # # ]: 0 : if (ct->is_original)
15601 : 0 : dev_flow->dv.actions[actions_n] =
15602 : 0 : ct->dr_action_orig;
15603 : : else
15604 : 0 : dev_flow->dv.actions[actions_n] =
15605 : 0 : ct->dr_action_rply;
15606 [ # # ]: 0 : if (flow->ct == 0) {
15607 : 0 : flow->indirect_type =
15608 : : MLX5_INDIRECT_ACTION_TYPE_CT;
15609 : 0 : flow->ct = owner_idx;
15610 : 0 : rte_atomic_fetch_add_explicit(&ct->refcnt, 1,
15611 : : rte_memory_order_relaxed);
15612 : : }
15613 : 0 : actions_n++;
15614 : 0 : action_flags |= MLX5_FLOW_ACTION_CT;
15615 : 0 : break;
15616 : 0 : case RTE_FLOW_ACTION_TYPE_END:
15617 : : actions_end = true;
15618 [ # # ]: 0 : if (mhdr_res->actions_num) {
15619 : : /* create modify action if needed. */
15620 [ # # ]: 0 : if (flow_dv_modify_hdr_resource_register
15621 : : (dev, mhdr_res, dev_flow, error))
15622 : 0 : return -rte_errno;
15623 : 0 : dev_flow->dv.actions[modify_action_position] =
15624 : 0 : handle->dvh.modify_hdr->action;
15625 : : }
15626 : : /*
15627 : : * Handle AGE and COUNT action by single HW counter
15628 : : * when they are not shared.
15629 : : */
15630 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_AGE) {
15631 [ # # # # ]: 0 : if ((non_shared_age && count) ||
15632 [ # # ]: 0 : !flow_hit_aso_supported(priv, !dev_flow->dv.group)) {
15633 : : /* Creates age by counters. */
15634 : 0 : cnt_act = flow_dv_prepare_counter
15635 : : (dev, dev_flow,
15636 : : flow, count,
15637 : : non_shared_age,
15638 : : error);
15639 [ # # ]: 0 : if (!cnt_act)
15640 : 0 : return -rte_errno;
15641 : 0 : dev_flow->dv.actions[age_act_pos] =
15642 : 0 : cnt_act->action;
15643 : 0 : break;
15644 : : }
15645 [ # # # # ]: 0 : if (!flow->age && non_shared_age) {
15646 : 0 : flow->age = flow_dv_aso_age_alloc
15647 : : (dev, error);
15648 [ # # ]: 0 : if (!flow->age)
15649 : 0 : return -rte_errno;
15650 : 0 : flow_dv_aso_age_params_init
15651 : : (dev, flow->age,
15652 : 0 : non_shared_age->context ?
15653 : : non_shared_age->context :
15654 : 0 : (void *)(uintptr_t)
15655 : 0 : (dev_flow->flow_idx),
15656 [ # # ]: 0 : non_shared_age->timeout);
15657 : : }
15658 : 0 : age_act = flow_aso_age_get_by_idx(dev,
15659 : : flow->age);
15660 : 0 : dev_flow->dv.actions[age_act_pos] =
15661 : 0 : age_act->dr_action;
15662 : : }
15663 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_COUNT) {
15664 : : /*
15665 : : * Create one count action, to be used
15666 : : * by all sub-flows.
15667 : : */
15668 : 0 : cnt_act = flow_dv_prepare_counter(dev, dev_flow,
15669 : : flow, count,
15670 : : NULL, error);
15671 [ # # ]: 0 : if (!cnt_act)
15672 : 0 : return -rte_errno;
15673 : 0 : dev_flow->dv.actions[actions_n++] =
15674 : 0 : cnt_act->action;
15675 : : }
15676 : : default:
15677 : : break;
15678 : : }
15679 [ # # # # ]: 0 : if (mhdr_res->actions_num &&
15680 : : modify_action_position == UINT32_MAX)
15681 : 0 : modify_action_position = actions_n++;
15682 : : }
15683 : 0 : dev_flow->act_flags = action_flags;
15684 : 0 : ret = flow_dv_translate_items_sws(dev, dev_flow, attr, items, &matcher,
15685 : : error);
15686 [ # # ]: 0 : if (ret)
15687 : 0 : return -rte_errno;
15688 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_RSS) {
15689 : 0 : dev_flow->symmetric_hash_function = rss_desc->symmetric_hash_function;
15690 : 0 : flow_dv_hashfields_set(dev_flow->handle->layers,
15691 : : rss_desc,
15692 : : &dev_flow->hash_fields);
15693 : : }
15694 : : /* If has RSS action in the sample action, the Sample/Mirror resource
15695 : : * should be registered after the hash filed be update.
15696 : : */
15697 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE) {
15698 : 0 : ret = flow_dv_translate_action_sample(dev,
15699 : : sample,
15700 : : dev_flow, attr,
15701 : : &num_of_dest,
15702 : : sample_actions,
15703 : : &sample_res,
15704 : : error);
15705 [ # # ]: 0 : if (ret < 0)
15706 : : return ret;
15707 : 0 : ret = flow_dv_create_action_sample(dev,
15708 : : dev_flow,
15709 : : num_of_dest,
15710 : : &sample_res,
15711 : : &mdest_res,
15712 : : sample_actions,
15713 : : action_flags,
15714 : : error);
15715 [ # # ]: 0 : if (ret < 0)
15716 : 0 : return rte_flow_error_set
15717 : : (error, rte_errno,
15718 : : RTE_FLOW_ERROR_TYPE_ACTION,
15719 : : NULL,
15720 : : "cannot create sample action");
15721 [ # # ]: 0 : if (num_of_dest > 1) {
15722 : 0 : dev_flow->dv.actions[sample_act_pos] =
15723 : 0 : dev_flow->dv.dest_array_res->action;
15724 : : } else {
15725 : 0 : dev_flow->dv.actions[sample_act_pos] =
15726 : 0 : dev_flow->dv.sample_res->verbs_action;
15727 : : }
15728 : : }
15729 : : /*
15730 : : * For multiple destination (sample action with ratio=1), the encap
15731 : : * action and port id action will be combined into group action.
15732 : : * So need remove the original these actions in the flow and only
15733 : : * use the sample action instead of.
15734 : : */
15735 [ # # ]: 0 : if (num_of_dest > 1 &&
15736 [ # # # # ]: 0 : (sample_act->dr_port_id_action || sample_act->dr_jump_action)) {
15737 : : int i;
15738 : 0 : void *temp_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
15739 : :
15740 [ # # ]: 0 : for (i = 0; i < actions_n; i++) {
15741 [ # # ]: 0 : if ((sample_act->dr_encap_action &&
15742 : : sample_act->dr_encap_action ==
15743 [ # # # # ]: 0 : dev_flow->dv.actions[i]) ||
15744 : 0 : (sample_act->dr_port_id_action &&
15745 : : sample_act->dr_port_id_action ==
15746 [ # # ]: 0 : dev_flow->dv.actions[i]) ||
15747 [ # # ]: 0 : (sample_act->dr_jump_action &&
15748 : : sample_act->dr_jump_action ==
15749 [ # # ]: 0 : dev_flow->dv.actions[i]))
15750 : 0 : continue;
15751 : 0 : temp_actions[tmp_actions_n++] = dev_flow->dv.actions[i];
15752 : : }
15753 : 0 : memcpy((void *)dev_flow->dv.actions,
15754 : : (void *)temp_actions,
15755 : : tmp_actions_n * sizeof(void *));
15756 : : actions_n = tmp_actions_n;
15757 : : }
15758 : 0 : dev_flow->dv.actions_n = actions_n;
15759 [ # # ]: 0 : if (wks->skip_matcher_reg)
15760 : : return 0;
15761 : : /* Register matcher. */
15762 : 0 : matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
15763 : : matcher.mask.size);
15764 : 0 : matcher.priority = mlx5_get_matcher_priority(dev, attr,
15765 : 0 : matcher.priority,
15766 : 0 : dev_flow->external);
15767 : : /**
15768 : : * When creating meter drop flow in drop table, using original
15769 : : * 5-tuple match, the matcher priority should be lower than
15770 : : * mtr_id matcher.
15771 : : */
15772 [ # # ]: 0 : if (attr->group == MLX5_FLOW_TABLE_LEVEL_METER &&
15773 [ # # # # ]: 0 : dev_flow->dv.table_id == MLX5_MTR_TABLE_ID_DROP &&
15774 : : matcher.priority <= MLX5_REG_BITS)
15775 : 0 : matcher.priority += MLX5_REG_BITS;
15776 : : /* reserved field no needs to be set to 0 here. */
15777 : 0 : tbl_key.is_fdb = attr->transfer;
15778 : 0 : tbl_key.is_egress = attr->egress;
15779 : 0 : tbl_key.level = dev_flow->dv.group;
15780 : 0 : tbl_key.id = dev_flow->dv.table_id;
15781 [ # # ]: 0 : if (flow_dv_matcher_register(dev, &matcher, &tbl_key, dev_flow,
15782 : : tunnel, attr->group, error))
15783 : 0 : return -rte_errno;
15784 : : return 0;
15785 : : }
15786 : :
15787 : : /**
15788 : : * Set hash RX queue by hash fields (see enum ibv_rx_hash_fields)
15789 : : * and tunnel.
15790 : : *
15791 : : * @param[in, out] action
15792 : : * Shred RSS action holding hash RX queue objects.
15793 : : * @param[in] hash_fields
15794 : : * Defines combination of packet fields to participate in RX hash.
15795 : : * @param[in] tunnel
15796 : : * Tunnel type
15797 : : * @param[in] hrxq_idx
15798 : : * Hash RX queue index to set.
15799 : : *
15800 : : * @return
15801 : : * 0 on success, otherwise negative errno value.
15802 : : */
15803 : : static int
15804 : 0 : __flow_dv_action_rss_hrxq_set(struct mlx5_shared_action_rss *action,
15805 : : const uint64_t hash_fields,
15806 : : uint32_t hrxq_idx)
15807 : : {
15808 : : uint32_t *hrxqs = action->hrxq;
15809 : :
15810 [ # # # # : 0 : switch (hash_fields & ~IBV_RX_HASH_INNER) {
# # # # #
# # ]
15811 : 0 : case MLX5_RSS_HASH_IPV4:
15812 : : /* fall-through. */
15813 : : case MLX5_RSS_HASH_IPV4_DST_ONLY:
15814 : : /* fall-through. */
15815 : : case MLX5_RSS_HASH_IPV4_SRC_ONLY:
15816 : 0 : hrxqs[0] = hrxq_idx;
15817 : 0 : return 0;
15818 : 0 : case MLX5_RSS_HASH_IPV4_TCP:
15819 : : /* fall-through. */
15820 : : case MLX5_RSS_HASH_IPV4_TCP_DST_ONLY:
15821 : : /* fall-through. */
15822 : : case MLX5_RSS_HASH_IPV4_TCP_SRC_ONLY:
15823 : 0 : hrxqs[1] = hrxq_idx;
15824 : 0 : return 0;
15825 : 0 : case MLX5_RSS_HASH_IPV4_UDP:
15826 : : /* fall-through. */
15827 : : case MLX5_RSS_HASH_IPV4_UDP_DST_ONLY:
15828 : : /* fall-through. */
15829 : : case MLX5_RSS_HASH_IPV4_UDP_SRC_ONLY:
15830 : 0 : hrxqs[2] = hrxq_idx;
15831 : 0 : return 0;
15832 : 0 : case MLX5_RSS_HASH_IPV6:
15833 : : /* fall-through. */
15834 : : case MLX5_RSS_HASH_IPV6_DST_ONLY:
15835 : : /* fall-through. */
15836 : : case MLX5_RSS_HASH_IPV6_SRC_ONLY:
15837 : 0 : hrxqs[3] = hrxq_idx;
15838 : 0 : return 0;
15839 : 0 : case MLX5_RSS_HASH_IPV6_TCP:
15840 : : /* fall-through. */
15841 : : case MLX5_RSS_HASH_IPV6_TCP_DST_ONLY:
15842 : : /* fall-through. */
15843 : : case MLX5_RSS_HASH_IPV6_TCP_SRC_ONLY:
15844 : 0 : hrxqs[4] = hrxq_idx;
15845 : 0 : return 0;
15846 : 0 : case MLX5_RSS_HASH_IPV6_UDP:
15847 : : /* fall-through. */
15848 : : case MLX5_RSS_HASH_IPV6_UDP_DST_ONLY:
15849 : : /* fall-through. */
15850 : : case MLX5_RSS_HASH_IPV6_UDP_SRC_ONLY:
15851 : 0 : hrxqs[5] = hrxq_idx;
15852 : 0 : return 0;
15853 : 0 : case MLX5_RSS_HASH_NONE:
15854 : 0 : hrxqs[6] = hrxq_idx;
15855 : 0 : return 0;
15856 : 0 : case MLX5_RSS_HASH_IPV4_ESP:
15857 : 0 : hrxqs[7] = hrxq_idx;
15858 : 0 : return 0;
15859 : 0 : case MLX5_RSS_HASH_IPV6_ESP:
15860 : 0 : hrxqs[8] = hrxq_idx;
15861 : 0 : return 0;
15862 : 0 : case MLX5_RSS_HASH_ESP_SPI:
15863 : 0 : hrxqs[9] = hrxq_idx;
15864 : 0 : return 0;
15865 : : default:
15866 : : return -1;
15867 : : }
15868 : : }
15869 : :
15870 : : /**
15871 : : * Look up for hash RX queue by hash fields (see enum ibv_rx_hash_fields)
15872 : : * and tunnel.
15873 : : *
15874 : : * @param[in] dev
15875 : : * Pointer to the Ethernet device structure.
15876 : : * @param[in] idx
15877 : : * Shared RSS action ID holding hash RX queue objects.
15878 : : * @param[in] hash_fields
15879 : : * Defines combination of packet fields to participate in RX hash.
15880 : : * @param[in] tunnel
15881 : : * Tunnel type
15882 : : *
15883 : : * @return
15884 : : * Valid hash RX queue index, otherwise 0.
15885 : : */
15886 : : uint32_t
15887 : 0 : flow_dv_action_rss_hrxq_lookup(struct rte_eth_dev *dev, uint32_t idx,
15888 : : const uint64_t hash_fields)
15889 : : {
15890 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15891 : : struct mlx5_shared_action_rss *shared_rss =
15892 : 0 : mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
15893 : : const uint32_t *hrxqs = shared_rss->hrxq;
15894 : :
15895 [ # # # # : 0 : switch (hash_fields & ~IBV_RX_HASH_INNER) {
# # # # #
# # ]
15896 : 0 : case MLX5_RSS_HASH_IPV4:
15897 : : /* fall-through. */
15898 : : case MLX5_RSS_HASH_IPV4_DST_ONLY:
15899 : : /* fall-through. */
15900 : : case MLX5_RSS_HASH_IPV4_SRC_ONLY:
15901 : 0 : return hrxqs[0];
15902 : 0 : case MLX5_RSS_HASH_IPV4_TCP:
15903 : : /* fall-through. */
15904 : : case MLX5_RSS_HASH_IPV4_TCP_DST_ONLY:
15905 : : /* fall-through. */
15906 : : case MLX5_RSS_HASH_IPV4_TCP_SRC_ONLY:
15907 : 0 : return hrxqs[1];
15908 : 0 : case MLX5_RSS_HASH_IPV4_UDP:
15909 : : /* fall-through. */
15910 : : case MLX5_RSS_HASH_IPV4_UDP_DST_ONLY:
15911 : : /* fall-through. */
15912 : : case MLX5_RSS_HASH_IPV4_UDP_SRC_ONLY:
15913 : 0 : return hrxqs[2];
15914 : 0 : case MLX5_RSS_HASH_IPV6:
15915 : : /* fall-through. */
15916 : : case MLX5_RSS_HASH_IPV6_DST_ONLY:
15917 : : /* fall-through. */
15918 : : case MLX5_RSS_HASH_IPV6_SRC_ONLY:
15919 : 0 : return hrxqs[3];
15920 : 0 : case MLX5_RSS_HASH_IPV6_TCP:
15921 : : /* fall-through. */
15922 : : case MLX5_RSS_HASH_IPV6_TCP_DST_ONLY:
15923 : : /* fall-through. */
15924 : : case MLX5_RSS_HASH_IPV6_TCP_SRC_ONLY:
15925 : 0 : return hrxqs[4];
15926 : 0 : case MLX5_RSS_HASH_IPV6_UDP:
15927 : : /* fall-through. */
15928 : : case MLX5_RSS_HASH_IPV6_UDP_DST_ONLY:
15929 : : /* fall-through. */
15930 : : case MLX5_RSS_HASH_IPV6_UDP_SRC_ONLY:
15931 : 0 : return hrxqs[5];
15932 : 0 : case MLX5_RSS_HASH_NONE:
15933 : 0 : return hrxqs[6];
15934 : 0 : case MLX5_RSS_HASH_IPV4_ESP:
15935 : 0 : return hrxqs[7];
15936 : 0 : case MLX5_RSS_HASH_IPV6_ESP:
15937 : 0 : return hrxqs[8];
15938 : 0 : case MLX5_RSS_HASH_ESP_SPI:
15939 : 0 : return hrxqs[9];
15940 : : default:
15941 : : return 0;
15942 : : }
15943 : :
15944 : : }
15945 : :
15946 : : /**
15947 : : * Apply the flow to the NIC, lock free,
15948 : : * (mutex should be acquired by caller).
15949 : : *
15950 : : * @param[in] dev
15951 : : * Pointer to the Ethernet device structure.
15952 : : * @param[in, out] flow
15953 : : * Pointer to flow structure.
15954 : : * @param[out] error
15955 : : * Pointer to error structure.
15956 : : *
15957 : : * @return
15958 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
15959 : : */
15960 : : static int
15961 : 0 : flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
15962 : : struct rte_flow_error *error)
15963 : : {
15964 : : struct mlx5_flow_dv_workspace *dv;
15965 : : struct mlx5_flow_handle *dh;
15966 : : struct mlx5_flow_handle_dv *dv_h;
15967 : : struct mlx5_flow *dev_flow;
15968 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15969 : : uint32_t handle_idx;
15970 : : int n;
15971 : : int err;
15972 : : int idx;
15973 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
15974 : 0 : struct mlx5_flow_rss_desc *rss_desc = &wks->rss_desc;
15975 : : uint8_t misc_mask;
15976 : :
15977 : : MLX5_ASSERT(wks);
15978 [ # # ]: 0 : for (idx = wks->flow_idx - 1; idx >= 0; idx--) {
15979 : 0 : dev_flow = &wks->flows[idx];
15980 : : dv = &dev_flow->dv;
15981 : 0 : dh = dev_flow->handle;
15982 : : dv_h = &dh->dvh;
15983 : 0 : n = dv->actions_n;
15984 [ # # ]: 0 : if (dh->fate_action == MLX5_FLOW_FATE_DROP) {
15985 [ # # ]: 0 : if (dv->transfer) {
15986 : : MLX5_ASSERT(priv->sh->dr_drop_action);
15987 : 0 : dv->actions[n++] = priv->sh->dr_drop_action;
15988 : : } else {
15989 : : #ifdef HAVE_MLX5DV_DR
15990 : : /* DR supports drop action placeholder. */
15991 : : MLX5_ASSERT(priv->sh->dr_drop_action);
15992 : 0 : dv->actions[n++] = dv->group ?
15993 [ # # ]: 0 : priv->sh->dr_drop_action :
15994 : : priv->root_drop_action;
15995 : : #else
15996 : : /* For DV we use the explicit drop queue. */
15997 : : MLX5_ASSERT(priv->drop_queue.hrxq);
15998 : : dv->actions[n++] =
15999 : : priv->drop_queue.hrxq->action;
16000 : : #endif
16001 : : }
16002 [ # # ]: 0 : } else if ((dh->fate_action == MLX5_FLOW_FATE_QUEUE &&
16003 [ # # # # ]: 0 : !dv_h->rix_sample && !dv_h->rix_dest_array)) {
16004 : : struct mlx5_hrxq *hrxq;
16005 : : uint32_t hrxq_idx;
16006 : :
16007 : 0 : hrxq = flow_dv_hrxq_prepare(dev, dev_flow, rss_desc,
16008 : : &hrxq_idx);
16009 [ # # ]: 0 : if (!hrxq) {
16010 : 0 : rte_flow_error_set
16011 : : (error, rte_errno,
16012 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16013 : : "cannot get hash queue");
16014 : 0 : goto error;
16015 : : }
16016 : 0 : dh->rix_hrxq = hrxq_idx;
16017 : 0 : dv->actions[n++] = hrxq->action;
16018 [ # # ]: 0 : } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
16019 : : struct mlx5_hrxq *hrxq = NULL;
16020 : : uint32_t hrxq_idx;
16021 : :
16022 : 0 : hrxq_idx = flow_dv_action_rss_hrxq_lookup(dev,
16023 : : rss_desc->shared_rss,
16024 : : dev_flow->hash_fields);
16025 [ # # ]: 0 : if (hrxq_idx)
16026 : 0 : hrxq = mlx5_ipool_get
16027 : 0 : (priv->sh->ipool[MLX5_IPOOL_HRXQ],
16028 : : hrxq_idx);
16029 [ # # ]: 0 : if (!hrxq) {
16030 : 0 : rte_flow_error_set
16031 : : (error, rte_errno,
16032 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16033 : : "cannot get hash queue");
16034 : 0 : goto error;
16035 : : }
16036 : 0 : dh->rix_srss = rss_desc->shared_rss;
16037 : 0 : dv->actions[n++] = hrxq->action;
16038 [ # # ]: 0 : } else if (dh->fate_action == MLX5_FLOW_FATE_DEFAULT_MISS) {
16039 [ # # ]: 0 : if (!priv->sh->default_miss_action) {
16040 : 0 : rte_flow_error_set
16041 : : (error, rte_errno,
16042 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16043 : : "default miss action not be created.");
16044 : 0 : goto error;
16045 : : }
16046 : 0 : dv->actions[n++] = priv->sh->default_miss_action;
16047 : : }
16048 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(dv_h->matcher->mask.buf);
16049 : : __flow_dv_adjust_buf_size(&dv->value.size, misc_mask);
16050 : 0 : err = mlx5_flow_os_create_flow(dv_h->matcher->matcher_object,
16051 : 0 : (void *)&dv->value, n,
16052 : 0 : dv->actions, &dh->drv_flow);
16053 : : if (err) {
16054 : 0 : rte_flow_error_set
16055 : 0 : (error, errno,
16056 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
16057 : : NULL,
16058 [ # # ]: 0 : (!priv->sh->config.allow_duplicate_pattern &&
16059 [ # # ]: 0 : errno == EEXIST) ?
16060 : : "duplicating pattern is not allowed" :
16061 : : "hardware refuses to create flow");
16062 : 0 : goto error;
16063 : : }
16064 [ # # ]: 0 : if (priv->vmwa_context &&
16065 [ # # # # ]: 0 : dh->vf_vlan.tag && !dh->vf_vlan.created) {
16066 : : /*
16067 : : * The rule contains the VLAN pattern.
16068 : : * For VF we are going to create VLAN
16069 : : * interface to make hypervisor set correct
16070 : : * e-Switch vport context.
16071 : : */
16072 : 0 : mlx5_vlan_vmwa_acquire(dev, &dh->vf_vlan);
16073 : : }
16074 : : }
16075 : : return 0;
16076 : 0 : error:
16077 : 0 : err = rte_errno; /* Save rte_errno before cleanup. */
16078 [ # # # # : 0 : SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
# # ]
16079 : : handle_idx, dh, next) {
16080 : : /* hrxq is union, don't clear it if the flag is not set. */
16081 [ # # # # ]: 0 : if (dh->fate_action == MLX5_FLOW_FATE_QUEUE && dh->rix_hrxq &&
16082 [ # # # # ]: 0 : !dh->dvh.rix_sample && !dh->dvh.rix_dest_array) {
16083 : 0 : mlx5_hrxq_release(dev, dh->rix_hrxq);
16084 : 0 : dh->rix_hrxq = 0;
16085 [ # # ]: 0 : } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
16086 : 0 : dh->rix_srss = 0;
16087 : : }
16088 [ # # # # ]: 0 : if (dh->vf_vlan.tag && dh->vf_vlan.created)
16089 : 0 : mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
16090 : : }
16091 : 0 : rte_errno = err; /* Restore rte_errno. */
16092 : 0 : return -rte_errno;
16093 : : }
16094 : :
16095 : : void
16096 : 0 : flow_matcher_remove_cb(void *tool_ctx __rte_unused,
16097 : : struct mlx5_list_entry *entry)
16098 : : {
16099 : : struct mlx5_flow_dv_matcher *resource = container_of(entry,
16100 : : typeof(*resource),
16101 : : entry);
16102 : : #ifdef HAVE_MLX5_HWS_SUPPORT
16103 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
16104 : :
16105 [ # # ]: 0 : if (sh->config.dv_flow_en == 2)
16106 : 0 : claim_zero(mlx5dr_bwc_matcher_destroy((struct mlx5dr_bwc_matcher *)
16107 : : resource->matcher_object));
16108 : : else
16109 : : #endif
16110 : 0 : claim_zero(mlx5_flow_os_destroy_flow_matcher(resource->matcher_object));
16111 : 0 : mlx5_free(resource);
16112 : 0 : }
16113 : :
16114 : : /**
16115 : : * Release the flow matcher.
16116 : : *
16117 : : * @param dev
16118 : : * Pointer to Ethernet device.
16119 : : * @param port_id
16120 : : * Index to port ID action resource.
16121 : : *
16122 : : * @return
16123 : : * 1 while a reference on it exists, 0 when freed.
16124 : : */
16125 : : static int
16126 : 0 : flow_dv_matcher_release(struct rte_eth_dev *dev,
16127 : : struct mlx5_flow_handle *handle)
16128 : : {
16129 : 0 : struct mlx5_flow_dv_matcher *matcher = handle->dvh.matcher;
16130 : 0 : struct mlx5_flow_tbl_data_entry *tbl = container_of(matcher->tbl,
16131 : : typeof(*tbl), tbl);
16132 : : int ret;
16133 : :
16134 : : MLX5_ASSERT(matcher->matcher_object);
16135 : 0 : ret = mlx5_list_unregister(tbl->matchers, &matcher->entry);
16136 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl->tbl);
16137 : 0 : return ret;
16138 : : }
16139 : :
16140 : : void
16141 : 0 : flow_encap_decap_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
16142 : : {
16143 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
16144 : : struct mlx5_flow_dv_encap_decap_resource *res =
16145 : : container_of(entry, typeof(*res), entry);
16146 : :
16147 : : #ifdef HAVE_MLX5_HWS_SUPPORT
16148 [ # # ]: 0 : if (sh->config.dv_flow_en == 2)
16149 : 0 : claim_zero(mlx5dr_action_destroy(res->action));
16150 : : else
16151 : : #endif
16152 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
16153 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], res->idx);
16154 : 0 : }
16155 : :
16156 : : /**
16157 : : * Release an encap/decap resource.
16158 : : *
16159 : : * @param dev
16160 : : * Pointer to Ethernet device.
16161 : : * @param encap_decap_idx
16162 : : * Index of encap decap resource.
16163 : : *
16164 : : * @return
16165 : : * 1 while a reference on it exists, 0 when freed.
16166 : : */
16167 : : int
16168 : 0 : flow_encap_decap_resource_release(struct rte_eth_dev *dev,
16169 : : uint32_t encap_decap_idx)
16170 : : {
16171 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16172 : : struct mlx5_flow_dv_encap_decap_resource *resource;
16173 : :
16174 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
16175 : : encap_decap_idx);
16176 [ # # ]: 0 : if (!resource)
16177 : : return 0;
16178 : : MLX5_ASSERT(resource->action);
16179 : 0 : return mlx5_hlist_unregister(priv->sh->encaps_decaps, &resource->entry);
16180 : : }
16181 : :
16182 : : /**
16183 : : * Release an jump to table action resource.
16184 : : *
16185 : : * @param dev
16186 : : * Pointer to Ethernet device.
16187 : : * @param rix_jump
16188 : : * Index to the jump action resource.
16189 : : *
16190 : : * @return
16191 : : * 1 while a reference on it exists, 0 when freed.
16192 : : */
16193 : : static int
16194 : 0 : flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev,
16195 : : uint32_t rix_jump)
16196 : : {
16197 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16198 : : struct mlx5_flow_tbl_data_entry *tbl_data;
16199 : :
16200 : 0 : tbl_data = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_JUMP],
16201 : : rix_jump);
16202 [ # # ]: 0 : if (!tbl_data)
16203 : : return 0;
16204 : 0 : return flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl_data->tbl);
16205 : : }
16206 : :
16207 : : void
16208 : 0 : flow_modify_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
16209 : : {
16210 : : struct mlx5_flow_dv_modify_hdr_resource *res =
16211 : : container_of(entry, typeof(*res), entry);
16212 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
16213 : :
16214 : : #ifdef HAVE_MLX5_HWS_SUPPORT
16215 [ # # ]: 0 : if (sh->config.dv_flow_en == 2)
16216 : 0 : claim_zero(mlx5dr_action_destroy(res->action));
16217 : : else
16218 : : #endif
16219 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
16220 : 0 : mlx5_ipool_free(sh->mdh_ipools[res->actions_num - 1], res->idx);
16221 : 0 : }
16222 : :
16223 : : /**
16224 : : * Release a modify-header resource.
16225 : : *
16226 : : * @param dev
16227 : : * Pointer to Ethernet device.
16228 : : * @param handle
16229 : : * Pointer to mlx5_flow_handle.
16230 : : *
16231 : : * @return
16232 : : * 1 while a reference on it exists, 0 when freed.
16233 : : */
16234 : : static int
16235 : : flow_dv_modify_hdr_resource_release(struct rte_eth_dev *dev,
16236 : : struct mlx5_flow_handle *handle)
16237 : : {
16238 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16239 : : struct mlx5_flow_dv_modify_hdr_resource *entry = handle->dvh.modify_hdr;
16240 : :
16241 : : MLX5_ASSERT(entry->action);
16242 : 0 : return mlx5_hlist_unregister(priv->sh->modify_cmds, &entry->entry);
16243 : : }
16244 : :
16245 : : void
16246 : 0 : flow_dv_port_id_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
16247 : : {
16248 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
16249 : : struct mlx5_flow_dv_port_id_action_resource *resource =
16250 : : container_of(entry, typeof(*resource), entry);
16251 : :
16252 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
16253 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], resource->idx);
16254 : 0 : }
16255 : :
16256 : : /**
16257 : : * Release port ID action resource.
16258 : : *
16259 : : * @param dev
16260 : : * Pointer to Ethernet device.
16261 : : * @param handle
16262 : : * Pointer to mlx5_flow_handle.
16263 : : *
16264 : : * @return
16265 : : * 1 while a reference on it exists, 0 when freed.
16266 : : */
16267 : : static int
16268 : 0 : flow_dv_port_id_action_resource_release(struct rte_eth_dev *dev,
16269 : : uint32_t port_id)
16270 : : {
16271 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16272 : : struct mlx5_flow_dv_port_id_action_resource *resource;
16273 : :
16274 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PORT_ID], port_id);
16275 [ # # ]: 0 : if (!resource)
16276 : : return 0;
16277 : : MLX5_ASSERT(resource->action);
16278 : 0 : return mlx5_list_unregister(priv->sh->port_id_action_list,
16279 : : &resource->entry);
16280 : : }
16281 : :
16282 : : /**
16283 : : * Release shared RSS action resource.
16284 : : *
16285 : : * @param dev
16286 : : * Pointer to Ethernet device.
16287 : : * @param srss
16288 : : * Shared RSS action index.
16289 : : */
16290 : : static void
16291 : 0 : flow_dv_shared_rss_action_release(struct rte_eth_dev *dev, uint32_t srss)
16292 : : {
16293 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16294 : : struct mlx5_shared_action_rss *shared_rss;
16295 : :
16296 : 0 : shared_rss = mlx5_ipool_get
16297 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], srss);
16298 : 0 : rte_atomic_fetch_sub_explicit(&shared_rss->refcnt, 1, rte_memory_order_relaxed);
16299 : 0 : }
16300 : :
16301 : : void
16302 : 0 : flow_dv_push_vlan_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
16303 : : {
16304 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
16305 : : struct mlx5_flow_dv_push_vlan_action_resource *resource =
16306 : : container_of(entry, typeof(*resource), entry);
16307 : :
16308 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
16309 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], resource->idx);
16310 : 0 : }
16311 : :
16312 : : /**
16313 : : * Release push vlan action resource.
16314 : : *
16315 : : * @param dev
16316 : : * Pointer to Ethernet device.
16317 : : * @param handle
16318 : : * Pointer to mlx5_flow_handle.
16319 : : *
16320 : : * @return
16321 : : * 1 while a reference on it exists, 0 when freed.
16322 : : */
16323 : : static int
16324 : 0 : flow_dv_push_vlan_action_resource_release(struct rte_eth_dev *dev,
16325 : : struct mlx5_flow_handle *handle)
16326 : : {
16327 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16328 : : struct mlx5_flow_dv_push_vlan_action_resource *resource;
16329 : 0 : uint32_t idx = handle->dvh.rix_push_vlan;
16330 : :
16331 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
16332 [ # # ]: 0 : if (!resource)
16333 : : return 0;
16334 : : MLX5_ASSERT(resource->action);
16335 : 0 : return mlx5_list_unregister(priv->sh->push_vlan_action_list,
16336 : : &resource->entry);
16337 : : }
16338 : :
16339 : : /**
16340 : : * Release the fate resource.
16341 : : *
16342 : : * @param dev
16343 : : * Pointer to Ethernet device.
16344 : : * @param handle
16345 : : * Pointer to mlx5_flow_handle.
16346 : : */
16347 : : static void
16348 : 0 : flow_dv_fate_resource_release(struct rte_eth_dev *dev,
16349 : : struct mlx5_flow_handle *handle)
16350 : : {
16351 [ # # ]: 0 : if (!handle->rix_fate)
16352 : : return;
16353 [ # # # # : 0 : switch (handle->fate_action) {
# ]
16354 : 0 : case MLX5_FLOW_FATE_QUEUE:
16355 [ # # # # ]: 0 : if (!handle->dvh.rix_sample && !handle->dvh.rix_dest_array)
16356 : 0 : mlx5_hrxq_release(dev, handle->rix_hrxq);
16357 : : break;
16358 : 0 : case MLX5_FLOW_FATE_JUMP:
16359 : 0 : flow_dv_jump_tbl_resource_release(dev, handle->rix_jump);
16360 : 0 : break;
16361 : 0 : case MLX5_FLOW_FATE_PORT_ID:
16362 : 0 : flow_dv_port_id_action_resource_release(dev,
16363 : : handle->rix_port_id_action);
16364 : 0 : break;
16365 : : case MLX5_FLOW_FATE_SEND_TO_KERNEL:
16366 : : /* In case of send_to_kernel action the actual release of
16367 : : * resource is done when all shared DR resources are released
16368 : : * since this resource is created once and always reused.
16369 : : */
16370 : : break;
16371 : 0 : default:
16372 : 0 : DRV_LOG(DEBUG, "Incorrect fate action:%d", handle->fate_action);
16373 : 0 : break;
16374 : : }
16375 : 0 : handle->rix_fate = 0;
16376 : : }
16377 : :
16378 : : void
16379 : 0 : flow_dv_sample_remove_cb(void *tool_ctx __rte_unused,
16380 : : struct mlx5_list_entry *entry)
16381 : : {
16382 : : struct mlx5_flow_dv_sample_resource *resource = container_of(entry,
16383 : : typeof(*resource),
16384 : : entry);
16385 : 0 : struct rte_eth_dev *dev = resource->dev;
16386 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16387 : :
16388 [ # # ]: 0 : if (resource->verbs_action)
16389 : : claim_zero(mlx5_flow_os_destroy_flow_action
16390 : : (resource->verbs_action));
16391 [ # # ]: 0 : if (resource->normal_path_tbl)
16392 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev),
16393 : : resource->normal_path_tbl);
16394 : 0 : flow_dv_sample_sub_actions_release(dev, &resource->sample_idx);
16395 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_SAMPLE], resource->idx);
16396 : 0 : DRV_LOG(DEBUG, "sample resource %p: removed", (void *)resource);
16397 : 0 : }
16398 : :
16399 : : /**
16400 : : * Release an sample resource.
16401 : : *
16402 : : * @param dev
16403 : : * Pointer to Ethernet device.
16404 : : * @param handle
16405 : : * Pointer to mlx5_flow_handle.
16406 : : *
16407 : : * @return
16408 : : * 1 while a reference on it exists, 0 when freed.
16409 : : */
16410 : : static int
16411 : 0 : flow_dv_sample_resource_release(struct rte_eth_dev *dev,
16412 : : struct mlx5_flow_handle *handle)
16413 : : {
16414 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16415 : : struct mlx5_flow_dv_sample_resource *resource;
16416 : :
16417 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_SAMPLE],
16418 : : handle->dvh.rix_sample);
16419 [ # # ]: 0 : if (!resource)
16420 : : return 0;
16421 : : MLX5_ASSERT(resource->verbs_action);
16422 : 0 : return mlx5_list_unregister(priv->sh->sample_action_list,
16423 : : &resource->entry);
16424 : : }
16425 : :
16426 : : void
16427 : 0 : flow_dv_dest_array_remove_cb(void *tool_ctx __rte_unused,
16428 : : struct mlx5_list_entry *entry)
16429 : : {
16430 : : struct mlx5_flow_dv_dest_array_resource *resource =
16431 : : container_of(entry, typeof(*resource), entry);
16432 : 0 : struct rte_eth_dev *dev = resource->dev;
16433 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16434 : : uint32_t i = 0;
16435 : :
16436 : : MLX5_ASSERT(resource->action);
16437 [ # # ]: 0 : if (resource->action)
16438 : : claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
16439 [ # # ]: 0 : for (; i < resource->num_of_dest; i++)
16440 : 0 : flow_dv_sample_sub_actions_release(dev,
16441 : : &resource->sample_idx[i]);
16442 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY], resource->idx);
16443 : 0 : DRV_LOG(DEBUG, "destination array resource %p: removed",
16444 : : (void *)resource);
16445 : 0 : }
16446 : :
16447 : : /**
16448 : : * Release an destination array resource.
16449 : : *
16450 : : * @param dev
16451 : : * Pointer to Ethernet device.
16452 : : * @param handle
16453 : : * Pointer to mlx5_flow_handle.
16454 : : *
16455 : : * @return
16456 : : * 1 while a reference on it exists, 0 when freed.
16457 : : */
16458 : : static int
16459 : 0 : flow_dv_dest_array_resource_release(struct rte_eth_dev *dev,
16460 : : struct mlx5_flow_handle *handle)
16461 : : {
16462 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16463 : : struct mlx5_flow_dv_dest_array_resource *resource;
16464 : :
16465 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY],
16466 : : handle->dvh.rix_dest_array);
16467 [ # # ]: 0 : if (!resource)
16468 : : return 0;
16469 : : MLX5_ASSERT(resource->action);
16470 : 0 : return mlx5_list_unregister(priv->sh->dest_array_list,
16471 : : &resource->entry);
16472 : : }
16473 : :
16474 : : static void
16475 : 0 : flow_dev_geneve_tlv_option_resource_release(struct mlx5_dev_ctx_shared *sh)
16476 : : {
16477 : 0 : struct mlx5_geneve_tlv_option_resource *geneve_opt_resource =
16478 : : sh->geneve_tlv_option_resource;
16479 : 0 : rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
16480 [ # # ]: 0 : if (geneve_opt_resource) {
16481 [ # # ]: 0 : if (!(rte_atomic_fetch_sub_explicit(&geneve_opt_resource->refcnt, 1,
16482 : : rte_memory_order_relaxed) - 1)) {
16483 : 0 : claim_zero(mlx5_devx_cmd_destroy
16484 : : (geneve_opt_resource->obj));
16485 : 0 : mlx5_free(sh->geneve_tlv_option_resource);
16486 : 0 : sh->geneve_tlv_option_resource = NULL;
16487 : : }
16488 : : }
16489 : : rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
16490 : 0 : }
16491 : :
16492 : : /**
16493 : : * Remove the flow from the NIC but keeps it in memory.
16494 : : * Lock free, (mutex should be acquired by caller).
16495 : : *
16496 : : * @param[in] dev
16497 : : * Pointer to Ethernet device.
16498 : : * @param[in, out] flow
16499 : : * Pointer to flow structure.
16500 : : */
16501 : : static void
16502 : 0 : flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
16503 : : {
16504 : : struct mlx5_flow_handle *dh;
16505 : : uint32_t handle_idx;
16506 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16507 : :
16508 [ # # ]: 0 : if (!flow)
16509 : : return;
16510 : 0 : handle_idx = flow->dev_handles;
16511 [ # # ]: 0 : while (handle_idx) {
16512 : 0 : dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
16513 : : handle_idx);
16514 [ # # ]: 0 : if (!dh)
16515 : : return;
16516 [ # # ]: 0 : if (dh->drv_flow) {
16517 : : claim_zero(mlx5_flow_os_destroy_flow(dh->drv_flow));
16518 : 0 : dh->drv_flow = NULL;
16519 : : }
16520 [ # # ]: 0 : if (dh->fate_action == MLX5_FLOW_FATE_QUEUE)
16521 : 0 : flow_dv_fate_resource_release(dev, dh);
16522 [ # # # # ]: 0 : if (dh->vf_vlan.tag && dh->vf_vlan.created)
16523 : 0 : mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
16524 : 0 : handle_idx = dh->next.next;
16525 : : }
16526 : : }
16527 : :
16528 : : /**
16529 : : * Remove the flow from the NIC and the memory.
16530 : : * Lock free, (mutex should be acquired by caller).
16531 : : *
16532 : : * @param[in] dev
16533 : : * Pointer to the Ethernet device structure.
16534 : : * @param[in, out] flow
16535 : : * Pointer to flow structure.
16536 : : */
16537 : : static void
16538 : 0 : flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
16539 : : {
16540 : : struct mlx5_flow_handle *dev_handle;
16541 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16542 : : struct mlx5_flow_meter_info *fm = NULL;
16543 : : uint32_t srss = 0;
16544 : :
16545 [ # # ]: 0 : if (!flow)
16546 : : return;
16547 : 0 : flow_dv_remove(dev, flow);
16548 [ # # ]: 0 : if (flow->counter) {
16549 : 0 : flow_dv_counter_free(dev, flow->counter);
16550 : 0 : flow->counter = 0;
16551 : : }
16552 [ # # ]: 0 : if (flow->meter) {
16553 : 0 : fm = flow_dv_meter_find_by_idx(priv, flow->meter);
16554 [ # # ]: 0 : if (fm)
16555 : 0 : mlx5_flow_meter_detach(priv, fm);
16556 : 0 : flow->meter = 0;
16557 : : }
16558 : : /* Keep the current age handling by default. */
16559 [ # # # # ]: 0 : if (flow->indirect_type == MLX5_INDIRECT_ACTION_TYPE_CT && flow->ct)
16560 : 0 : flow_dv_aso_ct_release(dev, flow->ct, NULL);
16561 [ # # ]: 0 : else if (flow->age)
16562 : 0 : flow_dv_aso_age_release(dev, flow->age);
16563 [ # # ]: 0 : while (flow->geneve_tlv_option) {
16564 : 0 : flow_dev_geneve_tlv_option_resource_release(priv->sh);
16565 : 0 : flow->geneve_tlv_option--;
16566 : : }
16567 [ # # ]: 0 : while (flow->dev_handles) {
16568 : : uint32_t tmp_idx = flow->dev_handles;
16569 : :
16570 : 0 : dev_handle = mlx5_ipool_get(priv->sh->ipool
16571 : : [MLX5_IPOOL_MLX5_FLOW], tmp_idx);
16572 [ # # ]: 0 : if (!dev_handle)
16573 : : return;
16574 : 0 : flow->dev_handles = dev_handle->next.next;
16575 [ # # ]: 0 : while (dev_handle->flex_item) {
16576 : 0 : int index = rte_bsf32(dev_handle->flex_item);
16577 : :
16578 : 0 : mlx5_flex_release_index(dev, index);
16579 : 0 : dev_handle->flex_item &= ~(uint8_t)RTE_BIT32(index);
16580 : : }
16581 [ # # ]: 0 : if (dev_handle->dvh.matcher)
16582 : 0 : flow_dv_matcher_release(dev, dev_handle);
16583 [ # # ]: 0 : if (dev_handle->dvh.rix_sample)
16584 : 0 : flow_dv_sample_resource_release(dev, dev_handle);
16585 [ # # ]: 0 : if (dev_handle->dvh.rix_dest_array)
16586 : 0 : flow_dv_dest_array_resource_release(dev, dev_handle);
16587 [ # # ]: 0 : if (dev_handle->dvh.rix_encap_decap)
16588 : 0 : flow_encap_decap_resource_release(dev,
16589 : : dev_handle->dvh.rix_encap_decap);
16590 [ # # ]: 0 : if (dev_handle->dvh.modify_hdr)
16591 : : flow_dv_modify_hdr_resource_release(dev, dev_handle);
16592 [ # # ]: 0 : if (dev_handle->dvh.rix_push_vlan)
16593 : 0 : flow_dv_push_vlan_action_resource_release(dev,
16594 : : dev_handle);
16595 [ # # ]: 0 : if (dev_handle->dvh.rix_tag)
16596 : 0 : flow_dv_tag_release(dev,
16597 : : dev_handle->dvh.rix_tag);
16598 [ # # ]: 0 : if (dev_handle->fate_action != MLX5_FLOW_FATE_SHARED_RSS)
16599 : 0 : flow_dv_fate_resource_release(dev, dev_handle);
16600 [ # # ]: 0 : else if (!srss)
16601 : 0 : srss = dev_handle->rix_srss;
16602 [ # # # # ]: 0 : if (fm && dev_handle->is_meter_flow_id &&
16603 [ # # ]: 0 : dev_handle->split_flow_id)
16604 : 0 : mlx5_ipool_free(fm->flow_ipool,
16605 : : dev_handle->split_flow_id);
16606 [ # # ]: 0 : else if (dev_handle->split_flow_id &&
16607 [ # # ]: 0 : !dev_handle->is_meter_flow_id)
16608 : 0 : mlx5_ipool_free(priv->sh->ipool
16609 : : [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
16610 : : dev_handle->split_flow_id);
16611 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
16612 : : tmp_idx);
16613 : : }
16614 [ # # ]: 0 : if (srss)
16615 : 0 : flow_dv_shared_rss_action_release(dev, srss);
16616 : : }
16617 : :
16618 : : /**
16619 : : * Release array of hash RX queue objects.
16620 : : * Helper function.
16621 : : *
16622 : : * @param[in] dev
16623 : : * Pointer to the Ethernet device structure.
16624 : : * @param[in, out] hrxqs
16625 : : * Array of hash RX queue objects.
16626 : : *
16627 : : * @return
16628 : : * Total number of references to hash RX queue objects in *hrxqs* array
16629 : : * after this operation.
16630 : : */
16631 : : static int
16632 : 0 : __flow_dv_hrxqs_release(struct rte_eth_dev *dev,
16633 : : uint32_t (*hrxqs)[MLX5_RSS_HASH_FIELDS_LEN])
16634 : : {
16635 : : size_t i;
16636 : : int remaining = 0;
16637 : :
16638 [ # # ]: 0 : for (i = 0; i < RTE_DIM(*hrxqs); i++) {
16639 : 0 : int ret = mlx5_hrxq_release(dev, (*hrxqs)[i]);
16640 : :
16641 [ # # ]: 0 : if (!ret)
16642 : 0 : (*hrxqs)[i] = 0;
16643 : 0 : remaining += ret;
16644 : : }
16645 : 0 : return remaining;
16646 : : }
16647 : :
16648 : : /**
16649 : : * Release all hash RX queue objects representing shared RSS action.
16650 : : *
16651 : : * @param[in] dev
16652 : : * Pointer to the Ethernet device structure.
16653 : : * @param[in, out] action
16654 : : * Shared RSS action to remove hash RX queue objects from.
16655 : : *
16656 : : * @return
16657 : : * Total number of references to hash RX queue objects stored in *action*
16658 : : * after this operation.
16659 : : * Expected to be 0 if no external references held.
16660 : : */
16661 : : static int
16662 : : __flow_dv_action_rss_hrxqs_release(struct rte_eth_dev *dev,
16663 : : struct mlx5_shared_action_rss *shared_rss)
16664 : : {
16665 : 0 : return __flow_dv_hrxqs_release(dev, &shared_rss->hrxq);
16666 : : }
16667 : :
16668 : : /**
16669 : : * Adjust L3/L4 hash value of pre-created shared RSS hrxq according to
16670 : : * user input.
16671 : : *
16672 : : * Only one hash value is available for one L3+L4 combination:
16673 : : * for example:
16674 : : * MLX5_RSS_HASH_IPV4, MLX5_RSS_HASH_IPV4_SRC_ONLY, and
16675 : : * MLX5_RSS_HASH_IPV4_DST_ONLY are mutually exclusive so they can share
16676 : : * same slot in mlx5_rss_hash_fields.
16677 : : *
16678 : : * @param[in] orig_rss_types
16679 : : * RSS type as provided in shared RSS action.
16680 : : * @param[in, out] hash_field
16681 : : * hash_field variable needed to be adjusted.
16682 : : *
16683 : : * @return
16684 : : * void
16685 : : */
16686 : : void
16687 [ # # ]: 0 : flow_dv_action_rss_l34_hash_adjust(uint64_t orig_rss_types,
16688 : : uint64_t *hash_field)
16689 : : {
16690 : : uint64_t rss_types = rte_eth_rss_hf_refine(orig_rss_types);
16691 : :
16692 [ # # # # : 0 : switch (*hash_field & ~IBV_RX_HASH_INNER) {
# ]
16693 : 0 : case MLX5_RSS_HASH_IPV4:
16694 [ # # ]: 0 : if (rss_types & MLX5_IPV4_LAYER_TYPES) {
16695 : 0 : *hash_field &= ~MLX5_RSS_HASH_IPV4;
16696 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
16697 : 0 : *hash_field |= IBV_RX_HASH_DST_IPV4;
16698 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
16699 : 0 : *hash_field |= IBV_RX_HASH_SRC_IPV4;
16700 : : else
16701 : 0 : *hash_field |= MLX5_RSS_HASH_IPV4;
16702 : : }
16703 : : return;
16704 : 0 : case MLX5_RSS_HASH_IPV6:
16705 [ # # ]: 0 : if (rss_types & MLX5_IPV6_LAYER_TYPES) {
16706 : 0 : *hash_field &= ~MLX5_RSS_HASH_IPV6;
16707 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
16708 : 0 : *hash_field |= IBV_RX_HASH_DST_IPV6;
16709 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
16710 : 0 : *hash_field |= IBV_RX_HASH_SRC_IPV6;
16711 : : else
16712 : 0 : *hash_field |= MLX5_RSS_HASH_IPV6;
16713 : : }
16714 : : return;
16715 : 0 : case MLX5_RSS_HASH_IPV4_UDP:
16716 : : /* fall-through. */
16717 : : case MLX5_RSS_HASH_IPV6_UDP:
16718 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_UDP) {
16719 : 0 : *hash_field &= ~MLX5_UDP_IBV_RX_HASH;
16720 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
16721 : 0 : *hash_field |= IBV_RX_HASH_DST_PORT_UDP;
16722 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
16723 : 0 : *hash_field |= IBV_RX_HASH_SRC_PORT_UDP;
16724 : : else
16725 : 0 : *hash_field |= MLX5_UDP_IBV_RX_HASH;
16726 : : }
16727 : : return;
16728 : 0 : case MLX5_RSS_HASH_IPV4_TCP:
16729 : : /* fall-through. */
16730 : : case MLX5_RSS_HASH_IPV6_TCP:
16731 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_TCP) {
16732 : 0 : *hash_field &= ~MLX5_TCP_IBV_RX_HASH;
16733 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
16734 : 0 : *hash_field |= IBV_RX_HASH_DST_PORT_TCP;
16735 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
16736 : 0 : *hash_field |= IBV_RX_HASH_SRC_PORT_TCP;
16737 : : else
16738 : 0 : *hash_field |= MLX5_TCP_IBV_RX_HASH;
16739 : : }
16740 : : return;
16741 : : default:
16742 : : return;
16743 : : }
16744 : : }
16745 : :
16746 : : /**
16747 : : * Setup shared RSS action.
16748 : : * Prepare set of hash RX queue objects sufficient to handle all valid
16749 : : * hash_fields combinations (see enum ibv_rx_hash_fields).
16750 : : *
16751 : : * @param[in] dev
16752 : : * Pointer to the Ethernet device structure.
16753 : : * @param[in] action_idx
16754 : : * Shared RSS action ipool index.
16755 : : * @param[in, out] action
16756 : : * Partially initialized shared RSS action.
16757 : : * @param[out] error
16758 : : * Perform verbose error reporting if not NULL. Initialized in case of
16759 : : * error only.
16760 : : *
16761 : : * @return
16762 : : * 0 on success, otherwise negative errno value.
16763 : : */
16764 : : static int
16765 : 0 : __flow_dv_action_rss_setup(struct rte_eth_dev *dev,
16766 : : uint32_t action_idx,
16767 : : struct mlx5_shared_action_rss *shared_rss,
16768 : : struct rte_flow_error *error)
16769 : : {
16770 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16771 : 0 : struct mlx5_flow_rss_desc rss_desc = { 0 };
16772 : : size_t i;
16773 : : int err;
16774 : :
16775 : 0 : shared_rss->ind_tbl = mlx5_ind_table_obj_new
16776 : : (dev, shared_rss->origin.queue,
16777 : : shared_rss->origin.queue_num,
16778 : : true,
16779 : 0 : !!dev->data->dev_started);
16780 [ # # ]: 0 : if (!shared_rss->ind_tbl)
16781 : 0 : return rte_flow_error_set(error, rte_errno,
16782 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16783 : : "cannot setup indirection table");
16784 : 0 : memcpy(rss_desc.key, shared_rss->origin.key, MLX5_RSS_HASH_KEY_LEN);
16785 : 0 : rss_desc.key_len = MLX5_RSS_HASH_KEY_LEN;
16786 : 0 : rss_desc.symmetric_hash_function =
16787 : 0 : MLX5_RSS_IS_SYMM(shared_rss->origin.func);
16788 : 0 : rss_desc.const_q = shared_rss->origin.queue;
16789 : 0 : rss_desc.queue_num = shared_rss->origin.queue_num;
16790 : : /* Set non-zero value to indicate a shared RSS. */
16791 : 0 : rss_desc.shared_rss = action_idx;
16792 : 0 : rss_desc.ind_tbl = shared_rss->ind_tbl;
16793 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
16794 : 0 : rss_desc.hws_flags = MLX5DR_ACTION_FLAG_HWS_RX;
16795 [ # # ]: 0 : for (i = 0; i < MLX5_RSS_HASH_FIELDS_LEN; i++) {
16796 : : struct mlx5_hrxq *hrxq;
16797 : 0 : uint64_t hash_fields = mlx5_rss_hash_fields[i];
16798 : : int tunnel = 0;
16799 : :
16800 : 0 : flow_dv_action_rss_l34_hash_adjust(shared_rss->origin.types,
16801 : : &hash_fields);
16802 [ # # ]: 0 : if (shared_rss->origin.level > 1) {
16803 : 0 : hash_fields |= IBV_RX_HASH_INNER;
16804 : : tunnel = 1;
16805 : : }
16806 : 0 : rss_desc.tunnel = tunnel;
16807 : 0 : rss_desc.hash_fields = hash_fields;
16808 : 0 : hrxq = mlx5_hrxq_get(dev, &rss_desc);
16809 [ # # ]: 0 : if (!hrxq) {
16810 : 0 : rte_flow_error_set
16811 : : (error, rte_errno,
16812 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16813 : : "cannot get hash queue");
16814 : 0 : goto error_hrxq_new;
16815 : : }
16816 : 0 : err = __flow_dv_action_rss_hrxq_set
16817 : : (shared_rss, hash_fields, hrxq->idx);
16818 : : MLX5_ASSERT(!err);
16819 : : }
16820 : : return 0;
16821 : : error_hrxq_new:
16822 : 0 : err = rte_errno;
16823 : : __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
16824 [ # # ]: 0 : if (!mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl, true))
16825 : 0 : shared_rss->ind_tbl = NULL;
16826 : 0 : rte_errno = err;
16827 : 0 : return -rte_errno;
16828 : : }
16829 : :
16830 : : /**
16831 : : * Create shared RSS action.
16832 : : *
16833 : : * @param[in] dev
16834 : : * Pointer to the Ethernet device structure.
16835 : : * @param[in] conf
16836 : : * Shared action configuration.
16837 : : * @param[in] rss
16838 : : * RSS action specification used to create shared action.
16839 : : * @param[out] error
16840 : : * Perform verbose error reporting if not NULL. Initialized in case of
16841 : : * error only.
16842 : : *
16843 : : * @return
16844 : : * A valid shared action ID in case of success, 0 otherwise and
16845 : : * rte_errno is set.
16846 : : */
16847 : : static uint32_t
16848 : 0 : __flow_dv_action_rss_create(struct rte_eth_dev *dev,
16849 : : const struct rte_flow_indir_action_conf *conf,
16850 : : const struct rte_flow_action_rss *rss,
16851 : : struct rte_flow_error *error)
16852 : : {
16853 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16854 : : struct mlx5_shared_action_rss *shared_rss = NULL;
16855 : : struct rte_flow_action_rss *origin;
16856 : : const uint8_t *rss_key;
16857 : : uint32_t idx;
16858 : :
16859 : : RTE_SET_USED(conf);
16860 : 0 : shared_rss = mlx5_ipool_zmalloc
16861 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], &idx);
16862 [ # # ]: 0 : if (!shared_rss) {
16863 : 0 : rte_flow_error_set(error, ENOMEM,
16864 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16865 : : "cannot allocate resource memory");
16866 : 0 : goto error_rss_init;
16867 : : }
16868 [ # # ]: 0 : if (idx > (1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET)) {
16869 : 0 : rte_flow_error_set(error, E2BIG,
16870 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16871 : : "rss action number out of range");
16872 : 0 : goto error_rss_init;
16873 : : }
16874 : : origin = &shared_rss->origin;
16875 : 0 : origin->func = rss->func;
16876 : 0 : origin->level = rss->level;
16877 : : /* RSS type 0 indicates default RSS type (RTE_ETH_RSS_IP). */
16878 [ # # ]: 0 : origin->types = !rss->types ? RTE_ETH_RSS_IP : rss->types;
16879 : : /* NULL RSS key indicates default RSS key. */
16880 [ # # ]: 0 : rss_key = !rss->key ? rss_hash_default_key : rss->key;
16881 : 0 : memcpy(shared_rss->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
16882 : 0 : origin->key = &shared_rss->key[0];
16883 : 0 : origin->key_len = MLX5_RSS_HASH_KEY_LEN;
16884 : 0 : origin->queue = rss->queue;
16885 : 0 : origin->queue_num = rss->queue_num;
16886 [ # # ]: 0 : if (__flow_dv_action_rss_setup(dev, idx, shared_rss, error))
16887 : 0 : goto error_rss_init;
16888 : : /* Update queue with indirect table queue memoyr. */
16889 : 0 : origin->queue = shared_rss->ind_tbl->queues;
16890 : : rte_spinlock_init(&shared_rss->action_rss_sl);
16891 : 0 : rte_atomic_fetch_add_explicit(&shared_rss->refcnt, 1, rte_memory_order_relaxed);
16892 : 0 : rte_spinlock_lock(&priv->shared_act_sl);
16893 [ # # # # ]: 0 : ILIST_INSERT(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
16894 : : &priv->rss_shared_actions, idx, shared_rss, next);
16895 : : rte_spinlock_unlock(&priv->shared_act_sl);
16896 : 0 : return idx;
16897 : 0 : error_rss_init:
16898 [ # # ]: 0 : if (shared_rss) {
16899 [ # # ]: 0 : if (shared_rss->ind_tbl)
16900 : 0 : mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl,
16901 : 0 : !!dev->data->dev_started);
16902 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
16903 : : idx);
16904 : : }
16905 : : return 0;
16906 : : }
16907 : :
16908 : : /**
16909 : : * Destroy the shared RSS action.
16910 : : * Release related hash RX queue objects.
16911 : : *
16912 : : * @param[in] dev
16913 : : * Pointer to the Ethernet device structure.
16914 : : * @param[in] idx
16915 : : * The shared RSS action object ID to be removed.
16916 : : * @param[out] error
16917 : : * Perform verbose error reporting if not NULL. Initialized in case of
16918 : : * error only.
16919 : : *
16920 : : * @return
16921 : : * 0 on success, otherwise negative errno value.
16922 : : */
16923 : : static int
16924 : 0 : __flow_dv_action_rss_release(struct rte_eth_dev *dev, uint32_t idx,
16925 : : struct rte_flow_error *error)
16926 : : {
16927 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16928 : : struct mlx5_shared_action_rss *shared_rss =
16929 : 0 : mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
16930 : : uint32_t old_refcnt = 1;
16931 : : int remaining;
16932 : :
16933 [ # # ]: 0 : if (!shared_rss)
16934 : 0 : return rte_flow_error_set(error, EINVAL,
16935 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
16936 : : "invalid shared action");
16937 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(&shared_rss->refcnt, &old_refcnt,
16938 : : 0, rte_memory_order_acquire,
16939 : : rte_memory_order_relaxed))
16940 : 0 : return rte_flow_error_set(error, EBUSY,
16941 : : RTE_FLOW_ERROR_TYPE_ACTION,
16942 : : NULL,
16943 : : "shared rss has references");
16944 : : remaining = __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
16945 [ # # ]: 0 : if (remaining)
16946 : 0 : return rte_flow_error_set(error, EBUSY,
16947 : : RTE_FLOW_ERROR_TYPE_ACTION,
16948 : : NULL,
16949 : : "shared rss hrxq has references");
16950 : 0 : remaining = mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl,
16951 : 0 : !!dev->data->dev_started);
16952 [ # # ]: 0 : if (remaining)
16953 : 0 : return rte_flow_error_set(error, EBUSY,
16954 : : RTE_FLOW_ERROR_TYPE_ACTION,
16955 : : NULL,
16956 : : "shared rss indirection table has"
16957 : : " references");
16958 : 0 : rte_spinlock_lock(&priv->shared_act_sl);
16959 [ # # # # : 0 : ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
# # # # #
# ]
16960 : : &priv->rss_shared_actions, idx, shared_rss, next);
16961 : : rte_spinlock_unlock(&priv->shared_act_sl);
16962 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
16963 : : idx);
16964 : 0 : return 0;
16965 : : }
16966 : :
16967 : : /**
16968 : : * Create indirect action, lock free,
16969 : : * (mutex should be acquired by caller).
16970 : : * Dispatcher for action type specific call.
16971 : : *
16972 : : * @param[in] dev
16973 : : * Pointer to the Ethernet device structure.
16974 : : * @param[in] conf
16975 : : * Shared action configuration.
16976 : : * @param[in] action
16977 : : * Action specification used to create indirect action.
16978 : : * @param[out] error
16979 : : * Perform verbose error reporting if not NULL. Initialized in case of
16980 : : * error only.
16981 : : *
16982 : : * @return
16983 : : * A valid shared action handle in case of success, NULL otherwise and
16984 : : * rte_errno is set.
16985 : : */
16986 : : struct rte_flow_action_handle *
16987 : 0 : flow_dv_action_create(struct rte_eth_dev *dev,
16988 : : const struct rte_flow_indir_action_conf *conf,
16989 : : const struct rte_flow_action *action,
16990 : : struct rte_flow_error *err)
16991 : : {
16992 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16993 : : uint32_t age_idx = 0;
16994 : : uint32_t idx = 0;
16995 : : uint32_t ret = 0;
16996 : :
16997 [ # # # # : 0 : switch (action->type) {
# ]
16998 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
16999 : 0 : ret = __flow_dv_action_rss_create(dev, conf, action->conf, err);
17000 : : idx = (MLX5_INDIRECT_ACTION_TYPE_RSS <<
17001 : : MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
17002 : 0 : break;
17003 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
17004 : 0 : age_idx = flow_dv_aso_age_alloc(dev, err);
17005 [ # # ]: 0 : if (!age_idx) {
17006 : 0 : ret = -rte_errno;
17007 : 0 : break;
17008 : : }
17009 : 0 : idx = (MLX5_INDIRECT_ACTION_TYPE_AGE <<
17010 : : MLX5_INDIRECT_ACTION_TYPE_OFFSET) | age_idx;
17011 : 0 : flow_dv_aso_age_params_init(dev, age_idx,
17012 : : ((const struct rte_flow_action_age *)
17013 : 0 : action->conf)->context ?
17014 : : ((const struct rte_flow_action_age *)
17015 : : action->conf)->context :
17016 : 0 : (void *)(uintptr_t)idx,
17017 : : ((const struct rte_flow_action_age *)
17018 [ # # ]: 0 : action->conf)->timeout);
17019 : : ret = age_idx;
17020 : 0 : break;
17021 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
17022 : 0 : ret = flow_dv_translate_create_counter(dev, NULL, NULL, NULL);
17023 : 0 : idx = (MLX5_INDIRECT_ACTION_TYPE_COUNT <<
17024 : : MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
17025 : 0 : break;
17026 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
17027 : 0 : ret = flow_dv_translate_create_conntrack(dev, action->conf,
17028 : : err);
17029 [ # # ]: 0 : if (!ret)
17030 : : break;
17031 : 0 : idx = MLX5_INDIRECT_ACT_CT_GEN_IDX(PORT_ID(priv), ret);
17032 : 0 : break;
17033 : 0 : default:
17034 : 0 : rte_flow_error_set(err, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
17035 : : NULL, "action type not supported");
17036 : : break;
17037 : : }
17038 [ # # ]: 0 : return ret ? (struct rte_flow_action_handle *)(uintptr_t)idx : NULL;
17039 : : }
17040 : :
17041 : : /**
17042 : : * Destroy the indirect action.
17043 : : * Release action related resources on the NIC and the memory.
17044 : : * Lock free, (mutex should be acquired by caller).
17045 : : * Dispatcher for action type specific call.
17046 : : *
17047 : : * @param[in] dev
17048 : : * Pointer to the Ethernet device structure.
17049 : : * @param[in] handle
17050 : : * The indirect action object handle to be removed.
17051 : : * @param[out] error
17052 : : * Perform verbose error reporting if not NULL. Initialized in case of
17053 : : * error only.
17054 : : *
17055 : : * @return
17056 : : * 0 on success, otherwise negative errno value.
17057 : : */
17058 : : int
17059 : 0 : flow_dv_action_destroy(struct rte_eth_dev *dev,
17060 : : struct rte_flow_action_handle *handle,
17061 : : struct rte_flow_error *error)
17062 : : {
17063 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
17064 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
17065 : 0 : uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
17066 : : struct mlx5_flow_counter *cnt;
17067 : : uint32_t no_flow_refcnt = 1;
17068 : : int ret;
17069 : :
17070 [ # # # # : 0 : switch (type) {
# ]
17071 : 0 : case MLX5_INDIRECT_ACTION_TYPE_RSS:
17072 : 0 : return __flow_dv_action_rss_release(dev, idx, error);
17073 : : case MLX5_INDIRECT_ACTION_TYPE_COUNT:
17074 : : cnt = flow_dv_counter_get_by_idx(dev, idx, NULL);
17075 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(&cnt->shared_info.refcnt,
17076 : : &no_flow_refcnt, 1,
17077 : : rte_memory_order_acquire,
17078 : : rte_memory_order_relaxed))
17079 : 0 : return rte_flow_error_set(error, EBUSY,
17080 : : RTE_FLOW_ERROR_TYPE_ACTION,
17081 : : NULL,
17082 : : "Indirect count action has references");
17083 : 0 : flow_dv_counter_free(dev, idx);
17084 : 0 : return 0;
17085 : 0 : case MLX5_INDIRECT_ACTION_TYPE_AGE:
17086 : 0 : ret = flow_dv_aso_age_release(dev, idx);
17087 [ # # ]: 0 : if (ret)
17088 : : /*
17089 : : * In this case, the last flow has a reference will
17090 : : * actually release the age action.
17091 : : */
17092 : 0 : DRV_LOG(DEBUG, "Indirect age action %" PRIu32 " was"
17093 : : " released with references %d.", idx, ret);
17094 : : return 0;
17095 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
17096 : 0 : ret = flow_dv_aso_ct_release(dev, idx, error);
17097 [ # # ]: 0 : if (ret < 0)
17098 : : return ret;
17099 [ # # ]: 0 : if (ret > 0)
17100 : 0 : DRV_LOG(DEBUG, "Connection tracking object %u still "
17101 : : "has references %d.", idx, ret);
17102 : : return 0;
17103 : 0 : default:
17104 : 0 : return rte_flow_error_set(error, ENOTSUP,
17105 : : RTE_FLOW_ERROR_TYPE_ACTION,
17106 : : NULL,
17107 : : "action type not supported");
17108 : : }
17109 : : }
17110 : :
17111 : : /**
17112 : : * Updates in place shared RSS action configuration.
17113 : : *
17114 : : * @param[in] dev
17115 : : * Pointer to the Ethernet device structure.
17116 : : * @param[in] idx
17117 : : * The shared RSS action object ID to be updated.
17118 : : * @param[in] action_conf
17119 : : * RSS action specification used to modify *shared_rss*.
17120 : : * @param[out] error
17121 : : * Perform verbose error reporting if not NULL. Initialized in case of
17122 : : * error only.
17123 : : *
17124 : : * @return
17125 : : * 0 on success, otherwise negative errno value.
17126 : : * @note: currently only support update of RSS queues.
17127 : : */
17128 : : static int
17129 : 0 : __flow_dv_action_rss_update(struct rte_eth_dev *dev, uint32_t idx,
17130 : : const struct rte_flow_action_rss *action_conf,
17131 : : struct rte_flow_error *error)
17132 : : {
17133 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17134 : : struct mlx5_shared_action_rss *shared_rss =
17135 : 0 : mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
17136 : : int ret = 0;
17137 : : void *queue = NULL;
17138 : : void *queue_i = NULL;
17139 : 0 : uint32_t queue_size = action_conf->queue_num * sizeof(uint16_t);
17140 : 0 : bool dev_started = !!dev->data->dev_started;
17141 : :
17142 [ # # ]: 0 : if (!shared_rss)
17143 : 0 : return rte_flow_error_set(error, EINVAL,
17144 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
17145 : : "invalid shared action to update");
17146 [ # # ]: 0 : if (priv->obj_ops.ind_table_modify == NULL)
17147 : 0 : return rte_flow_error_set(error, ENOTSUP,
17148 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
17149 : : "cannot modify indirection table");
17150 : 0 : queue = mlx5_malloc(MLX5_MEM_ZERO,
17151 : 0 : RTE_ALIGN_CEIL(queue_size, sizeof(void *)),
17152 : : 0, SOCKET_ID_ANY);
17153 [ # # ]: 0 : if (!queue)
17154 : 0 : return rte_flow_error_set(error, ENOMEM,
17155 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17156 : : NULL,
17157 : : "cannot allocate resource memory");
17158 : 0 : memcpy(queue, action_conf->queue, queue_size);
17159 : : MLX5_ASSERT(shared_rss->ind_tbl);
17160 : 0 : rte_spinlock_lock(&shared_rss->action_rss_sl);
17161 : 0 : queue_i = shared_rss->ind_tbl->queues;
17162 : 0 : ret = mlx5_ind_table_obj_modify(dev, shared_rss->ind_tbl,
17163 : 0 : queue, action_conf->queue_num,
17164 : : true /* standalone */,
17165 : : dev_started /* ref_new_qs */,
17166 : : dev_started /* deref_old_qs */);
17167 [ # # ]: 0 : if (ret) {
17168 : 0 : ret = rte_flow_error_set(error, rte_errno,
17169 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
17170 : : "cannot update indirection table");
17171 : : } else {
17172 : : /* Restore the queue to indirect table internal queue. */
17173 : : memcpy(queue_i, queue, queue_size);
17174 : 0 : shared_rss->ind_tbl->queues = queue_i;
17175 : 0 : shared_rss->origin.queue_num = action_conf->queue_num;
17176 : : }
17177 : 0 : mlx5_free(queue);
17178 : : rte_spinlock_unlock(&shared_rss->action_rss_sl);
17179 : 0 : return ret;
17180 : : }
17181 : :
17182 : : /*
17183 : : * Updates in place conntrack context or direction.
17184 : : * Context update should be synchronized.
17185 : : *
17186 : : * @param[in] dev
17187 : : * Pointer to the Ethernet device structure.
17188 : : * @param[in] idx
17189 : : * The conntrack object ID to be updated.
17190 : : * @param[in] update
17191 : : * Pointer to the structure of information to update.
17192 : : * @param[out] error
17193 : : * Perform verbose error reporting if not NULL. Initialized in case of
17194 : : * error only.
17195 : : *
17196 : : * @return
17197 : : * 0 on success, otherwise negative errno value.
17198 : : */
17199 : : static int
17200 : 0 : __flow_dv_action_ct_update(struct rte_eth_dev *dev, uint32_t idx,
17201 : : const struct rte_flow_modify_conntrack *update,
17202 : : struct rte_flow_error *error)
17203 : : {
17204 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17205 : : struct mlx5_aso_ct_action *ct;
17206 : : const struct rte_flow_action_conntrack *new_prf;
17207 : : int ret = 0;
17208 : 0 : uint16_t owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(idx);
17209 : : uint32_t dev_idx;
17210 : :
17211 [ # # ]: 0 : if (PORT_ID(priv) != owner)
17212 : 0 : return rte_flow_error_set(error, EACCES,
17213 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17214 : : NULL,
17215 : : "CT object owned by another port");
17216 : 0 : dev_idx = MLX5_INDIRECT_ACT_CT_GET_IDX(idx);
17217 : 0 : ct = flow_aso_ct_get_by_dev_idx(dev, dev_idx);
17218 [ # # ]: 0 : if (!ct->refcnt)
17219 : 0 : return rte_flow_error_set(error, ENOMEM,
17220 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17221 : : NULL,
17222 : : "CT object is inactive");
17223 : 0 : new_prf = &update->new_ct;
17224 [ # # ]: 0 : if (update->direction)
17225 : 0 : ct->is_original = !!new_prf->is_original_dir;
17226 [ # # ]: 0 : if (update->state) {
17227 : : /* Only validate the profile when it needs to be updated. */
17228 : 0 : ret = mlx5_validate_action_ct(dev, new_prf, error);
17229 [ # # ]: 0 : if (ret)
17230 : : return ret;
17231 : 0 : ret = mlx5_aso_ct_update_by_wqe(priv->sh, MLX5_HW_INV_QUEUE,
17232 : : ct, new_prf, NULL, true);
17233 [ # # ]: 0 : if (ret)
17234 : 0 : return rte_flow_error_set(error, EIO,
17235 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17236 : : NULL,
17237 : : "Failed to send CT context update WQE");
17238 : : /* Block until ready or a failure, default is asynchronous. */
17239 : 0 : ret = mlx5_aso_ct_available(priv->sh, MLX5_HW_INV_QUEUE, ct);
17240 [ # # ]: 0 : if (ret)
17241 : 0 : rte_flow_error_set(error, rte_errno,
17242 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17243 : : NULL,
17244 : : "Timeout to get the CT update");
17245 : : }
17246 : : return ret;
17247 : : }
17248 : :
17249 : : /**
17250 : : * Updates in place shared action configuration, lock free,
17251 : : * (mutex should be acquired by caller).
17252 : : *
17253 : : * @param[in] dev
17254 : : * Pointer to the Ethernet device structure.
17255 : : * @param[in] handle
17256 : : * The indirect action object handle to be updated.
17257 : : * @param[in] update
17258 : : * Action specification used to modify the action pointed by *handle*.
17259 : : * *update* could be of same type with the action pointed by the *handle*
17260 : : * handle argument, or some other structures like a wrapper, depending on
17261 : : * the indirect action type.
17262 : : * @param[out] error
17263 : : * Perform verbose error reporting if not NULL. Initialized in case of
17264 : : * error only.
17265 : : *
17266 : : * @return
17267 : : * 0 on success, otherwise negative errno value.
17268 : : */
17269 : : int
17270 : 0 : flow_dv_action_update(struct rte_eth_dev *dev,
17271 : : struct rte_flow_action_handle *handle,
17272 : : const void *update,
17273 : : struct rte_flow_error *err)
17274 : : {
17275 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
17276 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
17277 : 0 : uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
17278 : : const void *action_conf;
17279 : :
17280 [ # # # ]: 0 : switch (type) {
17281 : 0 : case MLX5_INDIRECT_ACTION_TYPE_RSS:
17282 : 0 : action_conf = ((const struct rte_flow_action *)update)->conf;
17283 : 0 : return __flow_dv_action_rss_update(dev, idx, action_conf, err);
17284 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
17285 : 0 : return __flow_dv_action_ct_update(dev, idx, update, err);
17286 : 0 : default:
17287 : 0 : return rte_flow_error_set(err, ENOTSUP,
17288 : : RTE_FLOW_ERROR_TYPE_ACTION,
17289 : : NULL,
17290 : : "action type update not supported");
17291 : : }
17292 : : }
17293 : :
17294 : : /**
17295 : : * Destroy the meter sub policy table rules.
17296 : : * Lock free, (mutex should be acquired by caller).
17297 : : *
17298 : : * @param[in] dev
17299 : : * Pointer to Ethernet device.
17300 : : * @param[in] sub_policy
17301 : : * Pointer to meter sub policy table.
17302 : : */
17303 : : static void
17304 : 0 : __flow_dv_destroy_sub_policy_rules(struct rte_eth_dev *dev,
17305 : : struct mlx5_flow_meter_sub_policy *sub_policy)
17306 : : {
17307 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17308 : : struct mlx5_flow_tbl_data_entry *tbl;
17309 : 0 : struct mlx5_flow_meter_policy *policy = sub_policy->main_policy;
17310 : : struct mlx5_flow_meter_info *next_fm;
17311 : : struct mlx5_sub_policy_color_rule *color_rule;
17312 : : void *tmp;
17313 : : uint32_t i;
17314 : :
17315 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
17316 : : next_fm = NULL;
17317 [ # # ]: 0 : if (i <= RTE_COLOR_YELLOW && policy &&
17318 [ # # ]: 0 : policy->act_cnt[i].fate_action == MLX5_FLOW_FATE_MTR)
17319 : 0 : next_fm = mlx5_flow_meter_find(priv,
17320 : : policy->act_cnt[i].next_mtr_id, NULL);
17321 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(color_rule, &sub_policy->color_rules[i],
17322 : : next_port, tmp) {
17323 : 0 : claim_zero(mlx5_flow_os_destroy_flow(color_rule->rule));
17324 : 0 : tbl = container_of(color_rule->matcher->tbl,
17325 : : typeof(*tbl), tbl);
17326 : 0 : mlx5_list_unregister(tbl->matchers,
17327 : : &color_rule->matcher->entry);
17328 [ # # ]: 0 : TAILQ_REMOVE(&sub_policy->color_rules[i],
17329 : : color_rule, next_port);
17330 : 0 : mlx5_free(color_rule);
17331 [ # # ]: 0 : if (next_fm)
17332 : 0 : mlx5_flow_meter_detach(priv, next_fm);
17333 : : }
17334 : : }
17335 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
17336 [ # # ]: 0 : if (sub_policy->rix_hrxq[i]) {
17337 [ # # # # ]: 0 : if (policy && !policy->is_hierarchy)
17338 : 0 : mlx5_hrxq_release(dev, sub_policy->rix_hrxq[i]);
17339 : 0 : sub_policy->rix_hrxq[i] = 0;
17340 : : }
17341 [ # # ]: 0 : if (sub_policy->jump_tbl[i]) {
17342 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev),
17343 : : sub_policy->jump_tbl[i]);
17344 : 0 : sub_policy->jump_tbl[i] = NULL;
17345 : : }
17346 : : }
17347 [ # # ]: 0 : if (sub_policy->tbl_rsc) {
17348 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev),
17349 : : sub_policy->tbl_rsc);
17350 : 0 : sub_policy->tbl_rsc = NULL;
17351 : : }
17352 : 0 : }
17353 : :
17354 : : /**
17355 : : * Destroy policy rules, lock free,
17356 : : * (mutex should be acquired by caller).
17357 : : * Dispatcher for action type specific call.
17358 : : *
17359 : : * @param[in] dev
17360 : : * Pointer to the Ethernet device structure.
17361 : : * @param[in] mtr_policy
17362 : : * Meter policy struct.
17363 : : */
17364 : : static void
17365 : 0 : flow_dv_destroy_policy_rules(struct rte_eth_dev *dev,
17366 : : struct mlx5_flow_meter_policy *mtr_policy)
17367 : : {
17368 : : uint32_t i, j;
17369 : : struct mlx5_flow_meter_sub_policy *sub_policy;
17370 : : uint16_t sub_policy_num;
17371 : :
17372 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
17373 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
17374 : 0 : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
17375 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
17376 [ # # ]: 0 : for (j = 0; j < sub_policy_num; j++) {
17377 : 0 : sub_policy = mtr_policy->sub_policys[i][j];
17378 [ # # ]: 0 : if (sub_policy)
17379 : 0 : __flow_dv_destroy_sub_policy_rules(dev,
17380 : : sub_policy);
17381 : : }
17382 : : }
17383 : 0 : }
17384 : :
17385 : : /**
17386 : : * Destroy policy action, lock free,
17387 : : * (mutex should be acquired by caller).
17388 : : * Dispatcher for action type specific call.
17389 : : *
17390 : : * @param[in] dev
17391 : : * Pointer to the Ethernet device structure.
17392 : : * @param[in] mtr_policy
17393 : : * Meter policy struct.
17394 : : */
17395 : : static void
17396 : 0 : flow_dv_destroy_mtr_policy_acts(struct rte_eth_dev *dev,
17397 : : struct mlx5_flow_meter_policy *mtr_policy)
17398 : : {
17399 : : struct rte_flow_action *rss_action;
17400 : : struct mlx5_flow_handle dev_handle;
17401 : : uint32_t i, j;
17402 : :
17403 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
17404 [ # # ]: 0 : if (mtr_policy->act_cnt[i].rix_mark) {
17405 : 0 : flow_dv_tag_release(dev,
17406 : : mtr_policy->act_cnt[i].rix_mark);
17407 : 0 : mtr_policy->act_cnt[i].rix_mark = 0;
17408 : : }
17409 [ # # ]: 0 : if (mtr_policy->act_cnt[i].modify_hdr) {
17410 : : dev_handle.dvh.modify_hdr =
17411 : : mtr_policy->act_cnt[i].modify_hdr;
17412 : : flow_dv_modify_hdr_resource_release(dev, &dev_handle);
17413 : : }
17414 [ # # # # ]: 0 : switch (mtr_policy->act_cnt[i].fate_action) {
17415 : 0 : case MLX5_FLOW_FATE_SHARED_RSS:
17416 : 0 : rss_action = mtr_policy->act_cnt[i].rss;
17417 : 0 : mlx5_free(rss_action);
17418 : 0 : break;
17419 : 0 : case MLX5_FLOW_FATE_PORT_ID:
17420 [ # # ]: 0 : if (mtr_policy->act_cnt[i].rix_port_id_action) {
17421 : 0 : flow_dv_port_id_action_resource_release(dev,
17422 : : mtr_policy->act_cnt[i].rix_port_id_action);
17423 : 0 : mtr_policy->act_cnt[i].rix_port_id_action = 0;
17424 : : }
17425 : : break;
17426 : : case MLX5_FLOW_FATE_DROP:
17427 : : case MLX5_FLOW_FATE_JUMP:
17428 [ # # ]: 0 : for (j = 0; j < MLX5_MTR_DOMAIN_MAX; j++)
17429 : 0 : mtr_policy->act_cnt[i].dr_jump_action[j] =
17430 : : NULL;
17431 : : break;
17432 : : default:
17433 : : /*Queue action do nothing*/
17434 : : break;
17435 : : }
17436 : : }
17437 [ # # ]: 0 : for (j = 0; j < MLX5_MTR_DOMAIN_MAX; j++)
17438 : 0 : mtr_policy->dr_drop_action[j] = NULL;
17439 : 0 : }
17440 : :
17441 : : /**
17442 : : * Create yellow action for color aware meter.
17443 : : *
17444 : : * @param[in] dev
17445 : : * Pointer to the Ethernet device structure.
17446 : : * @param[in] fm
17447 : : * Meter information table.
17448 : : * @param[out] error
17449 : : * Perform verbose error reporting if not NULL. Initialized in case of
17450 : : * error only.
17451 : : *
17452 : : * @return
17453 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
17454 : : */
17455 : : static int
17456 : 0 : __flow_dv_create_mtr_yellow_action(struct rte_eth_dev *dev,
17457 : : struct mlx5_flow_meter_info *fm,
17458 : : struct rte_mtr_error *error)
17459 : : {
17460 : : #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
17461 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17462 : : struct rte_flow_error flow_err;
17463 : : struct mlx5_aso_mtr *aso_mtr;
17464 : : struct mlx5_aso_mtr_pool *pool;
17465 : : uint8_t reg_id;
17466 : :
17467 : 0 : aso_mtr = container_of(fm, struct mlx5_aso_mtr, fm);
17468 : 0 : pool = container_of(aso_mtr, struct mlx5_aso_mtr_pool, mtrs[aso_mtr->offset]);
17469 : 0 : reg_id = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &flow_err);
17470 : 0 : fm->meter_action_y =
17471 : 0 : mlx5_glue->dv_create_flow_action_aso(priv->sh->rx_domain,
17472 : 0 : pool->devx_obj->obj,
17473 : : aso_mtr->offset,
17474 : : (1 << MLX5_FLOW_COLOR_YELLOW),
17475 : 0 : reg_id - REG_C_0);
17476 : : #else
17477 : : RTE_SET_USED(dev);
17478 : : #endif
17479 [ # # ]: 0 : if (!fm->meter_action_y) {
17480 : 0 : return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
17481 : : "Fail to create yellow meter action.");
17482 : : }
17483 : : return 0;
17484 : : }
17485 : :
17486 : : /**
17487 : : * Create policy action per domain, lock free,
17488 : : * (mutex should be acquired by caller).
17489 : : * Dispatcher for action type specific call.
17490 : : *
17491 : : * @param[in] dev
17492 : : * Pointer to the Ethernet device structure.
17493 : : * @param[in] mtr_policy
17494 : : * Meter policy struct.
17495 : : * @param[in] action
17496 : : * Action specification used to create meter actions.
17497 : : * @param[in] attr
17498 : : * Pointer to the flow attributes.
17499 : : * @param[out] error
17500 : : * Perform verbose error reporting if not NULL. Initialized in case of
17501 : : * error only.
17502 : : *
17503 : : * @return
17504 : : * 0 on success, otherwise negative errno value.
17505 : : */
17506 : : static int
17507 : 0 : __flow_dv_create_domain_policy_acts(struct rte_eth_dev *dev,
17508 : : struct mlx5_flow_meter_policy *mtr_policy,
17509 : : const struct rte_flow_action *actions[RTE_COLORS],
17510 : : struct rte_flow_attr *attr,
17511 : : enum mlx5_meter_domain domain,
17512 : : struct rte_mtr_error *error)
17513 : : {
17514 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17515 : : struct rte_flow_error flow_err;
17516 : : const struct rte_flow_action *act;
17517 : : uint64_t action_flags;
17518 : : struct mlx5_flow_handle dh;
17519 : : struct mlx5_flow dev_flow;
17520 : : struct mlx5_flow_dv_port_id_action_resource port_id_action;
17521 : : int i, ret;
17522 : : uint8_t egress, transfer;
17523 : : struct mlx5_meter_policy_action_container *act_cnt = NULL;
17524 : : union {
17525 : : struct mlx5_flow_dv_modify_hdr_resource res;
17526 : : uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
17527 : : sizeof(struct mlx5_modification_cmd) *
17528 : : (MLX5_MAX_MODIFY_NUM + 1)];
17529 : : } mhdr_dummy;
17530 : : struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
17531 : :
17532 : 0 : egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
17533 [ # # ]: 0 : transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
17534 : : memset(&dh, 0, sizeof(struct mlx5_flow_handle));
17535 : : memset(&dev_flow, 0, sizeof(struct mlx5_flow));
17536 : : memset(&port_id_action, 0,
17537 : : sizeof(struct mlx5_flow_dv_port_id_action_resource));
17538 : : memset(mhdr_res, 0, sizeof(*mhdr_res));
17539 [ # # ]: 0 : mhdr_res->ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
17540 : : (egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
17541 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX);
17542 : 0 : dev_flow.handle = &dh;
17543 : 0 : dev_flow.dv.port_id_action = &port_id_action;
17544 : 0 : dev_flow.external = true;
17545 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
17546 [ # # ]: 0 : if (i < MLX5_MTR_RTE_COLORS)
17547 : 0 : act_cnt = &mtr_policy->act_cnt[i];
17548 : : /* Skip the color policy actions creation. */
17549 [ # # # # : 0 : if ((i == RTE_COLOR_YELLOW && mtr_policy->skip_y) ||
# # ]
17550 [ # # ]: 0 : (i == RTE_COLOR_GREEN && mtr_policy->skip_g))
17551 : 0 : continue;
17552 : : action_flags = 0;
17553 : 0 : for (act = actions[i];
17554 [ # # # # ]: 0 : act && act->type != RTE_FLOW_ACTION_TYPE_END; act++) {
17555 [ # # # # : 0 : switch (act->type) {
# # # # #
# ]
17556 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
17557 : : {
17558 : : uint32_t tag_be = mlx5_flow_mark_set
17559 : : (((const struct rte_flow_action_mark *)
17560 [ # # ]: 0 : (act->conf))->id);
17561 : :
17562 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17563 : 0 : return -rte_mtr_error_set(error,
17564 : : ENOTSUP,
17565 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17566 : : NULL,
17567 : : "cannot create policy "
17568 : : "mark action for this color");
17569 [ # # ]: 0 : if (flow_dv_tag_resource_register(dev, tag_be,
17570 : : &dev_flow, &flow_err))
17571 : 0 : return -rte_mtr_error_set(error,
17572 : : ENOTSUP,
17573 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17574 : : NULL,
17575 : : "cannot setup policy mark action");
17576 : : MLX5_ASSERT(dev_flow.dv.tag_resource);
17577 : 0 : act_cnt->rix_mark =
17578 : 0 : dev_flow.handle->dvh.rix_tag;
17579 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK;
17580 : 0 : mtr_policy->mark = 1;
17581 : 0 : break;
17582 : : }
17583 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TAG:
17584 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17585 : 0 : return -rte_mtr_error_set(error,
17586 : : ENOTSUP,
17587 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17588 : : NULL,
17589 : : "cannot create policy "
17590 : : "set tag action for this color");
17591 [ # # ]: 0 : if (flow_dv_convert_action_set_tag
17592 : : (dev, mhdr_res,
17593 : : (const struct rte_flow_action_set_tag *)
17594 : 0 : act->conf, &flow_err))
17595 : 0 : return -rte_mtr_error_set(error,
17596 : : ENOTSUP,
17597 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17598 : : NULL, "cannot convert policy "
17599 : : "set tag action");
17600 [ # # ]: 0 : if (!mhdr_res->actions_num)
17601 : 0 : return -rte_mtr_error_set(error,
17602 : : ENOTSUP,
17603 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17604 : : NULL, "cannot find policy "
17605 : : "set tag action");
17606 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
17607 : 0 : break;
17608 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
17609 : : {
17610 : 0 : struct mlx5_flow_mtr_mng *mtrmng =
17611 : 0 : priv->sh->mtrmng;
17612 : : struct mlx5_flow_tbl_data_entry *tbl_data;
17613 : :
17614 : : /*
17615 : : * Create the drop table with
17616 : : * METER DROP level.
17617 : : */
17618 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
17619 : 0 : mtrmng->drop_tbl[domain] =
17620 : 0 : flow_dv_tbl_resource_get(dev,
17621 : : MLX5_FLOW_TABLE_LEVEL_METER,
17622 : : egress, transfer, false, NULL, 0,
17623 : : 0, MLX5_MTR_TABLE_ID_DROP, &flow_err);
17624 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain])
17625 : 0 : return -rte_mtr_error_set
17626 : : (error, ENOTSUP,
17627 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17628 : : NULL,
17629 : : "Failed to create meter drop table");
17630 : : }
17631 : 0 : tbl_data = container_of
17632 : : (mtrmng->drop_tbl[domain],
17633 : : struct mlx5_flow_tbl_data_entry, tbl);
17634 [ # # ]: 0 : if (i < MLX5_MTR_RTE_COLORS) {
17635 : 0 : act_cnt->dr_jump_action[domain] =
17636 : 0 : tbl_data->jump.action;
17637 : 0 : act_cnt->fate_action =
17638 : : MLX5_FLOW_FATE_DROP;
17639 : : }
17640 [ # # ]: 0 : if (i == RTE_COLOR_RED)
17641 : 0 : mtr_policy->dr_drop_action[domain] =
17642 : 0 : tbl_data->jump.action;
17643 : 0 : action_flags |= MLX5_FLOW_ACTION_DROP;
17644 : 0 : break;
17645 : : }
17646 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
17647 : : {
17648 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17649 : 0 : return -rte_mtr_error_set(error,
17650 : : ENOTSUP,
17651 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17652 : : NULL, "cannot create policy "
17653 : : "fate queue for this color");
17654 : 0 : act_cnt->queue =
17655 : : ((const struct rte_flow_action_queue *)
17656 : 0 : (act->conf))->index;
17657 : 0 : act_cnt->fate_action =
17658 : : MLX5_FLOW_FATE_QUEUE;
17659 : 0 : dev_flow.handle->fate_action =
17660 : : MLX5_FLOW_FATE_QUEUE;
17661 : 0 : mtr_policy->is_queue = 1;
17662 : 0 : action_flags |= MLX5_FLOW_ACTION_QUEUE;
17663 : 0 : break;
17664 : : }
17665 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
17666 : : {
17667 : : int rss_size;
17668 : :
17669 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17670 : 0 : return -rte_mtr_error_set(error,
17671 : : ENOTSUP,
17672 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17673 : : NULL,
17674 : : "cannot create policy "
17675 : : "rss action for this color");
17676 : : /*
17677 : : * Save RSS conf into policy struct
17678 : : * for translate stage.
17679 : : */
17680 : 0 : rss_size = (int)rte_flow_conv
17681 : : (RTE_FLOW_CONV_OP_ACTION,
17682 : : NULL, 0, act, &flow_err);
17683 [ # # ]: 0 : if (rss_size <= 0)
17684 : 0 : return -rte_mtr_error_set(error,
17685 : : ENOTSUP,
17686 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17687 : : NULL, "Get the wrong "
17688 : : "rss action struct size");
17689 : 0 : act_cnt->rss = mlx5_malloc(MLX5_MEM_ZERO,
17690 : : rss_size, 0, SOCKET_ID_ANY);
17691 [ # # ]: 0 : if (!act_cnt->rss)
17692 : 0 : return -rte_mtr_error_set(error,
17693 : : ENOTSUP,
17694 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17695 : : NULL,
17696 : : "Fail to malloc rss action memory");
17697 : 0 : ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTION,
17698 : : act_cnt->rss, rss_size,
17699 : : act, &flow_err);
17700 [ # # ]: 0 : if (ret < 0)
17701 : 0 : return -rte_mtr_error_set(error,
17702 : : ENOTSUP,
17703 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17704 : : NULL, "Fail to save "
17705 : : "rss action into policy struct");
17706 : 0 : act_cnt->fate_action =
17707 : : MLX5_FLOW_FATE_SHARED_RSS;
17708 : 0 : action_flags |= MLX5_FLOW_ACTION_RSS;
17709 : 0 : break;
17710 : : }
17711 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
17712 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
17713 : : {
17714 : : struct mlx5_flow_dv_port_id_action_resource
17715 : : port_id_resource;
17716 : 0 : uint32_t port_id = 0;
17717 : :
17718 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17719 : 0 : return -rte_mtr_error_set(error,
17720 : : ENOTSUP,
17721 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17722 : : NULL, "cannot create policy "
17723 : : "port action for this color");
17724 : : memset(&port_id_resource, 0,
17725 : : sizeof(port_id_resource));
17726 [ # # ]: 0 : if (flow_dv_translate_action_port_id(dev, act,
17727 : : &port_id, &flow_err))
17728 : 0 : return -rte_mtr_error_set(error,
17729 : : ENOTSUP,
17730 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17731 : : NULL, "cannot translate "
17732 : : "policy port action");
17733 : 0 : port_id_resource.port_id = port_id;
17734 [ # # ]: 0 : if (flow_dv_port_id_action_resource_register
17735 : : (dev, &port_id_resource,
17736 : : &dev_flow, &flow_err))
17737 : 0 : return -rte_mtr_error_set(error,
17738 : : ENOTSUP,
17739 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17740 : : NULL, "cannot setup "
17741 : : "policy port action");
17742 : 0 : act_cnt->rix_port_id_action =
17743 : 0 : dev_flow.handle->rix_port_id_action;
17744 : 0 : act_cnt->fate_action =
17745 : : MLX5_FLOW_FATE_PORT_ID;
17746 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_ID;
17747 : 0 : break;
17748 : : }
17749 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
17750 : : {
17751 : : uint32_t jump_group = 0;
17752 : 0 : uint32_t table = 0;
17753 : : struct mlx5_flow_tbl_data_entry *tbl_data;
17754 : 0 : struct flow_grp_info grp_info = {
17755 : 0 : .external = !!dev_flow.external,
17756 : : .transfer = !!transfer,
17757 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
17758 : : .std_tbl_fix = 0,
17759 : 0 : .skip_scale = dev_flow.skip_scale &
17760 : : (1 << MLX5_SCALE_FLOW_GROUP_BIT),
17761 : : };
17762 : 0 : struct mlx5_flow_meter_sub_policy *sub_policy =
17763 : 0 : mtr_policy->sub_policys[domain][0];
17764 : :
17765 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17766 : 0 : return -rte_mtr_error_set(error,
17767 : : ENOTSUP,
17768 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17769 : : NULL,
17770 : : "cannot create policy "
17771 : : "jump action for this color");
17772 : 0 : jump_group =
17773 : : ((const struct rte_flow_action_jump *)
17774 : 0 : act->conf)->group;
17775 [ # # ]: 0 : if (mlx5_flow_group_to_table(dev, NULL,
17776 : : jump_group,
17777 : : &table,
17778 : : &grp_info, &flow_err))
17779 : 0 : return -rte_mtr_error_set(error,
17780 : : ENOTSUP,
17781 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17782 : : NULL, "cannot setup "
17783 : : "policy jump action");
17784 : 0 : sub_policy->jump_tbl[i] =
17785 : 0 : flow_dv_tbl_resource_get(dev,
17786 : : table, egress,
17787 : : transfer,
17788 : : !!dev_flow.external,
17789 : : NULL, jump_group, 0,
17790 : : 0, &flow_err);
17791 : : if
17792 [ # # ]: 0 : (!sub_policy->jump_tbl[i])
17793 : 0 : return -rte_mtr_error_set(error,
17794 : : ENOTSUP,
17795 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17796 : : NULL, "cannot create jump action.");
17797 : 0 : tbl_data = container_of
17798 : : (sub_policy->jump_tbl[i],
17799 : : struct mlx5_flow_tbl_data_entry, tbl);
17800 : 0 : act_cnt->dr_jump_action[domain] =
17801 : 0 : tbl_data->jump.action;
17802 : 0 : act_cnt->fate_action =
17803 : : MLX5_FLOW_FATE_JUMP;
17804 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP;
17805 : 0 : break;
17806 : : }
17807 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
17808 : : {
17809 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17810 : 0 : return -rte_mtr_error_set(error,
17811 : : ENOTSUP,
17812 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17813 : : NULL,
17814 : : "cannot create policy modify field for this color");
17815 [ # # ]: 0 : if (flow_dv_convert_action_modify_field
17816 : : (dev, mhdr_res, act, attr, &flow_err))
17817 : 0 : return -rte_mtr_error_set(error,
17818 : : ENOTSUP,
17819 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17820 : : NULL, "cannot setup policy modify field action");
17821 [ # # ]: 0 : if (!mhdr_res->actions_num)
17822 : 0 : return -rte_mtr_error_set(error,
17823 : : ENOTSUP,
17824 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17825 : : NULL, "cannot find policy modify field action");
17826 : 0 : action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
17827 : 0 : break;
17828 : : }
17829 : : /*
17830 : : * No need to check meter hierarchy for R colors
17831 : : * here since it is done in the validation stage.
17832 : : */
17833 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
17834 : : {
17835 : : const struct rte_flow_action_meter *mtr;
17836 : : struct mlx5_flow_meter_info *next_fm;
17837 : : struct mlx5_flow_meter_policy *next_policy;
17838 : : struct rte_flow_action tag_action;
17839 : : struct mlx5_rte_flow_action_set_tag set_tag;
17840 : 0 : uint32_t next_mtr_idx = 0;
17841 : :
17842 : 0 : mtr = act->conf;
17843 : 0 : next_fm = mlx5_flow_meter_find(priv,
17844 : 0 : mtr->mtr_id,
17845 : : &next_mtr_idx);
17846 [ # # ]: 0 : if (!next_fm)
17847 : 0 : return -rte_mtr_error_set(error, EINVAL,
17848 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
17849 : : "Fail to find next meter.");
17850 [ # # ]: 0 : if (next_fm->def_policy)
17851 : 0 : return -rte_mtr_error_set(error, EINVAL,
17852 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
17853 : : "Hierarchy only supports termination meter.");
17854 : 0 : next_policy = mlx5_flow_meter_policy_find(dev,
17855 : : next_fm->policy_id, NULL);
17856 : : MLX5_ASSERT(next_policy);
17857 [ # # ]: 0 : if (next_fm->drop_cnt) {
17858 : 0 : set_tag.id =
17859 : 0 : (enum modify_reg)
17860 : 0 : mlx5_flow_get_reg_id(dev,
17861 : : MLX5_MTR_ID,
17862 : : 0,
17863 : : (struct rte_flow_error *)error);
17864 : 0 : set_tag.offset = (priv->mtr_reg_share ?
17865 : 0 : MLX5_MTR_COLOR_BITS : 0);
17866 [ # # ]: 0 : set_tag.length = (priv->mtr_reg_share ?
17867 : : MLX5_MTR_IDLE_BITS_IN_COLOR_REG :
17868 : : MLX5_REG_BITS);
17869 : 0 : set_tag.data = next_mtr_idx;
17870 : 0 : tag_action.type =
17871 : : (enum rte_flow_action_type)
17872 : : MLX5_RTE_FLOW_ACTION_TYPE_TAG;
17873 : 0 : tag_action.conf = &set_tag;
17874 [ # # ]: 0 : if (flow_dv_convert_action_set_reg
17875 : : (mhdr_res, &tag_action,
17876 : : (struct rte_flow_error *)error))
17877 : 0 : return -rte_errno;
17878 : 0 : action_flags |=
17879 : : MLX5_FLOW_ACTION_SET_TAG;
17880 : : }
17881 [ # # # # ]: 0 : if (i == RTE_COLOR_YELLOW && next_fm->color_aware &&
17882 [ # # ]: 0 : !next_fm->meter_action_y)
17883 [ # # ]: 0 : if (__flow_dv_create_mtr_yellow_action(dev, next_fm, error))
17884 : 0 : return -rte_errno;
17885 : 0 : act_cnt->fate_action = MLX5_FLOW_FATE_MTR;
17886 : 0 : act_cnt->next_mtr_id = next_fm->meter_id;
17887 : 0 : act_cnt->next_sub_policy = NULL;
17888 : 0 : mtr_policy->is_hierarchy = 1;
17889 [ # # ]: 0 : if (next_policy->mark)
17890 : 0 : mtr_policy->mark = 1;
17891 : 0 : mtr_policy->hierarchy_match_port =
17892 : 0 : next_policy->hierarchy_match_port;
17893 : 0 : action_flags |=
17894 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
17895 : 0 : break;
17896 : : }
17897 : : default:
17898 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
17899 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17900 : : NULL, "action type not supported");
17901 : : }
17902 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_SET_TAG) ||
17903 : : (action_flags & MLX5_FLOW_ACTION_MODIFY_FIELD)) {
17904 : : /* create modify action if needed. */
17905 : 0 : dev_flow.dv.group = 1;
17906 [ # # ]: 0 : if (flow_dv_modify_hdr_resource_register
17907 : : (dev, mhdr_res, &dev_flow, &flow_err))
17908 : 0 : return -rte_mtr_error_set(error,
17909 : : ENOTSUP,
17910 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17911 : : NULL, "cannot register policy set tag/modify field action");
17912 : 0 : act_cnt->modify_hdr =
17913 : 0 : dev_flow.handle->dvh.modify_hdr;
17914 : : }
17915 : : }
17916 : : }
17917 : : return 0;
17918 : : }
17919 : :
17920 : : /**
17921 : : * Create policy action per domain, lock free,
17922 : : * (mutex should be acquired by caller).
17923 : : * Dispatcher for action type specific call.
17924 : : *
17925 : : * @param[in] dev
17926 : : * Pointer to the Ethernet device structure.
17927 : : * @param[in] mtr_policy
17928 : : * Meter policy struct.
17929 : : * @param[in] action
17930 : : * Action specification used to create meter actions.
17931 : : * @param[in] attr
17932 : : * Pointer to the flow attributes.
17933 : : * @param[out] error
17934 : : * Perform verbose error reporting if not NULL. Initialized in case of
17935 : : * error only.
17936 : : *
17937 : : * @return
17938 : : * 0 on success, otherwise negative errno value.
17939 : : */
17940 : : static int
17941 : 0 : flow_dv_create_mtr_policy_acts(struct rte_eth_dev *dev,
17942 : : struct mlx5_flow_meter_policy *mtr_policy,
17943 : : const struct rte_flow_action *actions[RTE_COLORS],
17944 : : struct rte_flow_attr *attr,
17945 : : struct rte_mtr_error *error)
17946 : : {
17947 : : int ret, i;
17948 : : uint16_t sub_policy_num;
17949 : :
17950 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
17951 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
17952 : 0 : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
17953 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
17954 [ # # ]: 0 : if (sub_policy_num) {
17955 : 0 : ret = __flow_dv_create_domain_policy_acts(dev,
17956 : : mtr_policy, actions, attr,
17957 : : (enum mlx5_meter_domain)i, error);
17958 : : /* Cleaning resource is done in the caller level. */
17959 [ # # ]: 0 : if (ret)
17960 : 0 : return ret;
17961 : : }
17962 : : }
17963 : : return 0;
17964 : : }
17965 : :
17966 : : /**
17967 : : * Query a DV flow rule for its statistics via DevX.
17968 : : *
17969 : : * @param[in] dev
17970 : : * Pointer to Ethernet device.
17971 : : * @param[in] cnt_idx
17972 : : * Index to the flow counter.
17973 : : * @param[out] data
17974 : : * Data retrieved by the query.
17975 : : * @param[out] error
17976 : : * Perform verbose error reporting if not NULL.
17977 : : *
17978 : : * @return
17979 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
17980 : : */
17981 : : static int
17982 : 0 : flow_dv_query_count(struct rte_eth_dev *dev, uint32_t cnt_idx, void *data,
17983 : : struct rte_flow_error *error)
17984 : : {
17985 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17986 : : struct rte_flow_query_count *qc = data;
17987 : :
17988 [ # # ]: 0 : if (!priv->sh->cdev->config.devx)
17989 : 0 : return rte_flow_error_set(error, ENOTSUP,
17990 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17991 : : NULL,
17992 : : "counters are not supported");
17993 [ # # ]: 0 : if (cnt_idx) {
17994 : : uint64_t pkts, bytes;
17995 : : struct mlx5_flow_counter *cnt;
17996 : 0 : int err = _flow_dv_query_count(dev, cnt_idx, &pkts, &bytes);
17997 : :
17998 [ # # ]: 0 : if (err)
17999 : 0 : return rte_flow_error_set(error, -err,
18000 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18001 : : NULL, "cannot read counters");
18002 : : cnt = flow_dv_counter_get_by_idx(dev, cnt_idx, NULL);
18003 : 0 : qc->hits_set = 1;
18004 : 0 : qc->bytes_set = 1;
18005 : 0 : qc->hits = pkts - cnt->hits;
18006 : 0 : qc->bytes = bytes - cnt->bytes;
18007 [ # # ]: 0 : if (qc->reset) {
18008 : 0 : cnt->hits = pkts;
18009 : 0 : cnt->bytes = bytes;
18010 : : }
18011 : 0 : return 0;
18012 : : }
18013 : 0 : return rte_flow_error_set(error, EINVAL,
18014 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18015 : : NULL,
18016 : : "counters are not available");
18017 : : }
18018 : :
18019 : : int
18020 : 0 : flow_dv_action_query(struct rte_eth_dev *dev,
18021 : : const struct rte_flow_action_handle *handle, void *data,
18022 : : struct rte_flow_error *error)
18023 : : {
18024 : : struct mlx5_age_param *age_param;
18025 : : struct rte_flow_query_age *resp;
18026 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
18027 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
18028 : 0 : uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
18029 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18030 : : struct mlx5_aso_ct_action *ct;
18031 : : uint16_t owner;
18032 : : uint32_t dev_idx;
18033 : :
18034 [ # # # # ]: 0 : switch (type) {
18035 : 0 : case MLX5_INDIRECT_ACTION_TYPE_AGE:
18036 : 0 : age_param = &flow_aso_age_get_by_idx(dev, idx)->age_params;
18037 : : resp = data;
18038 : 0 : resp->aged = rte_atomic_load_explicit(&age_param->state,
18039 : : rte_memory_order_relaxed) == AGE_TMOUT ?
18040 : 0 : 1 : 0;
18041 : 0 : resp->sec_since_last_hit_valid = !resp->aged;
18042 [ # # ]: 0 : if (resp->sec_since_last_hit_valid)
18043 : 0 : resp->sec_since_last_hit = rte_atomic_load_explicit
18044 : : (&age_param->sec_since_last_hit, rte_memory_order_relaxed);
18045 : : return 0;
18046 : 0 : case MLX5_INDIRECT_ACTION_TYPE_COUNT:
18047 : 0 : return flow_dv_query_count(dev, idx, data, error);
18048 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
18049 : 0 : owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(idx);
18050 [ # # ]: 0 : if (owner != PORT_ID(priv))
18051 : 0 : return rte_flow_error_set(error, EACCES,
18052 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18053 : : NULL,
18054 : : "CT object owned by another port");
18055 : 0 : dev_idx = MLX5_INDIRECT_ACT_CT_GET_IDX(idx);
18056 : 0 : ct = flow_aso_ct_get_by_dev_idx(dev, dev_idx);
18057 : : MLX5_ASSERT(ct);
18058 [ # # ]: 0 : if (!ct->refcnt)
18059 : 0 : return rte_flow_error_set(error, EFAULT,
18060 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18061 : : NULL,
18062 : : "CT object is inactive");
18063 : 0 : ((struct rte_flow_action_conntrack *)data)->peer_port =
18064 : 0 : ct->peer;
18065 : 0 : ((struct rte_flow_action_conntrack *)data)->is_original_dir =
18066 : 0 : ct->is_original;
18067 [ # # ]: 0 : if (mlx5_aso_ct_query_by_wqe(priv->sh, MLX5_HW_INV_QUEUE, ct,
18068 : : data, NULL, true))
18069 : 0 : return rte_flow_error_set(error, EIO,
18070 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18071 : : NULL,
18072 : : "Failed to query CT context");
18073 : : return 0;
18074 : 0 : default:
18075 : 0 : return rte_flow_error_set(error, ENOTSUP,
18076 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
18077 : : "action type query not supported");
18078 : : }
18079 : : }
18080 : :
18081 : : /**
18082 : : * Query a flow rule AGE action for aging information.
18083 : : *
18084 : : * @param[in] dev
18085 : : * Pointer to Ethernet device.
18086 : : * @param[in] flow
18087 : : * Pointer to the sub flow.
18088 : : * @param[out] data
18089 : : * data retrieved by the query.
18090 : : * @param[out] error
18091 : : * Perform verbose error reporting if not NULL.
18092 : : *
18093 : : * @return
18094 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
18095 : : */
18096 : : static int
18097 : 0 : flow_dv_query_age(struct rte_eth_dev *dev, struct rte_flow *flow,
18098 : : void *data, struct rte_flow_error *error)
18099 : : {
18100 : : struct rte_flow_query_age *resp = data;
18101 : : struct mlx5_age_param *age_param;
18102 : :
18103 [ # # ]: 0 : if (flow->age) {
18104 : : struct mlx5_aso_age_action *act =
18105 : 0 : flow_aso_age_get_by_idx(dev, flow->age);
18106 : :
18107 : 0 : age_param = &act->age_params;
18108 [ # # ]: 0 : } else if (flow->counter) {
18109 : : age_param = flow_dv_counter_idx_get_age(dev, flow->counter);
18110 : :
18111 [ # # ]: 0 : if (!age_param || !age_param->timeout)
18112 : 0 : return rte_flow_error_set
18113 : : (error, EINVAL,
18114 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18115 : : NULL, "cannot read age data");
18116 : : } else {
18117 : 0 : return rte_flow_error_set(error, EINVAL,
18118 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18119 : : NULL, "age data not available");
18120 : : }
18121 : 0 : resp->aged = rte_atomic_load_explicit(&age_param->state, rte_memory_order_relaxed) ==
18122 : 0 : AGE_TMOUT ? 1 : 0;
18123 : 0 : resp->sec_since_last_hit_valid = !resp->aged;
18124 [ # # ]: 0 : if (resp->sec_since_last_hit_valid)
18125 : 0 : resp->sec_since_last_hit = rte_atomic_load_explicit
18126 : : (&age_param->sec_since_last_hit, rte_memory_order_relaxed);
18127 : : return 0;
18128 : : }
18129 : :
18130 : : /**
18131 : : * Query a flow.
18132 : : *
18133 : : * @see rte_flow_query()
18134 : : * @see rte_flow_ops
18135 : : */
18136 : : static int
18137 : 0 : flow_dv_query(struct rte_eth_dev *dev,
18138 : : struct rte_flow *flow __rte_unused,
18139 : : const struct rte_flow_action *actions __rte_unused,
18140 : : void *data __rte_unused,
18141 : : struct rte_flow_error *error __rte_unused)
18142 : : {
18143 : : int ret = -EINVAL;
18144 : :
18145 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
18146 [ # # # # ]: 0 : switch (actions->type) {
18147 : : case RTE_FLOW_ACTION_TYPE_VOID:
18148 : : break;
18149 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
18150 : 0 : ret = flow_dv_query_count(dev, flow->counter, data,
18151 : : error);
18152 : 0 : break;
18153 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
18154 [ # # ]: 0 : if (flow->indirect_type == MLX5_INDIRECT_ACTION_TYPE_CT)
18155 : 0 : return rte_flow_error_set(error, ENOTSUP,
18156 : : RTE_FLOW_ERROR_TYPE_ACTION,
18157 : : actions,
18158 : : "age not available");
18159 : 0 : ret = flow_dv_query_age(dev, flow, data, error);
18160 : 0 : break;
18161 : 0 : default:
18162 : 0 : return rte_flow_error_set(error, ENOTSUP,
18163 : : RTE_FLOW_ERROR_TYPE_ACTION,
18164 : : actions,
18165 : : "action not supported");
18166 : : }
18167 : : }
18168 : : return ret;
18169 : : }
18170 : :
18171 : : /**
18172 : : * Destroy the meter table set.
18173 : : * Lock free, (mutex should be acquired by caller).
18174 : : *
18175 : : * @param[in] dev
18176 : : * Pointer to Ethernet device.
18177 : : * @param[in] fm
18178 : : * Meter information table.
18179 : : */
18180 : : static void
18181 : 0 : flow_dv_destroy_mtr_tbls(struct rte_eth_dev *dev,
18182 : : struct mlx5_flow_meter_info *fm)
18183 : : {
18184 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18185 : : int i;
18186 : :
18187 [ # # # # ]: 0 : if (!fm || !priv->sh->config.dv_flow_en)
18188 : : return;
18189 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
18190 [ # # ]: 0 : if (fm->drop_rule[i]) {
18191 : : claim_zero(mlx5_flow_os_destroy_flow(fm->drop_rule[i]));
18192 : 0 : fm->drop_rule[i] = NULL;
18193 : : }
18194 : : }
18195 : : }
18196 : :
18197 : : static void
18198 : 0 : flow_dv_destroy_mtr_drop_tbls(struct rte_eth_dev *dev)
18199 : : {
18200 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18201 : 0 : struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
18202 : : struct mlx5_flow_tbl_data_entry *tbl;
18203 : : int i, j;
18204 : :
18205 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
18206 [ # # ]: 0 : if (mtrmng->def_rule[i]) {
18207 : : claim_zero(mlx5_flow_os_destroy_flow
18208 : : (mtrmng->def_rule[i]));
18209 : 0 : mtrmng->def_rule[i] = NULL;
18210 : : }
18211 [ # # ]: 0 : if (mtrmng->def_matcher[i]) {
18212 : 0 : tbl = container_of(mtrmng->def_matcher[i]->tbl,
18213 : : struct mlx5_flow_tbl_data_entry, tbl);
18214 : 0 : mlx5_list_unregister(tbl->matchers,
18215 : : &mtrmng->def_matcher[i]->entry);
18216 : 0 : mtrmng->def_matcher[i] = NULL;
18217 : : }
18218 [ # # ]: 0 : for (j = 0; j < MLX5_REG_BITS; j++) {
18219 [ # # ]: 0 : if (mtrmng->drop_matcher[i][j]) {
18220 : : tbl =
18221 : 0 : container_of(mtrmng->drop_matcher[i][j]->tbl,
18222 : : struct mlx5_flow_tbl_data_entry,
18223 : : tbl);
18224 : 0 : mlx5_list_unregister(tbl->matchers,
18225 : : &mtrmng->drop_matcher[i][j]->entry);
18226 : 0 : mtrmng->drop_matcher[i][j] = NULL;
18227 : : }
18228 : : }
18229 [ # # ]: 0 : if (mtrmng->drop_tbl[i]) {
18230 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev),
18231 : : mtrmng->drop_tbl[i]);
18232 : 0 : mtrmng->drop_tbl[i] = NULL;
18233 : : }
18234 : : }
18235 : 0 : }
18236 : :
18237 : : /* Number of meter flow actions, count and jump or count and drop. */
18238 : : #define METER_ACTIONS 2
18239 : :
18240 : : static void
18241 : 0 : __flow_dv_destroy_domain_def_policy(struct rte_eth_dev *dev,
18242 : : enum mlx5_meter_domain domain)
18243 : : {
18244 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18245 : 0 : struct mlx5_flow_meter_def_policy *def_policy =
18246 : 0 : priv->sh->mtrmng->def_policy[domain];
18247 : :
18248 : 0 : __flow_dv_destroy_sub_policy_rules(dev, &def_policy->sub_policy);
18249 : 0 : mlx5_free(def_policy);
18250 : 0 : priv->sh->mtrmng->def_policy[domain] = NULL;
18251 : 0 : }
18252 : :
18253 : : /**
18254 : : * Destroy the default policy table set.
18255 : : *
18256 : : * @param[in] dev
18257 : : * Pointer to Ethernet device.
18258 : : */
18259 : : static void
18260 : 0 : flow_dv_destroy_def_policy(struct rte_eth_dev *dev)
18261 : : {
18262 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18263 : : int i;
18264 : :
18265 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++)
18266 [ # # ]: 0 : if (priv->sh->mtrmng->def_policy[i])
18267 : 0 : __flow_dv_destroy_domain_def_policy(dev,
18268 : : (enum mlx5_meter_domain)i);
18269 : 0 : priv->sh->mtrmng->def_policy_id = MLX5_INVALID_POLICY_ID;
18270 : 0 : }
18271 : :
18272 : : static int
18273 : 0 : __flow_dv_create_policy_flow(struct rte_eth_dev *dev,
18274 : : uint32_t color_reg_c_idx,
18275 : : enum rte_color color, struct mlx5_flow_dv_matcher *matcher,
18276 : : int actions_n, void *actions,
18277 : : bool match_src_port, const struct rte_flow_item *item,
18278 : : void **rule, const struct rte_flow_attr *attr)
18279 : : {
18280 : : int ret;
18281 : 0 : struct mlx5_flow_dv_match_params value = {
18282 : : .size = sizeof(value.buf),
18283 : : };
18284 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18285 : : uint8_t misc_mask;
18286 : :
18287 [ # # # # ]: 0 : if (match_src_port && priv->sh->esw_mode) {
18288 [ # # # # ]: 0 : if (item && item->type == RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT)
18289 : 0 : ret = flow_dv_translate_item_represented_port(dev, value.buf,
18290 : : item, attr, MLX5_SET_MATCHER_SW_V);
18291 [ # # # # ]: 0 : else if (item && item->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR)
18292 : 0 : ret = flow_dv_translate_item_port_representor(dev, value.buf,
18293 : : MLX5_SET_MATCHER_SW_V);
18294 : : else
18295 : 0 : ret = flow_dv_translate_item_port_id(dev, value.buf,
18296 : : item, attr, MLX5_SET_MATCHER_SW_V);
18297 [ # # ]: 0 : if (ret) {
18298 : 0 : DRV_LOG(ERR, "Failed to create meter policy%d flow's"
18299 : : " value with port.", color);
18300 : 0 : return -1;
18301 : : }
18302 : : }
18303 : 0 : flow_dv_match_meta_reg(value.buf, (enum modify_reg)color_reg_c_idx,
18304 : : rte_col_2_mlx5_col(color), UINT32_MAX);
18305 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(matcher->mask.buf);
18306 : : __flow_dv_adjust_buf_size(&value.size, misc_mask);
18307 : 0 : ret = mlx5_flow_os_create_flow(matcher->matcher_object, (void *)&value,
18308 : : actions_n, actions, rule);
18309 : : if (ret) {
18310 : 0 : DRV_LOG(ERR, "Failed to create meter policy%d flow.", color);
18311 : 0 : return -1;
18312 : : }
18313 : : return 0;
18314 : : }
18315 : :
18316 : : static int
18317 : 0 : __flow_dv_create_policy_matcher(struct rte_eth_dev *dev,
18318 : : uint32_t color_reg_c_idx,
18319 : : uint16_t priority,
18320 : : struct mlx5_flow_meter_sub_policy *sub_policy,
18321 : : const struct rte_flow_attr *attr,
18322 : : bool match_src_port,
18323 : : const struct rte_flow_item *item,
18324 : : struct mlx5_flow_dv_matcher **policy_matcher,
18325 : : struct rte_flow_error *error)
18326 : : {
18327 : : struct mlx5_list_entry *entry;
18328 : 0 : struct mlx5_flow_tbl_resource *tbl_rsc = sub_policy->tbl_rsc;
18329 : 0 : struct mlx5_flow_dv_matcher matcher = {
18330 : : .mask = {
18331 : : .size = sizeof(matcher.mask.buf),
18332 : : },
18333 : : .tbl = tbl_rsc,
18334 : : };
18335 : 0 : struct mlx5_flow_cb_ctx ctx = {
18336 : : .error = error,
18337 : : .data = &matcher,
18338 : : };
18339 : : struct mlx5_flow_tbl_data_entry *tbl_data;
18340 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18341 : : const uint32_t color_mask = (UINT32_C(1) << MLX5_MTR_COLOR_BITS) - 1;
18342 : : int ret;
18343 : :
18344 [ # # # # ]: 0 : if (match_src_port && priv->sh->esw_mode) {
18345 [ # # # # ]: 0 : if (item && item->type == RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT)
18346 : 0 : ret = flow_dv_translate_item_represented_port(dev, matcher.mask.buf,
18347 : : item, attr, MLX5_SET_MATCHER_SW_M);
18348 [ # # # # ]: 0 : else if (item && item->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR)
18349 : 0 : ret = flow_dv_translate_item_port_representor(dev, matcher.mask.buf,
18350 : : MLX5_SET_MATCHER_SW_M);
18351 : : else
18352 : 0 : ret = flow_dv_translate_item_port_id(dev, matcher.mask.buf,
18353 : : item, attr, MLX5_SET_MATCHER_SW_M);
18354 [ # # ]: 0 : if (ret) {
18355 : 0 : DRV_LOG(ERR, "Failed to register meter policy%d matcher"
18356 : : " with port.", priority);
18357 : 0 : return -1;
18358 : : }
18359 : : }
18360 : 0 : tbl_data = container_of(tbl_rsc, struct mlx5_flow_tbl_data_entry, tbl);
18361 : 0 : flow_dv_match_meta_reg(matcher.mask.buf,
18362 : : (enum modify_reg)color_reg_c_idx, color_mask, color_mask);
18363 : 0 : matcher.priority = priority;
18364 : 0 : matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
18365 : : matcher.mask.size);
18366 : 0 : entry = mlx5_list_register(tbl_data->matchers, &ctx);
18367 [ # # ]: 0 : if (!entry) {
18368 : 0 : DRV_LOG(ERR, "Failed to register meter drop matcher.");
18369 : 0 : return -1;
18370 : : }
18371 : 0 : *policy_matcher =
18372 : : container_of(entry, struct mlx5_flow_dv_matcher, entry);
18373 : 0 : return 0;
18374 : : }
18375 : :
18376 : : /**
18377 : : * Create the policy rules per domain.
18378 : : *
18379 : : * @param[in] dev
18380 : : * Pointer to Ethernet device.
18381 : : * @param[in] sub_policy
18382 : : * Pointer to sub policy table..
18383 : : * @param[in] egress
18384 : : * Direction of the table.
18385 : : * @param[in] transfer
18386 : : * E-Switch or NIC flow.
18387 : : * @param[in] acts
18388 : : * Pointer to policy action list per color.
18389 : : *
18390 : : * @return
18391 : : * 0 on success, -1 otherwise.
18392 : : */
18393 : : static int
18394 : 0 : __flow_dv_create_domain_policy_rules(struct rte_eth_dev *dev,
18395 : : struct mlx5_flow_meter_sub_policy *sub_policy,
18396 : : uint8_t egress, uint8_t transfer, bool *match_src_port,
18397 : : struct mlx5_meter_policy_acts acts[RTE_COLORS])
18398 : : {
18399 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18400 : : struct rte_flow_error flow_err;
18401 : : uint32_t color_reg_c_idx;
18402 : 0 : struct rte_flow_attr attr = {
18403 : : .group = MLX5_FLOW_TABLE_LEVEL_POLICY,
18404 : : .priority = 0,
18405 : : .ingress = 0,
18406 : 0 : .egress = !!egress,
18407 : 0 : .transfer = !!transfer,
18408 : : .reserved = 0,
18409 : : };
18410 : : int i;
18411 : : uint16_t priority;
18412 : 0 : int ret = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &flow_err);
18413 : : struct mlx5_sub_policy_color_rule *color_rule;
18414 : 0 : struct mlx5_sub_policy_color_rule *tmp_rules[RTE_COLORS] = {NULL};
18415 : :
18416 [ # # ]: 0 : if (ret < 0)
18417 : : return -1;
18418 : : /* Create policy table with POLICY level. */
18419 [ # # ]: 0 : if (!sub_policy->tbl_rsc)
18420 : 0 : sub_policy->tbl_rsc = flow_dv_tbl_resource_get(dev,
18421 : : MLX5_FLOW_TABLE_LEVEL_POLICY,
18422 : : egress, transfer, false, NULL, 0, 0,
18423 : 0 : sub_policy->idx, &flow_err);
18424 [ # # ]: 0 : if (!sub_policy->tbl_rsc) {
18425 : 0 : DRV_LOG(ERR,
18426 : : "Failed to create meter sub policy table.");
18427 : 0 : return -1;
18428 : : }
18429 : : /* Prepare matchers. */
18430 : 0 : color_reg_c_idx = ret;
18431 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
18432 : 0 : TAILQ_INIT(&sub_policy->color_rules[i]);
18433 [ # # ]: 0 : if (!acts[i].actions_n)
18434 : 0 : continue;
18435 : 0 : color_rule = mlx5_malloc(MLX5_MEM_ZERO,
18436 : : sizeof(struct mlx5_sub_policy_color_rule),
18437 : : 0, SOCKET_ID_ANY);
18438 [ # # ]: 0 : if (!color_rule) {
18439 : 0 : DRV_LOG(ERR, "No memory to create color rule.");
18440 : 0 : goto err_exit;
18441 : : }
18442 : 0 : tmp_rules[i] = color_rule;
18443 : 0 : TAILQ_INSERT_TAIL(&sub_policy->color_rules[i],
18444 : : color_rule, next_port);
18445 : 0 : color_rule->src_port = priv->representor_id;
18446 : 0 : priority = (match_src_port[i] == match_src_port[RTE_COLOR_GREEN]) ?
18447 : 0 : MLX5_MTR_POLICY_MATCHER_PRIO : (MLX5_MTR_POLICY_MATCHER_PRIO + 1);
18448 : : /* Create matchers for colors. */
18449 [ # # ]: 0 : if (__flow_dv_create_policy_matcher(dev, color_reg_c_idx,
18450 : : priority, sub_policy,
18451 : : &attr, match_src_port[i], NULL,
18452 : : &color_rule->matcher, &flow_err)) {
18453 : 0 : DRV_LOG(ERR, "Failed to create color%u matcher.", i);
18454 : 0 : goto err_exit;
18455 : : }
18456 : : /* Create flow, matching color. */
18457 [ # # ]: 0 : if (__flow_dv_create_policy_flow(dev,
18458 : : color_reg_c_idx, (enum rte_color)i,
18459 : : color_rule->matcher,
18460 : 0 : acts[i].actions_n, acts[i].dv_actions,
18461 : 0 : match_src_port[i], NULL, &color_rule->rule,
18462 : : &attr)) {
18463 : 0 : DRV_LOG(ERR, "Failed to create color%u rule.", i);
18464 : 0 : goto err_exit;
18465 : : }
18466 : : }
18467 : : return 0;
18468 : : err_exit:
18469 : : /* All the policy rules will be cleared. */
18470 : : do {
18471 : 0 : color_rule = tmp_rules[i];
18472 [ # # ]: 0 : if (color_rule) {
18473 [ # # ]: 0 : if (color_rule->rule)
18474 : : mlx5_flow_os_destroy_flow(color_rule->rule);
18475 [ # # ]: 0 : if (color_rule->matcher) {
18476 : : struct mlx5_flow_tbl_data_entry *tbl =
18477 : 0 : container_of(color_rule->matcher->tbl,
18478 : : typeof(*tbl), tbl);
18479 : 0 : mlx5_list_unregister(tbl->matchers,
18480 : : &color_rule->matcher->entry);
18481 : : }
18482 [ # # ]: 0 : TAILQ_REMOVE(&sub_policy->color_rules[i],
18483 : : color_rule, next_port);
18484 : 0 : mlx5_free(color_rule);
18485 : : }
18486 [ # # ]: 0 : } while (i--);
18487 : : return -1;
18488 : : }
18489 : :
18490 : : static int
18491 : 0 : __flow_dv_create_policy_acts_rules(struct rte_eth_dev *dev,
18492 : : struct mlx5_flow_meter_policy *mtr_policy,
18493 : : struct mlx5_flow_meter_sub_policy *sub_policy,
18494 : : uint32_t domain)
18495 : : {
18496 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18497 : : struct mlx5_meter_policy_acts acts[RTE_COLORS];
18498 : : struct mlx5_flow_dv_tag_resource *tag;
18499 : : struct mlx5_flow_dv_port_id_action_resource *port_action;
18500 : : struct mlx5_hrxq *hrxq;
18501 : 0 : struct mlx5_flow_meter_info *next_fm[RTE_COLORS] = {NULL};
18502 : : struct mlx5_flow_meter_policy *next_policy;
18503 : : struct mlx5_flow_meter_sub_policy *next_sub_policy;
18504 : : struct mlx5_flow_tbl_data_entry *tbl_data;
18505 : : struct rte_flow_error error;
18506 : 0 : uint8_t egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
18507 : 0 : uint8_t transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
18508 [ # # # # : 0 : bool mtr_first = egress || (transfer && priv->representor_id != UINT16_MAX);
# # ]
18509 : 0 : bool match_src_port[RTE_COLORS] = {false};
18510 : : int i;
18511 : :
18512 : : /* If RSS or Queue, no previous actions / rules is created. */
18513 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
18514 : 0 : acts[i].actions_n = 0;
18515 [ # # ]: 0 : if (i == RTE_COLOR_RED) {
18516 : : /* Only support drop on red. */
18517 : 0 : acts[i].dv_actions[0] =
18518 : 0 : mtr_policy->dr_drop_action[domain];
18519 : 0 : acts[i].actions_n = 1;
18520 : 0 : continue;
18521 : : }
18522 [ # # ]: 0 : if (mtr_policy->act_cnt[i].fate_action == MLX5_FLOW_FATE_MTR) {
18523 : 0 : struct rte_flow_attr attr = {
18524 : : .transfer = transfer
18525 : : };
18526 : :
18527 : 0 : next_fm[i] = mlx5_flow_meter_find(priv,
18528 : : mtr_policy->act_cnt[i].next_mtr_id,
18529 : : NULL);
18530 [ # # ]: 0 : if (!next_fm[i]) {
18531 : 0 : DRV_LOG(ERR,
18532 : : "Failed to get next hierarchy meter.");
18533 : 0 : goto err_exit;
18534 : : }
18535 [ # # ]: 0 : if (mlx5_flow_meter_attach(priv, next_fm[i],
18536 : : &attr, &error)) {
18537 : 0 : DRV_LOG(ERR, "%s", error.message);
18538 : 0 : next_fm[i] = NULL;
18539 : 0 : goto err_exit;
18540 : : }
18541 : : /* Meter action must be the first for TX. */
18542 [ # # ]: 0 : if (mtr_first) {
18543 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18544 [ # # ]: 0 : (next_fm[i]->color_aware && i == RTE_COLOR_YELLOW) ?
18545 [ # # ]: 0 : next_fm[i]->meter_action_y :
18546 : : next_fm[i]->meter_action_g;
18547 : 0 : acts[i].actions_n++;
18548 : : }
18549 : : }
18550 [ # # ]: 0 : if (mtr_policy->act_cnt[i].rix_mark) {
18551 : 0 : tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG],
18552 : : mtr_policy->act_cnt[i].rix_mark);
18553 [ # # ]: 0 : if (!tag) {
18554 : 0 : DRV_LOG(ERR, "Failed to find "
18555 : : "mark action for policy.");
18556 : 0 : goto err_exit;
18557 : : }
18558 : 0 : acts[i].dv_actions[acts[i].actions_n] = tag->action;
18559 : 0 : acts[i].actions_n++;
18560 : : }
18561 [ # # ]: 0 : if (mtr_policy->act_cnt[i].modify_hdr) {
18562 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18563 : 0 : mtr_policy->act_cnt[i].modify_hdr->action;
18564 : 0 : acts[i].actions_n++;
18565 : : }
18566 [ # # ]: 0 : if (mtr_policy->act_cnt[i].fate_action) {
18567 [ # # # # : 0 : switch (mtr_policy->act_cnt[i].fate_action) {
# ]
18568 : 0 : case MLX5_FLOW_FATE_PORT_ID:
18569 : 0 : port_action = mlx5_ipool_get
18570 : 0 : (priv->sh->ipool[MLX5_IPOOL_PORT_ID],
18571 : : mtr_policy->act_cnt[i].rix_port_id_action);
18572 [ # # ]: 0 : if (!port_action) {
18573 : 0 : DRV_LOG(ERR, "Failed to find "
18574 : : "port action for policy.");
18575 : 0 : goto err_exit;
18576 : : }
18577 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18578 : 0 : port_action->action;
18579 : 0 : acts[i].actions_n++;
18580 : 0 : match_src_port[i] = true;
18581 : 0 : break;
18582 : 0 : case MLX5_FLOW_FATE_DROP:
18583 : : case MLX5_FLOW_FATE_JUMP:
18584 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18585 : 0 : mtr_policy->act_cnt[i].dr_jump_action[domain];
18586 : 0 : acts[i].actions_n++;
18587 : 0 : break;
18588 : 0 : case MLX5_FLOW_FATE_SHARED_RSS:
18589 : : case MLX5_FLOW_FATE_QUEUE:
18590 : 0 : hrxq = mlx5_ipool_get
18591 : 0 : (priv->sh->ipool[MLX5_IPOOL_HRXQ],
18592 : : sub_policy->rix_hrxq[i]);
18593 [ # # ]: 0 : if (!hrxq) {
18594 : 0 : DRV_LOG(ERR, "Failed to find "
18595 : : "queue action for policy.");
18596 : 0 : goto err_exit;
18597 : : }
18598 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18599 : 0 : hrxq->action;
18600 : 0 : acts[i].actions_n++;
18601 : 0 : break;
18602 : 0 : case MLX5_FLOW_FATE_MTR:
18603 [ # # ]: 0 : if (!next_fm[i]) {
18604 : 0 : DRV_LOG(ERR,
18605 : : "No next hierarchy meter.");
18606 : 0 : goto err_exit;
18607 : : }
18608 [ # # ]: 0 : if (!mtr_first) {
18609 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18610 [ # # ]: 0 : (next_fm[i]->color_aware && i == RTE_COLOR_YELLOW) ?
18611 [ # # ]: 0 : next_fm[i]->meter_action_y :
18612 : : next_fm[i]->meter_action_g;
18613 : 0 : acts[i].actions_n++;
18614 : : }
18615 [ # # ]: 0 : if (mtr_policy->act_cnt[i].next_sub_policy) {
18616 : : next_sub_policy =
18617 : : mtr_policy->act_cnt[i].next_sub_policy;
18618 : : } else {
18619 : : next_policy =
18620 : 0 : mlx5_flow_meter_policy_find(dev,
18621 : : next_fm[i]->policy_id, NULL);
18622 : : MLX5_ASSERT(next_policy);
18623 : 0 : next_sub_policy =
18624 : 0 : next_policy->sub_policys[domain][0];
18625 : : }
18626 : : tbl_data =
18627 : 0 : container_of(next_sub_policy->tbl_rsc,
18628 : : struct mlx5_flow_tbl_data_entry, tbl);
18629 : 0 : acts[i].dv_actions[acts[i].actions_n++] =
18630 : 0 : tbl_data->jump.action;
18631 [ # # ]: 0 : if (mtr_policy->act_cnt[i].modify_hdr)
18632 : 0 : match_src_port[i] = !!transfer;
18633 : : break;
18634 : : default:
18635 : : /*Queue action do nothing*/
18636 : : break;
18637 : : }
18638 : : }
18639 : : }
18640 [ # # ]: 0 : if (__flow_dv_create_domain_policy_rules(dev, sub_policy,
18641 : : egress, transfer, match_src_port, acts)) {
18642 : 0 : DRV_LOG(ERR,
18643 : : "Failed to create policy rules per domain.");
18644 : 0 : goto err_exit;
18645 : : }
18646 [ # # # # ]: 0 : if (match_src_port[RTE_COLOR_GREEN] || match_src_port[RTE_COLOR_YELLOW]) {
18647 : 0 : mtr_policy->match_port = 1;
18648 : 0 : mtr_policy->hierarchy_match_port = 1;
18649 : : }
18650 : : return 0;
18651 : : err_exit:
18652 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++)
18653 [ # # ]: 0 : if (next_fm[i])
18654 : 0 : mlx5_flow_meter_detach(priv, next_fm[i]);
18655 : : return -1;
18656 : : }
18657 : :
18658 : : /**
18659 : : * Create the policy rules.
18660 : : *
18661 : : * @param[in] dev
18662 : : * Pointer to Ethernet device.
18663 : : * @param[in,out] mtr_policy
18664 : : * Pointer to meter policy table.
18665 : : *
18666 : : * @return
18667 : : * 0 on success, -1 otherwise.
18668 : : */
18669 : : static int
18670 : 0 : flow_dv_create_policy_rules(struct rte_eth_dev *dev,
18671 : : struct mlx5_flow_meter_policy *mtr_policy)
18672 : : {
18673 : : int i;
18674 : : int ret = 0;
18675 : : uint16_t sub_policy_num;
18676 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_push_thread_workspace();
18677 : :
18678 : : RTE_SET_USED(wks);
18679 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
18680 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
18681 : 0 : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
18682 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
18683 [ # # ]: 0 : if (!sub_policy_num)
18684 : 0 : continue;
18685 : : /* Prepare actions list and create policy rules. */
18686 [ # # ]: 0 : if (__flow_dv_create_policy_acts_rules(dev, mtr_policy,
18687 : 0 : mtr_policy->sub_policys[i][0], i)) {
18688 : 0 : DRV_LOG(ERR, "Failed to create policy action "
18689 : : "list per domain.");
18690 : : ret = -1;
18691 : 0 : goto exit;
18692 : : }
18693 : : }
18694 : 0 : exit:
18695 : 0 : mlx5_flow_pop_thread_workspace();
18696 : 0 : return ret;
18697 : : }
18698 : :
18699 : : static int
18700 : 0 : __flow_dv_create_domain_def_policy(struct rte_eth_dev *dev, uint32_t domain)
18701 : : {
18702 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18703 : 0 : struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
18704 : : struct mlx5_flow_meter_def_policy *def_policy;
18705 : : struct mlx5_flow_tbl_resource *jump_tbl;
18706 : : struct mlx5_flow_tbl_data_entry *tbl_data;
18707 : : uint8_t egress, transfer;
18708 : : struct rte_flow_error error;
18709 : : struct mlx5_meter_policy_acts acts[RTE_COLORS];
18710 : 0 : bool match_src_port[RTE_COLORS] = {false};
18711 : : int ret;
18712 : :
18713 : 0 : egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
18714 : 0 : transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
18715 : 0 : def_policy = mtrmng->def_policy[domain];
18716 [ # # ]: 0 : if (!def_policy) {
18717 : 0 : def_policy = mlx5_malloc(MLX5_MEM_ZERO,
18718 : : sizeof(struct mlx5_flow_meter_def_policy),
18719 : : RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
18720 [ # # ]: 0 : if (!def_policy) {
18721 : 0 : DRV_LOG(ERR, "Failed to alloc default policy table.");
18722 : 0 : goto def_policy_error;
18723 : : }
18724 : 0 : mtrmng->def_policy[domain] = def_policy;
18725 : : /* Create the meter suffix table with SUFFIX level. */
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 create meter suffix table.");
18733 : 0 : goto def_policy_error;
18734 : : }
18735 : 0 : def_policy->sub_policy.jump_tbl[RTE_COLOR_GREEN] = 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_GREEN] =
18739 : 0 : tbl_data->jump.action;
18740 : 0 : acts[RTE_COLOR_GREEN].dv_actions[0] = tbl_data->jump.action;
18741 : 0 : acts[RTE_COLOR_GREEN].actions_n = 1;
18742 : : /*
18743 : : * YELLOW has the same default policy as GREEN does.
18744 : : * G & Y share the same table and action. The 2nd time of table
18745 : : * resource getting is just to update the reference count for
18746 : : * the releasing stage.
18747 : : */
18748 : 0 : jump_tbl = flow_dv_tbl_resource_get(dev,
18749 : : MLX5_FLOW_TABLE_LEVEL_METER,
18750 : : egress, transfer, false, NULL, 0,
18751 : : 0, MLX5_MTR_TABLE_ID_SUFFIX, &error);
18752 [ # # ]: 0 : if (!jump_tbl) {
18753 : 0 : DRV_LOG(ERR,
18754 : : "Failed to get meter suffix table.");
18755 : 0 : goto def_policy_error;
18756 : : }
18757 : 0 : def_policy->sub_policy.jump_tbl[RTE_COLOR_YELLOW] = jump_tbl;
18758 : 0 : tbl_data = container_of(jump_tbl,
18759 : : struct mlx5_flow_tbl_data_entry, tbl);
18760 : 0 : def_policy->dr_jump_action[RTE_COLOR_YELLOW] =
18761 : 0 : tbl_data->jump.action;
18762 : 0 : acts[RTE_COLOR_YELLOW].dv_actions[0] = tbl_data->jump.action;
18763 : 0 : acts[RTE_COLOR_YELLOW].actions_n = 1;
18764 : : /* Create jump action to the drop table. */
18765 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
18766 : 0 : mtrmng->drop_tbl[domain] = flow_dv_tbl_resource_get
18767 : : (dev, MLX5_FLOW_TABLE_LEVEL_METER,
18768 : : egress, transfer, false, NULL, 0,
18769 : : 0, MLX5_MTR_TABLE_ID_DROP, &error);
18770 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
18771 : 0 : DRV_LOG(ERR, "Failed to create meter "
18772 : : "drop table for default policy.");
18773 : 0 : goto def_policy_error;
18774 : : }
18775 : : }
18776 : : /* all RED: unique Drop table for jump action. */
18777 : 0 : tbl_data = container_of(mtrmng->drop_tbl[domain],
18778 : : struct mlx5_flow_tbl_data_entry, tbl);
18779 : 0 : def_policy->dr_jump_action[RTE_COLOR_RED] =
18780 : 0 : tbl_data->jump.action;
18781 : 0 : acts[RTE_COLOR_RED].dv_actions[0] = tbl_data->jump.action;
18782 : 0 : acts[RTE_COLOR_RED].actions_n = 1;
18783 : : /* Create default policy rules. */
18784 : 0 : ret = __flow_dv_create_domain_policy_rules(dev,
18785 : : &def_policy->sub_policy,
18786 : : egress, transfer, match_src_port, acts);
18787 [ # # ]: 0 : if (ret) {
18788 : 0 : DRV_LOG(ERR, "Failed to create default policy rules.");
18789 : 0 : goto def_policy_error;
18790 : : }
18791 : : }
18792 : : return 0;
18793 : 0 : def_policy_error:
18794 : 0 : __flow_dv_destroy_domain_def_policy(dev,
18795 : : (enum mlx5_meter_domain)domain);
18796 : 0 : return -1;
18797 : : }
18798 : :
18799 : : /**
18800 : : * Create the default policy table set.
18801 : : *
18802 : : * @param[in] dev
18803 : : * Pointer to Ethernet device.
18804 : : * @return
18805 : : * 0 on success, -1 otherwise.
18806 : : */
18807 : : static int
18808 : 0 : flow_dv_create_def_policy(struct rte_eth_dev *dev)
18809 : : {
18810 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18811 : : int i;
18812 : :
18813 : : /* Non-termination policy table. */
18814 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
18815 [ # # # # ]: 0 : if (!priv->sh->config.dv_esw_en &&
18816 : : i == MLX5_MTR_DOMAIN_TRANSFER)
18817 : 0 : continue;
18818 [ # # ]: 0 : if (__flow_dv_create_domain_def_policy(dev, i)) {
18819 : 0 : DRV_LOG(ERR, "Failed to create default policy");
18820 : : /* Rollback the created default policies for others. */
18821 : 0 : flow_dv_destroy_def_policy(dev);
18822 : 0 : return -1;
18823 : : }
18824 : : }
18825 : : return 0;
18826 : : }
18827 : :
18828 : : /**
18829 : : * Create the needed meter tables.
18830 : : * Lock free, (mutex should be acquired by caller).
18831 : : *
18832 : : * @param[in] dev
18833 : : * Pointer to Ethernet device.
18834 : : * @param[in] fm
18835 : : * Meter information table.
18836 : : * @param[in] mtr_idx
18837 : : * Meter index.
18838 : : * @param[in] domain_bitmap
18839 : : * Domain bitmap.
18840 : : * @return
18841 : : * 0 on success, -1 otherwise.
18842 : : */
18843 : : static int
18844 : 0 : flow_dv_create_mtr_tbls(struct rte_eth_dev *dev,
18845 : : struct mlx5_flow_meter_info *fm,
18846 : : uint32_t mtr_idx,
18847 : : uint8_t domain_bitmap)
18848 : : {
18849 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18850 : 0 : struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
18851 : : struct rte_flow_error error;
18852 : : struct mlx5_flow_tbl_data_entry *tbl_data;
18853 : : uint8_t egress, transfer;
18854 : : void *actions[METER_ACTIONS];
18855 : : int domain, ret, i;
18856 : : struct mlx5_flow_counter *cnt;
18857 : 0 : struct mlx5_flow_dv_match_params value = {
18858 : : .size = sizeof(value.buf),
18859 : : };
18860 : 0 : struct mlx5_flow_dv_match_params matcher_para = {
18861 : : .size = sizeof(matcher_para.buf),
18862 : : };
18863 : 0 : int mtr_id_reg_c = mlx5_flow_get_reg_id(dev, MLX5_MTR_ID,
18864 : : 0, &error);
18865 : 0 : uint32_t mtr_id_mask = (UINT32_C(1) << mtrmng->max_mtr_bits) - 1;
18866 : 0 : uint8_t mtr_id_offset = priv->mtr_reg_share ? MLX5_MTR_COLOR_BITS : 0;
18867 : : struct mlx5_list_entry *entry;
18868 : 0 : struct mlx5_flow_dv_matcher matcher = {
18869 : : .mask = {
18870 : : .size = sizeof(matcher.mask.buf),
18871 : : },
18872 : : };
18873 : : struct mlx5_flow_dv_matcher *drop_matcher;
18874 : 0 : struct mlx5_flow_cb_ctx ctx = {
18875 : : .error = &error,
18876 : : .data = &matcher,
18877 : : };
18878 : : uint8_t misc_mask;
18879 : :
18880 [ # # # # ]: 0 : if (!priv->mtr_en || mtr_id_reg_c < 0) {
18881 : 0 : rte_errno = ENOTSUP;
18882 : 0 : return -1;
18883 : : }
18884 [ # # ]: 0 : for (domain = 0; domain < MLX5_MTR_DOMAIN_MAX; domain++) {
18885 [ # # ]: 0 : if (!(domain_bitmap & (1 << domain)) ||
18886 [ # # # # ]: 0 : (mtrmng->def_rule[domain] && !fm->drop_cnt))
18887 : 0 : continue;
18888 : 0 : egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
18889 : 0 : transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
18890 : : /* Create the drop table with METER DROP level. */
18891 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
18892 : 0 : mtrmng->drop_tbl[domain] = flow_dv_tbl_resource_get(dev,
18893 : : MLX5_FLOW_TABLE_LEVEL_METER,
18894 : : egress, transfer, false, NULL, 0,
18895 : : 0, MLX5_MTR_TABLE_ID_DROP, &error);
18896 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
18897 : 0 : DRV_LOG(ERR, "Failed to create meter drop table.");
18898 : 0 : goto policy_error;
18899 : : }
18900 : : }
18901 : : /* Create default matcher in drop table. */
18902 : 0 : matcher.tbl = mtrmng->drop_tbl[domain],
18903 : 0 : tbl_data = container_of(mtrmng->drop_tbl[domain],
18904 : : struct mlx5_flow_tbl_data_entry, tbl);
18905 [ # # ]: 0 : if (!mtrmng->def_matcher[domain]) {
18906 : 0 : flow_dv_match_meta_reg_all(matcher.mask.buf, value.buf,
18907 : : (enum modify_reg)mtr_id_reg_c,
18908 : : 0, 0);
18909 : 0 : matcher.priority = MLX5_MTRS_DEFAULT_RULE_PRIORITY;
18910 : 0 : matcher.crc = rte_raw_cksum
18911 : : ((const void *)matcher.mask.buf,
18912 : : matcher.mask.size);
18913 : 0 : entry = mlx5_list_register(tbl_data->matchers, &ctx);
18914 [ # # ]: 0 : if (!entry) {
18915 : 0 : DRV_LOG(ERR, "Failed to register meter "
18916 : : "drop default matcher.");
18917 : 0 : goto policy_error;
18918 : : }
18919 : 0 : mtrmng->def_matcher[domain] = container_of(entry,
18920 : : struct mlx5_flow_dv_matcher, entry);
18921 : : }
18922 : : /* Create default rule in drop table. */
18923 [ # # ]: 0 : if (!mtrmng->def_rule[domain]) {
18924 : : i = 0;
18925 : 0 : actions[i++] = priv->sh->dr_drop_action;
18926 : 0 : flow_dv_match_meta_reg_all(matcher_para.buf, value.buf,
18927 : : (enum modify_reg)mtr_id_reg_c, 0, 0);
18928 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(mtrmng->def_matcher[domain]->mask.buf);
18929 : : __flow_dv_adjust_buf_size(&value.size, misc_mask);
18930 : 0 : ret = mlx5_flow_os_create_flow
18931 : : (mtrmng->def_matcher[domain]->matcher_object,
18932 : : (void *)&value, i, actions,
18933 : : &mtrmng->def_rule[domain]);
18934 : : if (ret) {
18935 : 0 : DRV_LOG(ERR, "Failed to create meter "
18936 : : "default drop rule for drop table.");
18937 : 0 : goto policy_error;
18938 : : }
18939 : : }
18940 [ # # ]: 0 : if (!fm->drop_cnt)
18941 : 0 : continue;
18942 : : MLX5_ASSERT(mtrmng->max_mtr_bits);
18943 [ # # ]: 0 : if (!mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1]) {
18944 : : /* Create matchers for Drop. */
18945 : 0 : flow_dv_match_meta_reg_all(matcher.mask.buf, value.buf,
18946 : : (enum modify_reg)mtr_id_reg_c, 0,
18947 : : (mtr_id_mask << mtr_id_offset));
18948 : 0 : matcher.priority = MLX5_REG_BITS - mtrmng->max_mtr_bits;
18949 : 0 : matcher.crc = rte_raw_cksum
18950 : : ((const void *)matcher.mask.buf,
18951 : : matcher.mask.size);
18952 : 0 : entry = mlx5_list_register(tbl_data->matchers, &ctx);
18953 [ # # ]: 0 : if (!entry) {
18954 : 0 : DRV_LOG(ERR,
18955 : : "Failed to register meter drop matcher.");
18956 : 0 : goto policy_error;
18957 : : }
18958 : 0 : mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1] =
18959 : : container_of(entry, struct mlx5_flow_dv_matcher,
18960 : : entry);
18961 : : }
18962 : 0 : drop_matcher =
18963 : 0 : mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1];
18964 : : /* Create drop rule, matching meter_id only. */
18965 : 0 : flow_dv_match_meta_reg_all(matcher_para.buf, value.buf,
18966 : : (enum modify_reg)mtr_id_reg_c,
18967 : : (mtr_idx << mtr_id_offset), UINT32_MAX);
18968 : : i = 0;
18969 [ # # ]: 0 : cnt = flow_dv_counter_get_by_idx(dev,
18970 : : fm->drop_cnt, NULL);
18971 : 0 : actions[i++] = cnt->action;
18972 : 0 : actions[i++] = priv->sh->dr_drop_action;
18973 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(drop_matcher->mask.buf);
18974 : : __flow_dv_adjust_buf_size(&value.size, misc_mask);
18975 : 0 : ret = mlx5_flow_os_create_flow(drop_matcher->matcher_object,
18976 : : (void *)&value, i, actions,
18977 : : &fm->drop_rule[domain]);
18978 : : if (ret) {
18979 : 0 : DRV_LOG(ERR, "Failed to create meter "
18980 : : "drop rule for drop table.");
18981 : 0 : goto policy_error;
18982 : : }
18983 : : }
18984 : : return 0;
18985 : : policy_error:
18986 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
18987 [ # # ]: 0 : if (fm->drop_rule[i]) {
18988 : : claim_zero(mlx5_flow_os_destroy_flow
18989 : : (fm->drop_rule[i]));
18990 : 0 : fm->drop_rule[i] = NULL;
18991 : : }
18992 : : }
18993 : : return -1;
18994 : : }
18995 : :
18996 : : static struct mlx5_flow_meter_sub_policy *
18997 : 0 : __flow_dv_meter_get_rss_sub_policy(struct rte_eth_dev *dev,
18998 : : struct mlx5_flow_meter_policy *mtr_policy,
18999 : : struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS],
19000 : : struct mlx5_flow_meter_sub_policy *next_sub_policy,
19001 : : bool *is_reuse)
19002 : : {
19003 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19004 : : struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
19005 : 0 : uint32_t sub_policy_idx = 0;
19006 : 0 : uint32_t hrxq_idx[MLX5_MTR_RTE_COLORS] = {0};
19007 : : uint32_t i, j;
19008 : : struct mlx5_hrxq *hrxq;
19009 : : struct mlx5_flow_handle dh;
19010 : : struct mlx5_meter_policy_action_container *act_cnt;
19011 : : uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
19012 : : uint16_t sub_policy_num;
19013 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
19014 : :
19015 : : MLX5_ASSERT(wks);
19016 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19017 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
19018 [ # # ]: 0 : if (!rss_desc[i])
19019 : 0 : continue;
19020 : 0 : hrxq = mlx5_hrxq_get(dev, rss_desc[i]);
19021 [ # # ]: 0 : if (!hrxq) {
19022 : : rte_spinlock_unlock(&mtr_policy->sl);
19023 : 0 : return NULL;
19024 : : }
19025 : 0 : hrxq_idx[i] = hrxq->idx;
19026 : : }
19027 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
19028 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
19029 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
19030 [ # # ]: 0 : for (j = 0; j < sub_policy_num; j++) {
19031 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
19032 [ # # ]: 0 : if (rss_desc[i] &&
19033 : 0 : hrxq_idx[i] !=
19034 [ # # ]: 0 : mtr_policy->sub_policys[domain][j]->rix_hrxq[i])
19035 : : break;
19036 : : }
19037 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS) {
19038 : : /*
19039 : : * Found the sub policy table with
19040 : : * the same queue per color.
19041 : : */
19042 : : rte_spinlock_unlock(&mtr_policy->sl);
19043 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++)
19044 : 0 : mlx5_hrxq_release(dev, hrxq_idx[i]);
19045 : 0 : *is_reuse = true;
19046 : 0 : return mtr_policy->sub_policys[domain][j];
19047 : : }
19048 : : }
19049 : : /* Create sub policy. */
19050 [ # # ]: 0 : if (!mtr_policy->sub_policys[domain][0]->rix_hrxq[RTE_COLOR_GREEN] &&
19051 : : !mtr_policy->sub_policys[domain][0]->rix_hrxq[RTE_COLOR_YELLOW]) {
19052 : : /* Reuse the first pre-allocated sub_policy. */
19053 : : sub_policy = mtr_policy->sub_policys[domain][0];
19054 : 0 : sub_policy_idx = sub_policy->idx;
19055 : : } else {
19056 : 0 : sub_policy = mlx5_ipool_zmalloc
19057 : 0 : (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
19058 : : &sub_policy_idx);
19059 [ # # ]: 0 : if (!sub_policy ||
19060 [ # # ]: 0 : sub_policy_idx > MLX5_MAX_SUB_POLICY_TBL_NUM) {
19061 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++)
19062 : 0 : mlx5_hrxq_release(dev, hrxq_idx[i]);
19063 : 0 : goto rss_sub_policy_error;
19064 : : }
19065 : 0 : sub_policy->idx = sub_policy_idx;
19066 : 0 : sub_policy->main_policy = mtr_policy;
19067 : : }
19068 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
19069 [ # # ]: 0 : if (!rss_desc[i])
19070 : 0 : continue;
19071 : 0 : sub_policy->rix_hrxq[i] = hrxq_idx[i];
19072 [ # # ]: 0 : if (mtr_policy->is_hierarchy) {
19073 : : act_cnt = &mtr_policy->act_cnt[i];
19074 : 0 : act_cnt->next_sub_policy = next_sub_policy;
19075 : 0 : mlx5_hrxq_release(dev, hrxq_idx[i]);
19076 : : } else {
19077 : : /*
19078 : : * Overwrite the last action from
19079 : : * RSS action to Queue action.
19080 : : */
19081 : 0 : hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
19082 : : hrxq_idx[i]);
19083 [ # # ]: 0 : if (!hrxq) {
19084 : 0 : DRV_LOG(ERR, "Failed to get policy hrxq");
19085 : 0 : goto rss_sub_policy_error;
19086 : : }
19087 : : act_cnt = &mtr_policy->act_cnt[i];
19088 [ # # # # ]: 0 : if (act_cnt->rix_mark || act_cnt->modify_hdr) {
19089 : : memset(&dh, 0, sizeof(struct mlx5_flow_handle));
19090 [ # # ]: 0 : if (act_cnt->rix_mark)
19091 : 0 : wks->mark = 1;
19092 : 0 : dh.fate_action = MLX5_FLOW_FATE_QUEUE;
19093 : 0 : dh.rix_hrxq = hrxq_idx[i];
19094 : 0 : flow_drv_rxq_flags_set(dev, &dh);
19095 : : }
19096 : : }
19097 : : }
19098 [ # # ]: 0 : if (__flow_dv_create_policy_acts_rules(dev, mtr_policy,
19099 : : sub_policy, domain)) {
19100 : 0 : DRV_LOG(ERR, "Failed to create policy "
19101 : : "rules for ingress domain.");
19102 : 0 : goto rss_sub_policy_error;
19103 : : }
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 : if (i >= MLX5_MTR_RSS_MAX_SUB_POLICY) {
19109 : 0 : DRV_LOG(ERR, "No free sub-policy slot.");
19110 : 0 : goto rss_sub_policy_error;
19111 : : }
19112 : 0 : mtr_policy->sub_policys[domain][i] = sub_policy;
19113 : 0 : i++;
19114 : 0 : mtr_policy->sub_policy_num &= ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
19115 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain));
19116 : 0 : mtr_policy->sub_policy_num |=
19117 : 0 : (i & MLX5_MTR_SUB_POLICY_NUM_MASK) <<
19118 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain);
19119 : : }
19120 : : rte_spinlock_unlock(&mtr_policy->sl);
19121 : 0 : *is_reuse = false;
19122 : 0 : return sub_policy;
19123 : 0 : rss_sub_policy_error:
19124 [ # # ]: 0 : if (sub_policy) {
19125 : 0 : __flow_dv_destroy_sub_policy_rules(dev, sub_policy);
19126 [ # # ]: 0 : if (sub_policy != mtr_policy->sub_policys[domain][0]) {
19127 : 0 : i = (mtr_policy->sub_policy_num >>
19128 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
19129 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
19130 : 0 : mtr_policy->sub_policys[domain][i] = NULL;
19131 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
19132 : 0 : sub_policy->idx);
19133 : : }
19134 : : }
19135 : : rte_spinlock_unlock(&mtr_policy->sl);
19136 : 0 : return NULL;
19137 : : }
19138 : :
19139 : : /**
19140 : : * Find the policy table for prefix table with RSS.
19141 : : *
19142 : : * @param[in] dev
19143 : : * Pointer to Ethernet device.
19144 : : * @param[in] mtr_policy
19145 : : * Pointer to meter policy table.
19146 : : * @param[in] rss_desc
19147 : : * Pointer to rss_desc
19148 : : * @return
19149 : : * Pointer to table set on success, NULL otherwise and rte_errno is set.
19150 : : */
19151 : : static struct mlx5_flow_meter_sub_policy *
19152 : 0 : flow_dv_meter_sub_policy_rss_prepare(struct rte_eth_dev *dev,
19153 : : struct mlx5_flow_meter_policy *mtr_policy,
19154 : : struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS])
19155 : : {
19156 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19157 : : struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
19158 : : struct mlx5_flow_meter_info *next_fm;
19159 : : struct mlx5_flow_meter_policy *next_policy;
19160 : : struct mlx5_flow_meter_sub_policy *next_sub_policy = NULL;
19161 : : struct mlx5_flow_meter_policy *policies[MLX5_MTR_CHAIN_MAX_NUM];
19162 : : struct mlx5_flow_meter_sub_policy *sub_policies[MLX5_MTR_CHAIN_MAX_NUM];
19163 : : uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
19164 : : bool reuse_sub_policy;
19165 : : uint32_t i = 0;
19166 : : uint32_t j = 0;
19167 : :
19168 : : while (true) {
19169 : : /* Iterate hierarchy to get all policies in this hierarchy. */
19170 : 0 : policies[i++] = mtr_policy;
19171 [ # # ]: 0 : if (!mtr_policy->is_hierarchy)
19172 : : break;
19173 [ # # ]: 0 : if (i >= MLX5_MTR_CHAIN_MAX_NUM) {
19174 : 0 : DRV_LOG(ERR, "Exceed max meter number in hierarchy.");
19175 : 0 : return NULL;
19176 : : }
19177 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19178 : 0 : next_fm = mlx5_flow_meter_hierarchy_next_meter(priv, mtr_policy, NULL);
19179 : : rte_spinlock_unlock(&mtr_policy->sl);
19180 [ # # ]: 0 : if (!next_fm) {
19181 : 0 : DRV_LOG(ERR, "Failed to get next meter in hierarchy.");
19182 : 0 : return NULL;
19183 : : }
19184 : : next_policy =
19185 : 0 : mlx5_flow_meter_policy_find(dev, next_fm->policy_id,
19186 : : NULL);
19187 : : MLX5_ASSERT(next_policy);
19188 : : mtr_policy = next_policy;
19189 : : }
19190 [ # # ]: 0 : while (i) {
19191 : : /**
19192 : : * From last policy to the first one in hierarchy,
19193 : : * create / get the sub policy for each of them.
19194 : : */
19195 : 0 : sub_policy = __flow_dv_meter_get_rss_sub_policy(dev,
19196 : : policies[--i],
19197 : : rss_desc,
19198 : : next_sub_policy,
19199 : : &reuse_sub_policy);
19200 [ # # ]: 0 : if (!sub_policy) {
19201 : 0 : DRV_LOG(ERR, "Failed to get the sub policy.");
19202 : 0 : goto err_exit;
19203 : : }
19204 [ # # ]: 0 : if (!reuse_sub_policy)
19205 : 0 : sub_policies[j++] = sub_policy;
19206 : : next_sub_policy = sub_policy;
19207 : : }
19208 : : return sub_policy;
19209 : : err_exit:
19210 [ # # ]: 0 : while (j) {
19211 : : uint16_t sub_policy_num;
19212 : :
19213 : 0 : sub_policy = sub_policies[--j];
19214 : 0 : mtr_policy = sub_policy->main_policy;
19215 : 0 : __flow_dv_destroy_sub_policy_rules(dev, sub_policy);
19216 [ # # ]: 0 : if (sub_policy != mtr_policy->sub_policys[domain][0]) {
19217 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
19218 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
19219 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
19220 : 0 : mtr_policy->sub_policys[domain][sub_policy_num - 1] =
19221 : : NULL;
19222 : 0 : sub_policy_num--;
19223 : 0 : mtr_policy->sub_policy_num &=
19224 : 0 : ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
19225 : 0 : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i));
19226 : 0 : mtr_policy->sub_policy_num |=
19227 : 0 : (sub_policy_num & MLX5_MTR_SUB_POLICY_NUM_MASK) <<
19228 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i);
19229 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
19230 : 0 : sub_policy->idx);
19231 : : }
19232 : : }
19233 : : return NULL;
19234 : : }
19235 : :
19236 : : /**
19237 : : * Check if need to create hierarchy tag rule.
19238 : : *
19239 : : * @param[in] priv
19240 : : * Pointer to mlx5_priv.
19241 : : * @param[in] mtr_policy
19242 : : * Pointer to current meter policy.
19243 : : * @param[in] src_port
19244 : : * The src port this extra rule should use.
19245 : : * @param[out] next_fm
19246 : : * Pointer to next meter in hierarchy.
19247 : : * @param[out] skip
19248 : : * Indicate if skip the tag rule creation.
19249 : : * @param[out] error
19250 : : * Perform verbose error reporting if not NULL.
19251 : : * @return
19252 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
19253 : : */
19254 : : static int
19255 : 0 : mlx5_meter_hierarchy_skip_tag_rule(struct mlx5_priv *priv,
19256 : : struct mlx5_flow_meter_policy *mtr_policy,
19257 : : int32_t src_port,
19258 : : struct mlx5_flow_meter_info **next_fm,
19259 : : bool *skip,
19260 : : struct rte_flow_error *error)
19261 : : {
19262 : : struct mlx5_flow_meter_sub_policy *sub_policy;
19263 : : struct mlx5_sub_policy_color_rule *color_rule;
19264 : : uint32_t domain = MLX5_MTR_DOMAIN_TRANSFER;
19265 : : int ret = 0;
19266 : : int i;
19267 : :
19268 : 0 : *next_fm = NULL;
19269 : 0 : *skip = false;
19270 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19271 [ # # ]: 0 : if (mtr_policy->is_hierarchy) {
19272 : 0 : *next_fm = mlx5_flow_meter_hierarchy_next_meter(priv, mtr_policy, NULL);
19273 [ # # ]: 0 : if (!*next_fm) {
19274 : 0 : ret = rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
19275 : : NULL, "Failed to find next meter in hierarchy.");
19276 : 0 : goto exit;
19277 : : }
19278 : : }
19279 [ # # ]: 0 : if (!mtr_policy->match_port) {
19280 : 0 : *skip = true;
19281 : 0 : goto exit;
19282 : : }
19283 : 0 : sub_policy = mtr_policy->sub_policys[domain][0];
19284 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
19285 [ # # ]: 0 : if (mtr_policy->act_cnt[i].fate_action != MLX5_FLOW_FATE_MTR &&
19286 : : mtr_policy->act_cnt[i].fate_action != MLX5_FLOW_FATE_PORT_ID)
19287 : 0 : continue;
19288 [ # # ]: 0 : TAILQ_FOREACH(color_rule, &sub_policy->color_rules[i], next_port)
19289 [ # # ]: 0 : if (color_rule->src_port == src_port) {
19290 : 0 : *skip = true;
19291 : 0 : goto exit;
19292 : : }
19293 : : }
19294 : 0 : exit:
19295 : : rte_spinlock_unlock(&mtr_policy->sl);
19296 : 0 : return ret;
19297 : : }
19298 : :
19299 : : /**
19300 : : * Create the sub policy tag rule for all meters in hierarchy.
19301 : : *
19302 : : * @param[in] dev
19303 : : * Pointer to Ethernet device.
19304 : : * @param[in] fm
19305 : : * Meter information table.
19306 : : * @param[in] src_port
19307 : : * The src port this extra rule should use.
19308 : : * @param[in] item
19309 : : * The src port match item.
19310 : : * @param[out] error
19311 : : * Perform verbose error reporting if not NULL.
19312 : : * @return
19313 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
19314 : : */
19315 : : static int
19316 : 0 : flow_dv_meter_hierarchy_rule_create(struct rte_eth_dev *dev,
19317 : : struct mlx5_flow_meter_info *fm,
19318 : : int32_t src_port,
19319 : : const struct rte_flow_item *item,
19320 : : struct rte_flow_error *error)
19321 : : {
19322 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19323 : : struct mlx5_flow_meter_policy *mtr_policy;
19324 : : struct mlx5_flow_meter_sub_policy *sub_policy;
19325 : 0 : struct mlx5_flow_meter_info *next_fm = NULL;
19326 : : struct mlx5_flow_meter_policy *next_policy;
19327 : : struct mlx5_flow_meter_sub_policy *next_sub_policy;
19328 : : struct mlx5_flow_tbl_data_entry *tbl_data;
19329 : : struct mlx5_sub_policy_color_rule *color_rule;
19330 : : struct mlx5_meter_policy_acts acts;
19331 : : uint32_t color_reg_c_idx;
19332 : : bool mtr_first = (src_port != UINT16_MAX) ? true : false;
19333 : 0 : struct rte_flow_attr attr = {
19334 : : .group = MLX5_FLOW_TABLE_LEVEL_POLICY,
19335 : : .priority = 0,
19336 : : .ingress = 0,
19337 : : .egress = 0,
19338 : : .transfer = 1,
19339 : : .reserved = 0,
19340 : : };
19341 : : uint32_t domain = MLX5_MTR_DOMAIN_TRANSFER;
19342 : : struct {
19343 : : struct mlx5_flow_meter_policy *fm_policy;
19344 : : struct mlx5_flow_meter_info *next_fm;
19345 : : struct mlx5_sub_policy_color_rule *tag_rule[RTE_COLORS];
19346 : 0 : } fm_info[MLX5_MTR_CHAIN_MAX_NUM] = { {0} };
19347 : : uint32_t fm_cnt = 0;
19348 : : uint32_t i, j;
19349 : :
19350 : 0 : color_reg_c_idx = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, error);
19351 : : /* Get all fms who need to create the tag color rule. */
19352 : : do {
19353 : 0 : bool skip = false;
19354 : :
19355 : 0 : mtr_policy = mlx5_flow_meter_policy_find(dev, fm->policy_id, NULL);
19356 : : MLX5_ASSERT(mtr_policy);
19357 [ # # ]: 0 : if (mlx5_meter_hierarchy_skip_tag_rule(priv, mtr_policy, src_port,
19358 : : &next_fm, &skip, error))
19359 : 0 : goto err_exit;
19360 [ # # ]: 0 : if (!skip) {
19361 : 0 : fm_info[fm_cnt].fm_policy = mtr_policy;
19362 : 0 : fm_info[fm_cnt].next_fm = next_fm;
19363 [ # # ]: 0 : if (++fm_cnt >= MLX5_MTR_CHAIN_MAX_NUM) {
19364 : 0 : rte_flow_error_set(error, errno,
19365 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
19366 : : "Exceed max meter number in hierarchy.");
19367 : 0 : goto err_exit;
19368 : : }
19369 : : }
19370 : 0 : fm = next_fm;
19371 [ # # ]: 0 : } while (fm);
19372 : : /* Create tag color rules for all needed fms. */
19373 [ # # ]: 0 : for (i = 0; i < fm_cnt; i++) {
19374 : : void *mtr_action;
19375 : :
19376 : 0 : mtr_policy = fm_info[i].fm_policy;
19377 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19378 : 0 : sub_policy = mtr_policy->sub_policys[domain][0];
19379 [ # # ]: 0 : for (j = 0; j < RTE_COLORS; j++) {
19380 : : uint8_t act_n = 0;
19381 : : struct mlx5_flow_dv_modify_hdr_resource *modify_hdr = NULL;
19382 : : struct mlx5_flow_dv_port_id_action_resource *port_action;
19383 : : uint8_t fate_action;
19384 : :
19385 [ # # ]: 0 : if (j == RTE_COLOR_RED) {
19386 : : fate_action = MLX5_FLOW_FATE_DROP;
19387 : : } else {
19388 : 0 : fate_action = mtr_policy->act_cnt[j].fate_action;
19389 : 0 : modify_hdr = mtr_policy->act_cnt[j].modify_hdr;
19390 : 0 : if (fate_action != MLX5_FLOW_FATE_MTR &&
19391 [ # # # # ]: 0 : fate_action != MLX5_FLOW_FATE_PORT_ID &&
19392 : : fate_action != MLX5_FLOW_FATE_DROP)
19393 : 0 : continue;
19394 : : }
19395 : 0 : color_rule = mlx5_malloc(MLX5_MEM_ZERO,
19396 : : sizeof(struct mlx5_sub_policy_color_rule),
19397 : : 0, SOCKET_ID_ANY);
19398 [ # # ]: 0 : if (!color_rule) {
19399 : : rte_spinlock_unlock(&mtr_policy->sl);
19400 : 0 : rte_flow_error_set(error, ENOMEM,
19401 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
19402 : : "No memory to create tag color rule.");
19403 : 0 : goto err_exit;
19404 : : }
19405 : 0 : color_rule->src_port = src_port;
19406 : : /* Prepare to create color rule. */
19407 [ # # ]: 0 : if (fate_action == MLX5_FLOW_FATE_MTR) {
19408 : 0 : next_fm = fm_info[i].next_fm;
19409 [ # # ]: 0 : if (mlx5_flow_meter_attach(priv, next_fm, &attr, error)) {
19410 : 0 : mlx5_free(color_rule);
19411 : : rte_spinlock_unlock(&mtr_policy->sl);
19412 : 0 : goto err_exit;
19413 : : }
19414 [ # # ]: 0 : mtr_action = (next_fm->color_aware && j == RTE_COLOR_YELLOW) ?
19415 [ # # ]: 0 : next_fm->meter_action_y :
19416 : : next_fm->meter_action_g;
19417 : 0 : next_policy = mlx5_flow_meter_policy_find(dev, next_fm->policy_id,
19418 : : NULL);
19419 : : MLX5_ASSERT(next_policy);
19420 : 0 : next_sub_policy = next_policy->sub_policys[domain][0];
19421 : 0 : tbl_data = container_of(next_sub_policy->tbl_rsc,
19422 : : struct mlx5_flow_tbl_data_entry, tbl);
19423 [ # # ]: 0 : if (mtr_first) {
19424 : 0 : acts.dv_actions[act_n++] = mtr_action;
19425 [ # # ]: 0 : if (modify_hdr)
19426 : 0 : acts.dv_actions[act_n++] = modify_hdr->action;
19427 : : } else {
19428 [ # # ]: 0 : if (modify_hdr)
19429 : 0 : acts.dv_actions[act_n++] = modify_hdr->action;
19430 : 0 : acts.dv_actions[act_n++] = mtr_action;
19431 : : }
19432 : 0 : acts.dv_actions[act_n++] = tbl_data->jump.action;
19433 : 0 : acts.actions_n = act_n;
19434 [ # # ]: 0 : } else if (fate_action == MLX5_FLOW_FATE_PORT_ID) {
19435 : : port_action =
19436 : 0 : mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PORT_ID],
19437 : : mtr_policy->act_cnt[j].rix_port_id_action);
19438 [ # # ]: 0 : if (!port_action) {
19439 : 0 : mlx5_free(color_rule);
19440 : : rte_spinlock_unlock(&mtr_policy->sl);
19441 : 0 : goto err_exit;
19442 : : }
19443 [ # # ]: 0 : if (modify_hdr)
19444 : 0 : acts.dv_actions[act_n++] = modify_hdr->action;
19445 : 0 : acts.dv_actions[act_n++] = port_action->action;
19446 : 0 : acts.actions_n = act_n;
19447 : : } else {
19448 : 0 : acts.dv_actions[act_n++] = mtr_policy->dr_drop_action[domain];
19449 : 0 : acts.actions_n = act_n;
19450 : : }
19451 : 0 : fm_info[i].tag_rule[j] = color_rule;
19452 : 0 : TAILQ_INSERT_TAIL(&sub_policy->color_rules[j], color_rule, next_port);
19453 [ # # ]: 0 : if (__flow_dv_create_policy_matcher(dev, color_reg_c_idx,
19454 : : MLX5_MTR_POLICY_MATCHER_PRIO, sub_policy,
19455 : : &attr, true, item, &color_rule->matcher, error)) {
19456 : : rte_spinlock_unlock(&mtr_policy->sl);
19457 : 0 : rte_flow_error_set(error, errno,
19458 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
19459 : : "Failed to create hierarchy meter matcher.");
19460 : 0 : goto err_exit;
19461 : : }
19462 [ # # ]: 0 : if (__flow_dv_create_policy_flow(dev, color_reg_c_idx, (enum rte_color)j,
19463 : : color_rule->matcher,
19464 : 0 : acts.actions_n, acts.dv_actions,
19465 : : true, item, &color_rule->rule, &attr)) {
19466 : : rte_spinlock_unlock(&mtr_policy->sl);
19467 : 0 : rte_flow_error_set(error, errno,
19468 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
19469 : : "Failed to create hierarchy meter rule.");
19470 : 0 : goto err_exit;
19471 : : }
19472 : : }
19473 : : rte_spinlock_unlock(&mtr_policy->sl);
19474 : : }
19475 : : return 0;
19476 : 0 : err_exit:
19477 [ # # ]: 0 : for (i = 0; i < fm_cnt; i++) {
19478 : 0 : mtr_policy = fm_info[i].fm_policy;
19479 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19480 : 0 : sub_policy = mtr_policy->sub_policys[domain][0];
19481 [ # # ]: 0 : for (j = 0; j < RTE_COLORS; j++) {
19482 : 0 : color_rule = fm_info[i].tag_rule[j];
19483 [ # # ]: 0 : if (!color_rule)
19484 : 0 : continue;
19485 [ # # ]: 0 : if (color_rule->rule)
19486 : : mlx5_flow_os_destroy_flow(color_rule->rule);
19487 [ # # ]: 0 : if (color_rule->matcher) {
19488 : : struct mlx5_flow_tbl_data_entry *tbl =
19489 : 0 : container_of(color_rule->matcher->tbl, typeof(*tbl), tbl);
19490 : 0 : mlx5_list_unregister(tbl->matchers, &color_rule->matcher->entry);
19491 : : }
19492 [ # # ]: 0 : if (fm_info[i].next_fm)
19493 : 0 : mlx5_flow_meter_detach(priv, fm_info[i].next_fm);
19494 [ # # ]: 0 : TAILQ_REMOVE(&sub_policy->color_rules[j], color_rule, next_port);
19495 : 0 : mlx5_free(color_rule);
19496 : : }
19497 : : rte_spinlock_unlock(&mtr_policy->sl);
19498 : : }
19499 : 0 : return -rte_errno;
19500 : : }
19501 : :
19502 : : /**
19503 : : * Destroy the sub policy table with RX queue.
19504 : : *
19505 : : * @param[in] dev
19506 : : * Pointer to Ethernet device.
19507 : : * @param[in] mtr_policy
19508 : : * Pointer to meter policy table.
19509 : : */
19510 : : static void
19511 : 0 : flow_dv_destroy_sub_policy_with_rxq(struct rte_eth_dev *dev,
19512 : : struct mlx5_flow_meter_policy *mtr_policy)
19513 : : {
19514 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19515 : : struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
19516 : : uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
19517 : : uint32_t i, j;
19518 : : uint16_t sub_policy_num, new_policy_num;
19519 : :
19520 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19521 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
19522 [ # # # ]: 0 : switch (mtr_policy->act_cnt[i].fate_action) {
19523 : 0 : case MLX5_FLOW_FATE_SHARED_RSS:
19524 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
19525 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
19526 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
19527 : : new_policy_num = sub_policy_num;
19528 [ # # ]: 0 : for (j = 0; j < sub_policy_num; j++) {
19529 : 0 : sub_policy =
19530 : 0 : mtr_policy->sub_policys[domain][j];
19531 [ # # ]: 0 : if (sub_policy) {
19532 : 0 : __flow_dv_destroy_sub_policy_rules(dev,
19533 : : sub_policy);
19534 : 0 : if (sub_policy !=
19535 [ # # ]: 0 : mtr_policy->sub_policys[domain][0]) {
19536 : 0 : mtr_policy->sub_policys[domain][j] =
19537 : : NULL;
19538 : 0 : mlx5_ipool_free
19539 : 0 : (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
19540 : 0 : sub_policy->idx);
19541 : 0 : new_policy_num--;
19542 : : }
19543 : : }
19544 : : }
19545 [ # # ]: 0 : if (new_policy_num != sub_policy_num) {
19546 : 0 : mtr_policy->sub_policy_num &=
19547 : : ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
19548 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain));
19549 : 0 : mtr_policy->sub_policy_num |=
19550 : : (new_policy_num &
19551 : : MLX5_MTR_SUB_POLICY_NUM_MASK) <<
19552 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain);
19553 : : }
19554 : : break;
19555 : 0 : case MLX5_FLOW_FATE_QUEUE:
19556 : 0 : sub_policy = mtr_policy->sub_policys[domain][0];
19557 : 0 : __flow_dv_destroy_sub_policy_rules(dev,
19558 : : sub_policy);
19559 : 0 : break;
19560 : : default:
19561 : : /*Other actions without queue and do nothing*/
19562 : : break;
19563 : : }
19564 : : }
19565 : : rte_spinlock_unlock(&mtr_policy->sl);
19566 : 0 : }
19567 : : /**
19568 : : * Check whether the DR drop action is supported on the root table or not.
19569 : : *
19570 : : * Create a simple flow with DR drop action on root table to validate
19571 : : * if DR drop action on root table is supported or not.
19572 : : *
19573 : : * @param[in] dev
19574 : : * Pointer to rte_eth_dev structure.
19575 : : *
19576 : : * @return
19577 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
19578 : : */
19579 : : int
19580 : 0 : mlx5_flow_discover_dr_action_support(struct rte_eth_dev *dev)
19581 : : {
19582 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19583 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
19584 : 0 : struct mlx5_flow_dv_match_params mask = {
19585 : : .size = sizeof(mask.buf),
19586 : : };
19587 : 0 : struct mlx5_flow_dv_match_params value = {
19588 : : .size = sizeof(value.buf),
19589 : : };
19590 : 0 : struct mlx5dv_flow_matcher_attr dv_attr = {
19591 : : .type = IBV_FLOW_ATTR_NORMAL,
19592 : : .priority = 0,
19593 : : .match_criteria_enable = 0,
19594 : : .match_mask = (void *)&mask,
19595 : : };
19596 : : struct mlx5_flow_tbl_resource *tbl = NULL;
19597 : : void *matcher = NULL;
19598 : : void *flow = NULL;
19599 : : int ret = -1;
19600 : :
19601 : 0 : tbl = flow_dv_tbl_resource_get(dev, 0, 0, 0, false, NULL,
19602 : : 0, 0, 0, NULL);
19603 [ # # ]: 0 : if (!tbl)
19604 : 0 : goto err;
19605 [ # # ]: 0 : dv_attr.match_criteria_enable = flow_dv_matcher_enable(mask.buf);
19606 : : __flow_dv_adjust_buf_size(&mask.size, dv_attr.match_criteria_enable);
19607 : 0 : ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
19608 : : tbl->obj, &matcher);
19609 : : if (ret)
19610 : 0 : goto err;
19611 [ # # ]: 0 : __flow_dv_adjust_buf_size(&value.size, dv_attr.match_criteria_enable);
19612 : 0 : ret = mlx5_flow_os_create_flow(matcher, (void *)&value, 1,
19613 : : &sh->dr_drop_action, &flow);
19614 : 0 : err:
19615 : : /*
19616 : : * If DR drop action is not supported on root table, flow create will
19617 : : * be failed with EOPNOTSUPP or EPROTONOSUPPORT.
19618 : : */
19619 [ # # ]: 0 : if (!flow) {
19620 [ # # ]: 0 : if (matcher &&
19621 [ # # ]: 0 : (errno == EPROTONOSUPPORT || errno == EOPNOTSUPP))
19622 : 0 : DRV_LOG(INFO, "DR drop action is not supported in root table.");
19623 : : else
19624 : 0 : DRV_LOG(ERR, "Unexpected error in DR drop action support detection");
19625 : : ret = -1;
19626 : : } else {
19627 : : claim_zero(mlx5_flow_os_destroy_flow(flow));
19628 : : }
19629 [ # # ]: 0 : if (matcher)
19630 : : claim_zero(mlx5_flow_os_destroy_flow_matcher(matcher));
19631 [ # # ]: 0 : if (tbl)
19632 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
19633 : 0 : return ret;
19634 : : }
19635 : :
19636 : : /**
19637 : : * Validate the batch counter support in root table.
19638 : : *
19639 : : * Create a simple flow with invalid counter and drop action on root table to
19640 : : * validate if batch counter with offset on root table is supported or not.
19641 : : *
19642 : : * @param[in] dev
19643 : : * Pointer to rte_eth_dev structure.
19644 : : *
19645 : : * @return
19646 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
19647 : : */
19648 : : int
19649 : 0 : mlx5_flow_dv_discover_counter_offset_support(struct rte_eth_dev *dev)
19650 : : {
19651 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19652 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
19653 : 0 : struct mlx5_flow_dv_match_params mask = {
19654 : : .size = sizeof(mask.buf),
19655 : : };
19656 : 0 : struct mlx5_flow_dv_match_params value = {
19657 : : .size = sizeof(value.buf),
19658 : : };
19659 : 0 : struct mlx5dv_flow_matcher_attr dv_attr = {
19660 : : .type = IBV_FLOW_ATTR_NORMAL,
19661 : : .flags = IBV_FLOW_ATTR_FLAGS_EGRESS,
19662 : : .priority = 0,
19663 : : .match_criteria_enable = 0,
19664 : : .match_mask = (void *)&mask,
19665 : : };
19666 : 0 : void *actions[2] = { 0 };
19667 : : struct mlx5_flow_tbl_resource *tbl = NULL;
19668 : : struct mlx5_devx_obj *dcs = NULL;
19669 : : void *matcher = NULL;
19670 : : void *flow = NULL;
19671 : : int ret = -1;
19672 : :
19673 : 0 : tbl = flow_dv_tbl_resource_get(dev, 0, 1, 0, false, NULL,
19674 : : 0, 0, 0, NULL);
19675 [ # # ]: 0 : if (!tbl)
19676 : 0 : goto err;
19677 : 0 : dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0x4);
19678 [ # # ]: 0 : if (!dcs)
19679 : 0 : goto err;
19680 : 0 : ret = mlx5_flow_os_create_flow_action_count(dcs->obj, UINT16_MAX,
19681 : : &actions[0]);
19682 : : if (ret)
19683 : 0 : goto err;
19684 [ # # ]: 0 : dv_attr.match_criteria_enable = flow_dv_matcher_enable(mask.buf);
19685 : : __flow_dv_adjust_buf_size(&mask.size, dv_attr.match_criteria_enable);
19686 : 0 : ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
19687 : : tbl->obj, &matcher);
19688 : : if (ret)
19689 : 0 : goto err;
19690 [ # # ]: 0 : __flow_dv_adjust_buf_size(&value.size, dv_attr.match_criteria_enable);
19691 : : ret = mlx5_flow_os_create_flow(matcher, (void *)&value, 1,
19692 : : actions, &flow);
19693 : 0 : err:
19694 : : /*
19695 : : * If batch counter with offset is not supported, the driver will not
19696 : : * validate the invalid offset value, flow create should success.
19697 : : * In this case, it means batch counter is not supported in root table.
19698 : : *
19699 : : * Otherwise, if flow create is failed, counter offset is supported.
19700 : : */
19701 [ # # ]: 0 : if (flow) {
19702 : 0 : DRV_LOG(INFO, "Batch counter is not supported in root "
19703 : : "table. Switch to fallback mode.");
19704 : 0 : rte_errno = ENOTSUP;
19705 : : ret = -rte_errno;
19706 : : claim_zero(mlx5_flow_os_destroy_flow(flow));
19707 : : } else {
19708 : : /* Check matcher to make sure validate fail at flow create. */
19709 [ # # # # ]: 0 : if (!matcher || (matcher && errno != EINVAL))
19710 : 0 : DRV_LOG(ERR, "Unexpected error in counter offset "
19711 : : "support detection");
19712 : : ret = 0;
19713 : : }
19714 [ # # ]: 0 : if (actions[0])
19715 : : claim_zero(mlx5_flow_os_destroy_flow_action(actions[0]));
19716 [ # # ]: 0 : if (matcher)
19717 : : claim_zero(mlx5_flow_os_destroy_flow_matcher(matcher));
19718 [ # # ]: 0 : if (tbl)
19719 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
19720 [ # # ]: 0 : if (dcs)
19721 : 0 : claim_zero(mlx5_devx_cmd_destroy(dcs));
19722 : 0 : return ret;
19723 : : }
19724 : :
19725 : : /**
19726 : : * Query a devx counter.
19727 : : *
19728 : : * @param[in] dev
19729 : : * Pointer to the Ethernet device structure.
19730 : : * @param[in] cnt
19731 : : * Index to the flow counter.
19732 : : * @param[in] clear
19733 : : * Set to clear the counter statistics.
19734 : : * @param[out] pkts
19735 : : * The statistics value of packets.
19736 : : * @param[out] bytes
19737 : : * The statistics value of bytes.
19738 : : *
19739 : : * @return
19740 : : * 0 on success, otherwise return -1.
19741 : : */
19742 : : static int
19743 : 0 : flow_dv_counter_query(struct rte_eth_dev *dev, uint32_t counter, bool clear,
19744 : : uint64_t *pkts, uint64_t *bytes, void **action)
19745 : : {
19746 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19747 : : struct mlx5_flow_counter *cnt;
19748 : : uint64_t inn_pkts, inn_bytes;
19749 : : int ret;
19750 : :
19751 [ # # ]: 0 : if (!priv->sh->cdev->config.devx)
19752 : : return -1;
19753 : :
19754 : 0 : ret = _flow_dv_query_count(dev, counter, &inn_pkts, &inn_bytes);
19755 [ # # ]: 0 : if (ret)
19756 : : return -1;
19757 : : cnt = flow_dv_counter_get_by_idx(dev, counter, NULL);
19758 [ # # ]: 0 : if (cnt && action)
19759 : 0 : *action = cnt->action;
19760 : :
19761 : 0 : *pkts = inn_pkts - cnt->hits;
19762 : 0 : *bytes = inn_bytes - cnt->bytes;
19763 [ # # ]: 0 : if (clear) {
19764 : 0 : cnt->hits = inn_pkts;
19765 : 0 : cnt->bytes = inn_bytes;
19766 : : }
19767 : : return 0;
19768 : : }
19769 : :
19770 : : /**
19771 : : * Get aged-out flows.
19772 : : *
19773 : : * @param[in] dev
19774 : : * Pointer to the Ethernet device structure.
19775 : : * @param[in] context
19776 : : * The address of an array of pointers to the aged-out flows contexts.
19777 : : * @param[in] nb_contexts
19778 : : * The length of context array pointers.
19779 : : * @param[out] error
19780 : : * Perform verbose error reporting if not NULL. Initialized in case of
19781 : : * error only.
19782 : : *
19783 : : * @return
19784 : : * how many contexts get in success, otherwise negative errno value.
19785 : : * if nb_contexts is 0, return the amount of all aged contexts.
19786 : : * if nb_contexts is not 0 , return the amount of aged flows reported
19787 : : * in the context array.
19788 : : * @note: only stub for now
19789 : : */
19790 : : static int
19791 : 0 : flow_dv_get_aged_flows(struct rte_eth_dev *dev,
19792 : : void **context,
19793 : : uint32_t nb_contexts,
19794 : : struct rte_flow_error *error)
19795 : : {
19796 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19797 : : struct mlx5_age_info *age_info;
19798 : : struct mlx5_age_param *age_param;
19799 : : struct mlx5_flow_counter *counter;
19800 : : struct mlx5_aso_age_action *act;
19801 : : int nb_flows = 0;
19802 : :
19803 [ # # ]: 0 : if (nb_contexts && !context)
19804 : 0 : return rte_flow_error_set(error, EINVAL,
19805 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
19806 : : NULL, "empty context");
19807 : 0 : age_info = GET_PORT_AGE_INFO(priv);
19808 : 0 : rte_spinlock_lock(&age_info->aged_sl);
19809 [ # # ]: 0 : LIST_FOREACH(act, &age_info->aged_aso, next) {
19810 : 0 : nb_flows++;
19811 [ # # ]: 0 : if (nb_contexts) {
19812 : 0 : context[nb_flows - 1] = act->age_params.context;
19813 [ # # ]: 0 : if (!(--nb_contexts))
19814 : : break;
19815 : : }
19816 : : }
19817 [ # # ]: 0 : TAILQ_FOREACH(counter, &age_info->aged_counters, next) {
19818 : 0 : nb_flows++;
19819 [ # # ]: 0 : if (nb_contexts) {
19820 : : age_param = MLX5_CNT_TO_AGE(counter);
19821 : 0 : context[nb_flows - 1] = age_param->context;
19822 [ # # ]: 0 : if (!(--nb_contexts))
19823 : : break;
19824 : : }
19825 : : }
19826 : : rte_spinlock_unlock(&age_info->aged_sl);
19827 : 0 : MLX5_AGE_SET(age_info, MLX5_AGE_TRIGGER);
19828 : 0 : return nb_flows;
19829 : : }
19830 : :
19831 : : /*
19832 : : * Mutex-protected thunk to lock-free flow_dv_counter_alloc().
19833 : : */
19834 : : static uint32_t
19835 : 0 : flow_dv_counter_allocate(struct rte_eth_dev *dev)
19836 : : {
19837 : 0 : return flow_dv_counter_alloc(dev, 0);
19838 : : }
19839 : :
19840 : : /**
19841 : : * Validate indirect action.
19842 : : * Dispatcher for action type specific validation.
19843 : : *
19844 : : * @param[in] dev
19845 : : * Pointer to the Ethernet device structure.
19846 : : * @param[in] conf
19847 : : * Indirect action configuration.
19848 : : * @param[in] action
19849 : : * The indirect action object to validate.
19850 : : * @param[out] error
19851 : : * Perform verbose error reporting if not NULL. Initialized in case of
19852 : : * error only.
19853 : : *
19854 : : * @return
19855 : : * 0 on success, otherwise negative errno value.
19856 : : */
19857 : : int
19858 : 0 : flow_dv_action_validate(struct rte_eth_dev *dev,
19859 : : const struct rte_flow_indir_action_conf *conf,
19860 : : const struct rte_flow_action *action,
19861 : : struct rte_flow_error *err)
19862 : : {
19863 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19864 : : /* called from RTE API */
19865 : :
19866 : : RTE_SET_USED(conf);
19867 [ # # # # : 0 : switch (action->type) {
# ]
19868 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
19869 : : /*
19870 : : * priv->obj_ops is set according to driver capabilities.
19871 : : * When DevX capabilities are
19872 : : * sufficient, it is set to devx_obj_ops.
19873 : : * Otherwise, it is set to ibv_obj_ops.
19874 : : * ibv_obj_ops doesn't support ind_table_modify operation.
19875 : : * In this case the indirect RSS action can't be used.
19876 : : */
19877 [ # # ]: 0 : if (priv->obj_ops.ind_table_modify == NULL)
19878 : 0 : return rte_flow_error_set
19879 : : (err, ENOTSUP,
19880 : : RTE_FLOW_ERROR_TYPE_ACTION,
19881 : : NULL,
19882 : : "Indirect RSS action not supported");
19883 : 0 : return mlx5_validate_action_rss(dev, action, err);
19884 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
19885 [ # # ]: 0 : if (!priv->sh->aso_age_mng)
19886 : 0 : return rte_flow_error_set(err, ENOTSUP,
19887 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
19888 : : NULL,
19889 : : "Indirect age action not supported");
19890 : 0 : return flow_dv_validate_action_age(0, action, dev, err);
19891 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
19892 : 0 : return flow_dv_validate_action_count(dev, true, 0, false, err);
19893 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
19894 [ # # ]: 0 : if (!priv->sh->ct_aso_en)
19895 : 0 : return rte_flow_error_set(err, ENOTSUP,
19896 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
19897 : : "ASO CT is not supported");
19898 : 0 : return mlx5_validate_action_ct(dev, action->conf, err);
19899 : 0 : default:
19900 : 0 : return rte_flow_error_set(err, ENOTSUP,
19901 : : RTE_FLOW_ERROR_TYPE_ACTION,
19902 : : NULL,
19903 : : "action type not supported");
19904 : : }
19905 : : }
19906 : :
19907 : : /*
19908 : : * Check if the RSS configurations for colors of a meter policy match
19909 : : * each other, except the queues.
19910 : : *
19911 : : * @param[in] r1
19912 : : * Pointer to the first RSS flow action.
19913 : : * @param[in] r2
19914 : : * Pointer to the second RSS flow action.
19915 : : *
19916 : : * @return
19917 : : * 0 on match, 1 on conflict.
19918 : : */
19919 : : static inline int
19920 : 0 : flow_dv_mtr_policy_rss_compare(const struct rte_flow_action_rss *r1,
19921 : : const struct rte_flow_action_rss *r2)
19922 : : {
19923 [ # # ]: 0 : if (r1 == NULL || r2 == NULL)
19924 : : return 0;
19925 [ # # # # : 0 : if (!(r1->level <= 1 && r2->level <= 1) &&
# # ]
19926 [ # # ]: 0 : !(r1->level > 1 && r2->level > 1))
19927 : : return 1;
19928 [ # # ]: 0 : if (r1->func != r2->func)
19929 : : return 1;
19930 [ # # ]: 0 : if (r1->types != r2->types &&
19931 [ # # ]: 0 : !((r1->types == 0 || r1->types == RTE_ETH_RSS_IP) &&
19932 [ # # ]: 0 : (r2->types == 0 || r2->types == RTE_ETH_RSS_IP)))
19933 : : return 1;
19934 [ # # # # ]: 0 : if (r1->key || r2->key) {
19935 [ # # ]: 0 : const void *key1 = r1->key ? r1->key : rss_hash_default_key;
19936 [ # # ]: 0 : const void *key2 = r2->key ? r2->key : rss_hash_default_key;
19937 : :
19938 [ # # ]: 0 : if (memcmp(key1, key2, MLX5_RSS_HASH_KEY_LEN))
19939 : 0 : return 1;
19940 : : }
19941 : : return 0;
19942 : : }
19943 : :
19944 : : /**
19945 : : * Validate the meter hierarchy chain for meter policy.
19946 : : *
19947 : : * @param[in] dev
19948 : : * Pointer to the Ethernet device structure.
19949 : : * @param[in] meter_id
19950 : : * Meter id.
19951 : : * @param[in] action_flags
19952 : : * Holds the actions detected until now.
19953 : : * @param[out] is_rss
19954 : : * Is RSS or not.
19955 : : * @param[out] hierarchy_domain
19956 : : * The domain bitmap for hierarchy policy.
19957 : : * @param[out] error
19958 : : * Perform verbose error reporting if not NULL. Initialized in case of
19959 : : * error only.
19960 : : *
19961 : : * @return
19962 : : * 0 on success, otherwise negative errno value with error set.
19963 : : */
19964 : : static int
19965 : 0 : flow_dv_validate_policy_mtr_hierarchy(struct rte_eth_dev *dev,
19966 : : uint32_t meter_id,
19967 : : uint64_t action_flags,
19968 : : bool *is_rss,
19969 : : uint8_t *hierarchy_domain,
19970 : : struct rte_mtr_error *error)
19971 : : {
19972 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19973 : : struct mlx5_flow_meter_info *fm;
19974 : : struct mlx5_flow_meter_policy *policy;
19975 : : uint8_t cnt = 1;
19976 : :
19977 [ # # ]: 0 : if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
19978 : : MLX5_FLOW_FATE_ESWITCH_ACTIONS))
19979 : 0 : return -rte_mtr_error_set(error, EINVAL,
19980 : : RTE_MTR_ERROR_TYPE_POLICER_ACTION_GREEN,
19981 : : NULL,
19982 : : "Multiple fate actions not supported.");
19983 : 0 : *hierarchy_domain = 0;
19984 : 0 : fm = mlx5_flow_meter_find(priv, meter_id, NULL);
19985 : : while (true) {
19986 [ # # ]: 0 : if (!fm)
19987 : 0 : return -rte_mtr_error_set(error, EINVAL,
19988 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
19989 : : "Meter not found in meter hierarchy.");
19990 [ # # ]: 0 : if (fm->def_policy)
19991 : 0 : return -rte_mtr_error_set(error, EINVAL,
19992 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
19993 : : "Non termination meter not supported in hierarchy.");
19994 [ # # ]: 0 : if (!fm->shared)
19995 : 0 : return -rte_mtr_error_set(error, EINVAL,
19996 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
19997 : : "Only shared meter supported in hierarchy.");
19998 : 0 : policy = mlx5_flow_meter_policy_find(dev, fm->policy_id, NULL);
19999 : : MLX5_ASSERT(policy);
20000 : : /**
20001 : : * Only inherit the supported domains of the first meter in
20002 : : * hierarchy.
20003 : : * One meter supports at least one domain.
20004 : : */
20005 [ # # ]: 0 : if (!*hierarchy_domain) {
20006 [ # # ]: 0 : if (policy->transfer)
20007 : 0 : *hierarchy_domain |=
20008 : : MLX5_MTR_DOMAIN_TRANSFER_BIT;
20009 [ # # ]: 0 : if (policy->ingress)
20010 : 0 : *hierarchy_domain |=
20011 : : MLX5_MTR_DOMAIN_INGRESS_BIT;
20012 [ # # ]: 0 : if (policy->egress)
20013 : 0 : *hierarchy_domain |= MLX5_MTR_DOMAIN_EGRESS_BIT;
20014 : : }
20015 [ # # ]: 0 : if (!policy->is_hierarchy) {
20016 : 0 : *is_rss = policy->is_rss;
20017 : : break;
20018 : : }
20019 : 0 : rte_spinlock_lock(&policy->sl);
20020 : 0 : fm = mlx5_flow_meter_hierarchy_next_meter(priv, policy, NULL);
20021 : : rte_spinlock_unlock(&policy->sl);
20022 [ # # ]: 0 : if (++cnt >= MLX5_MTR_CHAIN_MAX_NUM)
20023 : 0 : return -rte_mtr_error_set(error, EINVAL,
20024 : : RTE_MTR_ERROR_TYPE_METER_POLICY, NULL,
20025 : : "Exceed max hierarchy meter number.");
20026 : : }
20027 : 0 : return 0;
20028 : : }
20029 : :
20030 : : /**
20031 : : * Validate meter policy actions.
20032 : : * Dispatcher for action type specific validation.
20033 : : *
20034 : : * @param[in] dev
20035 : : * Pointer to the Ethernet device structure.
20036 : : * @param[in] action
20037 : : * The meter policy action object to validate.
20038 : : * @param[in] attr
20039 : : * Attributes of flow to determine steering domain.
20040 : : * @param[out] error
20041 : : * Perform verbose error reporting if not NULL. Initialized in case of
20042 : : * error only.
20043 : : *
20044 : : * @return
20045 : : * 0 on success, otherwise negative errno value.
20046 : : */
20047 : : static int
20048 : 0 : flow_dv_validate_mtr_policy_acts(struct rte_eth_dev *dev,
20049 : : const struct rte_flow_action *actions[RTE_COLORS],
20050 : : struct rte_flow_attr *attr,
20051 : : bool *is_rss,
20052 : : uint8_t *domain_bitmap,
20053 : : uint8_t *policy_mode,
20054 : : struct rte_mtr_error *error)
20055 : : {
20056 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
20057 : 0 : struct mlx5_sh_config *dev_conf = &priv->sh->config;
20058 : : const struct rte_flow_action *act;
20059 : 0 : uint64_t action_flags[RTE_COLORS] = {0};
20060 : : int actions_n;
20061 : : int i, ret;
20062 : : struct rte_flow_error flow_err;
20063 : 0 : uint8_t domain_color[RTE_COLORS] = {0};
20064 : : uint8_t def_domain = MLX5_MTR_ALL_DOMAIN_BIT;
20065 : 0 : uint8_t hierarchy_domain = 0;
20066 : : const struct rte_flow_action_meter *mtr;
20067 : : const struct rte_flow_action_meter *next_mtr = NULL;
20068 : : bool def_green = false;
20069 : : bool def_yellow = false;
20070 : 0 : const struct rte_flow_action_rss *rss_color[RTE_COLORS] = {NULL};
20071 : : /* Called from RTE API */
20072 [ # # # # : 0 : bool is_root = !(attr->group || (attr->transfer && priv->fdb_def_rule));
# # ]
20073 : :
20074 [ # # ]: 0 : if (!dev_conf->dv_esw_en)
20075 : : def_domain &= ~MLX5_MTR_DOMAIN_TRANSFER_BIT;
20076 : 0 : *domain_bitmap = def_domain;
20077 : : /* Red color could only support DROP action. */
20078 [ # # ]: 0 : if (!actions[RTE_COLOR_RED] ||
20079 [ # # ]: 0 : actions[RTE_COLOR_RED]->type != RTE_FLOW_ACTION_TYPE_DROP)
20080 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20081 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20082 : : NULL, "Red color only supports drop action.");
20083 : : /*
20084 : : * Check default policy actions:
20085 : : * Green / Yellow: no action, Red: drop action
20086 : : * Either G or Y will trigger default policy actions to be created.
20087 : : */
20088 [ # # ]: 0 : if (!actions[RTE_COLOR_GREEN] ||
20089 [ # # ]: 0 : actions[RTE_COLOR_GREEN]->type == RTE_FLOW_ACTION_TYPE_END)
20090 : : def_green = true;
20091 [ # # ]: 0 : if (!actions[RTE_COLOR_YELLOW] ||
20092 [ # # ]: 0 : actions[RTE_COLOR_YELLOW]->type == RTE_FLOW_ACTION_TYPE_END)
20093 : : def_yellow = true;
20094 [ # # ]: 0 : if (def_green && def_yellow) {
20095 : 0 : *policy_mode = MLX5_MTR_POLICY_MODE_DEF;
20096 : 0 : return 0;
20097 [ # # ]: 0 : } else if (!def_green && def_yellow) {
20098 : 0 : *policy_mode = MLX5_MTR_POLICY_MODE_OG;
20099 [ # # ]: 0 : } else if (def_green && !def_yellow) {
20100 : 0 : *policy_mode = MLX5_MTR_POLICY_MODE_OY;
20101 : : } else {
20102 : 0 : *policy_mode = MLX5_MTR_POLICY_MODE_ALL;
20103 : : }
20104 : : /* Set to empty string in case of NULL pointer access by user. */
20105 : 0 : flow_err.message = "";
20106 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
20107 : 0 : act = actions[i];
20108 : 0 : for (action_flags[i] = 0, actions_n = 0;
20109 [ # # # # ]: 0 : act && act->type != RTE_FLOW_ACTION_TYPE_END;
20110 : 0 : act++) {
20111 [ # # ]: 0 : if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
20112 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20113 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20114 : : NULL, "too many actions");
20115 [ # # # # : 0 : switch (act->type) {
# # # # #
# ]
20116 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
20117 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
20118 [ # # ]: 0 : if (!dev_conf->dv_esw_en)
20119 : 0 : return -rte_mtr_error_set(error,
20120 : : ENOTSUP,
20121 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20122 : : NULL, "PORT action validate check"
20123 : : " fail for ESW disable");
20124 : 0 : ret = flow_dv_validate_action_port_id(dev,
20125 : : action_flags[i],
20126 : : act, attr, &flow_err);
20127 [ # # ]: 0 : if (ret)
20128 : 0 : return -rte_mtr_error_set(error,
20129 : : ENOTSUP,
20130 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20131 [ # # ]: 0 : NULL, flow_err.message ?
20132 : : flow_err.message :
20133 : : "PORT action validate check fail");
20134 : 0 : ++actions_n;
20135 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_PORT_ID;
20136 : 0 : break;
20137 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
20138 : 0 : ret = flow_dv_validate_action_mark(dev, act,
20139 : : action_flags[i],
20140 : : attr, &flow_err);
20141 [ # # ]: 0 : if (ret < 0)
20142 : 0 : return -rte_mtr_error_set(error,
20143 : : ENOTSUP,
20144 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20145 [ # # ]: 0 : NULL, flow_err.message ?
20146 : : flow_err.message :
20147 : : "Mark action validate check fail");
20148 [ # # ]: 0 : if (dev_conf->dv_xmeta_en !=
20149 : : MLX5_XMETA_MODE_LEGACY)
20150 : 0 : return -rte_mtr_error_set(error,
20151 : : ENOTSUP,
20152 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20153 : : NULL, "Extend MARK action is "
20154 : : "not supported. Please try use "
20155 : : "default policy for meter.");
20156 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_MARK;
20157 : 0 : ++actions_n;
20158 : 0 : break;
20159 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TAG:
20160 : 0 : ret = flow_dv_validate_action_set_tag(dev,
20161 : : act, action_flags[i],
20162 : : attr, &flow_err);
20163 [ # # ]: 0 : if (ret)
20164 : 0 : return -rte_mtr_error_set(error,
20165 : : ENOTSUP,
20166 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20167 [ # # ]: 0 : NULL, flow_err.message ?
20168 : : flow_err.message :
20169 : : "Set tag action validate check fail");
20170 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_SET_TAG;
20171 : 0 : ++actions_n;
20172 : 0 : break;
20173 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
20174 : 0 : ret = mlx5_flow_validate_action_drop
20175 : : (dev, false, attr, &flow_err);
20176 [ # # ]: 0 : if (ret < 0)
20177 : 0 : return -rte_mtr_error_set(error,
20178 : : ENOTSUP,
20179 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20180 [ # # ]: 0 : NULL, flow_err.message ?
20181 : : flow_err.message :
20182 : : "Drop action validate check fail");
20183 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_DROP;
20184 : 0 : ++actions_n;
20185 : 0 : break;
20186 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
20187 : : /*
20188 : : * Check whether extensive
20189 : : * metadata feature is engaged.
20190 : : */
20191 [ # # ]: 0 : if (dev_conf->dv_flow_en &&
20192 [ # # ]: 0 : (dev_conf->dv_xmeta_en !=
20193 [ # # ]: 0 : MLX5_XMETA_MODE_LEGACY) &&
20194 : 0 : mlx5_flow_ext_mreg_supported(dev))
20195 : 0 : return -rte_mtr_error_set(error,
20196 : : ENOTSUP,
20197 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20198 : : NULL, "Queue action with meta "
20199 : : "is not supported. Please try use "
20200 : : "default policy for meter.");
20201 : 0 : ret = mlx5_flow_validate_action_queue(act,
20202 : : action_flags[i], dev,
20203 : : attr, &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 : : "Queue action validate check fail");
20211 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_QUEUE;
20212 : 0 : ++actions_n;
20213 : 0 : break;
20214 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
20215 [ # # ]: 0 : if (dev_conf->dv_flow_en &&
20216 [ # # ]: 0 : (dev_conf->dv_xmeta_en !=
20217 [ # # ]: 0 : MLX5_XMETA_MODE_LEGACY) &&
20218 : 0 : mlx5_flow_ext_mreg_supported(dev))
20219 : 0 : return -rte_mtr_error_set(error,
20220 : : ENOTSUP,
20221 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20222 : : NULL, "RSS action with meta "
20223 : : "is not supported. Please try use "
20224 : : "default policy for meter.");
20225 : 0 : ret = mlx5_validate_action_rss(dev, act,
20226 : : &flow_err);
20227 [ # # ]: 0 : if (ret < 0)
20228 : 0 : return -rte_mtr_error_set(error,
20229 : : ENOTSUP,
20230 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20231 [ # # ]: 0 : NULL, flow_err.message ?
20232 : : flow_err.message :
20233 : : "RSS action validate check fail");
20234 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_RSS;
20235 : 0 : ++actions_n;
20236 : : /* Either G or Y will set the RSS. */
20237 : 0 : rss_color[i] = act->conf;
20238 : 0 : break;
20239 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
20240 : 0 : ret = flow_dv_validate_action_jump(dev,
20241 : : NULL, act, action_flags[i],
20242 : : attr, true, &flow_err);
20243 [ # # ]: 0 : if (ret)
20244 : 0 : return -rte_mtr_error_set(error,
20245 : : ENOTSUP,
20246 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20247 [ # # ]: 0 : NULL, flow_err.message ?
20248 : : flow_err.message :
20249 : : "Jump action validate check fail");
20250 : 0 : ++actions_n;
20251 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_JUMP;
20252 : 0 : break;
20253 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
20254 : 0 : mtr = act->conf;
20255 [ # # # # ]: 0 : if (next_mtr && next_mtr->mtr_id != mtr->mtr_id)
20256 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20257 : : RTE_MTR_ERROR_TYPE_METER_POLICY, NULL,
20258 : : "Green and Yellow must use the same meter.");
20259 : 0 : ret = flow_dv_validate_policy_mtr_hierarchy(dev,
20260 : 0 : mtr->mtr_id,
20261 : : action_flags[i],
20262 : : is_rss,
20263 : : &hierarchy_domain,
20264 : : error);
20265 [ # # ]: 0 : if (ret)
20266 : 0 : return ret;
20267 : 0 : ++actions_n;
20268 : 0 : action_flags[i] |=
20269 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
20270 : : next_mtr = mtr;
20271 : 0 : break;
20272 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
20273 : 0 : ret = flow_dv_validate_action_modify_field(dev,
20274 : : action_flags[i], act, attr, is_root, &flow_err);
20275 [ # # ]: 0 : if (ret < 0)
20276 : 0 : return -rte_mtr_error_set(error,
20277 : : ENOTSUP,
20278 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20279 [ # # ]: 0 : NULL, flow_err.message ?
20280 : : flow_err.message :
20281 : : "Modify field action validate check fail");
20282 : 0 : ++actions_n;
20283 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_MODIFY_FIELD;
20284 : 0 : break;
20285 : : default:
20286 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20287 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20288 : : NULL,
20289 : : "Doesn't support optional action");
20290 : : }
20291 : : }
20292 [ # # ]: 0 : if (action_flags[i] & MLX5_FLOW_ACTION_PORT_ID) {
20293 : 0 : domain_color[i] = MLX5_MTR_DOMAIN_TRANSFER_BIT;
20294 [ # # ]: 0 : } else if ((action_flags[i] &
20295 : 0 : (MLX5_FLOW_ACTION_RSS | MLX5_FLOW_ACTION_QUEUE)) ||
20296 [ # # ]: 0 : (action_flags[i] & MLX5_FLOW_ACTION_MARK)) {
20297 : : /*
20298 : : * Only support MLX5_XMETA_MODE_LEGACY
20299 : : * so MARK action is only in ingress domain.
20300 : : */
20301 : 0 : domain_color[i] = MLX5_MTR_DOMAIN_INGRESS_BIT;
20302 : : } else {
20303 : 0 : domain_color[i] = def_domain;
20304 [ # # ]: 0 : if (action_flags[i] &&
20305 [ # # ]: 0 : !(action_flags[i] & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
20306 : 0 : domain_color[i] &=
20307 : : ~MLX5_MTR_DOMAIN_TRANSFER_BIT;
20308 : : }
20309 [ # # ]: 0 : if (action_flags[i] &
20310 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
20311 : 0 : domain_color[i] &= hierarchy_domain;
20312 : : /*
20313 : : * Non-termination actions only support NIC Tx domain.
20314 : : * The adjustion should be skipped when there is no
20315 : : * action or only END is provided. The default domains
20316 : : * bit-mask is set to find the MIN intersection.
20317 : : * The action flags checking should also be skipped.
20318 : : */
20319 [ # # ]: 0 : if ((def_green && i == RTE_COLOR_GREEN) ||
20320 [ # # ]: 0 : (def_yellow && i == RTE_COLOR_YELLOW))
20321 : 0 : continue;
20322 : : /*
20323 : : * Validate the drop action mutual exclusion
20324 : : * with other actions. Drop action is mutually-exclusive
20325 : : * with any other action, except for Count action.
20326 : : */
20327 [ # # ]: 0 : if ((action_flags[i] & MLX5_FLOW_ACTION_DROP) &&
20328 [ # # ]: 0 : (action_flags[i] & ~MLX5_FLOW_ACTION_DROP)) {
20329 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20330 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20331 : : NULL, "Drop action is mutually-exclusive "
20332 : : "with any other action");
20333 : : }
20334 : : /* Eswitch has few restrictions on using items and actions */
20335 [ # # ]: 0 : if (domain_color[i] & MLX5_MTR_DOMAIN_TRANSFER_BIT) {
20336 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev) &&
20337 [ # # ]: 0 : action_flags[i] & MLX5_FLOW_ACTION_MARK)
20338 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20339 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20340 : : NULL, "unsupported action MARK");
20341 [ # # ]: 0 : if (action_flags[i] & MLX5_FLOW_ACTION_QUEUE)
20342 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20343 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20344 : : NULL, "unsupported action QUEUE");
20345 [ # # ]: 0 : if (action_flags[i] & MLX5_FLOW_ACTION_RSS)
20346 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20347 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20348 : : NULL, "unsupported action RSS");
20349 [ # # ]: 0 : if (!(action_flags[i] & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
20350 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20351 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20352 : : NULL, "no fate action is found");
20353 : : } else {
20354 [ # # # # ]: 0 : if (!(action_flags[i] & MLX5_FLOW_FATE_ACTIONS) &&
20355 : : (domain_color[i] & MLX5_MTR_DOMAIN_INGRESS_BIT)) {
20356 [ # # ]: 0 : if ((domain_color[i] &
20357 : : MLX5_MTR_DOMAIN_EGRESS_BIT))
20358 : 0 : domain_color[i] =
20359 : : MLX5_MTR_DOMAIN_EGRESS_BIT;
20360 : : else
20361 : 0 : return -rte_mtr_error_set(error,
20362 : : ENOTSUP,
20363 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20364 : : NULL,
20365 : : "no fate action is found");
20366 : : }
20367 : : }
20368 : : }
20369 [ # # # # ]: 0 : if (next_mtr && *policy_mode == MLX5_MTR_POLICY_MODE_ALL) {
20370 : : uint64_t hierarchy_type_flag =
20371 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY | MLX5_FLOW_ACTION_JUMP;
20372 [ # # ]: 0 : if (!(action_flags[RTE_COLOR_GREEN] & hierarchy_type_flag) ||
20373 [ # # ]: 0 : !(action_flags[RTE_COLOR_YELLOW] & hierarchy_type_flag))
20374 : 0 : return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_METER_POLICY,
20375 : : NULL,
20376 : : "Unsupported action in meter hierarchy.");
20377 : : }
20378 : : /* If both colors have RSS, the attributes should be the same. */
20379 [ # # ]: 0 : if (flow_dv_mtr_policy_rss_compare(rss_color[RTE_COLOR_GREEN],
20380 : : rss_color[RTE_COLOR_YELLOW]))
20381 : 0 : return -rte_mtr_error_set(error, EINVAL,
20382 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20383 : : NULL, "policy RSS attr conflict");
20384 [ # # # # ]: 0 : if (rss_color[RTE_COLOR_GREEN] || rss_color[RTE_COLOR_YELLOW])
20385 : 0 : *is_rss = true;
20386 : : /* "domain_color[C]" is non-zero for each color, default is ALL. */
20387 [ # # ]: 0 : if (!def_green && !def_yellow &&
20388 [ # # ]: 0 : domain_color[RTE_COLOR_GREEN] != domain_color[RTE_COLOR_YELLOW] &&
20389 [ # # ]: 0 : !(action_flags[RTE_COLOR_GREEN] & MLX5_FLOW_ACTION_DROP) &&
20390 [ # # ]: 0 : !(action_flags[RTE_COLOR_YELLOW] & MLX5_FLOW_ACTION_DROP))
20391 : 0 : return -rte_mtr_error_set(error, EINVAL,
20392 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20393 : : NULL, "policy domains conflict");
20394 : : /*
20395 : : * At least one color policy is listed in the actions, the domains
20396 : : * to be supported should be the intersection.
20397 : : */
20398 : 0 : *domain_bitmap = domain_color[RTE_COLOR_GREEN] &
20399 : 0 : domain_color[RTE_COLOR_YELLOW];
20400 : 0 : return 0;
20401 : : }
20402 : :
20403 : : static int
20404 : 0 : flow_dv_sync_domain(struct rte_eth_dev *dev, uint32_t domains, uint32_t flags)
20405 : : {
20406 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
20407 : : int ret = 0;
20408 : :
20409 [ # # # # ]: 0 : if ((domains & RTE_PMD_MLX5_DOMAIN_BIT_NIC_RX) && priv->sh->rx_domain != NULL) {
20410 : : ret = mlx5_os_flow_dr_sync_domain(priv->sh->rx_domain,
20411 : : flags);
20412 [ # # ]: 0 : if (ret != 0)
20413 : : return ret;
20414 : : }
20415 [ # # # # ]: 0 : if ((domains & RTE_PMD_MLX5_DOMAIN_BIT_NIC_TX) && priv->sh->tx_domain != NULL) {
20416 : : ret = mlx5_os_flow_dr_sync_domain(priv->sh->tx_domain, flags);
20417 [ # # ]: 0 : if (ret != 0)
20418 : : return ret;
20419 : : }
20420 [ # # # # ]: 0 : if ((domains & RTE_PMD_MLX5_DOMAIN_BIT_FDB) && priv->sh->fdb_domain != NULL) {
20421 : : ret = mlx5_os_flow_dr_sync_domain(priv->sh->fdb_domain, flags);
20422 [ # # ]: 0 : if (ret != 0)
20423 : 0 : return ret;
20424 : : }
20425 : : return 0;
20426 : : }
20427 : :
20428 : : /**
20429 : : * Discover the number of available flow priorities
20430 : : * by trying to create a flow with the highest priority value
20431 : : * for each possible number.
20432 : : *
20433 : : * @param[in] dev
20434 : : * Ethernet device.
20435 : : * @param[in] vprio
20436 : : * List of possible number of available priorities.
20437 : : * @param[in] vprio_n
20438 : : * Size of @p vprio array.
20439 : : * @return
20440 : : * On success, number of available flow priorities.
20441 : : * On failure, a negative errno-style code and rte_errno is set.
20442 : : */
20443 : : static int
20444 : 0 : flow_dv_discover_priorities(struct rte_eth_dev *dev,
20445 : : const uint16_t *vprio, int vprio_n)
20446 : : {
20447 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
20448 : 0 : struct mlx5_indexed_pool *pool = priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW];
20449 : : struct rte_flow_item_eth eth;
20450 : 0 : struct rte_flow_item item = {
20451 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
20452 : : .spec = ð,
20453 : : .mask = ð,
20454 : : };
20455 : 0 : struct mlx5_flow_dv_matcher matcher = {
20456 : : .mask = {
20457 : : .size = sizeof(matcher.mask.buf),
20458 : : },
20459 : : };
20460 : : union mlx5_flow_tbl_key tbl_key;
20461 : : struct mlx5_flow flow;
20462 : : void *action;
20463 : : struct rte_flow_error error;
20464 : : uint8_t misc_mask;
20465 : : int i, err, ret = -ENOTSUP;
20466 : :
20467 : : /*
20468 : : * Prepare a flow with a catch-all pattern and a drop action.
20469 : : * Use drop queue, because shared drop action may be unavailable.
20470 : : */
20471 : 0 : action = priv->drop_queue.hrxq->action;
20472 [ # # ]: 0 : if (action == NULL) {
20473 : 0 : DRV_LOG(ERR, "Priority discovery requires a drop action");
20474 : 0 : rte_errno = ENOTSUP;
20475 : 0 : return -rte_errno;
20476 : : }
20477 : : memset(&flow, 0, sizeof(flow));
20478 : 0 : flow.handle = mlx5_ipool_zmalloc(pool, &flow.handle_idx);
20479 [ # # ]: 0 : if (flow.handle == NULL) {
20480 : 0 : DRV_LOG(ERR, "Cannot create flow handle");
20481 : 0 : rte_errno = ENOMEM;
20482 : 0 : return -rte_errno;
20483 : : }
20484 : 0 : flow.ingress = true;
20485 : 0 : flow.dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param);
20486 : 0 : flow.dv.actions[0] = action;
20487 : 0 : flow.dv.actions_n = 1;
20488 : : memset(ð, 0, sizeof(eth));
20489 : 0 : flow_dv_translate_item_eth(matcher.mask.buf, &item,
20490 : : /* inner */ false, /* group */ 0,
20491 : : MLX5_SET_MATCHER_SW_M);
20492 : 0 : flow_dv_translate_item_eth(flow.dv.value.buf, &item,
20493 : : /* inner */ false, /* group */ 0,
20494 : : MLX5_SET_MATCHER_SW_V);
20495 : 0 : matcher.crc = rte_raw_cksum(matcher.mask.buf, matcher.mask.size);
20496 [ # # ]: 0 : for (i = 0; i < vprio_n; i++) {
20497 : : /* Configure the next proposed maximum priority. */
20498 : 0 : matcher.priority = vprio[i] - 1;
20499 : : memset(&tbl_key, 0, sizeof(tbl_key));
20500 : 0 : err = flow_dv_matcher_register(dev, &matcher, &tbl_key, &flow,
20501 : : /* tunnel */ NULL,
20502 : : /* group */ 0,
20503 : : &error);
20504 [ # # ]: 0 : if (err != 0) {
20505 : : /* This action is pure SW and must always succeed. */
20506 : 0 : DRV_LOG(ERR, "Cannot register matcher");
20507 : 0 : ret = -rte_errno;
20508 : 0 : break;
20509 : : }
20510 : : /* Try to apply the flow to HW. */
20511 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(flow.handle->dvh.matcher->mask.buf);
20512 : : __flow_dv_adjust_buf_size(&flow.dv.value.size, misc_mask);
20513 : 0 : err = mlx5_flow_os_create_flow
20514 : : (flow.handle->dvh.matcher->matcher_object,
20515 : 0 : (void *)&flow.dv.value, flow.dv.actions_n,
20516 : : flow.dv.actions, &flow.handle->drv_flow);
20517 : : if (err == 0) {
20518 : 0 : claim_zero(mlx5_flow_os_destroy_flow
20519 : : (flow.handle->drv_flow));
20520 : 0 : flow.handle->drv_flow = NULL;
20521 : : }
20522 : 0 : claim_zero(flow_dv_matcher_release(dev, flow.handle));
20523 [ # # ]: 0 : if (err != 0)
20524 : : break;
20525 : 0 : ret = vprio[i];
20526 : : }
20527 : 0 : mlx5_ipool_free(pool, flow.handle_idx);
20528 : : /* Set rte_errno if no expected priority value matched. */
20529 [ # # ]: 0 : if (ret < 0)
20530 : 0 : rte_errno = -ret;
20531 : : return ret;
20532 : : }
20533 : :
20534 : : const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops = {
20535 : : .list_create = flow_legacy_list_create,
20536 : : .list_destroy = flow_legacy_list_destroy,
20537 : : .validate = flow_dv_validate,
20538 : : .prepare = flow_dv_prepare,
20539 : : .translate = flow_dv_translate,
20540 : : .apply = flow_dv_apply,
20541 : : .remove = flow_dv_remove,
20542 : : .destroy = flow_dv_destroy,
20543 : : .query = flow_dv_query,
20544 : : .create_mtr_tbls = flow_dv_create_mtr_tbls,
20545 : : .destroy_mtr_tbls = flow_dv_destroy_mtr_tbls,
20546 : : .destroy_mtr_drop_tbls = flow_dv_destroy_mtr_drop_tbls,
20547 : : .create_meter = flow_dv_mtr_alloc,
20548 : : .free_meter = flow_dv_aso_mtr_release_to_pool,
20549 : : .validate_mtr_acts = flow_dv_validate_mtr_policy_acts,
20550 : : .create_mtr_acts = flow_dv_create_mtr_policy_acts,
20551 : : .destroy_mtr_acts = flow_dv_destroy_mtr_policy_acts,
20552 : : .create_policy_rules = flow_dv_create_policy_rules,
20553 : : .destroy_policy_rules = flow_dv_destroy_policy_rules,
20554 : : .create_def_policy = flow_dv_create_def_policy,
20555 : : .destroy_def_policy = flow_dv_destroy_def_policy,
20556 : : .meter_sub_policy_rss_prepare = flow_dv_meter_sub_policy_rss_prepare,
20557 : : .meter_hierarchy_rule_create = flow_dv_meter_hierarchy_rule_create,
20558 : : .destroy_sub_policy_with_rxq = flow_dv_destroy_sub_policy_with_rxq,
20559 : : .counter_alloc = flow_dv_counter_allocate,
20560 : : .counter_free = flow_dv_counter_free,
20561 : : .counter_query = flow_dv_counter_query,
20562 : : .get_aged_flows = flow_dv_get_aged_flows,
20563 : : .action_validate = flow_dv_action_validate,
20564 : : .action_create = flow_dv_action_create,
20565 : : .action_destroy = flow_dv_action_destroy,
20566 : : .action_update = flow_dv_action_update,
20567 : : .action_query = flow_dv_action_query,
20568 : : .sync_domain = flow_dv_sync_domain,
20569 : : .discover_priorities = flow_dv_discover_priorities,
20570 : : .item_create = flow_dv_item_create,
20571 : : .item_release = flow_dv_item_release,
20572 : : };
20573 : :
20574 : : #endif /* HAVE_IBV_FLOW_DV_SUPPORT */
|