Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright 2018 Mellanox Technologies, Ltd
3 : : */
4 : :
5 : : #include <sys/queue.h>
6 : : #include <stdalign.h>
7 : : #include <stdint.h>
8 : : #include <string.h>
9 : : #include <unistd.h>
10 : :
11 : : #include <rte_bitops.h>
12 : : #include <rte_common.h>
13 : : #include <rte_ether.h>
14 : : #include <ethdev_driver.h>
15 : : #include <rte_flow.h>
16 : : #include <rte_flow_driver.h>
17 : : #include <rte_malloc.h>
18 : : #include <rte_cycles.h>
19 : : #include <bus_pci_driver.h>
20 : : #include <rte_ip.h>
21 : : #include <rte_gre.h>
22 : : #include <rte_vxlan.h>
23 : : #include <rte_gtp.h>
24 : : #include <rte_eal_paging.h>
25 : : #include <rte_mpls.h>
26 : : #include <rte_mtr.h>
27 : : #include <rte_mtr_driver.h>
28 : : #include <rte_tailq.h>
29 : :
30 : : #include <mlx5_glue.h>
31 : : #include <mlx5_devx_cmds.h>
32 : : #include <mlx5_prm.h>
33 : : #include <mlx5_malloc.h>
34 : :
35 : : #include "mlx5_defs.h"
36 : : #include "mlx5.h"
37 : : #include "mlx5_common_os.h"
38 : : #include "mlx5_flow.h"
39 : : #include "mlx5_flow_os.h"
40 : : #include "mlx5_rx.h"
41 : : #include "mlx5_tx.h"
42 : : #include "rte_pmd_mlx5.h"
43 : :
44 : : #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
45 : :
46 : : #ifndef HAVE_IBV_FLOW_DEVX_COUNTERS
47 : : #define MLX5DV_FLOW_ACTION_COUNTERS_DEVX 0
48 : : #endif
49 : :
50 : : #ifndef HAVE_MLX5DV_DR_ESWITCH
51 : : #ifndef MLX5DV_FLOW_TABLE_TYPE_FDB
52 : : #define MLX5DV_FLOW_TABLE_TYPE_FDB 0
53 : : #endif
54 : : #endif
55 : :
56 : : #ifndef HAVE_MLX5DV_DR
57 : : #define MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL 1
58 : : #endif
59 : :
60 : : /* VLAN header definitions */
61 : : #define MLX5DV_FLOW_VLAN_PCP_SHIFT 13
62 : : #define MLX5DV_FLOW_VLAN_PCP_MASK (0x7 << MLX5DV_FLOW_VLAN_PCP_SHIFT)
63 : : #define MLX5DV_FLOW_VLAN_VID_MASK 0x0fff
64 : : #define MLX5DV_FLOW_VLAN_PCP_MASK_BE RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK)
65 : : #define MLX5DV_FLOW_VLAN_VID_MASK_BE RTE_BE16(MLX5DV_FLOW_VLAN_VID_MASK)
66 : :
67 : : #define MLX5_ITEM_VALID(item, key_type) \
68 : : (((MLX5_SET_MATCHER_SW & (key_type)) && !((item)->spec)) || \
69 : : ((MLX5_SET_MATCHER_HS_V == (key_type)) && !((item)->spec)) || \
70 : : ((MLX5_SET_MATCHER_HS_M == (key_type)) && !((item)->mask)))
71 : :
72 : : #define MLX5_ITEM_UPDATE(item, key_type, v, m, gm) \
73 : : do { \
74 : : if ((key_type) == MLX5_SET_MATCHER_SW_V) { \
75 : : v = (item)->spec; \
76 : : m = (item)->mask ? (item)->mask : (gm); \
77 : : } else if ((key_type) == MLX5_SET_MATCHER_HS_V) { \
78 : : v = (item)->spec; \
79 : : m = (v); \
80 : : } else { \
81 : : v = (item)->mask ? (item)->mask : (gm); \
82 : : m = (v); \
83 : : } \
84 : : } while (0)
85 : :
86 : : #define CALC_MODI_ID(field, level) \
87 : : (((level) > 1) ? MLX5_MODI_IN_##field : MLX5_MODI_OUT_##field)
88 : :
89 : : union flow_dv_attr {
90 : : struct {
91 : : uint32_t valid:1;
92 : : uint32_t ipv4:1;
93 : : uint32_t ipv6:1;
94 : : uint32_t tcp:1;
95 : : uint32_t udp:1;
96 : : uint32_t reserved:27;
97 : : };
98 : : uint32_t attr;
99 : : };
100 : :
101 : : static int
102 : : flow_dv_port_id_action_resource_release(struct rte_eth_dev *dev,
103 : : uint32_t port_id);
104 : : static void
105 : : flow_dv_shared_rss_action_release(struct rte_eth_dev *dev, uint32_t srss);
106 : :
107 : : static int
108 : : flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev,
109 : : uint32_t rix_jump);
110 : :
111 : : /**
112 : : * Initialize flow attributes structure according to flow items' types.
113 : : *
114 : : * flow_dv_validate() avoids multiple L3/L4 layers cases other than tunnel
115 : : * mode. For tunnel mode, the items to be modified are the outermost ones.
116 : : *
117 : : * @param[in] item
118 : : * Pointer to item specification.
119 : : * @param[out] attr
120 : : * Pointer to flow attributes structure.
121 : : * @param[in] dev_flow
122 : : * Pointer to the sub flow.
123 : : * @param[in] tunnel_decap
124 : : * Whether action is after tunnel decapsulation.
125 : : */
126 : : static void
127 : 0 : flow_dv_attr_init(const struct rte_flow_item *item, union flow_dv_attr *attr,
128 : : struct mlx5_flow *dev_flow, bool tunnel_decap)
129 : : {
130 : 0 : uint64_t layers = dev_flow->handle->layers;
131 : : bool tunnel_match = false;
132 : :
133 : : /*
134 : : * If layers is already initialized, it means this dev_flow is the
135 : : * suffix flow, the layers flags is set by the prefix flow. Need to
136 : : * use the layer flags from prefix flow as the suffix flow may not
137 : : * have the user defined items as the flow is split.
138 : : */
139 [ # # ]: 0 : if (layers) {
140 [ # # ]: 0 : if (tunnel_decap) {
141 : : /*
142 : : * If decap action before modify, it means the driver
143 : : * should take the inner as outer for the modify actions.
144 : : */
145 : 0 : layers = ((layers >> 6) & MLX5_FLOW_LAYER_OUTER);
146 : : }
147 [ # # ]: 0 : if (layers & MLX5_FLOW_LAYER_OUTER_L3_IPV4)
148 : 0 : attr->ipv4 = 1;
149 [ # # ]: 0 : else if (layers & MLX5_FLOW_LAYER_OUTER_L3_IPV6)
150 : 0 : attr->ipv6 = 1;
151 [ # # ]: 0 : if (layers & MLX5_FLOW_LAYER_OUTER_L4_TCP)
152 : 0 : attr->tcp = 1;
153 [ # # ]: 0 : else if (layers & MLX5_FLOW_LAYER_OUTER_L4_UDP)
154 : 0 : attr->udp = 1;
155 : 0 : attr->valid = 1;
156 : 0 : return;
157 : : }
158 [ # # ]: 0 : for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
159 : : uint8_t next_protocol = 0xff;
160 [ # # # # : 0 : switch (item->type) {
# # ]
161 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
162 : : case RTE_FLOW_ITEM_TYPE_NVGRE:
163 : : case RTE_FLOW_ITEM_TYPE_VXLAN:
164 : : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
165 : : case RTE_FLOW_ITEM_TYPE_GENEVE:
166 : : case RTE_FLOW_ITEM_TYPE_MPLS:
167 : : case RTE_FLOW_ITEM_TYPE_GTP:
168 [ # # ]: 0 : if (tunnel_decap) {
169 : 0 : attr->attr = 0;
170 : : tunnel_match = true;
171 : : }
172 : : break;
173 : 0 : case RTE_FLOW_ITEM_TYPE_IPV4:
174 [ # # ]: 0 : if (!attr->ipv6)
175 : 0 : attr->ipv4 = 1;
176 [ # # ]: 0 : if (item->mask != NULL &&
177 : : ((const struct rte_flow_item_ipv4 *)
178 [ # # ]: 0 : item->mask)->hdr.next_proto_id)
179 : 0 : next_protocol =
180 : : ((const struct rte_flow_item_ipv4 *)
181 : 0 : (item->spec))->hdr.next_proto_id &
182 : : ((const struct rte_flow_item_ipv4 *)
183 : : (item->mask))->hdr.next_proto_id;
184 : 0 : if ((next_protocol == IPPROTO_IPIP ||
185 [ # # ]: 0 : next_protocol == IPPROTO_IPV6) && tunnel_decap &&
186 [ # # ]: 0 : !tunnel_match)
187 : 0 : attr->attr = 0;
188 : : break;
189 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6:
190 [ # # ]: 0 : if (!attr->ipv4)
191 : 0 : attr->ipv6 = 1;
192 [ # # ]: 0 : if (item->mask != NULL &&
193 : : ((const struct rte_flow_item_ipv6 *)
194 [ # # ]: 0 : item->mask)->hdr.proto)
195 : 0 : next_protocol =
196 : : ((const struct rte_flow_item_ipv6 *)
197 : 0 : (item->spec))->hdr.proto &
198 : : ((const struct rte_flow_item_ipv6 *)
199 : : (item->mask))->hdr.proto;
200 : 0 : if ((next_protocol == IPPROTO_IPIP ||
201 [ # # ]: 0 : next_protocol == IPPROTO_IPV6) && tunnel_decap &&
202 [ # # ]: 0 : !tunnel_match)
203 : 0 : attr->attr = 0;
204 : : break;
205 : 0 : case RTE_FLOW_ITEM_TYPE_UDP:
206 [ # # ]: 0 : if (!attr->tcp)
207 : 0 : attr->udp = 1;
208 : : break;
209 : 0 : case RTE_FLOW_ITEM_TYPE_TCP:
210 [ # # ]: 0 : if (!attr->udp)
211 : 0 : attr->tcp = 1;
212 : : break;
213 : : default:
214 : : break;
215 : : }
216 : : }
217 : 0 : attr->valid = 1;
218 : : }
219 : :
220 : : struct field_modify_info modify_eth[] = {
221 : : {4, 0, MLX5_MODI_OUT_DMAC_47_16},
222 : : {2, 4, MLX5_MODI_OUT_DMAC_15_0},
223 : : {4, 6, MLX5_MODI_OUT_SMAC_47_16},
224 : : {2, 10, MLX5_MODI_OUT_SMAC_15_0},
225 : : {0, 0, 0},
226 : : };
227 : :
228 : : struct field_modify_info modify_vlan_out_first_vid[] = {
229 : : /* Size in bits !!! */
230 : : {12, 0, MLX5_MODI_OUT_FIRST_VID},
231 : : {0, 0, 0},
232 : : };
233 : :
234 : : struct field_modify_info modify_ipv4[] = {
235 : : {1, 1, MLX5_MODI_OUT_IP_DSCP},
236 : : {1, 8, MLX5_MODI_OUT_IPV4_TTL},
237 : : {4, 12, MLX5_MODI_OUT_SIPV4},
238 : : {4, 16, MLX5_MODI_OUT_DIPV4},
239 : : {0, 0, 0},
240 : : };
241 : :
242 : : struct field_modify_info modify_ipv6[] = {
243 : : {1, 0, MLX5_MODI_OUT_IP_DSCP},
244 : : {1, 7, MLX5_MODI_OUT_IPV6_HOPLIMIT},
245 : : {4, 8, MLX5_MODI_OUT_SIPV6_127_96},
246 : : {4, 12, MLX5_MODI_OUT_SIPV6_95_64},
247 : : {4, 16, MLX5_MODI_OUT_SIPV6_63_32},
248 : : {4, 20, MLX5_MODI_OUT_SIPV6_31_0},
249 : : {4, 24, MLX5_MODI_OUT_DIPV6_127_96},
250 : : {4, 28, MLX5_MODI_OUT_DIPV6_95_64},
251 : : {4, 32, MLX5_MODI_OUT_DIPV6_63_32},
252 : : {4, 36, MLX5_MODI_OUT_DIPV6_31_0},
253 : : {0, 0, 0},
254 : : };
255 : :
256 : : struct field_modify_info modify_ipv6_traffic_class[] = {
257 : : {1, 0, MLX5_MODI_OUT_IPV6_TRAFFIC_CLASS},
258 : : {0, 0, 0},
259 : : };
260 : :
261 : : struct field_modify_info modify_udp[] = {
262 : : {2, 0, MLX5_MODI_OUT_UDP_SPORT},
263 : : {2, 2, MLX5_MODI_OUT_UDP_DPORT},
264 : : {0, 0, 0},
265 : : };
266 : :
267 : : struct field_modify_info modify_tcp[] = {
268 : : {2, 0, MLX5_MODI_OUT_TCP_SPORT},
269 : : {2, 2, MLX5_MODI_OUT_TCP_DPORT},
270 : : {4, 4, MLX5_MODI_OUT_TCP_SEQ_NUM},
271 : : {4, 8, MLX5_MODI_OUT_TCP_ACK_NUM},
272 : : {0, 0, 0},
273 : : };
274 : :
275 : : enum mlx5_l3_tunnel_detection {
276 : : l3_tunnel_none,
277 : : l3_tunnel_outer,
278 : : l3_tunnel_inner
279 : : };
280 : :
281 : : static enum mlx5_l3_tunnel_detection
282 : : mlx5_flow_tunnel_ip_check(const struct rte_flow_item *item __rte_unused,
283 : : uint8_t next_protocol, uint64_t item_flags,
284 : : uint64_t *l3_tunnel_flag)
285 : : {
286 : : enum mlx5_l3_tunnel_detection td = l3_tunnel_none;
287 : :
288 : : MLX5_ASSERT(item->type == RTE_FLOW_ITEM_TYPE_IPV4 ||
289 : : item->type == RTE_FLOW_ITEM_TYPE_IPV6);
290 [ # # # # : 0 : if ((item_flags & MLX5_FLOW_LAYER_OUTER_L3) == 0) {
# # # # ]
291 [ # # # # : 0 : switch (next_protocol) {
# # # # #
# # # ]
292 : : case IPPROTO_IPIP:
293 : : td = l3_tunnel_outer;
294 : : *l3_tunnel_flag = MLX5_FLOW_LAYER_IPIP;
295 : : break;
296 : : case IPPROTO_IPV6:
297 : : td = l3_tunnel_outer;
298 : : *l3_tunnel_flag = MLX5_FLOW_LAYER_IPV6_ENCAP;
299 : : break;
300 : : default:
301 : : break;
302 : : }
303 : : } else {
304 : : td = l3_tunnel_inner;
305 : : *l3_tunnel_flag = item->type == RTE_FLOW_ITEM_TYPE_IPV4 ?
306 : : MLX5_FLOW_LAYER_IPIP :
307 : : MLX5_FLOW_LAYER_IPV6_ENCAP;
308 : : }
309 : : return td;
310 : : }
311 : :
312 : : static inline struct mlx5_hlist *
313 : 0 : flow_dv_hlist_prepare(struct mlx5_dev_ctx_shared *sh, RTE_ATOMIC(struct mlx5_hlist *) *phl,
314 : : const char *name, uint32_t size, bool direct_key,
315 : : bool lcores_share, void *ctx,
316 : : mlx5_list_create_cb cb_create,
317 : : mlx5_list_match_cb cb_match,
318 : : mlx5_list_remove_cb cb_remove,
319 : : mlx5_list_clone_cb cb_clone,
320 : : mlx5_list_clone_free_cb cb_clone_free,
321 : : struct rte_flow_error *error)
322 : : {
323 : : struct mlx5_hlist *hl;
324 : : struct mlx5_hlist *expected = NULL;
325 : : char s[MLX5_NAME_SIZE];
326 : :
327 : 0 : hl = rte_atomic_load_explicit(phl, rte_memory_order_seq_cst);
328 [ # # ]: 0 : if (likely(hl))
329 : : return hl;
330 : 0 : snprintf(s, sizeof(s), "%s_%s", sh->ibdev_name, name);
331 : 0 : hl = mlx5_hlist_create(s, size, direct_key, lcores_share,
332 : : ctx, cb_create, cb_match, cb_remove, cb_clone,
333 : : cb_clone_free);
334 [ # # ]: 0 : if (!hl) {
335 : 0 : DRV_LOG(ERR, "%s hash creation failed", name);
336 : 0 : rte_flow_error_set(error, ENOMEM,
337 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
338 : : "cannot allocate resource memory");
339 : 0 : return NULL;
340 : : }
341 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(phl, &expected, hl,
342 : : rte_memory_order_seq_cst,
343 : : rte_memory_order_seq_cst)) {
344 : 0 : mlx5_hlist_destroy(hl);
345 : 0 : hl = rte_atomic_load_explicit(phl, rte_memory_order_seq_cst);
346 : : }
347 : : return hl;
348 : : }
349 : :
350 : : /* Update VLAN's VID/PCP based on input rte_flow_action.
351 : : *
352 : : * @param[in] action
353 : : * Pointer to struct rte_flow_action.
354 : : * @param[out] vlan
355 : : * Pointer to struct rte_vlan_hdr.
356 : : */
357 : : static void
358 : 0 : mlx5_update_vlan_vid_pcp(const struct rte_flow_action *action,
359 : : struct rte_vlan_hdr *vlan)
360 : : {
361 : : uint16_t vlan_tci;
362 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP) {
363 : 0 : vlan_tci =
364 : : ((const struct rte_flow_action_of_set_vlan_pcp *)
365 : 0 : action->conf)->vlan_pcp;
366 : 0 : vlan_tci = vlan_tci << MLX5DV_FLOW_VLAN_PCP_SHIFT;
367 : 0 : vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
368 : 0 : vlan->vlan_tci |= vlan_tci;
369 [ # # ]: 0 : } else if (action->type == RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID) {
370 : 0 : vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
371 [ # # ]: 0 : vlan->vlan_tci |= rte_be_to_cpu_16
372 : : (((const struct rte_flow_action_of_set_vlan_vid *)
373 : : action->conf)->vlan_vid);
374 : : }
375 : 0 : }
376 : :
377 : : /**
378 : : * Convert modify-header action to DV specification.
379 : : *
380 : : * Data length of each action is determined by provided field description
381 : : * and the item mask. Data bit offset and width of each action is determined
382 : : * by provided item mask.
383 : : *
384 : : * @param[in] item
385 : : * Pointer to item specification.
386 : : * @param[in] field
387 : : * Pointer to field modification information.
388 : : * For MLX5_MODIFICATION_TYPE_SET specifies destination field.
389 : : * For MLX5_MODIFICATION_TYPE_ADD specifies destination field.
390 : : * For MLX5_MODIFICATION_TYPE_COPY specifies source field.
391 : : * For MLX5_MODIFICATION_TYPE_ADD_FIELD specifies source field.
392 : : * @param[in] dest
393 : : * Destination field info for MLX5_MODIFICATION_TYPE_COPY and
394 : : * MLX5_MODIFICATION_TYPE_ADD_FIELD in @type.
395 : : * Negative offset value sets the same offset as source offset.
396 : : * size field is ignored, value is taken from source field.
397 : : * @param[in,out] resource
398 : : * Pointer to the modify-header resource.
399 : : * @param[in] type
400 : : * Type of modification.
401 : : * @param[out] error
402 : : * Pointer to the error structure.
403 : : *
404 : : * @return
405 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
406 : : */
407 : : int
408 : 0 : flow_dv_convert_modify_action(struct rte_flow_item *item,
409 : : struct field_modify_info *field,
410 : : struct field_modify_info *dest,
411 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
412 : : uint32_t type, struct rte_flow_error *error)
413 : : {
414 : 0 : uint32_t i = resource->actions_num;
415 : 0 : struct mlx5_modification_cmd *actions = resource->actions;
416 : : uint32_t carry_b = 0;
417 : : bool to_dest;
418 : :
419 : : /*
420 : : * The item and mask are provided in big-endian format.
421 : : * The fields should be presented as in big-endian format either.
422 : : * Mask must be always present, it defines the actual field width.
423 : : */
424 : : MLX5_ASSERT(item->mask);
425 : : MLX5_ASSERT(field->size);
426 : 0 : to_dest = type == MLX5_MODIFICATION_TYPE_COPY ||
427 : 0 : type == MLX5_MODIFICATION_TYPE_ADD_FIELD;
428 : : do {
429 : : uint32_t size_b;
430 : : uint32_t off_b;
431 : : uint32_t mask;
432 : : uint32_t data;
433 : : bool next_field = true;
434 : : bool next_dest = true;
435 : :
436 [ # # ]: 0 : if (i >= MLX5_MAX_MODIFY_NUM)
437 : 0 : return rte_flow_error_set(error, EINVAL,
438 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
439 : : "too many items to modify");
440 : : /* Fetch variable byte size mask from the array. */
441 : 0 : mask = flow_dv_fetch_field((const uint8_t *)item->mask +
442 : 0 : field->offset, field->size);
443 [ # # ]: 0 : if (!mask) {
444 : 0 : ++field;
445 : : continue;
446 : : }
447 [ # # # # ]: 0 : if (to_dest && field->is_flex) {
448 : 0 : off_b = 32 - field->shift + carry_b - field->size * CHAR_BIT;
449 : 0 : size_b = field->size * CHAR_BIT - carry_b;
450 : : } else {
451 : : /* Deduce actual data width in bits from mask value. */
452 : 0 : off_b = rte_bsf32(mask) + carry_b;
453 : 0 : size_b = sizeof(uint32_t) * CHAR_BIT -
454 : 0 : off_b - rte_clz32(mask);
455 : : }
456 : : MLX5_ASSERT(size_b);
457 : 0 : actions[i] = (struct mlx5_modification_cmd) {
458 : : .action_type = type,
459 : 0 : .field = field->id,
460 : : .offset = off_b,
461 : : .length = (size_b == sizeof(uint32_t) * CHAR_BIT) ?
462 [ # # ]: 0 : 0 : size_b,
463 : : };
464 [ # # ]: 0 : if (to_dest) {
465 : : MLX5_ASSERT(dest);
466 : 0 : actions[i].dst_field = dest->id;
467 : 0 : actions[i].dst_offset =
468 [ # # ]: 0 : (int)dest->offset < 0 ? off_b : dest->offset;
469 : : /* Convert entire record to big-endian format. */
470 [ # # ]: 0 : actions[i].data1 = rte_cpu_to_be_32(actions[i].data1);
471 : : /*
472 : : * Destination field overflow. Copy leftovers of
473 : : * a source field to the next destination field.
474 : : */
475 [ # # # # ]: 0 : if ((size_b > dest->size * CHAR_BIT - dest->offset) &&
476 : : dest->size != 0) {
477 : 0 : actions[i].length =
478 : 0 : dest->size * CHAR_BIT - dest->offset;
479 : 0 : carry_b += actions[i].length;
480 : 0 : next_field = false;
481 : : } else {
482 : : carry_b = 0;
483 : : }
484 : : /*
485 : : * Not enough bits in a source filed to fill a
486 : : * destination field. Switch to the next source.
487 : : */
488 [ # # ]: 0 : if ((size_b < dest->size * CHAR_BIT - dest->offset) &&
489 [ # # ]: 0 : ((size_b == field->size * CHAR_BIT - off_b) ||
490 [ # # ]: 0 : field->is_flex)) {
491 : 0 : actions[i].length = size_b;
492 : 0 : dest->offset += actions[i].length;
493 : : next_dest = false;
494 : : }
495 : : } else {
496 : : MLX5_ASSERT(item->spec);
497 : 0 : data = flow_dv_fetch_field((const uint8_t *)item->spec +
498 : : field->offset, field->size);
499 : : /* Shift out the trailing masked bits from data. */
500 : 0 : data = (data & mask) >> off_b;
501 [ # # ]: 0 : if (field->is_flex)
502 : 0 : actions[i].offset = 32 - field->shift - field->size * CHAR_BIT;
503 [ # # ]: 0 : actions[i].data1 = rte_cpu_to_be_32(data);
504 : : }
505 : : /* Convert entire record to expected big-endian format. */
506 [ # # ]: 0 : actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
507 [ # # ]: 0 : if ((!to_dest ||
508 [ # # # # ]: 0 : dest->id != (enum mlx5_modification_field)UINT32_MAX) &&
509 : : field->id != (enum mlx5_modification_field)UINT32_MAX)
510 : 0 : ++i;
511 [ # # ]: 0 : if (next_dest && to_dest)
512 : 0 : ++dest;
513 [ # # ]: 0 : if (next_field)
514 : 0 : ++field;
515 [ # # ]: 0 : } while (field->size);
516 [ # # ]: 0 : if (resource->actions_num == i)
517 : 0 : return rte_flow_error_set(error, EINVAL,
518 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
519 : : "invalid modification flow item");
520 : 0 : resource->actions_num = i;
521 : 0 : return 0;
522 : : }
523 : :
524 : : /**
525 : : * Convert modify-header set IPv4 address action to DV specification.
526 : : *
527 : : * @param[in,out] resource
528 : : * Pointer to the modify-header resource.
529 : : * @param[in] action
530 : : * Pointer to action specification.
531 : : * @param[out] error
532 : : * Pointer to the error structure.
533 : : *
534 : : * @return
535 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
536 : : */
537 : : static int
538 : 0 : flow_dv_convert_action_modify_ipv4
539 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
540 : : const struct rte_flow_action *action,
541 : : struct rte_flow_error *error)
542 : : {
543 : 0 : const struct rte_flow_action_set_ipv4 *conf =
544 : : (const struct rte_flow_action_set_ipv4 *)(action->conf);
545 [ # # ]: 0 : struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
546 : : struct rte_flow_item_ipv4 ipv4;
547 : : struct rte_flow_item_ipv4 ipv4_mask;
548 : :
549 : : memset(&ipv4, 0, sizeof(ipv4));
550 : : memset(&ipv4_mask, 0, sizeof(ipv4_mask));
551 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC) {
552 : 0 : ipv4.hdr.src_addr = conf->ipv4_addr;
553 : 0 : ipv4_mask.hdr.src_addr = rte_flow_item_ipv4_mask.hdr.src_addr;
554 : : } else {
555 : 0 : ipv4.hdr.dst_addr = conf->ipv4_addr;
556 : 0 : ipv4_mask.hdr.dst_addr = rte_flow_item_ipv4_mask.hdr.dst_addr;
557 : : }
558 : 0 : item.spec = &ipv4;
559 : 0 : item.mask = &ipv4_mask;
560 : 0 : return flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
561 : : MLX5_MODIFICATION_TYPE_SET, error);
562 : : }
563 : :
564 : : /**
565 : : * Convert modify-header set IPv6 address action to DV specification.
566 : : *
567 : : * @param[in,out] resource
568 : : * Pointer to the modify-header resource.
569 : : * @param[in] action
570 : : * Pointer to action specification.
571 : : * @param[out] error
572 : : * Pointer to the error structure.
573 : : *
574 : : * @return
575 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
576 : : */
577 : : static int
578 : 0 : flow_dv_convert_action_modify_ipv6
579 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
580 : : const struct rte_flow_action *action,
581 : : struct rte_flow_error *error)
582 : : {
583 : 0 : const struct rte_flow_action_set_ipv6 *conf =
584 : : (const struct rte_flow_action_set_ipv6 *)(action->conf);
585 [ # # ]: 0 : struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
586 : : struct rte_flow_item_ipv6 ipv6;
587 : : struct rte_flow_item_ipv6 ipv6_mask;
588 : :
589 : : memset(&ipv6, 0, sizeof(ipv6));
590 : : memset(&ipv6_mask, 0, sizeof(ipv6_mask));
591 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC) {
592 : : memcpy(&ipv6.hdr.src_addr, &conf->ipv6_addr,
593 : : sizeof(ipv6.hdr.src_addr));
594 : : memcpy(&ipv6_mask.hdr.src_addr,
595 : : &rte_flow_item_ipv6_mask.hdr.src_addr,
596 : : sizeof(ipv6.hdr.src_addr));
597 : : } else {
598 : : memcpy(&ipv6.hdr.dst_addr, &conf->ipv6_addr,
599 : : sizeof(ipv6.hdr.dst_addr));
600 : : memcpy(&ipv6_mask.hdr.dst_addr,
601 : : &rte_flow_item_ipv6_mask.hdr.dst_addr,
602 : : sizeof(ipv6.hdr.dst_addr));
603 : : }
604 : 0 : item.spec = &ipv6;
605 : 0 : item.mask = &ipv6_mask;
606 : 0 : return flow_dv_convert_modify_action(&item, modify_ipv6, NULL, resource,
607 : : MLX5_MODIFICATION_TYPE_SET, error);
608 : : }
609 : :
610 : : /**
611 : : * Convert modify-header set MAC address action to DV specification.
612 : : *
613 : : * @param[in,out] resource
614 : : * Pointer to the modify-header resource.
615 : : * @param[in] action
616 : : * Pointer to action specification.
617 : : * @param[out] error
618 : : * Pointer to the error structure.
619 : : *
620 : : * @return
621 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
622 : : */
623 : : static int
624 : 0 : flow_dv_convert_action_modify_mac
625 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
626 : : const struct rte_flow_action *action,
627 : : struct rte_flow_error *error)
628 : : {
629 : 0 : const struct rte_flow_action_set_mac *conf =
630 : : (const struct rte_flow_action_set_mac *)(action->conf);
631 [ # # ]: 0 : struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_ETH };
632 : : struct rte_flow_item_eth eth;
633 : : struct rte_flow_item_eth eth_mask;
634 : :
635 : : memset(ð, 0, sizeof(eth));
636 : : memset(ð_mask, 0, sizeof(eth_mask));
637 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_SET_MAC_SRC) {
638 : : memcpy(ð.hdr.src_addr.addr_bytes, &conf->mac_addr,
639 : : sizeof(eth.hdr.src_addr.addr_bytes));
640 : : memcpy(ð_mask.hdr.src_addr.addr_bytes,
641 : : &rte_flow_item_eth_mask.hdr.src_addr.addr_bytes,
642 : : sizeof(eth_mask.hdr.src_addr.addr_bytes));
643 : : } else {
644 : : memcpy(ð.hdr.dst_addr.addr_bytes, &conf->mac_addr,
645 : : sizeof(eth.hdr.dst_addr.addr_bytes));
646 : : memcpy(ð_mask.hdr.dst_addr.addr_bytes,
647 : : &rte_flow_item_eth_mask.hdr.dst_addr.addr_bytes,
648 : : sizeof(eth_mask.hdr.dst_addr.addr_bytes));
649 : : }
650 : 0 : item.spec = ð
651 : 0 : item.mask = ð_mask;
652 : 0 : return flow_dv_convert_modify_action(&item, modify_eth, NULL, resource,
653 : : MLX5_MODIFICATION_TYPE_SET, error);
654 : : }
655 : :
656 : : /**
657 : : * Convert modify-header set VLAN VID action to DV specification.
658 : : *
659 : : * @param[in,out] resource
660 : : * Pointer to the modify-header resource.
661 : : * @param[in] action
662 : : * Pointer to action specification.
663 : : * @param[out] error
664 : : * Pointer to the error structure.
665 : : *
666 : : * @return
667 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
668 : : */
669 : : static int
670 : 0 : flow_dv_convert_action_modify_vlan_vid
671 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
672 : : const struct rte_flow_action *action,
673 : : struct rte_flow_error *error)
674 : : {
675 : 0 : const struct rte_flow_action_of_set_vlan_vid *conf =
676 : : (const struct rte_flow_action_of_set_vlan_vid *)(action->conf);
677 : 0 : int i = resource->actions_num;
678 : 0 : struct mlx5_modification_cmd *actions = resource->actions;
679 : : struct field_modify_info *field = modify_vlan_out_first_vid;
680 : :
681 [ # # ]: 0 : if (i >= MLX5_MAX_MODIFY_NUM)
682 : 0 : return rte_flow_error_set(error, EINVAL,
683 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
684 : : "too many items to modify");
685 : 0 : actions[i] = (struct mlx5_modification_cmd) {
686 : : .action_type = MLX5_MODIFICATION_TYPE_SET,
687 : 0 : .field = field->id,
688 : 0 : .length = field->size,
689 : 0 : .offset = field->offset,
690 : : };
691 [ # # ]: 0 : actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
692 : 0 : actions[i].data1 = conf->vlan_vid;
693 : 0 : actions[i].data1 = actions[i].data1 << 16;
694 : 0 : resource->actions_num = ++i;
695 : 0 : return 0;
696 : : }
697 : :
698 : : /**
699 : : * Convert modify-header set TP action to DV specification.
700 : : *
701 : : * @param[in,out] resource
702 : : * Pointer to the modify-header resource.
703 : : * @param[in] action
704 : : * Pointer to action specification.
705 : : * @param[in] items
706 : : * Pointer to rte_flow_item objects list.
707 : : * @param[in] attr
708 : : * Pointer to flow attributes structure.
709 : : * @param[in] dev_flow
710 : : * Pointer to the sub flow.
711 : : * @param[in] tunnel_decap
712 : : * Whether action is after tunnel decapsulation.
713 : : * @param[out] error
714 : : * Pointer to the error structure.
715 : : *
716 : : * @return
717 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
718 : : */
719 : : static int
720 : 0 : flow_dv_convert_action_modify_tp
721 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
722 : : const struct rte_flow_action *action,
723 : : const struct rte_flow_item *items,
724 : : union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
725 : : bool tunnel_decap, struct rte_flow_error *error)
726 : : {
727 : 0 : const struct rte_flow_action_set_tp *conf =
728 : : (const struct rte_flow_action_set_tp *)(action->conf);
729 : : struct rte_flow_item item;
730 : : struct rte_flow_item_udp udp;
731 : : struct rte_flow_item_udp udp_mask;
732 : : struct rte_flow_item_tcp tcp;
733 : : struct rte_flow_item_tcp tcp_mask;
734 : : struct field_modify_info *field;
735 : :
736 [ # # ]: 0 : if (!attr->valid)
737 : 0 : flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
738 [ # # ]: 0 : if (attr->udp) {
739 : : memset(&udp, 0, sizeof(udp));
740 : : memset(&udp_mask, 0, sizeof(udp_mask));
741 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
742 : 0 : udp.hdr.src_port = conf->port;
743 : 0 : udp_mask.hdr.src_port =
744 : : rte_flow_item_udp_mask.hdr.src_port;
745 : : } else {
746 : 0 : udp.hdr.dst_port = conf->port;
747 : 0 : udp_mask.hdr.dst_port =
748 : : rte_flow_item_udp_mask.hdr.dst_port;
749 : : }
750 : 0 : item.type = RTE_FLOW_ITEM_TYPE_UDP;
751 : 0 : item.spec = &udp;
752 : 0 : item.mask = &udp_mask;
753 : : field = modify_udp;
754 : : } else {
755 : : MLX5_ASSERT(attr->tcp);
756 : : memset(&tcp, 0, sizeof(tcp));
757 : : memset(&tcp_mask, 0, sizeof(tcp_mask));
758 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_SET_TP_SRC) {
759 : 0 : tcp.hdr.src_port = conf->port;
760 : 0 : tcp_mask.hdr.src_port =
761 : : rte_flow_item_tcp_mask.hdr.src_port;
762 : : } else {
763 : 0 : tcp.hdr.dst_port = conf->port;
764 : 0 : tcp_mask.hdr.dst_port =
765 : : rte_flow_item_tcp_mask.hdr.dst_port;
766 : : }
767 : 0 : item.type = RTE_FLOW_ITEM_TYPE_TCP;
768 : 0 : item.spec = &tcp;
769 : 0 : item.mask = &tcp_mask;
770 : : field = modify_tcp;
771 : : }
772 : 0 : return flow_dv_convert_modify_action(&item, field, NULL, resource,
773 : : MLX5_MODIFICATION_TYPE_SET, error);
774 : : }
775 : :
776 : : /**
777 : : * Convert modify-header set TTL action to DV specification.
778 : : *
779 : : * @param[in,out] resource
780 : : * Pointer to the modify-header resource.
781 : : * @param[in] action
782 : : * Pointer to action specification.
783 : : * @param[in] items
784 : : * Pointer to rte_flow_item objects list.
785 : : * @param[in] attr
786 : : * Pointer to flow attributes structure.
787 : : * @param[in] dev_flow
788 : : * Pointer to the sub flow.
789 : : * @param[in] tunnel_decap
790 : : * Whether action is after tunnel decapsulation.
791 : : * @param[out] error
792 : : * Pointer to the error structure.
793 : : *
794 : : * @return
795 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
796 : : */
797 : : static int
798 : 0 : flow_dv_convert_action_modify_ttl
799 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
800 : : const struct rte_flow_action *action,
801 : : const struct rte_flow_item *items,
802 : : union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
803 : : bool tunnel_decap, struct rte_flow_error *error)
804 : : {
805 : 0 : const struct rte_flow_action_set_ttl *conf =
806 : : (const struct rte_flow_action_set_ttl *)(action->conf);
807 : : struct rte_flow_item item;
808 : : struct rte_flow_item_ipv4 ipv4;
809 : : struct rte_flow_item_ipv4 ipv4_mask;
810 : : struct rte_flow_item_ipv6 ipv6;
811 : : struct rte_flow_item_ipv6 ipv6_mask;
812 : : struct field_modify_info *field;
813 : :
814 [ # # ]: 0 : if (!attr->valid)
815 : 0 : flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
816 [ # # ]: 0 : if (attr->ipv4) {
817 : : memset(&ipv4, 0, sizeof(ipv4));
818 : : memset(&ipv4_mask, 0, sizeof(ipv4_mask));
819 : 0 : ipv4.hdr.time_to_live = conf->ttl_value;
820 : 0 : ipv4_mask.hdr.time_to_live = 0xFF;
821 : 0 : item.type = RTE_FLOW_ITEM_TYPE_IPV4;
822 : 0 : item.spec = &ipv4;
823 : 0 : item.mask = &ipv4_mask;
824 : : field = modify_ipv4;
825 : : } else {
826 : : MLX5_ASSERT(attr->ipv6);
827 : : memset(&ipv6, 0, sizeof(ipv6));
828 : : memset(&ipv6_mask, 0, sizeof(ipv6_mask));
829 : 0 : ipv6.hdr.hop_limits = conf->ttl_value;
830 : 0 : ipv6_mask.hdr.hop_limits = 0xFF;
831 : 0 : item.type = RTE_FLOW_ITEM_TYPE_IPV6;
832 : 0 : item.spec = &ipv6;
833 : 0 : item.mask = &ipv6_mask;
834 : : field = modify_ipv6;
835 : : }
836 : 0 : return flow_dv_convert_modify_action(&item, field, NULL, resource,
837 : : MLX5_MODIFICATION_TYPE_SET, error);
838 : : }
839 : :
840 : : /**
841 : : * Convert modify-header decrement TTL action to DV specification.
842 : : *
843 : : * @param[in,out] resource
844 : : * Pointer to the modify-header resource.
845 : : * @param[in] action
846 : : * Pointer to action specification.
847 : : * @param[in] items
848 : : * Pointer to rte_flow_item objects list.
849 : : * @param[in] attr
850 : : * Pointer to flow attributes structure.
851 : : * @param[in] dev_flow
852 : : * Pointer to the sub flow.
853 : : * @param[in] tunnel_decap
854 : : * Whether action is after tunnel decapsulation.
855 : : * @param[out] error
856 : : * Pointer to the error structure.
857 : : *
858 : : * @return
859 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
860 : : */
861 : : static int
862 : 0 : flow_dv_convert_action_modify_dec_ttl
863 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
864 : : const struct rte_flow_item *items,
865 : : union flow_dv_attr *attr, struct mlx5_flow *dev_flow,
866 : : bool tunnel_decap, struct rte_flow_error *error)
867 : : {
868 : : struct rte_flow_item item;
869 : : struct rte_flow_item_ipv4 ipv4;
870 : : struct rte_flow_item_ipv4 ipv4_mask;
871 : : struct rte_flow_item_ipv6 ipv6;
872 : : struct rte_flow_item_ipv6 ipv6_mask;
873 : : struct field_modify_info *field;
874 : :
875 [ # # ]: 0 : if (!attr->valid)
876 : 0 : flow_dv_attr_init(items, attr, dev_flow, tunnel_decap);
877 [ # # ]: 0 : if (attr->ipv4) {
878 : : memset(&ipv4, 0, sizeof(ipv4));
879 : : memset(&ipv4_mask, 0, sizeof(ipv4_mask));
880 : 0 : ipv4.hdr.time_to_live = 0xFF;
881 : 0 : ipv4_mask.hdr.time_to_live = 0xFF;
882 : 0 : item.type = RTE_FLOW_ITEM_TYPE_IPV4;
883 : 0 : item.spec = &ipv4;
884 : 0 : item.mask = &ipv4_mask;
885 : : field = modify_ipv4;
886 : : } else {
887 : : MLX5_ASSERT(attr->ipv6);
888 : : memset(&ipv6, 0, sizeof(ipv6));
889 : : memset(&ipv6_mask, 0, sizeof(ipv6_mask));
890 : 0 : ipv6.hdr.hop_limits = 0xFF;
891 : 0 : ipv6_mask.hdr.hop_limits = 0xFF;
892 : 0 : item.type = RTE_FLOW_ITEM_TYPE_IPV6;
893 : 0 : item.spec = &ipv6;
894 : 0 : item.mask = &ipv6_mask;
895 : : field = modify_ipv6;
896 : : }
897 : 0 : return flow_dv_convert_modify_action(&item, field, NULL, resource,
898 : : MLX5_MODIFICATION_TYPE_ADD, error);
899 : : }
900 : :
901 : : /**
902 : : * Convert modify-header increment/decrement TCP Sequence number
903 : : * to DV specification.
904 : : *
905 : : * @param[in,out] resource
906 : : * Pointer to the modify-header resource.
907 : : * @param[in] action
908 : : * Pointer to action specification.
909 : : * @param[out] error
910 : : * Pointer to the error structure.
911 : : *
912 : : * @return
913 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
914 : : */
915 : : static int
916 : 0 : flow_dv_convert_action_modify_tcp_seq
917 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
918 : : const struct rte_flow_action *action,
919 : : struct rte_flow_error *error)
920 : : {
921 : 0 : const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
922 [ # # ]: 0 : uint64_t value = rte_be_to_cpu_32(*conf);
923 : : struct rte_flow_item item;
924 : : struct rte_flow_item_tcp tcp;
925 : : struct rte_flow_item_tcp tcp_mask;
926 : :
927 : : memset(&tcp, 0, sizeof(tcp));
928 : : memset(&tcp_mask, 0, sizeof(tcp_mask));
929 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ)
930 : : /*
931 : : * The HW has no decrement operation, only increment operation.
932 : : * To simulate decrement X from Y using increment operation
933 : : * we need to add UINT32_MAX X times to Y.
934 : : * Each adding of UINT32_MAX decrements Y by 1.
935 : : */
936 : 0 : value *= UINT32_MAX;
937 [ # # ]: 0 : tcp.hdr.sent_seq = rte_cpu_to_be_32((uint32_t)value);
938 : 0 : tcp_mask.hdr.sent_seq = RTE_BE32(UINT32_MAX);
939 : 0 : item.type = RTE_FLOW_ITEM_TYPE_TCP;
940 : 0 : item.spec = &tcp;
941 : 0 : item.mask = &tcp_mask;
942 : 0 : return flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
943 : : MLX5_MODIFICATION_TYPE_ADD, error);
944 : : }
945 : :
946 : : /**
947 : : * Convert modify-header increment/decrement TCP Acknowledgment number
948 : : * to DV specification.
949 : : *
950 : : * @param[in,out] resource
951 : : * Pointer to the modify-header resource.
952 : : * @param[in] action
953 : : * Pointer to action specification.
954 : : * @param[out] error
955 : : * Pointer to the error structure.
956 : : *
957 : : * @return
958 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
959 : : */
960 : : static int
961 : 0 : flow_dv_convert_action_modify_tcp_ack
962 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
963 : : const struct rte_flow_action *action,
964 : : struct rte_flow_error *error)
965 : : {
966 : 0 : const rte_be32_t *conf = (const rte_be32_t *)(action->conf);
967 [ # # ]: 0 : uint64_t value = rte_be_to_cpu_32(*conf);
968 : : struct rte_flow_item item;
969 : : struct rte_flow_item_tcp tcp;
970 : : struct rte_flow_item_tcp tcp_mask;
971 : :
972 : : memset(&tcp, 0, sizeof(tcp));
973 : : memset(&tcp_mask, 0, sizeof(tcp_mask));
974 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK)
975 : : /*
976 : : * The HW has no decrement operation, only increment operation.
977 : : * To simulate decrement X from Y using increment operation
978 : : * we need to add UINT32_MAX X times to Y.
979 : : * Each adding of UINT32_MAX decrements Y by 1.
980 : : */
981 : 0 : value *= UINT32_MAX;
982 [ # # ]: 0 : tcp.hdr.recv_ack = rte_cpu_to_be_32((uint32_t)value);
983 : 0 : tcp_mask.hdr.recv_ack = RTE_BE32(UINT32_MAX);
984 : 0 : item.type = RTE_FLOW_ITEM_TYPE_TCP;
985 : 0 : item.spec = &tcp;
986 : 0 : item.mask = &tcp_mask;
987 : 0 : return flow_dv_convert_modify_action(&item, modify_tcp, NULL, resource,
988 : : MLX5_MODIFICATION_TYPE_ADD, error);
989 : : }
990 : :
991 : : enum mlx5_modification_field reg_to_field[] = {
992 : : [REG_NON] = MLX5_MODI_OUT_NONE,
993 : : [REG_A] = MLX5_MODI_META_DATA_REG_A,
994 : : [REG_B] = MLX5_MODI_META_DATA_REG_B,
995 : : [REG_C_0] = MLX5_MODI_META_REG_C_0,
996 : : [REG_C_1] = MLX5_MODI_META_REG_C_1,
997 : : [REG_C_2] = MLX5_MODI_META_REG_C_2,
998 : : [REG_C_3] = MLX5_MODI_META_REG_C_3,
999 : : [REG_C_4] = MLX5_MODI_META_REG_C_4,
1000 : : [REG_C_5] = MLX5_MODI_META_REG_C_5,
1001 : : [REG_C_6] = MLX5_MODI_META_REG_C_6,
1002 : : [REG_C_7] = MLX5_MODI_META_REG_C_7,
1003 : : [REG_C_8] = MLX5_MODI_META_REG_C_8,
1004 : : [REG_C_9] = MLX5_MODI_META_REG_C_9,
1005 : : [REG_C_10] = MLX5_MODI_META_REG_C_10,
1006 : : [REG_C_11] = MLX5_MODI_META_REG_C_11,
1007 : : };
1008 : :
1009 : : const size_t mlx5_mod_reg_size = RTE_DIM(reg_to_field);
1010 : :
1011 : : /**
1012 : : * Convert register set to DV specification.
1013 : : *
1014 : : * @param[in,out] resource
1015 : : * Pointer to the modify-header resource.
1016 : : * @param[in] action
1017 : : * Pointer to action specification.
1018 : : * @param[out] error
1019 : : * Pointer to the error structure.
1020 : : *
1021 : : * @return
1022 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1023 : : */
1024 : : static int
1025 : 0 : flow_dv_convert_action_set_reg
1026 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
1027 : : const struct rte_flow_action *action,
1028 : : struct rte_flow_error *error)
1029 : : {
1030 : 0 : const struct mlx5_rte_flow_action_set_tag *conf = action->conf;
1031 : 0 : struct mlx5_modification_cmd *actions = resource->actions;
1032 : 0 : uint32_t i = resource->actions_num;
1033 : :
1034 [ # # ]: 0 : if (i >= MLX5_MAX_MODIFY_NUM)
1035 : 0 : return rte_flow_error_set(error, EINVAL,
1036 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1037 : : "too many items to modify");
1038 : : MLX5_ASSERT(conf->id != REG_NON);
1039 : : MLX5_ASSERT(conf->id < (enum modify_reg)RTE_DIM(reg_to_field));
1040 : 0 : actions[i] = (struct mlx5_modification_cmd) {
1041 : : .action_type = MLX5_MODIFICATION_TYPE_SET,
1042 : 0 : .field = reg_to_field[conf->id],
1043 : 0 : .offset = conf->offset,
1044 : 0 : .length = conf->length,
1045 : : };
1046 [ # # ]: 0 : actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
1047 [ # # ]: 0 : actions[i].data1 = rte_cpu_to_be_32(conf->data);
1048 : : ++i;
1049 : 0 : resource->actions_num = i;
1050 : 0 : return 0;
1051 : : }
1052 : :
1053 : : /**
1054 : : * Convert SET_TAG action to DV specification.
1055 : : *
1056 : : * @param[in] dev
1057 : : * Pointer to the rte_eth_dev structure.
1058 : : * @param[in,out] resource
1059 : : * Pointer to the modify-header resource.
1060 : : * @param[in] conf
1061 : : * Pointer to action specification.
1062 : : * @param[out] error
1063 : : * Pointer to the error structure.
1064 : : *
1065 : : * @return
1066 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1067 : : */
1068 : : static int
1069 : 0 : flow_dv_convert_action_set_tag
1070 : : (struct rte_eth_dev *dev,
1071 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
1072 : : const struct rte_flow_action_set_tag *conf,
1073 : : struct rte_flow_error *error)
1074 : : {
1075 [ # # ]: 0 : rte_be32_t data = rte_cpu_to_be_32(conf->data);
1076 [ # # ]: 0 : rte_be32_t mask = rte_cpu_to_be_32(conf->mask);
1077 : 0 : struct rte_flow_item item = {
1078 : : .spec = &data,
1079 : : .mask = &mask,
1080 : : };
1081 : 0 : struct field_modify_info reg_c_x[] = {
1082 : : [1] = {0, 0, 0},
1083 : : };
1084 : : enum mlx5_modification_field reg_type;
1085 : : int ret;
1086 : :
1087 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
1088 [ # # ]: 0 : if (ret < 0)
1089 : : return ret;
1090 : : MLX5_ASSERT(ret != REG_NON);
1091 : : MLX5_ASSERT((unsigned int)ret < RTE_DIM(reg_to_field));
1092 : 0 : reg_type = reg_to_field[ret];
1093 : : MLX5_ASSERT(reg_type > 0);
1094 : 0 : reg_c_x[0] = (struct field_modify_info){4, 0, reg_type};
1095 : 0 : return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1096 : : MLX5_MODIFICATION_TYPE_SET, error);
1097 : : }
1098 : :
1099 : : /**
1100 : : * Convert internal COPY_REG action to DV specification.
1101 : : *
1102 : : * @param[in] dev
1103 : : * Pointer to the rte_eth_dev structure.
1104 : : * @param[in,out] res
1105 : : * Pointer to the modify-header resource.
1106 : : * @param[in] action
1107 : : * Pointer to action specification.
1108 : : * @param[out] error
1109 : : * Pointer to the error structure.
1110 : : *
1111 : : * @return
1112 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1113 : : */
1114 : : static int
1115 : 0 : flow_dv_convert_action_copy_mreg(struct rte_eth_dev *dev,
1116 : : struct mlx5_flow_dv_modify_hdr_resource *res,
1117 : : const struct rte_flow_action *action,
1118 : : struct rte_flow_error *error)
1119 : : {
1120 : 0 : const struct mlx5_flow_action_copy_mreg *conf = action->conf;
1121 : 0 : rte_be32_t mask = RTE_BE32(UINT32_MAX);
1122 : 0 : struct rte_flow_item item = {
1123 : : .spec = NULL,
1124 : : .mask = &mask,
1125 : : };
1126 : 0 : struct field_modify_info reg_src[] = {
1127 : 0 : {4, 0, reg_to_field[conf->src]},
1128 : : {0, 0, 0},
1129 : : };
1130 : 0 : struct field_modify_info reg_dst = {
1131 : : .offset = 0,
1132 : 0 : .id = reg_to_field[conf->dst],
1133 : : };
1134 : : /* Adjust reg_c[0] usage according to reported mask. */
1135 [ # # # # ]: 0 : if (conf->dst == REG_C_0 || conf->src == REG_C_0) {
1136 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1137 : 0 : uint32_t reg_c0 = priv->sh->dv_regc0_mask;
1138 : :
1139 : : MLX5_ASSERT(reg_c0);
1140 : : MLX5_ASSERT(priv->sh->config.dv_xmeta_en !=
1141 : : MLX5_XMETA_MODE_LEGACY);
1142 [ # # ]: 0 : if (conf->dst == REG_C_0) {
1143 : : /* Copy to reg_c[0], within mask only. */
1144 : 0 : reg_dst.offset = rte_bsf32(reg_c0);
1145 [ # # ]: 0 : mask = rte_cpu_to_be_32(reg_c0 >> reg_dst.offset);
1146 : : } else {
1147 : : reg_dst.offset = 0;
1148 [ # # ]: 0 : mask = rte_cpu_to_be_32(reg_c0);
1149 : : }
1150 : : }
1151 : 0 : return flow_dv_convert_modify_action(&item,
1152 : : reg_src, ®_dst, res,
1153 : : MLX5_MODIFICATION_TYPE_COPY,
1154 : : error);
1155 : : }
1156 : :
1157 : : /**
1158 : : * Convert MARK action to DV specification. This routine is used
1159 : : * in extensive metadata only and requires metadata register to be
1160 : : * handled. In legacy mode hardware tag resource is engaged.
1161 : : *
1162 : : * @param[in] dev
1163 : : * Pointer to the rte_eth_dev structure.
1164 : : * @param[in] conf
1165 : : * Pointer to MARK action specification.
1166 : : * @param[in,out] resource
1167 : : * Pointer to the modify-header resource.
1168 : : * @param[out] error
1169 : : * Pointer to the error structure.
1170 : : *
1171 : : * @return
1172 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1173 : : */
1174 : : static int
1175 : 0 : flow_dv_convert_action_mark(struct rte_eth_dev *dev,
1176 : : const struct rte_flow_action_mark *conf,
1177 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
1178 : : struct rte_flow_error *error)
1179 : : {
1180 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1181 [ # # ]: 0 : rte_be32_t mask = rte_cpu_to_be_32(MLX5_FLOW_MARK_MASK &
1182 : : priv->sh->dv_mark_mask);
1183 [ # # ]: 0 : rte_be32_t data = rte_cpu_to_be_32(conf->id) & mask;
1184 : 0 : struct rte_flow_item item = {
1185 : : .spec = &data,
1186 : : .mask = &mask,
1187 : : };
1188 : 0 : struct field_modify_info reg_c_x[] = {
1189 : : [1] = {0, 0, 0},
1190 : : };
1191 : : int reg;
1192 : :
1193 [ # # ]: 0 : if (!mask)
1194 : 0 : return rte_flow_error_set(error, EINVAL,
1195 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1196 : : NULL, "zero mark action mask");
1197 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
1198 [ # # ]: 0 : if (reg < 0)
1199 : : return reg;
1200 : : MLX5_ASSERT(reg > 0);
1201 [ # # ]: 0 : if (reg == REG_C_0) {
1202 [ # # ]: 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1203 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
1204 : :
1205 [ # # ]: 0 : data = rte_cpu_to_be_32(rte_cpu_to_be_32(data) << shl_c0);
1206 [ # # ]: 0 : mask = rte_cpu_to_be_32(mask) & msk_c0;
1207 [ # # ]: 0 : mask = rte_cpu_to_be_32(mask << shl_c0);
1208 : : }
1209 : 0 : reg_c_x[0] = (struct field_modify_info){4, 0, reg_to_field[reg]};
1210 : 0 : return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1211 : : MLX5_MODIFICATION_TYPE_SET, error);
1212 : : }
1213 : :
1214 : : /**
1215 : : * Get metadata register index for specified steering domain.
1216 : : *
1217 : : * @param[in] dev
1218 : : * Pointer to the rte_eth_dev structure.
1219 : : * @param[in] attr
1220 : : * Attributes of flow to determine steering domain.
1221 : : * @param[out] error
1222 : : * Pointer to the error structure.
1223 : : *
1224 : : * @return
1225 : : * positive index on success, a negative errno value otherwise
1226 : : * and rte_errno is set.
1227 : : */
1228 : : static enum modify_reg
1229 : 0 : flow_dv_get_metadata_reg(struct rte_eth_dev *dev,
1230 : : const struct rte_flow_attr *attr,
1231 : : struct rte_flow_error *error)
1232 : : {
1233 : : int reg =
1234 [ # # ]: 0 : mlx5_flow_get_reg_id(dev, attr->transfer ?
1235 : 0 : MLX5_METADATA_FDB :
1236 [ # # ]: 0 : attr->egress ?
1237 : : MLX5_METADATA_TX :
1238 : : MLX5_METADATA_RX, 0, error);
1239 [ # # ]: 0 : if (reg < 0)
1240 : 0 : return rte_flow_error_set(error,
1241 : : ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM,
1242 : : NULL, "unavailable "
1243 : : "metadata register");
1244 : 0 : return reg;
1245 : : }
1246 : :
1247 : : /**
1248 : : * Convert SET_META action to DV specification.
1249 : : *
1250 : : * @param[in] dev
1251 : : * Pointer to the rte_eth_dev structure.
1252 : : * @param[in,out] resource
1253 : : * Pointer to the modify-header resource.
1254 : : * @param[in] attr
1255 : : * Attributes of flow that includes this item.
1256 : : * @param[in] conf
1257 : : * Pointer to action specification.
1258 : : * @param[out] error
1259 : : * Pointer to the error structure.
1260 : : *
1261 : : * @return
1262 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1263 : : */
1264 : : static int
1265 : 0 : flow_dv_convert_action_set_meta
1266 : : (struct rte_eth_dev *dev,
1267 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
1268 : : const struct rte_flow_attr *attr,
1269 : : const struct rte_flow_action_set_meta *conf,
1270 : : struct rte_flow_error *error)
1271 : : {
1272 [ # # ]: 0 : uint32_t mask = rte_cpu_to_be_32(conf->mask);
1273 [ # # ]: 0 : uint32_t data = rte_cpu_to_be_32(conf->data) & mask;
1274 : 0 : struct rte_flow_item item = {
1275 : : .spec = &data,
1276 : : .mask = &mask,
1277 : : };
1278 : 0 : struct field_modify_info reg_c_x[] = {
1279 : : [1] = {0, 0, 0},
1280 : : };
1281 : 0 : int reg = flow_dv_get_metadata_reg(dev, attr, error);
1282 : :
1283 [ # # ]: 0 : if (reg < 0)
1284 : : return reg;
1285 : : MLX5_ASSERT(reg != REG_NON);
1286 [ # # ]: 0 : if (reg == REG_C_0) {
1287 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1288 [ # # ]: 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
1289 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
1290 : :
1291 [ # # ]: 0 : data = rte_cpu_to_be_32(rte_cpu_to_be_32(data) << shl_c0);
1292 [ # # ]: 0 : mask = rte_cpu_to_be_32(mask) & msk_c0;
1293 [ # # ]: 0 : mask = rte_cpu_to_be_32(mask << shl_c0);
1294 : : }
1295 : 0 : reg_c_x[0] = (struct field_modify_info){4, 0, reg_to_field[reg]};
1296 : : /* The routine expects parameters in memory as big-endian ones. */
1297 : 0 : return flow_dv_convert_modify_action(&item, reg_c_x, NULL, resource,
1298 : : MLX5_MODIFICATION_TYPE_SET, error);
1299 : : }
1300 : :
1301 : : /**
1302 : : * Convert modify-header set IPv4 DSCP action to DV specification.
1303 : : *
1304 : : * @param[in,out] resource
1305 : : * Pointer to the modify-header resource.
1306 : : * @param[in] action
1307 : : * Pointer to action specification.
1308 : : * @param[out] error
1309 : : * Pointer to the error structure.
1310 : : *
1311 : : * @return
1312 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1313 : : */
1314 : : static int
1315 : 0 : flow_dv_convert_action_modify_ipv4_dscp
1316 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
1317 : : const struct rte_flow_action *action,
1318 : : struct rte_flow_error *error)
1319 : : {
1320 : 0 : const struct rte_flow_action_set_dscp *conf =
1321 : : (const struct rte_flow_action_set_dscp *)(action->conf);
1322 : 0 : struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV4 };
1323 : : struct rte_flow_item_ipv4 ipv4;
1324 : : struct rte_flow_item_ipv4 ipv4_mask;
1325 : :
1326 : : memset(&ipv4, 0, sizeof(ipv4));
1327 : : memset(&ipv4_mask, 0, sizeof(ipv4_mask));
1328 : 0 : ipv4.hdr.type_of_service = conf->dscp;
1329 : 0 : ipv4_mask.hdr.type_of_service = RTE_IPV4_HDR_DSCP_MASK >> 2;
1330 : 0 : item.spec = &ipv4;
1331 : 0 : item.mask = &ipv4_mask;
1332 : 0 : return flow_dv_convert_modify_action(&item, modify_ipv4, NULL, resource,
1333 : : MLX5_MODIFICATION_TYPE_SET, error);
1334 : : }
1335 : :
1336 : : /**
1337 : : * Convert modify-header set IPv6 DSCP action to DV specification.
1338 : : *
1339 : : * @param[in,out] resource
1340 : : * Pointer to the modify-header resource.
1341 : : * @param[in] action
1342 : : * Pointer to action specification.
1343 : : * @param[out] error
1344 : : * Pointer to the error structure.
1345 : : *
1346 : : * @return
1347 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1348 : : */
1349 : : static int
1350 : 0 : flow_dv_convert_action_modify_ipv6_dscp
1351 : : (struct mlx5_flow_dv_modify_hdr_resource *resource,
1352 : : const struct rte_flow_action *action,
1353 : : uint32_t ipv6_tc_off,
1354 : : struct rte_flow_error *error)
1355 : : {
1356 : 0 : const struct rte_flow_action_set_dscp *conf =
1357 : : (const struct rte_flow_action_set_dscp *)(action->conf);
1358 [ # # ]: 0 : struct rte_flow_item item = { .type = RTE_FLOW_ITEM_TYPE_IPV6 };
1359 : : struct rte_flow_item_ipv6 ipv6;
1360 : : struct rte_flow_item_ipv6 ipv6_mask;
1361 : : struct field_modify_info *modify_info;
1362 : :
1363 : : memset(&ipv6, 0, sizeof(ipv6));
1364 : : memset(&ipv6_mask, 0, sizeof(ipv6_mask));
1365 : : /*
1366 : : * Even though the DSCP bits offset of IPv6 is not byte aligned,
1367 : : * rdma-core only accept the DSCP bits byte aligned start from
1368 : : * bit 0 to 5 as to be compatible with IPv4. No need to shift the
1369 : : * bits in IPv6 case as rdma-core requires byte aligned value.
1370 : : * IPv6 DSCP uses OUT_IPV6_TRAFFIC_CLASS as ID but it starts from 2
1371 : : * bits left. Shift the mask left for IPv6 DSCP. Do it here because
1372 : : * it's needed to distinguish DSCP from ECN in data field construct
1373 : : */
1374 : 0 : ipv6.hdr.vtc_flow = conf->dscp << ipv6_tc_off;
1375 : 0 : ipv6_mask.hdr.vtc_flow = RTE_IPV6_HDR_DSCP_MASK >> (22 - ipv6_tc_off);
1376 : 0 : item.spec = &ipv6;
1377 : 0 : item.mask = &ipv6_mask;
1378 [ # # ]: 0 : if (ipv6_tc_off)
1379 : : modify_info = modify_ipv6_traffic_class;
1380 : : else
1381 : : modify_info = modify_ipv6;
1382 : 0 : return flow_dv_convert_modify_action(&item, modify_info, NULL, resource,
1383 : : MLX5_MODIFICATION_TYPE_SET, error);
1384 : : }
1385 : :
1386 : : int
1387 : 0 : mlx5_flow_item_field_width(struct rte_eth_dev *dev,
1388 : : enum rte_flow_field_id field, int inherit,
1389 : : const struct rte_flow_attr *attr,
1390 : : struct rte_flow_error *error)
1391 : : {
1392 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1393 : :
1394 [ # # # # : 0 : switch (field) {
# # # # #
# # # # #
# # # # #
# # # # ]
1395 : : case RTE_FLOW_FIELD_START:
1396 : : return 32;
1397 : 0 : case RTE_FLOW_FIELD_MAC_DST:
1398 : : case RTE_FLOW_FIELD_MAC_SRC:
1399 : 0 : return 48;
1400 : 0 : case RTE_FLOW_FIELD_VLAN_TYPE:
1401 : 0 : return 16;
1402 : 0 : case RTE_FLOW_FIELD_VLAN_ID:
1403 : 0 : return 12;
1404 : 0 : case RTE_FLOW_FIELD_MAC_TYPE:
1405 : 0 : return 16;
1406 : 0 : case RTE_FLOW_FIELD_IPV4_DSCP:
1407 : 0 : return 6;
1408 : 0 : case RTE_FLOW_FIELD_IPV4_TTL:
1409 : : case RTE_FLOW_FIELD_IPV4_PROTO:
1410 : 0 : return 8;
1411 : : case RTE_FLOW_FIELD_IPV4_SRC:
1412 : : case RTE_FLOW_FIELD_IPV4_DST:
1413 : : return 32;
1414 : 0 : case RTE_FLOW_FIELD_IPV6_DSCP:
1415 : 0 : return 6;
1416 : 0 : case RTE_FLOW_FIELD_IPV6_FLOW_LABEL:
1417 : 0 : return 20;
1418 : 0 : case RTE_FLOW_FIELD_IPV6_TRAFFIC_CLASS:
1419 : : case RTE_FLOW_FIELD_IPV6_HOPLIMIT:
1420 : : case RTE_FLOW_FIELD_IPV6_PROTO:
1421 : 0 : return 8;
1422 : 0 : case RTE_FLOW_FIELD_IPV6_SRC:
1423 : : case RTE_FLOW_FIELD_IPV6_DST:
1424 : 0 : return 128;
1425 : 0 : case RTE_FLOW_FIELD_TCP_PORT_SRC:
1426 : : case RTE_FLOW_FIELD_TCP_PORT_DST:
1427 : 0 : return 16;
1428 : : case RTE_FLOW_FIELD_TCP_SEQ_NUM:
1429 : : case RTE_FLOW_FIELD_TCP_ACK_NUM:
1430 : : return 32;
1431 : 0 : case RTE_FLOW_FIELD_TCP_FLAGS:
1432 : 0 : return 9;
1433 : 0 : case RTE_FLOW_FIELD_UDP_PORT_SRC:
1434 : : case RTE_FLOW_FIELD_UDP_PORT_DST:
1435 : 0 : return 16;
1436 : 0 : case RTE_FLOW_FIELD_VXLAN_VNI:
1437 : : case RTE_FLOW_FIELD_GENEVE_VNI:
1438 : 0 : return 24;
1439 : 0 : case RTE_FLOW_FIELD_VXLAN_LAST_RSVD:
1440 : 0 : return 8;
1441 : : case RTE_FLOW_FIELD_GTP_TEID:
1442 : : case RTE_FLOW_FIELD_MPLS:
1443 : : case RTE_FLOW_FIELD_TAG:
1444 : : case RTE_FLOW_FIELD_ESP_SPI:
1445 : : case RTE_FLOW_FIELD_ESP_SEQ_NUM:
1446 : : return 32;
1447 : 0 : case RTE_FLOW_FIELD_ESP_PROTO:
1448 : 0 : return 8;
1449 : 0 : case RTE_FLOW_FIELD_MARK:
1450 : 0 : return rte_popcount32(priv->sh->dv_mark_mask);
1451 : 0 : case RTE_FLOW_FIELD_META:
1452 : 0 : return (flow_dv_get_metadata_reg(dev, attr, error) == REG_C_0) ?
1453 [ # # ]: 0 : rte_popcount32(priv->sh->dv_meta_mask) : 32;
1454 : 0 : case RTE_FLOW_FIELD_GTP_PSC_QFI:
1455 : 0 : return 6;
1456 : 0 : case RTE_FLOW_FIELD_POINTER:
1457 : : case RTE_FLOW_FIELD_VALUE:
1458 : 0 : return inherit < 0 ? 0 : inherit;
1459 : 0 : case RTE_FLOW_FIELD_IPV4_ECN:
1460 : : case RTE_FLOW_FIELD_IPV6_ECN:
1461 : : case RTE_FLOW_FIELD_METER_COLOR:
1462 : 0 : return 2;
1463 : : case RTE_FLOW_FIELD_HASH_RESULT:
1464 : : return 32;
1465 : 0 : default:
1466 : : MLX5_ASSERT(false);
1467 : : }
1468 : 0 : return 0;
1469 : : }
1470 : :
1471 : : static __rte_always_inline uint8_t
1472 : : flow_modify_info_mask_8(uint32_t length, uint32_t off)
1473 : : {
1474 : 0 : return (0xffu >> (8 - length)) << off;
1475 : : }
1476 : :
1477 : : static __rte_always_inline uint16_t
1478 : : flow_modify_info_mask_16(uint32_t length, uint32_t off)
1479 : : {
1480 [ # # # # : 0 : return rte_cpu_to_be_16((0xffffu >> (16 - length)) << off);
# # # # #
# # # # #
# # # # #
# # # ]
1481 : : }
1482 : :
1483 : : static __rte_always_inline uint32_t
1484 : : flow_modify_info_mask_32(uint32_t length, uint32_t off)
1485 : : {
1486 [ # # # # : 0 : return rte_cpu_to_be_32((0xffffffffu >> (32 - length)) << off);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1487 : : }
1488 : :
1489 : : static __rte_always_inline uint32_t
1490 : : flow_modify_info_mask_32_masked(uint32_t length, uint32_t off, uint32_t post_mask)
1491 : : {
1492 : 0 : uint32_t mask = (0xffffffffu >> (32 - length)) << off;
1493 : 0 : return rte_cpu_to_be_32(mask & post_mask);
1494 : : }
1495 : :
1496 : : static __rte_always_inline enum mlx5_modification_field
1497 : : mlx5_mpls_modi_field_get(const struct rte_flow_field_data *data)
1498 : : {
1499 : 0 : return MLX5_MODI_IN_MPLS_LABEL_0 + data->tag_index;
1500 : : }
1501 : :
1502 : : static __rte_always_inline int
1503 : : flow_geneve_opt_modi_field_get(struct mlx5_priv *priv,
1504 : : const struct rte_flow_field_data *data)
1505 : : {
1506 : : #ifdef HAVE_MLX5_HWS_SUPPORT
1507 : 0 : return mlx5_geneve_opt_modi_field_get(priv, data);
1508 : : #else
1509 : : (void)priv;
1510 : : (void)data;
1511 : : DRV_LOG(ERR, "GENEVE option modification is not supported.");
1512 : : rte_errno = ENOTSUP;
1513 : : return -rte_errno;
1514 : : #endif
1515 : : }
1516 : :
1517 : : static void
1518 : 0 : mlx5_modify_flex_item(const struct rte_eth_dev *dev,
1519 : : const struct mlx5_flex_item *flex,
1520 : : const struct rte_flow_field_data *data,
1521 : : struct field_modify_info *info,
1522 : : uint32_t *mask, uint32_t width)
1523 : : {
1524 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1525 : 0 : struct mlx5_hca_flex_attr *attr = &priv->sh->cdev->config.hca_attr.flex;
1526 : : uint32_t i, j;
1527 : : int id = 0;
1528 : 0 : uint32_t pos = 0;
1529 : : const struct mlx5_flex_pattern_field *map;
1530 : 0 : uint32_t offset = data->offset;
1531 : : uint32_t width_left = width;
1532 : : uint32_t cur_width = 0;
1533 : : uint32_t tmp_ofs;
1534 : : uint32_t idx = 0;
1535 : : struct field_modify_info tmp;
1536 : : int tmp_id;
1537 : :
1538 [ # # ]: 0 : if (!attr->query_match_sample_info) {
1539 : 0 : DRV_LOG(ERR, "FW doesn't support modify field with flex item.");
1540 : 0 : return;
1541 : : }
1542 : : /*
1543 : : * search for the mapping instance until Accumulated width is no
1544 : : * less than data->offset.
1545 : : */
1546 [ # # ]: 0 : for (i = 0; i < flex->mapnum; i++) {
1547 [ # # ]: 0 : if (flex->map[i].width + pos > data->offset)
1548 : : break;
1549 : 0 : pos += flex->map[i].width;
1550 : : }
1551 [ # # ]: 0 : if (i >= flex->mapnum)
1552 : : return;
1553 [ # # ]: 0 : tmp_ofs = pos < data->offset ? data->offset - pos : 0;
1554 [ # # # # ]: 0 : for (j = i; i < flex->mapnum && width_left > 0; ) {
1555 : 0 : map = flex->map + i;
1556 : 0 : id = mlx5_flex_get_sample_id(flex, i, &pos, false);
1557 [ # # ]: 0 : if (id == -1) {
1558 : 0 : i++;
1559 : : /* All left length is dummy */
1560 [ # # ]: 0 : if (pos >= data->offset + width)
1561 : : return;
1562 : 0 : cur_width = map->width;
1563 : : /* One mapping instance covers the whole width. */
1564 [ # # ]: 0 : } else if (pos + map->width >= (data->offset + width)) {
1565 : : cur_width = width_left;
1566 : : } else {
1567 : 0 : cur_width = cur_width + map->width - tmp_ofs;
1568 : 0 : pos += map->width;
1569 : : /*
1570 : : * Continue to search next until:
1571 : : * 1. Another flex parser ID.
1572 : : * 2. Width has been covered.
1573 : : */
1574 [ # # ]: 0 : for (j = i + 1; j < flex->mapnum; j++) {
1575 : 0 : tmp_id = mlx5_flex_get_sample_id(flex, j, &pos, false);
1576 [ # # ]: 0 : if (tmp_id == -1) {
1577 : : i = j;
1578 : 0 : pos -= flex->map[j].width;
1579 : 0 : break;
1580 : : }
1581 [ # # # # ]: 0 : if (id >= (int)flex->devx_fp->num_samples ||
1582 [ # # ]: 0 : id >= MLX5_GRAPH_NODE_SAMPLE_NUM ||
1583 [ # # ]: 0 : tmp_id >= (int)flex->devx_fp->num_samples ||
1584 : : tmp_id >= MLX5_GRAPH_NODE_SAMPLE_NUM)
1585 : : return;
1586 : 0 : if (flex->devx_fp->sample_info[id].modify_field_id !=
1587 [ # # ]: 0 : flex->devx_fp->sample_info[tmp_id].modify_field_id ||
1588 : 0 : flex->map[j].shift != flex->map[j - 1].width +
1589 [ # # ]: 0 : flex->map[j - 1].shift) {
1590 : : i = j;
1591 : : break;
1592 : : }
1593 [ # # ]: 0 : if ((pos + flex->map[j].width) >= (data->offset + width)) {
1594 : : cur_width = width_left;
1595 : : break;
1596 : : }
1597 : 0 : pos += flex->map[j].width;
1598 : 0 : cur_width += flex->map[j].width;
1599 : : }
1600 : : }
1601 [ # # ]: 0 : if (cur_width > width_left)
1602 : : cur_width = width_left;
1603 [ # # # # : 0 : else if (cur_width < width_left && (j == flex->mapnum || i == flex->mapnum))
# # ]
1604 : : return;
1605 : :
1606 : : MLX5_ASSERT(id < (int)flex->devx_fp->num_samples);
1607 [ # # # # ]: 0 : if (id >= (int)flex->devx_fp->num_samples || id >= MLX5_GRAPH_NODE_SAMPLE_NUM)
1608 : : return;
1609 : : /* Use invalid entry as placeholder for DUMMY mapping. */
1610 : 0 : info[idx] = (struct field_modify_info){cur_width / CHAR_BIT, offset / CHAR_BIT,
1611 [ # # ]: 0 : id == -1 ? MLX5_MODI_INVALID :
1612 : : (enum mlx5_modification_field)
1613 : 0 : flex->devx_fp->sample_info[id].modify_field_id,
1614 : 0 : map->shift + tmp_ofs, 1};
1615 : 0 : offset += cur_width;
1616 : 0 : width_left -= cur_width;
1617 [ # # ]: 0 : if (!mask) {
1618 : 0 : info[idx].offset = (32 - cur_width - map->shift - tmp_ofs);
1619 : 0 : info[idx].size = cur_width / CHAR_BIT + info[idx].offset / CHAR_BIT;
1620 : : }
1621 : : cur_width = 0;
1622 : : tmp_ofs = 0;
1623 : 0 : idx++;
1624 : : }
1625 [ # # ]: 0 : if (unlikely(width_left > 0)) {
1626 : : MLX5_ASSERT(false);
1627 : : return;
1628 : : }
1629 [ # # ]: 0 : if (mask)
1630 : 0 : memset(mask, 0xff, data->offset / CHAR_BIT + width / CHAR_BIT);
1631 : : /* Re-order the info to follow IPv6 address. */
1632 [ # # ]: 0 : for (i = 0; i < idx / 2; i++) {
1633 : 0 : tmp = info[i];
1634 : : MLX5_ASSERT(info[i].id);
1635 : : MLX5_ASSERT(info[idx - 1 - i].id);
1636 : 0 : info[i] = info[idx - 1 - i];
1637 : 0 : info[idx - 1 - i] = tmp;
1638 : : }
1639 : : }
1640 : :
1641 : : static inline bool
1642 : : mlx5_dv_modify_ipv6_traffic_class_supported(struct mlx5_priv *priv)
1643 : : {
1644 : 0 : return priv->sh->phdev->config.ipv6_tc_fallback == MLX5_IPV6_TC_OK;
1645 : : }
1646 : :
1647 : : void
1648 : 0 : mlx5_flow_field_id_to_modify_info
1649 : : (const struct rte_flow_field_data *data,
1650 : : struct field_modify_info *info, uint32_t *mask,
1651 : : uint32_t width, struct rte_eth_dev *dev,
1652 : : const struct rte_flow_attr *attr, struct rte_flow_error *error)
1653 : : {
1654 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1655 : : enum mlx5_modification_field modi_id;
1656 : : uint32_t idx = 0;
1657 : : uint32_t off_be = 0;
1658 : : uint32_t length = 0;
1659 : :
1660 [ # # # # : 0 : switch ((int)data->field) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
1661 : : case RTE_FLOW_FIELD_START:
1662 : : /* not supported yet */
1663 : : MLX5_ASSERT(false);
1664 : : break;
1665 : 0 : case RTE_FLOW_FIELD_MAC_DST:
1666 : : MLX5_ASSERT(data->offset + width <= 48);
1667 : 0 : off_be = 48 - (data->offset + width);
1668 [ # # ]: 0 : if (off_be < 16) {
1669 [ # # ]: 0 : modi_id = CALC_MODI_ID(DMAC_15_0, data->level);
1670 : 0 : info[idx] = (struct field_modify_info){2, 4, modi_id};
1671 [ # # ]: 0 : length = off_be + width <= 16 ? width : 16 - off_be;
1672 [ # # ]: 0 : if (mask)
1673 : 0 : mask[1] = flow_modify_info_mask_16(length,
1674 : : off_be);
1675 : : else
1676 : 0 : info[idx].offset = off_be;
1677 : 0 : width -= length;
1678 [ # # ]: 0 : if (!width)
1679 : : break;
1680 : : off_be = 0;
1681 : : idx++;
1682 : : } else {
1683 : 0 : off_be -= 16;
1684 : : }
1685 [ # # ]: 0 : modi_id = CALC_MODI_ID(DMAC_47_16, data->level);
1686 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1687 [ # # ]: 0 : if (mask)
1688 : 0 : mask[0] = flow_modify_info_mask_32(width, off_be);
1689 : : else
1690 : 0 : info[idx].offset = off_be;
1691 : : break;
1692 : 0 : case RTE_FLOW_FIELD_MAC_SRC:
1693 : : MLX5_ASSERT(data->offset + width <= 48);
1694 : 0 : off_be = 48 - (data->offset + width);
1695 [ # # ]: 0 : if (off_be < 16) {
1696 [ # # ]: 0 : modi_id = CALC_MODI_ID(SMAC_15_0, data->level);
1697 : 0 : info[idx] = (struct field_modify_info){2, 4, modi_id};
1698 [ # # ]: 0 : length = off_be + width <= 16 ? width : 16 - off_be;
1699 [ # # ]: 0 : if (mask)
1700 : 0 : mask[1] = flow_modify_info_mask_16(length,
1701 : : off_be);
1702 : : else
1703 : 0 : info[idx].offset = off_be;
1704 : 0 : width -= length;
1705 [ # # ]: 0 : if (!width)
1706 : : break;
1707 : : off_be = 0;
1708 : : idx++;
1709 : : } else {
1710 : 0 : off_be -= 16;
1711 : : }
1712 [ # # ]: 0 : modi_id = CALC_MODI_ID(SMAC_47_16, data->level);
1713 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1714 [ # # ]: 0 : if (mask)
1715 : 0 : mask[0] = flow_modify_info_mask_32(width, off_be);
1716 : : else
1717 : 0 : info[idx].offset = off_be;
1718 : : break;
1719 : : case RTE_FLOW_FIELD_VLAN_TYPE:
1720 : : /* not supported yet */
1721 : : break;
1722 : 0 : case RTE_FLOW_FIELD_VLAN_ID:
1723 : : MLX5_ASSERT(data->offset + width <= 12);
1724 : 0 : off_be = 12 - (data->offset + width);
1725 : 0 : info[idx] = (struct field_modify_info){2, 0,
1726 : : MLX5_MODI_OUT_FIRST_VID};
1727 [ # # ]: 0 : if (mask)
1728 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1729 : : else
1730 : 0 : info[idx].offset = off_be;
1731 : : break;
1732 : 0 : case RTE_FLOW_FIELD_MAC_TYPE:
1733 : : MLX5_ASSERT(data->offset + width <= 16);
1734 : 0 : off_be = 16 - (data->offset + width);
1735 [ # # ]: 0 : modi_id = CALC_MODI_ID(ETHERTYPE, data->level);
1736 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
1737 [ # # ]: 0 : if (mask)
1738 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1739 : : else
1740 : 0 : info[idx].offset = off_be;
1741 : : break;
1742 : 0 : case RTE_FLOW_FIELD_IPV4_IHL:
1743 : : MLX5_ASSERT(data->offset + width <= 4);
1744 : 0 : off_be = 4 - (data->offset + width);
1745 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV4_IHL, data->level);
1746 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
1747 [ # # ]: 0 : if (mask)
1748 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1749 : : else
1750 : 0 : info[idx].offset = off_be;
1751 : : break;
1752 : 0 : case RTE_FLOW_FIELD_IPV4_DSCP:
1753 : : MLX5_ASSERT(data->offset + width <= 6);
1754 : 0 : off_be = 6 - (data->offset + width);
1755 [ # # ]: 0 : modi_id = CALC_MODI_ID(IP_DSCP, data->level);
1756 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
1757 [ # # ]: 0 : if (mask)
1758 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1759 : : else
1760 : 0 : info[idx].offset = off_be;
1761 : : break;
1762 : 0 : case RTE_FLOW_FIELD_IPV4_TOTAL_LEN:
1763 : : MLX5_ASSERT(data->offset + width <= 16);
1764 : 0 : off_be = 16 - (data->offset + width);
1765 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV4_TOTAL_LEN, data->level);
1766 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
1767 [ # # ]: 0 : if (mask)
1768 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1769 : : else
1770 : 0 : info[idx].offset = off_be;
1771 : : break;
1772 : 0 : case RTE_FLOW_FIELD_IPV4_TTL:
1773 : : MLX5_ASSERT(data->offset + width <= 8);
1774 : 0 : off_be = 8 - (data->offset + width);
1775 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV4_TTL, data->level);
1776 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
1777 [ # # ]: 0 : if (mask)
1778 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1779 : : else
1780 : 0 : info[idx].offset = off_be;
1781 : : break;
1782 : 0 : case RTE_FLOW_FIELD_IPV4_SRC:
1783 : : MLX5_ASSERT(data->offset + width <= 32);
1784 : 0 : off_be = 32 - (data->offset + width);
1785 [ # # ]: 0 : modi_id = CALC_MODI_ID(SIPV4, data->level);
1786 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1787 [ # # ]: 0 : if (mask)
1788 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1789 : : else
1790 : 0 : info[idx].offset = off_be;
1791 : : break;
1792 : 0 : case RTE_FLOW_FIELD_IPV4_DST:
1793 : : MLX5_ASSERT(data->offset + width <= 32);
1794 : 0 : off_be = 32 - (data->offset + width);
1795 [ # # ]: 0 : modi_id = CALC_MODI_ID(DIPV4, data->level);
1796 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1797 [ # # ]: 0 : if (mask)
1798 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1799 : : else
1800 : 0 : info[idx].offset = off_be;
1801 : : break;
1802 : : case RTE_FLOW_FIELD_IPV6_DSCP:
1803 : : MLX5_ASSERT(data->offset + width <= 6);
1804 : : /*
1805 : : * IPv6 DSCP uses OUT_IPV6_TRAFFIC_CLASS as ID but it starts from 2
1806 : : * bits left. Shift the mask left for IPv6 DSCP. Do it here because
1807 : : * it's needed to distinguish DSCP from ECN in data field construct
1808 : : */
1809 [ # # ]: 0 : if (mlx5_dv_modify_ipv6_traffic_class_supported(priv)) {
1810 : 0 : off_be = 6 - (data->offset + width) + MLX5_IPV6_HDR_DSCP_SHIFT;
1811 : 0 : info[idx] = (struct field_modify_info){1, 0,
1812 : : MLX5_MODI_OUT_IPV6_TRAFFIC_CLASS};
1813 : : } else {
1814 : 0 : off_be = 6 - (data->offset + width);
1815 : 0 : info[idx] = (struct field_modify_info){1, 0,
1816 : : MLX5_MODI_OUT_IP_DSCP};
1817 : : }
1818 [ # # ]: 0 : if (mask)
1819 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1820 : : else
1821 : 0 : info[idx].offset = off_be;
1822 : : break;
1823 : 0 : case RTE_FLOW_FIELD_IPV6_TRAFFIC_CLASS:
1824 : : MLX5_ASSERT(data->offset + width <= 8);
1825 : 0 : off_be = 8 - (data->offset + width);
1826 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV6_TRAFFIC_CLASS, data->level);
1827 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
1828 [ # # ]: 0 : if (mask)
1829 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1830 : : else
1831 : 0 : info[idx].offset = off_be;
1832 : : break;
1833 : 0 : case RTE_FLOW_FIELD_IPV6_FLOW_LABEL:
1834 : : MLX5_ASSERT(data->offset + width <= 20);
1835 : 0 : off_be = 20 - (data->offset + width);
1836 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV6_FLOW_LABEL, data->level);
1837 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1838 [ # # ]: 0 : if (mask)
1839 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1840 : : else
1841 : 0 : info[idx].offset = off_be;
1842 : : break;
1843 : 0 : case RTE_FLOW_FIELD_IPV6_PAYLOAD_LEN:
1844 : : MLX5_ASSERT(data->offset + width <= 16);
1845 : 0 : off_be = 16 - (data->offset + width);
1846 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV6_PAYLOAD_LEN, data->level);
1847 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
1848 [ # # ]: 0 : if (mask)
1849 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1850 : : else
1851 : 0 : info[idx].offset = off_be;
1852 : : break;
1853 : 0 : case RTE_FLOW_FIELD_IPV6_HOPLIMIT:
1854 : : MLX5_ASSERT(data->offset + width <= 8);
1855 : 0 : off_be = 8 - (data->offset + width);
1856 [ # # ]: 0 : modi_id = CALC_MODI_ID(IPV6_HOPLIMIT, data->level);
1857 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
1858 [ # # ]: 0 : if (mask)
1859 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
1860 : : else
1861 : 0 : info[idx].offset = off_be;
1862 : : break;
1863 : 0 : case RTE_FLOW_FIELD_IPV6_SRC: {
1864 : : /*
1865 : : * Fields corresponding to IPv6 source address bytes
1866 : : * arranged according to network byte ordering.
1867 : : */
1868 : 0 : struct field_modify_info fields[] = {
1869 [ # # ]: 0 : { 4, 0, CALC_MODI_ID(SIPV6_127_96, data->level)},
1870 [ # # ]: 0 : { 4, 4, CALC_MODI_ID(SIPV6_95_64, data->level)},
1871 [ # # ]: 0 : { 4, 8, CALC_MODI_ID(SIPV6_63_32, data->level)},
1872 [ # # ]: 0 : { 4, 12, CALC_MODI_ID(SIPV6_31_0, data->level)},
1873 : : };
1874 : : /* First mask to be modified is the mask of 4th address byte. */
1875 : : uint32_t midx = 3;
1876 : :
1877 : : MLX5_ASSERT(data->offset + width <= 128);
1878 : 0 : off_be = 128 - (data->offset + width);
1879 [ # # ]: 0 : while (width > 0 && midx > 0) {
1880 [ # # ]: 0 : if (off_be < 32) {
1881 : 0 : info[idx] = fields[midx];
1882 : 0 : length = off_be + width <= 32 ?
1883 [ # # ]: 0 : width : 32 - off_be;
1884 [ # # ]: 0 : if (mask)
1885 [ # # ]: 0 : mask[midx] = flow_modify_info_mask_32
1886 : : (length, off_be);
1887 : : else
1888 : 0 : info[idx].offset = off_be;
1889 : 0 : width -= length;
1890 : : off_be = 0;
1891 : 0 : idx++;
1892 : : } else {
1893 : 0 : off_be -= 32;
1894 : : }
1895 : 0 : midx--;
1896 : : }
1897 [ # # ]: 0 : if (!width)
1898 : : break;
1899 : 0 : info[idx] = fields[midx];
1900 [ # # ]: 0 : if (mask)
1901 [ # # ]: 0 : mask[midx] = flow_modify_info_mask_32(width, off_be);
1902 : : else
1903 : 0 : info[idx].offset = off_be;
1904 : : break;
1905 : : }
1906 : 0 : case RTE_FLOW_FIELD_IPV6_DST: {
1907 : : /*
1908 : : * Fields corresponding to IPv6 destination address bytes
1909 : : * arranged according to network byte ordering.
1910 : : */
1911 : 0 : struct field_modify_info fields[] = {
1912 [ # # ]: 0 : { 4, 0, CALC_MODI_ID(DIPV6_127_96, data->level)},
1913 [ # # ]: 0 : { 4, 4, CALC_MODI_ID(DIPV6_95_64, data->level)},
1914 [ # # ]: 0 : { 4, 8, CALC_MODI_ID(DIPV6_63_32, data->level)},
1915 [ # # ]: 0 : { 4, 12, CALC_MODI_ID(DIPV6_31_0, data->level)},
1916 : : };
1917 : : /* First mask to be modified is the mask of 4th address byte. */
1918 : : uint32_t midx = 3;
1919 : :
1920 : : MLX5_ASSERT(data->offset + width <= 128);
1921 : 0 : off_be = 128 - (data->offset + width);
1922 [ # # ]: 0 : while (width > 0 && midx > 0) {
1923 [ # # ]: 0 : if (off_be < 32) {
1924 : 0 : info[idx] = fields[midx];
1925 : 0 : length = off_be + width <= 32 ?
1926 [ # # ]: 0 : width : 32 - off_be;
1927 [ # # ]: 0 : if (mask)
1928 [ # # ]: 0 : mask[midx] = flow_modify_info_mask_32
1929 : : (length, off_be);
1930 : : else
1931 : 0 : info[idx].offset = off_be;
1932 : 0 : width -= length;
1933 : : off_be = 0;
1934 : 0 : idx++;
1935 : : } else {
1936 : 0 : off_be -= 32;
1937 : : }
1938 : 0 : midx--;
1939 : : }
1940 [ # # ]: 0 : if (!width)
1941 : : break;
1942 : 0 : info[idx] = fields[midx];
1943 [ # # ]: 0 : if (mask)
1944 [ # # ]: 0 : mask[midx] = flow_modify_info_mask_32(width, off_be);
1945 : : else
1946 : 0 : info[idx].offset = off_be;
1947 : : break;
1948 : : }
1949 : 0 : case RTE_FLOW_FIELD_TCP_PORT_SRC:
1950 : : MLX5_ASSERT(data->offset + width <= 16);
1951 : 0 : off_be = 16 - (data->offset + width);
1952 [ # # ]: 0 : modi_id = CALC_MODI_ID(TCP_SPORT, data->level);
1953 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
1954 [ # # ]: 0 : if (mask)
1955 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1956 : : else
1957 : 0 : info[idx].offset = off_be;
1958 : : break;
1959 : 0 : case RTE_FLOW_FIELD_TCP_PORT_DST:
1960 : : MLX5_ASSERT(data->offset + width <= 16);
1961 : 0 : off_be = 16 - (data->offset + width);
1962 [ # # ]: 0 : modi_id = CALC_MODI_ID(TCP_DPORT, data->level);
1963 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
1964 [ # # ]: 0 : if (mask)
1965 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1966 : : else
1967 : 0 : info[idx].offset = off_be;
1968 : : break;
1969 : 0 : case RTE_FLOW_FIELD_TCP_SEQ_NUM:
1970 : : MLX5_ASSERT(data->offset + width <= 32);
1971 : 0 : off_be = 32 - (data->offset + width);
1972 [ # # ]: 0 : modi_id = CALC_MODI_ID(TCP_SEQ_NUM, data->level);
1973 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1974 [ # # ]: 0 : if (mask)
1975 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1976 : : else
1977 : 0 : info[idx].offset = off_be;
1978 : : break;
1979 : 0 : case RTE_FLOW_FIELD_TCP_ACK_NUM:
1980 : : MLX5_ASSERT(data->offset + width <= 32);
1981 : 0 : off_be = 32 - (data->offset + width);
1982 [ # # ]: 0 : modi_id = CALC_MODI_ID(TCP_ACK_NUM, data->level);
1983 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
1984 [ # # ]: 0 : if (mask)
1985 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
1986 : : else
1987 : 0 : info[idx].offset = off_be;
1988 : : break;
1989 : 0 : case RTE_FLOW_FIELD_TCP_FLAGS:
1990 : : MLX5_ASSERT(data->offset + width <= 9);
1991 : 0 : off_be = 9 - (data->offset + width);
1992 [ # # ]: 0 : modi_id = CALC_MODI_ID(TCP_FLAGS, data->level);
1993 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
1994 [ # # ]: 0 : if (mask)
1995 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
1996 : : else
1997 : 0 : info[idx].offset = off_be;
1998 : : break;
1999 : 0 : case RTE_FLOW_FIELD_TCP_DATA_OFFSET:
2000 : : MLX5_ASSERT(data->offset + width <= 4);
2001 : 0 : off_be = 4 - (data->offset + width);
2002 [ # # ]: 0 : modi_id = CALC_MODI_ID(TCP_DATA_OFFSET, data->level);
2003 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
2004 [ # # ]: 0 : if (mask)
2005 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
2006 : : else
2007 : 0 : info[idx].offset = off_be;
2008 : : break;
2009 : 0 : case RTE_FLOW_FIELD_UDP_PORT_SRC:
2010 : : MLX5_ASSERT(data->offset + width <= 16);
2011 : 0 : off_be = 16 - (data->offset + width);
2012 [ # # ]: 0 : modi_id = CALC_MODI_ID(UDP_SPORT, data->level);
2013 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
2014 [ # # ]: 0 : if (mask)
2015 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
2016 : : else
2017 : 0 : info[idx].offset = off_be;
2018 : : break;
2019 : 0 : case RTE_FLOW_FIELD_UDP_PORT_DST:
2020 : : MLX5_ASSERT(data->offset + width <= 16);
2021 : 0 : off_be = 16 - (data->offset + width);
2022 [ # # ]: 0 : modi_id = CALC_MODI_ID(UDP_DPORT, data->level);
2023 : 0 : info[idx] = (struct field_modify_info){2, 0, modi_id};
2024 [ # # ]: 0 : if (mask)
2025 : 0 : mask[idx] = flow_modify_info_mask_16(width, off_be);
2026 : : else
2027 : 0 : info[idx].offset = off_be;
2028 : : break;
2029 : 0 : case RTE_FLOW_FIELD_VXLAN_VNI:
2030 : : case RTE_FLOW_FIELD_GENEVE_VNI:
2031 : : MLX5_ASSERT(data->offset + width <= 24);
2032 : : /* VNI is on bits 31-8 of TUNNEL_HDR_DW_1. */
2033 : 0 : off_be = 24 - (data->offset + width) + 8;
2034 : 0 : info[idx] = (struct field_modify_info){4, 0,
2035 : : MLX5_MODI_TUNNEL_HDR_DW_1};
2036 [ # # ]: 0 : if (mask)
2037 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2038 : : else
2039 : 0 : info[idx].offset = off_be;
2040 : : break;
2041 : 0 : case RTE_FLOW_FIELD_VXLAN_LAST_RSVD:
2042 : : MLX5_ASSERT(data->offset + width <= 8);
2043 : : /* Last_rsvd is on bits 7-0 of TUNNEL_HDR_DW_1. */
2044 : 0 : off_be = 8 - (data->offset + width);
2045 : 0 : info[idx] = (struct field_modify_info){1, 0, MLX5_MODI_TUNNEL_HDR_DW_1};
2046 [ # # ]: 0 : if (mask)
2047 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
2048 : : else
2049 : 0 : info[idx].offset = off_be;
2050 : : break;
2051 : : case RTE_FLOW_FIELD_GENEVE_OPT_TYPE:
2052 : : MLX5_ASSERT(data->offset + width <= 8);
2053 : : modi_id = flow_geneve_opt_modi_field_get(priv, data);
2054 [ # # ]: 0 : if (modi_id < 0)
2055 : : return;
2056 : : /* Type is on bits 16-8 of GENEVE option header (DW0). */
2057 : 0 : off_be = 32 - (16 + data->offset + width);
2058 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
2059 [ # # ]: 0 : if (mask)
2060 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2061 : : else
2062 : 0 : info[idx].offset = off_be;
2063 : : break;
2064 : : case RTE_FLOW_FIELD_GENEVE_OPT_CLASS:
2065 : : MLX5_ASSERT(data->offset + width <= 16);
2066 : : modi_id = flow_geneve_opt_modi_field_get(priv, data);
2067 [ # # ]: 0 : if (modi_id < 0)
2068 : : return;
2069 : : /* Class is on bits 31-16 of GENEVE option header (DW0). */
2070 : 0 : off_be = 32 - (data->offset + width);
2071 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
2072 [ # # ]: 0 : if (mask)
2073 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2074 : : else
2075 : 0 : info[idx].offset = off_be;
2076 : : break;
2077 : 0 : case RTE_FLOW_FIELD_GENEVE_OPT_DATA:
2078 [ # # ]: 0 : if ((data->offset % 32) + width > 32) {
2079 : 0 : DRV_LOG(ERR, "Geneve TLV option data is per DW.");
2080 : 0 : return;
2081 : : }
2082 : : modi_id = flow_geneve_opt_modi_field_get(priv, data);
2083 [ # # ]: 0 : if (modi_id < 0)
2084 : : return;
2085 : : /* Use offset inside DW. */
2086 : 0 : off_be = 32 - ((data->offset % 32) + width);
2087 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
2088 [ # # ]: 0 : if (mask)
2089 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2090 : : else
2091 : 0 : info[idx].offset = off_be;
2092 : : break;
2093 : 0 : case RTE_FLOW_FIELD_GTP_TEID:
2094 : : MLX5_ASSERT(data->offset + width <= 32);
2095 : 0 : off_be = 32 - (data->offset + width);
2096 : 0 : info[idx] = (struct field_modify_info){4, 0,
2097 : : MLX5_MODI_GTP_TEID};
2098 [ # # ]: 0 : if (mask)
2099 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2100 : : else
2101 : 0 : info[idx].offset = off_be;
2102 : : break;
2103 : 0 : case RTE_FLOW_FIELD_MPLS:
2104 : : MLX5_ASSERT(data->offset + width <= 32);
2105 : 0 : off_be = 32 - (data->offset + width);
2106 : : modi_id = mlx5_mpls_modi_field_get(data);
2107 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
2108 [ # # ]: 0 : if (mask)
2109 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2110 : : else
2111 : 0 : info[idx].offset = off_be;
2112 : : break;
2113 : : case RTE_FLOW_FIELD_TAG:
2114 : : {
2115 : : MLX5_ASSERT(data->offset + width <= 32);
2116 : : uint8_t tag_index = flow_tag_index_get(data);
2117 : : int reg;
2118 : :
2119 : : off_be = (tag_index == RTE_PMD_MLX5_LINEAR_HASH_TAG_INDEX) ?
2120 [ # # ]: 0 : 16 - (data->offset + width) + 16 : data->offset;
2121 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
2122 [ # # ]: 0 : reg = flow_hw_get_reg_id(dev,
2123 : : RTE_FLOW_ITEM_TYPE_TAG,
2124 : : tag_index);
2125 : : else
2126 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG,
2127 : : tag_index, error);
2128 [ # # ]: 0 : if (reg < 0)
2129 : : return;
2130 : : MLX5_ASSERT(reg != REG_NON);
2131 : : MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
2132 : 0 : info[idx] = (struct field_modify_info){4, 0,
2133 : 0 : reg_to_field[reg]};
2134 [ # # ]: 0 : if (mask)
2135 : 0 : mask[idx] = flow_modify_info_mask_32
2136 : : (width, off_be);
2137 : : else
2138 : 0 : info[idx].offset = off_be;
2139 : : }
2140 : : break;
2141 : 0 : case RTE_FLOW_FIELD_MARK:
2142 : : {
2143 : 0 : uint32_t mark_mask = priv->sh->dv_mark_mask;
2144 : : uint32_t mark_count = rte_popcount32(mark_mask);
2145 : : RTE_SET_USED(mark_count);
2146 : : MLX5_ASSERT(data->offset + width <= mark_count);
2147 : 0 : int reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK,
2148 : : 0, error);
2149 [ # # ]: 0 : if (reg < 0)
2150 : : return;
2151 : : MLX5_ASSERT(reg != REG_NON);
2152 : : MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
2153 : 0 : info[idx] = (struct field_modify_info){4, 0,
2154 : 0 : reg_to_field[reg]};
2155 [ # # ]: 0 : if (mask)
2156 : 0 : mask[idx] = flow_modify_info_mask_32_masked
2157 [ # # ]: 0 : (width, data->offset, mark_mask);
2158 : : else
2159 : 0 : info[idx].offset = data->offset;
2160 : : }
2161 : : break;
2162 : 0 : case RTE_FLOW_FIELD_META:
2163 : : {
2164 : 0 : uint32_t meta_mask = priv->sh->dv_meta_mask;
2165 : : uint32_t meta_count = rte_popcount32(meta_mask);
2166 : : RTE_SET_USED(meta_count);
2167 : : MLX5_ASSERT(data->offset + width <= meta_count);
2168 : 0 : int reg = flow_dv_get_metadata_reg(dev, attr, error);
2169 [ # # ]: 0 : if (reg < 0)
2170 : : return;
2171 : : MLX5_ASSERT(reg != REG_NON);
2172 : : MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
2173 : 0 : info[idx] = (struct field_modify_info){4, 0,
2174 : 0 : reg_to_field[reg]};
2175 [ # # ]: 0 : if (mask)
2176 : 0 : mask[idx] = flow_modify_info_mask_32_masked
2177 [ # # ]: 0 : (width, data->offset, meta_mask);
2178 : : else
2179 : 0 : info[idx].offset = data->offset;
2180 : : }
2181 : : break;
2182 : 0 : case RTE_FLOW_FIELD_IPV4_ECN:
2183 : : MLX5_ASSERT(data->offset + width <= 2);
2184 : 0 : off_be = 2 - (data->offset + width);
2185 [ # # ]: 0 : modi_id = CALC_MODI_ID(IP_ECN, data->level);
2186 : 0 : info[idx] = (struct field_modify_info){1, 0, modi_id};
2187 [ # # ]: 0 : if (mask)
2188 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
2189 : : else
2190 : 0 : info[idx].offset = off_be;
2191 : : break;
2192 : 0 : case RTE_FLOW_FIELD_IPV6_ECN:
2193 : : MLX5_ASSERT(data->offset + width <= 2);
2194 : 0 : off_be = 2 - (data->offset + width);
2195 [ # # ]: 0 : if (mlx5_dv_modify_ipv6_traffic_class_supported(priv))
2196 : 0 : info[idx] = (struct field_modify_info){1, 0,
2197 : : MLX5_MODI_OUT_IPV6_TRAFFIC_CLASS};
2198 : : else
2199 : 0 : info[idx] = (struct field_modify_info){1, 0,
2200 : : MLX5_MODI_OUT_IP_ECN};
2201 [ # # ]: 0 : if (mask)
2202 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
2203 : : else
2204 : 0 : info[idx].offset = off_be;
2205 : : break;
2206 : 0 : case RTE_FLOW_FIELD_GTP_PSC_QFI:
2207 : : MLX5_ASSERT(data->offset + width <= 8);
2208 : 0 : off_be = data->offset + 8;
2209 : 0 : info[idx] = (struct field_modify_info){4, 0,
2210 : : MLX5_MODI_GTPU_FIRST_EXT_DW_0};
2211 [ # # ]: 0 : if (mask)
2212 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2213 : : else
2214 : 0 : info[idx].offset = off_be;
2215 : : break;
2216 : 0 : case MLX5_RTE_FLOW_FIELD_META_REG:
2217 : : {
2218 [ # # ]: 0 : uint32_t meta_mask = priv->sh->dv_meta_mask;
2219 : : uint32_t meta_count = rte_popcount32(meta_mask);
2220 : : uint8_t reg = flow_tag_index_get(data);
2221 : :
2222 : : RTE_SET_USED(meta_count);
2223 : : MLX5_ASSERT(data->offset + width <= meta_count);
2224 : : MLX5_ASSERT(reg != REG_NON);
2225 : : MLX5_ASSERT(reg < RTE_DIM(reg_to_field));
2226 : 0 : info[idx] = (struct field_modify_info){4, 0, reg_to_field[reg]};
2227 [ # # ]: 0 : if (mask)
2228 : 0 : mask[idx] = flow_modify_info_mask_32_masked
2229 [ # # ]: 0 : (width, data->offset, meta_mask);
2230 : : else
2231 : 0 : info[idx].offset = data->offset;
2232 : : }
2233 : : break;
2234 : 0 : case RTE_FLOW_FIELD_METER_COLOR:
2235 : : {
2236 : : const uint32_t color_mask =
2237 : : (UINT32_C(1) << MLX5_MTR_COLOR_BITS) - 1;
2238 : : int reg;
2239 : :
2240 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
2241 : : reg = flow_hw_get_reg_id
2242 : : (dev,
2243 : : RTE_FLOW_ITEM_TYPE_METER_COLOR, 0);
2244 : : else
2245 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR,
2246 : : 0, error);
2247 [ # # ]: 0 : if (reg < 0)
2248 : : return;
2249 : : MLX5_ASSERT(reg != REG_NON);
2250 : : MLX5_ASSERT((unsigned int)reg < RTE_DIM(reg_to_field));
2251 : 0 : info[idx] = (struct field_modify_info){4, 0,
2252 : 0 : reg_to_field[reg]};
2253 [ # # ]: 0 : if (mask)
2254 : 0 : mask[idx] = flow_modify_info_mask_32_masked
2255 [ # # ]: 0 : (width, data->offset, color_mask);
2256 : : else
2257 : 0 : info[idx].offset = data->offset;
2258 : : }
2259 : : break;
2260 : 0 : case RTE_FLOW_FIELD_IPV4_PROTO: /* Fall-through. */
2261 : : case RTE_FLOW_FIELD_IPV6_PROTO:
2262 : : MLX5_ASSERT(data->offset + width <= 8);
2263 : 0 : off_be = 8 - (data->offset + width);
2264 : 0 : info[idx] = (struct field_modify_info){1, 0, MLX5_MODI_OUT_IP_PROTOCOL};
2265 [ # # ]: 0 : if (mask)
2266 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
2267 : : else
2268 : 0 : info[idx].offset = off_be;
2269 : : break;
2270 : 0 : case RTE_FLOW_FIELD_ESP_PROTO:
2271 : : MLX5_ASSERT(data->offset + width <= 8);
2272 : 0 : off_be = 8 - (data->offset + width);
2273 : 0 : info[idx] = (struct field_modify_info){1, 0, MLX5_MODI_OUT_IPSEC_NEXT_HDR};
2274 [ # # ]: 0 : if (mask)
2275 : 0 : mask[idx] = flow_modify_info_mask_8(width, off_be);
2276 : : else
2277 : 0 : info[idx].offset = off_be;
2278 : : break;
2279 : 0 : case RTE_FLOW_FIELD_ESP_SPI:
2280 : : MLX5_ASSERT(data->offset + width <= 32);
2281 : 0 : off_be = 32 - (data->offset + width);
2282 [ # # ]: 0 : modi_id = CALC_MODI_ID(ESP_SPI, data->level);
2283 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
2284 [ # # ]: 0 : if (mask)
2285 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2286 : : else
2287 : 0 : info[idx].offset = off_be;
2288 : : break;
2289 : 0 : case RTE_FLOW_FIELD_ESP_SEQ_NUM:
2290 : : MLX5_ASSERT(data->offset + width <= 32);
2291 : 0 : off_be = 32 - (data->offset + width);
2292 [ # # ]: 0 : modi_id = CALC_MODI_ID(ESP_SEQ_NUM, data->level);
2293 : 0 : info[idx] = (struct field_modify_info){4, 0, modi_id};
2294 [ # # ]: 0 : if (mask)
2295 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2296 : : else
2297 : 0 : info[idx].offset = off_be;
2298 : : break;
2299 : 0 : case RTE_FLOW_FIELD_FLEX_ITEM:
2300 : : MLX5_ASSERT(data->flex_handle != NULL && !(data->offset & 0x7));
2301 : 0 : mlx5_modify_flex_item(dev, (const struct mlx5_flex_item *)data->flex_handle,
2302 : : data, info, mask, width);
2303 : 0 : break;
2304 : 0 : case RTE_FLOW_FIELD_HASH_RESULT:
2305 : : MLX5_ASSERT(data->offset + width <= 32);
2306 : 0 : off_be = 32 - (data->offset + width);
2307 : 0 : info[idx] = (struct field_modify_info){4, 0,
2308 : : MLX5_MODI_HASH_RESULT};
2309 [ # # ]: 0 : if (mask)
2310 : 0 : mask[idx] = flow_modify_info_mask_32(width, off_be);
2311 : : else
2312 : 0 : info[idx].offset = off_be;
2313 : : break;
2314 : : case RTE_FLOW_FIELD_POINTER:
2315 : : case RTE_FLOW_FIELD_VALUE:
2316 : : default:
2317 : : MLX5_ASSERT(false);
2318 : : break;
2319 : : }
2320 : : }
2321 : :
2322 : : /**
2323 : : * Convert modify_field action to DV specification.
2324 : : *
2325 : : * @param[in] dev
2326 : : * Pointer to the rte_eth_dev structure.
2327 : : * @param[in,out] resource
2328 : : * Pointer to the modify-header resource.
2329 : : * @param[in] action
2330 : : * Pointer to action specification.
2331 : : * @param[in] attr
2332 : : * Attributes of flow that includes this item.
2333 : : * @param[out] error
2334 : : * Pointer to the error structure.
2335 : : *
2336 : : * @return
2337 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2338 : : */
2339 : : static int
2340 : 0 : flow_dv_convert_action_modify_field
2341 : : (struct rte_eth_dev *dev,
2342 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
2343 : : const struct rte_flow_action *action,
2344 : : const struct rte_flow_attr *attr,
2345 : : struct rte_flow_error *error)
2346 : : {
2347 : 0 : const struct rte_flow_action_modify_field *conf =
2348 : : (const struct rte_flow_action_modify_field *)(action->conf);
2349 : 0 : struct rte_flow_item item = {
2350 : : .spec = NULL,
2351 : : .mask = NULL
2352 : : };
2353 : 0 : struct field_modify_info field[MLX5_ACT_MAX_MOD_FIELDS] = {
2354 : : {0, 0, 0} };
2355 : 0 : struct field_modify_info dcopy[MLX5_ACT_MAX_MOD_FIELDS] = {
2356 : : {0, 0, 0} };
2357 : 0 : uint32_t mask[MLX5_ACT_MAX_MOD_FIELDS] = {0, 0, 0, 0, 0};
2358 : 0 : uint32_t type, meta = 0, dscp = 0;
2359 : :
2360 [ # # ]: 0 : if (conf->src.field == RTE_FLOW_FIELD_POINTER ||
2361 : : conf->src.field == RTE_FLOW_FIELD_VALUE) {
2362 : 0 : type = conf->operation == RTE_FLOW_MODIFY_SET ?
2363 [ # # ]: 0 : MLX5_MODIFICATION_TYPE_SET : MLX5_MODIFICATION_TYPE_ADD;
2364 : : /** For SET fill the destination field (field) first. */
2365 : 0 : mlx5_flow_field_id_to_modify_info(&conf->dst, field, mask,
2366 : 0 : conf->width, dev,
2367 : : attr, error);
2368 : 0 : item.spec = conf->src.field == RTE_FLOW_FIELD_POINTER ?
2369 [ # # ]: 0 : (void *)(uintptr_t)conf->src.pvalue :
2370 : : (void *)(uintptr_t)&conf->src.value;
2371 [ # # ]: 0 : if (conf->dst.field == RTE_FLOW_FIELD_META ||
2372 [ # # ]: 0 : conf->dst.field == RTE_FLOW_FIELD_TAG ||
2373 : : conf->dst.field == RTE_FLOW_FIELD_METER_COLOR) {
2374 : 0 : meta = *(const unaligned_uint32_t *)item.spec;
2375 [ # # ]: 0 : meta = rte_cpu_to_be_32(meta);
2376 : 0 : item.spec = &meta;
2377 : : }
2378 [ # # # # ]: 0 : if (mlx5_dv_modify_ipv6_traffic_class_supported(dev->data->dev_private) &&
2379 : 0 : conf->dst.field == RTE_FLOW_FIELD_IPV6_DSCP &&
2380 [ # # ]: 0 : !(mask[0] & MLX5_IPV6_HDR_ECN_MASK)) {
2381 : 0 : dscp = *(const unaligned_uint32_t *)item.spec;
2382 : : /*
2383 : : * IPv6 DSCP uses OUT_IPV6_TRAFFIC_CLASS as ID but it starts from 2
2384 : : * bits left. Shift the data left for IPv6 DSCP
2385 : : */
2386 : 0 : dscp <<= MLX5_IPV6_HDR_DSCP_SHIFT;
2387 : 0 : item.spec = &dscp;
2388 : : }
2389 : : } else {
2390 : : type = MLX5_MODIFICATION_TYPE_COPY;
2391 : : /** For COPY fill the destination field (dcopy) without mask. */
2392 : 0 : mlx5_flow_field_id_to_modify_info(&conf->dst, dcopy, NULL,
2393 : 0 : conf->width, dev,
2394 : : attr, error);
2395 : : /** Then construct the source field (field) with mask. */
2396 : 0 : mlx5_flow_field_id_to_modify_info(&conf->src, field, mask,
2397 : 0 : conf->width, dev,
2398 : : attr, error);
2399 : : }
2400 : 0 : item.mask = &mask;
2401 : 0 : return flow_dv_convert_modify_action(&item,
2402 : : field, dcopy, resource, type, error);
2403 : : }
2404 : :
2405 : : /**
2406 : : * Validate MARK item.
2407 : : *
2408 : : * @param[in] dev
2409 : : * Pointer to the rte_eth_dev structure.
2410 : : * @param[in] item
2411 : : * Item specification.
2412 : : * @param[in] attr
2413 : : * Attributes of flow that includes this item.
2414 : : * @param[out] error
2415 : : * Pointer to error structure.
2416 : : *
2417 : : * @return
2418 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2419 : : */
2420 : : static int
2421 : 0 : flow_dv_validate_item_mark(struct rte_eth_dev *dev,
2422 : : const struct rte_flow_item *item,
2423 : : const struct rte_flow_attr *attr __rte_unused,
2424 : : struct rte_flow_error *error)
2425 : : {
2426 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2427 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
2428 : 0 : const struct rte_flow_item_mark *spec = item->spec;
2429 : 0 : const struct rte_flow_item_mark *mask = item->mask;
2430 : 0 : const struct rte_flow_item_mark nic_mask = {
2431 : 0 : .id = priv->sh->dv_mark_mask,
2432 : : };
2433 : : int ret;
2434 : :
2435 [ # # ]: 0 : if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
2436 : 0 : return rte_flow_error_set(error, ENOTSUP,
2437 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2438 : : "extended metadata feature"
2439 : : " isn't enabled");
2440 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
2441 : 0 : return rte_flow_error_set(error, ENOTSUP,
2442 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2443 : : "extended metadata register"
2444 : : " isn't supported");
2445 [ # # ]: 0 : if (!nic_mask.id)
2446 : 0 : return rte_flow_error_set(error, ENOTSUP,
2447 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2448 : : "extended metadata register"
2449 : : " isn't available");
2450 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
2451 [ # # ]: 0 : if (ret < 0)
2452 : : return ret;
2453 [ # # ]: 0 : if (!spec)
2454 : 0 : return rte_flow_error_set(error, EINVAL,
2455 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2456 : 0 : item->spec,
2457 : : "data cannot be empty");
2458 [ # # ]: 0 : if (spec->id >= (MLX5_FLOW_MARK_MAX & nic_mask.id))
2459 : 0 : return rte_flow_error_set(error, EINVAL,
2460 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
2461 : 0 : &spec->id,
2462 : : "mark id exceeds the limit");
2463 [ # # ]: 0 : if (!mask)
2464 : : mask = &nic_mask;
2465 [ # # ]: 0 : if (!mask->id)
2466 : 0 : return rte_flow_error_set(error, EINVAL,
2467 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2468 : : "mask cannot be zero");
2469 : :
2470 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2471 : : (const uint8_t *)&nic_mask,
2472 : : sizeof(struct rte_flow_item_mark),
2473 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2474 : : if (ret < 0)
2475 : : return ret;
2476 : : return 0;
2477 : : }
2478 : :
2479 : : /**
2480 : : * Validate META item.
2481 : : *
2482 : : * @param[in] dev
2483 : : * Pointer to the rte_eth_dev structure.
2484 : : * @param[in] item
2485 : : * Item specification.
2486 : : * @param[in] attr
2487 : : * Attributes of flow that includes this item.
2488 : : * @param[out] error
2489 : : * Pointer to error structure.
2490 : : *
2491 : : * @return
2492 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2493 : : */
2494 : : static int
2495 : 0 : flow_dv_validate_item_meta(struct rte_eth_dev *dev __rte_unused,
2496 : : const struct rte_flow_item *item,
2497 : : const struct rte_flow_attr *attr,
2498 : : struct rte_flow_error *error)
2499 : : {
2500 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2501 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
2502 : 0 : const struct rte_flow_item_meta *spec = item->spec;
2503 : 0 : const struct rte_flow_item_meta *mask = item->mask;
2504 : 0 : struct rte_flow_item_meta nic_mask = {
2505 : : .data = UINT32_MAX
2506 : : };
2507 : : int reg;
2508 : : int ret;
2509 : :
2510 [ # # ]: 0 : if (!spec)
2511 : 0 : return rte_flow_error_set(error, EINVAL,
2512 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2513 : : item->spec,
2514 : : "data cannot be empty");
2515 [ # # ]: 0 : if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
2516 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
2517 : 0 : return rte_flow_error_set(error, ENOTSUP,
2518 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2519 : : "extended metadata register"
2520 : : " isn't supported");
2521 : 0 : reg = flow_dv_get_metadata_reg(dev, attr, error);
2522 [ # # ]: 0 : if (reg < 0)
2523 : : return reg;
2524 [ # # ]: 0 : if (reg == REG_NON)
2525 : 0 : return rte_flow_error_set(error, ENOTSUP,
2526 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2527 : : "unavailable extended metadata register");
2528 [ # # ]: 0 : if (reg == REG_B)
2529 : 0 : return rte_flow_error_set(error, ENOTSUP,
2530 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2531 : : "match on reg_b "
2532 : : "isn't supported");
2533 [ # # ]: 0 : if (reg != REG_A)
2534 : 0 : nic_mask.data = priv->sh->dv_meta_mask;
2535 : : } else {
2536 [ # # ]: 0 : if (attr->transfer)
2537 : 0 : return rte_flow_error_set(error, ENOTSUP,
2538 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2539 : : "extended metadata feature "
2540 : : "should be enabled when "
2541 : : "meta item is requested "
2542 : : "with e-switch mode ");
2543 [ # # ]: 0 : if (attr->ingress)
2544 : 0 : return rte_flow_error_set(error, ENOTSUP,
2545 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2546 : : "match on metadata for ingress "
2547 : : "is not supported in legacy "
2548 : : "metadata mode");
2549 : : }
2550 [ # # ]: 0 : if (!mask)
2551 : : mask = &rte_flow_item_meta_mask;
2552 [ # # ]: 0 : if (!mask->data)
2553 : 0 : return rte_flow_error_set(error, EINVAL,
2554 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2555 : : "mask cannot be zero");
2556 : :
2557 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2558 : : (const uint8_t *)&nic_mask,
2559 : : sizeof(struct rte_flow_item_meta),
2560 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2561 : 0 : return ret;
2562 : : }
2563 : :
2564 : : /**
2565 : : * Validate TAG item.
2566 : : *
2567 : : * @param[in] dev
2568 : : * Pointer to the rte_eth_dev structure.
2569 : : * @param[in] item
2570 : : * Item specification.
2571 : : * @param[in] tag_bitmap
2572 : : * Tag index bitmap.
2573 : : * @param[in] attr
2574 : : * Attributes of flow that includes this item.
2575 : : * @param[out] error
2576 : : * Pointer to error structure.
2577 : : *
2578 : : * @return
2579 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2580 : : */
2581 : : static int
2582 : 0 : flow_dv_validate_item_tag(struct rte_eth_dev *dev,
2583 : : const struct rte_flow_item *item,
2584 : : uint32_t *tag_bitmap,
2585 : : const struct rte_flow_attr *attr __rte_unused,
2586 : : struct rte_flow_error *error)
2587 : : {
2588 : 0 : const struct rte_flow_item_tag *spec = item->spec;
2589 : 0 : const struct rte_flow_item_tag *mask = item->mask;
2590 : 0 : const struct rte_flow_item_tag nic_mask = {
2591 : : .data = RTE_BE32(UINT32_MAX),
2592 : : .index = 0xff,
2593 : : };
2594 : : int ret;
2595 : :
2596 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
2597 : 0 : return rte_flow_error_set(error, ENOTSUP,
2598 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2599 : : "extensive metadata register"
2600 : : " isn't supported");
2601 [ # # ]: 0 : if (!spec)
2602 : 0 : return rte_flow_error_set(error, EINVAL,
2603 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2604 : 0 : item->spec,
2605 : : "data cannot be empty");
2606 [ # # ]: 0 : if (!mask)
2607 : : mask = &rte_flow_item_tag_mask;
2608 [ # # ]: 0 : if (!mask->data)
2609 : 0 : return rte_flow_error_set(error, EINVAL,
2610 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2611 : : "mask cannot be zero");
2612 : :
2613 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2614 : : (const uint8_t *)&nic_mask,
2615 : : sizeof(struct rte_flow_item_tag),
2616 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2617 [ # # ]: 0 : if (ret < 0)
2618 : : return ret;
2619 [ # # ]: 0 : if (mask->index != 0xff)
2620 : 0 : return rte_flow_error_set(error, EINVAL,
2621 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
2622 : : "partial mask for tag index"
2623 : : " is not supported");
2624 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, spec->index, error);
2625 [ # # ]: 0 : if (ret < 0)
2626 : : return ret;
2627 : : MLX5_ASSERT(ret != REG_NON);
2628 [ # # ]: 0 : if (*tag_bitmap & (1 << ret))
2629 : 0 : return rte_flow_error_set(error, EINVAL,
2630 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2631 : 0 : item->spec,
2632 : : "Duplicated tag index");
2633 : 0 : *tag_bitmap |= 1 << ret;
2634 : 0 : return 0;
2635 : : }
2636 : :
2637 : : /**
2638 : : * Validate vport item.
2639 : : *
2640 : : * @param[in] dev
2641 : : * Pointer to the rte_eth_dev structure.
2642 : : * @param[in] item
2643 : : * Item specification.
2644 : : * @param[in] attr
2645 : : * Attributes of flow that includes this item.
2646 : : * @param[in] item_flags
2647 : : * Bit-fields that holds the items detected until now.
2648 : : * @param[out] error
2649 : : * Pointer to error structure.
2650 : : *
2651 : : * @return
2652 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2653 : : */
2654 : : static int
2655 : 0 : flow_dv_validate_item_port_id(struct rte_eth_dev *dev,
2656 : : const struct rte_flow_item *item,
2657 : : const struct rte_flow_attr *attr,
2658 : : uint64_t item_flags,
2659 : : struct mlx5_priv **act_priv,
2660 : : struct rte_flow_error *error)
2661 : : {
2662 : 0 : const struct rte_flow_item_port_id *spec = item->spec;
2663 : 0 : const struct rte_flow_item_port_id *mask = item->mask;
2664 : 0 : const struct rte_flow_item_port_id switch_mask = {
2665 : : .id = 0xffffffff,
2666 : : };
2667 : : struct mlx5_priv *esw_priv;
2668 : : struct mlx5_priv *dev_priv;
2669 : : int ret;
2670 : :
2671 [ # # ]: 0 : if (!attr->transfer)
2672 : 0 : return rte_flow_error_set(error, EINVAL,
2673 : : RTE_FLOW_ERROR_TYPE_ITEM,
2674 : : NULL,
2675 : : "match on port id is valid only"
2676 : : " when transfer flag is enabled");
2677 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_PORT_ID)
2678 : 0 : return rte_flow_error_set(error, ENOTSUP,
2679 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2680 : : "multiple source ports are not"
2681 : : " supported");
2682 [ # # ]: 0 : if (!mask)
2683 : : mask = &switch_mask;
2684 [ # # ]: 0 : if (mask->id != 0xffffffff)
2685 : 0 : return rte_flow_error_set(error, ENOTSUP,
2686 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK,
2687 : : mask,
2688 : : "no support for partial mask on"
2689 : : " \"id\" field");
2690 : 0 : ret = mlx5_flow_item_acceptable
2691 : : (dev, item, (const uint8_t *)mask,
2692 : : (const uint8_t *)&rte_flow_item_port_id_mask,
2693 : : sizeof(struct rte_flow_item_port_id),
2694 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2695 [ # # ]: 0 : if (ret)
2696 : : return ret;
2697 [ # # ]: 0 : if (!spec)
2698 : : return 0;
2699 [ # # ]: 0 : if (spec->id == MLX5_PORT_ESW_MGR)
2700 : : return 0;
2701 : 0 : esw_priv = mlx5_port_to_eswitch_info(spec->id, false);
2702 [ # # ]: 0 : if (!esw_priv)
2703 : 0 : return rte_flow_error_set(error, rte_errno,
2704 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2705 : : "failed to obtain E-Switch info for"
2706 : : " port");
2707 : 0 : dev_priv = mlx5_dev_to_eswitch_info(dev);
2708 [ # # ]: 0 : if (!dev_priv)
2709 : 0 : return rte_flow_error_set(error, rte_errno,
2710 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2711 : : NULL,
2712 : : "failed to obtain E-Switch info");
2713 [ # # ]: 0 : if (esw_priv->domain_id != dev_priv->domain_id)
2714 : 0 : return rte_flow_error_set(error, EINVAL,
2715 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2716 : : "cannot match on a port from a"
2717 : : " different E-Switch");
2718 : 0 : *act_priv = esw_priv;
2719 : 0 : return 0;
2720 : : }
2721 : :
2722 : : /**
2723 : : * Validate represented port item.
2724 : : *
2725 : : * @param[in] dev
2726 : : * Pointer to the rte_eth_dev structure.
2727 : : * @param[in] item
2728 : : * Item specification.
2729 : : * @param[in] attr
2730 : : * Attributes of flow that includes this item.
2731 : : * @param[in] item_flags
2732 : : * Bit-fields that holds the items detected until now.
2733 : : * @param[out] error
2734 : : * Pointer to error structure.
2735 : : *
2736 : : * @return
2737 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2738 : : */
2739 : : static int
2740 : 0 : flow_dv_validate_item_represented_port(struct rte_eth_dev *dev,
2741 : : const struct rte_flow_item *item,
2742 : : const struct rte_flow_attr *attr,
2743 : : uint64_t item_flags,
2744 : : struct mlx5_priv **act_priv,
2745 : : struct rte_flow_error *error)
2746 : : {
2747 : 0 : const struct rte_flow_item_ethdev *spec = item->spec;
2748 : 0 : const struct rte_flow_item_ethdev *mask = item->mask;
2749 : 0 : const struct rte_flow_item_ethdev switch_mask = {
2750 : : .port_id = UINT16_MAX,
2751 : : };
2752 : : struct mlx5_priv *esw_priv;
2753 : : struct mlx5_priv *dev_priv;
2754 : : int ret;
2755 : :
2756 [ # # ]: 0 : if (!attr->transfer)
2757 : 0 : return rte_flow_error_set(error, EINVAL,
2758 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2759 : : "match on port id is valid only when transfer flag is enabled");
2760 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_REPRESENTED_PORT)
2761 : 0 : return rte_flow_error_set(error, ENOTSUP,
2762 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2763 : : "multiple source ports are not supported");
2764 [ # # ]: 0 : if (!mask)
2765 : : mask = &switch_mask;
2766 [ # # ]: 0 : if (mask->port_id != UINT16_MAX)
2767 : 0 : return rte_flow_error_set(error, ENOTSUP,
2768 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
2769 : : "no support for partial mask on \"id\" field");
2770 : 0 : ret = mlx5_flow_item_acceptable
2771 : : (dev, item, (const uint8_t *)mask,
2772 : : (const uint8_t *)&rte_flow_item_ethdev_mask,
2773 : : sizeof(struct rte_flow_item_ethdev),
2774 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2775 [ # # ]: 0 : if (ret)
2776 : : return ret;
2777 [ # # # # ]: 0 : if (!spec || spec->port_id == UINT16_MAX)
2778 : : return 0;
2779 : 0 : esw_priv = mlx5_port_to_eswitch_info(spec->port_id, false);
2780 [ # # ]: 0 : if (!esw_priv)
2781 : 0 : return rte_flow_error_set(error, rte_errno,
2782 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2783 : : "failed to obtain E-Switch info for port");
2784 : 0 : dev_priv = mlx5_dev_to_eswitch_info(dev);
2785 [ # # ]: 0 : if (!dev_priv)
2786 : 0 : return rte_flow_error_set(error, rte_errno,
2787 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2788 : : NULL,
2789 : : "failed to obtain E-Switch info");
2790 [ # # ]: 0 : if (esw_priv->domain_id != dev_priv->domain_id)
2791 : 0 : return rte_flow_error_set(error, EINVAL,
2792 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, spec,
2793 : : "cannot match on a port from a different E-Switch");
2794 : 0 : *act_priv = esw_priv;
2795 : 0 : return 0;
2796 : : }
2797 : :
2798 : : /**
2799 : : * Validate VLAN item.
2800 : : *
2801 : : * @param[in] item
2802 : : * Item specification.
2803 : : * @param[in] item_flags
2804 : : * Bit-fields that holds the items detected until now.
2805 : : * @param[in] dev
2806 : : * Ethernet device flow is being created on.
2807 : : * @param[out] error
2808 : : * Pointer to error structure.
2809 : : *
2810 : : * @return
2811 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2812 : : */
2813 : : int
2814 : 0 : mlx5_flow_dv_validate_item_vlan(const struct rte_flow_item *item,
2815 : : uint64_t item_flags,
2816 : : struct rte_eth_dev *dev,
2817 : : struct rte_flow_error *error)
2818 : : {
2819 : 0 : const struct rte_flow_item_vlan *mask = item->mask;
2820 : 0 : const struct rte_flow_item_vlan nic_mask = {
2821 : : .hdr.vlan_tci = RTE_BE16(UINT16_MAX),
2822 : : .hdr.eth_proto = RTE_BE16(UINT16_MAX),
2823 : : .has_more_vlan = 1,
2824 : : };
2825 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
2826 : : int ret;
2827 : : const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
2828 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L4) :
2829 : : (MLX5_FLOW_LAYER_OUTER_L3 |
2830 : : MLX5_FLOW_LAYER_OUTER_L4);
2831 [ # # ]: 0 : const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
2832 : : MLX5_FLOW_LAYER_OUTER_VLAN;
2833 : :
2834 [ # # ]: 0 : if (item_flags & vlanm)
2835 : 0 : return rte_flow_error_set(error, EINVAL,
2836 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2837 : : "multiple VLAN layers not supported");
2838 [ # # ]: 0 : else if ((item_flags & l34m) != 0)
2839 : 0 : return rte_flow_error_set(error, EINVAL,
2840 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2841 : : "VLAN cannot follow L3/L4 layer");
2842 [ # # ]: 0 : if (!mask)
2843 : : mask = &rte_flow_item_vlan_mask;
2844 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2845 : : (const uint8_t *)&nic_mask,
2846 : : sizeof(struct rte_flow_item_vlan),
2847 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2848 [ # # ]: 0 : if (ret)
2849 : : return ret;
2850 [ # # # # ]: 0 : if (!tunnel && mask->hdr.vlan_tci != RTE_BE16(0x0fff)) {
2851 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2852 : :
2853 [ # # ]: 0 : if (priv->vmwa_context) {
2854 : : /*
2855 : : * Non-NULL context means we have a virtual machine
2856 : : * and SR-IOV enabled, we have to create VLAN interface
2857 : : * to make hypervisor to setup E-Switch vport
2858 : : * context correctly. We avoid creating the multiple
2859 : : * VLAN interfaces, so we cannot support VLAN tag mask.
2860 : : */
2861 : 0 : return rte_flow_error_set(error, EINVAL,
2862 : : RTE_FLOW_ERROR_TYPE_ITEM,
2863 : : item,
2864 : : "VLAN tag mask is not"
2865 : : " supported in virtual"
2866 : : " environment");
2867 : : }
2868 : : }
2869 : : return 0;
2870 : : }
2871 : :
2872 : : /*
2873 : : * GTP flags are contained in 1 byte of the format:
2874 : : * -------------------------------------------
2875 : : * | bit | 0 - 2 | 3 | 4 | 5 | 6 | 7 |
2876 : : * |-----------------------------------------|
2877 : : * | value | Version | PT | Res | E | S | PN |
2878 : : * -------------------------------------------
2879 : : *
2880 : : * Matching is supported only for GTP flags E, S, PN.
2881 : : */
2882 : : #define MLX5_GTP_FLAGS_MASK 0x07
2883 : :
2884 : : /**
2885 : : * Validate GTP item.
2886 : : *
2887 : : * @param[in] dev
2888 : : * Pointer to the rte_eth_dev structure.
2889 : : * @param[in] item
2890 : : * Item specification.
2891 : : * @param[in] item_flags
2892 : : * Bit-fields that holds the items detected until now.
2893 : : * @param[out] error
2894 : : * Pointer to error structure.
2895 : : *
2896 : : * @return
2897 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2898 : : */
2899 : : int
2900 : 0 : mlx5_flow_dv_validate_item_gtp(struct rte_eth_dev *dev,
2901 : : const struct rte_flow_item *item,
2902 : : uint64_t item_flags,
2903 : : struct rte_flow_error *error)
2904 : : {
2905 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2906 : 0 : const struct rte_flow_item_gtp *spec = item->spec;
2907 : 0 : const struct rte_flow_item_gtp *mask = item->mask;
2908 : 0 : const struct rte_flow_item_gtp nic_mask = {
2909 : : .hdr.gtp_hdr_info = MLX5_GTP_FLAGS_MASK,
2910 : : .hdr.msg_type = 0xff,
2911 : : .hdr.teid = RTE_BE32(0xffffffff),
2912 : : };
2913 : :
2914 [ # # ]: 0 : if (!priv->sh->cdev->config.hca_attr.tunnel_stateless_gtp)
2915 : 0 : return rte_flow_error_set(error, ENOTSUP,
2916 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2917 : : "GTP support is not enabled");
2918 [ # # ]: 0 : if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
2919 : 0 : return rte_flow_error_set(error, ENOTSUP,
2920 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2921 : : "multiple tunnel layers not"
2922 : : " supported");
2923 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
2924 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
2925 : 0 : return rte_flow_error_set(error, EINVAL,
2926 : : RTE_FLOW_ERROR_TYPE_ITEM,
2927 : : item, "no outer UDP layer found");
2928 : : }
2929 [ # # ]: 0 : if (!mask)
2930 : : mask = &rte_flow_item_gtp_mask;
2931 [ # # # # ]: 0 : if (spec && spec->hdr.gtp_hdr_info & ~MLX5_GTP_FLAGS_MASK)
2932 : 0 : return rte_flow_error_set(error, ENOTSUP,
2933 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
2934 : : "Match is supported for GTP"
2935 : : " flags only");
2936 : 0 : return mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
2937 : : (const uint8_t *)&nic_mask,
2938 : : sizeof(struct rte_flow_item_gtp),
2939 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
2940 : : }
2941 : :
2942 : : /**
2943 : : * Validate GTP PSC item.
2944 : : *
2945 : : * @param[in] item
2946 : : * Item specification.
2947 : : * @param[in] last_item
2948 : : * Previous validated item in the pattern items.
2949 : : * @param[in] gtp_item
2950 : : * Previous GTP item specification.
2951 : : * @param root
2952 : : * Whether action is on root table.
2953 : : * @param[out] error
2954 : : * Pointer to error structure.
2955 : : *
2956 : : * @return
2957 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2958 : : */
2959 : : int
2960 : 0 : mlx5_flow_dv_validate_item_gtp_psc(const struct rte_eth_dev *dev,
2961 : : const struct rte_flow_item *item,
2962 : : uint64_t last_item,
2963 : : const struct rte_flow_item *gtp_item,
2964 : : bool root,
2965 : : struct rte_flow_error *error)
2966 : : {
2967 : : const struct rte_flow_item_gtp *gtp_spec;
2968 : : const struct rte_flow_item_gtp *gtp_mask;
2969 : : const struct rte_flow_item_gtp_psc *mask;
2970 : 0 : const struct rte_flow_item_gtp_psc nic_mask = {
2971 : : .hdr.type = 0xF,
2972 : : .hdr.qfi = 0x3F,
2973 : : };
2974 : :
2975 [ # # # # ]: 0 : if (!gtp_item || !(last_item & MLX5_FLOW_LAYER_GTP))
2976 : 0 : return rte_flow_error_set
2977 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2978 : : "GTP PSC item must be preceded with GTP item");
2979 : 0 : gtp_spec = gtp_item->spec;
2980 [ # # ]: 0 : gtp_mask = gtp_item->mask ? gtp_item->mask : &rte_flow_item_gtp_mask;
2981 : : /* GTP spec and E flag is requested to match zero. */
2982 [ # # ]: 0 : if (gtp_spec &&
2983 : 0 : (gtp_mask->hdr.gtp_hdr_info &
2984 [ # # ]: 0 : ~gtp_spec->hdr.gtp_hdr_info & MLX5_GTP_EXT_HEADER_FLAG))
2985 : 0 : return rte_flow_error_set
2986 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
2987 : : "GTP E flag must be 1 to match GTP PSC");
2988 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
2989 : : /* Check the flow is not created in group zero. */
2990 [ # # ]: 0 : if (root)
2991 : 0 : return rte_flow_error_set
2992 : : (error, ENOTSUP,
2993 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2994 : : "GTP PSC is not supported for group 0");
2995 : : /* GTP spec is here and E flag is requested to match zero. */
2996 [ # # ]: 0 : if (!item->spec)
2997 : : return 0;
2998 : : }
2999 [ # # ]: 0 : mask = item->mask ? item->mask : &rte_flow_item_gtp_psc_mask;
3000 : 0 : return mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
3001 : : (const uint8_t *)&nic_mask,
3002 : : sizeof(struct rte_flow_item_gtp_psc),
3003 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
3004 : : }
3005 : :
3006 : : /*
3007 : : * Validate IPV4 item.
3008 : : * Use existing validation function mlx5_flow_validate_item_ipv4(), and
3009 : : * add specific validation of fragment_offset field,
3010 : : *
3011 : : * @param[in] dev
3012 : : * Pointer to the rte_eth_dev structure.
3013 : : * @param[in] item
3014 : : * Item specification.
3015 : : * @param[in] item_flags
3016 : : * Bit-fields that holds the items detected until now.
3017 : : * @param[in] last_item
3018 : : * Previous validated item in the pattern items.
3019 : : * @param[in] ether_type
3020 : : * Type in the ethernet layer header (including dot1q).
3021 : : * @param[in] acc_mask
3022 : : * Default acceptable mask (will be adjusted).
3023 : : * @param[out] error
3024 : : * Pointer to error structure.
3025 : : *
3026 : : * @return
3027 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3028 : : */
3029 : : int
3030 : 0 : mlx5_flow_dv_validate_item_ipv4(struct rte_eth_dev *dev,
3031 : : const struct rte_flow_item *item,
3032 : : uint64_t item_flags,
3033 : : uint64_t last_item,
3034 : : uint16_t ether_type,
3035 : : const struct rte_flow_item_ipv4 *acc_mask,
3036 : : struct rte_flow_error *error)
3037 : : {
3038 : : int ret;
3039 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3040 : 0 : struct mlx5_hca_attr *attr = &priv->sh->cdev->config.hca_attr;
3041 : 0 : const struct rte_flow_item_ipv4 *spec = item->spec;
3042 : 0 : const struct rte_flow_item_ipv4 *last = item->last;
3043 : 0 : const struct rte_flow_item_ipv4 *mask = item->mask;
3044 : : rte_be16_t fragment_offset_spec = 0;
3045 : : rte_be16_t fragment_offset_last = 0;
3046 : 0 : struct rte_flow_item_ipv4 actual_ipv4_mask = *acc_mask;
3047 : :
3048 [ # # # # ]: 0 : if (mask && (mask->hdr.version_ihl & RTE_IPV4_HDR_IHL_MASK)) {
3049 : 0 : int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
3050 : : bool ihl_cap = !tunnel ?
3051 [ # # ]: 0 : attr->outer_ipv4_ihl : attr->inner_ipv4_ihl;
3052 [ # # ]: 0 : if (!ihl_cap)
3053 : 0 : return rte_flow_error_set(error, ENOTSUP,
3054 : : RTE_FLOW_ERROR_TYPE_ITEM,
3055 : : item,
3056 : : "IPV4 ihl offload not supported");
3057 : 0 : actual_ipv4_mask.hdr.version_ihl = mask->hdr.version_ihl;
3058 : : }
3059 : 0 : ret = mlx5_flow_validate_item_ipv4(dev, item, item_flags, last_item,
3060 : : ether_type, &actual_ipv4_mask,
3061 : : MLX5_ITEM_RANGE_ACCEPTED, error);
3062 [ # # ]: 0 : if (ret < 0)
3063 : : return ret;
3064 [ # # ]: 0 : if (spec && mask)
3065 : 0 : fragment_offset_spec = spec->hdr.fragment_offset &
3066 : 0 : mask->hdr.fragment_offset;
3067 [ # # ]: 0 : if (!fragment_offset_spec)
3068 : : return 0;
3069 : : /*
3070 : : * spec and mask are valid, enforce using full mask to make sure the
3071 : : * complete value is used correctly.
3072 : : */
3073 [ # # ]: 0 : if ((mask->hdr.fragment_offset & RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
3074 : : != RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
3075 : 0 : return rte_flow_error_set(error, EINVAL,
3076 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK,
3077 : : item, "must use full mask for"
3078 : : " fragment_offset");
3079 : : /*
3080 : : * Match on fragment_offset 0x2000 means MF is 1 and frag-offset is 0,
3081 : : * indicating this is 1st fragment of fragmented packet.
3082 : : * This is not yet supported in MLX5, return appropriate error message.
3083 : : */
3084 [ # # ]: 0 : if (fragment_offset_spec == RTE_BE16(RTE_IPV4_HDR_MF_FLAG))
3085 : 0 : return rte_flow_error_set(error, ENOTSUP,
3086 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3087 : : "match on first fragment not "
3088 : : "supported");
3089 [ # # ]: 0 : if (fragment_offset_spec && !last)
3090 : 0 : return rte_flow_error_set(error, ENOTSUP,
3091 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3092 : : "specified value not supported");
3093 : : /* spec and last are valid, validate the specified range. */
3094 : 0 : fragment_offset_last = last->hdr.fragment_offset &
3095 : : mask->hdr.fragment_offset;
3096 : : /*
3097 : : * Match on fragment_offset spec 0x2001 and last 0x3fff
3098 : : * means MF is 1 and frag-offset is > 0.
3099 : : * This packet is fragment 2nd and onward, excluding last.
3100 : : * This is not yet supported in MLX5, return appropriate
3101 : : * error message.
3102 : : */
3103 : 0 : if (fragment_offset_spec == RTE_BE16(RTE_IPV4_HDR_MF_FLAG + 1) &&
3104 [ # # ]: 0 : fragment_offset_last == RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK))
3105 : 0 : return rte_flow_error_set(error, ENOTSUP,
3106 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST,
3107 : : last, "match on following "
3108 : : "fragments not supported");
3109 : : /*
3110 : : * Match on fragment_offset spec 0x0001 and last 0x1fff
3111 : : * means MF is 0 and frag-offset is > 0.
3112 : : * This packet is last fragment of fragmented packet.
3113 : : * This is not yet supported in MLX5, return appropriate
3114 : : * error message.
3115 : : */
3116 : 0 : if (fragment_offset_spec == RTE_BE16(1) &&
3117 [ # # ]: 0 : fragment_offset_last == RTE_BE16(RTE_IPV4_HDR_OFFSET_MASK))
3118 : 0 : return rte_flow_error_set(error, ENOTSUP,
3119 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST,
3120 : : last, "match on last "
3121 : : "fragment not supported");
3122 : : /*
3123 : : * Match on fragment_offset spec 0x0001 and last 0x3fff
3124 : : * means MF and/or frag-offset is not 0.
3125 : : * This is a fragmented packet.
3126 : : * Other range values are invalid and rejected.
3127 : : */
3128 : 0 : if (!(fragment_offset_spec == RTE_BE16(1) &&
3129 [ # # ]: 0 : fragment_offset_last == RTE_BE16(MLX5_IPV4_FRAG_OFFSET_MASK)))
3130 : 0 : return rte_flow_error_set(error, ENOTSUP,
3131 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST, last,
3132 : : "specified range not supported");
3133 : : return 0;
3134 : : }
3135 : :
3136 : : /**
3137 : : * Validate IPV6 fragment extension item.
3138 : : *
3139 : : * @param[in] item
3140 : : * Item specification.
3141 : : * @param[in] item_flags
3142 : : * Bit-fields that holds the items detected until now.
3143 : : * @param[out] error
3144 : : * Pointer to error structure.
3145 : : *
3146 : : * @return
3147 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3148 : : */
3149 : : static int
3150 : 0 : flow_dv_validate_item_ipv6_frag_ext(const struct rte_eth_dev *dev,
3151 : : const struct rte_flow_item *item,
3152 : : uint64_t item_flags,
3153 : : struct rte_flow_error *error)
3154 : : {
3155 : 0 : const struct rte_flow_item_ipv6_frag_ext *spec = item->spec;
3156 : 0 : const struct rte_flow_item_ipv6_frag_ext *last = item->last;
3157 : 0 : const struct rte_flow_item_ipv6_frag_ext *mask = item->mask;
3158 : : rte_be16_t frag_data_spec = 0;
3159 : : rte_be16_t frag_data_last = 0;
3160 : 0 : const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
3161 [ # # ]: 0 : const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
3162 : : MLX5_FLOW_LAYER_OUTER_L4;
3163 : : int ret = 0;
3164 : 0 : struct rte_flow_item_ipv6_frag_ext nic_mask = {
3165 : : .hdr = {
3166 : : .next_header = 0xff,
3167 : : .frag_data = RTE_BE16(0xffff),
3168 : : },
3169 : : };
3170 : :
3171 [ # # ]: 0 : if (item_flags & l4m)
3172 : 0 : return rte_flow_error_set(error, EINVAL,
3173 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3174 : : "ipv6 fragment extension item cannot "
3175 : : "follow L4 item.");
3176 [ # # # # : 0 : if ((tunnel && !(item_flags & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
# # ]
3177 [ # # ]: 0 : (!tunnel && !(item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV6)))
3178 : 0 : return rte_flow_error_set(error, EINVAL,
3179 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3180 : : "ipv6 fragment extension item must "
3181 : : "follow ipv6 item");
3182 [ # # ]: 0 : if (spec && mask)
3183 : 0 : frag_data_spec = spec->hdr.frag_data & mask->hdr.frag_data;
3184 [ # # ]: 0 : if (!frag_data_spec)
3185 : : return 0;
3186 : : /*
3187 : : * spec and mask are valid, enforce using full mask to make sure the
3188 : : * complete value is used correctly.
3189 : : */
3190 [ # # ]: 0 : if ((mask->hdr.frag_data & RTE_BE16(RTE_IPV6_FRAG_USED_MASK)) !=
3191 : : RTE_BE16(RTE_IPV6_FRAG_USED_MASK))
3192 : 0 : return rte_flow_error_set(error, EINVAL,
3193 : : RTE_FLOW_ERROR_TYPE_ITEM_MASK,
3194 : : item, "must use full mask for"
3195 : : " frag_data");
3196 : : /*
3197 : : * Match on frag_data 0x00001 means M is 1 and frag-offset is 0.
3198 : : * This is 1st fragment of fragmented packet.
3199 : : */
3200 [ # # ]: 0 : if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_MF_MASK))
3201 : 0 : return rte_flow_error_set(error, ENOTSUP,
3202 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3203 : : "match on first fragment not "
3204 : : "supported");
3205 [ # # ]: 0 : if (frag_data_spec && !last)
3206 : 0 : return rte_flow_error_set(error, EINVAL,
3207 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
3208 : : "specified value not supported");
3209 : 0 : ret = mlx5_flow_item_acceptable
3210 : : (dev, item, (const uint8_t *)mask,
3211 : : (const uint8_t *)&nic_mask,
3212 : : sizeof(struct rte_flow_item_ipv6_frag_ext),
3213 : : MLX5_ITEM_RANGE_ACCEPTED, error);
3214 [ # # ]: 0 : if (ret)
3215 : : return ret;
3216 : : /* spec and last are valid, validate the specified range. */
3217 : 0 : frag_data_last = last->hdr.frag_data & mask->hdr.frag_data;
3218 : : /*
3219 : : * Match on frag_data spec 0x0009 and last 0xfff9
3220 : : * means M is 1 and frag-offset is > 0.
3221 : : * This packet is fragment 2nd and onward, excluding last.
3222 : : * This is not yet supported in MLX5, return appropriate
3223 : : * error message.
3224 : : */
3225 : 0 : if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_FO_ALIGN |
3226 : 0 : RTE_IPV6_EHDR_MF_MASK) &&
3227 [ # # ]: 0 : frag_data_last == RTE_BE16(RTE_IPV6_FRAG_USED_MASK))
3228 : 0 : return rte_flow_error_set(error, ENOTSUP,
3229 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST,
3230 : : last, "match on following "
3231 : : "fragments not supported");
3232 : : /*
3233 : : * Match on frag_data spec 0x0008 and last 0xfff8
3234 : : * means M is 0 and frag-offset is > 0.
3235 : : * This packet is last fragment of fragmented packet.
3236 : : * This is not yet supported in MLX5, return appropriate
3237 : : * error message.
3238 : : */
3239 : 0 : if (frag_data_spec == RTE_BE16(RTE_IPV6_EHDR_FO_ALIGN) &&
3240 [ # # ]: 0 : frag_data_last == RTE_BE16(RTE_IPV6_EHDR_FO_MASK))
3241 : 0 : return rte_flow_error_set(error, ENOTSUP,
3242 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST,
3243 : : last, "match on last "
3244 : : "fragment not supported");
3245 : : /* Other range values are invalid and rejected. */
3246 : 0 : return rte_flow_error_set(error, EINVAL,
3247 : : RTE_FLOW_ERROR_TYPE_ITEM_LAST, last,
3248 : : "specified range not supported");
3249 : : }
3250 : :
3251 : : /*
3252 : : * Validate ASO CT item.
3253 : : *
3254 : : * @param[in] dev
3255 : : * Pointer to the rte_eth_dev structure.
3256 : : * @param[in] item
3257 : : * Item specification.
3258 : : * @param[in] item_flags
3259 : : * Pointer to bit-fields that holds the items detected until now.
3260 : : * @param[out] error
3261 : : * Pointer to error structure.
3262 : : *
3263 : : * @return
3264 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3265 : : */
3266 : : int
3267 : 0 : mlx5_flow_dv_validate_item_aso_ct(struct rte_eth_dev *dev,
3268 : : const struct rte_flow_item *item,
3269 : : uint64_t *item_flags,
3270 : : struct rte_flow_error *error)
3271 : : {
3272 : 0 : const struct rte_flow_item_conntrack *spec = item->spec;
3273 : 0 : const struct rte_flow_item_conntrack *mask = item->mask;
3274 : : uint32_t flags;
3275 : :
3276 [ # # ]: 0 : if (*item_flags & MLX5_FLOW_LAYER_ASO_CT)
3277 : 0 : return rte_flow_error_set(error, EINVAL,
3278 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
3279 : : "Only one CT is supported");
3280 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
3281 [ # # ]: 0 : if (!mask)
3282 : : mask = &rte_flow_item_conntrack_mask;
3283 : 0 : flags = spec->flags & mask->flags;
3284 [ # # ]: 0 : if ((flags & RTE_FLOW_CONNTRACK_PKT_STATE_VALID) &&
3285 : : ((flags & RTE_FLOW_CONNTRACK_PKT_STATE_INVALID) ||
3286 [ # # ]: 0 : (flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD) ||
3287 : : (flags & RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED)))
3288 : 0 : return rte_flow_error_set(error, EINVAL,
3289 : : RTE_FLOW_ERROR_TYPE_ITEM,
3290 : : NULL,
3291 : : "Conflict status bits");
3292 : : }
3293 : : /* State change also needs to be considered. */
3294 : 0 : *item_flags |= MLX5_FLOW_LAYER_ASO_CT;
3295 : 0 : return 0;
3296 : : }
3297 : :
3298 : : /**
3299 : : * Validate the pop VLAN action.
3300 : : *
3301 : : * @param[in] dev
3302 : : * Pointer to the rte_eth_dev structure.
3303 : : * @param[in] action_flags
3304 : : * Holds the actions detected until now.
3305 : : * @param[in] action
3306 : : * Pointer to the pop vlan action.
3307 : : * @param[in] item_flags
3308 : : * The items found in this flow rule.
3309 : : * @param[in] attr
3310 : : * Pointer to flow attributes.
3311 : : * @param[out] error
3312 : : * Pointer to error structure.
3313 : : *
3314 : : * @return
3315 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3316 : : */
3317 : : static int
3318 : 0 : flow_dv_validate_action_pop_vlan(struct rte_eth_dev *dev,
3319 : : uint64_t action_flags,
3320 : : const struct rte_flow_action *action,
3321 : : uint64_t item_flags,
3322 : : const struct rte_flow_attr *attr,
3323 : : struct rte_flow_error *error)
3324 : : {
3325 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
3326 : :
3327 [ # # ]: 0 : if (!priv->sh->pop_vlan_action)
3328 : 0 : return rte_flow_error_set(error, ENOTSUP,
3329 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3330 : : NULL,
3331 : : "pop vlan action is not supported");
3332 [ # # ]: 0 : if (action_flags & MLX5_FLOW_VLAN_ACTIONS)
3333 : 0 : return rte_flow_error_set(error, ENOTSUP,
3334 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3335 : : "no support for multiple VLAN "
3336 : : "actions");
3337 : : /* Pop VLAN with preceding Decap requires inner header with VLAN. */
3338 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_DECAP) &&
3339 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_INNER_VLAN))
3340 : 0 : return rte_flow_error_set(error, ENOTSUP,
3341 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3342 : : NULL,
3343 : : "cannot pop vlan after decap without "
3344 : : "match on inner vlan in the flow");
3345 : : /* Pop VLAN without preceding Decap requires outer header with VLAN. */
3346 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_ACTION_DECAP) &&
3347 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
3348 : 0 : return rte_flow_error_set(error, ENOTSUP,
3349 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3350 : : NULL,
3351 : : "cannot pop vlan without a "
3352 : : "match on (outer) vlan in the flow");
3353 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3354 : 0 : return rte_flow_error_set(error, EINVAL,
3355 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3356 : : "wrong action order, port_id should "
3357 : : "be after pop VLAN action");
3358 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
3359 : 0 : return rte_flow_error_set(error, ENOTSUP,
3360 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3361 : : "pop vlan action for VF representor "
3362 : : "not supported on NIC table");
3363 : : return 0;
3364 : : }
3365 : :
3366 : : /**
3367 : : * Get VLAN default info from vlan match info.
3368 : : *
3369 : : * @param[in] items
3370 : : * the list of item specifications.
3371 : : * @param[out] vlan
3372 : : * pointer VLAN info to fill to.
3373 : : *
3374 : : * @return
3375 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3376 : : */
3377 : : static void
3378 : 0 : flow_dev_get_vlan_info_from_items(const struct rte_flow_item *items,
3379 : : struct rte_vlan_hdr *vlan)
3380 : : {
3381 : 0 : const struct rte_flow_item_vlan nic_mask = {
3382 : : .hdr.vlan_tci = RTE_BE16(MLX5DV_FLOW_VLAN_PCP_MASK |
3383 : : MLX5DV_FLOW_VLAN_VID_MASK),
3384 : : .hdr.eth_proto = RTE_BE16(0xffff),
3385 : : };
3386 : :
3387 [ # # ]: 0 : if (items == NULL)
3388 : 0 : return;
3389 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
3390 : 0 : int type = items->type;
3391 : :
3392 : 0 : if (type == RTE_FLOW_ITEM_TYPE_VLAN ||
3393 [ # # ]: 0 : type == MLX5_RTE_FLOW_ITEM_TYPE_VLAN)
3394 : : break;
3395 : : }
3396 [ # # ]: 0 : if (items->type != RTE_FLOW_ITEM_TYPE_END) {
3397 : 0 : const struct rte_flow_item_vlan *vlan_m = items->mask;
3398 : 0 : const struct rte_flow_item_vlan *vlan_v = items->spec;
3399 : :
3400 : : /* If VLAN item in pattern doesn't contain data, return here. */
3401 [ # # ]: 0 : if (!vlan_v)
3402 : : return;
3403 [ # # ]: 0 : if (!vlan_m)
3404 : : vlan_m = &nic_mask;
3405 : : /* Only full match values are accepted */
3406 [ # # ]: 0 : if ((vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) ==
3407 : : MLX5DV_FLOW_VLAN_PCP_MASK_BE) {
3408 : 0 : vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
3409 : 0 : vlan->vlan_tci |=
3410 [ # # ]: 0 : rte_be_to_cpu_16(vlan_v->hdr.vlan_tci &
3411 : : MLX5DV_FLOW_VLAN_PCP_MASK_BE);
3412 : : }
3413 [ # # ]: 0 : if ((vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) ==
3414 : : MLX5DV_FLOW_VLAN_VID_MASK_BE) {
3415 : 0 : vlan->vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
3416 : 0 : vlan->vlan_tci |=
3417 [ # # ]: 0 : rte_be_to_cpu_16(vlan_v->hdr.vlan_tci &
3418 : : MLX5DV_FLOW_VLAN_VID_MASK_BE);
3419 : : }
3420 [ # # ]: 0 : if (vlan_m->hdr.eth_proto == nic_mask.hdr.eth_proto)
3421 [ # # ]: 0 : vlan->eth_proto = rte_be_to_cpu_16(vlan_v->hdr.eth_proto &
3422 : : vlan_m->hdr.eth_proto);
3423 : : }
3424 : : }
3425 : :
3426 : : /**
3427 : : * Validate the push VLAN action.
3428 : : *
3429 : : * @param[in] dev
3430 : : * Pointer to the rte_eth_dev structure.
3431 : : * @param[in] action_flags
3432 : : * Holds the actions detected until now.
3433 : : * @param[in] item_flags
3434 : : * The items found in this flow rule.
3435 : : * @param[in] action
3436 : : * Pointer to the action structure.
3437 : : * @param[in] attr
3438 : : * Pointer to flow attributes
3439 : : * @param[out] error
3440 : : * Pointer to error structure.
3441 : : *
3442 : : * @return
3443 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3444 : : */
3445 : : static int
3446 : 0 : flow_dv_validate_action_push_vlan(struct rte_eth_dev *dev,
3447 : : uint64_t action_flags,
3448 : : const struct rte_flow_item_vlan *vlan_m,
3449 : : const struct rte_flow_action *action,
3450 : : const struct rte_flow_attr *attr,
3451 : : struct rte_flow_error *error)
3452 : : {
3453 : 0 : const struct rte_flow_action_of_push_vlan *push_vlan = action->conf;
3454 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
3455 : :
3456 [ # # ]: 0 : if (push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_VLAN) &&
3457 : : push_vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_QINQ))
3458 : 0 : return rte_flow_error_set(error, EINVAL,
3459 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3460 : : "invalid vlan ethertype");
3461 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3462 : 0 : return rte_flow_error_set(error, EINVAL,
3463 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3464 : : "wrong action order, port_id should "
3465 : : "be after push VLAN");
3466 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
3467 : 0 : return rte_flow_error_set(error, ENOTSUP,
3468 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3469 : : "push vlan action for VF representor "
3470 : : "not supported on NIC table");
3471 [ # # ]: 0 : if (vlan_m &&
3472 [ # # # # ]: 0 : (vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) &&
3473 : : (vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_PCP_MASK_BE) !=
3474 : 0 : MLX5DV_FLOW_VLAN_PCP_MASK_BE &&
3475 [ # # # # ]: 0 : !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP) &&
3476 : 0 : !(mlx5_flow_find_action
3477 : : (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP)))
3478 : 0 : return rte_flow_error_set(error, EINVAL,
3479 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3480 : : "not full match mask on VLAN PCP and "
3481 : : "there is no of_set_vlan_pcp action, "
3482 : : "push VLAN action cannot figure out "
3483 : : "PCP value");
3484 [ # # ]: 0 : if (vlan_m &&
3485 [ # # # # ]: 0 : (vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) &&
3486 : : (vlan_m->hdr.vlan_tci & MLX5DV_FLOW_VLAN_VID_MASK_BE) !=
3487 : 0 : MLX5DV_FLOW_VLAN_VID_MASK_BE &&
3488 [ # # # # ]: 0 : !(action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID) &&
3489 : 0 : !(mlx5_flow_find_action
3490 : : (action + 1, RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID)))
3491 : 0 : return rte_flow_error_set(error, EINVAL,
3492 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3493 : : "not full match mask on VLAN VID and "
3494 : : "there is no of_set_vlan_vid action, "
3495 : : "push VLAN action cannot figure out "
3496 : : "VID value");
3497 : : (void)attr;
3498 : : return 0;
3499 : : }
3500 : :
3501 : : /**
3502 : : * Validate the set VLAN PCP.
3503 : : *
3504 : : * @param[in] action_flags
3505 : : * Holds the actions detected until now.
3506 : : * @param[in] actions
3507 : : * Pointer to the list of actions remaining in the flow rule.
3508 : : * @param[out] error
3509 : : * Pointer to error structure.
3510 : : *
3511 : : * @return
3512 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3513 : : */
3514 : : static int
3515 : 0 : flow_dv_validate_action_set_vlan_pcp(uint64_t action_flags,
3516 : : const struct rte_flow_action actions[],
3517 : : struct rte_flow_error *error)
3518 : : {
3519 : : const struct rte_flow_action *action = actions;
3520 : 0 : const struct rte_flow_action_of_set_vlan_pcp *conf = action->conf;
3521 : :
3522 [ # # ]: 0 : if (conf->vlan_pcp > 7)
3523 : 0 : return rte_flow_error_set(error, EINVAL,
3524 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3525 : : "VLAN PCP value is too big");
3526 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN))
3527 : 0 : return rte_flow_error_set(error, ENOTSUP,
3528 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3529 : : "set VLAN PCP action must follow "
3530 : : "the push VLAN action");
3531 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_PCP)
3532 : 0 : return rte_flow_error_set(error, ENOTSUP,
3533 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3534 : : "Multiple VLAN PCP modification are "
3535 : : "not supported");
3536 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3537 : 0 : return rte_flow_error_set(error, EINVAL,
3538 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3539 : : "wrong action order, port_id should "
3540 : : "be after set VLAN PCP");
3541 : : return 0;
3542 : : }
3543 : :
3544 : : /**
3545 : : * Validate the set VLAN VID.
3546 : : *
3547 : : * @param[in] item_flags
3548 : : * Holds the items detected in this rule.
3549 : : * @param[in] action_flags
3550 : : * Holds the actions detected until now.
3551 : : * @param[in] actions
3552 : : * Pointer to the list of actions remaining in the flow rule.
3553 : : * @param[out] error
3554 : : * Pointer to error structure.
3555 : : *
3556 : : * @return
3557 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3558 : : */
3559 : : static int
3560 : 0 : flow_dv_validate_action_set_vlan_vid(uint64_t item_flags,
3561 : : uint64_t action_flags,
3562 : : const struct rte_flow_action actions[],
3563 : : struct rte_flow_error *error)
3564 : : {
3565 : : const struct rte_flow_action *action = actions;
3566 : 0 : const struct rte_flow_action_of_set_vlan_vid *conf = action->conf;
3567 : :
3568 [ # # # # ]: 0 : if (rte_be_to_cpu_16(conf->vlan_vid) > 0xFFE)
3569 : 0 : return rte_flow_error_set(error, EINVAL,
3570 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3571 : : "VLAN VID value is too big");
3572 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) &&
3573 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN))
3574 : 0 : return rte_flow_error_set(error, ENOTSUP,
3575 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3576 : : "set VLAN VID action must follow push"
3577 : : " VLAN action or match on VLAN item");
3578 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_SET_VLAN_VID)
3579 : 0 : return rte_flow_error_set(error, ENOTSUP,
3580 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3581 : : "Multiple VLAN VID modifications are "
3582 : : "not supported");
3583 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_PORT_ID)
3584 : 0 : return rte_flow_error_set(error, EINVAL,
3585 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3586 : : "wrong action order, port_id should "
3587 : : "be after set VLAN VID");
3588 : : return 0;
3589 : : }
3590 : :
3591 : : /*
3592 : : * Validate the FLAG action.
3593 : : *
3594 : : * @param[in] dev
3595 : : * Pointer to the rte_eth_dev structure.
3596 : : * @param[in] action_flags
3597 : : * Holds the actions detected until now.
3598 : : * @param[in] attr
3599 : : * Pointer to flow attributes
3600 : : * @param[out] error
3601 : : * Pointer to error structure.
3602 : : *
3603 : : * @return
3604 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3605 : : */
3606 : : static int
3607 : 0 : flow_dv_validate_action_flag(struct rte_eth_dev *dev,
3608 : : uint64_t action_flags,
3609 : : const struct rte_flow_attr *attr,
3610 : : struct rte_flow_error *error)
3611 : : {
3612 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3613 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
3614 : : int ret;
3615 : :
3616 : : /* Fall back if no extended metadata register support. */
3617 [ # # ]: 0 : if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
3618 : 0 : return mlx5_flow_validate_action_flag(action_flags, attr,
3619 : : error);
3620 : : /* Extensive metadata mode requires registers. */
3621 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
3622 : 0 : return rte_flow_error_set(error, ENOTSUP,
3623 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3624 : : "no metadata registers "
3625 : : "to support flag action");
3626 [ # # ]: 0 : if (!(priv->sh->dv_mark_mask & MLX5_FLOW_MARK_DEFAULT))
3627 : 0 : return rte_flow_error_set(error, ENOTSUP,
3628 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3629 : : "extended metadata register"
3630 : : " isn't available");
3631 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3632 [ # # ]: 0 : if (ret < 0)
3633 : : return ret;
3634 : : MLX5_ASSERT(ret > 0);
3635 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
3636 : 0 : return rte_flow_error_set(error, EINVAL,
3637 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3638 : : "can't mark and flag in same flow");
3639 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_FLAG)
3640 : 0 : return rte_flow_error_set(error, EINVAL,
3641 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3642 : : "can't have 2 flag"
3643 : : " actions in same flow");
3644 : : return 0;
3645 : : }
3646 : :
3647 : : /**
3648 : : * Validate MARK action.
3649 : : *
3650 : : * @param[in] dev
3651 : : * Pointer to the rte_eth_dev structure.
3652 : : * @param[in] action
3653 : : * Pointer to action.
3654 : : * @param[in] action_flags
3655 : : * Holds the actions detected until now.
3656 : : * @param[in] attr
3657 : : * Pointer to flow attributes
3658 : : * @param[out] error
3659 : : * Pointer to error structure.
3660 : : *
3661 : : * @return
3662 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3663 : : */
3664 : : static int
3665 : 0 : flow_dv_validate_action_mark(struct rte_eth_dev *dev,
3666 : : const struct rte_flow_action *action,
3667 : : uint64_t action_flags,
3668 : : const struct rte_flow_attr *attr,
3669 : : struct rte_flow_error *error)
3670 : : {
3671 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3672 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
3673 [ # # ]: 0 : const struct rte_flow_action_mark *mark = action->conf;
3674 : : int ret;
3675 : :
3676 [ # # ]: 0 : if (is_tunnel_offload_active(dev))
3677 : 0 : return rte_flow_error_set(error, ENOTSUP,
3678 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3679 : : "no mark action "
3680 : : "if tunnel offload active");
3681 : : /* Fall back if no extended metadata register support. */
3682 [ # # ]: 0 : if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY)
3683 : 0 : return mlx5_flow_validate_action_mark(dev, action, action_flags,
3684 : : attr, error);
3685 : : /* Extensive metadata mode requires registers. */
3686 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
3687 : 0 : return rte_flow_error_set(error, ENOTSUP,
3688 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3689 : : "no metadata registers "
3690 : : "to support mark action");
3691 [ # # ]: 0 : if (!priv->sh->dv_mark_mask)
3692 : 0 : return rte_flow_error_set(error, ENOTSUP,
3693 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3694 : : "extended metadata register"
3695 : : " isn't available");
3696 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
3697 [ # # ]: 0 : if (ret < 0)
3698 : : return ret;
3699 : : MLX5_ASSERT(ret > 0);
3700 [ # # ]: 0 : if (!mark)
3701 : 0 : return rte_flow_error_set(error, EINVAL,
3702 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3703 : : "configuration cannot be null");
3704 [ # # ]: 0 : if (mark->id >= (MLX5_FLOW_MARK_MAX & priv->sh->dv_mark_mask))
3705 : 0 : return rte_flow_error_set(error, EINVAL,
3706 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
3707 : 0 : &mark->id,
3708 : : "mark id exceeds the limit");
3709 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_FLAG)
3710 : 0 : return rte_flow_error_set(error, EINVAL,
3711 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3712 : : "can't flag and mark in same flow");
3713 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
3714 : 0 : return rte_flow_error_set(error, EINVAL,
3715 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3716 : : "can't have 2 mark actions in same"
3717 : : " flow");
3718 : : return 0;
3719 : : }
3720 : :
3721 : : /**
3722 : : * Validate SET_META action.
3723 : : *
3724 : : * @param[in] dev
3725 : : * Pointer to the rte_eth_dev structure.
3726 : : * @param[in] action
3727 : : * Pointer to the action structure.
3728 : : * @param[in] action_flags
3729 : : * Holds the actions detected until now.
3730 : : * @param[in] attr
3731 : : * Pointer to flow attributes
3732 : : * @param[out] error
3733 : : * Pointer to error structure.
3734 : : *
3735 : : * @return
3736 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3737 : : */
3738 : : static int
3739 : 0 : flow_dv_validate_action_set_meta(struct rte_eth_dev *dev,
3740 : : const struct rte_flow_action *action,
3741 : : uint64_t action_flags __rte_unused,
3742 : : const struct rte_flow_attr *attr,
3743 : : struct rte_flow_error *error)
3744 : : {
3745 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3746 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
3747 : : const struct rte_flow_action_set_meta *conf;
3748 : : uint32_t nic_mask = UINT32_MAX;
3749 : : int reg;
3750 : :
3751 [ # # # # ]: 0 : if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
3752 : 0 : !mlx5_flow_ext_mreg_supported(dev))
3753 : 0 : return rte_flow_error_set(error, ENOTSUP,
3754 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3755 : : "extended metadata register"
3756 : : " isn't supported");
3757 : 0 : reg = flow_dv_get_metadata_reg(dev, attr, error);
3758 [ # # ]: 0 : if (reg < 0)
3759 : : return reg;
3760 [ # # ]: 0 : if (reg == REG_NON)
3761 : 0 : return rte_flow_error_set(error, ENOTSUP,
3762 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3763 : : "unavailable extended metadata register");
3764 [ # # ]: 0 : if (reg != REG_A && reg != REG_B) {
3765 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3766 : :
3767 : 0 : nic_mask = priv->sh->dv_meta_mask;
3768 : : }
3769 [ # # ]: 0 : if (!(action->conf))
3770 : 0 : return rte_flow_error_set(error, EINVAL,
3771 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3772 : : "configuration cannot be null");
3773 : : conf = (const struct rte_flow_action_set_meta *)action->conf;
3774 [ # # ]: 0 : if (!conf->mask)
3775 : 0 : return rte_flow_error_set(error, EINVAL,
3776 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3777 : : "zero mask doesn't have any effect");
3778 [ # # ]: 0 : if (conf->mask & ~nic_mask)
3779 : 0 : return rte_flow_error_set(error, EINVAL,
3780 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3781 : : "meta data must be within reg C0");
3782 : : return 0;
3783 : : }
3784 : :
3785 : : /**
3786 : : * Validate SET_TAG action.
3787 : : *
3788 : : * @param[in] dev
3789 : : * Pointer to the rte_eth_dev structure.
3790 : : * @param[in] action
3791 : : * Pointer to the action structure.
3792 : : * @param[in] action_flags
3793 : : * Holds the actions detected until now.
3794 : : * @param[in] attr
3795 : : * Pointer to flow attributes
3796 : : * @param[out] error
3797 : : * Pointer to error structure.
3798 : : *
3799 : : * @return
3800 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3801 : : */
3802 : : static int
3803 : 0 : flow_dv_validate_action_set_tag(struct rte_eth_dev *dev,
3804 : : const struct rte_flow_action *action,
3805 : : uint64_t action_flags,
3806 : : const struct rte_flow_attr *attr,
3807 : : struct rte_flow_error *error)
3808 : : {
3809 : : const struct rte_flow_action_set_tag *conf;
3810 : : const uint64_t terminal_action_flags =
3811 : : MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE |
3812 : : MLX5_FLOW_ACTION_RSS;
3813 : : int ret;
3814 : :
3815 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev))
3816 : 0 : return rte_flow_error_set(error, ENOTSUP,
3817 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3818 : : "extensive metadata register"
3819 : : " isn't supported");
3820 [ # # ]: 0 : if (!(action->conf))
3821 : 0 : return rte_flow_error_set(error, EINVAL,
3822 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3823 : : "configuration cannot be null");
3824 : : conf = (const struct rte_flow_action_set_tag *)action->conf;
3825 [ # # ]: 0 : if (!conf->mask)
3826 : 0 : return rte_flow_error_set(error, EINVAL,
3827 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3828 : : "zero mask doesn't have any effect");
3829 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, conf->index, error);
3830 [ # # ]: 0 : if (ret < 0)
3831 : : return ret;
3832 [ # # # # ]: 0 : if (attr->ingress && (action_flags & terminal_action_flags))
3833 : 0 : return rte_flow_error_set(error, EINVAL,
3834 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3835 : : "set_tag has no effect"
3836 : : " with terminal actions");
3837 : : return 0;
3838 : : }
3839 : :
3840 : : /**
3841 : : * Indicates whether ASO aging is supported.
3842 : : *
3843 : : * @param[in] priv
3844 : : * Pointer to device private context structure.
3845 : : * @param[in] root
3846 : : * Whether action is on root table.
3847 : : *
3848 : : * @return
3849 : : * True when ASO aging is supported, false otherwise.
3850 : : */
3851 : : static inline bool
3852 : : flow_hit_aso_supported(const struct mlx5_priv *priv, bool root)
3853 : : {
3854 : : MLX5_ASSERT(priv);
3855 [ # # # # : 0 : return (priv->sh->flow_hit_aso_en && !root);
# # # # #
# ]
3856 : : }
3857 : :
3858 : : /**
3859 : : * Validate count action.
3860 : : *
3861 : : * @param[in] dev
3862 : : * Pointer to rte_eth_dev structure.
3863 : : * @param[in] shared
3864 : : * Indicator if action is shared.
3865 : : * @param[in] action_flags
3866 : : * Holds the actions detected until now.
3867 : : * @param[in] root
3868 : : * Whether action is on root table.
3869 : : * @param[out] error
3870 : : * Pointer to error structure.
3871 : : *
3872 : : * @return
3873 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3874 : : */
3875 : : static int
3876 : 0 : flow_dv_validate_action_count(struct rte_eth_dev *dev, bool shared,
3877 : : uint64_t action_flags,
3878 : : bool root,
3879 : : struct rte_flow_error *error)
3880 : : {
3881 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3882 : :
3883 [ # # ]: 0 : if (!priv->sh->cdev->config.devx)
3884 : 0 : goto notsup_err;
3885 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_COUNT)
3886 : 0 : return rte_flow_error_set(error, EINVAL,
3887 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3888 : : "duplicate count actions set");
3889 [ # # # # : 0 : if (shared && (action_flags & MLX5_FLOW_ACTION_AGE) &&
# # ]
3890 : : !flow_hit_aso_supported(priv, root))
3891 : 0 : return rte_flow_error_set(error, EINVAL,
3892 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3893 : : "old age and indirect count combination is not supported");
3894 : : #ifdef HAVE_IBV_FLOW_DEVX_COUNTERS
3895 : : return 0;
3896 : : #endif
3897 : : notsup_err:
3898 : 0 : return rte_flow_error_set
3899 : : (error, ENOTSUP,
3900 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3901 : : NULL,
3902 : : "count action not supported");
3903 : : }
3904 : :
3905 : : /**
3906 : : * Validate the L2 encap action.
3907 : : *
3908 : : * @param[in] dev
3909 : : * Pointer to the rte_eth_dev structure.
3910 : : * @param[in] action_flags
3911 : : * Holds the actions detected until now.
3912 : : * @param[in] action
3913 : : * Pointer to the action structure.
3914 : : * @param[in] attr
3915 : : * Pointer to flow attributes.
3916 : : * @param[out] error
3917 : : * Pointer to error structure.
3918 : : *
3919 : : * @return
3920 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3921 : : */
3922 : : int
3923 : 0 : mlx5_flow_dv_validate_action_l2_encap(struct rte_eth_dev *dev,
3924 : : uint64_t action_flags,
3925 : : const struct rte_flow_action *action,
3926 : : const struct rte_flow_attr *attr,
3927 : : struct rte_flow_error *error)
3928 : : {
3929 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
3930 : :
3931 [ # # ]: 0 : if (!(action->conf))
3932 : 0 : return rte_flow_error_set(error, EINVAL,
3933 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
3934 : : "configuration cannot be null");
3935 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
3936 : 0 : return rte_flow_error_set(error, EINVAL,
3937 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3938 : : "can only have a single encap action "
3939 : : "in a flow");
3940 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
3941 : 0 : return rte_flow_error_set(error, ENOTSUP,
3942 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3943 : : "encap action for VF representor "
3944 : : "not supported on NIC table");
3945 : : return 0;
3946 : : }
3947 : :
3948 : : /**
3949 : : * Validate a decap action.
3950 : : *
3951 : : * @param[in] dev
3952 : : * Pointer to the rte_eth_dev structure.
3953 : : * @param[in] action_flags
3954 : : * Holds the actions detected until now.
3955 : : * @param[in] action
3956 : : * Pointer to the action structure.
3957 : : * @param[in] item_flags
3958 : : * Holds the items detected.
3959 : : * @param[in] attr
3960 : : * Pointer to flow attributes
3961 : : * @param[out] error
3962 : : * Pointer to error structure.
3963 : : *
3964 : : * @return
3965 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3966 : : */
3967 : : int
3968 : 0 : mlx5_flow_dv_validate_action_decap(struct rte_eth_dev *dev,
3969 : : uint64_t action_flags,
3970 : : const struct rte_flow_action *action,
3971 : : const uint64_t item_flags,
3972 : : const struct rte_flow_attr *attr,
3973 : : struct rte_flow_error *error)
3974 : : {
3975 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
3976 : :
3977 [ # # ]: 0 : if (priv->sh->cdev->config.hca_attr.scatter_fcs_w_decap_disable &&
3978 [ # # ]: 0 : !priv->sh->config.decap_en)
3979 : 0 : return rte_flow_error_set(error, ENOTSUP,
3980 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3981 : : "decap is not enabled");
3982 [ # # ]: 0 : if (action_flags & MLX5_FLOW_XCAP_ACTIONS)
3983 : 0 : return rte_flow_error_set(error, ENOTSUP,
3984 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3985 [ # # ]: 0 : action_flags &
3986 : : MLX5_FLOW_ACTION_DECAP ? "can only "
3987 : : "have a single decap action" : "decap "
3988 : : "after encap is not supported");
3989 [ # # ]: 0 : if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
3990 : 0 : return rte_flow_error_set(error, EINVAL,
3991 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3992 : : "can't have decap action after"
3993 : : " modify action");
3994 [ # # ]: 0 : if (attr->egress)
3995 : 0 : return rte_flow_error_set(error, ENOTSUP,
3996 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
3997 : : NULL,
3998 : : "decap action not supported for "
3999 : : "egress");
4000 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
4001 : 0 : return rte_flow_error_set(error, ENOTSUP,
4002 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4003 : : "decap action for VF representor "
4004 : : "not supported on NIC table");
4005 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_DECAP &&
4006 [ # # ]: 0 : !(item_flags & MLX5_FLOW_LAYER_VXLAN))
4007 : 0 : return rte_flow_error_set(error, ENOTSUP,
4008 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4009 : : "VXLAN item should be present for VXLAN decap");
4010 : : return 0;
4011 : : }
4012 : :
4013 : : const struct rte_flow_action_raw_decap empty_decap = {.data = NULL, .size = 0,};
4014 : :
4015 : : /**
4016 : : * Validate the raw encap and decap actions.
4017 : : *
4018 : : * @param[in] dev
4019 : : * Pointer to the rte_eth_dev structure.
4020 : : * @param[in] decap
4021 : : * Pointer to the decap action.
4022 : : * @param[in] encap
4023 : : * Pointer to the encap action.
4024 : : * @param[in] attr
4025 : : * Pointer to flow attributes
4026 : : * @param[in/out] action_flags
4027 : : * Holds the actions detected until now.
4028 : : * @param[out] actions_n
4029 : : * pointer to the number of actions counter.
4030 : : * @param[in] action
4031 : : * Pointer to the action structure.
4032 : : * @param[in] item_flags
4033 : : * Holds the items detected.
4034 : : * @param[out] error
4035 : : * Pointer to error structure.
4036 : : *
4037 : : * @return
4038 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4039 : : */
4040 : : int
4041 : 0 : mlx5_flow_dv_validate_action_raw_encap_decap
4042 : : (struct rte_eth_dev *dev,
4043 : : const struct rte_flow_action_raw_decap *decap,
4044 : : const struct rte_flow_action_raw_encap *encap,
4045 : : const struct rte_flow_attr *attr, uint64_t *action_flags,
4046 : : int *actions_n, const struct rte_flow_action *action,
4047 : : uint64_t item_flags, struct rte_flow_error *error)
4048 : : {
4049 : 0 : const struct mlx5_priv *priv = dev->data->dev_private;
4050 : : int ret;
4051 : :
4052 [ # # ]: 0 : if (encap) {
4053 [ # # ]: 0 : if (!mlx5_hws_active(dev)) {
4054 [ # # # # ]: 0 : if (!encap->size || !encap->data)
4055 : 0 : return rte_flow_error_set
4056 : : (error, EINVAL,
4057 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL, "raw encap data cannot be empty");
4058 : : } else {
4059 [ # # ]: 0 : if (!encap->size)
4060 : 0 : return rte_flow_error_set
4061 : : (error, EINVAL,
4062 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL, "raw encap size cannot be 0");
4063 : : }
4064 : : }
4065 [ # # ]: 0 : if (decap && encap) {
4066 [ # # ]: 0 : if (decap->size <= MLX5_ENCAPSULATION_DECISION_SIZE &&
4067 [ # # ]: 0 : encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
4068 : : /* L3 encap. */
4069 : : decap = NULL;
4070 [ # # ]: 0 : else if (encap->size <=
4071 [ # # ]: 0 : MLX5_ENCAPSULATION_DECISION_SIZE &&
4072 : : decap->size >
4073 : : MLX5_ENCAPSULATION_DECISION_SIZE)
4074 : : /* L3 decap. */
4075 : : encap = NULL;
4076 [ # # ]: 0 : else if (encap->size >
4077 [ # # ]: 0 : MLX5_ENCAPSULATION_DECISION_SIZE &&
4078 : : decap->size >
4079 : : MLX5_ENCAPSULATION_DECISION_SIZE)
4080 : : /* 2 L2 actions: encap and decap. */
4081 : : ;
4082 : : else
4083 : 0 : return rte_flow_error_set(error,
4084 : : ENOTSUP,
4085 : : RTE_FLOW_ERROR_TYPE_ACTION,
4086 : : NULL, "unsupported too small "
4087 : : "raw decap and too small raw "
4088 : : "encap combination");
4089 : : }
4090 [ # # ]: 0 : if (decap) {
4091 : 0 : ret = mlx5_flow_dv_validate_action_decap(dev, *action_flags,
4092 : : action,
4093 : : item_flags, attr,
4094 : : error);
4095 [ # # ]: 0 : if (ret < 0)
4096 : : return ret;
4097 : 0 : *action_flags |= MLX5_FLOW_ACTION_DECAP;
4098 : 0 : ++(*actions_n);
4099 : : }
4100 [ # # ]: 0 : if (encap) {
4101 [ # # ]: 0 : if (encap->size <= MLX5_ENCAPSULATION_DECISION_SIZE)
4102 : 0 : return rte_flow_error_set(error, ENOTSUP,
4103 : : RTE_FLOW_ERROR_TYPE_ACTION,
4104 : : NULL,
4105 : : "small raw encap size");
4106 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_ENCAP)
4107 : 0 : return rte_flow_error_set(error, EINVAL,
4108 : : RTE_FLOW_ERROR_TYPE_ACTION,
4109 : : NULL,
4110 : : "more than one encap action");
4111 [ # # # # ]: 0 : if (!attr->transfer && priv->representor)
4112 : 0 : return rte_flow_error_set
4113 : : (error, ENOTSUP,
4114 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4115 : : "encap action for VF representor "
4116 : : "not supported on NIC table");
4117 : 0 : *action_flags |= MLX5_FLOW_ACTION_ENCAP;
4118 : 0 : ++(*actions_n);
4119 : : }
4120 : : return 0;
4121 : : }
4122 : :
4123 : : /*
4124 : : * Validate the ASO CT action.
4125 : : *
4126 : : * @param[in] dev
4127 : : * Pointer to the rte_eth_dev structure.
4128 : : * @param[in] action_flags
4129 : : * Holds the actions detected until now.
4130 : : * @param[in] item_flags
4131 : : * The items found in this flow rule.
4132 : : * @param root
4133 : : * Whether action is on root table.
4134 : : * @param[out] error
4135 : : * Pointer to error structure.
4136 : : *
4137 : : * @return
4138 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4139 : : */
4140 : : int
4141 : 0 : mlx5_flow_dv_validate_action_aso_ct(struct rte_eth_dev *dev,
4142 : : uint64_t action_flags,
4143 : : uint64_t item_flags,
4144 : : bool root,
4145 : : struct rte_flow_error *error)
4146 : : {
4147 : : RTE_SET_USED(dev);
4148 : :
4149 [ # # ]: 0 : if (root)
4150 : 0 : return rte_flow_error_set(error, ENOTSUP,
4151 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4152 : : NULL,
4153 : : "Only support non-root table");
4154 [ # # ]: 0 : if (action_flags & MLX5_FLOW_FATE_ACTIONS)
4155 : 0 : return rte_flow_error_set(error, ENOTSUP,
4156 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4157 : : "CT cannot follow a fate action");
4158 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_METER) ||
4159 : : (action_flags & MLX5_FLOW_ACTION_AGE)) {
4160 [ # # ]: 0 : if (!mlx5_hws_active(dev))
4161 : 0 : return rte_flow_error_set(error, EINVAL,
4162 : : RTE_FLOW_ERROR_TYPE_ACTION,
4163 : : NULL, "Only one ASO action is supported");
4164 : : }
4165 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
4166 : 0 : return rte_flow_error_set(error, EINVAL,
4167 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4168 : : "Encap cannot exist before CT");
4169 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP))
4170 : 0 : return rte_flow_error_set(error, EINVAL,
4171 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4172 : : "Not a outer TCP packet");
4173 : : return 0;
4174 : : }
4175 : :
4176 : : /**
4177 : : * Validate METER_COLOR item.
4178 : : *
4179 : : * @param[in] dev
4180 : : * Pointer to the rte_eth_dev structure.
4181 : : * @param[in] item
4182 : : * Item specification.
4183 : : * @param[in] attr
4184 : : * Attributes of flow that includes this item.
4185 : : * @param[out] error
4186 : : * Pointer to error structure.
4187 : : *
4188 : : * @return
4189 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4190 : : */
4191 : : static int
4192 : 0 : flow_dv_validate_item_meter_color(struct rte_eth_dev *dev,
4193 : : const struct rte_flow_item *item,
4194 : : const struct rte_flow_attr *attr __rte_unused,
4195 : : struct rte_flow_error *error)
4196 : : {
4197 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4198 : 0 : const struct rte_flow_item_meter_color *spec = item->spec;
4199 : 0 : const struct rte_flow_item_meter_color *mask = item->mask;
4200 : 0 : struct rte_flow_item_meter_color nic_mask = {
4201 : : .color = RTE_COLORS
4202 : : };
4203 : : int ret;
4204 : :
4205 [ # # ]: 0 : if (priv->sh->registers.aso_reg == REG_NON)
4206 : 0 : return rte_flow_error_set(error, ENOTSUP,
4207 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
4208 : : "meter color register"
4209 : : " isn't available");
4210 : 0 : ret = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, error);
4211 [ # # ]: 0 : if (ret < 0)
4212 : : return ret;
4213 [ # # ]: 0 : if (!spec)
4214 : 0 : return rte_flow_error_set(error, EINVAL,
4215 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4216 : 0 : item->spec,
4217 : : "data cannot be empty");
4218 [ # # ]: 0 : if (spec->color > RTE_COLORS)
4219 : 0 : return rte_flow_error_set(error, EINVAL,
4220 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
4221 : 0 : &spec->color,
4222 : : "meter color is invalid");
4223 [ # # ]: 0 : if (!mask)
4224 : : mask = &rte_flow_item_meter_color_mask;
4225 [ # # ]: 0 : if (!mask->color)
4226 : 0 : return rte_flow_error_set(error, EINVAL,
4227 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
4228 : : "mask cannot be zero");
4229 : :
4230 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
4231 : : (const uint8_t *)&nic_mask,
4232 : : sizeof(struct rte_flow_item_meter_color),
4233 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
4234 : : if (ret < 0)
4235 : : return ret;
4236 : : return 0;
4237 : : }
4238 : :
4239 : : /**
4240 : : * Validate aggregated affinity item.
4241 : : *
4242 : : * @param[in] dev
4243 : : * Pointer to the rte_eth_dev structure.
4244 : : * @param[in] item
4245 : : * Item specification.
4246 : : * @param[in] attr
4247 : : * Attributes of flow that includes this item.
4248 : : * @param[out] error
4249 : : * Pointer to error structure.
4250 : : *
4251 : : * @return
4252 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4253 : : */
4254 : : static int
4255 : 0 : flow_dv_validate_item_aggr_affinity(struct rte_eth_dev *dev,
4256 : : const struct rte_flow_item *item,
4257 : : const struct rte_flow_attr *attr,
4258 : : struct rte_flow_error *error)
4259 : : {
4260 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4261 : 0 : const struct rte_flow_item_aggr_affinity *spec = item->spec;
4262 : 0 : const struct rte_flow_item_aggr_affinity *mask = item->mask;
4263 : 0 : struct rte_flow_item_aggr_affinity nic_mask = {
4264 : : .affinity = UINT8_MAX
4265 : : };
4266 : : int ret;
4267 : :
4268 [ # # ]: 0 : if (!priv->sh->lag_rx_port_affinity_en)
4269 : 0 : return rte_flow_error_set(error, EINVAL,
4270 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
4271 : : "Unsupported aggregated affinity with Older FW");
4272 [ # # # # : 0 : if ((attr->transfer && priv->fdb_def_rule) ||
# # ]
4273 [ # # ]: 0 : attr->egress || attr->group)
4274 : 0 : return rte_flow_error_set(error, ENOTSUP,
4275 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4276 : : item->spec,
4277 : : "aggregated affinity is not supported with egress or FDB on non root table");
4278 [ # # ]: 0 : if (!spec)
4279 : 0 : return rte_flow_error_set(error, EINVAL,
4280 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4281 : : item->spec,
4282 : : "data cannot be empty");
4283 [ # # ]: 0 : if (spec->affinity == 0)
4284 : 0 : return rte_flow_error_set(error, ENOTSUP,
4285 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4286 : : item->spec,
4287 : : "zero affinity number not supported");
4288 [ # # ]: 0 : if (spec->affinity > priv->num_lag_ports)
4289 : 0 : return rte_flow_error_set(error, ENOTSUP,
4290 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
4291 : : item->spec,
4292 : : "exceed max affinity number in lag ports");
4293 [ # # ]: 0 : if (!mask)
4294 : : mask = &rte_flow_item_aggr_affinity_mask;
4295 [ # # ]: 0 : if (!mask->affinity)
4296 : 0 : return rte_flow_error_set(error, EINVAL,
4297 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
4298 : : "mask cannot be zero");
4299 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
4300 : : (const uint8_t *)&nic_mask,
4301 : : sizeof(struct rte_flow_item_aggr_affinity),
4302 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
4303 : : if (ret < 0)
4304 : : return ret;
4305 : : return 0;
4306 : : }
4307 : :
4308 : : int
4309 : 0 : flow_encap_decap_match_cb(void *tool_ctx __rte_unused,
4310 : : struct mlx5_list_entry *entry, void *cb_ctx)
4311 : : {
4312 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4313 : 0 : struct mlx5_flow_dv_encap_decap_resource *ctx_resource = ctx->data;
4314 : : struct mlx5_flow_dv_encap_decap_resource *resource;
4315 : :
4316 : : resource = container_of(entry, struct mlx5_flow_dv_encap_decap_resource,
4317 : : entry);
4318 [ # # ]: 0 : if (resource->reformat_type == ctx_resource->reformat_type &&
4319 : 0 : resource->ft_type == ctx_resource->ft_type &&
4320 [ # # ]: 0 : resource->flags == ctx_resource->flags &&
4321 [ # # ]: 0 : resource->size == ctx_resource->size &&
4322 : 0 : !memcmp((const void *)resource->buf,
4323 [ # # ]: 0 : (const void *)ctx_resource->buf,
4324 : : resource->size))
4325 : 0 : return 0;
4326 : : return -1;
4327 : : }
4328 : :
4329 : : struct mlx5_list_entry *
4330 : 0 : flow_encap_decap_create_cb(void *tool_ctx, void *cb_ctx)
4331 : : {
4332 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4333 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4334 : : struct mlx5dv_dr_domain *domain;
4335 : 0 : struct mlx5_flow_dv_encap_decap_resource *ctx_resource = ctx->data;
4336 : : struct mlx5_flow_dv_encap_decap_resource *resource;
4337 : : uint32_t idx;
4338 : : int ret = 0;
4339 : : #ifdef HAVE_MLX5_HWS_SUPPORT
4340 : : struct mlx5dr_action_reformat_header hdr;
4341 : : #endif
4342 : :
4343 : : /* Register new encap/decap resource. */
4344 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], &idx);
4345 [ # # ]: 0 : if (!resource) {
4346 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4347 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4348 : : "cannot allocate resource memory");
4349 : 0 : return NULL;
4350 : : }
4351 : 0 : *resource = *ctx_resource;
4352 [ # # ]: 0 : if (sh->config.dv_flow_en == 2) {
4353 : : #ifdef HAVE_MLX5_HWS_SUPPORT
4354 : 0 : hdr.sz = ctx_resource->size;
4355 : 0 : hdr.data = ctx_resource->buf;
4356 : 0 : resource->action = mlx5dr_action_create_reformat
4357 : 0 : (ctx->data2, (enum mlx5dr_action_type)ctx_resource->reformat_type, 1,
4358 : 0 : &hdr, 0, ctx_resource->flags);
4359 [ # # ]: 0 : if (!resource->action)
4360 : : ret = -1;
4361 : : #else
4362 : : ret = -1;
4363 : : #endif
4364 : : } else {
4365 [ # # ]: 0 : if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
4366 : 0 : domain = sh->fdb_domain;
4367 [ # # ]: 0 : else if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
4368 : 0 : domain = sh->rx_domain;
4369 : : else
4370 : 0 : domain = sh->tx_domain;
4371 [ # # ]: 0 : ret = mlx5_flow_os_create_flow_action_packet_reformat(sh->cdev->ctx,
4372 : : domain, resource,
4373 : : &resource->action);
4374 : : }
4375 : : if (ret) {
4376 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], idx);
4377 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4378 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4379 : : NULL, "cannot create action");
4380 : 0 : return NULL;
4381 : : }
4382 : 0 : resource->idx = idx;
4383 : 0 : return &resource->entry;
4384 : : }
4385 : :
4386 : : struct mlx5_list_entry *
4387 : 0 : flow_encap_decap_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
4388 : : void *cb_ctx)
4389 : : {
4390 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4391 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4392 : : struct mlx5_flow_dv_encap_decap_resource *cache_resource;
4393 : : uint32_t idx;
4394 : :
4395 : 0 : cache_resource = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
4396 : : &idx);
4397 [ # # ]: 0 : if (!cache_resource) {
4398 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4399 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4400 : : "cannot allocate resource memory");
4401 : 0 : return NULL;
4402 : : }
4403 : : memcpy(cache_resource, oentry, sizeof(*cache_resource));
4404 : 0 : cache_resource->idx = idx;
4405 : 0 : return &cache_resource->entry;
4406 : : }
4407 : :
4408 : : void
4409 : 0 : flow_encap_decap_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4410 : : {
4411 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4412 : : struct mlx5_flow_dv_encap_decap_resource *res =
4413 : : container_of(entry, typeof(*res), entry);
4414 : :
4415 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], res->idx);
4416 : 0 : }
4417 : :
4418 : : int
4419 : 0 : __flow_encap_decap_resource_register(struct rte_eth_dev *dev,
4420 : : struct mlx5_flow_dv_encap_decap_resource *resource,
4421 : : bool is_root,
4422 : : struct mlx5_flow_dv_encap_decap_resource **encap_decap,
4423 : : struct rte_flow_error *error)
4424 : : {
4425 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4426 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
4427 : : struct mlx5_list_entry *entry;
4428 : : union {
4429 : : struct {
4430 : : uint32_t ft_type:8;
4431 : : uint32_t refmt_type:8;
4432 : : /*
4433 : : * Header reformat actions can be shared between
4434 : : * non-root tables. One bit to indicate non-root
4435 : : * table or not.
4436 : : */
4437 : : uint32_t is_root:1;
4438 : : uint32_t reserve:15;
4439 : : };
4440 : : uint32_t v32;
4441 : 0 : } encap_decap_key = {
4442 : : {
4443 : 0 : .ft_type = resource->ft_type,
4444 : 0 : .refmt_type = resource->reformat_type,
4445 : : .is_root = is_root,
4446 : : .reserve = 0,
4447 : : }
4448 : : };
4449 : 0 : struct mlx5_flow_cb_ctx ctx = {
4450 : : .error = error,
4451 : : .data = resource,
4452 : 0 : .data2 = priv->dr_ctx,
4453 : : };
4454 : : struct mlx5_hlist *encaps_decaps;
4455 : : uint64_t key64;
4456 : :
4457 : 0 : encaps_decaps = flow_dv_hlist_prepare(sh, &sh->encaps_decaps,
4458 : : "encaps_decaps",
4459 : : MLX5_FLOW_ENCAP_DECAP_HTABLE_SZ,
4460 : : true, true, sh,
4461 : : flow_encap_decap_create_cb,
4462 : : flow_encap_decap_match_cb,
4463 : : flow_encap_decap_remove_cb,
4464 : : flow_encap_decap_clone_cb,
4465 : : flow_encap_decap_clone_free_cb,
4466 : : error);
4467 [ # # ]: 0 : if (unlikely(!encaps_decaps))
4468 : 0 : return -rte_errno;
4469 : 0 : key64 = __rte_raw_cksum(&encap_decap_key.v32,
4470 : : sizeof(encap_decap_key.v32), 0);
4471 [ # # ]: 0 : if (resource->reformat_type !=
4472 : 0 : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2 &&
4473 [ # # ]: 0 : resource->size)
4474 : 0 : key64 = __rte_raw_cksum(resource->buf, resource->size, key64);
4475 : 0 : entry = mlx5_hlist_register(encaps_decaps, key64, &ctx);
4476 [ # # ]: 0 : if (!entry)
4477 : 0 : return -rte_errno;
4478 : 0 : *encap_decap = container_of(entry, typeof(*resource), entry);
4479 : 0 : return 0;
4480 : : }
4481 : :
4482 : : /**
4483 : : * Find existing encap/decap resource or create and register a new one.
4484 : : *
4485 : : * @param[in, out] dev
4486 : : * Pointer to rte_eth_dev structure.
4487 : : * @param[in, out] resource
4488 : : * Pointer to encap/decap resource.
4489 : : * @param[in, out] dev_flow
4490 : : * Pointer to the dev_flow.
4491 : : * @param[out] error
4492 : : * pointer to error structure.
4493 : : *
4494 : : * @return
4495 : : * 0 on success otherwise -errno and errno is set.
4496 : : */
4497 : : static int
4498 : 0 : flow_dv_encap_decap_resource_register
4499 : : (struct rte_eth_dev *dev,
4500 : : struct mlx5_flow_dv_encap_decap_resource *resource,
4501 : : struct mlx5_flow *dev_flow,
4502 : : struct rte_flow_error *error)
4503 : : {
4504 : : int ret;
4505 : :
4506 : 0 : resource->flags = dev_flow->dv.group ? 0 : 1;
4507 : 0 : ret = __flow_encap_decap_resource_register(dev, resource, !!dev_flow->dv.group,
4508 : : &dev_flow->dv.encap_decap, error);
4509 [ # # ]: 0 : if (ret)
4510 : : return ret;
4511 : 0 : dev_flow->handle->dvh.rix_encap_decap = dev_flow->dv.encap_decap->idx;
4512 : 0 : return 0;
4513 : : }
4514 : :
4515 : : /**
4516 : : * Find existing table jump resource or create and register a new one.
4517 : : *
4518 : : * @param[in, out] dev
4519 : : * Pointer to rte_eth_dev structure.
4520 : : * @param[in, out] tbl
4521 : : * Pointer to flow table resource.
4522 : : * @parm[in, out] dev_flow
4523 : : * Pointer to the dev_flow.
4524 : : * @param[out] error
4525 : : * pointer to error structure.
4526 : : *
4527 : : * @return
4528 : : * 0 on success otherwise -errno and errno is set.
4529 : : */
4530 : : static int
4531 : : flow_dv_jump_tbl_resource_register
4532 : : (struct rte_eth_dev *dev __rte_unused,
4533 : : struct mlx5_flow_tbl_resource *tbl,
4534 : : struct mlx5_flow *dev_flow,
4535 : : struct rte_flow_error *error __rte_unused)
4536 : : {
4537 : : struct mlx5_flow_tbl_data_entry *tbl_data =
4538 : 0 : container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
4539 : :
4540 : : MLX5_ASSERT(tbl);
4541 : : MLX5_ASSERT(tbl_data->jump.action);
4542 : 0 : dev_flow->handle->rix_jump = tbl_data->idx;
4543 : 0 : dev_flow->dv.jump = &tbl_data->jump;
4544 : : return 0;
4545 : : }
4546 : :
4547 : : int
4548 : 0 : flow_dv_port_id_match_cb(void *tool_ctx __rte_unused,
4549 : : struct mlx5_list_entry *entry, void *cb_ctx)
4550 : : {
4551 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4552 : 0 : struct mlx5_flow_dv_port_id_action_resource *ref = ctx->data;
4553 : : struct mlx5_flow_dv_port_id_action_resource *res =
4554 : : container_of(entry, typeof(*res), entry);
4555 : :
4556 : 0 : return ref->port_id != res->port_id;
4557 : : }
4558 : :
4559 : : struct mlx5_list_entry *
4560 : 0 : flow_dv_port_id_create_cb(void *tool_ctx, void *cb_ctx)
4561 : : {
4562 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4563 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4564 : 0 : struct mlx5_flow_dv_port_id_action_resource *ref = ctx->data;
4565 : : struct mlx5_flow_dv_port_id_action_resource *resource;
4566 : : uint32_t idx;
4567 : : int ret;
4568 : :
4569 : : /* Register new port id action resource. */
4570 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID], &idx);
4571 [ # # ]: 0 : if (!resource) {
4572 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4573 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4574 : : "cannot allocate port_id action memory");
4575 : 0 : return NULL;
4576 : : }
4577 : 0 : *resource = *ref;
4578 : 0 : ret = mlx5_flow_os_create_flow_action_dest_port(sh->fdb_domain,
4579 : : ref->port_id,
4580 : : &resource->action);
4581 : : if (ret) {
4582 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], idx);
4583 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4584 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4585 : : "cannot create action");
4586 : 0 : return NULL;
4587 : : }
4588 : 0 : resource->idx = idx;
4589 : 0 : return &resource->entry;
4590 : : }
4591 : :
4592 : : struct mlx5_list_entry *
4593 : 0 : flow_dv_port_id_clone_cb(void *tool_ctx,
4594 : : struct mlx5_list_entry *entry __rte_unused,
4595 : : void *cb_ctx)
4596 : : {
4597 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4598 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4599 : : struct mlx5_flow_dv_port_id_action_resource *resource;
4600 : : uint32_t idx;
4601 : :
4602 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID], &idx);
4603 [ # # ]: 0 : if (!resource) {
4604 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4605 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4606 : : "cannot allocate port_id action memory");
4607 : 0 : return NULL;
4608 : : }
4609 : : memcpy(resource, entry, sizeof(*resource));
4610 : 0 : resource->idx = idx;
4611 : 0 : return &resource->entry;
4612 : : }
4613 : :
4614 : : void
4615 : 0 : flow_dv_port_id_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4616 : : {
4617 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4618 : : struct mlx5_flow_dv_port_id_action_resource *resource =
4619 : : container_of(entry, typeof(*resource), entry);
4620 : :
4621 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], resource->idx);
4622 : 0 : }
4623 : :
4624 : : /**
4625 : : * Find existing table port ID resource or create and register a new one.
4626 : : *
4627 : : * @param[in, out] dev
4628 : : * Pointer to rte_eth_dev structure.
4629 : : * @param[in, out] ref
4630 : : * Pointer to port ID action resource reference.
4631 : : * @parm[in, out] dev_flow
4632 : : * Pointer to the dev_flow.
4633 : : * @param[out] error
4634 : : * pointer to error structure.
4635 : : *
4636 : : * @return
4637 : : * 0 on success otherwise -errno and errno is set.
4638 : : */
4639 : : static int
4640 : 0 : flow_dv_port_id_action_resource_register
4641 : : (struct rte_eth_dev *dev,
4642 : : struct mlx5_flow_dv_port_id_action_resource *ref,
4643 : : struct mlx5_flow *dev_flow,
4644 : : struct rte_flow_error *error)
4645 : : {
4646 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4647 : : struct mlx5_list_entry *entry;
4648 : : struct mlx5_flow_dv_port_id_action_resource *resource;
4649 : 0 : struct mlx5_flow_cb_ctx ctx = {
4650 : : .error = error,
4651 : : .data = ref,
4652 : : };
4653 : :
4654 : 0 : entry = mlx5_list_register(priv->sh->port_id_action_list, &ctx);
4655 [ # # ]: 0 : if (!entry)
4656 : 0 : return -rte_errno;
4657 : : resource = container_of(entry, typeof(*resource), entry);
4658 : 0 : dev_flow->dv.port_id_action = resource;
4659 : 0 : dev_flow->handle->rix_port_id_action = resource->idx;
4660 : 0 : return 0;
4661 : : }
4662 : :
4663 : : int
4664 : 0 : flow_dv_push_vlan_match_cb(void *tool_ctx __rte_unused,
4665 : : struct mlx5_list_entry *entry, void *cb_ctx)
4666 : : {
4667 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4668 : 0 : struct mlx5_flow_dv_push_vlan_action_resource *ref = ctx->data;
4669 : : struct mlx5_flow_dv_push_vlan_action_resource *res =
4670 : : container_of(entry, typeof(*res), entry);
4671 : :
4672 : 0 : return ref->vlan_tag != res->vlan_tag || ref->ft_type != res->ft_type;
4673 : : }
4674 : :
4675 : : struct mlx5_list_entry *
4676 : 0 : flow_dv_push_vlan_create_cb(void *tool_ctx, void *cb_ctx)
4677 : : {
4678 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4679 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4680 : 0 : struct mlx5_flow_dv_push_vlan_action_resource *ref = ctx->data;
4681 : : struct mlx5_flow_dv_push_vlan_action_resource *resource;
4682 : : struct mlx5dv_dr_domain *domain;
4683 : : uint32_t idx;
4684 : : int ret;
4685 : :
4686 : : /* Register new port id action resource. */
4687 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PUSH_VLAN], &idx);
4688 [ # # ]: 0 : if (!resource) {
4689 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4690 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4691 : : "cannot allocate push_vlan action memory");
4692 : 0 : return NULL;
4693 : : }
4694 : 0 : *resource = *ref;
4695 [ # # ]: 0 : if (ref->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
4696 : 0 : domain = sh->fdb_domain;
4697 [ # # ]: 0 : else if (ref->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
4698 : 0 : domain = sh->rx_domain;
4699 : : else
4700 : 0 : domain = sh->tx_domain;
4701 : 0 : ret = mlx5_flow_os_create_flow_action_push_vlan(domain, ref->vlan_tag,
4702 : : &resource->action);
4703 : : if (ret) {
4704 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
4705 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4706 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4707 : : "cannot create push vlan action");
4708 : 0 : return NULL;
4709 : : }
4710 : 0 : resource->idx = idx;
4711 : 0 : return &resource->entry;
4712 : : }
4713 : :
4714 : : struct mlx5_list_entry *
4715 : 0 : flow_dv_push_vlan_clone_cb(void *tool_ctx,
4716 : : struct mlx5_list_entry *entry __rte_unused,
4717 : : void *cb_ctx)
4718 : : {
4719 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4720 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
4721 : : struct mlx5_flow_dv_push_vlan_action_resource *resource;
4722 : : uint32_t idx;
4723 : :
4724 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PUSH_VLAN], &idx);
4725 [ # # ]: 0 : if (!resource) {
4726 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
4727 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
4728 : : "cannot allocate push_vlan action memory");
4729 : 0 : return NULL;
4730 : : }
4731 : : memcpy(resource, entry, sizeof(*resource));
4732 : 0 : resource->idx = idx;
4733 : 0 : return &resource->entry;
4734 : : }
4735 : :
4736 : : void
4737 : 0 : flow_dv_push_vlan_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
4738 : : {
4739 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
4740 : : struct mlx5_flow_dv_push_vlan_action_resource *resource =
4741 : : container_of(entry, typeof(*resource), entry);
4742 : :
4743 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], resource->idx);
4744 : 0 : }
4745 : :
4746 : : /**
4747 : : * Find existing push vlan resource or create and register a new one.
4748 : : *
4749 : : * @param [in, out] dev
4750 : : * Pointer to rte_eth_dev structure.
4751 : : * @param[in, out] ref
4752 : : * Pointer to port ID action resource reference.
4753 : : * @parm[in, out] dev_flow
4754 : : * Pointer to the dev_flow.
4755 : : * @param[out] error
4756 : : * pointer to error structure.
4757 : : *
4758 : : * @return
4759 : : * 0 on success otherwise -errno and errno is set.
4760 : : */
4761 : : static int
4762 : 0 : flow_dv_push_vlan_action_resource_register
4763 : : (struct rte_eth_dev *dev,
4764 : : struct mlx5_flow_dv_push_vlan_action_resource *ref,
4765 : : struct mlx5_flow *dev_flow,
4766 : : struct rte_flow_error *error)
4767 : : {
4768 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
4769 : : struct mlx5_flow_dv_push_vlan_action_resource *resource;
4770 : : struct mlx5_list_entry *entry;
4771 : 0 : struct mlx5_flow_cb_ctx ctx = {
4772 : : .error = error,
4773 : : .data = ref,
4774 : : };
4775 : :
4776 : 0 : entry = mlx5_list_register(priv->sh->push_vlan_action_list, &ctx);
4777 [ # # ]: 0 : if (!entry)
4778 : 0 : return -rte_errno;
4779 : : resource = container_of(entry, typeof(*resource), entry);
4780 : :
4781 : 0 : dev_flow->handle->dvh.rix_push_vlan = resource->idx;
4782 : 0 : dev_flow->dv.push_vlan_res = resource;
4783 : 0 : return 0;
4784 : : }
4785 : :
4786 : : /**
4787 : : * Get the size of specific rte_flow_item_type hdr size
4788 : : *
4789 : : * @param[in] item_type
4790 : : * Tested rte_flow_item_type.
4791 : : *
4792 : : * @return
4793 : : * sizeof struct item_type, 0 if void or irrelevant.
4794 : : */
4795 : : size_t
4796 [ # # ]: 0 : flow_dv_get_item_hdr_len(const enum rte_flow_item_type item_type)
4797 : : {
4798 : : size_t retval;
4799 : :
4800 : : switch (item_type) {
4801 : : case RTE_FLOW_ITEM_TYPE_ETH:
4802 : : retval = sizeof(struct rte_ether_hdr);
4803 : : break;
4804 : : case RTE_FLOW_ITEM_TYPE_VLAN:
4805 : : retval = sizeof(struct rte_vlan_hdr);
4806 : : break;
4807 : : case RTE_FLOW_ITEM_TYPE_IPV4:
4808 : : retval = sizeof(struct rte_ipv4_hdr);
4809 : : break;
4810 : : case RTE_FLOW_ITEM_TYPE_IPV6:
4811 : : retval = sizeof(struct rte_ipv6_hdr);
4812 : : break;
4813 : : case RTE_FLOW_ITEM_TYPE_UDP:
4814 : : retval = sizeof(struct rte_udp_hdr);
4815 : : break;
4816 : : case RTE_FLOW_ITEM_TYPE_TCP:
4817 : : retval = sizeof(struct rte_tcp_hdr);
4818 : : break;
4819 : : case RTE_FLOW_ITEM_TYPE_VXLAN:
4820 : : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
4821 : : retval = sizeof(struct rte_vxlan_hdr);
4822 : : break;
4823 : : case RTE_FLOW_ITEM_TYPE_GRE:
4824 : : case RTE_FLOW_ITEM_TYPE_NVGRE:
4825 : : retval = sizeof(struct rte_gre_hdr);
4826 : : break;
4827 : : case RTE_FLOW_ITEM_TYPE_MPLS:
4828 : : retval = sizeof(struct rte_mpls_hdr);
4829 : : break;
4830 : : case RTE_FLOW_ITEM_TYPE_VOID: /* Fall through. */
4831 : : default:
4832 : : retval = 0;
4833 : : break;
4834 : : }
4835 : 0 : return retval;
4836 : : }
4837 : :
4838 : : #define MLX5_ENCAP_IPV4_VERSION 0x40
4839 : : #define MLX5_ENCAP_IPV4_IHL_MIN 0x05
4840 : : #define MLX5_ENCAP_IPV4_TTL_DEF 0x40
4841 : : #define MLX5_ENCAP_IPV6_VTC_FLOW 0x60000000
4842 : : #define MLX5_ENCAP_IPV6_HOP_LIMIT 0xff
4843 : : #define MLX5_ENCAP_VXLAN_FLAGS 0x08000000
4844 : : #define MLX5_ENCAP_VXLAN_GPE_FLAGS 0x04
4845 : :
4846 : : /**
4847 : : * Convert the encap action data from list of rte_flow_item to raw buffer
4848 : : *
4849 : : * @param[in] items
4850 : : * Pointer to rte_flow_item objects list.
4851 : : * @param[out] buf
4852 : : * Pointer to the output buffer.
4853 : : * @param[out] size
4854 : : * Pointer to the output buffer size.
4855 : : * @param[out] error
4856 : : * Pointer to the error structure.
4857 : : *
4858 : : * @return
4859 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
4860 : : */
4861 : : int
4862 : 0 : flow_dv_convert_encap_data(const struct rte_flow_item *items, uint8_t *buf,
4863 : : size_t *size, struct rte_flow_error *error)
4864 : : {
4865 : : struct rte_ether_hdr *eth = NULL;
4866 : : struct rte_vlan_hdr *vlan = NULL;
4867 : : struct rte_ipv4_hdr *ipv4 = NULL;
4868 : : struct rte_ipv6_hdr *ipv6 = NULL;
4869 : : struct rte_udp_hdr *udp = NULL;
4870 : : struct rte_vxlan_hdr *vxlan = NULL;
4871 : : struct rte_vxlan_gpe_hdr *vxlan_gpe = NULL;
4872 : : struct rte_gre_hdr *gre = NULL;
4873 : : size_t len;
4874 : : size_t temp_size = 0;
4875 : :
4876 [ # # ]: 0 : if (!items)
4877 : 0 : return rte_flow_error_set(error, EINVAL,
4878 : : RTE_FLOW_ERROR_TYPE_ACTION,
4879 : : NULL, "invalid empty data");
4880 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
4881 : 0 : len = flow_dv_get_item_hdr_len(items->type);
4882 [ # # ]: 0 : if (len + temp_size > MLX5_ENCAP_MAX_LEN)
4883 : 0 : return rte_flow_error_set(error, EINVAL,
4884 : : RTE_FLOW_ERROR_TYPE_ACTION,
4885 : 0 : (void *)items->type,
4886 : : "items total size is too big"
4887 : : " for encap action");
4888 [ # # ]: 0 : if (items->spec)
4889 [ # # ]: 0 : rte_memcpy(&buf[temp_size], items->spec, len);
4890 [ # # # # : 0 : switch (items->type) {
# # # # #
# ]
4891 : 0 : case RTE_FLOW_ITEM_TYPE_ETH:
4892 : 0 : eth = (struct rte_ether_hdr *)&buf[temp_size];
4893 : 0 : break;
4894 : 0 : case RTE_FLOW_ITEM_TYPE_VLAN:
4895 : 0 : vlan = (struct rte_vlan_hdr *)&buf[temp_size];
4896 [ # # ]: 0 : if (!eth)
4897 : 0 : return rte_flow_error_set(error, EINVAL,
4898 : : RTE_FLOW_ERROR_TYPE_ACTION,
4899 : : (void *)items->type,
4900 : : "eth header not found");
4901 [ # # ]: 0 : if (!eth->ether_type)
4902 : 0 : eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_VLAN);
4903 : : break;
4904 : 0 : case RTE_FLOW_ITEM_TYPE_IPV4:
4905 : 0 : ipv4 = (struct rte_ipv4_hdr *)&buf[temp_size];
4906 [ # # ]: 0 : if (!vlan && !eth)
4907 : 0 : return rte_flow_error_set(error, EINVAL,
4908 : : RTE_FLOW_ERROR_TYPE_ACTION,
4909 : : (void *)items->type,
4910 : : "neither eth nor vlan"
4911 : : " header found");
4912 [ # # # # ]: 0 : if (vlan && !vlan->eth_proto)
4913 : 0 : vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV4);
4914 [ # # # # ]: 0 : else if (eth && !eth->ether_type)
4915 : 0 : eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV4);
4916 [ # # ]: 0 : if (!ipv4->version_ihl)
4917 : 0 : ipv4->version_ihl = MLX5_ENCAP_IPV4_VERSION |
4918 : : MLX5_ENCAP_IPV4_IHL_MIN;
4919 [ # # ]: 0 : if (!ipv4->time_to_live)
4920 : 0 : ipv4->time_to_live = MLX5_ENCAP_IPV4_TTL_DEF;
4921 : : break;
4922 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6:
4923 : 0 : ipv6 = (struct rte_ipv6_hdr *)&buf[temp_size];
4924 [ # # ]: 0 : if (!vlan && !eth)
4925 : 0 : return rte_flow_error_set(error, EINVAL,
4926 : : RTE_FLOW_ERROR_TYPE_ACTION,
4927 : : (void *)items->type,
4928 : : "neither eth nor vlan"
4929 : : " header found");
4930 [ # # # # ]: 0 : if (vlan && !vlan->eth_proto)
4931 : 0 : vlan->eth_proto = RTE_BE16(RTE_ETHER_TYPE_IPV6);
4932 [ # # # # ]: 0 : else if (eth && !eth->ether_type)
4933 : 0 : eth->ether_type = RTE_BE16(RTE_ETHER_TYPE_IPV6);
4934 [ # # ]: 0 : if (!ipv6->vtc_flow)
4935 : 0 : ipv6->vtc_flow =
4936 : : RTE_BE32(MLX5_ENCAP_IPV6_VTC_FLOW);
4937 [ # # ]: 0 : if (!ipv6->hop_limits)
4938 : 0 : ipv6->hop_limits = MLX5_ENCAP_IPV6_HOP_LIMIT;
4939 : : break;
4940 : 0 : case RTE_FLOW_ITEM_TYPE_UDP:
4941 : 0 : udp = (struct rte_udp_hdr *)&buf[temp_size];
4942 [ # # ]: 0 : if (!ipv4 && !ipv6)
4943 : 0 : return rte_flow_error_set(error, EINVAL,
4944 : : RTE_FLOW_ERROR_TYPE_ACTION,
4945 : : (void *)items->type,
4946 : : "ip header not found");
4947 [ # # # # ]: 0 : if (ipv4 && !ipv4->next_proto_id)
4948 : 0 : ipv4->next_proto_id = IPPROTO_UDP;
4949 [ # # # # ]: 0 : else if (ipv6 && !ipv6->proto)
4950 : 0 : ipv6->proto = IPPROTO_UDP;
4951 : : break;
4952 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN:
4953 : 0 : vxlan = (struct rte_vxlan_hdr *)&buf[temp_size];
4954 [ # # ]: 0 : if (!udp)
4955 : 0 : return rte_flow_error_set(error, EINVAL,
4956 : : RTE_FLOW_ERROR_TYPE_ACTION,
4957 : : (void *)items->type,
4958 : : "udp header not found");
4959 [ # # ]: 0 : if (!udp->dst_port)
4960 : 0 : udp->dst_port = RTE_BE16(MLX5_UDP_PORT_VXLAN);
4961 [ # # ]: 0 : if (!vxlan->vx_flags)
4962 : 0 : vxlan->vx_flags =
4963 : : RTE_BE32(MLX5_ENCAP_VXLAN_FLAGS);
4964 : : break;
4965 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
4966 : 0 : vxlan_gpe = (struct rte_vxlan_gpe_hdr *)&buf[temp_size];
4967 [ # # ]: 0 : if (!udp)
4968 : 0 : return rte_flow_error_set(error, EINVAL,
4969 : : RTE_FLOW_ERROR_TYPE_ACTION,
4970 : : (void *)items->type,
4971 : : "udp header not found");
4972 [ # # ]: 0 : if (!vxlan_gpe->proto)
4973 : 0 : return rte_flow_error_set(error, EINVAL,
4974 : : RTE_FLOW_ERROR_TYPE_ACTION,
4975 : : (void *)items->type,
4976 : : "next protocol not found");
4977 [ # # ]: 0 : if (!udp->dst_port)
4978 : 0 : udp->dst_port =
4979 : : RTE_BE16(MLX5_UDP_PORT_VXLAN_GPE);
4980 [ # # ]: 0 : if (!vxlan_gpe->vx_flags)
4981 : 0 : vxlan_gpe->vx_flags =
4982 : : MLX5_ENCAP_VXLAN_GPE_FLAGS;
4983 : : break;
4984 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
4985 : : case RTE_FLOW_ITEM_TYPE_NVGRE:
4986 : 0 : gre = (struct rte_gre_hdr *)&buf[temp_size];
4987 [ # # ]: 0 : if (!gre->proto)
4988 : 0 : return rte_flow_error_set(error, EINVAL,
4989 : : RTE_FLOW_ERROR_TYPE_ACTION,
4990 : 0 : (void *)items->type,
4991 : : "next protocol not found");
4992 [ # # ]: 0 : if (!ipv4 && !ipv6)
4993 : 0 : return rte_flow_error_set(error, EINVAL,
4994 : : RTE_FLOW_ERROR_TYPE_ACTION,
4995 : 0 : (void *)items->type,
4996 : : "ip header not found");
4997 [ # # # # ]: 0 : if (ipv4 && !ipv4->next_proto_id)
4998 : 0 : ipv4->next_proto_id = IPPROTO_GRE;
4999 [ # # # # ]: 0 : else if (ipv6 && !ipv6->proto)
5000 : 0 : ipv6->proto = IPPROTO_GRE;
5001 : : break;
5002 : : case RTE_FLOW_ITEM_TYPE_VOID:
5003 : : break;
5004 : 0 : default:
5005 : 0 : return rte_flow_error_set(error, EINVAL,
5006 : : RTE_FLOW_ERROR_TYPE_ACTION,
5007 : 0 : (void *)items->type,
5008 : : "unsupported item type");
5009 : : break;
5010 : : }
5011 : : temp_size += len;
5012 : : }
5013 : 0 : *size = temp_size;
5014 : 0 : return 0;
5015 : : }
5016 : :
5017 : : static int
5018 : 0 : flow_dv_zero_encap_udp_csum(void *data, struct rte_flow_error *error)
5019 : : {
5020 : : struct rte_ether_hdr *eth = NULL;
5021 : : struct rte_vlan_hdr *vlan = NULL;
5022 : : struct rte_ipv4_hdr *ipv4 = NULL;
5023 : : struct rte_ipv6_hdr *ipv6 = NULL;
5024 : : struct rte_udp_hdr *udp = NULL;
5025 : : char *next_hdr;
5026 : : uint16_t proto;
5027 : :
5028 : : eth = (struct rte_ether_hdr *)data;
5029 : 0 : next_hdr = (char *)(eth + 1);
5030 : 0 : proto = RTE_BE16(eth->ether_type);
5031 : :
5032 : : /* VLAN skipping */
5033 [ # # ]: 0 : while (proto == RTE_ETHER_TYPE_VLAN || proto == RTE_ETHER_TYPE_QINQ) {
5034 : : vlan = (struct rte_vlan_hdr *)next_hdr;
5035 : 0 : proto = RTE_BE16(vlan->eth_proto);
5036 : 0 : next_hdr += sizeof(struct rte_vlan_hdr);
5037 : : }
5038 : :
5039 : : /* non IPv4/IPv6 header. not supported */
5040 [ # # ]: 0 : if (proto != RTE_ETHER_TYPE_IPV4 && proto != RTE_ETHER_TYPE_IPV6) {
5041 : 0 : return rte_flow_error_set(error, ENOTSUP,
5042 : : RTE_FLOW_ERROR_TYPE_ACTION,
5043 : : NULL, "Cannot offload non IPv4/IPv6");
5044 : : }
5045 : :
5046 [ # # ]: 0 : if (proto == RTE_ETHER_TYPE_IPV4) {
5047 : : ipv4 = (struct rte_ipv4_hdr *)next_hdr;
5048 : : /* ignore non UDP */
5049 [ # # ]: 0 : if (ipv4->next_proto_id != IPPROTO_UDP)
5050 : : return 0;
5051 : 0 : udp = (struct rte_udp_hdr *)(ipv4 + 1);
5052 : : } else {
5053 : : ipv6 = (struct rte_ipv6_hdr *)next_hdr;
5054 : : /* ignore non UDP */
5055 [ # # ]: 0 : if (ipv6->proto != IPPROTO_UDP)
5056 : : return 0;
5057 : 0 : udp = (struct rte_udp_hdr *)(ipv6 + 1);
5058 : : }
5059 : :
5060 : 0 : udp->dgram_cksum = 0;
5061 : :
5062 : 0 : return 0;
5063 : : }
5064 : :
5065 : : /**
5066 : : * Convert L2 encap action to DV specification.
5067 : : *
5068 : : * @param[in] dev
5069 : : * Pointer to rte_eth_dev structure.
5070 : : * @param[in] action
5071 : : * Pointer to action structure.
5072 : : * @param[in, out] dev_flow
5073 : : * Pointer to the mlx5_flow.
5074 : : * @param[in] transfer
5075 : : * Mark if the flow is E-Switch flow.
5076 : : * @param[out] error
5077 : : * Pointer to the error structure.
5078 : : *
5079 : : * @return
5080 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5081 : : */
5082 : : static int
5083 : 0 : flow_dv_create_action_l2_encap(struct rte_eth_dev *dev,
5084 : : const struct rte_flow_action *action,
5085 : : struct mlx5_flow *dev_flow,
5086 : : uint8_t transfer,
5087 : : struct rte_flow_error *error)
5088 : : {
5089 : : const struct rte_flow_item *encap_data;
5090 : : const struct rte_flow_action_raw_encap *raw_encap_data;
5091 [ # # ]: 0 : struct mlx5_flow_dv_encap_decap_resource res = {
5092 : : .reformat_type =
5093 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L2_TUNNEL,
5094 : : .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
5095 : : MLX5DV_FLOW_TABLE_TYPE_NIC_TX,
5096 : : };
5097 : :
5098 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
5099 : 0 : raw_encap_data =
5100 : : (const struct rte_flow_action_raw_encap *)action->conf;
5101 : 0 : res.size = raw_encap_data->size;
5102 : 0 : memcpy(res.buf, raw_encap_data->data, res.size);
5103 : : } else {
5104 [ # # ]: 0 : if (action->type == RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP)
5105 : 0 : encap_data =
5106 : : ((const struct rte_flow_action_vxlan_encap *)
5107 : 0 : action->conf)->definition;
5108 : : else
5109 : 0 : encap_data =
5110 : : ((const struct rte_flow_action_nvgre_encap *)
5111 : 0 : action->conf)->definition;
5112 [ # # ]: 0 : if (flow_dv_convert_encap_data(encap_data, res.buf,
5113 : : &res.size, error))
5114 : 0 : return -rte_errno;
5115 : : }
5116 [ # # ]: 0 : if (flow_dv_zero_encap_udp_csum(res.buf, error))
5117 : 0 : return -rte_errno;
5118 [ # # ]: 0 : if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
5119 : 0 : return rte_flow_error_set(error, EINVAL,
5120 : : RTE_FLOW_ERROR_TYPE_ACTION,
5121 : : NULL, "can't create L2 encap action");
5122 : : return 0;
5123 : : }
5124 : :
5125 : : /**
5126 : : * Convert L2 decap action to DV specification.
5127 : : *
5128 : : * @param[in] dev
5129 : : * Pointer to rte_eth_dev structure.
5130 : : * @param[in, out] dev_flow
5131 : : * Pointer to the mlx5_flow.
5132 : : * @param[in] transfer
5133 : : * Mark if the flow is E-Switch flow.
5134 : : * @param[out] error
5135 : : * Pointer to the error structure.
5136 : : *
5137 : : * @return
5138 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5139 : : */
5140 : : static int
5141 : 0 : flow_dv_create_action_l2_decap(struct rte_eth_dev *dev,
5142 : : struct mlx5_flow *dev_flow,
5143 : : uint8_t transfer,
5144 : : struct rte_flow_error *error)
5145 : : {
5146 [ # # ]: 0 : struct mlx5_flow_dv_encap_decap_resource res = {
5147 : : .size = 0,
5148 : : .reformat_type =
5149 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2,
5150 : : .ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
5151 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX,
5152 : : };
5153 : :
5154 [ # # ]: 0 : if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
5155 : 0 : return rte_flow_error_set(error, EINVAL,
5156 : : RTE_FLOW_ERROR_TYPE_ACTION,
5157 : : NULL, "can't create L2 decap action");
5158 : : return 0;
5159 : : }
5160 : :
5161 : : /**
5162 : : * Convert raw decap/encap (L3 tunnel) action to DV specification.
5163 : : *
5164 : : * @param[in] dev
5165 : : * Pointer to rte_eth_dev structure.
5166 : : * @param[in] action
5167 : : * Pointer to action structure.
5168 : : * @param[in, out] dev_flow
5169 : : * Pointer to the mlx5_flow.
5170 : : * @param[in] attr
5171 : : * Pointer to the flow attributes.
5172 : : * @param[out] error
5173 : : * Pointer to the error structure.
5174 : : *
5175 : : * @return
5176 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5177 : : */
5178 : : static int
5179 [ # # ]: 0 : flow_dv_create_action_raw_encap(struct rte_eth_dev *dev,
5180 : : const struct rte_flow_action *action,
5181 : : struct mlx5_flow *dev_flow,
5182 : : const struct rte_flow_attr *attr,
5183 : : struct rte_flow_error *error)
5184 : : {
5185 : : const struct rte_flow_action_raw_encap *encap_data;
5186 : : struct mlx5_flow_dv_encap_decap_resource res;
5187 : :
5188 : : memset(&res, 0, sizeof(res));
5189 : 0 : encap_data = (const struct rte_flow_action_raw_encap *)action->conf;
5190 : 0 : res.size = encap_data->size;
5191 [ # # ]: 0 : memcpy(res.buf, encap_data->data, res.size);
5192 [ # # ]: 0 : res.reformat_type = res.size < MLX5_ENCAPSULATION_DECISION_SIZE ?
5193 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L3_TUNNEL_TO_L2 :
5194 : : MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L3_TUNNEL;
5195 [ # # ]: 0 : if (attr->transfer)
5196 : 0 : res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
5197 : : else
5198 : 0 : res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
5199 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
5200 [ # # ]: 0 : if (flow_dv_encap_decap_resource_register(dev, &res, dev_flow, error))
5201 : 0 : return rte_flow_error_set(error, EINVAL,
5202 : : RTE_FLOW_ERROR_TYPE_ACTION,
5203 : : NULL, "can't create encap action");
5204 : : return 0;
5205 : : }
5206 : :
5207 : : /**
5208 : : * Create action push VLAN.
5209 : : *
5210 : : * @param[in] dev
5211 : : * Pointer to rte_eth_dev structure.
5212 : : * @param[in] attr
5213 : : * Pointer to the flow attributes.
5214 : : * @param[in] vlan
5215 : : * Pointer to the vlan to push to the Ethernet header.
5216 : : * @param[in, out] dev_flow
5217 : : * Pointer to the mlx5_flow.
5218 : : * @param[out] error
5219 : : * Pointer to the error structure.
5220 : : *
5221 : : * @return
5222 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5223 : : */
5224 : : static int
5225 [ # # ]: 0 : flow_dv_create_action_push_vlan(struct rte_eth_dev *dev,
5226 : : const struct rte_flow_attr *attr,
5227 : : const struct rte_vlan_hdr *vlan,
5228 : : struct mlx5_flow *dev_flow,
5229 : : struct rte_flow_error *error)
5230 : : {
5231 : : struct mlx5_flow_dv_push_vlan_action_resource res;
5232 : :
5233 : : memset(&res, 0, sizeof(res));
5234 : 0 : res.vlan_tag =
5235 [ # # ]: 0 : rte_cpu_to_be_32(((uint32_t)vlan->eth_proto) << 16 |
5236 : : vlan->vlan_tci);
5237 [ # # ]: 0 : if (attr->transfer)
5238 : 0 : res.ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
5239 : : else
5240 : 0 : res.ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
5241 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
5242 : 0 : return flow_dv_push_vlan_action_resource_register
5243 : : (dev, &res, dev_flow, error);
5244 : : }
5245 : :
5246 : : /**
5247 : : * Validate the modify-header actions.
5248 : : *
5249 : : * @param[in] action_flags
5250 : : * Holds the actions detected until now.
5251 : : * @param[in] action
5252 : : * Pointer to the modify action.
5253 : : * @param[out] error
5254 : : * Pointer to error structure.
5255 : : *
5256 : : * @return
5257 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5258 : : */
5259 : : static int
5260 : 0 : flow_dv_validate_action_modify_hdr(const uint64_t action_flags,
5261 : : const struct rte_flow_action *action,
5262 : : struct rte_flow_error *error)
5263 : : {
5264 [ # # # # ]: 0 : if (action->type != RTE_FLOW_ACTION_TYPE_DEC_TTL && !action->conf)
5265 : 0 : return rte_flow_error_set(error, EINVAL,
5266 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5267 : : NULL, "action configuration not set");
5268 : :
5269 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
5270 : 0 : return rte_flow_error_set(error, EINVAL,
5271 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5272 : : "can't have encap action before"
5273 : : " modify action");
5274 : : return 0;
5275 : : }
5276 : :
5277 : : /**
5278 : : * Validate the modify-header MAC address actions.
5279 : : *
5280 : : * @param[in] action_flags
5281 : : * Holds the actions detected until now.
5282 : : * @param[in] action
5283 : : * Pointer to the modify action.
5284 : : * @param[in] item_flags
5285 : : * Holds the items detected.
5286 : : * @param[out] error
5287 : : * Pointer to error structure.
5288 : : *
5289 : : * @return
5290 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5291 : : */
5292 : : static int
5293 : 0 : flow_dv_validate_action_modify_mac(const uint64_t action_flags,
5294 : : const struct rte_flow_action *action,
5295 : : const uint64_t item_flags,
5296 : : struct rte_flow_error *error)
5297 : : {
5298 : : int ret = 0;
5299 : :
5300 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5301 [ # # ]: 0 : if (!ret) {
5302 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_L2))
5303 : 0 : return rte_flow_error_set(error, EINVAL,
5304 : : RTE_FLOW_ERROR_TYPE_ACTION,
5305 : : NULL,
5306 : : "no L2 item in pattern");
5307 : : }
5308 : : return ret;
5309 : : }
5310 : :
5311 : : /**
5312 : : * Validate the modify-header IPv4 address actions.
5313 : : *
5314 : : * @param[in] action_flags
5315 : : * Holds the actions detected until now.
5316 : : * @param[in] action
5317 : : * Pointer to the modify action.
5318 : : * @param[in] item_flags
5319 : : * Holds the items detected.
5320 : : * @param[out] error
5321 : : * Pointer to error structure.
5322 : : *
5323 : : * @return
5324 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5325 : : */
5326 : : static int
5327 : 0 : flow_dv_validate_action_modify_ipv4(const uint64_t action_flags,
5328 : : const struct rte_flow_action *action,
5329 : : const uint64_t item_flags,
5330 : : struct rte_flow_error *error)
5331 : : {
5332 : : int ret = 0;
5333 : : uint64_t layer;
5334 : :
5335 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5336 [ # # ]: 0 : if (!ret) {
5337 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5338 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L3_IPV4 :
5339 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4;
5340 [ # # ]: 0 : if (!(item_flags & layer))
5341 : 0 : return rte_flow_error_set(error, EINVAL,
5342 : : RTE_FLOW_ERROR_TYPE_ACTION,
5343 : : NULL,
5344 : : "no ipv4 item in pattern");
5345 : : }
5346 : : return ret;
5347 : : }
5348 : :
5349 : : /**
5350 : : * Validate the modify-header IPv6 address actions.
5351 : : *
5352 : : * @param[in] action_flags
5353 : : * Holds the actions detected until now.
5354 : : * @param[in] action
5355 : : * Pointer to the modify action.
5356 : : * @param[in] item_flags
5357 : : * Holds the items detected.
5358 : : * @param[out] error
5359 : : * Pointer to error structure.
5360 : : *
5361 : : * @return
5362 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5363 : : */
5364 : : static int
5365 : 0 : flow_dv_validate_action_modify_ipv6(const uint64_t action_flags,
5366 : : const struct rte_flow_action *action,
5367 : : const uint64_t item_flags,
5368 : : struct rte_flow_error *error)
5369 : : {
5370 : : int ret = 0;
5371 : : uint64_t layer;
5372 : :
5373 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5374 [ # # ]: 0 : if (!ret) {
5375 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5376 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L3_IPV6 :
5377 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6;
5378 [ # # ]: 0 : if (!(item_flags & layer))
5379 : 0 : return rte_flow_error_set(error, EINVAL,
5380 : : RTE_FLOW_ERROR_TYPE_ACTION,
5381 : : NULL,
5382 : : "no ipv6 item in pattern");
5383 : : }
5384 : : return ret;
5385 : : }
5386 : :
5387 : : /**
5388 : : * Validate the modify-header TP actions.
5389 : : *
5390 : : * @param[in] action_flags
5391 : : * Holds the actions detected until now.
5392 : : * @param[in] action
5393 : : * Pointer to the modify action.
5394 : : * @param[in] item_flags
5395 : : * Holds the items detected.
5396 : : * @param[out] error
5397 : : * Pointer to error structure.
5398 : : *
5399 : : * @return
5400 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5401 : : */
5402 : : static int
5403 : 0 : flow_dv_validate_action_modify_tp(const uint64_t action_flags,
5404 : : const struct rte_flow_action *action,
5405 : : const uint64_t item_flags,
5406 : : struct rte_flow_error *error)
5407 : : {
5408 : : int ret = 0;
5409 : : uint64_t layer;
5410 : :
5411 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5412 [ # # ]: 0 : if (!ret) {
5413 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5414 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L4 :
5415 : : MLX5_FLOW_LAYER_OUTER_L4;
5416 [ # # ]: 0 : if (!(item_flags & layer))
5417 : 0 : return rte_flow_error_set(error, EINVAL,
5418 : : RTE_FLOW_ERROR_TYPE_ACTION,
5419 : : NULL, "no transport layer "
5420 : : "in pattern");
5421 : : }
5422 : : return ret;
5423 : : }
5424 : :
5425 : : /**
5426 : : * Validate the modify-header actions of increment/decrement
5427 : : * TCP Sequence-number.
5428 : : *
5429 : : * @param[in] action_flags
5430 : : * Holds the actions detected until now.
5431 : : * @param[in] action
5432 : : * Pointer to the modify action.
5433 : : * @param[in] item_flags
5434 : : * Holds the items detected.
5435 : : * @param[out] error
5436 : : * Pointer to error structure.
5437 : : *
5438 : : * @return
5439 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5440 : : */
5441 : : static int
5442 : 0 : flow_dv_validate_action_modify_tcp_seq(const uint64_t action_flags,
5443 : : const struct rte_flow_action *action,
5444 : : const uint64_t item_flags,
5445 : : struct rte_flow_error *error)
5446 : : {
5447 : : int ret = 0;
5448 : : uint64_t layer;
5449 : :
5450 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5451 [ # # ]: 0 : if (!ret) {
5452 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5453 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L4_TCP :
5454 : : MLX5_FLOW_LAYER_OUTER_L4_TCP;
5455 [ # # ]: 0 : if (!(item_flags & layer))
5456 : 0 : return rte_flow_error_set(error, EINVAL,
5457 : : RTE_FLOW_ERROR_TYPE_ACTION,
5458 : : NULL, "no TCP item in"
5459 : : " pattern");
5460 [ # # ]: 0 : if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ &&
5461 [ # # # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_DEC_TCP_SEQ)) ||
5462 : 0 : (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ &&
5463 [ # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_INC_TCP_SEQ)))
5464 : 0 : return rte_flow_error_set(error, EINVAL,
5465 : : RTE_FLOW_ERROR_TYPE_ACTION,
5466 : : NULL,
5467 : : "cannot decrease and increase"
5468 : : " TCP sequence number"
5469 : : " at the same time");
5470 : : }
5471 : : return ret;
5472 : : }
5473 : :
5474 : : /**
5475 : : * Validate the modify-header actions of increment/decrement
5476 : : * TCP Acknowledgment number.
5477 : : *
5478 : : * @param[in] action_flags
5479 : : * Holds the actions detected until now.
5480 : : * @param[in] action
5481 : : * Pointer to the modify action.
5482 : : * @param[in] item_flags
5483 : : * Holds the items detected.
5484 : : * @param[out] error
5485 : : * Pointer to error structure.
5486 : : *
5487 : : * @return
5488 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5489 : : */
5490 : : static int
5491 : 0 : flow_dv_validate_action_modify_tcp_ack(const uint64_t action_flags,
5492 : : const struct rte_flow_action *action,
5493 : : const uint64_t item_flags,
5494 : : struct rte_flow_error *error)
5495 : : {
5496 : : int ret = 0;
5497 : : uint64_t layer;
5498 : :
5499 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5500 [ # # ]: 0 : if (!ret) {
5501 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5502 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L4_TCP :
5503 : : MLX5_FLOW_LAYER_OUTER_L4_TCP;
5504 [ # # ]: 0 : if (!(item_flags & layer))
5505 : 0 : return rte_flow_error_set(error, EINVAL,
5506 : : RTE_FLOW_ERROR_TYPE_ACTION,
5507 : : NULL, "no TCP item in"
5508 : : " pattern");
5509 [ # # ]: 0 : if ((action->type == RTE_FLOW_ACTION_TYPE_INC_TCP_ACK &&
5510 [ # # # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_DEC_TCP_ACK)) ||
5511 : 0 : (action->type == RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK &&
5512 [ # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_INC_TCP_ACK)))
5513 : 0 : return rte_flow_error_set(error, EINVAL,
5514 : : RTE_FLOW_ERROR_TYPE_ACTION,
5515 : : NULL,
5516 : : "cannot decrease and increase"
5517 : : " TCP acknowledgment number"
5518 : : " at the same time");
5519 : : }
5520 : : return ret;
5521 : : }
5522 : :
5523 : : /**
5524 : : * Validate the modify-header TTL actions.
5525 : : *
5526 : : * @param[in] action_flags
5527 : : * Holds the actions detected until now.
5528 : : * @param[in] action
5529 : : * Pointer to the modify action.
5530 : : * @param[in] item_flags
5531 : : * Holds the items detected.
5532 : : * @param[out] error
5533 : : * Pointer to error structure.
5534 : : *
5535 : : * @return
5536 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5537 : : */
5538 : : static int
5539 : 0 : flow_dv_validate_action_modify_ttl(const uint64_t action_flags,
5540 : : const struct rte_flow_action *action,
5541 : : const uint64_t item_flags,
5542 : : struct rte_flow_error *error)
5543 : : {
5544 : : int ret = 0;
5545 : : uint64_t layer;
5546 : :
5547 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5548 [ # # ]: 0 : if (!ret) {
5549 : 0 : layer = (action_flags & MLX5_FLOW_ACTION_DECAP) ?
5550 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L3 :
5551 : : MLX5_FLOW_LAYER_OUTER_L3;
5552 [ # # ]: 0 : if (!(item_flags & layer))
5553 : 0 : return rte_flow_error_set(error, EINVAL,
5554 : : RTE_FLOW_ERROR_TYPE_ACTION,
5555 : : NULL,
5556 : : "no IP protocol in pattern");
5557 : : }
5558 : : return ret;
5559 : : }
5560 : :
5561 : : /**
5562 : : * Validate the generic modify field actions.
5563 : : * @param[in] dev
5564 : : * Pointer to the rte_eth_dev structure.
5565 : : * @param[in] action_flags
5566 : : * Holds the actions detected until now.
5567 : : * @param[in] action
5568 : : * Pointer to the modify action.
5569 : : * @param[in] attr
5570 : : * Pointer to the flow attributes.
5571 : : * @param root
5572 : : * Whether action is on root table.
5573 : : * @param[out] error
5574 : : * Pointer to error structure.
5575 : : *
5576 : : * @return
5577 : : * Number of header fields to modify (0 or more) on success,
5578 : : * a negative errno value otherwise and rte_errno is set.
5579 : : */
5580 : : static int
5581 : 0 : flow_dv_validate_action_modify_field(struct rte_eth_dev *dev,
5582 : : const uint64_t action_flags,
5583 : : const struct rte_flow_action *action,
5584 : : const struct rte_flow_attr *attr,
5585 : : bool root,
5586 : : struct rte_flow_error *error)
5587 : : {
5588 : : int ret = 0;
5589 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5590 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
5591 : 0 : struct mlx5_hca_attr *hca_attr = &priv->sh->cdev->config.hca_attr;
5592 : 0 : const struct rte_flow_action_modify_field *conf = action->conf;
5593 : 0 : const struct rte_flow_field_data *src_data = &conf->src;
5594 : 0 : const struct rte_flow_field_data *dst_data = &conf->dst;
5595 : 0 : uint32_t dst_width, src_width, width = conf->width;
5596 : :
5597 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
5598 [ # # ]: 0 : if (ret)
5599 : : return ret;
5600 [ # # ]: 0 : if (src_data->field == RTE_FLOW_FIELD_FLEX_ITEM ||
5601 [ # # ]: 0 : dst_data->field == RTE_FLOW_FIELD_FLEX_ITEM)
5602 : 0 : return rte_flow_error_set(error, ENOTSUP,
5603 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5604 : : "flex item fields modification"
5605 : : " is not supported");
5606 : 0 : dst_width = mlx5_flow_item_field_width(dev, dst_data->field,
5607 : : -1, attr, error);
5608 : 0 : src_width = mlx5_flow_item_field_width(dev, src_data->field,
5609 : : dst_width, attr, error);
5610 [ # # ]: 0 : if (width == 0)
5611 : 0 : return rte_flow_error_set(error, EINVAL,
5612 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5613 : : "no bits are requested to be modified");
5614 [ # # ]: 0 : else if (width > dst_width || width > src_width)
5615 : 0 : return rte_flow_error_set(error, EINVAL,
5616 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5617 : : "cannot modify more bits than"
5618 : : " the width of a field");
5619 [ # # ]: 0 : if (dst_data->field != RTE_FLOW_FIELD_VALUE &&
5620 : : dst_data->field != RTE_FLOW_FIELD_POINTER) {
5621 [ # # ]: 0 : if (dst_data->offset + width > dst_width)
5622 : 0 : return rte_flow_error_set(error, EINVAL,
5623 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5624 : : "destination offset is too big");
5625 : 0 : ret = flow_validate_modify_field_level(dst_data, error);
5626 [ # # ]: 0 : if (ret)
5627 : : return ret;
5628 [ # # ]: 0 : if (dst_data->tag_index &&
5629 [ # # ]: 0 : !flow_modify_field_support_tag_array(dst_data->field))
5630 : 0 : return rte_flow_error_set(error, EINVAL,
5631 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5632 : : "destination tag index is not supported");
5633 [ # # ]: 0 : if (dst_data->class_id)
5634 : 0 : return rte_flow_error_set(error, EINVAL,
5635 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5636 : : "destination class ID is not supported");
5637 : : }
5638 [ # # ]: 0 : if (src_data->field != RTE_FLOW_FIELD_VALUE &&
5639 : : src_data->field != RTE_FLOW_FIELD_POINTER) {
5640 [ # # ]: 0 : if (root)
5641 : 0 : return rte_flow_error_set(error, ENOTSUP,
5642 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5643 : : "modify field action is not"
5644 : : " supported for group 0");
5645 [ # # ]: 0 : if (src_data->offset + width > src_width)
5646 : 0 : return rte_flow_error_set(error, EINVAL,
5647 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5648 : : "source offset is too big");
5649 : 0 : ret = flow_validate_modify_field_level(src_data, error);
5650 [ # # ]: 0 : if (ret)
5651 : : return ret;
5652 [ # # ]: 0 : if (src_data->tag_index &&
5653 [ # # ]: 0 : !flow_modify_field_support_tag_array(src_data->field))
5654 : 0 : return rte_flow_error_set(error, EINVAL,
5655 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5656 : : "source tag index is not supported");
5657 [ # # ]: 0 : if (src_data->class_id)
5658 : 0 : return rte_flow_error_set(error, EINVAL,
5659 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5660 : : "source class ID is not supported");
5661 : : }
5662 [ # # ]: 0 : if ((dst_data->field == src_data->field) &&
5663 [ # # ]: 0 : (dst_data->level == src_data->level))
5664 : 0 : return rte_flow_error_set(error, EINVAL,
5665 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5666 : : "source and destination fields"
5667 : : " cannot be the same");
5668 : 0 : if (dst_data->field == RTE_FLOW_FIELD_VALUE ||
5669 [ # # ]: 0 : dst_data->field == RTE_FLOW_FIELD_POINTER ||
5670 : : dst_data->field == RTE_FLOW_FIELD_MARK)
5671 : 0 : return rte_flow_error_set(error, EINVAL,
5672 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5673 : : "mark, immediate value or a pointer to it"
5674 : : " cannot be used as a destination");
5675 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_START ||
5676 : : src_data->field == RTE_FLOW_FIELD_START)
5677 : 0 : return rte_flow_error_set(error, ENOTSUP,
5678 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5679 : : "modifications of an arbitrary"
5680 : : " place in a packet is not supported");
5681 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_VLAN_TYPE ||
5682 : : src_data->field == RTE_FLOW_FIELD_VLAN_TYPE)
5683 : 0 : return rte_flow_error_set(error, ENOTSUP,
5684 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5685 : : "modifications of the 802.1Q Tag"
5686 : : " Identifier is not supported");
5687 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_VXLAN_VNI ||
5688 : : src_data->field == RTE_FLOW_FIELD_VXLAN_VNI)
5689 : 0 : return rte_flow_error_set(error, ENOTSUP,
5690 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5691 : : "modifications of the VXLAN Network"
5692 : : " Identifier is not supported");
5693 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_GENEVE_VNI ||
5694 : : src_data->field == RTE_FLOW_FIELD_GENEVE_VNI)
5695 : 0 : return rte_flow_error_set(error, ENOTSUP,
5696 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5697 : : "modifications of the GENEVE Network"
5698 : : " Identifier is not supported");
5699 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_GENEVE_OPT_TYPE ||
5700 : : src_data->field == RTE_FLOW_FIELD_GENEVE_OPT_TYPE)
5701 : 0 : return rte_flow_error_set(error, ENOTSUP,
5702 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5703 : : "modifications of the GENEVE option type is not supported");
5704 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_GENEVE_OPT_CLASS ||
5705 : : src_data->field == RTE_FLOW_FIELD_GENEVE_OPT_CLASS)
5706 : 0 : return rte_flow_error_set(error, ENOTSUP,
5707 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5708 : : "modifications of the GENEVE option class is not supported");
5709 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_GENEVE_OPT_DATA ||
5710 : : src_data->field == RTE_FLOW_FIELD_GENEVE_OPT_DATA)
5711 : 0 : return rte_flow_error_set(error, ENOTSUP,
5712 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5713 : : "modifications of the GENEVE option data is not supported");
5714 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_MPLS ||
5715 : : src_data->field == RTE_FLOW_FIELD_MPLS)
5716 : 0 : return rte_flow_error_set(error, ENOTSUP,
5717 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5718 : : "modifications of the MPLS header "
5719 : : "is not supported");
5720 [ # # # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_RANDOM ||
5721 : : src_data->field == RTE_FLOW_FIELD_RANDOM)
5722 : 0 : return rte_flow_error_set(error, ENOTSUP,
5723 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5724 : : "modifications of random value is not supported");
5725 [ # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_MARK ||
5726 : : src_data->field == RTE_FLOW_FIELD_MARK)
5727 [ # # # # ]: 0 : if (config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
5728 : 0 : !mlx5_flow_ext_mreg_supported(dev))
5729 : 0 : return rte_flow_error_set(error, ENOTSUP,
5730 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5731 : : "cannot modify mark in legacy mode"
5732 : : " or without extensive registers");
5733 [ # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_META ||
5734 [ # # ]: 0 : src_data->field == RTE_FLOW_FIELD_META) {
5735 [ # # # # ]: 0 : if (config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
5736 : 0 : !mlx5_flow_ext_mreg_supported(dev))
5737 : 0 : return rte_flow_error_set(error, ENOTSUP,
5738 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5739 : : "cannot modify meta without"
5740 : : " extensive registers support");
5741 : 0 : ret = flow_dv_get_metadata_reg(dev, attr, error);
5742 [ # # ]: 0 : if (ret < 0 || ret == REG_NON)
5743 : 0 : return rte_flow_error_set(error, ENOTSUP,
5744 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5745 : : "cannot modify meta without"
5746 : : " extensive registers available");
5747 : : }
5748 [ # # ]: 0 : if (conf->operation == RTE_FLOW_MODIFY_SUB)
5749 : 0 : return rte_flow_error_set(error, ENOTSUP,
5750 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5751 : : "sub operations are not supported");
5752 [ # # ]: 0 : if (dst_data->field == RTE_FLOW_FIELD_IPV4_ECN ||
5753 [ # # # # ]: 0 : src_data->field == RTE_FLOW_FIELD_IPV4_ECN ||
5754 [ # # ]: 0 : dst_data->field == RTE_FLOW_FIELD_IPV6_ECN ||
5755 : : src_data->field == RTE_FLOW_FIELD_IPV6_ECN)
5756 [ # # # # ]: 0 : if (!hca_attr->modify_outer_ip_ecn && root)
5757 : 0 : return rte_flow_error_set(error, ENOTSUP,
5758 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5759 : : "modifications of the ECN for current firmware is not supported");
5760 : 0 : return (width / 32) + !!(width % 32);
5761 : : }
5762 : :
5763 : : /**
5764 : : * Validate jump action.
5765 : : *
5766 : : * @param[in] action
5767 : : * Pointer to the jump action.
5768 : : * @param[in] action_flags
5769 : : * Holds the actions detected until now.
5770 : : * @param[in] attributes
5771 : : * Pointer to flow attributes
5772 : : * @param[in] external
5773 : : * Action belongs to flow rule created by request external to PMD.
5774 : : * @param[out] error
5775 : : * Pointer to error structure.
5776 : : *
5777 : : * @return
5778 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5779 : : */
5780 : : static int
5781 : 0 : flow_dv_validate_action_jump(struct rte_eth_dev *dev,
5782 : : const struct mlx5_flow_tunnel *tunnel,
5783 : : const struct rte_flow_action *action,
5784 : : uint64_t action_flags,
5785 : : const struct rte_flow_attr *attributes,
5786 : : bool external, struct rte_flow_error *error)
5787 : : {
5788 : 0 : uint32_t target_group, table = 0;
5789 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5790 : : int ret = 0;
5791 : 0 : struct flow_grp_info grp_info = {
5792 : : .external = !!external,
5793 : 0 : .transfer = !!attributes->transfer,
5794 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
5795 : : .std_tbl_fix = 0
5796 : : };
5797 [ # # ]: 0 : if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
5798 : : MLX5_FLOW_FATE_ESWITCH_ACTIONS))
5799 : 0 : return rte_flow_error_set(error, EINVAL,
5800 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5801 : : "can't have 2 fate actions in"
5802 : : " same flow");
5803 [ # # ]: 0 : if (!action->conf)
5804 : 0 : return rte_flow_error_set(error, EINVAL,
5805 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5806 : : NULL, "action configuration not set");
5807 : 0 : target_group =
5808 : : ((const struct rte_flow_action_jump *)action->conf)->group;
5809 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel, target_group, &table,
5810 : : &grp_info, error);
5811 [ # # ]: 0 : if (ret)
5812 : : return ret;
5813 [ # # ]: 0 : if (table == 0)
5814 : 0 : return rte_flow_error_set(error, EINVAL,
5815 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5816 : : NULL, "root table shouldn't be destination");
5817 : : return 0;
5818 : : }
5819 : :
5820 : : /*
5821 : : * Validate action PORT_ID / REPRESENTED_PORT.
5822 : : *
5823 : : * @param[in] dev
5824 : : * Pointer to rte_eth_dev structure.
5825 : : * @param[in] action_flags
5826 : : * Bit-fields that holds the actions detected until now.
5827 : : * @param[in] action
5828 : : * PORT_ID / REPRESENTED_PORT action structure.
5829 : : * @param[in] attr
5830 : : * Attributes of flow that includes this action.
5831 : : * @param[out] error
5832 : : * Pointer to error structure.
5833 : : *
5834 : : * @return
5835 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5836 : : */
5837 : : static int
5838 : 0 : flow_dv_validate_action_port_id(struct rte_eth_dev *dev,
5839 : : uint64_t action_flags,
5840 : : const struct rte_flow_action *action,
5841 : : const struct rte_flow_attr *attr,
5842 : : struct rte_flow_error *error)
5843 : : {
5844 : : const struct rte_flow_action_port_id *port_id;
5845 : : const struct rte_flow_action_ethdev *ethdev;
5846 : : struct mlx5_priv *act_priv;
5847 : : struct mlx5_priv *dev_priv;
5848 : : uint16_t port;
5849 : :
5850 [ # # ]: 0 : if (!attr->transfer)
5851 : 0 : return rte_flow_error_set(error, ENOTSUP,
5852 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5853 : : NULL,
5854 : : "port action is valid in transfer"
5855 : : " mode only");
5856 [ # # # # ]: 0 : if (!action || !action->conf)
5857 : 0 : return rte_flow_error_set(error, ENOTSUP,
5858 : : RTE_FLOW_ERROR_TYPE_ACTION_CONF,
5859 : : NULL,
5860 : : "port action parameters must be"
5861 : : " specified");
5862 [ # # ]: 0 : if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
5863 : : MLX5_FLOW_FATE_ESWITCH_ACTIONS))
5864 : 0 : return rte_flow_error_set(error, EINVAL,
5865 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5866 : : "can have only one fate actions in"
5867 : : " a flow");
5868 : 0 : dev_priv = mlx5_dev_to_eswitch_info(dev);
5869 [ # # ]: 0 : if (!dev_priv)
5870 : 0 : return rte_flow_error_set(error, rte_errno,
5871 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5872 : : NULL,
5873 : : "failed to obtain E-Switch info");
5874 [ # # # ]: 0 : switch (action->type) {
5875 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
5876 : 0 : port_id = action->conf;
5877 [ # # ]: 0 : port = port_id->original ? dev->data->port_id : port_id->id;
5878 : : break;
5879 : 0 : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
5880 : 0 : ethdev = action->conf;
5881 : 0 : port = ethdev->port_id;
5882 : 0 : break;
5883 : 0 : default:
5884 : : MLX5_ASSERT(false);
5885 : 0 : return rte_flow_error_set
5886 : : (error, EINVAL,
5887 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
5888 : : "unknown E-Switch action");
5889 : : }
5890 : 0 : act_priv = mlx5_port_to_eswitch_info(port, false);
5891 [ # # ]: 0 : if (!act_priv)
5892 : 0 : return rte_flow_error_set
5893 : : (error, rte_errno,
5894 : 0 : RTE_FLOW_ERROR_TYPE_ACTION_CONF, action->conf,
5895 : : "failed to obtain E-Switch port id for port");
5896 [ # # ]: 0 : if (act_priv->domain_id != dev_priv->domain_id)
5897 : 0 : return rte_flow_error_set
5898 : : (error, EINVAL,
5899 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5900 : : "port does not belong to"
5901 : : " E-Switch being configured");
5902 : : return 0;
5903 : : }
5904 : :
5905 : : /**
5906 : : * Get the maximum number of modify header actions.
5907 : : *
5908 : : * @param dev
5909 : : * Pointer to rte_eth_dev structure.
5910 : : * @param root
5911 : : * Whether action is on root table.
5912 : : *
5913 : : * @return
5914 : : * Max number of modify header actions device can support.
5915 : : */
5916 : : static inline unsigned int
5917 : : flow_dv_modify_hdr_action_max(struct rte_eth_dev *dev __rte_unused,
5918 : : bool root)
5919 : : {
5920 : : /*
5921 : : * There's no way to directly query the max capacity from FW.
5922 : : * The maximal value on root table should be assumed to be supported.
5923 : : */
5924 [ # # ]: 0 : if (!root)
5925 : : return MLX5_MAX_MODIFY_NUM;
5926 : : else
5927 : 0 : return MLX5_ROOT_TBL_MODIFY_NUM;
5928 : : }
5929 : :
5930 : : /**
5931 : : * Validate the meter action.
5932 : : *
5933 : : * @param[in] dev
5934 : : * Pointer to rte_eth_dev structure.
5935 : : * @param[in] action_flags
5936 : : * Bit-fields that holds the actions detected until now.
5937 : : * @param[in] item_flags
5938 : : * Holds the items detected.
5939 : : * @param[in] action
5940 : : * Pointer to the meter action.
5941 : : * @param[in] attr
5942 : : * Attributes of flow that includes this action.
5943 : : * @param[in] port_id_item
5944 : : * Pointer to item indicating port id.
5945 : : * @param[out] error
5946 : : * Pointer to error structure.
5947 : : *
5948 : : * @return
5949 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
5950 : : */
5951 : : static int
5952 : 0 : mlx5_flow_validate_action_meter(struct rte_eth_dev *dev,
5953 : : uint64_t action_flags, uint64_t item_flags,
5954 : : const struct rte_flow_action *action,
5955 : : const struct rte_flow_attr *attr,
5956 : : const struct rte_flow_item *port_id_item,
5957 : : bool *def_policy,
5958 : : struct rte_flow_error *error)
5959 : : {
5960 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
5961 : 0 : const struct rte_flow_action_meter *am = action->conf;
5962 : : struct mlx5_flow_meter_info *fm;
5963 : : struct mlx5_flow_meter_policy *mtr_policy;
5964 : 0 : struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
5965 : 0 : uint16_t flow_src_port = priv->representor_id;
5966 : 0 : bool all_ports = false;
5967 : :
5968 [ # # ]: 0 : if (!am)
5969 : 0 : return rte_flow_error_set(error, EINVAL,
5970 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5971 : : "meter action conf is NULL");
5972 : :
5973 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_METER)
5974 : 0 : return rte_flow_error_set(error, ENOTSUP,
5975 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5976 : : "meter chaining not support");
5977 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_JUMP)
5978 : 0 : return rte_flow_error_set(error, ENOTSUP,
5979 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5980 : : "meter with jump not support");
5981 [ # # ]: 0 : if (!priv->mtr_en)
5982 : 0 : return rte_flow_error_set(error, ENOTSUP,
5983 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
5984 : : NULL,
5985 : : "meter action not supported");
5986 : 0 : fm = mlx5_flow_meter_find(priv, am->mtr_id, NULL);
5987 [ # # ]: 0 : if (!fm)
5988 : 0 : return rte_flow_error_set(error, EINVAL,
5989 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5990 : : "Meter not found");
5991 : : /* aso meter can always be shared by different domains */
5992 [ # # # # ]: 0 : if (fm->ref_cnt && !priv->sh->meter_aso_en &&
5993 [ # # ]: 0 : !(fm->transfer == attr->transfer ||
5994 [ # # # # ]: 0 : (!fm->ingress && !attr->ingress && attr->egress) ||
5995 [ # # # # ]: 0 : (!fm->egress && !attr->egress && attr->ingress)))
5996 : 0 : return rte_flow_error_set(error, EINVAL,
5997 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
5998 : : "Flow attributes domain are either invalid "
5999 : : "or have a domain conflict with current "
6000 : : "meter attributes");
6001 [ # # ]: 0 : if (fm->def_policy) {
6002 [ # # ]: 0 : if (!((attr->transfer &&
6003 [ # # ]: 0 : mtrmng->def_policy[MLX5_MTR_DOMAIN_TRANSFER]) ||
6004 [ # # ]: 0 : (attr->egress &&
6005 [ # # ]: 0 : mtrmng->def_policy[MLX5_MTR_DOMAIN_EGRESS]) ||
6006 [ # # ]: 0 : (attr->ingress &&
6007 [ # # ]: 0 : mtrmng->def_policy[MLX5_MTR_DOMAIN_INGRESS])))
6008 : 0 : return rte_flow_error_set(error, EINVAL,
6009 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6010 : : "Flow attributes domain "
6011 : : "have a conflict with current "
6012 : : "meter domain attributes");
6013 : 0 : *def_policy = true;
6014 : : } else {
6015 : 0 : mtr_policy = mlx5_flow_meter_policy_find(dev,
6016 : : fm->policy_id, NULL);
6017 [ # # ]: 0 : if (!mtr_policy)
6018 : 0 : return rte_flow_error_set(error, EINVAL,
6019 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6020 : : "Invalid policy id for meter ");
6021 [ # # # # ]: 0 : if (!((attr->transfer && mtr_policy->transfer) ||
6022 [ # # # # ]: 0 : (attr->egress && mtr_policy->egress) ||
6023 [ # # # # ]: 0 : (attr->ingress && mtr_policy->ingress)))
6024 : 0 : return rte_flow_error_set(error, EINVAL,
6025 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6026 : : "Flow attributes domain "
6027 : : "have a conflict with current "
6028 : : "meter domain attributes");
6029 [ # # ]: 0 : if (port_id_item) {
6030 [ # # ]: 0 : if (mlx5_flow_get_item_vport_id(dev, port_id_item, &flow_src_port,
6031 : : &all_ports, error))
6032 : 0 : return -rte_errno;
6033 : : }
6034 [ # # ]: 0 : if (attr->transfer) {
6035 : : /* When flow matching all src ports, meter should not have drop count. */
6036 [ # # # # : 0 : if (all_ports && (fm->drop_cnt || mtr_policy->hierarchy_match_port))
# # ]
6037 : 0 : return rte_flow_error_set(error, EINVAL,
6038 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC, NULL,
6039 : : "Meter drop count or "
6040 : : "modify_field/set_tag in meter hierarchy "
6041 : : "not supported when matching all ports.");
6042 [ # # ]: 0 : } else if (mtr_policy->is_rss) {
6043 : : struct mlx5_flow_meter_policy *fp;
6044 : : struct mlx5_meter_policy_action_container *acg;
6045 : : struct mlx5_meter_policy_action_container *acy;
6046 : : const struct rte_flow_action *rss_act;
6047 : : int ret;
6048 : :
6049 : 0 : fp = mlx5_flow_meter_hierarchy_get_final_policy(dev,
6050 : : mtr_policy);
6051 [ # # ]: 0 : if (fp == NULL)
6052 : 0 : return rte_flow_error_set(error, EINVAL,
6053 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6054 : : "Unable to get the final "
6055 : : "policy in the hierarchy");
6056 : : acg = &fp->act_cnt[RTE_COLOR_GREEN];
6057 : : acy = &fp->act_cnt[RTE_COLOR_YELLOW];
6058 : : MLX5_ASSERT(acg->fate_action ==
6059 : : MLX5_FLOW_FATE_SHARED_RSS ||
6060 : : acy->fate_action ==
6061 : : MLX5_FLOW_FATE_SHARED_RSS);
6062 [ # # ]: 0 : if (acg->fate_action == MLX5_FLOW_FATE_SHARED_RSS)
6063 : 0 : rss_act = acg->rss;
6064 : : else
6065 : 0 : rss_act = acy->rss;
6066 : 0 : ret = mlx5_flow_validate_action_rss(rss_act,
6067 : : action_flags, dev, attr,
6068 : : item_flags, error);
6069 [ # # ]: 0 : if (ret)
6070 : : return ret;
6071 : : }
6072 : 0 : *def_policy = false;
6073 : : }
6074 : : return 0;
6075 : : }
6076 : :
6077 : : /**
6078 : : * Validate the age action.
6079 : : *
6080 : : * @param[in] action_flags
6081 : : * Holds the actions detected until now.
6082 : : * @param[in] action
6083 : : * Pointer to the age action.
6084 : : * @param[in] dev
6085 : : * Pointer to the Ethernet device structure.
6086 : : * @param[out] error
6087 : : * Pointer to error structure.
6088 : : *
6089 : : * @return
6090 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
6091 : : */
6092 : : static int
6093 : 0 : flow_dv_validate_action_age(uint64_t action_flags,
6094 : : const struct rte_flow_action *action,
6095 : : struct rte_eth_dev *dev,
6096 : : struct rte_flow_error *error)
6097 : : {
6098 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6099 : 0 : const struct rte_flow_action_age *age = action->conf;
6100 : :
6101 [ # # ]: 0 : if (!priv->sh->cdev->config.devx ||
6102 [ # # # # ]: 0 : (priv->sh->sws_cmng.counter_fallback && !priv->sh->aso_age_mng))
6103 : 0 : return rte_flow_error_set(error, ENOTSUP,
6104 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6105 : : NULL,
6106 : : "age action not supported");
6107 [ # # ]: 0 : if (!(action->conf))
6108 : 0 : return rte_flow_error_set(error, EINVAL,
6109 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6110 : : "configuration cannot be null");
6111 [ # # ]: 0 : if (!(age->timeout))
6112 : 0 : return rte_flow_error_set(error, EINVAL,
6113 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6114 : : "invalid timeout value 0");
6115 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_AGE)
6116 : 0 : return rte_flow_error_set(error, EINVAL,
6117 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6118 : : "duplicate age actions set");
6119 : : return 0;
6120 : : }
6121 : :
6122 : : /**
6123 : : * Validate the modify-header IPv4 DSCP actions.
6124 : : *
6125 : : * @param[in] action_flags
6126 : : * Holds the actions detected until now.
6127 : : * @param[in] action
6128 : : * Pointer to the modify action.
6129 : : * @param[in] item_flags
6130 : : * Holds the items detected.
6131 : : * @param[out] error
6132 : : * Pointer to error structure.
6133 : : *
6134 : : * @return
6135 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
6136 : : */
6137 : : static int
6138 : 0 : flow_dv_validate_action_modify_ipv4_dscp(const uint64_t action_flags,
6139 : : const struct rte_flow_action *action,
6140 : : const uint64_t item_flags,
6141 : : struct rte_flow_error *error)
6142 : : {
6143 : : int ret = 0;
6144 : :
6145 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
6146 [ # # ]: 0 : if (!ret) {
6147 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV4))
6148 : 0 : return rte_flow_error_set(error, EINVAL,
6149 : : RTE_FLOW_ERROR_TYPE_ACTION,
6150 : : NULL,
6151 : : "no ipv4 item in pattern");
6152 : : }
6153 : : return ret;
6154 : : }
6155 : :
6156 : : /**
6157 : : * Validate the modify-header IPv6 DSCP actions.
6158 : : *
6159 : : * @param[in] action_flags
6160 : : * Holds the actions detected until now.
6161 : : * @param[in] action
6162 : : * Pointer to the modify action.
6163 : : * @param[in] item_flags
6164 : : * Holds the items detected.
6165 : : * @param[out] error
6166 : : * Pointer to error structure.
6167 : : *
6168 : : * @return
6169 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
6170 : : */
6171 : : static int
6172 : 0 : flow_dv_validate_action_modify_ipv6_dscp(const uint64_t action_flags,
6173 : : const struct rte_flow_action *action,
6174 : : const uint64_t item_flags,
6175 : : struct rte_flow_error *error)
6176 : : {
6177 : : int ret = 0;
6178 : :
6179 : 0 : ret = flow_dv_validate_action_modify_hdr(action_flags, action, error);
6180 [ # # ]: 0 : if (!ret) {
6181 [ # # ]: 0 : if (!(item_flags & MLX5_FLOW_LAYER_L3_IPV6))
6182 : 0 : return rte_flow_error_set(error, EINVAL,
6183 : : RTE_FLOW_ERROR_TYPE_ACTION,
6184 : : NULL,
6185 : : "no ipv6 item in pattern");
6186 : : }
6187 : : return ret;
6188 : : }
6189 : :
6190 : : int
6191 : 0 : flow_modify_match_cb(void *tool_ctx __rte_unused,
6192 : : struct mlx5_list_entry *entry, void *cb_ctx)
6193 : : {
6194 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
6195 : 0 : struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
6196 : : struct mlx5_flow_dv_modify_hdr_resource *resource =
6197 : : container_of(entry, typeof(*resource), entry);
6198 : : uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type);
6199 : :
6200 : 0 : key_len += ref->actions_num * sizeof(ref->actions[0]);
6201 [ # # ]: 0 : return ref->actions_num != resource->actions_num ||
6202 [ # # ]: 0 : memcmp(&ref->ft_type, &resource->ft_type, key_len);
6203 : : }
6204 : :
6205 : : static struct mlx5_indexed_pool *
6206 : 0 : flow_dv_modify_ipool_get(struct mlx5_dev_ctx_shared *sh, uint8_t index)
6207 : : {
6208 : 0 : struct mlx5_indexed_pool *ipool = rte_atomic_load_explicit
6209 : : (&sh->mdh_ipools[index], rte_memory_order_seq_cst);
6210 : :
6211 [ # # ]: 0 : if (!ipool) {
6212 : : struct mlx5_indexed_pool *expected = NULL;
6213 : 0 : struct mlx5_indexed_pool_config cfg =
6214 : : (struct mlx5_indexed_pool_config) {
6215 : 0 : .size = sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
6216 : 0 : (index + 1) *
6217 : : sizeof(struct mlx5_modification_cmd),
6218 : : .trunk_size = 64,
6219 : : .grow_trunk = 3,
6220 : : .grow_shift = 2,
6221 : : .need_lock = 1,
6222 : 0 : .release_mem_en = !!sh->config.reclaim_mode,
6223 : : .per_core_cache =
6224 [ # # ]: 0 : sh->config.reclaim_mode ? 0 : (1 << 16),
6225 : : .malloc = mlx5_malloc,
6226 : : .free = mlx5_free,
6227 : : .type = "mlx5_modify_action_resource",
6228 : : };
6229 : :
6230 : 0 : cfg.size = RTE_ALIGN(cfg.size, sizeof(ipool));
6231 : 0 : ipool = mlx5_ipool_create(&cfg);
6232 [ # # ]: 0 : if (!ipool)
6233 : 0 : return NULL;
6234 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(&sh->mdh_ipools[index],
6235 : : &expected, ipool,
6236 : : rte_memory_order_seq_cst,
6237 : : rte_memory_order_seq_cst)) {
6238 : 0 : mlx5_ipool_destroy(ipool);
6239 : 0 : ipool = rte_atomic_load_explicit(&sh->mdh_ipools[index],
6240 : : rte_memory_order_seq_cst);
6241 : : }
6242 : : }
6243 : : return ipool;
6244 : : }
6245 : :
6246 : : struct mlx5_list_entry *
6247 : 0 : flow_modify_create_cb(void *tool_ctx, void *cb_ctx)
6248 : : {
6249 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
6250 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
6251 : : struct mlx5dv_dr_domain *ns;
6252 : : struct mlx5_flow_dv_modify_hdr_resource *entry;
6253 : 0 : struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
6254 : 0 : struct mlx5_indexed_pool *ipool = flow_dv_modify_ipool_get(sh,
6255 : 0 : ref->actions_num - 1);
6256 : : int ret = 0;
6257 : 0 : uint32_t data_len = ref->actions_num * sizeof(ref->actions[0]);
6258 : : uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type);
6259 : : uint32_t idx;
6260 : :
6261 [ # # ]: 0 : if (unlikely(!ipool)) {
6262 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
6263 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6264 : : NULL, "cannot allocate modify ipool");
6265 : 0 : return NULL;
6266 : : }
6267 : 0 : entry = mlx5_ipool_zmalloc(ipool, &idx);
6268 [ # # ]: 0 : if (!entry) {
6269 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
6270 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6271 : : "cannot allocate resource memory");
6272 : 0 : return NULL;
6273 : : }
6274 : 0 : rte_memcpy(&entry->ft_type,
6275 : 0 : RTE_PTR_ADD(ref, offsetof(typeof(*ref), ft_type)),
6276 [ # # ]: 0 : key_len + data_len);
6277 [ # # ]: 0 : if (sh->config.dv_flow_en == 2) {
6278 : : #ifdef HAVE_MLX5_HWS_SUPPORT
6279 : 0 : struct mlx5dr_action_mh_pattern pattern = {
6280 : : .sz = data_len,
6281 : 0 : .data = (__be64 *)ref->actions
6282 : : };
6283 : 0 : entry->action = mlx5dr_action_create_modify_header(ctx->data2,
6284 : : 1,
6285 : 0 : &pattern, 0, ref->flags);
6286 [ # # ]: 0 : if (!entry->action)
6287 : : ret = -1;
6288 : : #else
6289 : : ret = -1;
6290 : : #endif
6291 : : } else {
6292 [ # # ]: 0 : if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
6293 : 0 : ns = sh->fdb_domain;
6294 [ # # ]: 0 : else if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
6295 : 0 : ns = sh->tx_domain;
6296 : : else
6297 : 0 : ns = sh->rx_domain;
6298 : 0 : ret = mlx5_flow_os_create_flow_action_modify_header
6299 : 0 : (sh->cdev->ctx, ns, entry,
6300 : : data_len, &entry->action);
6301 : : }
6302 : : if (ret) {
6303 : 0 : mlx5_ipool_free(sh->mdh_ipools[ref->actions_num - 1], idx);
6304 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
6305 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6306 : : NULL, "cannot create modification action");
6307 : 0 : return NULL;
6308 : : }
6309 : 0 : entry->idx = idx;
6310 : 0 : return &entry->entry;
6311 : : }
6312 : :
6313 : : struct mlx5_list_entry *
6314 : 0 : flow_modify_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
6315 : : void *cb_ctx)
6316 : : {
6317 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
6318 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
6319 : : struct mlx5_flow_dv_modify_hdr_resource *entry;
6320 : 0 : struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data;
6321 : 0 : uint32_t data_len = ref->actions_num * sizeof(ref->actions[0]);
6322 : : uint32_t idx;
6323 : :
6324 : 0 : entry = mlx5_ipool_malloc(sh->mdh_ipools[ref->actions_num - 1],
6325 : : &idx);
6326 [ # # ]: 0 : if (!entry) {
6327 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
6328 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
6329 : : "cannot allocate resource memory");
6330 : 0 : return NULL;
6331 : : }
6332 : 0 : memcpy(entry, oentry, sizeof(*entry) + data_len);
6333 : 0 : entry->idx = idx;
6334 : 0 : return &entry->entry;
6335 : : }
6336 : :
6337 : : void
6338 : 0 : flow_modify_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
6339 : : {
6340 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
6341 : : struct mlx5_flow_dv_modify_hdr_resource *res =
6342 : : container_of(entry, typeof(*res), entry);
6343 : :
6344 : 0 : mlx5_ipool_free(sh->mdh_ipools[res->actions_num - 1], res->idx);
6345 : 0 : }
6346 : :
6347 : : /**
6348 : : * Validate the sample action.
6349 : : *
6350 : : * @param[in, out] action_flags
6351 : : * Holds the actions detected until now.
6352 : : * @param[in] action
6353 : : * Pointer to the sample action.
6354 : : * @param[in] dev
6355 : : * Pointer to the Ethernet device structure.
6356 : : * @param[in] attr
6357 : : * Attributes of flow that includes this action.
6358 : : * @param[in] item_flags
6359 : : * Holds the items detected.
6360 : : * @param[in] rss
6361 : : * Pointer to the RSS action.
6362 : : * @param[out] sample_rss
6363 : : * Pointer to the RSS action in sample action list.
6364 : : * @param[out] count
6365 : : * Pointer to the COUNT action in sample action list.
6366 : : * @param[out] fdb_mirror
6367 : : * Pointer to the FDB mirror flag.
6368 : : * @param root
6369 : : * Whether action is on root table.
6370 : : * @param[out] error
6371 : : * Pointer to error structure.
6372 : : *
6373 : : * @return
6374 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
6375 : : */
6376 : : static int
6377 : 0 : flow_dv_validate_action_sample(uint64_t *action_flags,
6378 : : uint64_t *sub_action_flags,
6379 : : const struct rte_flow_action *action,
6380 : : struct rte_eth_dev *dev,
6381 : : const struct rte_flow_attr *attr,
6382 : : uint64_t item_flags,
6383 : : const struct rte_flow_action_rss *rss,
6384 : : const struct rte_flow_action_rss **sample_rss,
6385 : : const struct rte_flow_action_count **count,
6386 : : int *fdb_mirror,
6387 : : uint16_t *sample_port_id,
6388 : : bool root,
6389 : : struct rte_flow_error *error)
6390 : : {
6391 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6392 : 0 : struct mlx5_sh_config *dev_conf = &priv->sh->config;
6393 : 0 : const struct rte_flow_action_sample *sample = action->conf;
6394 : : const struct rte_flow_action_port_id *port = NULL;
6395 : : const struct rte_flow_action *act;
6396 : : uint16_t queue_index = 0xFFFF;
6397 : 0 : int actions_n = 0;
6398 : : int ret;
6399 : :
6400 [ # # ]: 0 : if (!sample)
6401 : 0 : return rte_flow_error_set(error, EINVAL,
6402 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6403 : : "configuration cannot be NULL");
6404 [ # # ]: 0 : if (sample->ratio == 0)
6405 : 0 : return rte_flow_error_set(error, EINVAL,
6406 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6407 : : "ratio value starts from 1");
6408 [ # # ]: 0 : if (!priv->sh->cdev->config.devx ||
6409 [ # # ]: 0 : (sample->ratio > 0 && !priv->sampler_en))
6410 : 0 : return rte_flow_error_set(error, ENOTSUP,
6411 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
6412 : : NULL,
6413 : : "sample action not supported");
6414 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_SAMPLE)
6415 : 0 : return rte_flow_error_set(error, EINVAL,
6416 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6417 : : "Multiple sample actions not "
6418 : : "supported");
6419 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_METER)
6420 : 0 : return rte_flow_error_set(error, EINVAL,
6421 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6422 : : "wrong action order, meter should "
6423 : : "be after sample action");
6424 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_JUMP)
6425 : 0 : return rte_flow_error_set(error, EINVAL,
6426 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6427 : : "wrong action order, jump should "
6428 : : "be after sample action");
6429 [ # # ]: 0 : if (*action_flags & MLX5_FLOW_ACTION_CT)
6430 : 0 : return rte_flow_error_set(error, EINVAL,
6431 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
6432 : : "Sample after CT not supported");
6433 : 0 : act = sample->actions;
6434 [ # # ]: 0 : for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++) {
6435 [ # # ]: 0 : if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
6436 : 0 : return rte_flow_error_set(error, ENOTSUP,
6437 : : RTE_FLOW_ERROR_TYPE_ACTION,
6438 : : act, "too many actions");
6439 [ # # # # : 0 : switch (act->type) {
# # # # ]
6440 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
6441 : 0 : ret = mlx5_flow_validate_action_queue(act,
6442 : : *sub_action_flags,
6443 : : dev,
6444 : : attr, error);
6445 [ # # ]: 0 : if (ret < 0)
6446 : 0 : return ret;
6447 : 0 : queue_index = ((const struct rte_flow_action_queue *)
6448 : 0 : (act->conf))->index;
6449 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_QUEUE;
6450 : 0 : ++actions_n;
6451 : 0 : break;
6452 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
6453 : 0 : *sample_rss = act->conf;
6454 : 0 : ret = mlx5_flow_validate_action_rss(act,
6455 : : *sub_action_flags,
6456 : : dev, attr,
6457 : : item_flags,
6458 : : error);
6459 [ # # ]: 0 : if (ret < 0)
6460 : 0 : return ret;
6461 [ # # # # ]: 0 : if (rss && *sample_rss &&
6462 [ # # ]: 0 : ((*sample_rss)->level != rss->level ||
6463 [ # # ]: 0 : (*sample_rss)->types != rss->types))
6464 : 0 : return rte_flow_error_set(error, ENOTSUP,
6465 : : RTE_FLOW_ERROR_TYPE_ACTION,
6466 : : NULL,
6467 : : "Can't use the different RSS types "
6468 : : "or level in the same flow");
6469 [ # # # # ]: 0 : if (*sample_rss != NULL && (*sample_rss)->queue_num)
6470 : 0 : queue_index = (*sample_rss)->queue[0];
6471 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_RSS;
6472 : 0 : ++actions_n;
6473 : 0 : break;
6474 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
6475 : 0 : ret = flow_dv_validate_action_mark(dev, act,
6476 : : *sub_action_flags,
6477 : : attr, error);
6478 [ # # ]: 0 : if (ret < 0)
6479 : 0 : return ret;
6480 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY)
6481 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_MARK |
6482 : : MLX5_FLOW_ACTION_MARK_EXT;
6483 : : else
6484 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_MARK;
6485 : 0 : ++actions_n;
6486 : 0 : break;
6487 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
6488 : 0 : ret = flow_dv_validate_action_count
6489 : 0 : (dev, false, *action_flags | *sub_action_flags,
6490 : : root, error);
6491 [ # # ]: 0 : if (ret < 0)
6492 : 0 : return ret;
6493 : 0 : *count = act->conf;
6494 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_COUNT;
6495 : 0 : *action_flags |= MLX5_FLOW_ACTION_COUNT;
6496 : 0 : ++actions_n;
6497 : 0 : break;
6498 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
6499 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
6500 : 0 : ret = flow_dv_validate_action_port_id(dev,
6501 : : *sub_action_flags,
6502 : : act,
6503 : : attr,
6504 : : error);
6505 [ # # ]: 0 : if (ret)
6506 : 0 : return ret;
6507 [ # # ]: 0 : if (act->type == RTE_FLOW_ACTION_TYPE_PORT_ID) {
6508 : 0 : port = (const struct rte_flow_action_port_id *)
6509 : : act->conf;
6510 [ # # ]: 0 : *sample_port_id = port->original ?
6511 : 0 : dev->data->port_id : port->id;
6512 : : } else {
6513 : 0 : *sample_port_id = ((const struct rte_flow_action_ethdev *)
6514 : 0 : act->conf)->port_id;
6515 : : }
6516 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_PORT_ID;
6517 : 0 : ++actions_n;
6518 : 0 : break;
6519 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
6520 : 0 : ret = mlx5_flow_dv_validate_action_raw_encap_decap
6521 : 0 : (dev, NULL, act->conf, attr, sub_action_flags,
6522 : : &actions_n, action, item_flags, error);
6523 [ # # ]: 0 : if (ret < 0)
6524 : 0 : return ret;
6525 : 0 : ++actions_n;
6526 : 0 : break;
6527 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
6528 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
6529 : 0 : ret = mlx5_flow_dv_validate_action_l2_encap(dev,
6530 : : *sub_action_flags,
6531 : : act, attr,
6532 : : error);
6533 [ # # ]: 0 : if (ret < 0)
6534 : 0 : return ret;
6535 : 0 : *sub_action_flags |= MLX5_FLOW_ACTION_ENCAP;
6536 : 0 : ++actions_n;
6537 : 0 : break;
6538 : 0 : default:
6539 : 0 : return rte_flow_error_set(error, ENOTSUP,
6540 : : RTE_FLOW_ERROR_TYPE_ACTION,
6541 : : NULL,
6542 : : "Doesn't support optional "
6543 : : "action");
6544 : : }
6545 : : }
6546 [ # # ]: 0 : if (attr->ingress) {
6547 [ # # ]: 0 : if (!(*sub_action_flags & (MLX5_FLOW_ACTION_QUEUE |
6548 : : MLX5_FLOW_ACTION_RSS)))
6549 : 0 : return rte_flow_error_set(error, EINVAL,
6550 : : RTE_FLOW_ERROR_TYPE_ACTION,
6551 : : NULL,
6552 : : "Ingress must has a dest "
6553 : : "QUEUE for Sample");
6554 [ # # ]: 0 : } else if (attr->egress) {
6555 : 0 : return rte_flow_error_set(error, ENOTSUP,
6556 : : RTE_FLOW_ERROR_TYPE_ACTION,
6557 : : NULL,
6558 : : "Sample Only support Ingress "
6559 : : "or E-Switch");
6560 [ # # ]: 0 : } else if (sample->actions->type != RTE_FLOW_ACTION_TYPE_END) {
6561 : : MLX5_ASSERT(attr->transfer);
6562 [ # # ]: 0 : if (sample->ratio > 1)
6563 : 0 : return rte_flow_error_set(error, ENOTSUP,
6564 : : RTE_FLOW_ERROR_TYPE_ACTION,
6565 : : NULL,
6566 : : "E-Switch doesn't support "
6567 : : "any optional action "
6568 : : "for sampling");
6569 [ # # ]: 0 : if (*sub_action_flags & MLX5_FLOW_ACTION_QUEUE)
6570 : 0 : return rte_flow_error_set(error, ENOTSUP,
6571 : : RTE_FLOW_ERROR_TYPE_ACTION,
6572 : : NULL,
6573 : : "unsupported action QUEUE");
6574 [ # # ]: 0 : if (*sub_action_flags & MLX5_FLOW_ACTION_RSS)
6575 : 0 : return rte_flow_error_set(error, ENOTSUP,
6576 : : RTE_FLOW_ERROR_TYPE_ACTION,
6577 : : NULL,
6578 : : "unsupported action QUEUE");
6579 [ # # ]: 0 : if (!(*sub_action_flags & MLX5_FLOW_ACTION_PORT_ID))
6580 : 0 : return rte_flow_error_set(error, EINVAL,
6581 : : RTE_FLOW_ERROR_TYPE_ACTION,
6582 : : NULL,
6583 : : "E-Switch must has a dest "
6584 : : "port for mirroring");
6585 : 0 : *fdb_mirror = 1;
6586 : : }
6587 : : /* Continue validation for Xcap actions.*/
6588 [ # # # # ]: 0 : if ((*sub_action_flags & MLX5_FLOW_XCAP_ACTIONS) &&
6589 [ # # ]: 0 : (queue_index == 0xFFFF || !mlx5_rxq_is_hairpin(dev, queue_index))) {
6590 [ # # ]: 0 : if ((*sub_action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
6591 : : MLX5_FLOW_XCAP_ACTIONS)
6592 : 0 : return rte_flow_error_set(error, ENOTSUP,
6593 : : RTE_FLOW_ERROR_TYPE_ACTION,
6594 : : NULL, "encap and decap "
6595 : : "combination aren't "
6596 : : "supported");
6597 [ # # # # ]: 0 : if (attr->ingress && (*sub_action_flags & MLX5_FLOW_ACTION_ENCAP))
6598 : 0 : return rte_flow_error_set(error, ENOTSUP,
6599 : : RTE_FLOW_ERROR_TYPE_ACTION,
6600 : : NULL, "encap is not supported"
6601 : : " for ingress traffic");
6602 : : }
6603 : : return 0;
6604 : : }
6605 : :
6606 : : int
6607 : 0 : __flow_modify_hdr_resource_register(struct rte_eth_dev *dev,
6608 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
6609 : : struct mlx5_flow_dv_modify_hdr_resource **modify,
6610 : : struct rte_flow_error *error)
6611 : : {
6612 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6613 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
6614 : 0 : uint32_t key_len = sizeof(*resource) -
6615 : : offsetof(typeof(*resource), ft_type) +
6616 : 0 : resource->actions_num * sizeof(resource->actions[0]);
6617 : : struct mlx5_list_entry *entry;
6618 : 0 : struct mlx5_flow_cb_ctx ctx = {
6619 : : .error = error,
6620 : : .data = resource,
6621 : 0 : .data2 = priv->dr_ctx,
6622 : : };
6623 : : struct mlx5_hlist *modify_cmds;
6624 : : uint64_t key64;
6625 : :
6626 : 0 : modify_cmds = flow_dv_hlist_prepare(sh, &sh->modify_cmds,
6627 : : "hdr_modify",
6628 : : MLX5_FLOW_HDR_MODIFY_HTABLE_SZ,
6629 : : true, false, sh,
6630 : : flow_modify_create_cb,
6631 : : flow_modify_match_cb,
6632 : : flow_modify_remove_cb,
6633 : : flow_modify_clone_cb,
6634 : : flow_modify_clone_free_cb,
6635 : : error);
6636 [ # # ]: 0 : if (unlikely(!modify_cmds))
6637 : 0 : return -rte_errno;
6638 [ # # ]: 0 : if (resource->actions_num > flow_dv_modify_hdr_action_max(dev,
6639 [ # # ]: 0 : resource->root))
6640 : 0 : return rte_flow_error_set(error, EOVERFLOW,
6641 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
6642 : : "too many modify header items");
6643 : 0 : key64 = __rte_raw_cksum(&resource->ft_type, key_len, 0);
6644 : 0 : entry = mlx5_hlist_register(modify_cmds, key64, &ctx);
6645 [ # # ]: 0 : if (!entry)
6646 : 0 : return -rte_errno;
6647 : 0 : *modify = container_of(entry, typeof(*resource), entry);
6648 : 0 : return 0;
6649 : : }
6650 : :
6651 : : /**
6652 : : * Find existing modify-header resource or create and register a new one.
6653 : : *
6654 : : * @param dev[in, out]
6655 : : * Pointer to rte_eth_dev structure.
6656 : : * @param[in, out] resource
6657 : : * Pointer to modify-header resource.
6658 : : * @param[in, out] dev_flow
6659 : : * Pointer to the dev_flow.
6660 : : * @param[out] error
6661 : : * pointer to error structure.
6662 : : *
6663 : : * @return
6664 : : * 0 on success otherwise -errno and errno is set.
6665 : : */
6666 : : static int
6667 : : flow_dv_modify_hdr_resource_register
6668 : : (struct rte_eth_dev *dev,
6669 : : struct mlx5_flow_dv_modify_hdr_resource *resource,
6670 : : struct mlx5_flow *dev_flow,
6671 : : struct rte_flow_error *error)
6672 : : {
6673 : 0 : resource->root = !dev_flow->dv.group;
6674 : 0 : return __flow_modify_hdr_resource_register(dev, resource,
6675 : 0 : &dev_flow->handle->dvh.modify_hdr, error);
6676 : : }
6677 : :
6678 : : /**
6679 : : * Get DV flow counter by index.
6680 : : *
6681 : : * @param[in] dev
6682 : : * Pointer to the Ethernet device structure.
6683 : : * @param[in] idx
6684 : : * mlx5 flow counter index in the container.
6685 : : * @param[out] ppool
6686 : : * mlx5 flow counter pool in the container.
6687 : : *
6688 : : * @return
6689 : : * Pointer to the counter, NULL otherwise.
6690 : : */
6691 : : static struct mlx5_flow_counter *
6692 : : flow_dv_counter_get_by_idx(struct rte_eth_dev *dev,
6693 : : uint32_t idx,
6694 : : struct mlx5_flow_counter_pool **ppool)
6695 : : {
6696 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6697 : 0 : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
6698 : : struct mlx5_flow_counter_pool *pool;
6699 : :
6700 : : /* Decrease to original index and clear shared bit. */
6701 : 0 : idx = (idx - 1) & (MLX5_CNT_SHARED_OFFSET - 1);
6702 : : MLX5_ASSERT(idx / MLX5_COUNTERS_PER_POOL < MLX5_COUNTER_POOLS_MAX_NUM);
6703 : 0 : pool = cmng->pools[idx / MLX5_COUNTERS_PER_POOL];
6704 : : MLX5_ASSERT(pool);
6705 : : if (ppool)
6706 : : *ppool = pool;
6707 [ # # # # : 0 : return MLX5_POOL_GET_CNT(pool, idx % MLX5_COUNTERS_PER_POOL);
# # # # #
# # # ]
6708 : : }
6709 : :
6710 : : /**
6711 : : * Check the devx counter belongs to the pool.
6712 : : *
6713 : : * @param[in] pool
6714 : : * Pointer to the counter pool.
6715 : : * @param[in] id
6716 : : * The counter devx ID.
6717 : : *
6718 : : * @return
6719 : : * True if counter belongs to the pool, false otherwise.
6720 : : */
6721 : : static bool
6722 : : flow_dv_is_counter_in_pool(struct mlx5_flow_counter_pool *pool, int id)
6723 : : {
6724 : 0 : int base = (pool->min_dcs->id / MLX5_COUNTERS_PER_POOL) *
6725 : : MLX5_COUNTERS_PER_POOL;
6726 : :
6727 [ # # # # ]: 0 : if (id >= base && id < base + MLX5_COUNTERS_PER_POOL)
6728 : : return true;
6729 : : return false;
6730 : : }
6731 : :
6732 : : /**
6733 : : * Get a pool by devx counter ID.
6734 : : *
6735 : : * @param[in] cmng
6736 : : * Pointer to the counter management.
6737 : : * @param[in] id
6738 : : * The counter devx ID.
6739 : : *
6740 : : * @return
6741 : : * The counter pool pointer if exists, NULL otherwise,
6742 : : */
6743 : : static struct mlx5_flow_counter_pool *
6744 : 0 : flow_dv_find_pool_by_id(struct mlx5_flow_counter_mng *cmng, int id)
6745 : : {
6746 : : uint32_t i;
6747 : : struct mlx5_flow_counter_pool *pool = NULL;
6748 : :
6749 : 0 : rte_spinlock_lock(&cmng->pool_update_sl);
6750 : : /* Check last used pool. */
6751 [ # # ]: 0 : if (cmng->last_pool_idx != POOL_IDX_INVALID &&
6752 [ # # ]: 0 : flow_dv_is_counter_in_pool(cmng->pools[cmng->last_pool_idx], id)) {
6753 : : pool = cmng->pools[cmng->last_pool_idx];
6754 : 0 : goto out;
6755 : : }
6756 : : /* ID out of range means no suitable pool in the container. */
6757 [ # # # # ]: 0 : if (id > cmng->max_id || id < cmng->min_id)
6758 : 0 : goto out;
6759 : : /*
6760 : : * Find the pool from the end of the container, since mostly counter
6761 : : * ID is sequence increasing, and the last pool should be the needed
6762 : : * one.
6763 : : */
6764 : 0 : i = cmng->n_valid;
6765 [ # # ]: 0 : while (i--) {
6766 [ # # ]: 0 : struct mlx5_flow_counter_pool *pool_tmp = cmng->pools[i];
6767 : :
6768 : : if (flow_dv_is_counter_in_pool(pool_tmp, id)) {
6769 : : pool = pool_tmp;
6770 : : break;
6771 : : }
6772 : : }
6773 : 0 : out:
6774 : : rte_spinlock_unlock(&cmng->pool_update_sl);
6775 : 0 : return pool;
6776 : : }
6777 : :
6778 : : /**
6779 : : * Query a devx flow counter.
6780 : : *
6781 : : * @param[in] dev
6782 : : * Pointer to the Ethernet device structure.
6783 : : * @param[in] counter
6784 : : * Index to the flow counter.
6785 : : * @param[out] pkts
6786 : : * The statistics value of packets.
6787 : : * @param[out] bytes
6788 : : * The statistics value of bytes.
6789 : : *
6790 : : * @return
6791 : : * 0 on success, otherwise a negative errno value and rte_errno is set.
6792 : : */
6793 : : static inline int
6794 : 0 : _flow_dv_query_count(struct rte_eth_dev *dev, uint32_t counter, uint64_t *pkts,
6795 : : uint64_t *bytes)
6796 : : {
6797 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
6798 : : struct mlx5_flow_counter_pool *pool = NULL;
6799 : : struct mlx5_flow_counter *cnt;
6800 : : int offset;
6801 : :
6802 : : cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
6803 : : MLX5_ASSERT(pool);
6804 [ # # ]: 0 : if (priv->sh->sws_cmng.counter_fallback)
6805 : 0 : return mlx5_devx_cmd_flow_counter_query(cnt->dcs_when_active, 0,
6806 : : 0, pkts, bytes, 0, NULL, NULL, 0);
6807 : 0 : rte_spinlock_lock(&pool->sl);
6808 [ # # ]: 0 : if (!pool->raw) {
6809 : 0 : *pkts = 0;
6810 : 0 : *bytes = 0;
6811 : : } else {
6812 [ # # ]: 0 : offset = MLX5_CNT_ARRAY_IDX(pool, cnt);
6813 : 0 : *pkts = rte_be_to_cpu_64(pool->raw->data[offset].hits);
6814 : 0 : *bytes = rte_be_to_cpu_64(pool->raw->data[offset].bytes);
6815 : : }
6816 : : rte_spinlock_unlock(&pool->sl);
6817 : 0 : return 0;
6818 : : }
6819 : :
6820 : : /**
6821 : : * Create and initialize a new counter pool.
6822 : : *
6823 : : * @param[in] dev
6824 : : * Pointer to the Ethernet device structure.
6825 : : * @param[out] dcs
6826 : : * The devX counter handle.
6827 : : * @param[in] age
6828 : : * Whether the pool is for counter that was allocated for aging.
6829 : : *
6830 : : * @return
6831 : : * The pool container pointer on success, NULL otherwise and rte_errno is set.
6832 : : */
6833 : : static struct mlx5_flow_counter_pool *
6834 : 0 : flow_dv_pool_create(struct rte_eth_dev *dev, struct mlx5_devx_obj *dcs,
6835 : : uint32_t age)
6836 : : {
6837 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6838 : : struct mlx5_flow_counter_pool *pool;
6839 : 0 : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
6840 : 0 : bool fallback = cmng->counter_fallback;
6841 : : uint32_t size = sizeof(*pool);
6842 : :
6843 [ # # ]: 0 : if (cmng->n_valid == MLX5_COUNTER_POOLS_MAX_NUM) {
6844 : 0 : DRV_LOG(ERR, "All counter is in used, try again later.");
6845 : 0 : rte_errno = EAGAIN;
6846 : 0 : return NULL;
6847 : : }
6848 : : size += MLX5_COUNTERS_PER_POOL * MLX5_CNT_SIZE;
6849 [ # # ]: 0 : size += (!age ? 0 : MLX5_COUNTERS_PER_POOL * MLX5_AGE_SIZE);
6850 : 0 : pool = mlx5_malloc(MLX5_MEM_ZERO, size, 0, SOCKET_ID_ANY);
6851 [ # # ]: 0 : if (!pool) {
6852 : 0 : rte_errno = ENOMEM;
6853 : 0 : return NULL;
6854 : : }
6855 : 0 : pool->raw = NULL;
6856 : 0 : pool->is_aged = !!age;
6857 : 0 : pool->query_gen = 0;
6858 : 0 : pool->min_dcs = dcs;
6859 : : rte_spinlock_init(&pool->sl);
6860 : : rte_spinlock_init(&pool->csl);
6861 : 0 : TAILQ_INIT(&pool->counters[0]);
6862 : 0 : TAILQ_INIT(&pool->counters[1]);
6863 : 0 : pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
6864 : 0 : rte_spinlock_lock(&cmng->pool_update_sl);
6865 : 0 : pool->index = cmng->n_valid;
6866 : 0 : cmng->pools[pool->index] = pool;
6867 : 0 : cmng->n_valid++;
6868 [ # # ]: 0 : if (unlikely(fallback)) {
6869 : 0 : int base = RTE_ALIGN_FLOOR(dcs->id, MLX5_COUNTERS_PER_POOL);
6870 : :
6871 [ # # ]: 0 : if (base < cmng->min_id)
6872 : 0 : cmng->min_id = base;
6873 [ # # ]: 0 : if (base > cmng->max_id)
6874 : 0 : cmng->max_id = base + MLX5_COUNTERS_PER_POOL - 1;
6875 : 0 : cmng->last_pool_idx = pool->index;
6876 : : }
6877 : : rte_spinlock_unlock(&cmng->pool_update_sl);
6878 : 0 : return pool;
6879 : : }
6880 : :
6881 : : /**
6882 : : * Prepare a new counter and/or a new counter pool.
6883 : : *
6884 : : * @param[in] dev
6885 : : * Pointer to the Ethernet device structure.
6886 : : * @param[out] cnt_free
6887 : : * Where to put the pointer of a new counter.
6888 : : * @param[in] age
6889 : : * Whether the pool is for counter that was allocated for aging.
6890 : : *
6891 : : * @return
6892 : : * The counter pool pointer and @p cnt_free is set on success,
6893 : : * NULL otherwise and rte_errno is set.
6894 : : */
6895 : : static struct mlx5_flow_counter_pool *
6896 : 0 : flow_dv_counter_pool_prepare(struct rte_eth_dev *dev,
6897 : : struct mlx5_flow_counter **cnt_free,
6898 : : uint32_t age)
6899 : : {
6900 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6901 : 0 : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
6902 : : struct mlx5_flow_counter_pool *pool;
6903 : : struct mlx5_counters tmp_tq;
6904 : : struct mlx5_devx_obj *dcs = NULL;
6905 : : struct mlx5_flow_counter *cnt;
6906 : 0 : enum mlx5_counter_type cnt_type =
6907 : 0 : age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
6908 : 0 : bool fallback = priv->sh->sws_cmng.counter_fallback;
6909 : : uint32_t i;
6910 : :
6911 [ # # ]: 0 : if (fallback) {
6912 : : /* bulk_bitmap must be 0 for single counter allocation. */
6913 : 0 : dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0);
6914 [ # # ]: 0 : if (!dcs)
6915 : : return NULL;
6916 : 0 : pool = flow_dv_find_pool_by_id(cmng, dcs->id);
6917 [ # # ]: 0 : if (!pool) {
6918 : 0 : pool = flow_dv_pool_create(dev, dcs, age);
6919 [ # # ]: 0 : if (!pool) {
6920 : 0 : mlx5_devx_cmd_destroy(dcs);
6921 : 0 : return NULL;
6922 : : }
6923 : : }
6924 : 0 : i = dcs->id % MLX5_COUNTERS_PER_POOL;
6925 [ # # ]: 0 : cnt = MLX5_POOL_GET_CNT(pool, i);
6926 : 0 : cnt->pool = pool;
6927 : 0 : cnt->dcs_when_free = dcs;
6928 : 0 : *cnt_free = cnt;
6929 : 0 : return pool;
6930 : : }
6931 : 0 : dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0x4);
6932 [ # # ]: 0 : if (!dcs) {
6933 : 0 : rte_errno = ENODATA;
6934 : 0 : return NULL;
6935 : : }
6936 : 0 : pool = flow_dv_pool_create(dev, dcs, age);
6937 [ # # ]: 0 : if (!pool) {
6938 : 0 : mlx5_devx_cmd_destroy(dcs);
6939 : 0 : return NULL;
6940 : : }
6941 : 0 : TAILQ_INIT(&tmp_tq);
6942 [ # # ]: 0 : for (i = 1; i < MLX5_COUNTERS_PER_POOL; ++i) {
6943 [ # # ]: 0 : cnt = MLX5_POOL_GET_CNT(pool, i);
6944 : 0 : cnt->pool = pool;
6945 [ # # ]: 0 : TAILQ_INSERT_HEAD(&tmp_tq, cnt, next);
6946 : : }
6947 : 0 : rte_spinlock_lock(&cmng->csl[cnt_type]);
6948 [ # # ]: 0 : TAILQ_CONCAT(&cmng->counters[cnt_type], &tmp_tq, next);
6949 : : rte_spinlock_unlock(&cmng->csl[cnt_type]);
6950 : 0 : *cnt_free = MLX5_POOL_GET_CNT(pool, 0);
6951 : 0 : (*cnt_free)->pool = pool;
6952 : 0 : return pool;
6953 : : }
6954 : :
6955 : : /**
6956 : : * Allocate a flow counter.
6957 : : *
6958 : : * @param[in] dev
6959 : : * Pointer to the Ethernet device structure.
6960 : : * @param[in] age
6961 : : * Whether the counter was allocated for aging.
6962 : : *
6963 : : * @return
6964 : : * Index to flow counter on success, 0 otherwise and rte_errno is set.
6965 : : */
6966 : : static uint32_t
6967 : 0 : flow_dv_counter_alloc(struct rte_eth_dev *dev, uint32_t age)
6968 : : {
6969 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
6970 : : struct mlx5_flow_counter_pool *pool = NULL;
6971 : 0 : struct mlx5_flow_counter *cnt_free = NULL;
6972 : 0 : bool fallback = priv->sh->sws_cmng.counter_fallback;
6973 : : struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
6974 : 0 : enum mlx5_counter_type cnt_type =
6975 : 0 : age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN;
6976 : : uint32_t cnt_idx;
6977 : :
6978 [ # # ]: 0 : if (!priv->sh->cdev->config.devx) {
6979 : 0 : rte_errno = ENOTSUP;
6980 : 0 : return 0;
6981 : : }
6982 : : /* Get free counters from container. */
6983 : 0 : rte_spinlock_lock(&cmng->csl[cnt_type]);
6984 : 0 : cnt_free = TAILQ_FIRST(&cmng->counters[cnt_type]);
6985 [ # # ]: 0 : if (cnt_free)
6986 [ # # ]: 0 : TAILQ_REMOVE(&cmng->counters[cnt_type], cnt_free, next);
6987 : : rte_spinlock_unlock(&cmng->csl[cnt_type]);
6988 [ # # # # ]: 0 : if (!cnt_free && !flow_dv_counter_pool_prepare(dev, &cnt_free, age))
6989 : 0 : goto err;
6990 : 0 : pool = cnt_free->pool;
6991 [ # # ]: 0 : if (fallback)
6992 : 0 : cnt_free->dcs_when_active = cnt_free->dcs_when_free;
6993 : : /* Create a DV counter action only in the first time usage. */
6994 [ # # ]: 0 : if (!cnt_free->action) {
6995 : : uint16_t offset;
6996 : : struct mlx5_devx_obj *dcs;
6997 : : int ret;
6998 : :
6999 [ # # ]: 0 : if (!fallback) {
7000 [ # # ]: 0 : offset = MLX5_CNT_ARRAY_IDX(pool, cnt_free);
7001 : 0 : dcs = pool->min_dcs;
7002 : : } else {
7003 : : offset = 0;
7004 : 0 : dcs = cnt_free->dcs_when_free;
7005 : : }
7006 : 0 : ret = mlx5_flow_os_create_flow_action_count(dcs->obj, offset,
7007 : : &cnt_free->action);
7008 : : if (ret) {
7009 : 0 : rte_errno = errno;
7010 : 0 : goto err;
7011 : : }
7012 : : }
7013 [ # # ]: 0 : cnt_idx = MLX5_MAKE_CNT_IDX(pool->index,
7014 : : MLX5_CNT_ARRAY_IDX(pool, cnt_free));
7015 : : /* Update the counter reset values. */
7016 [ # # ]: 0 : if (_flow_dv_query_count(dev, cnt_idx, &cnt_free->hits,
7017 : : &cnt_free->bytes))
7018 : 0 : goto err;
7019 [ # # # # ]: 0 : if (!fallback && !priv->sh->sws_cmng.query_thread_on)
7020 : : /* Start the asynchronous batch query by the host thread. */
7021 : 0 : mlx5_set_query_alarm(priv->sh);
7022 : : /*
7023 : : * When the count action isn't shared (by ID), shared_info field is
7024 : : * used for indirect action API's refcnt.
7025 : : * When the counter action is not shared neither by ID nor by indirect
7026 : : * action API, shared info must be 1.
7027 : : */
7028 : 0 : cnt_free->shared_info.refcnt = 1;
7029 : 0 : return cnt_idx;
7030 : 0 : err:
7031 [ # # ]: 0 : if (cnt_free) {
7032 : 0 : cnt_free->pool = pool;
7033 [ # # ]: 0 : if (fallback)
7034 : 0 : cnt_free->dcs_when_free = cnt_free->dcs_when_active;
7035 : : rte_spinlock_lock(&cmng->csl[cnt_type]);
7036 : 0 : TAILQ_INSERT_TAIL(&cmng->counters[cnt_type], cnt_free, next);
7037 : : rte_spinlock_unlock(&cmng->csl[cnt_type]);
7038 : : }
7039 : : return 0;
7040 : : }
7041 : :
7042 : : /**
7043 : : * Get age param from counter index.
7044 : : *
7045 : : * @param[in] dev
7046 : : * Pointer to the Ethernet device structure.
7047 : : * @param[in] counter
7048 : : * Index to the counter handler.
7049 : : *
7050 : : * @return
7051 : : * The aging parameter specified for the counter index.
7052 : : */
7053 : : static struct mlx5_age_param*
7054 : : flow_dv_counter_idx_get_age(struct rte_eth_dev *dev,
7055 : : uint32_t counter)
7056 : : {
7057 : : struct mlx5_flow_counter *cnt;
7058 : : struct mlx5_flow_counter_pool *pool = NULL;
7059 : :
7060 : : flow_dv_counter_get_by_idx(dev, counter, &pool);
7061 : : counter = (counter - 1) % MLX5_COUNTERS_PER_POOL;
7062 : : cnt = MLX5_POOL_GET_CNT(pool, counter);
7063 : 0 : return MLX5_CNT_TO_AGE(cnt);
7064 : : }
7065 : :
7066 : : /**
7067 : : * Remove a flow counter from aged counter list.
7068 : : *
7069 : : * @param[in] dev
7070 : : * Pointer to the Ethernet device structure.
7071 : : * @param[in] counter
7072 : : * Index to the counter handler.
7073 : : * @param[in] cnt
7074 : : * Pointer to the counter handler.
7075 : : */
7076 : : static void
7077 : 0 : flow_dv_counter_remove_from_age(struct rte_eth_dev *dev,
7078 : : uint32_t counter, struct mlx5_flow_counter *cnt)
7079 : : {
7080 : : struct mlx5_age_info *age_info;
7081 : : struct mlx5_age_param *age_param;
7082 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7083 : : uint16_t expected = AGE_CANDIDATE;
7084 : :
7085 [ # # ]: 0 : age_info = GET_PORT_AGE_INFO(priv);
7086 : : age_param = flow_dv_counter_idx_get_age(dev, counter);
7087 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(&age_param->state, &expected,
7088 : : AGE_FREE, rte_memory_order_relaxed,
7089 : : rte_memory_order_relaxed)) {
7090 : : /**
7091 : : * We need the lock even it is age timeout,
7092 : : * since counter may still in process.
7093 : : */
7094 : 0 : rte_spinlock_lock(&age_info->aged_sl);
7095 [ # # ]: 0 : TAILQ_REMOVE(&age_info->aged_counters, cnt, next);
7096 : : rte_spinlock_unlock(&age_info->aged_sl);
7097 : 0 : rte_atomic_store_explicit(&age_param->state, AGE_FREE, rte_memory_order_relaxed);
7098 : : }
7099 : 0 : }
7100 : :
7101 : : /**
7102 : : * Release a flow counter.
7103 : : *
7104 : : * @param[in] dev
7105 : : * Pointer to the Ethernet device structure.
7106 : : * @param[in] counter
7107 : : * Index to the counter handler.
7108 : : */
7109 : : static void
7110 : 0 : flow_dv_counter_free(struct rte_eth_dev *dev, uint32_t counter)
7111 : : {
7112 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7113 : : struct mlx5_flow_counter_pool *pool = NULL;
7114 : : struct mlx5_flow_counter *cnt;
7115 : : enum mlx5_counter_type cnt_type;
7116 : :
7117 [ # # ]: 0 : if (!counter)
7118 : : return;
7119 : : cnt = flow_dv_counter_get_by_idx(dev, counter, &pool);
7120 : : MLX5_ASSERT(pool);
7121 [ # # ]: 0 : if (pool->is_aged) {
7122 : 0 : flow_dv_counter_remove_from_age(dev, counter, cnt);
7123 : : } else {
7124 : : /*
7125 : : * If the counter action is shared by indirect action API,
7126 : : * the atomic function reduces its references counter.
7127 : : * If after the reduction the action is still referenced, the
7128 : : * function returns here and does not release it.
7129 : : * When the counter action is not shared by
7130 : : * indirect action API, shared info is 1 before the reduction,
7131 : : * so this condition is failed and function doesn't return here.
7132 : : */
7133 [ # # ]: 0 : if (rte_atomic_fetch_sub_explicit(&cnt->shared_info.refcnt, 1,
7134 : : rte_memory_order_relaxed) - 1)
7135 : : return;
7136 : : }
7137 : 0 : cnt->pool = pool;
7138 : : /*
7139 : : * Put the counter back to list to be updated in none fallback mode.
7140 : : * Currently, we are using two list alternately, while one is in query,
7141 : : * add the freed counter to the other list based on the pool query_gen
7142 : : * value. After query finishes, add counter the list to the global
7143 : : * container counter list. The list changes while query starts. In
7144 : : * this case, lock will not be needed as query callback and release
7145 : : * function both operate with the different list.
7146 : : */
7147 [ # # ]: 0 : if (!priv->sh->sws_cmng.counter_fallback) {
7148 : 0 : rte_spinlock_lock(&pool->csl);
7149 : 0 : TAILQ_INSERT_TAIL(&pool->counters[pool->query_gen], cnt, next);
7150 : : rte_spinlock_unlock(&pool->csl);
7151 : : } else {
7152 : 0 : cnt->dcs_when_free = cnt->dcs_when_active;
7153 : 0 : cnt_type = pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
7154 : : MLX5_COUNTER_TYPE_ORIGIN;
7155 : 0 : rte_spinlock_lock(&priv->sh->sws_cmng.csl[cnt_type]);
7156 : 0 : TAILQ_INSERT_TAIL(&priv->sh->sws_cmng.counters[cnt_type],
7157 : : cnt, next);
7158 : 0 : rte_spinlock_unlock(&priv->sh->sws_cmng.csl[cnt_type]);
7159 : : }
7160 : : }
7161 : :
7162 : : /**
7163 : : * Resize a meter id container.
7164 : : *
7165 : : * @param[in] dev
7166 : : * Pointer to the Ethernet device structure.
7167 : : *
7168 : : * @return
7169 : : * 0 on success, otherwise negative errno value and rte_errno is set.
7170 : : */
7171 : : static int
7172 : 0 : flow_dv_mtr_container_resize(struct rte_eth_dev *dev)
7173 : : {
7174 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7175 : : struct mlx5_aso_mtr_pools_mng *pools_mng =
7176 : 0 : &priv->sh->mtrmng->pools_mng;
7177 : 0 : void *old_pools = pools_mng->pools;
7178 : 0 : uint32_t resize = pools_mng->n + MLX5_MTRS_CONTAINER_RESIZE;
7179 : 0 : uint32_t mem_size = sizeof(struct mlx5_aso_mtr_pool *) * resize;
7180 : 0 : void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
7181 : :
7182 [ # # ]: 0 : if (!pools) {
7183 : 0 : rte_errno = ENOMEM;
7184 : 0 : return -ENOMEM;
7185 : : }
7186 [ # # ]: 0 : if (!pools_mng->n)
7187 [ # # ]: 0 : if (mlx5_aso_queue_init(priv->sh, ASO_OPC_MOD_POLICER, 1)) {
7188 : 0 : mlx5_free(pools);
7189 : 0 : return -ENOMEM;
7190 : : }
7191 [ # # ]: 0 : if (old_pools)
7192 : 0 : memcpy(pools, old_pools, pools_mng->n *
7193 : : sizeof(struct mlx5_aso_mtr_pool *));
7194 : 0 : pools_mng->n = resize;
7195 : 0 : pools_mng->pools = pools;
7196 [ # # ]: 0 : if (old_pools)
7197 : 0 : mlx5_free(old_pools);
7198 : : return 0;
7199 : : }
7200 : :
7201 : : /**
7202 : : * Prepare a new meter and/or a new meter pool.
7203 : : *
7204 : : * @param[in] dev
7205 : : * Pointer to the Ethernet device structure.
7206 : : * @param[out] mtr_free
7207 : : * Where to put the pointer of a new meter.g.
7208 : : *
7209 : : * @return
7210 : : * The meter pool pointer and @mtr_free is set on success,
7211 : : * NULL otherwise and rte_errno is set.
7212 : : */
7213 : : static struct mlx5_aso_mtr_pool *
7214 : 0 : flow_dv_mtr_pool_create(struct rte_eth_dev *dev, struct mlx5_aso_mtr **mtr_free)
7215 : : {
7216 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7217 : 0 : struct mlx5_aso_mtr_pools_mng *pools_mng = &priv->sh->mtrmng->pools_mng;
7218 : : struct mlx5_aso_mtr_pool *pool = NULL;
7219 : : struct mlx5_devx_obj *dcs = NULL;
7220 : : uint32_t i;
7221 : : uint32_t log_obj_size;
7222 : :
7223 : : log_obj_size = rte_log2_u32(MLX5_ASO_MTRS_PER_POOL >> 1);
7224 : 0 : dcs = mlx5_devx_cmd_create_flow_meter_aso_obj(priv->sh->cdev->ctx,
7225 : 0 : priv->sh->cdev->pdn,
7226 : : log_obj_size);
7227 [ # # ]: 0 : if (!dcs) {
7228 : 0 : rte_errno = ENODATA;
7229 : 0 : return NULL;
7230 : : }
7231 : 0 : pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
7232 [ # # ]: 0 : if (!pool) {
7233 : 0 : rte_errno = ENOMEM;
7234 : 0 : claim_zero(mlx5_devx_cmd_destroy(dcs));
7235 : 0 : return NULL;
7236 : : }
7237 : 0 : pool->devx_obj = dcs;
7238 : 0 : rte_rwlock_write_lock(&pools_mng->resize_mtrwl);
7239 : 0 : pool->index = pools_mng->n_valid;
7240 [ # # # # ]: 0 : if (pool->index == pools_mng->n && flow_dv_mtr_container_resize(dev)) {
7241 : 0 : mlx5_free(pool);
7242 : 0 : claim_zero(mlx5_devx_cmd_destroy(dcs));
7243 : : rte_rwlock_write_unlock(&pools_mng->resize_mtrwl);
7244 : 0 : return NULL;
7245 : : }
7246 : 0 : pools_mng->pools[pool->index] = pool;
7247 : 0 : pools_mng->n_valid++;
7248 : : rte_rwlock_write_unlock(&pools_mng->resize_mtrwl);
7249 [ # # ]: 0 : for (i = 1; i < MLX5_ASO_MTRS_PER_POOL; ++i) {
7250 : 0 : pool->mtrs[i].offset = i;
7251 [ # # ]: 0 : LIST_INSERT_HEAD(&pools_mng->meters, &pool->mtrs[i], next);
7252 : : }
7253 : 0 : pool->mtrs[0].offset = 0;
7254 : 0 : *mtr_free = &pool->mtrs[0];
7255 : 0 : return pool;
7256 : : }
7257 : :
7258 : : /**
7259 : : * Release a flow meter into pool.
7260 : : *
7261 : : * @param[in] dev
7262 : : * Pointer to the Ethernet device structure.
7263 : : * @param[in] mtr_idx
7264 : : * Index to aso flow meter.
7265 : : */
7266 : : static void
7267 : 0 : flow_dv_aso_mtr_release_to_pool(struct rte_eth_dev *dev, uint32_t mtr_idx)
7268 : : {
7269 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7270 : : struct mlx5_aso_mtr_pools_mng *pools_mng =
7271 : 0 : &priv->sh->mtrmng->pools_mng;
7272 : 0 : struct mlx5_aso_mtr *aso_mtr = mlx5_aso_meter_by_idx(priv, mtr_idx);
7273 : :
7274 : : MLX5_ASSERT(aso_mtr);
7275 : 0 : rte_spinlock_lock(&pools_mng->mtrsl);
7276 [ # # ]: 0 : memset(&aso_mtr->fm, 0, sizeof(struct mlx5_flow_meter_info));
7277 : 0 : aso_mtr->state = ASO_METER_FREE;
7278 [ # # ]: 0 : LIST_INSERT_HEAD(&pools_mng->meters, aso_mtr, next);
7279 : : rte_spinlock_unlock(&pools_mng->mtrsl);
7280 : 0 : }
7281 : :
7282 : : /**
7283 : : * Allocate a aso flow meter.
7284 : : *
7285 : : * @param[in] dev
7286 : : * Pointer to the Ethernet device structure.
7287 : : *
7288 : : * @return
7289 : : * Index to aso flow meter on success, 0 otherwise and rte_errno is set.
7290 : : */
7291 : : static uint32_t
7292 : 0 : flow_dv_mtr_alloc(struct rte_eth_dev *dev)
7293 : : {
7294 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7295 : 0 : struct mlx5_aso_mtr *mtr_free = NULL;
7296 : : struct mlx5_aso_mtr_pools_mng *pools_mng =
7297 : 0 : &priv->sh->mtrmng->pools_mng;
7298 : : struct mlx5_aso_mtr_pool *pool;
7299 : : uint32_t mtr_idx = 0;
7300 : :
7301 [ # # ]: 0 : if (!priv->sh->cdev->config.devx) {
7302 : 0 : rte_errno = ENOTSUP;
7303 : 0 : return 0;
7304 : : }
7305 : : /* Allocate the flow meter memory. */
7306 : : /* Get free meters from management. */
7307 : 0 : rte_spinlock_lock(&pools_mng->mtrsl);
7308 : 0 : mtr_free = LIST_FIRST(&pools_mng->meters);
7309 [ # # ]: 0 : if (mtr_free)
7310 [ # # ]: 0 : LIST_REMOVE(mtr_free, next);
7311 [ # # # # ]: 0 : if (!mtr_free && !flow_dv_mtr_pool_create(dev, &mtr_free)) {
7312 : : rte_spinlock_unlock(&pools_mng->mtrsl);
7313 : 0 : return 0;
7314 : : }
7315 : 0 : mtr_free->state = ASO_METER_WAIT;
7316 : : rte_spinlock_unlock(&pools_mng->mtrsl);
7317 : 0 : pool = container_of(mtr_free,
7318 : : struct mlx5_aso_mtr_pool,
7319 : : mtrs[mtr_free->offset]);
7320 : 0 : mtr_idx = MLX5_MAKE_MTR_IDX(pool->index, mtr_free->offset);
7321 [ # # ]: 0 : if (!mtr_free->fm.meter_action_g) {
7322 : : #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
7323 : : struct rte_flow_error error;
7324 : : uint8_t reg_id;
7325 : :
7326 : 0 : reg_id = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &error);
7327 : 0 : mtr_free->fm.meter_action_g =
7328 : 0 : mlx5_glue->dv_create_flow_action_aso
7329 : 0 : (priv->sh->rx_domain,
7330 : 0 : pool->devx_obj->obj,
7331 : : mtr_free->offset,
7332 : : (1 << MLX5_FLOW_COLOR_GREEN),
7333 : 0 : reg_id - REG_C_0);
7334 : : #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
7335 [ # # ]: 0 : if (!mtr_free->fm.meter_action_g) {
7336 : 0 : flow_dv_aso_mtr_release_to_pool(dev, mtr_idx);
7337 : 0 : return 0;
7338 : : }
7339 : : }
7340 : : return mtr_idx;
7341 : : }
7342 : :
7343 : : /**
7344 : : * Verify the @p attributes will be correctly understood by the NIC and store
7345 : : * them in the @p flow if everything is correct.
7346 : : *
7347 : : * @param[in] dev
7348 : : * Pointer to dev struct.
7349 : : * @param[in] attributes
7350 : : * Pointer to flow attributes
7351 : : * @param[in] external
7352 : : * This flow rule is created by request external to PMD.
7353 : : * @param[out] error
7354 : : * Pointer to error structure.
7355 : : *
7356 : : * @return
7357 : : * - 0 on success and non root table.
7358 : : * - 1 on success and root table.
7359 : : * - a negative errno value otherwise and rte_errno is set.
7360 : : */
7361 : : static int
7362 : 0 : flow_dv_validate_attributes(struct rte_eth_dev *dev,
7363 : : const struct mlx5_flow_tunnel *tunnel,
7364 : : const struct rte_flow_attr *attributes,
7365 : : const struct flow_grp_info *grp_info,
7366 : : struct rte_flow_error *error)
7367 : : {
7368 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7369 : 0 : uint32_t lowest_priority = mlx5_get_lowest_priority(dev, attributes);
7370 : : int ret = 0;
7371 : :
7372 : : #ifndef HAVE_MLX5DV_DR
7373 : : RTE_SET_USED(tunnel);
7374 : : RTE_SET_USED(grp_info);
7375 : : if (attributes->group)
7376 : : return rte_flow_error_set(error, ENOTSUP,
7377 : : RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
7378 : : NULL,
7379 : : "groups are not supported");
7380 : : #else
7381 : 0 : uint32_t table = 0;
7382 : :
7383 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel, attributes->group, &table,
7384 : : grp_info, error);
7385 [ # # ]: 0 : if (ret)
7386 : : return ret;
7387 [ # # ]: 0 : if (!table)
7388 : : ret = MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL;
7389 : : #endif
7390 [ # # # # ]: 0 : if (attributes->priority != MLX5_FLOW_LOWEST_PRIO_INDICATOR &&
7391 : : attributes->priority > lowest_priority)
7392 : 0 : return rte_flow_error_set(error, ENOTSUP,
7393 : : RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
7394 : : NULL,
7395 : : "priority out of range");
7396 [ # # # # ]: 0 : if (attributes->transfer && !priv->sh->config.dv_esw_en)
7397 : 0 : return rte_flow_error_set(error, ENOTSUP,
7398 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
7399 : : "E-Switch dr is not supported");
7400 [ # # ]: 0 : if (attributes->ingress + attributes->egress + attributes->transfer != 1) {
7401 : 0 : return rte_flow_error_set(error, EINVAL,
7402 : : RTE_FLOW_ERROR_TYPE_ATTR, NULL,
7403 : : "must specify exactly one of "
7404 : : "ingress, egress or transfer");
7405 : : }
7406 : : return ret;
7407 : : }
7408 : :
7409 : : static int
7410 : 0 : validate_integrity_bits(const void *arg,
7411 : : int64_t pattern_flags, uint64_t l3_flags,
7412 : : uint64_t l4_flags, uint64_t ip4_flag,
7413 : : struct rte_flow_error *error)
7414 : : {
7415 : : const struct rte_flow_item_integrity *mask = arg;
7416 : :
7417 [ # # # # ]: 0 : if (mask->l3_ok && !(pattern_flags & l3_flags))
7418 : 0 : return rte_flow_error_set(error, EINVAL,
7419 : : RTE_FLOW_ERROR_TYPE_ITEM,
7420 : : NULL, "missing L3 protocol");
7421 : :
7422 [ # # # # ]: 0 : if (mask->ipv4_csum_ok && !(pattern_flags & ip4_flag))
7423 : 0 : return rte_flow_error_set(error, EINVAL,
7424 : : RTE_FLOW_ERROR_TYPE_ITEM,
7425 : : NULL, "missing IPv4 protocol");
7426 : :
7427 [ # # # # ]: 0 : if ((mask->l4_ok || mask->l4_csum_ok) && !(pattern_flags & l4_flags))
7428 : 0 : return rte_flow_error_set(error, EINVAL,
7429 : : RTE_FLOW_ERROR_TYPE_ITEM,
7430 : : NULL, "missing L4 protocol");
7431 : :
7432 : : return 0;
7433 : : }
7434 : :
7435 : : static int
7436 : 0 : flow_dv_validate_item_integrity_post(const struct
7437 : : rte_flow_item *integrity_items[2],
7438 : : int64_t pattern_flags,
7439 : : struct rte_flow_error *error)
7440 : : {
7441 : : const struct rte_flow_item_integrity *mask;
7442 : : int ret;
7443 : :
7444 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_OUTER_INTEGRITY) {
7445 : 0 : mask = (typeof(mask))integrity_items[0]->mask;
7446 : 0 : ret = validate_integrity_bits(mask, pattern_flags,
7447 : : MLX5_FLOW_LAYER_OUTER_L3,
7448 : : MLX5_FLOW_LAYER_OUTER_L4,
7449 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4,
7450 : : error);
7451 [ # # ]: 0 : if (ret)
7452 : : return ret;
7453 : : }
7454 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_INNER_INTEGRITY) {
7455 : 0 : mask = (typeof(mask))integrity_items[1]->mask;
7456 : 0 : ret = validate_integrity_bits(mask, pattern_flags,
7457 : : MLX5_FLOW_LAYER_INNER_L3,
7458 : : MLX5_FLOW_LAYER_INNER_L4,
7459 : : MLX5_FLOW_LAYER_INNER_L3_IPV4,
7460 : : error);
7461 [ # # ]: 0 : if (ret)
7462 : 0 : return ret;
7463 : : }
7464 : : return 0;
7465 : : }
7466 : :
7467 : : static int
7468 : 0 : flow_dv_validate_item_integrity(struct rte_eth_dev *dev,
7469 : : const struct rte_flow_item *integrity_item,
7470 : : uint64_t pattern_flags, uint64_t *last_item,
7471 : : const struct rte_flow_item *integrity_items[2],
7472 : : struct rte_flow_error *error)
7473 : : {
7474 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7475 : 0 : const struct rte_flow_item_integrity *mask = (typeof(mask))
7476 : : integrity_item->mask;
7477 : 0 : const struct rte_flow_item_integrity *spec = (typeof(spec))
7478 : : integrity_item->spec;
7479 : :
7480 [ # # ]: 0 : if (!priv->sh->cdev->config.hca_attr.pkt_integrity_match)
7481 : 0 : return rte_flow_error_set(error, ENOTSUP,
7482 : : RTE_FLOW_ERROR_TYPE_ITEM,
7483 : : integrity_item,
7484 : : "packet integrity integrity_item not supported");
7485 [ # # ]: 0 : if (!spec)
7486 : 0 : return rte_flow_error_set(error, ENOTSUP,
7487 : : RTE_FLOW_ERROR_TYPE_ITEM,
7488 : : integrity_item,
7489 : : "no spec for integrity item");
7490 [ # # ]: 0 : if (!mask)
7491 : : mask = &rte_flow_item_integrity_mask;
7492 [ # # ]: 0 : if (!mlx5_validate_integrity_item(mask))
7493 : 0 : return rte_flow_error_set(error, ENOTSUP,
7494 : : RTE_FLOW_ERROR_TYPE_ITEM,
7495 : : integrity_item,
7496 : : "unsupported integrity filter");
7497 [ # # # # ]: 0 : if ((mask->l3_ok & !spec->l3_ok) || (mask->l4_ok & !spec->l4_ok) ||
7498 [ # # ]: 0 : (mask->ipv4_csum_ok & !spec->ipv4_csum_ok) ||
7499 [ # # ]: 0 : (mask->l4_csum_ok & !spec->l4_csum_ok))
7500 : 0 : return rte_flow_error_set(error, EINVAL,
7501 : : RTE_FLOW_ERROR_TYPE_ITEM,
7502 : : NULL, "negative integrity flow is not supported");
7503 [ # # ]: 0 : if (spec->level > 1) {
7504 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_INNER_INTEGRITY)
7505 : 0 : return rte_flow_error_set
7506 : : (error, ENOTSUP,
7507 : : RTE_FLOW_ERROR_TYPE_ITEM,
7508 : : NULL, "multiple inner integrity items not supported");
7509 : 0 : integrity_items[1] = integrity_item;
7510 : 0 : *last_item |= MLX5_FLOW_ITEM_INNER_INTEGRITY;
7511 : : } else {
7512 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_OUTER_INTEGRITY)
7513 : 0 : return rte_flow_error_set
7514 : : (error, ENOTSUP,
7515 : : RTE_FLOW_ERROR_TYPE_ITEM,
7516 : : NULL, "multiple outer integrity items not supported");
7517 : 0 : integrity_items[0] = integrity_item;
7518 : 0 : *last_item |= MLX5_FLOW_ITEM_OUTER_INTEGRITY;
7519 : : }
7520 : : return 0;
7521 : : }
7522 : :
7523 : : static int
7524 : 0 : flow_dv_validate_item_flex(struct rte_eth_dev *dev,
7525 : : const struct rte_flow_item *item,
7526 : : uint64_t item_flags,
7527 : : uint64_t *last_item,
7528 : : bool is_inner,
7529 : : struct rte_flow_error *error)
7530 : : {
7531 : 0 : const struct rte_flow_item_flex *flow_spec = item->spec;
7532 : 0 : const struct rte_flow_item_flex *flow_mask = item->mask;
7533 : : struct mlx5_flex_item *flex;
7534 : :
7535 [ # # ]: 0 : if (!flow_spec)
7536 : 0 : return rte_flow_error_set(error, EINVAL,
7537 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
7538 : : "flex flow item spec cannot be NULL");
7539 [ # # ]: 0 : if (!flow_mask)
7540 : 0 : return rte_flow_error_set(error, EINVAL,
7541 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
7542 : : "flex flow item mask cannot be NULL");
7543 [ # # ]: 0 : if (item->last)
7544 : 0 : return rte_flow_error_set(error, ENOTSUP,
7545 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
7546 : : "flex flow item last not supported");
7547 [ # # ]: 0 : if (mlx5_flex_acquire_index(dev, flow_spec->handle, false) < 0)
7548 : 0 : return rte_flow_error_set(error, EINVAL,
7549 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
7550 : : "invalid flex flow item handle");
7551 : 0 : flex = (struct mlx5_flex_item *)flow_spec->handle;
7552 [ # # # # : 0 : switch (flex->tunnel_mode) {
# # ]
7553 : 0 : case FLEX_TUNNEL_MODE_SINGLE:
7554 [ # # ]: 0 : if (item_flags &
7555 : : (MLX5_FLOW_ITEM_OUTER_FLEX | MLX5_FLOW_ITEM_INNER_FLEX))
7556 : 0 : rte_flow_error_set(error, EINVAL,
7557 : : RTE_FLOW_ERROR_TYPE_ITEM,
7558 : : NULL, "multiple flex items not supported");
7559 : : break;
7560 : 0 : case FLEX_TUNNEL_MODE_OUTER:
7561 [ # # ]: 0 : if (is_inner)
7562 : 0 : rte_flow_error_set(error, EINVAL,
7563 : : RTE_FLOW_ERROR_TYPE_ITEM,
7564 : : NULL, "inner flex item was not configured");
7565 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_OUTER_FLEX)
7566 : 0 : rte_flow_error_set(error, ENOTSUP,
7567 : : RTE_FLOW_ERROR_TYPE_ITEM,
7568 : : NULL, "multiple flex items not supported");
7569 : : break;
7570 : 0 : case FLEX_TUNNEL_MODE_INNER:
7571 [ # # ]: 0 : if (!is_inner)
7572 : 0 : rte_flow_error_set(error, EINVAL,
7573 : : RTE_FLOW_ERROR_TYPE_ITEM,
7574 : : NULL, "outer flex item was not configured");
7575 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_INNER_FLEX)
7576 : 0 : rte_flow_error_set(error, EINVAL,
7577 : : RTE_FLOW_ERROR_TYPE_ITEM,
7578 : : NULL, "multiple flex items not supported");
7579 : : break;
7580 : 0 : case FLEX_TUNNEL_MODE_MULTI:
7581 [ # # # # : 0 : if ((is_inner && (item_flags & MLX5_FLOW_ITEM_INNER_FLEX)) ||
# # ]
7582 [ # # ]: 0 : (!is_inner && (item_flags & MLX5_FLOW_ITEM_OUTER_FLEX))) {
7583 : 0 : rte_flow_error_set(error, EINVAL,
7584 : : RTE_FLOW_ERROR_TYPE_ITEM,
7585 : : NULL, "multiple flex items not supported");
7586 : : }
7587 : : break;
7588 : 0 : case FLEX_TUNNEL_MODE_TUNNEL:
7589 [ # # # # ]: 0 : if (is_inner || (item_flags & MLX5_FLOW_ITEM_FLEX_TUNNEL))
7590 : 0 : rte_flow_error_set(error, EINVAL,
7591 : : RTE_FLOW_ERROR_TYPE_ITEM,
7592 : : NULL, "multiple flex tunnel items not supported");
7593 : : break;
7594 : 0 : default:
7595 : 0 : rte_flow_error_set(error, EINVAL,
7596 : : RTE_FLOW_ERROR_TYPE_ITEM,
7597 : : NULL, "invalid flex item configuration");
7598 : : }
7599 : 0 : *last_item = flex->tunnel_mode == FLEX_TUNNEL_MODE_TUNNEL ?
7600 [ # # ]: 0 : MLX5_FLOW_ITEM_FLEX_TUNNEL : is_inner ?
7601 [ # # ]: 0 : MLX5_FLOW_ITEM_INNER_FLEX : MLX5_FLOW_ITEM_OUTER_FLEX;
7602 : 0 : return 0;
7603 : : }
7604 : :
7605 : : static __rte_always_inline uint8_t
7606 : : mlx5_flow_l3_next_protocol(const struct rte_flow_item *l3_item,
7607 : : enum MLX5_SET_MATCHER key_type)
7608 : : {
7609 : : #define MLX5_L3_NEXT_PROTOCOL(i, ms) \
7610 : : ((i)->type == RTE_FLOW_ITEM_TYPE_IPV4 ? \
7611 : : ((const struct rte_flow_item_ipv4 *)(i)->ms)->hdr.next_proto_id : \
7612 : : (i)->type == RTE_FLOW_ITEM_TYPE_IPV6 ? \
7613 : : ((const struct rte_flow_item_ipv6 *)(i)->ms)->hdr.proto : \
7614 : : (i)->type == RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT ? \
7615 : : ((const struct rte_flow_item_ipv6_frag_ext *)(i)->ms)->hdr.next_header :\
7616 : : 0xff)
7617 : :
7618 : : uint8_t next_protocol;
7619 : :
7620 [ # # # # : 0 : if (l3_item->mask != NULL && l3_item->spec != NULL) {
# # # # #
# # # # #
# # # # #
# # # ]
7621 [ # # # # : 0 : next_protocol = MLX5_L3_NEXT_PROTOCOL(l3_item, mask);
# # # # #
# # # ]
7622 [ # # # # : 0 : if (next_protocol)
# # # # #
# # # ]
7623 [ # # # # : 0 : next_protocol &= MLX5_L3_NEXT_PROTOCOL(l3_item, spec);
# # # # #
# # # ]
7624 : : else
7625 : : next_protocol = 0xff;
7626 [ # # # # : 0 : } else if (key_type == MLX5_SET_MATCHER_HS_M && l3_item->mask != NULL) {
# # # # #
# # # ]
7627 [ # # # # : 0 : next_protocol = MLX5_L3_NEXT_PROTOCOL(l3_item, mask);
# # ]
7628 [ # # # # : 0 : } else if (key_type == MLX5_SET_MATCHER_HS_V && l3_item->spec != NULL) {
# # # # #
# # # ]
7629 [ # # # # : 0 : next_protocol = MLX5_L3_NEXT_PROTOCOL(l3_item, spec);
# # ]
7630 : : } else {
7631 : : /* Reset for inner layer. */
7632 : : next_protocol = 0xff;
7633 : : }
7634 : : return next_protocol;
7635 : :
7636 : : #undef MLX5_L3_NEXT_PROTOCOL
7637 : : }
7638 : :
7639 : : /**
7640 : : * Validate IB BTH item.
7641 : : *
7642 : : * @param[in] dev
7643 : : * Pointer to the rte_eth_dev structure.
7644 : : * @param[in] udp_dport
7645 : : * UDP destination port
7646 : : * @param[in] item
7647 : : * Item specification.
7648 : : * @param root
7649 : : * Whether action is on root table.
7650 : : * @param[out] error
7651 : : * Pointer to the error structure.
7652 : : *
7653 : : * @return
7654 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
7655 : : */
7656 : : static int
7657 : 0 : mlx5_flow_validate_item_ib_bth(struct rte_eth_dev *dev,
7658 : : uint16_t udp_dport,
7659 : : const struct rte_flow_item *item,
7660 : : bool root,
7661 : : struct rte_flow_error *error)
7662 : : {
7663 : 0 : const struct rte_flow_item_ib_bth *mask = item->mask;
7664 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7665 : : const struct rte_flow_item_ib_bth *valid_mask;
7666 : : int ret;
7667 : :
7668 : : valid_mask = &rte_flow_item_ib_bth_mask;
7669 [ # # ]: 0 : if (udp_dport && udp_dport != MLX5_UDP_PORT_ROCEv2)
7670 : 0 : return rte_flow_error_set(error, EINVAL,
7671 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
7672 : : "protocol filtering not compatible"
7673 : : " with UDP layer");
7674 [ # # # # ]: 0 : if (mask && (mask->hdr.se || mask->hdr.m || mask->hdr.padcnt ||
7675 [ # # # # ]: 0 : mask->hdr.tver || mask->hdr.pkey || mask->hdr.f || mask->hdr.b ||
7676 [ # # ]: 0 : mask->hdr.rsvd0 || mask->hdr.a || mask->hdr.rsvd1 ||
7677 [ # # # # : 0 : mask->hdr.psn[0] || mask->hdr.psn[1] || mask->hdr.psn[2]))
# # ]
7678 : 0 : return rte_flow_error_set(error, EINVAL,
7679 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
7680 : : "only opcode and dst_qp are supported");
7681 [ # # # # ]: 0 : if (root || priv->sh->steering_format_version ==
7682 : : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5)
7683 : 0 : return rte_flow_error_set(error, EINVAL,
7684 : : RTE_FLOW_ERROR_TYPE_ITEM,
7685 : : item,
7686 : : "IB BTH item is not supported");
7687 [ # # ]: 0 : if (!mask)
7688 : : mask = &rte_flow_item_ib_bth_mask;
7689 : 0 : ret = mlx5_flow_item_acceptable(dev, item, (const uint8_t *)mask,
7690 : : (const uint8_t *)valid_mask,
7691 : : sizeof(struct rte_flow_item_ib_bth),
7692 : : MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
7693 : : if (ret < 0)
7694 : : return ret;
7695 : : return 0;
7696 : : }
7697 : :
7698 : : const struct rte_flow_item_ipv4 nic_ipv4_mask = {
7699 : : .hdr = {
7700 : : .src_addr = RTE_BE32(0xffffffff),
7701 : : .dst_addr = RTE_BE32(0xffffffff),
7702 : : .type_of_service = 0xff,
7703 : : .fragment_offset = RTE_BE16(0xffff),
7704 : : .next_proto_id = 0xff,
7705 : : .time_to_live = 0xff,
7706 : : },
7707 : : };
7708 : :
7709 : : const struct rte_flow_item_ipv6 nic_ipv6_mask = {
7710 : : .hdr = {
7711 : : .src_addr = RTE_IPV6_MASK_FULL,
7712 : : .dst_addr = RTE_IPV6_MASK_FULL,
7713 : : .vtc_flow = RTE_BE32(0xffffffff),
7714 : : .proto = 0xff,
7715 : : .hop_limits = 0xff,
7716 : : },
7717 : : .has_frag_ext = 1,
7718 : : };
7719 : :
7720 : : const struct rte_flow_item_tcp nic_tcp_mask = {
7721 : : .hdr = {
7722 : : .tcp_flags = 0xFF,
7723 : : .src_port = RTE_BE16(UINT16_MAX),
7724 : : .dst_port = RTE_BE16(UINT16_MAX),
7725 : : }
7726 : : };
7727 : :
7728 : : /**
7729 : : * Internal validation function. For validating both actions and items.
7730 : : *
7731 : : * @param[in] dev
7732 : : * Pointer to the rte_eth_dev structure.
7733 : : * @param[in] attr
7734 : : * Pointer to the flow attributes.
7735 : : * @param[in] items
7736 : : * Pointer to the list of items.
7737 : : * @param[in] actions
7738 : : * Pointer to the list of actions.
7739 : : * @param[in] external
7740 : : * This flow rule is created by request external to PMD.
7741 : : * @param[in] hairpin
7742 : : * Number of hairpin TX actions, 0 means classic flow.
7743 : : * @param[out] error
7744 : : * Pointer to the error structure.
7745 : : *
7746 : : * @return
7747 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
7748 : : */
7749 : : int
7750 : 0 : flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
7751 : : const struct rte_flow_item items[],
7752 : : const struct rte_flow_action actions[],
7753 : : bool external, int hairpin, struct rte_flow_error *error)
7754 : : {
7755 : : int ret;
7756 : 0 : uint64_t aso_mask, action_flags = 0;
7757 : 0 : uint64_t item_flags = 0;
7758 : 0 : uint64_t last_item = 0;
7759 : : uint8_t next_protocol = 0xff;
7760 : : uint16_t ether_type = 0;
7761 : 0 : int actions_n = 0;
7762 : : uint8_t item_ipv6_proto = 0;
7763 : 0 : int fdb_mirror = 0;
7764 : : int modify_after_mirror = 0;
7765 : : const struct rte_flow_item *geneve_item = NULL;
7766 : : const struct rte_flow_item *gre_item = NULL;
7767 : : const struct rte_flow_item *gtp_item = NULL;
7768 : : const struct rte_flow_action_raw_decap *decap;
7769 : : const struct rte_flow_action_raw_encap *encap;
7770 : : const struct rte_flow_action_rss *rss = NULL;
7771 : 0 : const struct rte_flow_action_rss *sample_rss = NULL;
7772 : 0 : const struct rte_flow_action_count *sample_count = NULL;
7773 : 0 : const struct rte_flow_item_ecpri nic_ecpri_mask = {
7774 : : .hdr = {
7775 : : .common = {
7776 : : .u32 =
7777 : : RTE_BE32(((const struct rte_ecpri_common_hdr) {
7778 : : .type = 0xFF,
7779 : : }).u32),
7780 : : },
7781 : : .dummy[0] = 0xffffffff,
7782 : : },
7783 : : };
7784 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
7785 : 0 : struct mlx5_sh_config *dev_conf = &priv->sh->config;
7786 : : uint16_t queue_index = 0xFFFF;
7787 : : const struct rte_flow_item_vlan *vlan_m = NULL;
7788 : : uint32_t rw_act_num = 0;
7789 : : uint64_t is_root;
7790 : : const struct mlx5_flow_tunnel *tunnel;
7791 : : enum mlx5_tof_rule_type tof_rule_type;
7792 : 0 : struct flow_grp_info grp_info = {
7793 : : .external = !!external,
7794 : 0 : .transfer = !!attr->transfer,
7795 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
7796 : : .std_tbl_fix = true,
7797 : : };
7798 : : const struct rte_eth_hairpin_conf *conf;
7799 : 0 : const struct rte_flow_item *integrity_items[2] = {NULL, NULL};
7800 : : const struct rte_flow_item *port_id_item = NULL;
7801 : 0 : bool def_policy = false;
7802 : : bool shared_count = false;
7803 : : uint16_t udp_dport = 0;
7804 : 0 : uint32_t tag_id = 0, tag_bitmap = 0;
7805 : : const struct rte_flow_action_age *non_shared_age = NULL;
7806 : : const struct rte_flow_action_count *count = NULL;
7807 : : const struct rte_flow_action_port_id *port = NULL;
7808 : : const struct mlx5_rte_flow_item_tag *mlx5_tag;
7809 : 0 : struct mlx5_priv *act_priv = NULL;
7810 : : int aso_after_sample = 0;
7811 : : struct mlx5_priv *port_priv = NULL;
7812 : 0 : uint64_t sub_action_flags = 0;
7813 : 0 : uint16_t sample_port_id = 0;
7814 : : uint16_t port_id = 0;
7815 : :
7816 [ # # ]: 0 : if (items == NULL)
7817 : : return -1;
7818 : : tunnel = is_tunnel_offload_active(dev) ?
7819 [ # # ]: 0 : mlx5_get_tof(items, actions, &tof_rule_type) : NULL;
7820 [ # # ]: 0 : if (tunnel) {
7821 [ # # ]: 0 : if (!dev_conf->dv_flow_en)
7822 : 0 : return rte_flow_error_set
7823 : : (error, ENOTSUP,
7824 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7825 : : NULL, "tunnel offload requires DV flow interface");
7826 [ # # ]: 0 : if (priv->representor)
7827 : 0 : return rte_flow_error_set
7828 : : (error, ENOTSUP,
7829 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
7830 : : NULL, "decap not supported for VF representor");
7831 [ # # ]: 0 : if (tof_rule_type == MLX5_TUNNEL_OFFLOAD_SET_RULE)
7832 : 0 : action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
7833 [ # # ]: 0 : else if (tof_rule_type == MLX5_TUNNEL_OFFLOAD_MATCH_RULE)
7834 : 0 : action_flags |= MLX5_FLOW_ACTION_TUNNEL_MATCH |
7835 : : MLX5_FLOW_ACTION_DECAP;
7836 : 0 : grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
7837 : : (dev, attr, tunnel, tof_rule_type);
7838 : : }
7839 : 0 : ret = flow_dv_validate_attributes(dev, tunnel, attr, &grp_info, error);
7840 [ # # ]: 0 : if (ret < 0)
7841 : : return ret;
7842 : 0 : is_root = (uint64_t)ret;
7843 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
7844 : : enum mlx5_l3_tunnel_detection l3_tunnel_detection;
7845 : : uint64_t l3_tunnel_flag;
7846 : 0 : int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
7847 : 0 : int type = items->type;
7848 : :
7849 : : if (!mlx5_flow_os_item_supported(type))
7850 : : return rte_flow_error_set(error, ENOTSUP,
7851 : : RTE_FLOW_ERROR_TYPE_ITEM,
7852 : : NULL, "item not supported");
7853 [ # # # # : 0 : switch (type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # #
# ]
7854 : : case RTE_FLOW_ITEM_TYPE_VOID:
7855 : : break;
7856 : 0 : case RTE_FLOW_ITEM_TYPE_ESP:
7857 : 0 : ret = mlx5_flow_os_validate_item_esp(dev, items,
7858 : : item_flags,
7859 : : next_protocol,
7860 : : error);
7861 [ # # ]: 0 : if (ret < 0)
7862 : 0 : return ret;
7863 : 0 : last_item = MLX5_FLOW_ITEM_ESP;
7864 : 0 : break;
7865 : 0 : case RTE_FLOW_ITEM_TYPE_PORT_ID:
7866 : 0 : ret = flow_dv_validate_item_port_id
7867 : : (dev, items, attr, item_flags, &act_priv, error);
7868 [ # # ]: 0 : if (ret < 0)
7869 : 0 : return ret;
7870 : 0 : last_item = MLX5_FLOW_ITEM_PORT_ID;
7871 : : port_id_item = items;
7872 : 0 : break;
7873 : 0 : case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
7874 : : case RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR:
7875 : 0 : ret = flow_dv_validate_item_represented_port
7876 : : (dev, items, attr, item_flags, &act_priv, error);
7877 [ # # ]: 0 : if (ret < 0)
7878 : 0 : return ret;
7879 : 0 : last_item = MLX5_FLOW_ITEM_REPRESENTED_PORT;
7880 : : port_id_item = items;
7881 : 0 : break;
7882 : 0 : case RTE_FLOW_ITEM_TYPE_ETH:
7883 : 0 : ret = mlx5_flow_validate_item_eth(dev, items, item_flags,
7884 : : true, error);
7885 [ # # ]: 0 : if (ret < 0)
7886 : 0 : return ret;
7887 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
7888 : : MLX5_FLOW_LAYER_OUTER_L2;
7889 [ # # # # ]: 0 : if (items->mask != NULL && items->spec != NULL) {
7890 : 0 : ether_type =
7891 : : ((const struct rte_flow_item_eth *)
7892 : : items->spec)->hdr.ether_type;
7893 : 0 : ether_type &=
7894 : : ((const struct rte_flow_item_eth *)
7895 : 0 : items->mask)->hdr.ether_type;
7896 [ # # ]: 0 : ether_type = rte_be_to_cpu_16(ether_type);
7897 : : } else {
7898 : : ether_type = 0;
7899 : : }
7900 : : break;
7901 : 0 : case RTE_FLOW_ITEM_TYPE_VLAN:
7902 : 0 : ret = mlx5_flow_dv_validate_item_vlan(items, item_flags,
7903 : : dev, error);
7904 [ # # ]: 0 : if (ret < 0)
7905 : 0 : return ret;
7906 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
7907 : : MLX5_FLOW_LAYER_OUTER_VLAN;
7908 [ # # # # ]: 0 : if (items->mask != NULL && items->spec != NULL) {
7909 : 0 : ether_type =
7910 : : ((const struct rte_flow_item_vlan *)
7911 : : items->spec)->hdr.eth_proto;
7912 : 0 : ether_type &=
7913 : : ((const struct rte_flow_item_vlan *)
7914 : 0 : items->mask)->hdr.eth_proto;
7915 [ # # ]: 0 : ether_type = rte_be_to_cpu_16(ether_type);
7916 : : } else {
7917 : : ether_type = 0;
7918 : : }
7919 : : /* Store outer VLAN mask for of_push_vlan action. */
7920 [ # # ]: 0 : if (!tunnel)
7921 : : vlan_m = items->mask;
7922 : : break;
7923 : : case RTE_FLOW_ITEM_TYPE_IPV4:
7924 : : next_protocol = mlx5_flow_l3_next_protocol
7925 : : (items, (enum MLX5_SET_MATCHER)-1);
7926 : : l3_tunnel_detection =
7927 : : mlx5_flow_tunnel_ip_check(items, next_protocol,
7928 : : item_flags,
7929 : : &l3_tunnel_flag);
7930 : : /*
7931 : : * explicitly allow inner IPIP match
7932 : : */
7933 : : if (l3_tunnel_detection == l3_tunnel_outer) {
7934 : 0 : item_flags |= l3_tunnel_flag;
7935 : : tunnel = 1;
7936 : : }
7937 : 0 : ret = mlx5_flow_dv_validate_item_ipv4(dev, items,
7938 : : item_flags,
7939 : : last_item,
7940 : : ether_type,
7941 : : &nic_ipv4_mask,
7942 : : error);
7943 [ # # ]: 0 : if (ret < 0)
7944 : 0 : return ret;
7945 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
7946 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4;
7947 [ # # ]: 0 : if (l3_tunnel_detection == l3_tunnel_outer)
7948 : 0 : item_flags |= l3_tunnel_flag;
7949 : : break;
7950 : : case RTE_FLOW_ITEM_TYPE_IPV6:
7951 : : next_protocol = mlx5_flow_l3_next_protocol
7952 : : (items, (enum MLX5_SET_MATCHER)-1);
7953 : : l3_tunnel_detection =
7954 : : mlx5_flow_tunnel_ip_check(items, next_protocol,
7955 : : item_flags,
7956 : : &l3_tunnel_flag);
7957 : : /*
7958 : : * explicitly allow inner IPIP match
7959 : : */
7960 : : if (l3_tunnel_detection == l3_tunnel_outer) {
7961 : 0 : item_flags |= l3_tunnel_flag;
7962 : : tunnel = 1;
7963 : : }
7964 : 0 : ret = mlx5_flow_validate_item_ipv6(dev, items,
7965 : : item_flags,
7966 : : last_item,
7967 : : ether_type,
7968 : : &nic_ipv6_mask,
7969 : : error);
7970 [ # # ]: 0 : if (ret < 0)
7971 : 0 : return ret;
7972 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
7973 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6;
7974 [ # # ]: 0 : if (l3_tunnel_detection == l3_tunnel_outer)
7975 : 0 : item_flags |= l3_tunnel_flag;
7976 : : break;
7977 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
7978 : 0 : ret = flow_dv_validate_item_ipv6_frag_ext(dev, items,
7979 : : item_flags,
7980 : : error);
7981 [ # # ]: 0 : if (ret < 0)
7982 : 0 : return ret;
7983 [ # # ]: 0 : last_item = tunnel ?
7984 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
7985 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
7986 : : next_protocol = mlx5_flow_l3_next_protocol
7987 : : (items, (enum MLX5_SET_MATCHER)-1);
7988 : : break;
7989 : 0 : case RTE_FLOW_ITEM_TYPE_TCP:
7990 : 0 : ret = mlx5_flow_validate_item_tcp
7991 : : (dev, items, item_flags,
7992 : : next_protocol,
7993 : : &nic_tcp_mask,
7994 : : error);
7995 [ # # ]: 0 : if (ret < 0)
7996 : 0 : return ret;
7997 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
7998 : : MLX5_FLOW_LAYER_OUTER_L4_TCP;
7999 : 0 : break;
8000 : 0 : case RTE_FLOW_ITEM_TYPE_UDP:
8001 : 0 : ret = mlx5_flow_validate_item_udp(dev, items, item_flags,
8002 : : next_protocol,
8003 : : error);
8004 : 0 : const struct rte_flow_item_udp *spec = items->spec;
8005 : 0 : const struct rte_flow_item_udp *mask = items->mask;
8006 [ # # ]: 0 : if (!mask)
8007 : : mask = &rte_flow_item_udp_mask;
8008 [ # # ]: 0 : if (spec != NULL)
8009 [ # # ]: 0 : udp_dport = rte_be_to_cpu_16
8010 : : (spec->hdr.dst_port &
8011 : : mask->hdr.dst_port);
8012 [ # # ]: 0 : if (ret < 0)
8013 : 0 : return ret;
8014 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
8015 : : MLX5_FLOW_LAYER_OUTER_L4_UDP;
8016 : 0 : break;
8017 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
8018 : 0 : ret = mlx5_flow_validate_item_gre(dev, items, item_flags,
8019 : : next_protocol, error);
8020 [ # # ]: 0 : if (ret < 0)
8021 : 0 : return ret;
8022 : : gre_item = items;
8023 : 0 : last_item = MLX5_FLOW_LAYER_GRE;
8024 : 0 : break;
8025 : 0 : case RTE_FLOW_ITEM_TYPE_GRE_OPTION:
8026 : 0 : ret = mlx5_flow_validate_item_gre_option(dev, items, item_flags,
8027 : : attr, gre_item, error);
8028 [ # # ]: 0 : if (ret < 0)
8029 : 0 : return ret;
8030 : 0 : last_item = MLX5_FLOW_LAYER_GRE;
8031 : 0 : break;
8032 : 0 : case RTE_FLOW_ITEM_TYPE_NVGRE:
8033 : 0 : ret = mlx5_flow_validate_item_nvgre(dev, items,
8034 : : item_flags,
8035 : : next_protocol,
8036 : : error);
8037 [ # # ]: 0 : if (ret < 0)
8038 : 0 : return ret;
8039 : 0 : last_item = MLX5_FLOW_LAYER_NVGRE;
8040 : 0 : break;
8041 : 0 : case RTE_FLOW_ITEM_TYPE_GRE_KEY:
8042 : 0 : ret = mlx5_flow_validate_item_gre_key
8043 : : (dev, items, item_flags, gre_item, error);
8044 [ # # ]: 0 : if (ret < 0)
8045 : 0 : return ret;
8046 : 0 : last_item = MLX5_FLOW_LAYER_GRE_KEY;
8047 : 0 : break;
8048 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN:
8049 : 0 : ret = mlx5_flow_validate_item_vxlan(dev, udp_dport,
8050 : : items, item_flags,
8051 : : is_root, error);
8052 [ # # ]: 0 : if (ret < 0)
8053 : 0 : return ret;
8054 : 0 : last_item = MLX5_FLOW_LAYER_VXLAN;
8055 : 0 : break;
8056 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
8057 : 0 : ret = mlx5_flow_validate_item_vxlan_gpe(items,
8058 : : item_flags, dev,
8059 : : error);
8060 [ # # ]: 0 : if (ret < 0)
8061 : 0 : return ret;
8062 : 0 : last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
8063 : 0 : break;
8064 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE:
8065 : 0 : ret = mlx5_flow_validate_item_geneve(items,
8066 : : item_flags, dev,
8067 : : error);
8068 [ # # ]: 0 : if (ret < 0)
8069 : 0 : return ret;
8070 : : geneve_item = items;
8071 : 0 : last_item = MLX5_FLOW_LAYER_GENEVE;
8072 : 0 : break;
8073 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
8074 : 0 : ret = mlx5_flow_validate_item_geneve_opt(items,
8075 : : last_item,
8076 : : geneve_item,
8077 : : dev,
8078 : : error);
8079 [ # # ]: 0 : if (ret < 0)
8080 : 0 : return ret;
8081 : 0 : last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
8082 : 0 : break;
8083 : 0 : case RTE_FLOW_ITEM_TYPE_MPLS:
8084 : 0 : ret = mlx5_flow_validate_item_mpls(dev, items,
8085 : : item_flags,
8086 : : last_item, error);
8087 [ # # ]: 0 : if (ret < 0)
8088 : 0 : return ret;
8089 : 0 : last_item = MLX5_FLOW_LAYER_MPLS;
8090 : 0 : break;
8091 : :
8092 : 0 : case RTE_FLOW_ITEM_TYPE_MARK:
8093 : 0 : ret = flow_dv_validate_item_mark(dev, items, attr,
8094 : : error);
8095 [ # # ]: 0 : if (ret < 0)
8096 : 0 : return ret;
8097 : 0 : last_item = MLX5_FLOW_ITEM_MARK;
8098 : 0 : break;
8099 : 0 : case RTE_FLOW_ITEM_TYPE_META:
8100 : 0 : ret = flow_dv_validate_item_meta(dev, items, attr,
8101 : : error);
8102 [ # # ]: 0 : if (ret < 0)
8103 : 0 : return ret;
8104 : 0 : last_item = MLX5_FLOW_ITEM_METADATA;
8105 : 0 : break;
8106 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP:
8107 : 0 : ret = mlx5_flow_validate_item_icmp(dev, items, item_flags,
8108 : : next_protocol,
8109 : : error);
8110 [ # # ]: 0 : if (ret < 0)
8111 : 0 : return ret;
8112 : 0 : last_item = MLX5_FLOW_LAYER_ICMP;
8113 : 0 : break;
8114 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6:
8115 : 0 : ret = mlx5_flow_validate_item_icmp6(dev, items, item_flags,
8116 : : next_protocol,
8117 : : error);
8118 [ # # ]: 0 : if (ret < 0)
8119 : 0 : return ret;
8120 : : item_ipv6_proto = IPPROTO_ICMPV6;
8121 : 0 : last_item = MLX5_FLOW_LAYER_ICMP6;
8122 : 0 : break;
8123 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REQUEST:
8124 : : case RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REPLY:
8125 : 0 : ret = mlx5_flow_validate_item_icmp6_echo(dev, items,
8126 : : item_flags,
8127 : : next_protocol,
8128 : : error);
8129 [ # # ]: 0 : if (ret < 0)
8130 : 0 : return ret;
8131 : : item_ipv6_proto = IPPROTO_ICMPV6;
8132 : 0 : last_item = MLX5_FLOW_LAYER_ICMP6;
8133 : 0 : break;
8134 : 0 : case RTE_FLOW_ITEM_TYPE_TAG:
8135 : 0 : ret = flow_dv_validate_item_tag(dev, items, &tag_bitmap,
8136 : : attr, error);
8137 [ # # ]: 0 : if (ret < 0)
8138 : 0 : return ret;
8139 : 0 : last_item = MLX5_FLOW_ITEM_TAG;
8140 : 0 : break;
8141 : 0 : case RTE_FLOW_ITEM_TYPE_TX_QUEUE:
8142 : : case MLX5_RTE_FLOW_ITEM_TYPE_SQ:
8143 : 0 : last_item = MLX5_FLOW_ITEM_SQ;
8144 : 0 : break;
8145 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
8146 : 0 : mlx5_tag = (const struct mlx5_rte_flow_item_tag *)items->spec;
8147 [ # # ]: 0 : if (tag_bitmap & (1 << mlx5_tag->id))
8148 : 0 : return rte_flow_error_set(error, EINVAL,
8149 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
8150 : : items->spec,
8151 : : "Duplicated tag index");
8152 : 0 : tag_bitmap |= 1 << mlx5_tag->id;
8153 : 0 : break;
8154 : 0 : case RTE_FLOW_ITEM_TYPE_GTP:
8155 : 0 : ret = mlx5_flow_dv_validate_item_gtp(dev, items,
8156 : : item_flags,
8157 : : error);
8158 [ # # ]: 0 : if (ret < 0)
8159 : 0 : return ret;
8160 : : gtp_item = items;
8161 : 0 : last_item = MLX5_FLOW_LAYER_GTP;
8162 : 0 : break;
8163 : 0 : case RTE_FLOW_ITEM_TYPE_GTP_PSC:
8164 : 0 : ret = mlx5_flow_dv_validate_item_gtp_psc(dev, items,
8165 : : last_item,
8166 : : gtp_item,
8167 : : is_root, error);
8168 [ # # ]: 0 : if (ret < 0)
8169 : 0 : return ret;
8170 : 0 : last_item = MLX5_FLOW_LAYER_GTP_PSC;
8171 : 0 : break;
8172 : 0 : case RTE_FLOW_ITEM_TYPE_ECPRI:
8173 : : /* Capacity will be checked in the translate stage. */
8174 : 0 : ret = mlx5_flow_validate_item_ecpri(dev, items,
8175 : : item_flags,
8176 : : last_item,
8177 : : ether_type,
8178 : : &nic_ecpri_mask,
8179 : : error);
8180 [ # # ]: 0 : if (ret < 0)
8181 : 0 : return ret;
8182 : 0 : last_item = MLX5_FLOW_LAYER_ECPRI;
8183 : 0 : break;
8184 : 0 : case RTE_FLOW_ITEM_TYPE_INTEGRITY:
8185 : 0 : ret = flow_dv_validate_item_integrity(dev, items,
8186 : : item_flags,
8187 : : &last_item,
8188 : : integrity_items,
8189 : : error);
8190 [ # # ]: 0 : if (ret < 0)
8191 : 0 : return ret;
8192 : : break;
8193 : 0 : case RTE_FLOW_ITEM_TYPE_CONNTRACK:
8194 : 0 : ret = mlx5_flow_dv_validate_item_aso_ct(dev, items,
8195 : : &item_flags,
8196 : : error);
8197 [ # # ]: 0 : if (ret < 0)
8198 : 0 : return ret;
8199 : 0 : last_item = MLX5_FLOW_LAYER_ASO_CT;
8200 : 0 : break;
8201 : : case MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL:
8202 : : /* tunnel offload item was processed before
8203 : : * list it here as a supported type
8204 : : */
8205 : : break;
8206 : 0 : case RTE_FLOW_ITEM_TYPE_FLEX:
8207 : 0 : ret = flow_dv_validate_item_flex(dev, items, item_flags,
8208 : : &last_item,
8209 : : tunnel != 0, error);
8210 [ # # ]: 0 : if (ret < 0)
8211 : 0 : return ret;
8212 : : /* Reset for next proto, it is unknown. */
8213 : : next_protocol = 0xff;
8214 : : break;
8215 : 0 : case RTE_FLOW_ITEM_TYPE_METER_COLOR:
8216 : 0 : ret = flow_dv_validate_item_meter_color(dev, items,
8217 : : attr, error);
8218 [ # # ]: 0 : if (ret < 0)
8219 : 0 : return ret;
8220 : 0 : last_item = MLX5_FLOW_ITEM_METER_COLOR;
8221 : 0 : break;
8222 : 0 : case RTE_FLOW_ITEM_TYPE_AGGR_AFFINITY:
8223 : 0 : ret = flow_dv_validate_item_aggr_affinity(dev, items,
8224 : : attr, error);
8225 [ # # ]: 0 : if (ret < 0)
8226 : 0 : return ret;
8227 : 0 : last_item = MLX5_FLOW_ITEM_AGGR_AFFINITY;
8228 : 0 : break;
8229 : 0 : case RTE_FLOW_ITEM_TYPE_IB_BTH:
8230 : 0 : ret = mlx5_flow_validate_item_ib_bth(dev, udp_dport,
8231 : : items, is_root, error);
8232 [ # # ]: 0 : if (ret < 0)
8233 : 0 : return ret;
8234 : :
8235 : 0 : last_item = MLX5_FLOW_ITEM_IB_BTH;
8236 : 0 : break;
8237 : 0 : case RTE_FLOW_ITEM_TYPE_NSH:
8238 : 0 : ret = mlx5_flow_validate_item_nsh(dev, items, error);
8239 [ # # ]: 0 : if (ret < 0)
8240 : 0 : return ret;
8241 : 0 : last_item = MLX5_FLOW_ITEM_NSH;
8242 : 0 : break;
8243 : 0 : default:
8244 : 0 : return rte_flow_error_set(error, ENOTSUP,
8245 : : RTE_FLOW_ERROR_TYPE_ITEM,
8246 : : NULL, "item not supported");
8247 : : }
8248 : 0 : item_flags |= last_item;
8249 : : }
8250 [ # # ]: 0 : if (item_flags & MLX5_FLOW_ITEM_INTEGRITY) {
8251 : 0 : ret = flow_dv_validate_item_integrity_post(integrity_items,
8252 : : item_flags, error);
8253 [ # # ]: 0 : if (ret)
8254 : : return ret;
8255 : : }
8256 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
8257 : 0 : int type = actions->type;
8258 : :
8259 : : if (!mlx5_flow_os_action_supported(type))
8260 : : return rte_flow_error_set(error, ENOTSUP,
8261 : : RTE_FLOW_ERROR_TYPE_ACTION,
8262 : : actions,
8263 : : "action not supported");
8264 [ # # ]: 0 : if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
8265 : 0 : return rte_flow_error_set(error, ENOTSUP,
8266 : : RTE_FLOW_ERROR_TYPE_ACTION,
8267 : : actions, "too many actions");
8268 [ # # ]: 0 : if (action_flags &
8269 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
8270 : 0 : return rte_flow_error_set(error, ENOTSUP,
8271 : : RTE_FLOW_ERROR_TYPE_ACTION,
8272 : : NULL, "meter action with policy "
8273 : : "must be the last action");
8274 [ # # # # : 0 : switch (type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
8275 : : case RTE_FLOW_ACTION_TYPE_VOID:
8276 : : break;
8277 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
8278 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
8279 : 0 : ret = flow_dv_validate_action_port_id(dev,
8280 : : action_flags,
8281 : : actions,
8282 : : attr,
8283 : : error);
8284 [ # # ]: 0 : if (ret)
8285 : 0 : return ret;
8286 [ # # ]: 0 : if (type == RTE_FLOW_ACTION_TYPE_PORT_ID) {
8287 : 0 : port = (const struct rte_flow_action_port_id *)
8288 : : actions->conf;
8289 [ # # ]: 0 : port_id = port->original ? dev->data->port_id : port->id;
8290 : : } else {
8291 : 0 : port_id = ((const struct rte_flow_action_ethdev *)
8292 : 0 : actions->conf)->port_id;
8293 : : }
8294 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_ID;
8295 : 0 : ++actions_n;
8296 : 0 : break;
8297 : 0 : case RTE_FLOW_ACTION_TYPE_FLAG:
8298 : 0 : ret = flow_dv_validate_action_flag(dev, action_flags,
8299 : : attr, error);
8300 [ # # ]: 0 : if (ret < 0)
8301 : 0 : return ret;
8302 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
8303 : : /* Count all modify-header actions as one. */
8304 [ # # ]: 0 : if (!(action_flags &
8305 : : MLX5_FLOW_MODIFY_HDR_ACTIONS))
8306 : 0 : ++actions_n;
8307 : 0 : action_flags |= MLX5_FLOW_ACTION_FLAG |
8308 : : MLX5_FLOW_ACTION_MARK_EXT;
8309 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8310 : : modify_after_mirror = 1;
8311 : :
8312 : : } else {
8313 : 0 : action_flags |= MLX5_FLOW_ACTION_FLAG;
8314 : 0 : ++actions_n;
8315 : : }
8316 : 0 : rw_act_num += MLX5_ACT_NUM_SET_MARK;
8317 : 0 : break;
8318 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
8319 : 0 : ret = flow_dv_validate_action_mark(dev, actions,
8320 : : action_flags,
8321 : : attr, error);
8322 [ # # ]: 0 : if (ret < 0)
8323 : 0 : return ret;
8324 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
8325 : : /* Count all modify-header actions as one. */
8326 [ # # ]: 0 : if (!(action_flags &
8327 : : MLX5_FLOW_MODIFY_HDR_ACTIONS))
8328 : 0 : ++actions_n;
8329 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK |
8330 : : MLX5_FLOW_ACTION_MARK_EXT;
8331 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8332 : : modify_after_mirror = 1;
8333 : : } else {
8334 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK;
8335 : 0 : ++actions_n;
8336 : : }
8337 : 0 : rw_act_num += MLX5_ACT_NUM_SET_MARK;
8338 : 0 : break;
8339 : 0 : case RTE_FLOW_ACTION_TYPE_SET_META:
8340 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
8341 : 0 : return rte_flow_error_set(error, ENOTSUP,
8342 : : RTE_FLOW_ERROR_TYPE_ACTION,
8343 : : actions,
8344 : : "action not supported");
8345 : 0 : ret = flow_dv_validate_action_set_meta(dev, actions,
8346 : : action_flags,
8347 : : attr, error);
8348 [ # # ]: 0 : if (ret < 0)
8349 : 0 : return ret;
8350 : : /* Count all modify-header actions as one action. */
8351 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8352 : 0 : ++actions_n;
8353 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8354 : : modify_after_mirror = 1;
8355 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_META;
8356 : 0 : rw_act_num += MLX5_ACT_NUM_SET_META;
8357 : 0 : break;
8358 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TAG:
8359 : 0 : ret = flow_dv_validate_action_set_tag(dev, actions,
8360 : : action_flags,
8361 : : attr, error);
8362 [ # # ]: 0 : if (ret < 0)
8363 : 0 : return ret;
8364 : : /* Count all modify-header actions as one action. */
8365 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8366 : 0 : ++actions_n;
8367 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8368 : : modify_after_mirror = 1;
8369 : 0 : tag_id = ((const struct rte_flow_action_set_tag *)
8370 : 0 : actions->conf)->index;
8371 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
8372 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
8373 : 0 : break;
8374 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
8375 : 0 : ret = mlx5_flow_validate_action_drop(dev, is_root,
8376 : : attr, error);
8377 [ # # ]: 0 : if (ret < 0)
8378 : 0 : return ret;
8379 : 0 : action_flags |= MLX5_FLOW_ACTION_DROP;
8380 : 0 : ++actions_n;
8381 : 0 : break;
8382 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
8383 : 0 : ret = mlx5_flow_validate_action_queue(actions,
8384 : : action_flags, dev,
8385 : : attr, error);
8386 [ # # ]: 0 : if (ret < 0)
8387 : 0 : return ret;
8388 : 0 : queue_index = ((const struct rte_flow_action_queue *)
8389 : 0 : (actions->conf))->index;
8390 : 0 : action_flags |= MLX5_FLOW_ACTION_QUEUE;
8391 : 0 : ++actions_n;
8392 : 0 : break;
8393 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
8394 : 0 : rss = actions->conf;
8395 : 0 : ret = mlx5_flow_validate_action_rss(actions,
8396 : : action_flags, dev,
8397 : : attr, item_flags,
8398 : : error);
8399 [ # # ]: 0 : if (ret < 0)
8400 : 0 : return ret;
8401 [ # # ]: 0 : if (rss && sample_rss &&
8402 [ # # ]: 0 : (sample_rss->level != rss->level ||
8403 [ # # ]: 0 : sample_rss->types != rss->types))
8404 : 0 : return rte_flow_error_set(error, ENOTSUP,
8405 : : RTE_FLOW_ERROR_TYPE_ACTION,
8406 : : NULL,
8407 : : "Can't use the different RSS types "
8408 : : "or level in the same flow");
8409 [ # # # # ]: 0 : if (rss != NULL && rss->queue_num)
8410 : 0 : queue_index = rss->queue[0];
8411 : 0 : action_flags |= MLX5_FLOW_ACTION_RSS;
8412 : 0 : ++actions_n;
8413 : 0 : break;
8414 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
8415 : : ret =
8416 : 0 : mlx5_flow_validate_action_default_miss(action_flags,
8417 : : attr, error);
8418 [ # # ]: 0 : if (ret < 0)
8419 : 0 : return ret;
8420 : 0 : action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
8421 : 0 : ++actions_n;
8422 : 0 : break;
8423 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
8424 : : shared_count = true;
8425 : : /* fall-through. */
8426 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
8427 : 0 : ret = flow_dv_validate_action_count(dev, shared_count,
8428 : : action_flags,
8429 : : is_root, error);
8430 [ # # ]: 0 : if (ret < 0)
8431 : 0 : return ret;
8432 : 0 : count = actions->conf;
8433 : 0 : action_flags |= MLX5_FLOW_ACTION_COUNT;
8434 : 0 : ++actions_n;
8435 : 0 : break;
8436 : 0 : case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
8437 [ # # ]: 0 : if (flow_dv_validate_action_pop_vlan(dev,
8438 : : action_flags,
8439 : : actions,
8440 : : item_flags, attr,
8441 : : error))
8442 : 0 : return -rte_errno;
8443 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8444 : : modify_after_mirror = 1;
8445 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
8446 : 0 : ++actions_n;
8447 : 0 : break;
8448 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
8449 : 0 : ret = flow_dv_validate_action_push_vlan(dev,
8450 : : action_flags,
8451 : : vlan_m,
8452 : : actions, attr,
8453 : : error);
8454 [ # # ]: 0 : if (ret < 0)
8455 : 0 : return ret;
8456 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8457 : : modify_after_mirror = 1;
8458 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
8459 : 0 : ++actions_n;
8460 : 0 : break;
8461 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
8462 : 0 : ret = flow_dv_validate_action_set_vlan_pcp
8463 : : (action_flags, actions, error);
8464 [ # # ]: 0 : if (ret < 0)
8465 : 0 : return ret;
8466 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8467 : : modify_after_mirror = 1;
8468 : : /* Count PCP with push_vlan command. */
8469 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_PCP;
8470 : 0 : break;
8471 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
8472 : 0 : ret = flow_dv_validate_action_set_vlan_vid
8473 : : (item_flags, action_flags,
8474 : : actions, error);
8475 [ # # ]: 0 : if (ret < 0)
8476 : 0 : return ret;
8477 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8478 : : modify_after_mirror = 1;
8479 : : /* Count VID with push_vlan command. */
8480 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
8481 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_VID;
8482 : 0 : break;
8483 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
8484 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
8485 : 0 : ret = mlx5_flow_dv_validate_action_l2_encap(dev,
8486 : : action_flags,
8487 : : actions,
8488 : : attr,
8489 : : error);
8490 [ # # ]: 0 : if (ret < 0)
8491 : 0 : return ret;
8492 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
8493 : 0 : ++actions_n;
8494 : 0 : break;
8495 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
8496 : : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
8497 : 0 : ret = mlx5_flow_dv_validate_action_decap(dev,
8498 : : action_flags,
8499 : : actions,
8500 : : item_flags,
8501 : : attr, error);
8502 [ # # ]: 0 : if (ret < 0)
8503 : 0 : return ret;
8504 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8505 : : modify_after_mirror = 1;
8506 : 0 : action_flags |= MLX5_FLOW_ACTION_DECAP;
8507 : 0 : ++actions_n;
8508 : 0 : break;
8509 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
8510 : 0 : ret = mlx5_flow_dv_validate_action_raw_encap_decap
8511 : 0 : (dev, NULL, actions->conf, attr, &action_flags,
8512 : : &actions_n, actions, item_flags, error);
8513 [ # # ]: 0 : if (ret < 0)
8514 : 0 : return ret;
8515 : : break;
8516 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
8517 : 0 : decap = actions->conf;
8518 [ # # ]: 0 : while ((++actions)->type == RTE_FLOW_ACTION_TYPE_VOID)
8519 : : ;
8520 [ # # ]: 0 : if (actions->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
8521 : : encap = NULL;
8522 : : actions--;
8523 : : } else {
8524 : 0 : encap = actions->conf;
8525 : : }
8526 [ # # ]: 0 : ret = mlx5_flow_dv_validate_action_raw_encap_decap
8527 : : (dev,
8528 : : decap ? decap : &empty_decap, encap,
8529 : : attr, &action_flags, &actions_n,
8530 : : actions, item_flags, error);
8531 [ # # ]: 0 : if (ret < 0)
8532 : 0 : return ret;
8533 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_SAMPLE) &&
8534 : : (action_flags & MLX5_FLOW_ACTION_DECAP))
8535 : : modify_after_mirror = 1;
8536 : : break;
8537 : 0 : case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
8538 : : case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
8539 : 0 : ret = flow_dv_validate_action_modify_mac(action_flags,
8540 : : actions,
8541 : : item_flags,
8542 : : error);
8543 [ # # ]: 0 : if (ret < 0)
8544 : 0 : return ret;
8545 : : /* Count all modify-header actions as one action. */
8546 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8547 : 0 : ++actions_n;
8548 : 0 : action_flags |= actions->type ==
8549 : : RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
8550 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_MAC_SRC :
8551 : : MLX5_FLOW_ACTION_SET_MAC_DST;
8552 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8553 : : modify_after_mirror = 1;
8554 : : /*
8555 : : * Even if the source and destination MAC addresses have
8556 : : * overlap in the header with 4B alignment, the convert
8557 : : * function will handle them separately and 4 SW actions
8558 : : * will be created. And 2 actions will be added each
8559 : : * time no matter how many bytes of address will be set.
8560 : : */
8561 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_MAC;
8562 : 0 : break;
8563 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
8564 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
8565 : 0 : ret = flow_dv_validate_action_modify_ipv4(action_flags,
8566 : : actions,
8567 : : item_flags,
8568 : : error);
8569 [ # # ]: 0 : if (ret < 0)
8570 : 0 : return ret;
8571 : : /* Count all modify-header actions as one action. */
8572 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8573 : 0 : ++actions_n;
8574 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8575 : : modify_after_mirror = 1;
8576 : 0 : action_flags |= actions->type ==
8577 : : RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
8578 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_IPV4_SRC :
8579 : : MLX5_FLOW_ACTION_SET_IPV4_DST;
8580 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_IPV4;
8581 : 0 : break;
8582 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
8583 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
8584 : 0 : ret = flow_dv_validate_action_modify_ipv6(action_flags,
8585 : : actions,
8586 : : item_flags,
8587 : : error);
8588 [ # # ]: 0 : if (ret < 0)
8589 : 0 : return ret;
8590 [ # # ]: 0 : if (item_ipv6_proto == IPPROTO_ICMPV6)
8591 : 0 : return rte_flow_error_set(error, ENOTSUP,
8592 : : RTE_FLOW_ERROR_TYPE_ACTION,
8593 : : actions,
8594 : : "Can't change header "
8595 : : "with ICMPv6 proto");
8596 : : /* Count all modify-header actions as one action. */
8597 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8598 : 0 : ++actions_n;
8599 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8600 : : modify_after_mirror = 1;
8601 : 0 : action_flags |= actions->type ==
8602 : : RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
8603 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_IPV6_SRC :
8604 : : MLX5_FLOW_ACTION_SET_IPV6_DST;
8605 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_IPV6;
8606 : 0 : break;
8607 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
8608 : : case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
8609 : 0 : ret = flow_dv_validate_action_modify_tp(action_flags,
8610 : : actions,
8611 : : item_flags,
8612 : : error);
8613 [ # # ]: 0 : if (ret < 0)
8614 : 0 : return ret;
8615 : : /* Count all modify-header actions as one action. */
8616 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8617 : 0 : ++actions_n;
8618 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8619 : : modify_after_mirror = 1;
8620 : 0 : action_flags |= actions->type ==
8621 : : RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
8622 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_TP_SRC :
8623 : : MLX5_FLOW_ACTION_SET_TP_DST;
8624 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_PORT;
8625 : 0 : break;
8626 : 0 : case RTE_FLOW_ACTION_TYPE_DEC_TTL:
8627 : : case RTE_FLOW_ACTION_TYPE_SET_TTL:
8628 : 0 : ret = flow_dv_validate_action_modify_ttl(action_flags,
8629 : : actions,
8630 : : item_flags,
8631 : : error);
8632 [ # # ]: 0 : if (ret < 0)
8633 : 0 : return ret;
8634 : : /* Count all modify-header actions as one action. */
8635 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8636 : 0 : ++actions_n;
8637 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8638 : : modify_after_mirror = 1;
8639 : 0 : action_flags |= actions->type ==
8640 : : RTE_FLOW_ACTION_TYPE_SET_TTL ?
8641 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_TTL :
8642 : : MLX5_FLOW_ACTION_DEC_TTL;
8643 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_TTL;
8644 : 0 : break;
8645 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
8646 : 0 : ret = flow_dv_validate_action_jump(dev, tunnel, actions,
8647 : : action_flags,
8648 : : attr, external,
8649 : : error);
8650 [ # # ]: 0 : if (ret)
8651 : 0 : return ret;
8652 : 0 : ++actions_n;
8653 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP;
8654 : 0 : break;
8655 : 0 : case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
8656 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
8657 : 0 : ret = flow_dv_validate_action_modify_tcp_seq
8658 : : (action_flags,
8659 : : actions,
8660 : : item_flags,
8661 : : error);
8662 [ # # ]: 0 : if (ret < 0)
8663 : 0 : return ret;
8664 : : /* Count all modify-header actions as one action. */
8665 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8666 : 0 : ++actions_n;
8667 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8668 : : modify_after_mirror = 1;
8669 : 0 : action_flags |= actions->type ==
8670 : : RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
8671 [ # # ]: 0 : MLX5_FLOW_ACTION_INC_TCP_SEQ :
8672 : : MLX5_FLOW_ACTION_DEC_TCP_SEQ;
8673 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_TCPSEQ;
8674 : 0 : break;
8675 : 0 : case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
8676 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
8677 : 0 : ret = flow_dv_validate_action_modify_tcp_ack
8678 : : (action_flags,
8679 : : actions,
8680 : : item_flags,
8681 : : error);
8682 [ # # ]: 0 : if (ret < 0)
8683 : 0 : return ret;
8684 : : /* Count all modify-header actions as one action. */
8685 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8686 : 0 : ++actions_n;
8687 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8688 : : modify_after_mirror = 1;
8689 : 0 : action_flags |= actions->type ==
8690 : : RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
8691 [ # # ]: 0 : MLX5_FLOW_ACTION_INC_TCP_ACK :
8692 : : MLX5_FLOW_ACTION_DEC_TCP_ACK;
8693 : 0 : rw_act_num += MLX5_ACT_NUM_MDF_TCPACK;
8694 : 0 : break;
8695 : : case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
8696 : : break;
8697 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
8698 : : case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
8699 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
8700 : 0 : break;
8701 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
8702 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
8703 : 0 : return rte_flow_error_set(error, ENOTSUP,
8704 : : RTE_FLOW_ERROR_TYPE_ACTION,
8705 : : actions,
8706 : : "action not supported");
8707 : 0 : ret = mlx5_flow_validate_action_meter(dev,
8708 : : action_flags,
8709 : : item_flags,
8710 : : actions, attr,
8711 : : port_id_item,
8712 : : &def_policy,
8713 : : error);
8714 [ # # ]: 0 : if (ret < 0)
8715 : 0 : return ret;
8716 : 0 : action_flags |= MLX5_FLOW_ACTION_METER;
8717 [ # # ]: 0 : if (!def_policy)
8718 : 0 : action_flags |=
8719 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
8720 : 0 : ++actions_n;
8721 : : /* Meter action will add one more TAG action. */
8722 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
8723 : 0 : break;
8724 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
8725 [ # # ]: 0 : if (is_root)
8726 : 0 : return rte_flow_error_set(error, ENOTSUP,
8727 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
8728 : : NULL,
8729 : : "Shared ASO age action is not supported for group 0");
8730 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_AGE)
8731 : 0 : return rte_flow_error_set
8732 : : (error, EINVAL,
8733 : : RTE_FLOW_ERROR_TYPE_ACTION,
8734 : : NULL,
8735 : : "duplicate age actions set");
8736 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8737 : : aso_after_sample = 1;
8738 : 0 : action_flags |= MLX5_FLOW_ACTION_AGE;
8739 : 0 : ++actions_n;
8740 : 0 : break;
8741 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
8742 : 0 : non_shared_age = actions->conf;
8743 : 0 : ret = flow_dv_validate_action_age(action_flags,
8744 : : actions, dev,
8745 : : error);
8746 [ # # ]: 0 : if (ret < 0)
8747 : 0 : return ret;
8748 : : /*
8749 : : * Validate the regular AGE action (using counter)
8750 : : * mutual exclusion with indirect counter actions.
8751 : : */
8752 [ # # ]: 0 : if (!flow_hit_aso_supported(priv, is_root)) {
8753 [ # # ]: 0 : if (shared_count)
8754 : 0 : return rte_flow_error_set
8755 : : (error, EINVAL,
8756 : : RTE_FLOW_ERROR_TYPE_ACTION,
8757 : : NULL,
8758 : : "old age and indirect count combination is not supported");
8759 [ # # ]: 0 : if (sample_count)
8760 : 0 : return rte_flow_error_set
8761 : : (error, EINVAL,
8762 : : RTE_FLOW_ERROR_TYPE_ACTION,
8763 : : NULL,
8764 : : "old age action and count must be in the same sub flow");
8765 : : } else {
8766 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8767 : : aso_after_sample = 1;
8768 : : }
8769 : 0 : action_flags |= MLX5_FLOW_ACTION_AGE;
8770 : 0 : ++actions_n;
8771 : 0 : break;
8772 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
8773 : 0 : ret = flow_dv_validate_action_modify_ipv4_dscp
8774 : : (action_flags,
8775 : : actions,
8776 : : item_flags,
8777 : : error);
8778 [ # # ]: 0 : if (ret < 0)
8779 : 0 : return ret;
8780 : : /* Count all modify-header actions as one action. */
8781 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8782 : 0 : ++actions_n;
8783 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8784 : : modify_after_mirror = 1;
8785 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
8786 : 0 : rw_act_num += MLX5_ACT_NUM_SET_DSCP;
8787 : 0 : break;
8788 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
8789 : 0 : ret = flow_dv_validate_action_modify_ipv6_dscp
8790 : : (action_flags,
8791 : : actions,
8792 : : item_flags,
8793 : : error);
8794 [ # # ]: 0 : if (ret < 0)
8795 : 0 : return ret;
8796 : : /* Count all modify-header actions as one action. */
8797 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8798 : 0 : ++actions_n;
8799 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8800 : : modify_after_mirror = 1;
8801 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
8802 : 0 : rw_act_num += MLX5_ACT_NUM_SET_DSCP;
8803 : 0 : break;
8804 : 0 : case RTE_FLOW_ACTION_TYPE_SAMPLE:
8805 : 0 : ret = flow_dv_validate_action_sample(&action_flags,
8806 : : &sub_action_flags,
8807 : : actions, dev,
8808 : : attr, item_flags,
8809 : : rss, &sample_rss,
8810 : : &sample_count,
8811 : : &fdb_mirror,
8812 : : &sample_port_id,
8813 : : is_root,
8814 : : error);
8815 [ # # ]: 0 : if (ret < 0)
8816 : 0 : return ret;
8817 [ # # # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_SET_TAG) &&
8818 : 0 : tag_id == 0 &&
8819 [ # # ]: 0 : priv->sh->registers.aso_reg == REG_NON)
8820 : 0 : return rte_flow_error_set(error, EINVAL,
8821 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8822 : : "sample after tag action causes metadata tag index 0 corruption");
8823 : 0 : action_flags |= MLX5_FLOW_ACTION_SAMPLE;
8824 : 0 : ++actions_n;
8825 : 0 : break;
8826 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
8827 : 0 : ret = flow_dv_validate_action_modify_field(dev,
8828 : : action_flags,
8829 : : actions,
8830 : : attr,
8831 : : is_root,
8832 : : error);
8833 [ # # ]: 0 : if (ret < 0)
8834 : 0 : return ret;
8835 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8836 : : modify_after_mirror = 1;
8837 : : /* Count all modify-header actions as one action. */
8838 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS))
8839 : 0 : ++actions_n;
8840 : 0 : action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
8841 : 0 : rw_act_num += ret;
8842 : 0 : break;
8843 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
8844 : 0 : ret = mlx5_flow_dv_validate_action_aso_ct(dev,
8845 : : action_flags,
8846 : : item_flags,
8847 : : is_root,
8848 : : error);
8849 [ # # ]: 0 : if (ret < 0)
8850 : 0 : return ret;
8851 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
8852 : : aso_after_sample = 1;
8853 : 0 : action_flags |= MLX5_FLOW_ACTION_CT;
8854 : 0 : break;
8855 : : case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
8856 : : /* tunnel offload action was processed before
8857 : : * list it here as a supported type
8858 : : */
8859 : : break;
8860 : : #ifdef HAVE_MLX5DV_DR_ACTION_CREATE_DEST_ROOT_TABLE
8861 : : case RTE_FLOW_ACTION_TYPE_SEND_TO_KERNEL:
8862 : : action_flags |= MLX5_FLOW_ACTION_SEND_TO_KERNEL;
8863 : : ++actions_n;
8864 : : break;
8865 : : #endif
8866 : 0 : default:
8867 : 0 : return rte_flow_error_set(error, ENOTSUP,
8868 : : RTE_FLOW_ERROR_TYPE_ACTION,
8869 : : actions,
8870 : : "action not supported");
8871 : : }
8872 : : }
8873 : : /*
8874 : : * Validate actions in flow rules
8875 : : * - Explicit decap action is prohibited by the tunnel offload API.
8876 : : * - Drop action in tunnel steer rule is prohibited by the API.
8877 : : * - Application cannot use MARK action because it's value can mask
8878 : : * tunnel default miss notification.
8879 : : * - JUMP in tunnel match rule has no support in current PMD
8880 : : * implementation.
8881 : : * - TAG & META are reserved for future uses.
8882 : : */
8883 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_TUNNEL_SET) {
8884 : : uint64_t bad_actions_mask = MLX5_FLOW_ACTION_DECAP |
8885 : : MLX5_FLOW_ACTION_MARK |
8886 : : MLX5_FLOW_ACTION_SET_TAG |
8887 : : MLX5_FLOW_ACTION_SET_META |
8888 : : MLX5_FLOW_ACTION_DROP;
8889 : :
8890 [ # # ]: 0 : if (action_flags & bad_actions_mask)
8891 : 0 : return rte_flow_error_set
8892 : : (error, EINVAL,
8893 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8894 : : "Invalid RTE action in tunnel "
8895 : : "set decap rule");
8896 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_ACTION_JUMP))
8897 : 0 : return rte_flow_error_set
8898 : : (error, EINVAL,
8899 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8900 : : "tunnel set decap rule must terminate "
8901 : : "with JUMP");
8902 [ # # ]: 0 : if (attr->egress)
8903 : 0 : return rte_flow_error_set
8904 : : (error, EINVAL,
8905 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8906 : : "tunnel flows for ingress and transfer traffic only");
8907 : : }
8908 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_TUNNEL_MATCH) {
8909 : : uint64_t bad_actions_mask = MLX5_FLOW_ACTION_JUMP |
8910 : : MLX5_FLOW_ACTION_MARK |
8911 : : MLX5_FLOW_ACTION_SET_TAG |
8912 : : MLX5_FLOW_ACTION_SET_META;
8913 : :
8914 [ # # ]: 0 : if (action_flags & bad_actions_mask)
8915 : 0 : return rte_flow_error_set
8916 : : (error, EINVAL,
8917 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8918 : : "Invalid RTE action in tunnel "
8919 : : "set match rule");
8920 : : }
8921 : : /*
8922 : : * Validate the drop action mutual exclusion with other actions.
8923 : : * Drop action is mutually-exclusive with any other action, except for
8924 : : * Count/Sample/Age actions.
8925 : : * Drop action compatibility with tunnel offload was already validated.
8926 : : */
8927 [ # # ]: 0 : if (action_flags & (MLX5_FLOW_ACTION_TUNNEL_MATCH |
8928 : : MLX5_FLOW_ACTION_TUNNEL_MATCH));
8929 [ # # ]: 0 : else if ((action_flags & MLX5_FLOW_ACTION_DROP) &&
8930 [ # # ]: 0 : (action_flags & ~(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_DROP_INCLUSIVE_ACTIONS)))
8931 : 0 : return rte_flow_error_set(error, EINVAL,
8932 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
8933 : : "Drop action is mutually-exclusive "
8934 : : "with any other action, except for "
8935 : : "Count/Sample/Age action");
8936 : : /* Eswitch has few restrictions on using items and actions */
8937 [ # # ]: 0 : if (attr->transfer) {
8938 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev) &&
8939 [ # # ]: 0 : action_flags & MLX5_FLOW_ACTION_FLAG)
8940 : 0 : return rte_flow_error_set(error, ENOTSUP,
8941 : : RTE_FLOW_ERROR_TYPE_ACTION,
8942 : : NULL,
8943 : : "unsupported action FLAG");
8944 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev) &&
8945 [ # # ]: 0 : action_flags & MLX5_FLOW_ACTION_MARK)
8946 : 0 : return rte_flow_error_set(error, ENOTSUP,
8947 : : RTE_FLOW_ERROR_TYPE_ACTION,
8948 : : NULL,
8949 : : "unsupported action MARK");
8950 [ # # ]: 0 : if (!priv->jump_fdb_rx_en) {
8951 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_QUEUE)
8952 : 0 : return rte_flow_error_set(error, ENOTSUP,
8953 : : RTE_FLOW_ERROR_TYPE_ACTION,
8954 : : NULL,
8955 : : "unsupported action QUEUE");
8956 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_RSS)
8957 : 0 : return rte_flow_error_set(error, ENOTSUP,
8958 : : RTE_FLOW_ERROR_TYPE_ACTION,
8959 : : NULL,
8960 : : "unsupported action RSS");
8961 [ # # ]: 0 : if (!(action_flags & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
8962 : 0 : return rte_flow_error_set(error, EINVAL,
8963 : : RTE_FLOW_ERROR_TYPE_ACTION,
8964 : : actions,
8965 : : "no fate action is found");
8966 : : }
8967 : : } else {
8968 [ # # # # ]: 0 : if (!(action_flags & MLX5_FLOW_FATE_ACTIONS) && attr->ingress)
8969 : 0 : return rte_flow_error_set(error, EINVAL,
8970 : : RTE_FLOW_ERROR_TYPE_ACTION,
8971 : : actions,
8972 : : "no fate action is found");
8973 : : }
8974 : : /*
8975 : : * Continue validation for Xcap and VLAN actions.
8976 : : * If hairpin is working in explicit TX rule mode, there is no actions
8977 : : * splitting and the validation of hairpin ingress flow should be the
8978 : : * same as other standard flows.
8979 : : */
8980 [ # # ]: 0 : if ((action_flags & (MLX5_FLOW_XCAP_ACTIONS |
8981 [ # # ]: 0 : MLX5_FLOW_VLAN_ACTIONS)) &&
8982 [ # # # # ]: 0 : (queue_index == 0xFFFF || !mlx5_rxq_is_hairpin(dev, queue_index) ||
8983 : 0 : ((conf = mlx5_rxq_get_hairpin_conf(dev, queue_index)) != NULL &&
8984 [ # # ]: 0 : conf->tx_explicit != 0))) {
8985 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_XCAP_ACTIONS) ==
8986 : : MLX5_FLOW_XCAP_ACTIONS)
8987 : 0 : return rte_flow_error_set(error, ENOTSUP,
8988 : : RTE_FLOW_ERROR_TYPE_ACTION,
8989 : : NULL, "encap and decap "
8990 : : "combination aren't supported");
8991 : : /* Push VLAN is not supported in ingress except for NICs newer than CX5. */
8992 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN) {
8993 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
8994 : : bool direction_error = false;
8995 : :
8996 [ # # ]: 0 : if (attr->transfer) {
8997 [ # # ]: 0 : bool fdb_tx = flow_source_vport_representor(priv, act_priv);
8998 : 0 : bool is_cx5 = sh->steering_format_version ==
8999 : : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5;
9000 : :
9001 [ # # ]: 0 : if (!fdb_tx && is_cx5)
9002 : : direction_error = true;
9003 [ # # ]: 0 : } else if (attr->ingress) {
9004 : : direction_error = true;
9005 : : }
9006 : : if (direction_error)
9007 : 0 : return rte_flow_error_set(error, ENOTSUP,
9008 : : RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
9009 : : NULL,
9010 : : "push VLAN action not supported "
9011 : : "for ingress");
9012 : : }
9013 [ # # ]: 0 : if (attr->ingress) {
9014 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
9015 : 0 : return rte_flow_error_set
9016 : : (error, ENOTSUP,
9017 : : RTE_FLOW_ERROR_TYPE_ACTION,
9018 : : NULL, "encap is not supported"
9019 : : " for ingress traffic");
9020 [ # # ]: 0 : else if ((action_flags & MLX5_FLOW_VLAN_ACTIONS) ==
9021 : : MLX5_FLOW_VLAN_ACTIONS)
9022 : 0 : return rte_flow_error_set
9023 : : (error, ENOTSUP,
9024 : : RTE_FLOW_ERROR_TYPE_ACTION,
9025 : : NULL, "no support for "
9026 : : "multiple VLAN actions");
9027 : : }
9028 : : }
9029 : : /* Pop VLAN is not supported in egress except for NICs newer than CX5. */
9030 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_POP_VLAN) {
9031 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
9032 : : bool direction_error = false;
9033 : :
9034 [ # # ]: 0 : if (attr->transfer) {
9035 [ # # ]: 0 : bool fdb_tx = flow_source_vport_representor(priv, act_priv);
9036 : 0 : bool is_cx5 = sh->steering_format_version ==
9037 : : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5;
9038 : :
9039 [ # # ]: 0 : if (fdb_tx && is_cx5)
9040 : : direction_error = true;
9041 [ # # ]: 0 : } else if (attr->egress) {
9042 : : direction_error = true;
9043 : : }
9044 : : if (direction_error)
9045 : 0 : return rte_flow_error_set(error, ENOTSUP,
9046 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
9047 : : NULL,
9048 : : "pop vlan action not supported for egress");
9049 : : }
9050 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY) {
9051 [ # # ]: 0 : if ((action_flags & (MLX5_FLOW_FATE_ACTIONS &
9052 [ # # ]: 0 : ~MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)) &&
9053 : : attr->ingress)
9054 : 0 : return rte_flow_error_set
9055 : : (error, ENOTSUP,
9056 : : RTE_FLOW_ERROR_TYPE_ACTION,
9057 : : NULL, "fate action not supported for "
9058 : : "meter with policy");
9059 [ # # ]: 0 : if (attr->egress) {
9060 [ # # ]: 0 : if (action_flags & MLX5_FLOW_MODIFY_HDR_ACTIONS)
9061 : 0 : return rte_flow_error_set
9062 : : (error, ENOTSUP,
9063 : : RTE_FLOW_ERROR_TYPE_ACTION,
9064 : : NULL, "modify header action in egress "
9065 : : "cannot be done before meter action");
9066 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_ENCAP)
9067 : 0 : return rte_flow_error_set
9068 : : (error, ENOTSUP,
9069 : : RTE_FLOW_ERROR_TYPE_ACTION,
9070 : : NULL, "encap action in egress "
9071 : : "cannot be done before meter action");
9072 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
9073 : 0 : return rte_flow_error_set
9074 : : (error, ENOTSUP,
9075 : : RTE_FLOW_ERROR_TYPE_ACTION,
9076 : : NULL, "push vlan action in egress "
9077 : : "cannot be done before meter action");
9078 : : }
9079 : : }
9080 : : /*
9081 : : * Only support one ASO action in a single flow rule.
9082 : : * non-shared AGE + counter will fallback to use HW counter, no ASO hit object.
9083 : : * Group 0 uses HW counter for AGE too even if no counter action.
9084 : : */
9085 [ # # # # ]: 0 : aso_mask = (action_flags & MLX5_FLOW_ACTION_METER && priv->sh->meter_aso_en) << 2 |
9086 [ # # # # : 0 : (action_flags & MLX5_FLOW_ACTION_CT && priv->sh->ct_aso_en) << 1 |
# # ]
9087 : 0 : (action_flags & MLX5_FLOW_ACTION_AGE &&
9088 [ # # ]: 0 : !(non_shared_age && count) &&
9089 [ # # # # : 0 : (attr->group || (attr->transfer && priv->fdb_def_rule)) &&
# # # # ]
9090 [ # # ]: 0 : priv->sh->flow_hit_aso_en);
9091 [ # # ]: 0 : if (rte_popcount64(aso_mask) > 1)
9092 : 0 : return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
9093 : : NULL, "unsupported combining AGE, METER, CT ASO actions in a single rule");
9094 : : /*
9095 : : * Hairpin flow will add one more TAG action in TX implicit mode.
9096 : : * In TX explicit mode, there will be no hairpin flow ID.
9097 : : */
9098 [ # # ]: 0 : if (hairpin > 0)
9099 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
9100 : : /* extra metadata enabled: one more TAG action will be add. */
9101 [ # # ]: 0 : if (dev_conf->dv_flow_en &&
9102 [ # # # # ]: 0 : dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
9103 : 0 : mlx5_flow_ext_mreg_supported(dev))
9104 : 0 : rw_act_num += MLX5_ACT_NUM_SET_TAG;
9105 [ # # ]: 0 : if (rw_act_num >
9106 : : flow_dv_modify_hdr_action_max(dev, is_root)) {
9107 : 0 : return rte_flow_error_set(error, ENOTSUP,
9108 : : RTE_FLOW_ERROR_TYPE_ACTION,
9109 : : NULL, "too many header modify"
9110 : : " actions to support");
9111 : : }
9112 [ # # ]: 0 : if (fdb_mirror) {
9113 [ # # # # ]: 0 : if (!priv->sh->cdev->config.hca_attr.reg_c_preserve &&
9114 [ # # ]: 0 : flow_source_vport_representor(priv, act_priv)) {
9115 : : /* Eswitch egress mirror and modify flow has limitation on CX5 */
9116 [ # # ]: 0 : if (modify_after_mirror)
9117 : 0 : return rte_flow_error_set(error, EINVAL,
9118 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9119 : : "sample before modify action is not supported");
9120 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_JUMP)
9121 : 0 : return rte_flow_error_set(error, EINVAL,
9122 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9123 : : "sample and jump action combination is not supported");
9124 : : }
9125 [ # # ]: 0 : if (aso_mask > 0 && aso_after_sample && fdb_mirror)
9126 : 0 : return rte_flow_error_set(error, ENOTSUP,
9127 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9128 : : "sample before ASO action is not supported");
9129 [ # # ]: 0 : if (sub_action_flags & MLX5_FLOW_ACTION_PORT_ID) {
9130 : 0 : port_priv = mlx5_port_to_eswitch_info(sample_port_id, false);
9131 [ # # ]: 0 : if (flow_source_vport_representor(priv, port_priv)) {
9132 [ # # ]: 0 : if (sub_action_flags & MLX5_FLOW_ACTION_ENCAP)
9133 : 0 : return rte_flow_error_set(error, ENOTSUP,
9134 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9135 : : "mirror to rep port with encap is not supported");
9136 : : } else {
9137 [ # # ]: 0 : if (!(sub_action_flags & MLX5_FLOW_ACTION_ENCAP) &&
9138 [ # # ]: 0 : (action_flags & MLX5_FLOW_ACTION_JUMP))
9139 : 0 : return rte_flow_error_set(error, ENOTSUP,
9140 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9141 : : "mirror to wire port without encap is not supported");
9142 : : }
9143 : : }
9144 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_PORT_ID) &&
9145 : : (action_flags & MLX5_FLOW_ACTION_ENCAP)) {
9146 : 0 : port_priv = mlx5_port_to_eswitch_info(port_id, false);
9147 [ # # ]: 0 : if (flow_source_vport_representor(priv, port_priv))
9148 : 0 : return rte_flow_error_set(error, ENOTSUP,
9149 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
9150 : : "mirror to rep port with encap is not supported");
9151 : : }
9152 : : }
9153 : : /*
9154 : : * Validation the NIC Egress flow on representor, except implicit
9155 : : * hairpin default egress flow with TX_QUEUE item, other flows not
9156 : : * work due to metadata regC0 mismatch.
9157 : : */
9158 [ # # # # : 0 : if (attr->egress && priv->representor && !(item_flags & MLX5_FLOW_ITEM_SQ))
# # ]
9159 : 0 : return rte_flow_error_set(error, EINVAL,
9160 : : RTE_FLOW_ERROR_TYPE_ITEM,
9161 : : NULL,
9162 : : "NIC egress rules on representors"
9163 : : " is not supported");
9164 : : return 0;
9165 : : }
9166 : :
9167 : : /**
9168 : : * Internal preparation function. Allocates the DV flow size,
9169 : : * this size is constant.
9170 : : *
9171 : : * @param[in] dev
9172 : : * Pointer to the rte_eth_dev structure.
9173 : : * @param[in] attr
9174 : : * Pointer to the flow attributes.
9175 : : * @param[in] items
9176 : : * Pointer to the list of items.
9177 : : * @param[in] actions
9178 : : * Pointer to the list of actions.
9179 : : * @param[out] error
9180 : : * Pointer to the error structure.
9181 : : *
9182 : : * @return
9183 : : * Pointer to mlx5_flow object on success,
9184 : : * otherwise NULL and rte_errno is set.
9185 : : */
9186 : : static struct mlx5_flow *
9187 : 0 : flow_dv_prepare(struct rte_eth_dev *dev,
9188 : : const struct rte_flow_attr *attr __rte_unused,
9189 : : const struct rte_flow_item items[] __rte_unused,
9190 : : const struct rte_flow_action actions[] __rte_unused,
9191 : : struct rte_flow_error *error)
9192 : : {
9193 : 0 : uint32_t handle_idx = 0;
9194 : : struct mlx5_flow *dev_flow;
9195 : : struct mlx5_flow_handle *dev_handle;
9196 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
9197 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
9198 : :
9199 : : MLX5_ASSERT(wks);
9200 : 0 : wks->skip_matcher_reg = 0;
9201 : 0 : wks->policy = NULL;
9202 : 0 : wks->final_policy = NULL;
9203 : 0 : wks->vport_meta_tag = 0;
9204 : : /* In case of corrupting the memory. */
9205 [ # # ]: 0 : if (wks->flow_idx >= MLX5_NUM_MAX_DEV_FLOWS) {
9206 : 0 : rte_flow_error_set(error, ENOSPC,
9207 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9208 : : "not free temporary device flow");
9209 : 0 : return NULL;
9210 : : }
9211 : 0 : dev_handle = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
9212 : : &handle_idx);
9213 [ # # ]: 0 : if (!dev_handle) {
9214 : 0 : rte_flow_error_set(error, ENOMEM,
9215 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
9216 : : "not enough memory to create flow handle");
9217 : 0 : return NULL;
9218 : : }
9219 : : MLX5_ASSERT(wks->flow_idx < RTE_DIM(wks->flows));
9220 : 0 : dev_flow = &wks->flows[wks->flow_idx++];
9221 : : memset(dev_flow, 0, sizeof(*dev_flow));
9222 : 0 : dev_flow->handle = dev_handle;
9223 : 0 : dev_flow->handle_idx = handle_idx;
9224 : 0 : dev_flow->dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param);
9225 : 0 : dev_flow->ingress = attr->ingress;
9226 : 0 : dev_flow->dv.transfer = attr->transfer;
9227 : 0 : return dev_flow;
9228 : : }
9229 : :
9230 : : #ifdef RTE_LIBRTE_MLX5_DEBUG
9231 : : /**
9232 : : * Sanity check for match mask and value. Similar to check_valid_spec() in
9233 : : * kernel driver. If unmasked bit is present in value, it returns failure.
9234 : : *
9235 : : * @param match_mask
9236 : : * pointer to match mask buffer.
9237 : : * @param match_value
9238 : : * pointer to match value buffer.
9239 : : *
9240 : : * @return
9241 : : * 0 if valid, -EINVAL otherwise.
9242 : : */
9243 : : static int
9244 : : flow_dv_check_valid_spec(void *match_mask, void *match_value)
9245 : : {
9246 : : uint8_t *m = match_mask;
9247 : : uint8_t *v = match_value;
9248 : : unsigned int i;
9249 : :
9250 : : for (i = 0; i < MLX5_ST_SZ_BYTES(fte_match_param); ++i) {
9251 : : if (v[i] & ~m[i]) {
9252 : : DRV_LOG(ERR,
9253 : : "match_value differs from match_criteria"
9254 : : " %p[%u] != %p[%u]",
9255 : : match_value, i, match_mask, i);
9256 : : return -EINVAL;
9257 : : }
9258 : : }
9259 : : return 0;
9260 : : }
9261 : : #endif
9262 : :
9263 : : /**
9264 : : * Add match of ip_version.
9265 : : *
9266 : : * @param[in] group
9267 : : * Flow group.
9268 : : * @param[in] headers_v
9269 : : * Values header pointer.
9270 : : * @param[in] headers_m
9271 : : * Masks header pointer.
9272 : : * @param[in] ip_version
9273 : : * The IP version to set.
9274 : : */
9275 : : static inline void
9276 : 0 : flow_dv_set_match_ip_version(uint32_t group,
9277 : : void *headers_v,
9278 : : uint32_t key_type,
9279 : : uint8_t ip_version)
9280 : : {
9281 [ # # # # ]: 0 : if (group == 0 && (key_type & MLX5_SET_MATCHER_M))
9282 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version, 0xf);
9283 : : else
9284 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version,
9285 : : ip_version);
9286 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype, 0);
9287 : 0 : }
9288 : :
9289 : : /**
9290 : : * Add Ethernet item to the value.
9291 : : *
9292 : : * @param[in, out] key
9293 : : * Flow matcher value.
9294 : : * @param[in] item
9295 : : * Flow pattern to translate.
9296 : : * @param[in] inner
9297 : : * Item is inner pattern.
9298 : : * @param[in] grpup
9299 : : * Flow matcher group.
9300 : : * @param[in] key_type
9301 : : * Set flow matcher mask or value.
9302 : : */
9303 : : static void
9304 : 0 : flow_dv_translate_item_eth(void *key, const struct rte_flow_item *item,
9305 : : int inner, uint32_t group, uint32_t key_type)
9306 : : {
9307 : 0 : const struct rte_flow_item_eth *eth_vv = item->spec;
9308 : : const struct rte_flow_item_eth *eth_m;
9309 : : const struct rte_flow_item_eth *eth_v;
9310 : 0 : const struct rte_flow_item_eth nic_mask = {
9311 : : .hdr.dst_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
9312 : : .hdr.src_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
9313 : : .hdr.ether_type = RTE_BE16(0xffff),
9314 : : .has_vlan = 0,
9315 : : };
9316 : : void *hdrs_v;
9317 : : char *l24_v;
9318 : : unsigned int i;
9319 : :
9320 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9321 : 0 : return;
9322 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, eth_v, eth_m, &nic_mask);
# # # # ]
9323 [ # # ]: 0 : if (!eth_vv)
9324 : : eth_vv = eth_v;
9325 [ # # ]: 0 : if (inner)
9326 : 0 : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9327 : : else
9328 : : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9329 : : /* The value must be in the range of the mask. */
9330 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, dmac_47_16);
9331 [ # # ]: 0 : for (i = 0; i < sizeof(eth_m->hdr.dst_addr); ++i)
9332 : 0 : l24_v[i] = eth_m->hdr.dst_addr.addr_bytes[i] & eth_v->hdr.dst_addr.addr_bytes[i];
9333 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, smac_47_16);
9334 : : /* The value must be in the range of the mask. */
9335 [ # # ]: 0 : for (i = 0; i < sizeof(eth_m->hdr.dst_addr); ++i)
9336 : 0 : l24_v[i] = eth_m->hdr.src_addr.addr_bytes[i] & eth_v->hdr.src_addr.addr_bytes[i];
9337 : : /*
9338 : : * HW supports match on one Ethertype, the Ethertype following the last
9339 : : * VLAN tag of the packet (see PRM).
9340 : : * Set match on ethertype only if ETH header is not followed by VLAN.
9341 : : * HW is optimized for IPv4/IPv6. In such cases, avoid setting
9342 : : * ethertype, and use ip_version field instead.
9343 : : * eCPRI over Ether layer will use type value 0xAEFE.
9344 : : */
9345 [ # # ]: 0 : if (eth_m->hdr.ether_type == 0xFFFF) {
9346 : 0 : rte_be16_t type = eth_v->hdr.ether_type;
9347 : :
9348 : : /*
9349 : : * When set the matcher mask, refer to the original spec
9350 : : * value.
9351 : : */
9352 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M) {
9353 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
9354 : 0 : type = eth_vv->hdr.ether_type;
9355 : : }
9356 : : /* Set cvlan_tag mask for any single\multi\un-tagged case. */
9357 [ # # # # : 0 : switch (type) {
# ]
9358 : 0 : case RTE_BE16(RTE_ETHER_TYPE_VLAN):
9359 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
9360 : 0 : return;
9361 : 0 : case RTE_BE16(RTE_ETHER_TYPE_QINQ):
9362 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
9363 : 0 : return;
9364 : 0 : case RTE_BE16(RTE_ETHER_TYPE_IPV4):
9365 : 0 : flow_dv_set_match_ip_version(group, hdrs_v, key_type,
9366 : : 4);
9367 : 0 : return;
9368 : 0 : case RTE_BE16(RTE_ETHER_TYPE_IPV6):
9369 : 0 : flow_dv_set_match_ip_version(group, hdrs_v, key_type,
9370 : : 6);
9371 : 0 : return;
9372 : : default:
9373 : : break;
9374 : : }
9375 : : }
9376 : : /*
9377 : : * Only SW steering value should refer to the mask value.
9378 : : * Other cases are using the fake masks, just ignore the mask.
9379 : : */
9380 [ # # # # ]: 0 : if (eth_v->has_vlan && eth_m->has_vlan) {
9381 : : /*
9382 : : * Here, when also has_more_vlan field in VLAN item is
9383 : : * not set, only single-tagged packets will be matched.
9384 : : */
9385 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
9386 [ # # # # ]: 0 : if (key_type != MLX5_SET_MATCHER_HS_M && eth_vv->has_vlan)
9387 : : return;
9388 : : }
9389 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, ethertype);
9390 : 0 : *(uint16_t *)(l24_v) = eth_m->hdr.ether_type & eth_v->hdr.ether_type;
9391 : : }
9392 : :
9393 : : /**
9394 : : * Add VLAN item to the value.
9395 : : *
9396 : : * @param[in, out] key
9397 : : * Flow matcher value.
9398 : : * @param[in] item
9399 : : * Flow pattern to translate.
9400 : : * @param[in] inner
9401 : : * Item is inner pattern.
9402 : : * @param[in] wks
9403 : : * Item workspace.
9404 : : * @param[in] key_type
9405 : : * Set flow matcher mask or value.
9406 : : */
9407 : : static void
9408 : 0 : flow_dv_translate_item_vlan(void *key, const struct rte_flow_item *item,
9409 : : int inner, struct mlx5_dv_matcher_workspace *wks,
9410 : : uint32_t key_type)
9411 : : {
9412 : : const struct rte_flow_item_vlan *vlan_m;
9413 : : const struct rte_flow_item_vlan *vlan_v;
9414 : 0 : const struct rte_flow_item_vlan *vlan_vv = item->spec;
9415 : : void *hdrs_v;
9416 : : uint16_t tci_v;
9417 : :
9418 [ # # ]: 0 : if (inner) {
9419 : 0 : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
9420 : : } else {
9421 : : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9422 : : /*
9423 : : * This is workaround, masks are not supported,
9424 : : * and pre-validated.
9425 : : */
9426 [ # # ]: 0 : if (vlan_vv)
9427 [ # # ]: 0 : wks->vlan_tag = rte_be_to_cpu_16(vlan_vv->hdr.vlan_tci) & 0x0fff;
9428 : : }
9429 : : /*
9430 : : * When VLAN item exists in flow, mark packet as tagged,
9431 : : * even if TCI is not specified.
9432 : : */
9433 [ # # # # ]: 0 : if (!MLX5_GET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag))
9434 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 1);
9435 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9436 : : return;
9437 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, vlan_v, vlan_m,
# # # # ]
9438 : : &rte_flow_item_vlan_mask);
9439 [ # # ]: 0 : tci_v = rte_be_to_cpu_16(vlan_m->hdr.vlan_tci & vlan_v->hdr.vlan_tci);
9440 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_vid, tci_v);
9441 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_cfi, tci_v >> 12);
9442 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, first_prio, tci_v >> 13);
9443 : : /*
9444 : : * HW is optimized for IPv4/IPv6. In such cases, avoid setting
9445 : : * ethertype, and use ip_version field instead.
9446 : : */
9447 [ # # ]: 0 : if (vlan_m->hdr.eth_proto == 0xFFFF) {
9448 : 0 : rte_be16_t inner_type = vlan_v->hdr.eth_proto;
9449 : :
9450 : : /*
9451 : : * When set the matcher mask, refer to the original spec
9452 : : * value.
9453 : : */
9454 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M)
9455 : 0 : inner_type = vlan_vv->hdr.eth_proto;
9456 [ # # # # ]: 0 : switch (inner_type) {
9457 : 0 : case RTE_BE16(RTE_ETHER_TYPE_VLAN):
9458 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
9459 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_V)
9460 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v,
9461 : : cvlan_tag, 0);
9462 : 0 : return;
9463 : 0 : case RTE_BE16(RTE_ETHER_TYPE_IPV4):
9464 : 0 : flow_dv_set_match_ip_version
9465 : : (wks->group, hdrs_v, key_type, 4);
9466 : 0 : return;
9467 : 0 : case RTE_BE16(RTE_ETHER_TYPE_IPV6):
9468 : 0 : flow_dv_set_match_ip_version
9469 : : (wks->group, hdrs_v, key_type, 6);
9470 : 0 : return;
9471 : : default:
9472 : : break;
9473 : : }
9474 : : }
9475 [ # # # # ]: 0 : if (vlan_m->has_more_vlan && vlan_v->has_more_vlan) {
9476 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, svlan_tag, 1);
9477 : : /* Only one vlan_tag bit can be set. */
9478 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_V)
9479 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, cvlan_tag, 0);
9480 : 0 : return;
9481 : : }
9482 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, hdrs_v, ethertype,
9483 : : rte_be_to_cpu_16(vlan_m->hdr.eth_proto & vlan_v->hdr.eth_proto));
9484 : : }
9485 : :
9486 : : /**
9487 : : * Add IPV4 item to the value.
9488 : : *
9489 : : * @param[in, out] key
9490 : : * Flow matcher value.
9491 : : * @param[in] item
9492 : : * Flow pattern to translate.
9493 : : * @param[in] inner
9494 : : * Item is inner pattern.
9495 : : * @param[in] group
9496 : : * The group to insert the rule.
9497 : : * @param[in] key_type
9498 : : * Set flow matcher mask or value.
9499 : : */
9500 : : static void
9501 : 0 : flow_dv_translate_item_ipv4(void *key, const struct rte_flow_item *item,
9502 : : int inner, uint32_t group, uint32_t key_type)
9503 : : {
9504 : : const struct rte_flow_item_ipv4 *ipv4_m;
9505 : : const struct rte_flow_item_ipv4 *ipv4_v;
9506 : 0 : const struct rte_flow_item_ipv4 nic_mask = {
9507 : : .hdr = {
9508 : : .src_addr = RTE_BE32(0xffffffff),
9509 : : .dst_addr = RTE_BE32(0xffffffff),
9510 : : .type_of_service = 0xff,
9511 : : .next_proto_id = 0xff,
9512 : : .time_to_live = 0xff,
9513 : : },
9514 : : };
9515 : : void *headers_v;
9516 : : char *l24_v;
9517 : : uint8_t tos;
9518 : :
9519 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9520 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9521 : 0 : flow_dv_set_match_ip_version(group, headers_v, key_type, 4);
9522 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9523 : 0 : return;
9524 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, ipv4_v, ipv4_m, &nic_mask);
# # # # ]
9525 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
9526 : : dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
9527 : 0 : *(uint32_t *)l24_v = ipv4_m->hdr.dst_addr & ipv4_v->hdr.dst_addr;
9528 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
9529 : : src_ipv4_src_ipv6.ipv4_layout.ipv4);
9530 : 0 : *(uint32_t *)l24_v = ipv4_m->hdr.src_addr & ipv4_v->hdr.src_addr;
9531 : 0 : tos = ipv4_m->hdr.type_of_service & ipv4_v->hdr.type_of_service;
9532 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ipv4_ihl,
9533 : : ipv4_v->hdr.ihl & ipv4_m->hdr.ihl);
9534 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M)
9535 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn,
9536 : : ipv4_v->hdr.type_of_service);
9537 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, tos);
9538 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, tos >> 2);
9539 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
9540 : : ipv4_v->hdr.next_proto_id & ipv4_m->hdr.next_proto_id);
9541 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
9542 : : ipv4_v->hdr.time_to_live & ipv4_m->hdr.time_to_live);
9543 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
9544 : : !!(ipv4_v->hdr.fragment_offset & ipv4_m->hdr.fragment_offset));
9545 : : }
9546 : :
9547 : : /**
9548 : : * Add IPV6 item to the value.
9549 : : *
9550 : : * @param[in, out] key
9551 : : * Flow matcher value.
9552 : : * @param[in] item
9553 : : * Flow pattern to translate.
9554 : : * @param[in] inner
9555 : : * Item is inner pattern.
9556 : : * @param[in] group
9557 : : * The group to insert the rule.
9558 : : * @param[in] key_type
9559 : : * Set flow matcher mask or value.
9560 : : */
9561 : : static void
9562 : 0 : flow_dv_translate_item_ipv6(void *key, const struct rte_flow_item *item,
9563 : : int inner, uint32_t group, uint32_t key_type)
9564 : : {
9565 : : const struct rte_flow_item_ipv6 *ipv6_m;
9566 : : const struct rte_flow_item_ipv6 *ipv6_v;
9567 : 0 : const struct rte_flow_item_ipv6 nic_mask = {
9568 : : .hdr = {
9569 : : .src_addr = RTE_IPV6_MASK_FULL,
9570 : : .dst_addr = RTE_IPV6_MASK_FULL,
9571 : : .vtc_flow = RTE_BE32(0xffffffff),
9572 : : .proto = 0xff,
9573 : : .hop_limits = 0xff,
9574 : : },
9575 : : };
9576 : : void *headers_v;
9577 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9578 : : char *l24_v;
9579 : : uint32_t vtc_v;
9580 : : int i;
9581 : : int size;
9582 : :
9583 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9584 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9585 : 0 : flow_dv_set_match_ip_version(group, headers_v, key_type, 6);
9586 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9587 : 0 : return;
9588 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, ipv6_v, ipv6_m, &nic_mask);
# # # # ]
9589 : : size = sizeof(ipv6_m->hdr.dst_addr);
9590 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
9591 : : dst_ipv4_dst_ipv6.ipv6_layout.ipv6);
9592 [ # # ]: 0 : for (i = 0; i < size; ++i)
9593 : 0 : l24_v[i] = ipv6_m->hdr.dst_addr.a[i] & ipv6_v->hdr.dst_addr.a[i];
9594 : : l24_v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
9595 : : src_ipv4_src_ipv6.ipv6_layout.ipv6);
9596 [ # # ]: 0 : for (i = 0; i < size; ++i)
9597 : 0 : l24_v[i] = ipv6_m->hdr.src_addr.a[i] & ipv6_v->hdr.src_addr.a[i];
9598 : : /* TOS. */
9599 [ # # ]: 0 : vtc_v = rte_be_to_cpu_32(ipv6_m->hdr.vtc_flow & ipv6_v->hdr.vtc_flow);
9600 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ecn, vtc_v >> 20);
9601 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_dscp, vtc_v >> 22);
9602 : : /* Label. */
9603 [ # # ]: 0 : if (inner)
9604 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, inner_ipv6_flow_label,
9605 : : vtc_v);
9606 : : else
9607 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, outer_ipv6_flow_label,
9608 : : vtc_v);
9609 : : /* Protocol. */
9610 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
9611 : : ipv6_v->hdr.proto & ipv6_m->hdr.proto);
9612 : : /* Hop limit. */
9613 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_ttl_hoplimit,
9614 : : ipv6_v->hdr.hop_limits & ipv6_m->hdr.hop_limits);
9615 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag,
9616 : : !!(ipv6_v->has_frag_ext & ipv6_m->has_frag_ext));
9617 : : }
9618 : :
9619 : : /**
9620 : : * Add IPV6 fragment extension item to the value.
9621 : : *
9622 : : * @param[in, out] key
9623 : : * Flow matcher value.
9624 : : * @param[in] item
9625 : : * Flow pattern to translate.
9626 : : * @param[in] inner
9627 : : * Item is inner pattern.
9628 : : * @param[in] key_type
9629 : : * Set flow matcher mask or value.
9630 : : */
9631 : : static void
9632 : 0 : flow_dv_translate_item_ipv6_frag_ext(void *key,
9633 : : const struct rte_flow_item *item,
9634 : : int inner, uint32_t key_type)
9635 : : {
9636 : : const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_m;
9637 : : const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_ext_v;
9638 : 0 : const struct rte_flow_item_ipv6_frag_ext nic_mask = {
9639 : : .hdr = {
9640 : : .next_header = 0xff,
9641 : : .frag_data = RTE_BE16(0xffff),
9642 : : },
9643 : : };
9644 : : void *headers_v;
9645 : :
9646 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9647 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9648 : : /* IPv6 fragment extension item exists, so packet is IP fragment. */
9649 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, frag, 1);
9650 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9651 : 0 : return;
9652 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, ipv6_frag_ext_v,
# # # # ]
9653 : : ipv6_frag_ext_m, &nic_mask);
9654 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
9655 : : ipv6_frag_ext_v->hdr.next_header &
9656 : : ipv6_frag_ext_m->hdr.next_header);
9657 : : }
9658 : :
9659 : : /**
9660 : : * Add TCP item to the value.
9661 : : *
9662 : : * @param[in, out] key
9663 : : * Flow matcher value.
9664 : : * @param[in] item
9665 : : * Flow pattern to translate.
9666 : : * @param[in] inner
9667 : : * Item is inner pattern.
9668 : : * @param[in] key_type
9669 : : * Set flow matcher mask or value.
9670 : : */
9671 : : static void
9672 : 0 : flow_dv_translate_item_tcp(void *key, const struct rte_flow_item *item,
9673 : : int inner, uint32_t key_type)
9674 : : {
9675 : : const struct rte_flow_item_tcp *tcp_m;
9676 : : const struct rte_flow_item_tcp *tcp_v;
9677 : : void *headers_v;
9678 : :
9679 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9680 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9681 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9682 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9683 : : ip_protocol, 0xff);
9684 : : else
9685 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9686 : : ip_protocol, IPPROTO_TCP);
9687 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9688 : : return;
9689 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, tcp_v, tcp_m,
# # # # ]
9690 : : &rte_flow_item_tcp_mask);
9691 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_sport,
9692 : : rte_be_to_cpu_16(tcp_v->hdr.src_port & tcp_m->hdr.src_port));
9693 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_dport,
9694 : : rte_be_to_cpu_16(tcp_v->hdr.dst_port & tcp_m->hdr.dst_port));
9695 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, tcp_flags,
9696 : : tcp_v->hdr.tcp_flags & tcp_m->hdr.tcp_flags);
9697 : : }
9698 : :
9699 : : /**
9700 : : * Add ESP item to the value.
9701 : : *
9702 : : * @param[in, out] key
9703 : : * Flow matcher value.
9704 : : * @param[in] item
9705 : : * Flow pattern to translate.
9706 : : * @param[in] inner
9707 : : * Item is inner pattern.
9708 : : * @param[in] key_type
9709 : : * Set flow matcher mask or value.
9710 : : */
9711 : : static void
9712 : 0 : flow_dv_translate_item_esp(void *key, const struct rte_flow_item *item,
9713 : : int inner, uint32_t key_type)
9714 : : {
9715 : : const struct rte_flow_item_esp *esp_m;
9716 : : const struct rte_flow_item_esp *esp_v;
9717 : : void *headers_v;
9718 : : char *spi_v;
9719 : :
9720 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9721 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9722 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9723 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9724 : : ip_protocol, 0xff);
9725 : : else
9726 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9727 : : ip_protocol, IPPROTO_ESP);
9728 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9729 : : return;
9730 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, esp_v, esp_m,
# # # # ]
9731 : : &rte_flow_item_esp_mask);
9732 : : headers_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9733 : : spi_v = inner ? MLX5_ADDR_OF(fte_match_set_misc, headers_v,
9734 [ # # ]: 0 : inner_esp_spi) : MLX5_ADDR_OF(fte_match_set_misc
9735 : : , headers_v, outer_esp_spi);
9736 : 0 : *(uint32_t *)spi_v = esp_m->hdr.spi & esp_v->hdr.spi;
9737 : : }
9738 : :
9739 : : /**
9740 : : * Add UDP item to the value.
9741 : : *
9742 : : * @param[in, out] key
9743 : : * Flow matcher value.
9744 : : * @param[in] item
9745 : : * Flow pattern to translate.
9746 : : * @param[in] inner
9747 : : * Item is inner pattern.
9748 : : * @param[in] key_type
9749 : : * Set flow matcher mask or value.
9750 : : */
9751 : : static void
9752 : 0 : flow_dv_translate_item_udp(void *key, const struct rte_flow_item *item,
9753 : : int inner, struct mlx5_dv_matcher_workspace *wks,
9754 : : uint32_t key_type)
9755 : : {
9756 : : const struct rte_flow_item_udp *udp_m;
9757 : : const struct rte_flow_item_udp *udp_v;
9758 : : void *headers_v;
9759 : :
9760 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
9761 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9762 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9763 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9764 : : ip_protocol, 0xff);
9765 : : else
9766 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
9767 : : ip_protocol, IPPROTO_UDP);
9768 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9769 : : return;
9770 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, udp_v, udp_m,
# # # # ]
9771 : : &rte_flow_item_udp_mask);
9772 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_sport,
9773 : : rte_be_to_cpu_16(udp_v->hdr.src_port & udp_m->hdr.src_port));
9774 [ # # # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
9775 : : rte_be_to_cpu_16(udp_v->hdr.dst_port & udp_m->hdr.dst_port));
9776 : : /* Force get UDP dport in case to be used in VXLAN translate. */
9777 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_SW) {
9778 : 0 : udp_v = item->spec;
9779 [ # # ]: 0 : wks->udp_dport = rte_be_to_cpu_16(udp_v->hdr.dst_port &
9780 : : udp_m->hdr.dst_port);
9781 : : }
9782 : : }
9783 : :
9784 : : /**
9785 : : * Add GRE optional Key item to the value.
9786 : : *
9787 : : * @param[in, out] key
9788 : : * Flow matcher value.
9789 : : * @param[in] item
9790 : : * Flow pattern to translate.
9791 : : * @param[in] inner
9792 : : * Item is inner pattern.
9793 : : */
9794 : : static void
9795 : 0 : flow_dv_translate_item_gre_key(void *key, const struct rte_flow_item *item,
9796 : : uint32_t key_type)
9797 : : {
9798 : : const rte_be32_t *key_m;
9799 : : const rte_be32_t *key_v;
9800 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9801 : 0 : rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
9802 : :
9803 : : /* GRE K bit must be on and should already be validated */
9804 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_k_present, 1);
9805 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
9806 : 0 : return;
9807 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, key_v, key_m,
# # # # ]
9808 : : &gre_key_default_mask);
9809 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_key_h,
9810 : : rte_be_to_cpu_32((*key_v) & (*key_m)) >> 8);
9811 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_key_l,
9812 : : rte_be_to_cpu_32((*key_v) & (*key_m)) & 0xFF);
9813 : : }
9814 : :
9815 : : /**
9816 : : * Add GRE item to the value.
9817 : : *
9818 : : * @param[in, out] key
9819 : : * Flow matcher value.
9820 : : * @param[in] item
9821 : : * Flow pattern to translate.
9822 : : * @param[in] pattern_flags
9823 : : * Accumulated pattern flags.
9824 : : * @param[in] key_type
9825 : : * Set flow matcher mask or value.
9826 : : */
9827 : : static void
9828 : 0 : flow_dv_translate_item_gre(void *key, const struct rte_flow_item *item,
9829 : : uint64_t pattern_flags, uint32_t key_type)
9830 : : {
9831 : : static const struct rte_flow_item_gre empty_gre = {0,};
9832 : 0 : const struct rte_flow_item_gre *gre_m = item->mask;
9833 : 0 : const struct rte_flow_item_gre *gre_v = item->spec;
9834 : : void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
9835 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
9836 : : struct {
9837 : : union {
9838 : : __extension__
9839 : : struct {
9840 : : uint16_t version:3;
9841 : : uint16_t rsvd0:9;
9842 : : uint16_t s_present:1;
9843 : : uint16_t k_present:1;
9844 : : uint16_t rsvd_bit1:1;
9845 : : uint16_t c_present:1;
9846 : : };
9847 : : uint16_t value;
9848 : : };
9849 : : } gre_crks_rsvd0_ver_m, gre_crks_rsvd0_ver_v;
9850 : : uint16_t protocol_m, protocol_v;
9851 : :
9852 : : /* Common logic to SWS/HWS */
9853 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9854 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, 0xff);
9855 : : else
9856 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
9857 : : IPPROTO_GRE);
9858 : : /* HWS mask logic only */
9859 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_HS_M) {
9860 [ # # ]: 0 : if (!gre_m)
9861 : : gre_m = &empty_gre;
9862 : : gre_v = gre_m;
9863 [ # # ]: 0 : } else if (!gre_v) {
9864 : : gre_v = &empty_gre;
9865 : : gre_m = &empty_gre;
9866 [ # # ]: 0 : } else if (!gre_m) {
9867 : : gre_m = &rte_flow_item_gre_mask;
9868 : : }
9869 : : /* SWS logic only */
9870 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_SW_M)
9871 : : gre_v = gre_m;
9872 [ # # ]: 0 : gre_crks_rsvd0_ver_m.value = rte_be_to_cpu_16(gre_m->c_rsvd0_ver);
9873 [ # # ]: 0 : gre_crks_rsvd0_ver_v.value = rte_be_to_cpu_16(gre_v->c_rsvd0_ver);
9874 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_c_present,
9875 : : gre_crks_rsvd0_ver_v.c_present &
9876 : : gre_crks_rsvd0_ver_m.c_present);
9877 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_k_present,
9878 : : gre_crks_rsvd0_ver_v.k_present &
9879 : : gre_crks_rsvd0_ver_m.k_present);
9880 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_s_present,
9881 : : gre_crks_rsvd0_ver_v.s_present &
9882 : : gre_crks_rsvd0_ver_m.s_present);
9883 [ # # ]: 0 : protocol_m = rte_be_to_cpu_16(gre_m->protocol);
9884 [ # # ]: 0 : protocol_v = rte_be_to_cpu_16(gre_v->protocol);
9885 [ # # ]: 0 : if (!protocol_m) {
9886 : : /* Force next protocol to prevent matchers duplication */
9887 : : protocol_v = mlx5_translate_tunnel_etypes(pattern_flags);
9888 : : if (protocol_v)
9889 : : protocol_m = 0xFFFF;
9890 : : /* Restore the value to mask in mask case. */
9891 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
9892 : : protocol_v = protocol_m;
9893 : : }
9894 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, gre_protocol,
9895 : : protocol_m & protocol_v);
9896 : 0 : }
9897 : :
9898 : : /**
9899 : : * Add GRE optional items to the value.
9900 : : *
9901 : : * @param[in, out] key
9902 : : * Flow matcher value.
9903 : : * @param[in] item
9904 : : * Flow pattern to translate.
9905 : : * @param[in] gre_item
9906 : : * Pointer to gre_item.
9907 : : * @param[in] pattern_flags
9908 : : * Accumulated pattern flags.
9909 : : * @param[in] key_type
9910 : : * Set flow matcher mask or value.
9911 : : */
9912 : : static void
9913 : 0 : flow_dv_translate_item_gre_option(void *key,
9914 : : const struct rte_flow_item *item,
9915 : : const struct rte_flow_item *gre_item,
9916 : : uint64_t pattern_flags, uint32_t key_type)
9917 : : {
9918 : : void *misc5_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_5);
9919 : 0 : const struct rte_flow_item_gre_opt *option_m = item->mask;
9920 : 0 : const struct rte_flow_item_gre_opt *option_v = item->spec;
9921 : 0 : const struct rte_flow_item_gre *gre_m = gre_item->mask;
9922 : 0 : const struct rte_flow_item_gre *gre_v = gre_item->spec;
9923 : : static const struct rte_flow_item_gre empty_gre = {0};
9924 : : struct rte_flow_item gre_key_item;
9925 : : uint16_t c_rsvd0_ver_m, c_rsvd0_ver_v;
9926 : : uint16_t protocol_m, protocol_v;
9927 : :
9928 : : /*
9929 : : * If only match key field, keep using misc for matching.
9930 : : * If need to match checksum or sequence, using misc5 and do
9931 : : * not need using misc.
9932 : : */
9933 [ # # ]: 0 : if (!(option_m->sequence.sequence ||
9934 [ # # ]: 0 : option_m->checksum_rsvd.checksum)) {
9935 : 0 : flow_dv_translate_item_gre(key, gre_item, pattern_flags, key_type);
9936 : 0 : gre_key_item.spec = &option_v->key.key;
9937 : 0 : gre_key_item.mask = &option_m->key.key;
9938 : 0 : flow_dv_translate_item_gre_key(key, &gre_key_item, key_type);
9939 : 0 : return;
9940 : : }
9941 [ # # ]: 0 : if (!gre_v) {
9942 : : gre_v = &empty_gre;
9943 : : gre_m = &empty_gre;
9944 : : } else {
9945 [ # # ]: 0 : if (!gre_m)
9946 : : gre_m = &rte_flow_item_gre_mask;
9947 : : }
9948 : 0 : protocol_v = gre_v->protocol;
9949 : 0 : protocol_m = gre_m->protocol;
9950 [ # # ]: 0 : if (!protocol_m) {
9951 : : /* Force next protocol to prevent matchers duplication */
9952 : : uint16_t ether_type =
9953 : : mlx5_translate_tunnel_etypes(pattern_flags);
9954 : : if (ether_type) {
9955 [ # # ]: 0 : protocol_v = rte_be_to_cpu_16(ether_type);
9956 : : protocol_m = UINT16_MAX;
9957 : : }
9958 : : }
9959 : 0 : c_rsvd0_ver_v = gre_v->c_rsvd0_ver;
9960 : 0 : c_rsvd0_ver_m = gre_m->c_rsvd0_ver;
9961 [ # # ]: 0 : if (option_m->sequence.sequence) {
9962 : 0 : c_rsvd0_ver_v |= RTE_BE16(0x1000);
9963 : 0 : c_rsvd0_ver_m |= RTE_BE16(0x1000);
9964 : : }
9965 [ # # ]: 0 : if (option_m->key.key) {
9966 : 0 : c_rsvd0_ver_v |= RTE_BE16(0x2000);
9967 : 0 : c_rsvd0_ver_m |= RTE_BE16(0x2000);
9968 : : }
9969 [ # # ]: 0 : if (option_m->checksum_rsvd.checksum) {
9970 : 0 : c_rsvd0_ver_v |= RTE_BE16(0x8000);
9971 : 0 : c_rsvd0_ver_m |= RTE_BE16(0x8000);
9972 : : }
9973 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
9974 : : c_rsvd0_ver_v = c_rsvd0_ver_m;
9975 : : protocol_v = protocol_m;
9976 : : option_v = option_m;
9977 : : }
9978 : : /*
9979 : : * Hardware parses GRE optional field into the fixed location,
9980 : : * do not need to adjust the tunnel dword indices.
9981 : : */
9982 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_0,
9983 : : rte_be_to_cpu_32((c_rsvd0_ver_v | protocol_v << 16) &
9984 : : (c_rsvd0_ver_m | protocol_m << 16)));
9985 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_1,
9986 : : rte_be_to_cpu_32(option_v->checksum_rsvd.checksum &
9987 : : option_m->checksum_rsvd.checksum));
9988 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_2,
9989 : : rte_be_to_cpu_32(option_v->key.key & option_m->key.key));
9990 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_3,
9991 : : rte_be_to_cpu_32(option_v->sequence.sequence &
9992 : : option_m->sequence.sequence));
9993 : : }
9994 : :
9995 : : /**
9996 : : * Add NVGRE item to matcher and to the value.
9997 : : *
9998 : : * @param[in, out] key
9999 : : * Flow matcher value.
10000 : : * @param[in] item
10001 : : * Flow pattern to translate.
10002 : : * @param[in] pattern_flags
10003 : : * Accumulated pattern flags.
10004 : : * @param[in] key_type
10005 : : * Set flow matcher mask or value.
10006 : : */
10007 : : static void
10008 : 0 : flow_dv_translate_item_nvgre(void *key, const struct rte_flow_item *item,
10009 : : unsigned long pattern_flags, uint32_t key_type)
10010 : : {
10011 : : const struct rte_flow_item_nvgre *nvgre_m;
10012 : : const struct rte_flow_item_nvgre *nvgre_v;
10013 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10014 : : const char *tni_flow_id_m;
10015 : : const char *tni_flow_id_v;
10016 : : char *gre_key_v;
10017 : : int size;
10018 : : int i;
10019 : :
10020 : : /* For NVGRE, GRE header fields must be set with defined values. */
10021 : 0 : const struct rte_flow_item_gre gre_spec = {
10022 : : .c_rsvd0_ver = RTE_BE16(0x2000),
10023 : : .protocol = RTE_BE16(RTE_ETHER_TYPE_TEB)
10024 : : };
10025 : 0 : const struct rte_flow_item_gre gre_mask = {
10026 : : .c_rsvd0_ver = RTE_BE16(0xB000),
10027 : : .protocol = RTE_BE16(UINT16_MAX),
10028 : : };
10029 : 0 : const struct rte_flow_item gre_item = {
10030 : : .spec = &gre_spec,
10031 : : .mask = &gre_mask,
10032 : : .last = NULL,
10033 : : };
10034 : 0 : flow_dv_translate_item_gre(key, &gre_item, pattern_flags, key_type);
10035 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10036 : 0 : return;
10037 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, nvgre_v, nvgre_m,
# # # # ]
10038 : : &rte_flow_item_nvgre_mask);
10039 : 0 : tni_flow_id_m = (const char *)nvgre_m->tni;
10040 : 0 : tni_flow_id_v = (const char *)nvgre_v->tni;
10041 : : size = sizeof(nvgre_m->tni) + sizeof(nvgre_m->flow_id);
10042 : 0 : gre_key_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, gre_key_h);
10043 [ # # ]: 0 : for (i = 0; i < size; ++i)
10044 : 0 : gre_key_v[i] = tni_flow_id_m[i] & tni_flow_id_v[i];
10045 : : }
10046 : :
10047 : : /**
10048 : : * Add VXLAN item to the value.
10049 : : *
10050 : : * @param[in] dev
10051 : : * Pointer to the Ethernet device structure.
10052 : : * @param[in] attr
10053 : : * Flow rule attributes.
10054 : : * @param[in, out] key
10055 : : * Flow matcher value.
10056 : : * @param[in] item
10057 : : * Flow pattern to translate.
10058 : : * @param[in] inner
10059 : : * Item is inner pattern.
10060 : : * @param[in] wks
10061 : : * Matcher workspace.
10062 : : * @param[in] key_type
10063 : : * Set flow matcher mask or value.
10064 : : */
10065 : : static void
10066 : 0 : flow_dv_translate_item_vxlan(struct rte_eth_dev *dev,
10067 : : const struct rte_flow_attr *attr,
10068 : : void *key, const struct rte_flow_item *item,
10069 : : int inner, struct mlx5_dv_matcher_workspace *wks,
10070 : : uint32_t key_type)
10071 : : {
10072 : : const struct rte_flow_item_vxlan *vxlan_m;
10073 : : const struct rte_flow_item_vxlan *vxlan_v;
10074 : : void *headers_v;
10075 : : void *misc_v;
10076 : : void *misc5_v;
10077 : : uint32_t tunnel_v;
10078 : : char *vni_v;
10079 : : uint16_t dport;
10080 : : int size;
10081 : : int i;
10082 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10083 : 0 : const struct rte_flow_item_vxlan nic_mask = {
10084 : : .hdr.vni = { 0xff, 0xff, 0xff },
10085 : : .hdr.rsvd1 = 0xff,
10086 : : };
10087 : :
10088 : : misc5_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_5);
10089 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
10090 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10091 [ # # ]: 0 : dport = item->type == RTE_FLOW_ITEM_TYPE_VXLAN ?
10092 : : MLX5_UDP_PORT_VXLAN : MLX5_UDP_PORT_VXLAN_GPE;
10093 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
10094 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10095 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
10096 : : udp_dport, 0xFFFF);
10097 : : else
10098 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
10099 : : udp_dport, dport);
10100 : : }
10101 : : /*
10102 : : * Read the UDP dport to check if the value satisfies the VXLAN
10103 : : * matching with MISC5 for CX5.
10104 : : */
10105 [ # # ]: 0 : if (wks->udp_dport)
10106 : : dport = wks->udp_dport;
10107 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10108 : 0 : return;
10109 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, vxlan_v, vxlan_m, &nic_mask);
# # # # ]
10110 : : if ((item->mask == &nic_mask) &&
10111 : : ((!attr->group && !(attr->transfer && priv->fdb_def_rule) &&
10112 : : !priv->sh->tunnel_header_0_1) ||
10113 : : ((attr->group || (attr->transfer && priv->fdb_def_rule)) &&
10114 : : !priv->sh->misc5_cap)))
10115 : : vxlan_m = &rte_flow_item_vxlan_mask;
10116 [ # # ]: 0 : if ((priv->sh->steering_format_version ==
10117 [ # # ]: 0 : MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5 &&
10118 : 0 : dport != MLX5_UDP_PORT_VXLAN) ||
10119 [ # # # # : 0 : (!attr->group && !(attr->transfer && priv->fdb_def_rule)) ||
# # # # ]
10120 [ # # # # ]: 0 : ((attr->group || (attr->transfer && priv->fdb_def_rule)) &&
10121 [ # # ]: 0 : !priv->sh->misc5_cap)) {
10122 : : misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10123 : : size = sizeof(vxlan_m->hdr.vni);
10124 : 0 : vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, vxlan_vni);
10125 [ # # ]: 0 : for (i = 0; i < size; ++i)
10126 : 0 : vni_v[i] = vxlan_m->hdr.vni[i] & vxlan_v->hdr.vni[i];
10127 : : return;
10128 : : }
10129 : 0 : tunnel_v = (vxlan_v->hdr.vni[0] & vxlan_m->hdr.vni[0]) |
10130 : 0 : (vxlan_v->hdr.vni[1] & vxlan_m->hdr.vni[1]) << 8 |
10131 : 0 : (vxlan_v->hdr.vni[2] & vxlan_m->hdr.vni[2]) << 16;
10132 : 0 : tunnel_v |= (vxlan_v->hdr.rsvd1 & vxlan_m->hdr.rsvd1) << 24;
10133 [ # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_1, RTE_BE32(tunnel_v));
10134 : : }
10135 : :
10136 : : /**
10137 : : * Add VXLAN-GPE item to the value.
10138 : : *
10139 : : * @param[in, out] key
10140 : : * Flow matcher value.
10141 : : * @param[in] item
10142 : : * Flow pattern to translate.
10143 : : * @param[in] pattern_flags
10144 : : * Item pattern flags.
10145 : : * @param[in] key_type
10146 : : * Set flow matcher mask or value.
10147 : : */
10148 : :
10149 : : static void
10150 : 0 : flow_dv_translate_item_vxlan_gpe(void *key, const struct rte_flow_item *item,
10151 : : const uint64_t pattern_flags,
10152 : : uint32_t key_type)
10153 : : {
10154 : : static const struct rte_flow_item_vxlan_gpe dummy_vxlan_gpe_hdr = {{{0}}};
10155 : 0 : const struct rte_flow_item_vxlan_gpe *vxlan_m = item->mask;
10156 : 0 : const struct rte_flow_item_vxlan_gpe *vxlan_v = item->spec;
10157 : : /* The item was validated to be on the outer side */
10158 : : void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10159 : : void *misc_v =
10160 : : MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
10161 : 0 : char *vni_v =
10162 : : MLX5_ADDR_OF(fte_match_set_misc3, misc_v, outer_vxlan_gpe_vni);
10163 : : int i, size = sizeof(vxlan_m->hdr.vni);
10164 : : uint8_t flags_m = 0xff;
10165 : : uint8_t flags_v = 0xc;
10166 : : uint8_t m_protocol, v_protocol;
10167 : :
10168 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
10169 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10170 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
10171 : : 0xFFFF);
10172 : : else
10173 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
10174 : : MLX5_UDP_PORT_VXLAN_GPE);
10175 : : }
10176 [ # # ]: 0 : if (!vxlan_v) {
10177 : : vxlan_v = &dummy_vxlan_gpe_hdr;
10178 : : vxlan_m = &dummy_vxlan_gpe_hdr;
10179 : : } else {
10180 [ # # ]: 0 : if (!vxlan_m)
10181 : : vxlan_m = &rte_flow_item_vxlan_gpe_mask;
10182 : : }
10183 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10184 : : vxlan_v = vxlan_m;
10185 [ # # ]: 0 : else if (key_type == MLX5_SET_MATCHER_HS_V)
10186 : : vxlan_m = vxlan_v;
10187 [ # # ]: 0 : if (vxlan_m->hdr.flags) {
10188 : : flags_m = vxlan_m->hdr.flags;
10189 : 0 : flags_v = vxlan_v->hdr.flags;
10190 : : }
10191 : 0 : m_protocol = vxlan_m->hdr.protocol;
10192 : 0 : v_protocol = vxlan_v->hdr.protocol;
10193 [ # # ]: 0 : if (!m_protocol) {
10194 : : /* Force next protocol to ensure next headers parsing. */
10195 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_NSH)
10196 : : v_protocol = RTE_VXLAN_GPE_TYPE_NSH;
10197 [ # # ]: 0 : else if (pattern_flags & MLX5_FLOW_LAYER_INNER_L2)
10198 : : v_protocol = RTE_VXLAN_GPE_TYPE_ETH;
10199 [ # # ]: 0 : else if (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV4)
10200 : : v_protocol = RTE_VXLAN_GPE_TYPE_IPV4;
10201 [ # # ]: 0 : else if (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV6)
10202 : : v_protocol = RTE_VXLAN_GPE_TYPE_IPV6;
10203 [ # # ]: 0 : if (v_protocol)
10204 : : m_protocol = 0xFF;
10205 : : /* Restore the value to mask in mask case. */
10206 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10207 : : v_protocol = m_protocol;
10208 : : }
10209 : : /*
10210 : : * If only match flags/protocol/vni field, keep using misc3 for matching.
10211 : : * If need to match rsvd0 or rsvd1, using misc5 and do not need using misc3.
10212 : : */
10213 [ # # # # : 0 : if (!(vxlan_m->hdr.rsvd0[0] || vxlan_m->hdr.rsvd0[1] || vxlan_m->hdr.rsvd1)) {
# # ]
10214 [ # # ]: 0 : for (i = 0; i < size; ++i)
10215 : 0 : vni_v[i] = vxlan_m->hdr.vni[i] & vxlan_v->hdr.vni[i];
10216 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc_v, outer_vxlan_gpe_flags,
10217 : : flags_m & flags_v);
10218 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc_v,
10219 : : outer_vxlan_gpe_next_protocol, m_protocol & v_protocol);
10220 : : } else {
10221 : : uint32_t tunnel_v;
10222 : : void *misc5_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_5);
10223 : :
10224 : 0 : tunnel_v = (flags_m & flags_v) << 24 |
10225 : 0 : (vxlan_v->hdr.rsvd0[0] & vxlan_m->hdr.rsvd0[0]) << 16 |
10226 : 0 : (vxlan_v->hdr.rsvd0[1] & vxlan_m->hdr.rsvd0[1]) << 8 |
10227 : 0 : (m_protocol & v_protocol);
10228 [ # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_0, tunnel_v);
10229 : 0 : tunnel_v = (vxlan_v->hdr.vni[0] & vxlan_m->hdr.vni[0]) << 24 |
10230 : 0 : (vxlan_v->hdr.vni[1] & vxlan_m->hdr.vni[1]) << 16 |
10231 : 0 : (vxlan_v->hdr.vni[2] & vxlan_m->hdr.vni[2]) << 8 |
10232 : 0 : (vxlan_v->hdr.rsvd1 & vxlan_m->hdr.rsvd1);
10233 [ # # ]: 0 : MLX5_SET(fte_match_set_misc5, misc5_v, tunnel_header_1, tunnel_v);
10234 : : }
10235 : 0 : }
10236 : :
10237 : : /**
10238 : : * Add Geneve item to the value.
10239 : : *
10240 : : * @param[in, out] key
10241 : : * Flow matcher value.
10242 : : * @param[in] item
10243 : : * Flow pattern to translate.
10244 : : * @param[in] pattern_flags
10245 : : * Item pattern flags.
10246 : : * @param[in] key_type
10247 : : * Set flow matcher mask or value.
10248 : : */
10249 : :
10250 : : static void
10251 : 0 : flow_dv_translate_item_geneve(void *key, const struct rte_flow_item *item,
10252 : : uint64_t pattern_flags, uint32_t key_type)
10253 : : {
10254 : : static const struct rte_flow_item_geneve empty_geneve = {0,};
10255 : 0 : const struct rte_flow_item_geneve *geneve_m = item->mask;
10256 : 0 : const struct rte_flow_item_geneve *geneve_v = item->spec;
10257 : : /* GENEVE flow item validation allows single tunnel item */
10258 : : void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10259 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10260 : : uint16_t gbhdr_m;
10261 : : uint16_t gbhdr_v;
10262 : 0 : char *vni_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, geneve_vni);
10263 : : size_t size = sizeof(geneve_m->vni), i;
10264 : : uint16_t protocol_m, protocol_v;
10265 : :
10266 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
10267 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10268 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
10269 : : 0xFFFF);
10270 : : else
10271 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport,
10272 : : MLX5_UDP_PORT_GENEVE);
10273 : : }
10274 [ # # ]: 0 : if (!geneve_v) {
10275 : : geneve_v = &empty_geneve;
10276 : : geneve_m = &empty_geneve;
10277 : : } else {
10278 [ # # ]: 0 : if (!geneve_m)
10279 : : geneve_m = &rte_flow_item_geneve_mask;
10280 : : }
10281 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10282 : : geneve_v = geneve_m;
10283 [ # # ]: 0 : else if (key_type == MLX5_SET_MATCHER_HS_V)
10284 : : geneve_m = geneve_v;
10285 [ # # ]: 0 : for (i = 0; i < size; ++i)
10286 : 0 : vni_v[i] = geneve_m->vni[i] & geneve_v->vni[i];
10287 [ # # ]: 0 : gbhdr_m = rte_be_to_cpu_16(geneve_m->ver_opt_len_o_c_rsvd0);
10288 [ # # ]: 0 : gbhdr_v = rte_be_to_cpu_16(geneve_v->ver_opt_len_o_c_rsvd0);
10289 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, geneve_oam,
10290 : : MLX5_GENEVE_OAMF_VAL(gbhdr_v) & MLX5_GENEVE_OAMF_VAL(gbhdr_m));
10291 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, geneve_opt_len,
10292 : : MLX5_GENEVE_OPTLEN_VAL(gbhdr_v) &
10293 : : MLX5_GENEVE_OPTLEN_VAL(gbhdr_m));
10294 [ # # ]: 0 : protocol_m = rte_be_to_cpu_16(geneve_m->protocol);
10295 [ # # ]: 0 : protocol_v = rte_be_to_cpu_16(geneve_v->protocol);
10296 [ # # ]: 0 : if (!protocol_m) {
10297 : : /* Force next protocol to prevent matchers duplication */
10298 : : protocol_v = mlx5_translate_tunnel_etypes(pattern_flags);
10299 : : if (protocol_v)
10300 : : protocol_m = 0xFFFF;
10301 : : /* Restore the value to mask in mask case. */
10302 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10303 : : protocol_v = protocol_m;
10304 : : }
10305 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, geneve_protocol_type,
10306 : : protocol_m & protocol_v);
10307 : 0 : }
10308 : :
10309 : : /**
10310 : : * Create Geneve TLV option resource.
10311 : : *
10312 : : * @param[in, out] dev
10313 : : * Pointer to rte_eth_dev structure.
10314 : : * @param[in] item
10315 : : * Flow pattern to translate.
10316 : : * @param[out] error
10317 : : * pointer to error structure.
10318 : : *
10319 : : * @return
10320 : : * 0 on success otherwise -errno and errno is set.
10321 : : */
10322 : : static int
10323 : 0 : flow_dev_geneve_tlv_option_resource_register(struct rte_eth_dev *dev,
10324 : : const struct rte_flow_item *item,
10325 : : struct rte_flow_error *error)
10326 : : {
10327 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10328 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
10329 : 0 : struct mlx5_geneve_tlv_option_resource *geneve_opt_resource =
10330 : : sh->geneve_tlv_option_resource;
10331 : : struct mlx5_devx_obj *obj;
10332 : 0 : const struct rte_flow_item_geneve_opt *geneve_opt_v = item->spec;
10333 : : int ret = 0;
10334 : :
10335 : : MLX5_ASSERT(sh->config.dv_flow_en == 1);
10336 [ # # ]: 0 : if (!geneve_opt_v)
10337 : : return -1;
10338 : 0 : rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
10339 [ # # ]: 0 : if (geneve_opt_resource != NULL) {
10340 : 0 : if (geneve_opt_resource->option_class ==
10341 : : geneve_opt_v->option_class &&
10342 : : geneve_opt_resource->option_type ==
10343 [ # # ]: 0 : geneve_opt_v->option_type &&
10344 : : geneve_opt_resource->length ==
10345 : : geneve_opt_v->option_len) {
10346 : 0 : rte_atomic_fetch_add_explicit(&geneve_opt_resource->refcnt, 1,
10347 : : rte_memory_order_relaxed);
10348 : : } else {
10349 : 0 : ret = rte_flow_error_set(error, ENOMEM,
10350 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10351 : : "Only one GENEVE TLV option supported");
10352 : 0 : goto exit;
10353 : : }
10354 : : } else {
10355 : 0 : struct mlx5_devx_geneve_tlv_option_attr attr = {
10356 : 0 : .option_class = geneve_opt_v->option_class,
10357 : 0 : .option_type = geneve_opt_v->option_type,
10358 : 0 : .option_data_len = geneve_opt_v->option_len,
10359 : : };
10360 : :
10361 : : /* Create a GENEVE TLV object and resource. */
10362 : 0 : obj = mlx5_devx_cmd_create_geneve_tlv_option(sh->cdev->ctx,
10363 : : &attr);
10364 [ # # ]: 0 : if (!obj) {
10365 : 0 : ret = rte_flow_error_set(error, ENODATA,
10366 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10367 : : "Failed to create GENEVE TLV Devx object");
10368 : 0 : goto exit;
10369 : : }
10370 : 0 : sh->geneve_tlv_option_resource =
10371 : 0 : mlx5_malloc(MLX5_MEM_ZERO,
10372 : : sizeof(*geneve_opt_resource),
10373 : : 0, SOCKET_ID_ANY);
10374 [ # # ]: 0 : if (!sh->geneve_tlv_option_resource) {
10375 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
10376 : 0 : ret = rte_flow_error_set(error, ENOMEM,
10377 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
10378 : : "GENEVE TLV object memory allocation failed");
10379 : 0 : goto exit;
10380 : : }
10381 : : geneve_opt_resource = sh->geneve_tlv_option_resource;
10382 : 0 : geneve_opt_resource->obj = obj;
10383 : 0 : geneve_opt_resource->option_class = geneve_opt_v->option_class;
10384 : 0 : geneve_opt_resource->option_type = geneve_opt_v->option_type;
10385 : 0 : geneve_opt_resource->length = geneve_opt_v->option_len;
10386 : 0 : rte_atomic_store_explicit(&geneve_opt_resource->refcnt, 1,
10387 : : rte_memory_order_relaxed);
10388 : : }
10389 : 0 : exit:
10390 : : rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
10391 : 0 : return ret;
10392 : : }
10393 : :
10394 : : /**
10395 : : * Add Geneve TLV option item to value.
10396 : : *
10397 : : * @param[in, out] dev
10398 : : * Pointer to rte_eth_dev structure.
10399 : : * @param[in, out] key
10400 : : * Flow matcher value.
10401 : : * @param[in] item
10402 : : * Flow pattern to translate.
10403 : : * @param[in] key_type
10404 : : * Set flow matcher mask or value.
10405 : : * @param[out] error
10406 : : * Pointer to error structure.
10407 : : */
10408 : : static int
10409 : 0 : flow_dv_translate_item_geneve_opt(struct rte_eth_dev *dev, void *key,
10410 : : const struct rte_flow_item *item,
10411 : : uint32_t key_type,
10412 : : struct rte_flow_error *error)
10413 : : {
10414 : : const struct rte_flow_item_geneve_opt *geneve_opt_m;
10415 : : const struct rte_flow_item_geneve_opt *geneve_opt_v;
10416 : 0 : const struct rte_flow_item_geneve_opt *orig_spec = item->spec;
10417 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
10418 : 0 : rte_be32_t opt_data_key = 0, opt_data_mask = 0;
10419 : : size_t option_byte_len;
10420 : : int ret = 0;
10421 : :
10422 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type) || !orig_spec)
# # # # #
# # # ]
10423 : : return -1;
10424 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, geneve_opt_v, geneve_opt_m,
# # # # ]
10425 : : &rte_flow_item_geneve_opt_mask);
10426 : : /*
10427 : : * Register resource requires item spec for SW steering,
10428 : : * for HW steering resources is registered explicitly by user.
10429 : : */
10430 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_SW_V) {
10431 : 0 : ret = flow_dev_geneve_tlv_option_resource_register(dev, item,
10432 : : error);
10433 [ # # ]: 0 : if (ret) {
10434 : 0 : DRV_LOG(ERR, "Failed to create geneve_tlv_obj");
10435 : 0 : return ret;
10436 : : }
10437 : : }
10438 : : /* Convert the option length from DW to bytes for using memcpy. */
10439 : 0 : option_byte_len = RTE_MIN((size_t)(orig_spec->option_len * 4),
10440 : : sizeof(rte_be32_t));
10441 [ # # ]: 0 : if (geneve_opt_v->data) {
10442 : : memcpy(&opt_data_key, geneve_opt_v->data, option_byte_len);
10443 : 0 : memcpy(&opt_data_mask, geneve_opt_m->data, option_byte_len);
10444 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v,
10445 : : geneve_tlv_option_0_data,
10446 : : rte_be_to_cpu_32(opt_data_key & opt_data_mask));
10447 : : }
10448 : : return ret;
10449 : : }
10450 : :
10451 : : /**
10452 : : * Add MPLS item to the value.
10453 : : *
10454 : : * @param[in, out] key
10455 : : * Flow matcher value.
10456 : : * @param[in] item
10457 : : * Flow pattern to translate.
10458 : : * @param[in] prev_layer
10459 : : * The protocol layer indicated in previous item.
10460 : : * @param[in] inner
10461 : : * Item is inner pattern.
10462 : : * @param[in] key_type
10463 : : * Set flow matcher mask or value.
10464 : : */
10465 : : static void
10466 : 0 : flow_dv_translate_item_mpls(void *key, const struct rte_flow_item *item,
10467 : : uint64_t prev_layer, int inner,
10468 : : uint32_t key_type)
10469 : : {
10470 : : const uint32_t *in_mpls_m;
10471 : : const uint32_t *in_mpls_v;
10472 : : uint32_t *out_mpls_v = 0;
10473 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10474 : 0 : void *misc2_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
10475 : : void *headers_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
10476 : :
10477 [ # # # ]: 0 : switch (prev_layer) {
10478 : 0 : case MLX5_FLOW_LAYER_OUTER_L4_UDP:
10479 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
10480 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10481 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
10482 : : udp_dport, 0xffff);
10483 : : else
10484 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
10485 : : udp_dport, MLX5_UDP_PORT_MPLS);
10486 : : }
10487 : : break;
10488 : 0 : case MLX5_FLOW_LAYER_GRE:
10489 : : /* Fall-through. */
10490 : : case MLX5_FLOW_LAYER_GRE_KEY:
10491 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_misc, misc_v, gre_protocol)) {
10492 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10493 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v,
10494 : : gre_protocol, 0xffff);
10495 : : else
10496 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v,
10497 : : gre_protocol, RTE_ETHER_TYPE_MPLS);
10498 : : }
10499 : : break;
10500 : : default:
10501 : : break;
10502 : : }
10503 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10504 : : return;
10505 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, in_mpls_v, in_mpls_m,
# # # # ]
10506 : : &rte_flow_item_mpls_mask);
10507 [ # # # ]: 0 : switch (prev_layer) {
10508 : 0 : case MLX5_FLOW_LAYER_OUTER_L4_UDP:
10509 : 0 : out_mpls_v =
10510 : : (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
10511 : : outer_first_mpls_over_udp);
10512 : 0 : break;
10513 : 0 : case MLX5_FLOW_LAYER_GRE:
10514 : 0 : out_mpls_v =
10515 : : (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2, misc2_v,
10516 : : outer_first_mpls_over_gre);
10517 : 0 : break;
10518 : 0 : default:
10519 : : /* Inner MPLS not over GRE is not supported. */
10520 [ # # ]: 0 : if (!inner)
10521 : : out_mpls_v =
10522 : : (uint32_t *)MLX5_ADDR_OF(fte_match_set_misc2,
10523 : : misc2_v,
10524 : : outer_first_mpls);
10525 : : break;
10526 : : }
10527 : : if (out_mpls_v)
10528 : 0 : *out_mpls_v = *in_mpls_v & *in_mpls_m;
10529 : : }
10530 : :
10531 : : /**
10532 : : * Add metadata register item to matcher
10533 : : *
10534 : : * @param[in, out] key
10535 : : * Flow matcher value.
10536 : : * @param[in] reg_type
10537 : : * Type of device metadata register
10538 : : * @param[in] data
10539 : : * Register data
10540 : : * @param[in] mask
10541 : : * Register mask
10542 : : */
10543 : : static void
10544 : 0 : flow_dv_match_meta_reg(void *key, enum modify_reg reg_type,
10545 : : uint32_t data, uint32_t mask)
10546 : : {
10547 : : void *misc2_v =
10548 : : MLX5_ADDR_OF(fte_match_param, key, misc_parameters_2);
10549 : : uint32_t temp;
10550 : :
10551 [ # # ]: 0 : if (!key)
10552 : : return;
10553 : 0 : data &= mask;
10554 [ # # # # : 0 : switch (reg_type) {
# # # # #
# # ]
10555 : 0 : case REG_A:
10556 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_a, data);
10557 : 0 : break;
10558 : 0 : case REG_B:
10559 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_b, data);
10560 : 0 : break;
10561 : 0 : case REG_C_0:
10562 : : /*
10563 : : * The metadata register C0 field might be divided into
10564 : : * source vport index and META item value, we should set
10565 : : * this field according to specified mask, not as whole one.
10566 : : */
10567 [ # # ]: 0 : temp = MLX5_GET(fte_match_set_misc2, misc2_v, metadata_reg_c_0);
10568 [ # # ]: 0 : if (mask)
10569 : 0 : temp &= ~mask;
10570 : 0 : temp |= data;
10571 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_0, temp);
10572 : 0 : break;
10573 : 0 : case REG_C_1:
10574 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_1, data);
10575 : 0 : break;
10576 : 0 : case REG_C_2:
10577 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_2, data);
10578 : 0 : break;
10579 : 0 : case REG_C_3:
10580 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_3, data);
10581 : 0 : break;
10582 : 0 : case REG_C_4:
10583 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_4, data);
10584 : 0 : break;
10585 : 0 : case REG_C_5:
10586 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_5, data);
10587 : 0 : break;
10588 : 0 : case REG_C_6:
10589 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_6, data);
10590 : 0 : break;
10591 : 0 : case REG_C_7:
10592 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_v, metadata_reg_c_7, data);
10593 : 0 : break;
10594 : : default:
10595 : : MLX5_ASSERT(false);
10596 : : break;
10597 : : }
10598 : : }
10599 : :
10600 : : /**
10601 : : * Add metadata register item to matcher
10602 : : *
10603 : : * @param[in, out] matcher
10604 : : * Flow matcher.
10605 : : * @param[in, out] key
10606 : : * Flow matcher value.
10607 : : * @param[in] reg_type
10608 : : * Type of device metadata register
10609 : : * @param[in] value
10610 : : * Register value
10611 : : * @param[in] mask
10612 : : * Register mask
10613 : : */
10614 : : static void
10615 : : flow_dv_match_meta_reg_all(void *matcher, void *key, enum modify_reg reg_type,
10616 : : uint32_t data, uint32_t mask)
10617 : : {
10618 : 0 : flow_dv_match_meta_reg(key, reg_type, data, mask);
10619 : 0 : flow_dv_match_meta_reg(matcher, reg_type, mask, mask);
10620 : : }
10621 : :
10622 : : /**
10623 : : * Add MARK item to matcher
10624 : : *
10625 : : * @param[in] dev
10626 : : * The device to configure through.
10627 : : * @param[in, out] key
10628 : : * Flow matcher value.
10629 : : * @param[in] item
10630 : : * Flow pattern to translate.
10631 : : * @param[in] key_type
10632 : : * Set flow matcher mask or value.
10633 : : */
10634 : : static void
10635 : 0 : flow_dv_translate_item_mark(struct rte_eth_dev *dev, void *key,
10636 : : const struct rte_flow_item *item,
10637 : : uint32_t key_type)
10638 : : {
10639 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10640 : : const struct rte_flow_item_mark *mark;
10641 : : uint32_t value;
10642 : : uint32_t mask = 0;
10643 : :
10644 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_SW) {
10645 [ # # ]: 0 : mark = item->mask ? (const void *)item->mask :
10646 : : &rte_flow_item_mark_mask;
10647 : 0 : mask = mark->id;
10648 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M) {
10649 : : value = mask;
10650 : : } else {
10651 : 0 : mark = (const void *)item->spec;
10652 : : MLX5_ASSERT(mark);
10653 : 0 : value = mark->id;
10654 : : }
10655 : : } else {
10656 [ # # ]: 0 : mark = (key_type == MLX5_SET_MATCHER_HS_V) ?
10657 : : (const void *)item->spec : (const void *)item->mask;
10658 : : MLX5_ASSERT(mark);
10659 : 0 : value = mark->id;
10660 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_HS_M)
10661 : : mask = value;
10662 : : }
10663 : 0 : mask &= priv->sh->dv_mark_mask;
10664 : 0 : value &= mask;
10665 [ # # ]: 0 : if (mask) {
10666 : : enum modify_reg reg;
10667 : :
10668 : : /* Get the metadata register index for the mark. */
10669 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, NULL);
10670 : : MLX5_ASSERT(reg > 0);
10671 [ # # ]: 0 : if (reg == REG_C_0) {
10672 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10673 : 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
10674 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
10675 : :
10676 : 0 : mask &= msk_c0;
10677 : 0 : mask <<= shl_c0;
10678 : 0 : value <<= shl_c0;
10679 : : }
10680 : 0 : flow_dv_match_meta_reg(key, reg, value, mask);
10681 : : }
10682 : 0 : }
10683 : :
10684 : : /**
10685 : : * Add META item to matcher
10686 : : *
10687 : : * @param[in] dev
10688 : : * The devich to configure through.
10689 : : * @param[in, out] key
10690 : : * Flow matcher value.
10691 : : * @param[in] attr
10692 : : * Attributes of flow that includes this item.
10693 : : * @param[in] item
10694 : : * Flow pattern to translate.
10695 : : * @param[in] key_type
10696 : : * Set flow matcher mask or value.
10697 : : */
10698 : : static void
10699 : 0 : flow_dv_translate_item_meta(struct rte_eth_dev *dev,
10700 : : void *key,
10701 : : const struct rte_flow_attr *attr,
10702 : : const struct rte_flow_item *item,
10703 : : uint32_t key_type)
10704 : : {
10705 : : const struct rte_flow_item_meta *meta_m;
10706 : : const struct rte_flow_item_meta *meta_v;
10707 : : uint32_t value;
10708 : : uint32_t mask = 0;
10709 : : int reg;
10710 : :
10711 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10712 : : return;
10713 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, meta_v, meta_m,
# # # # ]
10714 : : &rte_flow_item_meta_mask);
10715 : 0 : value = meta_v->data;
10716 : 0 : mask = meta_m->data;
10717 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_HS_M)
10718 : : mask = value;
10719 : : /*
10720 : : * In the current implementation, REG_B cannot be used to match.
10721 : : * Force to use REG_C_1 in HWS root table as other tables.
10722 : : * This map may change.
10723 : : * NIC: modify - REG_B to be present in SW
10724 : : * match - REG_C_1 when copied from FDB, different from SWS
10725 : : * FDB: modify - REG_C_1 in Xmeta mode, REG_NON in legacy mode
10726 : : * match - REG_C_1 in FDB
10727 : : */
10728 [ # # ]: 0 : if (!!(key_type & MLX5_SET_MATCHER_SW))
10729 : 0 : reg = flow_dv_get_metadata_reg(dev, attr, NULL);
10730 : : else
10731 : : reg = flow_hw_get_reg_id(dev, RTE_FLOW_ITEM_TYPE_META, 0);
10732 [ # # ]: 0 : if (reg < 0)
10733 : : return;
10734 : : MLX5_ASSERT(reg != REG_NON);
10735 [ # # ]: 0 : if (reg == REG_C_0) {
10736 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10737 : 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
10738 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
10739 : :
10740 : 0 : mask &= msk_c0;
10741 : 0 : mask <<= shl_c0;
10742 : 0 : value <<= shl_c0;
10743 : : }
10744 : 0 : flow_dv_match_meta_reg(key, reg, value, mask);
10745 : : }
10746 : :
10747 : : /**
10748 : : * Add vport metadata Reg C0 item to matcher
10749 : : *
10750 : : * @param[in, out] key
10751 : : * Flow matcher value.
10752 : : * @param[in] value
10753 : : * Register value
10754 : : * @param[in] mask
10755 : : * Register mask
10756 : : */
10757 : : static void
10758 : : flow_dv_translate_item_meta_vport(void *key, uint32_t value, uint32_t mask)
10759 : : {
10760 : 0 : flow_dv_match_meta_reg(key, REG_C_0, value, mask);
10761 : 0 : }
10762 : :
10763 : : /**
10764 : : * Add tag item to matcher
10765 : : *
10766 : : * @param[in] dev
10767 : : * The devich to configure through.
10768 : : * @param[in, out] key
10769 : : * Flow matcher value.
10770 : : * @param[in] item
10771 : : * Flow pattern to translate.
10772 : : * @param[in] key_type
10773 : : * Set flow matcher mask or value.
10774 : : */
10775 : : static void
10776 : 0 : flow_dv_translate_mlx5_item_tag(struct rte_eth_dev *dev, void *key,
10777 : : const struct rte_flow_item *item,
10778 : : uint32_t key_type)
10779 : : {
10780 : 0 : const struct mlx5_rte_flow_item_tag *tag_v = item->spec;
10781 : 0 : const struct mlx5_rte_flow_item_tag *tag_m = item->mask;
10782 : : uint32_t mask, value;
10783 : :
10784 : : MLX5_ASSERT(tag_v);
10785 : 0 : value = tag_v->data;
10786 [ # # ]: 0 : mask = tag_m ? tag_m->data : UINT32_MAX;
10787 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
10788 : : value = mask;
10789 [ # # ]: 0 : if (tag_v->id == REG_C_0) {
10790 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10791 : 0 : uint32_t msk_c0 = priv->sh->dv_regc0_mask;
10792 : : uint32_t shl_c0 = rte_bsf32(msk_c0);
10793 : :
10794 : 0 : mask &= msk_c0;
10795 : 0 : mask <<= shl_c0;
10796 : 0 : value <<= shl_c0;
10797 : : }
10798 : 0 : flow_dv_match_meta_reg(key, tag_v->id, value, mask);
10799 : 0 : }
10800 : :
10801 : : /**
10802 : : * Add TAG item to matcher
10803 : : *
10804 : : * @param[in] dev
10805 : : * The devich to configure through.
10806 : : * @param[in, out] key
10807 : : * Flow matcher value.
10808 : : * @param[in] item
10809 : : * Flow pattern to translate.
10810 : : * @param[in] key_type
10811 : : * Set flow matcher mask or value.
10812 : : */
10813 : : static void
10814 : 0 : flow_dv_translate_item_tag(struct rte_eth_dev *dev, void *key,
10815 : : const struct rte_flow_item *item,
10816 : : uint32_t key_type)
10817 : : {
10818 : 0 : const struct rte_flow_item_tag *tag_vv = item->spec;
10819 : : const struct rte_flow_item_tag *tag_v;
10820 : : const struct rte_flow_item_tag *tag_m;
10821 : : int reg;
10822 : : uint32_t index;
10823 : :
10824 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
10825 : : return;
10826 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, tag_v, tag_m,
# # # # ]
10827 : : &rte_flow_item_tag_mask);
10828 : : /* When set mask, the index should be from spec. */
10829 [ # # ]: 0 : index = tag_vv ? tag_vv->index : tag_v->index;
10830 : : /* Get the metadata register index for the tag. */
10831 [ # # ]: 0 : if (!!(key_type & MLX5_SET_MATCHER_SW))
10832 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, index, NULL);
10833 : : else
10834 : : reg = flow_hw_get_reg_id(dev, RTE_FLOW_ITEM_TYPE_TAG, index);
10835 : : MLX5_ASSERT(reg > 0);
10836 : 0 : flow_dv_match_meta_reg(key, (enum modify_reg)reg, tag_v->data, tag_m->data);
10837 : : }
10838 : :
10839 : : /**
10840 : : * Add source vport match to the specified matcher.
10841 : : *
10842 : : * @param[in, out] key
10843 : : * Flow matcher value.
10844 : : * @param[in] port
10845 : : * Source vport value to match
10846 : : */
10847 : : static void
10848 : : flow_dv_translate_item_source_vport(void *key,
10849 : : int16_t port)
10850 : : {
10851 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
10852 : :
10853 [ # # # # : 0 : MLX5_SET(fte_match_set_misc, misc_v, source_port, port);
# # ]
10854 : 0 : }
10855 : :
10856 : : /**
10857 : : * Translate port-id item to eswitch match on port-id.
10858 : : *
10859 : : * @param[in] dev
10860 : : * The devich to configure through.
10861 : : * @param[in, out] key
10862 : : * Flow matcher value.
10863 : : * @param[in] item
10864 : : * Flow pattern to translate.
10865 : : * @param[in] attr
10866 : : * Flow attributes.
10867 : : * @param[in] key_type
10868 : : * Set flow matcher mask or value.
10869 : : *
10870 : : * @return
10871 : : * 0 on success, a negative errno value otherwise.
10872 : : */
10873 : : static int
10874 : 0 : flow_dv_translate_item_port_id(struct rte_eth_dev *dev, void *key,
10875 : : const struct rte_flow_item *item,
10876 : : const struct rte_flow_attr *attr,
10877 : : uint32_t key_type)
10878 : : {
10879 [ # # ]: 0 : const struct rte_flow_item_port_id *pid_m = item ? item->mask : NULL;
10880 [ # # ]: 0 : const struct rte_flow_item_port_id *pid_v = item ? item->spec : NULL;
10881 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
10882 : : struct mlx5_priv *priv;
10883 : : uint16_t mask, id;
10884 : : uint32_t vport_meta;
10885 : :
10886 : : MLX5_ASSERT(wks);
10887 [ # # # # ]: 0 : if (pid_v && pid_v->id == MLX5_PORT_ESW_MGR) {
10888 : 0 : priv = dev->data->dev_private;
10889 [ # # ]: 0 : if (priv->sh->dev_cap.esw_info.regc_mask) {
10890 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
10891 : : vport_meta = priv->sh->dev_cap.esw_info.regc_mask;
10892 : : } else {
10893 : 0 : vport_meta = priv->sh->dev_cap.esw_info.regc_value;
10894 : 0 : wks->vport_meta_tag = vport_meta;
10895 : : }
10896 : : flow_dv_translate_item_meta_vport(key, vport_meta,
10897 : : priv->sh->dev_cap.esw_info.regc_mask);
10898 : : } else {
10899 : 0 : flow_dv_translate_item_source_vport(key,
10900 [ # # ]: 0 : key_type & MLX5_SET_MATCHER_V ?
10901 : 0 : mlx5_flow_get_esw_manager_vport_id(dev) : 0xffff);
10902 : : }
10903 : 0 : return 0;
10904 : : }
10905 [ # # ]: 0 : mask = pid_m ? pid_m->id : 0xffff;
10906 [ # # ]: 0 : id = pid_v ? pid_v->id : dev->data->port_id;
10907 : 0 : priv = mlx5_port_to_eswitch_info(id, item == NULL);
10908 [ # # ]: 0 : if (!priv)
10909 : 0 : return -rte_errno;
10910 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
10911 : : id = mask;
10912 : 0 : vport_meta = priv->vport_meta_mask;
10913 : : } else {
10914 : 0 : id = priv->vport_id;
10915 : 0 : vport_meta = priv->vport_meta_tag;
10916 : 0 : wks->vport_meta_tag = vport_meta;
10917 : : }
10918 : : /*
10919 : : * Translate to vport field or to metadata, depending on mode.
10920 : : * Kernel can use either misc.source_port or half of C0 metadata
10921 : : * register.
10922 : : */
10923 [ # # ]: 0 : if (priv->vport_meta_mask) {
10924 : : /*
10925 : : * Provide the hint for SW steering library
10926 : : * to insert the flow into ingress domain and
10927 : : * save the extra vport match.
10928 : : */
10929 [ # # # # ]: 0 : if (mask == 0xffff && priv->vport_id == 0xffff &&
10930 [ # # # # ]: 0 : priv->pf_bond < 0 && attr->transfer)
10931 [ # # ]: 0 : flow_dv_translate_item_source_vport(key, id);
10932 : : /*
10933 : : * We should always set the vport metadata register,
10934 : : * otherwise the SW steering library can drop
10935 : : * the rule if wire vport metadata value is not zero,
10936 : : * it depends on kernel configuration.
10937 : : */
10938 : 0 : flow_dv_translate_item_meta_vport
10939 : : (key, vport_meta, priv->vport_meta_mask);
10940 : : } else {
10941 [ # # ]: 0 : flow_dv_translate_item_source_vport(key, id);
10942 : : }
10943 : : return 0;
10944 : : }
10945 : :
10946 : : /**
10947 : : * Translate port representor item to eswitch match on port id.
10948 : : *
10949 : : * @param[in] dev
10950 : : * The devich to configure through.
10951 : : * @param[in, out] key
10952 : : * Flow matcher value.
10953 : : * @param[in] key_type
10954 : : * Set flow matcher mask or value.
10955 : : *
10956 : : * @return
10957 : : * 0 on success, a negative errno value otherwise.
10958 : : */
10959 : : static int
10960 : 0 : flow_dv_translate_item_port_representor(struct rte_eth_dev *dev, void *key,
10961 : : uint32_t key_type)
10962 : : {
10963 : 0 : flow_dv_translate_item_source_vport(key,
10964 [ # # ]: 0 : key_type & MLX5_SET_MATCHER_V ?
10965 : 0 : mlx5_flow_get_esw_manager_vport_id(dev) : 0xffff);
10966 : 0 : return 0;
10967 : : }
10968 : :
10969 : : /**
10970 : : * Translate represented port item to eswitch match on port id.
10971 : : *
10972 : : * @param[in] dev
10973 : : * The devich to configure through.
10974 : : * @param[in, out] key
10975 : : * Flow matcher value.
10976 : : * @param[in] item
10977 : : * Flow pattern to translate.
10978 : : * @param[in]
10979 : : * Flow attributes.
10980 : : *
10981 : : * @return
10982 : : * 0 on success, a negative errno value otherwise.
10983 : : */
10984 : : static int
10985 : 0 : flow_dv_translate_item_represented_port(struct rte_eth_dev *dev, void *key,
10986 : : const struct rte_flow_item *item,
10987 : : const struct rte_flow_attr *attr,
10988 : : uint32_t key_type)
10989 : : {
10990 [ # # ]: 0 : const struct rte_flow_item_ethdev *pid_m = item ? item->mask : NULL;
10991 [ # # ]: 0 : const struct rte_flow_item_ethdev *pid_v = item ? item->spec : NULL;
10992 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
10993 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
10994 : : uint16_t mask, id;
10995 : : uint32_t vport_meta;
10996 : : bool vport_match = false;
10997 : :
10998 : : MLX5_ASSERT(wks);
10999 : : #ifndef HAVE_IBV_DEVICE_ATTR_ESW_MGR_REG_C0
11000 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
11001 : : vport_match = true;
11002 : : #endif
11003 [ # # ]: 0 : if (!pid_m && !pid_v)
11004 : : return 0;
11005 [ # # # # ]: 0 : if (pid_v && pid_v->port_id == UINT16_MAX) {
11006 [ # # # # ]: 0 : if (priv->sh->config.dv_flow_en != 2 || vport_match) {
11007 : 0 : flow_dv_translate_item_source_vport
11008 [ # # ]: 0 : (key, key_type & MLX5_SET_MATCHER_V ?
11009 : 0 : mlx5_flow_get_esw_manager_vport_id(dev) : 0xffff);
11010 : : } else {
11011 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11012 : 0 : vport_meta = priv->sh->dev_cap.esw_info.regc_mask;
11013 : : else
11014 : 0 : vport_meta = priv->sh->dev_cap.esw_info.regc_value;
11015 : 0 : flow_dv_translate_item_meta_vport(key, vport_meta,
11016 : : priv->sh->dev_cap.esw_info.regc_mask);
11017 : : }
11018 : 0 : return 0;
11019 : : }
11020 [ # # ]: 0 : mask = pid_m ? pid_m->port_id : UINT16_MAX;
11021 [ # # ]: 0 : id = pid_v ? pid_v->port_id : dev->data->port_id;
11022 : 0 : priv = mlx5_port_to_eswitch_info(id, item == NULL);
11023 [ # # ]: 0 : if (!priv)
11024 : 0 : return -rte_errno;
11025 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
11026 : : id = mask;
11027 : 0 : vport_meta = priv->vport_meta_mask;
11028 : : } else {
11029 : 0 : id = priv->vport_id;
11030 : 0 : vport_meta = priv->vport_meta_tag;
11031 : 0 : wks->vport_meta_tag = vport_meta;
11032 : : }
11033 : : /*
11034 : : * Translate to vport field or to metadata, depending on mode.
11035 : : * Kernel can use either misc.source_port or half of C0 metadata
11036 : : * register.
11037 : : */
11038 [ # # # # ]: 0 : if (priv->vport_meta_mask && !vport_match) {
11039 : : /*
11040 : : * Provide the hint for SW steering library
11041 : : * to insert the flow into ingress domain and
11042 : : * save the extra vport match.
11043 : : */
11044 [ # # # # ]: 0 : if (mask == UINT16_MAX && priv->vport_id == UINT16_MAX &&
11045 [ # # # # ]: 0 : priv->pf_bond < 0 && attr->transfer &&
11046 [ # # ]: 0 : priv->sh->config.dv_flow_en != 2)
11047 [ # # ]: 0 : flow_dv_translate_item_source_vport(key, id);
11048 : : /*
11049 : : * We should always set the vport metadata register,
11050 : : * otherwise the SW steering library can drop
11051 : : * the rule if wire vport metadata value is not zero,
11052 : : * it depends on kernel configuration.
11053 : : */
11054 : 0 : flow_dv_translate_item_meta_vport(key, vport_meta,
11055 : : priv->vport_meta_mask);
11056 : : } else {
11057 [ # # ]: 0 : flow_dv_translate_item_source_vport(key, id);
11058 : : }
11059 : : return 0;
11060 : : }
11061 : :
11062 : : /**
11063 : : * Translate port-id item to eswitch match on port-id.
11064 : : *
11065 : : * @param[in] dev
11066 : : * The devich to configure through.
11067 : : * @param[in, out] matcher
11068 : : * Flow matcher.
11069 : : * @param[in, out] key
11070 : : * Flow matcher value.
11071 : : * @param[in] item
11072 : : * Flow pattern to translate.
11073 : : * @param[in] attr
11074 : : * Flow attributes.
11075 : : *
11076 : : * @return
11077 : : * 0 on success, a negative errno value otherwise.
11078 : : */
11079 : : static int
11080 : 0 : flow_dv_translate_item_port_id_all(struct rte_eth_dev *dev,
11081 : : void *matcher, void *key,
11082 : : const struct rte_flow_item *item,
11083 : : const struct rte_flow_attr *attr)
11084 : : {
11085 : : int ret;
11086 : :
11087 : 0 : ret = flow_dv_translate_item_port_id
11088 : : (dev, matcher, item, attr, MLX5_SET_MATCHER_SW_M);
11089 [ # # ]: 0 : if (ret)
11090 : : return ret;
11091 : 0 : ret = flow_dv_translate_item_port_id
11092 : : (dev, key, item, attr, MLX5_SET_MATCHER_SW_V);
11093 : 0 : return ret;
11094 : : }
11095 : :
11096 : :
11097 : : /**
11098 : : * Add ICMP6 item to the value.
11099 : : *
11100 : : * @param[in, out] key
11101 : : * Flow matcher value.
11102 : : * @param[in] item
11103 : : * Flow pattern to translate.
11104 : : * @param[in] inner
11105 : : * Item is inner pattern.
11106 : : * @param[in] key_type
11107 : : * Set flow matcher mask or value.
11108 : : */
11109 : : static void
11110 : 0 : flow_dv_translate_item_icmp6(void *key, const struct rte_flow_item *item,
11111 : : int inner, uint32_t key_type)
11112 : : {
11113 : : const struct rte_flow_item_icmp6 *icmp6_m;
11114 : : const struct rte_flow_item_icmp6 *icmp6_v;
11115 : : void *headers_v;
11116 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
11117 : :
11118 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
11119 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11120 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11121 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, 0xFF);
11122 : : else
11123 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
11124 : : IPPROTO_ICMPV6);
11125 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11126 : : return;
11127 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, icmp6_v, icmp6_m,
# # # # ]
11128 : : &rte_flow_item_icmp6_mask);
11129 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type,
11130 : : icmp6_v->type & icmp6_m->type);
11131 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code,
11132 : : icmp6_v->code & icmp6_m->code);
11133 : : }
11134 : :
11135 : : /**
11136 : : * Add ICMP6 echo request/reply item to the value.
11137 : : *
11138 : : * @param[in, out] key
11139 : : * Flow matcher value.
11140 : : * @param[in] item
11141 : : * Flow pattern to translate.
11142 : : * @param[in] inner
11143 : : * Item is inner pattern.
11144 : : * @param[in] key_type
11145 : : * Set flow matcher mask or value.
11146 : : */
11147 : : static void
11148 [ # # ]: 0 : flow_dv_translate_item_icmp6_echo(void *key, const struct rte_flow_item *item,
11149 : : int inner, uint32_t key_type)
11150 : : {
11151 : : const struct rte_flow_item_icmp6_echo *icmp6_m;
11152 : : const struct rte_flow_item_icmp6_echo *icmp6_v;
11153 : : uint32_t icmp6_header_data_m = 0;
11154 : : uint32_t icmp6_header_data_v = 0;
11155 : : void *headers_v;
11156 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
11157 : : uint8_t icmp6_type = 0;
11158 : : struct rte_flow_item_icmp6_echo zero_mask;
11159 : :
11160 : : memset(&zero_mask, 0, sizeof(zero_mask));
11161 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
11162 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11163 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11164 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol, 0xFF);
11165 : : else
11166 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_protocol,
11167 : : IPPROTO_ICMPV6);
11168 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, icmp6_v, icmp6_m, &zero_mask);
# # # # ]
11169 : : /* Set fixed type and code for icmpv6 echo request or reply */
11170 [ # # ]: 0 : icmp6_type = (item->type == RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REQUEST ?
11171 : : RTE_ICMP6_ECHO_REQUEST : RTE_ICMP6_ECHO_REPLY);
11172 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M) {
11173 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type, 0xFF);
11174 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code, 0xFF);
11175 : : } else {
11176 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_type, icmp6_type);
11177 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_code, 0);
11178 : : }
11179 [ # # ]: 0 : if (icmp6_v == NULL)
11180 : 0 : return;
11181 : : /* Set icmp6 header data (identifier & sequence) accordingly */
11182 : 0 : icmp6_header_data_m =
11183 [ # # ]: 0 : (rte_be_to_cpu_16(icmp6_m->hdr.identifier) << 16) |
11184 [ # # ]: 0 : rte_be_to_cpu_16(icmp6_m->hdr.sequence);
11185 [ # # ]: 0 : if (icmp6_header_data_m) {
11186 : 0 : icmp6_header_data_v =
11187 [ # # ]: 0 : (rte_be_to_cpu_16(icmp6_v->hdr.identifier) << 16) |
11188 [ # # ]: 0 : rte_be_to_cpu_16(icmp6_v->hdr.sequence);
11189 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmpv6_header_data,
11190 : : icmp6_header_data_v & icmp6_header_data_m);
11191 : : }
11192 : : }
11193 : :
11194 : : /**
11195 : : * Add ICMP item to the value.
11196 : : *
11197 : : * @param[in, out] key
11198 : : * Flow matcher value.
11199 : : * @param[in] item
11200 : : * Flow pattern to translate.
11201 : : * @param[in] inner
11202 : : * Item is inner pattern.
11203 : : * @param[in] key_type
11204 : : * Set flow matcher mask or value.
11205 : : */
11206 : : static void
11207 : 0 : flow_dv_translate_item_icmp(void *key, const struct rte_flow_item *item,
11208 : : int inner, uint32_t key_type)
11209 : : {
11210 : : const struct rte_flow_item_icmp *icmp_m;
11211 : : const struct rte_flow_item_icmp *icmp_v;
11212 : : uint32_t icmp_header_data_m = 0;
11213 : : uint32_t icmp_header_data_v = 0;
11214 : : void *headers_v;
11215 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
11216 : :
11217 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
11218 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11219 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11220 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11221 : : ip_protocol, 0xFF);
11222 : : else
11223 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11224 : : ip_protocol, IPPROTO_ICMP);
11225 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11226 : : return;
11227 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, icmp_v, icmp_m,
# # # # ]
11228 : : &rte_flow_item_icmp_mask);
11229 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmp_type,
11230 : : icmp_v->hdr.icmp_type & icmp_m->hdr.icmp_type);
11231 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmp_code,
11232 : : icmp_v->hdr.icmp_code & icmp_m->hdr.icmp_code);
11233 [ # # ]: 0 : icmp_header_data_m = rte_be_to_cpu_16(icmp_m->hdr.icmp_seq_nb);
11234 [ # # ]: 0 : icmp_header_data_m |= rte_be_to_cpu_16(icmp_m->hdr.icmp_ident) << 16;
11235 [ # # ]: 0 : if (icmp_header_data_m) {
11236 [ # # ]: 0 : icmp_header_data_v = rte_be_to_cpu_16(icmp_v->hdr.icmp_seq_nb);
11237 : 0 : icmp_header_data_v |=
11238 [ # # ]: 0 : rte_be_to_cpu_16(icmp_v->hdr.icmp_ident) << 16;
11239 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, icmp_header_data,
11240 : : icmp_header_data_v & icmp_header_data_m);
11241 : : }
11242 : : }
11243 : :
11244 : : /**
11245 : : * Add GTP item to the value.
11246 : : *
11247 : : * @param[in, out] key
11248 : : * Flow matcher value.
11249 : : * @param[in] item
11250 : : * Flow pattern to translate.
11251 : : * @param[in] inner
11252 : : * Item is inner pattern.
11253 : : * @param[in] key_type
11254 : : * Set flow matcher mask or value.
11255 : : */
11256 : : static void
11257 : 0 : flow_dv_translate_item_gtp(void *key, const struct rte_flow_item *item,
11258 : : int inner, uint32_t key_type)
11259 : : {
11260 : : const struct rte_flow_item_gtp *gtp_m;
11261 : : const struct rte_flow_item_gtp *gtp_v;
11262 : : void *headers_v;
11263 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
11264 : : uint16_t dport = RTE_GTPU_UDP_PORT;
11265 : :
11266 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
11267 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11268 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
11269 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11270 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11271 : : udp_dport, 0xFFFF);
11272 : : else
11273 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v,
11274 : : udp_dport, dport);
11275 : : }
11276 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11277 : : return;
11278 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, gtp_v, gtp_m,
# # # # ]
11279 : : &rte_flow_item_gtp_mask);
11280 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags,
11281 : : gtp_v->hdr.gtp_hdr_info & gtp_m->hdr.gtp_hdr_info);
11282 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_type,
11283 : : gtp_v->hdr.msg_type & gtp_m->hdr.msg_type);
11284 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_teid,
11285 : : rte_be_to_cpu_32(gtp_v->hdr.teid & gtp_m->hdr.teid));
11286 : : }
11287 : :
11288 : : /**
11289 : : * Add GTP PSC item to matcher.
11290 : : *
11291 : : * @param[in, out] key
11292 : : * Flow matcher value.
11293 : : * @param[in] item
11294 : : * Flow pattern to translate.
11295 : : * @param[in] key_type
11296 : : * Set flow matcher mask or value.
11297 : : */
11298 : : static int
11299 : 0 : flow_dv_translate_item_gtp_psc(void *key, const struct rte_flow_item *item,
11300 : : uint32_t key_type)
11301 : : {
11302 : : const struct rte_flow_item_gtp_psc *gtp_psc_m;
11303 : : const struct rte_flow_item_gtp_psc *gtp_psc_v;
11304 : : void *misc3_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_3);
11305 : : union {
11306 : : uint32_t w32;
11307 : : struct {
11308 : : uint16_t seq_num;
11309 : : uint8_t npdu_num;
11310 : : uint8_t next_ext_header_type;
11311 : : };
11312 : : } dw_2;
11313 : : union {
11314 : : uint32_t w32;
11315 : : struct {
11316 : : uint8_t len;
11317 : : uint8_t type_flags;
11318 : : uint8_t qfi;
11319 : : uint8_t reserved;
11320 : : };
11321 : : } dw_0;
11322 : : uint8_t gtp_flags;
11323 : :
11324 : : /* Always set E-flag match on one, regardless of GTP item settings. */
11325 [ # # ]: 0 : gtp_flags = MLX5_GET(fte_match_set_misc3, misc3_v, gtpu_msg_flags);
11326 : 0 : gtp_flags |= MLX5_GTP_EXT_HEADER_FLAG;
11327 [ # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_msg_flags, gtp_flags);
11328 : : /*Set next extension header type. */
11329 : 0 : dw_2.seq_num = 0;
11330 : 0 : dw_2.npdu_num = 0;
11331 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11332 : 0 : dw_2.next_ext_header_type = 0xff;
11333 : : else
11334 : 0 : dw_2.next_ext_header_type = 0x85;
11335 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_dw_2,
11336 : : rte_cpu_to_be_32(dw_2.w32));
11337 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11338 : : return 0;
11339 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, gtp_psc_v,
# # # # ]
11340 : : gtp_psc_m, &rte_flow_item_gtp_psc_mask);
11341 : 0 : dw_0.w32 = 0;
11342 : 0 : dw_0.type_flags = MLX5_GTP_PDU_TYPE_SHIFT(gtp_psc_v->hdr.type &
11343 : : gtp_psc_m->hdr.type);
11344 : 0 : dw_0.qfi = gtp_psc_v->hdr.qfi & gtp_psc_m->hdr.qfi;
11345 [ # # # # ]: 0 : MLX5_SET(fte_match_set_misc3, misc3_v, gtpu_first_ext_dw_0,
11346 : : rte_cpu_to_be_32(dw_0.w32));
11347 : 0 : return 0;
11348 : : }
11349 : :
11350 : : /**
11351 : : * Add eCPRI item to matcher and to the value.
11352 : : *
11353 : : * @param[in] dev
11354 : : * The devich to configure through.
11355 : : * @param[in, out] key
11356 : : * Flow matcher value.
11357 : : * @param[in] item
11358 : : * Flow pattern to translate.
11359 : : * @param[in] last_item
11360 : : * Last item flags.
11361 : : * @param[in] key_type
11362 : : * Set flow matcher mask or value.
11363 : : */
11364 : : static void
11365 : 0 : flow_dv_translate_item_ecpri(struct rte_eth_dev *dev, void *key,
11366 : : const struct rte_flow_item *item,
11367 : : uint64_t last_item, uint32_t key_type)
11368 : : {
11369 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11370 : : const struct rte_flow_item_ecpri *ecpri_m;
11371 : : const struct rte_flow_item_ecpri *ecpri_v;
11372 : 0 : const struct rte_flow_item_ecpri *ecpri_vv = item->spec;
11373 : : struct rte_ecpri_common_hdr common;
11374 : : void *misc4_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters_4);
11375 : : uint32_t *samples;
11376 : : void *dw_v;
11377 : :
11378 : : /*
11379 : : * In case of eCPRI over Ethernet, if EtherType is not specified,
11380 : : * match on eCPRI EtherType implicitly.
11381 : : */
11382 [ # # ]: 0 : if (last_item & MLX5_FLOW_LAYER_OUTER_L2) {
11383 : : void *hdrs_v, *l2v;
11384 : :
11385 : : hdrs_v = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11386 : : l2v = MLX5_ADDR_OF(fte_match_set_lyr_2_4, hdrs_v, ethertype);
11387 [ # # ]: 0 : if (*(uint16_t *)l2v == 0) {
11388 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_M)
11389 : 0 : *(uint16_t *)l2v = UINT16_MAX;
11390 : : else
11391 : 0 : *(uint16_t *)l2v =
11392 : : RTE_BE16(RTE_ETHER_TYPE_ECPRI);
11393 : : }
11394 : : }
11395 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11396 : 0 : return;
11397 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, ecpri_v, ecpri_m,
# # # # ]
11398 : : &rte_flow_item_ecpri_mask);
11399 : : /*
11400 : : * Maximal four DW samples are supported in a single matching now.
11401 : : * Two are used now for a eCPRI matching:
11402 : : * 1. Type: one byte, mask should be 0x00ff0000 in network order
11403 : : * 2. ID of a message: one or two bytes, mask 0xffff0000 or 0xff000000
11404 : : * if any.
11405 : : */
11406 [ # # ]: 0 : if (!ecpri_m->hdr.common.u32)
11407 : : return;
11408 : 0 : samples = priv->sh->ecpri_parser.ids;
11409 : : /* Need to take the whole DW as the mask to fill the entry. */
11410 : : dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
11411 : : prog_sample_field_value_0);
11412 : : /* Already big endian (network order) in the header. */
11413 : 0 : *(uint32_t *)dw_v = ecpri_v->hdr.common.u32 & ecpri_m->hdr.common.u32;
11414 : : /* Sample#0, used for matching type, offset 0. */
11415 : : /* It makes no sense to set the sample ID in the mask field. */
11416 [ # # ]: 0 : MLX5_SET(fte_match_set_misc4, misc4_v,
11417 : : prog_sample_field_id_0, samples[0]);
11418 : : /*
11419 : : * Checking if message body part needs to be matched.
11420 : : * Some wildcard rules only matching type field should be supported.
11421 : : */
11422 [ # # ]: 0 : if (ecpri_m->hdr.dummy[0]) {
11423 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_M)
11424 [ # # ]: 0 : common.u32 = rte_be_to_cpu_32(ecpri_vv->hdr.common.u32);
11425 : : else
11426 [ # # ]: 0 : common.u32 = rte_be_to_cpu_32(ecpri_v->hdr.common.u32);
11427 [ # # ]: 0 : switch (common.type) {
11428 : 0 : case RTE_ECPRI_MSG_TYPE_IQ_DATA:
11429 : : case RTE_ECPRI_MSG_TYPE_RTC_CTRL:
11430 : : case RTE_ECPRI_MSG_TYPE_DLY_MSR:
11431 : : dw_v = MLX5_ADDR_OF(fte_match_set_misc4, misc4_v,
11432 : : prog_sample_field_value_1);
11433 : 0 : *(uint32_t *)dw_v = ecpri_v->hdr.dummy[0] &
11434 : : ecpri_m->hdr.dummy[0];
11435 : : /* Sample#1, to match message body, offset 4. */
11436 [ # # ]: 0 : MLX5_SET(fte_match_set_misc4, misc4_v,
11437 : : prog_sample_field_id_1, samples[1]);
11438 : 0 : break;
11439 : : default:
11440 : : /* Others, do not match any sample ID. */
11441 : : break;
11442 : : }
11443 : : }
11444 : : }
11445 : :
11446 : : /*
11447 : : * Add connection tracking status item to matcher
11448 : : *
11449 : : * @param[in] dev
11450 : : * The devich to configure through.
11451 : : * @param[in, out] matcher
11452 : : * Flow matcher.
11453 : : * @param[in, out] key
11454 : : * Flow matcher value.
11455 : : * @param[in] item
11456 : : * Flow pattern to translate.
11457 : : */
11458 : : static void
11459 : 0 : flow_dv_translate_item_aso_ct(struct rte_eth_dev *dev,
11460 : : void *matcher, void *key,
11461 : : const struct rte_flow_item *item)
11462 : : {
11463 : : uint32_t reg_value = 0;
11464 : : int reg_id;
11465 : : /* 8LSB 0b 11/0000/11, middle 4 bits are reserved. */
11466 : : uint32_t reg_mask = 0;
11467 : 0 : const struct rte_flow_item_conntrack *spec = item->spec;
11468 : 0 : const struct rte_flow_item_conntrack *mask = item->mask;
11469 : : uint32_t flags;
11470 : : struct rte_flow_error error;
11471 : :
11472 [ # # ]: 0 : if (!mask)
11473 : : mask = &rte_flow_item_conntrack_mask;
11474 [ # # # # ]: 0 : if (!spec || !mask->flags)
11475 : 0 : return;
11476 : 0 : flags = spec->flags & mask->flags;
11477 : : /* The conflict should be checked in the validation. */
11478 : : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_VALID)
11479 : : reg_value |= MLX5_CT_SYNDROME_VALID;
11480 [ # # ]: 0 : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_CHANGED)
11481 : : reg_value |= MLX5_CT_SYNDROME_STATE_CHANGE;
11482 [ # # ]: 0 : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_INVALID)
11483 : 0 : reg_value |= MLX5_CT_SYNDROME_INVALID;
11484 [ # # ]: 0 : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED)
11485 : 0 : reg_value |= MLX5_CT_SYNDROME_TRAP;
11486 [ # # ]: 0 : if (flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD)
11487 : 0 : reg_value |= MLX5_CT_SYNDROME_BAD_PACKET;
11488 [ # # ]: 0 : if (mask->flags & (RTE_FLOW_CONNTRACK_PKT_STATE_VALID |
11489 : : RTE_FLOW_CONNTRACK_PKT_STATE_INVALID |
11490 : : RTE_FLOW_CONNTRACK_PKT_STATE_DISABLED))
11491 : : reg_mask |= 0xc0;
11492 [ # # ]: 0 : if (mask->flags & RTE_FLOW_CONNTRACK_PKT_STATE_CHANGED)
11493 : 0 : reg_mask |= MLX5_CT_SYNDROME_STATE_CHANGE;
11494 [ # # ]: 0 : if (mask->flags & RTE_FLOW_CONNTRACK_PKT_STATE_BAD)
11495 : 0 : reg_mask |= MLX5_CT_SYNDROME_BAD_PACKET;
11496 : : /* The REG_C_x value could be saved during startup. */
11497 : 0 : reg_id = mlx5_flow_get_reg_id(dev, MLX5_ASO_CONNTRACK, 0, &error);
11498 [ # # ]: 0 : if (reg_id == REG_NON)
11499 : : return;
11500 : 0 : flow_dv_match_meta_reg_all(matcher, key, (enum modify_reg)reg_id,
11501 : : reg_value, reg_mask);
11502 : : }
11503 : :
11504 : : static void
11505 : 0 : flow_dv_translate_item_flex(struct rte_eth_dev *dev, void *matcher, void *key,
11506 : : const struct rte_flow_item *item,
11507 : : struct mlx5_flow *dev_flow, bool is_inner)
11508 : : {
11509 : 0 : const struct rte_flow_item_flex *spec =
11510 : : (const struct rte_flow_item_flex *)item->spec;
11511 : 0 : int index = mlx5_flex_acquire_index(dev, spec->handle, false);
11512 : :
11513 : : MLX5_ASSERT(index >= 0 && index < (int)(sizeof(uint32_t) * CHAR_BIT));
11514 [ # # ]: 0 : if (index < 0)
11515 : : return;
11516 [ # # ]: 0 : if (!(dev_flow->handle->flex_item & RTE_BIT32(index))) {
11517 : : /* Don't count both inner and outer flex items in one rule. */
11518 : 0 : if (mlx5_flex_acquire_index(dev, spec->handle, true) != index)
11519 : : MLX5_ASSERT(false);
11520 : 0 : dev_flow->handle->flex_item |= (uint8_t)RTE_BIT32(index);
11521 : : }
11522 : 0 : mlx5_flex_flow_translate_item(dev, matcher, key, item, is_inner);
11523 : : }
11524 : :
11525 : : /**
11526 : : * Add METER_COLOR item to matcher
11527 : : *
11528 : : * @param[in] dev
11529 : : * The device to configure through.
11530 : : * @param[in, out] key
11531 : : * Flow matcher value.
11532 : : * @param[in] item
11533 : : * Flow pattern to translate.
11534 : : * @param[in] key_type
11535 : : * Set flow matcher mask or value.
11536 : : */
11537 : : static void
11538 : 0 : flow_dv_translate_item_meter_color(struct rte_eth_dev *dev, void *key,
11539 : : const struct rte_flow_item *item,
11540 : : uint32_t key_type)
11541 : : {
11542 : 0 : const struct rte_flow_item_meter_color *color_m = item->mask;
11543 : 0 : const struct rte_flow_item_meter_color *color_v = item->spec;
11544 : : uint32_t value, mask;
11545 : : int reg = REG_NON;
11546 : :
11547 : : MLX5_ASSERT(color_v);
11548 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11549 : : return;
11550 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, color_v, color_m,
# # # # ]
11551 : : &rte_flow_item_meter_color_mask);
11552 [ # # ]: 0 : value = rte_col_2_mlx5_col(color_v->color);
11553 : : mask = color_m ?
11554 [ # # ]: 0 : color_m->color : (UINT32_C(1) << MLX5_MTR_COLOR_BITS) - 1;
11555 [ # # ]: 0 : if (!!(key_type & MLX5_SET_MATCHER_SW))
11556 : 0 : reg = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, NULL);
11557 : : else
11558 : : reg = flow_hw_get_reg_id(dev,
11559 : : RTE_FLOW_ITEM_TYPE_METER_COLOR, 0);
11560 [ # # ]: 0 : if (reg == REG_NON)
11561 : : return;
11562 : 0 : flow_dv_match_meta_reg(key, (enum modify_reg)reg, value, mask);
11563 : : }
11564 : :
11565 : : static void
11566 : 0 : flow_dv_translate_item_aggr_affinity(void *key,
11567 : : const struct rte_flow_item *item,
11568 : : uint32_t key_type)
11569 : : {
11570 : : const struct rte_flow_item_aggr_affinity *affinity_v;
11571 : : const struct rte_flow_item_aggr_affinity *affinity_m;
11572 : : void *misc_v;
11573 : :
11574 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, affinity_v, affinity_m,
# # # # ]
11575 : : &rte_flow_item_aggr_affinity_mask);
11576 : : misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
11577 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, lag_rx_port_affinity,
11578 : : affinity_v->affinity & affinity_m->affinity);
11579 : 0 : }
11580 : :
11581 : : static void
11582 : 0 : flow_dv_translate_item_ib_bth(void *key,
11583 : : const struct rte_flow_item *item,
11584 : : int inner, uint32_t key_type)
11585 : : {
11586 : : const struct rte_flow_item_ib_bth *bth_m;
11587 : : const struct rte_flow_item_ib_bth *bth_v;
11588 : : void *headers_v, *misc_v;
11589 : : uint16_t udp_dport;
11590 : : char *qpn_v;
11591 : : int i, size;
11592 : :
11593 [ # # ]: 0 : headers_v = inner ? MLX5_ADDR_OF(fte_match_param, key, inner_headers) :
11594 : : MLX5_ADDR_OF(fte_match_param, key, outer_headers);
11595 [ # # # # ]: 0 : if (!MLX5_GET16(fte_match_set_lyr_2_4, headers_v, udp_dport)) {
11596 [ # # ]: 0 : udp_dport = key_type & MLX5_SET_MATCHER_M ?
11597 : : 0xFFFF : MLX5_UDP_PORT_ROCEv2;
11598 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_v, udp_dport, udp_dport);
11599 : : }
11600 [ # # # # : 0 : if (MLX5_ITEM_VALID(item, key_type))
# # # # #
# ]
11601 : : return;
11602 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, bth_v, bth_m, &rte_flow_item_ib_bth_mask);
# # # # ]
11603 : : misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
11604 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, bth_opcode,
11605 : : bth_v->hdr.opcode & bth_m->hdr.opcode);
11606 : 0 : qpn_v = MLX5_ADDR_OF(fte_match_set_misc, misc_v, bth_dst_qp);
11607 : : size = sizeof(bth_m->hdr.dst_qp);
11608 [ # # ]: 0 : for (i = 0; i < size; ++i)
11609 : 0 : qpn_v[i] = bth_m->hdr.dst_qp[i] & bth_v->hdr.dst_qp[i];
11610 : : }
11611 : :
11612 : : static uint32_t matcher_zero[MLX5_ST_SZ_DW(fte_match_param)] = { 0 };
11613 : :
11614 : : #define HEADER_IS_ZERO(match_criteria, headers) \
11615 : : !(memcmp(MLX5_ADDR_OF(fte_match_param, match_criteria, headers), \
11616 : : matcher_zero, MLX5_FLD_SZ_BYTES(fte_match_param, headers))) \
11617 : :
11618 : : /**
11619 : : * Calculate flow matcher enable bitmap.
11620 : : *
11621 : : * @param match_criteria
11622 : : * Pointer to flow matcher criteria.
11623 : : *
11624 : : * @return
11625 : : * Bitmap of enabled fields.
11626 : : */
11627 : : static uint8_t
11628 : 0 : flow_dv_matcher_enable(uint32_t *match_criteria)
11629 : : {
11630 : : uint8_t match_criteria_enable;
11631 : :
11632 : : match_criteria_enable =
11633 : 0 : (!HEADER_IS_ZERO(match_criteria, outer_headers)) <<
11634 : : MLX5_MATCH_CRITERIA_ENABLE_OUTER_BIT;
11635 : 0 : match_criteria_enable |=
11636 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters)) <<
11637 : : MLX5_MATCH_CRITERIA_ENABLE_MISC_BIT;
11638 : 0 : match_criteria_enable |=
11639 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, inner_headers)) <<
11640 : : MLX5_MATCH_CRITERIA_ENABLE_INNER_BIT;
11641 : 0 : match_criteria_enable |=
11642 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) <<
11643 : : MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT;
11644 : 0 : match_criteria_enable |=
11645 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters_3)) <<
11646 : : MLX5_MATCH_CRITERIA_ENABLE_MISC3_BIT;
11647 : 0 : match_criteria_enable |=
11648 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters_4)) <<
11649 : : MLX5_MATCH_CRITERIA_ENABLE_MISC4_BIT;
11650 : 0 : match_criteria_enable |=
11651 [ # # ]: 0 : (!HEADER_IS_ZERO(match_criteria, misc_parameters_5)) <<
11652 : : MLX5_MATCH_CRITERIA_ENABLE_MISC5_BIT;
11653 : 0 : return match_criteria_enable;
11654 : : }
11655 : :
11656 : : static void
11657 : : __flow_dv_adjust_buf_size(size_t *size, uint8_t match_criteria)
11658 : : {
11659 : : /*
11660 : : * Check flow matching criteria first, subtract misc5/4 length if flow
11661 : : * doesn't own misc5/4 parameters. In some old rdma-core releases,
11662 : : * misc5/4 are not supported, and matcher creation failure is expected
11663 : : * w/o subtraction. If misc5 is provided, misc4 must be counted in since
11664 : : * misc5 is right after misc4.
11665 : : */
11666 : 0 : if (!(match_criteria & (1 << MLX5_MATCH_CRITERIA_ENABLE_MISC5_BIT))) {
11667 : 0 : *size = MLX5_ST_SZ_BYTES(fte_match_param) -
11668 : : MLX5_ST_SZ_BYTES(fte_match_set_misc5);
11669 [ # # # # : 0 : if (!(match_criteria & (1 <<
# # # # #
# # # # #
# # # # #
# ]
11670 : : MLX5_MATCH_CRITERIA_ENABLE_MISC4_BIT))) {
11671 : 0 : *size -= MLX5_ST_SZ_BYTES(fte_match_set_misc4);
11672 : : }
11673 : : }
11674 : : }
11675 : :
11676 : : struct mlx5_list_entry *
11677 : 0 : flow_matcher_clone_cb(void *tool_ctx __rte_unused,
11678 : : struct mlx5_list_entry *entry, void *cb_ctx)
11679 : : {
11680 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11681 : 0 : struct mlx5_flow_dv_matcher *ref = ctx->data;
11682 : 0 : struct mlx5_flow_tbl_data_entry *tbl = container_of(ref->tbl,
11683 : : typeof(*tbl), tbl);
11684 : 0 : struct mlx5_flow_dv_matcher *resource = mlx5_malloc(MLX5_MEM_ANY,
11685 : : sizeof(*resource),
11686 : : 0, SOCKET_ID_ANY);
11687 : :
11688 [ # # ]: 0 : if (!resource) {
11689 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
11690 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11691 : : "cannot create matcher");
11692 : 0 : return NULL;
11693 : : }
11694 : : memcpy(resource, entry, sizeof(*resource));
11695 : 0 : resource->tbl = &tbl->tbl;
11696 : 0 : return &resource->entry;
11697 : : }
11698 : :
11699 : : void
11700 : 0 : flow_matcher_clone_free_cb(void *tool_ctx __rte_unused,
11701 : : struct mlx5_list_entry *entry)
11702 : : {
11703 : 0 : mlx5_free(entry);
11704 : 0 : }
11705 : :
11706 : : struct mlx5_list_entry *
11707 : 0 : flow_dv_tbl_create_cb(void *tool_ctx, void *cb_ctx)
11708 : : {
11709 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11710 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11711 : 0 : struct rte_eth_dev *dev = ctx->dev;
11712 : : struct mlx5_flow_tbl_data_entry *tbl_data;
11713 : 0 : struct mlx5_flow_tbl_tunnel_prm *tt_prm = ctx->data2;
11714 : 0 : struct rte_flow_error *error = ctx->error;
11715 : 0 : union mlx5_flow_tbl_key key = { .v64 = *(uint64_t *)(ctx->data) };
11716 : : struct mlx5_flow_tbl_resource *tbl;
11717 : : void *domain;
11718 : 0 : uint32_t idx = 0;
11719 : : int ret;
11720 : :
11721 : 0 : tbl_data = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_JUMP], &idx);
11722 [ # # ]: 0 : if (!tbl_data) {
11723 : 0 : rte_flow_error_set(error, ENOMEM,
11724 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11725 : : NULL,
11726 : : "cannot allocate flow table data entry");
11727 : 0 : return NULL;
11728 : : }
11729 : 0 : tbl_data->idx = idx;
11730 : 0 : tbl_data->tunnel = tt_prm->tunnel;
11731 : 0 : tbl_data->group_id = tt_prm->group_id;
11732 [ # # ]: 0 : tbl_data->external = !!tt_prm->external;
11733 : 0 : tbl_data->tunnel_offload = is_tunnel_offload_active(dev);
11734 : 0 : tbl_data->is_egress = !!key.is_egress;
11735 : 0 : tbl_data->is_transfer = !!key.is_fdb;
11736 : 0 : tbl_data->dummy = !!key.dummy;
11737 : 0 : tbl_data->level = key.level;
11738 : 0 : tbl_data->id = key.id;
11739 : : tbl = &tbl_data->tbl;
11740 [ # # ]: 0 : if (key.dummy)
11741 : 0 : return &tbl_data->entry;
11742 [ # # ]: 0 : if (key.is_fdb)
11743 : 0 : domain = sh->fdb_domain;
11744 [ # # ]: 0 : else if (key.is_egress)
11745 : 0 : domain = sh->tx_domain;
11746 : : else
11747 : 0 : domain = sh->rx_domain;
11748 : : ret = mlx5_flow_os_create_flow_tbl(domain, key.level, &tbl->obj);
11749 : : if (ret) {
11750 : 0 : rte_flow_error_set(error, ENOMEM,
11751 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11752 : : NULL, "cannot create flow table object");
11753 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
11754 : 0 : return NULL;
11755 : : }
11756 [ # # ]: 0 : if (key.level != 0) {
11757 : : ret = mlx5_flow_os_create_flow_action_dest_flow_tbl
11758 : : (tbl->obj, &tbl_data->jump.action);
11759 : : if (ret) {
11760 : 0 : rte_flow_error_set(error, ENOMEM,
11761 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11762 : : NULL,
11763 : : "cannot create flow jump action");
11764 : 0 : mlx5_flow_os_destroy_flow_tbl(tbl->obj);
11765 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
11766 : 0 : return NULL;
11767 : : }
11768 : : }
11769 [ # # # # ]: 0 : MKSTR(matcher_name, "%s_%s_%u_%u_matcher_list",
11770 : : key.is_fdb ? "FDB" : "NIC", key.is_egress ? "egress" : "ingress",
11771 : : key.level, key.id);
11772 : 0 : tbl_data->matchers = mlx5_list_create(matcher_name, sh, true,
11773 : : flow_matcher_create_cb,
11774 : : flow_matcher_match_cb,
11775 : : flow_matcher_remove_cb,
11776 : : flow_matcher_clone_cb,
11777 : : flow_matcher_clone_free_cb);
11778 [ # # ]: 0 : if (!tbl_data->matchers) {
11779 : 0 : rte_flow_error_set(error, ENOMEM,
11780 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11781 : : NULL,
11782 : : "cannot create tbl matcher list");
11783 : 0 : mlx5_flow_os_destroy_flow_action(tbl_data->jump.action);
11784 : 0 : mlx5_flow_os_destroy_flow_tbl(tbl->obj);
11785 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], idx);
11786 : 0 : return NULL;
11787 : : }
11788 : 0 : return &tbl_data->entry;
11789 : : }
11790 : :
11791 : : int
11792 : 0 : flow_dv_tbl_match_cb(void *tool_ctx __rte_unused, struct mlx5_list_entry *entry,
11793 : : void *cb_ctx)
11794 : : {
11795 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11796 : : struct mlx5_flow_tbl_data_entry *tbl_data =
11797 : : container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
11798 : 0 : union mlx5_flow_tbl_key key = { .v64 = *(uint64_t *)(ctx->data) };
11799 : :
11800 : 0 : return tbl_data->level != key.level ||
11801 [ # # ]: 0 : tbl_data->id != key.id ||
11802 [ # # ]: 0 : tbl_data->dummy != key.dummy ||
11803 [ # # # # ]: 0 : tbl_data->is_transfer != !!key.is_fdb ||
11804 [ # # ]: 0 : tbl_data->is_egress != !!key.is_egress;
11805 : : }
11806 : :
11807 : : struct mlx5_list_entry *
11808 : 0 : flow_dv_tbl_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
11809 : : void *cb_ctx)
11810 : : {
11811 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11812 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11813 : : struct mlx5_flow_tbl_data_entry *tbl_data;
11814 : 0 : struct rte_flow_error *error = ctx->error;
11815 : 0 : uint32_t idx = 0;
11816 : :
11817 : 0 : tbl_data = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_JUMP], &idx);
11818 [ # # ]: 0 : if (!tbl_data) {
11819 : 0 : rte_flow_error_set(error, ENOMEM,
11820 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
11821 : : NULL,
11822 : : "cannot allocate flow table data entry");
11823 : 0 : return NULL;
11824 : : }
11825 : : memcpy(tbl_data, oentry, sizeof(*tbl_data));
11826 : 0 : tbl_data->idx = idx;
11827 : 0 : return &tbl_data->entry;
11828 : : }
11829 : :
11830 : : void
11831 : 0 : flow_dv_tbl_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
11832 : : {
11833 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11834 : : struct mlx5_flow_tbl_data_entry *tbl_data =
11835 : : container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
11836 : :
11837 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], tbl_data->idx);
11838 : 0 : }
11839 : :
11840 : : /**
11841 : : * Get a flow table.
11842 : : *
11843 : : * @param[in, out] dev
11844 : : * Pointer to rte_eth_dev structure.
11845 : : * @param[in] table_level
11846 : : * Table level to use.
11847 : : * @param[in] egress
11848 : : * Direction of the table.
11849 : : * @param[in] transfer
11850 : : * E-Switch or NIC flow.
11851 : : * @param[in] dummy
11852 : : * Dummy entry for dv API.
11853 : : * @param[in] table_id
11854 : : * Table id to use.
11855 : : * @param[out] error
11856 : : * pointer to error structure.
11857 : : *
11858 : : * @return
11859 : : * Returns tables resource based on the index, NULL in case of failed.
11860 : : */
11861 : : struct mlx5_flow_tbl_resource *
11862 : 0 : flow_dv_tbl_resource_get(struct rte_eth_dev *dev,
11863 : : uint32_t table_level, uint8_t egress,
11864 : : uint8_t transfer,
11865 : : bool external,
11866 : : const struct mlx5_flow_tunnel *tunnel,
11867 : : uint32_t group_id, uint8_t dummy,
11868 : : uint32_t table_id,
11869 : : struct rte_flow_error *error)
11870 : : {
11871 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
11872 : 0 : union mlx5_flow_tbl_key table_key = {
11873 : : {
11874 : : .level = table_level,
11875 : : .id = table_id,
11876 : : .reserved = 0,
11877 : 0 : .dummy = !!dummy,
11878 : 0 : .is_fdb = !!transfer,
11879 : 0 : .is_egress = !!egress,
11880 : : }
11881 : : };
11882 : 0 : struct mlx5_flow_tbl_tunnel_prm tt_prm = {
11883 : : .tunnel = tunnel,
11884 : : .group_id = group_id,
11885 : : .external = external,
11886 : : };
11887 : 0 : struct mlx5_flow_cb_ctx ctx = {
11888 : : .dev = dev,
11889 : : .error = error,
11890 : : .data = &table_key.v64,
11891 : : .data2 = &tt_prm,
11892 : : };
11893 : : struct mlx5_list_entry *entry;
11894 : : struct mlx5_flow_tbl_data_entry *tbl_data;
11895 : :
11896 : 0 : entry = mlx5_hlist_register(priv->sh->flow_tbls, table_key.v64, &ctx);
11897 [ # # ]: 0 : if (!entry) {
11898 : 0 : rte_flow_error_set(error, ENOMEM,
11899 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
11900 : : "cannot get table");
11901 : 0 : return NULL;
11902 : : }
11903 [ # # ]: 0 : DRV_LOG(DEBUG, "table_level %u table_id %u "
11904 : : "tunnel %u group %u registered.",
11905 : : table_level, table_id,
11906 : : tunnel ? tunnel->tunnel_id : 0, group_id);
11907 : : tbl_data = container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
11908 : 0 : return &tbl_data->tbl;
11909 : : }
11910 : :
11911 : : void
11912 : 0 : flow_dv_tbl_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
11913 : : {
11914 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11915 : : struct mlx5_flow_tbl_data_entry *tbl_data =
11916 : : container_of(entry, struct mlx5_flow_tbl_data_entry, entry);
11917 : :
11918 : : MLX5_ASSERT(entry && sh);
11919 [ # # ]: 0 : if (tbl_data->jump.action)
11920 : : mlx5_flow_os_destroy_flow_action(tbl_data->jump.action);
11921 [ # # ]: 0 : if (tbl_data->tbl.obj)
11922 : : mlx5_flow_os_destroy_flow_tbl(tbl_data->tbl.obj);
11923 [ # # ]: 0 : if (tbl_data->tunnel_offload && tbl_data->external) {
11924 : : struct mlx5_list_entry *he;
11925 : : struct mlx5_hlist *tunnel_grp_hash;
11926 : 0 : struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
11927 : 0 : union tunnel_tbl_key tunnel_key = {
11928 : 0 : .tunnel_id = tbl_data->tunnel ?
11929 [ # # ]: 0 : tbl_data->tunnel->tunnel_id : 0,
11930 : 0 : .group = tbl_data->group_id
11931 : : };
11932 : 0 : uint32_t table_level = tbl_data->level;
11933 : 0 : struct mlx5_flow_cb_ctx ctx = {
11934 : : .data = (void *)&tunnel_key.val,
11935 : : };
11936 : :
11937 : : tunnel_grp_hash = tbl_data->tunnel ?
11938 [ # # ]: 0 : tbl_data->tunnel->groups :
11939 : : thub->groups;
11940 : 0 : he = mlx5_hlist_lookup(tunnel_grp_hash, tunnel_key.val, &ctx);
11941 [ # # ]: 0 : if (he)
11942 : 0 : mlx5_hlist_unregister(tunnel_grp_hash, he);
11943 [ # # ]: 0 : DRV_LOG(DEBUG,
11944 : : "table_level %u id %u tunnel %u group %u released.",
11945 : : table_level,
11946 : : tbl_data->id,
11947 : : tbl_data->tunnel ?
11948 : : tbl_data->tunnel->tunnel_id : 0,
11949 : : tbl_data->group_id);
11950 : : }
11951 [ # # ]: 0 : if (tbl_data->matchers)
11952 : 0 : mlx5_list_destroy(tbl_data->matchers);
11953 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_JUMP], tbl_data->idx);
11954 : 0 : }
11955 : :
11956 : : /**
11957 : : * Release a flow table.
11958 : : *
11959 : : * @param[in] sh
11960 : : * Pointer to device shared structure.
11961 : : * @param[in] tbl
11962 : : * Table resource to be released.
11963 : : *
11964 : : * @return
11965 : : * Returns 0 if table was released, else return 1;
11966 : : */
11967 : : int
11968 : 0 : flow_dv_tbl_resource_release(struct mlx5_dev_ctx_shared *sh,
11969 : : struct mlx5_flow_tbl_resource *tbl)
11970 : : {
11971 : : struct mlx5_flow_tbl_data_entry *tbl_data =
11972 : 0 : container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
11973 : :
11974 [ # # ]: 0 : if (!tbl)
11975 : : return 0;
11976 : 0 : return mlx5_hlist_unregister(sh->flow_tbls, &tbl_data->entry);
11977 : : }
11978 : :
11979 : : int
11980 : 0 : flow_matcher_match_cb(void *tool_ctx __rte_unused,
11981 : : struct mlx5_list_entry *entry, void *cb_ctx)
11982 : : {
11983 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11984 : 0 : struct mlx5_flow_dv_matcher *ref = ctx->data;
11985 : : struct mlx5_flow_dv_matcher *cur = container_of(entry, typeof(*cur),
11986 : : entry);
11987 : :
11988 : 0 : return cur->crc != ref->crc ||
11989 [ # # ]: 0 : cur->priority != ref->priority ||
11990 : 0 : memcmp((const void *)cur->mask.buf,
11991 [ # # ]: 0 : (const void *)ref->mask.buf, ref->mask.size);
11992 : : }
11993 : :
11994 : : struct mlx5_list_entry *
11995 : 0 : flow_matcher_create_cb(void *tool_ctx, void *cb_ctx)
11996 : : {
11997 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
11998 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
11999 : 0 : struct mlx5_flow_dv_matcher *ref = ctx->data;
12000 : : struct mlx5_flow_dv_matcher *resource;
12001 : : #ifdef HAVE_MLX5_HWS_SUPPORT
12002 : : const struct rte_flow_item *items;
12003 : : #endif
12004 : 0 : struct mlx5dv_flow_matcher_attr dv_attr = {
12005 : : .type = IBV_FLOW_ATTR_NORMAL,
12006 : 0 : .match_mask = (void *)&ref->mask,
12007 : : };
12008 : : struct mlx5_flow_tbl_data_entry *tbl;
12009 : : int ret;
12010 : :
12011 : 0 : resource = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*resource), 0,
12012 : : SOCKET_ID_ANY);
12013 [ # # ]: 0 : if (!resource) {
12014 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12015 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12016 : : "cannot create matcher");
12017 : 0 : return NULL;
12018 : : }
12019 : 0 : *resource = *ref;
12020 [ # # ]: 0 : if (sh->config.dv_flow_en != 2) {
12021 : 0 : tbl = container_of(ref->tbl, typeof(*tbl), tbl);
12022 : 0 : dv_attr.match_criteria_enable =
12023 [ # # ]: 0 : flow_dv_matcher_enable(resource->mask.buf);
12024 : : __flow_dv_adjust_buf_size(&ref->mask.size,
12025 : : dv_attr.match_criteria_enable);
12026 : 0 : dv_attr.priority = ref->priority;
12027 [ # # ]: 0 : if (tbl->is_egress)
12028 : 0 : dv_attr.flags |= IBV_FLOW_ATTR_FLAGS_EGRESS;
12029 : 0 : ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
12030 : : tbl->tbl.obj,
12031 : : &resource->matcher_object);
12032 : : if (ret) {
12033 : 0 : mlx5_free(resource);
12034 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12035 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12036 : : "cannot create matcher");
12037 : 0 : return NULL;
12038 : : }
12039 : : } else {
12040 : : #ifdef HAVE_MLX5_HWS_SUPPORT
12041 : 0 : items = *((const struct rte_flow_item **)(ctx->data2));
12042 : 0 : resource->matcher_object = mlx5dr_bwc_matcher_create
12043 : 0 : (resource->group->tbl, resource->priority, items);
12044 [ # # ]: 0 : if (!resource->matcher_object) {
12045 : 0 : mlx5_free(resource);
12046 : 0 : return NULL;
12047 : : }
12048 : : #else
12049 : : mlx5_free(resource);
12050 : : return NULL;
12051 : : #endif
12052 : : }
12053 : 0 : return &resource->entry;
12054 : : }
12055 : :
12056 : : /**
12057 : : * Register the flow matcher.
12058 : : *
12059 : : * @param[in, out] dev
12060 : : * Pointer to rte_eth_dev structure.
12061 : : * @param[in, out] matcher
12062 : : * Pointer to flow matcher.
12063 : : * @param[in, out] key
12064 : : * Pointer to flow table key.
12065 : : * @parm[in, out] dev_flow
12066 : : * Pointer to the dev_flow.
12067 : : * @param[out] error
12068 : : * pointer to error structure.
12069 : : *
12070 : : * @return
12071 : : * 0 on success otherwise -errno and errno is set.
12072 : : */
12073 : : static int
12074 : 0 : flow_dv_matcher_register(struct rte_eth_dev *dev,
12075 : : struct mlx5_flow_dv_matcher *ref,
12076 : : union mlx5_flow_tbl_key *key,
12077 : : struct mlx5_flow *dev_flow,
12078 : : const struct mlx5_flow_tunnel *tunnel,
12079 : : uint32_t group_id,
12080 : : struct rte_flow_error *error)
12081 : : {
12082 : : struct mlx5_list_entry *entry;
12083 : : struct mlx5_flow_dv_matcher *resource;
12084 : : struct mlx5_flow_tbl_resource *tbl;
12085 : : struct mlx5_flow_tbl_data_entry *tbl_data;
12086 : 0 : struct mlx5_flow_cb_ctx ctx = {
12087 : : .error = error,
12088 : : .data = ref,
12089 : : };
12090 : : /**
12091 : : * tunnel offload API requires this registration for cases when
12092 : : * tunnel match rule was inserted before tunnel set rule.
12093 : : */
12094 : 0 : tbl = flow_dv_tbl_resource_get(dev, key->level,
12095 : 0 : key->is_egress, key->is_fdb,
12096 : 0 : dev_flow->external, tunnel,
12097 : 0 : group_id, 0, key->id, error);
12098 [ # # ]: 0 : if (!tbl)
12099 : 0 : return -rte_errno; /* No need to refill the error info */
12100 : 0 : tbl_data = container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
12101 : 0 : ref->tbl = tbl;
12102 : 0 : entry = mlx5_list_register(tbl_data->matchers, &ctx);
12103 [ # # ]: 0 : if (!entry) {
12104 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
12105 : 0 : return rte_flow_error_set(error, ENOMEM,
12106 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12107 : : "cannot allocate ref memory");
12108 : : }
12109 : : resource = container_of(entry, typeof(*resource), entry);
12110 : 0 : dev_flow->handle->dvh.matcher = resource;
12111 : 0 : return 0;
12112 : : }
12113 : :
12114 : : struct mlx5_list_entry *
12115 : 0 : flow_dv_tag_create_cb(void *tool_ctx, void *cb_ctx)
12116 : : {
12117 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
12118 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12119 : : struct mlx5_flow_dv_tag_resource *entry;
12120 : 0 : uint32_t idx = 0;
12121 : : int ret;
12122 : :
12123 : 0 : entry = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_TAG], &idx);
12124 [ # # ]: 0 : if (!entry) {
12125 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12126 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12127 : : "cannot allocate resource memory");
12128 : 0 : return NULL;
12129 : : }
12130 : 0 : entry->idx = idx;
12131 : 0 : entry->tag_id = *(uint32_t *)(ctx->data);
12132 : : ret = mlx5_flow_os_create_flow_action_tag(entry->tag_id,
12133 : : &entry->action);
12134 : : if (ret) {
12135 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], idx);
12136 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12137 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12138 : : NULL, "cannot create action");
12139 : 0 : return NULL;
12140 : : }
12141 : 0 : return &entry->entry;
12142 : : }
12143 : :
12144 : : int
12145 : 0 : flow_dv_tag_match_cb(void *tool_ctx __rte_unused, struct mlx5_list_entry *entry,
12146 : : void *cb_ctx)
12147 : : {
12148 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12149 : : struct mlx5_flow_dv_tag_resource *tag =
12150 : : container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
12151 : :
12152 : 0 : return *(uint32_t *)(ctx->data) != tag->tag_id;
12153 : : }
12154 : :
12155 : : struct mlx5_list_entry *
12156 : 0 : flow_dv_tag_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
12157 : : void *cb_ctx)
12158 : : {
12159 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
12160 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12161 : : struct mlx5_flow_dv_tag_resource *entry;
12162 : 0 : uint32_t idx = 0;
12163 : :
12164 : 0 : entry = mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_TAG], &idx);
12165 [ # # ]: 0 : if (!entry) {
12166 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12167 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
12168 : : "cannot allocate tag resource memory");
12169 : 0 : return NULL;
12170 : : }
12171 : : memcpy(entry, oentry, sizeof(*entry));
12172 : 0 : entry->idx = idx;
12173 : 0 : return &entry->entry;
12174 : : }
12175 : :
12176 : : void
12177 : 0 : flow_dv_tag_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
12178 : : {
12179 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
12180 : : struct mlx5_flow_dv_tag_resource *tag =
12181 : : container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
12182 : :
12183 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], tag->idx);
12184 : 0 : }
12185 : :
12186 : : /**
12187 : : * Find existing tag resource or create and register a new one.
12188 : : *
12189 : : * @param dev[in, out]
12190 : : * Pointer to rte_eth_dev structure.
12191 : : * @param[in, out] tag_be24
12192 : : * Tag value in big endian then R-shift 8.
12193 : : * @parm[in, out] dev_flow
12194 : : * Pointer to the dev_flow.
12195 : : * @param[out] error
12196 : : * pointer to error structure.
12197 : : *
12198 : : * @return
12199 : : * 0 on success otherwise -errno and errno is set.
12200 : : */
12201 : : static int
12202 : 0 : flow_dv_tag_resource_register
12203 : : (struct rte_eth_dev *dev,
12204 : : uint32_t tag_be24,
12205 : : struct mlx5_flow *dev_flow,
12206 : : struct rte_flow_error *error)
12207 : : {
12208 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12209 : : struct mlx5_flow_dv_tag_resource *resource;
12210 : : struct mlx5_list_entry *entry;
12211 : 0 : struct mlx5_flow_cb_ctx ctx = {
12212 : : .error = error,
12213 : : .data = &tag_be24,
12214 : : };
12215 : : struct mlx5_hlist *tag_table;
12216 : :
12217 : 0 : tag_table = flow_dv_hlist_prepare(priv->sh, &priv->sh->tag_table,
12218 : : "tags",
12219 : : MLX5_TAGS_HLIST_ARRAY_SIZE,
12220 : 0 : false, false, priv->sh,
12221 : : flow_dv_tag_create_cb,
12222 : : flow_dv_tag_match_cb,
12223 : : flow_dv_tag_remove_cb,
12224 : : flow_dv_tag_clone_cb,
12225 : : flow_dv_tag_clone_free_cb,
12226 : : error);
12227 [ # # ]: 0 : if (unlikely(!tag_table))
12228 : 0 : return -rte_errno;
12229 : 0 : entry = mlx5_hlist_register(tag_table, tag_be24, &ctx);
12230 [ # # ]: 0 : if (entry) {
12231 : : resource = container_of(entry, struct mlx5_flow_dv_tag_resource,
12232 : : entry);
12233 : 0 : dev_flow->handle->dvh.rix_tag = resource->idx;
12234 : 0 : dev_flow->dv.tag_resource = resource;
12235 : 0 : return 0;
12236 : : }
12237 : 0 : return -rte_errno;
12238 : : }
12239 : :
12240 : : void
12241 : 0 : flow_dv_tag_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
12242 : : {
12243 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
12244 : : struct mlx5_flow_dv_tag_resource *tag =
12245 : : container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
12246 : :
12247 : : MLX5_ASSERT(tag && sh && tag->action);
12248 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(tag->action));
12249 : 0 : DRV_LOG(DEBUG, "Tag %p: removed.", (void *)tag);
12250 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], tag->idx);
12251 : 0 : }
12252 : :
12253 : : /**
12254 : : * Release the tag.
12255 : : *
12256 : : * @param dev
12257 : : * Pointer to Ethernet device.
12258 : : * @param tag_idx
12259 : : * Tag index.
12260 : : *
12261 : : * @return
12262 : : * 1 while a reference on it exists, 0 when freed.
12263 : : */
12264 : : static int
12265 : 0 : flow_dv_tag_release(struct rte_eth_dev *dev,
12266 : : uint32_t tag_idx)
12267 : : {
12268 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12269 : : struct mlx5_flow_dv_tag_resource *tag;
12270 : :
12271 : 0 : tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG], tag_idx);
12272 [ # # ]: 0 : if (!tag)
12273 : : return 0;
12274 : 0 : DRV_LOG(DEBUG, "port %u tag %p: refcnt %d--",
12275 : : dev->data->port_id, (void *)tag, tag->entry.ref_cnt);
12276 : 0 : return mlx5_hlist_unregister(priv->sh->tag_table, &tag->entry);
12277 : : }
12278 : :
12279 : : /**
12280 : : * Translate action PORT_ID / REPRESENTED_PORT to vport.
12281 : : *
12282 : : * @param[in] dev
12283 : : * Pointer to rte_eth_dev structure.
12284 : : * @param[in] action
12285 : : * Pointer to action PORT_ID / REPRESENTED_PORT.
12286 : : * @param[out] dst_port_id
12287 : : * The target port ID.
12288 : : * @param[out] error
12289 : : * Pointer to the error structure.
12290 : : *
12291 : : * @return
12292 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
12293 : : */
12294 : : static int
12295 : 0 : flow_dv_translate_action_port_id(struct rte_eth_dev *dev,
12296 : : const struct rte_flow_action *action,
12297 : : uint32_t *dst_port_id,
12298 : : struct rte_flow_error *error)
12299 : : {
12300 : : uint32_t port;
12301 : : struct mlx5_priv *priv;
12302 : :
12303 [ # # # ]: 0 : switch (action->type) {
12304 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID: {
12305 : : const struct rte_flow_action_port_id *conf;
12306 : :
12307 : 0 : conf = (const struct rte_flow_action_port_id *)action->conf;
12308 [ # # ]: 0 : port = conf->original ? dev->data->port_id : conf->id;
12309 : : break;
12310 : : }
12311 : 0 : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT: {
12312 : : const struct rte_flow_action_ethdev *ethdev;
12313 : :
12314 : 0 : ethdev = (const struct rte_flow_action_ethdev *)action->conf;
12315 : 0 : port = ethdev->port_id;
12316 : 0 : break;
12317 : : }
12318 : 0 : default:
12319 : : MLX5_ASSERT(false);
12320 : 0 : return rte_flow_error_set(error, EINVAL,
12321 : : RTE_FLOW_ERROR_TYPE_ACTION, action,
12322 : : "unknown E-Switch action");
12323 : : }
12324 : :
12325 : 0 : priv = mlx5_port_to_eswitch_info(port, false);
12326 [ # # ]: 0 : if (!priv)
12327 : 0 : return rte_flow_error_set(error, -rte_errno,
12328 : : RTE_FLOW_ERROR_TYPE_ACTION,
12329 : : NULL,
12330 : : "No eswitch info was found for port");
12331 : : #ifdef HAVE_MLX5DV_DR_CREATE_DEST_IB_PORT
12332 : : /*
12333 : : * This parameter is transferred to
12334 : : * mlx5dv_dr_action_create_dest_ib_port().
12335 : : */
12336 : 0 : *dst_port_id = priv->dev_port;
12337 : : #else
12338 : : /*
12339 : : * Legacy mode, no LAG configurations is supported.
12340 : : * This parameter is transferred to
12341 : : * mlx5dv_dr_action_create_dest_vport().
12342 : : */
12343 : : *dst_port_id = priv->vport_id;
12344 : : #endif
12345 : 0 : return 0;
12346 : : }
12347 : :
12348 : : /**
12349 : : * Create a counter with aging configuration.
12350 : : *
12351 : : * @param[in] dev
12352 : : * Pointer to rte_eth_dev structure.
12353 : : * @param[in] dev_flow
12354 : : * Pointer to the mlx5_flow.
12355 : : * @param[out] count
12356 : : * Pointer to the counter action configuration.
12357 : : * @param[in] age
12358 : : * Pointer to the aging action configuration.
12359 : : *
12360 : : * @return
12361 : : * Index to flow counter on success, 0 otherwise.
12362 : : */
12363 : : static uint32_t
12364 : 0 : flow_dv_translate_create_counter(struct rte_eth_dev *dev,
12365 : : struct mlx5_flow *dev_flow,
12366 : : const struct rte_flow_action_count *count
12367 : : __rte_unused,
12368 : : const struct rte_flow_action_age *age)
12369 : : {
12370 : : uint32_t counter;
12371 : : struct mlx5_age_param *age_param;
12372 : :
12373 : 0 : counter = flow_dv_counter_alloc(dev, !!age);
12374 [ # # ]: 0 : if (!counter || age == NULL)
12375 : : return counter;
12376 : : age_param = flow_dv_counter_idx_get_age(dev, counter);
12377 [ # # ]: 0 : age_param->context = age->context ? age->context :
12378 : 0 : (void *)(uintptr_t)(dev_flow->flow_idx);
12379 : 0 : age_param->timeout = age->timeout;
12380 : 0 : age_param->port_id = dev->data->port_id;
12381 : 0 : rte_atomic_store_explicit(&age_param->sec_since_last_hit, 0, rte_memory_order_relaxed);
12382 : 0 : rte_atomic_store_explicit(&age_param->state, AGE_CANDIDATE, rte_memory_order_relaxed);
12383 : 0 : return counter;
12384 : : }
12385 : :
12386 : : /**
12387 : : * Add Tx queue matcher
12388 : : *
12389 : : * @param[in] dev
12390 : : * Pointer to rte_eth_dev structure.
12391 : : * @param[in, out] key
12392 : : * Flow matcher value.
12393 : : * @param[in] item
12394 : : * Flow pattern to translate.
12395 : : * @param[in] key_type
12396 : : * Set flow matcher mask or value.
12397 : : *
12398 : : * @return
12399 : : * 0 on success otherwise -errno and errno is set.
12400 : : */
12401 : : static int
12402 : 0 : flow_dv_translate_item_tx_queue(struct rte_eth_dev *dev, void *key,
12403 : : const struct rte_flow_item *item, uint32_t key_type)
12404 : : {
12405 : : const struct rte_flow_item_tx_queue *queue_m;
12406 : : const struct rte_flow_item_tx_queue *queue_v;
12407 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
12408 : : uint32_t tx_queue;
12409 : : uint32_t sqn = 0;
12410 : : int ret;
12411 : :
12412 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, queue_v, queue_m, &rte_flow_item_tx_queue_mask);
# # # # ]
12413 [ # # ]: 0 : if (!queue_m || !queue_v)
12414 : : return -EINVAL;
12415 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_V) {
12416 : 0 : tx_queue = queue_v->tx_queue;
12417 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_V)
12418 : 0 : tx_queue &= queue_m->tx_queue;
12419 [ # # ]: 0 : ret = flow_hw_get_sqn(dev, tx_queue, &sqn);
12420 [ # # ]: 0 : if (unlikely(ret))
12421 : 0 : return -ret;
12422 : : } else {
12423 : : /* Due to tx_queue to sqn converting, only fully masked value support. */
12424 [ # # ]: 0 : if (queue_m->tx_queue != rte_flow_item_tx_queue_mask.tx_queue)
12425 : : return -EINVAL;
12426 : : sqn = UINT32_MAX;
12427 : : }
12428 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, source_sqn, sqn);
12429 : 0 : return 0;
12430 : : }
12431 : :
12432 : : /**
12433 : : * Add SQ matcher
12434 : : *
12435 : : * @param[in, out] matcher
12436 : : * Flow matcher.
12437 : : * @param[in, out] key
12438 : : * Flow matcher value.
12439 : : * @param[in] item
12440 : : * Flow pattern to translate.
12441 : : * @param[in] key_type
12442 : : * Set flow matcher mask or value.
12443 : : */
12444 : : static void
12445 : 0 : flow_dv_translate_item_sq(void *key,
12446 : : const struct rte_flow_item *item,
12447 : : uint32_t key_type)
12448 : : {
12449 : : const struct mlx5_rte_flow_item_sq *queue_m;
12450 : : const struct mlx5_rte_flow_item_sq *queue_v;
12451 : 0 : const struct mlx5_rte_flow_item_sq queue_mask = {
12452 : : .queue = UINT32_MAX,
12453 : : };
12454 : : void *misc_v = MLX5_ADDR_OF(fte_match_param, key, misc_parameters);
12455 : : uint32_t queue;
12456 : :
12457 [ # # # # : 0 : MLX5_ITEM_UPDATE(item, key_type, queue_v, queue_m, &queue_mask);
# # # # ]
12458 [ # # ]: 0 : if (!queue_m || !queue_v)
12459 : 0 : return;
12460 [ # # ]: 0 : if (key_type & MLX5_SET_MATCHER_V) {
12461 : 0 : queue = queue_v->queue;
12462 [ # # ]: 0 : if (key_type == MLX5_SET_MATCHER_SW_V)
12463 : 0 : queue &= queue_m->queue;
12464 : : } else {
12465 : 0 : queue = queue_m->queue;
12466 : : }
12467 [ # # ]: 0 : MLX5_SET(fte_match_set_misc, misc_v, source_sqn, queue);
12468 : : }
12469 : :
12470 : : /**
12471 : : * Set the hash fields according to the @p flow information.
12472 : : *
12473 : : * @param[in] item_flags
12474 : : * The match pattern item flags.
12475 : : * @param[in] rss_desc
12476 : : * Pointer to the mlx5_flow_rss_desc.
12477 : : * @param[out] hash_fields
12478 : : * Pointer to the RSS hash fields.
12479 : : */
12480 : : void
12481 : 0 : flow_dv_hashfields_set(uint64_t item_flags,
12482 : : struct mlx5_flow_rss_desc *rss_desc,
12483 : : uint64_t *hash_fields)
12484 : : {
12485 : : uint64_t items = item_flags;
12486 : : uint64_t fields = 0;
12487 : : int rss_inner = 0;
12488 [ # # ]: 0 : uint64_t rss_types = rte_eth_rss_hf_refine(rss_desc->types);
12489 : :
12490 : : *hash_fields = 0;
12491 : : #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
12492 [ # # ]: 0 : if (rss_desc->level >= 2)
12493 : : rss_inner = 1;
12494 : : #endif
12495 [ # # # # ]: 0 : if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV4)) ||
12496 [ # # ]: 0 : (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV4))) {
12497 [ # # ]: 0 : if (rss_types & MLX5_IPV4_LAYER_TYPES) {
12498 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
12499 : : fields |= IBV_RX_HASH_SRC_IPV4;
12500 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
12501 : : fields |= IBV_RX_HASH_DST_IPV4;
12502 : : else
12503 : : fields |= MLX5_IPV4_IBV_RX_HASH;
12504 : : }
12505 [ # # # # : 0 : } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L3_IPV6)) ||
# # ]
12506 [ # # ]: 0 : (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L3_IPV6))) {
12507 [ # # ]: 0 : if (rss_types & MLX5_IPV6_LAYER_TYPES) {
12508 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
12509 : : fields |= IBV_RX_HASH_SRC_IPV6;
12510 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
12511 : : fields |= IBV_RX_HASH_DST_IPV6;
12512 : : else
12513 : : fields |= MLX5_IPV6_IBV_RX_HASH;
12514 : : }
12515 : : }
12516 [ # # ]: 0 : if (items & MLX5_FLOW_ITEM_ESP) {
12517 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_ESP)
12518 : 0 : fields |= IBV_RX_HASH_IPSEC_SPI;
12519 : : }
12520 [ # # ]: 0 : if ((fields & ~IBV_RX_HASH_IPSEC_SPI) == 0) {
12521 : 0 : *hash_fields = fields;
12522 : : /*
12523 : : * There is no match between the RSS types and the
12524 : : * L3 protocol (IPv4/IPv6) defined in the flow rule.
12525 : : */
12526 : 0 : return;
12527 : : }
12528 [ # # # # : 0 : if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_UDP)) ||
# # ]
12529 [ # # ]: 0 : (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_UDP))) {
12530 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_UDP) {
12531 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
12532 : 0 : fields |= IBV_RX_HASH_SRC_PORT_UDP;
12533 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
12534 : 0 : fields |= IBV_RX_HASH_DST_PORT_UDP;
12535 : : else
12536 : 0 : fields |= MLX5_UDP_IBV_RX_HASH;
12537 : : }
12538 [ # # # # : 0 : } else if ((rss_inner && (items & MLX5_FLOW_LAYER_INNER_L4_TCP)) ||
# # ]
12539 [ # # ]: 0 : (!rss_inner && (items & MLX5_FLOW_LAYER_OUTER_L4_TCP))) {
12540 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_TCP) {
12541 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
12542 : 0 : fields |= IBV_RX_HASH_SRC_PORT_TCP;
12543 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
12544 : 0 : fields |= IBV_RX_HASH_DST_PORT_TCP;
12545 : : else
12546 : 0 : fields |= MLX5_TCP_IBV_RX_HASH;
12547 : : }
12548 : : }
12549 [ # # ]: 0 : if (rss_inner)
12550 : 0 : fields |= IBV_RX_HASH_INNER;
12551 : 0 : *hash_fields = fields;
12552 : : }
12553 : :
12554 : : /**
12555 : : * Prepare an Rx Hash queue.
12556 : : *
12557 : : * @param dev
12558 : : * Pointer to Ethernet device.
12559 : : * @param[in] dev_flow
12560 : : * Pointer to the mlx5_flow.
12561 : : * @param[in] rss_desc
12562 : : * Pointer to the mlx5_flow_rss_desc.
12563 : : * @param[out] hrxq_idx
12564 : : * Hash Rx queue index.
12565 : : *
12566 : : * @return
12567 : : * The Verbs/DevX object initialised, NULL otherwise and rte_errno is set.
12568 : : */
12569 : : static struct mlx5_hrxq *
12570 : 0 : flow_dv_hrxq_prepare(struct rte_eth_dev *dev,
12571 : : struct mlx5_flow *dev_flow,
12572 : : struct mlx5_flow_rss_desc *rss_desc,
12573 : : uint32_t *hrxq_idx)
12574 : : {
12575 : 0 : struct mlx5_flow_handle *dh = dev_flow->handle;
12576 : 0 : uint32_t shared_rss = rss_desc->shared_rss;
12577 : : struct mlx5_hrxq *hrxq;
12578 : :
12579 : : MLX5_ASSERT(rss_desc->queue_num);
12580 : 0 : rss_desc->symmetric_hash_function = dev_flow->symmetric_hash_function;
12581 : 0 : rss_desc->key_len = MLX5_RSS_HASH_KEY_LEN;
12582 : 0 : rss_desc->hash_fields = dev_flow->hash_fields;
12583 : 0 : rss_desc->tunnel = !!(dh->layers & MLX5_FLOW_LAYER_TUNNEL);
12584 : 0 : rss_desc->shared_rss = 0;
12585 [ # # ]: 0 : if (rss_desc->hash_fields == 0)
12586 : 0 : rss_desc->queue_num = 1;
12587 : 0 : hrxq = mlx5_hrxq_get(dev, rss_desc);
12588 [ # # ]: 0 : *hrxq_idx = hrxq ? hrxq->idx : 0;
12589 : 0 : rss_desc->shared_rss = shared_rss;
12590 : 0 : return hrxq;
12591 : : }
12592 : :
12593 : : /**
12594 : : * Release sample sub action resource.
12595 : : *
12596 : : * @param[in, out] dev
12597 : : * Pointer to rte_eth_dev structure.
12598 : : * @param[in] act_res
12599 : : * Pointer to sample sub action resource.
12600 : : */
12601 : : static void
12602 : 0 : flow_dv_sample_sub_actions_release(struct rte_eth_dev *dev,
12603 : : struct mlx5_flow_sub_actions_idx *act_res)
12604 : : {
12605 [ # # ]: 0 : if (act_res->rix_hrxq) {
12606 : 0 : mlx5_hrxq_release(dev, act_res->rix_hrxq);
12607 : 0 : act_res->rix_hrxq = 0;
12608 : : }
12609 [ # # ]: 0 : if (act_res->rix_encap_decap) {
12610 : 0 : flow_encap_decap_resource_release(dev,
12611 : : act_res->rix_encap_decap);
12612 : 0 : act_res->rix_encap_decap = 0;
12613 : : }
12614 [ # # ]: 0 : if (act_res->rix_port_id_action) {
12615 : 0 : flow_dv_port_id_action_resource_release(dev,
12616 : : act_res->rix_port_id_action);
12617 : 0 : act_res->rix_port_id_action = 0;
12618 : : }
12619 [ # # ]: 0 : if (act_res->rix_tag) {
12620 : 0 : flow_dv_tag_release(dev, act_res->rix_tag);
12621 : 0 : act_res->rix_tag = 0;
12622 : : }
12623 [ # # ]: 0 : if (act_res->rix_jump) {
12624 : 0 : flow_dv_jump_tbl_resource_release(dev, act_res->rix_jump);
12625 : 0 : act_res->rix_jump = 0;
12626 : : }
12627 : 0 : }
12628 : :
12629 : : int
12630 : 0 : flow_dv_sample_match_cb(void *tool_ctx __rte_unused,
12631 : : struct mlx5_list_entry *entry, void *cb_ctx)
12632 : : {
12633 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12634 : 0 : struct rte_eth_dev *dev = ctx->dev;
12635 : 0 : struct mlx5_flow_dv_sample_resource *ctx_resource = ctx->data;
12636 : : struct mlx5_flow_dv_sample_resource *resource = container_of(entry,
12637 : : typeof(*resource),
12638 : : entry);
12639 : :
12640 [ # # ]: 0 : if (ctx_resource->ratio == resource->ratio &&
12641 [ # # ]: 0 : ctx_resource->ft_type == resource->ft_type &&
12642 [ # # ]: 0 : ctx_resource->ft_id == resource->ft_id &&
12643 [ # # ]: 0 : ctx_resource->set_action == resource->set_action &&
12644 : 0 : !memcmp((void *)&ctx_resource->sample_act,
12645 [ # # ]: 0 : (void *)&resource->sample_act,
12646 : : sizeof(struct mlx5_flow_sub_actions_list))) {
12647 : : /*
12648 : : * Existing sample action should release the prepared
12649 : : * sub-actions reference counter.
12650 : : */
12651 : 0 : flow_dv_sample_sub_actions_release(dev,
12652 : : &ctx_resource->sample_idx);
12653 : 0 : return 0;
12654 : : }
12655 : : return 1;
12656 : : }
12657 : :
12658 : : struct mlx5_list_entry *
12659 : 0 : flow_dv_sample_create_cb(void *tool_ctx __rte_unused, void *cb_ctx)
12660 : : {
12661 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12662 : 0 : struct rte_eth_dev *dev = ctx->dev;
12663 : 0 : struct mlx5_flow_dv_sample_resource *ctx_resource = ctx->data;
12664 : 0 : void **sample_dv_actions = ctx_resource->sub_actions;
12665 : : struct mlx5_flow_dv_sample_resource *resource;
12666 : : struct mlx5dv_dr_flow_sampler_attr sampler_attr;
12667 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12668 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
12669 : : struct mlx5_flow_tbl_resource *tbl;
12670 : 0 : uint32_t idx = 0;
12671 : : const uint32_t next_ft_step = 1;
12672 : 0 : uint32_t next_ft_id = ctx_resource->ft_id + next_ft_step;
12673 : : uint8_t is_egress = 0;
12674 : : uint8_t is_transfer = 0;
12675 : 0 : struct rte_flow_error *error = ctx->error;
12676 : :
12677 : : /* Register new sample resource. */
12678 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_SAMPLE], &idx);
12679 [ # # ]: 0 : if (!resource) {
12680 : 0 : rte_flow_error_set(error, ENOMEM,
12681 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12682 : : NULL,
12683 : : "cannot allocate resource memory");
12684 : 0 : return NULL;
12685 : : }
12686 : 0 : *resource = *ctx_resource;
12687 : : /* Create normal path table level */
12688 [ # # ]: 0 : if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
12689 : : is_transfer = 1;
12690 [ # # ]: 0 : else if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
12691 : : is_egress = 1;
12692 : 0 : tbl = flow_dv_tbl_resource_get(dev, next_ft_id,
12693 : : is_egress, is_transfer,
12694 : : true, NULL, 0, 0, 0, error);
12695 [ # # ]: 0 : if (!tbl) {
12696 : 0 : rte_flow_error_set(error, ENOMEM,
12697 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12698 : : NULL,
12699 : : "fail to create normal path table "
12700 : : "for sample");
12701 : 0 : goto error;
12702 : : }
12703 : 0 : resource->normal_path_tbl = tbl;
12704 [ # # ]: 0 : if (ctx_resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB) {
12705 [ # # ]: 0 : if (!sh->default_miss_action) {
12706 : 0 : rte_flow_error_set(error, ENOMEM,
12707 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12708 : : NULL,
12709 : : "default miss action was not "
12710 : : "created");
12711 : 0 : goto error;
12712 : : }
12713 : 0 : sample_dv_actions[ctx_resource->sample_act.actions_num++] =
12714 : : sh->default_miss_action;
12715 : : }
12716 : : /* Create a DR sample action */
12717 : 0 : sampler_attr.sample_ratio = resource->ratio;
12718 : 0 : sampler_attr.default_next_table = tbl->obj;
12719 : 0 : sampler_attr.num_sample_actions = ctx_resource->sample_act.actions_num;
12720 : 0 : sampler_attr.sample_actions = (struct mlx5dv_dr_action **)
12721 : : &sample_dv_actions[0];
12722 : 0 : sampler_attr.action = resource->set_action;
12723 : : if (mlx5_os_flow_dr_create_flow_action_sampler
12724 : : (&sampler_attr, &resource->verbs_action)) {
12725 : 0 : rte_flow_error_set(error, ENOMEM,
12726 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12727 : : NULL, "cannot create sample action");
12728 : 0 : goto error;
12729 : : }
12730 : 0 : resource->idx = idx;
12731 : 0 : resource->dev = dev;
12732 : 0 : return &resource->entry;
12733 : 0 : error:
12734 [ # # ]: 0 : if (resource->ft_type != MLX5DV_FLOW_TABLE_TYPE_FDB)
12735 : 0 : flow_dv_sample_sub_actions_release(dev,
12736 : : &resource->sample_idx);
12737 [ # # ]: 0 : if (resource->normal_path_tbl)
12738 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev),
12739 : : resource->normal_path_tbl);
12740 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_SAMPLE], idx);
12741 : 0 : return NULL;
12742 : :
12743 : : }
12744 : :
12745 : : struct mlx5_list_entry *
12746 : 0 : flow_dv_sample_clone_cb(void *tool_ctx __rte_unused,
12747 : : struct mlx5_list_entry *entry __rte_unused,
12748 : : void *cb_ctx)
12749 : : {
12750 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12751 : 0 : struct rte_eth_dev *dev = ctx->dev;
12752 : : struct mlx5_flow_dv_sample_resource *resource;
12753 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12754 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
12755 : 0 : uint32_t idx = 0;
12756 : :
12757 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_SAMPLE], &idx);
12758 [ # # ]: 0 : if (!resource) {
12759 : 0 : rte_flow_error_set(ctx->error, ENOMEM,
12760 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12761 : : NULL,
12762 : : "cannot allocate resource memory");
12763 : 0 : return NULL;
12764 : : }
12765 : : memcpy(resource, entry, sizeof(*resource));
12766 : 0 : resource->idx = idx;
12767 : 0 : resource->dev = dev;
12768 : 0 : return &resource->entry;
12769 : : }
12770 : :
12771 : : void
12772 : 0 : flow_dv_sample_clone_free_cb(void *tool_ctx __rte_unused,
12773 : : struct mlx5_list_entry *entry)
12774 : : {
12775 : : struct mlx5_flow_dv_sample_resource *resource =
12776 : : container_of(entry, typeof(*resource), entry);
12777 : 0 : struct rte_eth_dev *dev = resource->dev;
12778 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12779 : :
12780 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_SAMPLE], resource->idx);
12781 : 0 : }
12782 : :
12783 : : /**
12784 : : * Find existing sample resource or create and register a new one.
12785 : : *
12786 : : * @param[in, out] dev
12787 : : * Pointer to rte_eth_dev structure.
12788 : : * @param[in] ref
12789 : : * Pointer to sample resource reference.
12790 : : * @parm[in, out] dev_flow
12791 : : * Pointer to the dev_flow.
12792 : : * @param[out] error
12793 : : * pointer to error structure.
12794 : : *
12795 : : * @return
12796 : : * 0 on success otherwise -errno and errno is set.
12797 : : */
12798 : : static int
12799 : 0 : flow_dv_sample_resource_register(struct rte_eth_dev *dev,
12800 : : struct mlx5_flow_dv_sample_resource *ref,
12801 : : struct mlx5_flow *dev_flow,
12802 : : struct rte_flow_error *error)
12803 : : {
12804 : : struct mlx5_flow_dv_sample_resource *resource;
12805 : : struct mlx5_list_entry *entry;
12806 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12807 : 0 : struct mlx5_flow_cb_ctx ctx = {
12808 : : .dev = dev,
12809 : : .error = error,
12810 : : .data = ref,
12811 : : };
12812 : :
12813 : 0 : entry = mlx5_list_register(priv->sh->sample_action_list, &ctx);
12814 [ # # ]: 0 : if (!entry)
12815 : 0 : return -rte_errno;
12816 : : resource = container_of(entry, typeof(*resource), entry);
12817 : 0 : dev_flow->handle->dvh.rix_sample = resource->idx;
12818 : 0 : dev_flow->dv.sample_res = resource;
12819 : 0 : return 0;
12820 : : }
12821 : :
12822 : : int
12823 : 0 : flow_dv_dest_array_match_cb(void *tool_ctx __rte_unused,
12824 : : struct mlx5_list_entry *entry, void *cb_ctx)
12825 : : {
12826 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12827 : 0 : struct mlx5_flow_dv_dest_array_resource *ctx_resource = ctx->data;
12828 : 0 : struct rte_eth_dev *dev = ctx->dev;
12829 : : struct mlx5_flow_dv_dest_array_resource *resource =
12830 : : container_of(entry, typeof(*resource), entry);
12831 : : uint32_t idx = 0;
12832 : :
12833 [ # # ]: 0 : if (ctx_resource->num_of_dest == resource->num_of_dest &&
12834 : 0 : ctx_resource->ft_type == resource->ft_type &&
12835 : 0 : !memcmp((void *)resource->sample_act,
12836 : 0 : (void *)ctx_resource->sample_act,
12837 [ # # ]: 0 : (ctx_resource->num_of_dest *
12838 : : sizeof(struct mlx5_flow_sub_actions_list)))) {
12839 : : /*
12840 : : * Existing sample action should release the prepared
12841 : : * sub-actions reference counter.
12842 : : */
12843 [ # # ]: 0 : for (idx = 0; idx < ctx_resource->num_of_dest; idx++)
12844 : 0 : flow_dv_sample_sub_actions_release(dev,
12845 : : &ctx_resource->sample_idx[idx]);
12846 : : return 0;
12847 : : }
12848 : : return 1;
12849 : : }
12850 : :
12851 : : struct mlx5_list_entry *
12852 : 0 : flow_dv_dest_array_create_cb(void *tool_ctx __rte_unused, void *cb_ctx)
12853 : : {
12854 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12855 : 0 : struct rte_eth_dev *dev = ctx->dev;
12856 : : struct mlx5_flow_dv_dest_array_resource *resource;
12857 : 0 : struct mlx5_flow_dv_dest_array_resource *ctx_resource = ctx->data;
12858 : 0 : struct mlx5dv_dr_action_dest_attr *dest_attr[MLX5_MAX_DEST_NUM] = { 0 };
12859 : : struct mlx5dv_dr_action_dest_reformat dest_reformat[MLX5_MAX_DEST_NUM];
12860 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12861 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
12862 : : struct mlx5_flow_sub_actions_list *sample_act;
12863 : : struct mlx5dv_dr_domain *domain;
12864 : 0 : uint32_t idx = 0, res_idx = 0;
12865 : 0 : struct rte_flow_error *error = ctx->error;
12866 : : uint64_t action_flags;
12867 : : int ret;
12868 : :
12869 : : /* Register new destination array resource. */
12870 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DEST_ARRAY],
12871 : : &res_idx);
12872 [ # # ]: 0 : if (!resource) {
12873 : 0 : rte_flow_error_set(error, ENOMEM,
12874 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12875 : : NULL,
12876 : : "cannot allocate resource memory");
12877 : 0 : return NULL;
12878 : : }
12879 : 0 : *resource = *ctx_resource;
12880 [ # # ]: 0 : if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
12881 : 0 : domain = sh->fdb_domain;
12882 [ # # ]: 0 : else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_RX)
12883 : 0 : domain = sh->rx_domain;
12884 : : else
12885 : 0 : domain = sh->tx_domain;
12886 [ # # ]: 0 : for (idx = 0; idx < ctx_resource->num_of_dest; idx++) {
12887 : 0 : dest_attr[idx] = (struct mlx5dv_dr_action_dest_attr *)
12888 : 0 : mlx5_malloc(MLX5_MEM_ZERO,
12889 : : sizeof(struct mlx5dv_dr_action_dest_attr),
12890 : : 0, SOCKET_ID_ANY);
12891 [ # # ]: 0 : if (!dest_attr[idx]) {
12892 : 0 : rte_flow_error_set(error, ENOMEM,
12893 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12894 : : NULL,
12895 : : "cannot allocate resource memory");
12896 : 0 : goto error;
12897 : : }
12898 : 0 : dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST;
12899 : : sample_act = &ctx_resource->sample_act[idx];
12900 : 0 : action_flags = sample_act->action_flags;
12901 [ # # # # : 0 : switch (action_flags) {
# ]
12902 : 0 : case MLX5_FLOW_ACTION_QUEUE:
12903 : 0 : dest_attr[idx]->dest = sample_act->dr_queue_action;
12904 : 0 : break;
12905 : 0 : case (MLX5_FLOW_ACTION_PORT_ID | MLX5_FLOW_ACTION_ENCAP):
12906 : 0 : dest_attr[idx]->type = MLX5DV_DR_ACTION_DEST_REFORMAT;
12907 : 0 : dest_attr[idx]->dest_reformat = &dest_reformat[idx];
12908 : 0 : dest_attr[idx]->dest_reformat->reformat =
12909 : 0 : sample_act->dr_encap_action;
12910 : 0 : dest_attr[idx]->dest_reformat->dest =
12911 : 0 : sample_act->dr_port_id_action;
12912 : 0 : break;
12913 : 0 : case MLX5_FLOW_ACTION_PORT_ID:
12914 : 0 : dest_attr[idx]->dest = sample_act->dr_port_id_action;
12915 : 0 : break;
12916 : 0 : case MLX5_FLOW_ACTION_JUMP:
12917 : 0 : dest_attr[idx]->dest = sample_act->dr_jump_action;
12918 : 0 : break;
12919 : 0 : default:
12920 : 0 : rte_flow_error_set(error, EINVAL,
12921 : : RTE_FLOW_ERROR_TYPE_ACTION,
12922 : : NULL,
12923 : : "unsupported actions type");
12924 : 0 : goto error;
12925 : : }
12926 : : }
12927 : : /* create a dest array action */
12928 : 0 : ret = mlx5_os_flow_dr_create_flow_action_dest_array
12929 : : (domain,
12930 : 0 : resource->num_of_dest,
12931 : : dest_attr,
12932 : : &resource->action);
12933 : : if (ret) {
12934 : 0 : rte_flow_error_set(error, ENOMEM,
12935 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12936 : : NULL,
12937 : : "cannot create destination array action");
12938 : 0 : goto error;
12939 : : }
12940 : 0 : resource->idx = res_idx;
12941 : 0 : resource->dev = dev;
12942 [ # # ]: 0 : for (idx = 0; idx < ctx_resource->num_of_dest; idx++)
12943 : 0 : mlx5_free(dest_attr[idx]);
12944 : 0 : return &resource->entry;
12945 : : error:
12946 [ # # ]: 0 : for (idx = 0; idx < ctx_resource->num_of_dest; idx++) {
12947 : 0 : flow_dv_sample_sub_actions_release(dev,
12948 : : &resource->sample_idx[idx]);
12949 [ # # ]: 0 : if (dest_attr[idx])
12950 : 0 : mlx5_free(dest_attr[idx]);
12951 : : }
12952 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DEST_ARRAY], res_idx);
12953 : 0 : return NULL;
12954 : : }
12955 : :
12956 : : struct mlx5_list_entry *
12957 : 0 : flow_dv_dest_array_clone_cb(void *tool_ctx __rte_unused,
12958 : : struct mlx5_list_entry *entry __rte_unused,
12959 : : void *cb_ctx)
12960 : : {
12961 : : struct mlx5_flow_cb_ctx *ctx = cb_ctx;
12962 : 0 : struct rte_eth_dev *dev = ctx->dev;
12963 : : struct mlx5_flow_dv_dest_array_resource *resource;
12964 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12965 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
12966 : 0 : uint32_t res_idx = 0;
12967 : 0 : struct rte_flow_error *error = ctx->error;
12968 : :
12969 : 0 : resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DEST_ARRAY],
12970 : : &res_idx);
12971 [ # # ]: 0 : if (!resource) {
12972 : 0 : rte_flow_error_set(error, ENOMEM,
12973 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
12974 : : NULL,
12975 : : "cannot allocate dest-array memory");
12976 : 0 : return NULL;
12977 : : }
12978 : : memcpy(resource, entry, sizeof(*resource));
12979 : 0 : resource->idx = res_idx;
12980 : 0 : resource->dev = dev;
12981 : 0 : return &resource->entry;
12982 : : }
12983 : :
12984 : : void
12985 : 0 : flow_dv_dest_array_clone_free_cb(void *tool_ctx __rte_unused,
12986 : : struct mlx5_list_entry *entry)
12987 : : {
12988 : : struct mlx5_flow_dv_dest_array_resource *resource =
12989 : : container_of(entry, typeof(*resource), entry);
12990 : 0 : struct rte_eth_dev *dev = resource->dev;
12991 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
12992 : :
12993 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY], resource->idx);
12994 : 0 : }
12995 : :
12996 : : /**
12997 : : * Find existing destination array resource or create and register a new one.
12998 : : *
12999 : : * @param[in, out] dev
13000 : : * Pointer to rte_eth_dev structure.
13001 : : * @param[in] ref
13002 : : * Pointer to destination array resource reference.
13003 : : * @parm[in, out] dev_flow
13004 : : * Pointer to the dev_flow.
13005 : : * @param[out] error
13006 : : * pointer to error structure.
13007 : : *
13008 : : * @return
13009 : : * 0 on success otherwise -errno and errno is set.
13010 : : */
13011 : : static int
13012 : 0 : flow_dv_dest_array_resource_register(struct rte_eth_dev *dev,
13013 : : struct mlx5_flow_dv_dest_array_resource *ref,
13014 : : struct mlx5_flow *dev_flow,
13015 : : struct rte_flow_error *error)
13016 : : {
13017 : : struct mlx5_flow_dv_dest_array_resource *resource;
13018 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13019 : : struct mlx5_list_entry *entry;
13020 : 0 : struct mlx5_flow_cb_ctx ctx = {
13021 : : .dev = dev,
13022 : : .error = error,
13023 : : .data = ref,
13024 : : };
13025 : :
13026 : 0 : entry = mlx5_list_register(priv->sh->dest_array_list, &ctx);
13027 [ # # ]: 0 : if (!entry)
13028 : 0 : return -rte_errno;
13029 : : resource = container_of(entry, typeof(*resource), entry);
13030 : 0 : dev_flow->handle->dvh.rix_dest_array = resource->idx;
13031 : 0 : dev_flow->dv.dest_array_res = resource;
13032 : 0 : return 0;
13033 : : }
13034 : :
13035 : : /**
13036 : : * Convert Sample action to DV specification.
13037 : : *
13038 : : * @param[in] dev
13039 : : * Pointer to rte_eth_dev structure.
13040 : : * @param[in] action
13041 : : * Pointer to sample action structure.
13042 : : * @param[in, out] dev_flow
13043 : : * Pointer to the mlx5_flow.
13044 : : * @param[in] attr
13045 : : * Pointer to the flow attributes.
13046 : : * @param[in, out] num_of_dest
13047 : : * Pointer to the num of destination.
13048 : : * @param[in, out] sample_actions
13049 : : * Pointer to sample actions list.
13050 : : * @param[in, out] res
13051 : : * Pointer to sample resource.
13052 : : * @param[out] error
13053 : : * Pointer to the error structure.
13054 : : *
13055 : : * @return
13056 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
13057 : : */
13058 : : static int
13059 : 0 : flow_dv_translate_action_sample(struct rte_eth_dev *dev,
13060 : : const struct rte_flow_action_sample *action,
13061 : : struct mlx5_flow *dev_flow,
13062 : : const struct rte_flow_attr *attr,
13063 : : uint32_t *num_of_dest,
13064 : : void **sample_actions,
13065 : : struct mlx5_flow_dv_sample_resource *res,
13066 : : struct rte_flow_error *error)
13067 : : {
13068 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13069 : : const struct rte_flow_action *sub_actions;
13070 : : struct mlx5_flow_sub_actions_list *sample_act;
13071 : : struct mlx5_flow_sub_actions_idx *sample_idx;
13072 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
13073 : 0 : struct rte_flow *flow = dev_flow->flow;
13074 : : struct mlx5_flow_rss_desc *rss_desc;
13075 : : uint64_t action_flags = 0;
13076 : :
13077 : : MLX5_ASSERT(wks);
13078 : 0 : rss_desc = &wks->rss_desc;
13079 : : sample_act = &res->sample_act;
13080 : : sample_idx = &res->sample_idx;
13081 : 0 : res->ratio = action->ratio;
13082 : 0 : sub_actions = action->actions;
13083 [ # # ]: 0 : for (; sub_actions->type != RTE_FLOW_ACTION_TYPE_END; sub_actions++) {
13084 : : int type = sub_actions->type;
13085 : : uint32_t pre_rix = 0;
13086 : : void *pre_r;
13087 [ # # # # : 0 : switch (type) {
# # # ]
13088 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
13089 : : {
13090 : : const struct rte_flow_action_queue *queue;
13091 : : struct mlx5_hrxq *hrxq;
13092 : : uint32_t hrxq_idx;
13093 : :
13094 : 0 : queue = sub_actions->conf;
13095 : 0 : rss_desc->queue_num = 1;
13096 : 0 : rss_desc->queue[0] = queue->index;
13097 : 0 : hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
13098 : : rss_desc, &hrxq_idx);
13099 [ # # ]: 0 : if (!hrxq)
13100 : 0 : return rte_flow_error_set
13101 : : (error, rte_errno,
13102 : : RTE_FLOW_ERROR_TYPE_ACTION,
13103 : : NULL,
13104 : : "cannot create fate queue");
13105 : 0 : sample_act->dr_queue_action = hrxq->action;
13106 : 0 : sample_idx->rix_hrxq = hrxq_idx;
13107 : 0 : sample_actions[sample_act->actions_num++] =
13108 : : hrxq->action;
13109 : 0 : (*num_of_dest)++;
13110 : 0 : action_flags |= MLX5_FLOW_ACTION_QUEUE;
13111 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
13112 : 0 : dev_flow->handle->rix_hrxq = hrxq_idx;
13113 : 0 : dev_flow->handle->fate_action =
13114 : : MLX5_FLOW_FATE_QUEUE;
13115 : 0 : break;
13116 : : }
13117 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
13118 : : {
13119 : : struct mlx5_hrxq *hrxq;
13120 : : uint32_t hrxq_idx;
13121 : : const struct rte_flow_action_rss *rss;
13122 : : const uint8_t *rss_key;
13123 : :
13124 : 0 : rss = sub_actions->conf;
13125 : 0 : rss_desc->symmetric_hash_function =
13126 : 0 : MLX5_RSS_IS_SYMM(rss->func);
13127 : 0 : memcpy(rss_desc->queue, rss->queue,
13128 [ # # ]: 0 : rss->queue_num * sizeof(uint16_t));
13129 : 0 : rss_desc->queue_num = rss->queue_num;
13130 : : /* NULL RSS key indicates default RSS key. */
13131 [ # # ]: 0 : rss_key = !rss->key ? rss_hash_default_key : rss->key;
13132 : 0 : memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
13133 : : /*
13134 : : * rss->level and rss.types should be set in advance
13135 : : * when expanding items for RSS.
13136 : : */
13137 : 0 : flow_dv_hashfields_set(dev_flow->handle->layers,
13138 : : rss_desc,
13139 : : &dev_flow->hash_fields);
13140 : 0 : hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
13141 : : rss_desc, &hrxq_idx);
13142 [ # # ]: 0 : if (!hrxq)
13143 : 0 : return rte_flow_error_set
13144 : : (error, rte_errno,
13145 : : RTE_FLOW_ERROR_TYPE_ACTION,
13146 : : NULL,
13147 : : "cannot create fate queue");
13148 : 0 : sample_act->dr_queue_action = hrxq->action;
13149 : 0 : sample_idx->rix_hrxq = hrxq_idx;
13150 : 0 : sample_actions[sample_act->actions_num++] =
13151 : : hrxq->action;
13152 : 0 : (*num_of_dest)++;
13153 : 0 : action_flags |= MLX5_FLOW_ACTION_RSS;
13154 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
13155 : 0 : dev_flow->handle->rix_hrxq = hrxq_idx;
13156 : 0 : dev_flow->handle->fate_action =
13157 : : MLX5_FLOW_FATE_QUEUE;
13158 : 0 : break;
13159 : : }
13160 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
13161 : : {
13162 : : uint32_t tag_be = mlx5_flow_mark_set
13163 : : (((const struct rte_flow_action_mark *)
13164 [ # # ]: 0 : (sub_actions->conf))->id);
13165 : :
13166 : 0 : wks->mark = 1;
13167 : 0 : pre_rix = dev_flow->handle->dvh.rix_tag;
13168 : : /* Save the mark resource before sample */
13169 : 0 : pre_r = dev_flow->dv.tag_resource;
13170 [ # # ]: 0 : if (flow_dv_tag_resource_register(dev, tag_be,
13171 : : dev_flow, error))
13172 : 0 : return -rte_errno;
13173 : : MLX5_ASSERT(dev_flow->dv.tag_resource);
13174 : 0 : sample_act->dr_tag_action =
13175 : 0 : dev_flow->dv.tag_resource->action;
13176 : 0 : sample_idx->rix_tag =
13177 : 0 : dev_flow->handle->dvh.rix_tag;
13178 : 0 : sample_actions[sample_act->actions_num++] =
13179 : : sample_act->dr_tag_action;
13180 : : /* Recover the mark resource after sample */
13181 : 0 : dev_flow->dv.tag_resource = pre_r;
13182 : 0 : dev_flow->handle->dvh.rix_tag = pre_rix;
13183 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK;
13184 : 0 : break;
13185 : : }
13186 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
13187 : : {
13188 [ # # ]: 0 : if (!flow->counter) {
13189 : 0 : flow->counter =
13190 : 0 : flow_dv_translate_create_counter(dev,
13191 : 0 : dev_flow, sub_actions->conf,
13192 : : 0);
13193 [ # # ]: 0 : if (!flow->counter)
13194 : 0 : return rte_flow_error_set
13195 : : (error, rte_errno,
13196 : : RTE_FLOW_ERROR_TYPE_ACTION,
13197 : : NULL,
13198 : : "cannot create counter"
13199 : : " object.");
13200 : : }
13201 : 0 : sample_act->dr_cnt_action =
13202 [ # # ]: 0 : (flow_dv_counter_get_by_idx(dev,
13203 : 0 : flow->counter, NULL))->action;
13204 : 0 : sample_actions[sample_act->actions_num++] =
13205 : : sample_act->dr_cnt_action;
13206 : 0 : action_flags |= MLX5_FLOW_ACTION_COUNT;
13207 : 0 : break;
13208 : : }
13209 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
13210 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
13211 : : {
13212 : : struct mlx5_flow_dv_port_id_action_resource
13213 : : port_id_resource;
13214 : 0 : uint32_t port_id = 0;
13215 : :
13216 : : memset(&port_id_resource, 0, sizeof(port_id_resource));
13217 : : /* Save the port id resource before sample */
13218 : 0 : pre_rix = dev_flow->handle->rix_port_id_action;
13219 : 0 : pre_r = dev_flow->dv.port_id_action;
13220 [ # # ]: 0 : if (flow_dv_translate_action_port_id(dev, sub_actions,
13221 : : &port_id, error))
13222 : 0 : return -rte_errno;
13223 : 0 : port_id_resource.port_id = port_id;
13224 [ # # ]: 0 : if (flow_dv_port_id_action_resource_register
13225 : : (dev, &port_id_resource, dev_flow, error))
13226 : 0 : return -rte_errno;
13227 : 0 : sample_act->dr_port_id_action =
13228 : 0 : dev_flow->dv.port_id_action->action;
13229 : 0 : sample_idx->rix_port_id_action =
13230 : 0 : dev_flow->handle->rix_port_id_action;
13231 : 0 : sample_actions[sample_act->actions_num++] =
13232 : : sample_act->dr_port_id_action;
13233 : : /* Recover the port id resource after sample */
13234 : 0 : dev_flow->dv.port_id_action = pre_r;
13235 : 0 : dev_flow->handle->rix_port_id_action = pre_rix;
13236 : 0 : (*num_of_dest)++;
13237 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_ID;
13238 : 0 : break;
13239 : : }
13240 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
13241 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
13242 : : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
13243 : : /* Save the encap resource before sample */
13244 : 0 : pre_rix = dev_flow->handle->dvh.rix_encap_decap;
13245 : 0 : pre_r = dev_flow->dv.encap_decap;
13246 [ # # ]: 0 : if (flow_dv_create_action_l2_encap(dev, sub_actions,
13247 : : dev_flow,
13248 : 0 : attr->transfer,
13249 : : error))
13250 : 0 : return -rte_errno;
13251 : 0 : sample_act->dr_encap_action =
13252 : 0 : dev_flow->dv.encap_decap->action;
13253 : 0 : sample_idx->rix_encap_decap =
13254 : 0 : dev_flow->handle->dvh.rix_encap_decap;
13255 : 0 : sample_actions[sample_act->actions_num++] =
13256 : : sample_act->dr_encap_action;
13257 : : /* Recover the encap resource after sample */
13258 : 0 : dev_flow->dv.encap_decap = pre_r;
13259 : 0 : dev_flow->handle->dvh.rix_encap_decap = pre_rix;
13260 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
13261 : 0 : break;
13262 : 0 : default:
13263 : 0 : return rte_flow_error_set(error, EINVAL,
13264 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
13265 : : NULL,
13266 : : "Not support for sampler action");
13267 : : }
13268 : : }
13269 : 0 : sample_act->action_flags = action_flags;
13270 : 0 : res->ft_id = dev_flow->dv.group;
13271 [ # # ]: 0 : if (attr->transfer) {
13272 : : union {
13273 : : uint32_t action_in[MLX5_ST_SZ_DW(set_action_in)];
13274 : : uint64_t set_action;
13275 : : } action_ctx = { .set_action = 0 };
13276 : 0 : uint32_t vport_meta_tag = wks->vport_meta_tag ?
13277 [ # # ]: 0 : wks->vport_meta_tag :
13278 : : priv->vport_meta_tag;
13279 : :
13280 : 0 : res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
13281 : : MLX5_SET(set_action_in, action_ctx.action_in, action_type,
13282 : : MLX5_MODIFICATION_TYPE_SET);
13283 [ # # ]: 0 : MLX5_SET(set_action_in, action_ctx.action_in, field,
13284 : : MLX5_MODI_META_REG_C_0);
13285 : 0 : MLX5_SET(set_action_in, action_ctx.action_in, data,
13286 : : vport_meta_tag);
13287 : 0 : res->set_action = action_ctx.set_action;
13288 [ # # ]: 0 : } else if (attr->ingress) {
13289 : 0 : res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
13290 : : } else {
13291 : 0 : res->ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_TX;
13292 : : }
13293 : : return 0;
13294 : : }
13295 : :
13296 : : static void *
13297 : 0 : flow_dv_translate_action_send_to_kernel(struct rte_eth_dev *dev,
13298 : : const struct rte_flow_attr *attr,
13299 : : struct rte_flow_error *error)
13300 : : {
13301 : : struct mlx5_flow_tbl_resource *tbl;
13302 : : struct mlx5_dev_ctx_shared *sh;
13303 : : uint32_t priority;
13304 : : void *action;
13305 : : int ft_type;
13306 : : int ret;
13307 : :
13308 : 0 : sh = MLX5_SH(dev);
13309 [ # # ]: 0 : ft_type = (attr->ingress) ? MLX5DR_TABLE_TYPE_NIC_RX :
13310 [ # # ]: 0 : ((attr->transfer) ? MLX5DR_TABLE_TYPE_FDB :
13311 : : MLX5DR_TABLE_TYPE_NIC_TX);
13312 [ # # ]: 0 : if (sh->send_to_kernel_action[ft_type].action)
13313 : : return sh->send_to_kernel_action[ft_type].action;
13314 : 0 : priority = mlx5_get_send_to_kernel_priority(dev);
13315 [ # # ]: 0 : if (priority == (uint32_t)-1) {
13316 : 0 : rte_flow_error_set(error, ENOTSUP,
13317 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13318 : : "required priority is not available");
13319 : 0 : return NULL;
13320 : : }
13321 : 0 : tbl = flow_dv_tbl_resource_get(dev, 0, attr->egress, attr->transfer, false, NULL, 0, 0, 0,
13322 : : error);
13323 [ # # ]: 0 : if (!tbl) {
13324 : 0 : rte_flow_error_set(error, ENODATA,
13325 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13326 : : "cannot find destination root table");
13327 : 0 : return NULL;
13328 : : }
13329 : 0 : ret = mlx5_flow_os_create_flow_action_send_to_kernel(tbl->obj,
13330 : : priority, &action);
13331 : : if (ret) {
13332 : 0 : rte_flow_error_set(error, ENOMEM,
13333 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
13334 : : "cannot create action");
13335 : 0 : goto err;
13336 : : }
13337 : : MLX5_ASSERT(action);
13338 : 0 : sh->send_to_kernel_action[ft_type].action = action;
13339 : 0 : sh->send_to_kernel_action[ft_type].tbl = tbl;
13340 : 0 : return action;
13341 : : err:
13342 : 0 : flow_dv_tbl_resource_release(sh, tbl);
13343 : 0 : return NULL;
13344 : : }
13345 : :
13346 : : /**
13347 : : * Convert Sample action to DV specification.
13348 : : *
13349 : : * @param[in] dev
13350 : : * Pointer to rte_eth_dev structure.
13351 : : * @param[in, out] dev_flow
13352 : : * Pointer to the mlx5_flow.
13353 : : * @param[in] num_of_dest
13354 : : * The num of destination.
13355 : : * @param[in, out] res
13356 : : * Pointer to sample resource.
13357 : : * @param[in, out] mdest_res
13358 : : * Pointer to destination array resource.
13359 : : * @param[in] sample_actions
13360 : : * Pointer to sample path actions list.
13361 : : * @param[in] action_flags
13362 : : * Holds the actions detected until now.
13363 : : * @param[out] error
13364 : : * Pointer to the error structure.
13365 : : *
13366 : : * @return
13367 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
13368 : : */
13369 : : static int
13370 : 0 : flow_dv_create_action_sample(struct rte_eth_dev *dev,
13371 : : struct mlx5_flow *dev_flow,
13372 : : uint32_t num_of_dest,
13373 : : struct mlx5_flow_dv_sample_resource *res,
13374 : : struct mlx5_flow_dv_dest_array_resource *mdest_res,
13375 : : void **sample_actions,
13376 : : uint64_t action_flags,
13377 : : struct rte_flow_error *error)
13378 : : {
13379 : : /* update normal path action resource into last index of array */
13380 : : uint32_t dest_index = MLX5_MAX_DEST_NUM - 1;
13381 : : struct mlx5_flow_sub_actions_list *sample_act =
13382 : : &mdest_res->sample_act[dest_index];
13383 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
13384 : : struct mlx5_flow_rss_desc *rss_desc;
13385 : : uint32_t normal_idx = 0;
13386 : : struct mlx5_hrxq *hrxq;
13387 : : uint32_t hrxq_idx;
13388 : :
13389 : : MLX5_ASSERT(wks);
13390 : 0 : rss_desc = &wks->rss_desc;
13391 [ # # ]: 0 : if (num_of_dest > 1) {
13392 [ # # ]: 0 : if (sample_act->action_flags & MLX5_FLOW_ACTION_QUEUE) {
13393 : : /* Handle QP action for mirroring */
13394 : 0 : hrxq = flow_dv_hrxq_prepare(dev, dev_flow,
13395 : : rss_desc, &hrxq_idx);
13396 [ # # ]: 0 : if (!hrxq)
13397 : 0 : return rte_flow_error_set
13398 : : (error, rte_errno,
13399 : : RTE_FLOW_ERROR_TYPE_ACTION,
13400 : : NULL,
13401 : : "cannot create rx queue");
13402 : : normal_idx++;
13403 : 0 : mdest_res->sample_idx[dest_index].rix_hrxq = hrxq_idx;
13404 : 0 : sample_act->dr_queue_action = hrxq->action;
13405 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_MARK)
13406 : 0 : dev_flow->handle->rix_hrxq = hrxq_idx;
13407 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
13408 : : }
13409 [ # # ]: 0 : if (sample_act->action_flags & MLX5_FLOW_ACTION_ENCAP) {
13410 : 0 : normal_idx++;
13411 : 0 : mdest_res->sample_idx[dest_index].rix_encap_decap =
13412 : 0 : dev_flow->handle->dvh.rix_encap_decap;
13413 : 0 : sample_act->dr_encap_action =
13414 : 0 : dev_flow->dv.encap_decap->action;
13415 : 0 : dev_flow->handle->dvh.rix_encap_decap = 0;
13416 : : }
13417 [ # # ]: 0 : if (sample_act->action_flags & MLX5_FLOW_ACTION_PORT_ID) {
13418 : 0 : normal_idx++;
13419 : 0 : mdest_res->sample_idx[dest_index].rix_port_id_action =
13420 : 0 : dev_flow->handle->rix_port_id_action;
13421 : 0 : sample_act->dr_port_id_action =
13422 : 0 : dev_flow->dv.port_id_action->action;
13423 : 0 : dev_flow->handle->rix_port_id_action = 0;
13424 : : }
13425 [ # # ]: 0 : if (sample_act->action_flags & MLX5_FLOW_ACTION_JUMP) {
13426 : 0 : normal_idx++;
13427 : 0 : mdest_res->sample_idx[dest_index].rix_jump =
13428 : 0 : dev_flow->handle->rix_jump;
13429 : 0 : sample_act->dr_jump_action =
13430 : 0 : dev_flow->dv.jump->action;
13431 : 0 : dev_flow->handle->rix_jump = 0;
13432 : : }
13433 : 0 : sample_act->actions_num = normal_idx;
13434 : : /* update sample action resource into first index of array */
13435 : 0 : mdest_res->ft_type = res->ft_type;
13436 : 0 : memcpy(&mdest_res->sample_idx[0], &res->sample_idx,
13437 : : sizeof(struct mlx5_flow_sub_actions_idx));
13438 : 0 : memcpy(&mdest_res->sample_act[0], &res->sample_act,
13439 : : sizeof(struct mlx5_flow_sub_actions_list));
13440 : 0 : mdest_res->num_of_dest = num_of_dest;
13441 [ # # ]: 0 : if (flow_dv_dest_array_resource_register(dev, mdest_res,
13442 : : dev_flow, error))
13443 : 0 : return rte_flow_error_set(error, EINVAL,
13444 : : RTE_FLOW_ERROR_TYPE_ACTION,
13445 : : NULL, "can't create sample "
13446 : : "action");
13447 : : } else {
13448 : 0 : res->sub_actions = sample_actions;
13449 [ # # ]: 0 : if (flow_dv_sample_resource_register(dev, res, dev_flow, error))
13450 : 0 : return rte_flow_error_set(error, EINVAL,
13451 : : RTE_FLOW_ERROR_TYPE_ACTION,
13452 : : NULL,
13453 : : "can't create sample action");
13454 : : }
13455 : : return 0;
13456 : : }
13457 : :
13458 : : /**
13459 : : * Remove an ASO age action from age actions list.
13460 : : *
13461 : : * @param[in] dev
13462 : : * Pointer to the Ethernet device structure.
13463 : : * @param[in] age
13464 : : * Pointer to the aso age action handler.
13465 : : */
13466 : : static void
13467 : 0 : flow_dv_aso_age_remove_from_age(struct rte_eth_dev *dev,
13468 : : struct mlx5_aso_age_action *age)
13469 : : {
13470 : : struct mlx5_age_info *age_info;
13471 : : struct mlx5_age_param *age_param = &age->age_params;
13472 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13473 : : uint16_t expected = AGE_CANDIDATE;
13474 : :
13475 : 0 : age_info = GET_PORT_AGE_INFO(priv);
13476 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(&age_param->state, &expected,
13477 : : AGE_FREE, rte_memory_order_relaxed,
13478 : : rte_memory_order_relaxed)) {
13479 : : /**
13480 : : * We need the lock even it is age timeout,
13481 : : * since age action may still in process.
13482 : : */
13483 : 0 : rte_spinlock_lock(&age_info->aged_sl);
13484 [ # # ]: 0 : LIST_REMOVE(age, next);
13485 : : rte_spinlock_unlock(&age_info->aged_sl);
13486 : 0 : rte_atomic_store_explicit(&age_param->state, AGE_FREE, rte_memory_order_relaxed);
13487 : : }
13488 : 0 : }
13489 : :
13490 : : /**
13491 : : * Release an ASO age action.
13492 : : *
13493 : : * @param[in] dev
13494 : : * Pointer to the Ethernet device structure.
13495 : : * @param[in] age_idx
13496 : : * Index of ASO age action to release.
13497 : : * @param[in] flow
13498 : : * True if the release operation is during flow destroy operation.
13499 : : * False if the release operation is during action destroy operation.
13500 : : *
13501 : : * @return
13502 : : * 0 when age action was removed, otherwise the number of references.
13503 : : */
13504 : : static int
13505 : 0 : flow_dv_aso_age_release(struct rte_eth_dev *dev, uint32_t age_idx)
13506 : : {
13507 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13508 : 0 : struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
13509 : 0 : struct mlx5_aso_age_action *age = flow_aso_age_get_by_idx(dev, age_idx);
13510 : 0 : uint32_t ret = rte_atomic_fetch_sub_explicit(&age->refcnt, 1, rte_memory_order_relaxed) - 1;
13511 : :
13512 [ # # ]: 0 : if (!ret) {
13513 : 0 : flow_dv_aso_age_remove_from_age(dev, age);
13514 : 0 : rte_spinlock_lock(&mng->free_sl);
13515 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free, age, next);
13516 : : rte_spinlock_unlock(&mng->free_sl);
13517 : : }
13518 : 0 : return ret;
13519 : : }
13520 : :
13521 : : /**
13522 : : * Resize the ASO age pools array by MLX5_ASO_AGE_CONTAINER_RESIZE pools.
13523 : : *
13524 : : * @param[in] dev
13525 : : * Pointer to the Ethernet device structure.
13526 : : *
13527 : : * @return
13528 : : * 0 on success, otherwise negative errno value and rte_errno is set.
13529 : : */
13530 : : static int
13531 : 0 : flow_dv_aso_age_pools_resize(struct rte_eth_dev *dev)
13532 : : {
13533 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13534 : 0 : struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
13535 : 0 : void *old_pools = mng->pools;
13536 : 0 : uint32_t resize = mng->n + MLX5_ASO_AGE_CONTAINER_RESIZE;
13537 : 0 : uint32_t mem_size = sizeof(struct mlx5_aso_age_pool *) * resize;
13538 : 0 : void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
13539 : :
13540 [ # # ]: 0 : if (!pools) {
13541 : 0 : rte_errno = ENOMEM;
13542 : 0 : return -ENOMEM;
13543 : : }
13544 [ # # ]: 0 : if (old_pools) {
13545 : 0 : memcpy(pools, old_pools,
13546 : 0 : mng->n * sizeof(struct mlx5_flow_counter_pool *));
13547 : 0 : mlx5_free(old_pools);
13548 : : } else {
13549 : : /* First ASO flow hit allocation - starting ASO data-path. */
13550 : 0 : int ret = mlx5_aso_flow_hit_queue_poll_start(priv->sh);
13551 : :
13552 [ # # ]: 0 : if (ret) {
13553 : 0 : mlx5_free(pools);
13554 : 0 : return ret;
13555 : : }
13556 : : }
13557 : 0 : mng->n = resize;
13558 : 0 : mng->pools = pools;
13559 : 0 : return 0;
13560 : : }
13561 : :
13562 : : /**
13563 : : * Create and initialize a new ASO aging pool.
13564 : : *
13565 : : * @param[in] dev
13566 : : * Pointer to the Ethernet device structure.
13567 : : * @param[out] age_free
13568 : : * Where to put the pointer of a new age action.
13569 : : *
13570 : : * @return
13571 : : * The age actions pool pointer and @p age_free is set on success,
13572 : : * NULL otherwise and rte_errno is set.
13573 : : */
13574 : : static struct mlx5_aso_age_pool *
13575 : 0 : flow_dv_age_pool_create(struct rte_eth_dev *dev,
13576 : : struct mlx5_aso_age_action **age_free)
13577 : : {
13578 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13579 : 0 : struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
13580 : : struct mlx5_aso_age_pool *pool = NULL;
13581 : : struct mlx5_devx_obj *obj = NULL;
13582 : : uint32_t i;
13583 : :
13584 : 0 : obj = mlx5_devx_cmd_create_flow_hit_aso_obj(priv->sh->cdev->ctx,
13585 : 0 : priv->sh->cdev->pdn);
13586 [ # # ]: 0 : if (!obj) {
13587 : 0 : rte_errno = ENODATA;
13588 : 0 : DRV_LOG(ERR, "Failed to create flow_hit_aso_obj using DevX.");
13589 : 0 : return NULL;
13590 : : }
13591 : 0 : pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool), 0, SOCKET_ID_ANY);
13592 [ # # ]: 0 : if (!pool) {
13593 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
13594 : 0 : rte_errno = ENOMEM;
13595 : 0 : return NULL;
13596 : : }
13597 : 0 : pool->flow_hit_aso_obj = obj;
13598 : 0 : pool->time_of_last_age_check = MLX5_CURR_TIME_SEC;
13599 : 0 : rte_rwlock_write_lock(&mng->resize_rwl);
13600 : 0 : pool->index = mng->next;
13601 : : /* Resize pools array if there is no room for the new pool in it. */
13602 [ # # # # ]: 0 : if (pool->index == mng->n && flow_dv_aso_age_pools_resize(dev)) {
13603 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
13604 : 0 : mlx5_free(pool);
13605 : : rte_rwlock_write_unlock(&mng->resize_rwl);
13606 : 0 : return NULL;
13607 : : }
13608 : 0 : mng->pools[pool->index] = pool;
13609 : 0 : mng->next++;
13610 : : rte_rwlock_write_unlock(&mng->resize_rwl);
13611 : : /* Assign the first action in the new pool, the rest go to free list. */
13612 : 0 : *age_free = &pool->actions[0];
13613 [ # # ]: 0 : for (i = 1; i < MLX5_ASO_AGE_ACTIONS_PER_POOL; i++) {
13614 : 0 : pool->actions[i].offset = i;
13615 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free, &pool->actions[i], next);
13616 : : }
13617 : : return pool;
13618 : : }
13619 : :
13620 : : /**
13621 : : * Allocate a ASO aging bit.
13622 : : *
13623 : : * @param[in] dev
13624 : : * Pointer to the Ethernet device structure.
13625 : : * @param[out] error
13626 : : * Pointer to the error structure.
13627 : : *
13628 : : * @return
13629 : : * Index to ASO age action on success, 0 otherwise and rte_errno is set.
13630 : : */
13631 : : static uint32_t
13632 : 0 : flow_dv_aso_age_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
13633 : : {
13634 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13635 : : const struct mlx5_aso_age_pool *pool;
13636 : 0 : struct mlx5_aso_age_action *age_free = NULL;
13637 : 0 : struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
13638 : :
13639 : : MLX5_ASSERT(mng);
13640 : : /* Try to get the next free age action bit. */
13641 : 0 : rte_spinlock_lock(&mng->free_sl);
13642 : 0 : age_free = LIST_FIRST(&mng->free);
13643 [ # # ]: 0 : if (age_free) {
13644 [ # # ]: 0 : LIST_REMOVE(age_free, next);
13645 [ # # ]: 0 : } else if (!flow_dv_age_pool_create(dev, &age_free)) {
13646 : : rte_spinlock_unlock(&mng->free_sl);
13647 : 0 : rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
13648 : : NULL, "failed to create ASO age pool");
13649 : 0 : return 0; /* 0 is an error. */
13650 : : }
13651 : : rte_spinlock_unlock(&mng->free_sl);
13652 : 0 : pool = container_of
13653 : : ((const struct mlx5_aso_age_action (*)[MLX5_ASO_AGE_ACTIONS_PER_POOL])
13654 : : (age_free - age_free->offset), const struct mlx5_aso_age_pool,
13655 : : actions);
13656 [ # # ]: 0 : if (!age_free->dr_action) {
13657 : 0 : int reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_FLOW_HIT, 0,
13658 : : error);
13659 : :
13660 [ # # ]: 0 : if (reg_c < 0) {
13661 : 0 : rte_flow_error_set(error, rte_errno,
13662 : : RTE_FLOW_ERROR_TYPE_ACTION,
13663 : : NULL, "failed to get reg_c "
13664 : : "for ASO flow hit");
13665 : 0 : return 0; /* 0 is an error. */
13666 : : }
13667 : : #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
13668 : 0 : age_free->dr_action = mlx5_glue->dv_create_flow_action_aso
13669 : 0 : (priv->sh->rx_domain,
13670 : 0 : pool->flow_hit_aso_obj->obj, age_free->offset,
13671 : : MLX5DV_DR_ACTION_FLAGS_ASO_FIRST_HIT_SET,
13672 : 0 : (reg_c - REG_C_0));
13673 : : #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
13674 [ # # ]: 0 : if (!age_free->dr_action) {
13675 : 0 : rte_errno = errno;
13676 : : rte_spinlock_lock(&mng->free_sl);
13677 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free, age_free, next);
13678 : : rte_spinlock_unlock(&mng->free_sl);
13679 : 0 : rte_flow_error_set(error, rte_errno,
13680 : : RTE_FLOW_ERROR_TYPE_ACTION,
13681 : : NULL, "failed to create ASO "
13682 : : "flow hit action");
13683 : 0 : return 0; /* 0 is an error. */
13684 : : }
13685 : : }
13686 : 0 : rte_atomic_store_explicit(&age_free->refcnt, 1, rte_memory_order_relaxed);
13687 : 0 : return pool->index | ((age_free->offset + 1) << 16);
13688 : : }
13689 : :
13690 : : /**
13691 : : * Initialize flow ASO age parameters.
13692 : : *
13693 : : * @param[in] dev
13694 : : * Pointer to rte_eth_dev structure.
13695 : : * @param[in] age_idx
13696 : : * Index of ASO age action.
13697 : : * @param[in] context
13698 : : * Pointer to flow counter age context.
13699 : : * @param[in] timeout
13700 : : * Aging timeout in seconds.
13701 : : *
13702 : : */
13703 : : static void
13704 : 0 : flow_dv_aso_age_params_init(struct rte_eth_dev *dev,
13705 : : uint32_t age_idx,
13706 : : void *context,
13707 : : uint32_t timeout)
13708 : : {
13709 : : struct mlx5_aso_age_action *aso_age;
13710 : :
13711 : 0 : aso_age = flow_aso_age_get_by_idx(dev, age_idx);
13712 : : MLX5_ASSERT(aso_age);
13713 : 0 : aso_age->age_params.context = context;
13714 : 0 : aso_age->age_params.timeout = timeout;
13715 : 0 : aso_age->age_params.port_id = dev->data->port_id;
13716 : 0 : rte_atomic_store_explicit(&aso_age->age_params.sec_since_last_hit, 0,
13717 : : rte_memory_order_relaxed);
13718 : 0 : rte_atomic_store_explicit(&aso_age->age_params.state, AGE_CANDIDATE,
13719 : : rte_memory_order_relaxed);
13720 : 0 : }
13721 : :
13722 : : static void
13723 : 0 : flow_dv_translate_integrity_l4(const struct rte_flow_item_integrity *mask,
13724 : : void *headers)
13725 : : {
13726 : : /*
13727 : : * In HWS mode MLX5_ITEM_UPDATE() macro assigns the same pointer to
13728 : : * both mask and value, therefore ether can be used.
13729 : : * In SWS SW_V mode mask points to item mask and value points to item
13730 : : * spec. Integrity item value is used only if matching mask is set.
13731 : : * Use mask reference here to keep SWS functionality.
13732 : : */
13733 [ # # ]: 0 : if (mask->l4_ok) {
13734 : : /* RTE l4_ok filter aggregates hardware l4_ok and
13735 : : * l4_checksum_ok filters.
13736 : : * Positive RTE l4_ok match requires hardware match on both L4
13737 : : * hardware integrity bits.
13738 : : * PMD supports positive integrity item semantics only.
13739 : : */
13740 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, l4_ok, 1);
13741 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, l4_checksum_ok, 1);
13742 [ # # ]: 0 : } else if (mask->l4_csum_ok) {
13743 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, l4_checksum_ok, 1);
13744 : : }
13745 : 0 : }
13746 : :
13747 : : static void
13748 : 0 : flow_dv_translate_integrity_l3(const struct rte_flow_item_integrity *mask,
13749 : : void *headers, bool is_ipv4)
13750 : : {
13751 : : /*
13752 : : * In HWS mode MLX5_ITEM_UPDATE() macro assigns the same pointer to
13753 : : * both mask and value, therefore ether can be used.
13754 : : * In SWS SW_V mode mask points to item mask and value points to item
13755 : : * spec. Integrity item value used only if matching mask is set.
13756 : : * Use mask reference here to keep SWS functionality.
13757 : : */
13758 [ # # ]: 0 : if (mask->l3_ok) {
13759 : : /* RTE l3_ok filter aggregates for IPv4 hardware l3_ok and
13760 : : * ipv4_csum_ok filters.
13761 : : * Positive RTE l3_ok match requires hardware match on both L3
13762 : : * hardware integrity bits.
13763 : : * PMD supports positive integrity item semantics only.
13764 : : */
13765 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, l3_ok, 1);
13766 [ # # ]: 0 : if (is_ipv4) {
13767 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers,
13768 : : ipv4_checksum_ok, 1);
13769 : : }
13770 [ # # # # ]: 0 : } else if (is_ipv4 && mask->ipv4_csum_ok) {
13771 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers, ipv4_checksum_ok, 1);
13772 : : }
13773 : 0 : }
13774 : :
13775 : : static void
13776 : 0 : set_integrity_bits(void *headers, const struct rte_flow_item *integrity_item,
13777 : : bool is_l3_ip4, uint32_t key_type)
13778 : : {
13779 : : const struct rte_flow_item_integrity *spec;
13780 : : const struct rte_flow_item_integrity *mask;
13781 : :
13782 : : /* Integrity bits validation cleared spec pointer */
13783 [ # # # # : 0 : if (MLX5_ITEM_VALID(integrity_item, key_type))
# # # # #
# ]
13784 : : return;
13785 [ # # # # : 0 : MLX5_ITEM_UPDATE(integrity_item, key_type, spec, mask,
# # # # ]
13786 : : &rte_flow_item_integrity_mask);
13787 : 0 : flow_dv_translate_integrity_l3(mask, headers, is_l3_ip4);
13788 : 0 : flow_dv_translate_integrity_l4(mask, headers);
13789 : : }
13790 : :
13791 : : static void
13792 : 0 : flow_dv_translate_item_integrity_post(void *key,
13793 : : const
13794 : : struct rte_flow_item *integrity_items[2],
13795 : : uint64_t pattern_flags, uint32_t key_type)
13796 : : {
13797 : : void *headers;
13798 : : bool is_l3_ip4;
13799 : :
13800 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_INNER_INTEGRITY) {
13801 : 0 : headers = MLX5_ADDR_OF(fte_match_param, key, inner_headers);
13802 : 0 : is_l3_ip4 = (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV4) !=
13803 : : 0;
13804 : 0 : set_integrity_bits(headers, integrity_items[1], is_l3_ip4,
13805 : : key_type);
13806 : : }
13807 [ # # ]: 0 : if (pattern_flags & MLX5_FLOW_ITEM_OUTER_INTEGRITY) {
13808 : : headers = MLX5_ADDR_OF(fte_match_param, key, outer_headers);
13809 : 0 : is_l3_ip4 = (pattern_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV4) !=
13810 : : 0;
13811 : 0 : set_integrity_bits(headers, integrity_items[0], is_l3_ip4,
13812 : : key_type);
13813 : : }
13814 : 0 : }
13815 : :
13816 : : static uint64_t
13817 : : flow_dv_translate_item_integrity(const struct rte_flow_item *item,
13818 : : struct mlx5_dv_matcher_workspace *wks,
13819 : : uint64_t key_type)
13820 : : {
13821 : 0 : if ((key_type & MLX5_SET_MATCHER_SW) != 0) {
13822 : : const struct rte_flow_item_integrity
13823 : 0 : *spec = (typeof(spec))item->spec;
13824 : :
13825 : : /* SWS integrity bits validation cleared spec pointer */
13826 [ # # ]: 0 : if (spec->level > 1) {
13827 : 0 : wks->integrity_items[1] = item;
13828 : 0 : wks->last_item |= MLX5_FLOW_ITEM_INNER_INTEGRITY;
13829 : : } else {
13830 : 0 : wks->integrity_items[0] = item;
13831 : 0 : wks->last_item |= MLX5_FLOW_ITEM_OUTER_INTEGRITY;
13832 : : }
13833 : : } else {
13834 : : /* HWS supports outer integrity only */
13835 : 0 : wks->integrity_items[0] = item;
13836 : 0 : wks->last_item |= MLX5_FLOW_ITEM_OUTER_INTEGRITY;
13837 : : }
13838 : 0 : return wks->last_item;
13839 : : }
13840 : :
13841 : : /**
13842 : : * Prepares DV flow counter with aging configuration.
13843 : : * Gets it by index when exists, creates a new one when doesn't.
13844 : : *
13845 : : * @param[in] dev
13846 : : * Pointer to rte_eth_dev structure.
13847 : : * @param[in] dev_flow
13848 : : * Pointer to the mlx5_flow.
13849 : : * @param[in, out] flow
13850 : : * Pointer to the sub flow.
13851 : : * @param[in] count
13852 : : * Pointer to the counter action configuration.
13853 : : * @param[in] age
13854 : : * Pointer to the aging action configuration.
13855 : : * @param[out] error
13856 : : * Pointer to the error structure.
13857 : : *
13858 : : * @return
13859 : : * Pointer to the counter, NULL otherwise.
13860 : : */
13861 : : static struct mlx5_flow_counter *
13862 : 0 : flow_dv_prepare_counter(struct rte_eth_dev *dev,
13863 : : struct mlx5_flow *dev_flow,
13864 : : struct rte_flow *flow,
13865 : : const struct rte_flow_action_count *count,
13866 : : const struct rte_flow_action_age *age,
13867 : : struct rte_flow_error *error)
13868 : : {
13869 [ # # ]: 0 : if (!flow->counter) {
13870 : 0 : flow->counter = flow_dv_translate_create_counter(dev, dev_flow,
13871 : : count, age);
13872 [ # # ]: 0 : if (!flow->counter) {
13873 : 0 : rte_flow_error_set(error, rte_errno,
13874 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
13875 : : "cannot create counter object.");
13876 : 0 : return NULL;
13877 : : }
13878 : : }
13879 [ # # ]: 0 : return flow_dv_counter_get_by_idx(dev, flow->counter, NULL);
13880 : : }
13881 : :
13882 : : /*
13883 : : * Release an ASO CT action by its own device.
13884 : : *
13885 : : * @param[in] dev
13886 : : * Pointer to the Ethernet device structure.
13887 : : * @param[in] idx
13888 : : * Index of ASO CT action to release.
13889 : : *
13890 : : * @return
13891 : : * 0 when CT action was removed, otherwise the number of references.
13892 : : */
13893 : : static inline int
13894 : 0 : flow_dv_aso_ct_dev_release(struct rte_eth_dev *dev, uint32_t idx)
13895 : : {
13896 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13897 : 0 : struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
13898 : : uint32_t ret;
13899 : 0 : struct mlx5_aso_ct_action *ct = flow_aso_ct_get_by_dev_idx(dev, idx);
13900 : : enum mlx5_aso_ct_state state =
13901 : 0 : rte_atomic_load_explicit(&ct->state, rte_memory_order_relaxed);
13902 : :
13903 : : /* Cannot release when CT is in the ASO SQ. */
13904 [ # # ]: 0 : if (state == ASO_CONNTRACK_WAIT || state == ASO_CONNTRACK_QUERY)
13905 : : return -1;
13906 : 0 : ret = rte_atomic_fetch_sub_explicit(&ct->refcnt, 1, rte_memory_order_relaxed) - 1;
13907 [ # # ]: 0 : if (!ret) {
13908 [ # # ]: 0 : if (ct->dr_action_orig) {
13909 : : #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
13910 : 0 : claim_zero(mlx5_glue->destroy_flow_action
13911 : : (ct->dr_action_orig));
13912 : : #endif
13913 : 0 : ct->dr_action_orig = NULL;
13914 : : }
13915 [ # # ]: 0 : if (ct->dr_action_rply) {
13916 : : #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
13917 : 0 : claim_zero(mlx5_glue->destroy_flow_action
13918 : : (ct->dr_action_rply));
13919 : : #endif
13920 : 0 : ct->dr_action_rply = NULL;
13921 : : }
13922 : : /* Clear the state to free, no need in 1st allocation. */
13923 : 0 : MLX5_ASO_CT_UPDATE_STATE(ct, ASO_CONNTRACK_FREE);
13924 : 0 : rte_spinlock_lock(&mng->ct_sl);
13925 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free_cts, ct, next);
13926 : : rte_spinlock_unlock(&mng->ct_sl);
13927 : : }
13928 : 0 : return (int)ret;
13929 : : }
13930 : :
13931 : : static inline int
13932 : 0 : flow_dv_aso_ct_release(struct rte_eth_dev *dev, uint32_t own_idx,
13933 : : struct rte_flow_error *error)
13934 : : {
13935 : 0 : uint16_t owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(own_idx);
13936 : 0 : uint32_t idx = MLX5_INDIRECT_ACT_CT_GET_IDX(own_idx);
13937 : 0 : struct rte_eth_dev *owndev = &rte_eth_devices[owner];
13938 : : int ret;
13939 : :
13940 : : MLX5_ASSERT(owner < RTE_MAX_ETHPORTS);
13941 [ # # ]: 0 : if (dev->data->dev_started != 1)
13942 : 0 : return rte_flow_error_set(error, EAGAIN,
13943 : : RTE_FLOW_ERROR_TYPE_ACTION,
13944 : : NULL,
13945 : : "Indirect CT action cannot be destroyed when the port is stopped");
13946 : 0 : ret = flow_dv_aso_ct_dev_release(owndev, idx);
13947 [ # # ]: 0 : if (ret < 0)
13948 : 0 : return rte_flow_error_set(error, EAGAIN,
13949 : : RTE_FLOW_ERROR_TYPE_ACTION,
13950 : : NULL,
13951 : : "Current state prevents indirect CT action from being destroyed");
13952 : : return ret;
13953 : : }
13954 : :
13955 : : /*
13956 : : * Resize the ASO CT pools array by 64 pools.
13957 : : *
13958 : : * @param[in] dev
13959 : : * Pointer to the Ethernet device structure.
13960 : : *
13961 : : * @return
13962 : : * 0 on success, otherwise negative errno value and rte_errno is set.
13963 : : */
13964 : : static int
13965 : 0 : flow_dv_aso_ct_pools_resize(struct rte_eth_dev *dev)
13966 : : {
13967 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
13968 : 0 : struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
13969 : 0 : void *old_pools = mng->pools;
13970 : : /* Magic number now, need a macro. */
13971 : 0 : uint32_t resize = mng->n + 64;
13972 : 0 : uint32_t mem_size = sizeof(struct mlx5_aso_ct_pool *) * resize;
13973 : 0 : void *pools = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
13974 : :
13975 [ # # ]: 0 : if (!pools) {
13976 : 0 : rte_errno = ENOMEM;
13977 : 0 : return -rte_errno;
13978 : : }
13979 : 0 : rte_rwlock_write_lock(&mng->resize_rwl);
13980 : : /* ASO SQ/QP was already initialized in the startup. */
13981 [ # # ]: 0 : if (old_pools) {
13982 : : /* Realloc could be an alternative choice. */
13983 : 0 : rte_memcpy(pools, old_pools,
13984 [ # # ]: 0 : mng->n * sizeof(struct mlx5_aso_ct_pool *));
13985 : 0 : mlx5_free(old_pools);
13986 : : }
13987 : 0 : mng->n = resize;
13988 : 0 : mng->pools = pools;
13989 : : rte_rwlock_write_unlock(&mng->resize_rwl);
13990 : 0 : return 0;
13991 : : }
13992 : :
13993 : : /*
13994 : : * Create and initialize a new ASO CT pool.
13995 : : *
13996 : : * @param[in] dev
13997 : : * Pointer to the Ethernet device structure.
13998 : : * @param[out] ct_free
13999 : : * Where to put the pointer of a new CT action.
14000 : : *
14001 : : * @return
14002 : : * The CT actions pool pointer and @p ct_free is set on success,
14003 : : * NULL otherwise and rte_errno is set.
14004 : : */
14005 : : static struct mlx5_aso_ct_pool *
14006 : 0 : flow_dv_ct_pool_create(struct rte_eth_dev *dev,
14007 : : struct mlx5_aso_ct_action **ct_free)
14008 : : {
14009 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14010 : 0 : struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
14011 : : struct mlx5_aso_ct_pool *pool = NULL;
14012 : : struct mlx5_devx_obj *obj = NULL;
14013 : : uint32_t i;
14014 : : uint32_t log_obj_size = rte_log2_u32(MLX5_ASO_CT_ACTIONS_PER_POOL);
14015 : : size_t mem_size;
14016 : :
14017 : 0 : obj = mlx5_devx_cmd_create_conn_track_offload_obj(priv->sh->cdev->ctx,
14018 : 0 : priv->sh->cdev->pdn,
14019 : : log_obj_size);
14020 [ # # ]: 0 : if (!obj) {
14021 : 0 : rte_errno = ENODATA;
14022 : 0 : DRV_LOG(ERR, "Failed to create conn_track_offload_obj using DevX.");
14023 : 0 : return NULL;
14024 : : }
14025 : : mem_size = sizeof(struct mlx5_aso_ct_action) *
14026 : : MLX5_ASO_CT_ACTIONS_PER_POOL +
14027 : : sizeof(*pool);
14028 : 0 : pool = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 0, SOCKET_ID_ANY);
14029 [ # # ]: 0 : if (!pool) {
14030 : 0 : rte_errno = ENOMEM;
14031 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
14032 : 0 : return NULL;
14033 : : }
14034 : 0 : pool->devx_obj = obj;
14035 : 0 : pool->index = mng->next;
14036 : : /* Resize pools array if there is no room for the new pool in it. */
14037 [ # # # # ]: 0 : if (pool->index == mng->n && flow_dv_aso_ct_pools_resize(dev)) {
14038 : 0 : claim_zero(mlx5_devx_cmd_destroy(obj));
14039 : 0 : mlx5_free(pool);
14040 : 0 : return NULL;
14041 : : }
14042 : 0 : mng->pools[pool->index] = pool;
14043 : 0 : mng->next++;
14044 : : /* Assign the first action in the new pool, the rest go to free list. */
14045 : 0 : *ct_free = &pool->actions[0];
14046 : : /* Lock outside, the list operation is safe here. */
14047 [ # # ]: 0 : for (i = 1; i < MLX5_ASO_CT_ACTIONS_PER_POOL; i++) {
14048 : : /* refcnt is 0 when allocating the memory. */
14049 : 0 : pool->actions[i].offset = i;
14050 [ # # ]: 0 : LIST_INSERT_HEAD(&mng->free_cts, &pool->actions[i], next);
14051 : : }
14052 : : return pool;
14053 : : }
14054 : :
14055 : : /*
14056 : : * Allocate a ASO CT action from free list.
14057 : : *
14058 : : * @param[in] dev
14059 : : * Pointer to the Ethernet device structure.
14060 : : * @param[out] error
14061 : : * Pointer to the error structure.
14062 : : *
14063 : : * @return
14064 : : * Index to ASO CT action on success, 0 otherwise and rte_errno is set.
14065 : : */
14066 : : static uint32_t
14067 : 0 : flow_dv_aso_ct_alloc(struct rte_eth_dev *dev, struct rte_flow_error *error)
14068 : : {
14069 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14070 : 0 : struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng;
14071 : 0 : struct mlx5_aso_ct_action *ct = NULL;
14072 : : struct mlx5_aso_ct_pool *pool;
14073 : : uint8_t reg_c;
14074 : : uint32_t ct_idx;
14075 : :
14076 : : MLX5_ASSERT(mng);
14077 [ # # ]: 0 : if (!priv->sh->cdev->config.devx) {
14078 : 0 : rte_errno = ENOTSUP;
14079 : 0 : return 0;
14080 : : }
14081 : : /* Get a free CT action, if no, a new pool will be created. */
14082 : 0 : rte_spinlock_lock(&mng->ct_sl);
14083 : 0 : ct = LIST_FIRST(&mng->free_cts);
14084 [ # # ]: 0 : if (ct) {
14085 [ # # ]: 0 : LIST_REMOVE(ct, next);
14086 [ # # ]: 0 : } else if (!flow_dv_ct_pool_create(dev, &ct)) {
14087 : : rte_spinlock_unlock(&mng->ct_sl);
14088 : 0 : rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION,
14089 : : NULL, "failed to create ASO CT pool");
14090 : 0 : return 0;
14091 : : }
14092 : : rte_spinlock_unlock(&mng->ct_sl);
14093 : 0 : pool = container_of(ct, struct mlx5_aso_ct_pool, actions[ct->offset]);
14094 : 0 : ct_idx = MLX5_MAKE_CT_IDX(pool->index, ct->offset);
14095 : : /* 0: inactive, 1: created, 2+: used by flows. */
14096 : 0 : rte_atomic_store_explicit(&ct->refcnt, 1, rte_memory_order_relaxed);
14097 : 0 : reg_c = mlx5_flow_get_reg_id(dev, MLX5_ASO_CONNTRACK, 0, error);
14098 [ # # ]: 0 : if (!ct->dr_action_orig) {
14099 : : #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
14100 : 0 : ct->dr_action_orig = mlx5_glue->dv_create_flow_action_aso
14101 : 0 : (priv->sh->rx_domain, pool->devx_obj->obj,
14102 : : ct->offset,
14103 : : MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_INITIATOR,
14104 : 0 : reg_c - REG_C_0);
14105 : : #else
14106 : : RTE_SET_USED(reg_c);
14107 : : #endif
14108 [ # # ]: 0 : if (!ct->dr_action_orig) {
14109 : 0 : flow_dv_aso_ct_dev_release(dev, ct_idx);
14110 : 0 : rte_flow_error_set(error, rte_errno,
14111 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14112 : : "failed to create ASO CT action");
14113 : 0 : return 0;
14114 : : }
14115 : : }
14116 [ # # ]: 0 : if (!ct->dr_action_rply) {
14117 : : #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
14118 : 0 : ct->dr_action_rply = mlx5_glue->dv_create_flow_action_aso
14119 : 0 : (priv->sh->rx_domain, pool->devx_obj->obj,
14120 : : ct->offset,
14121 : : MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_RESPONDER,
14122 : 0 : reg_c - REG_C_0);
14123 : : #endif
14124 [ # # ]: 0 : if (!ct->dr_action_rply) {
14125 : 0 : flow_dv_aso_ct_dev_release(dev, ct_idx);
14126 : 0 : rte_flow_error_set(error, rte_errno,
14127 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14128 : : "failed to create ASO CT action");
14129 : 0 : return 0;
14130 : : }
14131 : : }
14132 : : return ct_idx;
14133 : : }
14134 : :
14135 : : /*
14136 : : * Create a conntrack object with context and actions by using ASO mechanism.
14137 : : *
14138 : : * @param[in] dev
14139 : : * Pointer to rte_eth_dev structure.
14140 : : * @param[in] pro
14141 : : * Pointer to conntrack information profile.
14142 : : * @param[out] error
14143 : : * Pointer to the error structure.
14144 : : *
14145 : : * @return
14146 : : * Index to conntrack object on success, 0 otherwise.
14147 : : */
14148 : : static uint32_t
14149 : 0 : flow_dv_translate_create_conntrack(struct rte_eth_dev *dev,
14150 : : const struct rte_flow_action_conntrack *pro,
14151 : : struct rte_flow_error *error)
14152 : : {
14153 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14154 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
14155 : : struct mlx5_aso_ct_action *ct;
14156 : : uint32_t idx;
14157 : :
14158 [ # # ]: 0 : if (!sh->ct_aso_en)
14159 : 0 : return rte_flow_error_set(error, ENOTSUP,
14160 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14161 : : "Connection is not supported");
14162 [ # # ]: 0 : if (dev->data->port_id >= MLX5_INDIRECT_ACT_CT_MAX_PORT) {
14163 : 0 : rte_flow_error_set(error, EINVAL,
14164 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
14165 : : "CT supports port indexes up to "
14166 : : RTE_STR(MLX5_ACTION_CTX_CT_MAX_PORT));
14167 : 0 : return 0;
14168 : : }
14169 : 0 : idx = flow_dv_aso_ct_alloc(dev, error);
14170 [ # # ]: 0 : if (!idx)
14171 : 0 : return rte_flow_error_set(error, rte_errno,
14172 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14173 : : "Failed to allocate CT object");
14174 : 0 : ct = flow_aso_ct_get_by_dev_idx(dev, idx);
14175 [ # # ]: 0 : if (mlx5_aso_ct_update_by_wqe(sh, MLX5_HW_INV_QUEUE, ct, pro, NULL, true)) {
14176 : 0 : flow_dv_aso_ct_dev_release(dev, idx);
14177 : 0 : rte_flow_error_set(error, EBUSY,
14178 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
14179 : : "Failed to update CT");
14180 : 0 : return 0;
14181 : : }
14182 : 0 : ct->is_original = !!pro->is_original_dir;
14183 : 0 : ct->peer = pro->peer_port;
14184 : 0 : return idx;
14185 : : }
14186 : :
14187 : : /**
14188 : : * Fill the flow matcher with DV spec.
14189 : : *
14190 : : * @param[in] dev
14191 : : * Pointer to rte_eth_dev structure.
14192 : : * @param[in] items
14193 : : * Pointer to the list of items.
14194 : : * @param[in] wks
14195 : : * Pointer to the matcher workspace.
14196 : : * @param[in] key
14197 : : * Pointer to the flow matcher key.
14198 : : * @param[in] key_type
14199 : : * Key type.
14200 : : * @param[out] error
14201 : : * Pointer to the error structure.
14202 : : *
14203 : : * @return
14204 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14205 : : */
14206 : : static int
14207 : 0 : flow_dv_translate_items(struct rte_eth_dev *dev,
14208 : : const struct rte_flow_item *items,
14209 : : struct mlx5_dv_matcher_workspace *wks,
14210 : : void *key, uint32_t key_type,
14211 : : struct rte_flow_error *error)
14212 : : {
14213 : 0 : struct mlx5_flow_rss_desc *rss_desc = wks->rss_desc;
14214 : 0 : uint8_t next_protocol = wks->next_protocol;
14215 : 0 : int tunnel = !!(wks->item_flags & MLX5_FLOW_LAYER_TUNNEL);
14216 : 0 : int item_type = items->type;
14217 : 0 : uint64_t last_item = wks->last_item;
14218 : : enum mlx5_l3_tunnel_detection l3_tunnel_detection;
14219 : : uint64_t l3_tunnel_flag;
14220 : : int ret;
14221 : :
14222 [ # # # # : 0 : switch (item_type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
14223 : 0 : case RTE_FLOW_ITEM_TYPE_ESP:
14224 : 0 : flow_dv_translate_item_esp(key, items, tunnel, key_type);
14225 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14226 : : last_item = MLX5_FLOW_ITEM_ESP;
14227 : 0 : break;
14228 : 0 : case RTE_FLOW_ITEM_TYPE_PORT_ID:
14229 : 0 : flow_dv_translate_item_port_id
14230 : : (dev, key, items, wks->attr, key_type);
14231 : : last_item = MLX5_FLOW_ITEM_PORT_ID;
14232 : 0 : break;
14233 : 0 : case RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR:
14234 : 0 : flow_dv_translate_item_port_representor
14235 : : (dev, key, key_type);
14236 : : last_item = MLX5_FLOW_ITEM_PORT_REPRESENTOR;
14237 : 0 : break;
14238 : 0 : case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
14239 : 0 : flow_dv_translate_item_represented_port
14240 : : (dev, key, items, wks->attr, key_type);
14241 : : last_item = MLX5_FLOW_ITEM_REPRESENTED_PORT;
14242 : 0 : break;
14243 : 0 : case RTE_FLOW_ITEM_TYPE_ETH:
14244 : 0 : flow_dv_translate_item_eth(key, items, tunnel,
14245 : : wks->group, key_type);
14246 [ # # ]: 0 : wks->priority = wks->action_flags &
14247 : 0 : MLX5_FLOW_ACTION_DEFAULT_MISS &&
14248 [ # # ]: 0 : !wks->external ?
14249 : : MLX5_PRIORITY_MAP_L3 :
14250 : : MLX5_PRIORITY_MAP_L2;
14251 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
14252 : : MLX5_FLOW_LAYER_OUTER_L2;
14253 : : break;
14254 : 0 : case RTE_FLOW_ITEM_TYPE_VLAN:
14255 : 0 : flow_dv_translate_item_vlan(key, items, tunnel, wks, key_type);
14256 : 0 : wks->priority = MLX5_PRIORITY_MAP_L2;
14257 : : last_item = tunnel ? (MLX5_FLOW_LAYER_INNER_L2 |
14258 [ # # ]: 0 : MLX5_FLOW_LAYER_INNER_VLAN) :
14259 : : (MLX5_FLOW_LAYER_OUTER_L2 |
14260 : : MLX5_FLOW_LAYER_OUTER_VLAN);
14261 : : break;
14262 : : case RTE_FLOW_ITEM_TYPE_IPV4:
14263 : : next_protocol = mlx5_flow_l3_next_protocol(items, key_type);
14264 : : l3_tunnel_detection =
14265 : : mlx5_flow_tunnel_ip_check(items, next_protocol,
14266 : : wks->item_flags,
14267 : : &l3_tunnel_flag);
14268 : : if (l3_tunnel_detection == l3_tunnel_inner) {
14269 : 0 : wks->item_flags |= l3_tunnel_flag;
14270 : : tunnel = 1;
14271 : : }
14272 : 0 : flow_dv_translate_item_ipv4(key, items, tunnel,
14273 : : wks->group, key_type);
14274 : 0 : wks->priority = MLX5_PRIORITY_MAP_L3;
14275 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
14276 : : MLX5_FLOW_LAYER_OUTER_L3_IPV4;
14277 [ # # ]: 0 : if (l3_tunnel_detection == l3_tunnel_outer)
14278 : 0 : wks->item_flags |= l3_tunnel_flag;
14279 : : break;
14280 : : case RTE_FLOW_ITEM_TYPE_IPV6:
14281 : : next_protocol = mlx5_flow_l3_next_protocol(items, key_type);
14282 : : l3_tunnel_detection =
14283 : : mlx5_flow_tunnel_ip_check(items, next_protocol,
14284 : : wks->item_flags,
14285 : : &l3_tunnel_flag);
14286 : : if (l3_tunnel_detection == l3_tunnel_inner) {
14287 : 0 : wks->item_flags |= l3_tunnel_flag;
14288 : : tunnel = 1;
14289 : : }
14290 : 0 : flow_dv_translate_item_ipv6(key, items, tunnel,
14291 : : wks->group, key_type);
14292 : 0 : wks->priority = MLX5_PRIORITY_MAP_L3;
14293 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
14294 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6;
14295 [ # # ]: 0 : if (l3_tunnel_detection == l3_tunnel_outer)
14296 : 0 : wks->item_flags |= l3_tunnel_flag;
14297 : : break;
14298 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
14299 : 0 : flow_dv_translate_item_ipv6_frag_ext
14300 : : (key, items, tunnel, key_type);
14301 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT :
14302 : : MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT;
14303 : : next_protocol = mlx5_flow_l3_next_protocol(items, key_type);
14304 : : break;
14305 : 0 : case RTE_FLOW_ITEM_TYPE_TCP:
14306 : 0 : flow_dv_translate_item_tcp(key, items, tunnel, key_type);
14307 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14308 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_TCP :
14309 : : MLX5_FLOW_LAYER_OUTER_L4_TCP;
14310 : : break;
14311 : 0 : case RTE_FLOW_ITEM_TYPE_UDP:
14312 : 0 : flow_dv_translate_item_udp(key, items, tunnel, wks, key_type);
14313 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14314 [ # # ]: 0 : last_item = tunnel ? MLX5_FLOW_LAYER_INNER_L4_UDP :
14315 : : MLX5_FLOW_LAYER_OUTER_L4_UDP;
14316 : : break;
14317 : 0 : case RTE_FLOW_ITEM_TYPE_GRE:
14318 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14319 : 0 : wks->tunnel_item = items;
14320 : 0 : wks->gre_item = items;
14321 : : last_item = MLX5_FLOW_LAYER_GRE;
14322 : 0 : break;
14323 : 0 : case RTE_FLOW_ITEM_TYPE_GRE_KEY:
14324 : 0 : flow_dv_translate_item_gre_key(key, items, key_type);
14325 : : last_item = MLX5_FLOW_LAYER_GRE_KEY;
14326 : 0 : break;
14327 : 0 : case RTE_FLOW_ITEM_TYPE_GRE_OPTION:
14328 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14329 : 0 : wks->tunnel_item = items;
14330 : : last_item = MLX5_FLOW_LAYER_GRE;
14331 : 0 : break;
14332 : 0 : case RTE_FLOW_ITEM_TYPE_NVGRE:
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_VXLAN:
14338 : 0 : flow_dv_translate_item_vxlan(dev, wks->attr, key,
14339 : : items, tunnel, wks, key_type);
14340 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14341 : : last_item = MLX5_FLOW_LAYER_VXLAN;
14342 : 0 : break;
14343 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
14344 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14345 : 0 : wks->tunnel_item = items;
14346 : : last_item = MLX5_FLOW_LAYER_VXLAN_GPE;
14347 : 0 : break;
14348 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE:
14349 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14350 : 0 : wks->tunnel_item = items;
14351 : : last_item = MLX5_FLOW_LAYER_GENEVE;
14352 : 0 : break;
14353 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
14354 : 0 : ret = flow_dv_translate_item_geneve_opt
14355 : : (dev, key, items, key_type, error);
14356 [ # # ]: 0 : if (ret)
14357 : 0 : return rte_flow_error_set(error, -ret,
14358 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14359 : : "cannot create GENEVE TLV option");
14360 : 0 : wks->geneve_tlv_option = 1;
14361 : : last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
14362 : 0 : break;
14363 : 0 : case RTE_FLOW_ITEM_TYPE_MPLS:
14364 : 0 : flow_dv_translate_item_mpls(key, items, last_item,
14365 : : tunnel, key_type);
14366 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14367 : : last_item = MLX5_FLOW_LAYER_MPLS;
14368 : 0 : break;
14369 : 0 : case RTE_FLOW_ITEM_TYPE_MARK:
14370 : 0 : flow_dv_translate_item_mark(dev, key, items, key_type);
14371 : : last_item = MLX5_FLOW_ITEM_MARK;
14372 : 0 : break;
14373 : 0 : case RTE_FLOW_ITEM_TYPE_META:
14374 : 0 : flow_dv_translate_item_meta
14375 : : (dev, key, wks->attr, items, key_type);
14376 : : last_item = MLX5_FLOW_ITEM_METADATA;
14377 : 0 : break;
14378 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP:
14379 : 0 : flow_dv_translate_item_icmp(key, items, tunnel, key_type);
14380 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14381 : : last_item = MLX5_FLOW_LAYER_ICMP;
14382 : 0 : break;
14383 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6:
14384 : 0 : flow_dv_translate_item_icmp6(key, items, tunnel, key_type);
14385 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14386 : : last_item = MLX5_FLOW_LAYER_ICMP6;
14387 : 0 : break;
14388 : 0 : case RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REQUEST:
14389 : : case RTE_FLOW_ITEM_TYPE_ICMP6_ECHO_REPLY:
14390 : 0 : flow_dv_translate_item_icmp6_echo(key, items, tunnel, key_type);
14391 : 0 : wks->priority = MLX5_PRIORITY_MAP_L4;
14392 : : last_item = MLX5_FLOW_LAYER_ICMP6;
14393 : 0 : break;
14394 : 0 : case RTE_FLOW_ITEM_TYPE_TAG:
14395 : 0 : flow_dv_translate_item_tag(dev, key, items, key_type);
14396 : : last_item = MLX5_FLOW_ITEM_TAG;
14397 : 0 : break;
14398 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_TAG:
14399 : 0 : flow_dv_translate_mlx5_item_tag(dev, key, items, key_type);
14400 : : last_item = MLX5_FLOW_ITEM_TAG;
14401 : 0 : break;
14402 : 0 : case RTE_FLOW_ITEM_TYPE_TX_QUEUE:
14403 : 0 : ret = flow_dv_translate_item_tx_queue(dev, key, items, key_type);
14404 [ # # ]: 0 : if (ret)
14405 : 0 : return rte_flow_error_set(error, -ret,
14406 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14407 : : "invalid tx_queue item");
14408 : : last_item = MLX5_FLOW_ITEM_SQ;
14409 : : break;
14410 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_SQ:
14411 : 0 : flow_dv_translate_item_sq(key, items, key_type);
14412 : : last_item = MLX5_FLOW_ITEM_SQ;
14413 : 0 : break;
14414 : 0 : case RTE_FLOW_ITEM_TYPE_GTP:
14415 : 0 : flow_dv_translate_item_gtp(key, items, tunnel, key_type);
14416 [ # # ]: 0 : wks->priority = MLX5_TUNNEL_PRIO_GET(rss_desc);
14417 : : last_item = MLX5_FLOW_LAYER_GTP;
14418 : 0 : break;
14419 : 0 : case RTE_FLOW_ITEM_TYPE_GTP_PSC:
14420 : 0 : ret = flow_dv_translate_item_gtp_psc(key, items, key_type);
14421 [ # # ]: 0 : if (ret)
14422 : 0 : return rte_flow_error_set(error, -ret,
14423 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14424 : : "cannot create GTP PSC item");
14425 : : last_item = MLX5_FLOW_LAYER_GTP_PSC;
14426 : : break;
14427 : 0 : case RTE_FLOW_ITEM_TYPE_ECPRI:
14428 [ # # ]: 0 : if (!mlx5_flex_parser_ecpri_exist(dev)) {
14429 : : /* Create it only the first time to be used. */
14430 : 0 : ret = mlx5_flex_parser_ecpri_alloc(dev);
14431 [ # # ]: 0 : if (ret)
14432 : 0 : return rte_flow_error_set
14433 : : (error, -ret,
14434 : : RTE_FLOW_ERROR_TYPE_ITEM,
14435 : : NULL,
14436 : : "cannot create eCPRI parser");
14437 : : }
14438 : 0 : flow_dv_translate_item_ecpri
14439 : : (dev, key, items, last_item, key_type);
14440 : : /* No other protocol should follow eCPRI layer. */
14441 : : last_item = MLX5_FLOW_LAYER_ECPRI;
14442 : 0 : break;
14443 : 0 : case RTE_FLOW_ITEM_TYPE_METER_COLOR:
14444 : 0 : flow_dv_translate_item_meter_color(dev, key, items, key_type);
14445 : : last_item = MLX5_FLOW_ITEM_METER_COLOR;
14446 : 0 : break;
14447 [ # # ]: 0 : case RTE_FLOW_ITEM_TYPE_INTEGRITY:
14448 : : last_item = flow_dv_translate_item_integrity(items,
14449 : : wks, key_type);
14450 : 0 : break;
14451 : 0 : case RTE_FLOW_ITEM_TYPE_AGGR_AFFINITY:
14452 : 0 : flow_dv_translate_item_aggr_affinity(key, items, key_type);
14453 : : last_item = MLX5_FLOW_ITEM_AGGR_AFFINITY;
14454 : 0 : break;
14455 : 0 : case RTE_FLOW_ITEM_TYPE_IB_BTH:
14456 : 0 : flow_dv_translate_item_ib_bth(key, items, tunnel, key_type);
14457 : : last_item = MLX5_FLOW_ITEM_IB_BTH;
14458 : 0 : break;
14459 : 0 : case RTE_FLOW_ITEM_TYPE_NSH:
14460 : : last_item = MLX5_FLOW_ITEM_NSH;
14461 : 0 : break;
14462 : : default:
14463 : : break;
14464 : : }
14465 : 0 : wks->item_flags |= last_item;
14466 : 0 : wks->last_item = last_item;
14467 : 0 : wks->next_protocol = next_protocol;
14468 : 0 : return 0;
14469 : : }
14470 : :
14471 : : static int
14472 : 0 : flow_dv_translate_items_geneve_opt_nta(struct rte_eth_dev *dev,
14473 : : const struct rte_flow_item *items,
14474 : : struct mlx5_flow_attr *attr,
14475 : : struct rte_flow_error *error)
14476 : : {
14477 : 0 : rte_be32_t geneve_mask = 0xffffffff;
14478 : 0 : struct rte_pmd_mlx5_geneve_tlv geneve_tlv = {
14479 : : /* Take from item spec, if changed, destroy and add new parser. */
14480 : : .option_class = 0,
14481 : : /* Take from item spec, if changed, destroy and add new parser. */
14482 : : .option_type = 0,
14483 : : /* 1DW is supported. */
14484 : : .option_len = 1,
14485 : : .match_on_class_mode = 1,
14486 : : .offset = 0,
14487 : : .sample_len = 1,
14488 : : .match_data_mask = &geneve_mask
14489 : : };
14490 : 0 : const struct rte_flow_item_geneve_opt *geneve_opt_v = items->spec;
14491 : 0 : const struct rte_flow_item_geneve_opt *geneve_opt_m = items->mask;
14492 : : void *geneve_parser;
14493 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14494 : : #ifdef RTE_LIBRTE_MLX5_DEBUG
14495 : : struct mlx5_geneve_tlv_option *option;
14496 : : #endif
14497 : :
14498 : : /* option length is not as supported. */
14499 [ # # ]: 0 : if ((geneve_opt_v->option_len & geneve_opt_m->option_len) > geneve_tlv.option_len)
14500 : 0 : return rte_flow_error_set(error, ENOTSUP,
14501 : : RTE_FLOW_ERROR_TYPE_ITEM, items,
14502 : : " GENEVE OPT length is not supported ");
14503 : 0 : geneve_tlv.option_class = geneve_opt_v->option_class & geneve_opt_m->option_class;
14504 : 0 : geneve_tlv.option_type = geneve_opt_v->option_type & geneve_opt_m->option_type;
14505 : : /* if parser doesn't exist */
14506 [ # # ]: 0 : if (!priv->tlv_options) {
14507 : : /* Create a GENEVE option parser. */
14508 : 0 : geneve_parser = mlx5_geneve_tlv_parser_create(attr->port_id,
14509 : : &geneve_tlv, 1);
14510 [ # # ]: 0 : if (!geneve_parser)
14511 : 0 : return rte_flow_error_set(error, EINVAL,
14512 : : RTE_FLOW_ERROR_TYPE_ITEM, items,
14513 : : " GENEVE OPT parser creation failed ");
14514 : : #ifdef RTE_LIBRTE_MLX5_DEBUG
14515 : : } else {
14516 : : /* Check if option exist in current parser. */
14517 : : option = mlx5_geneve_tlv_option_get(priv,
14518 : : geneve_tlv.option_type,
14519 : : geneve_tlv.option_class);
14520 : : if (!option)
14521 : : return rte_flow_error_set(error, EINVAL,
14522 : : RTE_FLOW_ERROR_TYPE_ITEM, items,
14523 : : " GENEVE OPT configured does not match this rule class/type");
14524 : : #endif
14525 : : }
14526 : : return 0;
14527 : : }
14528 : :
14529 : : /**
14530 : : * Fill the flow matcher with DV spec for items supported in non template mode.
14531 : : *
14532 : : * @param[in] dev
14533 : : * Pointer to rte_eth_dev structure.
14534 : : * @param[in] items
14535 : : * Pointer to the list of items.
14536 : : * @param[in] wks
14537 : : * Pointer to the matcher workspace.
14538 : : * @param[in] key
14539 : : * Pointer to the flow matcher key.
14540 : : * @param[in] key_type
14541 : : * Key type.
14542 : : * @param[out] error
14543 : : * Pointer to the error structure.
14544 : : *
14545 : : * @return
14546 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14547 : : */
14548 : : static int
14549 : 0 : flow_dv_translate_items_nta(struct rte_eth_dev *dev,
14550 : : const struct rte_flow_item *items,
14551 : : struct mlx5_dv_matcher_workspace *wks,
14552 : : void *key, uint32_t key_type,
14553 : : struct mlx5_flow_attr *attr,
14554 : : struct rte_flow_error *error)
14555 : : {
14556 : : int item_type;
14557 : : int ret = 0;
14558 : : int tunnel;
14559 : : /* Dummy structure to enable the key calculation for flex item. */
14560 : : struct mlx5_flow_dv_match_params flex_item_key;
14561 : :
14562 : 0 : tunnel = !!(wks->item_flags & MLX5_FLOW_LAYER_TUNNEL);
14563 : 0 : item_type = items->type;
14564 [ # # # # ]: 0 : switch (item_type) {
14565 : 0 : case RTE_FLOW_ITEM_TYPE_CONNTRACK:
14566 : 0 : flow_dv_translate_item_aso_ct(dev, key, NULL, items);
14567 : 0 : wks->last_item = MLX5_FLOW_LAYER_ASO_CT;
14568 : 0 : break;
14569 : : /* TODO: remove once flex item translation is added to flow_dv_translate_items. */
14570 : 0 : case RTE_FLOW_ITEM_TYPE_FLEX:
14571 : 0 : mlx5_flex_flow_translate_item(dev, key, flex_item_key.buf, items, tunnel != 0);
14572 [ # # ]: 0 : wks->last_item = tunnel ? MLX5_FLOW_ITEM_INNER_FLEX : MLX5_FLOW_ITEM_OUTER_FLEX;
14573 : 0 : break;
14574 : 0 : case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
14575 : 0 : ret = flow_dv_translate_items_geneve_opt_nta(dev, items, attr, error);
14576 [ # # ]: 0 : if (ret)
14577 : : return ret;
14578 : 0 : wks->last_item = MLX5_FLOW_LAYER_GENEVE_OPT;
14579 : 0 : break;
14580 : 0 : default:
14581 : 0 : ret = flow_dv_translate_items(dev, items, wks, key, key_type, error);
14582 [ # # ]: 0 : if (ret)
14583 : : return ret;
14584 : : break;
14585 : : }
14586 : 0 : wks->item_flags |= wks->last_item;
14587 : 0 : return 0;
14588 : : }
14589 : :
14590 : : /**
14591 : : * Fill the HW steering flow with DV spec.
14592 : : *
14593 : : * @param[in] items
14594 : : * Pointer to the list of items.
14595 : : * @param[in] attr
14596 : : * Pointer to the flow attributes.
14597 : : * @param[in] key
14598 : : * Pointer to the flow matcher key.
14599 : : * @param[in] key_type
14600 : : * Key type.
14601 : : * @param[in, out] item_flags
14602 : : * Pointer to the flow item flags.
14603 : : * @param[in, out] nt_flow
14604 : : * Non template flow.
14605 : : * @param[out] error
14606 : : * Pointer to the error structure.
14607 : : *
14608 : : * @return
14609 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14610 : : */
14611 : : int
14612 : 0 : __flow_dv_translate_items_hws(const struct rte_flow_item *items,
14613 : : struct mlx5_flow_attr *attr, void *key,
14614 : : uint32_t key_type, uint64_t *item_flags,
14615 : : uint8_t *match_criteria,
14616 : : bool nt_flow,
14617 : : struct rte_flow_error *error)
14618 : : {
14619 : 0 : struct mlx5_flow_workspace *flow_wks = mlx5_flow_push_thread_workspace();
14620 : 0 : struct mlx5_flow_rss_desc rss_desc = { .level = attr->rss_level };
14621 : 0 : struct rte_flow_attr rattr = {
14622 : 0 : .group = attr->group,
14623 : 0 : .priority = attr->priority,
14624 : 0 : .ingress = !!(attr->tbl_type == MLX5DR_TABLE_TYPE_NIC_RX),
14625 : 0 : .egress = !!(attr->tbl_type == MLX5DR_TABLE_TYPE_NIC_TX),
14626 : 0 : .transfer = !!(attr->tbl_type == MLX5DR_TABLE_TYPE_FDB),
14627 : : };
14628 : 0 : struct mlx5_dv_matcher_workspace wks = {
14629 : 0 : .action_flags = attr->act_flags,
14630 [ # # ]: 0 : .item_flags = item_flags ? *item_flags : 0,
14631 : : .external = 0,
14632 : : .next_protocol = 0xff,
14633 : : .attr = &rattr,
14634 : : .rss_desc = &rss_desc,
14635 : : .group = attr->group,
14636 : : };
14637 : : int ret = 0;
14638 : :
14639 : : RTE_SET_USED(flow_wks);
14640 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
14641 : : if (!mlx5_flow_os_item_supported(items->type)) {
14642 : : ret = rte_flow_error_set(error, ENOTSUP,
14643 : : RTE_FLOW_ERROR_TYPE_ITEM,
14644 : : NULL, "item not supported");
14645 : : goto exit;
14646 : : }
14647 : : /* Non template flow. */
14648 [ # # ]: 0 : if (nt_flow) {
14649 : 0 : ret = flow_dv_translate_items_nta(&rte_eth_devices[attr->port_id],
14650 : : items, &wks, key, key_type, attr, error);
14651 [ # # ]: 0 : if (ret)
14652 : 0 : goto exit;
14653 : : } else {
14654 : 0 : ret = flow_dv_translate_items(&rte_eth_devices[attr->port_id],
14655 : : items, &wks, key, key_type, error);
14656 [ # # ]: 0 : if (ret)
14657 : 0 : goto exit;
14658 : : }
14659 : : }
14660 [ # # ]: 0 : if (wks.item_flags & MLX5_FLOW_ITEM_INTEGRITY) {
14661 : 0 : flow_dv_translate_item_integrity_post(key,
14662 : : wks.integrity_items,
14663 : : wks.item_flags,
14664 : : key_type);
14665 : : }
14666 [ # # ]: 0 : if (wks.item_flags & MLX5_FLOW_LAYER_VXLAN_GPE) {
14667 : 0 : flow_dv_translate_item_vxlan_gpe(key,
14668 : : wks.tunnel_item,
14669 : : wks.item_flags,
14670 : : key_type);
14671 [ # # ]: 0 : } else if (wks.item_flags & MLX5_FLOW_LAYER_GENEVE) {
14672 : 0 : flow_dv_translate_item_geneve(key,
14673 : : wks.tunnel_item,
14674 : : wks.item_flags,
14675 : : key_type);
14676 [ # # ]: 0 : } else if (wks.item_flags & MLX5_FLOW_LAYER_GRE) {
14677 [ # # ]: 0 : if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE) {
14678 : 0 : flow_dv_translate_item_gre(key,
14679 : : wks.tunnel_item,
14680 : : wks.item_flags,
14681 : : key_type);
14682 [ # # ]: 0 : } else if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE_OPTION) {
14683 : 0 : flow_dv_translate_item_gre_option(key,
14684 : : wks.tunnel_item,
14685 : : wks.gre_item,
14686 : : wks.item_flags,
14687 : : key_type);
14688 [ # # ]: 0 : } else if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_NVGRE) {
14689 : 0 : flow_dv_translate_item_nvgre(key,
14690 : : wks.tunnel_item,
14691 : : wks.item_flags,
14692 : : key_type);
14693 : : } else {
14694 : : MLX5_ASSERT(false);
14695 : : }
14696 : : }
14697 : :
14698 [ # # ]: 0 : if (match_criteria)
14699 : 0 : *match_criteria = flow_dv_matcher_enable(key);
14700 [ # # ]: 0 : if (item_flags)
14701 : 0 : *item_flags = wks.item_flags;
14702 : 0 : exit:
14703 : 0 : mlx5_flow_pop_thread_workspace();
14704 : 0 : return ret;
14705 : : }
14706 : :
14707 : : /**
14708 : : * Fill the HW steering flow with DV spec.
14709 : : * This function assumes given flow is created from template API.
14710 : : *
14711 : : * @param[in] items
14712 : : * Pointer to the list of items.
14713 : : * @param[in] attr
14714 : : * Pointer to the flow attributes.
14715 : : * @param[in] key
14716 : : * Pointer to the flow matcher key.
14717 : : * @param[in] key_type
14718 : : * Key type.
14719 : : * @param[in, out] item_flags
14720 : : * Pointer to the flow item flags.
14721 : : * @param[out] error
14722 : : * Pointer to the error structure.
14723 : : *
14724 : : * @return
14725 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14726 : : */
14727 : : int
14728 : 0 : flow_dv_translate_items_hws(const struct rte_flow_item *items,
14729 : : struct mlx5_flow_attr *attr, void *key,
14730 : : uint32_t key_type, uint64_t *item_flags,
14731 : : uint8_t *match_criteria,
14732 : : struct rte_flow_error *error)
14733 : : {
14734 : 0 : return __flow_dv_translate_items_hws(items, attr, key, key_type, item_flags, match_criteria,
14735 : : false, error);
14736 : : }
14737 : :
14738 : : /**
14739 : : * Fill the SW steering flow with DV spec.
14740 : : *
14741 : : * @param[in] dev
14742 : : * Pointer to rte_eth_dev structure.
14743 : : * @param[in, out] dev_flow
14744 : : * Pointer to the sub flow.
14745 : : * @param[in] attr
14746 : : * Pointer to the flow attributes.
14747 : : * @param[in] items
14748 : : * Pointer to the list of items.
14749 : : * @param[in, out] matcher
14750 : : * Pointer to the flow matcher.
14751 : : * @param[out] error
14752 : : * Pointer to the error structure.
14753 : : *
14754 : : * @return
14755 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14756 : : */
14757 : : static int
14758 : 0 : flow_dv_translate_items_sws(struct rte_eth_dev *dev,
14759 : : struct mlx5_flow *dev_flow,
14760 : : const struct rte_flow_attr *attr,
14761 : : const struct rte_flow_item *items,
14762 : : struct mlx5_flow_dv_matcher *matcher,
14763 : : struct rte_flow_error *error)
14764 : : {
14765 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14766 : 0 : void *match_mask = matcher->mask.buf;
14767 : 0 : void *match_value = dev_flow->dv.value.buf;
14768 : 0 : struct mlx5_dv_matcher_workspace wks = {
14769 : 0 : .action_flags = dev_flow->act_flags,
14770 : : .item_flags = 0,
14771 : 0 : .external = dev_flow->external,
14772 : : .next_protocol = 0xff,
14773 : 0 : .group = dev_flow->dv.group,
14774 : : .attr = attr,
14775 : 0 : .rss_desc = &((struct mlx5_flow_workspace *)
14776 : : mlx5_flow_get_thread_workspace())->rss_desc,
14777 : : };
14778 : 0 : struct mlx5_dv_matcher_workspace wks_m = wks;
14779 : : int item_type;
14780 : : int ret = 0;
14781 : : int tunnel;
14782 : :
14783 [ # # ]: 0 : for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
14784 : 0 : if (!mlx5_flow_os_item_supported(items->type))
14785 : : return rte_flow_error_set(error, ENOTSUP,
14786 : : RTE_FLOW_ERROR_TYPE_ITEM,
14787 : : NULL, "item not supported");
14788 : 0 : tunnel = !!(wks.item_flags & MLX5_FLOW_LAYER_TUNNEL);
14789 : : item_type = items->type;
14790 [ # # # # : 0 : switch (item_type) {
# ]
14791 : 0 : case RTE_FLOW_ITEM_TYPE_CONNTRACK:
14792 : 0 : flow_dv_translate_item_aso_ct(dev, match_mask,
14793 : : match_value, items);
14794 : 0 : wks.last_item = MLX5_FLOW_LAYER_ASO_CT;
14795 : 0 : break;
14796 : 0 : case RTE_FLOW_ITEM_TYPE_FLEX:
14797 : 0 : flow_dv_translate_item_flex(dev, match_mask,
14798 : : match_value, items,
14799 : : dev_flow, tunnel != 0);
14800 [ # # ]: 0 : wks.last_item = tunnel ? MLX5_FLOW_ITEM_INNER_FLEX :
14801 : : MLX5_FLOW_ITEM_OUTER_FLEX;
14802 : 0 : break;
14803 : 0 : case RTE_FLOW_ITEM_TYPE_TX_QUEUE:
14804 : 0 : ret = flow_dv_translate_item_tx_queue(dev, match_value, items,
14805 : : MLX5_SET_MATCHER_SW_V);
14806 [ # # ]: 0 : if (ret)
14807 : 0 : return rte_flow_error_set(error, -ret,
14808 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14809 : : "invalid tx_queue item spec");
14810 : 0 : ret = flow_dv_translate_item_tx_queue(dev, match_mask, items,
14811 : : MLX5_SET_MATCHER_SW_M);
14812 [ # # ]: 0 : if (ret)
14813 : 0 : return rte_flow_error_set(error, -ret,
14814 : : RTE_FLOW_ERROR_TYPE_ITEM, NULL,
14815 : : "invalid tx_queue item mask");
14816 : : break;
14817 : 0 : case MLX5_RTE_FLOW_ITEM_TYPE_SQ:
14818 : 0 : flow_dv_translate_item_sq(match_value, items,
14819 : : MLX5_SET_MATCHER_SW_V);
14820 : 0 : flow_dv_translate_item_sq(match_mask, items,
14821 : : MLX5_SET_MATCHER_SW_M);
14822 : 0 : break;
14823 : 0 : default:
14824 : 0 : ret = flow_dv_translate_items(dev, items, &wks_m,
14825 : : match_mask, MLX5_SET_MATCHER_SW_M, error);
14826 [ # # ]: 0 : if (ret)
14827 : 0 : return ret;
14828 : 0 : ret = flow_dv_translate_items(dev, items, &wks,
14829 : : match_value, MLX5_SET_MATCHER_SW_V, error);
14830 [ # # ]: 0 : if (ret)
14831 : 0 : return ret;
14832 : : break;
14833 : : }
14834 : 0 : wks.item_flags |= wks.last_item;
14835 : : }
14836 : : /*
14837 : : * When E-Switch mode is enabled, we have two cases where we need to
14838 : : * set the source port manually.
14839 : : * The first one, is in case of NIC ingress steering rule, and the
14840 : : * second is E-Switch rule where no port_id item was found.
14841 : : * In both cases the source port is set according the current port
14842 : : * in use.
14843 : : */
14844 : 0 : if (!(wks.item_flags & MLX5_FLOW_ITEM_PORT_ID) &&
14845 [ # # ]: 0 : !(wks.item_flags & MLX5_FLOW_ITEM_REPRESENTED_PORT) &&
14846 : 0 : !(wks.item_flags & MLX5_FLOW_ITEM_PORT_REPRESENTOR) &&
14847 [ # # ]: 0 : priv->sh->esw_mode &&
14848 [ # # ]: 0 : !attr->egress &&
14849 [ # # ]: 0 : attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP) {
14850 [ # # ]: 0 : if (flow_dv_translate_item_port_id_all(dev, match_mask,
14851 : : match_value, NULL, attr))
14852 : 0 : return -rte_errno;
14853 : : }
14854 [ # # ]: 0 : if (wks.item_flags & MLX5_FLOW_ITEM_INTEGRITY) {
14855 : 0 : flow_dv_translate_item_integrity_post(match_mask,
14856 : : wks_m.integrity_items,
14857 : : wks_m.item_flags,
14858 : : MLX5_SET_MATCHER_SW_M);
14859 : 0 : flow_dv_translate_item_integrity_post(match_value,
14860 : : wks.integrity_items,
14861 : : wks.item_flags,
14862 : : MLX5_SET_MATCHER_SW_V);
14863 : : }
14864 [ # # ]: 0 : if (wks.item_flags & MLX5_FLOW_LAYER_VXLAN_GPE) {
14865 : 0 : flow_dv_translate_item_vxlan_gpe(match_mask,
14866 : : wks.tunnel_item,
14867 : : wks.item_flags,
14868 : : MLX5_SET_MATCHER_SW_M);
14869 : 0 : flow_dv_translate_item_vxlan_gpe(match_value,
14870 : : wks.tunnel_item,
14871 : : wks.item_flags,
14872 : : MLX5_SET_MATCHER_SW_V);
14873 [ # # ]: 0 : } else if (wks.item_flags & MLX5_FLOW_LAYER_GENEVE) {
14874 : 0 : flow_dv_translate_item_geneve(match_mask,
14875 : : wks.tunnel_item,
14876 : : wks.item_flags,
14877 : : MLX5_SET_MATCHER_SW_M);
14878 : 0 : flow_dv_translate_item_geneve(match_value,
14879 : : wks.tunnel_item,
14880 : : wks.item_flags,
14881 : : MLX5_SET_MATCHER_SW_V);
14882 [ # # ]: 0 : } else if (wks.item_flags & MLX5_FLOW_LAYER_GRE) {
14883 [ # # ]: 0 : if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE) {
14884 : 0 : flow_dv_translate_item_gre(match_mask,
14885 : : wks.tunnel_item,
14886 : : wks.item_flags,
14887 : : MLX5_SET_MATCHER_SW_M);
14888 : 0 : flow_dv_translate_item_gre(match_value,
14889 : : wks.tunnel_item,
14890 : : wks.item_flags,
14891 : : MLX5_SET_MATCHER_SW_V);
14892 [ # # ]: 0 : } else if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_NVGRE) {
14893 : 0 : flow_dv_translate_item_nvgre(match_mask,
14894 : : wks.tunnel_item,
14895 : : wks.item_flags,
14896 : : MLX5_SET_MATCHER_SW_M);
14897 : 0 : flow_dv_translate_item_nvgre(match_value,
14898 : : wks.tunnel_item,
14899 : : wks.item_flags,
14900 : : MLX5_SET_MATCHER_SW_V);
14901 [ # # ]: 0 : } else if (wks.tunnel_item->type == RTE_FLOW_ITEM_TYPE_GRE_OPTION) {
14902 : 0 : flow_dv_translate_item_gre_option(match_mask,
14903 : : wks.tunnel_item,
14904 : : wks.gre_item,
14905 : : wks.item_flags,
14906 : : MLX5_SET_MATCHER_SW_M);
14907 : 0 : flow_dv_translate_item_gre_option(match_value,
14908 : : wks.tunnel_item,
14909 : : wks.gre_item,
14910 : : wks.item_flags,
14911 : : MLX5_SET_MATCHER_SW_V);
14912 : : } else {
14913 : : MLX5_ASSERT(false);
14914 : : }
14915 : : }
14916 : 0 : dev_flow->handle->vf_vlan.tag = wks.vlan_tag;
14917 : 0 : matcher->priority = wks.priority;
14918 : : #ifdef RTE_LIBRTE_MLX5_DEBUG
14919 : : MLX5_ASSERT(!flow_dv_check_valid_spec(match_mask, match_value));
14920 : : #endif
14921 : : /*
14922 : : * Layers may be already initialized from prefix flow if this dev_flow
14923 : : * is the suffix flow.
14924 : : */
14925 : 0 : dev_flow->handle->layers |= wks.item_flags;
14926 : : /*
14927 : : * Update geneve_tlv_option flag only it is set in workspace.
14928 : : * Avoid be overwritten by other sub mlx5_flows.
14929 : : */
14930 [ # # ]: 0 : if (wks.geneve_tlv_option)
14931 : 0 : dev_flow->flow->geneve_tlv_option += wks.geneve_tlv_option;
14932 : : return 0;
14933 : : }
14934 : :
14935 : : /**
14936 : : * Fill the flow with DV spec, lock free
14937 : : * (mutex should be acquired by caller).
14938 : : *
14939 : : * @param[in] dev
14940 : : * Pointer to rte_eth_dev structure.
14941 : : * @param[in, out] dev_flow
14942 : : * Pointer to the sub flow.
14943 : : * @param[in] attr
14944 : : * Pointer to the flow attributes.
14945 : : * @param[in] items
14946 : : * Pointer to the list of items.
14947 : : * @param[in] actions
14948 : : * Pointer to the list of actions.
14949 : : * @param[out] error
14950 : : * Pointer to the error structure.
14951 : : *
14952 : : * @return
14953 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
14954 : : */
14955 : : static int
14956 : 0 : flow_dv_translate(struct rte_eth_dev *dev,
14957 : : struct mlx5_flow *dev_flow,
14958 : : const struct rte_flow_attr *attr,
14959 : : const struct rte_flow_item items[],
14960 : : const struct rte_flow_action actions[],
14961 : : struct rte_flow_error *error)
14962 : : {
14963 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
14964 : 0 : struct mlx5_sh_config *dev_conf = &priv->sh->config;
14965 : 0 : struct rte_flow *flow = dev_flow->flow;
14966 : 0 : struct mlx5_flow_handle *handle = dev_flow->handle;
14967 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
14968 : : struct mlx5_flow_rss_desc *rss_desc;
14969 : : uint64_t action_flags = 0;
14970 : 0 : struct mlx5_flow_dv_matcher matcher = {
14971 : : .mask = {
14972 : : .size = sizeof(matcher.mask.buf),
14973 : : },
14974 : : };
14975 : : int actions_n = 0;
14976 : : bool actions_end = false;
14977 : : union {
14978 : : struct mlx5_flow_dv_modify_hdr_resource res;
14979 : : uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
14980 : : sizeof(struct mlx5_modification_cmd) *
14981 : : (MLX5_MAX_MODIFY_NUM + 1)];
14982 : : } mhdr_dummy;
14983 : : struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
14984 : : const struct rte_flow_action_count *count = NULL;
14985 : : const struct rte_flow_action_age *non_shared_age = NULL;
14986 : 0 : union flow_dv_attr flow_attr = { .attr = 0 };
14987 : : uint32_t tag_be;
14988 : : union mlx5_flow_tbl_key tbl_key;
14989 : : uint32_t modify_action_position = UINT32_MAX;
14990 : 0 : struct rte_vlan_hdr vlan = { 0 };
14991 : : struct mlx5_flow_dv_dest_array_resource mdest_res;
14992 : : struct mlx5_flow_dv_sample_resource sample_res;
14993 : 0 : void *sample_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
14994 : : const struct rte_flow_action_sample *sample = NULL;
14995 : : struct mlx5_flow_sub_actions_list *sample_act;
14996 : : uint32_t sample_act_pos = UINT32_MAX;
14997 : : uint32_t age_act_pos = UINT32_MAX;
14998 : : uint32_t ipv6_tc_off = 0;
14999 : 0 : uint32_t num_of_dest = 0;
15000 : : int tmp_actions_n = 0;
15001 : : uint32_t table;
15002 : : int ret = 0;
15003 : : const struct mlx5_flow_tunnel *tunnel = NULL;
15004 : 0 : struct flow_grp_info grp_info = {
15005 : 0 : .external = !!dev_flow->external,
15006 : 0 : .transfer = !!attr->transfer,
15007 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
15008 : 0 : .skip_scale = dev_flow->skip_scale &
15009 : : (1 << MLX5_SCALE_FLOW_GROUP_BIT),
15010 : : .std_tbl_fix = true,
15011 : : };
15012 : :
15013 [ # # ]: 0 : if (!wks)
15014 : 0 : return rte_flow_error_set(error, ENOMEM,
15015 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15016 : : NULL,
15017 : : "failed to push flow workspace");
15018 [ # # ]: 0 : rss_desc = &wks->rss_desc;
15019 : : memset(&mdest_res, 0, sizeof(struct mlx5_flow_dv_dest_array_resource));
15020 : : memset(&sample_res, 0, sizeof(struct mlx5_flow_dv_sample_resource));
15021 [ # # ]: 0 : mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
15022 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
15023 : : /* update normal path action resource into last index of array */
15024 : : sample_act = &mdest_res.sample_act[MLX5_MAX_DEST_NUM - 1];
15025 [ # # ]: 0 : if (is_tunnel_offload_active(dev)) {
15026 [ # # ]: 0 : if (dev_flow->tunnel) {
15027 [ # # ]: 0 : RTE_VERIFY(dev_flow->tof_type ==
15028 : : MLX5_TUNNEL_OFFLOAD_MISS_RULE);
15029 : : tunnel = dev_flow->tunnel;
15030 : : } else {
15031 : 0 : tunnel = mlx5_get_tof(items, actions,
15032 : : &dev_flow->tof_type);
15033 : 0 : dev_flow->tunnel = tunnel;
15034 : : }
15035 [ # # ]: 0 : grp_info.std_tbl_fix = tunnel_use_standard_attr_group_translate
15036 : : (dev, attr, tunnel, dev_flow->tof_type);
15037 : : }
15038 : 0 : mhdr_res->ft_type = attr->egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
15039 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
15040 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel, attr->group, &table,
15041 : : &grp_info, error);
15042 [ # # ]: 0 : if (ret)
15043 : : return ret;
15044 : 0 : dev_flow->dv.group = table;
15045 [ # # ]: 0 : if (attr->transfer)
15046 : 0 : mhdr_res->ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
15047 : : /* number of actions must be set to 0 in case of dirty stack. */
15048 : 0 : mhdr_res->actions_num = 0;
15049 [ # # ]: 0 : if (is_flow_tunnel_match_rule(dev_flow->tof_type)) {
15050 : : /*
15051 : : * do not add decap action if match rule drops packet
15052 : : * HW rejects rules with decap & drop
15053 : : *
15054 : : * if tunnel match rule was inserted before matching tunnel set
15055 : : * rule flow table used in the match rule must be registered.
15056 : : * current implementation handles that in the
15057 : : * flow_dv_match_register() at the function end.
15058 : : */
15059 : : bool add_decap = true;
15060 : : const struct rte_flow_action *ptr = actions;
15061 : :
15062 [ # # ]: 0 : for (; ptr->type != RTE_FLOW_ACTION_TYPE_END; ptr++) {
15063 [ # # ]: 0 : if (ptr->type == RTE_FLOW_ACTION_TYPE_DROP) {
15064 : : add_decap = false;
15065 : : break;
15066 : : }
15067 : : }
15068 [ # # ]: 0 : if (add_decap) {
15069 [ # # ]: 0 : if (flow_dv_create_action_l2_decap(dev, dev_flow,
15070 : 0 : attr->transfer,
15071 : : error))
15072 : 0 : return -rte_errno;
15073 : 0 : dev_flow->dv.actions[actions_n++] =
15074 : 0 : dev_flow->dv.encap_decap->action;
15075 : : action_flags |= MLX5_FLOW_ACTION_DECAP;
15076 : : }
15077 : : }
15078 [ # # ]: 0 : for (; !actions_end ; actions++) {
15079 : : const struct rte_flow_action_queue *queue;
15080 : : const struct rte_flow_action_rss *rss;
15081 : : const struct rte_flow_action *action = actions;
15082 : : const uint8_t *rss_key;
15083 : : struct mlx5_flow_tbl_resource *tbl;
15084 : : struct mlx5_aso_age_action *age_act;
15085 : : struct mlx5_flow_counter *cnt_act;
15086 : 0 : uint32_t port_id = 0;
15087 : : struct mlx5_flow_dv_port_id_action_resource port_id_resource;
15088 : 0 : int action_type = actions->type;
15089 : : const struct rte_flow_action *found_action = NULL;
15090 : : uint32_t jump_group = 0;
15091 : : uint32_t owner_idx;
15092 : : struct mlx5_aso_ct_action *ct;
15093 : :
15094 : : if (!mlx5_flow_os_action_supported(action_type))
15095 : 0 : return rte_flow_error_set(error, ENOTSUP,
15096 : : RTE_FLOW_ERROR_TYPE_ACTION,
15097 : : actions,
15098 : : "action not supported");
15099 [ # # # # : 0 : switch (action_type) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
15100 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET:
15101 : 0 : action_flags |= MLX5_FLOW_ACTION_TUNNEL_SET;
15102 : 0 : break;
15103 : : case RTE_FLOW_ACTION_TYPE_VOID:
15104 : : break;
15105 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
15106 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
15107 [ # # ]: 0 : if (flow_dv_translate_action_port_id(dev, action,
15108 : : &port_id, error))
15109 : 0 : return -rte_errno;
15110 : 0 : port_id_resource.port_id = port_id;
15111 : : MLX5_ASSERT(!handle->rix_port_id_action);
15112 [ # # ]: 0 : if (flow_dv_port_id_action_resource_register
15113 : : (dev, &port_id_resource, dev_flow, error))
15114 : 0 : return -rte_errno;
15115 : 0 : dev_flow->dv.actions[actions_n++] =
15116 : 0 : dev_flow->dv.port_id_action->action;
15117 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_ID;
15118 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_PORT_ID;
15119 : 0 : sample_act->action_flags |= MLX5_FLOW_ACTION_PORT_ID;
15120 : 0 : num_of_dest++;
15121 : 0 : break;
15122 : 0 : case RTE_FLOW_ACTION_TYPE_FLAG:
15123 : 0 : action_flags |= MLX5_FLOW_ACTION_FLAG;
15124 : 0 : wks->mark = 1;
15125 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
15126 : 0 : struct rte_flow_action_mark mark = {
15127 : : .id = MLX5_FLOW_MARK_DEFAULT,
15128 : : };
15129 : :
15130 [ # # ]: 0 : if (flow_dv_convert_action_mark(dev, &mark,
15131 : : mhdr_res,
15132 : : error))
15133 : 0 : return -rte_errno;
15134 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
15135 : 0 : break;
15136 : : }
15137 : : tag_be = mlx5_flow_mark_set(MLX5_FLOW_MARK_DEFAULT);
15138 : : /*
15139 : : * Only one FLAG or MARK is supported per device flow
15140 : : * right now. So the pointer to the tag resource must be
15141 : : * zero before the register process.
15142 : : */
15143 : : MLX5_ASSERT(!handle->dvh.rix_tag);
15144 [ # # ]: 0 : if (flow_dv_tag_resource_register(dev, tag_be,
15145 : : dev_flow, error))
15146 : 0 : return -rte_errno;
15147 : : MLX5_ASSERT(dev_flow->dv.tag_resource);
15148 : 0 : dev_flow->dv.actions[actions_n++] =
15149 : 0 : dev_flow->dv.tag_resource->action;
15150 : 0 : break;
15151 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
15152 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK;
15153 : 0 : wks->mark = 1;
15154 [ # # ]: 0 : if (dev_conf->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
15155 : 0 : const struct rte_flow_action_mark *mark =
15156 : : (const struct rte_flow_action_mark *)
15157 : : actions->conf;
15158 : :
15159 [ # # ]: 0 : if (flow_dv_convert_action_mark(dev, mark,
15160 : : mhdr_res,
15161 : : error))
15162 : 0 : return -rte_errno;
15163 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK_EXT;
15164 : 0 : break;
15165 : : }
15166 : : /* Fall-through */
15167 : : case MLX5_RTE_FLOW_ACTION_TYPE_MARK:
15168 : : /* Legacy (non-extensive) MARK action. */
15169 : : tag_be = mlx5_flow_mark_set
15170 : : (((const struct rte_flow_action_mark *)
15171 [ # # ]: 0 : (actions->conf))->id);
15172 : : MLX5_ASSERT(!handle->dvh.rix_tag);
15173 [ # # ]: 0 : if (flow_dv_tag_resource_register(dev, tag_be,
15174 : : dev_flow, error))
15175 : 0 : return -rte_errno;
15176 : : MLX5_ASSERT(dev_flow->dv.tag_resource);
15177 : 0 : dev_flow->dv.actions[actions_n++] =
15178 : 0 : dev_flow->dv.tag_resource->action;
15179 : 0 : break;
15180 : 0 : case RTE_FLOW_ACTION_TYPE_SET_META:
15181 [ # # ]: 0 : if (flow_dv_convert_action_set_meta
15182 : : (dev, mhdr_res, attr,
15183 : : (const struct rte_flow_action_set_meta *)
15184 : 0 : actions->conf, error))
15185 : 0 : return -rte_errno;
15186 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_META;
15187 : 0 : break;
15188 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TAG:
15189 [ # # ]: 0 : if (flow_dv_convert_action_set_tag
15190 : : (dev, mhdr_res,
15191 : : (const struct rte_flow_action_set_tag *)
15192 : 0 : actions->conf, error))
15193 : 0 : return -rte_errno;
15194 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
15195 : 0 : break;
15196 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
15197 : 0 : action_flags |= MLX5_FLOW_ACTION_DROP;
15198 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_DROP;
15199 : 0 : break;
15200 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
15201 : 0 : queue = actions->conf;
15202 : 0 : rss_desc->queue_num = 1;
15203 : 0 : rss_desc->queue[0] = queue->index;
15204 : 0 : action_flags |= MLX5_FLOW_ACTION_QUEUE;
15205 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_QUEUE;
15206 : 0 : sample_act->action_flags |= MLX5_FLOW_ACTION_QUEUE;
15207 : 0 : num_of_dest++;
15208 : 0 : break;
15209 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
15210 : 0 : rss = actions->conf;
15211 : 0 : rss_desc->symmetric_hash_function =
15212 : 0 : MLX5_RSS_IS_SYMM(rss->func);
15213 : 0 : memcpy(rss_desc->queue, rss->queue,
15214 [ # # ]: 0 : rss->queue_num * sizeof(uint16_t));
15215 : 0 : rss_desc->queue_num = rss->queue_num;
15216 : : /* NULL RSS key indicates default RSS key. */
15217 [ # # ]: 0 : rss_key = !rss->key ? rss_hash_default_key : rss->key;
15218 [ # # ]: 0 : memcpy(rss_desc->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
15219 : : /*
15220 : : * rss->level and rss.types should be set in advance
15221 : : * when expanding items for RSS.
15222 : : */
15223 : 0 : action_flags |= MLX5_FLOW_ACTION_RSS;
15224 : 0 : dev_flow->handle->fate_action = rss_desc->shared_rss ?
15225 [ # # ]: 0 : MLX5_FLOW_FATE_SHARED_RSS :
15226 : : MLX5_FLOW_FATE_QUEUE;
15227 : 0 : break;
15228 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_AGE:
15229 : 0 : owner_idx = (uint32_t)(uintptr_t)action->conf;
15230 : 0 : age_act = flow_aso_age_get_by_idx(dev, owner_idx);
15231 [ # # ]: 0 : if (flow->age == 0) {
15232 : 0 : flow->age = owner_idx;
15233 : 0 : rte_atomic_fetch_add_explicit(&age_act->refcnt, 1,
15234 : : rte_memory_order_relaxed);
15235 : : }
15236 : 0 : age_act_pos = actions_n++;
15237 : 0 : action_flags |= MLX5_FLOW_ACTION_AGE;
15238 : 0 : break;
15239 : 0 : case RTE_FLOW_ACTION_TYPE_SEND_TO_KERNEL:
15240 : 0 : dev_flow->dv.actions[actions_n] =
15241 : 0 : flow_dv_translate_action_send_to_kernel(dev, attr,
15242 : : error);
15243 [ # # ]: 0 : if (!dev_flow->dv.actions[actions_n])
15244 : 0 : return -rte_errno;
15245 : 0 : actions_n++;
15246 : 0 : action_flags |= MLX5_FLOW_ACTION_SEND_TO_KERNEL;
15247 : 0 : dev_flow->handle->fate_action =
15248 : : MLX5_FLOW_FATE_SEND_TO_KERNEL;
15249 : 0 : break;
15250 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
15251 : 0 : non_shared_age = action->conf;
15252 : 0 : age_act_pos = actions_n++;
15253 : 0 : action_flags |= MLX5_FLOW_ACTION_AGE;
15254 : 0 : break;
15255 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
15256 [ # # ]: 0 : owner_idx = (uint32_t)(uintptr_t)action->conf;
15257 : : cnt_act = flow_dv_counter_get_by_idx(dev, owner_idx,
15258 : : NULL);
15259 : : MLX5_ASSERT(cnt_act != NULL);
15260 : : /**
15261 : : * When creating meter drop flow in drop table, the
15262 : : * counter should not overwrite the rte flow counter.
15263 : : */
15264 [ # # ]: 0 : if (attr->group == MLX5_FLOW_TABLE_LEVEL_METER &&
15265 [ # # ]: 0 : dev_flow->dv.table_id == MLX5_MTR_TABLE_ID_DROP) {
15266 : 0 : dev_flow->dv.actions[actions_n++] =
15267 : 0 : cnt_act->action;
15268 : : } else {
15269 [ # # ]: 0 : if (flow->counter == 0) {
15270 : 0 : flow->counter = owner_idx;
15271 : 0 : rte_atomic_fetch_add_explicit
15272 : : (&cnt_act->shared_info.refcnt,
15273 : : 1, rte_memory_order_relaxed);
15274 : : }
15275 : : /* Save information first, will apply later. */
15276 : 0 : action_flags |= MLX5_FLOW_ACTION_COUNT;
15277 : : }
15278 : : break;
15279 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
15280 [ # # ]: 0 : if (!priv->sh->cdev->config.devx) {
15281 : 0 : return rte_flow_error_set
15282 : : (error, ENOTSUP,
15283 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
15284 : : NULL,
15285 : : "count action not supported");
15286 : : }
15287 : : /* Save information first, will apply later. */
15288 : 0 : count = action->conf;
15289 : 0 : action_flags |= MLX5_FLOW_ACTION_COUNT;
15290 : 0 : break;
15291 : 0 : case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
15292 : 0 : dev_flow->dv.actions[actions_n++] =
15293 : 0 : priv->sh->pop_vlan_action;
15294 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_POP_VLAN;
15295 : 0 : break;
15296 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
15297 [ # # ]: 0 : if (!(action_flags &
15298 : : MLX5_FLOW_ACTION_OF_SET_VLAN_VID))
15299 : 0 : flow_dev_get_vlan_info_from_items(items, &vlan);
15300 [ # # ]: 0 : vlan.eth_proto = rte_be_to_cpu_16
15301 : : ((((const struct rte_flow_action_of_push_vlan *)
15302 : : actions->conf)->ethertype));
15303 : 0 : found_action = mlx5_flow_find_action
15304 : : (actions + 1,
15305 : : RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID);
15306 [ # # ]: 0 : if (found_action)
15307 : 0 : mlx5_update_vlan_vid_pcp(found_action, &vlan);
15308 : 0 : found_action = mlx5_flow_find_action
15309 : : (actions + 1,
15310 : : RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP);
15311 [ # # ]: 0 : if (found_action)
15312 : 0 : mlx5_update_vlan_vid_pcp(found_action, &vlan);
15313 [ # # ]: 0 : if (flow_dv_create_action_push_vlan
15314 : : (dev, attr, &vlan, dev_flow, error))
15315 : 0 : return -rte_errno;
15316 : 0 : dev_flow->dv.actions[actions_n++] =
15317 : 0 : dev_flow->dv.push_vlan_res->action;
15318 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
15319 : 0 : break;
15320 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
15321 : : /* of_vlan_push action handled this action */
15322 : : MLX5_ASSERT(action_flags &
15323 : : MLX5_FLOW_ACTION_OF_PUSH_VLAN);
15324 : : break;
15325 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
15326 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
15327 : : break;
15328 : 0 : flow_dev_get_vlan_info_from_items(items, &vlan);
15329 : 0 : mlx5_update_vlan_vid_pcp(actions, &vlan);
15330 : : /* If no VLAN push - this is a modify header action */
15331 [ # # ]: 0 : if (flow_dv_convert_action_modify_vlan_vid
15332 : : (mhdr_res, actions, error))
15333 : 0 : return -rte_errno;
15334 : 0 : action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID;
15335 : 0 : break;
15336 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
15337 : : case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
15338 [ # # ]: 0 : if (flow_dv_create_action_l2_encap(dev, actions,
15339 : : dev_flow,
15340 : 0 : attr->transfer,
15341 : : error))
15342 : 0 : return -rte_errno;
15343 : 0 : dev_flow->dv.actions[actions_n++] =
15344 : 0 : dev_flow->dv.encap_decap->action;
15345 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
15346 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
15347 : 0 : sample_act->action_flags |=
15348 : : MLX5_FLOW_ACTION_ENCAP;
15349 : : break;
15350 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
15351 : : case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
15352 [ # # ]: 0 : if (flow_dv_create_action_l2_decap(dev, dev_flow,
15353 : 0 : attr->transfer,
15354 : : error))
15355 : 0 : return -rte_errno;
15356 : 0 : dev_flow->dv.actions[actions_n++] =
15357 : 0 : dev_flow->dv.encap_decap->action;
15358 : 0 : action_flags |= MLX5_FLOW_ACTION_DECAP;
15359 : 0 : break;
15360 : 0 : case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
15361 : : /* Handle encap with preceding decap. */
15362 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_DECAP) {
15363 [ # # ]: 0 : if (flow_dv_create_action_raw_encap
15364 : : (dev, actions, dev_flow, attr, error))
15365 : 0 : return -rte_errno;
15366 : 0 : dev_flow->dv.actions[actions_n++] =
15367 : 0 : dev_flow->dv.encap_decap->action;
15368 : : } else {
15369 : : /* Handle encap without preceding decap. */
15370 [ # # ]: 0 : if (flow_dv_create_action_l2_encap
15371 : 0 : (dev, actions, dev_flow, attr->transfer,
15372 : : error))
15373 : 0 : return -rte_errno;
15374 : 0 : dev_flow->dv.actions[actions_n++] =
15375 : 0 : dev_flow->dv.encap_decap->action;
15376 : : }
15377 : 0 : action_flags |= MLX5_FLOW_ACTION_ENCAP;
15378 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE)
15379 : 0 : sample_act->action_flags |=
15380 : : MLX5_FLOW_ACTION_ENCAP;
15381 : : break;
15382 : : case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
15383 [ # # ]: 0 : while ((++action)->type == RTE_FLOW_ACTION_TYPE_VOID)
15384 : : ;
15385 [ # # ]: 0 : if (action->type != RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
15386 [ # # ]: 0 : if (flow_dv_create_action_l2_decap
15387 : 0 : (dev, dev_flow, attr->transfer, error))
15388 : 0 : return -rte_errno;
15389 : 0 : dev_flow->dv.actions[actions_n++] =
15390 : 0 : dev_flow->dv.encap_decap->action;
15391 : : }
15392 : : /* If decap is followed by encap, handle it at encap. */
15393 : 0 : action_flags |= MLX5_FLOW_ACTION_DECAP;
15394 : 0 : break;
15395 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_JUMP:
15396 : 0 : dev_flow->dv.actions[actions_n++] =
15397 : 0 : (void *)(uintptr_t)action->conf;
15398 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP;
15399 : 0 : break;
15400 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
15401 : 0 : jump_group = ((const struct rte_flow_action_jump *)
15402 : 0 : action->conf)->group;
15403 : 0 : grp_info.std_tbl_fix = 0;
15404 [ # # ]: 0 : if (dev_flow->skip_scale &
15405 : : (1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT))
15406 : 0 : grp_info.skip_scale = 1;
15407 : : else
15408 : 0 : grp_info.skip_scale = 0;
15409 : 0 : ret = mlx5_flow_group_to_table(dev, tunnel,
15410 : : jump_group,
15411 : : &table,
15412 : : &grp_info, error);
15413 [ # # ]: 0 : if (ret)
15414 : 0 : return ret;
15415 : 0 : tbl = flow_dv_tbl_resource_get(dev, table, attr->egress,
15416 : 0 : attr->transfer,
15417 : 0 : !!dev_flow->external,
15418 : : tunnel, jump_group, 0,
15419 : : 0, error);
15420 [ # # ]: 0 : if (!tbl)
15421 : 0 : return rte_flow_error_set
15422 : 0 : (error, errno,
15423 : : RTE_FLOW_ERROR_TYPE_ACTION,
15424 : : NULL,
15425 : : "cannot create jump action.");
15426 : : if (flow_dv_jump_tbl_resource_register
15427 : : (dev, tbl, dev_flow, error)) {
15428 : : flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
15429 : : return rte_flow_error_set
15430 : : (error, errno,
15431 : : RTE_FLOW_ERROR_TYPE_ACTION,
15432 : : NULL,
15433 : : "cannot create jump action.");
15434 : : }
15435 : 0 : dev_flow->dv.actions[actions_n++] =
15436 : 0 : dev_flow->dv.jump->action;
15437 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP;
15438 : 0 : dev_flow->handle->fate_action = MLX5_FLOW_FATE_JUMP;
15439 : 0 : sample_act->action_flags |= MLX5_FLOW_ACTION_JUMP;
15440 : 0 : num_of_dest++;
15441 : 0 : break;
15442 : 0 : case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
15443 : : case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
15444 [ # # ]: 0 : if (flow_dv_convert_action_modify_mac
15445 : : (mhdr_res, actions, error))
15446 : 0 : return -rte_errno;
15447 : 0 : action_flags |= actions->type ==
15448 : : RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
15449 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_MAC_SRC :
15450 : : MLX5_FLOW_ACTION_SET_MAC_DST;
15451 : 0 : break;
15452 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
15453 : : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
15454 [ # # ]: 0 : if (flow_dv_convert_action_modify_ipv4
15455 : : (mhdr_res, actions, error))
15456 : 0 : return -rte_errno;
15457 : 0 : action_flags |= actions->type ==
15458 : : RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ?
15459 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_IPV4_SRC :
15460 : : MLX5_FLOW_ACTION_SET_IPV4_DST;
15461 : 0 : break;
15462 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
15463 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
15464 [ # # ]: 0 : if (flow_dv_convert_action_modify_ipv6
15465 : : (mhdr_res, actions, error))
15466 : 0 : return -rte_errno;
15467 : 0 : action_flags |= actions->type ==
15468 : : RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ?
15469 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_IPV6_SRC :
15470 : : MLX5_FLOW_ACTION_SET_IPV6_DST;
15471 : 0 : break;
15472 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
15473 : : case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
15474 [ # # ]: 0 : if (flow_dv_convert_action_modify_tp
15475 : : (mhdr_res, actions, items,
15476 : 0 : &flow_attr, dev_flow, !!(action_flags &
15477 : : MLX5_FLOW_ACTION_DECAP), error))
15478 : 0 : return -rte_errno;
15479 : 0 : action_flags |= actions->type ==
15480 : : RTE_FLOW_ACTION_TYPE_SET_TP_SRC ?
15481 [ # # ]: 0 : MLX5_FLOW_ACTION_SET_TP_SRC :
15482 : : MLX5_FLOW_ACTION_SET_TP_DST;
15483 : 0 : break;
15484 : 0 : case RTE_FLOW_ACTION_TYPE_DEC_TTL:
15485 [ # # ]: 0 : if (flow_dv_convert_action_modify_dec_ttl
15486 : : (mhdr_res, items, &flow_attr, dev_flow,
15487 : 0 : !!(action_flags &
15488 : : MLX5_FLOW_ACTION_DECAP), error))
15489 : 0 : return -rte_errno;
15490 : 0 : action_flags |= MLX5_FLOW_ACTION_DEC_TTL;
15491 : 0 : break;
15492 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TTL:
15493 [ # # ]: 0 : if (flow_dv_convert_action_modify_ttl
15494 : : (mhdr_res, actions, items, &flow_attr,
15495 : 0 : dev_flow, !!(action_flags &
15496 : : MLX5_FLOW_ACTION_DECAP), error))
15497 : 0 : return -rte_errno;
15498 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TTL;
15499 : 0 : break;
15500 : 0 : case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
15501 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
15502 [ # # ]: 0 : if (flow_dv_convert_action_modify_tcp_seq
15503 : : (mhdr_res, actions, error))
15504 : 0 : return -rte_errno;
15505 : 0 : action_flags |= actions->type ==
15506 : : RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ ?
15507 [ # # ]: 0 : MLX5_FLOW_ACTION_INC_TCP_SEQ :
15508 : : MLX5_FLOW_ACTION_DEC_TCP_SEQ;
15509 : 0 : break;
15510 : :
15511 : 0 : case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
15512 : : case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
15513 [ # # ]: 0 : if (flow_dv_convert_action_modify_tcp_ack
15514 : : (mhdr_res, actions, error))
15515 : 0 : return -rte_errno;
15516 : 0 : action_flags |= actions->type ==
15517 : : RTE_FLOW_ACTION_TYPE_INC_TCP_ACK ?
15518 [ # # ]: 0 : MLX5_FLOW_ACTION_INC_TCP_ACK :
15519 : : MLX5_FLOW_ACTION_DEC_TCP_ACK;
15520 : 0 : break;
15521 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_TAG:
15522 [ # # ]: 0 : if (flow_dv_convert_action_set_reg
15523 : : (mhdr_res, actions, error))
15524 : 0 : return -rte_errno;
15525 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
15526 : 0 : break;
15527 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG:
15528 [ # # ]: 0 : if (flow_dv_convert_action_copy_mreg
15529 : : (dev, mhdr_res, actions, error))
15530 : 0 : return -rte_errno;
15531 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
15532 : 0 : break;
15533 : 0 : case MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS:
15534 : 0 : action_flags |= MLX5_FLOW_ACTION_DEFAULT_MISS;
15535 : 0 : dev_flow->handle->fate_action =
15536 : : MLX5_FLOW_FATE_DEFAULT_MISS;
15537 : 0 : break;
15538 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
15539 [ # # ]: 0 : if (!wks->fm)
15540 : 0 : return rte_flow_error_set(error, rte_errno,
15541 : : RTE_FLOW_ERROR_TYPE_ACTION,
15542 : : NULL, "Failed to get meter in flow.");
15543 : : /* Set the meter action. */
15544 : 0 : dev_flow->dv.actions[actions_n++] =
15545 : 0 : wks->fm->meter_action_g;
15546 : 0 : action_flags |= MLX5_FLOW_ACTION_METER;
15547 : 0 : break;
15548 : 0 : case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
15549 [ # # ]: 0 : if (flow_dv_convert_action_modify_ipv4_dscp(mhdr_res,
15550 : : actions, error))
15551 : 0 : return -rte_errno;
15552 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_IPV4_DSCP;
15553 : 0 : break;
15554 : : case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
15555 [ # # ]: 0 : if (mlx5_dv_modify_ipv6_traffic_class_supported(priv))
15556 : : ipv6_tc_off = MLX5_IPV6_HDR_DSCP_SHIFT;
15557 : : else
15558 : : ipv6_tc_off = 0;
15559 [ # # ]: 0 : if (flow_dv_convert_action_modify_ipv6_dscp(mhdr_res,
15560 : : actions, ipv6_tc_off, error))
15561 : 0 : return -rte_errno;
15562 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_IPV6_DSCP;
15563 : 0 : break;
15564 : 0 : case RTE_FLOW_ACTION_TYPE_SAMPLE:
15565 : 0 : sample_act_pos = actions_n;
15566 : 0 : sample = (const struct rte_flow_action_sample *)
15567 : : action->conf;
15568 : 0 : actions_n++;
15569 : 0 : action_flags |= MLX5_FLOW_ACTION_SAMPLE;
15570 : : /* put encap action into group if work with port id */
15571 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_ENCAP) &&
15572 : : (action_flags & MLX5_FLOW_ACTION_PORT_ID))
15573 : 0 : sample_act->action_flags |=
15574 : : MLX5_FLOW_ACTION_ENCAP;
15575 : : break;
15576 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
15577 [ # # ]: 0 : if (flow_dv_convert_action_modify_field
15578 : : (dev, mhdr_res, actions, attr, error))
15579 : 0 : return -rte_errno;
15580 : 0 : action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
15581 : 0 : break;
15582 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
15583 : 0 : owner_idx = (uint32_t)(uintptr_t)action->conf;
15584 : 0 : ct = flow_aso_ct_get_by_idx(dev, owner_idx);
15585 [ # # ]: 0 : if (!ct)
15586 : 0 : return rte_flow_error_set(error, EINVAL,
15587 : : RTE_FLOW_ERROR_TYPE_ACTION,
15588 : : NULL,
15589 : : "Failed to get CT object.");
15590 [ # # ]: 0 : if (mlx5_aso_ct_available(priv->sh, MLX5_HW_INV_QUEUE, ct))
15591 : 0 : return rte_flow_error_set(error, rte_errno,
15592 : : RTE_FLOW_ERROR_TYPE_ACTION,
15593 : : NULL,
15594 : : "CT is unavailable.");
15595 [ # # ]: 0 : if (ct->is_original)
15596 : 0 : dev_flow->dv.actions[actions_n] =
15597 : 0 : ct->dr_action_orig;
15598 : : else
15599 : 0 : dev_flow->dv.actions[actions_n] =
15600 : 0 : ct->dr_action_rply;
15601 [ # # ]: 0 : if (flow->ct == 0) {
15602 : 0 : flow->indirect_type =
15603 : : MLX5_INDIRECT_ACTION_TYPE_CT;
15604 : 0 : flow->ct = owner_idx;
15605 : 0 : rte_atomic_fetch_add_explicit(&ct->refcnt, 1,
15606 : : rte_memory_order_relaxed);
15607 : : }
15608 : 0 : actions_n++;
15609 : 0 : action_flags |= MLX5_FLOW_ACTION_CT;
15610 : 0 : break;
15611 : 0 : case RTE_FLOW_ACTION_TYPE_END:
15612 : : actions_end = true;
15613 [ # # ]: 0 : if (mhdr_res->actions_num) {
15614 : : /* create modify action if needed. */
15615 [ # # ]: 0 : if (flow_dv_modify_hdr_resource_register
15616 : : (dev, mhdr_res, dev_flow, error))
15617 : 0 : return -rte_errno;
15618 : 0 : dev_flow->dv.actions[modify_action_position] =
15619 : 0 : handle->dvh.modify_hdr->action;
15620 : : }
15621 : : /*
15622 : : * Handle AGE and COUNT action by single HW counter
15623 : : * when they are not shared.
15624 : : */
15625 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_AGE) {
15626 [ # # # # ]: 0 : if ((non_shared_age && count) ||
15627 [ # # ]: 0 : !flow_hit_aso_supported(priv, !dev_flow->dv.group)) {
15628 : : /* Creates age by counters. */
15629 : 0 : cnt_act = flow_dv_prepare_counter
15630 : : (dev, dev_flow,
15631 : : flow, count,
15632 : : non_shared_age,
15633 : : error);
15634 [ # # ]: 0 : if (!cnt_act)
15635 : 0 : return -rte_errno;
15636 : 0 : dev_flow->dv.actions[age_act_pos] =
15637 : 0 : cnt_act->action;
15638 : 0 : break;
15639 : : }
15640 [ # # # # ]: 0 : if (!flow->age && non_shared_age) {
15641 : 0 : flow->age = flow_dv_aso_age_alloc
15642 : : (dev, error);
15643 [ # # ]: 0 : if (!flow->age)
15644 : 0 : return -rte_errno;
15645 : 0 : flow_dv_aso_age_params_init
15646 : : (dev, flow->age,
15647 : 0 : non_shared_age->context ?
15648 : : non_shared_age->context :
15649 : 0 : (void *)(uintptr_t)
15650 : 0 : (dev_flow->flow_idx),
15651 [ # # ]: 0 : non_shared_age->timeout);
15652 : : }
15653 : 0 : age_act = flow_aso_age_get_by_idx(dev,
15654 : : flow->age);
15655 : 0 : dev_flow->dv.actions[age_act_pos] =
15656 : 0 : age_act->dr_action;
15657 : : }
15658 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_COUNT) {
15659 : : /*
15660 : : * Create one count action, to be used
15661 : : * by all sub-flows.
15662 : : */
15663 : 0 : cnt_act = flow_dv_prepare_counter(dev, dev_flow,
15664 : : flow, count,
15665 : : NULL, error);
15666 [ # # ]: 0 : if (!cnt_act)
15667 : 0 : return -rte_errno;
15668 : 0 : dev_flow->dv.actions[actions_n++] =
15669 : 0 : cnt_act->action;
15670 : : }
15671 : : default:
15672 : : break;
15673 : : }
15674 [ # # # # ]: 0 : if (mhdr_res->actions_num &&
15675 : : modify_action_position == UINT32_MAX)
15676 : 0 : modify_action_position = actions_n++;
15677 : : }
15678 : 0 : dev_flow->act_flags = action_flags;
15679 : 0 : ret = flow_dv_translate_items_sws(dev, dev_flow, attr, items, &matcher,
15680 : : error);
15681 [ # # ]: 0 : if (ret)
15682 : 0 : return -rte_errno;
15683 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_RSS) {
15684 : 0 : dev_flow->symmetric_hash_function = rss_desc->symmetric_hash_function;
15685 : 0 : flow_dv_hashfields_set(dev_flow->handle->layers,
15686 : : rss_desc,
15687 : : &dev_flow->hash_fields);
15688 : : }
15689 : : /* If has RSS action in the sample action, the Sample/Mirror resource
15690 : : * should be registered after the hash filed be update.
15691 : : */
15692 [ # # ]: 0 : if (action_flags & MLX5_FLOW_ACTION_SAMPLE) {
15693 : 0 : ret = flow_dv_translate_action_sample(dev,
15694 : : sample,
15695 : : dev_flow, attr,
15696 : : &num_of_dest,
15697 : : sample_actions,
15698 : : &sample_res,
15699 : : error);
15700 [ # # ]: 0 : if (ret < 0)
15701 : : return ret;
15702 : 0 : ret = flow_dv_create_action_sample(dev,
15703 : : dev_flow,
15704 : : num_of_dest,
15705 : : &sample_res,
15706 : : &mdest_res,
15707 : : sample_actions,
15708 : : action_flags,
15709 : : error);
15710 [ # # ]: 0 : if (ret < 0)
15711 : 0 : return rte_flow_error_set
15712 : : (error, rte_errno,
15713 : : RTE_FLOW_ERROR_TYPE_ACTION,
15714 : : NULL,
15715 : : "cannot create sample action");
15716 [ # # ]: 0 : if (num_of_dest > 1) {
15717 : 0 : dev_flow->dv.actions[sample_act_pos] =
15718 : 0 : dev_flow->dv.dest_array_res->action;
15719 : : } else {
15720 : 0 : dev_flow->dv.actions[sample_act_pos] =
15721 : 0 : dev_flow->dv.sample_res->verbs_action;
15722 : : }
15723 : : }
15724 : : /*
15725 : : * For multiple destination (sample action with ratio=1), the encap
15726 : : * action and port id action will be combined into group action.
15727 : : * So need remove the original these actions in the flow and only
15728 : : * use the sample action instead of.
15729 : : */
15730 [ # # ]: 0 : if (num_of_dest > 1 &&
15731 [ # # # # ]: 0 : (sample_act->dr_port_id_action || sample_act->dr_jump_action)) {
15732 : : int i;
15733 : 0 : void *temp_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS] = {0};
15734 : :
15735 [ # # ]: 0 : for (i = 0; i < actions_n; i++) {
15736 [ # # ]: 0 : if ((sample_act->dr_encap_action &&
15737 : : sample_act->dr_encap_action ==
15738 [ # # # # ]: 0 : dev_flow->dv.actions[i]) ||
15739 : 0 : (sample_act->dr_port_id_action &&
15740 : : sample_act->dr_port_id_action ==
15741 [ # # ]: 0 : dev_flow->dv.actions[i]) ||
15742 [ # # ]: 0 : (sample_act->dr_jump_action &&
15743 : : sample_act->dr_jump_action ==
15744 [ # # ]: 0 : dev_flow->dv.actions[i]))
15745 : 0 : continue;
15746 : 0 : temp_actions[tmp_actions_n++] = dev_flow->dv.actions[i];
15747 : : }
15748 : 0 : memcpy((void *)dev_flow->dv.actions,
15749 : : (void *)temp_actions,
15750 : : tmp_actions_n * sizeof(void *));
15751 : : actions_n = tmp_actions_n;
15752 : : }
15753 : 0 : dev_flow->dv.actions_n = actions_n;
15754 [ # # ]: 0 : if (wks->skip_matcher_reg)
15755 : : return 0;
15756 : : /* Register matcher. */
15757 : 0 : matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
15758 : : matcher.mask.size);
15759 : 0 : matcher.priority = mlx5_get_matcher_priority(dev, attr,
15760 : 0 : matcher.priority,
15761 : 0 : dev_flow->external);
15762 : : /**
15763 : : * When creating meter drop flow in drop table, using original
15764 : : * 5-tuple match, the matcher priority should be lower than
15765 : : * mtr_id matcher.
15766 : : */
15767 [ # # ]: 0 : if (attr->group == MLX5_FLOW_TABLE_LEVEL_METER &&
15768 [ # # # # ]: 0 : dev_flow->dv.table_id == MLX5_MTR_TABLE_ID_DROP &&
15769 : : matcher.priority <= MLX5_REG_BITS)
15770 : 0 : matcher.priority += MLX5_REG_BITS;
15771 : : /* reserved field no needs to be set to 0 here. */
15772 : 0 : tbl_key.is_fdb = attr->transfer;
15773 : 0 : tbl_key.is_egress = attr->egress;
15774 : 0 : tbl_key.level = dev_flow->dv.group;
15775 : 0 : tbl_key.id = dev_flow->dv.table_id;
15776 [ # # ]: 0 : if (flow_dv_matcher_register(dev, &matcher, &tbl_key, dev_flow,
15777 : : tunnel, attr->group, error))
15778 : 0 : return -rte_errno;
15779 : : return 0;
15780 : : }
15781 : :
15782 : : /**
15783 : : * Set hash RX queue by hash fields (see enum ibv_rx_hash_fields)
15784 : : * and tunnel.
15785 : : *
15786 : : * @param[in, out] action
15787 : : * Shred RSS action holding hash RX queue objects.
15788 : : * @param[in] hash_fields
15789 : : * Defines combination of packet fields to participate in RX hash.
15790 : : * @param[in] tunnel
15791 : : * Tunnel type
15792 : : * @param[in] hrxq_idx
15793 : : * Hash RX queue index to set.
15794 : : *
15795 : : * @return
15796 : : * 0 on success, otherwise negative errno value.
15797 : : */
15798 : : static int
15799 : 0 : __flow_dv_action_rss_hrxq_set(struct mlx5_shared_action_rss *action,
15800 : : const uint64_t hash_fields,
15801 : : uint32_t hrxq_idx)
15802 : : {
15803 : : uint32_t *hrxqs = action->hrxq;
15804 : :
15805 [ # # # # : 0 : switch (hash_fields & ~IBV_RX_HASH_INNER) {
# # # # #
# # ]
15806 : 0 : case MLX5_RSS_HASH_IPV4:
15807 : : /* fall-through. */
15808 : : case MLX5_RSS_HASH_IPV4_DST_ONLY:
15809 : : /* fall-through. */
15810 : : case MLX5_RSS_HASH_IPV4_SRC_ONLY:
15811 : 0 : hrxqs[0] = hrxq_idx;
15812 : 0 : return 0;
15813 : 0 : case MLX5_RSS_HASH_IPV4_TCP:
15814 : : /* fall-through. */
15815 : : case MLX5_RSS_HASH_IPV4_TCP_DST_ONLY:
15816 : : /* fall-through. */
15817 : : case MLX5_RSS_HASH_IPV4_TCP_SRC_ONLY:
15818 : 0 : hrxqs[1] = hrxq_idx;
15819 : 0 : return 0;
15820 : 0 : case MLX5_RSS_HASH_IPV4_UDP:
15821 : : /* fall-through. */
15822 : : case MLX5_RSS_HASH_IPV4_UDP_DST_ONLY:
15823 : : /* fall-through. */
15824 : : case MLX5_RSS_HASH_IPV4_UDP_SRC_ONLY:
15825 : 0 : hrxqs[2] = hrxq_idx;
15826 : 0 : return 0;
15827 : 0 : case MLX5_RSS_HASH_IPV6:
15828 : : /* fall-through. */
15829 : : case MLX5_RSS_HASH_IPV6_DST_ONLY:
15830 : : /* fall-through. */
15831 : : case MLX5_RSS_HASH_IPV6_SRC_ONLY:
15832 : 0 : hrxqs[3] = hrxq_idx;
15833 : 0 : return 0;
15834 : 0 : case MLX5_RSS_HASH_IPV6_TCP:
15835 : : /* fall-through. */
15836 : : case MLX5_RSS_HASH_IPV6_TCP_DST_ONLY:
15837 : : /* fall-through. */
15838 : : case MLX5_RSS_HASH_IPV6_TCP_SRC_ONLY:
15839 : 0 : hrxqs[4] = hrxq_idx;
15840 : 0 : return 0;
15841 : 0 : case MLX5_RSS_HASH_IPV6_UDP:
15842 : : /* fall-through. */
15843 : : case MLX5_RSS_HASH_IPV6_UDP_DST_ONLY:
15844 : : /* fall-through. */
15845 : : case MLX5_RSS_HASH_IPV6_UDP_SRC_ONLY:
15846 : 0 : hrxqs[5] = hrxq_idx;
15847 : 0 : return 0;
15848 : 0 : case MLX5_RSS_HASH_NONE:
15849 : 0 : hrxqs[6] = hrxq_idx;
15850 : 0 : return 0;
15851 : 0 : case MLX5_RSS_HASH_IPV4_ESP:
15852 : 0 : hrxqs[7] = hrxq_idx;
15853 : 0 : return 0;
15854 : 0 : case MLX5_RSS_HASH_IPV6_ESP:
15855 : 0 : hrxqs[8] = hrxq_idx;
15856 : 0 : return 0;
15857 : 0 : case MLX5_RSS_HASH_ESP_SPI:
15858 : 0 : hrxqs[9] = hrxq_idx;
15859 : 0 : return 0;
15860 : : default:
15861 : : return -1;
15862 : : }
15863 : : }
15864 : :
15865 : : /**
15866 : : * Look up for hash RX queue by hash fields (see enum ibv_rx_hash_fields)
15867 : : * and tunnel.
15868 : : *
15869 : : * @param[in] dev
15870 : : * Pointer to the Ethernet device structure.
15871 : : * @param[in] idx
15872 : : * Shared RSS action ID holding hash RX queue objects.
15873 : : * @param[in] hash_fields
15874 : : * Defines combination of packet fields to participate in RX hash.
15875 : : * @param[in] tunnel
15876 : : * Tunnel type
15877 : : *
15878 : : * @return
15879 : : * Valid hash RX queue index, otherwise 0.
15880 : : */
15881 : : uint32_t
15882 : 0 : flow_dv_action_rss_hrxq_lookup(struct rte_eth_dev *dev, uint32_t idx,
15883 : : const uint64_t hash_fields)
15884 : : {
15885 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15886 : : struct mlx5_shared_action_rss *shared_rss =
15887 : 0 : mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
15888 : : const uint32_t *hrxqs = shared_rss->hrxq;
15889 : :
15890 [ # # # # : 0 : switch (hash_fields & ~IBV_RX_HASH_INNER) {
# # # # #
# # ]
15891 : 0 : case MLX5_RSS_HASH_IPV4:
15892 : : /* fall-through. */
15893 : : case MLX5_RSS_HASH_IPV4_DST_ONLY:
15894 : : /* fall-through. */
15895 : : case MLX5_RSS_HASH_IPV4_SRC_ONLY:
15896 : 0 : return hrxqs[0];
15897 : 0 : case MLX5_RSS_HASH_IPV4_TCP:
15898 : : /* fall-through. */
15899 : : case MLX5_RSS_HASH_IPV4_TCP_DST_ONLY:
15900 : : /* fall-through. */
15901 : : case MLX5_RSS_HASH_IPV4_TCP_SRC_ONLY:
15902 : 0 : return hrxqs[1];
15903 : 0 : case MLX5_RSS_HASH_IPV4_UDP:
15904 : : /* fall-through. */
15905 : : case MLX5_RSS_HASH_IPV4_UDP_DST_ONLY:
15906 : : /* fall-through. */
15907 : : case MLX5_RSS_HASH_IPV4_UDP_SRC_ONLY:
15908 : 0 : return hrxqs[2];
15909 : 0 : case MLX5_RSS_HASH_IPV6:
15910 : : /* fall-through. */
15911 : : case MLX5_RSS_HASH_IPV6_DST_ONLY:
15912 : : /* fall-through. */
15913 : : case MLX5_RSS_HASH_IPV6_SRC_ONLY:
15914 : 0 : return hrxqs[3];
15915 : 0 : case MLX5_RSS_HASH_IPV6_TCP:
15916 : : /* fall-through. */
15917 : : case MLX5_RSS_HASH_IPV6_TCP_DST_ONLY:
15918 : : /* fall-through. */
15919 : : case MLX5_RSS_HASH_IPV6_TCP_SRC_ONLY:
15920 : 0 : return hrxqs[4];
15921 : 0 : case MLX5_RSS_HASH_IPV6_UDP:
15922 : : /* fall-through. */
15923 : : case MLX5_RSS_HASH_IPV6_UDP_DST_ONLY:
15924 : : /* fall-through. */
15925 : : case MLX5_RSS_HASH_IPV6_UDP_SRC_ONLY:
15926 : 0 : return hrxqs[5];
15927 : 0 : case MLX5_RSS_HASH_NONE:
15928 : 0 : return hrxqs[6];
15929 : 0 : case MLX5_RSS_HASH_IPV4_ESP:
15930 : 0 : return hrxqs[7];
15931 : 0 : case MLX5_RSS_HASH_IPV6_ESP:
15932 : 0 : return hrxqs[8];
15933 : 0 : case MLX5_RSS_HASH_ESP_SPI:
15934 : 0 : return hrxqs[9];
15935 : : default:
15936 : : return 0;
15937 : : }
15938 : :
15939 : : }
15940 : :
15941 : : /**
15942 : : * Apply the flow to the NIC, lock free,
15943 : : * (mutex should be acquired by caller).
15944 : : *
15945 : : * @param[in] dev
15946 : : * Pointer to the Ethernet device structure.
15947 : : * @param[in, out] flow
15948 : : * Pointer to flow structure.
15949 : : * @param[out] error
15950 : : * Pointer to error structure.
15951 : : *
15952 : : * @return
15953 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
15954 : : */
15955 : : static int
15956 : 0 : flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
15957 : : struct rte_flow_error *error)
15958 : : {
15959 : : struct mlx5_flow_dv_workspace *dv;
15960 : : struct mlx5_flow_handle *dh;
15961 : : struct mlx5_flow_handle_dv *dv_h;
15962 : : struct mlx5_flow *dev_flow;
15963 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
15964 : : uint32_t handle_idx;
15965 : : int n;
15966 : : int err;
15967 : : int idx;
15968 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
15969 : 0 : struct mlx5_flow_rss_desc *rss_desc = &wks->rss_desc;
15970 : : uint8_t misc_mask;
15971 : :
15972 : : MLX5_ASSERT(wks);
15973 [ # # ]: 0 : for (idx = wks->flow_idx - 1; idx >= 0; idx--) {
15974 : 0 : dev_flow = &wks->flows[idx];
15975 : : dv = &dev_flow->dv;
15976 : 0 : dh = dev_flow->handle;
15977 : : dv_h = &dh->dvh;
15978 : 0 : n = dv->actions_n;
15979 [ # # ]: 0 : if (dh->fate_action == MLX5_FLOW_FATE_DROP) {
15980 [ # # ]: 0 : if (dv->transfer) {
15981 : : MLX5_ASSERT(priv->sh->dr_drop_action);
15982 : 0 : dv->actions[n++] = priv->sh->dr_drop_action;
15983 : : } else {
15984 : : #ifdef HAVE_MLX5DV_DR
15985 : : /* DR supports drop action placeholder. */
15986 : : MLX5_ASSERT(priv->sh->dr_drop_action);
15987 : 0 : dv->actions[n++] = dv->group ?
15988 [ # # ]: 0 : priv->sh->dr_drop_action :
15989 : : priv->root_drop_action;
15990 : : #else
15991 : : /* For DV we use the explicit drop queue. */
15992 : : MLX5_ASSERT(priv->drop_queue.hrxq);
15993 : : dv->actions[n++] =
15994 : : priv->drop_queue.hrxq->action;
15995 : : #endif
15996 : : }
15997 [ # # ]: 0 : } else if ((dh->fate_action == MLX5_FLOW_FATE_QUEUE &&
15998 [ # # # # ]: 0 : !dv_h->rix_sample && !dv_h->rix_dest_array)) {
15999 : : struct mlx5_hrxq *hrxq;
16000 : : uint32_t hrxq_idx;
16001 : :
16002 : 0 : hrxq = flow_dv_hrxq_prepare(dev, dev_flow, rss_desc,
16003 : : &hrxq_idx);
16004 [ # # ]: 0 : if (!hrxq) {
16005 : 0 : rte_flow_error_set
16006 : : (error, rte_errno,
16007 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16008 : : "cannot get hash queue");
16009 : 0 : goto error;
16010 : : }
16011 : 0 : dh->rix_hrxq = hrxq_idx;
16012 : 0 : dv->actions[n++] = hrxq->action;
16013 [ # # ]: 0 : } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
16014 : : struct mlx5_hrxq *hrxq = NULL;
16015 : : uint32_t hrxq_idx;
16016 : :
16017 : 0 : hrxq_idx = flow_dv_action_rss_hrxq_lookup(dev,
16018 : : rss_desc->shared_rss,
16019 : : dev_flow->hash_fields);
16020 [ # # ]: 0 : if (hrxq_idx)
16021 : 0 : hrxq = mlx5_ipool_get
16022 : 0 : (priv->sh->ipool[MLX5_IPOOL_HRXQ],
16023 : : hrxq_idx);
16024 [ # # ]: 0 : if (!hrxq) {
16025 : 0 : rte_flow_error_set
16026 : : (error, rte_errno,
16027 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16028 : : "cannot get hash queue");
16029 : 0 : goto error;
16030 : : }
16031 : 0 : dh->rix_srss = rss_desc->shared_rss;
16032 : 0 : dv->actions[n++] = hrxq->action;
16033 [ # # ]: 0 : } else if (dh->fate_action == MLX5_FLOW_FATE_DEFAULT_MISS) {
16034 [ # # ]: 0 : if (!priv->sh->default_miss_action) {
16035 : 0 : rte_flow_error_set
16036 : : (error, rte_errno,
16037 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16038 : : "default miss action not be created.");
16039 : 0 : goto error;
16040 : : }
16041 : 0 : dv->actions[n++] = priv->sh->default_miss_action;
16042 : : }
16043 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(dv_h->matcher->mask.buf);
16044 : : __flow_dv_adjust_buf_size(&dv->value.size, misc_mask);
16045 : 0 : err = mlx5_flow_os_create_flow(dv_h->matcher->matcher_object,
16046 : 0 : (void *)&dv->value, n,
16047 : 0 : dv->actions, &dh->drv_flow);
16048 : : if (err) {
16049 : 0 : rte_flow_error_set
16050 : 0 : (error, errno,
16051 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
16052 : : NULL,
16053 [ # # ]: 0 : (!priv->sh->config.allow_duplicate_pattern &&
16054 [ # # ]: 0 : errno == EEXIST) ?
16055 : : "duplicating pattern is not allowed" :
16056 : : "hardware refuses to create flow");
16057 : 0 : goto error;
16058 : : }
16059 [ # # ]: 0 : if (priv->vmwa_context &&
16060 [ # # # # ]: 0 : dh->vf_vlan.tag && !dh->vf_vlan.created) {
16061 : : /*
16062 : : * The rule contains the VLAN pattern.
16063 : : * For VF we are going to create VLAN
16064 : : * interface to make hypervisor set correct
16065 : : * e-Switch vport context.
16066 : : */
16067 : 0 : mlx5_vlan_vmwa_acquire(dev, &dh->vf_vlan);
16068 : : }
16069 : : }
16070 : : return 0;
16071 : 0 : error:
16072 : 0 : err = rte_errno; /* Save rte_errno before cleanup. */
16073 [ # # # # : 0 : SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
# # ]
16074 : : handle_idx, dh, next) {
16075 : : /* hrxq is union, don't clear it if the flag is not set. */
16076 [ # # # # ]: 0 : if (dh->fate_action == MLX5_FLOW_FATE_QUEUE && dh->rix_hrxq &&
16077 [ # # # # ]: 0 : !dh->dvh.rix_sample && !dh->dvh.rix_dest_array) {
16078 : 0 : mlx5_hrxq_release(dev, dh->rix_hrxq);
16079 : 0 : dh->rix_hrxq = 0;
16080 [ # # ]: 0 : } else if (dh->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
16081 : 0 : dh->rix_srss = 0;
16082 : : }
16083 [ # # # # ]: 0 : if (dh->vf_vlan.tag && dh->vf_vlan.created)
16084 : 0 : mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
16085 : : }
16086 : 0 : rte_errno = err; /* Restore rte_errno. */
16087 : 0 : return -rte_errno;
16088 : : }
16089 : :
16090 : : void
16091 : 0 : flow_matcher_remove_cb(void *tool_ctx __rte_unused,
16092 : : struct mlx5_list_entry *entry)
16093 : : {
16094 : : struct mlx5_flow_dv_matcher *resource = container_of(entry,
16095 : : typeof(*resource),
16096 : : entry);
16097 : : #ifdef HAVE_MLX5_HWS_SUPPORT
16098 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
16099 : :
16100 [ # # ]: 0 : if (sh->config.dv_flow_en == 2)
16101 : 0 : claim_zero(mlx5dr_bwc_matcher_destroy((struct mlx5dr_bwc_matcher *)
16102 : : resource->matcher_object));
16103 : : else
16104 : : #endif
16105 : 0 : claim_zero(mlx5_flow_os_destroy_flow_matcher(resource->matcher_object));
16106 : 0 : mlx5_free(resource);
16107 : 0 : }
16108 : :
16109 : : /**
16110 : : * Release the flow matcher.
16111 : : *
16112 : : * @param dev
16113 : : * Pointer to Ethernet device.
16114 : : * @param port_id
16115 : : * Index to port ID action resource.
16116 : : *
16117 : : * @return
16118 : : * 1 while a reference on it exists, 0 when freed.
16119 : : */
16120 : : static int
16121 : 0 : flow_dv_matcher_release(struct rte_eth_dev *dev,
16122 : : struct mlx5_flow_handle *handle)
16123 : : {
16124 : 0 : struct mlx5_flow_dv_matcher *matcher = handle->dvh.matcher;
16125 : 0 : struct mlx5_flow_tbl_data_entry *tbl = container_of(matcher->tbl,
16126 : : typeof(*tbl), tbl);
16127 : : int ret;
16128 : :
16129 : : MLX5_ASSERT(matcher->matcher_object);
16130 : 0 : ret = mlx5_list_unregister(tbl->matchers, &matcher->entry);
16131 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl->tbl);
16132 : 0 : return ret;
16133 : : }
16134 : :
16135 : : void
16136 : 0 : flow_encap_decap_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
16137 : : {
16138 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
16139 : : struct mlx5_flow_dv_encap_decap_resource *res =
16140 : : container_of(entry, typeof(*res), entry);
16141 : :
16142 : : #ifdef HAVE_MLX5_HWS_SUPPORT
16143 [ # # ]: 0 : if (sh->config.dv_flow_en == 2)
16144 : 0 : claim_zero(mlx5dr_action_destroy(res->action));
16145 : : else
16146 : : #endif
16147 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
16148 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], res->idx);
16149 : 0 : }
16150 : :
16151 : : /**
16152 : : * Release an encap/decap resource.
16153 : : *
16154 : : * @param dev
16155 : : * Pointer to Ethernet device.
16156 : : * @param encap_decap_idx
16157 : : * Index of encap decap resource.
16158 : : *
16159 : : * @return
16160 : : * 1 while a reference on it exists, 0 when freed.
16161 : : */
16162 : : int
16163 : 0 : flow_encap_decap_resource_release(struct rte_eth_dev *dev,
16164 : : uint32_t encap_decap_idx)
16165 : : {
16166 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16167 : : struct mlx5_flow_dv_encap_decap_resource *resource;
16168 : :
16169 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DECAP_ENCAP],
16170 : : encap_decap_idx);
16171 [ # # ]: 0 : if (!resource)
16172 : : return 0;
16173 : : MLX5_ASSERT(resource->action);
16174 : 0 : return mlx5_hlist_unregister(priv->sh->encaps_decaps, &resource->entry);
16175 : : }
16176 : :
16177 : : /**
16178 : : * Release an jump to table action resource.
16179 : : *
16180 : : * @param dev
16181 : : * Pointer to Ethernet device.
16182 : : * @param rix_jump
16183 : : * Index to the jump action resource.
16184 : : *
16185 : : * @return
16186 : : * 1 while a reference on it exists, 0 when freed.
16187 : : */
16188 : : static int
16189 : 0 : flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev,
16190 : : uint32_t rix_jump)
16191 : : {
16192 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16193 : : struct mlx5_flow_tbl_data_entry *tbl_data;
16194 : :
16195 : 0 : tbl_data = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_JUMP],
16196 : : rix_jump);
16197 [ # # ]: 0 : if (!tbl_data)
16198 : : return 0;
16199 : 0 : return flow_dv_tbl_resource_release(MLX5_SH(dev), &tbl_data->tbl);
16200 : : }
16201 : :
16202 : : void
16203 : 0 : flow_modify_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
16204 : : {
16205 : : struct mlx5_flow_dv_modify_hdr_resource *res =
16206 : : container_of(entry, typeof(*res), entry);
16207 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
16208 : :
16209 : : #ifdef HAVE_MLX5_HWS_SUPPORT
16210 [ # # ]: 0 : if (sh->config.dv_flow_en == 2)
16211 : 0 : claim_zero(mlx5dr_action_destroy(res->action));
16212 : : else
16213 : : #endif
16214 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(res->action));
16215 : 0 : mlx5_ipool_free(sh->mdh_ipools[res->actions_num - 1], res->idx);
16216 : 0 : }
16217 : :
16218 : : /**
16219 : : * Release a modify-header resource.
16220 : : *
16221 : : * @param dev
16222 : : * Pointer to Ethernet device.
16223 : : * @param handle
16224 : : * Pointer to mlx5_flow_handle.
16225 : : *
16226 : : * @return
16227 : : * 1 while a reference on it exists, 0 when freed.
16228 : : */
16229 : : static int
16230 : : flow_dv_modify_hdr_resource_release(struct rte_eth_dev *dev,
16231 : : struct mlx5_flow_handle *handle)
16232 : : {
16233 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16234 : : struct mlx5_flow_dv_modify_hdr_resource *entry = handle->dvh.modify_hdr;
16235 : :
16236 : : MLX5_ASSERT(entry->action);
16237 : 0 : return mlx5_hlist_unregister(priv->sh->modify_cmds, &entry->entry);
16238 : : }
16239 : :
16240 : : void
16241 : 0 : flow_dv_port_id_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
16242 : : {
16243 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
16244 : : struct mlx5_flow_dv_port_id_action_resource *resource =
16245 : : container_of(entry, typeof(*resource), entry);
16246 : :
16247 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
16248 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PORT_ID], resource->idx);
16249 : 0 : }
16250 : :
16251 : : /**
16252 : : * Release port ID action resource.
16253 : : *
16254 : : * @param dev
16255 : : * Pointer to Ethernet device.
16256 : : * @param handle
16257 : : * Pointer to mlx5_flow_handle.
16258 : : *
16259 : : * @return
16260 : : * 1 while a reference on it exists, 0 when freed.
16261 : : */
16262 : : static int
16263 : 0 : flow_dv_port_id_action_resource_release(struct rte_eth_dev *dev,
16264 : : uint32_t port_id)
16265 : : {
16266 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16267 : : struct mlx5_flow_dv_port_id_action_resource *resource;
16268 : :
16269 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PORT_ID], port_id);
16270 [ # # ]: 0 : if (!resource)
16271 : : return 0;
16272 : : MLX5_ASSERT(resource->action);
16273 : 0 : return mlx5_list_unregister(priv->sh->port_id_action_list,
16274 : : &resource->entry);
16275 : : }
16276 : :
16277 : : /**
16278 : : * Release shared RSS action resource.
16279 : : *
16280 : : * @param dev
16281 : : * Pointer to Ethernet device.
16282 : : * @param srss
16283 : : * Shared RSS action index.
16284 : : */
16285 : : static void
16286 : 0 : flow_dv_shared_rss_action_release(struct rte_eth_dev *dev, uint32_t srss)
16287 : : {
16288 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16289 : : struct mlx5_shared_action_rss *shared_rss;
16290 : :
16291 : 0 : shared_rss = mlx5_ipool_get
16292 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], srss);
16293 : 0 : rte_atomic_fetch_sub_explicit(&shared_rss->refcnt, 1, rte_memory_order_relaxed);
16294 : 0 : }
16295 : :
16296 : : void
16297 : 0 : flow_dv_push_vlan_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
16298 : : {
16299 : : struct mlx5_dev_ctx_shared *sh = tool_ctx;
16300 : : struct mlx5_flow_dv_push_vlan_action_resource *resource =
16301 : : container_of(entry, typeof(*resource), entry);
16302 : :
16303 : 0 : claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
16304 : 0 : mlx5_ipool_free(sh->ipool[MLX5_IPOOL_PUSH_VLAN], resource->idx);
16305 : 0 : }
16306 : :
16307 : : /**
16308 : : * Release push vlan action resource.
16309 : : *
16310 : : * @param dev
16311 : : * Pointer to Ethernet device.
16312 : : * @param handle
16313 : : * Pointer to mlx5_flow_handle.
16314 : : *
16315 : : * @return
16316 : : * 1 while a reference on it exists, 0 when freed.
16317 : : */
16318 : : static int
16319 : 0 : flow_dv_push_vlan_action_resource_release(struct rte_eth_dev *dev,
16320 : : struct mlx5_flow_handle *handle)
16321 : : {
16322 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16323 : : struct mlx5_flow_dv_push_vlan_action_resource *resource;
16324 : 0 : uint32_t idx = handle->dvh.rix_push_vlan;
16325 : :
16326 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PUSH_VLAN], idx);
16327 [ # # ]: 0 : if (!resource)
16328 : : return 0;
16329 : : MLX5_ASSERT(resource->action);
16330 : 0 : return mlx5_list_unregister(priv->sh->push_vlan_action_list,
16331 : : &resource->entry);
16332 : : }
16333 : :
16334 : : /**
16335 : : * Release the fate resource.
16336 : : *
16337 : : * @param dev
16338 : : * Pointer to Ethernet device.
16339 : : * @param handle
16340 : : * Pointer to mlx5_flow_handle.
16341 : : */
16342 : : static void
16343 : 0 : flow_dv_fate_resource_release(struct rte_eth_dev *dev,
16344 : : struct mlx5_flow_handle *handle)
16345 : : {
16346 [ # # ]: 0 : if (!handle->rix_fate)
16347 : : return;
16348 [ # # # # : 0 : switch (handle->fate_action) {
# ]
16349 : 0 : case MLX5_FLOW_FATE_QUEUE:
16350 [ # # # # ]: 0 : if (!handle->dvh.rix_sample && !handle->dvh.rix_dest_array)
16351 : 0 : mlx5_hrxq_release(dev, handle->rix_hrxq);
16352 : : break;
16353 : 0 : case MLX5_FLOW_FATE_JUMP:
16354 : 0 : flow_dv_jump_tbl_resource_release(dev, handle->rix_jump);
16355 : 0 : break;
16356 : 0 : case MLX5_FLOW_FATE_PORT_ID:
16357 : 0 : flow_dv_port_id_action_resource_release(dev,
16358 : : handle->rix_port_id_action);
16359 : 0 : break;
16360 : : case MLX5_FLOW_FATE_SEND_TO_KERNEL:
16361 : : /* In case of send_to_kernel action the actual release of
16362 : : * resource is done when all shared DR resources are released
16363 : : * since this resource is created once and always reused.
16364 : : */
16365 : : break;
16366 : 0 : default:
16367 : 0 : DRV_LOG(DEBUG, "Incorrect fate action:%d", handle->fate_action);
16368 : 0 : break;
16369 : : }
16370 : 0 : handle->rix_fate = 0;
16371 : : }
16372 : :
16373 : : void
16374 : 0 : flow_dv_sample_remove_cb(void *tool_ctx __rte_unused,
16375 : : struct mlx5_list_entry *entry)
16376 : : {
16377 : : struct mlx5_flow_dv_sample_resource *resource = container_of(entry,
16378 : : typeof(*resource),
16379 : : entry);
16380 : 0 : struct rte_eth_dev *dev = resource->dev;
16381 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16382 : :
16383 [ # # ]: 0 : if (resource->verbs_action)
16384 : : claim_zero(mlx5_flow_os_destroy_flow_action
16385 : : (resource->verbs_action));
16386 [ # # ]: 0 : if (resource->normal_path_tbl)
16387 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev),
16388 : : resource->normal_path_tbl);
16389 : 0 : flow_dv_sample_sub_actions_release(dev, &resource->sample_idx);
16390 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_SAMPLE], resource->idx);
16391 : 0 : DRV_LOG(DEBUG, "sample resource %p: removed", (void *)resource);
16392 : 0 : }
16393 : :
16394 : : /**
16395 : : * Release an sample resource.
16396 : : *
16397 : : * @param dev
16398 : : * Pointer to Ethernet device.
16399 : : * @param handle
16400 : : * Pointer to mlx5_flow_handle.
16401 : : *
16402 : : * @return
16403 : : * 1 while a reference on it exists, 0 when freed.
16404 : : */
16405 : : static int
16406 : 0 : flow_dv_sample_resource_release(struct rte_eth_dev *dev,
16407 : : struct mlx5_flow_handle *handle)
16408 : : {
16409 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16410 : : struct mlx5_flow_dv_sample_resource *resource;
16411 : :
16412 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_SAMPLE],
16413 : : handle->dvh.rix_sample);
16414 [ # # ]: 0 : if (!resource)
16415 : : return 0;
16416 : : MLX5_ASSERT(resource->verbs_action);
16417 : 0 : return mlx5_list_unregister(priv->sh->sample_action_list,
16418 : : &resource->entry);
16419 : : }
16420 : :
16421 : : void
16422 : 0 : flow_dv_dest_array_remove_cb(void *tool_ctx __rte_unused,
16423 : : struct mlx5_list_entry *entry)
16424 : : {
16425 : : struct mlx5_flow_dv_dest_array_resource *resource =
16426 : : container_of(entry, typeof(*resource), entry);
16427 : 0 : struct rte_eth_dev *dev = resource->dev;
16428 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16429 : : uint32_t i = 0;
16430 : :
16431 : : MLX5_ASSERT(resource->action);
16432 [ # # ]: 0 : if (resource->action)
16433 : : claim_zero(mlx5_flow_os_destroy_flow_action(resource->action));
16434 [ # # ]: 0 : for (; i < resource->num_of_dest; i++)
16435 : 0 : flow_dv_sample_sub_actions_release(dev,
16436 : : &resource->sample_idx[i]);
16437 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY], resource->idx);
16438 : 0 : DRV_LOG(DEBUG, "destination array resource %p: removed",
16439 : : (void *)resource);
16440 : 0 : }
16441 : :
16442 : : /**
16443 : : * Release an destination array resource.
16444 : : *
16445 : : * @param dev
16446 : : * Pointer to Ethernet device.
16447 : : * @param handle
16448 : : * Pointer to mlx5_flow_handle.
16449 : : *
16450 : : * @return
16451 : : * 1 while a reference on it exists, 0 when freed.
16452 : : */
16453 : : static int
16454 : 0 : flow_dv_dest_array_resource_release(struct rte_eth_dev *dev,
16455 : : struct mlx5_flow_handle *handle)
16456 : : {
16457 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16458 : : struct mlx5_flow_dv_dest_array_resource *resource;
16459 : :
16460 : 0 : resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DEST_ARRAY],
16461 : : handle->dvh.rix_dest_array);
16462 [ # # ]: 0 : if (!resource)
16463 : : return 0;
16464 : : MLX5_ASSERT(resource->action);
16465 : 0 : return mlx5_list_unregister(priv->sh->dest_array_list,
16466 : : &resource->entry);
16467 : : }
16468 : :
16469 : : static void
16470 : 0 : flow_dev_geneve_tlv_option_resource_release(struct mlx5_dev_ctx_shared *sh)
16471 : : {
16472 : 0 : struct mlx5_geneve_tlv_option_resource *geneve_opt_resource =
16473 : : sh->geneve_tlv_option_resource;
16474 : 0 : rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
16475 [ # # ]: 0 : if (geneve_opt_resource) {
16476 [ # # ]: 0 : if (!(rte_atomic_fetch_sub_explicit(&geneve_opt_resource->refcnt, 1,
16477 : : rte_memory_order_relaxed) - 1)) {
16478 : 0 : claim_zero(mlx5_devx_cmd_destroy
16479 : : (geneve_opt_resource->obj));
16480 : 0 : mlx5_free(sh->geneve_tlv_option_resource);
16481 : 0 : sh->geneve_tlv_option_resource = NULL;
16482 : : }
16483 : : }
16484 : : rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
16485 : 0 : }
16486 : :
16487 : : /**
16488 : : * Remove the flow from the NIC but keeps it in memory.
16489 : : * Lock free, (mutex should be acquired by caller).
16490 : : *
16491 : : * @param[in] dev
16492 : : * Pointer to Ethernet device.
16493 : : * @param[in, out] flow
16494 : : * Pointer to flow structure.
16495 : : */
16496 : : static void
16497 : 0 : flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
16498 : : {
16499 : : struct mlx5_flow_handle *dh;
16500 : : uint32_t handle_idx;
16501 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16502 : :
16503 [ # # ]: 0 : if (!flow)
16504 : : return;
16505 : 0 : handle_idx = flow->dev_handles;
16506 [ # # ]: 0 : while (handle_idx) {
16507 : 0 : dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
16508 : : handle_idx);
16509 [ # # ]: 0 : if (!dh)
16510 : : return;
16511 [ # # ]: 0 : if (dh->drv_flow) {
16512 : : claim_zero(mlx5_flow_os_destroy_flow(dh->drv_flow));
16513 : 0 : dh->drv_flow = NULL;
16514 : : }
16515 [ # # ]: 0 : if (dh->fate_action == MLX5_FLOW_FATE_QUEUE)
16516 : 0 : flow_dv_fate_resource_release(dev, dh);
16517 [ # # # # ]: 0 : if (dh->vf_vlan.tag && dh->vf_vlan.created)
16518 : 0 : mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
16519 : 0 : handle_idx = dh->next.next;
16520 : : }
16521 : : }
16522 : :
16523 : : /**
16524 : : * Remove the flow from the NIC and the memory.
16525 : : * Lock free, (mutex should be acquired by caller).
16526 : : *
16527 : : * @param[in] dev
16528 : : * Pointer to the Ethernet device structure.
16529 : : * @param[in, out] flow
16530 : : * Pointer to flow structure.
16531 : : */
16532 : : static void
16533 : 0 : flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
16534 : : {
16535 : : struct mlx5_flow_handle *dev_handle;
16536 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16537 : : struct mlx5_flow_meter_info *fm = NULL;
16538 : : uint32_t srss = 0;
16539 : :
16540 [ # # ]: 0 : if (!flow)
16541 : : return;
16542 : 0 : flow_dv_remove(dev, flow);
16543 [ # # ]: 0 : if (flow->counter) {
16544 : 0 : flow_dv_counter_free(dev, flow->counter);
16545 : 0 : flow->counter = 0;
16546 : : }
16547 [ # # ]: 0 : if (flow->meter) {
16548 : 0 : fm = flow_dv_meter_find_by_idx(priv, flow->meter);
16549 [ # # ]: 0 : if (fm)
16550 : 0 : mlx5_flow_meter_detach(priv, fm);
16551 : 0 : flow->meter = 0;
16552 : : }
16553 : : /* Keep the current age handling by default. */
16554 [ # # # # ]: 0 : if (flow->indirect_type == MLX5_INDIRECT_ACTION_TYPE_CT && flow->ct)
16555 : 0 : flow_dv_aso_ct_release(dev, flow->ct, NULL);
16556 [ # # ]: 0 : else if (flow->age)
16557 : 0 : flow_dv_aso_age_release(dev, flow->age);
16558 [ # # ]: 0 : while (flow->geneve_tlv_option) {
16559 : 0 : flow_dev_geneve_tlv_option_resource_release(priv->sh);
16560 : 0 : flow->geneve_tlv_option--;
16561 : : }
16562 [ # # ]: 0 : while (flow->dev_handles) {
16563 : : uint32_t tmp_idx = flow->dev_handles;
16564 : :
16565 : 0 : dev_handle = mlx5_ipool_get(priv->sh->ipool
16566 : : [MLX5_IPOOL_MLX5_FLOW], tmp_idx);
16567 [ # # ]: 0 : if (!dev_handle)
16568 : : return;
16569 : 0 : flow->dev_handles = dev_handle->next.next;
16570 [ # # ]: 0 : while (dev_handle->flex_item) {
16571 : 0 : int index = rte_bsf32(dev_handle->flex_item);
16572 : :
16573 : 0 : mlx5_flex_release_index(dev, index);
16574 : 0 : dev_handle->flex_item &= ~(uint8_t)RTE_BIT32(index);
16575 : : }
16576 [ # # ]: 0 : if (dev_handle->dvh.matcher)
16577 : 0 : flow_dv_matcher_release(dev, dev_handle);
16578 [ # # ]: 0 : if (dev_handle->dvh.rix_sample)
16579 : 0 : flow_dv_sample_resource_release(dev, dev_handle);
16580 [ # # ]: 0 : if (dev_handle->dvh.rix_dest_array)
16581 : 0 : flow_dv_dest_array_resource_release(dev, dev_handle);
16582 [ # # ]: 0 : if (dev_handle->dvh.rix_encap_decap)
16583 : 0 : flow_encap_decap_resource_release(dev,
16584 : : dev_handle->dvh.rix_encap_decap);
16585 [ # # ]: 0 : if (dev_handle->dvh.modify_hdr)
16586 : : flow_dv_modify_hdr_resource_release(dev, dev_handle);
16587 [ # # ]: 0 : if (dev_handle->dvh.rix_push_vlan)
16588 : 0 : flow_dv_push_vlan_action_resource_release(dev,
16589 : : dev_handle);
16590 [ # # ]: 0 : if (dev_handle->dvh.rix_tag)
16591 : 0 : flow_dv_tag_release(dev,
16592 : : dev_handle->dvh.rix_tag);
16593 [ # # ]: 0 : if (dev_handle->fate_action != MLX5_FLOW_FATE_SHARED_RSS)
16594 : 0 : flow_dv_fate_resource_release(dev, dev_handle);
16595 [ # # ]: 0 : else if (!srss)
16596 : 0 : srss = dev_handle->rix_srss;
16597 [ # # # # ]: 0 : if (fm && dev_handle->is_meter_flow_id &&
16598 [ # # ]: 0 : dev_handle->split_flow_id)
16599 : 0 : mlx5_ipool_free(fm->flow_ipool,
16600 : : dev_handle->split_flow_id);
16601 [ # # ]: 0 : else if (dev_handle->split_flow_id &&
16602 [ # # ]: 0 : !dev_handle->is_meter_flow_id)
16603 : 0 : mlx5_ipool_free(priv->sh->ipool
16604 : : [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
16605 : : dev_handle->split_flow_id);
16606 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
16607 : : tmp_idx);
16608 : : }
16609 [ # # ]: 0 : if (srss)
16610 : 0 : flow_dv_shared_rss_action_release(dev, srss);
16611 : : }
16612 : :
16613 : : /**
16614 : : * Release array of hash RX queue objects.
16615 : : * Helper function.
16616 : : *
16617 : : * @param[in] dev
16618 : : * Pointer to the Ethernet device structure.
16619 : : * @param[in, out] hrxqs
16620 : : * Array of hash RX queue objects.
16621 : : *
16622 : : * @return
16623 : : * Total number of references to hash RX queue objects in *hrxqs* array
16624 : : * after this operation.
16625 : : */
16626 : : static int
16627 : 0 : __flow_dv_hrxqs_release(struct rte_eth_dev *dev,
16628 : : uint32_t (*hrxqs)[MLX5_RSS_HASH_FIELDS_LEN])
16629 : : {
16630 : : size_t i;
16631 : : int remaining = 0;
16632 : :
16633 [ # # ]: 0 : for (i = 0; i < RTE_DIM(*hrxqs); i++) {
16634 : 0 : int ret = mlx5_hrxq_release(dev, (*hrxqs)[i]);
16635 : :
16636 [ # # ]: 0 : if (!ret)
16637 : 0 : (*hrxqs)[i] = 0;
16638 : 0 : remaining += ret;
16639 : : }
16640 : 0 : return remaining;
16641 : : }
16642 : :
16643 : : /**
16644 : : * Release all hash RX queue objects representing shared RSS action.
16645 : : *
16646 : : * @param[in] dev
16647 : : * Pointer to the Ethernet device structure.
16648 : : * @param[in, out] action
16649 : : * Shared RSS action to remove hash RX queue objects from.
16650 : : *
16651 : : * @return
16652 : : * Total number of references to hash RX queue objects stored in *action*
16653 : : * after this operation.
16654 : : * Expected to be 0 if no external references held.
16655 : : */
16656 : : static int
16657 : : __flow_dv_action_rss_hrxqs_release(struct rte_eth_dev *dev,
16658 : : struct mlx5_shared_action_rss *shared_rss)
16659 : : {
16660 : 0 : return __flow_dv_hrxqs_release(dev, &shared_rss->hrxq);
16661 : : }
16662 : :
16663 : : /**
16664 : : * Adjust L3/L4 hash value of pre-created shared RSS hrxq according to
16665 : : * user input.
16666 : : *
16667 : : * Only one hash value is available for one L3+L4 combination:
16668 : : * for example:
16669 : : * MLX5_RSS_HASH_IPV4, MLX5_RSS_HASH_IPV4_SRC_ONLY, and
16670 : : * MLX5_RSS_HASH_IPV4_DST_ONLY are mutually exclusive so they can share
16671 : : * same slot in mlx5_rss_hash_fields.
16672 : : *
16673 : : * @param[in] orig_rss_types
16674 : : * RSS type as provided in shared RSS action.
16675 : : * @param[in, out] hash_field
16676 : : * hash_field variable needed to be adjusted.
16677 : : *
16678 : : * @return
16679 : : * void
16680 : : */
16681 : : void
16682 [ # # ]: 0 : flow_dv_action_rss_l34_hash_adjust(uint64_t orig_rss_types,
16683 : : uint64_t *hash_field)
16684 : : {
16685 : : uint64_t rss_types = rte_eth_rss_hf_refine(orig_rss_types);
16686 : :
16687 [ # # # # : 0 : switch (*hash_field & ~IBV_RX_HASH_INNER) {
# ]
16688 : 0 : case MLX5_RSS_HASH_IPV4:
16689 [ # # ]: 0 : if (rss_types & MLX5_IPV4_LAYER_TYPES) {
16690 : 0 : *hash_field &= ~MLX5_RSS_HASH_IPV4;
16691 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
16692 : 0 : *hash_field |= IBV_RX_HASH_DST_IPV4;
16693 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
16694 : 0 : *hash_field |= IBV_RX_HASH_SRC_IPV4;
16695 : : else
16696 : 0 : *hash_field |= MLX5_RSS_HASH_IPV4;
16697 : : }
16698 : : return;
16699 : 0 : case MLX5_RSS_HASH_IPV6:
16700 [ # # ]: 0 : if (rss_types & MLX5_IPV6_LAYER_TYPES) {
16701 : 0 : *hash_field &= ~MLX5_RSS_HASH_IPV6;
16702 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L3_DST_ONLY)
16703 : 0 : *hash_field |= IBV_RX_HASH_DST_IPV6;
16704 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L3_SRC_ONLY)
16705 : 0 : *hash_field |= IBV_RX_HASH_SRC_IPV6;
16706 : : else
16707 : 0 : *hash_field |= MLX5_RSS_HASH_IPV6;
16708 : : }
16709 : : return;
16710 : 0 : case MLX5_RSS_HASH_IPV4_UDP:
16711 : : /* fall-through. */
16712 : : case MLX5_RSS_HASH_IPV6_UDP:
16713 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_UDP) {
16714 : 0 : *hash_field &= ~MLX5_UDP_IBV_RX_HASH;
16715 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
16716 : 0 : *hash_field |= IBV_RX_HASH_DST_PORT_UDP;
16717 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
16718 : 0 : *hash_field |= IBV_RX_HASH_SRC_PORT_UDP;
16719 : : else
16720 : 0 : *hash_field |= MLX5_UDP_IBV_RX_HASH;
16721 : : }
16722 : : return;
16723 : 0 : case MLX5_RSS_HASH_IPV4_TCP:
16724 : : /* fall-through. */
16725 : : case MLX5_RSS_HASH_IPV6_TCP:
16726 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_TCP) {
16727 : 0 : *hash_field &= ~MLX5_TCP_IBV_RX_HASH;
16728 [ # # ]: 0 : if (rss_types & RTE_ETH_RSS_L4_DST_ONLY)
16729 : 0 : *hash_field |= IBV_RX_HASH_DST_PORT_TCP;
16730 [ # # ]: 0 : else if (rss_types & RTE_ETH_RSS_L4_SRC_ONLY)
16731 : 0 : *hash_field |= IBV_RX_HASH_SRC_PORT_TCP;
16732 : : else
16733 : 0 : *hash_field |= MLX5_TCP_IBV_RX_HASH;
16734 : : }
16735 : : return;
16736 : : default:
16737 : : return;
16738 : : }
16739 : : }
16740 : :
16741 : : /**
16742 : : * Setup shared RSS action.
16743 : : * Prepare set of hash RX queue objects sufficient to handle all valid
16744 : : * hash_fields combinations (see enum ibv_rx_hash_fields).
16745 : : *
16746 : : * @param[in] dev
16747 : : * Pointer to the Ethernet device structure.
16748 : : * @param[in] action_idx
16749 : : * Shared RSS action ipool index.
16750 : : * @param[in, out] action
16751 : : * Partially initialized shared RSS action.
16752 : : * @param[out] error
16753 : : * Perform verbose error reporting if not NULL. Initialized in case of
16754 : : * error only.
16755 : : *
16756 : : * @return
16757 : : * 0 on success, otherwise negative errno value.
16758 : : */
16759 : : static int
16760 : 0 : __flow_dv_action_rss_setup(struct rte_eth_dev *dev,
16761 : : uint32_t action_idx,
16762 : : struct mlx5_shared_action_rss *shared_rss,
16763 : : struct rte_flow_error *error)
16764 : : {
16765 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16766 : 0 : struct mlx5_flow_rss_desc rss_desc = { 0 };
16767 : : size_t i;
16768 : : int err;
16769 : :
16770 : 0 : shared_rss->ind_tbl = mlx5_ind_table_obj_new
16771 : : (dev, shared_rss->origin.queue,
16772 : : shared_rss->origin.queue_num,
16773 : : true,
16774 : 0 : !!dev->data->dev_started);
16775 [ # # ]: 0 : if (!shared_rss->ind_tbl)
16776 : 0 : return rte_flow_error_set(error, rte_errno,
16777 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16778 : : "cannot setup indirection table");
16779 : 0 : memcpy(rss_desc.key, shared_rss->origin.key, MLX5_RSS_HASH_KEY_LEN);
16780 : 0 : rss_desc.key_len = MLX5_RSS_HASH_KEY_LEN;
16781 : 0 : rss_desc.symmetric_hash_function =
16782 : 0 : MLX5_RSS_IS_SYMM(shared_rss->origin.func);
16783 : 0 : rss_desc.const_q = shared_rss->origin.queue;
16784 : 0 : rss_desc.queue_num = shared_rss->origin.queue_num;
16785 : : /* Set non-zero value to indicate a shared RSS. */
16786 : 0 : rss_desc.shared_rss = action_idx;
16787 : 0 : rss_desc.ind_tbl = shared_rss->ind_tbl;
16788 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
16789 : 0 : rss_desc.hws_flags = MLX5DR_ACTION_FLAG_HWS_RX;
16790 [ # # ]: 0 : for (i = 0; i < MLX5_RSS_HASH_FIELDS_LEN; i++) {
16791 : : struct mlx5_hrxq *hrxq;
16792 : 0 : uint64_t hash_fields = mlx5_rss_hash_fields[i];
16793 : : int tunnel = 0;
16794 : :
16795 : 0 : flow_dv_action_rss_l34_hash_adjust(shared_rss->origin.types,
16796 : : &hash_fields);
16797 [ # # ]: 0 : if (shared_rss->origin.level > 1) {
16798 : 0 : hash_fields |= IBV_RX_HASH_INNER;
16799 : : tunnel = 1;
16800 : : }
16801 : 0 : rss_desc.tunnel = tunnel;
16802 : 0 : rss_desc.hash_fields = hash_fields;
16803 : 0 : hrxq = mlx5_hrxq_get(dev, &rss_desc);
16804 [ # # ]: 0 : if (!hrxq) {
16805 : 0 : rte_flow_error_set
16806 : : (error, rte_errno,
16807 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16808 : : "cannot get hash queue");
16809 : 0 : goto error_hrxq_new;
16810 : : }
16811 : 0 : err = __flow_dv_action_rss_hrxq_set
16812 : : (shared_rss, hash_fields, hrxq->idx);
16813 : : MLX5_ASSERT(!err);
16814 : : }
16815 : : return 0;
16816 : : error_hrxq_new:
16817 : 0 : err = rte_errno;
16818 : : __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
16819 [ # # ]: 0 : if (!mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl, true))
16820 : 0 : shared_rss->ind_tbl = NULL;
16821 : 0 : rte_errno = err;
16822 : 0 : return -rte_errno;
16823 : : }
16824 : :
16825 : : /**
16826 : : * Create shared RSS action.
16827 : : *
16828 : : * @param[in] dev
16829 : : * Pointer to the Ethernet device structure.
16830 : : * @param[in] conf
16831 : : * Shared action configuration.
16832 : : * @param[in] rss
16833 : : * RSS action specification used to create shared action.
16834 : : * @param[out] error
16835 : : * Perform verbose error reporting if not NULL. Initialized in case of
16836 : : * error only.
16837 : : *
16838 : : * @return
16839 : : * A valid shared action ID in case of success, 0 otherwise and
16840 : : * rte_errno is set.
16841 : : */
16842 : : static uint32_t
16843 : 0 : __flow_dv_action_rss_create(struct rte_eth_dev *dev,
16844 : : const struct rte_flow_indir_action_conf *conf,
16845 : : const struct rte_flow_action_rss *rss,
16846 : : struct rte_flow_error *error)
16847 : : {
16848 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16849 : : struct mlx5_shared_action_rss *shared_rss = NULL;
16850 : : struct rte_flow_action_rss *origin;
16851 : : const uint8_t *rss_key;
16852 : : uint32_t idx;
16853 : :
16854 : : RTE_SET_USED(conf);
16855 : 0 : shared_rss = mlx5_ipool_zmalloc
16856 : 0 : (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], &idx);
16857 [ # # ]: 0 : if (!shared_rss) {
16858 : 0 : rte_flow_error_set(error, ENOMEM,
16859 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16860 : : "cannot allocate resource memory");
16861 : 0 : goto error_rss_init;
16862 : : }
16863 [ # # ]: 0 : if (idx > (1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET)) {
16864 : 0 : rte_flow_error_set(error, E2BIG,
16865 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
16866 : : "rss action number out of range");
16867 : 0 : goto error_rss_init;
16868 : : }
16869 : : origin = &shared_rss->origin;
16870 : 0 : origin->func = rss->func;
16871 : 0 : origin->level = rss->level;
16872 : : /* RSS type 0 indicates default RSS type (RTE_ETH_RSS_IP). */
16873 [ # # ]: 0 : origin->types = !rss->types ? RTE_ETH_RSS_IP : rss->types;
16874 : : /* NULL RSS key indicates default RSS key. */
16875 [ # # ]: 0 : rss_key = !rss->key ? rss_hash_default_key : rss->key;
16876 : 0 : memcpy(shared_rss->key, rss_key, MLX5_RSS_HASH_KEY_LEN);
16877 : 0 : origin->key = &shared_rss->key[0];
16878 : 0 : origin->key_len = MLX5_RSS_HASH_KEY_LEN;
16879 : 0 : origin->queue = rss->queue;
16880 : 0 : origin->queue_num = rss->queue_num;
16881 [ # # ]: 0 : if (__flow_dv_action_rss_setup(dev, idx, shared_rss, error))
16882 : 0 : goto error_rss_init;
16883 : : /* Update queue with indirect table queue memoyr. */
16884 : 0 : origin->queue = shared_rss->ind_tbl->queues;
16885 : : rte_spinlock_init(&shared_rss->action_rss_sl);
16886 : 0 : rte_atomic_fetch_add_explicit(&shared_rss->refcnt, 1, rte_memory_order_relaxed);
16887 : 0 : rte_spinlock_lock(&priv->shared_act_sl);
16888 [ # # # # ]: 0 : ILIST_INSERT(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
16889 : : &priv->rss_shared_actions, idx, shared_rss, next);
16890 : : rte_spinlock_unlock(&priv->shared_act_sl);
16891 : 0 : return idx;
16892 : 0 : error_rss_init:
16893 [ # # ]: 0 : if (shared_rss) {
16894 [ # # ]: 0 : if (shared_rss->ind_tbl)
16895 : 0 : mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl,
16896 : 0 : !!dev->data->dev_started);
16897 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
16898 : : idx);
16899 : : }
16900 : : return 0;
16901 : : }
16902 : :
16903 : : /**
16904 : : * Destroy the shared RSS action.
16905 : : * Release related hash RX queue objects.
16906 : : *
16907 : : * @param[in] dev
16908 : : * Pointer to the Ethernet device structure.
16909 : : * @param[in] idx
16910 : : * The shared RSS action object ID to be removed.
16911 : : * @param[out] error
16912 : : * Perform verbose error reporting if not NULL. Initialized in case of
16913 : : * error only.
16914 : : *
16915 : : * @return
16916 : : * 0 on success, otherwise negative errno value.
16917 : : */
16918 : : static int
16919 : 0 : __flow_dv_action_rss_release(struct rte_eth_dev *dev, uint32_t idx,
16920 : : struct rte_flow_error *error)
16921 : : {
16922 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16923 : : struct mlx5_shared_action_rss *shared_rss =
16924 : 0 : mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
16925 : : uint32_t old_refcnt = 1;
16926 : : int remaining;
16927 : :
16928 [ # # ]: 0 : if (!shared_rss)
16929 : 0 : return rte_flow_error_set(error, EINVAL,
16930 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
16931 : : "invalid shared action");
16932 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(&shared_rss->refcnt, &old_refcnt,
16933 : : 0, rte_memory_order_acquire,
16934 : : rte_memory_order_relaxed))
16935 : 0 : return rte_flow_error_set(error, EBUSY,
16936 : : RTE_FLOW_ERROR_TYPE_ACTION,
16937 : : NULL,
16938 : : "shared rss has references");
16939 : : remaining = __flow_dv_action_rss_hrxqs_release(dev, shared_rss);
16940 [ # # ]: 0 : if (remaining)
16941 : 0 : return rte_flow_error_set(error, EBUSY,
16942 : : RTE_FLOW_ERROR_TYPE_ACTION,
16943 : : NULL,
16944 : : "shared rss hrxq has references");
16945 : 0 : remaining = mlx5_ind_table_obj_release(dev, shared_rss->ind_tbl,
16946 : 0 : !!dev->data->dev_started);
16947 [ # # ]: 0 : if (remaining)
16948 : 0 : return rte_flow_error_set(error, EBUSY,
16949 : : RTE_FLOW_ERROR_TYPE_ACTION,
16950 : : NULL,
16951 : : "shared rss indirection table has"
16952 : : " references");
16953 : 0 : rte_spinlock_lock(&priv->shared_act_sl);
16954 [ # # # # : 0 : ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
# # # # #
# ]
16955 : : &priv->rss_shared_actions, idx, shared_rss, next);
16956 : : rte_spinlock_unlock(&priv->shared_act_sl);
16957 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
16958 : : idx);
16959 : 0 : return 0;
16960 : : }
16961 : :
16962 : : /**
16963 : : * Create indirect action, lock free,
16964 : : * (mutex should be acquired by caller).
16965 : : * Dispatcher for action type specific call.
16966 : : *
16967 : : * @param[in] dev
16968 : : * Pointer to the Ethernet device structure.
16969 : : * @param[in] conf
16970 : : * Shared action configuration.
16971 : : * @param[in] action
16972 : : * Action specification used to create indirect action.
16973 : : * @param[out] error
16974 : : * Perform verbose error reporting if not NULL. Initialized in case of
16975 : : * error only.
16976 : : *
16977 : : * @return
16978 : : * A valid shared action handle in case of success, NULL otherwise and
16979 : : * rte_errno is set.
16980 : : */
16981 : : struct rte_flow_action_handle *
16982 : 0 : flow_dv_action_create(struct rte_eth_dev *dev,
16983 : : const struct rte_flow_indir_action_conf *conf,
16984 : : const struct rte_flow_action *action,
16985 : : struct rte_flow_error *err)
16986 : : {
16987 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
16988 : : uint32_t age_idx = 0;
16989 : : uint32_t idx = 0;
16990 : : uint32_t ret = 0;
16991 : :
16992 [ # # # # : 0 : switch (action->type) {
# ]
16993 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
16994 : 0 : ret = __flow_dv_action_rss_create(dev, conf, action->conf, err);
16995 : : idx = (MLX5_INDIRECT_ACTION_TYPE_RSS <<
16996 : : MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
16997 : 0 : break;
16998 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
16999 : 0 : age_idx = flow_dv_aso_age_alloc(dev, err);
17000 [ # # ]: 0 : if (!age_idx) {
17001 : 0 : ret = -rte_errno;
17002 : 0 : break;
17003 : : }
17004 : 0 : idx = (MLX5_INDIRECT_ACTION_TYPE_AGE <<
17005 : : MLX5_INDIRECT_ACTION_TYPE_OFFSET) | age_idx;
17006 : 0 : flow_dv_aso_age_params_init(dev, age_idx,
17007 : : ((const struct rte_flow_action_age *)
17008 : 0 : action->conf)->context ?
17009 : : ((const struct rte_flow_action_age *)
17010 : : action->conf)->context :
17011 : 0 : (void *)(uintptr_t)idx,
17012 : : ((const struct rte_flow_action_age *)
17013 [ # # ]: 0 : action->conf)->timeout);
17014 : : ret = age_idx;
17015 : 0 : break;
17016 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
17017 : 0 : ret = flow_dv_translate_create_counter(dev, NULL, NULL, NULL);
17018 : 0 : idx = (MLX5_INDIRECT_ACTION_TYPE_COUNT <<
17019 : : MLX5_INDIRECT_ACTION_TYPE_OFFSET) | ret;
17020 : 0 : break;
17021 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
17022 : 0 : ret = flow_dv_translate_create_conntrack(dev, action->conf,
17023 : : err);
17024 [ # # ]: 0 : if (!ret)
17025 : : break;
17026 : 0 : idx = MLX5_INDIRECT_ACT_CT_GEN_IDX(PORT_ID(priv), ret);
17027 : 0 : break;
17028 : 0 : default:
17029 : 0 : rte_flow_error_set(err, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
17030 : : NULL, "action type not supported");
17031 : : break;
17032 : : }
17033 [ # # ]: 0 : return ret ? (struct rte_flow_action_handle *)(uintptr_t)idx : NULL;
17034 : : }
17035 : :
17036 : : /**
17037 : : * Destroy the indirect action.
17038 : : * Release action related resources on the NIC and the memory.
17039 : : * Lock free, (mutex should be acquired by caller).
17040 : : * Dispatcher for action type specific call.
17041 : : *
17042 : : * @param[in] dev
17043 : : * Pointer to the Ethernet device structure.
17044 : : * @param[in] handle
17045 : : * The indirect action object handle to be removed.
17046 : : * @param[out] error
17047 : : * Perform verbose error reporting if not NULL. Initialized in case of
17048 : : * error only.
17049 : : *
17050 : : * @return
17051 : : * 0 on success, otherwise negative errno value.
17052 : : */
17053 : : int
17054 : 0 : flow_dv_action_destroy(struct rte_eth_dev *dev,
17055 : : struct rte_flow_action_handle *handle,
17056 : : struct rte_flow_error *error)
17057 : : {
17058 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
17059 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
17060 : 0 : uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
17061 : : struct mlx5_flow_counter *cnt;
17062 : : uint32_t no_flow_refcnt = 1;
17063 : : int ret;
17064 : :
17065 [ # # # # : 0 : switch (type) {
# ]
17066 : 0 : case MLX5_INDIRECT_ACTION_TYPE_RSS:
17067 : 0 : return __flow_dv_action_rss_release(dev, idx, error);
17068 : : case MLX5_INDIRECT_ACTION_TYPE_COUNT:
17069 : : cnt = flow_dv_counter_get_by_idx(dev, idx, NULL);
17070 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit(&cnt->shared_info.refcnt,
17071 : : &no_flow_refcnt, 1,
17072 : : rte_memory_order_acquire,
17073 : : rte_memory_order_relaxed))
17074 : 0 : return rte_flow_error_set(error, EBUSY,
17075 : : RTE_FLOW_ERROR_TYPE_ACTION,
17076 : : NULL,
17077 : : "Indirect count action has references");
17078 : 0 : flow_dv_counter_free(dev, idx);
17079 : 0 : return 0;
17080 : 0 : case MLX5_INDIRECT_ACTION_TYPE_AGE:
17081 : 0 : ret = flow_dv_aso_age_release(dev, idx);
17082 [ # # ]: 0 : if (ret)
17083 : : /*
17084 : : * In this case, the last flow has a reference will
17085 : : * actually release the age action.
17086 : : */
17087 : 0 : DRV_LOG(DEBUG, "Indirect age action %" PRIu32 " was"
17088 : : " released with references %d.", idx, ret);
17089 : : return 0;
17090 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
17091 : 0 : ret = flow_dv_aso_ct_release(dev, idx, error);
17092 [ # # ]: 0 : if (ret < 0)
17093 : : return ret;
17094 [ # # ]: 0 : if (ret > 0)
17095 : 0 : DRV_LOG(DEBUG, "Connection tracking object %u still "
17096 : : "has references %d.", idx, ret);
17097 : : return 0;
17098 : 0 : default:
17099 : 0 : return rte_flow_error_set(error, ENOTSUP,
17100 : : RTE_FLOW_ERROR_TYPE_ACTION,
17101 : : NULL,
17102 : : "action type not supported");
17103 : : }
17104 : : }
17105 : :
17106 : : /**
17107 : : * Updates in place shared RSS action configuration.
17108 : : *
17109 : : * @param[in] dev
17110 : : * Pointer to the Ethernet device structure.
17111 : : * @param[in] idx
17112 : : * The shared RSS action object ID to be updated.
17113 : : * @param[in] action_conf
17114 : : * RSS action specification used to modify *shared_rss*.
17115 : : * @param[out] error
17116 : : * Perform verbose error reporting if not NULL. Initialized in case of
17117 : : * error only.
17118 : : *
17119 : : * @return
17120 : : * 0 on success, otherwise negative errno value.
17121 : : * @note: currently only support update of RSS queues.
17122 : : */
17123 : : static int
17124 : 0 : __flow_dv_action_rss_update(struct rte_eth_dev *dev, uint32_t idx,
17125 : : const struct rte_flow_action_rss *action_conf,
17126 : : struct rte_flow_error *error)
17127 : : {
17128 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17129 : : struct mlx5_shared_action_rss *shared_rss =
17130 : 0 : mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
17131 : : int ret = 0;
17132 : : void *queue = NULL;
17133 : : void *queue_i = NULL;
17134 : 0 : uint32_t queue_size = action_conf->queue_num * sizeof(uint16_t);
17135 : 0 : bool dev_started = !!dev->data->dev_started;
17136 : :
17137 [ # # ]: 0 : if (!shared_rss)
17138 : 0 : return rte_flow_error_set(error, EINVAL,
17139 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
17140 : : "invalid shared action to update");
17141 [ # # ]: 0 : if (priv->obj_ops.ind_table_modify == NULL)
17142 : 0 : return rte_flow_error_set(error, ENOTSUP,
17143 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
17144 : : "cannot modify indirection table");
17145 : 0 : queue = mlx5_malloc(MLX5_MEM_ZERO,
17146 : 0 : RTE_ALIGN_CEIL(queue_size, sizeof(void *)),
17147 : : 0, SOCKET_ID_ANY);
17148 [ # # ]: 0 : if (!queue)
17149 : 0 : return rte_flow_error_set(error, ENOMEM,
17150 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17151 : : NULL,
17152 : : "cannot allocate resource memory");
17153 : 0 : memcpy(queue, action_conf->queue, queue_size);
17154 : : MLX5_ASSERT(shared_rss->ind_tbl);
17155 : 0 : rte_spinlock_lock(&shared_rss->action_rss_sl);
17156 : 0 : queue_i = shared_rss->ind_tbl->queues;
17157 : 0 : ret = mlx5_ind_table_obj_modify(dev, shared_rss->ind_tbl,
17158 : 0 : queue, action_conf->queue_num,
17159 : : true /* standalone */,
17160 : : dev_started /* ref_new_qs */,
17161 : : dev_started /* deref_old_qs */);
17162 [ # # ]: 0 : if (ret) {
17163 : 0 : ret = rte_flow_error_set(error, rte_errno,
17164 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
17165 : : "cannot update indirection table");
17166 : : } else {
17167 : : /* Restore the queue to indirect table internal queue. */
17168 : : memcpy(queue_i, queue, queue_size);
17169 : 0 : shared_rss->ind_tbl->queues = queue_i;
17170 : 0 : shared_rss->origin.queue_num = action_conf->queue_num;
17171 : : }
17172 : 0 : mlx5_free(queue);
17173 : : rte_spinlock_unlock(&shared_rss->action_rss_sl);
17174 : 0 : return ret;
17175 : : }
17176 : :
17177 : : /*
17178 : : * Updates in place conntrack context or direction.
17179 : : * Context update should be synchronized.
17180 : : *
17181 : : * @param[in] dev
17182 : : * Pointer to the Ethernet device structure.
17183 : : * @param[in] idx
17184 : : * The conntrack object ID to be updated.
17185 : : * @param[in] update
17186 : : * Pointer to the structure of information to update.
17187 : : * @param[out] error
17188 : : * Perform verbose error reporting if not NULL. Initialized in case of
17189 : : * error only.
17190 : : *
17191 : : * @return
17192 : : * 0 on success, otherwise negative errno value.
17193 : : */
17194 : : static int
17195 : 0 : __flow_dv_action_ct_update(struct rte_eth_dev *dev, uint32_t idx,
17196 : : const struct rte_flow_modify_conntrack *update,
17197 : : struct rte_flow_error *error)
17198 : : {
17199 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17200 : : struct mlx5_aso_ct_action *ct;
17201 : : const struct rte_flow_action_conntrack *new_prf;
17202 : : int ret = 0;
17203 : 0 : uint16_t owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(idx);
17204 : : uint32_t dev_idx;
17205 : :
17206 [ # # ]: 0 : if (PORT_ID(priv) != owner)
17207 : 0 : return rte_flow_error_set(error, EACCES,
17208 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17209 : : NULL,
17210 : : "CT object owned by another port");
17211 : 0 : dev_idx = MLX5_INDIRECT_ACT_CT_GET_IDX(idx);
17212 : 0 : ct = flow_aso_ct_get_by_dev_idx(dev, dev_idx);
17213 [ # # ]: 0 : if (!ct->refcnt)
17214 : 0 : return rte_flow_error_set(error, ENOMEM,
17215 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17216 : : NULL,
17217 : : "CT object is inactive");
17218 : 0 : new_prf = &update->new_ct;
17219 [ # # ]: 0 : if (update->direction)
17220 : 0 : ct->is_original = !!new_prf->is_original_dir;
17221 [ # # ]: 0 : if (update->state) {
17222 : : /* Only validate the profile when it needs to be updated. */
17223 : 0 : ret = mlx5_validate_action_ct(dev, new_prf, error);
17224 [ # # ]: 0 : if (ret)
17225 : : return ret;
17226 : 0 : ret = mlx5_aso_ct_update_by_wqe(priv->sh, MLX5_HW_INV_QUEUE,
17227 : : ct, new_prf, NULL, true);
17228 [ # # ]: 0 : if (ret)
17229 : 0 : return rte_flow_error_set(error, EIO,
17230 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17231 : : NULL,
17232 : : "Failed to send CT context update WQE");
17233 : : /* Block until ready or a failure, default is asynchronous. */
17234 : 0 : ret = mlx5_aso_ct_available(priv->sh, MLX5_HW_INV_QUEUE, ct);
17235 [ # # ]: 0 : if (ret)
17236 : 0 : rte_flow_error_set(error, rte_errno,
17237 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17238 : : NULL,
17239 : : "Timeout to get the CT update");
17240 : : }
17241 : : return ret;
17242 : : }
17243 : :
17244 : : /**
17245 : : * Updates in place shared action configuration, lock free,
17246 : : * (mutex should be acquired by caller).
17247 : : *
17248 : : * @param[in] dev
17249 : : * Pointer to the Ethernet device structure.
17250 : : * @param[in] handle
17251 : : * The indirect action object handle to be updated.
17252 : : * @param[in] update
17253 : : * Action specification used to modify the action pointed by *handle*.
17254 : : * *update* could be of same type with the action pointed by the *handle*
17255 : : * handle argument, or some other structures like a wrapper, depending on
17256 : : * the indirect action type.
17257 : : * @param[out] error
17258 : : * Perform verbose error reporting if not NULL. Initialized in case of
17259 : : * error only.
17260 : : *
17261 : : * @return
17262 : : * 0 on success, otherwise negative errno value.
17263 : : */
17264 : : int
17265 : 0 : flow_dv_action_update(struct rte_eth_dev *dev,
17266 : : struct rte_flow_action_handle *handle,
17267 : : const void *update,
17268 : : struct rte_flow_error *err)
17269 : : {
17270 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
17271 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
17272 : 0 : uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
17273 : : const void *action_conf;
17274 : :
17275 [ # # # ]: 0 : switch (type) {
17276 : 0 : case MLX5_INDIRECT_ACTION_TYPE_RSS:
17277 : 0 : action_conf = ((const struct rte_flow_action *)update)->conf;
17278 : 0 : return __flow_dv_action_rss_update(dev, idx, action_conf, err);
17279 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
17280 : 0 : return __flow_dv_action_ct_update(dev, idx, update, err);
17281 : 0 : default:
17282 : 0 : return rte_flow_error_set(err, ENOTSUP,
17283 : : RTE_FLOW_ERROR_TYPE_ACTION,
17284 : : NULL,
17285 : : "action type update not supported");
17286 : : }
17287 : : }
17288 : :
17289 : : /**
17290 : : * Destroy the meter sub policy table rules.
17291 : : * Lock free, (mutex should be acquired by caller).
17292 : : *
17293 : : * @param[in] dev
17294 : : * Pointer to Ethernet device.
17295 : : * @param[in] sub_policy
17296 : : * Pointer to meter sub policy table.
17297 : : */
17298 : : static void
17299 : 0 : __flow_dv_destroy_sub_policy_rules(struct rte_eth_dev *dev,
17300 : : struct mlx5_flow_meter_sub_policy *sub_policy)
17301 : : {
17302 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17303 : : struct mlx5_flow_tbl_data_entry *tbl;
17304 : 0 : struct mlx5_flow_meter_policy *policy = sub_policy->main_policy;
17305 : : struct mlx5_flow_meter_info *next_fm;
17306 : : struct mlx5_sub_policy_color_rule *color_rule;
17307 : : void *tmp;
17308 : : uint32_t i;
17309 : :
17310 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
17311 : : next_fm = NULL;
17312 [ # # ]: 0 : if (i <= RTE_COLOR_YELLOW && policy &&
17313 [ # # ]: 0 : policy->act_cnt[i].fate_action == MLX5_FLOW_FATE_MTR)
17314 : 0 : next_fm = mlx5_flow_meter_find(priv,
17315 : : policy->act_cnt[i].next_mtr_id, NULL);
17316 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(color_rule, &sub_policy->color_rules[i],
17317 : : next_port, tmp) {
17318 : 0 : claim_zero(mlx5_flow_os_destroy_flow(color_rule->rule));
17319 : 0 : tbl = container_of(color_rule->matcher->tbl,
17320 : : typeof(*tbl), tbl);
17321 : 0 : mlx5_list_unregister(tbl->matchers,
17322 : : &color_rule->matcher->entry);
17323 [ # # ]: 0 : TAILQ_REMOVE(&sub_policy->color_rules[i],
17324 : : color_rule, next_port);
17325 : 0 : mlx5_free(color_rule);
17326 [ # # ]: 0 : if (next_fm)
17327 : 0 : mlx5_flow_meter_detach(priv, next_fm);
17328 : : }
17329 : : }
17330 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
17331 [ # # ]: 0 : if (sub_policy->rix_hrxq[i]) {
17332 [ # # # # ]: 0 : if (policy && !policy->is_hierarchy)
17333 : 0 : mlx5_hrxq_release(dev, sub_policy->rix_hrxq[i]);
17334 : 0 : sub_policy->rix_hrxq[i] = 0;
17335 : : }
17336 [ # # ]: 0 : if (sub_policy->jump_tbl[i]) {
17337 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev),
17338 : : sub_policy->jump_tbl[i]);
17339 : 0 : sub_policy->jump_tbl[i] = NULL;
17340 : : }
17341 : : }
17342 [ # # ]: 0 : if (sub_policy->tbl_rsc) {
17343 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev),
17344 : : sub_policy->tbl_rsc);
17345 : 0 : sub_policy->tbl_rsc = NULL;
17346 : : }
17347 : 0 : }
17348 : :
17349 : : /**
17350 : : * Destroy policy rules, lock free,
17351 : : * (mutex should be acquired by caller).
17352 : : * Dispatcher for action type specific call.
17353 : : *
17354 : : * @param[in] dev
17355 : : * Pointer to the Ethernet device structure.
17356 : : * @param[in] mtr_policy
17357 : : * Meter policy struct.
17358 : : */
17359 : : static void
17360 : 0 : flow_dv_destroy_policy_rules(struct rte_eth_dev *dev,
17361 : : struct mlx5_flow_meter_policy *mtr_policy)
17362 : : {
17363 : : uint32_t i, j;
17364 : : struct mlx5_flow_meter_sub_policy *sub_policy;
17365 : : uint16_t sub_policy_num;
17366 : :
17367 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
17368 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
17369 : 0 : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
17370 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
17371 [ # # ]: 0 : for (j = 0; j < sub_policy_num; j++) {
17372 : 0 : sub_policy = mtr_policy->sub_policys[i][j];
17373 [ # # ]: 0 : if (sub_policy)
17374 : 0 : __flow_dv_destroy_sub_policy_rules(dev,
17375 : : sub_policy);
17376 : : }
17377 : : }
17378 : 0 : }
17379 : :
17380 : : /**
17381 : : * Destroy policy action, lock free,
17382 : : * (mutex should be acquired by caller).
17383 : : * Dispatcher for action type specific call.
17384 : : *
17385 : : * @param[in] dev
17386 : : * Pointer to the Ethernet device structure.
17387 : : * @param[in] mtr_policy
17388 : : * Meter policy struct.
17389 : : */
17390 : : static void
17391 : 0 : flow_dv_destroy_mtr_policy_acts(struct rte_eth_dev *dev,
17392 : : struct mlx5_flow_meter_policy *mtr_policy)
17393 : : {
17394 : : struct rte_flow_action *rss_action;
17395 : : struct mlx5_flow_handle dev_handle;
17396 : : uint32_t i, j;
17397 : :
17398 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
17399 [ # # ]: 0 : if (mtr_policy->act_cnt[i].rix_mark) {
17400 : 0 : flow_dv_tag_release(dev,
17401 : : mtr_policy->act_cnt[i].rix_mark);
17402 : 0 : mtr_policy->act_cnt[i].rix_mark = 0;
17403 : : }
17404 [ # # ]: 0 : if (mtr_policy->act_cnt[i].modify_hdr) {
17405 : : dev_handle.dvh.modify_hdr =
17406 : : mtr_policy->act_cnt[i].modify_hdr;
17407 : : flow_dv_modify_hdr_resource_release(dev, &dev_handle);
17408 : : }
17409 [ # # # # ]: 0 : switch (mtr_policy->act_cnt[i].fate_action) {
17410 : 0 : case MLX5_FLOW_FATE_SHARED_RSS:
17411 : 0 : rss_action = mtr_policy->act_cnt[i].rss;
17412 : 0 : mlx5_free(rss_action);
17413 : 0 : break;
17414 : 0 : case MLX5_FLOW_FATE_PORT_ID:
17415 [ # # ]: 0 : if (mtr_policy->act_cnt[i].rix_port_id_action) {
17416 : 0 : flow_dv_port_id_action_resource_release(dev,
17417 : : mtr_policy->act_cnt[i].rix_port_id_action);
17418 : 0 : mtr_policy->act_cnt[i].rix_port_id_action = 0;
17419 : : }
17420 : : break;
17421 : : case MLX5_FLOW_FATE_DROP:
17422 : : case MLX5_FLOW_FATE_JUMP:
17423 [ # # ]: 0 : for (j = 0; j < MLX5_MTR_DOMAIN_MAX; j++)
17424 : 0 : mtr_policy->act_cnt[i].dr_jump_action[j] =
17425 : : NULL;
17426 : : break;
17427 : : default:
17428 : : /*Queue action do nothing*/
17429 : : break;
17430 : : }
17431 : : }
17432 [ # # ]: 0 : for (j = 0; j < MLX5_MTR_DOMAIN_MAX; j++)
17433 : 0 : mtr_policy->dr_drop_action[j] = NULL;
17434 : 0 : }
17435 : :
17436 : : /**
17437 : : * Create yellow action for color aware meter.
17438 : : *
17439 : : * @param[in] dev
17440 : : * Pointer to the Ethernet device structure.
17441 : : * @param[in] fm
17442 : : * Meter information table.
17443 : : * @param[out] error
17444 : : * Perform verbose error reporting if not NULL. Initialized in case of
17445 : : * error only.
17446 : : *
17447 : : * @return
17448 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
17449 : : */
17450 : : static int
17451 : 0 : __flow_dv_create_mtr_yellow_action(struct rte_eth_dev *dev,
17452 : : struct mlx5_flow_meter_info *fm,
17453 : : struct rte_mtr_error *error)
17454 : : {
17455 : : #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
17456 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17457 : : struct rte_flow_error flow_err;
17458 : : struct mlx5_aso_mtr *aso_mtr;
17459 : : struct mlx5_aso_mtr_pool *pool;
17460 : : uint8_t reg_id;
17461 : :
17462 : 0 : aso_mtr = container_of(fm, struct mlx5_aso_mtr, fm);
17463 : 0 : pool = container_of(aso_mtr, struct mlx5_aso_mtr_pool, mtrs[aso_mtr->offset]);
17464 : 0 : reg_id = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &flow_err);
17465 : 0 : fm->meter_action_y =
17466 : 0 : mlx5_glue->dv_create_flow_action_aso(priv->sh->rx_domain,
17467 : 0 : pool->devx_obj->obj,
17468 : : aso_mtr->offset,
17469 : : (1 << MLX5_FLOW_COLOR_YELLOW),
17470 : 0 : reg_id - REG_C_0);
17471 : : #else
17472 : : RTE_SET_USED(dev);
17473 : : #endif
17474 [ # # ]: 0 : if (!fm->meter_action_y) {
17475 : 0 : return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
17476 : : "Fail to create yellow meter action.");
17477 : : }
17478 : : return 0;
17479 : : }
17480 : :
17481 : : /**
17482 : : * Create policy action per domain, lock free,
17483 : : * (mutex should be acquired by caller).
17484 : : * Dispatcher for action type specific call.
17485 : : *
17486 : : * @param[in] dev
17487 : : * Pointer to the Ethernet device structure.
17488 : : * @param[in] mtr_policy
17489 : : * Meter policy struct.
17490 : : * @param[in] action
17491 : : * Action specification used to create meter actions.
17492 : : * @param[in] attr
17493 : : * Pointer to the flow attributes.
17494 : : * @param[out] error
17495 : : * Perform verbose error reporting if not NULL. Initialized in case of
17496 : : * error only.
17497 : : *
17498 : : * @return
17499 : : * 0 on success, otherwise negative errno value.
17500 : : */
17501 : : static int
17502 : 0 : __flow_dv_create_domain_policy_acts(struct rte_eth_dev *dev,
17503 : : struct mlx5_flow_meter_policy *mtr_policy,
17504 : : const struct rte_flow_action *actions[RTE_COLORS],
17505 : : struct rte_flow_attr *attr,
17506 : : enum mlx5_meter_domain domain,
17507 : : struct rte_mtr_error *error)
17508 : : {
17509 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17510 : : struct rte_flow_error flow_err;
17511 : : const struct rte_flow_action *act;
17512 : : uint64_t action_flags;
17513 : : struct mlx5_flow_handle dh;
17514 : : struct mlx5_flow dev_flow;
17515 : : struct mlx5_flow_dv_port_id_action_resource port_id_action;
17516 : : int i, ret;
17517 : : uint8_t egress, transfer;
17518 : : struct mlx5_meter_policy_action_container *act_cnt = NULL;
17519 : : union {
17520 : : struct mlx5_flow_dv_modify_hdr_resource res;
17521 : : uint8_t len[sizeof(struct mlx5_flow_dv_modify_hdr_resource) +
17522 : : sizeof(struct mlx5_modification_cmd) *
17523 : : (MLX5_MAX_MODIFY_NUM + 1)];
17524 : : } mhdr_dummy;
17525 : : struct mlx5_flow_dv_modify_hdr_resource *mhdr_res = &mhdr_dummy.res;
17526 : :
17527 : 0 : egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
17528 [ # # ]: 0 : transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
17529 : : memset(&dh, 0, sizeof(struct mlx5_flow_handle));
17530 : : memset(&dev_flow, 0, sizeof(struct mlx5_flow));
17531 : : memset(&port_id_action, 0,
17532 : : sizeof(struct mlx5_flow_dv_port_id_action_resource));
17533 : : memset(mhdr_res, 0, sizeof(*mhdr_res));
17534 [ # # ]: 0 : mhdr_res->ft_type = transfer ? MLX5DV_FLOW_TABLE_TYPE_FDB :
17535 : : (egress ? MLX5DV_FLOW_TABLE_TYPE_NIC_TX :
17536 : : MLX5DV_FLOW_TABLE_TYPE_NIC_RX);
17537 : 0 : dev_flow.handle = &dh;
17538 : 0 : dev_flow.dv.port_id_action = &port_id_action;
17539 : 0 : dev_flow.external = true;
17540 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
17541 [ # # ]: 0 : if (i < MLX5_MTR_RTE_COLORS)
17542 : 0 : act_cnt = &mtr_policy->act_cnt[i];
17543 : : /* Skip the color policy actions creation. */
17544 [ # # # # : 0 : if ((i == RTE_COLOR_YELLOW && mtr_policy->skip_y) ||
# # ]
17545 [ # # ]: 0 : (i == RTE_COLOR_GREEN && mtr_policy->skip_g))
17546 : 0 : continue;
17547 : : action_flags = 0;
17548 : 0 : for (act = actions[i];
17549 [ # # # # ]: 0 : act && act->type != RTE_FLOW_ACTION_TYPE_END; act++) {
17550 [ # # # # : 0 : switch (act->type) {
# # # # #
# ]
17551 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
17552 : : {
17553 : : uint32_t tag_be = mlx5_flow_mark_set
17554 : : (((const struct rte_flow_action_mark *)
17555 [ # # ]: 0 : (act->conf))->id);
17556 : :
17557 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17558 : 0 : return -rte_mtr_error_set(error,
17559 : : ENOTSUP,
17560 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17561 : : NULL,
17562 : : "cannot create policy "
17563 : : "mark action for this color");
17564 [ # # ]: 0 : if (flow_dv_tag_resource_register(dev, tag_be,
17565 : : &dev_flow, &flow_err))
17566 : 0 : return -rte_mtr_error_set(error,
17567 : : ENOTSUP,
17568 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17569 : : NULL,
17570 : : "cannot setup policy mark action");
17571 : : MLX5_ASSERT(dev_flow.dv.tag_resource);
17572 : 0 : act_cnt->rix_mark =
17573 : 0 : dev_flow.handle->dvh.rix_tag;
17574 : 0 : action_flags |= MLX5_FLOW_ACTION_MARK;
17575 : 0 : mtr_policy->mark = 1;
17576 : 0 : break;
17577 : : }
17578 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TAG:
17579 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17580 : 0 : return -rte_mtr_error_set(error,
17581 : : ENOTSUP,
17582 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17583 : : NULL,
17584 : : "cannot create policy "
17585 : : "set tag action for this color");
17586 [ # # ]: 0 : if (flow_dv_convert_action_set_tag
17587 : : (dev, mhdr_res,
17588 : : (const struct rte_flow_action_set_tag *)
17589 : 0 : act->conf, &flow_err))
17590 : 0 : return -rte_mtr_error_set(error,
17591 : : ENOTSUP,
17592 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17593 : : NULL, "cannot convert policy "
17594 : : "set tag action");
17595 [ # # ]: 0 : if (!mhdr_res->actions_num)
17596 : 0 : return -rte_mtr_error_set(error,
17597 : : ENOTSUP,
17598 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17599 : : NULL, "cannot find policy "
17600 : : "set tag action");
17601 : 0 : action_flags |= MLX5_FLOW_ACTION_SET_TAG;
17602 : 0 : break;
17603 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
17604 : : {
17605 : 0 : struct mlx5_flow_mtr_mng *mtrmng =
17606 : 0 : priv->sh->mtrmng;
17607 : : struct mlx5_flow_tbl_data_entry *tbl_data;
17608 : :
17609 : : /*
17610 : : * Create the drop table with
17611 : : * METER DROP level.
17612 : : */
17613 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
17614 : 0 : mtrmng->drop_tbl[domain] =
17615 : 0 : flow_dv_tbl_resource_get(dev,
17616 : : MLX5_FLOW_TABLE_LEVEL_METER,
17617 : : egress, transfer, false, NULL, 0,
17618 : : 0, MLX5_MTR_TABLE_ID_DROP, &flow_err);
17619 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain])
17620 : 0 : return -rte_mtr_error_set
17621 : : (error, ENOTSUP,
17622 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17623 : : NULL,
17624 : : "Failed to create meter drop table");
17625 : : }
17626 : 0 : tbl_data = container_of
17627 : : (mtrmng->drop_tbl[domain],
17628 : : struct mlx5_flow_tbl_data_entry, tbl);
17629 [ # # ]: 0 : if (i < MLX5_MTR_RTE_COLORS) {
17630 : 0 : act_cnt->dr_jump_action[domain] =
17631 : 0 : tbl_data->jump.action;
17632 : 0 : act_cnt->fate_action =
17633 : : MLX5_FLOW_FATE_DROP;
17634 : : }
17635 [ # # ]: 0 : if (i == RTE_COLOR_RED)
17636 : 0 : mtr_policy->dr_drop_action[domain] =
17637 : 0 : tbl_data->jump.action;
17638 : 0 : action_flags |= MLX5_FLOW_ACTION_DROP;
17639 : 0 : break;
17640 : : }
17641 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
17642 : : {
17643 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17644 : 0 : return -rte_mtr_error_set(error,
17645 : : ENOTSUP,
17646 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17647 : : NULL, "cannot create policy "
17648 : : "fate queue for this color");
17649 : 0 : act_cnt->queue =
17650 : : ((const struct rte_flow_action_queue *)
17651 : 0 : (act->conf))->index;
17652 : 0 : act_cnt->fate_action =
17653 : : MLX5_FLOW_FATE_QUEUE;
17654 : 0 : dev_flow.handle->fate_action =
17655 : : MLX5_FLOW_FATE_QUEUE;
17656 : 0 : mtr_policy->is_queue = 1;
17657 : 0 : action_flags |= MLX5_FLOW_ACTION_QUEUE;
17658 : 0 : break;
17659 : : }
17660 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
17661 : : {
17662 : : int rss_size;
17663 : :
17664 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17665 : 0 : return -rte_mtr_error_set(error,
17666 : : ENOTSUP,
17667 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17668 : : NULL,
17669 : : "cannot create policy "
17670 : : "rss action for this color");
17671 : : /*
17672 : : * Save RSS conf into policy struct
17673 : : * for translate stage.
17674 : : */
17675 : 0 : rss_size = (int)rte_flow_conv
17676 : : (RTE_FLOW_CONV_OP_ACTION,
17677 : : NULL, 0, act, &flow_err);
17678 [ # # ]: 0 : if (rss_size <= 0)
17679 : 0 : return -rte_mtr_error_set(error,
17680 : : ENOTSUP,
17681 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17682 : : NULL, "Get the wrong "
17683 : : "rss action struct size");
17684 : 0 : act_cnt->rss = mlx5_malloc(MLX5_MEM_ZERO,
17685 : : rss_size, 0, SOCKET_ID_ANY);
17686 [ # # ]: 0 : if (!act_cnt->rss)
17687 : 0 : return -rte_mtr_error_set(error,
17688 : : ENOTSUP,
17689 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17690 : : NULL,
17691 : : "Fail to malloc rss action memory");
17692 : 0 : ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTION,
17693 : : act_cnt->rss, rss_size,
17694 : : act, &flow_err);
17695 [ # # ]: 0 : if (ret < 0)
17696 : 0 : return -rte_mtr_error_set(error,
17697 : : ENOTSUP,
17698 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17699 : : NULL, "Fail to save "
17700 : : "rss action into policy struct");
17701 : 0 : act_cnt->fate_action =
17702 : : MLX5_FLOW_FATE_SHARED_RSS;
17703 : 0 : action_flags |= MLX5_FLOW_ACTION_RSS;
17704 : 0 : break;
17705 : : }
17706 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
17707 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
17708 : : {
17709 : : struct mlx5_flow_dv_port_id_action_resource
17710 : : port_id_resource;
17711 : 0 : uint32_t port_id = 0;
17712 : :
17713 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17714 : 0 : return -rte_mtr_error_set(error,
17715 : : ENOTSUP,
17716 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17717 : : NULL, "cannot create policy "
17718 : : "port action for this color");
17719 : : memset(&port_id_resource, 0,
17720 : : sizeof(port_id_resource));
17721 [ # # ]: 0 : if (flow_dv_translate_action_port_id(dev, act,
17722 : : &port_id, &flow_err))
17723 : 0 : return -rte_mtr_error_set(error,
17724 : : ENOTSUP,
17725 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17726 : : NULL, "cannot translate "
17727 : : "policy port action");
17728 : 0 : port_id_resource.port_id = port_id;
17729 [ # # ]: 0 : if (flow_dv_port_id_action_resource_register
17730 : : (dev, &port_id_resource,
17731 : : &dev_flow, &flow_err))
17732 : 0 : return -rte_mtr_error_set(error,
17733 : : ENOTSUP,
17734 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17735 : : NULL, "cannot setup "
17736 : : "policy port action");
17737 : 0 : act_cnt->rix_port_id_action =
17738 : 0 : dev_flow.handle->rix_port_id_action;
17739 : 0 : act_cnt->fate_action =
17740 : : MLX5_FLOW_FATE_PORT_ID;
17741 : 0 : action_flags |= MLX5_FLOW_ACTION_PORT_ID;
17742 : 0 : break;
17743 : : }
17744 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
17745 : : {
17746 : : uint32_t jump_group = 0;
17747 : 0 : uint32_t table = 0;
17748 : : struct mlx5_flow_tbl_data_entry *tbl_data;
17749 : 0 : struct flow_grp_info grp_info = {
17750 : 0 : .external = !!dev_flow.external,
17751 : : .transfer = !!transfer,
17752 : 0 : .fdb_def_rule = !!priv->fdb_def_rule,
17753 : : .std_tbl_fix = 0,
17754 : 0 : .skip_scale = dev_flow.skip_scale &
17755 : : (1 << MLX5_SCALE_FLOW_GROUP_BIT),
17756 : : };
17757 : 0 : struct mlx5_flow_meter_sub_policy *sub_policy =
17758 : 0 : mtr_policy->sub_policys[domain][0];
17759 : :
17760 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17761 : 0 : return -rte_mtr_error_set(error,
17762 : : ENOTSUP,
17763 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17764 : : NULL,
17765 : : "cannot create policy "
17766 : : "jump action for this color");
17767 : 0 : jump_group =
17768 : : ((const struct rte_flow_action_jump *)
17769 : 0 : act->conf)->group;
17770 [ # # ]: 0 : if (mlx5_flow_group_to_table(dev, NULL,
17771 : : jump_group,
17772 : : &table,
17773 : : &grp_info, &flow_err))
17774 : 0 : return -rte_mtr_error_set(error,
17775 : : ENOTSUP,
17776 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17777 : : NULL, "cannot setup "
17778 : : "policy jump action");
17779 : 0 : sub_policy->jump_tbl[i] =
17780 : 0 : flow_dv_tbl_resource_get(dev,
17781 : : table, egress,
17782 : : transfer,
17783 : : !!dev_flow.external,
17784 : : NULL, jump_group, 0,
17785 : : 0, &flow_err);
17786 : : if
17787 [ # # ]: 0 : (!sub_policy->jump_tbl[i])
17788 : 0 : return -rte_mtr_error_set(error,
17789 : : ENOTSUP,
17790 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17791 : : NULL, "cannot create jump action.");
17792 : 0 : tbl_data = container_of
17793 : : (sub_policy->jump_tbl[i],
17794 : : struct mlx5_flow_tbl_data_entry, tbl);
17795 : 0 : act_cnt->dr_jump_action[domain] =
17796 : 0 : tbl_data->jump.action;
17797 : 0 : act_cnt->fate_action =
17798 : : MLX5_FLOW_FATE_JUMP;
17799 : 0 : action_flags |= MLX5_FLOW_ACTION_JUMP;
17800 : 0 : break;
17801 : : }
17802 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
17803 : : {
17804 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS)
17805 : 0 : return -rte_mtr_error_set(error,
17806 : : ENOTSUP,
17807 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17808 : : NULL,
17809 : : "cannot create policy modify field for this color");
17810 [ # # ]: 0 : if (flow_dv_convert_action_modify_field
17811 : : (dev, mhdr_res, act, attr, &flow_err))
17812 : 0 : return -rte_mtr_error_set(error,
17813 : : ENOTSUP,
17814 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17815 : : NULL, "cannot setup policy modify field action");
17816 [ # # ]: 0 : if (!mhdr_res->actions_num)
17817 : 0 : return -rte_mtr_error_set(error,
17818 : : ENOTSUP,
17819 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17820 : : NULL, "cannot find policy modify field action");
17821 : 0 : action_flags |= MLX5_FLOW_ACTION_MODIFY_FIELD;
17822 : 0 : break;
17823 : : }
17824 : : /*
17825 : : * No need to check meter hierarchy for R colors
17826 : : * here since it is done in the validation stage.
17827 : : */
17828 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
17829 : : {
17830 : : const struct rte_flow_action_meter *mtr;
17831 : : struct mlx5_flow_meter_info *next_fm;
17832 : : struct mlx5_flow_meter_policy *next_policy;
17833 : : struct rte_flow_action tag_action;
17834 : : struct mlx5_rte_flow_action_set_tag set_tag;
17835 : 0 : uint32_t next_mtr_idx = 0;
17836 : :
17837 : 0 : mtr = act->conf;
17838 : 0 : next_fm = mlx5_flow_meter_find(priv,
17839 : 0 : mtr->mtr_id,
17840 : : &next_mtr_idx);
17841 [ # # ]: 0 : if (!next_fm)
17842 : 0 : return -rte_mtr_error_set(error, EINVAL,
17843 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
17844 : : "Fail to find next meter.");
17845 [ # # ]: 0 : if (next_fm->def_policy)
17846 : 0 : return -rte_mtr_error_set(error, EINVAL,
17847 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
17848 : : "Hierarchy only supports termination meter.");
17849 : 0 : next_policy = mlx5_flow_meter_policy_find(dev,
17850 : : next_fm->policy_id, NULL);
17851 : : MLX5_ASSERT(next_policy);
17852 [ # # ]: 0 : if (next_fm->drop_cnt) {
17853 : 0 : set_tag.id =
17854 : 0 : (enum modify_reg)
17855 : 0 : mlx5_flow_get_reg_id(dev,
17856 : : MLX5_MTR_ID,
17857 : : 0,
17858 : : (struct rte_flow_error *)error);
17859 : 0 : set_tag.offset = (priv->mtr_reg_share ?
17860 : 0 : MLX5_MTR_COLOR_BITS : 0);
17861 [ # # ]: 0 : set_tag.length = (priv->mtr_reg_share ?
17862 : : MLX5_MTR_IDLE_BITS_IN_COLOR_REG :
17863 : : MLX5_REG_BITS);
17864 : 0 : set_tag.data = next_mtr_idx;
17865 : 0 : tag_action.type =
17866 : : (enum rte_flow_action_type)
17867 : : MLX5_RTE_FLOW_ACTION_TYPE_TAG;
17868 : 0 : tag_action.conf = &set_tag;
17869 [ # # ]: 0 : if (flow_dv_convert_action_set_reg
17870 : : (mhdr_res, &tag_action,
17871 : : (struct rte_flow_error *)error))
17872 : 0 : return -rte_errno;
17873 : 0 : action_flags |=
17874 : : MLX5_FLOW_ACTION_SET_TAG;
17875 : : }
17876 [ # # # # ]: 0 : if (i == RTE_COLOR_YELLOW && next_fm->color_aware &&
17877 [ # # ]: 0 : !next_fm->meter_action_y)
17878 [ # # ]: 0 : if (__flow_dv_create_mtr_yellow_action(dev, next_fm, error))
17879 : 0 : return -rte_errno;
17880 : 0 : act_cnt->fate_action = MLX5_FLOW_FATE_MTR;
17881 : 0 : act_cnt->next_mtr_id = next_fm->meter_id;
17882 : 0 : act_cnt->next_sub_policy = NULL;
17883 : 0 : mtr_policy->is_hierarchy = 1;
17884 [ # # ]: 0 : if (next_policy->mark)
17885 : 0 : mtr_policy->mark = 1;
17886 : 0 : mtr_policy->hierarchy_match_port =
17887 : 0 : next_policy->hierarchy_match_port;
17888 : 0 : action_flags |=
17889 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
17890 : 0 : break;
17891 : : }
17892 : : default:
17893 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
17894 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17895 : : NULL, "action type not supported");
17896 : : }
17897 [ # # ]: 0 : if ((action_flags & MLX5_FLOW_ACTION_SET_TAG) ||
17898 : : (action_flags & MLX5_FLOW_ACTION_MODIFY_FIELD)) {
17899 : : /* create modify action if needed. */
17900 : 0 : dev_flow.dv.group = 1;
17901 [ # # ]: 0 : if (flow_dv_modify_hdr_resource_register
17902 : : (dev, mhdr_res, &dev_flow, &flow_err))
17903 : 0 : return -rte_mtr_error_set(error,
17904 : : ENOTSUP,
17905 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
17906 : : NULL, "cannot register policy set tag/modify field action");
17907 : 0 : act_cnt->modify_hdr =
17908 : 0 : dev_flow.handle->dvh.modify_hdr;
17909 : : }
17910 : : }
17911 : : }
17912 : : return 0;
17913 : : }
17914 : :
17915 : : /**
17916 : : * Create policy action per domain, lock free,
17917 : : * (mutex should be acquired by caller).
17918 : : * Dispatcher for action type specific call.
17919 : : *
17920 : : * @param[in] dev
17921 : : * Pointer to the Ethernet device structure.
17922 : : * @param[in] mtr_policy
17923 : : * Meter policy struct.
17924 : : * @param[in] action
17925 : : * Action specification used to create meter actions.
17926 : : * @param[in] attr
17927 : : * Pointer to the flow attributes.
17928 : : * @param[out] error
17929 : : * Perform verbose error reporting if not NULL. Initialized in case of
17930 : : * error only.
17931 : : *
17932 : : * @return
17933 : : * 0 on success, otherwise negative errno value.
17934 : : */
17935 : : static int
17936 : 0 : flow_dv_create_mtr_policy_acts(struct rte_eth_dev *dev,
17937 : : struct mlx5_flow_meter_policy *mtr_policy,
17938 : : const struct rte_flow_action *actions[RTE_COLORS],
17939 : : struct rte_flow_attr *attr,
17940 : : struct rte_mtr_error *error)
17941 : : {
17942 : : int ret, i;
17943 : : uint16_t sub_policy_num;
17944 : :
17945 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
17946 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
17947 : 0 : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
17948 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
17949 [ # # ]: 0 : if (sub_policy_num) {
17950 : 0 : ret = __flow_dv_create_domain_policy_acts(dev,
17951 : : mtr_policy, actions, attr,
17952 : : (enum mlx5_meter_domain)i, error);
17953 : : /* Cleaning resource is done in the caller level. */
17954 [ # # ]: 0 : if (ret)
17955 : 0 : return ret;
17956 : : }
17957 : : }
17958 : : return 0;
17959 : : }
17960 : :
17961 : : /**
17962 : : * Query a DV flow rule for its statistics via DevX.
17963 : : *
17964 : : * @param[in] dev
17965 : : * Pointer to Ethernet device.
17966 : : * @param[in] cnt_idx
17967 : : * Index to the flow counter.
17968 : : * @param[out] data
17969 : : * Data retrieved by the query.
17970 : : * @param[out] error
17971 : : * Perform verbose error reporting if not NULL.
17972 : : *
17973 : : * @return
17974 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
17975 : : */
17976 : : static int
17977 : 0 : flow_dv_query_count(struct rte_eth_dev *dev, uint32_t cnt_idx, void *data,
17978 : : struct rte_flow_error *error)
17979 : : {
17980 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
17981 : : struct rte_flow_query_count *qc = data;
17982 : :
17983 [ # # ]: 0 : if (!priv->sh->cdev->config.devx)
17984 : 0 : return rte_flow_error_set(error, ENOTSUP,
17985 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17986 : : NULL,
17987 : : "counters are not supported");
17988 [ # # ]: 0 : if (cnt_idx) {
17989 : : uint64_t pkts, bytes;
17990 : : struct mlx5_flow_counter *cnt;
17991 : 0 : int err = _flow_dv_query_count(dev, cnt_idx, &pkts, &bytes);
17992 : :
17993 [ # # ]: 0 : if (err)
17994 : 0 : return rte_flow_error_set(error, -err,
17995 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
17996 : : NULL, "cannot read counters");
17997 : : cnt = flow_dv_counter_get_by_idx(dev, cnt_idx, NULL);
17998 : 0 : qc->hits_set = 1;
17999 : 0 : qc->bytes_set = 1;
18000 : 0 : qc->hits = pkts - cnt->hits;
18001 : 0 : qc->bytes = bytes - cnt->bytes;
18002 [ # # ]: 0 : if (qc->reset) {
18003 : 0 : cnt->hits = pkts;
18004 : 0 : cnt->bytes = bytes;
18005 : : }
18006 : 0 : return 0;
18007 : : }
18008 : 0 : return rte_flow_error_set(error, EINVAL,
18009 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18010 : : NULL,
18011 : : "counters are not available");
18012 : : }
18013 : :
18014 : : int
18015 : 0 : flow_dv_action_query(struct rte_eth_dev *dev,
18016 : : const struct rte_flow_action_handle *handle, void *data,
18017 : : struct rte_flow_error *error)
18018 : : {
18019 : : struct mlx5_age_param *age_param;
18020 : : struct rte_flow_query_age *resp;
18021 : 0 : uint32_t act_idx = (uint32_t)(uintptr_t)handle;
18022 : 0 : uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
18023 : 0 : uint32_t idx = act_idx & ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
18024 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18025 : : struct mlx5_aso_ct_action *ct;
18026 : : uint16_t owner;
18027 : : uint32_t dev_idx;
18028 : :
18029 [ # # # # ]: 0 : switch (type) {
18030 : 0 : case MLX5_INDIRECT_ACTION_TYPE_AGE:
18031 : 0 : age_param = &flow_aso_age_get_by_idx(dev, idx)->age_params;
18032 : : resp = data;
18033 : 0 : resp->aged = rte_atomic_load_explicit(&age_param->state,
18034 : : rte_memory_order_relaxed) == AGE_TMOUT ?
18035 : 0 : 1 : 0;
18036 : 0 : resp->sec_since_last_hit_valid = !resp->aged;
18037 [ # # ]: 0 : if (resp->sec_since_last_hit_valid)
18038 : 0 : resp->sec_since_last_hit = rte_atomic_load_explicit
18039 : : (&age_param->sec_since_last_hit, rte_memory_order_relaxed);
18040 : : return 0;
18041 : 0 : case MLX5_INDIRECT_ACTION_TYPE_COUNT:
18042 : 0 : return flow_dv_query_count(dev, idx, data, error);
18043 : 0 : case MLX5_INDIRECT_ACTION_TYPE_CT:
18044 : 0 : owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(idx);
18045 [ # # ]: 0 : if (owner != PORT_ID(priv))
18046 : 0 : return rte_flow_error_set(error, EACCES,
18047 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18048 : : NULL,
18049 : : "CT object owned by another port");
18050 : 0 : dev_idx = MLX5_INDIRECT_ACT_CT_GET_IDX(idx);
18051 : 0 : ct = flow_aso_ct_get_by_dev_idx(dev, dev_idx);
18052 : : MLX5_ASSERT(ct);
18053 [ # # ]: 0 : if (!ct->refcnt)
18054 : 0 : return rte_flow_error_set(error, EFAULT,
18055 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18056 : : NULL,
18057 : : "CT object is inactive");
18058 : 0 : ((struct rte_flow_action_conntrack *)data)->peer_port =
18059 : 0 : ct->peer;
18060 : 0 : ((struct rte_flow_action_conntrack *)data)->is_original_dir =
18061 : 0 : ct->is_original;
18062 [ # # ]: 0 : if (mlx5_aso_ct_query_by_wqe(priv->sh, MLX5_HW_INV_QUEUE, ct,
18063 : : data, NULL, true))
18064 : 0 : return rte_flow_error_set(error, EIO,
18065 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18066 : : NULL,
18067 : : "Failed to query CT context");
18068 : : return 0;
18069 : 0 : default:
18070 : 0 : return rte_flow_error_set(error, ENOTSUP,
18071 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
18072 : : "action type query not supported");
18073 : : }
18074 : : }
18075 : :
18076 : : /**
18077 : : * Query a flow rule AGE action for aging information.
18078 : : *
18079 : : * @param[in] dev
18080 : : * Pointer to Ethernet device.
18081 : : * @param[in] flow
18082 : : * Pointer to the sub flow.
18083 : : * @param[out] data
18084 : : * data retrieved by the query.
18085 : : * @param[out] error
18086 : : * Perform verbose error reporting if not NULL.
18087 : : *
18088 : : * @return
18089 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
18090 : : */
18091 : : static int
18092 : 0 : flow_dv_query_age(struct rte_eth_dev *dev, struct rte_flow *flow,
18093 : : void *data, struct rte_flow_error *error)
18094 : : {
18095 : : struct rte_flow_query_age *resp = data;
18096 : : struct mlx5_age_param *age_param;
18097 : :
18098 [ # # ]: 0 : if (flow->age) {
18099 : : struct mlx5_aso_age_action *act =
18100 : 0 : flow_aso_age_get_by_idx(dev, flow->age);
18101 : :
18102 : 0 : age_param = &act->age_params;
18103 [ # # ]: 0 : } else if (flow->counter) {
18104 : : age_param = flow_dv_counter_idx_get_age(dev, flow->counter);
18105 : :
18106 [ # # ]: 0 : if (!age_param || !age_param->timeout)
18107 : 0 : return rte_flow_error_set
18108 : : (error, EINVAL,
18109 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18110 : : NULL, "cannot read age data");
18111 : : } else {
18112 : 0 : return rte_flow_error_set(error, EINVAL,
18113 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
18114 : : NULL, "age data not available");
18115 : : }
18116 : 0 : resp->aged = rte_atomic_load_explicit(&age_param->state, rte_memory_order_relaxed) ==
18117 : 0 : AGE_TMOUT ? 1 : 0;
18118 : 0 : resp->sec_since_last_hit_valid = !resp->aged;
18119 [ # # ]: 0 : if (resp->sec_since_last_hit_valid)
18120 : 0 : resp->sec_since_last_hit = rte_atomic_load_explicit
18121 : : (&age_param->sec_since_last_hit, rte_memory_order_relaxed);
18122 : : return 0;
18123 : : }
18124 : :
18125 : : /**
18126 : : * Query a flow.
18127 : : *
18128 : : * @see rte_flow_query()
18129 : : * @see rte_flow_ops
18130 : : */
18131 : : static int
18132 : 0 : flow_dv_query(struct rte_eth_dev *dev,
18133 : : struct rte_flow *flow __rte_unused,
18134 : : const struct rte_flow_action *actions __rte_unused,
18135 : : void *data __rte_unused,
18136 : : struct rte_flow_error *error __rte_unused)
18137 : : {
18138 : : int ret = -EINVAL;
18139 : :
18140 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
18141 [ # # # # ]: 0 : switch (actions->type) {
18142 : : case RTE_FLOW_ACTION_TYPE_VOID:
18143 : : break;
18144 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
18145 : 0 : ret = flow_dv_query_count(dev, flow->counter, data,
18146 : : error);
18147 : 0 : break;
18148 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
18149 [ # # ]: 0 : if (flow->indirect_type == MLX5_INDIRECT_ACTION_TYPE_CT)
18150 : 0 : return rte_flow_error_set(error, ENOTSUP,
18151 : : RTE_FLOW_ERROR_TYPE_ACTION,
18152 : : actions,
18153 : : "age not available");
18154 : 0 : ret = flow_dv_query_age(dev, flow, data, error);
18155 : 0 : break;
18156 : 0 : default:
18157 : 0 : return rte_flow_error_set(error, ENOTSUP,
18158 : : RTE_FLOW_ERROR_TYPE_ACTION,
18159 : : actions,
18160 : : "action not supported");
18161 : : }
18162 : : }
18163 : : return ret;
18164 : : }
18165 : :
18166 : : /**
18167 : : * Destroy the meter table set.
18168 : : * Lock free, (mutex should be acquired by caller).
18169 : : *
18170 : : * @param[in] dev
18171 : : * Pointer to Ethernet device.
18172 : : * @param[in] fm
18173 : : * Meter information table.
18174 : : */
18175 : : static void
18176 : 0 : flow_dv_destroy_mtr_tbls(struct rte_eth_dev *dev,
18177 : : struct mlx5_flow_meter_info *fm)
18178 : : {
18179 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18180 : : int i;
18181 : :
18182 [ # # # # ]: 0 : if (!fm || !priv->sh->config.dv_flow_en)
18183 : : return;
18184 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
18185 [ # # ]: 0 : if (fm->drop_rule[i]) {
18186 : : claim_zero(mlx5_flow_os_destroy_flow(fm->drop_rule[i]));
18187 : 0 : fm->drop_rule[i] = NULL;
18188 : : }
18189 : : }
18190 : : }
18191 : :
18192 : : static void
18193 : 0 : flow_dv_destroy_mtr_drop_tbls(struct rte_eth_dev *dev)
18194 : : {
18195 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18196 : 0 : struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
18197 : : struct mlx5_flow_tbl_data_entry *tbl;
18198 : : int i, j;
18199 : :
18200 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
18201 [ # # ]: 0 : if (mtrmng->def_rule[i]) {
18202 : : claim_zero(mlx5_flow_os_destroy_flow
18203 : : (mtrmng->def_rule[i]));
18204 : 0 : mtrmng->def_rule[i] = NULL;
18205 : : }
18206 [ # # ]: 0 : if (mtrmng->def_matcher[i]) {
18207 : 0 : tbl = container_of(mtrmng->def_matcher[i]->tbl,
18208 : : struct mlx5_flow_tbl_data_entry, tbl);
18209 : 0 : mlx5_list_unregister(tbl->matchers,
18210 : : &mtrmng->def_matcher[i]->entry);
18211 : 0 : mtrmng->def_matcher[i] = NULL;
18212 : : }
18213 [ # # ]: 0 : for (j = 0; j < MLX5_REG_BITS; j++) {
18214 [ # # ]: 0 : if (mtrmng->drop_matcher[i][j]) {
18215 : : tbl =
18216 : 0 : container_of(mtrmng->drop_matcher[i][j]->tbl,
18217 : : struct mlx5_flow_tbl_data_entry,
18218 : : tbl);
18219 : 0 : mlx5_list_unregister(tbl->matchers,
18220 : : &mtrmng->drop_matcher[i][j]->entry);
18221 : 0 : mtrmng->drop_matcher[i][j] = NULL;
18222 : : }
18223 : : }
18224 [ # # ]: 0 : if (mtrmng->drop_tbl[i]) {
18225 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev),
18226 : : mtrmng->drop_tbl[i]);
18227 : 0 : mtrmng->drop_tbl[i] = NULL;
18228 : : }
18229 : : }
18230 : 0 : }
18231 : :
18232 : : /* Number of meter flow actions, count and jump or count and drop. */
18233 : : #define METER_ACTIONS 2
18234 : :
18235 : : static void
18236 : 0 : __flow_dv_destroy_domain_def_policy(struct rte_eth_dev *dev,
18237 : : enum mlx5_meter_domain domain)
18238 : : {
18239 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18240 : 0 : struct mlx5_flow_meter_def_policy *def_policy =
18241 : 0 : priv->sh->mtrmng->def_policy[domain];
18242 : :
18243 : 0 : __flow_dv_destroy_sub_policy_rules(dev, &def_policy->sub_policy);
18244 : 0 : mlx5_free(def_policy);
18245 : 0 : priv->sh->mtrmng->def_policy[domain] = NULL;
18246 : 0 : }
18247 : :
18248 : : /**
18249 : : * Destroy the default policy table set.
18250 : : *
18251 : : * @param[in] dev
18252 : : * Pointer to Ethernet device.
18253 : : */
18254 : : static void
18255 : 0 : flow_dv_destroy_def_policy(struct rte_eth_dev *dev)
18256 : : {
18257 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18258 : : int i;
18259 : :
18260 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++)
18261 [ # # ]: 0 : if (priv->sh->mtrmng->def_policy[i])
18262 : 0 : __flow_dv_destroy_domain_def_policy(dev,
18263 : : (enum mlx5_meter_domain)i);
18264 : 0 : priv->sh->mtrmng->def_policy_id = MLX5_INVALID_POLICY_ID;
18265 : 0 : }
18266 : :
18267 : : static int
18268 : 0 : __flow_dv_create_policy_flow(struct rte_eth_dev *dev,
18269 : : uint32_t color_reg_c_idx,
18270 : : enum rte_color color, struct mlx5_flow_dv_matcher *matcher,
18271 : : int actions_n, void *actions,
18272 : : bool match_src_port, const struct rte_flow_item *item,
18273 : : void **rule, const struct rte_flow_attr *attr)
18274 : : {
18275 : : int ret;
18276 : 0 : struct mlx5_flow_dv_match_params value = {
18277 : : .size = sizeof(value.buf),
18278 : : };
18279 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18280 : : uint8_t misc_mask;
18281 : :
18282 [ # # # # ]: 0 : if (match_src_port && priv->sh->esw_mode) {
18283 [ # # # # ]: 0 : if (item && item->type == RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT)
18284 : 0 : ret = flow_dv_translate_item_represented_port(dev, value.buf,
18285 : : item, attr, MLX5_SET_MATCHER_SW_V);
18286 [ # # # # ]: 0 : else if (item && item->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR)
18287 : 0 : ret = flow_dv_translate_item_port_representor(dev, value.buf,
18288 : : MLX5_SET_MATCHER_SW_V);
18289 : : else
18290 : 0 : ret = flow_dv_translate_item_port_id(dev, value.buf,
18291 : : item, attr, MLX5_SET_MATCHER_SW_V);
18292 [ # # ]: 0 : if (ret) {
18293 : 0 : DRV_LOG(ERR, "Failed to create meter policy%d flow's"
18294 : : " value with port.", color);
18295 : 0 : return -1;
18296 : : }
18297 : : }
18298 : 0 : flow_dv_match_meta_reg(value.buf, (enum modify_reg)color_reg_c_idx,
18299 : : rte_col_2_mlx5_col(color), UINT32_MAX);
18300 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(matcher->mask.buf);
18301 : : __flow_dv_adjust_buf_size(&value.size, misc_mask);
18302 : 0 : ret = mlx5_flow_os_create_flow(matcher->matcher_object, (void *)&value,
18303 : : actions_n, actions, rule);
18304 : : if (ret) {
18305 : 0 : DRV_LOG(ERR, "Failed to create meter policy%d flow.", color);
18306 : 0 : return -1;
18307 : : }
18308 : : return 0;
18309 : : }
18310 : :
18311 : : static int
18312 : 0 : __flow_dv_create_policy_matcher(struct rte_eth_dev *dev,
18313 : : uint32_t color_reg_c_idx,
18314 : : uint16_t priority,
18315 : : struct mlx5_flow_meter_sub_policy *sub_policy,
18316 : : const struct rte_flow_attr *attr,
18317 : : bool match_src_port,
18318 : : const struct rte_flow_item *item,
18319 : : struct mlx5_flow_dv_matcher **policy_matcher,
18320 : : struct rte_flow_error *error)
18321 : : {
18322 : : struct mlx5_list_entry *entry;
18323 : 0 : struct mlx5_flow_tbl_resource *tbl_rsc = sub_policy->tbl_rsc;
18324 : 0 : struct mlx5_flow_dv_matcher matcher = {
18325 : : .mask = {
18326 : : .size = sizeof(matcher.mask.buf),
18327 : : },
18328 : : .tbl = tbl_rsc,
18329 : : };
18330 : 0 : struct mlx5_flow_cb_ctx ctx = {
18331 : : .error = error,
18332 : : .data = &matcher,
18333 : : };
18334 : : struct mlx5_flow_tbl_data_entry *tbl_data;
18335 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18336 : : const uint32_t color_mask = (UINT32_C(1) << MLX5_MTR_COLOR_BITS) - 1;
18337 : : int ret;
18338 : :
18339 [ # # # # ]: 0 : if (match_src_port && priv->sh->esw_mode) {
18340 [ # # # # ]: 0 : if (item && item->type == RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT)
18341 : 0 : ret = flow_dv_translate_item_represented_port(dev, matcher.mask.buf,
18342 : : item, attr, MLX5_SET_MATCHER_SW_M);
18343 [ # # # # ]: 0 : else if (item && item->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR)
18344 : 0 : ret = flow_dv_translate_item_port_representor(dev, matcher.mask.buf,
18345 : : MLX5_SET_MATCHER_SW_M);
18346 : : else
18347 : 0 : ret = flow_dv_translate_item_port_id(dev, matcher.mask.buf,
18348 : : item, attr, MLX5_SET_MATCHER_SW_M);
18349 [ # # ]: 0 : if (ret) {
18350 : 0 : DRV_LOG(ERR, "Failed to register meter policy%d matcher"
18351 : : " with port.", priority);
18352 : 0 : return -1;
18353 : : }
18354 : : }
18355 : 0 : tbl_data = container_of(tbl_rsc, struct mlx5_flow_tbl_data_entry, tbl);
18356 : 0 : flow_dv_match_meta_reg(matcher.mask.buf,
18357 : : (enum modify_reg)color_reg_c_idx, color_mask, color_mask);
18358 : 0 : matcher.priority = priority;
18359 : 0 : matcher.crc = rte_raw_cksum((const void *)matcher.mask.buf,
18360 : : matcher.mask.size);
18361 : 0 : entry = mlx5_list_register(tbl_data->matchers, &ctx);
18362 [ # # ]: 0 : if (!entry) {
18363 : 0 : DRV_LOG(ERR, "Failed to register meter drop matcher.");
18364 : 0 : return -1;
18365 : : }
18366 : 0 : *policy_matcher =
18367 : : container_of(entry, struct mlx5_flow_dv_matcher, entry);
18368 : 0 : return 0;
18369 : : }
18370 : :
18371 : : /**
18372 : : * Create the policy rules per domain.
18373 : : *
18374 : : * @param[in] dev
18375 : : * Pointer to Ethernet device.
18376 : : * @param[in] sub_policy
18377 : : * Pointer to sub policy table..
18378 : : * @param[in] egress
18379 : : * Direction of the table.
18380 : : * @param[in] transfer
18381 : : * E-Switch or NIC flow.
18382 : : * @param[in] acts
18383 : : * Pointer to policy action list per color.
18384 : : *
18385 : : * @return
18386 : : * 0 on success, -1 otherwise.
18387 : : */
18388 : : static int
18389 : 0 : __flow_dv_create_domain_policy_rules(struct rte_eth_dev *dev,
18390 : : struct mlx5_flow_meter_sub_policy *sub_policy,
18391 : : uint8_t egress, uint8_t transfer, bool *match_src_port,
18392 : : struct mlx5_meter_policy_acts acts[RTE_COLORS])
18393 : : {
18394 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18395 : : struct rte_flow_error flow_err;
18396 : : uint32_t color_reg_c_idx;
18397 : 0 : struct rte_flow_attr attr = {
18398 : : .group = MLX5_FLOW_TABLE_LEVEL_POLICY,
18399 : : .priority = 0,
18400 : : .ingress = 0,
18401 : 0 : .egress = !!egress,
18402 : 0 : .transfer = !!transfer,
18403 : : .reserved = 0,
18404 : : };
18405 : : int i;
18406 : : uint16_t priority;
18407 : 0 : int ret = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, &flow_err);
18408 : : struct mlx5_sub_policy_color_rule *color_rule;
18409 : 0 : struct mlx5_sub_policy_color_rule *tmp_rules[RTE_COLORS] = {NULL};
18410 : :
18411 [ # # ]: 0 : if (ret < 0)
18412 : : return -1;
18413 : : /* Create policy table with POLICY level. */
18414 [ # # ]: 0 : if (!sub_policy->tbl_rsc)
18415 : 0 : sub_policy->tbl_rsc = flow_dv_tbl_resource_get(dev,
18416 : : MLX5_FLOW_TABLE_LEVEL_POLICY,
18417 : : egress, transfer, false, NULL, 0, 0,
18418 : 0 : sub_policy->idx, &flow_err);
18419 [ # # ]: 0 : if (!sub_policy->tbl_rsc) {
18420 : 0 : DRV_LOG(ERR,
18421 : : "Failed to create meter sub policy table.");
18422 : 0 : return -1;
18423 : : }
18424 : : /* Prepare matchers. */
18425 : 0 : color_reg_c_idx = ret;
18426 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
18427 : 0 : TAILQ_INIT(&sub_policy->color_rules[i]);
18428 [ # # ]: 0 : if (!acts[i].actions_n)
18429 : 0 : continue;
18430 : 0 : color_rule = mlx5_malloc(MLX5_MEM_ZERO,
18431 : : sizeof(struct mlx5_sub_policy_color_rule),
18432 : : 0, SOCKET_ID_ANY);
18433 [ # # ]: 0 : if (!color_rule) {
18434 : 0 : DRV_LOG(ERR, "No memory to create color rule.");
18435 : 0 : goto err_exit;
18436 : : }
18437 : 0 : tmp_rules[i] = color_rule;
18438 : 0 : TAILQ_INSERT_TAIL(&sub_policy->color_rules[i],
18439 : : color_rule, next_port);
18440 : 0 : color_rule->src_port = priv->representor_id;
18441 : 0 : priority = (match_src_port[i] == match_src_port[RTE_COLOR_GREEN]) ?
18442 : 0 : MLX5_MTR_POLICY_MATCHER_PRIO : (MLX5_MTR_POLICY_MATCHER_PRIO + 1);
18443 : : /* Create matchers for colors. */
18444 [ # # ]: 0 : if (__flow_dv_create_policy_matcher(dev, color_reg_c_idx,
18445 : : priority, sub_policy,
18446 : : &attr, match_src_port[i], NULL,
18447 : : &color_rule->matcher, &flow_err)) {
18448 : 0 : DRV_LOG(ERR, "Failed to create color%u matcher.", i);
18449 : 0 : goto err_exit;
18450 : : }
18451 : : /* Create flow, matching color. */
18452 [ # # ]: 0 : if (__flow_dv_create_policy_flow(dev,
18453 : : color_reg_c_idx, (enum rte_color)i,
18454 : : color_rule->matcher,
18455 : 0 : acts[i].actions_n, acts[i].dv_actions,
18456 : 0 : match_src_port[i], NULL, &color_rule->rule,
18457 : : &attr)) {
18458 : 0 : DRV_LOG(ERR, "Failed to create color%u rule.", i);
18459 : 0 : goto err_exit;
18460 : : }
18461 : : }
18462 : : return 0;
18463 : : err_exit:
18464 : : /* All the policy rules will be cleared. */
18465 : : do {
18466 : 0 : color_rule = tmp_rules[i];
18467 [ # # ]: 0 : if (color_rule) {
18468 [ # # ]: 0 : if (color_rule->rule)
18469 : : mlx5_flow_os_destroy_flow(color_rule->rule);
18470 [ # # ]: 0 : if (color_rule->matcher) {
18471 : : struct mlx5_flow_tbl_data_entry *tbl =
18472 : 0 : container_of(color_rule->matcher->tbl,
18473 : : typeof(*tbl), tbl);
18474 : 0 : mlx5_list_unregister(tbl->matchers,
18475 : : &color_rule->matcher->entry);
18476 : : }
18477 [ # # ]: 0 : TAILQ_REMOVE(&sub_policy->color_rules[i],
18478 : : color_rule, next_port);
18479 : 0 : mlx5_free(color_rule);
18480 : : }
18481 [ # # ]: 0 : } while (i--);
18482 : : return -1;
18483 : : }
18484 : :
18485 : : static int
18486 : 0 : __flow_dv_create_policy_acts_rules(struct rte_eth_dev *dev,
18487 : : struct mlx5_flow_meter_policy *mtr_policy,
18488 : : struct mlx5_flow_meter_sub_policy *sub_policy,
18489 : : uint32_t domain)
18490 : : {
18491 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18492 : : struct mlx5_meter_policy_acts acts[RTE_COLORS];
18493 : : struct mlx5_flow_dv_tag_resource *tag;
18494 : : struct mlx5_flow_dv_port_id_action_resource *port_action;
18495 : : struct mlx5_hrxq *hrxq;
18496 : 0 : struct mlx5_flow_meter_info *next_fm[RTE_COLORS] = {NULL};
18497 : : struct mlx5_flow_meter_policy *next_policy;
18498 : : struct mlx5_flow_meter_sub_policy *next_sub_policy;
18499 : : struct mlx5_flow_tbl_data_entry *tbl_data;
18500 : : struct rte_flow_error error;
18501 : 0 : uint8_t egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
18502 : 0 : uint8_t transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
18503 [ # # # # : 0 : bool mtr_first = egress || (transfer && priv->representor_id != UINT16_MAX);
# # ]
18504 : 0 : bool match_src_port[RTE_COLORS] = {false};
18505 : : int i;
18506 : :
18507 : : /* If RSS or Queue, no previous actions / rules is created. */
18508 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
18509 : 0 : acts[i].actions_n = 0;
18510 [ # # ]: 0 : if (i == RTE_COLOR_RED) {
18511 : : /* Only support drop on red. */
18512 : 0 : acts[i].dv_actions[0] =
18513 : 0 : mtr_policy->dr_drop_action[domain];
18514 : 0 : acts[i].actions_n = 1;
18515 : 0 : continue;
18516 : : }
18517 [ # # ]: 0 : if (mtr_policy->act_cnt[i].fate_action == MLX5_FLOW_FATE_MTR) {
18518 : 0 : struct rte_flow_attr attr = {
18519 : : .transfer = transfer
18520 : : };
18521 : :
18522 : 0 : next_fm[i] = mlx5_flow_meter_find(priv,
18523 : : mtr_policy->act_cnt[i].next_mtr_id,
18524 : : NULL);
18525 [ # # ]: 0 : if (!next_fm[i]) {
18526 : 0 : DRV_LOG(ERR,
18527 : : "Failed to get next hierarchy meter.");
18528 : 0 : goto err_exit;
18529 : : }
18530 [ # # ]: 0 : if (mlx5_flow_meter_attach(priv, next_fm[i],
18531 : : &attr, &error)) {
18532 : 0 : DRV_LOG(ERR, "%s", error.message);
18533 : 0 : next_fm[i] = NULL;
18534 : 0 : goto err_exit;
18535 : : }
18536 : : /* Meter action must be the first for TX. */
18537 [ # # ]: 0 : if (mtr_first) {
18538 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18539 [ # # ]: 0 : (next_fm[i]->color_aware && i == RTE_COLOR_YELLOW) ?
18540 [ # # ]: 0 : next_fm[i]->meter_action_y :
18541 : : next_fm[i]->meter_action_g;
18542 : 0 : acts[i].actions_n++;
18543 : : }
18544 : : }
18545 [ # # ]: 0 : if (mtr_policy->act_cnt[i].rix_mark) {
18546 : 0 : tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG],
18547 : : mtr_policy->act_cnt[i].rix_mark);
18548 [ # # ]: 0 : if (!tag) {
18549 : 0 : DRV_LOG(ERR, "Failed to find "
18550 : : "mark action for policy.");
18551 : 0 : goto err_exit;
18552 : : }
18553 : 0 : acts[i].dv_actions[acts[i].actions_n] = tag->action;
18554 : 0 : acts[i].actions_n++;
18555 : : }
18556 [ # # ]: 0 : if (mtr_policy->act_cnt[i].modify_hdr) {
18557 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18558 : 0 : mtr_policy->act_cnt[i].modify_hdr->action;
18559 : 0 : acts[i].actions_n++;
18560 : : }
18561 [ # # ]: 0 : if (mtr_policy->act_cnt[i].fate_action) {
18562 [ # # # # : 0 : switch (mtr_policy->act_cnt[i].fate_action) {
# ]
18563 : 0 : case MLX5_FLOW_FATE_PORT_ID:
18564 : 0 : port_action = mlx5_ipool_get
18565 : 0 : (priv->sh->ipool[MLX5_IPOOL_PORT_ID],
18566 : : mtr_policy->act_cnt[i].rix_port_id_action);
18567 [ # # ]: 0 : if (!port_action) {
18568 : 0 : DRV_LOG(ERR, "Failed to find "
18569 : : "port action for policy.");
18570 : 0 : goto err_exit;
18571 : : }
18572 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18573 : 0 : port_action->action;
18574 : 0 : acts[i].actions_n++;
18575 : 0 : match_src_port[i] = true;
18576 : 0 : break;
18577 : 0 : case MLX5_FLOW_FATE_DROP:
18578 : : case MLX5_FLOW_FATE_JUMP:
18579 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18580 : 0 : mtr_policy->act_cnt[i].dr_jump_action[domain];
18581 : 0 : acts[i].actions_n++;
18582 : 0 : break;
18583 : 0 : case MLX5_FLOW_FATE_SHARED_RSS:
18584 : : case MLX5_FLOW_FATE_QUEUE:
18585 : 0 : hrxq = mlx5_ipool_get
18586 : 0 : (priv->sh->ipool[MLX5_IPOOL_HRXQ],
18587 : : sub_policy->rix_hrxq[i]);
18588 [ # # ]: 0 : if (!hrxq) {
18589 : 0 : DRV_LOG(ERR, "Failed to find "
18590 : : "queue action for policy.");
18591 : 0 : goto err_exit;
18592 : : }
18593 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18594 : 0 : hrxq->action;
18595 : 0 : acts[i].actions_n++;
18596 : 0 : break;
18597 : 0 : case MLX5_FLOW_FATE_MTR:
18598 [ # # ]: 0 : if (!next_fm[i]) {
18599 : 0 : DRV_LOG(ERR,
18600 : : "No next hierarchy meter.");
18601 : 0 : goto err_exit;
18602 : : }
18603 [ # # ]: 0 : if (!mtr_first) {
18604 : 0 : acts[i].dv_actions[acts[i].actions_n] =
18605 [ # # ]: 0 : (next_fm[i]->color_aware && i == RTE_COLOR_YELLOW) ?
18606 [ # # ]: 0 : next_fm[i]->meter_action_y :
18607 : : next_fm[i]->meter_action_g;
18608 : 0 : acts[i].actions_n++;
18609 : : }
18610 [ # # ]: 0 : if (mtr_policy->act_cnt[i].next_sub_policy) {
18611 : : next_sub_policy =
18612 : : mtr_policy->act_cnt[i].next_sub_policy;
18613 : : } else {
18614 : : next_policy =
18615 : 0 : mlx5_flow_meter_policy_find(dev,
18616 : : next_fm[i]->policy_id, NULL);
18617 : : MLX5_ASSERT(next_policy);
18618 : 0 : next_sub_policy =
18619 : 0 : next_policy->sub_policys[domain][0];
18620 : : }
18621 : : tbl_data =
18622 : 0 : container_of(next_sub_policy->tbl_rsc,
18623 : : struct mlx5_flow_tbl_data_entry, tbl);
18624 : 0 : acts[i].dv_actions[acts[i].actions_n++] =
18625 : 0 : tbl_data->jump.action;
18626 [ # # ]: 0 : if (mtr_policy->act_cnt[i].modify_hdr)
18627 : 0 : match_src_port[i] = !!transfer;
18628 : : break;
18629 : : default:
18630 : : /*Queue action do nothing*/
18631 : : break;
18632 : : }
18633 : : }
18634 : : }
18635 [ # # ]: 0 : if (__flow_dv_create_domain_policy_rules(dev, sub_policy,
18636 : : egress, transfer, match_src_port, acts)) {
18637 : 0 : DRV_LOG(ERR,
18638 : : "Failed to create policy rules per domain.");
18639 : 0 : goto err_exit;
18640 : : }
18641 [ # # # # ]: 0 : if (match_src_port[RTE_COLOR_GREEN] || match_src_port[RTE_COLOR_YELLOW]) {
18642 : 0 : mtr_policy->match_port = 1;
18643 : 0 : mtr_policy->hierarchy_match_port = 1;
18644 : : }
18645 : : return 0;
18646 : : err_exit:
18647 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++)
18648 [ # # ]: 0 : if (next_fm[i])
18649 : 0 : mlx5_flow_meter_detach(priv, next_fm[i]);
18650 : : return -1;
18651 : : }
18652 : :
18653 : : /**
18654 : : * Create the policy rules.
18655 : : *
18656 : : * @param[in] dev
18657 : : * Pointer to Ethernet device.
18658 : : * @param[in,out] mtr_policy
18659 : : * Pointer to meter policy table.
18660 : : *
18661 : : * @return
18662 : : * 0 on success, -1 otherwise.
18663 : : */
18664 : : static int
18665 : 0 : flow_dv_create_policy_rules(struct rte_eth_dev *dev,
18666 : : struct mlx5_flow_meter_policy *mtr_policy)
18667 : : {
18668 : : int i;
18669 : : int ret = 0;
18670 : : uint16_t sub_policy_num;
18671 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_push_thread_workspace();
18672 : :
18673 : : RTE_SET_USED(wks);
18674 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
18675 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
18676 : 0 : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i)) &
18677 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
18678 [ # # ]: 0 : if (!sub_policy_num)
18679 : 0 : continue;
18680 : : /* Prepare actions list and create policy rules. */
18681 [ # # ]: 0 : if (__flow_dv_create_policy_acts_rules(dev, mtr_policy,
18682 : 0 : mtr_policy->sub_policys[i][0], i)) {
18683 : 0 : DRV_LOG(ERR, "Failed to create policy action "
18684 : : "list per domain.");
18685 : : ret = -1;
18686 : 0 : goto exit;
18687 : : }
18688 : : }
18689 : 0 : exit:
18690 : 0 : mlx5_flow_pop_thread_workspace();
18691 : 0 : return ret;
18692 : : }
18693 : :
18694 : : static int
18695 : 0 : __flow_dv_create_domain_def_policy(struct rte_eth_dev *dev, uint32_t domain)
18696 : : {
18697 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18698 : 0 : struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
18699 : : struct mlx5_flow_meter_def_policy *def_policy;
18700 : : struct mlx5_flow_tbl_resource *jump_tbl;
18701 : : struct mlx5_flow_tbl_data_entry *tbl_data;
18702 : : uint8_t egress, transfer;
18703 : : struct rte_flow_error error;
18704 : : struct mlx5_meter_policy_acts acts[RTE_COLORS];
18705 : 0 : bool match_src_port[RTE_COLORS] = {false};
18706 : : int ret;
18707 : :
18708 : 0 : egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
18709 : 0 : transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
18710 : 0 : def_policy = mtrmng->def_policy[domain];
18711 [ # # ]: 0 : if (!def_policy) {
18712 : 0 : def_policy = mlx5_malloc(MLX5_MEM_ZERO,
18713 : : sizeof(struct mlx5_flow_meter_def_policy),
18714 : : RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
18715 [ # # ]: 0 : if (!def_policy) {
18716 : 0 : DRV_LOG(ERR, "Failed to alloc default policy table.");
18717 : 0 : goto def_policy_error;
18718 : : }
18719 : 0 : mtrmng->def_policy[domain] = def_policy;
18720 : : /* Create the meter suffix table with SUFFIX level. */
18721 : 0 : jump_tbl = flow_dv_tbl_resource_get(dev,
18722 : : MLX5_FLOW_TABLE_LEVEL_METER,
18723 : : egress, transfer, false, NULL, 0,
18724 : : 0, MLX5_MTR_TABLE_ID_SUFFIX, &error);
18725 [ # # ]: 0 : if (!jump_tbl) {
18726 : 0 : DRV_LOG(ERR,
18727 : : "Failed to create meter suffix table.");
18728 : 0 : goto def_policy_error;
18729 : : }
18730 : 0 : def_policy->sub_policy.jump_tbl[RTE_COLOR_GREEN] = jump_tbl;
18731 : 0 : tbl_data = container_of(jump_tbl,
18732 : : struct mlx5_flow_tbl_data_entry, tbl);
18733 : 0 : def_policy->dr_jump_action[RTE_COLOR_GREEN] =
18734 : 0 : tbl_data->jump.action;
18735 : 0 : acts[RTE_COLOR_GREEN].dv_actions[0] = tbl_data->jump.action;
18736 : 0 : acts[RTE_COLOR_GREEN].actions_n = 1;
18737 : : /*
18738 : : * YELLOW has the same default policy as GREEN does.
18739 : : * G & Y share the same table and action. The 2nd time of table
18740 : : * resource getting is just to update the reference count for
18741 : : * the releasing stage.
18742 : : */
18743 : 0 : jump_tbl = flow_dv_tbl_resource_get(dev,
18744 : : MLX5_FLOW_TABLE_LEVEL_METER,
18745 : : egress, transfer, false, NULL, 0,
18746 : : 0, MLX5_MTR_TABLE_ID_SUFFIX, &error);
18747 [ # # ]: 0 : if (!jump_tbl) {
18748 : 0 : DRV_LOG(ERR,
18749 : : "Failed to get meter suffix table.");
18750 : 0 : goto def_policy_error;
18751 : : }
18752 : 0 : def_policy->sub_policy.jump_tbl[RTE_COLOR_YELLOW] = jump_tbl;
18753 : 0 : tbl_data = container_of(jump_tbl,
18754 : : struct mlx5_flow_tbl_data_entry, tbl);
18755 : 0 : def_policy->dr_jump_action[RTE_COLOR_YELLOW] =
18756 : 0 : tbl_data->jump.action;
18757 : 0 : acts[RTE_COLOR_YELLOW].dv_actions[0] = tbl_data->jump.action;
18758 : 0 : acts[RTE_COLOR_YELLOW].actions_n = 1;
18759 : : /* Create jump action to the drop table. */
18760 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
18761 : 0 : mtrmng->drop_tbl[domain] = flow_dv_tbl_resource_get
18762 : : (dev, MLX5_FLOW_TABLE_LEVEL_METER,
18763 : : egress, transfer, false, NULL, 0,
18764 : : 0, MLX5_MTR_TABLE_ID_DROP, &error);
18765 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
18766 : 0 : DRV_LOG(ERR, "Failed to create meter "
18767 : : "drop table for default policy.");
18768 : 0 : goto def_policy_error;
18769 : : }
18770 : : }
18771 : : /* all RED: unique Drop table for jump action. */
18772 : 0 : tbl_data = container_of(mtrmng->drop_tbl[domain],
18773 : : struct mlx5_flow_tbl_data_entry, tbl);
18774 : 0 : def_policy->dr_jump_action[RTE_COLOR_RED] =
18775 : 0 : tbl_data->jump.action;
18776 : 0 : acts[RTE_COLOR_RED].dv_actions[0] = tbl_data->jump.action;
18777 : 0 : acts[RTE_COLOR_RED].actions_n = 1;
18778 : : /* Create default policy rules. */
18779 : 0 : ret = __flow_dv_create_domain_policy_rules(dev,
18780 : : &def_policy->sub_policy,
18781 : : egress, transfer, match_src_port, acts);
18782 [ # # ]: 0 : if (ret) {
18783 : 0 : DRV_LOG(ERR, "Failed to create default policy rules.");
18784 : 0 : goto def_policy_error;
18785 : : }
18786 : : }
18787 : : return 0;
18788 : 0 : def_policy_error:
18789 : 0 : __flow_dv_destroy_domain_def_policy(dev,
18790 : : (enum mlx5_meter_domain)domain);
18791 : 0 : return -1;
18792 : : }
18793 : :
18794 : : /**
18795 : : * Create the default policy table set.
18796 : : *
18797 : : * @param[in] dev
18798 : : * Pointer to Ethernet device.
18799 : : * @return
18800 : : * 0 on success, -1 otherwise.
18801 : : */
18802 : : static int
18803 : 0 : flow_dv_create_def_policy(struct rte_eth_dev *dev)
18804 : : {
18805 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18806 : : int i;
18807 : :
18808 : : /* Non-termination policy table. */
18809 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
18810 [ # # # # ]: 0 : if (!priv->sh->config.dv_esw_en &&
18811 : : i == MLX5_MTR_DOMAIN_TRANSFER)
18812 : 0 : continue;
18813 [ # # ]: 0 : if (__flow_dv_create_domain_def_policy(dev, i)) {
18814 : 0 : DRV_LOG(ERR, "Failed to create default policy");
18815 : : /* Rollback the created default policies for others. */
18816 : 0 : flow_dv_destroy_def_policy(dev);
18817 : 0 : return -1;
18818 : : }
18819 : : }
18820 : : return 0;
18821 : : }
18822 : :
18823 : : /**
18824 : : * Create the needed meter tables.
18825 : : * Lock free, (mutex should be acquired by caller).
18826 : : *
18827 : : * @param[in] dev
18828 : : * Pointer to Ethernet device.
18829 : : * @param[in] fm
18830 : : * Meter information table.
18831 : : * @param[in] mtr_idx
18832 : : * Meter index.
18833 : : * @param[in] domain_bitmap
18834 : : * Domain bitmap.
18835 : : * @return
18836 : : * 0 on success, -1 otherwise.
18837 : : */
18838 : : static int
18839 : 0 : flow_dv_create_mtr_tbls(struct rte_eth_dev *dev,
18840 : : struct mlx5_flow_meter_info *fm,
18841 : : uint32_t mtr_idx,
18842 : : uint8_t domain_bitmap)
18843 : : {
18844 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18845 : 0 : struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng;
18846 : : struct rte_flow_error error;
18847 : : struct mlx5_flow_tbl_data_entry *tbl_data;
18848 : : uint8_t egress, transfer;
18849 : : void *actions[METER_ACTIONS];
18850 : : int domain, ret, i;
18851 : : struct mlx5_flow_counter *cnt;
18852 : 0 : struct mlx5_flow_dv_match_params value = {
18853 : : .size = sizeof(value.buf),
18854 : : };
18855 : 0 : struct mlx5_flow_dv_match_params matcher_para = {
18856 : : .size = sizeof(matcher_para.buf),
18857 : : };
18858 : 0 : int mtr_id_reg_c = mlx5_flow_get_reg_id(dev, MLX5_MTR_ID,
18859 : : 0, &error);
18860 : 0 : uint32_t mtr_id_mask = (UINT32_C(1) << mtrmng->max_mtr_bits) - 1;
18861 : 0 : uint8_t mtr_id_offset = priv->mtr_reg_share ? MLX5_MTR_COLOR_BITS : 0;
18862 : : struct mlx5_list_entry *entry;
18863 : 0 : struct mlx5_flow_dv_matcher matcher = {
18864 : : .mask = {
18865 : : .size = sizeof(matcher.mask.buf),
18866 : : },
18867 : : };
18868 : : struct mlx5_flow_dv_matcher *drop_matcher;
18869 : 0 : struct mlx5_flow_cb_ctx ctx = {
18870 : : .error = &error,
18871 : : .data = &matcher,
18872 : : };
18873 : : uint8_t misc_mask;
18874 : :
18875 [ # # # # ]: 0 : if (!priv->mtr_en || mtr_id_reg_c < 0) {
18876 : 0 : rte_errno = ENOTSUP;
18877 : 0 : return -1;
18878 : : }
18879 [ # # ]: 0 : for (domain = 0; domain < MLX5_MTR_DOMAIN_MAX; domain++) {
18880 [ # # ]: 0 : if (!(domain_bitmap & (1 << domain)) ||
18881 [ # # # # ]: 0 : (mtrmng->def_rule[domain] && !fm->drop_cnt))
18882 : 0 : continue;
18883 : 0 : egress = (domain == MLX5_MTR_DOMAIN_EGRESS) ? 1 : 0;
18884 : 0 : transfer = (domain == MLX5_MTR_DOMAIN_TRANSFER) ? 1 : 0;
18885 : : /* Create the drop table with METER DROP level. */
18886 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
18887 : 0 : mtrmng->drop_tbl[domain] = flow_dv_tbl_resource_get(dev,
18888 : : MLX5_FLOW_TABLE_LEVEL_METER,
18889 : : egress, transfer, false, NULL, 0,
18890 : : 0, MLX5_MTR_TABLE_ID_DROP, &error);
18891 [ # # ]: 0 : if (!mtrmng->drop_tbl[domain]) {
18892 : 0 : DRV_LOG(ERR, "Failed to create meter drop table.");
18893 : 0 : goto policy_error;
18894 : : }
18895 : : }
18896 : : /* Create default matcher in drop table. */
18897 : 0 : matcher.tbl = mtrmng->drop_tbl[domain],
18898 : 0 : tbl_data = container_of(mtrmng->drop_tbl[domain],
18899 : : struct mlx5_flow_tbl_data_entry, tbl);
18900 [ # # ]: 0 : if (!mtrmng->def_matcher[domain]) {
18901 : 0 : flow_dv_match_meta_reg_all(matcher.mask.buf, value.buf,
18902 : : (enum modify_reg)mtr_id_reg_c,
18903 : : 0, 0);
18904 : 0 : matcher.priority = MLX5_MTRS_DEFAULT_RULE_PRIORITY;
18905 : 0 : matcher.crc = rte_raw_cksum
18906 : : ((const void *)matcher.mask.buf,
18907 : : matcher.mask.size);
18908 : 0 : entry = mlx5_list_register(tbl_data->matchers, &ctx);
18909 [ # # ]: 0 : if (!entry) {
18910 : 0 : DRV_LOG(ERR, "Failed to register meter "
18911 : : "drop default matcher.");
18912 : 0 : goto policy_error;
18913 : : }
18914 : 0 : mtrmng->def_matcher[domain] = container_of(entry,
18915 : : struct mlx5_flow_dv_matcher, entry);
18916 : : }
18917 : : /* Create default rule in drop table. */
18918 [ # # ]: 0 : if (!mtrmng->def_rule[domain]) {
18919 : : i = 0;
18920 : 0 : actions[i++] = priv->sh->dr_drop_action;
18921 : 0 : flow_dv_match_meta_reg_all(matcher_para.buf, value.buf,
18922 : : (enum modify_reg)mtr_id_reg_c, 0, 0);
18923 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(mtrmng->def_matcher[domain]->mask.buf);
18924 : : __flow_dv_adjust_buf_size(&value.size, misc_mask);
18925 : 0 : ret = mlx5_flow_os_create_flow
18926 : : (mtrmng->def_matcher[domain]->matcher_object,
18927 : : (void *)&value, i, actions,
18928 : : &mtrmng->def_rule[domain]);
18929 : : if (ret) {
18930 : 0 : DRV_LOG(ERR, "Failed to create meter "
18931 : : "default drop rule for drop table.");
18932 : 0 : goto policy_error;
18933 : : }
18934 : : }
18935 [ # # ]: 0 : if (!fm->drop_cnt)
18936 : 0 : continue;
18937 : : MLX5_ASSERT(mtrmng->max_mtr_bits);
18938 [ # # ]: 0 : if (!mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1]) {
18939 : : /* Create matchers for Drop. */
18940 : 0 : flow_dv_match_meta_reg_all(matcher.mask.buf, value.buf,
18941 : : (enum modify_reg)mtr_id_reg_c, 0,
18942 : : (mtr_id_mask << mtr_id_offset));
18943 : 0 : matcher.priority = MLX5_REG_BITS - mtrmng->max_mtr_bits;
18944 : 0 : matcher.crc = rte_raw_cksum
18945 : : ((const void *)matcher.mask.buf,
18946 : : matcher.mask.size);
18947 : 0 : entry = mlx5_list_register(tbl_data->matchers, &ctx);
18948 [ # # ]: 0 : if (!entry) {
18949 : 0 : DRV_LOG(ERR,
18950 : : "Failed to register meter drop matcher.");
18951 : 0 : goto policy_error;
18952 : : }
18953 : 0 : mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1] =
18954 : : container_of(entry, struct mlx5_flow_dv_matcher,
18955 : : entry);
18956 : : }
18957 : 0 : drop_matcher =
18958 : 0 : mtrmng->drop_matcher[domain][mtrmng->max_mtr_bits - 1];
18959 : : /* Create drop rule, matching meter_id only. */
18960 : 0 : flow_dv_match_meta_reg_all(matcher_para.buf, value.buf,
18961 : : (enum modify_reg)mtr_id_reg_c,
18962 : : (mtr_idx << mtr_id_offset), UINT32_MAX);
18963 : : i = 0;
18964 [ # # ]: 0 : cnt = flow_dv_counter_get_by_idx(dev,
18965 : : fm->drop_cnt, NULL);
18966 : 0 : actions[i++] = cnt->action;
18967 : 0 : actions[i++] = priv->sh->dr_drop_action;
18968 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(drop_matcher->mask.buf);
18969 : : __flow_dv_adjust_buf_size(&value.size, misc_mask);
18970 : 0 : ret = mlx5_flow_os_create_flow(drop_matcher->matcher_object,
18971 : : (void *)&value, i, actions,
18972 : : &fm->drop_rule[domain]);
18973 : : if (ret) {
18974 : 0 : DRV_LOG(ERR, "Failed to create meter "
18975 : : "drop rule for drop table.");
18976 : 0 : goto policy_error;
18977 : : }
18978 : : }
18979 : : return 0;
18980 : : policy_error:
18981 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_DOMAIN_MAX; i++) {
18982 [ # # ]: 0 : if (fm->drop_rule[i]) {
18983 : : claim_zero(mlx5_flow_os_destroy_flow
18984 : : (fm->drop_rule[i]));
18985 : 0 : fm->drop_rule[i] = NULL;
18986 : : }
18987 : : }
18988 : : return -1;
18989 : : }
18990 : :
18991 : : static struct mlx5_flow_meter_sub_policy *
18992 : 0 : __flow_dv_meter_get_rss_sub_policy(struct rte_eth_dev *dev,
18993 : : struct mlx5_flow_meter_policy *mtr_policy,
18994 : : struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS],
18995 : : struct mlx5_flow_meter_sub_policy *next_sub_policy,
18996 : : bool *is_reuse)
18997 : : {
18998 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
18999 : : struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
19000 : 0 : uint32_t sub_policy_idx = 0;
19001 : 0 : uint32_t hrxq_idx[MLX5_MTR_RTE_COLORS] = {0};
19002 : : uint32_t i, j;
19003 : : struct mlx5_hrxq *hrxq;
19004 : : struct mlx5_flow_handle dh;
19005 : : struct mlx5_meter_policy_action_container *act_cnt;
19006 : : uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
19007 : : uint16_t sub_policy_num;
19008 : 0 : struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
19009 : :
19010 : : MLX5_ASSERT(wks);
19011 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19012 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
19013 [ # # ]: 0 : if (!rss_desc[i])
19014 : 0 : continue;
19015 : 0 : hrxq = mlx5_hrxq_get(dev, rss_desc[i]);
19016 [ # # ]: 0 : if (!hrxq) {
19017 : : rte_spinlock_unlock(&mtr_policy->sl);
19018 : 0 : return NULL;
19019 : : }
19020 : 0 : hrxq_idx[i] = hrxq->idx;
19021 : : }
19022 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
19023 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
19024 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
19025 [ # # ]: 0 : for (j = 0; j < sub_policy_num; j++) {
19026 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
19027 [ # # ]: 0 : if (rss_desc[i] &&
19028 : 0 : hrxq_idx[i] !=
19029 [ # # ]: 0 : mtr_policy->sub_policys[domain][j]->rix_hrxq[i])
19030 : : break;
19031 : : }
19032 [ # # ]: 0 : if (i >= MLX5_MTR_RTE_COLORS) {
19033 : : /*
19034 : : * Found the sub policy table with
19035 : : * the same queue per color.
19036 : : */
19037 : : rte_spinlock_unlock(&mtr_policy->sl);
19038 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++)
19039 : 0 : mlx5_hrxq_release(dev, hrxq_idx[i]);
19040 : 0 : *is_reuse = true;
19041 : 0 : return mtr_policy->sub_policys[domain][j];
19042 : : }
19043 : : }
19044 : : /* Create sub policy. */
19045 [ # # ]: 0 : if (!mtr_policy->sub_policys[domain][0]->rix_hrxq[RTE_COLOR_GREEN] &&
19046 : : !mtr_policy->sub_policys[domain][0]->rix_hrxq[RTE_COLOR_YELLOW]) {
19047 : : /* Reuse the first pre-allocated sub_policy. */
19048 : : sub_policy = mtr_policy->sub_policys[domain][0];
19049 : 0 : sub_policy_idx = sub_policy->idx;
19050 : : } else {
19051 : 0 : sub_policy = mlx5_ipool_zmalloc
19052 : 0 : (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
19053 : : &sub_policy_idx);
19054 [ # # ]: 0 : if (!sub_policy ||
19055 [ # # ]: 0 : sub_policy_idx > MLX5_MAX_SUB_POLICY_TBL_NUM) {
19056 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++)
19057 : 0 : mlx5_hrxq_release(dev, hrxq_idx[i]);
19058 : 0 : goto rss_sub_policy_error;
19059 : : }
19060 : 0 : sub_policy->idx = sub_policy_idx;
19061 : 0 : sub_policy->main_policy = mtr_policy;
19062 : : }
19063 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
19064 [ # # ]: 0 : if (!rss_desc[i])
19065 : 0 : continue;
19066 : 0 : sub_policy->rix_hrxq[i] = hrxq_idx[i];
19067 [ # # ]: 0 : if (mtr_policy->is_hierarchy) {
19068 : : act_cnt = &mtr_policy->act_cnt[i];
19069 : 0 : act_cnt->next_sub_policy = next_sub_policy;
19070 : 0 : mlx5_hrxq_release(dev, hrxq_idx[i]);
19071 : : } else {
19072 : : /*
19073 : : * Overwrite the last action from
19074 : : * RSS action to Queue action.
19075 : : */
19076 : 0 : hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
19077 : : hrxq_idx[i]);
19078 [ # # ]: 0 : if (!hrxq) {
19079 : 0 : DRV_LOG(ERR, "Failed to get policy hrxq");
19080 : 0 : goto rss_sub_policy_error;
19081 : : }
19082 : : act_cnt = &mtr_policy->act_cnt[i];
19083 [ # # # # ]: 0 : if (act_cnt->rix_mark || act_cnt->modify_hdr) {
19084 : : memset(&dh, 0, sizeof(struct mlx5_flow_handle));
19085 [ # # ]: 0 : if (act_cnt->rix_mark)
19086 : 0 : wks->mark = 1;
19087 : 0 : dh.fate_action = MLX5_FLOW_FATE_QUEUE;
19088 : 0 : dh.rix_hrxq = hrxq_idx[i];
19089 : 0 : flow_drv_rxq_flags_set(dev, &dh);
19090 : : }
19091 : : }
19092 : : }
19093 [ # # ]: 0 : if (__flow_dv_create_policy_acts_rules(dev, mtr_policy,
19094 : : sub_policy, domain)) {
19095 : 0 : DRV_LOG(ERR, "Failed to create policy "
19096 : : "rules for ingress domain.");
19097 : 0 : goto rss_sub_policy_error;
19098 : : }
19099 [ # # ]: 0 : if (sub_policy != mtr_policy->sub_policys[domain][0]) {
19100 : 0 : i = (mtr_policy->sub_policy_num >>
19101 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
19102 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
19103 [ # # ]: 0 : if (i >= MLX5_MTR_RSS_MAX_SUB_POLICY) {
19104 : 0 : DRV_LOG(ERR, "No free sub-policy slot.");
19105 : 0 : goto rss_sub_policy_error;
19106 : : }
19107 : 0 : mtr_policy->sub_policys[domain][i] = sub_policy;
19108 : 0 : i++;
19109 : 0 : mtr_policy->sub_policy_num &= ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
19110 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain));
19111 : 0 : mtr_policy->sub_policy_num |=
19112 : 0 : (i & MLX5_MTR_SUB_POLICY_NUM_MASK) <<
19113 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain);
19114 : : }
19115 : : rte_spinlock_unlock(&mtr_policy->sl);
19116 : 0 : *is_reuse = false;
19117 : 0 : return sub_policy;
19118 : 0 : rss_sub_policy_error:
19119 [ # # ]: 0 : if (sub_policy) {
19120 : 0 : __flow_dv_destroy_sub_policy_rules(dev, sub_policy);
19121 [ # # ]: 0 : if (sub_policy != mtr_policy->sub_policys[domain][0]) {
19122 : 0 : i = (mtr_policy->sub_policy_num >>
19123 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
19124 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
19125 : 0 : mtr_policy->sub_policys[domain][i] = NULL;
19126 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
19127 : 0 : sub_policy->idx);
19128 : : }
19129 : : }
19130 : : rte_spinlock_unlock(&mtr_policy->sl);
19131 : 0 : return NULL;
19132 : : }
19133 : :
19134 : : /**
19135 : : * Find the policy table for prefix table with RSS.
19136 : : *
19137 : : * @param[in] dev
19138 : : * Pointer to Ethernet device.
19139 : : * @param[in] mtr_policy
19140 : : * Pointer to meter policy table.
19141 : : * @param[in] rss_desc
19142 : : * Pointer to rss_desc
19143 : : * @return
19144 : : * Pointer to table set on success, NULL otherwise and rte_errno is set.
19145 : : */
19146 : : static struct mlx5_flow_meter_sub_policy *
19147 : 0 : flow_dv_meter_sub_policy_rss_prepare(struct rte_eth_dev *dev,
19148 : : struct mlx5_flow_meter_policy *mtr_policy,
19149 : : struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS])
19150 : : {
19151 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19152 : : struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
19153 : : struct mlx5_flow_meter_info *next_fm;
19154 : : struct mlx5_flow_meter_policy *next_policy;
19155 : : struct mlx5_flow_meter_sub_policy *next_sub_policy = NULL;
19156 : : struct mlx5_flow_meter_policy *policies[MLX5_MTR_CHAIN_MAX_NUM];
19157 : : struct mlx5_flow_meter_sub_policy *sub_policies[MLX5_MTR_CHAIN_MAX_NUM];
19158 : : uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
19159 : : bool reuse_sub_policy;
19160 : : uint32_t i = 0;
19161 : : uint32_t j = 0;
19162 : :
19163 : : while (true) {
19164 : : /* Iterate hierarchy to get all policies in this hierarchy. */
19165 : 0 : policies[i++] = mtr_policy;
19166 [ # # ]: 0 : if (!mtr_policy->is_hierarchy)
19167 : : break;
19168 [ # # ]: 0 : if (i >= MLX5_MTR_CHAIN_MAX_NUM) {
19169 : 0 : DRV_LOG(ERR, "Exceed max meter number in hierarchy.");
19170 : 0 : return NULL;
19171 : : }
19172 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19173 : 0 : next_fm = mlx5_flow_meter_hierarchy_next_meter(priv, mtr_policy, NULL);
19174 : : rte_spinlock_unlock(&mtr_policy->sl);
19175 [ # # ]: 0 : if (!next_fm) {
19176 : 0 : DRV_LOG(ERR, "Failed to get next meter in hierarchy.");
19177 : 0 : return NULL;
19178 : : }
19179 : : next_policy =
19180 : 0 : mlx5_flow_meter_policy_find(dev, next_fm->policy_id,
19181 : : NULL);
19182 : : MLX5_ASSERT(next_policy);
19183 : : mtr_policy = next_policy;
19184 : : }
19185 [ # # ]: 0 : while (i) {
19186 : : /**
19187 : : * From last policy to the first one in hierarchy,
19188 : : * create / get the sub policy for each of them.
19189 : : */
19190 : 0 : sub_policy = __flow_dv_meter_get_rss_sub_policy(dev,
19191 : : policies[--i],
19192 : : rss_desc,
19193 : : next_sub_policy,
19194 : : &reuse_sub_policy);
19195 [ # # ]: 0 : if (!sub_policy) {
19196 : 0 : DRV_LOG(ERR, "Failed to get the sub policy.");
19197 : 0 : goto err_exit;
19198 : : }
19199 [ # # ]: 0 : if (!reuse_sub_policy)
19200 : 0 : sub_policies[j++] = sub_policy;
19201 : : next_sub_policy = sub_policy;
19202 : : }
19203 : : return sub_policy;
19204 : : err_exit:
19205 [ # # ]: 0 : while (j) {
19206 : : uint16_t sub_policy_num;
19207 : :
19208 : 0 : sub_policy = sub_policies[--j];
19209 : 0 : mtr_policy = sub_policy->main_policy;
19210 : 0 : __flow_dv_destroy_sub_policy_rules(dev, sub_policy);
19211 [ # # ]: 0 : if (sub_policy != mtr_policy->sub_policys[domain][0]) {
19212 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
19213 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
19214 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
19215 : 0 : mtr_policy->sub_policys[domain][sub_policy_num - 1] =
19216 : : NULL;
19217 : 0 : sub_policy_num--;
19218 : 0 : mtr_policy->sub_policy_num &=
19219 : 0 : ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
19220 : 0 : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i));
19221 : 0 : mtr_policy->sub_policy_num |=
19222 : 0 : (sub_policy_num & MLX5_MTR_SUB_POLICY_NUM_MASK) <<
19223 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * i);
19224 : 0 : mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
19225 : 0 : sub_policy->idx);
19226 : : }
19227 : : }
19228 : : return NULL;
19229 : : }
19230 : :
19231 : : /**
19232 : : * Check if need to create hierarchy tag rule.
19233 : : *
19234 : : * @param[in] priv
19235 : : * Pointer to mlx5_priv.
19236 : : * @param[in] mtr_policy
19237 : : * Pointer to current meter policy.
19238 : : * @param[in] src_port
19239 : : * The src port this extra rule should use.
19240 : : * @param[out] next_fm
19241 : : * Pointer to next meter in hierarchy.
19242 : : * @param[out] skip
19243 : : * Indicate if skip the tag rule creation.
19244 : : * @param[out] error
19245 : : * Perform verbose error reporting if not NULL.
19246 : : * @return
19247 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
19248 : : */
19249 : : static int
19250 : 0 : mlx5_meter_hierarchy_skip_tag_rule(struct mlx5_priv *priv,
19251 : : struct mlx5_flow_meter_policy *mtr_policy,
19252 : : int32_t src_port,
19253 : : struct mlx5_flow_meter_info **next_fm,
19254 : : bool *skip,
19255 : : struct rte_flow_error *error)
19256 : : {
19257 : : struct mlx5_flow_meter_sub_policy *sub_policy;
19258 : : struct mlx5_sub_policy_color_rule *color_rule;
19259 : : uint32_t domain = MLX5_MTR_DOMAIN_TRANSFER;
19260 : : int ret = 0;
19261 : : int i;
19262 : :
19263 : 0 : *next_fm = NULL;
19264 : 0 : *skip = false;
19265 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19266 [ # # ]: 0 : if (mtr_policy->is_hierarchy) {
19267 : 0 : *next_fm = mlx5_flow_meter_hierarchy_next_meter(priv, mtr_policy, NULL);
19268 [ # # ]: 0 : if (!*next_fm) {
19269 : 0 : ret = rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
19270 : : NULL, "Failed to find next meter in hierarchy.");
19271 : 0 : goto exit;
19272 : : }
19273 : : }
19274 [ # # ]: 0 : if (!mtr_policy->match_port) {
19275 : 0 : *skip = true;
19276 : 0 : goto exit;
19277 : : }
19278 : 0 : sub_policy = mtr_policy->sub_policys[domain][0];
19279 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
19280 [ # # ]: 0 : if (mtr_policy->act_cnt[i].fate_action != MLX5_FLOW_FATE_MTR &&
19281 : : mtr_policy->act_cnt[i].fate_action != MLX5_FLOW_FATE_PORT_ID)
19282 : 0 : continue;
19283 [ # # ]: 0 : TAILQ_FOREACH(color_rule, &sub_policy->color_rules[i], next_port)
19284 [ # # ]: 0 : if (color_rule->src_port == src_port) {
19285 : 0 : *skip = true;
19286 : 0 : goto exit;
19287 : : }
19288 : : }
19289 : 0 : exit:
19290 : : rte_spinlock_unlock(&mtr_policy->sl);
19291 : 0 : return ret;
19292 : : }
19293 : :
19294 : : /**
19295 : : * Create the sub policy tag rule for all meters in hierarchy.
19296 : : *
19297 : : * @param[in] dev
19298 : : * Pointer to Ethernet device.
19299 : : * @param[in] fm
19300 : : * Meter information table.
19301 : : * @param[in] src_port
19302 : : * The src port this extra rule should use.
19303 : : * @param[in] item
19304 : : * The src port match item.
19305 : : * @param[out] error
19306 : : * Perform verbose error reporting if not NULL.
19307 : : * @return
19308 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
19309 : : */
19310 : : static int
19311 : 0 : flow_dv_meter_hierarchy_rule_create(struct rte_eth_dev *dev,
19312 : : struct mlx5_flow_meter_info *fm,
19313 : : int32_t src_port,
19314 : : const struct rte_flow_item *item,
19315 : : struct rte_flow_error *error)
19316 : : {
19317 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19318 : : struct mlx5_flow_meter_policy *mtr_policy;
19319 : : struct mlx5_flow_meter_sub_policy *sub_policy;
19320 : 0 : struct mlx5_flow_meter_info *next_fm = NULL;
19321 : : struct mlx5_flow_meter_policy *next_policy;
19322 : : struct mlx5_flow_meter_sub_policy *next_sub_policy;
19323 : : struct mlx5_flow_tbl_data_entry *tbl_data;
19324 : : struct mlx5_sub_policy_color_rule *color_rule;
19325 : : struct mlx5_meter_policy_acts acts;
19326 : : uint32_t color_reg_c_idx;
19327 : : bool mtr_first = (src_port != UINT16_MAX) ? true : false;
19328 : 0 : struct rte_flow_attr attr = {
19329 : : .group = MLX5_FLOW_TABLE_LEVEL_POLICY,
19330 : : .priority = 0,
19331 : : .ingress = 0,
19332 : : .egress = 0,
19333 : : .transfer = 1,
19334 : : .reserved = 0,
19335 : : };
19336 : : uint32_t domain = MLX5_MTR_DOMAIN_TRANSFER;
19337 : : struct {
19338 : : struct mlx5_flow_meter_policy *fm_policy;
19339 : : struct mlx5_flow_meter_info *next_fm;
19340 : : struct mlx5_sub_policy_color_rule *tag_rule[RTE_COLORS];
19341 : 0 : } fm_info[MLX5_MTR_CHAIN_MAX_NUM] = { {0} };
19342 : : uint32_t fm_cnt = 0;
19343 : : uint32_t i, j;
19344 : :
19345 : 0 : color_reg_c_idx = mlx5_flow_get_reg_id(dev, MLX5_MTR_COLOR, 0, error);
19346 : : /* Get all fms who need to create the tag color rule. */
19347 : : do {
19348 : 0 : bool skip = false;
19349 : :
19350 : 0 : mtr_policy = mlx5_flow_meter_policy_find(dev, fm->policy_id, NULL);
19351 : : MLX5_ASSERT(mtr_policy);
19352 [ # # ]: 0 : if (mlx5_meter_hierarchy_skip_tag_rule(priv, mtr_policy, src_port,
19353 : : &next_fm, &skip, error))
19354 : 0 : goto err_exit;
19355 [ # # ]: 0 : if (!skip) {
19356 : 0 : fm_info[fm_cnt].fm_policy = mtr_policy;
19357 : 0 : fm_info[fm_cnt].next_fm = next_fm;
19358 [ # # ]: 0 : if (++fm_cnt >= MLX5_MTR_CHAIN_MAX_NUM) {
19359 : 0 : rte_flow_error_set(error, errno,
19360 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
19361 : : "Exceed max meter number in hierarchy.");
19362 : 0 : goto err_exit;
19363 : : }
19364 : : }
19365 : 0 : fm = next_fm;
19366 [ # # ]: 0 : } while (fm);
19367 : : /* Create tag color rules for all needed fms. */
19368 [ # # ]: 0 : for (i = 0; i < fm_cnt; i++) {
19369 : : void *mtr_action;
19370 : :
19371 : 0 : mtr_policy = fm_info[i].fm_policy;
19372 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19373 : 0 : sub_policy = mtr_policy->sub_policys[domain][0];
19374 [ # # ]: 0 : for (j = 0; j < RTE_COLORS; j++) {
19375 : : uint8_t act_n = 0;
19376 : : struct mlx5_flow_dv_modify_hdr_resource *modify_hdr = NULL;
19377 : : struct mlx5_flow_dv_port_id_action_resource *port_action;
19378 : : uint8_t fate_action;
19379 : :
19380 [ # # ]: 0 : if (j == RTE_COLOR_RED) {
19381 : : fate_action = MLX5_FLOW_FATE_DROP;
19382 : : } else {
19383 : 0 : fate_action = mtr_policy->act_cnt[j].fate_action;
19384 : 0 : modify_hdr = mtr_policy->act_cnt[j].modify_hdr;
19385 : 0 : if (fate_action != MLX5_FLOW_FATE_MTR &&
19386 [ # # # # ]: 0 : fate_action != MLX5_FLOW_FATE_PORT_ID &&
19387 : : fate_action != MLX5_FLOW_FATE_DROP)
19388 : 0 : continue;
19389 : : }
19390 : 0 : color_rule = mlx5_malloc(MLX5_MEM_ZERO,
19391 : : sizeof(struct mlx5_sub_policy_color_rule),
19392 : : 0, SOCKET_ID_ANY);
19393 [ # # ]: 0 : if (!color_rule) {
19394 : : rte_spinlock_unlock(&mtr_policy->sl);
19395 : 0 : rte_flow_error_set(error, ENOMEM,
19396 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
19397 : : "No memory to create tag color rule.");
19398 : 0 : goto err_exit;
19399 : : }
19400 : 0 : color_rule->src_port = src_port;
19401 : : /* Prepare to create color rule. */
19402 [ # # ]: 0 : if (fate_action == MLX5_FLOW_FATE_MTR) {
19403 : 0 : next_fm = fm_info[i].next_fm;
19404 [ # # ]: 0 : if (mlx5_flow_meter_attach(priv, next_fm, &attr, error)) {
19405 : 0 : mlx5_free(color_rule);
19406 : : rte_spinlock_unlock(&mtr_policy->sl);
19407 : 0 : goto err_exit;
19408 : : }
19409 [ # # ]: 0 : mtr_action = (next_fm->color_aware && j == RTE_COLOR_YELLOW) ?
19410 [ # # ]: 0 : next_fm->meter_action_y :
19411 : : next_fm->meter_action_g;
19412 : 0 : next_policy = mlx5_flow_meter_policy_find(dev, next_fm->policy_id,
19413 : : NULL);
19414 : : MLX5_ASSERT(next_policy);
19415 : 0 : next_sub_policy = next_policy->sub_policys[domain][0];
19416 : 0 : tbl_data = container_of(next_sub_policy->tbl_rsc,
19417 : : struct mlx5_flow_tbl_data_entry, tbl);
19418 [ # # ]: 0 : if (mtr_first) {
19419 : 0 : acts.dv_actions[act_n++] = mtr_action;
19420 [ # # ]: 0 : if (modify_hdr)
19421 : 0 : acts.dv_actions[act_n++] = modify_hdr->action;
19422 : : } else {
19423 [ # # ]: 0 : if (modify_hdr)
19424 : 0 : acts.dv_actions[act_n++] = modify_hdr->action;
19425 : 0 : acts.dv_actions[act_n++] = mtr_action;
19426 : : }
19427 : 0 : acts.dv_actions[act_n++] = tbl_data->jump.action;
19428 : 0 : acts.actions_n = act_n;
19429 [ # # ]: 0 : } else if (fate_action == MLX5_FLOW_FATE_PORT_ID) {
19430 : : port_action =
19431 : 0 : mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PORT_ID],
19432 : : mtr_policy->act_cnt[j].rix_port_id_action);
19433 [ # # ]: 0 : if (!port_action) {
19434 : 0 : mlx5_free(color_rule);
19435 : : rte_spinlock_unlock(&mtr_policy->sl);
19436 : 0 : goto err_exit;
19437 : : }
19438 [ # # ]: 0 : if (modify_hdr)
19439 : 0 : acts.dv_actions[act_n++] = modify_hdr->action;
19440 : 0 : acts.dv_actions[act_n++] = port_action->action;
19441 : 0 : acts.actions_n = act_n;
19442 : : } else {
19443 : 0 : acts.dv_actions[act_n++] = mtr_policy->dr_drop_action[domain];
19444 : 0 : acts.actions_n = act_n;
19445 : : }
19446 : 0 : fm_info[i].tag_rule[j] = color_rule;
19447 : 0 : TAILQ_INSERT_TAIL(&sub_policy->color_rules[j], color_rule, next_port);
19448 [ # # ]: 0 : if (__flow_dv_create_policy_matcher(dev, color_reg_c_idx,
19449 : : MLX5_MTR_POLICY_MATCHER_PRIO, sub_policy,
19450 : : &attr, true, item, &color_rule->matcher, error)) {
19451 : : rte_spinlock_unlock(&mtr_policy->sl);
19452 : 0 : rte_flow_error_set(error, errno,
19453 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
19454 : : "Failed to create hierarchy meter matcher.");
19455 : 0 : goto err_exit;
19456 : : }
19457 [ # # ]: 0 : if (__flow_dv_create_policy_flow(dev, color_reg_c_idx, (enum rte_color)j,
19458 : : color_rule->matcher,
19459 : 0 : acts.actions_n, acts.dv_actions,
19460 : : true, item, &color_rule->rule, &attr)) {
19461 : : rte_spinlock_unlock(&mtr_policy->sl);
19462 : 0 : rte_flow_error_set(error, errno,
19463 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
19464 : : "Failed to create hierarchy meter rule.");
19465 : 0 : goto err_exit;
19466 : : }
19467 : : }
19468 : : rte_spinlock_unlock(&mtr_policy->sl);
19469 : : }
19470 : : return 0;
19471 : 0 : err_exit:
19472 [ # # ]: 0 : for (i = 0; i < fm_cnt; i++) {
19473 : 0 : mtr_policy = fm_info[i].fm_policy;
19474 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19475 : 0 : sub_policy = mtr_policy->sub_policys[domain][0];
19476 [ # # ]: 0 : for (j = 0; j < RTE_COLORS; j++) {
19477 : 0 : color_rule = fm_info[i].tag_rule[j];
19478 [ # # ]: 0 : if (!color_rule)
19479 : 0 : continue;
19480 [ # # ]: 0 : if (color_rule->rule)
19481 : : mlx5_flow_os_destroy_flow(color_rule->rule);
19482 [ # # ]: 0 : if (color_rule->matcher) {
19483 : : struct mlx5_flow_tbl_data_entry *tbl =
19484 : 0 : container_of(color_rule->matcher->tbl, typeof(*tbl), tbl);
19485 : 0 : mlx5_list_unregister(tbl->matchers, &color_rule->matcher->entry);
19486 : : }
19487 [ # # ]: 0 : if (fm_info[i].next_fm)
19488 : 0 : mlx5_flow_meter_detach(priv, fm_info[i].next_fm);
19489 [ # # ]: 0 : TAILQ_REMOVE(&sub_policy->color_rules[j], color_rule, next_port);
19490 : 0 : mlx5_free(color_rule);
19491 : : }
19492 : : rte_spinlock_unlock(&mtr_policy->sl);
19493 : : }
19494 : 0 : return -rte_errno;
19495 : : }
19496 : :
19497 : : /**
19498 : : * Destroy the sub policy table with RX queue.
19499 : : *
19500 : : * @param[in] dev
19501 : : * Pointer to Ethernet device.
19502 : : * @param[in] mtr_policy
19503 : : * Pointer to meter policy table.
19504 : : */
19505 : : static void
19506 : 0 : flow_dv_destroy_sub_policy_with_rxq(struct rte_eth_dev *dev,
19507 : : struct mlx5_flow_meter_policy *mtr_policy)
19508 : : {
19509 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19510 : : struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
19511 : : uint32_t domain = MLX5_MTR_DOMAIN_INGRESS;
19512 : : uint32_t i, j;
19513 : : uint16_t sub_policy_num, new_policy_num;
19514 : :
19515 : 0 : rte_spinlock_lock(&mtr_policy->sl);
19516 [ # # ]: 0 : for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
19517 [ # # # ]: 0 : switch (mtr_policy->act_cnt[i].fate_action) {
19518 : 0 : case MLX5_FLOW_FATE_SHARED_RSS:
19519 : 0 : sub_policy_num = (mtr_policy->sub_policy_num >>
19520 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain)) &
19521 : : MLX5_MTR_SUB_POLICY_NUM_MASK;
19522 : : new_policy_num = sub_policy_num;
19523 [ # # ]: 0 : for (j = 0; j < sub_policy_num; j++) {
19524 : 0 : sub_policy =
19525 : 0 : mtr_policy->sub_policys[domain][j];
19526 [ # # ]: 0 : if (sub_policy) {
19527 : 0 : __flow_dv_destroy_sub_policy_rules(dev,
19528 : : sub_policy);
19529 : 0 : if (sub_policy !=
19530 [ # # ]: 0 : mtr_policy->sub_policys[domain][0]) {
19531 : 0 : mtr_policy->sub_policys[domain][j] =
19532 : : NULL;
19533 : 0 : mlx5_ipool_free
19534 : 0 : (priv->sh->ipool[MLX5_IPOOL_MTR_POLICY],
19535 : 0 : sub_policy->idx);
19536 : 0 : new_policy_num--;
19537 : : }
19538 : : }
19539 : : }
19540 [ # # ]: 0 : if (new_policy_num != sub_policy_num) {
19541 : 0 : mtr_policy->sub_policy_num &=
19542 : : ~(MLX5_MTR_SUB_POLICY_NUM_MASK <<
19543 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain));
19544 : 0 : mtr_policy->sub_policy_num |=
19545 : : (new_policy_num &
19546 : : MLX5_MTR_SUB_POLICY_NUM_MASK) <<
19547 : : (MLX5_MTR_SUB_POLICY_NUM_SHIFT * domain);
19548 : : }
19549 : : break;
19550 : 0 : case MLX5_FLOW_FATE_QUEUE:
19551 : 0 : sub_policy = mtr_policy->sub_policys[domain][0];
19552 : 0 : __flow_dv_destroy_sub_policy_rules(dev,
19553 : : sub_policy);
19554 : 0 : break;
19555 : : default:
19556 : : /*Other actions without queue and do nothing*/
19557 : : break;
19558 : : }
19559 : : }
19560 : : rte_spinlock_unlock(&mtr_policy->sl);
19561 : 0 : }
19562 : : /**
19563 : : * Check whether the DR drop action is supported on the root table or not.
19564 : : *
19565 : : * Create a simple flow with DR drop action on root table to validate
19566 : : * if DR drop action on root table is supported or not.
19567 : : *
19568 : : * @param[in] dev
19569 : : * Pointer to rte_eth_dev structure.
19570 : : *
19571 : : * @return
19572 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
19573 : : */
19574 : : int
19575 : 0 : mlx5_flow_discover_dr_action_support(struct rte_eth_dev *dev)
19576 : : {
19577 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19578 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
19579 : 0 : struct mlx5_flow_dv_match_params mask = {
19580 : : .size = sizeof(mask.buf),
19581 : : };
19582 : 0 : struct mlx5_flow_dv_match_params value = {
19583 : : .size = sizeof(value.buf),
19584 : : };
19585 : 0 : struct mlx5dv_flow_matcher_attr dv_attr = {
19586 : : .type = IBV_FLOW_ATTR_NORMAL,
19587 : : .priority = 0,
19588 : : .match_criteria_enable = 0,
19589 : : .match_mask = (void *)&mask,
19590 : : };
19591 : : struct mlx5_flow_tbl_resource *tbl = NULL;
19592 : : void *matcher = NULL;
19593 : : void *flow = NULL;
19594 : : int ret = -1;
19595 : :
19596 : 0 : tbl = flow_dv_tbl_resource_get(dev, 0, 0, 0, false, NULL,
19597 : : 0, 0, 0, NULL);
19598 [ # # ]: 0 : if (!tbl)
19599 : 0 : goto err;
19600 [ # # ]: 0 : dv_attr.match_criteria_enable = flow_dv_matcher_enable(mask.buf);
19601 : : __flow_dv_adjust_buf_size(&mask.size, dv_attr.match_criteria_enable);
19602 : 0 : ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
19603 : : tbl->obj, &matcher);
19604 : : if (ret)
19605 : 0 : goto err;
19606 [ # # ]: 0 : __flow_dv_adjust_buf_size(&value.size, dv_attr.match_criteria_enable);
19607 : 0 : ret = mlx5_flow_os_create_flow(matcher, (void *)&value, 1,
19608 : : &sh->dr_drop_action, &flow);
19609 : 0 : err:
19610 : : /*
19611 : : * If DR drop action is not supported on root table, flow create will
19612 : : * be failed with EOPNOTSUPP or EPROTONOSUPPORT.
19613 : : */
19614 [ # # ]: 0 : if (!flow) {
19615 [ # # ]: 0 : if (matcher &&
19616 [ # # ]: 0 : (errno == EPROTONOSUPPORT || errno == EOPNOTSUPP))
19617 : 0 : DRV_LOG(INFO, "DR drop action is not supported in root table.");
19618 : : else
19619 : 0 : DRV_LOG(ERR, "Unexpected error in DR drop action support detection");
19620 : : ret = -1;
19621 : : } else {
19622 : : claim_zero(mlx5_flow_os_destroy_flow(flow));
19623 : : }
19624 [ # # ]: 0 : if (matcher)
19625 : : claim_zero(mlx5_flow_os_destroy_flow_matcher(matcher));
19626 [ # # ]: 0 : if (tbl)
19627 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
19628 : 0 : return ret;
19629 : : }
19630 : :
19631 : : /**
19632 : : * Validate the batch counter support in root table.
19633 : : *
19634 : : * Create a simple flow with invalid counter and drop action on root table to
19635 : : * validate if batch counter with offset on root table is supported or not.
19636 : : *
19637 : : * @param[in] dev
19638 : : * Pointer to rte_eth_dev structure.
19639 : : *
19640 : : * @return
19641 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
19642 : : */
19643 : : int
19644 : 0 : mlx5_flow_dv_discover_counter_offset_support(struct rte_eth_dev *dev)
19645 : : {
19646 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19647 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
19648 : 0 : struct mlx5_flow_dv_match_params mask = {
19649 : : .size = sizeof(mask.buf),
19650 : : };
19651 : 0 : struct mlx5_flow_dv_match_params value = {
19652 : : .size = sizeof(value.buf),
19653 : : };
19654 : 0 : struct mlx5dv_flow_matcher_attr dv_attr = {
19655 : : .type = IBV_FLOW_ATTR_NORMAL | IBV_FLOW_ATTR_FLAGS_EGRESS,
19656 : : .priority = 0,
19657 : : .match_criteria_enable = 0,
19658 : : .match_mask = (void *)&mask,
19659 : : };
19660 : 0 : void *actions[2] = { 0 };
19661 : : struct mlx5_flow_tbl_resource *tbl = NULL;
19662 : : struct mlx5_devx_obj *dcs = NULL;
19663 : : void *matcher = NULL;
19664 : : void *flow = NULL;
19665 : : int ret = -1;
19666 : :
19667 : 0 : tbl = flow_dv_tbl_resource_get(dev, 0, 1, 0, false, NULL,
19668 : : 0, 0, 0, NULL);
19669 [ # # ]: 0 : if (!tbl)
19670 : 0 : goto err;
19671 : 0 : dcs = mlx5_devx_cmd_flow_counter_alloc(priv->sh->cdev->ctx, 0x4);
19672 [ # # ]: 0 : if (!dcs)
19673 : 0 : goto err;
19674 : 0 : ret = mlx5_flow_os_create_flow_action_count(dcs->obj, UINT16_MAX,
19675 : : &actions[0]);
19676 : : if (ret)
19677 : 0 : goto err;
19678 [ # # ]: 0 : dv_attr.match_criteria_enable = flow_dv_matcher_enable(mask.buf);
19679 : : __flow_dv_adjust_buf_size(&mask.size, dv_attr.match_criteria_enable);
19680 : 0 : ret = mlx5_flow_os_create_flow_matcher(sh->cdev->ctx, &dv_attr,
19681 : : tbl->obj, &matcher);
19682 : : if (ret)
19683 : 0 : goto err;
19684 [ # # ]: 0 : __flow_dv_adjust_buf_size(&value.size, dv_attr.match_criteria_enable);
19685 : : ret = mlx5_flow_os_create_flow(matcher, (void *)&value, 1,
19686 : : actions, &flow);
19687 : 0 : err:
19688 : : /*
19689 : : * If batch counter with offset is not supported, the driver will not
19690 : : * validate the invalid offset value, flow create should success.
19691 : : * In this case, it means batch counter is not supported in root table.
19692 : : *
19693 : : * Otherwise, if flow create is failed, counter offset is supported.
19694 : : */
19695 [ # # ]: 0 : if (flow) {
19696 : 0 : DRV_LOG(INFO, "Batch counter is not supported in root "
19697 : : "table. Switch to fallback mode.");
19698 : 0 : rte_errno = ENOTSUP;
19699 : : ret = -rte_errno;
19700 : : claim_zero(mlx5_flow_os_destroy_flow(flow));
19701 : : } else {
19702 : : /* Check matcher to make sure validate fail at flow create. */
19703 [ # # # # ]: 0 : if (!matcher || (matcher && errno != EINVAL))
19704 : 0 : DRV_LOG(ERR, "Unexpected error in counter offset "
19705 : : "support detection");
19706 : : ret = 0;
19707 : : }
19708 [ # # ]: 0 : if (actions[0])
19709 : : claim_zero(mlx5_flow_os_destroy_flow_action(actions[0]));
19710 [ # # ]: 0 : if (matcher)
19711 : : claim_zero(mlx5_flow_os_destroy_flow_matcher(matcher));
19712 [ # # ]: 0 : if (tbl)
19713 : 0 : flow_dv_tbl_resource_release(MLX5_SH(dev), tbl);
19714 [ # # ]: 0 : if (dcs)
19715 : 0 : claim_zero(mlx5_devx_cmd_destroy(dcs));
19716 : 0 : return ret;
19717 : : }
19718 : :
19719 : : /**
19720 : : * Query a devx counter.
19721 : : *
19722 : : * @param[in] dev
19723 : : * Pointer to the Ethernet device structure.
19724 : : * @param[in] cnt
19725 : : * Index to the flow counter.
19726 : : * @param[in] clear
19727 : : * Set to clear the counter statistics.
19728 : : * @param[out] pkts
19729 : : * The statistics value of packets.
19730 : : * @param[out] bytes
19731 : : * The statistics value of bytes.
19732 : : *
19733 : : * @return
19734 : : * 0 on success, otherwise return -1.
19735 : : */
19736 : : static int
19737 : 0 : flow_dv_counter_query(struct rte_eth_dev *dev, uint32_t counter, bool clear,
19738 : : uint64_t *pkts, uint64_t *bytes, void **action)
19739 : : {
19740 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19741 : : struct mlx5_flow_counter *cnt;
19742 : : uint64_t inn_pkts, inn_bytes;
19743 : : int ret;
19744 : :
19745 [ # # ]: 0 : if (!priv->sh->cdev->config.devx)
19746 : : return -1;
19747 : :
19748 : 0 : ret = _flow_dv_query_count(dev, counter, &inn_pkts, &inn_bytes);
19749 [ # # ]: 0 : if (ret)
19750 : : return -1;
19751 : : cnt = flow_dv_counter_get_by_idx(dev, counter, NULL);
19752 [ # # ]: 0 : if (cnt && action)
19753 : 0 : *action = cnt->action;
19754 : :
19755 : 0 : *pkts = inn_pkts - cnt->hits;
19756 : 0 : *bytes = inn_bytes - cnt->bytes;
19757 [ # # ]: 0 : if (clear) {
19758 : 0 : cnt->hits = inn_pkts;
19759 : 0 : cnt->bytes = inn_bytes;
19760 : : }
19761 : : return 0;
19762 : : }
19763 : :
19764 : : /**
19765 : : * Get aged-out flows.
19766 : : *
19767 : : * @param[in] dev
19768 : : * Pointer to the Ethernet device structure.
19769 : : * @param[in] context
19770 : : * The address of an array of pointers to the aged-out flows contexts.
19771 : : * @param[in] nb_contexts
19772 : : * The length of context array pointers.
19773 : : * @param[out] error
19774 : : * Perform verbose error reporting if not NULL. Initialized in case of
19775 : : * error only.
19776 : : *
19777 : : * @return
19778 : : * how many contexts get in success, otherwise negative errno value.
19779 : : * if nb_contexts is 0, return the amount of all aged contexts.
19780 : : * if nb_contexts is not 0 , return the amount of aged flows reported
19781 : : * in the context array.
19782 : : * @note: only stub for now
19783 : : */
19784 : : static int
19785 : 0 : flow_dv_get_aged_flows(struct rte_eth_dev *dev,
19786 : : void **context,
19787 : : uint32_t nb_contexts,
19788 : : struct rte_flow_error *error)
19789 : : {
19790 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19791 : : struct mlx5_age_info *age_info;
19792 : : struct mlx5_age_param *age_param;
19793 : : struct mlx5_flow_counter *counter;
19794 : : struct mlx5_aso_age_action *act;
19795 : : int nb_flows = 0;
19796 : :
19797 [ # # ]: 0 : if (nb_contexts && !context)
19798 : 0 : return rte_flow_error_set(error, EINVAL,
19799 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
19800 : : NULL, "empty context");
19801 : 0 : age_info = GET_PORT_AGE_INFO(priv);
19802 : 0 : rte_spinlock_lock(&age_info->aged_sl);
19803 [ # # ]: 0 : LIST_FOREACH(act, &age_info->aged_aso, next) {
19804 : 0 : nb_flows++;
19805 [ # # ]: 0 : if (nb_contexts) {
19806 : 0 : context[nb_flows - 1] = act->age_params.context;
19807 [ # # ]: 0 : if (!(--nb_contexts))
19808 : : break;
19809 : : }
19810 : : }
19811 [ # # ]: 0 : TAILQ_FOREACH(counter, &age_info->aged_counters, next) {
19812 : 0 : nb_flows++;
19813 [ # # ]: 0 : if (nb_contexts) {
19814 : : age_param = MLX5_CNT_TO_AGE(counter);
19815 : 0 : context[nb_flows - 1] = age_param->context;
19816 [ # # ]: 0 : if (!(--nb_contexts))
19817 : : break;
19818 : : }
19819 : : }
19820 : : rte_spinlock_unlock(&age_info->aged_sl);
19821 : 0 : MLX5_AGE_SET(age_info, MLX5_AGE_TRIGGER);
19822 : 0 : return nb_flows;
19823 : : }
19824 : :
19825 : : /*
19826 : : * Mutex-protected thunk to lock-free flow_dv_counter_alloc().
19827 : : */
19828 : : static uint32_t
19829 : 0 : flow_dv_counter_allocate(struct rte_eth_dev *dev)
19830 : : {
19831 : 0 : return flow_dv_counter_alloc(dev, 0);
19832 : : }
19833 : :
19834 : : /**
19835 : : * Validate indirect action.
19836 : : * Dispatcher for action type specific validation.
19837 : : *
19838 : : * @param[in] dev
19839 : : * Pointer to the Ethernet device structure.
19840 : : * @param[in] conf
19841 : : * Indirect action configuration.
19842 : : * @param[in] action
19843 : : * The indirect action object to validate.
19844 : : * @param[out] error
19845 : : * Perform verbose error reporting if not NULL. Initialized in case of
19846 : : * error only.
19847 : : *
19848 : : * @return
19849 : : * 0 on success, otherwise negative errno value.
19850 : : */
19851 : : int
19852 : 0 : flow_dv_action_validate(struct rte_eth_dev *dev,
19853 : : const struct rte_flow_indir_action_conf *conf,
19854 : : const struct rte_flow_action *action,
19855 : : struct rte_flow_error *err)
19856 : : {
19857 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19858 : : /* called from RTE API */
19859 : :
19860 : : RTE_SET_USED(conf);
19861 [ # # # # : 0 : switch (action->type) {
# ]
19862 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
19863 : : /*
19864 : : * priv->obj_ops is set according to driver capabilities.
19865 : : * When DevX capabilities are
19866 : : * sufficient, it is set to devx_obj_ops.
19867 : : * Otherwise, it is set to ibv_obj_ops.
19868 : : * ibv_obj_ops doesn't support ind_table_modify operation.
19869 : : * In this case the indirect RSS action can't be used.
19870 : : */
19871 [ # # ]: 0 : if (priv->obj_ops.ind_table_modify == NULL)
19872 : 0 : return rte_flow_error_set
19873 : : (err, ENOTSUP,
19874 : : RTE_FLOW_ERROR_TYPE_ACTION,
19875 : : NULL,
19876 : : "Indirect RSS action not supported");
19877 : 0 : return mlx5_validate_action_rss(dev, action, err);
19878 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
19879 [ # # ]: 0 : if (!priv->sh->aso_age_mng)
19880 : 0 : return rte_flow_error_set(err, ENOTSUP,
19881 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
19882 : : NULL,
19883 : : "Indirect age action not supported");
19884 : 0 : return flow_dv_validate_action_age(0, action, dev, err);
19885 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
19886 : 0 : return flow_dv_validate_action_count(dev, true, 0, false, err);
19887 : 0 : case RTE_FLOW_ACTION_TYPE_CONNTRACK:
19888 [ # # ]: 0 : if (!priv->sh->ct_aso_en)
19889 : 0 : return rte_flow_error_set(err, ENOTSUP,
19890 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
19891 : : "ASO CT is not supported");
19892 : 0 : return mlx5_validate_action_ct(dev, action->conf, err);
19893 : 0 : default:
19894 : 0 : return rte_flow_error_set(err, ENOTSUP,
19895 : : RTE_FLOW_ERROR_TYPE_ACTION,
19896 : : NULL,
19897 : : "action type not supported");
19898 : : }
19899 : : }
19900 : :
19901 : : /*
19902 : : * Check if the RSS configurations for colors of a meter policy match
19903 : : * each other, except the queues.
19904 : : *
19905 : : * @param[in] r1
19906 : : * Pointer to the first RSS flow action.
19907 : : * @param[in] r2
19908 : : * Pointer to the second RSS flow action.
19909 : : *
19910 : : * @return
19911 : : * 0 on match, 1 on conflict.
19912 : : */
19913 : : static inline int
19914 : 0 : flow_dv_mtr_policy_rss_compare(const struct rte_flow_action_rss *r1,
19915 : : const struct rte_flow_action_rss *r2)
19916 : : {
19917 [ # # ]: 0 : if (r1 == NULL || r2 == NULL)
19918 : : return 0;
19919 [ # # # # : 0 : if (!(r1->level <= 1 && r2->level <= 1) &&
# # ]
19920 [ # # ]: 0 : !(r1->level > 1 && r2->level > 1))
19921 : : return 1;
19922 [ # # ]: 0 : if (r1->func != r2->func)
19923 : : return 1;
19924 [ # # ]: 0 : if (r1->types != r2->types &&
19925 [ # # ]: 0 : !((r1->types == 0 || r1->types == RTE_ETH_RSS_IP) &&
19926 [ # # ]: 0 : (r2->types == 0 || r2->types == RTE_ETH_RSS_IP)))
19927 : : return 1;
19928 [ # # # # ]: 0 : if (r1->key || r2->key) {
19929 [ # # ]: 0 : const void *key1 = r1->key ? r1->key : rss_hash_default_key;
19930 [ # # ]: 0 : const void *key2 = r2->key ? r2->key : rss_hash_default_key;
19931 : :
19932 [ # # ]: 0 : if (memcmp(key1, key2, MLX5_RSS_HASH_KEY_LEN))
19933 : 0 : return 1;
19934 : : }
19935 : : return 0;
19936 : : }
19937 : :
19938 : : /**
19939 : : * Validate the meter hierarchy chain for meter policy.
19940 : : *
19941 : : * @param[in] dev
19942 : : * Pointer to the Ethernet device structure.
19943 : : * @param[in] meter_id
19944 : : * Meter id.
19945 : : * @param[in] action_flags
19946 : : * Holds the actions detected until now.
19947 : : * @param[out] is_rss
19948 : : * Is RSS or not.
19949 : : * @param[out] hierarchy_domain
19950 : : * The domain bitmap for hierarchy policy.
19951 : : * @param[out] error
19952 : : * Perform verbose error reporting if not NULL. Initialized in case of
19953 : : * error only.
19954 : : *
19955 : : * @return
19956 : : * 0 on success, otherwise negative errno value with error set.
19957 : : */
19958 : : static int
19959 : 0 : flow_dv_validate_policy_mtr_hierarchy(struct rte_eth_dev *dev,
19960 : : uint32_t meter_id,
19961 : : uint64_t action_flags,
19962 : : bool *is_rss,
19963 : : uint8_t *hierarchy_domain,
19964 : : struct rte_mtr_error *error)
19965 : : {
19966 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
19967 : : struct mlx5_flow_meter_info *fm;
19968 : : struct mlx5_flow_meter_policy *policy;
19969 : : uint8_t cnt = 1;
19970 : :
19971 [ # # ]: 0 : if (action_flags & (MLX5_FLOW_FATE_ACTIONS |
19972 : : MLX5_FLOW_FATE_ESWITCH_ACTIONS))
19973 : 0 : return -rte_mtr_error_set(error, EINVAL,
19974 : : RTE_MTR_ERROR_TYPE_POLICER_ACTION_GREEN,
19975 : : NULL,
19976 : : "Multiple fate actions not supported.");
19977 : 0 : *hierarchy_domain = 0;
19978 : 0 : fm = mlx5_flow_meter_find(priv, meter_id, NULL);
19979 : : while (true) {
19980 [ # # ]: 0 : if (!fm)
19981 : 0 : return -rte_mtr_error_set(error, EINVAL,
19982 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
19983 : : "Meter not found in meter hierarchy.");
19984 [ # # ]: 0 : if (fm->def_policy)
19985 : 0 : return -rte_mtr_error_set(error, EINVAL,
19986 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
19987 : : "Non termination meter not supported in hierarchy.");
19988 [ # # ]: 0 : if (!fm->shared)
19989 : 0 : return -rte_mtr_error_set(error, EINVAL,
19990 : : RTE_MTR_ERROR_TYPE_MTR_ID, NULL,
19991 : : "Only shared meter supported in hierarchy.");
19992 : 0 : policy = mlx5_flow_meter_policy_find(dev, fm->policy_id, NULL);
19993 : : MLX5_ASSERT(policy);
19994 : : /**
19995 : : * Only inherit the supported domains of the first meter in
19996 : : * hierarchy.
19997 : : * One meter supports at least one domain.
19998 : : */
19999 [ # # ]: 0 : if (!*hierarchy_domain) {
20000 [ # # ]: 0 : if (policy->transfer)
20001 : 0 : *hierarchy_domain |=
20002 : : MLX5_MTR_DOMAIN_TRANSFER_BIT;
20003 [ # # ]: 0 : if (policy->ingress)
20004 : 0 : *hierarchy_domain |=
20005 : : MLX5_MTR_DOMAIN_INGRESS_BIT;
20006 [ # # ]: 0 : if (policy->egress)
20007 : 0 : *hierarchy_domain |= MLX5_MTR_DOMAIN_EGRESS_BIT;
20008 : : }
20009 [ # # ]: 0 : if (!policy->is_hierarchy) {
20010 : 0 : *is_rss = policy->is_rss;
20011 : : break;
20012 : : }
20013 : 0 : rte_spinlock_lock(&policy->sl);
20014 : 0 : fm = mlx5_flow_meter_hierarchy_next_meter(priv, policy, NULL);
20015 : : rte_spinlock_unlock(&policy->sl);
20016 [ # # ]: 0 : if (++cnt >= MLX5_MTR_CHAIN_MAX_NUM)
20017 : 0 : return -rte_mtr_error_set(error, EINVAL,
20018 : : RTE_MTR_ERROR_TYPE_METER_POLICY, NULL,
20019 : : "Exceed max hierarchy meter number.");
20020 : : }
20021 : 0 : return 0;
20022 : : }
20023 : :
20024 : : /**
20025 : : * Validate meter policy actions.
20026 : : * Dispatcher for action type specific validation.
20027 : : *
20028 : : * @param[in] dev
20029 : : * Pointer to the Ethernet device structure.
20030 : : * @param[in] action
20031 : : * The meter policy action object to validate.
20032 : : * @param[in] attr
20033 : : * Attributes of flow to determine steering domain.
20034 : : * @param[out] error
20035 : : * Perform verbose error reporting if not NULL. Initialized in case of
20036 : : * error only.
20037 : : *
20038 : : * @return
20039 : : * 0 on success, otherwise negative errno value.
20040 : : */
20041 : : static int
20042 : 0 : flow_dv_validate_mtr_policy_acts(struct rte_eth_dev *dev,
20043 : : const struct rte_flow_action *actions[RTE_COLORS],
20044 : : struct rte_flow_attr *attr,
20045 : : bool *is_rss,
20046 : : uint8_t *domain_bitmap,
20047 : : uint8_t *policy_mode,
20048 : : struct rte_mtr_error *error)
20049 : : {
20050 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
20051 : 0 : struct mlx5_sh_config *dev_conf = &priv->sh->config;
20052 : : const struct rte_flow_action *act;
20053 : 0 : uint64_t action_flags[RTE_COLORS] = {0};
20054 : : int actions_n;
20055 : : int i, ret;
20056 : : struct rte_flow_error flow_err;
20057 : 0 : uint8_t domain_color[RTE_COLORS] = {0};
20058 : : uint8_t def_domain = MLX5_MTR_ALL_DOMAIN_BIT;
20059 : 0 : uint8_t hierarchy_domain = 0;
20060 : : const struct rte_flow_action_meter *mtr;
20061 : : const struct rte_flow_action_meter *next_mtr = NULL;
20062 : : bool def_green = false;
20063 : : bool def_yellow = false;
20064 : 0 : const struct rte_flow_action_rss *rss_color[RTE_COLORS] = {NULL};
20065 : : /* Called from RTE API */
20066 [ # # # # : 0 : bool is_root = !(attr->group || (attr->transfer && priv->fdb_def_rule));
# # ]
20067 : :
20068 [ # # ]: 0 : if (!dev_conf->dv_esw_en)
20069 : : def_domain &= ~MLX5_MTR_DOMAIN_TRANSFER_BIT;
20070 : 0 : *domain_bitmap = def_domain;
20071 : : /* Red color could only support DROP action. */
20072 [ # # ]: 0 : if (!actions[RTE_COLOR_RED] ||
20073 [ # # ]: 0 : actions[RTE_COLOR_RED]->type != RTE_FLOW_ACTION_TYPE_DROP)
20074 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20075 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20076 : : NULL, "Red color only supports drop action.");
20077 : : /*
20078 : : * Check default policy actions:
20079 : : * Green / Yellow: no action, Red: drop action
20080 : : * Either G or Y will trigger default policy actions to be created.
20081 : : */
20082 [ # # ]: 0 : if (!actions[RTE_COLOR_GREEN] ||
20083 [ # # ]: 0 : actions[RTE_COLOR_GREEN]->type == RTE_FLOW_ACTION_TYPE_END)
20084 : : def_green = true;
20085 [ # # ]: 0 : if (!actions[RTE_COLOR_YELLOW] ||
20086 [ # # ]: 0 : actions[RTE_COLOR_YELLOW]->type == RTE_FLOW_ACTION_TYPE_END)
20087 : : def_yellow = true;
20088 [ # # ]: 0 : if (def_green && def_yellow) {
20089 : 0 : *policy_mode = MLX5_MTR_POLICY_MODE_DEF;
20090 : 0 : return 0;
20091 [ # # ]: 0 : } else if (!def_green && def_yellow) {
20092 : 0 : *policy_mode = MLX5_MTR_POLICY_MODE_OG;
20093 [ # # ]: 0 : } else if (def_green && !def_yellow) {
20094 : 0 : *policy_mode = MLX5_MTR_POLICY_MODE_OY;
20095 : : } else {
20096 : 0 : *policy_mode = MLX5_MTR_POLICY_MODE_ALL;
20097 : : }
20098 : : /* Set to empty string in case of NULL pointer access by user. */
20099 : 0 : flow_err.message = "";
20100 [ # # ]: 0 : for (i = 0; i < RTE_COLORS; i++) {
20101 : 0 : act = actions[i];
20102 : 0 : for (action_flags[i] = 0, actions_n = 0;
20103 [ # # # # ]: 0 : act && act->type != RTE_FLOW_ACTION_TYPE_END;
20104 : 0 : act++) {
20105 [ # # ]: 0 : if (actions_n == MLX5_DV_MAX_NUMBER_OF_ACTIONS)
20106 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20107 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20108 : : NULL, "too many actions");
20109 [ # # # # : 0 : switch (act->type) {
# # # # #
# ]
20110 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
20111 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
20112 [ # # ]: 0 : if (!dev_conf->dv_esw_en)
20113 : 0 : return -rte_mtr_error_set(error,
20114 : : ENOTSUP,
20115 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20116 : : NULL, "PORT action validate check"
20117 : : " fail for ESW disable");
20118 : 0 : ret = flow_dv_validate_action_port_id(dev,
20119 : : action_flags[i],
20120 : : act, attr, &flow_err);
20121 [ # # ]: 0 : if (ret)
20122 : 0 : return -rte_mtr_error_set(error,
20123 : : ENOTSUP,
20124 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20125 [ # # ]: 0 : NULL, flow_err.message ?
20126 : : flow_err.message :
20127 : : "PORT action validate check fail");
20128 : 0 : ++actions_n;
20129 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_PORT_ID;
20130 : 0 : break;
20131 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
20132 : 0 : ret = flow_dv_validate_action_mark(dev, act,
20133 : : action_flags[i],
20134 : : attr, &flow_err);
20135 [ # # ]: 0 : if (ret < 0)
20136 : 0 : return -rte_mtr_error_set(error,
20137 : : ENOTSUP,
20138 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20139 [ # # ]: 0 : NULL, flow_err.message ?
20140 : : flow_err.message :
20141 : : "Mark action validate check fail");
20142 [ # # ]: 0 : if (dev_conf->dv_xmeta_en !=
20143 : : MLX5_XMETA_MODE_LEGACY)
20144 : 0 : return -rte_mtr_error_set(error,
20145 : : ENOTSUP,
20146 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20147 : : NULL, "Extend MARK action is "
20148 : : "not supported. Please try use "
20149 : : "default policy for meter.");
20150 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_MARK;
20151 : 0 : ++actions_n;
20152 : 0 : break;
20153 : 0 : case RTE_FLOW_ACTION_TYPE_SET_TAG:
20154 : 0 : ret = flow_dv_validate_action_set_tag(dev,
20155 : : act, action_flags[i],
20156 : : attr, &flow_err);
20157 [ # # ]: 0 : if (ret)
20158 : 0 : return -rte_mtr_error_set(error,
20159 : : ENOTSUP,
20160 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20161 [ # # ]: 0 : NULL, flow_err.message ?
20162 : : flow_err.message :
20163 : : "Set tag action validate check fail");
20164 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_SET_TAG;
20165 : 0 : ++actions_n;
20166 : 0 : break;
20167 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
20168 : 0 : ret = mlx5_flow_validate_action_drop
20169 : : (dev, false, attr, &flow_err);
20170 [ # # ]: 0 : if (ret < 0)
20171 : 0 : return -rte_mtr_error_set(error,
20172 : : ENOTSUP,
20173 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20174 [ # # ]: 0 : NULL, flow_err.message ?
20175 : : flow_err.message :
20176 : : "Drop action validate check fail");
20177 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_DROP;
20178 : 0 : ++actions_n;
20179 : 0 : break;
20180 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
20181 : : /*
20182 : : * Check whether extensive
20183 : : * metadata feature is engaged.
20184 : : */
20185 [ # # ]: 0 : if (dev_conf->dv_flow_en &&
20186 [ # # ]: 0 : (dev_conf->dv_xmeta_en !=
20187 [ # # ]: 0 : MLX5_XMETA_MODE_LEGACY) &&
20188 : 0 : mlx5_flow_ext_mreg_supported(dev))
20189 : 0 : return -rte_mtr_error_set(error,
20190 : : ENOTSUP,
20191 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20192 : : NULL, "Queue action with meta "
20193 : : "is not supported. Please try use "
20194 : : "default policy for meter.");
20195 : 0 : ret = mlx5_flow_validate_action_queue(act,
20196 : : action_flags[i], dev,
20197 : : attr, &flow_err);
20198 [ # # ]: 0 : if (ret < 0)
20199 : 0 : return -rte_mtr_error_set(error,
20200 : : ENOTSUP,
20201 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20202 [ # # ]: 0 : NULL, flow_err.message ?
20203 : : flow_err.message :
20204 : : "Queue action validate check fail");
20205 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_QUEUE;
20206 : 0 : ++actions_n;
20207 : 0 : break;
20208 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
20209 [ # # ]: 0 : if (dev_conf->dv_flow_en &&
20210 [ # # ]: 0 : (dev_conf->dv_xmeta_en !=
20211 [ # # ]: 0 : MLX5_XMETA_MODE_LEGACY) &&
20212 : 0 : mlx5_flow_ext_mreg_supported(dev))
20213 : 0 : return -rte_mtr_error_set(error,
20214 : : ENOTSUP,
20215 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20216 : : NULL, "RSS action with meta "
20217 : : "is not supported. Please try use "
20218 : : "default policy for meter.");
20219 : 0 : ret = mlx5_validate_action_rss(dev, act,
20220 : : &flow_err);
20221 [ # # ]: 0 : if (ret < 0)
20222 : 0 : return -rte_mtr_error_set(error,
20223 : : ENOTSUP,
20224 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20225 [ # # ]: 0 : NULL, flow_err.message ?
20226 : : flow_err.message :
20227 : : "RSS action validate check fail");
20228 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_RSS;
20229 : 0 : ++actions_n;
20230 : : /* Either G or Y will set the RSS. */
20231 : 0 : rss_color[i] = act->conf;
20232 : 0 : break;
20233 : 0 : case RTE_FLOW_ACTION_TYPE_JUMP:
20234 : 0 : ret = flow_dv_validate_action_jump(dev,
20235 : : NULL, act, action_flags[i],
20236 : : attr, true, &flow_err);
20237 [ # # ]: 0 : if (ret)
20238 : 0 : return -rte_mtr_error_set(error,
20239 : : ENOTSUP,
20240 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20241 [ # # ]: 0 : NULL, flow_err.message ?
20242 : : flow_err.message :
20243 : : "Jump action validate check fail");
20244 : 0 : ++actions_n;
20245 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_JUMP;
20246 : 0 : break;
20247 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
20248 : 0 : mtr = act->conf;
20249 [ # # # # ]: 0 : if (next_mtr && next_mtr->mtr_id != mtr->mtr_id)
20250 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20251 : : RTE_MTR_ERROR_TYPE_METER_POLICY, NULL,
20252 : : "Green and Yellow must use the same meter.");
20253 : 0 : ret = flow_dv_validate_policy_mtr_hierarchy(dev,
20254 : 0 : mtr->mtr_id,
20255 : : action_flags[i],
20256 : : is_rss,
20257 : : &hierarchy_domain,
20258 : : error);
20259 [ # # ]: 0 : if (ret)
20260 : 0 : return ret;
20261 : 0 : ++actions_n;
20262 : 0 : action_flags[i] |=
20263 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY;
20264 : : next_mtr = mtr;
20265 : 0 : break;
20266 : 0 : case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
20267 : 0 : ret = flow_dv_validate_action_modify_field(dev,
20268 : : action_flags[i], act, attr, is_root, &flow_err);
20269 [ # # ]: 0 : if (ret < 0)
20270 : 0 : return -rte_mtr_error_set(error,
20271 : : ENOTSUP,
20272 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20273 [ # # ]: 0 : NULL, flow_err.message ?
20274 : : flow_err.message :
20275 : : "Modify field action validate check fail");
20276 : 0 : ++actions_n;
20277 : 0 : action_flags[i] |= MLX5_FLOW_ACTION_MODIFY_FIELD;
20278 : 0 : break;
20279 : : default:
20280 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20281 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20282 : : NULL,
20283 : : "Doesn't support optional action");
20284 : : }
20285 : : }
20286 [ # # ]: 0 : if (action_flags[i] & MLX5_FLOW_ACTION_PORT_ID) {
20287 : 0 : domain_color[i] = MLX5_MTR_DOMAIN_TRANSFER_BIT;
20288 [ # # ]: 0 : } else if ((action_flags[i] &
20289 : 0 : (MLX5_FLOW_ACTION_RSS | MLX5_FLOW_ACTION_QUEUE)) ||
20290 [ # # ]: 0 : (action_flags[i] & MLX5_FLOW_ACTION_MARK)) {
20291 : : /*
20292 : : * Only support MLX5_XMETA_MODE_LEGACY
20293 : : * so MARK action is only in ingress domain.
20294 : : */
20295 : 0 : domain_color[i] = MLX5_MTR_DOMAIN_INGRESS_BIT;
20296 : : } else {
20297 : 0 : domain_color[i] = def_domain;
20298 [ # # ]: 0 : if (action_flags[i] &&
20299 [ # # ]: 0 : !(action_flags[i] & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
20300 : 0 : domain_color[i] &=
20301 : : ~MLX5_MTR_DOMAIN_TRANSFER_BIT;
20302 : : }
20303 [ # # ]: 0 : if (action_flags[i] &
20304 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
20305 : 0 : domain_color[i] &= hierarchy_domain;
20306 : : /*
20307 : : * Non-termination actions only support NIC Tx domain.
20308 : : * The adjustion should be skipped when there is no
20309 : : * action or only END is provided. The default domains
20310 : : * bit-mask is set to find the MIN intersection.
20311 : : * The action flags checking should also be skipped.
20312 : : */
20313 [ # # ]: 0 : if ((def_green && i == RTE_COLOR_GREEN) ||
20314 [ # # ]: 0 : (def_yellow && i == RTE_COLOR_YELLOW))
20315 : 0 : continue;
20316 : : /*
20317 : : * Validate the drop action mutual exclusion
20318 : : * with other actions. Drop action is mutually-exclusive
20319 : : * with any other action, except for Count action.
20320 : : */
20321 [ # # ]: 0 : if ((action_flags[i] & MLX5_FLOW_ACTION_DROP) &&
20322 [ # # ]: 0 : (action_flags[i] & ~MLX5_FLOW_ACTION_DROP)) {
20323 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20324 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20325 : : NULL, "Drop action is mutually-exclusive "
20326 : : "with any other action");
20327 : : }
20328 : : /* Eswitch has few restrictions on using items and actions */
20329 [ # # ]: 0 : if (domain_color[i] & MLX5_MTR_DOMAIN_TRANSFER_BIT) {
20330 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(dev) &&
20331 [ # # ]: 0 : action_flags[i] & MLX5_FLOW_ACTION_MARK)
20332 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20333 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20334 : : NULL, "unsupported action MARK");
20335 [ # # ]: 0 : if (action_flags[i] & MLX5_FLOW_ACTION_QUEUE)
20336 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20337 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20338 : : NULL, "unsupported action QUEUE");
20339 [ # # ]: 0 : if (action_flags[i] & MLX5_FLOW_ACTION_RSS)
20340 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20341 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20342 : : NULL, "unsupported action RSS");
20343 [ # # ]: 0 : if (!(action_flags[i] & MLX5_FLOW_FATE_ESWITCH_ACTIONS))
20344 : 0 : return -rte_mtr_error_set(error, ENOTSUP,
20345 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20346 : : NULL, "no fate action is found");
20347 : : } else {
20348 [ # # # # ]: 0 : if (!(action_flags[i] & MLX5_FLOW_FATE_ACTIONS) &&
20349 : : (domain_color[i] & MLX5_MTR_DOMAIN_INGRESS_BIT)) {
20350 [ # # ]: 0 : if ((domain_color[i] &
20351 : : MLX5_MTR_DOMAIN_EGRESS_BIT))
20352 : 0 : domain_color[i] =
20353 : : MLX5_MTR_DOMAIN_EGRESS_BIT;
20354 : : else
20355 : 0 : return -rte_mtr_error_set(error,
20356 : : ENOTSUP,
20357 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20358 : : NULL,
20359 : : "no fate action is found");
20360 : : }
20361 : : }
20362 : : }
20363 [ # # # # ]: 0 : if (next_mtr && *policy_mode == MLX5_MTR_POLICY_MODE_ALL) {
20364 : : uint64_t hierarchy_type_flag =
20365 : : MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY | MLX5_FLOW_ACTION_JUMP;
20366 [ # # ]: 0 : if (!(action_flags[RTE_COLOR_GREEN] & hierarchy_type_flag) ||
20367 [ # # ]: 0 : !(action_flags[RTE_COLOR_YELLOW] & hierarchy_type_flag))
20368 : 0 : return -rte_mtr_error_set(error, EINVAL, RTE_MTR_ERROR_TYPE_METER_POLICY,
20369 : : NULL,
20370 : : "Unsupported action in meter hierarchy.");
20371 : : }
20372 : : /* If both colors have RSS, the attributes should be the same. */
20373 [ # # ]: 0 : if (flow_dv_mtr_policy_rss_compare(rss_color[RTE_COLOR_GREEN],
20374 : : rss_color[RTE_COLOR_YELLOW]))
20375 : 0 : return -rte_mtr_error_set(error, EINVAL,
20376 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20377 : : NULL, "policy RSS attr conflict");
20378 [ # # # # ]: 0 : if (rss_color[RTE_COLOR_GREEN] || rss_color[RTE_COLOR_YELLOW])
20379 : 0 : *is_rss = true;
20380 : : /* "domain_color[C]" is non-zero for each color, default is ALL. */
20381 [ # # ]: 0 : if (!def_green && !def_yellow &&
20382 [ # # ]: 0 : domain_color[RTE_COLOR_GREEN] != domain_color[RTE_COLOR_YELLOW] &&
20383 [ # # ]: 0 : !(action_flags[RTE_COLOR_GREEN] & MLX5_FLOW_ACTION_DROP) &&
20384 [ # # ]: 0 : !(action_flags[RTE_COLOR_YELLOW] & MLX5_FLOW_ACTION_DROP))
20385 : 0 : return -rte_mtr_error_set(error, EINVAL,
20386 : : RTE_MTR_ERROR_TYPE_METER_POLICY,
20387 : : NULL, "policy domains conflict");
20388 : : /*
20389 : : * At least one color policy is listed in the actions, the domains
20390 : : * to be supported should be the intersection.
20391 : : */
20392 : 0 : *domain_bitmap = domain_color[RTE_COLOR_GREEN] &
20393 : 0 : domain_color[RTE_COLOR_YELLOW];
20394 : 0 : return 0;
20395 : : }
20396 : :
20397 : : static int
20398 : 0 : flow_dv_sync_domain(struct rte_eth_dev *dev, uint32_t domains, uint32_t flags)
20399 : : {
20400 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
20401 : : int ret = 0;
20402 : :
20403 [ # # # # ]: 0 : if ((domains & RTE_PMD_MLX5_DOMAIN_BIT_NIC_RX) && priv->sh->rx_domain != NULL) {
20404 : : ret = mlx5_os_flow_dr_sync_domain(priv->sh->rx_domain,
20405 : : flags);
20406 [ # # ]: 0 : if (ret != 0)
20407 : : return ret;
20408 : : }
20409 [ # # # # ]: 0 : if ((domains & RTE_PMD_MLX5_DOMAIN_BIT_NIC_TX) && priv->sh->tx_domain != NULL) {
20410 : : ret = mlx5_os_flow_dr_sync_domain(priv->sh->tx_domain, flags);
20411 [ # # ]: 0 : if (ret != 0)
20412 : : return ret;
20413 : : }
20414 [ # # # # ]: 0 : if ((domains & RTE_PMD_MLX5_DOMAIN_BIT_FDB) && priv->sh->fdb_domain != NULL) {
20415 : : ret = mlx5_os_flow_dr_sync_domain(priv->sh->fdb_domain, flags);
20416 [ # # ]: 0 : if (ret != 0)
20417 : 0 : return ret;
20418 : : }
20419 : : return 0;
20420 : : }
20421 : :
20422 : : /**
20423 : : * Discover the number of available flow priorities
20424 : : * by trying to create a flow with the highest priority value
20425 : : * for each possible number.
20426 : : *
20427 : : * @param[in] dev
20428 : : * Ethernet device.
20429 : : * @param[in] vprio
20430 : : * List of possible number of available priorities.
20431 : : * @param[in] vprio_n
20432 : : * Size of @p vprio array.
20433 : : * @return
20434 : : * On success, number of available flow priorities.
20435 : : * On failure, a negative errno-style code and rte_errno is set.
20436 : : */
20437 : : static int
20438 : 0 : flow_dv_discover_priorities(struct rte_eth_dev *dev,
20439 : : const uint16_t *vprio, int vprio_n)
20440 : : {
20441 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
20442 : 0 : struct mlx5_indexed_pool *pool = priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW];
20443 : : struct rte_flow_item_eth eth;
20444 : 0 : struct rte_flow_item item = {
20445 : : .type = RTE_FLOW_ITEM_TYPE_ETH,
20446 : : .spec = ð,
20447 : : .mask = ð,
20448 : : };
20449 : 0 : struct mlx5_flow_dv_matcher matcher = {
20450 : : .mask = {
20451 : : .size = sizeof(matcher.mask.buf),
20452 : : },
20453 : : };
20454 : : union mlx5_flow_tbl_key tbl_key;
20455 : : struct mlx5_flow flow;
20456 : : void *action;
20457 : : struct rte_flow_error error;
20458 : : uint8_t misc_mask;
20459 : : int i, err, ret = -ENOTSUP;
20460 : :
20461 : : /*
20462 : : * Prepare a flow with a catch-all pattern and a drop action.
20463 : : * Use drop queue, because shared drop action may be unavailable.
20464 : : */
20465 : 0 : action = priv->drop_queue.hrxq->action;
20466 [ # # ]: 0 : if (action == NULL) {
20467 : 0 : DRV_LOG(ERR, "Priority discovery requires a drop action");
20468 : 0 : rte_errno = ENOTSUP;
20469 : 0 : return -rte_errno;
20470 : : }
20471 : : memset(&flow, 0, sizeof(flow));
20472 : 0 : flow.handle = mlx5_ipool_zmalloc(pool, &flow.handle_idx);
20473 [ # # ]: 0 : if (flow.handle == NULL) {
20474 : 0 : DRV_LOG(ERR, "Cannot create flow handle");
20475 : 0 : rte_errno = ENOMEM;
20476 : 0 : return -rte_errno;
20477 : : }
20478 : 0 : flow.ingress = true;
20479 : 0 : flow.dv.value.size = MLX5_ST_SZ_BYTES(fte_match_param);
20480 : 0 : flow.dv.actions[0] = action;
20481 : 0 : flow.dv.actions_n = 1;
20482 : : memset(ð, 0, sizeof(eth));
20483 : 0 : flow_dv_translate_item_eth(matcher.mask.buf, &item,
20484 : : /* inner */ false, /* group */ 0,
20485 : : MLX5_SET_MATCHER_SW_M);
20486 : 0 : flow_dv_translate_item_eth(flow.dv.value.buf, &item,
20487 : : /* inner */ false, /* group */ 0,
20488 : : MLX5_SET_MATCHER_SW_V);
20489 : 0 : matcher.crc = rte_raw_cksum(matcher.mask.buf, matcher.mask.size);
20490 [ # # ]: 0 : for (i = 0; i < vprio_n; i++) {
20491 : : /* Configure the next proposed maximum priority. */
20492 : 0 : matcher.priority = vprio[i] - 1;
20493 : : memset(&tbl_key, 0, sizeof(tbl_key));
20494 : 0 : err = flow_dv_matcher_register(dev, &matcher, &tbl_key, &flow,
20495 : : /* tunnel */ NULL,
20496 : : /* group */ 0,
20497 : : &error);
20498 [ # # ]: 0 : if (err != 0) {
20499 : : /* This action is pure SW and must always succeed. */
20500 : 0 : DRV_LOG(ERR, "Cannot register matcher");
20501 : 0 : ret = -rte_errno;
20502 : 0 : break;
20503 : : }
20504 : : /* Try to apply the flow to HW. */
20505 [ # # ]: 0 : misc_mask = flow_dv_matcher_enable(flow.handle->dvh.matcher->mask.buf);
20506 : : __flow_dv_adjust_buf_size(&flow.dv.value.size, misc_mask);
20507 : 0 : err = mlx5_flow_os_create_flow
20508 : : (flow.handle->dvh.matcher->matcher_object,
20509 : 0 : (void *)&flow.dv.value, flow.dv.actions_n,
20510 : : flow.dv.actions, &flow.handle->drv_flow);
20511 : : if (err == 0) {
20512 : 0 : claim_zero(mlx5_flow_os_destroy_flow
20513 : : (flow.handle->drv_flow));
20514 : 0 : flow.handle->drv_flow = NULL;
20515 : : }
20516 : 0 : claim_zero(flow_dv_matcher_release(dev, flow.handle));
20517 [ # # ]: 0 : if (err != 0)
20518 : : break;
20519 : 0 : ret = vprio[i];
20520 : : }
20521 : 0 : mlx5_ipool_free(pool, flow.handle_idx);
20522 : : /* Set rte_errno if no expected priority value matched. */
20523 [ # # ]: 0 : if (ret < 0)
20524 : 0 : rte_errno = -ret;
20525 : : return ret;
20526 : : }
20527 : :
20528 : : const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops = {
20529 : : .list_create = flow_legacy_list_create,
20530 : : .list_destroy = flow_legacy_list_destroy,
20531 : : .validate = flow_dv_validate,
20532 : : .prepare = flow_dv_prepare,
20533 : : .translate = flow_dv_translate,
20534 : : .apply = flow_dv_apply,
20535 : : .remove = flow_dv_remove,
20536 : : .destroy = flow_dv_destroy,
20537 : : .query = flow_dv_query,
20538 : : .create_mtr_tbls = flow_dv_create_mtr_tbls,
20539 : : .destroy_mtr_tbls = flow_dv_destroy_mtr_tbls,
20540 : : .destroy_mtr_drop_tbls = flow_dv_destroy_mtr_drop_tbls,
20541 : : .create_meter = flow_dv_mtr_alloc,
20542 : : .free_meter = flow_dv_aso_mtr_release_to_pool,
20543 : : .validate_mtr_acts = flow_dv_validate_mtr_policy_acts,
20544 : : .create_mtr_acts = flow_dv_create_mtr_policy_acts,
20545 : : .destroy_mtr_acts = flow_dv_destroy_mtr_policy_acts,
20546 : : .create_policy_rules = flow_dv_create_policy_rules,
20547 : : .destroy_policy_rules = flow_dv_destroy_policy_rules,
20548 : : .create_def_policy = flow_dv_create_def_policy,
20549 : : .destroy_def_policy = flow_dv_destroy_def_policy,
20550 : : .meter_sub_policy_rss_prepare = flow_dv_meter_sub_policy_rss_prepare,
20551 : : .meter_hierarchy_rule_create = flow_dv_meter_hierarchy_rule_create,
20552 : : .destroy_sub_policy_with_rxq = flow_dv_destroy_sub_policy_with_rxq,
20553 : : .counter_alloc = flow_dv_counter_allocate,
20554 : : .counter_free = flow_dv_counter_free,
20555 : : .counter_query = flow_dv_counter_query,
20556 : : .get_aged_flows = flow_dv_get_aged_flows,
20557 : : .action_validate = flow_dv_action_validate,
20558 : : .action_create = flow_dv_action_create,
20559 : : .action_destroy = flow_dv_action_destroy,
20560 : : .action_update = flow_dv_action_update,
20561 : : .action_query = flow_dv_action_query,
20562 : : .sync_domain = flow_dv_sync_domain,
20563 : : .discover_priorities = flow_dv_discover_priorities,
20564 : : .item_create = flow_dv_item_create,
20565 : : .item_release = flow_dv_item_release,
20566 : : };
20567 : :
20568 : : #endif /* HAVE_IBV_FLOW_DV_SUPPORT */
|